marko 6.4.5 → 6.4.6

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 (133) hide show
  1. package/dist/common/errors.d.ts +2 -1
  2. package/dist/common/helpers.d.ts +7 -7
  3. package/dist/debug/dom/catch.feat.js +3 -3
  4. package/dist/debug/dom/catch.feat.mjs +3 -3
  5. package/dist/debug/dom/controllable-input.feat.js +1 -1
  6. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  7. package/dist/debug/dom/controllable-open.feat.js +1 -1
  8. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  9. package/dist/debug/dom/controllable-select.feat.js +1 -1
  10. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  11. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  12. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  13. package/dist/debug/dom/controllable.feat.js +5 -5
  14. package/dist/debug/dom/controllable.feat.mjs +5 -5
  15. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  16. package/dist/debug/dom/dynamic-tag-script.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/lazy.feat.js +1 -1
  20. package/dist/debug/dom/lazy.feat.mjs +1 -1
  21. package/dist/debug/dom/placeholder.feat.js +1 -1
  22. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  23. package/dist/debug/{dom-CUxvM4i9.js → dom-CNgQ6lj9.js} +52 -52
  24. package/dist/debug/{dom-BeY1nGUb.mjs → dom-o9jQjchF.mjs} +43 -43
  25. package/dist/debug/dom.js +4 -4
  26. package/dist/debug/dom.mjs +4 -4
  27. package/dist/debug/html.js +721 -652
  28. package/dist/debug/html.mjs +721 -652
  29. package/dist/dom/catch.feat.js +4 -4
  30. package/dist/dom/catch.feat.mjs +3 -3
  31. package/dist/dom/control-flow.d.ts +2 -2
  32. package/dist/dom/controllable-input.feat.js +2 -2
  33. package/dist/dom/controllable-input.feat.mjs +1 -1
  34. package/dist/dom/controllable-open.feat.js +2 -2
  35. package/dist/dom/controllable-open.feat.mjs +1 -1
  36. package/dist/dom/controllable-select.feat.js +2 -2
  37. package/dist/dom/controllable-select.feat.mjs +1 -1
  38. package/dist/dom/controllable-textarea.feat.js +2 -2
  39. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  40. package/dist/dom/controllable.d.ts +4 -4
  41. package/dist/dom/controllable.feat.js +2 -2
  42. package/dist/dom/controllable.feat.mjs +2 -2
  43. package/dist/dom/dom.d.ts +5 -5
  44. package/dist/dom/dynamic-tag-script.feat.js +2 -2
  45. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  46. package/dist/dom/dynamic-tag-var.feat.js +2 -2
  47. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  48. package/dist/dom/lazy.feat.js +1 -1
  49. package/dist/dom/lazy.feat.mjs +1 -1
  50. package/dist/dom/placeholder.feat.js +1 -1
  51. package/dist/dom/placeholder.feat.mjs +1 -1
  52. package/dist/dom/signals.d.ts +4 -1
  53. package/dist/{dom-Diu8MpmL.js → dom-60R4bRWD.js} +40 -40
  54. package/dist/{dom-DefWmvQB.mjs → dom-Ci2W4l1P.mjs} +33 -33
  55. package/dist/dom.js +6 -6
  56. package/dist/dom.mjs +4 -4
  57. package/dist/html/assets.d.ts +1 -1
  58. package/dist/html/compat.d.ts +2 -1
  59. package/dist/html/control-flow.d.ts +20 -0
  60. package/dist/html/serializer.d.ts +63 -16
  61. package/dist/html/writer.d.ts +47 -35
  62. package/dist/html.d.ts +2 -1
  63. package/dist/html.js +517 -467
  64. package/dist/html.mjs +517 -467
  65. package/dist/translator/core/for.d.ts +0 -4
  66. package/dist/translator/core/return.d.ts +0 -3
  67. package/dist/translator/core/style.d.ts +2 -2
  68. package/dist/translator/index.js +7934 -7978
  69. package/dist/translator/util/analyze-errors.d.ts +2 -1
  70. package/dist/translator/util/assert.d.ts +8 -1
  71. package/dist/translator/util/bindings.d.ts +13 -9
  72. package/dist/translator/util/body-to-text.d.ts +9 -0
  73. package/dist/translator/util/branch-tag.d.ts +10 -3
  74. package/dist/translator/util/build-string-expression.d.ts +4 -0
  75. package/dist/translator/util/content-derives.d.ts +7 -0
  76. package/dist/translator/util/entry-builder.d.ts +6 -2
  77. package/dist/translator/util/finalize-references.d.ts +3 -2
  78. package/dist/translator/util/generate-uid.d.ts +3 -2
  79. package/dist/translator/util/get-root.d.ts +3 -3
  80. package/dist/translator/util/get-tag-name.d.ts +1 -1
  81. package/dist/translator/util/known-tag.d.ts +10 -8
  82. package/dist/translator/util/module-read.d.ts +0 -3
  83. package/dist/translator/util/module-registrations.d.ts +44 -0
  84. package/dist/translator/util/nested-attribute-tags.d.ts +1 -1
  85. package/dist/translator/util/optional.d.ts +6 -1
  86. package/dist/translator/util/params-tree.d.ts +18 -0
  87. package/dist/translator/util/reasons.d.ts +10 -8
  88. package/dist/translator/util/references.d.ts +21 -27
  89. package/dist/translator/util/runtime.d.ts +0 -12
  90. package/dist/translator/util/scope-accessor.d.ts +0 -1
  91. package/dist/translator/util/scope-read.d.ts +3 -0
  92. package/dist/translator/util/section-renderer.d.ts +4 -0
  93. package/dist/translator/util/sections.d.ts +16 -16
  94. package/dist/translator/util/setup-work.d.ts +2 -1
  95. package/dist/translator/util/signals.d.ts +14 -12
  96. package/dist/translator/util/simplify-fn.d.ts +1 -0
  97. package/dist/translator/util/slots.d.ts +2 -2
  98. package/dist/translator/util/solve-reasons.d.ts +1 -3
  99. package/dist/translator/util/sources.d.ts +2 -1
  100. package/dist/translator/util/statement-tag.d.ts +2 -0
  101. package/dist/translator/util/static-text.d.ts +2 -1
  102. package/dist/translator/util/structure.d.ts +0 -10
  103. package/dist/translator/util/tag-facts.d.ts +8 -1
  104. package/dist/translator/util/tag-import.d.ts +20 -0
  105. package/dist/translator/util/tag-name-type.d.ts +9 -2
  106. package/dist/translator/util/to-only-or-block.d.ts +3 -0
  107. package/dist/translator/util/to-property-name.d.ts +2 -0
  108. package/dist/translator/util/translate-attrs.d.ts +7 -5
  109. package/dist/translator/util/translate-var.d.ts +2 -0
  110. package/dist/translator/util/traverse.d.ts +1 -2
  111. package/dist/translator/util/visitors.d.ts +4 -1
  112. package/dist/translator/util/with-previous-location.d.ts +1 -1
  113. package/dist/translator/util/write-guard.d.ts +2 -2
  114. package/dist/translator/util/writer.d.ts +1 -2
  115. package/dist/translator/visitors/export-declaration.d.ts +2 -3
  116. package/dist/translator/visitors/function.d.ts +0 -35
  117. package/dist/translator/visitors/import-declaration.d.ts +0 -16
  118. package/dist/translator/visitors/placeholder.d.ts +2 -1
  119. package/dist/translator/visitors/program/html.d.ts +0 -1
  120. package/dist/translator/visitors/program/index.d.ts +4 -5
  121. package/dist/translator/visitors/tag/custom-tag.d.ts +0 -14
  122. package/dist/translator/visitors/tag/native-tag.d.ts +3 -12
  123. package/package.json +3 -3
  124. package/dist/translator/util/binding-has-prop.d.ts +0 -8
  125. package/dist/translator/util/binding-prop-tree.d.ts +0 -18
  126. package/dist/translator/util/body-to-text-literal.d.ts +0 -9
  127. package/dist/translator/util/import-reference.d.ts +0 -3
  128. package/dist/translator/util/normalize-string-expression.d.ts +0 -4
  129. package/dist/translator/util/plugin-hooks.d.ts +0 -4
  130. package/dist/translator/util/resolve-relative-to-entry.d.ts +0 -2
  131. package/dist/translator/util/set-tag-derived-from.d.ts +0 -7
  132. package/dist/translator/util/to-first-expression-or-block.d.ts +0 -2
  133. package/dist/translator/util/to-first-statement-or-block.d.ts +0 -2
@@ -40,7 +40,7 @@ const Embed = "embed";
40
40
  const Lazy = "lazy";
41
41
  //#endregion
42
42
  //#region src/common/helpers.ts
43
- const htmlAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
43
+ const invalidNativeAttrNameReg = /^[^a-z_]|[^a-z0-9._:-]/i;
44
44
  const knownWrongAttrs = {
45
45
  className: "class",
46
46
  classList: "class",
@@ -78,11 +78,11 @@ function getWrongAttrSuggestion(name) {
78
78
  }
79
79
  }
80
80
  }
