what-core 0.13.11 → 0.15.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 (145) hide show
  1. package/LICENSE +21 -0
  2. package/README.md +64 -38
  3. package/a11y.d.ts +128 -0
  4. package/data.d.ts +294 -0
  5. package/dist/a11y.js +510 -0
  6. package/dist/a11y.min.js +413 -0
  7. package/dist/actions.js +158 -0
  8. package/dist/actions.min.js +112 -0
  9. package/dist/animation.js +481 -0
  10. package/dist/animation.min.js +295 -0
  11. package/dist/async.js +180 -0
  12. package/dist/async.min.js +134 -0
  13. package/dist/components.js +577 -0
  14. package/dist/components.min.js +413 -0
  15. package/dist/data.js +1212 -0
  16. package/dist/data.min.js +918 -0
  17. package/dist/diagnostics.js +187 -0
  18. package/dist/diagnostics.min.js +134 -0
  19. package/dist/dom.js +796 -0
  20. package/dist/dom.min.js +603 -0
  21. package/dist/entries/a11y.js +43 -0
  22. package/dist/entries/a11y.min.js +43 -0
  23. package/dist/entries/data.js +29 -0
  24. package/dist/entries/data.min.js +29 -0
  25. package/dist/entries/dom.js +45 -0
  26. package/dist/entries/dom.min.js +45 -0
  27. package/dist/entries/form.js +31 -0
  28. package/dist/entries/form.min.js +31 -0
  29. package/dist/entries/internal.js +123 -0
  30. package/dist/entries/internal.min.js +123 -0
  31. package/dist/entries/motion.js +23 -0
  32. package/dist/entries/motion.min.js +23 -0
  33. package/dist/entries/ui.js +25 -0
  34. package/dist/entries/ui.min.js +25 -0
  35. package/dist/env.js +5 -0
  36. package/dist/env.min.js +5 -0
  37. package/dist/errors.js +1518 -0
  38. package/dist/errors.min.js +548 -0
  39. package/dist/form.js +936 -0
  40. package/dist/form.min.js +703 -0
  41. package/dist/guardrails.js +84 -0
  42. package/dist/guardrails.min.js +55 -0
  43. package/dist/h.js +232 -0
  44. package/dist/h.min.js +171 -0
  45. package/dist/head.js +241 -0
  46. package/dist/head.min.js +207 -0
  47. package/dist/helpers.js +126 -0
  48. package/dist/helpers.min.js +98 -0
  49. package/dist/hooks.js +255 -0
  50. package/dist/hooks.min.js +153 -0
  51. package/dist/hot.js +215 -0
  52. package/dist/hot.min.js +24 -0
  53. package/dist/hydration-data.js +495 -0
  54. package/dist/hydration-data.min.js +371 -0
  55. package/dist/import-changes.js +273 -0
  56. package/dist/import-changes.min.js +272 -0
  57. package/dist/index.js +95 -0
  58. package/dist/index.min.js +95 -227
  59. package/dist/jsx-dev-runtime.js +10 -0
  60. package/dist/jsx-dev-runtime.min.js +10 -1
  61. package/dist/jsx-runtime.js +27 -0
  62. package/dist/jsx-runtime.min.js +15 -1
  63. package/dist/live.js +54 -0
  64. package/dist/live.min.js +49 -0
  65. package/dist/markup-rules.js +250 -0
  66. package/dist/markup-rules.min.js +213 -0
  67. package/dist/reactive.js +3334 -0
  68. package/dist/reactive.min.js +2033 -0
  69. package/dist/render.js +4746 -0
  70. package/dist/render.min.js +2797 -1
  71. package/dist/scheduler.js +225 -0
  72. package/dist/scheduler.min.js +162 -0
  73. package/dist/selector.js +11 -0
  74. package/dist/selector.min.js +10 -0
  75. package/dist/server-context.js +148 -0
  76. package/dist/server-context.min.js +121 -0
  77. package/dist/skeleton.js +342 -0
  78. package/dist/skeleton.min.js +310 -0
  79. package/dist/store.js +72 -0
  80. package/dist/store.min.js +50 -0
  81. package/dist/testing.js +720 -0
  82. package/dist/testing.min.js +458 -1
  83. package/dist/vnode-adoption.js +19 -0
  84. package/dist/vnode-adoption.min.js +19 -0
  85. package/dist/vnode-renderer.js +61 -0
  86. package/dist/vnode-renderer.min.js +47 -0
  87. package/dom.d.ts +44 -0
  88. package/form.d.ts +218 -0
  89. package/hot.d.ts +35 -0
  90. package/index.d.ts +421 -736
  91. package/internal.d.ts +284 -0
  92. package/jsx-runtime.d.ts +160 -137
  93. package/markup-rules.d.ts +83 -0
  94. package/motion.d.ts +156 -0
  95. package/package.json +117 -3
  96. package/render.d.ts +278 -29
  97. package/src/a11y.js +64 -59
  98. package/src/actions.js +226 -0
  99. package/src/animation.js +105 -57
  100. package/src/async.js +259 -0
  101. package/src/components.js +495 -144
  102. package/src/data.js +1410 -1159
  103. package/src/diagnostics.js +263 -0
  104. package/src/dom.js +1159 -872
  105. package/src/entries/a11y.js +24 -0
  106. package/src/entries/data.js +17 -0
  107. package/src/entries/dom.js +29 -0
  108. package/src/entries/form.js +16 -0
  109. package/src/entries/internal.js +63 -0
  110. package/src/entries/motion.js +13 -0
  111. package/src/entries/ui.js +13 -0
  112. package/src/env-development.js +12 -0
  113. package/src/env.js +33 -0
  114. package/src/errors.js +1144 -168
  115. package/src/form.js +723 -225
  116. package/src/guardrails.js +38 -126
  117. package/src/h.js +227 -152
  118. package/src/head.js +189 -19
  119. package/src/helpers.js +47 -75
  120. package/src/hooks.js +233 -248
  121. package/src/hot.js +316 -0
  122. package/src/hydration-data.js +859 -16
  123. package/src/import-changes.js +156 -0
  124. package/src/index.js +38 -188
  125. package/src/jsx-dev-runtime.js +7 -14
  126. package/src/jsx-runtime.js +25 -9
  127. package/src/live.js +80 -0
  128. package/src/markup-rules.js +387 -0
  129. package/src/reactive.js +4400 -862
  130. package/src/render.js +6502 -2570
  131. package/src/scheduler.js +56 -21
  132. package/src/selector.js +31 -0
  133. package/src/server-context.js +252 -22
  134. package/src/skeleton.js +22 -12
  135. package/src/store.js +17 -31
  136. package/src/testing.js +389 -63
  137. package/src/vnode-adoption.js +48 -0
  138. package/src/vnode-renderer.js +114 -0
  139. package/testing.d.ts +81 -1
  140. package/ui.d.ts +20 -0
  141. package/dist/chunk-6YOUZ6T4.min.js +0 -1
  142. package/dist/chunk-FN6HXME3.min.js +0 -11
  143. package/dist/chunk-VKZY7JPN.min.js +0 -1
  144. package/src/agent-context.js +0 -127
  145. package/src/warnings.js +0 -193
