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.
@@ -68,7 +68,7 @@ __export(index_exports, {
68
68
  computeRef: () => computeRef,
69
69
  computed: () => computed,
70
70
  createApp: () => createApp,
71
- createComponent: () => createComponent,
71
+ defineComponent: () => defineComponent,
72
72
  drainUnbind: () => drainUnbind,
73
73
  endBatch: () => endBatch,
74
74
  entangle: () => entangle,
@@ -110,8 +110,8 @@ var bindDataSymbol = Symbol(":regor");
110
110
  // src/cleanup/unbind.ts
111
111
  var unbind = (node) => {
112
112
  const stack = [node];
113
- while (stack.length > 0) {
114
- const currentNode = stack.pop();
113
+ for (let i = 0; i < stack.length; ++i) {
114
+ const currentNode = stack[i];
115
115
  unbindSingle(currentNode);
116
116
  for (let child = currentNode.lastChild; child != null; child = child.previousSibling) {
117
117
  stack.push(child);
@@ -462,6 +462,8 @@ var setSwitchOwner = (owner, switchNodes) => {
462
462
  };
463
463
 
464
464
  // src/bind/IfBinder.ts
465
+ var noopStopObserving = () => {
466
+ };
465
467
  var mount = (nodes, binder, parent, end) => {
466
468
  const childNodes = [];
467
469
  for (const x of nodes) {
@@ -586,18 +588,14 @@ var IfBinder = class {
586
588
  const parseResult = this.__binder.__parser.__parse(expression);
587
589
  const value = parseResult.value;
588
590
  const remainingElses = this.__collectElses(nextElement, refresh);
589
- const stopObserverList = [];
591
+ let stopObserver = noopStopObserving;
590
592
  const unbinder = () => {
591
593
  parseResult.stop();
592
- for (const stopObserver of stopObserverList) {
593
- stopObserver();
594
- }
595
- stopObserverList.length = 0;
594
+ stopObserver();
595
+ stopObserver = noopStopObserving;
596
596
  };
597
597
  addUnbinder(commentBegin, unbinder);
598
- const stopObserving = parseResult.subscribe ? parseResult.subscribe(refresh) : () => {
599
- };
600
- stopObserverList.push(stopObserving);
598
+ stopObserver = parseResult.subscribe(refresh);
601
599
  return [
602
600
  {
603
601
  mount: () => {
@@ -608,8 +606,9 @@ var IfBinder = class {
608
606
  },
609
607
  isTrue: () => !!value()[0],
610
608
  isMounted: false
611
- }
612
- ].concat(remainingElses);
609
+ },
610
+ ...remainingElses
611
+ ];
613
612
  }
614
613
  }
615
614
  __bindToExpression(el, expression) {
@@ -655,29 +654,31 @@ var IfBinder = class {
655
654
  });
656
655
  };
657
656
  const collectedElses = this.__collectElses(nextElement, refresh);
658
- const stopObserverList = [];
657
+ let stopObserver = noopStopObserving;
659
658
  const unbinder = () => {
660
659
  parseResult.stop();
661
- for (const stopObserver of stopObserverList) {
662
- stopObserver();
663
- }
664
- stopObserverList.length = 0;
660
+ stopObserver();
661
+ stopObserver = noopStopObserving;
665
662
  };
666
663
  addUnbinder(commentBegin, unbinder);
667
664
  refresh();
668
- const stopObserving = parseResult.subscribe ? parseResult.subscribe(refresh) : () => {
669
- };
670
- stopObserverList.push(stopObserving);
665
+ stopObserver = parseResult.subscribe(refresh);
671
666
  }
672
667
  };
673
668
 
674
669
  // src/common/common.ts
675
670
  var getNodes = (el) => {
676
- const childNodes = isTemplate(el) ? el.content.childNodes : [el];
677
- return Array.from(childNodes).filter((x) => {
678
- const tagName = x == null ? void 0 : x.tagName;
679
- return tagName !== "SCRIPT" && tagName !== "STYLE";
680
- });
671
+ const source = isTemplate(el) ? el.content.childNodes : [el];
672
+ const result = [];
673
+ for (let i = 0; i < source.length; ++i) {
674
+ const node = source[i];
675
+ if (node.nodeType === 1) {
676
+ const tagName = node == null ? void 0 : node.tagName;
677
+ if (tagName === "SCRIPT" || tagName === "STYLE") continue;
678
+ }
679
+ result.push(node);
680
+ }
681
+ return result;
681
682
  };
682
683
  var bindChildNodes = (binder, childNodes) => {
683
684
  for (let i = 0; i < childNodes.length; ++i) {
@@ -775,7 +776,9 @@ var capitalize = cacheStringFunction((str) => {
775
776
  });
776
777
 
777
778
  // src/directives/teleport.ts
778
- var teleportDirective = {};
779
+ var teleportDirective = {
780
+ mount: () => void 0
781
+ };
779
782
 
780
783
  // src/composition/callMounted.ts
781
784
  var callMounted = (context) => {
@@ -810,12 +813,6 @@ var isScope = (value) => {
810
813
  return scopeSymbol2 in value;
811
814
  };
812
815
 
813
- // src/composition/onUnmounted.ts
814
- var onUnmounted = (onUnmounted2, noThrow) => {
815
- var _a;
816
- (_a = peekScope(noThrow)) == null ? void 0 : _a.onUnmounted.push(onUnmounted2);
817
- };
818
-
819
816
  // src/reactivity/refSymbols.ts
820
817
  var refSymbol = Symbol("ref");
821
818
  var srefSymbol = Symbol("sref");
@@ -826,6 +823,35 @@ var isRef = (value) => {
826
823
  return value != null && value[srefSymbol] === 1;
827
824
  };
828
825
 
826
+ // src/directives/context.ts
827
+ var contextDirective = {
828
+ collectRefObj: true,
829
+ mount: ({ parseResult }) => ({
830
+ update: ({ values }) => {
831
+ const ctx = parseResult.context;
832
+ const obj = values[0];
833
+ if (!isObject(obj)) return;
834
+ for (const item of Object.entries(obj)) {
835
+ const key = item[0];
836
+ const nextValue = item[1];
837
+ const ctxKey = ctx[key];
838
+ if (ctxKey === nextValue) continue;
839
+ if (isRef(ctxKey)) {
840
+ ctxKey(nextValue);
841
+ } else {
842
+ ctx[key] = nextValue;
843
+ }
844
+ }
845
+ }
846
+ })
847
+ };
848
+
849
+ // src/composition/onUnmounted.ts
850
+ var onUnmounted = (onUnmounted2, noThrow) => {
851
+ var _a;
852
+ (_a = peekScope(noThrow)) == null ? void 0 : _a.onUnmounted.push(onUnmounted2);
853
+ };
854
+
829
855
  // src/observer/observe.ts
830
856
  var observe = (source, observer, init, trackUnmount = true) => {
831
857
  if (!isRef(source))
@@ -842,37 +868,6 @@ var observe = (source, observer, init, trackUnmount = true) => {
842
868
  return stop;
843
869
  };
844
870
 
845
- // src/directives/context.ts
846
- var contextDirective = {
847
- collectRefObj: true,
848
- onBind: (_, parseResult) => {
849
- const stopObserving = observe(
850
- parseResult.value,
851
- () => {
852
- const value = parseResult.value();
853
- const ctx = parseResult.context;
854
- const obj = value[0];
855
- if (!isObject(obj)) {
856
- return;
857
- }
858
- for (const item of Object.entries(obj)) {
859
- const key = item[0];
860
- const value2 = item[1];
861
- const ctxKey = ctx[key];
862
- if (ctxKey === value2) continue;
863
- if (isRef(ctxKey)) {
864
- ctxKey(value2);
865
- } else {
866
- ctx[key] = value2;
867
- }
868
- }
869
- },
870
- true
871
- );
872
- return stopObserving;
873
- }
874
- };
875
-
876
871
  // src/reactivity/entangle.ts
877
872
  var entangle = (r1, r2) => {
878
873
  if (r1 === r2) return () => {
@@ -1200,8 +1195,8 @@ var createModelBridge = (source) => {
1200
1195
  };
1201
1196
  var singlePropDirective = {
1202
1197
  collectRefObj: true,
1203
- onBind: (_, parseResult, _expr, option, _dynamicOption, _flags) => {
1204
- if (!option) return noop;
1198
+ mount: ({ parseResult, option }) => {
1199
+ if (typeof option !== "string" || !option) return noop;
1205
1200
  const key = camelize(option);
1206
1201
  let currentSource;
1207
1202
  let bridge;
@@ -1222,44 +1217,44 @@ var singlePropDirective = {
1222
1217
  stopEntangle = entangle(source, target);
1223
1218
  currentSource = source;
1224
1219
  };
1225
- const stopObserving = observe(
1226
- parseResult.value,
1227
- () => {
1228
- var _a;
1229
- const value = (_a = parseResult.refs[0]) != null ? _a : parseResult.value()[0];
1230
- const ctx = parseResult.context;
1231
- const ctxKey = ctx[key];
1232
- if (!isRef(value)) {
1233
- if (bridge && ctxKey === bridge) {
1234
- bridge(value);
1235
- return;
1236
- }
1237
- resetSync();
1238
- if (isRef(ctxKey)) {
1239
- ctxKey(value);
1240
- return;
1241
- }
1242
- ctx[key] = value;
1220
+ const apply = () => {
1221
+ var _a;
1222
+ const value = (_a = parseResult.refs[0]) != null ? _a : parseResult.value()[0];
1223
+ const ctx = parseResult.context;
1224
+ const ctxKey = ctx[key];
1225
+ if (!isRef(value)) {
1226
+ if (bridge && ctxKey === bridge) {
1227
+ bridge(value);
1243
1228
  return;
1244
1229
  }
1245
- if (isModelBridge(value)) {
1246
- if (ctxKey === value) return;
1247
- if (isRef(ctxKey)) {
1248
- syncRefs(value, ctxKey);
1249
- } else {
1250
- ctx[key] = value;
1251
- }
1230
+ resetSync();
1231
+ if (isRef(ctxKey)) {
1232
+ ctxKey(value);
1252
1233
  return;
1253
1234
  }
1254
- if (!bridge) bridge = createModelBridge(value);
1255
- ctx[key] = bridge;
1256
- syncRefs(value, bridge);
1235
+ ctx[key] = value;
1236
+ return;
1237
+ }
1238
+ if (isModelBridge(value)) {
1239
+ if (ctxKey === value) return;
1240
+ if (isRef(ctxKey)) {
1241
+ syncRefs(value, ctxKey);
1242
+ } else {
1243
+ ctx[key] = value;
1244
+ }
1245
+ return;
1246
+ }
1247
+ if (!bridge) bridge = createModelBridge(value);
1248
+ ctx[key] = bridge;
1249
+ syncRefs(value, bridge);
1250
+ };
1251
+ return {
1252
+ update: () => {
1253
+ apply();
1257
1254
  },
1258
- true
1259
- );
1260
- return () => {
1261
- stopEntangle();
1262
- stopObserving();
1255
+ unmount: () => {
1256
+ stopEntangle();
1257
+ }
1263
1258
  };
1264
1259
  }
1265
1260
  };
@@ -1280,7 +1275,10 @@ var ComponentBinder = class {
1280
1275
  __getRegisteredComponentSelector(registeredComponents) {
1281
1276
  if (this.__registeredComponentSize !== registeredComponents.size) {
1282
1277
  const names = [...registeredComponents.keys()];
1283
- this.__registeredComponentSelector = names.concat(names.map(hyphenate)).join(",");
1278
+ this.__registeredComponentSelector = [
1279
+ ...names,
1280
+ ...names.map(hyphenate)
1281
+ ].join(",");
1284
1282
  this.__registeredComponentSize = registeredComponents.size;
1285
1283
  }
1286
1284
  return this.__registeredComponentSelector;
@@ -1357,7 +1355,10 @@ var ComponentBinder = class {
1357
1355
  definedProp
1358
1356
  ])
1359
1357
  );
1360
- for (const name of definedProps.concat(definedProps.map(hyphenate))) {
1358
+ for (const name of [
1359
+ ...definedProps,
1360
+ ...definedProps.map(hyphenate)
1361
+ ]) {
1361
1362
  const value = component2.getAttribute(name);
1362
1363
  if (value === null) continue;
1363
1364
  props[camelize(name)] = value;
@@ -1652,18 +1653,17 @@ var DirectiveCollector = class {
1652
1653
  }
1653
1654
  };
1654
1655
  const processNode = (node) => {
1655
- var _a, _b;
1656
+ var _a;
1656
1657
  const attrs = node.attributes;
1657
1658
  if (!attrs || attrs.length === 0) return;
1658
- const attrsAny = attrs;
1659
1659
  for (let i = 0; i < attrs.length; ++i) {
1660
- const name = (_b = (_a = attrsAny[i]) != null ? _a : attrs.item(i)) == null ? void 0 : _b.name;
1660
+ const name = (_a = attrs.item(i)) == null ? void 0 : _a.name;
1661
1661
  if (!name) continue;
1662
1662
  appendDirective(node, name);
1663
1663
  }
1664
1664
  };
1665
1665
  processNode(element);
1666
- if (!isRecursive) return map;
1666
+ if (!isRecursive || !element.firstElementChild) return map;
1667
1667
  const nodes = element.querySelectorAll("*");
1668
1668
  for (const node of nodes) {
1669
1669
  processNode(node);
@@ -1673,6 +1673,8 @@ var DirectiveCollector = class {
1673
1673
  };
1674
1674
 
1675
1675
  // src/bind/DynamicBinder.ts
1676
+ var noopStopObserving2 = () => {
1677
+ };
1676
1678
  var mount2 = (nodes, parent) => {
1677
1679
  for (const x of nodes) {
1678
1680
  const node = x.cloneNode(true);
@@ -1788,19 +1790,15 @@ var DynamicBinder = class {
1788
1790
  mounted.name = name;
1789
1791
  });
1790
1792
  };
1791
- const stopObserverList = [];
1793
+ let stopObserver = noopStopObserving2;
1792
1794
  const unbinder = () => {
1793
1795
  parseResult.stop();
1794
- for (const stopObserver of stopObserverList) {
1795
- stopObserver();
1796
- }
1797
- stopObserverList.length = 0;
1796
+ stopObserver();
1797
+ stopObserver = noopStopObserving2;
1798
1798
  };
1799
1799
  addUnbinder(commentBegin, unbinder);
1800
1800
  refresh();
1801
- const stopObserving = parseResult.subscribe ? parseResult.subscribe(refresh) : () => {
1802
- };
1803
- stopObserverList.push(stopObserving);
1801
+ stopObserver = parseResult.subscribe(refresh);
1804
1802
  }
1805
1803
  };
1806
1804
 
@@ -1810,6 +1808,274 @@ var unref = (value) => {
1810
1808
  return anyValue != null && anyValue[srefSymbol] === 1 ? anyValue() : anyValue;
1811
1809
  };
1812
1810
 
1811
+ // src/directives/html.ts
1812
+ var updateHtml = (el, values) => {
1813
+ const [value, replacer] = values;
1814
+ if (isFunction(replacer)) replacer(el, value);
1815
+ else el.innerHTML = value == null ? void 0 : value.toString();
1816
+ };
1817
+ var htmlDirective = {
1818
+ mount: () => ({
1819
+ update: ({ el, values }) => {
1820
+ updateHtml(el, values);
1821
+ }
1822
+ })
1823
+ };
1824
+
1825
+ // src/bind/ForBinderFastPath.ts
1826
+ var ForBinderFastPath = class _ForBinderFastPath {
1827
+ constructor(bindings) {
1828
+ __publicField(this, "__bindings");
1829
+ this.__bindings = bindings;
1830
+ }
1831
+ static __create(binder, nodes) {
1832
+ var _a, _b;
1833
+ const parser = binder.__parser;
1834
+ const config = binder.__config;
1835
+ const builtInNames = config.__builtInNames;
1836
+ const blockedBuiltIns = /* @__PURE__ */ new Set([
1837
+ builtInNames.for,
1838
+ builtInNames.if,
1839
+ builtInNames.else,
1840
+ builtInNames.elseif,
1841
+ builtInNames.pre
1842
+ ]);
1843
+ const directiveMap = config.__directiveMap;
1844
+ const contextComponents = parser.__getComponents();
1845
+ if (Object.keys(contextComponents).length > 0 || config.__componentsUpperCase.size > 0) {
1846
+ return void 0;
1847
+ }
1848
+ const collector = binder.__directiveCollector;
1849
+ const bindings = [];
1850
+ let nodeIndex = 0;
1851
+ const stack = [];
1852
+ for (let i = nodes.length - 1; i >= 0; --i) {
1853
+ stack.push(nodes[i]);
1854
+ }
1855
+ while (stack.length > 0) {
1856
+ const node = stack.pop();
1857
+ if (node.nodeType === Node.ELEMENT_NODE) {
1858
+ const el = node;
1859
+ if (el.tagName === "TEMPLATE") return void 0;
1860
+ if (el.tagName.includes("-")) return void 0;
1861
+ const tagNameUpper = camelize(el.tagName).toUpperCase();
1862
+ if (config.__componentsUpperCase.has(tagNameUpper) || contextComponents[tagNameUpper]) {
1863
+ return void 0;
1864
+ }
1865
+ const attrs = el.attributes;
1866
+ for (let i = 0; i < attrs.length; ++i) {
1867
+ const attrName = (_a = attrs.item(i)) == null ? void 0 : _a.name;
1868
+ if (!attrName) continue;
1869
+ if (blockedBuiltIns.has(attrName)) return void 0;
1870
+ const { terms, flags } = collector.__parseName(attrName);
1871
+ const [name, option] = terms;
1872
+ const directive = (_b = directiveMap[attrName]) != null ? _b : directiveMap[name];
1873
+ if (!directive) continue;
1874
+ if (directive === htmlDirective) return void 0;
1875
+ bindings.push({
1876
+ nodeIndex,
1877
+ attrName,
1878
+ directive,
1879
+ option,
1880
+ flags
1881
+ });
1882
+ }
1883
+ ++nodeIndex;
1884
+ }
1885
+ const children = node.childNodes;
1886
+ for (let i = children.length - 1; i >= 0; --i) {
1887
+ stack.push(children[i]);
1888
+ }
1889
+ }
1890
+ if (bindings.length === 0) return void 0;
1891
+ return new _ForBinderFastPath(bindings);
1892
+ }
1893
+ __bind(binder, nodes) {
1894
+ const elements = [];
1895
+ const stack = [];
1896
+ for (let i = nodes.length - 1; i >= 0; --i) {
1897
+ stack.push(nodes[i]);
1898
+ }
1899
+ while (stack.length > 0) {
1900
+ const node = stack.pop();
1901
+ if (node.nodeType === Node.ELEMENT_NODE) {
1902
+ elements.push(node);
1903
+ }
1904
+ const children = node.childNodes;
1905
+ for (let i = children.length - 1; i >= 0; --i) {
1906
+ stack.push(children[i]);
1907
+ }
1908
+ }
1909
+ for (let i = 0; i < this.__bindings.length; ++i) {
1910
+ const binding = this.__bindings[i];
1911
+ const el = elements[binding.nodeIndex];
1912
+ if (!el) continue;
1913
+ binder.__bind(
1914
+ binding.directive,
1915
+ el,
1916
+ binding.attrName,
1917
+ false,
1918
+ binding.option,
1919
+ binding.flags
1920
+ );
1921
+ }
1922
+ }
1923
+ };
1924
+
1925
+ // src/bind/ForBinderKeyedDiff.ts
1926
+ var moveMountItemBefore = (item, anchor) => {
1927
+ const parent = anchor.parentNode;
1928
+ if (!parent) return;
1929
+ for (let i = 0; i < item.items.length; ++i) {
1930
+ parent.insertBefore(item.items[i], anchor);
1931
+ }
1932
+ };
1933
+ var getSequence = (arr) => {
1934
+ var _a;
1935
+ const len = arr.length;
1936
+ const p = arr.slice();
1937
+ const result = [];
1938
+ let u;
1939
+ let v;
1940
+ let c;
1941
+ for (let i = 0; i < len; ++i) {
1942
+ const value = arr[i];
1943
+ if (value === 0) continue;
1944
+ const j = result[result.length - 1];
1945
+ if (j === void 0 || arr[j] < value) {
1946
+ p[i] = j != null ? j : -1;
1947
+ result.push(i);
1948
+ continue;
1949
+ }
1950
+ u = 0;
1951
+ v = result.length - 1;
1952
+ while (u < v) {
1953
+ c = u + v >> 1;
1954
+ if (arr[result[c]] < value) u = c + 1;
1955
+ else v = c;
1956
+ }
1957
+ if (value < arr[result[u]]) {
1958
+ if (u > 0) p[i] = result[u - 1];
1959
+ result[u] = i;
1960
+ }
1961
+ }
1962
+ u = result.length;
1963
+ v = (_a = result[u - 1]) != null ? _a : -1;
1964
+ while (u-- > 0) {
1965
+ result[u] = v;
1966
+ v = p[v];
1967
+ }
1968
+ return result;
1969
+ };
1970
+ var ForBinderKeyedDiff = class {
1971
+ /**
1972
+ * Applies keyed patch and returns the next ordered mount list.
1973
+ * Returns `undefined` when keyed mode is not safe for this update.
1974
+ */
1975
+ static __patch(options) {
1976
+ const {
1977
+ oldItems,
1978
+ newValues,
1979
+ getKey,
1980
+ isSameValue,
1981
+ mountNewValue,
1982
+ removeMountItem,
1983
+ endAnchor
1984
+ } = options;
1985
+ const oldLen = oldItems.length;
1986
+ const newLen = newValues.length;
1987
+ const newKeys = new Array(newLen);
1988
+ const keySeen = /* @__PURE__ */ new Set();
1989
+ for (let i2 = 0; i2 < newLen; ++i2) {
1990
+ const key = getKey(newValues[i2]);
1991
+ if (key === void 0 || keySeen.has(key)) return void 0;
1992
+ keySeen.add(key);
1993
+ newKeys[i2] = key;
1994
+ }
1995
+ const newMountItems = new Array(newLen);
1996
+ let i = 0;
1997
+ let e1 = oldLen - 1;
1998
+ let e2 = newLen - 1;
1999
+ while (i <= e1 && i <= e2) {
2000
+ const oldItem = oldItems[i];
2001
+ if (getKey(oldItem.value) !== newKeys[i]) break;
2002
+ if (!isSameValue(oldItem.value, newValues[i])) break;
2003
+ oldItem.value = newValues[i];
2004
+ newMountItems[i] = oldItem;
2005
+ ++i;
2006
+ }
2007
+ while (i <= e1 && i <= e2) {
2008
+ const oldItem = oldItems[e1];
2009
+ if (getKey(oldItem.value) !== newKeys[e2]) break;
2010
+ if (!isSameValue(oldItem.value, newValues[e2])) break;
2011
+ oldItem.value = newValues[e2];
2012
+ newMountItems[e2] = oldItem;
2013
+ --e1;
2014
+ --e2;
2015
+ }
2016
+ if (i > e1) {
2017
+ for (let k = e2; k >= i; --k) {
2018
+ const anchor = k + 1 < newLen ? newMountItems[k + 1].items[0] : endAnchor;
2019
+ newMountItems[k] = mountNewValue(k, newValues[k], anchor);
2020
+ }
2021
+ return newMountItems;
2022
+ }
2023
+ if (i > e2) {
2024
+ for (let k = i; k <= e1; ++k) removeMountItem(oldItems[k]);
2025
+ return newMountItems;
2026
+ }
2027
+ const s1 = i;
2028
+ const s2 = i;
2029
+ const toBePatched = e2 - s2 + 1;
2030
+ const newIndexToOldIndexMap = new Array(toBePatched).fill(0);
2031
+ const keyToNewIndexMap = /* @__PURE__ */ new Map();
2032
+ for (let k = s2; k <= e2; ++k) {
2033
+ keyToNewIndexMap.set(newKeys[k], k);
2034
+ }
2035
+ let moved = false;
2036
+ let maxNewIndexSoFar = 0;
2037
+ for (let k = s1; k <= e1; ++k) {
2038
+ const oldItem = oldItems[k];
2039
+ const newIndex = keyToNewIndexMap.get(getKey(oldItem.value));
2040
+ if (newIndex === void 0) {
2041
+ removeMountItem(oldItem);
2042
+ continue;
2043
+ }
2044
+ if (!isSameValue(oldItem.value, newValues[newIndex])) {
2045
+ removeMountItem(oldItem);
2046
+ continue;
2047
+ }
2048
+ oldItem.value = newValues[newIndex];
2049
+ newMountItems[newIndex] = oldItem;
2050
+ newIndexToOldIndexMap[newIndex - s2] = k + 1;
2051
+ if (newIndex >= maxNewIndexSoFar) maxNewIndexSoFar = newIndex;
2052
+ else moved = true;
2053
+ }
2054
+ const increasingNewIndexSequence = moved ? getSequence(newIndexToOldIndexMap) : [];
2055
+ let seqIdx = increasingNewIndexSequence.length - 1;
2056
+ for (let k = toBePatched - 1; k >= 0; --k) {
2057
+ const newIndex = s2 + k;
2058
+ const anchor = newIndex + 1 < newLen ? newMountItems[newIndex + 1].items[0] : endAnchor;
2059
+ if (newIndexToOldIndexMap[k] === 0) {
2060
+ newMountItems[newIndex] = mountNewValue(
2061
+ newIndex,
2062
+ newValues[newIndex],
2063
+ anchor
2064
+ );
2065
+ continue;
2066
+ }
2067
+ const item = newMountItems[newIndex];
2068
+ if (!moved) continue;
2069
+ if (seqIdx >= 0 && increasingNewIndexSequence[seqIdx] === k) {
2070
+ --seqIdx;
2071
+ } else if (item) {
2072
+ moveMountItemBefore(item, anchor);
2073
+ }
2074
+ }
2075
+ return newMountItems;
2076
+ }
2077
+ };
2078
+
1813
2079
  // src/bind/MountList.ts
1814
2080
  var MountList = class {
1815
2081
  constructor(getKey) {
@@ -1891,6 +2157,8 @@ var MountList = class {
1891
2157
  // src/bind/ForBinder.ts
1892
2158
  var forMarker = Symbol("r-for");
1893
2159
  var noIndexRef = (_) => -1;
2160
+ var noopStopObserving3 = () => {
2161
+ };
1894
2162
  var _ForBinder = class _ForBinder {
1895
2163
  constructor(binder) {
1896
2164
  __publicField(this, "__binder");
@@ -1961,6 +2229,7 @@ var _ForBinder = class _ForBinder {
1961
2229
  el.removeAttribute(nameKey);
1962
2230
  el.removeAttribute(nameKeyBind);
1963
2231
  const nodes = getNodes(el);
2232
+ const fastPath = ForBinderFastPath.__create(this.__binder, nodes);
1964
2233
  const parent = el.parentNode;
1965
2234
  if (!parent) return;
1966
2235
  const title = `${this.__for} => ${forPath}`;
@@ -1980,6 +2249,7 @@ var _ForBinder = class _ForBinder {
1980
2249
  const rowContexts = singleCapturedContext ? [void 0, capturedContext[0]] : void 0;
1981
2250
  const getKey = this.__createKeyGetter(keyExpression);
1982
2251
  const areEqual = (a, b) => getKey(a) === getKey(b);
2252
+ const isSameValue = (a, b) => a === b;
1983
2253
  const mountNewValue = (i2, newValue, nextSibling) => {
1984
2254
  const result = config.createContext(newValue, i2);
1985
2255
  const mountItem = MountList.__createItem(result.index, newValue);
@@ -1993,7 +2263,8 @@ var _ForBinder = class _ForBinder {
1993
2263
  insertParent.insertBefore(node, nextSibling);
1994
2264
  childNodes.push(node);
1995
2265
  }
1996
- bindChildNodes(binder, childNodes);
2266
+ if (fastPath) fastPath.__bind(binder, childNodes);
2267
+ else bindChildNodes(binder, childNodes);
1997
2268
  start = start.nextSibling;
1998
2269
  while (start !== nextSibling) {
1999
2270
  mountItem.items.push(start);
@@ -2045,16 +2316,51 @@ var _ForBinder = class _ForBinder {
2045
2316
  mountList.__removeAllAfter(0);
2046
2317
  return;
2047
2318
  }
2319
+ const iterableValues = [];
2320
+ for (const value2 of this.__getIterable(newValues[0])) {
2321
+ iterableValues.push(value2);
2322
+ }
2323
+ const patched = ForBinderKeyedDiff.__patch({
2324
+ oldItems: mountList.__list,
2325
+ newValues: iterableValues,
2326
+ getKey,
2327
+ isSameValue,
2328
+ mountNewValue: (index, value2, nextSibling) => mountNewValue(index, value2, nextSibling),
2329
+ removeMountItem: (item) => {
2330
+ for (let k = 0; k < item.items.length; ++k) {
2331
+ removeNode(item.items[k]);
2332
+ }
2333
+ },
2334
+ endAnchor: commentEnd
2335
+ });
2336
+ if (patched) {
2337
+ mountList.__list = patched;
2338
+ mountList.__valueMap.clear();
2339
+ for (let k = 0; k < patched.length; ++k) {
2340
+ const item = patched[k];
2341
+ item.order = k;
2342
+ item.index(k);
2343
+ const key = getKey(item.value);
2344
+ if (key !== void 0) {
2345
+ mountList.__valueMap.set(key, item);
2346
+ }
2347
+ }
2348
+ return;
2349
+ }
2048
2350
  let i2 = 0;
2049
2351
  let firstRemovalOrInsertionIndex = Number.MAX_SAFE_INTEGER;
2050
2352
  const initialLength = len;
2051
2353
  const forGrowThreshold = this.__binder.__config.forGrowThreshold;
2052
2354
  const shouldGrowList = () => mountList.__length < initialLength + forGrowThreshold;
2053
- for (const newValue of this.__getIterable(newValues[0])) {
2355
+ for (const newValue of iterableValues) {
2054
2356
  const modify = () => {
2055
2357
  if (i2 < len) {
2056
2358
  const mountItem = mountList.__get(i2++);
2057
- if (areEqual(mountItem.value, newValue)) return;
2359
+ if (areEqual(mountItem.value, newValue)) {
2360
+ if (isSameValue(mountItem.value, newValue)) return;
2361
+ replace(i2 - 1, newValue);
2362
+ return;
2363
+ }
2058
2364
  const newValueMountPosition = mountList.__lookupValueOrderIfMounted(
2059
2365
  getKey(newValue)
2060
2366
  );
@@ -2104,24 +2410,21 @@ var _ForBinder = class _ForBinder {
2104
2410
  mountList.__removeAllAfter(j);
2105
2411
  updateIndexes(firstRemovalOrInsertionIndex);
2106
2412
  };
2107
- const observeTailChanges = () => {
2108
- stopObserving = parseResult.subscribe ? parseResult.subscribe(updateDom) : () => {
2109
- };
2110
- };
2111
2413
  const unbinder = () => {
2112
2414
  parseResult.stop();
2113
2415
  stopObserving();
2416
+ stopObserving = noopStopObserving3;
2114
2417
  };
2115
2418
  const parseResult = parser.__parse(config.list);
2116
2419
  const value = parseResult.value;
2117
- let stopObserving;
2420
+ let stopObserving = noopStopObserving3;
2118
2421
  let i = 0;
2119
2422
  const mountList = new MountList(getKey);
2120
2423
  for (const item of this.__getIterable(value()[0])) {
2121
2424
  mountList.__push(mountNewValue(i++, item, commentEnd));
2122
2425
  }
2123
2426
  addUnbinder(commentBegin, unbinder);
2124
- observeTailChanges();
2427
+ stopObserving = parseResult.subscribe(updateDom);
2125
2428
  }
2126
2429
  __parseForPath(forPath) {
2127
2430
  var _a, _b;
@@ -2305,105 +2608,111 @@ var Binder = class {
2305
2608
  return true;
2306
2609
  }
2307
2610
  __bindToExpression(config, el, valueExpression, option, flags) {
2308
- var _a;
2309
2611
  if (el.nodeType !== Node.ELEMENT_NODE || valueExpression == null) return;
2310
2612
  if (this.__handleTeleport(config, el, valueExpression)) return;
2311
- const result = this.__parser.__parse(
2613
+ const dynamicOption = this.__parseDynamicOption(option, config.once);
2614
+ const result = this.__parseExpression(config, valueExpression);
2615
+ const stops = this.__createBindStops(result, dynamicOption);
2616
+ addUnbinder(el, stops.stop);
2617
+ const payload = this.__createDirectivePayload(
2618
+ el,
2619
+ valueExpression,
2620
+ result,
2621
+ dynamicOption,
2622
+ option,
2623
+ flags
2624
+ );
2625
+ const mountedUpdate = this.__mountDirective(config, payload, stops);
2626
+ if (!mountedUpdate) return;
2627
+ const emitChange = this.__createEmitter(
2628
+ payload,
2629
+ result,
2630
+ dynamicOption,
2631
+ option,
2632
+ mountedUpdate
2633
+ );
2634
+ emitChange();
2635
+ if (!config.once) {
2636
+ stops.result = result.subscribe(emitChange);
2637
+ if (dynamicOption) {
2638
+ stops.dynamic = dynamicOption.subscribe(emitChange);
2639
+ }
2640
+ }
2641
+ }
2642
+ __parseDynamicOption(option, once) {
2643
+ const dynamicOptionExpression = isOptionDynamic(option, this.__dynamic);
2644
+ if (!dynamicOptionExpression) return void 0;
2645
+ return this.__parser.__parse(
2646
+ camelize(dynamicOptionExpression),
2647
+ void 0,
2648
+ void 0,
2649
+ void 0,
2650
+ once
2651
+ );
2652
+ }
2653
+ __parseExpression(config, valueExpression) {
2654
+ return this.__parser.__parse(
2312
2655
  valueExpression,
2313
2656
  config.isLazy,
2314
2657
  config.isLazyKey,
2315
2658
  config.collectRefObj,
2316
2659
  config.once
2317
2660
  );
2318
- const stopObserverList = [];
2319
- const hasOnChange = !!config.onChange;
2320
- const unbinder = () => {
2321
- result.stop();
2322
- dynamicOption == null ? void 0 : dynamicOption.stop();
2323
- for (let i = 0; i < stopObserverList.length; ++i) {
2324
- stopObserverList[i]();
2661
+ }
2662
+ __createBindStops(result, dynamicOption) {
2663
+ const stops = {
2664
+ stop: () => {
2665
+ var _a, _b, _c;
2666
+ result.stop();
2667
+ dynamicOption == null ? void 0 : dynamicOption.stop();
2668
+ (_a = stops.result) == null ? void 0 : _a.call(stops);
2669
+ (_b = stops.dynamic) == null ? void 0 : _b.call(stops);
2670
+ (_c = stops.mounted) == null ? void 0 : _c.call(stops);
2671
+ stops.result = void 0;
2672
+ stops.dynamic = void 0;
2673
+ stops.mounted = void 0;
2325
2674
  }
2326
- stopObserverList.length = 0;
2327
2675
  };
2328
- addUnbinder(el, unbinder);
2329
- const dynamicOptionExpression = isOptionDynamic(option, this.__dynamic);
2330
- let dynamicOption;
2331
- if (dynamicOptionExpression) {
2332
- dynamicOption = this.__parser.__parse(
2333
- camelize(dynamicOptionExpression),
2334
- void 0,
2335
- void 0,
2336
- void 0,
2337
- config.once
2338
- );
2676
+ return stops;
2677
+ }
2678
+ __createDirectivePayload(el, expr, result, dynamicOption, option, flags) {
2679
+ return {
2680
+ el,
2681
+ expr,
2682
+ values: result.value(),
2683
+ previousValues: void 0,
2684
+ option: dynamicOption ? dynamicOption.value()[0] : option,
2685
+ previousOption: void 0,
2686
+ flags,
2687
+ parseResult: result,
2688
+ dynamicOption
2689
+ };
2690
+ }
2691
+ __mountDirective(config, payload, stops) {
2692
+ const mounted = config.mount(payload);
2693
+ if (typeof mounted === "function") {
2694
+ stops.mounted = mounted;
2695
+ return void 0;
2339
2696
  }
2340
- const dynamicOpt = dynamicOption;
2341
- const hasDynamicOption = dynamicOpt != null;
2342
- let previousValues = result.value();
2343
- let previousOption = hasDynamicOption ? dynamicOption.value()[0] : option;
2344
- if (!config.once && hasOnChange) {
2345
- const stopObserving = result.subscribe ? result.subscribe(() => {
2346
- var _a2;
2347
- const preValues = previousValues;
2348
- const preOption = previousOption;
2349
- const nextValues = result.value();
2350
- const nextOption = hasDynamicOption ? dynamicOpt.value()[0] : option;
2351
- previousValues = nextValues;
2352
- previousOption = nextOption;
2353
- (_a2 = config.onChange) == null ? void 0 : _a2.call(
2354
- config,
2355
- el,
2356
- nextValues,
2357
- preValues,
2358
- nextOption,
2359
- preOption,
2360
- flags
2361
- );
2362
- }) : () => {
2363
- };
2364
- stopObserverList.push(stopObserving);
2365
- if (dynamicOpt) {
2366
- const stopObserving2 = dynamicOpt.subscribe ? dynamicOpt.subscribe(() => {
2367
- var _a2;
2368
- const preOption = previousOption;
2369
- const nextValues = result.value();
2370
- const nextOption = dynamicOpt.value()[0];
2371
- previousValues = nextValues;
2372
- previousOption = nextOption;
2373
- (_a2 = config.onChange) == null ? void 0 : _a2.call(
2374
- config,
2375
- el,
2376
- nextValues,
2377
- preOption,
2378
- nextOption,
2379
- preOption,
2380
- flags
2381
- );
2382
- }) : () => {
2383
- };
2384
- stopObserverList.push(stopObserving2);
2385
- }
2697
+ if (mounted == null ? void 0 : mounted.unmount) {
2698
+ stops.mounted = mounted.unmount;
2386
2699
  }
2387
- if (config.onBind)
2388
- stopObserverList.push(
2389
- config.onBind(
2390
- el,
2391
- result,
2392
- valueExpression,
2393
- option,
2394
- dynamicOption,
2395
- flags
2396
- )
2397
- );
2398
- (_a = config.onChange) == null ? void 0 : _a.call(
2399
- config,
2400
- el,
2401
- previousValues,
2402
- void 0,
2403
- previousOption,
2404
- void 0,
2405
- flags
2406
- );
2700
+ return mounted == null ? void 0 : mounted.update;
2701
+ }
2702
+ __createEmitter(payload, result, dynamicOption, option, mountedUpdate) {
2703
+ let previousValues;
2704
+ let previousOption;
2705
+ return () => {
2706
+ const nextValues = result.value();
2707
+ const nextOption = dynamicOption ? dynamicOption.value()[0] : option;
2708
+ payload.values = nextValues;
2709
+ payload.previousValues = previousValues;
2710
+ payload.option = nextOption;
2711
+ payload.previousOption = previousOption;
2712
+ previousValues = nextValues;
2713
+ previousOption = nextOption;
2714
+ mountedUpdate(payload);
2715
+ };
2407
2716
  }
2408
2717
  };
2409
2718
 
@@ -2440,39 +2749,51 @@ var booleanAttributes = {
2440
2749
  function includeBooleanAttr(value) {
2441
2750
  return !!value || value === "";
2442
2751
  }
2443
- var attrDirective = {
2444
- onChange: (el, values, previousValues, option, previousOption, flags) => {
2445
- var _a;
2446
- if (option) {
2447
- if (flags && flags.includes("camel")) option = camelize(option);
2448
- patchAttribute(el, option, values[0], previousOption);
2449
- return;
2450
- }
2451
- const len = values.length;
2452
- for (let i = 0; i < len; ++i) {
2453
- const next = values[i];
2454
- if (isArray(next)) {
2455
- const previousKey = (_a = previousValues == null ? void 0 : previousValues[i]) == null ? void 0 : _a[0];
2456
- const key = next[0];
2457
- const value = next[1];
2458
- patchAttribute(el, key, value, previousKey);
2459
- } else if (isObject(next)) {
2460
- for (const item of Object.entries(next)) {
2461
- const key = item[0];
2462
- const value = item[1];
2463
- const p = previousValues == null ? void 0 : previousValues[i];
2464
- const previousKey = p && key in p ? key : void 0;
2465
- patchAttribute(el, key, value, previousKey);
2466
- }
2467
- } else {
2468
- const previousKey = previousValues == null ? void 0 : previousValues[i];
2469
- const key = values[i++];
2470
- const value = values[i];
2752
+ var updateAttr = (el, values, previousValues, option, previousOption, flags) => {
2753
+ var _a;
2754
+ if (option) {
2755
+ if (flags && flags.includes("camel")) option = camelize(option);
2756
+ patchAttribute(el, option, values[0], previousOption);
2757
+ return;
2758
+ }
2759
+ const len = values.length;
2760
+ for (let i = 0; i < len; ++i) {
2761
+ const next = values[i];
2762
+ if (isArray(next)) {
2763
+ const previousKey = (_a = previousValues == null ? void 0 : previousValues[i]) == null ? void 0 : _a[0];
2764
+ const key = next[0];
2765
+ const value = next[1];
2766
+ patchAttribute(el, key, value, previousKey);
2767
+ } else if (isObject(next)) {
2768
+ for (const item of Object.entries(next)) {
2769
+ const key = item[0];
2770
+ const value = item[1];
2771
+ const p = previousValues == null ? void 0 : previousValues[i];
2772
+ const previousKey = p && key in p ? key : void 0;
2471
2773
  patchAttribute(el, key, value, previousKey);
2472
2774
  }
2775
+ } else {
2776
+ const previousKey = previousValues == null ? void 0 : previousValues[i];
2777
+ const key = values[i++];
2778
+ const value = values[i];
2779
+ patchAttribute(el, key, value, previousKey);
2473
2780
  }
2474
2781
  }
2475
2782
  };
2783
+ var attrDirective = {
2784
+ mount: () => ({
2785
+ update: ({ el, values, previousValues, option, previousOption, flags }) => {
2786
+ updateAttr(
2787
+ el,
2788
+ values,
2789
+ previousValues,
2790
+ option,
2791
+ previousOption,
2792
+ flags
2793
+ );
2794
+ }
2795
+ })
2796
+ };
2476
2797
  var patchAttribute = (el, key, value, previousKey) => {
2477
2798
  if (previousKey && previousKey !== key) {
2478
2799
  el.removeAttribute(previousKey);
@@ -2506,23 +2827,28 @@ var patchAttribute = (el, key, value, previousKey) => {
2506
2827
  };
2507
2828
 
2508
2829
  // src/directives/class.ts
2509
- var classDirective = {
2510
- onChange: (el, values, previousValues) => {
2511
- const len = values.length;
2512
- for (let i = 0; i < len; ++i) {
2513
- const next = values[i];
2514
- const previous = previousValues == null ? void 0 : previousValues[i];
2515
- if (isArray(next)) {
2516
- const len2 = next.length;
2517
- for (let j = 0; j < len2; ++j) {
2518
- patchClass(el, next[j], previous == null ? void 0 : previous[j]);
2519
- }
2520
- } else {
2521
- patchClass(el, next, previous);
2830
+ var updateClass = (el, values, previousValues) => {
2831
+ const len = values.length;
2832
+ for (let i = 0; i < len; ++i) {
2833
+ const next = values[i];
2834
+ const previous = previousValues == null ? void 0 : previousValues[i];
2835
+ if (isArray(next)) {
2836
+ const len2 = next.length;
2837
+ for (let j = 0; j < len2; ++j) {
2838
+ patchClass(el, next[j], previous == null ? void 0 : previous[j]);
2522
2839
  }
2840
+ } else {
2841
+ patchClass(el, next, previous);
2523
2842
  }
2524
2843
  }
2525
2844
  };
2845
+ var classDirective = {
2846
+ mount: () => ({
2847
+ update: ({ el, values, previousValues }) => {
2848
+ updateClass(el, values, previousValues);
2849
+ }
2850
+ })
2851
+ };
2526
2852
  var patchClass = (el, next, prev) => {
2527
2853
  const classList = el.classList;
2528
2854
  const isClassString = isString(next);
@@ -2550,15 +2876,6 @@ var patchClass = (el, next, prev) => {
2550
2876
  }
2551
2877
  };
2552
2878
 
2553
- // src/directives/html.ts
2554
- var htmlDirective = {
2555
- onChange: (el, values) => {
2556
- const [value, replacer] = values;
2557
- if (isFunction(replacer)) replacer(el, value);
2558
- else el.innerHTML = value == null ? void 0 : value.toString();
2559
- }
2560
- };
2561
-
2562
2879
  // src/common/looseEqual.ts
2563
2880
  function looseCompareArrays(a, b) {
2564
2881
  if (a.length !== b.length) return false;
@@ -2631,12 +2948,12 @@ var resume = (source) => {
2631
2948
 
2632
2949
  // src/directives/model.ts
2633
2950
  var modelDirective = {
2634
- onChange: (el, values) => {
2635
- updateDomElementValue(el, values[0]);
2636
- },
2637
- onBind: (el, parseResult, _expr, _option, _dynamicOption, flags) => {
2638
- return attachDOMChangeListener(el, parseResult, flags);
2639
- }
2951
+ mount: ({ el, parseResult, flags }) => ({
2952
+ update: ({ values }) => {
2953
+ updateDomElementValue(el, values[0]);
2954
+ },
2955
+ unmount: attachDOMChangeListener(el, parseResult, flags)
2956
+ })
2640
2957
  };
2641
2958
  var updateDomElementValue = (el, value) => {
2642
2959
  const isAnInput = isInput(el);
@@ -2942,66 +3259,75 @@ var getFlags2 = (flags) => {
2942
3259
  }
2943
3260
  return result;
2944
3261
  };
3262
+ var bindOn = (el, parseResult, option, dynamicOption, flags) => {
3263
+ var _a, _b;
3264
+ if (dynamicOption) {
3265
+ const values2 = parseResult.value();
3266
+ const option2 = unref(dynamicOption.value()[0]);
3267
+ if (!isString(option2)) return () => {
3268
+ };
3269
+ return attachEventListener(
3270
+ el,
3271
+ camelize(option2),
3272
+ () => parseResult.value()[0],
3273
+ (_a = flags == null ? void 0 : flags.join(",")) != null ? _a : values2[1]
3274
+ );
3275
+ } else if (option) {
3276
+ const values2 = parseResult.value();
3277
+ return attachEventListener(
3278
+ el,
3279
+ camelize(option),
3280
+ () => parseResult.value()[0],
3281
+ (_b = flags == null ? void 0 : flags.join(",")) != null ? _b : values2[1]
3282
+ );
3283
+ }
3284
+ const unbinders = [];
3285
+ const unbinder = () => {
3286
+ unbinders.forEach((x) => x());
3287
+ };
3288
+ const values = parseResult.value();
3289
+ const len = values.length;
3290
+ for (let i = 0; i < len; ++i) {
3291
+ let next = values[i];
3292
+ if (isFunction(next)) next = next();
3293
+ if (isObject(next)) {
3294
+ for (const item of Object.entries(next)) {
3295
+ const eventType = item[0];
3296
+ const method = () => {
3297
+ let obj = parseResult.value()[i];
3298
+ if (isFunction(obj)) obj = obj();
3299
+ obj = obj[eventType];
3300
+ if (isFunction(obj)) obj = obj();
3301
+ return obj;
3302
+ };
3303
+ const flags2 = next[eventType + "_flags"];
3304
+ unbinders.push(attachEventListener(el, eventType, method, flags2));
3305
+ }
3306
+ } else {
3307
+ warning(2 /* BindingRequiresObjectExpressions */, "r-on", el);
3308
+ }
3309
+ }
3310
+ return unbinder;
3311
+ };
2945
3312
  var onDirective = {
2946
3313
  isLazy: (i, d) => d === -1 && i % 2 === 0,
2947
3314
  isLazyKey: (key, d) => d === 0 && !key.endsWith("_flags"),
2948
3315
  once: false,
2949
3316
  collectRefObj: true,
2950
- onBind: (el, parseResult, _expr, option, dynamicOption, flags) => {
2951
- var _a, _b;
2952
- if (dynamicOption) {
2953
- const values2 = parseResult.value();
2954
- const option2 = unref(dynamicOption.value()[0]);
2955
- if (!isString(option2)) return () => {
2956
- };
2957
- return attachEventListener(
2958
- el,
2959
- camelize(option2),
2960
- () => parseResult.value()[0],
2961
- (_a = flags == null ? void 0 : flags.join(",")) != null ? _a : values2[1]
2962
- );
2963
- } else if (option) {
2964
- const values2 = parseResult.value();
2965
- return attachEventListener(
2966
- el,
2967
- camelize(option),
2968
- () => parseResult.value()[0],
2969
- (_b = flags == null ? void 0 : flags.join(",")) != null ? _b : values2[1]
2970
- );
2971
- }
2972
- const unbinders = [];
2973
- const unbinder = () => {
2974
- unbinders.forEach((x) => x());
2975
- };
2976
- const values = parseResult.value();
2977
- const len = values.length;
2978
- for (let i = 0; i < len; ++i) {
2979
- let next = values[i];
2980
- if (isFunction(next)) next = next();
2981
- if (isObject(next)) {
2982
- for (const item of Object.entries(next)) {
2983
- const eventType = item[0];
2984
- const method = () => {
2985
- let obj = parseResult.value()[i];
2986
- if (isFunction(obj)) obj = obj();
2987
- obj = obj[eventType];
2988
- if (isFunction(obj)) obj = obj();
2989
- return obj;
2990
- };
2991
- const flags2 = next[eventType + "_flags"];
2992
- unbinders.push(attachEventListener(el, eventType, method, flags2));
2993
- }
2994
- } else {
2995
- warning(2 /* BindingRequiresObjectExpressions */, "r-on", el);
2996
- }
2997
- }
2998
- return unbinder;
3317
+ mount: ({ el, parseResult, option, dynamicOption, flags }) => {
3318
+ return bindOn(
3319
+ el,
3320
+ parseResult,
3321
+ option,
3322
+ dynamicOption,
3323
+ flags
3324
+ );
2999
3325
  }
3000
3326
  };
3001
3327
  var getShouldExecuteEvent = (eventType, flags) => {
3002
3328
  if (eventType.startsWith("keydown") || eventType.startsWith("keyup") || eventType.startsWith("keypress")) {
3003
3329
  flags != null ? flags : flags = "";
3004
- const parts = eventType.split(".").concat(flags.split(","));
3330
+ const parts = [...eventType.split("."), ...flags.split(",")];
3005
3331
  eventType = parts[0];
3006
3332
  const keyType = parts[1];
3007
3333
  const isCtrl = parts.includes("ctrl");
@@ -3074,34 +3400,39 @@ var attachEventListener = (el, eventType, method, flags) => {
3074
3400
  };
3075
3401
 
3076
3402
  // src/directives/prop.ts
3077
- var propDirective = {
3078
- onChange: (el, values, _previousValues, option, _previousOption, flags) => {
3079
- if (option) {
3080
- if (flags && flags.includes("camel")) option = camelize(option);
3081
- patchProp(el, option, values[0]);
3082
- return;
3083
- }
3084
- const len = values.length;
3085
- for (let i = 0; i < len; ++i) {
3086
- const next = values[i];
3087
- if (isArray(next)) {
3088
- const key = next[0];
3089
- const value = next[1];
3090
- patchProp(el, key, value);
3091
- } else if (isObject(next)) {
3092
- for (const item of Object.entries(next)) {
3093
- const key = item[0];
3094
- const value = item[1];
3095
- patchProp(el, key, value);
3096
- }
3097
- } else {
3098
- const key = values[i++];
3099
- const value = values[i];
3403
+ var updatePropBinding = (el, values, option, flags) => {
3404
+ if (option) {
3405
+ if (flags && flags.includes("camel")) option = camelize(option);
3406
+ patchProp(el, option, values[0]);
3407
+ return;
3408
+ }
3409
+ const len = values.length;
3410
+ for (let i = 0; i < len; ++i) {
3411
+ const next = values[i];
3412
+ if (isArray(next)) {
3413
+ const key = next[0];
3414
+ const value = next[1];
3415
+ patchProp(el, key, value);
3416
+ } else if (isObject(next)) {
3417
+ for (const item of Object.entries(next)) {
3418
+ const key = item[0];
3419
+ const value = item[1];
3100
3420
  patchProp(el, key, value);
3101
3421
  }
3422
+ } else {
3423
+ const key = values[i++];
3424
+ const value = values[i];
3425
+ patchProp(el, key, value);
3102
3426
  }
3103
3427
  }
3104
3428
  };
3429
+ var propDirective = {
3430
+ mount: () => ({
3431
+ update: ({ el, values, option, flags }) => {
3432
+ updatePropBinding(el, values, option, flags);
3433
+ }
3434
+ })
3435
+ };
3105
3436
  function includeBooleanAttr2(value) {
3106
3437
  return !!value || value === "";
3107
3438
  }
@@ -3156,7 +3487,8 @@ var patchProp = (el, key, value) => {
3156
3487
  // src/directives/ref.ts
3157
3488
  var refDirective = {
3158
3489
  once: true,
3159
- onBind: (el, result, expr) => {
3490
+ mount: ({ el, parseResult, expr }) => {
3491
+ const result = parseResult;
3160
3492
  const value = result.value()[0];
3161
3493
  const isAnArray = isArray(value);
3162
3494
  const sref2 = result.refs[0];
@@ -3173,37 +3505,47 @@ var refDirective = {
3173
3505
  };
3174
3506
 
3175
3507
  // src/directives/show.ts
3508
+ var updateShow = (el, values) => {
3509
+ const data = getBindData(el).data;
3510
+ let originalDisplay = data._ord;
3511
+ if (isUndefined(originalDisplay)) {
3512
+ originalDisplay = data._ord = el.style.display;
3513
+ }
3514
+ const isVisible = !!values[0];
3515
+ if (isVisible) el.style.display = originalDisplay;
3516
+ else el.style.display = "none";
3517
+ };
3176
3518
  var showDirective = {
3177
- onChange: (el, values) => {
3178
- const data = getBindData(el).data;
3179
- let originalDisplay = data._ord;
3180
- if (isUndefined(originalDisplay)) {
3181
- originalDisplay = data._ord = el.style.display;
3519
+ mount: () => ({
3520
+ update: ({ el, values }) => {
3521
+ updateShow(el, values);
3182
3522
  }
3183
- const isVisible = !!values[0];
3184
- if (isVisible) el.style.display = originalDisplay;
3185
- else el.style.display = "none";
3186
- }
3523
+ })
3187
3524
  };
3188
3525
 
3189
3526
  // src/directives/style.ts
3190
- var styleDirective = {
3191
- onChange: (el, values, previousValues) => {
3192
- const len = values.length;
3193
- for (let i = 0; i < len; ++i) {
3194
- const next = values[i];
3195
- const previous = previousValues == null ? void 0 : previousValues[i];
3196
- if (isArray(next)) {
3197
- const len2 = next.length;
3198
- for (let j = 0; j < len2; ++j) {
3199
- patchStyle(el, next[j], previous == null ? void 0 : previous[j]);
3200
- }
3201
- } else {
3202
- patchStyle(el, next, previous);
3527
+ var updateStyle = (el, values, previousValues) => {
3528
+ const len = values.length;
3529
+ for (let i = 0; i < len; ++i) {
3530
+ const next = values[i];
3531
+ const previous = previousValues == null ? void 0 : previousValues[i];
3532
+ if (isArray(next)) {
3533
+ const len2 = next.length;
3534
+ for (let j = 0; j < len2; ++j) {
3535
+ patchStyle(el, next[j], previous == null ? void 0 : previous[j]);
3203
3536
  }
3537
+ } else {
3538
+ patchStyle(el, next, previous);
3204
3539
  }
3205
3540
  }
3206
3541
  };
3542
+ var styleDirective = {
3543
+ mount: () => ({
3544
+ update: ({ el, values, previousValues }) => {
3545
+ updateStyle(el, values, previousValues);
3546
+ }
3547
+ })
3548
+ };
3207
3549
  var patchStyle = (el, next, prev) => {
3208
3550
  const style = el.style;
3209
3551
  const isCssString = isString(next);
@@ -3311,19 +3653,26 @@ var flattenContent = (value, weakMap = /* @__PURE__ */ new WeakMap()) => {
3311
3653
  };
3312
3654
 
3313
3655
  // src/directives/text.ts
3656
+ var updateText = (el, values) => {
3657
+ var _a;
3658
+ const value = values[0];
3659
+ el.textContent = isSet(value) ? JSON.stringify(flatten([...value])) : isMap(value) ? JSON.stringify(flatten([...value])) : isObject(value) ? JSON.stringify(flatten(value)) : (_a = value == null ? void 0 : value.toString()) != null ? _a : "";
3660
+ };
3314
3661
  var textDirective = {
3315
- onChange: (el, values) => {
3316
- var _a;
3317
- const value = values[0];
3318
- el.textContent = isSet(value) ? JSON.stringify(flatten([...value])) : isMap(value) ? JSON.stringify(flatten([...value])) : isObject(value) ? JSON.stringify(flatten(value)) : (_a = value == null ? void 0 : value.toString()) != null ? _a : "";
3319
- }
3662
+ mount: () => ({
3663
+ update: ({ el, values }) => {
3664
+ updateText(el, values);
3665
+ }
3666
+ })
3320
3667
  };
3321
3668
 
3322
3669
  // src/directives/value.ts
3323
3670
  var valueDirective = {
3324
- onChange: (el, values) => {
3325
- patchProp(el, "value", values[0]);
3326
- }
3671
+ mount: () => ({
3672
+ update: ({ el, values }) => {
3673
+ patchProp(el, "value", values[0]);
3674
+ }
3675
+ })
3327
3676
  };
3328
3677
 
3329
3678
  // src/app/RegorConfig.ts
@@ -5139,6 +5488,7 @@ var regorEval = (expr, contexts, globalContext, isLazy, isLazyKey, context, coll
5139
5488
 
5140
5489
  // src/parser/Parser.ts
5141
5490
  var astCache = {};
5491
+ var isComponentMap = (value) => !!value;
5142
5492
  var Parser = class {
5143
5493
  constructor(contexts, config) {
5144
5494
  __publicField(this, "__contexts");
@@ -5151,7 +5501,7 @@ var Parser = class {
5151
5501
  this.__contexts = [context, ...this.__contexts];
5152
5502
  }
5153
5503
  __getComponents() {
5154
- const obj = this.__contexts.map((x) => x.components).filter((x) => !!x).reverse().reduce((p, c) => {
5504
+ const obj = this.__contexts.map((x) => x.components).filter(isComponentMap).reverse().reduce((p, c) => {
5155
5505
  for (const [key, value] of Object.entries(c)) {
5156
5506
  p[key.toUpperCase()] = value;
5157
5507
  }
@@ -5162,7 +5512,7 @@ var Parser = class {
5162
5512
  __getComponentSelectors() {
5163
5513
  const selectors = [];
5164
5514
  const seen = /* @__PURE__ */ new Set();
5165
- const componentsList = this.__contexts.map((x) => x.components).filter((x) => !!x).reverse();
5515
+ const componentsList = this.__contexts.map((x) => x.components).filter(isComponentMap).reverse();
5166
5516
  for (const components of componentsList) {
5167
5517
  for (const key of Object.keys(components)) {
5168
5518
  if (seen.has(key)) continue;
@@ -5174,12 +5524,12 @@ var Parser = class {
5174
5524
  }
5175
5525
  __parse(expression, isLazy, isLazyKey, collectRefObj, once) {
5176
5526
  var _a;
5177
- const value = sref([]);
5527
+ let currentValues = [];
5178
5528
  const stopObserverList = [];
5179
5529
  const subscribers = /* @__PURE__ */ new Set();
5180
5530
  const clearObservers = () => {
5181
- for (const stopObserver of stopObserverList) {
5182
- stopObserver();
5531
+ for (let i = 0; i < stopObserverList.length; ++i) {
5532
+ stopObserverList[i]();
5183
5533
  }
5184
5534
  stopObserverList.length = 0;
5185
5535
  };
@@ -5189,13 +5539,13 @@ var Parser = class {
5189
5539
  };
5190
5540
  const subscribe = (observer, init) => {
5191
5541
  subscribers.add(observer);
5192
- if (init) observer(value());
5542
+ if (init) observer(currentValues);
5193
5543
  return () => {
5194
5544
  subscribers.delete(observer);
5195
5545
  };
5196
5546
  };
5197
5547
  const result = {
5198
- value,
5548
+ value: () => currentValues,
5199
5549
  stop: unbinder,
5200
5550
  subscribe,
5201
5551
  refs: [],
@@ -5216,7 +5566,7 @@ var Parser = class {
5216
5566
  context,
5217
5567
  collectRefObj
5218
5568
  );
5219
- if (collectRefs2) refs.push(...r.refs);
5569
+ if (collectRefs2 && r.refs.length > 0) refs.push(...r.refs);
5220
5570
  return { value: r.value, refs: r.refs, ref: r.ref };
5221
5571
  } catch (e) {
5222
5572
  warning(6 /* ErrorLog */, `evaluation error: ${expression}`, e);
@@ -5229,36 +5579,37 @@ var Parser = class {
5229
5579
  const contexts = this.__contexts.slice();
5230
5580
  const elements = ast.elements;
5231
5581
  const len = elements.length;
5582
+ const expressionRefs = new Array(len);
5583
+ result.refs = expressionRefs;
5232
5584
  const refresh = () => {
5233
5585
  refs.length = 0;
5234
- uniqueRefs.clear();
5235
- clearObservers();
5236
- const values = new Array(len);
5237
- const expressionRefs = new Array(len);
5586
+ if (!once) {
5587
+ uniqueRefs.clear();
5588
+ clearObservers();
5589
+ }
5590
+ const nextValues = new Array(len);
5238
5591
  for (let i = 0; i < len; ++i) {
5239
5592
  const expr = elements[i];
5240
5593
  if (isLazy == null ? void 0 : isLazy(i, -1)) {
5241
- values[i] = (e) => evaluate(expr, contexts, false, { $event: e }).value;
5594
+ nextValues[i] = (e) => evaluate(expr, contexts, false, { $event: e }).value;
5242
5595
  continue;
5243
5596
  }
5244
5597
  const evaluated = evaluate(expr, contexts, true);
5245
- values[i] = evaluated.value;
5598
+ nextValues[i] = evaluated.value;
5246
5599
  expressionRefs[i] = evaluated.ref;
5247
5600
  }
5248
5601
  if (!once) {
5249
5602
  for (const r of refs) {
5250
5603
  if (uniqueRefs.has(r)) continue;
5251
5604
  uniqueRefs.add(r);
5252
- const stopObserving = observe(r, refresh);
5253
- stopObserverList.push(stopObserving);
5605
+ stopObserverList.push(observe(r, refresh));
5254
5606
  }
5255
5607
  }
5256
- result.refs = expressionRefs;
5257
- value(values);
5608
+ currentValues = nextValues;
5258
5609
  if (subscribers.size !== 0) {
5259
5610
  for (const subscriber of subscribers) {
5260
5611
  if (!subscribers.has(subscriber)) continue;
5261
- subscriber(values);
5612
+ subscriber(currentValues);
5262
5613
  }
5263
5614
  }
5264
5615
  };
@@ -5572,8 +5923,8 @@ var toJsonTemplate = (node) => {
5572
5923
  return json;
5573
5924
  };
5574
5925
 
5575
- // src/app/createComponent.ts
5576
- var createComponent = (template, options = {}) => {
5926
+ // src/app/defineComponent.ts
5927
+ var defineComponent = (template, options = {}) => {
5577
5928
  var _a, _b, _c, _d, _e, _f;
5578
5929
  if (isArray(options)) options = { props: options };
5579
5930
  if (isString(template)) template = { template };