marko 6.3.55 → 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 (90) hide show
  1. package/cheatsheet.md +3 -2
  2. package/dist/common/accessor.d.ts +3 -0
  3. package/dist/common/accessor.debug.d.ts +3 -0
  4. package/dist/common/constants/accessor-prefix.d.ts +1 -0
  5. package/dist/common/constants/accessor-prefix.debug.d.ts +1 -0
  6. package/dist/common/constants/accessor-prop.d.ts +3 -0
  7. package/dist/common/constants/accessor-prop.debug.d.ts +3 -0
  8. package/dist/common/constants/closure-scopes-prop.d.ts +4 -0
  9. package/dist/common/constants/closure-scopes-prop.debug.d.ts +4 -0
  10. package/dist/common/types.d.ts +9 -3
  11. package/dist/debug/dom/catch.feat.js +12 -14
  12. package/dist/debug/dom/catch.feat.mjs +12 -14
  13. package/dist/debug/dom/controllable-input.feat.js +1 -1
  14. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  15. package/dist/debug/dom/controllable-open.feat.js +1 -1
  16. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  17. package/dist/debug/dom/controllable-select.feat.js +1 -1
  18. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  19. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  20. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  21. package/dist/debug/dom/controllable.feat.js +1 -1
  22. package/dist/debug/dom/controllable.feat.mjs +1 -1
  23. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  24. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  25. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  26. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  27. package/dist/debug/dom/lazy.feat.js +4 -0
  28. package/dist/debug/dom/lazy.feat.mjs +4 -0
  29. package/dist/debug/dom/placeholder.feat.js +1 -1
  30. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  31. package/dist/debug/{dom-CI0Vojyk.js → dom-BRO5aArp.js} +248 -193
  32. package/dist/debug/{dom-tl43c2wO.mjs → dom-Btj2QJhk.mjs} +225 -176
  33. package/dist/debug/dom.js +15 -13
  34. package/dist/debug/dom.mjs +15 -13
  35. package/dist/debug/html.js +605 -523
  36. package/dist/debug/html.mjs +604 -524
  37. package/dist/dom/abort-signal.d.ts +2 -0
  38. package/dist/dom/catch.feat.js +6 -7
  39. package/dist/dom/catch.feat.mjs +5 -7
  40. package/dist/dom/control-flow.d.ts +3 -5
  41. package/dist/dom/controllable-input.feat.js +3 -2
  42. package/dist/dom/controllable-input.feat.mjs +1 -1
  43. package/dist/dom/controllable-open.feat.js +3 -2
  44. package/dist/dom/controllable-open.feat.mjs +1 -1
  45. package/dist/dom/controllable-select.feat.js +3 -2
  46. package/dist/dom/controllable-select.feat.mjs +1 -1
  47. package/dist/dom/controllable-textarea.feat.js +3 -2
  48. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  49. package/dist/dom/controllable.feat.js +3 -2
  50. package/dist/dom/controllable.feat.mjs +1 -1
  51. package/dist/dom/dynamic-tag-script.feat.js +3 -2
  52. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  53. package/dist/dom/dynamic-tag-var.feat.js +2 -1
  54. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  55. package/dist/dom/lazy.feat.d.ts +1 -0
  56. package/dist/dom/lazy.feat.js +4 -0
  57. package/dist/dom/lazy.feat.mjs +4 -0
  58. package/dist/dom/load.d.ts +3 -3
  59. package/dist/dom/placeholder.feat.js +4 -3
  60. package/dist/dom/placeholder.feat.mjs +1 -1
  61. package/dist/dom/queue.d.ts +2 -4
  62. package/dist/dom/resume.d.ts +2 -2
  63. package/dist/dom/scope.d.ts +0 -1
  64. package/dist/dom/signals.d.ts +1 -1
  65. package/dist/{dom-4udEPZaj.mjs → dom-B-v8Gw6T.mjs} +122 -92
  66. package/dist/{dom-C1mr-TA7.js → dom-BSsI9OPC.js} +218 -187
  67. package/dist/dom.d.ts +1 -1
  68. package/dist/dom.js +59 -56
  69. package/dist/dom.mjs +35 -33
  70. package/dist/html/attrs.d.ts +2 -0
  71. package/dist/html/writer.d.ts +5 -11
  72. package/dist/html.d.ts +1 -1
  73. package/dist/html.js +367 -327
  74. package/dist/html.mjs +366 -327
  75. package/dist/translator/index.js +866 -748
  76. package/dist/translator/util/binding-has-prop.d.ts +2 -0
  77. package/dist/translator/util/entry-builder.d.ts +2 -0
  78. package/dist/translator/util/generate-uid.d.ts +5 -0
  79. package/dist/translator/util/optional.d.ts +1 -3
  80. package/dist/translator/util/references.d.ts +6 -2
  81. package/dist/translator/util/runtime.d.ts +3 -3
  82. package/dist/translator/util/sections.d.ts +8 -2
  83. package/dist/translator/util/serialize-reasons.d.ts +3 -1
  84. package/dist/translator/util/setup-work.d.ts +5 -0
  85. package/dist/translator/util/signals.d.ts +5 -7
  86. package/dist/translator/util/translate-attrs.d.ts +2 -1
  87. package/dist/translator/visitors/tag/native-tag.d.ts +1 -0
  88. package/package.json +3 -3
  89. package/tags-html.d.ts +4 -3
  90. 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 {
@@ -485,7 +500,7 @@ var State$1 = class {
485
500
  strs = /* @__PURE__ */ new Map();
486
501
  refs = /* @__PURE__ */ new WeakMap();
487
502
  pendingAssignments = /* @__PURE__ */ new Set();
488
- boundary = void 0;
503
+ boundary;
489
504
  channel = void 0;
490
505
  channelDeps = null;
491
506
  mutated = [];
@@ -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);
@@ -797,9 +817,7 @@ function writeRegExp(state, val) {
797
817
  return source.includes("<") ? state.buf.push(`RegExp(${quote(source, 0)}${val.flags ? ",\"" + val.flags + "\"" : ""})`) : state.buf.push("/" + (unsafeRegExpSourceDetect.test(source) ? source.replace(unsafeRegExpSourceReg, replaceUnsafeRegExpSourceChar) : source) + "/" + val.flags), !0;
798
818
  }
799
819
  function writePromise(state, val, ref) {
800
- let { boundary, channel } = state;
801
- if (!boundary) return !1;
802
- let pId = nextRefAccess(state), handle = newAsyncHandle(state, ref, pId);
820
+ let { boundary, channel } = state, pId = nextRefAccess(state), handle = newAsyncHandle(state, ref, pId);
803
821
  return state.buf.push("(p=>p=new Promise((f,r)=>" + pId + "={f,r(e){p.catch(_=>0);r(e)}}))()"), val.then((v) => writeAsyncCall(state, boundary, handle, "f", v, channel, pId), (v) => writeAsyncCall(state, boundary, handle, "r", v, channel, pId)), boundary.startAsync(), !0;
804
822
  }
805
823
  function newAsyncHandle(state, parent, id) {
@@ -886,12 +904,12 @@ function writeArrayBuffer(state, val) {
886
904
  } else result = "new ArrayBuffer";
887
905
  return state.buf.push(result), !0;
888
906
  }
889
- function writeTypedArray(state, val, ref) {
907
+ function writeTypedArray(state, val, name, ref) {
890
908
  if (val.byteOffset || val.byteLength < val.buffer.byteLength || state.refs.has(val.buffer)) {
891
909
  if (!canWriteBuffer(state, val.buffer, ref)) return !1;
892
910
  let needsLength = val.byteOffset + val.byteLength < val.buffer.byteLength;
893
- state.buf.push("new " + val.constructor.name + "("), writeProp(state, val.buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
894
- } 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)) + ")"));
895
913
  return !0;
