@vidact/runtime 0.2.0-beta.0 → 0.2.0-beta.5

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 (244) hide show
  1. package/CHANGELOG.md +52 -0
  2. package/README.md +1 -1
  3. package/dist/actions.d.ts +32 -30
  4. package/dist/actions.d.ts.map +1 -1
  5. package/dist/actions.js +251 -266
  6. package/dist/actions.js.map +1 -1
  7. package/dist/async.d.ts +20 -17
  8. package/dist/async.d.ts.map +1 -1
  9. package/dist/async.js +18 -17
  10. package/dist/async.js.map +1 -1
  11. package/dist/compiled/async-resource.d.ts +9 -6
  12. package/dist/compiled/async-resource.d.ts.map +1 -1
  13. package/dist/compiled/async-resource.js +69 -77
  14. package/dist/compiled/async-resource.js.map +1 -1
  15. package/dist/compiled/core.d.ts +136 -147
  16. package/dist/compiled/core.d.ts.map +1 -1
  17. package/dist/compiled/core.js +2672 -2985
  18. package/dist/compiled/core.js.map +1 -1
  19. package/dist/compiled/types.d.ts +44 -56
  20. package/dist/compiled/types.d.ts.map +1 -1
  21. package/dist/compiled/types.js +10 -6
  22. package/dist/compiled/types.js.map +1 -1
  23. package/dist/compiled/validation.d.ts +4 -1
  24. package/dist/compiled/validation.d.ts.map +1 -1
  25. package/dist/compiled/validation.js +17 -20
  26. package/dist/compiled/validation.js.map +1 -1
  27. package/dist/component-spread.d.ts +5 -3
  28. package/dist/component-spread.d.ts.map +1 -1
  29. package/dist/component-spread.js +49 -67
  30. package/dist/component-spread.js.map +1 -1
  31. package/dist/concurrent.d.ts +20 -18
  32. package/dist/concurrent.d.ts.map +1 -1
  33. package/dist/concurrent.js +191 -210
  34. package/dist/concurrent.js.map +1 -1
  35. package/dist/direct-dom.d.ts +17 -12
  36. package/dist/direct-dom.d.ts.map +1 -1
  37. package/dist/direct-dom.js +187 -221
  38. package/dist/direct-dom.js.map +1 -1
  39. package/dist/dom/attributes.d.ts +9 -6
  40. package/dist/dom/attributes.d.ts.map +1 -1
  41. package/dist/dom/attributes.js +65 -47
  42. package/dist/dom/attributes.js.map +1 -1
  43. package/dist/dom/events.d.ts +5 -2
  44. package/dist/dom/events.d.ts.map +1 -1
  45. package/dist/dom/events.js +53 -65
  46. package/dist/dom/events.js.map +1 -1
  47. package/dist/dom/forms.d.ts +9 -6
  48. package/dist/dom/forms.d.ts.map +1 -1
  49. package/dist/dom/forms.js +152 -198
  50. package/dist/dom/forms.js.map +1 -1
  51. package/dist/dom/intrinsic.d.ts +17 -15
  52. package/dist/dom/intrinsic.d.ts.map +1 -1
  53. package/dist/dom/intrinsic.js +48 -50
  54. package/dist/dom/intrinsic.js.map +1 -1
  55. package/dist/dom/namespace.d.ts +4 -1
  56. package/dist/dom/namespace.d.ts.map +1 -1
  57. package/dist/dom/namespace.js +25 -28
  58. package/dist/dom/namespace.js.map +1 -1
  59. package/dist/dom/namespaces.d.ts +11 -8
  60. package/dist/dom/namespaces.d.ts.map +1 -1
  61. package/dist/dom/namespaces.js +14 -12
  62. package/dist/dom/namespaces.js.map +1 -1
  63. package/dist/dom/properties.d.ts +18 -16
  64. package/dist/dom/properties.d.ts.map +1 -1
  65. package/dist/dom/properties.js +273 -296
  66. package/dist/dom/properties.js.map +1 -1
  67. package/dist/dom/style-properties.d.ts +4 -1
  68. package/dist/dom/style-properties.d.ts.map +1 -1
  69. package/dist/dom/style-properties.js +49 -45
  70. package/dist/dom/style-properties.js.map +1 -1
  71. package/dist/dom/styles.d.ts +5 -2
  72. package/dist/dom/styles.d.ts.map +1 -1
  73. package/dist/dom/styles.js +47 -67
  74. package/dist/dom/styles.js.map +1 -1
  75. package/dist/dom-forms.d.ts +4 -1
  76. package/dist/dom-forms.d.ts.map +1 -1
  77. package/dist/dom-forms.js +16 -13
  78. package/dist/dom-forms.js.map +1 -1
  79. package/dist/dom-styles.d.ts +4 -1
  80. package/dist/dom-styles.d.ts.map +1 -1
  81. package/dist/dom-styles.js +10 -7
  82. package/dist/dom-styles.js.map +1 -1
  83. package/dist/framework-hydrate.d.ts +20 -17
  84. package/dist/framework-hydrate.d.ts.map +1 -1
  85. package/dist/framework-hydrate.js +128 -146
  86. package/dist/framework-hydrate.js.map +1 -1
  87. package/dist/framework-protocol.d.ts +27 -25
  88. package/dist/framework-protocol.d.ts.map +1 -1
  89. package/dist/framework-protocol.js +173 -211
  90. package/dist/framework-protocol.js.map +1 -1
  91. package/dist/framework.d.ts +34 -32
  92. package/dist/framework.d.ts.map +1 -1
  93. package/dist/framework.js +74 -93
  94. package/dist/framework.js.map +1 -1
  95. package/dist/hydrate.d.ts +11 -8
  96. package/dist/hydrate.d.ts.map +1 -1
  97. package/dist/hydrate.js +13 -9
  98. package/dist/hydrate.js.map +1 -1
  99. package/dist/hydration-bridge.d.ts +70 -58
  100. package/dist/hydration-bridge.d.ts.map +1 -1
  101. package/dist/hydration-bridge.js +77 -66
  102. package/dist/hydration-bridge.js.map +1 -1
  103. package/dist/hydration.d.ts +54 -28
  104. package/dist/hydration.d.ts.map +1 -1
  105. package/dist/hydration.js +450 -463
  106. package/dist/hydration.js.map +1 -1
  107. package/dist/index.d.ts +13 -13
  108. package/dist/index.js +11 -13
  109. package/dist/indexed-list.d.ts +8 -5
  110. package/dist/indexed-list.d.ts.map +1 -1
  111. package/dist/indexed-list.js +14 -7
  112. package/dist/indexed-list.js.map +1 -1
  113. package/dist/jsx-runtime.d.ts +10 -8
  114. package/dist/jsx-runtime.d.ts.map +1 -1
  115. package/dist/jsx-runtime.js +28 -23
  116. package/dist/jsx-runtime.js.map +1 -1
  117. package/dist/keyed-list.d.ts +13 -14
  118. package/dist/keyed-list.d.ts.map +1 -1
  119. package/dist/keyed-list.js +132 -160
  120. package/dist/keyed-list.js.map +1 -1
  121. package/dist/metadata.d.ts +6 -3
  122. package/dist/metadata.d.ts.map +1 -1
  123. package/dist/metadata.js +131 -164
  124. package/dist/metadata.js.map +1 -1
  125. package/dist/nested-prop.d.ts +4 -2
  126. package/dist/nested-prop.d.ts.map +1 -1
  127. package/dist/nested-prop.js +17 -16
  128. package/dist/nested-prop.js.map +1 -1
  129. package/dist/profiling.d.ts +11 -8
  130. package/dist/profiling.d.ts.map +1 -1
  131. package/dist/profiling.js +17 -17
  132. package/dist/profiling.js.map +1 -1
  133. package/dist/protocol.d.ts +5 -2
  134. package/dist/protocol.d.ts.map +1 -1
  135. package/dist/protocol.js +8 -5
  136. package/dist/protocol.js.map +1 -1
  137. package/dist/raw-html.d.ts +5 -2
  138. package/dist/raw-html.d.ts.map +1 -1
  139. package/dist/raw-html.js +86 -146
  140. package/dist/raw-html.js.map +1 -1
  141. package/dist/ref.d.ts +8 -3
  142. package/dist/ref.d.ts.map +1 -1
  143. package/dist/ref.js +10 -2
  144. package/dist/ref.js.map +1 -1
  145. package/dist/renderable-protocol.d.ts +26 -8
  146. package/dist/renderable-protocol.d.ts.map +1 -1
  147. package/dist/renderable-protocol.js +30 -9
  148. package/dist/renderable-protocol.js.map +1 -1
  149. package/dist/renderable.d.ts +27 -22
  150. package/dist/renderable.d.ts.map +1 -1
  151. package/dist/renderable.js +141 -133
  152. package/dist/renderable.js.map +1 -1
  153. package/dist/retained-ui.d.ts +9 -6
  154. package/dist/retained-ui.d.ts.map +1 -1
  155. package/dist/retained-ui.js +12 -10
  156. package/dist/retained-ui.js.map +1 -1
  157. package/dist/root.d.ts +18 -15
  158. package/dist/root.d.ts.map +1 -1
  159. package/dist/root.js +73 -85
  160. package/dist/root.js.map +1 -1
  161. package/dist/scheduler.d.ts +10 -8
  162. package/dist/scheduler.d.ts.map +1 -1
  163. package/dist/scheduler.js +97 -105
  164. package/dist/scheduler.js.map +1 -1
  165. package/dist/server-framework.d.ts +45 -42
  166. package/dist/server-framework.d.ts.map +1 -1
  167. package/dist/server-framework.js +209 -217
  168. package/dist/server-framework.js.map +1 -1
  169. package/dist/server.d.ts +130 -128
  170. package/dist/server.d.ts.map +1 -1
  171. package/dist/server.js +603 -710
  172. package/dist/server.js.map +1 -1
  173. package/dist/shared/promise.d.ts +6 -3
  174. package/dist/shared/promise.d.ts.map +1 -1
  175. package/dist/shared/promise.js +21 -19
  176. package/dist/shared/promise.js.map +1 -1
  177. package/dist/source-mask.d.ts +9 -6
  178. package/dist/source-mask.d.ts.map +1 -1
  179. package/dist/source-mask.js +45 -63
  180. package/dist/source-mask.js.map +1 -1
  181. package/dist/spread.d.ts +5 -2
  182. package/dist/spread.d.ts.map +1 -1
  183. package/dist/spread.js +79 -99
  184. package/dist/spread.js.map +1 -1
  185. package/dist/state-slot.d.ts +18 -15
  186. package/dist/state-slot.d.ts.map +1 -1
  187. package/dist/state-slot.js +43 -42
  188. package/dist/state-slot.js.map +1 -1
  189. package/dist/testing.d.ts +9 -6
  190. package/dist/testing.d.ts.map +1 -1
  191. package/dist/testing.js +16 -12
  192. package/dist/testing.js.map +1 -1
  193. package/package.json +8 -7
  194. package/src/actions.ts +415 -0
  195. package/src/async.ts +78 -0
  196. package/src/compiled/async-resource.ts +113 -0
  197. package/src/compiled/core.ts +4041 -0
  198. package/src/compiled/types.ts +96 -0
  199. package/src/compiled/validation.ts +23 -0
  200. package/src/component-spread.ts +86 -0
  201. package/src/concurrent.ts +310 -0
  202. package/src/direct-dom.ts +365 -0
  203. package/src/dom/attributes.ts +55 -0
  204. package/src/dom/events.ts +93 -0
  205. package/src/dom/forms.ts +220 -0
  206. package/src/dom/intrinsic.ts +94 -0
  207. package/src/dom/namespace.ts +30 -0
  208. package/src/dom/namespaces.ts +14 -0
  209. package/src/dom/properties.ts +355 -0
  210. package/src/dom/style-properties.ts +46 -0
  211. package/src/dom/styles.ts +86 -0
  212. package/src/dom-forms.ts +23 -0
  213. package/src/dom-styles.ts +11 -0
  214. package/src/env.d.ts +6 -0
  215. package/src/framework-hydrate.ts +224 -0
  216. package/src/framework-protocol.ts +335 -0
  217. package/src/framework.ts +161 -0
  218. package/src/hydrate.ts +38 -0
  219. package/src/hydration-bridge.ts +196 -0
  220. package/src/hydration.ts +642 -0
  221. package/src/index.ts +92 -0
  222. package/src/indexed-list.ts +20 -0
  223. package/src/jsx-runtime.ts +55 -0
  224. package/src/keyed-list.ts +233 -0
  225. package/src/metadata.ts +212 -0
  226. package/src/nested-prop.ts +27 -0
  227. package/src/profiling.ts +43 -0
  228. package/src/protocol.ts +8 -0
  229. package/src/raw-html.ts +206 -0
  230. package/src/ref.ts +13 -0
  231. package/src/renderable-protocol.ts +63 -0
  232. package/src/renderable.ts +283 -0
  233. package/src/retained-ui.ts +19 -0
  234. package/src/root.ts +122 -0
  235. package/src/scheduler.ts +136 -0
  236. package/src/server-framework.ts +397 -0
  237. package/src/server.ts +1160 -0
  238. package/src/shared/promise.ts +28 -0
  239. package/src/source-mask.ts +83 -0
  240. package/src/spread.ts +131 -0
  241. package/src/state-slot.ts +76 -0
  242. package/src/testing.ts +27 -0
  243. package/dist/index.d.ts.map +0 -1
  244. package/dist/index.js.map +0 -1
