-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImposterLayout.js
99 lines (88 loc) · 2.53 KB
/
ImposterLayout.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
customElements.define(
'imposter-layout',
class extends HTMLElement {
constructor() {
super()
this.attachShadow({ mode: 'open' })
}
render() {
// prettier-ignore
this.shadowRoot.innerHTML = `
<style>
:host {
${ this.fixed ? `position: fixed;` : 'position: absolute;' }
inset-block-start: 50%;
inset-inline-start: 50%;
transform: translate(-50%, -50%);
${ !this.breakout ? `
max-inline-size: calc(100% - (${this.margin} * 2));
max-block-size: calc(100% - (${this.margin} * 2));
overflow: auto;` : ''
}
}
</style>
<slot></slot>
`
console.log('imposter:', this.shadowRoot.innerHTML)
}
connectedCallback() {
this.render()
}
attributeChangedCallback() {
this.render()
}
static get observedAttributes() {
return ['breakout', 'margin', 'fixed']
}
get breakout() {
return this.hasAttribute('breakout')
}
set breakout(val) {
if (val) {
return this.setAttribute('breakout', '')
} else {
return this.removeAttribute('breakout')
}
}
get fixed() {
return this.hasAttribute('fixed')
}
set fixed(val) {
if (val) {
return this.setAttribute('fixed', '')
} else {
return this.removeAttribute('fixed')
}
}
get margin() {
return this.getAttribute('margin') || '0px'
}
set margin(val) {
return this.setAttribute('margin', val)
}
}
)
/*
stack-l {
display: flex;
flex-direction: column;
justify-content: flex-start;
}
stack-l > * + * {
margin-block-start: var(--s1);
}
[data-id="${id}"] ${this.recursive ? '' : ' > '} * + * {
margin-block-start: ${this.space};
}
${
this.splitAfter
? `
[data-id="${id}"] :only-child {
block-size: 100%;
}
[data-id="${id}"] > :nth-child(${this.splitAfter}) {
margin-block-end: auto;
}`
: ''
}
*/