marko 6.0.0-next.3.38 → 6.0.0-next.3.39

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.
package/dist/debug/dom.js CHANGED
@@ -70,7 +70,7 @@ __export(dom_exports, {
70
70
  props: () => props,
71
71
  register: () => register,
72
72
  registerBoundSignal: () => registerBoundSignal,
73
- registerSubscriber: () => registerSubscriber,
73
+ registerDynamicClosure: () => registerDynamicClosure,
74
74
  resetAbortSignal: () => resetAbortSignal,
75
75
  run: () => run,
76
76
  setTagVar: () => setTagVar,
@@ -130,49 +130,6 @@ function forTo(to, from, step, cb) {
130
130
  }
131
131
  }
132
132
 
133
- // src/dom/schedule.ts
134
- var runTask;
135
- var port2 = /* @__PURE__ */ (() => {
136
- const { port1, port2: port22 } = new MessageChannel();
137
- port1.onmessage = () => {
138
- isScheduled = false;
139
- if (true) {
140
- const run2 = runTask;
141
- runTask = void 0;
142
- run2();
143
- } else {
144
- run();
145
- }
146
- };
147
- return port22;
148
- })();
149
- var isScheduled;
150
- function schedule() {
151
- if (!isScheduled) {
152
- if (true) {
153
- if (console.createTask) {
154
- const task = console.createTask("queue");
155
- runTask = () => task.run(run);
156
- } else {
157
- runTask = run;
158
- }
159
- }
160
- isScheduled = true;
161
- queueMicrotask(flushAndWaitFrame);
162
- }
163
- }
164
- function flushAndWaitFrame() {
165
- if (true) {
166
- runTask();
167
- } else {
168
- run();
169
- }
170
- requestAnimationFrame(triggerMacroTask);
171
- }
172
- function triggerMacroTask() {
173
- port2.postMessage(0);
174
- }
175
-
176
133
  // src/common/helpers.ts
177
134
  function classValue(value2) {
178
135
  return toDelimitedString(value2, " ", stringifyClassObject);
@@ -503,10 +460,6 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
503
460
  });
504
461
  }
505
462
  }
506
- function registerSubscriber(id, signal) {
507
- register(id, signal.___subscribe);
508
- return signal;
509
- }
510
463
  function nodeRef(id, key) {
511
464
  return register(id, (scope) => () => scope[key]);
512
465
  }
