@fictjs/runtime 0.0.12 → 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 (65) 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/{slim.cjs → chunk-PMF6MWEV.cjs} +2557 -3110
  16. package/dist/chunk-PMF6MWEV.cjs.map +1 -0
  17. package/dist/{slim.js → chunk-RY4WDS6R.js} +2596 -3097
  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 +108 -4441
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +5 -1492
  26. package/dist/index.d.ts +5 -1492
  27. package/dist/index.dev.js +1020 -2788
  28. package/dist/index.dev.js.map +1 -1
  29. package/dist/index.js +63 -4301
  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 +10 -5
  42. package/src/advanced.ts +101 -0
  43. package/src/binding.ts +25 -422
  44. package/src/constants.ts +345 -344
  45. package/src/context.ts +300 -0
  46. package/src/cycle-guard.ts +124 -97
  47. package/src/delegated-events.ts +24 -0
  48. package/src/dom.ts +19 -25
  49. package/src/effect.ts +4 -0
  50. package/src/hooks.ts +9 -1
  51. package/src/index.ts +41 -130
  52. package/src/internal.ts +130 -0
  53. package/src/lifecycle.ts +13 -2
  54. package/src/list-helpers.ts +6 -65
  55. package/src/props.ts +48 -46
  56. package/src/signal.ts +59 -39
  57. package/src/store.ts +47 -7
  58. package/src/versioned-signal.ts +3 -3
  59. package/dist/jsx-runtime.d.cts +0 -671
  60. package/dist/jsx-runtime.d.ts +0 -671
  61. package/dist/slim.cjs.map +0 -1
  62. package/dist/slim.d.cts +0 -504
  63. package/dist/slim.d.ts +0 -504
  64. package/dist/slim.js.map +0 -1
  65. package/src/slim.ts +0 -69
package/dist/index.cjs CHANGED
@@ -1,4303 +1,40 @@
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
+
7
+
8
+
9
+
10
+
11
+
12
+
13
+
14
+
15
+
16
+
17
+
18
+
19
+
20
+
21
+
22
+
23
+
24
+
25
+
2
26
 