@@ -0,0 +1,577 @@
1
+ // src/components.js
2
+ import { h, _vnode, lowered } from "./h.js";
3
+ import {
4
+ signal,
5
+ effect,
6
+ untrack,
7
+ getOwner,
8
+ runWithOwner,
9
+ createRoot,
10
+ onCleanup,
11
+ _handleError,
12
+ _isDisposed,
13
+ HANDLED,
14
+ _trackWork,
15
+ _beginWork,
16
+ _retryErrors,
17
+ _errorSource,
18
+ _setUserEffectGate,
19
+ _releaseUserEffect,
20
+ _committingTransition,
21
+ __devtools
22
+ } from "./reactive.js";
23
+ import { report, recordObservation } from "./diagnostics.js";
24
+ import { isServerRender } from "./server-context.js";
25
+ import { hydrate, insert, _enableSuspense, _hydrationErrorHook, _toFunctionComponent, _withCursor } from "./render.js";
26
+ import { createDOM, _handleNavigationSignal, _place } from "./dom.js";
27
+ import { _islandHost } from "./hydration-data.js";
28
+ function memo(Component, _areEqual) {
29
+ const render = _toFunctionComponent(Component);
30
+ const MemoWrapper = function MemoWrapper2(props) {
31
+ return render(props);
32
+ };
33
+ MemoWrapper.displayName = `Memo(${Component.name || "Anonymous"})`;
34
+ return MemoWrapper;
35
+ }
36
+ function lazy(loader) {
37
+ _enableSuspense();
38
+ let Component = null;
39
+ let loading = null;
40
+ let failed = null;
41
+ let awaited = false;
42
+ const listeners = /* @__PURE__ */ new Set();
43
+ function load() {
44
+ failed = null;
45
+ awaited = false;
46
+ const download = loading = new Promise((resolve) => resolve(loader())).then((mod) => {
47
+ Component = mod.default || mod;
48
+ listeners.forEach((fn) => fn());
49
+ listeners.clear();
50
+ }, (error) => {
51
+ if (awaited) failed = { error };
52
+ else if (loading === download) loading = null;
53
+ });
54
+ return download;
55
+ }
56
+ function LazyWrapper(props) {
57
+ if (Component) return h(Component, props);
58
+ if (failed !== null) {
59
+ const shown = failed;
60
+ queueMicrotask(() => {
61
+ if (failed === shown) failed = loading = null;
62
+ });
63
+ throw shown.error;
64
+ }
65
+ if (loading === null) load();
66
+ awaited = true;
67
+ throw loading;
68
+ }
69
+ LazyWrapper.displayName = "Lazy";
70
+ LazyWrapper._lazy = true;
71
+ LazyWrapper._load = (prefetch) => {
72
+ if (Component) return null;
73
+ if (loading === null || failed !== null) load();
74
+ if (!prefetch) awaited = true;
75
+ return loading;
76
+ };
77
+ LazyWrapper._onLoad = (fn) => {
78
+ if (Component) fn();
79
+ else listeners.add(fn);
80
+ };
81
+ return LazyWrapper;
82
+ }
83
+ function deferChildren(Component) {
84
+ Component._deferChildren = true;
85
+ return Component;
86
+ }
87
+ var Suspense = /* @__PURE__ */ deferChildren(function Suspense2(props) {
88
+ const b = createSuspense(props);
89
+ const children = props.children;
90
+ return _vnode("__suspense", { get fallback() {
91
+ return b.fallback;
92
+ }, boundary: b }, Array.isArray(children) ? children : [children]);
93
+ });
94
+ var unrevealed = 0;
95
+ function gateUserEffect(e) {
96
+ if (unrevealed === 0) return false;
97
+ let target = null;
98
+ for (let o = e.owner; o != null; o = o.owner) {
99
+ const b = o._suspense;
100
+ if (b !== void 0 && !b.revealed) target = b;
101
+ }
102
+ if (target === null) return false;
103
+ target.deferred.push(e);
104
+ return true;
105
+ }
106
+ function awaitSuspended(waiting, link) {
107
+ const done = () => {
108
+ const b = link.b;
109
+ if (b === null) return;
110
+ b.links.delete(link);
111
+ b.thenables--;
112
+ b.check();
113
+ };
114
+ waiting.then(done, done);
115
+ }
116
+ function createSuspense(props) {
117
+ _enableSuspense();
118
+ const b = {
119
+ get fallback() {
120
+ return _place(props, "fallback");
121
+ },
122
+ revealed: false,
123
+ hydrating: false,
124
+ /** @type {Set<any>} held effects and bindings that have not completed a run since */
125
+ waiting: /* @__PURE__ */ new Set(),
126
+ /** promises of suspended components not settled yet */
127
+ thenables: 0,
128
+ /** @type {Set<{ b: any }>} what each of those promises reaches the boundary through */
129
+ links: /* @__PURE__ */ new Set(),
130
+ /** @type {any[]} user-phase effects waiting for the reveal */
131
+ deferred: [],
132
+ /** @type {(() => void) | null} */
133
+ show: null,
134
+ /** @type {(() => void) | null} */
135
+ conceal: null,
136
+ attached: false,
137
+ queued: false,
138
+ // `waiting` is a promise a component suspended on, or an effect or
139
+ // binding held on a value that is not ready. For an effect it counts,
140
+ // it returns the function the engine calls when the effect stops waiting.
141
+ onPending(waiting) {
142
+ if (b.revealed) {
143
+ if (waiting.showsFallback !== true) return null;
144
+ if ((process.env.NODE_ENV !== "production") && _committingTransition()) report("ERR_SUSPEND_IN_TRANSITION", { data: { component: waiting.component } });
145
+ b.revealed = false;
146
+ unrevealed++;
147
+ queueMicrotask(() => {
148
+ if (!b.revealed && b.conceal !== null) b.conceal();
149
+ });
150
+ }
151
+ if ((process.env.NODE_ENV !== "production")) recordObservation(
152
+ __devtools,
153
+ "suspense:waiting",
154
+ b,
155
+ /** @type {any} */
156
+ b.devOwner
157
+ );
158
+ if (typeof waiting.then !== "function") {
159
+ b.waiting.add(waiting);
160
+ return b.release;
161
+ }
162
+ b.thenables++;
163
+ _trackWork(waiting);
164
+ const link = { b };
165
+ b.links.add(link);
166
+ awaitSuspended(waiting, link);
167
+ return null;
168
+ },
169
+ // A counted effect completed a run, failed, or was disposed. Look again
170
+ // after the flush that is running (or the current task), when every
171
+ // binding that runs in it has run, and count the look as work settled()
172
+ // waits for.
173
+ release(e) {
174
+ b.waiting.delete(e);
175
+ b.schedule();
176
+ },
177
+ schedule() {
178
+ if (b.queued || b.revealed) return;
179
+ b.queued = true;
180
+ const done = _beginWork();
181
+ queueMicrotask(() => {
182
+ b.queued = false;
183
+ b.check();
184
+ done();
185
+ });
186
+ },
187
+ check() {
188
+ if (b.revealed || b.hydrating) return;
189
+ for (const e of b.waiting) if (_isDisposed(e)) b.waiting.delete(e);
190
+ if (b.waiting.size === 0 && b.thenables === 0) b.reveal();
191
+ },
192
+ reveal() {
193
+ b.revealed = true;
194
+ if ((process.env.NODE_ENV !== "production")) recordObservation(
195
+ __devtools,
196
+ "suspense:revealed",
197
+ b,
198
+ /** @type {any} */
199
+ b.devOwner
200
+ );
201
+ unrevealed--;
202
+ if (b.show !== null) b.show();
203
+ const deferred = b.deferred;
204
+ b.deferred = [];
205
+ for (const e of deferred) if (!gateUserEffect(e)) _releaseUserEffect(e);
206
+ },
207
+ // Start counting: the children are about to be built under `root`.
208
+ attach(root, hydrating) {
209
+ root._onPending = b.onPending;
210
+ root._suspense = b;
211
+ if (b.revealed || b.attached) return;
212
+ b.attached = true;
213
+ b.hydrating = hydrating;
214
+ unrevealed++;
215
+ _setUserEffectGate(gateUserEffect);
216
+ runWithOwner(root.owner, () => onCleanup(() => {
217
+ for (const link of b.links) link.b = null;
218
+ b.links.clear();
219
+ if (!b.revealed) {
220
+ b.revealed = true;
221
+ if ((process.env.NODE_ENV !== "production")) recordObservation(__devtools, "suspense:disposed", b);
222
+ unrevealed--;
223
+ }
224
+ }));
225
+ },
226
+ // Hydration: the children have been walked. The server's content is on
227
+ // screen unless a component suspended, so that is the reveal; a binding
228
+ // waiting for a value only the client fetches keeps the server's content
229
+ // up meanwhile.
230
+ walked() {
231
+ b.hydrating = false;
232
+ if (b.thenables === 0) {
233
+ b.waiting.clear();
234
+ if (!b.revealed) b.reveal();
235
+ }
236
+ },
237
+ mount: mountSuspense
238
+ };
239
+ if ((process.env.NODE_ENV !== "production")) b.devOwner = getOwner();
240
+ return b;
241
+ }
242
+ function buildArm(vnodes, end) {
243
+ return createRoot((dispose) => {
244
+ for (const v of Array.isArray(vnodes) ? vnodes : [vnodes]) {
245
+ const node = createDOM(v, end.parentNode);
246
+ if (node) end.parentNode.insertBefore(node, end);
247
+ }
248
+ return dispose;
249
+ });
250
+ }
251
+ function mountSuspense(vnode, parent) {
252
+ const b = vnode.props.boundary;
253
+ const owner = getOwner();
254
+ const start = document.createComment("sb:start");
255
+ const end = document.createComment("sb:end");
256
+ start._rangeEnd = end;
257
+ const container = document.createDocumentFragment();
258
+ container.appendChild(start);
259
+ container.appendChild(end);
260
+ const holder = document.createDocumentFragment();
261
+ createRoot(() => {
262
+ b.attach(getOwner(), false);
263
+ for (const v of vnode.children) {
264
+ const node = createDOM(v, parent);
265
+ if (node) holder.appendChild(node);
266
+ }
267
+ });
268
+ let fallbackArm = null;
269
+ b.show = () => {
270
+ if (fallbackArm !== null) {
271
+ fallbackArm();
272
+ fallbackArm = null;
273
+ for (let n = start.nextSibling; n !== null && n !== end; n = start.nextSibling) n.remove();
274
+ }
275
+ end.parentNode.insertBefore(holder, end);
276
+ };
277
+ b.conceal = () => {
278
+ for (let n = start.nextSibling; n !== null && n !== end; n = start.nextSibling) holder.appendChild(n);
279
+ fallbackArm = runWithOwner(owner, () => buildArm(b.fallback, end));
280
+ };
281
+ b.check();
282
+ if (!b.revealed) fallbackArm = buildArm(b.fallback, end);
283
+ onCleanup(() => {
284
+ if (fallbackArm !== null) fallbackArm();
285
+ });
286
+ return container;
287
+ }
288
+ var ErrorBoundary = /* @__PURE__ */ deferChildren(function ErrorBoundary2(props) {
289
+ const { children, onError } = props;
290
+ const errorState = signal(null);
291
+ const caught = [];
292
+ const handleError = (error) => {
293
+ const source = _errorSource(error);
294
+ if (source !== null) caught.push(source);
295
+ errorState.set(error);
296
+ if (onError) {
297
+ try {
298
+ onError(error);
299
+ } catch (e) {
300
+ console.error("Error in onError handler:", e);
301
+ }
302
+ }
303
+ };
304
+ const reset = () => {
305
+ _retryErrors(caught.splice(0));
306
+ errorState.set(null);
307
+ };
308
+ if ((process.env.NODE_ENV !== "production")) handleError._reset = reset;
309
+ return _vnode("__errorBoundary", {
310
+ errorState,
311
+ handleError,
312
+ reset,
313
+ mount: createErrorBoundary,
314
+ get fallback() {
315
+ return _place(props, "fallback");
316
+ }
317
+ }, Array.isArray(children) ? children : [children]);
318
+ });
319
+ function createErrorBoundary(vnode, parent) {
320
+ const { errorState, handleError, reset } = vnode.props;
321
+ const children = vnode.children;
322
+ const start = document.createComment("eb:start");
323
+ const end = document.createComment("eb:end");
324
+ start._rangeEnd = end;
325
+ const container = document.createDocumentFragment();
326
+ container.appendChild(start);
327
+ container.appendChild(end);
328
+ effect(() => {
329
+ const error = errorState();
330
+ for (let n = start.nextSibling; n !== null && n !== end; n = start.nextSibling) n.remove();
331
+ untrack(() => {
332
+ if (error) {
333
+ const fallback = vnode.props.fallback;
334
+ buildErrorArm(typeof fallback === "function" ? _toFunctionComponent(fallback)({ error, reset }) : fallback, parent, end, null);
335
+ return;
336
+ }
337
+ try {
338
+ _withCursor(buildErrorArm, children, parent, end, handleError);
339
+ } catch (err) {
340
+ if (_handleNavigationSignal(err)) return;
341
+ handleError(err);
342
+ }
343
+ });
344
+ });
345
+ return container;
346
+ }
347
+ function buildErrorArm(vnodes, parent, end, onError) {
348
+ createRoot(() => {
349
+ if (onError !== null) getOwner()._onError = onError;
350
+ for (const v of Array.isArray(vnodes) ? vnodes : [vnodes]) {
351
+ const node = createDOM(v, parent);
352
+ if (node) end.parentNode.insertBefore(node, end);
353
+ }
354
+ });
355
+ }
356
+ function reportError(error, owner) {
357
+ return _handleError(owner === void 0 ? getOwner() : owner, error) === HANDLED;
358
+ }
359
+ var Show = /* @__PURE__ */ lowered(function Show2({ when, fallback = null, children }) {
360
+ return () => {
361
+ const condition = typeof when === "function" ? when() : when;
362
+ return condition ? children : fallback;
363
+ };
364
+ });
365
+ var For = /* @__PURE__ */ lowered(function For2({ each, key, fallback = null, children }) {
366
+ const renderFn = Array.isArray(children) ? children[0] : children;
367
+ if (typeof renderFn !== "function") {
368
+ console.warn("[what] For: children must be a render function, e.g. <For each={items}>{(item) => ...}</For>");
369
+ return fallback;
370
+ }
371
+ if (typeof key === "function") return keyedFor(each, key, fallback, renderFn);
372
+ return () => {
373
+ const list = typeof each === "function" ? each() : each;
374
+ if (!list || list.length === 0) return fallback;
375
+ return list.map((item, index) => {
376
+ const vnode = renderFn(item, index);
377
+ if (vnode && typeof vnode === "object" && vnode.key == null) {
378
+ if (item != null && typeof item === "object") {
379
+ if (item.id != null) vnode.key = item.id;
380
+ else if (item.key != null) vnode.key = item.key;
381
+ } else if (typeof item === "string" || typeof item === "number") {
382
+ vnode.key = item;
383
+ vnode._itemKey = true;
384
+ }
385
+ }
386
+ return vnode;
387
+ });
388
+ };
389
+ });
390
+ function keyedFor(each, key, fallback, renderFn) {
391
+ let rows = /* @__PURE__ */ new Map();
392
+ return () => {
393
+ const list = typeof each === "function" ? each() : each;
394
+ const next = /* @__PURE__ */ new Map();
395
+ if (!list || list.length === 0) {
396
+ rows = next;
397
+ return fallback;
398
+ }
399
+ const out = list.map((item, index) => {
400
+ const k = key(item);
401
+ let row = rows.get(k);
402
+ if (row === void 0 || next.has(k)) {
403
+ const cell = signal(item);
404
+ row = { item: cell, vnode: untrack(() => renderFn(() => cell(), index)) };
405
+ if (row.vnode && typeof row.vnode === "object") row.vnode.key = k;
406
+ } else {
407
+ row.item(item);
408
+ }
409
+ next.set(k, row);
410
+ return row.vnode;
411
+ });
412
+ rows = next;
413
+ return out;
414
+ };
415
+ }
416
+ var Switch = /* @__PURE__ */ lowered(function Switch2({ fallback = null, children }) {
417
+ const kids = Array.isArray(children) ? children : [children];
418
+ return () => {
419
+ for (const child of kids) {
420
+ if (child && child.tag === Match) {
421
+ const when = child.props.when;
422
+ const condition = typeof when === "function" ? when() : when;
423
+ if (condition) return child.children;
424
+ }
425
+ }
426
+ return fallback;
427
+ };
428
+ });
429
+ var Match = /* @__PURE__ */ lowered(function Match2(props) {
430
+ return () => {
431
+ const condition = typeof props.when === "function" ? props.when() : props.when;
432
+ return condition ? props.children : null;
433
+ };
434
+ });
435
+ function serializeIslandProps(props) {
436
+ const out = {};
437
+ for (const key in props) {
438
+ const value = props[key];
439
+ if (typeof value === "function" || typeof value === "symbol" || value === void 0) continue;
440
+ out[key] = value;
441
+ }
442
+ try {
443
+ return JSON.stringify(out);
444
+ } catch {
445
+ return "{}";
446
+ }
447
+ }
448
+ var _$Island = /* @__PURE__ */ deferChildren(function Island({ component: Component, mode, mediaQuery, name, props: own, children, ...rest }) {
449
+ const props = own === void 0 ? rest : own;
450
+ if ((process.env.NODE_ENV !== "production") && !name) {
451
+ const component = Component?.name || "anonymous";
452
+ report("ERR_ISLAND_WITHOUT_NAME", { data: { component }, subject: { kind: "component", name: component } });
453
+ }
454
+ const islandName = name || Component?.name || "Island";
455
+ const resolvedMode = mode || "idle";
456
+ const marker = {
457
+ "data-island": islandName,
458
+ "data-island-mode": resolvedMode,
459
+ "data-hydrate": resolvedMode,
460
+ // Tells hydrateIslands() to leave this element alone: a compiler-emitted
461
+ // island holds a direct component reference and hydrates itself, so it
462
+ // needs no registry entry and must not be claimed twice.
463
+ "data-island-self": "1"
464
+ };
465
+ const childList = children == null ? [] : Array.isArray(children) ? children : [children];
466
+ if (isServerRender()) {
467
+ _islandHost();
468
+ return h(
469
+ "div",
470
+ { ...marker, "data-island-props": serializeIslandProps(props) },
471
+ h(Component, props, ...childList)
472
+ );
473
+ }
474
+ let hydrated = false;
475
+ const owner = getOwner();
476
+ const onHydrationError = _hydrationErrorHook();
477
+ function hydrateInto(el) {
478
+ if (hydrated || owner !== null && _isDisposed(owner)) return;
479
+ hydrated = true;
480
+ const vnode = h(Component, props, ...childList);
481
+ runWithOwner(owner, () => {
482
+ if (el.childNodes.length > 0) {
483
+ hydrate(vnode, el, onHydrationError === null ? void 0 : { onHydrationError });
484
+ } else {
485
+ insert(el, vnode, null);
486
+ }
487
+ });
488
+ el.removeAttribute("data-hydrate");
489
+ el.removeAttribute("data-island-self");
490
+ el.setAttribute("data-island-hydrated", "");
491
+ const view = el.ownerDocument?.defaultView ?? globalThis;
492
+ if (typeof view.CustomEvent === "function") {
493
+ el.dispatchEvent(new view.CustomEvent("island:hydrated", {
494
+ bubbles: true,
495
+ detail: { name: islandName, mode: resolvedMode }
496
+ }));
497
+ }
498
+ }
499
+ function scheduleHydration(el) {
500
+ const trigger = () => hydrateInto(el);
501
+ switch (resolvedMode) {
502
+ case "load":
503
+ queueMicrotask(trigger);
504
+ break;
505
+ case "idle":
506
+ if (typeof requestIdleCallback !== "undefined") requestIdleCallback(trigger);
507
+ else setTimeout(trigger, 200);
508
+ break;
509
+ case "visible": {
510
+ if (typeof IntersectionObserver === "undefined") {
511
+ queueMicrotask(trigger);
512
+ break;
513
+ }
514
+ const observer = new IntersectionObserver((entries) => {
515
+ if (entries.some((entry) => entry.isIntersecting)) {
516
+ observer.disconnect();
517
+ trigger();
518
+ }
519
+ }, { rootMargin: "200px" });
520
+ observer.observe(el);
521
+ break;
522
+ }
523
+ case "interaction":
524
+ case "action": {
525
+ if (el.childNodes.length === 0) {
526
+ queueMicrotask(trigger);
527
+ break;
528
+ }
529
+ const events = ["click", "focus", "mouseenter", "touchstart"];
530
+ const onInteract = () => {
531
+ for (const type of events) el.removeEventListener(type, onInteract, true);
532
+ trigger();
533
+ };
534
+ for (const type of events) el.addEventListener(type, onInteract, { capture: true, once: true });
535
+ break;
536
+ }
537
+ case "media": {
538
+ if (!mediaQuery || typeof window === "undefined" || !window.matchMedia) {
539
+ trigger();
540
+ break;
541
+ }
542
+ const mq = window.matchMedia(mediaQuery);
543
+ if (mq.matches) {
544
+ queueMicrotask(trigger);
545
+ break;
546
+ }
547
+ const onChange = () => {
548
+ if (!mq.matches) return;
549
+ mq.removeEventListener("change", onChange);
550
+ trigger();
551
+ };
552
+ mq.addEventListener("change", onChange);
553
+ break;
554
+ }
555
+ // 'static' ships no JS at all: the server HTML is the whole island.
556
+ case "static":
557
+ break;
558
+ default:
559
+ queueMicrotask(trigger);
560
+ }
561
+ }
562
+ return h("div", { ...marker, ref: (el) => {
563
+ if (el) scheduleHydration(el);
564
+ } });
565
+ });
566
+ export {
567
+ ErrorBoundary,
568
+ For,
569
+ Match,
570
+ Show,
571
+ Suspense,
572
+ Switch,
573
+ _$Island,
574
+ lazy,
575
+ memo,
576
+ reportError
577
+ };