@fictjs/runtime 0.9.0 → 0.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. package/dist/advanced.cjs +9 -9
  2. package/dist/advanced.d.cts +4 -4
  3. package/dist/advanced.d.ts +4 -4
  4. package/dist/advanced.js +4 -4
  5. package/dist/{binding-BWchH3Kp.d.cts → binding-DcnhUSQK.d.ts} +5 -3
  6. package/dist/{binding-BWchH3Kp.d.ts → binding-FRyTeLDn.d.cts} +5 -3
  7. package/dist/{chunk-FVX77557.js → chunk-2UR2UWE2.js} +3 -3
  8. package/dist/{chunk-LBE6DC3V.cjs → chunk-44EQF3AR.cjs} +63 -52
  9. package/dist/chunk-44EQF3AR.cjs.map +1 -0
  10. package/dist/{chunk-OAM7HABA.cjs → chunk-4QGEN5SJ.cjs} +340 -263
  11. package/dist/chunk-4QGEN5SJ.cjs.map +1 -0
  12. package/dist/{chunk-PD6IQY2Y.cjs → chunk-C5IE4WUG.cjs} +8 -8
  13. package/dist/{chunk-PD6IQY2Y.cjs.map → chunk-C5IE4WUG.cjs.map} +1 -1
  14. package/dist/{chunk-DXG3TARY.js → chunk-DIK33H5U.js} +202 -30
  15. package/dist/chunk-DIK33H5U.js.map +1 -0
  16. package/dist/{chunk-JVYH76ZX.js → chunk-FESAXMHT.js} +7 -6
  17. package/dist/{chunk-JVYH76ZX.js.map → chunk-FESAXMHT.js.map} +1 -1
  18. package/dist/chunk-FHQZCAAK.cjs +112 -0
  19. package/dist/chunk-FHQZCAAK.cjs.map +1 -0
  20. package/dist/{chunk-UBFDB6OL.cjs → chunk-QNMYVXRL.cjs} +222 -50
  21. package/dist/chunk-QNMYVXRL.cjs.map +1 -0
  22. package/dist/{chunk-N6ODUM2Y.js → chunk-S63VBIWN.js} +27 -16
  23. package/dist/chunk-S63VBIWN.js.map +1 -0
  24. package/dist/{chunk-T2LNV5Q5.js → chunk-WIHNVN6L.js} +153 -76
  25. package/dist/chunk-WIHNVN6L.js.map +1 -0
  26. package/dist/{devtools-BDp76luf.d.ts → devtools-BtIkN77t.d.cts} +14 -2
  27. package/dist/{devtools-5AipK9CX.d.cts → devtools-D2z4llpA.d.ts} +14 -2
  28. package/dist/index.cjs +60 -58
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +5 -5
  31. package/dist/index.d.ts +5 -5
  32. package/dist/index.dev.js +300 -74
  33. package/dist/index.dev.js.map +1 -1
  34. package/dist/index.js +13 -11
  35. package/dist/index.js.map +1 -1
  36. package/dist/internal-list.cjs +4 -4
  37. package/dist/internal-list.d.cts +2 -2
  38. package/dist/internal-list.d.ts +2 -2
  39. package/dist/internal-list.js +3 -3
  40. package/dist/internal.cjs +5 -5
  41. package/dist/internal.d.cts +6 -6
  42. package/dist/internal.d.ts +6 -6
  43. package/dist/internal.js +4 -4
  44. package/dist/jsx-dev-runtime.d.cts +671 -0
  45. package/dist/jsx-dev-runtime.d.ts +671 -0
  46. package/dist/jsx-runtime.d.cts +671 -0
  47. package/dist/jsx-runtime.d.ts +671 -0
  48. package/dist/{list-DL5DOFcO.d.ts → list-BKM6YOPq.d.ts} +2 -2
  49. package/dist/{list-hP7hQ9Vk.d.cts → list-Bi8dDF8Q.d.cts} +2 -2
  50. package/dist/loader.cjs +34 -28
  51. package/dist/loader.cjs.map +1 -1
  52. package/dist/loader.d.cts +2 -2
  53. package/dist/loader.d.ts +2 -2
  54. package/dist/loader.js +17 -11
  55. package/dist/loader.js.map +1 -1
  56. package/dist/{props-BpZz0AOq.d.cts → props-9chMyBGb.d.cts} +2 -2
  57. package/dist/{props-CjLH0JE-.d.ts → props-D1nj2p_3.d.ts} +2 -2
  58. package/dist/{resume-BJ4oHLi_.d.cts → resume-C5IKAIdh.d.ts} +2 -2
  59. package/dist/{resume-CuyJWXP_.d.ts → resume-DPZxmA95.d.cts} +2 -2
  60. package/dist/{scope-jPt5DHRT.d.ts → scope-BSkhJr0a.d.ts} +1 -1
  61. package/dist/{scope-BJCtq8hJ.d.cts → scope-Bn3sxem5.d.cts} +1 -1
  62. package/dist/{signal-C4ISF17w.d.cts → signal-Z4KkDk9h.d.cts} +12 -1
  63. package/dist/{signal-C4ISF17w.d.ts → signal-Z4KkDk9h.d.ts} +12 -1
  64. package/package.json +2 -2
  65. package/src/binding.ts +59 -29
  66. package/src/context.ts +4 -3
  67. package/src/devtools.ts +19 -2
  68. package/src/dom.ts +122 -42
  69. package/src/effect.ts +5 -5
  70. package/src/error-boundary.ts +5 -5
  71. package/src/hooks.ts +13 -5
  72. package/src/lifecycle.ts +48 -3
  73. package/src/list-helpers.ts +30 -13
  74. package/src/loader.ts +20 -12
  75. package/src/node-ops.ts +8 -5
  76. package/src/signal.ts +191 -18
  77. package/src/suspense.ts +5 -4
  78. package/src/transition.ts +9 -3
  79. package/dist/chunk-DXG3TARY.js.map +0 -1
  80. package/dist/chunk-LBE6DC3V.cjs.map +0 -1
  81. package/dist/chunk-N6ODUM2Y.js.map +0 -1
  82. package/dist/chunk-OAM7HABA.cjs.map +0 -1
  83. package/dist/chunk-PG4QX2I2.cjs +0 -111
  84. package/dist/chunk-PG4QX2I2.cjs.map +0 -1
  85. package/dist/chunk-T2LNV5Q5.js.map +0 -1
  86. package/dist/chunk-UBFDB6OL.cjs.map +0 -1
  87. /package/dist/{chunk-FVX77557.js.map → chunk-2UR2UWE2.js.map} +0 -0
