marko 6.4.1 → 6.4.2

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 (73) hide show
  1. package/cheatsheet.md +1 -1
  2. package/dist/common/errors.d.ts +1 -0
  3. package/dist/common/opt.d.ts +1 -0
  4. package/dist/debug/dom/catch.feat.js +1 -1
  5. package/dist/debug/dom/catch.feat.mjs +1 -1
  6. package/dist/debug/dom/controllable-input.feat.js +1 -1
  7. package/dist/debug/dom/controllable-input.feat.mjs +1 -1
  8. package/dist/debug/dom/controllable-open.feat.js +1 -1
  9. package/dist/debug/dom/controllable-open.feat.mjs +1 -1
  10. package/dist/debug/dom/controllable-select.feat.js +1 -1
  11. package/dist/debug/dom/controllable-select.feat.mjs +1 -1
  12. package/dist/debug/dom/controllable-textarea.feat.js +1 -1
  13. package/dist/debug/dom/controllable-textarea.feat.mjs +1 -1
  14. package/dist/debug/dom/controllable.feat.js +1 -1
  15. package/dist/debug/dom/controllable.feat.mjs +1 -1
  16. package/dist/debug/dom/dynamic-tag-script.feat.js +1 -1
  17. package/dist/debug/dom/dynamic-tag-script.feat.mjs +1 -1
  18. package/dist/debug/dom/dynamic-tag-var.feat.js +1 -1
  19. package/dist/debug/dom/dynamic-tag-var.feat.mjs +1 -1
  20. package/dist/debug/dom/lazy.feat.js +1 -1
  21. package/dist/debug/dom/lazy.feat.mjs +1 -1
  22. package/dist/debug/dom/placeholder.feat.js +1 -1
  23. package/dist/debug/dom/placeholder.feat.mjs +1 -1
  24. package/dist/debug/{dom-ClV4kVOO.js → dom-BLbR0hEx.js} +30 -0
  25. package/dist/debug/{dom-LFrKxOk5.mjs → dom-Cii0IA92.mjs} +19 -1
  26. package/dist/debug/dom.js +7 -4
  27. package/dist/debug/dom.mjs +6 -5
  28. package/dist/debug/html.js +280 -76
  29. package/dist/debug/html.mjs +280 -77
  30. package/dist/dom/catch.feat.js +3 -3
  31. package/dist/dom/catch.feat.mjs +1 -1
  32. package/dist/dom/controllable-input.feat.js +1 -1
  33. package/dist/dom/controllable-input.feat.mjs +1 -1
  34. package/dist/dom/controllable-open.feat.js +1 -1
  35. package/dist/dom/controllable-open.feat.mjs +1 -1
  36. package/dist/dom/controllable-select.feat.js +1 -1
  37. package/dist/dom/controllable-select.feat.mjs +1 -1
  38. package/dist/dom/controllable-textarea.feat.js +1 -1
  39. package/dist/dom/controllable-textarea.feat.mjs +1 -1
  40. package/dist/dom/controllable.feat.js +1 -1
  41. package/dist/dom/controllable.feat.mjs +1 -1
  42. package/dist/dom/dom.d.ts +1 -0
  43. package/dist/dom/dynamic-tag-script.feat.js +2 -2
  44. package/dist/dom/dynamic-tag-script.feat.mjs +1 -1
  45. package/dist/dom/dynamic-tag-var.feat.js +1 -1
  46. package/dist/dom/dynamic-tag-var.feat.mjs +1 -1
  47. package/dist/dom/lazy.feat.js +1 -1
  48. package/dist/dom/lazy.feat.mjs +1 -1
  49. package/dist/dom/placeholder.feat.js +3 -3
  50. package/dist/dom/placeholder.feat.mjs +1 -1
  51. package/dist/{dom-CNglVi8P.js → dom-B8UEYzOz.js} +99 -80
  52. package/dist/{dom-DfP3MCo0.mjs → dom-BPjLe6YU.mjs} +10 -1
  53. package/dist/dom.d.ts +2 -2
  54. package/dist/dom.js +34 -33
  55. package/dist/dom.mjs +6 -5
  56. package/dist/html/assets.d.ts +12 -6
  57. package/dist/html/attrs.d.ts +1 -0
  58. package/dist/html/compat.d.ts +10 -2
  59. package/dist/html/serializer.d.ts +1 -0
  60. package/dist/html/writer.d.ts +8 -0
  61. package/dist/html.d.ts +1 -1
  62. package/dist/html.js +194 -59
  63. package/dist/html.mjs +194 -59
  64. package/dist/translator/index.js +404 -190
  65. package/dist/translator/util/bindings.d.ts +9 -1
  66. package/dist/translator/util/constants/structure-kind.d.ts +1 -0
  67. package/dist/translator/util/known-tag.d.ts +2 -1
  68. package/dist/translator/util/module-read.d.ts +21 -0
  69. package/dist/translator/util/references.d.ts +1 -0
  70. package/dist/translator/util/runtime.d.ts +2 -0
  71. package/dist/translator/util/sections.d.ts +5 -1
  72. package/dist/translator/util/structure.d.ts +1 -0
  73. package/package.json +3 -3
@@ -162,6 +162,16 @@ function assertValidAttrValue(name, value) {
162
162
  const unrenderable = describeUnrenderable(value);
163
163
  if (unrenderable) throw new Error(`The \`${name}\` attribute cannot be ${unrenderable}.`);
164
164
  }