896
914
  }
897
915
  function writeWeakSet(state) {
@@ -900,8 +918,8 @@ function writeWeakSet(state) {
900
918
  function writeWeakMap(state) {
901
919
  return state.buf.push("new WeakMap"), !0;
902
920
  }
903
- function writeError(state, val, ref) {
904
- 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);
905
923
  if (val.cause !== void 0) {
906
924
  let pos = state.buf.push(result + ",{cause:") - 1;
907
925
  writeProp(state, val.cause, ref, "cause") ? state.buf.push("})") : state.buf[pos] = state.buf[pos].slice(0, -8) + ")";
@@ -979,9 +997,8 @@ function writeTemporal(state, val, name) {
979
997
  return state.buf.push("Temporal." + name + ".from(" + quote(val.toString(), 0) + ")"), !0;
980
998
  }
981
999
  function writeReadableStream(state, val, ref) {
982
- let { boundary, channel } = state;
983
- if (!boundary || val.locked) return !1;
984
- let reader = val.getReader(), iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1000
+ if (val.locked) return !1;
1001
+ let { boundary, channel } = state, reader = val.getReader(), iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
985
1002
  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));
986
1003
  }, onRejected = (reason) => {
987
1004
  writeAsyncCall(state, boundary, handle, "j", reason, channel);
@@ -1019,9 +1036,7 @@ function writeGenerator(state, iter, ref) {
1019
1036
  }
1020
1037
  function writeAsyncGenerator(state, iter, ref) {
1021
1038
  if (iter[kTouchedIterator]) return state.buf.push("(async function*(){}())"), !0;
1022
- let { boundary, channel } = state;
1023
- if (!boundary) return !1;
1024
- let iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1039
+ let { boundary, channel } = state, iterId = nextRefAccess(state), handle = newAsyncHandle(state, ref, iterId), onFulfilled = ({ value, done }) => {
1025
1040
  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));
1026
1041
  }, onRejected = (reason) => {
1027
1042
  writeAsyncCall(state, boundary, handle, "j", reason, channel);
@@ -1071,6 +1086,10 @@ function trackChannel(state, ref) {
1071
1086
  }
1072
1087
  return !1;
1073
1088
  }
1089
+ function abortRender(boundary, err) {
1090
+ for (; boundary.parent;) boundary = boundary.parent;
1091
+ boundary.abort(err);
1092
+ }
1074
1093
  function isCircular(parent, ref) {
1075
1094
  let cur = parent;
1076
1095
  for (; cur;) {
@@ -1083,16 +1102,17 @@ function toObjectKey(name) {
1083
1102
  if (name === "") return "\"\"";
1084
1103
  if (name === "__proto__") return "[\"__proto__\"]";
1085
1104
  let len = name.length, c0 = name.charCodeAt(0);
1086
- if (c0 >= 48 && c0 <= 57) if (c0 === 48) {
1087
- if (len !== 1) return quote(name, 1);
1088
- } else {
1089
- for (let i = 1; i < len; i++) {
1090
- let c = name.charCodeAt(i);
1091
- 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);
1092
1114
  }
1093
- if (len > 15 && "" + +name !== name) return quote(name, 0);
1094
- }
1095
- 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++) {
1096
1116
  let c = name.charCodeAt(i);
1097
1117
  if (!(c >= 97 && c <= 122 || c >= 65 && c <= 90 || c >= 48 && c <= 57 || c === 95 || c === 36)) return quote(name, i);
1098
1118
  }
@@ -1185,7 +1205,7 @@ function nextRefAccess(state) {
1185
1205
  function nextId(state) {
1186
1206
  let c = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ$_0123456789", n = state.ids++, r = c[n % 53];
1187
1207
  for (n = n / 53 | 0; n; n >>>= 6) r += c[n & 63];
1188
- return r;
1208
+ return r === "name" ? nextId(state) : r;
1189
1209
  }
1190
1210
  function hasSymbolIterator(value) {
1191
1211
  return Symbol.iterator in value;
@@ -1223,42 +1243,161 @@ function patchIteratorNext(proto) {
1223
1243
  }, proto.next[kTouchedIterator] = !0;
1224
1244
  }
1225
1245
  //#endregion
1226
- //#region src/common/for.ts
1227
- function forIn(obj, cb) {
1228
- 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));
1229
1249
  }
1230
- function forOf(list, cb) {
1231
- if (list) {
1232
- let i = 0;
1233
- 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;
1234
1287
  }
1235
1288
  }
1236
- function forTo(to, from, step, cb) {
1237
- let start = from || 0, delta = step || 1;
1238
- 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" : "";
1239
1292
  }
1240
- function forUntil(until, from, step, cb) {
1241
- let start = from || 0, delta = step || 1;
1242
- 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;
1243
1295
  }
1244
- //#endregion
1245
- //#region src/common/opt.ts
1246
- function forEach(opt, cb) {
1247
- if (opt) if (Array.isArray(opt)) for (let item of opt) cb(item);
1248
- else cb(opt);
1296
+ function _style_html(decls) {
1297
+ let id = _id();
1298
+ return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
1249
1299
  }
1250
- function push(opt, item) {
1251
- return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
1300
+ function _attr(name, value) {
1301
+ return isVoid(value) ? "" : nonVoidAttr(name, value);
1252
1302
  }
1253
- function concat(opt, other) {
1254
- if (!opt) return other;
1255
- if (!other) return opt;
1256
- if (Array.isArray(opt)) {
1257
- if (Array.isArray(other)) for (let item of other) opt.push(item);
1258
- else opt.push(other);
1259
- 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/>"'=]/);
1260
1327
  }
1261
- 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 + "" : "";
1262
1401
  }
1263
1402
  //#endregion
1264
1403
  //#region src/html/for.ts
@@ -1324,14 +1463,20 @@ function withContext(key, value, cb, cbValue) {
1324
1463
  ctx[kPendingContexts]--, ctx[key] = prev;
1325
1464
  }
1326
1465
  }
1466
+ function captureContext(chunk) {
1467
+ chunk.context?.[kPendingContexts] && (chunk.context = {
1468
+ ...chunk.context,
1469
+ [kPendingContexts]: 0
1470
+ });
1471
+ }
1327
1472
  function isInResumedBranch() {
1328
1473
  return $chunk?.context?.[kBranchId] !== void 0;
1329
1474
  }
1330
1475
  function withBranchId(branchId, cb, cbValue) {
1331
1476
  return withContext(kBranchId, branchId, cb, cbValue);
1332
1477
  }
1333
- function withIsAsync(cb, value) {
1334
- return withContext(kIsAsync, !0, cb, value);
1478
+ function withIsAsync(async, cb, value) {
1479
+ return withContext(kIsAsync, async, cb, value);
1335
1480
  }
1336
1481
  function _html(html) {
1337
1482
  $chunk.writeHTML(html);
@@ -1468,11 +1613,12 @@ function applyBranchStart(chunk, beforeBranch, rendered) {
1468
1613
  }
1469
1614
  function writeBranchEnd(scopeId, accessor, serializeStateful, serializeMarker, parentEndTag, singleNode, branchIds) {
1470
1615
  let endTag = parentEndTag || "";
1471
- if (serializeMarker !== 0) if (!parentEndTag || serializeStateful !== 0) {
1472
- let { state } = $chunk.boundary, mark = singleNode ? state.mark(parentEndTag ? "}" : "|", scopeId + " " + accessor + (branchIds || "")) : state.mark(parentEndTag ? ")" : "]", scopeId + " " + accessor + (branchIds || ""));
1473
- $chunk.writeHTML(mark + endTag);
1474
- } else $chunk.writeHTML(endTag + _el_resume(scopeId, accessor));
1475
- 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);
1476
1622
  }
1477
1623
  function _existing_scope(scopeId) {
1478
1624
  return writeScope(scopeId, {});
@@ -1526,26 +1672,24 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
1526
1672
  } else content(promise);
1527
1673
  return;
1528
1674
  }
1529
- let chunk = $chunk, { boundary } = chunk;
1530
- chunk.next = $chunk = chunk.fork(boundary, chunk.next), chunk.async = !0, chunk.context?.[kPendingContexts] && (chunk.context = {
1531
- ...chunk.context,
1532
- [kPendingContexts]: 0
1533
- }), 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) => {
1534
1677
  chunk.async && (chunk.async = !1, boundary.signal.aborted || (chunk.render(() => {
1535
1678
  if (resumeMarker) {
1536
1679
  let branchId = _peek_scope_id();
1537
- $chunk.writeHTML($chunk.boundary.state.mark("[", "")), withBranchId(branchId, () => withIsAsync(content, value)), $chunk.writeHTML($chunk.boundary.state.mark("]", scopeId + " " + accessor + " " + branchId));
1538
- } 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
+ }
1539
1685
  }), boundary.endAsync()));
1540
1686
  }, (err) => {
1541
1687
  chunk.async = !1, boundary.abort(err);
1542
1688
  });