package/dist/hydration.js CHANGED
@@ -1,489 +1,476 @@
1
- import { HydrationMismatch, installHydrationOperations, } from './hydration-bridge.js';
2
- const HYDRATION_PREFIX = 'vidact:v1';
1
+ import { HydrationMismatch, installHydrationOperations } from "./hydration-bridge.js";
2
+ //#region src/hydration.ts
3
3
  let activeHydration;
4
4
  let activeInsertionPoint;
5
- const hydrationFragments = new WeakMap();
6
- export function beginHydration(host) {
7
- if (activeHydration !== undefined) {
8
- throw new Error('a Vidact hydration is already active');
9
- }
10
- const ranges = scanRanges(host);
11
- const root = ranges.roots[0];
12
- if (root === undefined || ranges.roots.length !== 1) {
13
- throw mismatch('expected exactly one vidact:v1 root marker range');
14
- }
15
- activeHydration = {
16
- host,
17
- root,
18
- components: ranges.components,
19
- claimedElements: new WeakSet(),
20
- elementComponents: collectElementComponents(host),
21
- elements: collectPostorderElements(root),
22
- cursors: new WeakMap([[host, root[0].nextSibling]]),
23
- slots: new WeakMap(),
24
- componentIndex: 0,
25
- claimedElementCount: 0,
26
- pendingStructuralParents: 0,
27
- activeComponentStart: undefined,
28
- };
29
- return () => {
30
- activeHydration = undefined;
31
- };
32
- }
33
- export function finishHydration() {
34
- const state = requireHydration();
35
- if (state.componentIndex !== state.components.length) {
36
- throw mismatch(`claimed ${state.componentIndex} of ${state.components.length} server component ranges`);
37
- }
38
- if (state.claimedElementCount !== state.elements.length) {
39
- throw mismatch(`claimed ${state.claimedElementCount} of ${state.elements.length} server elements`);
40
- }
41
- const rootCursor = cursor(state, state.host);
42
- if (rootCursor !== state.root[1]) {
43
- throw mismatch(`compiled root did not consume the complete server root range; stopped at ${JSON.stringify(markerValue(rootCursor) ?? rootCursor?.nodeName ?? null)}`);
44
- }
45
- }
46
- export function hydrationRootMarkers() {
47
- return requireHydration().root;
48
- }
49
- export function isHydrating() {
50
- return activeHydration !== undefined;
51
- }
52
- export function createHydrationFragment(children) {
53
- const fragment = document.createDocumentFragment();
54
- hydrationFragments.set(fragment, children);
55
- return fragment;
56
- }
57
- export function hydrationFragmentChildren(fragment) {
58
- return hydrationFragments.get(fragment);
59
- }
60
- export function isHydrationMismatch(error) {
61
- return error instanceof HydrationMismatch;
62
- }
63
- export function claimHydrationElement(localName, namespace, matchesExpected) {
64
- const state = activeHydration;
65
- if (state === undefined)
66
- return undefined;
67
- const candidates = state.elements.filter((candidate) => !state.claimedElements.has(candidate) &&
68
- (state.activeComponentStart === undefined ||
69
- state.elementComponents.get(candidate) === state.activeComponentStart) &&
70
- candidate.localName === localName &&
71
- candidate.namespaceURI === namespace);
72
- const expectedMatches = matchesExpected === undefined ? candidates : candidates.filter(matchesExpected);
73
- const matches = expectedMatches.length === 0 ? candidates : expectedMatches;
74
- const element = state.pendingStructuralParents > 0
75
- ? (matches.find(containsArrayMarker) ?? matches[0])
76
- : matches[0];
77
- if (element === undefined) {
78
- throw mismatch(state.pendingStructuralParents > 0
79
- ? `missing server structural parent <${localName}>`
80
- : `missing server element <${localName}>`);
81
- }
82
- if (state.pendingStructuralParents > 0)
83
- state.pendingStructuralParents = 0;
84
- state.claimedElements.add(element);
85
- state.claimedElementCount += 1;
86
- state.cursors.set(element, element.firstChild);
87
- return element;
88
- }
89
- export function noteHydrationStructuralParent() {
90
- if (activeHydration !== undefined)
91
- activeHydration.pendingStructuralParents += 1;
92
- }
93
- export function claimHydrationComponentRange() {
94
- const state = activeHydration;
95
- if (state === undefined)
96
- return undefined;
97
- const range = state.components[state.componentIndex];
98
- if (range === undefined)
99
- throw mismatch('missing server component marker range');
100
- state.componentIndex += 1;
101
- const parent = range[0].parentNode;
102
- if (parent === null || range[1].parentNode !== parent) {
103
- throw mismatch('server component marker range is detached');
104
- }
105
- return range;
106
- }
107
- export function withHydrationComponentRange(range, operation) {
108
- const state = activeHydration;
109
- if (state === undefined)
110
- return operation();
111
- const previous = state.activeComponentStart;
112
- state.activeComponentStart = range[0];
113
- try {
114
- return operation();
115
- }
116
- finally {
117
- state.activeComponentStart = previous;
118
- }
119
- }
120
- export function withHydrationCursor(parent, value, operation) {
121
- const state = activeHydration;
122
- if (state === undefined)
123
- return operation();
124
- const hadCursor = state.cursors.has(parent);
125
- const previous = state.cursors.get(parent) ?? null;
126
- state.cursors.set(parent, value);
127
- try {
128
- return operation();
129
- }
130
- finally {
131
- if (hadCursor)
132
- state.cursors.set(parent, previous);
133
- else
134
- state.cursors.delete(parent);
135
- }
136
- }
137
- export function claimHydrationNode(parent, node) {
138
- const state = activeHydration;
139
- if (state === undefined)
140
- return false;
141
- enterHydrationSlot(state, parent);
142
- const next = cursor(state, parent);
143
- if (isMarker(next, `${HYDRATION_PREFIX}:s`)) {
144
- const end = findClosingSibling(next, `${HYDRATION_PREFIX}:s`);
145
- if (next.nextSibling !== node || node.nextSibling !== end) {
146
- throw mismatch(`server node range does not contain exactly the expected ${node.nodeName}`);
147
- }
148
- setHydrationCursor(state, parent, end.nextSibling);
149
- return true;
150
- }
151
- if (next !== node) {
152
- throw mismatch(`expected existing ${node.nodeName} at the current hydration position`);
153
- }
154
- setHydrationCursor(state, parent, node.nextSibling);
155
- return true;
156
- }
157
- export function claimHydrationComponentMount(parent, start, end) {
158
- const state = activeHydration;
159
- if (state === undefined)
160
- return false;
161
- enterHydrationSlot(state, parent);
162
- const current = cursor(state, parent);
163
- if ((current !== start && current !== end) ||
164
- start.parentNode !== parent ||
165
- end.parentNode !== parent) {
166
- throw mismatch('server component range does not match the compiled child position');
167
- }
168
- setHydrationCursor(state, parent, end.nextSibling);
169
- return true;
170
- }
171
- export function claimHydrationText(parent, expected) {
172
- return claimHydrationTextRange(parent, expected)?.[2];
173
- }
174
- export function claimHydrationTextRange(parent, expected) {
175
- const state = activeHydration;
176
- if (state === undefined)
177
- return undefined;
178
- enterHydrationSlot(state, parent);
179
- const start = cursor(state, parent);
180
- if (!isMarker(start, `${HYDRATION_PREFIX}:t`)) {
181
- throw mismatch('expected a vidact:v1 text marker');
182
- }
183
- const end = findClosingSibling(start, `${HYDRATION_PREFIX}:t`);
184
- const nodes = [];
185
- for (let node = start.nextSibling; node !== null && node !== end; node = node.nextSibling) {
186
- nodes.push(node);
187
- }
188
- if (nodes.length > 1 || (nodes.length === 1 && !(nodes[0] instanceof Text))) {
189
- throw mismatch('server text marker must contain at most one text node');
190
- }
191
- const text = nodes[0] ?? null;
192
- if ((text?.data ?? '') !== expected) {
193
- throw mismatch(`server text ${JSON.stringify(text?.data ?? '')} does not match ${JSON.stringify(expected)}`);
194
- }
195
- setHydrationCursor(state, parent, end.nextSibling);
196
- return [start, end, text];
197
- }
198
- export function claimHydrationArrayRange(parent) {
199
- const state = activeHydration;
200
- if (state === undefined)
201
- return undefined;
202
- enterHydrationSlot(state, parent);
203
- const start = cursor(state, parent);
204
- if (!isMarker(start, `${HYDRATION_PREFIX}:a`)) {
205
- throw mismatch(`expected a vidact:v1 array marker in ${parent.nodeName}; found ${JSON.stringify(markerValue(start) ?? start?.nodeName ?? null)}`);
206
- }
207
- const end = findClosingSibling(start, `${HYDRATION_PREFIX}:a`);
208
- state.cursors.set(parent, start.nextSibling);
209
- return [start, end];
210
- }
211
- export function finishHydrationArrayRange(parent, end) {
212
- const state = requireHydration();
213
- if (cursor(state, parent) !== end) {
214
- throw mismatch('compiled collection did not consume its complete server array range');
215
- }
216
- setHydrationCursor(state, parent, end.nextSibling);
217
- }
218
- export function claimHydrationSlotRange(parent) {
219
- const state = activeHydration;
220
- if (state === undefined)
221
- return undefined;
222
- const start = cursor(state, parent);
223
- if (!isMarker(start, `${HYDRATION_PREFIX}:b`)) {
224
- throw mismatch(`expected a vidact:v1 child-slot marker in ${parent.nodeName}; found ${JSON.stringify(markerValue(start) ?? start?.nodeName ?? null)} after ${JSON.stringify(markerValue(start?.previousSibling) ?? start?.previousSibling?.nodeName ?? null)}; insertion=${JSON.stringify(markerValue(activeInsertionPoint?.[1]) ?? activeInsertionPoint?.[1]?.nodeName ?? null)}`);
225
- }
226
- const end = findClosingSibling(start, `${HYDRATION_PREFIX}:b`);
227
- const slots = state.slots.get(parent) ?? [];
228
- slots.push(end);
229
- state.slots.set(parent, slots);
230
- state.cursors.set(parent, start.nextSibling);
231
- return [start, end];
232
- }
233
- export function borrowHydrationSlotRange(parent, current) {
234
- const state = activeHydration;
235
- if (state === undefined)
236
- return undefined;
237
- const start = (current ? cursor(state, parent) : cursor(state, parent)?.previousSibling);
238
- if (!isMarker(start, `${HYDRATION_PREFIX}:b`))
239
- return undefined;
240
- if (!current &&
241
- activeInsertionPoint?.[0] === parent &&
242
- isMarker(activeInsertionPoint[1], `/${HYDRATION_PREFIX}:b`)) {
243
- return [start, activeInsertionPoint[1]];
244
- }
245
- return [start, findClosingSibling(start, `${HYDRATION_PREFIX}:b`)];
246
- }
247
- export function claimHydrationSuspenseFallback(parent) {
248
- const state = activeHydration;
249
- if (state === undefined)
250
- return undefined;
251
- const marker = cursor(state, parent);
252
- if (!isMarker(marker, `${HYDRATION_PREFIX}:p`))
253
- return undefined;
254
- setHydrationCursor(state, parent, marker.nextSibling);
255
- return marker;
256
- }
257
- export function withoutHydration(operation) {
258
- const previous = activeHydration;
259
- activeHydration = undefined;
260
- try {
261
- return operation();
262
- }
263
- finally {
264
- activeHydration = previous;
265
- }
266
- }
267
- export function withHydrationInsertion(parent, before, operation) {
268
- if (activeHydration === undefined)
269
- return operation();
270
- const previous = activeInsertionPoint;
271
- activeInsertionPoint = [parent, before];
272
- try {
273
- return operation();
274
- }
275
- finally {
276
- activeInsertionPoint = previous;
277
- }
278
- }
279
- export function hydrationInsertionPoint() {
280
- return activeInsertionPoint;
281
- }
282
- export function hydrationCursor(parent) {
283
- const state = activeHydration;
284
- return state === undefined ? undefined : cursor(state, parent);
285
- }
286
- export function hydrationRangeParent(start, end) {
287
- if (activeHydration === undefined)
288
- return undefined;
289
- const parent = start.parentNode;
290
- if (parent === null || end.parentNode !== parent)
291
- throw mismatch('detached server marker range');
292
- return parent;
5
+ const hydrationFragments = /* @__PURE__ */ new WeakMap();
6
+ function beginHydration(host) {
7
+ if (activeHydration !== void 0) throw new Error("a Vidact hydration is already active");
8
+ const ranges = scanRanges(host);
9
+ const root = ranges.roots[0];
10
+ if (root === void 0 || ranges.roots.length !== 1) throw mismatch(`expected exactly one v2 root marker range`);
11
+ activeHydration = {
12
+ host,
13
+ root,
14
+ components: ranges.components,
15
+ claimedElements: /* @__PURE__ */ new WeakSet(),
16
+ elementComponents: collectElementComponents(host),
17
+ elements: collectPostorderElements(root),
18
+ cursors: new WeakMap([[host, root[0].nextSibling]]),
19
+ slots: /* @__PURE__ */ new WeakMap(),
20
+ componentIndex: 0,
21
+ claimedElementCount: 0,
22
+ pendingStructuralParents: 0,
23
+ activeComponentStart: void 0
24
+ };
25
+ return () => {
26
+ activeHydration = void 0;
27
+ };
28
+ }
29
+ function finishHydration() {
30
+ const state = requireHydration();
31
+ if (state.componentIndex !== state.components.length) throw mismatch(`claimed ${state.componentIndex} of ${state.components.length} server component ranges`);
32
+ if (state.claimedElementCount !== state.elements.length) throw mismatch(`claimed ${state.claimedElementCount} of ${state.elements.length} server elements`);
33
+ const rootCursor = cursor(state, state.host);
34
+ if (rootCursor !== state.root[1]) throw mismatch(`compiled root did not consume the complete server root range; stopped at ${JSON.stringify(markerValue(rootCursor) ?? rootCursor?.nodeName ?? null)}`);
35
+ }
36
+ function hydrationRootMarkers() {
37
+ return requireHydration().root;
38
+ }
39
+ function isHydrating() {
40
+ return activeHydration !== void 0;
41
+ }
42
+ function createHydrationFragment(children) {
43
+ const fragment = document.createDocumentFragment();
44
+ hydrationFragments.set(fragment, children);
45
+ return fragment;
46
+ }
47
+ function hydrationFragmentChildren(fragment) {
48
+ return hydrationFragments.get(fragment);
49
+ }
50
+ function isHydrationMismatch(error) {
51
+ return error instanceof HydrationMismatch;
52
+ }
53
+ function claimHydrationElement(localName, namespace, matchesExpected) {
54
+ const state = activeHydration;
55
+ if (state === void 0) return void 0;
56
+ const candidates = state.elements.filter((candidate) => !state.claimedElements.has(candidate) && (state.activeComponentStart === void 0 || state.elementComponents.get(candidate) === state.activeComponentStart) && candidate.localName === localName && candidate.namespaceURI === namespace);
57
+ const expectedMatches = matchesExpected === void 0 ? candidates : candidates.filter(matchesExpected);
58
+ const matches = expectedMatches.length === 0 ? candidates : expectedMatches;
59
+ const element = state.pendingStructuralParents > 0 ? matches.find(containsArrayMarker) ?? matches[0] : matches[0];
60
+ if (element === void 0) throw mismatch(state.pendingStructuralParents > 0 ? `missing server structural parent <${localName}>` : `missing server element <${localName}>`);
61
+ if (state.pendingStructuralParents > 0) state.pendingStructuralParents = 0;
62
+ state.claimedElements.add(element);
63
+ state.claimedElementCount += 1;
64
+ state.cursors.set(element, initialCursor(element));
65
+ return element;
66
+ }
67
+ /**
68
+ * Called by a compiled list right before its container element is claimed. Lists are the
69
+ * only structural bindings whose server markup carries an `a` marker, so they are the
70
+ * only ones that may prefer a candidate containing one — for a conditional, Suspense or
71
+ * any other structural child that bias would pick an unrelated element that happens to
72
+ * hold a list (see `claimHydrationElement`).
73
+ */
74
+ function noteHydrationStructuralParent() {
75
+ if (activeHydration !== void 0) activeHydration.pendingStructuralParents += 1;
76
+ }
77
+ function claimHydrationComponentRange() {
78
+ const state = activeHydration;
79
+ if (state === void 0) return void 0;
80
+ const range = state.components[state.componentIndex];
81
+ if (range === void 0) throw mismatch("missing server component marker range");
82
+ state.componentIndex += 1;
83
+ const parent = range[0].parentNode;
84
+ if (parent === null || range[1].parentNode !== parent) throw mismatch("server component marker range is detached");
85
+ return range;
86
+ }
87
+ function withHydrationComponentRange(range, operation) {
88
+ const state = activeHydration;
89
+ if (state === void 0) return operation();
90
+ const previous = state.activeComponentStart;
91
+ state.activeComponentStart = range[0];
92
+ try {
93
+ return operation();
94
+ } finally {
95
+ state.activeComponentStart = previous;
96
+ }
97
+ }
98
+ function withHydrationCursor(parent, value, operation) {
99
+ const state = activeHydration;
100
+ if (state === void 0) return operation();
101
+ const hadCursor = state.cursors.has(parent);
102
+ const previous = state.cursors.get(parent) ?? null;
103
+ state.cursors.set(parent, value);
104
+ try {
105
+ return operation();
106
+ } finally {
107
+ if (hadCursor) state.cursors.set(parent, previous);
108
+ else state.cursors.delete(parent);
109
+ }
110
+ }
111
+ function claimHydrationNode(parent, node) {
112
+ const state = activeHydration;
113
+ if (state === void 0) return false;
114
+ enterHydrationSlot(state, parent);
115
+ if (cursor(state, parent) !== node) throw mismatch(`expected existing ${node.nodeName} at the current hydration position`);
116
+ setHydrationCursor(state, parent, node.nextSibling);
117
+ return true;
118
+ }
119
+ function claimHydrationComponentMount(parent, start, end) {
120
+ const state = activeHydration;
121
+ if (state === void 0) return false;
122
+ enterHydrationSlot(state, parent);
123
+ const current = cursor(state, parent);
124
+ if (current !== start && current !== end || start.parentNode !== parent || end.parentNode !== parent) throw mismatch("server component range does not match the compiled child position");
125
+ setHydrationCursor(state, parent, end.nextSibling);
126
+ return true;
127
+ }
128
+ function claimHydrationText(parent, expected) {
129
+ const state = activeHydration;
130
+ if (state === void 0) return void 0;
131
+ enterHydrationSlot(state, parent);
132
+ return claimTextPrefix(state, parent, expected);
133
+ }
134
+ /**
135
+ * Claims the text for a scalar binding together with a range it can later swap an
136
+ * element or collection into. The server emits no markers around text, so the binding
137
+ * borrows the enclosing child-slot markers when the slot holds exactly this text — the
138
+ * common case, and no DOM is touched. A text node shared with adjacent scalars (one
139
+ * parsed node for several array items) gets fresh anchor comments instead.
140
+ */
141
+ function claimHydrationTextRange(parent, expected) {
142
+ const state = activeHydration;
143
+ if (state === void 0) return void 0;
144
+ enterHydrationSlot(state, parent);
145
+ const at = cursor(state, parent);
146
+ const slotStart = at === null ? parent.lastChild : at.previousSibling;
147
+ const text = claimTextPrefix(state, parent, expected);
148
+ const slotEnd = text === null ? at : text.nextSibling;
149
+ if (isMarker(slotStart, `v2:b`) && isMarker(slotEnd, `/v2:b`) && findClosingSibling(slotStart, `v2:b`) === slotEnd) return [
150
+ slotStart,
151
+ slotEnd,
152
+ text
153
+ ];
154
+ const start = document.createComment("");
155
+ const end = document.createComment("");
156
+ const reference = text ?? at;
157
+ parent.insertBefore(start, reference);
158
+ parent.insertBefore(end, text === null ? reference : text.nextSibling);
159
+ return [
160
+ start,
161
+ end,
162
+ text
163
+ ];
164
+ }
165
+ /**
166
+ * The server renders a scalar as bare text, and nothing at all for an empty one. Adjacent
167
+ * scalars in one collection parse into a single text node, so a claim takes only its own
168
+ * prefix and splits the rest off for the next claim.
169
+ */
170
+ function claimTextPrefix(state, parent, expected) {
171
+ const node = cursor(state, parent);
172
+ if (expected === "") {
173
+ if (node instanceof Text && node.data === "") {
174
+ setHydrationCursor(state, parent, node.nextSibling);
175
+ return node;
176
+ }
177
+ setHydrationCursor(state, parent, node);
178
+ return null;
179
+ }
180
+ if (!(node instanceof Text)) throw mismatch(`expected server text ${JSON.stringify(expected)} in ${describeNode(parent)}; found ${describeNode(node)}`);
181
+ if (!node.data.startsWith(expected)) throw mismatch(`server text ${JSON.stringify(node.data)} does not match ${JSON.stringify(expected)}`);
182
+ if (node.data.length > expected.length) node.splitText(expected.length);
183
+ setHydrationCursor(state, parent, node.nextSibling);
184
+ return node;
185
+ }
186
+ function claimHydrationArrayRange(parent) {
187
+ const state = activeHydration;
188
+ if (state === void 0) return void 0;
189
+ enterHydrationSlot(state, parent);
190
+ const start = cursor(state, parent);
191
+ if (!isMarker(start, `v2:a`)) throw mismatch(`expected a v2 array marker in ${describeNode(parent)}; found ${JSON.stringify(markerValue(start) ?? start?.nodeName ?? null)}`);
192
+ const end = findClosingSibling(start, `v2:a`);
193
+ state.cursors.set(parent, start.nextSibling);
194
+ return [start, end];
195
+ }
196
+ function finishHydrationArrayRange(parent, end) {
197
+ const state = requireHydration();
198
+ if (cursor(state, parent) !== end) throw mismatch("compiled collection did not consume its complete server array range");
199
+ setHydrationCursor(state, parent, end.nextSibling);
200
+ }
201
+ function claimHydrationSlotRange(parent) {
202
+ const state = activeHydration;
203
+ if (state === void 0) return void 0;
204
+ const start = cursor(state, parent);
205
+ if (!isMarker(start, `v2:b`)) throw mismatch(`expected a v2 child-slot marker in ${describeNode(parent)}; found ${JSON.stringify(markerValue(start) ?? start?.nodeName ?? null)} after ${JSON.stringify(markerValue(start?.previousSibling) ?? start?.previousSibling?.nodeName ?? null)}; insertion=${JSON.stringify(markerValue(activeInsertionPoint?.[1]) ?? activeInsertionPoint?.[1]?.nodeName ?? null)}`);
206
+ const end = findClosingSibling(start, `v2:b`);
207
+ const slots = state.slots.get(parent) ?? [];
208
+ slots.push(end);
209
+ state.slots.set(parent, slots);
210
+ state.cursors.set(parent, start.nextSibling);
211
+ return [start, end];
212
+ }
213
+ function borrowHydrationSlotRange(parent, current) {
214
+ const state = activeHydration;
215
+ if (state === void 0) return void 0;
216
+ const start = current ? cursor(state, parent) : cursor(state, parent)?.previousSibling;
217
+ if (!isMarker(start, `v2:b`)) return void 0;
218
+ if (!current && activeInsertionPoint?.[0] === parent && isMarker(activeInsertionPoint[1], `/v2:b`)) return [start, activeInsertionPoint[1]];
219
+ return [start, findClosingSibling(start, `v2:b`)];
220
+ }
221
+ /**
222
+ * Claims everything between two markers as-is, without hydrating into it. A Suspense
223
+ * boundary uses this when the server rendered its content but the client cannot
224
+ * produce it yet (a lazy chunk still loading): the server DOM stays on screen as a
225
+ * dehydrated boundary and the client render replaces it once the resource resolves.
226
+ * The elements and component ranges inside are marked claimed so `finishHydration`'s
227
+ * accounting still balances.
228
+ */
229
+ function skipHydrationRange(start, end) {
230
+ const state = requireHydration();
231
+ const parent = start.parentNode;
232
+ if (parent === null || end.parentNode !== parent) throw mismatch("detached server marker range");
233
+ for (const element of collectPostorderElements([start, end])) {
234
+ if (state.claimedElements.has(element)) continue;
235
+ state.claimedElements.add(element);
236
+ state.claimedElementCount += 1;
237
+ }
238
+ while (state.componentIndex < state.components.length) {
239
+ const componentStart = state.components[state.componentIndex][0];
240
+ if (!((start.compareDocumentPosition(componentStart) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0 && (componentStart.compareDocumentPosition(end) & Node.DOCUMENT_POSITION_FOLLOWING) !== 0)) break;
241
+ state.componentIndex += 1;
242
+ }
243
+ state.pendingStructuralParents = 0;
244
+ setHydrationCursor(state, parent, end);
245
+ }
246
+ function claimHydrationSuspenseFallback(parent) {
247
+ const state = activeHydration;
248
+ if (state === void 0) return void 0;
249
+ const marker = cursor(state, parent);
250
+ if (!isMarker(marker, `v2:p`)) return void 0;
251
+ setHydrationCursor(state, parent, marker.nextSibling);
252
+ return marker;
253
+ }
254
+ function withoutHydration(operation) {
255
+ const previous = activeHydration;
256
+ activeHydration = void 0;
257
+ try {
258
+ return operation();
259
+ } finally {
260
+ activeHydration = previous;
261
+ }
262
+ }
263
+ function withHydrationInsertion(parent, before, operation) {
264
+ if (activeHydration === void 0) return operation();
265
+ const previous = activeInsertionPoint;
266
+ activeInsertionPoint = [parent, before];
267
+ try {
268
+ return operation();
269
+ } finally {
270
+ activeInsertionPoint = previous;
271
+ }
272
+ }
273
+ function hydrationInsertionPoint() {
274
+ return activeInsertionPoint;
275
+ }
276
+ function hydrationCursor(parent) {
277
+ const state = activeHydration;
278
+ return state === void 0 ? void 0 : cursor(state, parent);
279
+ }
280
+ function hydrationRangeParent(start, end) {
281
+ if (activeHydration === void 0) return void 0;
282
+ const parent = start.parentNode;
283
+ if (parent === null || end.parentNode !== parent) throw mismatch("detached server marker range");
284
+ return parent;
293
285
  }
294
286
  function requireHydration() {
295
- if (activeHydration === undefined)
296
- throw new Error('no Vidact hydration is active');
297
- return activeHydration;
287
+ if (activeHydration === void 0) throw new Error("no Vidact hydration is active");
288
+ return activeHydration;
298
289
  }
299
290
  function cursor(state, parent) {
300
- if (!state.cursors.has(parent))
301
- state.cursors.set(parent, parent.firstChild);
302
- return state.cursors.get(parent) ?? null;
291
+ if (!state.cursors.has(parent)) state.cursors.set(parent, initialCursor(parent));
292
+ return state.cursors.get(parent) ?? null;
293
+ }
294
+ function initialCursor(parent) {
295
+ return parent.firstChild;
303
296
  }
304
297
  function enterHydrationSlot(state, parent) {
305
- const slots = state.slots.get(parent) ?? [];
306
- let start = cursor(state, parent);
307
- while (isMarker(start, `${HYDRATION_PREFIX}:b`)) {
308
- slots.push(findClosingSibling(start, `${HYDRATION_PREFIX}:b`));
309
- start = start.nextSibling;
310
- }
311
- if (slots.length !== 0)
312
- state.slots.set(parent, slots);
313
- state.cursors.set(parent, start);
298
+ const slots = state.slots.get(parent) ?? [];
299
+ let start = cursor(state, parent);
300
+ while (isMarker(start, `v2:b`)) {
301
+ slots.push(findClosingSibling(start, `v2:b`));
302
+ start = start.nextSibling;
303
+ }
304
+ if (slots.length !== 0) state.slots.set(parent, slots);
305
+ state.cursors.set(parent, start);
314
306
  }
315
307
  function setHydrationCursor(state, parent, value) {
316
- const slots = state.slots.get(parent);
317
- let next = value;
318
- if (slots !== undefined) {
319
- for (;;) {
320
- const end = slots.at(-1);
321
- if (end !== next)
322
- break;
323
- slots.pop();
324
- next = end.nextSibling;
325
- }
326
- }
327
- state.cursors.set(parent, next);
308
+ const slots = state.slots.get(parent);
309
+ let next = value;
310
+ if (slots !== void 0) for (;;) {
311
+ const end = slots.at(-1);
312
+ if (end !== next) break;
313
+ slots.pop();
314
+ next = end.nextSibling;
315
+ }
316
+ state.cursors.set(parent, next);
328
317
  }
329
318
  function mismatch(message) {
330
- return new HydrationMismatch(message);
319
+ return new HydrationMismatch(message);
320
+ }
321
+ /** `DIV.class-a[data-x]` — enough of an element to find it in the server markup. */
322
+ function describeNode(node) {
323
+ if (!(node instanceof Element)) return node?.nodeName ?? "null";
324
+ const classes = node.classList.length === 0 ? "" : `.${[...node.classList].join(".")}`;
325
+ const data = [...node.attributes].filter((attribute) => attribute.name.startsWith("data-") || attribute.name === "id").map((attribute) => `[${attribute.name}]`).join("");
326
+ return `${node.nodeName}${classes}${data}`;
331
327
  }
332
328
  function markerValue(node) {
333
- return node instanceof Comment ? node.data : undefined;
329
+ return node instanceof Comment ? node.data : void 0;
334
330
  }
335
331
  function isMarker(node, value) {
336
- return markerValue(node) === value;
332
+ return markerValue(node) === value;
337
333
  }
338
334
  function findClosingSibling(start, kind) {
339
- let depth = 0;
340
- for (let node = start.nextSibling; node !== null; node = node.nextSibling) {
341
- if (isMarker(node, kind)) {
342
- depth += 1;
343
- continue;
344
- }
345
- if (!isMarker(node, `/${kind}`))
346
- continue;
347
- if (depth === 0)
348
- return node;
349
- depth -= 1;
350
- }
351
- throw mismatch(`missing closing ${kind} marker`);
352
- }
335
+ let depth = 0;
336
+ for (let node = start.nextSibling; node !== null; node = node.nextSibling) {
337
+ if (isMarker(node, kind)) {
338
+ depth += 1;
339
+ continue;
340
+ }
341
+ if (!isMarker(node, `/${kind}`)) continue;
342
+ if (depth === 0) return node;
343
+ depth -= 1;
344
+ }
345
+ throw mismatch(`missing closing ${kind} marker`);
346
+ }
347
+ /** Paired markers; `p` (pending fallback) is a lone marker and stays out of the stacks. */
348
+ const RANGE_MARKER = new RegExp(`^\\/?v2:([abchr])$`);
353
349
  function scanRanges(host) {
354
- const roots = [];
355
- const components = [];
356
- const stacks = new Map();
357
- const walker = document.createTreeWalker(host, NodeFilter.SHOW_COMMENT);
358
- for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
359
- const comment = node;
360
- const match = comment.data.match(/^\/?vidact:v1:([abchrst])$/);
361
- if (match === null)
362
- continue;
363
- const kind = match[1];
364
- if (!comment.data.startsWith('/')) {
365
- const stack = stacks.get(kind) ?? [];
366
- stack.push(comment);
367
- stacks.set(kind, stack);
368
- continue;
369
- }
370
- const start = stacks.get(kind)?.pop();
371
- if (start === undefined)
372
- throw mismatch(`orphan closing vidact:v1:${kind} marker`);
373
- if (kind === 'r')
374
- roots.push([start, comment]);
375
- if (kind === 'c')
376
- components.push([start, comment]);
377
- }
378
- if ([...stacks.values()].some((stack) => stack.length !== 0)) {
379
- throw mismatch('unclosed vidact:v1 hydration marker');
380
- }
381
- components.sort(([left], [right]) => {
382
- const position = left.compareDocumentPosition(right);
383
- if (position & Node.DOCUMENT_POSITION_FOLLOWING)
384
- return -1;
385
- if (position & Node.DOCUMENT_POSITION_PRECEDING)
386
- return 1;
387
- return 0;
388
- });
389
- return { roots, components };
350
+ const roots = [];
351
+ const components = [];
352
+ const stacks = /* @__PURE__ */ new Map();
353
+ const walker = document.createTreeWalker(host, NodeFilter.SHOW_COMMENT);
354
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
355
+ const comment = node;
356
+ const match = RANGE_MARKER.exec(comment.data);
357
+ if (match === null) continue;
358
+ const kind = match[1];
359
+ if (!comment.data.startsWith("/")) {
360
+ const stack = stacks.get(kind) ?? [];
361
+ stack.push(comment);
362
+ stacks.set(kind, stack);
363
+ continue;
364
+ }
365
+ const start = stacks.get(kind)?.pop();
366
+ if (start === void 0) throw mismatch(`orphan closing v2:${kind} marker`);
367
+ if (kind === "r") roots.push([start, comment]);
368
+ if (kind === "c") components.push([start, comment]);
369
+ }
370
+ if ([...stacks.values()].some((stack) => stack.length !== 0)) throw mismatch(`unclosed v2 hydration marker`);
371
+ components.sort(([left], [right]) => {
372
+ const position = left.compareDocumentPosition(right);
373
+ if (position & Node.DOCUMENT_POSITION_FOLLOWING) return -1;
374
+ if (position & Node.DOCUMENT_POSITION_PRECEDING) return 1;
375
+ return 0;
376
+ });
377
+ return {
378
+ roots,
379
+ components
380
+ };
390
381
  }
