marko 6.3.19 → 6.3.21

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 (64) hide show
  1. package/cheatsheet.md +29 -3
  2. package/dist/common/accessor.d.ts +21 -75
  3. package/dist/common/accessor.debug.d.ts +21 -75
  4. package/dist/common/constants/accessor-prefix.d.ts +16 -0
  5. package/dist/common/constants/accessor-prefix.debug.d.ts +16 -0
  6. package/dist/common/constants/accessor-prop.d.ts +30 -0
  7. package/dist/common/constants/accessor-prop.debug.d.ts +30 -0
  8. package/dist/common/constants/closure-signal-prop.d.ts +6 -0
  9. package/dist/common/constants/closure-signal-prop.debug.d.ts +6 -0
  10. package/dist/common/constants/controlled-type.d.ts +9 -0
  11. package/dist/common/constants/keyed-scopes-prop.d.ts +4 -0
  12. package/dist/common/constants/keyed-scopes-prop.debug.d.ts +4 -0
  13. package/dist/common/constants/load-signal-value.d.ts +5 -0
  14. package/dist/common/constants/load-signal-value.debug.d.ts +5 -0
  15. package/dist/common/constants/node-type.d.ts +7 -0
  16. package/dist/common/constants/pending-render-prop.d.ts +9 -0
  17. package/dist/common/constants/pending-render-prop.debug.d.ts +9 -0
  18. package/dist/common/constants/renderer-prop.d.ts +12 -0
  19. package/dist/common/constants/renderer-prop.debug.d.ts +12 -0
  20. package/dist/common/constants/resume-symbol.d.ts +10 -0
  21. package/dist/common/constants/walk-code.d.ts +17 -0
  22. package/dist/common/constants/walk-range-size.d.ts +7 -0
  23. package/dist/common/types.d.ts +15 -45
  24. package/dist/debug/dom.js +291 -225
  25. package/dist/debug/dom.mjs +291 -225
  26. package/dist/debug/html.js +189 -42
  27. package/dist/debug/html.mjs +189 -42
  28. package/dist/dom/compat.d.ts +1 -1
  29. package/dist/dom/control-flow.d.ts +1 -1
  30. package/dist/dom/renderer.d.ts +2 -2
  31. package/dist/dom/scope.d.ts +1 -1
  32. package/dist/dom.js +8 -6
  33. package/dist/dom.mjs +8 -6
  34. package/dist/html/constants/char.d.ts +11 -0
  35. package/dist/html/constants/flush-status.d.ts +6 -0
  36. package/dist/html/constants/mark.d.ts +6 -0
  37. package/dist/html/constants/runtime-key.d.ts +7 -0
  38. package/dist/html/writer.d.ts +19 -23
  39. package/dist/html.js +128 -29
  40. package/dist/html.mjs +128 -29
  41. package/dist/translator/core/if.d.ts +7 -7
  42. package/dist/translator/core/index.d.ts +7 -7
  43. package/dist/translator/index.d.ts +9 -9
  44. package/dist/translator/index.js +191 -133
  45. package/dist/translator/interop/constants/feature-type.d.ts +5 -0
  46. package/dist/translator/interop/index.d.ts +2 -2
  47. package/dist/translator/util/body-to-text-literal.d.ts +2 -2
  48. package/dist/translator/util/constants/binding-type.d.ts +10 -0
  49. package/dist/translator/util/constants/compile-stage.d.ts +8 -0
  50. package/dist/translator/util/constants/content-type.d.ts +8 -0
  51. package/dist/translator/util/constants/step.d.ts +5 -0
  52. package/dist/translator/util/constants/tag-name-type.d.ts +7 -0
  53. package/dist/translator/util/is-static.d.ts +1 -1
  54. package/dist/translator/util/references.d.ts +5 -12
  55. package/dist/translator/util/sections.d.ts +4 -8
  56. package/dist/translator/util/signals.d.ts +1 -0
  57. package/dist/translator/util/tag-name-type.d.ts +4 -7
  58. package/dist/translator/util/walks.d.ts +4 -6
  59. package/dist/translator/visitors/constants/sibling-text.d.ts +7 -0
  60. package/dist/translator/visitors/placeholder.d.ts +2 -6
  61. package/dist/translator/visitors/tag/constants/class-hydration.d.ts +5 -0
  62. package/dist/translator/visitors/tag/dynamic-tag.d.ts +2 -4
  63. package/package.json +16 -16
  64. package/tags-html.d.ts +98 -22
@@ -1,6 +1,8 @@
1
1
  import { _hoist_read_error } from "../common/errors";
2
2
  import { type Opt } from "../common/opt";
3
3
  import { type $Global, type Accessor, type Falsy, ResumeSymbol } from "../common/types";
