what-core 0.11.0 → 0.11.1

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 (91) hide show
  1. package/dist/{chunk-RI7T5VFD.min.js → chunk-D5YDPQ57.min.js} +1 -2
  2. package/dist/chunk-O3SKPRTY.min.js +0 -1
  3. package/dist/chunk-W33M3HL5.min.js +1 -0
  4. package/dist/index.min.js +2 -3
  5. package/dist/jsx-dev-runtime.min.js +0 -1
  6. package/dist/jsx-runtime.min.js +0 -1
  7. package/dist/render.min.js +1 -2
  8. package/dist/testing.min.js +1 -2
  9. package/package.json +2 -2
  10. package/src/agent-context.js +1 -1
  11. package/src/reactive.js +20 -4
  12. package/dist/a11y.js +0 -440
  13. package/dist/animation.js +0 -548
  14. package/dist/chunk-2IZMPODD.min.js +0 -2
  15. package/dist/chunk-2IZMPODD.min.js.map +0 -7
  16. package/dist/chunk-2P7OVL2L.js +0 -1386
  17. package/dist/chunk-2P7OVL2L.js.map +0 -7
  18. package/dist/chunk-5EQUBJWQ.js +0 -1365
  19. package/dist/chunk-5EQUBJWQ.js.map +0 -7
  20. package/dist/chunk-6DAIK77K.min.js +0 -2
  21. package/dist/chunk-6DAIK77K.min.js.map +0 -7
  22. package/dist/chunk-AW3BAPIK.js +0 -1685
  23. package/dist/chunk-AW3BAPIK.js.map +0 -7
  24. package/dist/chunk-AZP2EOGX.js +0 -188
  25. package/dist/chunk-AZP2EOGX.js.map +0 -7
  26. package/dist/chunk-CCINITLW.js +0 -1692
  27. package/dist/chunk-CCINITLW.js.map +0 -7
  28. package/dist/chunk-F2HUXI22.js +0 -1675
  29. package/dist/chunk-F2HUXI22.js.map +0 -7
  30. package/dist/chunk-GZRA4IAJ.js +0 -1699
  31. package/dist/chunk-GZRA4IAJ.js.map +0 -7
  32. package/dist/chunk-H3GA34JK.js +0 -1384
  33. package/dist/chunk-H3GA34JK.js.map +0 -7
  34. package/dist/chunk-KBM6CWG4.min.js +0 -2
  35. package/dist/chunk-KBM6CWG4.min.js.map +0 -7
  36. package/dist/chunk-KL7TNUIU.min.js +0 -2
  37. package/dist/chunk-KL7TNUIU.min.js.map +0 -7
  38. package/dist/chunk-L6XOF7P4.min.js +0 -2
  39. package/dist/chunk-L6XOF7P4.min.js.map +0 -7
  40. package/dist/chunk-M7UEET5O.js +0 -1323
  41. package/dist/chunk-M7UEET5O.js.map +0 -7
  42. package/dist/chunk-MH7L756Y.min.js +0 -2
  43. package/dist/chunk-MH7L756Y.min.js.map +0 -7
  44. package/dist/chunk-O3SKPRTY.min.js.map +0 -7
  45. package/dist/chunk-RI7T5VFD.min.js.map +0 -7
  46. package/dist/chunk-RN6QIBWL.min.js +0 -2
  47. package/dist/chunk-RN6QIBWL.min.js.map +0 -7
  48. package/dist/chunk-VKCFJ4OT.min.js +0 -2
  49. package/dist/chunk-VKCFJ4OT.min.js.map +0 -7
  50. package/dist/chunk-VMTTYB4L.min.js +0 -2
  51. package/dist/chunk-VMTTYB4L.min.js.map +0 -7
  52. package/dist/chunk-VP4WLF5A.js +0 -1323
  53. package/dist/chunk-VP4WLF5A.js.map +0 -7
  54. package/dist/chunk-YA3W4XKH.js +0 -1323
  55. package/dist/chunk-YA3W4XKH.js.map +0 -7
  56. package/dist/compiler.js +0 -1799
  57. package/dist/compiler.js.map +0 -7
  58. package/dist/compiler.min.js +0 -2
  59. package/dist/compiler.min.js.map +0 -7
  60. package/dist/components.js +0 -229
  61. package/dist/data.js +0 -638
  62. package/dist/devtools.js +0 -10
  63. package/dist/devtools.js.map +0 -7
  64. package/dist/devtools.min.js +0 -2
  65. package/dist/devtools.min.js.map +0 -7
  66. package/dist/dom.js +0 -439
  67. package/dist/form.js +0 -509
  68. package/dist/h.js +0 -152
  69. package/dist/head.js +0 -51
  70. package/dist/helpers.js +0 -140
  71. package/dist/hooks.js +0 -210
  72. package/dist/index.js +0 -3576
  73. package/dist/index.js.map +0 -7
  74. package/dist/index.min.js.map +0 -7
  75. package/dist/jsx-dev-runtime.js +0 -23
  76. package/dist/jsx-dev-runtime.js.map +0 -7
  77. package/dist/jsx-dev-runtime.min.js.map +0 -7
  78. package/dist/jsx-runtime.js +0 -21
  79. package/dist/jsx-runtime.js.map +0 -7
  80. package/dist/jsx-runtime.min.js.map +0 -7
  81. package/dist/reactive.js +0 -432
  82. package/dist/render.js +0 -53
  83. package/dist/render.js.map +0 -7
  84. package/dist/render.min.js.map +0 -7
  85. package/dist/scheduler.js +0 -246
  86. package/dist/skeleton.js +0 -363
  87. package/dist/store.js +0 -83
  88. package/dist/testing.js +0 -439
  89. package/dist/testing.js.map +0 -7
  90. package/dist/testing.min.js.map +0 -7
  91. package/dist/what.js +0 -117