391
382
  function collectPostorderElements(root) {
392
- const elements = [];
393
- const visit = (element) => {
394
- visitChildren(element);
395
- elements.push(element);
396
- };
397
- const visitChildren = (parent) => {
398
- let opaqueDepth = 0;
399
- for (const child of parent.childNodes) {
400
- if (isMarker(child, `${HYDRATION_PREFIX}:h`)) {
401
- opaqueDepth += 1;
402
- continue;
403
- }
404
- if (isMarker(child, `/${HYDRATION_PREFIX}:h`)) {
405
- opaqueDepth -= 1;
406
- continue;
407
- }
408
- if (opaqueDepth === 0 && child instanceof Element)
409
- visit(child);
410
- }
411
- if (opaqueDepth !== 0)
412
- throw mismatch('unbalanced vidact:v1 raw HTML marker range');
413
- };
414
- let opaqueDepth = 0;
415
- for (let node = root[0].nextSibling; node !== null && node !== root[1]; node = node.nextSibling) {
416
- if (isMarker(node, `${HYDRATION_PREFIX}:h`)) {
417
- opaqueDepth += 1;
418
- continue;
419
- }
420
- if (isMarker(node, `/${HYDRATION_PREFIX}:h`)) {
421
- opaqueDepth -= 1;
422
- continue;
423
- }
424
- if (opaqueDepth === 0 && node instanceof Element)
425
- visit(node);
426
- }
427
- if (opaqueDepth !== 0)
428
- throw mismatch('unbalanced vidact:v1 raw HTML marker range');
429
- return elements;
383
+ const elements = [];
384
+ const visit = (element) => {
385
+ visitChildren(element);
386
+ elements.push(element);
387
+ };
388
+ const visitChildren = (parent) => {
389
+ let opaqueDepth = 0;
390
+ for (const child of parent.childNodes) {
391
+ if (isMarker(child, `v2:h`)) {
392
+ opaqueDepth += 1;
393
+ continue;
394
+ }
395
+ if (isMarker(child, `/v2:h`)) {
396
+ opaqueDepth -= 1;
397
+ continue;
398
+ }
399
+ if (opaqueDepth === 0 && child instanceof Element) visit(child);
400
+ }
401
+ if (opaqueDepth !== 0) throw mismatch(`unbalanced v2 raw HTML marker range`);
402
+ };
403
+ let opaqueDepth = 0;
404
+ for (let node = root[0].nextSibling; node !== null && node !== root[1]; node = node.nextSibling) {
405
+ if (isMarker(node, `v2:h`)) {
406
+ opaqueDepth += 1;
407
+ continue;
408
+ }
409
+ if (isMarker(node, `/v2:h`)) {
410
+ opaqueDepth -= 1;
411
+ continue;
412
+ }
413
+ if (opaqueDepth === 0 && node instanceof Element) visit(node);
414
+ }
415
+ if (opaqueDepth !== 0) throw mismatch(`unbalanced v2 raw HTML marker range`);
416
+ return elements;
430
417
  }
