enigmatic 0.11.0 → 0.11.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/components.js +16 -16
- package/enigmatic.css +277 -246
- package/enigmatic.js +172 -157
- package/package.json +12 -5
- package/server.mjs +9 -0
- package/test-components.html +16 -0
- package/test-flatten.html +25 -0
- package/test-js.html +24 -0
- package/test-layout.html +13 -0
- package/test-schema.html +12 -0
- package/test.mjs +26 -0
- package/index.html +0 -19
package/components.js
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
window.components = {
|
|
2
|
-
'hello-world': {
|
|
3
|
-
style: 'color: red',
|
|
4
|
-
onMount: async x => console.log('mounted h-w'),
|
|
5
|
-
template: 'Hello World'
|
|
6
|
-
},
|
|
7
|
-
'random-users': {
|
|
8
|
-
template: 'Hello Random user: {results[0].name.first} {results[0].name.last}',
|
|
9
|
-
onMount: e => console.log('Mounted', e.tagName, e.props),
|
|
10
|
-
beforeData: x => x.results[0].name.first = 'John'
|
|
11
|
-
},
|
|
12
|
-
'tailwind-example': {
|
|
13
|
-
template: '<div class="bg-blue-300 text-white font-bold py-2 px-4 rounded">I am Tailwind</div>',
|
|
14
|
-
onMount: async e => await loadCSS('https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css')
|
|
15
|
-
}
|
|
16
|
-
}
|
|
1
|
+
window.components = {
|
|
2
|
+
'hello-world': {
|
|
3
|
+
style: 'color: red',
|
|
4
|
+
onMount: async x => console.log('mounted h-w'),
|
|
5
|
+
template: 'Hello World'
|
|
6
|
+
},
|
|
7
|
+
'random-users': {
|
|
8
|
+
template: 'Hello Random user: {results[0].name.first} {results[0].name.last}',
|
|
9
|
+
onMount: e => console.log('Mounted', e.tagName, e.props),
|
|
10
|
+
beforeData: x => x.results[0].name.first = 'John'
|
|
11
|
+
},
|
|
12
|
+
'tailwind-example': {
|
|
13
|
+
template: '<div class="bg-blue-300 text-white font-bold py-2 px-4 rounded">I am Tailwind</div>',
|
|
14
|
+
onMount: async e => await loadCSS('https://unpkg.com/tailwindcss@^1.0/dist/tailwind.min.css')
|
|
15
|
+
}
|
|
16
|
+
}
|
package/enigmatic.css
CHANGED
|
@@ -1,247 +1,278 @@
|
|
|
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
|
-
0
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
0
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
-
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
.
|
|
143
|
-
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
.
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
.
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
.
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
.
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
.
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
.
|
|
246
|
-
|
|
1
|
+
html {
|
|
2
|
+
max-width: 70ch;
|
|
3
|
+
/* larger spacing on larger screens, very small spacing on tiny screens */
|
|
4
|
+
padding: calc(1vmin + .5rem);
|
|
5
|
+
/* shorthand for margin-left/margin-right */
|
|
6
|
+
margin-inline: auto;
|
|
7
|
+
/* fluid sizing: https://frontaid.io/blog/fluid-typography-2d-css-locks-clamp/ */
|
|
8
|
+
font-size: clamp(1em, 0.909em + 0.45vmin, 1.25em);
|
|
9
|
+
/* use system font stack: https://developer.mozilla.org/en-US/docs/Web/CSS/font-family */
|
|
10
|
+
font-family: system-ui
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
/* increase line-height for everything except headings */
|
|
14
|
+
body :not(:is(h1, h2, h3, h4, h5, h6)) {
|
|
15
|
+
line-height: 1.75;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
h1,
|
|
19
|
+
h2,
|
|
20
|
+
h3,
|
|
21
|
+
h4,
|
|
22
|
+
h5,
|
|
23
|
+
h6 {
|
|
24
|
+
margin: 3em 0 1em;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
p,
|
|
28
|
+
ul,
|
|
29
|
+
ol {
|
|
30
|
+
margin-bottom: 2em;
|
|
31
|
+
color: #1d1d1d;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
body,
|
|
35
|
+
section {
|
|
36
|
+
display: grid;
|
|
37
|
+
margin: 0;
|
|
38
|
+
grid-template-columns: var(--cols, 1fr 4fr 1fr);
|
|
39
|
+
grid-template-rows: var(--rows, 1fr 9fr 1fr);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
* {
|
|
43
|
+
grid-column: span var(--span, 1);
|
|
44
|
+
grid-row: span var(--span-rows, 1);
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.flex {
|
|
48
|
+
display: flex;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** positioning ***/
|
|
52
|
+
|
|
53
|
+
.center {
|
|
54
|
+
position: fixed;
|
|
55
|
+
top: 50%;
|
|
56
|
+
left: 50%;
|
|
57
|
+
margin-top: -50px;
|
|
58
|
+
margin-left: -100px;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
.right {
|
|
62
|
+
float: right;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.left {
|
|
66
|
+
float: left;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
.fixed {
|
|
70
|
+
position: fixed;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
.top {
|
|
74
|
+
top: 0;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
.bottom {
|
|
78
|
+
bottom: 0
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
.fill {
|
|
82
|
+
height: 100vh;
|
|
83
|
+
width: 100wh
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
.hide {
|
|
87
|
+
opacity: 0;
|
|
88
|
+
transition: opacity 0.25s linear;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
.show {
|
|
92
|
+
opacity: 1;
|
|
93
|
+
transition: opacity 0.25s linear;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
.slide-in {
|
|
97
|
+
animation: slide-in 0.1s forwards;
|
|
98
|
+
-webkit-animation: slide-in 0.1s forwards;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
.slide-out {
|
|
102
|
+
animation: slide-out 0.1s forwards;
|
|
103
|
+
-webkit-animation: slide-out 0.1s forwards;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
@keyframes slide-in {
|
|
107
|
+
100% {
|
|
108
|
+
transform: translateX(0%);
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
@-webkit-keyframes slide-in {
|
|
113
|
+
100% {
|
|
114
|
+
-webkit-transform: translateX(0%);
|
|
115
|
+
}
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
@keyframes slide-out {
|
|
119
|
+
0% {
|
|
120
|
+
transform: translateX(0%);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
100% {
|
|
124
|
+
transform: translateX(-100%);
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
@-webkit-keyframes slide-out {
|
|
129
|
+
0% {
|
|
130
|
+
-webkit-transform: translateX(0%);
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
100% {
|
|
134
|
+
-webkit-transform: translateX(-100%);
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
a {
|
|
139
|
+
text-decoration: none;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.shadow {
|
|
143
|
+
box-shadow: 6px 6px 6px #dbdbdb;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.cursor {
|
|
147
|
+
cursor: default;
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
.margins {
|
|
151
|
+
margin: var(--margins, 15px);
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
.padding {
|
|
155
|
+
padding: var(--padding, 15px);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
.rem {
|
|
159
|
+
font-size: var(--rem, 2rem);
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
.faded {
|
|
163
|
+
opacity: 0.5;
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
.fade {
|
|
167
|
+
opacity: 1;
|
|
168
|
+
transition: opacity 0.25s ease-in-out;
|
|
169
|
+
-moz-transition: opacity 0.25s ease-in-out;
|
|
170
|
+
-webkit-transition: opacity 0.25s ease-in-out;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
.fade:hover {
|
|
174
|
+
opacity: 0.5;
|
|
175
|
+
}
|
|
176
|
+
|
|
177
|
+
.unfade {
|
|
178
|
+
opacity: 0.5;
|
|
179
|
+
transition: opacity 0.25s ease-in-out;
|
|
180
|
+
-moz-transition: opacity 0.25s ease-in-out;
|
|
181
|
+
-webkit-transition: opacity 0.25s ease-in-out;
|
|
182
|
+
}
|
|
183
|
+
|
|
184
|
+
.unfade:hover {
|
|
185
|
+
opacity: 1;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
.rounded {
|
|
189
|
+
-moz-border-radius: 10px;
|
|
190
|
+
-webkit-border-radius: 10px;
|
|
191
|
+
border-radius: 10px;
|
|
192
|
+
-khtml-border-radius: 10px;
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
.round {
|
|
196
|
+
vertical-align: middle;
|
|
197
|
+
width: 50px;
|
|
198
|
+
height: 50px;
|
|
199
|
+
border-radius: 50%;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** html elements **/
|
|
203
|
+
|
|
204
|
+
canvas {
|
|
205
|
+
position: fixed;
|
|
206
|
+
top: 0;
|
|
207
|
+
left: 0;
|
|
208
|
+
}
|
|
209
|
+
|
|
210
|
+
ul {
|
|
211
|
+
list-style-type: none;
|
|
212
|
+
border: 20px;
|
|
213
|
+
padding: 20px;
|
|
214
|
+
width: 50%;
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
li {
|
|
218
|
+
list-style-type: none;
|
|
219
|
+
border: 10px;
|
|
220
|
+
padding: 10px;
|
|
221
|
+
}
|
|
222
|
+
|
|
223
|
+
li:hover {
|
|
224
|
+
background-color: rgb(243, 241, 241);
|
|
225
|
+
cursor: pointer;
|
|
226
|
+
}
|
|
227
|
+
|
|
228
|
+
.opacity1 {
|
|
229
|
+
opacity: .1
|
|
230
|
+
}
|
|
231
|
+
|
|
232
|
+
.opacity2 {
|
|
233
|
+
opacity: .2
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
.opacity3 {
|
|
237
|
+
opacity: .3
|
|
238
|
+
}
|
|
239
|
+
|
|
240
|
+
.opacity4 {
|
|
241
|
+
opacity: .4
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
.opacity5 {
|
|
245
|
+
opacity: .5
|
|
246
|
+
}
|
|
247
|
+
|
|
248
|
+
.opacity6 {
|
|
249
|
+
opacity: .6
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
.opacity7 {
|
|
253
|
+
opacity: .7
|
|
254
|
+
}
|
|
255
|
+
|
|
256
|
+
.opacity8 {
|
|
257
|
+
opacity: .8
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
.opacity9 {
|
|
261
|
+
opacity: .9
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
.bg-red {
|
|
265
|
+
background-color: red;
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
.bg-blue {
|
|
269
|
+
background-color: blue;
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
.bg-yellow {
|
|
273
|
+
background-color: yellow;
|
|
274
|
+
}
|
|
275
|
+
|
|
276
|
+
.bg-green {
|
|
277
|
+
background-color: green;
|
|
247
278
|
}
|
package/enigmatic.js
CHANGED
|
@@ -1,157 +1,172 @@
|
|
|
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
|
-
w
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
w.
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
return
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
)
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
if (
|
|
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
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
w.
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
)
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
if (e.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
e.
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
1
|
+
const w = {}, d = document
|
|
2
|
+
w.enigmatic = { version: '2022-09-24 0.11.2' }
|
|
3
|
+
|
|
4
|
+
/////// Helpers
|
|
5
|
+
|
|
6
|
+
w.$ = d.querySelector.bind(d)
|
|
7
|
+
w.$$ = d.querySelectorAll.bind(d)
|
|
8
|
+
w.loadJS = (src) => {
|
|
9
|
+
return new Promise((r, j) => {
|
|
10
|
+
if ($(`script[src="${src}"]`)) return r(true)
|
|
11
|
+
const s = d.createElement('script')
|
|
12
|
+
s.src = src
|
|
13
|
+
s.addEventListener('load', r)
|
|
14
|
+
d.head.appendChild(s)
|
|
15
|
+
})
|
|
16
|
+
}
|
|
17
|
+
w.loadCSS = (src) => {
|
|
18
|
+
return new Promise((r, j) => {
|
|
19
|
+
const s = document.createElement('link')
|
|
20
|
+
s.rel = 'stylesheet'
|
|
21
|
+
s.href = src
|
|
22
|
+
s.addEventListener('load', r)
|
|
23
|
+
d.head.appendChild(s)
|
|
24
|
+
})
|
|
25
|
+
}
|
|
26
|
+
w.wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
27
|
+
w.ready = async () => {
|
|
28
|
+
return new Promise((r) => {
|
|
29
|
+
if (document.readyState === 'complete') r(true)
|
|
30
|
+
document.onreadystatechange = () => {
|
|
31
|
+
if (document.readyState === 'complete') r()
|
|
32
|
+
}
|
|
33
|
+
})
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
// Template a string, using {$key}, {_key_}, {_val_}
|
|
37
|
+
// ie.. {key1: {name: 'value'}, key2: {name: 'value2'}} OR [{name: 'value'}, {name: 'value2'}]
|
|
38
|
+
w.flatten = (obj, text) => {
|
|
39
|
+
let htmls = ''
|
|
40
|
+
if (obj instanceof Array) obj = { ...obj }
|
|
41
|
+
for (let k in obj) {
|
|
42
|
+
let html = text.replaceAll('{$key}', k)
|
|
43
|
+
for (let j in obj[k]) {
|
|
44
|
+
html = html.replaceAll('{_key_}', j).replaceAll('{_val_}', obj[k][j])
|
|
45
|
+
html = html.replaceAll(`{${j}}`, obj[k][j])
|
|
46
|
+
}
|
|
47
|
+
htmls += html
|
|
48
|
+
}
|
|
49
|
+
return htmls
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
/////// Custom element
|
|
53
|
+
w.element = (
|
|
54
|
+
name,
|
|
55
|
+
{ onMount = x => x, beforeData = (x) => x, style, template = '' }
|
|
56
|
+
) => {
|
|
57
|
+
customElements.define(
|
|
58
|
+
name,
|
|
59
|
+
class extends HTMLElement {
|
|
60
|
+
connectedCallback(props) {
|
|
61
|
+
onMount(this)
|
|
62
|
+
if (style) {
|
|
63
|
+
const s = document.createElement('style')
|
|
64
|
+
s.innerHTML = `${name} {${style}}`
|
|
65
|
+
d.body.appendChild(s)
|
|
66
|
+
}
|
|
67
|
+
this.template = template
|
|
68
|
+
if (!this.template.match('{')) this.innerHTML = this.template
|
|
69
|
+
}
|
|
70
|
+
set(o) {
|
|
71
|
+
this.innerHTML = ''
|
|
72
|
+
o = beforeData(o)
|
|
73
|
+
if (!Array.isArray(o)) o = [o]
|
|
74
|
+
const m = new Function('o', 'return `' + this.template + '`')
|
|
75
|
+
o.map((i) => (this.innerHTML += m(i)))
|
|
76
|
+
return true
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
if (window.components) {
|
|
83
|
+
for (let name in window.components) w.element(name, window.components[name])
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
/////// State, data, and reactivity
|
|
87
|
+
w.state = new Proxy({}, {
|
|
88
|
+
set: (obj, prop, value) => {
|
|
89
|
+
console.log(prop, value)
|
|
90
|
+
if(this[prop] === value) {
|
|
91
|
+
return true
|
|
92
|
+
}
|
|
93
|
+
for (const e of $$(`[data=${prop}]`)) {
|
|
94
|
+
if(e.set) e.set(value)
|
|
95
|
+
}
|
|
96
|
+
obj[prop] = value
|
|
97
|
+
return value
|
|
98
|
+
},
|
|
99
|
+
get: (obj, prop, receiver) => {
|
|
100
|
+
if (prop == '_all') return obj
|
|
101
|
+
return obj[prop]
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
)
|
|
105
|
+
|
|
106
|
+
w.save = (obj, name) => {
|
|
107
|
+
return localStorage.setItem(name, JSON.stringify(obj))
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
w.load = (name) => {
|
|
111
|
+
return localStorage.getItem(name)
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
w.get = async (url, options = {}, transform, key) => {
|
|
115
|
+
let data = await (await fetch(`https://${url}`, options)).json()
|
|
116
|
+
if (transform) data = transform(data)
|
|
117
|
+
if (key) w.state[key] = data
|
|
118
|
+
return data
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
w.stream = async (url, key) => {
|
|
122
|
+
const ev = new EventSource(url)
|
|
123
|
+
ev.onmessage = (ev) => {
|
|
124
|
+
const data = JSON.parse(ev.data)
|
|
125
|
+
if (key) w.state[key] = data
|
|
126
|
+
return data
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/////// Startup
|
|
131
|
+
w.start = async () => {
|
|
132
|
+
await w.ready();
|
|
133
|
+
[...$$('*')].map(e => {
|
|
134
|
+
e.attr = {};
|
|
135
|
+
[...e.attributes].map((a) => (e.attr[a.name] = a.value))
|
|
136
|
+
if (e.attr?.fetch) {
|
|
137
|
+
e.fetch = async () => {
|
|
138
|
+
return w.get(e.attr?.fetch, {}, w[e.attr?.transform], e.attr.data)
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
if (e.hasAttribute('immediate')) {
|
|
142
|
+
e.fetch()
|
|
143
|
+
}
|
|
144
|
+
if (e.attr?.stream) {
|
|
145
|
+
e.stream = w.stream.bind(null, e.pr.stream, null, window[e.pr.transform], e.id)
|
|
146
|
+
}
|
|
147
|
+
let dta = e.attr?.data
|
|
148
|
+
if (dta) {
|
|
149
|
+
console.log(`processing ${e}`)
|
|
150
|
+
if (e.innerHTML) {
|
|
151
|
+
e.template = e.innerHTML
|
|
152
|
+
if(e.innerHTML.match('{')) {
|
|
153
|
+
e.innerHTML = ''
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
e.set = (o) => {
|
|
157
|
+
e.innerHTML = w.flatten(o, e.template)
|
|
158
|
+
}
|
|
159
|
+
if (e.attr?.value) {
|
|
160
|
+
let o = e.attr.value
|
|
161
|
+
try { o = JSON.parse(o) } catch(e) {}
|
|
162
|
+
w.state[dta] = o
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
})
|
|
166
|
+
}
|
|
167
|
+
|
|
168
|
+
Object.assign(window, w);
|
|
169
|
+
|
|
170
|
+
(async () => {
|
|
171
|
+
await w.start()
|
|
172
|
+
})()
|
package/package.json
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "enigmatic",
|
|
3
|
-
"main": "enigmatic.js",
|
|
4
|
-
"version": "0.11.
|
|
5
|
-
|
|
1
|
+
{
|
|
2
|
+
"name": "enigmatic",
|
|
3
|
+
"main": "enigmatic.js",
|
|
4
|
+
"version": "0.11.2",
|
|
5
|
+
"scripts": {
|
|
6
|
+
"test": "node test.mjs"
|
|
7
|
+
},
|
|
8
|
+
"devDependencies": {
|
|
9
|
+
"instax": "^0.1.5",
|
|
10
|
+
"puppeteer": "^17.1.3"
|
|
11
|
+
}
|
|
12
|
+
}
|
package/server.mjs
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
<script>
|
|
2
|
+
customElements.define('is-online', class IsOnline extends HTMLElement {
|
|
3
|
+
connectedCallback() {
|
|
4
|
+
this.setAttribute('rel', 'icon')
|
|
5
|
+
this.setAttribute('href', "data:image/svg+xml,<svg xmlns=%22http://www.w3.org/2000/svg%22 viewBox=%220 0 100 100%22><text y=%22.9em%22 font-size=%2290%22>🎯</text></svg>")
|
|
6
|
+
}
|
|
7
|
+
})
|
|
8
|
+
</script>
|
|
9
|
+
|
|
10
|
+
<link rel="stylesheet" href="enigmatic.css">
|
|
11
|
+
<body style="--cols:1fr 6fr 1fr; --rows:1fr 10fr">
|
|
12
|
+
<my-e>hey</my-e>
|
|
13
|
+
<my-e>hey</my-e>
|
|
14
|
+
<my-e>hey</my-e>
|
|
15
|
+
<my-e>hey</my-e>
|
|
16
|
+
<my-e>hey</my-e>
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
<script src='enigmatic.js'></script>
|
|
2
|
+
|
|
3
|
+
<div id='templ' data="akey">
|
|
4
|
+
{$key}: {_key_} : {_val_}, name = {name}, value = {value} <br>
|
|
5
|
+
</div>
|
|
6
|
+
|
|
7
|
+
<button onclick='window.testone()'>Test one</button>
|
|
8
|
+
<button onclick='window.testtwo()'>Test two</button>
|
|
9
|
+
|
|
10
|
+
<script type="module">
|
|
11
|
+
window.testone = () => {
|
|
12
|
+
const testone = [
|
|
13
|
+
{ name: 'myname', value: 'myvalue' },
|
|
14
|
+
{ name: 'myname2', value: 'myvalue2' },
|
|
15
|
+
]
|
|
16
|
+
state.akey = testone
|
|
17
|
+
}
|
|
18
|
+
window.testtwo = () => {
|
|
19
|
+
const testt = {
|
|
20
|
+
"k1": { name: 'myname3', value: 'myvalue3' },
|
|
21
|
+
"k2": { name: 'myname4', value: 'myvalue4' },
|
|
22
|
+
}
|
|
23
|
+
state.akey = testt
|
|
24
|
+
}
|
|
25
|
+
</script>
|
package/test-js.html
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
<script src='components.js'></script>
|
|
3
|
+
<script src='enigmatic.js'></script>
|
|
4
|
+
|
|
5
|
+
<div id="counter" data="count" value="0">{value}</div>
|
|
6
|
+
<button onclick="state.count++">Incr</button>
|
|
7
|
+
|
|
8
|
+
<div id='div1' data="users" fetch="randomuser.me/api" value='{"results": [ {"name": {"first": "set", "last": "me"}} ]}'>
|
|
9
|
+
{results[0].name.first} {results[0].name.last}
|
|
10
|
+
</div>
|
|
11
|
+
|
|
12
|
+
<button onclick='state.users = {"results": [ {"name": {"first": "first", "last": "last"} }]}'>Set user</button>
|
|
13
|
+
<button onclick="div1.fetch()">Fetch user</button>
|
|
14
|
+
|
|
15
|
+
<div id='div2' data="users2" fetch="randomuser.me/api" immediate>
|
|
16
|
+
<div>{results[0].name.first} {results[0].name.last}</div>
|
|
17
|
+
</div>
|
|
18
|
+
|
|
19
|
+
<div id='div3' data="users2">
|
|
20
|
+
<div>{results[0].name.first} {results[0].name.last}</div>
|
|
21
|
+
</div>
|
|
22
|
+
|
|
23
|
+
<random-users data="users"></random-users>
|
|
24
|
+
<tailwind-example></tailwind-example>
|
package/test-layout.html
ADDED
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
<link rel=stylesheet href=enigmatic.css>
|
|
2
|
+
|
|
3
|
+
<body style="--cols:1fr 1fr 1fr 10fr; --rows:1fr 10fr">
|
|
4
|
+
<div class="bg-red" style="--span:2">Hello</div>
|
|
5
|
+
<div class="bg-green"></div>
|
|
6
|
+
<div class="bg-yellow"></div>
|
|
7
|
+
<div class="bg-blue"></div>
|
|
8
|
+
<div class="bg-red"></div>
|
|
9
|
+
<div class="bg-green"></div>
|
|
10
|
+
<div class="bg-yellow"></div>
|
|
11
|
+
<div class="bg-blue"></div>
|
|
12
|
+
<div class="bg-red"></div>
|
|
13
|
+
</body>
|
package/test-schema.html
ADDED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<!DOCTYPE html>
|
|
2
|
+
|
|
3
|
+
<script src=enigmatic.js></script>
|
|
4
|
+
<script type=module src=https://unpkg.com/e-schema@0.0.2/module.mjs></script>
|
|
5
|
+
|
|
6
|
+
<script type="module">
|
|
7
|
+
const es = new eSchema({MyType: {message: 'string'}})
|
|
8
|
+
es.validate({message: 'you are'}, 'MyType')
|
|
9
|
+
save(es.schema, 'myschema')
|
|
10
|
+
console.log(load('myschema'))
|
|
11
|
+
console.log(load('nothing'))
|
|
12
|
+
</script>
|
package/test.mjs
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
// wsl install:
|
|
2
|
+
// wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
|
|
3
|
+
// sudo apt - y install./ google - chrome - stable_current_amd64.deb
|
|
4
|
+
|
|
5
|
+
import puppeteer from 'puppeteer'
|
|
6
|
+
import { te, tde, tm, wait } from 'instax'
|
|
7
|
+
const host = 'http://127.0.0.1:8080'
|
|
8
|
+
|
|
9
|
+
const browser = await puppeteer.launch({ headless: true })
|
|
10
|
+
const page = await browser.newPage()
|
|
11
|
+
await page.goto(`${host}/test.html`, {
|
|
12
|
+
waitUntil: 'networkidle2',
|
|
13
|
+
timeout: 5000
|
|
14
|
+
})
|
|
15
|
+
|
|
16
|
+
const e = (await page.evaluate("enigmatic"))
|
|
17
|
+
tm(e.version, /0.11.1/)
|
|
18
|
+
tm(await page.evaluate("$('#div1').template"), /results/)
|
|
19
|
+
|
|
20
|
+
// get
|
|
21
|
+
// state
|
|
22
|
+
// div
|
|
23
|
+
// custom
|
|
24
|
+
await wait(2000)
|
|
25
|
+
await page.close()
|
|
26
|
+
await browser.close()
|
package/index.html
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
<script src='enigmatic.js'></script>
|
|
2
|
-
|
|
3
|
-
<div id='tests'></div>
|
|
4
|
-
|
|
5
|
-
<script type='module'>
|
|
6
|
-
|
|
7
|
-
element('my-custom', data=>data.myvalue, '<div>${o.mykey}</div>')
|
|
8
|
-
const e = document.createElement('my-custom')
|
|
9
|
-
e.setAttribute('data', 'mydata')
|
|
10
|
-
|
|
11
|
-
state('mydata', {myvalue: 'my value'})
|
|
12
|
-
|
|
13
|
-
await get('', null, data=>data.myvalue, 'my-fetched-data')
|
|
14
|
-
state('my-fetched-data')
|
|
15
|
-
|
|
16
|
-
await stream('', 'my-streamed-data')
|
|
17
|
-
state('my-streamed-data')
|
|
18
|
-
|
|
19
|
-
</script>
|