@jxsuite/runtime 0.0.1
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/dist/runtime.js +2409 -0
- package/dist/runtime.js.map +12 -0
- package/package.json +25 -0
- package/src/runtime.js +1728 -0
package/dist/runtime.js
ADDED
|
@@ -0,0 +1,2409 @@
|
|
|
1
|
+
// ../../node_modules/@vue/shared/dist/shared.esm-bundler.js
|
|
2
|
+
function makeMap(str) {
|
|
3
|
+
const map = /* @__PURE__ */ Object.create(null);
|
|
4
|
+
for (const key of str.split(","))
|
|
5
|
+
map[key] = 1;
|
|
6
|
+
return (val) => (val in map);
|
|
7
|
+
}
|
|
8
|
+
var EMPTY_OBJ = Object.freeze({});
|
|
9
|
+
var EMPTY_ARR = Object.freeze([]);
|
|
10
|
+
var extend = Object.assign;
|
|
11
|
+
var hasOwnProperty = Object.prototype.hasOwnProperty;
|
|
12
|
+
var hasOwn = (val, key) => hasOwnProperty.call(val, key);
|
|
13
|
+
var isArray = Array.isArray;
|
|
14
|
+
var isMap = (val) => toTypeString(val) === "[object Map]";
|
|
15
|
+
var isFunction = (val) => typeof val === "function";
|
|
16
|
+
var isString = (val) => typeof val === "string";
|
|
17
|
+
var isSymbol = (val) => typeof val === "symbol";
|
|
18
|
+
var isObject = (val) => val !== null && typeof val === "object";
|
|
19
|
+
var objectToString = Object.prototype.toString;
|
|
20
|
+
var toTypeString = (value) => objectToString.call(value);
|
|
21
|
+
var toRawType = (value) => {
|
|
22
|
+
return toTypeString(value).slice(8, -1);
|
|
23
|
+
};
|
|
24
|
+
var isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
25
|
+
var cacheStringFunction = (fn) => {
|
|
26
|
+
const cache = /* @__PURE__ */ Object.create(null);
|
|
27
|
+
return (str) => {
|
|
28
|
+
const hit = cache[str];
|
|
29
|
+
return hit || (cache[str] = fn(str));
|
|
30
|
+
};
|
|
31
|
+
};
|
|
32
|
+
var camelizeRE = /-\w/g;
|
|
33
|
+
var camelize = cacheStringFunction((str) => {
|
|
34
|
+
return str.replace(camelizeRE, (c) => c.slice(1).toUpperCase());
|
|
35
|
+
});
|
|
36
|
+
var hyphenateRE = /\B([A-Z])/g;
|
|
37
|
+
var hyphenate = cacheStringFunction((str) => str.replace(hyphenateRE, "-$1").toLowerCase());
|
|
38
|
+
var capitalize = cacheStringFunction((str) => {
|
|
39
|
+
return str.charAt(0).toUpperCase() + str.slice(1);
|
|
40
|
+
});
|
|
41
|
+
var toHandlerKey = cacheStringFunction((str) => {
|
|
42
|
+
const s = str ? `on${capitalize(str)}` : ``;
|
|
43
|
+
return s;
|
|
44
|
+
});
|
|
45
|
+
var hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
46
|
+
var specialBooleanAttrs = `itemscope,allowfullscreen,formnovalidate,ismap,nomodule,novalidate,readonly`;
|
|
47
|
+
var isBooleanAttr = /* @__PURE__ */ makeMap(specialBooleanAttrs + `,async,autofocus,autoplay,controls,default,defer,disabled,hidden,inert,loop,open,required,reversed,scoped,seamless,checked,muted,multiple,selected`);
|
|
48
|
+
|
|
49
|
+
// ../../node_modules/@vue/reactivity/dist/reactivity.esm-bundler.js
|
|
50
|
+
function warn(msg, ...args) {
|
|
51
|
+
console.warn(`[Vue warn] ${msg}`, ...args);
|
|
52
|
+
}
|
|
53
|
+
var activeEffectScope;
|
|
54
|
+
var activeSub;
|
|
55
|
+
var pausedQueueEffects = /* @__PURE__ */ new WeakSet;
|
|
56
|
+
|
|
57
|
+
class ReactiveEffect {
|
|
58
|
+
constructor(fn) {
|
|
59
|
+
this.fn = fn;
|
|
60
|
+
this.deps = undefined;
|
|
61
|
+
this.depsTail = undefined;
|
|
62
|
+
this.flags = 1 | 4;
|
|
63
|
+
this.next = undefined;
|
|
64
|
+
this.cleanup = undefined;
|
|
65
|
+
this.scheduler = undefined;
|
|
66
|
+
if (activeEffectScope && activeEffectScope.active) {
|
|
67
|
+
activeEffectScope.effects.push(this);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
pause() {
|
|
71
|
+
this.flags |= 64;
|
|
72
|
+
}
|
|
73
|
+
resume() {
|
|
74
|
+
if (this.flags & 64) {
|
|
75
|
+
this.flags &= -65;
|
|
76
|
+
if (pausedQueueEffects.has(this)) {
|
|
77
|
+
pausedQueueEffects.delete(this);
|
|
78
|
+
this.trigger();
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
notify() {
|
|
83
|
+
if (this.flags & 2 && !(this.flags & 32)) {
|
|
84
|
+
return;
|
|
85
|
+
}
|
|
86
|
+
if (!(this.flags & 8)) {
|
|
87
|
+
batch(this);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
run() {
|
|
91
|
+
if (!(this.flags & 1)) {
|
|
92
|
+
return this.fn();
|
|
93
|
+
}
|
|
94
|
+
this.flags |= 2;
|
|
95
|
+
cleanupEffect(this);
|
|
96
|
+
prepareDeps(this);
|
|
97
|
+
const prevEffect = activeSub;
|
|
98
|
+
const prevShouldTrack = shouldTrack;
|
|
99
|
+
activeSub = this;
|
|
100
|
+
shouldTrack = true;
|
|
101
|
+
try {
|
|
102
|
+
return this.fn();
|
|
103
|
+
} finally {
|
|
104
|
+
if (activeSub !== this) {
|
|
105
|
+
warn("Active effect was not restored correctly - this is likely a Vue internal bug.");
|
|
106
|
+
}
|
|
107
|
+
cleanupDeps(this);
|
|
108
|
+
activeSub = prevEffect;
|
|
109
|
+
shouldTrack = prevShouldTrack;
|
|
110
|
+
this.flags &= -3;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
stop() {
|
|
114
|
+
if (this.flags & 1) {
|
|
115
|
+
for (let link = this.deps;link; link = link.nextDep) {
|
|
116
|
+
removeSub(link);
|
|
117
|
+
}
|
|
118
|
+
this.deps = this.depsTail = undefined;
|
|
119
|
+
cleanupEffect(this);
|
|
120
|
+
this.onStop && this.onStop();
|
|
121
|
+
this.flags &= -2;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
trigger() {
|
|
125
|
+
if (this.flags & 64) {
|
|
126
|
+
pausedQueueEffects.add(this);
|
|
127
|
+
} else if (this.scheduler) {
|
|
128
|
+
this.scheduler();
|
|
129
|
+
} else {
|
|
130
|
+
this.runIfDirty();
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
runIfDirty() {
|
|
134
|
+
if (isDirty(this)) {
|
|
135
|
+
this.run();
|
|
136
|
+
}
|
|
137
|
+
}
|
|
138
|
+
get dirty() {
|
|
139
|
+
return isDirty(this);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
var batchDepth = 0;
|
|
143
|
+
var batchedSub;
|
|
144
|
+
var batchedComputed;
|
|
145
|
+
function batch(sub, isComputed = false) {
|
|
146
|
+
sub.flags |= 8;
|
|
147
|
+
if (isComputed) {
|
|
148
|
+
sub.next = batchedComputed;
|
|
149
|
+
batchedComputed = sub;
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
sub.next = batchedSub;
|
|
153
|
+
batchedSub = sub;
|
|
154
|
+
}
|
|
155
|
+
function startBatch() {
|
|
156
|
+
batchDepth++;
|
|
157
|
+
}
|
|
158
|
+
function endBatch() {
|
|
159
|
+
if (--batchDepth > 0) {
|
|
160
|
+
return;
|
|
161
|
+
}
|
|
162
|
+
if (batchedComputed) {
|
|
163
|
+
let e = batchedComputed;
|
|
164
|
+
batchedComputed = undefined;
|
|
165
|
+
while (e) {
|
|
166
|
+
const next = e.next;
|
|
167
|
+
e.next = undefined;
|
|
168
|
+
e.flags &= -9;
|
|
169
|
+
e = next;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
let error;
|
|
173
|
+
while (batchedSub) {
|
|
174
|
+
let e = batchedSub;
|
|
175
|
+
batchedSub = undefined;
|
|
176
|
+
while (e) {
|
|
177
|
+
const next = e.next;
|
|
178
|
+
e.next = undefined;
|
|
179
|
+
e.flags &= -9;
|
|
180
|
+
if (e.flags & 1) {
|
|
181
|
+
try {
|
|
182
|
+
e.trigger();
|
|
183
|
+
} catch (err) {
|
|
184
|
+
if (!error)
|
|
185
|
+
error = err;
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
e = next;
|
|
189
|
+
}
|
|
190
|
+
}
|
|
191
|
+
if (error)
|
|
192
|
+
throw error;
|
|
193
|
+
}
|
|
194
|
+
function prepareDeps(sub) {
|
|
195
|
+
for (let link = sub.deps;link; link = link.nextDep) {
|
|
196
|
+
link.version = -1;
|
|
197
|
+
link.prevActiveLink = link.dep.activeLink;
|
|
198
|
+
link.dep.activeLink = link;
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function cleanupDeps(sub) {
|
|
202
|
+
let head;
|
|
203
|
+
let tail = sub.depsTail;
|
|
204
|
+
let link = tail;
|
|
205
|
+
while (link) {
|
|
206
|
+
const prev = link.prevDep;
|
|
207
|
+
if (link.version === -1) {
|
|
208
|
+
if (link === tail)
|
|
209
|
+
tail = prev;
|
|
210
|
+
removeSub(link);
|
|
211
|
+
removeDep(link);
|
|
212
|
+
} else {
|
|
213
|
+
head = link;
|
|
214
|
+
}
|
|
215
|
+
link.dep.activeLink = link.prevActiveLink;
|
|
216
|
+
link.prevActiveLink = undefined;
|
|
217
|
+
link = prev;
|
|
218
|
+
}
|
|
219
|
+
sub.deps = head;
|
|
220
|
+
sub.depsTail = tail;
|
|
221
|
+
}
|
|
222
|
+
function isDirty(sub) {
|
|
223
|
+
for (let link = sub.deps;link; link = link.nextDep) {
|
|
224
|
+
if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) {
|
|
225
|
+
return true;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
if (sub._dirty) {
|
|
229
|
+
return true;
|
|
230
|
+
}
|
|
231
|
+
return false;
|
|
232
|
+
}
|
|
233
|
+
function refreshComputed(computed) {
|
|
234
|
+
if (computed.flags & 4 && !(computed.flags & 16)) {
|
|
235
|
+
return;
|
|
236
|
+
}
|
|
237
|
+
computed.flags &= -17;
|
|
238
|
+
if (computed.globalVersion === globalVersion) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
computed.globalVersion = globalVersion;
|
|
242
|
+
if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) {
|
|
243
|
+
return;
|
|
244
|
+
}
|
|
245
|
+
computed.flags |= 2;
|
|
246
|
+
const dep = computed.dep;
|
|
247
|
+
const prevSub = activeSub;
|
|
248
|
+
const prevShouldTrack = shouldTrack;
|
|
249
|
+
activeSub = computed;
|
|
250
|
+
shouldTrack = true;
|
|
251
|
+
try {
|
|
252
|
+
prepareDeps(computed);
|
|
253
|
+
const value = computed.fn(computed._value);
|
|
254
|
+
if (dep.version === 0 || hasChanged(value, computed._value)) {
|
|
255
|
+
computed.flags |= 128;
|
|
256
|
+
computed._value = value;
|
|
257
|
+
dep.version++;
|
|
258
|
+
}
|
|
259
|
+
} catch (err) {
|
|
260
|
+
dep.version++;
|
|
261
|
+
throw err;
|
|
262
|
+
} finally {
|
|
263
|
+
activeSub = prevSub;
|
|
264
|
+
shouldTrack = prevShouldTrack;
|
|
265
|
+
cleanupDeps(computed);
|
|
266
|
+
computed.flags &= -3;
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
function removeSub(link, soft = false) {
|
|
270
|
+
const { dep, prevSub, nextSub } = link;
|
|
271
|
+
if (prevSub) {
|
|
272
|
+
prevSub.nextSub = nextSub;
|
|
273
|
+
link.prevSub = undefined;
|
|
274
|
+
}
|
|
275
|
+
if (nextSub) {
|
|
276
|
+
nextSub.prevSub = prevSub;
|
|
277
|
+
link.nextSub = undefined;
|
|
278
|
+
}
|
|
279
|
+
if (dep.subsHead === link) {
|
|
280
|
+
dep.subsHead = nextSub;
|
|
281
|
+
}
|
|
282
|
+
if (dep.subs === link) {
|
|
283
|
+
dep.subs = prevSub;
|
|
284
|
+
if (!prevSub && dep.computed) {
|
|
285
|
+
dep.computed.flags &= -5;
|
|
286
|
+
for (let l = dep.computed.deps;l; l = l.nextDep) {
|
|
287
|
+
removeSub(l, true);
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
}
|
|
291
|
+
if (!soft && !--dep.sc && dep.map) {
|
|
292
|
+
dep.map.delete(dep.key);
|
|
293
|
+
}
|
|
294
|
+
}
|
|
295
|
+
function removeDep(link) {
|
|
296
|
+
const { prevDep, nextDep } = link;
|
|
297
|
+
if (prevDep) {
|
|
298
|
+
prevDep.nextDep = nextDep;
|
|
299
|
+
link.prevDep = undefined;
|
|
300
|
+
}
|
|
301
|
+
if (nextDep) {
|
|
302
|
+
nextDep.prevDep = prevDep;
|
|
303
|
+
link.nextDep = undefined;
|
|
304
|
+
}
|
|
305
|
+
}
|
|
306
|
+
function effect(fn, options) {
|
|
307
|
+
if (fn.effect instanceof ReactiveEffect) {
|
|
308
|
+
fn = fn.effect.fn;
|
|
309
|
+
}
|
|
310
|
+
const e = new ReactiveEffect(fn);
|
|
311
|
+
if (options) {
|
|
312
|
+
extend(e, options);
|
|
313
|
+
}
|
|
314
|
+
try {
|
|
315
|
+
e.run();
|
|
316
|
+
} catch (err) {
|
|
317
|
+
e.stop();
|
|
318
|
+
throw err;
|
|
319
|
+
}
|
|
320
|
+
const runner = e.run.bind(e);
|
|
321
|
+
runner.effect = e;
|
|
322
|
+
return runner;
|
|
323
|
+
}
|
|
324
|
+
var shouldTrack = true;
|
|
325
|
+
var trackStack = [];
|
|
326
|
+
function pauseTracking() {
|
|
327
|
+
trackStack.push(shouldTrack);
|
|
328
|
+
shouldTrack = false;
|
|
329
|
+
}
|
|
330
|
+
function resetTracking() {
|
|
331
|
+
const last = trackStack.pop();
|
|
332
|
+
shouldTrack = last === undefined ? true : last;
|
|
333
|
+
}
|
|
334
|
+
function onEffectCleanup(fn, failSilently = false) {
|
|
335
|
+
if (activeSub instanceof ReactiveEffect) {
|
|
336
|
+
activeSub.cleanup = fn;
|
|
337
|
+
} else if (!failSilently) {
|
|
338
|
+
warn(`onEffectCleanup() was called when there was no active effect to associate with.`);
|
|
339
|
+
}
|
|
340
|
+
}
|
|
341
|
+
function cleanupEffect(e) {
|
|
342
|
+
const { cleanup } = e;
|
|
343
|
+
e.cleanup = undefined;
|
|
344
|
+
if (cleanup) {
|
|
345
|
+
const prevSub = activeSub;
|
|
346
|
+
activeSub = undefined;
|
|
347
|
+
try {
|
|
348
|
+
cleanup();
|
|
349
|
+
} finally {
|
|
350
|
+
activeSub = prevSub;
|
|
351
|
+
}
|
|
352
|
+
}
|
|
353
|
+
}
|
|
354
|
+
var globalVersion = 0;
|
|
355
|
+
|
|
356
|
+
class Link {
|
|
357
|
+
constructor(sub, dep) {
|
|
358
|
+
this.sub = sub;
|
|
359
|
+
this.dep = dep;
|
|
360
|
+
this.version = dep.version;
|
|
361
|
+
this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = undefined;
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
|
|
365
|
+
class Dep {
|
|
366
|
+
constructor(computed) {
|
|
367
|
+
this.computed = computed;
|
|
368
|
+
this.version = 0;
|
|
369
|
+
this.activeLink = undefined;
|
|
370
|
+
this.subs = undefined;
|
|
371
|
+
this.map = undefined;
|
|
372
|
+
this.key = undefined;
|
|
373
|
+
this.sc = 0;
|
|
374
|
+
this.__v_skip = true;
|
|
375
|
+
if (true) {
|
|
376
|
+
this.subsHead = undefined;
|
|
377
|
+
}
|
|
378
|
+
}
|
|
379
|
+
track(debugInfo) {
|
|
380
|
+
if (!activeSub || !shouldTrack || activeSub === this.computed) {
|
|
381
|
+
return;
|
|
382
|
+
}
|
|
383
|
+
let link = this.activeLink;
|
|
384
|
+
if (link === undefined || link.sub !== activeSub) {
|
|
385
|
+
link = this.activeLink = new Link(activeSub, this);
|
|
386
|
+
if (!activeSub.deps) {
|
|
387
|
+
activeSub.deps = activeSub.depsTail = link;
|
|
388
|
+
} else {
|
|
389
|
+
link.prevDep = activeSub.depsTail;
|
|
390
|
+
activeSub.depsTail.nextDep = link;
|
|
391
|
+
activeSub.depsTail = link;
|
|
392
|
+
}
|
|
393
|
+
addSub(link);
|
|
394
|
+
} else if (link.version === -1) {
|
|
395
|
+
link.version = this.version;
|
|
396
|
+
if (link.nextDep) {
|
|
397
|
+
const next = link.nextDep;
|
|
398
|
+
next.prevDep = link.prevDep;
|
|
399
|
+
if (link.prevDep) {
|
|
400
|
+
link.prevDep.nextDep = next;
|
|
401
|
+
}
|
|
402
|
+
link.prevDep = activeSub.depsTail;
|
|
403
|
+
link.nextDep = undefined;
|
|
404
|
+
activeSub.depsTail.nextDep = link;
|
|
405
|
+
activeSub.depsTail = link;
|
|
406
|
+
if (activeSub.deps === link) {
|
|
407
|
+
activeSub.deps = next;
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (activeSub.onTrack) {
|
|
412
|
+
activeSub.onTrack(extend({
|
|
413
|
+
effect: activeSub
|
|
414
|
+
}, debugInfo));
|
|
415
|
+
}
|
|
416
|
+
return link;
|
|
417
|
+
}
|
|
418
|
+
trigger(debugInfo) {
|
|
419
|
+
this.version++;
|
|
420
|
+
globalVersion++;
|
|
421
|
+
this.notify(debugInfo);
|
|
422
|
+
}
|
|
423
|
+
notify(debugInfo) {
|
|
424
|
+
startBatch();
|
|
425
|
+
try {
|
|
426
|
+
if (true) {
|
|
427
|
+
for (let head = this.subsHead;head; head = head.nextSub) {
|
|
428
|
+
if (head.sub.onTrigger && !(head.sub.flags & 8)) {
|
|
429
|
+
head.sub.onTrigger(extend({
|
|
430
|
+
effect: head.sub
|
|
431
|
+
}, debugInfo));
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
}
|
|
435
|
+
for (let link = this.subs;link; link = link.prevSub) {
|
|
436
|
+
if (link.sub.notify()) {
|
|
437
|
+
link.sub.dep.notify();
|
|
438
|
+
}
|
|
439
|
+
}
|
|
440
|
+
} finally {
|
|
441
|
+
endBatch();
|
|
442
|
+
}
|
|
443
|
+
}
|
|
444
|
+
}
|
|
445
|
+
function addSub(link) {
|
|
446
|
+
link.dep.sc++;
|
|
447
|
+
if (link.sub.flags & 4) {
|
|
448
|
+
const computed = link.dep.computed;
|
|
449
|
+
if (computed && !link.dep.subs) {
|
|
450
|
+
computed.flags |= 4 | 16;
|
|
451
|
+
for (let l = computed.deps;l; l = l.nextDep) {
|
|
452
|
+
addSub(l);
|
|
453
|
+
}
|
|
454
|
+
}
|
|
455
|
+
const currentTail = link.dep.subs;
|
|
456
|
+
if (currentTail !== link) {
|
|
457
|
+
link.prevSub = currentTail;
|
|
458
|
+
if (currentTail)
|
|
459
|
+
currentTail.nextSub = link;
|
|
460
|
+
}
|
|
461
|
+
if (link.dep.subsHead === undefined) {
|
|
462
|
+
link.dep.subsHead = link;
|
|
463
|
+
}
|
|
464
|
+
link.dep.subs = link;
|
|
465
|
+
}
|
|
466
|
+
}
|
|
467
|
+
var targetMap = /* @__PURE__ */ new WeakMap;
|
|
468
|
+
var ITERATE_KEY = /* @__PURE__ */ Symbol("Object iterate");
|
|
469
|
+
var MAP_KEY_ITERATE_KEY = /* @__PURE__ */ Symbol("Map keys iterate");
|
|
470
|
+
var ARRAY_ITERATE_KEY = /* @__PURE__ */ Symbol("Array iterate");
|
|
471
|
+
function track(target, type, key) {
|
|
472
|
+
if (shouldTrack && activeSub) {
|
|
473
|
+
let depsMap = targetMap.get(target);
|
|
474
|
+
if (!depsMap) {
|
|
475
|
+
targetMap.set(target, depsMap = /* @__PURE__ */ new Map);
|
|
476
|
+
}
|
|
477
|
+
let dep = depsMap.get(key);
|
|
478
|
+
if (!dep) {
|
|
479
|
+
depsMap.set(key, dep = new Dep);
|
|
480
|
+
dep.map = depsMap;
|
|
481
|
+
dep.key = key;
|
|
482
|
+
}
|
|
483
|
+
if (true) {
|
|
484
|
+
dep.track({
|
|
485
|
+
target,
|
|
486
|
+
type,
|
|
487
|
+
key
|
|
488
|
+
});
|
|
489
|
+
} else {}
|
|
490
|
+
}
|
|
491
|
+
}
|
|
492
|
+
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
493
|
+
const depsMap = targetMap.get(target);
|
|
494
|
+
if (!depsMap) {
|
|
495
|
+
globalVersion++;
|
|
496
|
+
return;
|
|
497
|
+
}
|
|
498
|
+
const run = (dep) => {
|
|
499
|
+
if (dep) {
|
|
500
|
+
if (true) {
|
|
501
|
+
dep.trigger({
|
|
502
|
+
target,
|
|
503
|
+
type,
|
|
504
|
+
key,
|
|
505
|
+
newValue,
|
|
506
|
+
oldValue,
|
|
507
|
+
oldTarget
|
|
508
|
+
});
|
|
509
|
+
} else {}
|
|
510
|
+
}
|
|
511
|
+
};
|
|
512
|
+
startBatch();
|
|
513
|
+
if (type === "clear") {
|
|
514
|
+
depsMap.forEach(run);
|
|
515
|
+
} else {
|
|
516
|
+
const targetIsArray = isArray(target);
|
|
517
|
+
const isArrayIndex = targetIsArray && isIntegerKey(key);
|
|
518
|
+
if (targetIsArray && key === "length") {
|
|
519
|
+
const newLength = Number(newValue);
|
|
520
|
+
depsMap.forEach((dep, key2) => {
|
|
521
|
+
if (key2 === "length" || key2 === ARRAY_ITERATE_KEY || !isSymbol(key2) && key2 >= newLength) {
|
|
522
|
+
run(dep);
|
|
523
|
+
}
|
|
524
|
+
});
|
|
525
|
+
} else {
|
|
526
|
+
if (key !== undefined || depsMap.has(undefined)) {
|
|
527
|
+
run(depsMap.get(key));
|
|
528
|
+
}
|
|
529
|
+
if (isArrayIndex) {
|
|
530
|
+
run(depsMap.get(ARRAY_ITERATE_KEY));
|
|
531
|
+
}
|
|
532
|
+
switch (type) {
|
|
533
|
+
case "add":
|
|
534
|
+
if (!targetIsArray) {
|
|
535
|
+
run(depsMap.get(ITERATE_KEY));
|
|
536
|
+
if (isMap(target)) {
|
|
537
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
538
|
+
}
|
|
539
|
+
} else if (isArrayIndex) {
|
|
540
|
+
run(depsMap.get("length"));
|
|
541
|
+
}
|
|
542
|
+
break;
|
|
543
|
+
case "delete":
|
|
544
|
+
if (!targetIsArray) {
|
|
545
|
+
run(depsMap.get(ITERATE_KEY));
|
|
546
|
+
if (isMap(target)) {
|
|
547
|
+
run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
break;
|
|
551
|
+
case "set":
|
|
552
|
+
if (isMap(target)) {
|
|
553
|
+
run(depsMap.get(ITERATE_KEY));
|
|
554
|
+
}
|
|
555
|
+
break;
|
|
556
|
+
}
|
|
557
|
+
}
|
|
558
|
+
}
|
|
559
|
+
endBatch();
|
|
560
|
+
}
|
|
561
|
+
function reactiveReadArray(array) {
|
|
562
|
+
const raw = toRaw(array);
|
|
563
|
+
if (raw === array)
|
|
564
|
+
return raw;
|
|
565
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
566
|
+
return isShallow(array) ? raw : raw.map(toReactive);
|
|
567
|
+
}
|
|
568
|
+
function shallowReadArray(arr) {
|
|
569
|
+
track(arr = toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
570
|
+
return arr;
|
|
571
|
+
}
|
|
572
|
+
function toWrapped(target, item) {
|
|
573
|
+
if (isReadonly(target)) {
|
|
574
|
+
return isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
|
|
575
|
+
}
|
|
576
|
+
return toReactive(item);
|
|
577
|
+
}
|
|
578
|
+
var arrayInstrumentations = {
|
|
579
|
+
__proto__: null,
|
|
580
|
+
[Symbol.iterator]() {
|
|
581
|
+
return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
|
|
582
|
+
},
|
|
583
|
+
concat(...args) {
|
|
584
|
+
return reactiveReadArray(this).concat(...args.map((x) => isArray(x) ? reactiveReadArray(x) : x));
|
|
585
|
+
},
|
|
586
|
+
entries() {
|
|
587
|
+
return iterator(this, "entries", (value) => {
|
|
588
|
+
value[1] = toWrapped(this, value[1]);
|
|
589
|
+
return value;
|
|
590
|
+
});
|
|
591
|
+
},
|
|
592
|
+
every(fn, thisArg) {
|
|
593
|
+
return apply(this, "every", fn, thisArg, undefined, arguments);
|
|
594
|
+
},
|
|
595
|
+
filter(fn, thisArg) {
|
|
596
|
+
return apply(this, "filter", fn, thisArg, (v) => v.map((item) => toWrapped(this, item)), arguments);
|
|
597
|
+
},
|
|
598
|
+
find(fn, thisArg) {
|
|
599
|
+
return apply(this, "find", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
600
|
+
},
|
|
601
|
+
findIndex(fn, thisArg) {
|
|
602
|
+
return apply(this, "findIndex", fn, thisArg, undefined, arguments);
|
|
603
|
+
},
|
|
604
|
+
findLast(fn, thisArg) {
|
|
605
|
+
return apply(this, "findLast", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
606
|
+
},
|
|
607
|
+
findLastIndex(fn, thisArg) {
|
|
608
|
+
return apply(this, "findLastIndex", fn, thisArg, undefined, arguments);
|
|
609
|
+
},
|
|
610
|
+
forEach(fn, thisArg) {
|
|
611
|
+
return apply(this, "forEach", fn, thisArg, undefined, arguments);
|
|
612
|
+
},
|
|
613
|
+
includes(...args) {
|
|
614
|
+
return searchProxy(this, "includes", args);
|
|
615
|
+
},
|
|
616
|
+
indexOf(...args) {
|
|
617
|
+
return searchProxy(this, "indexOf", args);
|
|
618
|
+
},
|
|
619
|
+
join(separator) {
|
|
620
|
+
return reactiveReadArray(this).join(separator);
|
|
621
|
+
},
|
|
622
|
+
lastIndexOf(...args) {
|
|
623
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
624
|
+
},
|
|
625
|
+
map(fn, thisArg) {
|
|
626
|
+
return apply(this, "map", fn, thisArg, undefined, arguments);
|
|
627
|
+
},
|
|
628
|
+
pop() {
|
|
629
|
+
return noTracking(this, "pop");
|
|
630
|
+
},
|
|
631
|
+
push(...args) {
|
|
632
|
+
return noTracking(this, "push", args);
|
|
633
|
+
},
|
|
634
|
+
reduce(fn, ...args) {
|
|
635
|
+
return reduce(this, "reduce", fn, args);
|
|
636
|
+
},
|
|
637
|
+
reduceRight(fn, ...args) {
|
|
638
|
+
return reduce(this, "reduceRight", fn, args);
|
|
639
|
+
},
|
|
640
|
+
shift() {
|
|
641
|
+
return noTracking(this, "shift");
|
|
642
|
+
},
|
|
643
|
+
some(fn, thisArg) {
|
|
644
|
+
return apply(this, "some", fn, thisArg, undefined, arguments);
|
|
645
|
+
},
|
|
646
|
+
splice(...args) {
|
|
647
|
+
return noTracking(this, "splice", args);
|
|
648
|
+
},
|
|
649
|
+
toReversed() {
|
|
650
|
+
return reactiveReadArray(this).toReversed();
|
|
651
|
+
},
|
|
652
|
+
toSorted(comparer) {
|
|
653
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
654
|
+
},
|
|
655
|
+
toSpliced(...args) {
|
|
656
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
657
|
+
},
|
|
658
|
+
unshift(...args) {
|
|
659
|
+
return noTracking(this, "unshift", args);
|
|
660
|
+
},
|
|
661
|
+
values() {
|
|
662
|
+
return iterator(this, "values", (item) => toWrapped(this, item));
|
|
663
|
+
}
|
|
664
|
+
};
|
|
665
|
+
function iterator(self2, method, wrapValue) {
|
|
666
|
+
const arr = shallowReadArray(self2);
|
|
667
|
+
const iter = arr[method]();
|
|
668
|
+
if (arr !== self2 && !isShallow(self2)) {
|
|
669
|
+
iter._next = iter.next;
|
|
670
|
+
iter.next = () => {
|
|
671
|
+
const result = iter._next();
|
|
672
|
+
if (!result.done) {
|
|
673
|
+
result.value = wrapValue(result.value);
|
|
674
|
+
}
|
|
675
|
+
return result;
|
|
676
|
+
};
|
|
677
|
+
}
|
|
678
|
+
return iter;
|
|
679
|
+
}
|
|
680
|
+
var arrayProto = Array.prototype;
|
|
681
|
+
function apply(self2, method, fn, thisArg, wrappedRetFn, args) {
|
|
682
|
+
const arr = shallowReadArray(self2);
|
|
683
|
+
const needsWrap = arr !== self2 && !isShallow(self2);
|
|
684
|
+
const methodFn = arr[method];
|
|
685
|
+
if (methodFn !== arrayProto[method]) {
|
|
686
|
+
const result2 = methodFn.apply(self2, args);
|
|
687
|
+
return needsWrap ? toReactive(result2) : result2;
|
|
688
|
+
}
|
|
689
|
+
let wrappedFn = fn;
|
|
690
|
+
if (arr !== self2) {
|
|
691
|
+
if (needsWrap) {
|
|
692
|
+
wrappedFn = function(item, index) {
|
|
693
|
+
return fn.call(this, toWrapped(self2, item), index, self2);
|
|
694
|
+
};
|
|
695
|
+
} else if (fn.length > 2) {
|
|
696
|
+
wrappedFn = function(item, index) {
|
|
697
|
+
return fn.call(this, item, index, self2);
|
|
698
|
+
};
|
|
699
|
+
}
|
|
700
|
+
}
|
|
701
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
702
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
703
|
+
}
|
|
704
|
+
function reduce(self2, method, fn, args) {
|
|
705
|
+
const arr = shallowReadArray(self2);
|
|
706
|
+
const needsWrap = arr !== self2 && !isShallow(self2);
|
|
707
|
+
let wrappedFn = fn;
|
|
708
|
+
let wrapInitialAccumulator = false;
|
|
709
|
+
if (arr !== self2) {
|
|
710
|
+
if (needsWrap) {
|
|
711
|
+
wrapInitialAccumulator = args.length === 0;
|
|
712
|
+
wrappedFn = function(acc, item, index) {
|
|
713
|
+
if (wrapInitialAccumulator) {
|
|
714
|
+
wrapInitialAccumulator = false;
|
|
715
|
+
acc = toWrapped(self2, acc);
|
|
716
|
+
}
|
|
717
|
+
return fn.call(this, acc, toWrapped(self2, item), index, self2);
|
|
718
|
+
};
|
|
719
|
+
} else if (fn.length > 3) {
|
|
720
|
+
wrappedFn = function(acc, item, index) {
|
|
721
|
+
return fn.call(this, acc, item, index, self2);
|
|
722
|
+
};
|
|
723
|
+
}
|
|
724
|
+
}
|
|
725
|
+
const result = arr[method](wrappedFn, ...args);
|
|
726
|
+
return wrapInitialAccumulator ? toWrapped(self2, result) : result;
|
|
727
|
+
}
|
|
728
|
+
function searchProxy(self2, method, args) {
|
|
729
|
+
const arr = toRaw(self2);
|
|
730
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
731
|
+
const res = arr[method](...args);
|
|
732
|
+
if ((res === -1 || res === false) && isProxy(args[0])) {
|
|
733
|
+
args[0] = toRaw(args[0]);
|
|
734
|
+
return arr[method](...args);
|
|
735
|
+
}
|
|
736
|
+
return res;
|
|
737
|
+
}
|
|
738
|
+
function noTracking(self2, method, args = []) {
|
|
739
|
+
pauseTracking();
|
|
740
|
+
startBatch();
|
|
741
|
+
const res = toRaw(self2)[method].apply(self2, args);
|
|
742
|
+
endBatch();
|
|
743
|
+
resetTracking();
|
|
744
|
+
return res;
|
|
745
|
+
}
|
|
746
|
+
var isNonTrackableKeys = /* @__PURE__ */ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
747
|
+
var builtInSymbols = new Set(/* @__PURE__ */ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
|
|
748
|
+
function hasOwnProperty2(key) {
|
|
749
|
+
if (!isSymbol(key))
|
|
750
|
+
key = String(key);
|
|
751
|
+
const obj = toRaw(this);
|
|
752
|
+
track(obj, "has", key);
|
|
753
|
+
return obj.hasOwnProperty(key);
|
|
754
|
+
}
|
|
755
|
+
|
|
756
|
+
class BaseReactiveHandler {
|
|
757
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
758
|
+
this._isReadonly = _isReadonly;
|
|
759
|
+
this._isShallow = _isShallow;
|
|
760
|
+
}
|
|
761
|
+
get(target, key, receiver) {
|
|
762
|
+
if (key === "__v_skip")
|
|
763
|
+
return target["__v_skip"];
|
|
764
|
+
const isReadonly2 = this._isReadonly, isShallow2 = this._isShallow;
|
|
765
|
+
if (key === "__v_isReactive") {
|
|
766
|
+
return !isReadonly2;
|
|
767
|
+
} else if (key === "__v_isReadonly") {
|
|
768
|
+
return isReadonly2;
|
|
769
|
+
} else if (key === "__v_isShallow") {
|
|
770
|
+
return isShallow2;
|
|
771
|
+
} else if (key === "__v_raw") {
|
|
772
|
+
if (receiver === (isReadonly2 ? isShallow2 ? shallowReadonlyMap : readonlyMap : isShallow2 ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) {
|
|
773
|
+
return target;
|
|
774
|
+
}
|
|
775
|
+
return;
|
|
776
|
+
}
|
|
777
|
+
const targetIsArray = isArray(target);
|
|
778
|
+
if (!isReadonly2) {
|
|
779
|
+
let fn;
|
|
780
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) {
|
|
781
|
+
return fn;
|
|
782
|
+
}
|
|
783
|
+
if (key === "hasOwnProperty") {
|
|
784
|
+
return hasOwnProperty2;
|
|
785
|
+
}
|
|
786
|
+
}
|
|
787
|
+
const res = Reflect.get(target, key, isRef(target) ? target : receiver);
|
|
788
|
+
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) {
|
|
789
|
+
return res;
|
|
790
|
+
}
|
|
791
|
+
if (!isReadonly2) {
|
|
792
|
+
track(target, "get", key);
|
|
793
|
+
}
|
|
794
|
+
if (isShallow2) {
|
|
795
|
+
return res;
|
|
796
|
+
}
|
|
797
|
+
if (isRef(res)) {
|
|
798
|
+
const value = targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
799
|
+
return isReadonly2 && isObject(value) ? readonly(value) : value;
|
|
800
|
+
}
|
|
801
|
+
if (isObject(res)) {
|
|
802
|
+
return isReadonly2 ? readonly(res) : reactive(res);
|
|
803
|
+
}
|
|
804
|
+
return res;
|
|
805
|
+
}
|
|
806
|
+
}
|
|
807
|
+
|
|
808
|
+
class MutableReactiveHandler extends BaseReactiveHandler {
|
|
809
|
+
constructor(isShallow2 = false) {
|
|
810
|
+
super(false, isShallow2);
|
|
811
|
+
}
|
|
812
|
+
set(target, key, value, receiver) {
|
|
813
|
+
let oldValue = target[key];
|
|
814
|
+
const isArrayWithIntegerKey = isArray(target) && isIntegerKey(key);
|
|
815
|
+
if (!this._isShallow) {
|
|
816
|
+
const isOldValueReadonly = isReadonly(oldValue);
|
|
817
|
+
if (!isShallow(value) && !isReadonly(value)) {
|
|
818
|
+
oldValue = toRaw(oldValue);
|
|
819
|
+
value = toRaw(value);
|
|
820
|
+
}
|
|
821
|
+
if (!isArrayWithIntegerKey && isRef(oldValue) && !isRef(value)) {
|
|
822
|
+
if (isOldValueReadonly) {
|
|
823
|
+
if (true) {
|
|
824
|
+
warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target[key]);
|
|
825
|
+
}
|
|
826
|
+
return true;
|
|
827
|
+
} else {
|
|
828
|
+
oldValue.value = value;
|
|
829
|
+
return true;
|
|
830
|
+
}
|
|
831
|
+
}
|
|
832
|
+
}
|
|
833
|
+
const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
|
|
834
|
+
const result = Reflect.set(target, key, value, isRef(target) ? target : receiver);
|
|
835
|
+
if (target === toRaw(receiver)) {
|
|
836
|
+
if (!hadKey) {
|
|
837
|
+
trigger(target, "add", key, value);
|
|
838
|
+
} else if (hasChanged(value, oldValue)) {
|
|
839
|
+
trigger(target, "set", key, value, oldValue);
|
|
840
|
+
}
|
|
841
|
+
}
|
|
842
|
+
return result;
|
|
843
|
+
}
|
|
844
|
+
deleteProperty(target, key) {
|
|
845
|
+
const hadKey = hasOwn(target, key);
|
|
846
|
+
const oldValue = target[key];
|
|
847
|
+
const result = Reflect.deleteProperty(target, key);
|
|
848
|
+
if (result && hadKey) {
|
|
849
|
+
trigger(target, "delete", key, undefined, oldValue);
|
|
850
|
+
}
|
|
851
|
+
return result;
|
|
852
|
+
}
|
|
853
|
+
has(target, key) {
|
|
854
|
+
const result = Reflect.has(target, key);
|
|
855
|
+
if (!isSymbol(key) || !builtInSymbols.has(key)) {
|
|
856
|
+
track(target, "has", key);
|
|
857
|
+
}
|
|
858
|
+
return result;
|
|
859
|
+
}
|
|
860
|
+
ownKeys(target) {
|
|
861
|
+
track(target, "iterate", isArray(target) ? "length" : ITERATE_KEY);
|
|
862
|
+
return Reflect.ownKeys(target);
|
|
863
|
+
}
|
|
864
|
+
}
|
|
865
|
+
|
|
866
|
+
class ReadonlyReactiveHandler extends BaseReactiveHandler {
|
|
867
|
+
constructor(isShallow2 = false) {
|
|
868
|
+
super(true, isShallow2);
|
|
869
|
+
}
|
|
870
|
+
set(target, key) {
|
|
871
|
+
if (true) {
|
|
872
|
+
warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
873
|
+
}
|
|
874
|
+
return true;
|
|
875
|
+
}
|
|
876
|
+
deleteProperty(target, key) {
|
|
877
|
+
if (true) {
|
|
878
|
+
warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
|
|
879
|
+
}
|
|
880
|
+
return true;
|
|
881
|
+
}
|
|
882
|
+
}
|
|
883
|
+
var mutableHandlers = /* @__PURE__ */ new MutableReactiveHandler;
|
|
884
|
+
var readonlyHandlers = /* @__PURE__ */ new ReadonlyReactiveHandler;
|
|
885
|
+
var toShallow = (value) => value;
|
|
886
|
+
var getProto = (v) => Reflect.getPrototypeOf(v);
|
|
887
|
+
function createIterableMethod(method, isReadonly2, isShallow2) {
|
|
888
|
+
return function(...args) {
|
|
889
|
+
const target = this["__v_raw"];
|
|
890
|
+
const rawTarget = toRaw(target);
|
|
891
|
+
const targetIsMap = isMap(rawTarget);
|
|
892
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
893
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
894
|
+
const innerIterator = target[method](...args);
|
|
895
|
+
const wrap = isShallow2 ? toShallow : isReadonly2 ? toReadonly : toReactive;
|
|
896
|
+
!isReadonly2 && track(rawTarget, "iterate", isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
|
|
897
|
+
return extend(Object.create(innerIterator), {
|
|
898
|
+
next() {
|
|
899
|
+
const { value, done } = innerIterator.next();
|
|
900
|
+
return done ? { value, done } : {
|
|
901
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
902
|
+
done
|
|
903
|
+
};
|
|
904
|
+
}
|
|
905
|
+
});
|
|
906
|
+
};
|
|
907
|
+
}
|
|
908
|
+
function createReadonlyMethod(type) {
|
|
909
|
+
return function(...args) {
|
|
910
|
+
if (true) {
|
|
911
|
+
const key = args[0] ? `on key "${args[0]}" ` : ``;
|
|
912
|
+
warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, toRaw(this));
|
|
913
|
+
}
|
|
914
|
+
return type === "delete" ? false : type === "clear" ? undefined : this;
|
|
915
|
+
};
|
|
916
|
+
}
|
|
917
|
+
function createInstrumentations(readonly, shallow) {
|
|
918
|
+
const instrumentations = {
|
|
919
|
+
get(key) {
|
|
920
|
+
const target = this["__v_raw"];
|
|
921
|
+
const rawTarget = toRaw(target);
|
|
922
|
+
const rawKey = toRaw(key);
|
|
923
|
+
if (!readonly) {
|
|
924
|
+
if (hasChanged(key, rawKey)) {
|
|
925
|
+
track(rawTarget, "get", key);
|
|
926
|
+
}
|
|
927
|
+
track(rawTarget, "get", rawKey);
|
|
928
|
+
}
|
|
929
|
+
const { has } = getProto(rawTarget);
|
|
930
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
931
|
+
if (has.call(rawTarget, key)) {
|
|
932
|
+
return wrap(target.get(key));
|
|
933
|
+
} else if (has.call(rawTarget, rawKey)) {
|
|
934
|
+
return wrap(target.get(rawKey));
|
|
935
|
+
} else if (target !== rawTarget) {
|
|
936
|
+
target.get(key);
|
|
937
|
+
}
|
|
938
|
+
},
|
|
939
|
+
get size() {
|
|
940
|
+
const target = this["__v_raw"];
|
|
941
|
+
!readonly && track(toRaw(target), "iterate", ITERATE_KEY);
|
|
942
|
+
return target.size;
|
|
943
|
+
},
|
|
944
|
+
has(key) {
|
|
945
|
+
const target = this["__v_raw"];
|
|
946
|
+
const rawTarget = toRaw(target);
|
|
947
|
+
const rawKey = toRaw(key);
|
|
948
|
+
if (!readonly) {
|
|
949
|
+
if (hasChanged(key, rawKey)) {
|
|
950
|
+
track(rawTarget, "has", key);
|
|
951
|
+
}
|
|
952
|
+
track(rawTarget, "has", rawKey);
|
|
953
|
+
}
|
|
954
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
955
|
+
},
|
|
956
|
+
forEach(callback, thisArg) {
|
|
957
|
+
const observed = this;
|
|
958
|
+
const target = observed["__v_raw"];
|
|
959
|
+
const rawTarget = toRaw(target);
|
|
960
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
961
|
+
!readonly && track(rawTarget, "iterate", ITERATE_KEY);
|
|
962
|
+
return target.forEach((value, key) => {
|
|
963
|
+
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
|
964
|
+
});
|
|
965
|
+
}
|
|
966
|
+
};
|
|
967
|
+
extend(instrumentations, readonly ? {
|
|
968
|
+
add: createReadonlyMethod("add"),
|
|
969
|
+
set: createReadonlyMethod("set"),
|
|
970
|
+
delete: createReadonlyMethod("delete"),
|
|
971
|
+
clear: createReadonlyMethod("clear")
|
|
972
|
+
} : {
|
|
973
|
+
add(value) {
|
|
974
|
+
const target = toRaw(this);
|
|
975
|
+
const proto = getProto(target);
|
|
976
|
+
const rawValue = toRaw(value);
|
|
977
|
+
const valueToAdd = !shallow && !isShallow(value) && !isReadonly(value) ? rawValue : value;
|
|
978
|
+
const hadKey = proto.has.call(target, valueToAdd) || hasChanged(value, valueToAdd) && proto.has.call(target, value) || hasChanged(rawValue, valueToAdd) && proto.has.call(target, rawValue);
|
|
979
|
+
if (!hadKey) {
|
|
980
|
+
target.add(valueToAdd);
|
|
981
|
+
trigger(target, "add", valueToAdd, valueToAdd);
|
|
982
|
+
}
|
|
983
|
+
return this;
|
|
984
|
+
},
|
|
985
|
+
set(key, value) {
|
|
986
|
+
if (!shallow && !isShallow(value) && !isReadonly(value)) {
|
|
987
|
+
value = toRaw(value);
|
|
988
|
+
}
|
|
989
|
+
const target = toRaw(this);
|
|
990
|
+
const { has, get } = getProto(target);
|
|
991
|
+
let hadKey = has.call(target, key);
|
|
992
|
+
if (!hadKey) {
|
|
993
|
+
key = toRaw(key);
|
|
994
|
+
hadKey = has.call(target, key);
|
|
995
|
+
} else if (true) {
|
|
996
|
+
checkIdentityKeys(target, has, key);
|
|
997
|
+
}
|
|
998
|
+
const oldValue = get.call(target, key);
|
|
999
|
+
target.set(key, value);
|
|
1000
|
+
if (!hadKey) {
|
|
1001
|
+
trigger(target, "add", key, value);
|
|
1002
|
+
} else if (hasChanged(value, oldValue)) {
|
|
1003
|
+
trigger(target, "set", key, value, oldValue);
|
|
1004
|
+
}
|
|
1005
|
+
return this;
|
|
1006
|
+
},
|
|
1007
|
+
delete(key) {
|
|
1008
|
+
const target = toRaw(this);
|
|
1009
|
+
const { has, get } = getProto(target);
|
|
1010
|
+
let hadKey = has.call(target, key);
|
|
1011
|
+
if (!hadKey) {
|
|
1012
|
+
key = toRaw(key);
|
|
1013
|
+
hadKey = has.call(target, key);
|
|
1014
|
+
} else if (true) {
|
|
1015
|
+
checkIdentityKeys(target, has, key);
|
|
1016
|
+
}
|
|
1017
|
+
const oldValue = get ? get.call(target, key) : undefined;
|
|
1018
|
+
const result = target.delete(key);
|
|
1019
|
+
if (hadKey) {
|
|
1020
|
+
trigger(target, "delete", key, undefined, oldValue);
|
|
1021
|
+
}
|
|
1022
|
+
return result;
|
|
1023
|
+
},
|
|
1024
|
+
clear() {
|
|
1025
|
+
const target = toRaw(this);
|
|
1026
|
+
const hadItems = target.size !== 0;
|
|
1027
|
+
const oldTarget = isMap(target) ? new Map(target) : new Set(target);
|
|
1028
|
+
const result = target.clear();
|
|
1029
|
+
if (hadItems) {
|
|
1030
|
+
trigger(target, "clear", undefined, undefined, oldTarget);
|
|
1031
|
+
}
|
|
1032
|
+
return result;
|
|
1033
|
+
}
|
|
1034
|
+
});
|
|
1035
|
+
const iteratorMethods = [
|
|
1036
|
+
"keys",
|
|
1037
|
+
"values",
|
|
1038
|
+
"entries",
|
|
1039
|
+
Symbol.iterator
|
|
1040
|
+
];
|
|
1041
|
+
iteratorMethods.forEach((method) => {
|
|
1042
|
+
instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
|
1043
|
+
});
|
|
1044
|
+
return instrumentations;
|
|
1045
|
+
}
|
|
1046
|
+
function createInstrumentationGetter(isReadonly2, shallow) {
|
|
1047
|
+
const instrumentations = createInstrumentations(isReadonly2, shallow);
|
|
1048
|
+
return (target, key, receiver) => {
|
|
1049
|
+
if (key === "__v_isReactive") {
|
|
1050
|
+
return !isReadonly2;
|
|
1051
|
+
} else if (key === "__v_isReadonly") {
|
|
1052
|
+
return isReadonly2;
|
|
1053
|
+
} else if (key === "__v_raw") {
|
|
1054
|
+
return target;
|
|
1055
|
+
}
|
|
1056
|
+
return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver);
|
|
1057
|
+
};
|
|
1058
|
+
}
|
|
1059
|
+
var mutableCollectionHandlers = {
|
|
1060
|
+
get: /* @__PURE__ */ createInstrumentationGetter(false, false)
|
|
1061
|
+
};
|
|
1062
|
+
var readonlyCollectionHandlers = {
|
|
1063
|
+
get: /* @__PURE__ */ createInstrumentationGetter(true, false)
|
|
1064
|
+
};
|
|
1065
|
+
function checkIdentityKeys(target, has, key) {
|
|
1066
|
+
const rawKey = toRaw(key);
|
|
1067
|
+
if (rawKey !== key && has.call(target, rawKey)) {
|
|
1068
|
+
const type = toRawType(target);
|
|
1069
|
+
warn(`Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`);
|
|
1070
|
+
}
|
|
1071
|
+
}
|
|
1072
|
+
var reactiveMap = /* @__PURE__ */ new WeakMap;
|
|
1073
|
+
var shallowReactiveMap = /* @__PURE__ */ new WeakMap;
|
|
1074
|
+
var readonlyMap = /* @__PURE__ */ new WeakMap;
|
|
1075
|
+
var shallowReadonlyMap = /* @__PURE__ */ new WeakMap;
|
|
1076
|
+
function targetTypeMap(rawType) {
|
|
1077
|
+
switch (rawType) {
|
|
1078
|
+
case "Object":
|
|
1079
|
+
case "Array":
|
|
1080
|
+
return 1;
|
|
1081
|
+
case "Map":
|
|
1082
|
+
case "Set":
|
|
1083
|
+
case "WeakMap":
|
|
1084
|
+
case "WeakSet":
|
|
1085
|
+
return 2;
|
|
1086
|
+
default:
|
|
1087
|
+
return 0;
|
|
1088
|
+
}
|
|
1089
|
+
}
|
|
1090
|
+
function getTargetType(value) {
|
|
1091
|
+
return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
|
|
1092
|
+
}
|
|
1093
|
+
function reactive(target) {
|
|
1094
|
+
if (/* @__PURE__ */ isReadonly(target)) {
|
|
1095
|
+
return target;
|
|
1096
|
+
}
|
|
1097
|
+
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
|
|
1098
|
+
}
|
|
1099
|
+
function readonly(target) {
|
|
1100
|
+
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
|
|
1101
|
+
}
|
|
1102
|
+
function createReactiveObject(target, isReadonly2, baseHandlers, collectionHandlers, proxyMap) {
|
|
1103
|
+
if (!isObject(target)) {
|
|
1104
|
+
if (true) {
|
|
1105
|
+
warn(`value cannot be made ${isReadonly2 ? "readonly" : "reactive"}: ${String(target)}`);
|
|
1106
|
+
}
|
|
1107
|
+
return target;
|
|
1108
|
+
}
|
|
1109
|
+
if (target["__v_raw"] && !(isReadonly2 && target["__v_isReactive"])) {
|
|
1110
|
+
return target;
|
|
1111
|
+
}
|
|
1112
|
+
const targetType = getTargetType(target);
|
|
1113
|
+
if (targetType === 0) {
|
|
1114
|
+
return target;
|
|
1115
|
+
}
|
|
1116
|
+
const existingProxy = proxyMap.get(target);
|
|
1117
|
+
if (existingProxy) {
|
|
1118
|
+
return existingProxy;
|
|
1119
|
+
}
|
|
1120
|
+
const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
|
|
1121
|
+
proxyMap.set(target, proxy);
|
|
1122
|
+
return proxy;
|
|
1123
|
+
}
|
|
1124
|
+
function isReactive(value) {
|
|
1125
|
+
if (/* @__PURE__ */ isReadonly(value)) {
|
|
1126
|
+
return /* @__PURE__ */ isReactive(value["__v_raw"]);
|
|
1127
|
+
}
|
|
1128
|
+
return !!(value && value["__v_isReactive"]);
|
|
1129
|
+
}
|
|
1130
|
+
function isReadonly(value) {
|
|
1131
|
+
return !!(value && value["__v_isReadonly"]);
|
|
1132
|
+
}
|
|
1133
|
+
function isShallow(value) {
|
|
1134
|
+
return !!(value && value["__v_isShallow"]);
|
|
1135
|
+
}
|
|
1136
|
+
function isProxy(value) {
|
|
1137
|
+
return value ? !!value["__v_raw"] : false;
|
|
1138
|
+
}
|
|
1139
|
+
function toRaw(observed) {
|
|
1140
|
+
const raw = observed && observed["__v_raw"];
|
|
1141
|
+
return raw ? /* @__PURE__ */ toRaw(raw) : observed;
|
|
1142
|
+
}
|
|
1143
|
+
var toReactive = (value) => isObject(value) ? /* @__PURE__ */ reactive(value) : value;
|
|
1144
|
+
var toReadonly = (value) => isObject(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
1145
|
+
function isRef(r) {
|
|
1146
|
+
return r ? r["__v_isRef"] === true : false;
|
|
1147
|
+
}
|
|
1148
|
+
function ref(value) {
|
|
1149
|
+
return createRef(value, false);
|
|
1150
|
+
}
|
|
1151
|
+
function createRef(rawValue, shallow) {
|
|
1152
|
+
if (/* @__PURE__ */ isRef(rawValue)) {
|
|
1153
|
+
return rawValue;
|
|
1154
|
+
}
|
|
1155
|
+
return new RefImpl(rawValue, shallow);
|
|
1156
|
+
}
|
|
1157
|
+
|
|
1158
|
+
class RefImpl {
|
|
1159
|
+
constructor(value, isShallow2) {
|
|
1160
|
+
this.dep = new Dep;
|
|
1161
|
+
this["__v_isRef"] = true;
|
|
1162
|
+
this["__v_isShallow"] = false;
|
|
1163
|
+
this._rawValue = isShallow2 ? value : toRaw(value);
|
|
1164
|
+
this._value = isShallow2 ? value : toReactive(value);
|
|
1165
|
+
this["__v_isShallow"] = isShallow2;
|
|
1166
|
+
}
|
|
1167
|
+
get value() {
|
|
1168
|
+
if (true) {
|
|
1169
|
+
this.dep.track({
|
|
1170
|
+
target: this,
|
|
1171
|
+
type: "get",
|
|
1172
|
+
key: "value"
|
|
1173
|
+
});
|
|
1174
|
+
} else {}
|
|
1175
|
+
return this._value;
|
|
1176
|
+
}
|
|
1177
|
+
set value(newValue) {
|
|
1178
|
+
const oldValue = this._rawValue;
|
|
1179
|
+
const useDirectValue = this["__v_isShallow"] || isShallow(newValue) || isReadonly(newValue);
|
|
1180
|
+
newValue = useDirectValue ? newValue : toRaw(newValue);
|
|
1181
|
+
if (hasChanged(newValue, oldValue)) {
|
|
1182
|
+
this._rawValue = newValue;
|
|
1183
|
+
this._value = useDirectValue ? newValue : toReactive(newValue);
|
|
1184
|
+
if (true) {
|
|
1185
|
+
this.dep.trigger({
|
|
1186
|
+
target: this,
|
|
1187
|
+
type: "set",
|
|
1188
|
+
key: "value",
|
|
1189
|
+
newValue,
|
|
1190
|
+
oldValue
|
|
1191
|
+
});
|
|
1192
|
+
} else {}
|
|
1193
|
+
}
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
class ComputedRefImpl {
|
|
1197
|
+
constructor(fn, setter, isSSR) {
|
|
1198
|
+
this.fn = fn;
|
|
1199
|
+
this.setter = setter;
|
|
1200
|
+
this._value = undefined;
|
|
1201
|
+
this.dep = new Dep(this);
|
|
1202
|
+
this.__v_isRef = true;
|
|
1203
|
+
this.deps = undefined;
|
|
1204
|
+
this.depsTail = undefined;
|
|
1205
|
+
this.flags = 16;
|
|
1206
|
+
this.globalVersion = globalVersion - 1;
|
|
1207
|
+
this.next = undefined;
|
|
1208
|
+
this.effect = this;
|
|
1209
|
+
this["__v_isReadonly"] = !setter;
|
|
1210
|
+
this.isSSR = isSSR;
|
|
1211
|
+
}
|
|
1212
|
+
notify() {
|
|
1213
|
+
this.flags |= 16;
|
|
1214
|
+
if (!(this.flags & 8) && activeSub !== this) {
|
|
1215
|
+
batch(this, true);
|
|
1216
|
+
return true;
|
|
1217
|
+
} else if (true)
|
|
1218
|
+
;
|
|
1219
|
+
}
|
|
1220
|
+
get value() {
|
|
1221
|
+
const link = this.dep.track({
|
|
1222
|
+
target: this,
|
|
1223
|
+
type: "get",
|
|
1224
|
+
key: "value"
|
|
1225
|
+
});
|
|
1226
|
+
refreshComputed(this);
|
|
1227
|
+
if (link) {
|
|
1228
|
+
link.version = this.dep.version;
|
|
1229
|
+
}
|
|
1230
|
+
return this._value;
|
|
1231
|
+
}
|
|
1232
|
+
set value(newValue) {
|
|
1233
|
+
if (this.setter) {
|
|
1234
|
+
this.setter(newValue);
|
|
1235
|
+
} else if (true) {
|
|
1236
|
+
warn("Write operation failed: computed value is readonly");
|
|
1237
|
+
}
|
|
1238
|
+
}
|
|
1239
|
+
}
|
|
1240
|
+
function computed(getterOrOptions, debugOptions, isSSR = false) {
|
|
1241
|
+
let getter;
|
|
1242
|
+
let setter;
|
|
1243
|
+
if (isFunction(getterOrOptions)) {
|
|
1244
|
+
getter = getterOrOptions;
|
|
1245
|
+
} else {
|
|
1246
|
+
getter = getterOrOptions.get;
|
|
1247
|
+
setter = getterOrOptions.set;
|
|
1248
|
+
}
|
|
1249
|
+
const cRef = new ComputedRefImpl(getter, setter, isSSR);
|
|
1250
|
+
if (debugOptions && !isSSR) {
|
|
1251
|
+
cRef.onTrack = debugOptions.onTrack;
|
|
1252
|
+
cRef.onTrigger = debugOptions.onTrigger;
|
|
1253
|
+
}
|
|
1254
|
+
return cRef;
|
|
1255
|
+
}
|
|
1256
|
+
|
|
1257
|
+
// src/runtime.js
|
|
1258
|
+
async function Jx(source, target = document.body, options) {
|
|
1259
|
+
const base = typeof source === "string" ? new URL(source, location.href).href : location.href;
|
|
1260
|
+
const doc = await resolve(source);
|
|
1261
|
+
if (doc.$elements) {
|
|
1262
|
+
await registerElements(doc.$elements, base);
|
|
1263
|
+
}
|
|
1264
|
+
if (doc.$head) {
|
|
1265
|
+
injectHead(doc.$head, base);
|
|
1266
|
+
}
|
|
1267
|
+
const state = await buildScope(doc, {}, base);
|
|
1268
|
+
target.appendChild(renderNode(doc, state, options));
|
|
1269
|
+
if (typeof state.onMount === "function")
|
|
1270
|
+
state.onMount(state);
|
|
1271
|
+
return state;
|
|
1272
|
+
}
|
|
1273
|
+
async function resolve(source) {
|
|
1274
|
+
if (typeof source !== "string")
|
|
1275
|
+
return source;
|
|
1276
|
+
const res = await fetch(source);
|
|
1277
|
+
if (!res.ok)
|
|
1278
|
+
throw new Error(`Jx: failed to fetch ${source} (${res.status})`);
|
|
1279
|
+
return res.json();
|
|
1280
|
+
}
|
|
1281
|
+
var SCHEMA_KEYWORDS = new Set([
|
|
1282
|
+
"type",
|
|
1283
|
+
"properties",
|
|
1284
|
+
"items",
|
|
1285
|
+
"enum",
|
|
1286
|
+
"minimum",
|
|
1287
|
+
"maximum",
|
|
1288
|
+
"minLength",
|
|
1289
|
+
"maxLength",
|
|
1290
|
+
"pattern",
|
|
1291
|
+
"required",
|
|
1292
|
+
"examples"
|
|
1293
|
+
]);
|
|
1294
|
+
async function buildScope(doc, parentScope = {}, base = location.href) {
|
|
1295
|
+
const raw = {};
|
|
1296
|
+
for (const [key, val] of Object.entries(parentScope)) {
|
|
1297
|
+
raw[key] = val;
|
|
1298
|
+
}
|
|
1299
|
+
const defs = doc.state ?? {};
|
|
1300
|
+
const imports = doc.imports ?? {};
|
|
1301
|
+
for (const [, def2] of Object.entries(defs)) {
|
|
1302
|
+
if (def2 && typeof def2 === "object" && !Array.isArray(def2) && def2.$prototype && def2.$prototype !== "Function" && !def2.$src) {
|
|
1303
|
+
const mapped = imports[def2.$prototype];
|
|
1304
|
+
if (mapped) {
|
|
1305
|
+
if (typeof mapped !== "string" || !mapped.endsWith(".class.json")) {
|
|
1306
|
+
console.warn(`Jx: import "${def2.$prototype}" must map to a .class.json path, got "${mapped}"`);
|
|
1307
|
+
continue;
|
|
1308
|
+
}
|
|
1309
|
+
def2.$src = mapped;
|
|
1310
|
+
}
|
|
1311
|
+
}
|
|
1312
|
+
}
|
|
1313
|
+
for (const [key, def2] of Object.entries(defs)) {
|
|
1314
|
+
if (typeof def2 === "string") {
|
|
1315
|
+
if (!def2.includes("${"))
|
|
1316
|
+
raw[key] = def2;
|
|
1317
|
+
continue;
|
|
1318
|
+
}
|
|
1319
|
+
if (typeof def2 === "number" || typeof def2 === "boolean" || def2 === null) {
|
|
1320
|
+
raw[key] = def2;
|
|
1321
|
+
continue;
|
|
1322
|
+
}
|
|
1323
|
+
if (Array.isArray(def2)) {
|
|
1324
|
+
raw[key] = def2;
|
|
1325
|
+
continue;
|
|
1326
|
+
}
|
|
1327
|
+
if (typeof def2 === "object") {
|
|
1328
|
+
if (def2.$prototype)
|
|
1329
|
+
continue;
|
|
1330
|
+
if (def2.timing === "server" && def2.$src && def2.$export)
|
|
1331
|
+
continue;
|
|
1332
|
+
if ("default" in def2) {
|
|
1333
|
+
raw[key] = def2.default;
|
|
1334
|
+
continue;
|
|
1335
|
+
}
|
|
1336
|
+
if (hasSchemaKeywords(def2))
|
|
1337
|
+
continue;
|
|
1338
|
+
raw[key] = def2;
|
|
1339
|
+
}
|
|
1340
|
+
}
|
|
1341
|
+
const state = reactive(raw);
|
|
1342
|
+
for (const [key, def2] of Object.entries(defs)) {
|
|
1343
|
+
if (typeof def2 === "string" && def2.includes("${")) {
|
|
1344
|
+
state[key] = computed(() => evaluateTemplate(def2, state));
|
|
1345
|
+
}
|
|
1346
|
+
}
|
|
1347
|
+
for (const [key, def2] of Object.entries(defs)) {
|
|
1348
|
+
if (typeof def2 === "object" && def2?.$prototype === "Function") {
|
|
1349
|
+
state[key] = await resolveFunction(def2, state, key, base);
|
|
1350
|
+
}
|
|
1351
|
+
}
|
|
1352
|
+
for (const [key, def2] of Object.entries(defs)) {
|
|
1353
|
+
if (typeof def2 === "object" && def2?.$prototype && def2.$prototype !== "Function") {
|
|
1354
|
+
state[key] = await resolvePrototype(def2, state, key, base);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
for (const [key, def2] of Object.entries(defs)) {
|
|
1358
|
+
if (def2 != null && typeof def2 === "object" && def2.timing === "server" && def2.$src && def2.$export && !def2.$prototype) {
|
|
1359
|
+
state[key] = await resolveServerFunction(def2, state, key, base);
|
|
1360
|
+
}
|
|
1361
|
+
}
|
|
1362
|
+
if (doc.$media) {
|
|
1363
|
+
state["$media"] = doc.$media;
|
|
1364
|
+
}
|
|
1365
|
+
return state;
|
|
1366
|
+
}
|
|
1367
|
+
function hasSchemaKeywords(obj) {
|
|
1368
|
+
for (const k of Object.keys(obj)) {
|
|
1369
|
+
if (SCHEMA_KEYWORDS.has(k))
|
|
1370
|
+
return true;
|
|
1371
|
+
}
|
|
1372
|
+
return false;
|
|
1373
|
+
}
|
|
1374
|
+
function evaluateTemplate(str, state) {
|
|
1375
|
+
const fn = new Function("state", "$map", `return \`${str}\``);
|
|
1376
|
+
return fn(state, state?.$map);
|
|
1377
|
+
}
|
|
1378
|
+
var _moduleCache = new Map;
|
|
1379
|
+
async function resolveFunction(def2, state, key, base) {
|
|
1380
|
+
if (def2.body && def2.$src) {
|
|
1381
|
+
throw new Error(`Jx: '${key}' declares both body and $src — these are mutually exclusive`);
|
|
1382
|
+
}
|
|
1383
|
+
if (!def2.body && !def2.$src) {
|
|
1384
|
+
throw new Error(`Jx: '${key}' is a Function prototype with no body or $src`);
|
|
1385
|
+
}
|
|
1386
|
+
let fn;
|
|
1387
|
+
if (def2.body) {
|
|
1388
|
+
const params = resolveParamNames(def2);
|
|
1389
|
+
fn = new Function(...params, def2.body);
|
|
1390
|
+
Object.defineProperty(fn, "name", { value: def2.name ?? key, configurable: true });
|
|
1391
|
+
} else {
|
|
1392
|
+
const src = def2.$src;
|
|
1393
|
+
const exportName = def2.$export ?? key;
|
|
1394
|
+
let mod;
|
|
1395
|
+
if (_moduleCache.has(src)) {
|
|
1396
|
+
mod = _moduleCache.get(src);
|
|
1397
|
+
} else {
|
|
1398
|
+
try {
|
|
1399
|
+
mod = await import(src);
|
|
1400
|
+
} catch {
|
|
1401
|
+
if (base) {
|
|
1402
|
+
const resolvedSrc = new URL(src, base).href;
|
|
1403
|
+
mod = await import(resolvedSrc);
|
|
1404
|
+
} else {
|
|
1405
|
+
throw new Error(`Jx: failed to import '$src' "${src}" for "${key}"`);
|
|
1406
|
+
}
|
|
1407
|
+
}
|
|
1408
|
+
_moduleCache.set(src, mod);
|
|
1409
|
+
}
|
|
1410
|
+
fn = mod[exportName] ?? mod.default?.[exportName];
|
|
1411
|
+
if (typeof fn !== "function") {
|
|
1412
|
+
throw new Error(`Jx: export "${exportName}" not found or not a function in "${src}"`);
|
|
1413
|
+
}
|
|
1414
|
+
}
|
|
1415
|
+
if (def2.body && /\breturn\b/.test(def2.body)) {
|
|
1416
|
+
return computed(() => fn(state));
|
|
1417
|
+
}
|
|
1418
|
+
return fn;
|
|
1419
|
+
}
|
|
1420
|
+
function resolveParamNames(def2) {
|
|
1421
|
+
const raw = def2.parameters ?? def2.arguments ?? [];
|
|
1422
|
+
let names;
|
|
1423
|
+
if (Array.isArray(raw) && raw.length > 0 && typeof raw[0] === "object") {
|
|
1424
|
+
names = raw.map((p) => p.name ?? p.identifier ?? "arg");
|
|
1425
|
+
} else {
|
|
1426
|
+
names = raw;
|
|
1427
|
+
}
|
|
1428
|
+
return names.length > 0 && names[0] === "state" ? names : ["state", ...names];
|
|
1429
|
+
}
|
|
1430
|
+
var RESERVED_KEYS = new Set([
|
|
1431
|
+
"$schema",
|
|
1432
|
+
"$id",
|
|
1433
|
+
"$defs",
|
|
1434
|
+
"state",
|
|
1435
|
+
"$ref",
|
|
1436
|
+
"$props",
|
|
1437
|
+
"$elements",
|
|
1438
|
+
"$switch",
|
|
1439
|
+
"$prototype",
|
|
1440
|
+
"$src",
|
|
1441
|
+
"$export",
|
|
1442
|
+
"$media",
|
|
1443
|
+
"$map",
|
|
1444
|
+
"timing",
|
|
1445
|
+
"default",
|
|
1446
|
+
"description",
|
|
1447
|
+
"body",
|
|
1448
|
+
"parameters",
|
|
1449
|
+
"arguments",
|
|
1450
|
+
"name",
|
|
1451
|
+
"tagName",
|
|
1452
|
+
"children",
|
|
1453
|
+
"style",
|
|
1454
|
+
"attributes",
|
|
1455
|
+
"items",
|
|
1456
|
+
"map",
|
|
1457
|
+
"filter",
|
|
1458
|
+
"sort",
|
|
1459
|
+
"cases",
|
|
1460
|
+
"observedAttributes"
|
|
1461
|
+
]);
|
|
1462
|
+
function renderNode(def2, state, options) {
|
|
1463
|
+
const path = options?._path ?? [];
|
|
1464
|
+
if (typeof def2 === "string" || typeof def2 === "number" || typeof def2 === "boolean") {
|
|
1465
|
+
const textNode = document.createTextNode(String(def2));
|
|
1466
|
+
if (typeof def2 === "string" && isTemplateString(def2)) {
|
|
1467
|
+
effect(() => {
|
|
1468
|
+
textNode.textContent = evaluateTemplate(def2, state);
|
|
1469
|
+
});
|
|
1470
|
+
}
|
|
1471
|
+
return textNode;
|
|
1472
|
+
}
|
|
1473
|
+
let localState = state;
|
|
1474
|
+
for (const [key, val] of Object.entries(def2)) {
|
|
1475
|
+
if (key.startsWith("$") && !RESERVED_KEYS.has(key)) {
|
|
1476
|
+
if (localState === state)
|
|
1477
|
+
localState = Object.create(state);
|
|
1478
|
+
localState[key] = isRefObj(val) ? resolveRef(val.$ref, state) : val;
|
|
1479
|
+
}
|
|
1480
|
+
}
|
|
1481
|
+
const tagName = def2.tagName ?? "div";
|
|
1482
|
+
const isCustomEl = tagName.includes("-") && customElements.get(tagName);
|
|
1483
|
+
if (def2.$props && isCustomEl) {
|
|
1484
|
+
return renderCustomElementWithProps(def2, localState, options, path);
|
|
1485
|
+
}
|
|
1486
|
+
if (def2.$props) {
|
|
1487
|
+
const { $props: _$props, ...rest } = def2;
|
|
1488
|
+
return renderNode(rest, mergeProps(def2, localState), options);
|
|
1489
|
+
}
|
|
1490
|
+
if (def2.$switch)
|
|
1491
|
+
return renderSwitch(def2, localState, options);
|
|
1492
|
+
if (def2.children?.$prototype === "Array")
|
|
1493
|
+
return renderMappedArray(def2, localState, options);
|
|
1494
|
+
const el = document.createElement(tagName);
|
|
1495
|
+
if (options?.onNodeCreated)
|
|
1496
|
+
options.onNodeCreated(el, path, def2);
|
|
1497
|
+
applyProperties(el, def2, localState);
|
|
1498
|
+
applyStyle(el, def2.style ?? {}, localState["$media"] ?? {}, localState);
|
|
1499
|
+
applyAttributes(el, def2.attributes ?? {}, localState);
|
|
1500
|
+
const children = Array.isArray(def2.children) ? def2.children : [];
|
|
1501
|
+
for (let i = 0;i < children.length; i++) {
|
|
1502
|
+
const childOpts = options ? { ...options, _path: [...path, "children", i] } : undefined;
|
|
1503
|
+
el.appendChild(renderNode(children[i], localState, childOpts));
|
|
1504
|
+
}
|
|
1505
|
+
return el;
|
|
1506
|
+
}
|
|
1507
|
+
function isTemplateString(val) {
|
|
1508
|
+
return typeof val === "string" && val.includes("${");
|
|
1509
|
+
}
|
|
1510
|
+
function applyProperties(el, def2, state) {
|
|
1511
|
+
for (const [key, val] of Object.entries(def2)) {
|
|
1512
|
+
if (RESERVED_KEYS.has(key))
|
|
1513
|
+
continue;
|
|
1514
|
+
if (key.startsWith("$"))
|
|
1515
|
+
continue;
|
|
1516
|
+
if (key.startsWith("on")) {
|
|
1517
|
+
if (isRefObj(val)) {
|
|
1518
|
+
const handler = resolveRef(val.$ref, state);
|
|
1519
|
+
if (typeof handler === "function") {
|
|
1520
|
+
const scope = state;
|
|
1521
|
+
el.addEventListener(key.slice(2), (e) => handler(scope, e));
|
|
1522
|
+
}
|
|
1523
|
+
continue;
|
|
1524
|
+
}
|
|
1525
|
+
if (val && typeof val === "object" && val.$prototype === "Function" && val.body) {
|
|
1526
|
+
const params = resolveParamNames(val);
|
|
1527
|
+
const fn = new Function(...params, val.body);
|
|
1528
|
+
const scope = state;
|
|
1529
|
+
el.addEventListener(key.slice(2), (e) => fn(scope, e));
|
|
1530
|
+
continue;
|
|
1531
|
+
}
|
|
1532
|
+
}
|
|
1533
|
+
bindProperty(el, key, val, state);
|
|
1534
|
+
}
|
|
1535
|
+
}
|
|
1536
|
+
function bindProperty(el, key, val, state) {
|
|
1537
|
+
if (isRefObj(val)) {
|
|
1538
|
+
if (key === "id") {
|
|
1539
|
+
el[key] = resolveRef(val.$ref, state);
|
|
1540
|
+
return;
|
|
1541
|
+
}
|
|
1542
|
+
effect(() => {
|
|
1543
|
+
el[key] = resolveRef(val.$ref, state);
|
|
1544
|
+
});
|
|
1545
|
+
return;
|
|
1546
|
+
}
|
|
1547
|
+
if (isTemplateString(val)) {
|
|
1548
|
+
effect(() => {
|
|
1549
|
+
el[key] = evaluateTemplate(val, state);
|
|
1550
|
+
});
|
|
1551
|
+
return;
|
|
1552
|
+
}
|
|
1553
|
+
el[key] = val;
|
|
1554
|
+
}
|
|
1555
|
+
function applyStyle(el, styleDef, mediaQueries = {}, state = {}) {
|
|
1556
|
+
const nested = {};
|
|
1557
|
+
const media = {};
|
|
1558
|
+
for (const [prop, val] of Object.entries(styleDef)) {
|
|
1559
|
+
if (prop.startsWith("@"))
|
|
1560
|
+
media[prop] = val;
|
|
1561
|
+
else if (isNestedSelector(prop))
|
|
1562
|
+
nested[prop] = val;
|
|
1563
|
+
else if (prop.startsWith("--")) {
|
|
1564
|
+
if (isTemplateString(val))
|
|
1565
|
+
effect(() => {
|
|
1566
|
+
el.style.setProperty(prop, evaluateTemplate(val, state));
|
|
1567
|
+
});
|
|
1568
|
+
else
|
|
1569
|
+
el.style.setProperty(prop, val);
|
|
1570
|
+
} else if (isTemplateString(val))
|
|
1571
|
+
effect(() => {
|
|
1572
|
+
el.style[prop] = evaluateTemplate(val, state);
|
|
1573
|
+
});
|
|
1574
|
+
else
|
|
1575
|
+
el.style[prop] = val;
|
|
1576
|
+
}
|
|
1577
|
+
const hasNested = Object.keys(nested).length > 0;
|
|
1578
|
+
const hasMedia = Object.keys(media).length > 0;
|
|
1579
|
+
if (!hasNested && !hasMedia)
|
|
1580
|
+
return;
|
|
1581
|
+
const uid = `jx-${Math.random().toString(36).slice(2, 7)}`;
|
|
1582
|
+
el.dataset.jx = uid;
|
|
1583
|
+
let css = "";
|
|
1584
|
+
for (const [sel, rules] of Object.entries(nested)) {
|
|
1585
|
+
const resolved = sel.startsWith("&") ? sel.replace("&", `[data-jx="${uid}"]`) : sel.startsWith("[") ? `[data-jx="${uid}"]${sel}` : `[data-jx="${uid}"] ${sel}`;
|
|
1586
|
+
css += `${resolved} { ${toCSSText(rules)} }
|
|
1587
|
+
`;
|
|
1588
|
+
}
|
|
1589
|
+
for (const [key, rules] of Object.entries(media)) {
|
|
1590
|
+
if (key === "@--")
|
|
1591
|
+
continue;
|
|
1592
|
+
const query = key.startsWith("@--") ? mediaQueries[key.slice(1)] ?? key.slice(1) : key.slice(1);
|
|
1593
|
+
const scope = `[data-jx="${uid}"]`;
|
|
1594
|
+
css += `@media ${query} { ${scope} { ${toCSSText(rules)} } }
|
|
1595
|
+
`;
|
|
1596
|
+
for (const [sel, nestedRules] of Object.entries(rules)) {
|
|
1597
|
+
if (!isNestedSelector(sel))
|
|
1598
|
+
continue;
|
|
1599
|
+
const resolved = sel.startsWith("&") ? sel.replace("&", scope) : sel.startsWith("[") ? `${scope}${sel}` : `${scope} ${sel}`;
|
|
1600
|
+
css += `@media ${query} { ${resolved} { ${toCSSText(nestedRules)} } }
|
|
1601
|
+
`;
|
|
1602
|
+
}
|
|
1603
|
+
}
|
|
1604
|
+
const tag = document.createElement("style");
|
|
1605
|
+
tag.textContent = css;
|
|
1606
|
+
document.head.appendChild(tag);
|
|
1607
|
+
}
|
|
1608
|
+
function applyAttributes(el, attrs, state) {
|
|
1609
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
1610
|
+
if (isRefObj(v)) {
|
|
1611
|
+
effect(() => el.setAttribute(k, String(resolveRef(v.$ref, state) ?? "")));
|
|
1612
|
+
} else if (isTemplateString(v)) {
|
|
1613
|
+
effect(() => el.setAttribute(k, String(evaluateTemplate(v, state))));
|
|
1614
|
+
} else {
|
|
1615
|
+
el.setAttribute(k, String(v));
|
|
1616
|
+
}
|
|
1617
|
+
}
|
|
1618
|
+
}
|
|
1619
|
+
function renderMappedArray(def2, state, options) {
|
|
1620
|
+
const path = options?._path ?? [];
|
|
1621
|
+
const container = document.createElement(def2.tagName ?? "div");
|
|
1622
|
+
if (options?.onNodeCreated)
|
|
1623
|
+
options.onNodeCreated(container, path, def2);
|
|
1624
|
+
applyProperties(container, def2, state);
|
|
1625
|
+
applyStyle(container, def2.style ?? {}, state["$media"] ?? {}, state);
|
|
1626
|
+
applyAttributes(container, def2.attributes ?? {}, state);
|
|
1627
|
+
const { items: itemsSrc, map: mapDef, filter: filterRef, sort: sortRef } = def2.children;
|
|
1628
|
+
effect(() => {
|
|
1629
|
+
container.innerHTML = "";
|
|
1630
|
+
let items;
|
|
1631
|
+
if (isRefObj(itemsSrc)) {
|
|
1632
|
+
items = resolveRef(itemsSrc.$ref, state);
|
|
1633
|
+
} else {
|
|
1634
|
+
items = itemsSrc;
|
|
1635
|
+
}
|
|
1636
|
+
if (!Array.isArray(items))
|
|
1637
|
+
return;
|
|
1638
|
+
if (filterRef) {
|
|
1639
|
+
const fn = resolveRef(filterRef.$ref, state);
|
|
1640
|
+
if (typeof fn === "function")
|
|
1641
|
+
items = items.filter(fn);
|
|
1642
|
+
}
|
|
1643
|
+
if (sortRef) {
|
|
1644
|
+
const fn = resolveRef(sortRef.$ref, state);
|
|
1645
|
+
if (typeof fn === "function")
|
|
1646
|
+
items = [...items].sort(fn);
|
|
1647
|
+
}
|
|
1648
|
+
items.forEach((item, index) => {
|
|
1649
|
+
const child = Object.create(state);
|
|
1650
|
+
child.$map = { item, index };
|
|
1651
|
+
child["$map/item"] = item;
|
|
1652
|
+
child["$map/index"] = index;
|
|
1653
|
+
const childOpts = options ? { ...options, _path: [...path, "children", "map", index] } : undefined;
|
|
1654
|
+
container.appendChild(renderNode(mapDef, child, childOpts));
|
|
1655
|
+
});
|
|
1656
|
+
});
|
|
1657
|
+
return container;
|
|
1658
|
+
}
|
|
1659
|
+
function renderSwitch(def2, state, options) {
|
|
1660
|
+
const path = options?._path ?? [];
|
|
1661
|
+
const container = document.createElement(def2.tagName ?? "div");
|
|
1662
|
+
if (options?.onNodeCreated)
|
|
1663
|
+
options.onNodeCreated(container, path, def2);
|
|
1664
|
+
applyProperties(container, def2, state);
|
|
1665
|
+
applyStyle(container, def2.style ?? {}, state["$media"] ?? {}, state);
|
|
1666
|
+
applyAttributes(container, def2.attributes ?? {}, state);
|
|
1667
|
+
let generation = 0;
|
|
1668
|
+
effect(() => {
|
|
1669
|
+
container.innerHTML = "";
|
|
1670
|
+
const key = resolveRef(def2.$switch.$ref, state);
|
|
1671
|
+
const caseDef = def2.cases?.[key];
|
|
1672
|
+
if (!caseDef)
|
|
1673
|
+
return;
|
|
1674
|
+
if (isRefObj(caseDef)) {
|
|
1675
|
+
const gen = ++generation;
|
|
1676
|
+
const href = new URL(caseDef.$ref, location.href).href;
|
|
1677
|
+
resolve(href).then(async (doc) => {
|
|
1678
|
+
if (gen !== generation)
|
|
1679
|
+
return;
|
|
1680
|
+
const childScope = await buildScope(doc, {}, href);
|
|
1681
|
+
if (gen !== generation)
|
|
1682
|
+
return;
|
|
1683
|
+
container.innerHTML = "";
|
|
1684
|
+
const childOpts2 = options ? { ...options, _path: [...path, "cases", key] } : undefined;
|
|
1685
|
+
container.appendChild(renderNode(doc, childScope, childOpts2));
|
|
1686
|
+
}).catch((e) => console.error("Jx $switch: failed to load external case", caseDef.$ref, e));
|
|
1687
|
+
return;
|
|
1688
|
+
}
|
|
1689
|
+
const childOpts = options ? { ...options, _path: [...path, "cases", key] } : undefined;
|
|
1690
|
+
container.appendChild(renderNode(caseDef, state, childOpts));
|
|
1691
|
+
});
|
|
1692
|
+
return container;
|
|
1693
|
+
}
|
|
1694
|
+
async function resolvePrototype(def2, state, key, base) {
|
|
1695
|
+
if (def2.$src) {
|
|
1696
|
+
return resolveExternalPrototype(def2, state, key, base);
|
|
1697
|
+
}
|
|
1698
|
+
switch (def2.$prototype) {
|
|
1699
|
+
case "Request": {
|
|
1700
|
+
const s = ref(null);
|
|
1701
|
+
const debounceMs = def2.debounce ?? 0;
|
|
1702
|
+
let debounceTimer = null;
|
|
1703
|
+
if (!def2.manual) {
|
|
1704
|
+
effect(() => {
|
|
1705
|
+
let url;
|
|
1706
|
+
if (isTemplateString(def2.url)) {
|
|
1707
|
+
url = evaluateTemplate(def2.url, state);
|
|
1708
|
+
} else {
|
|
1709
|
+
url = def2.url;
|
|
1710
|
+
}
|
|
1711
|
+
if (!url || url === "undefined" || url.includes("undefined"))
|
|
1712
|
+
return;
|
|
1713
|
+
const controller = new AbortController;
|
|
1714
|
+
onEffectCleanup(() => {
|
|
1715
|
+
controller.abort();
|
|
1716
|
+
clearTimeout(debounceTimer);
|
|
1717
|
+
});
|
|
1718
|
+
const doFetch = () => fetch(url, {
|
|
1719
|
+
signal: controller.signal,
|
|
1720
|
+
method: def2.method ?? "GET",
|
|
1721
|
+
...def2.headers && { headers: def2.headers },
|
|
1722
|
+
...def2.body && {
|
|
1723
|
+
body: typeof def2.body === "object" ? JSON.stringify(def2.body) : def2.body
|
|
1724
|
+
}
|
|
1725
|
+
}).then((r) => r.ok ? r.json() : Promise.reject(r.statusText)).then((d) => {
|
|
1726
|
+
s.value = d;
|
|
1727
|
+
}).catch((e) => {
|
|
1728
|
+
if (e.name !== "AbortError")
|
|
1729
|
+
s.value = { error: String(e) };
|
|
1730
|
+
});
|
|
1731
|
+
if (debounceMs > 0) {
|
|
1732
|
+
debounceTimer = setTimeout(doFetch, debounceMs);
|
|
1733
|
+
} else {
|
|
1734
|
+
doFetch();
|
|
1735
|
+
}
|
|
1736
|
+
});
|
|
1737
|
+
}
|
|
1738
|
+
return s;
|
|
1739
|
+
}
|
|
1740
|
+
case "URLSearchParams":
|
|
1741
|
+
return computed(() => {
|
|
1742
|
+
const p = {};
|
|
1743
|
+
for (const [k, v] of Object.entries(def2)) {
|
|
1744
|
+
if (k !== "$prototype") {
|
|
1745
|
+
p[k] = isRefObj(v) ? resolveRef(v.$ref, state) : isTemplateString(v) ? evaluateTemplate(v, state) : v;
|
|
1746
|
+
}
|
|
1747
|
+
}
|
|
1748
|
+
return new URLSearchParams(p).toString();
|
|
1749
|
+
});
|
|
1750
|
+
case "LocalStorage":
|
|
1751
|
+
case "SessionStorage": {
|
|
1752
|
+
const store = def2.$prototype === "LocalStorage" ? localStorage : sessionStorage;
|
|
1753
|
+
const k = def2.key ?? key;
|
|
1754
|
+
let init;
|
|
1755
|
+
try {
|
|
1756
|
+
const s = store.getItem(k);
|
|
1757
|
+
init = s !== null ? JSON.parse(s) : def2.default ?? null;
|
|
1758
|
+
} catch {
|
|
1759
|
+
init = def2.default ?? null;
|
|
1760
|
+
}
|
|
1761
|
+
const storageState = ref(init);
|
|
1762
|
+
effect(() => {
|
|
1763
|
+
const v = storageState.value;
|
|
1764
|
+
if (v === null) {
|
|
1765
|
+
try {
|
|
1766
|
+
store.removeItem(k);
|
|
1767
|
+
} catch {}
|
|
1768
|
+
} else {
|
|
1769
|
+
try {
|
|
1770
|
+
store.setItem(k, JSON.stringify(v));
|
|
1771
|
+
} catch {}
|
|
1772
|
+
}
|
|
1773
|
+
});
|
|
1774
|
+
return storageState;
|
|
1775
|
+
}
|
|
1776
|
+
case "Cookie": {
|
|
1777
|
+
const name = def2.name ?? key;
|
|
1778
|
+
const read = () => {
|
|
1779
|
+
const m = document.cookie.match(new RegExp("(?:^|; )" + name + "=([^;]*)"));
|
|
1780
|
+
if (!m)
|
|
1781
|
+
return null;
|
|
1782
|
+
try {
|
|
1783
|
+
return JSON.parse(decodeURIComponent(m[1]));
|
|
1784
|
+
} catch {
|
|
1785
|
+
return m[1];
|
|
1786
|
+
}
|
|
1787
|
+
};
|
|
1788
|
+
const cookieState = ref(read() ?? def2.default ?? null);
|
|
1789
|
+
effect(() => {
|
|
1790
|
+
const v = cookieState.value;
|
|
1791
|
+
let s = `${name}=${encodeURIComponent(JSON.stringify(v))}`;
|
|
1792
|
+
if (def2.maxAge !== undefined)
|
|
1793
|
+
s += `; Max-Age=${def2.maxAge}`;
|
|
1794
|
+
if (def2.path)
|
|
1795
|
+
s += `; Path=${def2.path}`;
|
|
1796
|
+
if (def2.domain)
|
|
1797
|
+
s += `; Domain=${def2.domain}`;
|
|
1798
|
+
if (def2.secure)
|
|
1799
|
+
s += `; Secure`;
|
|
1800
|
+
if (def2.sameSite)
|
|
1801
|
+
s += `; SameSite=${def2.sameSite}`;
|
|
1802
|
+
document.cookie = s;
|
|
1803
|
+
});
|
|
1804
|
+
return cookieState;
|
|
1805
|
+
}
|
|
1806
|
+
case "IndexedDB": {
|
|
1807
|
+
const idbState = ref(null);
|
|
1808
|
+
const {
|
|
1809
|
+
database,
|
|
1810
|
+
store,
|
|
1811
|
+
version = 1,
|
|
1812
|
+
keyPath = "id",
|
|
1813
|
+
autoIncrement = true,
|
|
1814
|
+
indexes = []
|
|
1815
|
+
} = def2;
|
|
1816
|
+
const req = indexedDB.open(database, version);
|
|
1817
|
+
req.onupgradeneeded = (e) => {
|
|
1818
|
+
const db = e.target?.result;
|
|
1819
|
+
if (!db.objectStoreNames.contains(store)) {
|
|
1820
|
+
const os = db.createObjectStore(store, { keyPath, autoIncrement });
|
|
1821
|
+
for (const i of indexes)
|
|
1822
|
+
os.createIndex(i.name, i.keyPath, { unique: i.unique ?? false });
|
|
1823
|
+
}
|
|
1824
|
+
};
|
|
1825
|
+
req.onsuccess = (e) => {
|
|
1826
|
+
const db = e.target?.result;
|
|
1827
|
+
idbState.value = {
|
|
1828
|
+
database,
|
|
1829
|
+
store,
|
|
1830
|
+
version,
|
|
1831
|
+
isReady: true,
|
|
1832
|
+
getStore: (mode = "readwrite") => Promise.resolve(db.transaction(store, mode).objectStore(store))
|
|
1833
|
+
};
|
|
1834
|
+
};
|
|
1835
|
+
req.onerror = () => {
|
|
1836
|
+
idbState.value = { error: req.error?.message };
|
|
1837
|
+
};
|
|
1838
|
+
return idbState;
|
|
1839
|
+
}
|
|
1840
|
+
case "Set":
|
|
1841
|
+
return new Set(def2.default ?? []);
|
|
1842
|
+
case "Map":
|
|
1843
|
+
return new Map(Object.entries(def2.default ?? {}));
|
|
1844
|
+
case "FormData": {
|
|
1845
|
+
const fd = new FormData;
|
|
1846
|
+
for (const [k, v] of Object.entries(def2.fields ?? {}))
|
|
1847
|
+
fd.append(k, v);
|
|
1848
|
+
return fd;
|
|
1849
|
+
}
|
|
1850
|
+
case "Blob":
|
|
1851
|
+
return new Blob(def2.parts ?? [], { type: def2.type ?? "text/plain" });
|
|
1852
|
+
case "ReadableStream":
|
|
1853
|
+
return null;
|
|
1854
|
+
default:
|
|
1855
|
+
console.warn(`Jx: unknown $prototype "${def2.$prototype}" for "${key}". Did you mean to add '$src'?`);
|
|
1856
|
+
return ref(null);
|
|
1857
|
+
}
|
|
1858
|
+
}
|
|
1859
|
+
var EXTERNAL_RESERVED = new Set([
|
|
1860
|
+
"$prototype",
|
|
1861
|
+
"$src",
|
|
1862
|
+
"$export",
|
|
1863
|
+
"timing",
|
|
1864
|
+
"default",
|
|
1865
|
+
"description",
|
|
1866
|
+
"body",
|
|
1867
|
+
"parameters",
|
|
1868
|
+
"arguments",
|
|
1869
|
+
"name"
|
|
1870
|
+
]);
|
|
1871
|
+
async function resolveExternalPrototype(def2, state, key, base) {
|
|
1872
|
+
const src = def2.$src;
|
|
1873
|
+
if (!src.endsWith(".class.json")) {
|
|
1874
|
+
throw new Error(`Jx: $prototype "${def2.$prototype}" requires a .class.json $src, got "${src}". Wrap the class in a .class.json schema with $implementation.`);
|
|
1875
|
+
}
|
|
1876
|
+
return resolveClassJson(def2, state, key, base);
|
|
1877
|
+
}
|
|
1878
|
+
async function importAndInstantiate(def2, src, exportName, base) {
|
|
1879
|
+
let mod;
|
|
1880
|
+
if (_moduleCache.has(src)) {
|
|
1881
|
+
mod = _moduleCache.get(src);
|
|
1882
|
+
} else {
|
|
1883
|
+
try {
|
|
1884
|
+
mod = await import(src);
|
|
1885
|
+
} catch {
|
|
1886
|
+
if (base) {
|
|
1887
|
+
const resolvedSrc = new URL(src, base).href;
|
|
1888
|
+
mod = await import(resolvedSrc);
|
|
1889
|
+
} else {
|
|
1890
|
+
throw new Error(`Failed to import "${src}"`);
|
|
1891
|
+
}
|
|
1892
|
+
}
|
|
1893
|
+
_moduleCache.set(src, mod);
|
|
1894
|
+
}
|
|
1895
|
+
const ExportedClass = mod[exportName] ?? mod.default?.[exportName];
|
|
1896
|
+
if (!ExportedClass) {
|
|
1897
|
+
throw new Error(`Jx: export "${exportName}" not found in "${src}"`);
|
|
1898
|
+
}
|
|
1899
|
+
if (typeof ExportedClass !== "function") {
|
|
1900
|
+
throw new Error(`Jx: "${exportName}" from "${src}" is not a class`);
|
|
1901
|
+
}
|
|
1902
|
+
const config = {};
|
|
1903
|
+
for (const [k, v] of Object.entries(def2)) {
|
|
1904
|
+
if (!EXTERNAL_RESERVED.has(k))
|
|
1905
|
+
config[k] = v;
|
|
1906
|
+
}
|
|
1907
|
+
const instance = new ExportedClass(config);
|
|
1908
|
+
let value;
|
|
1909
|
+
if (typeof instance.resolve === "function") {
|
|
1910
|
+
value = await instance.resolve();
|
|
1911
|
+
} else if ("value" in instance) {
|
|
1912
|
+
value = instance.value;
|
|
1913
|
+
} else {
|
|
1914
|
+
value = instance;
|
|
1915
|
+
}
|
|
1916
|
+
const s = ref(value);
|
|
1917
|
+
if (typeof instance.subscribe === "function") {
|
|
1918
|
+
instance.subscribe((newVal) => {
|
|
1919
|
+
s.value = newVal;
|
|
1920
|
+
});
|
|
1921
|
+
}
|
|
1922
|
+
return s;
|
|
1923
|
+
}
|
|
1924
|
+
async function resolveClassJson(def2, state, key, base) {
|
|
1925
|
+
const src = def2.$src;
|
|
1926
|
+
let classDef;
|
|
1927
|
+
try {
|
|
1928
|
+
const url = base ? new URL(src, base).href : src;
|
|
1929
|
+
const res = await fetch(url);
|
|
1930
|
+
if (!res.ok)
|
|
1931
|
+
throw new Error(`HTTP ${res.status}`);
|
|
1932
|
+
classDef = await res.json();
|
|
1933
|
+
} catch {
|
|
1934
|
+
return resolveViaDevProxy(def2, state, key, base);
|
|
1935
|
+
}
|
|
1936
|
+
if (classDef.$implementation) {
|
|
1937
|
+
const schemaUrl = base ? new URL(src, base).href : new URL(src, location.href).href;
|
|
1938
|
+
const implSrc = new URL(classDef.$implementation, schemaUrl).href;
|
|
1939
|
+
const exportName = def2.$export ?? classDef.title ?? def2.$prototype;
|
|
1940
|
+
try {
|
|
1941
|
+
return await importAndInstantiate(def2, implSrc, exportName, base);
|
|
1942
|
+
} catch {
|
|
1943
|
+
return resolveViaDevProxy(def2, state, key, base);
|
|
1944
|
+
}
|
|
1945
|
+
}
|
|
1946
|
+
const DynClass = classFromSchema(classDef);
|
|
1947
|
+
const config = {};
|
|
1948
|
+
for (const [k, v] of Object.entries(def2)) {
|
|
1949
|
+
if (!EXTERNAL_RESERVED.has(k))
|
|
1950
|
+
config[k] = v;
|
|
1951
|
+
}
|
|
1952
|
+
const instance = new DynClass(config);
|
|
1953
|
+
let value;
|
|
1954
|
+
if (typeof instance.resolve === "function") {
|
|
1955
|
+
value = await instance.resolve();
|
|
1956
|
+
} else if ("value" in instance) {
|
|
1957
|
+
value = instance.value;
|
|
1958
|
+
} else {
|
|
1959
|
+
value = instance;
|
|
1960
|
+
}
|
|
1961
|
+
const s = ref(value);
|
|
1962
|
+
if (typeof instance.subscribe === "function") {
|
|
1963
|
+
instance.subscribe((newVal) => {
|
|
1964
|
+
s.value = newVal;
|
|
1965
|
+
});
|
|
1966
|
+
}
|
|
1967
|
+
return s;
|
|
1968
|
+
}
|
|
1969
|
+
function classFromSchema(classDef) {
|
|
1970
|
+
const fields = classDef.$defs?.fields ?? {};
|
|
1971
|
+
const ctor = classDef.$defs?.constructor;
|
|
1972
|
+
const methods = classDef.$defs?.methods ?? {};
|
|
1973
|
+
|
|
1974
|
+
class DynClass {
|
|
1975
|
+
constructor(config = {}) {
|
|
1976
|
+
for (const [key, field] of Object.entries(fields)) {
|
|
1977
|
+
const typedField = field;
|
|
1978
|
+
const id = typedField.identifier ?? key;
|
|
1979
|
+
const propName = typedField.access === "private" ? `_${id}` : id;
|
|
1980
|
+
if (config[id] !== undefined)
|
|
1981
|
+
this[propName] = config[id];
|
|
1982
|
+
else if (typedField.initializer !== undefined)
|
|
1983
|
+
this[propName] = typedField.initializer;
|
|
1984
|
+
else if (typedField.default !== undefined)
|
|
1985
|
+
this[propName] = structuredClone(typedField.default);
|
|
1986
|
+
else
|
|
1987
|
+
this[propName] = null;
|
|
1988
|
+
}
|
|
1989
|
+
if (ctor?.body) {
|
|
1990
|
+
const bodyStr = Array.isArray(ctor.body) ? ctor.body.join(`
|
|
1991
|
+
`) : ctor.body;
|
|
1992
|
+
new Function("config", bodyStr).call(this, config);
|
|
1993
|
+
}
|
|
1994
|
+
}
|
|
1995
|
+
}
|
|
1996
|
+
for (const [key, method] of Object.entries(methods)) {
|
|
1997
|
+
const typedMethod = method;
|
|
1998
|
+
const name = typedMethod.identifier ?? key;
|
|
1999
|
+
const params = (typedMethod.parameters ?? []).map((p) => {
|
|
2000
|
+
if (p.$ref)
|
|
2001
|
+
return p.$ref.split("/").pop();
|
|
2002
|
+
return p.identifier ?? p.name ?? "arg";
|
|
2003
|
+
});
|
|
2004
|
+
const bodyStr = Array.isArray(typedMethod.body) ? typedMethod.body.join(`
|
|
2005
|
+
`) : typedMethod.body ?? "";
|
|
2006
|
+
if (typedMethod.role === "accessor") {
|
|
2007
|
+
const descriptor = {};
|
|
2008
|
+
if (typedMethod.getter)
|
|
2009
|
+
descriptor.get = new Function(typedMethod.getter.body);
|
|
2010
|
+
if (typedMethod.setter) {
|
|
2011
|
+
const sp = (typedMethod.setter.parameters ?? []).map((p) => p.$ref?.split("/").pop() ?? "v");
|
|
2012
|
+
descriptor.set = new Function(...sp, typedMethod.setter.body);
|
|
2013
|
+
}
|
|
2014
|
+
Object.defineProperty(DynClass.prototype, name, { ...descriptor, configurable: true });
|
|
2015
|
+
} else if (typedMethod.scope === "static") {
|
|
2016
|
+
DynClass[name] = new Function(...params, bodyStr);
|
|
2017
|
+
} else {
|
|
2018
|
+
DynClass.prototype[name] = new Function(...params, bodyStr);
|
|
2019
|
+
}
|
|
2020
|
+
}
|
|
2021
|
+
Object.defineProperty(DynClass, "name", { value: classDef.title, configurable: true });
|
|
2022
|
+
return DynClass;
|
|
2023
|
+
}
|
|
2024
|
+
async function resolveViaDevProxy(def2, state, key, base) {
|
|
2025
|
+
const config = {};
|
|
2026
|
+
for (const [k, v] of Object.entries(def2)) {
|
|
2027
|
+
if (!EXTERNAL_RESERVED.has(k))
|
|
2028
|
+
config[k] = v;
|
|
2029
|
+
}
|
|
2030
|
+
const hasTemplates = Object.values(config).some((v) => isTemplateString(v));
|
|
2031
|
+
const doResolve = (resolvedConfig) => fetch("/__jx_resolve__", {
|
|
2032
|
+
method: "POST",
|
|
2033
|
+
headers: { "Content-Type": "application/json" },
|
|
2034
|
+
body: JSON.stringify({
|
|
2035
|
+
$src: def2.$src,
|
|
2036
|
+
$prototype: def2.$prototype,
|
|
2037
|
+
$export: def2.$export,
|
|
2038
|
+
$base: base,
|
|
2039
|
+
...resolvedConfig
|
|
2040
|
+
})
|
|
2041
|
+
}).then((r) => {
|
|
2042
|
+
if (!r.ok)
|
|
2043
|
+
throw new Error(`Jx dev proxy ${r.status} for "${key}"`);
|
|
2044
|
+
return r.json();
|
|
2045
|
+
});
|
|
2046
|
+
const s = ref(null);
|
|
2047
|
+
if (hasTemplates) {
|
|
2048
|
+
effect(() => {
|
|
2049
|
+
const resolvedConfig = {};
|
|
2050
|
+
for (const [k, v] of Object.entries(config)) {
|
|
2051
|
+
resolvedConfig[k] = isTemplateString(v) ? evaluateTemplate(v, state) : v;
|
|
2052
|
+
}
|
|
2053
|
+
doResolve(resolvedConfig).then((value) => {
|
|
2054
|
+
s.value = value;
|
|
2055
|
+
}).catch((e) => console.error("Jx dev proxy:", e));
|
|
2056
|
+
});
|
|
2057
|
+
} else {
|
|
2058
|
+
doResolve(config).then((value) => {
|
|
2059
|
+
s.value = value;
|
|
2060
|
+
}).catch((e) => console.error("Jx dev proxy:", e));
|
|
2061
|
+
}
|
|
2062
|
+
return s;
|
|
2063
|
+
}
|
|
2064
|
+
async function resolveServerFunction(def2, state, key, base) {
|
|
2065
|
+
const src = def2.$src;
|
|
2066
|
+
const exportName = def2.$export;
|
|
2067
|
+
let mod;
|
|
2068
|
+
if (_moduleCache.has(src)) {
|
|
2069
|
+
mod = _moduleCache.get(src);
|
|
2070
|
+
} else {
|
|
2071
|
+
try {
|
|
2072
|
+
mod = await import(src);
|
|
2073
|
+
} catch {
|
|
2074
|
+
if (base) {
|
|
2075
|
+
try {
|
|
2076
|
+
const resolvedSrc = new URL(src, base).href;
|
|
2077
|
+
mod = await import(resolvedSrc);
|
|
2078
|
+
} catch {
|
|
2079
|
+
return resolveServerFunctionViaProxy(def2, state, key, base);
|
|
2080
|
+
}
|
|
2081
|
+
} else {
|
|
2082
|
+
return resolveServerFunctionViaProxy(def2, state, key, base);
|
|
2083
|
+
}
|
|
2084
|
+
}
|
|
2085
|
+
_moduleCache.set(src, mod);
|
|
2086
|
+
}
|
|
2087
|
+
const fn = mod[exportName] ?? mod.default?.[exportName];
|
|
2088
|
+
if (!fn)
|
|
2089
|
+
throw new Error(`Jx: export "${exportName}" not found in "${src}" for "${key}"`);
|
|
2090
|
+
if (typeof fn !== "function")
|
|
2091
|
+
throw new Error(`Jx: "${exportName}" from "${src}" is not a function`);
|
|
2092
|
+
const rawArgs = def2.arguments ?? {};
|
|
2093
|
+
const hasReactiveArg = Object.values(rawArgs).some((v) => isRefObj(v));
|
|
2094
|
+
const resolveArgs = () => {
|
|
2095
|
+
const args = {};
|
|
2096
|
+
for (const [k, v] of Object.entries(rawArgs)) {
|
|
2097
|
+
args[k] = isRefObj(v) ? resolveRef(v.$ref, state) : v;
|
|
2098
|
+
}
|
|
2099
|
+
return args;
|
|
2100
|
+
};
|
|
2101
|
+
const s = ref(null);
|
|
2102
|
+
if (hasReactiveArg) {
|
|
2103
|
+
effect(() => {
|
|
2104
|
+
const args = resolveArgs();
|
|
2105
|
+
onEffectCleanup(() => {});
|
|
2106
|
+
fn(args).then((result) => {
|
|
2107
|
+
s.value = result;
|
|
2108
|
+
}).catch(() => {});
|
|
2109
|
+
});
|
|
2110
|
+
} else {
|
|
2111
|
+
s.value = await fn(resolveArgs());
|
|
2112
|
+
}
|
|
2113
|
+
return s;
|
|
2114
|
+
}
|
|
2115
|
+
async function resolveServerFunctionViaProxy(def2, state, key, base) {
|
|
2116
|
+
const rawArgs = def2.arguments ?? {};
|
|
2117
|
+
const hasReactiveArg = Object.values(rawArgs).some((v) => isRefObj(v));
|
|
2118
|
+
const resolveArgs = () => {
|
|
2119
|
+
const args = {};
|
|
2120
|
+
for (const [k, v] of Object.entries(rawArgs)) {
|
|
2121
|
+
args[k] = isRefObj(v) ? resolveRef(v.$ref, state) : v;
|
|
2122
|
+
}
|
|
2123
|
+
return args;
|
|
2124
|
+
};
|
|
2125
|
+
const doResolve = (args) => fetch("/__jx_server__", {
|
|
2126
|
+
method: "POST",
|
|
2127
|
+
headers: { "Content-Type": "application/json" },
|
|
2128
|
+
body: JSON.stringify({
|
|
2129
|
+
$src: def2.$src,
|
|
2130
|
+
$export: def2.$export,
|
|
2131
|
+
$base: base,
|
|
2132
|
+
arguments: args
|
|
2133
|
+
})
|
|
2134
|
+
}).then((r) => {
|
|
2135
|
+
if (!r.ok)
|
|
2136
|
+
throw new Error(`Jx server proxy ${r.status} for "${key}"`);
|
|
2137
|
+
return r.json();
|
|
2138
|
+
});
|
|
2139
|
+
const s = ref(null);
|
|
2140
|
+
if (hasReactiveArg) {
|
|
2141
|
+
effect(() => {
|
|
2142
|
+
const args = resolveArgs();
|
|
2143
|
+
onEffectCleanup(() => {});
|
|
2144
|
+
doResolve(args).then((result) => {
|
|
2145
|
+
s.value = result;
|
|
2146
|
+
}).catch((e) => console.error("Jx server proxy:", e));
|
|
2147
|
+
});
|
|
2148
|
+
} else {
|
|
2149
|
+
doResolve(resolveArgs()).then((result) => {
|
|
2150
|
+
s.value = result;
|
|
2151
|
+
}).catch((e) => console.error("Jx server proxy:", e));
|
|
2152
|
+
}
|
|
2153
|
+
return s;
|
|
2154
|
+
}
|
|
2155
|
+
function resolveRef(ref2, state) {
|
|
2156
|
+
if (typeof ref2 !== "string")
|
|
2157
|
+
return ref2;
|
|
2158
|
+
if (ref2.startsWith("$map/")) {
|
|
2159
|
+
const parts = ref2.split("/");
|
|
2160
|
+
const key = parts[1];
|
|
2161
|
+
const base = state.$map?.[key] ?? state["$map/" + key];
|
|
2162
|
+
return parts.length > 2 ? getPath(base, parts.slice(2).join("/")) : base;
|
|
2163
|
+
}
|
|
2164
|
+
if (ref2.startsWith("#/state/")) {
|
|
2165
|
+
const sub = ref2.slice("#/state/".length);
|
|
2166
|
+
const slash = sub.indexOf("/");
|
|
2167
|
+
if (slash < 0)
|
|
2168
|
+
return state[sub];
|
|
2169
|
+
return getPath(state[sub.slice(0, slash)], sub.slice(slash + 1));
|
|
2170
|
+
}
|
|
2171
|
+
if (ref2.startsWith("parent#/"))
|
|
2172
|
+
return state[ref2.slice("parent#/".length)];
|
|
2173
|
+
if (ref2.startsWith("window#/"))
|
|
2174
|
+
return getPath(globalThis.window, ref2.slice("window#/".length));
|
|
2175
|
+
if (ref2.startsWith("document#/"))
|
|
2176
|
+
return getPath(globalThis.document, ref2.slice("document#/".length));
|
|
2177
|
+
return state[ref2] ?? null;
|
|
2178
|
+
}
|
|
2179
|
+
function isSignal(v) {
|
|
2180
|
+
return isRef(v);
|
|
2181
|
+
}
|
|
2182
|
+
function isRefObj(v) {
|
|
2183
|
+
return v !== null && typeof v === "object" && typeof v.$ref === "string";
|
|
2184
|
+
}
|
|
2185
|
+
function isNestedSelector(k) {
|
|
2186
|
+
return k.startsWith(":") || k.startsWith(".") || k.startsWith("&") || k.startsWith("[");
|
|
2187
|
+
}
|
|
2188
|
+
function getPath(obj, path) {
|
|
2189
|
+
return path.split(/[./]/).reduce((o, k) => o?.[k], obj);
|
|
2190
|
+
}
|
|
2191
|
+
function mergeProps(def2, parentState) {
|
|
2192
|
+
const child = Object.create(parentState);
|
|
2193
|
+
for (const [k, v] of Object.entries(def2.$props ?? {})) {
|
|
2194
|
+
child[k] = isRefObj(v) ? resolveRef(v.$ref, parentState) : v;
|
|
2195
|
+
}
|
|
2196
|
+
return child;
|
|
2197
|
+
}
|
|
2198
|
+
function camelToKebab(s) {
|
|
2199
|
+
return s.replace(/[A-Z]/g, (c) => `-${c.toLowerCase()}`);
|
|
2200
|
+
}
|
|
2201
|
+
function toCSSText(rules) {
|
|
2202
|
+
return Object.entries(rules).filter(([k]) => !isNestedSelector(k)).map(([p, v]) => `${camelToKebab(p)}: ${v}`).join("; ");
|
|
2203
|
+
}
|
|
2204
|
+
var _elementDefs = new Map;
|
|
2205
|
+
async function registerElements(elements, base) {
|
|
2206
|
+
for (const entry of elements) {
|
|
2207
|
+
if (typeof entry === "string") {
|
|
2208
|
+
try {
|
|
2209
|
+
const specifier = entry.startsWith("/") || entry.startsWith(".") ? entry : `/node_modules/${entry}`;
|
|
2210
|
+
await import(specifier);
|
|
2211
|
+
} catch (e) {
|
|
2212
|
+
console.warn(`Jx: failed to import package "${entry}"`, e);
|
|
2213
|
+
}
|
|
2214
|
+
continue;
|
|
2215
|
+
}
|
|
2216
|
+
if (!isRefObj(entry))
|
|
2217
|
+
continue;
|
|
2218
|
+
const href = new URL(entry.$ref, base).href;
|
|
2219
|
+
const doc = await resolve(href);
|
|
2220
|
+
if (!doc.tagName || !doc.tagName.includes("-"))
|
|
2221
|
+
continue;
|
|
2222
|
+
if (customElements.get(doc.tagName))
|
|
2223
|
+
continue;
|
|
2224
|
+
if (doc.$elements) {
|
|
2225
|
+
await registerElements(doc.$elements, href);
|
|
2226
|
+
}
|
|
2227
|
+
await defineElement(doc, href);
|
|
2228
|
+
}
|
|
2229
|
+
}
|
|
2230
|
+
function injectHead(entries, _base) {
|
|
2231
|
+
for (const entry of entries) {
|
|
2232
|
+
if (!entry || !entry.tagName)
|
|
2233
|
+
continue;
|
|
2234
|
+
const tag = entry.tagName.toLowerCase();
|
|
2235
|
+
const attrs = { ...entry.attributes };
|
|
2236
|
+
for (const key of ["href", "src"]) {
|
|
2237
|
+
if (attrs[key] && !attrs[key].startsWith("/") && !attrs[key].startsWith(".") && !attrs[key].startsWith("http")) {
|
|
2238
|
+
attrs[key] = `/node_modules/${attrs[key]}`;
|
|
2239
|
+
}
|
|
2240
|
+
}
|
|
2241
|
+
const selector = `${tag}${attrs.href ? `[href="${attrs.href}"]` : ""}${attrs.src ? `[src="${attrs.src}"]` : ""}`;
|
|
2242
|
+
if (selector !== tag && document.head.querySelector(selector))
|
|
2243
|
+
continue;
|
|
2244
|
+
const el = document.createElement(tag);
|
|
2245
|
+
for (const [k, v] of Object.entries(attrs)) {
|
|
2246
|
+
el.setAttribute(k, v);
|
|
2247
|
+
}
|
|
2248
|
+
if (entry.textContent)
|
|
2249
|
+
el.textContent = entry.textContent;
|
|
2250
|
+
document.head.appendChild(el);
|
|
2251
|
+
}
|
|
2252
|
+
}
|
|
2253
|
+
async function defineElement(source, base) {
|
|
2254
|
+
if (typeof source === "string") {
|
|
2255
|
+
base = new URL(source, base ?? location.href).href;
|
|
2256
|
+
source = await resolve(source);
|
|
2257
|
+
}
|
|
2258
|
+
base = base ?? location.href;
|
|
2259
|
+
const source_ = source;
|
|
2260
|
+
const tagName = source_.tagName;
|
|
2261
|
+
if (!tagName || !tagName.includes("-")) {
|
|
2262
|
+
throw new Error(`Jx defineElement: tagName "${tagName}" must contain a hyphen`);
|
|
2263
|
+
}
|
|
2264
|
+
if (customElements.get(tagName))
|
|
2265
|
+
return;
|
|
2266
|
+
if (source_.$elements) {
|
|
2267
|
+
await registerElements(source_.$elements, base);
|
|
2268
|
+
}
|
|
2269
|
+
_elementDefs.set(tagName, { doc: source_, base });
|
|
2270
|
+
const def2 = source_;
|
|
2271
|
+
const observedAttrs = def2.observedAttributes ?? [];
|
|
2272
|
+
const ElementClass = class extends HTMLElement {
|
|
2273
|
+
static get observedAttributes() {
|
|
2274
|
+
return observedAttrs;
|
|
2275
|
+
}
|
|
2276
|
+
async connectedCallback() {
|
|
2277
|
+
const state = await buildScope(def2, {}, base);
|
|
2278
|
+
for (const key of Object.keys(def2.state ?? {})) {
|
|
2279
|
+
if (key in this && this[key] !== undefined) {
|
|
2280
|
+
state[key] = this[key];
|
|
2281
|
+
}
|
|
2282
|
+
}
|
|
2283
|
+
for (const key of Object.keys(def2.state ?? {})) {
|
|
2284
|
+
if (!(key in HTMLElement.prototype)) {
|
|
2285
|
+
Object.defineProperty(this, key, {
|
|
2286
|
+
get: () => state[key],
|
|
2287
|
+
set: (v) => {
|
|
2288
|
+
state[key] = v;
|
|
2289
|
+
},
|
|
2290
|
+
configurable: true
|
|
2291
|
+
});
|
|
2292
|
+
}
|
|
2293
|
+
}
|
|
2294
|
+
this._state = state;
|
|
2295
|
+
const slottedChildren = Array.from(this.childNodes);
|
|
2296
|
+
this.innerHTML = "";
|
|
2297
|
+
applyStyle(this, def2.style ?? {}, state["$media"] ?? {}, state);
|
|
2298
|
+
applyAttributes(this, def2.attributes ?? {}, state);
|
|
2299
|
+
const children = Array.isArray(def2.children) ? def2.children : [];
|
|
2300
|
+
for (const childDef of children) {
|
|
2301
|
+
this.appendChild(renderNode(childDef, state));
|
|
2302
|
+
}
|
|
2303
|
+
distributeSlots(this, slottedChildren);
|
|
2304
|
+
if (typeof state.onMount === "function") {
|
|
2305
|
+
queueMicrotask(() => state.onMount(state));
|
|
2306
|
+
}
|
|
2307
|
+
}
|
|
2308
|
+
disconnectedCallback() {
|
|
2309
|
+
const self2 = this;
|
|
2310
|
+
if (typeof self2._state?.onUnmount === "function") {
|
|
2311
|
+
self2._state.onUnmount(self2._state);
|
|
2312
|
+
}
|
|
2313
|
+
}
|
|
2314
|
+
adoptedCallback() {
|
|
2315
|
+
const self2 = this;
|
|
2316
|
+
if (typeof self2._state?.onAdopted === "function") {
|
|
2317
|
+
self2._state.onAdopted(self2._state);
|
|
2318
|
+
}
|
|
2319
|
+
}
|
|
2320
|
+
attributeChangedCallback(name, oldVal, newVal) {
|
|
2321
|
+
const self2 = this;
|
|
2322
|
+
if (!self2._state || oldVal === newVal)
|
|
2323
|
+
return;
|
|
2324
|
+
const camelKey = name.replace(/-([a-z])/g, (_, c) => c.toUpperCase());
|
|
2325
|
+
const current = self2._state[camelKey];
|
|
2326
|
+
if (typeof current === "number")
|
|
2327
|
+
self2._state[camelKey] = Number(newVal);
|
|
2328
|
+
else if (typeof current === "boolean")
|
|
2329
|
+
self2._state[camelKey] = newVal !== null && newVal !== "false";
|
|
2330
|
+
else
|
|
2331
|
+
self2._state[camelKey] = newVal;
|
|
2332
|
+
}
|
|
2333
|
+
};
|
|
2334
|
+
customElements.define(tagName, ElementClass);
|
|
2335
|
+
}
|
|
2336
|
+
function renderCustomElementWithProps(def2, state, options, path) {
|
|
2337
|
+
const el = document.createElement(def2.tagName);
|
|
2338
|
+
if (options?.onNodeCreated)
|
|
2339
|
+
options.onNodeCreated(el, path, def2);
|
|
2340
|
+
for (const [key, val] of Object.entries(def2.$props ?? {})) {
|
|
2341
|
+
if (isRefObj(val)) {
|
|
2342
|
+
const resolved = resolveRef(val.$ref, state);
|
|
2343
|
+
el[key] = resolved;
|
|
2344
|
+
effect(() => {
|
|
2345
|
+
el[key] = resolveRef(val.$ref, state);
|
|
2346
|
+
});
|
|
2347
|
+
} else if (isTemplateString(val)) {
|
|
2348
|
+
effect(() => {
|
|
2349
|
+
el[key] = evaluateTemplate(val, state);
|
|
2350
|
+
});
|
|
2351
|
+
} else {
|
|
2352
|
+
el[key] = val;
|
|
2353
|
+
}
|
|
2354
|
+
}
|
|
2355
|
+
applyStyle(el, def2.style ?? {}, state["$media"] ?? {}, state);
|
|
2356
|
+
applyAttributes(el, def2.attributes ?? {}, state);
|
|
2357
|
+
const children = Array.isArray(def2.children) ? def2.children : [];
|
|
2358
|
+
for (let i = 0;i < children.length; i++) {
|
|
2359
|
+
el.appendChild(renderNode(children[i], state, options));
|
|
2360
|
+
}
|
|
2361
|
+
return el;
|
|
2362
|
+
}
|
|
2363
|
+
function distributeSlots(host, slottedChildren) {
|
|
2364
|
+
if (slottedChildren.length === 0)
|
|
2365
|
+
return;
|
|
2366
|
+
const slots = host.querySelectorAll("slot");
|
|
2367
|
+
if (slots.length === 0)
|
|
2368
|
+
return;
|
|
2369
|
+
const named = new Map;
|
|
2370
|
+
const unnamed = [];
|
|
2371
|
+
for (const child of slottedChildren) {
|
|
2372
|
+
if (child.nodeType === Node.ELEMENT_NODE && child.getAttribute("slot")) {
|
|
2373
|
+
const name = child.getAttribute("slot");
|
|
2374
|
+
if (!named.has(name))
|
|
2375
|
+
named.set(name, []);
|
|
2376
|
+
named.get(name).push(child);
|
|
2377
|
+
} else {
|
|
2378
|
+
unnamed.push(child);
|
|
2379
|
+
}
|
|
2380
|
+
}
|
|
2381
|
+
for (const slot of slots) {
|
|
2382
|
+
const name = slot.getAttribute("name");
|
|
2383
|
+
const matches = name ? named.get(name) ?? [] : unnamed;
|
|
2384
|
+
if (matches.length > 0) {
|
|
2385
|
+
slot.innerHTML = "";
|
|
2386
|
+
for (const child of matches) {
|
|
2387
|
+
slot.appendChild(child);
|
|
2388
|
+
}
|
|
2389
|
+
}
|
|
2390
|
+
}
|
|
2391
|
+
}
|
|
2392
|
+
export {
|
|
2393
|
+
toCSSText,
|
|
2394
|
+
resolveRef,
|
|
2395
|
+
resolvePrototype,
|
|
2396
|
+
resolve,
|
|
2397
|
+
renderNode,
|
|
2398
|
+
isSignal,
|
|
2399
|
+
hasSchemaKeywords,
|
|
2400
|
+
defineElement,
|
|
2401
|
+
camelToKebab,
|
|
2402
|
+
buildScope,
|
|
2403
|
+
applyStyle,
|
|
2404
|
+
RESERVED_KEYS,
|
|
2405
|
+
Jx
|
|
2406
|
+
};
|
|
2407
|
+
|
|
2408
|
+
//# debugId=302268380091C32C64756E2164756E21
|
|
2409
|
+
//# sourceMappingURL=runtime.js.map
|