enigmatic 0.10.3 → 0.11.0
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/README.md +0 -0
- package/components.js +16 -18
- package/enigmatic.css +246 -246
- package/enigmatic.js +157 -150
- package/index.html +18 -9
- package/package.json +4 -4
package/README.md
ADDED
|
File without changes
|
package/components.js
CHANGED
|
@@ -1,18 +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
|
-
}
|
|
17
|
-
|
|
18
|
-
console.log('components.mjs', components)
|
|
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,247 @@
|
|
|
1
|
-
body {
|
|
2
|
-
font-family: var(--font-primary, -apple-system, BlinkMacSystemFont, sans-serif);
|
|
3
|
-
height: 100vh;
|
|
4
|
-
background-color: var(--bg-color, #fff);
|
|
5
|
-
padding: .5rem;
|
|
6
|
-
}
|
|
7
|
-
|
|
8
|
-
body,
|
|
9
|
-
section {
|
|
10
|
-
display: grid;
|
|
11
|
-
margin: 0;
|
|
12
|
-
grid-template-columns: var(--cols, 1fr 4fr 1fr);
|
|
13
|
-
grid-template-rows: var(--rows, 1fr 9fr 1fr);
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
* {
|
|
17
|
-
grid-column: span var(--span, 1);
|
|
18
|
-
grid-row: span var(--span-rows, 1);
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
.flex {
|
|
22
|
-
display: flex;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/** positioning ***/
|
|
26
|
-
|
|
27
|
-
.center {
|
|
28
|
-
position: fixed;
|
|
29
|
-
top: 50%;
|
|
30
|
-
left: 50%;
|
|
31
|
-
margin-top: -50px;
|
|
32
|
-
margin-left: -100px;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
.right {
|
|
36
|
-
float: right;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
.left {
|
|
40
|
-
float: left;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
.fixed {
|
|
44
|
-
position: fixed;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
.top {
|
|
48
|
-
top: 0;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
.bottom { bottom: 0 }
|
|
52
|
-
|
|
53
|
-
.fill { height: 100vh; width: 100wh }
|
|
54
|
-
|
|
55
|
-
.hide {
|
|
56
|
-
opacity: 0;
|
|
57
|
-
transition: opacity 0.25s linear;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
.show {
|
|
61
|
-
opacity: 1;
|
|
62
|
-
transition: opacity 0.25s linear;
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
.slide-in {
|
|
66
|
-
animation: slide-in 0.1s forwards;
|
|
67
|
-
-webkit-animation: slide-in 0.1s forwards;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
.slide-out {
|
|
71
|
-
animation: slide-out 0.1s forwards;
|
|
72
|
-
-webkit-animation: slide-out 0.1s forwards;
|
|
73
|
-
}
|
|
74
|
-
|
|
75
|
-
@keyframes slide-in {
|
|
76
|
-
100% {
|
|
77
|
-
transform: translateX(0%);
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
@-webkit-keyframes slide-in {
|
|
82
|
-
100% {
|
|
83
|
-
-webkit-transform: translateX(0%);
|
|
84
|
-
}
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
@keyframes slide-out {
|
|
88
|
-
0% {
|
|
89
|
-
transform: translateX(0%);
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
100% {
|
|
93
|
-
transform: translateX(-100%);
|
|
94
|
-
}
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
@-webkit-keyframes slide-out {
|
|
98
|
-
0% {
|
|
99
|
-
-webkit-transform: translateX(0%);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
100% {
|
|
103
|
-
-webkit-transform: translateX(-100%);
|
|
104
|
-
}
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
a {
|
|
108
|
-
text-decoration: none;
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
.shadow {
|
|
112
|
-
box-shadow: 6px 6px 6px #dbdbdb;
|
|
113
|
-
}
|
|
114
|
-
|
|
115
|
-
.cursor {
|
|
116
|
-
cursor: default;
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
.margins {
|
|
120
|
-
margin: var(--margins, 15px);
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
.padding {
|
|
124
|
-
padding: var(--padding, 15px);
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
.rem {
|
|
128
|
-
font-size: var(--rem, 2rem);
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
.faded {
|
|
132
|
-
opacity: 0.5;
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
.fade {
|
|
136
|
-
opacity: 1;
|
|
137
|
-
transition: opacity 0.25s ease-in-out;
|
|
138
|
-
-moz-transition: opacity 0.25s ease-in-out;
|
|
139
|
-
-webkit-transition: opacity 0.25s ease-in-out;
|
|
140
|
-
}
|
|
141
|
-
|
|
142
|
-
.fade:hover {
|
|
143
|
-
opacity: 0.5;
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
.unfade {
|
|
147
|
-
opacity: 0.5;
|
|
148
|
-
transition: opacity 0.25s ease-in-out;
|
|
149
|
-
-moz-transition: opacity 0.25s ease-in-out;
|
|
150
|
-
-webkit-transition: opacity 0.25s ease-in-out;
|
|
151
|
-
}
|
|
152
|
-
|
|
153
|
-
.unfade:hover {
|
|
154
|
-
opacity: 1;
|
|
155
|
-
}
|
|
156
|
-
|
|
157
|
-
.rounded {
|
|
158
|
-
-moz-border-radius: 10px;
|
|
159
|
-
-webkit-border-radius: 10px;
|
|
160
|
-
border-radius: 10px;
|
|
161
|
-
-khtml-border-radius: 10px;
|
|
162
|
-
}
|
|
163
|
-
|
|
164
|
-
.round {
|
|
165
|
-
vertical-align: middle;
|
|
166
|
-
width: 50px;
|
|
167
|
-
height: 50px;
|
|
168
|
-
border-radius: 50%;
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
/** html elements **/
|
|
172
|
-
|
|
173
|
-
canvas {
|
|
174
|
-
position: fixed;
|
|
175
|
-
top: 0;
|
|
176
|
-
left: 0;
|
|
177
|
-
}
|
|
178
|
-
|
|
179
|
-
ul {
|
|
180
|
-
list-style-type: none;
|
|
181
|
-
border: 20px;
|
|
182
|
-
padding: 20px;
|
|
183
|
-
width: 50%;
|
|
184
|
-
}
|
|
185
|
-
|
|
186
|
-
li {
|
|
187
|
-
list-style-type: none;
|
|
188
|
-
border: 10px;
|
|
189
|
-
padding: 10px;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
li:hover {
|
|
193
|
-
background-color: rgb(243, 241, 241);
|
|
194
|
-
cursor: pointer;
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
.opacity1 {
|
|
198
|
-
opacity: .1
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
.opacity2 {
|
|
202
|
-
opacity: .2
|
|
203
|
-
}
|
|
204
|
-
|
|
205
|
-
.opacity3 {
|
|
206
|
-
opacity: .3
|
|
207
|
-
}
|
|
208
|
-
|
|
209
|
-
.opacity4 {
|
|
210
|
-
opacity: .4
|
|
211
|
-
}
|
|
212
|
-
|
|
213
|
-
.opacity5 {
|
|
214
|
-
opacity: .5
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
.opacity6 {
|
|
218
|
-
opacity: .6
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
.opacity7 {
|
|
222
|
-
opacity: .7
|
|
223
|
-
}
|
|
224
|
-
|
|
225
|
-
.opacity8 {
|
|
226
|
-
opacity: .8
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
.opacity9 {
|
|
230
|
-
opacity: .9
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
.bg-red {
|
|
234
|
-
background-color: red;
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
.bg-blue {
|
|
238
|
-
background-color: blue;
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
.bg-yellow {
|
|
242
|
-
background-color: yellow;
|
|
243
|
-
}
|
|
244
|
-
|
|
245
|
-
.bg-green {
|
|
246
|
-
background-color: green;
|
|
1
|
+
body {
|
|
2
|
+
font-family: var(--font-primary, -apple-system, BlinkMacSystemFont, sans-serif);
|
|
3
|
+
height: 100vh;
|
|
4
|
+
background-color: var(--bg-color, #fff);
|
|
5
|
+
padding: .5rem;
|
|
6
|
+
}
|
|
7
|
+
|
|
8
|
+
body,
|
|
9
|
+
section {
|
|
10
|
+
display: grid;
|
|
11
|
+
margin: 0;
|
|
12
|
+
grid-template-columns: var(--cols, 1fr 4fr 1fr);
|
|
13
|
+
grid-template-rows: var(--rows, 1fr 9fr 1fr);
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
* {
|
|
17
|
+
grid-column: span var(--span, 1);
|
|
18
|
+
grid-row: span var(--span-rows, 1);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.flex {
|
|
22
|
+
display: flex;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** positioning ***/
|
|
26
|
+
|
|
27
|
+
.center {
|
|
28
|
+
position: fixed;
|
|
29
|
+
top: 50%;
|
|
30
|
+
left: 50%;
|
|
31
|
+
margin-top: -50px;
|
|
32
|
+
margin-left: -100px;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
.right {
|
|
36
|
+
float: right;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
.left {
|
|
40
|
+
float: left;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
.fixed {
|
|
44
|
+
position: fixed;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
.top {
|
|
48
|
+
top: 0;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
.bottom { bottom: 0 }
|
|
52
|
+
|
|
53
|
+
.fill { height: 100vh; width: 100wh }
|
|
54
|
+
|
|
55
|
+
.hide {
|
|
56
|
+
opacity: 0;
|
|
57
|
+
transition: opacity 0.25s linear;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
.show {
|
|
61
|
+
opacity: 1;
|
|
62
|
+
transition: opacity 0.25s linear;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
.slide-in {
|
|
66
|
+
animation: slide-in 0.1s forwards;
|
|
67
|
+
-webkit-animation: slide-in 0.1s forwards;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
.slide-out {
|
|
71
|
+
animation: slide-out 0.1s forwards;
|
|
72
|
+
-webkit-animation: slide-out 0.1s forwards;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
@keyframes slide-in {
|
|
76
|
+
100% {
|
|
77
|
+
transform: translateX(0%);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
@-webkit-keyframes slide-in {
|
|
82
|
+
100% {
|
|
83
|
+
-webkit-transform: translateX(0%);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
@keyframes slide-out {
|
|
88
|
+
0% {
|
|
89
|
+
transform: translateX(0%);
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
100% {
|
|
93
|
+
transform: translateX(-100%);
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
@-webkit-keyframes slide-out {
|
|
98
|
+
0% {
|
|
99
|
+
-webkit-transform: translateX(0%);
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
100% {
|
|
103
|
+
-webkit-transform: translateX(-100%);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
a {
|
|
108
|
+
text-decoration: none;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
.shadow {
|
|
112
|
+
box-shadow: 6px 6px 6px #dbdbdb;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
.cursor {
|
|
116
|
+
cursor: default;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
.margins {
|
|
120
|
+
margin: var(--margins, 15px);
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
.padding {
|
|
124
|
+
padding: var(--padding, 15px);
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
.rem {
|
|
128
|
+
font-size: var(--rem, 2rem);
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
.faded {
|
|
132
|
+
opacity: 0.5;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
.fade {
|
|
136
|
+
opacity: 1;
|
|
137
|
+
transition: opacity 0.25s ease-in-out;
|
|
138
|
+
-moz-transition: opacity 0.25s ease-in-out;
|
|
139
|
+
-webkit-transition: opacity 0.25s ease-in-out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.fade:hover {
|
|
143
|
+
opacity: 0.5;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
.unfade {
|
|
147
|
+
opacity: 0.5;
|
|
148
|
+
transition: opacity 0.25s ease-in-out;
|
|
149
|
+
-moz-transition: opacity 0.25s ease-in-out;
|
|
150
|
+
-webkit-transition: opacity 0.25s ease-in-out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
.unfade:hover {
|
|
154
|
+
opacity: 1;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
.rounded {
|
|
158
|
+
-moz-border-radius: 10px;
|
|
159
|
+
-webkit-border-radius: 10px;
|
|
160
|
+
border-radius: 10px;
|
|
161
|
+
-khtml-border-radius: 10px;
|
|
162
|
+
}
|
|
163
|
+
|
|
164
|
+
.round {
|
|
165
|
+
vertical-align: middle;
|
|
166
|
+
width: 50px;
|
|
167
|
+
height: 50px;
|
|
168
|
+
border-radius: 50%;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
/** html elements **/
|
|
172
|
+
|
|
173
|
+
canvas {
|
|
174
|
+
position: fixed;
|
|
175
|
+
top: 0;
|
|
176
|
+
left: 0;
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
ul {
|
|
180
|
+
list-style-type: none;
|
|
181
|
+
border: 20px;
|
|
182
|
+
padding: 20px;
|
|
183
|
+
width: 50%;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
li {
|
|
187
|
+
list-style-type: none;
|
|
188
|
+
border: 10px;
|
|
189
|
+
padding: 10px;
|
|
190
|
+
}
|
|
191
|
+
|
|
192
|
+
li:hover {
|
|
193
|
+
background-color: rgb(243, 241, 241);
|
|
194
|
+
cursor: pointer;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
.opacity1 {
|
|
198
|
+
opacity: .1
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
.opacity2 {
|
|
202
|
+
opacity: .2
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
.opacity3 {
|
|
206
|
+
opacity: .3
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
.opacity4 {
|
|
210
|
+
opacity: .4
|
|
211
|
+
}
|
|
212
|
+
|
|
213
|
+
.opacity5 {
|
|
214
|
+
opacity: .5
|
|
215
|
+
}
|
|
216
|
+
|
|
217
|
+
.opacity6 {
|
|
218
|
+
opacity: .6
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
.opacity7 {
|
|
222
|
+
opacity: .7
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
.opacity8 {
|
|
226
|
+
opacity: .8
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
.opacity9 {
|
|
230
|
+
opacity: .9
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
.bg-red {
|
|
234
|
+
background-color: red;
|
|
235
|
+
}
|
|
236
|
+
|
|
237
|
+
.bg-blue {
|
|
238
|
+
background-color: blue;
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
.bg-yellow {
|
|
242
|
+
background-color: yellow;
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
.bg-green {
|
|
246
|
+
background-color: green;
|
|
247
247
|
}
|
package/enigmatic.js
CHANGED
|
@@ -1,150 +1,157 @@
|
|
|
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
|
-
|
|
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
|
-
}
|
|
1
|
+
/*
|
|
2
|
+
enigmatic v 0.11.0 front end js utils
|
|
3
|
+
|
|
4
|
+
Usage:
|
|
5
|
+
<div id='mykey' transform='func1' fetch='some.site/data' immediate>${name} ${value}</div>
|
|
6
|
+
<div id='mykey2' transform='func2' stream='some.site/data'>${name} ${value}</div>
|
|
7
|
+
|
|
8
|
+
$('selector')
|
|
9
|
+
$$('selector')
|
|
10
|
+
await loadJS('sounds.js')
|
|
11
|
+
await loadCSS('enigmatic.css')
|
|
12
|
+
await wait(1000)
|
|
13
|
+
await ready()
|
|
14
|
+
beep()
|
|
15
|
+
element(beforeData=>beforeData.field, '<div>${o.mykey}</div>')
|
|
16
|
+
window.components
|
|
17
|
+
state
|
|
18
|
+
await get
|
|
19
|
+
await stream
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
const w = {},
|
|
23
|
+
d = document
|
|
24
|
+
|
|
25
|
+
/////// Helpers
|
|
26
|
+
|
|
27
|
+
w.$ = d.querySelector.bind(d)
|
|
28
|
+
w.$$ = d.querySelectorAll.bind(d)
|
|
29
|
+
w.loadJS = (src) => {
|
|
30
|
+
return new Promise((r, j) => {
|
|
31
|
+
if ($(`script[src="${src}"]`)) return r(true)
|
|
32
|
+
const s = d.createElement('script')
|
|
33
|
+
s.src = src
|
|
34
|
+
s.addEventListener('load', r)
|
|
35
|
+
d.head.appendChild(s)
|
|
36
|
+
})
|
|
37
|
+
}
|
|
38
|
+
w.loadCSS = (src) => {
|
|
39
|
+
return new Promise((r, j) => {
|
|
40
|
+
const s = document.createElement('link')
|
|
41
|
+
s.rel = 'stylesheet'
|
|
42
|
+
s.href = src
|
|
43
|
+
s.addEventListener('load', r)
|
|
44
|
+
d.head.appendChild(s)
|
|
45
|
+
})
|
|
46
|
+
}
|
|
47
|
+
w.wait = (ms) => new Promise((r) => setTimeout(r, ms))
|
|
48
|
+
w.ready = async () => {
|
|
49
|
+
return new Promise((r) => {
|
|
50
|
+
if (document.readyState === 'complete') r(true)
|
|
51
|
+
document.onreadystatechange = () => {
|
|
52
|
+
if (document.readyState === 'complete') r()
|
|
53
|
+
}
|
|
54
|
+
})
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/////// Custom element
|
|
58
|
+
|
|
59
|
+
w.element = (
|
|
60
|
+
name,
|
|
61
|
+
{ onMount = x => x, beforeData = (x) => x, style, template = '' }
|
|
62
|
+
) => {
|
|
63
|
+
customElements.define(
|
|
64
|
+
name,
|
|
65
|
+
class extends HTMLElement {
|
|
66
|
+
connectedCallback(props) {
|
|
67
|
+
onMount(this)
|
|
68
|
+
if (style) {
|
|
69
|
+
const s = document.createElement('style')
|
|
70
|
+
s.innerHTML = `${name} {${style}}`
|
|
71
|
+
d.body.appendChild(s)
|
|
72
|
+
}
|
|
73
|
+
this.template = template
|
|
74
|
+
if (!this.template.match('{')) this.innerHTML = this.template
|
|
75
|
+
}
|
|
76
|
+
set(o) {
|
|
77
|
+
this.innerHTML = ''
|
|
78
|
+
o = beforeData(o)
|
|
79
|
+
if (!Array.isArray(o)) o = [o]
|
|
80
|
+
const m = new Function('o', 'return `' + this.template + '`')
|
|
81
|
+
o.map((i) => (this.innerHTML += m(i)))
|
|
82
|
+
return true
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
)
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
if (window.components) {
|
|
89
|
+
for (let name in window.components) w.element(name, window.components[name])
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
/////// State, data, and reactivity
|
|
93
|
+
|
|
94
|
+
w.state = (key, data) => {
|
|
95
|
+
if (!key && !data)
|
|
96
|
+
return localStorage.clear()
|
|
97
|
+
if (data) {
|
|
98
|
+
const stored_data = { when: new Date().toISOString(), data: data }
|
|
99
|
+
localStorage.setItem(key, JSON.stringify(stored_data))
|
|
100
|
+
for (const e of $$(`[data*=${key}]`)) e.set(stored_data.data)
|
|
101
|
+
return stored_data
|
|
102
|
+
}
|
|
103
|
+
return JSON.parse(localStorage.getItem(key))
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
w.get = async (
|
|
107
|
+
url,
|
|
108
|
+
options = null,
|
|
109
|
+
transform = null,
|
|
110
|
+
key = 'temp'
|
|
111
|
+
) => {
|
|
112
|
+
let data = await (await fetch(`https://${url}`, options)).json()
|
|
113
|
+
if (transform) data = transform(data)
|
|
114
|
+
state(key, data)
|
|
115
|
+
return data
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
w.stream = async (url, key) => {
|
|
119
|
+
const ev = new EventSource(url)
|
|
120
|
+
ev.onmessage = (ev) => {
|
|
121
|
+
const data = JSON.parse(ev.data)
|
|
122
|
+
state(key, data)
|
|
123
|
+
return data
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/////// Startup
|
|
128
|
+
|
|
129
|
+
w.start = async () => {
|
|
130
|
+
await w.ready();
|
|
131
|
+
[...$$('div')].map((e) => {
|
|
132
|
+
e.pr = {};
|
|
133
|
+
[...e.attributes].map((a) => (e.pr[a.name] = a.value))
|
|
134
|
+
if (e.pr.fetch) e.fetch = w.get.bind(null, e.pr.fetch, null, window[e.pr.transform], e.id)
|
|
135
|
+
if ('immediate' in e.pr) e.fetch()
|
|
136
|
+
if (e.pr.stream) e.stream = w.stream.bind(null, e.pr.stream, null, window[e.pr.transform], e.id)
|
|
137
|
+
if (e.pr.data) {
|
|
138
|
+
if (e.innerHTML && e.innerHTML.includes('{')) {
|
|
139
|
+
e.template = e.innerHTML.replaceAll('{', '${')
|
|
140
|
+
e.innerHTML = ''
|
|
141
|
+
}
|
|
142
|
+
e.set = (o) => {
|
|
143
|
+
e.innerHTML = ''
|
|
144
|
+
if (!Array.isArray(o)) o = [o]
|
|
145
|
+
const m = new Function('o', 'return `' + e.template + '`')
|
|
146
|
+
o.map((i) => (e.innerHTML += m(i)))
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
})
|
|
150
|
+
}
|
|
151
|
+
|
|
152
|
+
w.enigmatic = { version: '2022-07-24 0.11.0' }
|
|
153
|
+
Object.assign(window, w);
|
|
154
|
+
|
|
155
|
+
(async () => {
|
|
156
|
+
await w.start()
|
|
157
|
+
})()
|
package/index.html
CHANGED
|
@@ -1,10 +1,19 @@
|
|
|
1
|
-
<script src='
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
+
|
|
10
19
|
</script>
|
package/package.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "enigmatic",
|
|
3
|
-
"main": "enigmatic.js",
|
|
4
|
-
"version": "0.
|
|
1
|
+
{
|
|
2
|
+
"name": "enigmatic",
|
|
3
|
+
"main": "enigmatic.js",
|
|
4
|
+
"version": "0.11.0"
|
|
5
5
|
}
|