3
- // src/devtools.ts
4
- function getGlobalHook() {
5
- if (typeof globalThis === "undefined") return void 0;
6
- return globalThis.__FICT_DEVTOOLS_HOOK__;
7
- }
8
- function getDevtoolsHook() {
9
- return getGlobalHook();
10
- }
11
-
12
- // src/cycle-guard.ts
13
- var defaultOptions = {
14
- maxFlushCyclesPerMicrotask: 1e4,
15
- maxEffectRunsPerFlush: 2e4,
16
- windowSize: 5,
17
- highUsageRatio: 0.8,
18
- maxRootReentrantDepth: 10,
19
- enableWindowWarning: true,
20
- devMode: false
21
- };
22
- var options = {
23
- ...defaultOptions
24
- };
25
- var effectRunsThisFlush = 0;
26
- var windowUsage = [];
27
- var rootDepth = /* @__PURE__ */ new WeakMap();
28
- var flushWarned = false;
29
- var rootWarned = false;
30
- var windowWarned = false;
31
- function setCycleProtectionOptions(opts) {
32
- options = { ...options, ...opts };
33
- }
34
- function beginFlushGuard() {
35
- effectRunsThisFlush = 0;
36
- flushWarned = false;
37
- windowWarned = false;
38
- }
39
- function beforeEffectRunGuard() {
40
- const next = ++effectRunsThisFlush;
41
- if (next > options.maxFlushCyclesPerMicrotask || next > options.maxEffectRunsPerFlush) {
42
- const message = `[fict] cycle protection triggered: flush-budget-exceeded`;
43
- if (options.devMode) {
44
- throw new Error(message);
45
- }
46
- if (!flushWarned) {
47
- flushWarned = true;
48
- console.warn(message, { effectRuns: next });
49
- }
50
- return false;
51
- }
52
- return true;
53
- }
54
- function endFlushGuard() {
55
- recordWindowUsage(effectRunsThisFlush, options.maxFlushCyclesPerMicrotask);
56
- effectRunsThisFlush = 0;
57
- }
58
- function enterRootGuard(root) {
59
- const depth = (rootDepth.get(root) ?? 0) + 1;
60
- if (depth > options.maxRootReentrantDepth) {
61
- const message = `[fict] cycle protection triggered: root-reentry`;
62
- if (options.devMode) {
63
- throw new Error(message);
64
- }
65
- if (!rootWarned) {
66
- rootWarned = true;
67
- console.warn(message, { depth });
68
- }
69
- return false;
70
- }
71
- rootDepth.set(root, depth);
72
- return true;
73
- }
74
- function exitRootGuard(root) {
75
- const depth = rootDepth.get(root);
76
- if (depth === void 0) return;
77
- if (depth <= 1) {
78
- rootDepth.delete(root);
79
- } else {
80
- rootDepth.set(root, depth - 1);
81
- }
82
- }
83
- function recordWindowUsage(used, budget) {
84
- if (!options.enableWindowWarning) return;
85
- const entry = { used, budget };
86
- windowUsage.push(entry);
87
- if (windowUsage.length > options.windowSize) {
88
- windowUsage.shift();
89
- }
90
- if (windowWarned) return;
91
- if (windowUsage.length >= options.windowSize && windowUsage.every((item) => item.budget > 0 && item.used / item.budget >= options.highUsageRatio)) {
92
- windowWarned = true;
93
- reportCycle("high-usage-window", {
94
- windowSize: options.windowSize,
95
- ratio: options.highUsageRatio
96
- });
97
- }
98
- }
99
- function reportCycle(reason, detail = void 0) {
100
- const hook = getDevtoolsHook();
101
- hook?.cycleDetected?.(detail ? { reason, detail } : { reason });
102
- console.warn(`[fict] cycle protection triggered: ${reason}`, detail ?? "");
103
- }
104
-
105
- // src/lifecycle.ts
106
- var currentRoot;
107
- var currentEffectCleanups;
108
- var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
109
- var globalSuspenseHandlers = /* @__PURE__ */ new WeakMap();
110
- function createRootContext(parent = currentRoot) {
111
- return { parent, cleanups: [], destroyCallbacks: [] };
112
- }
113
- function pushRoot(root) {
114
- if (!enterRootGuard(root)) {
115
- return currentRoot;
116
- }
117
- const prev = currentRoot;
118
- currentRoot = root;
119
- return prev;
120
- }
121
- function getCurrentRoot() {
122
- return currentRoot;
123
- }
124
- function popRoot(prev) {
125
- if (currentRoot) {
126
- exitRootGuard(currentRoot);
127
- }
128
- currentRoot = prev;
129
- }
130
- function onMount(fn) {
131
- if (currentRoot) {
132
- (currentRoot.onMountCallbacks || (currentRoot.onMountCallbacks = [])).push(fn);
133
- return;
134
- }
135
- runLifecycle(fn);
136
- }
137
- function onDestroy(fn) {
138
- if (currentRoot) {
139
- currentRoot.destroyCallbacks.push(() => runLifecycle(fn));
140
- return;
141
- }
142
- runLifecycle(fn);
143
- }
144
- function onCleanup(fn) {
145
- registerEffectCleanup(fn);
146
- }
147
- function flushOnMount(root) {
148
- const cbs = root.onMountCallbacks;
149
- if (!cbs || cbs.length === 0) return;
150
- for (let i = 0; i < cbs.length; i++) {
151
- const cleanup = cbs[i]();
152
- if (typeof cleanup === "function") {
153
- root.cleanups.push(cleanup);
154
- }
155
- }
156
- cbs.length = 0;
157
- }
158
- function registerRootCleanup(fn) {
159
- if (currentRoot) {
160
- currentRoot.cleanups.push(fn);
161
- }
162
- }
163
- function clearRoot(root) {
164
- runCleanupList(root.cleanups);
165
- if (root.onMountCallbacks) {
166
- root.onMountCallbacks.length = 0;
167
- }
168
- }
169
- function destroyRoot(root) {
170
- clearRoot(root);
171
- runCleanupList(root.destroyCallbacks);
172
- if (root.errorHandlers) {
173
- root.errorHandlers.length = 0;
174
- }
175
- if (globalErrorHandlers.has(root)) {
176
- globalErrorHandlers.delete(root);
177
- }
178
- if (root.suspenseHandlers) {
179
- root.suspenseHandlers.length = 0;
180
- }
181
- if (globalSuspenseHandlers.has(root)) {
182
- globalSuspenseHandlers.delete(root);
183
- }
184
- }
185
- function createRoot(fn) {
186
- const root = createRootContext();
187
- const prev = pushRoot(root);
188
- let value;
189
- try {
190
- value = fn();
191
- } finally {
192
- popRoot(prev);
193
- }
194
- flushOnMount(root);
195
- return {
196
- dispose: () => destroyRoot(root),
197
- value
198
- };
199
- }
200
- function withEffectCleanups(bucket, fn) {
201
- const prev = currentEffectCleanups;
202
- currentEffectCleanups = bucket;
203
- try {
204
- return fn();
205
- } finally {
206
- currentEffectCleanups = prev;
207
- }
208
- }
209
- function registerEffectCleanup(fn) {
210
- if (currentEffectCleanups) {
211
- currentEffectCleanups.push(fn);
212
- } else {
213
- registerRootCleanup(fn);
214
- }
215
- }
216
- function runCleanupList(list) {
217
- let error;
218
- for (let i = list.length - 1; i >= 0; i--) {
219
- try {
220
- const cleanup = list[i];
221
- if (cleanup) cleanup();
222
- } catch (err) {
223
- if (error === void 0) {
224
- error = err;
225
- }
226
- }
227
- }
228
- list.length = 0;
229
- if (error !== void 0) {
230
- if (!handleError(error, { source: "cleanup" })) {
231
- throw error;
232
- }
233
- }
234
- }
235
- function runLifecycle(fn) {
236
- const cleanup = fn();
237
- if (typeof cleanup === "function") {
238
- cleanup();
239
- }
240
- }
241
- function registerErrorHandler(fn) {
242
- if (!currentRoot) {
243
- throw new Error("registerErrorHandler must be called within a root");
244
- }
245
- if (!currentRoot.errorHandlers) {
246
- currentRoot.errorHandlers = [];
247
- }
248
- currentRoot.errorHandlers.push(fn);
249
- const existing = globalErrorHandlers.get(currentRoot);
250
- if (existing) {
251
- existing.push(fn);
252
- } else {
253
- globalErrorHandlers.set(currentRoot, [fn]);
254
- }
255
- }
256
- function registerSuspenseHandler(fn) {
257
- if (!currentRoot) {
258
- throw new Error("registerSuspenseHandler must be called within a root");
259
- }
260
- if (!currentRoot.suspenseHandlers) {
261
- currentRoot.suspenseHandlers = [];
262
- }
263
- currentRoot.suspenseHandlers.push(fn);
264
- const existing = globalSuspenseHandlers.get(currentRoot);
265
- if (existing) {
266
- existing.push(fn);
267
- } else {
268
- globalSuspenseHandlers.set(currentRoot, [fn]);
269
- }
270
- }
271
- function handleError(err, info, startRoot) {
272
- let root = startRoot ?? currentRoot;
273
- let error = err;
274
- while (root) {
275
- const handlers = root.errorHandlers;
276
- if (handlers && handlers.length) {
277
- for (let i = handlers.length - 1; i >= 0; i--) {
278
- const handler = handlers[i];
279
- try {
280
- const handled = handler(error, info);
281
- if (handled !== false) {
282
- return true;
283
- }
284
- } catch (nextErr) {
285
- error = nextErr;
286
- }
287
- }
288
- }
289
- root = root.parent;
290
- }
291
- const globalForRoot = startRoot ? globalErrorHandlers.get(startRoot) : currentRoot ? globalErrorHandlers.get(currentRoot) : void 0;
292
- if (globalForRoot && globalForRoot.length) {
293
- for (let i = globalForRoot.length - 1; i >= 0; i--) {
294
- const handler = globalForRoot[i];
295
- try {
296
- const handled = handler(error, info);
297
- if (handled !== false) {
298
- return true;
299
- }
300
- } catch (nextErr) {
301
- error = nextErr;
302
- }
303
- }
304
- }
305
- return false;
306
- }
307
- function handleSuspend(token, startRoot) {
308
- let root = startRoot ?? currentRoot;
309
- while (root) {
310
- const handlers = root.suspenseHandlers;
311
- if (handlers && handlers.length) {
312
- for (let i = handlers.length - 1; i >= 0; i--) {
313
- const handler = handlers[i];
314
- const handled = handler(token);
315
- if (handled !== false) return true;
316
- }
317
- }
318
- root = root.parent;
319
- }
320
- const globalForRoot = startRoot && globalSuspenseHandlers.get(startRoot) ? globalSuspenseHandlers.get(startRoot) : currentRoot ? globalSuspenseHandlers.get(currentRoot) : void 0;
321
- if (globalForRoot && globalForRoot.length) {
322
- for (let i = globalForRoot.length - 1; i >= 0; i--) {
323
- const handler = globalForRoot[i];
324
- const handled = handler(token);
325
- if (handled !== false) return true;
326
- }
327
- }
328
- return false;
329
- }
330
-
331
- // src/signal.ts
332
- var Mutable = 1;
333
- var Watching = 2;
334
- var Running = 4;
335
- var Dirty = 16;
336
- var Pending = 32;
337
- var MutableDirty = 17;
338
- var MutablePending = 33;
339
- var MutableRunning = 5;
340
- var WatchingRunning = 6;
341
- var cycle = 0;
342
- var batchDepth = 0;
343
- var activeSub;
344
- var flushScheduled = false;
345
- var highPriorityQueue = [];
346
- var lowPriorityQueue = [];
347
- var isInTransition = false;
348
- var enqueueMicrotask = typeof queueMicrotask === "function" ? queueMicrotask : (fn) => {
349
- Promise.resolve().then(fn);
350
- };
351
- var inCleanup = false;
352
- var SIGNAL_MARKER = Symbol.for("fict:signal");
353
- var COMPUTED_MARKER = Symbol.for("fict:computed");
354
- var EFFECT_MARKER = Symbol.for("fict:effect");
355
- var EFFECT_SCOPE_MARKER = Symbol.for("fict:effectScope");
356
- function link(dep, sub, version) {
357
- const prevDep = sub.depsTail;
358
- if (prevDep !== void 0 && prevDep.dep === dep) return;
359
- const nextDep = prevDep !== void 0 ? prevDep.nextDep : sub.deps;
360
- if (nextDep !== void 0 && nextDep.dep === dep) {
361
- nextDep.version = version;
362
- sub.depsTail = nextDep;
363
- return;
364
- }
365
- const prevSub = dep.subsTail;
366
- if (prevSub !== void 0 && prevSub.version === version && prevSub.sub === sub) return;
367
- const newLink = { version, dep, sub, prevDep, nextDep, prevSub, nextSub: void 0 };
368
- sub.depsTail = newLink;
369
- dep.subsTail = newLink;
370
- if (nextDep !== void 0) nextDep.prevDep = newLink;
371
- if (prevDep !== void 0) prevDep.nextDep = newLink;
372
- else sub.deps = newLink;
373
- if (prevSub !== void 0) prevSub.nextSub = newLink;
374
- else dep.subs = newLink;
375
- }
376
- function unlink(lnk, sub = lnk.sub) {
377
- const dep = lnk.dep;
378
- const prevDep = lnk.prevDep;
379
- const nextDep = lnk.nextDep;
380
- const nextSub = lnk.nextSub;
381
- const prevSub = lnk.prevSub;
382
- if (nextDep !== void 0) nextDep.prevDep = prevDep;
383
- else sub.depsTail = prevDep;
384
- if (prevDep !== void 0) prevDep.nextDep = nextDep;
385
- else sub.deps = nextDep;
386
- if (nextSub !== void 0) nextSub.prevSub = prevSub;
387
- else dep.subsTail = prevSub;
388
- if (prevSub !== void 0) prevSub.nextSub = nextSub;
389
- else if ((dep.subs = nextSub) === void 0) unwatched(dep);
390
- return nextDep;
391
- }
392
- function unwatched(dep) {
393
- if (!(dep.flags & Mutable)) {
394
- disposeNode(dep);
395
- } else if ("getter" in dep && dep.getter !== void 0) {
396
- dep.depsTail = void 0;
397
- dep.flags = MutableDirty;
398
- purgeDeps(dep);
399
- }
400
- }
401
- function propagate(firstLink) {
402
- let link2 = firstLink;
403
- let next = link2.nextSub;
404
- let stack;
405
- top: for (; ; ) {
406
- const sub = link2.sub;
407
- let flags = sub.flags;
408
- if (!(flags & 60)) {
409
- sub.flags = flags | Pending;
410
- } else if (!(flags & 12)) {
411
- flags = 0;
412
- } else if (!(flags & Running)) {
413
- sub.flags = flags & -9 | Pending;
414
- } else if (!(flags & 48)) {
415
- let vlink = sub.depsTail;
416
- let valid = false;
417
- while (vlink !== void 0) {
418
- if (vlink === link2) {
419
- valid = true;
420
- break;
421
- }
422
- vlink = vlink.prevDep;
423
- }
424
- if (valid) {
425
- sub.flags = flags | 40;
426
- flags &= Mutable;
427
- } else {
428
- flags = 0;
429
- }
430
- } else {
431
- flags = 0;
432
- }
433
- if (flags & Watching) notify(sub);
434
- if (flags & Mutable) {
435
- const subSubs = sub.subs;
436
- if (subSubs !== void 0) {
437
- const nextSub = subSubs.nextSub;
438
- if (nextSub !== void 0) {
439
- stack = { value: next, prev: stack };
440
- next = nextSub;
441
- }
442
- link2 = subSubs;
443
- continue;
444
- }
445
- }
446
- if (next !== void 0) {
447
- link2 = next;
448
- next = link2.nextSub;
449
- continue;
450
- }
451
- while (stack !== void 0) {
452
- link2 = stack.value;
453
- stack = stack.prev;
454
- if (link2 !== void 0) {
455
- next = link2.nextSub;
456
- continue top;
457
- }
458
- }
459
- break;
460
- }
461
- }
462
- function checkDirty(firstLink, sub) {
463
- let link2 = firstLink;
464
- let stack;
465
- let checkDepth = 0;
466
- let dirty = false;
467
- top: for (; ; ) {
468
- const dep = link2.dep;
469
- const depFlags = dep.flags;
470
- if (sub.flags & Dirty) {
471
- dirty = true;
472
- } else if ((depFlags & MutableDirty) === MutableDirty) {
473
- if (update(dep)) {
474
- const subs = dep.subs;
475
- if (subs !== void 0 && subs.nextSub !== void 0) shallowPropagate(subs);
476
- dirty = true;
477
- }
478
- } else if ((depFlags & MutablePending) === MutablePending) {
479
- if (!dep.deps) {
480
- const nextDep = link2.nextDep;
481
- if (nextDep !== void 0) {
482
- link2 = nextDep;
483
- continue;
484
- }
485
- } else {
486
- if (link2.nextSub !== void 0 || link2.prevSub !== void 0) {
487
- stack = { value: link2, prev: stack };
488
- }
489
- link2 = dep.deps;
490
- sub = dep;
491
- ++checkDepth;
492
- continue;
493
- }
494
- }
495
- if (!dirty) {
496
- const nextDep = link2.nextDep;
497
- if (nextDep !== void 0) {
498
- link2 = nextDep;
499
- continue;
500
- }
501
- }
502
- while (checkDepth-- > 0) {
503
- const firstSub = sub.subs;
504
- const hasMultipleSubs = firstSub.nextSub !== void 0;
505
- if (hasMultipleSubs) {
506
- link2 = stack.value;
507
- stack = stack.prev;
508
- } else {
509
- link2 = firstSub;
510
- }
511
- if (dirty) {
512
- if (update(sub)) {
513
- if (hasMultipleSubs) shallowPropagate(firstSub);
514
- sub = link2.sub;
515
- continue;
516
- }
517
- dirty = false;
518
- } else {
519
- sub.flags &= ~Pending;
520
- }
521
- sub = link2.sub;
522
- const nextDep = link2.nextDep;
523
- if (nextDep !== void 0) {
524
- link2 = nextDep;
525
- continue top;
526
- }
527
- }
528
- return dirty;
529
- }
530
- }
531
- function shallowPropagate(firstLink) {
532
- let link2 = firstLink;
533
- do {
534
- const sub = link2.sub;
535
- const flags = sub.flags;
536
- if ((flags & 48) === Pending) {
537
- sub.flags = flags | Dirty;
538
- if ((flags & 6) === Watching) notify(sub);
539
- }
540
- link2 = link2.nextSub;
541
- } while (link2 !== void 0);
542
- }
543
- function update(node) {
544
- return "getter" in node && node.getter !== void 0 ? updateComputed(node) : updateSignal(node);
545
- }
546
- function notify(effect2) {
547
- effect2.flags &= ~Watching;
548
- const effects = [];
549
- for (; ; ) {
550
- effects.push(effect2);
551
- const nextLink = effect2.subs;
552
- if (nextLink === void 0) break;
553
- effect2 = nextLink.sub;
554
- if (effect2 === void 0 || !(effect2.flags & Watching)) break;
555
- effect2.flags &= ~Watching;
556
- }
557
- const targetQueue = isInTransition ? lowPriorityQueue : highPriorityQueue;
558
- for (let i = effects.length - 1; i >= 0; i--) {
559
- targetQueue.push(effects[i]);
560
- }
561
- }
562
- function purgeDeps(sub) {
563
- const depsTail = sub.depsTail;
564
- let dep = depsTail !== void 0 ? depsTail.nextDep : sub.deps;
565
- while (dep !== void 0) dep = unlink(dep, sub);
566
- }
567
- function disposeNode(node) {
568
- node.depsTail = void 0;
569
- node.flags = 0;
570
- purgeDeps(node);
571
- let sub = node.subs;
572
- while (sub !== void 0) {
573
- const next = sub.nextSub;
574
- unlink(sub);
575
- sub = next;
576
- }
577
- }
578
- function updateSignal(s) {
579
- s.flags = Mutable;
580
- const current = s.currentValue;
581
- const pending = s.pendingValue;
582
- if (current !== pending) {
583
- s.currentValue = pending;
584
- return true;
585
- }
586
- return false;
587
- }
588
- function updateComputed(c) {
589
- ++cycle;
590
- const oldValue = c.value;
591
- c.depsTail = void 0;
592
- c.flags = MutableRunning;
593
- const prevSub = activeSub;
594
- activeSub = c;
595
- try {
596
- const newValue = c.getter(oldValue);
597
- activeSub = prevSub;
598
- c.flags &= ~Running;
599
- purgeDeps(c);
600
- if (oldValue !== newValue) {
601
- c.value = newValue;
602
- return true;
603
- }
604
- return false;
605
- } catch (e) {
606
- activeSub = prevSub;
607
- c.flags &= ~Running;
608
- throw e;
609
- }
610
- }
611
- function runEffect(e) {
612
- const flags = e.flags;
613
- if (flags & Dirty) {
614
- if (e.runCleanup) {
615
- inCleanup = true;
616
- try {
617
- e.runCleanup();
618
- } finally {
619
- inCleanup = false;
620
- }
621
- }
622
- ++cycle;
623
- effectRunDevtools(e);
624
- e.depsTail = void 0;
625
- e.flags = WatchingRunning;
626
- const prevSub = activeSub;
627
- activeSub = e;
628
- try {
629
- e.fn();
630
- activeSub = prevSub;
631
- e.flags = Watching;
632
- purgeDeps(e);
633
- } catch (err) {
634
- activeSub = prevSub;
635
- e.flags = Watching;
636
- throw err;
637
- }
638
- } else if (flags & Pending && e.deps) {
639
- if (e.runCleanup) {
640
- inCleanup = true;
641
- try {
642
- e.runCleanup();
643
- } finally {
644
- inCleanup = false;
645
- }
646
- }
647
- if (checkDirty(e.deps, e)) {
648
- ++cycle;
649
- effectRunDevtools(e);
650
- e.depsTail = void 0;
651
- e.flags = WatchingRunning;
652
- const prevSub = activeSub;
653
- activeSub = e;
654
- try {
655
- e.fn();
656
- activeSub = prevSub;
657
- e.flags = Watching;
658
- purgeDeps(e);
659
- } catch (err) {
660
- activeSub = prevSub;
661
- e.flags = Watching;
662
- throw err;
663
- }
664
- } else {
665
- e.flags = Watching;
666
- }
667
- } else {
668
- e.flags = Watching;
669
- }
670
- }
671
- function scheduleFlush() {
672
- const hasWork = highPriorityQueue.length > 0 || lowPriorityQueue.length > 0;
673
- if (flushScheduled || !hasWork) return;
674
- if (batchDepth > 0) return;
675
- flushScheduled = true;
676
- enqueueMicrotask(() => {
677
- flush();
678
- });
679
- }
680
- function flush() {
681
- beginFlushGuard();
682
- if (batchDepth > 0) {
683
- scheduleFlush();
684
- endFlushGuard();
685
- return;
686
- }
687
- const hasWork = highPriorityQueue.length > 0 || lowPriorityQueue.length > 0;
688
- if (!hasWork) {
689
- flushScheduled = false;
690
- endFlushGuard();
691
- return;
692
- }
693
- flushScheduled = false;
694
- let highIndex = 0;
695
- while (highIndex < highPriorityQueue.length) {
696
- const e = highPriorityQueue[highIndex];
697
- if (!beforeEffectRunGuard()) {
698
- if (highIndex > 0) {
699
- highPriorityQueue.copyWithin(0, highIndex);
700
- highPriorityQueue.length -= highIndex;
701
- }
702
- endFlushGuard();
703
- return;
704
- }
705
- highIndex++;
706
- runEffect(e);
707
- }
708
- highPriorityQueue.length = 0;
709
- let lowIndex = 0;
710
- while (lowIndex < lowPriorityQueue.length) {
711
- if (highPriorityQueue.length > 0) {
712
- if (lowIndex > 0) {
713
- lowPriorityQueue.copyWithin(0, lowIndex);
714
- lowPriorityQueue.length -= lowIndex;
715
- }
716
- scheduleFlush();
717
- endFlushGuard();
718
- return;
719
- }
720
- const e = lowPriorityQueue[lowIndex];
721
- if (!beforeEffectRunGuard()) {
722
- if (lowIndex > 0) {
723
- lowPriorityQueue.copyWithin(0, lowIndex);
724
- lowPriorityQueue.length -= lowIndex;
725
- }
726
- endFlushGuard();
727
- return;
728
- }
729
- lowIndex++;
730
- runEffect(e);
731
- }
732
- lowPriorityQueue.length = 0;
733
- endFlushGuard();
734
- }
735
- function signal(initialValue) {
736
- const s = {
737
- currentValue: initialValue,
738
- pendingValue: initialValue,
739
- subs: void 0,
740
- subsTail: void 0,
741
- flags: Mutable,
742
- __id: void 0
743
- };
744
- registerSignalDevtools(initialValue, s);
745
- const accessor = signalOper.bind(s);
746
- accessor[SIGNAL_MARKER] = true;
747
- return accessor;
748
- }
749
- function signalOper(value) {
750
- if (arguments.length > 0) {
751
- if (this.pendingValue !== value) {
752
- this.pendingValue = value;
753
- this.flags = MutableDirty;
754
- updateSignalDevtools(this, value);
755
- const subs = this.subs;
756
- if (subs !== void 0) {
757
- propagate(subs);
758
- if (!batchDepth) scheduleFlush();
759
- }
760
- }
761
- return;
762
- }
763
- const flags = this.flags;
764
- if (flags & Dirty && !inCleanup) {
765
- if (updateSignal(this)) {
766
- const subs = this.subs;
767
- if (subs !== void 0) shallowPropagate(subs);
768
- }
769
- }
770
- let sub = activeSub;
771
- while (sub !== void 0) {
772
- if (sub.flags & 3) {
773
- link(this, sub, cycle);
774
- break;
775
- }
776
- const subSubs = sub.subs;
777
- sub = subSubs !== void 0 ? subSubs.sub : void 0;
778
- }
779
- return this.currentValue;
780
- }
781
- function computed(getter) {
782
- const c = {
783
- value: void 0,
784
- subs: void 0,
785
- subsTail: void 0,
786
- deps: void 0,
787
- depsTail: void 0,
788
- flags: 0,
789
- getter
790
- };
791
- const bound = computedOper.bind(c);
792
- bound[COMPUTED_MARKER] = true;
793
- return bound;
794
- }
795
- function computedOper() {
796
- const flags = this.flags;
797
- if (flags & Dirty) {
798
- if (updateComputed(this)) {
799
- const subs = this.subs;
800
- if (subs !== void 0) shallowPropagate(subs);
801
- }
802
- } else if (flags & Pending) {
803
- if (this.deps && checkDirty(this.deps, this)) {
804
- if (updateComputed(this)) {
805
- const subs = this.subs;
806
- if (subs !== void 0) shallowPropagate(subs);
807
- }
808
- } else {
809
- this.flags = flags & ~Pending;
810
- }
811
- } else if (!flags) {
812
- this.flags = MutableRunning;
813
- const prevSub = setActiveSub(this);
814
- try {
815
- this.value = this.getter(void 0);
816
- } finally {
817
- setActiveSub(prevSub);
818
- this.flags &= ~Running;
819
- }
820
- }
821
- if (activeSub !== void 0) link(this, activeSub, cycle);
822
- return this.value;
823
- }
824
- function effect(fn) {
825
- const e = {
826
- fn,
827
- subs: void 0,
828
- subsTail: void 0,
829
- deps: void 0,
830
- depsTail: void 0,
831
- flags: WatchingRunning,
832
- __id: void 0
833
- };
834
- registerEffectDevtools(e);
835
- const prevSub = activeSub;
836
- if (prevSub !== void 0) link(e, prevSub, 0);
837
- activeSub = e;
838
- try {
839
- effectRunDevtools(e);
840
- fn();
841
- } finally {
842
- activeSub = prevSub;
843
- e.flags &= ~Running;
844
- }
845
- const disposer = effectOper.bind(e);
846
- disposer[EFFECT_MARKER] = true;
847
- return disposer;
848
- }
849
- function effectWithCleanup(fn, cleanupRunner) {
850
- const e = {
851
- fn,
852
- subs: void 0,
853
- subsTail: void 0,
854
- deps: void 0,
855
- depsTail: void 0,
856
- flags: WatchingRunning,
857
- runCleanup: cleanupRunner,
858
- __id: void 0
859
- };
860
- registerEffectDevtools(e);
861
- const prevSub = activeSub;
862
- if (prevSub !== void 0) link(e, prevSub, 0);
863
- activeSub = e;
864
- try {
865
- effectRunDevtools(e);
866
- fn();
867
- } finally {
868
- activeSub = prevSub;
869
- e.flags &= ~Running;
870
- }
871
- const disposer = effectOper.bind(e);
872
- disposer[EFFECT_MARKER] = true;
873
- return disposer;
874
- }
875
- function effectOper() {
876
- disposeNode(this);
877
- }
878
- function effectScope(fn) {
879
- const e = { deps: void 0, depsTail: void 0, subs: void 0, subsTail: void 0, flags: 0 };
880
- const prevSub = activeSub;
881
- if (prevSub !== void 0) link(e, prevSub, 0);
882
- activeSub = e;
883
- try {
884
- fn();
885
- } finally {
886
- activeSub = prevSub;
887
- }
888
- const disposer = effectScopeOper.bind(e);
889
- disposer[EFFECT_SCOPE_MARKER] = true;
890
- return disposer;
891
- }
892
- function effectScopeOper() {
893
- disposeNode(this);
894
- }
895
- function batch(fn) {
896
- ++batchDepth;
897
- let hasError = false;
898
- try {
899
- return fn();
900
- } catch (e) {
901
- hasError = true;
902
- throw e;
903
- } finally {
904
- --batchDepth;
905
- if (!hasError && batchDepth === 0) {
906
- flush();
907
- }
908
- }
909
- }
910
- function setActiveSub(sub) {
911
- const prev = activeSub;
912
- activeSub = sub;
913
- return prev;
914
- }
915
- function untrack(fn) {
916
- const prev = activeSub;
917
- activeSub = void 0;
918
- try {
919
- return fn();
920
- } finally {
921
- activeSub = prev;
922
- }
923
- }
924
- function setTransitionContext(value) {
925
- const prev = isInTransition;
926
- isInTransition = value;
927
- return prev;
928
- }
929
- var $state = signal;
930
- var devtoolsSignalId = 0;
931
- var devtoolsEffectId = 0;
932
- function registerSignalDevtools(value, node) {
933
- const hook = getDevtoolsHook();
934
- if (!hook) return void 0;
935
- const id = ++devtoolsSignalId;
936
- hook.registerSignal(id, value);
937
- node.__id = id;
938
- return id;
939
- }
940
- function updateSignalDevtools(node, value) {
941
- const hook = getDevtoolsHook();
942
- if (!hook) return;
943
- const id = node.__id;
944
- if (id) hook.updateSignal(id, value);
945
- }
946
- function registerEffectDevtools(node) {
947
- const hook = getDevtoolsHook();
948
- if (!hook) return void 0;
949
- const id = ++devtoolsEffectId;
950
- hook.registerEffect(id);
951
- node.__id = id;
952
- return id;
953
- }
954
- function effectRunDevtools(node) {
955
- const hook = getDevtoolsHook();
956
- if (!hook) return;
957
- const id = node.__id;
958
- if (id) hook.effectRun(id);
959
- }
960
- function createSelector(source, equalityFn = (a, b) => a === b) {
961
- let current = source();
962
- const observers = /* @__PURE__ */ new Map();
963
- const dispose = effect(() => {
964
- const next = source();
965
- if (equalityFn(current, next)) return;
966
- const prevSig = observers.get(current);
967
- if (prevSig) prevSig(false);
968
- const nextSig = observers.get(next);
969
- if (nextSig) nextSig(true);
970
- current = next;
971
- });
972
- registerRootCleanup(() => {
973
- dispose();
974
- observers.clear();
975
- });
976
- return (key) => {
977
- let sig = observers.get(key);
978
- if (!sig) {
979
- sig = signal(equalityFn(key, current));
980
- observers.set(key, sig);
981
- registerRootCleanup(() => observers.delete(key));
982
- }
983
- return sig();
984
- };
985
- }
986
-
987
- // src/store.ts
988
- var PROXY = Symbol("fict:store-proxy");
989
- var TARGET = Symbol("fict:store-target");
990
- var ITERATE_KEY = Symbol("fict:iterate");
991
- function createStore(initialValue) {
992
- const unwrapped = unwrap(initialValue);
993
- const wrapped = wrap(unwrapped);
994
- function setStore(fn) {
995
- batch(() => {
996
- const result = fn(wrapped);
997
- if (result !== void 0) {
998
- reconcile(wrapped, result);
999
- }
1000
- });
1001
- }
1002
- return [wrapped, setStore];
1003
- }
1004
- var proxyCache = /* @__PURE__ */ new WeakMap();
1005
- var signalCache = /* @__PURE__ */ new WeakMap();
1006
- function wrap(value) {
1007
- if (value === null || typeof value !== "object") return value;
1008
- if (value[PROXY]) return value;
1009
- if (proxyCache.has(value)) return proxyCache.get(value);
1010
- const handler = {
1011
- get(target, prop, receiver) {
1012
- if (prop === PROXY) return true;
1013
- if (prop === TARGET) return target;
1014
- const value2 = Reflect.get(target, prop, receiver);
1015
- track(target, prop);
1016
- return wrap(value2);
1017
- },
1018
- has(target, prop) {
1019
- const result = Reflect.has(target, prop);
1020
- track(target, prop);
1021
- return result;
1022
- },
1023
- ownKeys(target) {
1024
- track(target, ITERATE_KEY);
1025
- return Reflect.ownKeys(target);
1026
- },
1027
- getOwnPropertyDescriptor(target, prop) {
1028
- track(target, prop);
1029
- return Reflect.getOwnPropertyDescriptor(target, prop);
1030
- },
1031
- set(target, prop, value2, receiver) {
1032
- if (prop === PROXY || prop === TARGET) return false;
1033
- const hadKey = Object.prototype.hasOwnProperty.call(target, prop);
1034
- const oldValue = Reflect.get(target, prop, receiver);
1035
- if (oldValue === value2) return true;
1036
- const result = Reflect.set(target, prop, value2, receiver);
1037
- if (result) {
1038
- trigger(target, prop);
1039
- if (!hadKey) {
1040
- trigger(target, ITERATE_KEY);
1041
- }
1042
- }
1043
- return result;
1044
- },
1045
- deleteProperty(target, prop) {
1046
- const hadKey = Object.prototype.hasOwnProperty.call(target, prop);
1047
- const result = Reflect.deleteProperty(target, prop);
1048
- if (result) {
1049
- trigger(target, prop);
1050
- if (hadKey) {
1051
- trigger(target, ITERATE_KEY);
1052
- }
1053
- }
1054
- return result;
1055
- }
1056
- };
1057
- const proxy = new Proxy(value, handler);
1058
- proxyCache.set(value, proxy);
1059
- return proxy;
1060
- }
1061
- function unwrap(value) {
1062
- if (value && typeof value === "object" && value[PROXY]) {
1063
- return value[TARGET];
1064
- }
1065
- return value;
1066
- }
1067
- function track(target, prop) {
1068
- let signals = signalCache.get(target);
1069
- if (!signals) {
1070
- signals = /* @__PURE__ */ new Map();
1071
- signalCache.set(target, signals);
1072
- }
1073
- let s = signals.get(prop);
1074
- if (!s) {
1075
- const initial = prop === ITERATE_KEY ? Reflect.ownKeys(target).length : getLastValue(target, prop);
1076
- s = signal(initial);
1077
- signals.set(prop, s);
1078
- }
1079
- s();
1080
- }
1081
- function trigger(target, prop) {
1082
- const signals = signalCache.get(target);
1083
- if (signals) {
1084
- const s = signals.get(prop);
1085
- if (s) {
1086
- if (prop === ITERATE_KEY) {
1087
- s(Reflect.ownKeys(target).length);
1088
- } else {
1089
- s(getLastValue(target, prop));
1090
- }
1091
- }
1092
- }
1093
- }
1094
- function getLastValue(target, prop) {
1095
- return target[prop];
1096
- }
1097
- function reconcile(target, value) {
1098
- if (target === value) return;
1099
- if (value === null || typeof value !== "object") return;
1100
- const realTarget = unwrap(target);
1101
- const realValue = unwrap(value);
1102
- const keys = /* @__PURE__ */ new Set([...Object.keys(realTarget), ...Object.keys(realValue)]);
1103
- for (const key of keys) {
1104
- if (realValue[key] === void 0 && realTarget[key] !== void 0) {
1105
- delete target[key];
1106
- } else if (realTarget[key] !== realValue[key]) {
1107
- target[key] = realValue[key];
1108
- }
1109
- }
1110
- }
1111
-
1112
- // src/memo.ts
1113
- function createMemo(fn) {
1114
- return computed(fn);
1115
- }
1116
- var $memo = createMemo;
1117
-
1118
- // src/effect.ts
1119
- function createEffect(fn) {
1120
- let cleanups = [];
1121
- const rootForError = getCurrentRoot();
1122
- const doCleanup = () => {
1123
- runCleanupList(cleanups);
1124
- cleanups = [];
1125
- };
1126
- const run = () => {
1127
- const bucket = [];
1128
- withEffectCleanups(bucket, () => {
1129
- try {
1130
- const maybeCleanup = fn();
1131
- if (typeof maybeCleanup === "function") {
1132
- bucket.push(maybeCleanup);
1133
- }
1134
- } catch (err) {
1135
- if (handleError(err, { source: "effect" }, rootForError)) {
1136
- return;
1137
- }
1138
- throw err;
1139
- }
1140
- });
1141
- cleanups = bucket;
1142
- };
1143
- const disposeEffect = effectWithCleanup(run, doCleanup);
1144
- const teardown = () => {
1145
- runCleanupList(cleanups);
1146
- disposeEffect();
1147
- };
1148
- registerRootCleanup(teardown);
1149
- return teardown;
1150
- }
1151
- var $effect = createEffect;
1152
- function createRenderEffect(fn) {
1153
- let cleanup;
1154
- const rootForError = getCurrentRoot();
1155
- const doCleanup = () => {
1156
- if (cleanup) {
1157
- cleanup();
1158
- cleanup = void 0;
1159
- }
1160
- };
1161
- const run = () => {
1162
- try {
1163
- const maybeCleanup = fn();
1164
- if (typeof maybeCleanup === "function") {
1165
- cleanup = maybeCleanup;
1166
- }
1167
- } catch (err) {
1168
- const handled = handleError(err, { source: "effect" }, rootForError);
1169
- if (handled) {
1170
- return;
1171
- }
1172
- throw err;
1173
- }
1174
- };
1175
- const disposeEffect = effectWithCleanup(run, doCleanup);
1176
- const teardown = () => {
1177
- if (cleanup) {
1178
- cleanup();
1179
- cleanup = void 0;
1180
- }
1181
- disposeEffect();
1182
- };
1183
- registerRootCleanup(teardown);
1184
- return teardown;
1185
- }
1186
-
1187
- // src/constants.ts
1188
- var booleans = [
1189
- "allowfullscreen",
1190
- "async",
1191
- "alpha",
1192
- // HTMLInputElement
1193
- "autofocus",
1194
- // HTMLElement prop
1195
- "autoplay",
1196
- "checked",
1197
- "controls",
1198
- "default",
1199
- "disabled",
1200
- "formnovalidate",
1201
- "hidden",
1202
- // HTMLElement prop
1203
- "indeterminate",
1204
- "inert",
1205
- // HTMLElement prop
1206
- "ismap",
1207
- "loop",
1208
- "multiple",
1209
- "muted",
1210
- "nomodule",
1211
- "novalidate",
1212
- "open",
1213
- "playsinline",
1214
- "readonly",
1215
- "required",
1216
- "reversed",
1217
- "seamless",
1218
- // HTMLIframeElement - non-standard
1219
- "selected",
1220
- // Experimental attributes
1221
- "adauctionheaders",
1222
- "browsingtopics",
1223
- "credentialless",
1224
- "defaultchecked",
1225
- "defaultmuted",
1226
- "defaultselected",
1227
- "defer",
1228
- "disablepictureinpicture",
1229
- "disableremoteplayback",
1230
- "preservespitch",
1231
- "shadowrootclonable",
1232
- "shadowrootcustomelementregistry",
1233
- "shadowrootdelegatesfocus",
1234
- "shadowrootserializable",
1235
- "sharedstoragewritable"
1236
- ];
1237
- var BooleanAttributes = new Set(booleans);
1238
- var Properties = /* @__PURE__ */ new Set([
1239
- // Core properties
1240
- "className",
1241
- "value",
1242
- // CamelCase booleans
1243
- "readOnly",
1244
- "noValidate",
1245
- "formNoValidate",
1246
- "isMap",
1247
- "noModule",
1248
- "playsInline",
1249
- // Experimental (camelCase)
1250
- "adAuctionHeaders",
1251
- "allowFullscreen",
1252
- "browsingTopics",
1253
- "defaultChecked",
1254
- "defaultMuted",
1255
- "defaultSelected",
1256
- "disablePictureInPicture",
1257
- "disableRemotePlayback",
1258
- "preservesPitch",
1259
- "shadowRootClonable",
1260
- "shadowRootCustomElementRegistry",
1261
- "shadowRootDelegatesFocus",
1262
- "shadowRootSerializable",
1263
- "sharedStorageWritable",
1264
- // All lowercase booleans
1265
- ...booleans
1266
- ]);
1267
- var ChildProperties = /* @__PURE__ */ new Set([
1268
- "innerHTML",
1269
- "textContent",
1270
- "innerText",
1271
- "children"
1272
- ]);
1273
- var Aliases = {
1274
- className: "class",
1275
- htmlFor: "for"
1276
- };
1277
- var PropAliases = {
1278
- // Direct mapping
1279
- class: "className",
1280
- // Element-specific mappings
1281
- novalidate: {
1282
- $: "noValidate",
1283
- FORM: 1
1284
- },
1285
- formnovalidate: {
1286
- $: "formNoValidate",
1287
- BUTTON: 1,
1288
- INPUT: 1
1289
- },
1290
- ismap: {
1291
- $: "isMap",
1292
- IMG: 1
1293
- },
1294
- nomodule: {
1295
- $: "noModule",
1296
- SCRIPT: 1
1297
- },
1298
- playsinline: {
1299
- $: "playsInline",
1300
- VIDEO: 1
1301
- },
1302
- readonly: {
1303
- $: "readOnly",
1304
- INPUT: 1,
1305
- TEXTAREA: 1
1306
- },
1307
- // Experimental element-specific
1308
- adauctionheaders: {
1309
- $: "adAuctionHeaders",
1310
- IFRAME: 1
1311
- },
1312
- allowfullscreen: {
1313
- $: "allowFullscreen",
1314
- IFRAME: 1
1315
- },
1316
- browsingtopics: {
1317
- $: "browsingTopics",
1318
- IMG: 1
1319
- },
1320
- defaultchecked: {
1321
- $: "defaultChecked",
1322
- INPUT: 1
1323
- },
1324
- defaultmuted: {
1325
- $: "defaultMuted",
1326
- AUDIO: 1,
1327
- VIDEO: 1
1328
- },
1329
- defaultselected: {
1330
- $: "defaultSelected",
1331
- OPTION: 1
1332
- },
1333
- disablepictureinpicture: {
1334
- $: "disablePictureInPicture",
1335
- VIDEO: 1
1336
- },
1337
- disableremoteplayback: {
1338
- $: "disableRemotePlayback",
1339
- AUDIO: 1,
1340
- VIDEO: 1
1341
- },
1342
- preservespitch: {
1343
- $: "preservesPitch",
1344
- AUDIO: 1,
1345
- VIDEO: 1
1346
- },
1347
- shadowrootclonable: {
1348
- $: "shadowRootClonable",
1349
- TEMPLATE: 1
1350
- },
1351
- shadowrootdelegatesfocus: {
1352
- $: "shadowRootDelegatesFocus",
1353
- TEMPLATE: 1
1354
- },
1355
- shadowrootserializable: {
1356
- $: "shadowRootSerializable",
1357
- TEMPLATE: 1
1358
- },
1359
- sharedstoragewritable: {
1360
- $: "sharedStorageWritable",
1361
- IFRAME: 1,
1362
- IMG: 1
1363
- }
1364
- };
1365
- function getPropAlias(prop, tagName) {
1366
- const a = PropAliases[prop];
1367
- if (typeof a === "object") {
1368
- return a[tagName] ? a["$"] : void 0;
1369
- }
1370
- return a;
1371
- }
1372
- var $$EVENTS = "_$FICT_DELEGATE";
1373
- var DelegatedEvents = /* @__PURE__ */ new Set([
1374
- "beforeinput",
1375
- "click",
1376
- "dblclick",
1377
- "contextmenu",
1378
- "focusin",
1379
- "focusout",
1380
- "input",
1381
- "keydown",
1382
- "keyup",
1383
- "mousedown",
1384
- "mousemove",
1385
- "mouseout",
1386
- "mouseover",
1387
- "mouseup",
1388
- "pointerdown",
1389
- "pointermove",
1390
- "pointerout",
1391
- "pointerover",
1392
- "pointerup",
1393
- "touchend",
1394
- "touchmove",
1395
- "touchstart"
1396
- ]);
1397
- var SVGElements = /* @__PURE__ */ new Set([
1398
- "altGlyph",
1399
- "altGlyphDef",
1400
- "altGlyphItem",
1401
- "animate",
1402
- "animateColor",
1403
- "animateMotion",
1404
- "animateTransform",
1405
- "circle",
1406
- "clipPath",
1407
- "color-profile",
1408
- "cursor",
1409
- "defs",
1410
- "desc",
1411
- "ellipse",
1412
- "feBlend",
1413
- "feColorMatrix",
1414
- "feComponentTransfer",
1415
- "feComposite",
1416
- "feConvolveMatrix",
1417
- "feDiffuseLighting",
1418
- "feDisplacementMap",
1419
- "feDistantLight",
1420
- "feDropShadow",
1421
- "feFlood",
1422
- "feFuncA",
1423
- "feFuncB",
1424
- "feFuncG",
1425
- "feFuncR",
1426
- "feGaussianBlur",
1427
- "feImage",
1428
- "feMerge",
1429
- "feMergeNode",
1430
- "feMorphology",
1431
- "feOffset",
1432
- "fePointLight",
1433
- "feSpecularLighting",
1434
- "feSpotLight",
1435
- "feTile",
1436
- "feTurbulence",
1437
- "filter",
1438
- "font",
1439
- "font-face",
1440
- "font-face-format",
1441
- "font-face-name",
1442
- "font-face-src",
1443
- "font-face-uri",
1444
- "foreignObject",
1445
- "g",
1446
- "glyph",
1447
- "glyphRef",
1448
- "hkern",
1449
- "image",
1450
- "line",
1451
- "linearGradient",
1452
- "marker",
1453
- "mask",
1454
- "metadata",
1455
- "missing-glyph",
1456
- "mpath",
1457
- "path",
1458
- "pattern",
1459
- "polygon",
1460
- "polyline",
1461
- "radialGradient",
1462
- "rect",
1463
- "set",
1464
- "stop",
1465
- "svg",
1466
- "switch",
1467
- "symbol",
1468
- "text",
1469
- "textPath",
1470
- "tref",
1471
- "tspan",
1472
- "use",
1473
- "view",
1474
- "vkern"
1475
- ]);
1476
- var SVGNamespace = {
1477
- xlink: "http://www.w3.org/1999/xlink",
1478
- xml: "http://www.w3.org/XML/1998/namespace"
1479
- };
1480
- var UnitlessStyles = /* @__PURE__ */ new Set([
1481
- "animationIterationCount",
1482
- "animation-iteration-count",
1483
- "borderImageOutset",
1484
- "border-image-outset",
1485
- "borderImageSlice",
1486
- "border-image-slice",
1487
- "borderImageWidth",
1488
- "border-image-width",
1489
- "boxFlex",
1490
- "box-flex",
1491
- "boxFlexGroup",
1492
- "box-flex-group",
1493
- "boxOrdinalGroup",
1494
- "box-ordinal-group",
1495
- "columnCount",
1496
- "column-count",
1497
- "columns",
1498
- "flex",
1499
- "flexGrow",
1500
- "flex-grow",
1501
- "flexPositive",
1502
- "flex-positive",
1503
- "flexShrink",
1504
- "flex-shrink",
1505
- "flexNegative",
1506
- "flex-negative",
1507
- "flexOrder",
1508
- "flex-order",
1509
- "gridRow",
1510
- "grid-row",
1511
- "gridRowEnd",
1512
- "grid-row-end",
1513
- "gridRowSpan",
1514
- "grid-row-span",
1515
- "gridRowStart",
1516
- "grid-row-start",
1517
- "gridColumn",
1518
- "grid-column",
1519
- "gridColumnEnd",
1520
- "grid-column-end",
1521
- "gridColumnSpan",
1522
- "grid-column-span",
1523
- "gridColumnStart",
1524
- "grid-column-start",
1525
- "fontWeight",
1526
- "font-weight",
1527
- "lineClamp",
1528
- "line-clamp",
1529
- "lineHeight",
1530
- "line-height",
1531
- "opacity",
1532
- "order",
1533
- "orphans",
1534
- "tabSize",
1535
- "tab-size",
1536
- "widows",
1537
- "zIndex",
1538
- "z-index",
1539
- "zoom",
1540
- "fillOpacity",
1541
- "fill-opacity",
1542
- "floodOpacity",
1543
- "flood-opacity",
1544
- "stopOpacity",
1545
- "stop-opacity",
1546
- "strokeDasharray",
1547
- "stroke-dasharray",
1548
- "strokeDashoffset",
1549
- "stroke-dashoffset",
1550
- "strokeMiterlimit",
1551
- "stroke-miterlimit",
1552
- "strokeOpacity",
1553
- "stroke-opacity",
1554
- "strokeWidth",
1555
- "stroke-width"
1556
- ]);
1557
-
1558
- // src/jsx.ts
1559
- var Fragment = Symbol("Fragment");
1560
-
1561
- // src/hooks.ts
1562
- var ctxStack = [];
1563
- function assertRenderContext(ctx, hookName) {
1564
- if (!ctx.rendering) {
1565
- throw new Error(`${hookName} can only be used during render execution`);
1566
- }
1567
- }
1568
- function __fictUseContext() {
1569
- if (ctxStack.length === 0) {
1570
- const ctx2 = { slots: [], cursor: 0, rendering: true };
1571
- ctxStack.push(ctx2);
1572
- return ctx2;
1573
- }
1574
- const ctx = ctxStack[ctxStack.length - 1];
1575
- ctx.cursor = 0;
1576
- ctx.rendering = true;
1577
- return ctx;
1578
- }
1579
- function __fictPushContext() {
1580
- const ctx = { slots: [], cursor: 0 };
1581
- ctxStack.push(ctx);
1582
- return ctx;
1583
- }
1584
- function __fictPopContext() {
1585
- ctxStack.pop();
1586
- }
1587
- function __fictResetContext() {
1588
- ctxStack.length = 0;
1589
- }
1590
- function __fictUseSignal(ctx, initial, slot) {
1591
- assertRenderContext(ctx, "__fictUseSignal");
1592
- const index = slot ?? ctx.cursor++;
1593
- if (!ctx.slots[index]) {
1594
- ctx.slots[index] = signal(initial);
1595
- }
1596
- return ctx.slots[index];
1597
- }
1598
- function __fictUseMemo(ctx, fn, slot) {
1599
- assertRenderContext(ctx, "__fictUseMemo");
1600
- const index = slot ?? ctx.cursor++;
1601
- if (!ctx.slots[index]) {
1602
- ctx.slots[index] = createMemo(fn);
1603
- }
1604
- return ctx.slots[index];
1605
- }
1606
- function __fictUseEffect(ctx, fn, slot) {
1607
- assertRenderContext(ctx, "__fictUseEffect");
1608
- const index = slot ?? ctx.cursor++;
1609
- if (!ctx.slots[index]) {
1610
- ctx.slots[index] = createEffect(fn);
1611
- }
1612
- }
1613
- function __fictRender(ctx, fn) {
1614
- ctxStack.push(ctx);
1615
- ctx.cursor = 0;
1616
- ctx.rendering = true;
1617
- try {
1618
- return fn();
1619
- } finally {
1620
- ctx.rendering = false;
1621
- ctxStack.pop();
1622
- }
1623
- }
1624
-
1625
- // src/props.ts
1626
- var propGetters = /* @__PURE__ */ new WeakSet();
1627
- var rawToProxy = /* @__PURE__ */ new WeakMap();
1628
- var proxyToRaw = /* @__PURE__ */ new WeakMap();
1629
- function __fictProp(getter) {
1630
- if (typeof getter === "function" && getter.length === 0) {
1631
- propGetters.add(getter);
1632
- }
1633
- return getter;
1634
- }
1635
- function isPropGetter(value) {
1636
- return typeof value === "function" && propGetters.has(value);
1637
- }
1638
- function createPropsProxy(props) {
1639
- if (!props || typeof props !== "object") {
1640
- return props;
1641
- }
1642
- if (proxyToRaw.has(props)) {
1643
- return props;
1644
- }
1645
- const cached = rawToProxy.get(props);
1646
- if (cached) {
1647
- return cached;
1648
- }
1649
- const proxy = new Proxy(props, {
1650
- get(target, prop, receiver) {
1651
- const value = Reflect.get(target, prop, receiver);
1652
- if (isPropGetter(value)) {
1653
- return value();
1654
- }
1655
- return value;
1656
- },
1657
- set(target, prop, value, receiver) {
1658
- return Reflect.set(target, prop, value, receiver);
1659
- },
1660
- has(target, prop) {
1661
- return prop in target;
1662
- },
1663
- ownKeys(target) {
1664
- return Reflect.ownKeys(target);
1665
- },
1666
- getOwnPropertyDescriptor(target, prop) {
1667
- return Object.getOwnPropertyDescriptor(target, prop);
1668
- }
1669
- });
1670
- rawToProxy.set(props, proxy);
1671
- proxyToRaw.set(proxy, props);
1672
- return proxy;
1673
- }
1674
- function unwrapProps(props) {
1675
- if (!props || typeof props !== "object") {
1676
- return props;
1677
- }
1678
- return proxyToRaw.get(props) ?? props;
1679
- }
1680
- function __fictPropsRest(props, exclude) {
1681
- const raw = unwrapProps(props);
1682
- const out = {};
1683
- const excludeSet = new Set(exclude);
1684
- for (const key of Reflect.ownKeys(raw)) {
1685
- if (excludeSet.has(key)) continue;
1686
- out[key] = raw[key];
1687
- }
1688
- return createPropsProxy(out);
1689
- }
1690
- function mergeProps(...sources) {
1691
- const validSources = sources.filter(
1692
- (s) => s != null && (typeof s === "object" || typeof s === "function")
1693
- );
1694
- if (validSources.length === 0) {
1695
- return {};
1696
- }
1697
- if (validSources.length === 1 && typeof validSources[0] === "object") {
1698
- return validSources[0];
1699
- }
1700
- const resolveSource = (src) => {
1701
- const value = typeof src === "function" ? src() : src;
1702
- if (!value || typeof value !== "object") return void 0;
1703
- return unwrapProps(value);
1704
- };
1705
- return new Proxy({}, {
1706
- get(_, prop) {
1707
- for (let i = validSources.length - 1; i >= 0; i--) {
1708
- const src = validSources[i];
1709
- const raw = resolveSource(src);
1710
- if (!raw || !(prop in raw)) continue;
1711
- const value = raw[prop];
1712
- if (typeof src === "function" && !isPropGetter(value)) {
1713
- return __fictProp(() => {
1714
- const latest = resolveSource(src);
1715
- if (!latest || !(prop in latest)) return void 0;
1716
- return latest[prop];
1717
- });
1718
- }
1719
- return value;
1720
- }
1721
- return void 0;
1722
- },
1723
- has(_, prop) {
1724
- for (const src of validSources) {
1725
- const raw = resolveSource(src);
1726
- if (raw && prop in raw) {
1727
- return true;
1728
- }
1729
- }
1730
- return false;
1731
- },
1732
- ownKeys() {
1733
- const keys = /* @__PURE__ */ new Set();
1734
- for (const src of validSources) {
1735
- const raw = resolveSource(src);
1736
- if (raw) {
1737
- for (const key of Reflect.ownKeys(raw)) {
1738
- keys.add(key);
1739
- }
1740
- }
1741
- }
1742
- return Array.from(keys);
1743
- },
1744
- getOwnPropertyDescriptor(_, prop) {
1745
- for (let i = validSources.length - 1; i >= 0; i--) {
1746
- const raw = resolveSource(validSources[i]);
1747
- if (raw && prop in raw) {
1748
- return {
1749
- enumerable: true,
1750
- configurable: true,
1751
- get: () => {
1752
- const value = raw[prop];
1753
- return value;
1754
- }
1755
- };
1756
- }
1757
- }
1758
- return void 0;
1759
- }
1760
- });
1761
- }
1762
- function useProp(getter) {
1763
- return __fictProp(createMemo(getter));
1764
- }
1765
-
1766
- // src/transition.ts
1767
- function startTransition(fn) {
1768
- const prev = setTransitionContext(true);
1769
- try {
1770
- fn();
1771
- } finally {
1772
- setTransitionContext(prev);
1773
- scheduleFlush();
1774
- }
1775
- }
1776
- function useTransition() {
1777
- const pending = signal(false);
1778
- const start = (fn) => {
1779
- startTransition(() => {
1780
- pending(true);
1781
- try {
1782
- fn();
1783
- } finally {
1784
- pending(false);
1785
- }
1786
- });
1787
- };
1788
- return [() => pending(), start];
1789
- }
1790
- function useDeferredValue(getValue) {
1791
- const deferredValue = signal(getValue());
1792
- createEffect(() => {
1793
- const newValue = getValue();
1794
- const currentDeferred = untrack(() => deferredValue());
1795
- if (currentDeferred !== newValue) {
1796
- startTransition(() => {
1797
- deferredValue(newValue);
1798
- });
1799
- }
1800
- });
1801
- return () => deferredValue();
1802
- }
1803
-
1804
- // src/scheduler.ts
1805
- function batch2(fn) {
1806
- return batch(fn);
1807
- }
1808
- function untrack2(fn) {
1809
- return untrack(fn);
1810
- }
1811
-
1812
- // src/dom.ts
1813
- var SVG_NS = "http://www.w3.org/2000/svg";
1814
- var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
1815
- function render(view, container) {
1816
- const root = createRootContext();
1817
- const prev = pushRoot(root);
1818
- let dom;
1819
- try {
1820
- const output = view();
1821
- dom = createElement(output);
1822
- } finally {
1823
- popRoot(prev);
1824
- }
1825
- container.replaceChildren(dom);
1826
- container.setAttribute("data-fict-fine-grained", "1");
1827
- flushOnMount(root);
1828
- const teardown = () => {
1829
- destroyRoot(root);
1830
- container.innerHTML = "";
1831
- };
1832
- return teardown;
1833
- }
1834
- function createElement(node) {
1835
- return createElementWithContext(node, null);
1836
- }
1837
- function resolveNamespace(tagName, namespace) {
1838
- if (tagName === "svg") return "svg";
1839
- if (tagName === "math") return "mathml";
1840
- if (namespace === "mathml") return "mathml";
1841
- if (namespace === "svg") return "svg";
1842
- if (SVGElements.has(tagName)) return "svg";
1843
- return null;
1844
- }
1845
- function createElementWithContext(node, namespace) {
1846
- if (node instanceof Node) {
1847
- return node;
1848
- }
1849
- if (node === null || node === void 0 || node === false) {
1850
- return document.createTextNode("");
1851
- }
1852
- if (typeof node === "object" && node !== null && !(node instanceof Node)) {
1853
- if ("marker" in node) {
1854
- const handle = node;
1855
- if (typeof handle.dispose === "function") {
1856
- registerRootCleanup(handle.dispose);
1857
- }
1858
- if (typeof handle.flush === "function") {
1859
- const runFlush = () => handle.flush && handle.flush();
1860
- if (typeof queueMicrotask === "function") {
1861
- queueMicrotask(runFlush);
1862
- } else {
1863
- Promise.resolve().then(runFlush).catch(() => void 0);
1864
- }
1865
- }
1866
- return createElement(handle.marker);
1867
- }
1868
- const nodeRecord = node;
1869
- if (nodeRecord[PRIMITIVE_PROXY]) {
1870
- const primitiveGetter = nodeRecord[Symbol.toPrimitive];
1871
- const value = typeof primitiveGetter === "function" ? primitiveGetter.call(node, "default") : node;
1872
- return document.createTextNode(value == null || value === false ? "" : String(value));
1873
- }
1874
- }
1875
- if (Array.isArray(node)) {
1876
- const frag = document.createDocumentFragment();
1877
- for (const child of node) {
1878
- appendChildNode(frag, child, namespace);
1879
- }
1880
- return frag;
1881
- }
1882
- if (typeof node === "string" || typeof node === "number") {
1883
- return document.createTextNode(String(node));
1884
- }
1885
- if (typeof node === "boolean") {
1886
- return document.createTextNode("");
1887
- }
1888
- const vnode = node;
1889
- if (typeof vnode.type === "function") {
1890
- const rawProps = unwrapProps(vnode.props ?? {});
1891
- const baseProps = vnode.key === void 0 ? rawProps : new Proxy(rawProps, {
1892
- get(target, prop, receiver) {
1893
- if (prop === "key") return vnode.key;
1894
- return Reflect.get(target, prop, receiver);
1895
- },
1896
- has(target, prop) {
1897
- if (prop === "key") return true;
1898
- return prop in target;
1899
- },
1900
- ownKeys(target) {
1901
- const keys = new Set(Reflect.ownKeys(target));
1902
- keys.add("key");
1903
- return Array.from(keys);
1904
- },
1905
- getOwnPropertyDescriptor(target, prop) {
1906
- if (prop === "key") {
1907
- return { enumerable: true, configurable: true, value: vnode.key };
1908
- }
1909
- return Object.getOwnPropertyDescriptor(target, prop);
1910
- }
1911
- });
1912
- const props = createPropsProxy(baseProps);
1913
- __fictPushContext();
1914
- try {
1915
- const rendered = vnode.type(props);
1916
- return createElementWithContext(rendered, namespace);
1917
- } catch (err) {
1918
- if (handleSuspend(err)) {
1919
- return document.createComment("fict:suspend");
1920
- }
1921
- handleError(err, { source: "render", componentName: vnode.type.name });
1922
- throw err;
1923
- } finally {
1924
- __fictPopContext();
1925
- }
1926
- }
1927
- if (vnode.type === Fragment) {
1928
- const frag = document.createDocumentFragment();
1929
- const children = vnode.props?.children;
1930
- appendChildren(frag, children, namespace);
1931
- return frag;
1932
- }
1933
- const tagName = typeof vnode.type === "string" ? vnode.type : "div";
1934
- const resolvedNamespace = resolveNamespace(tagName, namespace);
1935
- const el = resolvedNamespace === "svg" ? document.createElementNS(SVG_NS, tagName) : resolvedNamespace === "mathml" ? document.createElementNS(MATHML_NS, tagName) : document.createElement(tagName);
1936
- applyProps(el, vnode.props ?? {}, resolvedNamespace === "svg");
1937
- appendChildren(
1938
- el,
1939
- vnode.props?.children,
1940
- tagName === "foreignObject" ? null : resolvedNamespace
1941
- );
1942
- return el;
1943
- }
1944
- function template(html, isImportNode, isSVG, isMathML) {
1945
- let node = null;
1946
- const create = () => {
1947
- const t = isMathML ? document.createElementNS(MATHML_NS, "template") : document.createElement("template");
1948
- t.innerHTML = html;
1949
- if (isSVG) {
1950
- return t.content.firstChild.firstChild;
1951
- }
1952
- if (isMathML) {
1953
- return t.firstChild;
1954
- }
1955
- return t.content.firstChild;
1956
- };
1957
- const fn = isImportNode ? () => untrack2(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
1958
- fn.cloneNode = fn;
1959
- return fn;
1960
- }
1961
- function isBindingHandle(node) {
1962
- return node !== null && typeof node === "object" && "marker" in node && "dispose" in node && typeof node.dispose === "function";
1963
- }
1964
- function appendChildNode(parent, child, namespace) {
1965
- if (child === null || child === void 0 || child === false) {
1966
- return;
1967
- }
1968
- if (isBindingHandle(child)) {
1969
- appendChildNode(parent, child.marker, namespace);
1970
- child.flush?.();
1971
- return;
1972
- }
1973
- if (typeof child === "function" && child.length === 0) {
1974
- const childGetter = child;
1975
- createChildBinding(parent, childGetter, (node) => createElementWithContext(node, namespace));
1976
- return;
1977
- }
1978
- if (Array.isArray(child)) {
1979
- for (const item of child) {
1980
- appendChildNode(parent, item, namespace);
1981
- }
1982
- return;
1983
- }
1984
- let domNode;
1985
- if (typeof child !== "object" || child === null) {
1986
- domNode = document.createTextNode(String(child ?? ""));
1987
- } else {
1988
- domNode = createElementWithContext(child, namespace);
1989
- }
1990
- if (domNode.nodeType === 11) {
1991
- const children = Array.from(domNode.childNodes);
1992
- for (const node of children) {
1993
- appendChildNode(parent, node, namespace);
1994
- }
1995
- return;
1996
- }
1997
- if (domNode.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
1998
- parent.ownerDocument.adoptNode(domNode);
1999
- }
2000
- try {
2001
- parent.appendChild(domNode);
2002
- } catch (e) {
2003
- if (parent.ownerDocument) {
2004
- const clone = parent.ownerDocument.importNode(domNode, true);
2005
- parent.appendChild(clone);
2006
- return;
2007
- }
2008
- throw e;
2009
- }
2010
- }
2011
- function appendChildren(parent, children, namespace) {
2012
- if (children === void 0) return;
2013
- if (Array.isArray(children)) {
2014
- for (const child of children) {
2015
- appendChildren(parent, child, namespace);
2016
- }
2017
- return;
2018
- }
2019
- appendChildNode(parent, children, namespace);
2020
- }
2021
- function applyRef(el, value) {
2022
- if (typeof value === "function") {
2023
- const refFn = value;
2024
- refFn(el);
2025
- const root = getCurrentRoot();
2026
- if (root) {
2027
- registerRootCleanup(() => {
2028
- refFn(null);
2029
- });
2030
- }
2031
- } else if (value && typeof value === "object" && "current" in value) {
2032
- const refObj = value;
2033
- refObj.current = el;
2034
- const root = getCurrentRoot();
2035
- if (root) {
2036
- registerRootCleanup(() => {
2037
- refObj.current = null;
2038
- });
2039
- }
2040
- }
2041
- }
2042
- function applyProps(el, props, isSVG = false) {
2043
- props = unwrapProps(props);
2044
- const tagName = el.tagName;
2045
- const isCE = tagName.includes("-") || "is" in props;
2046
- for (const [key, value] of Object.entries(props)) {
2047
- if (key === "children") continue;
2048
- if (key === "ref") {
2049
- applyRef(el, value);
2050
- continue;
2051
- }
2052
- if (isEventKey(key)) {
2053
- bindEvent(
2054
- el,
2055
- eventNameFromProp(key),
2056
- value
2057
- );
2058
- continue;
2059
- }
2060
- if (key.slice(0, 3) === "on:") {
2061
- bindEvent(
2062
- el,
2063
- key.slice(3),
2064
- value,
2065
- false
2066
- // Non-delegated
2067
- );
2068
- continue;
2069
- }
2070
- if (key.slice(0, 10) === "oncapture:") {
2071
- bindEvent(
2072
- el,
2073
- key.slice(10),
2074
- value,
2075
- true
2076
- // Capture
2077
- );
2078
- continue;
2079
- }
2080
- if (key === "class" || key === "className") {
2081
- createClassBinding(el, value);
2082
- continue;
2083
- }
2084
- if (key === "classList") {
2085
- createClassBinding(el, value);
2086
- continue;
2087
- }
2088
- if (key === "style") {
2089
- createStyleBinding(
2090
- el,
2091
- value
2092
- );
2093
- continue;
2094
- }
2095
- if (key === "dangerouslySetInnerHTML" && value && typeof value === "object") {
2096
- const htmlValue = value.__html;
2097
- if (htmlValue !== void 0) {
2098
- if (isReactive(htmlValue)) {
2099
- createAttributeBinding(el, "innerHTML", htmlValue, setInnerHTML);
2100
- } else {
2101
- el.innerHTML = htmlValue;
2102
- }
2103
- }
2104
- continue;
2105
- }
2106
- if (ChildProperties.has(key)) {
2107
- createAttributeBinding(el, key, value, setProperty);
2108
- continue;
2109
- }
2110
- if (key.slice(0, 5) === "attr:") {
2111
- createAttributeBinding(el, key.slice(5), value, setAttribute);
2112
- continue;
2113
- }
2114
- if (key.slice(0, 5) === "bool:") {
2115
- createAttributeBinding(el, key.slice(5), value, setBoolAttribute);
2116
- continue;
2117
- }
2118
- if (key.slice(0, 5) === "prop:") {
2119
- createAttributeBinding(el, key.slice(5), value, setProperty);
2120
- continue;
2121
- }
2122
- const propAlias = !isSVG ? getPropAlias(key, tagName) : void 0;
2123
- if (propAlias || !isSVG && Properties.has(key) || isCE && !isSVG) {
2124
- const propName = propAlias || key;
2125
- if (isCE && !Properties.has(key)) {
2126
- createAttributeBinding(
2127
- el,
2128
- toPropertyName(propName),
2129
- value,
2130
- setProperty
2131
- );
2132
- } else {
2133
- createAttributeBinding(el, propName, value, setProperty);
2134
- }
2135
- continue;
2136
- }
2137
- if (isSVG && key.indexOf(":") > -1) {
2138
- const [prefix, name] = key.split(":");
2139
- const ns = SVGNamespace[prefix];
2140
- if (ns) {
2141
- createAttributeBinding(
2142
- el,
2143
- key,
2144
- value,
2145
- (el2, _key, val) => setAttributeNS(el2, ns, name, val)
2146
- );
2147
- continue;
2148
- }
2149
- }
2150
- const attrName = Aliases[key] || key;
2151
- createAttributeBinding(el, attrName, value, setAttribute);
2152
- }
2153
- }
2154
- function toPropertyName(name) {
2155
- return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
2156
- }
2157
- var setAttribute = (el, key, value) => {
2158
- if (value === void 0 || value === null || value === false) {
2159
- el.removeAttribute(key);
2160
- return;
2161
- }
2162
- if (value === true) {
2163
- el.setAttribute(key, "");
2164
- return;
2165
- }
2166
- const valueType = typeof value;
2167
- if (valueType === "string" || valueType === "number") {
2168
- el.setAttribute(key, String(value));
2169
- return;
2170
- }
2171
- if (key in el) {
2172
- el[key] = value;
2173
- return;
2174
- }
2175
- el.setAttribute(key, String(value));
2176
- };
2177
- var setProperty = (el, key, value) => {
2178
- if (value === void 0 || value === null) {
2179
- const fallback = key === "checked" || key === "selected" ? false : "";
2180
- el[key] = fallback;
2181
- return;
2182
- }
2183
- if (key === "style" && typeof value === "object" && value !== null) {
2184
- for (const k in value) {
2185
- const v = value[k];
2186
- if (v !== void 0) {
2187
- el.style[k] = String(v);
2188
- }
2189
- }
2190
- return;
2191
- }
2192
- el[key] = value;
2193
- };
2194
- var setInnerHTML = (el, _key, value) => {
2195
- el.innerHTML = value == null ? "" : String(value);
2196
- };
2197
- var setBoolAttribute = (el, key, value) => {
2198
- if (value) {
2199
- el.setAttribute(key, "");
2200
- } else {
2201
- el.removeAttribute(key);
2202
- }
2203
- };
2204
- function setAttributeNS(el, namespace, name, value) {
2205
- if (value == null) {
2206
- el.removeAttributeNS(namespace, name);
2207
- } else {
2208
- el.setAttributeNS(namespace, name, String(value));
2209
- }
2210
- }
2211
- function isEventKey(key) {
2212
- return key.startsWith("on") && key.length > 2 && key[2].toUpperCase() === key[2];
2213
- }
2214
- function eventNameFromProp(key) {
2215
- return key.slice(2).toLowerCase();
2216
- }
2217
-
2218
- // src/node-ops.ts
2219
- function toNodeArray(node) {
2220
- try {
2221
- if (Array.isArray(node)) {
2222
- let allNodes = true;
2223
- for (const item of node) {
2224
- let isItemNode = false;
2225
- try {
2226
- isItemNode = item instanceof Node;
2227
- } catch {
2228
- isItemNode = false;
2229
- }
2230
- if (!isItemNode) {
2231
- allNodes = false;
2232
- break;
2233
- }
2234
- }
2235
- if (allNodes) {
2236
- return node;
2237
- }
2238
- const result = [];
2239
- for (const item of node) {
2240
- result.push(...toNodeArray(item));
2241
- }
2242
- return result;
2243
- }
2244
- if (node === null || node === void 0 || node === false) {
2245
- return [];
2246
- }
2247
- } catch {
2248
- return [];
2249
- }
2250
- let isNode = false;
2251
- try {
2252
- isNode = node instanceof Node;
2253
- } catch {
2254
- isNode = false;
2255
- }
2256
- if (isNode) {
2257
- try {
2258
- if (node instanceof DocumentFragment) {
2259
- return Array.from(node.childNodes);
2260
- }
2261
- } catch {
2262
- }
2263
- return [node];
2264
- }
2265
- try {
2266
- if (typeof node === "object" && node !== null && "marker" in node) {
2267
- return toNodeArray(node.marker);
2268
- }
2269
- } catch {
2270
- }
2271
- try {
2272
- return [document.createTextNode(String(node))];
2273
- } catch {
2274
- return [document.createTextNode("")];
2275
- }
2276
- }
2277
- function insertNodesBefore(parent, nodes, anchor) {
2278
- if (nodes.length === 0) return;
2279
- if (nodes.length === 1) {
2280
- const node = nodes[0];
2281
- if (node === void 0 || node === null) return;
2282
- if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2283
- parent.ownerDocument.adoptNode(node);
2284
- }
2285
- try {
2286
- parent.insertBefore(node, anchor);
2287
- } catch (e) {
2288
- if (parent.ownerDocument) {
2289
- try {
2290
- const clone = parent.ownerDocument.importNode(node, true);
2291
- parent.insertBefore(clone, anchor);
2292
- return;
2293
- } catch {
2294
- }
2295
- }
2296
- throw e;
2297
- }
2298
- return;
2299
- }
2300
- const doc = parent.ownerDocument;
2301
- if (doc) {
2302
- const frag = doc.createDocumentFragment();
2303
- for (let i = 0; i < nodes.length; i++) {
2304
- const node = nodes[i];
2305
- if (node === void 0 || node === null) continue;
2306
- if (node.nodeType === 11) {
2307
- const childrenArr = Array.from(node.childNodes);
2308
- for (let j = 0; j < childrenArr.length; j++) {
2309
- frag.appendChild(childrenArr[j]);
2310
- }
2311
- } else {
2312
- if (node.ownerDocument !== doc) {
2313
- doc.adoptNode(node);
2314
- }
2315
- frag.appendChild(node);
2316
- }
2317
- }
2318
- parent.insertBefore(frag, anchor);
2319
- return;
2320
- }
2321
- const insertSingle = (nodeToInsert, anchorNode) => {
2322
- if (nodeToInsert.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2323
- parent.ownerDocument.adoptNode(nodeToInsert);
2324
- }
2325
- try {
2326
- parent.insertBefore(nodeToInsert, anchorNode);
2327
- return nodeToInsert;
2328
- } catch (e) {
2329
- if (parent.ownerDocument) {
2330
- try {
2331
- const clone = parent.ownerDocument.importNode(nodeToInsert, true);
2332
- parent.insertBefore(clone, anchorNode);
2333
- return clone;
2334
- } catch {
2335
- }
2336
- }
2337
- throw e;
2338
- }
2339
- };
2340
- for (let i = nodes.length - 1; i >= 0; i--) {
2341
- const node = nodes[i];
2342
- if (node === void 0 || node === null) continue;
2343
- const isFrag = node.nodeType === 11;
2344
- if (isFrag) {
2345
- const childrenArr = Array.from(node.childNodes);
2346
- for (let j = childrenArr.length - 1; j >= 0; j--) {
2347
- const child = childrenArr[j];
2348
- anchor = insertSingle(child, anchor);
2349
- }
2350
- } else {
2351
- anchor = insertSingle(node, anchor);
2352
- }
2353
- }
2354
- }
2355
- function removeNodes(nodes) {
2356
- for (const node of nodes) {
2357
- node.parentNode?.removeChild(node);
2358
- }
2359
- }
2360
-
2361
- // src/reconcile.ts
2362
- function reconcileArrays(parentNode, a, b) {
2363
- const bLength = b.length;
2364
- let aEnd = a.length;
2365
- let bEnd = bLength;
2366
- let aStart = 0;
2367
- let bStart = 0;
2368
- const after = aEnd > 0 ? a[aEnd - 1].nextSibling : null;
2369
- let map = null;
2370
- while (aStart < aEnd || bStart < bEnd) {
2371
- if (a[aStart] === b[bStart]) {
2372
- aStart++;
2373
- bStart++;
2374
- continue;
2375
- }
2376
- while (a[aEnd - 1] === b[bEnd - 1]) {
2377
- aEnd--;
2378
- bEnd--;
2379
- }
2380
- if (aEnd === aStart) {
2381
- const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] ?? null : after;
2382
- const count = bEnd - bStart;
2383
- const doc = parentNode.ownerDocument;
2384
- if (count > 1 && doc) {
2385
- const frag = doc.createDocumentFragment();
2386
- for (let i = bStart; i < bEnd; i++) {
2387
- frag.appendChild(b[i]);
2388
- }
2389
- parentNode.insertBefore(frag, node);
2390
- bStart = bEnd;
2391
- } else {
2392
- while (bStart < bEnd) {
2393
- parentNode.insertBefore(b[bStart++], node);
2394
- }
2395
- }
2396
- } else if (bEnd === bStart) {
2397
- while (aStart < aEnd) {
2398
- const nodeToRemove = a[aStart];
2399
- if (!map || !map.has(nodeToRemove)) {
2400
- nodeToRemove.parentNode?.removeChild(nodeToRemove);
2401
- }
2402
- aStart++;
2403
- }
2404
- } else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
2405
- const node = a[--aEnd].nextSibling;
2406
- parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
2407
- parentNode.insertBefore(b[--bEnd], node);
2408
- a[aEnd] = b[bEnd];
2409
- } else {
2410
- if (!map) {
2411
- map = /* @__PURE__ */ new Map();
2412
- let i = bStart;
2413
- while (i < bEnd) {
2414
- map.set(b[i], i++);
2415
- }
2416
- }
2417
- const index = map.get(a[aStart]);
2418
- if (index != null) {
2419
- if (bStart < index && index < bEnd) {
2420
- let i = aStart;
2421
- let sequence = 1;
2422
- let t;
2423
- while (++i < aEnd && i < bEnd) {
2424
- t = map.get(a[i]);
2425
- if (t == null || t !== index + sequence) break;
2426
- sequence++;
2427
- }
2428
- if (sequence > index - bStart) {
2429
- const node = a[aStart];
2430
- while (bStart < index) {
2431
- parentNode.insertBefore(b[bStart++], node);
2432
- }
2433
- } else {
2434
- parentNode.replaceChild(b[bStart++], a[aStart++]);
2435
- }
2436
- } else {
2437
- aStart++;
2438
- }
2439
- } else {
2440
- const nodeToRemove = a[aStart++];
2441
- nodeToRemove.parentNode?.removeChild(nodeToRemove);
2442
- }
2443
- }
2444
- }
2445
- }
2446
- function moveNodesBefore(parent, nodes, anchor) {
2447
- for (let i = nodes.length - 1; i >= 0; i--) {
2448
- const node = nodes[i];
2449
- if (!node || !(node instanceof Node)) {
2450
- throw new Error("Invalid node in moveNodesBefore");
2451
- }
2452
- if (node.nextSibling !== anchor) {
2453
- if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2454
- parent.ownerDocument.adoptNode(node);
2455
- }
2456
- try {
2457
- parent.insertBefore(node, anchor);
2458
- } catch (e) {
2459
- if (parent.ownerDocument) {
2460
- try {
2461
- const clone = parent.ownerDocument.importNode(node, true);
2462
- parent.insertBefore(clone, anchor);
2463
- continue;
2464
- } catch {
2465
- }
2466
- }
2467
- throw e;
2468
- }
2469
- }
2470
- anchor = node;
2471
- }
2472
- }
2473
- function moveMarkerBlock(parent, block, anchor) {
2474
- const nodes = collectBlockNodes(block);
2475
- if (nodes.length === 0) return;
2476
- moveNodesBefore(parent, nodes, anchor);
2477
- }
2478
- function destroyMarkerBlock(block) {
2479
- if (block.root) {
2480
- destroyRoot(block.root);
2481
- }
2482
- removeBlockRange(block);
2483
- }
2484
- function collectBlockNodes(block) {
2485
- const nodes = [];
2486
- let cursor = block.start;
2487
- while (cursor) {
2488
- nodes.push(cursor);
2489
- if (cursor === block.end) {
2490
- break;
2491
- }
2492
- cursor = cursor.nextSibling;
2493
- }
2494
- return nodes;
2495
- }
2496
- function removeBlockRange(block) {
2497
- let cursor = block.start;
2498
- while (cursor) {
2499
- const next = cursor.nextSibling;
2500
- cursor.parentNode?.removeChild(cursor);
2501
- if (cursor === block.end) {
2502
- break;
2503
- }
2504
- cursor = next;
2505
- }
2506
- }
2507
- var MAX_SAFE_VERSION = 9007199254740991;
2508
- function createVersionedSignalAccessor(initialValue) {
2509
- let current = initialValue;
2510
- let version = 0;
2511
- const track2 = signal(version);
2512
- function accessor(value) {
2513
- if (arguments.length === 0) {
2514
- track2();
2515
- return current;
2516
- }
2517
- current = value;
2518
- version = version >= MAX_SAFE_VERSION ? 1 : version + 1;
2519
- track2(version);
2520
- }
2521
- return accessor;
2522
- }
2523
- function createKeyedListContainer() {
2524
- const startMarker = document.createComment("fict:list:start");
2525
- const endMarker = document.createComment("fict:list:end");
2526
- const dispose = () => {
2527
- for (const block of container.blocks.values()) {
2528
- destroyRoot(block.root);
2529
- }
2530
- container.blocks.clear();
2531
- container.nextBlocks.clear();
2532
- if (!startMarker.parentNode || !endMarker.parentNode) {
2533
- container.currentNodes = [];
2534
- container.nextNodes = [];
2535
- container.orderedBlocks.length = 0;
2536
- container.nextOrderedBlocks.length = 0;
2537
- container.orderedIndexByKey.clear();
2538
- return;
2539
- }
2540
- const range = document.createRange();
2541
- range.setStartBefore(startMarker);
2542
- range.setEndAfter(endMarker);
2543
- range.deleteContents();
2544
- container.currentNodes = [];
2545
- container.nextNodes = [];
2546
- container.nextBlocks.clear();
2547
- container.orderedBlocks.length = 0;
2548
- container.nextOrderedBlocks.length = 0;
2549
- container.orderedIndexByKey.clear();
2550
- };
2551
- const container = {
2552
- startMarker,
2553
- endMarker,
2554
- blocks: /* @__PURE__ */ new Map(),
2555
- nextBlocks: /* @__PURE__ */ new Map(),
2556
- currentNodes: [startMarker, endMarker],
2557
- nextNodes: [],
2558
- orderedBlocks: [],
2559
- nextOrderedBlocks: [],
2560
- orderedIndexByKey: /* @__PURE__ */ new Map(),
2561
- dispose
2562
- };
2563
- return container;
2564
- }
2565
- function createKeyedBlock(key, item, index, render2, needsIndex = true, hostRoot) {
2566
- const itemSig = createVersionedSignalAccessor(item);
2567
- const indexSig = needsIndex ? signal(index) : ((next) => {
2568
- if (arguments.length === 0) return index;
2569
- index = next;
2570
- return index;
2571
- });
2572
- const root = createRootContext(hostRoot);
2573
- const prevRoot = pushRoot(root);
2574
- let nodes = [];
2575
- let scopeDispose;
2576
- const prevSub = setActiveSub(void 0);
2577
- try {
2578
- scopeDispose = effectScope(() => {
2579
- const rendered = render2(itemSig, indexSig, key);
2580
- if (rendered instanceof Node || Array.isArray(rendered) && rendered.every((n) => n instanceof Node)) {
2581
- nodes = toNodeArray(rendered);
2582
- } else {
2583
- const element = createElement(rendered);
2584
- nodes = toNodeArray(element);
2585
- }
2586
- });
2587
- if (scopeDispose) {
2588
- root.cleanups.push(scopeDispose);
2589
- }
2590
- } finally {
2591
- setActiveSub(prevSub);
2592
- popRoot(prevRoot);
2593
- }
2594
- return {
2595
- key,
2596
- nodes,
2597
- root,
2598
- item: itemSig,
2599
- index: indexSig,
2600
- rawItem: item,
2601
- rawIndex: index
2602
- };
2603
- }
2604
- function getFirstNodeAfter(marker) {
2605
- return marker.nextSibling;
2606
- }
2607
- function isNodeBetweenMarkers(node, startMarker, endMarker) {
2608
- let current = startMarker.nextSibling;
2609
- while (current && current !== endMarker) {
2610
- if (current === node) return true;
2611
- current = current.nextSibling;
2612
- }
2613
- return false;
2614
- }
2615
- function reorderBySwap(parent, first, second) {
2616
- if (first === second) return false;
2617
- const firstNodes = first.nodes;
2618
- const secondNodes = second.nodes;
2619
- if (firstNodes.length === 0 || secondNodes.length === 0) return false;
2620
- const lastFirst = firstNodes[firstNodes.length - 1];
2621
- const lastSecond = secondNodes[secondNodes.length - 1];
2622
- const afterFirst = lastFirst.nextSibling;
2623
- const afterSecond = lastSecond.nextSibling;
2624
- moveNodesBefore(parent, firstNodes, afterSecond);
2625
- moveNodesBefore(parent, secondNodes, afterFirst);
2626
- return true;
2627
- }
2628
- function getLISIndices(sequence) {
2629
- const predecessors = new Array(sequence.length);
2630
- const result = [];
2631
- for (let i = 0; i < sequence.length; i++) {
2632
- const value = sequence[i];
2633
- if (value < 0) {
2634
- predecessors[i] = -1;
2635
- continue;
2636
- }
2637
- let low = 0;
2638
- let high = result.length;
2639
- while (low < high) {
2640
- const mid = low + high >> 1;
2641
- if (sequence[result[mid]] < value) {
2642
- low = mid + 1;
2643
- } else {
2644
- high = mid;
2645
- }
2646
- }
2647
- predecessors[i] = low > 0 ? result[low - 1] : -1;
2648
- if (low === result.length) {
2649
- result.push(i);
2650
- } else {
2651
- result[low] = i;
2652
- }
2653
- }
2654
- const lis = new Array(result.length);
2655
- let k = result.length > 0 ? result[result.length - 1] : -1;
2656
- for (let i = result.length - 1; i >= 0; i--) {
2657
- lis[i] = k;
2658
- k = predecessors[k];
2659
- }
2660
- return lis;
2661
- }
2662
- function reorderByLIS(parent, endMarker, prev, next) {
2663
- const positions = /* @__PURE__ */ new Map();
2664
- for (let i = 0; i < prev.length; i++) {
2665
- positions.set(prev[i], i);
2666
- }
2667
- const sequence = new Array(next.length);
2668
- for (let i = 0; i < next.length; i++) {
2669
- const position = positions.get(next[i]);
2670
- if (position === void 0) return false;
2671
- sequence[i] = position;
2672
- }
2673
- const lisIndices = getLISIndices(sequence);
2674
- if (lisIndices.length === sequence.length) return true;
2675
- const inLIS = new Array(sequence.length).fill(false);
2676
- for (let i = 0; i < lisIndices.length; i++) {
2677
- inLIS[lisIndices[i]] = true;
2678
- }
2679
- let anchor = endMarker;
2680
- let moved = false;
2681
- for (let i = next.length - 1; i >= 0; i--) {
2682
- const block = next[i];
2683
- const nodes = block.nodes;
2684
- if (nodes.length === 0) continue;
2685
- if (inLIS[i]) {
2686
- anchor = nodes[0];
2687
- continue;
2688
- }
2689
- moveNodesBefore(parent, nodes, anchor);
2690
- anchor = nodes[0];
2691
- moved = true;
2692
- }
2693
- return moved;
2694
- }
2695
- function createKeyedList(getItems, keyFn, renderItem, needsIndex) {
2696
- const resolvedNeedsIndex = arguments.length >= 4 ? !!needsIndex : renderItem.length > 1;
2697
- return createFineGrainedKeyedList(getItems, keyFn, renderItem, resolvedNeedsIndex);
2698
- }
2699
- function createFineGrainedKeyedList(getItems, keyFn, renderItem, needsIndex) {
2700
- const container = createKeyedListContainer();
2701
- const hostRoot = getCurrentRoot();
2702
- const fragment = document.createDocumentFragment();
2703
- fragment.append(container.startMarker, container.endMarker);
2704
- let disposed = false;
2705
- let effectDispose;
2706
- let connectObserver = null;
2707
- let effectStarted = false;
2708
- let startScheduled = false;
2709
- const getConnectedParent = () => {
2710
- const endParent = container.endMarker.parentNode;
2711
- const startParent = container.startMarker.parentNode;
2712
- if (endParent && startParent && endParent === startParent && endParent.nodeType !== 11) {
2713
- return endParent;
2714
- }
2715
- return null;
2716
- };
2717
- const performDiff = () => {
2718
- if (disposed) return;
2719
- const parent = getConnectedParent();
2720
- if (!parent) return;
2721
- batch2(() => {
2722
- const oldBlocks = container.blocks;
2723
- const newBlocks = container.nextBlocks;
2724
- const prevOrderedBlocks = container.orderedBlocks;
2725
- const nextOrderedBlocks = container.nextOrderedBlocks;
2726
- const orderedIndexByKey = container.orderedIndexByKey;
2727
- const newItems = getItems();
2728
- if (newItems.length === 0) {
2729
- if (oldBlocks.size > 0) {
2730
- for (const block of oldBlocks.values()) {
2731
- destroyRoot(block.root);
2732
- }
2733
- const range = document.createRange();
2734
- range.setStartAfter(container.startMarker);
2735
- range.setEndBefore(container.endMarker);
2736
- range.deleteContents();
2737
- }
2738
- oldBlocks.clear();
2739
- newBlocks.clear();
2740
- prevOrderedBlocks.length = 0;
2741
- nextOrderedBlocks.length = 0;
2742
- orderedIndexByKey.clear();
2743
- container.currentNodes.length = 0;
2744
- container.currentNodes.push(container.startMarker, container.endMarker);
2745
- container.nextNodes.length = 0;
2746
- return;
2747
- }
2748
- const prevCount = prevOrderedBlocks.length;
2749
- if (prevCount > 0 && newItems.length === prevCount && orderedIndexByKey.size === prevCount) {
2750
- let stableOrder = true;
2751
- const seen = /* @__PURE__ */ new Set();
2752
- for (let i = 0; i < prevCount; i++) {
2753
- const item = newItems[i];
2754
- const key = keyFn(item, i);
2755
- if (seen.has(key) || prevOrderedBlocks[i].key !== key) {
2756
- stableOrder = false;
2757
- break;
2758
- }
2759
- seen.add(key);
2760
- }
2761
- if (stableOrder) {
2762
- for (let i = 0; i < prevCount; i++) {
2763
- const item = newItems[i];
2764
- const block = prevOrderedBlocks[i];
2765
- if (block.rawItem !== item) {
2766
- block.rawItem = item;
2767
- block.item(item);
2768
- }
2769
- if (needsIndex && block.rawIndex !== i) {
2770
- block.rawIndex = i;
2771
- block.index(i);
2772
- }
2773
- }
2774
- return;
2775
- }
2776
- }
2777
- newBlocks.clear();
2778
- nextOrderedBlocks.length = 0;
2779
- orderedIndexByKey.clear();
2780
- const createdBlocks = [];
2781
- let appendCandidate = prevCount > 0 && newItems.length >= prevCount;
2782
- const appendedBlocks = [];
2783
- let mismatchCount = 0;
2784
- let mismatchFirst = -1;
2785
- let mismatchSecond = -1;
2786
- let hasDuplicateKey = false;
2787
- newItems.forEach((item, index) => {
2788
- const key = keyFn(item, index);
2789
- let block = oldBlocks.get(key);
2790
- const existed = block !== void 0;
2791
- if (block) {
2792
- if (block.rawItem !== item) {
2793
- block.rawItem = item;
2794
- block.item(item);
2795
- }
2796
- if (needsIndex && block.rawIndex !== index) {
2797
- block.rawIndex = index;
2798
- block.index(index);
2799
- }
2800
- }
2801
- if (block) {
2802
- newBlocks.set(key, block);
2803
- oldBlocks.delete(key);
2804
- } else {
2805
- const existingBlock = newBlocks.get(key);
2806
- if (existingBlock) {
2807
- destroyRoot(existingBlock.root);
2808
- removeNodes(existingBlock.nodes);
2809
- }
2810
- block = createKeyedBlock(key, item, index, renderItem, needsIndex, hostRoot);
2811
- createdBlocks.push(block);
2812
- }
2813
- const resolvedBlock = block;
2814
- newBlocks.set(key, resolvedBlock);
2815
- const position = orderedIndexByKey.get(key);
2816
- if (position !== void 0) {
2817
- appendCandidate = false;
2818
- hasDuplicateKey = true;
2819
- const prior = nextOrderedBlocks[position];
2820
- if (prior && prior !== resolvedBlock) {
2821
- destroyRoot(prior.root);
2822
- removeNodes(prior.nodes);
2823
- }
2824
- nextOrderedBlocks[position] = resolvedBlock;
2825
- } else {
2826
- if (appendCandidate) {
2827
- if (index < prevCount) {
2828
- if (!prevOrderedBlocks[index] || prevOrderedBlocks[index].key !== key) {
2829
- appendCandidate = false;
2830
- }
2831
- } else if (existed) {
2832
- appendCandidate = false;
2833
- }
2834
- }
2835
- const nextIndex = nextOrderedBlocks.length;
2836
- orderedIndexByKey.set(key, nextIndex);
2837
- nextOrderedBlocks.push(resolvedBlock);
2838
- if (mismatchCount < 3 && (nextIndex >= prevCount || prevOrderedBlocks[nextIndex] !== resolvedBlock)) {
2839
- if (mismatchCount === 0) {
2840
- mismatchFirst = nextIndex;
2841
- } else if (mismatchCount === 1) {
2842
- mismatchSecond = nextIndex;
2843
- }
2844
- mismatchCount++;
2845
- }
2846
- }
2847
- if (appendCandidate && index >= prevCount) {
2848
- appendedBlocks.push(resolvedBlock);
2849
- }
2850
- });
2851
- const canAppend = appendCandidate && prevCount > 0 && newItems.length > prevCount && oldBlocks.size === 0 && appendedBlocks.length > 0;
2852
- if (canAppend) {
2853
- const appendedNodes = [];
2854
- for (const block of appendedBlocks) {
2855
- for (let i = 0; i < block.nodes.length; i++) {
2856
- appendedNodes.push(block.nodes[i]);
2857
- }
2858
- }
2859
- if (appendedNodes.length > 0) {
2860
- insertNodesBefore(parent, appendedNodes, container.endMarker);
2861
- const currentNodes = container.currentNodes;
2862
- currentNodes.pop();
2863
- for (let i = 0; i < appendedNodes.length; i++) {
2864
- currentNodes.push(appendedNodes[i]);
2865
- }
2866
- currentNodes.push(container.endMarker);
2867
- }
2868
- container.blocks = newBlocks;
2869
- container.nextBlocks = oldBlocks;
2870
- container.orderedBlocks = nextOrderedBlocks;
2871
- container.nextOrderedBlocks = prevOrderedBlocks;
2872
- for (const block of createdBlocks) {
2873
- if (newBlocks.get(block.key) === block) {
2874
- flushOnMount(block.root);
2875
- }
2876
- }
2877
- return;
2878
- }
2879
- if (oldBlocks.size > 0) {
2880
- for (const block of oldBlocks.values()) {
2881
- destroyRoot(block.root);
2882
- removeNodes(block.nodes);
2883
- }
2884
- oldBlocks.clear();
2885
- }
2886
- const canReorderInPlace = createdBlocks.length === 0 && oldBlocks.size === 0 && nextOrderedBlocks.length === prevOrderedBlocks.length;
2887
- let skipReconcile = false;
2888
- let updateNodeBuffer = true;
2889
- if (canReorderInPlace && nextOrderedBlocks.length > 0 && !hasDuplicateKey) {
2890
- if (mismatchCount === 0) {
2891
- skipReconcile = true;
2892
- updateNodeBuffer = false;
2893
- } else if (mismatchCount === 2 && prevOrderedBlocks[mismatchFirst] === nextOrderedBlocks[mismatchSecond] && prevOrderedBlocks[mismatchSecond] === nextOrderedBlocks[mismatchFirst]) {
2894
- if (reorderBySwap(
2895
- parent,
2896
- prevOrderedBlocks[mismatchFirst],
2897
- prevOrderedBlocks[mismatchSecond]
2898
- )) {
2899
- skipReconcile = true;
2900
- }
2901
- } else if (reorderByLIS(parent, container.endMarker, prevOrderedBlocks, nextOrderedBlocks)) {
2902
- skipReconcile = true;
2903
- }
2904
- }
2905
- if (!skipReconcile && (newBlocks.size > 0 || container.currentNodes.length > 0)) {
2906
- const prevNodes = container.currentNodes;
2907
- const nextNodes = container.nextNodes;
2908
- nextNodes.length = 0;
2909
- nextNodes.push(container.startMarker);
2910
- for (let i = 0; i < nextOrderedBlocks.length; i++) {
2911
- const nodes = nextOrderedBlocks[i].nodes;
2912
- for (let j = 0; j < nodes.length; j++) {
2913
- nextNodes.push(nodes[j]);
2914
- }
2915
- }
2916
- nextNodes.push(container.endMarker);
2917
- reconcileArrays(parent, prevNodes, nextNodes);
2918
- container.currentNodes = nextNodes;
2919
- container.nextNodes = prevNodes;
2920
- } else if (skipReconcile && updateNodeBuffer) {
2921
- const prevNodes = container.currentNodes;
2922
- const nextNodes = container.nextNodes;
2923
- nextNodes.length = 0;
2924
- nextNodes.push(container.startMarker);
2925
- for (let i = 0; i < nextOrderedBlocks.length; i++) {
2926
- const nodes = nextOrderedBlocks[i].nodes;
2927
- for (let j = 0; j < nodes.length; j++) {
2928
- nextNodes.push(nodes[j]);
2929
- }
2930
- }
2931
- nextNodes.push(container.endMarker);
2932
- container.currentNodes = nextNodes;
2933
- container.nextNodes = prevNodes;
2934
- }
2935
- container.blocks = newBlocks;
2936
- container.nextBlocks = oldBlocks;
2937
- container.orderedBlocks = nextOrderedBlocks;
2938
- container.nextOrderedBlocks = prevOrderedBlocks;
2939
- for (const block of createdBlocks) {
2940
- if (newBlocks.get(block.key) === block) {
2941
- flushOnMount(block.root);
2942
- }
2943
- }
2944
- });
2945
- };
2946
- const disconnectObserver = () => {
2947
- connectObserver?.disconnect();
2948
- connectObserver = null;
2949
- };
2950
- const ensureEffectStarted = () => {
2951
- if (disposed || effectStarted) return effectStarted;
2952
- const parent = getConnectedParent();
2953
- if (!parent) return false;
2954
- const start = () => {
2955
- effectDispose = createRenderEffect(performDiff);
2956
- effectStarted = true;
2957
- };
2958
- if (hostRoot) {
2959
- const prev = pushRoot(hostRoot);
2960
- try {
2961
- start();
2962
- } finally {
2963
- popRoot(prev);
2964
- }
2965
- } else {
2966
- start();
2967
- }
2968
- return true;
2969
- };
2970
- const waitForConnection = () => {
2971
- if (connectObserver || typeof MutationObserver === "undefined") return;
2972
- connectObserver = new MutationObserver(() => {
2973
- if (disposed) return;
2974
- if (getConnectedParent()) {
2975
- disconnectObserver();
2976
- if (ensureEffectStarted()) {
2977
- flush();
2978
- }
2979
- }
2980
- });
2981
- connectObserver.observe(document, { childList: true, subtree: true });
2982
- };
2983
- const scheduleStart = () => {
2984
- if (startScheduled || disposed || effectStarted) return;
2985
- startScheduled = true;
2986
- const run = () => {
2987
- startScheduled = false;
2988
- if (!ensureEffectStarted()) {
2989
- waitForConnection();
2990
- }
2991
- };
2992
- if (typeof queueMicrotask === "function") {
2993
- queueMicrotask(run);
2994
- } else {
2995
- Promise.resolve().then(run).catch(() => void 0);
2996
- }
2997
- };
2998
- scheduleStart();
2999
- return {
3000
- get marker() {
3001
- scheduleStart();
3002
- return fragment;
3003
- },
3004
- startMarker: container.startMarker,
3005
- endMarker: container.endMarker,
3006
- // Flush pending items - call after markers are inserted into DOM
3007
- flush: () => {
3008
- if (disposed) return;
3009
- scheduleStart();
3010
- if (ensureEffectStarted()) {
3011
- flush();
3012
- } else {
3013
- waitForConnection();
3014
- }
3015
- },
3016
- dispose: () => {
3017
- disposed = true;
3018
- effectDispose?.();
3019
- disconnectObserver();
3020
- container.dispose();
3021
- }
3022
- };
3023
- }
3024
-
3025
- // src/binding.ts
3026
- function isReactive(value) {
3027
- return typeof value === "function" && value.length === 0;
3028
- }
3029
- function unwrap2(value) {
3030
- return isReactive(value) ? value() : value;
3031
- }
3032
- function callEventHandler(handler, event, node, data) {
3033
- if (!handler) return;
3034
- const context = node ?? event.currentTarget ?? void 0;
3035
- const invoke = (fn) => {
3036
- if (typeof fn === "function") {
3037
- const result = data === void 0 ? fn.call(context, event) : fn.call(context, data, event);
3038
- if (typeof result === "function" && result !== fn) {
3039
- if (data === void 0) {
3040
- result.call(context, event);
3041
- } else {
3042
- result.call(context, data, event);
3043
- }
3044
- } else if (result && typeof result.handleEvent === "function") {
3045
- result.handleEvent.call(result, event);
3046
- }
3047
- } else if (fn && typeof fn.handleEvent === "function") {
3048
- fn.handleEvent.call(fn, event);
3049
- }
3050
- };
3051
- invoke(handler);
3052
- }
3053
- var PRIMITIVE_PROXY = Symbol("fict:primitive-proxy");
3054
- var PRIMITIVE_PROXY_RAW_VALUE = Symbol("fict:primitive-proxy:raw-value");
3055
- function unwrapPrimitive(value) {
3056
- if (value && typeof value === "object" && PRIMITIVE_PROXY in value) {
3057
- const getRawValue = value[PRIMITIVE_PROXY_RAW_VALUE];
3058
- if (typeof getRawValue === "function") {
3059
- return getRawValue();
3060
- }
3061
- }
3062
- return value;
3063
- }
3064
- function createTextBinding(value) {
3065
- const text = document.createTextNode("");
3066
- if (isReactive(value)) {
3067
- createRenderEffect(() => {
3068
- const v = value();
3069
- const fmt = formatTextValue(v);
3070
- if (text.data !== fmt) {
3071
- text.data = fmt;
3072
- }
3073
- });
3074
- } else {
3075
- text.data = formatTextValue(value);
3076
- }
3077
- return text;
3078
- }
3079
- function bindText(textNode, getValue) {
3080
- return createRenderEffect(() => {
3081
- const value = formatTextValue(getValue());
3082
- if (textNode.data !== value) {
3083
- textNode.data = value;
3084
- }
3085
- });
3086
- }
3087
- function formatTextValue(value) {
3088
- if (value == null || value === false) {
3089
- return "";
3090
- }
3091
- return String(value);
3092
- }
3093
- function createAttributeBinding(el, key, value, setter) {
3094
- if (isReactive(value)) {
3095
- createRenderEffect(() => {
3096
- setter(el, key, value());
3097
- });
3098
- } else {
3099
- setter(el, key, value);
3100
- }
3101
- }
3102
- function bindAttribute(el, key, getValue) {
3103
- let prevValue = void 0;
3104
- return createRenderEffect(() => {
3105
- const value = getValue();
3106
- if (value === prevValue) return;
3107
- prevValue = value;
3108
- if (value === void 0 || value === null || value === false) {
3109
- el.removeAttribute(key);
3110
- } else if (value === true) {
3111
- el.setAttribute(key, "");
3112
- } else {
3113
- el.setAttribute(key, String(value));
3114
- }
3115
- });
3116
- }
3117
- function bindProperty(el, key, getValue) {
3118
- const PROPERTY_BINDING_KEYS = /* @__PURE__ */ new Set([
3119
- "value",
3120
- "checked",
3121
- "selected",
3122
- "disabled",
3123
- "readOnly",
3124
- "multiple",
3125
- "muted"
3126
- ]);
3127
- let prevValue = void 0;
3128
- return createRenderEffect(() => {
3129
- const next = getValue();
3130
- if (next === prevValue) return;
3131
- prevValue = next;
3132
- if (PROPERTY_BINDING_KEYS.has(key) && (next === void 0 || next === null)) {
3133
- const fallback = key === "checked" || key === "selected" ? false : "";
3134
- el[key] = fallback;
3135
- return;
3136
- }
3137
- ;
3138
- el[key] = next;
3139
- });
3140
- }
3141
- function createStyleBinding(el, value) {
3142
- const target = el;
3143
- if (isReactive(value)) {
3144
- let prev;
3145
- createRenderEffect(() => {
3146
- const next = value();
3147
- applyStyle(target, next, prev);
3148
- prev = next;
3149
- });
3150
- } else {
3151
- applyStyle(target, value, void 0);
3152
- }
3153
- }
3154
- function bindStyle(el, getValue) {
3155
- const target = el;
3156
- let prev;
3157
- return createRenderEffect(() => {
3158
- const next = getValue();
3159
- applyStyle(target, next, prev);
3160
- prev = next;
3161
- });
3162
- }
3163
- function applyStyle(el, value, prev) {
3164
- if (typeof value === "string") {
3165
- el.style.cssText = value;
3166
- } else if (value && typeof value === "object") {
3167
- const styles = value;
3168
- if (typeof prev === "string") {
3169
- el.style.cssText = "";
3170
- }
3171
- if (prev && typeof prev === "object") {
3172
- const prevStyles = prev;
3173
- for (const key of Object.keys(prevStyles)) {
3174
- if (!(key in styles)) {
3175
- const cssProperty = key.replace(/([A-Z])/g, "-$1").toLowerCase();
3176
- el.style.removeProperty(cssProperty);
3177
- }
3178
- }
3179
- }
3180
- for (const [prop, v] of Object.entries(styles)) {
3181
- if (v != null) {
3182
- const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3183
- const unitless = isUnitlessStyleProperty(prop) || isUnitlessStyleProperty(cssProperty);
3184
- const valueStr = typeof v === "number" && !unitless ? `${v}px` : String(v);
3185
- el.style.setProperty(cssProperty, valueStr);
3186
- } else {
3187
- const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3188
- el.style.removeProperty(cssProperty);
3189
- }
3190
- }
3191
- } else {
3192
- if (prev && typeof prev === "object") {
3193
- const prevStyles = prev;
3194
- for (const key of Object.keys(prevStyles)) {
3195
- const cssProperty = key.replace(/([A-Z])/g, "-$1").toLowerCase();
3196
- el.style.removeProperty(cssProperty);
3197
- }
3198
- } else if (typeof prev === "string") {
3199
- el.style.cssText = "";
3200
- }
3201
- }
3202
- }
3203
- function isUnitlessStyleProperty(prop) {
3204
- return UnitlessStyles.has(prop);
3205
- }
3206
- function createClassBinding(el, value) {
3207
- if (isReactive(value)) {
3208
- let prev = {};
3209
- createRenderEffect(() => {
3210
- const next = value();
3211
- prev = applyClass(el, next, prev);
3212
- });
3213
- } else {
3214
- applyClass(el, value, {});
3215
- }
3216
- }
3217
- function bindClass(el, getValue) {
3218
- let prev = {};
3219
- let prevString;
3220
- return createRenderEffect(() => {
3221
- const next = getValue();
3222
- if (typeof next === "string") {
3223
- if (next === prevString) return;
3224
- prevString = next;
3225
- el.className = next;
3226
- prev = {};
3227
- return;
3228
- }
3229
- prevString = void 0;
3230
- prev = applyClass(el, next, prev);
3231
- });
3232
- }
3233
- function toggleClassKey(node, key, value) {
3234
- const classNames = key.trim().split(/\s+/);
3235
- for (let i = 0, len = classNames.length; i < len; i++) {
3236
- node.classList.toggle(classNames[i], value);
3237
- }
3238
- }
3239
- function applyClass(el, value, prev) {
3240
- const prevState = prev && typeof prev === "object" ? prev : {};
3241
- if (typeof value === "string") {
3242
- el.className = value;
3243
- return {};
3244
- }
3245
- if (value && typeof value === "object") {
3246
- const classes = value;
3247
- const classKeys = Object.keys(classes);
3248
- const prevKeys = Object.keys(prevState);
3249
- for (let i = 0, len = prevKeys.length; i < len; i++) {
3250
- const key = prevKeys[i];
3251
- if (!key || key === "undefined" || classes[key]) continue;
3252
- toggleClassKey(el, key, false);
3253
- delete prevState[key];
3254
- }
3255
- for (let i = 0, len = classKeys.length; i < len; i++) {
3256
- const key = classKeys[i];
3257
- const classValue = !!classes[key];
3258
- if (!key || key === "undefined" || prevState[key] === classValue || !classValue) continue;
3259
- toggleClassKey(el, key, true);
3260
- prevState[key] = classValue;
3261
- }
3262
- return prevState;
3263
- }
3264
- if (!value) {
3265
- for (const key of Object.keys(prevState)) {
3266
- if (key && key !== "undefined") {
3267
- toggleClassKey(el, key, false);
3268
- }
3269
- }
3270
- return {};
3271
- }
3272
- return prevState;
3273
- }
3274
- function classList(node, value, prev = {}) {
3275
- return applyClass(node, value, prev);
3276
- }
3277
- function insert(parent, getValue, markerOrCreateElement, createElementFn) {
3278
- const hostRoot = getCurrentRoot();
3279
- let marker;
3280
- let ownsMarker = false;
3281
- let createFn = createElementFn;
3282
- if (markerOrCreateElement instanceof Node) {
3283
- marker = markerOrCreateElement;
3284
- createFn = createElementFn;
3285
- } else {
3286
- marker = document.createComment("fict:insert");
3287
- parent.appendChild(marker);
3288
- createFn = markerOrCreateElement;
3289
- ownsMarker = true;
3290
- }
3291
- let currentNodes = [];
3292
- let currentText = null;
3293
- let currentRoot2 = null;
3294
- const clearCurrentNodes = () => {
3295
- if (currentNodes.length > 0) {
3296
- removeNodes(currentNodes);
3297
- currentNodes = [];
3298
- }
3299
- };
3300
- const setTextNode = (textValue, shouldInsert, parentNode) => {
3301
- if (!currentText) {
3302
- currentText = document.createTextNode(textValue);
3303
- } else if (currentText.data !== textValue) {
3304
- currentText.data = textValue;
3305
- }
3306
- if (!shouldInsert) {
3307
- clearCurrentNodes();
3308
- return;
3309
- }
3310
- if (currentNodes.length === 1 && currentNodes[0] === currentText) {
3311
- return;
3312
- }
3313
- clearCurrentNodes();
3314
- insertNodesBefore(parentNode, [currentText], marker);
3315
- currentNodes = [currentText];
3316
- };
3317
- const dispose = createRenderEffect(() => {
3318
- const value = getValue();
3319
- const parentNode = marker.parentNode;
3320
- const isPrimitive = value == null || value === false || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
3321
- if (isPrimitive) {
3322
- if (currentRoot2) {
3323
- destroyRoot(currentRoot2);
3324
- currentRoot2 = null;
3325
- }
3326
- if (!parentNode) {
3327
- clearCurrentNodes();
3328
- return;
3329
- }
3330
- const textValue = value == null || value === false ? "" : String(value);
3331
- const shouldInsert = value != null && value !== false;
3332
- setTextNode(textValue, shouldInsert, parentNode);
3333
- return;
3334
- }
3335
- if (currentRoot2) {
3336
- destroyRoot(currentRoot2);
3337
- currentRoot2 = null;
3338
- }
3339
- clearCurrentNodes();
3340
- const root = createRootContext(hostRoot);
3341
- const prev = pushRoot(root);
3342
- let nodes = [];
3343
- try {
3344
- let newNode;
3345
- if (value instanceof Node) {
3346
- newNode = value;
3347
- } else if (Array.isArray(value)) {
3348
- if (value.every((v) => v instanceof Node)) {
3349
- newNode = value;
3350
- } else {
3351
- if (createFn) {
3352
- const mapped = [];
3353
- for (const item of value) {
3354
- mapped.push(...toNodeArray(createFn(item)));
3355
- }
3356
- newNode = mapped;
3357
- } else {
3358
- newNode = document.createTextNode(String(value));
3359
- }
3360
- }
3361
- } else {
3362
- newNode = createFn ? createFn(value) : document.createTextNode(String(value));
3363
- }
3364
- nodes = toNodeArray(newNode);
3365
- if (parentNode) {
3366
- insertNodesBefore(parentNode, nodes, marker);
3367
- }
3368
- } finally {
3369
- popRoot(prev);
3370
- flushOnMount(root);
3371
- }
3372
- currentRoot2 = root;
3373
- currentNodes = nodes;
3374
- });
3375
- return () => {
3376
- dispose();
3377
- if (currentRoot2) {
3378
- destroyRoot(currentRoot2);
3379
- currentRoot2 = null;
3380
- }
3381
- clearCurrentNodes();
3382
- if (ownsMarker) {
3383
- marker.parentNode?.removeChild(marker);
3384
- }
3385
- };
3386
- }
3387
- function createChildBinding(parent, getValue, createElementFn) {
3388
- const marker = document.createComment("fict:child");
3389
- parent.appendChild(marker);
3390
- const hostRoot = getCurrentRoot();
3391
- const dispose = createRenderEffect(() => {
3392
- const root = createRootContext(hostRoot);
3393
- const prev = pushRoot(root);
3394
- let nodes = [];
3395
- let handledError = false;
3396
- try {
3397
- const value = getValue();
3398
- if (value == null || value === false) {
3399
- return;
3400
- }
3401
- const output = createElementFn(value);
3402
- nodes = toNodeArray(output);
3403
- const parentNode = marker.parentNode;
3404
- if (parentNode) {
3405
- insertNodesBefore(parentNode, nodes, marker);
3406
- }
3407
- return () => {
3408
- destroyRoot(root);
3409
- removeNodes(nodes);
3410
- };
3411
- } catch (err) {
3412
- if (handleSuspend(err, root)) {
3413
- handledError = true;
3414
- destroyRoot(root);
3415
- return;
3416
- }
3417
- if (handleError(err, { source: "renderChild" }, root)) {
3418
- handledError = true;
3419
- destroyRoot(root);
3420
- return;
3421
- }
3422
- throw err;
3423
- } finally {
3424
- popRoot(prev);
3425
- if (!handledError) {
3426
- flushOnMount(root);
3427
- }
3428
- }
3429
- });
3430
- return {
3431
- marker,
3432
- dispose: () => {
3433
- dispose();
3434
- marker.parentNode?.removeChild(marker);
3435
- }
3436
- };
3437
- }
3438
- function delegateEvents(eventNames, doc = window.document) {
3439
- const e = doc[$$EVENTS] || (doc[$$EVENTS] = /* @__PURE__ */ new Set());
3440
- for (let i = 0, l = eventNames.length; i < l; i++) {
3441
- const name = eventNames[i];
3442
- if (!e.has(name)) {
3443
- e.add(name);
3444
- doc.addEventListener(name, globalEventHandler);
3445
- }
3446
- }
3447
- }
3448
- function clearDelegatedEvents(doc = window.document) {
3449
- const e = doc[$$EVENTS];
3450
- if (e) {
3451
- for (const name of e.keys()) {
3452
- doc.removeEventListener(name, globalEventHandler);
3453
- }
3454
- delete doc[$$EVENTS];
3455
- }
3456
- }
3457
- function globalEventHandler(e) {
3458
- const asNode = (value) => value && typeof value.nodeType === "number" ? value : null;
3459
- const asElement = (value) => {
3460
- const n = asNode(value);
3461
- if (!n) return null;
3462
- if (n.nodeType === 1) return n;
3463
- return n.parentElement;
3464
- };
3465
- let node = asElement(e.target);
3466
- const key = `$$${e.type}`;
3467
- const dataKey = `${key}Data`;
3468
- const oriTarget = e.target;
3469
- const oriCurrentTarget = e.currentTarget;
3470
- let lastHandled = null;
3471
- const retarget = (value) => Object.defineProperty(e, "target", {
3472
- configurable: true,
3473
- value
3474
- });
3475
- const handleNode = () => {
3476
- if (!node) return false;
3477
- const handler = node[key];
3478
- if (handler && !node.disabled) {
3479
- const resolveData = (value) => {
3480
- if (typeof value === "function") {
3481
- try {
3482
- const fn = value;
3483
- return fn.length > 0 ? fn(e) : fn();
3484
- } catch {
3485
- return value();
3486
- }
3487
- }
3488
- return value;
3489
- };
3490
- const rawData = node[dataKey];
3491
- const hasData = rawData !== void 0;
3492
- const resolvedNodeData = hasData ? resolveData(rawData) : void 0;
3493
- batch2(() => {
3494
- if (typeof handler === "function") {
3495
- callEventHandler(handler, e, node, hasData ? resolvedNodeData : void 0);
3496
- } else if (Array.isArray(handler)) {
3497
- const tupleData = resolveData(handler[1]);
3498
- callEventHandler(handler[0], e, node, tupleData);
3499
- }
3500
- });
3501
- if (e.cancelBubble) return false;
3502
- }
3503
- const shadowHost = node.host;
3504
- if (shadowHost && typeof shadowHost !== "string" && !shadowHost._$host && (() => {
3505
- const targetNode = asNode(e.target);
3506
- return targetNode ? node.contains(targetNode) : false;
3507
- })()) {
3508
- retarget(shadowHost);
3509
- }
3510
- return true;
3511
- };
3512
- const walkUpTree = () => {
3513
- while (handleNode() && node) {
3514
- node = asElement(node._$host || node.parentNode || node.host);
3515
- }
3516
- };
3517
- Object.defineProperty(e, "currentTarget", {
3518
- configurable: true,
3519
- get() {
3520
- return node || document;
3521
- }
3522
- });
3523
- if (e.composedPath) {
3524
- const path = e.composedPath();
3525
- retarget(path[0]);
3526
- for (let i = 0; i < path.length - 2; i++) {
3527
- const nextNode = asElement(path[i]);
3528
- if (!nextNode || nextNode === lastHandled) continue;
3529
- node = nextNode;
3530
- if (!handleNode()) break;
3531
- lastHandled = node;
3532
- if (node._$host) {
3533
- node = node._$host;
3534
- walkUpTree();
3535
- break;
3536
- }
3537
- if (node.parentNode === oriCurrentTarget) {
3538
- break;
3539
- }
3540
- }
3541
- } else {
3542
- walkUpTree();
3543
- }
3544
- retarget(oriTarget);
3545
- }
3546
- function addEventListener(node, name, handler, delegate) {
3547
- if (handler == null) return;
3548
- if (delegate) {
3549
- if (Array.isArray(handler)) {
3550
- node[`$$${name}`] = handler[0];
3551
- node[`$$${name}Data`] = handler[1];
3552
- } else {
3553
- node[`$$${name}`] = handler;
3554
- }
3555
- } else if (Array.isArray(handler)) {
3556
- const handlerFn = handler[0];
3557
- node.addEventListener(name, (e) => handlerFn.call(node, handler[1], e));
3558
- } else {
3559
- node.addEventListener(name, handler);
3560
- }
3561
- }
3562
- function bindEvent(el, eventName, handler, options2) {
3563
- if (handler == null) return () => {
3564
- };
3565
- const rootRef = getCurrentRoot();
3566
- if (DelegatedEvents.has(eventName) && !options2) {
3567
- const key = `$$${eventName}`;
3568
- delegateEvents([eventName]);
3569
- const resolveHandler = isReactive(handler) ? handler : () => handler;
3570
- el[key] = function(...args) {
3571
- try {
3572
- const fn = resolveHandler();
3573
- callEventHandler(fn, args[0], el);
3574
- } catch (err) {
3575
- if (!handleError(err, { source: "event", eventName }, rootRef)) {
3576
- throw err;
3577
- }
3578
- }
3579
- };
3580
- return () => {
3581
- el[key] = void 0;
3582
- };
3583
- }
3584
- const getHandler = isReactive(handler) ? handler : () => handler;
3585
- const wrapped = (event) => {
3586
- try {
3587
- const resolved = getHandler();
3588
- callEventHandler(resolved, event, el);
3589
- } catch (err) {
3590
- if (handleError(err, { source: "event", eventName }, rootRef)) {
3591
- return;
3592
- }
3593
- throw err;
3594
- }
3595
- };
3596
- el.addEventListener(eventName, wrapped, options2);
3597
- const cleanup = () => el.removeEventListener(eventName, wrapped, options2);
3598
- registerRootCleanup(cleanup);
3599
- return cleanup;
3600
- }
3601
- function bindRef(el, ref) {
3602
- if (ref == null) return () => {
3603
- };
3604
- const getRef = isReactive(ref) ? ref : () => ref;
3605
- const applyRef2 = (refValue) => {
3606
- if (refValue == null) return;
3607
- if (typeof refValue === "function") {
3608
- refValue(el);
3609
- } else if (typeof refValue === "object" && "current" in refValue) {
3610
- refValue.current = el;
3611
- }
3612
- };
3613
- const initialRef = getRef();
3614
- applyRef2(initialRef);
3615
- if (isReactive(ref)) {
3616
- const cleanup2 = createRenderEffect(() => {
3617
- const currentRef = getRef();
3618
- applyRef2(currentRef);
3619
- });
3620
- registerRootCleanup(cleanup2);
3621
- const nullifyCleanup = () => {
3622
- const currentRef = getRef();
3623
- if (currentRef && typeof currentRef === "object" && "current" in currentRef) {
3624
- currentRef.current = null;
3625
- }
3626
- };
3627
- registerRootCleanup(nullifyCleanup);
3628
- return () => {
3629
- cleanup2();
3630
- nullifyCleanup();
3631
- };
3632
- }
3633
- const cleanup = () => {
3634
- const refValue = getRef();
3635
- if (refValue && typeof refValue === "object" && "current" in refValue) {
3636
- refValue.current = null;
3637
- }
3638
- };
3639
- registerRootCleanup(cleanup);
3640
- return cleanup;
3641
- }
3642
- function spread(node, props = {}, isSVG = false, skipChildren = false) {
3643
- const prevProps = {};
3644
- if (!skipChildren && "children" in props) {
3645
- createRenderEffect(() => {
3646
- prevProps.children = props.children;
3647
- });
3648
- }
3649
- createRenderEffect(() => {
3650
- if (typeof props.ref === "function") {
3651
- ;
3652
- props.ref(node);
3653
- }
3654
- });
3655
- createRenderEffect(() => {
3656
- assign(node, props, isSVG, true, prevProps, true);
3657
- });
3658
- return prevProps;
3659
- }
3660
- function assign(node, props, isSVG = false, skipChildren = false, prevProps = {}, skipRef = false) {
3661
- props = props || {};
3662
- for (const prop in prevProps) {
3663
- if (!(prop in props)) {
3664
- if (prop === "children") continue;
3665
- prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef, props);
3666
- }
3667
- }
3668
- for (const prop in props) {
3669
- if (prop === "children") {
3670
- if (!skipChildren) {
3671
- prevProps.children = props.children;
3672
- }
3673
- continue;
3674
- }
3675
- const value = props[prop];
3676
- prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef, props);
3677
- }
3678
- }
3679
- function assignProp(node, prop, value, prev, isSVG, skipRef, props) {
3680
- if (prop === "style") {
3681
- applyStyle(node, value, prev);
3682
- return value;
3683
- }
3684
- if (prop === "classList") {
3685
- return applyClass(node, value, prev);
3686
- }
3687
- if (value === prev) return prev;
3688
- if (prop === "ref") {
3689
- if (!skipRef && typeof value === "function") {
3690
- value(node);
3691
- }
3692
- return value;
3693
- }
3694
- if (prop.slice(0, 3) === "on:") {
3695
- const eventName = prop.slice(3);
3696
- if (prev) node.removeEventListener(eventName, prev);
3697
- if (value) node.addEventListener(eventName, value);
3698
- return value;
3699
- }
3700
- if (prop.slice(0, 10) === "oncapture:") {
3701
- const eventName = prop.slice(10);
3702
- if (prev) node.removeEventListener(eventName, prev, true);
3703
- if (value) node.addEventListener(eventName, value, true);
3704
- return value;
3705
- }
3706
- if (prop.slice(0, 2) === "on") {
3707
- const eventName = prop.slice(2).toLowerCase();
3708
- const shouldDelegate = DelegatedEvents.has(eventName);
3709
- if (!shouldDelegate && prev) {
3710
- const handler = Array.isArray(prev) ? prev[0] : prev;
3711
- node.removeEventListener(eventName, handler);
3712
- }
3713
- if (shouldDelegate || value) {
3714
- addEventListener(node, eventName, value, shouldDelegate);
3715
- if (shouldDelegate) delegateEvents([eventName]);
3716
- }
3717
- return value;
3718
- }
3719
- if (prop.slice(0, 5) === "attr:") {
3720
- if (value == null) node.removeAttribute(prop.slice(5));
3721
- else node.setAttribute(prop.slice(5), String(value));
3722
- return value;
3723
- }
3724
- if (prop.slice(0, 5) === "bool:") {
3725
- if (value) node.setAttribute(prop.slice(5), "");
3726
- else node.removeAttribute(prop.slice(5));
3727
- return value;
3728
- }
3729
- if (prop.slice(0, 5) === "prop:") {
3730
- node[prop.slice(5)] = value;
3731
- return value;
3732
- }
3733
- if (prop === "class" || prop === "className") {
3734
- if (value == null) node.removeAttribute("class");
3735
- else node.className = String(value);
3736
- return value;
3737
- }
3738
- const isCE = node.nodeName.includes("-") || "is" in props;
3739
- if (!isSVG) {
3740
- const propAlias = getPropAlias(prop, node.tagName);
3741
- const isProperty = Properties.has(prop);
3742
- const isChildProp = ChildProperties.has(prop);
3743
- if (propAlias || isProperty || isChildProp || isCE) {
3744
- const propName = propAlias || prop;
3745
- if (isCE && !isProperty && !isChildProp) {
3746
- node[toPropertyName2(propName)] = value;
3747
- } else {
3748
- node[propName] = value;
3749
- }
3750
- return value;
3751
- }
3752
- }
3753
- if (isSVG && prop.indexOf(":") > -1) {
3754
- const [prefix, name] = prop.split(":");
3755
- const ns = SVGNamespace[prefix];
3756
- if (ns) {
3757
- if (value == null) node.removeAttributeNS(ns, name);
3758
- else node.setAttributeNS(ns, name, String(value));
3759
- return value;
3760
- }
3761
- }
3762
- const attrName = Aliases[prop] || prop;
3763
- if (value == null) node.removeAttribute(attrName);
3764
- else node.setAttribute(attrName, String(value));
3765
- return value;
3766
- }
3767
- function toPropertyName2(name) {
3768
- return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
3769
- }
3770
- function createConditional(condition, renderTrue, createElementFn, renderFalse) {
3771
- const startMarker = document.createComment("fict:cond:start");
3772
- const endMarker = document.createComment("fict:cond:end");
3773
- const fragment = document.createDocumentFragment();
3774
- fragment.append(startMarker, endMarker);
3775
- const hostRoot = getCurrentRoot();
3776
- let currentNodes = [];
3777
- let currentRoot2 = null;
3778
- let lastCondition = void 0;
3779
- let pendingRender = false;
3780
- const conditionMemo = computed(condition);
3781
- const runConditional = () => {
3782
- const cond = conditionMemo();
3783
- const parent = startMarker.parentNode;
3784
- if (!parent) {
3785
- pendingRender = true;
3786
- return;
3787
- }
3788
- pendingRender = false;
3789
- if (lastCondition === cond && currentNodes.length > 0) {
3790
- return;
3791
- }
3792
- if (lastCondition === cond && lastCondition === false && renderFalse === void 0) {
3793
- return;
3794
- }
3795
- lastCondition = cond;
3796
- if (currentRoot2) {
3797
- destroyRoot(currentRoot2);
3798
- currentRoot2 = null;
3799
- }
3800
- removeNodes(currentNodes);
3801
- currentNodes = [];
3802
- const render2 = cond ? renderTrue : renderFalse;
3803
- if (!render2) {
3804
- return;
3805
- }
3806
- const root = createRootContext(hostRoot);
3807
- const prev = pushRoot(root);
3808
- let handledError = false;
3809
- try {
3810
- const output = untrack(render2);
3811
- if (output == null || output === false) {
3812
- return;
3813
- }
3814
- const el = createElementFn(output);
3815
- const nodes = toNodeArray(el);
3816
- insertNodesBefore(parent, nodes, endMarker);
3817
- currentNodes = nodes;
3818
- } catch (err) {
3819
- if (handleSuspend(err, root)) {
3820
- handledError = true;
3821
- destroyRoot(root);
3822
- return;
3823
- }
3824
- if (handleError(err, { source: "renderChild" }, root)) {
3825
- handledError = true;
3826
- destroyRoot(root);
3827
- return;
3828
- }
3829
- throw err;
3830
- } finally {
3831
- popRoot(prev);
3832
- if (!handledError) {
3833
- flushOnMount(root);
3834
- currentRoot2 = root;
3835
- } else {
3836
- currentRoot2 = null;
3837
- }
3838
- }
3839
- };
3840
- const dispose = createRenderEffect(runConditional);
3841
- return {
3842
- marker: fragment,
3843
- flush: () => {
3844
- if (pendingRender) {
3845
- runConditional();
3846
- }
3847
- },
3848
- dispose: () => {
3849
- dispose();
3850
- if (currentRoot2) {
3851
- destroyRoot(currentRoot2);
3852
- }
3853
- removeNodes(currentNodes);
3854
- currentNodes = [];
3855
- startMarker.parentNode?.removeChild(startMarker);
3856
- endMarker.parentNode?.removeChild(endMarker);
3857
- }
3858
- };
3859
- }
3860
- function createList(items, renderItem, createElementFn, getKey) {
3861
- const startMarker = document.createComment("fict:list:start");
3862
- const endMarker = document.createComment("fict:list:end");
3863
- const fragment = document.createDocumentFragment();
3864
- fragment.append(startMarker, endMarker);
3865
- const hostRoot = getCurrentRoot();
3866
- const nodeMap = /* @__PURE__ */ new Map();
3867
- let pendingItems = null;
3868
- const runListUpdate = () => {
3869
- const arr = items();
3870
- const parent = startMarker.parentNode;
3871
- if (!parent) {
3872
- pendingItems = arr;
3873
- return;
3874
- }
3875
- pendingItems = null;
3876
- const newNodeMap = /* @__PURE__ */ new Map();
3877
- const blocks = [];
3878
- for (let i = 0; i < arr.length; i++) {
3879
- const item = arr[i];
3880
- const key = getKey ? getKey(item, i) : i;
3881
- const existing = nodeMap.get(key);
3882
- let block;
3883
- if (existing) {
3884
- const previousValue = existing.value();
3885
- if (!getKey && previousValue !== item) {
3886
- destroyRoot(existing.root);
3887
- removeBlockNodes(existing);
3888
- block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn, hostRoot);
3889
- } else {
3890
- const previousIndex = existing.index();
3891
- existing.value(item);
3892
- existing.index(i);
3893
- const needsRerender = getKey ? true : previousValue !== item || previousIndex !== i;
3894
- block = needsRerender ? rerenderBlock(existing, createElementFn) : existing;
3895
- }
3896
- } else {
3897
- block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn, hostRoot);
3898
- }
3899
- newNodeMap.set(key, block);
3900
- blocks.push(block);
3901
- }
3902
- for (const [key, managed] of nodeMap) {
3903
- if (!newNodeMap.has(key)) {
3904
- destroyRoot(managed.root);
3905
- removeBlockNodes(managed);
3906
- }
3907
- }
3908
- let anchor = endMarker;
3909
- for (let i = blocks.length - 1; i >= 0; i--) {
3910
- const block = blocks[i];
3911
- insertNodesBefore(parent, block.nodes, anchor);
3912
- if (block.nodes.length > 0) {
3913
- anchor = block.nodes[0];
3914
- }
3915
- }
3916
- nodeMap.clear();
3917
- for (const [k, v] of newNodeMap) {
3918
- nodeMap.set(k, v);
3919
- }
3920
- };
3921
- const dispose = createRenderEffect(runListUpdate);
3922
- return {
3923
- marker: fragment,
3924
- flush: () => {
3925
- if (pendingItems !== null) {
3926
- runListUpdate();
3927
- }
3928
- },
3929
- dispose: () => {
3930
- dispose();
3931
- for (const [, managed] of nodeMap) {
3932
- destroyRoot(managed.root);
3933
- removeBlockNodes(managed);
3934
- }
3935
- nodeMap.clear();
3936
- startMarker.parentNode?.removeChild(startMarker);
3937
- endMarker.parentNode?.removeChild(endMarker);
3938
- }
3939
- };
3940
- }
3941
- function createShow(el, condition, displayValue) {
3942
- const originalDisplay = displayValue ?? el.style.display;
3943
- createRenderEffect(() => {
3944
- el.style.display = condition() ? originalDisplay : "none";
3945
- });
3946
- }
3947
- function createPortal(container, render2, createElementFn) {
3948
- const parentRoot = getCurrentRoot();
3949
- const marker = document.createComment("fict:portal");
3950
- container.appendChild(marker);
3951
- let currentNodes = [];
3952
- let currentRoot2 = null;
3953
- const dispose = createRenderEffect(() => {
3954
- if (currentRoot2) {
3955
- destroyRoot(currentRoot2);
3956
- currentRoot2 = null;
3957
- }
3958
- if (currentNodes.length > 0) {
3959
- removeNodes(currentNodes);
3960
- currentNodes = [];
3961
- }
3962
- const root = createRootContext(parentRoot);
3963
- const prev = pushRoot(root);
3964
- let handledError = false;
3965
- try {
3966
- const output = render2();
3967
- if (output != null && output !== false) {
3968
- const el = createElementFn(output);
3969
- const nodes = toNodeArray(el);
3970
- if (marker.parentNode) {
3971
- insertNodesBefore(marker.parentNode, nodes, marker);
3972
- }
3973
- currentNodes = nodes;
3974
- }
3975
- } catch (err) {
3976
- if (handleSuspend(err, root)) {
3977
- handledError = true;
3978
- destroyRoot(root);
3979
- currentNodes = [];
3980
- return;
3981
- }
3982
- if (handleError(err, { source: "renderChild" }, root)) {
3983
- handledError = true;
3984
- destroyRoot(root);
3985
- currentNodes = [];
3986
- return;
3987
- }
3988
- throw err;
3989
- } finally {
3990
- popRoot(prev);
3991
- if (!handledError) {
3992
- flushOnMount(root);
3993
- currentRoot2 = root;
3994
- } else {
3995
- currentRoot2 = null;
3996
- }
3997
- }
3998
- });
3999
- const portalDispose = () => {
4000
- dispose();
4001
- if (currentRoot2) {
4002
- destroyRoot(currentRoot2);
4003
- }
4004
- if (currentNodes.length > 0) {
4005
- removeNodes(currentNodes);
4006
- }
4007
- marker.parentNode?.removeChild(marker);
4008
- };
4009
- if (parentRoot) {
4010
- parentRoot.destroyCallbacks.push(portalDispose);
4011
- }
4012
- return {
4013
- marker,
4014
- dispose: portalDispose
4015
- };
4016
- }
4017
- function mountBlock(initialValue, initialIndex, renderItem, parent, anchor, createElementFn, hostRoot) {
4018
- const start = document.createComment("fict:block:start");
4019
- const end = document.createComment("fict:block:end");
4020
- const valueSig = createVersionedSignalAccessor(initialValue);
4021
- const indexSig = signal(initialIndex);
4022
- const renderCurrent = () => renderItem(valueSig, indexSig);
4023
- const root = createRootContext(hostRoot);
4024
- const prev = pushRoot(root);
4025
- const nodes = [start];
4026
- let handledError = false;
4027
- try {
4028
- const output = renderCurrent();
4029
- if (output != null && output !== false) {
4030
- const el = createElementFn(output);
4031
- const rendered = toNodeArray(el);
4032
- nodes.push(...rendered);
4033
- }
4034
- nodes.push(end);
4035
- insertNodesBefore(parent, nodes, anchor);
4036
- } catch (err) {
4037
- if (handleSuspend(err, root)) {
4038
- handledError = true;
4039
- nodes.push(end);
4040
- insertNodesBefore(parent, nodes, anchor);
4041
- } else if (handleError(err, { source: "renderChild" }, root)) {
4042
- handledError = true;
4043
- nodes.push(end);
4044
- insertNodesBefore(parent, nodes, anchor);
4045
- } else {
4046
- throw err;
4047
- }
4048
- } finally {
4049
- popRoot(prev);
4050
- if (!handledError) {
4051
- flushOnMount(root);
4052
- } else {
4053
- destroyRoot(root);
4054
- }
4055
- }
4056
- return {
4057
- nodes,
4058
- root,
4059
- value: valueSig,
4060
- index: indexSig,
4061
- start,
4062
- end,
4063
- renderCurrent
4064
- };
4065
- }
4066
- function rerenderBlock(block, createElementFn) {
4067
- const currentContent = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
4068
- const currentNode = currentContent.length === 1 ? currentContent[0] : null;
4069
- clearRoot(block.root);
4070
- const prev = pushRoot(block.root);
4071
- let nextOutput;
4072
- let handledError = false;
4073
- try {
4074
- nextOutput = block.renderCurrent();
4075
- } catch (err) {
4076
- if (handleSuspend(err, block.root)) {
4077
- handledError = true;
4078
- popRoot(prev);
4079
- destroyRoot(block.root);
4080
- block.nodes = [block.start, block.end];
4081
- return block;
4082
- }
4083
- if (handleError(err, { source: "renderChild" }, block.root)) {
4084
- handledError = true;
4085
- popRoot(prev);
4086
- destroyRoot(block.root);
4087
- block.nodes = [block.start, block.end];
4088
- return block;
4089
- }
4090
- throw err;
4091
- } finally {
4092
- if (!handledError) {
4093
- popRoot(prev);
4094
- }
4095
- }
4096
- if (isFragmentVNode(nextOutput) && currentContent.length > 0) {
4097
- const patched = patchFragmentChildren(currentContent, nextOutput.props?.children);
4098
- if (patched) {
4099
- block.nodes = [block.start, ...currentContent, block.end];
4100
- return block;
4101
- }
4102
- }
4103
- if (currentNode && patchNode(currentNode, nextOutput)) {
4104
- block.nodes = [block.start, currentNode, block.end];
4105
- return block;
4106
- }
4107
- clearContent(block);
4108
- if (nextOutput != null && nextOutput !== false) {
4109
- const newNodes = toNodeArray(
4110
- nextOutput instanceof Node ? nextOutput : createElementFn(nextOutput)
4111
- );
4112
- insertNodesBefore(block.start.parentNode, newNodes, block.end);
4113
- block.nodes = [block.start, ...newNodes, block.end];
4114
- } else {
4115
- block.nodes = [block.start, block.end];
4116
- }
4117
- return block;
4118
- }
4119
- function patchElement(el, output) {
4120
- if (output === null || output === void 0 || output === false || typeof output === "string" || typeof output === "number") {
4121
- el.textContent = output === null || output === void 0 || output === false ? "" : String(output);
4122
- return true;
4123
- }
4124
- if (output instanceof Text) {
4125
- el.textContent = output.data;
4126
- return true;
4127
- }
4128
- if (output && typeof output === "object" && !(output instanceof Node)) {
4129
- const vnode = output;
4130
- if (typeof vnode.type === "string" && vnode.type.toLowerCase() === el.tagName.toLowerCase()) {
4131
- const children = vnode.props?.children;
4132
- const props = vnode.props ?? {};
4133
- for (const [key, value] of Object.entries(props)) {
4134
- if (key === "children" || key === "key") continue;
4135
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
4136
- if (key === "class" || key === "className") {
4137
- el.setAttribute("class", value === false || value === null ? "" : String(value));
4138
- } else if (key === "style" && typeof value === "string") {
4139
- el.style.cssText = value;
4140
- } else if (value === false || value === null || value === void 0) {
4141
- el.removeAttribute(key);
4142
- } else if (value === true) {
4143
- el.setAttribute(key, "");
4144
- } else {
4145
- el.setAttribute(key, String(value));
4146
- }
4147
- }
4148
- }
4149
- if (typeof children === "string" || typeof children === "number" || children === null || children === void 0 || children === false) {
4150
- el.textContent = children === null || children === void 0 || children === false ? "" : String(children);
4151
- return true;
4152
- }
4153
- if (children && typeof children === "object" && !Array.isArray(children) && !(children instanceof Node)) {
4154
- const childVNode = children;
4155
- if (typeof childVNode.type === "string") {
4156
- const childEl = el.querySelector(childVNode.type);
4157
- if (childEl && patchElement(childEl, children)) {
4158
- return true;
4159
- }
4160
- }
4161
- }
4162
- return false;
4163
- }
4164
- }
4165
- if (output instanceof Node) {
4166
- if (output.nodeType === Node.ELEMENT_NODE) {
4167
- const nextEl = output;
4168
- if (nextEl.tagName.toLowerCase() === el.tagName.toLowerCase()) {
4169
- el.textContent = nextEl.textContent;
4170
- return true;
4171
- }
4172
- } else if (output.nodeType === Node.TEXT_NODE) {
4173
- el.textContent = output.data;
4174
- return true;
4175
- }
4176
- }
4177
- return false;
4178
- }
4179
- function patchNode(currentNode, nextOutput) {
4180
- if (!currentNode) return false;
4181
- if (currentNode instanceof Text && (nextOutput === null || nextOutput === void 0 || nextOutput === false || typeof nextOutput === "string" || typeof nextOutput === "number" || nextOutput instanceof Text)) {
4182
- const nextText = nextOutput instanceof Text ? nextOutput.data : nextOutput === null || nextOutput === void 0 || nextOutput === false ? "" : String(nextOutput);
4183
- currentNode.data = nextText;
4184
- return true;
4185
- }
4186
- if (currentNode instanceof Element && patchElement(currentNode, nextOutput)) {
4187
- return true;
4188
- }
4189
- if (nextOutput instanceof Node && currentNode === nextOutput) {
4190
- return true;
4191
- }
4192
- return false;
4193
- }
4194
- function isFragmentVNode(value) {
4195
- return value != null && typeof value === "object" && !(value instanceof Node) && value.type === Fragment;
4196
- }
4197
- function normalizeChildren(children, result = []) {
4198
- if (children === void 0) {
4199
- return result;
4200
- }
4201
- if (Array.isArray(children)) {
4202
- for (const child of children) {
4203
- normalizeChildren(child, result);
4204
- }
4205
- return result;
4206
- }
4207
- if (children === null || children === false) {
4208
- return result;
4209
- }
4210
- result.push(children);
4211
- return result;
4212
- }
4213
- function patchFragmentChildren(nodes, children) {
4214
- const normalized = normalizeChildren(children);
4215
- if (normalized.length !== nodes.length) {
4216
- return false;
4217
- }
4218
- for (let i = 0; i < normalized.length; i++) {
4219
- if (!patchNode(nodes[i], normalized[i])) {
4220
- return false;
4221
- }
4222
- }
4223
- return true;
4224
- }
4225
- function clearContent(block) {
4226
- const nodes = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
4227
- removeNodes(nodes);
4228
- }
4229
- function removeBlockNodes(block) {
4230
- let cursor = block.start;
4231
- const end = block.end;
4232
- while (cursor) {
4233
- const next = cursor.nextSibling;
4234
- cursor.parentNode?.removeChild(cursor);
4235
- if (cursor === end) break;
4236
- cursor = next;
4237
- }
4238
- }
4239
27
 