1543
1689
  }
1544
- function _try(scopeId, accessor, content, input) {
1545
- 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;
1546
- catchContent !== void 0 || placeholderContent ? renderersAtSettle = tryBoundary(placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId, scopeId, placeholderBranchId) : content, catchContent, placeholderContent, branchId) : withBranchId(branchId, content);
1547
- let rendered = chunk !== $chunk || boundary.resumeWrites !== resumeWrites;
1548
- 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)));
1549
1693
  }
1550
1694
  function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBranchId) {
1551
1695
  let chunk = $chunk, { boundary } = chunk, body = chunk.fork(boundary, null);
@@ -1553,7 +1697,7 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1553
1697
  chunk.append(body);
1554
1698
  return;
1555
1699
  }
1556
- chunk.next = $chunk = chunk.fork(boundary, chunk.next), chunk.placeholder = {
1700
+ chunk.next = $chunk = chunk.fork(boundary, chunk.next), captureContext(chunk), chunk.placeholder = {
1557
1701
  body,
1558
1702
  render: placeholder,
1559
1703
  branchId,
@@ -1561,29 +1705,31 @@ function tryPlaceholder(content, placeholder, branchId, scopeId, placeholderBran
1561
1705
  placeholderBranchId
1562
1706
  };
1563
1707
  }
1564
- function tryBoundary(content, catchContent, placeholderContent, branchId) {
1565
- 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));
1566
- 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;
1567
1711
  if (body === bodyEnd) return chunk.append(body), !1;