4
+ import * as FlushStatus from "./constants/flush-status";
5
+ import * as Mark from "./constants/mark";
4
6
  import { K_SCOPE_ID, Serializer } from "./serializer";
5
7
  import type { ServerRenderer } from "./template";
6
8
  export type PartialScope = Record<Accessor, unknown>;
@@ -73,16 +75,9 @@ export declare function _try(scopeId: number, accessor: Accessor, content: () =>
73
75
  content?(err: unknown): void;
74
76
  };
75
77
  }): void;
76
- declare enum Mark {
77
- Placeholder = "!^",
78
- PlaceholderEnd = "!",
79
- ReorderMarker = "#"
80
- }
78
+ declare const NOOP: () => void;
79
+ type Mark = Mark.Value;
81
80
  export declare class State implements SerializeState {
82
- $global: $Global & {
83
- renderId: string;
84
- runtimeId: string;
85
- };
86
81
  tagId: number;
87
82
  scopeId: number;
88
83
  reorderId: number;
@@ -104,6 +99,10 @@ export declare class State implements SerializeState {
104
99
  writeScopes: Record<number, PartialScope>;
105
100
  readyIds: Set<string> | null;
106
101
  serializeReason: SerializeReasonValue;
102
+ $global: $Global & {
103
+ renderId: string;
104
+ runtimeId: string;
105
+ };
107
106
  constructor($global: $Global & {
108
107
  renderId: string;
109
108
  runtimeId: string;
@@ -116,26 +115,19 @@ export declare class State implements SerializeState {
116
115
  nextReorderId(): string;
117
116
  mark(code: ResumeSymbol | Mark, str: string): string;
118
117
  }
119
- export declare enum FlushStatus {
120
- complete = 0,
121
- continue = 1,
122
- aborted = 2
123
- }
118
+ type FlushStatus = FlushStatus.Value;
119
+ export { FlushStatus };
124
120
  export declare class Boundary extends AbortController {
125
- state: State;
126
- parent?: Boundary | undefined;
127
- onNext: () => void;
121
+ onNext: typeof NOOP;
128
122
  count: number;
129
- constructor(state: State, signal?: AbortSignal, parent?: Boundary | undefined);
130
- flush(): FlushStatus;
123
+ state: State;
124
+ parent?: Boundary;
125
+ constructor(state: State, signal?: AbortSignal, parent?: Boundary);
126
+ flush(): 0 | 1 | 2;
131
127
  startAsync(): void;
132
128
  endAsync(): void;
133
129
  }
134
130
  export declare class Chunk {
135
- boundary: Boundary;
136
- next: Chunk | null;
137
- context: Record<string | symbol, unknown> | null;
138
- serializeState: SerializeState;
139
131
  html: string;
140
132
  scripts: string;
141
133
  effects: string;
@@ -150,6 +142,10 @@ export declare class Chunk {
150
142
  render: () => void;
151
143
  branchId: number;
152
144
  } | null;
145
+ boundary: Boundary;
146
+ next: Chunk | null;
147
+ context: Record<string | symbol, unknown> | null;
148
+ serializeState: SerializeState;
153
149
  constructor(boundary: Boundary, next: Chunk | null, context: Record<string | symbol, unknown> | null, serializeState: SerializeState);
154
150
  fork(boundary: Boundary, next: Chunk | null): Chunk;
155
151
  writeHTML(html: string): void;
package/dist/html.js CHANGED
@@ -332,7 +332,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
332
332
  return new Chunk(boundary, null, null, state).flushScript().scripts;
333
333
  },
334
334
  render(renderer, willRerender, classAPIOut, component, input, completeChunks, registerChildScope) {
335
- let state = this.ensureState(classAPIOut.global), boundary = new Boundary(state), head = new Chunk(boundary, null, null, state), normalizedInput = input;
335
+ let state = this.ensureState(classAPIOut.global), boundary = new Boundary(state), head = new Chunk(boundary, null, getChunk()?.context ?? null, state), normalizedInput = input;
336
336
  if ("renderBody" in input) {
337
337
  normalizedInput = {};
338
338
  for (let key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
@@ -455,14 +455,15 @@ var State$1 = class {
455
455
  channelDeps = null;
456
456
  mutated = [];
457
457
  }, Reference = class {
458
+ assigns = null;
459
+ calls = null;
460
+ scopeId = void 0;
461
+ channel = void 0;
458
462
  parent;
459
463
  accessor;
460
464
  flush;
461
465
  pos;
462
466
  id;
463
- assigns = null;
464
- scopeId = void 0;
465
- channel = void 0;
466
467
  constructor(parent, accessor, flush, pos = null, id = null) {
467
468
  this.parent = parent, this.accessor = accessor, this.flush = flush, this.pos = pos, this.id = id;
468
469
  }
@@ -527,9 +528,20 @@ function writeScopesRoot(state, flushes) {
527
528
  function writeAssigned(state) {
528
529
  let sep = state.buf.length ? "," : "";
529
530
  if (state.assigned.size) {
530
- let buf = "";
531
- for (let ref of state.assigned) buf += sep + assignsToString(ref.assigns, ref.id), ref.assigns = null, sep = ",";
532
- state.buf.push(buf), state.assigned = /* @__PURE__ */ new Set();
531
+ let assigned = state.assigned;
532
+ state.assigned = /* @__PURE__ */ new Set();
533
+ let buf = "", hasCalls = !1;
534
+ for (let ref of assigned) ref.assigns && (buf += sep + assignsToString(ref.assigns, ref.id), ref.assigns = null, sep = ","), hasCalls ||= ref.calls !== null;
535
+ if (buf && state.buf.push(buf), hasCalls) {
536
+ for (let ref of assigned) if (ref.calls) {
537
+ for (let { method, args } of ref.calls) {
538
+ state.buf.push((state.buf.length ? "," : "") + ref.id + "." + method + "(");
539
+ for (let a = 0; a < args.length; a++) a && state.buf.push(","), writeCallArg(state, args[a]);
540
+ state.buf.push(")");
541
+ }
542
+ ref.calls = null;
543
+ }
544
+ }
533
545
  }
534
546
  if (hasChannelMutations(state)) {
535
547
  let remaining = [];
@@ -550,8 +562,12 @@ function writeAssigned(state) {
550
562
  } else state.buf.push("void 0");
551
563
  state.buf.push(")");
552
564
  }
553
- state.mutated = remaining, state.assigned.size && writeAssigned(state);
565
+ state.mutated = remaining;
554
566
  }
567
+ state.assigned.size && writeAssigned(state);
568
+ }
569
+ function writeCallArg(state, val) {
570
+ val === void 0 ? (state.wroteUndefined = !0, state.buf.push("$")) : writeProp(state, val, null, "") || state.buf.push("void 0");
555
571
  }
556
572
  function hasChannelMutations(state) {
557
573
  return hasMatchingMutations(state.mutated, state.channel?.readyId);
@@ -688,6 +704,7 @@ function writeUnknownObject(state, val, ref) {
688
704
  case Float64Array:
689
705
  case BigInt64Array:
690
706
  case BigUint64Array: return writeTypedArray(state, val, ref);
707
+ case DataView: return writeDataView(state, val, ref);
691
708
  case WeakSet: return writeWeakSet(state);
692
709
  case WeakMap: return writeWeakMap(state);
693
710
  case globalThis.URL: return writeURL(state, val);
@@ -697,6 +714,24 @@ function writeUnknownObject(state, val, ref) {
697
714
  case globalThis.ReadableStream: return writeReadableStream(state, val, ref);
698
715
  case globalThis.Request: return writeRequest(state, val, ref);
699
716
  case globalThis.Response: return writeResponse(state, val, ref);
717
+ case globalThis.Intl?.NumberFormat: return writeIntl(state, val, "NumberFormat", ref);
718
+ case globalThis.Intl?.DateTimeFormat: return writeIntl(state, val, "DateTimeFormat", ref);
719
+ case globalThis.Intl?.Collator: return writeIntl(state, val, "Collator", ref);
720
+ case globalThis.Intl?.PluralRules: return writeIntl(state, val, "PluralRules", ref);
721
+ case globalThis.Intl?.RelativeTimeFormat: return writeIntl(state, val, "RelativeTimeFormat", ref);
722
+ case globalThis.Intl?.ListFormat: return writeIntl(state, val, "ListFormat", ref);
723
+ case globalThis.Intl?.DisplayNames: return writeIntl(state, val, "DisplayNames", ref);
724
+ case globalThis.Intl?.Segmenter: return writeIntl(state, val, "Segmenter", ref);
725
+ case globalThis.Intl?.DurationFormat: return writeIntl(state, val, "DurationFormat", ref);
726
+ case globalThis.Intl?.Locale: return writeIntlLocale(state, val);
727
+ case globalThis.Temporal?.Instant: return writeTemporal(state, val, "Instant");
728
+ case globalThis.Temporal?.Duration: return writeTemporal(state, val, "Duration");
729
+ case globalThis.Temporal?.PlainDate: return writeTemporal(state, val, "PlainDate");
730
+ case globalThis.Temporal?.PlainDateTime: return writeTemporal(state, val, "PlainDateTime");
731
+ case globalThis.Temporal?.PlainMonthDay: return writeTemporal(state, val, "PlainMonthDay");
732
+ case globalThis.Temporal?.PlainTime: return writeTemporal(state, val, "PlainTime");
733
+ case globalThis.Temporal?.PlainYearMonth: return writeTemporal(state, val, "PlainYearMonth");
734
+ case globalThis.Temporal?.ZonedDateTime: return writeTemporal(state, val, "ZonedDateTime");
700
735
  }
701
736
  return !1;
702
737
  }
@@ -730,22 +765,51 @@ function newAsyncHandle(state, parent, id) {
730
765
  }
731
766
  function writeMap(state, val, ref) {
732
767
  if (!val.size) return state.buf.push("new Map"), !0;
733
- let items = [], assigns, needsId, i = 0;
768
+ let items = [], assigns, needsId, deferring = !1, i = 0;
734
769
  if (val.size < 25) {
735
- for (let [itemKey, itemValue] of val) 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]);
770
+ for (let [itemKey, itemValue] of val) {
771
+ if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
772
+ deferCall(state, ref, "set", [itemKey, itemValue]);
773
+ continue;
774
+ }
775
+ 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]);
776
+ }
736
777
  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);
737
778
  } else {
738
- for (let [itemKey, itemValue] of val) 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);
779
+ for (let [itemKey, itemValue] of val) {
780
+ if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
781
+ deferCall(state, ref, "set", [itemKey, itemValue]);
782
+ continue;
783
+ }
784
+ 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);
785
+ }
739
786
  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);
740
787
  }
