@fictjs/runtime 0.0.12 → 0.0.14

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (65) hide show
  1. package/dist/advanced.cjs +79 -0
  2. package/dist/advanced.cjs.map +1 -0
  3. package/dist/advanced.d.cts +50 -0
  4. package/dist/advanced.d.ts +50 -0
  5. package/dist/advanced.js +79 -0
  6. package/dist/advanced.js.map +1 -0
  7. package/dist/chunk-624QY53A.cjs +45 -0
  8. package/dist/chunk-624QY53A.cjs.map +1 -0
  9. package/dist/chunk-F3AIYQB7.js +45 -0
  10. package/dist/chunk-F3AIYQB7.js.map +1 -0
  11. package/dist/chunk-GJTYOFMO.cjs +109 -0
  12. package/dist/chunk-GJTYOFMO.cjs.map +1 -0
  13. package/dist/chunk-IUZXKAAY.js +109 -0
  14. package/dist/chunk-IUZXKAAY.js.map +1 -0
  15. package/dist/{slim.cjs → chunk-PMF6MWEV.cjs} +2557 -3110
  16. package/dist/chunk-PMF6MWEV.cjs.map +1 -0
  17. package/dist/{slim.js → chunk-RY4WDS6R.js} +2596 -3097
  18. package/dist/chunk-RY4WDS6R.js.map +1 -0
  19. package/dist/context-B7UYnfzM.d.ts +153 -0
  20. package/dist/context-UXySaqI_.d.cts +153 -0
  21. package/dist/effect-Auji1rz9.d.cts +350 -0
  22. package/dist/effect-Auji1rz9.d.ts +350 -0
  23. package/dist/index.cjs +108 -4441
  24. package/dist/index.cjs.map +1 -1
  25. package/dist/index.d.cts +5 -1492
  26. package/dist/index.d.ts +5 -1492
  27. package/dist/index.dev.js +1020 -2788
  28. package/dist/index.dev.js.map +1 -1
  29. package/dist/index.js +63 -4301
  30. package/dist/index.js.map +1 -1
  31. package/dist/internal.cjs +901 -0
  32. package/dist/internal.cjs.map +1 -0
  33. package/dist/internal.d.cts +158 -0
  34. package/dist/internal.d.ts +158 -0
  35. package/dist/internal.js +901 -0
  36. package/dist/internal.js.map +1 -0
  37. package/dist/{jsx-dev-runtime.d.ts → props-CrOMYbLv.d.cts} +107 -18
  38. package/dist/{jsx-dev-runtime.d.cts → props-ES0Ag_Wd.d.ts} +107 -18
  39. package/dist/scope-DKYzWfTn.d.cts +55 -0
  40. package/dist/scope-S6eAzBJZ.d.ts +55 -0
  41. package/package.json +10 -5
  42. package/src/advanced.ts +101 -0
  43. package/src/binding.ts +25 -422
  44. package/src/constants.ts +345 -344
  45. package/src/context.ts +300 -0
  46. package/src/cycle-guard.ts +124 -97
  47. package/src/delegated-events.ts +24 -0
  48. package/src/dom.ts +19 -25
  49. package/src/effect.ts +4 -0
  50. package/src/hooks.ts +9 -1
  51. package/src/index.ts +41 -130
  52. package/src/internal.ts +130 -0
  53. package/src/lifecycle.ts +13 -2
  54. package/src/list-helpers.ts +6 -65
  55. package/src/props.ts +48 -46
  56. package/src/signal.ts +59 -39
  57. package/src/store.ts +47 -7
  58. package/src/versioned-signal.ts +3 -3
  59. package/dist/jsx-runtime.d.cts +0 -671
  60. package/dist/jsx-runtime.d.ts +0 -671
  61. package/dist/slim.cjs.map +0 -1
  62. package/dist/slim.d.cts +0 -504
  63. package/dist/slim.d.ts +0 -504
  64. package/dist/slim.js.map +0 -1
  65. package/src/slim.ts +0 -69
package/dist/index.dev.js CHANGED
@@ -8,99 +8,126 @@ function getDevtoolsHook() {
8
8
  }
9
9
 
10
10
  // src/cycle-guard.ts