1568
1712
  let renderersAtSettle = !catchBoundary.resumeWrites, bodyNext = bodyEnd.next = $chunk = chunk.fork(boundary, chunk.next);
1569
1713
  chunk.next = body, boundary.startAsync();
1570
- let reorderId = catchContent === void 0 ? "" : state.nextReorderId(), endMarker = reorderId && state.mark("!", reorderId);
1571
- return reorderId && (chunk.writeHTML(state.mark("!^", reorderId)), bodyEnd.writeHTML(endMarker)), catchBoundary.onNext = () => {
1572
- if (!boundary.signal.aborted) if (catchBoundary.signal.aborted) {
1573
- if (!reorderId) {
1574
- boundary.abort(catchBoundary.signal.reason);
1575
- return;
1576
- }
1577
- if (!bodyEnd.consumed) {
1578
- let cur = body, writeMarker = !0;
1579
- do {
1580
- let next = cur.next;
1581
- 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;
1582
- } while (cur !== bodyNext);
1583
- }
1584
- let catchChunk = chunk.fork(boundary, null), { resumeWrites } = boundary;
1585
- 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();
1586
- } 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
+ }
1587
1733
  }, renderersAtSettle;
1588
1734
  }
1589
1735
  function writeTryRenderers(branchId, catchContent, placeholderContent) {
@@ -1592,8 +1738,12 @@ function writeTryRenderers(branchId, catchContent, placeholderContent) {
1592
1738
  Q: placeholderContent
1593
1739
  });