741
788
  return !0;
742
789
  }
743
790
  function writeSet(state, val, ref) {
744
791
  if (!val.size) return state.buf.push("new Set"), !0;
745
- let items = [], assigns, needsId, i = 0;
746
- for (let item of val) item === val ? (item = 0, (assigns ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
792
+ let items = [], assigns, needsId, deferring = !1, i = 0;
793
+ for (let item of val) {
794
+ if (!deferring && item !== val && isAncestorMember(state, ref, item) && (deferring = !0), deferring) {
795
+ deferCall(state, ref, "add", [item]);
796
+ continue;
797
+ }
798
+ item === val ? (item = 0, (assigns ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
799
+ }
747
800
  return writeArrayArg(state, ref, items, assigns && "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId), !0;
748
801
  }
802
+ function isAncestorMember(state, container, member) {
803
+ if (member === null || typeof member != "object" && typeof member != "function") return !1;
804
+ let ref = state.refs.get(member);
805
+ return ref !== void 0 && isCircular(container, ref);
806
+ }
807
+ function deferCall(state, ref, method, args) {
808
+ ensureId(state, ref), (ref.calls ||= []).push({
809
+ method,
810
+ args
811
+ }), state.assigned.add(ref);
812
+ }
749
813
  function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
750
814
  if (assignsPrefix || needsId) {
751
815
  let arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
@@ -762,6 +826,15 @@ function isDedupedMember(val) {
762
826
  default: return !1;
763
827
  }
764
828
  }
829
+ function canWriteBuffer(state, buffer, ref) {
830
+ return Object.getPrototypeOf(buffer)?.constructor === ArrayBuffer;
831
+ }
832
+ function writeDataView(state, val, ref) {
833
+ let { buffer } = val;
834
+ if (!canWriteBuffer(state, buffer, ref)) return !1;
835
+ let needsLength = val.byteOffset + val.byteLength < buffer.byteLength;
836
+ return state.buf.push("new DataView("), writeProp(state, buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.byteLength : "") : "") + ")"), !0;
837
+ }
765
838
  function writeArrayBuffer(state, val) {
766
839
  let result;
767
840
  if (val.byteLength) {
@@ -772,6 +845,7 @@ function writeArrayBuffer(state, val) {
772
845
  }
773
846
  function writeTypedArray(state, val, ref) {
774
847
  if (val.byteOffset || val.byteLength < val.buffer.byteLength || state.refs.has(val.buffer)) {
848
+ if (!canWriteBuffer(state, val.buffer, ref)) return !1;
775
849
  let needsLength = val.byteOffset + val.byteLength < val.buffer.byteLength;
776
850
  state.buf.push("new " + val.constructor.name + "("), writeProp(state, val.buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
777
851
  } 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)) + ")"));
@@ -845,6 +919,22 @@ function writeResponse(state, val, ref) {
845
919
  }
846
920
  return !val.body || val.bodyUsed ? state.buf.push("new Response" + (options ? "(null,{" + options + "})" : "")) : (state.buf.push("new Response("), state.buf.push((writeProp(state, val.body, ref, "body") ? "" : "null") + (options ? ",{" + options + "})" : ")"))), !0;
847
921
  }
922
+ function writeIntl(state, val, name, ref) {
923
+ let { locale, ...options } = val.resolvedOptions(), needsId = !1;
924
+ for (let key in options) if (isDedupedMember(options[key])) {
925
+ needsId = !0;
926
+ break;
927
+ }
928
+ state.buf.push("new Intl." + name + "(" + quote(locale, 0) + ",");
929
+ let optionsRef;
930
+ 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;
931
+ }
932
+ function writeIntlLocale(state, val) {
933
+ return state.buf.push("new Intl.Locale(" + quote(val.toString(), 0) + ")"), !0;
934
+ }
935
+ function writeTemporal(state, val, name) {
936
+ return state.buf.push("Temporal." + name + ".from(" + quote(val.toString(), 0) + ")"), !0;
937
+ }
848
938
  function writeReadableStream(state, val, ref) {
849
939
  let { boundary, channel } = state;
850
940
  if (!boundary || val.locked) return !1;
@@ -1420,7 +1510,6 @@ function tryCatch(content, catchContent) {
1420
1510
  };
1421
1511
  }
1422
1512
  var State = class {
1423
- $global;
1424
1513
  tagId = 1;
1425
1514
  scopeId = 1;
1426
1515
  reorderId = 1;
@@ -1442,6 +1531,7 @@ var State = class {
1442
1531
  writeScopes = {};
1443
1532
  readyIds = null;
1444
1533
  serializeReason;
1534
+ $global;
1445
1535
  constructor($global) {
1446
1536
  this.$global = $global, $global.cspNonce && (this.nonceAttr = " nonce" + attrAssignment($global.cspNonce));
1447
1537
  }
@@ -1472,10 +1562,10 @@ var State = class {
1472
1562
  return "<!--" + this.commentPrefix + code + str + "-->";
1473
1563
  }
1474
1564
  }, Boundary = class extends AbortController {
1475
- state;
1476
- parent;
1477
1565
  onNext = NOOP$2;
1478
1566
  count = 0;
1567
+ state;
1568
+ parent;
1479
1569
  constructor(state, signal, parent) {
1480
1570
  super(), this.state = state, this.parent = parent, this.signal.addEventListener("abort", () => {
1481
1571
  this.count = 0, this.state = new State(this.state.$global), this.onNext();
@@ -1493,10 +1583,6 @@ var State = class {
1493
1583
  !this.signal.aborted && this.count && (this.count--, this.onNext());
1494
1584
  }
1495
1585
  }, Chunk = class Chunk {
1496
- boundary;
1497
- next;
1498
- context;
1499
- serializeState;
1500
1586
  html = "";
1501
1587
  scripts = "";
1502
1588
  effects = "";
@@ -1507,6 +1593,10 @@ var State = class {
1507
1593
  reorderId = null;
1508
1594
  deferredReady = null;
1509
1595
  placeholder = null;
1596
+ boundary;
1597
+ next;
1598
+ context;
1599
+ serializeState;
1510
1600
  constructor(boundary, next, context, serializeState) {
1511
1601
  this.boundary = boundary, this.next = next, this.context = context, this.serializeState = serializeState;
1512
1602
  }
@@ -1901,17 +1991,26 @@ var ServerRendered = class {
1901
1991
  }
1902
1992
  [Symbol.asyncIterator]() {
1903
1993
  let resolve, reject, value = "", done = !1, aborted = !1, reason, boundary = this.#read((html) => {
1904
- value += html, resolve && (resolve({
1905
- value,
1906
- done
1907
- }), value = "");
1994
+ if (value += html, resolve) {
1995
+ let settle = resolve;
1996
+ resolve = reject = void 0, settle({
1997
+ value,
1998
+ done
1999
+ }), value = "";
2000
+ }
1908
2001
  }, (err) => {
1909
- aborted = !0, reason = err, reject && reject(err);
2002
+ if (aborted = !0, reason = err, reject) {
2003
+ let settle = reject;
2004
+ resolve = reject = void 0, settle(err);
2005
+ }
1910
2006
  }, () => {
1911
- done = !0, resolve && (resolve({
1912
- value,
1913
- done: !value
1914
- }), value = "");
2007
+ if (done = !0, resolve) {
2008
+ let settle = resolve;
2009
+ resolve = reject = void 0, settle({
2010
+ value,
2011
+ done: !value
2012
+ }), value = "";
2013
+ }
1915
2014
  });
1916
2015
  return {
1917
2016
  next() {
package/dist/html.mjs CHANGED
@@ -332,7 +332,7 @@ let empty = [], rest = Symbol(), unsafeStyleAttrReg = /[\\;]/g, replaceUnsafeSty
332
332
  return new Chunk(boundary, null, null, state).flushScript().scripts;
333
333
  },
334
334
  render(renderer, willRerender, classAPIOut, component, input, completeChunks, registerChildScope) {
335
- let state = this.ensureState(classAPIOut.global), boundary = new Boundary(state), head = new Chunk(boundary, null, null, state), normalizedInput = input;
335
+ let state = this.ensureState(classAPIOut.global), boundary = new Boundary(state), head = new Chunk(boundary, null, getChunk()?.context ?? null, state), normalizedInput = input;
336
336
  if ("renderBody" in input) {
337
337
  normalizedInput = {};
338
338
  for (let key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
@@ -454,14 +454,15 @@ var State$1 = class {
454
454
  channelDeps = null;
455
455
  mutated = [];
456
456
  }, Reference = class {
457
+ assigns = null;
458
+ calls = null;
459
+ scopeId = void 0;
460
+ channel = void 0;
457
461
  parent;
458
462
  accessor;
459
463
  flush;
460
464
  pos;
461
465
  id;
462
- assigns = null;
463
- scopeId = void 0;
464
- channel = void 0;
465
466
  constructor(parent, accessor, flush, pos = null, id = null) {
466
467
  this.parent = parent, this.accessor = accessor, this.flush = flush, this.pos = pos, this.id = id;
467
468
  }
@@ -526,9 +527,20 @@ function writeScopesRoot(state, flushes) {
526
527
  function writeAssigned(state) {
527
528
  let sep = state.buf.length ? "," : "";
528
529
  if (state.assigned.size) {
529
- let buf = "";
530
- for (let ref of state.assigned) buf += sep + assignsToString(ref.assigns, ref.id), ref.assigns = null, sep = ",";
531
- state.buf.push(buf), state.assigned = /* @__PURE__ */ new Set();
530
+ let assigned = state.assigned;
531
+ state.assigned = /* @__PURE__ */ new Set();
532
+ let buf = "", hasCalls = !1;
533
+ for (let ref of assigned) ref.assigns && (buf += sep + assignsToString(ref.assigns, ref.id), ref.assigns = null, sep = ","), hasCalls ||= ref.calls !== null;
534
+ if (buf && state.buf.push(buf), hasCalls) {
535
+ for (let ref of assigned) if (ref.calls) {
536
+ for (let { method, args } of ref.calls) {
537
+ state.buf.push((state.buf.length ? "," : "") + ref.id + "." + method + "(");
538
+ for (let a = 0; a < args.length; a++) a && state.buf.push(","), writeCallArg(state, args[a]);
539
+ state.buf.push(")");
540
+ }
541
+ ref.calls = null;
542
+ }
543
+ }
532
544
  }
533
545
  if (hasChannelMutations(state)) {
534
546
  let remaining = [];
@@ -549,8 +561,12 @@ function writeAssigned(state) {
549
561
  } else state.buf.push("void 0");
550
562
  state.buf.push(")");
551
563
  }
552
- state.mutated = remaining, state.assigned.size && writeAssigned(state);
564
+ state.mutated = remaining;
553
565
  }
566
+ state.assigned.size && writeAssigned(state);
567
+ }
568
+ function writeCallArg(state, val) {
569
+ val === void 0 ? (state.wroteUndefined = !0, state.buf.push("$")) : writeProp(state, val, null, "") || state.buf.push("void 0");
554
570
  }
555
571
  function hasChannelMutations(state) {
556
572
  return hasMatchingMutations(state.mutated, state.channel?.readyId);
@@ -687,6 +703,7 @@ function writeUnknownObject(state, val, ref) {
687
703
  case Float64Array:
688
704
  case BigInt64Array:
689
705
  case BigUint64Array: return writeTypedArray(state, val, ref);
706
+ case DataView: return writeDataView(state, val, ref);
690
707
  case WeakSet: return writeWeakSet(state);
691
708
  case WeakMap: return writeWeakMap(state);
692
709
  case globalThis.URL: return writeURL(state, val);
@@ -696,6 +713,24 @@ function writeUnknownObject(state, val, ref) {
696
713
  case globalThis.ReadableStream: return writeReadableStream(state, val, ref);
697
714
  case globalThis.Request: return writeRequest(state, val, ref);
698
715
  case globalThis.Response: return writeResponse(state, val, ref);
716
+ case globalThis.Intl?.NumberFormat: return writeIntl(state, val, "NumberFormat", ref);
717
+ case globalThis.Intl?.DateTimeFormat: return writeIntl(state, val, "DateTimeFormat", ref);
718
+ case globalThis.Intl?.Collator: return writeIntl(state, val, "Collator", ref);
719
+ case globalThis.Intl?.PluralRules: return writeIntl(state, val, "PluralRules", ref);
720
+ case globalThis.Intl?.RelativeTimeFormat: return writeIntl(state, val, "RelativeTimeFormat", ref);
721
+ case globalThis.Intl?.ListFormat: return writeIntl(state, val, "ListFormat", ref);
722
+ case globalThis.Intl?.DisplayNames: return writeIntl(state, val, "DisplayNames", ref);
723
+ case globalThis.Intl?.Segmenter: return writeIntl(state, val, "Segmenter", ref);
724
+ case globalThis.Intl?.DurationFormat: return writeIntl(state, val, "DurationFormat", ref);
725
+ case globalThis.Intl?.Locale: return writeIntlLocale(state, val);
726
+ case globalThis.Temporal?.Instant: return writeTemporal(state, val, "Instant");
727
+ case globalThis.Temporal?.Duration: return writeTemporal(state, val, "Duration");
728
+ case globalThis.Temporal?.PlainDate: return writeTemporal(state, val, "PlainDate");
729
+ case globalThis.Temporal?.PlainDateTime: return writeTemporal(state, val, "PlainDateTime");
730
+ case globalThis.Temporal?.PlainMonthDay: return writeTemporal(state, val, "PlainMonthDay");
731
+ case globalThis.Temporal?.PlainTime: return writeTemporal(state, val, "PlainTime");
732
+ case globalThis.Temporal?.PlainYearMonth: return writeTemporal(state, val, "PlainYearMonth");
733
+ case globalThis.Temporal?.ZonedDateTime: return writeTemporal(state, val, "ZonedDateTime");
699
734
  }
700
735
  return !1;
701
736
  }
@@ -729,22 +764,51 @@ function newAsyncHandle(state, parent, id) {
729
764
  }
730
765
  function writeMap(state, val, ref) {
731
766
  if (!val.size) return state.buf.push("new Map"), !0;
732
- let items = [], assigns, needsId, i = 0;
767
+ let items = [], assigns, needsId, deferring = !1, i = 0;
733
768
  if (val.size < 25) {
734
- for (let [itemKey, itemValue] of val) 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]);
769
+ for (let [itemKey, itemValue] of val) {
770
+ if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
771
+ deferCall(state, ref, "set", [itemKey, itemValue]);
772
+ continue;
773
+ }
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]);
775
+ }
735
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);
736
777
  } else {
737
- for (let [itemKey, itemValue] of val) 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);
778
+ for (let [itemKey, itemValue] of val) {
779
+ if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue)) && (deferring = !0), deferring) {
780
+ deferCall(state, ref, "set", [itemKey, itemValue]);
781
+ continue;
782
+ }
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);
784
+ }
738
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);
739
786
  }
740
787
  return !0;
741
788
  }
742
789
  function writeSet(state, val, ref) {
743
790
  if (!val.size) return state.buf.push("new Set"), !0;
744
- let items = [], assigns, needsId, i = 0;
745
- for (let item of val) item === val ? (item = 0, (assigns ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
791
+ let items = [], assigns, needsId, deferring = !1, i = 0;
792
+ for (let item of val) {
793
+ if (!deferring && item !== val && isAncestorMember(state, ref, item) && (deferring = !0), deferring) {
794
+ deferCall(state, ref, "add", [item]);
795
+ continue;
796
+ }
797
+ item === val ? (item = 0, (assigns ||= []).push("i[" + i + "]")) : needsId ||= isDedupedMember(item), i = items.push(item);
798
+ }
746
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;
747
800
  }
801
+ function isAncestorMember(state, container, member) {
802
+ if (member === null || typeof member != "object" && typeof member != "function") return !1;
803
+ let ref = state.refs.get(member);
804
+ return ref !== void 0 && isCircular(container, ref);
805
+ }
806
+ function deferCall(state, ref, method, args) {
807
+ ensureId(state, ref), (ref.calls ||= []).push({
808
+ method,
809
+ args
810
+ }), state.assigned.add(ref);
811
+ }
748
812
  function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
749
813
  if (assignsPrefix || needsId) {
750
814
  let arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
@@ -761,6 +825,15 @@ function isDedupedMember(val) {
761
825
  default: return !1;
762
826
  }
763
827
  }
828
+ function canWriteBuffer(state, buffer, ref) {
829
+ return Object.getPrototypeOf(buffer)?.constructor === ArrayBuffer;
830
+ }
831
+ function writeDataView(state, val, ref) {
832
+ let { buffer } = val;
833
+ if (!canWriteBuffer(state, buffer, ref)) return !1;
834
+ let needsLength = val.byteOffset + val.byteLength < buffer.byteLength;
835
+ return state.buf.push("new DataView("), writeProp(state, buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.byteLength : "") : "") + ")"), !0;
836
+ }
764
837
  function writeArrayBuffer(state, val) {
765
838
  let result;
766
839
  if (val.byteLength) {
@@ -771,6 +844,7 @@ function writeArrayBuffer(state, val) {
771
844
  }
772
845
  function writeTypedArray(state, val, ref) {
773
846
  if (val.byteOffset || val.byteLength < val.buffer.byteLength || state.refs.has(val.buffer)) {
847
+ if (!canWriteBuffer(state, val.buffer, ref)) return !1;
774
848
  let needsLength = val.byteOffset + val.byteLength < val.buffer.byteLength;
775
849
  state.buf.push("new " + val.constructor.name + "("), writeProp(state, val.buffer, ref, "buffer"), state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
776
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)) + ")"));
@@ -844,6 +918,22 @@ function writeResponse(state, val, ref) {
844
918
  }
845
919
  return !val.body || val.bodyUsed ? state.buf.push("new Response" + (options ? "(null,{" + options + "})" : "")) : (state.buf.push("new Response("), state.buf.push((writeProp(state, val.body, ref, "body") ? "" : "null") + (options ? ",{" + options + "})" : ")"))), !0;
846
920
  }
