marko 6.4.5 → 6.4.7

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 (145) hide show
  1. package/cheatsheet.md +2 -1
  2. package/dist/common/errors.d.ts +3 -1
  3. package/dist/common/helpers.d.ts +7 -7
  4. package/dist/debug/dom/catch.feat.js +4 -4
  5. package/dist/debug/dom/catch.feat.mjs +4 -4
  6. package/dist/debug/dom/controllable-input.feat.js +1 -1
  7. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  8. package/dist/debug/dom/controllable-open.feat.js +1 -1
  9. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  10. package/dist/debug/dom/controllable-select.feat.js +1 -1
  11. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  12. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  13. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  14. package/dist/debug/dom/controllable.feat.js +5 -5
  15. package/dist/debug/dom/controllable.feat.mjs +5 -5
  16. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  17. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  18. package/dist/debug/dom/dynamic-tag-var.feat.js +2 -2
  19. package/dist/debug/dom/dynamic-tag-var.feat.mjs +2 -2
  20. package/dist/debug/dom/lazy.feat.js +1 -1
  21. package/dist/debug/dom/lazy.feat.mjs +1 -1
  22. package/dist/debug/dom/placeholder.feat.js +1 -1
  23. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  24. package/dist/debug/{dom-BeY1nGUb.mjs → dom-CFCBDift.mjs} +133 -135
  25. package/dist/debug/{dom-CUxvM4i9.js → dom-D8znnhpf.js} +148 -150
  26. package/dist/debug/dom.js +21 -22
  27. package/dist/debug/dom.mjs +22 -22
  28. package/dist/debug/html.js +736 -664
  29. package/dist/debug/html.mjs +736 -665
  30. package/dist/dom/catch.feat.js +5 -5
  31. package/dist/dom/catch.feat.mjs +4 -4
  32. package/dist/dom/control-flow.d.ts +3 -3
  33. package/dist/dom/controllable-input.feat.js +2 -2
  34. package/dist/dom/controllable-input.feat.mjs +1 -1
  35. package/dist/dom/controllable-open.feat.js +2 -2
  36. package/dist/dom/controllable-open.feat.mjs +1 -1
  37. package/dist/dom/controllable-select.feat.js +2 -2
  38. package/dist/dom/controllable-select.feat.mjs +1 -1
  39. package/dist/dom/controllable-textarea.feat.js +2 -2
  40. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  41. package/dist/dom/controllable.d.ts +4 -4
  42. package/dist/dom/controllable.feat.js +2 -2
  43. package/dist/dom/controllable.feat.mjs +2 -2
  44. package/dist/dom/dom.d.ts +5 -5
  45. package/dist/dom/dynamic-tag-script.feat.js +2 -2
  46. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  47. package/dist/dom/dynamic-tag-var.feat.js +3 -3
  48. package/dist/dom/dynamic-tag-var.feat.mjs +2 -2
  49. package/dist/dom/lazy.feat.js +1 -1
  50. package/dist/dom/lazy.feat.mjs +1 -1
  51. package/dist/dom/placeholder.feat.js +2 -2
  52. package/dist/dom/placeholder.feat.mjs +1 -1
  53. package/dist/dom/renderer.d.ts +1 -3
  54. package/dist/dom/resume.d.ts +2 -3
  55. package/dist/dom/signals.d.ts +6 -8
  56. package/dist/{dom-Diu8MpmL.js → dom-Bpkm72vV.js} +157 -166
  57. package/dist/{dom-DefWmvQB.mjs → dom-CVAevsbz.mjs} +103 -107
  58. package/dist/dom.d.ts +1 -1
  59. package/dist/dom.js +37 -37
  60. package/dist/dom.mjs +22 -22
  61. package/dist/html/assets.d.ts +2 -2
  62. package/dist/html/compat.d.ts +2 -1
  63. package/dist/html/control-flow.d.ts +20 -0
  64. package/dist/html/inlined-runtimes.d.ts +2 -2
  65. package/dist/html/inlined-runtimes.debug.d.ts +2 -2
  66. package/dist/html/serializer.d.ts +63 -16
  67. package/dist/html/template.d.ts +1 -1
  68. package/dist/html/writer.d.ts +47 -35
  69. package/dist/html.d.ts +3 -2
  70. package/dist/html.js +531 -484
  71. package/dist/html.mjs +531 -484
  72. package/dist/translator/core/for.d.ts +0 -4
  73. package/dist/translator/core/return.d.ts +0 -3
  74. package/dist/translator/core/style.d.ts +2 -2
  75. package/dist/translator/index.js +8093 -8021
  76. package/dist/translator/util/analyze-errors.d.ts +2 -1
  77. package/dist/translator/util/assert.d.ts +15 -1
  78. package/dist/translator/util/bindings.d.ts +24 -12
  79. package/dist/translator/util/body-to-text.d.ts +9 -0
  80. package/dist/translator/util/branch-tag.d.ts +10 -3
  81. package/dist/translator/util/build-string-expression.d.ts +4 -0
  82. package/dist/translator/util/content-derives.d.ts +7 -0
  83. package/dist/translator/util/cyclic-memo.d.ts +6 -2
  84. package/dist/translator/util/entry-builder.d.ts +6 -3
  85. package/dist/translator/util/finalize-references.d.ts +6 -3
  86. package/dist/translator/util/for-selector.d.ts +1 -1
  87. package/dist/translator/util/generate-uid.d.ts +4 -2
  88. package/dist/translator/util/get-root.d.ts +3 -3
  89. package/dist/translator/util/get-tag-name.d.ts +1 -1
  90. package/dist/translator/util/known-tag.d.ts +14 -9
  91. package/dist/translator/util/module-read.d.ts +0 -3
  92. package/dist/translator/util/module-registrations.d.ts +44 -0
  93. package/dist/translator/util/nested-attribute-tags.d.ts +1 -1
  94. package/dist/translator/util/optional.d.ts +7 -2
  95. package/dist/translator/util/params-tree.d.ts +18 -0
  96. package/dist/translator/util/reasons.d.ts +13 -8
  97. package/dist/translator/util/references.d.ts +23 -27
  98. package/dist/translator/util/runtime.d.ts +0 -12
  99. package/dist/translator/util/scope-accessor.d.ts +0 -1
  100. package/dist/translator/util/scope-read.d.ts +3 -0
  101. package/dist/translator/util/section-renderer.d.ts +4 -0
  102. package/dist/translator/util/sections.d.ts +21 -21
  103. package/dist/translator/util/setup-work.d.ts +2 -1
  104. package/dist/translator/util/signals.d.ts +16 -14
  105. package/dist/translator/util/simplify-fn.d.ts +1 -0
  106. package/dist/translator/util/slots.d.ts +4 -4
  107. package/dist/translator/util/solve-reasons.d.ts +1 -3
  108. package/dist/translator/util/sources.d.ts +2 -1
  109. package/dist/translator/util/state.d.ts +4 -2
  110. package/dist/translator/util/statement-tag.d.ts +2 -0
  111. package/dist/translator/util/static-text.d.ts +2 -1
  112. package/dist/translator/util/structure.d.ts +0 -10
  113. package/dist/translator/util/tag-facts.d.ts +8 -1
  114. package/dist/translator/util/tag-import.d.ts +20 -0
  115. package/dist/translator/util/tag-name-type.d.ts +9 -2
  116. package/dist/translator/util/to-only-or-block.d.ts +3 -0
  117. package/dist/translator/util/to-property-name.d.ts +2 -0
  118. package/dist/translator/util/translate-attrs.d.ts +7 -5
  119. package/dist/translator/util/translate-var.d.ts +2 -0
  120. package/dist/translator/util/traverse.d.ts +1 -2
  121. package/dist/translator/util/visitors.d.ts +4 -1
  122. package/dist/translator/util/with-previous-location.d.ts +1 -1
  123. package/dist/translator/util/write-guard.d.ts +2 -2
  124. package/dist/translator/util/writer.d.ts +1 -2
  125. package/dist/translator/visitors/export-declaration.d.ts +2 -3
  126. package/dist/translator/visitors/function.d.ts +0 -35
  127. package/dist/translator/visitors/import-declaration.d.ts +1 -15
  128. package/dist/translator/visitors/placeholder.d.ts +2 -1
  129. package/dist/translator/visitors/program/html.d.ts +0 -1
  130. package/dist/translator/visitors/program/index.d.ts +4 -5
  131. package/dist/translator/visitors/program/pre-analyze.d.ts +2 -0
  132. package/dist/translator/visitors/tag/custom-tag.d.ts +0 -14
  133. package/dist/translator/visitors/tag/dynamic-tag.d.ts +1 -0
  134. package/dist/translator/visitors/tag/native-tag.d.ts +3 -12
  135. package/package.json +4 -4
  136. package/dist/translator/util/binding-has-prop.d.ts +0 -8
  137. package/dist/translator/util/binding-prop-tree.d.ts +0 -18
  138. package/dist/translator/util/body-to-text-literal.d.ts +0 -9
  139. package/dist/translator/util/import-reference.d.ts +0 -3
  140. package/dist/translator/util/normalize-string-expression.d.ts +0 -4
  141. package/dist/translator/util/plugin-hooks.d.ts +0 -4
  142. package/dist/translator/util/resolve-relative-to-entry.d.ts +0 -2
  143. package/dist/translator/util/set-tag-derived-from.d.ts +0 -7
  144. package/dist/translator/util/to-first-expression-or-block.d.ts +0 -2
  145. package/dist/translator/util/to-first-statement-or-block.d.ts +0 -2
package/dist/html.js CHANGED
@@ -245,22 +245,17 @@ 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) || {};
255
255
  rendered = !0, (() => {
256
256
  if (_scope_id(), _html(`<${renderer}${_attrs(input, "a", branchId, renderer)}>`), !voidElementsReg.test(renderer)) {
257
257
  let renderContent = content || normalizeDynamicRenderer(input.content);
258
- if (renderer === "textarea") _html(_attrs_textarea_value(branchId, "a", input));
259
- else {
260
- if (renderContent && typeof renderContent != "function") throw Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
261
- renderer === "select" && ("value" in input || "valueChange" in input) ? _attr_select_value(branchId, "a", input.value, input.valueChange, renderContent ? () => _dynamic_tag(branchId, "a", renderContent, void 0, 0, void 0, markerGuard) : void 0, 1) : renderContent && _dynamic_tag(branchId, "a", renderContent, void 0, 0, void 0, markerGuard);
262
- }
263
- _html(`</${renderer}>`);
258
+ renderer === "textarea" ? _html(_attrs_textarea_value(branchId, "a", input)) : renderer === "select" && ("value" in input || "valueChange" in input) ? _attr_select_value(branchId, "a", input.value, input.valueChange, renderContent ? () => _dynamic_tag(branchId, "a", renderContent, void 0, 0, void 0, markerGuard) : void 0, 1) : renderContent && _dynamic_tag(branchId, "a", renderContent, void 0, 0, void 0, markerGuard), _html(`</${renderer}>`);
264
259
  }
265
260
  let childScope = getScopeById(branchId), needsScript = childScope && (childScope.Ia || childScope.Ea);
266
261
  needsScript && _script(branchId, "_d"), (shouldResume || needsScript) && _html(state.mark("(", scopeId + " " + accessor + " " + branchId));
@@ -268,7 +263,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
268
263
  } else {
269
264
  let chunk = getChunk(), beforeBranch = shouldResume ? deferBranchStart(chunk) : void 0, render = () => {
270
265
  if (renderer) try {
271
- return _set_scope_reason(shouldResume ? CLIENT_ALL : 0), inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
266
+ return _set_scope_reason(shouldResume ? ALL_GROUPS : 0), inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
272
267
  ...inputOrArgs,
273
268
  content
274
269
  } : inputOrArgs);
@@ -281,11 +276,11 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
281
276
  }
282
277
  return rendered ? shouldResume && writeScope(scopeId, { ["D" + accessor]: rendererKey(renderer) }) : _scope_id(), result;
283
278
  }, patchDynamicTag = /* @__PURE__ */ ((originalDynamicTag) => (patch) => {
284
- _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, resume, tagVar) => {
279
+ _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, markerGuard, tagVar) => {
285
280
  let patched = patch(tag, scopeId, accessor);
286
- return patched !== tag && (patched.a = tag), originalDynamicTag(scopeId, accessor, patched, input, content, inputIsArgs, resume, tagVar);
281
+ return patched !== tag && (patched.a = tag), originalDynamicTag(scopeId, accessor, patched, input, content, inputIsArgs, markerGuard, tagVar);
287
282
  };
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 = {
283
+ })(_dynamic_tag), _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
284
  $global,
