@fictjs/runtime 0.3.0 → 0.5.0

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