11
- var defaultOptions = {
12
- maxFlushCyclesPerMicrotask: 1e4,
13
- maxEffectRunsPerFlush: 2e4,
14
- windowSize: 5,
15
- highUsageRatio: 0.8,
16
- maxRootReentrantDepth: 10,
17
- enableWindowWarning: true,
18
- devMode: false
11
+ var isDev = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
12
+ var setCycleProtectionOptions = () => {
19
13
  };
20
- var options = {
21
- ...defaultOptions
14
+ var resetCycleProtectionStateForTests = () => {
22
15
  };
23
- var effectRunsThisFlush = 0;
24
- var windowUsage = [];
25
- var rootDepth = /* @__PURE__ */ new WeakMap();
26
- var flushWarned = false;
27
- var rootWarned = false;
28
- var windowWarned = false;
29
- function setCycleProtectionOptions(opts) {
30
- options = { ...options, ...opts };
31
- }
32
- function beginFlushGuard() {
33
- effectRunsThisFlush = 0;
34
- flushWarned = false;
35
- windowWarned = false;
36
- }
37
- function beforeEffectRunGuard() {
38
- const next = ++effectRunsThisFlush;
39
- if (next > options.maxFlushCyclesPerMicrotask || next > options.maxEffectRunsPerFlush) {
40
- const message = `[fict] cycle protection triggered: flush-budget-exceeded`;
41
- if (options.devMode) {
42
- throw new Error(message);
16
+ var beginFlushGuard = () => {
17
+ };
18
+ var beforeEffectRunGuard = () => true;
19
+ var endFlushGuard = () => {
20
+ };
21
+ var enterRootGuard = () => true;
22
+ var exitRootGuard = () => {
23
+ };
24
+ if (isDev) {
25
+ const defaultOptions = {
26
+ maxFlushCyclesPerMicrotask: 1e4,
27
+ maxEffectRunsPerFlush: 2e4,
28
+ windowSize: 5,
29
+ highUsageRatio: 0.8,
30
+ maxRootReentrantDepth: 10,
31
+ enableWindowWarning: true,
32
+ devMode: false
33
+ };
34
+ let options = {
35
+ ...defaultOptions
36
+ };
37
+ let effectRunsThisFlush = 0;
38
+ let windowUsage = [];
39
+ let rootDepth = /* @__PURE__ */ new WeakMap();
40
+ let flushWarned = false;
41
+ let rootWarned = false;
42
+ let windowWarned = false;
43
+ setCycleProtectionOptions = (opts) => {
44
+ options = { ...options, ...opts };
45
+ };
46
+ resetCycleProtectionStateForTests = () => {
47
+ options = { ...defaultOptions };
48
+ effectRunsThisFlush = 0;
49
+ windowUsage = [];
50
+ rootDepth = /* @__PURE__ */ new WeakMap();
51
+ flushWarned = false;
52
+ rootWarned = false;
53
+ windowWarned = false;
54
+ };
55
+ beginFlushGuard = () => {
56
+ effectRunsThisFlush = 0;
57
+ flushWarned = false;
58
+ windowWarned = false;
59
+ };
60
+ beforeEffectRunGuard = () => {
61
+ const next = ++effectRunsThisFlush;
62
+ if (next > options.maxFlushCyclesPerMicrotask || next > options.maxEffectRunsPerFlush) {
63
+ const message = `[fict] cycle protection triggered: flush-budget-exceeded`;
64
+ if (options.devMode) {
65
+ throw new Error(message);
66
+ }
67
+ if (!flushWarned) {
68
+ flushWarned = true;
69
+ console.warn(message, { effectRuns: next });
70
+ }
71
+ return false;
43
72
  }
44
- if (!flushWarned) {
45
- flushWarned = true;
46
- console.warn(message, { effectRuns: next });
73
+ return true;
74
+ };
75
+ endFlushGuard = () => {
76
+ recordWindowUsage(effectRunsThisFlush, options.maxFlushCyclesPerMicrotask);
77
+ effectRunsThisFlush = 0;
78
+ };
79
+ enterRootGuard = (root) => {
80
+ const depth = (rootDepth.get(root) ?? 0) + 1;
81
+ if (depth > options.maxRootReentrantDepth) {
82
+ const message = `[fict] cycle protection triggered: root-reentry`;
83
+ if (options.devMode) {
84
+ throw new Error(message);
85
+ }
86
+ if (!rootWarned) {
87
+ rootWarned = true;
88
+ console.warn(message, { depth });
89
+ }
90
+ return false;
47
91
  }
48
- return false;
49
- }
50
- return true;
51
- }
52
- function endFlushGuard() {
53
- recordWindowUsage(effectRunsThisFlush, options.maxFlushCyclesPerMicrotask);
54
- effectRunsThisFlush = 0;
55
- }
56
- function enterRootGuard(root) {
57
- const depth = (rootDepth.get(root) ?? 0) + 1;
58
- if (depth > options.maxRootReentrantDepth) {
59
- const message = `[fict] cycle protection triggered: root-reentry`;
60
- if (options.devMode) {
61
- throw new Error(message);
92
+ rootDepth.set(root, depth);
93
+ return true;
94
+ };
95
+ exitRootGuard = (root) => {
96
+ const depth = rootDepth.get(root);
97
+ if (depth === void 0) return;
98
+ if (depth <= 1) {
99
+ rootDepth.delete(root);
100
+ } else {
101
+ rootDepth.set(root, depth - 1);
62
102
  }
63
- if (!rootWarned) {
64
- rootWarned = true;
65
- console.warn(message, { depth });
103
+ };
104
+ const recordWindowUsage = (used, budget) => {
105
+ if (!options.enableWindowWarning) return;
106
+ const entry = { used, budget };
107
+ windowUsage.push(entry);
108
+ if (windowUsage.length > options.windowSize) {
109
+ windowUsage.shift();
110
+ }
111
+ if (windowWarned) return;
112
+ if (windowUsage.length >= options.windowSize && windowUsage.every(
113
+ (item) => item.budget > 0 && item.used / item.budget >= options.highUsageRatio
114
+ )) {
115
+ windowWarned = true;
116
+ reportCycle("high-usage-window", {
117
+ windowSize: options.windowSize,
118
+ ratio: options.highUsageRatio
119
+ });
66
120
  }
67
- return false;
68
- }
69
- rootDepth.set(root, depth);
70
- return true;
71
- }
72
- function exitRootGuard(root) {
73
- const depth = rootDepth.get(root);
74
- if (depth === void 0) return;
75
- if (depth <= 1) {
76
- rootDepth.delete(root);
77
- } else {
78
- rootDepth.set(root, depth - 1);
79
- }
80
- }
81
- function recordWindowUsage(used, budget) {
82
- if (!options.enableWindowWarning) return;
83
- const entry = { used, budget };
84
- windowUsage.push(entry);
85
- if (windowUsage.length > options.windowSize) {
86
- windowUsage.shift();
87
- }
88
- if (windowWarned) return;
89
- if (windowUsage.length >= options.windowSize && windowUsage.every((item) => item.budget > 0 && item.used / item.budget >= options.highUsageRatio)) {
90
- windowWarned = true;
91
- reportCycle("high-usage-window", {
92
- windowSize: options.windowSize,
93
- ratio: options.highUsageRatio
94
- });
95
- }
96
- }
97
- function reportCycle(reason, detail = void 0) {
98
- const hook = getDevtoolsHook();
99
- hook?.cycleDetected?.(detail ? { reason, detail } : { reason });
100
- console.warn(`[fict] cycle protection triggered: ${reason}`, detail ?? "");
121
+ };
122
+ const reportCycle = (reason, detail = void 0) => {
123
+ const hook = getDevtoolsHook();
124
+ hook?.cycleDetected?.(detail ? { reason, detail } : { reason });
125
+ console.warn(`[fict] cycle protection triggered: ${reason}`, detail ?? "");
126
+ };
101
127
  }
102
128
 
103
129
  // src/lifecycle.ts
130
+ var isDev2 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
104
131
  var currentRoot;
105
132
  var currentEffectCleanups;
106
133
  var globalErrorHandlers = /* @__PURE__ */ new WeakMap();
@@ -239,7 +266,8 @@ function runLifecycle(fn) {
239
266
  }
240
267
  function registerErrorHandler(fn) {
241
268
  if (!currentRoot) {
242
- throw new Error("registerErrorHandler must be called within a root");
269
+ const message = isDev2 ? "registerErrorHandler must be called within a root" : "FICT:E_ROOT_HANDLER";
270
+ throw new Error(message);
243
271
  }
244
272
  if (!currentRoot.errorHandlers) {
245
273
  currentRoot.errorHandlers = [];
@@ -254,7 +282,8 @@ function registerErrorHandler(fn) {
254
282
  }
255
283
  function registerSuspenseHandler(fn) {
256
284
  if (!currentRoot) {
257
- throw new Error("registerSuspenseHandler must be called within a root");
285
+ const message = isDev2 ? "registerSuspenseHandler must be called within a root" : "FICT:E_ROOT_SUSPENSE";
286
+ throw new Error(message);
258
287
  }
259
288
  if (!currentRoot.suspenseHandlers) {
260
289
  currentRoot.suspenseHandlers = [];
@@ -328,6 +357,7 @@ function handleSuspend(token, startRoot) {
328
357
  }
329
358
 
330
359
  // src/signal.ts
360
+ var isDev3 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
331
361
  var Mutable = 1;
332
362
  var Watching = 2;
333
363
  var Running = 4;
@@ -543,16 +573,16 @@ function shallowPropagate(firstLink) {
543
573
  function update(node) {
544
574
  return "getter" in node && node.getter !== void 0 ? updateComputed(node) : updateSignal(node);
545
575
  }
546
- function notify(effect2) {
547
- effect2.flags &= ~Watching;
576
+ function notify(effect) {
577
+ effect.flags &= ~Watching;
548
578
  const effects = [];
549
579
  for (; ; ) {
550
- effects.push(effect2);
551
- const nextLink = effect2.subs;
580
+ effects.push(effect);
581
+ const nextLink = effect.subs;
552
582
  if (nextLink === void 0) break;
553
- effect2 = nextLink.sub;
554
- if (effect2 === void 0 || !(effect2.flags & Watching)) break;
555
- effect2.flags &= ~Watching;
583
+ effect = nextLink.sub;
584
+ if (effect === void 0 || !(effect.flags & Watching)) break;
585
+ effect.flags &= ~Watching;
556
586
  }
557
587
  const targetQueue = isInTransition ? lowPriorityQueue : highPriorityQueue;
558
588
  for (let i = effects.length - 1; i >= 0; i--) {
@@ -821,31 +851,6 @@ function computedOper() {
821
851
  if (activeSub !== void 0) link(this, activeSub, cycle);
822
852
  return this.value;
823
853
  }
824
- function effect(fn) {
825
- const e = {
826
- fn,
827
- subs: void 0,
828
- subsTail: void 0,
829
- deps: void 0,
830
- depsTail: void 0,
831
- flags: WatchingRunning,
832
- __id: void 0
833
- };
834
- registerEffectDevtools(e);
835
- const prevSub = activeSub;
836
- if (prevSub !== void 0) link(e, prevSub, 0);
837
- activeSub = e;
838
- try {
839
- effectRunDevtools(e);
840
- fn();
841
- } finally {
842
- activeSub = prevSub;
843
- e.flags &= ~Running;
844
- }
845
- const disposer = effectOper.bind(e);
846
- disposer[EFFECT_MARKER] = true;
847
- return disposer;
848
- }
849
854
  function effectWithCleanup(fn, cleanupRunner) {
850
855
  const e = {
851
856
  fn,
@@ -875,39 +880,30 @@ function effectWithCleanup(fn, cleanupRunner) {
875
880
  function effectOper() {
876
881
  disposeNode(this);
877
882
  }
878
- function effectScope(fn) {
879
- const e = { deps: void 0, depsTail: void 0, subs: void 0, subsTail: void 0, flags: 0 };
880
- const prevSub = activeSub;
881
- if (prevSub !== void 0) link(e, prevSub, 0);
882
- activeSub = e;
883
- try {
884
- fn();
885
- } finally {
886
- activeSub = prevSub;
887
- }
888
- const disposer = effectScopeOper.bind(e);
889
- disposer[EFFECT_SCOPE_MARKER] = true;
890
- return disposer;
891
- }
892
- function effectScopeOper() {
893
- disposeNode(this);
894
- }
895
883
  function batch(fn) {
896
884
  ++batchDepth;
897
- let _error;
898
- let hasError = false;
885
+ let result;
886
+ let error;
899
887
  try {
900
- return fn();
888
+ result = fn();
901
889
  } catch (e) {
902
- _error = e;
903
- hasError = true;
904
- throw e;
890
+ error = e;
905
891
  } finally {
906
892
  --batchDepth;
907
- if (!hasError && batchDepth === 0) {
908
- flush();
893
+ if (batchDepth === 0) {
894
+ try {
895
+ flush();
896
+ } catch (flushErr) {
897
+ if (error === void 0) {
898
+ error = flushErr;
899
+ }
900
+ }
909
901
  }
910
902
  }
903
+ if (error !== void 0) {
904
+ throw error;
905
+ }
906
+ return result;
911
907
  }
912
908
  function setActiveSub(sub) {
913
909
  const prev = activeSub;
@@ -928,194 +924,49 @@ function setTransitionContext(value) {
928
924
  isInTransition = value;
929
925
  return prev;
930
926
  }
931
- var $state = signal;
932
- var devtoolsSignalId = 0;
933
- var devtoolsEffectId = 0;
934
- function registerSignalDevtools(value, node) {
935
- const hook = getDevtoolsHook();
936
- if (!hook) return void 0;
937
- const id = ++devtoolsSignalId;
938
- hook.registerSignal(id, value);
939
- node.__id = id;
940
- return id;
941
- }
942
- function updateSignalDevtools(node, value) {
943
- const hook = getDevtoolsHook();
944
- if (!hook) return;
945
- const id = node.__id;
946
- if (id) hook.updateSignal(id, value);
947
- }
948
- function registerEffectDevtools(node) {
949
- const hook = getDevtoolsHook();
950
- if (!hook) return void 0;
951
- const id = ++devtoolsEffectId;
952
- hook.registerEffect(id);
953
- node.__id = id;
954
- return id;
955
- }
956
- function effectRunDevtools(node) {
957
- const hook = getDevtoolsHook();
958
- if (!hook) return;
959
- const id = node.__id;
960
- if (id) hook.effectRun(id);
961
- }
962
- function createSelector(source, equalityFn = (a, b) => a === b) {
963
- let current = source();
964
- const observers = /* @__PURE__ */ new Map();
965
- const dispose = effect(() => {
966
- const next = source();
967
- if (equalityFn(current, next)) return;
968
- const prevSig = observers.get(current);
969
- if (prevSig) prevSig(false);
970
- const nextSig = observers.get(next);
971
- if (nextSig) nextSig(true);
972
- current = next;
973
- });
974
- registerRootCleanup(() => {
975
- dispose();
976
- observers.clear();
977
- });
978
- return (key) => {
979
- let sig = observers.get(key);
980
- if (!sig) {
981
- sig = signal(equalityFn(key, current));
982
- observers.set(key, sig);
983
- registerRootCleanup(() => observers.delete(key));
984
- }
985
- return sig();
927
+ var registerSignalDevtools = () => void 0;
928
+ var updateSignalDevtools = () => {
929
+ };
930
+ var registerEffectDevtools = () => void 0;
931
+ var effectRunDevtools = () => {
932
+ };
933
+ if (isDev3) {
934
+ let devtoolsSignalId = 0;
935
+ let devtoolsEffectId = 0;
936
+ registerSignalDevtools = (value, node) => {
937
+ const hook = getDevtoolsHook();
938
+ if (!hook) return void 0;
939
+ const id = ++devtoolsSignalId;
940
+ hook.registerSignal(id, value);
941
+ node.__id = id;
942
+ return id;
986
943
  };
987
- }
988
-
989
- // src/store.ts
990
- var PROXY = Symbol("fict:store-proxy");
991
- var TARGET = Symbol("fict:store-target");
992
- var ITERATE_KEY = Symbol("fict:iterate");
993
- function createStore(initialValue) {
994
- const unwrapped = unwrap(initialValue);
995
- const wrapped = wrap(unwrapped);
996
- function setStore(fn) {
997
- batch(() => {
998
- const result = fn(wrapped);
999
- if (result !== void 0) {
1000
- reconcile(wrapped, result);
1001
- }
1002
- });
1003
- }
1004
- return [wrapped, setStore];
1005
- }
1006
- var proxyCache = /* @__PURE__ */ new WeakMap();
1007
- var signalCache = /* @__PURE__ */ new WeakMap();
1008
- function wrap(value) {
1009
- if (value === null || typeof value !== "object") return value;
1010
- if (value[PROXY]) return value;
1011
- if (proxyCache.has(value)) return proxyCache.get(value);
1012
- const handler = {
1013
- get(target, prop, receiver) {
1014
- if (prop === PROXY) return true;
1015
- if (prop === TARGET) return target;
1016
- const value2 = Reflect.get(target, prop, receiver);
1017
- track(target, prop);
1018
- return wrap(value2);
1019
- },
1020
- has(target, prop) {
1021
- const result = Reflect.has(target, prop);
1022
- track(target, prop);
1023
- return result;
1024
- },
1025
- ownKeys(target) {
1026
- track(target, ITERATE_KEY);
1027
- return Reflect.ownKeys(target);
1028
- },
1029
- getOwnPropertyDescriptor(target, prop) {
1030
- track(target, prop);
1031
- return Reflect.getOwnPropertyDescriptor(target, prop);
1032
- },
1033
- set(target, prop, value2, receiver) {
1034
- if (prop === PROXY || prop === TARGET) return false;
1035
- const hadKey = Object.prototype.hasOwnProperty.call(target, prop);
1036
- const oldValue = Reflect.get(target, prop, receiver);
1037
- if (oldValue === value2) return true;
1038
- const result = Reflect.set(target, prop, value2, receiver);
1039
- if (result) {
1040
- trigger(target, prop);
1041
- if (!hadKey) {
1042
- trigger(target, ITERATE_KEY);
1043
- }
1044
- }
1045
- return result;
1046
- },
1047
- deleteProperty(target, prop) {
1048
- const hadKey = Object.prototype.hasOwnProperty.call(target, prop);
1049
- const result = Reflect.deleteProperty(target, prop);
1050
- if (result) {
1051
- trigger(target, prop);
1052
- if (hadKey) {
1053
- trigger(target, ITERATE_KEY);
1054
- }
1055
- }
1056
- return result;
1057
- }
944
+ updateSignalDevtools = (node, value) => {
945
+ const hook = getDevtoolsHook();
946
+ if (!hook) return;
947
+ const id = node.__id;
948
+ if (id) hook.updateSignal(id, value);
949
+ };
950
+ registerEffectDevtools = (node) => {
951
+ const hook = getDevtoolsHook();
952
+ if (!hook) return void 0;
953
+ const id = ++devtoolsEffectId;
954
+ hook.registerEffect(id);
955
+ node.__id = id;
956
+ return id;
957
+ };
958
+ effectRunDevtools = (node) => {
959
+ const hook = getDevtoolsHook();
960
+ if (!hook) return;
961
+ const id = node.__id;
962
+ if (id) hook.effectRun(id);
1058
963
  };
1059
- const proxy = new Proxy(value, handler);
1060
- proxyCache.set(value, proxy);
1061
- return proxy;
1062
- }
1063
- function unwrap(value) {
1064
- if (value && typeof value === "object" && value[PROXY]) {
1065
- return value[TARGET];
1066
- }
1067
- return value;
1068
- }
1069
- function track(target, prop) {
1070
- let signals = signalCache.get(target);
1071
- if (!signals) {
1072
- signals = /* @__PURE__ */ new Map();
1073
- signalCache.set(target, signals);
1074
- }
1075
- let s = signals.get(prop);
1076
- if (!s) {
1077
- const initial = prop === ITERATE_KEY ? Reflect.ownKeys(target).length : getLastValue(target, prop);
1078
- s = signal(initial);
1079
- signals.set(prop, s);
1080
- }
1081
- s();
1082
- }
1083
- function trigger(target, prop) {
1084
- const signals = signalCache.get(target);
1085
- if (signals) {
1086
- const s = signals.get(prop);
1087
- if (s) {
1088
- if (prop === ITERATE_KEY) {
1089
- s(Reflect.ownKeys(target).length);
1090
- } else {
1091
- s(getLastValue(target, prop));
1092
- }
1093
- }
1094
- }
1095
- }
1096
- function getLastValue(target, prop) {
1097
- return target[prop];
1098
- }
1099
- function reconcile(target, value) {
1100
- if (target === value) return;
1101
- if (value === null || typeof value !== "object") return;
1102
- const realTarget = unwrap(target);
1103
- const realValue = unwrap(value);
1104
- const keys = /* @__PURE__ */ new Set([...Object.keys(realTarget), ...Object.keys(realValue)]);
1105
- for (const key of keys) {
1106
- if (realValue[key] === void 0 && realTarget[key] !== void 0) {
1107
- delete target[key];
1108
- } else if (realTarget[key] !== realValue[key]) {
1109
- target[key] = realValue[key];
1110
- }
1111
- }
1112
964
  }
1113
965
 
1114
966
  // src/memo.ts
1115
967
  function createMemo(fn) {
1116
968
  return computed(fn);
1117
969
  }
1118
- var $memo = createMemo;
1119
970
 
1120
971
  // src/effect.ts
1121
972
  function createEffect(fn) {
@@ -1150,7 +1001,6 @@ function createEffect(fn) {
1150
1001
  registerRootCleanup(teardown);
1151
1002
  return teardown;
1152
1003
  }
1153
- var $effect = createEffect;
1154
1004
  function createRenderEffect(fn) {
1155
1005
  let cleanup;
1156
1006
  const rootForError = getCurrentRoot();
@@ -1186,8 +1036,89 @@ function createRenderEffect(fn) {
1186
1036
  return teardown;
1187
1037
  }
1188
1038
 
1039
+ // src/ref.ts
1040
+ function createRef() {
1041
+ return { current: null };
1042
+ }
1043
+
1044
+ // src/transition.ts
1045
+ function startTransition(fn) {
1046
+ const prev = setTransitionContext(true);
1047
+ try {
1048
+ fn();
1049
+ } finally {
1050
+ setTransitionContext(prev);
1051
+ scheduleFlush();
1052
+ }
1053
+ }
1054
+ function useTransition() {
1055
+ const pending = signal(false);
1056
+ const start = (fn) => {
1057
+ startTransition(() => {
1058
+ pending(true);
1059
+ try {
1060
+ fn();
1061
+ } finally {
1062
+ pending(false);
1063
+ }
1064
+ });
1065
+ };
1066
+ return [() => pending(), start];
1067
+ }
1068
+ function useDeferredValue(getValue) {
1069
+ const deferredValue = signal(getValue());
1070
+ createEffect(() => {
1071
+ const newValue = getValue();
1072
+ const currentDeferred = untrack(() => deferredValue());
1073
+ if (currentDeferred !== newValue) {
1074
+ startTransition(() => {
1075
+ deferredValue(newValue);
1076
+ });
1077
+ }
1078
+ });
1079
+ return () => deferredValue();
1080
+ }
1081
+
1082
+ // src/scheduler.ts
1083
+ function batch2(fn) {
1084
+ return batch(fn);
1085
+ }
1086
+ function untrack2(fn) {
1087
+ return untrack(fn);
1088
+ }
1089
+
1090
+ // src/jsx.ts
1091
+ var Fragment = Symbol("Fragment");
1092
+
1093
+ // src/delegated-events.ts
1094
+ var DelegatedEventNames = [
1095
+ "beforeinput",
1096
+ "click",
1097
+ "dblclick",
1098
+ "contextmenu",
1099
+ "focusin",
1100
+ "focusout",
1101
+ "input",
1102
+ "keydown",
1103
+ "keyup",
1104
+ "mousedown",
1105
+ "mousemove",
1106
+ "mouseout",
1107
+ "mouseover",
1108
+ "mouseup",
1109
+ "pointerdown",
1110
+ "pointermove",
1111
+ "pointerout",
1112
+ "pointerover",
1113
+ "pointerup",
1114
+ "touchend",
1115
+ "touchmove",
1116
+ "touchstart"
1117
+ ];
1118
+
1189
1119
  // src/constants.ts
1190
- var booleans = [
1120
+ var isDev4 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
1121
+ var booleans = isDev4 ? [
1191
1122
  "allowfullscreen",
1192
1123
  "async",
1193
1124
  "alpha",
@@ -1235,9 +1166,9 @@ var booleans = [
1235
1166
  "shadowrootdelegatesfocus",
1236
1167
  "shadowrootserializable",
1237
1168
  "sharedstoragewritable"
1238
- ];
1169
+ ] : [];
1239
1170
  var BooleanAttributes = new Set(booleans);
1240
- var Properties = /* @__PURE__ */ new Set([
1171
+ var properties = isDev4 ? [
1241
1172
  // Core properties
1242
1173
  "className",
1243
1174
  "value",
@@ -1265,18 +1196,15 @@ var Properties = /* @__PURE__ */ new Set([
1265
1196
  "sharedStorageWritable",
1266
1197
  // All lowercase booleans
1267
1198
  ...booleans
1268
- ]);
1199
+ ] : [];
1200
+ var Properties = new Set(properties);
1269
1201
  var ChildProperties = /* @__PURE__ */ new Set([
1270
1202
  "innerHTML",
1271
1203
  "textContent",
1272
1204
  "innerText",
1273
1205
  "children"
1274
1206
  ]);
1275
- var Aliases = {
1276
- className: "class",
1277
- htmlFor: "for"
1278
- };
1279
- var PropAliases = {
1207
+ var PropAliases = isDev4 ? {
1280
1208
  // Direct mapping
1281
1209
  class: "className",
1282
1210
  // Element-specific mappings
@@ -1363,40 +1291,19 @@ var PropAliases = {
1363
1291
  IFRAME: 1,
1364
1292
  IMG: 1
1365
1293
  }
1366
- };
1367
- function getPropAlias(prop, tagName) {
1368
- const a = PropAliases[prop];
1294
+ } : {};
1295
+ function getPropAlias(prop2, tagName) {
1296
+ if (!isDev4) return void 0;
1297
+ const a = PropAliases[prop2];
1369
1298
  if (typeof a === "object") {
1370
1299
  return a[tagName] ? a["$"] : void 0;
1371
1300
  }
1372
1301
  return a;
1373
1302
  }
1374
1303
  var $$EVENTS = "_$FICT_DELEGATE";
1375
- var DelegatedEvents = /* @__PURE__ */ new Set([
1376
- "beforeinput",
1377
- "click",
1378
- "dblclick",
1379
- "contextmenu",
1380
- "focusin",
1381
- "focusout",
1382
- "input",
1383
- "keydown",
1384
- "keyup",
1385
- "mousedown",
1386
- "mousemove",
1387
- "mouseout",
1388
- "mouseover",
1389
- "mouseup",
1390
- "pointerdown",
1391
- "pointermove",
1392
- "pointerout",
1393
- "pointerover",
1394
- "pointerup",
1395
- "touchend",
1396
- "touchmove",
1397
- "touchstart"
1398
- ]);
1399
- var SVGElements = /* @__PURE__ */ new Set([
1304
+ var delegatedEvents = isDev4 ? DelegatedEventNames : [];
1305
+ var DelegatedEvents = new Set(delegatedEvents);
1306
+ var svgElements = isDev4 ? [
1400
1307
  "altGlyph",
1401
1308
  "altGlyphDef",
1402
1309
  "altGlyphItem",
@@ -1474,12 +1381,13 @@ var SVGElements = /* @__PURE__ */ new Set([
1474
1381
  "use",
1475
1382
  "view",
1476
1383
  "vkern"
1477
- ]);
1384
+ ] : [];
1385
+ var SVGElements = new Set(svgElements);
1478
1386
  var SVGNamespace = {
1479
1387
  xlink: "http://www.w3.org/1999/xlink",
1480
1388
  xml: "http://www.w3.org/XML/1998/namespace"
1481
1389
  };
1482
- var UnitlessStyles = /* @__PURE__ */ new Set([
1390
+ var unitlessList = isDev4 ? [
1483
1391
  "animationIterationCount",
1484
1392
  "animation-iteration-count",
1485
1393
  "borderImageOutset",
@@ -1555,680 +1463,8 @@ var UnitlessStyles = /* @__PURE__ */ new Set([
1555
1463
  "stroke-opacity",
1556
1464
  "strokeWidth",
1557
1465
  "stroke-width"
1558
- ]);
1559
-
1560
- // src/jsx.ts
1561
- var Fragment = Symbol("Fragment");
1562
-
1563
- // src/hooks.ts
1564
- var ctxStack = [];
1565
- function assertRenderContext(ctx, hookName) {
1566
- if (!ctx.rendering) {
1567
- throw new Error(`${hookName} can only be used during render execution`);
1568
- }
1569
- }
1570
- function __fictUseContext() {
1571
- if (ctxStack.length === 0) {
1572
- const ctx2 = { slots: [], cursor: 0, rendering: true };
1573
- ctxStack.push(ctx2);
1574
- return ctx2;
1575
- }
1576
- const ctx = ctxStack[ctxStack.length - 1];
1577
- ctx.cursor = 0;
1578
- ctx.rendering = true;
1579
- return ctx;
1580
- }
1581
- function __fictPushContext() {
1582
- const ctx = { slots: [], cursor: 0 };
1583
- ctxStack.push(ctx);
1584
- return ctx;
1585
- }
1586
- function __fictPopContext() {
1587
- ctxStack.pop();
1588
- }
1589
- function __fictResetContext() {
1590
- ctxStack.length = 0;
1591
- }
1592
- function __fictUseSignal(ctx, initial, slot) {
1593
- assertRenderContext(ctx, "__fictUseSignal");
1594
- const index = slot ?? ctx.cursor++;
1595
- if (!ctx.slots[index]) {
1596
- ctx.slots[index] = signal(initial);
1597
- }
1598
- return ctx.slots[index];
1599
- }
1600
- function __fictUseMemo(ctx, fn, slot) {
1601
- assertRenderContext(ctx, "__fictUseMemo");
1602
- const index = slot ?? ctx.cursor++;
1603
- if (!ctx.slots[index]) {
1604
- ctx.slots[index] = createMemo(fn);
1605
- }
1606
- return ctx.slots[index];
1607
- }
1608
- function __fictUseEffect(ctx, fn, slot) {
1609
- assertRenderContext(ctx, "__fictUseEffect");
1610
- const index = slot ?? ctx.cursor++;
1611
- if (!ctx.slots[index]) {
1612
- ctx.slots[index] = createEffect(fn);
1613
- }
1614
- }
1615
- function __fictRender(ctx, fn) {
1616
- ctxStack.push(ctx);
1617
- ctx.cursor = 0;
1618
- ctx.rendering = true;
1619
- try {
1620
- return fn();
1621
- } finally {
1622
- ctx.rendering = false;
1623
- ctxStack.pop();
1624
- }
1625
- }
1626
-
1627
- // src/props.ts
1628
- var propGetters = /* @__PURE__ */ new WeakSet();
1629
- var rawToProxy = /* @__PURE__ */ new WeakMap();
1630
- var proxyToRaw = /* @__PURE__ */ new WeakMap();
1631
- function __fictProp(getter) {
1632
- if (typeof getter === "function" && getter.length === 0) {
1633
- propGetters.add(getter);
1634
- }
1635
- return getter;
1636
- }
1637
- function isPropGetter(value) {
1638
- return typeof value === "function" && propGetters.has(value);
1639
- }
1640
- function createPropsProxy(props) {
1641
- if (!props || typeof props !== "object") {
1642
- return props;
1643
- }
1644
- if (proxyToRaw.has(props)) {
1645
- return props;
1646
- }
1647
- const cached = rawToProxy.get(props);
1648
- if (cached) {
1649
- return cached;
1650
- }
1651
- const proxy = new Proxy(props, {
1652
- get(target, prop, receiver) {
1653
- const value = Reflect.get(target, prop, receiver);
1654
- if (isPropGetter(value)) {
1655
- return value();
1656
- }
1657
- return value;
1658
- },
1659
- set(target, prop, value, receiver) {
1660
- return Reflect.set(target, prop, value, receiver);
1661
- },
1662
- has(target, prop) {
1663
- return prop in target;
1664
- },
1665
- ownKeys(target) {
1666
- return Reflect.ownKeys(target);
1667
- },
1668
- getOwnPropertyDescriptor(target, prop) {
1669
- return Object.getOwnPropertyDescriptor(target, prop);
1670
- }
1671
- });
1672
- rawToProxy.set(props, proxy);
1673
- proxyToRaw.set(proxy, props);
1674
- return proxy;
1675
- }
1676
- function unwrapProps(props) {
1677
- if (!props || typeof props !== "object") {
1678
- return props;
1679
- }
1680
- return proxyToRaw.get(props) ?? props;
1681
- }
1682
- function __fictPropsRest(props, exclude) {
1683
- const raw = unwrapProps(props);
1684
- const out = {};
1685
- const excludeSet = new Set(exclude);
1686
- for (const key of Reflect.ownKeys(raw)) {
1687
- if (excludeSet.has(key)) continue;
1688
- out[key] = raw[key];
1689
- }
1690
- return createPropsProxy(out);
1691
- }
1692
- function mergeProps(...sources) {
1693
- const validSources = sources.filter(
1694
- (s) => s != null && (typeof s === "object" || typeof s === "function")
1695
- );
1696
- if (validSources.length === 0) {
1697
- return {};
1698
- }
1699
- if (validSources.length === 1 && typeof validSources[0] === "object") {
1700
- return validSources[0];
1701
- }
1702
- const resolveSource = (src) => {
1703
- const value = typeof src === "function" ? src() : src;
1704
- if (!value || typeof value !== "object") return void 0;
1705
- return unwrapProps(value);
1706
- };
1707
- return new Proxy({}, {
1708
- get(_, prop) {
1709
- for (let i = validSources.length - 1; i >= 0; i--) {
1710
- const src = validSources[i];
1711
- const raw = resolveSource(src);
1712
- if (!raw || !(prop in raw)) continue;
1713
- const value = raw[prop];
1714
- if (typeof src === "function" && !isPropGetter(value)) {
1715
- return __fictProp(() => {
1716
- const latest = resolveSource(src);
1717
- if (!latest || !(prop in latest)) return void 0;
1718
- return latest[prop];
1719
- });
1720
- }
1721
- return value;
1722
- }
1723
- return void 0;
1724
- },
1725
- has(_, prop) {
1726
- for (const src of validSources) {
1727
- const raw = resolveSource(src);
1728
- if (raw && prop in raw) {
1729
- return true;
1730
- }
1731
- }
1732
- return false;
1733
- },
1734
- ownKeys() {
1735
- const keys = /* @__PURE__ */ new Set();
1736
- for (const src of validSources) {
1737
- const raw = resolveSource(src);
1738
- if (raw) {
1739
- for (const key of Reflect.ownKeys(raw)) {
1740
- keys.add(key);
1741
- }
1742
- }
1743
- }
1744
- return Array.from(keys);
1745
- },
1746
- getOwnPropertyDescriptor(_, prop) {
1747
- for (let i = validSources.length - 1; i >= 0; i--) {
1748
- const raw = resolveSource(validSources[i]);
1749
- if (raw && prop in raw) {
1750
- return {
1751
- enumerable: true,
1752
- configurable: true,
1753
- get: () => {
1754
- const value = raw[prop];
1755
- return value;
1756
- }
1757
- };
1758
- }
1759
- }
1760
- return void 0;
1761
- }
1762
- });
1763
- }
1764
- function useProp(getter) {
1765
- return __fictProp(createMemo(getter));
1766
- }
1767
-
1768
- // src/transition.ts
1769
- function startTransition(fn) {
1770
- const prev = setTransitionContext(true);
1771
- try {
1772
- fn();
1773
- } finally {
1774
- setTransitionContext(prev);
1775
- scheduleFlush();
1776
- }
1777
- }
1778
- function useTransition() {
1779
- const pending = signal(false);
1780
- const start = (fn) => {
1781
- startTransition(() => {
1782
- pending(true);
1783
- try {
1784
- fn();
1785
- } finally {
1786
- pending(false);
1787
- }
1788
- });
1789
- };
1790
- return [() => pending(), start];
1791
- }
1792
- function useDeferredValue(getValue) {
1793
- const deferredValue = signal(getValue());
1794
- createEffect(() => {
1795
- const newValue = getValue();
1796
- const currentDeferred = untrack(() => deferredValue());
1797
- if (currentDeferred !== newValue) {
1798
- startTransition(() => {
1799
- deferredValue(newValue);
1800
- });
1801
- }
1802
- });
1803
- return () => deferredValue();
1804
- }
1805
-
1806
- // src/scheduler.ts
1807
- function batch2(fn) {
1808
- return batch(fn);
1809
- }
1810
- function untrack2(fn) {
1811
- return untrack(fn);
1812
- }
1813
-
1814
- // src/dom.ts
1815
- var SVG_NS = "http://www.w3.org/2000/svg";
1816
- var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
1817
- var isDev = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
1818
- function render(view, container) {
1819
- const root = createRootContext();
1820
- const prev = pushRoot(root);
1821
- let dom;
1822
- try {
1823
- const output = view();
1824
- dom = createElement(output);
1825
- } finally {
1826
- popRoot(prev);
1827
- }
1828
- container.replaceChildren(dom);
1829
- container.setAttribute("data-fict-fine-grained", "1");
1830
- flushOnMount(root);
1831
- const teardown = () => {
1832
- destroyRoot(root);
1833
- container.innerHTML = "";
1834
- };
1835
- return teardown;
1836
- }
1837
- function createElement(node) {
1838
- return createElementWithContext(node, null);
1839
- }
1840
- function resolveNamespace(tagName, namespace) {
1841
- if (tagName === "svg") return "svg";
1842
- if (tagName === "math") return "mathml";
1843
- if (namespace === "mathml") return "mathml";
1844
- if (namespace === "svg") return "svg";
1845
- if (SVGElements.has(tagName)) return "svg";
1846
- return null;
1847
- }
1848
- function createElementWithContext(node, namespace) {
1849
- if (node instanceof Node) {
1850
- return node;
1851
- }
1852
- if (node === null || node === void 0 || node === false) {
1853
- return document.createTextNode("");
1854
- }
1855
- if (typeof node === "object" && node !== null && !(node instanceof Node)) {
1856
- if ("marker" in node) {
1857
- const handle = node;
1858
- if (typeof handle.dispose === "function") {
1859
- registerRootCleanup(handle.dispose);
1860
- }
1861
- if (typeof handle.flush === "function") {
1862
- const runFlush = () => handle.flush && handle.flush();
1863
- if (typeof queueMicrotask === "function") {
1864
- queueMicrotask(runFlush);
1865
- } else {
1866
- Promise.resolve().then(runFlush).catch(() => void 0);
1867
- }
1868
- }
1869
- return createElement(handle.marker);
1870
- }
1871
- const nodeRecord = node;
1872
- if (nodeRecord[PRIMITIVE_PROXY]) {
1873
- const primitiveGetter = nodeRecord[Symbol.toPrimitive];
1874
- const value = typeof primitiveGetter === "function" ? primitiveGetter.call(node, "default") : node;
1875
- return document.createTextNode(value == null || value === false ? "" : String(value));
1876
- }
1877
- }
1878
- if (Array.isArray(node)) {
1879
- const frag = document.createDocumentFragment();
1880
- for (const child of node) {
1881
- appendChildNode(frag, child, namespace);
1882
- }
1883
- return frag;
1884
- }
1885
- if (typeof node === "string" || typeof node === "number") {
1886
- return document.createTextNode(String(node));
1887
- }
1888
- if (typeof node === "boolean") {
1889
- return document.createTextNode("");
1890
- }
1891
- const vnode = node;
1892
- if (typeof vnode.type === "function") {
1893
- const rawProps = unwrapProps(vnode.props ?? {});
1894
- const baseProps = vnode.key === void 0 ? rawProps : new Proxy(rawProps, {
1895
- get(target, prop, receiver) {
1896
- if (prop === "key") return vnode.key;
1897
- return Reflect.get(target, prop, receiver);
1898
- },
1899
- has(target, prop) {
1900
- if (prop === "key") return true;
1901
- return prop in target;
1902
- },
1903
- ownKeys(target) {
1904
- const keys = new Set(Reflect.ownKeys(target));
1905
- keys.add("key");
1906
- return Array.from(keys);
1907
- },
1908
- getOwnPropertyDescriptor(target, prop) {
1909
- if (prop === "key") {
1910
- return { enumerable: true, configurable: true, value: vnode.key };
1911
- }
1912
- return Object.getOwnPropertyDescriptor(target, prop);
1913
- }
1914
- });
1915
- const props = createPropsProxy(baseProps);
1916
- __fictPushContext();
1917
- try {
1918
- const rendered = vnode.type(props);
1919
- return createElementWithContext(rendered, namespace);
1920
- } catch (err) {
1921
- if (handleSuspend(err)) {
1922
- return document.createComment("fict:suspend");
1923
- }
1924
- handleError(err, { source: "render", componentName: vnode.type.name });
1925
- throw err;
1926
- } finally {
1927
- __fictPopContext();
1928
- }
1929
- }
1930
- if (vnode.type === Fragment) {
1931
- const frag = document.createDocumentFragment();
1932
- const children = vnode.props?.children;
1933
- appendChildren(frag, children, namespace);
1934
- return frag;
1935
- }
1936
- const tagName = typeof vnode.type === "string" ? vnode.type : "div";
1937
- const resolvedNamespace = resolveNamespace(tagName, namespace);
1938
- const el = resolvedNamespace === "svg" ? document.createElementNS(SVG_NS, tagName) : resolvedNamespace === "mathml" ? document.createElementNS(MATHML_NS, tagName) : document.createElement(tagName);
1939
- applyProps(el, vnode.props ?? {}, resolvedNamespace === "svg");
1940
- appendChildren(
1941
- el,
1942
- vnode.props?.children,
1943
- tagName === "foreignObject" ? null : resolvedNamespace
1944
- );
1945
- return el;
1946
- }
1947
- function template(html, isImportNode, isSVG, isMathML) {
1948
- let node = null;
1949
- const create = () => {
1950
- const t = isMathML ? document.createElementNS(MATHML_NS, "template") : document.createElement("template");
1951
- t.innerHTML = html;
1952
- if (isSVG) {
1953
- return t.content.firstChild.firstChild;
1954
- }
1955
- if (isMathML) {
1956
- return t.firstChild;
1957
- }
1958
- return t.content.firstChild;
1959
- };
1960
- const fn = isImportNode ? () => untrack2(() => document.importNode(node || (node = create()), true)) : () => (node || (node = create())).cloneNode(true);
1961
- fn.cloneNode = fn;
1962
- return fn;
1963
- }
1964
- function isBindingHandle(node) {
1965
- return node !== null && typeof node === "object" && "marker" in node && "dispose" in node && typeof node.dispose === "function";
1966
- }
1967
- function appendChildNode(parent, child, namespace) {
1968
- if (child === null || child === void 0 || child === false) {
1969
- return;
1970
- }
1971
- if (isBindingHandle(child)) {
1972
- appendChildNode(parent, child.marker, namespace);
1973
- child.flush?.();
1974
- return;
1975
- }
1976
- if (typeof child === "function" && child.length === 0) {
1977
- const childGetter = child;
1978
- createChildBinding(parent, childGetter, (node) => createElementWithContext(node, namespace));
1979
- return;
1980
- }
1981
- if (Array.isArray(child)) {
1982
- for (const item of child) {
1983
- appendChildNode(parent, item, namespace);
1984
- }
1985
- return;
1986
- }
1987
- let domNode;
1988
- if (typeof child !== "object" || child === null) {
1989
- domNode = document.createTextNode(String(child ?? ""));
1990
- } else {
1991
- domNode = createElementWithContext(child, namespace);
1992
- }
1993
- if (domNode.nodeType === 11) {
1994
- const children = Array.from(domNode.childNodes);
1995
- for (const node of children) {
1996
- appendChildNode(parent, node, namespace);
1997
- }
1998
- return;
1999
- }
2000
- if (domNode.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2001
- parent.ownerDocument.adoptNode(domNode);
2002
- }
2003
- try {
2004
- parent.appendChild(domNode);
2005
- } catch (e) {
2006
- if (parent.ownerDocument) {
2007
- const clone = parent.ownerDocument.importNode(domNode, true);
2008
- parent.appendChild(clone);
2009
- return;
2010
- }
2011
- throw e;
2012
- }
2013
- }
2014
- function appendChildren(parent, children, namespace) {
2015
- if (children === void 0) return;
2016
- if (Array.isArray(children)) {
2017
- for (const child of children) {
2018
- appendChildren(parent, child, namespace);
2019
- }
2020
- return;
2021
- }
2022
- appendChildNode(parent, children, namespace);
2023
- }
2024
- function applyRef(el, value) {
2025
- if (typeof value === "function") {
2026
- const refFn = value;
2027
- refFn(el);
2028
- const root = getCurrentRoot();
2029
- if (root) {
2030
- registerRootCleanup(() => {
2031
- refFn(null);
2032
- });
2033
- } else if (isDev) {
2034
- console.warn(
2035
- "[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."
2036
- );
2037
- }
2038
- } else if (value && typeof value === "object" && "current" in value) {
2039
- const refObj = value;
2040
- refObj.current = el;
2041
- const root = getCurrentRoot();
2042
- if (root) {
2043
- registerRootCleanup(() => {
2044
- refObj.current = null;
2045
- });
2046
- } else if (isDev) {
2047
- console.warn(
2048
- "[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."
2049
- );
2050
- }
2051
- }
2052
- }
2053
- function applyProps(el, props, isSVG = false) {
2054
- props = unwrapProps(props);
2055
- const tagName = el.tagName;
2056
- const isCE = tagName.includes("-") || "is" in props;
2057
- for (const [key, value] of Object.entries(props)) {
2058
- if (key === "children") continue;
2059
- if (key === "ref") {
2060
- applyRef(el, value);
2061
- continue;
2062
- }
2063
- if (isEventKey(key)) {
2064
- bindEvent(
2065
- el,
2066
- eventNameFromProp(key),
2067
- value
2068
- );
2069
- continue;
2070
- }
2071
- if (key.slice(0, 3) === "on:") {
2072
- bindEvent(
2073
- el,
2074
- key.slice(3),
2075
- value,
2076
- false
2077
- // Non-delegated
2078
- );
2079
- continue;
2080
- }
2081
- if (key.slice(0, 10) === "oncapture:") {
2082
- bindEvent(
2083
- el,
2084
- key.slice(10),
2085
- value,
2086
- true
2087
- // Capture
2088
- );
2089
- continue;
2090
- }
2091
- if (key === "class" || key === "className") {
2092
- createClassBinding(el, value);
2093
- continue;
2094
- }
2095
- if (key === "classList") {
2096
- createClassBinding(el, value);
2097
- continue;
2098
- }
2099
- if (key === "style") {
2100
- createStyleBinding(
2101
- el,
2102
- value
2103
- );
2104
- continue;
2105
- }
2106
- if (key === "dangerouslySetInnerHTML" && value && typeof value === "object") {
2107
- const htmlValue = value.__html;
2108
- if (htmlValue !== void 0) {
2109
- if (isReactive(htmlValue)) {
2110
- createAttributeBinding(el, "innerHTML", htmlValue, setInnerHTML);
2111
- } else {
2112
- el.innerHTML = htmlValue;
2113
- }
2114
- }
2115
- continue;
2116
- }
2117
- if (ChildProperties.has(key)) {
2118
- createAttributeBinding(el, key, value, setProperty);
2119
- continue;
2120
- }
2121
- if (key.slice(0, 5) === "attr:") {
2122
- createAttributeBinding(el, key.slice(5), value, setAttribute);
2123
- continue;
2124
- }
2125
- if (key.slice(0, 5) === "bool:") {
2126
- createAttributeBinding(el, key.slice(5), value, setBoolAttribute);
2127
- continue;
2128
- }
2129
- if (key.slice(0, 5) === "prop:") {
2130
- createAttributeBinding(el, key.slice(5), value, setProperty);
2131
- continue;
2132
- }
2133
- const propAlias = !isSVG ? getPropAlias(key, tagName) : void 0;
2134
- if (propAlias || !isSVG && Properties.has(key) || isCE && !isSVG) {
2135
- const propName = propAlias || key;
2136
- if (isCE && !Properties.has(key)) {
2137
- createAttributeBinding(
2138
- el,
2139
- toPropertyName(propName),
2140
- value,
2141
- setProperty
2142
- );
2143
- } else {
2144
- createAttributeBinding(el, propName, value, setProperty);
2145
- }
2146
- continue;
2147
- }
2148
- if (isSVG && key.indexOf(":") > -1) {
2149
- const [prefix, name] = key.split(":");
2150
- const ns = SVGNamespace[prefix];
2151
- if (ns) {
2152
- createAttributeBinding(
2153
- el,
2154
- key,
2155
- value,
2156
- (el2, _key, val) => setAttributeNS(el2, ns, name, val)
2157
- );
2158
- continue;
2159
- }
2160
- }
2161
- const attrName = Aliases[key] || key;
2162
- createAttributeBinding(el, attrName, value, setAttribute);
2163
- }
2164
- }
2165
- function toPropertyName(name) {
2166
- return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
2167
- }
2168
- var setAttribute = (el, key, value) => {
2169
- if (value === void 0 || value === null || value === false) {
2170
- el.removeAttribute(key);
2171
- return;
2172
- }
2173
- if (value === true) {
2174
- el.setAttribute(key, "");
2175
- return;
2176
- }
2177
- const valueType = typeof value;
2178
- if (valueType === "string" || valueType === "number") {
2179
- el.setAttribute(key, String(value));
2180
- return;
2181
- }
2182
- if (key in el) {
2183
- ;
2184
- el[key] = value;
2185
- return;
2186
- }
2187
- el.setAttribute(key, String(value));
2188
- };
2189
- var setProperty = (el, key, value) => {
2190
- if (value === void 0 || value === null) {
2191
- const fallback = key === "checked" || key === "selected" ? false : "";
2192
- el[key] = fallback;
2193
- return;
2194
- }
2195
- if (key === "style" && typeof value === "object" && value !== null) {
2196
- for (const k in value) {
2197
- const v = value[k];
2198
- if (v !== void 0) {
2199
- ;
2200
- el.style[k] = String(v);
2201
- }
2202
- }
2203
- return;
2204
- }
2205
- ;
2206
- el[key] = value;
2207
- };
2208
- var setInnerHTML = (el, _key, value) => {
2209
- ;
2210
- el.innerHTML = value == null ? "" : String(value);
2211
- };
2212
- var setBoolAttribute = (el, key, value) => {
2213
- if (value) {
2214
- el.setAttribute(key, "");
2215
- } else {
2216
- el.removeAttribute(key);
2217
- }
2218
- };
2219
- function setAttributeNS(el, namespace, name, value) {
2220
- if (value == null) {
2221
- el.removeAttributeNS(namespace, name);
2222
- } else {
2223
- el.setAttributeNS(namespace, name, String(value));
2224
- }
2225
- }
2226
- function isEventKey(key) {
2227
- return key.startsWith("on") && key.length > 2 && key[2].toUpperCase() === key[2];
2228
- }
2229
- function eventNameFromProp(key) {
2230
- return key.slice(2).toLowerCase();
2231
- }
1466
+ ] : ["opacity", "zIndex"];
1467
+ var UnitlessStyles = new Set(unitlessList);
2232
1468
 
2233
1469
  // src/node-ops.ts
2234
1470
  function toNodeArray(node) {
@@ -2301,757 +1537,83 @@ function insertNodesBefore(parent, nodes, anchor) {
2301
1537
  parent.insertBefore(node, anchor);
2302
1538
  } catch (e) {
2303
1539
  if (parent.ownerDocument) {
2304
- try {
2305
- const clone = parent.ownerDocument.importNode(node, true);
2306
- parent.insertBefore(clone, anchor);
2307
- return;
2308
- } catch {
2309
- }
2310
- }
2311
- throw e;
2312
- }
2313
- return;
2314
- }
2315
- const doc = parent.ownerDocument;
2316
- if (doc) {
2317
- const frag = doc.createDocumentFragment();
2318
- for (let i = 0; i < nodes.length; i++) {
2319
- const node = nodes[i];
2320
- if (node === void 0 || node === null) continue;
2321
- if (node.nodeType === 11) {
2322
- const childrenArr = Array.from(node.childNodes);
2323
- for (let j = 0; j < childrenArr.length; j++) {
2324
- frag.appendChild(childrenArr[j]);
2325
- }
2326
- } else {
2327
- if (node.ownerDocument !== doc) {
2328
- doc.adoptNode(node);
2329
- }
2330
- frag.appendChild(node);
2331
- }
2332
- }
2333
- parent.insertBefore(frag, anchor);
2334
- return;
2335
- }
2336
- const insertSingle = (nodeToInsert, anchorNode) => {
2337
- if (nodeToInsert.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2338
- parent.ownerDocument.adoptNode(nodeToInsert);
2339
- }
2340
- try {
2341
- parent.insertBefore(nodeToInsert, anchorNode);
2342
- return nodeToInsert;
2343
- } catch (e) {
2344
- if (parent.ownerDocument) {
2345
- try {
2346
- const clone = parent.ownerDocument.importNode(nodeToInsert, true);
2347
- parent.insertBefore(clone, anchorNode);
2348
- return clone;
2349
- } catch {
2350
- }
2351
- }
2352
- throw e;
2353
- }
2354
- };
2355
- for (let i = nodes.length - 1; i >= 0; i--) {
2356
- const node = nodes[i];
2357
- if (node === void 0 || node === null) continue;
2358
- const isFrag = node.nodeType === 11;
2359
- if (isFrag) {
2360
- const childrenArr = Array.from(node.childNodes);
2361
- for (let j = childrenArr.length - 1; j >= 0; j--) {
2362
- const child = childrenArr[j];
2363
- anchor = insertSingle(child, anchor);
2364
- }
2365
- } else {
2366
- anchor = insertSingle(node, anchor);
2367
- }
2368
- }
2369
- }
2370
- function removeNodes(nodes) {
2371
- for (const node of nodes) {
2372
- node.parentNode?.removeChild(node);
2373
- }
2374
- }
2375
-
2376
- // src/reconcile.ts
2377
- function reconcileArrays(parentNode, a, b) {
2378
- const bLength = b.length;
2379
- let aEnd = a.length;
2380
- let bEnd = bLength;
2381
- let aStart = 0;
2382
- let bStart = 0;
2383
- const after = aEnd > 0 ? a[aEnd - 1].nextSibling : null;
2384
- let map = null;
2385
- while (aStart < aEnd || bStart < bEnd) {
2386
- if (a[aStart] === b[bStart]) {
2387
- aStart++;
2388
- bStart++;
2389
- continue;
2390
- }
2391
- while (a[aEnd - 1] === b[bEnd - 1]) {
2392
- aEnd--;
2393
- bEnd--;
2394
- }
2395
- if (aEnd === aStart) {
2396
- const node = bEnd < bLength ? bStart ? b[bStart - 1].nextSibling : b[bEnd - bStart] ?? null : after;
2397
- const count = bEnd - bStart;
2398
- const doc = parentNode.ownerDocument;
2399
- if (count > 1 && doc) {
2400
- const frag = doc.createDocumentFragment();
2401
- for (let i = bStart; i < bEnd; i++) {
2402
- frag.appendChild(b[i]);
2403
- }
2404
- parentNode.insertBefore(frag, node);
2405
- bStart = bEnd;
2406
- } else {
2407
- while (bStart < bEnd) {
2408
- parentNode.insertBefore(b[bStart++], node);
2409
- }
2410
- }
2411
- } else if (bEnd === bStart) {
2412
- while (aStart < aEnd) {
2413
- const nodeToRemove = a[aStart];
2414
- if (!map || !map.has(nodeToRemove)) {
2415
- nodeToRemove.parentNode?.removeChild(nodeToRemove);
2416
- }
2417
- aStart++;
2418
- }
2419
- } else if (a[aStart] === b[bEnd - 1] && b[bStart] === a[aEnd - 1]) {
2420
- const node = a[--aEnd].nextSibling;
2421
- parentNode.insertBefore(b[bStart++], a[aStart++].nextSibling);
2422
- parentNode.insertBefore(b[--bEnd], node);
2423
- a[aEnd] = b[bEnd];
2424
- } else {
2425
- if (!map) {
2426
- map = /* @__PURE__ */ new Map();
2427
- let i = bStart;
2428
- while (i < bEnd) {
2429
- map.set(b[i], i++);
2430
- }
2431
- }
2432
- const index = map.get(a[aStart]);
2433
- if (index != null) {
2434
- if (bStart < index && index < bEnd) {
2435
- let i = aStart;
2436
- let sequence = 1;
2437
- let t;
2438
- while (++i < aEnd && i < bEnd) {
2439
- t = map.get(a[i]);
2440
- if (t == null || t !== index + sequence) break;
2441
- sequence++;
2442
- }
2443
- if (sequence > index - bStart) {
2444
- const node = a[aStart];
2445
- while (bStart < index) {
2446
- parentNode.insertBefore(b[bStart++], node);
2447
- }
2448
- } else {
2449
- parentNode.replaceChild(b[bStart++], a[aStart++]);
2450
- }
2451
- } else {
2452
- aStart++;
2453
- }
2454
- } else {
2455
- const nodeToRemove = a[aStart++];
2456
- nodeToRemove.parentNode?.removeChild(nodeToRemove);
2457
- }
2458
- }
2459
- }
2460
- }
2461
-
2462
- // src/list-helpers.ts
2463
- var isDev2 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
2464
- function moveNodesBefore(parent, nodes, anchor) {
2465
- for (let i = nodes.length - 1; i >= 0; i--) {
2466
- const node = nodes[i];
2467
- if (!node || !(node instanceof Node)) {
2468
- throw new Error("Invalid node in moveNodesBefore");
2469
- }
2470
- if (node.nextSibling !== anchor) {
2471
- if (node.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2472
- parent.ownerDocument.adoptNode(node);
2473
- }
2474
- try {
2475
- parent.insertBefore(node, anchor);
2476
- } catch (e) {
2477
- if (parent.ownerDocument) {
2478
- try {
2479
- const clone = parent.ownerDocument.importNode(node, true);
2480
- parent.insertBefore(clone, anchor);
2481
- continue;
2482
- } catch {
2483
- }
2484
- }
2485
- throw e;
2486
- }
2487
- }
2488
- anchor = node;
2489
- }
2490
- }
2491
- function moveMarkerBlock(parent, block, anchor) {
2492
- const nodes = collectBlockNodes(block);
2493
- if (nodes.length === 0) return;
2494
- moveNodesBefore(parent, nodes, anchor);
2495
- }
2496
- function destroyMarkerBlock(block) {
2497
- if (block.root) {
2498
- destroyRoot(block.root);
2499
- }
2500
- removeBlockRange(block);
2501
- }
2502
- function collectBlockNodes(block) {
2503
- const nodes = [];
2504
- let cursor = block.start;
2505
- while (cursor) {
2506
- nodes.push(cursor);
2507
- if (cursor === block.end) {
2508
- break;
2509
- }
2510
- cursor = cursor.nextSibling;
2511
- }
2512
- return nodes;
2513
- }
2514
- function removeBlockRange(block) {
2515
- let cursor = block.start;
2516
- while (cursor) {
2517
- const next = cursor.nextSibling;
2518
- cursor.parentNode?.removeChild(cursor);
2519
- if (cursor === block.end) {
2520
- break;
2521
- }
2522
- cursor = next;
2523
- }
2524
- }
2525
- var MAX_SAFE_VERSION = 9007199254740991;
2526
- function createVersionedSignalAccessor(initialValue) {
2527
- let current = initialValue;
2528
- let version = 0;
2529
- const track2 = signal(version);
2530
- function accessor(value) {
2531
- if (arguments.length === 0) {
2532
- track2();
2533
- return current;
2534
- }
2535
- current = value;
2536
- version = version >= MAX_SAFE_VERSION ? 1 : version + 1;
2537
- track2(version);
2538
- }
2539
- return accessor;
2540
- }
2541
- function createKeyedListContainer() {
2542
- const startMarker = document.createComment("fict:list:start");
2543
- const endMarker = document.createComment("fict:list:end");
2544
- const dispose = () => {
2545
- for (const block of container.blocks.values()) {
2546
- destroyRoot(block.root);
2547
- }
2548
- container.blocks.clear();
2549
- container.nextBlocks.clear();
2550
- if (!startMarker.parentNode || !endMarker.parentNode) {
2551
- container.currentNodes = [];
2552
- container.nextNodes = [];
2553
- container.orderedBlocks.length = 0;
2554
- container.nextOrderedBlocks.length = 0;
2555
- container.orderedIndexByKey.clear();
2556
- return;
2557
- }
2558
- const range = document.createRange();
2559
- range.setStartBefore(startMarker);
2560
- range.setEndAfter(endMarker);
2561
- range.deleteContents();
2562
- container.currentNodes = [];
2563
- container.nextNodes = [];
2564
- container.nextBlocks.clear();
2565
- container.orderedBlocks.length = 0;
2566
- container.nextOrderedBlocks.length = 0;
2567
- container.orderedIndexByKey.clear();
2568
- };
2569
- const container = {
2570
- startMarker,
2571
- endMarker,
2572
- blocks: /* @__PURE__ */ new Map(),
2573
- nextBlocks: /* @__PURE__ */ new Map(),
2574
- currentNodes: [startMarker, endMarker],
2575
- nextNodes: [],
2576
- orderedBlocks: [],
2577
- nextOrderedBlocks: [],
2578
- orderedIndexByKey: /* @__PURE__ */ new Map(),
2579
- dispose
2580
- };
2581
- return container;
2582
- }
2583
- function createKeyedBlock(key, item, index, render2, needsIndex = true, hostRoot) {
2584
- const itemSig = createVersionedSignalAccessor(item);
2585
- const indexSig = needsIndex ? signal(index) : ((next) => {
2586
- if (arguments.length === 0) return index;
2587
- index = next;
2588
- return index;
2589
- });
2590
- const root = createRootContext(hostRoot);
2591
- const prevRoot = pushRoot(root);
2592
- let nodes = [];
2593
- let scopeDispose;
2594
- const prevSub = setActiveSub(void 0);
2595
- try {
2596
- scopeDispose = effectScope(() => {
2597
- const rendered = render2(itemSig, indexSig, key);
2598
- if (rendered instanceof Node || Array.isArray(rendered) && rendered.every((n) => n instanceof Node)) {
2599
- nodes = toNodeArray(rendered);
2600
- } else {
2601
- const element = createElement(rendered);
2602
- nodes = toNodeArray(element);
2603
- }
2604
- });
2605
- if (scopeDispose) {
2606
- root.cleanups.push(scopeDispose);
2607
- }
2608
- } finally {
2609
- setActiveSub(prevSub);
2610
- popRoot(prevRoot);
2611
- }
2612
- return {
2613
- key,
2614
- nodes,
2615
- root,
2616
- item: itemSig,
2617
- index: indexSig,
2618
- rawItem: item,
2619
- rawIndex: index
2620
- };
2621
- }
2622
- function getFirstNodeAfter(marker) {
2623
- return marker.nextSibling;
2624
- }
2625
- function isNodeBetweenMarkers(node, startMarker, endMarker) {
2626
- let current = startMarker.nextSibling;
2627
- while (current && current !== endMarker) {
2628
- if (current === node) return true;
2629
- current = current.nextSibling;
2630
- }
2631
- return false;
2632
- }
2633
- function reorderBySwap(parent, first, second) {
2634
- if (first === second) return false;
2635
- const firstNodes = first.nodes;
2636
- const secondNodes = second.nodes;
2637
- if (firstNodes.length === 0 || secondNodes.length === 0) return false;
2638
- const lastFirst = firstNodes[firstNodes.length - 1];
2639
- const lastSecond = secondNodes[secondNodes.length - 1];
2640
- const afterFirst = lastFirst.nextSibling;
2641
- const afterSecond = lastSecond.nextSibling;
2642
- moveNodesBefore(parent, firstNodes, afterSecond);
2643
- moveNodesBefore(parent, secondNodes, afterFirst);
2644
- return true;
2645
- }
2646
- function getLISIndices(sequence) {
2647
- const predecessors = new Array(sequence.length);
2648
- const result = [];
2649
- for (let i = 0; i < sequence.length; i++) {
2650
- const value = sequence[i];
2651
- if (value < 0) {
2652
- predecessors[i] = -1;
2653
- continue;
2654
- }
2655
- let low = 0;
2656
- let high = result.length;
2657
- while (low < high) {
2658
- const mid = low + high >> 1;
2659
- if (sequence[result[mid]] < value) {
2660
- low = mid + 1;
2661
- } else {
2662
- high = mid;
2663
- }
2664
- }
2665
- predecessors[i] = low > 0 ? result[low - 1] : -1;
2666
- if (low === result.length) {
2667
- result.push(i);
2668
- } else {
2669
- result[low] = i;
2670
- }
2671
- }
2672
- const lis = new Array(result.length);
2673
- let k = result.length > 0 ? result[result.length - 1] : -1;
2674
- for (let i = result.length - 1; i >= 0; i--) {
2675
- lis[i] = k;
2676
- k = predecessors[k];
2677
- }
2678
- return lis;
2679
- }
2680
- function reorderByLIS(parent, endMarker, prev, next) {
2681
- const positions = /* @__PURE__ */ new Map();
2682
- for (let i = 0; i < prev.length; i++) {
2683
- positions.set(prev[i], i);
2684
- }
2685
- const sequence = new Array(next.length);
2686
- for (let i = 0; i < next.length; i++) {
2687
- const position = positions.get(next[i]);
2688
- if (position === void 0) return false;
2689
- sequence[i] = position;
2690
- }
2691
- const lisIndices = getLISIndices(sequence);
2692
- if (lisIndices.length === sequence.length) return true;
2693
- const inLIS = new Array(sequence.length).fill(false);
2694
- for (let i = 0; i < lisIndices.length; i++) {
2695
- inLIS[lisIndices[i]] = true;
2696
- }
2697
- let anchor = endMarker;
2698
- let moved = false;
2699
- for (let i = next.length - 1; i >= 0; i--) {
2700
- const block = next[i];
2701
- const nodes = block.nodes;
2702
- if (nodes.length === 0) continue;
2703
- if (inLIS[i]) {
2704
- anchor = nodes[0];
2705
- continue;
2706
- }
2707
- moveNodesBefore(parent, nodes, anchor);
2708
- anchor = nodes[0];
2709
- moved = true;
2710
- }
2711
- return moved;
2712
- }
2713
- function createKeyedList(getItems, keyFn, renderItem, needsIndex) {
2714
- const resolvedNeedsIndex = arguments.length >= 4 ? !!needsIndex : renderItem.length > 1;
2715
- return createFineGrainedKeyedList(getItems, keyFn, renderItem, resolvedNeedsIndex);
2716
- }
2717
- function createFineGrainedKeyedList(getItems, keyFn, renderItem, needsIndex) {
2718
- const container = createKeyedListContainer();
2719
- const hostRoot = getCurrentRoot();
2720
- const fragment = document.createDocumentFragment();
2721
- fragment.append(container.startMarker, container.endMarker);
2722
- let disposed = false;
2723
- let effectDispose;
2724
- let connectObserver = null;
2725
- let effectStarted = false;
2726
- let startScheduled = false;
2727
- const getConnectedParent = () => {
2728
- const endParent = container.endMarker.parentNode;
2729
- const startParent = container.startMarker.parentNode;
2730
- if (endParent && startParent && endParent === startParent && endParent.nodeType !== 11) {
2731
- return endParent;
2732
- }
2733
- return null;
2734
- };
2735
- const performDiff = () => {
2736
- if (disposed) return;
2737
- const parent = getConnectedParent();
2738
- if (!parent) return;
2739
- batch2(() => {
2740
- const oldBlocks = container.blocks;
2741
- const newBlocks = container.nextBlocks;
2742
- const prevOrderedBlocks = container.orderedBlocks;
2743
- const nextOrderedBlocks = container.nextOrderedBlocks;
2744
- const orderedIndexByKey = container.orderedIndexByKey;
2745
- const newItems = getItems();
2746
- if (newItems.length === 0) {
2747
- if (oldBlocks.size > 0) {
2748
- for (const block of oldBlocks.values()) {
2749
- destroyRoot(block.root);
2750
- }
2751
- const range = document.createRange();
2752
- range.setStartAfter(container.startMarker);
2753
- range.setEndBefore(container.endMarker);
2754
- range.deleteContents();
2755
- }
2756
- oldBlocks.clear();
2757
- newBlocks.clear();
2758
- prevOrderedBlocks.length = 0;
2759
- nextOrderedBlocks.length = 0;
2760
- orderedIndexByKey.clear();
2761
- container.currentNodes.length = 0;
2762
- container.currentNodes.push(container.startMarker, container.endMarker);
2763
- container.nextNodes.length = 0;
2764
- return;
2765
- }
2766
- const prevCount = prevOrderedBlocks.length;
2767
- if (prevCount > 0 && newItems.length === prevCount && orderedIndexByKey.size === prevCount) {
2768
- let stableOrder = true;
2769
- const seen = /* @__PURE__ */ new Set();
2770
- for (let i = 0; i < prevCount; i++) {
2771
- const item = newItems[i];
2772
- const key = keyFn(item, i);
2773
- if (seen.has(key) || prevOrderedBlocks[i].key !== key) {
2774
- stableOrder = false;
2775
- break;
2776
- }
2777
- seen.add(key);
2778
- }
2779
- if (stableOrder) {
2780
- for (let i = 0; i < prevCount; i++) {
2781
- const item = newItems[i];
2782
- const block = prevOrderedBlocks[i];
2783
- if (block.rawItem !== item) {
2784
- block.rawItem = item;
2785
- block.item(item);
2786
- }
2787
- if (needsIndex && block.rawIndex !== i) {
2788
- block.rawIndex = i;
2789
- block.index(i);
2790
- }
2791
- }
2792
- return;
2793
- }
2794
- }
2795
- newBlocks.clear();
2796
- nextOrderedBlocks.length = 0;
2797
- orderedIndexByKey.clear();
2798
- const createdBlocks = [];
2799
- let appendCandidate = prevCount > 0 && newItems.length >= prevCount;
2800
- const appendedBlocks = [];
2801
- let mismatchCount = 0;
2802
- let mismatchFirst = -1;
2803
- let mismatchSecond = -1;
2804
- let hasDuplicateKey = false;
2805
- newItems.forEach((item, index) => {
2806
- const key = keyFn(item, index);
2807
- let block = oldBlocks.get(key);
2808
- const existed = block !== void 0;
2809
- if (block) {
2810
- if (block.rawItem !== item) {
2811
- block.rawItem = item;
2812
- block.item(item);
2813
- }
2814
- if (needsIndex && block.rawIndex !== index) {
2815
- block.rawIndex = index;
2816
- block.index(index);
2817
- }
2818
- }
2819
- if (block) {
2820
- newBlocks.set(key, block);
2821
- oldBlocks.delete(key);
2822
- } else {
2823
- const existingBlock = newBlocks.get(key);
2824
- if (existingBlock) {
2825
- if (isDev2) {
2826
- console.warn(
2827
- `[fict] Duplicate key "${String(key)}" detected in list rendering. Each item should have a unique key. The previous item with this key will be replaced.`
2828
- );
2829
- }
2830
- destroyRoot(existingBlock.root);
2831
- removeNodes(existingBlock.nodes);
2832
- }
2833
- block = createKeyedBlock(key, item, index, renderItem, needsIndex, hostRoot);
2834
- createdBlocks.push(block);
2835
- }
2836
- const resolvedBlock = block;
2837
- newBlocks.set(key, resolvedBlock);
2838
- const position = orderedIndexByKey.get(key);
2839
- if (position !== void 0) {
2840
- appendCandidate = false;
2841
- hasDuplicateKey = true;
2842
- const prior = nextOrderedBlocks[position];
2843
- if (prior && prior !== resolvedBlock) {
2844
- destroyRoot(prior.root);
2845
- removeNodes(prior.nodes);
2846
- }
2847
- nextOrderedBlocks[position] = resolvedBlock;
2848
- } else {
2849
- if (appendCandidate) {
2850
- if (index < prevCount) {
2851
- if (!prevOrderedBlocks[index] || prevOrderedBlocks[index].key !== key) {
2852
- appendCandidate = false;
2853
- }
2854
- } else if (existed) {
2855
- appendCandidate = false;
2856
- }
2857
- }
2858
- const nextIndex = nextOrderedBlocks.length;
2859
- orderedIndexByKey.set(key, nextIndex);
2860
- nextOrderedBlocks.push(resolvedBlock);
2861
- if (mismatchCount < 3 && (nextIndex >= prevCount || prevOrderedBlocks[nextIndex] !== resolvedBlock)) {
2862
- if (mismatchCount === 0) {
2863
- mismatchFirst = nextIndex;
2864
- } else if (mismatchCount === 1) {
2865
- mismatchSecond = nextIndex;
2866
- }
2867
- mismatchCount++;
2868
- }
2869
- }
2870
- if (appendCandidate && index >= prevCount) {
2871
- appendedBlocks.push(resolvedBlock);
2872
- }
2873
- });
2874
- const canAppend = appendCandidate && prevCount > 0 && newItems.length > prevCount && oldBlocks.size === 0 && appendedBlocks.length > 0;
2875
- if (canAppend) {
2876
- const appendedNodes = [];
2877
- for (const block of appendedBlocks) {
2878
- for (let i = 0; i < block.nodes.length; i++) {
2879
- appendedNodes.push(block.nodes[i]);
2880
- }
2881
- }
2882
- if (appendedNodes.length > 0) {
2883
- insertNodesBefore(parent, appendedNodes, container.endMarker);
2884
- const currentNodes = container.currentNodes;
2885
- currentNodes.pop();
2886
- for (let i = 0; i < appendedNodes.length; i++) {
2887
- currentNodes.push(appendedNodes[i]);
2888
- }
2889
- currentNodes.push(container.endMarker);
2890
- }
2891
- container.blocks = newBlocks;
2892
- container.nextBlocks = oldBlocks;
2893
- container.orderedBlocks = nextOrderedBlocks;
2894
- container.nextOrderedBlocks = prevOrderedBlocks;
2895
- for (const block of createdBlocks) {
2896
- if (newBlocks.get(block.key) === block) {
2897
- flushOnMount(block.root);
2898
- }
2899
- }
2900
- return;
2901
- }
2902
- if (oldBlocks.size > 0) {
2903
- for (const block of oldBlocks.values()) {
2904
- destroyRoot(block.root);
2905
- removeNodes(block.nodes);
2906
- }
2907
- oldBlocks.clear();
2908
- }
2909
- const canReorderInPlace = createdBlocks.length === 0 && oldBlocks.size === 0 && nextOrderedBlocks.length === prevOrderedBlocks.length;
2910
- let skipReconcile = false;
2911
- let updateNodeBuffer = true;
2912
- if (canReorderInPlace && nextOrderedBlocks.length > 0 && !hasDuplicateKey) {
2913
- if (mismatchCount === 0) {
2914
- skipReconcile = true;
2915
- updateNodeBuffer = false;
2916
- } else if (mismatchCount === 2 && prevOrderedBlocks[mismatchFirst] === nextOrderedBlocks[mismatchSecond] && prevOrderedBlocks[mismatchSecond] === nextOrderedBlocks[mismatchFirst]) {
2917
- if (reorderBySwap(
2918
- parent,
2919
- prevOrderedBlocks[mismatchFirst],
2920
- prevOrderedBlocks[mismatchSecond]
2921
- )) {
2922
- skipReconcile = true;
2923
- }
2924
- } else if (reorderByLIS(parent, container.endMarker, prevOrderedBlocks, nextOrderedBlocks)) {
2925
- skipReconcile = true;
1540
+ try {
1541
+ const clone = parent.ownerDocument.importNode(node, true);
1542
+ parent.insertBefore(clone, anchor);
1543
+ return;
1544
+ } catch {
2926
1545
  }
2927
1546
  }
2928
- if (!skipReconcile && (newBlocks.size > 0 || container.currentNodes.length > 0)) {
2929
- const prevNodes = container.currentNodes;
2930
- const nextNodes = container.nextNodes;
2931
- nextNodes.length = 0;
2932
- nextNodes.push(container.startMarker);
2933
- for (let i = 0; i < nextOrderedBlocks.length; i++) {
2934
- const nodes = nextOrderedBlocks[i].nodes;
2935
- for (let j = 0; j < nodes.length; j++) {
2936
- nextNodes.push(nodes[j]);
2937
- }
2938
- }
2939
- nextNodes.push(container.endMarker);
2940
- reconcileArrays(parent, prevNodes, nextNodes);
2941
- container.currentNodes = nextNodes;
2942
- container.nextNodes = prevNodes;
2943
- } else if (skipReconcile && updateNodeBuffer) {
2944
- const prevNodes = container.currentNodes;
2945
- const nextNodes = container.nextNodes;
2946
- nextNodes.length = 0;
2947
- nextNodes.push(container.startMarker);
2948
- for (let i = 0; i < nextOrderedBlocks.length; i++) {
2949
- const nodes = nextOrderedBlocks[i].nodes;
2950
- for (let j = 0; j < nodes.length; j++) {
2951
- nextNodes.push(nodes[j]);
2952
- }
1547
+ throw e;
1548
+ }
1549
+ return;
1550
+ }
1551
+ const doc = parent.ownerDocument;
1552
+ if (doc) {
1553
+ const frag = doc.createDocumentFragment();
1554
+ for (let i = 0; i < nodes.length; i++) {
1555
+ const node = nodes[i];
1556
+ if (node === void 0 || node === null) continue;
1557
+ if (node.nodeType === 11) {
1558
+ const childrenArr = Array.from(node.childNodes);
1559
+ for (let j = 0; j < childrenArr.length; j++) {
1560
+ frag.appendChild(childrenArr[j]);
2953
1561
  }
2954
- nextNodes.push(container.endMarker);
2955
- container.currentNodes = nextNodes;
2956
- container.nextNodes = prevNodes;
2957
- }
2958
- container.blocks = newBlocks;
2959
- container.nextBlocks = oldBlocks;
2960
- container.orderedBlocks = nextOrderedBlocks;
2961
- container.nextOrderedBlocks = prevOrderedBlocks;
2962
- for (const block of createdBlocks) {
2963
- if (newBlocks.get(block.key) === block) {
2964
- flushOnMount(block.root);
1562
+ } else {
1563
+ if (node.ownerDocument !== doc) {
1564
+ doc.adoptNode(node);
2965
1565
  }
1566
+ frag.appendChild(node);
2966
1567
  }
2967
- });
2968
- };
2969
- const disconnectObserver = () => {
2970
- connectObserver?.disconnect();
2971
- connectObserver = null;
2972
- };
2973
- const ensureEffectStarted = () => {
2974
- if (disposed || effectStarted) return effectStarted;
2975
- const parent = getConnectedParent();
2976
- if (!parent) return false;
2977
- const start = () => {
2978
- effectDispose = createRenderEffect(performDiff);
2979
- effectStarted = true;
2980
- };
2981
- if (hostRoot) {
2982
- const prev = pushRoot(hostRoot);
2983
- try {
2984
- start();
2985
- } finally {
2986
- popRoot(prev);
2987
- }
2988
- } else {
2989
- start();
2990
1568
  }
2991
- return true;
2992
- };
2993
- const waitForConnection = () => {
2994
- if (connectObserver || typeof MutationObserver === "undefined") return;
2995
- connectObserver = new MutationObserver(() => {
2996
- if (disposed) return;
2997
- if (getConnectedParent()) {
2998
- disconnectObserver();
2999
- if (ensureEffectStarted()) {
3000
- flush();
1569
+ parent.insertBefore(frag, anchor);
1570
+ return;
1571
+ }
1572
+ const insertSingle = (nodeToInsert, anchorNode) => {
1573
+ if (nodeToInsert.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
1574
+ parent.ownerDocument.adoptNode(nodeToInsert);
1575
+ }
1576
+ try {
1577
+ parent.insertBefore(nodeToInsert, anchorNode);
1578
+ return nodeToInsert;
1579
+ } catch (e) {
1580
+ if (parent.ownerDocument) {
1581
+ try {
1582
+ const clone = parent.ownerDocument.importNode(nodeToInsert, true);
1583
+ parent.insertBefore(clone, anchorNode);
1584
+ return clone;
1585
+ } catch {
3001
1586
  }
3002
1587
  }
3003
- });
3004
- connectObserver.observe(document, { childList: true, subtree: true });
3005
- };
3006
- const scheduleStart = () => {
3007
- if (startScheduled || disposed || effectStarted) return;
3008
- startScheduled = true;
3009
- const run = () => {
3010
- startScheduled = false;
3011
- if (!ensureEffectStarted()) {
3012
- waitForConnection();
3013
- }
3014
- };
3015
- if (typeof queueMicrotask === "function") {
3016
- queueMicrotask(run);
3017
- } else {
3018
- Promise.resolve().then(run).catch(() => void 0);
1588
+ throw e;
3019
1589
  }
3020
1590
  };
3021
- scheduleStart();
3022
- return {
3023
- get marker() {
3024
- scheduleStart();
3025
- return fragment;
3026
- },
3027
- startMarker: container.startMarker,
3028
- endMarker: container.endMarker,
3029
- // Flush pending items - call after markers are inserted into DOM
3030
- flush: () => {
3031
- if (disposed) return;
3032
- scheduleStart();
3033
- if (ensureEffectStarted()) {
3034
- flush();
3035
- } else {
3036
- waitForConnection();
1591
+ for (let i = nodes.length - 1; i >= 0; i--) {
1592
+ const node = nodes[i];
1593
+ if (node === void 0 || node === null) continue;
1594
+ const isFrag = node.nodeType === 11;
1595
+ if (isFrag) {
1596
+ const childrenArr = Array.from(node.childNodes);
1597
+ for (let j = childrenArr.length - 1; j >= 0; j--) {
1598
+ const child = childrenArr[j];
1599
+ anchor = insertSingle(child, anchor);
3037
1600
  }
3038
- },
3039
- dispose: () => {
3040
- disposed = true;
3041
- effectDispose?.();
3042
- disconnectObserver();
3043
- container.dispose();
1601
+ } else {
1602
+ anchor = insertSingle(node, anchor);
3044
1603
  }
3045
- };
1604
+ }
1605
+ }
1606
+ function removeNodes(nodes) {
1607
+ for (const node of nodes) {
1608
+ node.parentNode?.removeChild(node);
1609
+ }
3046
1610
  }
3047
1611
 
3048
1612
  // src/binding.ts
1613
+ var isDev5 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
3049
1614
  function isReactive(value) {
3050
1615
  return typeof value === "function" && value.length === 0;
3051
1616
  }
3052
- function unwrap2(value) {
3053
- return isReactive(value) ? value() : value;
3054
- }
3055
1617
  function callEventHandler(handler, event, node, data) {
3056
1618
  if (!handler) return;
3057
1619
  const context = node ?? event.currentTarget ?? void 0;
@@ -3076,46 +1638,6 @@ function callEventHandler(handler, event, node, data) {
3076
1638
  };
3077
1639
  invoke(handler);
3078
1640
  }
3079
- var PRIMITIVE_PROXY = Symbol("fict:primitive-proxy");
3080
- var PRIMITIVE_PROXY_RAW_VALUE = Symbol("fict:primitive-proxy:raw-value");
3081
- function unwrapPrimitive(value) {
3082
- if (value && typeof value === "object" && PRIMITIVE_PROXY in value) {
3083
- const getRawValue = value[PRIMITIVE_PROXY_RAW_VALUE];
3084
- if (typeof getRawValue === "function") {
3085
- return getRawValue();
3086
- }
3087
- }
3088
- return value;
3089
- }
3090
- function createTextBinding(value) {
3091
- const text = document.createTextNode("");
3092
- if (isReactive(value)) {
3093
- createRenderEffect(() => {
3094
- const v = value();
3095
- const fmt = formatTextValue(v);
3096
- if (text.data !== fmt) {
3097
- text.data = fmt;
3098
- }
3099
- });
3100
- } else {
3101
- text.data = formatTextValue(value);
3102
- }
3103
- return text;
3104
- }
3105
- function bindText(textNode, getValue) {
3106
- return createRenderEffect(() => {
3107
- const value = formatTextValue(getValue());
3108
- if (textNode.data !== value) {
3109
- textNode.data = value;
3110
- }
3111
- });
3112
- }
3113
- function formatTextValue(value) {
3114
- if (value == null || value === false) {
3115
- return "";
3116
- }
3117
- return String(value);
3118
- }
3119
1641
  function createAttributeBinding(el, key, value, setter) {
3120
1642
  if (isReactive(value)) {
3121
1643
  createRenderEffect(() => {
@@ -3125,45 +1647,6 @@ function createAttributeBinding(el, key, value, setter) {
3125
1647
  setter(el, key, value);
3126
1648
  }
3127
1649
  }
3128
- function bindAttribute(el, key, getValue) {
3129
- let prevValue = void 0;
3130
- return createRenderEffect(() => {
3131
- const value = getValue();
3132
- if (value === prevValue) return;
3133
- prevValue = value;
3134
- if (value === void 0 || value === null || value === false) {
3135
- el.removeAttribute(key);
3136
- } else if (value === true) {
3137
- el.setAttribute(key, "");
3138
- } else {
3139
- el.setAttribute(key, String(value));
3140
- }
3141
- });
3142
- }
3143
- function bindProperty(el, key, getValue) {
3144
- const PROPERTY_BINDING_KEYS = /* @__PURE__ */ new Set([
3145
- "value",
3146
- "checked",
3147
- "selected",
3148
- "disabled",
3149
- "readOnly",
3150
- "multiple",
3151
- "muted"
3152
- ]);
3153
- let prevValue = void 0;
3154
- return createRenderEffect(() => {
3155
- const next = getValue();
3156
- if (next === prevValue) return;
3157
- prevValue = next;
3158
- if (PROPERTY_BINDING_KEYS.has(key) && (next === void 0 || next === null)) {
3159
- const fallback = key === "checked" || key === "selected" ? false : "";
3160
- el[key] = fallback;
3161
- return;
3162
- }
3163
- ;
3164
- el[key] = next;
3165
- });
3166
- }
3167
1650
  function createStyleBinding(el, value) {
3168
1651
  const target = el;
3169
1652
  if (isReactive(value)) {
@@ -3177,15 +1660,6 @@ function createStyleBinding(el, value) {
3177
1660
  applyStyle(target, value, void 0);
3178
1661
  }
3179
1662
  }
3180
- function bindStyle(el, getValue) {
3181
- const target = el;
3182
- let prev;
3183
- return createRenderEffect(() => {
3184
- const next = getValue();
3185
- applyStyle(target, next, prev);
3186
- prev = next;
3187
- });
3188
- }
3189
1663
  function applyStyle(el, value, prev) {
3190
1664
  if (typeof value === "string") {
3191
1665
  el.style.cssText = value;
@@ -3203,14 +1677,14 @@ function applyStyle(el, value, prev) {
3203
1677
  }
3204
1678
  }
3205
1679
  }
3206
- for (const [prop, v] of Object.entries(styles)) {
1680
+ for (const [prop2, v] of Object.entries(styles)) {
3207
1681
  if (v != null) {
3208
- const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
3209
- const unitless = isUnitlessStyleProperty(prop) || isUnitlessStyleProperty(cssProperty);
1682
+ const cssProperty = prop2.replace(/([A-Z])/g, "-$1").toLowerCase();
1683
+ const unitless = isUnitlessStyleProperty(prop2) || isUnitlessStyleProperty(cssProperty);
3210
1684
  const valueStr = typeof v === "number" && !unitless ? `${v}px` : String(v);
3211
1685
  el.style.setProperty(cssProperty, valueStr);
3212
1686
  } else {
3213
- const cssProperty = prop.replace(/([A-Z])/g, "-$1").toLowerCase();
1687
+ const cssProperty = prop2.replace(/([A-Z])/g, "-$1").toLowerCase();
3214
1688
  el.style.removeProperty(cssProperty);
3215
1689
  }
3216
1690
  }
@@ -3226,9 +1700,7 @@ function applyStyle(el, value, prev) {
3226
1700
  }
3227
1701
  }
3228
1702
  }
3229
- function isUnitlessStyleProperty(prop) {
3230
- return UnitlessStyles.has(prop);
3231
- }
1703
+ var isUnitlessStyleProperty = isDev5 ? (prop2) => UnitlessStyles.has(prop2) : (prop2) => prop2 === "opacity" || prop2 === "zIndex";
3232
1704
  function createClassBinding(el, value) {
3233
1705
  if (isReactive(value)) {
3234
1706
  let prev = {};
@@ -3240,22 +1712,6 @@ function createClassBinding(el, value) {
3240
1712
  applyClass(el, value, {});
3241
1713
  }
3242
1714
  }
3243
- function bindClass(el, getValue) {
3244
- let prev = {};
3245
- let prevString;
3246
- return createRenderEffect(() => {
3247
- const next = getValue();
3248
- if (typeof next === "string") {
3249
- if (next === prevString) return;
3250
- prevString = next;
3251
- el.className = next;
3252
- prev = {};
3253
- return;
3254
- }
3255
- prevString = void 0;
3256
- prev = applyClass(el, next, prev);
3257
- });
3258
- }
3259
1715
  function toggleClassKey(node, key, value) {
3260
1716
  const classNames = key.trim().split(/\s+/);
3261
1717
  for (let i = 0, len = classNames.length; i < len; i++) {
@@ -3297,119 +1753,6 @@ function applyClass(el, value, prev) {
3297
1753
  }
3298
1754
  return prevState;
3299
1755
  }
3300
- function classList(node, value, prev = {}) {
3301
- return applyClass(node, value, prev);
3302
- }
3303
- function insert(parent, getValue, markerOrCreateElement, createElementFn) {
3304
- const hostRoot = getCurrentRoot();
3305
- let marker;
3306
- let ownsMarker = false;
3307
- let createFn = createElementFn;
3308
- if (markerOrCreateElement instanceof Node) {
3309
- marker = markerOrCreateElement;
3310
- createFn = createElementFn;
3311
- } else {
3312
- marker = document.createComment("fict:insert");
3313
- parent.appendChild(marker);
3314
- createFn = markerOrCreateElement;
3315
- ownsMarker = true;
3316
- }
3317
- let currentNodes = [];
3318
- let currentText = null;
3319
- let currentRoot2 = null;
3320
- const clearCurrentNodes = () => {
3321
- if (currentNodes.length > 0) {
3322
- removeNodes(currentNodes);
3323
- currentNodes = [];
3324
- }
3325
- };
3326
- const setTextNode = (textValue, shouldInsert, parentNode) => {
3327
- if (!currentText) {
3328
- currentText = document.createTextNode(textValue);
3329
- } else if (currentText.data !== textValue) {
3330
- currentText.data = textValue;
3331
- }
3332
- if (!shouldInsert) {
3333
- clearCurrentNodes();
3334
- return;
3335
- }
3336
- if (currentNodes.length === 1 && currentNodes[0] === currentText) {
3337
- return;
3338
- }
3339
- clearCurrentNodes();
3340
- insertNodesBefore(parentNode, [currentText], marker);
3341
- currentNodes = [currentText];
3342
- };
3343
- const dispose = createRenderEffect(() => {
3344
- const value = getValue();
3345
- const parentNode = marker.parentNode;
3346
- const isPrimitive = value == null || value === false || typeof value === "string" || typeof value === "number" || typeof value === "boolean";
3347
- if (isPrimitive) {
3348
- if (currentRoot2) {
3349
- destroyRoot(currentRoot2);
3350
- currentRoot2 = null;
3351
- }
3352
- if (!parentNode) {
3353
- clearCurrentNodes();
3354
- return;
3355
- }
3356
- const textValue = value == null || value === false ? "" : String(value);
3357
- const shouldInsert = value != null && value !== false;
3358
- setTextNode(textValue, shouldInsert, parentNode);
3359
- return;
3360
- }
3361
- if (currentRoot2) {
3362
- destroyRoot(currentRoot2);
3363
- currentRoot2 = null;
3364
- }
3365
- clearCurrentNodes();
3366
- const root = createRootContext(hostRoot);
3367
- const prev = pushRoot(root);
3368
- let nodes = [];
3369
- try {
3370
- let newNode;
3371
- if (value instanceof Node) {
3372
- newNode = value;
3373
- } else if (Array.isArray(value)) {
3374
- if (value.every((v) => v instanceof Node)) {
3375
- newNode = value;
3376
- } else {
3377
- if (createFn) {
3378
- const mapped = [];
3379
- for (const item of value) {
3380
- mapped.push(...toNodeArray(createFn(item)));
3381
- }
3382
- newNode = mapped;
3383
- } else {
3384
- newNode = document.createTextNode(String(value));
3385
- }
3386
- }
3387
- } else {
3388
- newNode = createFn ? createFn(value) : document.createTextNode(String(value));
3389
- }
3390
- nodes = toNodeArray(newNode);
3391
- if (parentNode) {
3392
- insertNodesBefore(parentNode, nodes, marker);
3393
- }
3394
- } finally {
3395
- popRoot(prev);
3396
- flushOnMount(root);
3397
- }
3398
- currentRoot2 = root;
3399
- currentNodes = nodes;
3400
- });
3401
- return () => {
3402
- dispose();
3403
- if (currentRoot2) {
3404
- destroyRoot(currentRoot2);
3405
- currentRoot2 = null;
3406
- }
3407
- clearCurrentNodes();
3408
- if (ownsMarker) {
3409
- marker.parentNode?.removeChild(marker);
3410
- }
3411
- };
3412
- }
3413
1756
  function createChildBinding(parent, getValue, createElementFn) {
3414
1757
  const marker = document.createComment("fict:child");
3415
1758
  parent.appendChild(marker);
@@ -3471,15 +1814,6 @@ function delegateEvents(eventNames, doc = window.document) {
3471
1814
  }
3472
1815
  }
3473
1816
  }
3474
- function clearDelegatedEvents(doc = window.document) {
3475
- const e = doc[$$EVENTS];
3476
- if (e) {
3477
- for (const name of e.keys()) {
3478
- doc.removeEventListener(name, globalEventHandler);
3479
- }
3480
- delete doc[$$EVENTS];
3481
- }
3482
- }
3483
1817
  function globalEventHandler(e) {
3484
1818
  const asNode = (value) => value && typeof value.nodeType === "number" ? value : null;
3485
1819
  const asElement = (value) => {
@@ -3560,785 +1894,664 @@ function globalEventHandler(e) {
3560
1894
  walkUpTree();
3561
1895
  break;
3562
1896
  }
3563
- if (node.parentNode === oriCurrentTarget) {
3564
- break;
1897
+ if (node.parentNode === oriCurrentTarget) {
1898
+ break;
1899
+ }
1900
+ }
1901
+ } else {
1902
+ walkUpTree();
1903
+ }
1904
+ retarget(oriTarget);
1905
+ }
1906
+ function bindEvent(el, eventName, handler, options) {
1907
+ if (handler == null) return () => {
1908
+ };
1909
+ const rootRef = getCurrentRoot();
1910
+ if (isDev5 && DelegatedEvents.has(eventName) && !options) {
1911
+ const key = `$$${eventName}`;
1912
+ delegateEvents([eventName]);
1913
+ const resolveHandler = isReactive(handler) ? handler : () => handler;
1914
+ el[key] = function(...args) {
1915
+ try {
1916
+ const fn = resolveHandler();
1917
+ callEventHandler(fn, args[0], el);
1918
+ } catch (err) {
1919
+ if (!handleError(err, { source: "event", eventName }, rootRef)) {
1920
+ throw err;
1921
+ }
1922
+ }
1923
+ };
1924
+ return () => {
1925
+ el[key] = void 0;
1926
+ };
1927
+ }
1928
+ const getHandler = isReactive(handler) ? handler : () => handler;
1929
+ const wrapped = (event) => {
1930
+ try {
1931
+ const resolved = getHandler();
1932
+ callEventHandler(resolved, event, el);
1933
+ } catch (err) {
1934
+ if (handleError(err, { source: "event", eventName }, rootRef)) {
1935
+ return;
1936
+ }
1937
+ throw err;
1938
+ }
1939
+ };
1940
+ el.addEventListener(eventName, wrapped, options);
1941
+ const cleanup = () => el.removeEventListener(eventName, wrapped, options);
1942
+ registerRootCleanup(cleanup);
1943
+ return cleanup;
1944
+ }
1945
+ function createPortal(container, render2, createElementFn) {
1946
+ const parentRoot = getCurrentRoot();
1947
+ const marker = document.createComment("fict:portal");
1948
+ container.appendChild(marker);
1949
+ let currentNodes = [];
1950
+ let currentRoot2 = null;
1951
+ const dispose = createRenderEffect(() => {
1952
+ if (currentRoot2) {
1953
+ destroyRoot(currentRoot2);
1954
+ currentRoot2 = null;
1955
+ }
1956
+ if (currentNodes.length > 0) {
1957
+ removeNodes(currentNodes);
1958
+ currentNodes = [];
1959
+ }
1960
+ const root = createRootContext(parentRoot);
1961
+ const prev = pushRoot(root);
1962
+ let handledError = false;
1963
+ try {
1964
+ const output = render2();
1965
+ if (output != null && output !== false) {
1966
+ const el = createElementFn(output);
1967
+ const nodes = toNodeArray(el);
1968
+ if (marker.parentNode) {
1969
+ insertNodesBefore(marker.parentNode, nodes, marker);
1970
+ }
1971
+ currentNodes = nodes;
1972
+ }
1973
+ } catch (err) {
1974
+ if (handleSuspend(err, root)) {
1975
+ handledError = true;
1976
+ destroyRoot(root);
1977
+ currentNodes = [];
1978
+ return;
1979
+ }
1980
+ if (handleError(err, { source: "renderChild" }, root)) {
1981
+ handledError = true;
1982
+ destroyRoot(root);
1983
+ currentNodes = [];
1984
+ return;
1985
+ }
1986
+ throw err;
1987
+ } finally {
1988
+ popRoot(prev);
1989
+ if (!handledError) {
1990
+ flushOnMount(root);
1991
+ currentRoot2 = root;
1992
+ } else {
1993
+ currentRoot2 = null;
3565
1994
  }
3566
1995
  }
3567
- } else {
3568
- walkUpTree();
1996
+ });
1997
+ const portalDispose = () => {
1998
+ dispose();
1999
+ if (currentRoot2) {
2000
+ destroyRoot(currentRoot2);
2001
+ }
2002
+ if (currentNodes.length > 0) {
2003
+ removeNodes(currentNodes);
2004
+ }
2005
+ marker.parentNode?.removeChild(marker);
2006
+ };
2007
+ if (parentRoot) {
2008
+ parentRoot.destroyCallbacks.push(portalDispose);
3569
2009
  }
3570
- retarget(oriTarget);
2010
+ return {
2011
+ marker,
2012
+ dispose: portalDispose
2013
+ };
3571
2014
  }
3572
- function addEventListener(node, name, handler, delegate) {
3573
- if (handler == null) return;
3574
- if (delegate) {
3575
- if (Array.isArray(handler)) {
3576
- ;
3577
- node[`$$${name}`] = handler[0];
3578
- node[`$$${name}Data`] = handler[1];
3579
- } else {
3580
- ;
3581
- node[`$$${name}`] = handler;
3582
- }
3583
- } else if (Array.isArray(handler)) {
3584
- const handlerFn = handler[0];
3585
- node.addEventListener(name, (e) => handlerFn.call(node, handler[1], e));
3586
- } else {
3587
- node.addEventListener(name, handler);
2015
+
2016
+ // src/hooks.ts
2017
+ var isDev6 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
2018
+ var ctxStack = [];
2019
+ function __fictPushContext() {
2020
+ const ctx = { slots: [], cursor: 0 };
2021
+ ctxStack.push(ctx);
2022
+ return ctx;
2023
+ }
2024
+ function __fictPopContext() {
2025
+ ctxStack.pop();
2026
+ }
2027
+
2028
+ // src/props.ts
2029
+ var propGetters = /* @__PURE__ */ new WeakSet();
2030
+ var rawToProxy = /* @__PURE__ */ new WeakMap();
2031
+ var proxyToRaw = /* @__PURE__ */ new WeakMap();
2032
+ function __fictProp(getter) {
2033
+ if (typeof getter === "function" && getter.length === 0) {
2034
+ propGetters.add(getter);
3588
2035
  }
2036
+ return getter;
3589
2037
  }
3590
- function bindEvent(el, eventName, handler, options2) {
3591
- if (handler == null) return () => {
3592
- };
3593
- const rootRef = getCurrentRoot();
3594
- if (DelegatedEvents.has(eventName) && !options2) {
3595
- const key = `$$${eventName}`;
3596
- delegateEvents([eventName]);
3597
- const resolveHandler = isReactive(handler) ? handler : () => handler;
3598
- el[key] = function(...args) {
3599
- try {
3600
- const fn = resolveHandler();
3601
- callEventHandler(fn, args[0], el);
3602
- } catch (err) {
3603
- if (!handleError(err, { source: "event", eventName }, rootRef)) {
3604
- throw err;
3605
- }
3606
- }
3607
- };
3608
- return () => {
3609
- el[key] = void 0;
3610
- };
2038
+ function isPropGetter(value) {
2039
+ return typeof value === "function" && propGetters.has(value);
2040
+ }
2041
+ function createPropsProxy(props) {
2042
+ if (!props || typeof props !== "object") {
2043
+ return props;
3611
2044
  }
3612
- const getHandler = isReactive(handler) ? handler : () => handler;
3613
- const wrapped = (event) => {
3614
- try {
3615
- const resolved = getHandler();
3616
- callEventHandler(resolved, event, el);
3617
- } catch (err) {
3618
- if (handleError(err, { source: "event", eventName }, rootRef)) {
3619
- return;
2045
+ if (proxyToRaw.has(props)) {
2046
+ return props;
2047
+ }
2048
+ const cached = rawToProxy.get(props);
2049
+ if (cached) {
2050
+ return cached;
2051
+ }
2052
+ const proxy = new Proxy(props, {
2053
+ get(target, prop2, receiver) {
2054
+ const value = Reflect.get(target, prop2, receiver);
2055
+ if (isPropGetter(value)) {
2056
+ return value();
3620
2057
  }
3621
- throw err;
2058
+ return value;
2059
+ },
2060
+ set(target, prop2, value, receiver) {
2061
+ return Reflect.set(target, prop2, value, receiver);
2062
+ },
2063
+ has(target, prop2) {
2064
+ return prop2 in target;
2065
+ },
2066
+ ownKeys(target) {
2067
+ return Reflect.ownKeys(target);
2068
+ },
2069
+ getOwnPropertyDescriptor(target, prop2) {
2070
+ return Object.getOwnPropertyDescriptor(target, prop2);
3622
2071
  }
3623
- };
3624
- el.addEventListener(eventName, wrapped, options2);
3625
- const cleanup = () => el.removeEventListener(eventName, wrapped, options2);
3626
- registerRootCleanup(cleanup);
3627
- return cleanup;
2072
+ });
2073
+ rawToProxy.set(props, proxy);
2074
+ proxyToRaw.set(proxy, props);
2075
+ return proxy;
2076
+ }
2077
+ function unwrapProps(props) {
2078
+ if (!props || typeof props !== "object") {
2079
+ return props;
2080
+ }
2081
+ return proxyToRaw.get(props) ?? props;
3628
2082
  }
3629
- function bindRef(el, ref) {
3630
- if (ref == null) return () => {
2083
+ function mergeProps(...sources) {
2084
+ const validSources = sources.filter(
2085
+ (s) => s != null && (typeof s === "object" || typeof s === "function")
2086
+ );
2087
+ if (validSources.length === 0) {
2088
+ return {};
2089
+ }
2090
+ if (validSources.length === 1 && typeof validSources[0] === "object") {
2091
+ return validSources[0];
2092
+ }
2093
+ const resolveSource = (src) => {
2094
+ const value = typeof src === "function" ? src() : src;
2095
+ if (!value || typeof value !== "object") return void 0;
2096
+ return unwrapProps(value);
3631
2097
  };
3632
- const getRef = isReactive(ref) ? ref : () => ref;
3633
- const applyRef2 = (refValue) => {
3634
- if (refValue == null) return;
3635
- if (typeof refValue === "function") {
3636
- ;
3637
- refValue(el);
3638
- } else if (typeof refValue === "object" && "current" in refValue) {
3639
- ;
3640
- refValue.current = el;
2098
+ const hasProp = (prop2) => {
2099
+ for (const src of validSources) {
2100
+ const raw = resolveSource(src);
2101
+ if (raw && prop2 in raw) {
2102
+ return true;
2103
+ }
3641
2104
  }
2105
+ return false;
3642
2106
  };
3643
- const initialRef = getRef();
3644
- applyRef2(initialRef);
3645
- if (isReactive(ref)) {
3646
- const cleanup2 = createRenderEffect(() => {
3647
- const currentRef = getRef();
3648
- applyRef2(currentRef);
3649
- });
3650
- registerRootCleanup(cleanup2);
3651
- const nullifyCleanup = () => {
3652
- const currentRef = getRef();
3653
- if (currentRef && typeof currentRef === "object" && "current" in currentRef) {
3654
- ;
3655
- currentRef.current = null;
2107
+ const readProp = (prop2) => {
2108
+ for (let i = validSources.length - 1; i >= 0; i--) {
2109
+ const src = validSources[i];
2110
+ const raw = resolveSource(src);
2111
+ if (!raw || !(prop2 in raw)) continue;
2112
+ const value = raw[prop2];
2113
+ if (typeof src === "function" && !isPropGetter(value)) {
2114
+ return __fictProp(() => {
2115
+ const latest = resolveSource(src);
2116
+ if (!latest || !(prop2 in latest)) return void 0;
2117
+ return latest[prop2];
2118
+ });
3656
2119
  }
3657
- };
3658
- registerRootCleanup(nullifyCleanup);
3659
- return () => {
3660
- cleanup2();
3661
- nullifyCleanup();
3662
- };
3663
- }
3664
- const cleanup = () => {
3665
- const refValue = getRef();
3666
- if (refValue && typeof refValue === "object" && "current" in refValue) {
3667
- ;
3668
- refValue.current = null;
2120
+ return value;
3669
2121
  }
2122
+ return void 0;
3670
2123
  };
3671
- registerRootCleanup(cleanup);
3672
- return cleanup;
3673
- }
3674
- function spread(node, props = {}, isSVG = false, skipChildren = false) {
3675
- const prevProps = {};
3676
- if (!skipChildren && "children" in props) {
3677
- createRenderEffect(() => {
3678
- prevProps.children = props.children;
3679
- });
3680
- }
3681
- createRenderEffect(() => {
3682
- if (typeof props.ref === "function") {
3683
- ;
3684
- props.ref(node);
2124
+ return new Proxy({}, {
2125
+ get(_, prop2) {
2126
+ return readProp(prop2);
2127
+ },
2128
+ has(_, prop2) {
2129
+ return hasProp(prop2);
2130
+ },
2131
+ ownKeys() {
2132
+ const keys = /* @__PURE__ */ new Set();
2133
+ for (const src of validSources) {
2134
+ const raw = resolveSource(src);
2135
+ if (raw) {
2136
+ for (const key of Reflect.ownKeys(raw)) {
2137
+ keys.add(key);
2138
+ }
2139
+ }
2140
+ }
2141
+ return Array.from(keys);
2142
+ },
2143
+ getOwnPropertyDescriptor(_, prop2) {
2144
+ if (!hasProp(prop2)) return void 0;
2145
+ return {
2146
+ enumerable: true,
2147
+ configurable: true,
2148
+ get: () => readProp(prop2)
2149
+ };
3685
2150
  }
3686
2151
  });
3687
- createRenderEffect(() => {
3688
- assign(node, props, isSVG, true, prevProps, true);
3689
- });
3690
- return prevProps;
3691
2152
  }
3692
- function assign(node, props, isSVG = false, skipChildren = false, prevProps = {}, skipRef = false) {
3693
- props = props || {};
3694
- for (const prop in prevProps) {
3695
- if (!(prop in props)) {
3696
- if (prop === "children") continue;
3697
- prevProps[prop] = assignProp(node, prop, null, prevProps[prop], isSVG, skipRef, props);
2153
+ function prop(getter) {
2154
+ if (isPropGetter(getter)) {
2155
+ return getter;
2156
+ }
2157
+ return __fictProp(createMemo(getter));
2158
+ }
2159
+
2160
+ // src/dom.ts
2161
+ var SVG_NS = "http://www.w3.org/2000/svg";
2162
+ var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
2163
+ var isDev7 = true ? true : typeof process === "undefined" || process.env?.NODE_ENV !== "production";
2164
+ function render(view, container) {
2165
+ const root = createRootContext();
2166
+ const prev = pushRoot(root);
2167
+ let dom;
2168
+ try {
2169
+ const output = view();
2170
+ dom = createElement(output);
2171
+ } finally {
2172
+ popRoot(prev);
2173
+ }
2174
+ container.replaceChildren(dom);
2175
+ container.setAttribute("data-fict-fine-grained", "1");
2176
+ flushOnMount(root);
2177
+ const teardown = () => {
2178
+ destroyRoot(root);
2179
+ container.innerHTML = "";
2180
+ };
2181
+ return teardown;
2182
+ }
2183
+ function createElement(node) {
2184
+ return createElementWithContext(node, null);
2185
+ }
2186
+ function resolveNamespace(tagName, namespace) {
2187
+ if (tagName === "svg") return "svg";
2188
+ if (tagName === "math") return "mathml";
2189
+ if (namespace === "mathml") return "mathml";
2190
+ if (namespace === "svg") return "svg";
2191
+ if (isDev7 && SVGElements.has(tagName)) return "svg";
2192
+ return null;
2193
+ }
2194
+ function createElementWithContext(node, namespace) {
2195
+ if (node instanceof Node) {
2196
+ return node;
2197
+ }
2198
+ if (node === null || node === void 0 || node === false) {
2199
+ return document.createTextNode("");
2200
+ }
2201
+ if (typeof node === "object" && node !== null && !(node instanceof Node)) {
2202
+ if ("marker" in node) {
2203
+ const handle = node;
2204
+ if (typeof handle.dispose === "function") {
2205
+ registerRootCleanup(handle.dispose);
2206
+ }
2207
+ if (typeof handle.flush === "function") {
2208
+ const runFlush = () => handle.flush && handle.flush();
2209
+ if (typeof queueMicrotask === "function") {
2210
+ queueMicrotask(runFlush);
2211
+ } else {
2212
+ Promise.resolve().then(runFlush).catch(() => void 0);
2213
+ }
2214
+ }
2215
+ return createElement(handle.marker);
2216
+ }
2217
+ }
2218
+ if (Array.isArray(node)) {
2219
+ const frag = document.createDocumentFragment();
2220
+ for (const child of node) {
2221
+ appendChildNode(frag, child, namespace);
3698
2222
  }
2223
+ return frag;
2224
+ }
2225
+ if (typeof node === "string" || typeof node === "number") {
2226
+ return document.createTextNode(String(node));
3699
2227
  }
3700
- for (const prop in props) {
3701
- if (prop === "children") {
3702
- if (!skipChildren) {
3703
- prevProps.children = props.children;
2228
+ if (typeof node === "boolean") {
2229
+ return document.createTextNode("");
2230
+ }
2231
+ const vnode = node;
2232
+ if (typeof vnode.type === "function") {
2233
+ const rawProps = unwrapProps(vnode.props ?? {});
2234
+ const baseProps = vnode.key === void 0 ? rawProps : new Proxy(rawProps, {
2235
+ get(target, prop2, receiver) {
2236
+ if (prop2 === "key") return vnode.key;
2237
+ return Reflect.get(target, prop2, receiver);
2238
+ },
2239
+ has(target, prop2) {
2240
+ if (prop2 === "key") return true;
2241
+ return prop2 in target;
2242
+ },
2243
+ ownKeys(target) {
2244
+ const keys = new Set(Reflect.ownKeys(target));
2245
+ keys.add("key");
2246
+ return Array.from(keys);
2247
+ },
2248
+ getOwnPropertyDescriptor(target, prop2) {
2249
+ if (prop2 === "key") {
2250
+ return { enumerable: true, configurable: true, value: vnode.key };
2251
+ }
2252
+ return Object.getOwnPropertyDescriptor(target, prop2);
2253
+ }
2254
+ });
2255
+ const props = createPropsProxy(baseProps);
2256
+ __fictPushContext();
2257
+ try {
2258
+ const rendered = vnode.type(props);
2259
+ return createElementWithContext(rendered, namespace);
2260
+ } catch (err) {
2261
+ if (handleSuspend(err)) {
2262
+ return document.createComment("fict:suspend");
3704
2263
  }
3705
- continue;
2264
+ handleError(err, { source: "render", componentName: vnode.type.name });
2265
+ throw err;
2266
+ } finally {
2267
+ __fictPopContext();
3706
2268
  }
3707
- const value = props[prop];
3708
- prevProps[prop] = assignProp(node, prop, value, prevProps[prop], isSVG, skipRef, props);
3709
- }
3710
- }
3711
- function assignProp(node, prop, value, prev, isSVG, skipRef, props) {
3712
- if (prop === "style") {
3713
- applyStyle(node, value, prev);
3714
- return value;
3715
2269
  }
3716
- if (prop === "classList") {
3717
- return applyClass(node, value, prev);
2270
+ if (vnode.type === Fragment) {
2271
+ const frag = document.createDocumentFragment();
2272
+ const children = vnode.props?.children;
2273
+ appendChildren(frag, children, namespace);
2274
+ return frag;
3718
2275
  }
3719
- if (value === prev) return prev;
3720
- if (prop === "ref") {
3721
- if (!skipRef && typeof value === "function") {
3722
- ;
3723
- value(node);
3724
- }
3725
- return value;
2276
+ const tagName = typeof vnode.type === "string" ? vnode.type : "div";
2277
+ const resolvedNamespace = resolveNamespace(tagName, namespace);
2278
+ const el = resolvedNamespace === "svg" ? document.createElementNS(SVG_NS, tagName) : resolvedNamespace === "mathml" ? document.createElementNS(MATHML_NS, tagName) : document.createElement(tagName);
2279
+ applyProps(el, vnode.props ?? {}, resolvedNamespace === "svg");
2280
+ appendChildren(
2281
+ el,
2282
+ vnode.props?.children,
2283
+ tagName === "foreignObject" ? null : resolvedNamespace
2284
+ );
2285
+ return el;
2286
+ }
2287
+ function isBindingHandle(node) {
2288
+ return node !== null && typeof node === "object" && "marker" in node && "dispose" in node && typeof node.dispose === "function";
2289
+ }
2290
+ function appendChildNode(parent, child, namespace) {
2291
+ if (child === null || child === void 0 || child === false) {
2292
+ return;
3726
2293
  }
3727
- if (prop.slice(0, 3) === "on:") {
3728
- const eventName = prop.slice(3);
3729
- if (prev) node.removeEventListener(eventName, prev);
3730
- if (value) node.addEventListener(eventName, value);
3731
- return value;
2294
+ if (isBindingHandle(child)) {
2295
+ appendChildNode(parent, child.marker, namespace);
2296
+ child.flush?.();
2297
+ return;
3732
2298
  }
3733
- if (prop.slice(0, 10) === "oncapture:") {
3734
- const eventName = prop.slice(10);
3735
- if (prev) node.removeEventListener(eventName, prev, true);
3736
- if (value) node.addEventListener(eventName, value, true);
3737
- return value;
2299
+ if (typeof child === "function" && child.length === 0) {
2300
+ const childGetter = child;
2301
+ createChildBinding(parent, childGetter, (node) => createElementWithContext(node, namespace));
2302
+ return;
3738
2303
  }
3739
- if (prop.slice(0, 2) === "on") {
3740
- const eventName = prop.slice(2).toLowerCase();
3741
- const shouldDelegate = DelegatedEvents.has(eventName);
3742
- if (!shouldDelegate && prev) {
3743
- const handler = Array.isArray(prev) ? prev[0] : prev;
3744
- node.removeEventListener(eventName, handler);
3745
- }
3746
- if (shouldDelegate || value) {
3747
- addEventListener(node, eventName, value, shouldDelegate);
3748
- if (shouldDelegate) delegateEvents([eventName]);
2304
+ if (Array.isArray(child)) {
2305
+ for (const item of child) {
2306
+ appendChildNode(parent, item, namespace);
3749
2307
  }
3750
- return value;
3751
- }
3752
- if (prop.slice(0, 5) === "attr:") {
3753
- if (value == null) node.removeAttribute(prop.slice(5));
3754
- else node.setAttribute(prop.slice(5), String(value));
3755
- return value;
3756
- }
3757
- if (prop.slice(0, 5) === "bool:") {
3758
- if (value) node.setAttribute(prop.slice(5), "");
3759
- else node.removeAttribute(prop.slice(5));
3760
- return value;
3761
- }
3762
- if (prop.slice(0, 5) === "prop:") {
3763
- ;
3764
- node[prop.slice(5)] = value;
3765
- return value;
2308
+ return;
3766
2309
  }
3767
- if (prop === "class" || prop === "className") {
3768
- if (value == null) node.removeAttribute("class");
3769
- else node.className = String(value);
3770
- return value;
2310
+ let domNode;
2311
+ if (typeof child !== "object" || child === null) {
2312
+ domNode = document.createTextNode(String(child ?? ""));
2313
+ } else {
2314
+ domNode = createElementWithContext(child, namespace);
3771
2315
  }
3772
- const isCE = node.nodeName.includes("-") || "is" in props;
3773
- if (!isSVG) {
3774
- const propAlias = getPropAlias(prop, node.tagName);
3775
- const isProperty = Properties.has(prop);
3776
- const isChildProp = ChildProperties.has(prop);
3777
- if (propAlias || isProperty || isChildProp || isCE) {
3778
- const propName = propAlias || prop;
3779
- if (isCE && !isProperty && !isChildProp) {
3780
- ;
3781
- node[toPropertyName2(propName)] = value;
3782
- } else {
3783
- ;
3784
- node[propName] = value;
3785
- }
3786
- return value;
2316
+ if (domNode.nodeType === 11) {
2317
+ const children = Array.from(domNode.childNodes);
2318
+ for (const node of children) {
2319
+ appendChildNode(parent, node, namespace);
3787
2320
  }
2321
+ return;
3788
2322
  }
3789
- if (isSVG && prop.indexOf(":") > -1) {
3790
- const [prefix, name] = prop.split(":");
3791
- const ns = SVGNamespace[prefix];
3792
- if (ns) {
3793
- if (value == null) node.removeAttributeNS(ns, name);
3794
- else node.setAttributeNS(ns, name, String(value));
3795
- return value;
3796
- }
2323
+ if (domNode.ownerDocument !== parent.ownerDocument && parent.ownerDocument) {
2324
+ parent.ownerDocument.adoptNode(domNode);
3797
2325
  }
3798
- const attrName = Aliases[prop] || prop;
3799
- if (value == null) node.removeAttribute(attrName);
3800
- else node.setAttribute(attrName, String(value));
3801
- return value;
3802
- }
3803
- function toPropertyName2(name) {
3804
- return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
3805
- }
3806
- function createConditional(condition, renderTrue, createElementFn, renderFalse) {
3807
- const startMarker = document.createComment("fict:cond:start");
3808
- const endMarker = document.createComment("fict:cond:end");
3809
- const fragment = document.createDocumentFragment();
3810
- fragment.append(startMarker, endMarker);
3811
- const hostRoot = getCurrentRoot();
3812
- let currentNodes = [];
3813
- let currentRoot2 = null;
3814
- let lastCondition = void 0;
3815
- let pendingRender = false;
3816
- const conditionMemo = computed(condition);
3817
- const runConditional = () => {
3818
- const cond = conditionMemo();
3819
- const parent = startMarker.parentNode;
3820
- if (!parent) {
3821
- pendingRender = true;
3822
- return;
3823
- }
3824
- pendingRender = false;
3825
- if (lastCondition === cond && currentNodes.length > 0) {
3826
- return;
3827
- }
3828
- if (lastCondition === cond && lastCondition === false && renderFalse === void 0) {
3829
- return;
3830
- }
3831
- lastCondition = cond;
3832
- if (currentRoot2) {
3833
- destroyRoot(currentRoot2);
3834
- currentRoot2 = null;
3835
- }
3836
- removeNodes(currentNodes);
3837
- currentNodes = [];
3838
- const render2 = cond ? renderTrue : renderFalse;
3839
- if (!render2) {
2326
+ try {
2327
+ parent.appendChild(domNode);
2328
+ } catch (e) {
2329
+ if (parent.ownerDocument) {
2330
+ const clone = parent.ownerDocument.importNode(domNode, true);
2331
+ parent.appendChild(clone);
3840
2332
  return;
3841
2333
  }
3842
- const root = createRootContext(hostRoot);
3843
- const prev = pushRoot(root);
3844
- let handledError = false;
3845
- try {
3846
- const output = untrack(render2);
3847
- if (output == null || output === false) {
3848
- return;
3849
- }
3850
- const el = createElementFn(output);
3851
- const nodes = toNodeArray(el);
3852
- insertNodesBefore(parent, nodes, endMarker);
3853
- currentNodes = nodes;
3854
- } catch (err) {
3855
- if (handleSuspend(err, root)) {
3856
- handledError = true;
3857
- destroyRoot(root);
3858
- return;
3859
- }
3860
- if (handleError(err, { source: "renderChild" }, root)) {
3861
- handledError = true;
3862
- destroyRoot(root);
3863
- return;
3864
- }
3865
- throw err;
3866
- } finally {
3867
- popRoot(prev);
3868
- if (!handledError) {
3869
- flushOnMount(root);
3870
- currentRoot2 = root;
3871
- } else {
3872
- currentRoot2 = null;
3873
- }
3874
- }
3875
- };
3876
- const dispose = createRenderEffect(runConditional);
3877
- return {
3878
- marker: fragment,
3879
- flush: () => {
3880
- if (pendingRender) {
3881
- runConditional();
3882
- }
3883
- },
3884
- dispose: () => {
3885
- dispose();
3886
- if (currentRoot2) {
3887
- destroyRoot(currentRoot2);
3888
- }
3889
- removeNodes(currentNodes);
3890
- currentNodes = [];
3891
- startMarker.parentNode?.removeChild(startMarker);
3892
- endMarker.parentNode?.removeChild(endMarker);
3893
- }
3894
- };
2334
+ throw e;
2335
+ }
3895
2336
  }
3896
- function createList(items, renderItem, createElementFn, getKey) {
3897
- const startMarker = document.createComment("fict:list:start");
3898
- const endMarker = document.createComment("fict:list:end");
3899
- const fragment = document.createDocumentFragment();
3900
- fragment.append(startMarker, endMarker);
3901
- const hostRoot = getCurrentRoot();
3902
- const nodeMap = /* @__PURE__ */ new Map();
3903
- let pendingItems = null;
3904
- const runListUpdate = () => {
3905
- const arr = items();
3906
- const parent = startMarker.parentNode;
3907
- if (!parent) {
3908
- pendingItems = arr;
3909
- return;
3910
- }
3911
- pendingItems = null;
3912
- const newNodeMap = /* @__PURE__ */ new Map();
3913
- const blocks = [];
3914
- for (let i = 0; i < arr.length; i++) {
3915
- const item = arr[i];
3916
- const key = getKey ? getKey(item, i) : i;
3917
- const existing = nodeMap.get(key);
3918
- let block;
3919
- if (existing) {
3920
- const previousValue = existing.value();
3921
- if (!getKey && previousValue !== item) {
3922
- destroyRoot(existing.root);
3923
- removeBlockNodes(existing);
3924
- block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn, hostRoot);
3925
- } else {
3926
- const previousIndex = existing.index();
3927
- existing.value(item);
3928
- existing.index(i);
3929
- const needsRerender = getKey ? true : previousValue !== item || previousIndex !== i;
3930
- block = needsRerender ? rerenderBlock(existing, createElementFn) : existing;
3931
- }
3932
- } else {
3933
- block = mountBlock(item, i, renderItem, parent, endMarker, createElementFn, hostRoot);
3934
- }
3935
- newNodeMap.set(key, block);
3936
- blocks.push(block);
3937
- }
3938
- for (const [key, managed] of nodeMap) {
3939
- if (!newNodeMap.has(key)) {
3940
- destroyRoot(managed.root);
3941
- removeBlockNodes(managed);
3942
- }
3943
- }
3944
- let anchor = endMarker;
3945
- for (let i = blocks.length - 1; i >= 0; i--) {
3946
- const block = blocks[i];
3947
- insertNodesBefore(parent, block.nodes, anchor);
3948
- if (block.nodes.length > 0) {
3949
- anchor = block.nodes[0];
3950
- }
3951
- }
3952
- nodeMap.clear();
3953
- for (const [k, v] of newNodeMap) {
3954
- nodeMap.set(k, v);
3955
- }
3956
- };
3957
- const dispose = createRenderEffect(runListUpdate);
3958
- return {
3959
- marker: fragment,
3960
- flush: () => {
3961
- if (pendingItems !== null) {
3962
- runListUpdate();
3963
- }
3964
- },
3965
- dispose: () => {
3966
- dispose();
3967
- for (const [, managed] of nodeMap) {
3968
- destroyRoot(managed.root);
3969
- removeBlockNodes(managed);
3970
- }
3971
- nodeMap.clear();
3972
- startMarker.parentNode?.removeChild(startMarker);
3973
- endMarker.parentNode?.removeChild(endMarker);
2337
+ function appendChildren(parent, children, namespace) {
2338
+ if (children === void 0) return;
2339
+ if (Array.isArray(children)) {
2340
+ for (const child of children) {
2341
+ appendChildren(parent, child, namespace);
3974
2342
  }
3975
- };
3976
- }
3977
- function createShow(el, condition, displayValue) {
3978
- const originalDisplay = displayValue ?? el.style.display;
3979
- createRenderEffect(() => {
3980
- el.style.display = condition() ? originalDisplay : "none";
3981
- });
2343
+ return;
2344
+ }
2345
+ appendChildNode(parent, children, namespace);
3982
2346
  }
3983
- function createPortal(container, render2, createElementFn) {
3984
- const parentRoot = getCurrentRoot();
3985
- const marker = document.createComment("fict:portal");
3986
- container.appendChild(marker);
3987
- let currentNodes = [];
3988
- let currentRoot2 = null;
3989
- const dispose = createRenderEffect(() => {
3990
- if (currentRoot2) {
3991
- destroyRoot(currentRoot2);
3992
- currentRoot2 = null;
3993
- }
3994
- if (currentNodes.length > 0) {
3995
- removeNodes(currentNodes);
3996
- currentNodes = [];
3997
- }
3998
- const root = createRootContext(parentRoot);
3999
- const prev = pushRoot(root);
4000
- let handledError = false;
4001
- try {
4002
- const output = render2();
4003
- if (output != null && output !== false) {
4004
- const el = createElementFn(output);
4005
- const nodes = toNodeArray(el);
4006
- if (marker.parentNode) {
4007
- insertNodesBefore(marker.parentNode, nodes, marker);
4008
- }
4009
- currentNodes = nodes;
4010
- }
4011
- } catch (err) {
4012
- if (handleSuspend(err, root)) {
4013
- handledError = true;
4014
- destroyRoot(root);
4015
- currentNodes = [];
4016
- return;
4017
- }
4018
- if (handleError(err, { source: "renderChild" }, root)) {
4019
- handledError = true;
4020
- destroyRoot(root);
4021
- currentNodes = [];
4022
- return;
4023
- }
4024
- throw err;
4025
- } finally {
4026
- popRoot(prev);
4027
- if (!handledError) {
4028
- flushOnMount(root);
4029
- currentRoot2 = root;
4030
- } else {
4031
- currentRoot2 = null;
4032
- }
4033
- }
4034
- });
4035
- const portalDispose = () => {
4036
- dispose();
4037
- if (currentRoot2) {
4038
- destroyRoot(currentRoot2);
2347
+ function applyRef(el, value) {
2348
+ if (typeof value === "function") {
2349
+ const refFn = value;
2350
+ refFn(el);
2351
+ const root = getCurrentRoot();
2352
+ if (root) {
2353
+ registerRootCleanup(() => {
2354
+ refFn(null);
2355
+ });
2356
+ } else if (isDev7) {
2357
+ console.warn(
2358
+ "[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."
2359
+ );
4039
2360
  }
4040
- if (currentNodes.length > 0) {
4041
- removeNodes(currentNodes);
2361
+ } else if (value && typeof value === "object" && "current" in value) {
2362
+ const refObj = value;
2363
+ refObj.current = el;
2364
+ const root = getCurrentRoot();
2365
+ if (root) {
2366
+ registerRootCleanup(() => {
2367
+ refObj.current = null;
2368
+ });
2369
+ } else if (isDev7) {
2370
+ console.warn(
2371
+ "[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."
2372
+ );
4042
2373
  }
4043
- marker.parentNode?.removeChild(marker);
4044
- };
4045
- if (parentRoot) {
4046
- parentRoot.destroyCallbacks.push(portalDispose);
4047
2374
  }
4048
- return {
4049
- marker,
4050
- dispose: portalDispose
4051
- };
4052
2375
  }
4053
- function mountBlock(initialValue, initialIndex, renderItem, parent, anchor, createElementFn, hostRoot) {
4054
- const start = document.createComment("fict:block:start");
4055
- const end = document.createComment("fict:block:end");
4056
- const valueSig = createVersionedSignalAccessor(initialValue);
4057
- const indexSig = signal(initialIndex);
4058
- const renderCurrent = () => renderItem(valueSig, indexSig);
4059
- const root = createRootContext(hostRoot);
4060
- const prev = pushRoot(root);
4061
- const nodes = [start];
4062
- let handledError = false;
4063
- try {
4064
- const output = renderCurrent();
4065
- if (output != null && output !== false) {
4066
- const el = createElementFn(output);
4067
- const rendered = toNodeArray(el);
4068
- nodes.push(...rendered);
2376
+ function applyProps(el, props, isSVG = false) {
2377
+ props = unwrapProps(props);
2378
+ const tagName = el.tagName;
2379
+ const isCE = tagName.includes("-") || "is" in props;
2380
+ for (const [key, value] of Object.entries(props)) {
2381
+ if (key === "children") continue;
2382
+ if (key === "ref") {
2383
+ applyRef(el, value);
2384
+ continue;
4069
2385
  }
4070
- nodes.push(end);
4071
- insertNodesBefore(parent, nodes, anchor);
4072
- } catch (err) {
4073
- if (handleSuspend(err, root)) {
4074
- handledError = true;
4075
- nodes.push(end);
4076
- insertNodesBefore(parent, nodes, anchor);
4077
- } else if (handleError(err, { source: "renderChild" }, root)) {
4078
- handledError = true;
4079
- nodes.push(end);
4080
- insertNodesBefore(parent, nodes, anchor);
4081
- } else {
4082
- throw err;
2386
+ if (isEventKey(key)) {
2387
+ bindEvent(
2388
+ el,
2389
+ eventNameFromProp(key),
2390
+ value
2391
+ );
2392
+ continue;
4083
2393
  }
4084
- } finally {
4085
- popRoot(prev);
4086
- if (!handledError) {
4087
- flushOnMount(root);
4088
- } else {
4089
- destroyRoot(root);
2394
+ if (key.slice(0, 3) === "on:") {
2395
+ bindEvent(
2396
+ el,
2397
+ key.slice(3),
2398
+ value,
2399
+ false
2400
+ // Non-delegated
2401
+ );
2402
+ continue;
4090
2403
  }
4091
- }
4092
- return {
4093
- nodes,
4094
- root,
4095
- value: valueSig,
4096
- index: indexSig,
4097
- start,
4098
- end,
4099
- renderCurrent
4100
- };
4101
- }
4102
- function rerenderBlock(block, createElementFn) {
4103
- const currentContent = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
4104
- const currentNode = currentContent.length === 1 ? currentContent[0] : null;
4105
- clearRoot(block.root);
4106
- const prev = pushRoot(block.root);
4107
- let nextOutput;
4108
- let handledError = false;
4109
- try {
4110
- nextOutput = block.renderCurrent();
4111
- } catch (err) {
4112
- if (handleSuspend(err, block.root)) {
4113
- handledError = true;
4114
- popRoot(prev);
4115
- destroyRoot(block.root);
4116
- block.nodes = [block.start, block.end];
4117
- return block;
2404
+ if (key.slice(0, 10) === "oncapture:") {
2405
+ bindEvent(
2406
+ el,
2407
+ key.slice(10),
2408
+ value,
2409
+ true
2410
+ // Capture
2411
+ );
2412
+ continue;
4118
2413
  }
4119
- if (handleError(err, { source: "renderChild" }, block.root)) {
4120
- handledError = true;
4121
- popRoot(prev);
4122
- destroyRoot(block.root);
4123
- block.nodes = [block.start, block.end];
4124
- return block;
2414
+ if (key === "class" || key === "className") {
2415
+ createClassBinding(el, value);
2416
+ continue;
4125
2417
  }
4126
- throw err;
4127
- } finally {
4128
- if (!handledError) {
4129
- popRoot(prev);
2418
+ if (key === "classList") {
2419
+ createClassBinding(el, value);
2420
+ continue;
4130
2421
  }
4131
- }
4132
- if (isFragmentVNode(nextOutput) && currentContent.length > 0) {
4133
- const patched = patchFragmentChildren(currentContent, nextOutput.props?.children);
4134
- if (patched) {
4135
- block.nodes = [block.start, ...currentContent, block.end];
4136
- return block;
2422
+ if (key === "style") {
2423
+ createStyleBinding(
2424
+ el,
2425
+ value
2426
+ );
2427
+ continue;
4137
2428
  }
4138
- }
4139
- if (currentNode && patchNode(currentNode, nextOutput)) {
4140
- block.nodes = [block.start, currentNode, block.end];
4141
- return block;
4142
- }
4143
- clearContent(block);
4144
- if (nextOutput != null && nextOutput !== false) {
4145
- const newNodes = toNodeArray(
4146
- nextOutput instanceof Node ? nextOutput : createElementFn(nextOutput)
4147
- );
4148
- insertNodesBefore(block.start.parentNode, newNodes, block.end);
4149
- block.nodes = [block.start, ...newNodes, block.end];
4150
- } else {
4151
- block.nodes = [block.start, block.end];
4152
- }
4153
- return block;
4154
- }
4155
- function patchElement(el, output) {
4156
- if (output === null || output === void 0 || output === false || typeof output === "string" || typeof output === "number") {
4157
- el.textContent = output === null || output === void 0 || output === false ? "" : String(output);
4158
- return true;
4159
- }
4160
- if (output instanceof Text) {
4161
- el.textContent = output.data;
4162
- return true;
4163
- }
4164
- if (output && typeof output === "object" && !(output instanceof Node)) {
4165
- const vnode = output;
4166
- if (typeof vnode.type === "string" && vnode.type.toLowerCase() === el.tagName.toLowerCase()) {
4167
- const children = vnode.props?.children;
4168
- const props = vnode.props ?? {};
4169
- for (const [key, value] of Object.entries(props)) {
4170
- if (key === "children" || key === "key") continue;
4171
- if (typeof value === "string" || typeof value === "number" || typeof value === "boolean" || value === null || value === void 0) {
4172
- if (key === "class" || key === "className") {
4173
- el.setAttribute("class", value === false || value === null ? "" : String(value));
4174
- } else if (key === "style" && typeof value === "string") {
4175
- ;
4176
- el.style.cssText = value;
4177
- } else if (value === false || value === null || value === void 0) {
4178
- el.removeAttribute(key);
4179
- } else if (value === true) {
4180
- el.setAttribute(key, "");
4181
- } else {
4182
- el.setAttribute(key, String(value));
4183
- }
2429
+ if (key === "dangerouslySetInnerHTML" && value && typeof value === "object") {
2430
+ const htmlValue = value.__html;
2431
+ if (htmlValue !== void 0) {
2432
+ if (isReactive(htmlValue)) {
2433
+ createAttributeBinding(el, "innerHTML", htmlValue, setInnerHTML);
2434
+ } else {
2435
+ el.innerHTML = htmlValue;
4184
2436
  }
4185
2437
  }
4186
- if (typeof children === "string" || typeof children === "number" || children === null || children === void 0 || children === false) {
4187
- el.textContent = children === null || children === void 0 || children === false ? "" : String(children);
4188
- return true;
4189
- }
4190
- if (children && typeof children === "object" && !Array.isArray(children) && !(children instanceof Node)) {
4191
- const childVNode = children;
4192
- if (typeof childVNode.type === "string") {
4193
- const childEl = el.querySelector(childVNode.type);
4194
- if (childEl && patchElement(childEl, children)) {
4195
- return true;
4196
- }
4197
- }
2438
+ continue;
2439
+ }
2440
+ if (isDev7 && ChildProperties.has(key) || key === "innerHTML" || key === "textContent" || key === "innerText" || key === "children") {
2441
+ createAttributeBinding(el, key, value, setProperty);
2442
+ continue;
2443
+ }
2444
+ if (key.slice(0, 5) === "attr:") {
2445
+ createAttributeBinding(el, key.slice(5), value, setAttribute);
2446
+ continue;
2447
+ }
2448
+ if (key.slice(0, 5) === "bool:") {
2449
+ createAttributeBinding(el, key.slice(5), value, setBoolAttribute);
2450
+ continue;
2451
+ }
2452
+ if (key.slice(0, 5) === "prop:") {
2453
+ createAttributeBinding(el, key.slice(5), value, setProperty);
2454
+ continue;
2455
+ }
2456
+ const propAlias = !isSVG && isDev7 ? getPropAlias(key, tagName) : void 0;
2457
+ const isProperty = !isSVG ? isDev7 ? Properties.has(key) : key in el : false;
2458
+ if (propAlias || isProperty || isCE && !isSVG) {
2459
+ const propName = propAlias || key;
2460
+ if (isCE && !isProperty && !propAlias) {
2461
+ createAttributeBinding(
2462
+ el,
2463
+ toPropertyName(propName),
2464
+ value,
2465
+ setProperty
2466
+ );
2467
+ } else {
2468
+ createAttributeBinding(el, propName, value, setProperty);
4198
2469
  }
4199
- return false;
2470
+ continue;
4200
2471
  }
4201
- }
4202
- if (output instanceof Node) {
4203
- if (output.nodeType === Node.ELEMENT_NODE) {
4204
- const nextEl = output;
4205
- if (nextEl.tagName.toLowerCase() === el.tagName.toLowerCase()) {
4206
- el.textContent = nextEl.textContent;
4207
- return true;
2472
+ if (isSVG && key.indexOf(":") > -1) {
2473
+ const [prefix, name] = key.split(":");
2474
+ const ns = SVGNamespace[prefix];
2475
+ if (ns) {
2476
+ createAttributeBinding(
2477
+ el,
2478
+ key,
2479
+ value,
2480
+ (el2, _key, val) => setAttributeNS(el2, ns, name, val)
2481
+ );
2482
+ continue;
4208
2483
  }
4209
- } else if (output.nodeType === Node.TEXT_NODE) {
4210
- el.textContent = output.data;
4211
- return true;
4212
2484
  }
2485
+ const attrName = key === "htmlFor" ? "for" : key;
2486
+ createAttributeBinding(el, attrName, value, setAttribute);
4213
2487
  }
4214
- return false;
4215
- }
4216
- function patchNode(currentNode, nextOutput) {
4217
- if (!currentNode) return false;
4218
- if (currentNode instanceof Text && (nextOutput === null || nextOutput === void 0 || nextOutput === false || typeof nextOutput === "string" || typeof nextOutput === "number" || nextOutput instanceof Text)) {
4219
- const nextText = nextOutput instanceof Text ? nextOutput.data : nextOutput === null || nextOutput === void 0 || nextOutput === false ? "" : String(nextOutput);
4220
- currentNode.data = nextText;
4221
- return true;
4222
- }
4223
- if (currentNode instanceof Element && patchElement(currentNode, nextOutput)) {
4224
- return true;
4225
- }
4226
- if (nextOutput instanceof Node && currentNode === nextOutput) {
4227
- return true;
4228
- }
4229
- return false;
4230
2488
  }
4231
- function isFragmentVNode(value) {
4232
- return value != null && typeof value === "object" && !(value instanceof Node) && value.type === Fragment;
2489
+ function toPropertyName(name) {
2490
+ return name.toLowerCase().replace(/-([a-z])/g, (_, w) => w.toUpperCase());
4233
2491
  }
4234
- function normalizeChildren(children, result = []) {
4235
- if (children === void 0) {
4236
- return result;
2492
+ var setAttribute = (el, key, value) => {
2493
+ if (value === void 0 || value === null || value === false) {
2494
+ el.removeAttribute(key);
2495
+ return;
4237
2496
  }
4238
- if (Array.isArray(children)) {
4239
- for (const child of children) {
4240
- normalizeChildren(child, result);
4241
- }
4242
- return result;
2497
+ if (value === true) {
2498
+ el.setAttribute(key, "");
2499
+ return;
4243
2500
  }
4244
- if (children === null || children === false) {
4245
- return result;
2501
+ const valueType = typeof value;
2502
+ if (valueType === "string" || valueType === "number") {
2503
+ el.setAttribute(key, String(value));
2504
+ return;
4246
2505
  }
4247
- result.push(children);
4248
- return result;
4249
- }
4250
- function patchFragmentChildren(nodes, children) {
4251
- const normalized = normalizeChildren(children);
4252
- if (normalized.length !== nodes.length) {
4253
- return false;
2506
+ if (key in el) {
2507
+ ;
2508
+ el[key] = value;
2509
+ return;
4254
2510
  }
4255
- for (let i = 0; i < normalized.length; i++) {
4256
- if (!patchNode(nodes[i], normalized[i])) {
4257
- return false;
2511
+ el.setAttribute(key, String(value));
2512
+ };
2513
+ var setProperty = (el, key, value) => {
2514
+ if (value === void 0 || value === null) {
2515
+ const fallback = key === "checked" || key === "selected" ? false : "";
2516
+ el[key] = fallback;
2517
+ return;
2518
+ }
2519
+ if (key === "style" && typeof value === "object" && value !== null) {
2520
+ for (const k in value) {
2521
+ const v = value[k];
2522
+ if (v !== void 0) {
2523
+ ;
2524
+ el.style[k] = String(v);
2525
+ }
4258
2526
  }
2527
+ return;
4259
2528
  }
4260
- return true;
4261
- }
4262
- function clearContent(block) {
4263
- const nodes = block.nodes.slice(1, Math.max(1, block.nodes.length - 1));
4264
- removeNodes(nodes);
4265
- }
4266
- function removeBlockNodes(block) {
4267
- let cursor = block.start;
4268
- const end = block.end;
4269
- while (cursor) {
4270
- const next = cursor.nextSibling;
4271
- cursor.parentNode?.removeChild(cursor);
4272
- if (cursor === end) break;
4273
- cursor = next;
2529
+ ;
2530
+ el[key] = value;
2531
+ };
2532
+ var setInnerHTML = (el, _key, value) => {
2533
+ ;
2534
+ el.innerHTML = value == null ? "" : String(value);
2535
+ };
2536
+ var setBoolAttribute = (el, key, value) => {
2537
+ if (value) {
2538
+ el.setAttribute(key, "");
2539
+ } else {
2540
+ el.removeAttribute(key);
2541
+ }
2542
+ };
2543
+ function setAttributeNS(el, namespace, name, value) {
2544
+ if (value == null) {
2545
+ el.removeAttributeNS(namespace, name);
2546
+ } else {
2547
+ el.setAttributeNS(namespace, name, String(value));
4274
2548
  }
4275
2549
  }
4276
-
4277
- // src/scope.ts
4278
- function createScope() {
4279
- let dispose = null;
4280
- const stop = () => {
4281
- if (dispose) {
4282
- dispose();
4283
- dispose = null;
4284
- }
4285
- };
4286
- const run = (fn) => {
4287
- stop();
4288
- const { dispose: rootDispose, value } = createRoot(fn);
4289
- dispose = rootDispose;
4290
- return value;
4291
- };
4292
- registerRootCleanup(stop);
4293
- return { run, stop };
4294
- }
4295
- function runInScope(flag, fn) {
4296
- const scope = createScope();
4297
- const evaluate = () => isReactive(flag) ? flag() : !!flag;
4298
- createEffect(() => {
4299
- const enabled = evaluate();
4300
- if (enabled) {
4301
- scope.run(fn);
4302
- } else {
4303
- scope.stop();
4304
- }
4305
- });
4306
- onCleanup(scope.stop);
4307
- }
4308
-
4309
- // src/versioned-signal.ts
4310
- function createVersionedSignal(initialValue, options2) {
4311
- const equals = options2?.equals ?? Object.is;
4312
- const value = signal(initialValue);
4313
- const version = signal(0);
4314
- const bumpVersion = () => {
4315
- const next = version() + 1;
4316
- version(next);
4317
- };
4318
- return {
4319
- read: () => {
4320
- version();
4321
- return value();
4322
- },
4323
- write: (next) => {
4324
- const prev = value();
4325
- if (!equals(prev, next)) {
4326
- value(next);
4327
- return;
4328
- }
4329
- bumpVersion();
4330
- },
4331
- force: () => {
4332
- bumpVersion();
4333
- },
4334
- peekVersion: () => version(),
4335
- peekValue: () => value()
4336
- };
2550
+ function isEventKey(key) {
2551
+ return key.startsWith("on") && key.length > 2 && key[2].toUpperCase() === key[2];
4337
2552
  }
4338
-
4339
- // src/ref.ts
4340
- function createRef() {
4341
- return { current: null };
2553
+ function eventNameFromProp(key) {
2554
+ return key.slice(2).toLowerCase();
4342
2555
  }
4343
2556
 
4344
2557
  // src/error-boundary.ts
@@ -4566,100 +2779,119 @@ function Suspense(props) {
4566
2779
  }
4567
2780
  return fragment;
4568
2781
  }
2782
+
2783
+ // src/context.ts
2784
+ var contextStorage = /* @__PURE__ */ new WeakMap();
2785
+ function getContextMap(root) {
2786
+ let map = contextStorage.get(root);
2787
+ if (!map) {
2788
+ map = /* @__PURE__ */ new Map();
2789
+ contextStorage.set(root, map);
2790
+ }
2791
+ return map;
2792
+ }
2793
+ function createContext(defaultValue) {
2794
+ const id = Symbol("fict.context");
2795
+ const context = {
2796
+ id,
2797
+ defaultValue,
2798
+ Provider: null
2799
+ };
2800
+ context.Provider = function Provider(props) {
2801
+ const hostRoot = getCurrentRoot();
2802
+ const providerRoot = createRootContext(hostRoot);
2803
+ const contextMap = getContextMap(providerRoot);
2804
+ contextMap.set(id, props.value);
2805
+ const fragment = document.createDocumentFragment();
2806
+ const marker = document.createComment("fict:ctx");
2807
+ fragment.appendChild(marker);
2808
+ let cleanup;
2809
+ let activeNodes = [];
2810
+ const renderChildren = (children) => {
2811
+ if (cleanup) {
2812
+ cleanup();
2813
+ cleanup = void 0;
2814
+ }
2815
+ if (activeNodes.length) {
2816
+ removeNodes(activeNodes);
2817
+ activeNodes = [];
2818
+ }
2819
+ if (children == null || children === false) {
2820
+ return;
2821
+ }
2822
+ const prev = pushRoot(providerRoot);
2823
+ let nodes = [];
2824
+ try {
2825
+ const output = createElement(children);
2826
+ nodes = toNodeArray(output);
2827
+ const parentNode = marker.parentNode;
2828
+ if (parentNode) {
2829
+ insertNodesBefore(parentNode, nodes, marker);
2830
+ }
2831
+ } finally {
2832
+ popRoot(prev);
2833
+ flushOnMount(providerRoot);
2834
+ }
2835
+ cleanup = () => {
2836
+ destroyRoot(providerRoot);
2837
+ removeNodes(nodes);
2838
+ };
2839
+ activeNodes = nodes;
2840
+ };
2841
+ createRenderEffect(() => {
2842
+ contextMap.set(id, props.value);
2843
+ renderChildren(props.children);
2844
+ });
2845
+ return fragment;
2846
+ };
2847
+ return context;
2848
+ }
2849
+ function useContext(context) {
2850
+ let root = getCurrentRoot();
2851
+ while (root) {
2852
+ const contextMap = contextStorage.get(root);
2853
+ if (contextMap && contextMap.has(context.id)) {
2854
+ return contextMap.get(context.id);
2855
+ }
2856
+ root = root.parent;
2857
+ }
2858
+ return context.defaultValue;
2859
+ }
2860
+ function hasContext(context) {
2861
+ let root = getCurrentRoot();
2862
+ while (root) {
2863
+ const contextMap = contextStorage.get(root);
2864
+ if (contextMap && contextMap.has(context.id)) {
2865
+ return true;
2866
+ }
2867
+ root = root.parent;
2868
+ }
2869
+ return false;
2870
+ }
4569
2871
  export {
4570
- $effect,
4571
- $memo,
4572
- $state,
4573
- Aliases,
4574
- BooleanAttributes,
4575
- ChildProperties,
4576
- DelegatedEvents,
4577
2872
  ErrorBoundary,
4578
2873
  Fragment,
4579
- Properties,
4580
- SVGElements,
4581
- SVGNamespace,
4582
2874
  Suspense,
4583
- UnitlessStyles,
4584
- __fictPopContext,
4585
- __fictProp,
4586
- __fictPropsRest,
4587
- __fictPushContext,
4588
- __fictRender,
4589
- __fictResetContext,
4590
- __fictUseContext,
4591
- __fictUseEffect,
4592
- __fictUseMemo,
4593
- __fictUseSignal,
4594
- addEventListener,
4595
- assign,
4596
2875
  batch2 as batch,
4597
- bindAttribute,
4598
- bindClass,
4599
- bindEvent,
4600
- bindProperty,
4601
- bindRef,
4602
- bindStyle,
4603
- bindText,
4604
- callEventHandler,
4605
- classList,
4606
- clearDelegatedEvents,
4607
- createAttributeBinding,
4608
- createChildBinding,
4609
- createClassBinding,
4610
- createConditional,
2876
+ createContext,
4611
2877
  createEffect,
4612
2878
  createElement,
4613
- createKeyedBlock,
4614
- createKeyedList,
4615
- createKeyedListContainer,
4616
- createList,
4617
2879
  createMemo,
4618
2880
  createPortal,
4619
- createPropsProxy,
4620
2881
  createRef,
4621
- createRenderEffect,
4622
2882
  createRoot,
4623
- createScope,
4624
- createSelector,
4625
- createShow,
4626
- signal as createSignal,
4627
- createStore,
4628
- createStyleBinding,
4629
2883
  createSuspenseToken,
4630
- createTextBinding,
4631
- createVersionedSignal,
4632
- delegateEvents,
4633
- destroyMarkerBlock,
4634
- effectScope,
4635
- getDevtoolsHook,
4636
- getFirstNodeAfter,
4637
- getPropAlias,
4638
- insert,
4639
- insertNodesBefore,
4640
- isNodeBetweenMarkers,
4641
- isReactive,
2884
+ hasContext,
4642
2885
  mergeProps,
4643
- moveMarkerBlock,
4644
- moveNodesBefore,
4645
2886
  onCleanup,
4646
2887
  onDestroy,
4647
2888
  onMount,
4648
- __fictProp as prop,
4649
- reconcileArrays,
4650
- removeNodes,
2889
+ prop,
4651
2890
  render,
4652
- runInScope,
4653
- setCycleProtectionOptions,
4654
- spread,
4655
2891
  startTransition,
4656
- template,
4657
- toNodeArray,
4658
2892
  untrack2 as untrack,
4659
- unwrap2 as unwrap,
4660
- unwrapPrimitive,
2893
+ useContext,
4661
2894
  useDeferredValue,
4662
- useProp,
4663
2895
  useTransition
4664
2896
  };
4665
2897
  //# sourceMappingURL=index.dev.js.map