regor 1.3.5 → 1.3.7

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.
@@ -4,8 +4,8 @@ var bindDataSymbol = Symbol(":regor");
4
4
  // src/cleanup/unbind.ts
5
5
  var unbind = (node) => {
6
6
  const stack = [node];
7
- while (stack.length > 0) {
8
- const currentNode = stack.pop();
7
+ for (let i = 0; i < stack.length; ++i) {
8
+ const currentNode = stack[i];
9
9
  unbindSingle(currentNode);
10
10
  for (let child = currentNode.lastChild; child != null; child = child.previousSibling) {
11
11
  stack.push(child);
@@ -355,6 +355,8 @@ var setSwitchOwner = (owner, switchNodes) => {
355
355
  };
356
356
 
357
357
  // src/bind/IfBinder.ts
358
+ var noopStopObserving = () => {
359
+ };
358
360
  var mount = (nodes, binder, parent, end) => {
359
361
  const childNodes = [];
360
362
  for (const x of nodes) {
@@ -479,18 +481,14 @@ var IfBinder = class {
479
481
  const parseResult = this.__binder.__parser.__parse(expression);
480
482
  const value = parseResult.value;
481
483
  const remainingElses = this.__collectElses(nextElement, refresh);
482
- const stopObserverList = [];
484
+ let stopObserver = noopStopObserving;
483
485
  const unbinder = () => {
484
486
  parseResult.stop();
485
- for (const stopObserver of stopObserverList) {
486
- stopObserver();
487
- }
488
- stopObserverList.length = 0;
487
+ stopObserver();
488
+ stopObserver = noopStopObserving;
489
489
  };
490
490
  addUnbinder(commentBegin, unbinder);
491
- const stopObserving = parseResult.subscribe ? parseResult.subscribe(refresh) : () => {
492
- };
493
- stopObserverList.push(stopObserving);
491
+ stopObserver = parseResult.subscribe(refresh);
494
492
  return [
495
493
  {
496
494
  mount: () => {
@@ -501,8 +499,9 @@ var IfBinder = class {
501
499
  },
502
500
  isTrue: () => !!value()[0],
503
501
  isMounted: false
504
- }
505
- ].concat(remainingElses);
502
+ },
503
+ ...remainingElses
504
+ ];
506
505
  }
507
506
  }
508
507
  __bindToExpression(el, expression) {
@@ -548,29 +547,31 @@ var IfBinder = class {
548
547
  });
549
548
  };
550
549
  const collectedElses = this.__collectElses(nextElement, refresh);
551
- const stopObserverList = [];
550
+ let stopObserver = noopStopObserving;
552
551
  const unbinder = () => {
553
552
  parseResult.stop();
554
- for (const stopObserver of stopObserverList) {
555
- stopObserver();
556
- }
557
- stopObserverList.length = 0;
553
+ stopObserver();
554
+ stopObserver = noopStopObserving;
558
555
  };
559
556
  addUnbinder(commentBegin, unbinder);
560
557
  refresh();
561
- const stopObserving = parseResult.subscribe ? parseResult.subscribe(refresh) : () => {
562
- };
563
- stopObserverList.push(stopObserving);
558
+ stopObserver = parseResult.subscribe(refresh);
564
559
  }
565
560
  };
566
561
 
567
562
  // src/common/common.ts
568
563
  var getNodes = (el) => {
569
- const childNodes = isTemplate(el) ? el.content.childNodes : [el];
570
- return Array.from(childNodes).filter((x) => {
571
- const tagName = x?.tagName;
572
- return tagName !== "SCRIPT" && tagName !== "STYLE";
573
- });
564
+ const source = isTemplate(el) ? el.content.childNodes : [el];
565
+ const result = [];
566
+ for (let i = 0; i < source.length; ++i) {
567
+ const node = source[i];
568
+ if (node.nodeType === 1) {
569
+ const tagName = node?.tagName;
570
+ if (tagName === "SCRIPT" || tagName === "STYLE") continue;
571
+ }
572
+ result.push(node);
573
+ }
574
+ return result;
574
575
  };
575
576
  var bindChildNodes = (binder, childNodes) => {
576
577
  for (let i = 0; i < childNodes.length; ++i) {
@@ -667,7 +668,9 @@ var capitalize = cacheStringFunction((str) => {
667
668
  });
668
669
 
669
670
  // src/directives/teleport.ts
670
- var teleportDirective = {};
671
+ var teleportDirective = {
672
+ mount: () => void 0
673
+ };
671
674
 
672
675
  // src/composition/callMounted.ts
673
676
  var callMounted = (context) => {
@@ -701,11 +704,6 @@ var isScope = (value) => {
701
704
  return scopeSymbol2 in value;
702
705
  };
703
706
 
704
- // src/composition/onUnmounted.ts
705
- var onUnmounted = (onUnmounted2, noThrow) => {
706
- peekScope(noThrow)?.onUnmounted.push(onUnmounted2);
707
- };
708
-
709
707
  // src/reactivity/refSymbols.ts
710
708
  var refSymbol = Symbol("ref");
711
709
  var srefSymbol = Symbol("sref");
@@ -716,6 +714,34 @@ var isRef = (value) => {
716
714
  return value != null && value[srefSymbol] === 1;
717
715
  };
718
716
 
717
+ // src/directives/context.ts
718
+ var contextDirective = {
719
+ collectRefObj: true,
720
+ mount: ({ parseResult }) => ({
721
+ update: ({ values }) => {
722
+ const ctx = parseResult.context;
723
+ const obj = values[0];
724
+ if (!isObject(obj)) return;
725
+ for (const item of Object.entries(obj)) {
726
+ const key = item[0];
727
+ const nextValue = item[1];
728
+ const ctxKey = ctx[key];
729
+ if (ctxKey === nextValue) continue;
730
+ if (isRef(ctxKey)) {
731
+ ctxKey(nextValue);
732
+ } else {
733
+ ctx[key] = nextValue;
734
+ }
735
+ }
736
+ }
737
+ })
738
+ };
739
+
740
+ // src/composition/onUnmounted.ts
741
+ var onUnmounted = (onUnmounted2, noThrow) => {
742
+ peekScope(noThrow)?.onUnmounted.push(onUnmounted2);
743
+ };
744
+
719
745
  // src/observer/observe.ts
720
746
  var observe = (source, observer, init, trackUnmount = true) => {
721
747
  if (!isRef(source))
@@ -732,37 +758,6 @@ var observe = (source, observer, init, trackUnmount = true) => {
732
758
  return stop;
733
759
  };
734
760
 
735
- // src/directives/context.ts
736
- var contextDirective = {
737
- collectRefObj: true,
738
- onBind: (_, parseResult) => {
739
- const stopObserving = observe(
740
- parseResult.value,
741
- () => {
742
- const value = parseResult.value();
743
- const ctx = parseResult.context;
744
- const obj = value[0];
745
- if (!isObject(obj)) {
746
- return;
747
- }
748
- for (const item of Object.entries(obj)) {
749
- const key = item[0];
750
- const value2 = item[1];
751
- const ctxKey = ctx[key];
752
- if (ctxKey === value2) continue;
753
- if (isRef(ctxKey)) {
754
- ctxKey(value2);
755
- } else {
756
- ctx[key] = value2;
757
- }
758
- }
759
- },
760
- true
761
- );
762
- return stopObserving;
763
- }
764
- };
765
-
766
761
  // src/reactivity/entangle.ts
767
762
  var entangle = (r1, r2) => {
768
763
  if (r1 === r2) return () => {
@@ -1089,8 +1084,8 @@ var createModelBridge = (source) => {
1089
1084
  };
1090
1085
  var singlePropDirective = {
1091
1086
  collectRefObj: true,
1092
- onBind: (_, parseResult, _expr, option, _dynamicOption, _flags) => {
1093
- if (!option) return noop;
1087
+ mount: ({ parseResult, option }) => {
1088
+ if (typeof option !== "string" || !option) return noop;
1094
1089
  const key = camelize(option);
1095
1090
  let currentSource;
1096
1091
  let bridge;
@@ -1111,43 +1106,43 @@ var singlePropDirective = {
1111
1106
  stopEntangle = entangle(source, target);
1112
1107
  currentSource = source;
1113
1108
  };
1114
- const stopObserving = observe(
1115
- parseResult.value,
1116
- () => {
1117
- const value = parseResult.refs[0] ?? parseResult.value()[0];
1118
- const ctx = parseResult.context;
1119
- const ctxKey = ctx[key];
1120
- if (!isRef(value)) {
1121
- if (bridge && ctxKey === bridge) {
1122
- bridge(value);
1123
- return;
1124
- }
1125
- resetSync();
1126
- if (isRef(ctxKey)) {
1127
- ctxKey(value);
1128
- return;
1129
- }
1130
- ctx[key] = value;
1109
+ const apply = () => {
1110
+ const value = parseResult.refs[0] ?? parseResult.value()[0];
1111
+ const ctx = parseResult.context;
1112
+ const ctxKey = ctx[key];
1113
+ if (!isRef(value)) {
1114
+ if (bridge && ctxKey === bridge) {
1115
+ bridge(value);
1131
1116
  return;
1132
1117
  }
1133
- if (isModelBridge(value)) {
1134
- if (ctxKey === value) return;
1135
- if (isRef(ctxKey)) {
1136
- syncRefs(value, ctxKey);
1137
- } else {
1138
- ctx[key] = value;
1139
- }
1118
+ resetSync();
1119
+ if (isRef(ctxKey)) {
1120
+ ctxKey(value);
1140
1121
  return;
1141
1122
  }
1142
- if (!bridge) bridge = createModelBridge(value);
1143
- ctx[key] = bridge;
1144
- syncRefs(value, bridge);
1123
+ ctx[key] = value;
1124
+ return;
1125
+ }
1126
+ if (isModelBridge(value)) {
1127
+ if (ctxKey === value) return;
1128
+ if (isRef(ctxKey)) {
1129
+ syncRefs(value, ctxKey);
1130
+ } else {
1131
+ ctx[key] = value;
1132
+ }
1133
+ return;
1134
+ }
1135
+ if (!bridge) bridge = createModelBridge(value);
1136
+ ctx[key] = bridge;
1137
+ syncRefs(value, bridge);
1138
+ };
1139
+ return {
1140
+ update: () => {
1141
+ apply();
1145
1142
  },
1146
- true
1147
- );
1148
- return () => {
1149
- stopEntangle();
1150
- stopObserving();
1143
+ unmount: () => {
1144
+ stopEntangle();
1145
+ }
1151
1146
  };
1152
1147
  }
1153
1148
  };
@@ -1168,7 +1163,10 @@ var ComponentBinder = class {
1168
1163
  __getRegisteredComponentSelector(registeredComponents) {
1169
1164
  if (this.__registeredComponentSize !== registeredComponents.size) {
1170
1165
  const names = [...registeredComponents.keys()];
1171
- this.__registeredComponentSelector = names.concat(names.map(hyphenate)).join(",");
1166
+ this.__registeredComponentSelector = [
1167
+ ...names,
1168
+ ...names.map(hyphenate)
1169
+ ].join(",");
1172
1170
  this.__registeredComponentSize = registeredComponents.size;
1173
1171
  }
1174
1172
  return this.__registeredComponentSelector;
@@ -1243,7 +1241,10 @@ var ComponentBinder = class {
1243
1241
  definedProp
1244
1242
  ])
1245
1243
  );
1246
- for (const name of definedProps.concat(definedProps.map(hyphenate))) {
1244
+ for (const name of [
1245
+ ...definedProps,
1246
+ ...definedProps.map(hyphenate)
1247
+ ]) {
1247
1248
  const value = component2.getAttribute(name);
1248
1249
  if (value === null) continue;
1249
1250
  props[camelize(name)] = value;
@@ -1536,15 +1537,14 @@ var DirectiveCollector = class {
1536
1537
  const processNode = (node) => {
1537
1538
  const attrs = node.attributes;
1538
1539
  if (!attrs || attrs.length === 0) return;
1539
- const attrsAny = attrs;
1540
1540
  for (let i = 0; i < attrs.length; ++i) {
1541
- const name = (attrsAny[i] ?? attrs.item(i))?.name;
1541
+ const name = attrs.item(i)?.name;
1542
1542
  if (!name) continue;
1543
1543
  appendDirective(node, name);
1544
1544
  }
1545
1545
  };
1546
1546
  processNode(element);
1547
- if (!isRecursive) return map;
1547
+ if (!isRecursive || !element.firstElementChild) return map;
1548
1548
  const nodes = element.querySelectorAll("*");
1549
1549
  for (const node of nodes) {
1550
1550
  processNode(node);
@@ -1554,6 +1554,8 @@ var DirectiveCollector = class {
1554
1554
  };
1555
1555
 
1556
1556
  // src/bind/DynamicBinder.ts
1557
+ var noopStopObserving2 = () => {
1558
+ };
1557
1559
  var mount2 = (nodes, parent) => {
1558
1560
  for (const x of nodes) {
1559
1561
  const node = x.cloneNode(true);
@@ -1668,19 +1670,15 @@ var DynamicBinder = class {
1668
1670
  mounted.name = name;
1669
1671
  });
1670
1672
  };
1671
- const stopObserverList = [];
1673
+ let stopObserver = noopStopObserving2;
1672
1674
  const unbinder = () => {
1673
1675
  parseResult.stop();
1674
- for (const stopObserver of stopObserverList) {
1675
- stopObserver();
1676
- }
1677
- stopObserverList.length = 0;
1676
+ stopObserver();
1677
+ stopObserver = noopStopObserving2;
1678
1678
  };
1679
1679
  addUnbinder(commentBegin, unbinder);
1680
1680
  refresh();
1681
- const stopObserving = parseResult.subscribe ? parseResult.subscribe(refresh) : () => {
1682
- };
1683
- stopObserverList.push(stopObserving);
1681
+ stopObserver = parseResult.subscribe(refresh);
1684
1682
  }
1685
1683
  };
1686
1684
 
@@ -1690,6 +1688,272 @@ var unref = (value) => {
1690
1688
  return anyValue != null && anyValue[srefSymbol] === 1 ? anyValue() : anyValue;
1691
1689
  };
1692
1690
 
1691
+ // src/directives/html.ts
1692
+ var updateHtml = (el, values) => {
1693
+ const [value, replacer] = values;
1694
+ if (isFunction(replacer)) replacer(el, value);
1695
+ else el.innerHTML = value?.toString();
1696
+ };
1697
+ var htmlDirective = {
1698
+ mount: () => ({
1699
+ update: ({ el, values }) => {
1700
+ updateHtml(el, values);
1701
+ }
1702
+ })
1703
+ };
1704
+
1705
+ // src/bind/ForBinderFastPath.ts
1706
+ var ForBinderFastPath = class _ForBinderFastPath {
1707
+ __bindings;
1708
+ constructor(bindings) {
1709
+ this.__bindings = bindings;
1710
+ }
1711
+ static __create(binder, nodes) {
1712
+ const parser = binder.__parser;
1713
+ const config = binder.__config;
1714
+ const builtInNames = config.__builtInNames;
1715
+ const blockedBuiltIns = /* @__PURE__ */ new Set([
1716
+ builtInNames.for,
1717
+ builtInNames.if,
1718
+ builtInNames.else,
1719
+ builtInNames.elseif,
1720
+ builtInNames.pre
1721
+ ]);
1722
+ const directiveMap = config.__directiveMap;
1723
+ const contextComponents = parser.__getComponents();
1724
+ if (Object.keys(contextComponents).length > 0 || config.__componentsUpperCase.size > 0) {
1725
+ return void 0;
1726
+ }
1727
+ const collector = binder.__directiveCollector;
1728
+ const bindings = [];
1729
+ let nodeIndex = 0;
1730
+ const stack = [];
1731
+ for (let i = nodes.length - 1; i >= 0; --i) {
1732
+ stack.push(nodes[i]);
1733
+ }
1734
+ while (stack.length > 0) {
1735
+ const node = stack.pop();
1736
+ if (node.nodeType === Node.ELEMENT_NODE) {
1737
+ const el = node;
1738
+ if (el.tagName === "TEMPLATE") return void 0;
1739
+ if (el.tagName.includes("-")) return void 0;
1740
+ const tagNameUpper = camelize(el.tagName).toUpperCase();
1741
+ if (config.__componentsUpperCase.has(tagNameUpper) || contextComponents[tagNameUpper]) {
1742
+ return void 0;
1743
+ }
1744
+ const attrs = el.attributes;
1745
+ for (let i = 0; i < attrs.length; ++i) {
1746
+ const attrName = attrs.item(i)?.name;
1747
+ if (!attrName) continue;
1748
+ if (blockedBuiltIns.has(attrName)) return void 0;
1749
+ const { terms, flags } = collector.__parseName(attrName);
1750
+ const [name, option] = terms;
1751
+ const directive = directiveMap[attrName] ?? directiveMap[name];
1752
+ if (!directive) continue;
1753
+ if (directive === htmlDirective) return void 0;
1754
+ bindings.push({
1755
+ nodeIndex,
1756
+ attrName,
1757
+ directive,
1758
+ option,
1759
+ flags
1760
+ });
1761
+ }
1762
+ ++nodeIndex;
1763
+ }
1764
+ const children = node.childNodes;
1765
+ for (let i = children.length - 1; i >= 0; --i) {
1766
+ stack.push(children[i]);
1767
+ }
1768
+ }
1769
+ if (bindings.length === 0) return void 0;
1770
+ return new _ForBinderFastPath(bindings);
1771
+ }
1772
+ __bind(binder, nodes) {
1773
+ const elements = [];
1774
+ const stack = [];
1775
+ for (let i = nodes.length - 1; i >= 0; --i) {
1776
+ stack.push(nodes[i]);
1777
+ }
1778
+ while (stack.length > 0) {
1779
+ const node = stack.pop();
1780
+ if (node.nodeType === Node.ELEMENT_NODE) {
1781
+ elements.push(node);
1782
+ }
1783
+ const children = node.childNodes;
1784
+ for (let i = children.length - 1; i >= 0; --i) {
1785
+ stack.push(children[i]);
1786
+ }
1787
+ }
1788
+ for (let i = 0; i < this.__bindings.length; ++i) {
1789
+ const binding = this.__bindings[i];
1790
+ const el = elements[binding.nodeIndex];
1791
+ if (!el) continue;
1792
+ binder.__bind(
1793
+ binding.directive,
1794
+ el,
1795
+ binding.attrName,
1796
+ false,
1797
+ binding.option,
1798
+ binding.flags
1799
+ );
1800
+ }
1801
+ }
1802
+ };
1803
+
1804
+ // src/bind/ForBinderKeyedDiff.ts
1805
+ var moveMountItemBefore = (item, anchor) => {
1806
+ const parent = anchor.parentNode;
1807
+ if (!parent) return;
1808
+ for (let i = 0; i < item.items.length; ++i) {
1809
+ parent.insertBefore(item.items[i], anchor);
1810
+ }
1811
+ };
1812
+ var getSequence = (arr) => {
1813
+ const len = arr.length;
1814
+ const p = arr.slice();
1815
+ const result = [];
1816
+ let u;
1817
+ let v;
1818
+ let c;
1819
+ for (let i = 0; i < len; ++i) {
1820
+ const value = arr[i];
1821
+ if (value === 0) continue;
1822
+ const j = result[result.length - 1];
1823
+ if (j === void 0 || arr[j] < value) {
1824
+ p[i] = j ?? -1;
1825
+ result.push(i);
1826
+ continue;
1827
+ }
1828
+ u = 0;
1829
+ v = result.length - 1;
1830
+ while (u < v) {
1831
+ c = u + v >> 1;
1832
+ if (arr[result[c]] < value) u = c + 1;
1833
+ else v = c;
1834
+ }
1835
+ if (value < arr[result[u]]) {
1836
+ if (u > 0) p[i] = result[u - 1];
1837
+ result[u] = i;
1838
+ }
1839
+ }
1840
+ u = result.length;
1841
+ v = result[u - 1] ?? -1;
1842
+ while (u-- > 0) {
1843
+ result[u] = v;
1844
+ v = p[v];
1845
+ }
1846
+ return result;
1847
+ };
1848
+ var ForBinderKeyedDiff = class {
1849
+ /**
1850
+ * Applies keyed patch and returns the next ordered mount list.
1851
+ * Returns `undefined` when keyed mode is not safe for this update.
1852
+ */
1853
+ static __patch(options) {
1854
+ const {
1855
+ oldItems,
1856
+ newValues,
1857
+ getKey,
1858
+ isSameValue,
1859
+ mountNewValue,
1860
+ removeMountItem,
1861
+ endAnchor
1862
+ } = options;
1863
+ const oldLen = oldItems.length;
1864
+ const newLen = newValues.length;
1865
+ const newKeys = new Array(newLen);
1866
+ const keySeen = /* @__PURE__ */ new Set();
1867
+ for (let i2 = 0; i2 < newLen; ++i2) {
1868
+ const key = getKey(newValues[i2]);
1869
+ if (key === void 0 || keySeen.has(key)) return void 0;
1870
+ keySeen.add(key);
1871
+ newKeys[i2] = key;
1872
+ }
1873
+ const newMountItems = new Array(newLen);
1874
+ let i = 0;
1875
+ let e1 = oldLen - 1;
1876
+ let e2 = newLen - 1;
1877
+ while (i <= e1 && i <= e2) {
1878
+ const oldItem = oldItems[i];
1879
+ if (getKey(oldItem.value) !== newKeys[i]) break;
1880
+ if (!isSameValue(oldItem.value, newValues[i])) break;
1881
+ oldItem.value = newValues[i];
1882
+ newMountItems[i] = oldItem;
1883
+ ++i;
1884
+ }
1885
+ while (i <= e1 && i <= e2) {
1886
+ const oldItem = oldItems[e1];
1887
+ if (getKey(oldItem.value) !== newKeys[e2]) break;
1888
+ if (!isSameValue(oldItem.value, newValues[e2])) break;
1889
+ oldItem.value = newValues[e2];
1890
+ newMountItems[e2] = oldItem;
1891
+ --e1;
1892
+ --e2;
1893
+ }
1894
+ if (i > e1) {
1895
+ for (let k = e2; k >= i; --k) {
1896
+ const anchor = k + 1 < newLen ? newMountItems[k + 1].items[0] : endAnchor;
1897
+ newMountItems[k] = mountNewValue(k, newValues[k], anchor);
1898
+ }
1899
+ return newMountItems;
1900
+ }
1901
+ if (i > e2) {
1902
+ for (let k = i; k <= e1; ++k) removeMountItem(oldItems[k]);
1903
+ return newMountItems;
1904
+ }
1905
+ const s1 = i;
1906
+ const s2 = i;
1907
+ const toBePatched = e2 - s2 + 1;
1908
+ const newIndexToOldIndexMap = new Array(toBePatched).fill(0);
1909
+ const keyToNewIndexMap = /* @__PURE__ */ new Map();
1910
+ for (let k = s2; k <= e2; ++k) {
1911
+ keyToNewIndexMap.set(newKeys[k], k);
1912
+ }
1913
+ let moved = false;
1914
+ let maxNewIndexSoFar = 0;
1915
+ for (let k = s1; k <= e1; ++k) {
1916
+ const oldItem = oldItems[k];
1917
+ const newIndex = keyToNewIndexMap.get(getKey(oldItem.value));
1918
+ if (newIndex === void 0) {
1919
+ removeMountItem(oldItem);
1920
+ continue;
1921
+ }
1922
+ if (!isSameValue(oldItem.value, newValues[newIndex])) {
1923
+ removeMountItem(oldItem);
1924
+ continue;
1925
+ }
1926
+ oldItem.value = newValues[newIndex];
1927
+ newMountItems[newIndex] = oldItem;
1928
+ newIndexToOldIndexMap[newIndex - s2] = k + 1;
1929
+ if (newIndex >= maxNewIndexSoFar) maxNewIndexSoFar = newIndex;
1930
+ else moved = true;
1931
+ }
1932
+ const increasingNewIndexSequence = moved ? getSequence(newIndexToOldIndexMap) : [];
1933
+ let seqIdx = increasingNewIndexSequence.length - 1;
1934
+ for (let k = toBePatched - 1; k >= 0; --k) {
1935
+ const newIndex = s2 + k;
1936
+ const anchor = newIndex + 1 < newLen ? newMountItems[newIndex + 1].items[0] : endAnchor;
1937
+ if (newIndexToOldIndexMap[k] === 0) {
1938
+ newMountItems[newIndex] = mountNewValue(
1939
+ newIndex,
1940
+ newValues[newIndex],
1941
+ anchor
1942
+ );
1943
+ continue;
1944
+ }
1945
+ const item = newMountItems[newIndex];
1946
+ if (!moved) continue;
1947
+ if (seqIdx >= 0 && increasingNewIndexSequence[seqIdx] === k) {
1948
+ --seqIdx;
1949
+ } else if (item) {
1950
+ moveMountItemBefore(item, anchor);
1951
+ }
1952
+ }
1953
+ return newMountItems;
1954
+ }
1955
+ };
1956
+
1693
1957
  // src/bind/MountList.ts
1694
1958
  var MountList = class {
1695
1959
  __list = [];
@@ -1769,6 +2033,8 @@ var MountList = class {
1769
2033
  // src/bind/ForBinder.ts
1770
2034
  var forMarker = Symbol("r-for");
1771
2035
  var noIndexRef = (_) => -1;
2036
+ var noopStopObserving3 = () => {
2037
+ };
1772
2038
  var ForBinder = class _ForBinder {
1773
2039
  __binder;
1774
2040
  __for;
@@ -1838,6 +2104,7 @@ var ForBinder = class _ForBinder {
1838
2104
  el.removeAttribute(nameKey);
1839
2105
  el.removeAttribute(nameKeyBind);
1840
2106
  const nodes = getNodes(el);
2107
+ const fastPath = ForBinderFastPath.__create(this.__binder, nodes);
1841
2108
  const parent = el.parentNode;
1842
2109
  if (!parent) return;
1843
2110
  const title = `${this.__for} => ${forPath}`;
@@ -1857,6 +2124,7 @@ var ForBinder = class _ForBinder {
1857
2124
  const rowContexts = singleCapturedContext ? [void 0, capturedContext[0]] : void 0;
1858
2125
  const getKey = this.__createKeyGetter(keyExpression);
1859
2126
  const areEqual = (a, b) => getKey(a) === getKey(b);
2127
+ const isSameValue = (a, b) => a === b;
1860
2128
  const mountNewValue = (i2, newValue, nextSibling) => {
1861
2129
  const result = config.createContext(newValue, i2);
1862
2130
  const mountItem = MountList.__createItem(result.index, newValue);
@@ -1869,7 +2137,8 @@ var ForBinder = class _ForBinder {
1869
2137
  insertParent.insertBefore(node, nextSibling);
1870
2138
  childNodes.push(node);
1871
2139
  }
1872
- bindChildNodes(binder, childNodes);
2140
+ if (fastPath) fastPath.__bind(binder, childNodes);
2141
+ else bindChildNodes(binder, childNodes);
1873
2142
  start = start.nextSibling;
1874
2143
  while (start !== nextSibling) {
1875
2144
  mountItem.items.push(start);
@@ -1921,16 +2190,51 @@ var ForBinder = class _ForBinder {
1921
2190
  mountList.__removeAllAfter(0);
1922
2191
  return;
1923
2192
  }
2193
+ const iterableValues = [];
2194
+ for (const value2 of this.__getIterable(newValues[0])) {
2195
+ iterableValues.push(value2);
2196
+ }
2197
+ const patched = ForBinderKeyedDiff.__patch({
2198
+ oldItems: mountList.__list,
2199
+ newValues: iterableValues,
2200
+ getKey,
2201
+ isSameValue,
2202
+ mountNewValue: (index, value2, nextSibling) => mountNewValue(index, value2, nextSibling),
2203
+ removeMountItem: (item) => {
2204
+ for (let k = 0; k < item.items.length; ++k) {
2205
+ removeNode(item.items[k]);
2206
+ }
2207
+ },
2208
+ endAnchor: commentEnd
2209
+ });
2210
+ if (patched) {
2211
+ mountList.__list = patched;
2212
+ mountList.__valueMap.clear();
2213
+ for (let k = 0; k < patched.length; ++k) {
2214
+ const item = patched[k];
2215
+ item.order = k;
2216
+ item.index(k);
2217
+ const key = getKey(item.value);
2218
+ if (key !== void 0) {
2219
+ mountList.__valueMap.set(key, item);
2220
+ }
2221
+ }
2222
+ return;
2223
+ }
1924
2224
  let i2 = 0;
1925
2225
  let firstRemovalOrInsertionIndex = Number.MAX_SAFE_INTEGER;
1926
2226
  const initialLength = len;
1927
2227
  const forGrowThreshold = this.__binder.__config.forGrowThreshold;
1928
2228
  const shouldGrowList = () => mountList.__length < initialLength + forGrowThreshold;
1929
- for (const newValue of this.__getIterable(newValues[0])) {
2229
+ for (const newValue of iterableValues) {
1930
2230
  const modify = () => {
1931
2231
  if (i2 < len) {
1932
2232
  const mountItem = mountList.__get(i2++);
1933
- if (areEqual(mountItem.value, newValue)) return;
2233
+ if (areEqual(mountItem.value, newValue)) {
2234
+ if (isSameValue(mountItem.value, newValue)) return;
2235
+ replace(i2 - 1, newValue);
2236
+ return;
2237
+ }
1934
2238
  const newValueMountPosition = mountList.__lookupValueOrderIfMounted(
1935
2239
  getKey(newValue)
1936
2240
  );
@@ -1980,24 +2284,21 @@ var ForBinder = class _ForBinder {
1980
2284
  mountList.__removeAllAfter(j);
1981
2285
  updateIndexes(firstRemovalOrInsertionIndex);
1982
2286
  };
1983
- const observeTailChanges = () => {
1984
- stopObserving = parseResult.subscribe ? parseResult.subscribe(updateDom) : () => {
1985
- };
1986
- };
1987
2287
  const unbinder = () => {
1988
2288
  parseResult.stop();
1989
2289
  stopObserving();
2290
+ stopObserving = noopStopObserving3;
1990
2291
  };
1991
2292
  const parseResult = parser.__parse(config.list);
1992
2293
  const value = parseResult.value;
1993
- let stopObserving;
2294
+ let stopObserving = noopStopObserving3;
1994
2295
  let i = 0;
1995
2296
  const mountList = new MountList(getKey);
1996
2297
  for (const item of this.__getIterable(value()[0])) {
1997
2298
  mountList.__push(mountNewValue(i++, item, commentEnd));
1998
2299
  }
1999
2300
  addUnbinder(commentBegin, unbinder);
2000
- observeTailChanges();
2301
+ stopObserving = parseResult.subscribe(updateDom);
2001
2302
  }
2002
2303
  static __forPathRegex = /\{?\[?\(?([^)}\]]+)\)?\]?\}?([^)]+)?\s+\b(?:in|of)\b\s+(.*)\s*$/;
2003
2304
  __parseForPath(forPath) {
@@ -2176,97 +2477,108 @@ var Binder = class {
2176
2477
  __bindToExpression(config, el, valueExpression, option, flags) {
2177
2478
  if (el.nodeType !== Node.ELEMENT_NODE || valueExpression == null) return;
2178
2479
  if (this.__handleTeleport(config, el, valueExpression)) return;
2179
- const result = this.__parser.__parse(
2480
+ const dynamicOption = this.__parseDynamicOption(option, config.once);
2481
+ const result = this.__parseExpression(config, valueExpression);
2482
+ const stops = this.__createBindStops(result, dynamicOption);
2483
+ addUnbinder(el, stops.stop);
2484
+ const payload = this.__createDirectivePayload(
2485
+ el,
2486
+ valueExpression,
2487
+ result,
2488
+ dynamicOption,
2489
+ option,
2490
+ flags
2491
+ );
2492
+ const mountedUpdate = this.__mountDirective(config, payload, stops);
2493
+ if (!mountedUpdate) return;
2494
+ const emitChange = this.__createEmitter(
2495
+ payload,
2496
+ result,
2497
+ dynamicOption,
2498
+ option,
2499
+ mountedUpdate
2500
+ );
2501
+ emitChange();
2502
+ if (!config.once) {
2503
+ stops.result = result.subscribe(emitChange);
2504
+ if (dynamicOption) {
2505
+ stops.dynamic = dynamicOption.subscribe(emitChange);
2506
+ }
2507
+ }
2508
+ }
2509
+ __parseDynamicOption(option, once) {
2510
+ const dynamicOptionExpression = isOptionDynamic(option, this.__dynamic);
2511
+ if (!dynamicOptionExpression) return void 0;
2512
+ return this.__parser.__parse(
2513
+ camelize(dynamicOptionExpression),
2514
+ void 0,
2515
+ void 0,
2516
+ void 0,
2517
+ once
2518
+ );
2519
+ }
2520
+ __parseExpression(config, valueExpression) {
2521
+ return this.__parser.__parse(
2180
2522
  valueExpression,
2181
2523
  config.isLazy,
2182
2524
  config.isLazyKey,
2183
2525
  config.collectRefObj,
2184
2526
  config.once
2185
2527
  );
2186
- const stopObserverList = [];
2187
- const hasOnChange = !!config.onChange;
2188
- const unbinder = () => {
2189
- result.stop();
2190
- dynamicOption?.stop();
2191
- for (let i = 0; i < stopObserverList.length; ++i) {
2192
- stopObserverList[i]();
2528
+ }
2529
+ __createBindStops(result, dynamicOption) {
2530
+ const stops = {
2531
+ stop: () => {
2532
+ result.stop();
2533
+ dynamicOption?.stop();
2534
+ stops.result?.();
2535
+ stops.dynamic?.();
2536
+ stops.mounted?.();
2537
+ stops.result = void 0;
2538
+ stops.dynamic = void 0;
2539
+ stops.mounted = void 0;
2193
2540
  }
2194
- stopObserverList.length = 0;
2195
2541
  };
2196
- addUnbinder(el, unbinder);
2197
- const dynamicOptionExpression = isOptionDynamic(option, this.__dynamic);
2198
- let dynamicOption;
2199
- if (dynamicOptionExpression) {
2200
- dynamicOption = this.__parser.__parse(
2201
- camelize(dynamicOptionExpression),
2202
- void 0,
2203
- void 0,
2204
- void 0,
2205
- config.once
2206
- );
2542
+ return stops;
2543
+ }
2544
+ __createDirectivePayload(el, expr, result, dynamicOption, option, flags) {
2545
+ return {
2546
+ el,
2547
+ expr,
2548
+ values: result.value(),
2549
+ previousValues: void 0,
2550
+ option: dynamicOption ? dynamicOption.value()[0] : option,
2551
+ previousOption: void 0,
2552
+ flags,
2553
+ parseResult: result,
2554
+ dynamicOption
2555
+ };
2556
+ }
2557
+ __mountDirective(config, payload, stops) {
2558
+ const mounted = config.mount(payload);
2559
+ if (typeof mounted === "function") {
2560
+ stops.mounted = mounted;
2561
+ return void 0;
2207
2562
  }
2208
- const dynamicOpt = dynamicOption;
2209
- const hasDynamicOption = dynamicOpt != null;
2210
- let previousValues = result.value();
2211
- let previousOption = hasDynamicOption ? dynamicOption.value()[0] : option;
2212
- if (!config.once && hasOnChange) {
2213
- const stopObserving = result.subscribe ? result.subscribe(() => {
2214
- const preValues = previousValues;
2215
- const preOption = previousOption;
2216
- const nextValues = result.value();
2217
- const nextOption = hasDynamicOption ? dynamicOpt.value()[0] : option;
2218
- previousValues = nextValues;
2219
- previousOption = nextOption;
2220
- config.onChange?.(
2221
- el,
2222
- nextValues,
2223
- preValues,
2224
- nextOption,
2225
- preOption,
2226
- flags
2227
- );
2228
- }) : () => {
2229
- };
2230
- stopObserverList.push(stopObserving);
2231
- if (dynamicOpt) {
2232
- const stopObserving2 = dynamicOpt.subscribe ? dynamicOpt.subscribe(() => {
2233
- const preOption = previousOption;
2234
- const nextValues = result.value();
2235
- const nextOption = dynamicOpt.value()[0];
2236
- previousValues = nextValues;
2237
- previousOption = nextOption;
2238
- config.onChange?.(
2239
- el,
2240
- nextValues,
2241
- preOption,
2242
- nextOption,
2243
- preOption,
2244
- flags
2245
- );
2246
- }) : () => {
2247
- };
2248
- stopObserverList.push(stopObserving2);
2249
- }
2563
+ if (mounted?.unmount) {
2564
+ stops.mounted = mounted.unmount;
2250
2565
  }
2251
- if (config.onBind)
2252
- stopObserverList.push(
2253
- config.onBind(
2254
- el,
2255
- result,
2256
- valueExpression,
2257
- option,
2258
- dynamicOption,
2259
- flags
2260
- )
2261
- );
2262
- config.onChange?.(
2263
- el,
2264
- previousValues,
2265
- void 0,
2266
- previousOption,
2267
- void 0,
2268
- flags
2269
- );
2566
+ return mounted?.update;
2567
+ }
2568
+ __createEmitter(payload, result, dynamicOption, option, mountedUpdate) {
2569
+ let previousValues;
2570
+ let previousOption;
2571
+ return () => {
2572
+ const nextValues = result.value();
2573
+ const nextOption = dynamicOption ? dynamicOption.value()[0] : option;
2574
+ payload.values = nextValues;
2575
+ payload.previousValues = previousValues;
2576
+ payload.option = nextOption;
2577
+ payload.previousOption = previousOption;
2578
+ previousValues = nextValues;
2579
+ previousOption = nextOption;
2580
+ mountedUpdate(payload);
2581
+ };
2270
2582
  }
2271
2583
  };
2272
2584
 
@@ -2303,38 +2615,50 @@ var booleanAttributes = {
2303
2615
  function includeBooleanAttr(value) {
2304
2616
  return !!value || value === "";
2305
2617
  }
2306
- var attrDirective = {
2307
- onChange: (el, values, previousValues, option, previousOption, flags) => {
2308
- if (option) {
2309
- if (flags && flags.includes("camel")) option = camelize(option);
2310
- patchAttribute(el, option, values[0], previousOption);
2311
- return;
2312
- }
2313
- const len = values.length;
2314
- for (let i = 0; i < len; ++i) {
2315
- const next = values[i];
2316
- if (isArray(next)) {
2317
- const previousKey = previousValues?.[i]?.[0];
2318
- const key = next[0];
2319
- const value = next[1];
2320
- patchAttribute(el, key, value, previousKey);
2321
- } else if (isObject(next)) {
2322
- for (const item of Object.entries(next)) {
2323
- const key = item[0];
2324
- const value = item[1];
2325
- const p = previousValues?.[i];
2326
- const previousKey = p && key in p ? key : void 0;
2327
- patchAttribute(el, key, value, previousKey);
2328
- }
2329
- } else {
2330
- const previousKey = previousValues?.[i];
2331
- const key = values[i++];
2332
- const value = values[i];
2618
+ var updateAttr = (el, values, previousValues, option, previousOption, flags) => {
2619
+ if (option) {
2620
+ if (flags && flags.includes("camel")) option = camelize(option);
2621
+ patchAttribute(el, option, values[0], previousOption);
2622
+ return;
2623
+ }
2624
+ const len = values.length;
2625
+ for (let i = 0; i < len; ++i) {
2626
+ const next = values[i];
2627
+ if (isArray(next)) {
2628
+ const previousKey = previousValues?.[i]?.[0];
2629
+ const key = next[0];
2630
+ const value = next[1];
2631
+ patchAttribute(el, key, value, previousKey);
2632
+ } else if (isObject(next)) {
2633
+ for (const item of Object.entries(next)) {
2634
+ const key = item[0];
2635
+ const value = item[1];
2636
+ const p = previousValues?.[i];
2637
+ const previousKey = p && key in p ? key : void 0;
2333
2638
  patchAttribute(el, key, value, previousKey);
2334
2639
  }
2640
+ } else {
2641
+ const previousKey = previousValues?.[i];
2642
+ const key = values[i++];
2643
+ const value = values[i];
2644
+ patchAttribute(el, key, value, previousKey);
2335
2645
  }
2336
2646
  }
2337
2647
  };
2648
+ var attrDirective = {
2649
+ mount: () => ({
2650
+ update: ({ el, values, previousValues, option, previousOption, flags }) => {
2651
+ updateAttr(
2652
+ el,
2653
+ values,
2654
+ previousValues,
2655
+ option,
2656
+ previousOption,
2657
+ flags
2658
+ );
2659
+ }
2660
+ })
2661
+ };
2338
2662
  var patchAttribute = (el, key, value, previousKey) => {
2339
2663
  if (previousKey && previousKey !== key) {
2340
2664
  el.removeAttribute(previousKey);
@@ -2368,23 +2692,28 @@ var patchAttribute = (el, key, value, previousKey) => {
2368
2692
  };
2369
2693
 
2370
2694
  // src/directives/class.ts
2371
- var classDirective = {
2372
- onChange: (el, values, previousValues) => {
2373
- const len = values.length;
2374
- for (let i = 0; i < len; ++i) {
2375
- const next = values[i];
2376
- const previous = previousValues?.[i];
2377
- if (isArray(next)) {
2378
- const len2 = next.length;
2379
- for (let j = 0; j < len2; ++j) {
2380
- patchClass(el, next[j], previous?.[j]);
2381
- }
2382
- } else {
2383
- patchClass(el, next, previous);
2695
+ var updateClass = (el, values, previousValues) => {
2696
+ const len = values.length;
2697
+ for (let i = 0; i < len; ++i) {
2698
+ const next = values[i];
2699
+ const previous = previousValues?.[i];
2700
+ if (isArray(next)) {
2701
+ const len2 = next.length;
2702
+ for (let j = 0; j < len2; ++j) {
2703
+ patchClass(el, next[j], previous?.[j]);
2384
2704
  }
2705
+ } else {
2706
+ patchClass(el, next, previous);
2385
2707
  }
2386
2708
  }
2387
2709
  };
2710
+ var classDirective = {
2711
+ mount: () => ({
2712
+ update: ({ el, values, previousValues }) => {
2713
+ updateClass(el, values, previousValues);
2714
+ }
2715
+ })
2716
+ };
2388
2717
  var patchClass = (el, next, prev) => {
2389
2718
  const classList = el.classList;
2390
2719
  const isClassString = isString(next);
@@ -2412,15 +2741,6 @@ var patchClass = (el, next, prev) => {
2412
2741
  }
2413
2742
  };
2414
2743
 
2415
- // src/directives/html.ts
2416
- var htmlDirective = {
2417
- onChange: (el, values) => {
2418
- const [value, replacer] = values;
2419
- if (isFunction(replacer)) replacer(el, value);
2420
- else el.innerHTML = value?.toString();
2421
- }
2422
- };
2423
-
2424
2744
  // src/common/looseEqual.ts
2425
2745
  function looseCompareArrays(a, b) {
2426
2746
  if (a.length !== b.length) return false;
@@ -2493,12 +2813,12 @@ var resume = (source) => {
2493
2813
 
2494
2814
  // src/directives/model.ts
2495
2815
  var modelDirective = {
2496
- onChange: (el, values) => {
2497
- updateDomElementValue(el, values[0]);
2498
- },
2499
- onBind: (el, parseResult, _expr, _option, _dynamicOption, flags) => {
2500
- return attachDOMChangeListener(el, parseResult, flags);
2501
- }
2816
+ mount: ({ el, parseResult, flags }) => ({
2817
+ update: ({ values }) => {
2818
+ updateDomElementValue(el, values[0]);
2819
+ },
2820
+ unmount: attachDOMChangeListener(el, parseResult, flags)
2821
+ })
2502
2822
  };
2503
2823
  var updateDomElementValue = (el, value) => {
2504
2824
  const isAnInput = isInput(el);
@@ -2804,65 +3124,74 @@ var getFlags2 = (flags) => {
2804
3124
  }
2805
3125
  return result;
2806
3126
  };
3127
+ var bindOn = (el, parseResult, option, dynamicOption, flags) => {
3128
+ if (dynamicOption) {
3129
+ const values2 = parseResult.value();
3130
+ const option2 = unref(dynamicOption.value()[0]);
3131
+ if (!isString(option2)) return () => {
3132
+ };
3133
+ return attachEventListener(
3134
+ el,
3135
+ camelize(option2),
3136
+ () => parseResult.value()[0],
3137
+ flags?.join(",") ?? values2[1]
3138
+ );
3139
+ } else if (option) {
3140
+ const values2 = parseResult.value();
3141
+ return attachEventListener(
3142
+ el,
3143
+ camelize(option),
3144
+ () => parseResult.value()[0],
3145
+ flags?.join(",") ?? values2[1]
3146
+ );
3147
+ }
3148
+ const unbinders = [];
3149
+ const unbinder = () => {
3150
+ unbinders.forEach((x) => x());
3151
+ };
3152
+ const values = parseResult.value();
3153
+ const len = values.length;
3154
+ for (let i = 0; i < len; ++i) {
3155
+ let next = values[i];
3156
+ if (isFunction(next)) next = next();
3157
+ if (isObject(next)) {
3158
+ for (const item of Object.entries(next)) {
3159
+ const eventType = item[0];
3160
+ const method = () => {
3161
+ let obj = parseResult.value()[i];
3162
+ if (isFunction(obj)) obj = obj();
3163
+ obj = obj[eventType];
3164
+ if (isFunction(obj)) obj = obj();
3165
+ return obj;
3166
+ };
3167
+ const flags2 = next[eventType + "_flags"];
3168
+ unbinders.push(attachEventListener(el, eventType, method, flags2));
3169
+ }
3170
+ } else {
3171
+ warning(2 /* BindingRequiresObjectExpressions */, "r-on", el);
3172
+ }
3173
+ }
3174
+ return unbinder;
3175
+ };
2807
3176
  var onDirective = {
2808
3177
  isLazy: (i, d) => d === -1 && i % 2 === 0,
2809
3178
  isLazyKey: (key, d) => d === 0 && !key.endsWith("_flags"),
2810
3179
  once: false,
2811
3180
  collectRefObj: true,
2812
- onBind: (el, parseResult, _expr, option, dynamicOption, flags) => {
2813
- if (dynamicOption) {
2814
- const values2 = parseResult.value();
2815
- const option2 = unref(dynamicOption.value()[0]);
2816
- if (!isString(option2)) return () => {
2817
- };
2818
- return attachEventListener(
2819
- el,
2820
- camelize(option2),
2821
- () => parseResult.value()[0],
2822
- flags?.join(",") ?? values2[1]
2823
- );
2824
- } else if (option) {
2825
- const values2 = parseResult.value();
2826
- return attachEventListener(
2827
- el,
2828
- camelize(option),
2829
- () => parseResult.value()[0],
2830
- flags?.join(",") ?? values2[1]
2831
- );
2832
- }
2833
- const unbinders = [];
2834
- const unbinder = () => {
2835
- unbinders.forEach((x) => x());
2836
- };
2837
- const values = parseResult.value();
2838
- const len = values.length;
2839
- for (let i = 0; i < len; ++i) {
2840
- let next = values[i];
2841
- if (isFunction(next)) next = next();
2842
- if (isObject(next)) {
2843
- for (const item of Object.entries(next)) {
2844
- const eventType = item[0];
2845
- const method = () => {
2846
- let obj = parseResult.value()[i];
2847
- if (isFunction(obj)) obj = obj();
2848
- obj = obj[eventType];
2849
- if (isFunction(obj)) obj = obj();
2850
- return obj;
2851
- };
2852
- const flags2 = next[eventType + "_flags"];
2853
- unbinders.push(attachEventListener(el, eventType, method, flags2));
2854
- }
2855
- } else {
2856
- warning(2 /* BindingRequiresObjectExpressions */, "r-on", el);
2857
- }
2858
- }
2859
- return unbinder;
3181
+ mount: ({ el, parseResult, option, dynamicOption, flags }) => {
3182
+ return bindOn(
3183
+ el,
3184
+ parseResult,
3185
+ option,
3186
+ dynamicOption,
3187
+ flags
3188
+ );
2860
3189
  }
2861
3190
  };
2862
3191
  var getShouldExecuteEvent = (eventType, flags) => {
2863
3192
  if (eventType.startsWith("keydown") || eventType.startsWith("keyup") || eventType.startsWith("keypress")) {
2864
3193
  flags ??= "";
2865
- const parts = eventType.split(".").concat(flags.split(","));
3194
+ const parts = [...eventType.split("."), ...flags.split(",")];
2866
3195
  eventType = parts[0];
2867
3196
  const keyType = parts[1];
2868
3197
  const isCtrl = parts.includes("ctrl");
@@ -2935,34 +3264,39 @@ var attachEventListener = (el, eventType, method, flags) => {
2935
3264
  };
2936
3265
 
2937
3266
  // src/directives/prop.ts
2938
- var propDirective = {
2939
- onChange: (el, values, _previousValues, option, _previousOption, flags) => {
2940
- if (option) {
2941
- if (flags && flags.includes("camel")) option = camelize(option);
2942
- patchProp(el, option, values[0]);
2943
- return;
2944
- }
2945
- const len = values.length;
2946
- for (let i = 0; i < len; ++i) {
2947
- const next = values[i];
2948
- if (isArray(next)) {
2949
- const key = next[0];
2950
- const value = next[1];
2951
- patchProp(el, key, value);
2952
- } else if (isObject(next)) {
2953
- for (const item of Object.entries(next)) {
2954
- const key = item[0];
2955
- const value = item[1];
2956
- patchProp(el, key, value);
2957
- }
2958
- } else {
2959
- const key = values[i++];
2960
- const value = values[i];
3267
+ var updatePropBinding = (el, values, option, flags) => {
3268
+ if (option) {
3269
+ if (flags && flags.includes("camel")) option = camelize(option);
3270
+ patchProp(el, option, values[0]);
3271
+ return;
3272
+ }
3273
+ const len = values.length;
3274
+ for (let i = 0; i < len; ++i) {
3275
+ const next = values[i];
3276
+ if (isArray(next)) {
3277
+ const key = next[0];
3278
+ const value = next[1];
3279
+ patchProp(el, key, value);
3280
+ } else if (isObject(next)) {
3281
+ for (const item of Object.entries(next)) {
3282
+ const key = item[0];
3283
+ const value = item[1];
2961
3284
  patchProp(el, key, value);
2962
3285
  }
3286
+ } else {
3287
+ const key = values[i++];
3288
+ const value = values[i];
3289
+ patchProp(el, key, value);
2963
3290
  }
2964
3291
  }
2965
3292
  };
3293
+ var propDirective = {
3294
+ mount: () => ({
3295
+ update: ({ el, values, option, flags }) => {
3296
+ updatePropBinding(el, values, option, flags);
3297
+ }
3298
+ })
3299
+ };
2966
3300
  function includeBooleanAttr2(value) {
2967
3301
  return !!value || value === "";
2968
3302
  }
@@ -3017,7 +3351,8 @@ var patchProp = (el, key, value) => {
3017
3351
  // src/directives/ref.ts
3018
3352
  var refDirective = {
3019
3353
  once: true,
3020
- onBind: (el, result, expr) => {
3354
+ mount: ({ el, parseResult, expr }) => {
3355
+ const result = parseResult;
3021
3356
  const value = result.value()[0];
3022
3357
  const isAnArray = isArray(value);
3023
3358
  const sref2 = result.refs[0];
@@ -3034,37 +3369,47 @@ var refDirective = {
3034
3369
  };
3035
3370
 
3036
3371
  // src/directives/show.ts
3372
+ var updateShow = (el, values) => {
3373
+ const data = getBindData(el).data;
3374
+ let originalDisplay = data._ord;
3375
+ if (isUndefined(originalDisplay)) {
3376
+ originalDisplay = data._ord = el.style.display;
3377
+ }
3378
+ const isVisible = !!values[0];
3379
+ if (isVisible) el.style.display = originalDisplay;
3380
+ else el.style.display = "none";
3381
+ };
3037
3382
  var showDirective = {
3038
- onChange: (el, values) => {
3039
- const data = getBindData(el).data;
3040
- let originalDisplay = data._ord;
3041
- if (isUndefined(originalDisplay)) {
3042
- originalDisplay = data._ord = el.style.display;
3383
+ mount: () => ({
3384
+ update: ({ el, values }) => {
3385
+ updateShow(el, values);
3043
3386
  }
3044
- const isVisible = !!values[0];
3045
- if (isVisible) el.style.display = originalDisplay;
3046
- else el.style.display = "none";
3047
- }
3387
+ })
3048
3388
  };
3049
3389
 
3050
3390
  // src/directives/style.ts
3051
- var styleDirective = {
3052
- onChange: (el, values, previousValues) => {
3053
- const len = values.length;
3054
- for (let i = 0; i < len; ++i) {
3055
- const next = values[i];
3056
- const previous = previousValues?.[i];
3057
- if (isArray(next)) {
3058
- const len2 = next.length;
3059
- for (let j = 0; j < len2; ++j) {
3060
- patchStyle(el, next[j], previous?.[j]);
3061
- }
3062
- } else {
3063
- patchStyle(el, next, previous);
3391
+ var updateStyle = (el, values, previousValues) => {
3392
+ const len = values.length;
3393
+ for (let i = 0; i < len; ++i) {
3394
+ const next = values[i];
3395
+ const previous = previousValues?.[i];
3396
+ if (isArray(next)) {
3397
+ const len2 = next.length;
3398
+ for (let j = 0; j < len2; ++j) {
3399
+ patchStyle(el, next[j], previous?.[j]);
3064
3400
  }
3401
+ } else {
3402
+ patchStyle(el, next, previous);
3065
3403
  }
3066
3404
  }
3067
3405
  };
3406
+ var styleDirective = {
3407
+ mount: () => ({
3408
+ update: ({ el, values, previousValues }) => {
3409
+ updateStyle(el, values, previousValues);
3410
+ }
3411
+ })
3412
+ };
3068
3413
  var patchStyle = (el, next, prev) => {
3069
3414
  const style = el.style;
3070
3415
  const isCssString = isString(next);
@@ -3172,18 +3517,25 @@ var flattenContent = (value, weakMap = /* @__PURE__ */ new WeakMap()) => {
3172
3517
  };
3173
3518
 
3174
3519
  // src/directives/text.ts
3520
+ var updateText = (el, values) => {
3521
+ const value = values[0];
3522
+ el.textContent = isSet(value) ? JSON.stringify(flatten([...value])) : isMap(value) ? JSON.stringify(flatten([...value])) : isObject(value) ? JSON.stringify(flatten(value)) : value?.toString() ?? "";
3523
+ };
3175
3524
  var textDirective = {
3176
- onChange: (el, values) => {
3177
- const value = values[0];
3178
- el.textContent = isSet(value) ? JSON.stringify(flatten([...value])) : isMap(value) ? JSON.stringify(flatten([...value])) : isObject(value) ? JSON.stringify(flatten(value)) : value?.toString() ?? "";
3179
- }
3525
+ mount: () => ({
3526
+ update: ({ el, values }) => {
3527
+ updateText(el, values);
3528
+ }
3529
+ })
3180
3530
  };
3181
3531
 
3182
3532
  // src/directives/value.ts
3183
3533
  var valueDirective = {
3184
- onChange: (el, values) => {
3185
- patchProp(el, "value", values[0]);
3186
- }
3534
+ mount: () => ({
3535
+ update: ({ el, values }) => {
3536
+ patchProp(el, "value", values[0]);
3537
+ }
3538
+ })
3187
3539
  };
3188
3540
 
3189
3541
  // src/app/RegorConfig.ts
@@ -4987,6 +5339,7 @@ var regorEval = (expr, contexts, globalContext, isLazy, isLazyKey, context, coll
4987
5339
 
4988
5340
  // src/parser/Parser.ts
4989
5341
  var astCache = {};
5342
+ var isComponentMap = (value) => !!value;
4990
5343
  var Parser = class {
4991
5344
  __contexts;
4992
5345
  __config;
@@ -4998,7 +5351,7 @@ var Parser = class {
4998
5351
  this.__contexts = [context, ...this.__contexts];
4999
5352
  }
5000
5353
  __getComponents() {
5001
- const obj = this.__contexts.map((x) => x.components).filter((x) => !!x).reverse().reduce((p, c) => {
5354
+ const obj = this.__contexts.map((x) => x.components).filter(isComponentMap).reverse().reduce((p, c) => {
5002
5355
  for (const [key, value] of Object.entries(c)) {
5003
5356
  p[key.toUpperCase()] = value;
5004
5357
  }
@@ -5009,7 +5362,7 @@ var Parser = class {
5009
5362
  __getComponentSelectors() {
5010
5363
  const selectors = [];
5011
5364
  const seen = /* @__PURE__ */ new Set();
5012
- const componentsList = this.__contexts.map((x) => x.components).filter((x) => !!x).reverse();
5365
+ const componentsList = this.__contexts.map((x) => x.components).filter(isComponentMap).reverse();
5013
5366
  for (const components of componentsList) {
5014
5367
  for (const key of Object.keys(components)) {
5015
5368
  if (seen.has(key)) continue;
@@ -5020,12 +5373,12 @@ var Parser = class {
5020
5373
  return selectors;
5021
5374
  }
5022
5375
  __parse(expression, isLazy, isLazyKey, collectRefObj, once) {
5023
- const value = sref([]);
5376
+ let currentValues = [];
5024
5377
  const stopObserverList = [];
5025
5378
  const subscribers = /* @__PURE__ */ new Set();
5026
5379
  const clearObservers = () => {
5027
- for (const stopObserver of stopObserverList) {
5028
- stopObserver();
5380
+ for (let i = 0; i < stopObserverList.length; ++i) {
5381
+ stopObserverList[i]();
5029
5382
  }
5030
5383
  stopObserverList.length = 0;
5031
5384
  };
@@ -5035,13 +5388,13 @@ var Parser = class {
5035
5388
  };
5036
5389
  const subscribe = (observer, init) => {
5037
5390
  subscribers.add(observer);
5038
- if (init) observer(value());
5391
+ if (init) observer(currentValues);
5039
5392
  return () => {
5040
5393
  subscribers.delete(observer);
5041
5394
  };
5042
5395
  };
5043
5396
  const result = {
5044
- value,
5397
+ value: () => currentValues,
5045
5398
  stop: unbinder,
5046
5399
  subscribe,
5047
5400
  refs: [],
@@ -5062,7 +5415,7 @@ var Parser = class {
5062
5415
  context,
5063
5416
  collectRefObj
5064
5417
  );
5065
- if (collectRefs2) refs.push(...r.refs);
5418
+ if (collectRefs2 && r.refs.length > 0) refs.push(...r.refs);
5066
5419
  return { value: r.value, refs: r.refs, ref: r.ref };
5067
5420
  } catch (e) {
5068
5421
  warning(6 /* ErrorLog */, `evaluation error: ${expression}`, e);
@@ -5075,36 +5428,37 @@ var Parser = class {
5075
5428
  const contexts = this.__contexts.slice();
5076
5429
  const elements = ast.elements;
5077
5430
  const len = elements.length;
5431
+ const expressionRefs = new Array(len);
5432
+ result.refs = expressionRefs;
5078
5433
  const refresh = () => {
5079
5434
  refs.length = 0;
5080
- uniqueRefs.clear();
5081
- clearObservers();
5082
- const values = new Array(len);
5083
- const expressionRefs = new Array(len);
5435
+ if (!once) {
5436
+ uniqueRefs.clear();
5437
+ clearObservers();
5438
+ }
5439
+ const nextValues = new Array(len);
5084
5440
  for (let i = 0; i < len; ++i) {
5085
5441
  const expr = elements[i];
5086
5442
  if (isLazy?.(i, -1)) {
5087
- values[i] = (e) => evaluate(expr, contexts, false, { $event: e }).value;
5443
+ nextValues[i] = (e) => evaluate(expr, contexts, false, { $event: e }).value;
5088
5444
  continue;
5089
5445
  }
5090
5446
  const evaluated = evaluate(expr, contexts, true);
5091
- values[i] = evaluated.value;
5447
+ nextValues[i] = evaluated.value;
5092
5448
  expressionRefs[i] = evaluated.ref;
5093
5449
  }
5094
5450
  if (!once) {
5095
5451
  for (const r of refs) {
5096
5452
  if (uniqueRefs.has(r)) continue;
5097
5453
  uniqueRefs.add(r);
5098
- const stopObserving = observe(r, refresh);
5099
- stopObserverList.push(stopObserving);
5454
+ stopObserverList.push(observe(r, refresh));
5100
5455
  }
5101
5456
  }
5102
- result.refs = expressionRefs;
5103
- value(values);
5457
+ currentValues = nextValues;
5104
5458
  if (subscribers.size !== 0) {
5105
5459
  for (const subscriber of subscribers) {
5106
5460
  if (!subscribers.has(subscriber)) continue;
5107
- subscriber(values);
5461
+ subscriber(currentValues);
5108
5462
  }
5109
5463
  }
5110
5464
  };
@@ -5413,8 +5767,8 @@ var toJsonTemplate = (node) => {
5413
5767
  return json;
5414
5768
  };
5415
5769
 
5416
- // src/app/createComponent.ts
5417
- var createComponent = (template, options = {}) => {
5770
+ // src/app/defineComponent.ts
5771
+ var defineComponent = (template, options = {}) => {
5418
5772
  if (isArray(options)) options = { props: options };
5419
5773
  if (isString(template)) template = { template };
5420
5774
  const context = options.context ?? (() => ({}));
@@ -5705,7 +6059,7 @@ export {
5705
6059
  computeRef,
5706
6060
  computed,
5707
6061
  createApp,
5708
- createComponent,
6062
+ defineComponent,
5709
6063
  drainUnbind,
5710
6064
  endBatch,
5711
6065
  entangle,