290
285
  writeLoadAsset,
291
286
  fork: _await,
@@ -321,7 +316,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
321
316
  return function() {
322
317
  let compatRegistered = COMPAT_REGISTRY.get(this);
323
318
  if (!compatRegistered) {
324
- let registered = getRegistered(this);
319
+ let registered = REGISTRY.get(this);
325
320
  if (registered) {
326
321
  let scopeId = registered.scope ? getScopeId(registered.scope) : void 0;
327
322
  scopeId !== void 0 && _script(scopeId, SET_SCOPE_REGISTER_ID), COMPAT_REGISTRY.set(this, compatRegistered = [registered.id, scopeId]);
@@ -353,8 +348,8 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
353
348
  flushScript(chunk, reorders) {
354
349
  let { boundary } = chunk, { state } = boundary, html = "", scripts = "";
355
350
  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;
357
- if (boundary.count) throw Error("Cannot serialize promise across tags/class compat layer.");
351
+ if (boundary.flush() === 0 && ({html, scripts} = chunk.flush(boundary)), boundary.aborted) throw boundary.reason;
352
+ if (boundary.count) throw /* @__PURE__ */ Error();
358
353
  return {
359
354
  html,
360
355
  scripts
@@ -380,7 +375,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
380
375
  writeScope(scopeId, { m5c: component.id }), _script(scopeId, SET_SCOPE_REGISTER_ID);
381
376
  }
382
377
  }), head.render(() => {
383
- _set_scope_reason(willRerender ? CLIENT_ALL : 0);
378
+ _set_scope_reason(willRerender ? ALL_GROUPS : 0);
384
379
  try {
385
380
  renderer(normalizedInput);
386
381
  } finally {
@@ -413,7 +408,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
413
408
  registerClassFunctions(input) {
414
409
  for (let key in input) {
415
410
  let value = input[key];
416
- typeof value == "function" && !getRegistered(value) && register(RENDER_BODY_ID, value);
411
+ typeof value == "function" && !REGISTRY.has(value) && register(RENDER_BODY_ID, value);
417
412
  }
418
413
  },
419
414
  registerClassFunction($global, id, fn, hostId) {
@@ -441,10 +436,10 @@ function* attrTagIterator() {
441
436
  }
442
437
  //#endregion
443
438
  //#region src/common/helpers.ts
444
- function stringifyClassObject(name, value) {
439
+ function stringifyClassEntry(name, value) {
445
440
  return value ? name : "";
446
441
  }
447
- function stringifyStyleObject(name, value) {
442
+ function stringifyStyleEntry(name, value) {
448
443
  return value || value === 0 ? escapeStyleAttr(name) + ":" + escapeStyleAttr(value + "") : "";
449
444
  }
450
445
  function escapeStyleAttr(str) {
@@ -458,17 +453,17 @@ function escapeStyleValue(str) {
458
453
  function isEventHandler(name) {
459
454
  return /^on[A-Z-]/.test(name);
460
455
  }
461
- function getEventHandlerName(name) {
456
+ function getEventType(name) {
462
457
  return name[2] === "-" ? name.slice(3) : name.slice(2).toLowerCase();
463
458
  }
464
459
  function hasKeys(obj) {
465
460
  for (let _ in obj) return !0;
466
461
  return !1;
467
462
  }
468
- function isVoid(value) {
463
+ function isNullishOrFalse(value) {
469
464
  return value == null || value === !1;
470
465
  }
471
- function isNotVoid(value) {
466
+ function isNotNullishOrFalse(value) {
472
467
  return value != null && value !== !1;
473
468
  }
474
469
  function isPromise(value) {
@@ -486,27 +481,9 @@ function normalizeDynamicRenderer(value) {
486
481
  function _assert_class_toggles(classes, toggles) {}
487
482
  function _el_read_error() {}
488
483
  function _hoist_read_error() {}
484
+ function _signal_read_error() {}
489
485
  function _assert_hoist(value) {}
490
486
  //#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
487
  //#region src/common/opt.ts
511
488
  function reduce(opt, cb, acc) {
512
489
  if (opt) {
@@ -536,14 +513,44 @@ var State$1 = class {
536
513
  buf = [];
537
514
  strs = /* @__PURE__ */ new Map();
538
515
  refs = /* @__PURE__ */ new WeakMap();
539
- pendingAssignments = /* @__PURE__ */ new Set();
516
+ deferredRefs = /* @__PURE__ */ new Set();
540
517
  boundary;
541
518
  channel = void 0;
542
519
  channelDeps = null;
543
- mutated = [];
520
+ queuedCalls = [];
521
+ queuedReadyCalls = [];
522
+ scopeRef(scope, scopeId) {
523
+ return this.refs.get(scope) || newScopeReference(this, scope, scopeId);
524
+ }
525
+ writeScopeProps(props, ref) {
526
+ return writeObjectProps(this, props, ref);
527
+ }
528
+ scopesCursor(scopeId) {
529
+ return scopeId + ",";
530
+ }
531
+ writeTrailing(scopesIndex) {
532
+ let { buf } = this;
533
+ return ~scopesIndex && (buf[scopesIndex] = "_([" + buf[scopesIndex], buf.push("])")), writeDeferred(this), ",0)";
534
+ }
535
+ wrapPayload(result, extras) {
536
+ let arrow = this.wroteUndefined ? "(_,$)=>" : "_=>";
537
+ return this.wroteUndefined = !1, extras ? arrow + result : arrow + "[" + result + "]";
538
+ }
539
+ writeScopedRegistration(val, parent, accessor, registered) {
540
+ let ref = new Reference(parent, accessor, this.flushId, this.buf.length);
541
+ ref.channel = this.channel, this.refs.set(val, ref);
542
+ let scope = registered.scope, scopeId = scope[K_SCOPE_ID];
543
+ trackScope(this, scope, scopeId);
544
+ let locals = registered.locals?.(this.boundary.state.scope);
545
+ if (locals) {
546
+ this.buf.push(registered.access + "(_(" + scopeId + ")");
547
+ for (let local of locals) this.buf.push(","), writePlainObject(this, local, newArgReference(this, ref, local));
548
+ } else this.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
549
+ this.buf.push(")");
550
+ }
544
551
  }, Reference = class {
545
552
  assignments = null;
546
- calls = null;
553
+ deferredMembers = null;
547
554
  scopeId = void 0;
548
555
  channel = void 0;
549
556
  parent;
@@ -555,136 +562,121 @@ var State$1 = class {
555
562
  constructor(parent, accessor, flushId, pos = null, id = null) {
556
563
  this.parent = parent, this.accessor = accessor, this.flushId = flushId, this.pos = pos, this.id = id;
557
564
  }
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
- });
565
+ };
566
+ function stringifyScopes(state, flushes, boundary, channel) {
567
+ try {
568
+ return state.boundary = boundary, state.channel = channel, writeScopesRoot(state, flushes);
569
+ } catch (err) {
570
+ return abortRender(boundary, err), "";
571
+ } finally {
572
+ state.flushId++, state.buf = [];
589
573
  }
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;
574
+ }
575
+ function pendingReadyChannel(state) {
576
+ let calls = state.queuedReadyCalls;
577
+ return calls.length ? calls[0].channel : void 0;
578
+ }
579
+ function takeChannelDeps(state) {
580
+ let deps = state.channelDeps;
581
+ return state.channelDeps = null, deps;
582
+ }
583
+ function queueCall(state, value, object, method, channel) {
584
+ (channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
585
+ method,
586
+ value,
587
+ object,
588
+ channel,
589
+ valueId: null
590
+ });
591
+ }
592
+ function dropQueuedCall(state, value, object, method, channel) {
593
+ let queuedCalls = channel?.readyId ? state.queuedReadyCalls : state.queuedCalls;
594
+ for (let i = 0; i < queuedCalls.length; i++) {
595
+ let call = queuedCalls[i];
596
+ if (call.value === value && call.object === object && call.method === method) return queuedCalls.splice(i, 1), !0;
597
597
  }
598
- };
599
- function register(id, val, scope, locals) {
598
+ return !1;
599
+ }
600
+ function register(id, val, scope, locals, access = "_._" + toAccess(toObjectKey(id))) {
600
601
  return REGISTRY.set(val, {
601
602
  id,
602
603
  scope,
603
604
  locals,
604
- access: "_._" + toAccess(toObjectKey(id))
605
+ access
605
606
  }), val;
606
607
  }
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
608
  function writeScopesRoot(state, flushes) {
615
- let { buf } = state, nextSlotId = -1, fillIndex = -1;
609
+ let { buf } = state, nextSlotId = -1, scopesIndex = -1;
616
610
  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();
611
+ let scopeId = flush[0], scope = flush[1], ref = state.scopeRef(scope, scopeId), openIndex = buf.push("") - 1;
612
+ 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
613
  }
620
614
  let extras = "";
621
- (state.pendingAssignments.size || hasChannelMutations(state)) && (extras = ",0)", fillIndex !== -1 && (buf[fillIndex] = "_([" + buf[fillIndex], buf.push("])")), writeAssigned(state));
615
+ (state.deferredRefs.size || hasChannelCalls(state)) && (extras = state.writeTrailing(scopesIndex));
622
616
  let result = extras && "(";
623
617
  for (let chunk of buf) result += chunk;
624
- if (result += extras, !result) return "";
625
- let arrow = state.wroteUndefined ? "(_,$)=>" : "_=>";
626
- return state.wroteUndefined = !1, extras ? arrow + result : arrow + "[" + result + "]";
618
+ return result += extras, result ? state.wrapPayload(result, extras) : "";
627
619
  }
628
- function writeAssigned(state) {
620
+ function writeDeferred(state) {
629
621
  let sep = state.buf.length ? "," : "";
630
- if (state.pendingAssignments.size) {
631
- let pending = state.pendingAssignments;
632
- state.pendingAssignments = /* @__PURE__ */ new Set();
622
+ if (state.deferredRefs.size) {
623
+ let pending = state.deferredRefs;
624
+ state.deferredRefs = /* @__PURE__ */ new Set();
633
625
  let buf = "", hasCalls = !1;
634
- for (let ref of pending) ref.assignments && (buf += sep + assignmentsToString(ref.assignments, ref.id), ref.assignments = null, sep = ","), hasCalls ||= ref.calls !== null;
635
- if (buf && state.buf.push(buf), hasCalls) {
636
- for (let ref of pending) if (ref.calls) {
637
- for (let { method, args } of ref.calls) {
638
- state.buf.push((state.buf.length ? "," : "") + ref.id + "." + method + "(");
639
- for (let a = 0; a < args.length; a++) a && state.buf.push(","), writeCallArg(state, args[a]);
640
- state.buf.push(")");
641
- }
642
- ref.calls = null;
643
- }
626
+ for (let ref of pending) ref.assignments && (buf += sep + assignmentsToString(ref.assignments, ref.id), ref.assignments = null, sep = ","), hasCalls ||= ref.deferredMembers !== null;
627
+ if (buf && state.buf.push(buf), hasCalls) for (let ref of pending) {
628
+ let members = ref.deferredMembers;
629
+ members && (writeDeferredMembers(state, ref.id, members), ref.deferredMembers = null);
644
630
  }
645
631
  }
646
- if (hasChannelMutations(state)) {
632
+ let readyId = state.channel?.readyId, calls = state.queuedCalls;
633
+ if (readyId) {
634
+ calls = [];
647
635
  let remaining = [];
648
- for (let mutation of state.mutated) {
649
- if (!mutationMatchesReadyId(mutation, state.channel?.readyId)) {
650
- remaining.push(mutation);
651
- continue;
652
- }
653
- let hasSeen = state.refs.get(mutation.object)?.id, objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
654
- if (writeProp(state, mutation.object, null, "")) {
655
- let objectRef = state.refs.get(mutation.object);
656
- 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(")")));
657
- } else state.buf.push("void 0");
658
- let valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
659
- if (mutation.value !== void 0) {
660
- if (writeProp(state, mutation.value, null, "")) {
661
- let valueRef = typeof mutation.value == "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
662
- valueRef && !valueRef.id && valueRef.scopeId === void 0 && !isAncestorChannelRef(state, valueRef) && (valueRef.id = mutation.valueId || nextRefAccess(state), state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex]);
663
- } else state.buf.push("void 0");
664
- }
665
- state.buf.push(")");
666
- }
667
- state.mutated = remaining;
636
+ for (let call of state.queuedReadyCalls) (call.channel.readyId === readyId ? calls : remaining).push(call);
637
+ state.queuedReadyCalls = remaining;
638
+ } else calls.length && (state.queuedCalls = []);
639
+ for (let call of calls) {
640
+ let objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
641
+ if (writeProp(state, call.object, null, "")) {
642
+ let objectRef = state.refs.get(call.object);
643
+ !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(")"));
644
+ } else state.buf.push("void 0");
645
+ state.buf.push("." + call.method + "("), call.value !== void 0 && writeCallArg(state, call.value, call.valueId), state.buf.push(")");
646
+ }
647
+ state.deferredRefs.size && writeDeferred(state);
648
+ }
649
+ function writeDeferredMembers(state, id, { collection, first, rest }) {
650
+ if (collection instanceof Map) {
651
+ writeDeferredEntry(state, id, first);
652
+ for (let entry of rest) writeDeferredEntry(state, id, entry);
653
+ } else {
654
+ writeDeferredMember(state, id, first);
655
+ for (let member of rest) writeDeferredMember(state, id, member);
668
656
  }
669
- state.pendingAssignments.size && writeAssigned(state);
670
657
  }
671
- function writeCallArg(state, val) {
658
+ function writeDeferredEntry(state, id, [key, value]) {
659
+ 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(")");
660
+ }
661
+ function writeDeferredMember(state, id, member) {
662
+ state.buf.push("," + id + ".add("), member !== void 0 && writeCallArg(state, member, null), state.buf.push(")");
663
+ }
664
+ function writeCallArg(state, val, valueId) {
665
+ let startIndex = state.buf.length;
672
666
  if (val === void 0) state.wroteUndefined = !0, state.buf.push("$");
673
667
  else if (writeProp(state, val, null, "")) {
674
- let ref = state.refs.get(val) || state.strs.get(val);
675
- ref && ensureId(state, ref);
668
+ let ref = typeof val == "string" ? state.strs.get(val) : state.refs.get(val);
669
+ ref && !ref.id && ref.scopeId === void 0 && !isAncestorChannelRef(state, ref) && (ref.id = valueId || nextRefAccess(state), state.buf[startIndex] = ref.id + "=" + state.buf[startIndex]);
676
670
  } else state.buf.push("void 0");
677
671
  }
678
- function hasChannelMutations(state) {
679
- return hasMatchingMutations(state.mutated, state.channel?.readyId);
672
+ function hasChannelCalls(state) {
673
+ return hasMatchingCalls(state, state.channel?.readyId);
680
674
  }
681
- function hasMatchingMutations(mutated, readyId) {
682
- for (let mutation of mutated) if (mutationMatchesReadyId(mutation, readyId)) return !0;
675
+ function hasMatchingCalls(state, readyId) {
676
+ if (!readyId) return state.queuedCalls.length > 0;
677
+ for (let call of state.queuedReadyCalls) if (call.channel.readyId === readyId) return !0;
683
678
  return !1;
684
679
  }
685
- function mutationMatchesReadyId(mutation, readyId) {
686
- return mutation.channel?.readyId ? mutation.channel.readyId === readyId : !readyId;
687
- }
688
680
  function writeProp(state, val, parent, accessor) {
689
681
  switch (typeof val) {
690
682
  case "string": return writeString(state, val, parent, accessor);
@@ -699,7 +691,7 @@ function writeProp(state, val, parent, accessor) {
699
691
  }
700
692
  function writeReferenceOr(state, write, val, parent, accessor) {
701
693
  let ref = state.refs.get(val);
702
- 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;
694
+ 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;
703
695
  let registered = REGISTRY.get(val);
704
696
  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));
705
697
  }
@@ -716,19 +708,7 @@ function quoteRegisterId(id) {
716
708
  }
717
709
  function writeRegistered(state, val, parent, accessor, registered) {
718
710
  let { scope } = registered;
719
- if (scope) {
720
- let ref = new Reference(parent, accessor, state.flushId, state.buf.length);
721
- ref.channel = state.channel, state.refs.set(val, ref);
722
- let scopeId = scope[K_SCOPE_ID];
723
- trackScope(state, scope, scopeId);
724
- let locals = registered.locals?.(state.boundary.state.scope);
725
- if (locals) {
726
- state.buf.push(registered.access + "(_(" + scopeId + ")");
727
- for (let local of locals) state.buf.push(","), writePlainObject(state, local, newArgReference(state, ref, local));
728
- } else state.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
729
- state.buf.push(")");
730
- } else state.buf.push(registered.access);
731
- return !0;
711
+ return scope ? state.writeScopedRegistration(val, parent, accessor, registered) : state.buf.push(registered.access), !0;
732
712
  }
733
713
  function writeString(state, val, parent, accessor) {
734
714
  if (val.length > 12) {
@@ -864,7 +844,7 @@ function writeRegExp(state, val) {
864
844
  }
865
845
  function writePromise(state, val, ref) {
866
846
  let { boundary, channel } = state, pId = nextRefAccess(state), handle = newAsyncHandle(state, ref, pId);
867
- 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;
847
+ 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;
868
848
  }
869
849
  function newAsyncHandle(state, parent, id) {
870
850
  let handle = {}, handleRef = new Reference(parent, null, state.flushId, null, id);
@@ -872,23 +852,25 @@ function newAsyncHandle(state, parent, id) {
872
852
  }
873
853
  function writeMap(state, val, ref) {
874
854
  if (!val.size) return state.buf.push("new Map"), !0;
875
- let items = [], assignments, needsId, deferring = !1, i = 0;
855
+ let items = [], assignments, needsId, i = 0, entries = val.entries();
876
856
  if (val.size < 25) {
877
- for (let [itemKey, itemValue] of val) {
878
- if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
879
- deferCall(state, ref, "set", [itemKey, itemValue]);
880
- continue;
857
+ for (let entry of entries) {
858
+ let [itemKey, itemValue] = entry;
859
+ if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
860
+ if (deferMembers(state, ref, val, entry, entries), !i) return state.buf.push("new Map"), !0;
861
+ break;
881
862
  }
882
- 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]);
863
+ 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]);
883
864
  }
884
865
  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);
885
866
  } else {
886
- for (let [itemKey, itemValue] of val) {
887
- if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
888
- deferCall(state, ref, "set", [itemKey, itemValue]);
889
- continue;
867
+ for (let entry of entries) {
868
+ let [itemKey, itemValue] = entry;
869
+ if (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) {
870
+ if (deferMembers(state, ref, val, entry, entries), !i) return state.buf.push("new Map"), !0;
871
+ break;
890
872
  }
891
- 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);
873
+ 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);
892
874
  }
893
875
  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);
894
876
  }
@@ -896,13 +878,13 @@ function writeMap(state, val, ref) {
896
878
  }
897
879
  function writeSet(state, val, ref) {
898
880
  if (!val.size) return state.buf.push("new Set"), !0;
899
- let items = [], assignments, needsId, deferring = !1, i = 0;
900
- for (let item of val) {
901
- if (!deferring && item !== val && isAncestorMember(state, ref, item) && (deferring = !0), deferring) {
902
- deferCall(state, ref, "add", [item]);
903
- continue;
881
+ let items = [], assignments, needsId, i = 0, members = val.values();
882
+ for (let item of members) {
883
+ if (item !== val && isAncestorMember(state, ref, item)) {
884
+ if (deferMembers(state, ref, val, item, members), !i) return state.buf.push("new Set"), !0;
885
+ break;
904
886
  }
905
- item === val ? (item = 0, (assignments ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
887
+ item === val ? (item = 0, (assignments ||= []).push("i[" + i + "]")) : needsId ||= isReusableMember(item), i = items.push(item);
906
888
  }
907
889
  return writeArrayArg(state, ref, items, assignments && "((s,i)=>(" + assignmentsToString(assignments, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId), !0;
908
890
  }
@@ -911,11 +893,12 @@ function isAncestorMember(state, container, member) {
911
893
  let ref = state.refs.get(member);
912
894
  return ref !== void 0 && isCircular(container, ref);
913
895
  }
914
- function deferCall(state, ref, method, args) {
915
- ensureId(state, ref), (ref.calls ||= []).push({
916
- method,
917
- args
918
- }), state.pendingAssignments.add(ref);
896
+ function deferMembers(state, ref, collection, first, rest) {
897
+ ensureRefAccess(state, ref), ref.deferredMembers = {
898
+ collection,
899
+ first,
900
+ rest
901
+ }, state.deferredRefs.add(ref);
919
902
  }
920
903
  function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
921
904
  if (assignsPrefix || needsId) {
@@ -927,14 +910,14 @@ function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
927
910
  function newArgReference(state, parent, val) {
928
911
  for (let key in val) {
929
912
  let member = val[key];
930
- if (isDedupedMember(member) && !(typeof member == "string" ? state.strs.has(member) : state.refs.has(member))) {
913
+ if (isReusableMember(member) && !(typeof member == "string" ? state.strs.has(member) : state.refs.has(member))) {
931
914
  let ref = new Reference(parent, null, state.flushId, null, nextRefAccess(state));
932
915
  return state.buf.push(ref.id + "="), ref;
933
916
  }
934
917
  }
935
918
  return new Reference(parent, null, state.flushId, state.buf.length);
936
919
  }
937
- function isDedupedMember(val) {
920
+ function isReusableMember(val) {
938
921
  switch (typeof val) {
939
922
  case "object": return val !== null && val[K_SCOPE_ID] === void 0;
940
923
  case "function":
@@ -987,7 +970,7 @@ function writeAggregateError(state, val, ref) {
987
970
  let inlined = writeProp(state, val.errors, ref, "errors");
988
971
  if (inlined || state.buf.push("[]"), val.message ? state.buf.push("," + quote(val.message + "", 0) + ")") : state.buf.push(")"), inlined) {
989
972
  let errorsRef = state.refs.get(val.errors);
990
- errorsRef?.id && (state.pendingAssignments.add(errorsRef), addAssignment(errorsRef, accessId(state, ref) + toAccess("errors")));
973
+ errorsRef?.id && (state.deferredRefs.add(errorsRef), addAssignment(errorsRef, accessId(state, ref) + toAccess("errors")));
991
974
  }
992
975
  return !0;
993
976
  }
@@ -1016,7 +999,7 @@ function writeRequest(state, val, ref) {
1016
999
  let options = "";
1017
1000
  val.cache !== "default" && (options += sep + "cache:" + quote(val.cache, 0), sep = ","), val.credentials !== "same-origin" && (options += sep + "credentials:" + quote(val.credentials, 0), sep = ",");
1018
1001
  let seenHeaders = state.refs.get(val.headers);
1019
- if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders), sep = ",";
1002
+ if (seenHeaders) options += sep + "headers:" + ensureRefAccess(state, seenHeaders), sep = ",";
1020
1003
  else {
1021
1004
  state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
1022
1005
  let headers = stringEntriesToHeadersInit(val.headers);
@@ -1028,7 +1011,7 @@ function writeResponse(state, val, ref) {
1028
1011
  let sep = "", options = "";
1029
1012
  val.status !== 200 && (options += "status:" + val.status, sep = ","), val.statusText && (options += sep + "statusText:" + quote(val.statusText, 0), sep = ",");
1030
1013
  let seenHeaders = state.refs.get(val.headers);
1031
- if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders);
1014
+ if (seenHeaders) options += sep + "headers:" + ensureRefAccess(state, seenHeaders);
1032
1015
  else {
1033
1016
  state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
1034
1017
  let headers = stringEntriesToHeadersInit(val.headers);
@@ -1051,9 +1034,9 @@ function writeTemporal(state, val, name) {
1051
1034
  function writeReadableStream(state, val, ref) {
1052
1035
  if (val.locked) return !1;
1053
1036
  let { boundary, channel } = state, reader = val.getReader(), iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1054
- done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (reader.read().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
1037
+ done ? queueAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (reader.read().then(onFulfilled, onRejected), boundary.startAsync(), queueAsyncCall(state, boundary, handle, "f", value, channel));
1055
1038
  }, onRejected = (reason) => {
1056
- writeAsyncCall(state, boundary, handle, "j", reason, channel);
1039
+ queueAsyncCall(state, boundary, handle, "j", reason, channel);
1057
1040
  };
1058
1041
  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;
1059
1042
  }
@@ -1066,7 +1049,7 @@ function writeGenerator(state, iter, ref) {
1066
1049
  returnValue = value;
1067
1050
  break;
1068
1051
  }
1069
- needsId ||= isDedupedMember(value), yields.push(value);
1052
+ needsId ||= isReusableMember(value), yields.push(value);
1070
1053
  }
1071
1054
  if (returnValue === void 0 && !yields.length) return state.buf.push("(function*(){})()"), !0;
1072
1055
  let heldReturn = returnValue !== void 0 && isAncestorMember(state, ref, returnValue);
@@ -1077,18 +1060,18 @@ function writeGenerator(state, iter, ref) {
1077
1060
  if (heldReturn) {
1078
1061
  let holder = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1079
1062
  state.buf.push("," + holder.id + "={}"), writeProp(state, returnValue, holder, "v");
1080
- } else if (returnValue !== void 0 && (state.buf.push(","), writeProp(state, returnValue, ref, "") && isDedupedMember(returnValue))) {
1063
+ } else if (returnValue !== void 0 && (state.buf.push(","), writeProp(state, returnValue, ref, "") && isReusableMember(returnValue))) {
1081
1064
  let retRef = typeof returnValue == "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
1082
- retRef && ensureId(state, retRef);
1065
+ retRef && ensureRefAccess(state, retRef);
1083
1066
  }
1084
1067
  return state.buf.push(")"), !0;
1085
1068
  }
1086
1069
  function writeAsyncGenerator(state, iter, ref) {
1087
1070
  if (iter[kTouchedIterator]) return state.buf.push("(async function*(){}())"), !0;
1088
1071
  let { boundary, channel } = state, iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1089
- done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (iter.next().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
1072
+ done ? queueAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (iter.next().then(onFulfilled, onRejected), boundary.startAsync(), queueAsyncCall(state, boundary, handle, "f", value, channel));
1090
1073
  }, onRejected = (reason) => {
1091
- writeAsyncCall(state, boundary, handle, "j", reason, channel);
1074
+ queueAsyncCall(state, boundary, handle, "j", reason, channel);
1092
1075
  };
1093
1076
  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;
1094
1077
  }
@@ -1116,11 +1099,11 @@ function writeMaybeIterableProps(state, val, ref) {
1116
1099
  }
1117
1100
  return sep;
1118
1101
  }
1119
- function writeAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1120
- boundary.aborted || (state.mutated.push({
1102
+ function queueAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1103
+ boundary.aborted || ((channel?.readyId ? state.queuedReadyCalls : state.queuedCalls).push({
1104
+ method,
1121
1105
  value,
1122
1106
  object: handle,
1123
- property: method,
1124
1107
  channel,
1125
1108
  valueId
1126
1109
  }), boundary.endAsync());
@@ -1221,16 +1204,16 @@ function quote(str, startPos) {
1221
1204
  return "\"" + (lastPos === startPos ? str : result + str.slice(lastPos)) + "\"";
1222
1205
  }
1223
1206
  function writeRef(state, ref) {
1224
- 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));
1207
+ 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));
1225
1208
  }
1226
- function ensureId(state, ref) {
1227
- return ref.scopeId === void 0 ? ref.id ? (trackChannel(state, ref), ref.id) : assignId(state, ref) : (trackChannel(state, ref), "_(" + ref.scopeId + ")");
1209
+ function ensureRefAccess(state, ref) {
1210
+ return ref.scopeId === void 0 ? ref.id ? (trackChannel(state, ref), ref.id) : claimRefAccess(state, ref) : (trackChannel(state, ref), "_(" + ref.scopeId + ")");
1228
1211
  }
1229
1212
  function accessId(state, ref) {
1230
- let id = ensureId(state, ref);
1213
+ let id = ensureRefAccess(state, ref);
1231
1214
  return id === ref.id || ref.scopeId !== void 0 ? id : "(" + id + ")";
1232
1215
  }
1233
- function assignId(state, ref) {
1216
+ function claimRefAccess(state, ref) {
1234
1217
  let { pos } = ref;
1235
1218
  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)));
1236
1219
  }
@@ -1297,10 +1280,10 @@ function patchIteratorNext(proto) {
1297
1280
  //#endregion
1298
1281
  //#region src/html/attrs.ts
1299
1282
  function _attr_class(value) {
1300
- return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
1283
+ return stringAttr("class", toDelimitedString(value, " ", stringifyClassEntry));
1301
1284
  }
1302
1285
  function _attr_style(value) {
1303
- return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
1286
+ return stringAttr("style", toDelimitedString(value, ";", stringifyStyleEntry));
1304
1287
  }
1305
1288
  function _attr_option_value(value) {
1306
1289
  let valueAttr = _attr("value", value), selectedValue = getContext(kSelectedValue);
@@ -1326,7 +1309,7 @@ function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeT
1326
1309
  return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _attr("value", value);
1327
1310
  }
1328
1311
  function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
1329
- return checkedChange && writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType), isNotVoid(checked) ? " checked" : "";
1312
+ return checkedChange && writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType), isNotNullishOrFalse(checked) ? " checked" : "";
1330
1313
  }
1331
1314
  function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
1332
1315
  let valueAttr = _attr("value", value);
@@ -1339,7 +1322,7 @@ function getCheckedValueRef(checkedValue) {
1339
1322
  }
1340
1323
  }
1341
1324
  function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
1342
- let normalizedOpen = isNotVoid(open);
1325
+ let normalizedOpen = isNotNullishOrFalse(open);
1343
1326
  return openChange && writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType), normalizedOpen ? " open" : "";
1344
1327
  }
1345
1328
  function _attr_nonce() {
@@ -1350,7 +1333,7 @@ function _style_html(decls) {
1350
1333
  return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
1351
1334
  }
1352
1335
  function _attr(name, value) {
1353
- return isVoid(value) ? "" : nonVoidAttr(name, value);
1336
+ return isNullishOrFalse(value) ? "" : stringifyAttr(name, value);
1354
1337
  }
1355
1338
  function _attr_and(name, value, attr) {
1356
1339
  return value ? attr : _attr(name, value);
@@ -1386,7 +1369,7 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
1386
1369
  case "style":
1387
1370
  result += _attr_style(value);
1388
1371
  break;
1389
- 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));
1372
+ 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));
1390
1373
  }
1391
1374
  }
1392
1375
  return result;
@@ -1397,7 +1380,7 @@ function _attrs_content(data, nodeAccessor, scopeId, tagName, markerGuard) {
1397
1380
  function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
1398
1381
  let partial = {};
1399
1382
  for (let name in data) {
1400
- let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1383
+ let key = isEventHandler(name) ? `on-${getEventType(name)}` : name;
1401
1384
  skip[key] || (partial[key] = data[name]);
1402
1385
  }
1403
1386
  return _attrs(partial, nodeAccessor, scopeId, tagName);
@@ -1418,7 +1401,7 @@ function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, s
1418
1401
  function stringAttr(name, value) {
1419
1402
  return value && " " + name + attrAssignment(value);
1420
1403
  }
1421
- function nonVoidAttr(name, value) {
1404
+ function stringifyAttr(name, value) {
1422
1405
  switch (typeof value) {
1423
1406
  case "string": return " " + name + attrAssignment(value);
1424
1407
  case "boolean": return " " + name;
@@ -1449,18 +1432,7 @@ function normalizedValueMatches(a, b) {
1449
1432
  return !1;
1450
1433
  }
1451
1434
  function normalizeStrAttrValue(value) {
1452
- return isNotVoid(value) && value !== !0 ? value + "" : "";
1453
- }
1454
- //#endregion
1455
- //#region src/html/for.ts
1456
- function forOfBy(by, item, index) {
1457
- return by ? typeof by == "string" ? item[by] : by(item, index) : index;
1458
- }
1459
- function forInBy(by, name, value) {
1460
- return by ? by(name, value) : name;
1461
- }
1462
- function forStepBy(by, index) {
1463
- return by ? by(index) : index;
1435
+ return isNotNullishOrFalse(value) && value !== !0 ? value + "" : "";
1464
1436
  }
1465
1437
  //#endregion
1466
1438
  //#region src/html/inlined-runtimes.ts
@@ -1506,11 +1478,11 @@ function _scope_id() {
1506
1478
  function _peek_scope_id() {
1507
1479
  return $chunk.boundary.state.scopeId;
1508
1480
  }
1509
- function withContext(key, value, cb, cbValue) {
1481
+ function withContext(key, value, cb, cbValue, cbValue2) {
1510
1482
  let ctx = $chunk.context ||= { [kPendingContexts]: 0 }, prev = ctx[key];
1511
1483
  ctx[kPendingContexts]++, ctx[key] = value;
1512
1484
  try {
1513
- return cb(cbValue);
1485
+ return cb(cbValue, cbValue2);
1514
1486
  } finally {
1515
1487
  ctx[kPendingContexts]--, ctx[key] = prev;
1516
1488
  }
@@ -1524,11 +1496,11 @@ function captureContext(chunk) {
1524
1496
  function isInResumedBranch() {
1525
1497
  return $chunk?.context?.[kBranchId] !== void 0;
1526
1498
  }
1527
- function withBranchId(branchId, cb, cbValue) {
1528
- return withContext(kBranchId, branchId, cb, cbValue);
1499
+ function withBranchId(branchId, cb, cbValue, cbValue2) {
1500
+ return withContext(kBranchId, branchId, cb, cbValue, cbValue2);
1529
1501
  }
1530
- function withIsAsync(async, cb, value) {
1531
- return withContext(kIsAsync, async, cb, value);
1502
+ function withAsyncContent(async, cb, value) {
1503
+ return withContext(kAsyncContent, async, cb, value);
1532
1504
  }
1533
1505
  function _html(html) {
1534
1506
  $chunk.writeHTML(html);
@@ -1546,7 +1518,7 @@ function mayDrop(written) {
1546
1518
  return !1;
1547
1519
  }
1548
1520
  function _script(scopeId, registryId, markerGuard) {
1549
- markerGuard === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1521
+ markerGuard === 0 && ($chunk.channel.readyId || $chunk.context?.[kAsyncContent]) && _resume_branch(scopeId), $chunk.boundary.state.queueEffect(scopeId, registryId);
1550
1522
  }
1551
1523
  function _trailers(html) {
1552
1524
  $chunk.boundary.state.trailerHTML += html;
@@ -1564,24 +1536,24 @@ function _hoist(scopeId, id) {
1564
1536
  let getter = () => void 0;
1565
1537
  return getter[Symbol.iterator] = _hoist_read_error, _resume(getter, id, scopeId);
1566
1538
  }
1567
- function _el_resume(scopeId, accessor, shouldResume) {
1568
- if (shouldResume === 0) return "";
1539
+ function _el_resume(scopeId, accessor, markerGuard) {
1540
+ if (markerGuard === 0) return "";
1569
1541
  let { state } = $chunk.boundary;
1570
- return state.needsMainRuntime = !0, state.mark("$", scopeId + " " + accessor);
1542
+ return state.needsWalkerRuntime = !0, state.mark("$", scopeId + " " + accessor);
1571
1543
  }
1572
- function _text_resume(scopeId, accessor, val, shouldResume) {
1573
- return markText(scopeId, accessor, _escape(val), shouldResume);
1544
+ function _text_resume(scopeId, accessor, val, markerGuard) {
1545
+ return markText(scopeId, accessor, _escape(val), markerGuard);
1574
1546
  }
1575
- function _html_resume(scopeId, accessor, val, shouldResume) {
1547
+ function _html_resume(scopeId, accessor, val, markerGuard) {
1576
1548
  let html = _unescaped(val);
1577
- if (shouldResume === 0 || !~html.indexOf("<")) return markText(scopeId, accessor, html, shouldResume);
1549
+ if (markerGuard === 0 || !~html.indexOf("<")) return markText(scopeId, accessor, html, markerGuard);
1578
1550
  let { state } = $chunk.boundary;
1579
- return state.needsMainRuntime = !0, state.mark("&", "") + html + state.mark("'", scopeId + " " + accessor);
1551
+ return state.needsWalkerRuntime = !0, state.mark("&", "") + html + state.mark("'", scopeId + " " + accessor);
1580
1552
  }
1581
- function markText(scopeId, accessor, text, shouldResume) {
1582
- if (shouldResume === 0) return text;
1553
+ function markText(scopeId, accessor, text, markerGuard) {
1554
+ if (markerGuard === 0) return text;
1583
1555
  let { state } = $chunk.boundary;
1584
- return state.needsMainRuntime = !0, text ? (shouldResume === 2 ? "<!>" : "") + text + state.mark("$", scopeId + " " + accessor) : state.mark("%", scopeId + " " + accessor);
1556
+ return state.needsWalkerRuntime = !0, text ? (markerGuard === 2 ? "<!>" : "") + text + state.mark("$", scopeId + " " + accessor) : state.mark("%", scopeId + " " + accessor);
1585
1557
  }
1586
1558
  function _resume_branch(scopeId) {
1587
1559
  let branchId = $chunk.context?.[kBranchId];
@@ -1590,7 +1562,7 @@ function _resume_branch(scopeId) {
1590
1562
  function _attr_content(nodeAccessor, scopeId, content, markerGuard) {
1591
1563
  let shouldResume = markerGuard !== 0, render = normalizeServerRender(content), branchId = _peek_scope_id();
1592
1564
  if (render) try {
1593
- _set_scope_reason(shouldResume ? CLIENT_ALL : 0), shouldResume ? withBranchId(branchId, render) : render();
1565
+ _set_scope_reason(shouldResume ? ALL_GROUPS : 0), shouldResume ? withBranchId(branchId, render) : render();
1594
1566
  } finally {
1595
1567
  _set_scope_reason(void 0);
1596
1568
  }
@@ -1609,83 +1581,8 @@ function _var(parentScopeId, scopeOffsetAccessor, childScopeId, registryId, node
1609
1581
  nodeAccessor !== void 0 && writeScope(parentScopeId, { ["A" + nodeAccessor]: childScope });
1610
1582
  }
1611
1583
  function writeScopePassive(scopeId, partialScope) {
1612
- let target = $chunk.serializeState, scope = _scope_with_id(scopeId), passive = target.passiveScopes ||= {};
1613
- return Object.assign(scope, partialScope), passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope), scope;
1614
- }
1615
- function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
1616
- display ? resumesMarker(markerGuard, branchExprGuard, parentEndTag) && $chunk.writeHTML($chunk.boundary.state.mark("[", "")) : $chunk.writeHTML("<t hidden>");
1617
- }
1618
- function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1619
- let branchId = _scope_id(), wrap = !display;
1620
- wrap && $chunk.writeHTML("</t>"), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1621
- }
1622
- function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1623
- forBranches(by, (each) => each ? forOf(list, (item, index) => {
1624
- let itemKey = forOfBy(by, item, index);
1625
- each(itemKey, itemKey === index, () => cb(item, index));
1626
- }) : forOf(list, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1627
- }
1628
- function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1629
- forBranches(by, (each) => each ? forIn(obj, (key, value) => {
1630
- each(forInBy(by, key, value), !1, () => cb(key, value));
1631
- }) : forIn(obj, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1632
- }
1633
- function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1634
- forBranches(by, (each) => {
1635
- let index = 0;
1636
- return each ? forTo(to, from, step, (value) => {
1637
- let itemKey = forStepBy(by, value);
1638
- each(itemKey, itemKey === index++, () => cb(value));
1639
- }) : forTo(to, from, step, cb);
1640
- }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1641
- }
1642
- function _for_until(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1643
- forBranches(by, (each) => {
1644
- let index = 0;
1645
- return each ? forUntil(to, from, step, (value) => {
1646
- let itemKey = forStepBy(by, value);
1647
- each(itemKey, itemKey === index++, () => cb(value));
1648
- }) : forUntil(to, from, step, cb);
1649
- }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1650
- }
1651
- function forBranches(by, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1652
- if (branchGuard === 0) {
1653
- iterate(0), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
1654
- return;
1655
- }
1656
- let { state } = $chunk.boundary, resumeKeys = markerGuard !== 0, resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag), flushBranchIds = "", loopScopes;
1657
- iterate((itemKey, sameAsIndex, render) => {
1658
- let branchId = _peek_scope_id();
1659
- resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(state.mark("[", flushBranchIds)), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
1660
- render();
1661
- let branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { M: itemKey } : {});
1662
- resumeMarker || (loopScopes = push(loopScopes, branchScope));
1663
- });
1664
- }), loopScopes && writeScope(scopeId, { ["A" + accessor]: loopScopes }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1665
- }
1666
- function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1667
- 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;
1668
- beforeBranch !== void 0 && applyBranchStart(chunk, beforeBranch, shouldWriteBranch), shouldWriteBranch && (branchIndex || !resumeMarker) && writeScope(scopeId, {
1669
- ["D" + accessor]: branchIndex || void 0,
1670
- ["A" + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
1671
- }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
1672
- }
1673
- function deferBranchStart(chunk) {
1674
- let beforeBranch = chunk.html;
1675
- return chunk.html = "", beforeBranch;
1676
- }
1677
- function applyBranchStart(chunk, beforeBranch, rendered) {
1678
- chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
1679
- }
1680
- function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
1681
- return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
1682
- }
1683
- function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
1684
- let endTag = parentEndTag || "";
1685
- if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
1686
- let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
1687
- $chunk.writeHTML(mark + endTag);
1688
- } else markerGuard === 0 ? $chunk.writeHTML(endTag) : $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1584
+ let target = $chunk.channel, scope = _scope_with_id(scopeId);
1585
+ return Object.assign(scope, partialScope), $chunk.boundary.state.queuePassiveScope(target, scopeId, partialScope), scope;
1689
1586
  }
1690
1587
  function _existing_scope(scopeId) {
1691
1588
  return writeScope(scopeId, {});
@@ -1699,13 +1596,13 @@ function scopeWithId(state, scopeId) {
1699
1596
  }
1700
1597
  function _subscribe(subscribers, scope, resumeId, markerGuard) {
1701
1598
  if (subscribers) {
1702
- let { boundary, serializeState } = $chunk, { serializer } = boundary.state;
1703
- !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);
1599
+ let { boundary, channel } = $chunk, { serializer } = boundary.state;
1600
+ !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);
1704
1601
  }
1705
1602
  return scope;
1706
1603
  }
1707
- function maskGroup(mask, group) {
1708
- return mask === 715827883 ? 1 : typeof mask == "number" ? group < 15 ? mask >>> 1 + 2 * group & 3 : 0 : mask[group] ?? 0;
1604
+ function getGroupReason(reason, group) {
1605
+ return reason === 715827883 ? 1 : typeof reason == "number" ? group < 15 ? reason >>> 1 + 2 * group & 3 : 0 : reason[group] ?? 0;
1709
1606
  }
1710
1607
  function _set_scope_reason(reason) {
1711
1608
  $chunk.boundary.state.scopeReason = reason;
@@ -1714,148 +1611,65 @@ function _scope_reason() {
1714
1611
  let reason = $chunk.boundary.state.scopeReason;
1715
1612
  return $chunk.boundary.state.scopeReason = void 0, reason;
1716
1613
  }
1717
- function _write_if(condition, key) {
1718
- return condition && maskGroup(condition, key) ? 1 : void 0;
1614
+ function _write_if(reason, group) {
1615
+ return reason && getGroupReason(reason, group) ? 1 : void 0;
1719
1616
  }
1720
- function _write_guard(condition, key) {
1721
- return _write_if(condition, key) || 0;
1617
+ function _write_guard(reason, group) {
1618
+ return _write_if(reason, group) || 0;
1722
1619
  }
1723
1620
  function writeWaitReady(readyId, renderer, input) {
1724
1621
  let chunk = $chunk, { boundary } = chunk, body = new Chunk(boundary, null, chunk.context, {
1725
1622
  readyId,
1726
- parent: chunk.serializeState,
1623
+ parent: chunk.channel,
1727
1624
  resumes: "",
1728
1625
  writeScopes: {},
1729
1626
  flushScopes: !1
1730
1627
  }), bodyEnd = body.render(renderer, input);
1731
1628
  if (boundary.aborted) throw boundary.reason;
1732
- 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);
1733
- }
1734
- function _await(scopeId, accessor, promise, content, markerGuard) {
1735
- let resumeMarker = markerGuard !== 0;
1736
- if (!isPromise(promise)) {
1737
- if (resumeMarker) {
1738
- let branchId = _peek_scope_id();
1739
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, content, promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1740
- } else content(promise);
1741
- return;
1742
- }
1743
- let chunk = $chunk, { boundary } = chunk, startId = _peek_scope_id(), after = chunk.next = $chunk = chunk.fork(boundary, chunk.next);
1744
- chunk.async = !0, captureContext(chunk), boundary.startAsync(), promise.then((value) => {
1745
- if (chunk.async && (chunk.async = !1, !boundary.aborted)) {
1746
- let { state } = boundary;
1747
- chunk.render(() => {
1748
- if (resumeMarker) {
1749
- let branchId = _peek_scope_id();
1750
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync({ parent: getAsyncContent(chunk) }, content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1751
- } else {
1752
- let renderedSince = _peek_scope_id() !== startId, async = { parent: getAsyncContent(chunk) };
1753
- 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;
1754
- }
1755
- }), !chunk.async && boundary.pendingReorders?.delete(chunk) && state.reorder(chunk), boundary.endAsync();
1756
- }
1757
- }, (err) => {
1758
- chunk.async = !1, boundary.abort(err);
1759
- });
1629
+ body === bodyEnd ? (chunk.writeHTML(body.html), body.deferOwnReady(), chunk.deferredReady = push(chunk.deferredReady, body)) : (bodyEnd.next = chunk.forkRest(boundary), chunk.next = body);
1760
1630
  }
1761
- function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
1762
- 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;
1763
- applyBranchStart(chunk, beforeBranch, rendered), rendered && (renderersWritten || renderers(), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
1764
- }
1765
- function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1766
- let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
1767
- if (body === body.render(content)) {
1768
- chunk.append(body);
1769
- return;
1770
- }
1771
- chunk.next = $chunk = chunk.fork(boundary, chunk.next), captureContext(chunk), chunk.placeholder = {
1772
- body,
1773
- render: placeholder,
1774
- branchId,
1775
- scopeId,
1776
- placeholderBranchId
1777
- };
1631
+ function deferBranchStart(chunk) {
1632
+ let beforeBranch = chunk.html;
1633
+ return chunk.html = "", beforeBranch;
1778
1634
  }
1779
- function tryBoundary(content, catchContent, branchId, renderers) {
1780
- let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, void 0, boundary);
1781
- catchContent && (catchBoundary.withinCatch = !0);
1782
- let body = chunk.fork(catchBoundary, null), bodyEnd = body.render(() => withBranchId(branchId, content));
1783
- if (catchBoundary.aborted) {
1784
- if (!catchContent) throw catchBoundary.reason;
1785
- return catchContent(catchBoundary.reason), !0;
1786
- }
1787
- if (body === bodyEnd) return chunk.append(body), !1;
1788
- let renderersAtSettle = !catchBoundary.resumeWrites, bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1789
- chunk.next = body, boundary.startAsync();
1790
- let reorderId = catchContent ? state.nextReorderId() : "";
1791
- return reorderId && (chunk.catchRange = {
1792
- id: reorderId,
1793
- end: bodyEnd
1794
- }, captureContext(chunk)), catchBoundary.onNext = () => {
1795
- if (!boundary.aborted) {
1796
- if (catchBoundary.aborted) {
1797
- if (!reorderId) {
1798
- boundary.abort(catchBoundary.reason);
1799
- return;
1800
- }
1801
- let streamed = !chunk.catchRange, catchChunk = chunk.fork(boundary, null);
1802
- chunk.catchRange = null, renderersAtSettle || catchChunk.render(clearTryRenderers, branchId);
1803
- let inOrder = catchChunk === catchChunk.render(catchContent, catchBoundary.reason);
1804
- if (boundary.aborted) return;
1805
- if ((bodyEnd.consumed || !inOrder) && (catchChunk.reorderBranch = branchId), bodyEnd.consumed) catchChunk.reorderId = reorderId, state.reorder(catchChunk);
1806
- else {
1807
- let reorder = null;
1808
- inOrder ? streamed && (reorder = chunk.fork(boundary, null)) : reorder = catchChunk, reorder && (reorder.reorderId = reorderId);
1809
- let endMarker = state.mark("!", reorderId), cut = body;
1810
- for (; cut.consumed;) cut = cut.next;
1811
- 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);
1812
- }
1813
- boundary.endAsync();
1814
- } else catchBoundary.count ? boundary.onNext() : (renderersAtSettle && catchBoundary.resumeWrites && bodyEnd.render(renderers), chunk.catchRange = null, boundary.endAsync());
1815
- }
1816
- }, renderersAtSettle;
1635
+ function applyBranchStart(chunk, beforeBranch, rendered) {
1636
+ chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
1817
1637
  }
1818
1638
  function unsubscribe(subscribed, serializer) {
1819
1639
  for (let i = 0; i < subscribed.length; i += 3) {
1820
1640
  let subscribers = subscribed[i], scope = subscribed[i + 1];
1821
- serializer.written(subscribers) ? serializer.dropCall(scope, subscribers, "add") || serializer.writeCall(scope, subscribers, "delete", subscribed[i + 2]) : subscribers.delete(scope);
1641
+ if (!serializer.refs.has(subscribers)) subscribers.delete(scope);
1642
+ else {
1643
+ let channel = subscribed[i + 2];
1644
+ dropQueuedCall(serializer, scope, subscribers, "add", channel) || queueCall(serializer, scope, subscribers, "delete", channel);
1645
+ }
1822
1646
  }
1823
1647
  }
1824
- function clearTryRenderers(branchId) {
1825
- writeScope(branchId, {
1826
- E: 0,
1827
- Q: _scope_with_id(branchId).Q && 0
1828
- });
1829
- }
1830
- function writeTryRenderers(branchId, catchContent, placeholderContent) {
1831
- writeScope(branchId, {
1832
- E: catchContent,
1833
- Q: placeholderContent
1834
- });
1835
- }
1836
1648
  function countResumeWrite(chunk) {
1837
1649
  for (let boundary = chunk.boundary; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1650
+ }
1651
+ function writeAsyncVisits(chunk) {
1838
1652
  for (let async = getAsyncContent(chunk); async && !async.resumed; async = async.parent) async.resumed = !0, async.end?.writeHTML(async.visit);
1839
1653
  }
1840
1654
  function getAsyncContent(chunk) {
1841
- return chunk.context?.[kIsAsync];
1655
+ return chunk.context?.[kAsyncContent];
1842
1656
  }
1843
1657
  var State = class {
1844
1658
  tagId = 1;
1845
1659
  scopeId = 1;
1846
1660
  reorderId = 1;
1847
1661
  readyGate = 1;
1848
- hasGlobals = !1;
1849
- needsMainRuntime = !1;
1850
- hasMainRuntime = !1;
1851
- hasReadyRuntime = !1;
1662
+ hasWrittenGlobals = !1;
1663
+ needsWalkerRuntime = !1;
1664
+ hasWalkerRuntime = !1;
1665
+ hasWrittenReady = !1;
1852
1666
  hasReorderRuntime = !1;
1853
1667
  hasWrittenResume = !1;
1854
1668
  walkOnNextFlush = !1;
1855
1669
  trailerHTML = "";
1856
1670
  resumes = "";
1857
1671
  nonceAttr = "";
1858
- serializer = new Serializer();
1672
+ serializer = new State$1();
1859
1673
  writeReorders = null;
1860
1674
  scopes = /* @__PURE__ */ new Map();
1861
1675
  scope = (scopeId) => scopeWithId(this, scopeId);
@@ -1867,13 +1681,36 @@ var State = class {
1867
1681
  constructor($global) {
1868
1682
  this.$global = $global, $global.cspNonce && (this.nonceAttr = " nonce" + attrAssignment($global.cspNonce));
1869
1683
  }
1870
- flushChunk(html, scripts, pending) {
1684
+ joinFlush(html, scripts, pending) {
1871
1685
  let { $global, nonceAttr } = this, { __flush__ } = $global;
1872
1686
  return scripts && (html += "<script" + nonceAttr + ">" + scripts + "<\/script>"), __flush__ && ($global.__flush__ = void 0, html = __flush__($global, html)), pending ? html : html + this.trailerHTML;
1873
1687
  }
1874
1688
  walkScript() {
1875
1689
  return this.runtimePrefix + ".w()";
1876
1690
  }
1691
+ addResumes(channel, resumes) {
1692
+ channel.resumes = concatSequence(channel.resumes, resumes);
1693
+ }
1694
+ queueScope(target, scopeId, partialScope) {
1695
+ let pending = target.writeScopes[scopeId];
1696
+ pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0;
1697
+ }
1698
+ queuePassiveScope(target, scopeId, partialScope) {
1699
+ let passive = target.passiveScopes ||= {};
1700
+ passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope);
1701
+ }
1702
+ queueEffect(scopeId, registryId) {
1703
+ this.needsWalkerRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1704
+ }
1705
+ serializeFlush(boundary) {
1706
+ flushSerializer(boundary, this);
1707
+ }
1708
+ runtimeScript() {
1709
+ 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,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 + "\")";
1710
+ }
1711
+ keepsTryMarks(chunk, resumeWrites) {
1712
+ return chunk !== $chunk || chunk.boundary.resumeWrites !== resumeWrites;
1713
+ }
1877
1714
  resumeScript(resumes) {
1878
1715
  return this.hasWrittenResume ? this.runtimePrefix + ".r.push(" + resumes + ")" : (this.hasWrittenResume = !0, this.runtimePrefix + ".r=[" + resumes + "]");
1879
1716
  }
@@ -1886,11 +1723,11 @@ var State = class {
1886
1723
  return $global.runtimeId + $global.renderId;
1887
1724
  }
1888
1725
  reorder(chunk) {
1889
- this.writeReorders ? this.writeReorders.push(chunk) : (this.needsMainRuntime = !0, this.writeReorders = [chunk]);
1726
+ this.writeReorders ? this.writeReorders.push(chunk) : (this.needsWalkerRuntime = !0, this.writeReorders = [chunk]);
1890
1727
  }
1891
- writeReady(id, resumes) {
1728
+ readyScript(id, resumes) {
1892
1729
  let readyKey = toObjectKey(id);
1893
- 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 + "]}"));
1730
+ 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 + "]}"));
1894
1731
  }
1895
1732
  readyAccess(readyKey) {
1896
1733
  return this.runtimePrefix + ".b" + toAccess(readyKey);
@@ -1932,7 +1769,7 @@ var State = class {
1932
1769
  this.abort(event.target.reason);
1933
1770
  }
1934
1771
  flush() {
1935
- return this.aborted || flushSerializer(this, this.state), this.count ? 1 : this.aborted ? 2 : 0;
1772
+ return this.aborted || this.state.serializeFlush(this), this.count ? 1 : this.aborted ? 2 : 0;
1936
1773
  }
1937
1774
  startAsync() {
1938
1775
  this.aborted || this.count++;
@@ -1957,18 +1794,21 @@ var State = class {
1957
1794
  boundary;
1958
1795
  next;
1959
1796
  context;
1960
- serializeState;
1961
- constructor(boundary, next, context, serializeState) {
1962
- this.boundary = boundary, this.next = next, this.context = context, this.serializeState = serializeState;
1797
+ channel;
1798
+ constructor(boundary, next, context, channel) {
1799
+ this.boundary = boundary, this.next = next, this.context = context, this.channel = channel;
1963
1800
  }
1964
1801
  fork(boundary, next) {
1965
- return new Chunk(boundary, next, this.context, this.serializeState);
1802
+ return new Chunk(boundary, next, this.context, this.channel);
1803
+ }
1804
+ forkRest(boundary) {
1805
+ return $chunk = this.fork(boundary, this.next);
1966
1806
  }
1967
1807
  writeHTML(html) {
1968
1808
  this.html += html;
1969
1809
  }
1970
1810
  writeEffect(scopeId, registryId) {
1971
- countResumeWrite(this), this.lastEffect === registryId ? this.effects = concatEffects(this.effects, scopeId + "") : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1811
+ countResumeWrite(this), writeAsyncVisits(this), this.lastEffect === registryId ? this.effects = concatEffects(this.effects, scopeId + "") : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1972
1812
  }
1973
1813
  writeScript(script) {
1974
1814
  this.scripts = concatScripts(this.scripts, script);
@@ -1985,7 +1825,7 @@ var State = class {
1985
1825
  return this.deferredReady = null, deferredReady;
1986
1826
  }
1987
1827
  deferOwnReady() {
1988
- if (this.serializeState.readyId && (this.effects || this.scripts || this.serializeState.flushScopes)) {
1828
+ if (this.channel.readyId && (this.effects || this.scripts || this.channel.flushScopes)) {
1989
1829
  let deferred = this.fork(this.boundary, null);
1990
1830
  deferred.effects = this.effects, deferred.scripts = this.scripts, this.effects = this.scripts = this.lastEffect = "", this.deferredReady = concat(deferred, this.deferredReady);
1991
1831
  }
@@ -2023,9 +1863,9 @@ var State = class {
2023
1863
  let { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId + "";
2024
1864
  this.writeHTML(state.mark("!^", reorderId));
2025
1865
  let { effects } = this, beforeBranch = deferBranchStart(this);
2026
- if (this.render(() => withBranchId(placeholderBranchId, placeholder.render)) !== this && this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.boundary.aborted) return !0;
1866
+ if (this.render(withBranchId, placeholderBranchId, placeholder.render) !== this && this.boundary.abort(/* @__PURE__ */ Error()), this.boundary.aborted) return !0;
2027
1867
  let stateful = this.effects !== effects;
2028
- 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;
1868
+ 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;
2029
1869
  }
2030
1870
  markCatchRange() {
2031
1871
  let { catchRange } = this;
@@ -2041,14 +1881,14 @@ var State = class {
2041
1881
  consume(boundary) {
2042
1882
  this.renderPlaceholders(boundary);
2043
1883
  let cur = this, html = "", effects = "", scripts = "", effectsEnd, heldEffects = this.heldEffects, deferredReady;
2044
- 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;
2045
- 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;
1884
+ 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;
1885
+ 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;
2046
1886
  }
2047
- render(content, val) {
1887
+ render(content, val, val2) {
2048
1888
  let prev = $chunk;
2049
1889
  $chunk = this;
2050
1890
  try {
2051
- return content(val), $chunk;
1891
+ return content(val, val2), $chunk;
2052
1892
  } catch (err) {
2053
1893
  return this.boundary.abort(err), this;
2054
1894
  } finally {
@@ -2056,39 +1896,39 @@ var State = class {
2056
1896
  }
2057
1897
  }
2058
1898
  flushReadyScripts(boundary, reservations, holdEffects) {
2059
- let { serializeState } = this, { readyId } = serializeState, scripts = "", held = this.takeDeferredReady();
1899
+ let { channel } = this, { readyId } = channel, scripts = "", held = this.takeDeferredReady();
2060
1900
  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)));
2061
1901
  if (readyId && !this.async) {
2062
1902
  let { state } = boundary;
2063
- flushSerializer(boundary, serializeState);
2064
- let deps = state.serializer.takeChannelDeps(), effects = holdEffects ? "" : this.effects, { resumes } = serializeState, chunkScripts = this.scripts;
2065
- if (serializeState.resumes = this.scripts = "", effects && (this.effects = this.lastEffect = ""), resumes || effects) {
2066
- state.needsMainRuntime = !0;
1903
+ flushSerializer(boundary, channel);
1904
+ let deps = takeChannelDeps(state.serializer), effects = holdEffects ? "" : this.effects, { resumes } = channel, chunkScripts = this.scripts;
1905
+ if (channel.resumes = this.scripts = "", effects && (this.effects = this.lastEffect = ""), resumes || effects) {
1906
+ state.needsWalkerRuntime = !0;
2067
1907
  let batch = concatSequence(depsMarker(deps), concatSequence(resumes, effects && `"${effects}"`));
2068
1908
  if (reservations) {
2069
1909
  let gate = state.readyGate++;
2070
- reservations.push(state.writeReady(readyId, gate + "")), scripts = concatScripts(scripts, "(b=>b.splice(b.indexOf(" + gate + "),1," + batch + "))(" + state.readyAccess(toObjectKey(readyId)) + ")");
2071
- } else scripts = concatScripts(scripts, state.writeReady(readyId, batch));
1910
+ reservations.push(state.readyScript(readyId, gate + "")), scripts = concatScripts(scripts, "(b=>b.splice(b.indexOf(" + gate + "),1," + batch + "))(" + state.readyAccess(toObjectKey(readyId)) + ")");
1911
+ } else scripts = concatScripts(scripts, state.readyScript(readyId, batch));
2072
1912
  }
2073
1913
  scripts = concatScripts(scripts, chunkScripts);
2074
1914
  }
2075
1915
  return scripts;
2076
1916
  }
2077
- flushScript(boundary) {
2078
- let { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1917
+ flush(boundary) {
1918
+ let { state } = boundary, { runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
2079
1919
  needsWalk && (state.walkOnNextFlush = !1), flushSerializer(boundary, state);
2080
1920
  let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
2081
- for (let channel; !boundary.aborted && (channel = state.serializer.pendingReadyChannel());) {
2082
- let resumes = state.serializer.stringifyScopes([], boundary, channel), deps = state.serializer.takeChannelDeps();
2083
- state.needsMainRuntime = !0, readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
1921
+ for (let channel; !boundary.aborted && (channel = pendingReadyChannel(state.serializer));) {
1922
+ let resumes = stringifyScopes(state.serializer, [], boundary, channel), deps = takeChannelDeps(state.serializer);
1923
+ state.needsWalkerRuntime = !0, readyResumeScripts = concatScripts(readyResumeScripts, state.readyScript(channel.readyId, concatSequence(depsMarker(deps), resumes)));
2084
1924
  }
2085
1925
  readyResumeScripts && (needsWalk = !0);
2086
1926
  let effects = this.async ? "" : joinHeldEffects(this.takeHeldEffects(), this.effects), { html, scripts } = this;
2087
- 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 + "\"");
1927
+ 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 + "\"");
2088
1928
  let reordered = "", needsResumeArray = !1;
2089
1929
  if (state.writeReorders) {
2090
1930
  for (let reorderedChunk of state.writeReorders) {
2091
- needsWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, scripts = concatScripts(scripts, "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:1,r:a,c(i=e.l[\"^\"+a],f=d.cloneNode()){if(--o.i)return 1;for(;f.prepend(r=e.l[a].previousSibling||i),i!=r;);c(a,d)}}),e.v.push({data:e.i+\"*\"+l.r}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})(" + runtimePrefix + ")"));
1931
+ needsWalk = !0, state.hasReorderRuntime || (state.hasReorderRuntime = !0, scripts = concatScripts(scripts, "(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),\"#\"==n?(t[a]=l).i++:\"T\"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=e=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:1,r:a,c(i=e.l[\"^\"+a],f=d.cloneNode()){if(--o.i)return 1;for(;f.prepend(r=e.l[a].previousSibling||i),i!=r;);c(a,d)}}),e.v.push({data:e.i+\"*\"+l.r}),(n=e.j[a])&&(g=l.c,l.c=i=>g()||n(e.r)))}})(" + runtimePrefix + ")"));
2092
1932
  let { reorderId, reorderBranch } = reorderedChunk, rootBranch = reorderBranch || +reorderId, readyReservations = [], reorderHTML = "", reorderEffects = "", effectsBoundary = reorderedChunk.boundary, reorderScripts = "", cur = reorderedChunk.boundary.aborted ? null : reorderedChunk;
2093
1933
  for (reorderedChunk.reorderId = null; cur;) {
2094
1934
  cur.markCatchRange(), cur.queueDeferredReorder(), cur.deferOwnReady();
@@ -2110,9 +1950,9 @@ var State = class {
2110
1950
  }
2111
1951
  flushHTML(boundary) {
2112
1952
  let { state } = boundary;
2113
- this.flushScript(boundary);
1953
+ this.flush(boundary);
2114
1954
  let { html, scripts } = this;
2115
- return this.html = this.scripts = "", state.flushChunk(html, scripts, boundary.count);
1955
+ return this.html = this.scripts = "", state.joinFlush(html, scripts, boundary.count);
2116
1956
  }
2117
1957
  };
2118
1958
  function renderReorderPlaceholders(reorder, reorders) {
@@ -2131,7 +1971,7 @@ function followHeldEffects(chunk) {
2131
1971
  held !== chunk && (held.effects = concatEffects(held.effects, chunk.effects), chunk.effects = "");
2132
1972
  }
2133
1973
  function lastHeldOf(held, cur) {
2134
- return cur.serializeState === held.serializeState && cur.boundary === held.boundary ? cur : held;
1974
+ return cur.channel === held.channel && cur.boundary === held.boundary ? cur : held;
2135
1975
  }
2136
1976
  function holdEffectsOn(heldEffects, chunk, effects) {
2137
1977
  return chunk.effects = effects, push(heldEffects, chunk);
@@ -2141,7 +1981,7 @@ function isWithin(boundary, outer) {
2141
1981
  return !!boundary;
2142
1982
  }
2143
1983
  function holdReorderEffects(head, boundary, effects) {
2144
- 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);
1984
+ 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);
2145
1985
  }
2146
1986
  function joinHeldEffects(heldEffects, effects) {
2147
1987
  return concatEffects(reduce(heldEffects, joinUncaught, ""), effects);
@@ -2149,16 +1989,16 @@ function joinHeldEffects(heldEffects, effects) {
2149
1989
  function joinUncaught(joined, held) {
2150
1990
  return held.boundary.aborted ? joined : concatEffects(joined, held.effects);
2151
1991
  }
2152
- function flushSerializer(boundary, serializeState) {
2153
- let { state } = boundary, { serializer } = state, pending = serializer.pending(serializeState);
2154
- if (serializeState.flushScopes || pending) {
2155
- let { writeScopes, passiveScopes } = serializeState, isBlockingState = serializeState !== state, flushes = [];
1992
+ function flushSerializer(boundary, channel) {
1993
+ let { state } = boundary, { serializer } = state, pending = hasMatchingCalls(serializer, channel.readyId);
1994
+ if (channel.flushScopes || pending) {
1995
+ let { writeScopes, passiveScopes } = channel, flushes = [];
2156
1996
  if (passiveScopes) for (let key in passiveScopes) {
2157
1997
  let props = writeScopes[key];
2158
1998
  props && (writeScopes[key] = Object.assign(passiveScopes[key], props), delete passiveScopes[key]);
2159
1999
  }
2160
- if (!isBlockingState && !state.hasGlobals) {
2161
- state.hasGlobals = !0;
2000
+ if (!channel.readyId && !state.hasWrittenGlobals) {
2001
+ state.hasWrittenGlobals = !0;
2162
2002
  let globals = getFilteredGlobals(state.$global);
2163
2003
  globals && flushes.push([
2164
2004
  0,
@@ -2174,12 +2014,12 @@ function flushSerializer(boundary, serializeState) {
2174
2014
  props
2175
2015
  ]);
2176
2016
  }
2177
- (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);
2017
+ (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);
2178
2018
  }
2179
2019
  }
2180
2020
  function flushSerializerGlobals(boundary) {
2181
2021
  let { state } = boundary, globals = getFilteredGlobals(state.$global);
2182
- globals && (state.hasGlobals = !0, state.needsMainRuntime = !0, state.resumes = concatSequence(state.resumes, state.serializer.stringifyScopes([[
2022
+ globals && (state.hasWrittenGlobals = !0, state.needsWalkerRuntime = !0, state.resumes = concatSequence(state.resumes, stringifyScopes(state.serializer, [[
2183
2023
  0,
2184
2024
  globals,
2185
2025
  globals
@@ -2345,7 +2185,7 @@ var ServerRendered = class {
2345
2185
  });
2346
2186
  },
2347
2187
  return(value) {
2348
- return done || aborted || boundary?.abort(/* @__PURE__ */ Error("Iterator returned before consumed.")), Promise.resolve({
2188
+ return done || aborted || boundary?.abort(/* @__PURE__ */ Error()), Promise.resolve({
2349
2189
  value,
2350
2190
  done: !0
2351
2191
  });
@@ -2394,7 +2234,7 @@ var ServerRendered = class {
2394
2234
  #promise() {
2395
2235
  return this.#cachedPromise ||= new Promise((resolve, reject) => {
2396
2236
  let head = this.#head;
2397
- if (this.#head = null, !head) return reject(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2237
+ if (this.#head = null, !head) return reject(/* @__PURE__ */ Error());
2398
2238
  let { boundary } = head, html = "";
2399
2239
  (boundary.onNext = () => {
2400
2240
  switch (!boundary.count && boundary.flush()) {
@@ -2411,7 +2251,7 @@ var ServerRendered = class {
2411
2251
  #read(onWrite, onAbort, onClose) {
2412
2252
  let tick = !0, flushing = !1, again = !1, head = this.#head;
2413
2253
  if (this.#head = null, !head) {
2414
- onAbort(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2254
+ onAbort(/* @__PURE__ */ Error());
2415
2255
  return;
2416
2256
  }
2417
2257
  let { boundary } = head, onNext = boundary.onNext = (write) => {
@@ -2444,9 +2284,9 @@ var ServerRendered = class {
2444
2284
  }
2445
2285
  toString() {
2446
2286
  let head = this.#head;
2447
- if (this.#head = null, !head) throw Error(CONSUMED_RESULT_MESSAGE);
2287
+ if (this.#head = null, !head) throw /* @__PURE__ */ Error();
2448
2288
  let { boundary } = head, html = boundary.flush() === 0 ? head.consume(boundary).flushHTML(boundary) : "";
2449
- if (boundary.count && boundary.abort(/* @__PURE__ */ Error("Cannot consume asynchronous render with 'toString'")), settle(boundary), boundary.aborted) throw boundary.reason;
2289
+ if (boundary.count && boundary.abort(/* @__PURE__ */ Error()), settle(boundary), boundary.aborted) throw boundary.reason;
2450
2290
  return html;
2451
2291
  }
2452
2292
  };
@@ -2456,18 +2296,19 @@ function settle(boundary) {
2456
2296
  function NOOP$1() {}
2457
2297
  //#endregion
2458
2298
  //#region src/html/assets.ts
2459
- function withLoadAssets(renderer, flush, assetId, triggers) {
2460
- return register(renderer.a, Object.assign((input) => (writeLoadAsset(assetId, flush, triggers), writeWaitReady(assetId, renderer, input)), renderer));
2299
+ function withLoadAssets(template, id, flush, assetId, triggers) {
2300
+ let renderer = (input) => (writeLoadAsset(assetId, flush, triggers), writeWaitReady(assetId, template(), input));
2301
+ return _template(id, renderer), renderer;
2461
2302
  }
2462
2303
  function writeLoadAsset(assetId, flush, triggers) {
2463
2304
  let g = $global();
2464
2305
  writeAsset(g, addAsset(g, assetId, flush, triggers));
2465
2306
  }
2466
- function withPageAssets(template, runtime, assetId, runtimeId) {
2307
+ function withPageAssets(template, flush, assetId, runtimeId) {
2467
2308
  return Object.assign((input) => {
2468
2309
  let g = $global();
2469
2310
  runtimeId && (g[kAssets] || (g.runtimeId = runtimeId));
2470
- let asset = addAsset(g, assetId, runtime);
2311
+ let asset = addAsset(g, assetId, flush);
2471
2312
  return g.__flush__ ? (writeAsset(g, asset), writeWaitReady(assetId, template, input)) : (g.__flush__ = flushPage, template(input));
2472
2313
  }, template);
2473
2314
  }
@@ -2538,6 +2379,212 @@ function toObjectExpression(options) {
2538
2379
  //#endregion
2539
2380
  //#region src/common/compat-meta.ts
2540
2381
  //#endregion
2382
+ //#region src/common/for.ts
2383
+ function forIn(obj, cb) {
2384
+ for (let key in obj) cb(key, obj[key]);
2385
+ }
2386
+ function forOf(list, cb) {
2387
+ if (list) {
2388
+ let i = 0;
2389
+ for (let item of list) cb(item, i++);
2390
+ }
2391
+ }
2392
+ function forTo(to, from, step, cb) {
2393
+ let start = from || 0, delta = step || 1;
2394
+ for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
2395
+ }
2396
+ function forUntil(until, from, step, cb) {
2397
+ let start = from || 0, delta = step || 1;
2398
+ for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
2399
+ }
2400
+ //#endregion
2401
+ //#region src/html/for.ts
2402
+ function forOfBy(by, item, index) {
2403
+ return by ? typeof by == "string" ? item[by] : by(item, index) : index;
2404
+ }
2405
+ function forInBy(by, name, value) {
2406
+ return by ? by(name, value) : name;
2407
+ }
2408
+ function forStepBy(by, index) {
2409
+ return by ? by(index) : index;
2410
+ }
2411
+ //#endregion
2412
+ //#region src/html/control-flow.ts
2413
+ function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
2414
+ display ? resumesMarker(markerGuard, branchExprGuard, parentEndTag) && $chunk.writeHTML($chunk.boundary.state.mark("[", "")) : $chunk.writeHTML("<t hidden>");
2415
+ }
2416
+ function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2417
+ let branchId = _scope_id(), wrap = !display;
2418
+ wrap && $chunk.writeHTML("</t>"), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
2419
+ }
2420
+ function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2421
+ forBranches(by, cb, iterateForOf(list, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2422
+ }
2423
+ function iterateForOf(list, cb, by) {
2424
+ return (each) => each ? forOf(list, (item, index) => {
2425
+ let itemKey = forOfBy(by, item, index);
2426
+ each(itemKey, itemKey === index, item, index);
2427
+ }) : forOf(list, cb);
2428
+ }
2429
+ function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2430
+ forBranches(by, cb, iterateForIn(obj, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2431
+ }
2432
+ function iterateForIn(obj, cb, by) {
2433
+ return (each) => each ? forIn(obj, (key, value) => {
2434
+ each(forInBy(by, key, value), !1, key, value);
2435
+ }) : forIn(obj, cb);
2436
+ }
2437
+ function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2438
+ forBranches(by, cb, iterateForTo(to, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2439
+ }
2440
+ function iterateForTo(to, from, step, cb, by) {
2441
+ return (each) => {
2442
+ let index = 0;
2443
+ return each ? forTo(to, from, step, (value) => {
2444
+ let itemKey = forStepBy(by, value);
2445
+ each(itemKey, itemKey === index++, value);
2446
+ }) : forTo(to, from, step, cb);
2447
+ };
2448
+ }
2449
+ function _for_until(until, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2450
+ forBranches(by, cb, iterateForUntil(until, from, step, cb, by), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
2451
+ }
2452
+ function iterateForUntil(until, from, step, cb, by) {
2453
+ return (each) => {
2454
+ let index = 0;
2455
+ return each ? forUntil(until, from, step, (value) => {
2456
+ let itemKey = forStepBy(by, value);
2457
+ each(itemKey, itemKey === index++, value);
2458
+ }) : forUntil(until, from, step, cb);
2459
+ };
2460
+ }
2461
+ function forBranches(by, cb, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2462
+ if (branchGuard === 0) {
2463
+ iterate(0), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
2464
+ return;
2465
+ }
2466
+ let { state } = $chunk.boundary, resumeKeys = markerGuard !== 0, resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag), flushBranchIds = "", loopScopes;
2467
+ iterate((itemKey, sameAsIndex, a, b) => {
2468
+ let branchId = _peek_scope_id();
2469
+ resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(state.mark("[", flushBranchIds)), flushBranchIds = branchId + "")), withBranchId(branchId, cb, a, b);
2470
+ let branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { M: itemKey } : {});
2471
+ resumeMarker || (loopScopes = push(loopScopes, branchScope));
2472
+ }), loopScopes && writeScope(scopeId, { ["A" + accessor]: loopScopes }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
2473
+ }
2474
+ function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
2475
+ 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;
2476
+ beforeBranch !== void 0 && applyBranchStart(chunk, beforeBranch, shouldWriteBranch), shouldWriteBranch && (branchIndex || !resumeMarker) && writeScope(scopeId, {
2477
+ ["D" + accessor]: branchIndex || void 0,
2478
+ ["A" + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
2479
+ }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
2480
+ }
2481
+ function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
2482
+ return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
2483
+ }
2484
+ function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
2485
+ let endTag = parentEndTag || "";
2486
+ if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
2487
+ let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
2488
+ $chunk.writeHTML(mark + endTag);
2489
+ } else markerGuard === 0 ? $chunk.writeHTML(endTag) : $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
2490
+ }
2491
+ function _await(scopeId, accessor, promise, content, markerGuard) {
2492
+ let resumeMarker = markerGuard !== 0;
2493
+ if (!isPromise(promise)) {
2494
+ if (resumeMarker) {
2495
+ let branchId = _peek_scope_id();
2496
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, content, promise), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
2497
+ } else content(promise);
2498
+ return;
2499
+ }
2500
+ let chunk = $chunk, { boundary } = chunk, startId = _peek_scope_id(), after = chunk.next = chunk.forkRest(boundary);
2501
+ chunk.async = !0, captureContext(chunk), boundary.startAsync(), promise.then((value) => {
2502
+ if (chunk.async && (chunk.async = !1, !boundary.aborted)) {
2503
+ let { state } = boundary;
2504
+ chunk.render(() => {
2505
+ if (resumeMarker) {
2506
+ let branchId = _peek_scope_id();
2507
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withAsyncContent({ parent: getAsyncContent(chunk) }, content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
2508
+ } else {
2509
+ let renderedSince = _peek_scope_id() !== startId, async = { parent: getAsyncContent(chunk) };
2510
+ 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;
2511
+ }
2512
+ }), !chunk.async && boundary.pendingReorders?.delete(chunk) && state.reorder(chunk), boundary.endAsync();
2513
+ }
2514
+ }, (err) => {
2515
+ chunk.async = !1, boundary.abort(err);
2516
+ });
2517
+ }
2518
+ function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
2519
+ 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);
2520
+ applyBranchStart(chunk, beforeBranch, keepsMarks), keepsMarks && (writesRenderers || renderers(), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
2521
+ }
2522
+ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
2523
+ let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
2524
+ if (body === body.render(content)) {
2525
+ chunk.append(body);
2526
+ return;
2527
+ }
2528
+ chunk.next = chunk.forkRest(boundary), captureContext(chunk), chunk.placeholder = {
2529
+ body,
2530
+ render: placeholder,
2531
+ branchId,
2532
+ scopeId,
2533
+ placeholderBranchId
2534
+ };
2535
+ }
2536
+ function tryBoundary(content, catchContent, branchId, renderers) {
2537
+ let chunk = $chunk, { boundary } = chunk, { state } = boundary, bodyBoundary = new Boundary(state, void 0, boundary);
2538
+ catchContent && (bodyBoundary.withinCatch = !0);
2539
+ let body = chunk.fork(bodyBoundary, null), bodyEnd = body.render(withBranchId, branchId, content);
2540
+ if (bodyBoundary.aborted) {
2541
+ if (!catchContent) throw bodyBoundary.reason;
2542
+ return catchContent(bodyBoundary.reason), !0;
2543
+ }
2544
+ if (body === bodyEnd) return chunk.append(body), !1;
2545
+ let renderersAtSettle = !bodyBoundary.resumeWrites, bodyNext = bodyEnd.next = chunk.forkRest(boundary);
2546
+ chunk.next = body, boundary.startAsync();
2547
+ let reorderId = catchContent ? state.nextReorderId() : "";
2548
+ return reorderId && (chunk.catchRange = {
2549
+ id: reorderId,
2550
+ end: bodyEnd
2551
+ }, captureContext(chunk)), bodyBoundary.onNext = () => {
2552
+ if (!boundary.aborted) {
2553
+ if (bodyBoundary.aborted) {
2554
+ if (!reorderId) {
2555
+ boundary.abort(bodyBoundary.reason);
2556
+ return;
2557
+ }
2558
+ let streamed = !chunk.catchRange, catchChunk = chunk.fork(boundary, null);
2559
+ chunk.catchRange = null, renderersAtSettle || catchChunk.render(clearTryRenderers, branchId);
2560
+ let inOrder = catchChunk === catchChunk.render(catchContent, bodyBoundary.reason);
2561
+ if (boundary.aborted) return;
2562
+ if ((bodyEnd.consumed || !inOrder) && (catchChunk.reorderBranch = branchId), bodyEnd.consumed) catchChunk.reorderId = reorderId, state.reorder(catchChunk);
2563
+ else {
2564
+ let reorder = null;
2565
+ inOrder ? streamed && (reorder = chunk.fork(boundary, null)) : reorder = catchChunk, reorder && (reorder.reorderId = reorderId);
2566
+ let endMarker = state.mark("!", reorderId), cut = body;
2567
+ for (; cut.consumed;) cut = cut.next;
2568
+ 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);
2569
+ }
2570
+ boundary.endAsync();
2571
+ } else bodyBoundary.count ? boundary.onNext() : (renderersAtSettle && bodyBoundary.resumeWrites && bodyEnd.render(renderers), chunk.catchRange = null, boundary.endAsync());
2572
+ }
2573
+ }, renderersAtSettle;
2574
+ }
2575
+ function clearTryRenderers(branchId) {
2576
+ writeScope(branchId, {
2577
+ E: 0,
2578
+ Q: _scope_with_id(branchId).Q && 0
2579
+ });
2580
+ }
2581
+ function writeTryRenderers(branchId, catchContent, placeholderContent) {
2582
+ writeScope(branchId, {
2583
+ E: catchContent,
2584
+ Q: placeholderContent
2585
+ });
2586
+ }
2587
+ //#endregion
2541
2588
  //#region src/html/compat.ts
2542
2589
  function drainClassFunctions($global, writeScope) {
2543
2590
  let pending = pendingClassFunctions.get($global), scopeByHost = {};
@@ -2554,4 +2601,4 @@ exports.$global = $global, exports._assert_class_toggles = _assert_class_toggles
2554
2601
  get: function() {
2555
2602
  return _dynamic_tag;
2556
2603
  }
2557
- }), exports._el = _el, exports._el_read_error = _el_read_error, exports._el_resume = _el_resume, exports._escape = _escape, exports._escape_comment = _escape_comment, exports._escape_script = _escape_script, exports._escape_style = _escape_style, exports._escape_style_value = _escape_style_value, exports._existing_scope = _existing_scope, exports._flush_head = _flush_head, exports._for_in = _for_in, exports._for_of = _for_of, exports._for_to = _for_to, exports._for_until = _for_until, exports._hoist = _hoist, exports._hoist_read_error = _hoist_read_error, exports._html = _html, exports._html_resume = _html_resume, exports._id = _id, exports._if = _if, exports._peek_scope_id = _peek_scope_id, exports._resume = _resume, exports._resume_branch = _resume_branch, exports._resume_locals = _resume_locals, exports._scope = writeScope, exports._scope_id = _scope_id, exports._scope_reason = _scope_reason, exports._scope_with_id = _scope_with_id, exports._script = _script, exports._set_scope_reason = _set_scope_reason, exports._show_end = _show_end, exports._show_start = _show_start, exports._style_html = _style_html, exports._subscribe = _subscribe, exports._template = _template, exports._text_resume = _text_resume, exports._textarea_value = _textarea_value, exports._to_text = _to_text, exports._trailers = _trailers, exports._try = _try, exports._unescaped = _unescaped, exports._var = _var, exports._write_guard = _write_guard, exports._write_if = _write_if, exports.attrTag = attrTag, exports.attrTags = attrTags, exports.compat = compat, exports.forIn = forIn, exports.forOf = forOf, exports.forTo = forTo, exports.forUntil = forUntil, exports.withLoadAssets = withLoadAssets, exports.withPageAssets = withPageAssets;
2604
+ }), exports._el = _el, exports._el_read_error = _el_read_error, exports._el_resume = _el_resume, exports._escape = _escape, exports._escape_comment = _escape_comment, exports._escape_script = _escape_script, exports._escape_style = _escape_style, exports._escape_style_value = _escape_style_value, exports._existing_scope = _existing_scope, exports._flush_head = _flush_head, exports._for_in = _for_in, exports._for_of = _for_of, exports._for_to = _for_to, exports._for_until = _for_until, exports._hoist = _hoist, exports._hoist_read_error = _hoist_read_error, exports._html = _html, exports._html_resume = _html_resume, exports._id = _id, exports._if = _if, exports._peek_scope_id = _peek_scope_id, exports._resume = _resume, exports._resume_branch = _resume_branch, exports._resume_locals = _resume_locals, exports._scope = writeScope, exports._scope_id = _scope_id, exports._scope_reason = _scope_reason, exports._scope_with_id = _scope_with_id, exports._script = _script, exports._set_scope_reason = _set_scope_reason, exports._show_end = _show_end, exports._show_start = _show_start, exports._signal_read_error = _signal_read_error, exports._style_html = _style_html, exports._subscribe = _subscribe, exports._template = _template, exports._text_resume = _text_resume, exports._textarea_value = _textarea_value, exports._to_text = _to_text, exports._trailers = _trailers, exports._try = _try, exports._unescaped = _unescaped, exports._var = _var, exports._write_guard = _write_guard, exports._write_if = _write_if, exports.attrTag = attrTag, exports.attrTags = attrTags, exports.compat = compat, exports.forIn = forIn, exports.forOf = forOf, exports.forTo = forTo, exports.forUntil = forUntil, exports.withLoadAssets = withLoadAssets, exports.withPageAssets = withPageAssets;