marko 6.3.47 → 6.3.49

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.
Files changed (59) hide show
  1. package/cheatsheet.md +19 -16
  2. package/dist/common/accessor.d.ts +0 -3
  3. package/dist/common/accessor.debug.d.ts +0 -3
  4. package/dist/common/constants/resume-symbol.d.ts +1 -0
  5. package/dist/debug/dom/catch.feat.js +1 -1
  6. package/dist/debug/dom/catch.feat.mjs +1 -1
  7. package/dist/debug/dom/controllable-input.feat.js +1 -1
  8. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  9. package/dist/debug/dom/controllable-open.feat.js +1 -1
  10. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  11. package/dist/debug/dom/controllable-select.feat.js +1 -1
  12. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  13. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  14. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  15. package/dist/debug/dom/controllable.feat.js +1 -1
  16. package/dist/debug/dom/controllable.feat.mjs +1 -1
  17. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  18. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  19. package/dist/debug/dom/placeholder.feat.js +1 -1
  20. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  21. package/dist/debug/{dom-BheMBjYT.js → dom-BAGeiafn.js} +31 -17
  22. package/dist/debug/{dom-DyBeisho.mjs → dom-C55iHvof.mjs} +26 -18
  23. package/dist/debug/dom.js +20 -24
  24. package/dist/debug/dom.mjs +20 -24
  25. package/dist/debug/html.js +76 -37
  26. package/dist/debug/html.mjs +76 -37
  27. package/dist/dom/catch.feat.js +1 -1
  28. package/dist/dom/catch.feat.mjs +1 -1
  29. package/dist/dom/controllable-input.feat.js +1 -1
  30. package/dist/dom/controllable-input.feat.mjs +1 -1
  31. package/dist/dom/controllable-open.feat.js +1 -1
  32. package/dist/dom/controllable-open.feat.mjs +1 -1
  33. package/dist/dom/controllable-select.feat.js +1 -1
  34. package/dist/dom/controllable-select.feat.mjs +1 -1
  35. package/dist/dom/controllable-textarea.feat.js +1 -1
  36. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  37. package/dist/dom/controllable.feat.js +1 -1
  38. package/dist/dom/controllable.feat.mjs +1 -1
  39. package/dist/dom/dynamic-tag-var.feat.js +1 -1
  40. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  41. package/dist/dom/placeholder.feat.js +1 -1
  42. package/dist/dom/placeholder.feat.mjs +1 -1
  43. package/dist/{dom-DprILxYO.js → dom-BNmfm4st.js} +31 -26
  44. package/dist/{dom-BbknkVDz.mjs → dom-BsAS26Ze.mjs} +16 -16
  45. package/dist/dom.js +20 -20
  46. package/dist/dom.mjs +14 -14
  47. package/dist/html/inlined-runtimes.d.ts +2 -2
  48. package/dist/html/inlined-runtimes.debug.d.ts +2 -2
  49. package/dist/html/writer.d.ts +3 -1
  50. package/dist/html.js +46 -36
  51. package/dist/html.mjs +46 -36
  52. package/dist/translator/index.js +108 -82
  53. package/dist/translator/util/get-compile-stage.d.ts +2 -0
  54. package/dist/translator/util/references.d.ts +4 -2
  55. package/dist/translator/util/sections.d.ts +4 -1
  56. package/dist/translator/util/serialize-reasons.d.ts +3 -2
  57. package/package.json +4 -4
  58. package/dist/common/constants/load-signal-value.d.ts +0 -5
  59. package/dist/common/constants/load-signal-value.debug.d.ts +0 -5
package/dist/html.js CHANGED
@@ -246,7 +246,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
246
246
  return code >= 55296 && code <= 57343 ? "\\u" + code.toString(16).padStart(4, "0") : match;