4240
- // src/scope.ts
4241
- function createScope() {
4242
- let dispose = null;
4243
- const stop = () => {
4244
- if (dispose) {
4245
- dispose();
4246
- dispose = null;
4247
- }
4248
- };
4249
- const run = (fn) => {
4250
- stop();
4251
- const { dispose: rootDispose, value } = createRoot(fn);
4252
- dispose = rootDispose;
4253
- return value;
4254
- };
4255
- registerRootCleanup(stop);
4256
- return { run, stop };
4257
- }
4258
- function runInScope(flag, fn) {
4259
- const scope = createScope();
4260
- const evaluate = () => isReactive(flag) ? flag() : !!flag;
4261
- createEffect(() => {
4262
- const enabled = evaluate();
4263
- if (enabled) {
4264
- scope.run(fn);
4265
- } else {
4266
- scope.stop();
4267
- }
4268
- });
4269
- onCleanup(scope.stop);
4270
- }
4271
28
 
4272
- // src/versioned-signal.ts
4273
- function createVersionedSignal(initialValue, options2) {
4274
- const equals = options2?.equals ?? Object.is;
4275
- const value = signal(initialValue);
4276
- const version = signal(0);
4277
- const bumpVersion = () => {
4278
- const next = version() + 1;
4279
- version(next);
4280
- };
4281
- return {
4282
- read: () => {
4283
- version();
4284
- return value();
4285
- },
4286
- write: (next) => {
4287
- const prev = value();
4288
- if (!equals(prev, next)) {
4289
- value(next);
4290
- return;
4291
- }
4292
- bumpVersion();
4293
- },
4294
- force: () => {
4295
- bumpVersion();
4296
- },
4297
- peekVersion: () => version(),
4298
- peekValue: () => value()
4299
- };
4300
- }
29
+
30
+
31
+
32
+
33
+
34
+
35
+
36
+
37
+ var _chunkPMF6MWEVcjs = require('./chunk-PMF6MWEV.cjs');
4301
38
 