@@ -40,7 +40,7 @@ import {
40
40
  setTransitionContext,
41
41
  signal,
42
42
  untrack
43
- } from "./chunk-DXG3TARY.js";
43
+ } from "./chunk-DIK33H5U.js";
44
44
 
45
45
  // src/transition.ts
46
46
  function startTransition(fn) {
@@ -86,7 +86,11 @@ function useTransition() {
86
86
  throw thrown;
87
87
  }
88
88
  if (result && typeof result.then === "function") {
89
- Promise.resolve(result).finally(() => {
89
+ void Promise.resolve(result).catch((error) => {
90
+ if (typeof console !== "undefined" && typeof console.error === "function") {
91
+ console.error("[fict/transition] Async transition failed.", error);
92
+ }
93
+ }).finally(() => {
90
94
  endPending();
91
95
  });
92
96
  return;
@@ -125,7 +129,7 @@ function untrack2(fn) {
125
129
  var Fragment = Symbol("Fragment");
126
130
 
127
131
  // src/node-ops.ts
128
- function toNodeArray(node) {
132
+ function toNodeArray(node, ownerDocument = document) {
129
133
  try {
130
134
  if (Array.isArray(node)) {
131
135
  let allNodes = true;
@@ -146,7 +150,7 @@ function toNodeArray(node) {
146
150
  }
147
151
  const result = [];
148
152
  for (const item of node) {
149
- result.push(...toNodeArray(item));
153
+ result.push(...toNodeArray(item, ownerDocument));
150
154
  }
151
155
  return result;
152
156
  }
@@ -173,14 +177,14 @@ function toNodeArray(node) {
173
177
  }
174
178
  try {
175
179
  if (typeof node === "object" && node !== null && "marker" in node) {
176
- return toNodeArray(node.marker);
180
+ return toNodeArray(node.marker, ownerDocument);
177
181
  }
178
182
  } catch {
179
183
  }
180
184
  try {
181
- return [document.createTextNode(String(node))];
185
+ return [ownerDocument.createTextNode(String(node))];
182
186
  } catch {
183
- return [document.createTextNode("")];
187
+ return [ownerDocument.createTextNode("")];
184
188
  }
185
189
  }
186
190
  function insertNodesBefore(parent, nodes, anchor) {
@@ -488,8 +492,9 @@ function callEventHandler(handler, event, node, data) {
488
492
  };
489
493
  invoke(handler);
490
494
  }
491
- function createTextBinding(value) {
492
- const text = document.createTextNode("");
495
+ function createTextBinding(value, owner) {
496
+ const textOwnerDocument = owner && "nodeType" in owner ? owner.nodeType === 9 ? owner : owner.ownerDocument ?? document : document;
497
+ const text = textOwnerDocument.createTextNode("");
493
498
  if (isReactive(value)) {
494
499
  createRenderEffect(() => {
495
500
  setText(text, value());
@@ -704,6 +709,7 @@ function classList(node, value, prev = {}) {
704
709
  }
705
710
  function insert(parent, getValue, markerOrCreateElement, createElementFn) {
706
711
  const hostRoot = getCurrentRoot();
712
+ const parentOwnerDocument = parent.ownerDocument ?? document;
707
713
  let marker;
708
714
  let ownsMarker = false;
709
715
  let createFn = createElementFn;
@@ -711,11 +717,12 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
711
717
  marker = markerOrCreateElement;
712
718
  createFn = createElementFn;
713
719
  } else {
714
- marker = document.createComment("fict:insert");
720
+ marker = parentOwnerDocument.createComment("fict:insert");
715
721
  parent.appendChild(marker);
716
722
  createFn = markerOrCreateElement;
717
723
  ownsMarker = true;
718
724
  }
725
+ const markerOwnerDocument = marker.ownerDocument ?? parentOwnerDocument;
719
726
  let currentNodes = [];
720
727
  let currentText = null;
721
728
  let currentRoot = null;
@@ -727,7 +734,7 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
727
734
  };
728
735
  const setTextNode = (textValue, shouldInsert, parentNode) => {
729
736
  if (!currentText) {
730
- currentText = document.createTextNode(textValue);
737
+ currentText = (parentNode.ownerDocument ?? markerOwnerDocument).createTextNode(textValue);
731
738
  } else if (currentText.data !== textValue) {
732
739
  currentText.data = textValue;
733
740
  }
@@ -771,6 +778,7 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
771
778
  let handledError = false;
772
779
  try {
773
780
  let newNode;
781
+ const ownerDocument = parentNode?.ownerDocument ?? markerOwnerDocument;
774
782
  if (value instanceof Node) {
775
783
  newNode = value;
776
784
  } else if (Array.isArray(value)) {
@@ -780,17 +788,17 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
780
788
  if (createFn) {
781
789
  const mapped = [];
782
790
  for (const item of value) {
783
- mapped.push(...toNodeArray(createFn(item)));
791
+ mapped.push(...toNodeArray(createFn(item), ownerDocument));
784
792
  }
785
793
  newNode = mapped;
786
794
  } else {
787
- newNode = document.createTextNode(String(value));
795
+ newNode = ownerDocument.createTextNode(String(value));
788
796
  }
789
797
  }
790
798
  } else {
791
- newNode = createFn ? createFn(value) : document.createTextNode(String(value));
799
+ newNode = createFn ? createFn(value) : ownerDocument.createTextNode(String(value));
792
800
  }
793
- nodes = toNodeArray(newNode);
801
+ nodes = toNodeArray(newNode, ownerDocument);
794
802
  if (root.suspended) {
795
803
  handledError = true;
796
804
  destroyRoot(root);
@@ -834,6 +842,7 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
834
842
  }
835
843
  function insertBetween(start, end, getValue, createElementFn) {
836
844
  const hostRoot = getCurrentRoot();
845
+ const markerOwnerDocument = start.ownerDocument ?? end.ownerDocument ?? document;
837
846
  let currentNodes = [];
838
847
  let currentText = null;
839
848
  let currentRoot = null;
@@ -854,8 +863,9 @@ function insertBetween(start, end, getValue, createElementFn) {
854
863
  }
855
864
  };
856
865
  const setTextNode = (textValue, shouldInsert) => {
866
+ const parentNode = start.parentNode;
857
867
  if (!currentText) {
858
- currentText = document.createTextNode(textValue);
868
+ currentText = (parentNode?.ownerDocument ?? markerOwnerDocument).createTextNode(textValue);
859
869
  } else if (currentText.data !== textValue) {
860
870
  currentText.data = textValue;
861
871
  }
@@ -867,7 +877,6 @@ function insertBetween(start, end, getValue, createElementFn) {
867
877
  return;
868
878
  }
869
879
  clearCurrentNodes();
870
- const parentNode = start.parentNode;
871
880
  if (parentNode) {
872
881
  insertNodesBefore(parentNode, [currentText], end);
873
882
  currentNodes = [currentText];
@@ -911,6 +920,7 @@ function insertBetween(start, end, getValue, createElementFn) {
911
920
  let handledError = false;
912
921
  try {
913
922
  let newNode = void 0;
923
+ const ownerDocument = parentNode?.ownerDocument ?? markerOwnerDocument;
914
924
  const createValue = () => {
915
925
  if (value instanceof Node) {
916
926
  return value;
@@ -922,22 +932,27 @@ function insertBetween(start, end, getValue, createElementFn) {
922
932
  if (createElementFn) {
923
933
  const mapped = [];
924
934
  for (const item of value) {
925
- mapped.push(...toNodeArray(createElementFn(item)));
935
+ mapped.push(...toNodeArray(createElementFn(item), ownerDocument));
926
936
  }
927
937
  return mapped;
928
938
  }
929
- return document.createTextNode(String(value));
939
+ return ownerDocument.createTextNode(String(value));
930
940
  }
931
- return createElementFn ? createElementFn(value) : document.createTextNode(String(value));
941
+ return createElementFn ? createElementFn(value) : ownerDocument.createTextNode(String(value));
932
942
  };
933
943
  if (initialHydrating && isHydratingActive() && parentNode) {
934
- withHydrationRange(start.nextSibling, end, parentNode.ownerDocument ?? document, () => {
935
- newNode = createValue();
936
- });
944
+ withHydrationRange(
945
+ start.nextSibling,
946
+ end,
947
+ parentNode.ownerDocument ?? markerOwnerDocument,
948
+ () => {
949
+ newNode = createValue();
950
+ }
951
+ );
937
952
  } else {
938
953
  newNode = createValue();
939
954
  }
940
- nodes = toNodeArray(newNode);
955
+ nodes = toNodeArray(newNode, ownerDocument);
941
956
  if (root.suspended) {
942
957
  handledError = true;
943
958
  destroyRoot(root);
@@ -978,7 +993,7 @@ function insertBetween(start, end, getValue, createElementFn) {
978
993
  };
979
994
  }
980
995
  function createChildBinding(parent, getValue, createElementFn) {
981
- const marker = document.createComment("fict:child");
996
+ const marker = (parent.ownerDocument ?? document).createComment("fict:child");
982
997
  parent.appendChild(marker);
983
998
  const hostRoot = getCurrentRoot();
984
999
  const dispose = createRenderEffect(() => {
@@ -992,7 +1007,7 @@ function createChildBinding(parent, getValue, createElementFn) {
992
1007
  return;
993
1008
  }
994
1009
  const output = createElementFn(value);
995
- nodes = toNodeArray(output);
1010
+ nodes = toNodeArray(output, marker.ownerDocument ?? parent.ownerDocument ?? document);
996
1011
  const parentNode = marker.parentNode;
997
1012
  if (parentNode) {
998
1013
  insertNodesBefore(parentNode, nodes, marker);
@@ -1110,7 +1125,7 @@ function globalEventHandler(e) {
1110
1125
  Object.defineProperty(e, "currentTarget", {
1111
1126
  configurable: true,
1112
1127
  get() {
1113
- return node || document;
1128
+ return node || oriCurrentTarget || asNode(oriTarget)?.ownerDocument || document;
1114
1129
  }
1115
1130
  });
1116
1131
  if (e.composedPath) {
@@ -1377,15 +1392,16 @@ function toPropertyName(name) {
1377
1392
  }
1378
1393
  function createConditional(condition, renderTrue, createElementFn, renderFalse, startOverride, endOverride, options) {
1379
1394
  const trackBranchReads = options?.trackBranchReads === true;
1395
+ const hostRoot = getCurrentRoot();
1380
1396
  const useProvided = !!(startOverride && endOverride);
1381
- const startMarker = useProvided ? startOverride : document.createComment("fict:cond:start");
1382
- const endMarker = useProvided ? endOverride : document.createComment("fict:cond:end");
1383
- const fragment = useProvided ? startMarker : document.createDocumentFragment();
1397
+ const markerOwnerDocument = startOverride?.ownerDocument ?? endOverride?.ownerDocument ?? hostRoot?.ownerDocument ?? document;
1398
+ const startMarker = useProvided ? startOverride : markerOwnerDocument.createComment("fict:cond:start");
1399
+ const endMarker = useProvided ? endOverride : markerOwnerDocument.createComment("fict:cond:end");
1400
+ const fragment = useProvided ? startMarker : markerOwnerDocument.createDocumentFragment();
1384
1401
  if (!useProvided) {
1385
1402
  ;
1386
1403
  fragment.append(startMarker, endMarker);
1387
1404
  }
1388
- const hostRoot = getCurrentRoot();
1389
1405
  let currentNodes = [];
1390
1406
  let currentRoot = null;
1391
1407
  let lastCondition = void 0;
@@ -1424,7 +1440,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1424
1440
  withHydrationRange(
1425
1441
  startMarker.nextSibling,
1426
1442
  endMarker,
1427
- parent.ownerDocument ?? document,
1443
+ parent.ownerDocument ?? markerOwnerDocument,
1428
1444
  () => {
1429
1445
  const output = trackBranchReads ? render3() : untrack(render3);
1430
1446
  if (output == null || output === false) {
@@ -1523,7 +1539,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1523
1539
  return;
1524
1540
  }
1525
1541
  const el = createElementFn(scratchOutput);
1526
- const nodes = toNodeArray(el);
1542
+ const nodes = toNodeArray(el, parent.ownerDocument ?? markerOwnerDocument);
1527
1543
  insertNodesBefore(parent, nodes, endMarker);
1528
1544
  currentNodes = nodes;
1529
1545
  } catch (err) {
@@ -1569,7 +1585,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1569
1585
  return;
1570
1586
  }
1571
1587
  const el = createElementFn(output);
1572
- const nodes = toNodeArray(el);
1588
+ const nodes = toNodeArray(el, parent.ownerDocument ?? markerOwnerDocument);
1573
1589
  insertNodesBefore(parent, nodes, endMarker);
1574
1590
  currentNodes = nodes;
1575
1591
  } catch (err) {
@@ -1622,7 +1638,8 @@ function createShow(el, condition, displayValue) {
1622
1638
  }
1623
1639
  function createPortal(container, render2, createElementFn) {
1624
1640
  const parentRoot = getCurrentRoot();
1625
- const marker = document.createComment("fict:portal");
1641
+ const markerOwnerDocument = container.ownerDocument ?? document;
1642
+ const marker = markerOwnerDocument.createComment("fict:portal");
1626
1643
  container.appendChild(marker);
1627
1644
  let currentNodes = [];
1628
1645
  let currentRoot = null;
@@ -1636,13 +1653,14 @@ function createPortal(container, render2, createElementFn) {
1636
1653
  currentNodes = [];
1637
1654
  }
1638
1655
  const root = createRootContext(parentRoot);
1656
+ root.ownerDocument = container.ownerDocument ?? parentRoot?.ownerDocument ?? document;
1639
1657
  const prev = pushRoot(root);
1640
1658
  let handledError = false;
1641
1659
  try {
1642
1660
  const output = render2();
1643
1661
  if (output != null && output !== false) {
1644
1662
  const el = createElementFn(output);
1645
- const nodes = toNodeArray(el);
1663
+ const nodes = toNodeArray(el, markerOwnerDocument);
1646
1664
  if (marker.parentNode) {
1647
1665
  insertNodesBefore(marker.parentNode, nodes, marker);
1648
1666
  }
@@ -1996,8 +2014,35 @@ var SVG_NS = "http://www.w3.org/2000/svg";
1996
2014
  var MATHML_NS = "http://www.w3.org/1998/Math/MathML";
1997
2015
  var isDev2 = typeof __DEV__ !== "undefined" ? __DEV__ : typeof process !== "undefined" && process.env?.NODE_ENV !== "production";
1998
2016
  var nextComponentId = 1;
2017
+ function collectComponentMountElements(node) {
2018
+ if (node instanceof DocumentFragment) {
2019
+ return Array.from(node.childNodes).filter(
2020
+ (child) => child instanceof HTMLElement
2021
+ );
2022
+ }
2023
+ if (node instanceof HTMLElement) {
2024
+ if (node.hasAttribute("data-fict-host")) {
2025
+ const children = Array.from(node.children).filter(
2026
+ (child) => child instanceof HTMLElement
2027
+ );
2028
+ if (children.length > 0) return children;
2029
+ }
2030
+ return [node];
2031
+ }
2032
+ return [];
2033
+ }
2034
+ function annotateComponentElements(elements, componentId, componentName) {
2035
+ for (const element of elements) {
2036
+ element.setAttribute("data-fict-component", componentName);
2037
+ element.setAttribute("data-fict-component-id", String(componentId));
2038
+ const annotated = element;
2039
+ annotated.__fict_component_id__ = componentId;
2040
+ annotated.__fict_component_name__ = componentName;
2041
+ }
2042
+ }
1999
2043
  function render(view, container) {
2000
2044
  const root = createRootContext();
2045
+ root.ownerDocument = container.ownerDocument ?? document;
2001
2046
  const prev = pushRoot(root);
2002
2047
  let dom = void 0;
2003
2048
  try {
@@ -2025,6 +2070,7 @@ function render(view, container) {
2025
2070
  }
2026
2071
  function hydrateComponent(view, container) {
2027
2072
  const root = createRootContext();
2073
+ root.ownerDocument = container.ownerDocument ?? document;
2028
2074
  const prev = pushRoot(root);
2029
2075
  __fictEnterHydration();
2030
2076
  try {
@@ -2043,7 +2089,7 @@ function hydrateComponent(view, container) {
2043
2089
  return teardown;
2044
2090
  }
2045
2091
  function createElement(node) {
2046
- return createElementWithContext(node, null);
2092
+ return createElementWithContext(node, null, resolveOwnerDocument());
2047
2093
  }
2048
2094
  function resolveNamespace(tagName, namespace) {
2049
2095
  if (tagName === "svg") return "svg";
@@ -2053,22 +2099,25 @@ function resolveNamespace(tagName, namespace) {
2053
2099
  if (isDev2 && SVGElements.has(tagName)) return "svg";
2054
2100
  return null;
2055
2101
  }
2056
- function createElementWithContext(node, namespace) {
2102
+ function resolveOwnerDocument(ownerDocument) {
2103
+ return ownerDocument ?? getCurrentRoot()?.ownerDocument ?? document;
2104
+ }
2105
+ function createElementWithContext(node, namespace, ownerDocument) {
2057
2106
  if (node instanceof Node) {
2058
2107
  return node;
2059
2108
  }
2060
2109
  if (node === null || node === void 0 || node === false) {
2061
- return document.createTextNode("");
2110
+ return ownerDocument.createTextNode("");
2062
2111
  }
2063
2112
  if (isReactive(node)) {
2064
2113
  const resolved = node();
2065
2114
  if (resolved === node) {
2066
- return document.createTextNode("");
2115
+ return ownerDocument.createTextNode("");
2067
2116
  }
2068
- return createElementWithContext(resolved, namespace);
2117
+ return createElementWithContext(resolved, namespace, ownerDocument);
2069
2118
  }
2070
2119
  if (typeof node === "function") {
2071
- return document.createTextNode("");
2120
+ return ownerDocument.createTextNode("");
2072
2121
  }
2073
2122
  if (typeof node === "object" && node !== null && !(node instanceof Node)) {
2074
2123
  if ("marker" in node) {
@@ -2084,21 +2133,21 @@ function createElementWithContext(node, namespace) {
2084
2133
  Promise.resolve().then(runFlush).catch(() => void 0);
2085
2134
  }
2086
2135
  }
2087
- return createElement(handle.marker);
2136
+ return createElementWithContext(handle.marker, namespace, ownerDocument);
2088
2137
  }
2089
2138
  }
2090
2139
  if (Array.isArray(node)) {
2091
- const frag = document.createDocumentFragment();
2140
+ const frag = ownerDocument.createDocumentFragment();
2092
2141
  for (const child of node) {
2093
- appendChildNode(frag, child, namespace);
2142
+ appendChildNode(frag, child, namespace, ownerDocument);
2094
2143
  }
2095
2144
  return frag;
2096
2145
  }
2097
2146
  if (typeof node === "string" || typeof node === "number") {
2098
- return document.createTextNode(String(node));
2147
+ return ownerDocument.createTextNode(String(node));
2099
2148
  }
2100
2149
  if (typeof node === "boolean") {
2101
- return document.createTextNode("");
2150
+ return ownerDocument.createTextNode("");
2102
2151
  }
2103
2152
  const vnode = node;
2104
2153
  if (typeof vnode.type === "function") {
@@ -2126,10 +2175,11 @@ function createElementWithContext(node, namespace) {
2126
2175
  });
2127
2176
  const props = createPropsProxy(baseProps);
2128
2177
  const hook = isDev2 ? getDevtoolsHook() : void 0;
2178
+ const componentName = vnode.type.name || "Anonymous";
2129
2179
  const parentId = hook ? __fictGetCurrentComponentId() : void 0;
2130
2180
  const componentId = hook ? nextComponentId++ : void 0;
2131
2181
  if (hook?.registerComponent && componentId !== void 0) {
2132
- hook.registerComponent(componentId, vnode.type.name || "Anonymous", parentId);
2182
+ hook.registerComponent(componentId, componentName, parentId);
2133
2183
  }
2134
2184
  const ctx = __fictPushContext();
2135
2185
  if (componentId !== void 0) {
@@ -2140,15 +2190,19 @@ function createElementWithContext(node, namespace) {
2140
2190
  }
2141
2191
  try {
2142
2192
  const rendered = vnode.type(props);
2193
+ let mountElements;
2194
+ if (hook && componentId !== void 0) {
2195
+ hook.componentRender?.(componentId);
2196
+ }
2143
2197
  if (hook && componentId !== void 0) {
2144
2198
  onMount(() => {
2145
- hook.componentMount?.(componentId);
2199
+ hook.componentMount?.(componentId, mountElements);
2146
2200
  });
2147
2201
  onCleanup(() => hook.componentUnmount?.(componentId));
2148
2202
  }
2149
2203
  if (__fictIsResumable() && !__fictIsHydrating()) {
2150
- const content = createElementWithContext(rendered, namespace);
2151
- const host = namespace === "svg" ? document.createElementNS(SVG_NS, "fict-host") : namespace === "mathml" ? document.createElementNS(MATHML_NS, "fict-host") : document.createElement("fict-host");
2204
+ const content = createElementWithContext(rendered, namespace, ownerDocument);
2205
+ const host = namespace === "svg" ? ownerDocument.createElementNS(SVG_NS, "fict-host") : namespace === "mathml" ? ownerDocument.createElementNS(MATHML_NS, "fict-host") : ownerDocument.createElement("fict-host");
2152
2206
  host.setAttribute("data-fict-host", "");
2153
2207
  if (namespace === null && host.style) {
2154
2208
  ;
@@ -2165,12 +2219,21 @@ function createElementWithContext(node, namespace) {
2165
2219
  } else {
2166
2220
  host.appendChild(content);
2167
2221
  }
2222
+ if (hook && componentId !== void 0) {
2223
+ mountElements = collectComponentMountElements(host);
2224
+ annotateComponentElements(mountElements, componentId, componentName);
2225
+ }
2168
2226
  return host;
2169
2227
  }
2170
- return createElementWithContext(rendered, namespace);
2228
+ const componentRoot = createElementWithContext(rendered, namespace, ownerDocument);
2229
+ if (hook && componentId !== void 0) {
2230
+ mountElements = collectComponentMountElements(componentRoot);
2231
+ annotateComponentElements(mountElements, componentId, componentName);
2232
+ }
2233
+ return componentRoot;
2171
2234
  } catch (err) {
2172
2235
  if (handleSuspend(err)) {
2173
- return document.createComment("fict:suspend");
2236
+ return ownerDocument.createComment("fict:suspend");
2174
2237
  }
2175
2238
  handleError(err, { source: "render", componentName: vnode.type.name });
2176
2239
  throw err;
@@ -2179,26 +2242,27 @@ function createElementWithContext(node, namespace) {
2179
2242
  }
2180
2243
  }
2181
2244
  if (vnode.type === Fragment) {
2182
- const frag = document.createDocumentFragment();
2245
+ const frag = ownerDocument.createDocumentFragment();
2183
2246
  const children = vnode.props?.children;
2184
- appendChildren(frag, children, namespace);
2247
+ appendChildren(frag, children, namespace, ownerDocument);
2185
2248
  return frag;
2186
2249
  }
2187
2250
  const tagName = typeof vnode.type === "string" ? vnode.type : "div";
2188
2251
  const resolvedNamespace = resolveNamespace(tagName, namespace);
2189
- const el = resolvedNamespace === "svg" ? document.createElementNS(SVG_NS, tagName) : resolvedNamespace === "mathml" ? document.createElementNS(MATHML_NS, tagName) : document.createElement(tagName);
2252
+ const el = resolvedNamespace === "svg" ? ownerDocument.createElementNS(SVG_NS, tagName) : resolvedNamespace === "mathml" ? ownerDocument.createElementNS(MATHML_NS, tagName) : ownerDocument.createElement(tagName);
2190
2253
  applyProps(el, vnode.props ?? {}, resolvedNamespace === "svg");
2191
2254
  appendChildren(
2192
2255
  el,
2193
2256
  vnode.props?.children,
2194
- tagName === "foreignObject" ? null : resolvedNamespace
2257
+ tagName === "foreignObject" ? null : resolvedNamespace,
2258
+ ownerDocument
2195
2259
  );
2196
2260
  return el;
2197
2261
  }
2198
2262
  function template(html, isImportNode, isSVG, isMathML) {
2199
- let node = null;
2200
- const create = () => {
2201
- const t = document.createElement("template");
2263
+ const nodeByDocument = /* @__PURE__ */ new WeakMap();
2264
+ const create = (ownerDocument) => {
2265
+ const t = ownerDocument.createElement("template");
2202
2266
  if (isSVG) {
2203
2267
  t.innerHTML = `<svg>${html}</svg>`;
2204
2268
  const wrapper = t.content.firstChild;
@@ -2210,7 +2274,7 @@ function template(html, isImportNode, isSVG, isMathML) {
2210
2274
  if (wrapper.childNodes.length === 1) {
2211
2275
  return wrapper.firstChild;
2212
2276
  }
2213
- const fragment = document.createDocumentFragment();
2277
+ const fragment = ownerDocument.createDocumentFragment();
2214
2278
  fragment.append(...Array.from(wrapper.childNodes));
2215
2279
  return fragment;
2216
2280
  }
@@ -2225,7 +2289,7 @@ function template(html, isImportNode, isSVG, isMathML) {
2225
2289
  if (wrapper.childNodes.length === 1) {
2226
2290
  return wrapper.firstChild;
2227
2291
  }
2228
- const fragment = document.createDocumentFragment();
2292
+ const fragment = ownerDocument.createDocumentFragment();
2229
2293
  fragment.append(...Array.from(wrapper.childNodes));
2230
2294
  return fragment;
2231
2295
  }
@@ -2241,11 +2305,19 @@ function template(html, isImportNode, isSVG, isMathML) {
2241
2305
  }
2242
2306
  return content;
2243
2307
  };
2308
+ const getBase = (ownerDocument) => {
2309
+ const cached = nodeByDocument.get(ownerDocument);
2310
+ if (cached) return cached;
2311
+ const created = create(ownerDocument);
2312
+ nodeByDocument.set(ownerDocument, created);
2313
+ return created;
2314
+ };
2244
2315
  const fn = isImportNode ? () => untrack2(() => {
2245
- const base = node || (node = create());
2246
- return isHydratingActive() ? claimNodes(base, () => document.importNode(base, true)) : document.importNode(base, true);
2316
+ const ownerDocument = resolveOwnerDocument();
2317
+ const base = getBase(ownerDocument);
2318
+ return isHydratingActive() ? claimNodes(base, () => ownerDocument.importNode(base, true)) : ownerDocument.importNode(base, true);
2247
2319
  }) : () => {
2248
- const base = node || (node = create());
2320
+ const base = getBase(resolveOwnerDocument());
2249
2321
  return isHydratingActive() ? claimNodes(base, () => base.cloneNode(true)) : base.cloneNode(true);
2250
2322
  };
2251
2323
  fn.cloneNode = fn;
@@ -2254,39 +2326,44 @@ function template(html, isImportNode, isSVG, isMathML) {
2254
2326
  function isBindingHandle(node) {
2255
2327
  return node !== null && typeof node === "object" && "marker" in node && "dispose" in node && typeof node.dispose === "function";
2256
2328
  }
2257
- function appendChildNode(parent, child, namespace) {
2329
+ function appendChildNode(parent, child, namespace, ownerDocument) {
2330
+ const parentOwnerDocument = parent.ownerDocument ?? ownerDocument;
2258
2331
  if (child === null || child === void 0 || child === false) {
2259
2332
  return;
2260
2333
  }
2261
2334
  if (isBindingHandle(child)) {
2262
- appendChildNode(parent, child.marker, namespace);
2335
+ appendChildNode(parent, child.marker, namespace, parentOwnerDocument);
2263
2336
  child.flush?.();
2264
2337
  return;
2265
2338
  }
2266
2339
  if (typeof child === "function") {
2267
2340
  const childGetter = child;
2268
2341
  if (isReactive(childGetter)) {
2269
- createChildBinding(parent, childGetter, (node) => createElementWithContext(node, namespace));
2342
+ createChildBinding(
2343
+ parent,
2344
+ childGetter,
2345
+ (node) => createElementWithContext(node, namespace, parentOwnerDocument)
2346
+ );
2270
2347
  return;
2271
2348
  }
2272
2349
  return;
2273
2350
  }
2274
2351
  if (Array.isArray(child)) {
2275
2352
  for (const item of child) {
2276
- appendChildNode(parent, item, namespace);
2353
+ appendChildNode(parent, item, namespace, parentOwnerDocument);
2277
2354
  }
2278
2355
  return;
2279
2356
  }
2280
2357
  let domNode;
2281
2358
  if (typeof child !== "object" || child === null) {
2282
- domNode = document.createTextNode(String(child ?? ""));
2359
+ domNode = parentOwnerDocument.createTextNode(String(child ?? ""));
2283
2360
  } else {
2284
- domNode = createElementWithContext(child, namespace);
2361
+ domNode = createElementWithContext(child, namespace, parentOwnerDocument);
2285
2362
  }
2286
2363
  if (domNode.nodeType === 11) {
2287
2364
  const children = Array.from(domNode.childNodes);
2288
2365
  for (const node of children) {
2289
- appendChildNode(parent, node, namespace);
2366
+ appendChildNode(parent, node, namespace, parentOwnerDocument);
2290
2367
  }
2291
2368
  return;
2292
2369
  }
@@ -2304,15 +2381,15 @@ function appendChildNode(parent, child, namespace) {
2304
2381
  throw e;
2305
2382
  }
2306
2383
  }
2307
- function appendChildren(parent, children, namespace) {
2384
+ function appendChildren(parent, children, namespace, ownerDocument) {
2308
2385
  if (children === void 0) return;
2309
2386
  if (Array.isArray(children)) {
2310
2387
  for (const child of children) {
2311
- appendChildren(parent, child, namespace);
2388
+ appendChildren(parent, child, namespace, ownerDocument);
2312
2389
  }
2313
2390
  return;
2314
2391
  }
2315
- appendChildNode(parent, children, namespace);
2392
+ appendChildNode(parent, children, namespace, ownerDocument);
2316
2393
  }
2317
2394
  function applyRef(el, value) {
2318
2395
  if (typeof value === "function") {
@@ -2584,4 +2661,4 @@ export {
2584
2661
  createElement,
2585
2662
  template
2586
2663
  };
2587
- //# sourceMappingURL=chunk-T2LNV5Q5.js.map
2664
+ //# sourceMappingURL=chunk-WIHNVN6L.js.map