1594
1740
  }
1595
- function countResumeWrite(boundary) {
1596
- 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];
1597
1747
  }
1598
1748
  var State = class {
1599
1749
  tagId = 1;
@@ -1667,9 +1817,10 @@ var State = class {
1667
1817
  constructor(state, signal, parent) {
1668
1818
  super(), this.state = state, this.parent = parent, this.signal.addEventListener("abort", () => {
1669
1819
  this.count = 0, this.state = new State(this.state.$global), this.onNext();
1670
- }), signal && (signal.aborted ? this.abort(signal.reason) : signal.addEventListener("abort", () => {
1671
- this.abort(signal.reason);
1672
- }));
1820
+ }), signal && (signal.aborted ? this.abort(signal.reason) : signal.addEventListener("abort", this));
1821
+ }
1822
+ handleEvent(event) {
1823
+ this.abort(event.target.reason);
1673
1824
  }
1674
1825
  flush() {
1675
1826
  return this.signal.aborted || flushSerializer(this, this.state), this.count ? 1 : this.signal.aborted ? 2 : 0;
@@ -1678,7 +1829,7 @@ var State = class {
1678
1829
  this.signal.aborted || this.count++;
1679
1830
  }
1680
1831
  endAsync() {
1681
- !this.signal.aborted && this.count && (this.count--, this.onNext());
1832
+ this.signal.aborted || (this.count--, this.onNext());
1682
1833
  }
1683
1834
  }, Chunk = class Chunk {
1684
1835
  html = "";
@@ -1705,7 +1856,7 @@ var State = class {
1705
1856
  this.html += html;
1706
1857
  }
1707
1858
  writeEffect(scopeId, registryId) {
1708
- 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));
1709
1860
  }
