what-core 0.8.3 → 0.10.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 (55) hide show
  1. package/dist/chunk-AW3BAPIK.js +1685 -0
  2. package/dist/chunk-AW3BAPIK.js.map +7 -0
  3. package/dist/chunk-AZP2EOGX.js +188 -0
  4. package/dist/chunk-AZP2EOGX.js.map +7 -0
  5. package/dist/chunk-F2HUXI22.js +1675 -0
  6. package/dist/chunk-F2HUXI22.js.map +7 -0
  7. package/dist/chunk-KBM6CWG4.min.js +2 -0
  8. package/dist/chunk-KBM6CWG4.min.js.map +7 -0
  9. package/dist/chunk-KL7TNUIU.min.js +2 -0
  10. package/dist/chunk-KL7TNUIU.min.js.map +7 -0
  11. package/dist/chunk-L6XOF7P4.min.js +2 -0
  12. package/dist/chunk-L6XOF7P4.min.js.map +7 -0
  13. package/dist/chunk-M7UEET5O.js +1323 -0
  14. package/dist/chunk-M7UEET5O.js.map +7 -0
  15. package/dist/chunk-O3SKPRTY.min.js +2 -0
  16. package/dist/chunk-O3SKPRTY.min.js.map +7 -0
  17. package/dist/chunk-RN6QIBWL.min.js +2 -0
  18. package/dist/chunk-RN6QIBWL.min.js.map +7 -0
  19. package/dist/chunk-VMTTYB4L.min.js +2 -0
  20. package/dist/chunk-VMTTYB4L.min.js.map +7 -0
  21. package/dist/chunk-VP4WLF5A.js +1323 -0
  22. package/dist/chunk-VP4WLF5A.js.map +7 -0
  23. package/dist/chunk-YA3W4XKH.js +1323 -0
  24. package/dist/chunk-YA3W4XKH.js.map +7 -0
  25. package/dist/index.js +212 -2785
  26. package/dist/index.js.map +4 -4
  27. package/dist/index.min.js +6 -6
  28. package/dist/index.min.js.map +4 -4
  29. package/dist/jsx-dev-runtime.js +4 -53
  30. package/dist/jsx-dev-runtime.js.map +3 -3
  31. package/dist/jsx-dev-runtime.min.js +1 -1
  32. package/dist/jsx-dev-runtime.min.js.map +4 -4
  33. package/dist/jsx-runtime.js +4 -53
  34. package/dist/jsx-runtime.js.map +3 -3
  35. package/dist/jsx-runtime.min.js +1 -1
  36. package/dist/jsx-runtime.min.js.map +4 -4
  37. package/dist/render.js +22 -2044
  38. package/dist/render.js.map +4 -4
  39. package/dist/render.min.js +1 -1
  40. package/dist/render.min.js.map +4 -4
  41. package/dist/testing.js +13 -1079
  42. package/dist/testing.js.map +4 -4
  43. package/dist/testing.min.js +1 -1
  44. package/dist/testing.min.js.map +4 -4
  45. package/package.json +2 -2
  46. package/src/dom.js +54 -6
  47. package/src/h.js +15 -3
  48. package/src/head.js +72 -2
  49. package/src/hooks.js +65 -4
  50. package/src/hydration-data.js +34 -0
  51. package/src/index.js +9 -2
  52. package/src/reactive.js +78 -1
  53. package/src/render.js +450 -105
  54. package/src/server-context.js +48 -0
  55. package/src/store.js +6 -2
