@zeus-js/runtime-dom 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,2243 @@
1
+ /**
2
+ * runtime-dom v0.0.2
3
+ * (c) 2026 baicie
4
+ * Released under the MIT License.
5
+ **/
6
+ //#region packages/runtime-dom/src/template.ts
7
+ function template(html, _isImportNode = false, _isSVG = false, _isMathML = false) {
8
+ const t = document.createElement("template");
9
+ t.innerHTML = html;
10
+ return function clone() {
11
+ return t.content.cloneNode(true);
12
+ };
13
+ }
14
+ //#endregion
15
+ //#region packages/shared/src/makeMap.ts
16
+ /**
17
+ * Make a map and return a function for checking if a key
18
+ * is in that map.
19
+ * IMPORTANT: all calls of this function must be prefixed with
20
+ * \/\*#\_\_PURE\_\_\*\/
21
+ * So that rollup can tree-shake them if necessary.
22
+ */
23
+ /*@__NO_SIDE_EFFECTS__*/
24
+ function makeMap(str) {
25
+ const map = Object.create(null);
26
+ for (const key of str.split(",")) map[key] = 1;
27
+ return (val) => val in map;
28
+ }
29
+ Object.freeze({});
30
+ Object.freeze([]);
31
+ const extend = Object.assign;
32
+ const hasOwnProperty$1 = Object.prototype.hasOwnProperty;
33
+ const hasOwn = (val, key) => hasOwnProperty$1.call(val, key);
34
+ const isArray = Array.isArray;
35
+ const isMap = (val) => toTypeString(val) === "[object Map]";
36
+ const isString = (val) => typeof val === "string";
37
+ const isSymbol = (val) => typeof val === "symbol";
38
+ const isObject = (val) => val !== null && typeof val === "object";
39
+ const objectToString = Object.prototype.toString;
40
+ const toTypeString = (value) => objectToString.call(value);
41
+ const toRawType = (value) => {
42
+ return toTypeString(value).slice(8, -1);
43
+ };
44
+ const isIntegerKey = (key) => isString(key) && key !== "NaN" && key[0] !== "-" && "" + parseInt(key, 10) === key;
45
+ const cacheStringFunction = (fn) => {
46
+ const cache = Object.create(null);
47
+ return ((str) => {
48
+ return cache[str] || (cache[str] = fn(str));
49
+ });
50
+ };
51
+ /**
52
+ * @private
53
+ */
54
+ const capitalize = cacheStringFunction((str) => {
55
+ return str.charAt(0).toUpperCase() + str.slice(1);
56
+ });
57
+ const hasChanged = (value, oldValue) => !Object.is(value, oldValue);
58
+ //#endregion
59
+ //#region packages/signal/src/warning.ts
60
+ function warn(msg, ...args) {
61
+ console.warn(`[Zeus warn] ${msg}`, ...args);
62
+ }
63
+ //#endregion
64
+ //#region packages/signal/src/effectScope.ts
65
+ let activeEffectScope;
66
+ var EffectScope = class {
67
+ constructor(detached = false) {
68
+ this.detached = detached;
69
+ this._active = true;
70
+ this._on = 0;
71
+ this.effects = [];
72
+ this.cleanups = [];
73
+ this._isPaused = false;
74
+ this._warnOnRun = true;
75
+ this.__v_skip = true;
76
+ if (!detached && activeEffectScope) if (activeEffectScope.active) {
77
+ this.parent = activeEffectScope;
78
+ this.index = (activeEffectScope.scopes || (activeEffectScope.scopes = [])).push(this) - 1;
79
+ } else {
80
+ this._active = false;
81
+ this._warnOnRun = false;
82
+ }
83
+ }
84
+ get active() {
85
+ return this._active;
86
+ }
87
+ pause() {
88
+ if (this._active) {
89
+ this._isPaused = true;
90
+ let i, l;
91
+ if (this.scopes) for (i = 0, l = this.scopes.length; i < l; i++) this.scopes[i].pause();
92
+ for (i = 0, l = this.effects.length; i < l; i++) this.effects[i].pause();
93
+ }
94
+ }
95
+ /**
96
+ * Resumes the effect scope, including all child scopes and effects.
97
+ */
98
+ resume() {
99
+ if (this._active) {
100
+ if (this._isPaused) {
101
+ this._isPaused = false;
102
+ let i, l;
103
+ if (this.scopes) for (i = 0, l = this.scopes.length; i < l; i++) this.scopes[i].resume();
104
+ for (i = 0, l = this.effects.length; i < l; i++) this.effects[i].resume();
105
+ }
106
+ }
107
+ }
108
+ run(fn) {
109
+ if (this._active) {
110
+ const currentEffectScope = activeEffectScope;
111
+ try {
112
+ activeEffectScope = this;
113
+ return fn();
114
+ } finally {
115
+ activeEffectScope = currentEffectScope;
116
+ }
117
+ } else if (this._warnOnRun) warn(`cannot run an inactive effect scope.`);
118
+ }
119
+ /**
120
+ * This should only be called on non-detached scopes
121
+ * @internal
122
+ */
123
+ on() {
124
+ if (++this._on === 1) {
125
+ this.prevScope = activeEffectScope;
126
+ activeEffectScope = this;
127
+ }
128
+ }
129
+ /**
130
+ * This should only be called on non-detached scopes
131
+ * @internal
132
+ */
133
+ off() {
134
+ if (this._on > 0 && --this._on === 0) {
135
+ if (activeEffectScope === this) activeEffectScope = this.prevScope;
136
+ else {
137
+ let current = activeEffectScope;
138
+ while (current) {
139
+ if (current.prevScope === this) {
140
+ current.prevScope = this.prevScope;
141
+ break;
142
+ }
143
+ current = current.prevScope;
144
+ }
145
+ }
146
+ this.prevScope = void 0;
147
+ }
148
+ }
149
+ stop(fromParent) {
150
+ if (this._active) {
151
+ this._active = false;
152
+ let i, l;
153
+ for (i = 0, l = this.effects.length; i < l; i++) this.effects[i].stop();
154
+ this.effects.length = 0;
155
+ for (i = 0, l = this.cleanups.length; i < l; i++) this.cleanups[i]();
156
+ this.cleanups.length = 0;
157
+ if (this.scopes) {
158
+ for (i = 0, l = this.scopes.length; i < l; i++) this.scopes[i].stop(true);
159
+ this.scopes.length = 0;
160
+ }
161
+ if (!this.detached && this.parent && !fromParent) {
162
+ const last = this.parent.scopes.pop();
163
+ if (last && last !== this) {
164
+ this.parent.scopes[this.index] = last;
165
+ last.index = this.index;
166
+ }
167
+ }
168
+ this.parent = void 0;
169
+ }
170
+ }
171
+ };
172
+ /**
173
+ * Creates an effect scope object which can capture the reactive effects (i.e.
174
+ * computed and watchers) created within it so that these effects can be
175
+ * disposed together. For detailed use cases of this API, please consult its
176
+ * corresponding {@link https://github.com/vuejs/rfcs/blob/master/active-rfcs/0041-reactivity-effect-scope.md | RFC}.
177
+ *
178
+ * @param detached - Can be used to create a "detached" effect scope.
179
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#effectscope}
180
+ */
181
+ function effectScope(detached) {
182
+ return new EffectScope(detached);
183
+ }
184
+ /**
185
+ * Returns the current active effect scope if there is one.
186
+ *
187
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#getcurrentscope}
188
+ */
189
+ function getCurrentScope() {
190
+ return activeEffectScope;
191
+ }
192
+ /**
193
+ * Registers a dispose callback on the current active effect scope. The
194
+ * callback will be invoked when the associated effect scope is stopped.
195
+ *
196
+ * @param fn - The callback function to attach to the scope's cleanup.
197
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#onscopedispose}
198
+ */
199
+ function onScopeDispose(fn, failSilently = false) {
200
+ if (activeEffectScope) activeEffectScope.cleanups.push(fn);
201
+ else if (!failSilently) warn("onScopeDispose() is called when there is no active effect scope to be associated with.");
202
+ }
203
+ //#endregion
204
+ //#region packages/signal/src/effect.ts
205
+ let activeSub;
206
+ const pausedQueueEffects = /* @__PURE__ */ new WeakSet();
207
+ var ReactiveEffect = class {
208
+ constructor(fn) {
209
+ this.fn = fn;
210
+ this.deps = void 0;
211
+ this.depsTail = void 0;
212
+ this.flags = 5;
213
+ this.next = void 0;
214
+ this.cleanup = void 0;
215
+ this.scheduler = void 0;
216
+ if (activeEffectScope) if (activeEffectScope.active) activeEffectScope.effects.push(this);
217
+ else this.flags &= -2;
218
+ }
219
+ pause() {
220
+ this.flags |= 64;
221
+ }
222
+ resume() {
223
+ if (this.flags & 64) {
224
+ this.flags &= -65;
225
+ if (pausedQueueEffects.has(this)) {
226
+ pausedQueueEffects.delete(this);
227
+ this.trigger();
228
+ }
229
+ }
230
+ }
231
+ /**
232
+ * @internal
233
+ */
234
+ notify() {
235
+ if (this.flags & 2 && !(this.flags & 32)) return;
236
+ if (!(this.flags & 8)) queueSubscriber(this);
237
+ }
238
+ run() {
239
+ if (!(this.flags & 1)) return this.fn();
240
+ this.flags |= 2;
241
+ cleanupEffect(this);
242
+ prepareDeps(this);
243
+ const prevEffect = activeSub;
244
+ const prevShouldTrack = shouldTrack;
245
+ activeSub = this;
246
+ shouldTrack = true;
247
+ try {
248
+ return this.fn();
249
+ } finally {
250
+ if (activeSub !== this) warn("Active effect was not restored correctly - this is likely a Vue internal bug.");
251
+ cleanupDeps(this);
252
+ activeSub = prevEffect;
253
+ shouldTrack = prevShouldTrack;
254
+ this.flags &= -3;
255
+ }
256
+ }
257
+ stop() {
258
+ if (this.flags & 1) {
259
+ for (let link = this.deps; link; link = link.nextDep) removeSub(link);
260
+ this.deps = this.depsTail = void 0;
261
+ cleanupEffect(this);
262
+ this.onStop && this.onStop();
263
+ this.flags &= -2;
264
+ }
265
+ }
266
+ trigger() {
267
+ if (this.flags & 64) pausedQueueEffects.add(this);
268
+ else if (this.scheduler) this.scheduler();
269
+ else this.runIfDirty();
270
+ }
271
+ /**
272
+ * @internal
273
+ */
274
+ runIfDirty() {
275
+ if (isDirty(this)) this.run();
276
+ }
277
+ get dirty() {
278
+ return isDirty(this);
279
+ }
280
+ };
281
+ /**
282
+ * For debugging
283
+ */
284
+ let batchDepth = 0;
285
+ let batchedSub;
286
+ let batchedComputed;
287
+ /**
288
+ * @internal
289
+ */
290
+ function queueSubscriber(sub, isComputed = false) {
291
+ sub.flags |= 8;
292
+ if (isComputed) {
293
+ sub.next = batchedComputed;
294
+ batchedComputed = sub;
295
+ return;
296
+ }
297
+ sub.next = batchedSub;
298
+ batchedSub = sub;
299
+ }
300
+ /**
301
+ * @internal
302
+ */
303
+ function startBatch() {
304
+ batchDepth++;
305
+ }
306
+ /**
307
+ * Run batched effects when all batches have ended
308
+ * @internal
309
+ */
310
+ function endBatch() {
311
+ if (--batchDepth > 0) return;
312
+ if (batchedComputed) {
313
+ let e = batchedComputed;
314
+ batchedComputed = void 0;
315
+ while (e) {
316
+ const next = e.next;
317
+ e.next = void 0;
318
+ e.flags &= -9;
319
+ e = next;
320
+ }
321
+ }
322
+ let error;
323
+ while (batchedSub) {
324
+ let e = batchedSub;
325
+ batchedSub = void 0;
326
+ while (e) {
327
+ const next = e.next;
328
+ e.next = void 0;
329
+ e.flags &= -9;
330
+ if (e.flags & 1) try {
331
+ e.trigger();
332
+ } catch (err) {
333
+ if (!error) error = err;
334
+ }
335
+ e = next;
336
+ }
337
+ }
338
+ if (error) throw error;
339
+ }
340
+ function prepareDeps(sub) {
341
+ for (let link = sub.deps; link; link = link.nextDep) {
342
+ link.version = -1;
343
+ link.prevActiveLink = link.dep.activeLink;
344
+ link.dep.activeLink = link;
345
+ }
346
+ }
347
+ function cleanupDeps(sub) {
348
+ let head;
349
+ let tail = sub.depsTail;
350
+ let link = tail;
351
+ while (link) {
352
+ const prev = link.prevDep;
353
+ if (link.version === -1) {
354
+ if (link === tail) tail = prev;
355
+ removeSub(link);
356
+ removeDep(link);
357
+ } else head = link;
358
+ link.dep.activeLink = link.prevActiveLink;
359
+ link.prevActiveLink = void 0;
360
+ link = prev;
361
+ }
362
+ sub.deps = head;
363
+ sub.depsTail = tail;
364
+ }
365
+ function isDirty(sub) {
366
+ 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;
367
+ if (sub._dirty) return true;
368
+ return false;
369
+ }
370
+ /**
371
+ * Returning false indicates the refresh failed
372
+ * @internal
373
+ */
374
+ function refreshComputed(computed) {
375
+ if (computed.flags & 4 && !(computed.flags & 16)) return;
376
+ computed.flags &= -17;
377
+ if (computed.globalVersion === globalVersion) return;
378
+ computed.globalVersion = globalVersion;
379
+ if (!computed.isSSR && computed.flags & 128 && (!computed.deps && !computed._dirty || !isDirty(computed))) return;
380
+ computed.flags |= 2;
381
+ const dep = computed.dep;
382
+ const prevSub = activeSub;
383
+ const prevShouldTrack = shouldTrack;
384
+ activeSub = computed;
385
+ shouldTrack = true;
386
+ try {
387
+ prepareDeps(computed);
388
+ const value = computed.fn(computed._value);
389
+ if (dep.version === 0 || hasChanged(value, computed._value)) {
390
+ computed.flags |= 128;
391
+ computed._value = value;
392
+ dep.version++;
393
+ }
394
+ } catch (err) {
395
+ dep.version++;
396
+ throw err;
397
+ } finally {
398
+ activeSub = prevSub;
399
+ shouldTrack = prevShouldTrack;
400
+ cleanupDeps(computed);
401
+ computed.flags &= -3;
402
+ }
403
+ }
404
+ function removeSub(link, soft = false) {
405
+ const { dep, prevSub, nextSub } = link;
406
+ if (prevSub) {
407
+ prevSub.nextSub = nextSub;
408
+ link.prevSub = void 0;
409
+ }
410
+ if (nextSub) {
411
+ nextSub.prevSub = prevSub;
412
+ link.nextSub = void 0;
413
+ }
414
+ if (dep.subsHead === link) dep.subsHead = nextSub;
415
+ if (dep.subs === link) {
416
+ dep.subs = prevSub;
417
+ if (!prevSub && dep.computed) {
418
+ dep.computed.flags &= -5;
419
+ for (let l = dep.computed.deps; l; l = l.nextDep) removeSub(l, true);
420
+ }
421
+ }
422
+ if (!soft && !--dep.sc && dep.map) dep.map.delete(dep.key);
423
+ }
424
+ function removeDep(link) {
425
+ const { prevDep, nextDep } = link;
426
+ if (prevDep) {
427
+ prevDep.nextDep = nextDep;
428
+ link.prevDep = void 0;
429
+ }
430
+ if (nextDep) {
431
+ nextDep.prevDep = prevDep;
432
+ link.nextDep = void 0;
433
+ }
434
+ }
435
+ function effect(fn, options) {
436
+ if (fn.effect instanceof ReactiveEffect) fn = fn.effect.fn;
437
+ const e = new ReactiveEffect(fn);
438
+ if (options) extend(e, options);
439
+ try {
440
+ e.run();
441
+ } catch (err) {
442
+ e.stop();
443
+ throw err;
444
+ }
445
+ const runner = e.run.bind(e);
446
+ runner.effect = e;
447
+ return runner;
448
+ }
449
+ /**
450
+ * Stops the effect associated with the given runner.
451
+ *
452
+ * @param runner - Association with the effect to stop tracking.
453
+ */
454
+ function stop(runner) {
455
+ runner.effect.stop();
456
+ }
457
+ /**
458
+ * @internal
459
+ */
460
+ let shouldTrack = true;
461
+ const trackStack = [];
462
+ /**
463
+ * Temporarily pauses tracking.
464
+ */
465
+ function pauseTracking() {
466
+ trackStack.push(shouldTrack);
467
+ shouldTrack = false;
468
+ }
469
+ /**
470
+ * Resets the previous global effect tracking state.
471
+ */
472
+ function resetTracking() {
473
+ const last = trackStack.pop();
474
+ shouldTrack = last === void 0 ? true : last;
475
+ }
476
+ function cleanupEffect(e) {
477
+ const { cleanup } = e;
478
+ e.cleanup = void 0;
479
+ if (cleanup) {
480
+ const prevSub = activeSub;
481
+ activeSub = void 0;
482
+ try {
483
+ cleanup();
484
+ } finally {
485
+ activeSub = prevSub;
486
+ }
487
+ }
488
+ }
489
+ //#endregion
490
+ //#region packages/signal/src/dep.ts
491
+ /**
492
+ * Incremented every time a reactive change happens
493
+ * This is used to give computed a fast path to avoid re-compute when nothing
494
+ * has changed.
495
+ */
496
+ let globalVersion = 0;
497
+ /**
498
+ * Represents a link between a source (Dep) and a subscriber (Effect or Computed).
499
+ * Deps and subs have a many-to-many relationship - each link between a
500
+ * dep and a sub is represented by a Link instance.
501
+ *
502
+ * A Link is also a node in two doubly-linked lists - one for the associated
503
+ * sub to track all its deps, and one for the associated dep to track all its
504
+ * subs.
505
+ *
506
+ * @internal
507
+ */
508
+ var Link = class {
509
+ constructor(sub, dep) {
510
+ this.sub = sub;
511
+ this.dep = dep;
512
+ this.version = dep.version;
513
+ this.nextDep = this.prevDep = this.nextSub = this.prevSub = this.prevActiveLink = void 0;
514
+ }
515
+ };
516
+ /**
517
+ * @internal
518
+ */
519
+ var Dep = class {
520
+ constructor(computed) {
521
+ this.computed = computed;
522
+ this.version = 0;
523
+ this.activeLink = void 0;
524
+ this.subs = void 0;
525
+ this.map = void 0;
526
+ this.key = void 0;
527
+ this.sc = 0;
528
+ this.__v_skip = true;
529
+ this.subsHead = void 0;
530
+ }
531
+ track(debugInfo) {
532
+ if (!activeSub || !shouldTrack || activeSub === this.computed) return;
533
+ let link = this.activeLink;
534
+ if (link === void 0 || link.sub !== activeSub) {
535
+ link = this.activeLink = new Link(activeSub, this);
536
+ if (!activeSub.deps) activeSub.deps = activeSub.depsTail = link;
537
+ else {
538
+ link.prevDep = activeSub.depsTail;
539
+ activeSub.depsTail.nextDep = link;
540
+ activeSub.depsTail = link;
541
+ }
542
+ addSub(link);
543
+ } else if (link.version === -1) {
544
+ link.version = this.version;
545
+ if (link.nextDep) {
546
+ const next = link.nextDep;
547
+ next.prevDep = link.prevDep;
548
+ if (link.prevDep) link.prevDep.nextDep = next;
549
+ link.prevDep = activeSub.depsTail;
550
+ link.nextDep = void 0;
551
+ activeSub.depsTail.nextDep = link;
552
+ activeSub.depsTail = link;
553
+ if (activeSub.deps === link) activeSub.deps = next;
554
+ }
555
+ }
556
+ if (activeSub.onTrack) activeSub.onTrack(extend({ effect: activeSub }, debugInfo));
557
+ return link;
558
+ }
559
+ trigger(debugInfo) {
560
+ this.version++;
561
+ globalVersion++;
562
+ this.notify(debugInfo);
563
+ }
564
+ notify(debugInfo) {
565
+ startBatch();
566
+ try {
567
+ for (let head = this.subsHead; head; head = head.nextSub) if (head.sub.onTrigger && !(head.sub.flags & 8)) head.sub.onTrigger(extend({ effect: head.sub }, debugInfo));
568
+ for (let link = this.subs; link; link = link.prevSub) if (link.sub.notify()) link.sub.dep.notify();
569
+ } finally {
570
+ endBatch();
571
+ }
572
+ }
573
+ };
574
+ function addSub(link) {
575
+ link.dep.sc++;
576
+ if (link.sub.flags & 4) {
577
+ const computed = link.dep.computed;
578
+ if (computed && !link.dep.subs) {
579
+ computed.flags |= 20;
580
+ for (let l = computed.deps; l; l = l.nextDep) addSub(l);
581
+ }
582
+ const currentTail = link.dep.subs;
583
+ if (currentTail !== link) {
584
+ link.prevSub = currentTail;
585
+ if (currentTail) currentTail.nextSub = link;
586
+ }
587
+ if (link.dep.subsHead === void 0) link.dep.subsHead = link;
588
+ link.dep.subs = link;
589
+ }
590
+ }
591
+ const targetMap = /* @__PURE__ */ new WeakMap();
592
+ const ITERATE_KEY = Symbol("Object iterate");
593
+ const MAP_KEY_ITERATE_KEY = Symbol("Map keys iterate");
594
+ const ARRAY_ITERATE_KEY = Symbol("Array iterate");
595
+ /**
596
+ * Tracks access to a reactive property.
597
+ *
598
+ * This will check which effect is running at the moment and record it as dep
599
+ * which records all effects that depend on the reactive property.
600
+ *
601
+ * @param target - Object holding the reactive property.
602
+ * @param type - Defines the type of access to the reactive property.
603
+ * @param key - Identifier of the reactive property to track.
604
+ */
605
+ function track(target, type, key) {
606
+ if (shouldTrack && activeSub) {
607
+ let depsMap = targetMap.get(target);
608
+ if (!depsMap) targetMap.set(target, depsMap = /* @__PURE__ */ new Map());
609
+ let dep = depsMap.get(key);
610
+ if (!dep) {
611
+ depsMap.set(key, dep = new Dep());
612
+ dep.map = depsMap;
613
+ dep.key = key;
614
+ }
615
+ dep.track({
616
+ target,
617
+ type,
618
+ key
619
+ });
620
+ }
621
+ }
622
+ /**
623
+ * Finds all deps associated with the target (or a specific property) and
624
+ * triggers the effects stored within.
625
+ *
626
+ * @param target - The reactive object.
627
+ * @param type - Defines the type of the operation that needs to trigger effects.
628
+ * @param key - Can be used to target a specific reactive property in the target object.
629
+ */
630
+ function trigger(target, type, key, newValue, oldValue, oldTarget) {
631
+ const depsMap = targetMap.get(target);
632
+ if (!depsMap) {
633
+ globalVersion++;
634
+ return;
635
+ }
636
+ const run = (dep) => {
637
+ if (dep) dep.trigger({
638
+ target,
639
+ type,
640
+ key,
641
+ newValue,
642
+ oldValue,
643
+ oldTarget
644
+ });
645
+ };
646
+ startBatch();
647
+ if (type === "clear") depsMap.forEach(run);
648
+ else {
649
+ const targetIsArray = isArray(target);
650
+ const isArrayIndex = targetIsArray && isIntegerKey(key);
651
+ if (targetIsArray && key === "length") {
652
+ const newLength = Number(newValue);
653
+ depsMap.forEach((dep, key) => {
654
+ if (key === "length" || key === ARRAY_ITERATE_KEY || !isSymbol(key) && key >= newLength) run(dep);
655
+ });
656
+ } else {
657
+ if (key !== void 0 || depsMap.has(void 0)) run(depsMap.get(key));
658
+ if (isArrayIndex) run(depsMap.get(ARRAY_ITERATE_KEY));
659
+ switch (type) {
660
+ case "add":
661
+ if (!targetIsArray) {
662
+ run(depsMap.get(ITERATE_KEY));
663
+ if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
664
+ } else if (isArrayIndex) run(depsMap.get("length"));
665
+ break;
666
+ case "delete":
667
+ if (!targetIsArray) {
668
+ run(depsMap.get(ITERATE_KEY));
669
+ if (isMap(target)) run(depsMap.get(MAP_KEY_ITERATE_KEY));
670
+ }
671
+ break;
672
+ case "set":
673
+ if (isMap(target)) run(depsMap.get(ITERATE_KEY));
674
+ break;
675
+ }
676
+ }
677
+ }
678
+ endBatch();
679
+ }
680
+ //#endregion
681
+ //#region packages/signal/src/arrayInstrumentations.ts
682
+ /**
683
+ * Track array iteration and return:
684
+ * - if input is reactive: a cloned raw array with reactive values
685
+ * - if input is non-reactive or shallowReactive: the original raw array
686
+ */
687
+ function reactiveReadArray(array) {
688
+ const raw = /* @__PURE__ */ toRaw(array);
689
+ if (raw === array) return raw;
690
+ track(raw, "iterate", ARRAY_ITERATE_KEY);
691
+ return /* @__PURE__ */ isShallow(array) ? raw : raw.map(toReactive);
692
+ }
693
+ /**
694
+ * Track array iteration and return raw array
695
+ */
696
+ function shallowReadArray(arr) {
697
+ track(arr = /* @__PURE__ */ toRaw(arr), "iterate", ARRAY_ITERATE_KEY);
698
+ return arr;
699
+ }
700
+ function toWrapped(target, item) {
701
+ if (/* @__PURE__ */ isReadonly(target)) return /* @__PURE__ */ isReactive(target) ? toReadonly(toReactive(item)) : toReadonly(item);
702
+ return toReactive(item);
703
+ }
704
+ const arrayInstrumentations = {
705
+ __proto__: null,
706
+ [Symbol.iterator]() {
707
+ return iterator(this, Symbol.iterator, (item) => toWrapped(this, item));
708
+ },
709
+ concat(...args) {
710
+ return reactiveReadArray(this).concat(...args.map((x) => isArray(x) ? reactiveReadArray(x) : x));
711
+ },
712
+ entries() {
713
+ return iterator(this, "entries", (value) => {
714
+ value[1] = toWrapped(this, value[1]);
715
+ return value;
716
+ });
717
+ },
718
+ every(fn, thisArg) {
719
+ return apply(this, "every", fn, thisArg, void 0, arguments);
720
+ },
721
+ filter(fn, thisArg) {
722
+ return apply(this, "filter", fn, thisArg, (v) => v.map((item) => toWrapped(this, item)), arguments);
723
+ },
724
+ find(fn, thisArg) {
725
+ return apply(this, "find", fn, thisArg, (item) => toWrapped(this, item), arguments);
726
+ },
727
+ findIndex(fn, thisArg) {
728
+ return apply(this, "findIndex", fn, thisArg, void 0, arguments);
729
+ },
730
+ findLast(fn, thisArg) {
731
+ return apply(this, "findLast", fn, thisArg, (item) => toWrapped(this, item), arguments);
732
+ },
733
+ findLastIndex(fn, thisArg) {
734
+ return apply(this, "findLastIndex", fn, thisArg, void 0, arguments);
735
+ },
736
+ forEach(fn, thisArg) {
737
+ return apply(this, "forEach", fn, thisArg, void 0, arguments);
738
+ },
739
+ includes(...args) {
740
+ return searchProxy(this, "includes", args);
741
+ },
742
+ indexOf(...args) {
743
+ return searchProxy(this, "indexOf", args);
744
+ },
745
+ join(separator) {
746
+ return reactiveReadArray(this).join(separator);
747
+ },
748
+ lastIndexOf(...args) {
749
+ return searchProxy(this, "lastIndexOf", args);
750
+ },
751
+ map(fn, thisArg) {
752
+ return apply(this, "map", fn, thisArg, void 0, arguments);
753
+ },
754
+ pop() {
755
+ return noTracking(this, "pop");
756
+ },
757
+ push(...args) {
758
+ return noTracking(this, "push", args);
759
+ },
760
+ reduce(fn, ...args) {
761
+ return reduce(this, "reduce", fn, args);
762
+ },
763
+ reduceRight(fn, ...args) {
764
+ return reduce(this, "reduceRight", fn, args);
765
+ },
766
+ shift() {
767
+ return noTracking(this, "shift");
768
+ },
769
+ some(fn, thisArg) {
770
+ return apply(this, "some", fn, thisArg, void 0, arguments);
771
+ },
772
+ splice(...args) {
773
+ return noTracking(this, "splice", args);
774
+ },
775
+ toReversed() {
776
+ return reactiveReadArray(this).toReversed();
777
+ },
778
+ toSorted(comparer) {
779
+ return reactiveReadArray(this).toSorted(comparer);
780
+ },
781
+ toSpliced(...args) {
782
+ return reactiveReadArray(this).toSpliced(...args);
783
+ },
784
+ unshift(...args) {
785
+ return noTracking(this, "unshift", args);
786
+ },
787
+ values() {
788
+ return iterator(this, "values", (item) => toWrapped(this, item));
789
+ }
790
+ };
791
+ function iterator(self, method, wrapValue) {
792
+ const arr = shallowReadArray(self);
793
+ const iter = arr[method]();
794
+ if (arr !== self && !/* @__PURE__ */ isShallow(self)) {
795
+ iter._next = iter.next;
796
+ iter.next = () => {
797
+ const result = iter._next();
798
+ if (!result.done) result.value = wrapValue(result.value);
799
+ return result;
800
+ };
801
+ }
802
+ return iter;
803
+ }
804
+ const arrayProto = Array.prototype;
805
+ function apply(self, method, fn, thisArg, wrappedRetFn, args) {
806
+ const arr = shallowReadArray(self);
807
+ const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
808
+ const methodFn = arr[method];
809
+ if (methodFn !== arrayProto[method]) {
810
+ const result = methodFn.apply(self, args);
811
+ return needsWrap ? toReactive(result) : result;
812
+ }
813
+ let wrappedFn = fn;
814
+ if (arr !== self) {
815
+ if (needsWrap) wrappedFn = function(item, index) {
816
+ return fn.call(this, toWrapped(self, item), index, self);
817
+ };
818
+ else if (fn.length > 2) wrappedFn = function(item, index) {
819
+ return fn.call(this, item, index, self);
820
+ };
821
+ }
822
+ const result = methodFn.call(arr, wrappedFn, thisArg);
823
+ return needsWrap && wrappedRetFn ? wrappedRetFn(result) : result;
824
+ }
825
+ function reduce(self, method, fn, args) {
826
+ const arr = shallowReadArray(self);
827
+ const needsWrap = arr !== self && !/* @__PURE__ */ isShallow(self);
828
+ let wrappedFn = fn;
829
+ let wrapInitialAccumulator = false;
830
+ if (arr !== self) {
831
+ if (needsWrap) {
832
+ wrapInitialAccumulator = args.length === 0;
833
+ wrappedFn = function(acc, item, index) {
834
+ if (wrapInitialAccumulator) {
835
+ wrapInitialAccumulator = false;
836
+ acc = toWrapped(self, acc);
837
+ }
838
+ return fn.call(this, acc, toWrapped(self, item), index, self);
839
+ };
840
+ } else if (fn.length > 3) wrappedFn = function(acc, item, index) {
841
+ return fn.call(this, acc, item, index, self);
842
+ };
843
+ }
844
+ const result = arr[method](wrappedFn, ...args);
845
+ return wrapInitialAccumulator ? toWrapped(self, result) : result;
846
+ }
847
+ function searchProxy(self, method, args) {
848
+ const arr = /* @__PURE__ */ toRaw(self);
849
+ track(arr, "iterate", ARRAY_ITERATE_KEY);
850
+ const res = arr[method](...args);
851
+ if ((res === -1 || res === false) && /* @__PURE__ */ isProxy(args[0])) {
852
+ args[0] = /* @__PURE__ */ toRaw(args[0]);
853
+ return arr[method](...args);
854
+ }
855
+ return res;
856
+ }
857
+ function noTracking(self, method, args = []) {
858
+ pauseTracking();
859
+ startBatch();
860
+ const res = (/* @__PURE__ */ toRaw(self))[method].apply(self, args);
861
+ endBatch();
862
+ resetTracking();
863
+ return res;
864
+ }
865
+ //#endregion
866
+ //#region packages/signal/src/ref.ts
867
+ let _ReactiveFlags$IS_REF, _ReactiveFlags$IS_SHA;
868
+ /*@__NO_SIDE_EFFECTS__*/
869
+ function isRef(r) {
870
+ return r ? r["__v_isRef"] === true : false;
871
+ }
872
+ /*@__NO_SIDE_EFFECTS__*/
873
+ function ref(value) {
874
+ return createRef(value, false);
875
+ }
876
+ function createRef(rawValue, shallow) {
877
+ if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
878
+ return new RefImpl(rawValue, shallow);
879
+ }
880
+ _ReactiveFlags$IS_REF = "__v_isRef";
881
+ _ReactiveFlags$IS_SHA = "__v_isShallow";
882
+ /**
883
+ * @internal
884
+ */
885
+ var RefImpl = class {
886
+ constructor(value, isShallow) {
887
+ this.dep = new Dep();
888
+ this[_ReactiveFlags$IS_REF] = true;
889
+ this[_ReactiveFlags$IS_SHA] = false;
890
+ this._rawValue = isShallow ? value : /* @__PURE__ */ toRaw(value);
891
+ this._value = isShallow ? value : toReactive(value);
892
+ this["__v_isShallow"] = isShallow;
893
+ }
894
+ get value() {
895
+ this.dep.track({
896
+ target: this,
897
+ type: "get",
898
+ key: "value"
899
+ });
900
+ return this._value;
901
+ }
902
+ set value(newValue) {
903
+ const oldValue = this._rawValue;
904
+ const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
905
+ newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
906
+ if (hasChanged(newValue, oldValue)) {
907
+ this._rawValue = newValue;
908
+ this._value = useDirectValue ? newValue : toReactive(newValue);
909
+ this.dep.trigger({
910
+ target: this,
911
+ type: "set",
912
+ key: "value",
913
+ newValue,
914
+ oldValue
915
+ });
916
+ }
917
+ }
918
+ };
919
+ //#endregion
920
+ //#region packages/signal/src/baseHandlers.ts
921
+ const isNonTrackableKeys = /*@__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
922
+ const builtInSymbols = new Set(/*@__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
923
+ function hasOwnProperty(key) {
924
+ if (!isSymbol(key)) key = String(key);
925
+ const obj = /* @__PURE__ */ toRaw(this);
926
+ track(obj, "has", key);
927
+ return obj.hasOwnProperty(key);
928
+ }
929
+ var BaseReactiveHandler = class {
930
+ constructor(_isReadonly = false, _isShallow = false) {
931
+ this._isReadonly = _isReadonly;
932
+ this._isShallow = _isShallow;
933
+ }
934
+ get(target, key, receiver) {
935
+ if (key === "__v_skip") return target["__v_skip"];
936
+ const isReadonly = this._isReadonly, isShallow = this._isShallow;
937
+ if (key === "__v_isReactive") return !isReadonly;
938
+ else if (key === "__v_isReadonly") return isReadonly;
939
+ else if (key === "__v_isShallow") return isShallow;
940
+ else if (key === "__v_raw") {
941
+ if (receiver === (isReadonly ? isShallow ? shallowReadonlyMap : readonlyMap : isShallow ? shallowReactiveMap : reactiveMap).get(target) || Object.getPrototypeOf(target) === Object.getPrototypeOf(receiver)) return target;
942
+ return;
943
+ }
944
+ const targetIsArray = isArray(target);
945
+ if (!isReadonly) {
946
+ let fn;
947
+ if (targetIsArray && (fn = arrayInstrumentations[key])) return fn;
948
+ if (key === "hasOwnProperty") return hasOwnProperty;
949
+ }
950
+ const res = Reflect.get(target, key, /* @__PURE__ */ isRef(target) ? target : receiver);
951
+ if (isSymbol(key) ? builtInSymbols.has(key) : isNonTrackableKeys(key)) return res;
952
+ if (!isReadonly) track(target, "get", key);
953
+ if (isShallow) return res;
954
+ if (/* @__PURE__ */ isRef(res)) {
955
+ const value = targetIsArray && isIntegerKey(key) ? res : res.value;
956
+ return isReadonly && isObject(value) ? /* @__PURE__ */ readonly(value) : value;
957
+ }
958
+ if (isObject(res)) return isReadonly ? /* @__PURE__ */ readonly(res) : /* @__PURE__ */ reactive(res);
959
+ return res;
960
+ }
961
+ };
962
+ var MutableReactiveHandler = class extends BaseReactiveHandler {
963
+ constructor(isShallow = false) {
964
+ super(false, isShallow);
965
+ }
966
+ set(target, key, value, receiver) {
967
+ let oldValue = target[key];
968
+ const isArrayWithIntegerKey = isArray(target) && isIntegerKey(key);
969
+ if (!this._isShallow) {
970
+ const isOldValueReadonly = /* @__PURE__ */ isReadonly(oldValue);
971
+ if (!/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) {
972
+ oldValue = /* @__PURE__ */ toRaw(oldValue);
973
+ value = /* @__PURE__ */ toRaw(value);
974
+ }
975
+ if (!isArrayWithIntegerKey && /* @__PURE__ */ isRef(oldValue) && !/* @__PURE__ */ isRef(value)) if (isOldValueReadonly) {
976
+ warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target[key]);
977
+ return true;
978
+ } else {
979
+ oldValue.value = value;
980
+ return true;
981
+ }
982
+ }
983
+ const hadKey = isArrayWithIntegerKey ? Number(key) < target.length : hasOwn(target, key);
984
+ const result = Reflect.set(target, key, value, /* @__PURE__ */ isRef(target) ? target : receiver);
985
+ if (target === /* @__PURE__ */ toRaw(receiver)) {
986
+ if (!hadKey) trigger(target, "add", key, value);
987
+ else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
988
+ }
989
+ return result;
990
+ }
991
+ deleteProperty(target, key) {
992
+ const hadKey = hasOwn(target, key);
993
+ const oldValue = target[key];
994
+ const result = Reflect.deleteProperty(target, key);
995
+ if (result && hadKey) trigger(target, "delete", key, void 0, oldValue);
996
+ return result;
997
+ }
998
+ has(target, key) {
999
+ const result = Reflect.has(target, key);
1000
+ if (!isSymbol(key) || !builtInSymbols.has(key)) track(target, "has", key);
1001
+ return result;
1002
+ }
1003
+ ownKeys(target) {
1004
+ track(target, "iterate", isArray(target) ? "length" : ITERATE_KEY);
1005
+ return Reflect.ownKeys(target);
1006
+ }
1007
+ };
1008
+ var ReadonlyReactiveHandler = class extends BaseReactiveHandler {
1009
+ constructor(isShallow = false) {
1010
+ super(true, isShallow);
1011
+ }
1012
+ set(target, key) {
1013
+ warn(`Set operation on key "${String(key)}" failed: target is readonly.`, target);
1014
+ return true;
1015
+ }
1016
+ deleteProperty(target, key) {
1017
+ warn(`Delete operation on key "${String(key)}" failed: target is readonly.`, target);
1018
+ return true;
1019
+ }
1020
+ };
1021
+ const mutableHandlers = /*@__PURE__*/ new MutableReactiveHandler();
1022
+ const readonlyHandlers = /*@__PURE__*/ new ReadonlyReactiveHandler();
1023
+ //#endregion
1024
+ //#region packages/signal/src/collectionHandlers.ts
1025
+ const toShallow = (value) => value;
1026
+ const getProto = (v) => Reflect.getPrototypeOf(v);
1027
+ function createIterableMethod(method, isReadonly, isShallow) {
1028
+ return function(...args) {
1029
+ const target = this["__v_raw"];
1030
+ const rawTarget = /* @__PURE__ */ toRaw(target);
1031
+ const targetIsMap = isMap(rawTarget);
1032
+ const isPair = method === "entries" || method === Symbol.iterator && targetIsMap;
1033
+ const isKeyOnly = method === "keys" && targetIsMap;
1034
+ const innerIterator = target[method](...args);
1035
+ const wrap = isShallow ? toShallow : isReadonly ? toReadonly : toReactive;
1036
+ !isReadonly && track(rawTarget, "iterate", isKeyOnly ? MAP_KEY_ITERATE_KEY : ITERATE_KEY);
1037
+ return extend(Object.create(innerIterator), { next() {
1038
+ const { value, done } = innerIterator.next();
1039
+ return done ? {
1040
+ value,
1041
+ done
1042
+ } : {
1043
+ value: isPair ? [wrap(value[0]), wrap(value[1])] : wrap(value),
1044
+ done
1045
+ };
1046
+ } });
1047
+ };
1048
+ }
1049
+ function createReadonlyMethod(type) {
1050
+ return function(...args) {
1051
+ {
1052
+ const key = args[0] ? `on key "${args[0]}" ` : ``;
1053
+ warn(`${capitalize(type)} operation ${key}failed: target is readonly.`, /* @__PURE__ */ toRaw(this));
1054
+ }
1055
+ return type === "delete" ? false : type === "clear" ? void 0 : this;
1056
+ };
1057
+ }
1058
+ function createInstrumentations(readonly, shallow) {
1059
+ const instrumentations = {
1060
+ get(key) {
1061
+ const target = this["__v_raw"];
1062
+ const rawTarget = /* @__PURE__ */ toRaw(target);
1063
+ const rawKey = /* @__PURE__ */ toRaw(key);
1064
+ if (!readonly) {
1065
+ if (hasChanged(key, rawKey)) track(rawTarget, "get", key);
1066
+ track(rawTarget, "get", rawKey);
1067
+ }
1068
+ const { has } = getProto(rawTarget);
1069
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1070
+ if (has.call(rawTarget, key)) return wrap(target.get(key));
1071
+ else if (has.call(rawTarget, rawKey)) return wrap(target.get(rawKey));
1072
+ else if (target !== rawTarget) target.get(key);
1073
+ },
1074
+ get size() {
1075
+ const target = this["__v_raw"];
1076
+ !readonly && track(/* @__PURE__ */ toRaw(target), "iterate", ITERATE_KEY);
1077
+ return target.size;
1078
+ },
1079
+ has(key) {
1080
+ const target = this["__v_raw"];
1081
+ const rawTarget = /* @__PURE__ */ toRaw(target);
1082
+ const rawKey = /* @__PURE__ */ toRaw(key);
1083
+ if (!readonly) {
1084
+ if (hasChanged(key, rawKey)) track(rawTarget, "has", key);
1085
+ track(rawTarget, "has", rawKey);
1086
+ }
1087
+ return key === rawKey ? target.has(key) : target.has(key) || target.has(rawKey);
1088
+ },
1089
+ forEach(callback, thisArg) {
1090
+ const observed = this;
1091
+ const target = observed["__v_raw"];
1092
+ const rawTarget = /* @__PURE__ */ toRaw(target);
1093
+ const wrap = shallow ? toShallow : readonly ? toReadonly : toReactive;
1094
+ !readonly && track(rawTarget, "iterate", ITERATE_KEY);
1095
+ return target.forEach((value, key) => {
1096
+ return callback.call(thisArg, wrap(value), wrap(key), observed);
1097
+ });
1098
+ }
1099
+ };
1100
+ extend(instrumentations, readonly ? {
1101
+ add: createReadonlyMethod("add"),
1102
+ set: createReadonlyMethod("set"),
1103
+ delete: createReadonlyMethod("delete"),
1104
+ clear: createReadonlyMethod("clear")
1105
+ } : {
1106
+ add(value) {
1107
+ const target = /* @__PURE__ */ toRaw(this);
1108
+ const proto = getProto(target);
1109
+ const rawValue = /* @__PURE__ */ toRaw(value);
1110
+ const valueToAdd = !shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value) ? rawValue : value;
1111
+ if (!(proto.has.call(target, valueToAdd) || hasChanged(value, valueToAdd) && proto.has.call(target, value) || hasChanged(rawValue, valueToAdd) && proto.has.call(target, rawValue))) {
1112
+ target.add(valueToAdd);
1113
+ trigger(target, "add", valueToAdd, valueToAdd);
1114
+ }
1115
+ return this;
1116
+ },
1117
+ set(key, value) {
1118
+ if (!shallow && !/* @__PURE__ */ isShallow(value) && !/* @__PURE__ */ isReadonly(value)) value = /* @__PURE__ */ toRaw(value);
1119
+ const target = /* @__PURE__ */ toRaw(this);
1120
+ const { has, get } = getProto(target);
1121
+ let hadKey = has.call(target, key);
1122
+ if (!hadKey) {
1123
+ key = /* @__PURE__ */ toRaw(key);
1124
+ hadKey = has.call(target, key);
1125
+ } else checkIdentityKeys(target, has, key);
1126
+ const oldValue = get.call(target, key);
1127
+ target.set(key, value);
1128
+ if (!hadKey) trigger(target, "add", key, value);
1129
+ else if (hasChanged(value, oldValue)) trigger(target, "set", key, value, oldValue);
1130
+ return this;
1131
+ },
1132
+ delete(key) {
1133
+ const target = /* @__PURE__ */ toRaw(this);
1134
+ const { has, get } = getProto(target);
1135
+ let hadKey = has.call(target, key);
1136
+ if (!hadKey) {
1137
+ key = /* @__PURE__ */ toRaw(key);
1138
+ hadKey = has.call(target, key);
1139
+ } else checkIdentityKeys(target, has, key);
1140
+ const oldValue = get ? get.call(target, key) : void 0;
1141
+ const result = target.delete(key);
1142
+ if (hadKey) trigger(target, "delete", key, void 0, oldValue);
1143
+ return result;
1144
+ },
1145
+ clear() {
1146
+ const target = /* @__PURE__ */ toRaw(this);
1147
+ const hadItems = target.size !== 0;
1148
+ const oldTarget = isMap(target) ? new Map(target) : new Set(target);
1149
+ const result = target.clear();
1150
+ if (hadItems) trigger(target, "clear", void 0, void 0, oldTarget);
1151
+ return result;
1152
+ }
1153
+ });
1154
+ [
1155
+ "keys",
1156
+ "values",
1157
+ "entries",
1158
+ Symbol.iterator
1159
+ ].forEach((method) => {
1160
+ instrumentations[method] = createIterableMethod(method, readonly, shallow);
1161
+ });
1162
+ return instrumentations;
1163
+ }
1164
+ function createInstrumentationGetter(isReadonly, shallow) {
1165
+ const instrumentations = createInstrumentations(isReadonly, shallow);
1166
+ return (target, key, receiver) => {
1167
+ if (key === "__v_isReactive") return !isReadonly;
1168
+ else if (key === "__v_isReadonly") return isReadonly;
1169
+ else if (key === "__v_raw") return target;
1170
+ return Reflect.get(hasOwn(instrumentations, key) && key in target ? instrumentations : target, key, receiver);
1171
+ };
1172
+ }
1173
+ const mutableCollectionHandlers = { get: /*@__PURE__*/ createInstrumentationGetter(false, false) };
1174
+ const readonlyCollectionHandlers = { get: /*@__PURE__*/ createInstrumentationGetter(true, false) };
1175
+ function checkIdentityKeys(target, has, key) {
1176
+ const rawKey = /* @__PURE__ */ toRaw(key);
1177
+ if (rawKey !== key && has.call(target, rawKey)) {
1178
+ const type = toRawType(target);
1179
+ warn(`Reactive ${type} contains both the raw and reactive versions of the same object${type === `Map` ? ` as keys` : ``}, which can lead to inconsistencies. Avoid differentiating between the raw and reactive versions of an object and only use the reactive version if possible.`);
1180
+ }
1181
+ }
1182
+ //#endregion
1183
+ //#region packages/signal/src/reactive.ts
1184
+ const reactiveMap = /* @__PURE__ */ new WeakMap();
1185
+ const shallowReactiveMap = /* @__PURE__ */ new WeakMap();
1186
+ const readonlyMap = /* @__PURE__ */ new WeakMap();
1187
+ const shallowReadonlyMap = /* @__PURE__ */ new WeakMap();
1188
+ function targetTypeMap(rawType) {
1189
+ switch (rawType) {
1190
+ case "Object":
1191
+ case "Array": return 1;
1192
+ case "Map":
1193
+ case "Set":
1194
+ case "WeakMap":
1195
+ case "WeakSet": return 2;
1196
+ default: return 0;
1197
+ }
1198
+ }
1199
+ function getTargetType(value) {
1200
+ return value["__v_skip"] || !Object.isExtensible(value) ? 0 : targetTypeMap(toRawType(value));
1201
+ }
1202
+ /*@__NO_SIDE_EFFECTS__*/
1203
+ function reactive(target) {
1204
+ if (/* @__PURE__ */ isReadonly(target)) return target;
1205
+ return createReactiveObject(target, false, mutableHandlers, mutableCollectionHandlers, reactiveMap);
1206
+ }
1207
+ /**
1208
+ * Takes an object (reactive or plain) or a ref and returns a readonly proxy to
1209
+ * the original.
1210
+ *
1211
+ * A readonly proxy is deep: any nested property accessed will be readonly as
1212
+ * well. It also has the same ref-unwrapping behavior as {@link reactive},
1213
+ * except the unwrapped values will also be made readonly.
1214
+ *
1215
+ * @example
1216
+ * ```js
1217
+ * const original = reactive({ count: 0 })
1218
+ *
1219
+ * const copy = readonly(original)
1220
+ *
1221
+ * watchEffect(() => {
1222
+ * // works for reactivity tracking
1223
+ * console.log(copy.count)
1224
+ * })
1225
+ *
1226
+ * // mutating original will trigger watchers relying on the copy
1227
+ * original.count++
1228
+ *
1229
+ * // mutating the copy will fail and result in a warning
1230
+ * copy.count++ // warning!
1231
+ * ```
1232
+ *
1233
+ * @param target - The source object.
1234
+ * @see {@link https://vuejs.org/api/reactivity-core.html#readonly}
1235
+ */
1236
+ /*@__NO_SIDE_EFFECTS__*/
1237
+ function readonly(target) {
1238
+ return createReactiveObject(target, true, readonlyHandlers, readonlyCollectionHandlers, readonlyMap);
1239
+ }
1240
+ function createReactiveObject(target, isReadonly, baseHandlers, collectionHandlers, proxyMap) {
1241
+ if (!isObject(target)) {
1242
+ warn(`value cannot be made ${isReadonly ? "readonly" : "reactive"}: ${String(target)}`);
1243
+ return target;
1244
+ }
1245
+ if (target["__v_raw"] && !(isReadonly && target["__v_isReactive"])) return target;
1246
+ const targetType = getTargetType(target);
1247
+ if (targetType === 0) return target;
1248
+ const existingProxy = proxyMap.get(target);
1249
+ if (existingProxy) return existingProxy;
1250
+ const proxy = new Proxy(target, targetType === 2 ? collectionHandlers : baseHandlers);
1251
+ proxyMap.set(target, proxy);
1252
+ return proxy;
1253
+ }
1254
+ /**
1255
+ * Checks if an object is a proxy created by {@link reactive} or
1256
+ * {@link shallowReactive} (or {@link ref} in some cases).
1257
+ *
1258
+ * @example
1259
+ * ```js
1260
+ * isReactive(reactive({})) // => true
1261
+ * isReactive(readonly(reactive({}))) // => true
1262
+ * isReactive(ref({}).value) // => true
1263
+ * isReactive(readonly(ref({})).value) // => true
1264
+ * isReactive(ref(true)) // => false
1265
+ * isReactive(shallowRef({}).value) // => false
1266
+ * isReactive(shallowReactive({})) // => true
1267
+ * ```
1268
+ *
1269
+ * @param value - The value to check.
1270
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isreactive}
1271
+ */
1272
+ /*@__NO_SIDE_EFFECTS__*/
1273
+ function isReactive(value) {
1274
+ if (/* @__PURE__ */ isReadonly(value)) return /* @__PURE__ */ isReactive(value["__v_raw"]);
1275
+ return !!(value && value["__v_isReactive"]);
1276
+ }
1277
+ /**
1278
+ * Checks whether the passed value is a readonly object. The properties of a
1279
+ * readonly object can change, but they can't be assigned directly via the
1280
+ * passed object.
1281
+ *
1282
+ * The proxies created by {@link readonly} and {@link shallowReadonly} are
1283
+ * both considered readonly, as is a computed ref without a set function.
1284
+ *
1285
+ * @param value - The value to check.
1286
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isreadonly}
1287
+ */
1288
+ /*@__NO_SIDE_EFFECTS__*/
1289
+ function isReadonly(value) {
1290
+ return !!(value && value["__v_isReadonly"]);
1291
+ }
1292
+ /*@__NO_SIDE_EFFECTS__*/
1293
+ function isShallow(value) {
1294
+ return !!(value && value["__v_isShallow"]);
1295
+ }
1296
+ /**
1297
+ * Checks if an object is a proxy created by {@link reactive},
1298
+ * {@link readonly}, {@link shallowReactive} or {@link shallowReadonly}.
1299
+ *
1300
+ * @param value - The value to check.
1301
+ * @see {@link https://vuejs.org/api/reactivity-utilities.html#isproxy}
1302
+ */
1303
+ /*@__NO_SIDE_EFFECTS__*/
1304
+ function isProxy(value) {
1305
+ return value ? !!value["__v_raw"] : false;
1306
+ }
1307
+ /**
1308
+ * Returns the raw, original object of a Vue-created proxy.
1309
+ *
1310
+ * `toRaw()` can return the original object from proxies created by
1311
+ * {@link reactive}, {@link readonly}, {@link shallowReactive} or
1312
+ * {@link shallowReadonly}.
1313
+ *
1314
+ * This is an escape hatch that can be used to temporarily read without
1315
+ * incurring proxy access / tracking overhead or write without triggering
1316
+ * changes. It is **not** recommended to hold a persistent reference to the
1317
+ * original object. Use with caution.
1318
+ *
1319
+ * @example
1320
+ * ```js
1321
+ * const foo = {}
1322
+ * const reactiveFoo = reactive(foo)
1323
+ *
1324
+ * console.log(toRaw(reactiveFoo) === foo) // true
1325
+ * ```
1326
+ *
1327
+ * @param observed - The object for which the "raw" value is requested.
1328
+ * @see {@link https://vuejs.org/api/reactivity-advanced.html#toraw}
1329
+ */
1330
+ /*@__NO_SIDE_EFFECTS__*/
1331
+ function toRaw(observed) {
1332
+ const raw = observed && observed["__v_raw"];
1333
+ return raw ? /* @__PURE__ */ toRaw(raw) : observed;
1334
+ }
1335
+ /**
1336
+ * Returns a reactive proxy of the given value (if possible).
1337
+ *
1338
+ * If the given value is not an object, the original value itself is returned.
1339
+ *
1340
+ * @param value - The value for which a reactive proxy shall be created.
1341
+ */
1342
+ const toReactive = (value) => isObject(value) ? /* @__PURE__ */ reactive(value) : value;
1343
+ /**
1344
+ * Returns a readonly proxy of the given value (if possible).
1345
+ *
1346
+ * If the given value is not an object, the original value itself is returned.
1347
+ *
1348
+ * @param value - The value for which a readonly proxy shall be created.
1349
+ */
1350
+ const toReadonly = (value) => isObject(value) ? /* @__PURE__ */ readonly(value) : value;
1351
+ //#endregion
1352
+ //#region packages/signal/src/state.ts
1353
+ function state(value) {
1354
+ if (arguments.length === 0) return /* @__PURE__ */ ref();
1355
+ return isProxyable(value) ? /* @__PURE__ */ reactive(value) : /* @__PURE__ */ ref(value);
1356
+ }
1357
+ function isProxyable(value) {
1358
+ if (value === null || typeof value !== "object") return false;
1359
+ if (Array.isArray(value)) return true;
1360
+ if (value instanceof Map || value instanceof Set || value instanceof WeakMap || value instanceof WeakSet) return true;
1361
+ return isPlainObject(value);
1362
+ }
1363
+ function isPlainObject(value) {
1364
+ const proto = Object.getPrototypeOf(value);
1365
+ return proto === Object.prototype || proto === null;
1366
+ }
1367
+ //#endregion
1368
+ //#region packages/runtime-dom/src/hostContext.ts
1369
+ let currentHostContext;
1370
+ function getCurrentHostContext() {
1371
+ return currentHostContext;
1372
+ }
1373
+ function withHostContext(context, fn) {
1374
+ const previous = currentHostContext;
1375
+ currentHostContext = context;
1376
+ try {
1377
+ return fn();
1378
+ } finally {
1379
+ currentHostContext = previous;
1380
+ }
1381
+ }
1382
+ function captureCurrentHostContext() {
1383
+ return currentHostContext;
1384
+ }
1385
+ function withCapturedHostContext(fn) {
1386
+ const context = captureCurrentHostContext();
1387
+ return ((...args) => {
1388
+ return withHostContext(context, () => fn(...args));
1389
+ });
1390
+ }
1391
+ //#endregion
1392
+ //#region packages/runtime-dom/src/range.ts
1393
+ var DynamicRange = class {
1394
+ constructor(parent, marker) {
1395
+ this.parent = parent;
1396
+ this.marker = marker;
1397
+ this.nodes = [];
1398
+ }
1399
+ replace(value) {
1400
+ this.clear();
1401
+ this.nodes = insertTracked(this.parent, value, this.marker);
1402
+ }
1403
+ clear() {
1404
+ for (const node of this.nodes) {
1405
+ var _node$parentNode;
1406
+ (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 || _node$parentNode.removeChild(node);
1407
+ }
1408
+ this.nodes = [];
1409
+ }
1410
+ current() {
1411
+ return this.nodes;
1412
+ }
1413
+ };
1414
+ function insertTracked(parent, value, marker) {
1415
+ if (value === void 0 || value == null || value === false || value === true) return [];
1416
+ if (Array.isArray(value)) {
1417
+ const nodes = [];
1418
+ for (const item of value) nodes.push(...insertTracked(parent, item, marker));
1419
+ return nodes;
1420
+ }
1421
+ const node = value instanceof Node ? value : document.createTextNode(String(value));
1422
+ parent.insertBefore(node, marker);
1423
+ return [node];
1424
+ }
1425
+ function removeNodes$1(nodes) {
1426
+ for (const node of nodes) {
1427
+ var _node$parentNode2;
1428
+ (_node$parentNode2 = node.parentNode) === null || _node$parentNode2 === void 0 || _node$parentNode2.removeChild(node);
1429
+ }
1430
+ }
1431
+ function moveRangeBefore(nodes, parent, marker) {
1432
+ for (const node of nodes) parent.insertBefore(node, marker);
1433
+ }
1434
+ //#endregion
1435
+ //#region packages/runtime-dom/src/insert.ts
1436
+ function insert(parent, value, marker = null) {
1437
+ if (value === void 0) {
1438
+ console.warn("[Zeus runtime] insert received `undefined`, which is ignored. Use `null` or a fallback value explicitly if you want to suppress this warning.");
1439
+ return;
1440
+ }
1441
+ insertTracked(parent, value, marker);
1442
+ }
1443
+ function mountDynamic(parent, marker, value) {
1444
+ const range = new DynamicRange(parent, marker);
1445
+ const hostContext = captureCurrentHostContext();
1446
+ const owner = getCurrentOwner();
1447
+ const runner = effect(() => {
1448
+ const next = runWithOwner(owner, () => withHostContext(hostContext, value));
1449
+ range.replace(next);
1450
+ });
1451
+ onScopeDispose(() => {
1452
+ stop(runner);
1453
+ range.clear();
1454
+ }, true);
1455
+ }
1456
+ //#endregion
1457
+ //#region packages/runtime-dom/src/context.ts
1458
+ let currentOwner;
1459
+ function getCurrentOwner() {
1460
+ return currentOwner;
1461
+ }
1462
+ function createOwner(parent = currentOwner) {
1463
+ return {
1464
+ parent,
1465
+ provides: /* @__PURE__ */ new Map()
1466
+ };
1467
+ }
1468
+ function runWithOwner(owner, fn) {
1469
+ const previous = currentOwner;
1470
+ currentOwner = owner;
1471
+ try {
1472
+ return fn();
1473
+ } finally {
1474
+ currentOwner = previous;
1475
+ }
1476
+ }
1477
+ function createContext(defaultValue) {
1478
+ const hasDefaultValue = arguments.length > 0;
1479
+ const context = {
1480
+ id: Symbol("ZeusContext"),
1481
+ defaultValue,
1482
+ hasDefaultValue,
1483
+ Provider(props) {
1484
+ const owner = createOwner(currentOwner);
1485
+ owner.provides.set(context.id, props.value);
1486
+ return runWithOwner(owner, () => {
1487
+ const children = resolveValue$3(props.children);
1488
+ if (props.bridge) return createDOMContextBoundary(context, props.value, children);
1489
+ return children;
1490
+ });
1491
+ },
1492
+ Bridge(props) {
1493
+ return createDOMContextBoundary(context, props.value, resolveValue$3(props.children));
1494
+ }
1495
+ };
1496
+ return context;
1497
+ }
1498
+ function provide(context, value) {
1499
+ const owner = currentOwner;
1500
+ if (!owner) {
1501
+ console.warn("[Zeus context] provide() was called without an active component owner.");
1502
+ return;
1503
+ }
1504
+ owner.provides.set(context.id, value);
1505
+ }
1506
+ function inject(context, fallback) {
1507
+ let owner = currentOwner;
1508
+ while (owner) {
1509
+ if (owner.provides.has(context.id)) return owner.provides.get(context.id);
1510
+ owner = owner.parent;
1511
+ }
1512
+ if (arguments.length >= 2) return fallback;
1513
+ if (context.hasDefaultValue) return context.defaultValue;
1514
+ throw new Error(`[Zeus context] No provider found for context.`);
1515
+ }
1516
+ function useContext(context, fallback) {
1517
+ if (arguments.length >= 2) return inject(context, fallback);
1518
+ return inject(context);
1519
+ }
1520
+ const ZEUS_CONTEXT_REQUEST = "zeus:context-request";
1521
+ /**
1522
+ * Creates a transparent DOM element that acts as a context boundary.
1523
+ * Native custom elements inside it can use `requestDOMContext` to receive
1524
+ * context values via the DOM event protocol.
1525
+ */
1526
+ function createDOMContextBoundary(context, value, children) {
1527
+ const boundary = document.createElement("zeus-context");
1528
+ boundary.style.cssText = "display:contents;position:unset;width:0;height:0;overflow:hidden";
1529
+ provideDOMContext(boundary, context, value);
1530
+ insert(boundary, children);
1531
+ return boundary;
1532
+ }
1533
+ /**
1534
+ * Registers a context value on a DOM target so that any descendant custom
1535
+ * element can pick it up via `requestDOMContext`.
1536
+ */
1537
+ function provideDOMContext(target, context, value) {
1538
+ const handler = (event) => {
1539
+ const request = event;
1540
+ if (request.type !== "zeus:context-request") return;
1541
+ if (request.detail.id !== context.id) return;
1542
+ request.stopPropagation();
1543
+ request.detail.resolve(value);
1544
+ };
1545
+ target.addEventListener(ZEUS_CONTEXT_REQUEST, handler);
1546
+ onScopeDispose(() => {
1547
+ target.removeEventListener(ZEUS_CONTEXT_REQUEST, handler);
1548
+ }, true);
1549
+ }
1550
+ /**
1551
+ * Internal precise DOM context resolver.
1552
+ *
1553
+ * Unlike requestDOMContext(), this can distinguish:
1554
+ * - found: false, value: undefined
1555
+ * - found: true, value: undefined
1556
+ */
1557
+ function resolveDOMContext(host, context) {
1558
+ let found = false;
1559
+ let value;
1560
+ const event = new CustomEvent(ZEUS_CONTEXT_REQUEST, {
1561
+ bubbles: true,
1562
+ composed: true,
1563
+ cancelable: true,
1564
+ detail: {
1565
+ id: context.id,
1566
+ resolved: false,
1567
+ value: void 0,
1568
+ resolve(nextValue) {
1569
+ found = true;
1570
+ value = nextValue;
1571
+ this.resolved = true;
1572
+ this.value = nextValue;
1573
+ }
1574
+ }
1575
+ });
1576
+ host.dispatchEvent(event);
1577
+ return {
1578
+ found,
1579
+ value
1580
+ };
1581
+ }
1582
+ /**
1583
+ * Public compatibility API.
1584
+ *
1585
+ * Returns the resolved value if found, otherwise undefined.
1586
+ * If you need to distinguish "not found" from "found undefined",
1587
+ * use resolveDOMContext().
1588
+ */
1589
+ function requestDOMContext(host, context) {
1590
+ return resolveDOMContext(host, context).value;
1591
+ }
1592
+ function resolveValue$3(value) {
1593
+ return typeof value === "function" ? value() : value !== null && value !== void 0 ? value : null;
1594
+ }
1595
+ //#endregion
1596
+ //#region packages/runtime-dom/src/devtools.ts
1597
+ function emitDevtoolsEvent(event) {
1598
+ var _window$__ZEUS_DEVTOO;
1599
+ if (typeof window === "undefined") return;
1600
+ (_window$__ZEUS_DEVTOO = window.__ZEUS_DEVTOOLS_HOOK__) === null || _window$__ZEUS_DEVTOO === void 0 || _window$__ZEUS_DEVTOO.emit(event);
1601
+ }
1602
+ //#endregion
1603
+ //#region packages/runtime-dom/src/render.ts
1604
+ function render(value, container, options = {}) {
1605
+ var _options$owner;
1606
+ const renderScope = effectScope();
1607
+ const owner = (_options$owner = options.owner) !== null && _options$owner !== void 0 ? _options$owner : createOwner();
1608
+ renderScope.run(() => {
1609
+ container.textContent = "";
1610
+ runWithOwner(owner, () => {
1611
+ insert(container, resolveValue$2(value));
1612
+ });
1613
+ });
1614
+ emitDevtoolsEvent({
1615
+ type: "render",
1616
+ target: container
1617
+ });
1618
+ let disposed = false;
1619
+ return () => {
1620
+ if (disposed) return;
1621
+ disposed = true;
1622
+ renderScope.stop();
1623
+ container.textContent = "";
1624
+ };
1625
+ }
1626
+ function resolveValue$2(value) {
1627
+ return typeof value === "function" ? value() : value !== null && value !== void 0 ? value : null;
1628
+ }
1629
+ //#endregion
1630
+ //#region packages/runtime-dom/src/dom.ts
1631
+ function marker(parent, index) {
1632
+ let seen = 0;
1633
+ for (const node of parent.childNodes) {
1634
+ if (node.nodeType !== Node.COMMENT_NODE) continue;
1635
+ const comment = node;
1636
+ if (comment.data !== "" && comment.data !== "!") continue;
1637
+ if (seen === index) return comment;
1638
+ seen++;
1639
+ }
1640
+ throw new Error(`[Zeus runtime] marker ${index} not found`);
1641
+ }
1642
+ function child(parent, index) {
1643
+ const node = parent.childNodes.item(index);
1644
+ if (!node) throw new Error(`[Zeus runtime] child ${index} not found`);
1645
+ return node;
1646
+ }
1647
+ function removeNodes(nodes) {
1648
+ for (const node of nodes) {
1649
+ var _node$parentNode;
1650
+ (_node$parentNode = node.parentNode) === null || _node$parentNode === void 0 || _node$parentNode.removeChild(node);
1651
+ }
1652
+ }
1653
+ //#endregion
1654
+ //#region packages/runtime-dom/src/bindings.ts
1655
+ function bindText(node, value) {
1656
+ effect(() => {
1657
+ node.data = stringifyText(value());
1658
+ });
1659
+ }
1660
+ function bindTextContent(el, value) {
1661
+ effect(() => {
1662
+ el.textContent = stringifyText(value());
1663
+ });
1664
+ }
1665
+ function stringifyText(value) {
1666
+ if (Array.isArray(value)) return value.map(stringifyText).join("");
1667
+ if (value == null || value === false || value === true) return "";
1668
+ if (typeof Node !== "undefined" && value instanceof Node) {
1669
+ var _value$textContent;
1670
+ return (_value$textContent = value.textContent) !== null && _value$textContent !== void 0 ? _value$textContent : "";
1671
+ }
1672
+ return String(value);
1673
+ }
1674
+ function setAttr(el, name, value) {
1675
+ if (value == null || value === false) {
1676
+ el.removeAttribute(normalizeAttrName(name));
1677
+ return;
1678
+ }
1679
+ const attrName = normalizeAttrName(name);
1680
+ if (value === true) {
1681
+ el.setAttribute(attrName, "");
1682
+ return;
1683
+ }
1684
+ el.setAttribute(attrName, String(value));
1685
+ }
1686
+ function normalizeAttrName(name) {
1687
+ return name === "className" ? "class" : name;
1688
+ }
1689
+ function bindAttr(el, name, value) {
1690
+ effect(() => {
1691
+ setAttr(el, name, value());
1692
+ });
1693
+ }
1694
+ function bindProp(el, name, value) {
1695
+ effect(() => {
1696
+ el[name] = value();
1697
+ });
1698
+ }
1699
+ function bindClass(el, value) {
1700
+ effect(() => {
1701
+ const next = normalizeClass(value());
1702
+ if (next) el.setAttribute("class", next);
1703
+ else el.removeAttribute("class");
1704
+ });
1705
+ }
1706
+ function normalizeClass(value) {
1707
+ if (!value) return "";
1708
+ if (typeof value === "string") return value;
1709
+ if (Array.isArray(value)) return value.map(normalizeClass).filter(Boolean).join(" ");
1710
+ if (typeof value === "object") return Object.keys(value).filter((key) => value[key]).join(" ");
1711
+ return "";
1712
+ }
1713
+ function bindStyle(el, value) {
1714
+ let prev;
1715
+ effect(() => {
1716
+ const next = value();
1717
+ if (next == null) {
1718
+ el.removeAttribute("style");
1719
+ prev = void 0;
1720
+ return;
1721
+ }
1722
+ if (typeof next === "string") {
1723
+ el.setAttribute("style", next);
1724
+ prev = void 0;
1725
+ return;
1726
+ }
1727
+ patchStyle(el, prev, next);
1728
+ prev = next;
1729
+ });
1730
+ }
1731
+ function patchStyle(el, prev, next) {
1732
+ const style = el.style;
1733
+ if (prev) {
1734
+ for (const key in prev) if (!(key in next)) style.setProperty(toKebabCase$1(key), "");
1735
+ }
1736
+ for (const key in next) {
1737
+ const value = next[key];
1738
+ const name = toKebabCase$1(key);
1739
+ if (value == null) style.setProperty(name, "");
1740
+ else style.setProperty(name, normalizeStyleValue(key, value));
1741
+ }
1742
+ }
1743
+ function normalizeStyleValue(key, value) {
1744
+ if (typeof value === "number" && value !== 0 && !isUnitlessNumber(key)) return `${value}px`;
1745
+ return String(value);
1746
+ }
1747
+ const unitlessNumbers = new Set([
1748
+ "opacity",
1749
+ "zIndex",
1750
+ "fontWeight",
1751
+ "lineHeight",
1752
+ "flex",
1753
+ "flexGrow",
1754
+ "flexShrink",
1755
+ "order"
1756
+ ]);
1757
+ function isUnitlessNumber(key) {
1758
+ return unitlessNumbers.has(key);
1759
+ }
1760
+ function toKebabCase$1(value) {
1761
+ return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
1762
+ }
1763
+ //#endregion
1764
+ //#region packages/runtime-dom/src/events.ts
1765
+ const delegatedEvents = /* @__PURE__ */ new Set();
1766
+ const delegatedListeners = [];
1767
+ const nonBubblingEventMap = {
1768
+ focus: "focusin",
1769
+ blur: "focusout"
1770
+ };
1771
+ function bindEvent(el, name, handler) {
1772
+ const target = el;
1773
+ const events = target.__zeusEvents || (target.__zeusEvents = {});
1774
+ events[name] = handler;
1775
+ onScopeDispose(() => {
1776
+ var _target$__zeusEvents;
1777
+ if (((_target$__zeusEvents = target.__zeusEvents) === null || _target$__zeusEvents === void 0 ? void 0 : _target$__zeusEvents[name]) === handler) delete target.__zeusEvents[name];
1778
+ }, true);
1779
+ }
1780
+ function delegateEvents(events) {
1781
+ for (const event of events) {
1782
+ const delegatedName = normalizeDelegatedEventName(event);
1783
+ if (delegatedEvents.has(delegatedName)) continue;
1784
+ delegatedEvents.add(delegatedName);
1785
+ const handler = dispatchDelegatedEvent;
1786
+ delegatedListeners.push(delegatedName);
1787
+ document.addEventListener(delegatedName, handler);
1788
+ emitDevtoolsEvent({
1789
+ type: "delegate-event",
1790
+ event: delegatedName
1791
+ });
1792
+ }
1793
+ }
1794
+ function normalizeDelegatedEventName(name) {
1795
+ var _nonBubblingEventMap$;
1796
+ return (_nonBubblingEventMap$ = nonBubblingEventMap[name]) !== null && _nonBubblingEventMap$ !== void 0 ? _nonBubblingEventMap$ : name;
1797
+ }
1798
+ function normalizeOriginalEventName(name) {
1799
+ if (name === "focusin") return "focus";
1800
+ if (name === "focusout") return "blur";
1801
+ return name;
1802
+ }
1803
+ function dispatchDelegatedEvent(event) {
1804
+ const eventName = normalizeOriginalEventName(event.type);
1805
+ let node = event.target;
1806
+ while (node && node !== document) {
1807
+ if (node.nodeType === Node.ELEMENT_NODE) {
1808
+ var _el$__zeusEvents;
1809
+ const el = node;
1810
+ const handler = (_el$__zeusEvents = el.__zeusEvents) === null || _el$__zeusEvents === void 0 ? void 0 : _el$__zeusEvents[eventName];
1811
+ if (handler) {
1812
+ callDelegatedHandler(el, handler, event);
1813
+ if (event.cancelBubble) return;
1814
+ }
1815
+ }
1816
+ node = node.parentNode;
1817
+ }
1818
+ }
1819
+ function callDelegatedHandler(el, handler, event) {
1820
+ const previousCurrentTarget = Object.prototype.hasOwnProperty.call(event, "currentTarget") ? Object.getOwnPropertyDescriptor(event, "currentTarget") : void 0;
1821
+ try {
1822
+ Object.defineProperty(event, "currentTarget", {
1823
+ configurable: true,
1824
+ get() {
1825
+ return el;
1826
+ }
1827
+ });
1828
+ } catch (_unused) {}
1829
+ try {
1830
+ handler.call(el, event);
1831
+ } finally {
1832
+ try {
1833
+ if (previousCurrentTarget) Object.defineProperty(event, "currentTarget", previousCurrentTarget);
1834
+ else delete event.currentTarget;
1835
+ } catch (_unused2) {}
1836
+ }
1837
+ }
1838
+ //#endregion
1839
+ //#region packages/runtime-dom/src/refs.ts
1840
+ function setRef(target, value) {
1841
+ if (target == null) return;
1842
+ if (typeof target === "function") {
1843
+ target(value);
1844
+ return;
1845
+ }
1846
+ if ("value" in target) {
1847
+ target.value = value;
1848
+ return;
1849
+ }
1850
+ if ("current" in target) {
1851
+ target.current = value;
1852
+ return;
1853
+ }
1854
+ console.warn("[Zeus runtime] Invalid ref target:", target);
1855
+ }
1856
+ function bindRef(el, target) {
1857
+ setRef(target, el);
1858
+ if (getCurrentScope()) onScopeDispose(() => {
1859
+ setRef(target, null);
1860
+ }, true);
1861
+ }
1862
+ //#endregion
1863
+ //#region packages/runtime-dom/src/component.ts
1864
+ function createComponent(component, props) {
1865
+ return runWithOwner(createOwner(), () => component(props));
1866
+ }
1867
+ //#endregion
1868
+ //#region packages/runtime-dom/src/list.ts
1869
+ function mountFor$1(parent, marker, each, key, render) {
1870
+ if (!key) {
1871
+ mountIndexFor(parent, marker, each, render);
1872
+ return;
1873
+ }
1874
+ mountKeyedFor(parent, marker, each, key, render);
1875
+ }
1876
+ function mountIndexFor(parent, marker, each, render) {
1877
+ let current = [];
1878
+ const owner = getCurrentOwner();
1879
+ const runner = effect(() => {
1880
+ var _each;
1881
+ removeNodes$1(current);
1882
+ current = [];
1883
+ const list = (_each = each()) !== null && _each !== void 0 ? _each : [];
1884
+ for (let i = 0; i < list.length; i++) current.push(...insertTracked(parent, runWithOwner(owner, () => render(list[i], i)), marker));
1885
+ });
1886
+ onScopeDispose(() => {
1887
+ stop(runner);
1888
+ removeNodes$1(current);
1889
+ current = [];
1890
+ }, true);
1891
+ }
1892
+ function mountKeyedFor(parent, marker, each, key, render) {
1893
+ let records = [];
1894
+ const owner = getCurrentOwner();
1895
+ const runner = effect(() => {
1896
+ var _each2;
1897
+ const nextItems = (_each2 = each()) !== null && _each2 !== void 0 ? _each2 : [];
1898
+ const oldMap = /* @__PURE__ */ new Map();
1899
+ for (const record of records) oldMap.set(record.key, record);
1900
+ const nextRecords = [];
1901
+ for (let i = 0; i < nextItems.length; i++) {
1902
+ const item = nextItems[i];
1903
+ const itemKey = key(item, i);
1904
+ const oldRecord = oldMap.get(itemKey);
1905
+ if (oldRecord) {
1906
+ oldMap.delete(itemKey);
1907
+ oldRecord.item = item;
1908
+ oldRecord.index = i;
1909
+ nextRecords.push(oldRecord);
1910
+ } else nextRecords.push({
1911
+ key: itemKey,
1912
+ item,
1913
+ index: i,
1914
+ nodes: insertTracked(parent, runWithOwner(owner, () => render(item, i)), marker)
1915
+ });
1916
+ }
1917
+ for (const record of oldMap.values()) removeNodes$1(record.nodes);
1918
+ for (let i = nextRecords.length - 1; i >= 0; i--) {
1919
+ var _nextRecords$nodes$;
1920
+ const record = nextRecords[i];
1921
+ const anchor = i === nextRecords.length - 1 ? marker : (_nextRecords$nodes$ = nextRecords[i + 1].nodes[0]) !== null && _nextRecords$nodes$ !== void 0 ? _nextRecords$nodes$ : marker;
1922
+ moveRangeBefore(record.nodes, parent, anchor);
1923
+ }
1924
+ emitDevtoolsEvent({
1925
+ type: "mount-for",
1926
+ length: records.length
1927
+ });
1928
+ records = nextRecords;
1929
+ });
1930
+ onScopeDispose(() => {
1931
+ stop(runner);
1932
+ for (const record of records) removeNodes$1(record.nodes);
1933
+ records = [];
1934
+ }, true);
1935
+ }
1936
+ //#endregion
1937
+ //#region packages/runtime-dom/src/controlFlow.ts
1938
+ function Show(props) {
1939
+ return resolveValue(props.when ? props.children : props.fallback);
1940
+ }
1941
+ function resolveValue(value) {
1942
+ if (typeof value === "function") return value();
1943
+ return value !== null && value !== void 0 ? value : null;
1944
+ }
1945
+ function mountShow(parent, marker, when, children, fallback) {
1946
+ mountDynamic(parent, marker, () => when() ? children() : fallback ? fallback() : null);
1947
+ }
1948
+ function For(props) {
1949
+ var _props$each$map, _props$each;
1950
+ return (_props$each$map = (_props$each = props.each) === null || _props$each === void 0 ? void 0 : _props$each.map((item, index) => props.children(item, index))) !== null && _props$each$map !== void 0 ? _props$each$map : null;
1951
+ }
1952
+ function mountFor(parent, marker, each, key, render) {
1953
+ mountFor$1(parent, marker, each, key, render);
1954
+ }
1955
+ //#endregion
1956
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/typeof.js
1957
+ function _typeof(o) {
1958
+ "@babel/helpers - typeof";
1959
+ return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function(o) {
1960
+ return typeof o;
1961
+ } : function(o) {
1962
+ return o && "function" == typeof Symbol && o.constructor === Symbol && o !== Symbol.prototype ? "symbol" : typeof o;
1963
+ }, _typeof(o);
1964
+ }
1965
+ //#endregion
1966
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPrimitive.js
1967
+ function toPrimitive(t, r) {
1968
+ if ("object" != _typeof(t) || !t) return t;
1969
+ var e = t[Symbol.toPrimitive];
1970
+ if (void 0 !== e) {
1971
+ var i = e.call(t, r || "default");
1972
+ if ("object" != _typeof(i)) return i;
1973
+ throw new TypeError("@@toPrimitive must return a primitive value.");
1974
+ }
1975
+ return ("string" === r ? String : Number)(t);
1976
+ }
1977
+ //#endregion
1978
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/toPropertyKey.js
1979
+ function toPropertyKey(t) {
1980
+ var i = toPrimitive(t, "string");
1981
+ return "symbol" == _typeof(i) ? i : i + "";
1982
+ }
1983
+ //#endregion
1984
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/defineProperty.js
1985
+ function _defineProperty(e, r, t) {
1986
+ return (r = toPropertyKey(r)) in e ? Object.defineProperty(e, r, {
1987
+ value: t,
1988
+ enumerable: !0,
1989
+ configurable: !0,
1990
+ writable: !0
1991
+ }) : e[r] = t, e;
1992
+ }
1993
+ //#endregion
1994
+ //#region \0@oxc-project+runtime@0.133.0/helpers/esm/objectSpread2.js
1995
+ function ownKeys(e, r) {
1996
+ var t = Object.keys(e);
1997
+ if (Object.getOwnPropertySymbols) {
1998
+ var o = Object.getOwnPropertySymbols(e);
1999
+ r && (o = o.filter(function(r) {
2000
+ return Object.getOwnPropertyDescriptor(e, r).enumerable;
2001
+ })), t.push.apply(t, o);
2002
+ }
2003
+ return t;
2004
+ }
2005
+ function _objectSpread2(e) {
2006
+ for (var r = 1; r < arguments.length; r++) {
2007
+ var t = null != arguments[r] ? arguments[r] : {};
2008
+ r % 2 ? ownKeys(Object(t), !0).forEach(function(r) {
2009
+ _defineProperty(e, r, t[r]);
2010
+ }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function(r) {
2011
+ Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r));
2012
+ });
2013
+ }
2014
+ return e;
2015
+ }
2016
+ //#endregion
2017
+ //#region packages/runtime-dom/src/defineElement.ts
2018
+ function defineElement(tagName, options, setup) {
2019
+ var _options$props;
2020
+ const propDefs = normalizePropDefinitions((_options$props = options.props) !== null && _options$props !== void 0 ? _options$props : {});
2021
+ const observedAttributes = propDefs.filter((def) => def.attr !== false).map((def) => def.attr);
2022
+ class ZeusElement extends HTMLElement {
2023
+ static get observedAttributes() {
2024
+ return observedAttributes;
2025
+ }
2026
+ constructor() {
2027
+ super();
2028
+ this.props = state({});
2029
+ this.lightChildren = [];
2030
+ this.capturedLightChildren = false;
2031
+ this.reflecting = false;
2032
+ applyPropDefaults(this.props, propDefs);
2033
+ definePropAccessors(this, this.props, propDefs);
2034
+ }
2035
+ connectedCallback() {
2036
+ var _options$shadow, _options$consumes;
2037
+ if (this.dispose) return;
2038
+ const shadow = (_options$shadow = options.shadow) !== null && _options$shadow !== void 0 ? _options$shadow : false;
2039
+ const mode = shadow ? "shadow" : "light";
2040
+ if (mode === "light" && !this.capturedLightChildren) {
2041
+ this.lightChildren = Array.from(this.childNodes);
2042
+ this.capturedLightChildren = true;
2043
+ }
2044
+ this.syncAttributesToProps(propDefs);
2045
+ const owner = createOwner();
2046
+ for (const context of (_options$consumes = options.consumes) !== null && _options$consumes !== void 0 ? _options$consumes : []) {
2047
+ const resolved = resolveDOMContext(this, context);
2048
+ if (resolved.found) owner.provides.set(context.id, resolved.value);
2049
+ else if (context.hasDefaultValue) owner.provides.set(context.id, context.defaultValue);
2050
+ }
2051
+ const target = this.resolveRenderTarget(shadow);
2052
+ const hostContext = {
2053
+ host: this,
2054
+ mode,
2055
+ lightChildren: this.lightChildren
2056
+ };
2057
+ const setupContext = {
2058
+ host: this,
2059
+ emit: (name, detail, eventOptions) => {
2060
+ return this.dispatchEvent(new CustomEvent(name, _objectSpread2(_objectSpread2({
2061
+ bubbles: true,
2062
+ composed: true,
2063
+ cancelable: true
2064
+ }, eventOptions), {}, { detail })));
2065
+ }
2066
+ };
2067
+ this.dispose = render(() => runWithOwner(owner, () => withHostContext(hostContext, () => setup(this.props, setupContext))), target, { owner });
2068
+ mountStyles(target, options.styles);
2069
+ onScopeDispose(() => {
2070
+ var _this$dispose;
2071
+ (_this$dispose = this.dispose) === null || _this$dispose === void 0 || _this$dispose.call(this);
2072
+ this.dispose = void 0;
2073
+ }, true);
2074
+ }
2075
+ disconnectedCallback() {
2076
+ var _this$dispose2;
2077
+ (_this$dispose2 = this.dispose) === null || _this$dispose2 === void 0 || _this$dispose2.call(this);
2078
+ this.dispose = void 0;
2079
+ }
2080
+ attributeChangedCallback(name, oldValue, newValue) {
2081
+ if (oldValue === newValue || this.reflecting) return;
2082
+ const def = propDefs.find((item) => item.attr === name);
2083
+ if (!def) return;
2084
+ this.props[def.key] = castAttributeValue(newValue, def);
2085
+ }
2086
+ resolveRenderTarget(shadow) {
2087
+ if (this.target) return this.target;
2088
+ if (!shadow) {
2089
+ this.target = this;
2090
+ return this.target;
2091
+ }
2092
+ this.target = this.attachShadow(typeof shadow === "object" ? shadow : { mode: "open" });
2093
+ return this.target;
2094
+ }
2095
+ syncAttributesToProps(defs) {
2096
+ for (const def of defs) {
2097
+ if (def.attr === false) continue;
2098
+ const value = this.getAttribute(def.attr);
2099
+ if (value !== null || def.type === Boolean) this.props[def.key] = castAttributeValue(value, def);
2100
+ }
2101
+ }
2102
+ _writePropFromProperty(key, value) {
2103
+ const def = propDefs.find((item) => item.key === key);
2104
+ this.props[key] = value;
2105
+ if ((def === null || def === void 0 ? void 0 : def.reflect) && def.attr !== false) {
2106
+ this.reflecting = true;
2107
+ try {
2108
+ reflectPropToAttribute(this, def, value);
2109
+ } finally {
2110
+ this.reflecting = false;
2111
+ }
2112
+ }
2113
+ }
2114
+ }
2115
+ if (!customElements.get(tagName)) customElements.define(tagName, ZeusElement);
2116
+ return ZeusElement;
2117
+ }
2118
+ function normalizePropDefinitions(props) {
2119
+ return Object.keys(props).map((key) => {
2120
+ const input = props[key];
2121
+ if (typeof input === "function") return {
2122
+ key,
2123
+ attr: toKebabCase(key),
2124
+ type: input,
2125
+ reflect: false
2126
+ };
2127
+ return {
2128
+ key,
2129
+ attr: (input === null || input === void 0 ? void 0 : input.attr) === void 0 ? toKebabCase(key) : input.attr,
2130
+ type: input === null || input === void 0 ? void 0 : input.type,
2131
+ reflect: Boolean(input === null || input === void 0 ? void 0 : input.reflect),
2132
+ default: input === null || input === void 0 ? void 0 : input.default
2133
+ };
2134
+ });
2135
+ }
2136
+ function applyPropDefaults(props, defs) {
2137
+ for (const def of defs) {
2138
+ if (!("default" in def)) continue;
2139
+ const value = typeof def.default === "function" ? def.default() : def.default;
2140
+ props[def.key] = value;
2141
+ }
2142
+ }
2143
+ function definePropAccessors(element, props, defs) {
2144
+ for (const def of defs) {
2145
+ if (def.key in element) continue;
2146
+ Object.defineProperty(element, def.key, {
2147
+ configurable: true,
2148
+ enumerable: true,
2149
+ get() {
2150
+ return props[def.key];
2151
+ },
2152
+ set(value) {
2153
+ element._writePropFromProperty(def.key, value);
2154
+ }
2155
+ });
2156
+ }
2157
+ }
2158
+ function castAttributeValue(value, def) {
2159
+ if (def.type === Boolean) return value !== null;
2160
+ if (value === null) return;
2161
+ if (def.type === Number) return Number(value);
2162
+ if (def.type === Object || def.type === Array) try {
2163
+ return JSON.parse(value);
2164
+ } catch (_unused) {
2165
+ console.warn(`[Zeus custom-element] Failed to parse JSON attribute "${def.attr}".`);
2166
+ return def.type === Array ? [] : {};
2167
+ }
2168
+ return value;
2169
+ }
2170
+ function reflectPropToAttribute(element, def, value) {
2171
+ if (def.attr === false) return;
2172
+ if (def.type === Boolean) {
2173
+ if (value) element.setAttribute(def.attr, "");
2174
+ else element.removeAttribute(def.attr);
2175
+ return;
2176
+ }
2177
+ if (value == null) {
2178
+ element.removeAttribute(def.attr);
2179
+ return;
2180
+ }
2181
+ if (def.type === Object || def.type === Array) {
2182
+ element.setAttribute(def.attr, JSON.stringify(value));
2183
+ return;
2184
+ }
2185
+ element.setAttribute(def.attr, String(value));
2186
+ }
2187
+ function mountStyles(target, styles) {
2188
+ if (!styles) return;
2189
+ const list = Array.isArray(styles) ? styles : [styles];
2190
+ for (const css of list) {
2191
+ const style = document.createElement("style");
2192
+ style.textContent = css;
2193
+ target.appendChild(style);
2194
+ }
2195
+ }
2196
+ function toKebabCase(value) {
2197
+ return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
2198
+ }
2199
+ //#endregion
2200
+ //#region packages/runtime-dom/src/slot.ts
2201
+ function createSlot(name, fallback) {
2202
+ const context = getCurrentHostContext();
2203
+ if (!context) return createNativeSlot(name, fallback);
2204
+ if (context.mode === "shadow") return createNativeSlot(name, fallback);
2205
+ const assigned = findLightSlotNodes(context.lightChildren, name);
2206
+ if (assigned.length > 0) return Array.from(assigned);
2207
+ return fallback ? fallback() : null;
2208
+ }
2209
+ function createNativeSlot(name, fallback) {
2210
+ const slot = document.createElement("slot");
2211
+ if (name) slot.setAttribute("name", name);
2212
+ const fallbackValue = fallback === null || fallback === void 0 ? void 0 : fallback();
2213
+ if (fallbackValue != null) insert(slot, fallbackValue);
2214
+ return slot;
2215
+ }
2216
+ function findLightSlotNodes(nodes, name) {
2217
+ if (name) return nodes.filter((node) => {
2218
+ if (node.nodeType !== Node.ELEMENT_NODE) return false;
2219
+ return node.getAttribute("slot") === name;
2220
+ });
2221
+ return nodes.filter((node) => {
2222
+ if (node.nodeType === Node.ELEMENT_NODE) return !node.hasAttribute("slot");
2223
+ return isMeaningfulTextNode(node);
2224
+ });
2225
+ }
2226
+ function isMeaningfulTextNode(node) {
2227
+ var _node$textContent;
2228
+ if (node.nodeType !== Node.TEXT_NODE) return false;
2229
+ return Boolean((_node$textContent = node.textContent) === null || _node$textContent === void 0 ? void 0 : _node$textContent.trim());
2230
+ }
2231
+ //#endregion
2232
+ //#region packages/runtime-dom/src/webComponents.ts
2233
+ function Host(props) {
2234
+ return resolveValue$1(props.children);
2235
+ }
2236
+ function Slot(props) {
2237
+ return createSlot(props.name, () => resolveValue$1(props.children));
2238
+ }
2239
+ function resolveValue$1(value) {
2240
+ return typeof value === "function" ? value() : value;
2241
+ }
2242
+ //#endregion
2243
+ export { For, Host, Show, Slot, ZEUS_CONTEXT_REQUEST, bindAttr, bindClass, bindEvent, bindProp, bindRef, bindStyle, bindText, bindTextContent, captureCurrentHostContext, child, createComponent, createContext, createDOMContextBoundary, createOwner, createSlot, defineElement, delegateEvents, getCurrentHostContext, getCurrentOwner, inject, insert, marker, mountDynamic, mountFor, mountShow, normalizeClass, provide, provideDOMContext, removeNodes, render, requestDOMContext, resolveDOMContext, resolveValue, runWithOwner, setAttr, setRef, template, useContext, withCapturedHostContext, withHostContext };