marko 6.3.56 → 6.4.1

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 (135) hide show
  1. package/cheatsheet.md +3 -3
  2. package/dist/common/constants/accessor-prefix.d.ts +2 -0
  3. package/dist/common/constants/accessor-prefix.debug.d.ts +2 -0
  4. package/dist/common/constants/accessor-prop.d.ts +3 -0
  5. package/dist/common/constants/accessor-prop.debug.d.ts +3 -0
  6. package/dist/common/constants/reserved-id.d.ts +5 -0
  7. package/dist/common/errors.d.ts +1 -1
  8. package/dist/common/types.d.ts +11 -2
  9. package/dist/debug/dom/catch.feat.js +12 -14
  10. package/dist/debug/dom/catch.feat.mjs +12 -14
  11. package/dist/debug/dom/controllable-input.feat.js +1 -1
  12. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  13. package/dist/debug/dom/controllable-open.feat.js +1 -1
  14. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  15. package/dist/debug/dom/controllable-select.feat.js +1 -1
  16. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  17. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  18. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  19. package/dist/debug/dom/controllable.feat.js +1 -1
  20. package/dist/debug/dom/controllable.feat.mjs +1 -1
  21. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  22. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  23. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  24. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  25. package/dist/debug/dom/lazy.feat.js +4 -0
  26. package/dist/debug/dom/lazy.feat.mjs +4 -0
  27. package/dist/debug/dom/placeholder.feat.js +1 -1
  28. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  29. package/dist/debug/{dom-DcwejnYg.js → dom-ClV4kVOO.js} +263 -193
  30. package/dist/debug/{dom-BeCNT5R5.mjs → dom-LFrKxOk5.mjs} +246 -182
  31. package/dist/debug/dom.js +14 -12
  32. package/dist/debug/dom.mjs +14 -12
  33. package/dist/debug/html.js +826 -685
  34. package/dist/debug/html.mjs +822 -683
  35. package/dist/dom/abort-signal.d.ts +2 -0
  36. package/dist/dom/catch.feat.js +6 -7
  37. package/dist/dom/catch.feat.mjs +5 -7
  38. package/dist/dom/control-flow.d.ts +3 -5
  39. package/dist/dom/controllable-input.feat.js +3 -2
  40. package/dist/dom/controllable-input.feat.mjs +1 -1
  41. package/dist/dom/controllable-open.feat.js +3 -2
  42. package/dist/dom/controllable-open.feat.mjs +1 -1
  43. package/dist/dom/controllable-select.feat.js +3 -2
  44. package/dist/dom/controllable-select.feat.mjs +1 -1
  45. package/dist/dom/controllable-textarea.feat.js +3 -2
  46. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  47. package/dist/dom/controllable.feat.js +3 -2
  48. package/dist/dom/controllable.feat.mjs +1 -1
  49. package/dist/dom/dynamic-tag-script.feat.js +3 -2
  50. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  51. package/dist/dom/dynamic-tag-var.feat.js +2 -1
  52. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  53. package/dist/dom/lazy.feat.d.ts +1 -0
  54. package/dist/dom/lazy.feat.js +4 -0
  55. package/dist/dom/lazy.feat.mjs +4 -0
  56. package/dist/dom/load.d.ts +3 -3
  57. package/dist/dom/placeholder.feat.js +4 -3
  58. package/dist/dom/placeholder.feat.mjs +1 -1
  59. package/dist/dom/queue.d.ts +2 -4
  60. package/dist/dom/resume.d.ts +1 -1
  61. package/dist/dom/scope.d.ts +0 -1
  62. package/dist/dom/signals.d.ts +3 -2
  63. package/dist/{dom-QEF0csuC.js → dom-CNglVi8P.js} +222 -185
  64. package/dist/{dom-BwNsIevR.mjs → dom-DfP3MCo0.mjs} +126 -90
  65. package/dist/dom.js +59 -56
  66. package/dist/dom.mjs +34 -32
  67. package/dist/html/attrs.d.ts +4 -2
  68. package/dist/html/dynamic-tag.d.ts +1 -1
  69. package/dist/html/inlined-runtimes.d.ts +1 -1
  70. package/dist/html/inlined-runtimes.debug.d.ts +1 -1
  71. package/dist/html/serializer.d.ts +1 -1
  72. package/dist/html/writer.d.ts +39 -33
  73. package/dist/html.d.ts +2 -2
  74. package/dist/html.js +526 -424
  75. package/dist/html.mjs +524 -423
  76. package/dist/translator/core/html-comment.d.ts +0 -7
  77. package/dist/translator/core/let.d.ts +0 -5
  78. package/dist/translator/core/show.d.ts +2 -5
  79. package/dist/translator/core/style.d.ts +6 -8
  80. package/dist/translator/index.d.ts +9 -0
  81. package/dist/translator/index.js +8195 -7939
  82. package/dist/translator/util/binding-has-prop.d.ts +3 -1
  83. package/dist/translator/util/binding-prop-tree.d.ts +4 -4
  84. package/dist/translator/util/bindings.d.ts +127 -0
  85. package/dist/translator/util/body-to-text-literal.d.ts +1 -2
  86. package/dist/translator/util/branch-tag.d.ts +7 -7
  87. package/dist/translator/util/constants/binding-type.d.ts +5 -6
  88. package/dist/translator/util/constants/slot-kind.d.ts +14 -0
  89. package/dist/translator/util/constants/structure-kind.d.ts +1 -1
  90. package/dist/translator/util/entry-builder.d.ts +2 -0
  91. package/dist/translator/util/evaluate.d.ts +11 -10
  92. package/dist/translator/util/finalize-references.d.ts +4 -0
  93. package/dist/translator/util/for-selector.d.ts +1 -1
  94. package/dist/translator/util/generate-uid.d.ts +7 -0
  95. package/dist/translator/util/get-declared-binding-expression.d.ts +2 -2
  96. package/dist/translator/util/is-core-tag.d.ts +0 -3
  97. package/dist/translator/util/is-only-child-in-parent.d.ts +2 -7
  98. package/dist/translator/util/known-tag.d.ts +8 -7
  99. package/dist/translator/util/read-replacement.d.ts +3 -0
  100. package/dist/translator/util/reasons.d.ts +32 -0
  101. package/dist/translator/util/references.d.ts +69 -167
  102. package/dist/translator/util/runtime.d.ts +3 -3
  103. package/dist/translator/util/scope-accessor.d.ts +14 -0
  104. package/dist/translator/util/scope-read.d.ts +1 -1
  105. package/dist/translator/util/sections.d.ts +56 -50
  106. package/dist/translator/util/set-tag-derived-from.d.ts +7 -0
  107. package/dist/translator/util/setup-work.d.ts +4 -0
  108. package/dist/translator/util/signals.d.ts +8 -12
  109. package/dist/translator/util/slots.d.ts +50 -0
  110. package/dist/translator/util/solve-reasons.d.ts +10 -0
  111. package/dist/translator/util/sources.d.ts +21 -0
  112. package/dist/translator/util/structure.d.ts +5 -2
  113. package/dist/translator/util/tag-facts.d.ts +21 -0
  114. package/dist/translator/util/tag-name-type.d.ts +4 -1
  115. package/dist/translator/util/translate-attrs.d.ts +2 -0
  116. package/dist/translator/util/translate-var.d.ts +3 -0
  117. package/dist/translator/util/write-guard.d.ts +12 -0
  118. package/dist/translator/util/writer.d.ts +3 -3
  119. package/dist/translator/visitors/export-declaration.d.ts +9 -0
  120. package/dist/translator/visitors/function.d.ts +5 -4
  121. package/dist/translator/visitors/import-declaration.d.ts +2 -2
  122. package/dist/translator/visitors/placeholder.d.ts +0 -3
  123. package/dist/translator/visitors/program/index.d.ts +13 -3
  124. package/dist/translator/visitors/referenced-identifier.d.ts +2 -1
  125. package/dist/translator/visitors/tag/custom-tag.d.ts +1 -1
  126. package/dist/translator/visitors/tag/dynamic-tag.d.ts +0 -3
  127. package/dist/translator/visitors/tag/index.d.ts +2 -1
  128. package/dist/translator/visitors/tag/native-tag.d.ts +26 -11
  129. package/package.json +3 -3
  130. package/dist/translator/util/insertion-context.d.ts +0 -1
  131. package/dist/translator/util/is-non-html-text.d.ts +0 -3
  132. package/dist/translator/util/serialize-guard.d.ts +0 -11
  133. package/dist/translator/util/serialize-reasons.d.ts +0 -37
  134. package/dist/translator/util/set-tag-sections-downstream.d.ts +0 -6
  135. package/dist/translator/util/setup-statements.d.ts +0 -5
package/dist/html.mjs CHANGED
@@ -1,10 +1,12 @@
1
1
  let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeStyleAttr = (c) => c === ";" ? "\\3B " : "\\\\", toDelimitedString = function toDelimitedString(val, delimiter, stringify) {
2
2
  let str = "", sep = "", part;
3
- if (val) if (typeof val != "object") str += val;
4
- else if (Array.isArray(val)) for (let v of val) part = toDelimitedString(v, delimiter, stringify), part && (str += sep + part, sep = delimiter);
5
- else for (let name in val) part = stringify(name, val[name]), part && (str += sep + part, sep = delimiter);
3
+ if (val) {
4
+ if (typeof val != "object") str += val;
5
+ else if (Array.isArray(val)) for (let v of val) part = toDelimitedString(v, delimiter, stringify), part && (str += sep + part, sep = delimiter);
6
+ else for (let name in val) part = stringify(name, val[name]), part && (str += sep + part, sep = delimiter);
7
+ }
6
8
  return str;
7
- }, 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, "\\x3C$1") : str, unsafeStyleReg = /<(\/style)/gi, escapeStyleStr = (str) => unsafeStyleReg.test(str) ? str.replace(unsafeStyleReg, "\\3C$1") : str, unsafeCommentReg = />/g, escapeCommentStr = (str) => unsafeCommentReg.test(str) ? str.replace(unsafeCommentReg, "&gt;") : str, K_SCOPE_ID = Symbol("Scope ID"), kTouchedIterator = /* @__PURE__ */ Symbol.for("marko.touchedIterator"), { hasOwnProperty } = {}, objectProto = Object.prototype, arrayProto = Array.prototype, Generator = (/* @__PURE__ */ (function* () {})()).constructor, AsyncGenerator = (/* @__PURE__ */ (async function* () {})()).constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = /* @__PURE__ */ (() => {
9
+ }, K_SCOPE_ID = Symbol("Scope ID"), kTouchedIterator = /* @__PURE__ */ Symbol.for("marko.touchedIterator"), { hasOwnProperty } = {}, objectProto = Object.prototype, arrayProto = Array.prototype, Generator = (/* @__PURE__ */ (function* () {})()).constructor, AsyncGenerator = (/* @__PURE__ */ (async function* () {})()).constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = /* @__PURE__ */ (() => {
8
10
  let KNOWN_SYMBOLS = /* @__PURE__ */ new Map();
9
11
  for (let name of Object.getOwnPropertyNames(Symbol)) {
10
12
  let symbol = Symbol[name];
@@ -80,7 +82,6 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
80
82
  [Function, "Function"],
81
83
  [globalThis.atob, "atob"],
82
84
  [globalThis.btoa, "btoa"],
83
- [globalThis.clearImmediate, "clearImmediate"],
84
85
  [globalThis.clearInterval, "clearInterval"],
85
86
  [globalThis.clearTimeout, "clearTimeout"],
86
87
  [globalThis.crypto?.getRandomValues, "crypto.getRandomValues"],
@@ -88,7 +89,6 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
88
89
  [globalThis.fetch, "fetch"],
89
90
  [globalThis.performance?.now, "performance.now"],
90
91
  [globalThis.queueMicrotask, "queueMicrotask"],
91
- [globalThis.setImmediate, "setImmediate"],
92
92
  [globalThis.setInterval, "setInterval"],
93
93
  [globalThis.setTimeout, "setTimeout"],
94
94
  [globalThis.structuredClone, "structuredClone"],
@@ -244,20 +244,20 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
244
244
  if (ch === "\0") return "\\x00";
245
245
  let code = ch.charCodeAt(0);
246
246
  return code >= 55296 && code <= 57343 ? "\\u" + code.toString(16).padStart(4, "0") : match;
247
- }, unsafeQuoteReg = /["\\<\n\r\u2028\u2029\0\ud800-\udfff]/u, $chunk, kPendingContexts = Symbol("Pending Contexts"), kBranchId = Symbol("Branch Id"), kIsAsync = Symbol("Is Async"), writeScope = (scopeId, partialScope) => {
247
+ }, 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) => {
248
248
  let { state } = $chunk.boundary, target = $chunk.serializeState, scope = scopeWithId(state, scopeId), pending = target.writeScopes[scopeId];
249
- return state.needsMainRuntime = !0, countResumeWrite($chunk.boundary), Object.assign(scope, partialScope), pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0, scope;
250
- }, CLIENT_ALL = 715827883, NOOP$2 = () => {}, tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb)), tickQueue, 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, 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, serializeReason) => {
251
- let shouldResume = serializeReason !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = _peek_scope_id(), rendered, result;
249
+ 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;
250
+ }, 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, "\\x3C$1") : 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) => {
251
+ let shouldResume = markerGuard !== 0, renderer = normalizeDynamicRenderer(tag), state = getState(), branchId = _peek_scope_id(), rendered, result;
252
252
  if (typeof renderer == "string") {
253
253
  let input = (inputIsArgs ? inputOrArgs[0] : inputOrArgs) || {};
254
254
  rendered = !0, (() => {
255
255
  if (_scope_id(), _html(`<${renderer}${_attrs(input, "a", branchId, renderer)}>`), !voidElementsReg.test(renderer)) {
256
256
  let renderContent = content || normalizeDynamicRenderer(input.content);
257
- if (renderer === "textarea") _html(_attr_textarea_value(branchId, "a", input.value, input.valueChange, 1));
257
+ if (renderer === "textarea") _html(_attrs_textarea_value(branchId, "a", input));
258
258
  else {
259
259
  if (renderContent && typeof renderContent != "function") throw Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
260
- 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, serializeReason) : void 0, 1) : renderContent && _dynamic_tag(branchId, "a", renderContent, void 0, 0, void 0, serializeReason);
260
+ 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);
261
261
  }
262
262
  _html(`</${renderer}>`);
263
263
  }
@@ -267,12 +267,12 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
267
267
  } else {
268
268
  let chunk = getChunk(), beforeBranch = shouldResume ? deferBranchStart(chunk) : void 0, render = () => {
269
269
  if (renderer) try {
270
- return _set_serialize_reason(shouldResume && inputOrArgs !== void 0 ? CLIENT_ALL : 0), inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
270
+ return _set_scope_reason(shouldResume && inputOrArgs !== void 0 ? CLIENT_ALL : 0), inputIsArgs ? renderer(...inputOrArgs) : renderer(content ? {
271
271
  ...inputOrArgs,
272
272
  content
273
273
  } : inputOrArgs);
274
274
  } finally {
275
- _set_serialize_reason(void 0);
275
+ _set_scope_reason(void 0);
276
276
  }
277
277
  else if (content) return content();
278
278
  };
@@ -303,8 +303,8 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
303
303
  },
