brumate 0.4.4 → 0.5.1

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 (63) hide show
  1. package/dist/{boot-D3NjfyUX.d.ts → boot-Difa0qdg.d.ts} +2 -8
  2. package/dist/cli.js +2 -2
  3. package/dist/{client-iZ9a1Nut.js → client-BYHGusTe.js} +990 -369
  4. package/dist/client-BYHGusTe.js.map +1 -0
  5. package/dist/{client-DNva05jp.d.ts → client-DvsU9qxG.d.ts} +107 -23
  6. package/dist/{defer-DP7dMS2y.js → defer-B63oF5Oa.js} +2 -2
  7. package/dist/{defer-DP7dMS2y.js.map → defer-B63oF5Oa.js.map} +1 -1
  8. package/dist/{devtools-BJB_MMeL.js → devtools-D_SQpXTg.js} +4 -4
  9. package/dist/{devtools-BJB_MMeL.js.map → devtools-D_SQpXTg.js.map} +1 -1
  10. package/dist/{devtools-panel-CUV6A4ZE.js → devtools-panel-B9yokst5.js} +2 -2
  11. package/dist/{devtools-panel-CUV6A4ZE.js.map → devtools-panel-B9yokst5.js.map} +1 -1
  12. package/dist/{features-CHY5Ekku.js → features-D5kLyihb.js} +19 -2
  13. package/dist/features-D5kLyihb.js.map +1 -0
  14. package/dist/{files-BZRjz9Mx.js → files-s4wmjcZV.js} +2 -2
  15. package/dist/{files-BZRjz9Mx.js.map → files-s4wmjcZV.js.map} +1 -1
  16. package/dist/index.d.ts +1 -8
  17. package/dist/index.js +1 -1
  18. package/dist/{inspect-BLOdfj7o.js → inspect-BLPt-dZZ.js} +891 -142
  19. package/dist/inspect-BLPt-dZZ.js.map +1 -0
  20. package/dist/{loader-CheV6t0N.js → loader-DKxhLjJw.js} +4 -4
  21. package/dist/{loader-CheV6t0N.js.map → loader-DKxhLjJw.js.map} +1 -1
  22. package/dist/{navigate-CfOr-TRF.js → navigate-BcV1qkkx.js} +2 -2
  23. package/dist/navigate-BcV1qkkx.js.map +1 -0
  24. package/dist/{produce-DS-dQaUX.js → produce-Cq6KKi7b.js} +2 -2
  25. package/dist/{produce-DS-dQaUX.js.map → produce-Cq6KKi7b.js.map} +1 -1
  26. package/dist/{rpc-DvTwGfL_.js → rpc-CIVU4Ktx.js} +5 -5
  27. package/dist/rpc-CIVU4Ktx.js.map +1 -0
  28. package/dist/runtime/bundles.d.ts +9 -0
  29. package/dist/runtime/bundles.js +60 -0
  30. package/dist/runtime/bundles.js.map +1 -0
  31. package/dist/runtime/client.d.ts +2 -2
  32. package/dist/runtime/client.js +3 -3
  33. package/dist/runtime/devtools.d.ts +1 -1
  34. package/dist/runtime/devtools.js +1 -1
  35. package/dist/runtime/hot.d.ts +1 -1
  36. package/dist/runtime/loader.d.ts +2 -2
  37. package/dist/runtime/loader.js +2 -2
  38. package/dist/runtime/server.d.ts +3 -3
  39. package/dist/runtime/server.js +4 -4
  40. package/dist/runtime/static-loader.d.ts +2 -2
  41. package/dist/runtime/static-loader.js +1 -1
  42. package/dist/runtime/testing.d.ts +2 -2
  43. package/dist/runtime/testing.js +2 -2
  44. package/dist/{server-BXMH3Z9T.d.ts → server-CAwIqrXl.d.ts} +44 -5
  45. package/dist/{server-O_rC-RRL.js → server-Doy5HR7r.js} +106 -17
  46. package/dist/server-Doy5HR7r.js.map +1 -0
  47. package/dist/{static-loader-BiUaZaag.d.ts → static-loader-9Nc1GvF0.d.ts} +2 -2
  48. package/dist/{static-loader-BLJYvTKc.js → static-loader-Bdet7g76.js} +3 -26
  49. package/dist/static-loader-Bdet7g76.js.map +1 -0
  50. package/dist/{stream-JGRPr7u5.js → stream-BdhzvPQO.js} +2 -2
  51. package/dist/{stream-JGRPr7u5.js.map → stream-BdhzvPQO.js.map} +1 -1
  52. package/dist/vite.d.ts +1 -1
  53. package/dist/vite.js +129 -51
  54. package/dist/vite.js.map +1 -1
  55. package/package.json +5 -1
  56. package/skills/brumate/references/errors.md +19 -5
  57. package/dist/client-iZ9a1Nut.js.map +0 -1
  58. package/dist/features-CHY5Ekku.js.map +0 -1
  59. package/dist/inspect-BLOdfj7o.js.map +0 -1
  60. package/dist/navigate-CfOr-TRF.js.map +0 -1
  61. package/dist/rpc-DvTwGfL_.js.map +0 -1
  62. package/dist/server-O_rC-RRL.js.map +0 -1
  63. package/dist/static-loader-BLJYvTKc.js.map +0 -1
@@ -1,13 +1,9 @@
1
1
  import { C as spread$1, T as textValue, b as ownValue, f as handlerEntry, g as isRaw, n as VOID_ELEMENTS, o as attributeText, p as insertValue, r as actionAttributes, s as bindEntry, v as onAttribute, y as onValue } from "./html-t1JpkODI.js";
2
- import { a as HAS_CLIENT_HTML, c as HAS_TEMPLATES, i as HAS_CHILDREN, l as HAS_TITLES, n as HAS_BINDINGS, o as HAS_LATE_MARKUP } from "./features-CHY5Ekku.js";
3
- import { C as useSerialEntry, _ as mergeHandlers, a as ElementReference, b as parseId, c as PARTS, d as SlotReference, f as addEntryHandlers, g as isSlotReference, h as isPropWrapper, i as ChildrenReference, m as isBinding, n as Binding, o as FunctionReference, p as isAsyncIterable, s as MemoError, x as stateValues } from "./produce-DS-dQaUX.js";
2
+ import { a as HAS_CLIENT_HTML, c as HAS_LATE_MARKUP, d as HAS_ROOT_WAIT, f as HAS_ROUTES, g as HAS_WINDOWS, h as HAS_TRIES, i as HAS_CHILDREN, m as HAS_TITLES, n as HAS_BINDINGS, o as HAS_DYNAMIC, p as HAS_TEMPLATES, s as HAS_FIELDS, u as HAS_LOADING } from "./features-D5kLyihb.js";
3
+ import { C as useSerialEntry, _ as mergeHandlers, a as ElementReference, b as parseId, c as PARTS, d as SlotReference, f as addEntryHandlers, g as isSlotReference, h as isPropWrapper, i as ChildrenReference, m as isBinding, n as Binding, o as FunctionReference, p as isAsyncIterable, s as MemoError, x as stateValues } from "./produce-Cq6KKi7b.js";
4
4
  import { n as ROUTE_KEY } from "./context-CTiSzQRc.js";
5
5
  import { n as trustedHTML, t as loadOnce } from "./skew-FRmAy9iy.js";
6
6
  //#region src/runtime/client/state.ts
7
- /** The part that holds an export: `h<n>` and `c<n>` have their own, the rest are in `update`. */
8
- function getPart(name) {
9
- return /^[hct]\d/.test(name) ? name : "update";
10
- }
11
7
  let options;
12
8
  /** The URL prefix of server function calls, from the options. */
13
9
  let rpcPrefix = "/_brumate";
@@ -43,10 +39,8 @@ function devtools() {
43
39
  return globalThis[DEVTOOLS];
44
40
  }
45
41
  const modules = /* @__PURE__ */ new Map();
46
- const loading = /* @__PURE__ */ new Map();
42
+ const loading$1 = /* @__PURE__ */ new Map();
47
43
  const valueRenders = {};
48
- const parts = /* @__PURE__ */ new Map();
49
- const loadedParts = /* @__PURE__ */ new Map();
50
44
  const comments = /* @__PURE__ */ new Map();
51
45
  const elements = /* @__PURE__ */ new Map();
52
46
  const refs = /* @__PURE__ */ new Map();
@@ -84,6 +78,7 @@ const insertedChildren = [];
84
78
  * Slots that the render of a component in the browser filled with a promise,
85
79
  * by `scope:slot`. The first compute of their memo takes that promise
86
80
  * instead of calling again, so a server function is called once per row.
81
+ * A slot that `wait` filled with the settled value keeps it.
87
82
  */
88
83
  const renderedLoads = /* @__PURE__ */ new Set();
89
84
  /**
@@ -266,7 +261,7 @@ function clear(start, end) {
266
261
  //#endregion
267
262
  //#region src/runtime/client/code.ts
268
263
  function loadModule(id) {
269
- let promise = loading.get(id);
264
+ let promise = loading$1.get(id);
270
265
  if (!promise) {
271
266
  promise = Promise.resolve(options.load(id)).then((loaded) => {
272
267
  const module = loaded ?? {
@@ -278,22 +273,7 @@ function loadModule(id) {
278
273
  for (const render of module.components ?? []) valueRenders[render.brumateId] = render;
279
274
  return module;
280
275
  });
281
- loading.set(id, promise);
282
- }
283
- return promise;
284
- }
285
- function loadPart(module, name) {
286
- const key = `${module.id}:${name}`;
287
- let promise = parts.get(key);
288
- if (!promise) {
289
- let loaded;
290
- if (!module.load) loaded = Promise.resolve(module);
291
- else loaded = options.loadPart ? options.loadPart(module, name) : module.load(name);
292
- promise = loaded.then((part) => {
293
- loadedParts.set(key, part);
294
- return part;
295
- });
296
- parts.set(key, promise);
276
+ loading$1.set(id, promise);
297
277
  }
298
278
  return promise;
299
279
  }
@@ -324,7 +304,7 @@ function loadedFunction(ref) {
324
304
  const [id, name] = ref.split("#");
325
305
  const module = modules.get(id);
326
306
  if (!module) return;
327
- return (module.load ? loadedParts.get(`${id}:${getPart(name)}`) : module)?.[name];
307
+ return module[name];
328
308
  }
329
309
  //#endregion
330
310
  //#region src/runtime/client/scopes.ts
@@ -591,7 +571,7 @@ function refresh(added, memosOnly = false) {
591
571
  let any = false;
592
572
  for (const names of byKind.values()) any ||= names.length > 0;
593
573
  if (!any) return;
594
- const updates = await loadPart(module, "update");
574
+ const updates = module;
595
575
  await codeReady();
596
576
  refreshing = true;
597
577
  try {
@@ -731,7 +711,7 @@ let reloading;
731
711
  async function resolve$1(ref) {
732
712
  const [id, name] = ref.split("#");
733
713
  try {
734
- return (await loadPart(await loadModule(id), getPart(name)))[name];
714
+ return (await loadModule(id))[name];
735
715
  } catch (error) {
736
716
  const next = await serverBuild();
737
717
  if (!reloading && next !== void 0 && loadOnce(next)) {
@@ -959,6 +939,10 @@ function children(from, html) {
959
939
  */
