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