package/dist/render.js CHANGED
@@ -1,2046 +1,24 @@
1
- // packages/core/src/reactive.js
2
- var __DEV__ = typeof process !== "undefined" ? true : true;
3
- var __devtools = null;
4
- var currentEffect = null;
5
- var currentRoot = null;
6
- var currentOwner = null;
7
- var insideComputed = false;
8
- var batchDepth = 0;
9
- var pendingEffects = [];
10
- var pendingNeedSort = false;
11
- var NEEDS_UPSTREAM = /* @__PURE__ */ Symbol("needs_upstream");
12
- function signal(initial, debugName) {
13
- let value = initial;
14
- const subs = /* @__PURE__ */ new Set();
15
- let lastTracked = null;
16
- let lastTrackedEpoch = 0;
17
- function _sigWrite(next) {
18
- if (__DEV__ && insideComputed) {
19
- console.warn(
20
- "[what] Signal.set() called inside a computed function. This may cause infinite loops. Use effect() instead." + (debugName ? ` (signal: ${debugName})` : "")
21
- );
22
- }
23
- const nextVal = typeof next === "function" ? next(value) : next;
24
- if (value === nextVal || value !== value && nextVal !== nextVal) return;
25
- value = nextVal;
26
- lastTracked = null;
27
- if (__DEV__ && __devtools) __devtools.onSignalUpdate(sig);
28
- if (subs.size > 0) notify(subs);
29
- }
30
- function sig(newVal) {
31
- if (arguments.length === 0) {
32
- const ce = currentEffect;
33
- if (ce !== null) {
34
- if (ce !== lastTracked || ce._epoch !== lastTrackedEpoch) {
35
- lastTracked = ce;
36
- lastTrackedEpoch = ce._epoch;
37
- subs.add(ce);
38
- ce.deps.push(subs);
39
- }
40
- }
41
- return value;
42
- }
43
- _sigWrite(newVal);
44
- }
45
- sig.set = _sigWrite;
46
- sig.peek = () => value;
47
- sig.subscribe = (fn) => {
48
- return effect(() => fn(sig()));
49
- };
50
- sig._signal = true;
51
- if (__DEV__) {
52
- sig._subs = subs;
53
- if (debugName) sig._debugName = debugName;
54
- }
55
- if (__DEV__ && __devtools) __devtools.onSignalCreate(sig);
56
- return sig;
57
- }
58
- function _updateLevel(e) {
59
- let maxDepLevel = 0;
60
- const deps = e.deps;
61
- for (let i = 0; i < deps.length; i++) {
62
- const owner = deps[i]._owner;
63
- if (owner) {
64
- const depLevel = owner._level;
65
- if (depLevel > maxDepLevel) maxDepLevel = depLevel;
66
- }
67
- }
68
- e._level = maxDepLevel + 1;
69
- }
70
- function effect(fn, opts) {
71
- const e = _createEffect(fn);
72
- e._level = 1;
73
- const prev = currentEffect;
74
- currentEffect = e;
75
- try {
76
- const result = e.fn();
77
- if (typeof result === "function") e._cleanup = result;
78
- } finally {
79
- currentEffect = prev;
80
- }
81
- _updateLevel(e);
82
- if (opts?.stable) e._stable = true;
83
- const dispose = () => _disposeEffect(e);
84
- if (currentRoot) {
85
- currentRoot.disposals.push(dispose);
86
- }
87
- return dispose;
88
- }
89
- function _createEffect(fn, lazy) {
90
- const e = {
91
- fn,
92
- deps: [],
93
- // array of subscriber sets (cheaper than Set for typical 1-3 deps)
94
- lazy: lazy || false,
95
- _onNotify: null,
96
- disposed: false,
97
- _pending: false,
98
- _stable: false,
99
- // stable effects skip cleanup/re-subscribe on re-run
100
- _level: 0,
101
- // topological depth: signals=0, computed/effects=max(deps)+1
102
- _computed: false,
103
- // true for computed inner effects
104
- _computedSubs: null,
105
- // reference to the computed's subscriber set
106
- _isDirty: null,
107
- // function to check if computed is dirty (set by computed())
108
- _markDirty: null,
109
- // function to mark computed dirty (set by computed())
110
- _cleanup: null,
111
- // cleanup function returned by effect fn (declared upfront for shape)
112
- _epoch: 0
113
- // incremented on cleanup — used by signal lastTracked cache
114
- };
115
- if (__DEV__ && __devtools) __devtools.onEffectCreate(e);
116
- return e;
117
- }
118
- function _runEffect(e) {
119
- if (e.disposed) return;
120
- if (e._stable) {
121
- if (e._cleanup) {
122
- try {
123
- e._cleanup();
124
- } catch (err) {
125
- if (__DEV__) console.warn("[what] Error in effect cleanup:", err);
126
- }
127
- e._cleanup = null;
128
- }
129
- const prev2 = currentEffect;
130
- currentEffect = null;
131
- try {
132
- const result = e.fn();
133
- if (typeof result === "function") e._cleanup = result;
134
- } catch (err) {
135
- if (__devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
136
- if (__DEV__) console.warn("[what] Error in stable effect:", err);
137
- } finally {
138
- currentEffect = prev2;
139
- }
140
- if (__DEV__ && __devtools?.onEffectRun) __devtools.onEffectRun(e);
141
- return;
142
- }
143
- const singleDep = e.deps.length === 1 ? e.deps[0] : null;
144
- cleanup(e);
145
- if (e._cleanup) {
146
- try {
147
- e._cleanup();
148
- } catch (err) {
149
- if (__DEV__ && __devtools?.onError) __devtools.onError(err, { type: "effect-cleanup", effect: e });
150
- if (__DEV__) console.warn("[what] Error in effect cleanup:", err);
151
- }
152
- e._cleanup = null;
153
- }
154
- const prev = currentEffect;
155
- currentEffect = e;
156
- try {
157
- const result = e.fn();
158
- if (typeof result === "function") {
159
- e._cleanup = result;
160
- }
161
- } catch (err) {
162
- if (err === NEEDS_UPSTREAM) throw err;
163
- if (__DEV__ && __devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
164
- throw err;
165
- } finally {
166
- currentEffect = prev;
167
- }
168
- if (singleDep !== null && e.deps.length === 1 && e.deps[0] === singleDep && !e._cleanup && !e._pending) {
169
- e._stable = true;
170
- }
171
- if (__DEV__ && __devtools?.onEffectRun) __devtools.onEffectRun(e);
172
- }
173
- function _disposeEffect(e) {
174
- e.disposed = true;
175
- if (__DEV__ && __devtools) __devtools.onEffectDispose(e);
176
- cleanup(e);
177
- if (e._cleanup) {
178
- try {
179
- e._cleanup();
180
- } catch (err) {
181
- if (__DEV__) console.warn("[what] Error in effect cleanup on dispose:", err);
182
- }
183
- e._cleanup = null;
184
- }
185
- }
186
- function cleanup(e) {
187
- const deps = e.deps;
188
- for (let i = 0; i < deps.length; i++) deps[i].delete(e);
189
- deps.length = 0;
190
- e._epoch++;
191
- }
192
- var notifyDepth = 0;
193
- var notifyQueue = null;
194
- var notifyQueueLen = 0;
195
- function _processSubscriber(e) {
196
- if (e.disposed) return;
197
- if (e._onNotify) {
198
- e._onNotify();
199
- } else if (!e._pending) {
200
- if (batchDepth === 0 && e._stable) {
201
- const prev = currentEffect;
202
- currentEffect = null;
203
- try {
204
- const result = e.fn();
205
- if (typeof result === "function") {
206
- if (e._cleanup) try {
207
- e._cleanup();
208
- } catch (err) {
209
- }
210
- e._cleanup = result;
211
- }
212
- } catch (err) {
213
- if (__DEV__ && __devtools?.onError) __devtools.onError(err, { type: "effect", effect: e });
214
- if (__DEV__) console.warn("[what] Error in stable effect:", err);
215
- } finally {
216
- currentEffect = prev;
217
- }
218
- } else {
219
- e._pending = true;
220
- const level = e._level;
221
- const len = pendingEffects.length;
222
- if (len > 0 && pendingEffects[len - 1]._level > level) {
223
- pendingNeedSort = true;
224
- }
225
- pendingEffects.push(e);
226
- }
227
- }
228
- }
229
- function notify(subs) {
230
- if (notifyDepth === 0) {
231
- notifyDepth = 1;
232
- try {
233
- for (const e of subs) {
234
- _processSubscriber(e);
235
- }
236
- if (notifyQueueLen > 0) {
237
- let qi = 0;
238
- while (qi < notifyQueueLen) {
239
- const queuedSubs = notifyQueue[qi];
240
- notifyQueue[qi] = null;
241
- qi++;
242
- for (const e of queuedSubs) {
243
- _processSubscriber(e);
244
- }
245
- }
246
- notifyQueueLen = 0;
247
- }
248
- } finally {
249
- notifyDepth = 0;
250
- }
251
- if (batchDepth === 0 && pendingEffects.length > 0) scheduleMicrotask();
252
- } else {
253
- if (notifyQueue === null) notifyQueue = [];
254
- if (notifyQueueLen >= notifyQueue.length) {
255
- notifyQueue.push(subs);
256
- } else {
257
- notifyQueue[notifyQueueLen] = subs;
258
- }
259
- notifyQueueLen++;
260
- }
261
- }
262
- var microtaskScheduled = false;
263
- function scheduleMicrotask() {
264
- if (!microtaskScheduled) {
265
- microtaskScheduled = true;
266
- queueMicrotask(() => {
267
- microtaskScheduled = false;
268
- flush();
269
- });
270
- }
271
- }
272
- var isFlushing = false;
273
- function flush() {
274
- if (isFlushing) return;
275
- isFlushing = true;
276
- try {
277
- let iterations = 0;
278
- while (pendingEffects.length > 0 && iterations < 25) {
279
- const batch2 = pendingEffects;
280
- pendingEffects = [];
281
- if (batch2.length > 1 && pendingNeedSort) {
282
- batch2.sort((a, b) => a._level - b._level);
283
- }
284
- pendingNeedSort = false;
285
- for (let i = 0; i < batch2.length; i++) {
286
- const e = batch2[i];
287
- e._pending = false;
288
- if (!e.disposed && !e._onNotify) {
289
- const prevDepsLen = e.deps.length;
290
- _runEffect(e);
291
- if (!e._computed && e.deps.length !== prevDepsLen) {
292
- _updateLevel(e);
293
- }
294
- }
295
- }
296
- iterations++;
297
- }
298
- if (iterations >= 25) {
299
- if (__DEV__) {
300
- const remaining = pendingEffects.slice(0, 3);
301
- const effectNames = remaining.map((e) => e.fn?.name || e.fn?.toString().slice(0, 60) || "(anonymous)");
302
- console.warn(
303
- `[what] Possible infinite effect loop detected (25 iterations). Likely cause: an effect writes to a signal it also reads, creating a cycle. Use untrack() to read signals without subscribing. Looping effects: ${effectNames.join(", ")}`
304
- );
305
- } else {
306
- console.warn("[what] Possible infinite effect loop detected");
307
- }
308
- for (let i = 0; i < pendingEffects.length; i++) pendingEffects[i]._pending = false;
309
- pendingEffects.length = 0;
310
- }
311
- } finally {
312
- isFlushing = false;
313
- }
314
- }
315
- function untrack(fn) {
316
- const prev = currentEffect;
317
- currentEffect = null;
318
- try {
319
- return fn();
320
- } finally {
321
- currentEffect = prev;
322
- }
323
- }
324
- function _disposeRoot(root) {
325
- if (root._disposed) return;
326
- root._disposed = true;
327
- for (let i = root.children.length - 1; i >= 0; i--) {
328
- _disposeRoot(root.children[i]);
329
- }
330
- root.children.length = 0;
331
- for (let i = root.disposals.length - 1; i >= 0; i--) {
332
- root.disposals[i]();
333
- }
334
- root.disposals.length = 0;
335
- }
336
- function _createItemScope(fn) {
337
- const prevRoot = currentRoot;
338
- const prevOwner = currentOwner;
339
- const scope = {
340
- disposals: [],
341
- owner: null,
342
- // No parent registration
343
- children: [],
344
- // Kept for compat with effects that create sub-roots
345
- _disposed: false
346
- };
347
- currentRoot = scope;
348
- currentOwner = scope;
349
- try {
350
- const dispose = () => {
351
- if (scope._disposed) return;
352
- scope._disposed = true;
353
- for (let i = scope.children.length - 1; i >= 0; i--) {
354
- _disposeRoot(scope.children[i]);
355
- }
356
- scope.children.length = 0;
357
- for (let i = scope.disposals.length - 1; i >= 0; i--) {
358
- scope.disposals[i]();
359
- }
360
- scope.disposals.length = 0;
361
- };
362
- return fn(dispose);
363
- } finally {
364
- currentRoot = prevRoot;
365
- currentOwner = prevOwner;
366
- }
367
- }
368
-
369
- // packages/core/src/components.js
370
- var _getCurrentComponent = null;
371
- function _injectGetCurrentComponent(fn) {
372
- _getCurrentComponent = fn;
373
- }
374
- function reportError(error, startCtx) {
375
- let ctx = startCtx || _getCurrentComponent?.();
376
- while (ctx) {
377
- if (ctx._errorBoundary) {
378
- ctx._errorBoundary(error);
379
- return true;
380
- }
381
- ctx = ctx._parentCtx;
382
- }
383
- return false;
384
- }
385
-
386
- // packages/core/src/helpers.js
387
- var _getCurrentComponentRef = null;
388
- function _setComponentRef(fn) {
389
- _getCurrentComponentRef = fn;
390
- }
391
-
392
- // packages/core/src/dom.js
393
- var SVG_ELEMENTS = /* @__PURE__ */ new Set([
394
- "svg",
395
- "path",
396
- "circle",
397
- "rect",
398
- "line",
399
- "polyline",
400
- "polygon",
401
- "ellipse",
402
- "g",
403
- "defs",
404
- "use",
405
- "symbol",
406
- "clipPath",
407
- "mask",
408
- "pattern",
409
- "image",
410
- "text",
411
- "tspan",
412
- "textPath",
413
- "foreignObject",
414
- "linearGradient",
415
- "radialGradient",
416
- "stop",
417
- "marker",
418
- "animate",
419
- "animateTransform",
420
- "animateMotion",
421
- "set",
422
- "filter",
423
- "feBlend",
424
- "feColorMatrix",
425
- "feComponentTransfer",
426
- "feComposite",
427
- "feConvolveMatrix",
428
- "feDiffuseLighting",
429
- "feDisplacementMap",
430
- "feFlood",
431
- "feGaussianBlur",
432
- "feImage",
433
- "feMerge",
434
- "feMergeNode",
435
- "feMorphology",
436
- "feOffset",
437
- "feSpecularLighting",
438
- "feTile",
439
- "feTurbulence"
440
- ]);
441
- var SVG_NS = "http://www.w3.org/2000/svg";
442
- var mountedComponents = /* @__PURE__ */ new Set();
443
- var _commentCtxMap = /* @__PURE__ */ new WeakMap();
444
- function isDomNode(value) {
445
- if (!value || typeof value !== "object") return false;
446
- if (typeof Node !== "undefined" && value instanceof Node) return true;
447
- return typeof value.nodeType === "number" && typeof value.nodeName === "string";
448
- }
449
- function isVNode(value) {
450
- return !!value && typeof value === "object" && (value._vnode === true || "tag" in value);
451
- }
452
- function disposeComponent(ctx) {
453
- if (ctx.disposed) return;
454
- ctx.disposed = true;
455
- if (ctx.cleanups) {
456
- for (const cleanup2 of ctx.cleanups) {
457
- try {
458
- cleanup2();
459
- } catch (e) {
460
- console.error("[what] cleanup error:", e);
461
- }
462
- }
463
- }
464
- if (ctx.effects) {
465
- for (const dispose of ctx.effects) {
466
- try {
467
- dispose();
468
- } catch (e) {
469
- }
470
- }
471
- }
472
- if (ctx.hooks) {
473
- for (const hook of ctx.hooks) {
474
- if (hook && typeof hook.cleanup === "function") {
475
- try {
476
- hook.cleanup();
477
- } catch (e) {
478
- console.error("[what] hook cleanup error:", e);
479
- }
480
- }
481
- }
482
- }
483
- if (ctx._cleanupCallbacks) {
484
- for (const fn of ctx._cleanupCallbacks) {
485
- try {
486
- fn();
487
- } catch (e) {
488
- console.error("[what] onCleanup error:", e);
489
- }
490
- }
491
- }
492
- if (__DEV__ && __devtools?.onComponentUnmount) __devtools.onComponentUnmount(ctx);
493
- mountedComponents.delete(ctx);
494
- }
495
- function disposeTree(node) {
496
- if (!node) return;
497
- if (node._componentCtx) {
498
- disposeComponent(node._componentCtx);
499
- }
500
- if (node.nodeType === 8) {
501
- const commentCtx = _commentCtxMap.get(node);
502
- if (commentCtx) {
503
- disposeComponent(commentCtx);
504
- }
505
- }
506
- if (node._dispose) {
507
- try {
508
- node._dispose();
509
- } catch (e) {
510
- }
511
- }
512
- if (node._propEffects) {
513
- for (const key in node._propEffects) {
514
- try {
515
- node._propEffects[key]();
516
- } catch (e) {
517
- }
518
- }
519
- }
520
- const children = node.childNodes;
521
- if (children && children.length > 0) {
522
- for (let i = 0; i < children.length; i++) {
523
- disposeTree(children[i]);
524
- }
525
- }
526
- }
527
- function createDOM(vnode, parent, isSvg) {
528
- if (vnode == null || vnode === false || vnode === true) {
529
- return document.createComment("");
530
- }
531
- if (typeof vnode === "string" || typeof vnode === "number") {
532
- return document.createTextNode(String(vnode));
533
- }
534
- if (isDomNode(vnode)) {
535
- return vnode;
536
- }
537
- if (typeof vnode === "function") {
538
- const startMarker = document.createComment("fn");
539
- const endMarker = document.createComment("/fn");
540
- let currentNodes = [];
541
- const frag = document.createDocumentFragment();
542
- frag.appendChild(startMarker);
543
- frag.appendChild(endMarker);
544
- const dispose = effect(() => {
545
- const val = vnode();
546
- const vnodes = val == null || val === false || val === true ? [] : Array.isArray(val) ? val : [val];
547
- const realParent = endMarker.parentNode;
548
- if (!realParent) return;
549
- for (const old of currentNodes) {
550
- disposeTree(old);
551
- if (old.parentNode === realParent) realParent.removeChild(old);
552
- }
553
- currentNodes = [];
554
- for (const v of vnodes) {
555
- const node = createDOM(v, realParent, parent?._isSvg);
556
- if (node) {
557
- if (node.nodeType === 11) {
558
- const children = Array.from(node.childNodes);
559
- realParent.insertBefore(node, endMarker);
560
- for (const child of children) currentNodes.push(child);
561
- } else {
562
- realParent.insertBefore(node, endMarker);
563
- currentNodes.push(node);
564
- }
565
- }
566
- }
567
- });
568
- startMarker._dispose = dispose;
569
- endMarker._dispose = dispose;
570
- return frag;
571
- }
572
- if (Array.isArray(vnode)) {
573
- const frag = document.createDocumentFragment();
574
- for (const child of vnode) {
575
- const node = createDOM(child, parent, isSvg);
576
- if (node) frag.appendChild(node);
577
- }
578
- return frag;
579
- }
580
- if (isVNode(vnode) && typeof vnode.tag === "function") {
581
- return createComponent(vnode, parent, isSvg);
582
- }
583
- if (isVNode(vnode)) {
584
- return createElementFromVNode(vnode, parent, isSvg);
585
- }
586
- return document.createTextNode(String(vnode));
587
- }
588
- var _propsProxyHandler = {
589
- get(target, key) {
590
- if (key === "_sig") return void 0;
591
- return target._sig()[key];
592
- },
593
- has(target, key) {
594
- if (key === "_sig") return false;
595
- return key in target._sig();
596
- },
597
- ownKeys(target) {
598
- return Reflect.ownKeys(target._sig());
599
- },
600
- getOwnPropertyDescriptor(target, key) {
601
- if (key === "_sig") return void 0;
602
- const current = target._sig();
603
- if (key in current) {
604
- return { value: current[key], writable: false, enumerable: true, configurable: true };
605
- }
606
- return void 0;
607
- }
608
- };
609
- var componentStack = [];
610
- function getCurrentComponent() {
611
- return componentStack[componentStack.length - 1];
612
- }
613
- _injectGetCurrentComponent(getCurrentComponent);
614
- _setComponentRef(getCurrentComponent);
615
- function getComponentStack() {
616
- return componentStack;
617
- }
618
- function createComponent(vnode, parent, isSvg) {
619
- let { tag: Component, props, children } = vnode;
620
- if (typeof Component === "function" && (Component.prototype?.isReactComponent || Component.prototype?.render)) {
621
- const ClassComp = Component;
622
- Component = function ClassComponentBridge(props2) {
623
- const instance = new ClassComp(props2);
624
- return instance.render();
625
- };
626
- Component.displayName = ClassComp.displayName || ClassComp.name || "ClassComponent";
627
- }
628
- if (Component === "__errorBoundary" || vnode.tag === "__errorBoundary") {
629
- return createErrorBoundary(vnode, parent);
630
- }
631
- if (Component === "__suspense" || vnode.tag === "__suspense") {
632
- return createSuspenseBoundary(vnode, parent);
633
- }
634
- if (Component === "__portal" || vnode.tag === "__portal") {
635
- return createPortalDOM(vnode, parent);
636
- }
637
- const parentCtx = componentStack[componentStack.length - 1] || null;
638
- let errorBoundary = null;
639
- if (parentCtx) {
640
- errorBoundary = parentCtx._errorBoundary || null;
641
- if (!errorBoundary) {
642
- let p = parentCtx._parentCtx;
643
- while (p) {
644
- if (p._errorBoundary) {
645
- errorBoundary = p._errorBoundary;
646
- break;
647
- }
648
- p = p._parentCtx;
649
- }
650
- }
651
- }
652
- const ctx = {
653
- hooks: [],
654
- hookIndex: 0,
655
- effects: [],
656
- cleanups: [],
657
- mounted: false,
658
- disposed: false,
659
- Component,
660
- _parentCtx: parentCtx,
661
- _errorBoundary: errorBoundary
662
- };
663
- const startComment = document.createComment("c:start");
664
- const endComment = document.createComment("c:end");
665
- _commentCtxMap.set(startComment, ctx);
666
- ctx._startComment = startComment;
667
- ctx._endComment = endComment;
668
- const container = document.createDocumentFragment();
669
- container._componentCtx = ctx;
670
- ctx._wrapper = startComment;
671
- mountedComponents.add(ctx);
672
- if (__DEV__ && __devtools?.onComponentMount) __devtools.onComponentMount(ctx);
673
- const propsChildren = children.length === 0 ? void 0 : children.length === 1 ? children[0] : children;
674
- let mergedProps;
675
- if (propsChildren !== void 0) {
676
- mergedProps = props ? Object.assign({}, props, { children: propsChildren }) : { children: propsChildren };
677
- } else {
678
- mergedProps = props ? Object.assign({}, props) : {};
679
- }
680
- const propsSignal = signal(mergedProps);
681
- ctx._propsSignal = propsSignal;
682
- const reactiveProps = new Proxy({ _sig: propsSignal }, _propsProxyHandler);
683
- componentStack.push(ctx);
684
- let result;
685
- try {
686
- result = Component(reactiveProps);
687
- } catch (error) {
688
- componentStack.pop();
689
- if (!reportError(error, ctx)) {
690
- console.error("[what] Uncaught error in component:", Component.name || "Anonymous", error);
691
- throw error;
692
- }
693
- container.appendChild(startComment);
694
- container.appendChild(endComment);
695
- return container;
696
- }
697
- componentStack.pop();
698
- ctx.mounted = true;
699
- if (ctx._mountCallbacks) {
700
- queueMicrotask(() => {
701
- if (ctx.disposed) return;
702
- for (const fn of ctx._mountCallbacks) {
703
- try {
704
- fn();
705
- } catch (e) {
706
- console.error("[what] onMount error:", e);
707
- }
708
- }
709
- });
710
- }
711
- container.appendChild(startComment);
712
- const vnodes = Array.isArray(result) ? result : [result];
713
- for (const v of vnodes) {
714
- const node = createDOM(v, container, isSvg);
715
- if (node) container.appendChild(node);
716
- }
717
- container.appendChild(endComment);
718
- return container;
719
- }
720
- function createErrorBoundary(vnode, parent) {
721
- const { errorState, handleError, fallback, reset } = vnode.props;
722
- const children = vnode.children;
723
- const startComment = document.createComment("eb:start");
724
- const endComment = document.createComment("eb:end");
725
- const boundaryCtx = {
726
- hooks: [],
727
- hookIndex: 0,
728
- effects: [],
729
- cleanups: [],
730
- mounted: false,
731
- disposed: false,
732
- _parentCtx: componentStack[componentStack.length - 1] || null,
733
- _errorBoundary: handleError,
734
- _startComment: startComment,
735
- _endComment: endComment
736
- };
737
- _commentCtxMap.set(startComment, boundaryCtx);
738
- const container = document.createDocumentFragment();
739
- container._componentCtx = boundaryCtx;
740
- container.appendChild(startComment);
741
- container.appendChild(endComment);
742
- const dispose = effect(() => {
743
- const error = errorState();
744
- componentStack.push(boundaryCtx);
745
- if (startComment.parentNode) {
746
- while (startComment.nextSibling && startComment.nextSibling !== endComment) {
747
- const old = startComment.nextSibling;
748
- disposeTree(old);
749
- old.parentNode.removeChild(old);
750
- }
751
- }
752
- let vnodes;
753
- if (error) {
754
- vnodes = typeof fallback === "function" ? [fallback({ error, reset })] : [fallback];
755
- } else {
756
- vnodes = children;
757
- }
758
- vnodes = Array.isArray(vnodes) ? vnodes : [vnodes];
759
- for (const v of vnodes) {
760
- const node = createDOM(v, parent);
761
- if (node) {
762
- if (endComment.parentNode) {
763
- endComment.parentNode.insertBefore(node, endComment);
764
- } else {
765
- container.insertBefore(node, endComment);
766
- }
767
- }
768
- }
769
- componentStack.pop();
770
- });
771
- boundaryCtx.effects.push(dispose);
772
- return container;
773
- }
774
- function createSuspenseBoundary(vnode, parent) {
775
- const { boundary, fallback, loading } = vnode.props;
776
- const children = vnode.children;
777
- const startComment = document.createComment("sb:start");
778
- const endComment = document.createComment("sb:end");
779
- const boundaryCtx = {
780
- hooks: [],
781
- hookIndex: 0,
782
- effects: [],
783
- cleanups: [],
784
- mounted: false,
785
- disposed: false,
786
- _parentCtx: componentStack[componentStack.length - 1] || null,
787
- _startComment: startComment,
788
- _endComment: endComment
789
- };
790
- _commentCtxMap.set(startComment, boundaryCtx);
791
- const container = document.createDocumentFragment();
792
- container._componentCtx = boundaryCtx;
793
- container.appendChild(startComment);
794
- container.appendChild(endComment);
795
- const dispose = effect(() => {
796
- const isLoading = loading();
797
- const vnodes = isLoading ? [fallback] : children;
798
- const normalized = Array.isArray(vnodes) ? vnodes : [vnodes];
799
- componentStack.push(boundaryCtx);
800
- if (startComment.parentNode) {
801
- while (startComment.nextSibling && startComment.nextSibling !== endComment) {
802
- const old = startComment.nextSibling;
803
- disposeTree(old);
804
- old.parentNode.removeChild(old);
805
- }
806
- }
807
- for (const v of normalized) {
808
- const node = createDOM(v, parent);
809
- if (node) {
810
- if (endComment.parentNode) {
811
- endComment.parentNode.insertBefore(node, endComment);
812
- } else {
813
- container.insertBefore(node, endComment);
814
- }
815
- }
816
- }
817
- componentStack.pop();
818
- });
819
- boundaryCtx.effects.push(dispose);
820
- return container;
821
- }
822
- function createPortalDOM(vnode, parent) {
823
- const { container } = vnode.props;
824
- const children = vnode.children;
825
- if (!container) {
826
- console.warn("[what] Portal: target container not found");
827
- return document.createComment("portal:empty");
828
- }
829
- const portalCtx = {
830
- hooks: [],
831
- hookIndex: 0,
832
- effects: [],
833
- cleanups: [],
834
- mounted: false,
835
- disposed: false,
836
- _parentCtx: componentStack[componentStack.length - 1] || null
837
- };
838
- const placeholder = document.createComment("portal");
839
- placeholder._componentCtx = portalCtx;
840
- const portalNodes = [];
841
- for (const child of children) {
842
- const node = createDOM(child, container);
843
- if (node) {
844
- container.appendChild(node);
845
- portalNodes.push(node);
846
- }
847
- }
848
- portalCtx._cleanupCallbacks = [() => {
849
- for (const node of portalNodes) {
850
- disposeTree(node);
851
- if (node.parentNode) node.parentNode.removeChild(node);
852
- }
853
- }];
854
- return placeholder;
855
- }
856
- function createElementFromVNode(vnode, parent, isSvg) {
857
- const { tag, props, children } = vnode;
858
- const svgContext = isSvg || SVG_ELEMENTS.has(tag);
859
- const el = svgContext ? document.createElementNS(SVG_NS, tag) : document.createElement(tag);
860
- if (props) {
861
- applyProps(el, props, {}, svgContext);
862
- }
863
- const isSvgChildren = svgContext && tag !== "foreignObject";
864
- for (let i = 0; i < children.length; i++) {
865
- const node = createDOM(children[i], el, isSvgChildren);
866
- if (node) el.appendChild(node);
867
- }
868
- el._vnode = vnode;
869
- return el;
870
- }
871
- function applyProps(el, newProps, oldProps, isSvg) {
872
- if (!newProps) return;
873
- for (const key in newProps) {
874
- if (key === "key" || key === "children") continue;
875
- if (key === "ref") {
876
- const ref = newProps.ref;
877
- if (typeof ref === "function") ref(el);
878
- else if (ref) ref.current = el;
879
- continue;
880
- }
881
- setProp(el, key, newProps[key], isSvg);
882
- }
883
- }
884
- function setProp(el, key, value, isSvg) {
885
- if (typeof value === "function" && !(key.startsWith("on") && key.length > 2) && key !== "ref") {
886
- if (!el._propEffects) el._propEffects = {};
887
- if (el._propEffects[key]) {
888
- try {
889
- el._propEffects[key]();
890
- } catch (e) {
891
- }
892
- }
893
- el._propEffects[key] = effect(() => {
894
- const resolved = value();
895
- setProp(el, key, resolved, isSvg);
896
- });
897
- return;
898
- }
899
- if (key.startsWith("on") && key.length > 2) {
900
- let eventName = key.slice(2);
901
- let useCapture = false;
902
- if (eventName.endsWith("Capture")) {
903
- eventName = eventName.slice(0, -7);
904
- useCapture = true;
905
- }
906
- const event = eventName.toLowerCase();
907
- const storageKey = useCapture ? event + "_capture" : event;
908
- const old = el._events?.[storageKey];
909
- if (old && old._original === value) return;
910
- if (old) el.removeEventListener(event, old, useCapture);
911
- if (value == null) return;
912
- if (!el._events) el._events = {};
913
- const wrappedHandler = (e) => {
914
- if (!e.nativeEvent) e.nativeEvent = e;
915
- return untrack(() => wrappedHandler._handler(e));
916
- };
917
- wrappedHandler._handler = value;
918
- wrappedHandler._original = value;
919
- el._events[storageKey] = wrappedHandler;
920
- const eventOpts = value._eventOpts;
921
- el.addEventListener(event, wrappedHandler, eventOpts || useCapture || void 0);
922
- return;
923
- }
924
- if (key === "className" || key === "class") {
925
- if (isSvg) {
926
- el.setAttribute("class", value || "");
927
- } else {
928
- el.className = value || "";
929
- }
930
- return;
931
- }
932
- if (key === "style") {
933
- if (typeof value === "string") {
934
- el.style.cssText = value;
935
- el._prevStyle = null;
936
- } else if (typeof value === "object") {
937
- const oldStyle = el._prevStyle || {};
938
- for (const prop in oldStyle) {
939
- if (!(prop in value)) el.style[prop] = "";
940
- }
941
- for (const prop in value) {
942
- el.style[prop] = value[prop] ?? "";
943
- }
944
- el._prevStyle = { ...value };
945
- }
946
- return;
947
- }
948
- if (key === "dangerouslySetInnerHTML") {
949
- el.innerHTML = value?.__html ?? "";
950
- return;
951
- }
952
- if (key === "innerHTML") {
953
- if (value == null) return;
954
- if (value && typeof value === "object" && "__html" in value) {
955
- el.innerHTML = value.__html ?? "";
956
- } else {
957
- if (__DEV__) {
958
- console.warn(
959
- "[what] innerHTML received a raw string. This is a security risk (XSS). Use innerHTML={{ __html: trustedString }} or dangerouslySetInnerHTML={{ __html: trustedString }} instead."
960
- );
961
- }
962
- return;
963
- }
964
- return;
965
- }
966
- if (typeof value === "boolean") {
967
- if (value) el.setAttribute(key, "");
968
- else el.removeAttribute(key);
969
- return;
970
- }
971
- if (key.startsWith("data-") || key.startsWith("aria-")) {
972
- el.setAttribute(key, value);
973
- return;
974
- }
975
- if (isSvg) {
976
- if (value === false || value == null) {
977
- el.removeAttribute(key);
978
- } else {
979
- el.setAttribute(key, value === true ? "" : String(value));
980
- }
981
- return;
982
- }
983
- if (key in el) {
984
- el[key] = value;
985
- } else {
986
- el.setAttribute(key, value);
987
- }
988
- }
989
-
990
- // packages/core/src/render.js
991
- var _onTextInsert = null;
992
- function _setTextInsertHook(fn) {
993
- _onTextInsert = typeof fn === "function" ? fn : null;
994
- }
995
- function _$createComponent(Component, props, children) {
996
- if (children && children.length > 0) {
997
- const mergedChildren = children.length === 1 ? children[0] : children;
998
- if (props) {
999
- props.children = mergedChildren;
1000
- } else {
1001
- props = { children: mergedChildren };
1002
- }
1003
- }
1004
- return createDOM({ tag: Component, props: props || {}, children: children || [], key: null, _vnode: true });
1005
- }
1006
- var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "formAction"]);
1007
- function isSafeUrl(url) {
1008
- if (typeof url !== "string") return true;
1009
- const normalized = url.trim().replace(/[\s\x00-\x1f]/g, "").toLowerCase();
1010
- if (normalized.startsWith("javascript:")) return false;
1011
- if (normalized.startsWith("data:")) return false;
1012
- if (normalized.startsWith("vbscript:")) return false;
1013
- return true;
1014
- }
1015
- var TABLE_WRAPPERS = {
1016
- tr: { depth: 2, wrap: "<table><tbody>", unwrap: "</tbody></table>" },
1017
- td: { depth: 3, wrap: "<table><tbody><tr>", unwrap: "</tr></tbody></table>" },
1018
- th: { depth: 3, wrap: "<table><tbody><tr>", unwrap: "</tr></tbody></table>" },
1019
- thead: { depth: 1, wrap: "<table>", unwrap: "</table>" },
1020
- tbody: { depth: 1, wrap: "<table>", unwrap: "</table>" },
1021
- tfoot: { depth: 1, wrap: "<table>", unwrap: "</table>" },
1022
- colgroup: { depth: 1, wrap: "<table>", unwrap: "</table>" },
1023
- col: { depth: 1, wrap: "<table>", unwrap: "</table>" },
1024
- caption: { depth: 1, wrap: "<table>", unwrap: "</table>" }
1025
- };
1026
- var SVG_ELEMENTS2 = /* @__PURE__ */ new Set([
1027
- "svg",
1028
- "path",
1029
- "circle",
1030
- "rect",
1031
- "line",
1032
- "polyline",
1033
- "polygon",
1034
- "ellipse",
1035
- "g",
1036
- "defs",
1037
- "use",
1038
- "text",
1039
- "tspan",
1040
- "foreignObject",
1041
- "clipPath",
1042
- "mask",
1043
- "pattern",
1044
- "linearGradient",
1045
- "radialGradient",
1046
- "stop",
1047
- "marker",
1048
- "symbol",
1049
- "image",
1050
- "animate",
1051
- "animateTransform",
1052
- "animateMotion",
1053
- "set",
1054
- "filter",
1055
- "feGaussianBlur",
1056
- "feOffset",
1057
- "feMerge",
1058
- "feMergeNode",
1059
- "feBlend",
1060
- "feColorMatrix",
1061
- "feComponentTransfer",
1062
- "feComposite",
1063
- "feConvolveMatrix",
1064
- "feDiffuseLighting",
1065
- "feDisplacementMap",
1066
- "feFlood",
1067
- "feImage",
1068
- "feMorphology",
1069
- "feSpecularLighting",
1070
- "feTile",
1071
- "feTurbulence",
1072
- "feDistantLight",
1073
- "fePointLight",
1074
- "feSpotLight"
1075
- ]);
1076
- function getLeadingTag(html) {
1077
- const m = html.match(/^<([a-zA-Z][a-zA-Z0-9]*)/);
1078
- return m ? m[1] : "";
1079
- }
1080
- function _$templateImpl(html) {
1081
- const trimmed = html.trim();
1082
- const tag = getLeadingTag(trimmed);
1083
- if (SVG_ELEMENTS2.has(tag)) {
1084
- return svgTemplate(trimmed);
1085
- }
1086
- const tableInfo = TABLE_WRAPPERS[tag];
1087
- if (tableInfo) {
1088
- const t2 = document.createElement("template");
1089
- t2.innerHTML = tableInfo.wrap + trimmed + tableInfo.unwrap;
1090
- let target = t2.content.firstChild;
1091
- for (let i = 0; i < tableInfo.depth; i++) target = target.firstChild;
1092
- return () => target.cloneNode(true);
1093
- }
1094
- const t = document.createElement("template");
1095
- t.innerHTML = trimmed;
1096
- return () => t.content.firstChild.cloneNode(true);
1097
- }
1098
- var _templateWarned = false;
1099
- function template(html) {
1100
- if (__DEV__ && !_templateWarned) {
1101
- _templateWarned = true;
1102
- console.warn(
1103
- "[what] template() is a compiler internal. Use JSX instead. Direct calls with user input can lead to XSS vulnerabilities."
1104
- );
1105
- }
1106
- return _$templateImpl(html);
1107
- }
1108
- function svgTemplate(html) {
1109
- const trimmed = html.trim();
1110
- const tag = getLeadingTag(trimmed);
1111
- if (tag === "svg") {
1112
- const t2 = document.createElement("template");
1113
- t2.innerHTML = trimmed;
1114
- return () => t2.content.firstChild.cloneNode(true);
1115
- }
1116
- const t = document.createElement("template");
1117
- t.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg">${trimmed}</svg>`;
1118
- return () => t.content.firstChild.firstChild.cloneNode(true);
1119
- }
1120
- function insert(parent, child, marker) {
1121
- if (typeof child === "function") {
1122
- const first = child();
1123
- const t = typeof first;
1124
- if (t === "string" || t === "number") {
1125
- const textNode = document.createTextNode(String(first));
1126
- const m = marker || null;
1127
- if (m) parent.insertBefore(textNode, m);
1128
- else parent.appendChild(textNode);
1129
- if (_onTextInsert) _onTextInsert(parent, String(first));
1130
- let current2 = textNode;
1131
- let isTextFastPath = true;
1132
- effect(() => {
1133
- const val = child();
1134
- const vt = typeof val;
1135
- if (isTextFastPath && (vt === "string" || vt === "number")) {
1136
- const str = String(val);
1137
- if (textNode.data !== str) textNode.data = str;
1138
- if (_onTextInsert) _onTextInsert(parent, str);
1139
- } else {
1140
- isTextFastPath = false;
1141
- current2 = reconcileInsert(parent, val, current2, m);
1142
- }
1143
- });
1144
- return textNode;
1145
- }
1146
- let current = first != null ? reconcileInsert(parent, first, null, marker || null) : null;
1147
- effect(() => {
1148
- current = reconcileInsert(parent, child(), current, marker || null);
1149
- });
1150
- return current;
1151
- }
1152
- if (typeof child === "string" || typeof child === "number") {
1153
- const textNode = document.createTextNode(String(child));
1154
- if (marker) parent.insertBefore(textNode, marker);
1155
- else parent.appendChild(textNode);
1156
- return textNode;
1157
- }
1158
- if (child != null && typeof child === "object" && child.nodeType > 0) {
1159
- if (marker) parent.insertBefore(child, marker);
1160
- else parent.appendChild(child);
1161
- return child;
1162
- }
1163
- return reconcileInsert(parent, child, null, marker || null);
1164
- }
1165
- function isDomNode2(value) {
1166
- if (!value || typeof value !== "object") return false;
1167
- if (typeof Node !== "undefined" && value instanceof Node) return true;
1168
- return typeof value.nodeType === "number" && typeof value.nodeName === "string";
1169
- }
1170
- function isVNode2(value) {
1171
- return !!value && typeof value === "object" && (value._vnode === true || "tag" in value);
1172
- }
1173
- var _hasSVGElement = typeof SVGElement !== "undefined";
1174
- function isSvgParent(parent) {
1175
- return _hasSVGElement && parent instanceof SVGElement && parent.tagName !== "foreignObject";
1176
- }
1177
- function asNodeArray(value) {
1178
- if (value == null) return [];
1179
- return Array.isArray(value) ? value : [value];
1180
- }
1181
- function valuesToNodes(value, parent, out) {
1182
- if (value == null || typeof value === "boolean") return out;
1183
- if (Array.isArray(value)) {
1184
- for (let i = 0; i < value.length; i++) {
1185
- valuesToNodes(value[i], parent, out);
1186
- }
1187
- return out;
1188
- }
1189
- if (typeof value === "string" || typeof value === "number") {
1190
- out.push(document.createTextNode(String(value)));
1191
- return out;
1192
- }
1193
- if (isDomNode2(value)) {
1194
- out.push(value);
1195
- return out;
1196
- }
1197
- if (isVNode2(value)) {
1198
- out.push(createDOM(value, parent, isSvgParent(parent)));
1199
- return out;
1200
- }
1201
- out.push(document.createTextNode(String(value)));
1202
- return out;
1203
- }
1204
- function sameNodeArray(a, b) {
1205
- if (a.length !== b.length) return false;
1206
- for (let i = 0; i < a.length; i++) {
1207
- if (a[i] !== b[i]) return false;
1208
- }
1209
- return true;
1210
- }
1211
- function reconcileInsert(parent, value, current, marker) {
1212
- if (!parent || typeof parent.insertBefore !== "function") {
1213
- if (__DEV__) {
1214
- console.warn("[what] reconcileInsert called with invalid parent:", parent);
1215
- }
1216
- return current;
1217
- }
1218
- const targetMarker = marker || null;
1219
- if (value == null || typeof value === "boolean") {
1220
- const oldNodes2 = asNodeArray(current);
1221
- for (let i = 0; i < oldNodes2.length; i++) {
1222
- const oldNode = oldNodes2[i];
1223
- if (oldNode.parentNode === parent) {
1224
- disposeTree(oldNode);
1225
- parent.removeChild(oldNode);
1226
- }
1227
- }
1228
- return null;
1229
- }
1230
- if ((typeof value === "string" || typeof value === "number") && current && !Array.isArray(current) && current.nodeType === 3) {
1231
- const text = String(value);
1232
- if (current.data !== text) current.data = text;
1233
- return current;
1234
- }
1235
- if (typeof value === "object" && value !== null && value.nodeType > 0 && !Array.isArray(value)) {
1236
- if (value === current) return current;
1237
- if (current && !Array.isArray(current) && current.nodeType > 0) {
1238
- if (current.parentNode === parent) {
1239
- disposeTree(current);
1240
- parent.replaceChild(value, current);
1241
- } else {
1242
- if (targetMarker) parent.insertBefore(value, targetMarker);
1243
- else parent.appendChild(value);
1244
- }
1245
- return value;
1246
- }
1247
- }
1248
- const newNodes = valuesToNodes(value, parent, []);
1249
- const oldNodes = asNodeArray(current);
1250
- if (sameNodeArray(oldNodes, newNodes)) {
1251
- return current;
1252
- }
1253
- const newLen = newNodes.length;
1254
- for (let i = 0; i < oldNodes.length; i++) {
1255
- const oldNode = oldNodes[i];
1256
- if (oldNode.parentNode !== parent) continue;
1257
- let found = false;
1258
- for (let j = 0; j < newLen; j++) {
1259
- if (newNodes[j] === oldNode) {
1260
- found = true;
1261
- break;
1262
- }
1263
- }
1264
- if (!found) {
1265
- disposeTree(oldNode);
1266
- parent.removeChild(oldNode);
1267
- }
1268
- }
1269
- let ref = targetMarker;
1270
- for (let i = newNodes.length - 1; i >= 0; i--) {
1271
- const node = newNodes[i];
1272
- if (node.parentNode !== parent || node.nextSibling !== ref) {
1273
- if (ref && ref.parentNode !== parent) ref = null;
1274
- if (ref) parent.insertBefore(node, ref);
1275
- else parent.appendChild(node);
1276
- }
1277
- ref = node;
1278
- }
1279
- if (newNodes.length === 0) return null;
1280
- return newNodes.length === 1 ? newNodes[0] : newNodes;
1281
- }
1282
- function mapArray(source, mapFn, options) {
1283
- const keyFn = options?.key;
1284
- const raw = options?.raw || false;
1285
- return (parent, marker) => {
1286
- let items = [];
1287
- let mappedNodes = [];
1288
- let disposeFns = [];
1289
- let keyedState = keyFn && !raw ? /* @__PURE__ */ new Map() : null;
1290
- const endMarker = document.createComment("/list");
1291
- parent.insertBefore(endMarker, marker || null);
1292
- effect(() => {
1293
- const newItems = source() || [];
1294
- if (keyFn) {
1295
- reconcileKeyed(parent, endMarker, items, newItems, mappedNodes, disposeFns, mapFn, keyFn, keyedState);
1296
- } else {
1297
- reconcileList(parent, endMarker, items, newItems, mappedNodes, disposeFns, mapFn);
1298
- }
1299
- items = newItems.length > 0 ? newItems.slice() : newItems;
1300
- });
1301
- return endMarker;
1302
- };
1303
- }
1304
- function reconcileList(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn) {
1305
- const newLen = newItems.length;
1306
- const oldLen = oldItems.length;
1307
- if (newLen === 0) {
1308
- if (oldLen > 0) {
1309
- for (let i = 0; i < oldLen; i++) {
1310
- if (disposeFns[i]) disposeFns[i]();
1311
- }
1312
- for (let i = oldLen - 1; i >= 0; i--) {
1313
- const node = mappedNodes[i];
1314
- if (node) {
1315
- if (node._componentCtx || node._dispose || node._propEffects) {
1316
- disposeTree(node);
1317
- }
1318
- if (node.parentNode === parent) parent.removeChild(node);
1319
- }
1320
- }
1321
- mappedNodes.length = 0;
1322
- disposeFns.length = 0;
1323
- }
1324
- return;
1325
- }
1326
- if (oldLen === 0) {
1327
- const frag = document.createDocumentFragment();
1328
- for (let i = 0; i < newLen; i++) {
1329
- const item = newItems[i];
1330
- const node = _createItemScope((dispose) => {
1331
- disposeFns[i] = dispose;
1332
- return mapFn(item, i);
1333
- });
1334
- mappedNodes[i] = node;
1335
- frag.appendChild(node);
1336
- }
1337
- parent.insertBefore(frag, endMarker);
1338
- return;
1339
- }
1340
- let start = 0;
1341
- const minLen = Math.min(oldLen, newLen);
1342
- while (start < minLen && oldItems[start] === newItems[start]) start++;
1343
- if (start === oldLen && start === newLen) return;
1344
- let oldEnd = oldLen - 1;
1345
- let newEnd = newLen - 1;
1346
- while (oldEnd >= start && newEnd >= start && oldItems[oldEnd] === newItems[newEnd]) {
1347
- oldEnd--;
1348
- newEnd--;
1349
- }
1350
- const newMapped = new Array(newLen);
1351
- const newDispose = new Array(newLen);
1352
- for (let i = 0; i < start; i++) {
1353
- newMapped[i] = mappedNodes[i];
1354
- newDispose[i] = disposeFns[i];
1355
- }
1356
- for (let i = newEnd + 1; i < newLen; i++) {
1357
- const oldI = oldEnd + 1 + (i - newEnd - 1);
1358
- newMapped[i] = mappedNodes[oldI];
1359
- newDispose[i] = disposeFns[oldI];
1360
- }
1361
- const midNewLen = newEnd - start + 1;
1362
- const midOldLen = oldEnd - start + 1;
1363
- if (midNewLen === 0) {
1364
- for (let i = start; i <= oldEnd; i++) {
1365
- disposeFns[i]?.();
1366
- if (mappedNodes[i]?.parentNode) mappedNodes[i].parentNode.removeChild(mappedNodes[i]);
1367
- }
1368
- } else if (midOldLen === 0) {
1369
- const marker = start < newLen && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
1370
- const frag = document.createDocumentFragment();
1371
- for (let i = start; i <= newEnd; i++) {
1372
- const item = newItems[i];
1373
- const idx = i;
1374
- newMapped[i] = _createItemScope((dispose) => {
1375
- newDispose[idx] = dispose;
1376
- return mapFn(item, idx);
1377
- });
1378
- frag.appendChild(newMapped[i]);
1379
- }
1380
- parent.insertBefore(frag, marker);
1381
- } else {
1382
- _reconcileMiddle(
1383
- parent,
1384
- endMarker,
1385
- oldItems,
1386
- newItems,
1387
- mappedNodes,
1388
- disposeFns,
1389
- mapFn,
1390
- start,
1391
- oldEnd,
1392
- newEnd,
1393
- newMapped,
1394
- newDispose
1395
- );
1396
- }
1397
- mappedNodes.length = newLen;
1398
- disposeFns.length = newLen;
1399
- for (let i = 0; i < newLen; i++) {
1400
- mappedNodes[i] = newMapped[i];
1401
- disposeFns[i] = newDispose[i];
1402
- }
1403
- }
1404
- function _reconcileMiddle(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn, start, oldEnd, newEnd, newMapped, newDispose) {
1405
- const oldIdxMap = /* @__PURE__ */ new Map();
1406
- for (let i = start; i <= oldEnd; i++) {
1407
- oldIdxMap.set(oldItems[i], i);
1408
- }
1409
- const midLen = newEnd - start + 1;
1410
- const oldIndices = new Int32Array(midLen);
1411
- oldIndices.fill(-1);
1412
- for (let i = start; i <= newEnd; i++) {
1413
- const oldIdx = oldIdxMap.get(newItems[i]);
1414
- if (oldIdx !== void 0) {
1415
- oldIdxMap.delete(newItems[i]);
1416
- newMapped[i] = mappedNodes[oldIdx];
1417
- newDispose[i] = disposeFns[oldIdx];
1418
- oldIndices[i - start] = oldIdx;
1419
- }
1420
- }
1421
- for (const [, oldIdx] of oldIdxMap) {
1422
- disposeFns[oldIdx]?.();
1423
- if (mappedNodes[oldIdx]?.parentNode) mappedNodes[oldIdx].parentNode.removeChild(mappedNodes[oldIdx]);
1424
- }
1425
- const reusedCount = midLen - _countNeg1(oldIndices, midLen);
1426
- const inLIS = new Uint8Array(midLen);
1427
- if (reusedCount > 1) {
1428
- const seq = new Int32Array(reusedCount);
1429
- const seqToMid = new Int32Array(reusedCount);
1430
- let k = 0;
1431
- for (let i = 0; i < midLen; i++) {
1432
- if (oldIndices[i] !== -1) {
1433
- seq[k] = oldIndices[i];
1434
- seqToMid[k] = i;
1435
- k++;
1436
- }
1437
- }
1438
- const lisResult = _lis(seq, reusedCount);
1439
- for (let i = 0; i < lisResult.length; i++) {
1440
- inLIS[seqToMid[lisResult[i]]] = 1;
1441
- }
1442
- } else if (reusedCount === 1) {
1443
- for (let i = 0; i < midLen; i++) {
1444
- if (oldIndices[i] !== -1) {
1445
- inLIS[i] = 1;
1446
- break;
1447
- }
1448
- }
1449
- }
1450
- for (let i = start; i <= newEnd; i++) {
1451
- if (!newMapped[i]) {
1452
- const item = newItems[i];
1453
- const idx = i;
1454
- newMapped[i] = _createItemScope((dispose) => {
1455
- newDispose[idx] = dispose;
1456
- return mapFn(item, idx);
1457
- });
1458
- }
1459
- }
1460
- let nextSibling = newEnd + 1 < newMapped.length && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
1461
- for (let i = newEnd; i >= start; i--) {
1462
- const mi = i - start;
1463
- if (oldIndices[mi] === -1 || !inLIS[mi]) {
1464
- if (nextSibling && nextSibling.parentNode !== parent) nextSibling = endMarker;
1465
- parent.insertBefore(newMapped[i], nextSibling);
1466
- }
1467
- nextSibling = newMapped[i];
1468
- }
1469
- }
1470
- function _countNeg1(arr, len) {
1471
- let c = 0;
1472
- for (let i = 0; i < len; i++) if (arr[i] === -1) c++;
1473
- return c;
1474
- }
1475
- function _lis(arr, len) {
1476
- if (len === 0) return [];
1477
- if (len === 1) return [0];
1478
- const tails = new Int32Array(len);
1479
- const predecessors = new Int32Array(len);
1480
- let tailLen = 1;
1481
- tails[0] = 0;
1482
- predecessors[0] = -1;
1483
- for (let i = 1; i < len; i++) {
1484
- if (arr[i] > arr[tails[tailLen - 1]]) {
1485
- predecessors[i] = tails[tailLen - 1];
1486
- tails[tailLen++] = i;
1487
- } else {
1488
- let lo = 0, hi = tailLen - 1;
1489
- while (lo < hi) {
1490
- const mid = lo + hi >> 1;
1491
- if (arr[tails[mid]] < arr[i]) lo = mid + 1;
1492
- else hi = mid;
1493
- }
1494
- tails[lo] = i;
1495
- predecessors[i] = lo > 0 ? tails[lo - 1] : -1;
1496
- }
1497
- }
1498
- const result = new Array(tailLen);
1499
- let k = tails[tailLen - 1];
1500
- for (let i = tailLen - 1; i >= 0; i--) {
1501
- result[i] = k;
1502
- k = predecessors[k];
1503
- }
1504
- return result;
1505
- }
1506
- function reconcileKeyed(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn, keyFn, keyedState) {
1507
- const newLen = newItems.length;
1508
- const oldLen = oldItems.length;
1509
- if (newLen === 0) {
1510
- if (oldLen > 0) {
1511
- for (let i = 0; i < oldLen; i++) {
1512
- if (disposeFns[i]) disposeFns[i]();
1513
- }
1514
- for (let i = oldLen - 1; i >= 0; i--) {
1515
- const node = mappedNodes[i];
1516
- if (node) {
1517
- if (node._componentCtx || node._dispose || node._propEffects) {
1518
- disposeTree(node);
1519
- }
1520
- if (node.parentNode === parent) parent.removeChild(node);
1521
- }
1522
- }
1523
- mappedNodes.length = 0;
1524
- disposeFns.length = 0;
1525
- if (keyedState) keyedState.clear();
1526
- }
1527
- return;
1528
- }
1529
- if (oldLen === 0) {
1530
- const frag = document.createDocumentFragment();
1531
- for (let i = 0; i < newLen; i++) {
1532
- const item = newItems[i];
1533
- const idx = i;
1534
- let accessor;
1535
- if (keyedState) {
1536
- const key = keyFn(item);
1537
- const itemSig = signal(item);
1538
- accessor = itemSig;
1539
- keyedState.set(key, { itemSig });
1540
- } else {
1541
- accessor = item;
1542
- }
1543
- const node = _createItemScope((dispose) => {
1544
- disposeFns[idx] = dispose;
1545
- return mapFn(accessor, idx);
1546
- });
1547
- mappedNodes[i] = node;
1548
- frag.appendChild(node);
1549
- }
1550
- parent.insertBefore(frag, endMarker);
1551
- return;
1552
- }
1553
- let start = 0;
1554
- const minLen = Math.min(oldLen, newLen);
1555
- while (start < minLen) {
1556
- if (oldItems[start] === newItems[start]) {
1557
- start++;
1558
- continue;
1559
- }
1560
- const oldKey = keyFn(oldItems[start]);
1561
- const newKey = keyFn(newItems[start]);
1562
- if (oldKey !== newKey) break;
1563
- if (keyedState) keyedState.get(oldKey).itemSig.set(newItems[start]);
1564
- start++;
1565
- }
1566
- let oldEnd = oldLen - 1;
1567
- let newEnd = newLen - 1;
1568
- while (oldEnd >= start && newEnd >= start) {
1569
- if (oldItems[oldEnd] === newItems[newEnd]) {
1570
- oldEnd--;
1571
- newEnd--;
1572
- continue;
1573
- }
1574
- const oldKey = keyFn(oldItems[oldEnd]);
1575
- const newKey = keyFn(newItems[newEnd]);
1576
- if (oldKey !== newKey) break;
1577
- if (keyedState) keyedState.get(oldKey).itemSig.set(newItems[newEnd]);
1578
- oldEnd--;
1579
- newEnd--;
1580
- }
1581
- if (start > oldEnd && start > newEnd) {
1582
- return;
1583
- }
1584
- const newMapped = new Array(newLen);
1585
- const newDispose = new Array(newLen);
1586
- for (let i = 0; i < start; i++) {
1587
- newMapped[i] = mappedNodes[i];
1588
- newDispose[i] = disposeFns[i];
1589
- }
1590
- for (let i = newEnd + 1; i < newLen; i++) {
1591
- const oldI = oldEnd + 1 + (i - newEnd - 1);
1592
- newMapped[i] = mappedNodes[oldI];
1593
- newDispose[i] = disposeFns[oldI];
1594
- }
1595
- const midNewLen = newEnd - start + 1;
1596
- const midOldLen = oldEnd - start + 1;
1597
- if (midOldLen === 0) {
1598
- const marker = newEnd + 1 < newLen && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
1599
- const frag = document.createDocumentFragment();
1600
- for (let i = start; i <= newEnd; i++) {
1601
- const item = newItems[i];
1602
- const idx = i;
1603
- let accessor;
1604
- if (keyedState) {
1605
- const key = keyFn(item);
1606
- const itemSig = signal(item);
1607
- accessor = itemSig;
1608
- keyedState.set(key, { itemSig });
1609
- } else {
1610
- accessor = item;
1611
- }
1612
- newMapped[i] = _createItemScope((dispose) => {
1613
- newDispose[idx] = dispose;
1614
- return mapFn(accessor, idx);
1615
- });
1616
- frag.appendChild(newMapped[i]);
1617
- }
1618
- parent.insertBefore(frag, marker);
1619
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
1620
- return;
1621
- }
1622
- if (midNewLen === 0) {
1623
- for (let i = start; i <= oldEnd; i++) {
1624
- disposeFns[i]?.();
1625
- if (mappedNodes[i]?.parentNode) parent.removeChild(mappedNodes[i]);
1626
- if (keyedState) keyedState.delete(keyFn(oldItems[i]));
1627
- }
1628
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
1629
- return;
1630
- }
1631
- const oldKeyMap = /* @__PURE__ */ new Map();
1632
- for (let i = start; i <= oldEnd; i++) {
1633
- oldKeyMap.set(keyFn(oldItems[i]), i);
1634
- }
1635
- const oldIndices = new Int32Array(midNewLen);
1636
- oldIndices.fill(-1);
1637
- for (let i = start; i <= newEnd; i++) {
1638
- const key = keyFn(newItems[i]);
1639
- const oldIdx = oldKeyMap.get(key);
1640
- if (oldIdx !== void 0) {
1641
- oldKeyMap.delete(key);
1642
- newMapped[i] = mappedNodes[oldIdx];
1643
- newDispose[i] = disposeFns[oldIdx];
1644
- oldIndices[i - start] = oldIdx;
1645
- if (keyedState && newItems[i] !== oldItems[oldIdx]) {
1646
- keyedState.get(key).itemSig.set(newItems[i]);
1647
- }
1648
- }
1649
- }
1650
- for (const [key, oldIdx] of oldKeyMap) {
1651
- disposeFns[oldIdx]?.();
1652
- if (mappedNodes[oldIdx]?.parentNode) parent.removeChild(mappedNodes[oldIdx]);
1653
- if (keyedState) keyedState.delete(key);
1654
- }
1655
- for (let i = start; i <= newEnd; i++) {
1656
- if (!newMapped[i]) {
1657
- const item = newItems[i];
1658
- const idx = i;
1659
- let accessor;
1660
- if (keyedState) {
1661
- const key = keyFn(item);
1662
- const itemSig = signal(item);
1663
- accessor = itemSig;
1664
- keyedState.set(key, { itemSig });
1665
- } else {
1666
- accessor = item;
1667
- }
1668
- newMapped[i] = _createItemScope((dispose) => {
1669
- newDispose[idx] = dispose;
1670
- return mapFn(accessor, idx);
1671
- });
1672
- }
1673
- }
1674
- let reusedCount = 0;
1675
- let alreadySorted = true;
1676
- let lastOldIdx = -1;
1677
- for (let i = 0; i < midNewLen; i++) {
1678
- if (oldIndices[i] !== -1) {
1679
- reusedCount++;
1680
- if (oldIndices[i] <= lastOldIdx) alreadySorted = false;
1681
- lastOldIdx = oldIndices[i];
1682
- }
1683
- }
1684
- const inLIS = new Uint8Array(midNewLen);
1685
- if (alreadySorted) {
1686
- for (let i = 0; i < midNewLen; i++) {
1687
- if (oldIndices[i] !== -1) inLIS[i] = 1;
1688
- }
1689
- } else if (reusedCount > 1) {
1690
- const seq = new Int32Array(reusedCount);
1691
- const seqToMid = new Int32Array(reusedCount);
1692
- let k = 0;
1693
- for (let i = 0; i < midNewLen; i++) {
1694
- if (oldIndices[i] !== -1) {
1695
- seq[k] = oldIndices[i];
1696
- seqToMid[k] = i;
1697
- k++;
1698
- }
1699
- }
1700
- const lisResult = _lis(seq, reusedCount);
1701
- for (let i = 0; i < lisResult.length; i++) {
1702
- inLIS[seqToMid[lisResult[i]]] = 1;
1703
- }
1704
- } else if (reusedCount === 1) {
1705
- for (let i = 0; i < midNewLen; i++) {
1706
- if (oldIndices[i] !== -1) {
1707
- inLIS[i] = 1;
1708
- break;
1709
- }
1710
- }
1711
- }
1712
- let nextSibling = newEnd + 1 < newMapped.length && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
1713
- for (let i = newEnd; i >= start; i--) {
1714
- const mi = i - start;
1715
- if (oldIndices[mi] === -1 || !inLIS[mi]) {
1716
- if (nextSibling && nextSibling.parentNode !== parent) nextSibling = endMarker;
1717
- parent.insertBefore(newMapped[i], nextSibling);
1718
- }
1719
- nextSibling = newMapped[i];
1720
- }
1721
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
1722
- }
1723
- function _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen) {
1724
- mappedNodes.length = newLen;
1725
- disposeFns.length = newLen;
1726
- for (let i = 0; i < newLen; i++) {
1727
- mappedNodes[i] = newMapped[i];
1728
- disposeFns[i] = newDispose[i];
1729
- }
1730
- }
1731
- function spread(el, props) {
1732
- for (const key in props) {
1733
- const value = props[key];
1734
- if (key.startsWith("on") && key.length > 2) {
1735
- const event = key.slice(2).toLowerCase();
1736
- el.addEventListener(event, value);
1737
- continue;
1738
- }
1739
- if (typeof value === "function" && !key.startsWith("on")) {
1740
- if (key === "class" || key === "className") {
1741
- effect(() => {
1742
- el.className = value() || "";
1743
- });
1744
- } else if (key === "style" && typeof value() === "object") {
1745
- effect(() => {
1746
- const styles = value();
1747
- for (const prop in styles) {
1748
- el.style[prop] = styles[prop] ?? "";
1749
- }
1750
- });
1751
- } else {
1752
- effect(() => {
1753
- setProp2(el, key, value());
1754
- });
1755
- }
1756
- } else {
1757
- setProp2(el, key, value);
1758
- }
1759
- }
1760
- }
1761
- function setProp2(el, key, value) {
1762
- if (key === "ref") {
1763
- if (typeof value === "function") value(el);
1764
- else if (value && typeof value === "object") value.current = el;
1765
- return;
1766
- }
1767
- if (key === "key") return;
1768
- if (URL_ATTRS.has(key) || URL_ATTRS.has(key.toLowerCase())) {
1769
- if (!isSafeUrl(value)) {
1770
- if (typeof console !== "undefined") {
1771
- console.warn(`[what] Blocked unsafe URL in "${key}" attribute: ${value}`);
1772
- }
1773
- return;
1774
- }
1775
- }
1776
- if (key === "class" || key === "className") {
1777
- el.className = value || "";
1778
- } else if (key === "dangerouslySetInnerHTML") {
1779
- el.innerHTML = value?.__html ?? "";
1780
- } else if (key === "innerHTML") {
1781
- if (value && typeof value === "object" && "__html" in value) {
1782
- el.innerHTML = value.__html ?? "";
1783
- } else {
1784
- if (typeof console !== "undefined" && value != null && value !== "") {
1785
- console.warn(
1786
- '[what] Plain string innerHTML is not allowed. Use { __html: "..." } or dangerouslySetInnerHTML={{ __html: "..." }} instead.'
1787
- );
1788
- }
1789
- }
1790
- } else if (key === "style") {
1791
- if (typeof value === "string") {
1792
- el.style.cssText = value;
1793
- } else if (typeof value === "object") {
1794
- for (const prop in value) {
1795
- el.style[prop] = value[prop] ?? "";
1796
- }
1797
- }
1798
- } else if (key.startsWith("data-") || key.startsWith("aria-")) {
1799
- el.setAttribute(key, value);
1800
- } else if (typeof value === "boolean") {
1801
- if (value) el.setAttribute(key, "");
1802
- else el.removeAttribute(key);
1803
- } else if (key in el) {
1804
- el[key] = value;
1805
- } else {
1806
- el.setAttribute(key, value);
1807
- }
1808
- }
1809
- var delegatedEvents = /* @__PURE__ */ new Set();
1810
- function delegateEvents(eventNames) {
1811
- for (const name of eventNames) {
1812
- if (delegatedEvents.has(name)) continue;
1813
- delegatedEvents.add(name);
1814
- document.addEventListener(name, (e) => {
1815
- let node = e.target;
1816
- const key = "$$" + name;
1817
- while (node) {
1818
- const handler = node[key];
1819
- if (handler) {
1820
- handler(e);
1821
- if (e.cancelBubble) return;
1822
- }
1823
- node = node.parentNode;
1824
- }
1825
- });
1826
- }
1827
- }
1828
- function on(el, event, handler) {
1829
- el.addEventListener(event, handler);
1830
- return () => el.removeEventListener(event, handler);
1831
- }
1832
- function classList(el, classes) {
1833
- effect(() => {
1834
- for (const name in classes) {
1835
- const value = typeof classes[name] === "function" ? classes[name]() : classes[name];
1836
- el.classList.toggle(name, !!value);
1837
- }
1838
- });
1839
- }
1840
- var _isHydrating = false;
1841
- var _hydrationCursor = null;
1842
- function isHydrating() {
1843
- return _isHydrating;
1844
- }
1845
- function hydrate(vnode, container) {
1846
- _isHydrating = true;
1847
- _hydrationCursor = { parent: container, index: 0 };
1848
- try {
1849
- const result = hydrateNode(vnode, container);
1850
- return result;
1851
- } finally {
1852
- _isHydrating = false;
1853
- _hydrationCursor = null;
1854
- }
1855
- }
1856
- function claimNode(parent) {
1857
- const children = parent.childNodes;
1858
- while (_hydrationCursor.index < children.length) {
1859
- const node = children[_hydrationCursor.index];
1860
- if (node.nodeType === 8) {
1861
- const text = node.textContent;
1862
- if (text === "$" || text === "/$" || text === "[]" || text === "/[]") {
1863
- _hydrationCursor.index++;
1864
- continue;
1865
- }
1866
- }
1867
- _hydrationCursor.index++;
1868
- return node;
1869
- }
1870
- return null;
1871
- }
1872
- function isDevMode() {
1873
- return typeof process !== "undefined" && true;
1874
- }
1875
- function hydrateNode(vnode, parent) {
1876
- if (vnode == null || typeof vnode === "boolean") {
1877
- return null;
1878
- }
1879
- if (typeof vnode === "string" || typeof vnode === "number") {
1880
- const existing = claimNode(parent);
1881
- const text = String(vnode);
1882
- if (existing && existing.nodeType === 3) {
1883
- if (isDevMode() && existing.textContent !== text) {
1884
- console.warn(
1885
- `[what] Hydration mismatch: expected text "${text}", got "${existing.textContent}"`
1886
- );
1887
- existing.textContent = text;
1888
- }
1889
- return existing;
1890
- }
1891
- if (isDevMode()) {
1892
- console.warn(
1893
- `[what] Hydration mismatch: expected text node "${text}", got ${existing ? existing.nodeName : "nothing"}. Falling back to client render.`
1894
- );
1895
- }
1896
- const textNode2 = document.createTextNode(text);
1897
- if (existing) {
1898
- parent.replaceChild(textNode2, existing);
1899
- } else {
1900
- parent.appendChild(textNode2);
1901
- }
1902
- return textNode2;
1903
- }
1904
- if (typeof vnode === "function") {
1905
- const initialValue = vnode();
1906
- let current = hydrateNode(initialValue, parent);
1907
- effect(() => {
1908
- const value = vnode();
1909
- if (!_isHydrating) {
1910
- current = reconcileInsert(parent, value, current, null);
1911
- }
1912
- });
1913
- return current;
1914
- }
1915
- if (Array.isArray(vnode)) {
1916
- const nodes = [];
1917
- for (const child of vnode) {
1918
- const node = hydrateNode(child, parent);
1919
- if (node) nodes.push(node);
1920
- }
1921
- return nodes.length === 1 ? nodes[0] : nodes;
1922
- }
1923
- if (typeof vnode === "object" && vnode._vnode) {
1924
- if (typeof vnode.tag === "function") {
1925
- const componentStack2 = getComponentStack();
1926
- const Component = vnode.tag;
1927
- const props = vnode.props || {};
1928
- const children = vnode.children || [];
1929
- const ctx = {
1930
- hooks: [],
1931
- hookIndex: 0,
1932
- effects: [],
1933
- cleanups: [],
1934
- mounted: false,
1935
- disposed: false,
1936
- Component,
1937
- _parentCtx: componentStack2[componentStack2.length - 1] || null,
1938
- _errorBoundary: null
1939
- };
1940
- componentStack2.push(ctx);
1941
- let result;
1942
- try {
1943
- const propsChildren = children.length === 0 ? void 0 : children.length === 1 ? children[0] : children;
1944
- result = Component({ ...props, children: propsChildren });
1945
- } catch (error) {
1946
- componentStack2.pop();
1947
- console.error("[what] Error in component during hydration:", Component.name || "Anonymous", error);
1948
- return null;
1949
- }
1950
- componentStack2.pop();
1951
- ctx.mounted = true;
1952
- if (ctx._mountCallbacks) {
1953
- queueMicrotask(() => {
1954
- if (ctx.disposed) return;
1955
- for (const fn of ctx._mountCallbacks) {
1956
- try {
1957
- fn();
1958
- } catch (e) {
1959
- console.error("[what] onMount error:", e);
1960
- }
1961
- }
1962
- });
1963
- }
1964
- return hydrateNode(result, parent);
1965
- }
1966
- const existing = claimNode(parent);
1967
- const expectedTag = vnode.tag.toUpperCase();
1968
- if (existing && existing.nodeType === 1 && existing.nodeName === expectedTag) {
1969
- hydrateElementProps(existing, vnode.props || {});
1970
- const savedCursor = _hydrationCursor;
1971
- _hydrationCursor = { parent: existing, index: 0 };
1972
- const rawInner = vnode.props?.dangerouslySetInnerHTML?.__html;
1973
- if (rawInner == null) {
1974
- for (const child of vnode.children) {
1975
- hydrateNode(child, existing);
1976
- }
1977
- }
1978
- _hydrationCursor = savedCursor;
1979
- return existing;
1980
- }
1981
- if (isDevMode()) {
1982
- console.warn(
1983
- `[what] Hydration mismatch: expected <${vnode.tag}>, got ${existing ? existing.nodeName : "nothing"}. Falling back to client render.`
1984
- );
1985
- }
1986
- const newEl = document.createElement(vnode.tag);
1987
- for (const key in vnode.props || {}) {
1988
- if (key === "children" || key === "key") continue;
1989
- setProp2(newEl, key, vnode.props[key]);
1990
- }
1991
- for (const child of vnode.children) {
1992
- reconcileInsert(newEl, child, null, null);
1993
- }
1994
- if (existing) {
1995
- parent.replaceChild(newEl, existing);
1996
- } else {
1997
- parent.appendChild(newEl);
1998
- }
1999
- return newEl;
2000
- }
2001
- if (isDomNode2(vnode)) {
2002
- return vnode;
2003
- }
2004
- const textNode = document.createTextNode(String(vnode));
2005
- parent.appendChild(textNode);
2006
- return textNode;
2007
- }
2008
- function hydrateElementProps(el, props) {
2009
- for (const key in props) {
2010
- if (key === "children" || key === "key" || key === "ref") continue;
2011
- if (key === "dangerouslySetInnerHTML" || key === "innerHTML") continue;
2012
- const value = props[key];
2013
- if (key.startsWith("on") && key.length > 2) {
2014
- const event = key.slice(2).toLowerCase();
2015
- el.addEventListener(event, value);
2016
- continue;
2017
- }
2018
- if (key.startsWith("$$")) {
2019
- el[key] = value;
2020
- continue;
2021
- }
2022
- if (typeof value === "function" && !key.startsWith("on")) {
2023
- if (key === "class" || key === "className") {
2024
- effect(() => {
2025
- el.className = value() || "";
2026
- });
2027
- } else if (key === "style" && typeof value() === "object") {
2028
- effect(() => {
2029
- const styles = value();
2030
- for (const prop in styles) {
2031
- el.style[prop] = styles[prop] ?? "";
2032
- }
2033
- });
2034
- } else {
2035
- effect(() => {
2036
- setProp2(el, key, value());
2037
- });
2038
- }
2039
- continue;
2040
- }
2041
- if (key === "data-hk") continue;
2042
- }
2043
- }
1
+ import {
2
+ _$createComponent,
3
+ _$templateImpl,
4
+ _setTextInsertHook,
5
+ classList,
6
+ delegateEvents,
7
+ hydrate,
8
+ insert,
9
+ isHydrating,
10
+ mapArray,
11
+ on,
12
+ setProp,
13
+ spread,
14
+ svgTemplate,
15
+ template
16
+ } from "./chunk-M7UEET5O.js";
17
+ import {
18
+ effect,
19
+ untrack
20
+ } from "./chunk-AW3BAPIK.js";
21
+ import "./chunk-AZP2EOGX.js";
2044
22
  export {
2045
23
  _$createComponent,
2046
24
  _$templateImpl as _$template,
@@ -2054,7 +32,7 @@ export {
2054
32
  isHydrating,
2055
33
  mapArray,
2056
34
  on,
2057
- setProp2 as setProp,
35
+ setProp,
2058
36
  spread,
2059
37
  svgTemplate,
2060
38
  template,