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
@@ -35,6 +35,7 @@ const LoopKey = "#LoopKey";
35
35
  const PlaceholderContent = "#PlaceholderContent";
36
36
  const Renderer = "#Renderer";
37
37
  const TagVariable = "#TagVariable";
38
+ const Owner = "owner";
38
39
  const Embed = "embed";
39
40
  //#endregion
40
41
  //#region src/common/helpers.ts
@@ -85,6 +86,7 @@ function stringifyStyleObject(name, value) {
85
86
  warnedStyleKeys.add(name);
86
87
  console.warn(`\`${name}\` is not a CSS property name; \`style\` object keys are written verbatim, so it renders as invalid CSS. Use \`${name.replace(/[A-Z]/g, (m) => "-" + m.toLowerCase()).replace(/^ms-/, "-ms-")}\`.`);
87
88
  }
89
+ if (value !== value || typeof value === "bigint" && !value) console.warn(`The \`${name}\` style value \`${value !== value ? "NaN" : "0n"}\` drops the declaration; convert it to a string or number to render it.`);
88
90
  return value || value === 0 ? escapeStyleAttr(name) + ":" + escapeStyleAttr(value + "") : "";
89
91
  }
90
92
  const unsafeStyleAttrReg = /[\\;]/g;
@@ -159,6 +161,13 @@ function assertValidAttrValue(name, value) {
159
161
  function assertValidTextValue(value) {
160
162
  const unrenderable = describeUnrenderable(value);
161
163
  if (unrenderable) throw new Error(`Text content cannot be ${unrenderable}.`);
164
+ if (isSilentlyDropped(value)) console.warn(`Text content of \`${describeDropped(value)}\` renders as nothing; convert it to a string or number to render it.`);
165
+ }
166
+ function isSilentlyDropped(value) {
167
+ return value !== value || typeof value === "bigint" && !value;
168
+ }
169
+ function describeDropped(value) {
170
+ return value !== value ? "NaN" : "0n";
162
171
  }
163
172
  function describeUnrenderable(value) {
164
173
  if (typeof value === "symbol") return "a symbol";
@@ -182,6 +191,9 @@ function assertValidLoopKey(key, seenKeys) {
182
191
  function assertValidList(value) {
183
192
  if (value && typeof value[Symbol.iterator] !== "function") throw new Error(`A \`<for>\` tag's \`of\` attribute must be an iterable, such as an array, but received ${describeForValue(value)}.`);
184
193
  }
194
+ function assertValidRangeStart(name, value) {
195
+ if (value && (typeof value !== "number" || !isFinite(value))) throw new Error(`A \`<for>\` tag's \`${name}\` attribute must be a finite number, but received ${describeForValue(value)}.`);
196
+ }
185
197
  function assertValidRangeBound(name, value) {
186
198
  if (!isFinite(value)) throw new Error(`A \`<for>\` tag's \`${name}\` attribute must be a finite number, but received ${describeForValue(value)}.`);
187
199
  }
@@ -213,10 +225,16 @@ function assertExclusiveAttrs(attrs, onError = throwErr) {
213
225
  (exclusiveAttrs ||= []).push("checkedValueChange");
214
226
  if ("checked" in attrs) exclusiveAttrs.push("checked");
215
227
  }
216
- if (attrs.valueChange) (exclusiveAttrs ||= []).push("valueChange");
228
+ if (attrs.valueChange) {
229
+ (exclusiveAttrs ||= []).push("valueChange");
230
+ if ("checked" in attrs && !exclusiveAttrs.includes("checked")) exclusiveAttrs.push("checked");
231
+ }
217
232
  if (exclusiveAttrs && exclusiveAttrs.length > 1) onError(`The attributes ${joinWithAnd(exclusiveAttrs)} are mutually exclusive.`);
218
233
  }
219
234
  }
235
+ function assertNoValueBindingOnCheckable(type, valueChange) {
236
+ if (valueChange && /^(?:button|checkbox|hidden|image|radio|reset|submit)$/i.test(type)) console.error(`\`valueChange\` cannot be used on a \`type="${type}"\` \`<input>\` — user interaction can never change its \`value\`.` + (/^[cr]/i.test(type) ? " Bind `checked` or `checkedValue` instead." : ""));
237
+ }
220
238
  function assertHandlerIsFunction(name, value) {
221
239
  if (value && typeof value !== "function") throw new Error(`The \`${name}\` handler must be a function or a falsey value (\`null\`, \`undefined\`, \`false\`, \`0\`, …), but received type "${typeof value}".`);
222
240
  }
@@ -247,8 +265,8 @@ function _unescaped(val) {
247
265
  assertValidTextValue(val);
248
266
  return val ? val + "" : val === 0 ? "0" : "";
249
267
  }
250
- const unsafeXMLReg = /[<&]/g;
251
- const replaceUnsafeXML = (c) => c === "&" ? "&amp;" : "&lt;";
268
+ const unsafeXMLReg = /[<&\r]/g;
269
+ const replaceUnsafeXML = (c) => c === "&" ? "&amp;" : c === "<" ? "&lt;" : "&#13;";
252
270
  const escapeXMLStr = (str) => unsafeXMLReg.test(str) ? str.replace(unsafeXMLReg, replaceUnsafeXML) : str;
253
271
  function _escape(val) {
254
272
  assertValidTextValue(val);
@@ -527,31 +545,31 @@ const KNOWN_OBJECTS = /* @__PURE__ */ new Map([
527
545
  ]);
528
546
  var State$1 = class {
529
547
  ids = 0;
530
- flush = 0;
548
+ flushId = 0;
531
549
  wroteUndefined = false;
532
550
  buf = [];
533
551
  strs = /* @__PURE__ */ new Map();
534
552
  refs = /* @__PURE__ */ new WeakMap();
535
- assigned = /* @__PURE__ */ new Set();
553
+ pendingAssignments = /* @__PURE__ */ new Set();
536
554
  boundary = void 0;
537
555
  channel = void 0;
538
556
  channelDeps = null;
539
557
  mutated = [];
540
558
  };
541
559
  var Reference = class {
542
- assigns = null;
560
+ assignments = null;
543
561
  calls = null;
544
562
  scopeId = void 0;
545
563
  channel = void 0;
546
564
  parent;
547
565
  accessor;
548
- flush;
566
+ flushId;
549
567
  pos;
550
568
  id;
551
- constructor(parent, accessor, flush, pos = null, id = null) {
569
+ constructor(parent, accessor, flushId, pos = null, id = null) {
552
570
  this.parent = parent;
553
571
  this.accessor = accessor;
554
- this.flush = flush;
572
+ this.flushId = flushId;
555
573
  this.pos = pos;
556
574
  this.id = id;
557
575
  }
@@ -561,7 +579,18 @@ function setDebugInfo(obj, file, loc, vars) {
561
579
  DEBUG.set(obj, {
562
580
  file,
563
581
  loc,
564
- vars
582
+ vars,
583
+ slots: DEBUG.get(obj)?.slots
584
+ });
585
+ }
586
+ function setDebugSlotName(obj, accessor, name) {
587
+ const debug = DEBUG.get(obj);
588
+ if (debug) (debug.slots ??= {})[accessor] = name;
589
+ else DEBUG.set(obj, {
590
+ file: "",
591
+ loc: 0,
592
+ vars: void 0,
593
+ slots: { [accessor]: name }
565
594
  });
566
595
  }
567
596
  var Serializer = class {
@@ -578,7 +607,7 @@ var Serializer = class {
578
607
  this.#state.channel = channel;
579
608
  return writeScopesRoot(this.#state, flushes);
580
609
  } finally {
581
- this.#state.flush++;
610
+ this.#state.flushId++;
582
611
  this.#state.buf = [];
583
612
  }
584
613
  }
@@ -632,7 +661,7 @@ function writeScopesRoot(state, flushes) {
632
661
  }
633
662
  if (nextSlotId !== -1) buf.push("]");
634
663
  let extras = "";
635
- if (state.assigned.size || hasChannelMutations(state)) {
664
+ if (state.pendingAssignments.size || hasChannelMutations(state)) {
636
665
  extras = ",0)";
637
666
  if (fillIndex !== -1) {
638
667
  buf[fillIndex] = "_(" + buf[fillIndex];
@@ -651,21 +680,21 @@ function writeScopesRoot(state, flushes) {
651
680
  }
652
681
  function writeAssigned(state) {
653
682
  let sep = state.buf.length ? "," : "";
654
- if (state.assigned.size) {
655
- const assigned = state.assigned;
656
- state.assigned = /* @__PURE__ */ new Set();
683
+ if (state.pendingAssignments.size) {
684
+ const pending = state.pendingAssignments;
685
+ state.pendingAssignments = /* @__PURE__ */ new Set();
657
686
  let buf = "";
658
687
  let hasCalls = false;
659
- for (const ref of assigned) {
660
- if (ref.assigns) {
661
- buf += sep + assignsToString(ref.assigns, ref.id);
662
- ref.assigns = null;
688
+ for (const ref of pending) {
689
+ if (ref.assignments) {
690
+ buf += sep + assignmentsToString(ref.assignments, ref.id);
691
+ ref.assignments = null;
663
692
  sep = ",";
664
693
  }
665
694
  hasCalls ||= ref.calls !== null;
666
695
  }
667
696
  if (buf) state.buf.push(buf);
668
- if (hasCalls) for (const ref of assigned) {
697
+ if (hasCalls) for (const ref of pending) {
669
698
  if (!ref.calls) continue;
670
699
  for (const { method, args } of ref.calls) {
671
700
  state.buf.push((state.buf.length ? "," : "") + ref.id + "." + method + "(");
@@ -712,13 +741,16 @@ function writeAssigned(state) {
712
741
  }
713
742
  state.mutated = remaining;
714
743
  }
715
- if (state.assigned.size) writeAssigned(state);
744
+ if (state.pendingAssignments.size) writeAssigned(state);
716
745
  }
717
746
  function writeCallArg(state, val) {
718
747
  if (val === void 0) {
719
748
  state.wroteUndefined = true;
720
749
  state.buf.push("$");
721
- } else if (!writeProp(state, val, null, "")) state.buf.push("void 0");
750
+ } else if (writeProp(state, val, null, "")) {
751
+ const ref = state.refs.get(val) || state.strs.get(val);
752
+ if (ref && ref.id === null) assignId(state, ref);
753
+ } else state.buf.push("void 0");
722
754
  }
723
755
  function hasChannelMutations(state) {
724
756
  return hasMatchingMutations(state.mutated, state.channel?.readyId);
@@ -753,7 +785,7 @@ function writeReferenceOr(state, write, val, parent, accessor) {
753
785
  }
754
786
  if (parent && isCircular(parent, ref)) {
755
787
  ensureId(state, ref);
756
- state.assigned.add(ref);
788
+ state.pendingAssignments.add(ref);
757
789
  addAssignment(ref, accessId(state, parent) + toAccess(accessor));
758
790
  return false;
759
791
  }
@@ -762,7 +794,7 @@ function writeReferenceOr(state, write, val, parent, accessor) {
762
794
  }
763
795
  const registered = REGISTRY.get(val);
764
796
  if (registered) return writeRegistered(state, val, parent, accessor, registered);
765
- state.refs.set(val, ref = new Reference(parent, accessor, state.flush, state.buf.length));
797
+ state.refs.set(val, ref = new Reference(parent, accessor, state.flushId, state.buf.length));
766
798
  ref.channel = state.channel;
767
799
  ref.debug = DEBUG.get(val);
768
800
  if (write(state, val, ref)) return true;
@@ -775,7 +807,7 @@ function trackScope(state, val, scopeId) {
775
807
  else newScopeReference(state, val, scopeId);
776
808
  }
777
809
  function newScopeReference(state, val, scopeId) {
778
- const ref = new Reference(null, null, state.flush);
810
+ const ref = new Reference(null, null, state.flushId);
779
811
  ref.scopeId = scopeId;
780
812
  ref.channel = state.channel;
781
813
  state.refs.set(val, ref);
@@ -785,7 +817,7 @@ function newScopeReference(state, val, scopeId) {
785
817
  function writeRegistered(state, val, parent, accessor, registered) {
786
818
  const { scope } = registered;
787
819
  if (scope) {
788
- const ref = new Reference(parent, accessor, state.flush, state.buf.length);
820
+ const ref = new Reference(parent, accessor, state.flushId, state.buf.length);
789
821
  ref.channel = state.channel;
790
822
  state.refs.set(val, ref);
791
823
  ref.debug = DEBUG.get(val);
@@ -805,7 +837,7 @@ function writeString(state, val, parent, accessor) {
805
837
  return true;
806
838
  }
807
839
  } else {
808
- const ref = new Reference(parent, accessor, state.flush, state.buf.length);
840
+ const ref = new Reference(parent, accessor, state.flushId, state.buf.length);
809
841
  ref.channel = state.channel;
810
842
  state.strs.set(val, ref);
811
843
  }
@@ -991,7 +1023,7 @@ function writePromise(state, val, ref) {
991
1023
  }
992
1024
  function newAsyncHandle(state, parent, id) {
993
1025
  const handle = {};
994
- const handleRef = new Reference(parent, null, state.flush, null, id);
1026
+ const handleRef = new Reference(parent, null, state.flushId, null, id);
995
1027
  handleRef.channel = state.channel;
996
1028
  state.refs.set(handle, handleRef);
997
1029
  return handle;
@@ -1002,7 +1034,7 @@ function writeMap(state, val, ref) {
1002
1034
  return true;
1003
1035
  }
1004
1036
  const items = [];
1005
- let assigns;
1037
+ let assignments;
1006
1038
  let needsId;
1007
1039
  let deferring = false;
1008
1040
  let i = 0;
@@ -1015,16 +1047,16 @@ function writeMap(state, val, ref) {
1015
1047
  }
1016
1048
  if (itemKey === val) {
1017
1049
  itemKey = void 0;
1018
- (assigns ||= []).push("a[" + i + "][0]");
1050
+ (assignments ||= []).push("a[" + i + "][0]");
1019
1051
  }
1020
1052
  if (itemValue === val) {
1021
1053
  itemValue = void 0;
1022
- (assigns ||= []).push("a[" + i + "][1]");
1054
+ (assignments ||= []).push("a[" + i + "][1]");
1023
1055
  }
1024
1056
  needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
1025
1057
  i = items.push(itemValue === void 0 ? itemKey === void 0 ? [] : [itemKey] : [itemKey, itemValue]);
1026
1058
  }
1027
- 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);
1059
+ 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);
1028
1060
  } else {
1029
1061
  for (let [itemKey, itemValue] of val) {
1030
1062
  if (!deferring && (itemKey !== val && isAncestorMember(state, ref, itemKey) || itemValue !== val && isAncestorMember(state, ref, itemValue))) deferring = true;
@@ -1034,16 +1066,16 @@ function writeMap(state, val, ref) {
1034
1066
  }
1035
1067
  if (itemKey === val) {
1036
1068
  itemKey = 0;
1037
- (assigns ||= []).push("a[" + i + "]");
1069
+ (assignments ||= []).push("a[" + i + "]");
1038
1070
  }
1039
1071
  if (itemValue === val) {
1040
1072
  itemValue = 0;
1041
- (assigns ||= []).push("a[" + (i + 1) + "]");
1073
+ (assignments ||= []).push("a[" + (i + 1) + "]");
1042
1074
  }
1043
1075
  needsId ||= isDedupedMember(itemKey) || isDedupedMember(itemValue);
1044
1076
  i = items.push(itemKey, itemValue);
1045
1077
  }
1046
- 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);
1078
+ 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);
1047
1079
  }
1048
1080
  return true;
1049
1081
  }
@@ -1053,7 +1085,7 @@ function writeSet(state, val, ref) {
1053
1085
  return true;
1054
1086
  }
1055
1087
  const items = [];
1056
- let assigns;
1088
+ let assignments;
1057
1089
  let needsId;
1058
1090
  let deferring = false;
1059
1091
  let i = 0;
@@ -1065,11 +1097,11 @@ function writeSet(state, val, ref) {
1065
1097
  }
1066
1098
  if (item === val) {
1067
1099
  item = 0;
1068
- (assigns ||= []).push("i[" + i + "]");
1100
+ (assignments ||= []).push("i[" + i + "]");
1069
1101
  } else needsId ||= isDedupedMember(item);
1070
1102
  i = items.push(item);
1071
1103
  }
1072
- writeArrayArg(state, ref, items, assigns && "((s,i)=>(" + assignsToString(assigns, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId);
1104
+ writeArrayArg(state, ref, items, assignments && "((s,i)=>(" + assignmentsToString(assignments, "s") + ",i.forEach(i=>s.add(i)),s))(new Set,", "new Set(", needsId);
1073
1105
  return true;
1074
1106
  }
1075
1107
  function isAncestorMember(state, container, member) {
@@ -1083,16 +1115,16 @@ function deferCall(state, ref, method, args) {
1083
1115
  method,
1084
1116
  args
1085
1117
  });
1086
- state.assigned.add(ref);
1118
+ state.pendingAssignments.add(ref);
1087
1119
  }
1088
1120
  function writeArrayArg(state, ref, items, assignsPrefix, plainPrefix, needsId) {
1089
1121
  if (assignsPrefix || needsId) {
1090
- const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1122
+ const arrayRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1091
1123
  state.buf.push((assignsPrefix || plainPrefix) + arrayRef.id + "=");
1092
1124
  writeArray(state, items, arrayRef);
1093
1125
  } else {
1094
1126
  state.buf.push(plainPrefix);
1095
- writeArray(state, items, new Reference(ref, null, state.flush, state.buf.length));
1127
+ writeArray(state, items, new Reference(ref, null, state.flushId, state.buf.length));
1096
1128
  }
1097
1129
  state.buf.push(")");
1098
1130
  }
@@ -1136,7 +1168,7 @@ function writeTypedArray(state, val, ref) {
1136
1168
  writeProp(state, val.buffer, ref, "buffer");
1137
1169
  state.buf.push((val.byteOffset || needsLength ? "," + val.byteOffset + (needsLength ? "," + val.length : "") : "") + ")");
1138
1170
  } else {
1139
- state.refs.set(val.buffer, new Reference(ref, "buffer", state.flush, null));
1171
+ state.refs.set(val.buffer, new Reference(ref, "buffer", state.flushId, null));
1140
1172
  state.buf.push("new " + val.constructor.name + (val.length === 0 ? "" : "(" + (hasOnlyZeros(val) ? val.length : typedArrayToInitString(val)) + ")"));
1141
1173
  }
1142
1174
  return true;
@@ -1167,7 +1199,7 @@ function writeAggregateError(state, val, ref) {
1167
1199
  if (inlined) {
1168
1200
  const errorsRef = state.refs.get(val.errors);
1169
1201
  if (errorsRef?.id) {
1170
- state.assigned.add(errorsRef);
1202
+ state.pendingAssignments.add(errorsRef);
1171
1203
  addAssignment(errorsRef, accessId(state, ref) + toAccess("errors"));
1172
1204
  }
1173
1205
  }
@@ -1230,7 +1262,7 @@ function writeRequest(state, val, ref) {
1230
1262
  options += sep + "headers:" + ensureId(state, seenHeaders);
1231
1263
  sep = ",";
1232
1264
  } else {
1233
- state.refs.set(val.headers, new Reference(ref, "headers", state.flush, null));
1265
+ state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
1234
1266
  const headers = stringEntriesToHeadersInit(val.headers);
1235
1267
  if (headers) {
1236
1268
  options += sep + "headers:" + headers;
@@ -1279,7 +1311,7 @@ function writeResponse(state, val, ref) {
1279
1311
  const seenHeaders = state.refs.get(val.headers);
1280
1312
  if (seenHeaders) options += sep + "headers:" + ensureId(state, seenHeaders);
1281
1313
  else {
1282
- state.refs.set(val.headers, new Reference(ref, "headers", state.flush, null));
1314
+ state.refs.set(val.headers, new Reference(ref, "headers", state.flushId, null));
1283
1315
  const headers = stringEntriesToHeadersInit(val.headers);
1284
1316
  if (headers) options += sep + "headers:" + headers;
1285
1317
  }
@@ -1300,10 +1332,10 @@ function writeIntl(state, val, name, ref) {
1300
1332
  state.buf.push("new Intl." + name + "(" + quote(locale, 0) + ",");
1301
1333
  let optionsRef;
1302
1334
  if (needsId) {
1303
- optionsRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1335
+ optionsRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1304
1336
  state.buf.push(optionsRef.id + "={");
1305
1337
  } else {
1306
- optionsRef = new Reference(ref, null, state.flush, state.buf.length);
1338
+ optionsRef = new Reference(ref, null, state.flushId, state.buf.length);
1307
1339
  state.buf.push("{");
1308
1340
  }
1309
1341
  writeObjectProps(state, options, optionsRef);
@@ -1364,12 +1396,12 @@ function writeGenerator(state, iter, ref) {
1364
1396
  const heldReturn = returnValue !== void 0 && isAncestorMember(state, ref, returnValue);
1365
1397
  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})(");
1366
1398
  if (needsId) {
1367
- const arrayRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1399
+ const arrayRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1368
1400
  state.buf.push(arrayRef.id + "=");
1369
1401
  writeArray(state, yields, arrayRef);
1370
- } else writeArray(state, yields, new Reference(ref, null, state.flush, state.buf.length));
1402
+ } else writeArray(state, yields, new Reference(ref, null, state.flushId, state.buf.length));
1371
1403
  if (heldReturn) {
1372
- const holder = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1404
+ const holder = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1373
1405
  state.buf.push("," + holder.id + "={}");
1374
1406
  writeProp(state, returnValue, holder, "v");
1375
1407
  } else if (returnValue !== void 0) {
@@ -1433,7 +1465,7 @@ function writeMaybeIterableProps(state, val, ref) {
1433
1465
  for (const item of val) if (item === val && !(yieldSelf || iterArr.length)) yieldSelf = "yield this;";
1434
1466
  else iterArr.push(item);
1435
1467
  if (iterArr.length) {
1436
- const iterRef = new Reference(ref, null, state.flush, null, nextRefAccess(state));
1468
+ const iterRef = new Reference(ref, null, state.flushId, null, nextRefAccess(state));
1437
1469
  state.buf.push(sep + "*[(" + iterRef.id + "=");
1438
1470
  writeArray(state, iterArr, iterRef);
1439
1471
  state.buf.push(",Symbol.iterator)](){" + yieldSelf + "yield*" + iterRef.id + "}");
@@ -1457,21 +1489,27 @@ function throwUnserializable(state, cause, ref = null, accessor = "") {
1457
1489
  if (cause !== void 0 && state.boundary?.abort) {
1458
1490
  let message = "Unable to serialize";
1459
1491
  let access = "";
1460
- while (ref?.accessor) {
1492
+ while (ref) {
1493
+ const { accessor } = ref;
1461
1494
  const debug = ref.parent?.debug;
1462
- if (debug) {
1463
- const varLoc = debug.vars?.[ref.accessor];
1464
- let debugAccess = ref.accessor;
1495
+ if (accessor && debug) {
1496
+ const rawAccessor = fromObjectKey(accessor);
1497
+ const varLoc = debug.vars?.[rawAccessor];
1498
+ const slotName = debug.slots?.[rawAccessor];
1499
+ let debugAccess = varLoc ? rawAccessor : void 0;
1465
1500
  let debugLoc = debug.loc;
1466
1501
  if (varLoc) if (Array.isArray(varLoc)) {
1467
1502
  debugAccess = varLoc[0];
1468
1503
  if (varLoc[1]) debugLoc = varLoc[1];
1469
1504
  } else debugLoc = varLoc;
1470
- message += ` ${JSON.stringify(debugAccess)} in ${debug.file}`;
1505
+ let display;
1506
+ if (debugAccess !== void 0) display = slotName && debugAccess.startsWith("...") ? `\`${slotName}\` from \`${debugAccess}\`` : JSON.stringify(debugAccess);
1507
+ else display = describeAccessor(rawAccessor, slotName) ?? JSON.stringify(rawAccessor);
1508
+ message += ` ${display} in ${debug.file}`;
1471
1509
  if (debugLoc) message += `:${debugLoc}`;
1472
1510
  break;
1473
1511
  }
1474
- access = toAccess(ref.accessor) + access;
1512
+ if (accessor) access = toAccess(accessor) + access;
1475
1513
  ref = ref.parent;
1476
1514
  }
1477
1515
  if (accessor) access = toAccess(accessor) + access;
@@ -1483,6 +1521,40 @@ function throwUnserializable(state, cause, ref = null, accessor = "") {
1483
1521
  state.boundary.abort(err);
1484
1522
  }
1485
1523
  }
1524
+ const accessorPrefixDescriptions = {
1525
+ BranchScopes: "the branch scopes",
1526
+ ClosureScopes: "the closure scopes",
1527
+ ClosureSignalIndex: "the closure signal index",
1528
+ ConditionalRenderer: "the conditional renderer",
1529
+ ControlledObserver: "the controlled observer",
1530
+ ControlledHandler: "the change handler",
1531
+ ControlledType: "the controlled type",
1532
+ ControlledValue: "the controlled value",
1533
+ DynamicHTMLLastChild: "the dynamic html",
1534
+ EventAttributes: "the event handlers",
1535
+ IdFallback: "the generated id",
1536
+ KeyedScopes: "the keyed scopes",
1537
+ Lifecycle: "the lifecycle handlers",
1538
+ Promise: "the pending promise",
1539
+ TagVariableChange: "the tag variable change handler"
1540
+ };
1541
+ function describeAccessor(accessor, slotName) {
1542
+ const sep = accessor.indexOf(":");
1543
+ if (~sep) {
1544
+ const description = slotName === void 0 ? accessorPrefixDescriptions[accessor.slice(0, sep)] : `the \`${slotName}\` handler`;
1545
+ if (description) {
1546
+ const node = /^#([a-z-]+)\//i.exec(accessor.slice(sep + 1));
1547
+ return node ? `${description} of \`<${node[1]}>\`` : description;
1548
+ }
1549
+ }
1550
+ }
1551
+ function fromObjectKey(key) {
1552
+ try {
1553
+ if (key[0] === "\"") return JSON.parse(key.replace(/\\x/g, "\\u00"));
1554
+ if (key[0] === "[") return JSON.parse(key.slice(1, -1));
1555
+ } catch {}
1556
+ return key;
1557
+ }
1486
1558
  function trackChannel(state, ref) {
1487
1559
  const refReadyId = ref.channel?.readyId;
1488
1560
  if (!refReadyId || refReadyId === state.channel?.readyId) return true;
@@ -1603,7 +1675,7 @@ function accessId(state, ref) {
1603
1675
  function assignId(state, ref) {
1604
1676
  const { pos } = ref;
1605
1677
  ref.id = nextRefAccess(state);
1606
- if (pos !== null && ref.flush === state.flush) {
1678
+ if (pos !== null && ref.flushId === state.flushId) {
1607
1679
  if (pos === 0) state.buf[0] = ref.id + "=" + state.buf[0];
1608
1680
  else state.buf[pos - 1] += ref.id + "=";
1609
1681
  return ref.id;
@@ -1620,7 +1692,7 @@ function assignId(state, ref) {
1620
1692
  break;
1621
1693
  }
1622
1694
  }
1623
- if (parent.flush === state.flush || parent.scopeId !== void 0) {
1695
+ if (parent.flushId === state.flushId || parent.scopeId !== void 0) {
1624
1696
  accessPrevValue = accessId(state, parent) + accessPrevValue;
1625
1697
  break;
1626
1698
  }
@@ -1628,13 +1700,13 @@ function assignId(state, ref) {
1628
1700
  } while (cur);
1629
1701
  return ref.id + "=" + accessPrevValue;
1630
1702
  }
1631
- function assignsToString(assigns, value) {
1632
- if (assigns.length > 100) return "($=>(" + assigns.join("=$,") + "=$))(" + value + ")";
1633
- return assigns.join("=") + "=" + value;
1703
+ function assignmentsToString(assignments, value) {
1704
+ if (assignments.length > 100) return "($=>(" + assignments.join("=$,") + "=$))(" + value + ")";
1705
+ return assignments.join("=") + "=" + value;
1634
1706
  }
1635
1707
  function addAssignment(ref, assign) {
1636
- if (ref.assigns) ref.assigns.push(assign);
1637
- else ref.assigns = [assign];
1708
+ if (ref.assignments) ref.assignments.push(assign);
1709
+ else ref.assignments = [assign];
1638
1710
  }
1639
1711
  function nextRefAccess(state) {
1640
1712
  return "_." + nextId(state);
@@ -1708,12 +1780,16 @@ function forOf(list, cb) {
1708
1780
  }
1709
1781
  function forTo(to, from, step, cb) {
1710
1782
  assertValidRangeBound("to", to);
1783
+ assertValidRangeStart("from", from);
1784
+ assertValidRangeStart("step", step);
1711
1785
  const start = from || 0;
1712
1786
  const delta = step || 1;
1713
1787
  for (let steps = (to - start) / delta, i = 0; i <= steps; i++) cb(start + i * delta);
1714
1788
  }
1715
1789
  function forUntil(until, from, step, cb) {
1716
1790
  assertValidRangeBound("until", until);
1791
+ assertValidRangeStart("from", from);
1792
+ assertValidRangeStart("step", step);
1717
1793
  const start = from || 0;
1718
1794
  const delta = step || 1;
1719
1795
  for (let steps = (until - start) / delta, i = 0; i < steps; i++) cb(start + i * delta);
@@ -1859,6 +1935,9 @@ function getContext(key) {
1859
1935
  function getState() {
1860
1936
  return $chunk.boundary.state;
1861
1937
  }
1938
+ function rendererKey(renderer) {
1939
+ return renderer?.["owner"] === void 0 ? renderer?.["id"] || renderer : renderer["id"] + " " + renderer[Owner];
1940
+ }
1862
1941
  function getScopeId(scope) {
1863
1942
  return scope[K_SCOPE_ID];
1864
1943
  }
@@ -1954,7 +2033,7 @@ function _attr_content(nodeAccessor, scopeId, content, serializeReason) {
1954
2033
  if (_peek_scope_id() !== branchId) {
1955
2034
  if (shouldResume) writeScope(scopeId, {
1956
2035
  [BranchScopes + nodeAccessor]: writeScope(branchId, {}),
1957
- [ConditionalRenderer + nodeAccessor]: render?.["id"]
2036
+ [ConditionalRenderer + nodeAccessor]: rendererKey(render)
1958
2037
  });
1959
2038
  } else _scope_id();
1960
2039
  }
@@ -2741,7 +2820,13 @@ function offTick(cb) {
2741
2820
  function flushTickQueue() {
2742
2821
  const queue = tickQueue;
2743
2822
  tickQueue = void 0;
2744
- for (const cb of queue) cb(true);
2823
+ for (const cb of queue) try {
2824
+ cb(true);
2825
+ } catch (err) {
2826
+ tick(() => {
2827
+ throw err;
2828
+ });
2829
+ }
2745
2830
  }
2746
2831
  //#endregion
2747
2832
  //#region src/html/attrs.ts
@@ -2782,7 +2867,7 @@ function _attr_textarea_value(scopeId, nodeAccessor, value, valueChange, seriali
2782
2867
  }
2783
2868
  function _textarea_value(value) {
2784
2869
  const escaped = _escape(normalizeStrAttrValue(value));
2785
- return escaped[0] === "\n" || escaped[0] === "\r" ? "\n" + escaped : escaped;
2870
+ return escaped[0] === "\n" ? "\n" + escaped : escaped;
2786
2871
  }
2787
2872
  function _attr_input_value(scopeId, nodeAccessor, value, valueChange, serializeType) {
2788
2873
  if (valueChange) writeControlledScope(2, scopeId, nodeAccessor, void 0, valueChange, serializeType);
@@ -2846,6 +2931,7 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
2846
2931
  result += _attr_input_checkedValue(scopeId, nodeAccessor, data.checkedValue, data.checkedValueChange, data.value, 1);
2847
2932
  skip = /^(?:value|checked(?:Value)?)(?:Change)?$|[\s/>"'=]/;
2848
2933
  } else if (data.valueChange) {
2934
+ assertNoValueBindingOnCheckable(data.type, data.valueChange);
2849
2935
  result += _attr_input_value(scopeId, nodeAccessor, data.value, data.valueChange, 1);
2850
2936
  skip = /^value(?:Change)?$|[\s/>"'=]/;
2851
2937
  }
@@ -2878,16 +2964,14 @@ function _attrs(data, nodeAccessor, scopeId, tagName) {
2878
2964
  result += _attr_style(value);
2879
2965
  break;
2880
2966
  default:
2881
- if (name && !(isVoid(value) || skip.test(name) || name === "content" && tagName !== "meta")) {
2882
- assertValidAttrName(name);
2883
- if (isEventHandler(name)) {
2884
- if (!events) {
2885
- events = {};
2886
- writeScope(scopeId, { [EventAttributes + nodeAccessor]: events });
2887
- }
2888
- events[getEventHandlerName(name)] = value;
2889
- } else result += nonVoidAttr(name, value);
2890
- }
2967
+ if (name) assertValidAttrName(name);
2968
+ if (name && !(isVoid(value) || skip.test(name) || name === "content" && tagName !== "meta")) if (isEventHandler(name)) {
2969
+ if (!events) {
2970
+ events = {};
2971
+ writeScope(scopeId, { [EventAttributes + nodeAccessor]: events });
2972
+ }
2973
+ events[getEventHandlerName(name)] = value;
2974
+ } else result += nonVoidAttr(name, value);
2891
2975
  break;
2892
2976
  }
2893
2977
  }
@@ -2903,6 +2987,10 @@ function _attrs_partial(data, skip, nodeAccessor, scopeId, tagName) {
2903
2987
  const key = isEventHandler(name) ? `on-${getEventHandlerName(name)}` : name;
2904
2988
  if (!skip[key]) partial[key] = data[name];
2905
2989
  }
2990
+ assertExclusiveAttrs({
2991
+ ...data,
2992
+ ...skip
2993
+ });
2906
2994
  return _attrs(partial, nodeAccessor, scopeId, tagName);
2907
2995
  }
2908
2996
  function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, serializeReason) {
@@ -2910,15 +2998,22 @@ function _attrs_partial_content(data, skip, nodeAccessor, scopeId, tagName, seri
2910
2998
  _attr_content(nodeAccessor, scopeId, data?.content, serializeReason);
2911
2999
  }
2912
3000
  function writeControlledScope(type, scopeId, nodeAccessor, value, valueChange, serializeType) {
2913
- assertHandlerIsFunction("valueChange", valueChange);
2914
- writeScope(scopeId, serializeType ? {
3001
+ var handlerName = [
3002
+ "checkedChange",
3003
+ "checkedValueChange",
3004
+ "valueChange",
3005
+ "valueChange",
3006
+ "openChange"
3007
+ ][type];
3008
+ assertHandlerIsFunction(handlerName, valueChange);
3009
+ setDebugSlotName(writeScope(scopeId, serializeType ? {
2915
3010
  [ControlledType + nodeAccessor]: type,
2916
3011
  [ControlledValue + nodeAccessor]: value,
2917
3012
  [ControlledHandler + nodeAccessor]: valueChange
2918
3013
  } : {
2919
3014
  [ControlledValue + nodeAccessor]: value,
2920
3015
  [ControlledHandler + nodeAccessor]: valueChange
2921
- });
3016
+ }), ControlledHandler + nodeAccessor, handlerName);
2922
3017
  }
2923
3018
  function stringAttr(name, value) {
2924
3019
  return value && " " + name + attrAssignment(value);
@@ -2932,8 +3027,8 @@ function nonVoidAttr(name, value) {
2932
3027
  }
2933
3028
  return " " + name + attrAssignment(value + "");
2934
3029
  }
2935
- const singleQuoteAttrReplacements = /'|&(?=[#a-zA-Z])/g;
2936
- const doubleQuoteAttrReplacements = /"|&(?=[#a-zA-Z])/g;
3030
+ const singleQuoteAttrReplacements = /['\r]|&(?=[#a-zA-Z])/g;
3031
+ const doubleQuoteAttrReplacements = /["\r]|&(?=[#a-zA-Z])/g;
2937
3032
  const needsQuotedAttr = /["'>\s]|&[#a-zA-Z]|\/$/g;
2938
3033
  function attrAssignment(value) {
2939
3034
  return value ? needsQuotedAttr.test(value) ? value[needsQuotedAttr.lastIndex - 1] === (needsQuotedAttr.lastIndex = 0, "\"") ? "='" + escapeSingleQuotedAttrValue(value) + "'" : "=\"" + escapeDoubleQuotedAttrValue(value) + "\"" : "=" + value : "";
@@ -2942,13 +3037,13 @@ function escapeSingleQuotedAttrValue(value) {
2942
3037
  return singleQuoteAttrReplacements.test(value) ? value.replace(singleQuoteAttrReplacements, replaceUnsafeSingleQuoteAttrChar) : value;
2943
3038
  }
2944
3039
  function replaceUnsafeSingleQuoteAttrChar(match) {
2945
- return match === "'" ? "&#39;" : "&amp;";
3040
+ return match === "'" ? "&#39;" : match === "\r" ? "&#13;" : "&amp;";
2946
3041
  }
2947
3042
  function escapeDoubleQuotedAttrValue(value) {
2948
3043
  return doubleQuoteAttrReplacements.test(value) ? value.replace(doubleQuoteAttrReplacements, replaceUnsafeDoubleQuoteAttrChar) : value;
2949
3044
  }
2950
3045
  function replaceUnsafeDoubleQuoteAttrChar(match) {
2951
- return match === "\"" ? "&#34;" : "&amp;";
3046
+ return match === "\"" ? "&#34;" : match === "\r" ? "&#13;" : "&amp;";
2952
3047
  }
2953
3048
  function normalizedValueMatches(a, b) {
2954
3049
  const value = normalizeStrAttrValue(b);
@@ -2976,21 +3071,21 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
2976
3071
  rendered = true;
2977
3072
  const renderNative = () => {
2978
3073
  _scope_id();
2979
- _html(`<${renderer}${_attrs(input, `#${renderer}/0`, branchId, renderer)}>`);
3074
+ _html(`<${renderer}${_attrs(input, `#${renderer.toLowerCase()}/0`, branchId, renderer)}>`);
2980
3075
  if (!voidElementsReg.test(renderer)) {
2981
3076
  const renderContent = content || normalizeDynamicRenderer(input.content);
2982
3077
  if (renderer === "textarea") {
2983
3078
  if (renderContent) throw new Error("A dynamic tag rendering a `<textarea>` cannot have `content` and must use the `value` attribute instead.");
2984
- _html(_attr_textarea_value(branchId, `#${renderer}/0`, input.value, input.valueChange, 1));
3079
+ _html(_attr_textarea_value(branchId, `#${renderer.toLowerCase()}/0`, input.value, input.valueChange, 1));
2985
3080
  } else if (renderContent) {
2986
3081
  if (typeof renderContent !== "function") throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
2987
- if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer}/0`, input.value, input.valueChange, renderContent, 1);
2988
- else _dynamic_tag(branchId, `#${renderer}/0`, renderContent, void 0, 0, void 0, serializeReason);
3082
+ if (renderer === "select" && ("value" in input || "valueChange" in input)) _attr_select_value(branchId, `#${renderer.toLowerCase()}/0`, input.value, input.valueChange, renderContent, 1);
3083
+ else _dynamic_tag(branchId, `#${renderer.toLowerCase()}/0`, renderContent, void 0, 0, void 0, serializeReason);
2989
3084
  }
2990
3085
  _html(`</${renderer}>`);
2991
3086
  } else if (content) throw new Error(`Body content is not supported for the \`<${renderer}>\` tag.`);
2992
3087
  const childScope = getScopeById(branchId);
2993
- const needsScript = childScope && (childScope[`EventAttributes:#${renderer}/0`] || childScope[`ControlledHandler:#${renderer}/0`]);
3088
+ const needsScript = childScope && (childScope[`EventAttributes:#${renderer.toLowerCase()}/0`] || childScope[`ControlledHandler:#${renderer.toLowerCase()}/0`]);
2994
3089
  if (needsScript) {
2995
3090
  writeScope(branchId, { [Renderer]: renderer });
2996
3091
  _script(branchId, DYNAMIC_TAG_SCRIPT_REGISTER_ID);
@@ -3021,16 +3116,17 @@ let _dynamic_tag = (scopeId, accessor, tag, inputOrArgs, content, inputIsArgs, s
3021
3116
  }
3022
3117
  }
3023
3118
  if (rendered) {
3024
- if (shouldResume) writeScope(scopeId, { [ConditionalRenderer + accessor]: renderer?.["id"] || renderer });
3119
+ if (shouldResume) writeScope(scopeId, { [ConditionalRenderer + accessor]: rendererKey(renderer) });
3025
3120
  } else _scope_id();
3026
3121
  return result;
3027
3122
  };
3028
- function _content(id, fn) {
3123
+ function _content(id, fn, scopeId) {
3029
3124
  fn["id"] = id;
3125
+ fn[Owner] = scopeId;
3030
3126
  return fn;
3031
3127
  }
3032
3128
  function _content_resume(id, fn, scopeId) {
3033
- return _resume(_content(id, fn), id, scopeId);
3129
+ return _resume(_content(id, fn, scopeId), id, scopeId);
3034
3130
  }
3035
3131
  const patchDynamicTag = ((originalDynamicTag) => (patch) => {
3036
3132
  _dynamic_tag = (scopeId, accessor, tag, input, content, inputIsArgs, resume) => {
@@ -3351,14 +3447,17 @@ function writeTriggerScript(html, triggers) {
3351
3447
  const exprs = triggers.map((trigger) => {
3352
3448
  const options = trigger.options && toObjectExpression(trigger.options);
3353
3449
  switch (trigger.type) {
3354
- 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())`;
3450
+ case "visible": return `(e=>e&&new IntersectionObserver((e,i)=>e.some(e=>e.isIntersecting)&&i.disconnect()+l()${options ? `,${options}` : ""}).observe(e))(${querySelectorOrLoad(trigger.selector)})`;
3355
3451
  case "idle": return `(self.requestIdleCallback||l)(l${options ? `,${options}` : ""})`;
3356
3452
  case "media": return `(m=>m.matches?l():m.addEventListener("change",l,{once:1}))(matchMedia(${JSON.stringify(trigger.selector)}))`;
3357
- default: return `(e=>e?.addEventListener("${trigger.type.slice(3)}",l,{once:1}))(document.querySelector(${JSON.stringify(trigger.selector)})||l())`;
3453
+ default: return `(e=>e?.addEventListener("${trigger.type.slice(3)}",l,{once:1}))(${querySelectorOrLoad(trigger.selector)})`;
3358
3454
  }
3359
3455
  });
3360
3456
  writeScript(`((p,h,d,l=$=>{d||p.after(new Range().createContextualFragment(d=h))})=>${exprs.length > 1 ? `{${exprs.join(";")}}` : exprs[0]})(document.currentScript,${htmlStr})`);
3361
3457
  }
3458
+ function querySelectorOrLoad(selector) {
3459
+ return `document.querySelector(${JSON.stringify(selector)})||${`(console.warn(${JSON.stringify(`A lazy load trigger could not find an element matching "${selector}". The module was loaded immediately.`)}),l())`}`;
3460
+ }
3362
3461
  function toObjectExpression(options) {
3363
3462
  let result = "{";
3364
3463
  let sep = "";
@@ -3385,6 +3484,7 @@ const compat = {
3385
3484
  peekNextScopeId: _peek_scope_id,
3386
3485
  isInResumedBranch,
3387
3486
  withChunk,
3487
+ getChunk,
3388
3488
  ensureState($global) {
3389
3489
  let state = $global[K_TAGS_API_STATE] ||= getChunk()?.boundary.state;
3390
3490
  if (!state) {
@@ -3426,11 +3526,18 @@ const compat = {
3426
3526
  return compatRegistered;
3427
3527
  };
3428
3528
  },
3429
- flushScript($global) {
3529
+ createChunk($global) {
3430
3530
  const state = this.ensureState($global);
3431
- const boundary = new Boundary(state);
3432
- if (boundary.flush() === 1) throw new Error("Cannot serialize promise across tags/class compat layer.");
3433
- return new Chunk(boundary, null, null, state).flushScript().scripts;
3531
+ return new Chunk(new Boundary(state), null, null, state);
3532
+ },
3533
+ flushScript($global, chunk) {
3534
+ chunk ||= this.createChunk($global);
3535
+ const { boundary } = chunk;
3536
+ switch (boundary.flush()) {
3537
+ case 2: throw boundary.signal.reason;
3538
+ case 1: throw new Error("Cannot serialize promise across tags/class compat layer.");
3539
+ }
3540
+ return chunk.flushScript().scripts;
3434
3541
  },
3435
3542
  render(renderer, willRerender, classAPIOut, component, input, completeChunks, registerChildScope) {
3436
3543
  const state = this.ensureState(classAPIOut.global);