marko 6.0.0-next.3.68 → 6.0.0-next.3.70

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.
@@ -501,11 +501,7 @@ var Reference = class {
501
501
  };
502
502
  var DEBUG = /* @__PURE__ */ new WeakMap();
503
503
  function setDebugInfo(obj, file, loc, vars) {
504
- DEBUG.set(obj, {
505
- file,
506
- loc,
507
- vars
508
- });
504
+ DEBUG.set(obj, { file, loc, vars });
509
505
  }
510
506
  var Serializer = class {
511
507
  #state = new State();
@@ -564,10 +560,7 @@ function register(id, val, scope) {
564
560
  function getRegistered(val) {
565
561
  const registered = REGISTRY.get(val);
566
562
  if (registered) {
567
- return {
568
- id: registered.id,
569
- scope: registered.scope
570
- };
563
+ return { id: registered.id, scope: registered.scope };
571
564
  }
572
565
  }
573
566
  function writeRoot(state, root) {
@@ -737,7 +730,7 @@ function writeRegistered(state, val, parent, accessor, { access, scope, getter }
737
730
  return true;
738
731
  }
739
732
  if (scopeRef) {
740
- if (isCircular(parent, scopeRef)) {
733
+ if (parent && (state.assigned.has(scopeRef) || isCircular(parent, scopeRef))) {
741
734
  state.assigned.add(parent);
742
735
  state.assigned.add(fnRef);
743
736
  fnRef.init = access + "(" + ensureId(state, scopeRef) + ")";
@@ -1593,7 +1586,7 @@ function withContext(key, value, cb) {
1593
1586
  ctx[kPendingContexts]++;
1594
1587
  ctx[key] = value;
1595
1588
  try {
1596
- cb();
1589
+ return cb();
1597
1590
  } finally {
1598
1591
  ctx[kPendingContexts]--;
1599
1592
  ctx[key] = prev;
@@ -1654,23 +1647,33 @@ function hoist(scopeId, id) {
1654
1647
  function resumeClosestBranch(scopeId) {
1655
1648
  const branchId = $chunk.context?.[branchIdKey];
1656
1649
  if (branchId !== void 0 && branchId !== scopeId) {
1657
- writeScope(scopeId, {
1658
- ["#ClosestBranchId" /* ClosestBranchId */]: branchId
1659
- });
1650
+ writeScope(scopeId, { ["#ClosestBranchId" /* ClosestBranchId */]: branchId });
1660
1651
  }
1661
1652
  }
1662
1653
  var branchIdKey = Symbol();
1663
- function resumeForOf(list, cb, scopeId, accessor) {
1664
- forOf(list, (item, i) => {
1654
+ function withBranchId(branchId, cb) {
1655
+ return withContext(branchIdKey, branchId, cb);
1656
+ }
1657
+ function resumeForOf(list, cb, by, scopeId, accessor) {
1658
+ const loopScopes = /* @__PURE__ */ new Map();
1659
+ forOf(list, (item, index) => {
1665
1660
  const branchId = peekNextScopeId();
1666
1661
  $chunk.writeHTML(
1667
1662
  $chunk.boundary.state.mark(
1668
1663
  "[" /* BranchStart */,
1669
- branchId + (i ? " " : "")
1664
+ branchId + (index ? " " : "")
1670
1665
  )
1671
1666
  );
1672
- withContext(branchIdKey, branchId, () => cb(item, i));
1667
+ withBranchId(branchId, () => {
1668
+ cb(item, index);
1669
+ loopScopes.set(forOfBy(by, item, index), writeScope(branchId, {}));
1670
+ });
1673
1671
  });
1672
+ if (loopScopes.size) {
1673
+ writeScope(scopeId, {
1674
+ ["LoopScopeMap:" /* LoopScopeMap */ + accessor]: loopScopes
1675
+ });
1676
+ }
1674
1677
  $chunk.writeHTML(
1675
1678
  $chunk.boundary.state.mark(
1676
1679
  "]" /* BranchEnd */,
@@ -1678,13 +1681,22 @@ function resumeForOf(list, cb, scopeId, accessor) {
1678
1681
  )
1679
1682
  );
1680
1683
  }
1681
- function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
1684
+ function resumeSingleNodeForOf(list, cb, by, scopeId, accessor, onlyChildInParent) {
1685
+ const loopScopes = /* @__PURE__ */ new Map();
1682
1686
  let branchIds = "";
1683
1687
  forOf(list, (item, index) => {
1684
1688
  const branchId = peekNextScopeId();
1685
1689
  branchIds = " " + branchId + branchIds;
1686
- withContext(branchIdKey, branchId, () => cb(item, index));
1690
+ withBranchId(branchId, () => {
1691
+ cb(item, index);
1692
+ loopScopes.set(forOfBy(by, item, index), writeScope(branchId, {}));
1693
+ });
1687
1694
  });
1695
+ if (loopScopes.size) {
1696
+ writeScope(scopeId, {
1697
+ ["LoopScopeMap:" /* LoopScopeMap */ + accessor]: loopScopes
1698
+ });
1699
+ }
1688
1700
  $chunk.writeHTML(
1689
1701
  $chunk.boundary.state.mark(
1690
1702
  onlyChildInParent ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1692,7 +1704,17 @@ function resumeSingleNodeForOf(list, cb, scopeId, accessor, onlyChildInParent) {
1692
1704
  )
1693
1705
  );
1694
1706
  }
1695
- function resumeForIn(obj, cb, scopeId, accessor) {
1707
+ function forOfBy(by, item, index) {
1708
+ if (by) {
1709
+ if (typeof by === "string") {
1710
+ return item[by];
1711
+ }
1712
+ return by(item, index);
1713
+ }
1714
+ return index;
1715
+ }
1716
+ function resumeForIn(obj, cb, by, scopeId, accessor) {
1717
+ const loopScopes = /* @__PURE__ */ new Map();
1696
1718
  let sep = "";
1697
1719
  forIn(obj, (key, value) => {
1698
1720
  const branchId = peekNextScopeId();
@@ -1700,8 +1722,16 @@ function resumeForIn(obj, cb, scopeId, accessor) {
1700
1722
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1701
1723
  );
1702
1724
  sep = " ";
1703
- withContext(branchIdKey, branchId, () => cb(key, value));
1725
+ withBranchId(branchId, () => {
1726
+ cb(key, value);
1727
+ loopScopes.set(forInBy(by, key, value), writeScope(branchId, {}));
1728
+ });
1704
1729
  });
1730
+ if (loopScopes.size) {
1731
+ writeScope(scopeId, {
1732
+ ["LoopScopeMap:" /* LoopScopeMap */ + accessor]: loopScopes
1733
+ });
1734
+ }
1705
1735
  $chunk.writeHTML(
1706
1736
  $chunk.boundary.state.mark(
1707
1737
  "]" /* BranchEnd */,
@@ -1709,13 +1739,22 @@ function resumeForIn(obj, cb, scopeId, accessor) {
1709
1739
  )
1710
1740
  );
1711
1741
  }
1712
- function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
1742
+ function resumeSingleNodeForIn(obj, cb, by, scopeId, accessor, onlyChild) {
1743
+ const loopScopes = /* @__PURE__ */ new Map();
1713
1744
  let branchIds = "";
1714
1745
  forIn(obj, (key, value) => {
1715
1746
  const branchId = peekNextScopeId();
1716
1747
  branchIds = " " + branchId + branchIds;
1717
- withContext(branchIdKey, branchId, () => cb(key, value));
1748
+ withBranchId(branchId, () => {
1749
+ cb(key, value);
1750
+ loopScopes.set(forInBy(by, key, value), writeScope(branchId, {}));
1751
+ });
1718
1752
  });
1753
+ if (loopScopes.size) {
1754
+ writeScope(scopeId, {
1755
+ ["LoopScopeMap:" /* LoopScopeMap */ + accessor]: loopScopes
1756
+ });
1757
+ }
1719
1758
  $chunk.writeHTML(
1720
1759
  $chunk.boundary.state.mark(
1721
1760
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1723,7 +1762,14 @@ function resumeSingleNodeForIn(obj, cb, scopeId, accessor, onlyChild) {
1723
1762
  )
1724
1763
  );
1725
1764
  }
1726
- function resumeForTo(to, from, step, cb, scopeId, accessor) {
1765
+ function forInBy(by, name, value) {
1766
+ if (by) {
1767
+ return by(name, value);
1768
+ }
1769
+ return name;
1770
+ }
1771
+ function resumeForTo(to, from, step, cb, by, scopeId, accessor) {
1772
+ const loopScopes = /* @__PURE__ */ new Map();
1727
1773
  let sep = "";
1728
1774
  forTo(to, from, step, (index) => {
1729
1775
  const branchId = peekNextScopeId();
@@ -1731,8 +1777,16 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
1731
1777
  $chunk.boundary.state.mark("[" /* BranchStart */, branchId + sep)
1732
1778
  );
1733
1779
  sep = " ";
1734
- withContext(branchIdKey, branchId, () => cb(index));
1780
+ withBranchId(branchId, () => {
1781
+ cb(index);
1782
+ loopScopes.set(forToBy(by, index), writeScope(branchId, {}));
1783
+ });
1735
1784
  });
1785
+ if (loopScopes.size) {
1786
+ writeScope(scopeId, {
1787
+ ["LoopScopeMap:" /* LoopScopeMap */ + accessor]: loopScopes
1788
+ });
1789
+ }
1736
1790
  $chunk.writeHTML(
1737
1791
  $chunk.boundary.state.mark(
1738
1792
  "]" /* BranchEnd */,
@@ -1740,13 +1794,22 @@ function resumeForTo(to, from, step, cb, scopeId, accessor) {
1740
1794
  )
1741
1795
  );
1742
1796
  }
1743
- function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild) {
1797
+ function resumeSingleNodeForTo(to, from, step, cb, by, scopeId, accessor, onlyChild) {
1798
+ const loopScopes = /* @__PURE__ */ new Map();
1744
1799
  let branchIds = "";
1745
1800
  forTo(to, from, step, (index) => {
1746
1801
  const branchId = peekNextScopeId();
1747
1802
  branchIds = " " + branchId + branchIds;
1748
- withContext(branchIdKey, branchId, () => cb(index));
1803
+ withBranchId(branchId, () => {
1804
+ cb(index);
1805
+ loopScopes.set(forToBy(by, index), writeScope(branchId, {}));
1806
+ });
1749
1807
  });
1808
+ if (loopScopes.size) {
1809
+ writeScope(scopeId, {
1810
+ ["LoopScopeMap:" /* LoopScopeMap */ + accessor]: loopScopes
1811
+ });
1812
+ }
1750
1813
  $chunk.writeHTML(
1751
1814
  $chunk.boundary.state.mark(
1752
1815
  onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
@@ -1754,40 +1817,57 @@ function resumeSingleNodeForTo(to, from, step, cb, scopeId, accessor, onlyChild)
1754
1817
  )
1755
1818
  );
1756
1819
  }
1757
- function resumeConditional(cb, scopeId, accessor) {
1820
+ function forToBy(by, index) {
1821
+ if (by) {
1822
+ return by(index);
1823
+ }
1824
+ return index;
1825
+ }
1826
+ function resumeConditional(cb, scopeId, accessor, dynamic) {
1758
1827
  const branchId = peekNextScopeId();
1759
- $chunk.writeHTML(
1760
- $chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
1761
- );
1762
- withContext(branchIdKey, branchId, cb);
1763
- const rendered = peekNextScopeId() !== branchId;
1764
- if (rendered) {
1765
- writeScope(branchId, {});
1828
+ if (dynamic) {
1829
+ $chunk.writeHTML(
1830
+ $chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
1831
+ );
1832
+ }
1833
+ const branchIndex = withBranchId(branchId, cb);
1834
+ if (branchIndex !== void 0) {
1835
+ writeScope(scopeId, {
1836
+ ["ConditionalRenderer:" /* ConditionalRenderer */ + accessor]: dynamic ? branchIndex : void 0,
1837
+ ["ConditionalScope:" /* ConditionalScope */ + accessor]: writeScope(branchId, {})
1838
+ });
1766
1839
  } else {
1767
1840
  nextScopeId();
1768
1841
  }
1769
- $chunk.writeHTML(
1770
- $chunk.boundary.state.mark(
1771
- "]" /* BranchEnd */,
1772
- scopeId + " " + accessor
1773
- )
1774
- );
1842
+ if (dynamic) {
1843
+ $chunk.writeHTML(
1844
+ $chunk.boundary.state.mark(
1845
+ "]" /* BranchEnd */,
1846
+ scopeId + " " + accessor
1847
+ )
1848
+ );
1849
+ }
1775
1850
  }
1776
- function resumeSingleNodeConditional(cb, scopeId, accessor, onlyChild) {
1851
+ function resumeSingleNodeConditional(cb, scopeId, accessor, dynamic, onlyChild) {
1777
1852
  const branchId = peekNextScopeId();
1778
- withContext(branchIdKey, branchId, cb);
1779
- const rendered = peekNextScopeId() !== branchId;
1853
+ const branchIndex = withBranchId(branchId, cb);
1854
+ const rendered = branchIndex !== void 0;
1780
1855
  if (rendered) {
1781
- writeScope(branchId, {});
1856
+ writeScope(scopeId, {
1857
+ ["ConditionalRenderer:" /* ConditionalRenderer */ + accessor]: dynamic ? branchIndex : void 0,
1858
+ ["ConditionalScope:" /* ConditionalScope */ + accessor]: writeScope(branchId, {})
1859
+ });
1782
1860
  } else {
1783
1861
  nextScopeId();
1784
1862
  }
1785
- $chunk.writeHTML(
1786
- $chunk.boundary.state.mark(
1787
- onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
1788
- scopeId + " " + accessor + (rendered ? " " + branchId : "")
1789
- )
1790
- );
1863
+ if (dynamic) {
1864
+ $chunk.writeHTML(
1865
+ $chunk.boundary.state.mark(
1866
+ onlyChild ? "=" /* BranchSingleNodeOnlyChildInParent */ : "|" /* BranchSingleNode */,
1867
+ scopeId + " " + accessor + (rendered ? " " + branchId : "")
1868
+ )
1869
+ );
1870
+ }
1791
1871
  }
1792
1872
  var writeScope = (scopeId, partialScope) => {
1793
1873
  const { state } = $chunk.boundary;
@@ -1987,7 +2067,7 @@ function tryCatch(content, catchContent) {
1987
2067
  catchChunk.render(catchContent, catchBoundary.signal.reason);
1988
2068
  state.reorder(catchChunk);
1989
2069
  boundary.endAsync();
1990
- } else if (catchBoundary.done) {
2070
+ } else if (!catchBoundary.count) {
1991
2071
  boundary.endAsync();
1992
2072
  } else {
1993
2073
  boundary.onNext();
@@ -2012,6 +2092,7 @@ var State2 = class {
2012
2092
  hasReorderRuntime = false;
2013
2093
  hasWrittenResume = false;
2014
2094
  trailerHTML = "";
2095
+ resumes = "";
2015
2096
  nonceAttr = "";
2016
2097
  serializer = new Serializer();
2017
2098
  writeReorders = null;
@@ -2075,7 +2156,8 @@ var Boundary = class extends AbortController {
2075
2156
  onNext = NOOP;
2076
2157
  count = 0;
2077
2158
  get done() {
2078
- return this.count === 0;
2159
+ flushSerializer(this);
2160
+ return !this.count;
2079
2161
  }
2080
2162
  startAsync() {
2081
2163
  if (!this.signal.aborted) {
@@ -2181,145 +2263,152 @@ var Chunk = class {
2181
2263
  $chunk = prev;
2182
2264
  }
2183
2265
  }
2184
- };
2185
- function prepareChunk(chunk) {
2186
- const head = chunk.consume();
2187
- const { boundary, effects } = head;
2188
- const { state } = boundary;
2189
- const { $global: $global2, runtimePrefix, serializer, nonceAttr } = state;
2190
- let { html, scripts } = head;
2191
- let hasWalk = false;
2192
- head.effects = "";
2193
- if (state.needsMainRuntime && !state.hasMainRuntime) {
2194
- state.hasMainRuntime = true;
2195
- scripts = concatScripts(
2196
- scripts,
2197
- WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2198
- );
2199
- }
2200
- let resumes = "";
2201
- if (state.writeScopes || serializer.flushed) {
2202
- let { lastSerializedScopeId } = state;
2203
- const serializeData = [];
2204
- if (!state.hasGlobals) {
2205
- state.hasGlobals = true;
2206
- serializeData.push(getFilteredGlobals(state.$global));
2207
- }
2208
- for (const key in state.writeScopes) {
2209
- const scope = state.writeScopes[key];
2210
- const scopeId = getScopeId(scope);
2211
- const scopeIdDelta = scopeId - lastSerializedScopeId;
2212
- lastSerializedScopeId = scopeId + 1;
2213
- if (scopeIdDelta) serializeData.push(scopeIdDelta);
2214
- serializeData.push(scope);
2215
- }
2216
- resumes = state.serializer.stringify(serializeData, boundary);
2217
- state.writeScopes = null;
2218
- state.lastSerializedScopeId = lastSerializedScopeId;
2219
- }
2220
- if (effects) {
2221
- hasWalk = true;
2222
- resumes = resumes ? resumes + "," + effects : effects;
2223
- }
2224
- if (resumes) {
2225
- if (state.hasWrittenResume) {
2226
- scripts = concatScripts(
2227
- scripts,
2228
- runtimePrefix + ".r.push(" + resumes + ")"
2229
- );
2230
- } else {
2231
- state.hasWrittenResume = true;
2266
+ flushScript() {
2267
+ flushSerializer(this.boundary);
2268
+ const { boundary, effects } = this;
2269
+ const { state } = boundary;
2270
+ const { $global: $global2, runtimePrefix, nonceAttr } = state;
2271
+ let { resumes } = state;
2272
+ let { html, scripts } = this;
2273
+ let hasWalk = false;
2274
+ if (state.needsMainRuntime && !state.hasMainRuntime) {
2275
+ state.hasMainRuntime = true;
2232
2276
  scripts = concatScripts(
2233
2277
  scripts,
2234
- runtimePrefix + ".r=[" + resumes + "]"
2278
+ WALKER_RUNTIME_CODE + '("' + $global2.runtimeId + '")("' + $global2.renderId + '")'
2235
2279
  );
2236
2280
  }
2237
- }
2238
- if (state.writeReorders) {
2239
- hasWalk = true;
2240
- if (!state.hasReorderRuntime) {
2241
- state.hasReorderRuntime = true;
2242
- html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2243
- scripts = concatScripts(
2244
- scripts,
2245
- REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
2246
- );
2281
+ if (effects) {
2282
+ hasWalk = true;
2283
+ resumes = resumes ? resumes + "," + effects : effects;
2247
2284
  }
2248
- for (const reorderedChunk of state.writeReorders) {
2249
- const { reorderId } = reorderedChunk;
2250
- let reorderHTML = "";
2251
- let reorderEffects = "";
2252
- let reorderScripts = "";
2253
- let cur = reorderedChunk;
2254
- reorderedChunk.reorderId = null;
2255
- for (; ; ) {
2256
- cur.flushPlaceholder();
2257
- const { next } = cur;
2258
- cur.consumed = true;
2259
- reorderHTML += cur.html;
2260
- reorderEffects = concatEffects(reorderEffects, cur.effects);
2261
- reorderScripts = concatScripts(reorderScripts, cur.scripts);
2262
- if (cur.async) {
2263
- reorderHTML += state.mark(
2264
- "#" /* ReorderMarker */,
2265
- cur.reorderId = state.nextReorderId()
2266
- );
2267
- cur.html = cur.effects = cur.scripts = "";
2268
- cur.next = null;
2269
- }
2270
- if (next) {
2271
- cur = next;
2272
- } else {
2273
- break;
2274
- }
2285
+ if (resumes) {
2286
+ if (state.hasWrittenResume) {
2287
+ scripts = concatScripts(
2288
+ scripts,
2289
+ runtimePrefix + ".r.push(" + resumes + ")"
2290
+ );
2291
+ } else {
2292
+ state.hasWrittenResume = true;
2293
+ scripts = concatScripts(
2294
+ scripts,
2295
+ runtimePrefix + ".r=[" + resumes + "]"
2296
+ );
2297
+ }
2298
+ }
2299
+ if (state.writeReorders) {
2300
+ hasWalk = true;
2301
+ if (!state.hasReorderRuntime) {
2302
+ state.hasReorderRuntime = true;
2303
+ html += "<style " + state.commentPrefix + nonceAttr + ">t{display:none}</style>";
2304
+ scripts = concatScripts(
2305
+ scripts,
2306
+ REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")"
2307
+ );
2275
2308
  }
2276
- if (reorderEffects) {
2277
- if (!state.hasWrittenResume) {
2278
- state.hasWrittenResume = true;
2279
- scripts = concatScripts(
2280
- scripts,
2281
- runtimePrefix + ".r=[]"
2309
+ for (const reorderedChunk of state.writeReorders) {
2310
+ const { reorderId } = reorderedChunk;
2311
+ let reorderHTML = "";
2312
+ let reorderEffects = "";
2313
+ let reorderScripts = "";
2314
+ let cur = reorderedChunk;
2315
+ reorderedChunk.reorderId = null;
2316
+ for (; ; ) {
2317
+ cur.flushPlaceholder();
2318
+ const { next } = cur;
2319
+ cur.consumed = true;
2320
+ reorderHTML += cur.html;
2321
+ reorderEffects = concatEffects(reorderEffects, cur.effects);
2322
+ reorderScripts = concatScripts(reorderScripts, cur.scripts);
2323
+ if (cur.async) {
2324
+ reorderHTML += state.mark(
2325
+ "#" /* ReorderMarker */,
2326
+ cur.reorderId = state.nextReorderId()
2327
+ );
2328
+ cur.html = cur.effects = cur.scripts = "";
2329
+ cur.next = null;
2330
+ }
2331
+ if (next) {
2332
+ cur = next;
2333
+ } else {
2334
+ break;
2335
+ }
2336
+ }
2337
+ if (reorderEffects) {
2338
+ if (!state.hasWrittenResume) {
2339
+ state.hasWrittenResume = true;
2340
+ scripts = concatScripts(
2341
+ scripts,
2342
+ runtimePrefix + ".r=[]"
2343
+ );
2344
+ }
2345
+ reorderScripts = concatScripts(
2346
+ reorderScripts,
2347
+ "_.push(" + reorderEffects + ")"
2282
2348
  );
2283
2349
  }
2284
- reorderScripts = concatScripts(
2285
- reorderScripts,
2286
- "_.push(" + reorderEffects + ")"
2350
+ scripts = concatScripts(
2351
+ scripts,
2352
+ reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
2287
2353
  );
2354
+ html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2288
2355
  }
2289
- scripts = concatScripts(
2290
- scripts,
2291
- reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
2292
- );
2293
- html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2356
+ state.writeReorders = null;
2294
2357
  }
2295
- state.writeReorders = null;
2358
+ if (hasWalk) {
2359
+ scripts = concatScripts(scripts, runtimePrefix + ".w()");
2360
+ }
2361
+ this.effects = state.resumes = "";
2362
+ this.html = html;
2363
+ this.scripts = scripts;
2364
+ return this;
2296
2365
  }
2297
- if (hasWalk) {
2298
- scripts = concatScripts(scripts, runtimePrefix + ".w()");
2366
+ flushHTML() {
2367
+ this.flushScript();
2368
+ const { boundary, scripts } = this;
2369
+ const { state } = boundary;
2370
+ const { $global: $global2, nonceAttr } = state;
2371
+ const { __flush__ } = $global2;
2372
+ let { html } = this;
2373
+ this.html = this.scripts = "";
2374
+ if (scripts) {
2375
+ html += "<script" + nonceAttr + ">" + scripts + "</script>";
2376
+ }
2377
+ if (__flush__) {
2378
+ $global2.__flush__ = void 0;
2379
+ html = __flush__($global2, html);
2380
+ }
2381
+ if (!boundary.count) {
2382
+ html += state.trailerHTML;
2383
+ }
2384
+ return html;
2299
2385
  }
2300
- head.html = html;
2301
- head.scripts = scripts;
2302
- return head;
2303
- }
2304
- function flushChunk(head, last) {
2305
- const { boundary } = head;
2386
+ };
2387
+ function flushSerializer(boundary) {
2306
2388
  const { state } = boundary;
2307
- const { html, scripts } = head;
2308
- const { $global: $global2 } = state;
2309
- const { __flush__ } = $global2;
2310
- let result = html;
2311
- head.html = head.scripts = "";
2312
- if (scripts) {
2313
- result += "<script" + state.nonceAttr + ">" + scripts + "</script>";
2314
- }
2315
- if (__flush__) {
2316
- $global2.__flush__ = void 0;
2317
- result = __flush__($global2, result);
2318
- }
2319
- if (last && state.trailerHTML) {
2320
- result += state.trailerHTML;
2389
+ const { writeScopes, serializer } = state;
2390
+ if (writeScopes || serializer.flushed) {
2391
+ const serializeData = [];
2392
+ let { lastSerializedScopeId } = state;
2393
+ if (!state.hasGlobals) {
2394
+ state.hasGlobals = true;
2395
+ serializeData.push(getFilteredGlobals(state.$global));
2396
+ }
2397
+ for (const key in writeScopes) {
2398
+ const scope = writeScopes[key];
2399
+ const scopeId = getScopeId(scope);
2400
+ const scopeIdDelta = scopeId - lastSerializedScopeId;
2401
+ lastSerializedScopeId = scopeId + 1;
2402
+ if (scopeIdDelta) serializeData.push(scopeIdDelta);
2403
+ serializeData.push(scope);
2404
+ }
2405
+ state.resumes = concatEffects(
2406
+ state.resumes,
2407
+ serializer.stringify(serializeData, boundary)
2408
+ );
2409
+ state.lastSerializedScopeId = lastSerializedScopeId;
2410
+ state.writeScopes = null;
2321
2411
  }
2322
- return result;
2323
2412
  }
2324
2413
  function writeTrailers(html) {
2325
2414
  $chunk.boundary.state.trailerHTML += html;
@@ -2640,117 +2729,97 @@ var DEFAULT_RENDER_ID = "_";
2640
2729
 
2641
2730
  // src/html/dynamic-tag.ts
2642
2731
  var voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/;
2643
- function dynamicTagId(tagName) {
2644
- const normalizedRenderer = normalizeDynamicRenderer(tagName);
2645
- return normalizedRenderer?.___id || normalizedRenderer;
2646
- }
2647
- var dynamicTagInput = (scopeId, accessor, tag, input, content) => {
2648
- if (!tag && !content) {
2649
- nextScopeId();
2650
- return;
2651
- }
2652
- if (!tag) {
2653
- resumeConditional(content, scopeId, accessor);
2654
- return;
2732
+ var dynamicTag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, resume) => {
2733
+ const renderer = normalizeDynamicRenderer(tag);
2734
+ if (true) {
2735
+ if (renderer && typeof renderer !== "function" && typeof renderer !== "string") {
2736
+ throw new Error(`Invalid renderer passed for dynamic tag: ${renderer}`);
2737
+ }
2655
2738
  }
2656
- if (typeof tag === "string") {
2657
- resumeSingleNodeConditional(
2658
- () => {
2659
- nextScopeId();
2660
- write(`<${tag}${attrs(input, accessor, scopeId, tag)}>`);
2661
- if (!voidElementsReg.test(tag)) {
2662
- if (tag === "textarea") {
2663
- if (content) {
2664
- throw new Error(
2665
- "A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead."
2666
- );
2667
- }
2668
- write(
2669
- controllable_textarea_value(
2670
- scopeId,
2671
- accessor,
2672
- input.value,
2673
- input.valueChange
2674
- )
2739
+ const chunk = getChunk();
2740
+ const branchId = peekNextScopeId();
2741
+ let result;
2742
+ if (typeof renderer === "string") {
2743
+ const input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
2744
+ nextScopeId();
2745
+ write(`<${renderer}${attrs(input, accessor, scopeId, renderer)}>`);
2746
+ if (!voidElementsReg.test(renderer)) {
2747
+ withBranchId(branchId, () => {
2748
+ if (renderer === "textarea") {
2749
+ if (content) {
2750
+ throw new Error(
2751
+ "A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead."
2675
2752
  );
2676
- } else if (content) {
2677
- if (tag === "select" && ("value" in input || "valueChange" in input)) {
2678
- controllable_select_value(
2679
- scopeId,
2680
- accessor,
2681
- input.value,
2682
- input.valueChange,
2683
- content
2684
- );
2685
- } else {
2686
- content();
2687
- }
2688
2753
  }
2689
- write(`</${tag}>`);
2754
+ write(
2755
+ controllable_textarea_value(
2756
+ scopeId,
2757
+ accessor,
2758
+ input.value,
2759
+ input.valueChange
2760
+ )
2761
+ );
2690
2762
  } else if (content) {
2691
- throw new Error(`Body content is not supported for a "${tag}" tag.`);
2763
+ if (renderer === "select" && ("value" in input || "valueChange" in input)) {
2764
+ controllable_select_value(
2765
+ scopeId,
2766
+ accessor,
2767
+ input.value,
2768
+ input.valueChange,
2769
+ content
2770
+ );
2771
+ } else {
2772
+ content();
2773
+ }
2692
2774
  }
2693
- },
2694
- scopeId,
2695
- accessor
2696
- );
2697
- return;
2698
- }
2699
- const renderer = normalizeDynamicRenderer(
2700
- tag
2701
- );
2702
- if (true) {
2703
- if (typeof renderer !== "function") {
2704
- throw new Error(`Invalid renderer passed for dynamic tag: ${tag}`);
2775
+ });
2776
+ write(`</${renderer}>`);
2777
+ } else if (content) {
2778
+ throw new Error(`Body content is not supported for a "${renderer}" tag.`);
2779
+ }
2780
+ if (resume) {
2781
+ chunk.writeHTML(
2782
+ chunk.boundary.state.mark(
2783
+ "|" /* BranchSingleNode */,
2784
+ scopeId + " " + accessor + " " + branchId
2785
+ )
2786
+ );
2705
2787
  }
2706
- }
2707
- let result;
2708
- resumeConditional(
2709
- () => {
2710
- result = renderer(content ? { ...input, content } : input);
2711
- },
2712
- scopeId,
2713
- accessor
2714
- );
2715
- return result;
2716
- };
2717
- var dynamicTagArgs = (scopeId, accessor, tag, args) => {
2718
- if (!tag) {
2719
- nextScopeId();
2720
- return;
2721
- }
2722
- if (typeof tag === "string") {
2723
- resumeSingleNodeConditional(
2724
- () => {
2725
- nextScopeId();
2726
- write(
2727
- `<${tag}${attrs(args[0], accessor, scopeId, tag)}>`
2788
+ } else {
2789
+ if (resume) {
2790
+ chunk.writeHTML(
2791
+ chunk.boundary.state.mark("[" /* BranchStart */, branchId + "")
2792
+ );
2793
+ }
2794
+ result = withBranchId(branchId, () => {
2795
+ if (renderer) {
2796
+ return inputIsArgs ? renderer(...inputOrArgs) : renderer(
2797
+ content ? { ...inputOrArgs, content } : inputOrArgs
2728
2798
  );
2729
- if (!voidElementsReg.test(tag)) {
2730
- write(`</${tag}>`);
2731
- }
2732
- },
2733
- scopeId,
2734
- accessor
2735
- );
2736
- return;
2799
+ } else if (content) {
2800
+ return content();
2801
+ }
2802
+ });
2803
+ if (resume) {
2804
+ chunk.writeHTML(
2805
+ chunk.boundary.state.mark(
2806
+ "]" /* BranchEnd */,
2807
+ scopeId + " " + accessor
2808
+ )
2809
+ );
2810
+ }
2737
2811
  }
2738
- const renderer = normalizeDynamicRenderer(
2739
- tag
2740
- );
2741
- if (true) {
2742
- if (typeof renderer !== "function") {
2743
- throw new Error(`Invalid renderer passed for dynamic tag: ${tag}`);
2812
+ const rendered = peekNextScopeId() !== branchId;
2813
+ if (rendered) {
2814
+ if (resume) {
2815
+ writeScope(scopeId, {
2816
+ ["ConditionalScope:" /* ConditionalScope */ + accessor]: writeScope(branchId, {}),
2817
+ ["ConditionalRenderer:" /* ConditionalRenderer */ + accessor]: renderer?.___id || renderer
2818
+ });
2744
2819
  }
2820
+ } else {
2821
+ nextScopeId();
2745
2822
  }
2746
- let result;
2747
- resumeConditional(
2748
- () => {
2749
- result = renderer(...args);
2750
- },
2751
- scopeId,
2752
- accessor
2753
- );
2754
2823
  return result;
2755
2824
  };
2756
2825
  function createContent(id, fn) {
@@ -2761,19 +2830,19 @@ function registerContent(id, fn, scopeId) {
2761
2830
  return register2(createContent(id, fn), id, scopeId);
2762
2831
  }
2763
2832
  function patchDynamicTag(patch) {
2764
- dynamicTagInput = /* @__PURE__ */ ((originalDynamicTagInput) => (scopeId, accessor, tag, input, content) => originalDynamicTagInput(
2765
- scopeId,
2766
- accessor,
2767
- patch(scopeId, accessor, tag),
2768
- input,
2769
- content
2770
- ))(dynamicTagInput);
2771
- dynamicTagArgs = /* @__PURE__ */ ((originalDynamicTagArgs) => (scopeId, accessor, tag, args) => originalDynamicTagArgs(
2772
- scopeId,
2773
- accessor,
2774
- patch(scopeId, accessor, tag),
2775
- args
2776
- ))(dynamicTagArgs);
2833
+ dynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
2834
+ const patched = patch(scopeId, accessor, tag);
2835
+ patched.___id = tag;
2836
+ return originalDynamicTag(
2837
+ scopeId,
2838
+ accessor,
2839
+ patched,
2840
+ input,
2841
+ content,
2842
+ inputIsArgs,
2843
+ resume
2844
+ );
2845
+ })(dynamicTag);
2777
2846
  }
2778
2847
 
2779
2848
  // src/html/compat.ts
@@ -2819,7 +2888,7 @@ var compat = {
2819
2888
  $global2[K_TAGS_API_STATE] = state = new State2($global2);
2820
2889
  }
2821
2890
  const boundary = new Boundary(state);
2822
- let head = new Chunk(
2891
+ const head = new Chunk(
2823
2892
  boundary,
2824
2893
  null,
2825
2894
  null
@@ -2840,24 +2909,18 @@ var compat = {
2840
2909
  renderer(normalizedInput);
2841
2910
  });
2842
2911
  const asyncOut = classAPIOut.beginAsync();
2843
- (boundary.onNext = () => {
2844
- if (boundary.done) {
2912
+ queueMicrotask(
2913
+ boundary.onNext = () => {
2845
2914
  if (boundary.signal.aborted) {
2846
2915
  asyncOut.error(boundary.signal.reason);
2847
- } else {
2848
- queueMicrotask(() => {
2849
- head = prepareChunk(head);
2850
- if (boundary.done) {
2851
- const { scripts, html } = head;
2852
- asyncOut.script(scripts);
2853
- asyncOut.write(html);
2854
- asyncOut.end();
2855
- head.html = head.scripts = "";
2856
- }
2857
- });
2916
+ } else if (boundary.done) {
2917
+ const { scripts, html } = head.consume().flushScript();
2918
+ asyncOut.script(scripts);
2919
+ asyncOut.write(html);
2920
+ asyncOut.end();
2858
2921
  }
2859
2922
  }
2860
- })();
2923
+ );
2861
2924
  },
2862
2925
  registerRenderer(renderer, id) {
2863
2926
  return register(
@@ -2873,7 +2936,7 @@ var compat = {
2873
2936
  };
2874
2937
 
2875
2938
  // src/html/for.ts
2876
- function forOfBy(by, item, index) {
2939
+ function forOfBy2(by, item, index) {
2877
2940
  if (by) {
2878
2941
  if (typeof by === "string") {
2879
2942
  return item[by];
@@ -2882,13 +2945,13 @@ function forOfBy(by, item, index) {
2882
2945
  }
2883
2946
  return index;
2884
2947
  }
2885
- function forInBy(by, name, value) {
2948
+ function forInBy2(by, name, value) {
2886
2949
  if (by) {
2887
2950
  return by(name, value);
2888
2951
  }
2889
2952
  return name;
2890
2953
  }
2891
- function forToBy(by, index) {
2954
+ function forToBy2(by, index) {
2892
2955
  if (by) {
2893
2956
  return by(index);
2894
2957
  }
@@ -2918,10 +2981,7 @@ function render(input = {}) {
2918
2981
  ...$global2
2919
2982
  };
2920
2983
  } else {
2921
- $global2 = {
2922
- runtimeId: DEFAULT_RUNTIME_ID,
2923
- renderId: DEFAULT_RENDER_ID
2924
- };
2984
+ $global2 = { runtimeId: DEFAULT_RUNTIME_ID, renderId: DEFAULT_RENDER_ID };
2925
2985
  }
2926
2986
  const head = new Chunk(
2927
2987
  new Boundary(new State2($global2), $global2.signal),
@@ -2985,19 +3045,13 @@ var ServerRenderResult = class {
2985
3045
  if (!(done || aborted)) {
2986
3046
  boundary?.abort(error);
2987
3047
  }
2988
- return Promise.resolve({
2989
- value: "",
2990
- done: true
2991
- });
3048
+ return Promise.resolve({ value: "", done: true });
2992
3049
  },
2993
3050
  return(value2) {
2994
3051
  if (!(done || aborted)) {
2995
3052
  boundary?.abort(new Error("Iterator returned before consumed."));
2996
3053
  }
2997
- return Promise.resolve({
2998
- value: value2,
2999
- done: true
3000
- });
3054
+ return Promise.resolve({ value: value2, done: true });
3001
3055
  }
3002
3056
  };
3003
3057
  function exec(_resolve, _reject) {
@@ -3052,7 +3106,7 @@ var ServerRenderResult = class {
3052
3106
  }
3053
3107
  #promise() {
3054
3108
  return this.#cachedPromise ||= new Promise((resolve, reject) => {
3055
- let head = this.#head;
3109
+ const head = this.#head;
3056
3110
  this.#head = null;
3057
3111
  if (!head) {
3058
3112
  return reject(new Error("Cannot read from a consumed render result"));
@@ -3063,10 +3117,7 @@ var ServerRenderResult = class {
3063
3117
  boundary.onNext = NOOP2;
3064
3118
  reject(boundary.signal.reason);
3065
3119
  } else if (boundary.done) {
3066
- head = prepareChunk(head);
3067
- if (boundary.done) {
3068
- resolve(flushChunk(head, true));
3069
- }
3120
+ resolve(head.consume().flushHTML());
3070
3121
  }
3071
3122
  })();
3072
3123
  });
@@ -3086,13 +3137,11 @@ var ServerRenderResult = class {
3086
3137
  boundary.onNext = NOOP2;
3087
3138
  onAbort(boundary.signal.reason);
3088
3139
  } else {
3089
- if (write2 || boundary.done) {
3090
- head = prepareChunk(head);
3091
- }
3092
- if (write2 || boundary.done) {
3093
- const html = flushChunk(head, boundary.done);
3140
+ const { done } = boundary;
3141
+ if (done || write2) {
3142
+ const html = (head = head.consume()).flushHTML();
3094
3143
  if (html) onWrite(html);
3095
- if (boundary.done) {
3144
+ if (done) {
3096
3145
  if (!tick2) offTick(onNext);
3097
3146
  onClose();
3098
3147
  } else {
@@ -3109,10 +3158,10 @@ var ServerRenderResult = class {
3109
3158
  }
3110
3159
  toString() {
3111
3160
  const head = this.#head;
3112
- if (!head) throw new Error("Cannot read from a consumed render result");
3113
- if (head.next) throw new Error("Cannot fork in sync mode");
3114
3161
  this.#head = null;
3115
- return flushChunk(prepareChunk(head), true);
3162
+ if (!head) throw new Error("Cannot read from a consumed render result");
3163
+ if (!head.boundary.done) throw new Error("Cannot fork in sync mode");
3164
+ return head.consume().flushHTML();
3116
3165
  }
3117
3166
  };
3118
3167
  function NOOP2() {
@@ -3133,19 +3182,17 @@ export {
3133
3182
  controllable_textarea_value,
3134
3183
  createContent,
3135
3184
  createTemplate,
3136
- dynamicTagArgs,
3137
- dynamicTagId,
3138
- dynamicTagInput,
3185
+ dynamicTag,
3139
3186
  ensureScopeWithId,
3140
3187
  escapeScript,
3141
3188
  escapeStyle,
3142
3189
  escapeXML,
3143
3190
  forIn,
3144
- forInBy,
3191
+ forInBy2 as forInBy,
3145
3192
  forOf,
3146
- forOfBy,
3193
+ forOfBy2 as forOfBy,
3147
3194
  forTo,
3148
- forToBy,
3195
+ forToBy2 as forToBy,
3149
3196
  fork,
3150
3197
  getScopeById,
3151
3198
  hoist,