marko 6.3.33 → 6.3.35

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 (69) hide show
  1. package/cheatsheet.md +37 -33
  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/errors.d.ts +2 -0
  5. package/dist/common/types.d.ts +10 -0
  6. package/dist/debug/dom/catch.feat.js +1 -1
  7. package/dist/debug/dom/catch.feat.mjs +1 -1
  8. package/dist/debug/dom/controllable-input.feat.js +1 -1
  9. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  10. package/dist/debug/dom/controllable-open.feat.js +1 -1
  11. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  12. package/dist/debug/dom/controllable-select.feat.js +1 -1
  13. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  14. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  15. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  16. package/dist/debug/dom/controllable.feat.js +1 -1
  17. package/dist/debug/dom/controllable.feat.mjs +1 -1
  18. package/dist/debug/{dom-BJ93mcSe.mjs → dom-B57LrRnX.mjs} +89 -46
  19. package/dist/debug/{dom-CiFITSPN.js → dom-Bt4OoZ-j.js} +89 -46
  20. package/dist/debug/dom.js +3 -1
  21. package/dist/debug/dom.mjs +3 -1
  22. package/dist/debug/html.js +205 -98
  23. package/dist/debug/html.mjs +205 -98
  24. package/dist/dom/catch.feat.js +1 -1
  25. package/dist/dom/catch.feat.mjs +1 -1
  26. package/dist/dom/control-flow.d.ts +4 -1
  27. package/dist/dom/controllable-input.feat.js +1 -1
  28. package/dist/dom/controllable-input.feat.mjs +1 -1
  29. package/dist/dom/controllable-open.feat.js +1 -1
  30. package/dist/dom/controllable-open.feat.mjs +1 -1
  31. package/dist/dom/controllable-select.feat.js +1 -1
  32. package/dist/dom/controllable-select.feat.mjs +1 -1
  33. package/dist/dom/controllable-textarea.feat.js +1 -1
  34. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  35. package/dist/dom/controllable.feat.js +1 -1
  36. package/dist/dom/controllable.feat.mjs +1 -1
  37. package/dist/dom/signals.d.ts +3 -3
  38. package/dist/{dom-Cj4HQ7T_.mjs → dom-BP2XSglG.mjs} +46 -33
  39. package/dist/{dom-CI-06TZb.js → dom-BeF9xIzO.js} +46 -33
  40. package/dist/dom.js +3 -1
  41. package/dist/dom.mjs +3 -1
  42. package/dist/html/compat.d.ts +4 -2
  43. package/dist/html/dynamic-tag.d.ts +1 -1
  44. package/dist/html/serializer.d.ts +9 -1
  45. package/dist/html/template.d.ts +1 -0
  46. package/dist/html/writer.d.ts +1 -0
  47. package/dist/html.js +88 -63
  48. package/dist/html.mjs +88 -63
  49. package/dist/translator/core/client.d.ts +1 -2
  50. package/dist/translator/core/server.d.ts +1 -2
  51. package/dist/translator/core/static.d.ts +1 -2
  52. package/dist/translator/index.js +514 -314
  53. package/dist/translator/util/constants/binding-type.d.ts +1 -0
  54. package/dist/translator/util/references.d.ts +8 -1
  55. package/dist/translator/util/serialize-reasons.d.ts +4 -4
  56. package/dist/translator/util/signals.d.ts +5 -0
  57. package/dist/translator/util/statement-tag.d.ts +2 -0
  58. package/dist/translator/util/translate-var.d.ts +1 -1
  59. package/dist/translator/visitors/export-declaration.d.ts +8 -0
  60. package/dist/translator/visitors/program/index.d.ts +0 -1
  61. package/package.json +5 -4
  62. package/tags/html-comment.d.marko +2 -0
  63. package/tags/html-script.d.marko +2 -0
  64. package/tags/html-style.d.marko +2 -0
  65. package/tags/let.d.marko +4 -5
  66. package/tags/show.d.marko +6 -0
  67. package/tags/try.d.marko +1 -1
  68. package/tags-html.d.ts +6 -1
  69. /package/dist/translator/util/{get-accessor-char.d.ts → get-accessor-enums.d.ts} +0 -0
@@ -1,6 +1,6 @@
1
1
  import { register } from "./serializer";
2
2
  import type { ServerRenderer } from "./template";