1710
1861
  writeScript(script) {
1711
1862
  this.scripts = concatScripts(this.scripts, script);
@@ -1726,14 +1877,16 @@ var State = class {
1726
1877
  flushPlaceholder() {
1727
1878
  let { placeholder } = this;
1728
1879
  if (placeholder) {
1880
+ this.placeholder = null;
1729
1881
  let body = placeholder.body.consume();
1730
1882
  if (body.async) {
1731
1883
  let { state } = this.boundary, { branchId, scopeId, placeholderBranchId } = placeholder, reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
1732
1884
  this.writeHTML(state.mark("!^", reorderId));
1733
- let { effects } = this, beforeBranch = deferBranchStart(this), after = this.render(() => withBranchId(placeholderBranchId, placeholder.render)), stateful = after === this && this.effects !== effects;
1734
- 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);
1735
1889
  } else body.next = this.next, this.next = body;
1736
- this.placeholder = null;
1737
1890
  }
1738
1891
  }
1739
1892
  consume() {
@@ -1752,10 +1905,10 @@ var State = class {
1752
1905
  $chunk = prev;
1753
1906
  }
1754
1907
  }
1755
- flushReadyScripts(reservations, holdEffects) {
1756
- let { boundary, serializeState } = this, { readyId } = serializeState, scripts = "";
1908
+ flushReadyScripts(boundary, reservations, holdEffects) {
1909
+ let { serializeState } = this, { readyId } = serializeState, scripts = "";
1757
1910
  if (forEach(this.takeDeferredReady(), (chunk) => {
1758
- 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));
1759
1912
  }), readyId && !this.async) {
1760
1913
  let { state } = boundary;
1761
1914
  flushSerializer(boundary, serializeState);
@@ -1772,11 +1925,11 @@ var State = class {
1772
1925
  }
1773
1926
  return scripts;
1774
1927
  }
1775
- flushScript() {
1776
- let { boundary } = this, { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1928
+ flushScript(boundary) {
1929
+ let { state } = boundary, { $global, runtimePrefix } = state, needsWalk = state.walkOnNextFlush;
1777
1930
  needsWalk && (state.walkOnNextFlush = !1);
1778
- let readyResumeScripts = this.flushReadyScripts(void 0, this.async);
1779
- 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());) {
1780
1933
  let resumes = state.serializer.stringifyScopes([], boundary, channel), deps = state.serializer.takeChannelDeps();
1781
1934
  state.needsMainRuntime = !0, readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
1782
1935
  }
@@ -1800,7 +1953,7 @@ var State = class {
1800
1953
  let { reorderId } = reorderedChunk, readyReservations = [], reorderHTML = "", reorderEffects = "", reorderScripts = "", cur = reorderedChunk;
1801
1954
  for (reorderedChunk.reorderId = null;;) {
1802
1955
  cur.flushPlaceholder(), cur.deferOwnReady();
1803
- let { next } = cur, readyResumeScripts = cur.flushReadyScripts(readyReservations, this.async);
1956
+ let { next } = cur, readyResumeScripts = cur.flushReadyScripts(boundary, readyReservations, this.async);
1804
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;
1805
1958
  else break;
1806
1959
  }
@@ -1812,9 +1965,9 @@ var State = class {
1812
1965
  }
1813
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;
1814
1967
  }
1815
- flushHTML() {
1816
- let { boundary } = this, { state } = boundary;
1817
- 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);
1818
1971
  let { html, scripts } = this;
1819
1972
  return this.html = this.scripts = "", state.flushChunk(html, scripts, boundary.count);
1820
1973
  }
@@ -1905,159 +2058,30 @@ function flushTickQueue() {
1905
2058
  }
1906
2059
  }
1907
2060
  //#endregion
