@estjs/template 0.0.15-beta.8 → 0.0.15

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.
@@ -1,12 +1,6 @@
1
- import { isObject, startsWith, isHTMLElement, isString, error, isArray, camelCase, capitalize, warn, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isUndefined, isPromise, isFunction, coerceArray, isFalsy, isNumber, isPrimitive, isNil, kebabCase } from '@estjs/shared';
2
- export { escapeHTML } from '@estjs/shared';
3
- import { effect, shallowReactive, isSignal, signal, isComputed } from '@estjs/signals';
1
+ import { error, isHTMLElement, isPrimitive, isFalsy, isNull, isObject, isArray, isHtmlInputElement, isHtmlSelectElement, isHtmlTextAreaElement, isFunction, hasChanged, isPromise, coerceArray, startsWith, isString, isBrowser, normalizeClassName, camelCase, capitalize, warn, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isUndefined, isNumber, isTextNode } from '@estjs/shared';
2
+ import { effect, shallowReactive, isSignal, isComputed, signal, memoEffect, untrack } from '@estjs/signals';
4
3
 
5
- /**
6
- * @estjs/template v0.0.15-beta.8
7
- * (c) 2023-Present jiangxd <jiangxd2016@gmail.com>
8
- * @license MIT
9
- **/
10
4
  var __defProp = Object.defineProperty;
11
5
  var __getOwnPropSymbols = Object.getOwnPropertySymbols;
12
6
  var __hasOwnProp = Object.prototype.hasOwnProperty;
@@ -43,9 +37,110 @@ var __async = (__this, __arguments, generator) => {
43
37
  step((generator = generator.apply(__this, __arguments)).next());
44
38
  });
45
39
  };
40
+ var LIFECYCLE = {
41
+ mount: "mount",
42
+ destroy: "destroy",
43
+ update: "update"
44
+ };
45
+ function registerScopedHook(scope, listKey, hook) {
46
+ let hookList = scope[listKey];
47
+ if (!hookList) {
48
+ hookList = scope[listKey] = [];
49
+ }
50
+ if (!hookList.includes(hook)) {
51
+ hookList.push(hook);
52
+ }
53
+ }
54
+ function executeHooks(hooks, scopeId2, phase) {
55
+ const len = hooks.length;
56
+ if (len === 0) return;
57
+ let pending;
58
+ for (let i = 0; i < len; i++) {
59
+ try {
60
+ const result = hooks[i]();
61
+ if (isPromise(result)) {
62
+ const safePromise = result.catch((error_) => {
63
+ if (true) {
64
+ error(`Scope(${scopeId2}): Async ${phase} hook rejected:`, error_);
65
+ }
66
+ });
67
+ (pending != null ? pending : pending = []).push(safePromise);
68
+ }
69
+ } catch (error_) {
70
+ {
71
+ error(`Scope(${scopeId2}): Error in ${phase} hook:`, error_);
72
+ }
73
+ }
74
+ }
75
+ if (!pending) return;
76
+ return Promise.all(pending).then(() => void 0);
77
+ }
78
+ function onMount(hook) {
79
+ const scope = getActiveScope();
80
+ if (!scope) {
81
+ error("onMount() must be called within a scope");
82
+ return;
83
+ }
84
+ if (scope.isMounted) {
85
+ try {
86
+ const result = hook();
87
+ if (isPromise(result)) {
88
+ result.catch((error_) => {
89
+ if (true) error(`Scope(${scope.id}): Async ${LIFECYCLE.mount} hook rejected:`, error_);
90
+ });
91
+ }
92
+ } catch (error_) {
93
+ error(`Scope(${scope.id}): Error in ${LIFECYCLE.mount} hook:`, error_);
94
+ }
95
+ return;
96
+ }
97
+ registerScopedHook(scope, "onMount", hook);
98
+ }
99
+ function onUpdate(hook) {
100
+ const scope = getActiveScope();
101
+ if (!scope) {
102
+ error("onUpdate() must be called within a scope");
103
+ return;
104
+ }
105
+ registerScopedHook(scope, "onUpdate", hook);
106
+ }
107
+ function onDestroy(hook) {
108
+ const scope = getActiveScope();
109
+ if (!scope) {
110
+ error("onDestroy() must be called within a scope");
111
+ return;
112
+ }
113
+ registerScopedHook(scope, "onDestroy", hook);
114
+ }
115
+ function triggerMountHooks(scope) {
116
+ var _a2;
117
+ if (scope.isDestroyed || !((_a2 = scope.onMount) == null ? void 0 : _a2.length)) {
118
+ scope.isMounted = true;
119
+ return;
120
+ }
121
+ const mountHooks = scope.onMount;
122
+ const result = runWithScope(scope, () => executeHooks(mountHooks, scope.id, LIFECYCLE.mount));
123
+ mountHooks.length = 0;
124
+ scope.isMounted = true;
125
+ return result;
126
+ }
127
+ function triggerUpdateHooks(scope) {
128
+ var _a2;
129
+ if (scope.isDestroyed || !((_a2 = scope.onUpdate) == null ? void 0 : _a2.length)) return;
130
+ const updateHooks = scope.onUpdate;
131
+ const result = runWithScope(scope, () => executeHooks(updateHooks, scope.id, "update"));
132
+ updateHooks.length = 0;
133
+ return result;
134
+ }
135
+ function triggerDestroyHooks(scope) {
136
+ var _a2;
137
+ if (scope.isDestroyed || !((_a2 = scope.onDestroy) == null ? void 0 : _a2.length)) return;
138
+ return runWithScope(scope, () => executeHooks(scope.onDestroy, scope.id, "destroy"));
139
+ }
140
+
141
+ // src/scope.ts
46
142
  var activeScope = null;
47
143
  var scopeId = 0;
48
- var scopeStack = [];
49
144
  function getActiveScope() {
50
145
  return activeScope;
51
146
  }
@@ -57,64 +152,48 @@ function createScope(parent = activeScope) {
57
152
  id: ++scopeId,
58
153
  parent,
59
154
  children: null,
60
- // Lazy initialized
61
155
  provides: null,
62
- // Lazy initialized
63
156
  cleanup: null,
64
- // Lazy initialized
65
157
  onMount: null,
66
- // Lazy initialized
67
158
  onUpdate: null,
68
- // Lazy initialized
69
159
  onDestroy: null,
70
- // Lazy initialized
71
160
  isMounted: false,
72
161
  isDestroyed: false
73
162
  };
74
163
  if (parent) {
75
164
  if (!parent.children) {
76
- parent.children = /* @__PURE__ */ new Set();
165
+ parent.children = [];
77
166
  }
78
- parent.children.add(scope);
167
+ parent.children.push(scope);
79
168
  }
80
169
  return scope;
81
170
  }
82
171
  function runWithScope(scope, fn) {
83
172
  const prevScope = activeScope;
84
- if (prevScope) {
85
- scopeStack.push(prevScope);
86
- }
87
173
  activeScope = scope;
88
174
  try {
89
175
  return fn();
90
176
  } finally {
91
- activeScope = scopeStack.length > 0 ? scopeStack.pop() : prevScope;
177
+ activeScope = prevScope;
92
178
  }
93
179
  }