4302
39
  // src/ref.ts
4303
40
  function createRef() {
@@ -4309,8 +46,8 @@ function ErrorBoundary(props) {
4309
46
  const fragment = document.createDocumentFragment();
4310
47
  const marker = document.createComment("fict:error-boundary");
4311
48
  fragment.appendChild(marker);
4312
- const currentView = signal(props.children ?? null);
4313
- const hostRoot = getCurrentRoot();
49
+ const currentView = _chunkPMF6MWEVcjs.signal.call(void 0, _nullishCoalesce(props.children, () => ( null)));
50
+ const hostRoot = _chunkPMF6MWEVcjs.getCurrentRoot.call(void 0, );
4314
51
  let cleanup;
4315
52
  let activeNodes = [];
4316
53
  let renderingFallback = false;
@@ -4318,7 +55,7 @@ function ErrorBoundary(props) {
4318
55
  if (err != null) {
4319
56
  return typeof props.fallback === "function" ? props.fallback(err) : props.fallback;
4320
57
  }
4321
- return props.children ?? null;
58
+ return _nullishCoalesce(props.children, () => ( null));
4322
59
  };
4323
60
  const renderValue = (value) => {
4324
61
  if (cleanup) {
@@ -4326,26 +63,26 @@ function ErrorBoundary(props) {
4326
63
  cleanup = void 0;
4327
64
  }
4328
65
  if (activeNodes.length) {
4329
- removeNodes(activeNodes);
66
+ _chunkPMF6MWEVcjs.removeNodes.call(void 0, activeNodes);
4330
67
  activeNodes = [];
4331
68
  }
4332
69
  if (value == null || value === false) {
4333
70
  return;
4334
71
  }
4335
- const root = createRootContext(hostRoot);
4336
- const prev = pushRoot(root);
72
+ const root = _chunkPMF6MWEVcjs.createRootContext.call(void 0, hostRoot);
73
+ const prev = _chunkPMF6MWEVcjs.pushRoot.call(void 0, root);
4337
74
  let nodes = [];
4338
75
  try {
4339
- const output = createElement(value);
4340
- nodes = toNodeArray(output);
76
+ const output = _chunkPMF6MWEVcjs.createElement.call(void 0, value);
77
+ nodes = _chunkPMF6MWEVcjs.toNodeArray.call(void 0, output);
4341
78
  const parentNode = marker.parentNode;
4342
79
  if (parentNode) {
4343
- insertNodesBefore(parentNode, nodes, marker);
80
+ _chunkPMF6MWEVcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
4344
81
  }
4345
82
  } catch (err) {
4346
- popRoot(prev);
4347
- flushOnMount(root);
4348
- destroyRoot(root);
83
+ _chunkPMF6MWEVcjs.popRoot.call(void 0, prev);
84
+ _chunkPMF6MWEVcjs.flushOnMount.call(void 0, root);
85
+ _chunkPMF6MWEVcjs.destroyRoot.call(void 0, root);
4349
86
  if (renderingFallback) {
4350
87
  throw err;
4351
88
  }
@@ -4353,35 +90,35 @@ function ErrorBoundary(props) {
4353
90
  try {
4354
91
  renderValue(toView(err));
4355
92
  renderingFallback = false;
4356
- props.onError?.(err);
93
+ _optionalChain([props, 'access', _ => _.onError, 'optionalCall', _2 => _2(err)]);
4357
94
  } catch (fallbackErr) {
4358
- props.onError?.(err);
95
+ _optionalChain([props, 'access', _3 => _3.onError, 'optionalCall', _4 => _4(err)]);
4359
96
  throw fallbackErr;
4360
97
  }
4361
98
  return;
4362
99
  }
4363
- popRoot(prev);
4364
- flushOnMount(root);
100
+ _chunkPMF6MWEVcjs.popRoot.call(void 0, prev);
101
+ _chunkPMF6MWEVcjs.flushOnMount.call(void 0, root);
4365
102
  cleanup = () => {
4366
- destroyRoot(root);
4367
- removeNodes(nodes);
103
+ _chunkPMF6MWEVcjs.destroyRoot.call(void 0, root);
104
+ _chunkPMF6MWEVcjs.removeNodes.call(void 0, nodes);
4368
105
  };
4369
106
  activeNodes = nodes;
4370
107
  };
4371
- createEffect(() => {
108
+ _chunkPMF6MWEVcjs.createEffect.call(void 0, () => {
4372
109
  const value = currentView();
4373
110
  renderValue(value);
4374
111
  });
4375
- registerErrorHandler((err) => {
112
+ _chunkPMF6MWEVcjs.registerErrorHandler.call(void 0, (err) => {
4376
113
  renderValue(toView(err));
4377
- props.onError?.(err);
114
+ _optionalChain([props, 'access', _5 => _5.onError, 'optionalCall', _6 => _6(err)]);
4378
115
  return true;
4379
116
  });
4380
117
  if (props.resetKeys !== void 0) {
4381
118
  const isGetter = typeof props.resetKeys === "function" && props.resetKeys.length === 0;
4382
119
  const getter = isGetter ? props.resetKeys : void 0;
4383
120
  let prev = isGetter ? getter() : props.resetKeys;
4384
- createEffect(() => {
121
+ _chunkPMF6MWEVcjs.createEffect.call(void 0, () => {
4385
122
  const next = getter ? getter() : props.resetKeys;
4386
123
  if (prev !== next) {
4387
124
  prev = next;
@@ -4410,11 +147,11 @@ function createSuspenseToken() {
4410
147
  }
4411
148
  var isThenable = (value) => typeof value === "object" && value !== null && typeof value.then === "function";
4412
149
  function Suspense(props) {
4413
- const currentView = signal(props.children ?? null);
4414
- 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);
4415
152
  let resolvedOnce = false;
4416
153
  let epoch = 0;
4417
- const hostRoot = getCurrentRoot();
154
+ const hostRoot = _chunkPMF6MWEVcjs.getCurrentRoot.call(void 0, );
4418
155
  const toFallback = (err) => typeof props.fallback === "function" ? props.fallback(err) : props.fallback;
4419
156
  const switchView = (view) => {
4420
157
  currentView(view);
@@ -4426,42 +163,42 @@ function Suspense(props) {
4426
163
  cleanup = void 0;
4427
164
  }
4428
165
  if (activeNodes.length) {
4429
- removeNodes(activeNodes);
166
+ _chunkPMF6MWEVcjs.removeNodes.call(void 0, activeNodes);
4430
167
  activeNodes = [];
4431
168
  }
4432
169
  if (view == null || view === false) {
4433
170
  return;
4434
171
  }
4435
- const root = createRootContext(hostRoot);
4436
- const prev = pushRoot(root);
172
+ const root = _chunkPMF6MWEVcjs.createRootContext.call(void 0, hostRoot);
173
+ const prev = _chunkPMF6MWEVcjs.pushRoot.call(void 0, root);
4437
174
  let nodes = [];
4438
175
  try {
4439
- const output = createElement(view);
4440
- nodes = toNodeArray(output);
176
+ const output = _chunkPMF6MWEVcjs.createElement.call(void 0, view);
177
+ nodes = _chunkPMF6MWEVcjs.toNodeArray.call(void 0, output);
4441
178
  const suspendedAttempt = nodes.length > 0 && nodes.every((node) => node instanceof Comment && node.data === "fict:suspend");
4442
179
  if (suspendedAttempt) {
4443
- popRoot(prev);
4444
- destroyRoot(root);
180
+ _chunkPMF6MWEVcjs.popRoot.call(void 0, prev);
181
+ _chunkPMF6MWEVcjs.destroyRoot.call(void 0, root);
4445
182
  return;
4446
183
  }
4447
184
  const parentNode = marker.parentNode;
4448
185
  if (parentNode) {
4449
- insertNodesBefore(parentNode, nodes, marker);
186
+ _chunkPMF6MWEVcjs.insertNodesBefore.call(void 0, parentNode, nodes, marker);
4450
187
  }
4451
188
  } catch (err) {
4452
- popRoot(prev);
4453
- flushOnMount(root);
4454
- destroyRoot(root);
4455
- 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)) {
4456
193
  throw err;
4457
194
  }
4458
195
  return;
4459
196
  }
4460
- popRoot(prev);
4461
- flushOnMount(root);
197
+ _chunkPMF6MWEVcjs.popRoot.call(void 0, prev);
198
+ _chunkPMF6MWEVcjs.flushOnMount.call(void 0, root);
4462
199
  cleanup = () => {
4463
- destroyRoot(root);
4464
- removeNodes(nodes);
200
+ _chunkPMF6MWEVcjs.destroyRoot.call(void 0, root);
201
+ _chunkPMF6MWEVcjs.removeNodes.call(void 0, nodes);
4465
202
  };
4466
203
  activeNodes = nodes;
4467
204
  };
@@ -4473,10 +210,10 @@ function Suspense(props) {
4473
210
  const onResolveMaybe = () => {
4474
211
  if (!resolvedOnce) {
4475
212
  resolvedOnce = true;
4476
- props.onResolve?.();
213
+ _optionalChain([props, 'access', _7 => _7.onResolve, 'optionalCall', _8 => _8()]);
4477
214
  }
4478
215
  };
4479
- registerSuspenseHandler((token) => {
216
+ _chunkPMF6MWEVcjs.registerSuspenseHandler.call(void 0, (token) => {
4480
217
  const tokenEpoch = epoch;
4481
218
  pending(pending() + 1);
4482
219
  switchView(toFallback());
@@ -4490,7 +227,7 @@ function Suspense(props) {
4490
227
  const newPending = Math.max(0, pending() - 1);
4491
228
  pending(newPending);
4492
229
  if (newPending === 0) {
4493
- switchView(props.children ?? null);
230
+ switchView(_nullishCoalesce(props.children, () => ( null)));
4494
231
  onResolveMaybe();
4495
232
  }
4496
233
  },
@@ -4500,8 +237,8 @@ function Suspense(props) {
4500
237
  }
4501
238
  const newPending = Math.max(0, pending() - 1);
4502
239
  pending(newPending);
4503
- props.onReject?.(err);
4504
- 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)) {
4505
242
  throw err;
4506
243
  }
4507
244
  }
@@ -4510,119 +247,49 @@ function Suspense(props) {
4510
247
  }
4511
248
  return false;
4512
249
  });
4513
- createEffect(() => {
250
+ _chunkPMF6MWEVcjs.createEffect.call(void 0, () => {
4514
251
  renderView(currentView());
4515
252
  });
4516
253
  if (props.resetKeys !== void 0) {
4517
254
  const isGetter = typeof props.resetKeys === "function" && props.resetKeys.length === 0;
4518
255
  const getter = isGetter ? props.resetKeys : void 0;
4519
256
  let prev = isGetter ? getter() : props.resetKeys;
4520
- createEffect(() => {
257
+ _chunkPMF6MWEVcjs.createEffect.call(void 0, () => {
4521
258
  const next = getter ? getter() : props.resetKeys;
4522
259
  if (prev !== next) {
4523
260
  prev = next;
4524
261
  epoch++;
4525
262
  pending(0);
4526
- switchView(props.children ?? null);
263
+ switchView(_nullishCoalesce(props.children, () => ( null)));
4527
264
  }
4528
265
  });
4529
266
  }
4530
267
  return fragment;
4531
268
  }
4532
269
 
4533
- exports.$effect = $effect;
4534
- exports.$memo = $memo;
4535
- exports.$state = $state;
4536
- exports.Aliases = Aliases;
4537
- exports.BooleanAttributes = BooleanAttributes;
4538
- exports.ChildProperties = ChildProperties;
4539
- exports.DelegatedEvents = DelegatedEvents;
4540
- exports.ErrorBoundary = ErrorBoundary;
4541
- exports.Fragment = Fragment;
4542
- exports.Properties = Properties;
4543
- exports.SVGElements = SVGElements;
4544
- exports.SVGNamespace = SVGNamespace;
4545
- exports.Suspense = Suspense;
4546
- exports.UnitlessStyles = UnitlessStyles;
4547
- exports.__fictPopContext = __fictPopContext;
4548
- exports.__fictProp = __fictProp;
4549
- exports.__fictPropsRest = __fictPropsRest;
4550
- exports.__fictPushContext = __fictPushContext;
4551
- exports.__fictRender = __fictRender;
4552
- exports.__fictResetContext = __fictResetContext;
4553
- exports.__fictUseContext = __fictUseContext;
4554
- exports.__fictUseEffect = __fictUseEffect;
4555
- exports.__fictUseMemo = __fictUseMemo;
4556
- exports.__fictUseSignal = __fictUseSignal;
4557
- exports.addEventListener = addEventListener;
4558
- exports.assign = assign;
4559
- exports.batch = batch2;
4560
- exports.bindAttribute = bindAttribute;
4561
- exports.bindClass = bindClass;
4562
- exports.bindEvent = bindEvent;
4563
- exports.bindProperty = bindProperty;
4564
- exports.bindRef = bindRef;
4565
- exports.bindStyle = bindStyle;
4566
- exports.bindText = bindText;
4567
- exports.callEventHandler = callEventHandler;
4568
- exports.classList = classList;
4569
- exports.clearDelegatedEvents = clearDelegatedEvents;
4570
- exports.createAttributeBinding = createAttributeBinding;
4571
- exports.createChildBinding = createChildBinding;
4572
- exports.createClassBinding = createClassBinding;
4573
- exports.createConditional = createConditional;
4574
- exports.createEffect = createEffect;
4575
- exports.createElement = createElement;
4576
- exports.createKeyedBlock = createKeyedBlock;
4577
- exports.createKeyedList = createKeyedList;
4578
- exports.createKeyedListContainer = createKeyedListContainer;
4579
- exports.createList = createList;
4580
- exports.createMemo = createMemo;
4581
- exports.createPortal = createPortal;
4582
- exports.createPropsProxy = createPropsProxy;
4583
- exports.createRef = createRef;
4584
- exports.createRenderEffect = createRenderEffect;
4585
- exports.createRoot = createRoot;
4586
- exports.createScope = createScope;
4587
- exports.createSelector = createSelector;
4588
- exports.createShow = createShow;
4589
- exports.createSignal = signal;
4590
- exports.createStore = createStore;
4591
- exports.createStyleBinding = createStyleBinding;
4592
- exports.createSuspenseToken = createSuspenseToken;
4593
- exports.createTextBinding = createTextBinding;
4594
- exports.createVersionedSignal = createVersionedSignal;
4595
- exports.delegateEvents = delegateEvents;
4596
- exports.destroyMarkerBlock = destroyMarkerBlock;
4597
- exports.effectScope = effectScope;
4598
- exports.getDevtoolsHook = getDevtoolsHook;
4599
- exports.getFirstNodeAfter = getFirstNodeAfter;
4600
- exports.getPropAlias = getPropAlias;
4601
- exports.insert = insert;
4602
- exports.insertNodesBefore = insertNodesBefore;
4603
- exports.isNodeBetweenMarkers = isNodeBetweenMarkers;
4604
- exports.isReactive = isReactive;
4605
- exports.mergeProps = mergeProps;
4606
- exports.moveMarkerBlock = moveMarkerBlock;
4607
- exports.moveNodesBefore = moveNodesBefore;
4608
- exports.onCleanup = onCleanup;
4609
- exports.onDestroy = onDestroy;
4610
- exports.onMount = onMount;
4611
- exports.prop = __fictProp;
4612
- exports.reconcileArrays = reconcileArrays;
4613
- exports.removeNodes = removeNodes;
4614
- exports.render = render;
4615
- exports.runInScope = runInScope;
4616
- exports.setCycleProtectionOptions = setCycleProtectionOptions;
4617
- exports.spread = spread;
4618
- exports.startTransition = startTransition;
4619
- exports.template = template;
4620
- exports.toNodeArray = toNodeArray;
4621
- exports.untrack = untrack2;
4622
- exports.unwrap = unwrap2;
4623
- exports.unwrapPrimitive = unwrapPrimitive;
4624
- exports.useDeferredValue = useDeferredValue;
4625
- exports.useProp = useProp;
4626
- exports.useTransition = useTransition;
4627
- //# sourceMappingURL=index.cjs.map
270
+
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;
4628
295
  //# sourceMappingURL=index.cjs.map