1908
- //#region src/html/attrs.ts
1909
- function _attr_class(value) {
1910
- return stringAttr("class", toDelimitedString(value, " ", stringifyClassObject));
1911
- }
1912
- function _attr_style(value) {
1913
- return stringAttr("style", toDelimitedString(value, ";", stringifyStyleObject));
1914
- }
1915
- function _attr_option_value(value) {
1916
- let valueAttr = _attr("value", value), selectedValue = getContext(kSelectedValue);
1917
- return selectedValue !== void 0 && normalizedValueMatches(selectedValue, value) ? valueAttr + " selected" : valueAttr;
1918
- }
1919
- function _attr_select_value(scopeId, nodeAccessor, value, valueChange, content, serializeType) {
1920
- valueChange && writeControlledScope(3, scopeId, nodeAccessor, void 0, valueChange, serializeType), content && withContext(kSelectedValue, value ?? "", content);
1921
- }
1922
- function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1923
- return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _textarea_value(value);
1924
- }
1925
- function _textarea_value(value) {
1926
- let escaped = _escape(normalizeStrAttrValue(value));
1927
- return escaped[0] === "\n" ? "\n" + escaped : escaped;
1928
- }
1929
- function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1930
- return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _attr("value", value);
1931
- }
1932
- function _attr_input_checked(scopeId, nodeAccessor, checked, checkedChange, serializeType) {
1933
- return checkedChange && writeControlledScope(0, scopeId, nodeAccessor, void 0, checkedChange, serializeType), isNotVoid(checked) ? " checked" : "";
1934
- }
1935
- function _attr_input_checkedValue(scopeId, nodeAccessor, checkedValue, checkedValueChange, value, serializeType) {
1936
- let valueAttr = _attr("value", value);
1937
- return checkedValueChange && writeControlledScope(1, scopeId, nodeAccessor, getCheckedValueRef(checkedValue), checkedValueChange, serializeType), normalizedValueMatches(checkedValue, value) ? valueAttr + " checked" : valueAttr;
1938
- }
1939
- function getCheckedValueRef(checkedValue) {
1940
- if (Array.isArray(checkedValue)) {
1941
- let ref = checkedValuesRefs.get(checkedValue);
1942
- return ref || (ref = [], checkedValuesRefs.set(checkedValue, ref)), ref;
1943
- }
1944
- }
1945
- function _attr_details_or_dialog_open(scopeId, nodeAccessor, open, openChange, serializeType) {
1946
- let normalizedOpen = isNotVoid(open);
1947
- return openChange && writeControlledScope(4, scopeId, nodeAccessor, normalizedOpen || void 0, openChange, serializeType), normalizedOpen ? " open" : "";
1948
- }
1949
- function _attr_nonce() {
1950
- return getChunk().boundary.state.nonceAttr;
1951
- }
1952
- function _style_html(decls) {
1953
- let id = _id();
1954
- return `<style${_attr_nonce()} class=${id}>.${id}~*{${decls}}</style>`;
1955
- }
1956
- function _attr(name, value) {
1957
- return isVoid(value) ? "" : nonVoidAttr(name, value);
1958
- }
1959
- function _attr_and(name, value, attr) {
1960
- return value ? attr : _attr(name, value);
1961
- }
1962
- function _attr_or(name, value, attr) {
1963
- return value ? _attr(name, value) : attr;
1964
- }
1965
- function _attr_nullish(name, value, attr) {
1966
- return value == null ? attr : _attr(name, value);
1967
- }
1968
- function _attrs(data, nodeAccessor, scopeId, tagName) {
1969
- let result = "", skip = /[\s/>"'=]/, events;
1970
- switch (data && tagName) {
1971
- case "input":
1972
- 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/>"'=]/);
1973
- break;
1974
- case "select":
1975
- case "textarea":
1976
- ("value" in data || data.valueChange) && (skip = /^value(?:Change)?$|[\s/>"'=]/);
1977
- break;
1978
- case "option":
1979
- "value" in data && (result += _attr_option_value(data.value), skip = /^value$|[\s/>"'=]/);
1980
- break;
1981
- case "details":
1982
- case "dialog":
1983
- data.openChange && (result += _attr_details_or_dialog_open(scopeId, nodeAccessor, data.open, data.openChange, 1), skip = /^open(?:Change)?$|[\s/>"'=]/);
1984
- break;
1985
- }
1986
- for (let name in data) {
1987
- let value = data[name];
1988
- switch (name) {
1989
- case "class":
1990
- result += _attr_class(value);
1991
- break;
1992
- case "style":
1993
- result += _attr_style(value);
1994
- break;
1995
- default:
1996
- 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));
1997
- break;
1998
- }
1999
- }
2000
- return result;
2001
- }
2002
- function _attrs_content(data, nodeAccessor, scopeId, tagName, serializeReason) {
2003
- _html(`${_attrs(data, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
2004
- }
2005
- function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
2006
- let partial = {};
2007
- for (let name in data) {
2008
- let key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
2009
- skip[key] || (partial[key] = data[name]);
2010
- }
2011
- return _attrs(partial, nodeAccessor, scopeId, tagName);
2012
- }
2013
- function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, serializeReason) {
2014
- _html(`${_attrs_partial(data, skip, nodeAccessor, scopeId, tagName)}>`), _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
2015
- }
2016
- function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, serializeType) {
2017
- writeScope(scopeId, serializeType ? {
2018
- ["F" + nodeAccessor]: type,
2019
- ["G" + nodeAccessor]: value,
2020
- ["E" + nodeAccessor]: valueChange
2021
- } : {
2022
- ["G" + nodeAccessor]: value,
2023
- ["E" + nodeAccessor]: valueChange
2024
- });
2025
- }
2026
- function stringAttr(name, value) {
2027
- return value && " " + name + attrAssignment(value);
2028
- }
2029
- function nonVoidAttr(name, value) {
2030
- switch (typeof value) {
2031
- case "string": return " " + name + attrAssignment(value);
2032
- case "boolean": return " " + name;
2033
- case "number": return " " + name + "=" + value;
2034
- }
2035
- return " " + name + attrAssignment(value + "");
2061
+ //#region src/html/content.ts
2062
+ function _to_text(val) {
2063
+ return val || val === 0 ? val + "" : "";
2036
2064
  }
2037
- function attrAssignment(value) {
2038
- 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" : "";
2039
2067
  }
2040
- function escapeSingleQuotedAttrValue(value) {
2041
- return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
2068
+ function _escape(val) {
2069
+ return val ? escapeXMLStr(val + "") : val === 0 ? "0" : "";
2042
2070
  }
2043
- function replaceUnsafeSingleQuoteAttrChar(match) {
2044
- return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
2071
+ function _escape_script(val) {
2072
+ return val ? escapeScriptStr(val + "") : val === 0 ? "0" : "";
2045
2073
  }
2046
- function escapeDoubleQuotedAttrValue(value) {
2047
- return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
2074
+ function _escape_style(val) {
2075
+ return val ? escapeStyleStr(val + "") : val === 0 ? "0" : "";
2048
2076
  }
2049
- function replaceUnsafeDoubleQuoteAttrChar(match) {
2050
- return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
2077
+ function _escape_style_value(val) {
2078
+ return val || val === 0 ? escapeStyleValue(val + "") : "";
2051
2079
  }
2052
- function normalizedValueMatches(a, b) {
2053
- let value = normalizeStrAttrValue(b);
2054
- if (Array.isArray(a)) {
2055
- for (let item of a) if (normalizeStrAttrValue(item) === value) return !0;
2056
- } else if (normalizeStrAttrValue(a) === value) return !0;
2057
- 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;
2058
2082
  }
2059
- function normalizeStrAttrValue(value) {
2060
- return isNotVoid(value) && value !== !0 ? value + "" : "";
2083
+ function _escape_comment(val) {
2084
+ return val ? escapeCommentStr(val + "") : val === 0 ? "0" : "";
2061
2085
  }
2062
2086
  //#endregion
2063
2087
  //#region src/html/dynamic-tag.ts
@@ -2131,11 +2155,11 @@ var ServerRendered = class {
2131
2155
  done: !1
2132
2156
  };
2133
2157
  return value = "", Promise.resolve(result);
2134
- } else if (done) return Promise.resolve({
2158
+ }
2159
+ return done ? Promise.resolve({
2135
2160
  value: "",
2136
2161
  done
2137
- });
2138
- else return new Promise(exec);
2162
+ }) : new Promise(exec);
2139
2163
  },
2140
2164
  throw(error) {
2141
2165
  return done || aborted || boundary?.abort(error), Promise.resolve({
@@ -2194,49 +2218,64 @@ var ServerRendered = class {
2194
2218
  return this.#cachedPromise ||= new Promise((resolve, reject) => {
2195
2219
  let head = this.#head;
2196
2220
  if (this.#head = null, !head) return reject(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2197
- let { boundary } = head;
2221
+ let { boundary } = head, html = "";
2198
2222
  (boundary.onNext = () => {
2199
2223
  switch (!boundary.count && boundary.flush()) {
2200
2224
  case 2:
2201
- boundary.onNext = NOOP$1, reject(boundary.signal.reason);
2202
- break;
2203
- case 0: {
2204
- let consumed = head.consume();
2205
- boundary.signal.aborted || resolve(consumed.flushHTML());
2225
+ settle(boundary), reject(boundary.signal.reason);
2206
2226
  break;
2207
- }
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));
2208
2230
  }
2209
2231
  })();
2210
2232
  });
2211
2233
  }
2212
2234
  #read(onWrite, onAbort, onClose) {
2213
- let tick = !0, head = this.#head;
2235
+ let tick = !0, flushing = !1, again = !1, head = this.#head;
2214
2236
  if (this.#head = null, !head) {
2215
2237
  onAbort(/* @__PURE__ */ Error(CONSUMED_RESULT_MESSAGE));
2216
2238
  return;
2217
2239
  }
2218
2240
  let { boundary } = head, onNext = boundary.onNext = (write) => {
2219
- let status = boundary.flush();
2220
- if (status === 2) tick || offTick(onNext), boundary.onNext = NOOP$1, onAbort(boundary.signal.reason);
2221
- else if (write || status === 0) {
2222
- if (head = head.consume(), boundary.signal.aborted) return;
2223
- let html = head.flushHTML();
2224
- html && onWrite(html), status === 0 ? (tick || offTick(onNext), onClose()) : tick = !0;
2225
- } 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;
2226
2265
  };
2227
2266
  return onNext(), boundary;
2228
2267
  }
2229
2268
  toString() {
2230
2269
  let head = this.#head;
2231
2270
  if (this.#head = null, !head) throw Error(CONSUMED_RESULT_MESSAGE);
2232
- let { boundary } = head;
2233
- switch (boundary.flush()) {
2234
- case 2: throw boundary.signal.reason;
2235
- case 1: throw Error("Cannot consume asynchronous render with 'toString'");
2236
- }
2237
- 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;
2238
2274
  }
2239
2275
  };
2276
+ function settle(boundary) {
2277
+ boundary.onNext = NOOP$1, boundary.state.$global.signal?.removeEventListener("abort", boundary);
2278
+ }
2240
2279
  function NOOP$1() {}
2241
2280
  //#endregion
2242
2281
  //#region src/html/assets.ts
@@ -2249,7 +2288,7 @@ function withLoadAssets(renderer, assetId, triggers) {
2249
2288
  function withPageAssets(template, runtime, assetId, runtimeId) {
2250
2289
  return assetFlush = runtime, Object.assign((input) => {
2251
2290
  let g = $global();
2252
- 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));
2253
2292
  }, template);
2254
2293
  }
2255
2294
  function _flush_head() {
@@ -2306,4 +2345,4 @@ function drainClassFunctions($global, writeScope) {
2306
2345
  }
2307
2346
  function NOOP() {}
2308
2347
  //#endregion
2309
- 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 };