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
package/dist/html.js CHANGED
@@ -245,10 +245,10 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
245
245
  if (ch === "\0") return "\\x00";
246
246
  let code = ch.charCodeAt(0);
247
247
  return code >= 55296 && code <= 57343 ? "\\u" + code.toString(16).padStart(4, "0") : match;
248
- }, unsafeQuoteReg = /["\\<\n\r\u2028\u2029\0\ud800-\udfff]/u, kSelectedValue = Symbol("selectedValue"), checkedValuesRefs = /* @__PURE__ */ new WeakMap(), singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g, doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g, needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g, $chunk, kPendingContexts = Symbol("Pending Contexts"), kBranchId = Symbol("Branch Id"), kIsAsync = Symbol("Is Async"), writeScope = (scopeId, partialScope) => {
249
- let { state } = $chunk.boundary, target = $chunk.serializeState, scope = scopeWithId(state, scopeId), pending = target.writeScopes[scopeId];
250
- return state.needsMainRuntime = !0, countResumeWrite($chunk), Object.assign(scope, partialScope), pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0, scope;
251
- }, CLIENT_ALL = 715827883, NOOP$2 = () => {}, tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb)), tickQueue, unsafeXMLReg = /[<&\r]/g, replaceUnsafeXML = (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&#13;", escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str, unsafeScriptReg = /<(\/?script|!--)/gi, escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\u003C$1") : str, unsafeScriptTemplateLiteralReg = /[`\\\r]|\$\{|<(?=\/?script|!--)/gi, replaceUnsafeScriptTemplateLiteral = (c) => c === "<" ? "\\x3C" : c === "\r" ? "\\r" : "\\" + c, quoteScriptTemplateLiteral = (str) => "`" + (unsafeScriptTemplateLiteralReg.test(str) ? str.replace(unsafeScriptTemplateLiteralReg, replaceUnsafeScriptTemplateLiteral) : str) + "`", unsafeStyleReg = /<(\/style)/gi, escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str, unsafeCommentReg = />/g, voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, markerGuard, tagVar) => {
248
+ }, unsafeQuoteReg = /["\\<\n\r\u2028\u2029\0\ud800-\udfff]/u, kSelectedValue = Symbol("selectedValue"), checkedValuesRefs = /* @__PURE__ */ new WeakMap(), singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g, doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g, needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g, $chunk, kPendingContexts = Symbol("Pending Contexts"), kBranchId = Symbol("Branch Id"), kAsyncContent = Symbol("Async Content"), writeScope = (scopeId, partialScope) => {
249
+ let { state } = $chunk.boundary, target = $chunk.channel, scope = scopeWithId(state, scopeId);
250
+ return state.needsWalkerRuntime = !0, countResumeWrite($chunk), writeAsyncVisits($chunk), Object.assign(scope, partialScope), state.queueScope(target, scopeId, partialScope), scope;
251
+ }, ALL_GROUPS = 715827883, NOOP$2 = () => {}, tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb)), tickQueue, unsafeXMLReg = /[<&\r]/g, replaceUnsafeXML = (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&#13;", escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str, unsafeScriptReg = /<(\/?script|!--)/gi, escapeScriptStr = (str) => unsafeScriptReg.test(str) ? str.replace(unsafeScriptReg, "\\u003C$1") : str, unsafeScriptTemplateLiteralReg = /[`\\\r]|\$\{|<(?=\/?script|!--)/gi, replaceUnsafeScriptTemplateLiteral = (c) => c === "<" ? "\\x3C" : c === "\r" ? "\\r" : "\\" + c, quoteScriptTemplateLiteral = (str) => "`" + (unsafeScriptTemplateLiteralReg.test(str) ? str.replace(unsafeScriptTemplateLiteralReg, replaceUnsafeScriptTemplateLiteral) : str) + "`", unsafeStyleReg = /<(\/style)/gi, escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str, unsafeCommentReg = />/g, voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, markerGuard, tagVar) => {
252
252
  let shouldResume = markerGuard !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = _peek_scope_id(), rendered, result;
253
253
  if (typeof renderer == "string") {
254
254
  let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
@@ -268,7 +268,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
268
268
  } else {
269
269
  let chunk = getChunk(), beforeBranch = shouldResume ? deferBranchStart(chunk) : void 0, render = () => {
270
270
  if (renderer) try {
271
- return _set_scope_reason(shouldResume ? CLIENT_ALL : 0), inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
271
+ return _set_scope_reason(shouldResume ? ALL_GROUPS : 0), inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
272
272
  ...inputOrArgs,
273
273
  content
274
274
  } : inputOrArgs);
@@ -281,9 +281,9 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
281
281
  }
282
282
  return rendered ? shouldResume && writeScope(scopeId, { ["D" + accessor]: rendererKey(renderer) }) : _scope_id(), result;
283
283
  }, patchDynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (patch) => {
284
- _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, resume, tagVar) => {
284
+ _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, markerGuard, tagVar) => {
285
285
  let patched = patch(tag, scopeId, accessor);
286
- return patched !== tag && (patched.a = tag), originalDynamicTag(scopeId, accessor, patched, input, content, inputIsArgs, resume, tagVar);
286
+ return patched !== tag && (patched.a = tag), originalDynamicTag(scopeId, accessor, patched, input, content, inputIsArgs, markerGuard, tagVar);
287
287
  };