304
304
  onFlush(fn) {
305
305
  let { flushHTML } = Chunk.prototype;
306
- Chunk.prototype.flushHTML = function() {
307
- return fn(this), flushHTML.call(this);
306
+ Chunk.prototype.flushHTML = function(boundary) {
307
+ return fn(this), flushHTML.call(this, boundary);
308
308
  };
309
309
  },
310
310
  patchDynamicTag,
@@ -333,15 +333,13 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
333
333
  },
334
334
  flushScript($global, chunk) {
335
335
  chunk ||= this.createChunk($global);
336
- let { boundary } = chunk;
337
- switch (boundary.flush()) {
338
- case 2: throw boundary.signal.reason;
339
- case 1: throw Error("Cannot serialize promise across tags/class compat layer.");
340
- }
341
- return chunk.flushScript().scripts;
336
+ let { boundary } = chunk, scripts = boundary.flush() === 0 ? chunk.flushScript(boundary).scripts : "";
337
+ if (boundary.aborted) throw boundary.reason;
338
+ if (boundary.count) throw Error("Cannot serialize promise across tags/class compat layer.");
339
+ return scripts;
342
340
  },
343
341
  render(renderer, willRerender, classAPIOut, component, input, completeChunks, registerChildScope) {
344
- let state = this.ensureState(classAPIOut.global), boundary = new Boundary(state), head = new Chunk(boundary, null, getChunk()?.context ?? null, state), normalizedInput = input;
342
+ let state = this.ensureState(classAPIOut.global), boundary = new Boundary(state), context = getChunk()?.context ?? null, head = new Chunk(boundary, new Chunk(boundary, null, context, state), context, state), normalizedInput = input;
345
343
  if ("renderBody" in input) {
346
344
  normalizedInput = {};
347
345
  for (let key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
@@ -357,11 +355,11 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
357
355
  let scopeId = _peek_scope_id();
358
356
  writeScope(scopeId, { m5c: component.id }), _script(scopeId, SET_SCOPE_REGISTER_ID);
359
357
  }
360
- _set_serialize_reason(willRerender ? CLIENT_ALL : 0);
358
+ _set_scope_reason(willRerender ? CLIENT_ALL : 0);
361
359
  try {
362
360
  renderer(normalizedInput);
363
361
  } finally {
364
- _set_serialize_reason(void 0);
362
+ _set_scope_reason(void 0);
365
363
  }
366
364
  let asyncOut = classAPIOut.beginAsync({
367
365
  last: !0,
@@ -369,7 +367,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
369
367
  });
370
368
  classAPIOut.onLast((next) => {
371
369
  (boundary.onNext = () => {
372
- boundary.signal.aborted ? (asyncOut.error(boundary.signal.reason), boundary.onNext = NOOP) : boundary.count || (boundary.onNext = NOOP, head = head.consume(), asyncOut.write(head.html), asyncOut.script(head.scripts), asyncOut.end(), head.html = head.scripts = "", completeChunks.push(head), next());
370
+ boundary.aborted ? (asyncOut.error(boundary.reason), boundary.onNext = NOOP) : boundary.count || (boundary.onNext = NOOP, head = head.consume(boundary), asyncOut.write(head.html), asyncOut.script(head.scripts), asyncOut.end(), head.html = head.scripts = "", completeChunks.push(head), next());
373
371
  })();
374
372
  });
375
373
  });
@@ -454,27 +452,38 @@ function _el_read_error() {}
454
452
  function _hoist_read_error() {}
455
453
  function _assert_hoist(value) {}
456
454
  //#endregion