@@ -1,1323 +0,0 @@
1
- import {
2
- __DEV__,
3
- _createItemScope,
4
- _setSelectValue,
5
- createDOM,
6
- disposeTree,
7
- effect,
8
- getComponentStack,
9
- signal
10
- } from "./chunk-F2HUXI22.js";
11
-
12
- // packages/core/src/render.js
13
- var _onTextInsert = null;
14
- function _setTextInsertHook(fn) {
15
- _onTextInsert = typeof fn === "function" ? fn : null;
16
- }
17
- function _$createComponent(Component, props, children) {
18
- if (children && children.length > 0) {
19
- const mergedChildren = children.length === 1 ? children[0] : children;
20
- if (props) {
21
- props.children = mergedChildren;
22
- } else {
23
- props = { children: mergedChildren };
24
- }
25
- }
26
- return createDOM({ tag: Component, props: props || {}, children: children || [], key: null, _vnode: true });
27
- }
28
- var URL_ATTRS = /* @__PURE__ */ new Set(["href", "src", "action", "formaction", "formAction"]);
29
- function isSafeUrl(url) {
30
- if (typeof url !== "string") return true;
31
- const normalized = url.trim().replace(/[\s\x00-\x1f]/g, "").toLowerCase();
32
- if (normalized.startsWith("javascript:")) return false;
33
- if (normalized.startsWith("data:")) return false;
34
- if (normalized.startsWith("vbscript:")) return false;
35
- return true;
36
- }
37
- var TABLE_WRAPPERS = {
38
- tr: { depth: 2, wrap: "<table><tbody>", unwrap: "</tbody></table>" },
39
- td: { depth: 3, wrap: "<table><tbody><tr>", unwrap: "</tr></tbody></table>" },
40
- th: { depth: 3, wrap: "<table><tbody><tr>", unwrap: "</tr></tbody></table>" },
41
- thead: { depth: 1, wrap: "<table>", unwrap: "</table>" },
42
- tbody: { depth: 1, wrap: "<table>", unwrap: "</table>" },
43
- tfoot: { depth: 1, wrap: "<table>", unwrap: "</table>" },
44
- colgroup: { depth: 1, wrap: "<table>", unwrap: "</table>" },
45
- col: { depth: 1, wrap: "<table>", unwrap: "</table>" },
46
- caption: { depth: 1, wrap: "<table>", unwrap: "</table>" }
47
- };
48
- var SVG_ELEMENTS = /* @__PURE__ */ new Set([
49
- "svg",
50
- "path",
51
- "circle",
52
- "rect",
53
- "line",
54
- "polyline",
55
- "polygon",
56
- "ellipse",
57
- "g",
58
- "defs",
59
- "use",
60
- "text",
61
- "tspan",
62
- "foreignObject",
63
- "clipPath",
64
- "mask",
65
- "pattern",
66
- "linearGradient",
67
- "radialGradient",
68
- "stop",
69
- "marker",
70
- "symbol",
71
- "image",
72
- "animate",
73
- "animateTransform",
74
- "animateMotion",
75
- "set",
76
- "filter",
77
- "feGaussianBlur",
78
- "feOffset",
79
- "feMerge",
80
- "feMergeNode",
81
- "feBlend",
82
- "feColorMatrix",
83
- "feComponentTransfer",
84
- "feComposite",
85
- "feConvolveMatrix",
86
- "feDiffuseLighting",
87
- "feDisplacementMap",
88
- "feFlood",
89
- "feImage",
90
- "feMorphology",
91
- "feSpecularLighting",
92
- "feTile",
93
- "feTurbulence",
94
- "feDistantLight",
95
- "fePointLight",
96
- "feSpotLight"
97
- ]);
98
- function getLeadingTag(html) {
99
- const m = html.match(/^<([a-zA-Z][a-zA-Z0-9]*)/);
100
- return m ? m[1] : "";
101
- }
102
- function _$templateImpl(html) {
103
- const trimmed = html.trim();
104
- const tag = getLeadingTag(trimmed);
105
- if (SVG_ELEMENTS.has(tag)) {
106
- return svgTemplate(trimmed);
107
- }
108
- const tableInfo = TABLE_WRAPPERS[tag];
109
- if (tableInfo) {
110
- const t2 = document.createElement("template");
111
- t2.innerHTML = tableInfo.wrap + trimmed + tableInfo.unwrap;
112
- let target = t2.content.firstChild;
113
- for (let i = 0; i < tableInfo.depth; i++) target = target.firstChild;
114
- return () => target.cloneNode(true);
115
- }
116
- const t = document.createElement("template");
117
- t.innerHTML = trimmed;
118
- return () => t.content.firstChild.cloneNode(true);
119
- }
120
- var _templateWarned = false;
121
- function template(html) {
122
- if (__DEV__ && !_templateWarned) {
123
- _templateWarned = true;
124
- console.warn(
125
- "[what] template() is a compiler internal. Use JSX instead. Direct calls with user input can lead to XSS vulnerabilities."
126
- );
127
- }
128
- return _$templateImpl(html);
129
- }
130
- function svgTemplate(html) {
131
- const trimmed = html.trim();
132
- const tag = getLeadingTag(trimmed);
133
- if (tag === "svg") {
134
- const t2 = document.createElement("template");
135
- t2.innerHTML = trimmed;
136
- return () => t2.content.firstChild.cloneNode(true);
137
- }
138
- const t = document.createElement("template");
139
- t.innerHTML = `<svg xmlns="http://www.w3.org/2000/svg">${trimmed}</svg>`;
140
- return () => t.content.firstChild.firstChild.cloneNode(true);
141
- }
142
- function insert(parent, child, marker) {
143
- if (typeof child === "function" && child._mapArray) {
144
- return child(parent, marker || null);
145
- }
146
- if (typeof child === "function") {
147
- const first = child();
148
- const t = typeof first;
149
- if (t === "string" || t === "number") {
150
- const textNode = document.createTextNode(String(first));
151
- const m = marker || null;
152
- if (m) parent.insertBefore(textNode, m);
153
- else parent.appendChild(textNode);
154
- if (_onTextInsert) _onTextInsert(parent, String(first));
155
- let current2 = textNode;
156
- let isTextFastPath = true;
157
- effect(() => {
158
- const val = child();
159
- const vt = typeof val;
160
- if (isTextFastPath && (vt === "string" || vt === "number")) {
161
- const str = String(val);
162
- if (textNode.data !== str) textNode.data = str;
163
- if (_onTextInsert) _onTextInsert(parent, str);
164
- } else {
165
- isTextFastPath = false;
166
- current2 = reconcileInsert(parent, val, current2, m);
167
- }
168
- });
169
- return textNode;
170
- }
171
- let current = null;
172
- effect(() => {
173
- current = reconcileInsert(parent, child(), current, marker || null);
174
- });
175
- return current;
176
- }
177
- if (typeof child === "string" || typeof child === "number") {
178
- const textNode = document.createTextNode(String(child));
179
- if (marker) parent.insertBefore(textNode, marker);
180
- else parent.appendChild(textNode);
181
- return textNode;
182
- }
183
- if (child != null && typeof child === "object" && child.nodeType > 0) {
184
- if (marker) parent.insertBefore(child, marker);
185
- else parent.appendChild(child);
186
- return child;
187
- }
188
- return reconcileInsert(parent, child, null, marker || null);
189
- }
190
- function isDomNode(value) {
191
- if (!value || typeof value !== "object") return false;
192
- if (typeof Node !== "undefined" && value instanceof Node) return true;
193
- return typeof value.nodeType === "number" && typeof value.nodeName === "string";
194
- }
195
- function isVNode(value) {
196
- return !!value && typeof value === "object" && (value._vnode === true || "tag" in value);
197
- }
198
- var _hasSVGElement = typeof SVGElement !== "undefined";
199
- function isSvgParent(parent) {
200
- return _hasSVGElement && parent instanceof SVGElement && parent.tagName !== "foreignObject";
201
- }
202
- function asNodeArray(value) {
203
- if (value == null) return [];
204
- return Array.isArray(value) ? value : [value];
205
- }
206
- function valuesToNodes(value, parent, out) {
207
- if (value == null || typeof value === "boolean") return out;
208
- if (Array.isArray(value)) {
209
- for (let i = 0; i < value.length; i++) {
210
- valuesToNodes(value[i], parent, out);
211
- }
212
- return out;
213
- }
214
- if (typeof value === "function") {
215
- valuesToNodes(value(), parent, out);
216
- return out;
217
- }
218
- if (typeof value === "string" || typeof value === "number") {
219
- out.push(document.createTextNode(String(value)));
220
- return out;
221
- }
222
- if (isDomNode(value)) {
223
- if (value.nodeType === 11 && value.childNodes.length > 0) {
224
- const children = Array.from(value.childNodes);
225
- for (let i = 0; i < children.length; i++) {
226
- out.push(children[i]);
227
- }
228
- } else {
229
- out.push(value);
230
- }
231
- return out;
232
- }
233
- if (isVNode(value)) {
234
- out.push(createDOM(value, parent, isSvgParent(parent)));
235
- return out;
236
- }
237
- out.push(document.createTextNode(String(value)));
238
- return out;
239
- }
240
- function sameNodeArray(a, b) {
241
- if (a.length !== b.length) return false;
242
- for (let i = 0; i < a.length; i++) {
243
- if (a[i] !== b[i]) return false;
244
- }
245
- return true;
246
- }
247
- function reconcileInsert(parent, value, current, marker) {
248
- if (!parent || typeof parent.insertBefore !== "function") {
249
- if (__DEV__) {
250
- console.warn("[what] reconcileInsert called with invalid parent:", parent);
251
- }
252
- return current;
253
- }
254
- const targetMarker = marker || null;
255
- if (value == null || typeof value === "boolean") {
256
- const oldNodes2 = asNodeArray(current);
257
- for (let i = 0; i < oldNodes2.length; i++) {
258
- const oldNode = oldNodes2[i];
259
- if (oldNode.parentNode === parent) {
260
- disposeTree(oldNode);
261
- parent.removeChild(oldNode);
262
- }
263
- }
264
- return null;
265
- }
266
- if ((typeof value === "string" || typeof value === "number") && current && !Array.isArray(current) && current.nodeType === 3) {
267
- const text = String(value);
268
- if (current.data !== text) current.data = text;
269
- return current;
270
- }
271
- if (typeof value === "object" && value !== null && value.nodeType > 0 && !Array.isArray(value)) {
272
- if (value === current) return current;
273
- if (current && !Array.isArray(current) && current.nodeType > 0) {
274
- if (current.parentNode === parent) {
275
- disposeTree(current);
276
- parent.replaceChild(value, current);
277
- } else {
278
- if (targetMarker) parent.insertBefore(value, targetMarker);
279
- else parent.appendChild(value);
280
- }
281
- return value;
282
- }
283
- }
284
- const newNodes = valuesToNodes(value, parent, []);
285
- const oldNodes = asNodeArray(current);
286
- if (sameNodeArray(oldNodes, newNodes)) {
287
- return current;
288
- }
289
- const newLen = newNodes.length;
290
- for (let i = 0; i < oldNodes.length; i++) {
291
- const oldNode = oldNodes[i];
292
- if (oldNode.parentNode !== parent) continue;
293
- let found = false;
294
- for (let j = 0; j < newLen; j++) {
295
- if (newNodes[j] === oldNode) {
296
- found = true;
297
- break;
298
- }
299
- }
300
- if (!found) {
301
- disposeTree(oldNode);
302
- parent.removeChild(oldNode);
303
- }
304
- }
305
- let ref = targetMarker;
306
- for (let i = newNodes.length - 1; i >= 0; i--) {
307
- const node = newNodes[i];
308
- if (node.parentNode !== parent || node.nextSibling !== ref) {
309
- if (ref && ref.parentNode !== parent) ref = null;
310
- if (ref) parent.insertBefore(node, ref);
311
- else parent.appendChild(node);
312
- }
313
- ref = node;
314
- }
315
- if (newNodes.length === 0) return null;
316
- return newNodes.length === 1 ? newNodes[0] : newNodes;
317
- }
318
- function mapArray(source, mapFn, options) {
319
- const keyFn = options?.key;
320
- const raw = options?.raw || false;
321
- const inserter = (parent, marker) => {
322
- let items = [];
323
- let mappedNodes = [];
324
- let disposeFns = [];
325
- let keyedState = keyFn && !raw ? /* @__PURE__ */ new Map() : null;
326
- const endMarker = document.createComment("/list");
327
- parent.insertBefore(endMarker, marker || null);
328
- effect(() => {
329
- const newItems = source() || [];
330
- if (keyFn) {
331
- reconcileKeyed(parent, endMarker, items, newItems, mappedNodes, disposeFns, mapFn, keyFn, keyedState);
332
- } else {
333
- reconcileList(parent, endMarker, items, newItems, mappedNodes, disposeFns, mapFn);
334
- }
335
- items = newItems.length > 0 ? newItems.slice() : newItems;
336
- });
337
- return endMarker;
338
- };
339
- inserter._mapArray = true;
340
- return inserter;
341
- }
342
- function reconcileList(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn) {
343
- const newLen = newItems.length;
344
- const oldLen = oldItems.length;
345
- if (newLen === 0) {
346
- if (oldLen > 0) {
347
- for (let i = 0; i < oldLen; i++) {
348
- if (disposeFns[i]) disposeFns[i]();
349
- }
350
- for (let i = oldLen - 1; i >= 0; i--) {
351
- const node = mappedNodes[i];
352
- if (node) {
353
- disposeTree(node);
354
- if (node.parentNode === parent) parent.removeChild(node);
355
- }
356
- }
357
- mappedNodes.length = 0;
358
- disposeFns.length = 0;
359
- }
360
- return;
361
- }
362
- if (oldLen === 0) {
363
- const frag = document.createDocumentFragment();
364
- for (let i = 0; i < newLen; i++) {
365
- const item = newItems[i];
366
- const node = _createItemScope((dispose) => {
367
- disposeFns[i] = dispose;
368
- return mapFn(item, i);
369
- });
370
- mappedNodes[i] = node;
371
- frag.appendChild(node);
372
- }
373
- parent.insertBefore(frag, endMarker);
374
- return;
375
- }
376
- let start = 0;
377
- const minLen = Math.min(oldLen, newLen);
378
- while (start < minLen && oldItems[start] === newItems[start]) start++;
379
- if (start === oldLen && start === newLen) return;
380
- let oldEnd = oldLen - 1;
381
- let newEnd = newLen - 1;
382
- while (oldEnd >= start && newEnd >= start && oldItems[oldEnd] === newItems[newEnd]) {
383
- oldEnd--;
384
- newEnd--;
385
- }
386
- const newMapped = new Array(newLen);
387
- const newDispose = new Array(newLen);
388
- for (let i = 0; i < start; i++) {
389
- newMapped[i] = mappedNodes[i];
390
- newDispose[i] = disposeFns[i];
391
- }
392
- for (let i = newEnd + 1; i < newLen; i++) {
393
- const oldI = oldEnd + 1 + (i - newEnd - 1);
394
- newMapped[i] = mappedNodes[oldI];
395
- newDispose[i] = disposeFns[oldI];
396
- }
397
- const midNewLen = newEnd - start + 1;
398
- const midOldLen = oldEnd - start + 1;
399
- if (midNewLen === 0) {
400
- for (let i = start; i <= oldEnd; i++) {
401
- disposeFns[i]?.();
402
- if (mappedNodes[i]) disposeTree(mappedNodes[i]);
403
- if (mappedNodes[i]?.parentNode) mappedNodes[i].parentNode.removeChild(mappedNodes[i]);
404
- }
405
- } else if (midOldLen === 0) {
406
- const marker = start < newLen && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
407
- const frag = document.createDocumentFragment();
408
- for (let i = start; i <= newEnd; i++) {
409
- const item = newItems[i];
410
- const idx = i;
411
- newMapped[i] = _createItemScope((dispose) => {
412
- newDispose[idx] = dispose;
413
- return mapFn(item, idx);
414
- });
415
- frag.appendChild(newMapped[i]);
416
- }
417
- parent.insertBefore(frag, marker);
418
- } else {
419
- _reconcileMiddle(
420
- parent,
421
- endMarker,
422
- oldItems,
423
- newItems,
424
- mappedNodes,
425
- disposeFns,
426
- mapFn,
427
- start,
428
- oldEnd,
429
- newEnd,
430
- newMapped,
431
- newDispose
432
- );
433
- }
434
- mappedNodes.length = newLen;
435
- disposeFns.length = newLen;
436
- for (let i = 0; i < newLen; i++) {
437
- mappedNodes[i] = newMapped[i];
438
- disposeFns[i] = newDispose[i];
439
- }
440
- }
441
- function _reconcileMiddle(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn, start, oldEnd, newEnd, newMapped, newDispose) {
442
- const oldIdxMap = /* @__PURE__ */ new Map();
443
- for (let i = start; i <= oldEnd; i++) {
444
- oldIdxMap.set(oldItems[i], i);
445
- }
446
- const midLen = newEnd - start + 1;
447
- const oldIndices = new Int32Array(midLen);
448
- oldIndices.fill(-1);
449
- for (let i = start; i <= newEnd; i++) {
450
- const oldIdx = oldIdxMap.get(newItems[i]);
451
- if (oldIdx !== void 0) {
452
- oldIdxMap.delete(newItems[i]);
453
- newMapped[i] = mappedNodes[oldIdx];
454
- newDispose[i] = disposeFns[oldIdx];
455
- oldIndices[i - start] = oldIdx;
456
- }
457
- }
458
- for (const [, oldIdx] of oldIdxMap) {
459
- disposeFns[oldIdx]?.();
460
- if (mappedNodes[oldIdx]) disposeTree(mappedNodes[oldIdx]);
461
- if (mappedNodes[oldIdx]?.parentNode) mappedNodes[oldIdx].parentNode.removeChild(mappedNodes[oldIdx]);
462
- }
463
- const reusedCount = midLen - _countNeg1(oldIndices, midLen);
464
- const inLIS = new Uint8Array(midLen);
465
- if (reusedCount > 1) {
466
- const seq = new Int32Array(reusedCount);
467
- const seqToMid = new Int32Array(reusedCount);
468
- let k = 0;
469
- for (let i = 0; i < midLen; i++) {
470
- if (oldIndices[i] !== -1) {
471
- seq[k] = oldIndices[i];
472
- seqToMid[k] = i;
473
- k++;
474
- }
475
- }
476
- const lisResult = _lis(seq, reusedCount);
477
- for (let i = 0; i < lisResult.length; i++) {
478
- inLIS[seqToMid[lisResult[i]]] = 1;
479
- }
480
- } else if (reusedCount === 1) {
481
- for (let i = 0; i < midLen; i++) {
482
- if (oldIndices[i] !== -1) {
483
- inLIS[i] = 1;
484
- break;
485
- }
486
- }
487
- }
488
- for (let i = start; i <= newEnd; i++) {
489
- if (!newMapped[i]) {
490
- const item = newItems[i];
491
- const idx = i;
492
- newMapped[i] = _createItemScope((dispose) => {
493
- newDispose[idx] = dispose;
494
- return mapFn(item, idx);
495
- });
496
- }
497
- }
498
- let nextSibling = newEnd + 1 < newMapped.length && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
499
- for (let i = newEnd; i >= start; i--) {
500
- const mi = i - start;
501
- if (oldIndices[mi] === -1 || !inLIS[mi]) {
502
- if (nextSibling && nextSibling.parentNode !== parent) nextSibling = endMarker;
503
- parent.insertBefore(newMapped[i], nextSibling);
504
- }
505
- nextSibling = newMapped[i];
506
- }
507
- }
508
- function _countNeg1(arr, len) {
509
- let c = 0;
510
- for (let i = 0; i < len; i++) if (arr[i] === -1) c++;
511
- return c;
512
- }
513
- function _lis(arr, len) {
514
- if (len === 0) return [];
515
- if (len === 1) return [0];
516
- const tails = new Int32Array(len);
517
- const predecessors = new Int32Array(len);
518
- let tailLen = 1;
519
- tails[0] = 0;
520
- predecessors[0] = -1;
521
- for (let i = 1; i < len; i++) {
522
- if (arr[i] > arr[tails[tailLen - 1]]) {
523
- predecessors[i] = tails[tailLen - 1];
524
- tails[tailLen++] = i;
525
- } else {
526
- let lo = 0, hi = tailLen - 1;
527
- while (lo < hi) {
528
- const mid = lo + hi >> 1;
529
- if (arr[tails[mid]] < arr[i]) lo = mid + 1;
530
- else hi = mid;
531
- }
532
- tails[lo] = i;
533
- predecessors[i] = lo > 0 ? tails[lo - 1] : -1;
534
- }
535
- }
536
- const result = new Array(tailLen);
537
- let k = tails[tailLen - 1];
538
- for (let i = tailLen - 1; i >= 0; i--) {
539
- result[i] = k;
540
- k = predecessors[k];
541
- }
542
- return result;
543
- }
544
- function _createItemMarker() {
545
- return document.createComment("i");
546
- }
547
- function _moveItem(parent, marker, beforeEnd, ref) {
548
- let n = marker;
549
- while (n && n !== beforeEnd) {
550
- const next = n.nextSibling;
551
- parent.insertBefore(n, ref);
552
- n = next;
553
- }
554
- }
555
- function _removeItemNodes(parent, marker, beforeEnd) {
556
- let n = marker;
557
- while (n && n !== beforeEnd) {
558
- const next = n.nextSibling;
559
- disposeTree(n);
560
- parent.removeChild(n);
561
- n = next;
562
- }
563
- }
564
- function _createKeyedItem(target, item, idx, keyFn, keyedState, mapFn, mappedArr, disposeArr, signal_) {
565
- let accessor;
566
- if (keyedState) {
567
- const key = keyFn(item);
568
- const itemSig = signal_(item);
569
- accessor = itemSig;
570
- keyedState.set(key, { itemSig });
571
- } else {
572
- accessor = item;
573
- }
574
- const marker = _createItemMarker();
575
- target.appendChild(marker);
576
- const result = _createItemScope((dispose) => {
577
- disposeArr[idx] = dispose;
578
- return mapFn(accessor, idx);
579
- });
580
- target.appendChild(result);
581
- mappedArr[idx] = marker;
582
- }
583
- function reconcileKeyed(parent, endMarker, oldItems, newItems, mappedNodes, disposeFns, mapFn, keyFn, keyedState) {
584
- const newLen = newItems.length;
585
- const oldLen = oldItems.length;
586
- if (newLen === 0) {
587
- if (oldLen > 0) {
588
- for (let i = 0; i < oldLen; i++) {
589
- if (disposeFns[i]) disposeFns[i]();
590
- }
591
- if (mappedNodes[0]) {
592
- _removeItemNodes(parent, mappedNodes[0], endMarker);
593
- }
594
- mappedNodes.length = 0;
595
- disposeFns.length = 0;
596
- if (keyedState) keyedState.clear();
597
- }
598
- return;
599
- }
600
- if (oldLen === 0) {
601
- const frag = document.createDocumentFragment();
602
- for (let i = 0; i < newLen; i++) {
603
- _createKeyedItem(frag, newItems[i], i, keyFn, keyedState, mapFn, mappedNodes, disposeFns, signal);
604
- }
605
- parent.insertBefore(frag, endMarker);
606
- return;
607
- }
608
- let start = 0;
609
- const minLen = Math.min(oldLen, newLen);
610
- while (start < minLen) {
611
- if (oldItems[start] === newItems[start]) {
612
- start++;
613
- continue;
614
- }
615
- const oldKey = keyFn(oldItems[start]);
616
- const newKey = keyFn(newItems[start]);
617
- if (oldKey !== newKey) break;
618
- if (keyedState) keyedState.get(oldKey).itemSig.set(newItems[start]);
619
- start++;
620
- }
621
- let oldEnd = oldLen - 1;
622
- let newEnd = newLen - 1;
623
- while (oldEnd >= start && newEnd >= start) {
624
- if (oldItems[oldEnd] === newItems[newEnd]) {
625
- oldEnd--;
626
- newEnd--;
627
- continue;
628
- }
629
- const oldKey = keyFn(oldItems[oldEnd]);
630
- const newKey = keyFn(newItems[newEnd]);
631
- if (oldKey !== newKey) break;
632
- if (keyedState) keyedState.get(oldKey).itemSig.set(newItems[newEnd]);
633
- oldEnd--;
634
- newEnd--;
635
- }
636
- if (start > oldEnd && start > newEnd) return;
637
- const newMapped = new Array(newLen);
638
- const newDispose = new Array(newLen);
639
- for (let i = 0; i < start; i++) {
640
- newMapped[i] = mappedNodes[i];
641
- newDispose[i] = disposeFns[i];
642
- }
643
- for (let i = newEnd + 1; i < newLen; i++) {
644
- const oldI = oldEnd + 1 + (i - newEnd - 1);
645
- newMapped[i] = mappedNodes[oldI];
646
- newDispose[i] = disposeFns[oldI];
647
- }
648
- const midNewLen = newEnd - start + 1;
649
- const midOldLen = oldEnd - start + 1;
650
- if (midOldLen === 0) {
651
- const ref2 = newEnd + 1 < newLen && newMapped[newEnd + 1] ? newMapped[newEnd + 1] : endMarker;
652
- const frag = document.createDocumentFragment();
653
- for (let i = start; i <= newEnd; i++) {
654
- _createKeyedItem(frag, newItems[i], i, keyFn, keyedState, mapFn, newMapped, newDispose, signal);
655
- }
656
- parent.insertBefore(frag, ref2);
657
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
658
- return;
659
- }
660
- if (midNewLen === 0) {
661
- for (let i = start; i <= oldEnd; i++) {
662
- disposeFns[i]?.();
663
- const rangeEnd = _findNextMarkerAfter(parent, mappedNodes[i], mappedNodes, i, endMarker);
664
- _removeItemNodes(parent, mappedNodes[i], rangeEnd);
665
- if (keyedState) keyedState.delete(keyFn(oldItems[i]));
666
- }
667
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
668
- return;
669
- }
670
- if (midNewLen === midOldLen && midNewLen >= 2 && midNewLen <= Math.max(midOldLen, 200)) {
671
- let mismatchCount = 0;
672
- let mm1 = -1, mm2 = -1;
673
- for (let i = 0; i < midNewLen && mismatchCount <= 4; i++) {
674
- const oldKey = keyFn(oldItems[start + i]);
675
- const newKey = keyFn(newItems[start + i]);
676
- if (oldKey !== newKey) {
677
- if (mismatchCount === 0) mm1 = i;
678
- else if (mismatchCount === 1) mm2 = i;
679
- mismatchCount++;
680
- }
681
- }
682
- if (mismatchCount === 2) {
683
- const i1 = start + mm1, i2 = start + mm2;
684
- const oldKey1 = keyFn(oldItems[i1]), oldKey2 = keyFn(oldItems[i2]);
685
- const newKey1 = keyFn(newItems[i1]), newKey2 = keyFn(newItems[i2]);
686
- if (oldKey1 === newKey2 && oldKey2 === newKey1) {
687
- for (let i = 0; i < start; i++) {
688
- newMapped[i] = mappedNodes[i];
689
- newDispose[i] = disposeFns[i];
690
- }
691
- for (let i = start; i <= newEnd; i++) {
692
- newMapped[i] = mappedNodes[i];
693
- newDispose[i] = disposeFns[i];
694
- }
695
- for (let i = newEnd + 1; i < newLen; i++) {
696
- const oldI = oldEnd + 1 + (i - newEnd - 1);
697
- newMapped[i] = mappedNodes[oldI];
698
- newDispose[i] = disposeFns[oldI];
699
- }
700
- const tmpM = newMapped[i1];
701
- newMapped[i1] = newMapped[i2];
702
- newMapped[i2] = tmpM;
703
- const tmpD = newDispose[i1];
704
- newDispose[i1] = newDispose[i2];
705
- newDispose[i2] = tmpD;
706
- if (keyedState) {
707
- if (newItems[i1] !== oldItems[i1]) {
708
- const k = keyFn(newItems[i1]);
709
- const entry = keyedState.get(k);
710
- if (entry) entry.itemSig.set(newItems[i1]);
711
- }
712
- if (newItems[i2] !== oldItems[i2]) {
713
- const k = keyFn(newItems[i2]);
714
- const entry = keyedState.get(k);
715
- if (entry) entry.itemSig.set(newItems[i2]);
716
- }
717
- }
718
- const isAdjacent = i2 === i1 + 1 || i1 === i2 + 1;
719
- const lo = Math.min(i1, i2), hi = Math.max(i1, i2);
720
- if (isAdjacent) {
721
- const endHi = _findNextMarkerAfter(parent, mappedNodes[hi], mappedNodes, hi, endMarker);
722
- _moveItem(parent, mappedNodes[hi], endHi, mappedNodes[lo]);
723
- } else {
724
- const end2 = _findNextMarkerAfter(parent, mappedNodes[i2], mappedNodes, i2, endMarker);
725
- const placeholder = document.createComment("tmp");
726
- parent.insertBefore(placeholder, mappedNodes[i2]);
727
- _moveItem(parent, mappedNodes[i2], end2, mappedNodes[i1]);
728
- const end1 = _findNextMarkerAfter(parent, mappedNodes[i1], mappedNodes, i1, endMarker);
729
- _moveItem(parent, mappedNodes[i1], end1, placeholder);
730
- parent.removeChild(placeholder);
731
- }
732
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
733
- return;
734
- }
735
- }
736
- if (mismatchCount >= 2 && mismatchCount <= midNewLen) {
737
- const fromRel = mm1;
738
- let movedKey = null;
739
- let fromAbs = -1, toAbs = -1;
740
- let isMove = false;
741
- const candidateKey = keyFn(oldItems[start + fromRel]);
742
- let destRel = -1;
743
- for (let i = fromRel; i < midNewLen; i++) {
744
- if (keyFn(newItems[start + i]) === candidateKey) {
745
- destRel = i;
746
- break;
747
- }
748
- }
749
- if (destRel > fromRel) {
750
- let match = true;
751
- for (let i = fromRel; i < destRel; i++) {
752
- if (keyFn(oldItems[start + i + 1]) !== keyFn(newItems[start + i])) {
753
- match = false;
754
- break;
755
- }
756
- }
757
- if (match) {
758
- let afterMatch = true;
759
- for (let i = destRel + 1; i < midNewLen; i++) {
760
- if (keyFn(oldItems[start + i]) !== keyFn(newItems[start + i])) {
761
- afterMatch = false;
762
- break;
763
- }
764
- }
765
- if (afterMatch) {
766
- isMove = true;
767
- fromAbs = start + fromRel;
768
- toAbs = start + destRel;
769
- movedKey = candidateKey;
770
- }
771
- }
772
- }
773
- if (!isMove) {
774
- const candidateKey2 = keyFn(newItems[start + fromRel]);
775
- let srcRel = -1;
776
- for (let i = fromRel; i < midOldLen; i++) {
777
- if (keyFn(oldItems[start + i]) === candidateKey2) {
778
- srcRel = i;
779
- break;
780
- }
781
- }
782
- if (srcRel > fromRel) {
783
- let match = true;
784
- for (let i = fromRel; i < srcRel; i++) {
785
- if (keyFn(oldItems[start + i]) !== keyFn(newItems[start + i + 1])) {
786
- match = false;
787
- break;
788
- }
789
- }
790
- if (match) {
791
- let afterMatch = true;
792
- for (let i = srcRel + 1; i < midNewLen; i++) {
793
- if (keyFn(oldItems[start + i]) !== keyFn(newItems[start + i])) {
794
- afterMatch = false;
795
- break;
796
- }
797
- }
798
- if (afterMatch) {
799
- isMove = true;
800
- fromAbs = start + srcRel;
801
- toAbs = start + fromRel;
802
- movedKey = candidateKey2;
803
- }
804
- }
805
- }
806
- }
807
- if (isMove) {
808
- for (let i = start; i <= oldEnd; i++) {
809
- newMapped[i] = mappedNodes[i];
810
- newDispose[i] = disposeFns[i];
811
- }
812
- const movedMarker = newMapped[fromAbs];
813
- const movedDispose = newDispose[fromAbs];
814
- if (fromAbs < toAbs) {
815
- for (let i = fromAbs; i < toAbs; i++) {
816
- newMapped[i] = newMapped[i + 1];
817
- newDispose[i] = newDispose[i + 1];
818
- }
819
- } else {
820
- for (let i = fromAbs; i > toAbs; i--) {
821
- newMapped[i] = newMapped[i - 1];
822
- newDispose[i] = newDispose[i - 1];
823
- }
824
- }
825
- newMapped[toAbs] = movedMarker;
826
- newDispose[toAbs] = movedDispose;
827
- if (keyedState) {
828
- for (let i = start; i <= newEnd; i++) {
829
- const key = keyFn(newItems[i]);
830
- if (newItems[i] !== oldItems[i]) {
831
- const entry = keyedState.get(key);
832
- if (entry) entry.itemSig.set(newItems[i]);
833
- }
834
- }
835
- }
836
- const movedEnd = _findNextMarkerAfter(parent, movedMarker, mappedNodes, fromAbs, endMarker);
837
- let ref2;
838
- if (toAbs + 1 < newLen) {
839
- ref2 = newMapped[toAbs + 1];
840
- } else {
841
- ref2 = endMarker;
842
- }
843
- if (toAbs >= newEnd + 1 || ref2 && ref2.parentNode !== parent) {
844
- ref2 = endMarker;
845
- }
846
- _moveItem(parent, movedMarker, movedEnd, ref2);
847
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
848
- return;
849
- }
850
- }
851
- }
852
- const oldKeyMap = /* @__PURE__ */ new Map();
853
- for (let i = start; i <= oldEnd; i++) {
854
- oldKeyMap.set(keyFn(oldItems[i]), i);
855
- }
856
- const oldIndices = new Int32Array(midNewLen);
857
- oldIndices.fill(-1);
858
- for (let i = start; i <= newEnd; i++) {
859
- const key = keyFn(newItems[i]);
860
- const oldIdx = oldKeyMap.get(key);
861
- if (oldIdx !== void 0) {
862
- oldKeyMap.delete(key);
863
- newMapped[i] = mappedNodes[oldIdx];
864
- newDispose[i] = disposeFns[oldIdx];
865
- oldIndices[i - start] = oldIdx;
866
- if (keyedState && newItems[i] !== oldItems[oldIdx]) {
867
- keyedState.get(key).itemSig.set(newItems[i]);
868
- }
869
- }
870
- }
871
- const removedIndices = [...oldKeyMap.values()].sort((a, b) => b - a);
872
- for (const oldIdx of removedIndices) {
873
- disposeFns[oldIdx]?.();
874
- const rangeEnd = _findNextMarkerAfter(parent, mappedNodes[oldIdx], mappedNodes, oldIdx, endMarker);
875
- _removeItemNodes(parent, mappedNodes[oldIdx], rangeEnd);
876
- if (keyedState) keyedState.delete(keyFn(oldItems[oldIdx]));
877
- }
878
- for (let i = start; i <= newEnd; i++) {
879
- if (!newMapped[i]) {
880
- const frag = document.createDocumentFragment();
881
- _createKeyedItem(frag, newItems[i], i, keyFn, keyedState, mapFn, newMapped, newDispose, signal);
882
- newMapped[i]._frag = frag;
883
- }
884
- }
885
- let reusedCount = 0;
886
- let alreadySorted = true;
887
- let lastOldIdx = -1;
888
- for (let i = 0; i < midNewLen; i++) {
889
- if (oldIndices[i] !== -1) {
890
- reusedCount++;
891
- if (oldIndices[i] <= lastOldIdx) alreadySorted = false;
892
- lastOldIdx = oldIndices[i];
893
- }
894
- }
895
- const inLIS = new Uint8Array(midNewLen);
896
- if (alreadySorted) {
897
- for (let i = 0; i < midNewLen; i++) {
898
- if (oldIndices[i] !== -1) inLIS[i] = 1;
899
- }
900
- } else if (reusedCount > 1) {
901
- const seq = new Int32Array(reusedCount);
902
- const seqToMid = new Int32Array(reusedCount);
903
- let k = 0;
904
- for (let i = 0; i < midNewLen; i++) {
905
- if (oldIndices[i] !== -1) {
906
- seq[k] = oldIndices[i];
907
- seqToMid[k] = i;
908
- k++;
909
- }
910
- }
911
- const lisResult = _lis(seq, reusedCount);
912
- for (let i = 0; i < lisResult.length; i++) {
913
- inLIS[seqToMid[lisResult[i]]] = 1;
914
- }
915
- } else if (reusedCount === 1) {
916
- for (let i = 0; i < midNewLen; i++) {
917
- if (oldIndices[i] !== -1) {
918
- inLIS[i] = 1;
919
- break;
920
- }
921
- }
922
- }
923
- _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen);
924
- let ref = newEnd + 1 < newLen && mappedNodes[newEnd + 1] ? mappedNodes[newEnd + 1] : endMarker;
925
- for (let i = newEnd; i >= start; i--) {
926
- const mi = i - start;
927
- const marker = mappedNodes[i];
928
- if (oldIndices[mi] === -1) {
929
- if (marker._frag) {
930
- parent.insertBefore(marker._frag, ref);
931
- delete marker._frag;
932
- }
933
- } else if (!inLIS[mi]) {
934
- const nextItemMarker = _findNextMarkerAfter(parent, marker, mappedNodes, i, endMarker);
935
- _moveItem(parent, marker, nextItemMarker, ref);
936
- }
937
- ref = marker;
938
- }
939
- }
940
- function _findNextMarkerAfter(parent, marker, mappedNodes, idx, endMarker) {
941
- let n = marker.nextSibling;
942
- while (n && n !== endMarker) {
943
- if (n.nodeType === 8 && n.data === "i") return n;
944
- n = n.nextSibling;
945
- }
946
- return endMarker;
947
- }
948
- function _copyBack(mappedNodes, disposeFns, newMapped, newDispose, newLen) {
949
- mappedNodes.length = newLen;
950
- disposeFns.length = newLen;
951
- for (let i = 0; i < newLen; i++) {
952
- mappedNodes[i] = newMapped[i];
953
- disposeFns[i] = newDispose[i];
954
- }
955
- }
956
- function spread(el, props) {
957
- for (const key in props) {
958
- const value = props[key];
959
- if (key.startsWith("on") && key.length > 2) {
960
- const event = key.slice(2).toLowerCase();
961
- el.addEventListener(event, value);
962
- continue;
963
- }
964
- if (typeof value === "function" && !key.startsWith("on")) {
965
- if (!el._propEffects) el._propEffects = {};
966
- if (el._propEffects[key]) {
967
- try {
968
- el._propEffects[key]();
969
- } catch (e) {
970
- }
971
- }
972
- if (key === "class" || key === "className") {
973
- el._propEffects[key] = effect(() => {
974
- const cls = value() || "";
975
- if (_hasSVGElement && el instanceof SVGElement) el.setAttribute("class", cls);
976
- else el.className = cls;
977
- });
978
- } else if (key === "style" && typeof value() === "object") {
979
- el._propEffects[key] = effect(() => {
980
- const styles = value();
981
- for (const prop in styles) {
982
- el.style[prop] = styles[prop] ?? "";
983
- }
984
- });
985
- } else {
986
- el._propEffects[key] = effect(() => {
987
- setProp(el, key, value());
988
- });
989
- }
990
- } else {
991
- setProp(el, key, value);
992
- }
993
- }
994
- }
995
- function setProp(el, key, value) {
996
- if (key === "ref") {
997
- if (typeof value === "function") value(el);
998
- else if (value && typeof value === "object") value.current = el;
999
- return;
1000
- }
1001
- if (key === "key") return;
1002
- if (typeof value === "function" && !key.startsWith("on")) {
1003
- if (!el._propEffects) el._propEffects = {};
1004
- if (el._propEffects[key]) {
1005
- try {
1006
- el._propEffects[key]();
1007
- } catch (e) {
1008
- }
1009
- }
1010
- el._propEffects[key] = effect(() => setProp(el, key, value()));
1011
- return;
1012
- }
1013
- if (URL_ATTRS.has(key) || URL_ATTRS.has(key.toLowerCase())) {
1014
- if (!isSafeUrl(value)) {
1015
- if (typeof console !== "undefined") {
1016
- console.warn(`[what] Blocked unsafe URL in "${key}" attribute: ${value}`);
1017
- }
1018
- return;
1019
- }
1020
- }
1021
- const isSvg = _hasSVGElement && el instanceof SVGElement;
1022
- if (key === "class" || key === "className") {
1023
- if (isSvg) {
1024
- el.setAttribute("class", value || "");
1025
- } else {
1026
- el.className = value || "";
1027
- }
1028
- } else if (key === "dangerouslySetInnerHTML") {
1029
- const html = value?.__html ?? "";
1030
- if (typeof __DEV__ !== "undefined" && __DEV__ && typeof html === "string" && /(<script|onerror\s*=|onload\s*=|javascript:)/i.test(html)) {
1031
- console.warn("[what] dangerouslySetInnerHTML contains potential XSS vectors. Ensure content is sanitized.");
1032
- }
1033
- el.innerHTML = html;
1034
- } else if (key === "innerHTML") {
1035
- if (value && typeof value === "object" && "__html" in value) {
1036
- const html = value.__html ?? "";
1037
- if (typeof __DEV__ !== "undefined" && __DEV__ && typeof html === "string" && /(<script|onerror\s*=|onload\s*=|javascript:)/i.test(html)) {
1038
- console.warn("[what] dangerouslySetInnerHTML contains potential XSS vectors. Ensure content is sanitized.");
1039
- }
1040
- el.innerHTML = html;
1041
- } else {
1042
- if (typeof console !== "undefined" && value != null && value !== "") {
1043
- console.warn(
1044
- '[what] Plain string innerHTML is not allowed. Use { __html: "..." } or dangerouslySetInnerHTML={{ __html: "..." }} instead.'
1045
- );
1046
- }
1047
- }
1048
- } else if (key === "style") {
1049
- if (typeof value === "string") {
1050
- el.style.cssText = value;
1051
- } else if (typeof value === "object") {
1052
- for (const prop in value) {
1053
- el.style[prop] = value[prop] ?? "";
1054
- }
1055
- }
1056
- } else if (key.startsWith("data-") || key.startsWith("aria-")) {
1057
- el.setAttribute(key, value);
1058
- } else if (typeof value === "boolean") {
1059
- if (value) el.setAttribute(key, "");
1060
- else el.removeAttribute(key);
1061
- } else if (isSvg) {
1062
- el.setAttribute(key, value);
1063
- } else if (key === "value" && el.tagName === "SELECT") {
1064
- _setSelectValue(el, value);
1065
- } else if (key in el) {
1066
- el[key] = value;
1067
- } else {
1068
- el.setAttribute(key, value);
1069
- }
1070
- }
1071
- var delegatedEvents = /* @__PURE__ */ new Set();
1072
- function delegateEvents(eventNames) {
1073
- for (const name of eventNames) {
1074
- if (delegatedEvents.has(name)) continue;
1075
- delegatedEvents.add(name);
1076
- document.addEventListener(name, (e) => {
1077
- let node = e.target;
1078
- const key = "$$" + name;
1079
- while (node) {
1080
- const handler = node[key];
1081
- if (handler) {
1082
- handler(e);
1083
- if (e.cancelBubble) return;
1084
- }
1085
- node = node.parentNode;
1086
- }
1087
- });
1088
- }
1089
- }
1090
- function on(el, event, handler) {
1091
- el.addEventListener(event, handler);
1092
- return () => el.removeEventListener(event, handler);
1093
- }
1094
- function classList(el, classes) {
1095
- effect(() => {
1096
- for (const name in classes) {
1097
- const value = typeof classes[name] === "function" ? classes[name]() : classes[name];
1098
- el.classList.toggle(name, !!value);
1099
- }
1100
- });
1101
- }
1102
- var _isHydrating = false;
1103
- var _hydrationCursor = null;
1104
- function isHydrating() {
1105
- return _isHydrating;
1106
- }
1107
- function hydrate(vnode, container) {
1108
- _isHydrating = true;
1109
- _hydrationCursor = { parent: container, index: 0 };
1110
- try {
1111
- const result = hydrateNode(vnode, container);
1112
- return result;
1113
- } finally {
1114
- _isHydrating = false;
1115
- _hydrationCursor = null;
1116
- }
1117
- }
1118
- function claimNode(parent) {
1119
- const children = parent.childNodes;
1120
- while (_hydrationCursor.index < children.length) {
1121
- const node = children[_hydrationCursor.index];
1122
- if (node.nodeType === 8) {
1123
- const text = node.textContent;
1124
- if (text === "$" || text === "/$" || text === "[]" || text === "/[]") {
1125
- _hydrationCursor.index++;
1126
- continue;
1127
- }
1128
- }
1129
- _hydrationCursor.index++;
1130
- return node;
1131
- }
1132
- return null;
1133
- }
1134
- function isDevMode() {
1135
- return typeof process !== "undefined" && true;
1136
- }
1137
- function hydrateNode(vnode, parent) {
1138
- if (vnode == null || typeof vnode === "boolean") {
1139
- return null;
1140
- }
1141
- if (typeof vnode === "string" || typeof vnode === "number") {
1142
- const existing = claimNode(parent);
1143
- const text = String(vnode);
1144
- if (existing && existing.nodeType === 3) {
1145
- if (isDevMode() && existing.textContent !== text) {
1146
- console.warn(
1147
- `[what] Hydration mismatch: expected text "${text}", got "${existing.textContent}"`
1148
- );
1149
- existing.textContent = text;
1150
- }
1151
- return existing;
1152
- }
1153
- if (isDevMode()) {
1154
- console.warn(
1155
- `[what] Hydration mismatch: expected text node "${text}", got ${existing ? existing.nodeName : "nothing"}. Falling back to client render.`
1156
- );
1157
- }
1158
- const textNode2 = document.createTextNode(text);
1159
- if (existing) {
1160
- parent.replaceChild(textNode2, existing);
1161
- } else {
1162
- parent.appendChild(textNode2);
1163
- }
1164
- return textNode2;
1165
- }
1166
- if (typeof vnode === "function") {
1167
- const initialValue = vnode();
1168
- let current = hydrateNode(initialValue, parent);
1169
- effect(() => {
1170
- const value = vnode();
1171
- if (!_isHydrating) {
1172
- current = reconcileInsert(parent, value, current, null);
1173
- }
1174
- });
1175
- return current;
1176
- }
1177
- if (Array.isArray(vnode)) {
1178
- const nodes = [];
1179
- for (const child of vnode) {
1180
- const node = hydrateNode(child, parent);
1181
- if (node) nodes.push(node);
1182
- }
1183
- return nodes.length === 1 ? nodes[0] : nodes;
1184
- }
1185
- if (typeof vnode === "object" && vnode._vnode) {
1186
- if (typeof vnode.tag === "function") {
1187
- const componentStack = getComponentStack();
1188
- const Component = vnode.tag;
1189
- const props = vnode.props || {};
1190
- const children = vnode.children || [];
1191
- const ctx = {
1192
- hooks: [],
1193
- hookIndex: 0,
1194
- effects: [],
1195
- cleanups: [],
1196
- mounted: false,
1197
- disposed: false,
1198
- Component,
1199
- _parentCtx: componentStack[componentStack.length - 1] || null,
1200
- _errorBoundary: null
1201
- };
1202
- componentStack.push(ctx);
1203
- let result;
1204
- try {
1205
- const propsChildren = children.length === 0 ? void 0 : children.length === 1 ? children[0] : children;
1206
- result = Component({ ...props, children: propsChildren });
1207
- } catch (error) {
1208
- componentStack.pop();
1209
- console.error("[what] Error in component during hydration:", Component.name || "Anonymous", error);
1210
- return null;
1211
- }
1212
- componentStack.pop();
1213
- ctx.mounted = true;
1214
- if (ctx._mountCallbacks) {
1215
- queueMicrotask(() => {
1216
- if (ctx.disposed) return;
1217
- for (const fn of ctx._mountCallbacks) {
1218
- try {
1219
- fn();
1220
- } catch (e) {
1221
- console.error("[what] onMount error:", e);
1222
- }
1223
- }
1224
- });
1225
- }
1226
- return hydrateNode(result, parent);
1227
- }
1228
- const existing = claimNode(parent);
1229
- const expectedTag = vnode.tag.toUpperCase();
1230
- if (existing && existing.nodeType === 1 && existing.nodeName === expectedTag) {
1231
- hydrateElementProps(existing, vnode.props || {});
1232
- const savedCursor = _hydrationCursor;
1233
- _hydrationCursor = { parent: existing, index: 0 };
1234
- const rawInner = vnode.props?.dangerouslySetInnerHTML?.__html;
1235
- if (rawInner == null) {
1236
- for (const child of vnode.children) {
1237
- hydrateNode(child, existing);
1238
- }
1239
- }
1240
- _hydrationCursor = savedCursor;
1241
- return existing;
1242
- }
1243
- if (isDevMode()) {
1244
- console.warn(
1245
- `[what] Hydration mismatch: expected <${vnode.tag}>, got ${existing ? existing.nodeName : "nothing"}. Falling back to client render.`
1246
- );
1247
- }
1248
- const newEl = document.createElement(vnode.tag);
1249
- for (const key in vnode.props || {}) {
1250
- if (key === "children" || key === "key") continue;
1251
- setProp(newEl, key, vnode.props[key]);
1252
- }
1253
- for (const child of vnode.children) {
1254
- reconcileInsert(newEl, child, null, null);
1255
- }
1256
- if (existing) {
1257
- parent.replaceChild(newEl, existing);
1258
- } else {
1259
- parent.appendChild(newEl);
1260
- }
1261
- return newEl;
1262
- }
1263
- if (isDomNode(vnode)) {
1264
- return vnode;
1265
- }
1266
- const textNode = document.createTextNode(String(vnode));
1267
- parent.appendChild(textNode);
1268
- return textNode;
1269
- }
1270
- function hydrateElementProps(el, props) {
1271
- for (const key in props) {
1272
- if (key === "children" || key === "key" || key === "ref") continue;
1273
- if (key === "dangerouslySetInnerHTML" || key === "innerHTML") continue;
1274
- const value = props[key];
1275
- if (key.startsWith("on") && key.length > 2) {
1276
- const event = key.slice(2).toLowerCase();
1277
- el.addEventListener(event, value);
1278
- continue;
1279
- }
1280
- if (key.startsWith("$$")) {
1281
- el[key] = value;
1282
- continue;
1283
- }
1284
- if (typeof value === "function" && !key.startsWith("on")) {
1285
- if (key === "class" || key === "className") {
1286
- effect(() => {
1287
- el.className = value() || "";
1288
- });
1289
- } else if (key === "style" && typeof value() === "object") {
1290
- effect(() => {
1291
- const styles = value();
1292
- for (const prop in styles) {
1293
- el.style[prop] = styles[prop] ?? "";
1294
- }
1295
- });
1296
- } else {
1297
- effect(() => {
1298
- setProp(el, key, value());
1299
- });
1300
- }
1301
- continue;
1302
- }
1303
- if (key === "data-hk") continue;
1304
- }
1305
- }
1306
-
1307
- export {
1308
- _setTextInsertHook,
1309
- _$createComponent,
1310
- _$templateImpl,
1311
- template,
1312
- svgTemplate,
1313
- insert,
1314
- mapArray,
1315
- spread,
1316
- setProp,
1317
- delegateEvents,
1318
- on,
1319
- classList,
1320
- isHydrating,
1321
- hydrate
1322
- };
1323
- //# sourceMappingURL=chunk-YA3W4XKH.js.map