960
940
  function fail(scope, error) {
961
941
  options.onError?.(error, { scope: scope?.id });
942
+ if (!HAS_TRIES) {
943
+ unhandled(error, scope);
944
+ return;
945
+ }
962
946
  (async () => {
963
947
  for (let current = scope; current; current = current.l ?? current.p ?? current.o) {
964
948
  const id = findRoot(current).m;
@@ -1005,6 +989,19 @@ function replaceTry(key) {
1005
989
  }
1006
990
  template?.remove();
1007
991
  }
992
+ /**
993
+ * The scope that each rejection was reported to, as an unread memo and the waits of a render in
994
+ * one scope can hold the same promise.
995
+ */
996
+ const reported = /* @__PURE__ */ new WeakMap();
997
+ /** `fail`, once per error and scope. */
998
+ function reportOnce(scope, error) {
999
+ if (typeof error === "object" && error !== null) {
1000
+ if (reported.has(error) && reported.get(error) === scope) return;
1001
+ reported.set(error, scope);
1002
+ }
1003
+ fail(scope, error);
1004
+ }
1008
1005
  /** Reports the error of a `#loading` body that failed on the server, with no `#try` around it. */
1009
1006
  function failBoundary(error) {
1010
1007
  options.onError?.(error, {});
@@ -1014,7 +1011,7 @@ function failBoundary(error) {
1014
1011
  * Renders the `#catch` body of a `#try` with an error, in place of `body`, the body that failed.
1015
1012
  */
1016
1013
  async function catchInto(owner, body, module, [, anchor, , fallback, kinds, holderKind, holderAnchor], error) {
1017
- const updates = await loadPart(module, "update");
1014
+ const updates = module;
1018
1015
  if (scopes.get(body.id) !== body) return;
1019
1016
  const start = blockStart(owner, anchor);
1020
1017
  if (!start) return;
@@ -1027,6 +1024,7 @@ async function catchInto(owner, body, module, [, anchor, , fallback, kinds, hold
1027
1024
  function get(scope, slot) {
1028
1025
  if (dirty.size > 0 && !draining) settle(scope);
1029
1026
  const value = scope.s[slot];
1027
+ if (value === void 0 && exempt > 0 && !(slot in scope.s)) throw new NotReady(Promise.resolve());
1030
1028
  if (value instanceof Promise && !scope.plain?.has(slot)) {
1031
1029
  if (computing > 0) throw new NotReady(value);
1032
1030
  if (loadingValues.has(value)) {
@@ -1047,7 +1045,7 @@ function get(scope, slot) {
1047
1045
  * reads it throws into the nearest `#try` around it, and the code that does not read it runs as
1048
1046
  * usual. A memo that computes again without a throw holds its value again.
1049
1047
  */
1050
- function hold(scope, slot, key, error) {
1048
+ function hold$1(scope, slot, key, error) {
1051
1049
  loadingSlots.delete(key);
1052
1050
  loads.delete(key);
1053
1051
  guesses?.map.delete(key);
@@ -1098,7 +1096,7 @@ function send(bound, value) {
1098
1096
  /** The setters that were given each element, so an update of a spread does not call them again. */
1099
1097
  const given = /* @__PURE__ */ new WeakMap();
1100
1098
  /** Calls the setter of a binding with an element, once for each element and setter. */
1101
- function give(bound, element) {
1099
+ function give$1(bound, element) {
1102
1100
  const key = bound instanceof FunctionReference ? `${bound.scope}#${bound.ref}` : bound;
1103
1101
  const seen = given.get(element) ?? /* @__PURE__ */ new Set();
1104
1102
  if (!seen.has(key)) {
@@ -1208,7 +1206,7 @@ function isThenable(value) {
1208
1206
  function unreadMemo(scope, value) {
1209
1207
  if (isThenable(value)) {
1210
1208
  const at = resolveScope(scope);
1211
- value.then(void 0, (error) => fail(at, error));
1209
+ value.then(void 0, (error) => reportOnce(at, error));
1212
1210
  }
1213
1211
  }
1214
1212
  /**
@@ -1227,7 +1225,7 @@ function asyncMemo(scope, slot, promise) {
1227
1225
  else trigger(scope, slot);
1228
1226
  }
1229
1227
  function failed(error) {
1230
- if (loads.get(key) === load) hold(scope, slot, key, error);
1228
+ if (loads.get(key) === load) hold$1(scope, slot, key, error);
1231
1229
  }
1232
1230
  promise.then((value) => {
1233
1231
  if (!isAsyncIterable(value)) {
@@ -1338,8 +1336,8 @@ function memo(scope, slot, compute) {
1338
1336
  const key = `${scope.id}:${slot}`;
1339
1337
  if (guesses?.same(key)) return;
1340
1338
  const rendered = scope.s[slot];
1341
- if (renderedLoads.delete(key) && isThenable(rendered)) {
1342
- asyncMemo(scope, slot, Promise.resolve(rendered));
1339
+ if (renderedLoads.delete(key)) {
1340
+ if (isThenable(rendered)) asyncMemo(scope, slot, Promise.resolve(rendered));
1343
1341
  return;
1344
1342
  }
1345
1343
  let value;
@@ -1363,7 +1361,7 @@ function memo(scope, slot, compute) {
1363
1361
  memoKey = outer;
1364
1362
  }
1365
1363
  if (threw) {
1366
- hold(scope, slot, key, value);
1364
+ hold$1(scope, slot, key, value);
1367
1365
  return;
1368
1366
  }
1369
1367
  if (isThenable(value) || isAsyncIterable(value)) {
@@ -1394,7 +1392,7 @@ function trigger(scope, slot) {
1394
1392
  for (const check of waiters.keys()) check();
1395
1393
  const id = findRoot(scope).m;
1396
1394
  const children = childrenReady(scope);
1397
- if (modules.has(id) && loadedParts.has(`${id}:update`) && loadingCode.size === 0 && !children) {
1395
+ if (modules.has(id) && loadingCode.size === 0 && !children) {
1398
1396
  pass(() => queueWrite(scope, slot));
1399
1397
  return;
1400
1398
  }
@@ -1402,7 +1400,7 @@ function trigger(scope, slot) {
1402
1400
  waiting.push([
1403
1401
  scope,
1404
1402
  slot,
1405
- updateCode(scope, slot).catch((error) => fail(scope, error))
1403
+ loadModule(id).then(() => childrenReady(scope)).catch((error) => fail(scope, error))
1406
1404
  ]);
1407
1405
  return;
1408
1406
  }
@@ -1410,8 +1408,7 @@ function trigger(scope, slot) {
1410
1408
  const via = viaContext;
1411
1409
  const list = [[scope, slot]];
1412
1410
  if (running > 0) waiting = list;
1413
- const loading = loadModule(id).then(async (loaded) => {
1414
- await (loaded.g[scope.k]?.[slot] && loadPart(loaded, "update"));
1411
+ const loading = loadModule(id).then(async () => {
1415
1412
  const waits = [...loadingCode, children];
1416
1413
  for (const [, , load] of list) waits.push(load);
1417
1414
  await Promise.allSettled(waits);
@@ -1432,32 +1429,11 @@ function trigger(scope, slot) {
1432
1429
  flushEffects();
1433
1430
  });
1434
1431
  loadingUpdates.add(loading);
1435
- loading.finally(() => loadingUpdates.delete(loading));
1436
- }
1437
- /** Loads the code of a component, its update code when something reads the slot, and its children. */
1438
- async function updateCode(scope, slot) {
1439
- await loadUpdate(scope, slot);
1440
- return childrenReady(scope);
1441
- }
1442
- /** Loads the module of a component and its update code, when something reads the slot. */
1443
- function loadUpdate(scope, slot) {
1444
- return loadModule(findRoot(scope).m).then((loaded) => {
1445
- const reads = loaded.g[scope.k];
1446
- return (slot === void 0 ? reads : reads?.[slot]) && loadPart(loaded, "update");
1432
+ loading.finally(() => {
1433
+ loadingUpdates.delete(loading);
1434
+ if (loadingUpdates.size === 0 && running === 0) flushEffects();
1447
1435
  });
1448
1436
  }
1449
- /**
1450
- * Loads the update code that a write of a handler can need, so its writes run before it returns.
1451
- * A handler that is not in `w` of its module writes only the slots of its own component, and
1452
- * waits for the code of that component. A handler in `w` also waits for the components above it, which a
1453
- * write of a bound prop reaches, and for the scope that its children render in.
1454
- */
1455
- async function updateReady(scope, ref) {
1456
- if (!scope) return;
1457
- const root = findRoot(scope);
1458
- const own = ref && !(await loadModule(root.m)).w?.includes(ref.split("#")[1]);
1459
- return Promise.all([loadUpdate(scope), own ? loadUpdate(root) : Promise.all([updateReady(scope.p ?? scope.o), updateReady(scope.t)])]);
1460
- }
1461
1437
  /** The writes of the pass that runs that wait for code, to run as one pass of their own. */
1462
1438
  let waiting;
1463
1439
  /** The updates that wait for their code. */
@@ -1509,7 +1485,7 @@ function pass(write) {
1509
1485
  }
1510
1486
  }
1511
1487
  if (running === 0) {
1512
- if (!held) flushEffects();
1488
+ if (!held && loadingUpdates.size === 0) flushEffects();
1513
1489
  if (DEV) devtools()?.updated?.(updateCount, updateStart, performance.now());
1514
1490
  }
1515
1491
  return result;
@@ -1541,9 +1517,8 @@ globalThis[Symbol.for("brumate.flush")] = flush;
1541
1517
  function queueWrite(scope, slot) {
1542
1518
  const id = findRoot(scope).m;
1543
1519
  const module = modules.get(id);
1544
- const updates = loadedParts.get(`${id}:update`);
1545
- if (!module || !updates) return;
1546
- for (const [kind, name] of module.g[scope.k]?.[slot] ?? []) for (const target of kind === scope.k ? [scope] : descendants(scope, kind)) queue(updates[name], name, target);
1520
+ if (!module) return;
1521
+ for (const [kind, name] of module.g[scope.k]?.[slot] ?? []) for (const target of kind === scope.k ? [scope] : descendants(scope, kind)) queue(module[name], name, target);
1547
1522
  }
1548
1523
  /** Queues an update of a scope, once. */
1549
1524
  function queue(fn, name, target) {
@@ -1565,7 +1540,7 @@ function queue(fn, name, target) {
1565
1540
  origin = before;
1566
1541
  }
1567
1542
  } catch (error) {
1568
- fail(target, error);
1543
+ if (!(error instanceof NotReady)) fail(target, error);
1569
1544
  }
1570
1545
  }
1571
1546
  const depth = getDepth(target);
@@ -1681,7 +1656,7 @@ function effect(scope, name, callback, client) {
1681
1656
  if (error instanceof NotReady) {
1682
1657
  const token = {};
1683
1658
  skipped.set(key, token);
1684
- scope.cleanups.set(name, noop);
1659
+ scope.cleanups.set(name, noop$1);
1685
1660
  function again() {
1686
1661
  if (skipped.get(key) === token && scopes.get(scope.id) === scope) effect(scope, name, callback);
1687
1662
  }
@@ -1698,7 +1673,7 @@ function effect(scope, name, callback, client) {
1698
1673
  origin = outer;
1699
1674
  if (!client) runningEffects--;
1700
1675
  }
1701
- let stored = typeof cleanup === "function" ? cleanup : noop;
1676
+ let stored = typeof cleanup === "function" ? cleanup : noop$1;
1702
1677
  if (DEV) {
1703
1678
  devtools()?.effect?.(scope, name, "run", performance.now() - start);
1704
1679
  const own = stored;
@@ -1709,7 +1684,7 @@ function effect(scope, name, callback, client) {
1709
1684
  }
1710
1685
  scope.cleanups.set(name, stored);
1711
1686
  }
1712
- function noop() {}
1687
+ function noop$1() {}
1713
1688
  //#endregion
1714
1689
  //#region src/runtime/client/context.ts
1715
1690
  /** The scope that provides a context to `scope`: itself or the nearest one above it. */
@@ -1745,7 +1720,7 @@ function consumeContext(context, scope, slot) {
1745
1720
  }
1746
1721
  const provider = findProvider(target, context.key);
1747
1722
  if (provider) return provider.v[context.key];
1748
- if (context.key === "brumate.route" && !globals.has("brumate.route")) globals.set(ROUTE_KEY, currentRoute());
1723
+ if (HAS_ROUTES && context.key === "brumate.route" && !globals.has("brumate.route")) globals.set(ROUTE_KEY, currentRoute());
1749
1724
  return globals.has(context.key) ? globals.get(context.key) : context.defaultValue;
1750
1725
  }
1751
1726
  /** The values of the contexts that the runtime provides to the whole page, by key. */
@@ -1960,8 +1935,7 @@ function handle(element, entry, event, typed) {
1960
1935
  const loaded = Promise.all([
1961
1936
  resolve$1(ref),
1962
1937
  children,
1963
- code,
1964
- updateReady(scope, ref)
1938
+ code
1965
1939
  ]).then(([handler]) => handler);
1966
1940
  const started = lastHandler.then(() => loaded).then((handler) => {
1967
1941
  if (!DEV) return { value: pass(() => handler(scope, ...args)) };
@@ -1992,15 +1966,16 @@ function action(name, id, method, result) {
1992
1966
  * call loads, so the core holds only this.
1993
1967
  */
1994
1968
  function submitAction(form, submitter) {
1995
- import("./rpc-DvTwGfL_.js").then((module) => module.sendAction(form, submitter));
1969
+ import("./rpc-CIVU4Ktx.js").then((module) => module.sendAction(form, submitter));
1996
1970
  }
1997
1971
  /** Calls a server function. */
1998
1972
  async function rpc(id, args) {
1999
1973
  const signal = memoSignal();
2000
- return track(import("./rpc-DvTwGfL_.js").then((module) => module.call(rpcPrefix, id, args, signal)));
1974
+ return track(import("./rpc-CIVU4Ktx.js").then((module) => module.call(rpcPrefix, id, args, signal)));
2001
1975
  }
2002
1976
  /** A function prop rendered on the client calls the parent's exported handler. */
2003
1977
  function handlerProp(value, ref, scope, bound = [], modifiers) {
1978
+ if (DEV && isThenable(value)) throw new Error(`The handler prop of ${ref} gives a promise, and an event handler cannot wait for one [BRM188]. Await it in the code that runs, or read its value with $memo`);
2004
1979
  if (typeof value !== "function" || isTemplate(ref)) return value;
2005
1980
  const instance = resolveScope(scope);
2006
1981
  function handler(...args) {
@@ -2036,12 +2011,12 @@ function readRecord([script, code]) {
2036
2011
  const root = script.getAttribute("b-root") ?? "0";
2037
2012
  if (!refs.has(root)) refs.set(root, []);
2038
2013
  const decoded = code(refs.get(root), stateValues);
2039
- const catches = script.getAttribute("b-catch");
2014
+ const catches = HAS_TRIES ? script.getAttribute("b-catch") : null;
2040
2015
  if (catches !== null) {
2041
2016
  replaceTry(catches);
2042
2017
  return;
2043
2018
  }
2044
- if (script.getAttribute("b-fail") !== null) {
2019
+ if ((HAS_LATE_MARKUP ? script.getAttribute("b-fail") : null) !== null) {
2045
2020
  failBoundary(decoded);
2046
2021
  return;
2047
2022
  }
@@ -2136,7 +2111,6 @@ function addScopes(state, root) {
2136
2111
  if (record.f !== void 0) scope.f = scopes.get(record.f);
2137
2112
  if (record.l !== void 0) scope.l = scopes.get(record.l);
2138
2113
  }
2139
- for (const scope of added) if (scope.m) options.loadBundle?.(scope.m)?.catch(() => {});
2140
2114
  for (const scope of added) if (scope.m) loadComponent(scope.m);
2141
2115
  const seen = /* @__PURE__ */ new Set();
2142
2116
  for (const scope of added) {
@@ -2167,7 +2141,7 @@ function addScopes(state, root) {
2167
2141
  }
2168
2142
  for (const scope of added) for (const [anchor, bound] of Object.entries(state[scope.id].r ?? {})) {
2169
2143
  const element = findElement(scope.id, +anchor);
2170
- if (element) give(bound, element);
2144
+ if (element) give$1(bound, element);
2171
2145
  }
2172
2146
  }
2173
2147
  hooks.added?.(added);
@@ -2209,12 +2183,8 @@ function removeRoot(root) {
2209
2183
  function forget(ids) {
2210
2184
  for (const id of ids) {
2211
2185
  modules.delete(id);
2212
- loading.delete(id);
2186
+ loading$1.delete(id);
2213
2187
  pageComponents.delete(id);
2214
- for (const key of parts.keys()) if (key.startsWith(`${id}:`)) {
2215
- parts.delete(key);
2216
- loadedParts.delete(key);
2217
- }
2218
2188
  }
2219
2189
  }
2220
2190
  /** The values of the signals of components whose markup changed, for when the page renders again. */
@@ -2331,7 +2301,7 @@ function init(value) {
2331
2301
  if (HAS_LATE_MARKUP) observeMarkers();
2332
2302
  else if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => indexMarkers(document.documentElement), { once: true });
2333
2303
  indexMarkers(document.documentElement);
2334
- readFields();
2304
+ if (HAS_FIELDS) readFields();
2335
2305
  watchTitles(document);
2336
2306
  if (DEV) devtools()?.attach?.({
2337
2307
  scopes,
@@ -2340,237 +2310,6 @@ function init(value) {
2340
2310
  });
2341
2311
  }
2342
2312
  //#endregion
2343
- //#region src/runtime/client/branches.ts
2344
- /** Shows the branch at `index` of `#if` or `#switch`, or nothing for -1. */
2345
- function branch(scope, anchor, index, renders, kinds, holderKind, holderAnchor) {
2346
- const start = blockStart(scope, anchor);
2347
- if (!start) return;
2348
- if (Number(start.data.split(":")[2]) === index) return;
2349
- const end = rangeEnd(start);
2350
- removeBlock(scope, kinds, start, end);
2351
- start.data = `b${scope.id}:${anchor}:${index}`;
2352
- const render = inPlace(scope, renders[index], holderKind, holderAnchor);
2353
- if (render) insertHTML(end, render(scope));
2354
- }
2355
- /** Renders the body of `#key` again when its value changes. */
2356
- function rekey(scope, anchor, value, render, kinds, holderKind, holderAnchor) {
2357
- scope.keys ??= /* @__PURE__ */ new Map();
2358
- if (scope.keys.has(anchor) && Object.is(scope.keys.get(anchor), value)) return;
2359
- scope.keys.set(anchor, value);
2360
- const start = blockStart(scope, anchor);
2361
- if (!start) return;
2362
- const end = rangeEnd(start);
2363
- removeBlock(scope, kinds, start, end);
2364
- insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
2365
- }
2366
- /**
2367
- * `rekey` for the block around a dynamic tag. The first update keeps the element that the server
2368
- * rendered, when it has the tag already, such as an update of a scope that streams in after an
2369
- * event.
2370
- */
2371
- function retag(scope, anchor, value, render, kinds, holderKind, holderAnchor) {
2372
- scope.keys ??= /* @__PURE__ */ new Map();
2373
- if (!scope.keys.has(anchor) && typeof value === "string") {
2374
- let node = blockStart(scope, anchor)?.nextSibling;
2375
- while (node && node.nodeType !== 1 && node.nodeType !== 8) node = node.nextSibling;
2376
- if (node?.nodeType === 1 && node.localName === value.toLowerCase()) {
2377
- scope.keys.set(anchor, value);
2378
- return;
2379
- }
2380
- }
2381
- if (!scope.keys.has(anchor) && typeof value === "function") {
2382
- for (const block of scopes.values()) if (block.p === scope && kinds.includes(block.k)) {
2383
- for (const id of Object.values(block.c ?? {})) if (scopes.get(id)?.m === value.brumateId) {
2384
- scope.keys.set(anchor, value);
2385
- return;
2386
- }
2387
- }
2388
- }
2389
- rekey(scope, anchor, value, render, kinds, holderKind, holderAnchor);
2390
- }
2391
- /**
2392
- * Renders the body of a `#try` block again, for its `reset` function. If the
2393
- * body throws, the fallback renders again with the error.
2394
- */
2395
- async function reset(scope, anchor, id, body, fallback, kinds, holderKind, holderAnchor) {
2396
- const updates = await loadPart(await loadModule(id), "update");
2397
- const start = blockStart(scope, anchor);
2398
- if (!start) return;
2399
- const end = rangeEnd(start);
2400
- removeBlock(scope, kinds, start, end);
2401
- let html;
2402
- try {
2403
- html = inPlace(scope, updates[body], holderKind, holderAnchor)(scope);
2404
- } catch (error) {
2405
- disposeKinds(scope, kinds);
2406
- afterInsert.length = 0;
2407
- html = inPlace(scope, updates[fallback], holderKind, holderAnchor)(scope, error);
2408
- }
2409
- insertHTML(end, html);
2410
- }
2411
- /**
2412
- * Renders the body of a `#client` block once, in place of its fallback.
2413
- * `kinds` are the scope IDs inside the fallback, whose instances go.
2414
- */
2415
- function fill(scope, anchor, render, kinds = [], holderKind, holderAnchor) {
2416
- const start = blockStart(scope, anchor);
2417
- if (!start || start.data.split(":").length > 2) return;
2418
- start.data += ":1";
2419
- const end = rangeEnd(start);
2420
- removeBlock(scope, kinds, start, end);
2421
- insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
2422
- }
2423
- /**
2424
- * Shows or hides the body of an `#offscreen` block. A body that the page
2425
- * does not have yet renders the first time it shows. `kind` is the body's
2426
- * scope ID in the compiled component.
2427
- */
2428
- function offscreen(scope, anchor, value, render, kind, holderKind, holderAnchor) {
2429
- const start = blockStart(scope, anchor);
2430
- if (!start) return;
2431
- const visible = Boolean(value);
2432
- const state = start.data.split(":")[2];
2433
- if (visible ? state === "1" : state !== "1") return;
2434
- start.data = `b${scope.id}:${anchor}:${visible ? 1 : 0}`;
2435
- const end = rangeEnd(start);
2436
- if (state === "-1") {
2437
- insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
2438
- return;
2439
- }
2440
- let body;
2441
- for (const child of scope.children ?? []) if (child.k === kind) body = child;
2442
- if (body) {
2443
- const holder = hiding ?? setHiding(createHiding());
2444
- if (visible) holder.show(body);
2445
- else holder.hide(body, start, end);
2446
- }
2447
- }
2448
- /** True for a scope that is `ancestor` or inside it, also through the owner of a component. */
2449
- function within(scope, ancestor) {
2450
- for (let current = scope; current; current = current.p ?? current.o) if (current === ancestor) return true;
2451
- return false;
2452
- }
2453
- /** True for a scope in a hidden `#offscreen` body. */
2454
- function hidden(scope) {
2455
- for (let current = scope; current; current = current.p ?? current.o) if (current.h) return true;
2456
- return false;
2457
- }
2458
- /** The nodes between two markers. */
2459
- function between([start, end]) {
2460
- const result = [];
2461
- for (let node = start.nextSibling; node && node !== end; node = node.nextSibling) result.push(node);
2462
- return result;
2463
- }
2464
- /** The inline style of an element, which an element that is not HTML or SVG may not have. */
2465
- function display(element) {
2466
- return element.style;
2467
- }
2468
- function createHiding() {
2469
- const bodies = /* @__PURE__ */ new Set();
2470
- const nodes = /* @__PURE__ */ new WeakMap();
2471
- function hideNode(node) {
2472
- const saved = nodes.get(node);
2473
- if (saved) {
2474
- saved.n++;
2475
- return;
2476
- }
2477
- if (node.nodeType === 3) {
2478
- nodes.set(node, {
2479
- n: 1,
2480
- v: node.data
2481
- });
2482
- node.data = "";
2483
- return;
2484
- }
2485
- const style = node.nodeType === 1 ? display(node) : void 0;
2486
- if (style) {
2487
- nodes.set(node, {
2488
- n: 1,
2489
- v: style.getPropertyValue("display"),
2490
- p: style.getPropertyPriority("display"),
2491
- a: node.hasAttribute("style")
2492
- });
2493
- style.setProperty("display", "none", "important");
2494
- }
2495
- }
2496
- function showNode(node) {
2497
- const saved = nodes.get(node);
2498
- if (!saved || --saved.n > 0) return;
2499
- nodes.delete(node);
2500
- if (node.nodeType === 3) {
2501
- node.data = saved.v;
2502
- return;
2503
- }
2504
- const element = node;
2505
- const style = display(element);
2506
- if (saved.v) style.setProperty("display", saved.v, saved.p);
2507
- else style.removeProperty("display");
2508
- if (!saved.a && element.getAttribute("style") === "") element.removeAttribute("style");
2509
- }
2510
- return {
2511
- bodies,
2512
- nodes,
2513
- hidden,
2514
- hide(body, start, end) {
2515
- const record = {
2516
- scope: body,
2517
- ranges: [[start, end]]
2518
- };
2519
- body.h = record;
2520
- bodies.add(record);
2521
- const inside = [];
2522
- for (const scope of scopes.values()) if (within(scope, body)) inside.push(scope);
2523
- for (const scope of inside) {
2524
- const portal = comments.get(`P${scope.id}`);
2525
- if (portal?.isConnected) record.ranges.push([portal, rangeEnd(portal)]);
2526
- }
2527
- for (const range of record.ranges) for (const node of between(range)) hideNode(node);
2528
- for (const scope of inside) {
2529
- for (const [name, cleanup] of scope.cleanups ?? []) {
2530
- cleanup();
2531
- (scope.w ??= /* @__PURE__ */ new Set()).add(name);
2532
- }
2533
- scope.cleanups?.clear();
2534
- }
2535
- },
2536
- show(body) {
2537
- const record = body.h;
2538
- if (!record) return;
2539
- body.h = void 0;
2540
- bodies.delete(record);
2541
- for (const range of record.ranges) if (range[0].isConnected) for (const node of between(range)) showNode(node);
2542
- for (const scope of scopes.values()) if (scope.w && within(scope, body) && !hidden(scope)) {
2543
- const ref = `${findRoot(scope).m}#`;
2544
- for (const name of scope.w) call(ref + name, scope, []);
2545
- scope.w = void 0;
2546
- }
2547
- },
2548
- paused(scope, name) {
2549
- if (bodies.size === 0 || !hidden(scope)) return false;
2550
- (scope.w ??= /* @__PURE__ */ new Set()).add(name);
2551
- return true;
2552
- },
2553
- added(added) {
2554
- for (const node of added) for (const record of bodies) {
2555
- for (const [start, end] of record.ranges) if (node.parentNode === start.parentNode && start.compareDocumentPosition(node) & 4 && node.compareDocumentPosition(end) & 4) hideNode(node);
2556
- const data = node.nodeType === 8 ? node.data : "";
2557
- const scope = /^P-?[\d.]+$/.test(data) ? scopes.get(parseId(data.slice(1))) : void 0;
2558
- if (scope && within(scope, record.scope)) record.ranges.push([node, rangeEnd(node)]);
2559
- }
2560
- },
2561
- styled(element) {
2562
- const saved = nodes.get(element);
2563
- const style = display(element);
2564
- if (saved && style) {
2565
- saved.v = style.getPropertyValue("display");
2566
- saved.p = style.getPropertyPriority("display");
2567
- saved.a = element.hasAttribute("style");
2568
- style.setProperty("display", "none", "important");
2569
- }
2570
- }
2571
- };
2572
- }
2573
- //#endregion
2574
2313
  //#region src/runtime/client/templates.ts
2575
2314
  /** A template of the markup of a render, which `clone` parses once. */
2576
2315
  function template(html, count, foreign) {
@@ -2727,7 +2466,7 @@ function keepBlock(place, scope, data, anchor) {
2727
2466
  return found;
2728
2467
  }
2729
2468
  /** Puts what renders gave into the range that a marker of cloned markup opens. */
2730
- function fillRange(place, html, inserted) {
2469
+ function fillRange$1(place, html, inserted) {
2731
2470
  if (html) {
2732
2471
  place.after(parseHTML(html, place));
2733
2472
  markCloned();
@@ -2746,7 +2485,7 @@ function fillBranch(place, scope, anchor, index, renders) {
2746
2485
  const render = renders[index];
2747
2486
  if (found && render) {
2748
2487
  const out = render(found);
2749
- fillRange(place, typeof out === "string" ? out : "", typeof out === "string" ? void 0 : out);
2488
+ fillRange$1(place, typeof out === "string" ? out : "", typeof out === "string" ? void 0 : out);
2750
2489
  }
2751
2490
  }
2752
2491
  /** Fills a nested `#for` of cloned markup with its items, before the clone is in the page. */
@@ -2760,7 +2499,7 @@ function fillList(place, scope, anchor, items, render) {
2760
2499
  if (typeof out === "string") html += out;
2761
2500
  else (parts ??= document.createDocumentFragment()).append(out);
2762
2501
  }
2763
- fillRange(place, html, parts);
2502
+ fillRange$1(place, html, parts);
2764
2503
  }
2765
2504
  /** Writes an attribute of an element of cloned markup, as `attribute` writes it in HTML. */
2766
2505
  function setAttr(element, name, value) {
@@ -2832,39 +2571,10 @@ function setOn(element, on, own) {
2832
2571
  options?.listen(element);
2833
2572
  }
2834
2573
  }
2835
- /**
2836
- * The scope that `fillSettled` reported each rejection to, as two renders or two writes in one
2837
- * scope can read the same memo.
2838
- */
2839
- const reportedRejections = /* @__PURE__ */ new WeakMap();
2840
- /**
2841
- * Writes cloned markup that reads memos which never change, once the ones that are promises
2842
- * settle, as no update writes their values. A rejection goes to the nearest `#try` around the
2843
- * scope, or `onError`.
2844
- */
2845
- function fillSettled(scope, values, write) {
2846
- let loading = false;
2847
- for (const value of values) loading ||= isThenable(value);
2848
- if (!loading) {
2849
- write(...values);
2850
- return;
2851
- }
2852
- const at = resolveScope(scope);
2853
- Promise.all(values).then((settled) => {
2854
- if (scopes.get(at.id) === at) write(...settled);
2855
- }, (error) => {
2856
- if (scopes.get(at.id) !== at) return;
2857
- if (typeof error === "object" && error !== null) {
2858
- if (reportedRejections.get(error) === at) return;
2859
- reportedRejections.set(error, at);
2860
- }
2861
- fail(at, error);
2862
- });
2863
- }
2864
- /** Writes the content of an element of cloned markup, as `insert` writes it in HTML. */
2865
- function setContent(element, value, at) {
2866
- if (typeof value === "string" || typeof value === "number") {
2867
- element.textContent = String(value);
2574
+ /** Writes the content of an element of cloned markup, as `insert` writes it in HTML. */
2575
+ function setContent(element, value, at) {
2576
+ if (typeof value === "string" || typeof value === "number") {
2577
+ element.textContent = String(value);
2868
2578
  return;
2869
2579
  }
2870
2580
  element.replaceChildren(insertNodes(value, at, element));
@@ -2958,18 +2668,15 @@ function setSlots(id, values) {
2958
2668
  const value = values[slot];
2959
2669
  if (value instanceof Promise && scopes.get(id).props?.includes(value) && values.indexOf(value) === slot) {
2960
2670
  (scopes.get(id).plain ??= /* @__PURE__ */ new Set()).add(slot);
2961
- value.catch(noop);
2671
+ value.catch(noop$1);
2962
2672
  } else if (isThenable(value)) {
2963
2673
  const key = `${id}:${slot}`;
2964
2674
  renderedLoads.add(key);
2965
2675
  loadingValues.add(value);
2966
2676
  Promise.resolve(value).then((result) => {
2967
2677
  const scope = scopes.get(id);
2968
- if (scope?.s[slot] === value && !loads.has(key)) {
2969
- renderedLoads.delete(key);
2970
- set(scope, slot, result);
2971
- }
2972
- }, noop);
2678
+ if (scope?.s[slot] === value && !loads.has(key)) set(scope, slot, result);
2679
+ }, noop$1);
2973
2680
  }
2974
2681
  }
2975
2682
  scopes.get(id).props = void 0;
@@ -3173,7 +2880,7 @@ function withVariables(element, style) {
3173
2880
  return style ? `${style};${variables.join(";")}` : variables.join(";");
3174
2881
  }
3175
2882
  function attr(scope, anchor, name, value) {
3176
- if (scope.c?.[anchor] !== void 0) {
2883
+ if (HAS_DYNAMIC && scope.c?.[anchor] !== void 0) {
3177
2884
  prop(scope, anchor, name, value);
3178
2885
  return;
3179
2886
  }
@@ -3193,7 +2900,7 @@ function forwardRef(element, values) {
3193
2900
  if (isSlotReference(target)) {
3194
2901
  const owner = scopes.get(target.scope);
3195
2902
  if (owner) set(owner, target.slot, element);
3196
- } else give(target, element);
2903
+ } else give$1(target, element);
3197
2904
  }
3198
2905
  }
3199
2906
  /** The element of a spread in markup that the browser renders goes to the `ref` of its attributes. */
@@ -3241,6 +2948,905 @@ function updateSpreadEntries(element, values) {
3241
2948
  options.listen(element);
3242
2949
  }
3243
2950
  //#endregion
2951
+ //#region src/runtime/client/waits.ts
2952
+ /** The slots of a scope whose awaits settled, until the insert that shows the scope. */
2953
+ const settledSlots = /* @__PURE__ */ new WeakMap();
2954
+ /** The boundary of the render that runs, if any. */
2955
+ let boundary;
2956
+ /** The scope whose rest of a render runs after a wait, if any. */
2957
+ let resting;
2958
+ /** Runs a render with `own` as the boundary that its waits count in. */
2959
+ function within$1(own, render) {
2960
+ const outer = boundary;
2961
+ boundary = own;
2962
+ try {
2963
+ return render();
2964
+ } finally {
2965
+ boundary = outer;
2966
+ }
2967
+ }
2968
+ /**
2969
+ * Renders `body` in a boundary of its own. Returns what it rendered, and the boundary when a wait
2970
+ * in it has not settled. That boundary holds the scopes and the `afterInsert` work of the body,
2971
+ * so the insert of anything else does not take them. `give` puts them back before the body goes
2972
+ * in, and the caller sets `done`, and `f` if it handles failures, before any wait settles.
2973
+ */
2974
+ function bound(body) {
2975
+ const own = {
2976
+ n: 0,
2977
+ c: writes,
2978
+ o: boundary
2979
+ };
2980
+ const made = rendered.length;
2981
+ const queued = afterInsert.length;
2982
+ const out = within$1(own, body);
2983
+ if (own.n === 0) return [out];
2984
+ own.w = [rendered.splice(made), afterInsert.splice(queued)];
2985
+ return [out, own];
2986
+ }
2987
+ /**
2988
+ * Puts back the work that a boundary held, for the insert of its body. Updates do not reach a
2989
+ * body that is not in the page, since blocks find their markers in the page. So when anything
2990
+ * was written during the hold, the updates of the body's scopes all run once it is in.
2991
+ */
2992
+ function give(own) {
2993
+ const [made, queued] = own.w ?? [[], []];
2994
+ own.w = void 0;
2995
+ const outer = own.o?.w;
2996
+ if (outer) {
2997
+ outer[0].push(...made);
2998
+ outer[1].push(...queued);
2999
+ return;
3000
+ }
3001
+ if (own.c === writes) rendered.push(...made);
3002
+ else queued.push(() => refresh(made));
3003
+ afterInsert.push(...queued);
3004
+ }
3005
+ /**
3006
+ * The body of a `#try` that the browser renders, in a boundary of its own that counts as one wait
3007
+ * of the boundary around it. A wait of the body that fails ends there, so a `#loading` around the
3008
+ * `#try` shows its body, and `fail` renders the `#catch` body in place of the `#try`. Outside a
3009
+ * boundary, the body fills in place.
3010
+ */
3011
+ function attempt(body) {
3012
+ if (!boundary) return toNodes(body());
3013
+ const [out, own] = bound(body);
3014
+ if (own) {
3015
+ const outer = join();
3016
+ own.done = () => {
3017
+ give(own);
3018
+ leave(outer);
3019
+ };
3020
+ own.f = () => {
3021
+ own.done = void 0;
3022
+ own.f = noop$1;
3023
+ own.w = void 0;
3024
+ leave(outer);
3025
+ };
3026
+ }
3027
+ return toNodes(out);
3028
+ }
3029
+ /** Counts a new wait in the boundary of the render that runs, and returns that boundary. */
3030
+ function join() {
3031
+ const own = boundary;
3032
+ if (own) own.n++;
3033
+ return own;
3034
+ }
3035
+ /** True when the wait of `scope` in the range that `end` closes is gone with its block. */
3036
+ function gone(scope, end) {
3037
+ return scopes.get(scope.id) !== scope || !end.parentNode;
3038
+ }
3039
+ /**
3040
+ * Waits until `ready()`, then runs `run` a microtask later, outside the write that made it ready.
3041
+ * Each write of a slot, and the removal of `scope`, checks again. A scope or range that goes ends
3042
+ * the wait with `leave`. `run` gets the check, to wait again with `waiters.set(check, scope)`.
3043
+ */
3044
+ function until(own, scope, end, ready, run) {
3045
+ function check() {
3046
+ if (gone(scope, end)) {
3047
+ waiters.delete(check);
3048
+ leave(own);
3049
+ } else if (ready()) {
3050
+ waiters.delete(check);
3051
+ queueMicrotask(() => {
3052
+ if (gone(scope, end)) leave(own);
3053
+ else run(check);
3054
+ });
3055
+ }
3056
+ }
3057
+ waiters.set(check, scope);
3058
+ return check;
3059
+ }
3060
+ /** Ends a wait that `join` counted. At 0, the boundary runs `done`. */
3061
+ function leave(own) {
3062
+ if (own && --own.n === 0) own.done?.();
3063
+ }
3064
+ /** Ends a wait that failed: its boundary's `f`, or the count-down when the boundary has none. */
3065
+ function fault(own, error) {
3066
+ if (own?.f) own.f(error);
3067
+ else leave(own);
3068
+ }
3069
+ /** Ends a wait for a value that rejected: `fail`, once per error and scope, then `fault`. */
3070
+ function failOnce(scope, own, error) {
3071
+ if (scopes.get(scope.id) !== scope) {
3072
+ leave(own);
3073
+ return;
3074
+ }
3075
+ try {
3076
+ reportOnce(scope, error);
3077
+ } finally {
3078
+ fault(own, error);
3079
+ }
3080
+ }
3081
+ /**
3082
+ * The wait of cloned markup that reads memos which never change: `write` runs once the ones
3083
+ * that are promises settle, as no update writes their values. It counts in the boundary of the
3084
+ * render, as `wait` does. A rejection goes to `fail`, once per error and scope, then to `fault`.
3085
+ * A scope that goes during the wait ends it with `leave`.
3086
+ */
3087
+ function fillSettled(id, values, write) {
3088
+ let promised = false;
3089
+ for (const value of values) promised ||= isThenable(value);
3090
+ if (!promised) {
3091
+ write(...values);
3092
+ return;
3093
+ }
3094
+ const scope = resolveScope(id);
3095
+ const own = join();
3096
+ Promise.all(values).then((settled) => {
3097
+ try {
3098
+ if (scopes.get(scope.id) === scope) write(...settled);
3099
+ } finally {
3100
+ leave(own);
3101
+ }
3102
+ }, (error) => failOnce(scope, own, error));
3103
+ }
3104
+ /**
3105
+ * A value of markup that the browser writes, in text or an attribute, which can be a promise.
3106
+ * A value that is not one is written at once. A promise counts in the boundary of the render, as
3107
+ * a memo of `fillSettled` does, and `write` gets its value once it settles. The scope keeps the
3108
+ * latest value of each place, by `key`, so a promise that an update replaced before it settled
3109
+ * writes nothing: the latest wins.
3110
+ */
3111
+ function fillValue(id, key, value, write) {
3112
+ const scope = resolveScope(id);
3113
+ if (!isThenable(value)) {
3114
+ if (scope.q) scope.q[key] = value;
3115
+ write(value);
3116
+ return;
3117
+ }
3118
+ const latest = scope.q ??= {};
3119
+ latest[key] = value;
3120
+ fillSettled(scope, [value], (settled) => {
3121
+ if (latest[key] === value) write(settled);
3122
+ });
3123
+ }
3124
+ /**
3125
+ * A text insert of cloned markup whose value can be a promise, as `keepText` writes it, or as
3126
+ * `appendText` does at the end of the element when `append` is set. A promise leaves an empty
3127
+ * text node, which the scope keeps, so an update finds it, and its value takes the place of that
3128
+ * node once it settles, in or out of the page.
3129
+ */
3130
+ function keepValue(id, anchor, place, value, at = id, append) {
3131
+ const promised = isThenable(value);
3132
+ if (append) appendText(id, anchor, place, promised ? "" : value, at);
3133
+ else keepText(id, anchor, place, promised ? "" : value, at);
3134
+ if (promised) fillValue(id, anchor, value, (settled) => {
3135
+ const comment = document.createComment("");
3136
+ resolveScope(id).n[anchor].replaceWith(comment);
3137
+ keepText(id, anchor, comment, settled, at);
3138
+ });
3139
+ }
3140
+ /**
3141
+ * The update of the spreads of an element whose values can be promises, as `attrs` writes them.
3142
+ * An attribute whose value is a promise keeps what it shows until the promise settles.
3143
+ */
3144
+ function fillAttrs(scope, anchor, values, own) {
3145
+ const now = {};
3146
+ for (const [name, value] of Object.entries(values)) {
3147
+ const key = `${anchor} ${name}`;
3148
+ if (isThenable(value)) {
3149
+ now[name] = findElement(scope.id, anchor)?.getAttribute(name) ?? void 0;
3150
+ fillValue(scope, key, value, (settled) => attr(scope, anchor, name, settled));
3151
+ } else fillValue(scope, key, value, (settled) => {
3152
+ now[name] = settled;
3153
+ });
3154
+ }
3155
+ attrs(scope, anchor, now, own);
3156
+ }
3157
+ /**
3158
+ * The spreads of an element of cloned markup whose values can be promises, as `setSpread` writes
3159
+ * them. An attribute whose value is a promise is written once it settles. `place` names the
3160
+ * element among the places of the scope: its anchor, which the update of the spread uses too.
3161
+ */
3162
+ function fillSpread(id, place, element, attributes, on, names) {
3163
+ setSpread(element, attributes, on, names);
3164
+ for (const [name, value] of Object.entries(attributes)) if (isThenable(value)) fillValue(id, `${place} ${name}`, value, (settled) => setAttr(element, name, settled));
3165
+ }
3166
+ /**
3167
+ * Renders the rest of a wait in its boundary and puts it before `end`. In a boundary whose body
3168
+ * is not in the page yet, the scopes and work of the rest join the body's. A throw drops them.
3169
+ */
3170
+ function fillRange(own, end, rest) {
3171
+ const made = rendered.length;
3172
+ const queued = afterInsert.length;
3173
+ let out;
3174
+ try {
3175
+ out = within$1(own, rest);
3176
+ } catch (error) {
3177
+ rendered.length = made;
3178
+ afterInsert.length = queued;
3179
+ throw error;
3180
+ }
3181
+ if (own?.w) {
3182
+ own.w[0].push(...rendered.splice(made));
3183
+ own.w[1].push(...afterInsert.splice(queued));
3184
+ }
3185
+ insertHTML(end, out);
3186
+ }
3187
+ /**
3188
+ * The rest of a render after `const x = await $memo(...)`. `slots` are the slots that the code
3189
+ * before the `await` set, with the value of the memo at `slot`, and `rest` gets them back.
3190
+ *
3191
+ * A value goes on at once, in the same render. A promise leaves a range of two comments, and
3192
+ * the scope holds `slots` while it waits, so a parent can write its props. The rest renders when
3193
+ * the slot holds a value: the first load's, or a newer load's that a prop started, whichever
3194
+ * settles as the latest. Its markup fills the range. A rejection, or a throw of `rest`, goes to
3195
+ * `fail`. A scope that goes during the wait ends it, and its boundary counts down.
3196
+ */
3197
+ function wait(id, slots, slot, rest) {
3198
+ const scope = resolveScope(id);
3199
+ if (scope.s[slot] !== void 0) slots[slot] = scope.s[slot];
3200
+ const first = slots[slot];
3201
+ if (!isThenable(first)) return rest(slots);
3202
+ const promise = Promise.resolve(first);
3203
+ slots[slot] = void 0;
3204
+ const props = scope.props;
3205
+ setSlots(id, slots);
3206
+ scope.props = props;
3207
+ scope.s[slot] = promise;
3208
+ loadingValues.add(promise);
3209
+ const at = rendered.indexOf(scope);
3210
+ if (at !== -1) rendered.splice(at, 1);
3211
+ const item = "i" in scope && resting !== scope;
3212
+ const start = document.createComment(item ? `i${scope.id}` : `l${scope.id}:w`);
3213
+ const end = document.createComment(item ? "/i" : "/w");
3214
+ const range = document.createDocumentFragment();
3215
+ range.append(start, end);
3216
+ const own = join();
3217
+ function settle(check) {
3218
+ if (pending(scope, slot)) {
3219
+ waiters.set(check, scope);
3220
+ return;
3221
+ }
3222
+ const value = scope.s[slot];
3223
+ if (value instanceof MemoError) {
3224
+ fail(scope, value.error);
3225
+ fault(own, value.error);
3226
+ return;
3227
+ }
3228
+ let shown = false;
3229
+ try {
3230
+ fillRange(own, end, () => {
3231
+ rendered.push(scope);
3232
+ const outer = resting;
3233
+ resting = scope;
3234
+ try {
3235
+ const out = updating(() => rest(scope.s));
3236
+ shown = rendered.includes(scope);
3237
+ return out;
3238
+ } finally {
3239
+ resting = outer;
3240
+ }
3241
+ });
3242
+ } catch (error) {
3243
+ fail(scope, error);
3244
+ fault(own, error);
3245
+ return;
3246
+ }
3247
+ const done = settledSlots.get(scope) ?? [];
3248
+ done.push(slot);
3249
+ settledSlots.set(scope, done);
3250
+ if (shown) {
3251
+ settledSlots.delete(scope);
3252
+ for (const settled of done) if (settled < scope.s.length) renderedLoads.add(`${scope.id}:${settled}`);
3253
+ }
3254
+ leave(own);
3255
+ }
3256
+ const check = until(own, scope, end, () => !pending(scope, slot), settle);
3257
+ function write(value) {
3258
+ if (scope.s[slot] === promise) scope.s[slot] = value;
3259
+ if (waiters.has(check)) check();
3260
+ }
3261
+ promise.then(write, (error) => write(new MemoError(error)));
3262
+ return range;
3263
+ }
3264
+ /**
3265
+ * Starts the load of an awaited memo before its `await`, where its inputs are ready. A throw
3266
+ * becomes a rejected promise, and a rejection is handled here, so neither surfaces before the
3267
+ * `await` waits for the load, which gets the same rejection.
3268
+ */
3269
+ function started(load) {
3270
+ let value;
3271
+ try {
3272
+ value = load();
3273
+ } catch (error) {
3274
+ value = Promise.reject(error);
3275
+ }
3276
+ if (isThenable(value)) value.then(void 0, noop$1);
3277
+ return value;
3278
+ }
3279
+ /**
3280
+ * Starts the load of an awaited memo that reads other awaited memos once their loads settle.
3281
+ * `load` gets their values. A rejection of theirs rejects it too.
3282
+ */
3283
+ function after(loads, load) {
3284
+ return started(() => Promise.all(loads).then((values) => load(...values)));
3285
+ }
3286
+ /**
3287
+ * Gives back the work of a held body for its insert, and returns true. A body that went stale,
3288
+ * whose block left the page or whose scopes went, drops its scopes instead.
3289
+ */
3290
+ function take(own, at, stale) {
3291
+ let gone = stale || !at.isConnected;
3292
+ for (const scope of own.w?.[0] ?? []) gone ||= scopes.get(scope.id) !== scope;
3293
+ if (gone) {
3294
+ own.done = void 0;
3295
+ for (const scope of own.w?.[0] ?? []) destroy(scope);
3296
+ own.w = void 0;
3297
+ return false;
3298
+ }
3299
+ give(own);
3300
+ markCloned();
3301
+ return true;
3302
+ }
3303
+ /** The held body of each block, by the start comment of the block. */
3304
+ const holds = /* @__PURE__ */ new WeakMap();
3305
+ /** Drops the body that the block at `at` holds, if any. */
3306
+ function drop(at) {
3307
+ const held = holds.get(at);
3308
+ if (held) {
3309
+ holds.delete(at);
3310
+ take(held[1], at, true);
3311
+ }
3312
+ }
3313
+ /**
3314
+ * The root boundary. The server holds the page outside every `#loading` until its waits end,
3315
+ * so a block there keeps what it shows until the waits of its new body end. `render` renders
3316
+ * the body for `key` in a boundary, and `show` puts it in place of the old one: at once when
3317
+ * nothing waits, otherwise when the waits end. A block that asks again for the key that it
3318
+ * holds keeps waiting, and another key drops the held body.
3319
+ */
3320
+ function hold(at, key, render, show) {
3321
+ const held = holds.get(at);
3322
+ if (held && Object.is(held[0], key)) {
3323
+ held[2] = false;
3324
+ return;
3325
+ }
3326
+ drop(at);
3327
+ const [out, own] = bound(render);
3328
+ if (!own) {
3329
+ show(out);
3330
+ return;
3331
+ }
3332
+ const entry = [key, own];
3333
+ holds.set(at, entry);
3334
+ own.done = () => {
3335
+ holds.delete(at);
3336
+ if (take(own, at, entry[2])) show(out);
3337
+ };
3338
+ }
3339
+ /**
3340
+ * Renders a new body of a block in the root boundary, and puts it in place of the old body when
3341
+ * its waits end. The new body renders before the old one goes, so the script of a new body runs
3342
+ * before the cleanups of the old one, and its effects after them.
3343
+ */
3344
+ function swap(scope, kinds, start, key, render, mark) {
3345
+ const made = [];
3346
+ function renderNew() {
3347
+ const old = new Set(scope.children);
3348
+ const out = render();
3349
+ for (const child of scope.children ?? []) if (!old.has(child)) made.push(child);
3350
+ return out;
3351
+ }
3352
+ hold(start, key, renderNew, (out) => {
3353
+ for (const child of Array.from(scope.children ?? [])) if (kinds.includes(child.k) && !made.includes(child)) destroy(child);
3354
+ const end = rangeEnd(start);
3355
+ removeBlock(scope, [], start, end);
3356
+ mark?.();
3357
+ insertHTML(end, out);
3358
+ });
3359
+ }
3360
+ /**
3361
+ * The block at `at` went back to what it shows. Its held body goes when it settles, unless the
3362
+ * block asks for it again before, which then does not render and load it again.
3363
+ */
3364
+ function release(at) {
3365
+ const held = holds.get(at);
3366
+ if (held) held[2] = true;
3367
+ }
3368
+ /**
3369
+ * A new row of a list outside every `#loading`, which shows when its waits end. A row that waits
3370
+ * leaves an empty item marker in its place, so the next update of the list finds it and does
3371
+ * not render it again.
3372
+ */
3373
+ function holdRow(list, render) {
3374
+ const [out, own] = bound(render);
3375
+ if (!own) return out;
3376
+ let row;
3377
+ for (const scope of own.w[0]) if (scope.p === list) row ??= scope;
3378
+ const first = typeof out === "string" ? void 0 : out.firstChild;
3379
+ let mark = `i${(row ?? own.w[0][0])?.id}`;
3380
+ if (!row && first?.nodeType === 8 && first.data[0] === "i") mark = first.data;
3381
+ const start = document.createComment(mark);
3382
+ const end = document.createComment("/i");
3383
+ const range = document.createDocumentFragment();
3384
+ range.append(start, end);
3385
+ own.done = () => {
3386
+ if (take(own, end)) insertHTML(end, out);
3387
+ };
3388
+ return range;
3389
+ }
3390
+ /**
3391
+ * Counts the memos that markup of a browser render reads and that still load, in the boundary of
3392
+ * the render, as the server waits for them. The compiler passes the memos of a scope that markup
3393
+ * outside every `#loading` body reads, and the memos that a `#loading` body reads from outside.
3394
+ * Each counts down when its value settles. A rejection goes to `fail` and `fault`, as in
3395
+ * `fillSettled`. Outside a boundary, the markup fills in when the values arrive.
3396
+ */
3397
+ function countLoads(id, values) {
3398
+ if (!(HAS_LOADING || HAS_ROOT_WAIT) || !boundary) return;
3399
+ for (const value of values) if (isThenable(value)) {
3400
+ const scope = resolveScope(id);
3401
+ const own = join();
3402
+ Promise.resolve(value).then(() => updated().then(() => leave(own)), (error) => failOnce(scope, own, error));
3403
+ }
3404
+ }
3405
+ /** The `#reveal` block whose body renders, which the `#loading` blocks of the render join. */
3406
+ let revealing;
3407
+ /**
3408
+ * A `#reveal` block in a browser render: the `#loading` blocks that its body renders, also in
3409
+ * the components inside it, join one group, as on the server. The group ends with the render,
3410
+ * before any body settles, so a block that a later update adds there is not ordered.
3411
+ */
3412
+ function reveal(order, collapsed, body) {
3413
+ const group = {
3414
+ o: order,
3415
+ c: collapsed,
3416
+ m: [],
3417
+ t: () => showTurns(group)
3418
+ };
3419
+ queueMicrotask(() => {
3420
+ group.e = true;
3421
+ group.t();
3422
+ });
3423
+ const outer = revealing;
3424
+ revealing = group;
3425
+ try {
3426
+ return toNodes(body());
3427
+ } finally {
3428
+ revealing = outer;
3429
+ }
3430
+ }
3431
+ /** Shows the bodies of a `#reveal` block that are ready and whose turn it is. */
3432
+ function showTurns(group) {
3433
+ const { m: members, o: order } = group;
3434
+ function showAt(index) {
3435
+ const member = members[index];
3436
+ member.d = true;
3437
+ member.s();
3438
+ members[index + 1]?.f?.();
3439
+ }
3440
+ if (order === "natural") {
3441
+ for (const [index, member] of members.entries()) if (member.s && !member.d) showAt(index);
3442
+ } else if (order === "sequential") {
3443
+ for (let index = 0; index < members.length && members[index].s; index++) if (!members[index].d) showAt(index);
3444
+ } else if (group.e && order === "backwards") {
3445
+ for (let index = members.length - 1; index >= 0 && members[index].s; index--) if (!members[index].d) showAt(index);
3446
+ } else if (group.e) {
3447
+ let ready = true;
3448
+ for (const member of members) ready &&= member.s !== void 0;
3449
+ for (const [index, member] of members.entries()) if (ready && !member.d) showAt(index);
3450
+ }
3451
+ }
3452
+ /** What a body or a fallback rendered, as nodes. HTML holds clones that it parses back in. */
3453
+ function toNodes(out) {
3454
+ if (typeof out !== "string") return out;
3455
+ markCloned();
3456
+ return parseHTML(out);
3457
+ }
3458
+ /**
3459
+ * A `#loading` block that the browser renders, as a streamed one shows: the body at once when
3460
+ * nothing that it reads loads, and otherwise the fallback, until every wait of the body ends.
3461
+ * The body renders now, in a boundary of its own, and enters the page in one insert with its
3462
+ * work. A body whose wait fails keeps the fallback, and `fail` reported the error. The `#reveal`
3463
+ * block around it can hold a body that is ready for its turn. Updates after that keep the
3464
+ * content, since they render no boundary.
3465
+ */
3466
+ function loading(body, fallback) {
3467
+ const group = revealing;
3468
+ revealing = void 0;
3469
+ try {
3470
+ return renderLoading(group, body, fallback);
3471
+ } finally {
3472
+ revealing = group;
3473
+ }
3474
+ }
3475
+ /** `loading` with the `#reveal` group of the render, and none for its own body and fallback. */
3476
+ function renderLoading(group, body, fallback) {
3477
+ const made = rendered.length;
3478
+ const queued = afterInsert.length;
3479
+ const turn = group && !(group.o === "natural" || group.o === "sequential" && group.m.length === 0);
3480
+ const result = bound(body);
3481
+ const nodes = toNodes(result[0]);
3482
+ let own = result[1];
3483
+ if (!own) {
3484
+ if (!turn) return nodes;
3485
+ own = {
3486
+ n: 0,
3487
+ c: writes,
3488
+ o: boundary,
3489
+ w: [rendered.splice(made), afterInsert.splice(queued)]
3490
+ };
3491
+ }
3492
+ const held = own;
3493
+ const start = document.createComment("");
3494
+ const end = document.createComment("");
3495
+ const range = document.createDocumentFragment();
3496
+ let fallbackScopes = [];
3497
+ function showFallback() {
3498
+ const first = rendered.length;
3499
+ const fallbackNodes = fallback ? toNodes(fallback()) : document.createDocumentFragment();
3500
+ fallbackScopes = rendered.slice(first);
3501
+ return fallbackNodes;
3502
+ }
3503
+ const member = {};
3504
+ const hidden = group?.c && group.m.length > 0;
3505
+ range.append(start);
3506
+ if (!hidden) range.append(showFallback());
3507
+ range.append(end);
3508
+ if (hidden) member.f = () => {
3509
+ if (end.parentNode) insertHTML(end, showFallback());
3510
+ };
3511
+ function showBody() {
3512
+ let dropped = !end.parentNode;
3513
+ for (const scope of held.w?.[0] ?? []) dropped ||= scopes.get(scope.id) !== scope;
3514
+ if (dropped) {
3515
+ held.w = void 0;
3516
+ return;
3517
+ }
3518
+ for (const scope of fallbackScopes) destroy(scope);
3519
+ clear(start, end);
3520
+ give(held);
3521
+ markCloned();
3522
+ insertHTML(end, nodes);
3523
+ }
3524
+ if (group) group.m.push(member);
3525
+ held.done = () => {
3526
+ if (group) {
3527
+ member.s = showBody;
3528
+ group.t();
3529
+ } else showBody();
3530
+ };
3531
+ held.f = () => {
3532
+ held.done = void 0;
3533
+ held.f = noop$1;
3534
+ for (const scope of held.w?.[0] ?? []) destroy(scope);
3535
+ held.w = void 0;
3536
+ if (group) {
3537
+ member.s = noop$1;
3538
+ group.t();
3539
+ }
3540
+ };
3541
+ if (held.n === 0) held.done();
3542
+ return range;
3543
+ }
3544
+ //#endregion
3545
+ //#region src/runtime/client/branches.ts
3546
+ /** Shows the branch at `index` of `#if` or `#switch`, or nothing for -1. */
3547
+ function branch(scope, anchor, index, renders, kinds, holderKind, holderAnchor) {
3548
+ const start = blockStart(scope, anchor);
3549
+ if (!start) return;
3550
+ if (Number(start.data.split(":")[2]) === index) {
3551
+ if (HAS_ROOT_WAIT) release(start);
3552
+ return;
3553
+ }
3554
+ if (HAS_ROOT_WAIT) {
3555
+ const body = inPlace(scope, renders[index], holderKind, holderAnchor);
3556
+ swap(scope, kinds, start, index, () => body ? body(scope) : "", () => {
3557
+ start.data = `b${scope.id}:${anchor}:${index}`;
3558
+ });
3559
+ return;
3560
+ }
3561
+ const end = rangeEnd(start);
3562
+ removeBlock(scope, kinds, start, end);
3563
+ start.data = `b${scope.id}:${anchor}:${index}`;
3564
+ const render = inPlace(scope, renders[index], holderKind, holderAnchor);
3565
+ if (render) insertHTML(end, render(scope));
3566
+ }
3567
+ /** Renders the body of `#key` again when its value changes. */
3568
+ function rekey(scope, anchor, value, render, kinds, holderKind, holderAnchor) {
3569
+ scope.keys ??= /* @__PURE__ */ new Map();
3570
+ if (scope.keys.has(anchor) && Object.is(scope.keys.get(anchor), value)) {
3571
+ const start = HAS_ROOT_WAIT && blockStart(scope, anchor);
3572
+ if (start) release(start);
3573
+ return;
3574
+ }
3575
+ if (HAS_ROOT_WAIT) {
3576
+ const start = blockStart(scope, anchor);
3577
+ const keys = scope.keys;
3578
+ if (!start) {
3579
+ keys.set(anchor, value);
3580
+ return;
3581
+ }
3582
+ const body = inPlace(scope, render, holderKind, holderAnchor);
3583
+ swap(scope, kinds, start, value, () => body(scope), () => keys.set(anchor, value));
3584
+ return;
3585
+ }
3586
+ scope.keys.set(anchor, value);
3587
+ const start = blockStart(scope, anchor);
3588
+ if (!start) return;
3589
+ const end = rangeEnd(start);
3590
+ removeBlock(scope, kinds, start, end);
3591
+ insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
3592
+ }
3593
+ /**
3594
+ * `rekey` for the block around a dynamic tag. The first update keeps the element that the server
3595
+ * rendered, when it has the tag already, such as an update of a scope that streams in after an
3596
+ * event.
3597
+ */
3598
+ function retag(scope, anchor, value, render, kinds, holderKind, holderAnchor) {
3599
+ scope.keys ??= /* @__PURE__ */ new Map();
3600
+ if (!scope.keys.has(anchor) && typeof value === "string") {
3601
+ let node = blockStart(scope, anchor)?.nextSibling;
3602
+ while (node && node.nodeType !== 1 && node.nodeType !== 8) node = node.nextSibling;
3603
+ if (node?.nodeType === 1 && node.localName === value.toLowerCase()) {
3604
+ scope.keys.set(anchor, value);
3605
+ return;
3606
+ }
3607
+ }
3608
+ if (!scope.keys.has(anchor) && typeof value === "function") {
3609
+ for (const block of scopes.values()) if (block.p === scope && kinds.includes(block.k)) {
3610
+ for (const id of Object.values(block.c ?? {})) if (scopes.get(id)?.m === value.brumateId) {
3611
+ scope.keys.set(anchor, value);
3612
+ return;
3613
+ }
3614
+ }
3615
+ }
3616
+ rekey(scope, anchor, value, render, kinds, holderKind, holderAnchor);
3617
+ }
3618
+ /**
3619
+ * Renders the body of a `#try` block again, for its `reset` function. If the
3620
+ * body throws, the fallback renders again with the error.
3621
+ */
3622
+ async function reset(scope, anchor, id, body, fallback, kinds, holderKind, holderAnchor) {
3623
+ const updates = await loadModule(id);
3624
+ const start = blockStart(scope, anchor);
3625
+ if (!start) return;
3626
+ const end = rangeEnd(start);
3627
+ removeBlock(scope, kinds, start, end);
3628
+ let html;
3629
+ try {
3630
+ html = inPlace(scope, updates[body], holderKind, holderAnchor)(scope);
3631
+ } catch (error) {
3632
+ disposeKinds(scope, kinds);
3633
+ afterInsert.length = 0;
3634
+ html = inPlace(scope, updates[fallback], holderKind, holderAnchor)(scope, error);
3635
+ }
3636
+ insertHTML(end, html);
3637
+ }
3638
+ /**
3639
+ * Renders the body of a `#client` block once, in place of its fallback.
3640
+ * `kinds` are the scope IDs inside the fallback, whose instances go.
3641
+ */
3642
+ function fill(scope, anchor, render, kinds = [], holderKind, holderAnchor) {
3643
+ const start = blockStart(scope, anchor);
3644
+ if (!start || start.data.split(":").length > 2) return;
3645
+ if (HAS_ROOT_WAIT) {
3646
+ const body = inPlace(scope, render, holderKind, holderAnchor);
3647
+ hold(start, 1, () => body(scope), (out) => {
3648
+ start.data += ":1";
3649
+ const end = rangeEnd(start);
3650
+ removeBlock(scope, kinds, start, end);
3651
+ insertHTML(end, out);
3652
+ });
3653
+ return;
3654
+ }
3655
+ start.data += ":1";
3656
+ const end = rangeEnd(start);
3657
+ removeBlock(scope, kinds, start, end);
3658
+ insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
3659
+ }
3660
+ /**
3661
+ * Shows or hides the body of an `#offscreen` block. A body that the page
3662
+ * does not have yet renders the first time it shows. `kind` is the body's
3663
+ * scope ID in the compiled component.
3664
+ */
3665
+ function offscreen(scope, anchor, value, render, kind, holderKind, holderAnchor) {
3666
+ const start = blockStart(scope, anchor);
3667
+ if (!start) return;
3668
+ const visible = Boolean(value);
3669
+ const state = start.data.split(":")[2];
3670
+ if (visible ? state === "1" : state !== "1") return;
3671
+ start.data = `b${scope.id}:${anchor}:${visible ? 1 : 0}`;
3672
+ const end = rangeEnd(start);
3673
+ if (state === "-1") {
3674
+ if (HAS_ROOT_WAIT) {
3675
+ const body = inPlace(scope, render, holderKind, holderAnchor);
3676
+ hold(start, 1, () => body(scope), (out) => insertHTML(end, out));
3677
+ return;
3678
+ }
3679
+ insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
3680
+ return;
3681
+ }
3682
+ let body;
3683
+ for (const child of scope.children ?? []) if (child.k === kind) body = child;
3684
+ if (body) {
3685
+ const holder = hiding ?? setHiding(createHiding());
3686
+ if (visible) holder.show(body);
3687
+ else holder.hide(body, start, end);
3688
+ }
3689
+ }
3690
+ /** The ranges of the fallbacks that `#loading (memo)` blocks show, by the start of the body. */
3691
+ const fallbacks = /* @__PURE__ */ new WeakMap();
3692
+ /**
3693
+ * Hides the body of a `#loading (memo)` block that has shown, and shows its fallback after it,
3694
+ * while a memo of the header loads, then shows the body again. The body stays in the page and
3695
+ * follows the `#offscreen` rules. A body that has not shown yet has no markers in the page, so
3696
+ * its boundary shows the fallback. `kind` is the body's scope ID in the compiled component, and
3697
+ * `kinds` are the scope IDs inside the fallback, whose instances go with it.
3698
+ */
3699
+ function held(scope, anchor, pending, kind, render, kinds, holderKind, holderAnchor) {
3700
+ const start = blockStart(scope, anchor);
3701
+ if (!start || start.data.split(":")[2] === "0" === pending) return;
3702
+ start.data = `b${scope.id}:${anchor}:${pending ? 0 : 1}`;
3703
+ const end = rangeEnd(start);
3704
+ let body;
3705
+ for (const child of scope.children ?? []) if (child.k === kind) body = child;
3706
+ const holder = hiding ?? setHiding(createHiding());
3707
+ if (pending) {
3708
+ const range = [document.createComment(""), document.createComment("")];
3709
+ end.after(...range);
3710
+ fallbacks.set(start, range);
3711
+ if (body) holder.hide(body, start, end);
3712
+ if (render) insertHTML(range[1], inPlace(scope, render, holderKind, holderAnchor)(scope));
3713
+ return;
3714
+ }
3715
+ const range = fallbacks.get(start);
3716
+ if (range) {
3717
+ fallbacks.delete(start);
3718
+ removeBlock(scope, kinds, range[0], range[1]);
3719
+ range[0].remove();
3720
+ range[1].remove();
3721
+ }
3722
+ if (body) holder.show(body);
3723
+ }
3724
+ /** True for a scope that is `ancestor` or inside it, also through the owner of a component. */
3725
+ function within(scope, ancestor) {
3726
+ for (let current = scope; current; current = current.p ?? current.o) if (current === ancestor) return true;
3727
+ return false;
3728
+ }
3729
+ /** True for a scope in a hidden `#offscreen` body. */
3730
+ function hidden(scope) {
3731
+ for (let current = scope; current; current = current.p ?? current.o) if (current.h) return true;
3732
+ return false;
3733
+ }
3734
+ /** The nodes between two markers. */
3735
+ function between([start, end]) {
3736
+ const result = [];
3737
+ for (let node = start.nextSibling; node && node !== end; node = node.nextSibling) result.push(node);
3738
+ return result;
3739
+ }
3740
+ /** The inline style of an element, which an element that is not HTML or SVG may not have. */
3741
+ function display(element) {
3742
+ return element.style;
3743
+ }
3744
+ function createHiding() {
3745
+ const bodies = /* @__PURE__ */ new Set();
3746
+ const nodes = /* @__PURE__ */ new WeakMap();
3747
+ function hideNode(node) {
3748
+ const saved = nodes.get(node);
3749
+ if (saved) {
3750
+ saved.n++;
3751
+ return;
3752
+ }
3753
+ if (node.nodeType === 3) {
3754
+ nodes.set(node, {
3755
+ n: 1,
3756
+ v: node.data
3757
+ });
3758
+ node.data = "";
3759
+ return;
3760
+ }
3761
+ const style = node.nodeType === 1 ? display(node) : void 0;
3762
+ if (style) {
3763
+ nodes.set(node, {
3764
+ n: 1,
3765
+ v: style.getPropertyValue("display"),
3766
+ p: style.getPropertyPriority("display"),
3767
+ a: node.hasAttribute("style")
3768
+ });
3769
+ style.setProperty("display", "none", "important");
3770
+ }
3771
+ }
3772
+ function showNode(node) {
3773
+ const saved = nodes.get(node);
3774
+ if (!saved || --saved.n > 0) return;
3775
+ nodes.delete(node);
3776
+ if (node.nodeType === 3) {
3777
+ node.data = saved.v;
3778
+ return;
3779
+ }
3780
+ const element = node;
3781
+ const style = display(element);
3782
+ if (saved.v) style.setProperty("display", saved.v, saved.p);
3783
+ else style.removeProperty("display");
3784
+ if (!saved.a && element.getAttribute("style") === "") element.removeAttribute("style");
3785
+ }
3786
+ return {
3787
+ bodies,
3788
+ nodes,
3789
+ hidden,
3790
+ hide(body, start, end) {
3791
+ const record = {
3792
+ scope: body,
3793
+ ranges: [[start, end]]
3794
+ };
3795
+ body.h = record;
3796
+ bodies.add(record);
3797
+ const inside = [];
3798
+ for (const scope of scopes.values()) if (within(scope, body)) inside.push(scope);
3799
+ for (const scope of inside) {
3800
+ const portal = comments.get(`P${scope.id}`);
3801
+ if (portal?.isConnected) record.ranges.push([portal, rangeEnd(portal)]);
3802
+ }
3803
+ for (const range of record.ranges) for (const node of between(range)) hideNode(node);
3804
+ for (const scope of inside) {
3805
+ for (const [name, cleanup] of scope.cleanups ?? []) {
3806
+ cleanup();
3807
+ (scope.w ??= /* @__PURE__ */ new Set()).add(name);
3808
+ }
3809
+ scope.cleanups?.clear();
3810
+ }
3811
+ },
3812
+ show(body) {
3813
+ const record = body.h;
3814
+ if (!record) return;
3815
+ body.h = void 0;
3816
+ bodies.delete(record);
3817
+ for (const range of record.ranges) if (range[0].isConnected) for (const node of between(range)) showNode(node);
3818
+ for (const scope of scopes.values()) if (scope.w && within(scope, body) && !hidden(scope)) {
3819
+ const ref = `${findRoot(scope).m}#`;
3820
+ for (const name of scope.w) call(ref + name, scope, []);
3821
+ scope.w = void 0;
3822
+ }
3823
+ },
3824
+ paused(scope, name) {
3825
+ if (bodies.size === 0 || !hidden(scope)) return false;
3826
+ (scope.w ??= /* @__PURE__ */ new Set()).add(name);
3827
+ return true;
3828
+ },
3829
+ added(added) {
3830
+ for (const node of added) for (const record of bodies) {
3831
+ for (const [start, end] of record.ranges) if (node.parentNode === start.parentNode && start.compareDocumentPosition(node) & 4 && node.compareDocumentPosition(end) & 4) hideNode(node);
3832
+ const data = node.nodeType === 8 ? node.data : "";
3833
+ const scope = /^P-?[\d.]+$/.test(data) ? scopes.get(parseId(data.slice(1))) : void 0;
3834
+ if (scope && within(scope, record.scope)) record.ranges.push([node, rangeEnd(node)]);
3835
+ }
3836
+ },
3837
+ styled(element) {
3838
+ const saved = nodes.get(element);
3839
+ const style = display(element);
3840
+ if (saved && style) {
3841
+ saved.v = style.getPropertyValue("display");
3842
+ saved.p = style.getPropertyPriority("display");
3843
+ saved.a = element.hasAttribute("style");
3844
+ style.setProperty("display", "none", "important");
3845
+ }
3846
+ }
3847
+ };
3848
+ }
3849
+ //#endregion
3244
3850
  //#region src/runtime/client/lists.ts
3245
3851
  const ITEM_MARKER = /^i(-?[\d.]+)$/;
3246
3852
  /** The items of a `#for` list: an array as it is, since `list` only reads it, or any iterable as an array. */
@@ -3248,7 +3854,8 @@ function toList(value) {
3248
3854
  return Array.isArray(value) ? value : Array.from(value);
3249
3855
  }
3250
3856
  /** Updates the items of `#for` or `#repeat`, keeping the elements of items whose keys stay. */
3251
- function list(scope, anchor, items, key, given, assign, givenFallback, fallbackKinds, holderKind, holderAnchor, park) {
3857
+ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackKinds, holderKind, holderAnchor, givenPark) {
3858
+ const park = HAS_WINDOWS ? givenPark : void 0;
3252
3859
  const start = blockStart(scope, anchor);
3253
3860
  if (!start) return;
3254
3861
  const render = inPlace(scope, given, holderKind, holderAnchor);
@@ -3306,11 +3913,19 @@ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackK
3306
3913
  }
3307
3914
  if (count === 0 && !(park && park.total > 0)) {
3308
3915
  if (previous.size === 0 && others) return;
3916
+ if (HAS_ROOT_WAIT) {
3917
+ hold(start, 0, () => fallback ? fallback(scope) : "", (out) => {
3918
+ removeBlock(scope, [], start, end);
3919
+ insertHTML(end, out);
3920
+ });
3921
+ return;
3922
+ }
3309
3923
  for (const [id, item] of previous) leave(id, item);
3310
3924
  clear(start, end);
3311
3925
  if (fallback) insertHTML(end, fallback(scope));
3312
3926
  return;
3313
3927
  }
3928
+ if (HAS_ROOT_WAIT) release(start);
3314
3929
  disposeKinds(scope, fallbackKinds);
3315
3930
  if (others) for (const node of others) node.parentNode?.removeChild(node);
3316
3931
  const parent = end.parentNode;
@@ -3318,6 +3933,7 @@ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackK
3318
3933
  const kept = [];
3319
3934
  for (let index = 0; index < count; index++) {
3320
3935
  const id = keys[index] = key(items[index], index + (park?.from ?? 0));
3936
+ if (DEV && isThenable(id)) throw new Error("The key of a #for row gives a promise, and the key of a #for cannot wait for one [BRM188]. Await it in the code that runs, or read its value with $memo");
3321
3937
  const item = previous.get(id);
3322
3938
  if (item && !item.kept) {
3323
3939
  item.kept = true;
@@ -3353,7 +3969,11 @@ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackK
3353
3969
  continue;
3354
3970
  }
3355
3971
  if (!item) {
3356
- const out = render(scope, items[index], index);
3972
+ let out;
3973
+ if (HAS_ROOT_WAIT) {
3974
+ out = holdRow(scope, () => render(scope, items[index], index));
3975
+ if (typeof out === "string" ? addedNodes : added) flushAdded();
3976
+ } else out = render(scope, items[index], index);
3357
3977
  if (typeof out === "string") added += out;
3358
3978
  else (addedNodes ??= []).push(out);
3359
3979
  continue;
@@ -3561,10 +4181,11 @@ const loader = {
3561
4181
  handle,
3562
4182
  dispose,
3563
4183
  submitAction,
3564
- setGlobal,
3565
- updateRoute
4184
+ setGlobal: HAS_ROUTES ? setGlobal : noop,
4185
+ updateRoute: HAS_ROUTES ? updateRoute : noop
3566
4186
  };
4187
+ function noop() {}
3567
4188
  //#endregion
3568
- export { dispose as $, scopes as $t, branchNodes as A, timed as At, putText as B, descendants as Bt, dynamicNodes as C, effect as Ct, setItem as D, pending as Dt, place as E, memo as Et, keep as F, children as Ft, setSpread as G, sink as Gt, setAttrText as H, makeId as Ht, keepText as I, insert as It, fill as J, nameComment as Jt, template as K, loadModule as Kt, listNodes as L, title as Lt, fillBranch as M, update as Mt, fillList as N, updated as Nt, setSlots as O, resolve as Ot, fillSettled as P, fail as Pt, retag as Q, rpcPrefix as Qt, markBlock as R, afterInsert as Rt, dynamic as S, cells as St, foreignNodes as T, isBound as Tt, setContent as U, removeScope as Ut, setAttr as V, getScope as Vt, setOn as W, setOwner as Wt, rekey as X, build as Xt, offscreen as Y, DEVTOOLS as Yt, reset as Z, hooks as Zt, writeText as _, updateContext as _t, deferInBrowser as a, removeRoot as at, component as b, binding as bt, toList as c, handlerProp as ct, attr as d, submitAction as dt, skew as en, forget as et, attrs as f, guess as ft, text as g, setGlobal as gt, restRef as h, provideValue as ht, addStyle as i, remount as it, clone as j, unreadMemo as jt, appendText as k, set as kt, windowList as l, rpc as lt, portalTo as m, consumeContext as mt, addHead as n, leavePage as nt, setVar as o, action as ot, content as p, track as pt, branch as q, loadPart as qt, addPortal as r, leaveRoutes as rt, list as s, handle as st, loader as t, init as tt, windowStart as u, spread as ut, prop as v, updateRoute as vt, elementAt as w, get as wt, componentNodes as x, bindings as xt, spreadProps as y, asyncMemo as yt, nodes as z, createScope as zt };
4189
+ export { keep as $, getScope as $t, attr as A, updateRoute as At, componentNodes as B, resolve as Bt, fillSpread as C, submitAction as Ct, reveal as D, provideValue as Dt, loading as E, consumeContext as Et, text as F, effect as Ft, place as G, updated as Gt, dynamicNodes as H, timed as Ht, writeText as I, get as It, appendText as J, insert as Jt, setItem as K, fail as Kt, prop as L, isBound as Lt, content as M, binding as Mt, portalTo as N, bindings as Nt, started as O, setGlobal as Ot, restRef as P, cells as Pt, fillList as Q, descendants as Qt, spreadProps as R, memo as Rt, fillSettled as S, spread as St, keepValue as T, track as Tt, elementAt as U, unreadMemo as Ut, dynamic as V, set as Vt, foreignNodes as W, update as Wt, clone as X, afterInsert as Xt, branchNodes as Y, title as Yt, fillBranch as Z, createScope as Zt, retag as _, removeRoot as _t, deferInBrowser as a, nameComment as an, setAttr as at, countLoads as b, handlerProp as bt, toList as c, hooks as cn, setOn as ct, branch as d, skew as dn, dispose as dt, makeId as en, keepText as et, fill as f, forget as ft, reset as g, remount as gt, rekey as h, leaveRoutes as ht, addStyle as i, loadModule as in, putText as it, attrs as j, asyncMemo as jt, wait as k, updateContext as kt, windowList as l, rpcPrefix as ln, setSpread as lt, offscreen as m, leavePage as mt, addHead as n, setOwner as nn, markBlock as nt, setVar as o, DEVTOOLS as on, setAttrText as ot, held as p, init as pt, setSlots as q, children as qt, addPortal as r, sink as rn, nodes as rt, list as s, build as sn, setContent as st, loader as t, removeScope as tn, listNodes as tt, windowStart as u, scopes as un, template as ut, after as v, action as vt, fillValue as w, guess as wt, fillAttrs as x, rpc as xt, attempt as y, handle as yt, component as z, pending as zt };
3569
4190
 
3570
- //# sourceMappingURL=client-iZ9a1Nut.js.map
4191
+ //# sourceMappingURL=client-BYHGusTe.js.map