81
- function stringifyClassObject(name, value) {
81
+ function stringifyClassEntry(name, value) {
82
82
  return value ? name : "";
83
83
  }
84
84
  const warnedStyleKeys = /* @__PURE__ */ new Set();
85
- function stringifyStyleObject(name, value) {
85
+ function stringifyStyleEntry(name, value) {
86
86
  if (/[A-Z]/.test(name) && !name.includes("-") && !warnedStyleKeys.has(name)) {
87
87
  warnedStyleKeys.add(name);
88
88
  console.warn(`\`${name}\` is not a CSS property name; \`style\` object keys are written verbatim, so it renders as invalid CSS. Use \`${name.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()).replace(/^ms-/, "-ms-")}\`.`);
@@ -129,17 +129,17 @@ const toDelimitedString = function toDelimitedString(val, delimiter, stringify)
129
129
  function isEventHandler(name) {
130
130
  return /^on[A-Z-]/.test(name);
131
131
  }
132
- function getEventHandlerName(name) {
132
+ function getEventType(name) {
133
133
  return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
134
134
  }
135
135
  function hasKeys(obj) {
136
136
  for (const _ in obj) return true;
137
137
  return false;
138
138
  }
139
- function isVoid(value) {
139
+ function isNullishOrFalse(value) {
140
140
  return value == null || value === false;
141
141
  }
142
- function isNotVoid(value) {
142
+ function isNotNullishOrFalse(value) {
143
143
  return value != null && value !== false;
144
144
  }
145
145
  function isPromise(value) {
@@ -158,9 +158,9 @@ function normalizeDynamicRenderer(value) {
158
158
  }
159
159
  //#endregion
160
160
  //#region src/common/errors.ts
161
- const lowercaseEventHandlerReg = /^on[a-z]/;
161
+ const lowercaseOnAttrReg = /^on[a-z]/;
162
162
  function assertValidAttrValue(name, value) {
163
- if (value && typeof value !== "string" && lowercaseEventHandlerReg.test(name)) throw new Error(`The \`${name}\` attribute must be a string or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}". To attach an event listener, use the \`on${name[2].toUpperCase()}${name.slice(3)}\` event handler instead.`);
163
+ if (value && typeof value !== "string" && lowercaseOnAttrReg.test(name)) throw new Error(`The \`${name}\` attribute must be a string or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}". To attach an event listener, use the \`on${name[2].toUpperCase()}${name.slice(3)}\` event handler instead.`);
164
164
  if (typeof value === "function") throw new Error(`The \`${name}\` attribute cannot be a function.${/Change$/.test(name) ? " A change handler is only used when its matching controllable attribute combination applies." : ""}`);
165
165
  const unrenderable = describeUnrenderable(value);
166
166
  if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
@@ -199,7 +199,7 @@ function describeUnrenderable(value) {
199
199
  }
200
200
  }
201
201
  function assertValidLoopKey(key, seenKeys) {
202
- if (typeof key !== "string" && typeof key !== "number") throw new Error(`A \`<for>\` tag's \`by\` attribute must return a string or number for each item, but received ${key === null ? "null" : `type "${typeof key}"`}.`);
202
+ if (typeof key !== "string" && typeof key !== "number" || key !== key) throw new Error(`A \`<for>\` tag's \`by\` attribute must return a string or number for each item, but received ${key === null || key !== key ? key : `type "${typeof key}"`}.`);
203
203
  if (seenKeys) {
204
204
  if (seenKeys.has(key)) throw new Error(`A \`<for>\` tag's \`by\` attribute must return a unique value for each item, but \`${key}\` was used more than once.`);
205
205
  seenKeys.add(key);
@@ -208,7 +208,7 @@ function assertValidLoopKey(key, seenKeys) {
208
208
  function assertValidList(value) {
209
209
  if (value && typeof value[Symbol.iterator] !== "function") throw new Error(`A \`<for>\` tag's \`of\` attribute must be an iterable, such as an array, but received ${describeForValue(value)}.`);
210
210
  }
211
- function assertValidRangeStart(name, value) {
211
+ function assertOptionalRangeNumber(name, value) {
212
212
  if (value && (typeof value !== "number" || !isFinite(value))) throw new Error(`A \`<for>\` tag's \`${name}\` attribute must be a finite number, but received ${describeForValue(value)}.`);
213
213
  }
214
214
  function assertValidRangeBound(name, value) {
@@ -218,7 +218,7 @@ function describeForValue(value) {
218
218
  return typeof value === "number" || typeof value === "bigint" ? `\`${value}\`` : value === null ? "null" : `type "${typeof value}"`;
219
219
  }
220
220
  function assertValidAttrName(name) {
221
- if (htmlAttrNameReg.test(name)) throw new Error(`Invalid attribute name: ${JSON.stringify(name)}`);
221
+ if (invalidNativeAttrNameReg.test(name)) throw new Error(`Invalid attribute name: ${JSON.stringify(name)}`);
222
222
  const suggestion = getWrongAttrSuggestion(name);
223
223
  if (suggestion) throw new Error(`\`${name}\` is not a valid attribute, did you mean \`${suggestion}\`?`);
224
224
  }
@@ -278,34 +278,6 @@ const DYNAMIC_TAG_SCRIPT_REGISTER_ID = "_dynamicTagScript";
278
278
  const DYNAMIC_TAG_VAR_REGISTER_ID = "_dynamicTagVar";
279
279
  const PLACEHOLDER_DISMISS_REGISTER_ID = "_placeholderDismiss";
280
280
  //#endregion
281
- //#region src/common/for.ts
282
- function forIn(obj, cb) {
283
- for (const key in obj) cb(key, obj[key]);
284
- }
285
- function forOf(list, cb) {
286
- assertValidList(list);
287
- if (list) {
288
- let i = 0;
289
- for (const item of list) cb(item, i++);
290
- }
291
- }
292
- function forTo(to, from, step, cb) {
293
- assertValidRangeBound("to", to);
294
- assertValidRangeStart("from", from);
295
- assertValidRangeStart("step", step);
296
- const start = from || 0;
297
- const delta = step || 1;
298
- for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
299
- }
300
- function forUntil(until, from, step, cb) {
301
- assertValidRangeBound("until", until);
302
- assertValidRangeStart("from", from);
303
- assertValidRangeStart("step", step);
304
- const start = from || 0;
305
- const delta = step || 1;
306
- for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
307
- }
308
- //#endregion
309
281
  //#region src/common/opt.ts
310
282
  function reduce(opt, cb, acc) {
311
283
  if (opt) {
@@ -581,15 +553,57 @@ var State$1 = class {
581
553
  buf = [];
582
554
  strs = /* @__PURE__ */ new Map();
583
555
  refs = /* @__PURE__ */ new WeakMap();
584
- pendingAssignments = /* @__PURE__ */ new Set();
556
+ deferredRefs = /* @__PURE__ */ new Set();
585
557
  boundary;
586
558
  channel = void 0;
587
559
  channelDeps = null;
588
- mutated = [];
560
+ queuedCalls = [];
561
+ queuedReadyCalls = [];
562
+ scopeRef(scope, scopeId) {
563
+ return this.refs.get(scope) || newScopeReference(this, scope, scopeId);
564
+ }
565
+ writeScopeProps(props, ref) {
566
+ return writeObjectProps(this, props, ref);
567
+ }
568
+ scopesCursor(scopeId) {
569
+ return scopeId + ",";
570
+ }
571
+ writeTrailing(scopesIndex) {
572
+ const { buf } = this;
573
+ if (~scopesIndex) {
574
+ buf[scopesIndex] = "_([" + buf[scopesIndex];
575
+ buf.push("])");
576
+ }
577
+ writeDeferred(this);
578
+ return ",0)";
579
+ }
580
+ wrapPayload(result, extras) {
581
+ const arrow = this.wroteUndefined ? "(_,$)=>" : "_=>";
582
+ this.wroteUndefined = false;
583
+ return extras ? arrow + result : arrow + "[" + result + "]";
584
+ }
585
+ writeScopedRegistration(val, parent, accessor, registered) {
586
+ const ref = new Reference(parent, accessor, this.flushId, this.buf.length);
587
+ ref.channel = this.channel;
588
+ this.refs.set(val, ref);
589
+ ref.debug = DEBUG.get(val);
590
+ const scope = registered.scope;
591
+ const scopeId = scope[K_SCOPE_ID];
592
+ trackScope(this, scope, scopeId);
593
+ const locals = registered.locals?.(this.boundary.state.scope);
594
+ if (locals) {
595
+ this.buf.push(registered.access + "(_(" + scopeId + ")");
596
+ for (const local of locals) {
597
+ this.buf.push(",");
598
+ writePlainObject(this, local, newArgReference(this, ref, local));
599
+ }
600
+ } else this.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
601
+ this.buf.push(")");
602
+ }
589
603
  };
590
604
  var Reference = class {
591
605
  assignments = null;
592
- calls = null;
606
+ deferredMembers = null;
593
607
  scopeId = void 0;
594
608
  channel = void 0;
595
609
  parent;
@@ -625,109 +639,86 @@ function setDebugSlotName(obj, accessor, name) {
625
639
  slots: { [accessor]: name }
626
640
  });
627
641
  }
628
- var Serializer = class {
629
- #state = new State$1();
630
- pending(channel) {
631
- return hasMatchingMutations(this.#state.mutated, channel?.readyId);
632
- }
633
- pendingReadyChannel() {
634
- for (const mutation of this.#state.mutated) if (mutation.channel?.readyId) return mutation.channel;
635
- }
636
- stringifyScopes(flushes, boundary, channel) {
637
- try {
638
- this.#state.boundary = boundary;
639
- this.#state.channel = channel;
640
- return writeScopesRoot(this.#state, flushes);
641
- } catch (err) {
642
- abortRender(boundary, err);
643
- return "";
644
- } finally {
645
- this.#state.flushId++;
646
- this.#state.buf = [];
647
- }
648
- }
649
- written(val) {
650
- return this.#state.refs.has(val);
651
- }
652
- takeChannelDeps() {
653
- const deps = this.#state.channelDeps;
654
- this.#state.channelDeps = null;
655
- return deps;
656
- }
657
- writeCall(value, object, property, channel) {
658
- this.#state.mutated.push({
659
- value,
660
- object,
661
- property,
662
- channel
663
- });
642
+ function stringifyScopes(state, flushes, boundary, channel) {
643
+ try {
644
+ state.boundary = boundary;
645
+ state.channel = channel;
646
+ return writeScopesRoot(state, flushes);
647
+ } catch (err) {
648
+ abortRender(boundary, err);
649
+ return "";
650
+ } finally {
651
+ state.flushId++;
652
+ state.buf = [];
664
653
  }
665
- dropCall(value, object, property) {
666
- const { mutated } = this.#state;
667
- for (let i = 0; i < mutated.length; i++) {
668
- const mutation = mutated[i];
669
- if (mutation.value === value && mutation.object === object && mutation.property === property) {
670
- mutated.splice(i, 1);
671
- return true;
672
- }
654
+ }
655
+ function pendingReadyChannel(state) {
656
+ const calls = state.queuedReadyCalls;
657
+ return calls.length ? calls[0].channel : void 0;
658
+ }
659
+ function takeChannelDeps(state) {
660
+ const deps = state.channelDeps;
661
+ state.channelDeps = null;
662
+ return deps;
663
+ }
664
+ function queueCall(state, value, object, method, channel) {
665
+ (channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
666
+ method,
667
+ value,
668
+ object,
669
+ channel,
670
+ valueId: null
671
+ });
672
+ }
673
+ function dropQueuedCall(state, value, object, method, channel) {
674
+ const queuedCalls = channel?.readyId ? state.queuedReadyCalls : state.queuedCalls;
675
+ for (let i = 0; i < queuedCalls.length; i++) {
676
+ const call = queuedCalls[i];
677
+ if (call.value === value && call.object === object && call.method === method) {
678
+ queuedCalls.splice(i, 1);
679
+ return true;
673
680
  }
674
- return false;
675
681
  }
676
- };
677
- function register(id, val, scope, locals) {
682
+ return false;
683
+ }
684
+ function register(id, val, scope, locals, access = "_._" + toAccess(toObjectKey(id))) {
678
685
  REGISTRY.set(val, {
679
686
  id,
680
687
  scope,
681
688
  locals,
682
- access: "_._" + toAccess(toObjectKey(id))
689
+ access
683
690
  });
684
691
  return val;
685
692
  }
686
- function getRegistered(val) {
687
- const registered = REGISTRY.get(val);
688
- if (registered) return {
689
- id: registered.id,
690
- scope: registered.scope
691
- };
692
- }
693
693
  function writeScopesRoot(state, flushes) {
694
694
  const { buf } = state;
695
695
  let nextSlotId = -1;
696
- let fillIndex = -1;
696
+ let scopesIndex = -1;
697
697
  for (const flush of flushes) {
698
698
  const scopeId = flush[0];
699
699
  const scope = flush[1];
700
- const ref = state.refs.get(scope) || newScopeReference(state, scope, scopeId);
700
+ const ref = state.scopeRef(scope, scopeId);
701
701
  const openIndex = buf.push("") - 1;
702
- if (writeObjectProps(state, flush[2], ref)) {
703
- buf[openIndex] = nextSlotId === -1 ? scopeId + ",{" : (scopeId !== nextSlotId ? "," + (scopeId - nextSlotId) : "") + ",{";
704
- if (fillIndex === -1) fillIndex = openIndex;
702
+ if (state.writeScopeProps(flush[2], ref)) {
703
+ buf[openIndex] = nextSlotId === -1 ? state.scopesCursor(scopeId) + "{" : (scopeId !== nextSlotId ? "," + (scopeId - nextSlotId) : "") + ",{";
704
+ if (scopesIndex === -1) scopesIndex = openIndex;
705
705
  nextSlotId = scopeId + 1;
706
706
  buf.push("}");
707
707
  } else buf.pop();
708
708
  }
709
709
  let extras = "";
710
- if (state.pendingAssignments.size || hasChannelMutations(state)) {
711
- extras = ",0)";
712
- if (fillIndex !== -1) {
713
- buf[fillIndex] = "_([" + buf[fillIndex];
714
- buf.push("])");
715
- }
716
- writeAssigned(state);
717
- }
710
+ if (state.deferredRefs.size || hasChannelCalls(state)) extras = state.writeTrailing(scopesIndex);
718
711
  let result = extras && "(";
719
712
  for (const chunk of buf) result += chunk;
720
713
  result += extras;
721
714
  if (!result) return "";
722
- const arrow = state.wroteUndefined ? "(_,$)=>" : "_=>";
723
- state.wroteUndefined = false;
724
- return extras ? arrow + result : arrow + "[" + result + "]";
715
+ return state.wrapPayload(result, extras);
725
716
  }
726
- function writeAssigned(state) {
717
+ function writeDeferred(state) {
727
718
  let sep = state.buf.length ? "," : "";
728
- if (state.pendingAssignments.size) {
729
- const pending = state.pendingAssignments;
730
- state.pendingAssignments = /* @__PURE__ */ new Set();
719
+ if (state.deferredRefs.size) {
720
+ const pending = state.deferredRefs;
721
+ state.deferredRefs = /* @__PURE__ */ new Set();
731
722
  let buf = "";
732
723
  let hasCalls = false;
733
724
  for (const ref of pending) {
@@ -736,77 +727,88 @@ function writeAssigned(state) {
736
727
  ref.assignments = null;
737
728
  sep = ",";
738
729
  }
739
- hasCalls ||= ref.calls !== null;
730
+ hasCalls ||= ref.deferredMembers !== null;
740
731
  }
741
732
  if (buf) state.buf.push(buf);
742
733
  if (hasCalls) for (const ref of pending) {
743
- if (!ref.calls) continue;
744
- for (const { method, args } of ref.calls) {
745
- state.buf.push((state.buf.length ? "," : "") + ref.id + "." + method + "(");
746
- for (let a = 0; a < args.length; a++) {
747
- if (a) state.buf.push(",");
748
- writeCallArg(state, args[a]);
749
- }
750
- state.buf.push(")");
734
+ const members = ref.deferredMembers;
735
+ if (members) {
736
+ writeDeferredMembers(state, ref.id, members);
737
+ ref.deferredMembers = null;
751
738
  }
752
- ref.calls = null;
753
739
  }
754
740
  }
755
- if (hasChannelMutations(state)) {
741
+ const readyId = state.channel?.readyId;
742
+ let calls = state.queuedCalls;
743
+ if (readyId) {
744
+ calls = [];
756
745
  const remaining = [];
757
- for (const mutation of state.mutated) {
758
- if (!mutationMatchesReadyId(mutation, state.channel?.readyId)) {
759
- remaining.push(mutation);
760
- continue;
746
+ for (const call of state.queuedReadyCalls) (call.channel.readyId === readyId ? calls : remaining).push(call);
747
+ state.queuedReadyCalls = remaining;
748
+ } else if (calls.length) state.queuedCalls = [];
749
+ for (const call of calls) {
750
+ const objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
751
+ if (writeProp(state, call.object, null, "")) {
752
+ const objectRef = state.refs.get(call.object);
753
+ if (!objectRef.id && !isAncestorChannelRef(state, objectRef)) {
754
+ objectRef.id = nextRefAccess(state);
755
+ state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex];
756
+ state.buf.push(")");
757
+ } else if (objectRef.id && state.buf[objectStartIndex] !== objectRef.id) {
758
+ state.buf[objectStartIndex] = "(" + state.buf[objectStartIndex];
759
+ state.buf.push(")");
761
760
  }
762
- const hasSeen = state.refs.get(mutation.object)?.id;
763
- const objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
764
- if (writeProp(state, mutation.object, null, "")) {
765
- const objectRef = state.refs.get(mutation.object);
766
- if (objectRef && objectRef.scopeId === void 0) {
767
- if (!objectRef.id && !isAncestorChannelRef(state, objectRef)) {
768
- objectRef.id = nextRefAccess(state);
769
- state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex];
770
- state.buf.push(")");
771
- } else if (!hasSeen) {
772
- state.buf[objectStartIndex] = "(" + state.buf[objectStartIndex];
773
- state.buf.push(")");
774
- }
775
- }
776
- } else state.buf.push("void 0");
777
- const valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
778
- if (mutation.value === void 0) {} else if (writeProp(state, mutation.value, null, "")) {
779
- const valueRef = typeof mutation.value === "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
780
- if (valueRef && !valueRef.id && valueRef.scopeId === void 0 && !isAncestorChannelRef(state, valueRef)) {
781
- valueRef.id = mutation.valueId || nextRefAccess(state);
782
- state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex];
783
- }
784
- } else state.buf.push("void 0");
785
- state.buf.push(")");
786
- }
787
- state.mutated = remaining;
761
+ } else state.buf.push("void 0");
762
+ state.buf.push("." + call.method + "(");
763
+ if (call.value !== void 0) writeCallArg(state, call.value, call.valueId);
764
+ state.buf.push(")");
765
+ }
766
+ if (state.deferredRefs.size) writeDeferred(state);
767
+ }
768
+ function writeDeferredMembers(state, id, { collection, first, rest }) {
769
+ if (collection instanceof Map) {
770
+ writeDeferredEntry(state, id, first);
771
+ for (const entry of rest) writeDeferredEntry(state, id, entry);
772
+ } else {
773
+ writeDeferredMember(state, id, first);
774
+ for (const member of rest) writeDeferredMember(state, id, member);
775
+ }
776
+ }
777
+ function writeDeferredEntry(state, id, [key, value]) {
778
+ state.buf.push("," + id + ".set(");
779
+ if (key !== void 0 || value !== void 0) writeCallArg(state, key, null);
780
+ if (value !== void 0) {
781
+ state.buf.push(",");
782
+ writeCallArg(state, value, null);
788
783
  }
789
- if (state.pendingAssignments.size) writeAssigned(state);
784
+ state.buf.push(")");
785
+ }
786
+ function writeDeferredMember(state, id, member) {
787
+ state.buf.push("," + id + ".add(");
788
+ if (member !== void 0) writeCallArg(state, member, null);
789
+ state.buf.push(")");
790
790
  }
791
- function writeCallArg(state, val) {
791
+ function writeCallArg(state, val, valueId) {
792
+ const startIndex = state.buf.length;
792
793
  if (val === void 0) {
793
794
  state.wroteUndefined = true;
794
795
  state.buf.push("$");
795
796
  } else if (writeProp(state, val, null, "")) {
796
- const ref = state.refs.get(val) || state.strs.get(val);
797
- if (ref) ensureId(state, ref);
797
+ const ref = typeof val === "string" ? state.strs.get(val) : state.refs.get(val);
798
+ if (ref && !ref.id && ref.scopeId === void 0 && !isAncestorChannelRef(state, ref)) {
799
+ ref.id = valueId || nextRefAccess(state);
800
+ state.buf[startIndex] = ref.id + "=" + state.buf[startIndex];
801
+ }
798
802
  } else state.buf.push("void 0");
799
803
  }
800
- function hasChannelMutations(state) {
801
- return hasMatchingMutations(state.mutated, state.channel?.readyId);
804
+ function hasChannelCalls(state) {
805
+ return hasMatchingCalls(state, state.channel?.readyId);
802
806
  }
803
- function hasMatchingMutations(mutated, readyId) {
804
- for (const mutation of mutated) if (mutationMatchesReadyId(mutation, readyId)) return true;
807
+ function hasMatchingCalls(state, readyId) {
808
+ if (!readyId) return state.queuedCalls.length > 0;
809
+ for (const call of state.queuedReadyCalls) if (call.channel.readyId === readyId) return true;
805
810
  return false;
806
811
  }
807
- function mutationMatchesReadyId(mutation, readyId) {
808
- return mutation.channel?.readyId ? mutation.channel.readyId === readyId : !readyId;
809
- }
810
812
  function writeProp(state, val, parent, accessor) {
811
813
  switch (typeof val) {
812
814
  case "string": return writeString(state, val, parent, accessor);
@@ -829,8 +831,8 @@ function writeReferenceOr(state, write, val, parent, accessor) {
829
831
  return false;
830
832
  }
831
833
  if (parent && isCircular(parent, ref)) {
832
- ensureId(state, ref);
833
- state.pendingAssignments.add(ref);
834
+ ensureRefAccess(state, ref);
835
+ state.deferredRefs.add(ref);
834
836
  addAssignment(ref, accessId(state, parent) + toAccess(accessor));
835
837
  return false;
836
838
  }
@@ -864,23 +866,8 @@ function quoteRegisterId(id) {
864
866
  }
865
867
  function writeRegistered(state, val, parent, accessor, registered) {
866
868
  const { scope } = registered;
867
- if (scope) {
868
- const ref = new Reference(parent, accessor, state.flushId, state.buf.length);
869
- ref.channel = state.channel;
870
- state.refs.set(val, ref);
871
- ref.debug = DEBUG.get(val);
872
- const scopeId = scope[K_SCOPE_ID];
873
- trackScope(state, scope, scopeId);
874
- const locals = registered.locals?.(state.boundary.state.scope);
875
- if (locals) {
876
- state.buf.push(registered.access + "(_(" + scopeId + ")");
877
- for (const local of locals) {
878
- state.buf.push(",");
879
- writePlainObject(state, local, newArgReference(state, ref, local));
880
- }
881
- } else state.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
882
- state.buf.push(")");
883
- } else state.buf.push(registered.access);
869
+ if (scope) state.writeScopedRegistration(val, parent, accessor, registered);
870
+ else state.buf.push(registered.access);
884
871
  return true;
885
872
  }
886
873
  const STRING_DEDUP_LENGTH = 12;
@@ -1074,7 +1061,7 @@ function writePromise(state, val, ref) {
1074
1061
  const pId = nextRefAccess(state);
1075
1062
  const handle = newAsyncHandle(state, ref, pId);
1076
1063
  state.buf.push("(p=>p=new Promise((f,r)=>" + pId + "={f,r(e){p.catch(_=>0);r(e)}}))()");
1077
- val.then((v) => writeAsyncCall(state, boundary, handle, "f", v, channel, pId), (v) => writeAsyncCall(state, boundary, handle, "r", v, channel, pId));
1064
+ val.then((v) => queueAsyncCall(state, boundary, handle, "f", v, channel, pId), (v) => queueAsyncCall(state, boundary, handle, "r", v, channel, pId));
1078
1065
  boundary.startAsync();
1079
1066
  return true;
1080
1067
  }
@@ -1093,14 +1080,18 @@ function writeMap(state, val, ref) {
1093
1080
  const items = [];
1094
1081
  let assignments;
1095
1082
  let needsId;
1096
- let deferring = false;
1097
1083
  let i = 0;
1084
+ const entries = val.entries();
1098
1085
  if (val.size < 25) {
1099
- for (let [itemKey, itemValue] of val) {
1100
- if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue))) deferring = true;
1101
- if (deferring) {
1102
- deferCall(state, ref, "set", [itemKey, itemValue]);
1103
- continue;
1086
+ for (const entry of entries) {
1087
+ let [itemKey, itemValue] = entry;
1088
+ if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
1089
+ deferMembers(state, ref, val, entry, entries);
1090
+ if (!i) {
1091
+ state.buf.push("new Map");
1092
+ return true;
1093
+ }
1094
+ break;
1104
1095
  }
1105
1096
  if (itemKey === val) {
1106
1097
  itemKey = void 0;
@@ -1110,16 +1101,20 @@ function writeMap(state, val, ref) {
1110
1101
  itemValue = void 0;
1111
1102
  (assignments ||= []).push("a[" + i + "][1]");
1112
1103
  }
1113
- needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
1104
+ needsId ||= isReusableMember(itemKey) || isReusableMember(itemValue);
1114
1105
  i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
1115
1106
  }
1116
1107
  writeArrayArg(state, ref, items, assignments && "((m,a)=>(" + assignmentsToString(assignments, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map,", "new Map(", needsId);
1117
1108
  } else {
1118
- for (let [itemKey, itemValue] of val) {
1119
- if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue))) deferring = true;
1120
- if (deferring) {
1121
- deferCall(state, ref, "set", [itemKey, itemValue]);
1122
- continue;
1109
+ for (const entry of entries) {
1110
+ let [itemKey, itemValue] = entry;
1111
+ if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
1112
+ deferMembers(state, ref, val, entry, entries);
1113
+ if (!i) {
1114
+ state.buf.push("new Map");
1115
+ return true;
1116
+ }
1117
+ break;
1123
1118
  }
1124
1119
  if (itemKey === val) {
1125
1120
  itemKey = 0;
@@ -1129,7 +1124,7 @@ function writeMap(state, val, ref) {
1129
1124
  itemValue = 0;
1130
1125
  (assignments ||= []).push("a[" + (i + 1) + "]");
1131
1126
  }
1132
- needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
1127
+ needsId ||= isReusableMember(itemKey) || isReusableMember(itemValue);
1133
1128
  i = items.push(itemKey, itemValue);
1134
1129
  }
1135
1130
  writeArrayArg(state, ref, items, assignments && "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignmentsToString(assignments, "new Map") + "))(", "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(", needsId);
@@ -1144,18 +1139,21 @@ function writeSet(state, val, ref) {
1144
1139
  const items = [];
1145
1140
  let assignments;
1146
1141
  let needsId;
1147
- let deferring = false;
1148
1142
  let i = 0;
1149
- for (let item of val) {
1150
- if (!deferring && item !== val && isAncestorMember(state, ref, item)) deferring = true;
1151
- if (deferring) {
1152
- deferCall(state, ref, "add", [item]);
1153
- continue;
1143
+ const members = val.values();
1144
+ for (let item of members) {
1145
+ if (item !== val && isAncestorMember(state, ref, item)) {
1146
+ deferMembers(state, ref, val, item, members);
1147
+ if (!i) {
1148
+ state.buf.push("new Set");
1149
+ return true;
1150
+ }
1151
+ break;
1154
1152
  }
1155
1153
  if (item === val) {
1156
1154
  item = 0;
1157
1155
  (assignments ||= []).push("i[" + i + "]");
1158
- } else needsId ||= isDedupedMember(item);
1156
+ } else needsId ||= isReusableMember(item);
1159
1157
  i = items.push(item);
1160
1158
  }
1161
1159
  writeArrayArg(state, ref, items, assignments && "((s,i)=>(" + assignmentsToString(assignments, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId);
@@ -1166,13 +1164,14 @@ function isAncestorMember(state, container, member) {
1166
1164
  const ref = state.refs.get(member);
1167
1165
  return ref !== void 0 && isCircular(container, ref);
1168
1166
  }
1169
- function deferCall(state, ref, method, args) {
1170
- ensureId(state, ref);
1171
- (ref.calls ||= []).push({
1172
- method,
1173
- args
1174
- });
1175
- state.pendingAssignments.add(ref);
1167
+ function deferMembers(state, ref, collection, first, rest) {
1168
+ ensureRefAccess(state, ref);
1169
+ ref.deferredMembers = {
1170
+ collection,
1171
+ first,
1172
+ rest
1173
+ };
1174
+ state.deferredRefs.add(ref);
1176
1175
  }
1177
1176
  function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
1178
1177
  if (assignsPrefix || needsId) {
@@ -1188,7 +1187,7 @@ function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
1188
1187
  function newArgReference(state, parent, val) {
1189
1188
  for (const key in val) {
1190
1189
  const member = val[key];
1191
- if (isDedupedMember(member) && !(typeof member === "string" ? state.strs.has(member) : state.refs.has(member))) {
1190
+ if (isReusableMember(member) && !(typeof member === "string" ? state.strs.has(member) : state.refs.has(member))) {
1192
1191
  const ref = new Reference(parent, null, state.flushId, null, nextRefAccess(state));
1193
1192
  state.buf.push(ref.id + "=");
1194
1193
  return ref;
@@ -1196,7 +1195,7 @@ function newArgReference(state, parent, val) {
1196
1195
  }
1197
1196
  return new Reference(parent, null, state.flushId, state.buf.length);
1198
1197
  }
1199
- function isDedupedMember(val) {
1198
+ function isReusableMember(val) {
1200
1199
  switch (typeof val) {
1201
1200
  case "object": return val !== null && val[K_SCOPE_ID] === void 0;
1202
1201
  case "function":
@@ -1267,7 +1266,7 @@ function writeAggregateError(state, val, ref) {
1267
1266
  if (inlined) {
1268
1267
  const errorsRef = state.refs.get(val.errors);
1269
1268
  if (errorsRef?.id) {
1270
- state.pendingAssignments.add(errorsRef);
1269
+ state.deferredRefs.add(errorsRef);
1271
1270
  addAssignment(errorsRef, accessId(state, ref) + toAccess("errors"));
1272
1271
  }
1273
1272
  }
@@ -1327,7 +1326,7 @@ function writeRequest(state, val, ref) {
1327
1326
  }
1328
1327
  const seenHeaders = state.refs.get(val.headers);
1329
1328
  if (seenHeaders) {
1330
- options += sep + "headers:" + ensureId(state, seenHeaders);
1329
+ options += sep + "headers:" + ensureRefAccess(state, seenHeaders);
1331
1330
  sep = ",";
1332
1331
  } else {
1333
1332
  state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
@@ -1377,7 +1376,7 @@ function writeResponse(state, val, ref) {
1377
1376
  sep = ",";
1378
1377
  }
1379
1378
  const seenHeaders = state.refs.get(val.headers);
1380
- if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders);
1379
+ if (seenHeaders) options += sep + "headers:" + ensureRefAccess(state, seenHeaders);
1381
1380
  else {
1382
1381
  state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
1383
1382
  const headers = stringEntriesToHeadersInit(val.headers);
@@ -1417,15 +1416,15 @@ function writeReadableStream(state, val, ref) {
1417
1416
  const iterId = nextRefAccess(state);
1418
1417
  const handle = newAsyncHandle(state, ref, iterId);
1419
1418
  const onFulfilled = ({ value, done }) => {
1420
- if (done) writeAsyncCall(state, boundary, handle, "r", value, channel);
1419
+ if (done) queueAsyncCall(state, boundary, handle, "r", value, channel);
1421
1420
  else if (!boundary.aborted) {
1422
1421
  reader.read().then(onFulfilled, onRejected);
1423
1422
  boundary.startAsync();
1424
- writeAsyncCall(state, boundary, handle, "f", value, channel);
1423
+ queueAsyncCall(state, boundary, handle, "f", value, channel);
1425
1424
  }
1426
1425
  };
1427
1426
  const onRejected = (reason) => {
1428
- writeAsyncCall(state, boundary, handle, "j", reason, channel);
1427
+ queueAsyncCall(state, boundary, handle, "j", reason, channel);
1429
1428
  };
1430
1429
  state.buf.push("new ReadableStream({start(c){(async(_,f,v,l,i,p=a=>l=new Promise((r,j)=>{f=_.r=r;_.j=j}),a=((_.f=v=>{f(v);a.push(p())}),[p()]))=>{for(i of a)v=await i,i==l?c.close():c.enqueue(v)})(" + iterId + "={}).catch(e=>c.error(e))}})");
1431
1430
  reader.read().then(onFulfilled, onRejected);
@@ -1446,7 +1445,7 @@ function writeGenerator(state, iter, ref) {
1446
1445
  returnValue = value;
1447
1446
  break;
1448
1447
  }
1449
- needsId ||= isDedupedMember(value);
1448
+ needsId ||= isReusableMember(value);
1450
1449
  yields.push(value);
1451
1450
  }
1452
1451
  if (returnValue === void 0 && !yields.length) {
@@ -1466,9 +1465,9 @@ function writeGenerator(state, iter, ref) {
1466
1465
  writeProp(state, returnValue, holder, "v");
1467
1466
  } else if (returnValue !== void 0) {
1468
1467
  state.buf.push(",");
1469
- if (writeProp(state, returnValue, ref, "") && isDedupedMember(returnValue)) {
1468
+ if (writeProp(state, returnValue, ref, "") && isReusableMember(returnValue)) {
1470
1469
  const retRef = typeof returnValue === "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
1471
- if (retRef) ensureId(state, retRef);
1470
+ if (retRef) ensureRefAccess(state, retRef);
1472
1471
  }
1473
1472
  }
1474
1473
  state.buf.push(")");
@@ -1483,15 +1482,15 @@ function writeAsyncGenerator(state, iter, ref) {
1483
1482
  const iterId = nextRefAccess(state);
1484
1483
  const handle = newAsyncHandle(state, ref, iterId);
1485
1484
  const onFulfilled = ({ value, done }) => {
1486
- if (done) writeAsyncCall(state, boundary, handle, "r", value, channel);
1485
+ if (done) queueAsyncCall(state, boundary, handle, "r", value, channel);
1487
1486
  else if (!boundary.aborted) {
1488
1487
  iter.next().then(onFulfilled, onRejected);
1489
1488
  boundary.startAsync();
1490
- writeAsyncCall(state, boundary, handle, "f", value, channel);
1489
+ queueAsyncCall(state, boundary, handle, "f", value, channel);
1491
1490
  }
1492
1491
  };
1493
1492
  const onRejected = (reason) => {
1494
- writeAsyncCall(state, boundary, handle, "j", reason, channel);
1493
+ queueAsyncCall(state, boundary, handle, "j", reason, channel);
1495
1494
  };
1496
1495
  state.buf.push("(async function*(_,f,v,l,i,p=a=>l=new Promise((r,j)=>{f=_.r=r;_.j=j}),a=((_.f=v=>{f(v);a.push(p())}),[p()])){for(i of a)v=await i,i!=l&&(yield v);return v})(" + iterId + "={})");
1497
1496
  iter.next().then(onFulfilled, onRejected);
@@ -1530,12 +1529,12 @@ function writeMaybeIterableProps(state, val, ref) {
1530
1529
  }
1531
1530
  return sep;
1532
1531
  }
1533
- function writeAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1532
+ function queueAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1534
1533
  if (boundary.aborted) return;
1535
- state.mutated.push({
1534
+ (channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
1535
+ method,
1536
1536
  value,
1537
1537
  object: handle,
1538
- property: method,
1539
1538
  channel,
1540
1539
  valueId
1541
1540
  });
@@ -1729,9 +1728,9 @@ function writeRef(state, ref) {
1729
1728
  ref.pos = state.buf.length;
1730
1729
  ref.flushId = state.flushId;
1731
1730
  state.buf.push(ref.path);
1732
- } else state.buf.push(ensureId(state, ref));
1731
+ } else state.buf.push(ensureRefAccess(state, ref));
1733
1732
  }
1734
- function ensureId(state, ref) {
1733
+ function ensureRefAccess(state, ref) {
1735
1734
  if (ref.scopeId !== void 0) {
1736
1735
  trackChannel(state, ref);
1737
1736
  return "_(" + ref.scopeId + ")";
@@ -1740,13 +1739,13 @@ function ensureId(state, ref) {
1740
1739
  trackChannel(state, ref);
1741
1740
  return ref.id;
1742
1741
  }
1743
- return assignId(state, ref);
1742
+ return claimRefAccess(state, ref);
1744
1743
  }
1745
1744
  function accessId(state, ref) {
1746
- const id = ensureId(state, ref);
1745
+ const id = ensureRefAccess(state, ref);
1747
1746
  return id === ref.id || ref.scopeId !== void 0 ? id : "(" + id + ")";
1748
1747
  }
1749
- function assignId(state, ref) {
1748
+ function claimRefAccess(state, ref) {
1750
1749
  const { pos } = ref;
1751
1750
  if (pos !== null && ref.flushId === state.flushId) {
1752
1751
  ref.id = nextRefAccess(state);
@@ -1843,10 +1842,10 @@ function patchIteratorNext(proto) {
1843
1842
  //#endregion
1844
1843
  //#region src/html/attrs.ts
1845
1844
  function _attr_class(value) {
1846
- return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
1845
+ return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
1847
1846
  }
1848
1847
  function _attr_style(value) {
1849
- return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
1848
+ return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
1850
1849
  }
1851
1850
  function _attr_option_value(value) {
1852
1851
  const valueAttr = _attr("value", value);
@@ -1894,7 +1893,7 @@ function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeT
1894
1893
  }
1895
1894
  function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
1896
1895
  if (checkedChange) writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType);
1897
- return isNotVoid(checked) ? " checked" : "";
1896
+ return isNotNullishOrFalse(checked) ? " checked" : "";
1898
1897
  }
1899
1898
  function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
1900
1899
  const valueAttr = _attr("value", value);
@@ -1913,7 +1912,7 @@ function getCheckedValueRef(checkedValue) {
1913
1912
  }
1914
1913
  }
1915
1914
  function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
1916
- const normalizedOpen = isNotVoid(open);
1915
+ const normalizedOpen = isNotNullishOrFalse(open);
1917
1916
  if (openChange) writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType);
1918
1917
  return normalizedOpen ? " open" : "";
1919
1918
  }
@@ -1925,7 +1924,7 @@ function _style_html(decls) {
1925
1924
  return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
1926
1925
  }
1927
1926
  function _attr(name, value) {
1928
- return isVoid(value) ? "" : nonVoidAttr(name, value);
1927
+ return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
1929
1928
  }
1930
1929
  function _attr_and(name, value, attr) {
1931
1930
  return value ? attr : _attr(name, value);
@@ -1982,14 +1981,14 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
1982
1981
  break;
1983
1982
  default:
1984
1983
  if (name) assertValidAttrName(name);
1985
- if (name && !(isVoid(value) || skip.test(name) || name === "content" && tagName !== "meta")) {
1984
+ if (name && !(isNullishOrFalse(value) || skip.test(name) || name === "content" && tagName !== "meta")) {
1986
1985
  if (isEventHandler(name)) {
1987
1986
  if (!events) {
1988
1987
  events = {};
1989
1988
  writeScope(scopeId, { [EventAttributes + nodeAccessor]: events });
1990
1989
  }
1991
- events[getEventHandlerName(name)] = value;
1992
- } else result += nonVoidAttr(name, value);
1990
+ events[getEventType(name)] = value;
1991
+ } else result += stringifyAttr(name, value);
1993
1992
  }
1994
1993
  }
1995
1994
  }
@@ -2002,7 +2001,7 @@ function _attrs_content(data, nodeAccessor, scopeId, tagName, markerGuard) {
2002
2001
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
2003
2002
  const partial = {};
2004
2003
  for (const name in data) {
2005
- const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
2004
+ const key = isEventHandler(name) ? `on-${getEventType(name)}` : name;
2006
2005
  if (!skip[key]) partial[key] = data[name];
2007
2006
  }
2008
2007
  assertExclusiveAttrs({
@@ -2036,7 +2035,7 @@ function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, s
2036
2035
  function stringAttr(name, value) {
2037
2036
  return value && " " + name + attrAssignment(value);
2038
2037
  }
2039
- function nonVoidAttr(name, value) {
2038
+ function stringifyAttr(name, value) {
2040
2039
  assertValidAttrValue(name, value);
2041
2040
  switch (typeof value) {
2042
2041
  case "string": return " " + name + attrAssignment(value);
@@ -2071,18 +2070,7 @@ function normalizedValueMatches(a, b) {
2071
2070
  return false;
2072
2071
  }
2073
2072
  function normalizeStrAttrValue(value) {
2074
- return isNotVoid(value) && value !== true ? value + "" : "";
2075
- }
2076
- //#endregion
2077
- //#region src/html/for.ts
2078
- function forOfBy(by, item, index) {
2079
- return by ? typeof by === "string" ? item[by] : by(item, index) : index;
2080
- }
2081
- function forInBy(by, name, value) {
2082
- return by ? by(name, value) : name;
2083
- }
2084
- function forStepBy(by, index) {
2085
- return by ? by(index) : index;
2073
+ return isNotNullishOrFalse(value) && value !== true ? value + "" : "";
2086
2074
  }
2087
2075
  //#endregion
2088
2076
  //#region src/html/inlined-runtimes.debug.ts
@@ -2227,13 +2215,13 @@ function _peek_scope_id() {
2227
2215
  return $chunk.boundary.state.scopeId;
2228
2216
  }
2229
2217
  const kPendingContexts = Symbol("Pending Contexts");
2230
- function withContext(key, value, cb, cbValue) {
2218
+ function withContext(key, value, cb, cbValue, cbValue2) {
2231
2219
  const ctx = $chunk.context ||= { [kPendingContexts]: 0 };
2232
2220
  const prev = ctx[key];
2233
2221
  ctx[kPendingContexts]++;
2234
2222
  ctx[key] = value;
2235
2223
  try {
2236
- return cb(cbValue);
2224
+ return cb(cbValue, cbValue2);
2237
2225
  } finally {
2238
2226
  ctx[kPendingContexts]--;
2239
2227
  ctx[key] = prev;
@@ -2246,15 +2234,15 @@ function captureContext(chunk) {
2246
2234
  };
2247
2235
  }
2248
2236
  const kBranchId = Symbol("Branch Id");
2249
- const kIsAsync = Symbol("Is Async");
2237
+ const kAsyncContent = Symbol("Async Content");
2250
2238
  function isInResumedBranch() {
2251
2239
  return $chunk?.context?.[kBranchId] !== void 0;
2252
2240
  }
2253
- function withBranchId(branchId, cb, cbValue) {
2254
- return withContext(kBranchId, branchId, cb, cbValue);
2241
+ function withBranchId(branchId, cb, cbValue, cbValue2) {
2242
+ return withContext(kBranchId, branchId, cb, cbValue, cbValue2);
2255
2243
  }
2256
- function withIsAsync(async, cb, value) {
2257
- return withContext(kIsAsync, async, cb, value);
2244
+ function withAsyncContent(async, cb, value) {
2245
+ return withContext(kAsyncContent, async, cb, value);
2258
2246
  }
2259
2247
  function _html(html) {
2260
2248
  $chunk.writeHTML(html);
@@ -2272,9 +2260,8 @@ function mayDrop(written) {
2272
2260
  return false;
2273
2261
  }
2274
2262
  function _script(scopeId, registryId, markerGuard) {
2275
- if (markerGuard === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync])) _resume_branch(scopeId);
2276
- $chunk.boundary.state.needsMainRuntime = true;
2277
- $chunk.writeEffect(scopeId, registryId);
2263
+ if (markerGuard === 0 && ($chunk.channel.readyId || $chunk.context?.[kAsyncContent])) _resume_branch(scopeId);
2264
+ $chunk.boundary.state.queueEffect(scopeId, registryId);
2278
2265
  }
2279
2266
  function _trailers(html) {
2280
2267
  $chunk.boundary.state.trailerHTML += html;
@@ -2294,27 +2281,27 @@ function _hoist(scopeId, id) {
2294
2281
  getter[Symbol.iterator] = _hoist_read_error;
2295
2282
  return _resume(getter, id, scopeId);
2296
2283
  }
2297
- function _el_resume(scopeId, accessor, shouldResume) {
2298
- if (shouldResume === 0) return "";
2284
+ function _el_resume(scopeId, accessor, markerGuard) {
2285
+ if (markerGuard === 0) return "";
2299
2286
  const { state } = $chunk.boundary;
2300
- state.needsMainRuntime = true;
2287
+ state.needsWalkerRuntime = true;
2301
2288
  return state.mark("$", scopeId + " " + accessor);
2302
2289
  }
2303
- function _text_resume(scopeId, accessor, val, shouldResume) {
2304
- return markText(scopeId, accessor, _escape(val), shouldResume);
2290
+ function _text_resume(scopeId, accessor, val, markerGuard) {
2291
+ return markText(scopeId, accessor, _escape(val), markerGuard);
2305
2292
  }
2306
- function _html_resume(scopeId, accessor, val, shouldResume) {
2293
+ function _html_resume(scopeId, accessor, val, markerGuard) {
2307
2294
  const html = _unescaped(val);
2308
- if (shouldResume === 0 || !~html.indexOf("<")) return markText(scopeId, accessor, html, shouldResume);
2295
+ if (markerGuard === 0 || !~html.indexOf("<")) return markText(scopeId, accessor, html, markerGuard);
2309
2296
  const { state } = $chunk.boundary;
2310
- state.needsMainRuntime = true;
2297
+ state.needsWalkerRuntime = true;
2311
2298
  return state.mark("&", "") + html + state.mark("'", scopeId + " " + accessor);
2312
2299
  }
2313
- function markText(scopeId, accessor, text, shouldResume) {
2314
- if (shouldResume === 0) return text;
2300
+ function markText(scopeId, accessor, text, markerGuard) {
2301
+ if (markerGuard === 0) return text;
2315
2302
  const { state } = $chunk.boundary;
2316
- state.needsMainRuntime = true;
2317
- return text ? (shouldResume === 2 ? "<!>" : "") + text + state.mark("$", scopeId + " " + accessor) : state.mark("%", scopeId + " " + accessor);
2303
+ state.needsWalkerRuntime = true;
2304
+ return text ? (markerGuard === 2 ? "<!>" : "") + text + state.mark("$", scopeId + " " + accessor) : state.mark("%", scopeId + " " + accessor);
2318
2305
  }
2319
2306
  function _resume_branch(scopeId) {
2320
2307
  const branchId = $chunk.context?.[kBranchId];
@@ -2325,7 +2312,7 @@ function _attr_content(nodeAccessor, scopeId, content, markerGuard) {
2325
2312
  const render = normalizeServerRender(content);
2326
2313
  const branchId = _peek_scope_id();
2327
2314
  if (render) try {
2328
- _set_scope_reason(shouldResume ? CLIENT_ALL : 0);
2315
+ _set_scope_reason(shouldResume ? ALL_GROUPS : 0);
2329
2316
  if (shouldResume) withBranchId(branchId, render);
2330
2317
  else render();
2331
2318
  } finally {
@@ -2351,137 +2338,21 @@ function _var(parentScopeId, scopeOffsetAccessor, childScopeId, registryId, node
2351
2338
  if (nodeAccessor !== void 0) writeScope(parentScopeId, { [BranchScopes + nodeAccessor]: childScope });
2352
2339
  }
2353
2340
  function writeScopePassive(scopeId, partialScope) {
2354
- const target = $chunk.serializeState;
2341
+ const target = $chunk.channel;
2355
2342
  const scope = _scope_with_id(scopeId);
2356
- const passive = target.passiveScopes ||= {};
2357
2343
  Object.assign(scope, partialScope);
2358
- passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
2344
+ $chunk.boundary.state.queuePassiveScope(target, scopeId, partialScope);
2359
2345
  return scope;
2360
2346
  }
2361
- function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
2362
- if (display) {
2363
- if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
2364
- } else $chunk.writeHTML("<t hidden>");
2365
- }
2366
- function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2367
- const branchId = _scope_id();
2368
- const wrap = !display;
2369
- if (wrap) $chunk.writeHTML("</t>");
2370
- writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
2371
- }
2372
- function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2373
- forBranches(by, (each) => each ? forOf(list, (item, index) => {
2374
- const itemKey = forOfBy(by, item, index);
2375
- each(itemKey, itemKey === index, () => cb(item, index));
2376
- }) : forOf(list, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2377
- }
2378
- function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2379
- forBranches(by, (each) => each ? forIn(obj, (key, value) => {
2380
- each(forInBy(by, key, value), false, () => cb(key, value));
2381
- }) : forIn(obj, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2382
- }
2383
- function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2384
- forBranches(by, (each) => {
2385
- let index = 0;
2386
- return each ? forTo(to, from, step, (value) => {
2387
- const itemKey = forStepBy(by, value);
2388
- each(itemKey, itemKey === index++, () => cb(value));
2389
- }) : forTo(to, from, step, cb);
2390
- }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2391
- }
2392
- function _for_until(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2393
- forBranches(by, (each) => {
2394
- let index = 0;
2395
- return each ? forUntil(to, from, step, (value) => {
2396
- const itemKey = forStepBy(by, value);
2397
- each(itemKey, itemKey === index++, () => cb(value));
2398
- }) : forUntil(to, from, step, cb);
2399
- }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2400
- }
2401
- function forBranches(by, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2402
- if (by) {
2403
- const run = iterate;
2404
- const seenKeys = /* @__PURE__ */ new Set();
2405
- iterate = (each) => run((itemKey, sameAsIndex, render) => {
2406
- assertValidLoopKey(itemKey, seenKeys);
2407
- if (each) each(itemKey, sameAsIndex, render);
2408
- else render();
2409
- });
2410
- }
2411
- if (branchGuard === 0) {
2412
- iterate(0);
2413
- writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
2414
- return;
2415
- }
2416
- const { state } = $chunk.boundary;
2417
- const resumeKeys = markerGuard !== 0;
2418
- const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
2419
- let flushBranchIds = "";
2420
- let loopScopes;
2421
- iterate((itemKey, sameAsIndex, render) => {
2422
- const branchId = _peek_scope_id();
2423
- if (resumeMarker) {
2424
- if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
2425
- else {
2426
- $chunk.writeHTML(state.mark("[", flushBranchIds));
2427
- flushBranchIds = branchId + "";
2428
- }
2429
- }
2430
- withBranchId(branchId, () => {
2431
- render();
2432
- const branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { [LoopKey]: itemKey } : {});
2433
- if (!resumeMarker) loopScopes = push(loopScopes, branchScope);
2434
- });
2435
- });
2436
- if (loopScopes) writeScope(scopeId, { [BranchScopes + accessor]: loopScopes });
2437
- writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
2438
- }
2439
- function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2440
- const resumeBranch = branchGuard !== 0;
2441
- const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
2442
- const branchId = _peek_scope_id();
2443
- const chunk = $chunk;
2444
- const beforeBranch = resumeMarker && resumeBranch && !singleNode ? deferBranchStart(chunk) : void 0;
2445
- const branchIndex = resumeBranch ? withBranchId(branchId, cb) : cb();
2446
- const shouldWriteBranch = resumeBranch && branchIndex !== void 0;
2447
- if (beforeBranch !== void 0) applyBranchStart(chunk, beforeBranch, shouldWriteBranch);
2448
- if (shouldWriteBranch && (branchIndex || !resumeMarker)) writeScope(scopeId, {
2449
- [ConditionalRenderer + accessor]: branchIndex || void 0,
2450
- [BranchScopes + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
2451
- });
2452
- writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
2453
- }
2454
- function deferBranchStart(chunk) {
2455
- const beforeBranch = chunk.html;
2456
- chunk.html = "";
2457
- return beforeBranch;
2458
- }
2459
- function applyBranchStart(chunk, beforeBranch, rendered) {
2460
- chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
2461
- }
2462
- function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
2463
- return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
2464
- }
2465
- function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
2466
- const endTag = parentEndTag || "";
2467
- if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
2468
- const { state } = $chunk.boundary;
2469
- const mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
2470
- $chunk.writeHTML(mark + endTag);
2471
- } else if (markerGuard !== 0) $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
2472
- else $chunk.writeHTML(endTag);
2473
- }
2474
2347
  let writeScope = (scopeId, partialScope) => {
2475
2348
  const { state } = $chunk.boundary;
2476
- const target = $chunk.serializeState;
2349
+ const target = $chunk.channel;
2477
2350
  const scope = scopeWithId(state, scopeId);
2478
- const pending = target.writeScopes[scopeId];
2479
- state.needsMainRuntime = true;
2351
+ state.needsWalkerRuntime = true;
2480
2352
  countResumeWrite($chunk);
2353
+ writeAsyncVisits($chunk);
2481
2354
  Object.assign(scope, partialScope);
2482
- if (pending && pending !== partialScope) Object.assign(pending, partialScope);
2483
- else target.writeScopes[scopeId] = partialScope;
2484
- target.flushScopes = true;
2355
+ state.queueScope(target, scopeId, partialScope);
2485
2356
  return scope;
2486
2357
  };
2487
2358
  writeScope = ((writeScope) => (scopeId, partialScope, file, loc, vars) => {
@@ -2503,18 +2374,18 @@ function scopeWithId(state, scopeId) {
2503
2374
  }
2504
2375
  function _subscribe(subscribers, scope, resumeId, markerGuard) {
2505
2376
  if (subscribers) {
2506
- const { boundary, serializeState } = $chunk;
2377
+ const { boundary, channel } = $chunk;
2507
2378
  const { serializer } = boundary.state;
2508
- if (!serializeState.readyId && !serializer.written(subscribers)) subscribers.add(scope);
2379
+ if (!channel.readyId && !serializer.refs.has(subscribers)) subscribers.add(scope);
2509
2380
  else if (resumeId) _script(scope[K_SCOPE_ID], resumeId, markerGuard);
2510
- else serializer.writeCall(scope, subscribers, "add", serializeState);
2511
- if (boundary.withinCatch) (boundary.subscribed ||= []).push(subscribers, scope, serializeState);
2381
+ else queueCall(serializer, scope, subscribers, "add", channel);
2382
+ if (boundary.withinCatch) (boundary.subscribed ||= []).push(subscribers, scope, channel);
2512
2383
  }
2513
2384
  return scope;
2514
2385
  }
2515
- const CLIENT_ALL = 715827883;
2516
- function maskGroup(mask, group) {
2517
- return mask === 715827883 ? 1 : typeof mask === "number" ? group < 15 ? mask >>> 1 + 2 * group & 3 : 0 : mask[group] ?? 0;
2386
+ const ALL_GROUPS = 715827883;
2387
+ function getGroupReason(reason, group) {
2388
+ return reason === 715827883 ? 1 : typeof reason === "number" ? group < 15 ? reason >>> 1 + 2 * group & 3 : 0 : reason[group] ?? 0;
2518
2389
  }
2519
2390
  function _set_scope_reason(reason) {
2520
2391
  $chunk.boundary.state.scopeReason = reason;
@@ -2524,18 +2395,18 @@ function _scope_reason() {
2524
2395
  $chunk.boundary.state.scopeReason = void 0;
2525
2396
  return reason;
2526
2397
  }
2527
- function _write_if(condition, key) {
2528
- return condition && maskGroup(condition, key) ? 1 : void 0;
2398
+ function _write_if(reason, group) {
2399
+ return reason && getGroupReason(reason, group) ? 1 : void 0;
2529
2400
  }
2530
- function _write_guard(condition, key) {
2531
- return _write_if(condition, key) || 0;
2401
+ function _write_guard(reason, group) {
2402
+ return _write_if(reason, group) || 0;
2532
2403
  }
2533
2404
  function writeWaitReady(readyId, renderer, input) {
2534
2405
  const chunk = $chunk;
2535
2406
  const { boundary } = chunk;
2536
2407
  const body = new Chunk(boundary, null, chunk.context, {
2537
2408
  readyId,
2538
- parent: chunk.serializeState,
2409
+ parent: chunk.channel,
2539
2410
  resumes: "",
2540
2411
  writeScopes: {},
2541
2412
  flushScopes: false
@@ -2547,209 +2418,58 @@ function writeWaitReady(readyId, renderer, input) {
2547
2418
  body.deferOwnReady();
2548
2419
  chunk.deferredReady = push(chunk.deferredReady, body);
2549
2420
  } else {
2550
- bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
2421
+ bodyEnd.next = chunk.forkRest(boundary);
2551
2422
  chunk.next = body;
2552
2423
  }
2553
2424
  }
2554
- function _await(scopeId, accessor, promise, content, markerGuard) {
2555
- const resumeMarker = markerGuard !== 0;
2556
- if (!isPromise(promise)) {
2557
- if (resumeMarker) {
2558
- const branchId = _peek_scope_id();
2559
- $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
2560
- withBranchId(branchId, content, promise);
2561
- $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
2562
- } else content(promise);
2563
- return;
2564
- }
2565
- const chunk = $chunk;
2566
- const { boundary } = chunk;
2567
- const startId = _peek_scope_id();
2568
- const after = chunk.next = $chunk = chunk.fork(boundary, chunk.next);
2569
- chunk.async = true;
2570
- captureContext(chunk);
2571
- boundary.startAsync();
2572
- promise.then((value) => {
2573
- if (chunk.async) {
2574
- chunk.async = false;
2575
- if (!boundary.aborted) {
2576
- const { state } = boundary;
2577
- chunk.render(() => {
2578
- if (resumeMarker) {
2579
- const branchId = _peek_scope_id();
2580
- $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
2581
- withBranchId(branchId, () => withIsAsync({ parent: getAsyncContent(chunk) }, content, value));
2582
- $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
2583
- } else {
2584
- const renderedSince = _peek_scope_id() !== startId;
2585
- const async = { parent: getAsyncContent(chunk) };
2586
- withIsAsync(async, content, value);
2587
- async.visit = renderedSince && (after.html || after.next) ? $chunk.boundary.state.mark("]", scopeId + " " + accessor) : "";
2588
- if (async.resumed) $chunk.writeHTML(async.visit);
2589
- async.end = $chunk;
2590
- }
2591
- });
2592
- if (!chunk.async && boundary.pendingReorders?.delete(chunk)) state.reorder(chunk);
2593
- boundary.endAsync();
2594
- }
2595
- }
2596
- }, (err) => {
2597
- chunk.async = false;
2598
- boundary.abort(err);
2599
- });
2425
+ function deferBranchStart(chunk) {
2426
+ const beforeBranch = chunk.html;
2427
+ chunk.html = "";
2428
+ return beforeBranch;
2600
2429
  }
2601
- function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
2602
- const placeholderBranchId = placeholderContent ? _scope_id() : 0;
2603
- const branchId = _peek_scope_id();
2604
- const chunk = $chunk;
2605
- const { boundary } = chunk;
2606
- const { state } = boundary;
2607
- const { resumeWrites } = boundary;
2608
- const beforeBranch = deferBranchStart(chunk);
2609
- const renderers = () => writeTryRenderers(branchId, catchContent && _resume(catchContent, catchId), placeholderContent && _resume(placeholderContent, placeholderId));
2610
- const renderersWritten = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, branchId, renderers);
2611
- const rendered = chunk !== $chunk || boundary.resumeWrites !== resumeWrites;
2612
- applyBranchStart(chunk, beforeBranch, rendered);
2613
- if (!rendered) return;
2614
- if (!renderersWritten) renderers();
2615
- $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId));
2616
- }
2617
- function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
2618
- const chunk = $chunk;
2619
- const { boundary } = chunk;
2620
- const body = chunk.fork(boundary, null);
2621
- if (body === body.render(content)) {
2622
- chunk.append(body);
2623
- return;
2624
- }
2625
- chunk.next = $chunk = chunk.fork(boundary, chunk.next);
2626
- captureContext(chunk);
2627
- chunk.placeholder = {
2628
- body,
2629
- render: placeholder,
2630
- branchId,
2631
- scopeId,
2632
- placeholderBranchId
2633
- };
2634
- }
2635
- function tryBoundary(content, catchContent, branchId, renderers) {
2636
- const chunk = $chunk;
2637
- const { boundary } = chunk;
2638
- const { state } = boundary;
2639
- const catchBoundary = new Boundary(state, void 0, boundary);
2640
- if (catchContent) catchBoundary.withinCatch = true;
2641
- const body = chunk.fork(catchBoundary, null);
2642
- const bodyEnd = body.render(() => withBranchId(branchId, content));
2643
- if (catchBoundary.aborted) {
2644
- if (!catchContent) throw catchBoundary.reason;
2645
- catchContent(catchBoundary.reason);
2646
- return true;
2647
- }
2648
- if (body === bodyEnd) {
2649
- chunk.append(body);
2650
- return false;
2651
- }
2652
- const renderersAtSettle = !catchBoundary.resumeWrites;
2653
- const bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
2654
- chunk.next = body;
2655
- boundary.startAsync();
2656
- const reorderId = catchContent ? state.nextReorderId() : "";
2657
- if (reorderId) {
2658
- chunk.catchRange = {
2659
- id: reorderId,
2660
- end: bodyEnd
2661
- };
2662
- captureContext(chunk);
2663
- }
2664
- catchBoundary.onNext = () => {
2665
- if (boundary.aborted) return;
2666
- if (catchBoundary.aborted) {
2667
- if (!reorderId) {
2668
- boundary.abort(catchBoundary.reason);
2669
- return;
2670
- }
2671
- const streamed = !chunk.catchRange;
2672
- const catchChunk = chunk.fork(boundary, null);
2673
- chunk.catchRange = null;
2674
- if (!renderersAtSettle) catchChunk.render(clearTryRenderers, branchId);
2675
- const inOrder = catchChunk === catchChunk.render(catchContent, catchBoundary.reason);
2676
- if (boundary.aborted) return;
2677
- if (bodyEnd.consumed || !inOrder) catchChunk.reorderBranch = branchId;
2678
- if (bodyEnd.consumed) {
2679
- catchChunk.reorderId = reorderId;
2680
- state.reorder(catchChunk);
2681
- } else {
2682
- let reorder = null;
2683
- if (!inOrder) reorder = catchChunk;
2684
- else if (streamed) reorder = chunk.fork(boundary, null);
2685
- if (reorder) reorder.reorderId = reorderId;
2686
- const endMarker = state.mark("!", reorderId);
2687
- let cut = body;
2688
- while (cut.consumed) cut = cut.next;
2689
- cut.async = false;
2690
- cut.next = inOrder ? catchChunk : bodyNext;
2691
- cut.html = streamed ? endMarker : inOrder ? "" : state.mark("!^", reorderId) + endMarker;
2692
- cut.scripts = cut.effects = cut.lastEffect = "";
2693
- cut.placeholder = cut.reorderId = cut.catchRange = null;
2694
- cut.deferredReorder = reorder;
2695
- if (inOrder) catchChunk.next = bodyNext;
2696
- }
2697
- boundary.endAsync();
2698
- } else if (!catchBoundary.count) {
2699
- if (renderersAtSettle && catchBoundary.resumeWrites) bodyEnd.render(renderers);
2700
- chunk.catchRange = null;
2701
- boundary.endAsync();
2702
- } else boundary.onNext();
2703
- };
2704
- return renderersAtSettle;
2430
+ function applyBranchStart(chunk, beforeBranch, rendered) {
2431
+ chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
2705
2432
  }
2706
2433
  function unsubscribe(subscribed, serializer) {
2707
2434
  for (let i = 0; i < subscribed.length; i += 3) {
2708
2435
  const subscribers = subscribed[i];
2709
2436
  const scope = subscribed[i + 1];
2710
- if (!serializer.written(subscribers)) subscribers.delete(scope);
2711
- else if (!serializer.dropCall(scope, subscribers, "add")) serializer.writeCall(scope, subscribers, "delete", subscribed[i + 2]);
2437
+ if (!serializer.refs.has(subscribers)) subscribers.delete(scope);
2438
+ else {
2439
+ const channel = subscribed[i + 2];
2440
+ if (!dropQueuedCall(serializer, scope, subscribers, "add", channel)) queueCall(serializer, scope, subscribers, "delete", channel);
2441
+ }
2712
2442
  }
2713
2443
  }
2714
- function clearTryRenderers(branchId) {
2715
- writeScope(branchId, {
2716
- [CatchContent]: 0,
2717
- [PlaceholderContent]: _scope_with_id(branchId)["#PlaceholderContent"] && 0
2718
- });
2719
- }
2720
- function writeTryRenderers(branchId, catchContent, placeholderContent) {
2721
- writeScope(branchId, {
2722
- [CatchContent]: catchContent,
2723
- [PlaceholderContent]: placeholderContent
2724
- });
2725
- }
2726
2444
  const NOOP$2 = () => {};
2727
2445
  function countResumeWrite(chunk) {
2728
2446
  for (let boundary = chunk.boundary; boundary; boundary = boundary.parent) boundary.resumeWrites++;
2447
+ }
2448
+ function writeAsyncVisits(chunk) {
2729
2449
  for (let async = getAsyncContent(chunk); async && !async.resumed; async = async.parent) {
2730
2450
  async.resumed = true;
2731
2451
  async.end?.writeHTML(async.visit);
2732
2452
  }
2733
2453
  }
2734
2454
  function getAsyncContent(chunk) {
2735
- return chunk.context?.[kIsAsync];
2455
+ return chunk.context?.[kAsyncContent];
2736
2456
  }
2737
2457
  var State = class {
2738
2458
  tagId = 1;
2739
2459
  scopeId = 1;
2740
2460
  reorderId = 1;
2741
2461
  readyGate = 1;
2742
- hasGlobals = false;
2743
- needsMainRuntime = false;
2744
- hasMainRuntime = false;
2745
- hasReadyRuntime = false;
2462
+ hasWrittenGlobals = false;
2463
+ needsWalkerRuntime = false;
2464
+ hasWalkerRuntime = false;
2465
+ hasWrittenReady = false;
2746
2466
  hasReorderRuntime = false;
2747
2467
  hasWrittenResume = false;
2748
2468
  walkOnNextFlush = false;
2749
2469
  trailerHTML = "";
2750
2470
  resumes = "";
2751
2471
  nonceAttr = "";
2752
- serializer = new Serializer();
2472
+ serializer = new State$1();
2753
2473
  writeReorders = null;
2754
2474
  scopes = /* @__PURE__ */ new Map();
2755
2475
  scope = (scopeId) => scopeWithId(this, scopeId);
@@ -2762,7 +2482,7 @@ var State = class {
2762
2482
  this.$global = $global;
2763
2483
  if ($global.cspNonce) this.nonceAttr = " nonce" + attrAssignment($global.cspNonce);
2764
2484
  }
2765
- flushChunk(html, scripts, pending) {
2485
+ joinFlush(html, scripts, pending) {
2766
2486
  const { $global, nonceAttr } = this;
2767
2487
  const { __flush__ } = $global;
2768
2488
  if (scripts) html += "<script" + nonceAttr + ">" + scripts + "<\/script>";
@@ -2775,6 +2495,32 @@ var State = class {
2775
2495
  walkScript() {
2776
2496
  return this.runtimePrefix + ".w()";
2777
2497
  }
2498
+ addResumes(channel, resumes) {
2499
+ channel.resumes = concatSequence(channel.resumes, resumes);
2500
+ }
2501
+ queueScope(target, scopeId, partialScope) {
2502
+ const pending = target.writeScopes[scopeId];
2503
+ if (pending && pending !== partialScope) Object.assign(pending, partialScope);
2504
+ else target.writeScopes[scopeId] = partialScope;
2505
+ target.flushScopes = true;
2506
+ }
2507
+ queuePassiveScope(target, scopeId, partialScope) {
2508
+ const passive = target.passiveScopes ||= {};
2509
+ passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
2510
+ }
2511
+ queueEffect(scopeId, registryId) {
2512
+ this.needsWalkerRuntime = true;
2513
+ $chunk.writeEffect(scopeId, registryId);
2514
+ }
2515
+ serializeFlush(boundary) {
2516
+ flushSerializer(boundary, this);
2517
+ }
2518
+ runtimeScript() {
2519
+ return WALKER_RUNTIME_CODE + "(\"" + this.$global.runtimeId + "\")(\"" + this.$global.renderId + "\")";
2520
+ }
2521
+ keepsTryMarks(chunk, resumeWrites) {
2522
+ return chunk !== $chunk || chunk.boundary.resumeWrites !== resumeWrites;
2523
+ }
2778
2524
  resumeScript(resumes) {
2779
2525
  if (this.hasWrittenResume) return this.runtimePrefix + ".r.push(" + resumes + ")";
2780
2526
  this.hasWrittenResume = true;
@@ -2791,16 +2537,16 @@ var State = class {
2791
2537
  reorder(chunk) {
2792
2538
  if (this.writeReorders) this.writeReorders.push(chunk);
2793
2539
  else {
2794
- this.needsMainRuntime = true;
2540
+ this.needsWalkerRuntime = true;
2795
2541
  this.writeReorders = [chunk];
2796
2542
  }
2797
2543
  }
2798
- writeReady(id, resumes) {
2544
+ readyScript(id, resumes) {
2799
2545
  const readyKey = toObjectKey(id);
2800
2546
  if (this.readyIds?.has(id)) return this.readyAccess(readyKey) + ".push(" + resumes + ")";
2801
2547
  (this.readyIds ||= /* @__PURE__ */ new Set()).add(id);
2802
- if (this.hasReadyRuntime) return this.readyAccess(readyKey) + "=[" + resumes + "]";
2803
- this.hasReadyRuntime = true;
2548
+ if (this.hasWrittenReady) return this.readyAccess(readyKey) + "=[" + resumes + "]";
2549
+ this.hasWrittenReady = true;
2804
2550
  return this.runtimePrefix + ".b={" + readyKey + ":[" + resumes + "]}";
2805
2551
  }
2806
2552
  readyAccess(readyKey) {
@@ -2860,7 +2606,7 @@ var Boundary = class {
2860
2606
  this.abort(event.target.reason);
2861
2607
  }
2862
2608
  flush() {
2863
- if (!this.aborted) flushSerializer(this, this.state);
2609
+ if (!this.aborted) this.state.serializeFlush(this);
2864
2610
  return this.count ? 1 : this.aborted ? 2 : 0;
2865
2611
  }
2866
2612
  startAsync() {
@@ -2891,21 +2637,25 @@ var Chunk = class Chunk {
2891
2637
  boundary;
2892
2638
  next;
2893
2639
  context;
2894
- serializeState;
2895
- constructor(boundary, next, context, serializeState) {
2640
+ channel;
2641
+ constructor(boundary, next, context, channel) {
2896
2642
  this.boundary = boundary;
2897
2643
  this.next = next;
2898
2644
  this.context = context;
2899
- this.serializeState = serializeState;
2645
+ this.channel = channel;
2900
2646
  }
2901
2647
  fork(boundary, next) {
2902
- return new Chunk(boundary, next, this.context, this.serializeState);
2648
+ return new Chunk(boundary, next, this.context, this.channel);
2649
+ }
2650
+ forkRest(boundary) {
2651
+ return $chunk = this.fork(boundary, this.next);
2903
2652
  }
2904
2653
  writeHTML(html) {
2905
2654
  this.html += html;
2906
2655
  }
2907
2656
  writeEffect(scopeId, registryId) {
2908
2657
  countResumeWrite(this);
2658
+ writeAsyncVisits(this);
2909
2659
  if (this.lastEffect === registryId) this.effects = concatEffects(this.effects, scopeId + "");
2910
2660
  else {
2911
2661
  this.lastEffect = registryId;
@@ -2933,7 +2683,7 @@ var Chunk = class Chunk {
2933
2683
  return deferredReady;
2934
2684
  }
2935
2685
  deferOwnReady() {
2936
- if (this.serializeState.readyId && (this.effects || this.scripts || this.serializeState.flushScopes)) {
2686
+ if (this.channel.readyId && (this.effects || this.scripts || this.channel.flushScopes)) {
2937
2687
  const deferred = this.fork(this.boundary, null);
2938
2688
  deferred.effects = this.effects;
2939
2689
  deferred.scripts = this.scripts;
@@ -2983,12 +2733,12 @@ var Chunk = class Chunk {
2983
2733
  this.writeHTML(state.mark("!^", reorderId));
2984
2734
  const { effects } = this;
2985
2735
  const beforeBranch = deferBranchStart(this);
2986
- if (this.render(() => withBranchId(placeholderBranchId, placeholder.render)) !== this) this.boundary.abort(/* @__PURE__ */ new Error("An @placeholder cannot contain async content."));
2736
+ if (this.render(withBranchId, placeholderBranchId, placeholder.render) !== this) this.boundary.abort(/* @__PURE__ */ new Error("An @placeholder cannot contain async content."));
2987
2737
  if (this.boundary.aborted) return true;
2988
2738
  const stateful = this.effects !== effects;
2989
2739
  applyBranchStart(this, beforeBranch, stateful);
2990
2740
  if (stateful) {
2991
- this.render(() => writeScope(branchId, { [PlaceholderBranch]: scopeWithId(state, placeholderBranchId) }));
2741
+ this.render(writeScope, branchId, { [PlaceholderBranch]: scopeWithId(state, placeholderBranchId) });
2992
2742
  this.writeHTML(state.mark("]", scopeId + " " + (PlaceholderBranch + branchId) + " " + placeholderBranchId));
2993
2743
  dismissChunk(end, body).writeEffect(branchId, PLACEHOLDER_DISMISS_REGISTER_ID);
2994
2744
  }
@@ -3022,12 +2772,12 @@ var Chunk = class Chunk {
3022
2772
  let heldEffects = this.heldEffects;
3023
2773
  let deferredReady;
3024
2774
  this.heldEffects = null;
3025
- if (this.serializeState.readyId && this.effects) followHeldEffects(this);
2775
+ if (this.channel.readyId && this.effects) followHeldEffects(this);
3026
2776
  while (cur.next && !cur.async) {
3027
2777
  cur.markCatchRange();
3028
2778
  cur.queueDeferredReorder();
3029
2779
  html += cur.html;
3030
- if (cur.serializeState.readyId) deferredReady = push(deferredReady, cur);
2780
+ if (cur.channel.readyId) deferredReady = push(deferredReady, cur);
3031
2781
  else {
3032
2782
  if (cur.effects) {
3033
2783
  if (effectsEnd && effectsEnd.boundary !== cur.boundary) {
@@ -3045,7 +2795,7 @@ var Chunk = class Chunk {
3045
2795
  }
3046
2796
  cur.deferOwnReady();
3047
2797
  if (effects) {
3048
- if (cur.serializeState.readyId) heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
2798
+ if (cur.channel.readyId) heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
3049
2799
  else if (effectsEnd.boundary !== cur.boundary) {
3050
2800
  heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
3051
2801
  if (isWithin(cur.boundary, effectsEnd.boundary)) cur.lastEffect ||= effectsEnd.lastEffect;
@@ -3060,11 +2810,11 @@ var Chunk = class Chunk {
3060
2810
  cur.scripts = concatScripts(scripts, cur.scripts);
3061
2811
  return cur;
3062
2812
  }
3063
- render(content, val) {
2813
+ render(content, val, val2) {
3064
2814
  const prev = $chunk;
3065
2815
  $chunk = this;
3066
2816
  try {
3067
- content(val);
2817
+ content(val, val2);
3068
2818
  return $chunk;
3069
2819
  } catch (err) {
3070
2820
  this.boundary.abort(err);
@@ -3074,8 +2824,8 @@ var Chunk = class Chunk {
3074
2824
  }
3075
2825
  }
3076
2826
  flushReadyScripts(boundary, reservations, holdEffects) {
3077
- const { serializeState } = this;
3078
- const { readyId } = serializeState;
2827
+ const { channel } = this;
2828
+ const { readyId } = channel;
3079
2829
  let scripts = "";
3080
2830
  const held = this.takeDeferredReady();
3081
2831
  if (held) for (const chunk of Array.isArray(held) ? held : [held]) {
@@ -3085,46 +2835,46 @@ var Chunk = class Chunk {
3085
2835
  }
3086
2836
  if (readyId && !this.async) {
3087
2837
  const { state } = boundary;
3088
- flushSerializer(boundary, serializeState);
3089
- const deps = state.serializer.takeChannelDeps();
2838
+ flushSerializer(boundary, channel);
2839
+ const deps = takeChannelDeps(state.serializer);
3090
2840
  const effects = holdEffects ? "" : this.effects;
3091
- const { resumes } = serializeState;
2841
+ const { resumes } = channel;
3092
2842
  const chunkScripts = this.scripts;
3093
- serializeState.resumes = this.scripts = "";
2843
+ channel.resumes = this.scripts = "";
3094
2844
  if (effects) this.effects = this.lastEffect = "";
3095
2845
  if (resumes || effects) {
3096
- state.needsMainRuntime = true;
2846
+ state.needsWalkerRuntime = true;
3097
2847
  const batch = concatSequence(depsMarker(deps), concatSequence(resumes, effects && `"${effects}"`));
3098
2848
  if (reservations) {
3099
2849
  const gate = state.readyGate++;
3100
- reservations.push(state.writeReady(readyId, gate + ""));
2850
+ reservations.push(state.readyScript(readyId, gate + ""));
3101
2851
  scripts = concatScripts(scripts, "(b=>b.splice(b.indexOf(" + gate + "),1," + batch + "))(" + state.readyAccess(toObjectKey(readyId)) + ")");
3102
- } else scripts = concatScripts(scripts, state.writeReady(readyId, batch));
2852
+ } else scripts = concatScripts(scripts, state.readyScript(readyId, batch));
3103
2853
  }
3104
2854
  scripts = concatScripts(scripts, chunkScripts);
3105
2855
  }
3106
2856
  return scripts;
3107
2857
  }
3108
- flushScript(boundary) {
2858
+ flush(boundary) {
3109
2859
  const { state } = boundary;
3110
- const { $global, runtimePrefix } = state;
2860
+ const { runtimePrefix } = state;
3111
2861
  let needsWalk = state.walkOnNextFlush;
3112
2862
  if (needsWalk) state.walkOnNextFlush = false;
3113
2863
  flushSerializer(boundary, state);
3114
2864
  let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
3115
- for (let channel; !boundary.aborted && (channel = state.serializer.pendingReadyChannel());) {
3116
- const resumes = state.serializer.stringifyScopes([], boundary, channel);
3117
- const deps = state.serializer.takeChannelDeps();
3118
- state.needsMainRuntime = true;
3119
- readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
2865
+ for (let channel; !boundary.aborted && (channel = pendingReadyChannel(state.serializer));) {
2866
+ const resumes = stringifyScopes(state.serializer, [], boundary, channel);
2867
+ const deps = takeChannelDeps(state.serializer);
2868
+ state.needsWalkerRuntime = true;
2869
+ readyResumeScripts = concatScripts(readyResumeScripts, state.readyScript(channel.readyId, concatSequence(depsMarker(deps), resumes)));
3120
2870
  }
3121
2871
  if (readyResumeScripts) needsWalk = true;
3122
2872
  const effects = this.async ? "" : joinHeldEffects(this.takeHeldEffects(), this.effects);
3123
2873
  let { html, scripts } = this;
3124
2874
  if (html && state.hasReorderRuntime) html = state.mark("*", "") + html;
3125
- if (state.needsMainRuntime && !state.hasMainRuntime) {
3126
- state.hasMainRuntime = true;
3127
- scripts = concatScripts(scripts, WALKER_RUNTIME_CODE + "(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")");
2875
+ if (state.needsWalkerRuntime && !state.hasWalkerRuntime) {
2876
+ state.hasWalkerRuntime = true;
2877
+ scripts = concatScripts(scripts, state.runtimeScript());
3128
2878
  }
3129
2879
  scripts = concatScripts(scripts, readyResumeScripts);
3130
2880
  if (effects) {
@@ -3201,10 +2951,10 @@ var Chunk = class Chunk {
3201
2951
  }
3202
2952
  flushHTML(boundary) {
3203
2953
  const { state } = boundary;
3204
- this.flushScript(boundary);
2954
+ this.flush(boundary);
3205
2955
  const { html, scripts } = this;
3206
2956
  this.html = this.scripts = "";
3207
- return state.flushChunk(html, scripts, boundary.count);
2957
+ return state.joinFlush(html, scripts, boundary.count);
3208
2958
  }
3209
2959
  };
3210
2960
  function renderReorderPlaceholders(reorder, reorders) {
@@ -3226,7 +2976,7 @@ function followHeldEffects(chunk) {
3226
2976
  }
3227
2977
  }
3228
2978
  function lastHeldOf(held, cur) {
3229
- return cur.serializeState === held.serializeState && cur.boundary === held.boundary ? cur : held;
2979
+ return cur.channel === held.channel && cur.boundary === held.boundary ? cur : held;
3230
2980
  }
3231
2981
  function holdEffectsOn(heldEffects, chunk, effects) {
3232
2982
  chunk.effects = effects;
@@ -3237,7 +2987,7 @@ function isWithin(boundary, outer) {
3237
2987
  return !!boundary;
3238
2988
  }
3239
2989
  function holdReorderEffects(head, boundary, effects) {
3240
- if (!head.serializeState.readyId) {
2990
+ if (!head.channel.readyId) {
3241
2991
  if (head.effects) head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(head.boundary, null), head.effects);
3242
2992
  head.effects = head.lastEffect = "";
3243
2993
  }
@@ -3249,13 +2999,12 @@ function joinHeldEffects(heldEffects, effects) {
3249
2999
  function joinUncaught(joined, held) {
3250
3000
  return held.boundary.aborted ? joined : concatEffects(joined, held.effects);
3251
3001
  }
3252
- function flushSerializer(boundary, serializeState) {
3002
+ function flushSerializer(boundary, channel) {
3253
3003
  const { state } = boundary;
3254
3004
  const { serializer } = state;
3255
- const pending = serializer.pending(serializeState);
3256
- if (serializeState.flushScopes || pending) {
3257
- const { writeScopes, passiveScopes } = serializeState;
3258
- const isBlockingState = serializeState !== state;
3005
+ const pending = hasMatchingCalls(serializer, channel.readyId);
3006
+ if (channel.flushScopes || pending) {
3007
+ const { writeScopes, passiveScopes } = channel;
3259
3008
  const flushes = [];
3260
3009
  if (passiveScopes) for (const key in passiveScopes) {
3261
3010
  const props = writeScopes[key];
@@ -3264,8 +3013,8 @@ function flushSerializer(boundary, serializeState) {
3264
3013
  delete passiveScopes[key];
3265
3014
  }
3266
3015
  }
3267
- if (!isBlockingState && !state.hasGlobals) {
3268
- state.hasGlobals = true;
3016
+ if (!channel.readyId && !state.hasWrittenGlobals) {
3017
+ state.hasWrittenGlobals = true;
3269
3018
  const globals = getFilteredGlobals(state.$global);
3270
3019
  if (globals) flushes.push([
3271
3020
  0,
@@ -3283,11 +3032,11 @@ function flushSerializer(boundary, serializeState) {
3283
3032
  ]);
3284
3033
  }
3285
3034
  if (flushes.length || pending) {
3286
- if (isBlockingState && !state.hasGlobals) flushSerializerGlobals(boundary);
3287
- serializeState.resumes = concatSequence(serializeState.resumes, serializer.stringifyScopes(flushes, boundary, serializeState));
3035
+ if (channel.readyId && !state.hasWrittenGlobals) flushSerializerGlobals(boundary);
3036
+ state.addResumes(channel, stringifyScopes(serializer, flushes, boundary, channel));
3288
3037
  }
3289
- serializeState.writeScopes = {};
3290
- serializeState.flushScopes = false;
3038
+ channel.writeScopes = {};
3039
+ channel.flushScopes = false;
3291
3040
  if (pending) state.walkOnNextFlush = true;
3292
3041
  }
3293
3042
  }
@@ -3295,9 +3044,9 @@ function flushSerializerGlobals(boundary) {
3295
3044
  const { state } = boundary;
3296
3045
  const globals = getFilteredGlobals(state.$global);
3297
3046
  if (globals) {
3298
- state.hasGlobals = true;
3299
- state.needsMainRuntime = true;
3300
- state.resumes = concatSequence(state.resumes, state.serializer.stringifyScopes([[
3047
+ state.hasWrittenGlobals = true;
3048
+ state.needsWalkerRuntime = true;
3049
+ state.resumes = concatSequence(state.resumes, stringifyScopes(state.serializer, [[
3301
3050
  0,
3302
3051
  globals,
3303
3052
  globals
@@ -3455,7 +3204,7 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, m
3455
3204
  const beforeBranch = shouldResume ? deferBranchStart(chunk) : void 0;
3456
3205
  const render = () => {
3457
3206
  if (renderer) try {
3458
- _set_scope_reason(shouldResume ? CLIENT_ALL : 0);
3207
+ _set_scope_reason(shouldResume ? ALL_GROUPS : 0);
3459
3208
  return inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
3460
3209
  ...inputOrArgs,
3461
3210
  content
@@ -3487,10 +3236,10 @@ function _content_resume(id, fn, scopeId, locals) {
3487
3236
  return _resume(_content(id, fn, scopeId), id, scopeId, locals);
3488
3237
  }
3489
3238
  const patchDynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (patch) => {
3490
- _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, resume, tagVar) => {
3239
+ _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, markerGuard, tagVar) => {
3491
3240
  const patched = patch(tag, scopeId, accessor);
3492
3241
  if (patched !== tag) patched["id"] = tag;
3493
- return originalDynamicTag(scopeId, accessor, patched, input, content, inputIsArgs, resume, tagVar);
3242
+ return originalDynamicTag(scopeId, accessor, patched, input, content, inputIsArgs, markerGuard, tagVar);
3494
3243
  };
3495
3244
  })(_dynamic_tag);
3496
3245
  //#endregion
@@ -3775,7 +3524,7 @@ function writeLoadAsset(assetId, flush, triggers) {
3775
3524
  const g = $global();
3776
3525
  writeAsset(g, addAsset(g, assetId, flush, triggers));
3777
3526
  }
3778
- function withPageAssets(template, runtime, assetId, runtimeId) {
3527
+ function withPageAssets(template, flush, assetId, runtimeId) {
3779
3528
  return Object.assign((input) => {
3780
3529
  const g = $global();
3781
3530
  if (runtimeId) {
@@ -3784,7 +3533,7 @@ function withPageAssets(template, runtime, assetId, runtimeId) {
3784
3533
  g.runtimeId = runtimeId;
3785
3534
  } else if (g.runtimeId !== runtimeId) console.error(`A page entry compiled with runtimeId "${runtimeId}" is nested in a render using runtimeId "${g.runtimeId}", so its content cannot resume.`);
3786
3535
  }
3787
- const asset = addAsset(g, assetId, runtime);
3536
+ const asset = addAsset(g, assetId, flush);
3788
3537
  if (g.__flush__) {
3789
3538
  writeAsset(g, asset);
3790
3539
  return writeWaitReady(assetId, template, input);
@@ -3884,6 +3633,326 @@ function toObjectExpression(options) {
3884
3633
  const SET_SCOPE_REGISTER_ID = "$compat_setScope";
3885
3634
  const RENDER_BODY_ID = "$compat_renderBody";
3886
3635
  //#endregion
3636
+ //#region src/common/for.ts
3637
+ function forIn(obj, cb) {
3638
+ for (const key in obj) cb(key, obj[key]);
3639
+ }
3640
+ function forOf(list, cb) {
3641
+ assertValidList(list);
3642
+ if (list) {
3643
+ let i = 0;
3644
+ for (const item of list) cb(item, i++);
3645
+ }
3646
+ }
3647
+ function forTo(to, from, step, cb) {
3648
+ assertValidRangeBound("to", to);
3649
+ assertOptionalRangeNumber("from", from);
3650
+ assertOptionalRangeNumber("step", step);
3651
+ const start = from || 0;
3652
+ const delta = step || 1;
3653
+ for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
3654
+ }
3655
+ function forUntil(until, from, step, cb) {
3656
+ assertValidRangeBound("until", until);
3657
+ assertOptionalRangeNumber("from", from);
3658
+ assertOptionalRangeNumber("step", step);
3659
+ const start = from || 0;
3660
+ const delta = step || 1;
3661
+ for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
3662
+ }
3663
+ //#endregion
3664
+ //#region src/html/for.ts
3665
+ function forOfBy(by, item, index) {
3666
+ return by ? typeof by === "string" ? item[by] : by(item, index) : index;
3667
+ }
3668
+ function forInBy(by, name, value) {
3669
+ return by ? by(name, value) : name;
3670
+ }
3671
+ function forStepBy(by, index) {
3672
+ return by ? by(index) : index;
3673
+ }
3674
+ //#endregion
3675
+ //#region src/html/control-flow.ts
3676
+ function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
3677
+ if (display) {
3678
+ if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
3679
+ } else $chunk.writeHTML("<t hidden>");
3680
+ }
3681
+ function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
3682
+ const branchId = _scope_id();
3683
+ const wrap = !display;
3684
+ if (wrap) $chunk.writeHTML("</t>");
3685
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
3686
+ }
3687
+ function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
3688
+ forBranches(by, cb, iterateForOf(list, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
3689
+ }
3690
+ function iterateForOf(list, cb, by) {
3691
+ return (each) => each ? forOf(list, (item, index) => {
3692
+ const itemKey = forOfBy(by, item, index);
3693
+ each(itemKey, itemKey === index, item, index);
3694
+ }) : forOf(list, cb);
3695
+ }
3696
+ function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
3697
+ forBranches(by, cb, iterateForIn(obj, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
3698
+ }
3699
+ function iterateForIn(obj, cb, by) {
3700
+ return (each) => each ? forIn(obj, (key, value) => {
3701
+ each(forInBy(by, key, value), false, key, value);
3702
+ }) : forIn(obj, cb);
3703
+ }
3704
+ function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
3705
+ forBranches(by, cb, iterateForTo(to, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
3706
+ }
3707
+ function iterateForTo(to, from, step, cb, by) {
3708
+ return (each) => {
3709
+ let index = 0;
3710
+ return each ? forTo(to, from, step, (value) => {
3711
+ const itemKey = forStepBy(by, value);
3712
+ each(itemKey, itemKey === index++, value);
3713
+ }) : forTo(to, from, step, cb);
3714
+ };
3715
+ }
3716
+ function _for_until(until, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
3717
+ forBranches(by, cb, iterateForUntil(until, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
3718
+ }
3719
+ function iterateForUntil(until, from, step, cb, by) {
3720
+ return (each) => {
3721
+ let index = 0;
3722
+ return each ? forUntil(until, from, step, (value) => {
3723
+ const itemKey = forStepBy(by, value);
3724
+ each(itemKey, itemKey === index++, value);
3725
+ }) : forUntil(until, from, step, cb);
3726
+ };
3727
+ }
3728
+ function checkLoopKeys(cb, iterate) {
3729
+ const seenKeys = /* @__PURE__ */ new Set();
3730
+ return (each) => iterate((itemKey, sameAsIndex, a, b) => {
3731
+ assertValidLoopKey(itemKey, seenKeys);
3732
+ if (each) each(itemKey, sameAsIndex, a, b);
3733
+ else cb(a, b);
3734
+ });
3735
+ }
3736
+ function forBranches(by, cb, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
3737
+ if (by) iterate = checkLoopKeys(cb, iterate);
3738
+ if (branchGuard === 0) {
3739
+ iterate(0);
3740
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
3741
+ return;
3742
+ }
3743
+ const { state } = $chunk.boundary;
3744
+ const resumeKeys = markerGuard !== 0;
3745
+ const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
3746
+ let flushBranchIds = "";
3747
+ let loopScopes;
3748
+ iterate((itemKey, sameAsIndex, a, b) => {
3749
+ const branchId = _peek_scope_id();
3750
+ if (resumeMarker) {
3751
+ if (singleNode) flushBranchIds = " " + branchId + flushBranchIds;
3752
+ else {
3753
+ $chunk.writeHTML(state.mark("[", flushBranchIds));
3754
+ flushBranchIds = branchId + "";
3755
+ }
3756
+ }
3757
+ withBranchId(branchId, cb, a, b);
3758
+ const branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { [LoopKey]: itemKey } : {});
3759
+ if (!resumeMarker) loopScopes = push(loopScopes, branchScope);
3760
+ });
3761
+ if (loopScopes) writeScope(scopeId, { [BranchScopes + accessor]: loopScopes });
3762
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
3763
+ }
3764
+ function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
3765
+ const resumeBranch = branchGuard !== 0;
3766
+ const resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag);
3767
+ const branchId = _peek_scope_id();
3768
+ const chunk = $chunk;
3769
+ const beforeBranch = resumeMarker && resumeBranch && !singleNode ? deferBranchStart(chunk) : void 0;
3770
+ const branchIndex = resumeBranch ? withBranchId(branchId, cb) : cb();
3771
+ const shouldWriteBranch = resumeBranch && branchIndex !== void 0;
3772
+ if (beforeBranch !== void 0) applyBranchStart(chunk, beforeBranch, shouldWriteBranch);
3773
+ if (shouldWriteBranch && (branchIndex || !resumeMarker)) writeScope(scopeId, {
3774
+ [ConditionalRenderer + accessor]: branchIndex || void 0,
3775
+ [BranchScopes + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
3776
+ });
3777
+ writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
3778
+ }
3779
+ function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
3780
+ return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
3781
+ }
3782
+ function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
3783
+ const endTag = parentEndTag || "";
3784
+ if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
3785
+ const { state } = $chunk.boundary;
3786
+ const mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
3787
+ $chunk.writeHTML(mark + endTag);
3788
+ } else if (markerGuard !== 0) $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
3789
+ else $chunk.writeHTML(endTag);
3790
+ }
3791
+ function _await(scopeId, accessor, promise, content, markerGuard) {
3792
+ const resumeMarker = markerGuard !== 0;
3793
+ if (!isPromise(promise)) {
3794
+ if (resumeMarker) {
3795
+ const branchId = _peek_scope_id();
3796
+ $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
3797
+ withBranchId(branchId, content, promise);
3798
+ $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
3799
+ } else content(promise);
3800
+ return;
3801
+ }
3802
+ const chunk = $chunk;
3803
+ const { boundary } = chunk;
3804
+ const startId = _peek_scope_id();
3805
+ const after = chunk.next = chunk.forkRest(boundary);
3806
+ chunk.async = true;
3807
+ captureContext(chunk);
3808
+ boundary.startAsync();
3809
+ promise.then((value) => {
3810
+ if (chunk.async) {
3811
+ chunk.async = false;
3812
+ if (!boundary.aborted) {
3813
+ const { state } = boundary;
3814
+ chunk.render(() => {
3815
+ if (resumeMarker) {
3816
+ const branchId = _peek_scope_id();
3817
+ $chunk.writeHTML($chunk.boundary.state.mark("[", ""));
3818
+ withBranchId(branchId, () => withAsyncContent({ parent: getAsyncContent(chunk) }, content, value));
3819
+ $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
3820
+ } else {
3821
+ const renderedSince = _peek_scope_id() !== startId;
3822
+ const async = { parent: getAsyncContent(chunk) };
3823
+ withAsyncContent(async, content, value);
3824
+ async.visit = renderedSince && (after.html || after.next) ? $chunk.boundary.state.mark("]", scopeId + " " + accessor) : "";
3825
+ if (async.resumed) $chunk.writeHTML(async.visit);
3826
+ async.end = $chunk;
3827
+ }
3828
+ });
3829
+ if (!chunk.async && boundary.pendingReorders?.delete(chunk)) state.reorder(chunk);
3830
+ boundary.endAsync();
3831
+ }
3832
+ }
3833
+ }, (err) => {
3834
+ chunk.async = false;
3835
+ boundary.abort(err);
3836
+ });
3837
+ }
3838
+ function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
3839
+ const placeholderBranchId = placeholderContent ? _scope_id() : 0;
3840
+ const branchId = _peek_scope_id();
3841
+ const chunk = $chunk;
3842
+ const { boundary } = chunk;
3843
+ const { state } = boundary;
3844
+ const { resumeWrites } = boundary;
3845
+ const beforeBranch = deferBranchStart(chunk);
3846
+ const renderers = () => writeTryRenderers(branchId, catchContent && _resume(catchContent, catchId), placeholderContent && _resume(placeholderContent, placeholderId));
3847
+ const writesRenderers = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, branchId, renderers);
3848
+ const keepsMarks = state.keepsTryMarks(chunk, resumeWrites);
3849
+ applyBranchStart(chunk, beforeBranch, keepsMarks);
3850
+ if (!keepsMarks) return;
3851
+ if (!writesRenderers) renderers();
3852
+ $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId));
3853
+ }
3854
+ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
3855
+ const chunk = $chunk;
3856
+ const { boundary } = chunk;
3857
+ const body = chunk.fork(boundary, null);
3858
+ if (body === body.render(content)) {
3859
+ chunk.append(body);
3860
+ return;
3861
+ }
3862
+ chunk.next = chunk.forkRest(boundary);
3863
+ captureContext(chunk);
3864
+ chunk.placeholder = {
3865
+ body,
3866
+ render: placeholder,
3867
+ branchId,
3868
+ scopeId,
3869
+ placeholderBranchId
3870
+ };
3871
+ }
3872
+ function tryBoundary(content, catchContent, branchId, renderers) {
3873
+ const chunk = $chunk;
3874
+ const { boundary } = chunk;
3875
+ const { state } = boundary;
3876
+ const bodyBoundary = new Boundary(state, void 0, boundary);
3877
+ if (catchContent) bodyBoundary.withinCatch = true;
3878
+ const body = chunk.fork(bodyBoundary, null);
3879
+ const bodyEnd = body.render(withBranchId, branchId, content);
3880
+ if (bodyBoundary.aborted) {
3881
+ if (!catchContent) throw bodyBoundary.reason;
3882
+ catchContent(bodyBoundary.reason);
3883
+ return true;
3884
+ }
3885
+ if (body === bodyEnd) {
3886
+ chunk.append(body);
3887
+ return false;
3888
+ }
3889
+ const renderersAtSettle = !bodyBoundary.resumeWrites;
3890
+ const bodyNext = bodyEnd.next = chunk.forkRest(boundary);
3891
+ chunk.next = body;
3892
+ boundary.startAsync();
3893
+ const reorderId = catchContent ? state.nextReorderId() : "";
3894
+ if (reorderId) {
3895
+ chunk.catchRange = {
3896
+ id: reorderId,
3897
+ end: bodyEnd
3898
+ };
3899
+ captureContext(chunk);
3900
+ }
3901
+ bodyBoundary.onNext = () => {
3902
+ if (boundary.aborted) return;
3903
+ if (bodyBoundary.aborted) {
3904
+ if (!reorderId) {
3905
+ boundary.abort(bodyBoundary.reason);
3906
+ return;
3907
+ }
3908
+ const streamed = !chunk.catchRange;
3909
+ const catchChunk = chunk.fork(boundary, null);
3910
+ chunk.catchRange = null;
3911
+ if (!renderersAtSettle) catchChunk.render(clearTryRenderers, branchId);
3912
+ const inOrder = catchChunk === catchChunk.render(catchContent, bodyBoundary.reason);
3913
+ if (boundary.aborted) return;
3914
+ if (bodyEnd.consumed || !inOrder) catchChunk.reorderBranch = branchId;
3915
+ if (bodyEnd.consumed) {
3916
+ catchChunk.reorderId = reorderId;
3917
+ state.reorder(catchChunk);
3918
+ } else {
3919
+ let reorder = null;
3920
+ if (!inOrder) reorder = catchChunk;
3921
+ else if (streamed) reorder = chunk.fork(boundary, null);
3922
+ if (reorder) reorder.reorderId = reorderId;
3923
+ const endMarker = state.mark("!", reorderId);
3924
+ let cut = body;
3925
+ while (cut.consumed) cut = cut.next;
3926
+ cut.async = false;
3927
+ cut.next = inOrder ? catchChunk : bodyNext;
3928
+ cut.html = streamed ? endMarker : inOrder ? "" : state.mark("!^", reorderId) + endMarker;
3929
+ cut.scripts = cut.effects = cut.lastEffect = "";
3930
+ cut.placeholder = cut.reorderId = cut.catchRange = null;
3931
+ cut.deferredReorder = reorder;
3932
+ if (inOrder) catchChunk.next = bodyNext;
3933
+ }
3934
+ boundary.endAsync();
3935
+ } else if (!bodyBoundary.count) {
3936
+ if (renderersAtSettle && bodyBoundary.resumeWrites) bodyEnd.render(renderers);
3937
+ chunk.catchRange = null;
3938
+ boundary.endAsync();
3939
+ } else boundary.onNext();
3940
+ };
3941
+ return renderersAtSettle;
3942
+ }
3943
+ function clearTryRenderers(branchId) {
3944
+ writeScope(branchId, {
3945
+ [CatchContent]: 0,
3946
+ [PlaceholderContent]: _scope_with_id(branchId)["#PlaceholderContent"] && 0
3947
+ });
3948
+ }
3949
+ function writeTryRenderers(branchId, catchContent, placeholderContent) {
3950
+ writeScope(branchId, {
3951
+ [CatchContent]: catchContent,
3952
+ [PlaceholderContent]: placeholderContent
3953
+ });
3954
+ }
3955
+ //#endregion
3887
3956
  //#region src/html/compat.ts
3888
3957
  const K_TAGS_API_STATE = Symbol();
3889
3958
  const COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap();
@@ -3932,7 +4001,7 @@ const compat = {
3932
4001
  return function toJSON() {
3933
4002
  let compatRegistered = COMPAT_REGISTRY.get(this);
3934
4003
  if (!compatRegistered) {
3935
- const registered = getRegistered(this);
4004
+ const registered = REGISTRY.get(this);
3936
4005
  if (registered) {
3937
4006
  const scopeId = registered.scope ? getScopeId(registered.scope) : void 0;
3938
4007
  if (scopeId !== void 0) _script(scopeId, SET_SCOPE_REGISTER_ID);
@@ -3976,7 +4045,7 @@ const compat = {
3976
4045
  let html = "";
3977
4046
  let scripts = "";
3978
4047
  if (reorders) for (const reorder of reorders) state.reorder(reorder);
3979
- if (boundary.flush() === 0) ({html, scripts} = chunk.flushScript(boundary));
4048
+ if (boundary.flush() === 0) ({html, scripts} = chunk.flush(boundary));
3980
4049
  if (boundary.aborted) throw boundary.reason;
3981
4050
  if (boundary.count) throw new Error("Cannot serialize promise across tags/class compat layer.");
3982
4051
  return {
@@ -4013,7 +4082,7 @@ const compat = {
4013
4082
  }
4014
4083
  });
4015
4084
  head.render(() => {
4016
- _set_scope_reason(willRerender ? CLIENT_ALL : 0);
4085
+ _set_scope_reason(willRerender ? ALL_GROUPS : 0);
4017
4086
  try {
4018
4087
  renderer(normalizedInput);
4019
4088
  } finally {
@@ -4061,7 +4130,7 @@ const compat = {
4061
4130
  registerClassFunctions(input) {
4062
4131
  for (const key in input) {
4063
4132
  const value = input[key];
4064
- if (typeof value === "function" && !getRegistered(value)) register(RENDER_BODY_ID, value);
4133
+ if (typeof value === "function" && !REGISTRY.has(value)) register(RENDER_BODY_ID, value);
4065
4134
  }
4066
4135
  },
4067
4136
  registerClassFunction($global, id, fn, hostId) {