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