marko 6.3.56 → 6.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (81) hide show
  1. package/cheatsheet.md +2 -2
  2. package/dist/common/constants/accessor-prefix.d.ts +1 -0
  3. package/dist/common/constants/accessor-prefix.debug.d.ts +1 -0
  4. package/dist/common/constants/accessor-prop.d.ts +3 -0
  5. package/dist/common/constants/accessor-prop.debug.d.ts +3 -0
  6. package/dist/common/types.d.ts +8 -2
  7. package/dist/debug/dom/catch.feat.js +12 -14
  8. package/dist/debug/dom/catch.feat.mjs +12 -14
  9. package/dist/debug/dom/controllable-input.feat.js +1 -1
  10. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  11. package/dist/debug/dom/controllable-open.feat.js +1 -1
  12. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  13. package/dist/debug/dom/controllable-select.feat.js +1 -1
  14. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  15. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  16. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  17. package/dist/debug/dom/controllable.feat.js +1 -1
  18. package/dist/debug/dom/controllable.feat.mjs +1 -1
  19. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  20. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  21. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  22. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  23. package/dist/debug/dom/lazy.feat.js +4 -0
  24. package/dist/debug/dom/lazy.feat.mjs +4 -0
  25. package/dist/debug/dom/placeholder.feat.js +1 -1
  26. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  27. package/dist/debug/{dom-DcwejnYg.js → dom-BRO5aArp.js} +232 -178
  28. package/dist/debug/{dom-BeCNT5R5.mjs → dom-Btj2QJhk.mjs} +215 -167
  29. package/dist/debug/dom.js +14 -12
  30. package/dist/debug/dom.mjs +14 -12
  31. package/dist/debug/html.js +603 -517
  32. package/dist/debug/html.mjs +602 -518
  33. package/dist/dom/abort-signal.d.ts +2 -0
  34. package/dist/dom/catch.feat.js +6 -7
  35. package/dist/dom/catch.feat.mjs +5 -7
  36. package/dist/dom/control-flow.d.ts +3 -5
  37. package/dist/dom/controllable-input.feat.js +3 -2
  38. package/dist/dom/controllable-input.feat.mjs +1 -1
  39. package/dist/dom/controllable-open.feat.js +3 -2
  40. package/dist/dom/controllable-open.feat.mjs +1 -1
  41. package/dist/dom/controllable-select.feat.js +3 -2
  42. package/dist/dom/controllable-select.feat.mjs +1 -1
  43. package/dist/dom/controllable-textarea.feat.js +3 -2
  44. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  45. package/dist/dom/controllable.feat.js +3 -2
  46. package/dist/dom/controllable.feat.mjs +1 -1
  47. package/dist/dom/dynamic-tag-script.feat.js +3 -2
  48. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  49. package/dist/dom/dynamic-tag-var.feat.js +2 -1
  50. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  51. package/dist/dom/lazy.feat.d.ts +1 -0
  52. package/dist/dom/lazy.feat.js +4 -0
  53. package/dist/dom/lazy.feat.mjs +4 -0
  54. package/dist/dom/load.d.ts +3 -3
  55. package/dist/dom/placeholder.feat.js +4 -3
  56. package/dist/dom/placeholder.feat.mjs +1 -1
  57. package/dist/dom/queue.d.ts +2 -4
  58. package/dist/dom/resume.d.ts +1 -1
  59. package/dist/dom/scope.d.ts +0 -1
  60. package/dist/{dom-BwNsIevR.mjs → dom-B-v8Gw6T.mjs} +114 -87
  61. package/dist/{dom-QEF0csuC.js → dom-BSsI9OPC.js} +210 -182
  62. package/dist/dom.js +59 -56
  63. package/dist/dom.mjs +34 -32
  64. package/dist/html/attrs.d.ts +2 -0
  65. package/dist/html/writer.d.ts +5 -11
  66. package/dist/html.d.ts +1 -1
  67. package/dist/html.js +362 -317
  68. package/dist/html.mjs +361 -317
  69. package/dist/translator/index.js +791 -650
  70. package/dist/translator/util/binding-has-prop.d.ts +2 -0
  71. package/dist/translator/util/entry-builder.d.ts +2 -0
  72. package/dist/translator/util/generate-uid.d.ts +5 -0
  73. package/dist/translator/util/references.d.ts +3 -2
  74. package/dist/translator/util/runtime.d.ts +3 -3
  75. package/dist/translator/util/sections.d.ts +8 -2
  76. package/dist/translator/util/serialize-reasons.d.ts +2 -2
  77. package/dist/translator/util/setup-work.d.ts +5 -0
  78. package/dist/translator/util/signals.d.ts +5 -7
  79. package/dist/translator/visitors/tag/native-tag.d.ts +1 -0
  80. package/package.json +3 -3
  81. package/dist/translator/util/setup-statements.d.ts +0 -5
@@ -14,6 +14,7 @@ const KeyedScopes = "KeyedScopes:";
14
14
  const Lifecycle = "Lifecycle:";
15
15
  const Promise$1 = "Promise:";
16
16
  const TagVariableChange$1 = "TagVariableChange:";
17
+ const TryBranch$1 = "TryBranch:";
17
18
  //#endregion
18
19
  //#region src/common/constants/accessor-prop.debug.ts
19
20
  const Global = "$global";
@@ -32,15 +33,18 @@ const Load = "#Load";
32
33
  const LoopKey = "#LoopKey";
33
34
  const ParentBranch = "#ParentBranch";
34
35
  const PendingEffects = "#PendingEffects";
36
+ const PendingEffectScopes = "#PendingEffectScopes";
35
37
  const PendingRenders = "#PendingRenders";
36
38
  const PendingScopes = "#PendingScopes";
37
39
  const PlaceholderBranch = "#PlaceholderBranch";
38
40
  const PlaceholderContent = "#PlaceholderContent";
39
41
  const Renderer = "#Renderer";
42
+ const ReturnValue = "#ReturnValue";
40
43
  const StartNode = "#StartNode";
41
44
  const Subscriptions = "#Subscriptions";
42
45
  const TagVariable = "#TagVariable";
