@fictjs/runtime 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.
Files changed (51) hide show
  1. package/README.md +17 -0
  2. package/dist/index.cjs +4224 -0
  3. package/dist/index.cjs.map +1 -0
  4. package/dist/index.d.cts +1572 -0
  5. package/dist/index.d.ts +1572 -0
  6. package/dist/index.dev.js +4240 -0
  7. package/dist/index.dev.js.map +1 -0
  8. package/dist/index.js +4133 -0
  9. package/dist/index.js.map +1 -0
  10. package/dist/jsx-dev-runtime.cjs +44 -0
  11. package/dist/jsx-dev-runtime.cjs.map +1 -0
  12. package/dist/jsx-dev-runtime.js +14 -0
  13. package/dist/jsx-dev-runtime.js.map +1 -0
  14. package/dist/jsx-runtime.cjs +44 -0
  15. package/dist/jsx-runtime.cjs.map +1 -0
  16. package/dist/jsx-runtime.js +14 -0
  17. package/dist/jsx-runtime.js.map +1 -0
  18. package/dist/slim.cjs +3384 -0
  19. package/dist/slim.cjs.map +1 -0
  20. package/dist/slim.d.cts +475 -0
  21. package/dist/slim.d.ts +475 -0
  22. package/dist/slim.js +3335 -0
  23. package/dist/slim.js.map +1 -0
  24. package/package.json +68 -0
  25. package/src/binding.ts +2127 -0
  26. package/src/constants.ts +456 -0
  27. package/src/cycle-guard.ts +134 -0
  28. package/src/devtools.ts +17 -0
  29. package/src/dom.ts +683 -0
  30. package/src/effect.ts +83 -0
  31. package/src/error-boundary.ts +118 -0
  32. package/src/hooks.ts +72 -0
  33. package/src/index.ts +184 -0
  34. package/src/jsx-dev-runtime.ts +2 -0
  35. package/src/jsx-runtime.ts +2 -0
  36. package/src/jsx.ts +786 -0
  37. package/src/lifecycle.ts +273 -0
  38. package/src/list-helpers.ts +619 -0
  39. package/src/memo.ts +14 -0
  40. package/src/node-ops.ts +185 -0
  41. package/src/props.ts +212 -0
  42. package/src/reconcile.ts +151 -0
  43. package/src/ref.ts +25 -0
  44. package/src/scheduler.ts +12 -0
  45. package/src/signal.ts +1278 -0
  46. package/src/slim.ts +68 -0
  47. package/src/store.ts +210 -0
  48. package/src/suspense.ts +187 -0
  49. package/src/transition.ts +128 -0
  50. package/src/types.ts +172 -0
  51. package/src/versioned-signal.ts +58 -0
