@zeus-js/runtime-dom 0.1.0 → 0.1.1-beta.1

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.0
2
+ * runtime-dom v0.1.1-beta.1
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
  /**
@@ -493,6 +504,31 @@ function cleanupEffect(e) {
493
504
  }
494
505
  }
495
506
  }
507
+ /**
508
+ * Batches reactive updates synchronously within the given function.
509
+ * All updates triggered inside `fn` are deferred until the function completes,
510
+ * then flushed together in a single batch.
511
+ */
512
+ function batch(fn) {
513
+ startBatch();
514
+ try {
515
+ return fn();
516
+ } finally {
517
+ endBatch();
518
+ }
519
+ }
520
+ /**
521
+ * Executes the given function without tracking reactive dependencies.
522
+ * Any reactive reads inside `fn` will not trigger effect re-runs.
523
+ */
524
+ function untrack(fn) {
525
+ pauseTracking();
526
+ try {
527
+ return fn();
528
+ } finally {
529
+ resetTracking();
530
+ }
531
+ }
496
532
  //#endregion
497
533
  //#region packages/core/signal/src/dep.ts
498
534
  /**
@@ -870,60 +906,6 @@ function noTracking(self, method, args = []) {
870
906
  return res;
871
907
  }
872
908
  //#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
909
  //#region packages/core/signal/src/baseHandlers.ts
928
910
  const isNonTrackableKeys = /*@__PURE__*/ makeMap(`__proto__,__v_isRef,__isVue`);
929
911
  const builtInSymbols = new Set(/*@__PURE__*/ Object.getOwnPropertyNames(Symbol).filter((key) => key !== "arguments" && key !== "caller").map((key) => Symbol[key]).filter(isSymbol));
@@ -1356,11 +1338,84 @@ const toReactive = (value) => isObject(value) ? /* @__PURE__ */ reactive(value)
1356
1338
  */
1357
1339
  const toReadonly = (value) => isObject(value) ? /* @__PURE__ */ readonly(value) : value;
1358
1340
  //#endregion
1341
+ //#region packages/core/signal/src/ref.ts
1342
+ let _ReactiveFlags$IS_REF, _ReactiveFlags$IS_SHA;
1343
+ /*@__NO_SIDE_EFFECTS__*/
1344
+ function isRef(r) {
1345
+ return r ? r["__v_isRef"] === true : false;
1346
+ }
1347
+ /*@__NO_SIDE_EFFECTS__*/
1348
+ function ref(value) {
1349
+ return createRef(value, false);
1350
+ }
1351
+ /*@__NO_SIDE_EFFECTS__*/
1352
+ function shallowRef(value) {
1353
+ return createRef(value, true);
1354
+ }
1355
+ function createRef(rawValue, shallow) {
1356
+ if (/* @__PURE__ */ isRef(rawValue)) return rawValue;
1357
+ return new RefImpl(rawValue, shallow);
1358
+ }
1359
+ _ReactiveFlags$IS_REF = "__v_isRef";
1360
+ _ReactiveFlags$IS_SHA = "__v_isShallow";
1361
+ /**
1362
+ * @internal
1363
+ */
1364
+ var RefImpl = class {
1365
+ constructor(value, isShallow) {
1366
+ this.dep = new Dep();
1367
+ this[_ReactiveFlags$IS_REF] = true;
1368
+ this[_ReactiveFlags$IS_SHA] = false;
1369
+ this._rawValue = isShallow ? value : /* @__PURE__ */ toRaw(value);
1370
+ this._value = isShallow ? value : toReactive(value);
1371
+ this["__v_isShallow"] = isShallow;
1372
+ }
1373
+ get value() {
1374
+ this.dep.track({
1375
+ target: this,
1376
+ type: "get",
1377
+ key: "value"
1378
+ });
1379
+ return this._value;
1380
+ }
1381
+ set value(newValue) {
1382
+ const oldValue = this._rawValue;
1383
+ const useDirectValue = this["__v_isShallow"] || /* @__PURE__ */ isShallow(newValue) || /* @__PURE__ */ isReadonly(newValue);
1384
+ newValue = useDirectValue ? newValue : /* @__PURE__ */ toRaw(newValue);
1385
+ if (hasChanged(newValue, oldValue)) {
1386
+ this._rawValue = newValue;
1387
+ this._value = useDirectValue ? newValue : toReactive(newValue);
1388
+ this.dep.trigger({
1389
+ target: this,
1390
+ type: "set",
1391
+ key: "value",
1392
+ newValue,
1393
+ oldValue
1394
+ });
1395
+ }
1396
+ }
1397
+ };
1398
+ //#endregion
1399
+ //#region packages/core/signal/src/primitives.ts
1400
+ function createSignal(initialValue) {
1401
+ const source = /* @__PURE__ */ shallowRef(initialValue);
1402
+ const read = () => source.value;
1403
+ const write = (value) => {
1404
+ const next = typeof value === "function" ? value(source.value) : value;
1405
+ source.value = next;
1406
+ return next;
1407
+ };
1408
+ return [read, write];
1409
+ }
1410
+ //#endregion
1359
1411
  //#region packages/core/signal/src/state.ts