165
+ function _assert_class_toggles(classes, toggles) {
166
+ {
167
+ const written = new Set(classes.split(" "));
168
+ for (const toggle of toggles) {
169
+ const names = new Set(toggle.split(" "));
170
+ for (const name of names) if (written.has(name)) throw new Error(`The toggled class \`${name}\` is also written by another part of the \`class\` value; a toggled class may appear only once.`);
171
+ for (const name of names) written.add(name);
172
+ }
173
+ }
174
+ }
165
175
  function assertValidTextValue(value) {
166
176
  const unrenderable = describeUnrenderable(value);
167
177
  if (unrenderable) throw new Error(`Text content cannot be ${unrenderable}.`);
@@ -294,6 +304,13 @@ function forUntil(until, from, step, cb) {
294
304
  }
295
305
  //#endregion
296
306
  //#region src/common/opt.ts
307
+ function reduce(opt, cb, acc) {
308
+ if (opt) {
309
+ if (Array.isArray(opt)) for (const item of opt) acc = cb(acc, item);
310
+ else acc = cb(acc, opt);
311
+ }
312
+ return acc;
313
+ }
297
314
  function push(opt, item) {
298
315
  return opt ? Array.isArray(opt) ? (opt.push(item), opt) : [opt, item] : item;
299
316
  }
@@ -642,6 +659,17 @@ var Serializer = class {
642
659
  channel
643
660
  });
644
661
  }
662
+ dropCall(value, object, property) {
663
+ const { mutated } = this.#state;
664
+ for (let i = 0; i < mutated.length; i++) {
665
+ const mutation = mutated[i];
666
+ if (mutation.value === value && mutation.object === object && mutation.property === property) {
667
+ mutated.splice(i, 1);
668
+ return true;
669
+ }
670
+ }
671
+ return false;
672
+ }
645
673
  };
