@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.
@@ -1,9 +1,7 @@
1
- import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __async } from './chunk-OEKE4VTS.dev.esm.js';
2
- import { normalizeClassName, isObject, warn, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isString, isArray, kebabCase, camelCase, capitalize, isBrowser, error, isPromise, isFunction, isOn, coerceArray } from '@estjs/shared';
3
- import { effect, shallowReactive, isSignal, isComputed, signal } from '@estjs/signals';
1
+ import { getActiveScope, runWithScope, onCleanup, __objRest, createScope, disposeScope, __async } from './chunk-R6JICOKI.dev.js';
2
+ import { normalizeClassName, SPREAD_NAME, isObject, warn, startsWith, isSpecialBooleanAttr, isBooleanAttr, includeBooleanAttr, isSymbol, isString, isArray, kebabCase, camelCase, capitalize, HYDRATION_ANCHOR_ATTR, isBrowser, error, isPromise, isFunction, isOn, coerceArray } from '@estjs/shared';
3
+ import { effect, shallowReactive, isSignal, isComputed, isReactive, signal } from '@estjs/signals';
4
4
 
5
- // src/constants.ts
6
- var SPREAD_NAME = "_$spread$";
7
5
  var REF_KEY = "ref";
8
6
  var KEY_PROP = "key";
9
7
  var SVG_NAMESPACE = "http://www.w3.org/2000/svg";
@@ -13,6 +11,8 @@ var FRAGMENT_COMPONENT = /* @__PURE__ */ Symbol("Fragment Component" );
13
11
  var PORTAL_COMPONENT = /* @__PURE__ */ Symbol("Portal Component" );
14
12
  var SUSPENSE_COMPONENT = /* @__PURE__ */ Symbol("Suspense Component" );
15
13
  var FOR_COMPONENT = /* @__PURE__ */ Symbol("For Component" );