431
418
  function collectElementComponents(host) {
432
- const owners = new WeakMap();
433
- const components = [];
434
- const walker = document.createTreeWalker(host, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT);
435
- for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
436
- if (isMarker(node, `${HYDRATION_PREFIX}:c`)) {
437
- components.push(node);
438
- continue;
439
- }
440
- if (isMarker(node, `/${HYDRATION_PREFIX}:c`)) {
441
- components.pop();
442
- continue;
443
- }
444
- if (node instanceof Element) {
445
- const owner = components.at(-1);
446
- if (owner !== undefined)
447
- owners.set(node, owner);
448
- }
449
- }
450
- return owners;
419
+ const owners = /* @__PURE__ */ new WeakMap();
420
+ const components = [];
421
+ const walker = document.createTreeWalker(host, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT);
422
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
423
+ if (isMarker(node, `v2:c`)) {
424
+ components.push(node);
425
+ continue;
426
+ }
427
+ if (isMarker(node, `/v2:c`)) {
428
+ components.pop();
429
+ continue;
430
+ }
431
+ if (node instanceof Element) {
432
+ const owner = components.at(-1);
433
+ if (owner !== void 0) owners.set(node, owner);
434
+ }
435
+ }
436
+ return owners;
451
437
  }
452
438
  function containsArrayMarker(element) {
453
- const walker = document.createTreeWalker(element, NodeFilter.SHOW_COMMENT);
454
- for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) {
455
- if (isMarker(node, `${HYDRATION_PREFIX}:a`))
456
- return true;
457
- }
458
- return false;
459
- }
460
- export function installHydration() {
461
- installHydrationOperations({
462
- begin: beginHydration,
463
- finish: finishHydration,
464
- rootMarkers: hydrationRootMarkers,
465
- active: isHydrating,
466
- createFragment: createHydrationFragment,
467
- fragmentChildren: hydrationFragmentChildren,
468
- claimElement: claimHydrationElement,
469
- noteStructuralParent: noteHydrationStructuralParent,
470
- claimComponentRange: claimHydrationComponentRange,
471
- withComponentRange: withHydrationComponentRange,
472
- withCursor: withHydrationCursor,
473
- claimNode: claimHydrationNode,
474
- claimComponentMount: claimHydrationComponentMount,
475
- claimText: claimHydrationText,
476
- claimTextRange: claimHydrationTextRange,
477
- claimArrayRange: claimHydrationArrayRange,
478
- finishArrayRange: finishHydrationArrayRange,
479
- claimSlotRange: claimHydrationSlotRange,
480
- borrowSlotRange: borrowHydrationSlotRange,
481
- claimSuspenseFallback: claimHydrationSuspenseFallback,
482
- withoutHydration,
483
- withInsertion: withHydrationInsertion,
484
- insertionPoint: hydrationInsertionPoint,
485
- cursor: hydrationCursor,
486
- rangeParent: hydrationRangeParent,
487
- });
488
- }
439
+ const walker = document.createTreeWalker(element, NodeFilter.SHOW_COMMENT);
440
+ for (let node = walker.nextNode(); node !== null; node = walker.nextNode()) if (isMarker(node, `v2:a`)) return true;
441
+ return false;
442
+ }
443
+ function installHydration() {
444
+ installHydrationOperations({
445
+ begin: beginHydration,
446
+ finish: finishHydration,
447
+ rootMarkers: hydrationRootMarkers,
448
+ active: isHydrating,
449
+ createFragment: createHydrationFragment,
450
+ fragmentChildren: hydrationFragmentChildren,
451
+ claimElement: claimHydrationElement,
452
+ noteStructuralParent: noteHydrationStructuralParent,
453
+ claimComponentRange: claimHydrationComponentRange,
454
+ withComponentRange: withHydrationComponentRange,
455
+ withCursor: withHydrationCursor,
456
+ claimNode: claimHydrationNode,
457
+ claimComponentMount: claimHydrationComponentMount,
458
+ claimText: claimHydrationText,
459
+ claimTextRange: claimHydrationTextRange,
460
+ claimArrayRange: claimHydrationArrayRange,
461
+ finishArrayRange: finishHydrationArrayRange,
462
+ claimSlotRange: claimHydrationSlotRange,
463
+ borrowSlotRange: borrowHydrationSlotRange,
464
+ claimSuspenseFallback: claimHydrationSuspenseFallback,
465
+ skipRange: skipHydrationRange,
466
+ withoutHydration,
467
+ withInsertion: withHydrationInsertion,
468
+ insertionPoint: hydrationInsertionPoint,
469
+ cursor: hydrationCursor,
470
+ rangeParent: hydrationRangeParent
471
+ });
472
+ }
473
+ //#endregion
474
+ export { beginHydration, borrowHydrationSlotRange, claimHydrationArrayRange, claimHydrationComponentMount, claimHydrationComponentRange, claimHydrationElement, claimHydrationNode, claimHydrationSlotRange, claimHydrationSuspenseFallback, claimHydrationText, claimHydrationTextRange, createHydrationFragment, finishHydration, finishHydrationArrayRange, hydrationCursor, hydrationFragmentChildren, hydrationInsertionPoint, hydrationRangeParent, hydrationRootMarkers, installHydration, isHydrating, isHydrationMismatch, noteHydrationStructuralParent, skipHydrationRange, withHydrationComponentRange, withHydrationCursor, withHydrationInsertion, withoutHydration };
475
+
489
476
  //# sourceMappingURL=hydration.js.map