marko 6.3.56 → 6.4.0

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 (81) hide show
  1. package/cheatsheet.md +2 -2
  2. package/dist/common/constants/accessor-prefix.d.ts +1 -0
  3. package/dist/common/constants/accessor-prefix.debug.d.ts +1 -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/types.d.ts +8 -2
  7. package/dist/debug/dom/catch.feat.js +12 -14
  8. package/dist/debug/dom/catch.feat.mjs +12 -14
  9. package/dist/debug/dom/controllable-input.feat.js +1 -1
  10. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  11. package/dist/debug/dom/controllable-open.feat.js +1 -1
  12. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  13. package/dist/debug/dom/controllable-select.feat.js +1 -1
  14. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  15. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  16. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  17. package/dist/debug/dom/controllable.feat.js +1 -1
  18. package/dist/debug/dom/controllable.feat.mjs +1 -1
  19. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  20. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  21. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  22. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  23. package/dist/debug/dom/lazy.feat.js +4 -0
  24. package/dist/debug/dom/lazy.feat.mjs +4 -0
  25. package/dist/debug/dom/placeholder.feat.js +1 -1
  26. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  27. package/dist/debug/{dom-DcwejnYg.js → dom-BRO5aArp.js} +232 -178
  28. package/dist/debug/{dom-BeCNT5R5.mjs → dom-Btj2QJhk.mjs} +215 -167
  29. package/dist/debug/dom.js +14 -12
  30. package/dist/debug/dom.mjs +14 -12
  31. package/dist/debug/html.js +603 -517
  32. package/dist/debug/html.mjs +602 -518
  33. package/dist/dom/abort-signal.d.ts +2 -0
  34. package/dist/dom/catch.feat.js +6 -7
  35. package/dist/dom/catch.feat.mjs +5 -7
  36. package/dist/dom/control-flow.d.ts +3 -5
  37. package/dist/dom/controllable-input.feat.js +3 -2
  38. package/dist/dom/controllable-input.feat.mjs +1 -1
  39. package/dist/dom/controllable-open.feat.js +3 -2
  40. package/dist/dom/controllable-open.feat.mjs +1 -1
  41. package/dist/dom/controllable-select.feat.js +3 -2
  42. package/dist/dom/controllable-select.feat.mjs +1 -1
  43. package/dist/dom/controllable-textarea.feat.js +3 -2
  44. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  45. package/dist/dom/controllable.feat.js +3 -2
  46. package/dist/dom/controllable.feat.mjs +1 -1
  47. package/dist/dom/dynamic-tag-script.feat.js +3 -2
  48. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  49. package/dist/dom/dynamic-tag-var.feat.js +2 -1
  50. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  51. package/dist/dom/lazy.feat.d.ts +1 -0
  52. package/dist/dom/lazy.feat.js +4 -0
  53. package/dist/dom/lazy.feat.mjs +4 -0
  54. package/dist/dom/load.d.ts +3 -3
  55. package/dist/dom/placeholder.feat.js +4 -3
  56. package/dist/dom/placeholder.feat.mjs +1 -1
  57. package/dist/dom/queue.d.ts +2 -4
  58. package/dist/dom/resume.d.ts +1 -1
  59. package/dist/dom/scope.d.ts +0 -1
  60. package/dist/{dom-BwNsIevR.mjs → dom-B-v8Gw6T.mjs} +114 -87
  61. package/dist/{dom-QEF0csuC.js → dom-BSsI9OPC.js} +210 -182
  62. package/dist/dom.js +59 -56
  63. package/dist/dom.mjs +34 -32
  64. package/dist/html/attrs.d.ts +2 -0
  65. package/dist/html/writer.d.ts +5 -11
  66. package/dist/html.d.ts +1 -1
  67. package/dist/html.js +362 -317
  68. package/dist/html.mjs +361 -317
  69. package/dist/translator/index.js +791 -650
  70. package/dist/translator/util/binding-has-prop.d.ts +2 -0
  71. package/dist/translator/util/entry-builder.d.ts +2 -0
  72. package/dist/translator/util/generate-uid.d.ts +5 -0
  73. package/dist/translator/util/references.d.ts +3 -2
  74. package/dist/translator/util/runtime.d.ts +3 -3
  75. package/dist/translator/util/sections.d.ts +8 -2
  76. package/dist/translator/util/serialize-reasons.d.ts +2 -2
  77. package/dist/translator/util/setup-work.d.ts +5 -0
  78. package/dist/translator/util/signals.d.ts +5 -7
  79. package/dist/translator/visitors/tag/native-tag.d.ts +1 -0
  80. package/package.json +3 -3
  81. 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,17 +244,17 @@ 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) => {
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, serializeReason) => {
251
251
  let shouldResume = serializeReason !== 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
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);
@@ -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.signal.aborted) throw boundary.signal.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];
@@ -454,27 +452,44 @@ 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 + "" : "";
455
+ //#region src/common/for.ts
456
+ function forIn(obj, cb) {
457
+ for (let key in obj) cb(key, obj[key]);
460
458
  }
