@marko/runtime-tags 6.3.14 → 6.3.15

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.
@@ -1666,7 +1666,6 @@ const REORDER_RUNTIME_CODE = `((runtime) => {
1666
1666
  //#endregion
1667
1667
  //#region src/html/writer.ts
1668
1668
  let $chunk;
1669
- const NOOP$2 = () => {};
1670
1669
  function getChunk() {
1671
1670
  return $chunk;
1672
1671
  }
@@ -1679,54 +1678,22 @@ function getState() {
1679
1678
  function getScopeId(scope) {
1680
1679
  return scope[K_SCOPE_ID];
1681
1680
  }
1682
- function _html(html) {
1683
- $chunk.writeHTML(html);
1684
- }
1685
- function writeScript(script) {
1686
- $chunk.writeScript(script);
1681
+ function getScopeById(scopeId) {
1682
+ if (scopeId !== void 0) return $chunk.boundary.state.scopes.get(scopeId);
1687
1683
  }
1688
- function writeWaitReady(readyId, renderer, input) {
1689
- const chunk = $chunk;
1690
- const { boundary } = chunk;
1691
- const body = new Chunk(boundary, null, chunk.context, {
1692
- readyId,
1693
- parent: chunk.serializeState,
1694
- resumes: "",
1695
- writeScopes: {},
1696
- flushScopes: false
1697
- });
1698
- const bodyEnd = body.render(renderer, input);
1699
- if (body === bodyEnd) {
1700
- chunk.writeHTML(body.html);
1701
- body.deferOwnReady();
1702
- chunk.deferredReady = push(chunk.deferredReady, body);
1703
- } else {
1704
- bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1705
- chunk.next = body;
1706
- }
1684
+ function $global() {
1685
+ return $chunk.boundary.state.$global;
1707
1686
  }
1708
- function _script(scopeId, registryId) {
1709
- if ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) _resume_branch(scopeId);
1710
- $chunk.boundary.state.needsMainRuntime = true;
1711
- $chunk.writeEffect(scopeId, registryId);
1687
+ function _id() {
1688
+ const state = $chunk.boundary.state;
1689
+ const { $global } = state;
1690
+ return "s" + $global.runtimeId + $global.renderId + (state.tagId++).toString(36);
1712
1691
  }
1713
- function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
1714
- const shouldResume = serializeReason !== 0;
1715
- const render = normalizeServerRender(content);
1716
- const branchId = _peek_scope_id();
1717
- if (render) if (shouldResume) withBranchId(branchId, render);
1718
- else render();
1719
- if (_peek_scope_id() !== branchId) {
1720
- if (shouldResume) writeScope(scopeId, {
1721
- ["BranchScopes:" + nodeAccessor]: writeScope(branchId, {}),
1722
- ["ConditionalRenderer:" + nodeAccessor]: render?.["id"]
1723
- });
1724
- } else _scope_id();
1692
+ function _scope_id() {
1693
+ return $chunk.boundary.state.scopeId++;
1725
1694
  }
1726
- function normalizeServerRender(value) {
1727
- const renderer = normalizeDynamicRenderer(value);
1728
- if (renderer) if (typeof renderer === "function") return renderer;
1729
- else throw new Error(`Invalid \`content\` attribute. Received ${typeof value}`);
1695
+ function _peek_scope_id() {
1696
+ return $chunk.boundary.state.scopeId;
1730
1697
  }
1731
1698
  const kPendingContexts = Symbol("Pending Contexts");
1732
1699
  function withContext(key, value, cb, cbValue) {
@@ -1741,49 +1708,41 @@ function withContext(key, value, cb, cbValue) {
1741
1708
  ctx[key] = prev;
1742
1709
  }
1743
1710
  }