247
247
  }, unsafeQuoteReg = /["\\<\n\r\u2028\u2029\0\ud800-\udfff]/u, $chunk, kPendingContexts = Symbol("Pending Contexts"), kBranchId = Symbol("Branch Id"), kIsAsync = Symbol("Is Async"), writeScope = (scopeId, partialScope) => {
248
248
  let { state } = $chunk.boundary, target = $chunk.serializeState, scope = scopeWithId(state, scopeId), pending = target.writeScopes[scopeId];
249
- return state.needsMainRuntime = !0, Object.assign(scope, partialScope), pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0, scope;
249
+ return state.needsMainRuntime = !0, countResumeWrite($chunk.boundary), Object.assign(scope, partialScope), pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0, scope;
250
250
  }, NOOP$2 = () => {}, tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb)), tickQueue, kSelectedValue = Symbol("selectedValue"), checkedValuesRefs = /* @__PURE__ */ new WeakMap(), singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g, doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g, needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g, voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, serializeReason) => {
251
251
  let shouldResume = serializeReason !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = _peek_scope_id(), rendered, result;
252
252
  if (typeof renderer == "string") {
@@ -1315,8 +1315,8 @@ function withContext(key, value, cb, cbValue) {
1315
1315
  function isInResumedBranch() {
1316
1316
  return $chunk?.context?.[kBranchId] !== void 0;
1317
1317
  }
1318
- function withBranchId(branchId, cb) {
1319
- return withContext(kBranchId, branchId, cb);
1318
+ function withBranchId(branchId, cb, cbValue) {
1319
+ return withContext(kBranchId, branchId, cb, cbValue);
1320
1320
  }
1321
1321
  function withIsAsync(cb, value) {
1322
1322
  return withContext(kIsAsync, !0, cb, value);
@@ -1327,8 +1327,8 @@ function _html(html) {
1327
1327
  function writeScript(script) {
1328
1328
  $chunk.writeScript(script);
1329
1329
  }
1330
- function _script(scopeId, registryId) {
1331
- ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1330
+ function _script(scopeId, registryId, serializeMarker) {
1331
+ serializeMarker === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1332
1332
  }
1333
1333
  function _trailers(html) {
1334
1334
  $chunk.boundary.state.trailerHTML += html;
@@ -1507,7 +1507,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1507
1507
  if (!isPromise(promise)) {
1508
1508
  if (resumeMarker) {
1509
1509
  let branchId = _peek_scope_id();
1510
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), content(promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1510
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, content, promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1511
1511
  } else content(promise);
1512
1512
  return;
1513
1513
  }
@@ -1519,7 +1519,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1519
1519
  chunk.async && (chunk.async = !1, boundary.signal.aborted || (chunk.render(() => {
1520
1520
  if (resumeMarker) {
1521
1521
  let branchId = _peek_scope_id();
1522
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withIsAsync(content, value), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1522
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync(content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1523
1523
  } else withIsAsync(content, value);
1524
1524
  }), boundary.endAsync()));
1525
1525
  }, (err) => {
@@ -1527,12 +1527,10 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1527
1527
  });
1528
1528
  }
1529
1529
  function _try(scopeId, accessor, content, input) {
1530
- let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder), placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id();
1531
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), catchContent === void 0 ? placeholderContent ? tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content() : tryCatch(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent || (() => {})), writeScope(branchId, {
1532
- C: accessor,
1533
- E: catchContent,
1534
- Q: placeholderContent
1535
- }), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1530
+ let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder), placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id(), chunk = $chunk, { boundary } = chunk, { state } = boundary, { resumeWrites } = boundary, beforeBranch = deferBranchStart(chunk), renderersAtSettle = !1;
1531
+ catchContent !== void 0 || placeholderContent ? renderersAtSettle = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, placeholderContent, branchId) : withBranchId(branchId, content);
1532
+ let rendered = chunk !== $chunk || boundary.resumeWrites !== resumeWrites;
1533
+ applyBranchStart(chunk, beforeBranch, rendered), rendered && (renderersAtSettle || writeTryRenderers(branchId, catchContent, placeholderContent), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
1536
1534
  }
1537
1535
  function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1538
1536
  let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
@@ -1548,19 +1546,19 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1548
1546
  placeholderBranchId
1549
1547
  };
1550
1548
  }
1551
- function tryCatch(content, catchContent) {
1552
- let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, boundary.signal, boundary), body = chunk.fork(catchBoundary, null), bodyEnd = body.render(content);
1553
- if (catchBoundary.signal.aborted) {
1554
- catchContent(catchBoundary.signal.reason);
1555
- return;
1556
- }
1557
- if (body === bodyEnd) {
1558
- chunk.append(body);
1559
- return;
1560
- }
1561
- let reorderId = state.nextReorderId(), endMarker = state.mark("!", reorderId), bodyNext = bodyEnd.next = $chunk = body.fork(boundary, chunk.next);
1562
- chunk.next = body, chunk.writeHTML(state.mark("!^", reorderId)), bodyEnd.writeHTML(endMarker), boundary.startAsync(), catchBoundary.onNext = () => {
1549
+ function tryBoundary(content, catchContent, placeholderContent, branchId) {
1550
+ let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, boundary.signal, boundary), body = chunk.fork(catchBoundary, null), bodyEnd = withBranchId(branchId, () => body.render(content));
1551
+ if (catchBoundary.signal.aborted) return catchContent === void 0 ? boundary.abort(catchBoundary.signal.reason) : catchContent && catchContent(catchBoundary.signal.reason), !1;
1552
+ if (body === bodyEnd) return chunk.append(body), !1;
1553
+ let renderersAtSettle = !catchBoundary.resumeWrites, bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1554
+ chunk.next = body, boundary.startAsync();
1555
+ let reorderId = catchContent === void 0 ? "" : state.nextReorderId(), endMarker = reorderId && state.mark("!", reorderId);
1556
+ return reorderId && (chunk.writeHTML(state.mark("!^", reorderId)), bodyEnd.writeHTML(endMarker)), catchBoundary.onNext = () => {
1563
1557
  if (!boundary.signal.aborted) if (catchBoundary.signal.aborted) {
1558
+ if (!reorderId) {
1559
+ boundary.abort(catchBoundary.signal.reason);
1560
+ return;
1561
+ }
1564
1562
  if (!bodyEnd.consumed) {
1565
1563
  let cur = body, writeMarker = !0;
1566
1564
  do {
@@ -1568,10 +1566,19 @@ function tryCatch(content, catchContent) {
1568
1566
  cur.boundary !== catchBoundary && cur.boundary.abort(catchBoundary.signal.reason), writeMarker && !cur.consumed && (writeMarker = !1, cur.async = !1, cur.next = bodyNext, cur.needsWalk = !0, cur.html = endMarker, cur.scripts = cur.effects = cur.lastEffect = "", cur.placeholder = cur.reorderId = cur.deferredReady = null), cur = next;
1569
1567
  } while (cur !== bodyNext);
1570
1568
  }
1571
- let catchChunk = chunk.fork(boundary, null);
1572
- catchChunk.reorderId = reorderId, catchChunk.render(catchContent, catchBoundary.signal.reason), state.reorder(catchChunk), boundary.endAsync();
1573
- } else catchBoundary.count ? boundary.onNext() : boundary.endAsync();
1574
- };
1569
+ let catchChunk = chunk.fork(boundary, null), { resumeWrites } = boundary;
1570
+ catchChunk.reorderId = reorderId, (catchChunk.render(catchContent || NOOP$2, catchBoundary.signal.reason) !== catchChunk || boundary.resumeWrites !== resumeWrites) && renderersAtSettle && catchChunk.render(() => writeTryRenderers(branchId, catchContent, placeholderContent)), state.reorder(catchChunk), boundary.endAsync();
1571
+ } else catchBoundary.count ? boundary.onNext() : (renderersAtSettle && catchBoundary.resumeWrites && bodyEnd.render(() => writeTryRenderers(branchId, catchContent, placeholderContent)), boundary.endAsync());
1572
+ }, renderersAtSettle;
1573
+ }
1574
+ function writeTryRenderers(branchId, catchContent, placeholderContent) {
1575
+ writeScope(branchId, {
1576
+ E: catchContent,
1577
+ Q: placeholderContent
1578
+ });
1579
+ }
1580
+ function countResumeWrite(boundary) {
1581
+ for (; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1575
1582
  }
1576
1583
  var State = class {
1577
1584
  tagId = 1;
@@ -1628,6 +1635,7 @@ var State = class {
1628
1635
  }, Boundary = class extends AbortController {
1629
1636
  onNext = NOOP$2;
1630
1637
  count = 0;
1638
+ resumeWrites = 0;
1631
1639
  state;
1632
1640
  parent;
1633
1641
  constructor(state, signal, parent) {
@@ -1671,7 +1679,7 @@ var State = class {
1671
1679
  this.html += html;
1672
1680
  }
1673
1681
  writeEffect(scopeId, registryId) {
1674
- this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1682
+ countResumeWrite(this.boundary), this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1675
1683
  }
1676
1684
  writeScript(script) {
1677
1685
  this.scripts = concatScripts(this.scripts, script);
@@ -1748,7 +1756,9 @@ var State = class {
1748
1756
  }
1749
1757
  readyResumeScripts && (needsWalk = !0);
1750
1758
  let effects = this.async ? "" : this.effects, { html, scripts } = this;
1751
- if (state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\""), state.writeReorders) {
1759
+ state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(r=l.slice(s+1),(l=l[s])>\"#\"||(a[r]=e),l),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\"");
1760
+ let reordered = "", needsResumeArray = !1;
1761
+ if (state.writeReorders) {
1752
1762
  let carried = null;
1753
1763
  for (let reorderedChunk of state.writeReorders) {
1754
1764
  if (reorderedChunk.async && reorderedChunk.consumed) {
@@ -1760,7 +1770,7 @@ var State = class {
1760
1770
  }
1761
1771
  reorderedChunk.async = !1;
1762
1772
  }
1763
- needsWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, scripts = concatScripts(scripts, "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"!\"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l[\"^\"+a],f=d.cloneNode()){if(--o.i)return 1;for(;f.prepend(r=e.l[a].previousSibling||i),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})(" + runtimePrefix + ")"));
1773
+ needsWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, scripts = concatScripts(scripts, "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"!\"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,r:a,c(i=e.l[\"^\"+a],f=d.cloneNode()){if(--o.i)return 1;for(;f.prepend(r=e.l[a].previousSibling||i),i!=r;);c(a,d)}}),e.v.push({data:e.i+\"*\"+l.r}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})(" + runtimePrefix + ")"));
1764
1774
  let { reorderId } = reorderedChunk, readyReservations = [], reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk;
1765
1775
  for (reorderedChunk.reorderId = null;;) {
1766
1776
  cur.flushPlaceholder(), cur.deferOwnReady();
@@ -1768,13 +1778,13 @@ var State = class {
1768
1778
  if (cur.consumed = !0, reorderHTML += cur.html, reorderEffects = concatEffects(reorderEffects, cur.effects), reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts)), cur.async && (reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId()), state.reorder(cur), cur.html = cur.effects = cur.scripts = cur.lastEffect = "", cur.next = null), next) cur = next;
1769
1779
  else break;
1770
1780
  }
1771
- reorderEffects && (state.hasWrittenResume || (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[]")), reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")"));
1772
- for (let reservation of readyReservations) scripts = concatScripts(scripts, reservation);
1773
- scripts = concatScripts(scripts, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}"), html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1781
+ reorderEffects && (needsResumeArray = !0, reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")"));
1782
+ for (let reservation of readyReservations) reordered = concatScripts(reordered, reservation);
1783
+ reordered = concatScripts(reordered, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}"), html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1774
1784
  }
1775
1785
  state.writeReorders = carried;
1776
1786
  }
1777
- return flushSerializer(boundary, state), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]"))), needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1787
+ return flushSerializer(boundary, state), state.resumes ? state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]")) : needsResumeArray && !state.hasWrittenResume && (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[]")), scripts = concatScripts(scripts, reordered), needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1778
1788
  }
