brumate 0.4.3 → 0.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (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-DNva05jp.d.ts → client-DvsU9qxG.d.ts} +107 -23
  4. package/dist/{client-AXNULmRZ.js → client-glvRglTB.js} +1000 -370
  5. package/dist/client-glvRglTB.js.map +1 -0
  6. package/dist/{defer-D3YMPgkX.js → defer-CNYYG-A5.js} +2 -2
  7. package/dist/{defer-D3YMPgkX.js.map → defer-CNYYG-A5.js.map} +1 -1
  8. package/dist/{devtools-BiP5fDiB.js → devtools-D8EioKXs.js} +4 -4
  9. package/dist/{devtools-BiP5fDiB.js.map → devtools-D8EioKXs.js.map} +1 -1
  10. package/dist/{devtools-panel-EQhLm39H.js → devtools-panel-BKmBqkau.js} +2 -2
  11. package/dist/{devtools-panel-EQhLm39H.js.map → devtools-panel-BKmBqkau.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-BUjvEO_o.js → files-ClQJlDcB.js} +2 -2
  15. package/dist/{files-BUjvEO_o.js.map → files-ClQJlDcB.js.map} +1 -1
  16. package/dist/index.d.ts +1 -8
  17. package/dist/index.js +1 -1
  18. package/dist/{inspect-BvPTZs6k.js → inspect-B8i6R3mZ.js} +877 -132
  19. package/dist/inspect-B8i6R3mZ.js.map +1 -0
  20. package/dist/{loader-DgMk6p9M.js → loader-DB0i9MwD.js} +4 -4
  21. package/dist/{loader-DgMk6p9M.js.map → loader-DB0i9MwD.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-Bxv7DYGe.js → rpc-BHlxmeWe.js} +5 -5
  27. package/dist/rpc-BHlxmeWe.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-U_x-ctJI.js → static-loader-D0ARlMxM.js} +3 -26
  49. package/dist/static-loader-D0ARlMxM.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 +39 -5
  57. package/dist/client-AXNULmRZ.js.map +0 -1
  58. package/dist/features-CHY5Ekku.js.map +0 -1
  59. package/dist/inspect-BvPTZs6k.js.map +0 -1
  60. package/dist/navigate-CfOr-TRF.js.map +0 -1
  61. package/dist/rpc-Bxv7DYGe.js.map +0 -1
  62. package/dist/server-O_rC-RRL.js.map +0 -1
  63. package/dist/static-loader-U_x-ctJI.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;
@@ -967,9 +951,13 @@ function fail(scope, error) {
967
951
  const entry = module?.t?.[current.k];
968
952
  if (!entry) continue;
969
953
  let owner = current.p;
970
- while (owner && owner.k !== entry[0]) owner = owner.p;
954
+ let body = current;
955
+ while (owner && owner.k !== entry[0]) {
956
+ body = owner;
957
+ owner = owner.p;
958
+ }
971
959
  if (owner) {
972
- await catchInto(owner, module, entry, error);
960
+ await catchInto(owner, body, module, entry, error);
973
961
  return;
974
962
  }
975
963
  }
@@ -1001,14 +989,30 @@ function replaceTry(key) {
1001
989
  }
1002
990
  template?.remove();
1003
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
+ }
1004
1005
  /** Reports the error of a `#loading` body that failed on the server, with no `#try` around it. */
1005
1006
  function failBoundary(error) {
1006
1007
  options.onError?.(error, {});
1007
1008
  unhandled(error);
1008
1009
  }