921
+ function writeIntl(state, val, name, ref) {
922
+ let { locale, ...options } = val.resolvedOptions(), needsId = !1;
923
+ for (let key in options) if (isDedupedMember(options[key])) {
924
+ needsId = !0;
925
+ break;
926
+ }
927
+ state.buf.push("new Intl." + name + "(" + quote(locale, 0) + ",");
928
+ 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;
930
+ }
931
+ function writeIntlLocale(state, val) {
932
+ return state.buf.push("new Intl.Locale(" + quote(val.toString(), 0) + ")"), !0;
933
+ }
934
+ function writeTemporal(state, val, name) {
935
+ return state.buf.push("Temporal." + name + ".from(" + quote(val.toString(), 0) + ")"), !0;
936
+ }
847
937
  function writeReadableStream(state, val, ref) {
848
938
  let { boundary, channel } = state;
849
939
  if (!boundary || val.locked) return !1;
@@ -1419,7 +1509,6 @@ function tryCatch(content, catchContent) {
1419
1509
  };
1420
1510
  }
1421
1511
  var State = class {
1422
- $global;
1423
1512
  tagId = 1;
1424
1513
  scopeId = 1;
1425
1514
  reorderId = 1;
@@ -1441,6 +1530,7 @@ var State = class {
1441
1530
  writeScopes = {};
1442
1531
  readyIds = null;
1443
1532
  serializeReason;
1533
+ $global;
1444
1534
  constructor($global) {
1445
1535
  this.$global = $global, $global.cspNonce && (this.nonceAttr = " nonce" + attrAssignment($global.cspNonce));
1446
1536
  }
@@ -1471,10 +1561,10 @@ var State = class {
1471
1561
  return "<!--" + this.commentPrefix + code + str + "-->";
1472
1562
  }
1473
1563
  }, Boundary = class extends AbortController {
1474
- state;
1475
- parent;
1476
1564
  onNext = NOOP$2;
1477
1565
  count = 0;
1566
+ state;
1567
+ parent;
1478
1568
  constructor(state, signal, parent) {
1479
1569
  super(), this.state = state, this.parent = parent, this.signal.addEventListener("abort", () => {
1480
1570
  this.count = 0, this.state = new State(this.state.$global), this.onNext();
@@ -1492,10 +1582,6 @@ var State = class {
1492
1582
  !this.signal.aborted && this.count && (this.count--, this.onNext());
1493
1583
  }
1494
1584
  }, Chunk = class Chunk {
1495
- boundary;
1496
- next;
1497
- context;
1498
- serializeState;
1499
1585
  html = "";
1500
1586
  scripts = "";
1501
1587
  effects = "";
@@ -1506,6 +1592,10 @@ var State = class {
1506
1592
  reorderId = null;
1507
1593
  deferredReady = null;
1508
1594
  placeholder = null;
1595
+ boundary;
1596
+ next;
1597
+ context;
1598
+ serializeState;
1509
1599
  constructor(boundary, next, context, serializeState) {
1510
1600
  this.boundary = boundary, this.next = next, this.context = context, this.serializeState = serializeState;
1511
1601
  }
@@ -1900,17 +1990,26 @@ var ServerRendered = class {
1900
1990
  }
1901
1991
  [Symbol.asyncIterator]() {
1902
1992
  let resolve, reject, value = "", done = !1, aborted = !1, reason, boundary = this.#read((html) => {
1903
- value += html, resolve && (resolve({
1904
- value,
1905
- done
1906
- }), value = "");
1993
+ if (value += html, resolve) {
1994
+ let settle = resolve;
1995
+ resolve = reject = void 0, settle({
1996
+ value,
1997
+ done
1998
+ }), value = "";
1999
+ }
1907
2000
  }, (err) => {
1908
- aborted = !0, reason = err, reject && reject(err);
2001
+ if (aborted = !0, reason = err, reject) {
2002
+ let settle = reject;
2003
+ resolve = reject = void 0, settle(err);
2004
+ }
1909
2005
  }, () => {
1910
- done = !0, resolve && (resolve({
1911
- value,
1912
- done: !value
1913
- }), value = "");
2006
+ if (done = !0, resolve) {
2007
+ let settle = resolve;
2008
+ resolve = reject = void 0, settle({
2009
+ value,
2010
+ done: !value
2011
+ }), value = "";
2012
+ }
1914
2013
  });
1915
2014
  return {
1916
2015
  next() {