@fictjs/runtime 0.10.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 (72) hide show
  1. package/dist/advanced.cjs +9 -9
  2. package/dist/advanced.d.cts +3 -3
  3. package/dist/advanced.d.ts +3 -3
  4. package/dist/advanced.js +4 -4
  5. package/dist/{binding-DqxS9ZQf.d.ts → binding-DcnhUSQK.d.ts} +1 -1
  6. package/dist/{binding-DUEukRxl.d.cts → binding-FRyTeLDn.d.cts} +1 -1
  7. package/dist/{chunk-DKA2I6ET.js → chunk-2UR2UWE2.js} +3 -3
  8. package/dist/{chunk-SZLJCQFZ.cjs → chunk-44EQF3AR.cjs} +63 -52
  9. package/dist/chunk-44EQF3AR.cjs.map +1 -0
  10. package/dist/{chunk-I4GKKAAY.cjs → chunk-4QGEN5SJ.cjs} +295 -262
  11. package/dist/chunk-4QGEN5SJ.cjs.map +1 -0
  12. package/dist/{chunk-V7BC64W2.cjs → chunk-C5IE4WUG.cjs} +8 -8
  13. package/dist/{chunk-V7BC64W2.cjs.map → chunk-C5IE4WUG.cjs.map} +1 -1
  14. package/dist/{chunk-F4RVNXOL.js → chunk-DIK33H5U.js} +8 -2
  15. package/dist/chunk-DIK33H5U.js.map +1 -0
  16. package/dist/{chunk-2JRPPCG7.js → chunk-FESAXMHT.js} +7 -6
  17. package/dist/{chunk-2JRPPCG7.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-EQ5E4WOV.cjs → chunk-QNMYVXRL.cjs} +44 -38
  21. package/dist/chunk-QNMYVXRL.cjs.map +1 -0
  22. package/dist/{chunk-P4TZLFV6.js → chunk-S63VBIWN.js} +27 -16
  23. package/dist/chunk-S63VBIWN.js.map +1 -0
  24. package/dist/{chunk-R6FINS25.js → chunk-WIHNVN6L.js} +106 -73
  25. package/dist/chunk-WIHNVN6L.js.map +1 -0
  26. package/dist/{devtools-CMxlJUTx.d.cts → devtools-BtIkN77t.d.cts} +1 -1
  27. package/dist/{devtools-C4Hgfa-S.d.ts → devtools-D2z4llpA.d.ts} +1 -1
  28. package/dist/index.cjs +60 -58
  29. package/dist/index.cjs.map +1 -1
  30. package/dist/index.d.cts +4 -4
  31. package/dist/index.d.ts +4 -4
  32. package/dist/index.dev.js +72 -51
  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 +1 -1
  38. package/dist/internal-list.d.ts +1 -1
  39. package/dist/internal-list.js +3 -3
  40. package/dist/internal.cjs +5 -5
  41. package/dist/internal.d.cts +4 -4
  42. package/dist/internal.d.ts +4 -4
  43. package/dist/internal.js +4 -4
  44. package/dist/{list-BBzsJhrm.d.ts → list-BKM6YOPq.d.ts} +1 -1
  45. package/dist/{list-_NJCcjl1.d.cts → list-Bi8dDF8Q.d.cts} +1 -1
  46. package/dist/loader.cjs +28 -26
  47. package/dist/loader.cjs.map +1 -1
  48. package/dist/loader.js +11 -9
  49. package/dist/loader.js.map +1 -1
  50. package/dist/{props--zJ4ebbT.d.cts → props-9chMyBGb.d.cts} +1 -1
  51. package/dist/{props-BAGR7j-j.d.ts → props-D1nj2p_3.d.ts} +1 -1
  52. package/dist/{scope-CuImnvh1.d.ts → scope-BSkhJr0a.d.ts} +1 -1
  53. package/dist/{scope-Dq5hOu7c.d.cts → scope-Bn3sxem5.d.cts} +1 -1
  54. package/package.json +1 -1
  55. package/src/binding.ts +59 -29
  56. package/src/context.ts +4 -3
  57. package/src/dom.ts +65 -39
  58. package/src/error-boundary.ts +5 -5
  59. package/src/lifecycle.ts +8 -1
  60. package/src/list-helpers.ts +30 -13
  61. package/src/loader.ts +10 -8
  62. package/src/node-ops.ts +8 -5
  63. package/src/suspense.ts +5 -4
  64. package/dist/chunk-EQ5E4WOV.cjs.map +0 -1
  65. package/dist/chunk-F4RVNXOL.js.map +0 -1
  66. package/dist/chunk-I4GKKAAY.cjs.map +0 -1
  67. package/dist/chunk-K3DH5SD5.cjs +0 -111
  68. package/dist/chunk-K3DH5SD5.cjs.map +0 -1
  69. package/dist/chunk-P4TZLFV6.js.map +0 -1
  70. package/dist/chunk-R6FINS25.js.map +0 -1
  71. package/dist/chunk-SZLJCQFZ.cjs.map +0 -1
  72. /package/dist/{chunk-DKA2I6ET.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-F4RVNXOL.js";
43
+ } from "./chunk-DIK33H5U.js";
44
44
 