288
288
  })(_dynamic_tag), CONSUMED_RESULT_MESSAGE = "Cannot read from a consumed render result", _template = (templateId, renderer, page) => (renderer.render = render, renderer.i = !page, renderer._ = renderer, _content_resume(templateId, renderer)), kAssets = Symbol(), kHead = Symbol(), SET_SCOPE_REGISTER_ID = "$C_s", RENDER_BODY_ID = "$C_b", K_TAGS_API_STATE = Symbol(), COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap(), compat = {
289
289
  $global,
@@ -321,7 +321,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
321
321
  return function() {
322
322
  let compatRegistered = COMPAT_REGISTRY.get(this);
323
323
  if (!compatRegistered) {
324
- let registered = getRegistered(this);
324
+ let registered = REGISTRY.get(this);
325
325
  if (registered) {
326
326
  let scopeId = registered.scope ? getScopeId(registered.scope) : void 0;
327
327
  scopeId !== void 0 && _script(scopeId, SET_SCOPE_REGISTER_ID), COMPAT_REGISTRY.set(this, compatRegistered = [registered.id, scopeId]);
@@ -353,7 +353,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
353
353
  flushScript(chunk, reorders) {
354
354
  let { boundary } = chunk, { state } = boundary, html = "", scripts = "";
355
355
  if (reorders) for (let reorder of reorders) state.reorder(reorder);
356
- if (boundary.flush() === 0 && ({html, scripts} = chunk.flushScript(boundary)), boundary.aborted) throw boundary.reason;
356
+ if (boundary.flush() === 0 && ({html, scripts} = chunk.flush(boundary)), boundary.aborted) throw boundary.reason;
357
357
  if (boundary.count) throw Error("Cannot serialize promise across tags/class compat layer.");
358
358
  return {
359
359
  html,
@@ -380,7 +380,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
380
380
  writeScope(scopeId, { m5c: component.id }), _script(scopeId, SET_SCOPE_REGISTER_ID);
381
381
  }
382
382
  }), head.render(() => {
383
- _set_scope_reason(willRerender ? CLIENT_ALL : 0);
383
+ _set_scope_reason(willRerender ? ALL_GROUPS : 0);
384
384
  try {
385
385
  renderer(normalizedInput);
386
386
  } finally {
@@ -413,7 +413,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
413
413
  registerClassFunctions(input) {
414
414
  for (let key in input) {
415
415
  let value = input[key];
416
- typeof value == "function" && !getRegistered(value) && register(RENDER_BODY_ID, value);
416
+ typeof value == "function" && !REGISTRY.has(value) && register(RENDER_BODY_ID, value);
417
417
  }
418
418
  },
419
419
  registerClassFunction($global, id, fn, hostId) {
@@ -441,10 +441,10 @@ function* attrTagIterator() {
441
441
  }
442
442
  //#endregion
443
443
  //#region src/common/helpers.ts
444
- function stringifyClassObject(name, value) {
444
+ function stringifyClassEntry(name, value) {
445
445
  return value ? name : "";
446
446
  }
447
- function stringifyStyleObject(name, value) {
447
+ function stringifyStyleEntry(name, value) {
448
448
  return value || value === 0 ? escapeStyleAttr(name) + ":" + escapeStyleAttr(value + "") : "";
449
449
  }
450
450
  function escapeStyleAttr(str) {
@@ -458,17 +458,17 @@ function escapeStyleValue(str) {
458
458
  function isEventHandler(name) {
459
459
  return /^on[A-Z-]/.test(name);
460
460
  }
461
- function getEventHandlerName(name) {
461
+ function getEventType(name) {
462
462
  return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
463
463
  }
464
464
  function hasKeys(obj) {
465
465
  for (let _ in obj) return !0;
466
466
  return !1;
467
467
  }
468
- function isVoid(value) {
468
+ function isNullishOrFalse(value) {
469
469
  return value == null || value === !1;
470
470
  }
471
- function isNotVoid(value) {
471
+ function isNotNullishOrFalse(value) {
472
472
  return value != null && value !== !1;
473
473
  }
474
474
  function isPromise(value) {
@@ -488,25 +488,6 @@ function _el_read_error() {}
488
488
  function _hoist_read_error() {}
489
489
  function _assert_hoist(value) {}
490
490
  //#endregion
491
- //#region src/common/for.ts
492
- function forIn(obj, cb) {
493
- for (let key in obj) cb(key, obj[key]);
494
- }
495
- function forOf(list, cb) {
496
- if (list) {
497
- let i = 0;
498
- for (let item of list) cb(item, i++);
499
- }
500
- }
501
- function forTo(to, from, step, cb) {
502
- let start = from || 0, delta = step || 1;
503
- for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
504
- }
505
- function forUntil(until, from, step, cb) {
506
- let start = from || 0, delta = step || 1;
507
- for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
508
- }
509
- //#endregion
510
491
  //#region src/common/opt.ts
511
492
  function reduce(opt, cb, acc) {
512
493
  if (opt) {
@@ -536,14 +517,44 @@ var State$1 = class {
536
517
  buf = [];
537
518
  strs = /* @__PURE__ */ new Map();
538
519
  refs = /* @__PURE__ */ new WeakMap();
539
- pendingAssignments = /* @__PURE__ */ new Set();
520
+ deferredRefs = /* @__PURE__ */ new Set();
540
521
  boundary;
541
522
  channel = void 0;
542
523
  channelDeps = null;
543
- mutated = [];
524
+ queuedCalls = [];
525
+ queuedReadyCalls = [];
526
+ scopeRef(scope, scopeId) {
527
+ return this.refs.get(scope) || newScopeReference(this, scope, scopeId);
528
+ }
529
+ writeScopeProps(props, ref) {
530
+ return writeObjectProps(this, props, ref);
531
+ }
532
+ scopesCursor(scopeId) {
533
+ return scopeId + ",";
534
+ }
535
+ writeTrailing(scopesIndex) {
536
+ let { buf } = this;
537
+ return ~scopesIndex && (buf[scopesIndex] = "_([" + buf[scopesIndex], buf.push("])")), writeDeferred(this), ",0)";
538
+ }
539
+ wrapPayload(result, extras) {
540
+ let arrow = this.wroteUndefined ? "(_,$)=>" : "_=>";
541
+ return this.wroteUndefined = !1, extras ? arrow + result : arrow + "[" + result + "]";
542
+ }
543
+ writeScopedRegistration(val, parent, accessor, registered) {
544
+ let ref = new Reference(parent, accessor, this.flushId, this.buf.length);
545
+ ref.channel = this.channel, this.refs.set(val, ref);
546
+ let scope = registered.scope, scopeId = scope[K_SCOPE_ID];
547
+ trackScope(this, scope, scopeId);
548
+ let locals = registered.locals?.(this.boundary.state.scope);
549
+ if (locals) {
550
+ this.buf.push(registered.access + "(_(" + scopeId + ")");
551
+ for (let local of locals) this.buf.push(","), writePlainObject(this, local, newArgReference(this, ref, local));
552
+ } else this.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
553
+ this.buf.push(")");
554
+ }
544
555
  }, Reference = class {
545
556
  assignments = null;
546
- calls = null;
557
+ deferredMembers = null;
547
558
  scopeId = void 0;
548
559
  channel = void 0;
549
560
  parent;
@@ -555,135 +566,121 @@ var State$1 = class {
555
566
  constructor(parent, accessor, flushId, pos = null, id = null) {
556
567
  this.parent = parent, this.accessor = accessor, this.flushId = flushId, this.pos = pos, this.id = id;
557
568
  }
558
- }, Serializer = class {
559
- #state = new State$1();
560
- pending(channel) {
561
- return hasMatchingMutations(this.#state.mutated, channel?.readyId);
562
- }
563
- pendingReadyChannel() {
564
- for (let mutation of this.#state.mutated) if (mutation.channel?.readyId) return mutation.channel;
565
- }
566
- stringifyScopes(flushes, boundary, channel) {
567
- try {
568
- return this.#state.boundary = boundary, this.#state.channel = channel, writeScopesRoot(this.#state, flushes);
569
- } catch (err) {
570
- return abortRender(boundary, err), "";
571
- } finally {
572
- this.#state.flushId++, this.#state.buf = [];
573
- }
574
- }
575
- written(val) {
576
- return this.#state.refs.has(val);
577
- }
578
- takeChannelDeps() {
579
- let deps = this.#state.channelDeps;
580
- return this.#state.channelDeps = null, deps;
581
- }
582
- writeCall(value, object, property, channel) {
583
- this.#state.mutated.push({
584
- value,
585
- object,
586
- property,
587
- channel
588
- });
569
+ };
570
+ function stringifyScopes(state, flushes, boundary, channel) {
571
+ try {
572
+ return state.boundary = boundary, state.channel = channel, writeScopesRoot(state, flushes);
573
+ } catch (err) {
574
+ return abortRender(boundary, err), "";
575
+ } finally {
576
+ state.flushId++, state.buf = [];
589
577
  }
590
- dropCall(value, object, property) {
591
- let { mutated } = this.#state;
592
- for (let i = 0; i < mutated.length; i++) {
593
- let mutation = mutated[i];
594
- if (mutation.value === value && mutation.object === object && mutation.property === property) return mutated.splice(i, 1), !0;
595
- }
596
- return !1;
578
+ }
579
+ function pendingReadyChannel(state) {
580
+ let calls = state.queuedReadyCalls;
581
+ return calls.length ? calls[0].channel : void 0;
582
+ }
583
+ function takeChannelDeps(state) {
584
+ let deps = state.channelDeps;
585
+ return state.channelDeps = null, deps;
586
+ }
587
+ function queueCall(state, value, object, method, channel) {
588
+ (channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
589
+ method,
590
+ value,
591
+ object,
592
+ channel,
593
+ valueId: null
594
+ });
595
+ }
596
+ function dropQueuedCall(state, value, object, method, channel) {
597
+ let queuedCalls = channel?.readyId ? state.queuedReadyCalls : state.queuedCalls;
598
+ for (let i = 0; i < queuedCalls.length; i++) {
599
+ let call = queuedCalls[i];
600
+ if (call.value === value && call.object === object && call.method === method) return queuedCalls.splice(i, 1), !0;
597
601
  }
598
- };
599
- function register(id, val, scope, locals) {
602
+ return !1;
603
+ }
604
+ function register(id, val, scope, locals, access = "_._" + toAccess(toObjectKey(id))) {
600
605
  return REGISTRY.set(val, {
601
606
  id,
602
607
  scope,
603
608
  locals,
604
- access: "_._" + toAccess(toObjectKey(id))
609
+ access
605
610
  }), val;
606
611
  }
607
- function getRegistered(val) {
608
- let registered = REGISTRY.get(val);
609
- if (registered) return {
610
- id: registered.id,
611
- scope: registered.scope
612
- };
613
- }
614
612
  function writeScopesRoot(state, flushes) {
615
- let { buf } = state, nextSlotId = -1, fillIndex = -1;
613
+ let { buf } = state, nextSlotId = -1, scopesIndex = -1;
616
614
  for (let flush of flushes) {
617
- let scopeId = flush[0], scope = flush[1], ref = state.refs.get(scope) || newScopeReference(state, scope, scopeId), openIndex = buf.push("") - 1;
618
- writeObjectProps(state, flush[2], ref) ? (buf[openIndex] = nextSlotId === -1 ? "[" + scopeId + ",{" : (scopeId === nextSlotId ? "" : "," + (scopeId - nextSlotId)) + ",{", fillIndex === -1 && (fillIndex = openIndex), nextSlotId = scopeId + 1, buf.push("}")) : buf.pop();
615
+ let scopeId = flush[0], scope = flush[1], ref = state.scopeRef(scope, scopeId), openIndex = buf.push("") - 1;
616
+ state.writeScopeProps(flush[2], ref) ? (buf[openIndex] = nextSlotId === -1 ? state.scopesCursor(scopeId) + "{" : (scopeId === nextSlotId ? "" : "," + (scopeId - nextSlotId)) + ",{", scopesIndex === -1 && (scopesIndex = openIndex), nextSlotId = scopeId + 1, buf.push("}")) : buf.pop();
619
617
  }
620
- nextSlotId !== -1 && buf.push("]");
621
618
  let extras = "";
622
- (state.pendingAssignments.size || hasChannelMutations(state)) && (extras = ",0)", fillIndex !== -1 && (buf[fillIndex] = "_(" + buf[fillIndex], buf.push(")")), writeAssigned(state));
619
+ (state.deferredRefs.size || hasChannelCalls(state)) && (extras = state.writeTrailing(scopesIndex));
623
620
  let result = extras && "(";
624
621
  for (let chunk of buf) result += chunk;
625
- return result += extras, result ? state.wroteUndefined ? (state.wroteUndefined = !1, "(_,$)=>" + result) : "_=>" + result : "";
622
+ return result += extras, result ? state.wrapPayload(result, extras) : "";
626
623
  }
627
- function writeAssigned(state) {
624
+ function writeDeferred(state) {
628
625
  let sep = state.buf.length ? "," : "";
629
- if (state.pendingAssignments.size) {
630
- let pending = state.pendingAssignments;
631
- state.pendingAssignments = /* @__PURE__ */ new Set();
626
+ if (state.deferredRefs.size) {
627
+ let pending = state.deferredRefs;
628
+ state.deferredRefs = /* @__PURE__ */ new Set();
632
629
  let buf = "", hasCalls = !1;
633
- for (let ref of pending) ref.assignments && (buf += sep + assignmentsToString(ref.assignments, ref.id), ref.assignments = null, sep = ","), hasCalls ||= ref.calls !== null;
634
- if (buf && state.buf.push(buf), hasCalls) {
635
- for (let ref of pending) if (ref.calls) {
636
- for (let { method, args } of ref.calls) {
637
- state.buf.push((state.buf.length ? "," : "") + ref.id + "." + method + "(");
638
- for (let a = 0; a < args.length; a++) a && state.buf.push(","), writeCallArg(state, args[a]);
639
- state.buf.push(")");
640
- }
641
- ref.calls = null;
642
- }
630
+ for (let ref of pending) ref.assignments && (buf += sep + assignmentsToString(ref.assignments, ref.id), ref.assignments = null, sep = ","), hasCalls ||= ref.deferredMembers !== null;
631
+ if (buf && state.buf.push(buf), hasCalls) for (let ref of pending) {
632
+ let members = ref.deferredMembers;
633
+ members && (writeDeferredMembers(state, ref.id, members), ref.deferredMembers = null);
643
634
  }
644
635
  }
645
- if (hasChannelMutations(state)) {
636
+ let readyId = state.channel?.readyId, calls = state.queuedCalls;
637
+ if (readyId) {
638
+ calls = [];
646
639
  let remaining = [];
647
- for (let mutation of state.mutated) {
648
- if (!mutationMatchesReadyId(mutation, state.channel?.readyId)) {
649
- remaining.push(mutation);
650
- continue;
651
- }
652
- let hasSeen = state.refs.get(mutation.object)?.id, objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
653
- if (writeProp(state, mutation.object, null, "")) {
654
- let objectRef = state.refs.get(mutation.object);
655
- objectRef && objectRef.scopeId === void 0 && (!objectRef.id && !isAncestorChannelRef(state, objectRef) ? (objectRef.id = nextRefAccess(state), state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex], state.buf.push(")")) : hasSeen || (state.buf[objectStartIndex] = "(" + state.buf[objectStartIndex], state.buf.push(")")));
656
- } else state.buf.push("void 0");
657
- let valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
658
- if (mutation.value !== void 0) {
659
- if (writeProp(state, mutation.value, null, "")) {
660
- let valueRef = typeof mutation.value == "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
661
- valueRef && !valueRef.id && valueRef.scopeId === void 0 && !isAncestorChannelRef(state, valueRef) && (valueRef.id = mutation.valueId || nextRefAccess(state), state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex]);
662
- } else state.buf.push("void 0");
663
- }
664
- state.buf.push(")");
665
- }
666
- state.mutated = remaining;
640
+ for (let call of state.queuedReadyCalls) (call.channel.readyId === readyId ? calls : remaining).push(call);
641
+ state.queuedReadyCalls = remaining;
642
+ } else calls.length && (state.queuedCalls = []);
643
+ for (let call of calls) {
644
+ let objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
645
+ if (writeProp(state, call.object, null, "")) {
646
+ let objectRef = state.refs.get(call.object);
647
+ !objectRef.id && !isAncestorChannelRef(state, objectRef) ? (objectRef.id = nextRefAccess(state), state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex], state.buf.push(")")) : objectRef.id && state.buf[objectStartIndex] !== objectRef.id && (state.buf[objectStartIndex] = "(" + state.buf[objectStartIndex], state.buf.push(")"));
648
+ } else state.buf.push("void 0");
649
+ state.buf.push("." + call.method + "("), call.value !== void 0 && writeCallArg(state, call.value, call.valueId), state.buf.push(")");
650
+ }
651
+ state.deferredRefs.size && writeDeferred(state);
652
+ }
653
+ function writeDeferredMembers(state, id, { collection, first, rest }) {
654
+ if (collection instanceof Map) {
655
+ writeDeferredEntry(state, id, first);
656
+ for (let entry of rest) writeDeferredEntry(state, id, entry);
657
+ } else {
658
+ writeDeferredMember(state, id, first);
659
+ for (let member of rest) writeDeferredMember(state, id, member);
667
660
  }
668
- state.pendingAssignments.size && writeAssigned(state);
669
661
  }
670
- function writeCallArg(state, val) {
662
+ function writeDeferredEntry(state, id, [key, value]) {
663
+ state.buf.push("," + id + ".set("), (key !== void 0 || value !== void 0) && writeCallArg(state, key, null), value !== void 0 && (state.buf.push(","), writeCallArg(state, value, null)), state.buf.push(")");
664
+ }
665
+ function writeDeferredMember(state, id, member) {
666
+ state.buf.push("," + id + ".add("), member !== void 0 && writeCallArg(state, member, null), state.buf.push(")");
667
+ }
668
+ function writeCallArg(state, val, valueId) {
669
+ let startIndex = state.buf.length;
671
670
  if (val === void 0) state.wroteUndefined = !0, state.buf.push("$");
672
671
  else if (writeProp(state, val, null, "")) {
673
- let ref = state.refs.get(val) || state.strs.get(val);
674
- ref && ensureId(state, ref);
672
+ let ref = typeof val == "string" ? state.strs.get(val) : state.refs.get(val);
673
+ ref && !ref.id && ref.scopeId === void 0 && !isAncestorChannelRef(state, ref) && (ref.id = valueId || nextRefAccess(state), state.buf[startIndex] = ref.id + "=" + state.buf[startIndex]);
675
674
  } else state.buf.push("void 0");
676
675
  }
677
- function hasChannelMutations(state) {
678
- return hasMatchingMutations(state.mutated, state.channel?.readyId);
676
+ function hasChannelCalls(state) {
677
+ return hasMatchingCalls(state, state.channel?.readyId);
679
678
  }
680
- function hasMatchingMutations(mutated, readyId) {
681
- for (let mutation of mutated) if (mutationMatchesReadyId(mutation, readyId)) return !0;
679
+ function hasMatchingCalls(state, readyId) {
680
+ if (!readyId) return state.queuedCalls.length > 0;
681
+ for (let call of state.queuedReadyCalls) if (call.channel.readyId === readyId) return !0;
682
682
  return !1;
683
683
  }
684
- function mutationMatchesReadyId(mutation, readyId) {
685
- return mutation.channel?.readyId ? mutation.channel.readyId === readyId : !readyId;
686
- }
687
684
  function writeProp(state, val, parent, accessor) {
688
685
  switch (typeof val) {
689
686
  case "string": return writeString(state, val, parent, accessor);
@@ -698,7 +695,7 @@ function writeProp(state, val, parent, accessor) {
698
695
  }
699
696
  function writeReferenceOr(state, write, val, parent, accessor) {
700
697
  let ref = state.refs.get(val);
701
- if (ref) return trackChannel(state, ref) ? parent && isCircular(parent, ref) ? (ensureId(state, ref), state.pendingAssignments.add(ref), addAssignment(ref, accessId(state, parent) + toAccess(accessor)), !1) : (writeRef(state, ref), !0) : !1;
698
+ if (ref) return trackChannel(state, ref) ? parent && isCircular(parent, ref) ? (ensureRefAccess(state, ref), state.deferredRefs.add(ref), addAssignment(ref, accessId(state, parent) + toAccess(accessor)), !1) : (writeRef(state, ref), !0) : !1;
702
699
  let registered = REGISTRY.get(val);
703
700
  return registered ? writeRegistered(state, val, parent, accessor, registered) : (state.refs.set(val, ref = new Reference(parent, accessor, state.flushId, state.buf.length)), ref.channel = state.channel, write(state, val, ref) ? !0 : (state.refs.delete(val), !1));
704
701
  }
@@ -715,19 +712,7 @@ function quoteRegisterId(id) {
715
712
  }
716
713
  function writeRegistered(state, val, parent, accessor, registered) {
717
714
  let { scope } = registered;
718
- if (scope) {
719
- let ref = new Reference(parent, accessor, state.flushId, state.buf.length);
720
- ref.channel = state.channel, state.refs.set(val, ref);
721
- let scopeId = scope[K_SCOPE_ID];
722
- trackScope(state, scope, scopeId);
723
- let locals = registered.locals?.(state.boundary.state.scope);
724
- if (locals) {
725
- state.buf.push(registered.access + "(_(" + scopeId + ")");
726
- for (let local of locals) state.buf.push(","), writePlainObject(state, local, newArgReference(state, ref, local));
727
- } else state.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
728
- state.buf.push(")");
729
- } else state.buf.push(registered.access);
730
- return !0;
715
+ return scope ? state.writeScopedRegistration(val, parent, accessor, registered) : state.buf.push(registered.access), !0;
731
716
  }
732
717
  function writeString(state, val, parent, accessor) {
733
718
  if (val.length > 12) {
@@ -863,7 +848,7 @@ function writeRegExp(state, val) {
863
848
  }
864
849
  function writePromise(state, val, ref) {
865
850
  let { boundary, channel } = state, pId = nextRefAccess(state), handle = newAsyncHandle(state, ref, pId);
866
- return state.buf.push("(p=>p=new Promise((f,r)=>" + pId + "={f,r(e){p.catch(_=>0);r(e)}}))()"), val.then((v) => writeAsyncCall(state, boundary, handle, "f", v, channel, pId), (v) => writeAsyncCall(state, boundary, handle, "r", v, channel, pId)), boundary.startAsync(), !0;
851
+ return state.buf.push("(p=>p=new Promise((f,r)=>" + pId + "={f,r(e){p.catch(_=>0);r(e)}}))()"), val.then((v) => queueAsyncCall(state, boundary, handle, "f", v, channel, pId), (v) => queueAsyncCall(state, boundary, handle, "r", v, channel, pId)), boundary.startAsync(), !0;
867
852
  }
868
853
  function newAsyncHandle(state, parent, id) {
869
854
  let handle = {}, handleRef = new Reference(parent, null, state.flushId, null, id);
@@ -871,23 +856,25 @@ function newAsyncHandle(state, parent, id) {
871
856
  }
872
857
  function writeMap(state, val, ref) {
873
858
  if (!val.size) return state.buf.push("new Map"), !0;
874
- let items = [], assignments, needsId, deferring = !1, i = 0;
859
+ let items = [], assignments, needsId, i = 0, entries = val.entries();
875
860
  if (val.size < 25) {
876
- for (let [itemKey, itemValue] of val) {
877
- if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
878
- deferCall(state, ref, "set", [itemKey, itemValue]);
879
- continue;
861
+ for (let entry of entries) {
862
+ let [itemKey, itemValue] = entry;
863
+ if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
864
+ if (deferMembers(state, ref, val, entry, entries), !i) return state.buf.push("new Map"), !0;
865
+ break;
880
866
  }
881
- itemKey === val && (itemKey = void 0, (assignments ||= []).push("a[" + i + "][0]")), itemValue === val && (itemValue = void 0, (assignments ||= []).push("a[" + i + "][1]")), needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue), i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
867
+ itemKey === val && (itemKey = void 0, (assignments ||= []).push("a[" + i + "][0]")), itemValue === val && (itemValue = void 0, (assignments ||= []).push("a[" + i + "][1]")), needsId ||= isReusableMember(itemKey) || isReusableMember(itemValue), i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
882
868
  }
883
869
  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);
884
870
  } else {
885
- for (let [itemKey, itemValue] of val) {
886
- if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
887
- deferCall(state, ref, "set", [itemKey, itemValue]);
888
- continue;
871
+ for (let entry of entries) {
872
+ let [itemKey, itemValue] = entry;
873
+ if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
874
+ if (deferMembers(state, ref, val, entry, entries), !i) return state.buf.push("new Map"), !0;
875
+ break;
889
876
  }
890
- itemKey === val && (itemKey = 0, (assignments ||= []).push("a[" + i + "]")), itemValue === val && (itemValue = 0, (assignments ||= []).push("a[" + (i + 1) + "]")), needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue), i = items.push(itemKey, itemValue);
877
+ itemKey === val && (itemKey = 0, (assignments ||= []).push("a[" + i + "]")), itemValue === val && (itemValue = 0, (assignments ||= []).push("a[" + (i + 1) + "]")), needsId ||= isReusableMember(itemKey) || isReusableMember(itemValue), i = items.push(itemKey, itemValue);
891
878
  }
892
879
  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);
893
880
  }
@@ -895,13 +882,13 @@ function writeMap(state, val, ref) {
895
882
  }
896
883
  function writeSet(state, val, ref) {
897
884
  if (!val.size) return state.buf.push("new Set"), !0;
898
- let items = [], assignments, needsId, deferring = !1, i = 0;
899
- for (let item of val) {
900
- if (!deferring && item !== val && isAncestorMember(state, ref, item) && (deferring = !0), deferring) {
901
- deferCall(state, ref, "add", [item]);
902
- continue;
885
+ let items = [], assignments, needsId, i = 0, members = val.values();
886
+ for (let item of members) {
887
+ if (item !== val && isAncestorMember(state, ref, item)) {
888
+ if (deferMembers(state, ref, val, item, members), !i) return state.buf.push("new Set"), !0;
889
+ break;
903
890
  }
904
- item === val ? (item = 0, (assignments ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
891
+ item === val ? (item = 0, (assignments ||= []).push("i[" + i + "]")) : needsId ||= isReusableMember(item), i = items.push(item);
905
892
  }
906
893
  return writeArrayArg(state, ref, items, assignments && "((s,i)=>(" + assignmentsToString(assignments, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId), !0;
907
894
  }
@@ -910,11 +897,12 @@ function isAncestorMember(state, container, member) {
910
897
  let ref = state.refs.get(member);
911
898
  return ref !== void 0 && isCircular(container, ref);
912
899
  }
913
- function deferCall(state, ref, method, args) {
914
- ensureId(state, ref), (ref.calls ||= []).push({
915
- method,
916
- args
917
- }), state.pendingAssignments.add(ref);
900
+ function deferMembers(state, ref, collection, first, rest) {
901
+ ensureRefAccess(state, ref), ref.deferredMembers = {
902
+ collection,
903
+ first,
904
+ rest
905
+ }, state.deferredRefs.add(ref);
918
906
  }
919
907
  function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
920
908
  if (assignsPrefix || needsId) {
@@ -926,14 +914,14 @@ function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
926
914
  function newArgReference(state, parent, val) {
927
915
  for (let key in val) {
928
916
  let member = val[key];
929
- if (isDedupedMember(member) && !(typeof member == "string" ? state.strs.has(member) : state.refs.has(member))) {
917
+ if (isReusableMember(member) && !(typeof member == "string" ? state.strs.has(member) : state.refs.has(member))) {
930
918
  let ref = new Reference(parent, null, state.flushId, null, nextRefAccess(state));
931
919
  return state.buf.push(ref.id + "="), ref;
932
920
  }
933
921
  }
934
922
  return new Reference(parent, null, state.flushId, state.buf.length);
935
923
  }
936
- function isDedupedMember(val) {
924
+ function isReusableMember(val) {
937
925
  switch (typeof val) {
938
926
  case "object": return val !== null && val[K_SCOPE_ID] === void 0;
939
927
  case "function":
@@ -986,7 +974,7 @@ function writeAggregateError(state, val, ref) {
986
974
  let inlined = writeProp(state, val.errors, ref, "errors");
987
975
  if (inlined || state.buf.push("[]"), val.message ? state.buf.push("," + quote(val.message + "", 0) + ")") : state.buf.push(")"), inlined) {
988
976
  let errorsRef = state.refs.get(val.errors);
989
- errorsRef?.id && (state.pendingAssignments.add(errorsRef), addAssignment(errorsRef, accessId(state, ref) + toAccess("errors")));
977
+ errorsRef?.id && (state.deferredRefs.add(errorsRef), addAssignment(errorsRef, accessId(state, ref) + toAccess("errors")));
990
978
  }
991
979
  return !0;
992
980
  }
@@ -1015,7 +1003,7 @@ function writeRequest(state, val, ref) {
1015
1003
  let options = "";
1016
1004
  val.cache !== "default" && (options += sep + "cache:" + quote(val.cache, 0), sep = ","), val.credentials !== "same-origin" && (options += sep + "credentials:" + quote(val.credentials, 0), sep = ",");
1017
1005
  let seenHeaders = state.refs.get(val.headers);
1018
- if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders), sep = ",";
1006
+ if (seenHeaders) options += sep + "headers:" + ensureRefAccess(state, seenHeaders), sep = ",";
1019
1007
  else {
1020
1008
  state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
1021
1009
  let headers = stringEntriesToHeadersInit(val.headers);
@@ -1027,7 +1015,7 @@ function writeResponse(state, val, ref) {
1027
1015
  let sep = "", options = "";
1028
1016
  val.status !== 200 && (options += "status:" + val.status, sep = ","), val.statusText && (options += sep + "statusText:" + quote(val.statusText, 0), sep = ",");
1029
1017
  let seenHeaders = state.refs.get(val.headers);
1030
- if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders);
1018
+ if (seenHeaders) options += sep + "headers:" + ensureRefAccess(state, seenHeaders);
1031
1019
  else {
1032
1020
  state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
1033
1021
  let headers = stringEntriesToHeadersInit(val.headers);
@@ -1050,9 +1038,9 @@ function writeTemporal(state, val, name) {
1050
1038
  function writeReadableStream(state, val, ref) {
1051
1039
  if (val.locked) return !1;
1052
1040
  let { boundary, channel } = state, reader = val.getReader(), iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1053
- done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (reader.read().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
1041
+ done ? queueAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (reader.read().then(onFulfilled, onRejected), boundary.startAsync(), queueAsyncCall(state, boundary, handle, "f", value, channel));
1054
1042
  }, onRejected = (reason) => {
1055
- writeAsyncCall(state, boundary, handle, "j", reason, channel);
1043
+ queueAsyncCall(state, boundary, handle, "j", reason, channel);
1056
1044
  };
1057
1045
  return 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))}})"), reader.read().then(onFulfilled, onRejected), boundary.startAsync(), !0;
1058
1046
  }
@@ -1065,7 +1053,7 @@ function writeGenerator(state, iter, ref) {
1065
1053
  returnValue = value;
1066
1054
  break;
1067
1055
  }
1068
- needsId ||= isDedupedMember(value), yields.push(value);
1056
+ needsId ||= isReusableMember(value), yields.push(value);
1069
1057
  }
1070
1058
  if (returnValue === void 0 && !yields.length) return state.buf.push("(function*(){})()"), !0;
1071
1059
  let heldReturn = returnValue !== void 0 && isAncestorMember(state, ref, returnValue);
@@ -1076,18 +1064,18 @@ function writeGenerator(state, iter, ref) {
1076
1064
  if (heldReturn) {
1077
1065
  let holder = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1078
1066
  state.buf.push("," + holder.id + "={}"), writeProp(state, returnValue, holder, "v");
1079
- } else if (returnValue !== void 0 && (state.buf.push(","), writeProp(state, returnValue, ref, "") && isDedupedMember(returnValue))) {
1067
+ } else if (returnValue !== void 0 && (state.buf.push(","), writeProp(state, returnValue, ref, "") && isReusableMember(returnValue))) {
1080
1068
  let retRef = typeof returnValue == "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
1081
- retRef && ensureId(state, retRef);
1069
+ retRef && ensureRefAccess(state, retRef);
1082
1070
  }
1083
1071
  return state.buf.push(")"), !0;
1084
1072
  }
1085
1073
  function writeAsyncGenerator(state, iter, ref) {
1086
1074
  if (iter[kTouchedIterator]) return state.buf.push("(async function*(){}())"), !0;
1087
1075
  let { boundary, channel } = state, iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1088
- done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (iter.next().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
1076
+ done ? queueAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (iter.next().then(onFulfilled, onRejected), boundary.startAsync(), queueAsyncCall(state, boundary, handle, "f", value, channel));
1089
1077
  }, onRejected = (reason) => {
1090
- writeAsyncCall(state, boundary, handle, "j", reason, channel);
1078
+ queueAsyncCall(state, boundary, handle, "j", reason, channel);
1091
1079
  };
1092
1080
  return 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 + "={})"), iter.next().then(onFulfilled, onRejected), boundary.startAsync(), !0;
1093
1081
  }
@@ -1115,11 +1103,11 @@ function writeMaybeIterableProps(state, val, ref) {
1115
1103
  }
1116
1104
  return sep;
1117
1105
  }
1118
- function writeAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1119
- boundary.aborted || (state.mutated.push({
1106
+ function queueAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1107
+ boundary.aborted || ((channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
1108
+ method,
1120
1109
  value,
1121
1110
  object: handle,
1122
- property: method,
1123
1111
  channel,
1124
1112
  valueId
1125
1113
  }), boundary.endAsync());
@@ -1220,16 +1208,16 @@ function quote(str, startPos) {
1220
1208
  return "\"" + (lastPos === startPos ? str : result + str.slice(lastPos)) + "\"";
1221
1209
  }
1222
1210
  function writeRef(state, ref) {
1223
- ref.id === null && ref.scopeId === void 0 && ref.path === null && (ref.pos === null || ref.flushId !== state.flushId) && !isAncestorChannelRef(state, ref) ? (ref.path = accessPath(state, ref), ref.pos = state.buf.length, ref.flushId = state.flushId, state.buf.push(ref.path)) : state.buf.push(ensureId(state, ref));
1211
+ ref.id === null && ref.scopeId === void 0 && ref.path === null && (ref.pos === null || ref.flushId !== state.flushId) && !isAncestorChannelRef(state, ref) ? (ref.path = accessPath(state, ref), ref.pos = state.buf.length, ref.flushId = state.flushId, state.buf.push(ref.path)) : state.buf.push(ensureRefAccess(state, ref));
1224
1212
  }
1225
- function ensureId(state, ref) {
1226
- return ref.scopeId === void 0 ? ref.id ? (trackChannel(state, ref), ref.id) : assignId(state, ref) : (trackChannel(state, ref), "_(" + ref.scopeId + ")");
1213
+ function ensureRefAccess(state, ref) {
1214
+ return ref.scopeId === void 0 ? ref.id ? (trackChannel(state, ref), ref.id) : claimRefAccess(state, ref) : (trackChannel(state, ref), "_(" + ref.scopeId + ")");
1227
1215
  }
1228
1216
  function accessId(state, ref) {
1229
- let id = ensureId(state, ref);
1217
+ let id = ensureRefAccess(state, ref);
1230
1218
  return id === ref.id || ref.scopeId !== void 0 ? id : "(" + id + ")";
1231
1219
  }
1232
- function assignId(state, ref) {
1220
+ function claimRefAccess(state, ref) {
1233
1221
  let { pos } = ref;
1234
1222
  return pos !== null && ref.flushId === state.flushId ? (ref.id = nextRefAccess(state), pos === 0 ? state.buf[0] = ref.id + "=" + state.buf[0] : state.buf[pos - 1] += ref.id + "=", ref.id) : isAncestorChannelRef(state, ref) ? ref.path || accessPath(state, ref) : (ref.id = nextRefAccess(state), ref.id + "=" + (ref.path || accessPath(state, ref)));
1235
1223
  }
@@ -1296,10 +1284,10 @@ function patchIteratorNext(proto) {
1296
1284
  //#endregion
1297
1285
  //#region src/html/attrs.ts
1298
1286
  function _attr_class(value) {
1299
- return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
1287
+ return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
1300
1288
  }
1301
1289
  function _attr_style(value) {
1302
- return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
1290
+ return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
1303
1291
  }
1304
1292
  function _attr_option_value(value) {
1305
1293
  let valueAttr = _attr("value", value), selectedValue = getContext(kSelectedValue);
@@ -1325,7 +1313,7 @@ function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeT
1325
1313
  return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _attr("value", value);
1326
1314
  }
1327
1315
  function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
1328
- return checkedChange && writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType), isNotVoid(checked) ? " checked" : "";
1316
+ return checkedChange && writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType), isNotNullishOrFalse(checked) ? " checked" : "";
1329
1317
  }
1330
1318
  function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
1331
1319
  let valueAttr = _attr("value", value);
@@ -1338,7 +1326,7 @@ function getCheckedValueRef(checkedValue) {
1338
1326
  }
1339
1327
  }
1340
1328
  function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
1341
- let normalizedOpen = isNotVoid(open);
1329
+ let normalizedOpen = isNotNullishOrFalse(open);
1342
1330
  return openChange && writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType), normalizedOpen ? " open" : "";
1343
1331
  }
1344
1332
  function _attr_nonce() {
@@ -1349,7 +1337,7 @@ function _style_html(decls) {
1349
1337
  return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
1350
1338
  }
1351
1339
  function _attr(name, value) {
1352
- return isVoid(value) ? "" : nonVoidAttr(name, value);
1340
+ return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
1353
1341
  }
1354
1342
  function _attr_and(name, value, attr) {
1355
1343
  return value ? attr : _attr(name, value);
@@ -1385,7 +1373,7 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
1385
1373
  case "style":
1386
1374
  result += _attr_style(value);
1387
1375
  break;
1388
- default: name && !(isVoid(value) || skip.test(name) || name === "content" && tagName !== "meta") && (isEventHandler(name) ? (events || (events = {}, writeScope(scopeId, { ["I" + nodeAccessor]: events })), events[getEventHandlerName(name)] = value) : result += nonVoidAttr(name, value));
1376
+ default: name && !(isNullishOrFalse(value) || skip.test(name) || name === "content" && tagName !== "meta") && (isEventHandler(name) ? (events || (events = {}, writeScope(scopeId, { ["I" + nodeAccessor]: events })), events[getEventType(name)] = value) : result += stringifyAttr(name, value));
1389
1377
  }
1390
1378
  }
1391
1379
  return result;
@@ -1396,7 +1384,7 @@ function _attrs_content(data, nodeAccessor, scopeId, tagName, markerGuard) {
1396
1384
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
1397
1385
  let partial = {};
1398
1386
  for (let name in data) {
1399
- let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1387
+ let key = isEventHandler(name) ? `on-${getEventType(name)}` : name;
1400
1388
  skip[key] || (partial[key] = data[name]);
1401
1389
  }
1402
1390
  return _attrs(partial, nodeAccessor, scopeId, tagName);
@@ -1417,7 +1405,7 @@ function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, s
1417
1405
  function stringAttr(name, value) {
1418
1406
  return value && " " + name + attrAssignment(value);
1419
1407
  }
1420
- function nonVoidAttr(name, value) {
1408
+ function stringifyAttr(name, value) {
1421
1409
  switch (typeof value) {
1422
1410
  case "string": return " " + name + attrAssignment(value);
1423
1411
  case "boolean": return " " + name;
@@ -1448,18 +1436,7 @@ function normalizedValueMatches(a, b) {
1448
1436
  return !1;
1449
1437
  }
1450
1438
  function normalizeStrAttrValue(value) {
1451
- return isNotVoid(value) && value !== !0 ? value + "" : "";
1452
- }
1453
- //#endregion
1454
- //#region src/html/for.ts
1455
- function forOfBy(by, item, index) {
1456
- return by ? typeof by == "string" ? item[by] : by(item, index) : index;
1457
- }
1458
- function forInBy(by, name, value) {
1459
- return by ? by(name, value) : name;
1460
- }
1461
- function forStepBy(by, index) {
1462
- return by ? by(index) : index;
1439
+ return isNotNullishOrFalse(value) && value !== !0 ? value + "" : "";
1463
1440
  }
1464
1441
  //#endregion
1465
1442
  //#region src/html/inlined-runtimes.ts
@@ -1505,11 +1482,11 @@ function _scope_id() {
1505
1482
  function _peek_scope_id() {
1506
1483
  return $chunk.boundary.state.scopeId;
1507
1484
  }
1508
- function withContext(key, value, cb, cbValue) {
1485
+ function withContext(key, value, cb, cbValue, cbValue2) {
1509
1486
  let ctx = $chunk.context ||= { [kPendingContexts]: 0 }, prev = ctx[key];
1510
1487
  ctx[kPendingContexts]++, ctx[key] = value;
1511
1488
  try {
1512
- return cb(cbValue);
1489
+ return cb(cbValue, cbValue2);
1513
1490
  } finally {
1514
1491
  ctx[kPendingContexts]--, ctx[key] = prev;
1515
1492
  }
@@ -1523,11 +1500,11 @@ function captureContext(chunk) {
1523
1500
  function isInResumedBranch() {
1524
1501
  return $chunk?.context?.[kBranchId] !== void 0;
1525
1502
  }
1526
- function withBranchId(branchId, cb, cbValue) {
1527
- return withContext(kBranchId, branchId, cb, cbValue);
1503
+ function withBranchId(branchId, cb, cbValue, cbValue2) {
1504
+ return withContext(kBranchId, branchId, cb, cbValue, cbValue2);
1528
1505
  }
1529
- function withIsAsync(async, cb, value) {
1530
- return withContext(kIsAsync, async, cb, value);
1506
+ function withAsyncContent(async, cb, value) {
1507
+ return withContext(kAsyncContent, async, cb, value);
1531
1508
  }
1532
1509
  function _html(html) {
1533
1510
  $chunk.writeHTML(html);
@@ -1545,7 +1522,7 @@ function mayDrop(written) {
1545
1522
  return !1;
1546
1523
  }
1547
1524
  function _script(scopeId, registryId, markerGuard) {
1548
- markerGuard === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1525
+ markerGuard === 0 && ($chunk.channel.readyId || $chunk.context?.[kAsyncContent]) && _resume_branch(scopeId), $chunk.boundary.state.queueEffect(scopeId, registryId);
1549
1526
  }
1550
1527
  function _trailers(html) {
1551
1528
  $chunk.boundary.state.trailerHTML += html;
@@ -1563,24 +1540,24 @@ function _hoist(scopeId, id) {
1563
1540
  let getter = () => void 0;
1564
1541
  return getter[Symbol.iterator] = _hoist_read_error, _resume(getter, id, scopeId);
1565
1542
  }
1566
- function _el_resume(scopeId, accessor, shouldResume) {
1567
- if (shouldResume === 0) return "";
1543
+ function _el_resume(scopeId, accessor, markerGuard) {
1544
+ if (markerGuard === 0) return "";
1568
1545
  let { state } = $chunk.boundary;
1569
- return state.needsMainRuntime = !0, state.mark("$", scopeId + " " + accessor);
1546
+ return state.needsWalkerRuntime = !0, state.mark("$", scopeId + " " + accessor);
1570
1547
  }
1571
- function _text_resume(scopeId, accessor, val, shouldResume) {
1572
- return markText(scopeId, accessor, _escape(val), shouldResume);
1548
+ function _text_resume(scopeId, accessor, val, markerGuard) {
1549
+ return markText(scopeId, accessor, _escape(val), markerGuard);
1573
1550
  }
1574
- function _html_resume(scopeId, accessor, val, shouldResume) {
1551
+ function _html_resume(scopeId, accessor, val, markerGuard) {
1575
1552
  let html = _unescaped(val);
1576
- if (shouldResume === 0 || !~html.indexOf("<")) return markText(scopeId, accessor, html, shouldResume);
1553
+ if (markerGuard === 0 || !~html.indexOf("<")) return markText(scopeId, accessor, html, markerGuard);
1577
1554
  let { state } = $chunk.boundary;
1578
- return state.needsMainRuntime = !0, state.mark("&", "") + html + state.mark("'", scopeId + " " + accessor);
1555
+ return state.needsWalkerRuntime = !0, state.mark("&", "") + html + state.mark("'", scopeId + " " + accessor);
1579
1556
  }
1580
- function markText(scopeId, accessor, text, shouldResume) {
1581
- if (shouldResume === 0) return text;
1557
+ function markText(scopeId, accessor, text, markerGuard) {
1558
+ if (markerGuard === 0) return text;
1582
1559
  let { state } = $chunk.boundary;
1583
- return state.needsMainRuntime = !0, text ? (shouldResume === 2 ? "<!>" : "") + text + state.mark("$", scopeId + " " + accessor) : state.mark("%", scopeId + " " + accessor);
1560
+ return state.needsWalkerRuntime = !0, text ? (markerGuard === 2 ? "<!>" : "") + text + state.mark("$", scopeId + " " + accessor) : state.mark("%", scopeId + " " + accessor);
1584
1561
  }
1585
1562
  function _resume_branch(scopeId) {
1586
1563
  let branchId = $chunk.context?.[kBranchId];
@@ -1589,7 +1566,7 @@ function _resume_branch(scopeId) {
1589
1566
  function _attr_content(nodeAccessor, scopeId, content, markerGuard) {
1590
1567
  let shouldResume = markerGuard !== 0, render = normalizeServerRender(content), branchId = _peek_scope_id();
1591
1568
  if (render) try {
1592
- _set_scope_reason(shouldResume ? CLIENT_ALL : 0), shouldResume ? withBranchId(branchId, render) : render();
1569
+ _set_scope_reason(shouldResume ? ALL_GROUPS : 0), shouldResume ? withBranchId(branchId, render) : render();
1593
1570
  } finally {
1594
1571
  _set_scope_reason(void 0);
1595
1572
  }
@@ -1608,83 +1585,8 @@ function _var(parentScopeId, scopeOffsetAccessor, childScopeId, registryId, node
1608
1585
  nodeAccessor !== void 0 && writeScope(parentScopeId, { ["A" + nodeAccessor]: childScope });
1609
1586
  }
1610
1587
  function writeScopePassive(scopeId, partialScope) {
1611
- let target = $chunk.serializeState, scope = _scope_with_id(scopeId), passive = target.passiveScopes ||= {};
1612
- return Object.assign(scope, partialScope), passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope), scope;
1613
- }
1614
- function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
1615
- display ? resumesMarker(markerGuard, branchExprGuard, parentEndTag) && $chunk.writeHTML($chunk.boundary.state.mark("[", "")) : $chunk.writeHTML("<t hidden>");
1616
- }
1617
- function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1618
- let branchId = _scope_id(), wrap = !display;
1619
- wrap && $chunk.writeHTML("</t>"), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1620
- }
1621
- function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1622
- forBranches(by, (each) => each ? forOf(list, (item, index) => {
1623
- let itemKey = forOfBy(by, item, index);
1624
- each(itemKey, itemKey === index, () => cb(item, index));
1625
- }) : forOf(list, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1626
- }
1627
- function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1628
- forBranches(by, (each) => each ? forIn(obj, (key, value) => {
1629
- each(forInBy(by, key, value), !1, () => cb(key, value));
1630
- }) : forIn(obj, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1631
- }
1632
- function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1633
- forBranches(by, (each) => {
1634
- let index = 0;
1635
- return each ? forTo(to, from, step, (value) => {
1636
- let itemKey = forStepBy(by, value);
1637
- each(itemKey, itemKey === index++, () => cb(value));
1638
- }) : forTo(to, from, step, cb);
1639
- }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1640
- }
1641
- function _for_until(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1642
- forBranches(by, (each) => {
1643
- let index = 0;
1644
- return each ? forUntil(to, from, step, (value) => {
1645
- let itemKey = forStepBy(by, value);
1646
- each(itemKey, itemKey === index++, () => cb(value));
1647
- }) : forUntil(to, from, step, cb);
1648
- }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1649
- }
1650
- function forBranches(by, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1651
- if (branchGuard === 0) {
1652
- iterate(0), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
1653
- return;
1654
- }
1655
- let { state } = $chunk.boundary, resumeKeys = markerGuard !== 0, resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag), flushBranchIds = "", loopScopes;
1656
- iterate((itemKey, sameAsIndex, render) => {
1657
- let branchId = _peek_scope_id();
1658
- resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(state.mark("[", flushBranchIds)), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1659
- render();
1660
- let branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { M: itemKey } : {});
1661
- resumeMarker || (loopScopes = push(loopScopes, branchScope));
1662
- });
1663
- }), loopScopes && writeScope(scopeId, { ["A" + accessor]: loopScopes }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1664
- }
1665
- function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1666
- let resumeBranch = branchGuard !== 0, resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag), branchId = _peek_scope_id(), chunk = $chunk, beforeBranch = resumeMarker && resumeBranch && !singleNode ? deferBranchStart(chunk) : void 0, branchIndex = resumeBranch ? withBranchId(branchId, cb) : cb(), shouldWriteBranch = resumeBranch && branchIndex !== void 0;
1667
- beforeBranch !== void 0 && applyBranchStart(chunk, beforeBranch, shouldWriteBranch), shouldWriteBranch && (branchIndex || !resumeMarker) && writeScope(scopeId, {
1668
- ["D" + accessor]: branchIndex || void 0,
1669
- ["A" + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
1670
- }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
1671
- }
1672
- function deferBranchStart(chunk) {
1673
- let beforeBranch = chunk.html;
1674
- return chunk.html = "", beforeBranch;
1675
- }
1676
- function applyBranchStart(chunk, beforeBranch, rendered) {
1677
- chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
1678
- }
1679
- function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
1680
- return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
1681
- }
1682
- function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
1683
- let endTag = parentEndTag || "";
1684
- if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
1685
- let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
1686
- $chunk.writeHTML(mark + endTag);
1687
- } else markerGuard === 0 ? $chunk.writeHTML(endTag) : $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1588
+ let target = $chunk.channel, scope = _scope_with_id(scopeId);
1589
+ return Object.assign(scope, partialScope), $chunk.boundary.state.queuePassiveScope(target, scopeId, partialScope), scope;
1688
1590
  }
1689
1591
  function _existing_scope(scopeId) {
1690
1592
  return writeScope(scopeId, {});
@@ -1698,13 +1600,13 @@ function scopeWithId(state, scopeId) {
1698
1600
  }
1699
1601
  function _subscribe(subscribers, scope, resumeId, markerGuard) {
1700
1602
  if (subscribers) {
1701
- let { boundary, serializeState } = $chunk, { serializer } = boundary.state;
1702
- !serializeState.readyId && !serializer.written(subscribers) ? subscribers.add(scope) : resumeId ? _script(scope[K_SCOPE_ID], resumeId, markerGuard) : serializer.writeCall(scope, subscribers, "add", serializeState), boundary.withinCatch && (boundary.subscribed ||= []).push(subscribers, scope, serializeState);
1603
+ let { boundary, channel } = $chunk, { serializer } = boundary.state;
1604
+ !channel.readyId && !serializer.refs.has(subscribers) ? subscribers.add(scope) : resumeId ? _script(scope[K_SCOPE_ID], resumeId, markerGuard) : queueCall(serializer, scope, subscribers, "add", channel), boundary.withinCatch && (boundary.subscribed ||= []).push(subscribers, scope, channel);
1703
1605
  }
1704
1606
  return scope;
1705
1607
  }
1706
- function maskGroup(mask, group) {
1707
- return mask === 715827883 ? 1 : typeof mask == "number" ? group < 15 ? mask >>> 1 + 2 * group & 3 : 0 : mask[group] ?? 0;
1608
+ function getGroupReason(reason, group) {
1609
+ return reason === 715827883 ? 1 : typeof reason == "number" ? group < 15 ? reason >>> 1 + 2 * group & 3 : 0 : reason[group] ?? 0;
1708
1610
  }
1709
1611
  function _set_scope_reason(reason) {
1710
1612
  $chunk.boundary.state.scopeReason = reason;
@@ -1713,148 +1615,65 @@ function _scope_reason() {
1713
1615
  let reason = $chunk.boundary.state.scopeReason;
1714
1616
  return $chunk.boundary.state.scopeReason = void 0, reason;
1715
1617
  }
1716
- function _write_if(condition, key) {
1717
- return condition && maskGroup(condition, key) ? 1 : void 0;
1618
+ function _write_if(reason, group) {
1619
+ return reason && getGroupReason(reason, group) ? 1 : void 0;
1718
1620
  }
1719
- function _write_guard(condition, key) {
1720
- return _write_if(condition, key) || 0;
1621
+ function _write_guard(reason, group) {
1622
+ return _write_if(reason, group) || 0;
1721
1623
  }
1722
1624
  function writeWaitReady(readyId, renderer, input) {
1723
1625
  let chunk = $chunk, { boundary } = chunk, body = new Chunk(boundary, null, chunk.context, {
1724
1626
  readyId,
1725
- parent: chunk.serializeState,
1627
+ parent: chunk.channel,
1726
1628
  resumes: "",
1727
1629
  writeScopes: {},
1728
1630
  flushScopes: !1
1729
1631
  }), bodyEnd = body.render(renderer, input);
1730
1632
  if (boundary.aborted) throw boundary.reason;
1731
- body === bodyEnd ? (chunk.writeHTML(body.html), body.deferOwnReady(), chunk.deferredReady = push(chunk.deferredReady, body)) : (bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next), chunk.next = body);
1732
- }
1733
- function _await(scopeId, accessor, promise, content, markerGuard) {
1734
- let resumeMarker = markerGuard !== 0;
1735
- if (!isPromise(promise)) {
1736
- if (resumeMarker) {
1737
- let branchId = _peek_scope_id();
1738
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, content, promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1739
- } else content(promise);
1740
- return;
1741
- }
1742
- let chunk = $chunk, { boundary } = chunk, startId = _peek_scope_id(), after = chunk.next = $chunk = chunk.fork(boundary, chunk.next);
1743
- chunk.async = !0, captureContext(chunk), boundary.startAsync(), promise.then((value) => {
1744
- if (chunk.async && (chunk.async = !1, !boundary.aborted)) {
1745
- let { state } = boundary;
1746
- chunk.render(() => {
1747
- if (resumeMarker) {
1748
- let branchId = _peek_scope_id();
1749
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync({ parent: getAsyncContent(chunk) }, content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1750
- } else {
1751
- let renderedSince = _peek_scope_id() !== startId, async = { parent: getAsyncContent(chunk) };
1752
- withIsAsync(async, content, value), async.visit = renderedSince && (after.html || after.next) ? $chunk.boundary.state.mark("]", scopeId + " " + accessor) : "", async.resumed && $chunk.writeHTML(async.visit), async.end = $chunk;
1753
- }
1754
- }), !chunk.async && boundary.pendingReorders?.delete(chunk) && state.reorder(chunk), boundary.endAsync();
1755
- }
1756
- }, (err) => {
1757
- chunk.async = !1, boundary.abort(err);
1758
- });
1759
- }
1760
- function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
1761
- let placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id(), chunk = $chunk, { boundary } = chunk, { state } = boundary, { resumeWrites } = boundary, beforeBranch = deferBranchStart(chunk), renderers = () => writeTryRenderers(branchId, catchContent && _resume(catchContent, catchId), placeholderContent && _resume(placeholderContent, placeholderId)), renderersWritten = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, branchId, renderers), rendered = chunk !== $chunk || boundary.resumeWrites !== resumeWrites;
1762
- applyBranchStart(chunk, beforeBranch, rendered), rendered && (renderersWritten || renderers(), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
1633
+ body === bodyEnd ? (chunk.writeHTML(body.html), body.deferOwnReady(), chunk.deferredReady = push(chunk.deferredReady, body)) : (bodyEnd.next = chunk.forkRest(boundary), chunk.next = body);
1763
1634
  }
1764
- function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1765
- let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
1766
- if (body === body.render(content)) {
1767
- chunk.append(body);
1768
- return;
1769
- }
1770
- chunk.next = $chunk = chunk.fork(boundary, chunk.next), captureContext(chunk), chunk.placeholder = {
1771
- body,
1772
- render: placeholder,
1773
- branchId,
1774
- scopeId,
1775
- placeholderBranchId
1776
- };
1635
+ function deferBranchStart(chunk) {
1636
+ let beforeBranch = chunk.html;
1637
+ return chunk.html = "", beforeBranch;
1777
1638
  }
1778
- function tryBoundary(content, catchContent, branchId, renderers) {
1779
- let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, void 0, boundary);
1780
- catchContent && (catchBoundary.withinCatch = !0);
1781
- let body = chunk.fork(catchBoundary, null), bodyEnd = body.render(() => withBranchId(branchId, content));
1782
- if (catchBoundary.aborted) {
1783
- if (!catchContent) throw catchBoundary.reason;
1784
- return catchContent(catchBoundary.reason), !0;
1785
- }
1786
- if (body === bodyEnd) return chunk.append(body), !1;
1787
- let renderersAtSettle = !catchBoundary.resumeWrites, bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1788
- chunk.next = body, boundary.startAsync();
1789
- let reorderId = catchContent ? state.nextReorderId() : "";
1790
- return reorderId && (chunk.catchRange = {
1791
- id: reorderId,
1792
- end: bodyEnd
1793
- }, captureContext(chunk)), catchBoundary.onNext = () => {
1794
- if (!boundary.aborted) {
1795
- if (catchBoundary.aborted) {
1796
- if (!reorderId) {
1797
- boundary.abort(catchBoundary.reason);
1798
- return;
1799
- }
1800
- let streamed = !chunk.catchRange, catchChunk = chunk.fork(boundary, null);
1801
- chunk.catchRange = null, renderersAtSettle || catchChunk.render(clearTryRenderers, branchId);
1802
- let inOrder = catchChunk === catchChunk.render(catchContent, catchBoundary.reason);
1803
- if (boundary.aborted) return;
1804
- if ((bodyEnd.consumed || !inOrder) && (catchChunk.reorderBranch = branchId), bodyEnd.consumed) catchChunk.reorderId = reorderId, state.reorder(catchChunk);
1805
- else {
1806
- let reorder = null;
1807
- inOrder ? streamed && (reorder = chunk.fork(boundary, null)) : reorder = catchChunk, reorder && (reorder.reorderId = reorderId);
1808
- let endMarker = state.mark("!", reorderId), cut = body;
1809
- for (; cut.consumed;) cut = cut.next;
1810
- cut.async = !1, cut.next = inOrder ? catchChunk : bodyNext, cut.html = streamed ? endMarker : inOrder ? "" : state.mark("!^", reorderId) + endMarker, cut.scripts = cut.effects = cut.lastEffect = "", cut.placeholder = cut.reorderId = cut.catchRange = null, cut.deferredReorder = reorder, inOrder && (catchChunk.next = bodyNext);
1811
- }
1812
- boundary.endAsync();
1813
- } else catchBoundary.count ? boundary.onNext() : (renderersAtSettle && catchBoundary.resumeWrites && bodyEnd.render(renderers), chunk.catchRange = null, boundary.endAsync());
1814
- }
1815
- }, renderersAtSettle;
1639
+ function applyBranchStart(chunk, beforeBranch, rendered) {
1640
+ chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
1816
1641
  }
1817
1642
  function unsubscribe(subscribed, serializer) {
1818
1643
  for (let i = 0; i < subscribed.length; i += 3) {
1819
1644
  let subscribers = subscribed[i], scope = subscribed[i + 1];
1820
- serializer.written(subscribers) ? serializer.dropCall(scope, subscribers, "add") || serializer.writeCall(scope, subscribers, "delete", subscribed[i + 2]) : subscribers.delete(scope);
1645
+ if (!serializer.refs.has(subscribers)) subscribers.delete(scope);
1646
+ else {
1647
+ let channel = subscribed[i + 2];
1648
+ dropQueuedCall(serializer, scope, subscribers, "add", channel) || queueCall(serializer, scope, subscribers, "delete", channel);
1649
+ }
1821
1650
  }
1822
1651
  }
1823
- function clearTryRenderers(branchId) {
1824
- writeScope(branchId, {
1825
- E: 0,
1826
- Q: _scope_with_id(branchId).Q && 0
1827
- });
1828
- }
1829
- function writeTryRenderers(branchId, catchContent, placeholderContent) {
1830
- writeScope(branchId, {
1831
- E: catchContent,
1832
- Q: placeholderContent
1833
- });
1834
- }
1835
1652
  function countResumeWrite(chunk) {
1836
1653
  for (let boundary = chunk.boundary; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1654
+ }
1655
+ function writeAsyncVisits(chunk) {
1837
1656
  for (let async = getAsyncContent(chunk); async && !async.resumed; async = async.parent) async.resumed = !0, async.end?.writeHTML(async.visit);
1838
1657
  }
1839
1658
  function getAsyncContent(chunk) {
1840
- return chunk.context?.[kIsAsync];
1659
+ return chunk.context?.[kAsyncContent];
1841
1660
  }
1842
1661
  var State = class {
1843
1662
  tagId = 1;
1844
1663
  scopeId = 1;
1845
1664
  reorderId = 1;
1846
1665
  readyGate = 1;
1847
- hasGlobals = !1;
1848
- needsMainRuntime = !1;
1849
- hasMainRuntime = !1;
1850
- hasReadyRuntime = !1;
1666
+ hasWrittenGlobals = !1;
1667
+ needsWalkerRuntime = !1;
1668
+ hasWalkerRuntime = !1;
1669
+ hasWrittenReady = !1;
1851
1670
  hasReorderRuntime = !1;
1852
1671
  hasWrittenResume = !1;
1853
1672
  walkOnNextFlush = !1;
1854
1673
  trailerHTML = "";
1855
1674
  resumes = "";
1856
1675
  nonceAttr = "";
1857
- serializer = new Serializer();
1676
+ serializer = new State$1();
1858
1677
  writeReorders = null;
1859
1678
  scopes = /* @__PURE__ */ new Map();
1860
1679
  scope = (scopeId) => scopeWithId(this, scopeId);
@@ -1866,13 +1685,36 @@ var State = class {
1866
1685
  constructor($global) {
1867
1686
  this.$global = $global, $global.cspNonce && (this.nonceAttr = " nonce" + attrAssignment($global.cspNonce));
1868
1687
  }
1869
- flushChunk(html, scripts, pending) {
1688
+ joinFlush(html, scripts, pending) {
1870
1689
  let { $global, nonceAttr } = this, { __flush__ } = $global;
1871
1690
  return scripts && (html += "<script" + nonceAttr + ">" + scripts + "<\/script>"), __flush__ && ($global.__flush__ = void 0, html = __flush__($global, html)), pending ? html : html + this.trailerHTML;
1872
1691
  }
1873
1692
  walkScript() {
1874
1693
  return this.runtimePrefix + ".w()";
1875
1694
  }
1695
+ addResumes(channel, resumes) {
1696
+ channel.resumes = concatSequence(channel.resumes, resumes);
1697
+ }
1698
+ queueScope(target, scopeId, partialScope) {
1699
+ let pending = target.writeScopes[scopeId];
1700
+ pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0;
1701
+ }
1702
+ queuePassiveScope(target, scopeId, partialScope) {
1703
+ let passive = target.passiveScopes ||= {};
1704
+ passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
1705
+ }
1706
+ queueEffect(scopeId, registryId) {
1707
+ this.needsWalkerRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1708
+ }
1709
+ serializeFlush(boundary) {
1710
+ flushSerializer(boundary, this);
1711
+ }
1712
+ runtimeScript() {
1713
+ return "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(r=l.slice(s+1),(l=l[s])>\"#\"||(a[r]=e),l),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + this.$global.runtimeId + "\")(\"" + this.$global.renderId + "\")";
1714
+ }
1715
+ keepsTryMarks(chunk, resumeWrites) {
1716
+ return chunk !== $chunk || chunk.boundary.resumeWrites !== resumeWrites;
1717
+ }
1876
1718
  resumeScript(resumes) {
1877
1719
  return this.hasWrittenResume ? this.runtimePrefix + ".r.push(" + resumes + ")" : (this.hasWrittenResume = !0, this.runtimePrefix + ".r=[" + resumes + "]");
1878
1720
  }
@@ -1885,11 +1727,11 @@ var State = class {
1885
1727
  return $global.runtimeId + $global.renderId;
1886
1728
  }
1887
1729
  reorder(chunk) {
1888
- this.writeReorders ? this.writeReorders.push(chunk) : (this.needsMainRuntime = !0, this.writeReorders = [chunk]);
1730
+ this.writeReorders ? this.writeReorders.push(chunk) : (this.needsWalkerRuntime = !0, this.writeReorders = [chunk]);
1889
1731
  }
1890
- writeReady(id, resumes) {
1732
+ readyScript(id, resumes) {
1891
1733
  let readyKey = toObjectKey(id);
1892
- return this.readyIds?.has(id) ? this.readyAccess(readyKey) + ".push(" + resumes + ")" : ((this.readyIds ||= /* @__PURE__ */ new Set()).add(id), this.hasReadyRuntime ? this.readyAccess(readyKey) + "=[" + resumes + "]" : (this.hasReadyRuntime = !0, this.runtimePrefix + ".b={" + readyKey + ":[" + resumes + "]}"));
1734
+ return this.readyIds?.has(id) ? this.readyAccess(readyKey) + ".push(" + resumes + ")" : ((this.readyIds ||= /* @__PURE__ */ new Set()).add(id), this.hasWrittenReady ? this.readyAccess(readyKey) + "=[" + resumes + "]" : (this.hasWrittenReady = !0, this.runtimePrefix + ".b={" + readyKey + ":[" + resumes + "]}"));
1893
1735
  }
1894
1736
  readyAccess(readyKey) {
1895
1737
  return this.runtimePrefix + ".b" + toAccess(readyKey);
@@ -1931,7 +1773,7 @@ var State = class {
1931
1773
  this.abort(event.target.reason);
1932
1774
  }
1933
1775
  flush() {
1934
- return this.aborted || flushSerializer(this, this.state), this.count ? 1 : this.aborted ? 2 : 0;
1776
+ return this.aborted || this.state.serializeFlush(this), this.count ? 1 : this.aborted ? 2 : 0;
1935
1777
  }
1936
1778
  startAsync() {
1937
1779
  this.aborted || this.count++;
@@ -1956,18 +1798,21 @@ var State = class {
1956
1798
  boundary;
1957
1799
  next;
1958
1800
  context;
1959
- serializeState;
1960
- constructor(boundary, next, context, serializeState) {
1961
- this.boundary = boundary, this.next = next, this.context = context, this.serializeState = serializeState;
1801
+ channel;
1802
+ constructor(boundary, next, context, channel) {
1803
+ this.boundary = boundary, this.next = next, this.context = context, this.channel = channel;
1962
1804
  }
1963
1805
  fork(boundary, next) {
1964
- return new Chunk(boundary, next, this.context, this.serializeState);
1806
+ return new Chunk(boundary, next, this.context, this.channel);
1807
+ }
1808
+ forkRest(boundary) {
1809
+ return $chunk = this.fork(boundary, this.next);
1965
1810
  }
1966
1811
  writeHTML(html) {
1967
1812
  this.html += html;
1968
1813
  }
1969
1814
  writeEffect(scopeId, registryId) {
1970
- countResumeWrite(this), this.lastEffect === registryId ? this.effects = concatEffects(this.effects, scopeId + "") : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1815
+ countResumeWrite(this), writeAsyncVisits(this), this.lastEffect === registryId ? this.effects = concatEffects(this.effects, scopeId + "") : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1971
1816
  }
1972
1817
  writeScript(script) {
1973
1818
  this.scripts = concatScripts(this.scripts, script);
@@ -1984,7 +1829,7 @@ var State = class {
1984
1829
  return this.deferredReady = null, deferredReady;
1985
1830
  }
1986
1831
  deferOwnReady() {
1987
- if (this.serializeState.readyId && (this.effects || this.scripts || this.serializeState.flushScopes)) {
1832
+ if (this.channel.readyId && (this.effects || this.scripts || this.channel.flushScopes)) {
1988
1833
  let deferred = this.fork(this.boundary, null);
1989
1834
  deferred.effects = this.effects, deferred.scripts = this.scripts, this.effects = this.scripts = this.lastEffect = "", this.deferredReady = concat(deferred, this.deferredReady);
1990
1835
  }
@@ -2022,9 +1867,9 @@ var State = class {
2022
1867
  let { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId + "";
2023
1868
  this.writeHTML(state.mark("!^", reorderId));
2024
1869
  let { effects } = this, beforeBranch = deferBranchStart(this);
2025
- if (this.render(() => withBranchId(placeholderBranchId, placeholder.render)) !== this && this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.boundary.aborted) return !0;
1870
+ if (this.render(withBranchId, placeholderBranchId, placeholder.render) !== this && this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.boundary.aborted) return !0;
2026
1871
  let stateful = this.effects !== effects;
2027
- return applyBranchStart(this, beforeBranch, stateful), stateful && (this.render(() => writeScope(branchId, { P: scopeWithId(state, placeholderBranchId) })), this.writeHTML(state.mark("]", scopeId + " " + ("P" + branchId) + " " + placeholderBranchId)), dismissChunk(end, body).writeEffect(branchId, "_f")), this.writeHTML(state.mark("!", reorderId)), this.deferredReorder = body, !1;
1872
+ return applyBranchStart(this, beforeBranch, stateful), stateful && (this.render(writeScope, branchId, { P: scopeWithId(state, placeholderBranchId) }), this.writeHTML(state.mark("]", scopeId + " " + ("P" + branchId) + " " + placeholderBranchId)), dismissChunk(end, body).writeEffect(branchId, "_f")), this.writeHTML(state.mark("!", reorderId)), this.deferredReorder = body, !1;
2028
1873
  }
2029
1874
  markCatchRange() {
2030
1875
  let { catchRange } = this;
@@ -2040,14 +1885,14 @@ var State = class {
2040
1885
  consume(boundary) {
2041
1886
  this.renderPlaceholders(boundary);
2042
1887
  let cur = this, html = "", effects = "", scripts = "", effectsEnd, heldEffects = this.heldEffects, deferredReady;
2043
- for (this.heldEffects = null, this.serializeState.readyId && this.effects && followHeldEffects(this); cur.next && !cur.async;) cur.markCatchRange(), cur.queueDeferredReorder(), html += cur.html, cur.serializeState.readyId ? deferredReady = push(deferredReady, cur) : (cur.effects && (effectsEnd && effectsEnd.boundary !== cur.boundary && (heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects), effects = ""), effectsEnd = cur, effects = concatEffects(effects, cur.effects)), scripts = concatScripts(scripts, cur.scripts)), deferredReady = concat(deferredReady, cur.takeDeferredReady()), cur.consumed = !0, cur = cur.next;
2044
- return cur.deferOwnReady(), effects && (cur.serializeState.readyId ? heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects) : effectsEnd.boundary === cur.boundary ? (cur.effects = concatEffects(effects, cur.effects), cur.lastEffect ||= effectsEnd.lastEffect) : (heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects), isWithin(cur.boundary, effectsEnd.boundary) && (cur.lastEffect ||= effectsEnd.lastEffect))), cur.heldEffects = heldEffects, cur.deferredReady = concat(deferredReady, cur.deferredReady), cur.html = html + cur.html, cur.scripts = concatScripts(scripts, cur.scripts), cur;
1888
+ for (this.heldEffects = null, this.channel.readyId && this.effects && followHeldEffects(this); cur.next && !cur.async;) cur.markCatchRange(), cur.queueDeferredReorder(), html += cur.html, cur.channel.readyId ? deferredReady = push(deferredReady, cur) : (cur.effects && (effectsEnd && effectsEnd.boundary !== cur.boundary && (heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects), effects = ""), effectsEnd = cur, effects = concatEffects(effects, cur.effects)), scripts = concatScripts(scripts, cur.scripts)), deferredReady = concat(deferredReady, cur.takeDeferredReady()), cur.consumed = !0, cur = cur.next;
1889
+ return cur.deferOwnReady(), effects && (cur.channel.readyId ? heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects) : effectsEnd.boundary === cur.boundary ? (cur.effects = concatEffects(effects, cur.effects), cur.lastEffect ||= effectsEnd.lastEffect) : (heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects), isWithin(cur.boundary, effectsEnd.boundary) && (cur.lastEffect ||= effectsEnd.lastEffect))), cur.heldEffects = heldEffects, cur.deferredReady = concat(deferredReady, cur.deferredReady), cur.html = html + cur.html, cur.scripts = concatScripts(scripts, cur.scripts), cur;
2045
1890
  }
2046
- render(content, val) {
1891
+ render(content, val, val2) {
2047
1892
  let prev = $chunk;
2048
1893
  $chunk = this;
2049
1894
  try {
2050
- return content(val), $chunk;
1895
+ return content(val, val2), $chunk;
2051
1896
  } catch (err) {
2052
1897
  return this.boundary.abort(err), this;
2053
1898
  } finally {
@@ -2055,35 +1900,35 @@ var State = class {
2055
1900
  }
2056
1901
  }
2057
1902
  flushReadyScripts(boundary, reservations, holdEffects) {
2058
- let { serializeState } = this, { readyId } = serializeState, scripts = "", held = this.takeDeferredReady();
1903
+ let { channel } = this, { readyId } = channel, scripts = "", held = this.takeDeferredReady();
2059
1904
  if (held) for (let chunk of Array.isArray(held) ? held : [held]) chunk.boundary.aborted || (scripts = concatScripts(scripts, chunk.flushReadyScripts(boundary, reservations, holdEffects)), (chunk.effects || chunk.deferredReady) && (this.deferredReady = push(this.deferredReady, chunk)));
2060
1905
  if (readyId && !this.async) {
2061
1906
  let { state } = boundary;
2062
- flushSerializer(boundary, serializeState);
2063
- let deps = state.serializer.takeChannelDeps(), effects = holdEffects ? "" : this.effects, { resumes } = serializeState, chunkScripts = this.scripts;
2064
- if (serializeState.resumes = this.scripts = "", effects && (this.effects = this.lastEffect = ""), resumes || effects) {
2065
- state.needsMainRuntime = !0;
1907
+ flushSerializer(boundary, channel);
1908
+ let deps = takeChannelDeps(state.serializer), effects = holdEffects ? "" : this.effects, { resumes } = channel, chunkScripts = this.scripts;
1909
+ if (channel.resumes = this.scripts = "", effects && (this.effects = this.lastEffect = ""), resumes || effects) {
1910
+ state.needsWalkerRuntime = !0;
2066
1911
  let batch = concatSequence(depsMarker(deps), concatSequence(resumes, effects && `"${effects}"`));
2067
1912
  if (reservations) {
2068
1913
  let gate = state.readyGate++;
2069
- reservations.push(state.writeReady(readyId, gate + "")), scripts = concatScripts(scripts, "(b=>b.splice(b.indexOf(" + gate + "),1," + batch + "))(" + state.readyAccess(toObjectKey(readyId)) + ")");
2070
- } else scripts = concatScripts(scripts, state.writeReady(readyId, batch));
1914
+ reservations.push(state.readyScript(readyId, gate + "")), scripts = concatScripts(scripts, "(b=>b.splice(b.indexOf(" + gate + "),1," + batch + "))(" + state.readyAccess(toObjectKey(readyId)) + ")");
1915
+ } else scripts = concatScripts(scripts, state.readyScript(readyId, batch));
2071
1916
  }
2072
1917
  scripts = concatScripts(scripts, chunkScripts);
2073
1918
  }
2074
1919
  return scripts;
2075
1920
  }
2076
- flushScript(boundary) {
2077
- let { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1921
+ flush(boundary) {
1922
+ let { state } = boundary, { runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
2078
1923
  needsWalk && (state.walkOnNextFlush = !1), flushSerializer(boundary, state);
2079
1924
  let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
2080
- for (let channel; !boundary.aborted && (channel = state.serializer.pendingReadyChannel());) {
2081
- let resumes = state.serializer.stringifyScopes([], boundary, channel), deps = state.serializer.takeChannelDeps();
2082
- state.needsMainRuntime = !0, readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
1925
+ for (let channel; !boundary.aborted && (channel = pendingReadyChannel(state.serializer));) {
1926
+ let resumes = stringifyScopes(state.serializer, [], boundary, channel), deps = takeChannelDeps(state.serializer);
1927
+ state.needsWalkerRuntime = !0, readyResumeScripts = concatScripts(readyResumeScripts, state.readyScript(channel.readyId, concatSequence(depsMarker(deps), resumes)));
2083
1928
  }
2084
1929
  readyResumeScripts && (needsWalk = !0);
2085
1930
  let effects = this.async ? "" : joinHeldEffects(this.takeHeldEffects(), this.effects), { html, scripts } = this;
2086
- html && state.hasReorderRuntime && (html = state.mark("*", "") + html), state.needsMainRuntime && !state.hasMainRuntime && (state.hasMainRuntime = !0, scripts = concatScripts(scripts, "(e=>(self[e]||=(l,f=e+l,s=f.length,a={},d=[],t=document,n=t.createTreeWalker(t,129))=>t=self[e][l]={i:f,d:t,l:a,v:d,x(){},w(e,l,r){for(;e=n.nextNode();)t.x(l=(l=e.data)&&!l.indexOf(f)&&(r=l.slice(s+1),(l=l[s])>\"#\"||(a[r]=e),l),r,e),l>\"#\"&&d.push(e)}},self[e]))(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")")), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\"");
1931
+ html && state.hasReorderRuntime && (html = state.mark("*", "") + html), state.needsWalkerRuntime && !state.hasWalkerRuntime && (state.hasWalkerRuntime = !0, scripts = concatScripts(scripts, state.runtimeScript())), scripts = concatScripts(scripts, readyResumeScripts), effects && (needsWalk = !0, state.resumes = state.resumes ? state.resumes + ",\"" + effects + "\"" : "\"" + effects + "\"");
2087
1932
  let reordered = "", needsResumeArray = !1;
2088
1933
  if (state.writeReorders) {
2089
1934
  for (let reorderedChunk of state.writeReorders) {
@@ -2109,9 +1954,9 @@ var State = class {
2109
1954
  }
2110
1955
  flushHTML(boundary) {
2111
1956
  let { state } = boundary;
2112
- this.flushScript(boundary);
1957
+ this.flush(boundary);
2113
1958
  let { html, scripts } = this;
2114
- return this.html = this.scripts = "", state.flushChunk(html, scripts, boundary.count);
1959
+ return this.html = this.scripts = "", state.joinFlush(html, scripts, boundary.count);
2115
1960
  }
2116
1961
  };
2117
1962
  function renderReorderPlaceholders(reorder, reorders) {
@@ -2130,7 +1975,7 @@ function followHeldEffects(chunk) {
2130
1975
  held !== chunk && (held.effects = concatEffects(held.effects, chunk.effects), chunk.effects = "");
2131
1976
  }
2132
1977
  function lastHeldOf(held, cur) {
2133
- return cur.serializeState === held.serializeState && cur.boundary === held.boundary ? cur : held;
1978
+ return cur.channel === held.channel && cur.boundary === held.boundary ? cur : held;
2134
1979
  }
2135
1980
  function holdEffectsOn(heldEffects, chunk, effects) {
2136
1981
  return chunk.effects = effects, push(heldEffects, chunk);
@@ -2140,7 +1985,7 @@ function isWithin(boundary, outer) {
2140
1985
  return !!boundary;
2141
1986
  }
2142
1987
  function holdReorderEffects(head, boundary, effects) {
2143
- head.serializeState.readyId || (head.effects && (head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(head.boundary, null), head.effects)), head.effects = head.lastEffect = ""), head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(boundary, null), effects);
1988
+ head.channel.readyId || (head.effects && (head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(head.boundary, null), head.effects)), head.effects = head.lastEffect = ""), head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(boundary, null), effects);
2144
1989
  }
2145
1990
  function joinHeldEffects(heldEffects, effects) {
2146
1991
  return concatEffects(reduce(heldEffects, joinUncaught, ""), effects);
@@ -2148,16 +1993,16 @@ function joinHeldEffects(heldEffects, effects) {
2148
1993
  function joinUncaught(joined, held) {
2149
1994
  return held.boundary.aborted ? joined : concatEffects(joined, held.effects);
2150
1995
  }
2151
- function flushSerializer(boundary, serializeState) {
2152
- let { state } = boundary, { serializer } = state, pending = serializer.pending(serializeState);
2153
- if (serializeState.flushScopes || pending) {
2154
- let { writeScopes, passiveScopes } = serializeState, isBlockingState = serializeState !== state, flushes = [];
1996
+ function flushSerializer(boundary, channel) {
1997
+ let { state } = boundary, { serializer } = state, pending = hasMatchingCalls(serializer, channel.readyId);
1998
+ if (channel.flushScopes || pending) {
1999
+ let { writeScopes, passiveScopes } = channel, flushes = [];
2155
2000
  if (passiveScopes) for (let key in passiveScopes) {
2156
2001
  let props = writeScopes[key];
2157
2002
  props && (writeScopes[key] = Object.assign(passiveScopes[key], props), delete passiveScopes[key]);
2158
2003
  }
2159
- if (!isBlockingState && !state.hasGlobals) {
2160
- state.hasGlobals = !0;
2004
+ if (!channel.readyId && !state.hasWrittenGlobals) {
2005
+ state.hasWrittenGlobals = !0;
2161
2006
  let globals = getFilteredGlobals(state.$global);
2162
2007
  globals && flushes.push([
2163
2008
  0,
@@ -2173,12 +2018,12 @@ function flushSerializer(boundary, serializeState) {
2173
2018
  props
2174
2019
  ]);
2175
2020
  }
2176
- (flushes.length || pending) && (isBlockingState && !state.hasGlobals && flushSerializerGlobals(boundary), serializeState.resumes = concatSequence(serializeState.resumes, serializer.stringifyScopes(flushes, boundary, serializeState))), serializeState.writeScopes = {}, serializeState.flushScopes = !1, pending && (state.walkOnNextFlush = !0);
2021
+ (flushes.length || pending) && (channel.readyId && !state.hasWrittenGlobals && flushSerializerGlobals(boundary), state.addResumes(channel, stringifyScopes(serializer, flushes, boundary, channel))), channel.writeScopes = {}, channel.flushScopes = !1, pending && (state.walkOnNextFlush = !0);
2177
2022
  }
2178
2023
  }
2179
2024
  function flushSerializerGlobals(boundary) {
2180
2025
  let { state } = boundary, globals = getFilteredGlobals(state.$global);
2181
- globals && (state.hasGlobals = !0, state.needsMainRuntime = !0, state.resumes = concatSequence(state.resumes, state.serializer.stringifyScopes([[
2026
+ globals && (state.hasWrittenGlobals = !0, state.needsWalkerRuntime = !0, state.resumes = concatSequence(state.resumes, stringifyScopes(state.serializer, [[
2182
2027
  0,
2183
2028
  globals,
2184
2029
  globals
@@ -2462,11 +2307,11 @@ function writeLoadAsset(assetId, flush, triggers) {
2462
2307
  let g = $global();
2463
2308
  writeAsset(g, addAsset(g, assetId, flush, triggers));
2464
2309
  }
2465
- function withPageAssets(template, runtime, assetId, runtimeId) {
2310
+ function withPageAssets(template, flush, assetId, runtimeId) {
2466
2311
  return Object.assign((input) => {
2467
2312
  let g = $global();
2468
2313
  runtimeId && (g[kAssets] || (g.runtimeId = runtimeId));
2469
- let asset = addAsset(g, assetId, runtime);
2314
+ let asset = addAsset(g, assetId, flush);
2470
2315
  return g.__flush__ ? (writeAsset(g, asset), writeWaitReady(assetId, template, input)) : (g.__flush__ = flushPage, template(input));
2471
2316
  }, template);
2472
2317
  }
@@ -2537,6 +2382,212 @@ function toObjectExpression(options) {
2537
2382
  //#endregion
2538
2383
  //#region src/common/compat-meta.ts
2539
2384
  //#endregion
2385
+ //#region src/common/for.ts
2386
+ function forIn(obj, cb) {
2387
+ for (let key in obj) cb(key, obj[key]);
2388
+ }
2389
+ function forOf(list, cb) {
2390
+ if (list) {
2391
+ let i = 0;
2392
+ for (let item of list) cb(item, i++);
2393
+ }
2394
+ }
2395
+ function forTo(to, from, step, cb) {
2396
+ let start = from || 0, delta = step || 1;
2397
+ for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
2398
+ }
2399
+ function forUntil(until, from, step, cb) {
2400
+ let start = from || 0, delta = step || 1;
2401
+ for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
2402
+ }
2403
+ //#endregion
2404
+ //#region src/html/for.ts
2405
+ function forOfBy(by, item, index) {
2406
+ return by ? typeof by == "string" ? item[by] : by(item, index) : index;
2407
+ }
2408
+ function forInBy(by, name, value) {
2409
+ return by ? by(name, value) : name;
2410
+ }
2411
+ function forStepBy(by, index) {
2412
+ return by ? by(index) : index;
2413
+ }
2414
+ //#endregion
2415
+ //#region src/html/control-flow.ts
2416
+ function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
2417
+ display ? resumesMarker(markerGuard, branchExprGuard, parentEndTag) && $chunk.writeHTML($chunk.boundary.state.mark("[", "")) : $chunk.writeHTML("<t hidden>");
2418
+ }
2419
+ function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2420
+ let branchId = _scope_id(), wrap = !display;
2421
+ wrap && $chunk.writeHTML("</t>"), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
2422
+ }
2423
+ function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2424
+ forBranches(by, cb, iterateForOf(list, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2425
+ }
2426
+ function iterateForOf(list, cb, by) {
2427
+ return (each) => each ? forOf(list, (item, index) => {
2428
+ let itemKey = forOfBy(by, item, index);
2429
+ each(itemKey, itemKey === index, item, index);
2430
+ }) : forOf(list, cb);
2431
+ }
2432
+ function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2433
+ forBranches(by, cb, iterateForIn(obj, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2434
+ }
2435
+ function iterateForIn(obj, cb, by) {
2436
+ return (each) => each ? forIn(obj, (key, value) => {
2437
+ each(forInBy(by, key, value), !1, key, value);
2438
+ }) : forIn(obj, cb);
2439
+ }
2440
+ function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2441
+ forBranches(by, cb, iterateForTo(to, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2442
+ }
2443
+ function iterateForTo(to, from, step, cb, by) {
2444
+ return (each) => {
2445
+ let index = 0;
2446
+ return each ? forTo(to, from, step, (value) => {
2447
+ let itemKey = forStepBy(by, value);
2448
+ each(itemKey, itemKey === index++, value);
2449
+ }) : forTo(to, from, step, cb);
2450
+ };
2451
+ }
2452
+ function _for_until(until, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2453
+ forBranches(by, cb, iterateForUntil(until, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2454
+ }
2455
+ function iterateForUntil(until, from, step, cb, by) {
2456
+ return (each) => {
2457
+ let index = 0;
2458
+ return each ? forUntil(until, from, step, (value) => {
2459
+ let itemKey = forStepBy(by, value);
2460
+ each(itemKey, itemKey === index++, value);
2461
+ }) : forUntil(until, from, step, cb);
2462
+ };
2463
+ }
2464
+ function forBranches(by, cb, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2465
+ if (branchGuard === 0) {
2466
+ iterate(0), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
2467
+ return;
2468
+ }
2469
+ let { state } = $chunk.boundary, resumeKeys = markerGuard !== 0, resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag), flushBranchIds = "", loopScopes;
2470
+ iterate((itemKey, sameAsIndex, a, b) => {
2471
+ let branchId = _peek_scope_id();
2472
+ resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(state.mark("[", flushBranchIds)), flushBranchIds = branchId + "")), withBranchId(branchId, cb, a, b);
2473
+ let branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { M: itemKey } : {});
2474
+ resumeMarker || (loopScopes = push(loopScopes, branchScope));
2475
+ }), loopScopes && writeScope(scopeId, { ["A" + accessor]: loopScopes }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
2476
+ }
2477
+ function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2478
+ let resumeBranch = branchGuard !== 0, resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag), branchId = _peek_scope_id(), chunk = $chunk, beforeBranch = resumeMarker && resumeBranch && !singleNode ? deferBranchStart(chunk) : void 0, branchIndex = resumeBranch ? withBranchId(branchId, cb) : cb(), shouldWriteBranch = resumeBranch && branchIndex !== void 0;
2479
+ beforeBranch !== void 0 && applyBranchStart(chunk, beforeBranch, shouldWriteBranch), shouldWriteBranch && (branchIndex || !resumeMarker) && writeScope(scopeId, {
2480
+ ["D" + accessor]: branchIndex || void 0,
2481
+ ["A" + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
2482
+ }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
2483
+ }
2484
+ function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
2485
+ return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
2486
+ }
2487
+ function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
2488
+ let endTag = parentEndTag || "";
2489
+ if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
2490
+ let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
2491
+ $chunk.writeHTML(mark + endTag);
2492
+ } else markerGuard === 0 ? $chunk.writeHTML(endTag) : $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
2493
+ }
2494
+ function _await(scopeId, accessor, promise, content, markerGuard) {
2495
+ let resumeMarker = markerGuard !== 0;
2496
+ if (!isPromise(promise)) {
2497
+ if (resumeMarker) {
2498
+ let branchId = _peek_scope_id();
2499
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, content, promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
2500
+ } else content(promise);
2501
+ return;
2502
+ }
2503
+ let chunk = $chunk, { boundary } = chunk, startId = _peek_scope_id(), after = chunk.next = chunk.forkRest(boundary);
2504
+ chunk.async = !0, captureContext(chunk), boundary.startAsync(), promise.then((value) => {
2505
+ if (chunk.async && (chunk.async = !1, !boundary.aborted)) {
2506
+ let { state } = boundary;
2507
+ chunk.render(() => {
2508
+ if (resumeMarker) {
2509
+ let branchId = _peek_scope_id();
2510
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withAsyncContent({ parent: getAsyncContent(chunk) }, content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
2511
+ } else {
2512
+ let renderedSince = _peek_scope_id() !== startId, async = { parent: getAsyncContent(chunk) };
2513
+ withAsyncContent(async, content, value), async.visit = renderedSince && (after.html || after.next) ? $chunk.boundary.state.mark("]", scopeId + " " + accessor) : "", async.resumed && $chunk.writeHTML(async.visit), async.end = $chunk;
2514
+ }
2515
+ }), !chunk.async && boundary.pendingReorders?.delete(chunk) && state.reorder(chunk), boundary.endAsync();
2516
+ }
2517
+ }, (err) => {
2518
+ chunk.async = !1, boundary.abort(err);
2519
+ });
2520
+ }
2521
+ function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
2522
+ let placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id(), chunk = $chunk, { boundary } = chunk, { state } = boundary, { resumeWrites } = boundary, beforeBranch = deferBranchStart(chunk), renderers = () => writeTryRenderers(branchId, catchContent && _resume(catchContent, catchId), placeholderContent && _resume(placeholderContent, placeholderId)), writesRenderers = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, branchId, renderers), keepsMarks = state.keepsTryMarks(chunk, resumeWrites);
2523
+ applyBranchStart(chunk, beforeBranch, keepsMarks), keepsMarks && (writesRenderers || renderers(), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
2524
+ }
2525
+ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
2526
+ let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
2527
+ if (body === body.render(content)) {
2528
+ chunk.append(body);
2529
+ return;
2530
+ }
2531
+ chunk.next = chunk.forkRest(boundary), captureContext(chunk), chunk.placeholder = {
2532
+ body,
2533
+ render: placeholder,
2534
+ branchId,
2535
+ scopeId,
2536
+ placeholderBranchId
2537
+ };
2538
+ }
2539
+ function tryBoundary(content, catchContent, branchId, renderers) {
2540
+ let chunk = $chunk, { boundary } = chunk, { state } = boundary, bodyBoundary = new Boundary(state, void 0, boundary);
2541
+ catchContent && (bodyBoundary.withinCatch = !0);
2542
+ let body = chunk.fork(bodyBoundary, null), bodyEnd = body.render(withBranchId, branchId, content);
2543
+ if (bodyBoundary.aborted) {
2544
+ if (!catchContent) throw bodyBoundary.reason;
2545
+ return catchContent(bodyBoundary.reason), !0;
2546
+ }
2547
+ if (body === bodyEnd) return chunk.append(body), !1;
2548
+ let renderersAtSettle = !bodyBoundary.resumeWrites, bodyNext = bodyEnd.next = chunk.forkRest(boundary);
2549
+ chunk.next = body, boundary.startAsync();
2550
+ let reorderId = catchContent ? state.nextReorderId() : "";
2551
+ return reorderId && (chunk.catchRange = {
2552
+ id: reorderId,
2553
+ end: bodyEnd
2554
+ }, captureContext(chunk)), bodyBoundary.onNext = () => {
2555
+ if (!boundary.aborted) {
2556
+ if (bodyBoundary.aborted) {
2557
+ if (!reorderId) {
2558
+ boundary.abort(bodyBoundary.reason);
2559
+ return;
2560
+ }
2561
+ let streamed = !chunk.catchRange, catchChunk = chunk.fork(boundary, null);
2562
+ chunk.catchRange = null, renderersAtSettle || catchChunk.render(clearTryRenderers, branchId);
2563
+ let inOrder = catchChunk === catchChunk.render(catchContent, bodyBoundary.reason);
2564
+ if (boundary.aborted) return;
2565
+ if ((bodyEnd.consumed || !inOrder) && (catchChunk.reorderBranch = branchId), bodyEnd.consumed) catchChunk.reorderId = reorderId, state.reorder(catchChunk);
2566
+ else {
2567
+ let reorder = null;
2568
+ inOrder ? streamed && (reorder = chunk.fork(boundary, null)) : reorder = catchChunk, reorder && (reorder.reorderId = reorderId);
2569
+ let endMarker = state.mark("!", reorderId), cut = body;
2570
+ for (; cut.consumed;) cut = cut.next;
2571
+ cut.async = !1, cut.next = inOrder ? catchChunk : bodyNext, cut.html = streamed ? endMarker : inOrder ? "" : state.mark("!^", reorderId) + endMarker, cut.scripts = cut.effects = cut.lastEffect = "", cut.placeholder = cut.reorderId = cut.catchRange = null, cut.deferredReorder = reorder, inOrder && (catchChunk.next = bodyNext);
2572
+ }
2573
+ boundary.endAsync();
2574
+ } else bodyBoundary.count ? boundary.onNext() : (renderersAtSettle && bodyBoundary.resumeWrites && bodyEnd.render(renderers), chunk.catchRange = null, boundary.endAsync());
2575
+ }
2576
+ }, renderersAtSettle;
2577
+ }
2578
+ function clearTryRenderers(branchId) {
2579
+ writeScope(branchId, {
2580
+ E: 0,
2581
+ Q: _scope_with_id(branchId).Q && 0
2582
+ });
2583
+ }
2584
+ function writeTryRenderers(branchId, catchContent, placeholderContent) {
2585
+ writeScope(branchId, {
2586
+ E: catchContent,
2587
+ Q: placeholderContent
2588
+ });
2589
+ }
2590
+ //#endregion
2540
2591
  //#region src/html/compat.ts
2541
2592
  function drainClassFunctions($global, writeScope) {
2542
2593
  let pending = pendingClassFunctions.get($global), scopeByHost = {};