14
+ var TRANSITION_COMPONENT = /* @__PURE__ */ Symbol("Transition Component" );
15
+ var TRANSITION_GROUP_COMPONENT = /* @__PURE__ */ Symbol("TransitionGroup Component" );
16
16
  function patchAttr(el, key, prev, next2) {
17
17
  if (key === KEY_PROP) {
18
18
  if (next2 == null) {
@@ -57,8 +57,8 @@ function patchAttr(el, key, prev, next2) {
57
57
  return;
58
58
  }
59
59
  const elementIsSVG = (el == null ? void 0 : el.namespaceURI) === SVG_NAMESPACE;
60
- const isXlink = elementIsSVG && key.startsWith("xlink:");
61
- const isXmlns = elementIsSVG && key.startsWith("xmlns:");
60
+ const isXlink = elementIsSVG && startsWith(key, "xlink:");
61
+ const isXmlns = elementIsSVG && startsWith(key, "xmlns:");
62
62
  const isBoolean = isSpecialBooleanAttr(key) || isBooleanAttr(key);
63
63
  if (prev === next2) {
64
64
  return;
@@ -96,7 +96,7 @@ function patchAttr(el, key, prev, next2) {
96
96
  const isUrlAttr = lowerKey === "href" || lowerKey === "src" || lowerKey === "xlink:href" || lowerKey === "action" || lowerKey === "formaction" || lowerKey === "poster";
97
97
  if (isUrlAttr && isString(attrValue)) {
98
98
  const v = attrValue.trim().toLowerCase();
99
- if (v.startsWith("javascript:") || v.startsWith("data:")) {
99
+ if (startsWith(v, "javascript:") || startsWith(v, "data:")) {
100
100
  return;
101
101
  }
102
102
  }
@@ -200,7 +200,7 @@ function setStyle(style, name, val) {
200
200
  if (priority) {
201
201
  val = val.replace(importantRE, "");
202
202
  }
203
- if (name.startsWith("--")) {
203
+ if (startsWith(name, "--")) {
204
204
  if (priority) {
205
205
  style.setProperty(name, val, priority);
206
206
  } else {
@@ -217,7 +217,7 @@ function setStyle(style, name, val) {
217
217
  }
218
218
  function toCssPropertyName(name) {
219
219
  const hyphenated = kebabCase(name);
220
- return name.startsWith("Webkit") || name.startsWith("Moz") || name.startsWith("ms") ? `-${hyphenated}` : hyphenated;
220
+ return startsWith(name, "Webkit") || startsWith(name, "Moz") || startsWith(name, "ms") ? `-${hyphenated}` : hyphenated;
221
221
  }
222
222
  function autoPrefix(style, rawName) {
223
223
  const cached = prefixCache[rawName];
@@ -319,6 +319,77 @@ function endHydration() {
319
319
  _teleportCallsiteAnchors.length = 0;
320
320
  _teleportTargetStarts.clear();
321
321
  }
322
+ function claimHydratedNodes(parent, expected, before) {
323
+ var _a2, _b;
324
+ if (!_isHydrating || before && before.parentNode !== parent) return null;
325
+ if (expected.length === 0) return [];
326
+ const claimed = new Array(expected.length);
327
+ let cursor = before ? before.previousSibling : parent.lastChild;
328
+ for (let i = expected.length - 1; i >= 0; i--) {
329
+ if (!cursor) return null;
330
+ const expectedNode = expected[i];
331
+ const expectedType = expectedNode.nodeType;
332
+ if (expectedType === Node.TEXT_NODE) {
333
+ const expectedText = (_a2 = expectedNode.textContent) != null ? _a2 : "";
334
+ if (!expectedText || cursor.nodeType !== Node.TEXT_NODE) return null;
335
+ const existingText = (_b = cursor.textContent) != null ? _b : "";
336
+ if (existingText === expectedText) {
337
+ claimed[i] = cursor;
338
+ cursor = cursor.previousSibling;
339
+ continue;
340
+ }
341
+ if (!existingText.endsWith(expectedText)) return null;
342
+ const prefix = existingText.slice(0, existingText.length - expectedText.length);
343
+ if (!prefix) return null;
344
+ const prefixNode = document.createTextNode(prefix);
345
+ parent.insertBefore(prefixNode, cursor);
346
+ cursor.textContent = expectedText;
347
+ claimed[i] = cursor;
348
+ cursor = prefixNode;
349
+ continue;
350
+ }
351
+ if (cursor.nodeType !== expectedType) return null;
352
+ if (expectedType === Node.ELEMENT_NODE) {
353
+ if (cursor.tagName !== expectedNode.tagName) return null;
354
+ } else if (expectedType === Node.COMMENT_NODE && cursor.data !== expectedNode.data) {
355
+ return null;
356
+ }
357
+ claimed[i] = cursor;
358
+ cursor = cursor.previousSibling;
359
+ }
360
+ return claimed;
361
+ }
362
+ function resolveHydrationKey(parent) {
363
+ var _a2, _b, _c;
364
+ const el = parent;
365
+ return (_c = (_b = el.dataset.hk) != null ? _b : (_a2 = parent.closest("[data-hk]")) == null ? void 0 : _a2.dataset.hk) != null ? _c : null;
366
+ }
367
+ function hydrationMarker(parent, index) {
368
+ if (!_isHydrating || !parent || index < 0) return null;
369
+ const key = parent instanceof Element ? resolveHydrationKey(parent) : null;
370
+ const expected = key ? `${key}-${index}` : String(index);
371
+ let cursor = parent.firstChild;
372
+ while (cursor) {
373
+ if (cursor.nodeType === Node.COMMENT_NODE && cursor.data === expected) {
374
+ return cursor;
375
+ }
376
+ cursor = cursor.nextSibling;
377
+ }
378
+ return null;
379
+ }
380
+ function hydrationAnchor(parent, index) {
381
+ if (!_isHydrating || !(parent instanceof Element) || index < 0) return null;
382
+ const key = resolveHydrationKey(parent);
383
+ const expected = key ? `${key}-${index}` : String(index);
384
+ let cursor = parent.firstChild;
385
+ while (cursor) {
386
+ if (cursor instanceof Element && cursor.getAttribute(HYDRATION_ANCHOR_ATTR) === expected) {
387
+ return cursor;
388
+ }
389
+ cursor = cursor.nextSibling;
390
+ }
391
+ return null;
392
+ }
322
393
  function getRenderedElement(html) {
323
394
  if (!isBrowser()) {
324
395
  return () => {
@@ -416,12 +487,17 @@ function reconcileArrays(parent, oldNodes, newNodes, anchor) {
416
487
  }
417
488
  function reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, newEnd, anchor) {
418
489
  const newLength = newEnd - start + 1;
419
- const newIndexMap = /* @__PURE__ */ new Map();
420
- for (let i = start; i <= newEnd; i++) {
421
- newIndexMap.set(newNodes[i], i);
422
- }
490
+ const findNewIndex = newLength <= 4 ? (node) => {
491
+ for (let i = start; i <= newEnd; i++) {
492
+ if (newNodes[i] === node) return i;
493
+ }
494
+ return void 0;
495
+ } : (() => {
496
+ const map = /* @__PURE__ */ new Map();
497
+ for (let i = start; i <= newEnd; i++) map.set(newNodes[i], i);
498
+ return (node) => map.get(node);
499
+ })();
423
500
  const newIndexToOldIndexMap = new Int32Array(newLength);
424
- newIndexToOldIndexMap.fill(0);
425
501
  let patched = 0;
426
502
  let moved = false;
427
503
  let maxNewIndexSoFar = 0;
@@ -431,7 +507,7 @@ function reconcileUnknownSequence(parent, oldNodes, newNodes, start, oldEnd, new
431
507
  removeNode(oldNode);
432
508
  continue;
433
509
  }
434
- const newIndex = newIndexMap.get(oldNode);
510
+ const newIndex = findNewIndex(oldNode);
435
511
  if (newIndex === void 0) {
436
512
  removeNode(oldNode);
437
513
  } else {
@@ -577,6 +653,14 @@ function insert(parent, nodeFactory, before) {
577
653
  isFirstRun = false;
578
654
  return;
579
655
  }
656
+ if (isFirstRun && isHydrating()) {
657
+ const hydratedNodes = claimHydratedNodes(parent, nodes, before);
658
+ if (hydratedNodes) {
659
+ renderedNodes = hydratedNodes;
660
+ isFirstRun = false;
661
+ return;
662
+ }
663
+ }
580
664
  renderedNodes = reconcileArrays(parent, renderedNodes, nodes, before);
581
665
  isFirstRun = false;
582
666
  };
@@ -723,14 +807,13 @@ function triggerUpdateHooks(scope) {
723
807
 
724
808
  // src/component.ts
725
809
  function syncDescriptors(target, source, pruneMissing = false) {
726
- const seen = pruneMissing ? /* @__PURE__ */ new Set() : null;
727
810
  for (const key of Object.getOwnPropertyNames(source)) {
728
- seen == null ? void 0 : seen.add(key);
729
811
  Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
730
812
  }
731
- if (seen) {
813
+ if (pruneMissing) {
814
+ const sourceKeys = Object.getOwnPropertyNames(source);
732
815
  for (const key of Object.getOwnPropertyNames(target)) {
733
- if (!seen.has(key)) delete target[key];
816
+ if (!sourceKeys.includes(key)) delete target[key];
734
817
  }
735
818
  }
736
819
  }
@@ -839,6 +922,9 @@ var Component = class {
839
922
  this.renderedNodes = [];
840
923
  this.firstChild = void 0;
841
924
  this.parentNode = void 0;
925
+ for (const key of Object.getOwnPropertyNames(this.reactiveProps)) {
926
+ delete this.reactiveProps[key];
927
+ }
842
928
  }
843
929
  /**
844
930
  * Apply props that bind to the root DOM element rather than flowing into
@@ -849,7 +935,7 @@ var Component = class {
849
935
  syncSpecialProps(props) {
850
936
  if (!props) return;
851
937
  const root = this.firstChild;
852
- if (!root) return;
938
+ if (!root || !(root instanceof Element)) return;
853
939
  this.releaseSpecialProps();
854
940
  for (const key of Object.getOwnPropertyNames(props)) {
855
941
  if (key === REF_KEY) {
@@ -861,7 +947,22 @@ var Component = class {
861
947
  const value = readProp(props, key);
862
948
  if (!isFunction(value)) continue;
863
949
  const eventName = key.slice(2).toLowerCase();
864
- this.rootEventCleanups.push(addEvent(root, eventName, value));
950
+ const target = root;
951
+ const slot = `_$${eventName}`;
952
+ const prev = target[slot];
953
+ if (isFunction(prev)) {
954
+ target[slot] = value;
955
+ this.rootEventCleanups.push(() => {
956
+ if (target[slot] === value) target[slot] = prev;
957
+ });
958
+ continue;
959
+ }
960
+ const fn = value;
961
+ const handler = (event) => {
962
+ if (target.disabled) return;
963
+ fn.call(target, event);
964
+ };
965
+ this.rootEventCleanups.push(addEvent(target, eventName, handler));
865
966
  }
866
967
  }
867
968
  }
@@ -1079,7 +1180,7 @@ function eventHandler(e) {
1079
1180
  reTargetEvent(e, oriTarget);
1080
1181
  }
1081
1182
  var $EVENTS = /* @__PURE__ */ Symbol("_$EVENTS");
1082
- function delegateEvents(eventNames, document2 = window.document) {
1183
+ function delegateEvents(eventNames, document2 = globalThis.document) {
1083
1184
  const docWithEvents = document2;
1084
1185
  const eventSet = docWithEvents[$EVENTS] || (docWithEvents[$EVENTS] = /* @__PURE__ */ new Set());
1085
1186
  for (const name of eventNames) {
@@ -1089,7 +1190,7 @@ function delegateEvents(eventNames, document2 = window.document) {
1089
1190
  }
1090
1191
  }
1091
1192
  }
1092
- function clearDelegatedEvents(document2 = window.document) {
1193
+ function clearDelegatedEvents(document2 = globalThis.document) {
1093
1194
  const docWithEvents = document2;
1094
1195
  const eventSet = docWithEvents[$EVENTS];
1095
1196
  if (eventSet) {
@@ -1107,6 +1208,11 @@ function addEventListener(element, event, handler, options) {
1107
1208
  }
1108
1209
 
1109
1210
  // src/binding.ts
1211
+ var IDENTITY = (v) => v;
1212
+ var EMPTY_FILES = (() => {
1213
+ if (typeof DataTransfer !== "undefined") return new DataTransfer().files;
1214
+ return [];
1215
+ })();
1110
1216
  function writeValue(el, v) {
1111
1217
  const target = el;
1112
1218
  const next2 = v == null ? "" : String(v);
@@ -1115,10 +1221,11 @@ function writeValue(el, v) {
1115
1221
  var CHECKBOX = {
1116
1222
  event: "change",
1117
1223
  forceChange: true,
1224
+ checkboxArray: true,
1118
1225
  read: (el) => el.checked,
1119
1226
  write(el, v) {
1120
1227
  const e = el;
1121
- const next2 = Boolean(v);
1228
+ const next2 = isArray(v) ? v.map(String).includes(e.value) : Boolean(v);
1122
1229
  if (e.checked !== next2) e.checked = next2;
1123
1230
  }
1124
1231
  };
@@ -1139,17 +1246,15 @@ var FILE = {
1139
1246
  event: "change",
1140
1247
  forceChange: true,
1141
1248
  read: (el) => el.files,
1142
- write() {
1249
+ write(el, v) {
1250
+ if (v != null) return;
1251
+ try {
1252
+ el.files = EMPTY_FILES;
1253
+ } catch (e) {
1254
+ }
1143
1255
  }
1144
- // browsers forbid programmatic writes to file inputs
1145
1256
  };
1146
- var TEXT = {
1147
- event: "input",
1148
- ime: true,
1149
- read: (el) => el.value,
1150
- write: writeValue
1151
- };
1152
- var TEXTAREA = {
1257
+ var TEXT_LIKE = {
1153
1258
  event: "input",
1154
1259
  ime: true,
1155
1260
  read: (el) => el.value,
@@ -1164,41 +1269,44 @@ var SELECT = {
1164
1269
  },
1165
1270
  write(el, v) {
1166
1271
  const s = el;
1167
- if (s.multiple) {
1168
- const selected = new Set((Array.isArray(v) ? v : []).map(String));
1169
- for (const opt of Array.from(s.options)) opt.selected = selected.has(opt.value);
1170
- } else {
1171
- writeValue(el, v);
1172
- }
1272
+ if (!s.multiple) return writeValue(el, v);
1273
+ const selected = new Set((isArray(v) ? v : []).map(String));
1274
+ for (const opt of Array.from(s.options)) opt.selected = selected.has(opt.value);
1173
1275
  }
1174
1276
  };
1277
+ function customStrategy(prop) {
1278
+ return {
1279
+ event: "input",
1280
+ read: (el) => el[prop],
1281
+ write(el, v) {
1282
+ el[prop] = v;
1283
+ }
1284
+ };
1285
+ }
1175
1286
  function resolve(node, prop) {
1176
1287
  switch (node.nodeName) {
1177
1288
  case "INPUT":
1178
1289
  if (prop === "checked") return node.type === "radio" ? RADIO : CHECKBOX;
1179
1290
  if (prop === "files") return FILE;
1180
- return TEXT;
1291
+ if (prop === "value") return TEXT_LIKE;
1292
+ return customStrategy(prop);
1181
1293
  case "SELECT":
1182
1294
  return SELECT;
1183
1295
  case "TEXTAREA":
1184
- return TEXTAREA;
1296
+ return TEXT_LIKE;
1185
1297
  default:
1186
- return {
1187
- event: "input",
1188
- read: (el) => el[prop],
1189
- write(el, v) {
1190
- el[prop] = v;
1191
- }
1192
- };
1298
+ return customStrategy(prop);
1193
1299
  }
1194
1300
  }
1195
1301
  function applyModifiers(v, trim, toNum) {
1196
1302
  if (!isString(v)) return v;
1197
- let s = v;
1198
- if (trim) s = s.trim();
1199
- if (toNum && s !== "") {
1200
- const n = Number(s);
1201
- if (!Number.isNaN(n)) return n;
1303
+ const s = trim ? v.trim() : v;
1304
+ if (toNum) {
1305
+ const probe = trim ? s : s.trim();
1306
+ if (probe !== "") {
1307
+ const n = Number(probe);
1308
+ if (!Number.isNaN(n)) return n;
1309
+ }
1202
1310
  }
1203
1311
  return s;
1204
1312
  }
@@ -1206,44 +1314,54 @@ function isFocused(el) {
1206
1314
  const root = el.getRootNode();
1207
1315
  return (root instanceof Document || root instanceof ShadowRoot) && root.activeElement === el;
1208
1316
  }
1317
+ function shouldAutoCoerceNumber(node, prop) {
1318
+ if (prop !== "value" || node.nodeName !== "INPUT") return false;
1319
+ const t = node.type;
1320
+ return t === "number" || t === "range";
1321
+ }
1209
1322
  function bindElement(node, prop, getter, setter, modifiers = {}) {
1210
1323
  if (!node) return;
1211
- const { event, read, write, forceChange, ime } = resolve(node, prop);
1324
+ const { event, read, write, forceChange, ime, checkboxArray } = resolve(node, prop);
1212
1325
  const trim = modifiers.trim === true;
1213
- const toNum = modifiers.number === true;
1326
+ const toNum = modifiers.number === true || shouldAutoCoerceNumber(node, prop);
1214
1327
  const lazy = modifiers.lazy === true;
1215
1328
  const shouldCast = (trim || toNum) && prop !== "files";
1216
1329
  const getModel = isFunction(getter) ? getter : () => getter;
1217
- const cast = shouldCast ? (v) => applyModifiers(v, trim, toNum) : (v) => v;
1330
+ const cast = shouldCast ? (v) => applyModifiers(v, trim, toNum) : IDENTITY;
1331
+ const computeNext = checkboxArray ? (raw) => {
1332
+ const current = getModel();
1333
+ if (!isArray(current)) return cast(raw);
1334
+ const own = node.value;
1335
+ const next2 = current.filter((item) => String(item) !== own);
1336
+ if (raw) next2.push(own);
1337
+ return next2;
1338
+ } : cast;
1218
1339
  let composing = false;
1219
1340
  const eventName = lazy || forceChange ? "change" : event;
1220
1341
  const syncToModel = () => {
1221
1342
  if (composing) return;
1222
1343
  const raw = read(node);
1223
1344
  if (raw === void 0) return;
1224
- const next2 = cast(raw);
1345
+ const next2 = computeNext(raw);
1225
1346
  if (!Object.is(getModel(), next2)) setter(next2);
1226
1347
  };
1227
1348
  addEventListener(node, eventName, syncToModel);
1228
1349
  if (!lazy && shouldCast && eventName !== "change") {
1229
1350
  addEventListener(node, "change", () => write(node, cast(read(node))));
1230
1351
  }
1231
- if (ime && !lazy) {
1352
+ if (ime) {
1232
1353
  addEventListener(node, "compositionstart", () => {
1233
1354
  composing = true;
1234
1355
  });
1235
1356
  addEventListener(node, "compositionend", () => {
1236
- if (!composing) return;
1237
1357
  composing = false;
1238
- syncToModel();
1358
+ if (!lazy) syncToModel();
1239
1359
  });
1240
1360
  }
1241
1361
  const runner = effect(() => {
1242
1362
  const value = getModel();
1243
- if (ime && !lazy && isFocused(node)) {
1244
- if (composing) return;
1245
- if (Object.is(cast(read(node)), value)) return;
1246
- }
1363
+ if (ime && composing) return;
1364
+ if (ime && !lazy && isFocused(node) && Object.is(cast(read(node)), value)) return;
1247
1365
  write(node, value);
1248
1366
  });
1249
1367
  if (getActiveScope()) {
@@ -1252,6 +1370,18 @@ function bindElement(node, prop, getter, setter, modifiers = {}) {
1252
1370
  }
1253
1371
 
1254
1372
  // src/utils.ts
1373
+ function unwrapSlotValue(raw) {
1374
+ let v = raw;
1375
+ if (Array.isArray(v) && v.length === 1) v = v[0];
1376
+ return typeof v === "function" ? v() : v;
1377
+ }
1378
+ function useChildren(props) {
1379
+ const desc = Object.getOwnPropertyDescriptor(props, "children");
1380
+ if (desc == null ? void 0 : desc.get) {
1381
+ return () => unwrapSlotValue(desc.get.call(props));
1382
+ }
1383
+ return () => unwrapSlotValue(props.children);
1384
+ }
1255
1385
  function omitProps(target, keys) {
1256
1386
  const excludeSet = new Set(keys);
1257
1387
  return new Proxy(target, {
@@ -1290,9 +1420,11 @@ function omitProps(target, keys) {
1290
1420
  }
1291
1421
  });
1292
1422
  }
1293
-
1294
- // src/components/Fragment.ts
1295
1423
  function Fragment(props) {
1424
+ var _a2;
1425
+ if (props && (((_a2 = Object.getOwnPropertyDescriptor(props, "children")) == null ? void 0 : _a2.get) || isReactive(props))) {
1426
+ return [() => props.children];
1427
+ }
1296
1428
  const children = props == null ? void 0 : props.children;
1297
1429
  if (children == null) return null;
1298
1430
  return children;
@@ -1811,7 +1943,11 @@ function For(props) {
1811
1943
  let entries = [];
1812
1944
  let fallbackNodes = [];
1813
1945
  const keyFn = props.key;
1814
- const renderFn = props.children;
1946
+ const raw = props.children;
1947
+ const renderFn = Array.isArray(raw) && raw.length === 1 && isFunction(raw[0]) ? raw[0] : props.children;
1948
+ if (!isFunction(renderFn)) {
1949
+ throw new TypeError("<For> requires `children` to be a function (item, index) => Node");
1950
+ }
1815
1951
  const getList = () => {
1816
1952
  var _a2, _b;
1817
1953
  const input = props.each;
@@ -1820,26 +1956,20 @@ function For(props) {
1820
1956
  return input != null ? input : [];
1821
1957
  };
1822
1958
  const getKey = (item, index) => keyFn ? keyFn(item, index) : item;
1823
- const normalizeNodes = (value) => {
1959
+ const mountValue = (value, parent, before) => {
1960
+ if (value == null || value === false) return [];
1824
1961
  if (Array.isArray(value)) {
1825
1962
  const nodes = [];
1826
- for (const item of value) {
1827
- nodes.push(...normalizeNodes(item));
1828
- }
1963
+ for (const child2 of value) nodes.push(...mountValue(child2, parent, before));
1829
1964
  return nodes;
1830
1965
  }
1831
- return [normalizeNode(value)];
1832
- };
1833
- const mountValue = (value, parent, before) => {
1834
- const nodes = normalizeNodes(value);
1835
- for (const node of nodes) {
1836
- if (before) {
1837
- parent.insertBefore(node, before);
1838
- } else {
1839
- parent.appendChild(node);
1840
- }
1966
+ if (isComponent(value)) {
1967
+ insertNode(parent, value, before != null ? before : void 0);
1968
+ return value.renderedNodes;
1841
1969
  }
1842
- return nodes;
1970
+ const node = normalizeNode(value);
1971
+ insertNode(parent, node, before != null ? before : void 0);
1972
+ return [node];
1843
1973
  };
1844
1974
  const mountFallback = (parent, before) => {
1845
1975
  if (!props.fallback) return;
@@ -1995,7 +2125,655 @@ function For(props) {
1995
2125
  return fragment;
1996
2126
  }
1997
2127
  For[FOR_COMPONENT] = true;
2128
+ function resolveTransitionClasses(props) {
2129
+ var _a2, _b, _c, _d, _e, _f, _g, _h, _i, _j;
2130
+ const n = (_a2 = props.name) != null ? _a2 : "v";
2131
+ const enterFrom = (_b = props.enterFromClass) != null ? _b : `${n}-enter-from`;
2132
+ const enterActive = (_c = props.enterActiveClass) != null ? _c : `${n}-enter-active`;
2133
+ const enterTo = (_d = props.enterToClass) != null ? _d : `${n}-enter-to`;
2134
+ return {
2135
+ enterFrom,
2136
+ enterActive,
2137
+ enterTo,
2138
+ leaveFrom: (_e = props.leaveFromClass) != null ? _e : `${n}-leave-from`,
2139
+ leaveActive: (_f = props.leaveActiveClass) != null ? _f : `${n}-leave-active`,
2140
+ leaveTo: (_g = props.leaveToClass) != null ? _g : `${n}-leave-to`,
2141
+ appearFrom: (_h = props.appearFromClass) != null ? _h : enterFrom,
2142
+ appearActive: (_i = props.appearActiveClass) != null ? _i : enterActive,
2143
+ appearTo: (_j = props.appearToClass) != null ? _j : enterTo
2144
+ };
2145
+ }
2146
+ var toMs = (s) => {
2147
+ if (!s) return 0;
2148
+ if (s.endsWith("ms")) return Number(s.slice(0, -2).replace(",", "."));
2149
+ return Number(s.slice(0, -1).replace(",", ".")) * 1e3;
2150
+ };
2151
+ function sumMs(delays, durations) {
2152
+ const d = delays.split(", ");
2153
+ const u = durations.split(", ");
2154
+ let max = 0;
2155
+ for (const [i, dur] of u.entries()) {
2156
+ const total = toMs(dur) + toMs(d[i % d.length] || "0s");
2157
+ if (total > max) max = total;
2158
+ }
2159
+ return max;
2160
+ }
2161
+ function getTransitionInfo(el, type) {
2162
+ const s = getComputedStyle(el);
2163
+ const tt = type !== "animation" ? sumMs(s.transitionDelay, s.transitionDuration) : 0;
2164
+ const at = type !== "transition" ? sumMs(s.animationDelay, s.animationDuration) : 0;
2165
+ if (tt === 0 && at === 0) return null;
2166
+ return tt >= at ? { event: "transitionend", timeout: tt } : { event: "animationend", timeout: at };
2167
+ }
2168
+ function addClass(el, cls) {
2169
+ for (const c of cls.split(/\s+/)) if (c) el.classList.add(c);
2170
+ }
2171
+ function removeClass(el, cls) {
2172
+ for (const c of cls.split(/\s+/)) if (c) el.classList.remove(c);
2173
+ }
2174
+ function nextFrame(cb) {
2175
+ requestAnimationFrame(() => requestAnimationFrame(cb));
2176
+ }
2177
+ function forceReflow(el) {
2178
+ void el.offsetHeight;
2179
+ }
2180
+ function whenTransitionEnds(el, type, explicit, resolve2) {
2181
+ if (explicit != null) {
2182
+ setTimeout(resolve2, explicit);
2183
+ return;
2184
+ }
2185
+ const info = getTransitionInfo(el, type);
2186
+ if (!info) {
2187
+ resolve2();
2188
+ return;
2189
+ }
2190
+ let done = false;
2191
+ const finish = () => {
2192
+ if (done) return;
2193
+ done = true;
2194
+ el.removeEventListener(info.event, onEnd);
2195
+ resolve2();
2196
+ };
2197
+ const onEnd = () => finish();
2198
+ el.addEventListener(info.event, onEnd);
2199
+ setTimeout(finish, info.timeout + 1);
2200
+ }
2201
+ function resolveDuration(d, dir) {
2202
+ if (d == null) return null;
2203
+ if (typeof d === "number") return d;
2204
+ return d[dir];
2205
+ }
2206
+ function validateSlot(value) {
2207
+ if (value == null || value === false) return null;
2208
+ if (Array.isArray(value)) {
2209
+ {
2210
+ throw new Error(
2211
+ "[essor] <Transition> expects a single root child. Use <TransitionGroup> for multiple children."
2212
+ );
2213
+ }
2214
+ }
2215
+ if (value instanceof Element) return value;
2216
+ if (isComponent(value)) {
2217
+ const comp = value;
2218
+ if (comp.scope == null) {
2219
+ const fragment = document.createDocumentFragment();
2220
+ comp.mount(fragment);
2221
+ }
2222
+ if (comp.renderedNodes.length > 1) {
2223
+ warn(
2224
+ "[Transition] child component rendered multiple root nodes; only the first is animated. Wrap the children in a single element or use <TransitionGroup>."
2225
+ );
2226
+ }
2227
+ const first = comp.firstChild;
2228
+ if (first instanceof Element) return first;
2229
+ {
2230
+ warn("[Transition] child component did not render an Element root.");
2231
+ }
2232
+ return null;
2233
+ }
2234
+ {
2235
+ warn("[Transition] received a non-element child; animation will be skipped.");
2236
+ }
2237
+ return null;
2238
+ }
2239
+ var ENTER_CB = /* @__PURE__ */ Symbol("enter_cb");
2240
+ var LEAVE_CB = /* @__PURE__ */ Symbol("leave_cb");
2241
+ function Transition(props) {
2242
+ const anchor = document.createComment("");
2243
+ const classes = resolveTransitionClasses(props);
2244
+ const useCss = props.css !== false;
2245
+ const readSlot = useChildren(props);
2246
+ let state = "idle";
2247
+ let currentEl = null;
2248
+ let leavingEl = null;
2249
+ let mounted = false;
2250
+ let pendingRaw = void 0;
2251
+ let hasPending = false;
2252
+ let scheduled = false;
2253
+ let disposed = false;
2254
+ const enter = (el, phase) => {
2255
+ var _a2;
2256
+ const prevLeave = el[LEAVE_CB];
2257
+ if (prevLeave) prevLeave(true);
2258
+ state = "entering";
2259
+ const fromCls = phase === "appear" ? classes.appearFrom : classes.enterFrom;
2260
+ const activeCls = phase === "appear" ? classes.appearActive : classes.enterActive;
2261
+ const toCls = phase === "appear" ? classes.appearTo : classes.enterTo;
2262
+ (_a2 = props.onBeforeEnter) == null ? void 0 : _a2.call(props, el);
2263
+ if (useCss) {
2264
+ addClass(el, fromCls);
2265
+ addClass(el, activeCls);
2266
+ }
2267
+ let called = false;
2268
+ const done = (cancelled) => {
2269
+ var _a3, _b;
2270
+ if (called) return;
2271
+ called = true;
2272
+ el[ENTER_CB] = void 0;
2273
+ if (useCss) {
2274
+ removeClass(el, fromCls);
2275
+ removeClass(el, activeCls);
2276
+ removeClass(el, toCls);
2277
+ }
2278
+ if (cancelled) {
2279
+ (_a3 = props.onEnterCancelled) == null ? void 0 : _a3.call(props, el);
2280
+ } else {
2281
+ state = "entered";
2282
+ (_b = props.onAfterEnter) == null ? void 0 : _b.call(props, el);
2283
+ }
2284
+ };
2285
+ el[ENTER_CB] = done;
2286
+ nextFrame(() => {
2287
+ if (called) return;
2288
+ if (useCss) {
2289
+ removeClass(el, fromCls);
2290
+ addClass(el, toCls);
2291
+ }
2292
+ if (props.onEnter) {
2293
+ props.onEnter(el, () => done(false));
2294
+ } else if (useCss) {
2295
+ const explicit = resolveDuration(props.duration, "enter");
2296
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2297
+ } else {
2298
+ done(false);
2299
+ }
2300
+ });
2301
+ };
2302
+ const leave = (el, after) => {
2303
+ var _a2;
2304
+ const prevEnter = el[ENTER_CB];
2305
+ if (prevEnter) {
2306
+ prevEnter(true);
2307
+ forceReflow(el);
2308
+ }
2309
+ state = "leaving";
2310
+ (_a2 = props.onBeforeLeave) == null ? void 0 : _a2.call(props, el);
2311
+ if (useCss) {
2312
+ addClass(el, classes.leaveFrom);
2313
+ addClass(el, classes.leaveActive);
2314
+ }
2315
+ let called = false;
2316
+ const done = (cancelled) => {
2317
+ var _a3, _b;
2318
+ if (called) return;
2319
+ called = true;
2320
+ el[LEAVE_CB] = void 0;
2321
+ if (useCss) {
2322
+ removeClass(el, classes.leaveFrom);
2323
+ removeClass(el, classes.leaveActive);
2324
+ removeClass(el, classes.leaveTo);
2325
+ }
2326
+ if (cancelled) {
2327
+ (_a3 = props.onLeaveCancelled) == null ? void 0 : _a3.call(props, el);
2328
+ } else {
2329
+ state = "idle";
2330
+ after();
2331
+ (_b = props.onAfterLeave) == null ? void 0 : _b.call(props, el);
2332
+ }
2333
+ };
2334
+ el[LEAVE_CB] = done;
2335
+ const explicit = resolveDuration(props.duration, "leave");
2336
+ const hasCssInfo = useCss && !props.onLeave && explicit == null ? !!getTransitionInfo(el, props.type) : false;
2337
+ if (!props.onLeave && explicit == null && !hasCssInfo) {
2338
+ done(false);
2339
+ return;
2340
+ }
2341
+ nextFrame(() => {
2342
+ if (called) return;
2343
+ if (useCss) {
2344
+ removeClass(el, classes.leaveFrom);
2345
+ addClass(el, classes.leaveTo);
2346
+ }
2347
+ if (props.onLeave) {
2348
+ props.onLeave(el, () => done(false));
2349
+ } else if (useCss) {
2350
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2351
+ } else {
2352
+ done(false);
2353
+ }
2354
+ });
2355
+ };
2356
+ const commit = (next2, isFirst) => {
2357
+ if (next2 && state === "leaving" && leavingEl) {
2358
+ const reviving = leavingEl;
2359
+ const leaveCb = reviving[LEAVE_CB];
2360
+ if (leaveCb) leaveCb(true);
2361
+ leavingEl = null;
2362
+ currentEl = reviving;
2363
+ enter(reviving, "enter");
2364
+ return;
2365
+ }
2366
+ if (next2 === currentEl) return;
2367
+ const outgoing = currentEl;
2368
+ currentEl = next2;
2369
+ if (outgoing) {
2370
+ leavingEl = outgoing;
2371
+ const captured = outgoing;
2372
+ leave(captured, () => {
2373
+ if (captured.parentNode) captured.parentNode.removeChild(captured);
2374
+ if (leavingEl === captured) leavingEl = null;
2375
+ });
2376
+ }
2377
+ if (next2 && anchor.parentNode) {
2378
+ anchor.parentNode.insertBefore(next2, anchor);
2379
+ if (isFirst && !props.appear) {
2380
+ state = "entered";
2381
+ } else {
2382
+ enter(next2, isFirst && props.appear ? "appear" : "enter");
2383
+ }
2384
+ } else if (!outgoing && !next2) {
2385
+ state = "idle";
2386
+ }
2387
+ };
2388
+ const flush = () => {
2389
+ scheduled = false;
2390
+ if (disposed || !hasPending) return;
2391
+ const raw = pendingRaw;
2392
+ hasPending = false;
2393
+ pendingRaw = void 0;
2394
+ try {
2395
+ commit(validateSlot(raw), false);
2396
+ } catch (error4) {
2397
+ console.error("[essor] <Transition>", error4);
2398
+ }
2399
+ };
2400
+ const scheduleCommit = (raw) => {
2401
+ pendingRaw = raw;
2402
+ hasPending = true;
2403
+ if (scheduled) return;
2404
+ scheduled = true;
2405
+ queueMicrotask(flush);
2406
+ };
2407
+ const effectRunner = effect(() => {
2408
+ const raw = readSlot();
2409
+ if (mounted) {
2410
+ scheduleCommit(raw);
2411
+ } else {
2412
+ pendingRaw = raw;
2413
+ hasPending = true;
2414
+ }
2415
+ });
2416
+ onMount(() => {
2417
+ mounted = true;
2418
+ const initial = hasPending ? validateSlot(pendingRaw) : null;
2419
+ hasPending = false;
2420
+ pendingRaw = void 0;
2421
+ commit(initial, true);
2422
+ });
2423
+ onCleanup(() => {
2424
+ disposed = true;
2425
+ effectRunner.stop();
2426
+ for (const el of [currentEl, leavingEl]) {
2427
+ if (!el) continue;
2428
+ const ec = el[ENTER_CB];
2429
+ const lc = el[LEAVE_CB];
2430
+ ec == null ? void 0 : ec(true);
2431
+ lc == null ? void 0 : lc(true);
2432
+ if (el.parentNode) el.parentNode.removeChild(el);
2433
+ }
2434
+ currentEl = null;
2435
+ leavingEl = null;
2436
+ state = "idle";
2437
+ });
2438
+ return anchor;
2439
+ }
2440
+ Transition[TRANSITION_COMPONENT] = true;
2441
+ function isTransition(node) {
2442
+ return !!node && !!node[TRANSITION_COMPONENT];
2443
+ }
2444
+ function resolveItemElement(raw, parent) {
2445
+ if (raw == null || raw === false) return { el: null, comp: null };
2446
+ if (Array.isArray(raw) && raw.length === 1) {
2447
+ return resolveItemElement(raw[0], parent);
2448
+ }
2449
+ if (isFunction(raw)) {
2450
+ return resolveItemElement(raw(), parent);
2451
+ }
2452
+ if (raw instanceof HTMLElement) {
2453
+ return { el: raw, comp: null };
2454
+ }
2455
+ if (isComponent(raw)) {
2456
+ const comp = raw;
2457
+ if (comp.scope == null) {
2458
+ comp.mount(parent);
2459
+ }
2460
+ if (comp.renderedNodes.length > 1) {
2461
+ warn(
2462
+ "[TransitionGroup] child component rendered multiple root nodes; only the first participates in enter/leave/move animations."
2463
+ );
2464
+ }
2465
+ const first = comp.firstChild;
2466
+ if (first instanceof HTMLElement) return { el: first, comp };
2467
+ return { el: null, comp };
2468
+ }
2469
+ {
2470
+ warn(
2471
+ "[TransitionGroup] child render returned a non-element value; animations require Element or Component roots."
2472
+ );
2473
+ }
2474
+ return { el: null, comp: null };
2475
+ }
2476
+ function saveStyles(el) {
2477
+ return {
2478
+ position: el.style.position,
2479
+ top: el.style.top,
2480
+ left: el.style.left,
2481
+ width: el.style.width,
2482
+ height: el.style.height
2483
+ };
2484
+ }
2485
+ function restoreStyles(el, s) {
2486
+ el.style.position = s.position;
2487
+ el.style.top = s.top;
2488
+ el.style.left = s.left;
2489
+ el.style.width = s.width;
2490
+ el.style.height = s.height;
2491
+ }
2492
+ function TransitionGroup(props) {
2493
+ var _a2, _b, _c;
2494
+ const tag = (_a2 = props.tag) != null ? _a2 : "div";
2495
+ const wrapper = document.createElement(tag);
2496
+ const classes = resolveTransitionClasses(props);
2497
+ const useCss = props.css !== false;
2498
+ const moveClass = (_c = props.moveClass) != null ? _c : `${(_b = props.name) != null ? _b : "v"}-move`;
2499
+ const keyFn = props.key;
2500
+ const rawChildren = props.children;
2501
+ const childrenFn = Array.isArray(rawChildren) && rawChildren.length === 1 && isFunction(rawChildren[0]) ? rawChildren[0] : props.children;
2502
+ if (!isFunction(childrenFn) || !isFunction(keyFn)) {
2503
+ throw new TypeError(
2504
+ "<TransitionGroup> requires `children: (item, index) => Node` and `key: (item, index) => unknown`"
2505
+ );
2506
+ }
2507
+ const getList = () => {
2508
+ var _a3, _b2;
2509
+ const input = props.each;
2510
+ if (isSignal(input)) return (_a3 = input.value) != null ? _a3 : [];
2511
+ if (isFunction(input)) return (_b2 = input()) != null ? _b2 : [];
2512
+ return input != null ? input : [];
2513
+ };
2514
+ let entries = [];
2515
+ let mounted = false;
2516
+ const renderEntry = (item, index) => {
2517
+ const parentScope = getActiveScope();
2518
+ const scope = createScope(parentScope);
2519
+ let raw;
2520
+ runWithScope(scope, () => {
2521
+ raw = childrenFn(item, index);
2522
+ });
2523
+ const { el, comp } = resolveItemElement(raw, wrapper);
2524
+ if (!el) {
2525
+ disposeScope(scope);
2526
+ return null;
2527
+ }
2528
+ return {
2529
+ key: keyFn(item, index),
2530
+ item,
2531
+ el,
2532
+ comp,
2533
+ scope,
2534
+ state: "entering"
2535
+ };
2536
+ };
2537
+ const detachEntryDom = (entry) => {
2538
+ if (entry.comp) {
2539
+ for (const node of entry.comp.renderedNodes) {
2540
+ if (node.parentNode === wrapper) wrapper.removeChild(node);
2541
+ }
2542
+ return;
2543
+ }
2544
+ if (entry.el.parentNode === wrapper) wrapper.removeChild(entry.el);
2545
+ };
2546
+ const disposeEntry = (entry) => {
2547
+ var _a3, _b2;
2548
+ (_a3 = entry.cancelEnter) == null ? void 0 : _a3.call(entry, true);
2549
+ (_b2 = entry.cancelLeave) == null ? void 0 : _b2.call(entry, true);
2550
+ if (entry.comp) entry.comp.destroy();
2551
+ detachEntryDom(entry);
2552
+ disposeScope(entry.scope);
2553
+ };
2554
+ const runEnter = (entry) => {
2555
+ var _a3, _b2, _c2;
2556
+ const el = entry.el;
2557
+ (_a3 = entry.cancelLeave) == null ? void 0 : _a3.call(entry, true);
2558
+ if (!useCss) {
2559
+ entry.state = "present";
2560
+ (_b2 = props.onAfterEnter) == null ? void 0 : _b2.call(props, el);
2561
+ return;
2562
+ }
2563
+ (_c2 = props.onBeforeEnter) == null ? void 0 : _c2.call(props, el);
2564
+ addClass(el, classes.enterFrom);
2565
+ addClass(el, classes.enterActive);
2566
+ let called = false;
2567
+ const done = (cancelled) => {
2568
+ var _a4, _b3;
2569
+ if (called) return;
2570
+ called = true;
2571
+ entry.cancelEnter = void 0;
2572
+ removeClass(el, classes.enterFrom);
2573
+ removeClass(el, classes.enterActive);
2574
+ removeClass(el, classes.enterTo);
2575
+ if (cancelled) {
2576
+ (_a4 = props.onEnterCancelled) == null ? void 0 : _a4.call(props, el);
2577
+ } else {
2578
+ entry.state = "present";
2579
+ (_b3 = props.onAfterEnter) == null ? void 0 : _b3.call(props, el);
2580
+ }
2581
+ };
2582
+ entry.cancelEnter = done;
2583
+ entry.state = "entering";
2584
+ nextFrame(() => {
2585
+ if (called) return;
2586
+ removeClass(el, classes.enterFrom);
2587
+ addClass(el, classes.enterTo);
2588
+ if (props.onEnter) {
2589
+ props.onEnter(el, () => done(false));
2590
+ } else {
2591
+ const explicit = resolveDuration(props.duration, "enter");
2592
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2593
+ }
2594
+ });
2595
+ };
2596
+ const runLeave = (entry, prevRect) => {
2597
+ var _a3, _b2;
2598
+ const el = entry.el;
2599
+ if (entry.cancelEnter) {
2600
+ entry.cancelEnter(true);
2601
+ forceReflow(el);
2602
+ }
2603
+ entry.state = "leaving";
2604
+ entry.savedStyles = saveStyles(el);
2605
+ const parentRect = wrapper.getBoundingClientRect();
2606
+ el.style.position = "absolute";
2607
+ el.style.top = `${prevRect.top - parentRect.top}px`;
2608
+ el.style.left = `${prevRect.left - parentRect.left}px`;
2609
+ el.style.width = `${prevRect.width}px`;
2610
+ el.style.height = `${prevRect.height}px`;
2611
+ if (!useCss) {
2612
+ if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
2613
+ detachEntryDom(entry);
2614
+ disposeScope(entry.scope);
2615
+ if (entry.comp) entry.comp.destroy();
2616
+ (_a3 = props.onAfterLeave) == null ? void 0 : _a3.call(props, el);
2617
+ return;
2618
+ }
2619
+ (_b2 = props.onBeforeLeave) == null ? void 0 : _b2.call(props, el);
2620
+ addClass(el, classes.leaveFrom);
2621
+ addClass(el, classes.leaveActive);
2622
+ let called = false;
2623
+ const done = (cancelled) => {
2624
+ var _a4, _b3;
2625
+ if (called) return;
2626
+ called = true;
2627
+ entry.cancelLeave = void 0;
2628
+ removeClass(el, classes.leaveFrom);
2629
+ removeClass(el, classes.leaveActive);
2630
+ removeClass(el, classes.leaveTo);
2631
+ if (cancelled) {
2632
+ if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
2633
+ entry.savedStyles = void 0;
2634
+ (_a4 = props.onLeaveCancelled) == null ? void 0 : _a4.call(props, el);
2635
+ return;
2636
+ }
2637
+ if (entry.savedStyles) restoreStyles(el, entry.savedStyles);
2638
+ entry.savedStyles = void 0;
2639
+ detachEntryDom(entry);
2640
+ disposeScope(entry.scope);
2641
+ if (entry.comp) entry.comp.destroy();
2642
+ (_b3 = props.onAfterLeave) == null ? void 0 : _b3.call(props, el);
2643
+ };
2644
+ entry.cancelLeave = done;
2645
+ nextFrame(() => {
2646
+ if (called) return;
2647
+ removeClass(el, classes.leaveFrom);
2648
+ addClass(el, classes.leaveTo);
2649
+ if (props.onLeave) {
2650
+ props.onLeave(el, () => done(false));
2651
+ } else {
2652
+ const explicit = resolveDuration(props.duration, "leave");
2653
+ whenTransitionEnds(el, props.type, explicit, () => done(false));
2654
+ }
2655
+ });
2656
+ };
2657
+ const runMove = (entry, prevRect) => {
2658
+ if (!useCss || entry.state !== "present") return;
2659
+ const el = entry.el;
2660
+ const newRect = el.getBoundingClientRect();
2661
+ const dx = prevRect.left - newRect.left;
2662
+ const dy = prevRect.top - newRect.top;
2663
+ if (!dx && !dy) return;
2664
+ const savedTransform = el.style.transform;
2665
+ const savedTransition = el.style.transitionDuration;
2666
+ el.style.transform = `translate(${dx}px, ${dy}px)`;
2667
+ el.style.transitionDuration = "0s";
2668
+ addClass(el, moveClass);
2669
+ forceReflow(el);
2670
+ el.style.transform = savedTransform;
2671
+ el.style.transitionDuration = savedTransition;
2672
+ const explicit = resolveDuration(props.duration, "enter");
2673
+ whenTransitionEnds(el, props.type, explicit, () => {
2674
+ removeClass(el, moveClass);
2675
+ });
2676
+ };
2677
+ const snapshotPositions = () => {
2678
+ for (const entry of entries) {
2679
+ if (entry.state === "leaving") continue;
2680
+ entry.prevRect = entry.el.getBoundingClientRect();
2681
+ }
2682
+ };
2683
+ const reconcile = (newItems) => {
2684
+ const byKey = /* @__PURE__ */ new Map();
2685
+ for (const entry of entries) byKey.set(entry.key, entry);
2686
+ const next2 = [];
2687
+ for (const [i, item] of newItems.entries()) {
2688
+ const key = keyFn(item, i);
2689
+ const reused = byKey.get(key);
2690
+ if (reused) {
2691
+ byKey.delete(key);
2692
+ reused.item = item;
2693
+ next2.push(reused);
2694
+ } else {
2695
+ const fresh = renderEntry(item, i);
2696
+ if (fresh) next2.push(fresh);
2697
+ }
2698
+ }
2699
+ const leaving = [];
2700
+ for (const entry of byKey.values()) {
2701
+ if (entry.state !== "leaving") leaving.push(entry);
2702
+ }
2703
+ let anchor = null;
2704
+ for (let i = next2.length - 1; i >= 0; i--) {
2705
+ const el = next2[i].el;
2706
+ if (el.parentNode !== wrapper || el.nextSibling !== anchor) {
2707
+ wrapper.insertBefore(el, anchor);
2708
+ }
2709
+ anchor = el;
2710
+ }
2711
+ return { next: next2, leaving };
2712
+ };
2713
+ const update = (newItems, isInitial) => {
2714
+ if (isInitial) {
2715
+ const initial = [];
2716
+ for (const [i, item] of newItems.entries()) {
2717
+ const entry = renderEntry(item, i);
2718
+ if (!entry) continue;
2719
+ if (entry.el.parentNode !== wrapper) wrapper.appendChild(entry.el);
2720
+ entry.state = "present";
2721
+ initial.push(entry);
2722
+ }
2723
+ entries = initial;
2724
+ return;
2725
+ }
2726
+ snapshotPositions();
2727
+ const { next: next2, leaving } = reconcile(newItems);
2728
+ for (const entry of next2) {
2729
+ if (entry.state !== "present") runEnter(entry);
2730
+ }
2731
+ for (const entry of leaving) {
2732
+ const rect = entry.prevRect;
2733
+ if (!rect) {
2734
+ {
2735
+ warn("[TransitionGroup] leaving entry without prevRect \u2014 skipping leave animation");
2736
+ }
2737
+ continue;
2738
+ }
2739
+ runLeave(entry, rect);
2740
+ }
2741
+ for (const entry of next2) {
2742
+ if (entry.state !== "present" || !entry.prevRect) continue;
2743
+ runMove(entry, entry.prevRect);
2744
+ entry.prevRect = void 0;
2745
+ }
2746
+ entries = next2.concat(leaving);
2747
+ };
2748
+ let pendingItems = null;
2749
+ const effectRunner = effect(() => {
2750
+ const list = getList();
2751
+ if (!mounted) {
2752
+ pendingItems = list;
2753
+ return;
2754
+ }
2755
+ update(list, false);
2756
+ });
2757
+ onMount(() => {
2758
+ mounted = true;
2759
+ if (pendingItems) {
2760
+ update(pendingItems, true);
2761
+ pendingItems = null;
2762
+ }
2763
+ });
2764
+ onCleanup(() => {
2765
+ effectRunner.stop();
2766
+ for (const entry of entries) disposeEntry(entry);
2767
+ entries = [];
2768
+ if (wrapper.parentNode) wrapper.parentNode.removeChild(wrapper);
2769
+ });
2770
+ return wrapper;
2771
+ }
2772
+ TransitionGroup[TRANSITION_GROUP_COMPONENT] = true;
2773
+ function isTransitionGroup(node) {
2774
+ return !!node && !!node[TRANSITION_GROUP_COMPONENT];
2775
+ }
1998
2776
 
1999
- export { Component, For, Fragment, Portal, Suspense, addEvent, addEventListener, beginHydration, bindElement, child, clearDelegatedEvents, consumeTeleportAnchor, consumeTeleportBlock, createApp, createComponent, createResource, defineAsyncComponent, delegateEvents, endHydration, getHydrationKey, getRenderedElement, hydrate, inject, insert, isComponent, isFragment, isHydrating, isPortal, isSuspense, next, normalizeClass, nthChild, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchAttrHydrate, patchClass, patchClassHydrate, patchStyle, patchStyleHydrate, provide, resetHydrationKey, setStyle, template };
2000
- //# sourceMappingURL=template.dev.esm.js.map
2001
- //# sourceMappingURL=template.dev.esm.js.map
2777
+ export { Component, For, Fragment, Portal, Suspense, Transition, TransitionGroup, addEvent, addEventListener, beginHydration, bindElement, child, clearDelegatedEvents, consumeTeleportAnchor, consumeTeleportBlock, createApp, createComponent, createResource, defineAsyncComponent, delegateEvents, endHydration, getHydrationKey, getRenderedElement, hydrate, hydrationAnchor, hydrationMarker, inject, insert, isComponent, isFragment, isHydrating, isPortal, isSuspense, isTransition, isTransitionGroup, next, normalizeClass, nthChild, omitProps, onDestroy, onMount, onUpdate, patchAttr, patchAttrHydrate, patchClass, patchClassHydrate, patchStyle, patchStyleHydrate, provide, resetHydrationKey, setStyle, template };
2778
+ //# sourceMappingURL=template.dev.js.map
2779
+ //# sourceMappingURL=template.dev.js.map