@estjs/template 0.0.16-beta.8 → 0.0.16

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.
@@ -38,9 +38,6 @@ var __async = (__this, __arguments, generator) => {
38
38
  step((generator = generator.apply(__this, __arguments)).next());
39
39
  });
40
40
  };
41
-
42
- // src/constants.ts
43
- var SPREAD_NAME = "_$spread$";
44
41
  var REF_KEY = "ref";
45
42
  var KEY_PROP = "key";
46
43
  var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
@@ -50,11 +47,17 @@ var FRAGMENT_COMPONENT = /* @__PURE__ */ Symbol("Fragment Component" );
50
47
  var PORTAL_COMPONENT = /* @__PURE__ */ Symbol("Portal Component" );
51
48
  var SUSPENSE_COMPONENT = /* @__PURE__ */ Symbol("Suspense Component" );
52
49
  var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
50
+ var TRANSITION_COMPONENT = /* @__PURE__ */ Symbol("Transition Component" );
51
+ var TRANSITION_GROUP_COMPONENT = /* @__PURE__ */ Symbol("TransitionGroup Component" );
53
52
  var activeScope = null;
54
53
  var scopeId = 0;
55
54
  function getActiveScope() {
56
55
  return activeScope;
57
56
  }
57
+ function setActiveScope(scope) {
58
+ activeScope = scope;
59
+ signals.setCurrentScope(scope == null ? void 0 : scope.effectScope);
60
+ }
58
61
  function createScope(parent = activeScope) {
59
62
  const reactiveScope = parent ? parent.effectScope.run(() => signals.effectScope()) : signals.effectScope(true);
60
63
  const scope = {
@@ -86,11 +89,11 @@ function createScope(parent = activeScope) {
86
89
  }
87
90
  function runWithScope(scope, fn) {
88
91
  const prevScope = activeScope;
89
- activeScope = scope;
92
+ setActiveScope(scope);
90
93
  try {
91
94
  return scope.effectScope.run(fn);
92
95
  } finally {
93
- activeScope = prevScope;
96
+ setActiveScope(prevScope);
94
97
  }
95
98
  }
96
99
  function disposeScope(scope) {
@@ -108,32 +111,29 @@ function disposeScope(scope) {
108
111
  }
109
112
  scope.children.clear();
110
113
  }
111
- runWithScope(scope, () => {
112
- if (scope.onDestroy) {
113
- for (let i = 0; i < scope.onDestroy.length; i++) {
114
- try {
115
- scope.onDestroy[i]();
116
- } catch (error_) {
117
- {
118
- shared.error(`Scope(${scope.id}): Error in destroy hook:`, error_);
119
- }
120
- }
114
+ const prevScope = activeScope;
115
+ setActiveScope(scope);
116
+ if (scope.onDestroy) {
117
+ for (let i = 0; i < scope.onDestroy.length; i++) {
118
+ try {
119
+ scope.onDestroy[i]();
120
+ } catch (error_) {
121
+ shared.error(`Scope(${scope.id}): Error in destroy hook:`, error_);
121
122
  }
122
- scope.onDestroy = null;
123
123
  }
124
- if (scope.cleanup) {
125
- for (let i = 0; i < scope.cleanup.length; i++) {
126
- try {
127
- scope.cleanup[i]();
128
- } catch (error_) {
129
- {
130
- shared.error(`Scope(${scope.id}): Error in cleanup:`, error_);
131
- }
132
- }
124
+ scope.onDestroy = null;
125
+ }
126
+ if (scope.cleanup) {
127
+ for (let i = 0; i < scope.cleanup.length; i++) {
128
+ try {
129
+ scope.cleanup[i]();
130
+ } catch (error_) {
131
+ shared.error(`Scope(${scope.id}): Error in cleanup:`, error_);
133
132
  }
134
- scope.cleanup = null;
135
133
  }
136
- });
134
+ scope.cleanup = null;
135
+ }
136
+ setActiveScope(prevScope);
137
137
  scope.effectScope.stop();
138
138
  if ((_a2 = scope.parent) == null ? void 0 : _a2.children) {
139
139
  scope.parent.children.delete(scope);
@@ -169,7 +169,7 @@ function patchAttr(el, key, prev, next2) {
169
169
  }
170
170
  return;
171
171
  }
172
- if (key === SPREAD_NAME) {
172
+ if (key === shared.SPREAD_NAME) {
173
173
  const prevObj = shared.isObject(prev) ? prev : null;
174
174
  const nextObj = shared.isObject(next2) ? next2 : null;
175
175
  {
@@ -179,7 +179,7 @@ function patchAttr(el, key, prev, next2) {
179
179
  }
180
180
  if (prevObj) {
181
181
  for (const attrKey in prevObj) {
182
- if (attrKey === SPREAD_NAME) {
182
+ if (attrKey === shared.SPREAD_NAME) {
183
183
  {
184
184
  shared.warn("nested spread attributes are ignored");
185
185
  }
@@ -192,7 +192,7 @@ function patchAttr(el, key, prev, next2) {
192
192
  }
193
193
  if (nextObj) {
194
194
  for (const attrKey in nextObj) {
195
- if (attrKey === SPREAD_NAME) {
195
+ if (attrKey === shared.SPREAD_NAME) {
196
196
  {
197
197
  shared.warn("nested spread attributes are ignored");
198
198
  }
@@ -204,8 +204,8 @@ function patchAttr(el, key, prev, next2) {
204
204
  return;
205
205
  }
206
206
  const elementIsSVG = (el == null ? void 0 : el.namespaceURI) === SVG_NAMESPACE;
207
- const isXlink = elementIsSVG && key.startsWith("xlink:");
208
- const isXmlns = elementIsSVG && key.startsWith("xmlns:");
207
+ const isXlink = elementIsSVG && shared.startsWith(key, "xlink:");
208
+ const isXmlns = elementIsSVG && shared.startsWith(key, "xmlns:");
209
209
  const isBoolean = shared.isSpecialBooleanAttr(key) || shared.isBooleanAttr(key);
210
210
  if (prev === next2) {
211
211
  return;
@@ -243,7 +243,7 @@ function patchAttr(el, key, prev, next2) {
243
243
  const isUrlAttr = lowerKey === "href" || lowerKey === "src" || lowerKey === "xlink:href" || lowerKey === "action" || lowerKey === "formaction" || lowerKey === "poster";
244
244
  if (isUrlAttr && shared.isString(attrValue)) {
245
245
  const v = attrValue.trim().toLowerCase();
246
- if (v.startsWith("javascript:") || v.startsWith("data:")) {
246
+ if (shared.startsWith(v, "javascript:") || shared.startsWith(v, "data:")) {
247
247
  return;
248
248
  }
249
249
  }
@@ -347,7 +347,7 @@ function setStyle(style, name, val) {
347
347
  if (priority) {
348
348
  val = val.replace(importantRE, "");
349
349
  }
350
- if (name.startsWith("--")) {
350
+ if (shared.startsWith(name, "--")) {
351
351
  if (priority) {
352
352
  style.setProperty(name, val, priority);
353
353
  } else {
@@ -364,7 +364,7 @@ function setStyle(style, name, val) {
364
364
  }
365
365
  function toCssPropertyName(name) {
366
366
  const hyphenated = shared.kebabCase(name);
367
- return name.startsWith("Webkit") || name.startsWith("Moz") || name.startsWith("ms") ? `-${hyphenated}` : hyphenated;
367
+ return shared.startsWith(name, "Webkit") || shared.startsWith(name, "Moz") || shared.startsWith(name, "ms") ? `-${hyphenated}` : hyphenated;
368
368
  }
369
369
  function autoPrefix(style, rawName) {
370
370
  const cached = prefixCache[rawName];
@@ -466,6 +466,77 @@ function endHydration() {
466
466
  _teleportCallsiteAnchors.length = 0;
467
467
  _teleportTargetStarts.clear();
468
468
  }
469
+ function claimHydratedNodes(parent, expected, before) {
470
+ var _a2, _b;
471
+ if (!_isHydrating || before && before.parentNode !== parent) return null;
472
+ if (expected.length === 0) return [];
473
+ const claimed = new Array(expected.length);
474
+ let cursor = before ? before.previousSibling : parent.lastChild;
475
+ for (let i = expected.length - 1; i >= 0; i--) {
476
+ if (!cursor) return null;
477
+ const expectedNode = expected[i];
478
+ const expectedType = expectedNode.nodeType;
479
+ if (expectedType === Node.TEXT_NODE) {
480
+ const expectedText = (_a2 = expectedNode.textContent) != null ? _a2 : "";
481
+ if (!expectedText || cursor.nodeType !== Node.TEXT_NODE) return null;
482
+ const existingText = (_b = cursor.textContent) != null ? _b : "";
483
+ if (existingText === expectedText) {
484
+ claimed[i] = cursor;
485
+ cursor = cursor.previousSibling;
486
+ continue;
487
+ }
488
+ if (!existingText.endsWith(expectedText)) return null;
489
+ const prefix = existingText.slice(0, existingText.length - expectedText.length);
490
+ if (!prefix) return null;
491
+ const prefixNode = document.createTextNode(prefix);
492
+ parent.insertBefore(prefixNode, cursor);
493
+ cursor.textContent = expectedText;
494
+ claimed[i] = cursor;
495
+ cursor = prefixNode;
496
+ continue;
497
+ }
498
+ if (cursor.nodeType !== expectedType) return null;
499
+ if (expectedType === Node.ELEMENT_NODE) {
500
+ if (cursor.tagName !== expectedNode.tagName) return null;
501
+ } else if (expectedType === Node.COMMENT_NODE && cursor.data !== expectedNode.data) {
502
+ return null;
503
+ }
504
+ claimed[i] = cursor;
505
+ cursor = cursor.previousSibling;
506
+ }
507
+ return claimed;
508
+ }
509
+ function resolveHydrationKey(parent) {
510
+ var _a2, _b, _c;
511
+ const el = parent;
512
+ return (_c = (_b = el.dataset.hk) != null ? _b : (_a2 = parent.closest("[data-hk]")) == null ? void 0 : _a2.dataset.hk) != null ? _c : null;
513
+ }
514
+ function hydrationMarker(parent, index) {
515
+ if (!_isHydrating || !parent || index < 0) return null;
516
+ const key = parent instanceof Element ? resolveHydrationKey(parent) : null;
517
+ const expected = key ? `${key}-${index}` : String(index);
518
+ let cursor = parent.firstChild;
519
+ while (cursor) {
520
+ if (cursor.nodeType === Node.COMMENT_NODE && cursor.data === expected) {
521
+ return cursor;
522
+ }
523
+ cursor = cursor.nextSibling;
524
+ }
525
+ return null;
526
+ }
527
+ function hydrationAnchor(parent, index) {
528
+ if (!_isHydrating || !(parent instanceof Element) || index < 0) return null;
529
+ const key = resolveHydrationKey(parent);
530
+ const expected = key ? `${key}-${index}` : String(index);
531
+ let cursor = parent.firstChild;
532
+ while (cursor) {
533
+ if (cursor instanceof Element && cursor.getAttribute(shared.HYDRATION_ANCHOR_ATTR) === expected) {
534
+ return cursor;
535
+ }
536
+ cursor = cursor.nextSibling;
537
+ }
538
+ return null;
539
+ }
469
540
  function getRenderedElement(html) {
470
541
  if (!shared.isBrowser()) {
471
542
  return () => {
@@ -563,12 +634,17 @@ function reconcileArrays(parent, oldNodes, newNodes, anchor) {
563
634
  }
564
635
  function reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, newEnd, anchor) {
565
636
  const newLength = newEnd - start + 1;
566
- const newIndexMap = /* @__PURE__ */ new Map();
567
- for (let i = start; i <= newEnd; i++) {
568
- newIndexMap.set(newNodes[i], i);
569
- }
637
+ const findNewIndex = newLength <= 4 ? (node) => {
638
+ for (let i = start; i <= newEnd; i++) {
639
+ if (newNodes[i] === node) return i;
640
+ }
641
+ return void 0;
642
+ } : (() => {
643
+ const map = /* @__PURE__ */ new Map();
644
+ for (let i = start; i <= newEnd; i++) map.set(newNodes[i], i);
645
+ return (node) => map.get(node);
646
+ })();
570
647
  const newIndexToOldIndexMap = new Int32Array(newLength);
571
- newIndexToOldIndexMap.fill(0);
572
648
  let patched = 0;
573
649
  let moved = false;
574
650
  let maxNewIndexSoFar = 0;
@@ -578,7 +654,7 @@ function reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, new
578
654
  removeNode(oldNode);
579
655
  continue;
580
656
  }
581
- const newIndex = newIndexMap.get(oldNode);
657
+ const newIndex = findNewIndex(oldNode);
582
658
  if (newIndex === void 0) {
583
659
  removeNode(oldNode);
584
660
  } else {
@@ -724,6 +800,14 @@ function insert(parent, nodeFactory, before) {
724
800
  isFirstRun = false;
725
801
  return;
726
802
  }
803
+ if (isFirstRun && isHydrating()) {
804
+ const hydratedNodes = claimHydratedNodes(parent, nodes, before);
805
+ if (hydratedNodes) {
806
+ renderedNodes = hydratedNodes;
807
+ isFirstRun = false;
808
+ return;
809
+ }
810
+ }
727
811
  renderedNodes = reconcileArrays(parent, renderedNodes, nodes, before);
728
812
  isFirstRun = false;
729
813
  };
@@ -870,14 +954,13 @@ function triggerUpdateHooks(scope) {
870
954
 
871
955
  // src/component.ts
872
956
  function syncDescriptors(target, source, pruneMissing = false) {
873
- const seen = pruneMissing ? /* @__PURE__ */ new Set() : null;
874
957
  for (const key of Object.getOwnPropertyNames(source)) {
875
- seen == null ? void 0 : seen.add(key);
876
958
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
877
959
  }
878
- if (seen) {
960
+ if (pruneMissing) {
961
+ const sourceKeys = Object.getOwnPropertyNames(source);
879
962
  for (const key of Object.getOwnPropertyNames(target)) {
880
- if (!seen.has(key)) delete target[key];
963
+ if (!sourceKeys.includes(key)) delete target[key];
881
964
  }
882
965
  }
883
966
  }
@@ -986,6 +1069,9 @@ var Component = class {
986
1069
  this.renderedNodes = [];
987
1070
  this.firstChild = void 0;
988
1071
  this.parentNode = void 0;
1072
+ for (const key of Object.getOwnPropertyNames(this.reactiveProps)) {
1073
+ delete this.reactiveProps[key];
1074
+ }
989
1075
  }
990
1076
  /**
991
1077
  * Apply props that bind to the root DOM element rather than flowing into
@@ -996,7 +1082,7 @@ var Component = class {
996
1082
  syncSpecialProps(props) {
997
1083
  if (!props) return;
998
1084
  const root = this.firstChild;
999
- if (!root) return;
1085
+ if (!root || !(root instanceof Element)) return;
1000
1086
  this.releaseSpecialProps();
1001
1087
  for (const key of Object.getOwnPropertyNames(props)) {
1002
1088
  if (key === REF_KEY) {
@@ -1008,7 +1094,22 @@ var Component = class {
1008
1094
  const value = readProp(props, key);
1009
1095
  if (!shared.isFunction(value)) continue;
1010
1096
  const eventName = key.slice(2).toLowerCase();
1011
- this.rootEventCleanups.push(addEvent(root, eventName, value));
1097
+ const target = root;
1098
+ const slot = `_$${eventName}`;
1099
+ const prev = target[slot];
1100
+ if (shared.isFunction(prev)) {
1101
+ target[slot] = value;
1102
+ this.rootEventCleanups.push(() => {
1103
+ if (target[slot] === value) target[slot] = prev;
1104
+ });
1105
+ continue;
1106
+ }
1107
+ const fn = value;
1108
+ const handler = (event) => {
1109
+ if (target.disabled) return;
1110
+ fn.call(target, event);
1111
+ };
1112
+ this.rootEventCleanups.push(addEvent(target, eventName, handler));
1012
1113
  }
1013
1114
  }
1014
1115
  }
@@ -1226,7 +1327,7 @@ function eventHandler(e) {
1226
1327
  reTargetEvent(e, oriTarget);
1227
1328
  }
1228
1329
  var $EVENTS = /* @__PURE__ */ Symbol("_$EVENTS");
1229
- function delegateEvents(eventNames, document2 = window.document) {
1330
+ function delegateEvents(eventNames, document2 = globalThis.document) {
1230
1331
  const docWithEvents = document2;
1231
1332
  const eventSet = docWithEvents[$EVENTS] || (docWithEvents[$EVENTS] = /* @__PURE__ */ new Set());
1232
1333
  for (const name of eventNames) {
@@ -1236,7 +1337,7 @@ function delegateEvents(eventNames, document2 = window.document) {
1236
1337
  }
1237
1338
  }
1238
1339
  }
1239
- function clearDelegatedEvents(document2 = window.document) {
1340
+ function clearDelegatedEvents(document2 = globalThis.document) {
1240
1341
  const docWithEvents = document2;
1241
1342
  const eventSet = docWithEvents[$EVENTS];
1242
1343
  if (eventSet) {
@@ -1254,6 +1355,11 @@ function addEventListener(element, event, handler, options) {
1254
1355
  }
1255
1356
 
1256
1357
  // src/binding.ts
1358
+ var IDENTITY = (v) => v;
1359
+ var EMPTY_FILES = (() => {
1360
+ if (typeof DataTransfer !== "undefined") return new DataTransfer().files;
1361
+ return [];
1362
+ })();
1257
1363
  function writeValue(el, v) {
1258
1364
  const target = el;
1259
1365
  const next2 = v == null ? "" : String(v);
@@ -1262,10 +1368,11 @@ function writeValue(el, v) {
1262
1368
  var CHECKBOX = {
1263
1369
  event: "change",
1264
1370
  forceChange: true,
1371
+ checkboxArray: true,
1265
1372
  read: (el) => el.checked,
1266
1373
  write(el, v) {
1267
1374
  const e = el;
1268
- const next2 = Boolean(v);
1375
+ const next2 = shared.isArray(v) ? v.map(String).includes(e.value) : Boolean(v);
1269
1376
  if (e.checked !== next2) e.checked = next2;
1270
1377
  }
1271
1378
  };
@@ -1286,17 +1393,15 @@ var FILE = {
1286
1393
  event: "change",
1287
1394
  forceChange: true,
1288
1395
  read: (el) => el.files,
1289
- write() {
1396
+ write(el, v) {
1397
+ if (v != null) return;
1398
+ try {
1399
+ el.files = EMPTY_FILES;
1400
+ } catch (e) {
1401
+ }
1290
1402
  }
1291
- // browsers forbid programmatic writes to file inputs
1292
- };
1293
- var TEXT = {
1294
- event: "input",
1295
- ime: true,
1296
- read: (el) => el.value,
1297
- write: writeValue
1298
1403
  };
1299
- var TEXTAREA = {
1404
+ var TEXT_LIKE = {
1300
1405
  event: "input",
1301
1406
  ime: true,
1302
1407
  read: (el) => el.value,
@@ -1311,41 +1416,44 @@ var SELECT = {
1311
1416
  },
1312
1417
  write(el, v) {
1313
1418
  const s = el;
1314
- if (s.multiple) {
1315
- const selected = new Set((Array.isArray(v) ? v : []).map(String));
1316
- for (const opt of Array.from(s.options)) opt.selected = selected.has(opt.value);
1317
- } else {
1318
- writeValue(el, v);
1319
- }
1419
+ if (!s.multiple) return writeValue(el, v);
1420
+ const selected = new Set((shared.isArray(v) ? v : []).map(String));
1421
+ for (const opt of Array.from(s.options)) opt.selected = selected.has(opt.value);
1320
1422
  }
1321
1423
  };
1424
+ function customStrategy(prop) {
1425
+ return {
1426
+ event: "input",
1427
+ read: (el) => el[prop],
1428
+ write(el, v) {
1429
+ el[prop] = v;
1430
+ }
1431
+ };
1432
+ }
1322
1433
  function resolve(node, prop) {
1323
1434
  switch (node.nodeName) {
1324
1435
  case "INPUT":
1325
1436
  if (prop === "checked") return node.type === "radio" ? RADIO : CHECKBOX;
1326
1437
  if (prop === "files") return FILE;
1327
- return TEXT;
1438
+ if (prop === "value") return TEXT_LIKE;
1439
+ return customStrategy(prop);
1328
1440
  case "SELECT":
1329
1441
  return SELECT;
1330
1442
  case "TEXTAREA":
1331
- return TEXTAREA;
1443
+ return TEXT_LIKE;
1332
1444
  default:
1333
- return {
1334
- event: "input",
1335
- read: (el) => el[prop],
1336
- write(el, v) {
1337
- el[prop] = v;
1338
- }
1339
- };
1445
+ return customStrategy(prop);
1340
1446
  }
1341
1447
  }
1342
1448
  function applyModifiers(v, trim, toNum) {
1343
1449
  if (!shared.isString(v)) return v;
1344
- let s = v;
1345
- if (trim) s = s.trim();
1346
- if (toNum && s !== "") {
1347
- const n = Number(s);
1348
- if (!Number.isNaN(n)) return n;
1450
+ const s = trim ? v.trim() : v;
1451
+ if (toNum) {
1452
+ const probe = trim ? s : s.trim();
1453
+ if (probe !== "") {
1454
+ const n = Number(probe);
1455
+ if (!Number.isNaN(n)) return n;
1456
+ }
1349
1457
  }
1350
1458
  return s;
1351
1459
  }
@@ -1353,44 +1461,54 @@ function isFocused(el) {
1353
1461
  const root = el.getRootNode();
1354
1462
  return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === el;
1355
1463
  }
1464
+ function shouldAutoCoerceNumber(node, prop) {
1465
+ if (prop !== "value" || node.nodeName !== "INPUT") return false;
1466
+ const t = node.type;
1467
+ return t === "number" || t === "range";
1468
+ }
1356
1469
  function bindElement(node, prop, getter, setter, modifiers = {}) {
1357
1470
  if (!node) return;
1358
- const { event, read, write, forceChange, ime } = resolve(node, prop);
1471
+ const { event, read, write, forceChange, ime, checkboxArray } = resolve(node, prop);
1359
1472
  const trim = modifiers.trim === true;
1360
- const toNum = modifiers.number === true;
1473
+ const toNum = modifiers.number === true || shouldAutoCoerceNumber(node, prop);
1361
1474
  const lazy = modifiers.lazy === true;
1362
1475
  const shouldCast = (trim || toNum) && prop !== "files";
1363
1476
  const getModel = shared.isFunction(getter) ? getter : () => getter;
1364
- const cast = shouldCast ? (v) => applyModifiers(v, trim, toNum) : (v) => v;
1477
+ const cast = shouldCast ? (v) => applyModifiers(v, trim, toNum) : IDENTITY;
1478
+ const computeNext = checkboxArray ? (raw) => {
1479
+ const current = getModel();
1480
+ if (!shared.isArray(current)) return cast(raw);
1481
+ const own = node.value;
1482
+ const next2 = current.filter((item) => String(item) !== own);
1483
+ if (raw) next2.push(own);
1484
+ return next2;
1485
+ } : cast;
1365
1486
  let composing = false;
1366
1487
  const eventName = lazy || forceChange ? "change" : event;
1367
1488
  const syncToModel = () => {
1368
1489
  if (composing) return;
1369
1490
  const raw = read(node);
1370
1491
  if (raw === void 0) return;
1371
- const next2 = cast(raw);
1492
+ const next2 = computeNext(raw);
1372
1493
  if (!Object.is(getModel(), next2)) setter(next2);
1373
1494
  };
1374
1495
  addEventListener(node, eventName, syncToModel);
1375
1496
  if (!lazy && shouldCast && eventName !== "change") {
1376
1497
  addEventListener(node, "change", () => write(node, cast(read(node))));
1377
1498
  }
1378
- if (ime && !lazy) {
1499
+ if (ime) {
1379
1500
  addEventListener(node, "compositionstart", () => {
1380
1501
  composing = true;
1381
1502
  });
1382
1503
  addEventListener(node, "compositionend", () => {
1383
- if (!composing) return;
1384
1504
  composing = false;
1385
- syncToModel();
1505
+ if (!lazy) syncToModel();
1386
1506
  });
1387
1507
  }
1388
1508
  const runner = signals.effect(() => {
1389
1509
  const value = getModel();
1390
- if (ime && !lazy && isFocused(node)) {
1391
- if (composing) return;
1392
- if (Object.is(cast(read(node)), value)) return;
1393
- }
1510
+ if (ime && composing) return;
1511
+ if (ime && !lazy && isFocused(node) && Object.is(cast(read(node)), value)) return;
1394
1512
  write(node, value);
1395
1513
  });
1396
1514
  if (getActiveScope()) {
@@ -1399,6 +1517,18 @@ function bindElement(node, prop, getter, setter, modifiers = {}) {
1399
1517
  }
1400
1518
 
1401
1519
  // src/utils.ts
1520
+ function unwrapSlotValue(raw) {
1521
+ let v = raw;
1522
+ if (Array.isArray(v) && v.length === 1) v = v[0];
1523
+ return typeof v === "function" ? v() : v;
1524
+ }
1525
+ function useChildren(props) {
1526
+ const desc = Object.getOwnPropertyDescriptor(props, "children");
1527
+ if (desc == null ? void 0 : desc.get) {
1528
+ return () => unwrapSlotValue(desc.get.call(props));
1529
+ }
1530
+ return () => unwrapSlotValue(props.children);
1531
+ }
1402
1532
  function omitProps(target, keys) {
1403
1533
  const excludeSet = new Set(keys);
1404
1534
  return new Proxy(target, {
@@ -1437,9 +1567,11 @@ function omitProps(target, keys) {
1437
1567
  }
1438
1568
  });
1439
1569
  }
1440
-
1441
- // src/components/Fragment.ts
1442
1570
  function Fragment(props) {
1571
+ var _a2;
1572
+ if (props && (((_a2 = Object.getOwnPropertyDescriptor(props, "children")) == null ? void 0 : _a2.get) || signals.isReactive(props))) {
1573
+ return [() => props.children];
1574
+ }
1443
1575
  const children = props == null ? void 0 : props.children;
1444
1576
  if (children == null) return null;
1445
1577
  return children;
@@ -1958,7 +2090,11 @@ function For(props) {
1958
2090
  let entries = [];
1959
2091
  let fallbackNodes = [];
1960
2092
  const keyFn = props.key;
1961
- const renderFn = props.children;
2093
+ const raw = props.children;
2094
+ const renderFn = Array.isArray(raw) && raw.length === 1 && shared.isFunction(raw[0]) ? raw[0] : props.children;
2095
+ if (!shared.isFunction(renderFn)) {
2096
+ throw new TypeError("<For> requires `children` to be a function (item, index) => Node");
2097
+ }
1962
2098
  const getList = () => {
1963
2099
  var _a2, _b;
1964
2100
  const input = props.each;
@@ -1967,26 +2103,20 @@ function For(props) {
1967
2103
  return input != null ? input : [];
1968
2104
  };
1969
2105
  const getKey = (item, index) => keyFn ? keyFn(item, index) : item;
1970
- const normalizeNodes = (value) => {
2106
+ const mountValue = (value, parent, before) => {
2107
+ if (value == null || value === false) return [];
1971
2108
  if (Array.isArray(value)) {
1972
2109
  const nodes = [];
1973
- for (const item of value) {
1974
- nodes.push(...normalizeNodes(item));
1975
- }
2110
+ for (const child2 of value) nodes.push(...mountValue(child2, parent, before));
1976
2111
  return nodes;
1977
2112
  }
1978
- return [normalizeNode(value)];
1979
- };
1980
- const mountValue = (value, parent, before) => {
1981
- const nodes = normalizeNodes(value);
1982
- for (const node of nodes) {
1983
- if (before) {
1984
- parent.insertBefore(node, before);
1985
- } else {
1986
- parent.appendChild(node);
1987
- }
2113
+ if (isComponent(value)) {
2114
+ insertNode(parent, value, before != null ? before : void 0);
2115
+ return value.renderedNodes;
1988
2116
  }
1989
- return nodes;
2117
+ const node = normalizeNode(value);
2118
+ insertNode(parent, node, before != null ? before : void 0);
2119
+ return [node];
1990
2120
  };
1991
2121
  const mountFallback = (parent, before) => {
1992
2122
  if (!props.fallback) return;
@@ -2142,12 +2272,662 @@ function For(props) {
2142
2272
  return fragment;
2143
2273
  }
2144
2274
  For[FOR_COMPONENT] = true;
2275
+ function resolveTransitionClasses(props) {
2276
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2277
+ const n = (_a2 = props.name) != null ? _a2 : "v";
2278
+ const enterFrom = (_b = props.enterFromClass) != null ? _b : `${n}-enter-from`;
2279
+ const enterActive = (_c = props.enterActiveClass) != null ? _c : `${n}-enter-active`;
2280
+ const enterTo = (_d = props.enterToClass) != null ? _d : `${n}-enter-to`;
2281
+ return {
2282
+ enterFrom,
2283
+ enterActive,
2284
+ enterTo,
2285
+ leaveFrom: (_e = props.leaveFromClass) != null ? _e : `${n}-leave-from`,
2286
+ leaveActive: (_f = props.leaveActiveClass) != null ? _f : `${n}-leave-active`,
2287
+ leaveTo: (_g = props.leaveToClass) != null ? _g : `${n}-leave-to`,
2288
+ appearFrom: (_h = props.appearFromClass) != null ? _h : enterFrom,
2289
+ appearActive: (_i = props.appearActiveClass) != null ? _i : enterActive,
2290
+ appearTo: (_j = props.appearToClass) != null ? _j : enterTo
2291
+ };
2292
+ }
2293
+ var toMs = (s) => {
2294
+ if (!s) return 0;
2295
+ if (s.endsWith("ms")) return Number(s.slice(0, -2).replace(",", "."));
2296
+ return Number(s.slice(0, -1).replace(",", ".")) * 1e3;
2297
+ };
2298
+ function sumMs(delays, durations) {
2299
+ const d = delays.split(", ");
2300
+ const u = durations.split(", ");
2301
+ let max = 0;
2302
+ for (const [i, dur] of u.entries()) {
2303
+ const total = toMs(dur) + toMs(d[i % d.length] || "0s");
2304
+ if (total > max) max = total;
2305
+ }
2306
+ return max;
2307
+ }
2308
+ function getTransitionInfo(el, type) {
2309
+ const s = getComputedStyle(el);
2310
+ const tt = type !== "animation" ? sumMs(s.transitionDelay, s.transitionDuration) : 0;
2311
+ const at = type !== "transition" ? sumMs(s.animationDelay, s.animationDuration) : 0;
2312
+ if (tt === 0 && at === 0) return null;
2313
+ return tt >= at ? { event: "transitionend", timeout: tt } : { event: "animationend", timeout: at };
2314
+ }
2315
+ function addClass(el, cls) {
2316
+ for (const c of cls.split(/\s+/)) if (c) el.classList.add(c);
2317
+ }
2318
+ function removeClass(el, cls) {
2319
+ for (const c of cls.split(/\s+/)) if (c) el.classList.remove(c);
2320
+ }
2321
+ function nextFrame(cb) {
2322
+ requestAnimationFrame(() => requestAnimationFrame(cb));
2323
+ }
2324
+ function forceReflow(el) {
2325
+ void el.offsetHeight;
2326
+ }
2327
+ function whenTransitionEnds(el, type, explicit, resolve2) {
2328
+ if (explicit != null) {
2329
+ setTimeout(resolve2, explicit);
2330
+ return;
2331
+ }
2332
+ const info = getTransitionInfo(el, type);
2333
+ if (!info) {
2334
+ resolve2();
2335
+ return;
2336
+ }
2337
+ let done = false;
2338
+ const finish = () => {
2339
+ if (done) return;
2340
+ done = true;
2341
+ el.removeEventListener(info.event, onEnd);
2342
+ resolve2();
2343
+ };
2344
+ const onEnd = () => finish();
2345
+ el.addEventListener(info.event, onEnd);
2346
+ setTimeout(finish, info.timeout + 1);
2347
+ }
2348
+ function resolveDuration(d, dir) {
2349
+ if (d == null) return null;
2350
+ if (typeof d === "number") return d;
2351
+ return d[dir];
2352
+ }
2353
+ function validateSlot(value) {
2354
+ if (value == null || value === false) return null;
2355
+ if (Array.isArray(value)) {
2356
+ {
2357
+ throw new Error(
2358
+ "[essor] <Transition> expects a single root child. Use <TransitionGroup> for multiple children."
2359
+ );
2360
+ }
2361
+ }
2362
+ if (value instanceof Element) return value;
2363
+ if (isComponent(value)) {
2364
+ const comp = value;
2365
+ if (comp.scope == null) {
2366
+ const fragment = document.createDocumentFragment();
2367
+ comp.mount(fragment);
2368
+ }
2369
+ if (comp.renderedNodes.length > 1) {
2370
+ shared.warn(
2371
+ "[Transition] child component rendered multiple root nodes; only the first is animated. Wrap the children in a single element or use <TransitionGroup>."
2372
+ );
2373
+ }
2374
+ const first = comp.firstChild;
2375
+ if (first instanceof Element) return first;
2376
+ {
2377
+ shared.warn("[Transition] child component did not render an Element root.");
2378
+ }
2379
+ return null;
2380
+ }
2381
+ {
2382
+ shared.warn("[Transition] received a non-element child; animation will be skipped.");
2383
+ }
2384
+ return null;
2385
+ }
2386
+ var ENTER_CB = /* @__PURE__ */ Symbol("enter_cb");
2387
+ var LEAVE_CB = /* @__PURE__ */ Symbol("leave_cb");
2388
+ function Transition(props) {
2389
+ const anchor = document.createComment("");
2390
+ const classes = resolveTransitionClasses(props);
2391
+ const useCss = props.css !== false;
2392
+ const readSlot = useChildren(props);
2393
+ let state = "idle";
2394
+ let currentEl = null;
2395
+ let leavingEl = null;
2396
+ let mounted = false;
2397
+ let pendingRaw = void 0;
2398
+ let hasPending = false;
2399
+ let scheduled = false;
2400
+ let disposed = false;
2401
+ const enter = (el, phase) => {
2402
+ var _a2;
2403
+ const prevLeave = el[LEAVE_CB];
2404
+ if (prevLeave) prevLeave(true);
2405
+ state = "entering";
2406
+ const fromCls = phase === "appear" ? classes.appearFrom : classes.enterFrom;
2407
+ const activeCls = phase === "appear" ? classes.appearActive : classes.enterActive;
2408
+ const toCls = phase === "appear" ? classes.appearTo : classes.enterTo;
2409
+ (_a2 = props.onBeforeEnter) == null ? void 0 : _a2.call(props, el);
2410
+ if (useCss) {
2411
+ addClass(el, fromCls);
2412
+ addClass(el, activeCls);
2413
+ }
2414
+ let called = false;
2415
+ const done = (cancelled) => {
2416
+ var _a3, _b;
2417
+ if (called) return;
2418
+ called = true;
2419
+ el[ENTER_CB] = void 0;
2420
+ if (useCss) {
2421
+ removeClass(el, fromCls);
2422
+ removeClass(el, activeCls);
2423
+ removeClass(el, toCls);
2424
+ }
2425
+ if (cancelled) {
2426
+ (_a3 = props.onEnterCancelled) == null ? void 0 : _a3.call(props, el);
2427
+ } else {
2428
+ state = "entered";
2429
+ (_b = props.onAfterEnter) == null ? void 0 : _b.call(props, el);
2430
+ }
2431
+ };
2432
+ el[ENTER_CB] = done;
2433
+ nextFrame(() => {
2434
+ if (called) return;
2435
+ if (useCss) {
2436
+ removeClass(el, fromCls);
2437
+ addClass(el, toCls);
2438
+ }
2439
+ if (props.onEnter) {
2440
+ props.onEnter(el, () => done(false));
2441
+ } else if (useCss) {
2442
+ const explicit = resolveDuration(props.duration, "enter");
2443
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2444
+ } else {
2445
+ done(false);
2446
+ }
2447
+ });
2448
+ };
2449
+ const leave = (el, after) => {
2450
+ var _a2;
2451
+ const prevEnter = el[ENTER_CB];
2452
+ if (prevEnter) {
2453
+ prevEnter(true);
2454
+ forceReflow(el);
2455
+ }
2456
+ state = "leaving";
2457
+ (_a2 = props.onBeforeLeave) == null ? void 0 : _a2.call(props, el);
2458
+ if (useCss) {
2459
+ addClass(el, classes.leaveFrom);
2460
+ addClass(el, classes.leaveActive);
2461
+ }
2462
+ let called = false;
2463
+ const done = (cancelled) => {
2464
+ var _a3, _b;
2465
+ if (called) return;
2466
+ called = true;
2467
+ el[LEAVE_CB] = void 0;
2468
+ if (useCss) {
2469
+ removeClass(el, classes.leaveFrom);
2470
+ removeClass(el, classes.leaveActive);
2471
+ removeClass(el, classes.leaveTo);
2472
+ }
2473
+ if (cancelled) {
2474
+ (_a3 = props.onLeaveCancelled) == null ? void 0 : _a3.call(props, el);
2475
+ } else {
2476
+ state = "idle";
2477
+ after();
2478
+ (_b = props.onAfterLeave) == null ? void 0 : _b.call(props, el);
2479
+ }
2480
+ };
2481
+ el[LEAVE_CB] = done;
2482
+ const explicit = resolveDuration(props.duration, "leave");
2483
+ const hasCssInfo = useCss && !props.onLeave && explicit == null ? !!getTransitionInfo(el, props.type) : false;
2484
+ if (!props.onLeave && explicit == null && !hasCssInfo) {
2485
+ done(false);
2486
+ return;
2487
+ }
2488
+ nextFrame(() => {
2489
+ if (called) return;
2490
+ if (useCss) {
2491
+ removeClass(el, classes.leaveFrom);
2492
+ addClass(el, classes.leaveTo);
2493
+ }
2494
+ if (props.onLeave) {
2495
+ props.onLeave(el, () => done(false));
2496
+ } else if (useCss) {
2497
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2498
+ } else {
2499
+ done(false);
2500
+ }
2501
+ });
2502
+ };
2503
+ const commit = (next2, isFirst) => {
2504
+ if (next2 && state === "leaving" && leavingEl) {
2505
+ const reviving = leavingEl;
2506
+ const leaveCb = reviving[LEAVE_CB];
2507
+ if (leaveCb) leaveCb(true);
2508
+ leavingEl = null;
2509
+ currentEl = reviving;
2510
+ enter(reviving, "enter");
2511
+ return;
2512
+ }
2513
+ if (next2 === currentEl) return;
2514
+ const outgoing = currentEl;
2515
+ currentEl = next2;
2516
+ if (outgoing) {
2517
+ leavingEl = outgoing;
2518
+ const captured = outgoing;
2519
+ leave(captured, () => {
2520
+ if (captured.parentNode) captured.parentNode.removeChild(captured);
2521
+ if (leavingEl === captured) leavingEl = null;
2522
+ });
2523
+ }
2524
+ if (next2 && anchor.parentNode) {
2525
+ anchor.parentNode.insertBefore(next2, anchor);
2526
+ if (isFirst && !props.appear) {
2527
+ state = "entered";
2528
+ } else {
2529
+ enter(next2, isFirst && props.appear ? "appear" : "enter");
2530
+ }
2531
+ } else if (!outgoing && !next2) {
2532
+ state = "idle";
2533
+ }
2534
+ };
2535
+ const flush = () => {
2536
+ scheduled = false;
2537
+ if (disposed || !hasPending) return;
2538
+ const raw = pendingRaw;
2539
+ hasPending = false;
2540
+ pendingRaw = void 0;
2541
+ try {
2542
+ commit(validateSlot(raw), false);
2543
+ } catch (error5) {
2544
+ console.error("[essor] <Transition>", error5);
2545
+ }
2546
+ };
2547
+ const scheduleCommit = (raw) => {
2548
+ pendingRaw = raw;
2549
+ hasPending = true;
2550
+ if (scheduled) return;
2551
+ scheduled = true;
2552
+ queueMicrotask(flush);
2553
+ };
2554
+ const effectRunner = signals.effect(() => {
2555
+ const raw = readSlot();
2556
+ if (mounted) {
2557
+ scheduleCommit(raw);
2558
+ } else {
2559
+ pendingRaw = raw;
2560
+ hasPending = true;
2561
+ }
2562
+ });
2563
+ onMount(() => {
2564
+ mounted = true;
2565
+ const initial = hasPending ? validateSlot(pendingRaw) : null;
2566
+ hasPending = false;
2567
+ pendingRaw = void 0;
2568
+ commit(initial, true);
2569
+ });
2570
+ onCleanup(() => {
2571
+ disposed = true;
2572
+ effectRunner.stop();
2573
+ for (const el of [currentEl, leavingEl]) {
2574
+ if (!el) continue;
2575
+ const ec = el[ENTER_CB];
2576
+ const lc = el[LEAVE_CB];
2577
+ ec == null ? void 0 : ec(true);
2578
+ lc == null ? void 0 : lc(true);
2579
+ if (el.parentNode) el.parentNode.removeChild(el);
2580
+ }
2581
+ currentEl = null;
2582
+ leavingEl = null;
2583
+ state = "idle";
2584
+ });
2585
+ return anchor;
2586
+ }
2587
+ Transition[TRANSITION_COMPONENT] = true;
2588
+ function isTransition(node) {
2589
+ return !!node && !!node[TRANSITION_COMPONENT];
2590
+ }
2591
+ function resolveItemElement(raw, parent) {
2592
+ if (raw == null || raw === false) return { el: null, comp: null };
2593
+ if (Array.isArray(raw) && raw.length === 1) {
2594
+ return resolveItemElement(raw[0], parent);
2595
+ }
2596
+ if (shared.isFunction(raw)) {
2597
+ return resolveItemElement(raw(), parent);
2598
+ }
2599
+ if (raw instanceof HTMLElement) {
2600
+ return { el: raw, comp: null };
2601
+ }
2602
+ if (isComponent(raw)) {
2603
+ const comp = raw;
2604
+ if (comp.scope == null) {
2605
+ comp.mount(parent);
2606
+ }
2607
+ if (comp.renderedNodes.length > 1) {
2608
+ shared.warn(
2609
+ "[TransitionGroup] child component rendered multiple root nodes; only the first participates in enter/leave/move animations."
2610
+ );
2611
+ }
2612
+ const first = comp.firstChild;
2613
+ if (first instanceof HTMLElement) return { el: first, comp };
2614
+ return { el: null, comp };
2615
+ }
2616
+ {
2617
+ shared.warn(
2618
+ "[TransitionGroup] child render returned a non-element value; animations require Element or Component roots."
2619
+ );
2620
+ }
2621
+ return { el: null, comp: null };
2622
+ }
2623
+ function saveStyles(el) {
2624
+ return {
2625
+ position: el.style.position,
2626
+ top: el.style.top,
2627
+ left: el.style.left,
2628
+ width: el.style.width,
2629
+ height: el.style.height
2630
+ };
2631
+ }
2632
+ function restoreStyles(el, s) {
2633
+ el.style.position = s.position;
2634
+ el.style.top = s.top;
2635
+ el.style.left = s.left;
2636
+ el.style.width = s.width;
2637
+ el.style.height = s.height;
2638
+ }
2639
+ function TransitionGroup(props) {
2640
+ var _a2, _b, _c;
2641
+ const tag = (_a2 = props.tag) != null ? _a2 : "div";
2642
+ const wrapper = document.createElement(tag);
2643
+ const classes = resolveTransitionClasses(props);
2644
+ const useCss = props.css !== false;
2645
+ const moveClass = (_c = props.moveClass) != null ? _c : `${(_b = props.name) != null ? _b : "v"}-move`;
2646
+ const keyFn = props.key;
2647
+ const rawChildren = props.children;
2648
+ const childrenFn = Array.isArray(rawChildren) && rawChildren.length === 1 && shared.isFunction(rawChildren[0]) ? rawChildren[0] : props.children;
2649
+ if (!shared.isFunction(childrenFn) || !shared.isFunction(keyFn)) {
2650
+ throw new TypeError(
2651
+ "<TransitionGroup> requires `children: (item, index) => Node` and `key: (item, index) => unknown`"
2652
+ );
2653
+ }
2654
+ const getList = () => {
2655
+ var _a3, _b2;
2656
+ const input = props.each;
2657
+ if (signals.isSignal(input)) return (_a3 = input.value) != null ? _a3 : [];
2658
+ if (shared.isFunction(input)) return (_b2 = input()) != null ? _b2 : [];
2659
+ return input != null ? input : [];
2660
+ };
2661
+ let entries = [];
2662
+ let mounted = false;
2663
+ const renderEntry = (item, index) => {
2664
+ const parentScope = getActiveScope();
2665
+ const scope = createScope(parentScope);
2666
+ let raw;
2667
+ runWithScope(scope, () => {
2668
+ raw = childrenFn(item, index);
2669
+ });
2670
+ const { el, comp } = resolveItemElement(raw, wrapper);
2671
+ if (!el) {
2672
+ disposeScope(scope);
2673
+ return null;
2674
+ }
2675
+ return {
2676
+ key: keyFn(item, index),
2677
+ item,
2678
+ el,
2679
+ comp,
2680
+ scope,
2681
+ state: "entering"
2682
+ };
2683
+ };
2684
+ const detachEntryDom = (entry) => {
2685
+ if (entry.comp) {
2686
+ for (const node of entry.comp.renderedNodes) {
2687
+ if (node.parentNode === wrapper) wrapper.removeChild(node);
2688
+ }
2689
+ return;
2690
+ }
2691
+ if (entry.el.parentNode === wrapper) wrapper.removeChild(entry.el);
2692
+ };
2693
+ const disposeEntry = (entry) => {
2694
+ var _a3, _b2;
2695
+ (_a3 = entry.cancelEnter) == null ? void 0 : _a3.call(entry, true);
2696
+ (_b2 = entry.cancelLeave) == null ? void 0 : _b2.call(entry, true);
2697
+ if (entry.comp) entry.comp.destroy();
2698
+ detachEntryDom(entry);
2699
+ disposeScope(entry.scope);
2700
+ };
2701
+ const runEnter = (entry) => {
2702
+ var _a3, _b2, _c2;
2703
+ const el = entry.el;
2704
+ (_a3 = entry.cancelLeave) == null ? void 0 : _a3.call(entry, true);
2705
+ if (!useCss) {
2706
+ entry.state = "present";
2707
+ (_b2 = props.onAfterEnter) == null ? void 0 : _b2.call(props, el);
2708
+ return;
2709
+ }
2710
+ (_c2 = props.onBeforeEnter) == null ? void 0 : _c2.call(props, el);
2711
+ addClass(el, classes.enterFrom);
2712
+ addClass(el, classes.enterActive);
2713
+ let called = false;
2714
+ const done = (cancelled) => {
2715
+ var _a4, _b3;
2716
+ if (called) return;
2717
+ called = true;
2718
+ entry.cancelEnter = void 0;
2719
+ removeClass(el, classes.enterFrom);
2720
+ removeClass(el, classes.enterActive);
2721
+ removeClass(el, classes.enterTo);
2722
+ if (cancelled) {
2723
+ (_a4 = props.onEnterCancelled) == null ? void 0 : _a4.call(props, el);
2724
+ } else {
2725
+ entry.state = "present";
2726
+ (_b3 = props.onAfterEnter) == null ? void 0 : _b3.call(props, el);
2727
+ }
2728
+ };
2729
+ entry.cancelEnter = done;
2730
+ entry.state = "entering";
2731
+ nextFrame(() => {
2732
+ if (called) return;
2733
+ removeClass(el, classes.enterFrom);
2734
+ addClass(el, classes.enterTo);
2735
+ if (props.onEnter) {
2736
+ props.onEnter(el, () => done(false));
2737
+ } else {
2738
+ const explicit = resolveDuration(props.duration, "enter");
2739
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2740
+ }
2741
+ });
2742
+ };
2743
+ const runLeave = (entry, prevRect) => {
2744
+ var _a3, _b2;
2745
+ const el = entry.el;
2746
+ if (entry.cancelEnter) {
2747
+ entry.cancelEnter(true);
2748
+ forceReflow(el);
2749
+ }
2750
+ entry.state = "leaving";
2751
+ entry.savedStyles = saveStyles(el);
2752
+ const parentRect = wrapper.getBoundingClientRect();
2753
+ el.style.position = "absolute";
2754
+ el.style.top = `${prevRect.top - parentRect.top}px`;
2755
+ el.style.left = `${prevRect.left - parentRect.left}px`;
2756
+ el.style.width = `${prevRect.width}px`;
2757
+ el.style.height = `${prevRect.height}px`;
2758
+ if (!useCss) {
2759
+ if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
2760
+ detachEntryDom(entry);
2761
+ disposeScope(entry.scope);
2762
+ if (entry.comp) entry.comp.destroy();
2763
+ (_a3 = props.onAfterLeave) == null ? void 0 : _a3.call(props, el);
2764
+ return;
2765
+ }
2766
+ (_b2 = props.onBeforeLeave) == null ? void 0 : _b2.call(props, el);
2767
+ addClass(el, classes.leaveFrom);
2768
+ addClass(el, classes.leaveActive);
2769
+ let called = false;
2770
+ const done = (cancelled) => {
2771
+ var _a4, _b3;
2772
+ if (called) return;
2773
+ called = true;
2774
+ entry.cancelLeave = void 0;
2775
+ removeClass(el, classes.leaveFrom);
2776
+ removeClass(el, classes.leaveActive);
2777
+ removeClass(el, classes.leaveTo);
2778
+ if (cancelled) {
2779
+ if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
2780
+ entry.savedStyles = void 0;
2781
+ (_a4 = props.onLeaveCancelled) == null ? void 0 : _a4.call(props, el);
2782
+ return;
2783
+ }
2784
+ if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
2785
+ entry.savedStyles = void 0;
2786
+ detachEntryDom(entry);
2787
+ disposeScope(entry.scope);
2788
+ if (entry.comp) entry.comp.destroy();
2789
+ (_b3 = props.onAfterLeave) == null ? void 0 : _b3.call(props, el);
2790
+ };
2791
+ entry.cancelLeave = done;
2792
+ nextFrame(() => {
2793
+ if (called) return;
2794
+ removeClass(el, classes.leaveFrom);
2795
+ addClass(el, classes.leaveTo);
2796
+ if (props.onLeave) {
2797
+ props.onLeave(el, () => done(false));
2798
+ } else {
2799
+ const explicit = resolveDuration(props.duration, "leave");
2800
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2801
+ }
2802
+ });
2803
+ };
2804
+ const runMove = (entry, prevRect) => {
2805
+ if (!useCss || entry.state !== "present") return;
2806
+ const el = entry.el;
2807
+ const newRect = el.getBoundingClientRect();
2808
+ const dx = prevRect.left - newRect.left;
2809
+ const dy = prevRect.top - newRect.top;
2810
+ if (!dx && !dy) return;
2811
+ const savedTransform = el.style.transform;
2812
+ const savedTransition = el.style.transitionDuration;
2813
+ el.style.transform = `translate(${dx}px, ${dy}px)`;
2814
+ el.style.transitionDuration = "0s";
2815
+ addClass(el, moveClass);
2816
+ forceReflow(el);
2817
+ el.style.transform = savedTransform;
2818
+ el.style.transitionDuration = savedTransition;
2819
+ const explicit = resolveDuration(props.duration, "enter");
2820
+ whenTransitionEnds(el, props.type, explicit, () => {
2821
+ removeClass(el, moveClass);
2822
+ });
2823
+ };
2824
+ const snapshotPositions = () => {
2825
+ for (const entry of entries) {
2826
+ if (entry.state === "leaving") continue;
2827
+ entry.prevRect = entry.el.getBoundingClientRect();
2828
+ }
2829
+ };
2830
+ const reconcile = (newItems) => {
2831
+ const byKey = /* @__PURE__ */ new Map();
2832
+ for (const entry of entries) byKey.set(entry.key, entry);
2833
+ const next2 = [];
2834
+ for (const [i, item] of newItems.entries()) {
2835
+ const key = keyFn(item, i);
2836
+ const reused = byKey.get(key);
2837
+ if (reused) {
2838
+ byKey.delete(key);
2839
+ reused.item = item;
2840
+ next2.push(reused);
2841
+ } else {
2842
+ const fresh = renderEntry(item, i);
2843
+ if (fresh) next2.push(fresh);
2844
+ }
2845
+ }
2846
+ const leaving = [];
2847
+ for (const entry of byKey.values()) {
2848
+ if (entry.state !== "leaving") leaving.push(entry);
2849
+ }
2850
+ let anchor = null;
2851
+ for (let i = next2.length - 1; i >= 0; i--) {
2852
+ const el = next2[i].el;
2853
+ if (el.parentNode !== wrapper || el.nextSibling !== anchor) {
2854
+ wrapper.insertBefore(el, anchor);
2855
+ }
2856
+ anchor = el;
2857
+ }
2858
+ return { next: next2, leaving };
2859
+ };
2860
+ const update = (newItems, isInitial) => {
2861
+ if (isInitial) {
2862
+ const initial = [];
2863
+ for (const [i, item] of newItems.entries()) {
2864
+ const entry = renderEntry(item, i);
2865
+ if (!entry) continue;
2866
+ if (entry.el.parentNode !== wrapper) wrapper.appendChild(entry.el);
2867
+ entry.state = "present";
2868
+ initial.push(entry);
2869
+ }
2870
+ entries = initial;
2871
+ return;
2872
+ }
2873
+ snapshotPositions();
2874
+ const { next: next2, leaving } = reconcile(newItems);
2875
+ for (const entry of next2) {
2876
+ if (entry.state !== "present") runEnter(entry);
2877
+ }
2878
+ for (const entry of leaving) {
2879
+ const rect = entry.prevRect;
2880
+ if (!rect) {
2881
+ {
2882
+ shared.warn("[TransitionGroup] leaving entry without prevRect \u2014 skipping leave animation");
2883
+ }
2884
+ continue;
2885
+ }
2886
+ runLeave(entry, rect);
2887
+ }
2888
+ for (const entry of next2) {
2889
+ if (entry.state !== "present" || !entry.prevRect) continue;
2890
+ runMove(entry, entry.prevRect);
2891
+ entry.prevRect = void 0;
2892
+ }
2893
+ entries = next2.concat(leaving);
2894
+ };
2895
+ let pendingItems = null;
2896
+ const effectRunner = signals.effect(() => {
2897
+ const list = getList();
2898
+ if (!mounted) {
2899
+ pendingItems = list;
2900
+ return;
2901
+ }
2902
+ update(list, false);
2903
+ });
2904
+ onMount(() => {
2905
+ mounted = true;
2906
+ if (pendingItems) {
2907
+ update(pendingItems, true);
2908
+ pendingItems = null;
2909
+ }
2910
+ });
2911
+ onCleanup(() => {
2912
+ effectRunner.stop();
2913
+ for (const entry of entries) disposeEntry(entry);
2914
+ entries = [];
2915
+ if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper);
2916
+ });
2917
+ return wrapper;
2918
+ }
2919
+ TransitionGroup[TRANSITION_GROUP_COMPONENT] = true;
2920
+ function isTransitionGroup(node) {
2921
+ return !!node && !!node[TRANSITION_GROUP_COMPONENT];
2922
+ }
2145
2923
 
2146
2924
  exports.Component = Component;
2147
2925
  exports.For = For;
2148
2926
  exports.Fragment = Fragment;
2149
2927
  exports.Portal = Portal;
2150
2928
  exports.Suspense = Suspense;
2929
+ exports.Transition = Transition;
2930
+ exports.TransitionGroup = TransitionGroup;
2151
2931
  exports.addEvent = addEvent;
2152
2932
  exports.addEventListener = addEventListener;
2153
2933
  exports.beginHydration = beginHydration;
@@ -2165,6 +2945,8 @@ exports.endHydration = endHydration;
2165
2945
  exports.getHydrationKey = getHydrationKey;
2166
2946
  exports.getRenderedElement = getRenderedElement;
2167
2947
  exports.hydrate = hydrate;
2948
+ exports.hydrationAnchor = hydrationAnchor;
2949
+ exports.hydrationMarker = hydrationMarker;
2168
2950
  exports.inject = inject;
2169
2951
  exports.insert = insert;
2170
2952
  exports.isComponent = isComponent;
@@ -2172,6 +2954,8 @@ exports.isFragment = isFragment;
2172
2954
  exports.isHydrating = isHydrating;
2173
2955
  exports.isPortal = isPortal;
2174
2956
  exports.isSuspense = isSuspense;
2957
+ exports.isTransition = isTransition;
2958
+ exports.isTransitionGroup = isTransitionGroup;
2175
2959
  exports.next = next;
2176
2960
  exports.normalizeClass = normalizeClass;
2177
2961
  exports.nthChild = nthChild;
@@ -2189,5 +2973,5 @@ exports.provide = provide;
2189
2973
  exports.resetHydrationKey = resetHydrationKey;
2190
2974
  exports.setStyle = setStyle;
2191
2975
  exports.template = template;
2192
- //# sourceMappingURL=template.dev.cjs.js.map
2193
- //# sourceMappingURL=template.dev.cjs.js.map
2976
+ //# sourceMappingURL=template.dev.cjs.map
2977
+ //# sourceMappingURL=template.dev.cjs.map