646
674
  function register(id, val, scope, locals) {
647
675
  REGISTRY.set(val, {
@@ -2233,6 +2261,15 @@ function _html(html) {
2233
2261
  function writeScript(script) {
2234
2262
  $chunk.writeScript(script);
2235
2263
  }
2264
+ function catchableBoundary() {
2265
+ const { boundary } = $chunk;
2266
+ return boundary.withinCatch ? boundary : null;
2267
+ }
2268
+ function mayDrop(written) {
2269
+ const { boundary } = $chunk;
2270
+ for (let cur = written; cur && !isWithin(boundary, cur); cur = cur.parent) if (cur.aborted || cur.count) return true;
2271
+ return false;
2272
+ }
2236
2273
  function _script(scopeId, registryId, markerGuard) {
2237
2274
  if (markerGuard === 0 && ($chunk.serializeState.readyId || $chunk.context?.[kIsAsync])) _resume_branch(scopeId);
2238
2275
  $chunk.boundary.state.needsMainRuntime = true;
@@ -2462,10 +2499,12 @@ function scopeWithId(state, scopeId) {
2462
2499
  }
2463
2500
  function _subscribe(subscribers, scope, resumeId, markerGuard) {
2464
2501
  if (subscribers) {
2465
- const { serializer } = $chunk.boundary.state;
2466
- if (!$chunk.serializeState.readyId && !serializer.written(subscribers)) subscribers.add(scope);
2502
+ const { boundary, serializeState } = $chunk;
2503
+ const { serializer } = boundary.state;
2504
+ if (!serializeState.readyId && !serializer.written(subscribers)) subscribers.add(scope);
2467
2505
  else if (resumeId) _script(scope[K_SCOPE_ID], resumeId, markerGuard);
2468
- else serializer.writeCall(scope, subscribers, "add", $chunk.serializeState);
2506
+ else serializer.writeCall(scope, subscribers, "add", serializeState);
2507
+ if (boundary.withinCatch) (boundary.subscribed ||= []).push(subscribers, scope, serializeState);
2469
2508
  }
2470
2509
  return scope;
2471
2510
  }
@@ -2594,6 +2633,7 @@ function tryBoundary(content, catchContent, branchId, renderers) {
2594
2633
  const { boundary } = chunk;
2595
2634
  const { state } = boundary;
2596
2635
  const catchBoundary = new Boundary(state, void 0, boundary);
2636
+ if (catchContent) catchBoundary.withinCatch = true;
2597
2637
  const body = chunk.fork(catchBoundary, null);
2598
2638
  const bodyEnd = body.render(() => withBranchId(branchId, content));
2599
2639
  if (catchBoundary.aborted) {
@@ -2627,8 +2667,10 @@ function tryBoundary(content, catchContent, branchId, renderers) {
2627
2667
  const streamed = !chunk.catchRange;
2628
2668
  const catchChunk = chunk.fork(boundary, null);
2629
2669
  chunk.catchRange = null;
2670
+ if (!renderersAtSettle) catchChunk.render(clearTryRenderers, branchId);
2630
2671
  const inOrder = catchChunk === catchChunk.render(catchContent, catchBoundary.reason);
2631
2672
  if (boundary.aborted) return;
2673
+ if (bodyEnd.consumed || !inOrder) catchChunk.reorderStart = state.mark("*", branchId + "");
2632
2674
  if (bodyEnd.consumed) {
2633
2675
  catchChunk.reorderId = reorderId;
2634
2676
  state.reorder(catchChunk);
@@ -2657,6 +2699,20 @@ function tryBoundary(content, catchContent, branchId, renderers) {
2657
2699
  };
2658
2700
  return renderersAtSettle;
2659
2701
  }
2702
+ function unsubscribe(subscribed, serializer) {
2703
+ for (let i = 0; i < subscribed.length; i += 3) {
2704
+ const subscribers = subscribed[i];
2705
+ const scope = subscribed[i + 1];
2706
+ if (!serializer.written(subscribers)) subscribers.delete(scope);
2707
+ else if (!serializer.dropCall(scope, subscribers, "add")) serializer.writeCall(scope, subscribers, "delete", subscribed[i + 2]);
2708
+ }
2709
+ }
2710
+ function clearTryRenderers(branchId) {
2711
+ writeScope(branchId, {
2712
+ [CatchContent]: 0,
2713
+ [PlaceholderContent]: _scope_with_id(branchId)["#PlaceholderContent"] && 0
2714
+ });
2715
+ }
2660
2716
  function writeTryRenderers(branchId, catchContent, placeholderContent) {
2661
2717
  writeScope(branchId, {
2662
2718
  [CatchContent]: catchContent,
@@ -2765,12 +2821,15 @@ var Boundary = class {
2765
2821
  parent;
2766
2822
  aborted = false;
2767
2823
  reason;
2824
+ subscribed;
2768
2825
  pendingReorders;
2769
2826
  children;
2827
+ withinCatch = false;
2770
2828
  constructor(state, signal, parent) {
2771
2829
  this.state = state;
2772
2830
  this.parent = parent;
2773
2831
  if (parent) {
2832
+ this.withinCatch = parent.withinCatch;
2774
2833
  if (parent.aborted) this.abort(parent.reason);
2775
2834
  else (parent.children ||= []).push(this);
2776
2835
  } else if (signal) {
@@ -2783,6 +2842,7 @@ var Boundary = class {
2783
2842
  const { state } = this;
2784
2843
  this.aborted = true;
2785
2844
  this.reason = reason;
2845
+ if (this.subscribed) unsubscribe(this.subscribed, state.serializer);
2786
2846
  if (this.pendingReorders) {
2787
2847
  for (const reorder of this.pendingReorders) state.reorder(reorder);
2788
2848
  this.pendingReorders = void 0;
@@ -2818,7 +2878,9 @@ var Chunk = class Chunk {
2818
2878
  async = false;
2819
2879
  consumed = false;
2820
2880
  reorderId = null;
2881
+ reorderStart = "";
2821
2882
  deferredReady = null;
2883
+ heldEffects = null;
2822
2884
  deferredReorder = null;
2823
2885
  catchRange = null;
2824
2886
  placeholder = null;
@@ -2840,7 +2902,7 @@ var Chunk = class Chunk {
2840
2902
  }
2841
2903
  writeEffect(scopeId, registryId) {
2842
2904
  countResumeWrite(this);
2843
- if (this.lastEffect === registryId) this.effects += " " + scopeId;
2905
+ if (this.lastEffect === registryId) this.effects = concatEffects(this.effects, scopeId + "");
2844
2906
  else {
2845
2907
  this.lastEffect = registryId;
2846
2908
  this.effects = concatEffects(this.effects, registryId + " " + scopeId);
@@ -2856,6 +2918,11 @@ var Chunk = class Chunk {
2856
2918
  this.lastEffect = chunk.lastEffect || this.lastEffect;
2857
2919
  this.deferredReady = concat(this.deferredReady, chunk.takeDeferredReady());
2858
2920
  }
2921
+ takeHeldEffects() {
2922
+ const { heldEffects } = this;
2923
+ this.heldEffects = null;
2924
+ return heldEffects;
2925
+ }
2859
2926
  takeDeferredReady() {
2860
2927
  const { deferredReady } = this;
2861
2928
  this.deferredReady = null;
@@ -2908,7 +2975,7 @@ var Chunk = class Chunk {
2908
2975
  return false;
2909
2976
  }
2910
2977
  const { branchId, scopeId, placeholderBranchId } = placeholder;
2911
- const reorderId = body.reorderId = branchId ? branchId + "" : state.nextReorderId();
2978
+ const reorderId = body.reorderId = branchId + "";
2912
2979
  this.writeHTML(state.mark("!^", reorderId));
2913
2980
  const { effects } = this;
2914
2981
  const beforeBranch = deferBranchStart(this);
@@ -2919,7 +2986,7 @@ var Chunk = class Chunk {
2919
2986
  if (stateful) {
2920
2987
  this.render(() => writeScope(branchId, { [PlaceholderBranch]: scopeWithId(state, placeholderBranchId) }));
2921
2988
  this.writeHTML(state.mark("]", scopeId + " " + (PlaceholderBranch + branchId) + " " + placeholderBranchId));
2922
- end.writeEffect(branchId, PLACEHOLDER_DISMISS_REGISTER_ID);
2989
+ dismissChunk(end, body).writeEffect(branchId, PLACEHOLDER_DISMISS_REGISTER_ID);
2923
2990
  }
2924
2991
  this.writeHTML(state.mark("!", reorderId));
2925
2992
  this.deferredReorder = body;
@@ -2947,28 +3014,46 @@ var Chunk = class Chunk {
2947
3014
  let html = "";
2948
3015
  let effects = "";
2949
3016
  let scripts = "";
2950
- let lastEffect = "";
3017
+ let effectsEnd;
3018
+ let heldEffects = this.heldEffects;
2951
3019
  let deferredReady;
3020
+ this.heldEffects = null;
3021
+ if (this.serializeState.readyId && this.effects) followHeldEffects(this);
2952
3022
  while (cur.next && !cur.async) {
2953
3023
  cur.markCatchRange();
2954
3024
  cur.queueDeferredReorder();
2955
3025
  html += cur.html;
2956
3026
  if (cur.serializeState.readyId) deferredReady = push(deferredReady, cur);
2957
3027
  else {
2958
- effects = concatEffects(effects, cur.effects);
3028
+ if (cur.effects) {
3029
+ if (effectsEnd && effectsEnd.boundary !== cur.boundary) {
3030
+ heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
3031
+ effects = "";
3032
+ }
3033
+ effectsEnd = cur;
3034
+ effects = concatEffects(effects, cur.effects);
3035
+ }
2959
3036
  scripts = concatScripts(scripts, cur.scripts);
2960
- lastEffect = cur.lastEffect || lastEffect;
2961
3037
  }
2962
3038
  deferredReady = concat(deferredReady, cur.takeDeferredReady());
2963
3039
  cur.consumed = true;
2964
3040
  cur = cur.next;
2965
3041
  }
2966
3042
  cur.deferOwnReady();
3043
+ if (effects) {
3044
+ if (cur.serializeState.readyId) heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
3045
+ else if (effectsEnd.boundary !== cur.boundary) {
3046
+ heldEffects = holdEffectsOn(heldEffects, effectsEnd, effects);
3047
+ if (isWithin(cur.boundary, effectsEnd.boundary)) cur.lastEffect ||= effectsEnd.lastEffect;
3048
+ } else {
3049
+ cur.effects = concatEffects(effects, cur.effects);
3050
+ cur.lastEffect ||= effectsEnd.lastEffect;
3051
+ }
3052
+ }
3053
+ cur.heldEffects = heldEffects;
2967
3054
  cur.deferredReady = concat(deferredReady, cur.deferredReady);
2968
3055
  cur.html = html + cur.html;
2969
- cur.effects = concatEffects(effects, cur.effects);
2970
3056
  cur.scripts = concatScripts(scripts, cur.scripts);
2971
- cur.lastEffect ||= lastEffect;
2972
3057
  return cur;
2973
3058
  }
2974
3059
  render(content, val) {
@@ -3021,6 +3106,7 @@ var Chunk = class Chunk {
3021
3106
  const { $global, runtimePrefix } = state;
3022
3107
  let needsWalk = state.walkOnNextFlush;
3023
3108
  if (needsWalk) state.walkOnNextFlush = false;
3109
+ flushSerializer(boundary, state);
3024
3110
  let readyResumeScripts = this.flushReadyScripts(boundary, void 0, this.async);
3025
3111
  for (let channel; !boundary.aborted && (channel = state.serializer.pendingReadyChannel());) {
3026
3112
  const resumes = state.serializer.stringifyScopes([], boundary, channel);
@@ -3029,8 +3115,9 @@ var Chunk = class Chunk {
3029
3115
  readyResumeScripts = concatScripts(readyResumeScripts, state.writeReady(channel.readyId, concatSequence(depsMarker(deps), resumes)));
3030
3116
  }
3031
3117
  if (readyResumeScripts) needsWalk = true;
3032
- const effects = this.async ? "" : this.effects;
3118
+ const effects = this.async ? "" : joinHeldEffects(this.takeHeldEffects(), this.effects);
3033
3119
  let { html, scripts } = this;
3120
+ if (html && state.hasReorderRuntime) html = state.mark("*", "") + html;
3034
3121
  if (state.needsMainRuntime && !state.hasMainRuntime) {
3035
3122
  state.hasMainRuntime = true;
3036
3123
  scripts = concatScripts(scripts, WALKER_RUNTIME_CODE + "(\"" + $global.runtimeId + "\")(\"" + $global.renderId + "\")");
@@ -3049,10 +3136,11 @@ var Chunk = class Chunk {
3049
3136
  state.hasReorderRuntime = true;
3050
3137
  scripts = concatScripts(scripts, REORDER_RUNTIME_CODE + "(" + runtimePrefix + ")");
3051
3138
  }
3052
- const { reorderId } = reorderedChunk;
3139
+ const { reorderId, reorderStart } = reorderedChunk;
3053
3140
  const readyReservations = [];
3054
3141
  let reorderHTML = "";
3055
3142
  let reorderEffects = "";
3143
+ let effectsBoundary = reorderedChunk.boundary;
3056
3144
  let reorderScripts = "";
3057
3145
  let cur = reorderedChunk.boundary.aborted ? null : reorderedChunk;
3058
3146
  reorderedChunk.reorderId = null;
@@ -3065,10 +3153,18 @@ var Chunk = class Chunk {
3065
3153
  this.deferredReady = concat(this.deferredReady, cur.takeDeferredReady());
3066
3154
  cur.consumed = true;
3067
3155
  reorderHTML += cur.html;
3156
+ if (this.async && cur.effects && cur.boundary !== effectsBoundary) {
3157
+ if (reorderEffects) {
3158
+ holdReorderEffects(this, effectsBoundary, reorderEffects);
3159
+ reorderEffects = "";
3160
+ }
3161
+ effectsBoundary = cur.boundary;
3162
+ }
3068
3163
  reorderEffects = concatEffects(reorderEffects, cur.effects);
3069
3164
  reorderScripts = concatScripts(reorderScripts, concatScripts(readyResumeScripts, cur.scripts));
3070
3165
  if (cur.async) {
3071
3166
  reorderHTML += state.mark("#", cur.reorderId = state.nextReorderId());
3167
+ cur.reorderStart = reorderStart;
3072
3168
  (cur.boundary.pendingReorders ||= /* @__PURE__ */ new Set()).add(cur);
3073
3169
  cur.html = cur.effects = cur.scripts = cur.lastEffect = "";
3074
3170
  cur.next = null;
@@ -3076,21 +3172,18 @@ var Chunk = class Chunk {
3076
3172
  cur = next;
3077
3173
  }
3078
3174
  if (reorderEffects) {
3079
- if (this.async) {
3080
- this.effects = concatEffects(this.effects, reorderEffects);
3081
- this.lastEffect = "";
3082
- } else {
3175
+ if (this.async) holdReorderEffects(this, effectsBoundary, reorderEffects);
3176
+ else {
3083
3177
  needsResumeArray = true;
3084
3178
  reorderScripts = concatScripts(reorderScripts, "_.push(\"" + reorderEffects + "\")");
3085
3179
  }
3086
3180
  }
3087
3181
  for (const reservation of readyReservations) reordered = concatScripts(reordered, reservation);
3088
3182
  reordered = concatScripts(reordered, reorderScripts && runtimePrefix + ".j" + toAccess(reorderId) + "=_=>{" + reorderScripts + "}");
3089
- html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
3183
+ html += "<t hidden " + state.commentPrefix + "=" + reorderId + ">" + reorderStart + reorderHTML + "</t>";
3090
3184
  }
3091
3185
  state.writeReorders = null;
3092
3186
  }
3093
- flushSerializer(boundary, state);
3094
3187
  if (state.resumes || needsResumeArray && !state.hasWrittenResume) scripts = concatScripts(scripts, state.resumeScript(state.resumes));
3095
3188
  scripts = concatScripts(scripts, reordered);
3096
3189
  if (needsWalk) scripts = concatScripts(scripts, state.walkScript());
@@ -3115,6 +3208,41 @@ function renderReorderPlaceholders(reorder, reorders) {
3115
3208
  }
3116
3209
  return reorders;
3117
3210
  }
3211
+ function dismissChunk(end, body) {
3212
+ if (end.boundary !== body.boundary) while (end.next) end = end.next;
3213
+ return end;
3214
+ }
3215
+ function followHeldEffects(chunk) {
3216
+ const held = reduce(chunk.deferredReady, lastHeldOf, chunk);
3217
+ if (held !== chunk) {
3218
+ held.effects = concatEffects(held.effects, chunk.effects);
3219
+ chunk.effects = "";
3220
+ }
3221
+ }
3222
+ function lastHeldOf(held, cur) {
3223
+ return cur.serializeState === held.serializeState && cur.boundary === held.boundary ? cur : held;
3224
+ }
3225
+ function holdEffectsOn(heldEffects, chunk, effects) {
3226
+ chunk.effects = effects;
3227
+ return push(heldEffects, chunk);
3228
+ }
3229
+ function isWithin(boundary, outer) {
3230
+ while (boundary && boundary !== outer) boundary = boundary.parent;
3231
+ return !!boundary;
3232
+ }
3233
+ function holdReorderEffects(head, boundary, effects) {
3234
+ if (!head.serializeState.readyId) {
3235
+ if (head.effects) head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(head.boundary, null), head.effects);
3236
+ head.effects = head.lastEffect = "";
3237
+ }
3238
+ head.heldEffects = holdEffectsOn(head.heldEffects, head.fork(boundary, null), effects);
3239
+ }
3240
+ function joinHeldEffects(heldEffects, effects) {
3241
+ return concatEffects(reduce(heldEffects, joinUncaught, ""), effects);
3242
+ }
3243
+ function joinUncaught(joined, held) {
3244
+ return held.boundary.aborted ? joined : concatEffects(joined, held.effects);
3245
+ }
3118
3246
  function flushSerializer(boundary, serializeState) {
3119
3247
  const { state } = boundary;
3120
3248
  const { serializer } = state;
@@ -3622,19 +3750,18 @@ function NOOP$1() {}
3622
3750
  //#endregion
3623
3751
  //#region src/html/assets.ts
3624
3752
  const kAssets = Symbol();
3625
- const kBlockIndex = Symbol();
3626
- const kDeferIndex = Symbol();
3627
- let assetFlush;
3628
- function withLoadAssets(renderer, assetId, triggers) {
3753
+ const kHead = Symbol();
3754
+ function withLoadAssets(renderer, flush, assetId, triggers) {
3629
3755
  return Object.assign((input) => {
3630
- const g = $global();
3631
- addAsset(g, assetId, triggers);
3632
- _html(flush(g, ""));
3756
+ writeLoadAsset(assetId, flush, triggers);
3633
3757
  return writeWaitReady(assetId, renderer, input);
3634
3758
  }, renderer);
3635
3759
  }
3760
+ function writeLoadAsset(assetId, flush, triggers) {
3761
+ const g = $global();
3762
+ writeAsset(g, addAsset(g, assetId, flush, triggers));
3763
+ }
3636
3764
  function withPageAssets(template, runtime, assetId, runtimeId) {
3637
- assetFlush = runtime;
3638
3765
  return Object.assign((input) => {
3639
3766
  const g = $global();
3640
3767
  if (runtimeId) {
@@ -3643,57 +3770,78 @@ function withPageAssets(template, runtime, assetId, runtimeId) {
3643
3770
  g.runtimeId = runtimeId;
3644
3771
  } else if (g.runtimeId !== runtimeId) console.error(`A page entry compiled with runtimeId "${runtimeId}" is nested in a render using runtimeId "${g.runtimeId}", so its content cannot resume.`);
3645
3772
  }
3646
- addAsset(g, assetId);
3773
+ const asset = addAsset(g, assetId, runtime);
3647
3774
  if (g.__flush__) {
3648
- _html(flush(g, ""));
3775
+ writeAsset(g, asset);
3649
3776
  return writeWaitReady(assetId, template, input);
3650
3777
  }
3651
- g.__flush__ = flush;
3778
+ g.__flush__ = flushPage;
3652
3779
  return template(input);
3653
3780
  }, template);
3654
3781
  }
3655
3782
  function _flush_head() {
3656
3783
  const g = $global();
3657
- return g[kAssets] ? flush(g, "") : "";
3784
+ if (!g[kAssets]) return "";
3785
+ g[kHead] = true;
3786
+ return takeAssets(g, catchableBoundary());
3658
3787
  }
3659
- function flush(g, html) {
3660
- let result = "";
3661
- const assets = g[kAssets];
3662
- const { length } = assets;
3663
- let bi = g[kBlockIndex];
3664
- let di = g[kDeferIndex];
3665
- for (; bi < length; bi++) result += assetFlush(g, "block", assets[bi].id);
3666
- for (; di < length; di++) {
3667
- const { id, triggers } = assets[di];
3668
- const deferHTML = assetFlush(g, "defer", id);
3669
- if (triggers) {
3670
- if (deferHTML) writeTriggerScript(id, deferHTML, triggers);
3671
- } else result += deferHTML;
3672
- }
3673
- g[kBlockIndex] = bi;
3674
- g[kDeferIndex] = di;
3675
- return result + html;
3676
- }
3677
- function addAsset(g, id, triggers) {
3678
- const assets = g[kAssets];
3679
- if (!assets) {
3680
- g[kAssets] = [{
3681
- id,
3682
- triggers
3683
- }];
3684
- g[kBlockIndex] = g[kDeferIndex] = 0;
3685
- } else if (!assets.find((a) => a.id === id)) assets.push({
3788
+ function flushPage(g, html) {
3789
+ return takeAssets(g, null) + html;
3790
+ }
3791
+ function takeAssets(g, at) {
3792
+ let block = "";
3793
+ let defer = "";
3794
+ for (const asset of g[kAssets]) if (asset.htmlAt === void 0) {
3795
+ asset.htmlAt = at;
3796
+ block += blockHTML(g, asset);
3797
+ if (!asset.triggers) defer += deferHTML(g, asset);
3798
+ }
3799
+ return block + defer;
3800
+ }
3801
+ function writeAsset(g, asset) {
3802
+ if (needsWrite(asset.htmlAt)) {
3803
+ asset.htmlAt = void 0;
3804
+ if (g[kHead] || g.__flush__ !== flushPage) {
3805
+ const block = blockHTML(g, asset);
3806
+ _html(block + (asset.triggers ? "" : deferHTML(g, asset)));
3807
+ if (block && isInResumedBranch()) writeScript(`document.head.insertAdjacentHTML("beforeend",${_escape_script(JSON.stringify(block))})`);
3808
+ asset.htmlAt = catchableBoundary();
3809
+ }
3810
+ }
3811
+ if (asset.triggers && needsWrite(asset.scriptAt)) {
3812
+ const defer = deferHTML(g, asset);
3813
+ if (defer) writeScript(asset.script ||= triggerScript(asset.id, defer, asset.triggers));
3814
+ asset.scriptAt = catchableBoundary();
3815
+ }
3816
+ }
3817
+ function needsWrite(at) {
3818
+ return at === void 0 || at !== null && mayDrop(at);
3819
+ }
3820
+ function blockHTML(g, asset) {
3821
+ return asset.block ??= asset.flush(g, "block", asset.id);
3822
+ }
3823
+ function deferHTML(g, asset) {
3824
+ return asset.defer ??= asset.flush(g, "defer", asset.id);
3825
+ }
3826
+ function addAsset(g, id, flush, triggers) {
3827
+ const assets = g[kAssets] ||= [];
3828
+ let asset = assets.find((a) => a.id === id);
3829
+ if (!asset) assets.push(asset = {
3686
3830
  id,
3687
- triggers
3831
+ flush,
3832
+ triggers,
3833
+ block: void 0,
3834
+ defer: void 0,
3835
+ script: void 0,
3836
+ htmlAt: void 0,
3837
+ scriptAt: void 0
3688
3838
  });
3689
- else {
3690
- const existing = assets.find((a) => a.id === id);
3691
- if (JSON.stringify(existing.triggers) !== JSON.stringify(triggers)) console.error(`The lazy asset "${id}" is imported with different \`load\` triggers; an asset must use one consistent trigger.`);
3692
- }
3839
+ else if (JSON.stringify(asset.triggers) !== JSON.stringify(triggers)) console.error(`The lazy asset "${id}" is imported with different \`load\` triggers; an asset must use one consistent trigger.`);
3840
+ return asset;
3693
3841
  }
3694
- function writeTriggerScript(id, html, triggers) {
3842
+ function triggerScript(id, html, triggers) {
3695
3843
  const htmlStr = _escape_script(JSON.stringify(html));
3696
- const insert = `(d=new Range().createContextualFragment(h),d.querySelectorAll("script").forEach(s=>s.onerror=()=>console.error(${_escape_script(JSON.stringify(`The lazy module for "${id}" failed to load; its server-rendered content cannot become interactive.`))})),p.after(d))`;
3844
+ const insert = `(d=new Range().createContextualFragment(h),d.querySelectorAll("script").forEach(s=>s.onerror=()=>console.error(${_escape_script(JSON.stringify(`The lazy module for "${id}" failed to load; its server-rendered content cannot become interactive.`))})),document.head.append(d))`;
3697
3845
  const exprs = triggers.map((trigger) => {
3698
3846
  const options = trigger.options && toObjectExpression(trigger.options);
3699
3847
  switch (trigger.type) {
@@ -3703,7 +3851,7 @@ function writeTriggerScript(id, html, triggers) {
3703
3851
  default: return `(e=>e?.addEventListener("${trigger.type.slice(3)}",l,{once:1}))(${querySelectorOrLoad(trigger.selector)})`;
3704
3852
  }
3705
3853
  });
3706
- writeScript(`((p,h,d,l=$=>{d||${insert}})=>${exprs.length > 1 ? `{${exprs.join(";")}}` : exprs[0]})(document.currentScript,${htmlStr})`);
3854
+ return `((h,d,l=$=>{d||${insert}})=>${exprs.length > 1 ? `{${exprs.join(";")}}` : exprs[0]})(${htmlStr})`;
3707
3855
  }
3708
3856
  function querySelectorOrLoad(selector) {
3709
3857
  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())`}`;
@@ -3727,6 +3875,7 @@ const K_TAGS_API_STATE = Symbol();
3727
3875
  const COMPAT_REGISTRY = /* @__PURE__ */ new WeakMap();
3728
3876
  const compat = {
3729
3877
  $global,
3878
+ writeLoadAsset,
3730
3879
  fork: _await,
3731
3880
  write: _html,
3732
3881
  writeScript,
@@ -3750,7 +3899,10 @@ const compat = {
3750
3899
  onFlush(fn) {
3751
3900
  const { flushHTML } = Chunk.prototype;
3752
3901
  Chunk.prototype.flushHTML = function(boundary) {
3902
+ const { state } = boundary;
3903
+ const reorders = swapReorders(state, null);
3753
3904
  fn(this);
3905
+ swapReorders(state, reorders);
3754
3906
  return flushHTML.call(this, boundary);
3755
3907
  };
3756
3908
  },
@@ -3776,21 +3928,52 @@ const compat = {
3776
3928
  return compatRegistered;
3777
3929
  };
3778
3930
  },
3931
+ joinChunks(chunks) {
3932
+ let joined;
3933
+ for (const chunk of chunks) {
3934
+ if (chunk.boundary.aborted) continue;
3935
+ if (joined) joined.append(chunk);
3936
+ else joined = chunk;
3937
+ }
3938
+ return joined;
3939
+ },
3940
+ appendChunks(chunks) {
3941
+ const chunk = getChunk();
3942
+ for (const part of chunks) {
3943
+ chunk.append(part);
3944
+ if (part.effects) chunk.lastEffect = part.lastEffect;
3945
+ }
3946
+ },
3947
+ deferReorders(reorders) {
3948
+ const chunk = getChunk();
3949
+ for (let i = reorders.length; i--;) {
3950
+ const carrier = chunk.fork(chunk.boundary, chunk.next);
3951
+ carrier.deferredReorder = reorders[i];
3952
+ chunk.next = carrier;
3953
+ }
3954
+ },
3779
3955
  createChunk($global) {
3780
3956
  const state = this.ensureState($global);
3781
3957
  return new Chunk(new Boundary(state), null, null, state);
3782
3958
  },
3783
- flushScript($global, chunk) {
3784
- chunk ||= this.createChunk($global);
3959
+ flushScript(chunk, reorders) {
3785
3960
  const { boundary } = chunk;
3786
- const scripts = boundary.flush() === 0 ? chunk.flushScript(boundary).scripts : "";
3961
+ const { state } = boundary;
3962
+ let html = "";
3963
+ let scripts = "";
3964
+ if (reorders) for (const reorder of reorders) state.reorder(reorder);
3965
+ if (boundary.flush() === 0) ({html, scripts} = chunk.flushScript(boundary));
3787
3966
  if (boundary.aborted) throw boundary.reason;
3788
3967
  if (boundary.count) throw new Error("Cannot serialize promise across tags/class compat layer.");
3789
- return scripts;
3968
+ return {
3969
+ html,
3970
+ scripts
3971
+ };
3790
3972
  },
3791
- render(renderer, willRerender, classAPIOut, component, input, completeChunks, registerChildScope) {
3973
+ render(renderer, willRerender, classAPIOut, component, input, componentScopes, registerChildScope, parentChunk) {
3974
+ if (parentChunk?.boundary.aborted) return;
3792
3975
  const state = this.ensureState(classAPIOut.global);
3793
- const boundary = new Boundary(state);
3976
+ const boundary = new Boundary(state, void 0, parentChunk?.boundary);
3794
3977
  const context = getChunk()?.context ?? null;
3795
3978
  let head = new Chunk(boundary, new Chunk(boundary, null, context, state), context, state);
3796
3979
  let normalizedInput = input;
@@ -3798,7 +3981,8 @@ const compat = {
3798
3981
  normalizedInput = {};
3799
3982
  for (const key in input) normalizedInput[key === "renderBody" ? "content" : key] = input[key];
3800
3983
  }
3801
- head.render(() => {
3984
+ const componentScope = new Chunk(boundary, null, context, state);
3985
+ componentScope.render(() => {
3802
3986
  if (this.hasPendingClassFunctions(classAPIOut.global)) drainClassFunctions(classAPIOut.global, (hostId) => {
3803
3987
  const fnScopeId = _scope_id();
3804
3988
  const scope = writeScope(fnScopeId, {
@@ -3813,6 +3997,8 @@ const compat = {
3813
3997
  writeScope(scopeId, { m5c: component.id });
3814
3998
  _script(scopeId, SET_SCOPE_REGISTER_ID);
3815
3999
  }
4000
+ });
4001
+ head.render(() => {
3816
4002
  _set_scope_reason(willRerender ? CLIENT_ALL : 0);
3817
4003
  try {
3818
4004
  renderer(normalizedInput);
@@ -3826,16 +4012,28 @@ const compat = {
3826
4012
  classAPIOut.onLast((next) => {
3827
4013
  (boundary.onNext = () => {
3828
4014
  if (boundary.aborted) {
3829
- asyncOut.error(boundary.reason);
3830
4015
  boundary.onNext = NOOP;
4016
+ if (parentChunk?.boundary.aborted) {
4017
+ asyncOut.end();
4018
+ next();
4019
+ } else asyncOut.error(boundary.reason);
3831
4020
  } else if (!boundary.count) {
3832
4021
  boundary.onNext = NOOP;
4022
+ const queued = swapReorders(state, null);
3833
4023
  head = head.consume(boundary);
4024
+ const reorders = swapReorders(state, queued);
4025
+ if (reorders) asyncOut.writer.get("reorders").push(...reorders);
4026
+ const heldEffects = head.takeHeldEffects();
4027
+ if (heldEffects) {
4028
+ head.effects = joinHeldEffects(heldEffects, head.effects);
4029
+ head.lastEffect = "";
4030
+ }
3834
4031
  asyncOut.write(head.html);
3835
4032
  asyncOut.script(head.scripts);
3836
- asyncOut.end();
3837
4033
  head.html = head.scripts = "";
3838
- completeChunks.push(head);
4034
+ asyncOut.writer.get("chunks").push(head);
4035
+ asyncOut.end();
4036
+ componentScopes.push(componentScope);
3839
4037
  next();
3840
4038
  }
3841
4039
  })();
@@ -3873,6 +4071,11 @@ function drainClassFunctions($global, writeScope) {
3873
4071
  for (const [id, fn, hostId] of pending) register(id, fn, scopeByHost[hostId] ||= writeScope(hostId));
3874
4072
  pending.length = 0;
3875
4073
  }
4074
+ function swapReorders(state, reorders) {
4075
+ const { writeReorders } = state;
4076
+ state.writeReorders = reorders;
4077
+ return writeReorders;
4078
+ }
3876
4079
  function NOOP() {}
3877
4080
  //#endregion
3878
- export { $global, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_select_value, _attrs_textarea_value, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _escape_style_value, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _html_resume, _id, _if, _peek_scope_id, _resume, _resume_branch, _resume_locals, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _set_scope_reason, _show_end, _show_start, _style_html, _subscribe, _template, _text_resume, _textarea_value, _to_text, _trailers, _try, _unescaped, _var, _write_guard, _write_if, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, withLoadAssets, withPageAssets };
4081
+ export { $global, _assert_class_toggles, _assert_hoist, _attr, _attr_and, _attr_class, _attr_content, _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open as _attr_dialog_open, _attr_input_checked, _attr_input_checkedValue, _attr_input_value, _attr_nonce, _attr_nullish, _attr_option_value, _attr_or, _attr_select_value, _attr_style, _attr_textarea_value, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_select_value, _attrs_textarea_value, _await, _content, _content_resume, _dynamic_tag, _el, _el_read_error, _el_resume, _escape, _escape_comment, _escape_script, _escape_style, _escape_style_value, _existing_scope, _flush_head, _for_in, _for_of, _for_to, _for_until, _hoist, _hoist_read_error, _html, _html_resume, _id, _if, _peek_scope_id, _resume, _resume_branch, _resume_locals, writeScope as _scope, _scope_id, _scope_reason, _scope_with_id, _script, _set_scope_reason, _show_end, _show_start, _style_html, _subscribe, _template, _text_resume, _textarea_value, _to_text, _trailers, _try, _unescaped, _var, _write_guard, _write_if, attrTag, attrTags, compat, forIn, forOf, forTo, forUntil, withLoadAssets, withPageAssets };
@@ -1,12 +1,12 @@
1
1
  "use strict";
2
- let require_control_flow = require("../dom-CNglVi8P.js"), handlePendingTry = (fn, scope, branch) => {
2
+ let require_control_flow = require("../dom-B8UEYzOz.js"), handlePendingTry = (fn, scope, branch) => {
3
3
  for (; branch;) {
4
- if (branch.O?.i) return (scope.J ||= ((branch.JS ||= (branch.O.m && ((complete) => branch.O.c = () => complete() || require_control_flow.an(branch, require_control_flow.on, require_control_flow.b))(branch.O.c), [])).push(scope), /* @__PURE__ */ new Set())).add(fn);
4
+ if (branch.O?.i) return (scope.J ||= ((branch.JS ||= (branch.O.m && ((complete) => branch.O.c = () => complete() || require_control_flow.on(branch, require_control_flow.sn, require_control_flow.b))(branch.O.c), [])).push(scope), /* @__PURE__ */ new Set())).add(fn);
5
5
  branch = branch.N;
6
6
  }
7
7
  };
8
8
  //#region src/dom/catch.feat.ts
9
- require_control_flow.rn((effects) => {
9
+ require_control_flow.in((effects) => {
10
10
  let i = 0, fn, scope, branch;
11
11
  for (; i < effects.length;) fn = effects[i++], scope = effects[i++], (branch = scope.F)?.H !== 0 && !handlePendingTry(fn, scope, branch) && fn(scope);
12
12
  }, (runRender) => (render) => {
@@ -4,7 +4,7 @@ let handlePendingTry = (fn, scope, branch) => {
4
4
  branch = branch.N;
5
5
  }
6
6
  };
7
- import { an as queueAsyncRender, b as runPendingEffects, on as queueEffect, rn as installCatch, y as renderCatch } from "../dom-DfP3MCo0.mjs";
7
+ import { b as runPendingEffects, in as installCatch, on as queueAsyncRender, sn as queueEffect, y as renderCatch } from "../dom-BPjLe6YU.mjs";
8
8
  //#region src/dom/catch.feat.ts
9
9
  installCatch((effects) => {
10
10
  let i = 0, fn, scope, branch;