461
- function _unescaped(val) {
462
- return val ? 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
+ }
463
464
  }
464
- function _escape(val) {
465
- return val ? escapeXMLStr(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);
466
468
  }
467
- function _escape_script(val) {
468
- return val ? escapeScriptStr(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);
469
472
  }
470
- function _escape_style(val) {
471
- return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
473
+ //#endregion
474
+ //#region src/common/opt.ts
475
+ function forEach(opt, cb) {
476
+ if (opt) {
477
+ if (Array.isArray(opt)) for (let item of opt) cb(item);
478
+ else cb(opt);
479
+ }
472
480
  }
473
- function _escape_style_value(val) {
474
- return val || val === 0 ? escapeStyleValue(val + "") : "";
481
+ function push(opt, item) {
482
+ return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
475
483
  }
476
- function _escape_comment(val) {
477
- return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
484
+ function concat(opt, other) {
485
+ if (!opt) return other;
486
+ if (!other) return opt;
487
+ if (Array.isArray(opt)) {
488
+ if (Array.isArray(other)) for (let item of other) opt.push(item);
489
+ else opt.push(other);
490
+ return opt;
491
+ }
492
+ return Array.isArray(other) ? [opt, ...other] : [opt, other];
478
493
  }
479
494
  patchIteratorNext(Generator.prototype), patchIteratorNext(AsyncGenerator.prototype);
480
495
  var State$1 = class {
@@ -514,6 +529,8 @@ var State$1 = class {
514
529
  stringifyScopes(flushes, boundary, channel) {
515
530
  try {
516
531
  return this.#state.boundary = boundary, this.#state.channel = channel, writeScopesRoot(this.#state, flushes);
532
+ } catch (err) {
533
+ return abortRender(boundary, err), "";
517
534
  } finally {
518
535
  this.#state.flushId++, this.#state.buf = [];
519
536
  }
@@ -593,10 +610,12 @@ function writeAssigned(state) {
593
610
  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(")")));
594
611
  } else state.buf.push("void 0");
595
612
  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");
613
+ if (mutation.value !== void 0) {
614
+ if (writeProp(state, mutation.value, null, "")) {
615
+ let valueRef = typeof mutation.value == "string" ? state.strs.get(mutation.value) : state.refs.get(mutation.value);
616
+ valueRef && !valueRef.id && valueRef.scopeId === void 0 && (valueRef.id = mutation.valueId || nextRefAccess(state), state.buf[valueStartIndex] = valueRef.id + "=" + state.buf[valueStartIndex]);
617
+ } else state.buf.push("void 0");
618
+ }
600
619
  state.buf.push(")");
601
620
  }
602
621
  state.mutated = remaining;
@@ -716,7 +735,8 @@ function writeUnknownObject(state, val, ref) {
716
735
  let proto = Object.getPrototypeOf(val);
717
736
  if (proto === objectProto) return writePlainObject(state, val, ref);
718
737
  if (proto === arrayProto) return writeArray(state, val, ref);
719
- switch (proto?.constructor) {
738
+ let constructor = proto?.constructor;
739
+ switch (constructor) {
720
740
  case void 0: return writeNullObject(state, val, ref);
721
741
  case Object: return writePlainObject(state, val, ref);
722
742
  case Array: return writeArray(state, val, ref);
@@ -733,7 +753,7 @@ function writeUnknownObject(state, val, ref) {
733
753
  case ReferenceError:
734
754
  case SyntaxError:
735
755
  case TypeError:
736
- case URIError: return writeError(state, val, ref);
756
+ case URIError: return writeError(state, val, constructor.name, ref);
737
757
  case AggregateError: return writeAggregateError(state, val, ref);
738
758
  case ArrayBuffer: return writeArrayBuffer(state, val);
739
759
  case Int8Array:
@@ -746,7 +766,7 @@ function writeUnknownObject(state, val, ref) {
746
766
  case Float32Array:
747
767
  case Float64Array:
748
768
  case BigInt64Array:
749
- case BigUint64Array: return writeTypedArray(state, val, ref);
769
+ case BigUint64Array: return writeTypedArray(state, val, constructor.name, ref);
750
770
  case DataView: return writeDataView(state, val, ref);
751
771
  case WeakSet: return writeWeakSet(state);
752
772
  case WeakMap: return writeWeakMap(state);
@@ -884,12 +904,12 @@ function writeArrayBuffer(state, val) {
884
904
  } else result = "new ArrayBuffer";
885
905
  return state.buf.push(result), !0;
886
906
  }
887
- function writeTypedArray(state, val, ref) {
907
+ function writeTypedArray(state, val, name, ref) {
888
908
  if (val.byteOffset || val.byteLength < val.buffer.byteLength || state.refs.has(val.buffer)) {
889
909
  if (!canWriteBuffer(state, val.buffer, ref)) return !1;
890
910
  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)) + ")"));
911
+ state.buf.push("new " + name + "("), writeProp(state, val.buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
912
+ } 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
913
  return !0;
894
914
  }
895
915
  function writeWeakSet(state) {
@@ -898,8 +918,8 @@ function writeWeakSet(state) {
898
918
  function writeWeakMap(state) {
899
919
  return state.buf.push("new WeakMap"), !0;
900
920
  }
901
- function writeError(state, val, ref) {
902
- let result = "new " + val.constructor.name + "(" + quote(val.message + "", 0);
921
+ function writeError(state, val, name, ref) {
922
+ let result = "new " + name + "(" + quote(val.message + "", 0);
903
923
  if (val.cause !== void 0) {
904
924
  let pos = state.buf.push(result + ",{cause:") - 1;
905
925
  writeProp(state, val.cause, ref, "cause") ? state.buf.push("})") : state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
@@ -1066,6 +1086,10 @@ function trackChannel(state, ref) {
1066
1086
  }
1067
1087
  return !1;
1068
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
  }
@@ -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, serializeReason) {
1343
+ _html(`${_attrs(data, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
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, serializeReason) {
1354
+ _html(`${_attrs_partial(data, skip, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
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);
@@ -1463,11 +1613,12 @@ function applyBranchStart(chunk, beforeBranch, rendered) {
1463
1613
  }
1464
1614
  function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
1465
1615
  let endTag = parentEndTag || "";
1466
- if (serializeMarker !== 0) if (!parentEndTag || serializeStateful !== 0) {
1467
- let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
1468
- $chunk.writeHTML(mark + endTag);
1469
- } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1470
- else $chunk.writeHTML(endTag);
1616
+ if (serializeMarker !== 0) {
1617
+ if (!parentEndTag || serializeStateful !== 0) {
1618
+ let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
1619
+ $chunk.writeHTML(mark + endTag);
1620
+ } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1621
+ } else $chunk.writeHTML(endTag);
1471
1622
  }
1472
1623
  function _existing_scope(scopeId) {
1473
1624
  return writeScope(scopeId, {});
@@ -1521,26 +1672,24 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1521
1672
  } else content(promise);
1522
1673
  return;
1523
1674
  }
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) => {
1675
+ let chunk = $chunk, { boundary } = chunk, startId = _peek_scope_id(), after = chunk.next = $chunk = chunk.fork(boundary, chunk.next);
1676
+ chunk.async = !0, captureContext(chunk), boundary.startAsync(), promise.then((value) => {
1529
1677
  chunk.async && (chunk.async = !1, boundary.signal.aborted || (chunk.render(() => {
1530
1678
  if (resumeMarker) {
1531
1679
  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);
1680
+ $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync({ parent: getAsyncContent(chunk) }, content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1681
+ } else {
1682
+ let renderedSince = _peek_scope_id() !== startId, async = { parent: getAsyncContent(chunk) };
1683
+ 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;
1684
+ }
1534
1685
  }), boundary.endAsync()));
1535
1686
  }, (err) => {
1536
1687
  chunk.async = !1, boundary.abort(err);
1537
1688
  });
1538
1689
  }
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)));
1690
+ function _try(scopeId, accessor, content, placeholderContent, catchContent, placeholderId, catchId) {
1691
+ 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;
1692
+ applyBranchStart(chunk, beforeBranch, rendered), rendered && (renderersWritten || renderers(), $chunk.writeHTML(state.mark("]", scopeId + " " + accessor + " " + branchId)));
1544
1693
  }
1545
1694
  function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1546
1695
  let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
@@ -1548,7 +1697,7 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1548
1697
  chunk.append(body);
1549
1698
  return;
1550
1699
  }
1551
- chunk.next = $chunk = chunk.fork(boundary, chunk.next), chunk.placeholder = {
1700
+ chunk.next = $chunk = chunk.fork(boundary, chunk.next), captureContext(chunk), chunk.placeholder = {
1552
1701
  body,
1553
1702
  render: placeholder,
1554
1703
  branchId,
@@ -1556,29 +1705,31 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1556
1705
  placeholderBranchId
1557
1706
  };
1558
1707
  }
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;
1708
+ function tryBoundary(content, catchContent, branchId, renderers) {
1709
+ let chunk = $chunk, { boundary } = chunk, { state } = boundary, catchBoundary = new Boundary(state, boundary.signal, boundary), body = chunk.fork(catchBoundary, null), bodyEnd = body.render(() => withBranchId(branchId, content));
1710
+ if (catchBoundary.signal.aborted) return catchContent ? catchContent(catchBoundary.signal.reason) : boundary.abort(catchBoundary.signal.reason), !0;
1562
1711
  if (body === bodyEnd) return chunk.append(body), !1;
1563
1712
  let renderersAtSettle = !catchBoundary.resumeWrites, bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1564
1713
  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());
1714
+ let reorderId = catchContent ? state.nextReorderId() : "", endMarker = reorderId && state.mark("!", reorderId);
1715
+ return reorderId && (chunk.writeHTML(state.mark("!^", reorderId)), bodyEnd.writeHTML(endMarker), captureContext(chunk)), catchBoundary.onNext = () => {
1716
+ if (!boundary.signal.aborted) {
1717
+ if (catchBoundary.signal.aborted) {
1718
+ if (!reorderId) {
1719
+ boundary.abort(catchBoundary.signal.reason);
1720
+ return;
1721
+ }
1722
+ if (!bodyEnd.consumed) {
1723
+ let cur = body, writeMarker = !0;
1724
+ do {
1725
+ let next = cur.next;
1726
+ 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;
1727
+ } while (cur !== bodyNext);
1728
+ }
1729
+ let catchChunk = chunk.fork(boundary, null);
1730
+ catchChunk.reorderId = reorderId, catchChunk.render(catchContent, catchBoundary.signal.reason), state.reorder(catchChunk), boundary.endAsync();
1731
+ } else catchBoundary.count ? boundary.onNext() : (renderersAtSettle && catchBoundary.resumeWrites && bodyEnd.render(renderers), boundary.endAsync());
1732
+ }
1582
1733
  }, renderersAtSettle;
1583
1734
  }
1584
1735
  function writeTryRenderers(branchId, catchContent, placeholderContent) {
@@ -1587,8 +1738,12 @@ function writeTryRenderers(branchId, catchContent, placeholderContent) {
1587
1738
  Q: placeholderContent
1588
1739
  });
1589
1740
  }
1590
- function countResumeWrite(boundary) {
1591
- for (; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1741
+ function countResumeWrite(chunk) {
1742
+ for (let boundary = chunk.boundary; boundary; boundary = boundary.parent) boundary.resumeWrites++;
1743
+ for (let async = getAsyncContent(chunk); async && !async.resumed; async = async.parent) async.resumed = !0, async.end?.writeHTML(async.visit);
1744
+ }
1745
+ function getAsyncContent(chunk) {
1746
+ return chunk.context?.[kIsAsync];
1592
1747
  }
1593
1748
  var State = class {
1594
1749
  tagId = 1;
@@ -1662,9 +1817,10 @@ var State = class {
1662
1817
  constructor(state, signal, parent) {
1663
1818
  super(), this.state = state, this.parent = parent, this.signal.addEventListener("abort", () => {
1664
1819
  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
- }));
1820
+ }), signal && (signal.aborted ? this.abort(signal.reason) : signal.addEventListener("abort", this));
1821
+ }
1822
+ handleEvent(event) {
1823
+ this.abort(event.target.reason);
1668
1824
  }
1669
1825
  flush() {
1670
1826
  return this.signal.aborted || flushSerializer(this, this.state), this.count ? 1 : this.signal.aborted ? 2 : 0;
@@ -1673,7 +1829,7 @@ var State = class {
1673
1829
  this.signal.aborted || this.count++;
1674
1830
  }
1675
1831
  endAsync() {
1676
- !this.signal.aborted && this.count && (this.count--, this.onNext());
1832
+ this.signal.aborted || (this.count--, this.onNext());
1677
1833
  }
1678
1834
  }, Chunk = class Chunk {
1679
1835
  html = "";
@@ -1700,7 +1856,7 @@ var State = class {
1700
1856
  this.html += html;
1701
1857
  }
1702
1858
  writeEffect(scopeId, registryId) {
1703
- countResumeWrite(this.boundary), this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1859
+ countResumeWrite(this), this.lastEffect === registryId ? this.effects += " " + scopeId : (this.lastEffect = registryId, this.effects = concatEffects(this.effects, registryId + " " + scopeId));
1704
1860
  }
1705
1861
  writeScript(script) {
1706
1862
  this.scripts = concatScripts(this.scripts, script);
@@ -1721,14 +1877,16 @@ var State = class {
1721
1877
  flushPlaceholder() {
1722
1878
  let { placeholder } = this;
1723
1879
  if (placeholder) {
1880
+ this.placeholder = null;
1724
1881
  let body = placeholder.body.consume();
1725
1882
  if (body.async) {
1726
1883
  let { state } = this.boundary, { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
1727
1884
  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);
1885
+ let { effects } = this, beforeBranch = deferBranchStart(this);
1886
+ if (this.render(() => withBranchId(placeholderBranchId, placeholder.render)) !== this && this.boundary.abort(/* @__PURE__ */ Error("An @placeholder cannot contain async content.")), this.boundary.signal.aborted) return;
1887
+ let stateful = this.effects !== effects;
1888
+ applyBranchStart(this, beforeBranch, stateful), stateful && (this.render(() => writeScope(branchId, { P: scopeWithId(state, placeholderBranchId) })), this.writeHTML(state.mark("]", scopeId + " " + ("P" + branchId) + " " + placeholderBranchId)), body.writeEffect(branchId, "_f")), this.writeHTML(state.mark("!", reorderId)), state.reorder(body);
1730
1889
  } else body.next = this.next, this.next = body;
1731
- this.placeholder = null;
1732
1890
  }
1733
1891
  }
1734
1892
  consume() {
@@ -1747,10 +1905,10 @@ var State = class {
1747
1905
  $chunk = prev;
1748
1906
  }
1749
1907
  }
1750
- flushReadyScripts(reservations, holdEffects) {
1751
- let { boundary, serializeState } = this, { readyId } = serializeState, scripts = "";
1908
+ flushReadyScripts(boundary, reservations, holdEffects) {
1909
+ let { serializeState } = this, { readyId } = serializeState, scripts = "";
1752
1910
  if (forEach(this.takeDeferredReady(), (chunk) => {
1753
- scripts = concatScripts(scripts, chunk.flushReadyScripts(reservations, holdEffects)), (chunk.effects || chunk.deferredReady) && (this.deferredReady = push(this.deferredReady, chunk));
1911
+ scripts = concatScripts(scripts, chunk.flushReadyScripts(boundary, reservations, holdEffects)), (chunk.effects || chunk.deferredReady) && (this.deferredReady = push(this.deferredReady, chunk));
1754
1912
  }), readyId && !this.async) {
1755
1913
  let { state } = boundary;
1756
1914
  flushSerializer(boundary, serializeState);
@@ -1767,11 +1925,11 @@ var State = class {
1767
1925
  }
1768
1926
  return scripts;
1769
1927
  }
1770
- flushScript() {
1771
- let { boundary } = this, { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1928
+ flushScript(boundary) {
1929
+ let { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1772
1930
  needsWalk && (state.walkOnNextFlush = !1);
1773
- let readyResumeScripts = this.flushReadyScripts(void 0, this.async);
1774
- for (let channel; channel = state.serializer.pendingReadyChannel();) {
1931
+ let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
1932
+ for (let channel; !boundary.signal.aborted && (channel = state.serializer.pendingReadyChannel());) {
1775
1933
  let resumes = state.serializer.stringifyScopes([], boundary, channel), deps = state.serializer.takeChannelDeps();
1776
1934
  state.needsMainRuntime = !0, readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
1777
1935
  }
@@ -1795,7 +1953,7 @@ var State = class {
1795
1953
  let { reorderId } = reorderedChunk, readyReservations = [], reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk;
1796
1954
  for (reorderedChunk.reorderId = null;;) {
1797
1955
  cur.flushPlaceholder(), cur.deferOwnReady();
1798
- let { next } = cur, readyResumeScripts = cur.flushReadyScripts(readyReservations, this.async);
1956
+ let { next } = cur, readyResumeScripts = cur.flushReadyScripts(boundary, readyReservations, this.async);
1799
1957
  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
1958
  else break;
1801
1959
  }
@@ -1807,9 +1965,9 @@ var State = class {
1807
1965
  }
1808
1966
  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
1967
  }
1810
- flushHTML() {
1811
- let { boundary } = this, { state } = boundary;
1812
- this.needsWalk && (this.needsWalk = !1, state.walkOnNextFlush = !0), this.flushScript();
1968
+ flushHTML(boundary) {
1969
+ let { state } = boundary;
1970
+ this.needsWalk && (this.needsWalk = !1, state.walkOnNextFlush = !0), this.flushScript(boundary);
1813
1971
  let { html, scripts } = this;
1814
1972
  return this.html = this.scripts = "", state.flushChunk(html, scripts, boundary.count);
1815
1973
  }
@@ -1900,159 +2058,30 @@ function flushTickQueue() {
1900
2058
  }
1901
2059
  }
1902
2060
  //#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 + "");
2061
+ //#region src/html/content.ts
2062
+ function _to_text(val) {
2063
+ return val || val === 0 ? val + "" : "";
2031
2064
  }
2032
- function attrAssignment(value) {
2033
- return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
2065
+ function _unescaped(val) {
2066
+ return val ? val + "" : val === 0 ? "0" : "";
2034
2067
  }
2035
- function escapeSingleQuotedAttrValue(value) {
2036
- return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
2068
+ function _escape(val) {
2069
+ return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
2037
2070
  }
2038
- function replaceUnsafeSingleQuoteAttrChar(match) {
2039
- return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
2071
+ function _escape_script(val) {
2072
+ return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
2040
2073
  }
2041
- function escapeDoubleQuotedAttrValue(value) {
2042
- return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
2074
+ function _escape_style(val) {
2075
+ return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
2043
2076
  }
2044
- function replaceUnsafeDoubleQuoteAttrChar(match) {
2045
- return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
2077
+ function _escape_style_value(val) {
2078
+ return val || val === 0 ? escapeStyleValue(val + "") : "";
2046
2079
  }
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;
2080
+ function escapeCommentStr(str) {
2081
+ return unsafeCommentReg.test(str) && (str = str.replace(unsafeCommentReg, "&gt;")), str.startsWith(getState().commentPrefix) ? "&#" + str.charCodeAt(0) + ";" + str.slice(1) : str;
2053
2082
  }
2054
- function normalizeStrAttrValue(value) {
2055
- return isNotVoid(value) && value !== !0 ? value + "" : "";
2083
+ function _escape_comment(val) {
2084
+ return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
2056
2085
  }
2057
2086
  //#endregion
2058
2087
  //#region src/html/dynamic-tag.ts
@@ -2126,11 +2155,11 @@ var ServerRendered = class {
2126
2155
  done: !1
2127
2156
  };
2128
2157
  return value = "", Promise.resolve(result);
2129
- } else if (done) return Promise.resolve({
2158
+ }
2159
+ return done ? Promise.resolve({
2130
2160
  value: "",
2131
2161
  done
2132
- });
2133
- else return new Promise(exec);
2162
+ }) : new Promise(exec);
2134
2163
  },
2135
2164
  throw(error) {
2136
2165
  return done || aborted || boundary?.abort(error), Promise.resolve({
@@ -2189,49 +2218,64 @@ var ServerRendered = class {
2189
2218
  return this.#cachedPromise ||= new Promise((resolve, reject) => {
2190
2219
  let head = this.#head;
2191
2220
  if (this.#head = null, !head) return reject(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2192
- let { boundary } = head;
2221
+ let { boundary } = head, html = "";
2193
2222
  (boundary.onNext = () => {
2194
2223
  switch (!boundary.count && boundary.flush()) {
2195
2224
  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());
2225
+ settle(boundary), reject(boundary.signal.reason);
2201
2226
  break;
2202
- }
2227
+ case 0:
2228
+ if (head = head.consume(), boundary.signal.aborted) break;
2229
+ html += head.flushHTML(boundary), boundary.count || boundary.signal.aborted || (settle(boundary), resolve(html));
2203
2230
  }
2204
2231
  })();
2205
2232
  });
2206
2233
  }
2207
2234
  #read(onWrite, onAbort, onClose) {
2208
- let tick = !0, head = this.#head;
2235
+ let tick = !0, flushing = !1, again = !1, head = this.#head;
2209
2236
  if (this.#head = null, !head) {
2210
2237
  onAbort(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2211
2238
  return;
2212
2239
  }
2213
2240
  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));
2241
+ if (flushing) {
2242
+ again = !0;
2243
+ return;
2244
+ }
2245
+ flushing = !0;
2246
+ do {
2247
+ again = !1;
2248
+ let status = boundary.flush();
2249
+ if (status === 2) {
2250
+ tick || offTick(onNext), settle(boundary), onAbort(boundary.signal.reason);
2251
+ return;
2252
+ }
2253
+ if (write || status === 0) {
2254
+ if (head = head.consume(), boundary.signal.aborted) continue;
2255
+ let html = head.flushHTML(boundary);
2256
+ if (boundary.signal.aborted) continue;
2257
+ if (html && onWrite(html), !boundary.count) {
2258
+ tick || offTick(onNext), settle(boundary), onClose();
2259
+ return;
2260
+ }
2261
+ write && (tick = !0);
2262
+ } else tick && (tick = !1, queueTick(onNext));
2263
+ } while (again);
2264
+ flushing = !1;
2221
2265
  };
2222
2266
  return onNext(), boundary;
2223
2267
  }
2224
2268
  toString() {
2225
2269
  let head = this.#head;
2226
2270
  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();
2271
+ let { boundary } = head, html = boundary.flush() === 0 ? head.consume().flushHTML(boundary) : "";
2272
+ if (boundary.count && boundary.abort(/* @__PURE__ */ Error("Cannot consume asynchronous render with 'toString'")), settle(boundary), boundary.signal.aborted) throw boundary.signal.reason;
2273
+ return html;
2233
2274
  }
2234
2275
  };
2276
+ function settle(boundary) {
2277
+ boundary.onNext = NOOP$1, boundary.state.$global.signal?.removeEventListener("abort", boundary);
2278
+ }
2235
2279
  function NOOP$1() {}
2236
2280
  //#endregion
2237
2281
  //#region src/html/assets.ts
@@ -2244,7 +2288,7 @@ function withLoadAssets(renderer, assetId, triggers) {
2244
2288
  function withPageAssets(template, runtime, assetId, runtimeId) {
2245
2289
  return assetFlush = runtime, Object.assign((input) => {
2246
2290
  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));
2291
+ 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
2292
  }, template);
2249
2293
  }
2250
2294
  function _flush_head() {
@@ -2301,4 +2345,4 @@ function drainClassFunctions($global, writeScope) {
2301
2345
  }
2302
2346
  function NOOP() {}
2303
2347
  //#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 };
2348
+ 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, _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 };