@zeus-js/runtime-dom 0.1.1-beta.0 → 0.1.1-beta.10

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,16 +1,27 @@
1
1
  /**
2
- * runtime-dom v0.1.1-beta.0
2
+ * runtime-dom v0.1.1-beta.10
3
3
  * (c) 2026 baicie
4
4
  * Released under the MIT License.
5
5
  **/
6
6
  //#region packages/core/runtime-dom/src/template.ts
7
- function template(html, _isImportNode = false, _isSVG = false, _isMathML = false) {
8
- const t = document.createElement("template");
9
- t.innerHTML = html;
7
+ function template(html, _isImportNode = false, isSVG = false, _isMathML = false) {
8
+ const content = isSVG ? createSvgContent(html) : createHtmlContent(html);
10
9
  return function clone() {
11
- return t.content.cloneNode(true);
10
+ return content.cloneNode(true);
12
11
  };
13
12
  }
13
+ function createHtmlContent(html) {
14
+ const template = document.createElement("template");
15
+ template.innerHTML = html;
16
+ return template.content;
17
+ }
18
+ function createSvgContent(html) {
19
+ const wrapper = document.createElementNS("http://www.w3.org/2000/svg", "svg");
20
+ wrapper.innerHTML = html;
21
+ const content = document.createDocumentFragment();
22
+ while (wrapper.firstChild) content.appendChild(wrapper.firstChild);
23
+ return content;
24
+ }
14
25
  //#endregion
15
26
  //#region packages/core/shared/src/makeMap.ts
16
27
  /**
@@ -267,7 +278,8 @@ var ReactiveEffect = class {
267
278
  trigger() {
268
279
  if (this.flags & 64) pausedQueueEffects.add(this);
269
280
  else if (this.scheduler) this.scheduler();
270
- else this.runIfDirty();
281
+ else if (this.flags & 128) this.runIfDirty();
282
+ else this.run();
271
283
  }
272
284
  /**
273
285
  * @internal
@@ -493,6 +505,31 @@ function cleanupEffect(e) {
493
505
  }
494
506
  }
495
507
  }
508
+ /**
509
+ * Batches reactive updates synchronously within the given function.
510
+ * All updates triggered inside `fn` are deferred until the function completes,
511
+ * then flushed together in a single batch.
512
+ */
513
+ function batch(fn) {
514
+ startBatch();
515
+ try {
516
+ return fn();
517
+ } finally {
518
+ endBatch();
519
+ }
520
+ }
521
+ /**
522
+ * Executes the given function without tracking reactive dependencies.
523
+ * Any reactive reads inside `fn` will not trigger effect re-runs.
524
+ */
525
+ function untrack(fn) {
526
+ pauseTracking();
527
+ try {
528
+ return fn();
529
+ } finally {
530
+ resetTracking();
531
+ }
532
+ }
496
533
  //#endregion
497
534
  //#region packages/core/signal/src/dep.ts
498
535
  /**
@@ -537,6 +574,7 @@ var Dep = class {
537
574
  }
538
575
  track(debugInfo) {
539
576
  if (!activeSub || !shouldTrack || activeSub === this.computed) return;
577
+ if (this.computed) activeSub.flags |= 128;
540
578
  let link = this.activeLink;
541
579
  if (link === void 0 || link.sub !== activeSub) {
542
580
  link = this.activeLink = new Link(activeSub, this);
@@ -870,60 +908,6 @@ function noTracking(self, method, args = []) {
870
908
  return res;
871
909
  }
872
910
  //#endregion
873
- //#region packages/core/signal/src/ref.ts
874
- let _ReactiveFlags$IS_REF, _ReactiveFlags$IS_SHA;
875
- /*@__NO_SIDE_EFFECTS__*/
876
- function isRef(r) {
877
- return r ? r["__v_isRef"] === true : false;
878
- }
879
- /*@__NO_SIDE_EFFECTS__*/
880
- function ref(value) {
881
- return createRef(value, false);
882
- }
883
- function createRef(rawValue, shallow) {
884
- if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
885
- return new RefImpl(rawValue, shallow);
886
- }
887
- _ReactiveFlags$IS_REF = "__v_isRef";
888
- _ReactiveFlags$IS_SHA = "__v_isShallow";
889
- /**
890
- * @internal
891
- */
892
- var RefImpl = class {
893
- constructor(value, isShallow) {
894
- this.dep = new Dep();
895
- this[_ReactiveFlags$IS_REF] = true;
896
- this[_ReactiveFlags$IS_SHA] = false;
897
- this._rawValue = isShallow ? value : /* @__PURE__ */ toRaw(value);
898
- this._value = isShallow ? value : toReactive(value);
899
- this["__v_isShallow"] = isShallow;
900
- }
901
- get value() {
902
- this.dep.track({
903
- target: this,
904
- type: "get",
905
- key: "value"
906
- });
907
- return this._value;
908
- }
909
- set value(newValue) {
910
- const oldValue = this._rawValue;
911
- const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
912
- newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
913
- if (hasChanged(newValue, oldValue)) {
914
- this._rawValue = newValue;
915
- this._value = useDirectValue ? newValue : toReactive(newValue);
916
- this.dep.trigger({
917
- target: this,
918
- type: "set",
919
- key: "value",
920
- newValue,
921
- oldValue
922
- });
923
- }
924
- }
925
- };
926
- //#endregion
927
911
  //#region packages/core/signal/src/baseHandlers.ts
928
912
  const isNonTrackableKeys = /*@__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
929
913
  const builtInSymbols = new Set(/*@__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
@@ -1356,11 +1340,84 @@ const toReactive = (value) => isObject(value) ? /* @__PURE__ */ reactive(value)
1356
1340
  */
1357
1341
  const toReadonly = (value) => isObject(value) ? /* @__PURE__ */ readonly(value) : value;
1358
1342
  //#endregion
1343
+ //#region packages/core/signal/src/ref.ts
1344
+ let _ReactiveFlags$IS_REF, _ReactiveFlags$IS_SHA;
1345
+ /*@__NO_SIDE_EFFECTS__*/
1346
+ function isRef(r) {
1347
+ return r ? r["__v_isRef"] === true : false;
1348
+ }
1349
+ /*@__NO_SIDE_EFFECTS__*/
1350
+ function ref(value) {
1351
+ return createRef(value, false);
1352
+ }
1353
+ /*@__NO_SIDE_EFFECTS__*/
1354
+ function shallowRef(value) {
1355
+ return createRef(value, true);
1356
+ }
1357
+ function createRef(rawValue, shallow) {
1358
+ if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
1359
+ return new RefImpl(rawValue, shallow);
1360
+ }
1361
+ _ReactiveFlags$IS_REF = "__v_isRef";
1362
+ _ReactiveFlags$IS_SHA = "__v_isShallow";
1363
+ /**
1364
+ * @internal
1365
+ */
1366
+ var RefImpl = class {
1367
+ constructor(value, isShallow) {
1368
+ this.dep = new Dep();
1369
+ this[_ReactiveFlags$IS_REF] = true;
1370
+ this[_ReactiveFlags$IS_SHA] = false;
1371
+ this._rawValue = isShallow ? value : /* @__PURE__ */ toRaw(value);
1372
+ this._value = isShallow ? value : toReactive(value);
1373
+ this["__v_isShallow"] = isShallow;
1374
+ }
1375
+ get value() {
1376
+ this.dep.track({
1377
+ target: this,
1378
+ type: "get",
1379
+ key: "value"
1380
+ });
1381
+ return this._value;
1382
+ }
1383
+ set value(newValue) {
1384
+ const oldValue = this._rawValue;
1385
+ const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
1386
+ newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
1387
+ if (hasChanged(newValue, oldValue)) {
1388
+ this._rawValue = newValue;
1389
+ this._value = useDirectValue ? newValue : toReactive(newValue);
1390
+ this.dep.trigger({
1391
+ target: this,
1392
+ type: "set",
1393
+ key: "value",
1394
+ newValue,
1395
+ oldValue
1396
+ });
1397
+ }
1398
+ }
1399
+ };
1400
+ //#endregion
1401
+ //#region packages/core/signal/src/primitives.ts
1402
+ function createSignal(initialValue) {
1403
+ const source = /* @__PURE__ */ shallowRef(initialValue);
1404
+ const read = () => source.value;
1405
+ const write = (value) => {
1406
+ const next = typeof value === "function" ? value(source.value) : value;
1407
+ source.value = next;
1408
+ return next;
1409
+ };
1410
+ return [read, write];
1411
+ }
1412
+ //#endregion
1359
1413
  //#region packages/core/signal/src/state.ts
1360
1414
  function state(value) {
1361
1415
  if (arguments.length === 0) return /* @__PURE__ */ ref();
1362
1416
  return isProxyable(value) ? /* @__PURE__ */ reactive(value) : /* @__PURE__ */ ref(value);
1363
1417
  }
1418
+ function shallowState(value) {
1419
+ return arguments.length === 0 ? /* @__PURE__ */ shallowRef() : /* @__PURE__ */ shallowRef(value);
1420
+ }
1364
1421
  function isProxyable(value) {
1365
1422
  if (value === null || typeof value !== "object") return false;
1366
1423
  if (Array.isArray(value)) return true;
@@ -1372,6 +1429,32 @@ function isPlainObject(value) {
1372
1429
  return proto === Object.prototype || proto === null;
1373
1430
  }
1374
1431
  //#endregion
1432
+ //#region packages/core/runtime-dom/src/domMove.ts
1433
+ const activeMoveRoots = /* @__PURE__ */ new Set();
1434
+ function moveNodeBefore(parent, node, marker) {
1435
+ activeMoveRoots.add(node);
1436
+ try {
1437
+ const moveBefore = parent.moveBefore;
1438
+ if (typeof moveBefore === "function") moveBefore.call(parent, node, marker);
1439
+ else parent.insertBefore(node, marker);
1440
+ } finally {
1441
+ activeMoveRoots.delete(node);
1442
+ }
1443
+ }
1444
+ function isWithinRuntimeDomMove(node) {
1445
+ let current = node;
1446
+ while (current) {
1447
+ if (activeMoveRoots.has(current)) return true;
1448
+ if (current.parentNode) {
1449
+ current = current.parentNode;
1450
+ continue;
1451
+ }
1452
+ const root = current.getRootNode();
1453
+ current = "host" in root ? root.host : null;
1454
+ }
1455
+ return false;
1456
+ }
1457
+ //#endregion
1375
1458
  //#region packages/core/runtime-dom/src/domOwnership.ts
1376
1459
  const activeLightDomHosts = /* @__PURE__ */ new WeakMap();
1377
1460
  const runtimeOwnedNodes = /* @__PURE__ */ new WeakSet();
@@ -1406,6 +1489,14 @@ function insertTracked(parent, value, marker = null) {
1406
1489
  for (const item of value) nodes.push(...insertTracked(parent, item, marker));
1407
1490
  return nodes;
1408
1491
  }
1492
+ if (value instanceof Node && value.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
1493
+ const nodes = Array.from(value.childNodes);
1494
+ for (const node of nodes) {
1495
+ trackRuntimeDomInsertion(parent, node);
1496
+ parent.insertBefore(node, marker);
1497
+ }
1498
+ return nodes;
1499
+ }
1409
1500
  const node = value instanceof Node ? value : document.createTextNode(String(value));
1410
1501
  trackRuntimeDomInsertion(parent, node);
1411
1502
  parent.insertBefore(node, marker);
@@ -1420,7 +1511,7 @@ function removeNodes$1(nodes) {
1420
1511
  function moveRangeBefore(nodes, parent, marker = null) {
1421
1512
  for (const node of nodes) {
1422
1513
  trackRuntimeDomInsertion(parent, node);
1423
- parent.insertBefore(node, marker);
1514
+ moveNodeBefore(parent, node, marker);
1424
1515
  }
1425
1516
  }
1426
1517
  //#endregion
@@ -1465,10 +1556,11 @@ var ScopedSubtree = class {
1465
1556
  replace(render) {
1466
1557
  this.dispose();
1467
1558
  const scope = effectScope(true);
1559
+ const parent = this.resolveParent(this.marker);
1468
1560
  let nodes = [];
1469
1561
  try {
1470
1562
  scope.run(() => {
1471
- nodes = runWithOwner(this.context.owner, () => withHostContext(this.context.host, () => insertTracked(this.parent, render(), this.marker)));
1563
+ nodes = runWithOwner(this.context.owner, () => withHostContext(this.context.host, () => insertTracked(parent, render(), this.marker)));
1472
1564
  });
1473
1565
  } catch (error) {
1474
1566
  scope.stop();
@@ -1486,11 +1578,15 @@ var ScopedSubtree = class {
1486
1578
  this.nodes = [];
1487
1579
  }
1488
1580
  moveBefore(marker) {
1489
- moveRangeBefore(this.nodes, this.parent, marker);
1581
+ moveRangeBefore(this.nodes, this.resolveParent(marker), marker);
1490
1582
  }
1491
1583
  current() {
1492
1584
  return this.nodes;
1493
1585
  }
1586
+ resolveParent(marker) {
1587
+ var _ref, _marker$parentNode, _this$marker;
1588
+ return (_ref = (_marker$parentNode = marker === null || marker === void 0 ? void 0 : marker.parentNode) !== null && _marker$parentNode !== void 0 ? _marker$parentNode : (_this$marker = this.marker) === null || _this$marker === void 0 ? void 0 : _this$marker.parentNode) !== null && _ref !== void 0 ? _ref : this.parent;
1589
+ }
1494
1590
  };
1495
1591
  //#endregion
1496
1592
  //#region packages/core/runtime-dom/src/insert.ts
@@ -1700,14 +1796,23 @@ function removeNodes(nodes) {
1700
1796
  }
1701
1797
  //#endregion
1702
1798
  //#region packages/core/runtime-dom/src/bindings.ts
1703
- function bindText(node, value) {
1704
- effect(() => {
1705
- node.data = stringifyText(value());
1799
+ function bindText(node, value, once = false) {
1800
+ applyBinding(value, once, (next) => {
1801
+ node.data = stringifyText(next);
1802
+ });
1803
+ }
1804
+ function bindTextContent(el, value, once = false) {
1805
+ applyBinding(value, once, (next) => {
1806
+ el.textContent = stringifyText(next);
1706
1807
  });
1707
1808
  }
1708
- function bindTextContent(el, value) {
1809
+ function applyBinding(value, once, apply) {
1810
+ if (once) {
1811
+ untrack(() => apply(value()));
1812
+ return;
1813
+ }
1709
1814
  effect(() => {
1710
- el.textContent = stringifyText(value());
1815
+ apply(value());
1711
1816
  });
1712
1817
  }
1713
1818
  function stringifyText(value) {
@@ -1760,19 +1865,19 @@ const BOOLEAN_DOM_PROPERTY_NAME = {
1760
1865
  function normalizeAttrName(name) {
1761
1866
  return name === "className" ? "class" : name;
1762
1867
  }
1763
- function bindAttr(el, name, value) {
1764
- effect(() => {
1765
- setAttr(el, name, value());
1868
+ function bindAttr(el, name, value, once = false) {
1869
+ applyBinding(value, once, (next) => {
1870
+ setAttr(el, name, next);
1766
1871
  });
1767
1872
  }
1768
- function bindProp(el, name, value) {
1769
- effect(() => {
1770
- el[name] = value();
1873
+ function bindProp(el, name, value, once = false) {
1874
+ applyBinding(value, once, (next) => {
1875
+ el[name] = next;
1771
1876
  });
1772
1877
  }
1773
- function bindClass(el, value) {
1774
- effect(() => {
1775
- const next = normalizeClass(value());
1878
+ function bindClass(el, value, once = false) {
1879
+ applyBinding(value, once, (value) => {
1880
+ const next = normalizeClass(value);
1776
1881
  if (next) el.setAttribute("class", next);
1777
1882
  else el.removeAttribute("class");
1778
1883
  });
@@ -1784,10 +1889,9 @@ function normalizeClass(value) {
1784
1889
  if (typeof value === "object") return Object.keys(value).filter((key) => value[key]).join(" ");
1785
1890
  return "";
1786
1891
  }
1787
- function bindStyle(el, value) {
1892
+ function bindStyle(el, value, once = false) {
1788
1893
  let prev;
1789
- effect(() => {
1790
- const next = value();
1894
+ applyBinding(value, once, (next) => {
1791
1895
  if (next == null) {
1792
1896
  el.removeAttribute("style");
1793
1897
  prev = void 0;
@@ -1798,42 +1902,41 @@ function bindStyle(el, value) {
1798
1902
  prev = void 0;
1799
1903
  return;
1800
1904
  }
1801
- patchStyle(el, prev, next);
1802
- prev = next;
1905
+ prev = patchStyle(el, prev, next);
1803
1906
  });
1804
1907
  }
1805
1908
  function patchStyle(el, prev, next) {
1806
1909
  const style = el.style;
1807
- if (prev) {
1808
- for (const key in prev) if (!(key in next)) style.setProperty(toKebabCase$2(key), "");
1910
+ const values = prev ? prev[0] : Object.create(null);
1911
+ const state = style.cssText + Object.keys(next);
1912
+ const styleChanged = prev && state != prev[1];
1913
+ for (const key in values) if (!(key in next)) {
1914
+ style.setProperty(key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`), "");
1915
+ delete values[key];
1809
1916
  }
1810
1917
  for (const key in next) {
1811
1918
  const value = next[key];
1812
- const name = toKebabCase$2(key);
1813
- if (value == null) style.setProperty(name, "");
1814
- else style.setProperty(name, normalizeStyleValue(key, value));
1919
+ const expected = value == null ? "" : normalizeStyleValue(key, value);
1920
+ if (values[key] === expected && !styleChanged) continue;
1921
+ style.setProperty(key.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`), expected);
1922
+ values[key] = expected;
1815
1923
  }
1924
+ return [values, style.cssText + Object.keys(next)];
1816
1925
  }
1817
1926
  function normalizeStyleValue(key, value) {
1818
- if (typeof value === "number" && value !== 0 && !isUnitlessNumber(key)) return `${value}px`;
1927
+ if (typeof value === "number" && value !== 0 && unitlessNumbers[key] !== true) return `${value}px`;
1819
1928
  return String(value);
1820
1929
  }
1821
- const unitlessNumbers = /* @__PURE__ */ new Set([
1822
- "opacity",
1823
- "zIndex",
1824
- "fontWeight",
1825
- "lineHeight",
1826
- "flex",
1827
- "flexGrow",
1828
- "flexShrink",
1829
- "order"
1830
- ]);
1831
- function isUnitlessNumber(key) {
1832
- return unitlessNumbers.has(key);
1833
- }
1834
- function toKebabCase$2(value) {
1835
- return value.replace(/[A-Z]/g, (match) => `-${match.toLowerCase()}`);
1836
- }
1930
+ const unitlessNumbers = {
1931
+ opacity: true,
1932
+ zIndex: true,
1933
+ fontWeight: true,
1934
+ lineHeight: true,
1935
+ flex: true,
1936
+ flexGrow: true,
1937
+ flexShrink: true,
1938
+ order: true
1939
+ };
1837
1940
  //#endregion
1838
1941
  //#region packages/core/runtime-dom/src/events.ts
1839
1942
  const delegatedEvents = /* @__PURE__ */ new Set();
@@ -1943,6 +2046,30 @@ function createComponent(component, props) {
1943
2046
  function disposeListRecord(record) {
1944
2047
  record.subtree.dispose();
1945
2048
  }
2049
+ function isImmediatelyBefore(record, anchor) {
2050
+ const nodes = record.subtree.current();
2051
+ const last = nodes[nodes.length - 1];
2052
+ return last === void 0 || last.nextSibling === anchor;
2053
+ }
2054
+ function containsNode(record, node) {
2055
+ let current = node;
2056
+ while (current) {
2057
+ if (record.subtree.current().some((root) => root === current || root.contains(current))) return true;
2058
+ const treeRoot = current.getRootNode();
2059
+ current = "host" in treeRoot ? treeRoot.host : null;
2060
+ }
2061
+ return false;
2062
+ }
2063
+ function getDeepestActiveElement(parent) {
2064
+ var _parent$ownerDocument, _parent$ownerDocument2, _active$shadowRoot;
2065
+ const treeRoot = parent.getRootNode();
2066
+ let active = "activeElement" in treeRoot ? treeRoot.activeElement : (_parent$ownerDocument = (_parent$ownerDocument2 = parent.ownerDocument) === null || _parent$ownerDocument2 === void 0 ? void 0 : _parent$ownerDocument2.activeElement) !== null && _parent$ownerDocument !== void 0 ? _parent$ownerDocument : null;
2067
+ while (active === null || active === void 0 || (_active$shadowRoot = active.shadowRoot) === null || _active$shadowRoot === void 0 ? void 0 : _active$shadowRoot.activeElement) active = active.shadowRoot.activeElement;
2068
+ return active;
2069
+ }
2070
+ function duplicateKeyError(key, index) {
2071
+ return /* @__PURE__ */ new Error(`[Zeus runtime] <For> received duplicate key ${String(key)} at index ${index}.`);
2072
+ }
1946
2073
  function mountFor$1(parent, marker, each, key, render) {
1947
2074
  if (!key) {
1948
2075
  mountIndexFor(parent, marker, each, render);
@@ -1952,63 +2079,248 @@ function mountFor$1(parent, marker, each, key, render) {
1952
2079
  }
1953
2080
  function mountIndexFor(parent, marker, each, render) {
1954
2081
  const subtree = new ScopedSubtree(parent, marker, captureScopedSubtreeContext());
1955
- const runner = effect(() => {
1956
- var _each;
1957
- const list = (_each = each()) !== null && _each !== void 0 ? _each : [];
1958
- subtree.replace(() => list.map((item, index) => render(item, index)));
1959
- });
1960
- onScopeDispose(() => {
2082
+ let latestItems = [];
2083
+ let reconcileRequested = false;
2084
+ let reconciling = false;
2085
+ let disposed = false;
2086
+ let runner;
2087
+ const dispose = () => {
2088
+ if (disposed) return;
2089
+ disposed = true;
2090
+ if (runner) stop(runner);
2091
+ subtree.dispose();
2092
+ };
2093
+ onScopeDispose(dispose, true);
2094
+ const drainReconciliations = () => {
2095
+ if (disposed || reconciling) return;
2096
+ reconciling = true;
2097
+ try {
2098
+ while (reconcileRequested && !disposed) {
2099
+ reconcileRequested = false;
2100
+ untrack(() => {
2101
+ subtree.replace(() => latestItems.map((item, index) => render(() => item, () => index)));
2102
+ });
2103
+ }
2104
+ } finally {
2105
+ reconciling = false;
2106
+ if (disposed) subtree.dispose();
2107
+ }
2108
+ };
2109
+ const scheduleReconciliation = () => {
2110
+ if (disposed || !runner) return;
2111
+ runner();
2112
+ if (disposed) return;
2113
+ reconcileRequested = true;
2114
+ drainReconciliations();
2115
+ };
2116
+ try {
2117
+ runner = effect(() => {
2118
+ var _each;
2119
+ const nextItems = (_each = each()) !== null && _each !== void 0 ? _each : [];
2120
+ for (let i = 0; i < nextItems.length; i++) nextItems[i];
2121
+ latestItems = nextItems;
2122
+ }, { scheduler: scheduleReconciliation });
2123
+ } catch (error) {
2124
+ dispose();
2125
+ throw error;
2126
+ }
2127
+ if (disposed) {
1961
2128
  stop(runner);
1962
2129
  subtree.dispose();
1963
- }, true);
2130
+ return;
2131
+ }
2132
+ reconcileRequested = true;
2133
+ try {
2134
+ drainReconciliations();
2135
+ } catch (error) {
2136
+ dispose();
2137
+ throw error;
2138
+ }
1964
2139
  }
1965
2140
  function mountKeyedFor(parent, marker, each, key, render) {
1966
2141
  let records = [];
1967
2142
  const subtreeContext = captureScopedSubtreeContext();
1968
- const runner = effect(() => {
1969
- var _each2;
1970
- const nextItems = (_each2 = each()) !== null && _each2 !== void 0 ? _each2 : [];
2143
+ let latestItems = [];
2144
+ const latestKeys = [];
2145
+ let latestItemsUseFixedSlots = false;
2146
+ let reconcileRequested = false;
2147
+ let reconciling = false;
2148
+ let disposed = false;
2149
+ let runner;
2150
+ const dispose = () => {
2151
+ if (disposed) return;
2152
+ disposed = true;
2153
+ if (runner) stop(runner);
2154
+ const currentRecords = records;
2155
+ records = [];
2156
+ for (const record of currentRecords) disposeListRecord(record);
2157
+ };
2158
+ onScopeDispose(dispose, true);
2159
+ const reconcileEntries = (nextEntries) => {
2160
+ if (disposed) return;
1971
2161
  const oldMap = /* @__PURE__ */ new Map();
1972
2162
  for (const record of records) oldMap.set(record.key, record);
1973
2163
  const nextRecords = [];
1974
- for (let i = 0; i < nextItems.length; i++) {
1975
- const item = nextItems[i];
1976
- const itemKey = key(item, i);
1977
- const oldRecord = oldMap.get(itemKey);
1978
- if (oldRecord) {
1979
- oldMap.delete(itemKey);
1980
- oldRecord.item = item;
1981
- oldRecord.index = i;
1982
- nextRecords.push(oldRecord);
1983
- } else {
1984
- const subtree = new ScopedSubtree(parent, marker, subtreeContext);
1985
- subtree.replace(() => render(item, i));
1986
- nextRecords.push({
1987
- key: itemKey,
1988
- item,
1989
- index: i,
1990
- subtree
1991
- });
2164
+ const createdRecords = [];
2165
+ try {
2166
+ batch(() => {
2167
+ for (let i = 0; i < nextEntries.length; i++) {
2168
+ const { item, key: itemKey } = nextEntries[i];
2169
+ const oldRecord = oldMap.get(itemKey);
2170
+ if (oldRecord) {
2171
+ oldMap.delete(itemKey);
2172
+ if (!Object.is(oldRecord.item, item)) {
2173
+ oldRecord.item = item;
2174
+ oldRecord.setItem(() => item);
2175
+ }
2176
+ oldRecord.setIndex(i);
2177
+ nextRecords.push(oldRecord);
2178
+ } else {
2179
+ const [readItem, setItem] = createSignal(item);
2180
+ const [readIndex, setIndex] = createSignal(i);
2181
+ const subtree = new ScopedSubtree(parent, marker, subtreeContext);
2182
+ const record = {
2183
+ item,
2184
+ key: itemKey,
2185
+ setItem,
2186
+ setIndex,
2187
+ subtree
2188
+ };
2189
+ createdRecords.push(record);
2190
+ subtree.replace(() => render(readItem, readIndex));
2191
+ nextRecords.push(record);
2192
+ }
2193
+ if (disposed) break;
2194
+ }
2195
+ });
2196
+ } catch (error) {
2197
+ for (const record of createdRecords) disposeListRecord(record);
2198
+ throw error;
2199
+ }
2200
+ if (disposed) {
2201
+ for (const record of createdRecords) disposeListRecord(record);
2202
+ return;
2203
+ }
2204
+ const activeElement = getDeepestActiveElement(parent);
2205
+ const shouldRestoreFocus = Boolean(activeElement && nextRecords.some((record) => containsNode(record, activeElement)));
2206
+ let committed = false;
2207
+ try {
2208
+ for (const record of oldMap.values()) disposeListRecord(record);
2209
+ if (disposed) {
2210
+ for (const record of createdRecords) disposeListRecord(record);
2211
+ return;
2212
+ }
2213
+ records = nextRecords;
2214
+ committed = true;
2215
+ let moved = false;
2216
+ let anchor = marker;
2217
+ for (let i = nextRecords.length - 1; i >= 0; i--) {
2218
+ var _record$subtree$curre;
2219
+ const record = nextRecords[i];
2220
+ if (!isImmediatelyBefore(record, anchor)) {
2221
+ record.subtree.moveBefore(anchor);
2222
+ moved = true;
2223
+ }
2224
+ anchor = (_record$subtree$curre = record.subtree.current()[0]) !== null && _record$subtree$curre !== void 0 ? _record$subtree$curre : anchor;
1992
2225
  }
2226
+ if (disposed) return;
2227
+ if (moved && shouldRestoreFocus) {
2228
+ var _focus;
2229
+ (_focus = activeElement.focus) === null || _focus === void 0 || _focus.call(activeElement, { preventScroll: true });
2230
+ }
2231
+ if (!disposed) emitDevtoolsEvent({
2232
+ type: "mount-for",
2233
+ length: nextRecords.length
2234
+ });
2235
+ } catch (error) {
2236
+ if (!committed) for (const record of createdRecords) disposeListRecord(record);
2237
+ throw error;
2238
+ }
2239
+ };
2240
+ const reconcileLatestItems = () => {
2241
+ if (disposed) return;
2242
+ if (latestItemsUseFixedSlots) {
2243
+ const items = latestItems;
2244
+ batch(() => {
2245
+ for (let i = 0; i < items.length; i++) {
2246
+ const item = items[i];
2247
+ const record = records[i];
2248
+ if (!Object.is(record.item, item)) {
2249
+ record.item = item;
2250
+ record.setItem(() => item);
2251
+ }
2252
+ }
2253
+ });
2254
+ if (!disposed) emitDevtoolsEvent({
2255
+ type: "mount-for",
2256
+ length: records.length
2257
+ });
2258
+ return;
1993
2259
  }
1994
- for (const record of oldMap.values()) disposeListRecord(record);
1995
- for (let i = nextRecords.length - 1; i >= 0; i--) {
1996
- var _nextRecords$subtree$;
1997
- const record = nextRecords[i];
1998
- const anchor = i === nextRecords.length - 1 ? marker : (_nextRecords$subtree$ = nextRecords[i + 1].subtree.current()[0]) !== null && _nextRecords$subtree$ !== void 0 ? _nextRecords$subtree$ : marker;
1999
- record.subtree.moveBefore(anchor);
2260
+ const items = latestItems;
2261
+ const nextEntries = [];
2262
+ const nextKeys = /* @__PURE__ */ new Set();
2263
+ for (let i = 0; i < items.length; i++) {
2264
+ const item = items[i];
2265
+ const itemKey = latestKeys[i];
2266
+ if (nextKeys.has(itemKey)) throw duplicateKeyError(itemKey, i);
2267
+ nextKeys.add(itemKey);
2268
+ nextEntries.push({
2269
+ item,
2270
+ key: itemKey
2271
+ });
2000
2272
  }
2001
- emitDevtoolsEvent({
2002
- type: "mount-for",
2003
- length: nextRecords.length
2004
- });
2005
- records = nextRecords;
2006
- });
2007
- onScopeDispose(() => {
2273
+ reconcileEntries(nextEntries);
2274
+ };
2275
+ const drainReconciliations = () => {
2276
+ if (reconciling) return;
2277
+ reconciling = true;
2278
+ try {
2279
+ while (reconcileRequested) {
2280
+ reconcileRequested = false;
2281
+ untrack(reconcileLatestItems);
2282
+ }
2283
+ } finally {
2284
+ reconciling = false;
2285
+ }
2286
+ };
2287
+ const scheduleReconciliation = () => {
2288
+ if (disposed || !runner) return;
2289
+ runner();
2290
+ if (disposed) return;
2291
+ reconcileRequested = true;
2292
+ drainReconciliations();
2293
+ };
2294
+ try {
2295
+ runner = effect(() => {
2296
+ var _each2;
2297
+ const nextItems = (_each2 = each()) !== null && _each2 !== void 0 ? _each2 : [];
2298
+ let useFixedSlots = nextItems.length === records.length;
2299
+ for (let i = 0; i < nextItems.length; i++) {
2300
+ const item = nextItems[i];
2301
+ const itemKey = key(item, i);
2302
+ latestKeys[i] = itemKey;
2303
+ if (useFixedSlots && !Object.is(itemKey, records[i].key)) useFixedSlots = false;
2304
+ }
2305
+ latestKeys.length = nextItems.length;
2306
+ latestItems = nextItems;
2307
+ latestItemsUseFixedSlots = useFixedSlots;
2308
+ }, { scheduler: scheduleReconciliation });
2309
+ } catch (error) {
2310
+ dispose();
2311
+ throw error;
2312
+ }
2313
+ if (disposed) {
2008
2314
  stop(runner);
2009
- for (const record of records) disposeListRecord(record);
2010
- records = [];
2011
- }, true);
2315
+ return;
2316
+ }
2317
+ reconcileRequested = true;
2318
+ try {
2319
+ drainReconciliations();
2320
+ } catch (error) {
2321
+ dispose();
2322
+ throw error;
2323
+ }
2012
2324
  }
2013
2325
  //#endregion
2014
2326
  //#region packages/core/runtime-dom/src/controlFlow.ts
@@ -2233,7 +2545,14 @@ function createLightDomProjection(host, lightChildren) {
2233
2545
  function replaceOutletNodes(outlet, nextNodes) {
2234
2546
  const parent = outlet.end.parentNode;
2235
2547
  if (!parent || parent !== outlet.start.parentNode) return;
2548
+ const currentNodes = [];
2236
2549
  let current = outlet.start.nextSibling;
2550
+ while (current && current !== outlet.end) {
2551
+ currentNodes.push(current);
2552
+ current = current.nextSibling;
2553
+ }
2554
+ if (currentNodes.length === nextNodes.length && currentNodes.every((node, index) => node === nextNodes[index])) return;
2555
+ current = outlet.start.nextSibling;
2237
2556
  while (current && current !== outlet.end) {
2238
2557
  const next = current.nextSibling;
2239
2558
  parent.removeChild(current);
@@ -2287,6 +2606,7 @@ function prop(input, options = {}) {
2287
2606
  values: input,
2288
2607
  attr: options.attr,
2289
2608
  reflect: options.reflect,
2609
+ reactivity: options.reactivity,
2290
2610
  default: options.default,
2291
2611
  serialize: options.serialize,
2292
2612
  deserialize: options.deserialize
@@ -2296,6 +2616,7 @@ function prop(input, options = {}) {
2296
2616
  type,
2297
2617
  attr: options.attr,
2298
2618
  reflect: type === Boolean ? (_options$reflect = options.reflect) !== null && _options$reflect !== void 0 ? _options$reflect : true : options.reflect,
2619
+ reactivity: options.reactivity,
2299
2620
  default: type === Boolean ? (_options$default = options.default) !== null && _options$default !== void 0 ? _options$default : false : options.default,
2300
2621
  serialize: options.serialize,
2301
2622
  deserialize: options.deserialize
@@ -2318,7 +2639,7 @@ function createPropStore(defs) {
2318
2639
  const slots = /* @__PURE__ */ new Map();
2319
2640
  const props = {};
2320
2641
  for (const def of defs) {
2321
- const slot = state();
2642
+ const slot = def.reactivity === "shallow" ? shallowState() : state();
2322
2643
  slots.set(def.name, slot);
2323
2644
  Object.defineProperty(props, def.name, {
2324
2645
  configurable: false,
@@ -2387,6 +2708,7 @@ function defineElement(tagName, options, setup) {
2387
2708
  this.mountLifecycle.connect();
2388
2709
  }
2389
2710
  disconnectedCallback() {
2711
+ if (isWithinRuntimeDomMove(this)) return;
2390
2712
  this.mountLifecycle.disconnect();
2391
2713
  }
2392
2714
  mountElement() {
@@ -2577,7 +2899,8 @@ function normalizePropDefinitions(props) {
2577
2899
  name: propKey,
2578
2900
  attrName: isAttributeBackedConstructor(type) ? toKebabCase(propKey) : false,
2579
2901
  type: normalizePropType(type),
2580
- reflect: false
2902
+ reflect: false,
2903
+ reactivity: "deep"
2581
2904
  };
2582
2905
  }
2583
2906
  const type = input === null || input === void 0 ? void 0 : input.type;
@@ -2587,6 +2910,7 @@ function normalizePropDefinitions(props) {
2587
2910
  attrName: (input === null || input === void 0 ? void 0 : input.attr) === void 0 ? defaultAttr : input.attr,
2588
2911
  type: normalizePropType(type),
2589
2912
  reflect: Boolean(input === null || input === void 0 ? void 0 : input.reflect),
2913
+ reactivity: (input === null || input === void 0 ? void 0 : input.reactivity) === "shallow" ? "shallow" : "deep",
2590
2914
  default: input === null || input === void 0 ? void 0 : input.default,
2591
2915
  serialize: input === null || input === void 0 ? void 0 : input.serialize,
2592
2916
  deserialize: input === null || input === void 0 ? void 0 : input.deserialize