@@ -1057,9 +1010,10 @@ function toInsertNode(startNode, endNode) {
1057
1010
  // src/dom/scope.ts
1058
1011
  var pendingScopes = [];
1059
1012
  var debugID = 0;
1060
- function createScope($global) {
1013
+ function createScope($global, closestBranch) {
1061
1014
  const scope = {
1062
1015
  ___pending: 1,
1016
+ ___closestBranch: closestBranch,
1063
1017
  $global
1064
1018
  };
1065
1019
  if (true) {
@@ -1281,10 +1235,10 @@ function trimWalkString(walkString) {
1281
1235
  }
1282
1236
  function walk(startNode, walkCodes, branch) {
1283
1237
  walker.currentNode = startNode;
1284
- walkInternal(walkCodes, branch, 0);
1238
+ walkInternal(0, walkCodes, branch);
1285
1239
  walker.currentNode = document;
1286
1240
  }
1287
- function walkInternal(walkCodes, scope, currentWalkIndex) {
1241
+ function walkInternal(currentWalkIndex, walkCodes, scope) {
1288
1242
  let value2;
1289
1243
  let storedMultiplier = 0;
1290
1244
  let currentMultiplier = 0;
@@ -1311,9 +1265,11 @@ function walkInternal(walkCodes, scope, currentWalkIndex) {
1311
1265
  walker.nextNode();
1312
1266
  }
1313
1267
  } else if (value2 === 47 /* BeginChild */) {
1314
- const childScope = scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global);
1315
- childScope.___closestBranch = scope.___closestBranch;
1316
- currentWalkIndex = walkInternal(walkCodes, childScope, currentWalkIndex);
1268
+ currentWalkIndex = walkInternal(
1269
+ currentWalkIndex,
1270
+ walkCodes,
1271
+ scope[true ? getDebugKey(currentScopeIndex++, "#childScope") : currentScopeIndex++] = createScope(scope.$global, scope.___closestBranch)
1272
+ );
1317
1273
  } else if (value2 === 38 /* EndChild */) {
1318
1274
  return currentWalkIndex;
1319
1275
  } else if (value2 === 32 /* Get */) {
@@ -1390,9 +1346,14 @@ function createBranch($global, ownerScope, parentScope) {
1390
1346
  function initBranch(renderer, branch, parentNode) {
1391
1347
  const clone = renderer.___clone(parentNode.namespaceURI);
1392
1348
  const cloneParent = clone.parentNode;
1393
- walk(cloneParent?.firstChild || clone, renderer.___walks, branch);
1394
- branch.___startNode = cloneParent?.firstChild || clone;
1395
- branch.___endNode = cloneParent?.lastChild || clone;
1349
+ if (cloneParent) {
1350
+ walk(cloneParent.firstChild, renderer.___walks, branch);
1351
+ branch.___startNode = cloneParent.firstChild;
1352
+ branch.___endNode = cloneParent.lastChild;
1353
+ } else {
1354
+ walk(clone, renderer.___walks, branch);
1355
+ branch.___startNode = branch.___endNode = clone;
1356
+ }
1396
1357
  if (renderer.___setup) {
1397
1358
  queueRender(branch, renderer.___setup);
1398
1359
  }
@@ -1665,6 +1626,49 @@ function isDifferentRenderer(a, b) {
1665
1626
  return a !== b && (a?.___id || 0) !== b?.___id;
1666
1627
  }
1667
1628
 
1629
+ // src/dom/schedule.ts
1630
+ var runTask;
1631
+ var port2 = /* @__PURE__ */ (() => {
1632
+ const { port1, port2: port22 } = new MessageChannel();
1633
+ port1.onmessage = () => {
1634
+ isScheduled = false;
1635
+ if (true) {
1636
+ const run2 = runTask;
1637
+ runTask = void 0;
1638
+ run2();
1639
+ } else {
1640
+ run();
1641
+ }
1642
+ };
1643
+ return port22;
1644
+ })();
1645
+ var isScheduled;
1646
+ function schedule() {
1647
+ if (!isScheduled) {
1648
+ if (true) {
1649
+ if (console.createTask) {
1650
+ const task = console.createTask("queue");
1651
+ runTask = () => task.run(run);
1652
+ } else {
1653
+ runTask = run;
1654
+ }
1655
+ }
1656
+ isScheduled = true;
1657
+ queueMicrotask(flushAndWaitFrame);
1658
+ }
1659
+ }
1660
+ function flushAndWaitFrame() {
1661
+ if (true) {
1662
+ runTask();
1663
+ } else {
1664
+ run();
1665
+ }
1666
+ requestAnimationFrame(triggerMacroTask);
1667
+ }
1668
+ function triggerMacroTask() {
1669
+ port2.postMessage(0);
1670
+ }
1671
+
1668
1672
  // src/dom/signals.ts
1669
1673
  var MARK = true ? Symbol("mark") : {};
1670
1674
  var CLEAN = true ? Symbol("clean") : {};
@@ -1683,6 +1687,7 @@ function state(valueAccessor, fn, getIntersection) {
1683
1687
  } else if (scope[valueChangeAccessor]) {
1684
1688
  scope[valueChangeAccessor](valueOrOp);
1685
1689
  } else {
1690
+ schedule();
1686
1691
  queueSource(scope, valueSignal, valueOrOp);
1687
1692
  }
1688
1693
  return valueOrOp;
@@ -1690,21 +1695,21 @@ function state(valueAccessor, fn, getIntersection) {
1690
1695
  }
1691
1696
  function value(valueAccessor, fn, getIntersection) {
1692
1697
  const markAccessor = valueAccessor + "#" /* Mark */;
1693
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1698
+ let intersection2;
1694
1699
  return (scope, valueOrOp) => {
1695
1700
  if (valueOrOp === MARK) {
1696
1701
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1697
- intersection2?.(scope, MARK);
1702
+ getIntersection && (intersection2 ||= getIntersection())(scope, MARK);
1698
1703
  }
1699
1704
  } else if (valueOrOp !== DIRTY) {
1700
1705
  const existing = scope[markAccessor] !== void 0;
1701
1706
  if ((scope[markAccessor] ||= 1) === 1) {
1702
1707
  if (valueOrOp === CLEAN || existing && scope[valueAccessor] === valueOrOp) {
1703
- intersection2?.(scope, CLEAN);
1708
+ getIntersection && (intersection2 ||= getIntersection())(scope, CLEAN);
1704
1709
  } else {
1705
1710
  scope[valueAccessor] = valueOrOp;
1706
1711
  fn && fn(scope, valueOrOp);
1707
- intersection2?.(scope, DIRTY);
1712
+ getIntersection && (intersection2 ||= getIntersection())(scope, DIRTY);
1708
1713
  }
1709
1714
  }
1710
1715
  scope[markAccessor]--;
@@ -1715,11 +1720,11 @@ var accessorId = 0;
1715
1720
  function intersection(count, fn, getIntersection) {
1716
1721
  const dirtyAccessor = "?" /* Dynamic */ + accessorId++;
1717
1722
  const markAccessor = dirtyAccessor + "#" /* Mark */;
1718
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1723
+ let intersection2;
1719
1724
  return (scope, op) => {
1720
1725
  if (op === MARK) {
1721
1726
  if ((scope[markAccessor] = (scope[markAccessor] ?? 0) + 1) === 1) {
1722
- intersection2?.(scope, MARK);
1727
+ getIntersection && (intersection2 ||= getIntersection())(scope, MARK);
1723
1728
  }
1724
1729
  } else if (scope[markAccessor] === void 0) {
1725
1730
  scope[markAccessor] = count - 1;
@@ -1727,84 +1732,101 @@ function intersection(count, fn, getIntersection) {
1727
1732
  } else if (--scope[markAccessor] === 0) {
1728
1733
  if (op === DIRTY || scope[dirtyAccessor]) {
1729
1734
  scope[dirtyAccessor] = false;
1730
- fn(scope, 0);
1731
- intersection2?.(scope, DIRTY);
1735
+ fn(scope);
1736
+ getIntersection && (intersection2 ||= getIntersection())(scope, DIRTY);
1732
1737
  } else {
1733
- intersection2?.(scope, CLEAN);
1738
+ getIntersection && (intersection2 ||= getIntersection())(scope, CLEAN);
1734
1739
  }
1735
1740
  } else {
1736
1741
  scope[dirtyAccessor] ||= op === DIRTY;
1737
1742
  }
1738
1743
  };
1739
1744
  }
1740
- function closure(fn, getIntersection) {
1741
- let intersection2 = getIntersection && ((scope, op) => (intersection2 = getIntersection())(scope, op));
1742
- return (scope, valueOrOp) => {
1743
- if (valueOrOp === MARK) {
1744
- intersection2?.(scope, MARK);
1745
- } else {
1746
- fn && fn(scope, valueOrOp);
1747
- intersection2?.(scope, DIRTY);
1748
- }
1749
- };
1750
- }
1751
- function loopClosure(ownerLoopNodeAccessor, fn, getIntersection) {
1752
- const signal = closure(fn, getIntersection);
1745
+ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn, getIntersection) {
1746
+ const childSignal = closure(valueAccessor, fn, getIntersection);
1753
1747
  const loopScopeAccessor = ownerLoopNodeAccessor + "!" /* LoopScopeArray */;
1754
1748
  const loopScopeMapAccessor = ownerLoopNodeAccessor + "(" /* LoopScopeMap */;
1755
- const helperSignal = (ownerScope, value2) => {
1749
+ const ownerSignal = (ownerScope) => {
1756
1750
  const loopScopes = ownerScope[loopScopeAccessor] ?? ownerScope[loopScopeMapAccessor]?.values() ?? [];
1757
1751
  if (loopScopes !== emptyMarkerArray) {
1758
1752
  for (const scope of loopScopes) {
1759
1753
  if (!scope.___pending) {
1760
- queueSource(scope, signal, value2);
1754
+ queueSource(scope, childSignal);
1761
1755
  }
1762
1756
  }
1763
1757
  }
1764
1758
  };
1765
- helperSignal._ = signal;
1766
- return helperSignal;
1759
+ ownerSignal._ = childSignal;
1760
+ return ownerSignal;
1767
1761
  }
1768
- function conditionalClosure(ownerConditionalNodeAccessor, branch, fn, getIntersection) {
1769
- const signal = closure(fn, getIntersection);
1762
+ function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch, fn, getIntersection) {
1763
+ const childSignal = closure(valueAccessor, fn, getIntersection);
1770
1764
  const scopeAccessor = ownerConditionalNodeAccessor + "!" /* ConditionalScope */;
1771
1765
  const branchAccessor = ownerConditionalNodeAccessor + "(" /* ConditionalRenderer */;
1772
- const helperSignal = (scope, value2) => {
1766
+ const ownerSignal = (scope) => {
1773
1767
  const ifScope = scope[scopeAccessor];
1774
1768
  if (ifScope && !ifScope.___pending && scope[branchAccessor] === branch) {
1775
- queueSource(ifScope, signal, value2);
1769
+ queueSource(ifScope, childSignal);
1776
1770
  }
1777
1771
  };
1778
- helperSignal._ = signal;
1779
- return helperSignal;
1780
- }
1781
- var defaultGetOwnerScope = (scope) => scope._;
1782
- function dynamicClosure(fn, getOwnerScope = defaultGetOwnerScope, getIntersection) {
1783
- const ownerSubscribersAccessor = "?" /* Dynamic */ + accessorId++;
1784
- const _signal = closure(fn, getIntersection);
1785
- const helperSignal = (ownerScope, value2) => {
1786
- const subscribers = ownerScope[ownerSubscribersAccessor];
1772
+ ownerSignal._ = childSignal;
1773
+ return ownerSignal;
1774
+ }
1775
+ function dynamicClosure(valueAccessor, fn, getIntersection, getOwnerScope) {
1776
+ const subscribersAccessor = "?" /* Dynamic */ + accessorId++;
1777
+ const childSignal = closure(
1778
+ valueAccessor,
1779
+ fn,
1780
+ getIntersection,
1781
+ getOwnerScope
1782
+ );
1783
+ const ownerSignal = (ownerScope) => {
1784
+ const subscribers = ownerScope[subscribersAccessor];
1787
1785
  if (subscribers) {
1788
1786
  for (const subscriber of subscribers) {
1789
1787
  if (!subscriber.___pending) {
1790
- queueSource(subscriber, _signal, value2);
1788
+ queueSource(subscriber, childSignal);
1791
1789
  }
1792
1790
  }
1793
1791
  }
1794
1792
  };
1795
- const setupSignal = (scope, value2) => {
1796
- _signal(scope, value2);
1793
+ const subscribe = (scope) => {
1794
+ const owner = getOwnerScope ? getOwnerScope(scope) : scope._;
1795
+ const subscribers = owner[subscribersAccessor] ||= /* @__PURE__ */ new Set();
1796
+ if (!subscribers.has(scope)) {
1797
+ subscribers.add(scope);
1798
+ getAbortSignal(scope, -1).addEventListener(
1799
+ "abort",
1800
+ () => owner[subscribersAccessor].delete(scope)
1801
+ );
1802
+ }
1803
+ };
1804
+ ownerSignal.___subscribe = subscribe;
1805
+ ownerSignal._ = (scope) => {
1806
+ childSignal(scope);
1797
1807
  subscribe(scope);
1798
1808
  };
1799
- const subscribe = (scope) => {
1800
- (getOwnerScope(scope)[ownerSubscribersAccessor] ||= /* @__PURE__ */ new Set()).add(scope);
1801
- getAbortSignal(scope, -1).addEventListener("abort", () => {
1802
- getOwnerScope(scope)[ownerSubscribersAccessor].delete(scope);
1803
- });
1809
+ return ownerSignal;
1810
+ }
1811
+ function registerDynamicClosure(id, valueAccessor, fn, getIntersection, getOwnerScope) {
1812
+ const signal = dynamicClosure(
1813
+ valueAccessor,
1814
+ fn,
1815
+ getIntersection,
1816
+ getOwnerScope
1817
+ );
1818
+ register(id, signal.___subscribe);
1819
+ return signal;
1820
+ }
1821
+ function closure(valueAccessor, fn, getIntersection, getOwnerScope) {
1822
+ let intersection2;
1823
+ return (scope, op) => {
1824
+ op || fn && fn(
1825
+ scope,
1826
+ (getOwnerScope ? getOwnerScope(scope) : scope._)[valueAccessor]
1827
+ );
1828
+ getIntersection && (intersection2 ||= getIntersection())(scope, op ? MARK : DIRTY);
1804
1829
  };
1805
- helperSignal._ = setupSignal;
1806
- helperSignal.___subscribe = subscribe;
1807
- return helperSignal;
1808
1830
  }
1809
1831
  function setTagVar(scope, childAccessor, tagVarSignal2) {
1810
1832
  scope[childAccessor]["/" /* TagVariable */] = (valueOrOp) => tagVarSignal2(scope, valueOrOp);
@@ -1844,13 +1866,11 @@ var pendingRenders = [];
1844
1866
  var pendingEffects = [];
1845
1867
  var rendering = false;
1846
1868
  function queueSource(scope, signal, value2) {
1847
- schedule();
1848
1869
  const prevRendering = rendering;
1849
1870
  rendering = true;
1850
1871
  signal(scope, MARK);
1851
1872
  rendering = prevRendering;
1852
1873
  queueRender(scope, signal, value2);
1853
- return value2;
1854
1874
  }
1855
1875
  function queueRender(scope, signal, value2) {
1856
1876
  let i = pendingRenders.length;
@@ -1858,6 +1878,7 @@ function queueRender(scope, signal, value2) {
1858
1878
  ___scope: scope,
1859
1879
  ___signal: signal,
1860
1880
  ___value: value2,
1881
+ ___depth: scope.___closestBranch?.___branchDepth || 0,
1861
1882
  ___index: i
1862
1883
  };
1863
1884
  pendingRenders.push(render);
@@ -1901,7 +1922,7 @@ function prepareEffects(fn) {
1901
1922
  }
1902
1923
  return preparedEffects;
1903
1924
  }
1904
- function runEffects(effects = pendingEffects) {
1925
+ function runEffects(effects) {
1905
1926
  for (let i = 0; i < effects.length; i += 2 /* Total */) {
1906
1927
  const scope = effects[i];
1907
1928
  const fn = effects[i + 1];
@@ -1941,10 +1962,7 @@ function runRenders() {
1941
1962
  finishPendingScopes();
1942
1963
  }
1943
1964
  function comparePendingRenders(a, b) {
1944
- return getBranchDepth(a) - getBranchDepth(b) || a.___index - b.___index;
1945
- }
1946
- function getBranchDepth(render) {
1947
- return render.___scope.___closestBranch?.___branchDepth || 0;
1965
+ return a.___depth - b.___depth || a.___index - b.___index;
1948
1966
  }
1949
1967
 
1950
1968
  // src/dom/abort-signal.ts
@@ -2119,7 +2137,7 @@ function mount(input = {}, reference, position) {
2119
2137
  );
2120
2138
  runEffects(effects);
2121
2139
  return {
2122
- update: (newInput) => {
2140
+ update(newInput) {
2123
2141
  if (args) {
2124
2142
  runEffects(
2125
2143
  prepareEffects(() => {
@@ -2129,7 +2147,7 @@ function mount(input = {}, reference, position) {
2129
2147
  );
2130
2148
  }
2131
2149
  },
2132
- destroy: () => {
2150
+ destroy() {
2133
2151
  removeAndDestroyBranch(branch);
2134
2152
  }
2135
2153
  };