@zeus-js/runtime-dom 0.1.0-beta.7 → 0.1.0-beta.9
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-dom.cjs.js +1810 -214
- package/dist/runtime-dom.cjs.prod.js +1746 -213
- package/dist/runtime-dom.d.ts +33 -5
- package/dist/runtime-dom.esm-browser.js +437 -198
- package/dist/runtime-dom.esm-browser.prod.js +1 -1
- package/dist/runtime-dom.esm-bundler.js +1785 -195
- package/dist/runtime-dom.global.js +442 -197
- package/dist/runtime-dom.global.prod.js +1 -1
- package/package.json +2 -2
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* runtime-dom v0.1.0-beta.
|
|
2
|
+
* runtime-dom v0.1.0-beta.9
|
|
3
3
|
* (c) 2026 baicie
|
|
4
4
|
* Released under the MIT License.
|
|
5
5
|
**/
|
|
@@ -7,7 +7,6 @@ Object.defineProperties(exports, {
|
|
|
7
7
|
__esModule: { value: true },
|
|
8
8
|
[Symbol.toStringTag]: { value: "Module" }
|
|
9
9
|
});
|
|
10
|
-
let _zeus_js_signal = require("@zeus-js/signal");
|
|
11
10
|
//#region packages/core/runtime-dom/src/template.ts
|
|
12
11
|
function template(html, _isImportNode = false, _isSVG = false, _isMathML = false) {
|
|
13
12
|
const t = document.createElement("template");
|
|
@@ -17,6 +16,1355 @@ function template(html, _isImportNode = false, _isSVG = false, _isMathML = false
|
|
|
17
16
|
};
|
|
18
17
|
}
|
|
19
18
|
//#endregion
|
|
19
|
+
//#region packages/core/shared/src/makeMap.ts
|
|
20
|
+
/**
|
|
21
|
+
* Make a map and return a function for checking if a key
|
|
22
|
+
* is in that map.
|
|
23
|
+
* IMPORTANT: all calls of this function must be prefixed with
|
|
24
|
+
* \/\*#\_\_PURE\_\_\*\/
|
|
25
|
+
* So that rollup can tree-shake them if necessary.
|
|
26
|
+
*/
|
|
27
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
28
|
+
function makeMap(str) {
|
|
29
|
+
const map = Object.create(null);
|
|
30
|
+
for (const key of str.split(",")) map[key] = 1;
|
|
31
|
+
return (val) => val in map;
|
|
32
|
+
}
|
|
33
|
+
//#endregion
|
|
34
|
+
//#region packages/core/shared/src/general.ts
|
|
35
|
+
const extend = Object.assign;
|
|
36
|
+
const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
|
|
37
|
+
const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
|
|
38
|
+
const isArray = Array.isArray;
|
|
39
|
+
const isMap = (val) => toTypeString(val) === "[object Map]";
|
|
40
|
+
const isString = (val) => typeof val === "string";
|
|
41
|
+
const isSymbol = (val) => typeof val === "symbol";
|
|
42
|
+
const isObject = (val) => val !== null && typeof val === "object";
|
|
43
|
+
const objectToString = Object.prototype.toString;
|
|
44
|
+
const toTypeString = (value) => objectToString.call(value);
|
|
45
|
+
const toRawType = (value) => {
|
|
46
|
+
return toTypeString(value).slice(8, -1);
|
|
47
|
+
};
|
|
48
|
+
const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
|
|
49
|
+
const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
|
|
50
|
+
//#endregion
|
|
51
|
+
//#region packages/core/signal/src/effectScope.ts
|
|
52
|
+
let activeEffectScope;
|
|
53
|
+
var EffectScope = class {
|
|
54
|
+
constructor(detached = false) {
|
|
55
|
+
this.detached = detached;
|
|
56
|
+
this._active = true;
|
|
57
|
+
this._on = 0;
|
|
58
|
+
this.effects = [];
|
|
59
|
+
this.cleanups = [];
|
|
60
|
+
this._isPaused = false;
|
|
61
|
+
this._warnOnRun = true;
|
|
62
|
+
this.__v_skip = true;
|
|
63
|
+
if (!detached && activeEffectScope) if (activeEffectScope.active) {
|
|
64
|
+
this.parent = activeEffectScope;
|
|
65
|
+
this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
|
|
66
|
+
} else {
|
|
67
|
+
this._active = false;
|
|
68
|
+
this._warnOnRun = false;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
get active() {
|
|
72
|
+
return this._active;
|
|
73
|
+
}
|
|
74
|
+
pause() {
|
|
75
|
+
if (this._active) {
|
|
76
|
+
this._isPaused = true;
|
|
77
|
+
let i, l;
|
|
78
|
+
if (this.scopes) for (i = 0, l = this.scopes.length; i < l; i++) this.scopes[i].pause();
|
|
79
|
+
for (i = 0, l = this.effects.length; i < l; i++) this.effects[i].pause();
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Resumes the effect scope, including all child scopes and effects.
|
|
84
|
+
*/
|
|
85
|
+
resume() {
|
|
86
|
+
if (this._active) {
|
|
87
|
+
if (this._isPaused) {
|
|
88
|
+
this._isPaused = false;
|
|
89
|
+
let i, l;
|
|
90
|
+
if (this.scopes) for (i = 0, l = this.scopes.length; i < l; i++) this.scopes[i].resume();
|
|
91
|
+
for (i = 0, l = this.effects.length; i < l; i++) this.effects[i].resume();
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
run(fn) {
|
|
96
|
+
if (this._active) {
|
|
97
|
+
const currentEffectScope = activeEffectScope;
|
|
98
|
+
try {
|
|
99
|
+
activeEffectScope = this;
|
|
100
|
+
return fn();
|
|
101
|
+
} finally {
|
|
102
|
+
activeEffectScope = currentEffectScope;
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* This should only be called on non-detached scopes
|
|
108
|
+
* @internal
|
|
109
|
+
*/
|
|
110
|
+
on() {
|
|
111
|
+
if (++this._on === 1) {
|
|
112
|
+
this.prevScope = activeEffectScope;
|
|
113
|
+
activeEffectScope = this;
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* This should only be called on non-detached scopes
|
|
118
|
+
* @internal
|
|
119
|
+
*/
|
|
120
|
+
off() {
|
|
121
|
+
if (this._on > 0 && --this._on === 0) {
|
|
122
|
+
if (activeEffectScope === this) activeEffectScope = this.prevScope;
|
|
123
|
+
else {
|
|
124
|
+
let current = activeEffectScope;
|
|
125
|
+
while (current) {
|
|
126
|
+
if (current.prevScope === this) {
|
|
127
|
+
current.prevScope = this.prevScope;
|
|
128
|
+
break;
|
|
129
|
+
}
|
|
130
|
+
current = current.prevScope;
|
|
131
|
+
}
|
|
132
|
+
}
|
|
133
|
+
this.prevScope = void 0;
|
|
134
|
+
}
|
|
135
|
+
}
|
|
136
|
+
stop(fromParent) {
|
|
137
|
+
if (this._active) {
|
|
138
|
+
this._active = false;
|
|
139
|
+
let i, l;
|
|
140
|
+
for (i = 0, l = this.effects.length; i < l; i++) this.effects[i].stop();
|
|
141
|
+
this.effects.length = 0;
|
|
142
|
+
for (i = 0, l = this.cleanups.length; i < l; i++) this.cleanups[i]();
|
|
143
|
+
this.cleanups.length = 0;
|
|
144
|
+
if (this.scopes) {
|
|
145
|
+
for (i = 0, l = this.scopes.length; i < l; i++) this.scopes[i].stop(true);
|
|
146
|
+
this.scopes.length = 0;
|
|
147
|
+
}
|
|
148
|
+
if (!this.detached && this.parent && !fromParent) {
|
|
149
|
+
const last = this.parent.scopes.pop();
|
|
150
|
+
if (last && last !== this) {
|
|
151
|
+
this.parent.scopes[this.index] = last;
|
|
152
|
+
last.index = this.index;
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
this.parent = void 0;
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
};
|
|
159
|
+
/**
|
|
160
|
+
* Creates an effect scope object which can capture the reactive effects (i.e.
|
|
161
|
+
* computed and watchers) created within it so that these effects can be
|
|
162
|
+
* disposed together. For detailed use cases of this API, please consult its
|
|
163
|
+
* corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
|
|
164
|
+
*
|
|
165
|
+
* @param detached - Can be used to create a "detached" effect scope.
|
|
166
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
|
|
167
|
+
*/
|
|
168
|
+
function effectScope(detached) {
|
|
169
|
+
return new EffectScope(detached);
|
|
170
|
+
}
|
|
171
|
+
/**
|
|
172
|
+
* Returns the current active effect scope if there is one.
|
|
173
|
+
*
|
|
174
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
|
|
175
|
+
*/
|
|
176
|
+
function getCurrentScope() {
|
|
177
|
+
return activeEffectScope;
|
|
178
|
+
}
|
|
179
|
+
/**
|
|
180
|
+
* Registers a dispose callback on the current active effect scope. The
|
|
181
|
+
* callback will be invoked when the associated effect scope is stopped.
|
|
182
|
+
*
|
|
183
|
+
* @param fn - The callback function to attach to the scope's cleanup.
|
|
184
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
|
|
185
|
+
*/
|
|
186
|
+
function onScopeDispose(fn, failSilently = false) {
|
|
187
|
+
if (activeEffectScope) activeEffectScope.cleanups.push(fn);
|
|
188
|
+
}
|
|
189
|
+
//#endregion
|
|
190
|
+
//#region packages/core/signal/src/effect.ts
|
|
191
|
+
let activeSub;
|
|
192
|
+
const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
|
|
193
|
+
var ReactiveEffect = class {
|
|
194
|
+
constructor(fn) {
|
|
195
|
+
this.fn = fn;
|
|
196
|
+
this.deps = void 0;
|
|
197
|
+
this.depsTail = void 0;
|
|
198
|
+
this.flags = 5;
|
|
199
|
+
this.next = void 0;
|
|
200
|
+
this.cleanups = void 0;
|
|
201
|
+
this.scheduler = void 0;
|
|
202
|
+
this.scope = activeEffectScope;
|
|
203
|
+
if (activeEffectScope) if (activeEffectScope.active) activeEffectScope.effects.push(this);
|
|
204
|
+
else this.flags &= -2;
|
|
205
|
+
}
|
|
206
|
+
pause() {
|
|
207
|
+
this.flags |= 64;
|
|
208
|
+
}
|
|
209
|
+
resume() {
|
|
210
|
+
if (this.flags & 64) {
|
|
211
|
+
this.flags &= -65;
|
|
212
|
+
if (pausedQueueEffects.has(this)) {
|
|
213
|
+
pausedQueueEffects.delete(this);
|
|
214
|
+
this.trigger();
|
|
215
|
+
}
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
/**
|
|
219
|
+
* @internal
|
|
220
|
+
*/
|
|
221
|
+
notify() {
|
|
222
|
+
if (this.flags & 2 && !(this.flags & 32)) return;
|
|
223
|
+
if (!(this.flags & 8)) queueSubscriber(this);
|
|
224
|
+
}
|
|
225
|
+
run() {
|
|
226
|
+
if (!(this.flags & 1)) return this.fn();
|
|
227
|
+
this.flags |= 2;
|
|
228
|
+
cleanupEffect(this);
|
|
229
|
+
prepareDeps(this);
|
|
230
|
+
const prevEffect = activeSub;
|
|
231
|
+
const prevShouldTrack = shouldTrack;
|
|
232
|
+
activeSub = this;
|
|
233
|
+
shouldTrack = true;
|
|
234
|
+
try {
|
|
235
|
+
return this.fn();
|
|
236
|
+
} finally {
|
|
237
|
+
cleanupDeps(this);
|
|
238
|
+
activeSub = prevEffect;
|
|
239
|
+
shouldTrack = prevShouldTrack;
|
|
240
|
+
this.flags &= -3;
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
stop() {
|
|
244
|
+
if (this.flags & 1) {
|
|
245
|
+
for (let link = this.deps; link; link = link.nextDep) removeSub(link);
|
|
246
|
+
this.deps = this.depsTail = void 0;
|
|
247
|
+
cleanupEffect(this);
|
|
248
|
+
this.onStop && this.onStop();
|
|
249
|
+
this.flags &= -2;
|
|
250
|
+
}
|
|
251
|
+
}
|
|
252
|
+
trigger() {
|
|
253
|
+
if (this.flags & 64) pausedQueueEffects.add(this);
|
|
254
|
+
else if (this.scheduler) this.scheduler();
|
|
255
|
+
else this.runIfDirty();
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* @internal
|
|
259
|
+
*/
|
|
260
|
+
runIfDirty() {
|
|
261
|
+
if (isDirty(this)) this.run();
|
|
262
|
+
}
|
|
263
|
+
get dirty() {
|
|
264
|
+
return isDirty(this);
|
|
265
|
+
}
|
|
266
|
+
};
|
|
267
|
+
/**
|
|
268
|
+
* For debugging
|
|
269
|
+
*/
|
|
270
|
+
let batchDepth = 0;
|
|
271
|
+
let batchedSub;
|
|
272
|
+
let batchedComputed;
|
|
273
|
+
/**
|
|
274
|
+
* @internal
|
|
275
|
+
*/
|
|
276
|
+
function queueSubscriber(sub, isComputed = false) {
|
|
277
|
+
sub.flags |= 8;
|
|
278
|
+
if (isComputed) {
|
|
279
|
+
sub.next = batchedComputed;
|
|
280
|
+
batchedComputed = sub;
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
sub.next = batchedSub;
|
|
284
|
+
batchedSub = sub;
|
|
285
|
+
}
|
|
286
|
+
/**
|
|
287
|
+
* @internal
|
|
288
|
+
*/
|
|
289
|
+
function startBatch() {
|
|
290
|
+
batchDepth++;
|
|
291
|
+
}
|
|
292
|
+
/**
|
|
293
|
+
* Run batched effects when all batches have ended
|
|
294
|
+
* @internal
|
|
295
|
+
*/
|
|
296
|
+
function endBatch() {
|
|
297
|
+
if (--batchDepth > 0) return;
|
|
298
|
+
if (batchedComputed) {
|
|
299
|
+
let e = batchedComputed;
|
|
300
|
+
batchedComputed = void 0;
|
|
301
|
+
while (e) {
|
|
302
|
+
const next = e.next;
|
|
303
|
+
e.next = void 0;
|
|
304
|
+
e.flags &= -9;
|
|
305
|
+
e = next;
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
let error;
|
|
309
|
+
while (batchedSub) {
|
|
310
|
+
let e = batchedSub;
|
|
311
|
+
batchedSub = void 0;
|
|
312
|
+
while (e) {
|
|
313
|
+
const next = e.next;
|
|
314
|
+
e.next = void 0;
|
|
315
|
+
e.flags &= -9;
|
|
316
|
+
if (e.flags & 1) try {
|
|
317
|
+
e.trigger();
|
|
318
|
+
} catch (err) {
|
|
319
|
+
if (!error) error = err;
|
|
320
|
+
}
|
|
321
|
+
e = next;
|
|
322
|
+
}
|
|
323
|
+
}
|
|
324
|
+
if (error) throw error;
|
|
325
|
+
}
|
|
326
|
+
function prepareDeps(sub) {
|
|
327
|
+
for (let link = sub.deps; link; link = link.nextDep) {
|
|
328
|
+
link.version = -1;
|
|
329
|
+
link.prevActiveLink = link.dep.activeLink;
|
|
330
|
+
link.dep.activeLink = link;
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
function cleanupDeps(sub) {
|
|
334
|
+
let head;
|
|
335
|
+
let tail = sub.depsTail;
|
|
336
|
+
let link = tail;
|
|
337
|
+
while (link) {
|
|
338
|
+
const prev = link.prevDep;
|
|
339
|
+
if (link.version === -1) {
|
|
340
|
+
if (link === tail) tail = prev;
|
|
341
|
+
removeSub(link);
|
|
342
|
+
removeDep(link);
|
|
343
|
+
} else head = link;
|
|
344
|
+
link.dep.activeLink = link.prevActiveLink;
|
|
345
|
+
link.prevActiveLink = void 0;
|
|
346
|
+
link = prev;
|
|
347
|
+
}
|
|
348
|
+
sub.deps = head;
|
|
349
|
+
sub.depsTail = tail;
|
|
350
|
+
}
|
|
351
|
+
function isDirty(sub) {
|
|
352
|
+
for (let link = sub.deps; link; link = link.nextDep) if (link.dep.version !== link.version || link.dep.computed && (refreshComputed(link.dep.computed) || link.dep.version !== link.version)) return true;
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
/**
|
|
356
|
+
* Returning false indicates the refresh failed
|
|
357
|
+
* @internal
|
|
358
|
+
*/
|
|
359
|
+
function refreshComputed(computed) {
|
|
360
|
+
if (computed.flags & 4 && !(computed.flags & 16)) return;
|
|
361
|
+
computed.flags &= -17;
|
|
362
|
+
if (computed.globalVersion === globalVersion) return;
|
|
363
|
+
computed.globalVersion = globalVersion;
|
|
364
|
+
if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) return;
|
|
365
|
+
computed.flags |= 2;
|
|
366
|
+
const dep = computed.dep;
|
|
367
|
+
const prevSub = activeSub;
|
|
368
|
+
const prevShouldTrack = shouldTrack;
|
|
369
|
+
activeSub = computed;
|
|
370
|
+
shouldTrack = true;
|
|
371
|
+
try {
|
|
372
|
+
prepareDeps(computed);
|
|
373
|
+
const value = computed.fn(computed._value);
|
|
374
|
+
if (dep.version === 0 || hasChanged(value, computed._value)) {
|
|
375
|
+
computed.flags |= 128;
|
|
376
|
+
computed._value = value;
|
|
377
|
+
dep.version++;
|
|
378
|
+
}
|
|
379
|
+
} catch (err) {
|
|
380
|
+
dep.version++;
|
|
381
|
+
throw err;
|
|
382
|
+
} finally {
|
|
383
|
+
activeSub = prevSub;
|
|
384
|
+
shouldTrack = prevShouldTrack;
|
|
385
|
+
cleanupDeps(computed);
|
|
386
|
+
computed.flags &= -3;
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
function removeSub(link, soft = false) {
|
|
390
|
+
const { dep, prevSub, nextSub } = link;
|
|
391
|
+
if (prevSub) {
|
|
392
|
+
prevSub.nextSub = nextSub;
|
|
393
|
+
link.prevSub = void 0;
|
|
394
|
+
}
|
|
395
|
+
if (nextSub) {
|
|
396
|
+
nextSub.prevSub = prevSub;
|
|
397
|
+
link.nextSub = void 0;
|
|
398
|
+
}
|
|
399
|
+
if (dep.subs === link) {
|
|
400
|
+
dep.subs = prevSub;
|
|
401
|
+
if (!prevSub && dep.computed) {
|
|
402
|
+
dep.computed.flags &= -5;
|
|
403
|
+
for (let l = dep.computed.deps; l; l = l.nextDep) removeSub(l, true);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
if (!soft && !--dep.sc && dep.map) dep.map.delete(dep.key);
|
|
407
|
+
}
|
|
408
|
+
function removeDep(link) {
|
|
409
|
+
const { prevDep, nextDep } = link;
|
|
410
|
+
if (prevDep) {
|
|
411
|
+
prevDep.nextDep = nextDep;
|
|
412
|
+
link.prevDep = void 0;
|
|
413
|
+
}
|
|
414
|
+
if (nextDep) {
|
|
415
|
+
nextDep.prevDep = prevDep;
|
|
416
|
+
link.nextDep = void 0;
|
|
417
|
+
}
|
|
418
|
+
}
|
|
419
|
+
function effect(fn, options) {
|
|
420
|
+
if (fn.effect instanceof ReactiveEffect) fn = fn.effect.fn;
|
|
421
|
+
const e = new ReactiveEffect(fn);
|
|
422
|
+
if (options) extend(e, options);
|
|
423
|
+
try {
|
|
424
|
+
e.run();
|
|
425
|
+
} catch (err) {
|
|
426
|
+
e.stop();
|
|
427
|
+
throw err;
|
|
428
|
+
}
|
|
429
|
+
const runner = e.run.bind(e);
|
|
430
|
+
runner.effect = e;
|
|
431
|
+
return runner;
|
|
432
|
+
}
|
|
433
|
+
/**
|
|
434
|
+
* Stops the effect associated with the given runner.
|
|
435
|
+
*
|
|
436
|
+
* @param runner - Association with the effect to stop tracking.
|
|
437
|
+
*/
|
|
438
|
+
function stop(runner) {
|
|
439
|
+
runner.effect.stop();
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* @internal
|
|
443
|
+
*/
|
|
444
|
+
let shouldTrack = true;
|
|
445
|
+
const trackStack = [];
|
|
446
|
+
/**
|
|
447
|
+
* Temporarily pauses tracking.
|
|
448
|
+
*/
|
|
449
|
+
function pauseTracking() {
|
|
450
|
+
trackStack.push(shouldTrack);
|
|
451
|
+
shouldTrack = false;
|
|
452
|
+
}
|
|
453
|
+
/**
|
|
454
|
+
* Resets the previous global effect tracking state.
|
|
455
|
+
*/
|
|
456
|
+
function resetTracking() {
|
|
457
|
+
const last = trackStack.pop();
|
|
458
|
+
shouldTrack = last === void 0 ? true : last;
|
|
459
|
+
}
|
|
460
|
+
function cleanupEffect(e) {
|
|
461
|
+
const cleanups = e.cleanups;
|
|
462
|
+
e.cleanups = void 0;
|
|
463
|
+
if (cleanups) {
|
|
464
|
+
const prevSub = activeSub;
|
|
465
|
+
activeSub = void 0;
|
|
466
|
+
try {
|
|
467
|
+
let error;
|
|
468
|
+
for (const cleanup of cleanups) try {
|
|
469
|
+
cleanup();
|
|
470
|
+
} catch (cleanupError) {
|
|
471
|
+
var _error;
|
|
472
|
+
(_error = error) !== null && _error !== void 0 || (error = cleanupError);
|
|
473
|
+
}
|
|
474
|
+
if (error) throw error;
|
|
475
|
+
} finally {
|
|
476
|
+
activeSub = prevSub;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
//#endregion
|
|
481
|
+
//#region packages/core/signal/src/dep.ts
|
|
482
|
+
/**
|
|
483
|
+
* Incremented every time a reactive change happens
|
|
484
|
+
* This is used to give computed a fast path to avoid re-compute when nothing
|
|
485
|
+
* has changed.
|
|
486
|
+
*/
|
|
487
|
+
let globalVersion = 0;
|
|
488
|
+
/**
|
|
489
|
+
* Represents a link between a source (Dep) and a subscriber (Effect or Computed).
|
|
490
|
+
* Deps and subs have a many-to-many relationship - each link between a
|
|
491
|
+
* dep and a sub is represented by a Link instance.
|
|
492
|
+
*
|
|
493
|
+
* A Link is also a node in two doubly-linked lists - one for the associated
|
|
494
|
+
* sub to track all its deps, and one for the associated dep to track all its
|
|
495
|
+
* subs.
|
|
496
|
+
*
|
|
497
|
+
* @internal
|
|
498
|
+
*/
|
|
499
|
+
var Link = class {
|
|
500
|
+
constructor(sub, dep) {
|
|
501
|
+
this.sub = sub;
|
|
502
|
+
this.dep = dep;
|
|
503
|
+
this.version = dep.version;
|
|
504
|
+
this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
|
|
505
|
+
}
|
|
506
|
+
};
|
|
507
|
+
/**
|
|
508
|
+
* @internal
|
|
509
|
+
*/
|
|
510
|
+
var Dep = class {
|
|
511
|
+
constructor(computed) {
|
|
512
|
+
this.computed = computed;
|
|
513
|
+
this.version = 0;
|
|
514
|
+
this.activeLink = void 0;
|
|
515
|
+
this.subs = void 0;
|
|
516
|
+
this.map = void 0;
|
|
517
|
+
this.key = void 0;
|
|
518
|
+
this.sc = 0;
|
|
519
|
+
this.__v_skip = true;
|
|
520
|
+
}
|
|
521
|
+
track(debugInfo) {
|
|
522
|
+
if (!activeSub || !shouldTrack || activeSub === this.computed) return;
|
|
523
|
+
let link = this.activeLink;
|
|
524
|
+
if (link === void 0 || link.sub !== activeSub) {
|
|
525
|
+
link = this.activeLink = new Link(activeSub, this);
|
|
526
|
+
if (!activeSub.deps) activeSub.deps = activeSub.depsTail = link;
|
|
527
|
+
else {
|
|
528
|
+
link.prevDep = activeSub.depsTail;
|
|
529
|
+
activeSub.depsTail.nextDep = link;
|
|
530
|
+
activeSub.depsTail = link;
|
|
531
|
+
}
|
|
532
|
+
addSub(link);
|
|
533
|
+
} else if (link.version === -1) {
|
|
534
|
+
link.version = this.version;
|
|
535
|
+
if (link.nextDep) {
|
|
536
|
+
const next = link.nextDep;
|
|
537
|
+
next.prevDep = link.prevDep;
|
|
538
|
+
if (link.prevDep) link.prevDep.nextDep = next;
|
|
539
|
+
link.prevDep = activeSub.depsTail;
|
|
540
|
+
link.nextDep = void 0;
|
|
541
|
+
activeSub.depsTail.nextDep = link;
|
|
542
|
+
activeSub.depsTail = link;
|
|
543
|
+
if (activeSub.deps === link) activeSub.deps = next;
|
|
544
|
+
}
|
|
545
|
+
}
|
|
546
|
+
return link;
|
|
547
|
+
}
|
|
548
|
+
trigger(debugInfo) {
|
|
549
|
+
this.version++;
|
|
550
|
+
globalVersion++;
|
|
551
|
+
this.notify(debugInfo);
|
|
552
|
+
}
|
|
553
|
+
notify(debugInfo) {
|
|
554
|
+
startBatch();
|
|
555
|
+
try {
|
|
556
|
+
for (let link = this.subs; link; link = link.prevSub) if (link.sub.notify()) link.sub.dep.notify();
|
|
557
|
+
} finally {
|
|
558
|
+
endBatch();
|
|
559
|
+
}
|
|
560
|
+
}
|
|
561
|
+
};
|
|
562
|
+
function addSub(link) {
|
|
563
|
+
link.dep.sc++;
|
|
564
|
+
if (link.sub.flags & 4) {
|
|
565
|
+
const computed = link.dep.computed;
|
|
566
|
+
if (computed && !link.dep.subs) {
|
|
567
|
+
computed.flags |= 20;
|
|
568
|
+
for (let l = computed.deps; l; l = l.nextDep) addSub(l);
|
|
569
|
+
}
|
|
570
|
+
const currentTail = link.dep.subs;
|
|
571
|
+
if (currentTail !== link) {
|
|
572
|
+
link.prevSub = currentTail;
|
|
573
|
+
if (currentTail) currentTail.nextSub = link;
|
|
574
|
+
}
|
|
575
|
+
link.dep.subs = link;
|
|
576
|
+
}
|
|
577
|
+
}
|
|
578
|
+
const targetMap = /* @__PURE__ */ new WeakMap();
|
|
579
|
+
const ITERATE_KEY = Symbol("");
|
|
580
|
+
const MAP_KEY_ITERATE_KEY = Symbol("");
|
|
581
|
+
const ARRAY_ITERATE_KEY = Symbol("");
|
|
582
|
+
/**
|
|
583
|
+
* Tracks access to a reactive property.
|
|
584
|
+
*
|
|
585
|
+
* This will check which effect is running at the moment and record it as dep
|
|
586
|
+
* which records all effects that depend on the reactive property.
|
|
587
|
+
*
|
|
588
|
+
* @param target - Object holding the reactive property.
|
|
589
|
+
* @param type - Defines the type of access to the reactive property.
|
|
590
|
+
* @param key - Identifier of the reactive property to track.
|
|
591
|
+
*/
|
|
592
|
+
function track(target, type, key) {
|
|
593
|
+
if (shouldTrack && activeSub) {
|
|
594
|
+
let depsMap = targetMap.get(target);
|
|
595
|
+
if (!depsMap) targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
|
|
596
|
+
let dep = depsMap.get(key);
|
|
597
|
+
if (!dep) {
|
|
598
|
+
depsMap.set(key, dep = new Dep());
|
|
599
|
+
dep.map = depsMap;
|
|
600
|
+
dep.key = key;
|
|
601
|
+
}
|
|
602
|
+
dep.track();
|
|
603
|
+
}
|
|
604
|
+
}
|
|
605
|
+
/**
|
|
606
|
+
* Finds all deps associated with the target (or a specific property) and
|
|
607
|
+
* triggers the effects stored within.
|
|
608
|
+
*
|
|
609
|
+
* @param target - The reactive object.
|
|
610
|
+
* @param type - Defines the type of the operation that needs to trigger effects.
|
|
611
|
+
* @param key - Can be used to target a specific reactive property in the target object.
|
|
612
|
+
*/
|
|
613
|
+
function trigger(target, type, key, newValue, oldValue, oldTarget) {
|
|
614
|
+
const depsMap = targetMap.get(target);
|
|
615
|
+
if (!depsMap) {
|
|
616
|
+
globalVersion++;
|
|
617
|
+
return;
|
|
618
|
+
}
|
|
619
|
+
const run = (dep) => {
|
|
620
|
+
if (dep) dep.trigger();
|
|
621
|
+
};
|
|
622
|
+
startBatch();
|
|
623
|
+
if (type === "clear") depsMap.forEach(run);
|
|
624
|
+
else {
|
|
625
|
+
const targetIsArray = isArray(target);
|
|
626
|
+
const isArrayIndex = targetIsArray && isIntegerKey(key);
|
|
627
|
+
if (targetIsArray && key === "length") {
|
|
628
|
+
const newLength = Number(newValue);
|
|
629
|
+
depsMap.forEach((dep, key) => {
|
|
630
|
+
if (key === "length" || key === ARRAY_ITERATE_KEY || !isSymbol(key) && key >= newLength) run(dep);
|
|
631
|
+
});
|
|
632
|
+
} else {
|
|
633
|
+
if (key !== void 0 || depsMap.has(void 0)) run(depsMap.get(key));
|
|
634
|
+
if (isArrayIndex) run(depsMap.get(ARRAY_ITERATE_KEY));
|
|
635
|
+
switch (type) {
|
|
636
|
+
case "add":
|
|
637
|
+
if (!targetIsArray) {
|
|
638
|
+
run(depsMap.get(ITERATE_KEY));
|
|
639
|
+
if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
640
|
+
} else if (isArrayIndex) run(depsMap.get("length"));
|
|
641
|
+
break;
|
|
642
|
+
case "delete":
|
|
643
|
+
if (!targetIsArray) {
|
|
644
|
+
run(depsMap.get(ITERATE_KEY));
|
|
645
|
+
if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
|
|
646
|
+
}
|
|
647
|
+
break;
|
|
648
|
+
case "set":
|
|
649
|
+
if (isMap(target)) run(depsMap.get(ITERATE_KEY));
|
|
650
|
+
break;
|
|
651
|
+
}
|
|
652
|
+
}
|
|
653
|
+
}
|
|
654
|
+
endBatch();
|
|
655
|
+
}
|
|
656
|
+
//#endregion
|
|
657
|
+
//#region packages/core/signal/src/arrayInstrumentations.ts
|
|
658
|
+
/**
|
|
659
|
+
* Track array iteration and return:
|
|
660
|
+
* - if input is reactive: a cloned raw array with reactive values
|
|
661
|
+
* - if input is non-reactive or shallowReactive: the original raw array
|
|
662
|
+
*/
|
|
663
|
+
function reactiveReadArray(array) {
|
|
664
|
+
const raw = /* @__PURE__ */ toRaw(array);
|
|
665
|
+
if (raw === array) return raw;
|
|
666
|
+
track(raw, "iterate", ARRAY_ITERATE_KEY);
|
|
667
|
+
return /* @__PURE__ */ isShallow(array) ? raw : raw.map(toReactive);
|
|
668
|
+
}
|
|
669
|
+
/**
|
|
670
|
+
* Track array iteration and return raw array
|
|
671
|
+
*/
|
|
672
|
+
function shallowReadArray(arr) {
|
|
673
|
+
track(arr = /* @__PURE__ */ toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
|
|
674
|
+
return arr;
|
|
675
|
+
}
|
|
676
|
+
function toWrapped(target, item) {
|
|
677
|
+
if (/* @__PURE__ */ isReadonly(target)) return /* @__PURE__ */ isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
|
|
678
|
+
return toReactive(item);
|
|
679
|
+
}
|
|
680
|
+
const arrayInstrumentations = {
|
|
681
|
+
__proto__: null,
|
|
682
|
+
[Symbol.iterator]() {
|
|
683
|
+
return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
|
|
684
|
+
},
|
|
685
|
+
concat(...args) {
|
|
686
|
+
return reactiveReadArray(this).concat(...args.map((x) => isArray(x) ? reactiveReadArray(x) : x));
|
|
687
|
+
},
|
|
688
|
+
entries() {
|
|
689
|
+
return iterator(this, "entries", (value) => {
|
|
690
|
+
value[1] = toWrapped(this, value[1]);
|
|
691
|
+
return value;
|
|
692
|
+
});
|
|
693
|
+
},
|
|
694
|
+
every(fn, thisArg) {
|
|
695
|
+
return apply(this, "every", fn, thisArg, void 0, arguments);
|
|
696
|
+
},
|
|
697
|
+
filter(fn, thisArg) {
|
|
698
|
+
return apply(this, "filter", fn, thisArg, (v) => v.map((item) => toWrapped(this, item)), arguments);
|
|
699
|
+
},
|
|
700
|
+
find(fn, thisArg) {
|
|
701
|
+
return apply(this, "find", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
702
|
+
},
|
|
703
|
+
findIndex(fn, thisArg) {
|
|
704
|
+
return apply(this, "findIndex", fn, thisArg, void 0, arguments);
|
|
705
|
+
},
|
|
706
|
+
findLast(fn, thisArg) {
|
|
707
|
+
return apply(this, "findLast", fn, thisArg, (item) => toWrapped(this, item), arguments);
|
|
708
|
+
},
|
|
709
|
+
findLastIndex(fn, thisArg) {
|
|
710
|
+
return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
|
|
711
|
+
},
|
|
712
|
+
forEach(fn, thisArg) {
|
|
713
|
+
return apply(this, "forEach", fn, thisArg, void 0, arguments);
|
|
714
|
+
},
|
|
715
|
+
includes(...args) {
|
|
716
|
+
return searchProxy(this, "includes", args);
|
|
717
|
+
},
|
|
718
|
+
indexOf(...args) {
|
|
719
|
+
return searchProxy(this, "indexOf", args);
|
|
720
|
+
},
|
|
721
|
+
join(separator) {
|
|
722
|
+
return reactiveReadArray(this).join(separator);
|
|
723
|
+
},
|
|
724
|
+
lastIndexOf(...args) {
|
|
725
|
+
return searchProxy(this, "lastIndexOf", args);
|
|
726
|
+
},
|
|
727
|
+
map(fn, thisArg) {
|
|
728
|
+
return apply(this, "map", fn, thisArg, void 0, arguments);
|
|
729
|
+
},
|
|
730
|
+
pop() {
|
|
731
|
+
return noTracking(this, "pop");
|
|
732
|
+
},
|
|
733
|
+
push(...args) {
|
|
734
|
+
return noTracking(this, "push", args);
|
|
735
|
+
},
|
|
736
|
+
reduce(fn, ...args) {
|
|
737
|
+
return reduce(this, "reduce", fn, args);
|
|
738
|
+
},
|
|
739
|
+
reduceRight(fn, ...args) {
|
|
740
|
+
return reduce(this, "reduceRight", fn, args);
|
|
741
|
+
},
|
|
742
|
+
shift() {
|
|
743
|
+
return noTracking(this, "shift");
|
|
744
|
+
},
|
|
745
|
+
some(fn, thisArg) {
|
|
746
|
+
return apply(this, "some", fn, thisArg, void 0, arguments);
|
|
747
|
+
},
|
|
748
|
+
splice(...args) {
|
|
749
|
+
return noTracking(this, "splice", args);
|
|
750
|
+
},
|
|
751
|
+
toReversed() {
|
|
752
|
+
return reactiveReadArray(this).toReversed();
|
|
753
|
+
},
|
|
754
|
+
toSorted(comparer) {
|
|
755
|
+
return reactiveReadArray(this).toSorted(comparer);
|
|
756
|
+
},
|
|
757
|
+
toSpliced(...args) {
|
|
758
|
+
return reactiveReadArray(this).toSpliced(...args);
|
|
759
|
+
},
|
|
760
|
+
unshift(...args) {
|
|
761
|
+
return noTracking(this, "unshift", args);
|
|
762
|
+
},
|
|
763
|
+
values() {
|
|
764
|
+
return iterator(this, "values", (item) => toWrapped(this, item));
|
|
765
|
+
}
|
|
766
|
+
};
|
|
767
|
+
function iterator(self, method, wrapValue) {
|
|
768
|
+
const arr = shallowReadArray(self);
|
|
769
|
+
const iter = arr[method]();
|
|
770
|
+
if (arr !== self && !/* @__PURE__ */ isShallow(self)) {
|
|
771
|
+
iter._next = iter.next;
|
|
772
|
+
iter.next = () => {
|
|
773
|
+
const result = iter._next();
|
|
774
|
+
if (!result.done) result.value = wrapValue(result.value);
|
|
775
|
+
return result;
|
|
776
|
+
};
|
|
777
|
+
}
|
|
778
|
+
return iter;
|
|
779
|
+
}
|
|
780
|
+
const arrayProto = Array.prototype;
|
|
781
|
+
function apply(self, method, fn, thisArg, wrappedRetFn, args) {
|
|
782
|
+
const arr = shallowReadArray(self);
|
|
783
|
+
const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
|
|
784
|
+
const methodFn = arr[method];
|
|
785
|
+
if (methodFn !== arrayProto[method]) {
|
|
786
|
+
const result = methodFn.apply(self, args);
|
|
787
|
+
return needsWrap ? toReactive(result) : result;
|
|
788
|
+
}
|
|
789
|
+
let wrappedFn = fn;
|
|
790
|
+
if (arr !== self) {
|
|
791
|
+
if (needsWrap) wrappedFn = function(item, index) {
|
|
792
|
+
return fn.call(this, toWrapped(self, item), index, self);
|
|
793
|
+
};
|
|
794
|
+
else if (fn.length > 2) wrappedFn = function(item, index) {
|
|
795
|
+
return fn.call(this, item, index, self);
|
|
796
|
+
};
|
|
797
|
+
}
|
|
798
|
+
const result = methodFn.call(arr, wrappedFn, thisArg);
|
|
799
|
+
return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
|
|
800
|
+
}
|
|
801
|
+
function reduce(self, method, fn, args) {
|
|
802
|
+
const arr = shallowReadArray(self);
|
|
803
|
+
const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
|
|
804
|
+
let wrappedFn = fn;
|
|
805
|
+
let wrapInitialAccumulator = false;
|
|
806
|
+
if (arr !== self) {
|
|
807
|
+
if (needsWrap) {
|
|
808
|
+
wrapInitialAccumulator = args.length === 0;
|
|
809
|
+
wrappedFn = function(acc, item, index) {
|
|
810
|
+
if (wrapInitialAccumulator) {
|
|
811
|
+
wrapInitialAccumulator = false;
|
|
812
|
+
acc = toWrapped(self, acc);
|
|
813
|
+
}
|
|
814
|
+
return fn.call(this, acc, toWrapped(self, item), index, self);
|
|
815
|
+
};
|
|
816
|
+
} else if (fn.length > 3) wrappedFn = function(acc, item, index) {
|
|
817
|
+
return fn.call(this, acc, item, index, self);
|
|
818
|
+
};
|
|
819
|
+
}
|
|
820
|
+
const result = arr[method](wrappedFn, ...args);
|
|
821
|
+
return wrapInitialAccumulator ? toWrapped(self, result) : result;
|
|
822
|
+
}
|
|
823
|
+
function searchProxy(self, method, args) {
|
|
824
|
+
const arr = /* @__PURE__ */ toRaw(self);
|
|
825
|
+
track(arr, "iterate", ARRAY_ITERATE_KEY);
|
|
826
|
+
const res = arr[method](...args);
|
|
827
|
+
if ((res === -1 || res === false) && /* @__PURE__ */ isProxy(args[0])) {
|
|
828
|
+
args[0] = /* @__PURE__ */ toRaw(args[0]);
|
|
829
|
+
return arr[method](...args);
|
|
830
|
+
}
|
|
831
|
+
return res;
|
|
832
|
+
}
|
|
833
|
+
function noTracking(self, method, args = []) {
|
|
834
|
+
pauseTracking();
|
|
835
|
+
startBatch();
|
|
836
|
+
const res = (/* @__PURE__ */ toRaw(self))[method].apply(self, args);
|
|
837
|
+
endBatch();
|
|
838
|
+
resetTracking();
|
|
839
|
+
return res;
|
|
840
|
+
}
|
|
841
|
+
//#endregion
|
|
842
|
+
//#region packages/core/signal/src/ref.ts
|
|
843
|
+
let _ReactiveFlags$IS_REF, _ReactiveFlags$IS_SHA;
|
|
844
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
845
|
+
function isRef(r) {
|
|
846
|
+
return r ? r["__v_isRef"] === true : false;
|
|
847
|
+
}
|
|
848
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
849
|
+
function ref(value) {
|
|
850
|
+
return createRef(value, false);
|
|
851
|
+
}
|
|
852
|
+
function createRef(rawValue, shallow) {
|
|
853
|
+
if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
|
|
854
|
+
return new RefImpl(rawValue, shallow);
|
|
855
|
+
}
|
|
856
|
+
_ReactiveFlags$IS_REF = "__v_isRef";
|
|
857
|
+
_ReactiveFlags$IS_SHA = "__v_isShallow";
|
|
858
|
+
/**
|
|
859
|
+
* @internal
|
|
860
|
+
*/
|
|
861
|
+
var RefImpl = class {
|
|
862
|
+
constructor(value, isShallow) {
|
|
863
|
+
this.dep = new Dep();
|
|
864
|
+
this[_ReactiveFlags$IS_REF] = true;
|
|
865
|
+
this[_ReactiveFlags$IS_SHA] = false;
|
|
866
|
+
this._rawValue = isShallow ? value : /* @__PURE__ */ toRaw(value);
|
|
867
|
+
this._value = isShallow ? value : toReactive(value);
|
|
868
|
+
this["__v_isShallow"] = isShallow;
|
|
869
|
+
}
|
|
870
|
+
get value() {
|
|
871
|
+
this.dep.track();
|
|
872
|
+
return this._value;
|
|
873
|
+
}
|
|
874
|
+
set value(newValue) {
|
|
875
|
+
const oldValue = this._rawValue;
|
|
876
|
+
const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
|
|
877
|
+
newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
|
|
878
|
+
if (hasChanged(newValue, oldValue)) {
|
|
879
|
+
this._rawValue = newValue;
|
|
880
|
+
this._value = useDirectValue ? newValue : toReactive(newValue);
|
|
881
|
+
this.dep.trigger();
|
|
882
|
+
}
|
|
883
|
+
}
|
|
884
|
+
};
|
|
885
|
+
//#endregion
|
|
886
|
+
//#region packages/core/signal/src/baseHandlers.ts
|
|
887
|
+
const isNonTrackableKeys = /*@__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
|
|
888
|
+
const builtInSymbols = new Set(/*@__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
|
|
889
|
+
function hasOwnProperty(key) {
|
|
890
|
+
if (!isSymbol(key)) key = String(key);
|
|
891
|
+
const obj = /* @__PURE__ */ toRaw(this);
|
|
892
|
+
track(obj, "has", key);
|
|
893
|
+
return obj.hasOwnProperty(key);
|
|
894
|
+
}
|
|
895
|
+
var BaseReactiveHandler = class {
|
|
896
|
+
constructor(_isReadonly = false, _isShallow = false) {
|
|
897
|
+
this._isReadonly = _isReadonly;
|
|
898
|
+
this._isShallow = _isShallow;
|
|
899
|
+
}
|
|
900
|
+
get(target, key, receiver) {
|
|
901
|
+
if (key === "__v_skip") return target["__v_skip"];
|
|
902
|
+
const isReadonly = this._isReadonly, isShallow = this._isShallow;
|
|
903
|
+
if (key === "__v_isReactive") return !isReadonly;
|
|
904
|
+
else if (key === "__v_isReadonly") return isReadonly;
|
|
905
|
+
else if (key === "__v_isShallow") return isShallow;
|
|
906
|
+
else if (key === "__v_raw") {
|
|
907
|
+
if (receiver === (isReadonly ? isShallow ? shallowReadonlyMap : readonlyMap : isShallow ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) return target;
|
|
908
|
+
return;
|
|
909
|
+
}
|
|
910
|
+
const targetIsArray = isArray(target);
|
|
911
|
+
if (!isReadonly) {
|
|
912
|
+
let fn;
|
|
913
|
+
if (targetIsArray && (fn = arrayInstrumentations[key])) return fn;
|
|
914
|
+
if (key === "hasOwnProperty") return hasOwnProperty;
|
|
915
|
+
}
|
|
916
|
+
const res = Reflect.get(target, key, /* @__PURE__ */ isRef(target) ? target : receiver);
|
|
917
|
+
if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) return res;
|
|
918
|
+
if (!isReadonly) track(target, "get", key);
|
|
919
|
+
if (isShallow) return res;
|
|
920
|
+
if (/* @__PURE__ */ isRef(res)) {
|
|
921
|
+
const value = targetIsArray && isIntegerKey(key) ? res : res.value;
|
|
922
|
+
return isReadonly && isObject(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
923
|
+
}
|
|
924
|
+
if (isObject(res)) return isReadonly ? /* @__PURE__ */ readonly(res) : /* @__PURE__ */ reactive(res);
|
|
925
|
+
return res;
|
|
926
|
+
}
|
|
927
|
+
};
|
|
928
|
+
var MutableReactiveHandler = class extends BaseReactiveHandler {
|
|
929
|
+
constructor(isShallow = false) {
|
|
930
|
+
super(false, isShallow);
|
|
931
|
+
}
|
|
932
|
+
set(target, key, value, receiver) {
|
|
933
|
+
let oldValue = target[key];
|
|
934
|
+
const isArrayWithIntegerKey = isArray(target) && isIntegerKey(key);
|
|
935
|
+
if (!this._isShallow) {
|
|
936
|
+
const isOldValueReadonly = /* @__PURE__ */ isReadonly(oldValue);
|
|
937
|
+
if (!/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) {
|
|
938
|
+
oldValue = /* @__PURE__ */ toRaw(oldValue);
|
|
939
|
+
value = /* @__PURE__ */ toRaw(value);
|
|
940
|
+
}
|
|
941
|
+
if (!isArrayWithIntegerKey && /* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) if (isOldValueReadonly) return true;
|
|
942
|
+
else {
|
|
943
|
+
oldValue.value = value;
|
|
944
|
+
return true;
|
|
945
|
+
}
|
|
946
|
+
}
|
|
947
|
+
const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
|
|
948
|
+
const result = Reflect.set(target, key, value, /* @__PURE__ */ isRef(target) ? target : receiver);
|
|
949
|
+
if (target === /* @__PURE__ */ toRaw(receiver)) {
|
|
950
|
+
if (!hadKey) trigger(target, "add", key, value);
|
|
951
|
+
else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
|
|
952
|
+
}
|
|
953
|
+
return result;
|
|
954
|
+
}
|
|
955
|
+
deleteProperty(target, key) {
|
|
956
|
+
const hadKey = hasOwn(target, key);
|
|
957
|
+
const oldValue = target[key];
|
|
958
|
+
const result = Reflect.deleteProperty(target, key);
|
|
959
|
+
if (result && hadKey) trigger(target, "delete", key, void 0, oldValue);
|
|
960
|
+
return result;
|
|
961
|
+
}
|
|
962
|
+
has(target, key) {
|
|
963
|
+
const result = Reflect.has(target, key);
|
|
964
|
+
if (!isSymbol(key) || !builtInSymbols.has(key)) track(target, "has", key);
|
|
965
|
+
return result;
|
|
966
|
+
}
|
|
967
|
+
ownKeys(target) {
|
|
968
|
+
track(target, "iterate", isArray(target) ? "length" : ITERATE_KEY);
|
|
969
|
+
return Reflect.ownKeys(target);
|
|
970
|
+
}
|
|
971
|
+
};
|
|
972
|
+
var ReadonlyReactiveHandler = class extends BaseReactiveHandler {
|
|
973
|
+
constructor(isShallow = false) {
|
|
974
|
+
super(true, isShallow);
|
|
975
|
+
}
|
|
976
|
+
set(target, key) {
|
|
977
|
+
return true;
|
|
978
|
+
}
|
|
979
|
+
deleteProperty(target, key) {
|
|
980
|
+
return true;
|
|
981
|
+
}
|
|
982
|
+
};
|
|
983
|
+
const mutableHandlers = /*@__PURE__*/ new MutableReactiveHandler();
|
|
984
|
+
const readonlyHandlers = /*@__PURE__*/ new ReadonlyReactiveHandler();
|
|
985
|
+
//#endregion
|
|
986
|
+
//#region packages/core/signal/src/collectionHandlers.ts
|
|
987
|
+
const toShallow = (value) => value;
|
|
988
|
+
const getProto = (v) => Reflect.getPrototypeOf(v);
|
|
989
|
+
function createIterableMethod(method, isReadonly, isShallow) {
|
|
990
|
+
return function(...args) {
|
|
991
|
+
const target = this["__v_raw"];
|
|
992
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
993
|
+
const targetIsMap = isMap(rawTarget);
|
|
994
|
+
const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
|
|
995
|
+
const isKeyOnly = method === "keys" && targetIsMap;
|
|
996
|
+
const innerIterator = target[method](...args);
|
|
997
|
+
const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
|
|
998
|
+
!isReadonly && track(rawTarget, "iterate", isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
|
|
999
|
+
return extend(Object.create(innerIterator), { next() {
|
|
1000
|
+
const { value, done } = innerIterator.next();
|
|
1001
|
+
return done ? {
|
|
1002
|
+
value,
|
|
1003
|
+
done
|
|
1004
|
+
} : {
|
|
1005
|
+
value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
|
|
1006
|
+
done
|
|
1007
|
+
};
|
|
1008
|
+
} });
|
|
1009
|
+
};
|
|
1010
|
+
}
|
|
1011
|
+
function createReadonlyMethod(type) {
|
|
1012
|
+
return function(...args) {
|
|
1013
|
+
return type === "delete" ? false : type === "clear" ? void 0 : this;
|
|
1014
|
+
};
|
|
1015
|
+
}
|
|
1016
|
+
function createInstrumentations(readonly, shallow) {
|
|
1017
|
+
const instrumentations = {
|
|
1018
|
+
get(key) {
|
|
1019
|
+
const target = this["__v_raw"];
|
|
1020
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
1021
|
+
const rawKey = /* @__PURE__ */ toRaw(key);
|
|
1022
|
+
if (!readonly) {
|
|
1023
|
+
if (hasChanged(key, rawKey)) track(rawTarget, "get", key);
|
|
1024
|
+
track(rawTarget, "get", rawKey);
|
|
1025
|
+
}
|
|
1026
|
+
const { has } = getProto(rawTarget);
|
|
1027
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
1028
|
+
if (has.call(rawTarget, key)) return wrap(target.get(key));
|
|
1029
|
+
else if (has.call(rawTarget, rawKey)) return wrap(target.get(rawKey));
|
|
1030
|
+
else if (target !== rawTarget) target.get(key);
|
|
1031
|
+
},
|
|
1032
|
+
get size() {
|
|
1033
|
+
const target = this["__v_raw"];
|
|
1034
|
+
!readonly && track(/* @__PURE__ */ toRaw(target), "iterate", ITERATE_KEY);
|
|
1035
|
+
return target.size;
|
|
1036
|
+
},
|
|
1037
|
+
has(key) {
|
|
1038
|
+
const target = this["__v_raw"];
|
|
1039
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
1040
|
+
const rawKey = /* @__PURE__ */ toRaw(key);
|
|
1041
|
+
if (!readonly) {
|
|
1042
|
+
if (hasChanged(key, rawKey)) track(rawTarget, "has", key);
|
|
1043
|
+
track(rawTarget, "has", rawKey);
|
|
1044
|
+
}
|
|
1045
|
+
return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
|
|
1046
|
+
},
|
|
1047
|
+
forEach(callback, thisArg) {
|
|
1048
|
+
const observed = this;
|
|
1049
|
+
const target = observed["__v_raw"];
|
|
1050
|
+
const rawTarget = /* @__PURE__ */ toRaw(target);
|
|
1051
|
+
const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
|
|
1052
|
+
!readonly && track(rawTarget, "iterate", ITERATE_KEY);
|
|
1053
|
+
return target.forEach((value, key) => {
|
|
1054
|
+
return callback.call(thisArg, wrap(value), wrap(key), observed);
|
|
1055
|
+
});
|
|
1056
|
+
}
|
|
1057
|
+
};
|
|
1058
|
+
extend(instrumentations, readonly ? {
|
|
1059
|
+
add: createReadonlyMethod("add"),
|
|
1060
|
+
set: createReadonlyMethod("set"),
|
|
1061
|
+
delete: createReadonlyMethod("delete"),
|
|
1062
|
+
clear: createReadonlyMethod("clear")
|
|
1063
|
+
} : {
|
|
1064
|
+
add(value) {
|
|
1065
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
1066
|
+
const proto = getProto(target);
|
|
1067
|
+
const rawValue = /* @__PURE__ */ toRaw(value);
|
|
1068
|
+
const valueToAdd = !shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value) ? rawValue : value;
|
|
1069
|
+
if (!(proto.has.call(target, valueToAdd) || hasChanged(value, valueToAdd) && proto.has.call(target, value) || hasChanged(rawValue, valueToAdd) && proto.has.call(target, rawValue))) {
|
|
1070
|
+
target.add(valueToAdd);
|
|
1071
|
+
trigger(target, "add", valueToAdd, valueToAdd);
|
|
1072
|
+
}
|
|
1073
|
+
return this;
|
|
1074
|
+
},
|
|
1075
|
+
set(key, value) {
|
|
1076
|
+
if (!shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) value = /* @__PURE__ */ toRaw(value);
|
|
1077
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
1078
|
+
const { has, get } = getProto(target);
|
|
1079
|
+
let hadKey = has.call(target, key);
|
|
1080
|
+
if (!hadKey) {
|
|
1081
|
+
key = /* @__PURE__ */ toRaw(key);
|
|
1082
|
+
hadKey = has.call(target, key);
|
|
1083
|
+
}
|
|
1084
|
+
const oldValue = get.call(target, key);
|
|
1085
|
+
target.set(key, value);
|
|
1086
|
+
if (!hadKey) trigger(target, "add", key, value);
|
|
1087
|
+
else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
|
|
1088
|
+
return this;
|
|
1089
|
+
},
|
|
1090
|
+
delete(key) {
|
|
1091
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
1092
|
+
const { has, get } = getProto(target);
|
|
1093
|
+
let hadKey = has.call(target, key);
|
|
1094
|
+
if (!hadKey) {
|
|
1095
|
+
key = /* @__PURE__ */ toRaw(key);
|
|
1096
|
+
hadKey = has.call(target, key);
|
|
1097
|
+
}
|
|
1098
|
+
const oldValue = get ? get.call(target, key) : void 0;
|
|
1099
|
+
const result = target.delete(key);
|
|
1100
|
+
if (hadKey) trigger(target, "delete", key, void 0, oldValue);
|
|
1101
|
+
return result;
|
|
1102
|
+
},
|
|
1103
|
+
clear() {
|
|
1104
|
+
const target = /* @__PURE__ */ toRaw(this);
|
|
1105
|
+
const hadItems = target.size !== 0;
|
|
1106
|
+
const oldTarget = void 0;
|
|
1107
|
+
const result = target.clear();
|
|
1108
|
+
if (hadItems) trigger(target, "clear", void 0, void 0, oldTarget);
|
|
1109
|
+
return result;
|
|
1110
|
+
}
|
|
1111
|
+
});
|
|
1112
|
+
[
|
|
1113
|
+
"keys",
|
|
1114
|
+
"values",
|
|
1115
|
+
"entries",
|
|
1116
|
+
Symbol.iterator
|
|
1117
|
+
].forEach((method) => {
|
|
1118
|
+
instrumentations[method] = createIterableMethod(method, readonly, shallow);
|
|
1119
|
+
});
|
|
1120
|
+
return instrumentations;
|
|
1121
|
+
}
|
|
1122
|
+
function createInstrumentationGetter(isReadonly, shallow) {
|
|
1123
|
+
const instrumentations = createInstrumentations(isReadonly, shallow);
|
|
1124
|
+
return (target, key, receiver) => {
|
|
1125
|
+
if (key === "__v_isReactive") return !isReadonly;
|
|
1126
|
+
else if (key === "__v_isReadonly") return isReadonly;
|
|
1127
|
+
else if (key === "__v_raw") return target;
|
|
1128
|
+
return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver);
|
|
1129
|
+
};
|
|
1130
|
+
}
|
|
1131
|
+
const mutableCollectionHandlers = { get: /*@__PURE__*/ createInstrumentationGetter(false, false) };
|
|
1132
|
+
const readonlyCollectionHandlers = { get: /*@__PURE__*/ createInstrumentationGetter(true, false) };
|
|
1133
|
+
//#endregion
|
|
1134
|
+
//#region packages/core/signal/src/reactive.ts
|
|
1135
|
+
const reactiveMap = /* @__PURE__ */ new WeakMap();
|
|
1136
|
+
const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
|
|
1137
|
+
const readonlyMap = /* @__PURE__ */ new WeakMap();
|
|
1138
|
+
const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
|
|
1139
|
+
function targetTypeMap(rawType) {
|
|
1140
|
+
switch (rawType) {
|
|
1141
|
+
case "Object":
|
|
1142
|
+
case "Array": return 1;
|
|
1143
|
+
case "Map":
|
|
1144
|
+
case "Set":
|
|
1145
|
+
case "WeakMap":
|
|
1146
|
+
case "WeakSet": return 2;
|
|
1147
|
+
default: return 0;
|
|
1148
|
+
}
|
|
1149
|
+
}
|
|
1150
|
+
function getTargetType(value) {
|
|
1151
|
+
return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
|
|
1152
|
+
}
|
|
1153
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1154
|
+
function reactive(target) {
|
|
1155
|
+
if (/* @__PURE__ */ isReadonly(target)) return target;
|
|
1156
|
+
return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
|
|
1157
|
+
}
|
|
1158
|
+
/**
|
|
1159
|
+
* Takes an object (reactive or plain) or a ref and returns a readonly proxy to
|
|
1160
|
+
* the original.
|
|
1161
|
+
*
|
|
1162
|
+
* A readonly proxy is deep: any nested property accessed will be readonly as
|
|
1163
|
+
* well. It also has the same ref-unwrapping behavior as {@link reactive},
|
|
1164
|
+
* except the unwrapped values will also be made readonly.
|
|
1165
|
+
*
|
|
1166
|
+
* @example
|
|
1167
|
+
* ```js
|
|
1168
|
+
* const original = reactive({ count: 0 })
|
|
1169
|
+
*
|
|
1170
|
+
* const copy = readonly(original)
|
|
1171
|
+
*
|
|
1172
|
+
* watchEffect(() => {
|
|
1173
|
+
* // works for reactivity tracking
|
|
1174
|
+
* console.log(copy.count)
|
|
1175
|
+
* })
|
|
1176
|
+
*
|
|
1177
|
+
* // mutating original will trigger watchers relying on the copy
|
|
1178
|
+
* original.count++
|
|
1179
|
+
*
|
|
1180
|
+
* // mutating the copy will fail and result in a warning
|
|
1181
|
+
* copy.count++ // warning!
|
|
1182
|
+
* ```
|
|
1183
|
+
*
|
|
1184
|
+
* @param target - The source object.
|
|
1185
|
+
* @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
|
|
1186
|
+
*/
|
|
1187
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1188
|
+
function readonly(target) {
|
|
1189
|
+
return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
|
|
1190
|
+
}
|
|
1191
|
+
function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
|
|
1192
|
+
if (!isObject(target)) return target;
|
|
1193
|
+
if (target["__v_raw"] && !(isReadonly && target["__v_isReactive"])) return target;
|
|
1194
|
+
const targetType = getTargetType(target);
|
|
1195
|
+
if (targetType === 0) return target;
|
|
1196
|
+
const existingProxy = proxyMap.get(target);
|
|
1197
|
+
if (existingProxy) return existingProxy;
|
|
1198
|
+
const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
|
|
1199
|
+
proxyMap.set(target, proxy);
|
|
1200
|
+
return proxy;
|
|
1201
|
+
}
|
|
1202
|
+
/**
|
|
1203
|
+
* Checks if an object is a proxy created by {@link reactive} or
|
|
1204
|
+
* {@link shallowReactive} (or {@link ref} in some cases).
|
|
1205
|
+
*
|
|
1206
|
+
* @example
|
|
1207
|
+
* ```js
|
|
1208
|
+
* isReactive(reactive({})) // => true
|
|
1209
|
+
* isReactive(readonly(reactive({}))) // => true
|
|
1210
|
+
* isReactive(ref({}).value) // => true
|
|
1211
|
+
* isReactive(readonly(ref({})).value) // => true
|
|
1212
|
+
* isReactive(ref(true)) // => false
|
|
1213
|
+
* isReactive(shallowRef({}).value) // => false
|
|
1214
|
+
* isReactive(shallowReactive({})) // => true
|
|
1215
|
+
* ```
|
|
1216
|
+
*
|
|
1217
|
+
* @param value - The value to check.
|
|
1218
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
|
|
1219
|
+
*/
|
|
1220
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1221
|
+
function isReactive(value) {
|
|
1222
|
+
if (/* @__PURE__ */ isReadonly(value)) return /* @__PURE__ */ isReactive(value["__v_raw"]);
|
|
1223
|
+
return !!(value && value["__v_isReactive"]);
|
|
1224
|
+
}
|
|
1225
|
+
/**
|
|
1226
|
+
* Checks whether the passed value is a readonly object. The properties of a
|
|
1227
|
+
* readonly object can change, but they can't be assigned directly via the
|
|
1228
|
+
* passed object.
|
|
1229
|
+
*
|
|
1230
|
+
* The proxies created by {@link readonly} and {@link shallowReadonly} are
|
|
1231
|
+
* both considered readonly, as is a computed ref without a set function.
|
|
1232
|
+
*
|
|
1233
|
+
* @param value - The value to check.
|
|
1234
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
|
|
1235
|
+
*/
|
|
1236
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1237
|
+
function isReadonly(value) {
|
|
1238
|
+
return !!(value && value["__v_isReadonly"]);
|
|
1239
|
+
}
|
|
1240
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1241
|
+
function isShallow(value) {
|
|
1242
|
+
return !!(value && value["__v_isShallow"]);
|
|
1243
|
+
}
|
|
1244
|
+
/**
|
|
1245
|
+
* Checks if an object is a proxy created by {@link reactive},
|
|
1246
|
+
* {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
|
|
1247
|
+
*
|
|
1248
|
+
* @param value - The value to check.
|
|
1249
|
+
* @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
|
|
1250
|
+
*/
|
|
1251
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1252
|
+
function isProxy(value) {
|
|
1253
|
+
return value ? !!value["__v_raw"] : false;
|
|
1254
|
+
}
|
|
1255
|
+
/**
|
|
1256
|
+
* Returns the raw, original object of a Vue-created proxy.
|
|
1257
|
+
*
|
|
1258
|
+
* `toRaw()` can return the original object from proxies created by
|
|
1259
|
+
* {@link reactive}, {@link readonly}, {@link shallowReactive} or
|
|
1260
|
+
* {@link shallowReadonly}.
|
|
1261
|
+
*
|
|
1262
|
+
* This is an escape hatch that can be used to temporarily read without
|
|
1263
|
+
* incurring proxy access / tracking overhead or write without triggering
|
|
1264
|
+
* changes. It is **not** recommended to hold a persistent reference to the
|
|
1265
|
+
* original object. Use with caution.
|
|
1266
|
+
*
|
|
1267
|
+
* @example
|
|
1268
|
+
* ```js
|
|
1269
|
+
* const foo = {}
|
|
1270
|
+
* const reactiveFoo = reactive(foo)
|
|
1271
|
+
*
|
|
1272
|
+
* console.log(toRaw(reactiveFoo) === foo) // true
|
|
1273
|
+
* ```
|
|
1274
|
+
*
|
|
1275
|
+
* @param observed - The object for which the "raw" value is requested.
|
|
1276
|
+
* @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
|
|
1277
|
+
*/
|
|
1278
|
+
/*@__NO_SIDE_EFFECTS__*/
|
|
1279
|
+
function toRaw(observed) {
|
|
1280
|
+
const raw = observed && observed["__v_raw"];
|
|
1281
|
+
return raw ? /* @__PURE__ */ toRaw(raw) : observed;
|
|
1282
|
+
}
|
|
1283
|
+
/**
|
|
1284
|
+
* Returns a reactive proxy of the given value (if possible).
|
|
1285
|
+
*
|
|
1286
|
+
* If the given value is not an object, the original value itself is returned.
|
|
1287
|
+
*
|
|
1288
|
+
* @param value - The value for which a reactive proxy shall be created.
|
|
1289
|
+
*/
|
|
1290
|
+
const toReactive = (value) => isObject(value) ? /* @__PURE__ */ reactive(value) : value;
|
|
1291
|
+
/**
|
|
1292
|
+
* Returns a readonly proxy of the given value (if possible).
|
|
1293
|
+
*
|
|
1294
|
+
* If the given value is not an object, the original value itself is returned.
|
|
1295
|
+
*
|
|
1296
|
+
* @param value - The value for which a readonly proxy shall be created.
|
|
1297
|
+
*/
|
|
1298
|
+
const toReadonly = (value) => isObject(value) ? /* @__PURE__ */ readonly(value) : value;
|
|
1299
|
+
//#endregion
|
|
1300
|
+
//#region packages/core/signal/src/state.ts
|
|
1301
|
+
function state(value) {
|
|
1302
|
+
if (arguments.length === 0) return /* @__PURE__ */ ref();
|
|
1303
|
+
return isProxyable(value) ? /* @__PURE__ */ reactive(value) : /* @__PURE__ */ ref(value);
|
|
1304
|
+
}
|
|
1305
|
+
function isProxyable(value) {
|
|
1306
|
+
if (value === null || typeof value !== "object") return false;
|
|
1307
|
+
if (Array.isArray(value)) return true;
|
|
1308
|
+
if (value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet) return true;
|
|
1309
|
+
return isPlainObject(value);
|
|
1310
|
+
}
|
|
1311
|
+
function isPlainObject(value) {
|
|
1312
|
+
const proto = Object.getPrototypeOf(value);
|
|
1313
|
+
return proto === Object.prototype || proto === null;
|
|
1314
|
+
}
|
|
1315
|
+
//#endregion
|
|
1316
|
+
//#region packages/core/runtime-dom/src/domOwnership.ts
|
|
1317
|
+
const activeLightDomHosts = /* @__PURE__ */ new WeakMap();
|
|
1318
|
+
const runtimeOwnedNodes = /* @__PURE__ */ new WeakSet();
|
|
1319
|
+
function registerLightDomHost(host, lightChildren) {
|
|
1320
|
+
const ownership = { lightChildren };
|
|
1321
|
+
activeLightDomHosts.set(host, ownership);
|
|
1322
|
+
return () => {
|
|
1323
|
+
if (activeLightDomHosts.get(host) === ownership) activeLightDomHosts.delete(host);
|
|
1324
|
+
};
|
|
1325
|
+
}
|
|
1326
|
+
function trackRuntimeDomInsertion(parent, node) {
|
|
1327
|
+
const ownership = activeLightDomHosts.get(parent);
|
|
1328
|
+
if (!ownership) return;
|
|
1329
|
+
if (node.nodeType === 11) {
|
|
1330
|
+
for (const child of node.childNodes) trackRuntimeNode(ownership, child);
|
|
1331
|
+
return;
|
|
1332
|
+
}
|
|
1333
|
+
trackRuntimeNode(ownership, node);
|
|
1334
|
+
}
|
|
1335
|
+
function isRuntimeOwnedNode(node) {
|
|
1336
|
+
return runtimeOwnedNodes.has(node);
|
|
1337
|
+
}
|
|
1338
|
+
function trackRuntimeNode(ownership, node) {
|
|
1339
|
+
if (!ownership.lightChildren.includes(node)) runtimeOwnedNodes.add(node);
|
|
1340
|
+
}
|
|
1341
|
+
//#endregion
|
|
1342
|
+
//#region packages/core/runtime-dom/src/range.ts
|
|
1343
|
+
function insertTracked(parent, value, marker = null) {
|
|
1344
|
+
if (value === void 0 || value == null || value === false || value === true) return [];
|
|
1345
|
+
if (Array.isArray(value)) {
|
|
1346
|
+
const nodes = [];
|
|
1347
|
+
for (const item of value) nodes.push(...insertTracked(parent, item, marker));
|
|
1348
|
+
return nodes;
|
|
1349
|
+
}
|
|
1350
|
+
const node = value instanceof Node ? value : document.createTextNode(String(value));
|
|
1351
|
+
trackRuntimeDomInsertion(parent, node);
|
|
1352
|
+
parent.insertBefore(node, marker);
|
|
1353
|
+
return [node];
|
|
1354
|
+
}
|
|
1355
|
+
function removeNodes$1(nodes) {
|
|
1356
|
+
for (const node of nodes) {
|
|
1357
|
+
var _node$parentNode2;
|
|
1358
|
+
(_node$parentNode2 = node.parentNode) === null || _node$parentNode2 === void 0 || _node$parentNode2.removeChild(node);
|
|
1359
|
+
}
|
|
1360
|
+
}
|
|
1361
|
+
function moveRangeBefore(nodes, parent, marker = null) {
|
|
1362
|
+
for (const node of nodes) {
|
|
1363
|
+
trackRuntimeDomInsertion(parent, node);
|
|
1364
|
+
parent.insertBefore(node, marker);
|
|
1365
|
+
}
|
|
1366
|
+
}
|
|
1367
|
+
//#endregion
|
|
20
1368
|
//#region packages/core/runtime-dom/src/hostContext.ts
|
|
21
1369
|
let currentHostContext;
|
|
22
1370
|
function getCurrentHostContext() {
|
|
@@ -41,48 +1389,50 @@ function withCapturedHostContext(fn) {
|
|
|
41
1389
|
});
|
|
42
1390
|
}
|
|
43
1391
|
//#endregion
|
|
44
|
-
//#region packages/core/runtime-dom/src/
|
|
45
|
-
|
|
46
|
-
|
|
1392
|
+
//#region packages/core/runtime-dom/src/scopedSubtree.ts
|
|
1393
|
+
function captureScopedSubtreeContext() {
|
|
1394
|
+
return {
|
|
1395
|
+
owner: getCurrentOwner(),
|
|
1396
|
+
host: captureCurrentHostContext()
|
|
1397
|
+
};
|
|
1398
|
+
}
|
|
1399
|
+
var ScopedSubtree = class {
|
|
1400
|
+
constructor(parent, marker, context) {
|
|
47
1401
|
this.parent = parent;
|
|
48
1402
|
this.marker = marker;
|
|
1403
|
+
this.context = context;
|
|
49
1404
|
this.nodes = [];
|
|
50
1405
|
}
|
|
51
|
-
replace(
|
|
52
|
-
this.
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
1406
|
+
replace(render) {
|
|
1407
|
+
this.dispose();
|
|
1408
|
+
const scope = effectScope(true);
|
|
1409
|
+
let nodes = [];
|
|
1410
|
+
try {
|
|
1411
|
+
scope.run(() => {
|
|
1412
|
+
nodes = runWithOwner(this.context.owner, () => withHostContext(this.context.host, () => insertTracked(this.parent, render(), this.marker)));
|
|
1413
|
+
});
|
|
1414
|
+
} catch (error) {
|
|
1415
|
+
scope.stop();
|
|
1416
|
+
removeNodes$1(nodes);
|
|
1417
|
+
throw error;
|
|
59
1418
|
}
|
|
1419
|
+
this.scope = scope;
|
|
1420
|
+
this.nodes = nodes;
|
|
1421
|
+
}
|
|
1422
|
+
dispose() {
|
|
1423
|
+
var _this$scope;
|
|
1424
|
+
(_this$scope = this.scope) === null || _this$scope === void 0 || _this$scope.stop();
|
|
1425
|
+
this.scope = void 0;
|
|
1426
|
+
removeNodes$1(this.nodes);
|
|
60
1427
|
this.nodes = [];
|
|
61
1428
|
}
|
|
1429
|
+
moveBefore(marker) {
|
|
1430
|
+
moveRangeBefore(this.nodes, this.parent, marker);
|
|
1431
|
+
}
|
|
62
1432
|
current() {
|
|
63
1433
|
return this.nodes;
|
|
64
1434
|
}
|
|
65
1435
|
};
|
|
66
|
-
function insertTracked(parent, value, marker = null) {
|
|
67
|
-
if (value === void 0 || value == null || value === false || value === true) return [];
|
|
68
|
-
if (Array.isArray(value)) {
|
|
69
|
-
const nodes = [];
|
|
70
|
-
for (const item of value) nodes.push(...insertTracked(parent, item, marker));
|
|
71
|
-
return nodes;
|
|
72
|
-
}
|
|
73
|
-
const node = value instanceof Node ? value : document.createTextNode(String(value));
|
|
74
|
-
parent.insertBefore(node, marker);
|
|
75
|
-
return [node];
|
|
76
|
-
}
|
|
77
|
-
function removeNodes$1(nodes) {
|
|
78
|
-
for (const node of nodes) {
|
|
79
|
-
var _node$parentNode2;
|
|
80
|
-
(_node$parentNode2 = node.parentNode) === null || _node$parentNode2 === void 0 || _node$parentNode2.removeChild(node);
|
|
81
|
-
}
|
|
82
|
-
}
|
|
83
|
-
function moveRangeBefore(nodes, parent, marker = null) {
|
|
84
|
-
for (const node of nodes) parent.insertBefore(node, marker);
|
|
85
|
-
}
|
|
86
1436
|
//#endregion
|
|
87
1437
|
//#region packages/core/runtime-dom/src/insert.ts
|
|
88
1438
|
function insert(parent, value, marker = null) {
|
|
@@ -90,16 +1440,13 @@ function insert(parent, value, marker = null) {
|
|
|
90
1440
|
insertTracked(parent, value, marker);
|
|
91
1441
|
}
|
|
92
1442
|
function mountDynamic(parent, marker, value) {
|
|
93
|
-
const
|
|
94
|
-
const
|
|
95
|
-
|
|
96
|
-
const runner = (0, _zeus_js_signal.effect)(() => {
|
|
97
|
-
const next = runWithOwner(owner, () => withHostContext(hostContext, value));
|
|
98
|
-
range.replace(next);
|
|
1443
|
+
const subtree = new ScopedSubtree(parent, marker, captureScopedSubtreeContext());
|
|
1444
|
+
const runner = effect(() => {
|
|
1445
|
+
subtree.replace(value);
|
|
99
1446
|
});
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
1447
|
+
onScopeDispose(() => {
|
|
1448
|
+
stop(runner);
|
|
1449
|
+
subtree.dispose();
|
|
103
1450
|
}, true);
|
|
104
1451
|
}
|
|
105
1452
|
//#endregion
|
|
@@ -189,7 +1536,7 @@ function provideDOMContext(target, context, value) {
|
|
|
189
1536
|
request.detail.resolve(value);
|
|
190
1537
|
};
|
|
191
1538
|
target.addEventListener(ZEUS_CONTEXT_REQUEST, handler);
|
|
192
|
-
|
|
1539
|
+
onScopeDispose(() => {
|
|
193
1540
|
target.removeEventListener(ZEUS_CONTEXT_REQUEST, handler);
|
|
194
1541
|
}, true);
|
|
195
1542
|
}
|
|
@@ -239,7 +1586,7 @@ function emitDevtoolsEvent(event) {
|
|
|
239
1586
|
//#region packages/core/runtime-dom/src/render.ts
|
|
240
1587
|
function render(value, container, options = {}) {
|
|
241
1588
|
var _options$owner;
|
|
242
|
-
const renderScope = (
|
|
1589
|
+
const renderScope = effectScope();
|
|
243
1590
|
const owner = (_options$owner = options.owner) !== null && _options$owner !== void 0 ? _options$owner : createOwner();
|
|
244
1591
|
renderScope.run(() => {
|
|
245
1592
|
container.textContent = "";
|
|
@@ -289,12 +1636,12 @@ function removeNodes(nodes) {
|
|
|
289
1636
|
//#endregion
|
|
290
1637
|
//#region packages/core/runtime-dom/src/bindings.ts
|
|
291
1638
|
function bindText(node, value) {
|
|
292
|
-
|
|
1639
|
+
effect(() => {
|
|
293
1640
|
node.data = stringifyText(value());
|
|
294
1641
|
});
|
|
295
1642
|
}
|
|
296
1643
|
function bindTextContent(el, value) {
|
|
297
|
-
|
|
1644
|
+
effect(() => {
|
|
298
1645
|
el.textContent = stringifyText(value());
|
|
299
1646
|
});
|
|
300
1647
|
}
|
|
@@ -349,17 +1696,17 @@ function normalizeAttrName(name) {
|
|
|
349
1696
|
return name === "className" ? "class" : name;
|
|
350
1697
|
}
|
|
351
1698
|
function bindAttr(el, name, value) {
|
|
352
|
-
|
|
1699
|
+
effect(() => {
|
|
353
1700
|
setAttr(el, name, value());
|
|
354
1701
|
});
|
|
355
1702
|
}
|
|
356
1703
|
function bindProp(el, name, value) {
|
|
357
|
-
|
|
1704
|
+
effect(() => {
|
|
358
1705
|
el[name] = value();
|
|
359
1706
|
});
|
|
360
1707
|
}
|
|
361
1708
|
function bindClass(el, value) {
|
|
362
|
-
|
|
1709
|
+
effect(() => {
|
|
363
1710
|
const next = normalizeClass(value());
|
|
364
1711
|
if (next) el.setAttribute("class", next);
|
|
365
1712
|
else el.removeAttribute("class");
|
|
@@ -374,7 +1721,7 @@ function normalizeClass(value) {
|
|
|
374
1721
|
}
|
|
375
1722
|
function bindStyle(el, value) {
|
|
376
1723
|
let prev;
|
|
377
|
-
|
|
1724
|
+
effect(() => {
|
|
378
1725
|
const next = value();
|
|
379
1726
|
if (next == null) {
|
|
380
1727
|
el.removeAttribute("style");
|
|
@@ -393,11 +1740,11 @@ function bindStyle(el, value) {
|
|
|
393
1740
|
function patchStyle(el, prev, next) {
|
|
394
1741
|
const style = el.style;
|
|
395
1742
|
if (prev) {
|
|
396
|
-
for (const key in prev) if (!(key in next)) style.setProperty(toKebabCase$
|
|
1743
|
+
for (const key in prev) if (!(key in next)) style.setProperty(toKebabCase$2(key), "");
|
|
397
1744
|
}
|
|
398
1745
|
for (const key in next) {
|
|
399
1746
|
const value = next[key];
|
|
400
|
-
const name = toKebabCase$
|
|
1747
|
+
const name = toKebabCase$2(key);
|
|
401
1748
|
if (value == null) style.setProperty(name, "");
|
|
402
1749
|
else style.setProperty(name, normalizeStyleValue(key, value));
|
|
403
1750
|
}
|
|
@@ -419,7 +1766,7 @@ const unitlessNumbers = /* @__PURE__ */ new Set([
|
|
|
419
1766
|
function isUnitlessNumber(key) {
|
|
420
1767
|
return unitlessNumbers.has(key);
|
|
421
1768
|
}
|
|
422
|
-
function toKebabCase$
|
|
1769
|
+
function toKebabCase$2(value) {
|
|
423
1770
|
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
424
1771
|
}
|
|
425
1772
|
//#endregion
|
|
@@ -434,7 +1781,7 @@ function bindEvent(el, name, handler) {
|
|
|
434
1781
|
const target = el;
|
|
435
1782
|
const events = target.__zeusEvents || (target.__zeusEvents = {});
|
|
436
1783
|
events[name] = handler;
|
|
437
|
-
|
|
1784
|
+
onScopeDispose(() => {
|
|
438
1785
|
var _target$__zeusEvents;
|
|
439
1786
|
if (((_target$__zeusEvents = target.__zeusEvents) === null || _target$__zeusEvents === void 0 ? void 0 : _target$__zeusEvents[name]) === handler) delete target.__zeusEvents[name];
|
|
440
1787
|
}, true);
|
|
@@ -516,7 +1863,7 @@ function setRef(target, value) {
|
|
|
516
1863
|
}
|
|
517
1864
|
function bindRef(el, target) {
|
|
518
1865
|
setRef(target, el);
|
|
519
|
-
if (
|
|
1866
|
+
if (getCurrentScope()) onScopeDispose(() => {
|
|
520
1867
|
setRef(target, null);
|
|
521
1868
|
}, true);
|
|
522
1869
|
}
|
|
@@ -527,6 +1874,9 @@ function createComponent(component, props) {
|
|
|
527
1874
|
}
|
|
528
1875
|
//#endregion
|
|
529
1876
|
//#region packages/core/runtime-dom/src/list.ts
|
|
1877
|
+
function disposeListRecord(record) {
|
|
1878
|
+
record.subtree.dispose();
|
|
1879
|
+
}
|
|
530
1880
|
function mountFor$1(parent, marker, each, key, render) {
|
|
531
1881
|
if (!key) {
|
|
532
1882
|
mountIndexFor(parent, marker, each, render);
|
|
@@ -535,25 +1885,21 @@ function mountFor$1(parent, marker, each, key, render) {
|
|
|
535
1885
|
mountKeyedFor(parent, marker, each, key, render);
|
|
536
1886
|
}
|
|
537
1887
|
function mountIndexFor(parent, marker, each, render) {
|
|
538
|
-
|
|
539
|
-
const
|
|
540
|
-
const runner = (0, _zeus_js_signal.effect)(() => {
|
|
1888
|
+
const subtree = new ScopedSubtree(parent, marker, captureScopedSubtreeContext());
|
|
1889
|
+
const runner = effect(() => {
|
|
541
1890
|
var _each;
|
|
542
|
-
removeNodes$1(current);
|
|
543
|
-
current = [];
|
|
544
1891
|
const list = (_each = each()) !== null && _each !== void 0 ? _each : [];
|
|
545
|
-
|
|
1892
|
+
subtree.replace(() => list.map((item, index) => render(item, index)));
|
|
546
1893
|
});
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
current = [];
|
|
1894
|
+
onScopeDispose(() => {
|
|
1895
|
+
stop(runner);
|
|
1896
|
+
subtree.dispose();
|
|
551
1897
|
}, true);
|
|
552
1898
|
}
|
|
553
1899
|
function mountKeyedFor(parent, marker, each, key, render) {
|
|
554
1900
|
let records = [];
|
|
555
|
-
const
|
|
556
|
-
const runner =
|
|
1901
|
+
const subtreeContext = captureScopedSubtreeContext();
|
|
1902
|
+
const runner = effect(() => {
|
|
557
1903
|
var _each2;
|
|
558
1904
|
const nextItems = (_each2 = each()) !== null && _each2 !== void 0 ? _each2 : [];
|
|
559
1905
|
const oldMap = /* @__PURE__ */ new Map();
|
|
@@ -568,19 +1914,23 @@ function mountKeyedFor(parent, marker, each, key, render) {
|
|
|
568
1914
|
oldRecord.item = item;
|
|
569
1915
|
oldRecord.index = i;
|
|
570
1916
|
nextRecords.push(oldRecord);
|
|
571
|
-
} else
|
|
572
|
-
|
|
573
|
-
item,
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
1917
|
+
} else {
|
|
1918
|
+
const subtree = new ScopedSubtree(parent, marker, subtreeContext);
|
|
1919
|
+
subtree.replace(() => render(item, i));
|
|
1920
|
+
nextRecords.push({
|
|
1921
|
+
key: itemKey,
|
|
1922
|
+
item,
|
|
1923
|
+
index: i,
|
|
1924
|
+
subtree
|
|
1925
|
+
});
|
|
1926
|
+
}
|
|
577
1927
|
}
|
|
578
|
-
for (const record of oldMap.values())
|
|
1928
|
+
for (const record of oldMap.values()) disposeListRecord(record);
|
|
579
1929
|
for (let i = nextRecords.length - 1; i >= 0; i--) {
|
|
580
|
-
var _nextRecords$
|
|
1930
|
+
var _nextRecords$subtree$;
|
|
581
1931
|
const record = nextRecords[i];
|
|
582
|
-
const anchor = i === nextRecords.length - 1 ? marker : (_nextRecords$
|
|
583
|
-
|
|
1932
|
+
const anchor = i === nextRecords.length - 1 ? marker : (_nextRecords$subtree$ = nextRecords[i + 1].subtree.current()[0]) !== null && _nextRecords$subtree$ !== void 0 ? _nextRecords$subtree$ : marker;
|
|
1933
|
+
record.subtree.moveBefore(anchor);
|
|
584
1934
|
}
|
|
585
1935
|
emitDevtoolsEvent({
|
|
586
1936
|
type: "mount-for",
|
|
@@ -588,9 +1938,9 @@ function mountKeyedFor(parent, marker, each, key, render) {
|
|
|
588
1938
|
});
|
|
589
1939
|
records = nextRecords;
|
|
590
1940
|
});
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
for (const record of records)
|
|
1941
|
+
onScopeDispose(() => {
|
|
1942
|
+
stop(runner);
|
|
1943
|
+
for (const record of records) disposeListRecord(record);
|
|
594
1944
|
records = [];
|
|
595
1945
|
}, true);
|
|
596
1946
|
}
|
|
@@ -614,6 +1964,253 @@ function mountFor(parent, marker, each, key, render) {
|
|
|
614
1964
|
mountFor$1(parent, marker, each, key, render);
|
|
615
1965
|
}
|
|
616
1966
|
//#endregion
|
|
1967
|
+
//#region packages/core/runtime-dom/src/customElementContract.ts
|
|
1968
|
+
function getCustomElementAttributeName(prop) {
|
|
1969
|
+
var _prop$attrName;
|
|
1970
|
+
if (prop.attrName === false) return void 0;
|
|
1971
|
+
if (!isAttributeBackedType(prop.type) && !prop.deserialize) return;
|
|
1972
|
+
return normalizeAttributeName((_prop$attrName = prop.attrName) !== null && _prop$attrName !== void 0 ? _prop$attrName : toKebabCase$1(prop.name));
|
|
1973
|
+
}
|
|
1974
|
+
function getCustomElementObservedAttributes(props) {
|
|
1975
|
+
const attributes = /* @__PURE__ */ new Set();
|
|
1976
|
+
for (const prop of props) {
|
|
1977
|
+
const attrName = getCustomElementAttributeName(prop);
|
|
1978
|
+
if (attrName) attributes.add(attrName);
|
|
1979
|
+
}
|
|
1980
|
+
return Array.from(attributes);
|
|
1981
|
+
}
|
|
1982
|
+
function findCustomElementPropByAttribute(props, attrName) {
|
|
1983
|
+
const normalizedName = normalizeAttributeName(attrName);
|
|
1984
|
+
return props.find((prop) => {
|
|
1985
|
+
return getCustomElementAttributeName(prop) === normalizedName;
|
|
1986
|
+
});
|
|
1987
|
+
}
|
|
1988
|
+
function coerceCustomElementAttribute(prop, value) {
|
|
1989
|
+
if (typeof prop.deserialize === "function") return prop.deserialize(value);
|
|
1990
|
+
if (prop.deserialize === true) return value;
|
|
1991
|
+
switch (prop.type) {
|
|
1992
|
+
case "boolean": return value !== null;
|
|
1993
|
+
case "number": return value === null ? void 0 : Number(value);
|
|
1994
|
+
case "string": return value !== null && value !== void 0 ? value : void 0;
|
|
1995
|
+
case "object":
|
|
1996
|
+
case "array": return coerceStructuredAttribute(prop, value);
|
|
1997
|
+
case "function": return;
|
|
1998
|
+
default: return value;
|
|
1999
|
+
}
|
|
2000
|
+
}
|
|
2001
|
+
function reflectCustomElementProperty(element, prop, value, reflectingAttrs) {
|
|
2002
|
+
const attrName = getCustomElementAttributeName(prop);
|
|
2003
|
+
if (!attrName || prop.serialize === true) return;
|
|
2004
|
+
reflectingAttrs === null || reflectingAttrs === void 0 || reflectingAttrs.add(attrName);
|
|
2005
|
+
try {
|
|
2006
|
+
const serialized = serializeCustomElementProperty(prop, value);
|
|
2007
|
+
if (serialized == null) element.removeAttribute(attrName);
|
|
2008
|
+
else element.setAttribute(attrName, serialized);
|
|
2009
|
+
} finally {
|
|
2010
|
+
reflectingAttrs === null || reflectingAttrs === void 0 || reflectingAttrs.delete(attrName);
|
|
2011
|
+
}
|
|
2012
|
+
}
|
|
2013
|
+
function createCustomElementMountLifecycle(mount) {
|
|
2014
|
+
let mounted;
|
|
2015
|
+
return {
|
|
2016
|
+
connect() {
|
|
2017
|
+
var _mounted;
|
|
2018
|
+
(_mounted = mounted) !== null && _mounted !== void 0 || (mounted = mount());
|
|
2019
|
+
return mounted;
|
|
2020
|
+
},
|
|
2021
|
+
disconnect() {
|
|
2022
|
+
const current = mounted;
|
|
2023
|
+
mounted = void 0;
|
|
2024
|
+
current === null || current === void 0 || current.dispose();
|
|
2025
|
+
},
|
|
2026
|
+
current() {
|
|
2027
|
+
return mounted;
|
|
2028
|
+
}
|
|
2029
|
+
};
|
|
2030
|
+
}
|
|
2031
|
+
function serializeCustomElementProperty(prop, value) {
|
|
2032
|
+
if (typeof prop.serialize === "function") return prop.serialize(value);
|
|
2033
|
+
if (prop.type === "boolean") return value ? "" : null;
|
|
2034
|
+
if (value == null) return null;
|
|
2035
|
+
if (prop.type === "object" || prop.type === "array") return JSON.stringify(value);
|
|
2036
|
+
if (prop.type === "function") return void 0;
|
|
2037
|
+
return String(value);
|
|
2038
|
+
}
|
|
2039
|
+
function coerceStructuredAttribute(prop, value) {
|
|
2040
|
+
if (value === null) return void 0;
|
|
2041
|
+
try {
|
|
2042
|
+
return JSON.parse(value);
|
|
2043
|
+
} catch {
|
|
2044
|
+
return prop.type === "array" ? [] : {};
|
|
2045
|
+
}
|
|
2046
|
+
}
|
|
2047
|
+
function isAttributeBackedType(type) {
|
|
2048
|
+
return type === "string" || type === "number" || type === "boolean";
|
|
2049
|
+
}
|
|
2050
|
+
function normalizeAttributeName(value) {
|
|
2051
|
+
return value.toLowerCase();
|
|
2052
|
+
}
|
|
2053
|
+
function toKebabCase$1(value) {
|
|
2054
|
+
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
2055
|
+
}
|
|
2056
|
+
//#endregion
|
|
2057
|
+
//#region packages/core/runtime-dom/src/slot.ts
|
|
2058
|
+
function createSlot(name, fallback) {
|
|
2059
|
+
const context = getCurrentHostContext();
|
|
2060
|
+
if (!context) return createNativeSlot(name, fallback);
|
|
2061
|
+
if (context.mode === "shadow") return createNativeSlot(name, fallback);
|
|
2062
|
+
if (context.projection) return context.projection.createSlot(name, fallback);
|
|
2063
|
+
const assigned = findLightSlotNodes(context.lightChildren, name);
|
|
2064
|
+
if (assigned.length > 0) return Array.from(assigned);
|
|
2065
|
+
return fallback ? fallback() : null;
|
|
2066
|
+
}
|
|
2067
|
+
function createLightDomProjection(host, lightChildren) {
|
|
2068
|
+
const outlets = [];
|
|
2069
|
+
let observer;
|
|
2070
|
+
let unregisterHost;
|
|
2071
|
+
const observe = () => {
|
|
2072
|
+
observer === null || observer === void 0 || observer.observe(host, {
|
|
2073
|
+
attributes: true,
|
|
2074
|
+
attributeFilter: ["slot"],
|
|
2075
|
+
childList: true,
|
|
2076
|
+
subtree: true
|
|
2077
|
+
});
|
|
2078
|
+
for (const node of lightChildren) {
|
|
2079
|
+
if (node.nodeType !== Node.ELEMENT_NODE || host.contains(node)) continue;
|
|
2080
|
+
observer === null || observer === void 0 || observer.observe(node, {
|
|
2081
|
+
attributes: true,
|
|
2082
|
+
attributeFilter: ["slot"]
|
|
2083
|
+
});
|
|
2084
|
+
}
|
|
2085
|
+
};
|
|
2086
|
+
const reconcile = () => {
|
|
2087
|
+
observer === null || observer === void 0 || observer.disconnect();
|
|
2088
|
+
const claimed = /* @__PURE__ */ new Set();
|
|
2089
|
+
for (const outlet of outlets) {
|
|
2090
|
+
const assigned = lightChildren.filter((node) => {
|
|
2091
|
+
if (claimed.has(node) || !matchesLightSlot(node, outlet.name)) return false;
|
|
2092
|
+
claimed.add(node);
|
|
2093
|
+
return true;
|
|
2094
|
+
});
|
|
2095
|
+
replaceOutletNodes(outlet, assigned.length > 0 ? assigned : outlet.fallbackNodes);
|
|
2096
|
+
}
|
|
2097
|
+
for (const node of lightChildren) if (!claimed.has(node) && host.contains(node)) {
|
|
2098
|
+
var _node$parentNode;
|
|
2099
|
+
(_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 || _node$parentNode.removeChild(node);
|
|
2100
|
+
}
|
|
2101
|
+
observer === null || observer === void 0 || observer.takeRecords();
|
|
2102
|
+
observe();
|
|
2103
|
+
};
|
|
2104
|
+
const handleMutations = (records) => {
|
|
2105
|
+
const added = /* @__PURE__ */ new Set();
|
|
2106
|
+
const removed = /* @__PURE__ */ new Set();
|
|
2107
|
+
let changed = false;
|
|
2108
|
+
for (const record of records) {
|
|
2109
|
+
if (record.type === "attributes") {
|
|
2110
|
+
if (lightChildren.includes(record.target)) changed = true;
|
|
2111
|
+
continue;
|
|
2112
|
+
}
|
|
2113
|
+
for (const node of record.removedNodes) if (lightChildren.includes(node)) removed.add(node);
|
|
2114
|
+
if (record.target !== host) continue;
|
|
2115
|
+
const additions = Array.from(record.addedNodes).filter((node) => {
|
|
2116
|
+
return !isRuntimeOwnedNode(node);
|
|
2117
|
+
});
|
|
2118
|
+
if (additions.length === 0) continue;
|
|
2119
|
+
for (const node of additions) added.add(node);
|
|
2120
|
+
insertLightChildren(lightChildren, additions, record);
|
|
2121
|
+
changed = true;
|
|
2122
|
+
}
|
|
2123
|
+
for (const node of removed) {
|
|
2124
|
+
if (added.has(node) || host.contains(node)) continue;
|
|
2125
|
+
const index = lightChildren.indexOf(node);
|
|
2126
|
+
if (index >= 0) {
|
|
2127
|
+
lightChildren.splice(index, 1);
|
|
2128
|
+
changed = true;
|
|
2129
|
+
}
|
|
2130
|
+
}
|
|
2131
|
+
if (changed) reconcile();
|
|
2132
|
+
};
|
|
2133
|
+
return {
|
|
2134
|
+
createSlot(name, fallback) {
|
|
2135
|
+
const fragment = document.createDocumentFragment();
|
|
2136
|
+
const start = document.createComment(name ? `zeus-slot:${name}` : "zeus-slot");
|
|
2137
|
+
const end = document.createComment("/zeus-slot");
|
|
2138
|
+
fragment.append(start, end);
|
|
2139
|
+
const outlet = {
|
|
2140
|
+
name,
|
|
2141
|
+
start,
|
|
2142
|
+
end,
|
|
2143
|
+
fallbackNodes: fallback ? insertTracked(fragment, fallback(), end) : []
|
|
2144
|
+
};
|
|
2145
|
+
outlets.push(outlet);
|
|
2146
|
+
reconcile();
|
|
2147
|
+
return fragment;
|
|
2148
|
+
},
|
|
2149
|
+
connect() {
|
|
2150
|
+
var _host$ownerDocument$d;
|
|
2151
|
+
if (observer) return;
|
|
2152
|
+
const Observer = (_host$ownerDocument$d = host.ownerDocument.defaultView) === null || _host$ownerDocument$d === void 0 ? void 0 : _host$ownerDocument$d.MutationObserver;
|
|
2153
|
+
if (!Observer) return;
|
|
2154
|
+
unregisterHost = registerLightDomHost(host, lightChildren);
|
|
2155
|
+
observer = new Observer(handleMutations);
|
|
2156
|
+
observe();
|
|
2157
|
+
},
|
|
2158
|
+
disconnect() {
|
|
2159
|
+
observer === null || observer === void 0 || observer.disconnect();
|
|
2160
|
+
observer = void 0;
|
|
2161
|
+
unregisterHost === null || unregisterHost === void 0 || unregisterHost();
|
|
2162
|
+
unregisterHost = void 0;
|
|
2163
|
+
}
|
|
2164
|
+
};
|
|
2165
|
+
}
|
|
2166
|
+
function replaceOutletNodes(outlet, nextNodes) {
|
|
2167
|
+
const parent = outlet.end.parentNode;
|
|
2168
|
+
if (!parent || parent !== outlet.start.parentNode) return;
|
|
2169
|
+
let current = outlet.start.nextSibling;
|
|
2170
|
+
while (current && current !== outlet.end) {
|
|
2171
|
+
const next = current.nextSibling;
|
|
2172
|
+
parent.removeChild(current);
|
|
2173
|
+
current = next;
|
|
2174
|
+
}
|
|
2175
|
+
for (const node of nextNodes) parent.insertBefore(node, outlet.end);
|
|
2176
|
+
}
|
|
2177
|
+
function insertLightChildren(lightChildren, additions, record) {
|
|
2178
|
+
for (const node of additions) {
|
|
2179
|
+
const currentIndex = lightChildren.indexOf(node);
|
|
2180
|
+
if (currentIndex >= 0) lightChildren.splice(currentIndex, 1);
|
|
2181
|
+
}
|
|
2182
|
+
let insertionIndex = lightChildren.length;
|
|
2183
|
+
const previousIndex = record.previousSibling ? lightChildren.indexOf(record.previousSibling) : -1;
|
|
2184
|
+
const nextIndex = record.nextSibling ? lightChildren.indexOf(record.nextSibling) : -1;
|
|
2185
|
+
if (previousIndex >= 0) insertionIndex = previousIndex + 1;
|
|
2186
|
+
else if (nextIndex >= 0) insertionIndex = nextIndex;
|
|
2187
|
+
else if (record.previousSibling === null) insertionIndex = 0;
|
|
2188
|
+
lightChildren.splice(insertionIndex, 0, ...additions);
|
|
2189
|
+
}
|
|
2190
|
+
function createNativeSlot(name, fallback) {
|
|
2191
|
+
const slot = document.createElement("slot");
|
|
2192
|
+
if (name) slot.setAttribute("name", name);
|
|
2193
|
+
const fallbackValue = fallback === null || fallback === void 0 ? void 0 : fallback();
|
|
2194
|
+
if (fallbackValue != null) insert(slot, fallbackValue);
|
|
2195
|
+
return slot;
|
|
2196
|
+
}
|
|
2197
|
+
function findLightSlotNodes(nodes, name) {
|
|
2198
|
+
return nodes.filter((node) => matchesLightSlot(node, name));
|
|
2199
|
+
}
|
|
2200
|
+
function matchesLightSlot(node, name) {
|
|
2201
|
+
if (name) {
|
|
2202
|
+
if (node.nodeType !== Node.ELEMENT_NODE) return false;
|
|
2203
|
+
return node.getAttribute("slot") === name;
|
|
2204
|
+
}
|
|
2205
|
+
if (node.nodeType === Node.ELEMENT_NODE) return !node.hasAttribute("slot");
|
|
2206
|
+
return isMeaningfulTextNode(node);
|
|
2207
|
+
}
|
|
2208
|
+
function isMeaningfulTextNode(node) {
|
|
2209
|
+
var _node$textContent;
|
|
2210
|
+
if (node.nodeType !== Node.TEXT_NODE) return false;
|
|
2211
|
+
return Boolean((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim());
|
|
2212
|
+
}
|
|
2213
|
+
//#endregion
|
|
617
2214
|
//#region packages/core/runtime-dom/src/defineElement.ts
|
|
618
2215
|
const ZEUS_ELEMENT_DEFINITION = Symbol.for("zeus.element.definition");
|
|
619
2216
|
function prop(input, options = {}) {
|
|
@@ -654,9 +2251,9 @@ function createPropStore(defs) {
|
|
|
654
2251
|
const slots = /* @__PURE__ */ new Map();
|
|
655
2252
|
const props = {};
|
|
656
2253
|
for (const def of defs) {
|
|
657
|
-
const slot =
|
|
658
|
-
slots.set(def.
|
|
659
|
-
Object.defineProperty(props, def.
|
|
2254
|
+
const slot = state();
|
|
2255
|
+
slots.set(def.name, slot);
|
|
2256
|
+
Object.defineProperty(props, def.name, {
|
|
660
2257
|
configurable: false,
|
|
661
2258
|
enumerable: true,
|
|
662
2259
|
get() {
|
|
@@ -692,7 +2289,7 @@ function defineElement(tagName, options, setup) {
|
|
|
692
2289
|
setup,
|
|
693
2290
|
propDefs
|
|
694
2291
|
};
|
|
695
|
-
const observedAttributes = propDefs
|
|
2292
|
+
const observedAttributes = getCustomElementObservedAttributes(propDefs);
|
|
696
2293
|
class ZeusElement extends HTMLElement {
|
|
697
2294
|
static get observedAttributes() {
|
|
698
2295
|
return observedAttributes;
|
|
@@ -701,7 +2298,8 @@ function defineElement(tagName, options, setup) {
|
|
|
701
2298
|
super();
|
|
702
2299
|
this.lightChildren = [];
|
|
703
2300
|
this.capturedLightChildren = false;
|
|
704
|
-
this.
|
|
2301
|
+
this.attributeProps = /* @__PURE__ */ new Set();
|
|
2302
|
+
this.reflectingAttrs = /* @__PURE__ */ new Set();
|
|
705
2303
|
this.propStore = createPropStore(propDefs);
|
|
706
2304
|
this.props = this.propStore.props;
|
|
707
2305
|
applyPropDefaults(this.propStore, propDefs);
|
|
@@ -713,17 +2311,23 @@ function defineElement(tagName, options, setup) {
|
|
|
713
2311
|
emit: createEmitApi(this, options.emits),
|
|
714
2312
|
expose: createExpose(this)
|
|
715
2313
|
};
|
|
2314
|
+
this.mountLifecycle = createCustomElementMountLifecycle(() => this.mountElement());
|
|
716
2315
|
}
|
|
717
2316
|
connectedCallback() {
|
|
2317
|
+
this.mountLifecycle.connect();
|
|
2318
|
+
}
|
|
2319
|
+
disconnectedCallback() {
|
|
2320
|
+
this.mountLifecycle.disconnect();
|
|
2321
|
+
}
|
|
2322
|
+
mountElement() {
|
|
718
2323
|
var _options$shadow, _options$consumes;
|
|
719
|
-
if (this.dispose) return;
|
|
720
2324
|
const shadow = (_options$shadow = options.shadow) !== null && _options$shadow !== void 0 ? _options$shadow : false;
|
|
721
2325
|
const mode = shadow ? "shadow" : "light";
|
|
722
2326
|
if (mode === "light" && !this.capturedLightChildren) {
|
|
723
2327
|
this.lightChildren = Array.from(this.childNodes);
|
|
724
2328
|
this.capturedLightChildren = true;
|
|
725
2329
|
}
|
|
726
|
-
this.
|
|
2330
|
+
const projection = mode === "light" ? createLightDomProjection(this, this.lightChildren) : void 0;
|
|
727
2331
|
const owner = createOwner();
|
|
728
2332
|
for (const context of (_options$consumes = options.consumes) !== null && _options$consumes !== void 0 ? _options$consumes : []) {
|
|
729
2333
|
const resolved = resolveDOMContext(this, context);
|
|
@@ -734,18 +2338,19 @@ function defineElement(tagName, options, setup) {
|
|
|
734
2338
|
const hostContext = {
|
|
735
2339
|
host: this,
|
|
736
2340
|
mode,
|
|
737
|
-
lightChildren: this.lightChildren
|
|
2341
|
+
lightChildren: this.lightChildren,
|
|
2342
|
+
projection
|
|
738
2343
|
};
|
|
739
|
-
|
|
2344
|
+
const dispose = render(() => runWithOwner(owner, () => withHostContext(hostContext, () => {
|
|
740
2345
|
syncFormValue(this.props, this.setupContext, options.form);
|
|
741
2346
|
return setup(this.props, this.setupContext);
|
|
742
2347
|
})), target, { owner });
|
|
743
2348
|
mountStyles(target, options.styles);
|
|
744
|
-
|
|
745
|
-
|
|
746
|
-
|
|
747
|
-
|
|
748
|
-
|
|
2349
|
+
projection === null || projection === void 0 || projection.connect();
|
|
2350
|
+
return { dispose() {
|
|
2351
|
+
projection === null || projection === void 0 || projection.disconnect();
|
|
2352
|
+
dispose();
|
|
2353
|
+
} };
|
|
749
2354
|
}
|
|
750
2355
|
formAssociatedCallback(form) {
|
|
751
2356
|
var _options$form, _options$form$associa;
|
|
@@ -764,10 +2369,11 @@ function defineElement(tagName, options, setup) {
|
|
|
764
2369
|
(_options$form4 = options.form) === null || _options$form4 === void 0 || (_options$form4$stateR = _options$form4.stateRestore) === null || _options$form4$stateR === void 0 || _options$form4$stateR.call(_options$form4, state, mode, this.props, this.setupContext);
|
|
765
2370
|
}
|
|
766
2371
|
attributeChangedCallback(name, oldValue, newValue) {
|
|
767
|
-
if (oldValue === newValue || this.
|
|
768
|
-
const def = propDefs.find((item) => item.
|
|
2372
|
+
if (oldValue === newValue || this.reflectingAttrs.has(name)) return;
|
|
2373
|
+
const def = propDefs.find((item) => item.attrName === name);
|
|
769
2374
|
if (!def) return;
|
|
770
|
-
this.
|
|
2375
|
+
this.attributeProps.add(def.name);
|
|
2376
|
+
this.propStore.set(def.name, coerceCustomElementAttribute(def, newValue));
|
|
771
2377
|
}
|
|
772
2378
|
resolveRenderTarget(shadow) {
|
|
773
2379
|
if (this.target) return this.target;
|
|
@@ -778,24 +2384,11 @@ function defineElement(tagName, options, setup) {
|
|
|
778
2384
|
this.target = this.attachShadow(typeof shadow === "object" ? shadow : { mode: "open" });
|
|
779
2385
|
return this.target;
|
|
780
2386
|
}
|
|
781
|
-
syncAttributesToProps(defs) {
|
|
782
|
-
for (const def of defs) {
|
|
783
|
-
if (def.attr === false) continue;
|
|
784
|
-
const value = this.getAttribute(def.attr);
|
|
785
|
-
if (value !== null || def.type === Boolean) this.propStore.set(def.key, castAttributeValue(value, def));
|
|
786
|
-
}
|
|
787
|
-
}
|
|
788
2387
|
_writePropFromProperty(key, value) {
|
|
789
|
-
const def = propDefs.find((item) => item.
|
|
2388
|
+
const def = propDefs.find((item) => item.name === key);
|
|
2389
|
+
this.attributeProps.delete(key);
|
|
790
2390
|
this.propStore.set(key, value);
|
|
791
|
-
if (
|
|
792
|
-
this.reflecting = true;
|
|
793
|
-
try {
|
|
794
|
-
reflectPropToAttribute(this, def, value);
|
|
795
|
-
} finally {
|
|
796
|
-
this.reflecting = false;
|
|
797
|
-
}
|
|
798
|
-
}
|
|
2391
|
+
if (def === null || def === void 0 ? void 0 : def.reflect) reflectCustomElementProperty(this, def, value, this.reflectingAttrs);
|
|
799
2392
|
}
|
|
800
2393
|
}
|
|
801
2394
|
ZeusElement.formAssociated = Boolean(options.formAssociated);
|
|
@@ -818,13 +2411,13 @@ function mountElementDefinition(ctor, host, initialValues = /* @__PURE__ */ new
|
|
|
818
2411
|
applyPropDefaults(propStore, propDefs);
|
|
819
2412
|
for (const def of propDefs) {
|
|
820
2413
|
var _mountState$attribute;
|
|
821
|
-
if (def.
|
|
822
|
-
propStore.set(def.
|
|
823
|
-
initialValues.set(def.
|
|
2414
|
+
if (def.attrName !== false && ((_mountState$attribute = mountState.attributeProps) === null || _mountState$attribute === void 0 ? void 0 : _mountState$attribute.has(def.name))) {
|
|
2415
|
+
propStore.set(def.name, coerceCustomElementAttribute(def, host.getAttribute(def.attrName)));
|
|
2416
|
+
initialValues.set(def.name, propStore.get(def.name));
|
|
824
2417
|
continue;
|
|
825
2418
|
}
|
|
826
|
-
if (initialValues.has(def.
|
|
827
|
-
propStore.set(def.
|
|
2419
|
+
if (initialValues.has(def.name)) {
|
|
2420
|
+
propStore.set(def.name, initialValues.get(def.name));
|
|
828
2421
|
continue;
|
|
829
2422
|
}
|
|
830
2423
|
/**
|
|
@@ -832,11 +2425,11 @@ function mountElementDefinition(ctor, host, initialValues = /* @__PURE__ */ new
|
|
|
832
2425
|
* back to the lazy host value map so that `element.propName` returns the
|
|
833
2426
|
* correct default value rather than undefined.
|
|
834
2427
|
*/
|
|
835
|
-
initialValues.set(def.
|
|
2428
|
+
initialValues.set(def.name, propStore.get(def.name));
|
|
836
2429
|
}
|
|
837
2430
|
for (const def of propDefs) {
|
|
838
2431
|
var _mountState$attribute2;
|
|
839
|
-
if (def.reflect && def.serialize && !((_mountState$attribute2 = mountState.attributeProps) === null || _mountState$attribute2 === void 0 ? void 0 : _mountState$attribute2.has(def.
|
|
2432
|
+
if (def.reflect && def.serialize && !((_mountState$attribute2 = mountState.attributeProps) === null || _mountState$attribute2 === void 0 ? void 0 : _mountState$attribute2.has(def.name))) reflectCustomElementProperty(host, def, propStore.get(def.name), mountState.reflectingAttrs);
|
|
840
2433
|
}
|
|
841
2434
|
const shadow = (_options$shadow2 = options.shadow) !== null && _options$shadow2 !== void 0 ? _options$shadow2 : false;
|
|
842
2435
|
const mode = shadow ? "shadow" : "light";
|
|
@@ -845,6 +2438,7 @@ function mountElementDefinition(ctor, host, initialValues = /* @__PURE__ */ new
|
|
|
845
2438
|
mountState.capturedLightChildren = true;
|
|
846
2439
|
}
|
|
847
2440
|
const lightChildren = (_mountState$lightChil = mountState.lightChildren) !== null && _mountState$lightChil !== void 0 ? _mountState$lightChil : [];
|
|
2441
|
+
const projection = mode === "light" ? createLightDomProjection(host, lightChildren) : void 0;
|
|
848
2442
|
const owner = createOwner();
|
|
849
2443
|
for (const context of (_options$consumes2 = options.consumes) !== null && _options$consumes2 !== void 0 ? _options$consumes2 : []) {
|
|
850
2444
|
const resolved = resolveDOMContext(host, context);
|
|
@@ -855,7 +2449,8 @@ function mountElementDefinition(ctor, host, initialValues = /* @__PURE__ */ new
|
|
|
855
2449
|
const hostContext = {
|
|
856
2450
|
host,
|
|
857
2451
|
mode,
|
|
858
|
-
lightChildren
|
|
2452
|
+
lightChildren,
|
|
2453
|
+
projection
|
|
859
2454
|
};
|
|
860
2455
|
const setupContext = {
|
|
861
2456
|
host,
|
|
@@ -869,15 +2464,16 @@ function mountElementDefinition(ctor, host, initialValues = /* @__PURE__ */ new
|
|
|
869
2464
|
return setup(propStore.props, setupContext);
|
|
870
2465
|
})), target, { owner });
|
|
871
2466
|
mountStyles(target, options.styles);
|
|
2467
|
+
projection === null || projection === void 0 || projection.connect();
|
|
872
2468
|
return {
|
|
873
2469
|
propertyChanged(name, _oldValue, newValue) {
|
|
874
2470
|
var _mountState$attribute3;
|
|
875
|
-
const def = propDefs.find((item) => item.
|
|
876
|
-
const fromAttribute = Boolean((def === null || def === void 0 ? void 0 : def.
|
|
877
|
-
const value = fromAttribute && def ?
|
|
2471
|
+
const def = propDefs.find((item) => item.name === name);
|
|
2472
|
+
const fromAttribute = Boolean((def === null || def === void 0 ? void 0 : def.attrName) !== false && ((_mountState$attribute3 = mountState.attributeProps) === null || _mountState$attribute3 === void 0 ? void 0 : _mountState$attribute3.has(name)));
|
|
2473
|
+
const value = fromAttribute && def ? coerceCustomElementAttribute(def, typeof newValue === "string" ? newValue : null) : newValue;
|
|
878
2474
|
propStore.set(name, value);
|
|
879
2475
|
initialValues.set(name, value);
|
|
880
|
-
if ((def === null || def === void 0 ? void 0 : def.reflect) && !fromAttribute)
|
|
2476
|
+
if ((def === null || def === void 0 ? void 0 : def.reflect) && !fromAttribute) reflectCustomElementProperty(host, def, value, mountState.reflectingAttrs);
|
|
881
2477
|
},
|
|
882
2478
|
formAssociated(form) {
|
|
883
2479
|
var _options$form5, _options$form5$associ;
|
|
@@ -896,6 +2492,7 @@ function mountElementDefinition(ctor, host, initialValues = /* @__PURE__ */ new
|
|
|
896
2492
|
(_options$form8 = options.form) === null || _options$form8 === void 0 || (_options$form8$stateR = _options$form8.stateRestore) === null || _options$form8$stateR === void 0 || _options$form8$stateR.call(_options$form8, state, mode, propStore.props, setupContext);
|
|
897
2493
|
},
|
|
898
2494
|
dispose() {
|
|
2495
|
+
projection === null || projection === void 0 || projection.disconnect();
|
|
899
2496
|
dispose();
|
|
900
2497
|
}
|
|
901
2498
|
};
|
|
@@ -907,18 +2504,18 @@ function normalizePropDefinitions(props) {
|
|
|
907
2504
|
if (typeof input === "function") {
|
|
908
2505
|
const type = input;
|
|
909
2506
|
return {
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
type,
|
|
2507
|
+
name: propKey,
|
|
2508
|
+
attrName: isAttributeBackedConstructor(type) ? toKebabCase(propKey) : false,
|
|
2509
|
+
type: normalizePropType(type),
|
|
913
2510
|
reflect: false
|
|
914
2511
|
};
|
|
915
2512
|
}
|
|
916
2513
|
const type = input === null || input === void 0 ? void 0 : input.type;
|
|
917
2514
|
const defaultAttr = isAttributeBackedConstructor(type) ? toKebabCase(propKey) : false;
|
|
918
2515
|
return {
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
type,
|
|
2516
|
+
name: propKey,
|
|
2517
|
+
attrName: (input === null || input === void 0 ? void 0 : input.attr) === void 0 ? defaultAttr : input.attr,
|
|
2518
|
+
type: normalizePropType(type),
|
|
922
2519
|
reflect: Boolean(input === null || input === void 0 ? void 0 : input.reflect),
|
|
923
2520
|
default: input === null || input === void 0 ? void 0 : input.default,
|
|
924
2521
|
serialize: input === null || input === void 0 ? void 0 : input.serialize,
|
|
@@ -930,12 +2527,12 @@ function applyPropDefaults(store, defs) {
|
|
|
930
2527
|
for (const def of defs) {
|
|
931
2528
|
if (!("default" in def)) continue;
|
|
932
2529
|
const value = typeof def.default === "function" ? def.default() : def.default;
|
|
933
|
-
store.set(def.
|
|
2530
|
+
store.set(def.name, value);
|
|
934
2531
|
}
|
|
935
2532
|
}
|
|
936
2533
|
function definePropAccessors(element, store, defs) {
|
|
937
2534
|
for (const def of defs) {
|
|
938
|
-
const key = def.
|
|
2535
|
+
const key = def.name;
|
|
939
2536
|
const hadOwnValue = Object.prototype.hasOwnProperty.call(element, key);
|
|
940
2537
|
const ownValue = hadOwnValue ? element[key] : void 0;
|
|
941
2538
|
if (hadOwnValue) delete element[key];
|
|
@@ -954,58 +2551,11 @@ function definePropAccessors(element, store, defs) {
|
|
|
954
2551
|
if (hadOwnValue) element._writePropFromProperty(key, ownValue);
|
|
955
2552
|
}
|
|
956
2553
|
}
|
|
957
|
-
function castAttributeValue(value, def) {
|
|
958
|
-
if (def.deserialize) return def.deserialize(value);
|
|
959
|
-
if (def.type === Boolean) return value !== null;
|
|
960
|
-
if (value === null) return;
|
|
961
|
-
if (def.type === Number) return Number(value);
|
|
962
|
-
if (def.type === Object || def.type === Array) try {
|
|
963
|
-
return JSON.parse(value);
|
|
964
|
-
} catch {
|
|
965
|
-
return def.type === Array ? [] : {};
|
|
966
|
-
}
|
|
967
|
-
if (def.type === Function) return;
|
|
968
|
-
return value;
|
|
969
|
-
}
|
|
970
|
-
function reflectPropToAttribute(element, def, value) {
|
|
971
|
-
if (def.attr === false) return;
|
|
972
|
-
if (def.serialize) {
|
|
973
|
-
const serialized = def.serialize(value);
|
|
974
|
-
if (serialized == null) element.removeAttribute(def.attr);
|
|
975
|
-
else element.setAttribute(def.attr, serialized);
|
|
976
|
-
return;
|
|
977
|
-
}
|
|
978
|
-
if (def.type === Boolean) {
|
|
979
|
-
if (value) element.setAttribute(def.attr, "");
|
|
980
|
-
else element.removeAttribute(def.attr);
|
|
981
|
-
return;
|
|
982
|
-
}
|
|
983
|
-
if (value == null) {
|
|
984
|
-
element.removeAttribute(def.attr);
|
|
985
|
-
return;
|
|
986
|
-
}
|
|
987
|
-
if (def.type === Object || def.type === Array) {
|
|
988
|
-
element.setAttribute(def.attr, JSON.stringify(value));
|
|
989
|
-
return;
|
|
990
|
-
}
|
|
991
|
-
if (def.type === Function) return;
|
|
992
|
-
element.setAttribute(def.attr, String(value));
|
|
993
|
-
}
|
|
994
|
-
function reflectExternalProp(element, def, value, reflectingAttrs) {
|
|
995
|
-
if (def.attr === false) return;
|
|
996
|
-
const attrName = def.attr.toLowerCase();
|
|
997
|
-
reflectingAttrs === null || reflectingAttrs === void 0 || reflectingAttrs.add(attrName);
|
|
998
|
-
try {
|
|
999
|
-
reflectPropToAttribute(element, def, value);
|
|
1000
|
-
} finally {
|
|
1001
|
-
reflectingAttrs === null || reflectingAttrs === void 0 || reflectingAttrs.delete(attrName);
|
|
1002
|
-
}
|
|
1003
|
-
}
|
|
1004
2554
|
function syncFormValue(props, context, form) {
|
|
1005
2555
|
const valueResolver = form === null || form === void 0 ? void 0 : form.value;
|
|
1006
2556
|
const stateResolver = form === null || form === void 0 ? void 0 : form.state;
|
|
1007
2557
|
if (!context.internals || valueResolver === void 0) return;
|
|
1008
|
-
|
|
2558
|
+
effect(() => {
|
|
1009
2559
|
const value = resolveFormValue(props, valueResolver);
|
|
1010
2560
|
const state = stateResolver === void 0 ? void 0 : resolveFormValue(props, stateResolver);
|
|
1011
2561
|
context.internals.setFormValue(value, state);
|
|
@@ -1061,6 +2611,15 @@ function createExpose(host) {
|
|
|
1061
2611
|
function isAttributeBackedConstructor(type) {
|
|
1062
2612
|
return type === String || type === Number || type === Boolean;
|
|
1063
2613
|
}
|
|
2614
|
+
function normalizePropType(type) {
|
|
2615
|
+
if (type === String) return "string";
|
|
2616
|
+
if (type === Number) return "number";
|
|
2617
|
+
if (type === Boolean) return "boolean";
|
|
2618
|
+
if (type === Object) return "object";
|
|
2619
|
+
if (type === Array) return "array";
|
|
2620
|
+
if (type === Function) return "function";
|
|
2621
|
+
return "unknown";
|
|
2622
|
+
}
|
|
1064
2623
|
function resolveExternalRenderTarget(host, shadow) {
|
|
1065
2624
|
var _host$shadowRoot;
|
|
1066
2625
|
if (!shadow) return host;
|
|
@@ -1079,38 +2638,6 @@ function toKebabCase(value) {
|
|
|
1079
2638
|
return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
|
|
1080
2639
|
}
|
|
1081
2640
|
//#endregion
|
|
1082
|
-
//#region packages/core/runtime-dom/src/slot.ts
|
|
1083
|
-
function createSlot(name, fallback) {
|
|
1084
|
-
const context = getCurrentHostContext();
|
|
1085
|
-
if (!context) return createNativeSlot(name, fallback);
|
|
1086
|
-
if (context.mode === "shadow") return createNativeSlot(name, fallback);
|
|
1087
|
-
const assigned = findLightSlotNodes(context.lightChildren, name);
|
|
1088
|
-
if (assigned.length > 0) return Array.from(assigned);
|
|
1089
|
-
return fallback ? fallback() : null;
|
|
1090
|
-
}
|
|
1091
|
-
function createNativeSlot(name, fallback) {
|
|
1092
|
-
const slot = document.createElement("slot");
|
|
1093
|
-
if (name) slot.setAttribute("name", name);
|
|
1094
|
-
const fallbackValue = fallback === null || fallback === void 0 ? void 0 : fallback();
|
|
1095
|
-
if (fallbackValue != null) insert(slot, fallbackValue);
|
|
1096
|
-
return slot;
|
|
1097
|
-
}
|
|
1098
|
-
function findLightSlotNodes(nodes, name) {
|
|
1099
|
-
if (name) return nodes.filter((node) => {
|
|
1100
|
-
if (node.nodeType !== Node.ELEMENT_NODE) return false;
|
|
1101
|
-
return node.getAttribute("slot") === name;
|
|
1102
|
-
});
|
|
1103
|
-
return nodes.filter((node) => {
|
|
1104
|
-
if (node.nodeType === Node.ELEMENT_NODE) return !node.hasAttribute("slot");
|
|
1105
|
-
return isMeaningfulTextNode(node);
|
|
1106
|
-
});
|
|
1107
|
-
}
|
|
1108
|
-
function isMeaningfulTextNode(node) {
|
|
1109
|
-
var _node$textContent;
|
|
1110
|
-
if (node.nodeType !== Node.TEXT_NODE) return false;
|
|
1111
|
-
return Boolean((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim());
|
|
1112
|
-
}
|
|
1113
|
-
//#endregion
|
|
1114
2641
|
//#region packages/core/runtime-dom/src/webComponents.ts
|
|
1115
2642
|
const HOST_RESERVED_KEYS = /* @__PURE__ */ new Set([
|
|
1116
2643
|
"children",
|
|
@@ -1218,16 +2745,21 @@ exports.bindText = bindText;
|
|
|
1218
2745
|
exports.bindTextContent = bindTextContent;
|
|
1219
2746
|
exports.captureCurrentHostContext = captureCurrentHostContext;
|
|
1220
2747
|
exports.child = child;
|
|
2748
|
+
exports.coerceCustomElementAttribute = coerceCustomElementAttribute;
|
|
1221
2749
|
exports.createComponent = createComponent;
|
|
1222
2750
|
exports.createContext = createContext;
|
|
2751
|
+
exports.createCustomElementMountLifecycle = createCustomElementMountLifecycle;
|
|
1223
2752
|
exports.createDOMContextBoundary = createDOMContextBoundary;
|
|
1224
2753
|
exports.createOwner = createOwner;
|
|
1225
2754
|
exports.createSlot = createSlot;
|
|
1226
2755
|
exports.defineElement = defineElement;
|
|
1227
2756
|
exports.delegateEvents = delegateEvents;
|
|
1228
2757
|
exports.event = event;
|
|
2758
|
+
exports.findCustomElementPropByAttribute = findCustomElementPropByAttribute;
|
|
1229
2759
|
exports.getCurrentHostContext = getCurrentHostContext;
|
|
1230
2760
|
exports.getCurrentOwner = getCurrentOwner;
|
|
2761
|
+
exports.getCustomElementAttributeName = getCustomElementAttributeName;
|
|
2762
|
+
exports.getCustomElementObservedAttributes = getCustomElementObservedAttributes;
|
|
1231
2763
|
exports.getElementDefinition = getElementDefinition;
|
|
1232
2764
|
exports.inject = inject;
|
|
1233
2765
|
exports.insert = insert;
|
|
@@ -1241,6 +2773,7 @@ exports.normalizeClass = normalizeClass;
|
|
|
1241
2773
|
exports.prop = prop;
|
|
1242
2774
|
exports.provide = provide;
|
|
1243
2775
|
exports.provideDOMContext = provideDOMContext;
|
|
2776
|
+
exports.reflectCustomElementProperty = reflectCustomElementProperty;
|
|
1244
2777
|
exports.removeNodes = removeNodes;
|
|
1245
2778
|
exports.render = render;
|
|
1246
2779
|
exports.resolveDOMContext = resolveDOMContext;
|