@fictjs/runtime 0.0.13 → 0.0.14

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