marko 6.0.0-next.3.63 → 6.0.0-next.3.65

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.
@@ -21,5 +21,6 @@ export declare enum AccessorProp {
21
21
  PlaceholderBranch = "c",
22
22
  PlaceholderContent = "d",
23
23
  TagVariable = "e",
24
- TagVariableChange = "f"
24
+ TagVariableChange = "f",
25
+ ClosestBranchId = "g"
25
26
  }
@@ -21,5 +21,6 @@ export declare enum AccessorProp {
21
21
  PlaceholderBranch = "#PlaceholderBranch",
22
22
  PlaceholderContent = "#PlaceholderContent",
23
23
  TagVariable = "#TagVariable",
24
- TagVariableChange = "#TagVariableChange"
24
+ TagVariableChange = "#TagVariableChange",
25
+ ClosestBranchId = "#ClosestBranchId"
25
26
  }
@@ -10,6 +10,7 @@ export interface BranchScope extends Scope {
10
10
  ___branchScopes: Set<BranchScope> | undefined;
11
11
  ___renderer: ClientRenderer | string;
12
12
  ___pendingAsyncCount: number | undefined;
13
+ ___effects: unknown[] | undefined;
13
14
  }
14
15
  export interface Scope {
15
16
  $global: Record<string, unknown> & {
@@ -18,7 +19,7 @@ export interface Scope {
18
19
  _: Scope | undefined;
19
20
  ___id: number;
20
21
  ___args: unknown;
21
- ___pending: 1 | 0 | undefined;
22
+ ___creating: 1 | 0 | undefined;
22
23
  ___abortControllers: Record<string | number, AbortController | void> | undefined;
23
24
  ___closestBranch: BranchScope | undefined;
24
25
  [x: string | number]: any;
@@ -28,8 +29,7 @@ export declare enum ResumeSymbol {
28
29
  BranchStart = "[",
29
30
  BranchEnd = "]",
30
31
  BranchSingleNode = "|",
31
- BranchSingleNodeOnlyChildInParent = "=",
32
- ClosestBranch = "$"
32
+ BranchSingleNodeOnlyChildInParent = "="
33
33
  }
34
34
  export { AccessorPrefix, AccessorProp } from "./accessor.debug";
35
35
  export declare enum NodeType {
package/dist/debug/dom.js CHANGED
@@ -269,15 +269,14 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
269
269
  const render = resumeRender[renderId] = renders2[renderId] || renders2(renderId);
270
270
  const walk2 = render.w;
271
271
  const commentPrefixLen = render.i.length;
272
- const scopeStack = [];
272
+ const branchStack = [];
273
273
  const scopeLookup = render.s = {};
274
274
  const serializeContext = {
275
275
  _: registeredValues
276
276
  };
277
277
  const branchIds = /* @__PURE__ */ new Set();
278
278
  const parentBranchIds = /* @__PURE__ */ new Map();
279
- const closestBranchMarkers = /* @__PURE__ */ new Map();
280
- let currentScopeId;
279
+ let currentBranchId;
281
280
  render.w = () => {
282
281
  walk2.call(render);
283
282
  const visits = render.v;
@@ -285,8 +284,8 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
285
284
  if (visits.length) {
286
285
  const visitNodes = new Set(visits);
287
286
  let lastEndNode;
288
- render.v = [];
289
- const branchEnd = (branchId, visit, reference) => {
287
+ visits.length = 0;
288
+ const branchEnd = (branchId, reference) => {
290
289
  const branch = scopeLookup[branchId] ||= {};
291
290
  let endNode = reference;
292
291
  while (visitNodes.has(endNode = endNode.previousSibling)) ;
@@ -298,17 +297,10 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
298
297
  }
299
298
  branch.___endNode = lastEndNode = endNode;
300
299
  branch.___startNode ||= endNode;
301
- for (const [markerScopeId, markerNode] of closestBranchMarkers) {
302
- if (branch.___startNode.compareDocumentPosition(markerNode) & 4 && reference.compareDocumentPosition(markerNode) & 2) {
303
- parentBranchIds.set(markerScopeId, branchId);
304
- closestBranchMarkers.delete(markerScopeId);
305
- }
306
- }
307
300
  branchIds.add(branchId);
308
- closestBranchMarkers.set(branchId, visit);
309
301
  return branch;
310
302
  };
311
- for (const visit of visits) {
303
+ for (const visit of visitNodes) {
312
304
  const commentText = visit.data;
313
305
  const dataIndex = commentText.indexOf(" ") + 1;
314
306
  const scopeId = commentText.slice(
@@ -323,29 +315,28 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
323
315
  if (token === "*" /* Node */) {
324
316
  const node = scope[data2] = visit.previousSibling;
325
317
  scope["Getter:" /* Getter */ + data2] = () => node;
326
- } else if (token === "$" /* ClosestBranch */) {
327
- closestBranchMarkers.set(scopeId, visit);
328
318
  } else if (token === "[" /* BranchStart */) {
329
- if (currentScopeId) {
330
- if (dataIndex) {
331
- branchEnd(currentScopeId, visit, visit);
332
- }
333
- scopeStack.push(currentScopeId);
319
+ if (currentBranchId && dataIndex) {
320
+ branchEnd(currentBranchId, visit);
321
+ currentBranchId = branchStack.pop();
322
+ }
323
+ if (currentBranchId) {
324
+ branchStack.push(currentBranchId);
325
+ parentBranchIds.set(scopeId, currentBranchId);
334
326
  }
335
- currentScopeId = scopeId;
327
+ currentBranchId = scopeId;
336
328
  scope.___startNode = visit;
337
329
  } else if (token === "]" /* BranchEnd */) {
338
330
  scope[data2] = visit;
339
331
  const curParent = visit.parentNode;
340
332
  const startNode = branchEnd(
341
- currentScopeId,
342
- visit,
333
+ currentBranchId,
343
334
  visit
344
335
  ).___startNode;
345
336
  if (curParent !== startNode.parentNode) {
346
337
  curParent.prepend(startNode);
347
338
  }
348
- currentScopeId = scopeStack.pop();
339
+ currentBranchId = branchStack.pop();
349
340
  } else if (token === "|" /* BranchSingleNode */ || token === "=" /* BranchSingleNodeOnlyChildInParent */) {
350
341
  let next = data2.indexOf(" ");
351
342
  let curNode = visit;
@@ -357,7 +348,8 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
357
348
  start,
358
349
  ~next ? next : data2.length
359
350
  );
360
- curNode = branchEnd(childScopeId, visit, curNode).___endNode;
351
+ curNode = branchEnd(childScopeId, curNode).___endNode;
352
+ parentBranchIds.set(childScopeId, scopeId);
361
353
  }
362
354
  }
363
355
  }
@@ -389,7 +381,7 @@ function init(runtimeId = DEFAULT_RUNTIME_ID) {
389
381
  prevScope
390
382
  );
391
383
  }
392
- const parentBranchId = parentBranchIds.get(scopeId);
384
+ const parentBranchId = scope["#ClosestBranchId" /* ClosestBranchId */] || parentBranchIds.get(scopeId);
393
385
  if (parentBranchId) {
394
386
  scope.___closestBranch = scopes[parentBranchId];
395
387
  }
@@ -990,7 +982,7 @@ var pendingScopes = [];
990
982
  function createScope($global, closestBranch) {
991
983
  const scope = {
992
984
  ___id: $global.___nextScopeId++,
993
- ___pending: 1,
985
+ ___creating: 1,
994
986
  ___closestBranch: closestBranch,
995
987
  $global
996
988
  };
@@ -1002,10 +994,17 @@ function skipScope(scope) {
1002
994
  }
1003
995
  function finishPendingScopes() {
1004
996
  for (const scope of pendingScopes) {
1005
- scope.___pending = 0;
997
+ scope.___creating = 0;
1006
998
  }
1007
999
  pendingScopes = [];
1008
1000
  }
1001
+ function findBranchWithKey(scope, key) {
1002
+ let branch = scope.___closestBranch;
1003
+ while (branch && !branch[key]) {
1004
+ branch = branch.___parentBranch;
1005
+ }
1006
+ return branch;
1007
+ }
1009
1008
  function destroyBranch(branch) {
1010
1009
  branch.___parentBranch?.___branchScopes?.delete(branch);
1011
1010
  destroyNestedBranches(branch);
@@ -1475,7 +1474,7 @@ function value(valueAccessor, fn = () => {
1475
1474
  }
1476
1475
  function intersection(id, fn, defaultPending = 1, scopeIdAccessor = /* @__KEY__ */ "___id") {
1477
1476
  return (scope) => {
1478
- if (scope.___pending) {
1477
+ if (scope.___creating) {
1479
1478
  if (scope[id] === void 0) {
1480
1479
  scope[id] = defaultPending;
1481
1480
  } else if (!--scope[id]) {
@@ -1498,7 +1497,7 @@ function loopClosure(valueAccessor, ownerLoopNodeAccessor, fn) {
1498
1497
  ownerScope,
1499
1498
  () => {
1500
1499
  for (const scope of scopes) {
1501
- if (!scope.___pending && !scope.___destroyed) {
1500
+ if (!scope.___creating && !scope.___destroyed) {
1502
1501
  childSignal(scope);
1503
1502
  }
1504
1503
  }
@@ -1518,7 +1517,7 @@ function conditionalClosure(valueAccessor, ownerConditionalNodeAccessor, branch,
1518
1517
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + ownerConditionalNodeAccessor;
1519
1518
  const ownerSignal = (scope) => {
1520
1519
  const ifScope = scope[scopeAccessor];
1521
- if (ifScope && !ifScope.___pending && scope[branchAccessor] === branch) {
1520
+ if (ifScope && !ifScope.___creating && scope[branchAccessor] === branch) {
1522
1521
  queueRender(ifScope, childSignal, -1);
1523
1522
  }
1524
1523
  };
@@ -1543,7 +1542,7 @@ function dynamicClosure(...closureSignals) {
1543
1542
  return (scope) => {
1544
1543
  if (scope[___scopeInstancesAccessor]) {
1545
1544
  for (const childScope of scope[___scopeInstancesAccessor]) {
1546
- if (!childScope.___pending) {
1545
+ if (!childScope.___creating) {
1547
1546
  queueRender(
1548
1547
  childScope,
1549
1548
  closureSignals[childScope[___signalIndexAccessor]],
@@ -1620,98 +1619,88 @@ function awaitTag(nodeAccessor, renderer) {
1620
1619
  const promiseAccessor = "Promise:" /* Promise */ + nodeAccessor;
1621
1620
  const branchAccessor = "ConditionalScope:" /* ConditionalScope */ + nodeAccessor;
1622
1621
  return (scope, promise) => {
1623
- let tryBranch = scope.___closestBranch;
1622
+ const tryWithPlaceholder = findBranchWithKey(
1623
+ scope,
1624
+ "#PlaceholderContent" /* PlaceholderContent */
1625
+ );
1624
1626
  let awaitBranch = scope[branchAccessor];
1625
1627
  const referenceNode = scope[nodeAccessor];
1626
1628
  const namespaceNode = (awaitBranch?.___startNode ?? referenceNode).parentNode;
1627
- while (tryBranch && !tryBranch["#PlaceholderContent" /* PlaceholderContent */]) {
1628
- tryBranch = tryBranch.___parentBranch;
1629
- }
1630
1629
  const thisPromise = scope[promiseAccessor] = promise.then((data2) => {
1631
1630
  if (scope.___closestBranch?.___destroyed || scope[promiseAccessor] !== thisPromise) {
1632
1631
  return;
1633
1632
  }
1634
1633
  scope[promiseAccessor] = void 0;
1635
- const effects = prepareEffects(() => {
1636
- if (!awaitBranch || !tryBranch) {
1637
- insertBranchBefore(
1638
- awaitBranch ??= scope[branchAccessor] = createAndSetupBranch(
1639
- scope.$global,
1640
- renderer,
1641
- scope,
1642
- namespaceNode
1643
- ),
1644
- referenceNode.parentNode,
1645
- referenceNode
1646
- );
1647
- referenceNode.remove();
1648
- }
1649
- renderer.___params?.(awaitBranch, [data2]);
1650
- });
1651
- if (tryBranch) {
1652
- if (!--tryBranch.___pendingAsyncCount) {
1653
- const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */];
1634
+ runEffects(
1635
+ prepareEffects(() => {
1636
+ if (tryWithPlaceholder) {
1637
+ placeholderShown.add(pendingEffects);
1638
+ }
1639
+ if (!awaitBranch || !tryWithPlaceholder) {
1640
+ insertBranchBefore(
1641
+ awaitBranch ??= scope[branchAccessor] = createAndSetupBranch(
1642
+ scope.$global,
1643
+ renderer,
1644
+ scope,
1645
+ namespaceNode
1646
+ ),
1647
+ referenceNode.parentNode,
1648
+ referenceNode
1649
+ );
1650
+ referenceNode.remove();
1651
+ }
1652
+ renderer.___params?.(awaitBranch, [data2]);
1653
+ })
1654
+ );
1655
+ if (tryWithPlaceholder) {
1656
+ tryWithPlaceholder;
1657
+ if (!--tryWithPlaceholder.___pendingAsyncCount) {
1658
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */];
1659
+ tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = void 0;
1654
1660
  if (placeholderBranch) {
1655
1661
  insertBranchBefore(
1656
- tryBranch,
1662
+ tryWithPlaceholder,
1657
1663
  placeholderBranch.___startNode.parentNode,
1658
1664
  placeholderBranch.___startNode
1659
1665
  );
1660
1666
  removeAndDestroyBranch(placeholderBranch);
1661
1667
  } else {
1662
1668
  insertBranchBefore(
1663
- tryBranch,
1669
+ tryWithPlaceholder,
1664
1670
  referenceNode.parentNode,
1665
1671
  referenceNode
1666
1672
  );
1667
1673
  }
1674
+ if (tryWithPlaceholder.___effects) {
1675
+ runEffects(tryWithPlaceholder.___effects, true);
1676
+ }
1668
1677
  }
1669
- } else {
1670
- runEffects(effects);
1671
1678
  }
1672
1679
  }).catch((error) => {
1673
- let tryBranch2 = scope.___closestBranch;
1674
- while (tryBranch2 && !tryBranch2["#CatchContent" /* CatchContent */]) {
1675
- tryBranch2 = tryBranch2.___parentBranch;
1676
- }
1677
- if (!tryBranch2) {
1678
- setTimeout(() => {
1679
- throw error;
1680
- });
1681
- } else {
1682
- setConditionalRenderer(
1683
- tryBranch2._,
1684
- tryBranch2["#BranchAccessor" /* BranchAccessor */],
1685
- tryBranch2["#CatchContent" /* CatchContent */],
1686
- createAndSetupBranch
1687
- );
1688
- tryBranch2["#CatchContent" /* CatchContent */].___params?.(
1689
- tryBranch2._["ConditionalScope:" /* ConditionalScope */ + tryBranch2["#BranchAccessor" /* BranchAccessor */]],
1690
- [error]
1691
- );
1692
- }
1680
+ renderCatch(scope, error, true);
1693
1681
  });
1694
- if (tryBranch) {
1695
- if (!tryBranch.___pendingAsyncCount) {
1696
- tryBranch.___pendingAsyncCount = 0;
1682
+ if (tryWithPlaceholder) {
1683
+ placeholderShown.add(pendingEffects);
1684
+ if (!tryWithPlaceholder.___pendingAsyncCount) {
1685
+ tryWithPlaceholder.___pendingAsyncCount = 0;
1697
1686
  requestAnimationFrame(() => {
1698
- if (tryBranch.___pendingAsyncCount && !tryBranch.___destroyed) {
1699
- const placeholderBranch = tryBranch["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1687
+ if (tryWithPlaceholder.___pendingAsyncCount && !tryWithPlaceholder.___destroyed) {
1688
+ const placeholderBranch = tryWithPlaceholder["#PlaceholderBranch" /* PlaceholderBranch */] = createAndSetupBranch(
1700
1689
  scope.$global,
1701
- tryBranch["#PlaceholderContent" /* PlaceholderContent */],
1702
- tryBranch._,
1703
- tryBranch.___startNode.parentNode
1690
+ tryWithPlaceholder["#PlaceholderContent" /* PlaceholderContent */],
1691
+ tryWithPlaceholder._,
1692
+ tryWithPlaceholder.___startNode.parentNode
1704
1693
  );
1705
1694
  insertBranchBefore(
1706
1695
  placeholderBranch,
1707
- tryBranch.___startNode.parentNode,
1708
- tryBranch.___startNode
1696
+ tryWithPlaceholder.___startNode.parentNode,
1697
+ tryWithPlaceholder.___startNode
1709
1698
  );
1710
- tempDetatchBranch(tryBranch);
1699
+ tempDetatchBranch(tryWithPlaceholder);
1711
1700
  }
1712
1701
  });
1713
1702
  }
1714
- tryBranch.___pendingAsyncCount++;
1703
+ tryWithPlaceholder.___pendingAsyncCount++;
1715
1704
  } else if (awaitBranch) {
1716
1705
  awaitBranch.___startNode.parentNode.insertBefore(
1717
1706
  referenceNode,
@@ -1742,6 +1731,35 @@ function createTry(nodeAccessor, tryContent) {
1742
1731
  }
1743
1732
  };
1744
1733
  }
1734
+ function renderCatch(scope, error, async) {
1735
+ const tryWithCatch = findBranchWithKey(scope, "#CatchContent" /* CatchContent */);
1736
+ if (!tryWithCatch) {
1737
+ if (async) {
1738
+ setTimeout(() => {
1739
+ throw error;
1740
+ });
1741
+ } else {
1742
+ throw error;
1743
+ }
1744
+ } else {
1745
+ const placeholderBranch = tryWithCatch["#PlaceholderBranch" /* PlaceholderBranch */];
1746
+ if (placeholderBranch) {
1747
+ tryWithCatch._["ConditionalScope:" /* ConditionalScope */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]] = placeholderBranch;
1748
+ destroyBranch(tryWithCatch);
1749
+ }
1750
+ caughtError.add(pendingEffects);
1751
+ setConditionalRenderer(
1752
+ tryWithCatch._,
1753
+ tryWithCatch["#BranchAccessor" /* BranchAccessor */],
1754
+ tryWithCatch["#CatchContent" /* CatchContent */],
1755
+ createAndSetupBranch
1756
+ );
1757
+ tryWithCatch["#CatchContent" /* CatchContent */].___params?.(
1758
+ tryWithCatch._["ConditionalScope:" /* ConditionalScope */ + tryWithCatch["#BranchAccessor" /* BranchAccessor */]],
1759
+ [error]
1760
+ );
1761
+ }
1762
+ }
1745
1763
  function conditional(nodeAccessor, ...branches) {
1746
1764
  const branchAccessor = "ConditionalRenderer:" /* ConditionalRenderer */ + nodeAccessor;
1747
1765
  return (scope, newBranch) => {
@@ -1940,6 +1958,8 @@ function byFirstArg(name) {
1940
1958
  // src/dom/queue.ts
1941
1959
  var pendingRenders = [];
1942
1960
  var pendingRendersLookup = /* @__PURE__ */ new Map();
1961
+ var caughtError = /* @__PURE__ */ new WeakSet();
1962
+ var placeholderShown = /* @__PURE__ */ new WeakSet();
1943
1963
  var pendingEffects = [];
1944
1964
  var rendering = false;
1945
1965
  var scopeKeyOffset = 1e3;
@@ -2002,14 +2022,14 @@ function prepareEffects(fn) {
2002
2022
  }
2003
2023
  return preparedEffects;
2004
2024
  }
2005
- function runEffects(effects) {
2025
+ var runEffects = (effects) => {
2006
2026
  for (let i = 0, scope; i < effects.length; ) {
2007
2027
  effects[i++](
2008
2028
  scope = effects[i++],
2009
2029
  scope
2010
2030
  );
2011
2031
  }
2012
- }
2032
+ };
2013
2033
  function runRenders() {
2014
2034
  while (pendingRenders.length) {
2015
2035
  const render = pendingRenders[0];
@@ -2043,27 +2063,37 @@ var runRender = (render) => render.___signal(render.___scope, render.___value);
2043
2063
  var enableCatch = () => {
2044
2064
  enableCatch = () => {
2045
2065
  };
2066
+ const handlePendingTry = (fn, scope, branch) => {
2067
+ while (branch) {
2068
+ if (branch.___pendingAsyncCount) {
2069
+ return (branch.___effects ||= []).push(fn, scope);
2070
+ }
2071
+ branch = branch.___parentBranch;
2072
+ }
2073
+ };
2074
+ runEffects = /* @__PURE__ */ ((runEffects2) => (effects, checkPending = placeholderShown.has(effects)) => {
2075
+ if (checkPending || caughtError.has(effects)) {
2076
+ let i = 0;
2077
+ let fn;
2078
+ let scope;
2079
+ let branch;
2080
+ for (; i < effects.length; ) {
2081
+ fn = effects[i++];
2082
+ scope = effects[i++];
2083
+ branch = scope.___closestBranch;
2084
+ if (!branch?.___destroyed && !(checkPending && handlePendingTry(fn, scope, branch))) {
2085
+ fn(scope, scope);
2086
+ }
2087
+ }
2088
+ } else {
2089
+ runEffects2(effects);
2090
+ }
2091
+ })(runEffects);
2046
2092
  runRender = /* @__PURE__ */ ((runRender2) => (render) => {
2047
2093
  try {
2048
2094
  runRender2(render);
2049
2095
  } catch (error) {
2050
- let branch = render.___scope.___closestBranch;
2051
- while (branch && !branch["#CatchContent" /* CatchContent */])
2052
- branch = branch.___parentBranch;
2053
- if (!branch) {
2054
- throw error;
2055
- } else {
2056
- setConditionalRenderer(
2057
- branch._,
2058
- branch["#BranchAccessor" /* BranchAccessor */],
2059
- branch["#CatchContent" /* CatchContent */],
2060
- createAndSetupBranch
2061
- );
2062
- branch["#CatchContent" /* CatchContent */].___params?.(
2063
- branch._["ConditionalScope:" /* ConditionalScope */ + branch["#BranchAccessor" /* BranchAccessor */]],
2064
- [error]
2065
- );
2066
- }
2096
+ renderCatch(render.___scope, error);
2067
2097
  }
2068
2098
  })(runRender);
2069
2099
  };