457
- //#region src/html/content.ts
458
- function _to_text(val) {
459
- return val || val === 0 ? val + "" : "";
460
- }
461
- function _unescaped(val) {
462
- return val ? val + "" : val === 0 ? "0" : "";
455
+ //#region src/common/for.ts
456
+ function forIn(obj, cb) {
457
+ for (let key in obj) cb(key, obj[key]);
463
458
  }
464
- function _escape(val) {
465
- return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
459
+ function forOf(list, cb) {
460
+ if (list) {
461
+ let i = 0;
462
+ for (let item of list) cb(item, i++);
463
+ }
466
464
  }
467
- function _escape_script(val) {
468
- return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
465
+ function forTo(to, from, step, cb) {
466
+ let start = from || 0, delta = step || 1;
467
+ for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
469
468
  }
470
- function _escape_style(val) {
471
- return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
469
+ function forUntil(until, from, step, cb) {
470
+ let start = from || 0, delta = step || 1;
471
+ for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
472
472
  }
473
- function _escape_style_value(val) {
474
- return val || val === 0 ? escapeStyleValue(val + "") : "";
473
+ //#endregion
474
+ //#region src/common/opt.ts
475
+ function push(opt, item) {
476
+ return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
475
477
  }
476
- function _escape_comment(val) {
477
- return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
478
+ function concat(opt, other) {
479
+ if (!opt) return other;
480
+ if (!other) return opt;
481
+ if (Array.isArray(opt)) {
482
+ if (Array.isArray(other)) for (let item of other) opt.push(item);
483
+ else opt.push(other);
484
+ return opt;
485
+ }
486
+ return Array.isArray(other) ? [opt, ...other] : [opt, other];
478
487
  }
479
488
  patchIteratorNext(Generator.prototype), patchIteratorNext(AsyncGenerator.prototype);
480
489
  var State$1 = class {
@@ -514,6 +523,8 @@ var State$1 = class {
514
523
  stringifyScopes(flushes, boundary, channel) {
515
524
  try {
516
525
  return this.#state.boundary = boundary, this.#state.channel = channel, writeScopesRoot(this.#state, flushes);
526
+ } catch (err) {
527
+ return abortRender(boundary, err), "";
517
528
  } finally {
518
529
  this.#state.flushId++, this.#state.buf = [];
519
530
  }
@@ -590,13 +601,15 @@ function writeAssigned(state) {
590
601
  let hasSeen = state.refs.get(mutation.object)?.id, objectStartIndex = state.buf.push(state.buf.length === 0 ? "" : ",");
591
602
  if (writeProp(state, mutation.object, null, "")) {
592
603
  let objectRef = state.refs.get(mutation.object);
593
- objectRef && objectRef.scopeId === void 0 && (objectRef.id ? hasSeen || (state.buf[objectStartIndex] = "(" + state.buf[objectStartIndex], state.buf.push(")")) : (objectRef.id = nextRefAccess(state), state.buf[objectStartIndex] = "(" + objectRef.id + "=" + state.buf[objectStartIndex], state.buf.push(")")));
604
+ 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(")")));
594
605
  } else state.buf.push("void 0");
595
606
  let valueStartIndex = state.buf.push(toAccess(toObjectKey(mutation.property)) + "(");
596
- if (mutation.value !== void 0) if (writeProp(state, mutation.value, null, "")) {
597
- let valueRef = typeof mutation.value == "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
598
- valueRef && !valueRef.id && valueRef.scopeId === void 0 && (valueRef.id = mutation.valueId || nextRefAccess(state), state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex]);
599
- } else state.buf.push("void 0");
607
+ if (mutation.value !== void 0) {
608
+ if (writeProp(state, mutation.value, null, "")) {
609
+ let valueRef = typeof mutation.value == "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
610
+ valueRef && !valueRef.id && valueRef.scopeId === void 0 && !isAncestorChannelRef(state, valueRef) && (valueRef.id = mutation.valueId || nextRefAccess(state), state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex]);
611
+ } else state.buf.push("void 0");
612
+ }
600
613
  state.buf.push(")");
601
614
  }
602
615
  state.mutated = remaining;
@@ -607,7 +620,7 @@ function writeCallArg(state, val) {
607
620
  if (val === void 0) state.wroteUndefined = !0, state.buf.push("$");
608
621
  else if (writeProp(state, val, null, "")) {
609
622
  let ref = state.refs.get(val) || state.strs.get(val);
610
- ref && ref.id === null && assignId(state, ref);
623
+ ref && ensureId(state, ref);
611
624
  } else state.buf.push("void 0");
612
625
  }
613
626
  function hasChannelMutations(state) {
@@ -659,7 +672,7 @@ function writeRegistered(state, val, parent, accessor, registered) {
659
672
  let locals = registered.locals?.(state.boundary.state.scope);
660
673
  if (locals) {
661
674
  state.buf.push(registered.access + "(_(" + scopeId + ")");
662
- for (let local of locals) state.buf.push(","), local ? writePlainObject(state, local, new Reference(ref, null, state.flushId, state.buf.length)) : state.buf.push("0");
675
+ for (let local of locals) state.buf.push(","), writePlainObject(state, local, newArgReference(state, ref, local));
663
676
  } else state.buf.push("_(" + scopeId + "," + quoteRegisterId(registered.id));
664
677
  state.buf.push(")");
665
678
  } else state.buf.push(registered.access);
@@ -716,7 +729,8 @@ function writeUnknownObject(state, val, ref) {
716
729
  let proto = Object.getPrototypeOf(val);
717
730
  if (proto === objectProto) return writePlainObject(state, val, ref);
718
731
  if (proto === arrayProto) return writeArray(state, val, ref);
719
- switch (proto?.constructor) {
732
+ let constructor = proto?.constructor;
733
+ switch (constructor) {
720
734
  case void 0: return writeNullObject(state, val, ref);
721
735
  case Object: return writePlainObject(state, val, ref);
722
736
  case Array: return writeArray(state, val, ref);
@@ -733,7 +747,7 @@ function writeUnknownObject(state, val, ref) {
733
747
  case ReferenceError:
734
748
  case SyntaxError:
735
749
  case TypeError:
736
- case URIError: return writeError(state, val, ref);
750
+ case URIError: return writeError(state, val, constructor.name, ref);
737
751
  case AggregateError: return writeAggregateError(state, val, ref);
738
752
  case ArrayBuffer: return writeArrayBuffer(state, val);
739
753
  case Int8Array:
@@ -746,7 +760,7 @@ function writeUnknownObject(state, val, ref) {
746
760
  case Float32Array:
747
761
  case Float64Array:
748
762
  case BigInt64Array:
749
- case BigUint64Array: return writeTypedArray(state, val, ref);
763
+ case BigUint64Array: return writeTypedArray(state, val, constructor.name, ref);
750
764
  case DataView: return writeDataView(state, val, ref);
751
765
  case WeakSet: return writeWeakSet(state);
752
766
  case WeakMap: return writeWeakMap(state);
@@ -858,6 +872,16 @@ function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
858
872
  } else state.buf.push(plainPrefix), writeArray(state, items, new Reference(ref, null, state.flushId, state.buf.length));
859
873
  state.buf.push(")");
860
874
  }
875
+ function newArgReference(state, parent, val) {
876
+ for (let key in val) {
877
+ let member = val[key];
878
+ if (isDedupedMember(member) && !(typeof member == "string" ? state.strs.has(member) : state.refs.has(member))) {
879
+ let ref = new Reference(parent, null, state.flushId, null, nextRefAccess(state));
880
+ return state.buf.push(ref.id + "="), ref;
881
+ }
882
+ }
883
+ return new Reference(parent, null, state.flushId, state.buf.length);
884
+ }
861
885
  function isDedupedMember(val) {
862
886
  switch (typeof val) {
863
887
  case "object": return val !== null && val[K_SCOPE_ID] === void 0;
@@ -884,12 +908,12 @@ function writeArrayBuffer(state, val) {
884
908
  } else result = "new ArrayBuffer";
885
909
  return state.buf.push(result), !0;
886
910
  }
887
- function writeTypedArray(state, val, ref) {
911
+ function writeTypedArray(state, val, name, ref) {
888
912
  if (val.byteOffset || val.byteLength < val.buffer.byteLength || state.refs.has(val.buffer)) {
889
913
  if (!canWriteBuffer(state, val.buffer, ref)) return !1;
890
914
  let needsLength = val.byteOffset + val.byteLength < val.buffer.byteLength;
891
- state.buf.push("new " + val.constructor.name + "("), writeProp(state, val.buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
892
- } else state.refs.set(val.buffer, new Reference(ref, "buffer", state.flushId, null)), state.buf.push("new " + val.constructor.name + (val.length === 0 ? "" : "(" + (hasOnlyZeros(val) ? val.length : typedArrayToInitString(val)) + ")"));
915
+ state.buf.push("new " + name + "("), writeProp(state, val.buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
916
+ } else state.refs.set(val.buffer, new Reference(ref, "buffer", state.flushId, null)), state.buf.push("new " + name + (val.length === 0 ? "" : "(" + (hasOnlyZeros(val) ? val.length : typedArrayToInitString(val)) + ")"));
893
917
  return !0;
894
918
  }
895
919
  function writeWeakSet(state) {
@@ -898,8 +922,8 @@ function writeWeakSet(state) {
898
922
  function writeWeakMap(state) {
899
923
  return state.buf.push("new WeakMap"), !0;
900
924
  }
901
- function writeError(state, val, ref) {
902
- let result = "new " + val.constructor.name + "(" + quote(val.message + "", 0);
925
+ function writeError(state, val, name, ref) {
926
+ let result = "new " + name + "(" + quote(val.message + "", 0);
903
927
  if (val.cause !== void 0) {
904
928
  let pos = state.buf.push(result + ",{cause:") - 1;
905
929
  writeProp(state, val.cause, ref, "cause") ? state.buf.push("})") : state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
@@ -961,14 +985,10 @@ function writeResponse(state, val, ref) {
961
985
  return !val.body || val.bodyUsed ? state.buf.push("new Response" + (options ? "(null,{" + options + "})" : "")) : (state.buf.push("new Response("), state.buf.push((writeProp(state, val.body, ref, "body") ? "" : "null") + (options ? ",{" + options + "})" : ")"))), !0;
962
986
  }
963
987
  function writeIntl(state, val, name, ref) {
964
- let { locale, ...options } = val.resolvedOptions(), needsId = !1;
965
- for (let key in options) if (isDedupedMember(options[key])) {
966
- needsId = !0;
967
- break;
968
- }
988
+ let { locale, ...options } = val.resolvedOptions();
969
989
  state.buf.push("new Intl." + name + "(" + quote(locale, 0) + ",");
970
- let optionsRef;
971
- return needsId ? (optionsRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state)), state.buf.push(optionsRef.id + "={")) : (optionsRef = new Reference(ref, null, state.flushId, state.buf.length), state.buf.push("{")), writeObjectProps(state, options, optionsRef), state.buf.push("})"), !0;
990
+ let optionsRef = newArgReference(state, ref, options);
991
+ return state.buf.push("{"), writeObjectProps(state, options, optionsRef), state.buf.push("})"), !0;
972
992
  }
973
993
  function writeIntlLocale(state, val) {
974
994
  return state.buf.push("new Intl.Locale(" + quote(val.toString(), 0) + ")"), !0;
@@ -979,7 +999,7 @@ function writeTemporal(state, val, name) {
979
999
  function writeReadableStream(state, val, ref) {
980
1000
  if (val.locked) return !1;
981
1001
  let { boundary, channel } = state, reader = val.getReader(), iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
982
- done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.signal.aborted || (reader.read().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
1002
+ done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (reader.read().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
983
1003
  }, onRejected = (reason) => {
984
1004
  writeAsyncCall(state, boundary, handle, "j", reason, channel);
985
1005
  };
@@ -1005,19 +1025,16 @@ function writeGenerator(state, iter, ref) {
1005
1025
  if (heldReturn) {
1006
1026
  let holder = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1007
1027
  state.buf.push("," + holder.id + "={}"), writeProp(state, returnValue, holder, "v");
1008
- } else if (returnValue !== void 0) {
1009
- let sepIndex = state.buf.push(",") - 1;
1010
- if (writeProp(state, returnValue, ref, "") && isDedupedMember(returnValue)) {
1011
- let retRef = typeof returnValue == "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
1012
- retRef && !retRef.id && retRef.scopeId === void 0 && (retRef.id = nextRefAccess(state), state.buf[sepIndex] = "," + retRef.id + "=");
1013
- }
1028
+ } else if (returnValue !== void 0 && (state.buf.push(","), writeProp(state, returnValue, ref, "") && isDedupedMember(returnValue))) {
1029
+ let retRef = typeof returnValue == "string" ? state.strs.get(returnValue) : state.refs.get(returnValue);
1030
+ retRef && ensureId(state, retRef);
1014
1031
  }
1015
1032
  return state.buf.push(")"), !0;
1016
1033
  }
1017
1034
  function writeAsyncGenerator(state, iter, ref) {
1018
1035
  if (iter[kTouchedIterator]) return state.buf.push("(async function*(){}())"), !0;
1019
1036
  let { boundary, channel } = state, iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1020
- done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.signal.aborted || (iter.next().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
1037
+ done ? writeAsyncCall(state, boundary, handle, "r", value, channel) : boundary.aborted || (iter.next().then(onFulfilled, onRejected), boundary.startAsync(), writeAsyncCall(state, boundary, handle, "f", value, channel));
1021
1038
  }, onRejected = (reason) => {
1022
1039
  writeAsyncCall(state, boundary, handle, "j", reason, channel);
1023
1040
  };
@@ -1048,7 +1065,7 @@ function writeMaybeIterableProps(state, val, ref) {
1048
1065
  return sep;
1049
1066
  }
1050
1067
  function writeAsyncCall(state, boundary, handle, method, value, channel, valueId = null) {
1051
- boundary.signal.aborted || (state.mutated.push({
1068
+ boundary.aborted || (state.mutated.push({
1052
1069
  value,
1053
1070
  object: handle,
1054
1071
  property: method,
@@ -1066,6 +1083,13 @@ function trackChannel(state, ref) {
1066
1083
  }
1067
1084
  return !1;
1068
1085
  }
1086
+ function isAncestorChannelRef(state, ref) {
1087
+ return ref.channel?.readyId !== state.channel?.readyId;
1088
+ }
1089
+ function abortRender(boundary, err) {
1090
+ for (; boundary.parent;) boundary = boundary.parent;
1091
+ boundary.abort(err);
1092
+ }
1069
1093
  function isCircular(parent, ref) {
1070
1094
  let cur = parent;
1071
1095
  for (; cur;) {
@@ -1078,16 +1102,17 @@ function toObjectKey(name) {
1078
1102
  if (name === "") return "\"\"";
1079
1103
  if (name === "__proto__") return "[\"__proto__\"]";
1080
1104
  let len = name.length, c0 = name.charCodeAt(0);
1081
- if (c0 >= 48 && c0 <= 57) if (c0 === 48) {
1082
- if (len !== 1) return quote(name, 1);
1083
- } else {
1084
- for (let i = 1; i < len; i++) {
1085
- let c = name.charCodeAt(i);
1086
- if (c < 48 || c > 57) return quote(name, i);
1105
+ if (c0 >= 48 && c0 <= 57) {
1106
+ if (c0 === 48) {
1107
+ if (len !== 1) return quote(name, 1);
1108
+ } else {
1109
+ for (let i = 1; i < len; i++) {
1110
+ let c = name.charCodeAt(i);
1111
+ if (c < 48 || c > 57) return quote(name, i);
1112
+ }
1113
+ if (len > 15 && "" + +name !== name) return quote(name, 0);
1087
1114
  }
1088
- if (len > 15 && "" + +name !== name) return quote(name, 0);
1089
- }
1090
- else if (c0 >= 97 && c0 <= 122 || c0 >= 65 && c0 <= 90 || c0 === 95 || c0 === 36) for (let i = 1; i < len; i++) {
1115
+ } else if (c0 >= 97 && c0 <= 122 || c0 >= 65 && c0 <= 90 || c0 === 95 || c0 === 36) for (let i = 1; i < len; i++) {
1091
1116
  let c = name.charCodeAt(i);
1092
1117
  if (!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 95 || c === 36)) return quote(name, i);
1093
1118
  }
@@ -1144,7 +1169,7 @@ function quote(str, startPos) {
1144
1169
  return "\"" + (lastPos === startPos ? str : result + str.slice(lastPos)) + "\"";
1145
1170
  }
1146
1171
  function writeRef(state, ref) {
1147
- ref.id === null && ref.scopeId === void 0 && ref.path === null && (ref.pos === null || ref.flushId !== state.flushId) ? (ref.path = accessPath(state, ref), ref.pos = state.buf.length, ref.flushId = state.flushId, ref.channel = state.channel, state.buf.push(ref.path)) : state.buf.push(ensureId(state, ref));
1172
+ 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));
1148
1173
  }
1149
1174
  function ensureId(state, ref) {
1150
1175
  return ref.scopeId === void 0 ? ref.id ? (trackChannel(state, ref), ref.id) : assignId(state, ref) : (trackChannel(state, ref), "_(" + ref.scopeId + ")");
@@ -1155,14 +1180,14 @@ function accessId(state, ref) {
1155
1180
  }
1156
1181
  function assignId(state, ref) {
1157
1182
  let { pos } = ref;
1158
- return ref.id = nextRefAccess(state), pos !== null && ref.flushId === state.flushId ? (pos === 0 ? state.buf[0] = ref.id + "=" + state.buf[0] : state.buf[pos - 1] += ref.id + "=", ref.id) : (ref.channel = state.channel, ref.id + "=" + (ref.path || accessPath(state, ref)));
1183
+ 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)));
1159
1184
  }
1160
1185
  function accessPath(state, ref) {
1161
1186
  let cur = ref, accessPrevValue = "";
1162
1187
  do {
1163
1188
  accessPrevValue = toAccess(cur.accessor) + accessPrevValue;
1164
1189
  let parent = cur.parent;
1165
- if (parent.id && (trackChannel(state, parent) || !parent.parent)) return parent.id + accessPrevValue;
1190
+ if (parent.id) return trackChannel(state, parent), parent.id + accessPrevValue;
1166
1191
  if (parent.flushId === state.flushId || parent.scopeId !== void 0) return accessId(state, parent) + accessPrevValue;
1167
1192
  cur = parent;
1168
1193
  } while (cur);
@@ -1180,7 +1205,7 @@ function nextRefAccess(state) {
1180
1205
  function nextId(state) {
1181
1206
  let c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789", n = state.ids++, r = c[n % 53];
1182
1207
  for (n = n / 53 | 0; n; n >>>= 6) r += c[n & 63];
1183
- return r;
1208
+ return r === "name" ? nextId(state) : r;
1184
1209
  }
1185
1210
  function hasSymbolIterator(value) {
1186
1211
  return Symbol.iterator in value;
@@ -1218,42 +1243,161 @@ function patchIteratorNext(proto) {
1218
1243
  }, proto.next[kTouchedIterator] = !0;
1219
1244
  }
1220
1245
  //#endregion
1221
- //#region src/common/for.ts
1222
- function forIn(obj, cb) {
1223
- for (let key in obj) cb(key, obj[key]);
1246
+ //#region src/html/attrs.ts
1247
+ function _attr_class(value) {
1248
+ return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
1224
1249
  }
1225
- function forOf(list, cb) {
1226
- if (list) {
1227
- let i = 0;
1228
- for (let item of list) cb(item, i++);
1250
+ function _attr_style(value) {
1251
+ return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
1252
+ }
1253
+ function _attr_option_value(value) {
1254
+ let valueAttr = _attr("value", value), selectedValue = getContext(kSelectedValue);
1255
+ return selectedValue !== void 0 && normalizedValueMatches(selectedValue, value) ? valueAttr + " selected" : valueAttr;
1256
+ }
1257
+ function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content, serializeType) {
1258
+ valueChange && writeControlledScope(3, scopeId, nodeAccessor, void 0, valueChange, serializeType), content && withContext(kSelectedValue, value ?? "", content);
1259
+ }
1260
+ function _attrs_select_value(scopeId, nodeAccessor, data, content) {
1261
+ data && ("value" in data || data.valueChange) ? _attr_select_value(scopeId, nodeAccessor, data.value, data.valueChange, content, 1) : content();
1262
+ }
1263
+ function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1264
+ return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _textarea_value(value);
1265
+ }
1266
+ function _attrs_textarea_value(scopeId, nodeAccessor, data) {
1267
+ return _attr_textarea_value(scopeId, nodeAccessor, data?.value, data?.valueChange, 1);
1268
+ }
1269
+ function _textarea_value(value) {
1270
+ let escaped = _escape(normalizeStrAttrValue(value));
1271
+ return escaped[0] === "\n" ? "\n" + escaped : escaped;
1272
+ }
1273
+ function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1274
+ return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _attr("value", value);
1275
+ }
1276
+ function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
1277
+ return checkedChange && writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType), isNotVoid(checked) ? " checked" : "";
1278
+ }
1279
+ function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
1280
+ let valueAttr = _attr("value", value);
1281
+ return checkedValueChange && writeControlledScope(1, scopeId, nodeAccessor, getCheckedValueRef(checkedValue), checkedValueChange, serializeType), normalizedValueMatches(checkedValue, value) ? valueAttr + " checked" : valueAttr;
1282
+ }
1283
+ function getCheckedValueRef(checkedValue) {
1284
+ if (Array.isArray(checkedValue)) {
1285
+ let ref = checkedValuesRefs.get(checkedValue);
1286
+ return ref || (ref = [], checkedValuesRefs.set(checkedValue, ref)), ref;
1229
1287
  }
1230
1288
  }
1231
- function forTo(to, from, step, cb) {
1232
- let start = from || 0, delta = step || 1;
1233
- for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
1289
+ function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
1290
+ let normalizedOpen = isNotVoid(open);
1291
+ return openChange && writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType), normalizedOpen ? " open" : "";
1234
1292
  }
1235
- function forUntil(until, from, step, cb) {
1236
- let start = from || 0, delta = step || 1;
1237
- for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
1293
+ function _attr_nonce() {
1294
+ return getChunk().boundary.state.nonceAttr;
1238
1295
  }
1239
- //#endregion
1240
- //#region src/common/opt.ts
1241
- function forEach(opt, cb) {
1242
- if (opt) if (Array.isArray(opt)) for (let item of opt) cb(item);
1243
- else cb(opt);
1296
+ function _style_html(decls) {
1297
+ let id = _id();
1298
+ return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
1244
1299
  }
1245
- function push(opt, item) {
1246
- return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
1300
+ function _attr(name, value) {
1301
+ return isVoid(value) ? "" : nonVoidAttr(name, value);
1247
1302
  }
1248
- function concat(opt, other) {
1249
- if (!opt) return other;
1250
- if (!other) return opt;
1251
- if (Array.isArray(opt)) {
1252
- if (Array.isArray(other)) for (let item of other) opt.push(item);
1253
- else opt.push(other);
1254
- return opt;
1303
+ function _attr_and(name, value, attr) {
1304
+ return value ? attr : _attr(name, value);
1305
+ }
1306
+ function _attr_or(name, value, attr) {
1307
+ return value ? _attr(name, value) : attr;
1308
+ }
1309
+ function _attr_nullish(name, value, attr) {
1310
+ return value == null ? attr : _attr(name, value);
1311
+ }
1312
+ function _attrs(data, nodeAccessor, scopeId, tagName) {
1313
+ let result = "", skip = /[\s/>"'=]/, events;
1314
+ switch (data && tagName) {
1315
+ case "input":
1316
+ data.checkedChange ? (result += _attr_input_checked(scopeId, nodeAccessor, data.checked, data.checkedChange, 1), skip = /^checked(?:Value)?(?:Change)?$|[\s/>"'=]/) : "checkedValue" in data || data.checkedValueChange ? (result += _attr_input_checkedValue(scopeId, nodeAccessor, data.checkedValue, data.checkedValueChange, data.value, 1), skip = /^(?:value|checked(?:Value)?)(?:Change)?$|[\s/>"'=]/) : data.valueChange && (result += _attr_input_value(scopeId, nodeAccessor, data.value, data.valueChange, 1), skip = /^value(?:Change)?$|[\s/>"'=]/);
1317
+ break;
1318
+ case "select":
1319
+ case "textarea":
1320
+ ("value" in data || data.valueChange) && (skip = /^value(?:Change)?$|[\s/>"'=]/);
1321
+ break;
1322
+ case "option":
1323
+ "value" in data && (result += _attr_option_value(data.value), skip = /^value$|[\s/>"'=]/);
1324
+ break;
1325
+ case "details":
1326
+ case "dialog": data.openChange && (result += _attr_details_or_dialog_open(scopeId, nodeAccessor, data.open, data.openChange, 1), skip = /^open(?:Change)?$|[\s/>"'=]/);
1255
1327
  }
1256
- return Array.isArray(other) ? [opt, ...other] : [opt, other];
1328
+ for (let name in data) {
1329
+ let value = data[name];
1330
+ switch (name) {
1331
+ case "class":
1332
+ result += _attr_class(value);
1333
+ break;
1334
+ case "style":
1335
+ result += _attr_style(value);
1336
+ break;
1337
+ 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));
1338
+ }
1339
+ }
1340
+ return result;
1341
+ }
1342
+ function _attrs_content(data, nodeAccessor, scopeId, tagName, markerGuard) {
1343
+ _html(`${_attrs(data, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, markerGuard);
1344
+ }
1345
+ function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
1346
+ let partial = {};
1347
+ for (let name in data) {
1348
+ let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
1349
+ skip[key] || (partial[key] = data[name]);
1350
+ }
1351
+ return _attrs(partial, nodeAccessor, scopeId, tagName);
1352
+ }
1353
+ function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, markerGuard) {
1354
+ _html(`${_attrs_partial(data, skip, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, markerGuard);
1355
+ }
1356
+ function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, serializeType) {
1357
+ writeScope(scopeId, serializeType ? {
1358
+ ["F" + nodeAccessor]: type,
1359
+ ["G" + nodeAccessor]: value,
1360
+ ["E" + nodeAccessor]: valueChange
1361
+ } : {
1362
+ ["G" + nodeAccessor]: value,
1363
+ ["E" + nodeAccessor]: valueChange
1364
+ });
1365
+ }
1366
+ function stringAttr(name, value) {
1367
+ return value && " " + name + attrAssignment(value);
1368
+ }
1369
+ function nonVoidAttr(name, value) {
1370
+ switch (typeof value) {
1371
+ case "string": return " " + name + attrAssignment(value);
1372
+ case "boolean": return " " + name;
1373
+ case "number": return " " + name + "=" + value;
1374
+ }
1375
+ return " " + name + attrAssignment(value + "");
1376
+ }
1377
+ function attrAssignment(value) {
1378
+ return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
1379
+ }
1380
+ function escapeSingleQuotedAttrValue(value) {
1381
+ return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
1382
+ }
1383
+ function replaceUnsafeSingleQuoteAttrChar(match) {
1384
+ return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
1385
+ }
1386
+ function escapeDoubleQuotedAttrValue(value) {
1387
+ return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
1388
+ }
1389
+ function replaceUnsafeDoubleQuoteAttrChar(match) {
1390
+ return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
1391
+ }
1392
+ function normalizedValueMatches(a, b) {
1393
+ let value = normalizeStrAttrValue(b);
1394
+ if (Array.isArray(a)) {
1395
+ for (let item of a) if (normalizeStrAttrValue(item) === value) return !0;
1396
+ } else if (normalizeStrAttrValue(a) === value) return !0;
1397
+ return !1;
1398
+ }
1399
+ function normalizeStrAttrValue(value) {
1400
+ return isNotVoid(value) && value !== !0 ? value + "" : "";
1257
1401
  }
1258
1402
  //#endregion
1259
1403
  //#region src/html/for.ts
@@ -1319,14 +1463,20 @@ function withContext(key, value, cb, cbValue) {
1319
1463
  ctx[kPendingContexts]--, ctx[key] = prev;
1320
1464
  }
1321
1465
  }
1466
+ function captureContext(chunk) {
1467
+ chunk.context?.[kPendingContexts] && (chunk.context = {
1468
+ ...chunk.context,
1469
+ [kPendingContexts]: 0
1470
+ });
1471
+ }
1322
1472
  function isInResumedBranch() {
1323
1473
  return $chunk?.context?.[kBranchId] !== void 0;
1324
1474
  }
1325
1475
  function withBranchId(branchId, cb, cbValue) {
1326
1476
  return withContext(kBranchId, branchId, cb, cbValue);
1327
1477
  }
1328
- function withIsAsync(cb, value) {
1329
- return withContext(kIsAsync, !0, cb, value);
1478
+ function withIsAsync(async, cb, value) {
1479
+ return withContext(kIsAsync, async, cb, value);
1330
1480
  }
1331
1481
  function _html(html) {
1332
1482
  $chunk.writeHTML(html);
@@ -1334,8 +1484,8 @@ function _html(html) {
1334
1484
  function writeScript(script) {
1335
1485
  $chunk.writeScript(script);
1336
1486
  }
1337
- function _script(scopeId, registryId, serializeMarker) {
1338
- serializeMarker === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1487
+ function _script(scopeId, registryId, markerGuard) {
1488
+ markerGuard === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync]) && _resume_branch(scopeId), $chunk.boundary.state.needsMainRuntime = !0, $chunk.writeEffect(scopeId, registryId);
1339
1489
  }
1340
1490
  function _trailers(html) {
1341
1491
  $chunk.boundary.state.trailerHTML += html;
@@ -1376,8 +1526,8 @@ function _resume_branch(scopeId) {
1376
1526
  let branchId = $chunk.context?.[kBranchId];
1377
1527
  branchId !== void 0 && branchId !== scopeId && writeScope(scopeId, { G: branchId });
1378
1528
  }
1379
- function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
1380
- let shouldResume = serializeReason !== 0, render = normalizeServerRender(content), branchId = _peek_scope_id();
1529
+ function _attr_content(nodeAccessor, scopeId, content, markerGuard) {
1530
+ let shouldResume = markerGuard !== 0, render = normalizeServerRender(content), branchId = _peek_scope_id();
1381
1531
  render && (shouldResume ? withBranchId(branchId, render) : render()), _peek_scope_id() === branchId ? _scope_id() : shouldResume && writeScope(scopeId, {
1382
1532
  ["A" + nodeAccessor]: writeScope(branchId, {}),
1383
1533
  ["D" + nodeAccessor]: rendererKey(render)
@@ -1396,48 +1546,48 @@ function writeScopePassive(scopeId, partialScope) {
1396
1546
  let target = $chunk.serializeState, scope = _scope_with_id(scopeId), passive = target.passiveScopes ||= {};
1397
1547
  return Object.assign(scope, partialScope), passive[scopeId] = Object.assign(passive[scopeId] || {}, partialScope), scope;
1398
1548
  }
1399
- function _show_start(display, mark) {
1400
- display ? mark && $chunk.writeHTML($chunk.boundary.state.mark("[", "")) : $chunk.writeHTML("<t hidden>");
1549
+ function _show_start(display, markerGuard, branchExprGuard, parentEndTag) {
1550
+ display ? resumesMarker(markerGuard, branchExprGuard, parentEndTag) && $chunk.writeHTML($chunk.boundary.state.mark("[", "")) : $chunk.writeHTML("<t hidden>");
1401
1551
  }
1402
- function _show_end(scopeId, accessor, display, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1552
+ function _show_end(scopeId, accessor, display, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1403
1553
  let branchId = _scope_id(), wrap = !display;
1404
- wrap && $chunk.writeHTML("</t>"), writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1554
+ wrap && $chunk.writeHTML("</t>"), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, wrap || singleNode ? 1 : void 0, " " + branchId);
1405
1555
  }
1406
- function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1556
+ function _for_of(list, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1407
1557
  forBranches(by, (each) => each ? forOf(list, (item, index) => {
1408
1558
  let itemKey = forOfBy(by, item, index);
1409
1559
  each(itemKey, itemKey === index, () => cb(item, index));
1410
- }) : forOf(list, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1560
+ }) : forOf(list, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1411
1561
  }
1412
- function _for_in(obj, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1562
+ function _for_in(obj, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1413
1563
  forBranches(by, (each) => each ? forIn(obj, (key, value) => {
1414
1564
  each(forInBy(by, key, value), !1, () => cb(key, value));
1415
- }) : forIn(obj, cb), scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1565
+ }) : forIn(obj, cb), scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1416
1566
  }
1417
- function _for_to(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1567
+ function _for_to(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1418
1568
  forBranches(by, (each) => {
1419
1569
  let index = 0;
1420
1570
  return each ? forTo(to, from, step, (value) => {
1421
1571
  let itemKey = forStepBy(by, value);
1422
1572
  each(itemKey, itemKey === index++, () => cb(value));
1423
1573
  }) : forTo(to, from, step, cb);
1424
- }, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1574
+ }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1425
1575
  }
1426
- function _for_until(to, from, step, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1576
+ function _for_until(to, from, step, cb, by, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1427
1577
  forBranches(by, (each) => {
1428
1578
  let index = 0;
1429
1579
  return each ? forUntil(to, from, step, (value) => {
1430
1580
  let itemKey = forStepBy(by, value);
1431
1581
  each(itemKey, itemKey === index++, () => cb(value));
1432
1582
  }) : forUntil(to, from, step, cb);
1433
- }, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode);
1583
+ }, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode);
1434
1584
  }
1435
- function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1436
- if (serializeBranch === 0) {
1437
- iterate(0), writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, "");
1585
+ function forBranches(by, iterate, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1586
+ if (branchGuard === 0) {
1587
+ iterate(0), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, "");
1438
1588
  return;
1439
1589
  }
1440
- let { state } = $chunk.boundary, resumeKeys = serializeMarker !== 0, resumeMarker = resumeKeys && (!parentEndTag || serializeStateful !== 0), flushBranchIds = "", loopScopes;
1590
+ let { state } = $chunk.boundary, resumeKeys = markerGuard !== 0, resumeMarker = resumesMarker(markerGuard, branchExprGuard, parentEndTag), flushBranchIds = "", loopScopes;
1441
1591
  iterate((itemKey, sameAsIndex, render) => {
1442
1592
  let branchId = _peek_scope_id();
1443
1593
  resumeMarker && (singleNode ? flushBranchIds = " " + branchId + flushBranchIds : ($chunk.writeHTML(state.mark("[", flushBranchIds)), flushBranchIds = branchId + "")), withBranchId(branchId, () => {
@@ -1445,14 +1595,14 @@ function forBranches(by, iterate, scopeId, accessor, serializeBranch, serializeM
1445
1595
  let branchScope = writeScope(branchId, resumeKeys && !sameAsIndex ? { M: itemKey } : {});
1446
1596
  resumeMarker || (loopScopes = push(loopScopes, branchScope));
1447
1597
  });
1448
- }), loopScopes && writeScope(scopeId, { ["A" + accessor]: loopScopes }), writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1598
+ }), loopScopes && writeScope(scopeId, { ["A" + accessor]: loopScopes }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, singleNode ? flushBranchIds : flushBranchIds ? " " + flushBranchIds : "");
1449
1599
  }
1450
- function _if(cb, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1451
- let resumeBranch = serializeBranch !== 0, resumeMarker = serializeMarker !== 0 && (!parentEndTag || serializeStateful !== 0), 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;
1600
+ function _if(cb, scopeId, accessor, branchGuard, markerGuard, branchExprGuard, parentEndTag, singleNode) {
1601
+ 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;
1452
1602
  beforeBranch !== void 0 && applyBranchStart(chunk, beforeBranch, shouldWriteBranch), shouldWriteBranch && (branchIndex || !resumeMarker) && writeScope(scopeId, {
1453
1603
  ["D" + accessor]: branchIndex || void 0,
1454
1604
  ["A" + accessor]: resumeMarker ? void 0 : writeScope(branchId, {})
1455
- }), writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
1605
+ }), writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, shouldWriteBranch ? " " + branchId : "");
1456
1606
  }
1457
1607
  function deferBranchStart(chunk) {
1458
1608
  let beforeBranch = chunk.html;
@@ -1461,13 +1611,15 @@ function deferBranchStart(chunk) {
1461
1611
  function applyBranchStart(chunk, beforeBranch, rendered) {
1462
1612
  chunk.html = beforeBranch + (rendered ? chunk.boundary.state.mark("[", "") : "") + chunk.html;
1463
1613
  }
1464
- function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
1614
+ function resumesMarker(markerGuard, branchExprGuard, parentEndTag) {
1615
+ return markerGuard !== 0 && (!parentEndTag || branchExprGuard !== 0);
1616
+ }
1617
+ function writeBranchEnd(scopeId, accessor, branchExprGuard, markerGuard, parentEndTag, singleNode, branchIds) {
1465
1618
  let endTag = parentEndTag || "";
1466
- if (serializeMarker !== 0) if (!parentEndTag || serializeStateful !== 0) {
1619
+ if (resumesMarker(markerGuard, branchExprGuard, parentEndTag)) {
1467
1620
  let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
1468
1621
  $chunk.writeHTML(mark + endTag);
1469
- } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1470
- else $chunk.writeHTML(endTag);
1622
+ } else markerGuard === 0 ? $chunk.writeHTML(endTag) : $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1471
1623
  }
1472
1624
  function _existing_scope(scopeId) {
1473
1625
  return writeScope(scopeId, {});
@@ -1479,28 +1631,28 @@ function scopeWithId(state, scopeId) {
1479
1631
  let { scopes } = state, scope = scopes.get(scopeId);
1480
1632
  return scope || scopes.set(scopeId, scope = { [K_SCOPE_ID]: scopeId }), scope;
1481
1633
  }
1482
- function _subscribe(subscribers, scope, resumeId, serializeMarker) {
1634
+ function _subscribe(subscribers, scope, resumeId, markerGuard) {
1483
1635
  if (subscribers) {
1484
1636
  let { serializer } = $chunk.boundary.state;
1485
- !$chunk.serializeState.readyId && !serializer.written(subscribers) ? subscribers.add(scope) : resumeId ? _script(scope[K_SCOPE_ID], resumeId, serializeMarker) : serializer.writeCall(scope, subscribers, "add", $chunk.serializeState);
1637
+ !$chunk.serializeState.readyId && !serializer.written(subscribers) ? subscribers.add(scope) : resumeId ? _script(scope[K_SCOPE_ID], resumeId, markerGuard) : serializer.writeCall(scope, subscribers, "add", $chunk.serializeState);
1486
1638
  }
1487
1639
  return scope;
1488
1640
  }
1489
1641
  function maskGroup(mask, group) {
1490
1642
  return mask === 715827883 ? 1 : typeof mask == "number" ? group < 15 ? mask >>> 1 + 2 * group & 3 : 0 : mask[group] ?? 0;
1491
1643
  }
1492
- function _set_serialize_reason(reason) {
1493
- $chunk.boundary.state.serializeReason = reason;
1644
+ function _set_scope_reason(reason) {
1645
+ $chunk.boundary.state.scopeReason = reason;
1494
1646
  }
1495
1647
  function _scope_reason() {
1496
- let reason = $chunk.boundary.state.serializeReason;
1497
- return $chunk.boundary.state.serializeReason = void 0, reason;
1648
+ let reason = $chunk.boundary.state.scopeReason;
1649
+ return $chunk.boundary.state.scopeReason = void 0, reason;
1498
1650
  }
1499
- function _serialize_if(condition, key) {
1651
+ function _write_if(condition, key) {
1500
1652
  return condition && maskGroup(condition, key) ? 1 : void 0;
1501
1653
  }
1502
- function _serialize_guard(condition, key) {
1503
- return _serialize_if(condition, key) || 0;
1654
+ function _write_guard(condition, key) {
1655
+ return _write_if(condition, key) || 0;
1504
1656
  }
1505
1657
  function writeWaitReady(readyId, renderer, input) {
1506
1658
  let chunk = $chunk, { boundary } = chunk, body = new Chunk(boundary, null, chunk.context, {
@@ -1510,10 +1662,11 @@ function writeWaitReady(readyId, renderer, input) {
1510
1662
  writeScopes: {},
1511
1663
  flushScopes: !1
1512
1664
  }), bodyEnd = body.render(renderer, input);
1665
+ if (boundary.aborted) throw boundary.reason;
1513
1666
  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);
1514
1667
  }
1515
- function _await(scopeId, accessor, promise, content, serializeMarker) {
1516
- let resumeMarker = serializeMarker !== 0;
1668
+ function _await(scopeId, accessor, promise, content, markerGuard) {
1669
+ let resumeMarker = markerGuard !== 0;
1517
1670
  if (!isPromise(promise)) {
1518
1671
  if (resumeMarker) {
1519
1672
  let branchId = _peek_scope_id();
@@ -1521,26 +1674,27 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1521
1674
  } else content(promise);
1522
1675
  return;
1523
1676
  }
1524
- let chunk = $chunk, { boundary } = chunk;
1525
- chunk.next = $chunk = chunk.fork(boundary, chunk.next), chunk.async = !0, chunk.context?.[kPendingContexts] && (chunk.context = {
1526
- ...chunk.context,
1527
- [kPendingContexts]: 0
1528
- }), boundary.startAsync(), promise.then((value) => {
1529
- chunk.async && (chunk.async = !1, boundary.signal.aborted || (chunk.render(() => {
1530
- if (resumeMarker) {
1531
- let branchId = _peek_scope_id();
1532
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync(content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1533
- } else withIsAsync(content, value);
1534
- }), boundary.endAsync()));
1677
+ let chunk = $chunk, { boundary } = chunk, startId = _peek_scope_id(), after = chunk.next = $chunk = chunk.fork(boundary, chunk.next);
1678
+ chunk.async = !0, captureContext(chunk), boundary.startAsync(), promise.then((value) => {
1679
+ if (chunk.async && (chunk.async = !1, !boundary.aborted)) {
1680
+ let { state } = boundary;
1681
+ chunk.render(() => {
1682
+ if (resumeMarker) {
1683
+ let branchId = _peek_scope_id();
1684
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync({ parent: getAsyncContent(chunk) }, content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1685
+ } else {
1686
+ let renderedSince = _peek_scope_id() !== startId, async = { parent: getAsyncContent(chunk) };
1687
+ 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;
1688
+ }
1689
+ }), !chunk.async && boundary.pendingReorders?.delete(chunk) && state.reorder(chunk), boundary.endAsync();
1690
+ }
1535
1691
  }, (err) => {
1536
1692
  chunk.async = !1, boundary.abort(err);
1537
1693
  });
1538
1694
  }
1539
- function _try(scopeId, accessor, content, input) {
1540
- let catchContent = input.catch ? normalizeDynamicRenderer(input.catch) || 0 : void 0, placeholderContent = normalizeDynamicRenderer(input.placeholder), placeholderBranchId = placeholderContent ? _scope_id() : 0, branchId = _peek_scope_id(), chunk = $chunk, { boundary } = chunk, { state } = boundary, { resumeWrites } = boundary, beforeBranch = deferBranchStart(chunk), renderersAtSettle = !1;
1541
- catchContent !== void 0 || placeholderContent ? renderersAtSettle = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, placeholderContent, branchId) : withBranchId(branchId, content);
1542
- let rendered = chunk !== $chunk || boundary.resumeWrites !== resumeWrites;
1543
- applyBranchStart(chunk, beforeBranch, rendered), rendered && (renderersAtSettle || writeTryRenderers(branchId, catchContent, placeholderContent), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
1695
+ function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
1696
+ 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;
1697
+ applyBranchStart(chunk, beforeBranch, rendered), rendered && (renderersWritten || renderers(), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
1544
1698
  }
1545
1699
  function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1546
1700
  let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
@@ -1548,7 +1702,7 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1548
1702
  chunk.append(body);
1549
1703
  return;
1550
1704
  }
1551
- chunk.next = $chunk = chunk.fork(boundary, chunk.next), chunk.placeholder = {
1705
+ chunk.next = $chunk = chunk.fork(boundary, chunk.next), captureContext(chunk), chunk.placeholder = {
1552
1706
  body,
1553
1707
  render: placeholder,
1554
1708
  branchId,
@@ -1556,29 +1710,41 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1556
1710
  placeholderBranchId
1557
1711
  };
1558
1712
  }
1559
- function tryBoundary(content, catchContent, placeholderContent, branchId) {
1560
- let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, boundary.signal, boundary), body = chunk.fork(catchBoundary, null), bodyEnd = withBranchId(branchId, () => body.render(content));
1561
- if (catchBoundary.signal.aborted) return catchContent === void 0 ? boundary.abort(catchBoundary.signal.reason) : catchContent && catchContent(catchBoundary.signal.reason), !1;
1713
+ function tryBoundary(content, catchContent, branchId, renderers) {
1714
+ let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, void 0, boundary), body = chunk.fork(catchBoundary, null), bodyEnd = body.render(() => withBranchId(branchId, content));
1715
+ if (catchBoundary.aborted) {
1716
+ if (!catchContent) throw catchBoundary.reason;
1717
+ return catchContent(catchBoundary.reason), !0;
1718
+ }
1562
1719
  if (body === bodyEnd) return chunk.append(body), !1;
1563
1720
  let renderersAtSettle = !catchBoundary.resumeWrites, bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1564
1721
  chunk.next = body, boundary.startAsync();
1565
- let reorderId = catchContent === void 0 ? "" : state.nextReorderId(), endMarker = reorderId && state.mark("!", reorderId);
1566
- return reorderId && (chunk.writeHTML(state.mark("!^", reorderId)), bodyEnd.writeHTML(endMarker)), catchBoundary.onNext = () => {
1567
- if (!boundary.signal.aborted) if (catchBoundary.signal.aborted) {
1568
- if (!reorderId) {
1569
- boundary.abort(catchBoundary.signal.reason);
1570
- return;
1571
- }
1572
- if (!bodyEnd.consumed) {
1573
- let cur = body, writeMarker = !0;
1574
- do {
1575
- let next = cur.next;
1576
- cur.boundary !== catchBoundary && cur.boundary.abort(catchBoundary.signal.reason), writeMarker && !cur.consumed && (writeMarker = !1, cur.async = !1, cur.next = bodyNext, cur.needsWalk = !0, cur.html = endMarker, cur.scripts = cur.effects = cur.lastEffect = "", cur.placeholder = cur.reorderId = cur.deferredReady = null), cur = next;
1577
- } while (cur !== bodyNext);
1578
- }
1579
- let catchChunk = chunk.fork(boundary, null), { resumeWrites } = boundary;
1580
- catchChunk.reorderId = reorderId, (catchChunk.render(catchContent || NOOP$2, catchBoundary.signal.reason) !== catchChunk || boundary.resumeWrites !== resumeWrites) && renderersAtSettle && catchChunk.render(() => writeTryRenderers(branchId, catchContent, placeholderContent)), state.reorder(catchChunk), boundary.endAsync();
1581
- } else catchBoundary.count ? boundary.onNext() : (renderersAtSettle && catchBoundary.resumeWrites && bodyEnd.render(() => writeTryRenderers(branchId, catchContent, placeholderContent)), boundary.endAsync());
1722
+ let reorderId = catchContent ? state.nextReorderId() : "";
1723
+ return reorderId && (chunk.catchRange = {
1724
+ id: reorderId,
1725
+ end: bodyEnd
1726
+ }, captureContext(chunk)), catchBoundary.onNext = () => {
1727
+ if (!boundary.aborted) {
1728
+ if (catchBoundary.aborted) {
1729
+ if (!reorderId) {
1730
+ boundary.abort(catchBoundary.reason);
1731
+ return;
1732
+ }
1733
+ let streamed = !chunk.catchRange, catchChunk = chunk.fork(boundary, null);
1734
+ chunk.catchRange = null;
1735
+ let inOrder = catchChunk === catchChunk.render(catchContent, catchBoundary.reason);
1736
+ if (boundary.aborted) return;
1737
+ if (bodyEnd.consumed) catchChunk.reorderId = reorderId, state.reorder(catchChunk);
1738
+ else {
1739
+ let reorder = null;
1740
+ inOrder ? streamed && (reorder = chunk.fork(boundary, null)) : reorder = catchChunk, reorder && (reorder.reorderId = reorderId);
1741
+ let endMarker = state.mark("!", reorderId), cut = body;
1742
+ for (; cut.consumed;) cut = cut.next;
1743
+ 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);
1744
+ }
1745
+ boundary.endAsync();
1746
+ } else catchBoundary.count ? boundary.onNext() : (renderersAtSettle && catchBoundary.resumeWrites && bodyEnd.render(renderers), chunk.catchRange = null, boundary.endAsync());
1747
+ }
1582
1748
  }, renderersAtSettle;
1583
1749
  }
1584
1750
  function writeTryRenderers(branchId, catchContent, placeholderContent) {
@@ -1587,8 +1753,12 @@ function writeTryRenderers(branchId, catchContent, placeholderContent) {
1587
1753
  Q: placeholderContent
1588
1754
  });
1589
1755
  }
1590
- function countResumeWrite(boundary) {
1591
- for (; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1756
+ function countResumeWrite(chunk) {
1757
+ for (let boundary = chunk.boundary; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1758
+ for (let async = getAsyncContent(chunk); async && !async.resumed; async = async.parent) async.resumed = !0, async.end?.writeHTML(async.visit);
1759
+ }
1760
+ function getAsyncContent(chunk) {
1761
+ return chunk.context?.[kIsAsync];
1592
1762
  }
1593
1763
  var State = class {
1594
1764
  tagId = 1;
@@ -1612,7 +1782,7 @@ var State = class {
1612
1782
  flushScopes = !1;
1613
1783
  writeScopes = {};
1614
1784
  readyIds = null;
1615
- serializeReason;
1785
+ scopeReason;
1616
1786
  $global;
1617
1787
  constructor($global) {
1618
1788
  this.$global = $global, $global.cspNonce && (this.nonceAttr = " nonce" + attrAssignment($global.cspNonce));
@@ -1653,27 +1823,40 @@ var State = class {
1653
1823
  mark(code, str) {
1654
1824
  return "<!--" + this.commentPrefix + code + str + "-->";
1655
1825
  }
1656
- }, Boundary = class extends AbortController {
1826
+ }, Boundary = class {
1657
1827
  onNext = NOOP$2;
1658
1828
  count = 0;
1659
1829
  resumeWrites = 0;
1660
1830
  state;
1661
1831
  parent;
1832
+ aborted = !1;
1833
+ reason;
1834
+ pendingReorders;
1835
+ children;
1662
1836
  constructor(state, signal, parent) {
1663
- super(), this.state = state, this.parent = parent, this.signal.addEventListener("abort", () => {
1664
- this.count = 0, this.state = new State(this.state.$global), this.onNext();
1665
- }), signal && (signal.aborted ? this.abort(signal.reason) : signal.addEventListener("abort", () => {
1666
- this.abort(signal.reason);
1667
- }));
1837
+ this.state = state, this.parent = parent, parent ? parent.aborted ? this.abort(parent.reason) : (parent.children ||= []).push(this) : signal && (signal.aborted ? this.abort(signal.reason) : signal.addEventListener("abort", this));
1838
+ }
1839
+ abort(reason) {
1840
+ if (this.aborted) return;
1841
+ let { state } = this;
1842
+ if (this.aborted = !0, this.reason = reason, this.pendingReorders) {
1843
+ for (let reorder of this.pendingReorders) state.reorder(reorder);
1844
+ this.pendingReorders = void 0;
1845
+ }
1846
+ if (this.count = 0, this.state = new State(state.$global), this.children) for (let child of this.children) child.abort(reason);
1847
+ this.onNext();
1848
+ }
1849
+ handleEvent(event) {
1850
+ this.abort(event.target.reason);
1668
1851
  }
1669
1852
  flush() {
1670
- return this.signal.aborted || flushSerializer(this, this.state), this.count ? 1 : this.signal.aborted ? 2 : 0;
1853
+ return this.aborted || flushSerializer(this, this.state), this.count ? 1 : this.aborted ? 2 : 0;
1671
1854
  }
1672
1855
  startAsync() {
1673
- this.signal.aborted || this.count++;
1856
+ this.aborted || this.count++;
1674
1857
  }
1675
1858
  endAsync() {
1676
- !this.signal.aborted && this.count && (this.count--, this.onNext());
1859
+ this.aborted || (this.count--, this.onNext());
1677
1860
  }
1678
1861
  }, Chunk = class Chunk {
1679
1862
  html = "";
@@ -1682,9 +1865,10 @@ var State = class {
1682
1865
  lastEffect = "";
1683
1866
  async = !1;
1684
1867
  consumed = !1;
1685
- needsWalk = !1;
1686
1868
  reorderId = null;
1687
1869
  deferredReady = null;
1870
+ deferredReorder = null;
1871
+ catchRange = null;
1688
1872
  placeholder = null;
1689
1873
  boundary;
1690
1874
  next;
@@ -1700,13 +1884,13 @@ var State = class {
1700
1884
  this.html += html;
1701
1885
  }
1702
1886
  writeEffect(scopeId, registryId) {
1703
- countResumeWrite(this.boundary), this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1887
+ countResumeWrite(this), this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1704
1888
  }
1705
1889
  writeScript(script) {
1706
1890
  this.scripts = concatScripts(this.scripts, script);
1707
1891
  }
1708
1892
  append(chunk) {
1709
- this.html += chunk.html, this.needsWalk ||= chunk.needsWalk, this.effects = concatEffects(this.effects, chunk.effects), this.scripts = concatScripts(this.scripts, chunk.scripts), this.lastEffect = chunk.lastEffect || this.lastEffect, this.deferredReady = concat(this.deferredReady, chunk.takeDeferredReady());
1893
+ this.html += chunk.html, this.effects = concatEffects(this.effects, chunk.effects), this.scripts = concatScripts(this.scripts, chunk.scripts), this.lastEffect = chunk.lastEffect || this.lastEffect, this.deferredReady = concat(this.deferredReady, chunk.takeDeferredReady());
1710
1894
  }
1711
1895
  takeDeferredReady() {
1712
1896
  let { deferredReady } = this;
@@ -1718,23 +1902,59 @@ var State = class {
1718
1902
  deferred.effects = this.effects, deferred.scripts = this.scripts, this.effects = this.scripts = this.lastEffect = "", this.deferredReady = concat(deferred, this.deferredReady);
1719
1903
  }
1720
1904
  }
1721
- flushPlaceholder() {
1905
+ renderPlaceholders(boundary) {
1906
+ let { state } = boundary;
1907
+ restart: for (;;) {
1908
+ let reorders = null;
1909
+ for (let cur = this; cur.next && !cur.async; cur = cur.next) {
1910
+ if (cur.renderPlaceholder(state)) {
1911
+ if (boundary.aborted) return;
1912
+ continue restart;
1913
+ }
1914
+ cur.deferredReorder && (reorders ||= []).push(cur.deferredReorder);
1915
+ }
1916
+ if (state.writeReorders) {
1917
+ for (let reorder of state.writeReorders) if ((reorders = renderReorderPlaceholders(reorder, reorders)) === !1) {
1918
+ if (boundary.aborted) return;
1919
+ continue restart;
1920
+ }
1921
+ }
1922
+ for (let i = 0; reorders && i < reorders.length; i++) if ((reorders = renderReorderPlaceholders(reorders[i], reorders)) === !1) {
1923
+ if (boundary.aborted) return;
1924
+ continue restart;
1925
+ }
1926
+ return;
1927
+ }
1928
+ }
1929
+ renderPlaceholder(state) {
1722
1930
  let { placeholder } = this;
1723
- if (placeholder) {
1724
- let body = placeholder.body.consume();
1725
- if (body.async) {
1726
- let { state } = this.boundary, { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
1727
- this.writeHTML(state.mark("!^", reorderId));
1728
- let { effects } = this, beforeBranch = deferBranchStart(this), after = this.render(() => withBranchId(placeholderBranchId, placeholder.render)), stateful = after === this && this.effects !== effects;
1729
- applyBranchStart(this, beforeBranch, stateful), after === this ? stateful && (this.render(() => writeScope(branchId, { P: scopeWithId(state, placeholderBranchId) })), this.writeHTML(state.mark("]", scopeId + " " + ("P" + branchId) + " " + placeholderBranchId)), body.writeEffect(branchId, "_f")) : this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.writeHTML(state.mark("!", reorderId)), state.reorder(body);
1730
- } else body.next = this.next, this.next = body;
1731
- this.placeholder = null;
1931
+ if (!placeholder || (this.placeholder = null, this.boundary.aborted)) return !1;
1932
+ let { body } = placeholder, end = body;
1933
+ for (; end.next && !end.async;) end = end.next;
1934
+ if (!end.async) return end.next = this.next, this.next = body, !1;
1935
+ let { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
1936
+ this.writeHTML(state.mark("!^", reorderId));
1937
+ let { effects } = this, beforeBranch = deferBranchStart(this);
1938
+ if (this.render(() => withBranchId(placeholderBranchId, placeholder.render)) !== this && this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.boundary.aborted) return !0;
1939
+ let stateful = this.effects !== effects;
1940
+ return applyBranchStart(this, beforeBranch, stateful), stateful && (this.render(() => writeScope(branchId, { P: scopeWithId(state, placeholderBranchId) })), this.writeHTML(state.mark("]", scopeId + " " + ("P" + branchId) + " " + placeholderBranchId)), end.writeEffect(branchId, "_f")), this.writeHTML(state.mark("!", reorderId)), this.deferredReorder = body, !1;
1941
+ }
1942
+ markCatchRange() {
1943
+ let { catchRange } = this;
1944
+ if (catchRange) {
1945
+ let { state } = this.boundary;
1946
+ this.catchRange = null, this.writeHTML(state.mark("!^", catchRange.id)), catchRange.end.writeHTML(state.mark("!", catchRange.id));
1732
1947
  }
1733
1948
  }
1734
- consume() {
1735
- let cur = this, html = "", effects = "", scripts = "", lastEffect = "", needsWalk = !1, deferredReady;
1736
- for (; cur.next && !cur.async;) cur.flushPlaceholder(), needsWalk ||= cur.needsWalk, html += cur.html, cur.serializeState.readyId ? deferredReady = push(deferredReady, cur) : (effects = concatEffects(effects, cur.effects), scripts = concatScripts(scripts, cur.scripts), lastEffect = cur.lastEffect || lastEffect), deferredReady = concat(deferredReady, cur.takeDeferredReady()), cur.consumed = !0, cur = cur.next;
1737
- return cur.deferOwnReady(), cur.deferredReady = concat(deferredReady, cur.deferredReady), cur.needsWalk ||= needsWalk, cur.html = html + cur.html, cur.effects = concatEffects(effects, cur.effects), cur.scripts = concatScripts(scripts, cur.scripts), cur.lastEffect ||= lastEffect, cur;
1949
+ queueDeferredReorder() {
1950
+ let { deferredReorder } = this;
1951
+ deferredReorder && (this.deferredReorder = null, deferredReorder.boundary.state.reorder(deferredReorder));
1952
+ }
1953
+ consume(boundary) {
1954
+ this.renderPlaceholders(boundary);
1955
+ let cur = this, html = "", effects = "", scripts = "", lastEffect = "", deferredReady;
1956
+ for (; cur.next && !cur.async;) cur.markCatchRange(), cur.queueDeferredReorder(), html += cur.html, cur.serializeState.readyId ? deferredReady = push(deferredReady, cur) : (effects = concatEffects(effects, cur.effects), scripts = concatScripts(scripts, cur.scripts), lastEffect = cur.lastEffect || lastEffect), deferredReady = concat(deferredReady, cur.takeDeferredReady()), cur.consumed = !0, cur = cur.next;
1957
+ return cur.deferOwnReady(), cur.deferredReady = concat(deferredReady, cur.deferredReady), cur.html = html + cur.html, cur.effects = concatEffects(effects, cur.effects), cur.scripts = concatScripts(scripts, cur.scripts), cur.lastEffect ||= lastEffect, cur;
1738
1958
  }
1739
1959
  render(content, val) {
1740
1960
  let prev = $chunk;
@@ -1747,11 +1967,10 @@ var State = class {
1747
1967
  $chunk = prev;
1748
1968
  }
1749
1969
  }
1750
- flushReadyScripts(reservations, holdEffects) {
1751
- let { boundary, serializeState } = this, { readyId } = serializeState, scripts = "";
1752
- if (forEach(this.takeDeferredReady(), (chunk) => {
1753
- scripts = concatScripts(scripts, chunk.flushReadyScripts(reservations, holdEffects)), (chunk.effects || chunk.deferredReady) && (this.deferredReady = push(this.deferredReady, chunk));
1754
- }), readyId && !this.async) {
1970
+ flushReadyScripts(boundary, reservations, holdEffects) {
1971
+ let { serializeState } = this, { readyId } = serializeState, scripts = "", held = this.takeDeferredReady();
1972
+ 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)));
1973
+ if (readyId && !this.async) {
1755
1974
  let { state } = boundary;
1756
1975
  flushSerializer(boundary, serializeState);
1757
1976
  let deps = state.serializer.takeChannelDeps(), effects = holdEffects ? "" : this.effects, { resumes } = serializeState, chunkScripts = this.scripts;
@@ -1767,11 +1986,11 @@ var State = class {
1767
1986
  }
1768
1987
  return scripts;
1769
1988
  }
1770
- flushScript() {
1771
- let { boundary } = this, { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1989
+ flushScript(boundary) {
1990
+ let { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1772
1991
  needsWalk && (state.walkOnNextFlush = !1);
1773
- let readyResumeScripts = this.flushReadyScripts(void 0, this.async);
1774
- for (let channel; channel = state.serializer.pendingReadyChannel();) {
1992
+ let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
1993
+ for (let channel; !boundary.aborted && (channel = state.serializer.pendingReadyChannel());) {
1775
1994
  let resumes = state.serializer.stringifyScopes([], boundary, channel), deps = state.serializer.takeChannelDeps();
1776
1995
  state.needsMainRuntime = !0, readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
1777
1996
  }
@@ -1780,40 +1999,36 @@ var State = class {
1780
1999
  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 + "\"");
1781
2000
  let reordered = "", needsResumeArray = !1;
1782
2001
  if (state.writeReorders) {
1783
- let carried = null;
1784
2002
  for (let reorderedChunk of state.writeReorders) {
1785
- if (reorderedChunk.async && reorderedChunk.consumed) {
1786
- let aborted = reorderedChunk.boundary;
1787
- for (; aborted && !aborted.signal.aborted;) aborted = aborted.parent;
1788
- if (!aborted) {
1789
- (carried ||= []).push(reorderedChunk);
1790
- continue;
1791
- }
1792
- reorderedChunk.async = !1;
1793
- }
1794
- 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++:\"!\"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):\"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:e.l[a]?1:2,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 + ")"));
1795
- let { reorderId } = reorderedChunk, readyReservations = [], reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk;
1796
- for (reorderedChunk.reorderId = null;;) {
1797
- cur.flushPlaceholder(), cur.deferOwnReady();
1798
- let { next } = cur, readyResumeScripts = cur.flushReadyScripts(readyReservations, this.async);
1799
- if (this.deferredReady = concat(this.deferredReady, cur.takeDeferredReady()), cur.consumed = !0, reorderHTML += cur.html, reorderEffects = concatEffects(reorderEffects, cur.effects), reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts)), cur.async && (reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId()), state.reorder(cur), cur.html = cur.effects = cur.scripts = cur.lastEffect = "", cur.next = null), next) cur = next;
1800
- else break;
2003
+ 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 + ")"));
2004
+ let { reorderId } = reorderedChunk, readyReservations = [], reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk.boundary.aborted ? null : reorderedChunk;
2005
+ for (reorderedChunk.reorderId = null; cur;) {
2006
+ cur.markCatchRange(), cur.queueDeferredReorder(), cur.deferOwnReady();
2007
+ let { next } = cur, readyResumeScripts = cur.flushReadyScripts(boundary, readyReservations, this.async);
2008
+ this.deferredReady = concat(this.deferredReady, cur.takeDeferredReady()), cur.consumed = !0, reorderHTML += cur.html, reorderEffects = concatEffects(reorderEffects, cur.effects), reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts)), cur.async && (reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId()), (cur.boundary.pendingReorders ||= /* @__PURE__ */ new Set()).add(cur), cur.html = cur.effects = cur.scripts = cur.lastEffect = "", cur.next = null), cur = next;
1801
2009
  }
1802
2010
  reorderEffects && (this.async ? (this.effects = concatEffects(this.effects, reorderEffects), this.lastEffect = "") : (needsResumeArray = !0, reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")")));
1803
2011
  for (let reservation of readyReservations) reordered = concatScripts(reordered, reservation);
1804
2012
  reordered = concatScripts(reordered, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}"), html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
1805
2013
  }
1806
- state.writeReorders = carried;
2014
+ state.writeReorders = null;
1807
2015
  }
1808
2016
  return flushSerializer(boundary, state), (state.resumes || needsResumeArray && !state.hasWrittenResume) && (scripts = concatScripts(scripts, state.resumeScript(state.resumes))), scripts = concatScripts(scripts, reordered), needsWalk && (scripts = concatScripts(scripts, state.walkScript())), this.html = html, this.scripts = scripts, this.async || (this.effects = this.lastEffect = ""), state.resumes = "", this;
1809
2017
  }
1810
- flushHTML() {
1811
- let { boundary } = this, { state } = boundary;
1812
- this.needsWalk && (this.needsWalk = !1, state.walkOnNextFlush = !0), this.flushScript();
2018
+ flushHTML(boundary) {
2019
+ let { state } = boundary;
2020
+ this.flushScript(boundary);
1813
2021
  let { html, scripts } = this;
1814
2022
  return this.html = this.scripts = "", state.flushChunk(html, scripts, boundary.count);
1815
2023
  }
1816
2024
  };
2025
+ function renderReorderPlaceholders(reorder, reorders) {
2026
+ if (!reorder.boundary.aborted) for (let cur = reorder; cur; cur = cur.next) {
2027
+ if (cur.renderPlaceholder(reorder.boundary.state)) return !1;
2028
+ cur.deferredReorder && (reorders ||= []).push(cur.deferredReorder);
2029
+ }
2030
+ return reorders;
2031
+ }
1817
2032
  function flushSerializer(boundary, serializeState) {
1818
2033
  let { state } = boundary, { serializer } = state, pending = serializer.pending(serializeState);
1819
2034
  if (serializeState.flushScopes || pending) {
@@ -1900,159 +2115,30 @@ function flushTickQueue() {
1900
2115
  }
1901
2116
  }
1902
2117
  //#endregion
1903
- //#region src/html/attrs.ts
1904
- function _attr_class(value) {
1905
- return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
1906
- }
1907
- function _attr_style(value) {
1908
- return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
1909
- }
1910
- function _attr_option_value(value) {
1911
- let valueAttr = _attr("value", value), selectedValue = getContext(kSelectedValue);
1912
- return selectedValue !== void 0 && normalizedValueMatches(selectedValue, value) ? valueAttr + " selected" : valueAttr;
1913
- }
1914
- function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content, serializeType) {
1915
- valueChange && writeControlledScope(3, scopeId, nodeAccessor, void 0, valueChange, serializeType), content && withContext(kSelectedValue, value ?? "", content);
1916
- }
1917
- function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1918
- return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _textarea_value(value);
1919
- }
1920
- function _textarea_value(value) {
1921
- let escaped = _escape(normalizeStrAttrValue(value));
1922
- return escaped[0] === "\n" ? "\n" + escaped : escaped;
1923
- }
1924
- function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1925
- return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _attr("value", value);
1926
- }
1927
- function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
1928
- return checkedChange && writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType), isNotVoid(checked) ? " checked" : "";
1929
- }
1930
- function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
1931
- let valueAttr = _attr("value", value);
1932
- return checkedValueChange && writeControlledScope(1, scopeId, nodeAccessor, getCheckedValueRef(checkedValue), checkedValueChange, serializeType), normalizedValueMatches(checkedValue, value) ? valueAttr + " checked" : valueAttr;
1933
- }
1934
- function getCheckedValueRef(checkedValue) {
1935
- if (Array.isArray(checkedValue)) {
1936
- let ref = checkedValuesRefs.get(checkedValue);
1937
- return ref || (ref = [], checkedValuesRefs.set(checkedValue, ref)), ref;
1938
- }
1939
- }
1940
- function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
1941
- let normalizedOpen = isNotVoid(open);
1942
- return openChange && writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType), normalizedOpen ? " open" : "";
1943
- }
1944
- function _attr_nonce() {
1945
- return getChunk().boundary.state.nonceAttr;
1946
- }
1947
- function _style_html(decls) {
1948
- let id = _id();
1949
- return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
1950
- }
1951
- function _attr(name, value) {
1952
- return isVoid(value) ? "" : nonVoidAttr(name, value);
1953
- }
1954
- function _attr_and(name, value, attr) {
1955
- return value ? attr : _attr(name, value);
1956
- }
1957
- function _attr_or(name, value, attr) {
1958
- return value ? _attr(name, value) : attr;
1959
- }
1960
- function _attr_nullish(name, value, attr) {
1961
- return value == null ? attr : _attr(name, value);
1962
- }
1963
- function _attrs(data, nodeAccessor, scopeId, tagName) {
1964
- let result = "", skip = /[\s/>"'=]/, events;
1965
- switch (data && tagName) {
1966
- case "input":
1967
- data.checkedChange ? (result += _attr_input_checked(scopeId, nodeAccessor, data.checked, data.checkedChange, 1), skip = /^checked(?:Value)?(?:Change)?$|[\s/>"'=]/) : "checkedValue" in data || data.checkedValueChange ? (result += _attr_input_checkedValue(scopeId, nodeAccessor, data.checkedValue, data.checkedValueChange, data.value, 1), skip = /^(?:value|checked(?:Value)?)(?:Change)?$|[\s/>"'=]/) : data.valueChange && (result += _attr_input_value(scopeId, nodeAccessor, data.value, data.valueChange, 1), skip = /^value(?:Change)?$|[\s/>"'=]/);
1968
- break;
1969
- case "select":
1970
- case "textarea":
1971
- ("value" in data || data.valueChange) && (skip = /^value(?:Change)?$|[\s/>"'=]/);
1972
- break;
1973
- case "option":
1974
- "value" in data && (result += _attr_option_value(data.value), skip = /^value$|[\s/>"'=]/);
1975
- break;
1976
- case "details":
1977
- case "dialog":
1978
- data.openChange && (result += _attr_details_or_dialog_open(scopeId, nodeAccessor, data.open, data.openChange, 1), skip = /^open(?:Change)?$|[\s/>"'=]/);
1979
- break;
1980
- }
1981
- for (let name in data) {
1982
- let value = data[name];
1983
- switch (name) {
1984
- case "class":
1985
- result += _attr_class(value);
1986
- break;
1987
- case "style":
1988
- result += _attr_style(value);
1989
- break;
1990
- default:
1991
- 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));
1992
- break;
1993
- }
1994
- }
1995
- return result;
1996
- }
1997
- function _attrs_content(data, nodeAccessor, scopeId, tagName, serializeReason) {
1998
- _html(`${_attrs(data, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
1999
- }
2000
- function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
2001
- let partial = {};
2002
- for (let name in data) {
2003
- let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
2004
- skip[key] || (partial[key] = data[name]);
2005
- }
2006
- return _attrs(partial, nodeAccessor, scopeId, tagName);
2007
- }
2008
- function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, serializeReason) {
2009
- _html(`${_attrs_partial(data, skip, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
2010
- }
2011
- function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, serializeType) {
2012
- writeScope(scopeId, serializeType ? {
2013
- ["F" + nodeAccessor]: type,
2014
- ["G" + nodeAccessor]: value,
2015
- ["E" + nodeAccessor]: valueChange
2016
- } : {
2017
- ["G" + nodeAccessor]: value,
2018
- ["E" + nodeAccessor]: valueChange
2019
- });
2020
- }
2021
- function stringAttr(name, value) {
2022
- return value && " " + name + attrAssignment(value);
2023
- }
2024
- function nonVoidAttr(name, value) {
2025
- switch (typeof value) {
2026
- case "string": return " " + name + attrAssignment(value);
2027
- case "boolean": return " " + name;
2028
- case "number": return " " + name + "=" + value;
2029
- }
2030
- return " " + name + attrAssignment(value + "");
2118
+ //#region src/html/content.ts
2119
+ function _to_text(val) {
2120
+ return val || val === 0 ? val + "" : "";
2031
2121
  }
2032
- function attrAssignment(value) {
2033
- return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
2122
+ function _unescaped(val) {
2123
+ return val ? val + "" : val === 0 ? "0" : "";
2034
2124
  }
2035
- function escapeSingleQuotedAttrValue(value) {
2036
- return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
2125
+ function _escape(val) {
2126
+ return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
2037
2127
  }
2038
- function replaceUnsafeSingleQuoteAttrChar(match) {
2039
- return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
2128
+ function _escape_script(val) {
2129
+ return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
2040
2130
  }
2041
- function escapeDoubleQuotedAttrValue(value) {
2042
- return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
2131
+ function _escape_style(val) {
2132
+ return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
2043
2133
  }
2044
- function replaceUnsafeDoubleQuoteAttrChar(match) {
2045
- return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
2134
+ function _escape_style_value(val) {
2135
+ return val || val === 0 ? escapeStyleValue(val + "") : "";
2046
2136
  }
2047
- function normalizedValueMatches(a, b) {
2048
- let value = normalizeStrAttrValue(b);
2049
- if (Array.isArray(a)) {
2050
- for (let item of a) if (normalizeStrAttrValue(item) === value) return !0;
2051
- } else if (normalizeStrAttrValue(a) === value) return !0;
2052
- return !1;
2137
+ function escapeCommentStr(str) {
2138
+ return unsafeCommentReg.test(str) && (str = str.replace(unsafeCommentReg, "&gt;")), str.startsWith(getState().commentPrefix) ? "&#" + str.charCodeAt(0) + ";" + str.slice(1) : str;
2053
2139
  }
2054
- function normalizeStrAttrValue(value) {
2055
- return isNotVoid(value) && value !== !0 ? value + "" : "";
2140
+ function _escape_comment(val) {
2141
+ return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
2056
2142
  }
2057
2143
  //#endregion
2058
2144
  //#region src/html/dynamic-tag.ts
@@ -2126,11 +2212,11 @@ var ServerRendered = class {
2126
2212
  done: !1
2127
2213
  };
2128
2214
  return value = "", Promise.resolve(result);
2129
- } else if (done) return Promise.resolve({
2215
+ }
2216
+ return done ? Promise.resolve({
2130
2217
  value: "",
2131
2218
  done
2132
- });
2133
- else return new Promise(exec);
2219
+ }) : new Promise(exec);
2134
2220
  },
2135
2221
  throw(error) {
2136
2222
  return done || aborted || boundary?.abort(error), Promise.resolve({
@@ -2189,49 +2275,64 @@ var ServerRendered = class {
2189
2275
  return this.#cachedPromise ||= new Promise((resolve, reject) => {
2190
2276
  let head = this.#head;
2191
2277
  if (this.#head = null, !head) return reject(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2192
- let { boundary } = head;
2278
+ let { boundary } = head, html = "";
2193
2279
  (boundary.onNext = () => {
2194
2280
  switch (!boundary.count && boundary.flush()) {
2195
2281
  case 2:
2196
- boundary.onNext = NOOP$1, reject(boundary.signal.reason);
2197
- break;
2198
- case 0: {
2199
- let consumed = head.consume();
2200
- boundary.signal.aborted || resolve(consumed.flushHTML());
2282
+ settle(boundary), reject(boundary.reason);
2201
2283
  break;
2202
- }
2284
+ case 0:
2285
+ if (head = head.consume(boundary), boundary.aborted) break;
2286
+ html += head.flushHTML(boundary), boundary.count || boundary.aborted || (settle(boundary), resolve(html));
2203
2287
  }
2204
2288
  })();
2205
2289
  });
2206
2290
  }
2207
2291
  #read(onWrite, onAbort, onClose) {
2208
- let tick = !0, head = this.#head;
2292
+ let tick = !0, flushing = !1, again = !1, head = this.#head;
2209
2293
  if (this.#head = null, !head) {
2210
2294
  onAbort(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2211
2295
  return;
2212
2296
  }
2213
2297
  let { boundary } = head, onNext = boundary.onNext = (write) => {
2214
- let status = boundary.flush();
2215
- if (status === 2) tick || offTick(onNext), boundary.onNext = NOOP$1, onAbort(boundary.signal.reason);
2216
- else if (write || status === 0) {
2217
- if (head = head.consume(), boundary.signal.aborted) return;
2218
- let html = head.flushHTML();
2219
- html && onWrite(html), status === 0 ? (tick || offTick(onNext), onClose()) : tick = !0;
2220
- } else tick && (tick = !1, queueTick(onNext));
2298
+ if (flushing) {
2299
+ again = !0;
2300
+ return;
2301
+ }
2302
+ flushing = !0;
2303
+ do {
2304
+ again = !1;
2305
+ let status = boundary.flush();
2306
+ if (status === 2) {
2307
+ tick || offTick(onNext), settle(boundary), onAbort(boundary.reason);
2308
+ return;
2309
+ }
2310
+ if (write || status === 0) {
2311
+ if (head = head.consume(boundary), boundary.aborted) continue;
2312
+ let html = head.flushHTML(boundary);
2313
+ if (boundary.aborted) continue;
2314
+ if (html && onWrite(html), !boundary.count) {
2315
+ tick || offTick(onNext), settle(boundary), onClose();
2316
+ return;
2317
+ }
2318
+ write && (tick = !0);
2319
+ } else tick && (tick = !1, queueTick(onNext));
2320
+ } while (again);
2321
+ flushing = !1;
2221
2322
  };
2222
2323
  return onNext(), boundary;
2223
2324
  }
2224
2325
  toString() {
2225
2326
  let head = this.#head;
2226
2327
  if (this.#head = null, !head) throw Error(CONSUMED_RESULT_MESSAGE);
2227
- let { boundary } = head;
2228
- switch (boundary.flush()) {
2229
- case 2: throw boundary.signal.reason;
2230
- case 1: throw Error("Cannot consume asynchronous render with 'toString'");
2231
- }
2232
- return head.consume().flushHTML();
2328
+ let { boundary } = head, html = boundary.flush() === 0 ? head.consume(boundary).flushHTML(boundary) : "";
2329
+ if (boundary.count && boundary.abort(/* @__PURE__ */ Error("Cannot consume asynchronous render with 'toString'")), settle(boundary), boundary.aborted) throw boundary.reason;
2330
+ return html;
2233
2331
  }
2234
2332
  };
2333
+ function settle(boundary) {
2334
+ boundary.onNext = NOOP$1, boundary.state.$global.signal?.removeEventListener("abort", boundary);
2335
+ }
2235
2336
  function NOOP$1() {}
2236
2337
  //#endregion
2237
2338
  //#region src/html/assets.ts
@@ -2244,7 +2345,7 @@ function withLoadAssets(renderer, assetId, triggers) {
2244
2345
  function withPageAssets(template, runtime, assetId, runtimeId) {
2245
2346
  return assetFlush = runtime, Object.assign((input) => {
2246
2347
  let g = $global();
2247
- return runtimeId && (g.runtimeId = runtimeId), addAsset(g, assetId), g.__flush__ ? (_html(flush(g, "")), writeWaitReady(assetId, template, input)) : (g.__flush__ = flush, template(input));
2348
+ return runtimeId && (g[kAssets] || (g.runtimeId = runtimeId)), addAsset(g, assetId), g.__flush__ ? (_html(flush(g, "")), writeWaitReady(assetId, template, input)) : (g.__flush__ = flush, template(input));
2248
2349
  }, template);
2249
2350
  }
2250
2351
  function _flush_head() {
@@ -2301,4 +2402,4 @@ function drainClassFunctions($global, writeScope) {
2301
2402
  }
2302
2403
  function NOOP() {}
2303
2404
  //#endregion
2304
- export { $global, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _escape_style_value, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _html_resume, _id, _if, _peek_scope_id, _resume, _resume_branch, _resume_locals, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _serialize_guard, _serialize_if, _set_serialize_reason, _show_end, _show_start, _style_html, _subscribe, _template, _text_resume, _textarea_value, _to_text, _trailers, _try, _unescaped, _var, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, withLoadAssets, withPageAssets };
2405
+ export { $global, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_select_value, _attrs_textarea_value, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _escape_style_value, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _html_resume, _id, _if, _peek_scope_id, _resume, _resume_branch, _resume_locals, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _set_scope_reason, _show_end, _show_start, _style_html, _subscribe, _template, _text_resume, _textarea_value, _to_text, _trailers, _try, _unescaped, _var, _write_guard, _write_if, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, withLoadAssets, withPageAssets };