1779
1789
  flushHTML() {
1780
1790
  let { boundary } = this, { state } = boundary;
package/dist/html.mjs CHANGED
@@ -246,7 +246,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
246
246
  return code >= 55296 && code <= 57343 ? "\\u" + code.toString(16).padStart(4, "0") : match;
247
247
  }, unsafeQuoteReg = /["\\<\n\r\u2028\u2029\0\ud800-\udfff]/u, $chunk, kPendingContexts = Symbol("Pending Contexts"), kBranchId = Symbol("Branch Id"), kIsAsync = Symbol("Is Async"), writeScope = (scopeId, partialScope) => {
248
248
  let { state } = $chunk.boundary, target = $chunk.serializeState, scope = scopeWithId(state, scopeId), pending = target.writeScopes[scopeId];
249
- return state.needsMainRuntime = !0, Object.assign(scope, partialScope), pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0, scope;
249
+ return state.needsMainRuntime = !0, countResumeWrite($chunk.boundary), Object.assign(scope, partialScope), pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0, scope;
250
250
  }, NOOP$2 = () => {}, tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb)), tickQueue, kSelectedValue = Symbol("selectedValue"), checkedValuesRefs = /* @__PURE__ */ new WeakMap(), singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g, doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g, needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g, voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, serializeReason) => {
251
251
  let shouldResume = serializeReason !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = _peek_scope_id(), rendered, result;
252
252
  if (typeof renderer == "string") {
@@ -1314,8 +1314,8 @@ function withContext(key, value, cb, cbValue) {
1314
1314
  function isInResumedBranch() {
1315
1315
  return $chunk?.context?.[kBranchId] !== void 0;
1316
1316
  }
1317
- function withBranchId(branchId, cb) {
1318
- return withContext(kBranchId, branchId, cb);
1317
+ function withBranchId(branchId, cb, cbValue) {
1318
+ return withContext(kBranchId, branchId, cb, cbValue);
1319
1319
  }
1320
1320
  function withIsAsync(cb, value) {
1321
1321
  return withContext(kIsAsync, !0, cb, value);
@@ -1326,8 +1326,8 @@ function _html(html) {
1326
1326
  function writeScript(script) {
1327
1327
  $chunk.writeScript(script);
1328
1328
  }
1329
- function _script(scopeId, registryId) {
1330
- ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1329
+ function _script(scopeId, registryId, serializeMarker) {
1330
+ serializeMarker === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1331
1331
  }
1332
1332
  function _trailers(html) {
1333
1333
  $chunk.boundary.state.trailerHTML += html;
@@ -1506,7 +1506,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1506
1506
  if (!isPromise(promise)) {
1507
1507
  if (resumeMarker) {
1508
1508
  let branchId = _peek_scope_id();
1509
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), content(promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1509
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, content, promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1510
1510
  } else content(promise);
1511
1511
  return;
1512
1512
  }
@@ -1518,7 +1518,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1518
1518
  chunk.async && (chunk.async = !1, boundary.signal.aborted || (chunk.render(() => {
1519
1519
  if (resumeMarker) {
1520
1520
  let branchId = _peek_scope_id();
1521
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withIsAsync(content, value), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1521
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync(content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1522
1522
  } else withIsAsync(content, value);
1523
1523
  }), boundary.endAsync()));
1524
1524
  }, (err) => {
@@ -1526,12 +1526,10 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1526
1526
  });
1527
1527
  }
1528
1528
  function _try(scopeId, accessor, content, input) {
1529
- let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder), placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id();
1530
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), catchContent === void 0 ? placeholderContent ? tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content() : tryCatch(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent || (() => {})), writeScope(branchId, {
1531
- C: accessor,
1532
- E: catchContent,
1533
- Q: placeholderContent
1534
- }), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1529
+ let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder), placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id(), chunk = $chunk, { boundary } = chunk, { state } = boundary, { resumeWrites } = boundary, beforeBranch = deferBranchStart(chunk), renderersAtSettle = !1;
1530
+ catchContent !== void 0 || placeholderContent ? renderersAtSettle = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, placeholderContent, branchId) : withBranchId(branchId, content);
1531
+ let rendered = chunk !== $chunk || boundary.resumeWrites !== resumeWrites;
1532
+ applyBranchStart(chunk, beforeBranch, rendered), rendered && (renderersAtSettle || writeTryRenderers(branchId, catchContent, placeholderContent), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
1535
1533
  }
1536
1534
  function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1537
1535
  let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
@@ -1547,19 +1545,19 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1547
1545
  placeholderBranchId
1548
1546
  };
1549
1547
  }
1550
- function tryCatch(content, catchContent) {
1551
- let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, boundary.signal, boundary), body = chunk.fork(catchBoundary, null), bodyEnd = body.render(content);
1552
- if (catchBoundary.signal.aborted) {
1553
- catchContent(catchBoundary.signal.reason);
1554
- return;
1555
- }
1556
- if (body === bodyEnd) {
1557
- chunk.append(body);
1558
- return;
1559
- }
1560
- let reorderId = state.nextReorderId(), endMarker = state.mark("!", reorderId), bodyNext = bodyEnd.next = $chunk = body.fork(boundary, chunk.next);
1561
- chunk.next = body, chunk.writeHTML(state.mark("!^", reorderId)), bodyEnd.writeHTML(endMarker), boundary.startAsync(), catchBoundary.onNext = () => {
1548
+ function tryBoundary(content, catchContent, placeholderContent, branchId) {
1549
+ let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, boundary.signal, boundary), body = chunk.fork(catchBoundary, null), bodyEnd = withBranchId(branchId, () => body.render(content));
1550
+ if (catchBoundary.signal.aborted) return catchContent === void 0 ? boundary.abort(catchBoundary.signal.reason) : catchContent && catchContent(catchBoundary.signal.reason), !1;
1551
+ if (body === bodyEnd) return chunk.append(body), !1;
1552
+ let renderersAtSettle = !catchBoundary.resumeWrites, bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1553
+ chunk.next = body, boundary.startAsync();
1554
+ let reorderId = catchContent === void 0 ? "" : state.nextReorderId(), endMarker = reorderId && state.mark("!", reorderId);
1555
+ return reorderId && (chunk.writeHTML(state.mark("!^", reorderId)), bodyEnd.writeHTML(endMarker)), catchBoundary.onNext = () => {
1562
1556
  if (!boundary.signal.aborted) if (catchBoundary.signal.aborted) {
1557
+ if (!reorderId) {
1558
+ boundary.abort(catchBoundary.signal.reason);
1559
+ return;
1560
+ }
1563
1561
  if (!bodyEnd.consumed) {
1564
1562
  let cur = body, writeMarker = !0;
1565
1563
  do {
@@ -1567,10 +1565,19 @@ function tryCatch(content, catchContent) {
1567
1565
  cur.boundary !== catchBoundary && cur.boundary.abort(catchBoundary.signal.reason), writeMarker && !cur.consumed && (writeMarker = !1, cur.async = !1, cur.next = bodyNext, cur.needsWalk = !0, cur.html = endMarker, cur.scripts = cur.effects = cur.lastEffect = "", cur.placeholder = cur.reorderId = cur.deferredReady = null), cur = next;
1568
1566
  } while (cur !== bodyNext);
1569
1567
  }
1570
- let catchChunk = chunk.fork(boundary, null);
1571
- catchChunk.reorderId = reorderId, catchChunk.render(catchContent, catchBoundary.signal.reason), state.reorder(catchChunk), boundary.endAsync();
1572
- } else catchBoundary.count ? boundary.onNext() : boundary.endAsync();
1573
- };
1568
+ let catchChunk = chunk.fork(boundary, null), { resumeWrites } = boundary;
1569
+ catchChunk.reorderId = reorderId, (catchChunk.render(catchContent || NOOP$2, catchBoundary.signal.reason) !== catchChunk || boundary.resumeWrites !== resumeWrites) && renderersAtSettle && catchChunk.render(() => writeTryRenderers(branchId, catchContent, placeholderContent)), state.reorder(catchChunk), boundary.endAsync();
1570
+ } else catchBoundary.count ? boundary.onNext() : (renderersAtSettle && catchBoundary.resumeWrites && bodyEnd.render(() => writeTryRenderers(branchId, catchContent, placeholderContent)), boundary.endAsync());
1571
+ }, renderersAtSettle;
1572
+ }
1573
+ function writeTryRenderers(branchId, catchContent, placeholderContent) {
1574
+ writeScope(branchId, {
1575
+ E: catchContent,
1576
+ Q: placeholderContent
1577
+ });
1578
+ }
1579
+ function countResumeWrite(boundary) {
1580
+ for (; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1574
1581
  }
1575
1582
  var State = class {
1576
1583
  tagId = 1;
@@ -1627,6 +1634,7 @@ var State = class {
1627
1634
  }, Boundary = class extends AbortController {
1628
1635
  onNext = NOOP$2;
1629
1636
  count = 0;
1637
+ resumeWrites = 0;
1630
1638
  state;
1631
1639
  parent;
1632
1640
  constructor(state, signal, parent) {
@@ -1670,7 +1678,7 @@ var State = class {
1670
1678
  this.html += html;
1671
1679
  }
1672
1680
  writeEffect(scopeId, registryId) {
1673
- this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1681
+ countResumeWrite(this.boundary), this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1674
1682
  }
1675
1683
  writeScript(script) {
1676
1684
  this.scripts = concatScripts(this.scripts, script);
@@ -1747,7 +1755,9 @@ var State = class {
1747
1755
  }
1748
1756
  readyResumeScripts && (needsWalk = !0);
1749
1757
  let effects = this.async ? "" : this.effects, { html, scripts } = this;
1750
- if (state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(a[r=l.slice(s+1)]=e,l[s]),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\""), state.writeReorders) {
1758
+ state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(r=l.slice(s+1),(l=l[s])>\"#\"||(a[r]=e),l),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\"");
1759
+ let reordered = "", needsResumeArray = !1;
1760
+ if (state.writeReorders) {
1751
1761
  let carried = null;
1752
1762
  for (let reorderedChunk of state.writeReorders) {
1753
1763
  if (reorderedChunk.async && reorderedChunk.consumed) {
@@ -1759,7 +1769,7 @@ var State = class {
1759
1769
  }
1760
1770
  reorderedChunk.async = !1;
1761
1771
  }
1762
- needsWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, scripts = concatScripts(scripts, "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"!\"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l[\"^\"+a],f=d.cloneNode()){if(--o.i)return 1;for(;f.prepend(r=e.l[a].previousSibling||i),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})(" + runtimePrefix + ")"));
1772
+ needsWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, scripts = concatScripts(scripts, "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"!\"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,r:a,c(i=e.l[\"^\"+a],f=d.cloneNode()){if(--o.i)return 1;for(;f.prepend(r=e.l[a].previousSibling||i),i!=r;);c(a,d)}}),e.v.push({data:e.i+\"*\"+l.r}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})(" + runtimePrefix + ")"));
1763
1773
  let { reorderId } = reorderedChunk, readyReservations = [], reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk;
1764
1774
  for (reorderedChunk.reorderId = null;;) {
1765
1775
  cur.flushPlaceholder(), cur.deferOwnReady();
@@ -1767,13 +1777,13 @@ var State = class {
1767
1777
  if (cur.consumed = !0, reorderHTML += cur.html, reorderEffects = concatEffects(reorderEffects, cur.effects), reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts)), cur.async && (reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId()), state.reorder(cur), cur.html = cur.effects = cur.scripts = cur.lastEffect = "", cur.next = null), next) cur = next;
1768
1778
  else break;
1769
1779
  }
1770
- reorderEffects && (state.hasWrittenResume || (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[]")), reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")"));
1771
- for (let reservation of readyReservations) scripts = concatScripts(scripts, reservation);
1772
- scripts = concatScripts(scripts, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}"), html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1780
+ reorderEffects && (needsResumeArray = !0, reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")"));
1781
+ for (let reservation of readyReservations) reordered = concatScripts(reordered, reservation);
1782
+ reordered = concatScripts(reordered, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}"), html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1773
1783
  }
1774
1784
  state.writeReorders = carried;
1775
1785
  }
1776
- return flushSerializer(boundary, state), state.resumes && (state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]"))), needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1786
+ return flushSerializer(boundary, state), state.resumes ? state.hasWrittenResume ? scripts = concatScripts(scripts, runtimePrefix + ".r.push(" + state.resumes + ")") : (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[" + state.resumes + "]")) : needsResumeArray && !state.hasWrittenResume && (state.hasWrittenResume = !0, scripts = concatScripts(scripts, runtimePrefix + ".r=[]")), scripts = concatScripts(scripts, reordered), needsWalk && (scripts = concatScripts(scripts, runtimePrefix + ".w()")), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1777
1787
  }
1778
1788
  flushHTML() {
1779
1789
  let { boundary } = this, { state } = boundary;