3
- import { _await, _html, _peek_scope_id, _scope_id, $global, Chunk, isInResumedBranch, State, withChunk, writeScript } from "./writer";
3
+ import { _await, _html, _peek_scope_id, _scope_id, $global, Chunk, getChunk, isInResumedBranch, State, withChunk, writeScript } from "./writer";
4
4
  export declare const compat: {
5
5
  $global: typeof $global;
6
6
  fork: typeof _await;
@@ -10,13 +10,15 @@ export declare const compat: {
10
10
  peekNextScopeId: typeof _peek_scope_id;
11
11
  isInResumedBranch: typeof isInResumedBranch;
12
12
  withChunk: typeof withChunk;
13
+ getChunk: typeof getChunk;
13
14
  ensureState($global: any): State;
14
15
  isTagsAPI(fn: any): boolean;
15
16
  onFlush(fn: (chunk: Chunk) => void): void;
16
17
  patchDynamicTag: (patch: (tag: unknown, scopeId: number, accessor: import("../common/types").Accessor) => unknown) => void;
17
18
  writeSetScopeForComponent(branchId: number, m5c: string, m5i: unknown): void;
18
19
  toJSON(): (this: WeakKey) => [registryId: string, scopeId: unknown] | undefined;
19
- flushScript($global: any): string;
20
+ createChunk($global: any): Chunk;
21
+ flushScript($global: any, chunk?: Chunk): string;
20
22
  render(renderer: ServerRenderer, willRerender: boolean, classAPIOut: any, component: any, input: any, completeChunks: Chunk[], registerChildScope?: boolean): void;
21
23
  register: typeof register;
22
24
  registerRenderBody(fn: any): void;
@@ -5,7 +5,7 @@ interface BodyContentObject {
5
5
  content: ServerRenderer;
6
6
  }
7
7
  export declare let _dynamic_tag: (scopeId: number, accessor: Accessor, tag: unknown | string | ServerRenderer | BodyContentObject, inputOrArgs: unknown, content?: (() => void) | 0, inputIsArgs?: 1, serializeReason?: 1 | 0) => unknown;
8
- export declare function _content(id: string, fn: ServerRenderer): ServerRenderer;
8
+ export declare function _content(id: string, fn: ServerRenderer, scopeId?: number): ServerRenderer;
9
9
  export declare function _content_resume(id: string, fn: ServerRenderer, scopeId?: number): ServerRenderer;
10
10
  export declare const patchDynamicTag: (patch: (tag: unknown, scopeId: number, accessor: Accessor) => unknown) => void;
11
11
  export {};
@@ -5,7 +5,14 @@ export interface SerializeChannel {
5
5
  readyId?: string;
6
6
  parent?: SerializeChannel;
7
7
  }
8
- export declare function setDebugInfo(obj: WeakKey, file: string, loc: string | 0, vars?: Record<string, string>): void;
8
+ interface Debug {
9
+ file: string;
10
+ loc: string | 0;
11
+ vars: Record<string, string | [name: string, loc?: string]> | undefined;
12
+ slots?: Record<string, string>;
13
+ }
14
+ export declare function setDebugInfo(obj: WeakKey, file: string, loc: string | 0, vars?: Debug["vars"]): void;
15
+ export declare function setDebugSlotName(obj: WeakKey, accessor: string, name: string): void;
9
16
  export declare class Serializer {
10
17
  #private;
11
18
  pending(channel?: SerializeChannel): boolean;
@@ -23,3 +30,4 @@ export declare function getRegistered(val: WeakKey): {
23
30
  export declare function toObjectKey(name: string): string;
24
31
  export declare function toAccess(accessor: string): string;
25
32
  export declare function quote(str: string, startPos: number): string;
33
+ export {};
@@ -1,6 +1,7 @@
1
1
  import { RendererProp, type Template } from "../common/types";
2
2
  export type ServerRenderer = ((...args: unknown[]) => unknown) & {
3
3
  [RendererProp.Id]?: string;
4
+ [RendererProp.Owner]?: number;
4
5
  [RendererProp.Embed]?: boolean;
5
6
  };
6
7
  export declare const _template: (templateId: string, renderer: ServerRenderer, page?: 1) => Template;
@@ -21,6 +21,7 @@ export declare function getChunk(): Chunk | undefined;
21
21
  export declare function withChunk<T>(chunk: Chunk, cb: () => T): T;
22
22
  export declare function getContext(key: keyof NonNullable<Chunk["context"]>): unknown;
23
23
  export declare function getState(): State;
24
+ export declare function rendererKey(renderer: unknown): unknown;
24
25
  export declare function getScopeId(scope: unknown): number | undefined;
25
26
  export declare function getScopeById(scopeId: number | undefined): ScopeInternals | undefined;
26
27
  export declare function $global(): $Global & {
package/dist/html.js CHANGED
@@ -4,7 +4,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
4
4
  else if (Array.isArray(val)) for (let v of val) part = toDelimitedString(v, delimiter, stringify), part && (str += sep + part, sep = delimiter);
5
5
  else for (let name in val) part = stringify(name, val[name]), part && (str += sep + part, sep = delimiter);
6
6
  return str;
7
- }, unsafeXMLReg = /[<&]/g, replaceUnsafeXML = (c) => c === "&" ? "&amp;" : "&lt;", 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 = Symbol.for("marko.touchedIterator"), { hasOwnProperty } = {}, objectProto = Object.prototype, arrayProto = Array.prototype, Generator = (function* () {})().constructor, AsyncGenerator = (async function* () {})().constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = (() => {
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 = Symbol.for("marko.touchedIterator"), { hasOwnProperty } = {}, objectProto = Object.prototype, arrayProto = Array.prototype, Generator = (function* () {})().constructor, AsyncGenerator = (async function* () {})().constructor, REGISTRY = /* @__PURE__ */ new WeakMap(), KNOWN_SYMBOLS = (() => {
8
8
  let KNOWN_SYMBOLS = /* @__PURE__ */ new Map();
9
9
  for (let name of Object.getOwnPropertyNames(Symbol)) {
10
10
  let symbol = Symbol[name];
@@ -247,7 +247,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
247
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) => {
248
248
  let { state } = $chunk.boundary, target = $chunk.serializeState, scope = scopeWithId(state, scopeId), pending = target.writeScopes[scopeId];
249
249
  return state.needsMainRuntime = !0, Object.assign(scope, partialScope), pending && pending !== partialScope ? Object.assign(pending, partialScope) : target.writeScopes[scopeId] = partialScope, target.flushScopes = !0, scope;
250
- }, NOOP$2 = () => {}, tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb)), tickQueue, kSelectedValue = Symbol("selectedValue"), checkedValuesRefs = /* @__PURE__ */ new WeakMap(), singleQuoteAttrReplacements = /'|&(?=[#a-zA-Z])/g, doubleQuoteAttrReplacements = /"|&(?=[#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) => {
250
+ }, NOOP$2 = () => {}, tick = globalThis.setImmediate || globalThis.setTimeout || globalThis.queueMicrotask || ((cb) => Promise.resolve().then(cb)), tickQueue, kSelectedValue = Symbol("selectedValue"), checkedValuesRefs = /* @__PURE__ */ new WeakMap(), singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g, doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g, needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g, voidElementsReg = /^(?:area|b(?:ase|r)|col|embed|hr|i(?:mg|nput)|link|meta|param|source|track|wbr)$/, _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, serializeReason) => {
251
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) || {};
@@ -278,7 +278,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
278
278
  };
279
279
  result = shouldResume ? withBranchId(branchId, render) : render(), rendered = _peek_scope_id() !== branchId, beforeBranch !== void 0 && (applyBranchStart(chunk, beforeBranch, rendered), _html(state.mark("]", scopeId + " " + accessor + (rendered ? " " + branchId : ""))));
280
280
  }
281
- return rendered ? shouldResume && writeScope(scopeId, { ["D" + accessor]: renderer?.a || renderer }) : _scope_id(), result;
281
+ return rendered ? shouldResume && writeScope(scopeId, { ["D" + accessor]: rendererKey(renderer) }) : _scope_id(), result;
282
282
  }, patchDynamicTag = ((originalDynamicTag) => (patch) => {
283
283
  _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
284
284
  let patched = patch(tag, scopeId, accessor);
@@ -293,6 +293,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
293
293
  peekNextScopeId: _peek_scope_id,
294
294
  isInResumedBranch,
295
295
  withChunk,
296
+ getChunk,
296
297
  ensureState($global) {
297
298
  let state = $global[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
298
299
  return state || ($global.runtimeId ||= "M", $global.renderId ||= $global.componentIdPrefix || $global.widgetIdPrefix || "_", $global[K_TAGS_API_STATE] = state = new State($global)), state;
@@ -326,10 +327,18 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
326
327
  return compatRegistered;
327
328
  };
328
329
  },
329
- flushScript($global) {
330
- let state = this.ensureState($global), boundary = new Boundary(state);
331
- if (boundary.flush() === 1) throw Error("Cannot serialize promise across tags/class compat layer.");
332
- return new Chunk(boundary, null, null, state).flushScript().scripts;
330
+ createChunk($global) {
331
+ let state = this.ensureState($global);
332
+ return new Chunk(new Boundary(state), null, null, state);
333
+ },
334
+ flushScript($global, chunk) {
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;
333
342
  },
334
343
  render(renderer, willRerender, classAPIOut, component, input, completeChunks, registerChildScope) {
335
344
  let state = this.ensureState(classAPIOut.global), boundary = new Boundary(state), head = new Chunk(boundary, null, getChunk()?.context ?? null, state), normalizedInput = input;
@@ -450,28 +459,28 @@ function _escape_comment(val) {
450
459
  patchIteratorNext(Generator.prototype), patchIteratorNext(AsyncGenerator.prototype);
451
460
  var State$1 = class {
452
461
  ids = 0;
453
- flush = 0;
462
+ flushId = 0;
454
463
  wroteUndefined = !1;
455
464
  buf = [];
456
465
  strs = /* @__PURE__ */ new Map();
457
466
  refs = /* @__PURE__ */ new WeakMap();
458
- assigned = /* @__PURE__ */ new Set();
467
+ pendingAssignments = /* @__PURE__ */ new Set();
459
468
  boundary = void 0;
460
469
  channel = void 0;
461
470
  channelDeps = null;
462
471
  mutated = [];
463
472
  }, Reference = class {
464
- assigns = null;
473
+ assignments = null;
465
474
  calls = null;
466
475
  scopeId = void 0;
467
476
  channel = void 0;
468
477
  parent;
469
478
  accessor;
470
- flush;
479
+ flushId;
471
480
  pos;
472
481
  id;
473
- constructor(parent, accessor, flush, pos = null, id = null) {
474
- this.parent = parent, this.accessor = accessor, this.flush = flush, this.pos = pos, this.id = id;
482
+ constructor(parent, accessor, flushId, pos = null, id = null) {
483
+ this.parent = parent, this.accessor = accessor, this.flushId = flushId, this.pos = pos, this.id = id;
475
484
  }
476
485
  }, Serializer = class {
477
486
  #state = new State$1();
@@ -485,7 +494,7 @@ var State$1 = class {
485
494
  try {
486
495
  return this.#state.boundary = boundary, this.#state.channel = channel, writeScopesRoot(this.#state, flushes);
487
496
  } finally {
488
- this.#state.flush++, this.#state.buf = [];
497
+ this.#state.flushId++, this.#state.buf = [];
489
498
  }
490
499
  }
491
500
  written(val) {
@@ -526,20 +535,20 @@ function writeScopesRoot(state, flushes) {
526
535
  }
527
536
  nextSlotId !== -1 && buf.push("]");
528
537
  let extras = "";
529
- (state.assigned.size || hasChannelMutations(state)) && (extras = ",0)", fillIndex !== -1 && (buf[fillIndex] = "_(" + buf[fillIndex], buf.push(")")), writeAssigned(state));
538
+ (state.pendingAssignments.size || hasChannelMutations(state)) && (extras = ",0)", fillIndex !== -1 && (buf[fillIndex] = "_(" + buf[fillIndex], buf.push(")")), writeAssigned(state));
530
539
  let result = extras && "(";
531
540
  for (let chunk of buf) result += chunk;
532
541
  return result += extras, result ? state.wroteUndefined ? (state.wroteUndefined = !1, "(_,$)=>" + result) : "_=>" + result : "";
533
542
  }
534
543
  function writeAssigned(state) {
535
544
  let sep = state.buf.length ? "," : "";
536
- if (state.assigned.size) {
537
- let assigned = state.assigned;
538
- state.assigned = /* @__PURE__ */ new Set();
545
+ if (state.pendingAssignments.size) {
546
+ let pending = state.pendingAssignments;
547
+ state.pendingAssignments = /* @__PURE__ */ new Set();
539
548
  let buf = "", hasCalls = !1;
540
- for (let ref of assigned) ref.assigns && (buf += sep + assignsToString(ref.assigns, ref.id), ref.assigns = null, sep = ","), hasCalls ||= ref.calls !== null;
549
+ for (let ref of pending) ref.assignments && (buf += sep + assignmentsToString(ref.assignments, ref.id), ref.assignments = null, sep = ","), hasCalls ||= ref.calls !== null;
541
550
  if (buf && state.buf.push(buf), hasCalls) {
542
- for (let ref of assigned) if (ref.calls) {
551
+ for (let ref of pending) if (ref.calls) {
543
552
  for (let { method, args } of ref.calls) {
544
553
  state.buf.push((state.buf.length ? "," : "") + ref.id + "." + method + "(");
545
554
  for (let a = 0; a < args.length; a++) a && state.buf.push(","), writeCallArg(state, args[a]);
@@ -570,10 +579,14 @@ function writeAssigned(state) {
570
579
  }
571
580
  state.mutated = remaining;
572
581
  }
573
- state.assigned.size && writeAssigned(state);
582
+ state.pendingAssignments.size && writeAssigned(state);
574
583
  }
575
584
  function writeCallArg(state, val) {
576
- val === void 0 ? (state.wroteUndefined = !0, state.buf.push("$")) : writeProp(state, val, null, "") || state.buf.push("void 0");
585
+ if (val === void 0) state.wroteUndefined = !0, state.buf.push("$");
586
+ else if (writeProp(state, val, null, "")) {
587
+ let ref = state.refs.get(val) || state.strs.get(val);
588
+ ref && ref.id === null && assignId(state, ref);
589
+ } else state.buf.push("void 0");
577
590
  }
578
591
  function hasChannelMutations(state) {
579
592
  return hasMatchingMutations(state.mutated, state.channel?.readyId);
@@ -599,22 +612,22 @@ function writeProp(state, val, parent, accessor) {
599
612
  }
600
613
  function writeReferenceOr(state, write, val, parent, accessor) {
601
614
  let ref = state.refs.get(val);
602
- if (ref) return trackChannel(state, ref) ? parent && isCircular(parent, ref) ? (ensureId(state, ref), state.assigned.add(ref), addAssignment(ref, accessId(state, parent) + toAccess(accessor)), !1) : (state.buf.push(ensureId(state, ref)), !0) : !1;
615
+ if (ref) return trackChannel(state, ref) ? parent && isCircular(parent, ref) ? (ensureId(state, ref), state.pendingAssignments.add(ref), addAssignment(ref, accessId(state, parent) + toAccess(accessor)), !1) : (state.buf.push(ensureId(state, ref)), !0) : !1;
603
616
  let registered = REGISTRY.get(val);
604
- return registered ? writeRegistered(state, val, parent, accessor, registered) : (state.refs.set(val, ref = new Reference(parent, accessor, state.flush, state.buf.length)), ref.channel = state.channel, write(state, val, ref) ? !0 : (state.refs.delete(val), !1));
617
+ return registered ? writeRegistered(state, val, parent, accessor, registered) : (state.refs.set(val, ref = new Reference(parent, accessor, state.flushId, state.buf.length)), ref.channel = state.channel, write(state, val, ref) ? !0 : (state.refs.delete(val), !1));
605
618
  }
606
619
  function trackScope(state, val, scopeId) {
607
620
  let ref = state.refs.get(val);
608
621
  ref ? trackChannel(state, ref) : newScopeReference(state, val, scopeId);
609
622
  }
610
623
  function newScopeReference(state, val, scopeId) {
611
- let ref = new Reference(null, null, state.flush);
624
+ let ref = new Reference(null, null, state.flushId);
612
625
  return ref.scopeId = scopeId, ref.channel = state.channel, state.refs.set(val, ref), ref;
613
626
  }
614
627
  function writeRegistered(state, val, parent, accessor, registered) {
615
628
  let { scope } = registered;
616
629
  if (scope) {
617
- let ref = new Reference(parent, accessor, state.flush, state.buf.length);
630
+ let ref = new Reference(parent, accessor, state.flushId, state.buf.length);
618
631
  ref.channel = state.channel, state.refs.set(val, ref);
619
632
  let scopeId = scope[K_SCOPE_ID];
620
633
  trackScope(state, scope, scopeId), state.buf.push("_(" + scopeId + "," + quote(registered.id, 0) + ")");
@@ -627,7 +640,7 @@ function writeString(state, val, parent, accessor) {
627
640
  if (ref) {
628
641
  if (trackChannel(state, ref)) return state.buf.push(ensureId(state, ref)), !0;
629
642
  } else {
630
- let ref = new Reference(parent, accessor, state.flush, state.buf.length);
643
+ let ref = new Reference(parent, accessor, state.flushId, state.buf.length);
631
644
  ref.channel = state.channel, state.strs.set(val, ref);
632
645
  }
633
646
  }
@@ -759,44 +772,44 @@ function writePromise(state, val, ref) {
759
772
  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;
760
773
  }
761
774
  function newAsyncHandle(state, parent, id) {
762
- let handle = {}, handleRef = new Reference(parent, null, state.flush, null, id);
775
+ let handle = {}, handleRef = new Reference(parent, null, state.flushId, null, id);
763
776
  return handleRef.channel = state.channel, state.refs.set(handle, handleRef), handle;
764
777
  }
765
778
  function writeMap(state, val, ref) {
766
779
  if (!val.size) return state.buf.push("new Map"), !0;
767
- let items = [], assigns, needsId, deferring = !1, i = 0;
780
+ let items = [], assignments, needsId, deferring = !1, i = 0;
768
781
  if (val.size < 25) {
769
782
  for (let [itemKey, itemValue] of val) {
770
783
  if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
771
784
  deferCall(state, ref, "set", [itemKey, itemValue]);
772
785
  continue;
773
786
  }
774
- itemKey === val && (itemKey = void 0, (assigns ||= []).push("a[" + i + "][0]")), itemValue === val && (itemValue = void 0, (assigns ||= []).push("a[" + i + "][1]")), needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue), i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
787
+ itemKey === val && (itemKey = void 0, (assignments ||= []).push("a[" + i + "][0]")), itemValue === val && (itemValue = void 0, (assignments ||= []).push("a[" + i + "][1]")), needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue), i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
775
788
  }
776
- writeArrayArg(state, ref, items, assigns && "((m,a)=>(" + assignsToString(assigns, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map,", "new Map(", needsId);
789
+ writeArrayArg(state, ref, items, assignments && "((m,a)=>(" + assignmentsToString(assignments, "m") + ",a.forEach(i=>m.set(i[0],i[1])),m))(new Map,", "new Map(", needsId);
777
790
  } else {
778
791
  for (let [itemKey, itemValue] of val) {
779
792
  if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
780
793
  deferCall(state, ref, "set", [itemKey, itemValue]);
781
794
  continue;
782
795
  }
783
- itemKey === val && (itemKey = 0, (assigns ||= []).push("a[" + i + "]")), itemValue === val && (itemValue = 0, (assigns ||= []).push("a[" + (i + 1) + "]")), needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue), i = items.push(itemKey, itemValue);
796
+ itemKey === val && (itemKey = 0, (assignments ||= []).push("a[" + i + "]")), itemValue === val && (itemValue = 0, (assignments ||= []).push("a[" + (i + 1) + "]")), needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue), i = items.push(itemKey, itemValue);
784
797
  }
785
- writeArrayArg(state, ref, items, assigns && "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignsToString(assigns, "new Map") + "))(", "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(", needsId);
798
+ writeArrayArg(state, ref, items, assignments && "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1])," + assignmentsToString(assignments, "new Map") + "))(", "(a=>a.reduce((m,v,i)=>i%2?m:m.set(v,a[i+1]),new Map))(", needsId);
786
799
  }
787
800
  return !0;
788
801
  }
789
802
  function writeSet(state, val, ref) {
790
803
  if (!val.size) return state.buf.push("new Set"), !0;
791
- let items = [], assigns, needsId, deferring = !1, i = 0;
804
+ let items = [], assignments, needsId, deferring = !1, i = 0;
792
805
  for (let item of val) {
793
806
  if (!deferring && item !== val && isAncestorMember(state, ref, item) && (deferring = !0), deferring) {
794
807
  deferCall(state, ref, "add", [item]);
795
808
  continue;
796
809
  }
797
- item === val ? (item = 0, (assigns ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
810
+ item === val ? (item = 0, (assignments ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
798
811
  }
799
- return writeArrayArg(state, ref, items, assigns && "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId), !0;
812
+ return writeArrayArg(state, ref, items, assignments && "((s,i)=>(" + assignmentsToString(assignments, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId), !0;
800
813
  }
801
814
  function isAncestorMember(state, container, member) {
802
815
  if (member === null || typeof member != "object" && typeof member != "function") return !1;
@@ -807,13 +820,13 @@ function deferCall(state, ref, method, args) {
807
820
  ensureId(state, ref), (ref.calls ||= []).push({
808
821
  method,
809
822
  args
810
- }), state.assigned.add(ref);
823
+ }), state.pendingAssignments.add(ref);
811
824
  }
812
825
  function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
813
826
  if (assignsPrefix || needsId) {
814
- let arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
827
+ let arrayRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
815
828
  state.buf.push((assignsPrefix || plainPrefix) + arrayRef.id + "="), writeArray(state, items, arrayRef);
816
- } else state.buf.push(plainPrefix), writeArray(state, items, new Reference(ref, null, state.flush, state.buf.length));
829
+ } else state.buf.push(plainPrefix), writeArray(state, items, new Reference(ref, null, state.flushId, state.buf.length));
817
830
  state.buf.push(")");
818
831
  }
819
832
  function isDedupedMember(val) {
@@ -847,7 +860,7 @@ function writeTypedArray(state, val, ref) {
847
860
  if (!canWriteBuffer(state, val.buffer, ref)) return !1;
848
861
  let needsLength = val.byteOffset + val.byteLength < val.buffer.byteLength;
849
862
  state.buf.push("new " + val.constructor.name + "("), writeProp(state, val.buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
850
- } else state.refs.set(val.buffer, new Reference(ref, "buffer", state.flush, null)), state.buf.push("new " + val.constructor.name + (val.length === 0 ? "" : "(" + (hasOnlyZeros(val) ? val.length : typedArrayToInitString(val)) + ")"));
863
+ } 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)) + ")"));
851
864
  return !0;
852
865
  }
853
866
  function writeWeakSet(state) {
@@ -869,7 +882,7 @@ function writeAggregateError(state, val, ref) {
869
882
  let inlined = writeProp(state, val.errors, ref, "errors");
870
883
  if (inlined || state.buf.push("[]"), val.message ? state.buf.push("," + quote(val.message + "", 0) + ")") : state.buf.push(")"), inlined) {
871
884
  let errorsRef = state.refs.get(val.errors);
872
- errorsRef?.id && (state.assigned.add(errorsRef), addAssignment(errorsRef, accessId(state, ref) + toAccess("errors")));
885
+ errorsRef?.id && (state.pendingAssignments.add(errorsRef), addAssignment(errorsRef, accessId(state, ref) + toAccess("errors")));
873
886
  }
874
887
  return !0;
875
888
  }
@@ -900,7 +913,7 @@ function writeRequest(state, val, ref) {
900
913
  let seenHeaders = state.refs.get(val.headers);
901
914
  if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders), sep = ",";
902
915
  else {
903
- state.refs.set(val.headers, new Reference(ref, "headers", state.flush, null));
916
+ state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
904
917
  let headers = stringEntriesToHeadersInit(val.headers);
905
918
  headers && (options += sep + "headers:" + headers, sep = ",");
906
919
  }
@@ -912,7 +925,7 @@ function writeResponse(state, val, ref) {
912
925
  let seenHeaders = state.refs.get(val.headers);
913
926
  if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders);
914
927
  else {
915
- state.refs.set(val.headers, new Reference(ref, "headers", state.flush, null));
928
+ state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
916
929
  let headers = stringEntriesToHeadersInit(val.headers);
917
930
  headers && (options += sep + "headers:" + headers);
918
931
  }
@@ -926,7 +939,7 @@ function writeIntl(state, val, name, ref) {
926
939
  }
927
940
  state.buf.push("new Intl." + name + "(" + quote(locale, 0) + ",");
928
941
  let optionsRef;
929
- return needsId ? (optionsRef = new Reference(ref, null, state.flush, null, nextRefAccess(state)), state.buf.push(optionsRef.id + "={")) : (optionsRef = new Reference(ref, null, state.flush, state.buf.length), state.buf.push("{")), writeObjectProps(state, options, optionsRef), state.buf.push("})"), !0;
942
+ return needsId ? (optionsRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state)), state.buf.push(optionsRef.id + "={")) : (optionsRef = new Reference(ref, null, state.flushId, state.buf.length), state.buf.push("{")), writeObjectProps(state, options, optionsRef), state.buf.push("})"), !0;
930
943
  }
931
944
  function writeIntlLocale(state, val) {
932
945
  return state.buf.push("new Intl.Locale(" + quote(val.toString(), 0) + ")"), !0;
@@ -958,11 +971,11 @@ function writeGenerator(state, iter, ref) {
958
971
  if (returnValue === void 0 && !yields.length) return state.buf.push("(function*(){})()"), !0;
959
972
  let heldReturn = returnValue !== void 0 && isAncestorMember(state, ref, returnValue);
960
973
  if (state.buf.push(returnValue === void 0 ? "(function*(a){yield*a})(" : heldReturn ? "(function*(a,r){yield*a;return r.v})(" : "(function*(a,r){yield*a;return r})("), needsId) {
961
- let arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
974
+ let arrayRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
962
975
  state.buf.push(arrayRef.id + "="), writeArray(state, yields, arrayRef);
963
- } else writeArray(state, yields, new Reference(ref, null, state.flush, state.buf.length));
976
+ } else writeArray(state, yields, new Reference(ref, null, state.flushId, state.buf.length));
964
977
  if (heldReturn) {
965
- let holder = new Reference(ref, null, state.flush, null, nextRefAccess(state));
978
+ let holder = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
966
979
  state.buf.push("," + holder.id + "={}"), writeProp(state, returnValue, holder, "v");
967
980
  } else if (returnValue !== void 0) {
968
981
  let sepIndex = state.buf.push(",") - 1;
@@ -1001,7 +1014,7 @@ function writeMaybeIterableProps(state, val, ref) {
1001
1014
  let yieldSelf = "", iterArr = [];
1002
1015
  for (let item of val) item === val && !(yieldSelf || iterArr.length) ? yieldSelf = "yield this;" : iterArr.push(item);
1003
1016
  if (iterArr.length) {
1004
- let iterRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1017
+ let iterRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1005
1018
  state.buf.push(sep + "*[(" + iterRef.id + "="), writeArray(state, iterArr, iterRef), state.buf.push(",Symbol.iterator)](){" + yieldSelf + "yield*" + iterRef.id + "}");
1006
1019
  } else state.buf.push(sep + "*[Symbol.iterator](){" + yieldSelf.slice(0, -1) + "}");
1007
1020
  sep = ",";
@@ -1113,7 +1126,7 @@ function accessId(state, ref) {
1113
1126
  }
1114
1127
  function assignId(state, ref) {
1115
1128
  let { pos } = ref;
1116
- if (ref.id = nextRefAccess(state), pos !== null && ref.flush === state.flush) return pos === 0 ? state.buf[0] = ref.id + "=" + state.buf[0] : state.buf[pos - 1] += ref.id + "=", ref.id;
1129
+ if (ref.id = nextRefAccess(state), pos !== null && ref.flushId === state.flushId) return pos === 0 ? state.buf[0] = ref.id + "=" + state.buf[0] : state.buf[pos - 1] += ref.id + "=", ref.id;
1117
1130
  ref.channel = state.channel;
1118
1131
  let cur = ref, accessPrevValue = "";
1119
1132
  do {
@@ -1123,7 +1136,7 @@ function assignId(state, ref) {
1123
1136
  accessPrevValue = parent.id + accessPrevValue;
1124
1137
  break;
1125
1138
  }
1126
- if (parent.flush === state.flush || parent.scopeId !== void 0) {
1139
+ if (parent.flushId === state.flushId || parent.scopeId !== void 0) {
1127
1140
  accessPrevValue = accessId(state, parent) + accessPrevValue;
1128
1141
  break;
1129
1142
  }
@@ -1131,11 +1144,11 @@ function assignId(state, ref) {
1131
1144
  } while (cur);
1132
1145
  return ref.id + "=" + accessPrevValue;
1133
1146
  }
1134
- function assignsToString(assigns, value) {
1135
- return assigns.length > 100 ? "($=>(" + assigns.join("=$,") + "=$))(" + value + ")" : assigns.join("=") + "=" + value;
1147
+ function assignmentsToString(assignments, value) {
1148
+ return assignments.length > 100 ? "($=>(" + assignments.join("=$,") + "=$))(" + value + ")" : assignments.join("=") + "=" + value;
1136
1149
  }
1137
1150
  function addAssignment(ref, assign) {
1138
- ref.assigns ? ref.assigns.push(assign) : ref.assigns = [assign];
1151
+ ref.assignments ? ref.assignments.push(assign) : ref.assignments = [assign];
1139
1152
  }
1140
1153
  function nextRefAccess(state) {
1141
1154
  return "_." + nextId(state);
@@ -1251,6 +1264,9 @@ function getContext(key) {
1251
1264
  function getState() {
1252
1265
  return $chunk.boundary.state;
1253
1266
  }
1267
+ function rendererKey(renderer) {
1268
+ return renderer?.e === void 0 ? renderer?.a || renderer : renderer.a + " " + renderer.e;
1269
+ }
1254
1270
  function getScopeId(scope) {
1255
1271
  return scope[K_SCOPE_ID];
1256
1272
  }
@@ -1329,7 +1345,7 @@ function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
1329
1345
  let shouldResume = serializeReason !== 0, render = normalizeServerRender(content), branchId = _peek_scope_id();
1330
1346
  render && (shouldResume ? withBranchId(branchId, render) : render()), _peek_scope_id() === branchId ? _scope_id() : shouldResume && writeScope(scopeId, {
1331
1347
  ["A" + nodeAccessor]: writeScope(branchId, {}),
1332
- ["D" + nodeAccessor]: render?.a
1348
+ ["D" + nodeAccessor]: rendererKey(render)
1333
1349
  });
1334
1350
  }
1335
1351
  function normalizeServerRender(value) {
@@ -1816,7 +1832,13 @@ function offTick(cb) {
1816
1832
  function flushTickQueue() {
1817
1833
  let queue = tickQueue;
1818
1834
  tickQueue = void 0;
1819
- for (let cb of queue) cb(!0);
1835
+ for (let cb of queue) try {
1836
+ cb(!0);
1837
+ } catch (err) {
1838
+ tick(() => {
1839
+ throw err;
1840
+ });
1841
+ }
1820
1842
  }
1821
1843
  //#endregion
1822
1844
  //#region src/html/attrs.ts
@@ -1838,7 +1860,7 @@ function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, seriali
1838
1860
  }
1839
1861
  function _textarea_value(value) {
1840
1862
  let escaped = _escape(normalizeStrAttrValue(value));
1841
- return escaped[0] === "\n" || escaped[0] === "\r" ? "\n" + escaped : escaped;
1863
+ return escaped[0] === "\n" ? "\n" + escaped : escaped;
1842
1864
  }
1843
1865
  function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
1844
1866
  return valueChange && writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType), _attr("value", value);
@@ -1955,13 +1977,13 @@ function escapeSingleQuotedAttrValue(value) {
1955
1977
  return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
1956
1978
  }
1957
1979
  function replaceUnsafeSingleQuoteAttrChar(match) {
1958
- return match === "'" ? "&#39;" : "&amp;";
1980
+ return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
1959
1981
  }
1960
1982
  function escapeDoubleQuotedAttrValue(value) {
1961
1983
  return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
1962
1984
  }
1963
1985
  function replaceUnsafeDoubleQuoteAttrChar(match) {
1964
- return match === "\"" ? "&#34;" : "&amp;";
1986
+ return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
1965
1987
  }
1966
1988
  function normalizedValueMatches(a, b) {
1967
1989
  let value = normalizeStrAttrValue(b);
@@ -1975,11 +1997,11 @@ function normalizeStrAttrValue(value) {
1975
1997
  }
1976
1998
  //#endregion
1977
1999
  //#region src/html/dynamic-tag.ts
1978
- function _content(id, fn) {
1979
- return fn.a = id, fn;
2000
+ function _content(id, fn, scopeId) {
2001
+ return fn.a = id, fn.e = scopeId, fn;
1980
2002
  }
1981
2003
  function _content_resume(id, fn, scopeId) {
1982
- return _resume(_content(id, fn), id, scopeId);
2004
+ return _resume(_content(id, fn, scopeId), id, scopeId);
1983
2005
  }
1984
2006
  //#endregion
1985
2007
  //#region src/html/template.ts
@@ -2190,14 +2212,17 @@ function writeTriggerScript(html, triggers) {
2190
2212
  let htmlStr = _escape_script(JSON.stringify(html)), exprs = triggers.map((trigger) => {
2191
2213
  let options = trigger.options && toObjectExpression(trigger.options);
2192
2214
  switch (trigger.type) {
2193
- case "visible": return `(e=>e&&new IntersectionObserver((e,i)=>e.some(e=>e.isIntersecting)&&i.disconnect()+l()${options ? `,${options}` : ""}).observe(e))(document.querySelector(${JSON.stringify(trigger.selector)})||l())`;
2215
+ case "visible": return `(e=>e&&new IntersectionObserver((e,i)=>e.some(e=>e.isIntersecting)&&i.disconnect()+l()${options ? `,${options}` : ""}).observe(e))(${querySelectorOrLoad(trigger.selector)})`;
2194
2216
  case "idle": return `(self.requestIdleCallback||l)(l${options ? `,${options}` : ""})`;
2195
2217
  case "media": return `(m=>m.matches?l():m.addEventListener("change",l,{once:1}))(matchMedia(${JSON.stringify(trigger.selector)}))`;
2196
- default: return `(e=>e?.addEventListener("${trigger.type.slice(3)}",l,{once:1}))(document.querySelector(${JSON.stringify(trigger.selector)})||l())`;
2218
+ default: return `(e=>e?.addEventListener("${trigger.type.slice(3)}",l,{once:1}))(${querySelectorOrLoad(trigger.selector)})`;
2197
2219
  }
2198
2220
  });
2199
2221
  writeScript(`((p,h,d,l=$=>{d||p.after(new Range().createContextualFragment(d=h))})=>${exprs.length > 1 ? `{${exprs.join(";")}}` : exprs[0]})(document.currentScript,${htmlStr})`);
2200
2222
  }
2223
+ function querySelectorOrLoad(selector) {
2224
+ return `document.querySelector(${JSON.stringify(selector)})||l()`;
2225
+ }
2201
2226
  function toObjectExpression(options) {
2202
2227
  let result = "{", sep = "";
2203
2228
  for (let key in options) Object.hasOwn(options, key) && (result += sep + toObjectKey(key) + ":" + JSON.stringify(options[key]), sep = ",");