43
46
  const TagVariableChange = "#TagVariableChange";
47
+ const TryBranch = "#TryBranch";
44
48
  //#endregion
45
49
  //#region src/common/constants/closure-scopes-prop.debug.ts
46
50
  const Changed = "Changed";
@@ -135,19 +139,21 @@ const toDelimitedString = function toDelimitedString(val, delimiter, stringify)
135
139
  let str = "";
136
140
  let sep = "";
137
141
  let part;
138
- if (val) if (typeof val !== "object") str += val;
139
- else if (Array.isArray(val)) for (const v of val) {
140
- part = toDelimitedString(v, delimiter, stringify);
141
- if (part) {
142
- str += sep + part;
143
- sep = delimiter;
142
+ if (val) {
143
+ if (typeof val !== "object") str += val;
144
+ else if (Array.isArray(val)) for (const v of val) {
145
+ part = toDelimitedString(v, delimiter, stringify);
146
+ if (part) {
147
+ str += sep + part;
148
+ sep = delimiter;
149
+ }
144
150
  }
145
- }
146
- else for (const name in val) {
147
- part = stringify(name, val[name]);
148
- if (part) {
149
- str += sep + part;
150
- sep = delimiter;
151
+ else for (const name in val) {
152
+ part = stringify(name, val[name]);
153
+ if (part) {
154
+ str += sep + part;
155
+ sep = delimiter;
156
+ }
151
157
  }
152
158
  }
153
159
  return str;
@@ -320,8 +326,6 @@ function forUntil(until, from, step, cb) {
320
326
  //#region src/dom/queue.ts
321
327
  let rendering;
322
328
  let runId = 2;
323
- const caughtError = /* @__PURE__ */ new WeakSet();
324
- const placeholderShown = /* @__PURE__ */ new WeakSet();
325
329
  let pendingEffects = [];
326
330
  let pendingRenders = [];
327
331
  const scopeKeyOffset = 1e6;
@@ -398,10 +402,10 @@ let runRender = (render) => {
398
402
  if (!branchesEnabled || render["scope"]["#ClosestBranch"]?.["#Gen"] !== 0) render[Signal](render[Scope], render[Value]);
399
403
  };
400
404
  let catchEnabled;
401
- function installCatch(wrapEffects, wrapRender) {
405
+ function installCatch(catchEffects, wrapRender) {
402
406
  catchEnabled = 1;
403
407
  withBranches();
404
- runEffects = wrapEffects(runEffects);
408
+ runEffects = catchEffects;
405
409
  runRender = wrapRender(runRender);
406
410
  }
407
411
  function runRenders() {
@@ -442,6 +446,12 @@ function $signal(scope, id) {
442
446
  trackCleanup(scope);
443
447
  return ((scope[AbortControllers] ||= {})[id] ||= new AbortController()).signal;
444
448
  }
449
+ /** Runs `abort` as a destroyed scope's `$signal` would fire, without creating one. */
450
+ function trackAbort(scope, id, abort) {
451
+ abortsEnabled = 1;
452
+ trackCleanup(scope);
453
+ (scope[AbortControllers] ||= {})[id] = { abort };
454
+ }
445
455
  /** Enrols `scope` with its branch so destroying the branch cleans it up. */
446
456
  function trackCleanup(scope, subscribers) {
447
457
  const branch = scope[ClosestBranch];
@@ -462,8 +472,10 @@ function toArray(opt) {
462
472
  return opt ? Array.isArray(opt) ? opt : [opt] : [];
463
473
  }
464
474
  function forEach(opt, cb) {
465
- if (opt) if (Array.isArray(opt)) for (const item of opt) cb(item);
466
- else cb(opt);
475
+ if (opt) {
476
+ if (Array.isArray(opt)) for (const item of opt) cb(item);
477
+ else cb(opt);
478
+ }
467
479
  }
468
480
  function push(opt, item) {
469
481
  return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
@@ -538,11 +550,6 @@ function collectScopes(fn) {
538
550
  function skipScope() {
539
551
  return nextScopeId++;
540
552
  }
541
- function findBranchWithKey(scope, key) {
542
- let branch = scope[ClosestBranch];
543
- while (branch && branch[key] == null) branch = branch[ParentBranch];
544
- return branch;
545
- }
546
553
  function destroyBranch(branch) {
547
554
  branch[ParentBranch]?.[BranchScopes]?.delete(branch);
548
555
  destroyNestedScopes(branch);
@@ -633,11 +640,12 @@ function _let_change(id, fn) {
633
640
  const valueChangeAccessor = TagVariableChange$1 + valueAccessor;
634
641
  const base = _let(id, fn);
635
642
  return (scope, value, valueChange) => {
636
- if (rendering) if ((scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope))) {
637
- scope[valueAccessor] = value;
638
- fn?.(scope);
639
- } else base(scope, value);
640
- else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
643
+ if (rendering) {
644
+ if ((scope[valueChangeAccessor] = valueChange) && (scope[valueAccessor] !== value || !(valueAccessor in scope))) {
645
+ scope[valueAccessor] = value;
646
+ fn?.(scope);
647
+ } else base(scope, value);
648
+ } else if (scope[valueChangeAccessor]) scope[valueChangeAccessor](value);
641
649
  else base(scope, value);
642
650
  return value;
643
651
  };
@@ -652,10 +660,11 @@ function _const(valueAccessor, fn) {
652
660
  }
653
661
  function _or(id, fn, defaultPending = 1, scopeIdAccessor = "#Id") {
654
662
  return (scope) => {
655
- if (scope["#Gen"] === runId) if (~id in scope) {
656
- if (!--scope[~id]) fn(scope);
657
- } else scope[~id] = defaultPending;
658
- else queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
663
+ if (scope["#Gen"] === runId) {
664
+ if (~id in scope) {
665
+ if (!--scope[~id]) fn(scope);
666
+ } else scope[~id] = defaultPending;
667
+ } else queueRender(scope, fn, id, 0, scope[scopeIdAccessor]);
659
668
  };
660
669
  }
661
670
  function _for_closure(ownerLoopNodeAccessor, fn) {
@@ -738,7 +747,8 @@ function _closure_get(valueAccessor, fn, getOwnerScope, resumeId) {
738
747
  const closureSignal = ((scope, resumed) => {
739
748
  const ownerScope = getOwnerScope ? getOwnerScope(scope) : scope["_"];
740
749
  scope[closureSignal[SignalIndexAccessor]] = closureSignal[Index];
741
- if (!resumed || ownerScope[closureSignal["scopeInstancesAccessor"]]["Changed"]) fn(scope);
750
+ if (!resumed) fn(scope);
751
+ else if (ownerScope[closureSignal["scopeInstancesAccessor"]]["Changed"]) queueAsyncRender(scope, closureSignal);
742
752
  subscribeToScopeSet(ownerScope, closureSignal[ScopeInstancesAccessor], scope);
743
753
  });
744
754
  closureSignal[ScopeInstancesAccessor] = ClosureScopes + valueAccessor;
@@ -754,9 +764,11 @@ function _child_setup(setup) {
754
764
  return setup;
755
765
  }
756
766
  function _var(scope, childAccessor, signal) {
757
- scope[childAccessor][TagVariable] = (value) => signal(scope, value);
767
+ const childScope = scope[childAccessor];
768
+ childScope[TagVariable] = (value) => signal(scope, value);
769
+ if ("#ReturnValue" in childScope) signal(scope, childScope[ReturnValue]);
758
770
  }
759
- const _return = (scope, value) => scope[TagVariable]?.(value);
771
+ const _return = (scope, value) => scope["#TagVariable"] ? scope[TagVariable](value) : scope[ReturnValue] = value;
760
772
  function _return_change(scope, changeHandler) {
761
773
  scope[TagVariableChange] = changeHandler || void 0;
762
774
  }
@@ -783,7 +795,7 @@ function _script(id, fn) {
783
795
  };
784
796
  }
785
797
  function _global_read($global, key) {
786
- if (!(key in $global)) console.error(`\`$global.${key}\` is not serialized to the client, so this read is \`undefined\`. Add \`${key}\` to \`serializedGlobals\` at the render call.`);
798
+ if (!(key in $global)) console.error(`\`$global.${key}\` is not serialized to the client, so this read is \`undefined\`. Serialized globals are embedded in the page: add \`${key}\` to \`serializedGlobals\` at the render call only if it holds no secrets; otherwise copy the field the client needs into its own \`$global\` key and serialize that.`);
787
799
  return $global[key];
788
800
  }
789
801
  function _el_read(value) {
@@ -792,12 +804,14 @@ function _el_read(value) {
792
804
  }
793
805
  function* traverse(scope, path, args, i = path.length - 1) {
794
806
  if (rendering) _hoist_read_error();
795
- if (scope) if (Symbol.iterator in scope) {
796
- for (const childScope of scope.values()) if (childScope["#Gen"] !== 0) yield* traverse(childScope, path, args, i);
797
- } else {
798
- const item = scope[path[i]];
799
- if (i) yield* traverse(item, path, args, i - 1);
800
- else yield typeof item === "function" ? item(...args) : item;
807
+ if (scope) {
808
+ if (Symbol.iterator in scope) {
809
+ for (const childScope of scope.values()) if (childScope["#Gen"] !== 0) yield* traverse(childScope, path, args, i);
810
+ } else {
811
+ const item = scope[path[i]];
812
+ if (i) yield* traverse(item, path, args, i - 1);
813
+ else yield typeof item === "function" ? item(...args) : item;
814
+ }
801
815
  }
802
816
  }
803
817
  function _hoist(...path) {
@@ -881,9 +895,8 @@ function readyFailed(readyId) {
881
895
  (failedIds ||= /* @__PURE__ */ new Set()).add(readyId);
882
896
  console.error(`The lazy module for "${readyId}" failed to load; its server-rendered content cannot become interactive.`);
883
897
  }
884
- function withLazy(runtime) {
898
+ function withLazy() {
885
899
  lazyEnabled = 1;
886
- return runtime;
887
900
  }
888
901
  function initEmbedded(readyId, runtimeId) {
889
902
  if (!embedRenders) {
@@ -957,7 +970,7 @@ function init(runtimeId = "M") {
957
970
  setParentBranch(branch, branch[ClosestBranch]);
958
971
  if (branch["#AwaitCounter"] = render.p?.[branchId]) branch[AwaitCounter].m = render.m;
959
972
  if (singleNode) {
960
- while (startVisit.previousSibling && ~visits.indexOf(startVisit = startVisit.previousSibling));
973
+ while (startVisit.previousSibling && (startVisit = startVisit.previousSibling).nodeType > 1);
961
974
  branch["_"] ??= visitScope;
962
975
  branch[EndNode] = branch[StartNode] = startVisit;
963
976
  if (visitType === "(") branch[getDebugKey(0, startVisit)] = startVisit;
@@ -1024,6 +1037,7 @@ function init(runtimeId = "M") {
1024
1037
  let embedAnchor;
1025
1038
  serializeContext._ = _resumed;
1026
1039
  if (render.m) throw new Error(`Marko rendered multiple times with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as ${JSON.stringify(renderId)}. Ensure each render into a page has a unique $global.renderId.`);
1040
+ for (const otherId in curRenders) if (otherId !== renderId && (otherId.startsWith(renderId) || renderId.startsWith(otherId))) console.error(`Marko rendered with $global.runtimeId as ${JSON.stringify(runtimeId)} and $global.renderId as both ${JSON.stringify(otherId)} and ${JSON.stringify(renderId)}, so one render claims the other's resume comments. Ensure no $global.renderId in a page starts another.`);
1027
1041
  render.m = (effects) => {
1028
1042
  processResumes(render.r, effects);
1029
1043
  if (readyIds && render.b) for (let progress = 1; progress;) {
@@ -1039,13 +1053,14 @@ function init(runtimeId = "M") {
1039
1053
  visitText = visit.data;
1040
1054
  visitType = visitText[lastTokenIndex++];
1041
1055
  visitScope = getScope(nextToken());
1042
- if (dynamicHtmlEnabled && visitType > "%" && visitType <= "'") if (visitType === "&") htmlStart = visit;
1043
- else {
1044
- visitScope[nextToken()] = htmlStart;
1045
- visitScope[DynamicHTMLLastChild + lastToken] = visit;
1046
- if ((branchesEnabled || lazyEnabled) && pending[pending.length - 1] !== visitScope) pending.push(visitScope);
1047
- }
1048
- else if (branchesEnabled && visitType > "'") (visitBranches ||= createVisitBranches())();
1056
+ if (dynamicHtmlEnabled && visitType > "%" && visitType <= "'") {
1057
+ if (visitType === "&") htmlStart = visit;
1058
+ else {
1059
+ visitScope[nextToken()] = htmlStart;
1060
+ visitScope[DynamicHTMLLastChild + lastToken] = visit;
1061
+ if ((branchesEnabled || lazyEnabled) && pending[pending.length - 1] !== visitScope) pending.push(visitScope);
1062
+ }
1063
+ } else if (branchesEnabled && visitType > "'") (visitBranches ||= createVisitBranches())();
1049
1064
  else if (lazyEnabled && render.b && visitType > "%") visits[retained++] = visit;
1050
1065
  else {
1051
1066
  visitScope[nextToken()] = visitType === "%" ? visit.parentNode.insertBefore(new Text(), visit) : visit.previousSibling;
@@ -1080,7 +1095,7 @@ let isResuming;
1080
1095
  function runResumeEffects(render) {
1081
1096
  try {
1082
1097
  isResuming = 1;
1083
- runEffects(render.m([]), 1);
1098
+ runEffects(render.m([]));
1084
1099
  } finally {
1085
1100
  isResuming = 0;
1086
1101
  }
@@ -1196,8 +1211,10 @@ function _attr(element, name, value) {
1196
1211
  setAttribute(element, name, normalizeAttrValue(value));
1197
1212
  }
1198
1213
  function setAttribute(element, name, value) {
1199
- if (element.getAttribute(name) != value) if (value === void 0) element.removeAttribute(name);
1200
- else element.setAttribute(name, value);
1214
+ if (element.getAttribute(name) != value) {
1215
+ if (value === void 0) element.removeAttribute(name);
1216
+ else element.setAttribute(name, value);
1217
+ }
1201
1218
  }
1202
1219
  function _attr_class(element, value) {
1203
1220
  setAttribute(element, "class", toDelimitedString(value, " ", stringifyClassObject) || void 0);
@@ -1302,7 +1319,6 @@ function attrsInternal(scope, nodeAccessor, nextAttrs, controllable) {
1302
1319
  assertValidAttrName(name);
1303
1320
  if (isEventHandler(name)) (events ||= scope[EventAttributes + nodeAccessor] = {})[getEventHandlerName(name)] = value;
1304
1321
  else if (!(skip?.test(name) || name === "content" && el.tagName !== "META")) _attr(el, name, value);
1305
- break;
1306
1322
  }
1307
1323
  }
1308
1324
  }
@@ -1335,8 +1351,10 @@ const _html = /*@__PURE__*/ withDynamicHtml(function _html(scope, value, accesso
1335
1351
  });
1336
1352
  function normalizeClientRender(value) {
1337
1353
  const renderer = normalizeDynamicRenderer(value);
1338
- if (renderer) if (renderer["id"]) return renderer;
1339
- else throw new Error(`Invalid \`content\` attribute. Received ${typeof value}`);
1354
+ if (renderer) {
1355
+ if (renderer["id"]) return renderer;
1356
+ else throw new Error(`Invalid \`content\` attribute. Received ${typeof value}`);
1357
+ }
1340
1358
  }
1341
1359
  function normalizeAttrValue(value) {
1342
1360
  if (isNotVoid(value)) return value === true ? "" : value + "";
@@ -1354,7 +1372,7 @@ function _lifecycle(scope, thisObj, index = 0) {
1354
1372
  Object.assign(thisObj, thisObj.onMount?.());
1355
1373
  for (const prop in snapshot) if (!Object.is(snapshot[prop], thisObj[prop])) throw new Error(`Tried to overwrite existing property "${prop}" in <lifecycle> onMount.`);
1356
1374
  }
1357
- $signal(scope, accessor).onabort = () => thisObj.onDestroy?.();
1375
+ trackAbort(scope, accessor, () => thisObj.onDestroy?.());
1358
1376
  }
1359
1377
  }
1360
1378
  function removeChildNodes(startNode, endNode) {
@@ -1456,8 +1474,10 @@ function _attr_input_checkedValue(scope, nodeAccessor, checkedValue, checkedValu
1456
1474
  }
1457
1475
  function _attr_input_checkedValue_script(scope, nodeAccessor) {
1458
1476
  const el = scope[nodeAccessor];
1459
- if (isResuming && el.defaultChecked) if (scope["ControlledValue:" + nodeAccessor]) scope[ControlledValue + nodeAccessor].push(el.value);
1460
- else scope[ControlledValue + nodeAccessor] = el.value;
1477
+ if (isResuming && el.defaultChecked) {
1478
+ if (scope["ControlledValue:" + nodeAccessor]) scope[ControlledValue + nodeAccessor].push(el.value);
1479
+ else scope[ControlledValue + nodeAccessor] = el.value;
1480
+ }
1461
1481
  syncControllableFormInput(el, hasCheckboxChanged, () => {
1462
1482
  const checkedValueChange = scope[ControlledHandler + nodeAccessor];
1463
1483
  if (checkedValueChange) {
@@ -1566,14 +1586,16 @@ function _attr_select_value_script(scope, nodeAccessor) {
1566
1586
  run();
1567
1587
  }
1568
1588
  };
1569
- if (isResuming) if (el.multiple) {
1570
- scope[ControlledValue + nodeAccessor] = [];
1571
- for (const opt of el.options) if (opt.defaultSelected) scope[ControlledValue + nodeAccessor].push(opt.value);
1572
- } else {
1573
- scope[ControlledValue + nodeAccessor] = "";
1574
- for (const opt of el.options) if (opt.defaultSelected) {
1575
- scope[ControlledValue + nodeAccessor] = opt.value;
1576
- break;
1589
+ if (isResuming) {
1590
+ if (el.multiple) {
1591
+ scope[ControlledValue + nodeAccessor] = [];
1592
+ for (const opt of el.options) if (opt.defaultSelected) scope[ControlledValue + nodeAccessor].push(opt.value);
1593
+ } else {
1594
+ scope[ControlledValue + nodeAccessor] = "";
1595
+ for (const opt of el.options) if (opt.defaultSelected) {
1596
+ scope[ControlledValue + nodeAccessor] = opt.value;
1597
+ break;
1598
+ }
1577
1599
  }
1578
1600
  }
1579
1601
  syncControllableFormInput(el, hasSelectChanged, onChange);
@@ -1695,6 +1717,7 @@ function _controllable_open(scope, nodeAccessor, nextAttrs) {
1695
1717
  function _await_promise(nodeAccessor, params) {
1696
1718
  const promiseAccessor = Promise$1 + nodeAccessor;
1697
1719
  const branchAccessor = BranchScopes$1 + nodeAccessor;
1720
+ const tryAccessor = TryBranch$1 + nodeAccessor;
1698
1721
  const resolveAwait = (scope, referenceNode, value) => {
1699
1722
  const awaitBranch = scope[branchAccessor];
1700
1723
  if (awaitBranch["#DetachedAwait"]) {
@@ -1710,80 +1733,73 @@ function _await_promise(nodeAccessor, params) {
1710
1733
  const awaitPromise = (scope, promise) => {
1711
1734
  if (!isPromise(scope[promiseAccessor])) scope[promiseAccessor] = 0;
1712
1735
  let awaitBranch = scope[branchAccessor];
1713
- const tryPlaceholder = (isPromise(promise) || scope[promiseAccessor]) && findBranchWithKey(scope, "#PlaceholderContent");
1714
- const tryBranch = tryPlaceholder || awaitBranch;
1736
+ const tryBranch = scope[tryAccessor] || isPromise(promise) && findTryWithPlaceholder(scope) || awaitBranch;
1715
1737
  if (!tryBranch) {
1716
1738
  const deferred = scope[promiseAccessor] = () => deferred === scope[promiseAccessor] && awaitPromise(scope, promise);
1717
- const awaitCounter = findBranchWithKey(scope, PlaceholderContent)?.[AwaitCounter];
1739
+ const awaitCounter = findTryWithPlaceholder(scope)?.[AwaitCounter];
1718
1740
  if (awaitCounter?.i) {
1719
1741
  const complete = awaitCounter.c;
1720
1742
  awaitCounter.c = () => complete() || queueAsyncRender(scope, deferred);
1721
1743
  }
1722
1744
  return;
1723
1745
  }
1724
- if (!isPromise(promise)) return scope[promiseAccessor] ? awaitPromise(scope, Promise.resolve(promise)) : resolveAwait(scope, scope[nodeAccessor], promise);
1746
+ if (!isPromise(promise)) return scope[tryAccessor] ? awaitPromise(scope, Promise.resolve(promise)) : resolveAwait(scope, scope[nodeAccessor], promise);
1725
1747
  let awaitCounter = tryBranch[AwaitCounter];
1726
- placeholderShown.add(pendingEffects);
1727
- if (!tryPlaceholder && !awaitCounter?.i) awaitCounter = createAwaitCounter(tryBranch, () => {
1728
- if (tryBranch === scope[branchAccessor]) {
1729
- const anchor = scope[nodeAccessor];
1730
- if (anchor.parentNode) {
1731
- const detachedParent = scope[branchAccessor][StartNode].parentNode;
1732
- if (detachedParent === anchor.parentNode) anchor.remove();
1733
- else anchor.replaceWith(detachedParent);
1734
- }
1735
- }
1736
- });
1737
- if (!scope[promiseAccessor]) {
1738
- if (awaitBranch) awaitBranch[PendingRenders] ||= [];
1739
- if (tryPlaceholder) awaitCounter = addAwaitCounter(scope, tryPlaceholder);
1740
- else scheduleAwaitFrame(awaitCounter, scope, () => {
1741
- if (!awaitBranch["#DetachedAwait"]) {
1742
- awaitBranch[StartNode].parentNode.insertBefore(scope[nodeAccessor], awaitBranch[StartNode]);
1743
- tempDetachBranch(tryBranch);
1744
- }
1748
+ if (!scope[tryAccessor]) {
1749
+ scope[tryAccessor] = tryBranch;
1750
+ trackAbort(scope, promiseAccessor, () => {
1751
+ scope[promiseAccessor] = 0;
1752
+ if (scope[tryAccessor]) queueAsyncRender(scope[tryAccessor], completeAwaitCounter, awaitCounter);
1745
1753
  });
1754
+ if (awaitBranch) awaitBranch[PendingRenders] ||= [];
1755
+ if (tryBranch !== awaitBranch) awaitCounter = addAwaitCounter(scope, tryBranch);
1756
+ else {
1757
+ if (!awaitCounter?.i) awaitCounter = createAwaitCounter(tryBranch, () => {
1758
+ if (tryBranch === scope[branchAccessor]) {
1759
+ const anchor = scope[nodeAccessor];
1760
+ if (anchor.parentNode) {
1761
+ const detachedParent = scope[branchAccessor][StartNode].parentNode;
1762
+ if (detachedParent === anchor.parentNode) anchor.remove();
1763
+ else anchor.replaceWith(detachedParent);
1764
+ }
1765
+ }
1766
+ });
1767
+ scheduleAwaitFrame(awaitCounter, scope, () => {
1768
+ if (!awaitBranch["#DetachedAwait"]) {
1769
+ awaitBranch[StartNode].parentNode.insertBefore(scope[nodeAccessor], awaitBranch[StartNode]);
1770
+ tempDetachBranch(tryBranch);
1771
+ }
1772
+ });
1773
+ }
1746
1774
  }
1747
1775
  const thisPromise = scope[promiseAccessor] = promise.then((data) => {
1748
1776
  if (thisPromise === scope[promiseAccessor]) {
1749
1777
  const referenceNode = scope[nodeAccessor];
1750
1778
  scope[promiseAccessor] = 0;
1751
- if (!scope[branchAccessor] || scope["#ClosestBranch"]?.["#Gen"] === 0) {
1752
- if (!scope[branchAccessor]) awaitPromise(scope, data);
1779
+ if (!scope[branchAccessor]) {
1780
+ scope[tryAccessor] = 0;
1781
+ awaitPromise(scope, data);
1753
1782
  awaitCounter.c();
1754
1783
  run();
1755
- return;
1756
- }
1757
- queueAsyncRender(scope, () => {
1758
- awaitBranch = resolveAwait(scope, referenceNode, data);
1759
- const pendingRenders = awaitBranch[PendingRenders];
1760
- awaitBranch[PendingRenders] = 0;
1761
- pendingRenders?.forEach(queuePendingRender);
1762
- placeholderShown.add(pendingEffects);
1763
- awaitCounter.c();
1764
- if (awaitCounter.m) {
1765
- const fnScopes = /* @__PURE__ */ new Map();
1766
- const effects = awaitCounter.m([]);
1767
- for (let i = 0; i < pendingEffects.length;) {
1768
- const fn = pendingEffects[i++];
1769
- let scopes = fnScopes.get(fn);
1770
- if (!scopes) fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1771
- scopes.add(pendingEffects[i++]);
1772
- }
1773
- for (let i = 0; i < effects.length;) {
1774
- const fn = effects[i++];
1775
- const scope = effects[i++];
1776
- if (!fnScopes.get(fn)?.has(scope)) queueEffect(scope, fn);
1777
- }
1784
+ } else queueAsyncRender(scope, () => {
1785
+ if (!scope[promiseAccessor]) {
1786
+ awaitBranch = resolveAwait(scope, referenceNode, data);
1787
+ const pendingRenders = awaitBranch[PendingRenders];
1788
+ awaitBranch[PendingRenders] = 0;
1789
+ pendingRenders?.forEach(queuePendingRender);
1790
+ scope[tryAccessor] = 0;
1791
+ queueCompleteAwaitCounter(tryBranch, awaitCounter);
1778
1792
  }
1779
1793
  });
1780
1794
  }
1781
1795
  }, (error) => {
1782
1796
  if (thisPromise === scope[promiseAccessor]) {
1783
- scope[promiseAccessor] = 0;
1784
- if (tryPlaceholder && !awaitCounter.m) awaitCounter.c();
1785
- else awaitCounter.i = 0;
1797
+ scope[promiseAccessor] = scope[tryAccessor] = 0;
1786
1798
  queueAsyncRender(scope, renderCatch, error);
1799
+ if (tryBranch !== awaitBranch && !awaitCounter.m) {
1800
+ if (findTryWithCatch(scope)) queueCompleteAwaitCounter(tryBranch, awaitCounter);
1801
+ else awaitCounter.c();
1802
+ } else awaitCounter.i = 0;
1787
1803
  }
1788
1804
  });
1789
1805
  };
@@ -1799,13 +1815,13 @@ function _await_content(nodeAccessor, template, walks, setup) {
1799
1815
  if (typeof scope[promiseAccessor] === "function") scope[promiseAccessor]();
1800
1816
  };
1801
1817
  }
1802
- function addAwaitCounter(scope, tryBranch = findBranchWithKey(scope, PlaceholderContent)) {
1818
+ function addAwaitCounter(scope, tryBranch = findTryWithPlaceholder(scope)) {
1803
1819
  if (!tryBranch) return;
1804
1820
  let awaitCounter = tryBranch[AwaitCounter];
1805
1821
  if (!awaitCounter?.i) awaitCounter = createAwaitCounter(tryBranch, () => dismissPlaceholder(tryBranch));
1806
- placeholderShown.add(pendingEffects);
1807
1822
  scheduleAwaitFrame(awaitCounter, tryBranch, () => {
1808
- insertBranchBefore(tryBranch[PlaceholderBranch] = createAndSetupBranch(tryBranch[Global], tryBranch[PlaceholderContent], tryBranch["_"], tryBranch[StartNode].parentNode), tryBranch[StartNode].parentNode, tryBranch[StartNode]);
1823
+ (tryBranch[PlaceholderBranch] = createAndSetupBranch(tryBranch[Global], tryBranch[PlaceholderContent](), tryBranch["_"], tryBranch[StartNode].parentNode))[TryBranch] = tryBranch;
1824
+ insertBranchBefore(tryBranch[PlaceholderBranch], tryBranch[StartNode].parentNode, tryBranch[StartNode]);
1809
1825
  tempDetachBranch(tryBranch);
1810
1826
  });
1811
1827
  return awaitCounter;
@@ -1813,10 +1829,32 @@ function addAwaitCounter(scope, tryBranch = findBranchWithKey(scope, Placeholder
1813
1829
  function scheduleAwaitFrame(awaitCounter, scope, render) {
1814
1830
  if (!awaitCounter.i++) requestAnimationFrame(() => awaitCounter.i && runEffects(prepareEffects(() => queueRender(scope, render, -1))));
1815
1831
  }
1832
+ function queueCompleteAwaitCounter(tryBranch, awaitCounter) {
1833
+ queueRender(tryBranch, completeAwaitCounter, -1, awaitCounter, tryBranch["#Id"] + 1e9);
1834
+ }
1835
+ function completeAwaitCounter(_scope, awaitCounter) {
1836
+ awaitCounter.c();
1837
+ if (awaitCounter.m) {
1838
+ const fnScopes = /* @__PURE__ */ new Map();
1839
+ const effects = awaitCounter.m([]);
1840
+ for (let i = 0; i < pendingEffects.length;) {
1841
+ const fn = pendingEffects[i++];
1842
+ let scopes = fnScopes.get(fn);
1843
+ if (!scopes) fnScopes.set(fn, scopes = /* @__PURE__ */ new Set());
1844
+ scopes.add(pendingEffects[i++]);
1845
+ }
1846
+ for (let i = 0; i < effects.length;) {
1847
+ const fn = effects[i++];
1848
+ const scope = effects[i++];
1849
+ if (!fnScopes.get(fn)?.has(scope)) queueEffect(scope, fn);
1850
+ }
1851
+ }
1852
+ }
1816
1853
  function createAwaitCounter(tryBranch, done) {
1817
1854
  const awaitCounter = tryBranch[AwaitCounter] = {
1818
1855
  i: 0,
1819
1856
  c() {
1857
+ if (awaitCounter.i < 1) throw new Error("An await counter completed more counts than it took.");
1820
1858
  if (--awaitCounter.i) return 1;
1821
1859
  done();
1822
1860
  queueEffect(tryBranch, runPendingEffects);
@@ -1824,12 +1862,8 @@ function createAwaitCounter(tryBranch, done) {
1824
1862
  };
1825
1863
  return awaitCounter;
1826
1864
  }
1827
- function runPendingEffects(scope) {
1828
- const effects = scope[PendingEffects];
1829
- if (effects) {
1830
- scope[PendingEffects] = [];
1831
- runEffects(effects, 1);
1832
- }
1865
+ function runPendingEffects(tryBranch) {
1866
+ tryBranch[PendingEffectScopes]?.forEach((scope) => scope[PendingEffects].forEach((fn) => runEffects([fn, scope]), scope[PendingEffects] = null), tryBranch[PendingEffectScopes] = null);
1833
1867
  }
1834
1868
  function dismissPlaceholder(tryBranch) {
1835
1869
  const placeholderBranch = tryBranch[PlaceholderBranch];
@@ -1839,21 +1873,19 @@ function dismissPlaceholder(tryBranch) {
1839
1873
  removeAndDestroyBranch(placeholderBranch);
1840
1874
  }
1841
1875
  }
1842
- function _try(nodeAccessor, template, walks, setup) {
1876
+ function _try(nodeAccessor, template, walks, setup, placeholderContent, catchContent) {
1843
1877
  const branchAccessor = BranchScopes$1 + nodeAccessor;
1844
1878
  const renderer = _content("", template, walks, setup)();
1845
- return (scope, input) => {
1846
- if (!scope[branchAccessor]) setConditionalRenderer(scope, nodeAccessor, renderer, createAndSetupBranch);
1879
+ return (scope) => {
1880
+ setConditionalRenderer(scope, nodeAccessor, renderer, createAndSetupBranch);
1847
1881
  const branch = scope[branchAccessor];
1848
- if (branch) {
1849
- branch[BranchAccessor] = nodeAccessor;
1850
- branch[CatchContent] = input.catch && (normalizeDynamicRenderer(input.catch) || 0);
1851
- branch[PlaceholderContent] = normalizeDynamicRenderer(input.placeholder);
1852
- }
1882
+ branch[BranchAccessor] = nodeAccessor;
1883
+ branch[CatchContent] = catchContent;
1884
+ branch[PlaceholderContent] = placeholderContent || void 0;
1853
1885
  };
1854
1886
  }
1855
1887
  function renderCatch(scope, error) {
1856
- const tryWithCatch = findBranchWithKey(scope, CatchContent);
1888
+ const tryWithCatch = findTryWithCatch(scope);
1857
1889
  if (!tryWithCatch) throw error;
1858
1890
  else {
1859
1891
  const owner = tryWithCatch["_"];
@@ -1863,11 +1895,21 @@ function renderCatch(scope, error) {
1863
1895
  owner[BranchScopes$1 + tryWithCatch[BranchAccessor]] = placeholderBranch;
1864
1896
  destroyBranch(tryWithCatch);
1865
1897
  }
1866
- caughtError.add(pendingEffects);
1867
- setConditionalRenderer(owner, tryWithCatch[BranchAccessor], tryWithCatch[CatchContent], createAndSetupBranch);
1868
- tryWithCatch[CatchContent]?.[Params]?.(owner[BranchScopes$1 + tryWithCatch[BranchAccessor]], [error]);
1898
+ const catchContent = tryWithCatch[CatchContent]();
1899
+ setConditionalRenderer(owner, tryWithCatch[BranchAccessor], catchContent, createAndSetupBranch);
1900
+ catchContent[Params]?.(owner[BranchScopes$1 + tryWithCatch[BranchAccessor]], [error]);
1869
1901
  }
1870
1902
  }
1903
+ function findTryWithPlaceholder(scope) {
1904
+ let branch = scope[ClosestBranch];
1905
+ while (branch && !branch["#PlaceholderContent"]) branch = branch[ParentBranch];
1906
+ return branch;
1907
+ }
1908
+ function findTryWithCatch(scope) {
1909
+ let branch = scope[ClosestBranch];
1910
+ while (branch && !branch["#CatchContent"]) branch = branch["#TryBranch"] || branch["#ParentBranch"];
1911
+ return branch;
1912
+ }
1871
1913
  const _if = /*@__PURE__*/ withBranches((nodeAccessor, ...branchesArgs) => {
1872
1914
  const branchAccessor = ConditionalRenderer + nodeAccessor;
1873
1915
  const branches = [];
@@ -1924,10 +1966,12 @@ let _dynamic_tag = /*@__PURE__*/ withBranches((nodeAccessor, getContent, getTagV
1924
1966
  if (scope[rendererAccessor] !== (scope[rendererAccessor] = rendererKey(normalizedRenderer)) || getContent && !(normalizedRenderer || scope[childScopeAccessor])) {
1925
1967
  const renderer = normalizedRenderer || (getContent ? getContent(scope) : void 0);
1926
1968
  setConditionalRenderer(scope, nodeAccessor, renderer, createBranchWithTagNameOrRenderer);
1927
- if (getTagVar) if (scope[childScopeAccessor]) {
1928
- scope[childScopeAccessor][TagVariable] = (value) => getTagVar()(scope, value);
1929
- if (typeof normalizedRenderer === "string") bindNativeTagVar?.(scope[childScopeAccessor]);
1930
- } else getTagVar()(scope, void 0);
1969
+ if (getTagVar) {
1970
+ if (scope[childScopeAccessor]) {
1971
+ scope[childScopeAccessor][TagVariable] = (value) => getTagVar()(scope, value);
1972
+ if (typeof normalizedRenderer === "string") bindNativeTagVar?.(scope[childScopeAccessor]);
1973
+ } else getTagVar()(scope, void 0);
1974
+ }
1931
1975
  if (typeof renderer === "string") {
1932
1976
  if (getContent) {
1933
1977
  const content = getContent(scope);
@@ -1945,13 +1989,15 @@ let _dynamic_tag = /*@__PURE__*/ withBranches((nodeAccessor, getContent, getTagV
1945
1989
  if (childScope["EventAttributes:" + nodeAccessor] || childScope["ControlledHandler:" + nodeAccessor]) queueEffect(childScope, dynamicTagScript);
1946
1990
  } else {
1947
1991
  normalizedRenderer[LocalClosures]?.(childScope);
1948
- if (normalizedRenderer["params"]) if (inputIsArgs) normalizedRenderer[Params](childScope, normalizedRenderer._ ? args[0] : args);
1949
- else {
1950
- const inputWithContent = getContent ? {
1951
- ...args,
1952
- content: getContent(scope)
1953
- } : args || {};
1954
- normalizedRenderer[Params](childScope, normalizedRenderer._ ? inputWithContent : [inputWithContent]);
1992
+ if (normalizedRenderer["params"]) {
1993
+ if (inputIsArgs) normalizedRenderer[Params](childScope, normalizedRenderer._ ? args[0] : args);
1994
+ else {
1995
+ const inputWithContent = getContent ? {
1996
+ ...args,
1997
+ content: getContent(scope)
1998
+ } : args || {};
1999
+ normalizedRenderer[Params](childScope, normalizedRenderer._ ? inputWithContent : [inputWithContent]);
2000
+ }
1955
2001
  }
1956
2002
  }
1957
2003
  }
@@ -2089,20 +2135,22 @@ function reorderKeyed(newScopes, start, newEnd, parentNode, afterReference) {
2089
2135
  let hi;
2090
2136
  let mid;
2091
2137
  for (let i = diffLen; i--;) sources[i] = newScopes[start + i]["#LoopIndex"] ?? -1;
2092
- for (let i = 0; i < diffLen; i++) if (~sources[i]) if (tail < 0 || sources[tails[tail]] < sources[i]) {
2093
- if (~tail) pred[i] = tails[tail];
2094
- tails[++tail] = i;
2095
- } else {
2096
- lo = 0;
2097
- hi = tail;
2098
- while (lo < hi) {
2099
- mid = (lo + hi) / 2 | 0;
2100
- if (sources[tails[mid]] < sources[i]) lo = mid + 1;
2101
- else hi = mid;
2102
- }
2103
- if (sources[i] < sources[tails[lo]]) {
2104
- if (lo > 0) pred[i] = tails[lo - 1];
2105
- tails[lo] = i;
2138
+ for (let i = 0; i < diffLen; i++) if (~sources[i]) {
2139
+ if (tail < 0 || sources[tails[tail]] < sources[i]) {
2140
+ if (~tail) pred[i] = tails[tail];
2141
+ tails[++tail] = i;
2142
+ } else {
2143
+ lo = 0;
2144
+ hi = tail;
2145
+ while (lo < hi) {
2146
+ mid = (lo + hi) / 2 | 0;
2147
+ if (sources[tails[mid]] < sources[i]) lo = mid + 1;
2148
+ else hi = mid;
2149
+ }
2150
+ if (sources[i] < sources[tails[lo]]) {
2151
+ if (lo > 0) pred[i] = tails[lo - 1];
2152
+ tails[lo] = i;
2153
+ }
2106
2154
  }
2107
2155
  }
2108
2156
  hi = tails[tail];
@@ -2221,6 +2269,12 @@ Object.defineProperty(exports, "Pending", {
2221
2269
  return Pending;
2222
2270
  }
2223
2271
  });
2272
+ Object.defineProperty(exports, "PendingEffectScopes", {
2273
+ enumerable: true,
2274
+ get: function() {
2275
+ return PendingEffectScopes;
2276
+ }
2277
+ });
2224
2278
  Object.defineProperty(exports, "PendingEffects", {
2225
2279
  enumerable: true,
2226
2280
  get: function() {
@@ -2797,12 +2851,6 @@ Object.defineProperty(exports, "addAwaitCounter", {
2797
2851
  return addAwaitCounter;
2798
2852
  }
2799
2853
  });
2800
- Object.defineProperty(exports, "caughtError", {
2801
- enumerable: true,
2802
- get: function() {
2803
- return caughtError;
2804
- }
2805
- });
2806
2854
  Object.defineProperty(exports, "controllableRenders", {
2807
2855
  enumerable: true,
2808
2856
  get: function() {
@@ -2911,12 +2959,6 @@ Object.defineProperty(exports, "patchDynamicTag", {
2911
2959
  return patchDynamicTag;
2912
2960
  }
2913
2961
  });
2914
- Object.defineProperty(exports, "placeholderShown", {
2915
- enumerable: true,
2916
- get: function() {
2917
- return placeholderShown;
2918
- }
2919
- });
2920
2962
  Object.defineProperty(exports, "prepareEffects", {
2921
2963
  enumerable: true,
2922
2964
  get: function() {
@@ -2965,6 +3007,12 @@ Object.defineProperty(exports, "renderCatch", {
2965
3007
  return renderCatch;
2966
3008
  }
2967
3009
  });
3010
+ Object.defineProperty(exports, "rendering", {
3011
+ enumerable: true,
3012
+ get: function() {
3013
+ return rendering;
3014
+ }
3015
+ });
2968
3016
  Object.defineProperty(exports, "run", {
2969
3017
  enumerable: true,
2970
3018
  get: function() {
@@ -2983,6 +3031,12 @@ Object.defineProperty(exports, "runId", {
2983
3031
  return runId;
2984
3032
  }
2985
3033
  });
3034
+ Object.defineProperty(exports, "runPendingEffects", {
3035
+ enumerable: true,
3036
+ get: function() {
3037
+ return runPendingEffects;
3038
+ }
3039
+ });
2986
3040
  Object.defineProperty(exports, "setupBranch", {
2987
3041
  enumerable: true,
2988
3042
  get: function() {