package/dist/slim.cjs ADDED
@@ -0,0 +1,3384 @@
1
+ 'use strict';
2
+
3
+ // src/devtools.ts
4
+ function getGlobalHook() {
5
+ if (typeof globalThis === "undefined") return void 0;
6
+ return globalThis.__FICT_DEVTOOLS_HOOK__;
7
+ }
8
+ function getDevtoolsHook() {
9
+ return getGlobalHook();
10
+ }
11
+
12
+ // src/cycle-guard.ts
13
+ var defaultOptions = {
14
+ maxFlushCyclesPerMicrotask: 1e4,
15
+ maxEffectRunsPerFlush: 2e4,
16
+ windowSize: 5,
17
+ highUsageRatio: 0.8,
18
+ maxRootReentrantDepth: 10,
19
+ enableWindowWarning: true,
20
+ devMode: false
21
+ };
22
+ var options = {
23
+ ...defaultOptions
24
+ };
25
+ var effectRunsThisFlush = 0;
26
+ var windowUsage = [];
27
+ var rootDepth = /* @__PURE__ */ new WeakMap();
28
+ var flushWarned = false;
29
+ var rootWarned = false;
30
+ var windowWarned = false;
31
+ function beginFlushGuard() {
32
+ effectRunsThisFlush = 0;
33
+ flushWarned = false;
34
+ windowWarned = false;
35
+ }
36
+ function beforeEffectRunGuard() {
37
+ const next = ++effectRunsThisFlush;
38
+ if (next > options.maxFlushCyclesPerMicrotask || next > options.maxEffectRunsPerFlush) {
39
+ const message = `[fict] cycle protection triggered: flush-budget-exceeded`;
40
+ if (options.devMode) {
41
+ throw new Error(message);
42
+ }
43
+ if (!flushWarned) {
44
+ flushWarned = true;
45
+ console.warn(message, { effectRuns: next });
46
+ }
47
+ return false;
48
+ }
49
+ return true;
50
+ }
51
+ function endFlushGuard() {
52
+ recordWindowUsage(effectRunsThisFlush, options.maxFlushCyclesPerMicrotask);
53
+ effectRunsThisFlush = 0;
54
+ }
55
+ function enterRootGuard(root) {
56
+ const depth = (rootDepth.get(root) ?? 0) + 1;
57
+ if (depth > options.maxRootReentrantDepth) {
58
+ const message = `[fict] cycle protection triggered: root-reentry`;
59
+ if (options.devMode) {
60
+ throw new Error(message);
61
+ }
62
+ if (!rootWarned) {
63
+ rootWarned = true;
64
+ console.warn(message, { depth });
65
+ }
66
+ return false;
67
+ }
68
+ rootDepth.set(root, depth);
69
+ return true;
70
+ }
71
+ function exitRootGuard(root) {
72
+ const depth = rootDepth.get(root);
73
+ if (depth === void 0) return;
74
+ if (depth <= 1) {
75
+ rootDepth.delete(root);
76
+ } else {
77
+ rootDepth.set(root, depth - 1);
78
+ }
79
+ }
80
+ function recordWindowUsage(used, budget) {
81
+ if (!options.enableWindowWarning) return;
82
+ const entry = { used, budget };
83
+ windowUsage.push(entry);
84
+ if (windowUsage.length > options.windowSize) {
85
+ windowUsage.shift();
86
+ }
87
+ if (windowWarned) return;
88
+ if (windowUsage.length >= options.windowSize && windowUsage.every((item) => item.budget > 0 && item.used / item.budget >= options.highUsageRatio)) {
89
+ windowWarned = true;
90
+ reportCycle("high-usage-window", {
91
+ windowSize: options.windowSize,
92
+ ratio: options.highUsageRatio
93
+ });
94
+ }
95
+ }
96
+ function reportCycle(reason, detail = void 0) {
97
+ const hook = getDevtoolsHook();
98
+ hook?.cycleDetected?.(detail ? { reason, detail } : { reason });
99
+ console.warn(`[fict] cycle protection triggered: ${reason}`, detail ?? "");
100
+ }
101
+
102
+ // src/lifecycle.ts
103
+ var currentRoot;
104
+ var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
105
+ var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
106
+ function createRootContext(parent = currentRoot) {
107
+ return { parent, cleanups: [], destroyCallbacks: [] };
108
+ }
109
+ function pushRoot(root) {
110
+ if (!enterRootGuard(root)) {
111
+ return currentRoot;
112
+ }
113
+ const prev = currentRoot;
114
+ currentRoot = root;
115
+ return prev;
116
+ }
117
+ function getCurrentRoot() {
118
+ return currentRoot;
119
+ }
120
+ function popRoot(prev) {
121
+ if (currentRoot) {
122
+ exitRootGuard(currentRoot);
123
+ }
124
+ currentRoot = prev;
125
+ }
126
+ function onDestroy(fn) {
127
+ if (currentRoot) {
128
+ currentRoot.destroyCallbacks.push(() => runLifecycle(fn));
129
+ return;
130
+ }
131
+ runLifecycle(fn);
132
+ }
133
+ function flushOnMount(root) {
134
+ const cbs = root.onMountCallbacks;
135
+ if (!cbs || cbs.length === 0) return;
136
+ for (let i = 0; i < cbs.length; i++) {
137
+ const cleanup = cbs[i]();
138
+ if (typeof cleanup === "function") {
139
+ root.cleanups.push(cleanup);
140
+ }
141
+ }
142
+ cbs.length = 0;
143
+ }
144
+ function registerRootCleanup(fn) {
145
+ if (currentRoot) {
146
+ currentRoot.cleanups.push(fn);
147
+ }
148
+ }
149
+ function clearRoot(root) {
150
+ runCleanupList(root.cleanups);
151
+ if (root.onMountCallbacks) {
152
+ root.onMountCallbacks.length = 0;
153
+ }
154
+ }
155
+ function destroyRoot(root) {
156
+ clearRoot(root);
157
+ runCleanupList(root.destroyCallbacks);
158
+ if (root.errorHandlers) {
159
+ root.errorHandlers.length = 0;
160
+ }
161
+ if (globalErrorHandlers.has(root)) {
162
+ globalErrorHandlers.delete(root);
163
+ }
164
+ if (root.suspenseHandlers) {
165
+ root.suspenseHandlers.length = 0;
166
+ }
167
+ if (globalSuspenseHandlers.has(root)) {
168
+ globalSuspenseHandlers.delete(root);
169
+ }
170
+ }
171
+ function withEffectCleanups(bucket, fn) {
172
+ try {
173
+ return fn();
174
+ } finally {
175
+ }
176
+ }
177
+ function runCleanupList(list) {
178
+ let error;
179
+ for (let i = list.length - 1; i >= 0; i--) {
180
+ try {
181
+ const cleanup = list[i];
182
+ if (cleanup) cleanup();
183
+ } catch (err) {
184
+ if (error === void 0) {
185
+ error = err;
186
+ }
187
+ }
188
+ }
189
+ list.length = 0;
190
+ if (error !== void 0) {
191
+ if (!handleError(error, { source: "cleanup" })) {
192
+ throw error;
193
+ }
194
+ }
195
+ }
196
+ function runLifecycle(fn) {
197
+ const cleanup = fn();
198
+ if (typeof cleanup === "function") {
199
+ cleanup();
200
+ }
201
+ }
202
+ function handleError(err, info, startRoot) {
203
+ let root = startRoot ?? currentRoot;
204
+ let error = err;
205
+ while (root) {
206
+ const handlers = root.errorHandlers;
207
+ if (handlers && handlers.length) {
208
+ for (let i = handlers.length - 1; i >= 0; i--) {
209
+ const handler = handlers[i];
210
+ try {
211
+ const handled = handler(error, info);
212
+ if (handled !== false) {
213
+ return true;
214
+ }
215
+ } catch (nextErr) {
216
+ error = nextErr;
217
+ }
218
+ }
219
+ }
220
+ root = root.parent;
221
+ }
222
+ const globalForRoot = startRoot ? globalErrorHandlers.get(startRoot) : currentRoot ? globalErrorHandlers.get(currentRoot) : void 0;
223
+ if (globalForRoot && globalForRoot.length) {
224
+ for (let i = globalForRoot.length - 1; i >= 0; i--) {
225
+ const handler = globalForRoot[i];
226
+ try {
227
+ const handled = handler(error, info);
228
+ if (handled !== false) {
229
+ return true;
230
+ }
231
+ } catch (nextErr) {
232
+ error = nextErr;
233
+ }
234
+ }
235
+ }
236
+ throw error;
237
+ }
238
+ function handleSuspend(token, startRoot) {
239
+ let root = startRoot ?? currentRoot;
240
+ while (root) {
241
+ const handlers = root.suspenseHandlers;
242
+ if (handlers && handlers.length) {
243
+ for (let i = handlers.length - 1; i >= 0; i--) {
244
+ const handler = handlers[i];
245
+ const handled = handler(token);
246
+ if (handled !== false) return true;
247
+ }
248
+ }
249
+ root = root.parent;
250
+ }
251
+ const globalForRoot = startRoot && globalSuspenseHandlers.get(startRoot) ? globalSuspenseHandlers.get(startRoot) : currentRoot ? globalSuspenseHandlers.get(currentRoot) : void 0;
252
+ if (globalForRoot && globalForRoot.length) {
253
+ for (let i = globalForRoot.length - 1; i >= 0; i--) {
254
+ const handler = globalForRoot[i];
255
+ const handled = handler(token);
256
+ if (handled !== false) return true;
257
+ }
258
+ }
259
+ return false;
260
+ }
261
+
262
+ // src/signal.ts
263
+ var Mutable = 1;
264
+ var Watching = 2;
265
+ var Running = 4;
266
+ var Dirty = 16;
267
+ var Pending = 32;
268
+ var MutableDirty = 17;
269
+ var MutablePending = 33;
270
+ var MutableRunning = 5;
271
+ var WatchingRunning = 6;
272
+ var cycle = 0;
273
+ var batchDepth = 0;
274
+ var activeSub;
275
+ var flushScheduled = false;
276
+ var highPriorityQueue = [];
277
+ var lowPriorityQueue = [];
278
+ var enqueueMicrotask = typeof queueMicrotask === "function" ? queueMicrotask : (fn) => {
279
+ Promise.resolve().then(fn);
280
+ };
281
+ function link(dep, sub, version) {
282
+ const prevDep = sub.depsTail;
283
+ if (prevDep !== void 0 && prevDep.dep === dep) return;
284
+ const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
285
+ if (nextDep !== void 0 && nextDep.dep === dep) {
286
+ nextDep.version = version;
287
+ sub.depsTail = nextDep;
288
+ return;
289
+ }
290
+ const prevSub = dep.subsTail;
291
+ if (prevSub !== void 0 && prevSub.version === version && prevSub.sub === sub) return;
292
+ const newLink = { version, dep, sub, prevDep, nextDep, prevSub, nextSub: void 0 };
293
+ sub.depsTail = newLink;
294
+ dep.subsTail = newLink;
295
+ if (nextDep !== void 0) nextDep.prevDep = newLink;
296
+ if (prevDep !== void 0) prevDep.nextDep = newLink;
297
+ else sub.deps = newLink;
298
+ if (prevSub !== void 0) prevSub.nextSub = newLink;
299
+ else dep.subs = newLink;
300
+ }
301
+ function unlink(lnk, sub = lnk.sub) {
302
+ const dep = lnk.dep;
303
+ const prevDep = lnk.prevDep;
304
+ const nextDep = lnk.nextDep;
305
+ const nextSub = lnk.nextSub;
306
+ const prevSub = lnk.prevSub;
307
+ if (nextDep !== void 0) nextDep.prevDep = prevDep;
308
+ else sub.depsTail = prevDep;
309
+ if (prevDep !== void 0) prevDep.nextDep = nextDep;
310
+ else sub.deps = nextDep;
311
+ if (nextSub !== void 0) nextSub.prevSub = prevSub;
312
+ else dep.subsTail = prevSub;
313
+ if (prevSub !== void 0) prevSub.nextSub = nextSub;
314
+ else if ((dep.subs = nextSub) === void 0) unwatched(dep);
315
+ return nextDep;
316
+ }
317
+ function unwatched(dep) {
318
+ if (!(dep.flags & Mutable)) {
319
+ disposeNode(dep);
320
+ } else if ("getter" in dep && dep.getter !== void 0) {
321
+ dep.depsTail = void 0;
322
+ dep.flags = MutableDirty;
323
+ purgeDeps(dep);
324
+ }
325
+ }
326
+ function propagate(firstLink) {
327
+ let link2 = firstLink;
328
+ let next = link2.nextSub;
329
+ let stack;
330
+ top: for (; ; ) {
331
+ const sub = link2.sub;
332
+ let flags = sub.flags;
333
+ if (!(flags & 60)) {
334
+ sub.flags = flags | Pending;
335
+ } else if (!(flags & 12)) {
336
+ flags = 0;
337
+ } else if (!(flags & Running)) {
338
+ sub.flags = flags & -9 | Pending;
339
+ } else if (!(flags & 48)) {
340
+ let vlink = sub.depsTail;
341
+ let valid = false;
342
+ while (vlink !== void 0) {
343
+ if (vlink === link2) {
344
+ valid = true;
345
+ break;
346
+ }
347
+ vlink = vlink.prevDep;
348
+ }
349
+ if (valid) {
350
+ sub.flags = flags | 40;
351
+ flags &= Mutable;
352
+ } else {
353
+ flags = 0;
354
+ }
355
+ } else {
356
+ flags = 0;
357
+ }
358
+ if (flags & Watching) notify(sub);
359
+ if (flags & Mutable) {
360
+ const subSubs = sub.subs;
361
+ if (subSubs !== void 0) {
362
+ const nextSub = subSubs.nextSub;
363
+ if (nextSub !== void 0) {
364
+ stack = { value: next, prev: stack };
365
+ next = nextSub;
366
+ }
367
+ link2 = subSubs;
368
+ continue;
369
+ }
370
+ }
371
+ if (next !== void 0) {
372
+ link2 = next;
373
+ next = link2.nextSub;
374
+ continue;
375
+ }
376
+ while (stack !== void 0) {
377
+ link2 = stack.value;
378
+ stack = stack.prev;
379
+ if (link2 !== void 0) {
380
+ next = link2.nextSub;
381
+ continue top;
382
+ }
383
+ }
384
+ break;
385
+ }
386
+ }
387
+ function checkDirty(firstLink, sub) {
388
+ let link2 = firstLink;
389
+ let stack;
390
+ let checkDepth = 0;
391
+ let dirty = false;
392
+ top: for (; ; ) {
393
+ const dep = link2.dep;
394
+ const depFlags = dep.flags;
395
+ if (sub.flags & Dirty) {
396
+ dirty = true;
397
+ } else if ((depFlags & MutableDirty) === MutableDirty) {
398
+ if (update(dep)) {
399
+ const subs = dep.subs;
400
+ if (subs !== void 0 && subs.nextSub !== void 0) shallowPropagate(subs);
401
+ dirty = true;
402
+ }
403
+ } else if ((depFlags & MutablePending) === MutablePending) {
404
+ if (link2.nextSub !== void 0 || link2.prevSub !== void 0) {
405
+ stack = { value: link2, prev: stack };
406
+ }
407
+ link2 = dep.deps;
408
+ sub = dep;
409
+ ++checkDepth;
410
+ continue;
411
+ }
412
+ if (!dirty) {
413
+ const nextDep = link2.nextDep;
414
+ if (nextDep !== void 0) {
415
+ link2 = nextDep;
416
+ continue;
417
+ }
418
+ }
419
+ while (checkDepth-- > 0) {
420
+ const firstSub = sub.subs;
421
+ const hasMultipleSubs = firstSub.nextSub !== void 0;
422
+ if (hasMultipleSubs) {
423
+ link2 = stack.value;
424
+ stack = stack.prev;
425
+ } else {
426
+ link2 = firstSub;
427
+ }
428
+ if (dirty) {
429
+ if (update(sub)) {
430
+ if (hasMultipleSubs) shallowPropagate(firstSub);
431
+ sub = link2.sub;
432
+ continue;
433
+ }
434
+ dirty = false;
435
+ } else {
436
+ sub.flags &= ~Pending;
437
+ }
438
+ sub = link2.sub;
439
+ const nextDep = link2.nextDep;
440
+ if (nextDep !== void 0) {
441
+ link2 = nextDep;
442
+ continue top;
443
+ }
444
+ }
445
+ return dirty;
446
+ }
447
+ }
448
+ function shallowPropagate(firstLink) {
449
+ let link2 = firstLink;
450
+ do {
451
+ const sub = link2.sub;
452
+ const flags = sub.flags;
453
+ if ((flags & 48) === Pending) {
454
+ sub.flags = flags | Dirty;
455
+ if ((flags & 6) === Watching) notify(sub);
456
+ }
457
+ link2 = link2.nextSub;
458
+ } while (link2 !== void 0);
459
+ }
460
+ function update(node) {
461
+ return "getter" in node && node.getter !== void 0 ? updateComputed(node) : updateSignal(node);
462
+ }
463
+ function notify(effect2) {
464
+ effect2.flags &= ~Watching;
465
+ const effects = [];
466
+ for (; ; ) {
467
+ effects.push(effect2);
468
+ const nextLink = effect2.subs;
469
+ if (nextLink === void 0) break;
470
+ effect2 = nextLink.sub;
471
+ if (effect2 === void 0 || !(effect2.flags & Watching)) break;
472
+ effect2.flags &= ~Watching;
473
+ }
474
+ const targetQueue = highPriorityQueue;
475
+ for (let i = effects.length - 1; i >= 0; i--) {
476
+ targetQueue.push(effects[i]);
477
+ }
478
+ }
479
+ function purgeDeps(sub) {
480
+ const depsTail = sub.depsTail;
481
+ let dep = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
482
+ while (dep !== void 0) dep = unlink(dep, sub);
483
+ }
484
+ function disposeNode(node) {
485
+ node.depsTail = void 0;
486
+ node.flags = 0;
487
+ purgeDeps(node);
488
+ const sub = node.subs;
489
+ if (sub !== void 0) unlink(sub, node);
490
+ }
491
+ function updateSignal(s) {
492
+ s.flags = Mutable;
493
+ const current = s.currentValue;
494
+ const pending = s.pendingValue;
495
+ if (current !== pending) {
496
+ s.currentValue = pending;
497
+ return true;
498
+ }
499
+ return false;
500
+ }
501
+ function updateComputed(c) {
502
+ ++cycle;
503
+ const oldValue = c.value;
504
+ c.depsTail = void 0;
505
+ c.flags = MutableRunning;
506
+ const prevSub = activeSub;
507
+ activeSub = c;
508
+ try {
509
+ const newValue = c.getter(oldValue);
510
+ activeSub = prevSub;
511
+ c.flags &= ~Running;
512
+ purgeDeps(c);
513
+ if (oldValue !== newValue) {
514
+ c.value = newValue;
515
+ return true;
516
+ }
517
+ return false;
518
+ } catch (e) {
519
+ activeSub = prevSub;
520
+ c.flags &= ~Running;
521
+ throw e;
522
+ }
523
+ }
524
+ function runEffect(e) {
525
+ const flags = e.flags;
526
+ if (flags & Dirty || flags & Pending && e.deps && checkDirty(e.deps, e)) {
527
+ ++cycle;
528
+ effectRunDevtools(e);
529
+ e.depsTail = void 0;
530
+ e.flags = WatchingRunning;
531
+ const prevSub = activeSub;
532
+ activeSub = e;
533
+ try {
534
+ e.fn();
535
+ activeSub = prevSub;
536
+ e.flags = Watching;
537
+ purgeDeps(e);
538
+ } catch (err) {
539
+ activeSub = prevSub;
540
+ e.flags = Watching;
541
+ throw err;
542
+ }
543
+ } else {
544
+ e.flags = Watching;
545
+ }
546
+ }
547
+ function scheduleFlush() {
548
+ const hasWork = highPriorityQueue.length > 0 || lowPriorityQueue.length > 0;
549
+ if (flushScheduled || !hasWork) return;
550
+ if (batchDepth > 0) return;
551
+ flushScheduled = true;
552
+ enqueueMicrotask(() => {
553
+ flush();
554
+ });
555
+ }
556
+ function flush() {
557
+ beginFlushGuard();
558
+ if (batchDepth > 0) {
559
+ scheduleFlush();
560
+ endFlushGuard();
561
+ return;
562
+ }
563
+ const hasWork = highPriorityQueue.length > 0 || lowPriorityQueue.length > 0;
564
+ if (!hasWork) {
565
+ flushScheduled = false;
566
+ endFlushGuard();
567
+ return;
568
+ }
569
+ flushScheduled = false;
570
+ let highIndex = 0;
571
+ while (highIndex < highPriorityQueue.length) {
572
+ const e = highPriorityQueue[highIndex];
573
+ if (!beforeEffectRunGuard()) {
574
+ if (highIndex > 0) {
575
+ highPriorityQueue.copyWithin(0, highIndex);
576
+ highPriorityQueue.length -= highIndex;
577
+ }
578
+ endFlushGuard();
579
+ return;
580
+ }
581
+ highIndex++;
582
+ runEffect(e);
583
+ }
584
+ highPriorityQueue.length = 0;
585
+ let lowIndex = 0;
586
+ while (lowIndex < lowPriorityQueue.length) {
587
+ if (highPriorityQueue.length > 0) {
588
+ if (lowIndex > 0) {
589
+ lowPriorityQueue.copyWithin(0, lowIndex);
590
+ lowPriorityQueue.length -= lowIndex;
591
+ }
592
+ scheduleFlush();
593
+ endFlushGuard();
594
+ return;
595
+ }
596
+ const e = lowPriorityQueue[lowIndex];
597
+ if (!beforeEffectRunGuard()) {
598
+ if (lowIndex > 0) {
599
+ lowPriorityQueue.copyWithin(0, lowIndex);
600
+ lowPriorityQueue.length -= lowIndex;
601
+ }
602
+ endFlushGuard();
603
+ return;
604
+ }
605
+ lowIndex++;
606
+ runEffect(e);
607
+ }
608
+ lowPriorityQueue.length = 0;
609
+ endFlushGuard();
610
+ }
611
+ function signal(initialValue) {
612
+ const s = {
613
+ currentValue: initialValue,
614
+ pendingValue: initialValue,
615
+ subs: void 0,
616
+ subsTail: void 0,
617
+ flags: Mutable,
618
+ __id: void 0
619
+ };
620
+ registerSignalDevtools(initialValue, s);
621
+ return signalOper.bind(s);
622
+ }
623
+ function signalOper(value) {
624
+ if (arguments.length > 0) {
625
+ if (this.pendingValue !== value) {
626
+ this.pendingValue = value;
627
+ this.flags = MutableDirty;
628
+ updateSignalDevtools(this, value);
629
+ const subs = this.subs;
630
+ if (subs !== void 0) {
631
+ propagate(subs);
632
+ if (!batchDepth) scheduleFlush();
633
+ }
634
+ }
635
+ return;
636
+ }
637
+ const flags = this.flags;
638
+ if (flags & Dirty) {
639
+ if (updateSignal(this)) {
640
+ const subs = this.subs;
641
+ if (subs !== void 0) shallowPropagate(subs);
642
+ }
643
+ }
644
+ let sub = activeSub;
645
+ while (sub !== void 0) {
646
+ if (sub.flags & 3) {
647
+ link(this, sub, cycle);
648
+ break;
649
+ }
650
+ const subSubs = sub.subs;
651
+ sub = subSubs !== void 0 ? subSubs.sub : void 0;
652
+ }
653
+ return this.currentValue;
654
+ }
655
+ function computed(getter) {
656
+ const c = {
657
+ value: void 0,
658
+ subs: void 0,
659
+ subsTail: void 0,
660
+ deps: void 0,
661
+ depsTail: void 0,
662
+ flags: 0,
663
+ getter
664
+ };
665
+ const bound = computedOper.bind(c);
666
+ return bound;
667
+ }
668
+ function computedOper() {
669
+ const flags = this.flags;
670
+ if (flags & Dirty) {
671
+ if (updateComputed(this)) {
672
+ const subs = this.subs;
673
+ if (subs !== void 0) shallowPropagate(subs);
674
+ }
675
+ } else if (flags & Pending) {
676
+ if (this.deps && checkDirty(this.deps, this)) {
677
+ if (updateComputed(this)) {
678
+ const subs = this.subs;
679
+ if (subs !== void 0) shallowPropagate(subs);
680
+ }
681
+ } else {
682
+ this.flags = flags & ~Pending;
683
+ }
684
+ } else if (!flags) {
685
+ this.flags = MutableRunning;
686
+ const prevSub = setActiveSub(this);
687
+ try {
688
+ this.value = this.getter(void 0);
689
+ } finally {
690
+ setActiveSub(prevSub);
691
+ this.flags &= ~Running;
692
+ }
693
+ }
694
+ if (activeSub !== void 0) link(this, activeSub, cycle);
695
+ return this.value;
696
+ }
697
+ function effect(fn) {
698
+ const e = {
699
+ fn,
700
+ subs: void 0,
701
+ subsTail: void 0,
702
+ deps: void 0,
703
+ depsTail: void 0,
704
+ flags: WatchingRunning,
705
+ __id: void 0
706
+ };
707
+ registerEffectDevtools(e);
708
+ const prevSub = activeSub;
709
+ if (prevSub !== void 0) link(e, prevSub, 0);
710
+ activeSub = e;
711
+ try {
712
+ effectRunDevtools(e);
713
+ fn();
714
+ } finally {
715
+ activeSub = prevSub;
716
+ e.flags &= ~Running;
717
+ }
718
+ return effectOper.bind(e);
719
+ }
720
+ function effectOper() {
721
+ disposeNode(this);
722
+ }
723
+ function batch(fn) {
724
+ ++batchDepth;
725
+ try {
726
+ return fn();
727
+ } finally {
728
+ if (--batchDepth === 0) flush();
729
+ }
730
+ }
731
+ function setActiveSub(sub) {
732
+ const prev = activeSub;
733
+ activeSub = sub;
734
+ return prev;
735
+ }
736
+ function untrack(fn) {
737
+ const prev = activeSub;
738
+ activeSub = void 0;
739
+ try {
740
+ return fn();
741
+ } finally {
742
+ activeSub = prev;
743
+ }
744
+ }
745
+ var $state = signal;
746
+ var devtoolsSignalId = 0;
747
+ var devtoolsEffectId = 0;
748
+ function registerSignalDevtools(value, node) {
749
+ const hook = getDevtoolsHook();
750
+ if (!hook) return void 0;
751
+ const id = ++devtoolsSignalId;
752
+ hook.registerSignal(id, value);
753
+ node.__id = id;
754
+ return id;
755
+ }
756
+ function updateSignalDevtools(node, value) {
757
+ const hook = getDevtoolsHook();
758
+ if (!hook) return;
759
+ const id = node.__id;
760
+ if (id) hook.updateSignal(id, value);
761
+ }
762
+ function registerEffectDevtools(node) {
763
+ const hook = getDevtoolsHook();
764
+ if (!hook) return void 0;
765
+ const id = ++devtoolsEffectId;
766
+ hook.registerEffect(id);
767
+ node.__id = id;
768
+ return id;
769
+ }
770
+ function effectRunDevtools(node) {
771
+ const hook = getDevtoolsHook();
772
+ if (!hook) return;
773
+ const id = node.__id;
774
+ if (id) hook.effectRun(id);
775
+ }
776
+ function createSelector(source, equalityFn = (a, b) => a === b) {
777
+ let current = source();
778
+ const observers = /* @__PURE__ */ new Map();
779
+ effect(() => {
780
+ const next = source();
781
+ if (equalityFn(current, next)) return;
782
+ const prevSig = observers.get(current);
783
+ if (prevSig) prevSig(false);
784
+ const nextSig = observers.get(next);
785
+ if (nextSig) nextSig(true);
786
+ current = next;
787
+ });
788
+ return (key) => {
789
+ let sig = observers.get(key);
790
+ if (!sig) {
791
+ sig = signal(equalityFn(key, current));
792
+ observers.set(key, sig);
793
+ registerRootCleanup(() => observers.delete(key));
794
+ }
795
+ return sig();
796
+ };
797
+ }
798
+
799
+ // src/memo.ts
800
+ function createMemo(fn) {
801
+ return computed(fn);
802
+ }
803
+
804
+ // src/effect.ts
805
+ function createEffect(fn) {
806
+ let cleanups = [];
807
+ const rootForError = getCurrentRoot();
808
+ const run = () => {
809
+ runCleanupList(cleanups);
810
+ const bucket = [];
811
+ withEffectCleanups(bucket, () => {
812
+ try {
813
+ const maybeCleanup = fn();
814
+ if (typeof maybeCleanup === "function") {
815
+ bucket.push(maybeCleanup);
816
+ }
817
+ } catch (err) {
818
+ if (handleError(err, { source: "effect" }, rootForError)) {
819
+ return;
820
+ }
821
+ throw err;
822
+ }
823
+ });
824
+ cleanups = bucket;
825
+ };
826
+ const disposeEffect = effect(run);
827
+ const teardown = () => {
828
+ runCleanupList(cleanups);
829
+ disposeEffect();
830
+ };
831
+ registerRootCleanup(teardown);
832
+ return teardown;
833
+ }
834
+ function createRenderEffect(fn) {
835
+ let cleanup;
836
+ const rootForError = getCurrentRoot();
837
+ const run = () => {
838
+ if (cleanup) {
839
+ cleanup();
840
+ cleanup = void 0;
841
+ }
842
+ try {
843
+ const maybeCleanup = fn();
844
+ if (typeof maybeCleanup === "function") {
845
+ cleanup = maybeCleanup;
846
+ }
847
+ } catch (err) {
848
+ if (handleError(err, { source: "effect" }, rootForError)) {
849
+ return;
850
+ }
851
+ throw err;
852
+ }
853
+ };
854
+ const disposeEffect = effect(run);
855
+ const teardown = () => {
856
+ if (cleanup) {
857
+ cleanup();
858
+ cleanup = void 0;
859
+ }
860
+ disposeEffect();
861
+ };
862
+ registerRootCleanup(teardown);
863
+ return teardown;
864
+ }
865
+
866
+ // src/scheduler.ts
867
+ function batch2(fn) {
868
+ return batch(fn);
869
+ }
870
+ function untrack2(fn) {
871
+ return untrack(fn);
872
+ }
873
+
874
+ // src/constants.ts
875
+ var booleans = [
876
+ "allowfullscreen",
877
+ "async",
878
+ "alpha",
879
+ // HTMLInputElement
880
+ "autofocus",
881
+ // HTMLElement prop
882
+ "autoplay",
883
+ "checked",
884
+ "controls",
885
+ "default",
886
+ "disabled",
887
+ "formnovalidate",
888
+ "hidden",
889
+ // HTMLElement prop
890
+ "indeterminate",
891
+ "inert",
892
+ // HTMLElement prop
893
+ "ismap",
894
+ "loop",
895
+ "multiple",
896
+ "muted",
897
+ "nomodule",
898
+ "novalidate",
899
+ "open",
900
+ "playsinline",
901
+ "readonly",
902
+ "required",
903
+ "reversed",
904
+ "seamless",
905
+ // HTMLIframeElement - non-standard
906
+ "selected",
907
+ // Experimental attributes
908
+ "adauctionheaders",
909
+ "browsingtopics",
910
+ "credentialless",
911
+ "defaultchecked",
912
+ "defaultmuted",
913
+ "defaultselected",
914
+ "defer",
915
+ "disablepictureinpicture",
916
+ "disableremoteplayback",
917
+ "preservespitch",
918
+ "shadowrootclonable",
919
+ "shadowrootcustomelementregistry",
920
+ "shadowrootdelegatesfocus",
921
+ "shadowrootserializable",
922
+ "sharedstoragewritable"
923
+ ];
924
+ new Set(booleans);
925
+ var Properties = /* @__PURE__ */ new Set([
926
+ // Core properties
927
+ "className",
928
+ "value",
929
+ // CamelCase booleans
930
+ "readOnly",
931
+ "noValidate",
932
+ "formNoValidate",
933
+ "isMap",
934
+ "noModule",
935
+ "playsInline",
936
+ // Experimental (camelCase)
937
+ "adAuctionHeaders",
938
+ "allowFullscreen",
939
+ "browsingTopics",
940
+ "defaultChecked",
941
+ "defaultMuted",
942
+ "defaultSelected",
943
+ "disablePictureInPicture",
944
+ "disableRemotePlayback",
945
+ "preservesPitch",
946
+ "shadowRootClonable",
947
+ "shadowRootCustomElementRegistry",
948
+ "shadowRootDelegatesFocus",
949
+ "shadowRootSerializable",
950
+ "sharedStorageWritable",
951
+ // All lowercase booleans
952
+ ...booleans
953
+ ]);
954
+ var ChildProperties = /* @__PURE__ */ new Set([
955
+ "innerHTML",
956
+ "textContent",
957
+ "innerText",
958
+ "children"
959
+ ]);
960
+ var Aliases = {
961
+ className: "class",
962
+ htmlFor: "for"
963
+ };
964
+ var PropAliases = {
965
+ // Direct mapping
966
+ class: "className",
967
+ // Element-specific mappings
968
+ novalidate: {
969
+ $: "noValidate",
970
+ FORM: 1
971
+ },
972
+ formnovalidate: {
973
+ $: "formNoValidate",
974
+ BUTTON: 1,
975
+ INPUT: 1
976
+ },
977
+ ismap: {
978
+ $: "isMap",
979
+ IMG: 1
980
+ },
981
+ nomodule: {
982
+ $: "noModule",
983
+ SCRIPT: 1
984
+ },
985
+ playsinline: {
986
+ $: "playsInline",
987
+ VIDEO: 1
988
+ },
989
+ readonly: {
990
+ $: "readOnly",
991
+ INPUT: 1,
992
+ TEXTAREA: 1
993
+ },
994
+ // Experimental element-specific
995
+ adauctionheaders: {
996
+ $: "adAuctionHeaders",
997
+ IFRAME: 1
998
+ },
999
+ allowfullscreen: {
1000
+ $: "allowFullscreen",
1001
+ IFRAME: 1
1002
+ },
1003
+ browsingtopics: {
1004
+ $: "browsingTopics",
1005
+ IMG: 1
1006
+ },
1007
+ defaultchecked: {
1008
+ $: "defaultChecked",
1009
+ INPUT: 1
1010
+ },
1011
+ defaultmuted: {
1012
+ $: "defaultMuted",
1013
+ AUDIO: 1,
1014
+ VIDEO: 1
1015
+ },
1016
+ defaultselected: {
1017
+ $: "defaultSelected",
1018
+ OPTION: 1
1019
+ },
1020
+ disablepictureinpicture: {
1021
+ $: "disablePictureInPicture",
1022
+ VIDEO: 1
1023
+ },
1024
+ disableremoteplayback: {
1025
+ $: "disableRemotePlayback",
1026
+ AUDIO: 1,
1027
+ VIDEO: 1
1028
+ },
1029
+ preservespitch: {
1030
+ $: "preservesPitch",
1031
+ AUDIO: 1,
1032
+ VIDEO: 1
1033
+ },
1034
+ shadowrootclonable: {
1035
+ $: "shadowRootClonable",
1036
+ TEMPLATE: 1
1037
+ },
1038
+ shadowrootdelegatesfocus: {
1039
+ $: "shadowRootDelegatesFocus",
1040
+ TEMPLATE: 1
1041
+ },
1042
+ shadowrootserializable: {
1043
+ $: "shadowRootSerializable",
1044
+ TEMPLATE: 1
1045
+ },
1046
+ sharedstoragewritable: {
1047
+ $: "sharedStorageWritable",
1048
+ IFRAME: 1,
1049
+ IMG: 1
1050
+ }
1051
+ };
1052
+ function getPropAlias(prop, tagName) {
1053
+ const a = PropAliases[prop];
1054
+ if (typeof a === "object") {
1055
+ return a[tagName] ? a["$"] : void 0;
1056
+ }
1057
+ return a;
1058
+ }
1059
+ var $$EVENTS = "_$FICT_DELEGATE";
1060
+ var DelegatedEvents = /* @__PURE__ */ new Set([
1061
+ "beforeinput",
1062
+ "click",
1063
+ "dblclick",
1064
+ "contextmenu",
1065
+ "focusin",
1066
+ "focusout",
1067
+ "input",
1068
+ "keydown",
1069
+ "keyup",
1070
+ "mousedown",
1071
+ "mousemove",
1072
+ "mouseout",
1073
+ "mouseover",
1074
+ "mouseup",
1075
+ "pointerdown",
1076
+ "pointermove",
1077
+ "pointerout",
1078
+ "pointerover",
1079
+ "pointerup",
1080
+ "touchend",
1081
+ "touchmove",
1082
+ "touchstart"
1083
+ ]);
1084
+ var SVGNamespace = {
1085
+ xlink: "http://www.w3.org/1999/xlink",
1086
+ xml: "http://www.w3.org/XML/1998/namespace"
1087
+ };
1088
+ var UnitlessStyles = /* @__PURE__ */ new Set([
1089
+ "animationIterationCount",
1090
+ "animation-iteration-count",
1091
+ "borderImageOutset",
1092
+ "border-image-outset",
1093
+ "borderImageSlice",
1094
+ "border-image-slice",
1095
+ "borderImageWidth",
1096
+ "border-image-width",
1097
+ "boxFlex",
1098
+ "box-flex",
1099
+ "boxFlexGroup",
1100
+ "box-flex-group",
1101
+ "boxOrdinalGroup",
1102
+ "box-ordinal-group",
1103
+ "columnCount",
1104
+ "column-count",
1105
+ "columns",
1106
+ "flex",
1107
+ "flexGrow",
1108
+ "flex-grow",
1109
+ "flexPositive",
1110
+ "flex-positive",
1111
+ "flexShrink",
1112
+ "flex-shrink",
1113
+ "flexNegative",
1114
+ "flex-negative",
1115
+ "flexOrder",
1116
+ "flex-order",
1117
+ "gridRow",
1118
+ "grid-row",
1119
+ "gridRowEnd",
1120
+ "grid-row-end",
1121
+ "gridRowSpan",
1122
+ "grid-row-span",
1123
+ "gridRowStart",
1124
+ "grid-row-start",
1125
+ "gridColumn",
1126
+ "grid-column",
1127
+ "gridColumnEnd",
1128
+ "grid-column-end",
1129
+ "gridColumnSpan",
1130
+ "grid-column-span",
1131
+ "gridColumnStart",
1132
+ "grid-column-start",
1133
+ "fontWeight",
1134
+ "font-weight",
1135
+ "lineClamp",
1136
+ "line-clamp",
1137
+ "lineHeight",
1138
+ "line-height",
1139
+ "opacity",
1140
+ "order",
1141
+ "orphans",
1142
+ "tabSize",
1143
+ "tab-size",
1144
+ "widows",
1145
+ "zIndex",
1146
+ "z-index",
1147
+ "zoom",
1148
+ "fillOpacity",
1149
+ "fill-opacity",
1150
+ "floodOpacity",
1151
+ "flood-opacity",
1152
+ "stopOpacity",
1153
+ "stop-opacity",
1154
+ "strokeDasharray",
1155
+ "stroke-dasharray",
1156
+ "strokeDashoffset",
1157
+ "stroke-dashoffset",
1158
+ "strokeMiterlimit",
1159
+ "stroke-miterlimit",
1160
+ "strokeOpacity",
1161
+ "stroke-opacity",
1162
+ "strokeWidth",
1163
+ "stroke-width"
1164
+ ]);
1165
+
1166
+ // src/jsx.ts
1167
+ var Fragment = Symbol("Fragment");
1168
+
1169
+ // src/node-ops.ts
1170
+ function toNodeArray(node) {
1171
+ try {
1172
+ if (Array.isArray(node)) {
1173
+ let allNodes = true;
1174
+ for (const item of node) {
1175
+ let isItemNode = false;
1176
+ try {
1177
+ isItemNode = item instanceof Node;
1178
+ } catch {
1179
+ isItemNode = false;
1180
+ }
1181
+ if (!isItemNode) {
1182
+ allNodes = false;
1183
+ break;
1184
+ }
1185
+ }
1186
+ if (allNodes) {
1187
+ return node;
1188
+ }
1189
+ const result = [];
1190
+ for (const item of node) {
1191
+ result.push(...toNodeArray(item));
1192
+ }
1193
+ return result;
1194
+ }
1195
+ if (node === null || node === void 0 || node === false) {
1196
+ return [];
1197
+ }
1198
+ } catch {
1199
+ return [];
1200
+ }
1201
+ let isNode = false;
1202
+ try {
1203
+ isNode = node instanceof Node;
1204
+ } catch {
1205
+ isNode = false;
1206
+ }
1207
+ if (isNode) {
1208
+ try {
1209
+ if (node instanceof DocumentFragment) {
1210
+ return Array.from(node.childNodes);
1211
+ }
1212
+ } catch {
1213
+ }
1214
+ return [node];
1215
+ }
1216
+ try {
1217
+ if (typeof node === "object" && node !== null && "marker" in node) {
1218
+ return toNodeArray(node.marker);
1219
+ }
1220
+ } catch {
1221
+ }
1222
+ try {
1223
+ return [document.createTextNode(String(node))];
1224
+ } catch {
1225
+ return [document.createTextNode("")];
1226
+ }
1227
+ }
1228
+ function insertNodesBefore(parent, nodes, anchor) {
1229
+ if (nodes.length === 0) return;
1230
+ if (nodes.length === 1) {
1231
+ const node = nodes[0];
1232
+ if (node === void 0 || node === null) return;
1233
+ if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
1234
+ parent.ownerDocument.adoptNode(node);
1235
+ }
1236
+ try {
1237
+ parent.insertBefore(node, anchor);
1238
+ } catch (e) {
1239
+ if (parent.ownerDocument) {
1240
+ try {
1241
+ const clone = parent.ownerDocument.importNode(node, true);
1242
+ parent.insertBefore(clone, anchor);
1243
+ return;
1244
+ } catch {
1245
+ }
1246
+ }
1247
+ throw e;
1248
+ }
1249
+ return;
1250
+ }
1251
+ const doc = parent.ownerDocument;
1252
+ if (doc) {
1253
+ const frag = doc.createDocumentFragment();
1254
+ for (let i = 0; i < nodes.length; i++) {
1255
+ const node = nodes[i];
1256
+ if (node === void 0 || node === null) continue;
1257
+ if (node.nodeType === 11) {
1258
+ const childrenArr = Array.from(node.childNodes);
1259
+ for (let j = 0; j < childrenArr.length; j++) {
1260
+ frag.appendChild(childrenArr[j]);
1261
+ }
1262
+ } else {
1263
+ if (node.ownerDocument !== doc) {
1264
+ doc.adoptNode(node);
1265
+ }
1266
+ frag.appendChild(node);
1267
+ }
1268
+ }
1269
+ parent.insertBefore(frag, anchor);
1270
+ return;
1271
+ }
1272
+ const insertSingle = (nodeToInsert, anchorNode) => {
1273
+ if (nodeToInsert.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
1274
+ parent.ownerDocument.adoptNode(nodeToInsert);
1275
+ }
1276
+ try {
1277
+ parent.insertBefore(nodeToInsert, anchorNode);
1278
+ return nodeToInsert;
1279
+ } catch (e) {
1280
+ if (parent.ownerDocument) {
1281
+ try {
1282
+ const clone = parent.ownerDocument.importNode(nodeToInsert, true);
1283
+ parent.insertBefore(clone, anchorNode);
1284
+ return clone;
1285
+ } catch {
1286
+ }
1287
+ }
1288
+ throw e;
1289
+ }
1290
+ };
1291
+ for (let i = nodes.length - 1; i >= 0; i--) {
1292
+ const node = nodes[i];
1293
+ if (node === void 0 || node === null) continue;
1294
+ const isFrag = node.nodeType === 11;
1295
+ if (isFrag) {
1296
+ const childrenArr = Array.from(node.childNodes);
1297
+ for (let j = childrenArr.length - 1; j >= 0; j--) {
1298
+ const child = childrenArr[j];
1299
+ anchor = insertSingle(child, anchor);
1300
+ }
1301
+ } else {
1302
+ anchor = insertSingle(node, anchor);
1303
+ }
1304
+ }
1305
+ }
1306
+ function removeNodes(nodes) {
1307
+ for (const node of nodes) {
1308
+ node.parentNode?.removeChild(node);
1309
+ }
1310
+ }
1311
+
1312
+ // src/binding.ts
1313
+ function isReactive(value) {
1314
+ return typeof value === "function" && value.length === 0;
1315
+ }
1316
+ var PRIMITIVE_PROXY = Symbol("fict:primitive-proxy");
1317
+ var PRIMITIVE_PROXY_RAW_VALUE = Symbol("fict:primitive-proxy:raw-value");
1318
+ function createValueProxy(read) {
1319
+ const getPrimitivePrototype = (value) => {
1320
+ switch (typeof value) {
1321
+ case "string":
1322
+ return String.prototype;
1323
+ case "number":
1324
+ return Number.prototype;
1325
+ case "boolean":
1326
+ return Boolean.prototype;
1327
+ case "bigint":
1328
+ return BigInt.prototype;
1329
+ case "symbol":
1330
+ return Symbol.prototype;
1331
+ default:
1332
+ return void 0;
1333
+ }
1334
+ };
1335
+ const target = {};
1336
+ const handler = {
1337
+ get(_target, prop, receiver) {
1338
+ if (prop === PRIMITIVE_PROXY) {
1339
+ return true;
1340
+ }
1341
+ if (prop === PRIMITIVE_PROXY_RAW_VALUE) {
1342
+ return () => read();
1343
+ }
1344
+ if (prop === Symbol.toPrimitive) {
1345
+ return (hint) => {
1346
+ const value2 = read();
1347
+ if (value2 != null && (typeof value2 === "object" || typeof value2 === "function")) {
1348
+ const toPrimitive = value2[Symbol.toPrimitive];
1349
+ if (typeof toPrimitive === "function") {
1350
+ return toPrimitive.call(value2, hint);
1351
+ }
1352
+ if (hint === "string") return value2.toString?.() ?? "[object Object]";
1353
+ if (hint === "number") return value2.valueOf?.() ?? value2;
1354
+ return value2.valueOf?.() ?? value2;
1355
+ }
1356
+ return value2;
1357
+ };
1358
+ }
1359
+ if (prop === "valueOf") {
1360
+ return () => {
1361
+ const value2 = read();
1362
+ if (value2 != null && (typeof value2 === "object" || typeof value2 === "function")) {
1363
+ return typeof value2.valueOf === "function" ? value2.valueOf() : value2;
1364
+ }
1365
+ return value2;
1366
+ };
1367
+ }
1368
+ if (prop === "toString") {
1369
+ return () => String(read());
1370
+ }
1371
+ const value = read();
1372
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
1373
+ return Reflect.get(value, prop, receiver === _target ? value : receiver);
1374
+ }
1375
+ const proto = getPrimitivePrototype(value);
1376
+ if (proto && prop in proto) {
1377
+ const descriptor = Reflect.get(proto, prop, value);
1378
+ return typeof descriptor === "function" ? descriptor.bind(value) : descriptor;
1379
+ }
1380
+ return void 0;
1381
+ },
1382
+ set(_target, prop, newValue, receiver) {
1383
+ const value = read();
1384
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
1385
+ return Reflect.set(value, prop, newValue, receiver === _target ? value : receiver);
1386
+ }
1387
+ return false;
1388
+ },
1389
+ has(_target, prop) {
1390
+ if (prop === PRIMITIVE_PROXY || prop === PRIMITIVE_PROXY_RAW_VALUE) {
1391
+ return true;
1392
+ }
1393
+ const value = read();
1394
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
1395
+ return prop in value;
1396
+ }
1397
+ const proto = getPrimitivePrototype(value);
1398
+ return proto ? prop in proto : false;
1399
+ },
1400
+ ownKeys() {
1401
+ const value = read();
1402
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
1403
+ return Reflect.ownKeys(value);
1404
+ }
1405
+ const proto = getPrimitivePrototype(value);
1406
+ return proto ? Reflect.ownKeys(proto) : [];
1407
+ },
1408
+ getOwnPropertyDescriptor(_target, prop) {
1409
+ const value = read();
1410
+ if (value != null && (typeof value === "object" || typeof value === "function")) {
1411
+ return Object.getOwnPropertyDescriptor(value, prop);
1412
+ }
1413
+ const proto = getPrimitivePrototype(value);
1414
+ return proto ? Object.getOwnPropertyDescriptor(proto, prop) || void 0 : void 0;
1415
+ }
1416
+ };
1417
+ return new Proxy(target, handler);
1418
+ }
1419
+ function bindText(textNode, getValue) {
1420
+ return createRenderEffect(() => {
1421
+ const value = formatTextValue(getValue());
1422
+ if (textNode.data !== value) {
1423
+ textNode.data = value;
1424
+ }
1425
+ });
1426
+ }
1427
+ function formatTextValue(value) {
1428
+ if (value == null || value === false) {
1429
+ return "";
1430
+ }
1431
+ return String(value);
1432
+ }
1433
+ function createAttributeBinding(el, key, value, setter) {
1434
+ if (isReactive(value)) {
1435
+ createRenderEffect(() => {
1436
+ setter(el, key, value());
1437
+ });
1438
+ } else {
1439
+ setter(el, key, value);
1440
+ }
1441
+ }
1442
+ function bindAttribute(el, key, getValue) {
1443
+ let prevValue = void 0;
1444
+ return createRenderEffect(() => {
1445
+ const value = getValue();
1446
+ if (value === prevValue) return;
1447
+ prevValue = value;
1448
+ if (value === void 0 || value === null || value === false) {
1449
+ el.removeAttribute(key);
1450
+ } else if (value === true) {
1451
+ el.setAttribute(key, "");
1452
+ } else {
1453
+ el.setAttribute(key, String(value));
1454
+ }
1455
+ });
1456
+ }
1457
+ function bindProperty(el, key, getValue) {
1458
+ const PROPERTY_BINDING_KEYS = /* @__PURE__ */ new Set([
1459
+ "value",
1460
+ "checked",
1461
+ "selected",
1462
+ "disabled",
1463
+ "readOnly",
1464
+ "multiple",
1465
+ "muted"
1466
+ ]);
1467
+ let prevValue = void 0;
1468
+ return createRenderEffect(() => {
1469
+ const next = getValue();
1470
+ if (next === prevValue) return;
1471
+ prevValue = next;
1472
+ if (PROPERTY_BINDING_KEYS.has(key) && (next === void 0 || next === null)) {
1473
+ const fallback = key === "checked" || key === "selected" ? false : "";
1474
+ el[key] = fallback;
1475
+ return;
1476
+ }
1477
+ ;
1478
+ el[key] = next;
1479
+ });
1480
+ }
1481
+ function createStyleBinding(el, value) {
1482
+ if (isReactive(value)) {
1483
+ let prev;
1484
+ createRenderEffect(() => {
1485
+ const next = value();
1486
+ applyStyle(el, next, prev);
1487
+ prev = next;
1488
+ });
1489
+ } else {
1490
+ applyStyle(el, value, void 0);
1491
+ }
1492
+ }
1493
+ function bindStyle(el, getValue) {
1494
+ let prev;
1495
+ return createRenderEffect(() => {
1496
+ const next = getValue();
1497
+ applyStyle(el, next, prev);
1498
+ prev = next;
1499
+ });
1500
+ }
1501
+ function applyStyle(el, value, prev) {
1502
+ if (typeof value === "string") {
1503
+ el.style.cssText = value;
1504
+ } else if (value && typeof value === "object") {
1505
+ const styles = value;
1506
+ if (typeof prev === "string") {
1507
+ el.style.cssText = "";
1508
+ }
1509
+ if (prev && typeof prev === "object") {
1510
+ const prevStyles = prev;
1511
+ for (const key of Object.keys(prevStyles)) {
1512
+ if (!(key in styles)) {
1513
+ const cssProperty = key.replace(/([A-Z])/g, "-$1").toLowerCase();
1514
+ el.style.removeProperty(cssProperty);
1515
+ }
1516
+ }
1517
+ }
1518
+ for (const [prop, v] of Object.entries(styles)) {
1519
+ if (v != null) {
1520
+ const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
1521
+ const unitless = isUnitlessStyleProperty(prop) || isUnitlessStyleProperty(cssProperty);
1522
+ const valueStr = typeof v === "number" && !unitless ? `${v}px` : String(v);
1523
+ el.style.setProperty(cssProperty, valueStr);
1524
+ } else {
1525
+ const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
1526
+ el.style.removeProperty(cssProperty);
1527
+ }
1528
+ }
1529
+ } else {
1530
+ if (prev && typeof prev === "object") {
1531
+ const prevStyles = prev;
1532
+ for (const key of Object.keys(prevStyles)) {
1533
+ const cssProperty = key.replace(/([A-Z])/g, "-$1").toLowerCase();
1534
+ el.style.removeProperty(cssProperty);
1535
+ }
1536
+ } else if (typeof prev === "string") {
1537
+ el.style.cssText = "";
1538
+ }
1539
+ }
1540
+ }
1541
+ function isUnitlessStyleProperty(prop) {
1542
+ return UnitlessStyles.has(prop);
1543
+ }
1544
+ function createClassBinding(el, value) {
1545
+ if (isReactive(value)) {
1546
+ let prev = {};
1547
+ createRenderEffect(() => {
1548
+ const next = value();
1549
+ prev = applyClass(el, next, prev);
1550
+ });
1551
+ } else {
1552
+ applyClass(el, value, {});
1553
+ }
1554
+ }
1555
+ function bindClass(el, getValue) {
1556
+ let prev = {};
1557
+ return createRenderEffect(() => {
1558
+ const next = getValue();
1559
+ prev = applyClass(el, next, prev);
1560
+ });
1561
+ }
1562
+ function toggleClassKey(node, key, value) {
1563
+ const classNames = key.trim().split(/\s+/);
1564
+ for (let i = 0, len = classNames.length; i < len; i++) {
1565
+ node.classList.toggle(classNames[i], value);
1566
+ }
1567
+ }
1568
+ function applyClass(el, value, prev) {
1569
+ const prevState = prev && typeof prev === "object" ? prev : {};
1570
+ if (typeof value === "string") {
1571
+ el.className = value;
1572
+ return {};
1573
+ }
1574
+ if (value && typeof value === "object") {
1575
+ const classes = value;
1576
+ const classKeys = Object.keys(classes);
1577
+ const prevKeys = Object.keys(prevState);
1578
+ for (let i = 0, len = prevKeys.length; i < len; i++) {
1579
+ const key = prevKeys[i];
1580
+ if (!key || key === "undefined" || classes[key]) continue;
1581
+ toggleClassKey(el, key, false);
1582
+ delete prevState[key];
1583
+ }
1584
+ for (let i = 0, len = classKeys.length; i < len; i++) {
1585
+ const key = classKeys[i];
1586
+ const classValue = !!classes[key];
1587
+ if (!key || key === "undefined" || prevState[key] === classValue || !classValue) continue;
1588
+ toggleClassKey(el, key, true);
1589
+ prevState[key] = classValue;
1590
+ }
1591
+ return prevState;
1592
+ }
1593
+ if (!value) {
1594
+ for (const key of Object.keys(prevState)) {
1595
+ if (key && key !== "undefined") {
1596
+ toggleClassKey(el, key, false);
1597
+ }
1598
+ }
1599
+ return {};
1600
+ }
1601
+ return prevState;
1602
+ }
1603
+ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
1604
+ let marker;
1605
+ let ownsMarker = false;
1606
+ let createFn = createElementFn;
1607
+ if (markerOrCreateElement instanceof Node) {
1608
+ marker = markerOrCreateElement;
1609
+ createFn = createElementFn;
1610
+ } else {
1611
+ marker = document.createComment("fict:insert");
1612
+ parent.appendChild(marker);
1613
+ createFn = markerOrCreateElement;
1614
+ ownsMarker = true;
1615
+ }
1616
+ let currentNodes = [];
1617
+ let currentText = null;
1618
+ let currentRoot2 = null;
1619
+ const clearCurrentNodes = () => {
1620
+ if (currentNodes.length > 0) {
1621
+ removeNodes(currentNodes);
1622
+ currentNodes = [];
1623
+ }
1624
+ };
1625
+ const setTextNode = (textValue, shouldInsert, parentNode) => {
1626
+ if (!currentText) {
1627
+ currentText = document.createTextNode(textValue);
1628
+ } else if (currentText.data !== textValue) {
1629
+ currentText.data = textValue;
1630
+ }
1631
+ if (!shouldInsert) {
1632
+ clearCurrentNodes();
1633
+ return;
1634
+ }
1635
+ if (currentNodes.length === 1 && currentNodes[0] === currentText) {
1636
+ return;
1637
+ }
1638
+ clearCurrentNodes();
1639
+ insertNodesBefore(parentNode, [currentText], marker);
1640
+ currentNodes = [currentText];
1641
+ };
1642
+ const dispose = createRenderEffect(() => {
1643
+ const value = getValue();
1644
+ const parentNode = marker.parentNode;
1645
+ const isPrimitive = value == null || value === false || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
1646
+ if (isPrimitive) {
1647
+ if (currentRoot2) {
1648
+ destroyRoot(currentRoot2);
1649
+ currentRoot2 = null;
1650
+ }
1651
+ if (!parentNode) {
1652
+ clearCurrentNodes();
1653
+ return;
1654
+ }
1655
+ const textValue = value == null || value === false ? "" : String(value);
1656
+ const shouldInsert = value != null && value !== false;
1657
+ setTextNode(textValue, shouldInsert, parentNode);
1658
+ return;
1659
+ }
1660
+ if (currentRoot2) {
1661
+ destroyRoot(currentRoot2);
1662
+ currentRoot2 = null;
1663
+ }
1664
+ clearCurrentNodes();
1665
+ const root = createRootContext();
1666
+ const prev = pushRoot(root);
1667
+ let nodes = [];
1668
+ try {
1669
+ let newNode;
1670
+ if (value instanceof Node) {
1671
+ newNode = value;
1672
+ } else if (Array.isArray(value)) {
1673
+ if (value.every((v) => v instanceof Node)) {
1674
+ newNode = value;
1675
+ } else {
1676
+ newNode = createFn ? createFn(value) : document.createTextNode(String(value));
1677
+ }
1678
+ } else {
1679
+ newNode = createFn ? createFn(value) : document.createTextNode(String(value));
1680
+ }
1681
+ nodes = toNodeArray(newNode);
1682
+ if (parentNode) {
1683
+ insertNodesBefore(parentNode, nodes, marker);
1684
+ }
1685
+ } finally {
1686
+ popRoot(prev);
1687
+ flushOnMount(root);
1688
+ }
1689
+ currentRoot2 = root;
1690
+ currentNodes = nodes;
1691
+ });
1692
+ return () => {
1693
+ dispose();
1694
+ if (currentRoot2) {
1695
+ destroyRoot(currentRoot2);
1696
+ currentRoot2 = null;
1697
+ }
1698
+ clearCurrentNodes();
1699
+ if (ownsMarker) {
1700
+ marker.parentNode?.removeChild(marker);
1701
+ }
1702
+ };
1703
+ }
1704
+ function createChildBinding(parent, getValue, createElementFn) {
1705
+ const marker = document.createComment("fict:child");
1706
+ parent.appendChild(marker);
1707
+ const dispose = createRenderEffect(() => {
1708
+ const root = createRootContext();
1709
+ const prev = pushRoot(root);
1710
+ let nodes = [];
1711
+ let handledError = false;
1712
+ try {
1713
+ const value = getValue();
1714
+ if (value == null || value === false) {
1715
+ return;
1716
+ }
1717
+ const output = createElementFn(value);
1718
+ nodes = toNodeArray(output);
1719
+ const parentNode = marker.parentNode;
1720
+ if (parentNode) {
1721
+ insertNodesBefore(parentNode, nodes, marker);
1722
+ }
1723
+ return () => {
1724
+ destroyRoot(root);
1725
+ removeNodes(nodes);
1726
+ };
1727
+ } catch (err) {
1728
+ if (handleSuspend(err, root)) {
1729
+ handledError = true;
1730
+ destroyRoot(root);
1731
+ return;
1732
+ }
1733
+ if (handleError(err, { source: "renderChild" }, root)) {
1734
+ handledError = true;
1735
+ destroyRoot(root);
1736
+ return;
1737
+ }
1738
+ throw err;
1739
+ } finally {
1740
+ popRoot(prev);
1741
+ if (!handledError) {
1742
+ flushOnMount(root);
1743
+ }
1744
+ }
1745
+ });
1746
+ return {
1747
+ marker,
1748
+ dispose: () => {
1749
+ dispose();
1750
+ marker.parentNode?.removeChild(marker);
1751
+ }
1752
+ };
1753
+ }
1754
+ function delegateEvents(eventNames, doc = window.document) {
1755
+ const e = doc[$$EVENTS] || (doc[$$EVENTS] = /* @__PURE__ */ new Set());
1756
+ for (let i = 0, l = eventNames.length; i < l; i++) {
1757
+ const name = eventNames[i];
1758
+ if (!e.has(name)) {
1759
+ e.add(name);
1760
+ doc.addEventListener(name, globalEventHandler);
1761
+ }
1762
+ }
1763
+ }
1764
+ function clearDelegatedEvents(doc = window.document) {
1765
+ const e = doc[$$EVENTS];
1766
+ if (e) {
1767
+ for (const name of e.keys()) {
1768
+ doc.removeEventListener(name, globalEventHandler);
1769
+ }
1770
+ delete doc[$$EVENTS];
1771
+ }
1772
+ }
1773
+ function globalEventHandler(e) {
1774
+ let node = e.target;
1775
+ const key = `$$${e.type}`;
1776
+ const dataKey = `${key}Data`;
1777
+ const oriTarget = e.target;
1778
+ const oriCurrentTarget = e.currentTarget;
1779
+ const retarget = (value) => Object.defineProperty(e, "target", {
1780
+ configurable: true,
1781
+ value
1782
+ });
1783
+ const handleNode = () => {
1784
+ if (!node) return false;
1785
+ const handler = node[key];
1786
+ if (handler && !node.disabled) {
1787
+ const resolveData = (value) => {
1788
+ if (typeof value === "function") {
1789
+ try {
1790
+ const fn = value;
1791
+ return fn.length > 0 ? fn(e) : fn();
1792
+ } catch {
1793
+ return value();
1794
+ }
1795
+ }
1796
+ return value;
1797
+ };
1798
+ const rawData = node[dataKey];
1799
+ const hasData = rawData !== void 0;
1800
+ const resolvedNodeData = hasData ? resolveData(rawData) : void 0;
1801
+ if (typeof handler === "function") {
1802
+ if (hasData) {
1803
+ handler.call(node, resolvedNodeData, e);
1804
+ } else {
1805
+ handler.call(node, e);
1806
+ }
1807
+ } else if (Array.isArray(handler)) {
1808
+ const tupleData = resolveData(handler[1]);
1809
+ handler[0].call(node, tupleData, e);
1810
+ }
1811
+ if (e.cancelBubble) return false;
1812
+ }
1813
+ const shadowHost = node.host;
1814
+ if (shadowHost && typeof shadowHost !== "string" && !shadowHost._$host && node.contains(e.target)) {
1815
+ retarget(shadowHost);
1816
+ }
1817
+ return true;
1818
+ };
1819
+ const walkUpTree = () => {
1820
+ while (handleNode() && node) {
1821
+ node = node._$host || node.parentNode || node.host;
1822
+ }
1823
+ };
1824
+ Object.defineProperty(e, "currentTarget", {
1825
+ configurable: true,
1826
+ get() {
1827
+ return node || document;
1828
+ }
1829
+ });
1830
+ if (e.composedPath) {
1831
+ const path = e.composedPath();
1832
+ retarget(path[0]);
1833
+ for (let i = 0; i < path.length - 2; i++) {
1834
+ node = path[i];
1835
+ if (!handleNode()) break;
1836
+ if (node._$host) {
1837
+ node = node._$host;
1838
+ walkUpTree();
1839
+ break;
1840
+ }
1841
+ if (node.parentNode === oriCurrentTarget) {
1842
+ break;
1843
+ }
1844
+ }
1845
+ } else {
1846
+ walkUpTree();
1847
+ }
1848
+ retarget(oriTarget);
1849
+ }
1850
+ function bindEvent(el, eventName, handler, options2) {
1851
+ if (handler == null) return () => {
1852
+ };
1853
+ const rootRef = getCurrentRoot();
1854
+ if (DelegatedEvents.has(eventName) && !options2) {
1855
+ const key = `$$${eventName}`;
1856
+ delegateEvents([eventName]);
1857
+ const createWrapped = (resolve) => {
1858
+ const wrapped2 = function(...args) {
1859
+ try {
1860
+ const fn = resolve();
1861
+ if (typeof fn === "function") {
1862
+ return fn.apply(this, args);
1863
+ } else if (fn && typeof fn.handleEvent === "function") {
1864
+ return fn.handleEvent.apply(fn, args);
1865
+ }
1866
+ } catch (err) {
1867
+ handleError(err, { source: "event", eventName }, rootRef);
1868
+ }
1869
+ };
1870
+ return wrapped2;
1871
+ };
1872
+ const resolveHandler = isReactive(handler) ? handler : () => handler;
1873
+ el[key] = createWrapped(resolveHandler);
1874
+ return () => {
1875
+ el[key] = void 0;
1876
+ };
1877
+ }
1878
+ const getHandler = isReactive(handler) ? handler : () => handler;
1879
+ const wrapped = (event) => {
1880
+ try {
1881
+ const resolved = getHandler();
1882
+ if (typeof resolved === "function") {
1883
+ ;
1884
+ resolved(event);
1885
+ } else if (resolved && typeof resolved.handleEvent === "function") {
1886
+ ;
1887
+ resolved.handleEvent(event);
1888
+ }
1889
+ } catch (err) {
1890
+ if (handleError(err, { source: "event", eventName }, rootRef)) {
1891
+ return;
1892
+ }
1893
+ throw err;
1894
+ }
1895
+ };
1896
+ el.addEventListener(eventName, wrapped, options2);
1897
+ const cleanup = () => el.removeEventListener(eventName, wrapped, options2);
1898
+ registerRootCleanup(cleanup);
1899
+ return cleanup;
1900
+ }
1901
+ function bindRef(el, ref) {
1902
+ if (ref == null) return () => {
1903
+ };
1904
+ const getRef = isReactive(ref) ? ref : () => ref;
1905
+ const applyRef2 = (refValue) => {
1906
+ if (refValue == null) return;
1907
+ if (typeof refValue === "function") {
1908
+ refValue(el);
1909
+ } else if (typeof refValue === "object" && "current" in refValue) {
1910
+ refValue.current = el;
1911
+ }
1912
+ };
1913
+ const initialRef = getRef();
1914
+ applyRef2(initialRef);
1915
+ if (isReactive(ref)) {
1916
+ const cleanup2 = createRenderEffect(() => {
1917
+ const currentRef = getRef();
1918
+ applyRef2(currentRef);
1919
+ });
1920
+ registerRootCleanup(cleanup2);
1921
+ const nullifyCleanup = () => {
1922
+ const currentRef = getRef();
1923
+ if (currentRef && typeof currentRef === "object" && "current" in currentRef) {
1924
+ currentRef.current = null;
1925
+ }
1926
+ };
1927
+ registerRootCleanup(nullifyCleanup);
1928
+ return () => {
1929
+ cleanup2();
1930
+ nullifyCleanup();
1931
+ };
1932
+ }
1933
+ const cleanup = () => {
1934
+ const refValue = getRef();
1935
+ if (refValue && typeof refValue === "object" && "current" in refValue) {
1936
+ refValue.current = null;
1937
+ }
1938
+ };
1939
+ registerRootCleanup(cleanup);
1940
+ return cleanup;
1941
+ }
1942
+ function createConditional(condition, renderTrue, createElementFn, renderFalse) {
1943
+ const startMarker = document.createComment("fict:cond:start");
1944
+ const endMarker = document.createComment("fict:cond:end");
1945
+ const fragment = document.createDocumentFragment();
1946
+ fragment.append(startMarker, endMarker);
1947
+ let currentNodes = [];
1948
+ let currentRoot2 = null;
1949
+ let lastCondition = void 0;
1950
+ let pendingRender = false;
1951
+ const conditionMemo = computed(condition);
1952
+ const runConditional = () => {
1953
+ const cond = conditionMemo();
1954
+ const parent = startMarker.parentNode;
1955
+ if (!parent) {
1956
+ pendingRender = true;
1957
+ return;
1958
+ }
1959
+ pendingRender = false;
1960
+ if (lastCondition === cond && currentNodes.length > 0) {
1961
+ return;
1962
+ }
1963
+ if (lastCondition === cond && lastCondition === false && renderFalse === void 0) {
1964
+ return;
1965
+ }
1966
+ lastCondition = cond;
1967
+ if (currentRoot2) {
1968
+ destroyRoot(currentRoot2);
1969
+ currentRoot2 = null;
1970
+ }
1971
+ removeNodes(currentNodes);
1972
+ currentNodes = [];
1973
+ const render2 = cond ? renderTrue : renderFalse;
1974
+ if (!render2) {
1975
+ return;
1976
+ }
1977
+ const root = createRootContext();
1978
+ const prev = pushRoot(root);
1979
+ let handledError = false;
1980
+ try {
1981
+ const output = untrack(render2);
1982
+ if (output == null || output === false) {
1983
+ return;
1984
+ }
1985
+ const el = createElementFn(output);
1986
+ const nodes = toNodeArray(el);
1987
+ insertNodesBefore(parent, nodes, endMarker);
1988
+ currentNodes = nodes;
1989
+ } catch (err) {
1990
+ if (handleSuspend(err, root)) {
1991
+ handledError = true;
1992
+ destroyRoot(root);
1993
+ return;
1994
+ }
1995
+ if (handleError(err, { source: "renderChild" }, root)) {
1996
+ handledError = true;
1997
+ destroyRoot(root);
1998
+ return;
1999
+ }
2000
+ throw err;
2001
+ } finally {
2002
+ popRoot(prev);
2003
+ if (!handledError) {
2004
+ flushOnMount(root);
2005
+ currentRoot2 = root;
2006
+ } else {
2007
+ currentRoot2 = null;
2008
+ }
2009
+ }
2010
+ };
2011
+ const dispose = createRenderEffect(runConditional);
2012
+ return {
2013
+ marker: fragment,
2014
+ flush: () => {
2015
+ if (pendingRender) {
2016
+ runConditional();
2017
+ }
2018
+ },
2019
+ dispose: () => {
2020
+ dispose();
2021
+ if (currentRoot2) {
2022
+ destroyRoot(currentRoot2);
2023
+ }
2024
+ removeNodes(currentNodes);
2025
+ currentNodes = [];
2026
+ startMarker.parentNode?.removeChild(startMarker);
2027
+ endMarker.parentNode?.removeChild(endMarker);
2028
+ }
2029
+ };
2030
+ }
2031
+ function createList(items, renderItem, createElementFn, getKey) {
2032
+ const startMarker = document.createComment("fict:list:start");
2033
+ const endMarker = document.createComment("fict:list:end");
2034
+ const fragment = document.createDocumentFragment();
2035
+ fragment.append(startMarker, endMarker);
2036
+ const nodeMap = /* @__PURE__ */ new Map();
2037
+ let pendingItems = null;
2038
+ const runListUpdate = () => {
2039
+ const arr = items();
2040
+ const parent = startMarker.parentNode;
2041
+ if (!parent) {
2042
+ pendingItems = arr;
2043
+ return;
2044
+ }
2045
+ pendingItems = null;
2046
+ const newNodeMap = /* @__PURE__ */ new Map();
2047
+ const blocks = [];
2048
+ for (let i = 0; i < arr.length; i++) {
2049
+ const item = arr[i];
2050
+ const key = getKey ? getKey(item, i) : i;
2051
+ const existing = nodeMap.get(key);
2052
+ let block;
2053
+ if (existing) {
2054
+ const previousValue = existing.value();
2055
+ if (!getKey && previousValue !== item) {
2056
+ destroyRoot(existing.root);
2057
+ removeBlockNodes(existing);
2058
+ block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn);
2059
+ } else {
2060
+ const previousIndex = existing.index();
2061
+ existing.value(item);
2062
+ existing.index(i);
2063
+ if (previousValue === item) {
2064
+ bumpBlockVersion(existing);
2065
+ }
2066
+ const needsRerender = getKey ? true : previousValue !== item || previousIndex !== i;
2067
+ block = needsRerender ? rerenderBlock(existing, createElementFn) : existing;
2068
+ }
2069
+ } else {
2070
+ block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn);
2071
+ }
2072
+ newNodeMap.set(key, block);
2073
+ blocks.push(block);
2074
+ }
2075
+ for (const [key, managed] of nodeMap) {
2076
+ if (!newNodeMap.has(key)) {
2077
+ destroyRoot(managed.root);
2078
+ removeBlockNodes(managed);
2079
+ }
2080
+ }
2081
+ let anchor = endMarker;
2082
+ for (let i = blocks.length - 1; i >= 0; i--) {
2083
+ const block = blocks[i];
2084
+ insertNodesBefore(parent, block.nodes, anchor);
2085
+ if (block.nodes.length > 0) {
2086
+ anchor = block.nodes[0];
2087
+ }
2088
+ }
2089
+ nodeMap.clear();
2090
+ for (const [k, v] of newNodeMap) {
2091
+ nodeMap.set(k, v);
2092
+ }
2093
+ };
2094
+ const dispose = createRenderEffect(runListUpdate);
2095
+ return {
2096
+ marker: fragment,
2097
+ flush: () => {
2098
+ if (pendingItems !== null) {
2099
+ runListUpdate();
2100
+ }
2101
+ },
2102
+ dispose: () => {
2103
+ dispose();
2104
+ for (const [, managed] of nodeMap) {
2105
+ destroyRoot(managed.root);
2106
+ removeBlockNodes(managed);
2107
+ }
2108
+ nodeMap.clear();
2109
+ startMarker.parentNode?.removeChild(startMarker);
2110
+ endMarker.parentNode?.removeChild(endMarker);
2111
+ }
2112
+ };
2113
+ }
2114
+ function mountBlock(initialValue, initialIndex, renderItem, parent, anchor, createElementFn) {
2115
+ const start = document.createComment("fict:block:start");
2116
+ const end = document.createComment("fict:block:end");
2117
+ const valueSig = signal(initialValue);
2118
+ const indexSig = signal(initialIndex);
2119
+ const versionSig = signal(0);
2120
+ const valueProxy = createValueProxy(() => {
2121
+ versionSig();
2122
+ return valueSig();
2123
+ });
2124
+ const renderCurrent = () => renderItem(valueProxy, indexSig());
2125
+ const root = createRootContext();
2126
+ const prev = pushRoot(root);
2127
+ const nodes = [start];
2128
+ let handledError = false;
2129
+ try {
2130
+ const output = renderCurrent();
2131
+ if (output != null && output !== false) {
2132
+ const el = createElementFn(output);
2133
+ const rendered = toNodeArray(el);
2134
+ nodes.push(...rendered);
2135
+ }
2136
+ nodes.push(end);
2137
+ insertNodesBefore(parent, nodes, anchor);
2138
+ } catch (err) {
2139
+ if (handleSuspend(err, root)) {
2140
+ handledError = true;
2141
+ nodes.push(end);
2142
+ insertNodesBefore(parent, nodes, anchor);
2143
+ } else if (handleError(err, { source: "renderChild" }, root)) {
2144
+ handledError = true;
2145
+ nodes.push(end);
2146
+ insertNodesBefore(parent, nodes, anchor);
2147
+ } else {
2148
+ throw err;
2149
+ }
2150
+ } finally {
2151
+ popRoot(prev);
2152
+ if (!handledError) {
2153
+ flushOnMount(root);
2154
+ } else {
2155
+ destroyRoot(root);
2156
+ }
2157
+ }
2158
+ return {
2159
+ nodes,
2160
+ root,
2161
+ value: valueSig,
2162
+ index: indexSig,
2163
+ version: versionSig,
2164
+ start,
2165
+ end,
2166
+ valueProxy,
2167
+ renderCurrent
2168
+ };
2169
+ }
2170
+ function rerenderBlock(block, createElementFn) {
2171
+ const currentContent = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
2172
+ const currentNode = currentContent.length === 1 ? currentContent[0] : null;
2173
+ clearRoot(block.root);
2174
+ const prev = pushRoot(block.root);
2175
+ let nextOutput;
2176
+ let handledError = false;
2177
+ try {
2178
+ nextOutput = block.renderCurrent();
2179
+ } catch (err) {
2180
+ if (handleSuspend(err, block.root)) {
2181
+ handledError = true;
2182
+ popRoot(prev);
2183
+ destroyRoot(block.root);
2184
+ block.nodes = [block.start, block.end];
2185
+ return block;
2186
+ }
2187
+ if (handleError(err, { source: "renderChild" }, block.root)) {
2188
+ handledError = true;
2189
+ popRoot(prev);
2190
+ destroyRoot(block.root);
2191
+ block.nodes = [block.start, block.end];
2192
+ return block;
2193
+ }
2194
+ throw err;
2195
+ } finally {
2196
+ if (!handledError) {
2197
+ popRoot(prev);
2198
+ }
2199
+ }
2200
+ if (isFragmentVNode(nextOutput) && currentContent.length > 0) {
2201
+ const patched = patchFragmentChildren(currentContent, nextOutput.props?.children);
2202
+ if (patched) {
2203
+ block.nodes = [block.start, ...currentContent, block.end];
2204
+ return block;
2205
+ }
2206
+ }
2207
+ if (currentNode && patchNode(currentNode, nextOutput)) {
2208
+ block.nodes = [block.start, currentNode, block.end];
2209
+ return block;
2210
+ }
2211
+ clearContent(block);
2212
+ if (nextOutput != null && nextOutput !== false) {
2213
+ const newNodes = toNodeArray(
2214
+ nextOutput instanceof Node ? nextOutput : createElementFn(nextOutput)
2215
+ );
2216
+ insertNodesBefore(block.start.parentNode, newNodes, block.end);
2217
+ block.nodes = [block.start, ...newNodes, block.end];
2218
+ } else {
2219
+ block.nodes = [block.start, block.end];
2220
+ }
2221
+ return block;
2222
+ }
2223
+ function patchElement(el, output) {
2224
+ if (output === null || output === void 0 || output === false || typeof output === "string" || typeof output === "number") {
2225
+ el.textContent = output === null || output === void 0 || output === false ? "" : String(output);
2226
+ return true;
2227
+ }
2228
+ if (output instanceof Text) {
2229
+ el.textContent = output.data;
2230
+ return true;
2231
+ }
2232
+ if (output && typeof output === "object" && !(output instanceof Node)) {
2233
+ const vnode = output;
2234
+ if (typeof vnode.type === "string" && vnode.type.toLowerCase() === el.tagName.toLowerCase()) {
2235
+ const children = vnode.props?.children;
2236
+ const props = vnode.props ?? {};
2237
+ for (const [key, value] of Object.entries(props)) {
2238
+ if (key === "children" || key === "key") continue;
2239
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
2240
+ if (key === "class" || key === "className") {
2241
+ el.setAttribute("class", value === false || value === null ? "" : String(value));
2242
+ } else if (key === "style" && typeof value === "string") {
2243
+ el.style.cssText = value;
2244
+ } else if (value === false || value === null || value === void 0) {
2245
+ el.removeAttribute(key);
2246
+ } else if (value === true) {
2247
+ el.setAttribute(key, "");
2248
+ } else {
2249
+ el.setAttribute(key, String(value));
2250
+ }
2251
+ }
2252
+ }
2253
+ if (typeof children === "string" || typeof children === "number" || children === null || children === void 0 || children === false) {
2254
+ el.textContent = children === null || children === void 0 || children === false ? "" : String(children);
2255
+ return true;
2256
+ }
2257
+ if (children && typeof children === "object" && !Array.isArray(children) && !(children instanceof Node)) {
2258
+ const childVNode = children;
2259
+ if (typeof childVNode.type === "string") {
2260
+ const childEl = el.querySelector(childVNode.type);
2261
+ if (childEl && patchElement(childEl, children)) {
2262
+ return true;
2263
+ }
2264
+ }
2265
+ }
2266
+ return false;
2267
+ }
2268
+ }
2269
+ if (output instanceof Node) {
2270
+ if (output.nodeType === Node.ELEMENT_NODE) {
2271
+ const nextEl = output;
2272
+ if (nextEl.tagName.toLowerCase() === el.tagName.toLowerCase()) {
2273
+ el.textContent = nextEl.textContent;
2274
+ return true;
2275
+ }
2276
+ } else if (output.nodeType === Node.TEXT_NODE) {
2277
+ el.textContent = output.data;
2278
+ return true;
2279
+ }
2280
+ }
2281
+ return false;
2282
+ }
2283
+ function patchNode(currentNode, nextOutput) {
2284
+ if (!currentNode) return false;
2285
+ if (currentNode instanceof Text && (nextOutput === null || nextOutput === void 0 || nextOutput === false || typeof nextOutput === "string" || typeof nextOutput === "number" || nextOutput instanceof Text)) {
2286
+ const nextText = nextOutput instanceof Text ? nextOutput.data : nextOutput === null || nextOutput === void 0 || nextOutput === false ? "" : String(nextOutput);
2287
+ currentNode.data = nextText;
2288
+ return true;
2289
+ }
2290
+ if (currentNode instanceof Element && patchElement(currentNode, nextOutput)) {
2291
+ return true;
2292
+ }
2293
+ if (nextOutput instanceof Node && currentNode === nextOutput) {
2294
+ return true;
2295
+ }
2296
+ return false;
2297
+ }
2298
+ function isFragmentVNode(value) {
2299
+ return value != null && typeof value === "object" && !(value instanceof Node) && value.type === Fragment;
2300
+ }
2301
+ function normalizeChildren(children, result = []) {
2302
+ if (children === void 0) {
2303
+ return result;
2304
+ }
2305
+ if (Array.isArray(children)) {
2306
+ for (const child of children) {
2307
+ normalizeChildren(child, result);
2308
+ }
2309
+ return result;
2310
+ }
2311
+ if (children === null || children === false) {
2312
+ return result;
2313
+ }
2314
+ result.push(children);
2315
+ return result;
2316
+ }
2317
+ function patchFragmentChildren(nodes, children) {
2318
+ const normalized = normalizeChildren(children);
2319
+ if (normalized.length !== nodes.length) {
2320
+ return false;
2321
+ }
2322
+ for (let i = 0; i < normalized.length; i++) {
2323
+ if (!patchNode(nodes[i], normalized[i])) {
2324
+ return false;
2325
+ }
2326
+ }
2327
+ return true;
2328
+ }
2329
+ function clearContent(block) {
2330
+ const nodes = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
2331
+ removeNodes(nodes);
2332
+ }
2333
+ function removeBlockNodes(block) {
2334
+ let cursor = block.start;
2335
+ const end = block.end;
2336
+ while (cursor) {
2337
+ const next = cursor.nextSibling;
2338
+ cursor.parentNode?.removeChild(cursor);
2339
+ if (cursor === end) break;
2340
+ cursor = next;
2341
+ }
2342
+ }
2343
+ function bumpBlockVersion(block) {
2344
+ block.version(block.version() + 1);
2345
+ }
2346
+
2347
+ // src/hooks.ts
2348
+ var ctxStack = [];
2349
+ function __fictUseContext() {
2350
+ if (ctxStack.length === 0) {
2351
+ const ctx2 = { slots: [], cursor: 0 };
2352
+ ctxStack.push(ctx2);
2353
+ return ctx2;
2354
+ }
2355
+ const ctx = ctxStack[ctxStack.length - 1];
2356
+ ctx.cursor = 0;
2357
+ return ctx;
2358
+ }
2359
+ function __fictPushContext() {
2360
+ const ctx = { slots: [], cursor: 0 };
2361
+ ctxStack.push(ctx);
2362
+ return ctx;
2363
+ }
2364
+ function __fictPopContext() {
2365
+ ctxStack.pop();
2366
+ }
2367
+ function __fictResetContext() {
2368
+ ctxStack.length = 0;
2369
+ }
2370
+ function __fictUseSignal(ctx, initial, slot) {
2371
+ const index = slot ?? ctx.cursor++;
2372
+ if (!ctx.slots[index]) {
2373
+ ctx.slots[index] = signal(initial);
2374
+ }
2375
+ return ctx.slots[index];
2376
+ }
2377
+ function __fictUseMemo(ctx, fn, slot) {
2378
+ const index = slot ?? ctx.cursor++;
2379
+ if (!ctx.slots[index]) {
2380
+ ctx.slots[index] = createMemo(fn);
2381
+ }
2382
+ return ctx.slots[index];
2383
+ }
2384
+ function __fictUseEffect(ctx, fn, slot) {
2385
+ const index = slot ?? ctx.cursor++;
2386
+ if (!ctx.slots[index]) {
2387
+ ctx.slots[index] = createEffect(fn);
2388
+ }
2389
+ }
2390
+ function __fictRender(ctx, fn) {
2391
+ ctxStack.push(ctx);
2392
+ ctx.cursor = 0;
2393
+ try {
2394
+ return fn();
2395
+ } finally {
2396
+ ctxStack.pop();
2397
+ }
2398
+ }
2399
+
2400
+ // src/props.ts
2401
+ var propGetters = /* @__PURE__ */ new WeakSet();
2402
+ var rawToProxy = /* @__PURE__ */ new WeakMap();
2403
+ var proxyToRaw = /* @__PURE__ */ new WeakMap();
2404
+ function __fictProp(getter) {
2405
+ if (typeof getter === "function" && getter.length === 0) {
2406
+ propGetters.add(getter);
2407
+ }
2408
+ return getter;
2409
+ }
2410
+ function isPropGetter(value) {
2411
+ return typeof value === "function" && propGetters.has(value);
2412
+ }
2413
+ function createPropsProxy(props) {
2414
+ if (!props || typeof props !== "object") {
2415
+ return props;
2416
+ }
2417
+ if (proxyToRaw.has(props)) {
2418
+ return props;
2419
+ }
2420
+ const cached = rawToProxy.get(props);
2421
+ if (cached) {
2422
+ return cached;
2423
+ }
2424
+ const proxy = new Proxy(props, {
2425
+ get(target, prop, receiver) {
2426
+ const value = Reflect.get(target, prop, receiver);
2427
+ if (isPropGetter(value)) {
2428
+ return value();
2429
+ }
2430
+ return value;
2431
+ },
2432
+ set(target, prop, value, receiver) {
2433
+ return Reflect.set(target, prop, value, receiver);
2434
+ },
2435
+ has(target, prop) {
2436
+ return prop in target;
2437
+ },
2438
+ ownKeys(target) {
2439
+ return Reflect.ownKeys(target);
2440
+ },
2441
+ getOwnPropertyDescriptor(target, prop) {
2442
+ return Object.getOwnPropertyDescriptor(target, prop);
2443
+ }
2444
+ });
2445
+ rawToProxy.set(props, proxy);
2446
+ proxyToRaw.set(proxy, props);
2447
+ return proxy;
2448
+ }
2449
+ function unwrapProps(props) {
2450
+ if (!props || typeof props !== "object") {
2451
+ return props;
2452
+ }
2453
+ return proxyToRaw.get(props) ?? props;
2454
+ }
2455
+ function __fictPropsRest(props, exclude) {
2456
+ const raw = unwrapProps(props);
2457
+ const out = {};
2458
+ const excludeSet = new Set(exclude);
2459
+ for (const key of Reflect.ownKeys(raw)) {
2460
+ if (excludeSet.has(key)) continue;
2461
+ out[key] = raw[key];
2462
+ }
2463
+ return createPropsProxy(out);
2464
+ }
2465
+ function mergeProps(...sources) {
2466
+ const validSources = sources.filter(
2467
+ (s) => s != null && (typeof s === "object" || typeof s === "function")
2468
+ );
2469
+ if (validSources.length === 0) {
2470
+ return {};
2471
+ }
2472
+ if (validSources.length === 1 && typeof validSources[0] === "object") {
2473
+ return validSources[0];
2474
+ }
2475
+ const resolveSource = (src) => {
2476
+ const value = typeof src === "function" ? src() : src;
2477
+ if (!value || typeof value !== "object") return void 0;
2478
+ return unwrapProps(value);
2479
+ };
2480
+ return new Proxy({}, {
2481
+ get(_, prop) {
2482
+ if (typeof prop === "symbol") {
2483
+ return void 0;
2484
+ }
2485
+ for (let i = validSources.length - 1; i >= 0; i--) {
2486
+ const src = validSources[i];
2487
+ const raw = resolveSource(src);
2488
+ if (!raw || !(prop in raw)) continue;
2489
+ const value = raw[prop];
2490
+ if (typeof src === "function" && !isPropGetter(value)) {
2491
+ return __fictProp(() => {
2492
+ const latest = resolveSource(src);
2493
+ if (!latest || !(prop in latest)) return void 0;
2494
+ return latest[prop];
2495
+ });
2496
+ }
2497
+ return value;
2498
+ }
2499
+ return void 0;
2500
+ },
2501
+ has(_, prop) {
2502
+ for (const src of validSources) {
2503
+ const raw = resolveSource(src);
2504
+ if (raw && prop in raw) {
2505
+ return true;
2506
+ }
2507
+ }
2508
+ return false;
2509
+ },
2510
+ ownKeys() {
2511
+ const keys = /* @__PURE__ */ new Set();
2512
+ for (const src of validSources) {
2513
+ const raw = resolveSource(src);
2514
+ if (raw) {
2515
+ for (const key of Reflect.ownKeys(raw)) {
2516
+ keys.add(key);
2517
+ }
2518
+ }
2519
+ }
2520
+ return Array.from(keys);
2521
+ },
2522
+ getOwnPropertyDescriptor(_, prop) {
2523
+ for (let i = validSources.length - 1; i >= 0; i--) {
2524
+ const raw = resolveSource(validSources[i]);
2525
+ if (raw && prop in raw) {
2526
+ return {
2527
+ enumerable: true,
2528
+ configurable: true,
2529
+ get: () => {
2530
+ const value = raw[prop];
2531
+ return value;
2532
+ }
2533
+ };
2534
+ }
2535
+ }
2536
+ return void 0;
2537
+ }
2538
+ });
2539
+ }
2540
+ function useProp(getter) {
2541
+ return __fictProp(createMemo(getter));
2542
+ }
2543
+
2544
+ // src/dom.ts
2545
+ function render(view, container) {
2546
+ const root = createRootContext();
2547
+ const prev = pushRoot(root);
2548
+ let dom;
2549
+ try {
2550
+ const output = view();
2551
+ dom = createElement(output);
2552
+ } finally {
2553
+ popRoot(prev);
2554
+ }
2555
+ container.replaceChildren(dom);
2556
+ container.setAttribute("data-fict-fine-grained", "1");
2557
+ flushOnMount(root);
2558
+ const teardown = () => {
2559
+ destroyRoot(root);
2560
+ container.innerHTML = "";
2561
+ };
2562
+ return teardown;
2563
+ }
2564
+ function createElement(node) {
2565
+ if (node instanceof Node) {
2566
+ return node;
2567
+ }
2568
+ if (node === null || node === void 0 || node === false) {
2569
+ return document.createTextNode("");
2570
+ }
2571
+ if (typeof node === "object" && node !== null && !(node instanceof Node)) {
2572
+ if ("marker" in node) {
2573
+ return createElement(node.marker);
2574
+ }
2575
+ const nodeRecord = node;
2576
+ if (nodeRecord[PRIMITIVE_PROXY]) {
2577
+ const primitiveGetter = nodeRecord[Symbol.toPrimitive];
2578
+ const value = typeof primitiveGetter === "function" ? primitiveGetter.call(node, "default") : node;
2579
+ return document.createTextNode(value == null || value === false ? "" : String(value));
2580
+ }
2581
+ }
2582
+ if (Array.isArray(node)) {
2583
+ const frag = document.createDocumentFragment();
2584
+ for (const child of node) {
2585
+ appendChildNode(frag, child);
2586
+ }
2587
+ return frag;
2588
+ }
2589
+ if (typeof node === "string" || typeof node === "number") {
2590
+ return document.createTextNode(String(node));
2591
+ }
2592
+ if (typeof node === "boolean") {
2593
+ return document.createTextNode("");
2594
+ }
2595
+ const vnode = node;
2596
+ if (typeof vnode.type === "function") {
2597
+ const rawProps = unwrapProps(vnode.props ?? {});
2598
+ const baseProps = vnode.key === void 0 ? rawProps : new Proxy(rawProps, {
2599
+ get(target, prop, receiver) {
2600
+ if (prop === "key") return vnode.key;
2601
+ return Reflect.get(target, prop, receiver);
2602
+ },
2603
+ has(target, prop) {
2604
+ if (prop === "key") return true;
2605
+ return prop in target;
2606
+ },
2607
+ ownKeys(target) {
2608
+ const keys = new Set(Reflect.ownKeys(target));
2609
+ keys.add("key");
2610
+ return Array.from(keys);
2611
+ },
2612
+ getOwnPropertyDescriptor(target, prop) {
2613
+ if (prop === "key") {
2614
+ return { enumerable: true, configurable: true, value: vnode.key };
2615
+ }
2616
+ return Object.getOwnPropertyDescriptor(target, prop);
2617
+ }
2618
+ });
2619
+ const props = createPropsProxy(baseProps);
2620
+ try {
2621
+ __fictPushContext();
2622
+ const rendered = vnode.type(props);
2623
+ __fictPopContext();
2624
+ return createElement(rendered);
2625
+ } catch (err) {
2626
+ __fictPopContext();
2627
+ if (handleSuspend(err)) {
2628
+ return document.createComment("fict:suspend");
2629
+ }
2630
+ handleError(err, { source: "render", componentName: vnode.type.name });
2631
+ throw err;
2632
+ }
2633
+ }
2634
+ if (vnode.type === Fragment) {
2635
+ const frag = document.createDocumentFragment();
2636
+ const children = vnode.props?.children;
2637
+ appendChildren(frag, children);
2638
+ return frag;
2639
+ }
2640
+ const tagName = typeof vnode.type === "string" ? vnode.type : "div";
2641
+ const el = document.createElement(tagName);
2642
+ applyProps(el, vnode.props ?? {});
2643
+ return el;
2644
+ }
2645
+ function template(html, isImportNode, isSVG, isMathML) {
2646
+ let node = null;
2647
+ const create = () => {
2648
+ const t = isMathML ? document.createElementNS("http://www.w3.org/1998/Math/MathML", "template") : document.createElement("template");
2649
+ t.innerHTML = html;
2650
+ if (isSVG) {
2651
+ return t.content.firstChild.firstChild;
2652
+ }
2653
+ if (isMathML) {
2654
+ return t.firstChild;
2655
+ }
2656
+ return t.content.firstChild;
2657
+ };
2658
+ const fn = isImportNode ? () => untrack2(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
2659
+ fn.cloneNode = fn;
2660
+ return fn;
2661
+ }
2662
+ function isBindingHandle(node) {
2663
+ return node !== null && typeof node === "object" && "marker" in node && "dispose" in node && typeof node.dispose === "function";
2664
+ }
2665
+ function appendChildNode(parent, child) {
2666
+ if (child === null || child === void 0 || child === false) {
2667
+ return;
2668
+ }
2669
+ if (isBindingHandle(child)) {
2670
+ appendChildNode(parent, child.marker);
2671
+ child.flush?.();
2672
+ return;
2673
+ }
2674
+ if (typeof child === "function" && child.length === 0) {
2675
+ const childGetter = child;
2676
+ createChildBinding(parent, childGetter, createElement);
2677
+ return;
2678
+ }
2679
+ if (Array.isArray(child)) {
2680
+ for (const item of child) {
2681
+ appendChildNode(parent, item);
2682
+ }
2683
+ return;
2684
+ }
2685
+ let domNode;
2686
+ if (typeof child !== "object" || child === null) {
2687
+ domNode = document.createTextNode(String(child ?? ""));
2688
+ } else {
2689
+ domNode = createElement(child);
2690
+ }
2691
+ if (domNode.nodeType === 11) {
2692
+ const children = Array.from(domNode.childNodes);
2693
+ for (const node of children) {
2694
+ appendChildNode(parent, node);
2695
+ }
2696
+ return;
2697
+ }
2698
+ if (domNode.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2699
+ parent.ownerDocument.adoptNode(domNode);
2700
+ }
2701
+ try {
2702
+ parent.appendChild(domNode);
2703
+ } catch (e) {
2704
+ if (parent.ownerDocument) {
2705
+ const clone = parent.ownerDocument.importNode(domNode, true);
2706
+ parent.appendChild(clone);
2707
+ return;
2708
+ }
2709
+ throw e;
2710
+ }
2711
+ }
2712
+ function appendChildren(parent, children) {
2713
+ if (children === void 0) return;
2714
+ if (Array.isArray(children)) {
2715
+ for (const child of children) {
2716
+ appendChildren(parent, child);
2717
+ }
2718
+ return;
2719
+ }
2720
+ appendChildNode(parent, children);
2721
+ }
2722
+ function applyRef(el, value) {
2723
+ if (typeof value === "function") {
2724
+ const refFn = value;
2725
+ refFn(el);
2726
+ if (getCurrentRoot()) {
2727
+ registerRootCleanup(() => {
2728
+ refFn(null);
2729
+ });
2730
+ }
2731
+ } else if (value && typeof value === "object" && "current" in value) {
2732
+ const refObj = value;
2733
+ refObj.current = el;
2734
+ if (getCurrentRoot()) {
2735
+ registerRootCleanup(() => {
2736
+ refObj.current = null;
2737
+ });
2738
+ }
2739
+ }
2740
+ }
2741
+ function applyProps(el, props, isSVG = false) {
2742
+ props = unwrapProps(props);
2743
+ const tagName = el.tagName;
2744
+ const isCE = tagName.includes("-") || "is" in props;
2745
+ for (const [key, value] of Object.entries(props)) {
2746
+ if (key === "children") continue;
2747
+ if (key === "ref") {
2748
+ applyRef(el, value);
2749
+ continue;
2750
+ }
2751
+ if (isEventKey(key)) {
2752
+ bindEvent(
2753
+ el,
2754
+ eventNameFromProp(key),
2755
+ value
2756
+ );
2757
+ continue;
2758
+ }
2759
+ if (key.slice(0, 3) === "on:") {
2760
+ bindEvent(
2761
+ el,
2762
+ key.slice(3),
2763
+ value,
2764
+ false
2765
+ // Non-delegated
2766
+ );
2767
+ continue;
2768
+ }
2769
+ if (key.slice(0, 10) === "oncapture:") {
2770
+ bindEvent(
2771
+ el,
2772
+ key.slice(10),
2773
+ value,
2774
+ true
2775
+ // Capture
2776
+ );
2777
+ continue;
2778
+ }
2779
+ if (key === "class" || key === "className") {
2780
+ createClassBinding(el, value);
2781
+ continue;
2782
+ }
2783
+ if (key === "classList") {
2784
+ createClassBinding(el, value);
2785
+ continue;
2786
+ }
2787
+ if (key === "style") {
2788
+ createStyleBinding(
2789
+ el,
2790
+ value
2791
+ );
2792
+ continue;
2793
+ }
2794
+ if (key === "dangerouslySetInnerHTML" && value && typeof value === "object") {
2795
+ const htmlValue = value.__html;
2796
+ if (htmlValue !== void 0) {
2797
+ if (isReactive(htmlValue)) {
2798
+ createAttributeBinding(el, "innerHTML", htmlValue, setInnerHTML);
2799
+ } else {
2800
+ el.innerHTML = htmlValue;
2801
+ }
2802
+ }
2803
+ continue;
2804
+ }
2805
+ if (ChildProperties.has(key)) {
2806
+ createAttributeBinding(el, key, value, setProperty);
2807
+ continue;
2808
+ }
2809
+ if (key.slice(0, 5) === "attr:") {
2810
+ createAttributeBinding(el, key.slice(5), value, setAttribute);
2811
+ continue;
2812
+ }
2813
+ if (key.slice(0, 5) === "bool:") {
2814
+ createAttributeBinding(el, key.slice(5), value, setBoolAttribute);
2815
+ continue;
2816
+ }
2817
+ if (key.slice(0, 5) === "prop:") {
2818
+ createAttributeBinding(el, key.slice(5), value, setProperty);
2819
+ continue;
2820
+ }
2821
+ const propAlias = !isSVG ? getPropAlias(key, tagName) : void 0;
2822
+ if (propAlias || !isSVG && Properties.has(key) || isCE && !isSVG) {
2823
+ const propName = propAlias || key;
2824
+ if (isCE && !Properties.has(key)) {
2825
+ createAttributeBinding(
2826
+ el,
2827
+ toPropertyName(propName),
2828
+ value,
2829
+ setProperty
2830
+ );
2831
+ } else {
2832
+ createAttributeBinding(el, propName, value, setProperty);
2833
+ }
2834
+ continue;
2835
+ }
2836
+ if (isSVG && key.indexOf(":") > -1) {
2837
+ const [prefix, name] = key.split(":");
2838
+ const ns = SVGNamespace[prefix];
2839
+ if (ns) {
2840
+ createAttributeBinding(
2841
+ el,
2842
+ key,
2843
+ value,
2844
+ (el2, _key, val) => setAttributeNS(el2, ns, name, val)
2845
+ );
2846
+ continue;
2847
+ }
2848
+ }
2849
+ const attrName = Aliases[key] || key;
2850
+ createAttributeBinding(el, attrName, value, setAttribute);
2851
+ }
2852
+ const children = props.children;
2853
+ appendChildren(el, children);
2854
+ }
2855
+ function toPropertyName(name) {
2856
+ return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
2857
+ }
2858
+ var setAttribute = (el, key, value) => {
2859
+ if (value === void 0 || value === null || value === false) {
2860
+ el.removeAttribute(key);
2861
+ return;
2862
+ }
2863
+ if (value === true) {
2864
+ el.setAttribute(key, "");
2865
+ return;
2866
+ }
2867
+ const valueType = typeof value;
2868
+ if (valueType === "string" || valueType === "number") {
2869
+ el.setAttribute(key, String(value));
2870
+ return;
2871
+ }
2872
+ if (key in el) {
2873
+ el[key] = value;
2874
+ return;
2875
+ }
2876
+ el.setAttribute(key, String(value));
2877
+ };
2878
+ var setProperty = (el, key, value) => {
2879
+ if (value === void 0 || value === null) {
2880
+ const fallback = key === "checked" || key === "selected" ? false : "";
2881
+ el[key] = fallback;
2882
+ return;
2883
+ }
2884
+ if (key === "style" && typeof value === "object" && value !== null) {
2885
+ for (const k in value) {
2886
+ const v = value[k];
2887
+ if (v !== void 0) {
2888
+ el.style[k] = String(v);
2889
+ }
2890
+ }
2891
+ return;
2892
+ }
2893
+ el[key] = value;
2894
+ };
2895
+ var setInnerHTML = (el, _key, value) => {
2896
+ el.innerHTML = value == null ? "" : String(value);
2897
+ };
2898
+ var setBoolAttribute = (el, key, value) => {
2899
+ if (value) {
2900
+ el.setAttribute(key, "");
2901
+ } else {
2902
+ el.removeAttribute(key);
2903
+ }
2904
+ };
2905
+ function setAttributeNS(el, namespace, name, value) {
2906
+ if (value == null) {
2907
+ el.removeAttributeNS(namespace, name);
2908
+ } else {
2909
+ el.setAttributeNS(namespace, name, String(value));
2910
+ }
2911
+ }
2912
+ function isEventKey(key) {
2913
+ return key.startsWith("on") && key.length > 2 && key[2].toUpperCase() === key[2];
2914
+ }
2915
+ function eventNameFromProp(key) {
2916
+ return key.slice(2).toLowerCase();
2917
+ }
2918
+
2919
+ // src/reconcile.ts
2920
+ function reconcileArrays(parentNode, a, b) {
2921
+ const bLength = b.length;
2922
+ let aEnd = a.length;
2923
+ let bEnd = bLength;
2924
+ let aStart = 0;
2925
+ let bStart = 0;
2926
+ const after = aEnd > 0 ? a[aEnd - 1].nextSibling : null;
2927
+ let map = null;
2928
+ while (aStart < aEnd || bStart < bEnd) {
2929
+ if (a[aStart] === b[bStart]) {
2930
+ aStart++;
2931
+ bStart++;
2932
+ continue;
2933
+ }
2934
+ while (a[aEnd - 1] === b[bEnd - 1]) {
2935
+ aEnd--;
2936
+ bEnd--;
2937
+ }
2938
+ if (aEnd === aStart) {
2939
+ const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] ?? null : after;
2940
+ const count = bEnd - bStart;
2941
+ const doc = parentNode.ownerDocument;
2942
+ if (count > 1 && doc) {
2943
+ const frag = doc.createDocumentFragment();
2944
+ for (let i = bStart; i < bEnd; i++) {
2945
+ frag.appendChild(b[i]);
2946
+ }
2947
+ parentNode.insertBefore(frag, node);
2948
+ bStart = bEnd;
2949
+ } else {
2950
+ while (bStart < bEnd) {
2951
+ parentNode.insertBefore(b[bStart++], node);
2952
+ }
2953
+ }
2954
+ } else if (bEnd === bStart) {
2955
+ while (aStart < aEnd) {
2956
+ const nodeToRemove = a[aStart];
2957
+ if (!map || !map.has(nodeToRemove)) {
2958
+ nodeToRemove.parentNode?.removeChild(nodeToRemove);
2959
+ }
2960
+ aStart++;
2961
+ }
2962
+ } else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
2963
+ const node = a[--aEnd].nextSibling;
2964
+ parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
2965
+ parentNode.insertBefore(b[--bEnd], node);
2966
+ a[aEnd] = b[bEnd];
2967
+ } else {
2968
+ if (!map) {
2969
+ map = /* @__PURE__ */ new Map();
2970
+ let i = bStart;
2971
+ while (i < bEnd) {
2972
+ map.set(b[i], i++);
2973
+ }
2974
+ }
2975
+ const index = map.get(a[aStart]);
2976
+ if (index != null) {
2977
+ if (bStart < index && index < bEnd) {
2978
+ let i = aStart;
2979
+ let sequence = 1;
2980
+ let t;
2981
+ while (++i < aEnd && i < bEnd) {
2982
+ t = map.get(a[i]);
2983
+ if (t == null || t !== index + sequence) break;
2984
+ sequence++;
2985
+ }
2986
+ if (sequence > index - bStart) {
2987
+ const node = a[aStart];
2988
+ while (bStart < index) {
2989
+ parentNode.insertBefore(b[bStart++], node);
2990
+ }
2991
+ } else {
2992
+ parentNode.replaceChild(b[bStart++], a[aStart++]);
2993
+ }
2994
+ } else {
2995
+ aStart++;
2996
+ }
2997
+ } else {
2998
+ const nodeToRemove = a[aStart++];
2999
+ nodeToRemove.parentNode?.removeChild(nodeToRemove);
3000
+ }
3001
+ }
3002
+ }
3003
+ }
3004
+
3005
+ // src/list-helpers.ts
3006
+ function moveNodesBefore(parent, nodes, anchor) {
3007
+ for (let i = nodes.length - 1; i >= 0; i--) {
3008
+ const node = nodes[i];
3009
+ if (!node || !(node instanceof Node)) {
3010
+ throw new Error("Invalid node in moveNodesBefore");
3011
+ }
3012
+ if (node.nextSibling !== anchor) {
3013
+ if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
3014
+ parent.ownerDocument.adoptNode(node);
3015
+ }
3016
+ try {
3017
+ parent.insertBefore(node, anchor);
3018
+ } catch (e) {
3019
+ if (parent.ownerDocument) {
3020
+ try {
3021
+ const clone = parent.ownerDocument.importNode(node, true);
3022
+ parent.insertBefore(clone, anchor);
3023
+ continue;
3024
+ } catch {
3025
+ }
3026
+ }
3027
+ throw e;
3028
+ }
3029
+ }
3030
+ anchor = node;
3031
+ }
3032
+ }
3033
+ function moveMarkerBlock(parent, block, anchor) {
3034
+ const nodes = collectBlockNodes(block);
3035
+ if (nodes.length === 0) return;
3036
+ moveNodesBefore(parent, nodes, anchor);
3037
+ }
3038
+ function destroyMarkerBlock(block) {
3039
+ if (block.root) {
3040
+ destroyRoot(block.root);
3041
+ }
3042
+ removeBlockRange(block);
3043
+ }
3044
+ function collectBlockNodes(block) {
3045
+ const nodes = [];
3046
+ let cursor = block.start;
3047
+ while (cursor) {
3048
+ nodes.push(cursor);
3049
+ if (cursor === block.end) {
3050
+ break;
3051
+ }
3052
+ cursor = cursor.nextSibling;
3053
+ }
3054
+ return nodes;
3055
+ }
3056
+ function removeBlockRange(block) {
3057
+ let cursor = block.start;
3058
+ while (cursor) {
3059
+ const next = cursor.nextSibling;
3060
+ cursor.parentNode?.removeChild(cursor);
3061
+ if (cursor === block.end) {
3062
+ break;
3063
+ }
3064
+ cursor = next;
3065
+ }
3066
+ }
3067
+ function createVersionedSignalAccessor(initialValue) {
3068
+ let current = initialValue;
3069
+ let version = 0;
3070
+ const track = signal(version);
3071
+ function accessor(value) {
3072
+ if (arguments.length === 0) {
3073
+ track();
3074
+ return current;
3075
+ }
3076
+ current = value;
3077
+ version++;
3078
+ track(version);
3079
+ }
3080
+ return accessor;
3081
+ }
3082
+ function createKeyedListContainer() {
3083
+ const startMarker = document.createComment("fict:list:start");
3084
+ const endMarker = document.createComment("fict:list:end");
3085
+ const dispose = () => {
3086
+ for (const block of container.blocks.values()) {
3087
+ destroyRoot(block.root);
3088
+ }
3089
+ container.blocks.clear();
3090
+ container.nextBlocks.clear();
3091
+ const range = document.createRange();
3092
+ range.setStartBefore(startMarker);
3093
+ range.setEndAfter(endMarker);
3094
+ range.deleteContents();
3095
+ container.currentNodes = [];
3096
+ container.nextNodes = [];
3097
+ container.nextBlocks.clear();
3098
+ container.orderedBlocks.length = 0;
3099
+ container.nextOrderedBlocks.length = 0;
3100
+ container.orderedIndexByKey.clear();
3101
+ };
3102
+ const container = {
3103
+ startMarker,
3104
+ endMarker,
3105
+ blocks: /* @__PURE__ */ new Map(),
3106
+ nextBlocks: /* @__PURE__ */ new Map(),
3107
+ currentNodes: [startMarker, endMarker],
3108
+ nextNodes: [],
3109
+ orderedBlocks: [],
3110
+ nextOrderedBlocks: [],
3111
+ orderedIndexByKey: /* @__PURE__ */ new Map(),
3112
+ dispose
3113
+ };
3114
+ return container;
3115
+ }
3116
+ function createKeyedBlock(key, item, index, render2, needsIndex = true) {
3117
+ const itemSig = createVersionedSignalAccessor(item);
3118
+ const indexSig = needsIndex ? signal(index) : ((next) => {
3119
+ if (arguments.length === 0) return index;
3120
+ index = next;
3121
+ return index;
3122
+ });
3123
+ const root = createRootContext();
3124
+ const prevRoot = pushRoot(root);
3125
+ const prevSub = setActiveSub(void 0);
3126
+ let nodes = [];
3127
+ try {
3128
+ const rendered = render2(itemSig, indexSig, key);
3129
+ if (rendered instanceof Node || Array.isArray(rendered) && rendered.every((n) => n instanceof Node)) {
3130
+ nodes = toNodeArray(rendered);
3131
+ } else {
3132
+ const element = createElement(rendered);
3133
+ nodes = toNodeArray(element);
3134
+ }
3135
+ } finally {
3136
+ setActiveSub(prevSub);
3137
+ popRoot(prevRoot);
3138
+ flushOnMount(root);
3139
+ }
3140
+ return {
3141
+ key,
3142
+ nodes,
3143
+ root,
3144
+ item: itemSig,
3145
+ index: indexSig,
3146
+ rawItem: item,
3147
+ rawIndex: index
3148
+ };
3149
+ }
3150
+ function getFirstNodeAfter(marker) {
3151
+ return marker.nextSibling;
3152
+ }
3153
+ function createKeyedList(getItems, keyFn, renderItem, needsIndex) {
3154
+ const resolvedNeedsIndex = arguments.length >= 4 ? !!needsIndex : renderItem.length > 1;
3155
+ return createFineGrainedKeyedList(getItems, keyFn, renderItem, resolvedNeedsIndex);
3156
+ }
3157
+ function createFineGrainedKeyedList(getItems, keyFn, renderItem, needsIndex) {
3158
+ const container = createKeyedListContainer();
3159
+ const fragment = document.createDocumentFragment();
3160
+ fragment.append(container.startMarker, container.endMarker);
3161
+ let pendingItems = null;
3162
+ let disposed = false;
3163
+ const performDiff = () => {
3164
+ if (disposed) return;
3165
+ batch2(() => {
3166
+ const newItems = pendingItems || getItems();
3167
+ pendingItems = null;
3168
+ const oldBlocks = container.blocks;
3169
+ const newBlocks = container.nextBlocks;
3170
+ const prevOrderedBlocks = container.orderedBlocks;
3171
+ const nextOrderedBlocks = container.nextOrderedBlocks;
3172
+ const orderedIndexByKey = container.orderedIndexByKey;
3173
+ newBlocks.clear();
3174
+ nextOrderedBlocks.length = 0;
3175
+ orderedIndexByKey.clear();
3176
+ const endParent = container.endMarker.parentNode;
3177
+ const startParent = container.startMarker.parentNode;
3178
+ const parent = endParent && startParent && endParent === startParent && endParent.isConnected ? endParent : null;
3179
+ if (!parent) {
3180
+ pendingItems = newItems;
3181
+ queueMicrotask(performDiff);
3182
+ return;
3183
+ }
3184
+ if (newItems.length === 0) {
3185
+ if (oldBlocks.size > 0) {
3186
+ for (const block of oldBlocks.values()) {
3187
+ destroyRoot(block.root);
3188
+ removeNodes(block.nodes);
3189
+ }
3190
+ }
3191
+ oldBlocks.clear();
3192
+ newBlocks.clear();
3193
+ prevOrderedBlocks.length = 0;
3194
+ nextOrderedBlocks.length = 0;
3195
+ orderedIndexByKey.clear();
3196
+ container.currentNodes.length = 0;
3197
+ container.currentNodes.push(container.startMarker, container.endMarker);
3198
+ container.nextNodes.length = 0;
3199
+ return;
3200
+ }
3201
+ const prevCount = prevOrderedBlocks.length;
3202
+ let appendCandidate = prevCount > 0 && newItems.length >= prevCount;
3203
+ const appendedBlocks = [];
3204
+ newItems.forEach((item, index) => {
3205
+ const key = keyFn(item, index);
3206
+ const existed = oldBlocks.has(key);
3207
+ let block = oldBlocks.get(key);
3208
+ if (block) {
3209
+ if (block.rawItem !== item) {
3210
+ block.rawItem = item;
3211
+ block.item(item);
3212
+ }
3213
+ if (needsIndex && block.rawIndex !== index) {
3214
+ block.rawIndex = index;
3215
+ block.index(index);
3216
+ }
3217
+ }
3218
+ const existingBlock = newBlocks.get(key);
3219
+ if (existingBlock && existingBlock !== block) {
3220
+ destroyRoot(existingBlock.root);
3221
+ removeNodes(existingBlock.nodes);
3222
+ }
3223
+ if (block) {
3224
+ newBlocks.set(key, block);
3225
+ oldBlocks.delete(key);
3226
+ } else {
3227
+ const existingBlock2 = newBlocks.get(key);
3228
+ if (existingBlock2) {
3229
+ destroyRoot(existingBlock2.root);
3230
+ removeNodes(existingBlock2.nodes);
3231
+ }
3232
+ block = createKeyedBlock(key, item, index, renderItem, needsIndex);
3233
+ }
3234
+ const resolvedBlock = block;
3235
+ newBlocks.set(key, resolvedBlock);
3236
+ const position = orderedIndexByKey.get(key);
3237
+ if (position !== void 0) {
3238
+ appendCandidate = false;
3239
+ }
3240
+ if (appendCandidate) {
3241
+ if (index < prevCount) {
3242
+ if (!prevOrderedBlocks[index] || prevOrderedBlocks[index].key !== key) {
3243
+ appendCandidate = false;
3244
+ }
3245
+ } else if (existed) {
3246
+ appendCandidate = false;
3247
+ }
3248
+ }
3249
+ if (position !== void 0) {
3250
+ const prior = nextOrderedBlocks[position];
3251
+ if (prior && prior !== resolvedBlock) {
3252
+ destroyRoot(prior.root);
3253
+ removeNodes(prior.nodes);
3254
+ }
3255
+ nextOrderedBlocks[position] = resolvedBlock;
3256
+ } else {
3257
+ orderedIndexByKey.set(key, nextOrderedBlocks.length);
3258
+ nextOrderedBlocks.push(resolvedBlock);
3259
+ }
3260
+ if (appendCandidate && index >= prevCount) {
3261
+ appendedBlocks.push(resolvedBlock);
3262
+ }
3263
+ });
3264
+ const canAppend = appendCandidate && prevCount > 0 && newItems.length > prevCount && oldBlocks.size === 0 && appendedBlocks.length > 0;
3265
+ if (canAppend) {
3266
+ const appendedNodes = [];
3267
+ for (const block of appendedBlocks) {
3268
+ for (let i = 0; i < block.nodes.length; i++) {
3269
+ appendedNodes.push(block.nodes[i]);
3270
+ }
3271
+ }
3272
+ if (appendedNodes.length > 0) {
3273
+ insertNodesBefore(parent, appendedNodes, container.endMarker);
3274
+ const currentNodes = container.currentNodes;
3275
+ currentNodes.pop();
3276
+ for (let i = 0; i < appendedNodes.length; i++) {
3277
+ currentNodes.push(appendedNodes[i]);
3278
+ }
3279
+ currentNodes.push(container.endMarker);
3280
+ }
3281
+ container.blocks = newBlocks;
3282
+ container.nextBlocks = oldBlocks;
3283
+ container.orderedBlocks = nextOrderedBlocks;
3284
+ container.nextOrderedBlocks = prevOrderedBlocks;
3285
+ return;
3286
+ }
3287
+ if (oldBlocks.size > 0) {
3288
+ for (const block of oldBlocks.values()) {
3289
+ destroyRoot(block.root);
3290
+ removeNodes(block.nodes);
3291
+ }
3292
+ oldBlocks.clear();
3293
+ }
3294
+ if (newBlocks.size > 0 || container.currentNodes.length > 0) {
3295
+ const prevNodes = container.currentNodes;
3296
+ const nextNodes = container.nextNodes;
3297
+ nextNodes.length = 0;
3298
+ nextNodes.push(container.startMarker);
3299
+ for (let i = 0; i < nextOrderedBlocks.length; i++) {
3300
+ const nodes = nextOrderedBlocks[i].nodes;
3301
+ for (let j = 0; j < nodes.length; j++) {
3302
+ nextNodes.push(nodes[j]);
3303
+ }
3304
+ }
3305
+ nextNodes.push(container.endMarker);
3306
+ reconcileArrays(parent, prevNodes, nextNodes);
3307
+ container.currentNodes = nextNodes;
3308
+ container.nextNodes = prevNodes;
3309
+ }
3310
+ container.blocks = newBlocks;
3311
+ container.nextBlocks = oldBlocks;
3312
+ container.orderedBlocks = nextOrderedBlocks;
3313
+ container.nextOrderedBlocks = prevOrderedBlocks;
3314
+ });
3315
+ };
3316
+ const effectDispose = createRenderEffect(performDiff);
3317
+ return {
3318
+ marker: fragment,
3319
+ startMarker: container.startMarker,
3320
+ endMarker: container.endMarker,
3321
+ // Flush pending items - call after markers are inserted into DOM
3322
+ flush: () => {
3323
+ if (pendingItems !== null) {
3324
+ performDiff();
3325
+ }
3326
+ },
3327
+ dispose: () => {
3328
+ disposed = true;
3329
+ effectDispose?.();
3330
+ container.dispose();
3331
+ }
3332
+ };
3333
+ }
3334
+
3335
+ exports.$state = $state;
3336
+ exports.Fragment = Fragment;
3337
+ exports.__fictPopContext = __fictPopContext;
3338
+ exports.__fictProp = __fictProp;
3339
+ exports.__fictPropsRest = __fictPropsRest;
3340
+ exports.__fictPushContext = __fictPushContext;
3341
+ exports.__fictRender = __fictRender;
3342
+ exports.__fictResetContext = __fictResetContext;
3343
+ exports.__fictUseContext = __fictUseContext;
3344
+ exports.__fictUseEffect = __fictUseEffect;
3345
+ exports.__fictUseMemo = __fictUseMemo;
3346
+ exports.__fictUseSignal = __fictUseSignal;
3347
+ exports.batch = batch2;
3348
+ exports.bindAttribute = bindAttribute;
3349
+ exports.bindClass = bindClass;
3350
+ exports.bindEvent = bindEvent;
3351
+ exports.bindProperty = bindProperty;
3352
+ exports.bindRef = bindRef;
3353
+ exports.bindStyle = bindStyle;
3354
+ exports.bindText = bindText;
3355
+ exports.clearDelegatedEvents = clearDelegatedEvents;
3356
+ exports.createConditional = createConditional;
3357
+ exports.createEffect = createEffect;
3358
+ exports.createElement = createElement;
3359
+ exports.createKeyedBlock = createKeyedBlock;
3360
+ exports.createKeyedList = createKeyedList;
3361
+ exports.createKeyedListContainer = createKeyedListContainer;
3362
+ exports.createList = createList;
3363
+ exports.createMemo = createMemo;
3364
+ exports.createPropsProxy = createPropsProxy;
3365
+ exports.createRenderEffect = createRenderEffect;
3366
+ exports.createSelector = createSelector;
3367
+ exports.createSignal = signal;
3368
+ exports.delegateEvents = delegateEvents;
3369
+ exports.destroyMarkerBlock = destroyMarkerBlock;
3370
+ exports.getFirstNodeAfter = getFirstNodeAfter;
3371
+ exports.insert = insert;
3372
+ exports.insertNodesBefore = insertNodesBefore;
3373
+ exports.mergeProps = mergeProps;
3374
+ exports.moveMarkerBlock = moveMarkerBlock;
3375
+ exports.onDestroy = onDestroy;
3376
+ exports.prop = __fictProp;
3377
+ exports.removeNodes = removeNodes;
3378
+ exports.render = render;
3379
+ exports.template = template;
3380
+ exports.toNodeArray = toNodeArray;
3381
+ exports.untrack = untrack2;
3382
+ exports.useProp = useProp;
3383
+ //# sourceMappingURL=slim.cjs.map
3384
+ //# sourceMappingURL=slim.cjs.map