marko 6.0.113 → 6.0.114

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.
@@ -281,7 +281,7 @@ var REORDER_RUNTIME_CODE = true ? (
281
281
  let onNextSibling,
282
282
  placeholder,
283
283
  nextSibling,
284
- placeholders = {},
284
+ placeholders = runtime.p = {},
285
285
  replace = (id, container) => runtime.l[id].replaceWith(...container.childNodes);
286
286
  runtime.d.head.append(
287
287
  runtime.d.querySelector("style[" + runtime.i + "]") || ""
@@ -331,7 +331,7 @@ var REORDER_RUNTIME_CODE = true ? (
331
331
  }
332
332
  };
333
333
  })`
334
- ) : `(e=>{if(e.j)return;let i,l,r,t={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),"#"==n?(t[a]=l).i++:"!"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):"T"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l["^"+a]){if(--o.i)return 1;for(;(r=e.l[a].previousSibling||i).remove(),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})`;
334
+ ) : `(e=>{if(e.j)return;let i,l,r,t=e.p={},c=(i,l)=>e.l[i].replaceWith(...l.childNodes);e.d.head.append(e.d.querySelector("style["+e.i+"]")||""),e.j={},e.x=(n,a,d,o,g)=>{d==r&&i(),"#"==n?(t[a]=l).i++:"!"==n?e.l[a]&&t[a]&&(r=d.nextSibling,i=()=>t[a].c()):"T"==d.tagName&&(a=d.getAttribute(e.i))&&(r=d.nextSibling,i=()=>{d.remove(),o||c(a,d),l.c()},l=t[a]||(o=t[a]={i:e.l[a]?1:2,c(i=e.l["^"+a]){if(--o.i)return 1;for(;(r=e.l[a].previousSibling||i).remove(),i!=r;);c(a,d)}}),(n=e.j[a])&&(g=l.c,l.c=()=>g()||n(e.r)))}})`;
335
335
 
336
336
  // src/html/serializer.ts
337
337
  var kTouchedIterator = Symbol();
@@ -1699,6 +1699,9 @@ function writeScript(script) {
1699
1699
  $chunk.writeScript(script);
1700
1700
  }
1701
1701
  function _script(scopeId, registryId) {
1702
+ if ($chunk.context?.[kIsAsync]) {
1703
+ _resume_branch(scopeId);
1704
+ }
1702
1705
  $chunk.boundary.state.needsMainRuntime = true;
1703
1706
  $chunk.writeEffect(scopeId, registryId);
1704
1707
  }
@@ -1738,13 +1741,13 @@ function normalizeServerRender(value) {
1738
1741
  }
1739
1742
  }
1740
1743
  var kPendingContexts = Symbol("Pending Contexts");
1741
- function withContext(key, value, cb) {
1744
+ function withContext(key, value, cb, cbValue) {
1742
1745
  const ctx = $chunk.context ||= { [kPendingContexts]: 0 };
1743
1746
  const prev = ctx[key];
1744
1747
  ctx[kPendingContexts]++;
1745
1748
  ctx[key] = value;
1746
1749
  try {
1747
- return cb();
1750
+ return cb(cbValue);
1748
1751
  } finally {
1749
1752
  ctx[kPendingContexts]--;
1750
1753
  ctx[key] = prev;
@@ -1813,17 +1816,21 @@ function _hoist(scopeId, id) {
1813
1816
  return _resume(getter, id, scopeId);
1814
1817
  }
1815
1818
  function _resume_branch(scopeId) {
1816
- const branchId = $chunk.context?.[branchIdKey];
1819
+ const branchId = $chunk.context?.[kBranchId];
1817
1820
  if (branchId !== void 0 && branchId !== scopeId) {
1818
1821
  writeScope(scopeId, { ["#ClosestBranchId" /* ClosestBranchId */]: branchId });
1819
1822
  }
1820
1823
  }
1821
- var branchIdKey = Symbol();
1824
+ var kBranchId = Symbol("Branch Id");
1825
+ var kIsAsync = Symbol("Is Async");
1822
1826
  function isInResumedBranch() {
1823
- return $chunk?.context?.[branchIdKey] !== void 0;
1827
+ return $chunk?.context?.[kBranchId] !== void 0;
1824
1828
  }
1825
1829
  function withBranchId(branchId, cb) {
1826
- return withContext(branchIdKey, branchId, cb);
1830
+ return withContext(kBranchId, branchId, cb);
1831
+ }
1832
+ function withIsAsync(cb, value) {
1833
+ return withContext(kIsAsync, true, cb, value);
1827
1834
  }
1828
1835
  function _for_of(list, cb, by, scopeId, accessor, serializeBranch, serializeMarker, serializeStateful, parentEndTag, singleNode) {
1829
1836
  const { state } = $chunk.boundary;
@@ -2207,7 +2214,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
2207
2214
  $chunk.writeHTML(
2208
2215
  $chunk.boundary.state.mark("[" /* BranchStart */, "")
2209
2216
  );
2210
- content(value);
2217
+ withIsAsync(content, value);
2211
2218
  $chunk.writeHTML(
2212
2219
  $chunk.boundary.state.mark(
2213
2220
  "]" /* BranchEnd */,
@@ -2215,7 +2222,7 @@ function _await(scopeId, accessor, promise, content, serializeMarker) {
2215
2222
  )
2216
2223
  );
2217
2224
  } else {
2218
- content(value);
2225
+ withIsAsync(content, value);
2219
2226
  }
2220
2227
  });
2221
2228
  boundary.endAsync(chunk);
@@ -2235,11 +2242,11 @@ function _try(scopeId, accessor, content, input) {
2235
2242
  const placeholderContent = normalizeDynamicRenderer(input.placeholder);
2236
2243
  if (catchContent) {
2237
2244
  tryCatch(
2238
- placeholderContent ? () => tryPlaceholder(content, placeholderContent) : content,
2245
+ placeholderContent ? () => tryPlaceholder(content, placeholderContent, branchId) : content,
2239
2246
  catchContent
2240
2247
  );
2241
2248
  } else if (placeholderContent) {
2242
- tryPlaceholder(content, placeholderContent);
2249
+ tryPlaceholder(content, placeholderContent, branchId);
2243
2250
  } else {
2244
2251
  content();
2245
2252
  }
@@ -2255,7 +2262,7 @@ function _try(scopeId, accessor, content, input) {
2255
2262
  )
2256
2263
  );
2257
2264
  }
2258
- function tryPlaceholder(content, placeholder) {
2265
+ function tryPlaceholder(content, placeholder, branchId) {
2259
2266
  const chunk = $chunk;
2260
2267
  const { boundary } = chunk;
2261
2268
  const body = new Chunk(boundary, null, chunk.context);
@@ -2263,9 +2270,10 @@ function tryPlaceholder(content, placeholder) {
2263
2270
  chunk.append(body);
2264
2271
  return;
2265
2272
  }
2266
- chunk.next = $chunk = new Chunk(boundary, chunk.next, body.context);
2273
+ chunk.next = $chunk = new Chunk(boundary, chunk.next, chunk.context);
2267
2274
  chunk.placeholderBody = body;
2268
2275
  chunk.placeholderRender = placeholder;
2276
+ chunk.placeholderBranchId = branchId;
2269
2277
  }
2270
2278
  function tryCatch(content, catchContent) {
2271
2279
  const chunk = $chunk;
@@ -2441,18 +2449,16 @@ var Chunk = class {
2441
2449
  reorderId = null;
2442
2450
  placeholderBody = null;
2443
2451
  placeholderRender = null;
2452
+ placeholderBranchId = null;
2444
2453
  writeHTML(html) {
2445
2454
  this.html += html;
2446
2455
  }
2447
2456
  writeEffect(scopeId, registryId) {
2448
2457
  if (this.lastEffect === registryId) {
2449
- this.effects += "," + scopeId;
2458
+ this.effects += " " + scopeId;
2450
2459
  } else {
2451
2460
  this.lastEffect = registryId;
2452
- this.effects = concatEffects(
2453
- this.effects,
2454
- '"' + registryId + '",' + scopeId
2455
- );
2461
+ this.effects = concatEffects(this.effects, registryId + " " + scopeId);
2456
2462
  }
2457
2463
  }
2458
2464
  writeScript(script) {
@@ -2469,7 +2475,8 @@ var Chunk = class {
2469
2475
  const body = this.placeholderBody.consume();
2470
2476
  if (body.async) {
2471
2477
  const { state } = this.boundary;
2472
- const reorderId = body.reorderId = state.nextReorderId();
2478
+ const reorderId = body.reorderId = this.placeholderBranchId ? this.placeholderBranchId + "" : state.nextReorderId();
2479
+ this.placeholderBranchId = null;
2473
2480
  this.writeHTML(state.mark("!^" /* Placeholder */, reorderId));
2474
2481
  const after = this.render(this.placeholderRender);
2475
2482
  if (after !== this) {
@@ -2541,7 +2548,7 @@ var Chunk = class {
2541
2548
  }
2542
2549
  if (effects) {
2543
2550
  needsWalk = true;
2544
- state.resumes = state.resumes ? state.resumes + "," + effects : effects;
2551
+ state.resumes = state.resumes ? state.resumes + ',"' + effects + '"' : '"' + effects + '"';
2545
2552
  }
2546
2553
  if (state.resumes) {
2547
2554
  if (state.hasWrittenResume) {
@@ -2605,12 +2612,12 @@ var Chunk = class {
2605
2612
  }
2606
2613
  reorderScripts = concatScripts(
2607
2614
  reorderScripts,
2608
- "_.push(" + reorderEffects + ")"
2615
+ '_.push("' + reorderEffects + '")'
2609
2616
  );
2610
2617
  }
2611
2618
  scripts = concatScripts(
2612
2619
  scripts,
2613
- reorderScripts && runtimePrefix + ".j." + reorderId + "=_=>{" + reorderScripts + "}"
2620
+ reorderScripts && runtimePrefix + ".j" /* Scripts */ + toAccess(reorderId) + "=_=>{" + reorderScripts + "}"
2614
2621
  );
2615
2622
  html += "<t " + state.commentPrefix + "=" + reorderId + ">" + reorderHTML + "</t>";
2616
2623
  }
@@ -2669,7 +2676,7 @@ function flushSerializer(boundary) {
2669
2676
  if (scopeIdDelta) serializeData.push(scopeIdDelta);
2670
2677
  serializeData.push(scope);
2671
2678
  }
2672
- state.resumes = concatEffects(
2679
+ state.resumes = concatSequence(
2673
2680
  state.resumes,
2674
2681
  serializer.stringify(serializeData, boundary)
2675
2682
  );
@@ -2684,6 +2691,9 @@ function _trailers(html) {
2684
2691
  $chunk.boundary.state.trailerHTML += html;
2685
2692
  }
2686
2693
  function concatEffects(a, b) {
2694
+ return a ? b ? a + " " + b : a : b;
2695
+ }
2696
+ function concatSequence(a, b) {
2687
2697
  return a ? b ? a + "," + b : a : b;
2688
2698
  }
2689
2699
  function concatScripts(a, b) {
@@ -1,7 +1,8 @@
1
1
  import { type Accessor, AccessorProp, type BranchScope, type EncodedAccessor, type Scope } from "../common/types";
2
2
  import { type Renderer, type SetupFn } from "./renderer";
3
3
  import { type Signal } from "./signals";
4
- export declare function _await(nodeAccessor: EncodedAccessor, template?: string | 0, walks?: string | 0, setup?: SetupFn | 0, params?: Signal<unknown>): (scope: Scope, promise: Promise<unknown>) => void;
4
+ export declare function _await_promise(nodeAccessor: EncodedAccessor, params?: Signal<unknown>): (scope: Scope, promise: Promise<unknown>) => void;
5
+ export declare function _await_content(nodeAccessor: EncodedAccessor, template?: string | 0, walks?: string | 0, setup?: SetupFn | 0): (scope: Scope) => void;
5
6
  export declare function _try(nodeAccessor: EncodedAccessor, template?: string | 0, walks?: string | 0, setup?: SetupFn | 0): (scope: Scope, input: {
6
7
  catch: unknown;
7
8
  placeholder: unknown;
@@ -10,6 +10,6 @@ export declare function queueRender<T>(scope: Scope, signal: Signal<T>, signalKe
10
10
  export declare function queueEffect<S extends Scope, T extends ExecFn<S>>(scope: S, fn: T): void;
11
11
  export declare function run(): void;
12
12
  export declare function prepareEffects(fn: () => void): unknown[];
13
- export declare let runEffects: (effects: unknown[], checkPending?: boolean) => void;
13
+ export declare let runEffects: (effects: unknown[], checkPending?: boolean | 1) => void;
14
14
  export declare let _enable_catch: () => void;
15
15
  export {};
@@ -1,5 +1,24 @@
1
- import { type EncodedAccessor, type Scope } from "../common/types";
1
+ import { type AwaitCounter, type EncodedAccessor, type Scope } from "../common/types";
2
2
  import type { Signal } from "./signals";
3
+ type Resumes = (number | Scope)[];
4
+ type ResumeFn = (ctx: object) => Resumes;
5
+ export interface Renders {
6
+ (renderId: string): RenderData;
7
+ [renderId: string]: RenderData;
8
+ }
9
+ export interface RenderData {
10
+ i: string;
11
+ v: Comment[];
12
+ r?: (string | ResumeFn)[];
13
+ s?: Record<string, Scope>;
14
+ w(): void;
15
+ m(): unknown[];
16
+ d: never;
17
+ l: never;
18
+ x: never;
19
+ j?: never;
20
+ p?: Record<string | number, AwaitCounter>;
21
+ }
3
22
  export declare function enableBranches(): void;
4
23
  export declare function init(runtimeId?: string): void;
5
24
  export declare let isResuming: undefined | 0 | 1;
@@ -7,3 +26,4 @@ export declare function getRegisteredWithScope(id: string, scope?: Scope): unkno
7
26
  export declare function _resume<T>(id: string, obj: T): T;
8
27
  export declare function _var_resume<T extends Signal<unknown>>(id: string, signal: T): T;
9
28
  export declare function _el(id: string, accessor: EncodedAccessor): (scope: Scope) => () => any;
29
+ export {};
package/dist/dom.d.ts CHANGED
@@ -4,7 +4,7 @@ export { forIn, forOf, forTo, forUntil } from "./common/for";
4
4
  export { _call } from "./common/helpers";
5
5
  export { $signal, $signalReset } from "./dom/abort-signal";
6
6
  export { compat } from "./dom/compat";
7
- export { _await, _dynamic_tag, _for_in, _for_of, _for_to, _for_until, _if, _resume_dynamic_tag, _try, } from "./dom/control-flow";
7
+ export { _await_content, _await_promise, _dynamic_tag, _for_in, _for_of, _for_to, _for_until, _if, _resume_dynamic_tag, _try, } from "./dom/control-flow";
8
8
  export { _attr_details_or_dialog_open as _attr_details_open, _attr_details_or_dialog_open_script as _attr_details_open_script, _attr_details_or_dialog_open as _attr_dialog_open, _attr_details_or_dialog_open_script as _attr_dialog_open_script, _attr_input_checked, _attr_input_checked_script, _attr_input_checkedValue, _attr_input_checkedValue_script, _attr_input_value, _attr_input_value_script, _attr_select_value, _attr_select_value_script, _attr_textarea_value, _attr_textarea_value_script, } from "./dom/controllable";
9
9
  export { _attr, _attr_class, _attr_class_item, _attr_class_items, _attr_content, _attr_style, _attr_style_item, _attr_style_items, _attrs, _attrs_content, _attrs_partial, _attrs_partial_content, _attrs_script, _html, _lifecycle, _text, _text_content, } from "./dom/dom";
10
10
  export { _on } from "./dom/event";