vaderjs 1.3.3 → 1.3.4
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/create-vader-app/example_proj/dist/vaderjs/index.js +5 -0
- package/create-vader-app/example_proj/dist/vaderjs/vader-min.js +1115 -0
- package/create-vader-app/example_proj/dist/vaderjs/vaderRouter-min.js +1 -0
- package/create-vader-app/example_proj/dist/vaderjs/worker.js +327 -0
- package/create-vader-app/example_proj/index.html +20 -0
- package/create-vader-app/example_proj/readme.md +2 -0
- package/create-vader-app/example_proj/src/pages/Index.js +13 -0
- package/create-vader-app/example_proj/src/views/app.html +16 -0
- package/create-vader-app/index.js +20 -0
- package/create-vader-app/node_modules/.package-lock.json +350 -0
- package/create-vader-app/node_modules/chalk/license +9 -0
- package/create-vader-app/node_modules/chalk/package.json +83 -0
- package/create-vader-app/node_modules/chalk/readme.md +325 -0
- package/create-vader-app/node_modules/chalk/source/index.d.ts +320 -0
- package/create-vader-app/node_modules/chalk/source/index.js +225 -0
- package/create-vader-app/node_modules/chalk/source/utilities.js +33 -0
- package/create-vader-app/node_modules/chalk/source/vendor/ansi-styles/index.d.ts +236 -0
- package/create-vader-app/node_modules/chalk/source/vendor/ansi-styles/index.js +223 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/browser.d.ts +1 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/browser.js +30 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/index.d.ts +55 -0
- package/create-vader-app/node_modules/chalk/source/vendor/supports-color/index.js +182 -0
- package/create-vader-app/node_modules/commander/LICENSE +22 -0
- package/create-vader-app/node_modules/commander/Readme.md +1146 -0
- package/create-vader-app/node_modules/commander/esm.mjs +16 -0
- package/create-vader-app/node_modules/commander/index.js +27 -0
- package/create-vader-app/node_modules/commander/lib/argument.js +147 -0
- package/create-vader-app/node_modules/commander/lib/command.js +2196 -0
- package/create-vader-app/node_modules/commander/lib/error.js +45 -0
- package/create-vader-app/node_modules/commander/lib/help.js +464 -0
- package/create-vader-app/node_modules/commander/lib/option.js +331 -0
- package/create-vader-app/node_modules/commander/lib/suggestSimilar.js +100 -0
- package/create-vader-app/node_modules/commander/package-support.json +16 -0
- package/create-vader-app/node_modules/commander/package.json +90 -0
- package/create-vader-app/node_modules/commander/typings/esm.d.mts +3 -0
- package/create-vader-app/node_modules/commander/typings/index.d.ts +889 -0
- package/create-vader-app/node_modules/fs-extra/LICENSE +15 -0
- package/create-vader-app/node_modules/fs-extra/README.md +292 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/copy-sync.js +161 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/copy.js +238 -0
- package/create-vader-app/node_modules/fs-extra/lib/copy/index.js +7 -0
- package/create-vader-app/node_modules/fs-extra/lib/empty/index.js +39 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/file.js +69 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/index.js +23 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/link.js +64 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink-paths.js +99 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink-type.js +31 -0
- package/create-vader-app/node_modules/fs-extra/lib/ensure/symlink.js +82 -0
- package/create-vader-app/node_modules/fs-extra/lib/esm.mjs +68 -0
- package/create-vader-app/node_modules/fs-extra/lib/fs/index.js +140 -0
- package/create-vader-app/node_modules/fs-extra/lib/index.js +16 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/index.js +16 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/jsonfile.js +11 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/output-json-sync.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/json/output-json.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/index.js +14 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/make-dir.js +27 -0
- package/create-vader-app/node_modules/fs-extra/lib/mkdirs/utils.js +21 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/index.js +7 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/move-sync.js +55 -0
- package/create-vader-app/node_modules/fs-extra/lib/move/move.js +76 -0
- package/create-vader-app/node_modules/fs-extra/lib/output-file/index.js +40 -0
- package/create-vader-app/node_modules/fs-extra/lib/path-exists/index.js +12 -0
- package/create-vader-app/node_modules/fs-extra/lib/remove/index.js +17 -0
- package/create-vader-app/node_modules/fs-extra/lib/util/stat.js +154 -0
- package/create-vader-app/node_modules/fs-extra/lib/util/utimes.js +26 -0
- package/create-vader-app/node_modules/fs-extra/package.json +71 -0
- package/create-vader-app/node_modules/graceful-fs/LICENSE +15 -0
- package/create-vader-app/node_modules/graceful-fs/README.md +143 -0
- package/create-vader-app/node_modules/graceful-fs/clone.js +23 -0
- package/create-vader-app/node_modules/graceful-fs/graceful-fs.js +448 -0
- package/create-vader-app/node_modules/graceful-fs/legacy-streams.js +118 -0
- package/create-vader-app/node_modules/graceful-fs/package.json +53 -0
- package/create-vader-app/node_modules/graceful-fs/polyfills.js +355 -0
- package/create-vader-app/node_modules/inherits/LICENSE +16 -0
- package/create-vader-app/node_modules/inherits/README.md +42 -0
- package/create-vader-app/node_modules/inherits/inherits.js +7 -0
- package/create-vader-app/node_modules/inherits/inherits_browser.js +23 -0
- package/create-vader-app/node_modules/inherits/package.json +29 -0
- package/create-vader-app/node_modules/jsonfile/CHANGELOG.md +171 -0
- package/create-vader-app/node_modules/jsonfile/LICENSE +15 -0
- package/create-vader-app/node_modules/jsonfile/README.md +230 -0
- package/create-vader-app/node_modules/jsonfile/index.js +88 -0
- package/create-vader-app/node_modules/jsonfile/package.json +40 -0
- package/create-vader-app/node_modules/jsonfile/utils.js +14 -0
- package/create-vader-app/node_modules/path/LICENSE +18 -0
- package/create-vader-app/node_modules/path/README.md +15 -0
- package/create-vader-app/node_modules/path/package.json +24 -0
- package/create-vader-app/node_modules/path/path.js +628 -0
- package/create-vader-app/node_modules/process/.eslintrc +21 -0
- package/create-vader-app/node_modules/process/LICENSE +22 -0
- package/create-vader-app/node_modules/process/README.md +26 -0
- package/create-vader-app/node_modules/process/browser.js +184 -0
- package/create-vader-app/node_modules/process/index.js +2 -0
- package/create-vader-app/node_modules/process/package.json +27 -0
- package/create-vader-app/node_modules/process/test.js +199 -0
- package/create-vader-app/node_modules/universalify/LICENSE +20 -0
- package/create-vader-app/node_modules/universalify/README.md +76 -0
- package/create-vader-app/node_modules/universalify/index.js +24 -0
- package/create-vader-app/node_modules/universalify/package.json +34 -0
- package/create-vader-app/node_modules/util/LICENSE +18 -0
- package/create-vader-app/node_modules/util/README.md +15 -0
- package/create-vader-app/node_modules/util/package.json +35 -0
- package/create-vader-app/node_modules/util/support/isBuffer.js +3 -0
- package/create-vader-app/node_modules/util/support/isBufferBrowser.js +6 -0
- package/create-vader-app/node_modules/util/util.js +586 -0
- package/create-vader-app/package-lock.json +384 -0
- package/create-vader-app/package.json +18 -0
- package/package.json +1 -1
- package/vader-min.js +1 -1
- package/vader.js +4 -4
- package/worker-min.js +1 -1
- package/worker.js +49 -24
|
@@ -0,0 +1,384 @@
|
|
|
1
|
+
{
|
|
2
|
+
|
|
3
|
+
"name": "create-vader-app",
|
|
4
|
+
|
|
5
|
+
"lockfileVersion": 3,
|
|
6
|
+
|
|
7
|
+
"requires": true,
|
|
8
|
+
|
|
9
|
+
"packages": {
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
"": {
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
|
|
16
|
+
"dependencies": {
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
"chalk": "^5.3.0",
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
"commander": "^11.0.0",
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
"fs-extra": "^11.1.1",
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
"path": "^0.12.7"
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
|
|
43
|
+
},
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
"node_modules/chalk": {
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
"version": "5.3.0",
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
"resolved": "https://registry.npmjs.org/chalk/-/chalk-5.3.0.tgz",
|
|
55
|
+
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
"integrity": "sha512-dLitG79d+GV1Nb/VYcCDFivJeK1hiukt9QjRNVOsUtTy1rR1YJsmpGGTZ3qJos+uw7WmWF4wUwBd9jxjocFC2w==",
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
"engines": {
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
"node": "^12.17.0 || ^14.13 || >=16.0.0"
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
|
|
71
|
+
},
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
"funding": {
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
"url": "https://github.com/chalk/chalk?sponsor=1"
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
},
|
|
88
|
+
|
|
89
|
+
|
|
90
|
+
"node_modules/commander": {
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
"version": "11.0.0",
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
"resolved": "https://registry.npmjs.org/commander/-/commander-11.0.0.tgz",
|
|
99
|
+
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
"integrity": "sha512-9HMlXtt/BNoYr8ooyjjNRdIilOTkVJXB+GhxMTtOKwk0R4j4lS4NpjuqmRxroBfnfTSHQIHQB7wryHhXarNjmQ==",
|
|
103
|
+
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
"engines": {
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
|
|
110
|
+
|
|
111
|
+
"node": ">=16"
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
},
|
|
119
|
+
|
|
120
|
+
|
|
121
|
+
"node_modules/fs-extra": {
|
|
122
|
+
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
"version": "11.1.1",
|
|
126
|
+
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
"resolved": "https://registry.npmjs.org/fs-extra/-/fs-extra-11.1.1.tgz",
|
|
130
|
+
|
|
131
|
+
|
|
132
|
+
|
|
133
|
+
"integrity": "sha512-MGIE4HOvQCeUCzmlHs0vXpih4ysz4wg9qiSAu6cd42lVwPbTM1TjV7RusoyQqMmk/95gdQZX72u+YW+c3eEpFQ==",
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
|
|
137
|
+
"dependencies": {
|
|
138
|
+
|
|
139
|
+
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
"graceful-fs": "^4.2.0",
|
|
143
|
+
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
|
|
147
|
+
"jsonfile": "^6.0.1",
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
|
|
151
|
+
|
|
152
|
+
"universalify": "^2.0.0"
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
|
|
156
|
+
},
|
|
157
|
+
|
|
158
|
+
|
|
159
|
+
|
|
160
|
+
"engines": {
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
|
|
165
|
+
"node": ">=14.14"
|
|
166
|
+
|
|
167
|
+
|
|
168
|
+
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
|
|
172
|
+
},
|
|
173
|
+
|
|
174
|
+
|
|
175
|
+
"node_modules/graceful-fs": {
|
|
176
|
+
|
|
177
|
+
|
|
178
|
+
|
|
179
|
+
"version": "4.2.11",
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
|
|
183
|
+
"resolved": "https://registry.npmjs.org/graceful-fs/-/graceful-fs-4.2.11.tgz",
|
|
184
|
+
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
"integrity": "sha512-RbJ5/jmFcNNCcDV5o9eTnBLJ/HszWV0P73bc+Ff4nS/rJj+YaS6IGyiOL0VoBYX+l1Wrl3k63h/KrH+nhJ0XvQ=="
|
|
188
|
+
|
|
189
|
+
|
|
190
|
+
},
|
|
191
|
+
|
|
192
|
+
|
|
193
|
+
"node_modules/inherits": {
|
|
194
|
+
|
|
195
|
+
|
|
196
|
+
|
|
197
|
+
"version": "2.0.3",
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
|
|
201
|
+
"resolved": "https://registry.npmjs.org/inherits/-/inherits-2.0.3.tgz",
|
|
202
|
+
|
|
203
|
+
|
|
204
|
+
|
|
205
|
+
"integrity": "sha512-x00IRNXNy63jwGkJmzPigoySHbaqpNuzKbBOmzK+g2OdZpQ9w+sxCN+VSB3ja7IAge2OP2qpfxTjeNcyjmW1uw=="
|
|
206
|
+
|
|
207
|
+
|
|
208
|
+
},
|
|
209
|
+
|
|
210
|
+
|
|
211
|
+
"node_modules/jsonfile": {
|
|
212
|
+
|
|
213
|
+
|
|
214
|
+
|
|
215
|
+
"version": "6.1.0",
|
|
216
|
+
|
|
217
|
+
|
|
218
|
+
|
|
219
|
+
"resolved": "https://registry.npmjs.org/jsonfile/-/jsonfile-6.1.0.tgz",
|
|
220
|
+
|
|
221
|
+
|
|
222
|
+
|
|
223
|
+
"integrity": "sha512-5dgndWOriYSm5cnYaJNhalLNDKOqFwyDB/rr1E9ZsGciGvKPs8R2xYGCacuf3z6K1YKDz182fd+fY3cn3pMqXQ==",
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
|
|
227
|
+
"dependencies": {
|
|
228
|
+
|
|
229
|
+
|
|
230
|
+
|
|
231
|
+
|
|
232
|
+
"universalify": "^2.0.0"
|
|
233
|
+
|
|
234
|
+
|
|
235
|
+
|
|
236
|
+
},
|
|
237
|
+
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
"optionalDependencies": {
|
|
241
|
+
|
|
242
|
+
|
|
243
|
+
|
|
244
|
+
|
|
245
|
+
"graceful-fs": "^4.1.6"
|
|
246
|
+
|
|
247
|
+
|
|
248
|
+
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
|
|
252
|
+
},
|
|
253
|
+
|
|
254
|
+
|
|
255
|
+
"node_modules/path": {
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
|
|
259
|
+
"version": "0.12.7",
|
|
260
|
+
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
"resolved": "https://registry.npmjs.org/path/-/path-0.12.7.tgz",
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
"integrity": "sha512-aXXC6s+1w7otVF9UletFkFcDsJeO7lSZBPUQhtb5O0xJe8LtYhj/GxldoL09bBj9+ZmE2hNoHqQSFMN5fikh4Q==",
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
"dependencies": {
|
|
272
|
+
|
|
273
|
+
|
|
274
|
+
|
|
275
|
+
|
|
276
|
+
"process": "^0.11.1",
|
|
277
|
+
|
|
278
|
+
|
|
279
|
+
|
|
280
|
+
|
|
281
|
+
"util": "^0.10.3"
|
|
282
|
+
|
|
283
|
+
|
|
284
|
+
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
|
|
288
|
+
},
|
|
289
|
+
|
|
290
|
+
|
|
291
|
+
"node_modules/process": {
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
|
|
295
|
+
"version": "0.11.10",
|
|
296
|
+
|
|
297
|
+
|
|
298
|
+
|
|
299
|
+
"resolved": "https://registry.npmjs.org/process/-/process-0.11.10.tgz",
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
|
|
303
|
+
"integrity": "sha512-cdGef/drWFoydD1JsMzuFf8100nZl+GT+yacc2bEced5f9Rjk4z+WtFUTBu9PhOi9j/jfmBPu0mMEY4wIdAF8A==",
|
|
304
|
+
|
|
305
|
+
|
|
306
|
+
|
|
307
|
+
"engines": {
|
|
308
|
+
|
|
309
|
+
|
|
310
|
+
|
|
311
|
+
|
|
312
|
+
"node": ">= 0.6.0"
|
|
313
|
+
|
|
314
|
+
|
|
315
|
+
|
|
316
|
+
}
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
},
|
|
320
|
+
|
|
321
|
+
|
|
322
|
+
"node_modules/universalify": {
|
|
323
|
+
|
|
324
|
+
|
|
325
|
+
|
|
326
|
+
"version": "2.0.0",
|
|
327
|
+
|
|
328
|
+
|
|
329
|
+
|
|
330
|
+
"resolved": "https://registry.npmjs.org/universalify/-/universalify-2.0.0.tgz",
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
|
|
334
|
+
"integrity": "sha512-hAZsKq7Yy11Zu1DE0OzWjw7nnLZmJZYTDZZyEFHZdUhV8FkH5MCfoU1XMaxXovpyW5nq5scPqq0ZDP9Zyl04oQ==",
|
|
335
|
+
|
|
336
|
+
|
|
337
|
+
|
|
338
|
+
"engines": {
|
|
339
|
+
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
|
|
343
|
+
"node": ">= 10.0.0"
|
|
344
|
+
|
|
345
|
+
|
|
346
|
+
|
|
347
|
+
}
|
|
348
|
+
|
|
349
|
+
|
|
350
|
+
},
|
|
351
|
+
|
|
352
|
+
|
|
353
|
+
"node_modules/util": {
|
|
354
|
+
|
|
355
|
+
|
|
356
|
+
|
|
357
|
+
"version": "0.10.4",
|
|
358
|
+
|
|
359
|
+
|
|
360
|
+
|
|
361
|
+
"resolved": "https://registry.npmjs.org/util/-/util-0.10.4.tgz",
|
|
362
|
+
|
|
363
|
+
|
|
364
|
+
|
|
365
|
+
"integrity": "sha512-0Pm9hTQ3se5ll1XihRic3FDIku70C+iHUdT/W926rSgHV5QgXsYbKZN8MSC3tJtSkhuROzvsQjAaFENRXr+19A==",
|
|
366
|
+
|
|
367
|
+
|
|
368
|
+
|
|
369
|
+
"dependencies": {
|
|
370
|
+
|
|
371
|
+
|
|
372
|
+
|
|
373
|
+
|
|
374
|
+
"inherits": "2.0.3"
|
|
375
|
+
|
|
376
|
+
|
|
377
|
+
|
|
378
|
+
}
|
|
379
|
+
|
|
380
|
+
|
|
381
|
+
}
|
|
382
|
+
|
|
383
|
+
}
|
|
384
|
+
}
|
package/package.json
CHANGED
package/vader-min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
let dom=[],states={},worker=new Worker(new URL("./worker.js",import.meta.url));export const useRef=t=>{const e=document.querySelector(`[ref="${t}"]`);return{current:e,update:t=>{const s=(new DOMParser).parseFromString(t,"text/html").body.firstChild;if(e){!s.isEqualNode(e)&&e.parentNode.replaceChild(s,e)}}}};let components=[];export class Component{constructor(){this.states={},this.name=this.constructor.name,this.executedEffects={},this.storedProps={},this.componentMounted=!1,this.hasMounted=!1,this.$_signal_subscribers=[],this.$_signal_subscribers_ran=[],this.effects={},this.$_useStore_subscribers=[],this.init(),this.Componentcontent=null,this.$_signal_dispatch_event=new CustomEvent("SignalDispatch",{detail:{hasUpdated:!1,state:null}}),this.$_signal_dispatch_cleanup_event=new CustomEvent("Signal_Cleanup_Dispatch",{detail:{state:null,lastState:null}}),this.snapshots=[],this.dom=[],this.cfr=!1}adapter(t){}init(){this.registerComponent()}registerComponent(){components.push(this)}setState(t,e){this.states[t]=e,this.updateComponent()}unmount(){this.componentMounted=!1,this.componentWillUnmount(),document.querySelector(`[data-component="${this.name}"]`).remove(),document.querySelector(`[data-component="${this.name}"]`)||(components=components.filter((t=>t.name!==this.name)))}componentUpdate(t,e,s){}componentDidMount(){}componentWillUnmount(){}signal=(t,e)=>{let s=!1,[n,i]=this.useState(t,e,(()=>{if(this.$_signal_subscribers.length>0){for(var t=0;t<this.$_signal_subscribers.length;t++)if(!s){if(this.$_signal_subscribers[t].runonce&&this.$_signal_subscribers_ran.includes(this.$_signal_subscribers[t]))break;return this.$_signal_subscribers[t].function(n),void this.$_signal_subscribers_ran.push(this.$_signal_subscribers[t])}}else this.$_signal_dispatch_event.detail.hasUpdated=!0,this.$_signal_dispatch_event.detail.state=n,window.dispatchEvent(this.$_signal_dispatch_event)}));return this.$_signal_subscribe=(t,e)=>(this.$_signal_subscribers.push({function:t,runonce:e}),t),this.$_signal_cleanup=t=>{this.lastState=n,this.$_signal_subscribers=this.$_signal_subscribers.filter((e=>e.function!==t)),this.$_signal_dispatch_cleanup_event.detail.state=this.states,this.$_signal_dispatch_cleanup_event.detail.lastState=this.lastState,window.dispatchEvent(this.$_signal_dispatch_event)},this.$_signal_dispatch=()=>{for(var t=0;t<this.$_signal_subscribers.length&&(!this.$_signal_subscribers[t].runonce||!this.$_signal_subscribers_ran.includes(this.$_signal_subscribers[t]));t++)this.$_signal_subscribers[t].function(n),this.$_signal_subscribers_ran.push(this.$_signal_subscribers[t])},this.$_signal_get=()=>n,this.$_signal_call=()=>{s=!0,this.$_signal_dispatch()},this.$_signal_set=t=>{i(t)},{subscribe:this.$_signal_subscribe,cleanup:this.$_signal_cleanup,dispatch:this.$_signal_dispatch,call:this.$_signal_call,set:this.$_signal_set,get:this.$_signal_get}};useAuth(t){let e=t.rulesets;if(!e)throw new Error("No rulesets provided");let s=t.user,n={can:t=>{let n=!1;return e.forEach((e=>{e.action===t&&e.condition(s)&&(n=!0)})),n},hasRole:t=>s.role&&s.role.includes(t),canWithRole:(t,e)=>n.can(t)&&n.hasRole(e),assignRule:t=>{e.some((e=>e.action===t.action))||e.push(t)},revokeRule:t=>{e=e.filter((e=>e.action!==t))},canAnyOf:t=>t.some((t=>n.can(t))),canAllOf:t=>t.every((t=>n.can(t))),canGroup:(t,e="any")=>"any"===e?n.canAnyOf(t):n.canAllOf(t)};return n}useReducer(t,e,s){return this.states[t]||(this.states[t]=s),[this.states[t],s=>{this.states[t]=e(this.states[t],s),this.updateComponent()}]}runEffects(){Object.keys(this.effects).forEach((t=>{this.effects[t].forEach((t=>{this.executedEffects[t]||(t(),this.executedEffects[t]=!0)}))}))}useSyncStore(t,e){let[s,n]=this.useState(t,e||localStorage.getItem(`$_vader_${t}`,(e=>{localStorage.setItem(`$_vader_${t}`,JSON.stringify(e)),this.$_useStore_subscribers.forEach((t=>{t(e)}))}))||{});return{getField:t=>s[t],setField:(t,e)=>{const i={...s,[t]:e};n(i)},subscribe:t=>this.$_useStore_subscribers.push(t),clear:t=>{let e=s;delete e[t],n(e)}}}useState(t,e,s=null){return this.states[t]||(this.states[t]=e),[this.states[t],e=>{this.states[t]=e,this.updateComponent(),"function"==typeof s&&s()}]}useRef(t){const e=this.dom[t];return{current:()=>e,update:t=>{const s=(new DOMParser).parseFromString(t,"text/html").body.firstChild;if(e){!s.isEqualNode(e)&&e.parentNode.replaceChild(s,e)}}}}useEffect(t,e){return this.effects[this.name]||(this.effects[this.name]=[]),this.effects[this.name].push(t),e.length>0?e.forEach((t=>{if(t.set)throw new Error("signal found, do not use effect and signals at the same time - signals are more efficient")})):this.hasMounted||(t(),this.hasMounted=!0),{cleanup:()=>{this.effects[this.name]=this.effects[this.name].filter((e=>e!==t))}}}$Function(t){let e=t.name;return e||(e="anonymous"+Math.floor(1e17*Math.random())),window[e]=t,`window.${e}()`}updateComponent(){const t=document.createDocumentFragment();Object.keys(components).forEach((async e=>{const{name:s}=components[e];let n=document.querySelector(`[data-component="${s}"]`),i={name:s,time:(new Date).getTime(),prev_state:this.states,prev_props:this.storedProps,content:n.innerHTML};if(!n)return;const r=await new Function("useState","useEffect","useAuth","useReducer","useSyncStore","signal","rf","props","render","return `"+await this.render()+"`;")(this.useState,this.useEffect,this.useAuth,this.useReducer,this.useSyncStore,this.signal,this.render);if(r!==n.innerHTML){if(this.snapshots.length>0){this.snapshots[this.snapshots.length-1]!==i&&this.snapshots.push(i)}else this.snapshots.push(i);this.componentUpdate(i.prev_state,i.prev_props,i.content),t.appendChild(document.createRange().createContextualFragment(r)),n.innerHTML="",n.appendChild(t),this.runEffects()}}))}validateClassName(t){return/^[a-zA-Z0-9-_]+$/.test(t)}html(t,...e){let s=setInterval((()=>{document.querySelector(`[data-component="${this.name}"]`)&&(clearInterval(s),this.componentMounted=!0,document.querySelector(`[data-component="${this.name}"]`)?.querySelectorAll("*").forEach((t=>{t.hasAttribute("ref")&&(this.dom[t.getAttribute("ref")]=t)})),this.componentDidMount())}),100),n=document.createElement("script");n.setAttribute("type","text/javascript"),n.setAttribute("data-component-script",this.name),worker.postMessage({strings:t,args:e,location:window.location.origin+window.location.pathname.replace(/\/[^\/]*$/,"")+"/public/",name:this.name});let i=new Promise(((t,e)=>{worker.onmessage=e=>{if(e.data.error)throw new Error(e.data.error);this.dom;let s=e.data.js,n=e.data.template;const i=this.useState.bind(this),r=this.useEffect.bind(this),a=this.useReducer.bind(this),o=this.useAuth.bind(this),c=this.useSyncStore.bind(this),u=this.signal.bind(this),h=this.$Function.bind(this);let l=this.states;const d=this.useRef.bind(this);new Function("useState","useEffect","useAuth","useReducer","useSyncStore","signal","$Function","dom","render","states","useRef",s)(i,r,o,a,c,u,h,this.dom,this.render,this.states,d),t(new Function("useRef","states","signal","useState","useReducer","useAuth","useSyncStore","useRef","$Function","return`"+n+"`")(d,l,u,i,a,o,c,d,h))},worker.onerror=t=>{e(t)}}));return i}async render(t){}}const Vader={Component:Component,useRef:useRef};export const component=()=>new Component;export const rf=(t,e)=>{window[t]=e};let cache={};async function handletemplate(t){let e=(new DOMParser).parseFromString(t,"text/html"),s=e.documentElement.querySelectorAll("*");if(s.length>0)for(var n=0;n<s.length;n++)if("INCLUDE"===s[n].nodeName){if(!s[n].getAttribute("src")||""===s[n].getAttribute("src"))throw new Error("Include tag must have src attribute");let t=s[n].getAttribute("src")?.split("/").pop()?.split(".")[0],i=await include(s[n].getAttribute("src"));i=i.replace(/`/g,"\\`"),cache[s[n].getAttribute("src")]=i,i=new Function(`return \`${i}\`;`)();let r=(new DOMParser).parseFromString(i,"text/html");r.querySelectorAll("include").forEach((t=>{t.remove()})),e.querySelectorAll(t).forEach((t=>{if(t.attributes.length>0)for(var s=0;s<t.attributes.length;s++){let e="{{"+t.attributes[s].name+"}}";r.body.innerHTML.includes(e)&&(r.body.innerHTML=r.body.innerHTML.replaceAll(e,t.attributes[s].value))}if(t.children.length>0&&r.body.querySelector("slot"))for(s=0;s<t.children.length;s++){r.body.querySelectorAll("slot").forEach((e=>{let n=e.getAttribute("id");(t.hasAttribute("key")&&t.getAttribute("key")===n||!t.hasAttribute("key")&&t.nodeName===n)&&t.children[s].innerHTML.length>0&&(e.outerHTML=t.children[s].innerHTML)}))}e.body.querySelectorAll("include").forEach((t=>{t.remove()})),e.body.outerHTML=e.body.outerHTML.replace(/`/g,"\\`"),e.body.outerHTML=e.body.outerHTML.replace(t.outerHTML,new Function(`return \`${r.body.outerHTML}\`;`)())}))}return e.body.outerHTML=e.body.outerHTML.replace(/`/g,"\\`"),t=new Function(`return \`${e.body.outerHTML}\`;`)()}export const include=async t=>(!t.startsWith("/")||t.includes("/src/")||document.documentElement.outerHTML.trim().includes("\x3c!-- #vader-disable_relative-paths --\x3e")||(t="/src/"+t),cache[t]?
|
|
1
|
+
let dom=[],states={},worker=new Worker(new URL("./worker.js",import.meta.url));export const useRef=t=>{const e=document.querySelector(`[ref="${t}"]`);return{current:e,update:t=>{const s=(new DOMParser).parseFromString(t,"text/html").body.firstChild;if(e){!s.isEqualNode(e)&&e.parentNode.replaceChild(s,e)}}}};let components=[];export class Component{constructor(){this.states={},this.name=this.constructor.name,this.executedEffects={},this.storedProps={},this.componentMounted=!1,this.hasMounted=!1,this.$_signal_subscribers=[],this.$_signal_subscribers_ran=[],this.effects={},this.$_useStore_subscribers=[],this.init(),this.Componentcontent=null,this.$_signal_dispatch_event=new CustomEvent("SignalDispatch",{detail:{hasUpdated:!1,state:null}}),this.$_signal_dispatch_cleanup_event=new CustomEvent("Signal_Cleanup_Dispatch",{detail:{state:null,lastState:null}}),this.snapshots=[],this.dom=[],this.cfr=!1}adapter(t){}init(){this.registerComponent()}registerComponent(){components.push(this)}setState(t,e){this.states[t]=e,this.updateComponent()}unmount(){this.componentMounted=!1,this.componentWillUnmount(),document.querySelector(`[data-component="${this.name}"]`).remove(),document.querySelector(`[data-component="${this.name}"]`)||(components=components.filter((t=>t.name!==this.name)))}componentUpdate(t,e,s){}componentDidMount(){}componentWillUnmount(){}signal=(t,e)=>{let s=!1,[n,i]=this.useState(t,e,(()=>{if(this.$_signal_subscribers.length>0){for(var t=0;t<this.$_signal_subscribers.length;t++)if(!s){if(this.$_signal_subscribers[t].runonce&&this.$_signal_subscribers_ran.includes(this.$_signal_subscribers[t]))break;return this.$_signal_subscribers[t].function(n),void this.$_signal_subscribers_ran.push(this.$_signal_subscribers[t])}}else this.$_signal_dispatch_event.detail.hasUpdated=!0,this.$_signal_dispatch_event.detail.state=n,window.dispatchEvent(this.$_signal_dispatch_event)}));return this.$_signal_subscribe=(t,e)=>(this.$_signal_subscribers.push({function:t,runonce:e}),t),this.$_signal_cleanup=t=>{this.lastState=n,this.$_signal_subscribers=this.$_signal_subscribers.filter((e=>e.function!==t)),this.$_signal_dispatch_cleanup_event.detail.state=this.states,this.$_signal_dispatch_cleanup_event.detail.lastState=this.lastState,window.dispatchEvent(this.$_signal_dispatch_event)},this.$_signal_dispatch=()=>{for(var t=0;t<this.$_signal_subscribers.length&&(!this.$_signal_subscribers[t].runonce||!this.$_signal_subscribers_ran.includes(this.$_signal_subscribers[t]));t++)this.$_signal_subscribers[t].function(n),this.$_signal_subscribers_ran.push(this.$_signal_subscribers[t])},this.$_signal_get=()=>n,this.$_signal_call=()=>{s=!0,this.$_signal_dispatch()},this.$_signal_set=t=>{i(t)},{subscribe:this.$_signal_subscribe,cleanup:this.$_signal_cleanup,dispatch:this.$_signal_dispatch,call:this.$_signal_call,set:this.$_signal_set,get:this.$_signal_get}};useAuth(t){let e=t.rulesets;if(!e)throw new Error("No rulesets provided");let s=t.user,n={can:t=>{let n=!1;return e.forEach((e=>{e.action===t&&e.condition(s)&&(n=!0)})),n},hasRole:t=>s.role&&s.role.includes(t),canWithRole:(t,e)=>n.can(t)&&n.hasRole(e),assignRule:t=>{e.some((e=>e.action===t.action))||e.push(t)},revokeRule:t=>{e=e.filter((e=>e.action!==t))},canAnyOf:t=>t.some((t=>n.can(t))),canAllOf:t=>t.every((t=>n.can(t))),canGroup:(t,e="any")=>"any"===e?n.canAnyOf(t):n.canAllOf(t)};return n}useReducer(t,e,s){return this.states[t]||(this.states[t]=s),[this.states[t],s=>{this.states[t]=e(this.states[t],s),this.updateComponent()}]}runEffects(){Object.keys(this.effects).forEach((t=>{this.effects[t].forEach((t=>{this.executedEffects[t]||(t(),this.executedEffects[t]=!0)}))}))}useSyncStore(t,e){let[s,n]=this.useState(t,e||localStorage.getItem(`$_vader_${t}`,(e=>{localStorage.setItem(`$_vader_${t}`,JSON.stringify(e)),this.$_useStore_subscribers.forEach((t=>{t(e)}))}))||{});return{getField:t=>s[t],setField:(t,e)=>{const i={...s,[t]:e};n(i)},subscribe:t=>this.$_useStore_subscribers.push(t),clear:t=>{let e=s;delete e[t],n(e)}}}useState(t,e,s=null){return this.states[t]||(this.states[t]=e),[this.states[t],e=>{this.states[t]=e,this.updateComponent(),"function"==typeof s&&s()}]}useRef(t){const e=this.dom[t];return{current:()=>e,update:t=>{const s=(new DOMParser).parseFromString(t,"text/html").body.firstChild;if(e){!s.isEqualNode(e)&&e.parentNode.replaceChild(s,e)}}}}useEffect(t,e){return this.effects[this.name]||(this.effects[this.name]=[]),this.effects[this.name].push(t),e.length>0?e.forEach((t=>{if(t.set)throw new Error("signal found, do not use effect and signals at the same time - signals are more efficient")})):this.hasMounted||(t(),this.hasMounted=!0),{cleanup:()=>{this.effects[this.name]=this.effects[this.name].filter((e=>e!==t))}}}$Function(t){let e=t.name;return e||(e="anonymous"+Math.floor(1e17*Math.random())),window[e]=t,`window.${e}()`}updateComponent(){const t=document.createDocumentFragment();Object.keys(components).forEach((async e=>{const{name:s}=components[e];let n=document.querySelector(`[data-component="${s}"]`),i={name:s,time:(new Date).getTime(),prev_state:this.states,prev_props:this.storedProps,content:n.innerHTML};if(!n)return;const r=await new Function("useState","useEffect","useAuth","useReducer","useSyncStore","signal","rf","props","render","return `"+await this.render()+"`;")(this.useState,this.useEffect,this.useAuth,this.useReducer,this.useSyncStore,this.signal,this.render);if(r!==n.innerHTML){if(this.snapshots.length>0){this.snapshots[this.snapshots.length-1]!==i&&this.snapshots.push(i)}else this.snapshots.push(i);this.componentUpdate(i.prev_state,i.prev_props,i.content),t.appendChild(document.createRange().createContextualFragment(r)),n.innerHTML="",n.appendChild(t),this.runEffects()}}))}validateClassName(t){return/^[a-zA-Z0-9-_]+$/.test(t)}html(t,...e){let s=setInterval((()=>{document.querySelector(`[data-component="${this.name}"]`)&&(clearInterval(s),this.componentMounted=!0,document.querySelector(`[data-component="${this.name}"]`)?.querySelectorAll("*").forEach((t=>{t.hasAttribute("ref")&&(this.dom[t.getAttribute("ref")]=t)})),this.componentDidMount())}),100),n=document.createElement("script");n.setAttribute("type","text/javascript"),n.setAttribute("data-component-script",this.name),worker.postMessage({strings:t,args:e,location:window.location.origin+window.location.pathname.replace(/\/[^\/]*$/,"")+"/public/",name:this.name});let i=new Promise(((t,e)=>{worker.onmessage=e=>{if(e.data.error)throw new Error(e.data.error);this.dom;let s=e.data.js,n=e.data.template;const i=this.useState.bind(this),r=this.useEffect.bind(this),a=this.useReducer.bind(this),o=this.useAuth.bind(this),c=this.useSyncStore.bind(this),u=this.signal.bind(this),h=this.$Function.bind(this);let l=this.states;const d=this.useRef.bind(this);new Function("useState","useEffect","useAuth","useReducer","useSyncStore","signal","$Function","dom","render","states","useRef",s)(i,r,o,a,c,u,h,this.dom,this.render,this.states,d),t(handletemplate(new Function("useRef","states","signal","useState","useReducer","useAuth","useSyncStore","useRef","$Function","return`"+n+"`")(d,l,u,i,a,o,c,d,h)))},worker.onerror=t=>{e(t)}}));return i}async render(t){}}const Vader={Component:Component,useRef:useRef};export const component=()=>new Component;export const rf=(t,e)=>{window[t]=e};let cache={};async function handletemplate(t){let e=(new DOMParser).parseFromString(t,"text/html"),s=e.documentElement.querySelectorAll("*");if(s.length>0)for(var n=0;n<s.length;n++)if("INCLUDE"===s[n].nodeName){if(!s[n].getAttribute("src")||""===s[n].getAttribute("src"))throw new Error("Include tag must have src attribute");let t=s[n].getAttribute("src")?.split("/").pop()?.split(".")[0],i=await include(s[n].getAttribute("src"));i=i.replace(/`/g,"\\`"),cache[s[n].getAttribute("src")]=i,i=new Function(`return \`${i}\`;`)();let r=(new DOMParser).parseFromString(i,"text/html");r.querySelectorAll("include").forEach((t=>{t.remove()})),e.querySelectorAll(t).forEach((t=>{if(t.attributes.length>0)for(var s=0;s<t.attributes.length;s++){let e="{{"+t.attributes[s].name+"}}";r.body.innerHTML.includes(e)&&(r.body.innerHTML=r.body.innerHTML.replaceAll(e,t.attributes[s].value))}if(t.children.length>0&&r.body.querySelector("slot"))for(s=0;s<t.children.length;s++){r.body.querySelectorAll("slot").forEach((e=>{let n=e.getAttribute("id");(t.hasAttribute("key")&&t.getAttribute("key")===n||!t.hasAttribute("key")&&t.nodeName===n)&&t.children[s].innerHTML.length>0&&(e.outerHTML=t.children[s].innerHTML)}))}e.body.querySelectorAll("include").forEach((t=>{t.remove()})),e.body.outerHTML=e.body.outerHTML.replace(/`/g,"\\`"),e.body.outerHTML=e.body.outerHTML.replace(t.outerHTML,new Function(`return \`${r.body.outerHTML}\`;`)())}))}return e.body.outerHTML=e.body.outerHTML.replace(/`/g,"\\`"),t=new Function(`return \`${e.body.outerHTML}\`;`)()}export const include=async t=>(!t.startsWith("/")||t.includes("/src/")||document.documentElement.outerHTML.trim().includes("\x3c!-- #vader-disable_relative-paths --\x3e")||(t="/src/"+t),cache[t]?cache[t]:fetch(`./${t}`).then((e=>{if(404===e.status)throw new Error(`No file found at ${t}`);return e.text()})).then((async e=>(cache[t]=e,e))));export default Vader;
|
package/vader.js
CHANGED
|
@@ -875,7 +875,7 @@ export class Component {
|
|
|
875
875
|
);
|
|
876
876
|
|
|
877
877
|
resolve(
|
|
878
|
-
new Function(
|
|
878
|
+
handletemplate( new Function(
|
|
879
879
|
"useRef",
|
|
880
880
|
"states",
|
|
881
881
|
"signal",
|
|
@@ -896,7 +896,7 @@ export class Component {
|
|
|
896
896
|
useSyncStore,
|
|
897
897
|
useRef,
|
|
898
898
|
$Function
|
|
899
|
-
)
|
|
899
|
+
))
|
|
900
900
|
);
|
|
901
901
|
};
|
|
902
902
|
worker.onerror = (e) => {
|
|
@@ -1092,7 +1092,7 @@ export const include = async (path) => {
|
|
|
1092
1092
|
// @ts-ignore
|
|
1093
1093
|
if (cache[path]) {
|
|
1094
1094
|
// @ts-ignore
|
|
1095
|
-
return
|
|
1095
|
+
return cache[path];
|
|
1096
1096
|
} else {
|
|
1097
1097
|
return fetch(`./${path}`)
|
|
1098
1098
|
.then((res) => {
|
|
@@ -1105,7 +1105,7 @@ export const include = async (path) => {
|
|
|
1105
1105
|
// @ts-ignore
|
|
1106
1106
|
cache[path] = data;
|
|
1107
1107
|
|
|
1108
|
-
|
|
1108
|
+
|
|
1109
1109
|
|
|
1110
1110
|
return data;
|
|
1111
1111
|
});
|
package/worker-min.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
onmessage=e=>{let l=Date.now(),a=e.data.strings,t=e.data.args,s="",r=e.data.location.split("/").slice(0,-1).join("/"),c="";for(let e=0;e<a.length;e++)c+=a[e],e<t.length&&(c+=t[e]);let i=c.match(/--([^>]*)--/gs);if(i)for(;i.length;){let e=i.pop();c=c.replace(e,"")}if(c=c.replace(/(#+)(
|
|
1
|
+
onmessage=e=>{let l=Date.now(),a=e.data.strings,t=e.data.args,s="",r=e.data.location.split("/").slice(0,-1).join("/"),c="";for(let e=0;e<a.length;e++)c+=a[e],e<t.length&&(c+=t[e]);let i=c.match(/--([^>]*)--/gs);if(i)for(;i.length;){let e=i.pop();c=c.replace(e,"")}if(c=c.replace(/(#+)([^<>\n]*)(?![^<]*>)(?![^{]*})/g,((e,l,a)=>{let t=l.length;return`<h${t} class="markdown_heading">${a}</h${t}>`})),c=c.replace(/\*\*(.*?)\*\*/g,((e,l)=>`<b class="markdown_bold">${l}</b>`)),c=c.replace(/\*(.*?)\*/g,((e,l)=>`<i class="markdown_italic">${l}</i>`)),c=c.replace(/`(.*?)`/g,((e,l)=>`<code>${l}</code>`)),c=c.replace(/\[([^\]]+)\]\(([^)]+)\)/g,((e,l,a)=>`<a class="markdown_link" href="${a}">${l}</a>`)),c=c.replace(/!\[([^\]]+)\]\(([^)]+)\)/g,((e,l,a)=>`<img class="markdown_image" src="${a}" alt="${l}" />`)),c.split("\n").forEach(((e,l,a)=>{e.match(/^\s*-\s+(.*?)$/gm)&&(c=0!==l&&a[l-1].match(/^\s*-\s+(.*?)$/gm)?l!==a.length-1&&a[l+1].match(/^\s*-\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li></ul>`):c.replace(e,`<ul class="markdown_unordered" style="list-style-type:disc;list-style:inside"><li>${e.replace(/^\s*-\s+(.*?)$/gm,"$1")}</li>`))})),c.split("\n").forEach(((e,l,a)=>{e.match(/^\s*\d+\.\s+(.*?)$/gm)&&(c=0!==l&&a[l-1].match(/^\s*\d+\.\s+(.*?)$/gm)?l!==a.length-1&&a[l+1].match(/^\s*\d+\.\s+(.*?)$/gm)?c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`):c.replace(e,`<li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li></ol>`):c.replace(e,`<ol class="markdown_ordered" style="list-style-type:decimal;"><li>${e.replace(/^\s*\d+\.\s+(.*?)$/gm,"$1")}</li>`))})),c=c.replace(/^\s*-\s+(.*?)$/gm,((e,l)=>`<li class="markdown_list_item">${l}</li>`)),c=c.replace(/^\s*---\s*$/gm,'<hr class="markdown_horizontal" />'),c=c.replace(/^\s*> (.*)$/gm,((e,l)=>`<blockquote class="markdown_blockquote">${l}</blockquote>`)),c=c.replace(/((?: *\|.*?)+)\n((?: *\|.*?)+)/gm,((e,l,a)=>{const t=l.split("|").slice(1,-1),s=a.split("|").slice(1,-1);let r='<table class="markdown_table">';return r+='<thead class="markdown_table_head"><tr class="markdown_table_row">',t.forEach((e=>{r+=`<th class="markdown_table_header_cell">${e}</th>`})),r+='</tr></thead><tbody class="markdown_table_body"><tr class="markdown_table_row">',s.forEach((e=>{r+=`<td class="markdown_table_body_cell">${e}</td>`})),r+="</tr></tbody></table>",r})),!c.includes("<body>"))throw new Error(`Vader Error: You must enclose your html in a body tag for all components. \n\n${c}`);c=c.replace(/classname/g,"class");let o=c.match(/<img([^>]*)>/g);if(o)for(let l=0;l<o.length;l++){let a=o[l],t=a.match(/src="([^"]*)"/);if(!a.match(/alt="([^"]*)"/)&&!c.includes("\x3c!-- #vader-disable_accessibility --\x3e"))throw new Error(`Vader Error: You must include an alt attribute in the image tag \n\n${a} of class ${e.data.name}. `);t&&t.forEach((l=>{if(l.includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!l.includes("http")&&l.startsWith(".")&&!c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${l}`)}else c=c.replace(`src="${l}"`,`src="${r}/${l}"`)}))}let n=c.match(/href="([^"]*)"/g);if(n)for(;n.length;){let l=n.pop();if(l=l.replace('href="',"").replace('"',""),l.includes("http")||c.includes("\x3c!-- #vader-disable_relative-paths --\x3e")){if(!l.includes("http")&&l.startsWith(".")&&!c.includes("\x3c!-- #vader-disable_relative-paths --\x3e"))throw new Error(`Vader Error: You cannot use absolute paths since relative paths are not disabled in ${e.data.file}. Use relative paths instead. \n\n${l}`)}else c=c.replace(`href="${l}"`,`href="#${l}"`)}let d=Date.now()-l,p=!1;(r.includes("localhost")||r.includes("127.0.0.1")&&!p)&&(p=!0,c+=`\${console.log('%c${e.data.name} component rendered in ${d}ms')}`);const h=c.split("<script>");h&&h.forEach(((e,l)=>{if(0===l)c=e;else{if(e.includes("// <![CDATA[ <-- For SVG support"))return;let l=e.split("<\/script>")[0];s+=l}}));let m=c.match(/(\$\(.*?\))/gs);if(m)for(;m.length;){let e=m.pop();c=c.replace(e,`\${${e.replace("$(","").replace(")","")}}`)}let $=c.match(/@title '([^>]*)';/);if($){let e=`{document.title = "${$[1]}", ""}`;c=c.replace($[0],"$"+e)}let g=c.match(/@style{([^>]*)};/gs);if(g)for(let e=0;e<g.length;e++){if(!g[e].includes("style"))continue;let l=g[e];console.log(l);let a=l.replace("@style{","").replace("};","");a=a.replaceAll(",",";"),a=a.replaceAll(/[A-Z]/g,(e=>`-${e.toLowerCase()}`)),a=a.replaceAll(/'/g," "),c=c.replace(l,`style="${a}"`)}let u=c.match(/@stylesheet{([^>]*)};/);if(u){let e=u[1].replaceAll(" ","");e=e.replaceAll(",",";"),e=e.replaceAll(/[A-Z]/g,(e=>`-${e.toLowerCase()}`)),e=e.replaceAll(/'/g," "),c=c.replace(u[0],`<style>${e}</style>`)}postMessage({template:`<div data-component=${e.data.name}>${c}</div>`,js:s||""})};
|
package/worker.js
CHANGED
|
@@ -13,6 +13,11 @@ onmessage = (e) => {
|
|
|
13
13
|
}
|
|
14
14
|
|
|
15
15
|
let comments = result.match(/--([^>]*)--/gs);
|
|
16
|
+
/**
|
|
17
|
+
* @example
|
|
18
|
+
*
|
|
19
|
+
* -- This is a comment --
|
|
20
|
+
*/
|
|
16
21
|
if (comments) {
|
|
17
22
|
while (comments.length) {
|
|
18
23
|
let comment = comments.pop();
|
|
@@ -21,16 +26,11 @@ onmessage = (e) => {
|
|
|
21
26
|
}
|
|
22
27
|
}
|
|
23
28
|
|
|
24
|
-
|
|
25
|
-
// @ts-ignore
|
|
26
|
-
result = result.replace(/(#+)(.*)/g, (match, hashes, text) => {
|
|
27
|
-
if (!match.includes("<") || !match.includes(">")) {
|
|
29
|
+
result = result.replace(/(#+)([^<>\n]*)(?![^<]*>)(?![^{]*})/g, (match, hashes, text) => {
|
|
28
30
|
let level = hashes.length;
|
|
29
|
-
return `<h
|
|
30
|
-
} else {
|
|
31
|
-
return match;
|
|
32
|
-
}
|
|
31
|
+
return `<h${level} class="markdown_heading">${text}</h${level}>`;
|
|
33
32
|
});
|
|
33
|
+
|
|
34
34
|
|
|
35
35
|
// Convert bold (e.g., **Bold** => <b>Bold</b>)
|
|
36
36
|
result = result.replace(/\*\*(.*?)\*\*/g, (match, text) => {
|
|
@@ -259,15 +259,17 @@ onmessage = (e) => {
|
|
|
259
259
|
}
|
|
260
260
|
}
|
|
261
261
|
|
|
262
|
-
let title = result.match(/@title '([^>]*)'
|
|
262
|
+
let title = result.match(/@title '([^>]*)';/);
|
|
263
263
|
if (title) {
|
|
264
264
|
let t = title[1];
|
|
265
265
|
let ti = `{document.title = "${t}", ""}`;
|
|
266
266
|
result = result.replace(title[0], "$" + ti);
|
|
267
267
|
}
|
|
268
268
|
// @ts-ignore
|
|
269
|
-
|
|
269
|
+
|
|
270
|
+
|
|
270
271
|
let styles = result.match(/@style{([^>]*)};/gs);
|
|
272
|
+
|
|
271
273
|
if (styles) {
|
|
272
274
|
for (let i = 0; i < styles.length; i++) {
|
|
273
275
|
// make sure its in a tag
|
|
@@ -276,24 +278,47 @@ onmessage = (e) => {
|
|
|
276
278
|
continue;
|
|
277
279
|
}
|
|
278
280
|
let style = styles[i];
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
let s = style.match(/@style{([^>]*)};/);
|
|
282
|
-
|
|
283
|
-
// @ts-ignore
|
|
284
|
-
s.forEach((style) => {
|
|
281
|
+
console.log(style)
|
|
285
282
|
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
283
|
+
let css = style.replace("@style{", "").replace("};", "");
|
|
284
|
+
// @ts-ignore
|
|
285
|
+
css = css.replaceAll(",", ";");
|
|
286
|
+
// @ts-ignore
|
|
287
|
+
css = css.replaceAll(/[A-Z]/g, (match) => {
|
|
288
|
+
return `-${match.toLowerCase()}`;
|
|
289
|
+
}
|
|
290
|
+
);
|
|
291
|
+
//@ts-ignore
|
|
292
|
+
css = css.replaceAll(/'/g, " ");
|
|
293
|
+
result = result.replace(style, `style="${css}"`);
|
|
294
|
+
|
|
295
|
+
|
|
294
296
|
}
|
|
295
297
|
}
|
|
296
298
|
|
|
299
|
+
let stylsheet = result.match(/@stylesheet{([^>]*)};/);
|
|
300
|
+
if (stylsheet) {
|
|
301
|
+
let styles = stylsheet[1];
|
|
302
|
+
/**
|
|
303
|
+
* @stylesheet{
|
|
304
|
+
* body:{
|
|
305
|
+
* backgroundColor: red;
|
|
306
|
+
*
|
|
307
|
+
* }
|
|
308
|
+
* }
|
|
309
|
+
*/
|
|
310
|
+
|
|
311
|
+
// @ts-ignore
|
|
312
|
+
let css = styles.replaceAll(" ", "");
|
|
313
|
+
css = css.replaceAll(",", ";");
|
|
314
|
+
css = css.replaceAll(/[A-Z]/g, (match) => {
|
|
315
|
+
return `-${match.toLowerCase()}`;
|
|
316
|
+
}
|
|
317
|
+
);
|
|
318
|
+
css = css.replaceAll(/'/g, " ");
|
|
319
|
+
|
|
320
|
+
result = result.replace(stylsheet[0], `<style>${css}</style>`);
|
|
321
|
+
}
|
|
297
322
|
postMessage({
|
|
298
323
|
template: `<div data-component=${e.data.name}>${result}</div>`,
|
|
299
324
|
js: js ? js : ""
|