1744
- function _var(parentScopeId, scopeOffsetAccessor, childScopeId, registryId, nodeAccessor) {
1745
- writeScopePassive(parentScopeId, { [scopeOffsetAccessor]: _scope_id() });
1746
- const childScope = writeScopePassive(childScopeId, { ["#TagVariable"]: _resume({}, registryId, parentScopeId) });
1747
- if (nodeAccessor !== void 0) writeScope(parentScopeId, { ["BranchScopes:" + nodeAccessor]: childScope });
1748
- }
1749
- function writeScopePassive(scopeId, partialScope) {
1750
- const target = $chunk.serializeState;
1751
- const scope = _scope_with_id(scopeId);
1752
- const passive = target.passiveScopes ||= {};
1753
- Object.assign(scope, partialScope);
1754
- passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
1755
- return scope;
1711
+ const kBranchId = Symbol("Branch Id");
1712
+ const kIsAsync = Symbol("Is Async");
1713
+ function isInResumedBranch() {
1714
+ return $chunk?.context?.[kBranchId] !== void 0;
1756
1715
  }
1757
- function _resume(val, id, scopeId) {
1758
- return register(id, val, scopeId === void 0 ? void 0 : _scope_with_id(scopeId));
1716
+ function withBranchId(branchId, cb) {
1717
+ return withContext(kBranchId, branchId, cb);
1759
1718
  }
1760
- function _id() {
1761
- const state = $chunk.boundary.state;
1762
- const { $global } = state;
1763
- return "s" + $global.runtimeId + $global.renderId + (state.tagId++).toString(36);
1719
+ function withIsAsync(cb, value) {
1720
+ return withContext(kIsAsync, true, cb, value);
1764
1721
  }
1765
- function _scope_id() {
1766
- return $chunk.boundary.state.scopeId++;
1722
+ function _html(html) {
1723
+ $chunk.writeHTML(html);
1767
1724
  }
1768
- function _peek_scope_id() {
1769
- return $chunk.boundary.state.scopeId;
1725
+ function writeScript(script) {
1726
+ $chunk.writeScript(script);
1770
1727
  }
1771
- function getScopeById(scopeId) {
1772
- if (scopeId !== void 0) return $chunk.boundary.state.scopes.get(scopeId);
1728
+ function _script(scopeId, registryId) {
1729
+ if ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) _resume_branch(scopeId);
1730
+ $chunk.boundary.state.needsMainRuntime = true;
1731
+ $chunk.writeEffect(scopeId, registryId);
1773
1732
  }
1774
- function _set_serialize_reason(reason) {
1775
- $chunk.boundary.state.serializeReason = reason;
1733
+ function _trailers(html) {
1734
+ $chunk.boundary.state.trailerHTML += html;
1776
1735
  }
1777
- function _scope_reason() {
1778
- const reason = $chunk.boundary.state.serializeReason;
1779
- $chunk.boundary.state.serializeReason = void 0;
1780
- return reason;
1736
+ function _resume(val, id, scopeId) {
1737
+ return register(id, val, scopeId === void 0 ? void 0 : _scope_with_id(scopeId));
1781
1738
  }
1782
- function _serialize_if(condition, key) {
1783
- return condition && (condition === 1 || (typeof condition === "number" ? condition >>> key + 1 & 1 : condition[key])) ? 1 : void 0;
1739
+ function _el(scopeId, id) {
1740
+ return _resume(() => _el_read_error(), id, scopeId);
1784
1741
  }
1785
- function _serialize_guard(condition, key) {
1786
- return _serialize_if(condition, key) || 0;
1742
+ function _hoist(scopeId, id) {
1743
+ const getter = () => _hoist_read_error();
1744
+ getter[Symbol.iterator] = _hoist_read_error;
1745
+ return _resume(getter, id, scopeId);
1787
1746
  }
1788
1747
  function _el_resume(scopeId, accessor, shouldResume) {
1789
1748
  if (shouldResume === 0) return "";
@@ -1794,28 +1753,51 @@ function _el_resume(scopeId, accessor, shouldResume) {
1794
1753
  function _sep(shouldResume) {
1795
1754
  return shouldResume === 0 ? "" : "<!>";
1796
1755
  }
1797
- function _el(scopeId, id) {
1798
- return _resume(() => _el_read_error(), id, scopeId);
1799
- }
1800
- function _hoist(scopeId, id) {
1801
- const getter = () => _hoist_read_error();
1802
- getter[Symbol.iterator] = _hoist_read_error;
1803
- return _resume(getter, id, scopeId);
1804
- }
1805
1756
  function _resume_branch(scopeId) {
1806
1757
  const branchId = $chunk.context?.[kBranchId];
1807
1758
  if (branchId !== void 0 && branchId !== scopeId) writeScope(scopeId, { ["#ClosestBranchId"]: branchId });
1808
1759
  }
1809
- const kBranchId = Symbol("Branch Id");
1810
- const kIsAsync = Symbol("Is Async");
1811
- function isInResumedBranch() {
1812
- return $chunk?.context?.[kBranchId] !== void 0;
1760
+ function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
1761
+ const shouldResume = serializeReason !== 0;
1762
+ const render = normalizeServerRender(content);
1763
+ const branchId = _peek_scope_id();
1764
+ if (render) if (shouldResume) withBranchId(branchId, render);
1765
+ else render();
1766
+ if (_peek_scope_id() !== branchId) {
1767
+ if (shouldResume) writeScope(scopeId, {
1768
+ ["BranchScopes:" + nodeAccessor]: writeScope(branchId, {}),
1769
+ ["ConditionalRenderer:" + nodeAccessor]: render?.["id"]
1770
+ });
1771
+ } else _scope_id();
1813
1772
  }
1814
- function withBranchId(branchId, cb) {
1815
- return withContext(kBranchId, branchId, cb);
1773
+ function normalizeServerRender(value) {
1774
+ const renderer = normalizeDynamicRenderer(value);
1775
+ if (renderer) if (typeof renderer === "function") return renderer;
1776
+ else throw new Error(`Invalid \`content\` attribute. Received ${typeof value}`);
1816
1777
  }
1817
- function withIsAsync(cb, value) {
1818
- return withContext(kIsAsync, true, cb, value);
1778
+ function _var(parentScopeId, scopeOffsetAccessor, childScopeId, registryId, nodeAccessor) {
1779
+ writeScopePassive(parentScopeId, { [scopeOffsetAccessor]: _scope_id() });
1780
+ const childScope = writeScopePassive(childScopeId, { ["#TagVariable"]: _resume({}, registryId, parentScopeId) });
1781
+ if (nodeAccessor !== void 0) writeScope(parentScopeId, { ["BranchScopes:" + nodeAccessor]: childScope });
1782
+ }
1783
+ function writeScopePassive(scopeId, partialScope) {
1784
+ const target = $chunk.serializeState;
1785
+ const scope = _scope_with_id(scopeId);
1786
+ const passive = target.passiveScopes ||= {};
1787
+ Object.assign(scope, partialScope);
1788
+ passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
1789
+ return scope;
1790
+ }
1791
+ function _show_start(display, mark) {
1792
+ if (display) {
1793
+ if (mark) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
1794
+ } else $chunk.writeHTML("<t hidden>");
1795
+ }
1796
+ function _show_end(scopeId, accessor, display, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1797
+ const branchId = _scope_id();
1798
+ const wrap = !display;
1799
+ if (wrap) $chunk.writeHTML("</t>");
1800
+ writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1819
1801
  }
1820
1802
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1821
1803
  forBranches(by, (each) => each ? forOf(list, (item, index) => {
@@ -1902,17 +1884,6 @@ function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, p
1902
1884
  } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1903
1885
  else $chunk.writeHTML(endTag);
1904
1886
  }
1905
- function _show_start(display, mark) {
1906
- if (display) {
1907
- if (mark) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
1908
- } else $chunk.writeHTML("<t hidden>");
1909
- }
1910
- function _show_end(scopeId, accessor, display, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1911
- const branchId = _scope_id();
1912
- const wrap = !display;
1913
- if (wrap) $chunk.writeHTML("</t>");
1914
- writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1915
- }
1916
1887
  let writeScope = (scopeId, partialScope) => {
1917
1888
  const { state } = $chunk.boundary;
1918
1889
  const target = $chunk.serializeState;
@@ -1942,8 +1913,47 @@ function scopeWithId(state, scopeId) {
1942
1913
  if (!scope) scopes.set(scopeId, scope = { [K_SCOPE_ID]: scopeId });
1943
1914
  return scope;
1944
1915
  }
1945
- function $global() {
1946
- return $chunk.boundary.state.$global;
1916
+ function _subscribe(subscribers, scope) {
1917
+ if (subscribers) {
1918
+ const { serializer } = $chunk.boundary.state;
1919
+ if (!$chunk.serializeState.readyId && !serializer.written(subscribers)) subscribers.add(scope);
1920
+ else serializer.writeCall(scope, subscribers, "add", $chunk.serializeState);
1921
+ }
1922
+ return scope;
1923
+ }
1924
+ function _set_serialize_reason(reason) {
1925
+ $chunk.boundary.state.serializeReason = reason;
1926
+ }
1927
+ function _scope_reason() {
1928
+ const reason = $chunk.boundary.state.serializeReason;
1929
+ $chunk.boundary.state.serializeReason = void 0;
1930
+ return reason;
1931
+ }
1932
+ function _serialize_if(condition, key) {
1933
+ return condition && (condition === 1 || (typeof condition === "number" ? condition >>> key + 1 & 1 : condition[key])) ? 1 : void 0;
1934
+ }
1935
+ function _serialize_guard(condition, key) {
1936
+ return _serialize_if(condition, key) || 0;
1937
+ }
1938
+ function writeWaitReady(readyId, renderer, input) {
1939
+ const chunk = $chunk;
1940
+ const { boundary } = chunk;
1941
+ const body = new Chunk(boundary, null, chunk.context, {
1942
+ readyId,
1943
+ parent: chunk.serializeState,
1944
+ resumes: "",
1945
+ writeScopes: {},
1946
+ flushScopes: false
1947
+ });
1948
+ const bodyEnd = body.render(renderer, input);
1949
+ if (body === bodyEnd) {
1950
+ chunk.writeHTML(body.html);
1951
+ body.deferOwnReady();
1952
+ chunk.deferredReady = push(chunk.deferredReady, body);
1953
+ } else {
1954
+ bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1955
+ chunk.next = body;
1956
+ }
1947
1957
  }
1948
1958
  function _await(scopeId, accessor, promise, content, serializeMarker) {
1949
1959
  const resumeMarker = serializeMarker !== 0;
@@ -2067,6 +2077,7 @@ function tryCatch(content, catchContent) {
2067
2077
  else boundary.onNext();
2068
2078
  };
2069
2079
  }
2080
+ const NOOP$2 = () => {};
2070
2081
  var State = class {
2071
2082
  $global;
2072
2083
  tagId = 1;
@@ -2492,8 +2503,22 @@ function depsMarker(deps) {
2492
2503
  }
2493
2504
  return marker;
2494
2505
  }
2495
- function _trailers(html) {
2496
- $chunk.boundary.state.trailerHTML += html;
2506
+ function getFilteredGlobals($global) {
2507
+ if (!$global) return 0;
2508
+ const serializedGlobals = $global.serializedGlobals;
2509
+ if (!serializedGlobals) return 0;
2510
+ let filtered = 0;
2511
+ if (Array.isArray(serializedGlobals)) for (const key of serializedGlobals) {
2512
+ const value = $global[key];
2513
+ if (value !== void 0) if (filtered) filtered[key] = value;
2514
+ else filtered = { [key]: value };
2515
+ }
2516
+ else for (const key in serializedGlobals) if (serializedGlobals[key]) {
2517
+ const value = $global[key];
2518
+ if (value !== void 0) if (filtered) filtered[key] = value;
2519
+ else filtered = { [key]: value };
2520
+ }
2521
+ return filtered;
2497
2522
  }
2498
2523
  function concatEffects(a, b) {
2499
2524
  return a ? b ? a + " " + b : a : b;
@@ -2521,31 +2546,6 @@ function flushTickQueue() {
2521
2546
  tickQueue = void 0;
2522
2547
  for (const cb of queue) cb(true);
2523
2548
  }
2524
- function getFilteredGlobals($global) {
2525
- if (!$global) return 0;
2526
- const serializedGlobals = $global.serializedGlobals;
2527
- if (!serializedGlobals) return 0;
2528
- let filtered = 0;
2529
- if (Array.isArray(serializedGlobals)) for (const key of serializedGlobals) {
2530
- const value = $global[key];
2531
- if (value !== void 0) if (filtered) filtered[key] = value;
2532
- else filtered = { [key]: value };
2533
- }
2534
- else for (const key in serializedGlobals) if (serializedGlobals[key]) {
2535
- const value = $global[key];
2536
- if (value !== void 0) if (filtered) filtered[key] = value;
2537
- else filtered = { [key]: value };
2538
- }
2539
- return filtered;
2540
- }
2541
- function _subscribe(subscribers, scope) {
2542
- if (subscribers) {
2543
- const { serializer } = $chunk.boundary.state;
2544
- if (!$chunk.serializeState.readyId && !serializer.written(subscribers)) subscribers.add(scope);
2545
- else serializer.writeCall(scope, subscribers, "add", $chunk.serializeState);
2546
- }
2547
- return scope;
2548
- }
2549
2549
  //#endregion
2550
2550
  //#region src/html/attrs.ts
2551
2551
  function _attr_class(value) {
@@ -2770,27 +2770,30 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
2770
2770
  assertValidTagName(renderer);
2771
2771
  const input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
2772
2772
  rendered = true;
2773
- _scope_id();
2774
- _html(`<${renderer}${_attrs(input, `#${renderer}/0`, branchId, renderer)}>`);
2775
- if (!voidElementsReg.test(renderer)) {
2776
- const renderContent = content || normalizeDynamicRenderer(input.content);
2777
- if (renderer === "textarea") {
2778
- if (renderContent) throw new Error("A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead.");
2779
- _html(_attr_textarea_value(branchId, `#${renderer}/0`, input.value, input.valueChange, 1));
2780
- } else if (renderContent) {
2781
- if (typeof renderContent !== "function") throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
2782
- if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer}/0`, input.value, input.valueChange, renderContent, 1);
2783
- else _dynamic_tag(branchId, `#${renderer}/0`, renderContent, void 0, 0, void 0, serializeReason);
2773
+ const renderNative = () => {
2774
+ _scope_id();
2775
+ _html(`<${renderer}${_attrs(input, `#${renderer}/0`, branchId, renderer)}>`);
2776
+ if (!voidElementsReg.test(renderer)) {
2777
+ const renderContent = content || normalizeDynamicRenderer(input.content);
2778
+ if (renderer === "textarea") {
2779
+ if (renderContent) throw new Error("A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead.");
2780
+ _html(_attr_textarea_value(branchId, `#${renderer}/0`, input.value, input.valueChange, 1));
2781
+ } else if (renderContent) {
2782
+ if (typeof renderContent !== "function") throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
2783
+ if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer}/0`, input.value, input.valueChange, renderContent, 1);
2784
+ else _dynamic_tag(branchId, `#${renderer}/0`, renderContent, void 0, 0, void 0, serializeReason);
2785
+ }
2786
+ _html(`</${renderer}>`);
2787
+ } else if (content) throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
2788
+ const childScope = getScopeById(branchId);
2789
+ const needsScript = childScope && (childScope[`EventAttributes:#${renderer}/0`] || childScope[`ControlledHandler:#${renderer}/0`]);
2790
+ if (needsScript) {
2791
+ writeScope(branchId, { ["#Renderer"]: renderer });
2792
+ _script(branchId, DYNAMIC_TAG_SCRIPT_REGISTER_ID);
2784
2793
  }
2785
- _html(`</${renderer}>`);
2786
- } else if (content) throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
2787
- const childScope = getScopeById(branchId);
2788
- const needsScript = childScope && (childScope[`EventAttributes:#${renderer}/0`] || childScope[`ControlledHandler:#${renderer}/0`]);
2789
- if (needsScript) {
2790
- writeScope(branchId, { ["#Renderer"]: renderer });
2791
- _script(branchId, DYNAMIC_TAG_SCRIPT_REGISTER_ID);
2792
- }
2793
- if (shouldResume || needsScript) _html(state.mark("'", scopeId + " " + accessor + " " + branchId));
2794
+ if (shouldResume || needsScript) _html(state.mark("'", scopeId + " " + accessor + " " + branchId));
2795
+ };
2796
+ renderNative();
2794
2797
  } else {
2795
2798
  if (shouldResume) _html(state.mark("[", ""));
2796
2799
  const render = () => {
@@ -3000,9 +3003,11 @@ var ServerRendered = class {
3000
3003
  boundary.onNext = NOOP$1;
3001
3004
  reject(boundary.signal.reason);
3002
3005
  break;
3003
- case 0:
3004
- resolve(head.consume().flushHTML());
3006
+ case 0: {
3007
+ const consumed = head.consume();
3008
+ if (!boundary.signal.aborted) resolve(consumed.flushHTML());
3005
3009
  break;
3010
+ }
3006
3011
  }
3007
3012
  })();
3008
3013
  });