1360
1412
  function state(value) {
1361
1413
  if (arguments.length === 0) return /* @__PURE__ */ ref();
1362
1414
  return isProxyable(value) ? /* @__PURE__ */ reactive(value) : /* @__PURE__ */ ref(value);
1363
1415
  }
1416
+ function shallowState(value) {
1417
+ return arguments.length === 0 ? /* @__PURE__ */ shallowRef() : /* @__PURE__ */ shallowRef(value);
1418
+ }
1364
1419
  function isProxyable(value) {
1365
1420
  if (value === null || typeof value !== "object") return false;
1366
1421
  if (Array.isArray(value)) return true;
@@ -1372,6 +1427,32 @@ function isPlainObject(value) {
1372
1427
  return proto === Object.prototype || proto === null;
1373
1428
  }
1374
1429
  //#endregion
1430
+ //#region packages/core/runtime-dom/src/domMove.ts
1431
+ const activeMoveRoots = /* @__PURE__ */ new Set();
1432
+ function moveNodeBefore(parent, node, marker) {
1433
+ activeMoveRoots.add(node);
1434
+ try {
1435
+ const moveBefore = parent.moveBefore;
1436
+ if (typeof moveBefore === "function") moveBefore.call(parent, node, marker);
1437
+ else parent.insertBefore(node, marker);
1438
+ } finally {
1439
+ activeMoveRoots.delete(node);
1440
+ }
1441
+ }
1442
+ function isWithinRuntimeDomMove(node) {
1443
+ let current = node;
1444
+ while (current) {
1445
+ if (activeMoveRoots.has(current)) return true;
1446
+ if (current.parentNode) {
1447
+ current = current.parentNode;
1448
+ continue;
1449
+ }
1450
+ const root = current.getRootNode();
1451
+ current = "host" in root ? root.host : null;
1452
+ }
1453
+ return false;
1454
+ }
1455
+ //#endregion
1375
1456
  //#region packages/core/runtime-dom/src/domOwnership.ts
1376
1457
  const activeLightDomHosts = /* @__PURE__ */ new WeakMap();
1377
1458
  const runtimeOwnedNodes = /* @__PURE__ */ new WeakSet();
@@ -1406,6 +1487,14 @@ function insertTracked(parent, value, marker = null) {
1406
1487
  for (const item of value) nodes.push(...insertTracked(parent, item, marker));
1407
1488
  return nodes;
1408
1489
  }
1490
+ if (value instanceof Node && value.nodeType === Node.DOCUMENT_FRAGMENT_NODE) {
1491
+ const nodes = Array.from(value.childNodes);
1492
+ for (const node of nodes) {
1493
+ trackRuntimeDomInsertion(parent, node);
1494
+ parent.insertBefore(node, marker);
1495
+ }
1496
+ return nodes;
1497
+ }
1409
1498
  const node = value instanceof Node ? value : document.createTextNode(String(value));
1410
1499
  trackRuntimeDomInsertion(parent, node);
1411
1500
  parent.insertBefore(node, marker);
@@ -1420,7 +1509,7 @@ function removeNodes$1(nodes) {
1420
1509
  function moveRangeBefore(nodes, parent, marker = null) {
1421
1510
  for (const node of nodes) {
1422
1511
  trackRuntimeDomInsertion(parent, node);
1423
- parent.insertBefore(node, marker);
1512
+ moveNodeBefore(parent, node, marker);
1424
1513
  }
1425
1514
  }
1426
1515
  //#endregion
@@ -1465,10 +1554,11 @@ var ScopedSubtree = class {
1465
1554
  replace(render) {
1466
1555
  this.dispose();
1467
1556
  const scope = effectScope(true);
1557
+ const parent = this.resolveParent(this.marker);
1468
1558
  let nodes = [];
1469
1559
  try {
1470
1560
  scope.run(() => {
1471
- nodes = runWithOwner(this.context.owner, () => withHostContext(this.context.host, () => insertTracked(this.parent, render(), this.marker)));
1561
+ nodes = runWithOwner(this.context.owner, () => withHostContext(this.context.host, () => insertTracked(parent, render(), this.marker)));
1472
1562
  });
1473
1563
  } catch (error) {
1474
1564
  scope.stop();
@@ -1486,11 +1576,15 @@ var ScopedSubtree = class {
1486
1576
  this.nodes = [];
1487
1577
  }
1488
1578
  moveBefore(marker) {
1489
- moveRangeBefore(this.nodes, this.parent, marker);
1579
+ moveRangeBefore(this.nodes, this.resolveParent(marker), marker);
1490
1580
  }
1491
1581
  current() {
1492
1582
  return this.nodes;
1493
1583
  }
1584
+ resolveParent(marker) {
1585
+ var _ref, _marker$parentNode, _this$marker;
1586
+ 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;
1587
+ }
1494
1588
  };
1495
1589
  //#endregion
1496
1590
  //#region packages/core/runtime-dom/src/insert.ts
@@ -1700,14 +1794,23 @@ function removeNodes(nodes) {
1700
1794
  }
1701
1795
  //#endregion
1702
1796
  //#region packages/core/runtime-dom/src/bindings.ts
1703
- function bindText(node, value) {
1704
- effect(() => {
1705
- node.data = stringifyText(value());
1797
+ function bindText(node, value, once = false) {
1798
+ applyBinding(value, once, (next) => {
1799
+ node.data = stringifyText(next);
1706
1800
  });
1707
1801
  }
1708
- function bindTextContent(el, value) {
1802
+ function bindTextContent(el, value, once = false) {
1803
+ applyBinding(value, once, (next) => {
1804
+ el.textContent = stringifyText(next);
1805
+ });
1806
+ }
1807
+ function applyBinding(value, once, apply) {
1808
+ if (once) {
1809
+ untrack(() => apply(value()));
1810
+ return;
1811
+ }
1709
1812
  effect(() => {
1710
- el.textContent = stringifyText(value());
1813
+ apply(value());
1711
1814
  });
1712
1815
  }
1713
1816
  function stringifyText(value) {
@@ -1760,19 +1863,19 @@ const BOOLEAN_DOM_PROPERTY_NAME = {
1760
1863
  function normalizeAttrName(name) {
1761
1864
  return name === "className" ? "class" : name;
1762
1865
  }
1763
- function bindAttr(el, name, value) {
1764
- effect(() => {
1765
- setAttr(el, name, value());
1866
+ function bindAttr(el, name, value, once = false) {
1867
+ applyBinding(value, once, (next) => {
1868
+ setAttr(el, name, next);
1766
1869
  });
1767
1870
  }
1768
- function bindProp(el, name, value) {
1769
- effect(() => {
1770
- el[name] = value();
1871
+ function bindProp(el, name, value, once = false) {
1872
+ applyBinding(value, once, (next) => {
1873
+ el[name] = next;
1771
1874
  });
1772
1875
  }
1773
- function bindClass(el, value) {
1774
- effect(() => {
1775
- const next = normalizeClass(value());
1876
+ function bindClass(el, value, once = false) {
1877
+ applyBinding(value, once, (value) => {
1878
+ const next = normalizeClass(value);
1776
1879
  if (next) el.setAttribute("class", next);
1777
1880
  else el.removeAttribute("class");
1778
1881
  });
@@ -1784,10 +1887,9 @@ function normalizeClass(value) {
1784
1887
  if (typeof value === "object") return Object.keys(value).filter((key) => value[key]).join(" ");
1785
1888
  return "";
1786
1889
  }
1787
- function bindStyle(el, value) {
1890
+ function bindStyle(el, value, once = false) {
1788
1891
  let prev;
1789
- effect(() => {
1790
- const next = value();
1892
+ applyBinding(value, once, (next) => {
1791
1893
  if (next == null) {
1792
1894
  el.removeAttribute("style");
1793
1895
  prev = void 0;
@@ -1943,6 +2045,30 @@ function createComponent(component, props) {
1943
2045
  function disposeListRecord(record) {
1944
2046
  record.subtree.dispose();
1945
2047
  }
2048
+ function isImmediatelyBefore(record, anchor) {
2049
+ const nodes = record.subtree.current();
2050
+ const last = nodes[nodes.length - 1];
2051
+ return last === void 0 || last.nextSibling === anchor;
2052
+ }
2053
+ function containsNode(record, node) {
2054
+ let current = node;
2055
+ while (current) {
2056
+ if (record.subtree.current().some((root) => root === current || root.contains(current))) return true;
2057
+ const treeRoot = current.getRootNode();
2058
+ current = "host" in treeRoot ? treeRoot.host : null;
2059
+ }
2060
+ return false;
2061
+ }
2062
+ function getDeepestActiveElement(parent) {
2063
+ var _parent$ownerDocument, _parent$ownerDocument2, _active$shadowRoot;
2064
+ const treeRoot = parent.getRootNode();
2065
+ 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;
2066
+ while (active === null || active === void 0 || (_active$shadowRoot = active.shadowRoot) === null || _active$shadowRoot === void 0 ? void 0 : _active$shadowRoot.activeElement) active = active.shadowRoot.activeElement;
2067
+ return active;
2068
+ }
2069
+ function duplicateKeyError(key, index) {
2070
+ return /* @__PURE__ */ new Error(`[Zeus runtime] <For> received duplicate key ${String(key)} at index ${index}.`);
2071
+ }
1946
2072
  function mountFor$1(parent, marker, each, key, render) {
1947
2073
  if (!key) {
1948
2074
  mountIndexFor(parent, marker, each, render);
@@ -1952,63 +2078,210 @@ function mountFor$1(parent, marker, each, key, render) {
1952
2078
  }
1953
2079
  function mountIndexFor(parent, marker, each, render) {
1954
2080
  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(() => {
2081
+ let latestItems = [];
2082
+ let reconcileRequested = false;
2083
+ let reconciling = false;
2084
+ let disposed = false;
2085
+ let runner;
2086
+ const dispose = () => {
2087
+ if (disposed) return;
2088
+ disposed = true;
2089
+ if (runner) stop(runner);
2090
+ subtree.dispose();
2091
+ };
2092
+ onScopeDispose(dispose, true);
2093
+ const drainReconciliations = () => {
2094
+ if (disposed || reconciling) return;
2095
+ reconciling = true;
2096
+ try {
2097
+ while (reconcileRequested && !disposed) {
2098
+ reconcileRequested = false;
2099
+ untrack(() => {
2100
+ subtree.replace(() => latestItems.map((item, index) => render(() => item, () => index)));
2101
+ });
2102
+ }
2103
+ } finally {
2104
+ reconciling = false;
2105
+ if (disposed) subtree.dispose();
2106
+ }
2107
+ };
2108
+ const scheduleReconciliation = () => {
2109
+ if (disposed || !runner) return;
2110
+ runner();
2111
+ if (disposed) return;
2112
+ reconcileRequested = true;
2113
+ drainReconciliations();
2114
+ };
2115
+ try {
2116
+ runner = effect(() => {
2117
+ var _each;
2118
+ const nextItems = (_each = each()) !== null && _each !== void 0 ? _each : [];
2119
+ for (let i = 0; i < nextItems.length; i++) nextItems[i];
2120
+ latestItems = nextItems;
2121
+ }, { scheduler: scheduleReconciliation });
2122
+ } catch (error) {
2123
+ dispose();
2124
+ throw error;
2125
+ }
2126
+ if (disposed) {
1961
2127
  stop(runner);
1962
2128
  subtree.dispose();
1963
- }, true);
2129
+ return;
2130
+ }
2131
+ reconcileRequested = true;
2132
+ try {
2133
+ drainReconciliations();
2134
+ } catch (error) {
2135
+ dispose();
2136
+ throw error;
2137
+ }
1964
2138
  }
1965
2139
  function mountKeyedFor(parent, marker, each, key, render) {
1966
2140
  let records = [];
1967
2141
  const subtreeContext = captureScopedSubtreeContext();
1968
- const runner = effect(() => {
1969
- var _each2;
1970
- const nextItems = (_each2 = each()) !== null && _each2 !== void 0 ? _each2 : [];
2142
+ let latestEntries = [];
2143
+ let reconcileRequested = false;
2144
+ let reconciling = false;
2145
+ let disposed = false;
2146
+ let runner;
2147
+ const dispose = () => {
2148
+ if (disposed) return;
2149
+ disposed = true;
2150
+ if (runner) stop(runner);
2151
+ const currentRecords = records;
2152
+ records = [];
2153
+ for (const record of currentRecords) disposeListRecord(record);
2154
+ };
2155
+ onScopeDispose(dispose, true);
2156
+ const reconcile = (nextEntries) => {
2157
+ if (disposed) return;
1971
2158
  const oldMap = /* @__PURE__ */ new Map();
1972
2159
  for (const record of records) oldMap.set(record.key, record);
1973
2160
  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
- });
2161
+ const createdRecords = [];
2162
+ try {
2163
+ batch(() => {
2164
+ for (let i = 0; i < nextEntries.length; i++) {
2165
+ const { item, key: itemKey } = nextEntries[i];
2166
+ const oldRecord = oldMap.get(itemKey);
2167
+ if (oldRecord) {
2168
+ oldMap.delete(itemKey);
2169
+ oldRecord.setItem(() => item);
2170
+ oldRecord.setIndex(i);
2171
+ nextRecords.push(oldRecord);
2172
+ } else {
2173
+ const [readItem, setItem] = createSignal(item);
2174
+ const [readIndex, setIndex] = createSignal(i);
2175
+ const subtree = new ScopedSubtree(parent, marker, subtreeContext);
2176
+ const record = {
2177
+ key: itemKey,
2178
+ setItem,
2179
+ setIndex,
2180
+ subtree
2181
+ };
2182
+ createdRecords.push(record);
2183
+ subtree.replace(() => render(readItem, readIndex));
2184
+ nextRecords.push(record);
2185
+ }
2186
+ if (disposed) break;
2187
+ }
2188
+ });
2189
+ } catch (error) {
2190
+ for (const record of createdRecords) disposeListRecord(record);
2191
+ throw error;
2192
+ }
2193
+ if (disposed) {
2194
+ for (const record of createdRecords) disposeListRecord(record);
2195
+ return;
2196
+ }
2197
+ const activeElement = getDeepestActiveElement(parent);
2198
+ const shouldRestoreFocus = Boolean(activeElement && nextRecords.some((record) => containsNode(record, activeElement)));
2199
+ let committed = false;
2200
+ try {
2201
+ for (const record of oldMap.values()) disposeListRecord(record);
2202
+ if (disposed) {
2203
+ for (const record of createdRecords) disposeListRecord(record);
2204
+ return;
2205
+ }
2206
+ records = nextRecords;
2207
+ committed = true;
2208
+ let moved = false;
2209
+ let anchor = marker;
2210
+ for (let i = nextRecords.length - 1; i >= 0; i--) {
2211
+ var _record$subtree$curre;
2212
+ const record = nextRecords[i];
2213
+ if (!isImmediatelyBefore(record, anchor)) {
2214
+ record.subtree.moveBefore(anchor);
2215
+ moved = true;
2216
+ }
2217
+ anchor = (_record$subtree$curre = record.subtree.current()[0]) !== null && _record$subtree$curre !== void 0 ? _record$subtree$curre : anchor;
2218
+ }
2219
+ if (disposed) return;
2220
+ if (moved && shouldRestoreFocus) {
2221
+ var _focus;
2222
+ (_focus = activeElement.focus) === null || _focus === void 0 || _focus.call(activeElement, { preventScroll: true });
1992
2223
  }
2224
+ if (!disposed) emitDevtoolsEvent({
2225
+ type: "mount-for",
2226
+ length: nextRecords.length
2227
+ });
2228
+ } catch (error) {
2229
+ if (!committed) for (const record of createdRecords) disposeListRecord(record);
2230
+ throw error;
1993
2231
  }
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);
2232
+ };
2233
+ const drainReconciliations = () => {
2234
+ if (reconciling) return;
2235
+ reconciling = true;
2236
+ try {
2237
+ while (reconcileRequested) {
2238
+ reconcileRequested = false;
2239
+ untrack(() => reconcile(latestEntries));
2240
+ }
2241
+ } finally {
2242
+ reconciling = false;
2000
2243
  }
2001
- emitDevtoolsEvent({
2002
- type: "mount-for",
2003
- length: nextRecords.length
2004
- });
2005
- records = nextRecords;
2006
- });
2007
- onScopeDispose(() => {
2244
+ };
2245
+ const scheduleReconciliation = () => {
2246
+ if (disposed || !runner) return;
2247
+ runner();
2248
+ if (disposed) return;
2249
+ reconcileRequested = true;
2250
+ drainReconciliations();
2251
+ };
2252
+ try {
2253
+ runner = effect(() => {
2254
+ var _each2;
2255
+ const nextItems = (_each2 = each()) !== null && _each2 !== void 0 ? _each2 : [];
2256
+ const nextEntries = [];
2257
+ const nextKeys = /* @__PURE__ */ new Set();
2258
+ for (let i = 0; i < nextItems.length; i++) {
2259
+ const item = nextItems[i];
2260
+ const itemKey = key(item, i);
2261
+ if (nextKeys.has(itemKey)) throw duplicateKeyError(itemKey, i);
2262
+ nextKeys.add(itemKey);
2263
+ nextEntries.push({
2264
+ item,
2265
+ key: itemKey
2266
+ });
2267
+ }
2268
+ latestEntries = nextEntries;
2269
+ }, { scheduler: scheduleReconciliation });
2270
+ } catch (error) {
2271
+ dispose();
2272
+ throw error;
2273
+ }
2274
+ if (disposed) {
2008
2275
  stop(runner);
2009
- for (const record of records) disposeListRecord(record);
2010
- records = [];
2011
- }, true);
2276
+ return;
2277
+ }
2278
+ reconcileRequested = true;
2279
+ try {
2280
+ drainReconciliations();
2281
+ } catch (error) {
2282
+ dispose();
2283
+ throw error;
2284
+ }
2012
2285
  }
2013
2286
  //#endregion
2014
2287
  //#region packages/core/runtime-dom/src/controlFlow.ts
@@ -2233,7 +2506,14 @@ function createLightDomProjection(host, lightChildren) {
2233
2506
  function replaceOutletNodes(outlet, nextNodes) {
2234
2507
  const parent = outlet.end.parentNode;
2235
2508
  if (!parent || parent !== outlet.start.parentNode) return;
2509
+ const currentNodes = [];
2236
2510
  let current = outlet.start.nextSibling;
2511
+ while (current && current !== outlet.end) {
2512
+ currentNodes.push(current);
2513
+ current = current.nextSibling;
2514
+ }
2515
+ if (currentNodes.length === nextNodes.length && currentNodes.every((node, index) => node === nextNodes[index])) return;
2516
+ current = outlet.start.nextSibling;
2237
2517
  while (current && current !== outlet.end) {
2238
2518
  const next = current.nextSibling;
2239
2519
  parent.removeChild(current);
@@ -2287,6 +2567,7 @@ function prop(input, options = {}) {
2287
2567
  values: input,
2288
2568
  attr: options.attr,
2289
2569
  reflect: options.reflect,
2570
+ reactivity: options.reactivity,
2290
2571
  default: options.default,
2291
2572
  serialize: options.serialize,
2292
2573
  deserialize: options.deserialize
@@ -2296,6 +2577,7 @@ function prop(input, options = {}) {
2296
2577
  type,
2297
2578
  attr: options.attr,
2298
2579
  reflect: type === Boolean ? (_options$reflect = options.reflect) !== null && _options$reflect !== void 0 ? _options$reflect : true : options.reflect,
2580
+ reactivity: options.reactivity,
2299
2581
  default: type === Boolean ? (_options$default = options.default) !== null && _options$default !== void 0 ? _options$default : false : options.default,
2300
2582
  serialize: options.serialize,
2301
2583
  deserialize: options.deserialize
@@ -2318,7 +2600,7 @@ function createPropStore(defs) {
2318
2600
  const slots = /* @__PURE__ */ new Map();
2319
2601
  const props = {};
2320
2602
  for (const def of defs) {
2321
- const slot = state();
2603
+ const slot = def.reactivity === "shallow" ? shallowState() : state();
2322
2604
  slots.set(def.name, slot);
2323
2605
  Object.defineProperty(props, def.name, {
2324
2606
  configurable: false,
@@ -2387,6 +2669,7 @@ function defineElement(tagName, options, setup) {
2387
2669
  this.mountLifecycle.connect();
2388
2670
  }
2389
2671
  disconnectedCallback() {
2672
+ if (isWithinRuntimeDomMove(this)) return;
2390
2673
  this.mountLifecycle.disconnect();
2391
2674
  }
2392
2675
  mountElement() {
@@ -2577,7 +2860,8 @@ function normalizePropDefinitions(props) {
2577
2860
  name: propKey,
2578
2861
  attrName: isAttributeBackedConstructor(type) ? toKebabCase(propKey) : false,
2579
2862
  type: normalizePropType(type),
2580
- reflect: false
2863
+ reflect: false,
2864
+ reactivity: "deep"
2581
2865
  };
2582
2866
  }
2583
2867
  const type = input === null || input === void 0 ? void 0 : input.type;
@@ -2587,6 +2871,7 @@ function normalizePropDefinitions(props) {
2587
2871
  attrName: (input === null || input === void 0 ? void 0 : input.attr) === void 0 ? defaultAttr : input.attr,
2588
2872
  type: normalizePropType(type),
2589
2873
  reflect: Boolean(input === null || input === void 0 ? void 0 : input.reflect),
2874
+ reactivity: (input === null || input === void 0 ? void 0 : input.reactivity) === "shallow" ? "shallow" : "deep",
2590
2875
  default: input === null || input === void 0 ? void 0 : input.default,
2591
2876
  serialize: input === null || input === void 0 ? void 0 : input.serialize,
2592
2877
  deserialize: input === null || input === void 0 ? void 0 : input.deserialize