45
45
  // src/transition.ts
46
46
  function startTransition(fn) {
@@ -129,7 +129,7 @@ function untrack2(fn) {
129
129
  var Fragment = Symbol("Fragment");
130
130
 
131
131
  // src/node-ops.ts
132
- function toNodeArray(node) {
132
+ function toNodeArray(node, ownerDocument = document) {
133
133
  try {
134
134
  if (Array.isArray(node)) {
135
135
  let allNodes = true;
@@ -150,7 +150,7 @@ function toNodeArray(node) {
150
150
  }
151
151
  const result = [];
152
152
  for (const item of node) {
153
- result.push(...toNodeArray(item));
153
+ result.push(...toNodeArray(item, ownerDocument));
154
154
  }
155
155
  return result;
156
156
  }
@@ -177,14 +177,14 @@ function toNodeArray(node) {
177
177
  }
178
178
  try {
179
179
  if (typeof node === "object" && node !== null && "marker" in node) {
180
- return toNodeArray(node.marker);
180
+ return toNodeArray(node.marker, ownerDocument);
181
181
  }
182
182
  } catch {
183
183
  }
184
184
  try {
185
- return [document.createTextNode(String(node))];
185
+ return [ownerDocument.createTextNode(String(node))];
186
186
  } catch {
187
- return [document.createTextNode("")];
187
+ return [ownerDocument.createTextNode("")];
188
188
  }
189
189
  }
190
190
  function insertNodesBefore(parent, nodes, anchor) {
@@ -492,8 +492,9 @@ function callEventHandler(handler, event, node, data) {
492
492
  };
493
493
  invoke(handler);
494
494
  }
495
- function createTextBinding(value) {
496
- 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("");
497
498
  if (isReactive(value)) {
498
499
  createRenderEffect(() => {
499
500
  setText(text, value());
@@ -708,6 +709,7 @@ function classList(node, value, prev = {}) {
708
709
  }
709
710
  function insert(parent, getValue, markerOrCreateElement, createElementFn) {
710
711
  const hostRoot = getCurrentRoot();
712
+ const parentOwnerDocument = parent.ownerDocument ?? document;
711
713
  let marker;
712
714
  let ownsMarker = false;
713
715
  let createFn = createElementFn;
@@ -715,11 +717,12 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
715
717
  marker = markerOrCreateElement;
716
718
  createFn = createElementFn;
717
719
  } else {
718
- marker = document.createComment("fict:insert");
720
+ marker = parentOwnerDocument.createComment("fict:insert");
719
721
  parent.appendChild(marker);
720
722
  createFn = markerOrCreateElement;
721
723
  ownsMarker = true;
722
724
  }
725
+ const markerOwnerDocument = marker.ownerDocument ?? parentOwnerDocument;
723
726
  let currentNodes = [];
724
727
  let currentText = null;
725
728
  let currentRoot = null;
@@ -731,7 +734,7 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
731
734
  };
732
735
  const setTextNode = (textValue, shouldInsert, parentNode) => {
733
736
  if (!currentText) {
734
- currentText = document.createTextNode(textValue);
737
+ currentText = (parentNode.ownerDocument ?? markerOwnerDocument).createTextNode(textValue);
735
738
  } else if (currentText.data !== textValue) {
736
739
  currentText.data = textValue;
737
740
  }
@@ -775,6 +778,7 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
775
778
  let handledError = false;
776
779
  try {
777
780
  let newNode;
781
+ const ownerDocument = parentNode?.ownerDocument ?? markerOwnerDocument;
778
782
  if (value instanceof Node) {
779
783
  newNode = value;
780
784
  } else if (Array.isArray(value)) {
@@ -784,17 +788,17 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
784
788
  if (createFn) {
785
789
  const mapped = [];
786
790
  for (const item of value) {
787
- mapped.push(...toNodeArray(createFn(item)));
791
+ mapped.push(...toNodeArray(createFn(item), ownerDocument));
788
792
  }
789
793
  newNode = mapped;
790
794
  } else {
791
- newNode = document.createTextNode(String(value));
795
+ newNode = ownerDocument.createTextNode(String(value));
792
796
  }
793
797
  }
794
798
  } else {
795
- newNode = createFn ? createFn(value) : document.createTextNode(String(value));
799
+ newNode = createFn ? createFn(value) : ownerDocument.createTextNode(String(value));
796
800
  }
797
- nodes = toNodeArray(newNode);
801
+ nodes = toNodeArray(newNode, ownerDocument);
798
802
  if (root.suspended) {
799
803
  handledError = true;
800
804
  destroyRoot(root);
@@ -838,6 +842,7 @@ function insert(parent, getValue, markerOrCreateElement, createElementFn) {
838
842
  }
839
843
  function insertBetween(start, end, getValue, createElementFn) {
840
844
  const hostRoot = getCurrentRoot();
845
+ const markerOwnerDocument = start.ownerDocument ?? end.ownerDocument ?? document;
841
846
  let currentNodes = [];
842
847
  let currentText = null;
843
848
  let currentRoot = null;
@@ -858,8 +863,9 @@ function insertBetween(start, end, getValue, createElementFn) {
858
863
  }
859
864
  };
860
865
  const setTextNode = (textValue, shouldInsert) => {
866
+ const parentNode = start.parentNode;
861
867
  if (!currentText) {
862
- currentText = document.createTextNode(textValue);
868
+ currentText = (parentNode?.ownerDocument ?? markerOwnerDocument).createTextNode(textValue);
863
869
  } else if (currentText.data !== textValue) {
864
870
  currentText.data = textValue;
865
871
  }
@@ -871,7 +877,6 @@ function insertBetween(start, end, getValue, createElementFn) {
871
877
  return;
872
878
  }
873
879
  clearCurrentNodes();
874
- const parentNode = start.parentNode;
875
880
  if (parentNode) {
876
881
  insertNodesBefore(parentNode, [currentText], end);
877
882
  currentNodes = [currentText];
@@ -915,6 +920,7 @@ function insertBetween(start, end, getValue, createElementFn) {
915
920
  let handledError = false;
916
921
  try {
917
922
  let newNode = void 0;
923
+ const ownerDocument = parentNode?.ownerDocument ?? markerOwnerDocument;
918
924
  const createValue = () => {
919
925
  if (value instanceof Node) {
920
926
  return value;
@@ -926,22 +932,27 @@ function insertBetween(start, end, getValue, createElementFn) {
926
932
  if (createElementFn) {
927
933
  const mapped = [];
928
934
  for (const item of value) {
929
- mapped.push(...toNodeArray(createElementFn(item)));
935
+ mapped.push(...toNodeArray(createElementFn(item), ownerDocument));
930
936
  }
931
937
  return mapped;
932
938
  }
933
- return document.createTextNode(String(value));
939
+ return ownerDocument.createTextNode(String(value));
934
940
  }
935
- return createElementFn ? createElementFn(value) : document.createTextNode(String(value));
941
+ return createElementFn ? createElementFn(value) : ownerDocument.createTextNode(String(value));
936
942
  };
937
943
  if (initialHydrating && isHydratingActive() && parentNode) {
938
- withHydrationRange(start.nextSibling, end, parentNode.ownerDocument ?? document, () => {
939
- newNode = createValue();
940
- });
944
+ withHydrationRange(
945
+ start.nextSibling,
946
+ end,
947
+ parentNode.ownerDocument ?? markerOwnerDocument,
948
+ () => {
949
+ newNode = createValue();
950
+ }
951
+ );
941
952
  } else {
942
953
  newNode = createValue();
943
954
  }
944
- nodes = toNodeArray(newNode);
955
+ nodes = toNodeArray(newNode, ownerDocument);
945
956
  if (root.suspended) {
946
957
  handledError = true;
947
958
  destroyRoot(root);
@@ -982,7 +993,7 @@ function insertBetween(start, end, getValue, createElementFn) {
982
993
  };
983
994
  }
984
995
  function createChildBinding(parent, getValue, createElementFn) {
985
- const marker = document.createComment("fict:child");
996
+ const marker = (parent.ownerDocument ?? document).createComment("fict:child");
986
997
  parent.appendChild(marker);
987
998
  const hostRoot = getCurrentRoot();
988
999
  const dispose = createRenderEffect(() => {
@@ -996,7 +1007,7 @@ function createChildBinding(parent, getValue, createElementFn) {
996
1007
  return;
997
1008
  }
998
1009
  const output = createElementFn(value);
999
- nodes = toNodeArray(output);
1010
+ nodes = toNodeArray(output, marker.ownerDocument ?? parent.ownerDocument ?? document);
1000
1011
  const parentNode = marker.parentNode;
1001
1012
  if (parentNode) {
1002
1013
  insertNodesBefore(parentNode, nodes, marker);
@@ -1114,7 +1125,7 @@ function globalEventHandler(e) {
1114
1125
  Object.defineProperty(e, "currentTarget", {
1115
1126
  configurable: true,
1116
1127
  get() {
1117
- return node || document;
1128
+ return node || oriCurrentTarget || asNode(oriTarget)?.ownerDocument || document;
1118
1129
  }
1119
1130
  });
1120
1131
  if (e.composedPath) {
@@ -1381,15 +1392,16 @@ function toPropertyName(name) {
1381
1392
  }
1382
1393
  function createConditional(condition, renderTrue, createElementFn, renderFalse, startOverride, endOverride, options) {
1383
1394
  const trackBranchReads = options?.trackBranchReads === true;
1395
+ const hostRoot = getCurrentRoot();
1384
1396
  const useProvided = !!(startOverride && endOverride);
1385
- const startMarker = useProvided ? startOverride : document.createComment("fict:cond:start");
1386
- const endMarker = useProvided ? endOverride : document.createComment("fict:cond:end");
1387
- 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();
1388
1401
  if (!useProvided) {
1389
1402
  ;
1390
1403
  fragment.append(startMarker, endMarker);
1391
1404
  }
1392
- const hostRoot = getCurrentRoot();
1393
1405
  let currentNodes = [];
1394
1406
  let currentRoot = null;
1395
1407
  let lastCondition = void 0;
@@ -1428,7 +1440,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1428
1440
  withHydrationRange(
1429
1441
  startMarker.nextSibling,
1430
1442
  endMarker,
1431
- parent.ownerDocument ?? document,
1443
+ parent.ownerDocument ?? markerOwnerDocument,
1432
1444
  () => {
1433
1445
  const output = trackBranchReads ? render3() : untrack(render3);
1434
1446
  if (output == null || output === false) {
@@ -1527,7 +1539,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1527
1539
  return;
1528
1540
  }
1529
1541
  const el = createElementFn(scratchOutput);
1530
- const nodes = toNodeArray(el);
1542
+ const nodes = toNodeArray(el, parent.ownerDocument ?? markerOwnerDocument);
1531
1543
  insertNodesBefore(parent, nodes, endMarker);
1532
1544
  currentNodes = nodes;
1533
1545
  } catch (err) {
@@ -1573,7 +1585,7 @@ function createConditional(condition, renderTrue, createElementFn, renderFalse,
1573
1585
  return;
1574
1586
  }
1575
1587
  const el = createElementFn(output);
1576
- const nodes = toNodeArray(el);
1588
+ const nodes = toNodeArray(el, parent.ownerDocument ?? markerOwnerDocument);
1577
1589
  insertNodesBefore(parent, nodes, endMarker);
1578
1590
  currentNodes = nodes;
1579
1591
  } catch (err) {
@@ -1626,7 +1638,8 @@ function createShow(el, condition, displayValue) {
1626
1638
  }
1627
1639
  function createPortal(container, render2, createElementFn) {
1628
1640
  const parentRoot = getCurrentRoot();
1629
- const marker = document.createComment("fict:portal");
1641
+ const markerOwnerDocument = container.ownerDocument ?? document;
1642
+ const marker = markerOwnerDocument.createComment("fict:portal");
1630
1643
  container.appendChild(marker);
1631
1644
  let currentNodes = [];
1632
1645
  let currentRoot = null;
@@ -1640,13 +1653,14 @@ function createPortal(container, render2, createElementFn) {
1640
1653
  currentNodes = [];
1641
1654
  }
1642
1655
  const root = createRootContext(parentRoot);
1656
+ root.ownerDocument = container.ownerDocument ?? parentRoot?.ownerDocument ?? document;
1643
1657
  const prev = pushRoot(root);
1644
1658
  let handledError = false;
1645
1659
  try {
1646
1660
  const output = render2();
1647
1661
  if (output != null && output !== false) {
1648
1662
  const el = createElementFn(output);
1649
- const nodes = toNodeArray(el);
1663
+ const nodes = toNodeArray(el, markerOwnerDocument);
1650
1664
  if (marker.parentNode) {
1651
1665
  insertNodesBefore(marker.parentNode, nodes, marker);
1652
1666
  }
@@ -2028,6 +2042,7 @@ function annotateComponentElements(elements, componentId, componentName) {
2028
2042
  }
2029
2043
  function render(view, container) {
2030
2044
  const root = createRootContext();
2045
+ root.ownerDocument = container.ownerDocument ?? document;
2031
2046
  const prev = pushRoot(root);
2032
2047
  let dom = void 0;
2033
2048
  try {
@@ -2055,6 +2070,7 @@ function render(view, container) {
2055
2070
  }
2056
2071
  function hydrateComponent(view, container) {
2057
2072
  const root = createRootContext();
2073
+ root.ownerDocument = container.ownerDocument ?? document;
2058
2074
  const prev = pushRoot(root);
2059
2075
  __fictEnterHydration();
2060
2076
  try {
@@ -2073,7 +2089,7 @@ function hydrateComponent(view, container) {
2073
2089
  return teardown;
2074
2090
  }
2075
2091
  function createElement(node) {
2076
- return createElementWithContext(node, null);
2092
+ return createElementWithContext(node, null, resolveOwnerDocument());
2077
2093
  }
2078
2094
  function resolveNamespace(tagName, namespace) {
2079
2095
  if (tagName === "svg") return "svg";
@@ -2083,22 +2099,25 @@ function resolveNamespace(tagName, namespace) {
2083
2099
  if (isDev2 && SVGElements.has(tagName)) return "svg";
2084
2100
  return null;
2085
2101
  }
2086
- function createElementWithContext(node, namespace) {
2102
+ function resolveOwnerDocument(ownerDocument) {
2103
+ return ownerDocument ?? getCurrentRoot()?.ownerDocument ?? document;
2104
+ }
2105
+ function createElementWithContext(node, namespace, ownerDocument) {
2087
2106
  if (node instanceof Node) {
2088
2107
  return node;
2089
2108
  }
2090
2109
  if (node === null || node === void 0 || node === false) {
2091
- return document.createTextNode("");
2110
+ return ownerDocument.createTextNode("");
2092
2111
  }
2093
2112
  if (isReactive(node)) {
2094
2113
  const resolved = node();
2095
2114
  if (resolved === node) {
2096
- return document.createTextNode("");
2115
+ return ownerDocument.createTextNode("");
2097
2116
  }
2098
- return createElementWithContext(resolved, namespace);
2117
+ return createElementWithContext(resolved, namespace, ownerDocument);
2099
2118
  }
2100
2119
  if (typeof node === "function") {
2101
- return document.createTextNode("");
2120
+ return ownerDocument.createTextNode("");
2102
2121
  }
2103
2122
  if (typeof node === "object" && node !== null && !(node instanceof Node)) {
2104
2123
  if ("marker" in node) {
@@ -2114,21 +2133,21 @@ function createElementWithContext(node, namespace) {
2114
2133
  Promise.resolve().then(runFlush).catch(() => void 0);
2115
2134
  }
2116
2135
  }
2117
- return createElement(handle.marker);
2136
+ return createElementWithContext(handle.marker, namespace, ownerDocument);
2118
2137
  }
2119
2138
  }
2120
2139
  if (Array.isArray(node)) {
2121
- const frag = document.createDocumentFragment();
2140
+ const frag = ownerDocument.createDocumentFragment();
2122
2141
  for (const child of node) {
2123
- appendChildNode(frag, child, namespace);
2142
+ appendChildNode(frag, child, namespace, ownerDocument);
2124
2143
  }
2125
2144
  return frag;
2126
2145
  }
2127
2146
  if (typeof node === "string" || typeof node === "number") {
2128
- return document.createTextNode(String(node));
2147
+ return ownerDocument.createTextNode(String(node));
2129
2148
  }
2130
2149
  if (typeof node === "boolean") {
2131
- return document.createTextNode("");
2150
+ return ownerDocument.createTextNode("");
2132
2151
  }
2133
2152
  const vnode = node;
2134
2153
  if (typeof vnode.type === "function") {
@@ -2182,8 +2201,8 @@ function createElementWithContext(node, namespace) {
2182
2201
  onCleanup(() => hook.componentUnmount?.(componentId));
2183
2202
  }
2184
2203
  if (__fictIsResumable() && !__fictIsHydrating()) {
2185
- const content = createElementWithContext(rendered, namespace);
2186
- 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");
2187
2206
  host.setAttribute("data-fict-host", "");
2188
2207
  if (namespace === null && host.style) {
2189
2208
  ;
@@ -2206,7 +2225,7 @@ function createElementWithContext(node, namespace) {
2206
2225
  }
2207
2226
  return host;
2208
2227
  }
2209
- const componentRoot = createElementWithContext(rendered, namespace);
2228
+ const componentRoot = createElementWithContext(rendered, namespace, ownerDocument);
2210
2229
  if (hook && componentId !== void 0) {
2211
2230
  mountElements = collectComponentMountElements(componentRoot);
2212
2231
  annotateComponentElements(mountElements, componentId, componentName);
@@ -2214,7 +2233,7 @@ function createElementWithContext(node, namespace) {
2214
2233
  return componentRoot;
2215
2234
  } catch (err) {
2216
2235
  if (handleSuspend(err)) {
2217
- return document.createComment("fict:suspend");
2236
+ return ownerDocument.createComment("fict:suspend");
2218
2237
  }
2219
2238
  handleError(err, { source: "render", componentName: vnode.type.name });
2220
2239
  throw err;
@@ -2223,26 +2242,27 @@ function createElementWithContext(node, namespace) {
2223
2242
  }
2224
2243
  }
2225
2244
  if (vnode.type === Fragment) {
2226
- const frag = document.createDocumentFragment();
2245
+ const frag = ownerDocument.createDocumentFragment();
2227
2246
  const children = vnode.props?.children;
2228
- appendChildren(frag, children, namespace);
2247
+ appendChildren(frag, children, namespace, ownerDocument);
2229
2248
  return frag;
2230
2249
  }
2231
2250
  const tagName = typeof vnode.type === "string" ? vnode.type : "div";
2232
2251
  const resolvedNamespace = resolveNamespace(tagName, namespace);
2233
- 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);
2234
2253
  applyProps(el, vnode.props ?? {}, resolvedNamespace === "svg");
2235
2254
  appendChildren(
2236
2255
  el,
2237
2256
  vnode.props?.children,
2238
- tagName === "foreignObject" ? null : resolvedNamespace
2257
+ tagName === "foreignObject" ? null : resolvedNamespace,
2258
+ ownerDocument
2239
2259
  );
2240
2260
  return el;
2241
2261
  }
2242
2262
  function template(html, isImportNode, isSVG, isMathML) {
2243
- let node = null;
2244
- const create = () => {
2245
- const t = document.createElement("template");
2263
+ const nodeByDocument = /* @__PURE__ */ new WeakMap();
2264
+ const create = (ownerDocument) => {
2265
+ const t = ownerDocument.createElement("template");
2246
2266
  if (isSVG) {
2247
2267
  t.innerHTML = `<svg>${html}</svg>`;
2248
2268
  const wrapper = t.content.firstChild;
@@ -2254,7 +2274,7 @@ function template(html, isImportNode, isSVG, isMathML) {
2254
2274
  if (wrapper.childNodes.length === 1) {
2255
2275
  return wrapper.firstChild;
2256
2276
  }
2257
- const fragment = document.createDocumentFragment();
2277
+ const fragment = ownerDocument.createDocumentFragment();
2258
2278
  fragment.append(...Array.from(wrapper.childNodes));
2259
2279
  return fragment;
2260
2280
  }
@@ -2269,7 +2289,7 @@ function template(html, isImportNode, isSVG, isMathML) {
2269
2289
  if (wrapper.childNodes.length === 1) {
2270
2290
  return wrapper.firstChild;
2271
2291
  }
2272
- const fragment = document.createDocumentFragment();
2292
+ const fragment = ownerDocument.createDocumentFragment();
2273
2293
  fragment.append(...Array.from(wrapper.childNodes));
2274
2294
  return fragment;
2275
2295
  }
@@ -2285,11 +2305,19 @@ function template(html, isImportNode, isSVG, isMathML) {
2285
2305
  }
2286
2306
  return content;
2287
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
+ };
2288
2315
  const fn = isImportNode ? () => untrack2(() => {
2289
- const base = node || (node = create());
2290
- 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);
2291
2319
  }) : () => {
2292
- const base = node || (node = create());
2320
+ const base = getBase(resolveOwnerDocument());
2293
2321
  return isHydratingActive() ? claimNodes(base, () => base.cloneNode(true)) : base.cloneNode(true);
2294
2322
  };
2295
2323
  fn.cloneNode = fn;
@@ -2298,39 +2326,44 @@ function template(html, isImportNode, isSVG, isMathML) {
2298
2326
  function isBindingHandle(node) {
2299
2327
  return node !== null && typeof node === "object" && "marker" in node && "dispose" in node && typeof node.dispose === "function";
2300
2328
  }
2301
- function appendChildNode(parent, child, namespace) {
2329
+ function appendChildNode(parent, child, namespace, ownerDocument) {
2330
+ const parentOwnerDocument = parent.ownerDocument ?? ownerDocument;
2302
2331
  if (child === null || child === void 0 || child === false) {
2303
2332
  return;
2304
2333
  }
2305
2334
  if (isBindingHandle(child)) {
2306
- appendChildNode(parent, child.marker, namespace);
2335
+ appendChildNode(parent, child.marker, namespace, parentOwnerDocument);
2307
2336
  child.flush?.();
2308
2337
  return;
2309
2338
  }
2310
2339
  if (typeof child === "function") {
2311
2340
  const childGetter = child;
2312
2341
  if (isReactive(childGetter)) {
2313
- createChildBinding(parent, childGetter, (node) => createElementWithContext(node, namespace));
2342
+ createChildBinding(
2343
+ parent,
2344
+ childGetter,
2345
+ (node) => createElementWithContext(node, namespace, parentOwnerDocument)
2346
+ );
2314
2347
  return;
2315
2348
  }
2316
2349
  return;
2317
2350
  }
2318
2351
  if (Array.isArray(child)) {
2319
2352
  for (const item of child) {
2320
- appendChildNode(parent, item, namespace);
2353
+ appendChildNode(parent, item, namespace, parentOwnerDocument);
2321
2354
  }
2322
2355
  return;
2323
2356
  }
2324
2357
  let domNode;
2325
2358
  if (typeof child !== "object" || child === null) {
2326
- domNode = document.createTextNode(String(child ?? ""));
2359
+ domNode = parentOwnerDocument.createTextNode(String(child ?? ""));
2327
2360
  } else {
2328
- domNode = createElementWithContext(child, namespace);
2361
+ domNode = createElementWithContext(child, namespace, parentOwnerDocument);
2329
2362
  }
2330
2363
  if (domNode.nodeType === 11) {
2331
2364
  const children = Array.from(domNode.childNodes);
2332
2365
  for (const node of children) {
2333
- appendChildNode(parent, node, namespace);
2366
+ appendChildNode(parent, node, namespace, parentOwnerDocument);
2334
2367
  }
2335
2368
  return;
2336
2369
  }
@@ -2348,15 +2381,15 @@ function appendChildNode(parent, child, namespace) {
2348
2381
  throw e;
2349
2382
  }
2350
2383
  }
2351
- function appendChildren(parent, children, namespace) {
2384
+ function appendChildren(parent, children, namespace, ownerDocument) {
2352
2385
  if (children === void 0) return;
2353
2386
  if (Array.isArray(children)) {
2354
2387
  for (const child of children) {
2355
- appendChildren(parent, child, namespace);
2388
+ appendChildren(parent, child, namespace, ownerDocument);
2356
2389
  }
2357
2390
  return;
2358
2391
  }
2359
- appendChildNode(parent, children, namespace);
2392
+ appendChildNode(parent, children, namespace, ownerDocument);
2360
2393
  }
2361
2394
  function applyRef(el, value) {
2362
2395
  if (typeof value === "function") {
@@ -2628,4 +2661,4 @@ export {
2628
2661
  createElement,
2629
2662
  template
2630
2663
  };
2631
- //# sourceMappingURL=chunk-R6FINS25.js.map
2664
+ //# sourceMappingURL=chunk-WIHNVN6L.js.map