1009
- /** Renders the `#catch` body of a `#try` with an error, in place of what the block shows. */
1010
- async function catchInto(owner, module, [, anchor, , fallback, kinds, holderKind, holderAnchor], error) {
1011
- const updates = await loadPart(module, "update");
1010
+ /**
1011
+ * Renders the `#catch` body of a `#try` with an error, in place of `body`, the body that failed.
1012
+ */
1013
+ async function catchInto(owner, body, module, [, anchor, , fallback, kinds, holderKind, holderAnchor], error) {
1014
+ const updates = module;
1015
+ if (scopes.get(body.id) !== body) return;
1012
1016
  const start = blockStart(owner, anchor);
1013
1017
  if (!start) return;
1014
1018
  const end = rangeEnd(start);
@@ -1020,6 +1024,7 @@ async function catchInto(owner, module, [, anchor, , fallback, kinds, holderKind
1020
1024
  function get(scope, slot) {
1021
1025
  if (dirty.size > 0 && !draining) settle(scope);
1022
1026
  const value = scope.s[slot];
1027
+ if (value === void 0 && exempt > 0 && !(slot in scope.s)) throw new NotReady(Promise.resolve());
1023
1028
  if (value instanceof Promise && !scope.plain?.has(slot)) {
1024
1029
  if (computing > 0) throw new NotReady(value);
1025
1030
  if (loadingValues.has(value)) {
@@ -1040,7 +1045,7 @@ function get(scope, slot) {
1040
1045
  * reads it throws into the nearest `#try` around it, and the code that does not read it runs as
1041
1046
  * usual. A memo that computes again without a throw holds its value again.
1042
1047
  */
1043
- function hold(scope, slot, key, error) {
1048
+ function hold$1(scope, slot, key, error) {
1044
1049
  loadingSlots.delete(key);
1045
1050
  loads.delete(key);
1046
1051
  guesses?.map.delete(key);
@@ -1091,7 +1096,7 @@ function send(bound, value) {
1091
1096
  /** The setters that were given each element, so an update of a spread does not call them again. */
1092
1097
  const given = /* @__PURE__ */ new WeakMap();
1093
1098
  /** Calls the setter of a binding with an element, once for each element and setter. */
1094
- function give(bound, element) {
1099
+ function give$1(bound, element) {
1095
1100
  const key = bound instanceof FunctionReference ? `${bound.scope}#${bound.ref}` : bound;
1096
1101
  const seen = given.get(element) ?? /* @__PURE__ */ new Set();
1097
1102
  if (!seen.has(key)) {
@@ -1201,7 +1206,7 @@ function isThenable(value) {
1201
1206
  function unreadMemo(scope, value) {
1202
1207
  if (isThenable(value)) {
1203
1208
  const at = resolveScope(scope);
1204
- value.then(void 0, (error) => fail(at, error));
1209
+ value.then(void 0, (error) => reportOnce(at, error));
1205
1210
  }
1206
1211
  }
1207
1212
  /**
@@ -1220,7 +1225,7 @@ function asyncMemo(scope, slot, promise) {
1220
1225
  else trigger(scope, slot);
1221
1226
  }
1222
1227
  function failed(error) {
1223
- if (loads.get(key) === load) hold(scope, slot, key, error);
1228
+ if (loads.get(key) === load) hold$1(scope, slot, key, error);
1224
1229
  }
1225
1230
  promise.then((value) => {
1226
1231
  if (!isAsyncIterable(value)) {
@@ -1331,8 +1336,8 @@ function memo(scope, slot, compute) {
1331
1336
  const key = `${scope.id}:${slot}`;
1332
1337
  if (guesses?.same(key)) return;
1333
1338
  const rendered = scope.s[slot];
1334
- if (renderedLoads.delete(key) && isThenable(rendered)) {
1335
- asyncMemo(scope, slot, Promise.resolve(rendered));
1339
+ if (renderedLoads.delete(key)) {
1340
+ if (isThenable(rendered)) asyncMemo(scope, slot, Promise.resolve(rendered));
1336
1341
  return;
1337
1342
  }
1338
1343
  let value;
@@ -1356,7 +1361,7 @@ function memo(scope, slot, compute) {
1356
1361
  memoKey = outer;
1357
1362
  }
1358
1363
  if (threw) {
1359
- hold(scope, slot, key, value);
1364
+ hold$1(scope, slot, key, value);
1360
1365
  return;
1361
1366
  }
1362
1367
  if (isThenable(value) || isAsyncIterable(value)) {
@@ -1387,7 +1392,7 @@ function trigger(scope, slot) {
1387
1392
  for (const check of waiters.keys()) check();
1388
1393
  const id = findRoot(scope).m;
1389
1394
  const children = childrenReady(scope);
1390
- if (modules.has(id) && loadedParts.has(`${id}:update`) && loadingCode.size === 0 && !children) {
1395
+ if (modules.has(id) && loadingCode.size === 0 && !children) {
1391
1396
  pass(() => queueWrite(scope, slot));
1392
1397
  return;
1393
1398
  }
@@ -1395,7 +1400,7 @@ function trigger(scope, slot) {
1395
1400
  waiting.push([
1396
1401
  scope,
1397
1402
  slot,
1398
- updateCode(scope, slot).catch((error) => fail(scope, error))
1403
+ loadModule(id).then(() => childrenReady(scope)).catch((error) => fail(scope, error))
1399
1404
  ]);
1400
1405
  return;
1401
1406
  }
@@ -1403,8 +1408,7 @@ function trigger(scope, slot) {
1403
1408
  const via = viaContext;
1404
1409
  const list = [[scope, slot]];
1405
1410
  if (running > 0) waiting = list;
1406
- const loading = loadModule(id).then(async (loaded) => {
1407
- await (loaded.g[scope.k]?.[slot] && loadPart(loaded, "update"));
1411
+ const loading = loadModule(id).then(async () => {
1408
1412
  const waits = [...loadingCode, children];
1409
1413
  for (const [, , load] of list) waits.push(load);
1410
1414
  await Promise.allSettled(waits);
@@ -1425,32 +1429,11 @@ function trigger(scope, slot) {
1425
1429
  flushEffects();
1426
1430
  });
1427
1431
  loadingUpdates.add(loading);
1428
- loading.finally(() => loadingUpdates.delete(loading));
1429
- }
1430
- /** Loads the code of a component, its update code when something reads the slot, and its children. */
1431
- async function updateCode(scope, slot) {
1432
- await loadUpdate(scope, slot);
1433
- return childrenReady(scope);
1434
- }
1435
- /** Loads the module of a component and its update code, when something reads the slot. */
1436
- function loadUpdate(scope, slot) {
1437
- return loadModule(findRoot(scope).m).then((loaded) => {
1438
- const reads = loaded.g[scope.k];
1439
- 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();
1440
1435
  });
1441
1436
  }
1442
- /**
1443
- * Loads the update code that a write of a handler can need, so its writes run before it returns.
1444
- * A handler that is not in `w` of its module writes only the slots of its own component, and
1445
- * waits for the code of that component. A handler in `w` also waits for the components above it, which a
1446
- * write of a bound prop reaches, and for the scope that its children render in.
1447
- */
1448
- async function updateReady(scope, ref) {
1449
- if (!scope) return;
1450
- const root = findRoot(scope);
1451
- const own = ref && !(await loadModule(root.m)).w?.includes(ref.split("#")[1]);
1452
- return Promise.all([loadUpdate(scope), own ? loadUpdate(root) : Promise.all([updateReady(scope.p ?? scope.o), updateReady(scope.t)])]);
1453
- }
1454
1437
  /** The writes of the pass that runs that wait for code, to run as one pass of their own. */
1455
1438
  let waiting;
1456
1439
  /** The updates that wait for their code. */
@@ -1502,7 +1485,7 @@ function pass(write) {
1502
1485
  }
1503
1486
  }
1504
1487
  if (running === 0) {
1505
- if (!held) flushEffects();
1488
+ if (!held && loadingUpdates.size === 0) flushEffects();
1506
1489
  if (DEV) devtools()?.updated?.(updateCount, updateStart, performance.now());
1507
1490
  }
1508
1491
  return result;
@@ -1534,9 +1517,8 @@ globalThis[Symbol.for("brumate.flush")] = flush;
1534
1517
  function queueWrite(scope, slot) {
1535
1518
  const id = findRoot(scope).m;
1536
1519
  const module = modules.get(id);
1537
- const updates = loadedParts.get(`${id}:update`);
1538
- if (!module || !updates) return;
1539
- 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);
1540
1522
  }
1541
1523
  /** Queues an update of a scope, once. */
1542
1524
  function queue(fn, name, target) {
@@ -1548,7 +1530,7 @@ function queue(fn, name, target) {
1548
1530
  if (!failed && scopes.get(target.id) === target) try {
1549
1531
  if (stuck) {
1550
1532
  failed = true;
1551
- throw new Error(DEV ? "The updates of a write did not settle after 10000 rounds. An update writes a value that it reads, such as through ref=$bind." : "Update loop");
1533
+ throw new Error(DEV ? `The ${name[0] === "e" ? "effect" : "update"} ${name} of ${findRoot(target).m} did not settle: it writes a value that it reads, and runs again without end. Wrap the read or the write in $untrack, or write only when the value changes [BRM187]` : `Update loop ${key} [BRM187]`);
1552
1534
  }
1553
1535
  const before = origin;
1554
1536
  origin = from;
@@ -1558,7 +1540,7 @@ function queue(fn, name, target) {
1558
1540
  origin = before;
1559
1541
  }
1560
1542
  } catch (error) {
1561
- fail(target, error);
1543
+ if (!(error instanceof NotReady)) fail(target, error);
1562
1544
  }
1563
1545
  }
1564
1546
  const depth = getDepth(target);
@@ -1638,10 +1620,12 @@ function drain() {
1638
1620
  function flushEffects() {
1639
1621
  if (flushing) return;
1640
1622
  flushing = true;
1623
+ let rounds = 0;
1641
1624
  try {
1642
1625
  while (pendingEffects.size > 0) {
1643
1626
  const run = [...pendingEffects.values()];
1644
1627
  pendingEffects.clear();
1628
+ if (stuck = ++rounds > 1e3) rounds = 0;
1645
1629
  pass(() => {
1646
1630
  for (const runEffect of run) runEffect();
1647
1631
  });
@@ -1672,7 +1656,7 @@ function effect(scope, name, callback, client) {
1672
1656
  if (error instanceof NotReady) {
1673
1657
  const token = {};
1674
1658
  skipped.set(key, token);
1675
- scope.cleanups.set(name, noop);
1659
+ scope.cleanups.set(name, noop$1);
1676
1660
  function again() {
1677
1661
  if (skipped.get(key) === token && scopes.get(scope.id) === scope) effect(scope, name, callback);
1678
1662
  }
@@ -1689,7 +1673,7 @@ function effect(scope, name, callback, client) {
1689
1673
  origin = outer;
1690
1674
  if (!client) runningEffects--;
1691
1675
  }
1692
- let stored = typeof cleanup === "function" ? cleanup : noop;
1676
+ let stored = typeof cleanup === "function" ? cleanup : noop$1;
1693
1677
  if (DEV) {
1694
1678
  devtools()?.effect?.(scope, name, "run", performance.now() - start);
1695
1679
  const own = stored;
@@ -1700,7 +1684,7 @@ function effect(scope, name, callback, client) {
1700
1684
  }
1701
1685
  scope.cleanups.set(name, stored);
1702
1686
  }
1703
- function noop() {}
1687
+ function noop$1() {}
1704
1688
  //#endregion
1705
1689
  //#region src/runtime/client/context.ts
1706
1690
  /** The scope that provides a context to `scope`: itself or the nearest one above it. */
@@ -1736,7 +1720,7 @@ function consumeContext(context, scope, slot) {
1736
1720
  }
1737
1721
  const provider = findProvider(target, context.key);
1738
1722
  if (provider) return provider.v[context.key];
1739
- 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());
1740
1724
  return globals.has(context.key) ? globals.get(context.key) : context.defaultValue;
1741
1725
  }
1742
1726
  /** The values of the contexts that the runtime provides to the whole page, by key. */
@@ -1951,8 +1935,7 @@ function handle(element, entry, event, typed) {
1951
1935
  const loaded = Promise.all([
1952
1936
  resolve$1(ref),
1953
1937
  children,
1954
- code,
1955
- updateReady(scope, ref)
1938
+ code
1956
1939
  ]).then(([handler]) => handler);
1957
1940
  const started = lastHandler.then(() => loaded).then((handler) => {
1958
1941
  if (!DEV) return { value: pass(() => handler(scope, ...args)) };
@@ -1983,15 +1966,16 @@ function action(name, id, method, result) {
1983
1966
  * call loads, so the core holds only this.
1984
1967
  */
1985
1968
  function submitAction(form, submitter) {
1986
- import("./rpc-Bxv7DYGe.js").then((module) => module.sendAction(form, submitter));
1969
+ import("./rpc-BHlxmeWe.js").then((module) => module.sendAction(form, submitter));
1987
1970
  }
1988
1971
  /** Calls a server function. */
1989
1972
  async function rpc(id, args) {
1990
1973
  const signal = memoSignal();
1991
- return track(import("./rpc-Bxv7DYGe.js").then((module) => module.call(rpcPrefix, id, args, signal)));
1974
+ return track(import("./rpc-BHlxmeWe.js").then((module) => module.call(rpcPrefix, id, args, signal)));
1992
1975
  }
1993
1976
  /** A function prop rendered on the client calls the parent's exported handler. */
1994
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`);
1995
1979
  if (typeof value !== "function" || isTemplate(ref)) return value;
1996
1980
  const instance = resolveScope(scope);
1997
1981
  function handler(...args) {
@@ -2027,12 +2011,12 @@ function readRecord([script, code]) {
2027
2011
  const root = script.getAttribute("b-root") ?? "0";
2028
2012
  if (!refs.has(root)) refs.set(root, []);
2029
2013
  const decoded = code(refs.get(root), stateValues);
2030
- const catches = script.getAttribute("b-catch");
2014
+ const catches = HAS_TRIES ? script.getAttribute("b-catch") : null;
2031
2015
  if (catches !== null) {
2032
2016
  replaceTry(catches);
2033
2017
  return;
2034
2018
  }
2035
- if (script.getAttribute("b-fail") !== null) {
2019
+ if ((HAS_LATE_MARKUP ? script.getAttribute("b-fail") : null) !== null) {
2036
2020
  failBoundary(decoded);
2037
2021
  return;
2038
2022
  }
@@ -2127,7 +2111,6 @@ function addScopes(state, root) {
2127
2111
  if (record.f !== void 0) scope.f = scopes.get(record.f);
2128
2112
  if (record.l !== void 0) scope.l = scopes.get(record.l);
2129
2113
  }
2130
- for (const scope of added) if (scope.m) options.loadBundle?.(scope.m)?.catch(() => {});
2131
2114
  for (const scope of added) if (scope.m) loadComponent(scope.m);
2132
2115
  const seen = /* @__PURE__ */ new Set();
2133
2116
  for (const scope of added) {
@@ -2158,7 +2141,7 @@ function addScopes(state, root) {
2158
2141
  }
2159
2142
  for (const scope of added) for (const [anchor, bound] of Object.entries(state[scope.id].r ?? {})) {
2160
2143
  const element = findElement(scope.id, +anchor);
2161
- if (element) give(bound, element);
2144
+ if (element) give$1(bound, element);
2162
2145
  }
2163
2146
  }
2164
2147
  hooks.added?.(added);
@@ -2200,12 +2183,8 @@ function removeRoot(root) {
2200
2183
  function forget(ids) {
2201
2184
  for (const id of ids) {
2202
2185
  modules.delete(id);
2203
- loading.delete(id);
2186
+ loading$1.delete(id);
2204
2187
  pageComponents.delete(id);
2205
- for (const key of parts.keys()) if (key.startsWith(`${id}:`)) {
2206
- parts.delete(key);
2207
- loadedParts.delete(key);
2208
- }
2209
2188
  }
2210
2189
  }
2211
2190
  /** The values of the signals of components whose markup changed, for when the page renders again. */
@@ -2322,7 +2301,7 @@ function init(value) {
2322
2301
  if (HAS_LATE_MARKUP) observeMarkers();
2323
2302
  else if (document.readyState === "loading") document.addEventListener("DOMContentLoaded", () => indexMarkers(document.documentElement), { once: true });
2324
2303
  indexMarkers(document.documentElement);
2325
- readFields();
2304
+ if (HAS_FIELDS) readFields();
2326
2305
  watchTitles(document);
2327
2306
  if (DEV) devtools()?.attach?.({
2328
2307
  scopes,
@@ -2331,237 +2310,6 @@ function init(value) {
2331
2310
  });
2332
2311
  }
2333
2312
  //#endregion
2334
- //#region src/runtime/client/branches.ts
2335
- /** Shows the branch at `index` of `#if` or `#switch`, or nothing for -1. */
2336
- function branch(scope, anchor, index, renders, kinds, holderKind, holderAnchor) {
2337
- const start = blockStart(scope, anchor);
2338
- if (!start) return;
2339
- if (Number(start.data.split(":")[2]) === index) return;
2340
- const end = rangeEnd(start);
2341
- removeBlock(scope, kinds, start, end);
2342
- start.data = `b${scope.id}:${anchor}:${index}`;
2343
- const render = inPlace(scope, renders[index], holderKind, holderAnchor);
2344
- if (render) insertHTML(end, render(scope));
2345
- }
2346
- /** Renders the body of `#key` again when its value changes. */
2347
- function rekey(scope, anchor, value, render, kinds, holderKind, holderAnchor) {
2348
- scope.keys ??= /* @__PURE__ */ new Map();
2349
- if (scope.keys.has(anchor) && Object.is(scope.keys.get(anchor), value)) return;
2350
- scope.keys.set(anchor, value);
2351
- const start = blockStart(scope, anchor);
2352
- if (!start) return;
2353
- const end = rangeEnd(start);
2354
- removeBlock(scope, kinds, start, end);
2355
- insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
2356
- }
2357
- /**
2358
- * `rekey` for the block around a dynamic tag. The first update keeps the element that the server
2359
- * rendered, when it has the tag already, such as an update of a scope that streams in after an
2360
- * event.
2361
- */
2362
- function retag(scope, anchor, value, render, kinds, holderKind, holderAnchor) {
2363
- scope.keys ??= /* @__PURE__ */ new Map();
2364
- if (!scope.keys.has(anchor) && typeof value === "string") {
2365
- let node = blockStart(scope, anchor)?.nextSibling;
2366
- while (node && node.nodeType !== 1 && node.nodeType !== 8) node = node.nextSibling;
2367
- if (node?.nodeType === 1 && node.localName === value.toLowerCase()) {
2368
- scope.keys.set(anchor, value);
2369
- return;
2370
- }
2371
- }
2372
- if (!scope.keys.has(anchor) && typeof value === "function") {
2373
- for (const block of scopes.values()) if (block.p === scope && kinds.includes(block.k)) {
2374
- for (const id of Object.values(block.c ?? {})) if (scopes.get(id)?.m === value.brumateId) {
2375
- scope.keys.set(anchor, value);
2376
- return;
2377
- }
2378
- }
2379
- }
2380
- rekey(scope, anchor, value, render, kinds, holderKind, holderAnchor);
2381
- }
2382
- /**
2383
- * Renders the body of a `#try` block again, for its `reset` function. If the
2384
- * body throws, the fallback renders again with the error.
2385
- */
2386
- async function reset(scope, anchor, id, body, fallback, kinds, holderKind, holderAnchor) {
2387
- const updates = await loadPart(await loadModule(id), "update");
2388
- const start = blockStart(scope, anchor);
2389
- if (!start) return;
2390
- const end = rangeEnd(start);
2391
- removeBlock(scope, kinds, start, end);
2392
- let html;
2393
- try {
2394
- html = inPlace(scope, updates[body], holderKind, holderAnchor)(scope);
2395
- } catch (error) {
2396
- disposeKinds(scope, kinds);
2397
- afterInsert.length = 0;
2398
- html = inPlace(scope, updates[fallback], holderKind, holderAnchor)(scope, error);
2399
- }
2400
- insertHTML(end, html);
2401
- }
2402
- /**
2403
- * Renders the body of a `#client` block once, in place of its fallback.
2404
- * `kinds` are the scope IDs inside the fallback, whose instances go.
2405
- */
2406
- function fill(scope, anchor, render, kinds = [], holderKind, holderAnchor) {
2407
- const start = blockStart(scope, anchor);
2408
- if (!start || start.data.split(":").length > 2) return;
2409
- start.data += ":1";
2410
- const end = rangeEnd(start);
2411
- removeBlock(scope, kinds, start, end);
2412
- insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
2413
- }
2414
- /**
2415
- * Shows or hides the body of an `#offscreen` block. A body that the page
2416
- * does not have yet renders the first time it shows. `kind` is the body's
2417
- * scope ID in the compiled component.
2418
- */
2419
- function offscreen(scope, anchor, value, render, kind, holderKind, holderAnchor) {
2420
- const start = blockStart(scope, anchor);
2421
- if (!start) return;
2422
- const visible = Boolean(value);
2423
- const state = start.data.split(":")[2];
2424
- if (visible ? state === "1" : state !== "1") return;
2425
- start.data = `b${scope.id}:${anchor}:${visible ? 1 : 0}`;
2426
- const end = rangeEnd(start);
2427
- if (state === "-1") {
2428
- insertHTML(end, inPlace(scope, render, holderKind, holderAnchor)(scope));
2429
- return;
2430
- }
2431
- let body;
2432
- for (const child of scope.children ?? []) if (child.k === kind) body = child;
2433
- if (body) {
2434
- const holder = hiding ?? setHiding(createHiding());
2435
- if (visible) holder.show(body);
2436
- else holder.hide(body, start, end);
2437
- }
2438
- }
2439
- /** True for a scope that is `ancestor` or inside it, also through the owner of a component. */
2440
- function within(scope, ancestor) {
2441
- for (let current = scope; current; current = current.p ?? current.o) if (current === ancestor) return true;
2442
- return false;
2443
- }
2444
- /** True for a scope in a hidden `#offscreen` body. */
2445
- function hidden(scope) {
2446
- for (let current = scope; current; current = current.p ?? current.o) if (current.h) return true;
2447
- return false;
2448
- }
2449
- /** The nodes between two markers. */
2450
- function between([start, end]) {
2451
- const result = [];
2452
- for (let node = start.nextSibling; node && node !== end; node = node.nextSibling) result.push(node);
2453
- return result;
2454
- }
2455
- /** The inline style of an element, which an element that is not HTML or SVG may not have. */
2456
- function display(element) {
2457
- return element.style;
2458
- }
2459
- function createHiding() {
2460
- const bodies = /* @__PURE__ */ new Set();
2461
- const nodes = /* @__PURE__ */ new WeakMap();
2462
- function hideNode(node) {
2463
- const saved = nodes.get(node);
2464
- if (saved) {
2465
- saved.n++;
2466
- return;
2467
- }
2468
- if (node.nodeType === 3) {
2469
- nodes.set(node, {
2470
- n: 1,
2471
- v: node.data
2472
- });
2473
- node.data = "";
2474
- return;
2475
- }
2476
- const style = node.nodeType === 1 ? display(node) : void 0;
2477
- if (style) {
2478
- nodes.set(node, {
2479
- n: 1,
2480
- v: style.getPropertyValue("display"),
2481
- p: style.getPropertyPriority("display"),
2482
- a: node.hasAttribute("style")
2483
- });
2484
- style.setProperty("display", "none", "important");
2485
- }
2486
- }
2487
- function showNode(node) {
2488
- const saved = nodes.get(node);
2489
- if (!saved || --saved.n > 0) return;
2490
- nodes.delete(node);
2491
- if (node.nodeType === 3) {
2492
- node.data = saved.v;
2493
- return;
2494
- }
2495
- const element = node;
2496
- const style = display(element);
2497
- if (saved.v) style.setProperty("display", saved.v, saved.p);
2498
- else style.removeProperty("display");
2499
- if (!saved.a && element.getAttribute("style") === "") element.removeAttribute("style");
2500
- }
2501
- return {
2502
- bodies,
2503
- nodes,
2504
- hidden,
2505
- hide(body, start, end) {
2506
- const record = {
2507
- scope: body,
2508
- ranges: [[start, end]]
2509
- };
2510
- body.h = record;
2511
- bodies.add(record);
2512
- const inside = [];
2513
- for (const scope of scopes.values()) if (within(scope, body)) inside.push(scope);
2514
- for (const scope of inside) {
2515
- const portal = comments.get(`P${scope.id}`);
2516
- if (portal?.isConnected) record.ranges.push([portal, rangeEnd(portal)]);
2517
- }
2518
- for (const range of record.ranges) for (const node of between(range)) hideNode(node);
2519
- for (const scope of inside) {
2520
- for (const [name, cleanup] of scope.cleanups ?? []) {
2521
- cleanup();
2522
- (scope.w ??= /* @__PURE__ */ new Set()).add(name);
2523
- }
2524
- scope.cleanups?.clear();
2525
- }
2526
- },
2527
- show(body) {
2528
- const record = body.h;
2529
- if (!record) return;
2530
- body.h = void 0;
2531
- bodies.delete(record);
2532
- for (const range of record.ranges) if (range[0].isConnected) for (const node of between(range)) showNode(node);
2533
- for (const scope of scopes.values()) if (scope.w && within(scope, body) && !hidden(scope)) {
2534
- const ref = `${findRoot(scope).m}#`;
2535
- for (const name of scope.w) call(ref + name, scope, []);
2536
- scope.w = void 0;
2537
- }
2538
- },
2539
- paused(scope, name) {
2540
- if (bodies.size === 0 || !hidden(scope)) return false;
2541
- (scope.w ??= /* @__PURE__ */ new Set()).add(name);
2542
- return true;
2543
- },
2544
- added(added) {
2545
- for (const node of added) for (const record of bodies) {
2546
- for (const [start, end] of record.ranges) if (node.parentNode === start.parentNode && start.compareDocumentPosition(node) & 4 && node.compareDocumentPosition(end) & 4) hideNode(node);
2547
- const data = node.nodeType === 8 ? node.data : "";
2548
- const scope = /^P-?[\d.]+$/.test(data) ? scopes.get(parseId(data.slice(1))) : void 0;
2549
- if (scope && within(scope, record.scope)) record.ranges.push([node, rangeEnd(node)]);
2550
- }
2551
- },
2552
- styled(element) {
2553
- const saved = nodes.get(element);
2554
- const style = display(element);
2555
- if (saved && style) {
2556
- saved.v = style.getPropertyValue("display");
2557
- saved.p = style.getPropertyPriority("display");
2558
- saved.a = element.hasAttribute("style");
2559
- style.setProperty("display", "none", "important");
2560
- }
2561
- }
2562
- };
2563
- }
2564
- //#endregion
2565
2313
  //#region src/runtime/client/templates.ts
2566
2314
  /** A template of the markup of a render, which `clone` parses once. */
2567
2315
  function template(html, count, foreign) {
@@ -2718,7 +2466,7 @@ function keepBlock(place, scope, data, anchor) {
2718
2466
  return found;
2719
2467
  }
2720
2468
  /** Puts what renders gave into the range that a marker of cloned markup opens. */
2721
- function fillRange(place, html, inserted) {
2469
+ function fillRange$1(place, html, inserted) {
2722
2470
  if (html) {
2723
2471
  place.after(parseHTML(html, place));
2724
2472
  markCloned();
@@ -2737,7 +2485,7 @@ function fillBranch(place, scope, anchor, index, renders) {
2737
2485
  const render = renders[index];
2738
2486
  if (found && render) {
2739
2487
  const out = render(found);
2740
- 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);
2741
2489
  }
2742
2490
  }
2743
2491
  /** Fills a nested `#for` of cloned markup with its items, before the clone is in the page. */
@@ -2751,7 +2499,7 @@ function fillList(place, scope, anchor, items, render) {
2751
2499
  if (typeof out === "string") html += out;
2752
2500
  else (parts ??= document.createDocumentFragment()).append(out);
2753
2501
  }
2754
- fillRange(place, html, parts);
2502
+ fillRange$1(place, html, parts);
2755
2503
  }
2756
2504
  /** Writes an attribute of an element of cloned markup, as `attribute` writes it in HTML. */
2757
2505
  function setAttr(element, name, value) {
@@ -2823,35 +2571,6 @@ function setOn(element, on, own) {
2823
2571
  options?.listen(element);
2824
2572
  }
2825
2573
  }
2826
- /**
2827
- * The scope that `fillSettled` reported each rejection to, as two renders or two writes in one
2828
- * scope can read the same memo.
2829
- */
2830
- const reportedRejections = /* @__PURE__ */ new WeakMap();
2831
- /**
2832
- * Writes cloned markup that reads memos which never change, once the ones that are promises
2833
- * settle, as no update writes their values. A rejection goes to the nearest `#try` around the
2834
- * scope, or `onError`.
2835
- */
2836
- function fillSettled(scope, values, write) {
2837
- let loading = false;
2838
- for (const value of values) loading ||= isThenable(value);
2839
- if (!loading) {
2840
- write(...values);
2841
- return;
2842
- }
2843
- const at = resolveScope(scope);
2844
- Promise.all(values).then((settled) => {
2845
- if (scopes.get(at.id) === at) write(...settled);
2846
- }, (error) => {
2847
- if (scopes.get(at.id) !== at) return;
2848
- if (typeof error === "object" && error !== null) {
2849
- if (reportedRejections.get(error) === at) return;
2850
- reportedRejections.set(error, at);
2851
- }
2852
- fail(at, error);
2853
- });
2854
- }
2855
2574
  /** Writes the content of an element of cloned markup, as `insert` writes it in HTML. */
2856
2575
  function setContent(element, value, at) {
2857
2576
  if (typeof value === "string" || typeof value === "number") {
@@ -2949,18 +2668,15 @@ function setSlots(id, values) {
2949
2668
  const value = values[slot];
2950
2669
  if (value instanceof Promise && scopes.get(id).props?.includes(value) && values.indexOf(value) === slot) {
2951
2670
  (scopes.get(id).plain ??= /* @__PURE__ */ new Set()).add(slot);
2952
- value.catch(noop);
2671
+ value.catch(noop$1);
2953
2672
  } else if (isThenable(value)) {
2954
2673
  const key = `${id}:${slot}`;
2955
2674
  renderedLoads.add(key);
2956
2675
  loadingValues.add(value);
2957
2676
  Promise.resolve(value).then((result) => {
2958
2677
  const scope = scopes.get(id);
2959
- if (scope?.s[slot] === value && !loads.has(key)) {
2960
- renderedLoads.delete(key);
2961
- set(scope, slot, result);
2962
- }
2963
- }, noop);
2678
+ if (scope?.s[slot] === value && !loads.has(key)) set(scope, slot, result);
2679
+ }, noop$1);
2964
2680
  }
2965
2681
  }
2966
2682
  scopes.get(id).props = void 0;
@@ -3164,7 +2880,7 @@ function withVariables(element, style) {
3164
2880
  return style ? `${style};${variables.join(";")}` : variables.join(";");
3165
2881
  }
3166
2882
  function attr(scope, anchor, name, value) {
3167
- if (scope.c?.[anchor] !== void 0) {
2883
+ if (HAS_DYNAMIC && scope.c?.[anchor] !== void 0) {
3168
2884
  prop(scope, anchor, name, value);
3169
2885
  return;
3170
2886
  }
@@ -3184,7 +2900,7 @@ function forwardRef(element, values) {
3184
2900
  if (isSlotReference(target)) {
3185
2901
  const owner = scopes.get(target.scope);
3186
2902
  if (owner) set(owner, target.slot, element);
3187
- } else give(target, element);
2903
+ } else give$1(target, element);
3188
2904
  }
3189
2905
  }
3190
2906
  /** The element of a spread in markup that the browser renders goes to the `ref` of its attributes. */
@@ -3232,6 +2948,905 @@ function updateSpreadEntries(element, values) {
3232
2948
  options.listen(element);
3233
2949
  }
3234
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(() => 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
3235
3850
  //#region src/runtime/client/lists.ts
3236
3851
  const ITEM_MARKER = /^i(-?[\d.]+)$/;
3237
3852
  /** The items of a `#for` list: an array as it is, since `list` only reads it, or any iterable as an array. */
@@ -3239,7 +3854,8 @@ function toList(value) {
3239
3854
  return Array.isArray(value) ? value : Array.from(value);
3240
3855
  }
3241
3856
  /** Updates the items of `#for` or `#repeat`, keeping the elements of items whose keys stay. */
3242
- 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;
3243
3859
  const start = blockStart(scope, anchor);
3244
3860
  if (!start) return;
3245
3861
  const render = inPlace(scope, given, holderKind, holderAnchor);
@@ -3297,11 +3913,19 @@ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackK
3297
3913
  }
3298
3914
  if (count === 0 && !(park && park.total > 0)) {
3299
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
+ }
3300
3923
  for (const [id, item] of previous) leave(id, item);
3301
3924
  clear(start, end);
3302
3925
  if (fallback) insertHTML(end, fallback(scope));
3303
3926
  return;
3304
3927
  }
3928
+ if (HAS_ROOT_WAIT) release(start);
3305
3929
  disposeKinds(scope, fallbackKinds);
3306
3930
  if (others) for (const node of others) node.parentNode?.removeChild(node);
3307
3931
  const parent = end.parentNode;
@@ -3309,6 +3933,7 @@ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackK
3309
3933
  const kept = [];
3310
3934
  for (let index = 0; index < count; index++) {
3311
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");
3312
3937
  const item = previous.get(id);
3313
3938
  if (item && !item.kept) {
3314
3939
  item.kept = true;
@@ -3344,7 +3969,11 @@ function list(scope, anchor, items, key, given, assign, givenFallback, fallbackK
3344
3969
  continue;
3345
3970
  }
3346
3971
  if (!item) {
3347
- 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);
3348
3977
  if (typeof out === "string") added += out;
3349
3978
  else (addedNodes ??= []).push(out);
3350
3979
  continue;
@@ -3552,10 +4181,11 @@ const loader = {
3552
4181
  handle,
3553
4182
  dispose,
3554
4183
  submitAction,
3555
- setGlobal,
3556
- updateRoute
4184
+ setGlobal: HAS_ROUTES ? setGlobal : noop,
4185
+ updateRoute: HAS_ROUTES ? updateRoute : noop
3557
4186
  };
4187
+ function noop() {}
3558
4188
  //#endregion
3559
- 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 };
3560
4190
 
3561
- //# sourceMappingURL=client-AXNULmRZ.js.map
4191
+ //# sourceMappingURL=client-glvRglTB.js.map