94
180
  function disposeScope(scope) {
95
- var _a2, _b, _c, _d, _e;
181
+ var _a2, _b, _c;
96
182
  if (!scope || scope.isDestroyed) {
97
183
  return;
98
184
  }
185
+ const parentScope = scope.parent;
99
186
  if (scope.children) {
100
- const children = Array.from(scope.children);
101
- for (const child of children) {
187
+ for (const child of scope.children) {
102
188
  disposeScope(child);
103
189
  }
190
+ scope.children.length = 0;
104
191
  }
105
- if (scope.onDestroy) {
106
- for (const hook of scope.onDestroy) {
107
- try {
108
- hook();
109
- } catch (error_) {
110
- {
111
- error(`Scope(${scope.id}): Error in destroy hook:`, error_);
112
- }
113
- }
114
- }
115
- scope.onDestroy.clear();
192
+ if ((_a2 = scope.onDestroy) == null ? void 0 : _a2.length) {
193
+ triggerDestroyHooks(scope);
194
+ scope.onDestroy.length = 0;
116
195
  }
117
- if (scope.cleanup) {
196
+ if ((_b = scope.cleanup) == null ? void 0 : _b.length) {
118
197
  for (const fn of scope.cleanup) {
119
198
  try {
120
199
  fn();
@@ -124,18 +203,22 @@ function disposeScope(scope) {
124
203
  }
125
204
  }
126
205
  }
127
- scope.cleanup.clear();
206
+ scope.cleanup.length = 0;
128
207
  }
129
- if ((_a2 = scope.parent) == null ? void 0 : _a2.children) {
130
- scope.parent.children.delete(scope);
208
+ if (parentScope == null ? void 0 : parentScope.children) {
209
+ const idx = parentScope.children.indexOf(scope);
210
+ if (idx !== -1) {
211
+ parentScope.children.splice(idx, 1);
212
+ }
131
213
  }
132
- (_b = scope.children) == null ? void 0 : _b.clear();
133
214
  (_c = scope.provides) == null ? void 0 : _c.clear();
134
- (_d = scope.onMount) == null ? void 0 : _d.clear();
135
- (_e = scope.onUpdate) == null ? void 0 : _e.clear();
136
- setActiveScope(scope.parent);
215
+ if (scope.onMount) scope.onMount.length = 0;
216
+ if (scope.onUpdate) scope.onUpdate.length = 0;
137
217
  scope.parent = null;
138
218
  scope.isDestroyed = true;
219
+ if (activeScope === scope) {
220
+ activeScope = parentScope;
221
+ }
139
222
  }
140
223
  function onCleanup(fn) {
141
224
  const scope = activeScope;
@@ -146,9 +229,9 @@ function onCleanup(fn) {
146
229
  return;
147
230
  }
148
231
  if (!scope.cleanup) {
149
- scope.cleanup = /* @__PURE__ */ new Set();
232
+ scope.cleanup = [];
150
233
  }
151
- scope.cleanup.add(fn);
234
+ scope.cleanup.push(fn);
152
235
  }
153
236
 
154
237
  // src/constants.ts
@@ -159,7 +242,11 @@ var KEY_PROP = "key";
159
242
  var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
160
243
  var XLINK_NAMESPACE = "http://www.w3.org/2000/xlink";
161
244
  var XMLNS_NAMESPACE = "http://www.w3.org/2000/xmlns/";
162
- var DATA_IDX_REGEX = /^\d+-\d+$/;
245
+ var NORMAL_COMPONENT = /* @__PURE__ */ Symbol("Normal Component" );
246
+ var FRAGMENT_COMPONENT = /* @__PURE__ */ Symbol("Fragment Component" );
247
+ var PORTAL_COMPONENT = /* @__PURE__ */ Symbol("Portal Component" );
248
+ var SUSPENSE_COMPONENT = /* @__PURE__ */ Symbol("Suspense Component" );
249
+ var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
163
250
  var MAX_KEY_LENGTH = 1e3;
164
251
  var componentKeyPrefixCache = /* @__PURE__ */ new WeakMap();
165
252
  function getComponentKey(type) {
@@ -219,7 +306,7 @@ function normalizeKey(key) {
219
306
  }
220
307
  return String(key);
221
308
  }
222
- var NODE_KEY_SYMBOL = Symbol("essor.key");
309
+ var NODE_KEY_SYMBOL = /* @__PURE__ */ Symbol("essor.key");
223
310
  function setNodeKey(node, key) {
224
311
  if (isComponent(node)) {
225
312
  return;
@@ -242,93 +329,14 @@ function getNodeKey(node) {
242
329
  return isComponent(node) ? node.key : node[NODE_KEY_SYMBOL];
243
330
  }
244
331
 
245
- // src/utils.ts
246
- function omitProps(target, keys) {
247
- const excludeSet = new Set(keys);
248
- return new Proxy(target, {
249
- // Intercept property reads
250
- get(obj, prop) {
251
- if (excludeSet.has(prop)) {
252
- return void 0;
253
- }
254
- return Reflect.get(obj, prop);
255
- },
256
- // Intercept property enumeration (for...in, Object.keys, etc.)
257
- ownKeys(obj) {
258
- return Reflect.ownKeys(obj).filter((key) => !excludeSet.has(key));
259
- },
260
- // Intercept property descriptor retrieval
261
- getOwnPropertyDescriptor(obj, prop) {
262
- if (excludeSet.has(prop)) {
263
- return void 0;
264
- }
265
- return Reflect.getOwnPropertyDescriptor(obj, prop);
266
- },
267
- // Intercept the 'in' operator
268
- has(obj, prop) {
269
- if (excludeSet.has(prop)) {
270
- return false;
271
- }
272
- return Reflect.has(obj, prop);
273
- }
274
- });
275
- }
276
- function removeNode(node) {
277
- if (!node) return;
278
- try {
279
- if (isComponent(node)) {
280
- node.destroy();
281
- } else {
282
- const element = node;
283
- if (element.parentElement) {
284
- element.remove();
285
- }
286
- }
287
- } catch (_error) {
288
- error("Failed to remove node:", _error);
289
- }
290
- }
291
- function insertNode(parent, child, before) {
292
- if (!parent || !child) return;
293
- try {
294
- const beforeNode = isComponent(before) ? before.firstChild : before;
295
- if (isComponent(child)) {
296
- child.mount(parent, beforeNode);
297
- return;
298
- }
299
- if (beforeNode) {
300
- parent.insertBefore(child, beforeNode);
301
- } else {
302
- if (true) {
303
- if (!child) {
304
- error("insertNode: child is not a Node", child);
305
- }
306
- }
307
- parent.appendChild(child);
308
- }
309
- } catch (_error) {
310
- error("Failed to insert node:", _error);
311
- }
312
- }
313
- function replaceNode(parent, newNode, oldNode) {
314
- if (!parent || !newNode || !oldNode || newNode === oldNode) return;
315
- try {
316
- const beforeNode = isComponent(oldNode) ? oldNode.beforeNode : oldNode.nextSibling;
317
- removeNode(oldNode);
318
- insertNode(parent, newNode, beforeNode);
319
- } catch (_error) {
320
- error("Failed to replace node:", _error);
321
- }
322
- }
323
- function getFirstDOMNode(node) {
324
- if (!node) {
325
- return;
326
- }
327
- if (isComponent(node)) {
328
- return node.firstChild;
332
+ // src/utils/node.ts
333
+ function normalizeNode(node) {
334
+ if (isHTMLElement(node)) {
335
+ return node;
329
336
  }
330
337
  if (isPrimitive(node)) {
331
- return void 0;
338
+ const textContent = isFalsy(node) ? "" : String(node);
339
+ return document.createTextNode(textContent);
332
340
  }
333
341
  return node;
334
342
  }
@@ -359,39 +367,65 @@ function isSameNode(a, b) {
359
367
  }
360
368
  return true;
361
369
  }
362
- function normalizeNode(node) {
363
- if (isHTMLElement(node)) {
364
- return node;
365
- }
366
- if (isPrimitive(node)) {
367
- const textContent = isFalsy(node) ? "" : String(node);
368
- return document.createTextNode(textContent);
370
+ function shallowCompare(a, b) {
371
+ if (a === b) return true;
372
+ if (isNull(a) || isNull(b)) return false;
373
+ if (!isObject(a) || !isObject(b)) return false;
374
+ if (isArray(a) !== isArray(b)) return false;
375
+ const aRecord = a;
376
+ const bRecord = b;
377
+ const aKeys = Object.keys(aRecord);
378
+ const bKeys = Object.keys(bRecord);
379
+ if (aKeys.length !== bKeys.length) return false;
380
+ for (const key of aKeys) {
381
+ if (!(key in bRecord) || aRecord[key] !== bRecord[key]) {
382
+ return false;
383
+ }
369
384
  }
370
- return node;
371
- }
372
- function isHtmlInputElement(val) {
373
- return val instanceof HTMLInputElement;
385
+ return true;
374
386
  }
375
- function isHtmlSelectElement(val) {
376
- return val instanceof HTMLSelectElement;
387
+ function removeNode(node) {
388
+ if (!node) return;
389
+ if (isComponent(node)) {
390
+ node.destroy();
391
+ return;
392
+ }
393
+ const element = node;
394
+ if (element.parentElement) {
395
+ element.remove();
396
+ }
377
397
  }
378
- function isHtmlTextAreaElement(val) {
379
- return val instanceof HTMLTextAreaElement;
398
+ function insertNode(parent, child, before) {
399
+ if (!parent || !child) return;
400
+ if (isComponent(child)) {
401
+ const beforeNode2 = isComponent(before) ? before.firstChild : before;
402
+ child.mount(parent, beforeNode2);
403
+ return;
404
+ }
405
+ const beforeNode = isComponent(before) ? before.firstChild : before;
406
+ if (beforeNode) {
407
+ parent.insertBefore(child, beforeNode);
408
+ } else {
409
+ parent.appendChild(child);
410
+ }
380
411
  }
381
- function isHtmLTextElement(val) {
382
- return val instanceof Text;
412
+ function replaceNode(parent, newNode, oldNode) {
413
+ if (!parent || !newNode || !oldNode || newNode === oldNode) return;
414
+ const beforeNode = isComponent(oldNode) ? oldNode.beforeNode : oldNode.nextSibling;
415
+ removeNode(oldNode);
416
+ insertNode(parent, newNode, beforeNode);
383
417
  }
384
- function shallowCompare(a, b) {
385
- if (a === b) return true;
386
- if (!a || !b) return false;
387
- if (Array.isArray(a) !== Array.isArray(b)) return false;
388
- for (const key in a) {
389
- if (a[key] !== b[key]) return false;
418
+ function getFirstDOMNode(node) {
419
+ if (!node) {
420
+ return;
390
421
  }
391
- for (const key in b) {
392
- if (!(key in a)) return false;
422
+ if (isComponent(node)) {
423
+ return node.firstChild;
393
424
  }
394
- return true;
425
+ if (isPrimitive(node)) {
426
+ return void 0;
427
+ }
428
+ return node;
395
429
  }
396
430
  function transferKey(oldNode, newNode) {
397
431
  if (isComponent(oldNode) || isComponent(newNode)) {
@@ -431,7 +465,7 @@ function patch(parent, oldNode, newNode) {
431
465
  return oldNode;
432
466
  }
433
467
  }
434
- if (isHtmLTextElement(oldNode) && isHtmLTextElement(newNode)) {
468
+ if (isTextNode(oldNode) && isTextNode(newNode)) {
435
469
  if (oldNode.textContent !== newNode.textContent) {
436
470
  oldNode.textContent = newNode.textContent;
437
471
  }
@@ -571,7 +605,6 @@ function patchKeyedChildren(parent, oldChildren, newChildren, anchor) {
571
605
  }
572
606
  function patchUnknownSequence(parent, oldChildren, newChildren, oldStartIdx, oldEndIdx, newStartIdx, newEndIdx, anchor) {
573
607
  const newLength = newEndIdx - newStartIdx + 1;
574
- const newChildrenLen = newChildren.length;
575
608
  let keyToNewIndexMap;
576
609
  for (let i = newStartIdx; i <= newEndIdx; i++) {
577
610
  const key = getNodeKey(newChildren[i]);
@@ -621,21 +654,26 @@ function patchUnknownSequence(parent, oldChildren, newChildren, oldStartIdx, old
621
654
  }
622
655
  const increasingNewIndexSequence = moved ? getSequence(newIndexToOldIndexMap) : [];
623
656
  let j = increasingNewIndexSequence.length - 1;
657
+ let cachedAnchor = anchor;
624
658
  for (let i = newLength - 1; i >= 0; i--) {
625
659
  const nextIndex = newStartIdx + i;
626
660
  const nextNode = newChildren[nextIndex];
627
- const nextAnchor = nextIndex + 1 < newChildrenLen ? getFirstDOMNode(newChildren[nextIndex + 1]) : anchor;
628
661
  if (newIndexToOldIndexMap[i] === 0) {
629
- insertNode(parent, nextNode, nextAnchor);
662
+ insertNode(parent, nextNode, cachedAnchor);
663
+ cachedAnchor = getFirstDOMNode(nextNode) || cachedAnchor;
630
664
  } else if (moved) {
631
665
  if (j < 0 || i !== increasingNewIndexSequence[j]) {
632
666
  const domNode = getFirstDOMNode(nextNode);
633
667
  if (domNode && domNode.parentNode === parent) {
634
- insertNode(parent, domNode, nextAnchor);
668
+ insertNode(parent, domNode, cachedAnchor);
635
669
  }
670
+ cachedAnchor = domNode || cachedAnchor;
636
671
  } else {
672
+ cachedAnchor = getFirstDOMNode(nextNode) || cachedAnchor;
637
673
  j--;
638
674
  }
675
+ } else {
676
+ cachedAnchor = getFirstDOMNode(nextNode) || cachedAnchor;
639
677
  }
640
678
  }
641
679
  }
@@ -695,72 +733,78 @@ function addEventListener(element, event, handler, options) {
695
733
  }
696
734
  function bindElement(node, key, defaultValue, setter) {
697
735
  if (isHtmlInputElement(node)) {
698
- switch (node.type) {
699
- case "checkbox":
700
- addEventListener(node, "change", () => {
701
- setter(Boolean(node.checked));
702
- });
703
- break;
704
- case "radio":
705
- addEventListener(node, "change", () => {
706
- setter(node.checked ? node.value : "");
707
- });
708
- break;
709
- case "file":
710
- addEventListener(node, "change", () => {
711
- setter(node.files);
712
- });
713
- break;
714
- case "number":
715
- case "range":
716
- addEventListener(node, "input", () => {
717
- setter(node.value || "");
718
- });
719
- break;
720
- case "date":
721
- case "datetime-local":
722
- case "month":
723
- case "time":
724
- case "week":
725
- addEventListener(node, "change", () => {
726
- setter(node.value || "");
727
- });
728
- break;
729
- default:
730
- addEventListener(node, "input", () => {
731
- setter(node.value);
732
- });
733
- break;
734
- }
736
+ bindInputElement(node, setter);
735
737
  } else if (isHtmlSelectElement(node)) {
736
- addEventListener(node, "change", () => {
737
- if (node.multiple) {
738
- const values = Array.from(node.options).filter((option) => option.selected).map((option) => option.value);
739
- setter(values);
740
- } else {
741
- setter(node.value);
742
- }
743
- });
738
+ bindSelectElement(node, setter);
744
739
  } else if (isHtmlTextAreaElement(node)) {
745
740
  addEventListener(node, "input", () => {
746
741
  setter(node.value);
747
742
  });
748
743
  }
749
744
  }
745
+ function bindInputElement(node, setter) {
746
+ switch (node.type) {
747
+ case "checkbox":
748
+ addEventListener(node, "change", () => {
749
+ setter(Boolean(node.checked));
750
+ });
751
+ break;
752
+ case "radio":
753
+ addEventListener(node, "change", () => {
754
+ setter(node.checked ? node.value : "");
755
+ });
756
+ break;
757
+ case "file":
758
+ addEventListener(node, "change", () => {
759
+ setter(node.files);
760
+ });
761
+ break;
762
+ case "number":
763
+ case "range":
764
+ addEventListener(node, "input", () => {
765
+ setter(node.value || "");
766
+ });
767
+ break;
768
+ case "date":
769
+ case "datetime-local":
770
+ case "month":
771
+ case "time":
772
+ case "week":
773
+ addEventListener(node, "change", () => {
774
+ setter(node.value || "");
775
+ });
776
+ break;
777
+ default:
778
+ addEventListener(node, "input", () => {
779
+ setter(node.value);
780
+ });
781
+ break;
782
+ }
783
+ }
784
+ function bindSelectElement(node, setter) {
785
+ addEventListener(node, "change", () => {
786
+ if (node.multiple) {
787
+ const values = Array.from(node.options).filter((option) => option.selected).map((option) => option.value);
788
+ setter(values);
789
+ } else {
790
+ setter(node.value);
791
+ }
792
+ });
793
+ }
750
794
  function insert(parent, nodeFactory, before) {
751
795
  if (!parent) return;
752
- const ownerScope = getActiveScope();
753
796
  let renderedNodes = [];
797
+ const currentScope = getActiveScope();
754
798
  const cleanup = effect(() => {
755
- const executeUpdate = () => {
799
+ const run = () => {
756
800
  const rawNodes = isFunction(nodeFactory) ? nodeFactory() : nodeFactory;
757
- const nodes = coerceArray(rawNodes).map((item) => isFunction(item) ? item() : item).flatMap((i) => i).map(normalizeNode);
801
+ const nodes = coerceArray(rawNodes).map((item) => isFunction(item) ? item() : item).flatMap(normalizeNode);
758
802
  renderedNodes = patchChildren(parent, renderedNodes, nodes, before);
759
803
  };
760
- if (ownerScope && !ownerScope.isDestroyed) {
761
- runWithScope(ownerScope, executeUpdate);
804
+ if (currentScope) {
805
+ runWithScope(currentScope, run);
762
806
  } else {
763
- executeUpdate();
807
+ run();
764
808
  }
765
809
  });
766
810
  onCleanup(() => {
@@ -794,142 +838,53 @@ function mapNodes(template2, indexes) {
794
838
  walk(template2);
795
839
  return tree;
796
840
  }
797
- function registerMountHook(hook) {
798
- const scope = getActiveScope();
799
- if (!scope) {
800
- {
801
- error("onMount() must be called within a scope");
802
- }
803
- return;
804
- }
805
- if (scope.isMounted) {
806
- try {
807
- hook();
808
- } catch (error_) {
809
- {
810
- error(`Scope(${scope.id}): Error in mount hook:`, error_);
841
+
842
+ // src/component.ts
843
+ var _a;
844
+ _a = NORMAL_COMPONENT;
845
+ var Component = class {
846
+ constructor(component, props = {}) {
847
+ this.component = component;
848
+ this.props = props;
849
+ // Component rendered nodes (supports arrays and fragments)
850
+ this.renderedNodes = [];
851
+ // Component scope (unified context management)
852
+ this.scope = null;
853
+ // Component parent node
854
+ this.parentNode = void 0;
855
+ // Component before node
856
+ this.beforeNode = void 0;
857
+ // Component props (reactive and snapshot)
858
+ this.reactiveProps = {};
859
+ this._propSnapshots = {};
860
+ // Component lifecycle state
861
+ this.state = 0 /* INITIAL */;
862
+ // Parent scope captured at construction time for correct hierarchy
863
+ this.parentScope = null;
864
+ // @ts-ignore
865
+ this[_a] = true;
866
+ this.key = props.key ? normalizeKey(props.key) : getComponentKey(component);
867
+ this.reactiveProps = shallowReactive(__spreadValues({}, props));
868
+ this.parentScope = getActiveScope();
869
+ for (const key in props) {
870
+ const val = props[key];
871
+ if (isObject(val)) {
872
+ this._propSnapshots[key] = isArray(val) ? [...val] : __spreadValues({}, val);
811
873
  }
812
874
  }
813
- return;
814
- }
815
- if (!scope.onMount) {
816
- scope.onMount = /* @__PURE__ */ new Set();
817
- }
818
- scope.onMount.add(hook);
819
- }
820
- function registerUpdateHook(hook) {
821
- const scope = getActiveScope();
822
- if (!scope) {
823
- {
824
- error("onUpdate() must be called within a scope");
825
- }
826
- return;
827
875
  }
828
- if (!scope.onUpdate) {
829
- scope.onUpdate = /* @__PURE__ */ new Set();
876
+ get isConnected() {
877
+ return this.state === 2 /* MOUNTED */;
830
878
  }
831
- scope.onUpdate.add(hook);
832
- }
833
- function registerDestroyHook(hook) {
834
- const scope = getActiveScope();
835
- if (!scope) {
836
- {
837
- error("onDestroy() must be called within a scope");
879
+ get firstChild() {
880
+ for (const node of this.renderedNodes) {
881
+ const dom = getFirstDOMNode(node);
882
+ if (dom) return dom;
838
883
  }
839
- return;
840
- }
841
- if (!scope.onDestroy) {
842
- scope.onDestroy = /* @__PURE__ */ new Set();
843
- }
844
- scope.onDestroy.add(hook);
845
- }
846
- function triggerMountHooks(scope) {
847
- if (!scope || scope.isDestroyed || scope.isMounted) {
848
- return;
849
- }
850
- scope.isMounted = true;
851
- if (scope.onMount) {
852
- runWithScope(scope, () => {
853
- for (const hook of scope.onMount) {
854
- try {
855
- hook();
856
- } catch (error_) {
857
- if (true) {
858
- error(`Scope(${scope.id}): Error in mount hook:`, error_);
859
- }
860
- }
861
- }
862
- });
863
- }
864
- }
865
- function triggerUpdateHooks(scope) {
866
- if (!scope || scope.isDestroyed) {
867
- return;
868
- }
869
- if (scope.onUpdate) {
870
- for (const hook of scope.onUpdate) {
871
- try {
872
- hook();
873
- } catch (error_) {
874
- {
875
- error(`Scope(${scope.id}): Error in update hook:`, error_);
876
- }
877
- }
878
- }
879
- }
880
- }
881
- function onMount(hook) {
882
- registerMountHook(hook);
883
- }
884
- function onDestroy(hook) {
885
- registerDestroyHook(hook);
886
- }
887
- function onUpdate(hook) {
888
- registerUpdateHook(hook);
889
- }
890
-
891
- // src/component.ts
892
- var _a;
893
- _a = "normal" /* NORMAL */;
894
- var Component = class {
895
- constructor(component, props = {}) {
896
- this.component = component;
897
- this.props = props;
898
- // component rendered nodes (supports arrays and fragments)
899
- this.renderedNodes = [];
900
- // component scope (unified context management)
901
- this.scope = null;
902
- // component parent node
903
- this.parentNode = void 0;
904
- // component before node
905
- this.beforeNode = void 0;
906
- // component reactive props
907
- this.reactiveProps = {};
908
- // component state
909
- this.state = 0 /* INITIAL */;
910
- // parent scope captured at construction time
911
- this.parentScope = null;
912
- // component type
913
- // @ts-ignore
914
- this[_a] = true;
915
- this.key = props.key ? normalizeKey(props.key) : getComponentKey(component);
916
- this.reactiveProps = shallowReactive(__spreadValues({}, props || {}));
917
- this.parentScope = getActiveScope();
918
- }
919
- get isConnected() {
920
- return this.state === 2 /* MOUNTED */;
921
- }
922
- get firstChild() {
923
- for (const node of this.renderedNodes) {
924
- const dom = getFirstDOMNode(node);
925
- if (dom) {
926
- return dom;
927
- }
928
- }
929
- return void 0;
884
+ return void 0;
930
885
  }
931
886
  mount(parentNode, beforeNode) {
932
- var _a2;
887
+ var _a2, _b;
933
888
  this.parentNode = parentNode;
934
889
  this.beforeNode = beforeNode;
935
890
  this.state = 1 /* MOUNTING */;
@@ -940,28 +895,21 @@ var Component = class {
940
895
  this.state = 2 /* MOUNTED */;
941
896
  return this.renderedNodes;
942
897
  }
943
- const parent = (_a2 = this.parentScope) != null ? _a2 : getActiveScope();
944
- this.scope = createScope(parent);
945
- const renderedNodes = runWithScope(this.scope, () => {
946
- var _a3;
947
- let result = this.component(this.reactiveProps);
948
- if (isFunction(result)) {
949
- result = result(this.reactiveProps);
950
- }
951
- if (isSignal(result) || isComputed(result)) {
952
- result = result.value;
953
- }
954
- const nodes = (_a3 = insert(parentNode, result, beforeNode)) != null ? _a3 : [];
955
- return nodes;
956
- });
898
+ const parentScope = (_a2 = this.parentScope) != null ? _a2 : getActiveScope();
899
+ this.scope = createScope(parentScope);
900
+ setActiveScope(this.scope);
901
+ let result = this.component(this.reactiveProps);
902
+ if (isFunction(result)) {
903
+ result = result(this.reactiveProps);
904
+ }
905
+ if (isSignal(result) || isComputed(result)) {
906
+ result = result.value;
907
+ }
908
+ const renderedNodes = (_b = insert(parentNode, result, beforeNode)) != null ? _b : [];
957
909
  this.renderedNodes = renderedNodes;
958
- runWithScope(this.scope, () => {
959
- this.applyProps(this.props || {});
960
- });
910
+ this.applyProps(this.props);
961
911
  this.state = 2 /* MOUNTED */;
962
- if (this.scope) {
963
- triggerMountHooks(this.scope);
964
- }
912
+ triggerMountHooks(this.scope);
965
913
  return this.renderedNodes;
966
914
  }
967
915
  update(prevNode) {
@@ -976,76 +924,106 @@ var Component = class {
976
924
  this.renderedNodes = prevNode.renderedNodes;
977
925
  this.state = prevNode.state;
978
926
  this.reactiveProps = prevNode.reactiveProps;
979
- if (this.props) {
980
- for (const key in this.props) {
981
- if (key === "key") continue;
982
- const newValue = this.props[key];
983
- const oldValue = this.reactiveProps[key];
984
- if (Object.is(oldValue, newValue)) {
985
- continue;
986
- }
987
- if (isObject(oldValue) && isObject(newValue)) {
988
- if (shallowCompare(oldValue, newValue)) {
989
- continue;
990
- }
991
- }
992
- this.reactiveProps[key] = newValue;
993
- }
994
- }
927
+ this._propSnapshots = prevNode._propSnapshots;
928
+ this._updateReactiveProps(this.props);
995
929
  if (!this.isConnected && this.parentNode) {
996
930
  this.mount(this.parentNode, this.beforeNode);
931
+ return this;
997
932
  }
998
933
  if (this.scope) {
999
- runWithScope(this.scope, () => {
1000
- this.applyProps(this.props || {});
1001
- });
934
+ setActiveScope(this.scope);
935
+ this.applyProps(this.props);
1002
936
  triggerUpdateHooks(this.scope);
1003
937
  }
1004
938
  return this;
1005
939
  }
1006
- forceUpdate() {
1007
- return __async(this, null, function* () {
1008
- yield Promise.resolve();
1009
- if (this.state === 5 /* DESTROYED */ || !this.parentNode || !this.scope) {
1010
- return;
1011
- }
1012
- const originalNodes = [...this.renderedNodes];
1013
- try {
1014
- runWithScope(this.scope, () => {
1015
- let result = this.component(this.reactiveProps);
1016
- if (isFunction(result)) {
1017
- result = result(this.reactiveProps);
1018
- }
1019
- if (isSignal(result) || isComputed(result)) {
1020
- result = result.value;
1021
- }
1022
- const newNodes = coerceArray(result);
1023
- if (this.parentNode) {
1024
- let anchor = this.beforeNode;
1025
- if (!anchor && this.renderedNodes.length > 0) {
1026
- const lastNode = this.renderedNodes[this.renderedNodes.length - 1];
1027
- const lastDom = getFirstDOMNode(lastNode);
1028
- if (lastDom) {
1029
- anchor = lastDom.nextSibling;
1030
- }
1031
- }
1032
- for (const node of this.renderedNodes) {
1033
- removeNode(node);
1034
- }
1035
- for (const node of newNodes) {
1036
- insertNode(this.parentNode, node, anchor);
1037
- }
1038
- this.renderedNodes = newNodes;
940
+ /**
941
+ * Update reactive props by comparing with current values
942
+ */
943
+ _updateReactiveProps(props) {
944
+ for (const key in props) {
945
+ if (key === "key") continue;
946
+ const newValue = props[key];
947
+ const oldValue = this.reactiveProps[key];
948
+ if (newValue === oldValue && !this._propSnapshots[key]) continue;
949
+ const isNewValueObject = isObject(newValue);
950
+ if (isNewValueObject) {
951
+ const snapshot = this._propSnapshots[key];
952
+ if (snapshot && shallowCompare(newValue, snapshot)) continue;
953
+ const newSnapshot = isArray(newValue) ? [...newValue] : __spreadValues({}, newValue);
954
+ this.reactiveProps[key] = newSnapshot;
955
+ this._propSnapshots[key] = newSnapshot;
956
+ } else {
957
+ if (hasChanged(newValue, oldValue)) {
958
+ this.reactiveProps[key] = newValue;
959
+ if (this._propSnapshots[key]) {
960
+ delete this._propSnapshots[key];
1039
961
  }
1040
- });
1041
- if (this.scope) {
1042
- triggerUpdateHooks(this.scope);
1043
962
  }
1044
- } catch (error10) {
1045
- this.renderedNodes = originalNodes;
1046
- throw error10;
1047
963
  }
1048
- });
964
+ }
965
+ }
966
+ unwrapRenderResult(result) {
967
+ if (isFunction(result)) {
968
+ result = result(this.reactiveProps);
969
+ }
970
+ if (isSignal(result) || isComputed(result)) {
971
+ result = result.value;
972
+ }
973
+ if (isComponent(result)) {
974
+ result = result.mount(this.parentNode, this.beforeNode);
975
+ }
976
+ if (isPromise(result)) {
977
+ result = result.then((r) => this.unwrapRenderResult(r));
978
+ }
979
+ return result;
980
+ }
981
+ forceUpdate() {
982
+ if (this.state === 5 /* DESTROYED */ || !this.parentNode || !this.scope) {
983
+ return;
984
+ }
985
+ const originalNodes = [...this.renderedNodes];
986
+ try {
987
+ runWithScope(this.scope, () => {
988
+ let result = this.component(this.reactiveProps);
989
+ if (isFunction(result)) {
990
+ result = result(this.reactiveProps);
991
+ }
992
+ if (isSignal(result) || isComputed(result)) {
993
+ result = result.value;
994
+ }
995
+ const newNodes = coerceArray(result);
996
+ const anchor = this._getAnchorNode();
997
+ if (!this.parentNode) return;
998
+ for (const node of this.renderedNodes) {
999
+ removeNode(node);
1000
+ }
1001
+ for (const node of newNodes) {
1002
+ insertNode(this.parentNode, node, anchor);
1003
+ }
1004
+ this.renderedNodes = newNodes;
1005
+ });
1006
+ if (this.scope) {
1007
+ triggerUpdateHooks(this.scope);
1008
+ }
1009
+ } catch (error8) {
1010
+ this.renderedNodes = originalNodes;
1011
+ throw error8;
1012
+ }
1013
+ }
1014
+ /**
1015
+ * Get anchor node for insertion
1016
+ */
1017
+ _getAnchorNode() {
1018
+ if (this.beforeNode) return this.beforeNode;
1019
+ if (this.renderedNodes.length > 0) {
1020
+ const lastNode = this.renderedNodes[this.renderedNodes.length - 1];
1021
+ const lastDom = getFirstDOMNode(lastNode);
1022
+ if (lastDom) {
1023
+ return lastDom.nextSibling;
1024
+ }
1025
+ }
1026
+ return void 0;
1049
1027
  }
1050
1028
  /**
1051
1029
  * Destroy component
@@ -1055,14 +1033,14 @@ var Component = class {
1055
1033
  return;
1056
1034
  }
1057
1035
  this.state = 4 /* DESTROYING */;
1036
+ for (const node of this.renderedNodes) {
1037
+ removeNode(node);
1038
+ }
1058
1039
  const scope = this.scope;
1059
1040
  if (scope) {
1060
1041
  disposeScope(scope);
1061
1042
  this.scope = null;
1062
1043
  }
1063
- for (const node of this.renderedNodes) {
1064
- removeNode(node);
1065
- }
1066
1044
  this.renderedNodes = [];
1067
1045
  this.parentNode = void 0;
1068
1046
  this.beforeNode = void 0;
@@ -1072,16 +1050,13 @@ var Component = class {
1072
1050
  this.state = 5 /* DESTROYED */;
1073
1051
  }
1074
1052
  applyProps(props) {
1075
- if (!props) {
1076
- return;
1077
- }
1053
+ if (!props) return;
1078
1054
  const firstElement = this.firstChild;
1079
1055
  for (const [propName, propValue] of Object.entries(props)) {
1080
- if (startsWith(propName, EVENT_PREFIX) && firstElement) {
1081
- const eventName = propName.slice(2).toLowerCase();
1082
- if (isHTMLElement(firstElement)) {
1083
- addEventListener(firstElement, eventName, propValue);
1084
- }
1056
+ if (startsWith(propName, EVENT_PREFIX)) {
1057
+ if (!firstElement || !isHTMLElement(firstElement)) return;
1058
+ const eventName = propName.slice(EVENT_PREFIX.length).toLowerCase();
1059
+ addEventListener(firstElement, eventName, propValue);
1085
1060
  } else if (propName === REF_KEY && isSignal(propValue)) {
1086
1061
  propValue.value = firstElement;
1087
1062
  }
@@ -1090,7 +1065,7 @@ var Component = class {
1090
1065
  }
1091
1066
  };
1092
1067
  function isComponent(node) {
1093
- return !!node && !!node["normal" /* NORMAL */];
1068
+ return !!node && !!node[NORMAL_COMPONENT];
1094
1069
  }
1095
1070
  function createComponent(componentFn, props) {
1096
1071
  if (isComponent(componentFn)) {
@@ -1124,7 +1099,7 @@ function createApp(component, target) {
1124
1099
  error(`Target element is not empty, it will be delete: ${target}`);
1125
1100
  container.innerHTML = "";
1126
1101
  }
1127
- const rootComponent = createComponent(component);
1102
+ const rootComponent = isComponent(component) ? component : createComponent(component);
1128
1103
  rootComponent.mount(container);
1129
1104
  return rootComponent;
1130
1105
  }
@@ -1161,55 +1136,61 @@ function inject(key, defaultValue) {
1161
1136
  }
1162
1137
  return defaultValue;
1163
1138
  }
1164
- function eventHandler(e) {
1165
- let node = e.target;
1166
- const key = `${e.type}`;
1167
- const oriTarget = e.target;
1168
- const oriCurrentTarget = e.currentTarget;
1169
- const reTarget = (value) => Object.defineProperty(e, "target", {
1139
+ function reTarget(event, value) {
1140
+ Object.defineProperty(event, "target", {
1170
1141
  configurable: true,
1171
1142
  value
1172
1143
  });
1173
- const handleNode = () => {
1174
- const handler = node[`_$${key}`];
1175
- if (handler && isFunction(handler) && !node.disabled) {
1176
- const data = node[`${key}Data`];
1177
- data ? handler.call(node, data, e) : handler.call(node, e);
1178
- if (e.cancelBubble) return false;
1179
- }
1180
- if (node.host && !isString(node.host) && !node.host._$host && isFunction(node.contains) && node.contains(e.target)) {
1181
- reTarget(node.host);
1182
- }
1183
- return true;
1184
- };
1185
- const walkUpTree = () => {
1186
- while (handleNode() && (node = node._$host || node.parentNode || node.host)) ;
1187
- };
1188
- Object.defineProperty(e, "currentTarget", {
1144
+ }
1145
+ function handleNodeEvent(node, event, key) {
1146
+ const handler = node[`_$${key}`];
1147
+ if (handler && isFunction(handler) && !node.disabled) {
1148
+ const data = node[`${key}Data`];
1149
+ data ? handler.call(node, data, event) : handler.call(node, event);
1150
+ if (event.cancelBubble) return false;
1151
+ }
1152
+ if (node.host && !isString(node.host) && !node.host._$host && isFunction(node.contains) && node.contains(event.target)) {
1153
+ reTarget(event, node.host);
1154
+ }
1155
+ return true;
1156
+ }
1157
+ function walkUpTree(startNode, event, key) {
1158
+ let node = startNode;
1159
+ while (handleNodeEvent(node, event, key) && (node = node._$host || node.parentNode || node.host)) ;
1160
+ return node;
1161
+ }
1162
+ function eventHandler(event) {
1163
+ let node = event.target;
1164
+ const key = `${event.type}`;
1165
+ const oriTarget = event.target;
1166
+ const oriCurrentTarget = event.currentTarget;
1167
+ Object.defineProperty(event, "currentTarget", {
1189
1168
  configurable: true,
1190
1169
  get() {
1191
1170
  return node || document;
1192
1171
  }
1193
1172
  });
1194
- if (e.composedPath) {
1195
- const path = e.composedPath();
1196
- reTarget(path[0]);
1173
+ if (event.composedPath) {
1174
+ const path = event.composedPath();
1175
+ reTarget(event, path[0]);
1197
1176
  for (let i = 0; i < path.length - 2; i++) {
1198
1177
  node = path[i];
1199
- if (!handleNode()) break;
1178
+ if (!handleNodeEvent(node, event, key)) break;
1200
1179
  if (node._$host) {
1201
1180
  node = node._$host;
1202
- walkUpTree();
1181
+ node = walkUpTree(node, event, key);
1203
1182
  break;
1204
1183
  }
1205
1184
  if (node.parentNode === oriCurrentTarget) {
1206
1185
  break;
1207
1186
  }
1208
1187
  }
1209
- } else walkUpTree();
1210
- reTarget(oriTarget);
1188
+ } else {
1189
+ node = walkUpTree(node, event, key);
1190
+ }
1191
+ reTarget(event, oriTarget);
1211
1192
  }
1212
- var $EVENTS = Symbol("_$EVENTS");
1193
+ var $EVENTS = /* @__PURE__ */ Symbol("_$EVENTS");
1213
1194
  function delegateEvents(eventNames, document2 = window.document) {
1214
1195
  const docWithEvents = document2;
1215
1196
  const eventSet = docWithEvents[$EVENTS] || (docWithEvents[$EVENTS] = /* @__PURE__ */ new Set());
@@ -1220,10 +1201,149 @@ function delegateEvents(eventNames, document2 = window.document) {
1220
1201
  }
1221
1202
  }
1222
1203
  }
1204
+
1205
+ // src/utils/props.ts
1206
+ function omitProps(target, keys) {
1207
+ const excludeSet = new Set(keys);
1208
+ return new Proxy(target, {
1209
+ // Intercept property reads
1210
+ get(obj, prop) {
1211
+ if (excludeSet.has(prop)) {
1212
+ return void 0;
1213
+ }
1214
+ return Reflect.get(obj, prop);
1215
+ },
1216
+ // Intercept property enumeration (for...in, Object.keys, etc.)
1217
+ ownKeys(obj) {
1218
+ return Reflect.ownKeys(obj).filter((key) => !excludeSet.has(key));
1219
+ },
1220
+ // Intercept property descriptor retrieval
1221
+ getOwnPropertyDescriptor(obj, prop) {
1222
+ if (excludeSet.has(prop)) {
1223
+ return void 0;
1224
+ }
1225
+ return Reflect.getOwnPropertyDescriptor(obj, prop);
1226
+ },
1227
+ // Intercept the 'in' operator
1228
+ has(obj, prop) {
1229
+ if (excludeSet.has(prop)) {
1230
+ return false;
1231
+ }
1232
+ return Reflect.has(obj, prop);
1233
+ }
1234
+ });
1235
+ }
1236
+
1237
+ // src/hydration/shared.ts
1238
+ var isHydrationActive = false;
1239
+ function startHydration() {
1240
+ isHydrationActive = true;
1241
+ }
1242
+ function endHydration() {
1243
+ isHydrationActive = false;
1244
+ }
1245
+ function isHydrating() {
1246
+ return isHydrationActive;
1247
+ }
1248
+ var hydrationCounter = 0;
1249
+ function getHydrationKey() {
1250
+ return `${hydrationCounter++}`;
1251
+ }
1252
+ function resetHydrationKey() {
1253
+ hydrationCounter = 0;
1254
+ }
1255
+
1256
+ // src/hydration/hydration.ts
1257
+ var DATA_IDX_REGEX = /^\d+-\d+$/;
1258
+ function getRenderedElement(temp) {
1259
+ return () => {
1260
+ if (!isBrowser()) {
1261
+ return null;
1262
+ }
1263
+ const key = getHydrationKey();
1264
+ const node = document.querySelector(`[data-hk="${key}"]`);
1265
+ if (node) {
1266
+ return node;
1267
+ }
1268
+ return template(temp)();
1269
+ };
1270
+ }
1271
+ function mapSSRNodes(templateEl, idx) {
1272
+ const hk = templateEl.dataset.hk;
1273
+ if (!hk) {
1274
+ return mapNodes(templateEl, idx);
1275
+ }
1276
+ const nodesList = [];
1277
+ const elements = templateEl.querySelectorAll(`[data-idx^="${hk}"]`);
1278
+ if (elements.length > 0) {
1279
+ nodesList.push(
1280
+ ...Array.from(elements).filter((item) => {
1281
+ const idxAttr = item.dataset.idx;
1282
+ return idxAttr !== null && DATA_IDX_REGEX.test(idxAttr);
1283
+ }).map((item) => {
1284
+ const idxAttr = item.dataset.idx || "";
1285
+ const [hkPart, idxPart] = idxAttr.split("-");
1286
+ return {
1287
+ hk: hkPart,
1288
+ idx: idxPart,
1289
+ node: item
1290
+ };
1291
+ })
1292
+ );
1293
+ }
1294
+ const commentNodes = [];
1295
+ const walkNodes = (node) => {
1296
+ if (node.nodeType === Node.COMMENT_NODE && node.textContent && DATA_IDX_REGEX.test(node.textContent)) {
1297
+ const [hkPart, idxPart] = node.textContent.split("-");
1298
+ commentNodes.push({
1299
+ hk: hkPart,
1300
+ idx: idxPart,
1301
+ node
1302
+ });
1303
+ }
1304
+ let child = node.firstChild;
1305
+ while (child) {
1306
+ walkNodes(child);
1307
+ child = child.nextSibling;
1308
+ }
1309
+ };
1310
+ walkNodes(templateEl);
1311
+ nodesList.push(...commentNodes);
1312
+ const nodes = [templateEl];
1313
+ idx.forEach((indexValue) => {
1314
+ const node = nodesList.find((item) => item.idx === String(indexValue));
1315
+ if (node) {
1316
+ nodes.push(node.node);
1317
+ }
1318
+ });
1319
+ return nodes;
1320
+ }
1321
+ function hydrate(component, container) {
1322
+ startHydration();
1323
+ resetHydrationKey();
1324
+ try {
1325
+ const rootElement = isString(container) ? document.querySelector(container) : container;
1326
+ if (!rootElement) {
1327
+ error("Hydration error: Root element not found");
1328
+ return void 0;
1329
+ }
1330
+ const rootComponent = createComponent(component);
1331
+ rootComponent.mount(rootElement);
1332
+ endHydration();
1333
+ return rootComponent;
1334
+ } catch (error_) {
1335
+ error("Hydration error:", error_);
1336
+ endHydration();
1337
+ return void 0;
1338
+ }
1339
+ }
1223
1340
  function patchClass(el, prev, next, isSVG = false) {
1224
1341
  if (prev === next) {
1225
1342
  return;
1226
1343
  }
1344
+ if (isHydrating()) {
1345
+ return;
1346
+ }
1227
1347
  const normalizedNext = normalizeClass(next);
1228
1348
  const normalizedPrev = normalizeClass(prev);
1229
1349
  if (normalizedNext && normalizedPrev === normalizedNext) {
@@ -1238,25 +1358,7 @@ function patchClass(el, prev, next, isSVG = false) {
1238
1358
  }
1239
1359
  }
1240
1360
  function normalizeClass(value) {
1241
- if (value == null) {
1242
- return "";
1243
- }
1244
- if (typeof value === "string") {
1245
- return value.trim();
1246
- }
1247
- if (isArray(value)) {
1248
- return value.map(normalizeClass).filter(Boolean).join(" ");
1249
- }
1250
- if (isObject(value)) {
1251
- const result = [];
1252
- for (const key in value) {
1253
- if (value[key]) {
1254
- result.push(key);
1255
- }
1256
- }
1257
- return result.join(" ");
1258
- }
1259
- return String(value).trim();
1361
+ return normalizeClassName(value);
1260
1362
  }
1261
1363
  var importantRE = /\s*!important$/;
1262
1364
  var prefixes = ["Webkit", "Moz", "ms"];
@@ -1264,6 +1366,9 @@ var prefixCache = {};
1264
1366
  function patchStyle(el, prev, next) {
1265
1367
  const style = el.style;
1266
1368
  const isCssString = isString(next);
1369
+ if (isHydrating()) {
1370
+ return;
1371
+ }
1267
1372
  if (next && isCssString) {
1268
1373
  if (prev !== next) {
1269
1374
  style.cssText = next;
@@ -1318,7 +1423,7 @@ function setStyle(style, name, val) {
1318
1423
  return;
1319
1424
  }
1320
1425
  const prefixed = autoPrefix(style, name);
1321
- if (typeof val === "string" && importantRE.test(val)) {
1426
+ if (isString(val) && importantRE.test(val)) {
1322
1427
  style.setProperty(camelCase(prefixed), val.replace(importantRE, ""), "important");
1323
1428
  } else {
1324
1429
  style[prefixed] = val;
@@ -1362,6 +1467,9 @@ function patchAttr(el, key, prev, next) {
1362
1467
  });
1363
1468
  return;
1364
1469
  }
1470
+ if (isHydrating()) {
1471
+ return;
1472
+ }
1365
1473
  const elementIsSVG = (el == null ? void 0 : el.namespaceURI) === SVG_NAMESPACE;
1366
1474
  const isXlink = elementIsSVG && key.startsWith("xlink:");
1367
1475
  const isXmlns = elementIsSVG && key.startsWith("xmlns:");
@@ -1370,7 +1478,7 @@ function patchAttr(el, key, prev, next) {
1370
1478
  return;
1371
1479
  }
1372
1480
  const lowerKey = key.toLowerCase();
1373
- if (/^on[a-z]+/.test(lowerKey)) {
1481
+ if (lowerKey.length > 2 && lowerKey.charCodeAt(0) === 111 && lowerKey.charCodeAt(1) === 110) {
1374
1482
  return;
1375
1483
  }
1376
1484
  if (lowerKey === "innerhtml") {
@@ -1405,7 +1513,7 @@ function patchAttr(el, key, prev, next) {
1405
1513
  }
1406
1514
  const attrValue = isSymbol(next) ? String(next) : next;
1407
1515
  const isUrlAttr = lowerKey === "href" || lowerKey === "src" || lowerKey === "xlink:href";
1408
- if (isUrlAttr && typeof attrValue === "string") {
1516
+ if (isUrlAttr && isString(attrValue)) {
1409
1517
  const v = attrValue.trim().toLowerCase();
1410
1518
  if (v.startsWith("javascript:") || v.startsWith("data:")) {
1411
1519
  return;
@@ -1452,26 +1560,21 @@ function Fragment(props) {
1452
1560
  error("Fragment component requires props");
1453
1561
  return null;
1454
1562
  }
1455
- if (!props.children) {
1456
- error("Fragment component requires children");
1457
- return null;
1458
- }
1459
1563
  }
1460
- return props == null ? void 0 : props.children;
1564
+ if (!(props == null ? void 0 : props.children)) {
1565
+ error("Fragment component requires children");
1566
+ return null;
1567
+ }
1568
+ const { children } = props;
1569
+ return children;
1461
1570
  }
1462
- Fragment["fragment" /* FRAGMENT */] = true;
1571
+ Fragment[FRAGMENT_COMPONENT] = true;
1463
1572
  function isFragment(node) {
1464
- return !!node && !!node["fragment" /* FRAGMENT */];
1573
+ return !!node && !!node[FRAGMENT_COMPONENT];
1465
1574
  }
1466
1575
  function Portal(props) {
1467
- if (typeof document === "undefined") {
1468
- const children2 = props.children;
1469
- if (!children2) return "";
1470
- const childArray = isArray(children2) ? children2 : [children2];
1471
- return childArray.map((child) => String(child || "")).join("");
1472
- }
1473
1576
  const placeholder = document.createComment("portal");
1474
- placeholder["portal" /* PORTAL */] = true;
1577
+ placeholder[PORTAL_COMPONENT] = true;
1475
1578
  const children = props.children;
1476
1579
  if (children) {
1477
1580
  const childArray = isArray(children) ? children : [children];
@@ -1479,7 +1582,7 @@ function Portal(props) {
1479
1582
  onMount(() => {
1480
1583
  const targetElement = isString(props.target) ? document.querySelector(props.target) : props.target;
1481
1584
  if (!targetElement) {
1482
- {
1585
+ if (true) {
1483
1586
  warn(`[Portal] Target element not found: ${props.target}`);
1484
1587
  }
1485
1588
  return;
@@ -1495,7 +1598,7 @@ function Portal(props) {
1495
1598
  });
1496
1599
  onCleanup(() => {
1497
1600
  nodes.forEach((node) => {
1498
- if (typeof node !== "string" && node.parentNode === targetElement) {
1601
+ if (!isString(node) && node.parentNode === targetElement) {
1499
1602
  targetElement.removeChild(node);
1500
1603
  }
1501
1604
  });
@@ -1504,11 +1607,11 @@ function Portal(props) {
1504
1607
  }
1505
1608
  return placeholder;
1506
1609
  }
1507
- Portal["portal" /* PORTAL */] = true;
1610
+ Portal[PORTAL_COMPONENT] = true;
1508
1611
  function isPortal(node) {
1509
- return !!node && !!node["portal" /* PORTAL */];
1612
+ return !!node && !!node[PORTAL_COMPONENT];
1510
1613
  }
1511
- var SuspenseContext = Symbol("SuspenseContext");
1614
+ var SuspenseContext = /* @__PURE__ */ Symbol("SuspenseContext");
1512
1615
  function Suspense(props) {
1513
1616
  if (isUndefined(document)) {
1514
1617
  const fallback = props.fallback;
@@ -1592,9 +1695,9 @@ function Suspense(props) {
1592
1695
  if (pendingCount === 0) {
1593
1696
  showChildren();
1594
1697
  }
1595
- }).catch((error10) => {
1698
+ }).catch((error8) => {
1596
1699
  {
1597
- warn("[Suspense] Resource failed:", error10);
1700
+ warn("[Suspense] Resource failed:", error8);
1598
1701
  }
1599
1702
  if (!isMounted) return;
1600
1703
  pendingCount--;
@@ -1635,14 +1738,14 @@ function Suspense(props) {
1635
1738
  });
1636
1739
  return container;
1637
1740
  }
1638
- Suspense["suspense" /* SUSPENSE */] = true;
1741
+ Suspense[SUSPENSE_COMPONENT] = true;
1639
1742
  function isSuspense(node) {
1640
- return !!node && !!node["suspense" /* SUSPENSE */];
1743
+ return !!node && !!node[SUSPENSE_COMPONENT];
1641
1744
  }
1642
1745
  function createResource(fetcher, options) {
1643
1746
  const value = signal(options == null ? void 0 : options.initialValue);
1644
1747
  const loading = signal(true);
1645
- const error10 = signal(null);
1748
+ const error8 = signal(null);
1646
1749
  const state = signal("pending");
1647
1750
  let fetchId = 0;
1648
1751
  let currentPromise = null;
@@ -1650,7 +1753,7 @@ function createResource(fetcher, options) {
1650
1753
  const currentFetchId = ++fetchId;
1651
1754
  loading.value = true;
1652
1755
  state.value = "pending";
1653
- error10.value = null;
1756
+ error8.value = null;
1654
1757
  try {
1655
1758
  const promise = fetcher();
1656
1759
  currentPromise = promise.then(() => {
@@ -1664,7 +1767,7 @@ function createResource(fetcher, options) {
1664
1767
  }
1665
1768
  } catch (error_) {
1666
1769
  if (currentFetchId === fetchId) {
1667
- error10.value = error_ instanceof Error ? error_ : new Error(String(error_));
1770
+ error8.value = error_ instanceof Error ? error_ : new Error(String(error_));
1668
1771
  state.value = "errored";
1669
1772
  loading.value = false;
1670
1773
  }
@@ -1681,14 +1784,14 @@ function createResource(fetcher, options) {
1681
1784
  return value.value;
1682
1785
  });
1683
1786
  resource.loading = loading;
1684
- resource.error = error10;
1787
+ resource.error = error8;
1685
1788
  resource.state = state;
1686
1789
  const actions = {
1687
1790
  mutate: (newValue) => {
1688
1791
  value.value = newValue;
1689
1792
  state.value = "ready";
1690
1793
  loading.value = false;
1691
- error10.value = null;
1794
+ error8.value = null;
1692
1795
  },
1693
1796
  refetch: () => __async(null, null, function* () {
1694
1797
  yield fetch();
@@ -1696,243 +1799,173 @@ function createResource(fetcher, options) {
1696
1799
  };
1697
1800
  return [resource, actions];
1698
1801
  }
1699
- var hydrationCounter = 0;
1700
- function getHydrationKey() {
1701
- return `${hydrationCounter++}`;
1702
- }
1703
- function resetHydrationKey() {
1704
- hydrationCounter = 0;
1705
- }
1706
- function endHydration() {
1707
- }
1708
- function convertToString(content, isSvg = false) {
1709
- if (isNil(content)) {
1710
- return "";
1711
- }
1712
- if (isString(content)) {
1713
- return content;
1714
- }
1715
- if (isArray(content)) {
1716
- return content.map((item) => convertToString(item, isSvg)).join("");
1717
- }
1718
- if (isFunction(content)) {
1719
- return convertToString(content(), isSvg);
1720
- }
1721
- return String(content);
1722
- }
1723
- function addAttributes(htmlContent, hydrationId) {
1724
- const rootElementRegex = /^<([a-z]+)(\s*)([^>]*)>/i;
1725
- const indexAttributeRegex = /data-idx="(\d+)"/g;
1726
- const commentRegex = /<!--(.*?)-->/g;
1727
- const enhancedHtml = htmlContent.replace(rootElementRegex, `<$1$2$3 data-hk="${hydrationId}">`).replaceAll(indexAttributeRegex, `data-idx="${hydrationId}-$1"`).replaceAll(commentRegex, `<!--${hydrationId}-$1-->`);
1728
- return enhancedHtml;
1729
- }
1730
-
1731
- // src/server/render.ts
1732
- function renderToString(component, props = {}) {
1733
- if (!isFunction(component)) {
1734
- error("Component must be a function");
1735
- return "";
1736
- }
1737
- resetHydrationKey();
1738
- const result = component(props);
1739
- return convertToString(result);
1740
- }
1741
- function render(templates, hydrationKey, ...components) {
1742
- let content = "";
1743
- let index = 0;
1744
- for (const template2 of templates) {
1745
- content += template2;
1746
- if (index < components.length) {
1747
- const component = components[index++];
1748
- if (component) {
1749
- content += convertToString(component);
1802
+ function For(props) {
1803
+ const fragment = document.createDocumentFragment();
1804
+ const marker = document.createComment("");
1805
+ fragment.appendChild(marker);
1806
+ let entries = [];
1807
+ let fallbackNode = null;
1808
+ const keyFn = props.keyFn;
1809
+ const renderFn = props.children;
1810
+ const getList = () => {
1811
+ var _a2, _b;
1812
+ const input = props.each;
1813
+ if (isSignal(input)) return (_a2 = input.value) != null ? _a2 : [];
1814
+ if (typeof input === "function") return (_b = input()) != null ? _b : [];
1815
+ return input != null ? input : [];
1816
+ };
1817
+ const getKey = (item) => keyFn ? keyFn(item) : item;
1818
+ const renderItem = (item, index, parent, before) => {
1819
+ var _a2;
1820
+ const prevScope = getActiveScope();
1821
+ const scope = createScope(prevScope);
1822
+ setActiveScope(scope);
1823
+ let node;
1824
+ try {
1825
+ const result = renderFn(item, index);
1826
+ if (isComponent(result)) {
1827
+ result.mount(parent, before);
1828
+ node = (_a2 = result.firstChild) != null ? _a2 : document.createComment("empty");
1829
+ } else {
1830
+ node = result;
1831
+ if (!node.parentNode) {
1832
+ if (before) {
1833
+ parent.insertBefore(node, before);
1834
+ } else {
1835
+ parent.appendChild(node);
1836
+ }
1837
+ }
1750
1838
  }
1839
+ } finally {
1840
+ setActiveScope(prevScope);
1751
1841
  }
1752
- }
1753
- const result = addAttributes(content, hydrationKey);
1754
- return result;
1755
- }
1756
- function createSSGComponent(component, props = {}) {
1757
- if (!isFunction(component)) {
1758
- error("create ssg component: Component is not a function");
1759
- return "";
1760
- }
1761
- const result = component(props);
1762
- return convertToString(result);
1763
- }
1764
- function normalizeStyle(styleValue) {
1765
- if (isArray(styleValue)) {
1766
- const normalizedStyleObject = {};
1767
- for (const styleItem of styleValue) {
1768
- const normalizedItem = isString(styleItem) ? parseStyleString(styleItem) : normalizeStyle(styleItem);
1769
- if (normalizedItem) {
1770
- for (const key in normalizedItem) {
1771
- normalizedStyleObject[key] = normalizedItem[key];
1842
+ return { key: getKey(item), node, scope };
1843
+ };
1844
+ const disposeItem = (entry) => {
1845
+ disposeScope(entry.scope);
1846
+ if (entry.node.parentNode) {
1847
+ entry.node.parentNode.removeChild(entry.node);
1848
+ }
1849
+ };
1850
+ memoEffect(
1851
+ ({ prev }) => {
1852
+ var _a2;
1853
+ const newItems = getList();
1854
+ if (prev === newItems) return { prev: newItems };
1855
+ const parent = marker.parentNode;
1856
+ if (!parent) {
1857
+ if (newItems.length === 0) {
1858
+ if (props.fallback) {
1859
+ const fb = props.fallback();
1860
+ if (isComponent(fb)) {
1861
+ fb.mount(fragment, marker);
1862
+ fallbackNode = (_a2 = fb.firstChild) != null ? _a2 : document.createComment("empty");
1863
+ } else {
1864
+ fallbackNode = fb;
1865
+ fragment.insertBefore(fallbackNode, marker);
1866
+ }
1867
+ }
1868
+ return { prev: newItems };
1869
+ }
1870
+ entries = new Array(newItems.length);
1871
+ for (const [i, newItem] of newItems.entries()) {
1872
+ entries[i] = renderItem(newItem, i, fragment, marker);
1772
1873
  }
1874
+ return { prev: newItems };
1773
1875
  }
1876
+ untrack(() => reconcile(parent, newItems));
1877
+ return { prev: newItems };
1878
+ },
1879
+ {
1880
+ prev: []
1774
1881
  }
1775
- return normalizedStyleObject;
1776
- }
1777
- if (isString(styleValue) || isObject(styleValue)) {
1778
- return styleValue;
1779
- }
1780
- return void 0;
1781
- }
1782
- var styleSeparatorRegex = /;(?![^(]*\))/g;
1783
- var propertyValueSeparatorRegex = /:([\s\S]+)/;
1784
- var styleCommentRegex = /\/\*[\s\S]*?\*\//g;
1785
- function parseStyleString(cssText) {
1786
- const styleObject = {};
1787
- cssText.replaceAll(styleCommentRegex, "").split(styleSeparatorRegex).forEach((styleItem) => {
1788
- if (styleItem) {
1789
- const parts = styleItem.split(propertyValueSeparatorRegex);
1790
- if (parts.length > 1) {
1791
- styleObject[parts[0].trim()] = parts[1].trim();
1882
+ );
1883
+ function reconcile(parent, newItems) {
1884
+ var _a2;
1885
+ const oldLen = entries.length;
1886
+ const newLen = newItems.length;
1887
+ if (newLen === 0) {
1888
+ for (let i = 0; i < oldLen; i++) {
1889
+ disposeItem(entries[i]);
1890
+ }
1891
+ entries = [];
1892
+ if (props.fallback && !fallbackNode) {
1893
+ const fb = props.fallback();
1894
+ if (isComponent(fb)) {
1895
+ fb.mount(parent, marker);
1896
+ fallbackNode = (_a2 = fb.firstChild) != null ? _a2 : document.createComment("empty");
1897
+ } else {
1898
+ fallbackNode = fb;
1899
+ parent.insertBefore(fallbackNode, marker);
1900
+ }
1792
1901
  }
1902
+ return;
1793
1903
  }
1794
- });
1795
- return styleObject;
1796
- }
1797
- function styleObjectToString(styleValue) {
1798
- if (!styleValue) {
1799
- return "";
1800
- }
1801
- if (isString(styleValue)) {
1802
- return styleValue;
1803
- }
1804
- let cssText = "";
1805
- for (const propName in styleValue) {
1806
- const propValue = styleValue[propName];
1807
- if (isString(propValue) || isNumber(propValue)) {
1808
- const normalizedPropName = propName.startsWith("--") ? propName : kebabCase(propName);
1809
- cssText += `${normalizedPropName}:${propValue};`;
1904
+ if (oldLen === 0 || fallbackNode) {
1905
+ if (fallbackNode) {
1906
+ if (fallbackNode.parentNode) fallbackNode.parentNode.removeChild(fallbackNode);
1907
+ fallbackNode = null;
1908
+ }
1909
+ entries = new Array(newLen);
1910
+ const batchFragment2 = document.createDocumentFragment();
1911
+ for (let i = 0; i < newLen; i++) {
1912
+ entries[i] = renderItem(newItems[i], i, batchFragment2, null);
1913
+ }
1914
+ parent.insertBefore(batchFragment2, marker);
1915
+ return;
1810
1916
  }
1811
- }
1812
- return cssText;
1813
- }
1814
- function normalizeClassName(classValue) {
1815
- let resultClassName = "";
1816
- if (isString(classValue)) {
1817
- resultClassName = classValue;
1818
- } else if (isArray(classValue)) {
1819
- for (const item of classValue) {
1820
- const normalizedItem = normalizeClassName(item);
1821
- if (normalizedItem) {
1822
- resultClassName += `${normalizedItem} `;
1917
+ const oldKeyMap = /* @__PURE__ */ new Map();
1918
+ for (let i = 0; i < oldLen; i++) {
1919
+ const entry = entries[i];
1920
+ const list = oldKeyMap.get(entry.key);
1921
+ if (list) {
1922
+ list.push(entry);
1923
+ } else {
1924
+ oldKeyMap.set(entry.key, [entry]);
1823
1925
  }
1824
1926
  }
1825
- } else if (isObject(classValue)) {
1826
- for (const className in classValue) {
1827
- if (classValue[className]) {
1828
- resultClassName += `${className} `;
1927
+ const newEntries = new Array(newLen);
1928
+ const toRemove = [];
1929
+ const batchFragment = document.createDocumentFragment();
1930
+ for (let i = 0; i < newLen; i++) {
1931
+ const item = newItems[i];
1932
+ const key = getKey(item);
1933
+ const oldList = oldKeyMap.get(key);
1934
+ if (oldList && oldList.length > 0) {
1935
+ newEntries[i] = oldList.shift();
1936
+ } else {
1937
+ newEntries[i] = renderItem(item, i, batchFragment, null);
1829
1938
  }
1830
1939
  }
1831
- }
1832
- return resultClassName.trim();
1833
- }
1834
- function setSSGAttr(attrName, attrValue, hydrationId) {
1835
- if (isSignal(attrValue) || isComputed(attrValue)) {
1836
- return setSSGAttr(attrName, attrValue.value);
1837
- }
1838
- if (!attrValue && attrValue !== 0) {
1839
- return "";
1840
- }
1841
- if (attrName === "style") {
1842
- const normalizedStyle = normalizeStyle(attrValue);
1843
- if (!normalizedStyle) {
1844
- return "";
1940
+ for (const list of oldKeyMap.values()) {
1941
+ for (const entry of list) {
1942
+ toRemove.push(entry);
1943
+ }
1845
1944
  }
1846
- if (isString(normalizedStyle)) {
1847
- return ` style="${normalizedStyle}"`;
1945
+ for (const entry of toRemove) {
1946
+ disposeItem(entry);
1848
1947
  }
1849
- return ` style="${styleObjectToString(normalizedStyle)}"`;
1850
- }
1851
- if (attrName === "class") {
1852
- const normalizedClassName = normalizeClassName(attrValue);
1853
- return normalizedClassName ? ` class="${normalizedClassName}"` : "";
1854
- }
1855
- if (attrName.startsWith("on")) {
1856
- return "";
1857
- }
1858
- if (attrValue === true) {
1859
- return ` ${attrName}`;
1860
- }
1861
- return ` ${attrName}="${attrValue}"`;
1862
- }
1863
- function getRenderedElement(temp) {
1864
- return () => {
1865
- const key = getHydrationKey();
1866
- const node = document.querySelector(`[data-hk="${key}"]`);
1867
- return node || template(temp)();
1868
- };
1869
- }
1870
- function mapSSRNodes(template2, idx) {
1871
- const hk = template2.dataset.hk;
1872
- if (!hk) {
1873
- return mapNodes(template2, idx);
1874
- }
1875
- const nodesList = [];
1876
- const elements = template2.querySelectorAll(`[data-idx^="${hk}"]`);
1877
- if (elements.length > 0) {
1878
- nodesList.push(
1879
- ...Array.from(elements).filter((item) => {
1880
- const idxAttr = item.dataset.idx;
1881
- return idxAttr !== null && DATA_IDX_REGEX.test(idxAttr);
1882
- }).map((item) => {
1883
- const idxAttr = item.dataset.idx || "";
1884
- const [hkPart, idxPart] = idxAttr.split("-");
1885
- return {
1886
- hk: hkPart,
1887
- idx: idxPart,
1888
- node: item
1889
- };
1890
- })
1891
- );
1948
+ for (let i = 0; i < newLen; i++) {
1949
+ const node = newEntries[i].node;
1950
+ parent.insertBefore(node, marker);
1951
+ }
1952
+ entries = newEntries;
1892
1953
  }
1893
- const commentNodes = [];
1894
- const walkNodes = (node) => {
1895
- if (node.nodeType === Node.COMMENT_NODE && node.textContent && DATA_IDX_REGEX.test(node.textContent)) {
1896
- const [hkPart, idxPart] = node.textContent.split("-");
1897
- commentNodes.push({
1898
- hk: hkPart,
1899
- idx: idxPart,
1900
- node
1901
- });
1954
+ onCleanup(() => {
1955
+ for (const entry of entries) {
1956
+ disposeItem(entry);
1902
1957
  }
1903
- let child = node.firstChild;
1904
- while (child) {
1905
- walkNodes(child);
1906
- child = child.nextSibling;
1958
+ if (fallbackNode && fallbackNode.parentNode) {
1959
+ fallbackNode.parentNode.removeChild(fallbackNode);
1907
1960
  }
1908
- };
1909
- walkNodes(template2);
1910
- nodesList.push(...commentNodes);
1911
- const nodes = [template2];
1912
- idx.forEach((indexValue) => {
1913
- const node = nodesList.find((item) => item.idx === String(indexValue));
1914
- if (node) {
1915
- nodes.push(node.node);
1961
+ if (marker.parentNode) {
1962
+ marker.parentNode.removeChild(marker);
1916
1963
  }
1917
1964
  });
1918
- return nodes;
1919
- }
1920
- function hydrate(component, container, props = {}) {
1921
- resetHydrationKey();
1922
- try {
1923
- const rootElement = isString(container) ? document.querySelector(container) : container;
1924
- if (!rootElement) {
1925
- error("Hydration error: Root element not found");
1926
- return void 0;
1927
- }
1928
- const rootComponent = createComponent(component, props);
1929
- rootComponent.mount(rootElement);
1930
- endHydration();
1931
- return rootComponent;
1932
- } catch (error_) {
1933
- error("Hydration error:", error_);
1934
- return void 0;
1935
- }
1965
+ return fragment;
1936
1966
  }
1967
+ For[FOR_COMPONENT] = true;
1937
1968
 
1938
- export { Component, Fragment, Portal, Suspense, SuspenseContext, addEvent, addEventListener, bindElement, createApp, createComponent, createResource, createSSGComponent, delegateEvents, getHydrationKey, getRenderedElement, hydrate, inject, insert, isComponent, isFragment, isPortal, isSuspense, mapNodes, mapSSRNodes, normalizeClass, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchClass, patchStyle, provide, render, renderToString, setSSGAttr, setStyle, template };
1969
+ export { Component, For, Fragment, Portal, Suspense, addEvent, addEventListener, bindElement, createApp, createComponent, createResource, createScope, delegateEvents, disposeScope, endHydration, getActiveScope, getFirstDOMNode, getHydrationKey, getRenderedElement, hydrate, inject, insert, insertNode, isComponent, isFragment, isHydrating, isPortal, isSameNode, isSuspense, mapNodes, mapSSRNodes, normalizeClass, normalizeNode, omitProps, onCleanup, onDestroy, onMount, onUpdate, patchAttr, patchClass, patchStyle, provide, removeNode, replaceNode, resetHydrationKey, runWithScope, setActiveScope, setStyle, shallowCompare, startHydration, template };
1970
+ //# sourceMappingURL=template.dev.esm.js.map
1971
+ //# sourceMappingURL=template.dev.esm.js.map