brumate 0.5.2 → 0.6.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 (73) hide show
  1. package/dist/{boot-Difa0qdg.d.ts → boot-DkbcqdUz.d.ts} +2 -2
  2. package/dist/cli.js +2 -2
  3. package/dist/{client-De-7aGlO.js → client-C3vRNuLi.js} +353 -103
  4. package/dist/client-C3vRNuLi.js.map +1 -0
  5. package/dist/{client-DvsU9qxG.d.ts → client-CqGDbWd_.d.ts} +45 -8
  6. package/dist/{defer-DlFYiAuK.js → defer-M18UKyfG.js} +2 -2
  7. package/dist/{defer-DlFYiAuK.js.map → defer-M18UKyfG.js.map} +1 -1
  8. package/dist/{devtools-Di_dI9tS.js → devtools-YnvrZ6D8.js} +4 -4
  9. package/dist/{devtools-Di_dI9tS.js.map → devtools-YnvrZ6D8.js.map} +1 -1
  10. package/dist/{devtools-panel-BvIKX1LY.js → devtools-panel-DRcKclEG.js} +2 -2
  11. package/dist/{devtools-panel-BvIKX1LY.js.map → devtools-panel-DRcKclEG.js.map} +1 -1
  12. package/dist/{features-D5kLyihb.js → features-CbgII-o7.js} +4 -2
  13. package/dist/features-CbgII-o7.js.map +1 -0
  14. package/dist/{files-s4wmjcZV.js → files-HzPDUyTY.js} +2 -2
  15. package/dist/{files-s4wmjcZV.js.map → files-HzPDUyTY.js.map} +1 -1
  16. package/dist/index.d.ts +8 -4
  17. package/dist/index.js +2 -7
  18. package/dist/index.js.map +1 -1
  19. package/dist/{inspect-BLPt-dZZ.js → inspect-Q5W0A66e.js} +476 -122
  20. package/dist/inspect-Q5W0A66e.js.map +1 -0
  21. package/dist/{loader-krRrJuIv.js → loader-C-S3yzep.js} +13 -5
  22. package/dist/loader-C-S3yzep.js.map +1 -0
  23. package/dist/{navigate-BcV1qkkx.js → navigate-r23FFR6e.js} +5 -2
  24. package/dist/{navigate-BcV1qkkx.js.map → navigate-r23FFR6e.js.map} +1 -1
  25. package/dist/routes-D21FQyGF.js +51 -0
  26. package/dist/routes-D21FQyGF.js.map +1 -0
  27. package/dist/{rpc-BYYAj1vV.js → rpc-C_znDZ_w.js} +3 -3
  28. package/dist/{rpc-BYYAj1vV.js.map → rpc-C_znDZ_w.js.map} +1 -1
  29. package/dist/runtime/bundles.d.ts +1 -1
  30. package/dist/runtime/client.d.ts +2 -2
  31. package/dist/runtime/client.js +3 -3
  32. package/dist/runtime/devtools.d.ts +1 -1
  33. package/dist/runtime/devtools.js +1 -1
  34. package/dist/runtime/hot.d.ts +1 -1
  35. package/dist/runtime/loader.d.ts +2 -2
  36. package/dist/runtime/loader.js +2 -2
  37. package/dist/runtime/routes.js +1 -51
  38. package/dist/runtime/server.d.ts +2 -2
  39. package/dist/runtime/server.js +3 -3
  40. package/dist/runtime/signals.d.ts +2 -140
  41. package/dist/runtime/signals.js +4 -1
  42. package/dist/runtime/signals.js.map +1 -1
  43. package/dist/runtime/static-loader.d.ts +2 -2
  44. package/dist/runtime/static-loader.js +1 -1
  45. package/dist/runtime/testing.d.ts +24 -4
  46. package/dist/runtime/testing.js +66 -2
  47. package/dist/runtime/testing.js.map +1 -1
  48. package/dist/{produce-Cq6KKi7b.js → search-params-CM1RWR2P.js} +25 -3
  49. package/dist/search-params-CM1RWR2P.js.map +1 -0
  50. package/dist/{server-Doy5HR7r.js → server-BcT9icQ4.js} +107 -40
  51. package/dist/server-BcT9icQ4.js.map +1 -0
  52. package/dist/{server-CAwIqrXl.d.ts → server-dP_ucRiJ.d.ts} +42 -3
  53. package/dist/signals-BwD4u22K.d.ts +165 -0
  54. package/dist/{static-loader-DoHWsf9t.js → static-loader-Bt2WDkY1.js} +3 -3
  55. package/dist/{static-loader-DoHWsf9t.js.map → static-loader-Bt2WDkY1.js.map} +1 -1
  56. package/dist/{static-loader-9Nc1GvF0.d.ts → static-loader-DysAET-w.d.ts} +2 -2
  57. package/dist/{stream-BdhzvPQO.js → stream-DRjx0keF.js} +2 -2
  58. package/dist/{stream-BdhzvPQO.js.map → stream-DRjx0keF.js.map} +1 -1
  59. package/dist/vite.d.ts +1 -1
  60. package/dist/vite.js +18 -13
  61. package/dist/vite.js.map +1 -1
  62. package/elements.d.ts +239 -37
  63. package/package.json +6 -1
  64. package/skills/brumate/references/errors.md +46 -12
  65. package/skills/brumate/references/signals.md +27 -25
  66. package/skills/brumate/references/syntax.md +1 -1
  67. package/dist/client-De-7aGlO.js.map +0 -1
  68. package/dist/features-D5kLyihb.js.map +0 -1
  69. package/dist/inspect-BLPt-dZZ.js.map +0 -1
  70. package/dist/loader-krRrJuIv.js.map +0 -1
  71. package/dist/produce-Cq6KKi7b.js.map +0 -1
  72. package/dist/runtime/routes.js.map +0 -1
  73. package/dist/server-Doy5HR7r.js.map +0 -1
@@ -1,8 +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_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";
2
+ import { _ as HAS_WINDOWS, a as HAS_CLIENT_HTML, c as HAS_LATE_MARKUP, d as HAS_ROOT_WAIT, f as HAS_ROUTES, g as HAS_TRIES, h as HAS_TITLES, i as HAS_CHILDREN, m as HAS_TEMPLATES, n as HAS_BINDINGS, o as HAS_DYNAMIC, s as HAS_FIELDS, u as HAS_LOADING } from "./features-CbgII-o7.js";
3
+ import { C as parseId, E as useSerialEntry, _ as isBinding, a as Binding, b as mergeHandlers, c as ElementReference, d as PARTS, g as isAsyncIterable, h as addEntryHandlers, l as FunctionReference, m as SlotReference, r as writeParam, s as ChildrenReference, t as readParam, u as MemoError, v as isPropWrapper, w as stateValues, y as isSlotReference } from "./search-params-CM1RWR2P.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
+ import { n as navigate } from "./routes-D21FQyGF.js";
6
7
  //#region src/runtime/client/state.ts
7
8
  let options;
8
9
  /** The URL prefix of server function calls, from the options. */
@@ -48,6 +49,12 @@ const loads = /* @__PURE__ */ new Map();
48
49
  const loadingSlots = /* @__PURE__ */ new Set();
49
50
  /** The timers of debounced and throttled memos, by `scope:slot`, with when each last computed. */
50
51
  const timers = /* @__PURE__ */ new Map();
52
+ /**
53
+ * The slots that the browser wrote since the page loaded, as `module:kind:slot`. The key has no
54
+ * instance: a write in one instance of a component marks the slot in all of them, so `refresh`
55
+ * runs more updates than it needs, never fewer.
56
+ */
57
+ const written = /* @__PURE__ */ new Set();
51
58
  /** Aborts the server function calls of a memo's compute, by memo key. */
52
59
  const memoControllers = /* @__PURE__ */ new Map();
53
60
  /**
@@ -75,13 +82,6 @@ function setHiding(value) {
75
82
  /** Children that render where they are inserted, and the scopes that they find contexts from. */
76
83
  const insertedChildren = [];
77
84
  /**
78
- * Slots that the render of a component in the browser filled with a promise,
79
- * by `scope:slot`. The first compute of their memo takes that promise
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.
82
- */
83
- const renderedLoads = /* @__PURE__ */ new Set();
84
- /**
85
85
  * The promises that the page knows are values still loading: a memo that the server streams, and
86
86
  * a memo that the browser rendered. Any other promise in a slot is a plain value.
87
87
  */
@@ -414,7 +414,11 @@ function removeBlock(scope, kinds, start, end) {
414
414
  * closes, but not the scope of the block or those around it.
415
415
  */
416
416
  function destroyRange(scope, start, end) {
417
- if (scopes.size > 0 && start.nextSibling !== end) {
417
+ destroyNodes(scope, start.nextSibling, end);
418
+ }
419
+ /** Destroys the scopes whose markup is from `first` up to `end`, or to the last sibling. */
420
+ function destroyNodes(scope, first, end) {
421
+ if (scopes.size > 0 && first !== end) {
418
422
  const above = /* @__PURE__ */ new Set();
419
423
  for (let current = scope; current; current = current.p ?? current.o) above.add(current);
420
424
  const inside = /* @__PURE__ */ new Set();
@@ -422,7 +426,7 @@ function destroyRange(scope, start, end) {
422
426
  const found = scopes.get(parseId(id));
423
427
  if (found && !above.has(found)) inside.add(found);
424
428
  }
425
- for (let node = start.nextSibling; node && node !== end; node = node.nextSibling) {
429
+ for (let node = first; node && node !== end; node = node.nextSibling) {
426
430
  const walker = document.createTreeWalker(node, NodeFilter.SHOW_ELEMENT | NodeFilter.SHOW_COMMENT);
427
431
  for (let current = walker.currentNode; current; current = walker.nextNode()) if (current.nodeType === 1) {
428
432
  const key = current.getAttribute("b-b");
@@ -577,10 +581,13 @@ let refreshing = false;
577
581
  * Updates scopes that the server rendered before values changed on the
578
582
  * client, such as the body of a `#loading` block that streams in after an
579
583
  * event. Effects do not run: they run only when a value changes. With
580
- * `memosOnly`, as for scopes that the client just rendered with its values,
581
- * only the memos run, so the ones that load start.
584
+ * `memos` off, as for a body that was held, the memos stay: they compute without the page, so the
585
+ * writes during the hold reached them. With `onlyWritten`, as for the body of a
586
+ * `#defer` block, which the server rendered for this request, only the updates that read a slot
587
+ * that the browser wrote run, because the other slots of the page can hold the values of a render
588
+ * for no request, such as a context in a prerendered page.
582
589
  */
583
- function refresh(added, memosOnly = false) {
590
+ function refresh(added, onlyWritten = false, memos = true) {
584
591
  const byModule = /* @__PURE__ */ new Map();
585
592
  for (const scope of added) {
586
593
  const id = findRoot(scope).m;
@@ -591,7 +598,7 @@ function refresh(added, memosOnly = false) {
591
598
  }
592
599
  for (const [id, list] of byModule) loadModule(id).then(async (module) => {
593
600
  const byKind = /* @__PURE__ */ new Map();
594
- for (const scope of list) if (!byKind.has(scope.k)) byKind.set(scope.k, refreshNames(module, scope.k, memosOnly));
601
+ for (const scope of list) if (!byKind.has(scope.k)) byKind.set(scope.k, refreshNames(module, id, scope.k, onlyWritten, memos));
595
602
  let any = false;
596
603
  for (const names of byKind.values()) any ||= names.length > 0;
597
604
  if (!any) return;
@@ -608,13 +615,17 @@ function refresh(added, memosOnly = false) {
608
615
  });
609
616
  }
610
617
  /** The names of the updates of a kind of scope that `refresh` runs, memos first. */
611
- function refreshNames(module, kind, memosOnly) {
618
+ function refreshNames(module, id, kind, onlyWritten, withMemos) {
612
619
  const memos = /* @__PURE__ */ new Set();
613
620
  const others = /* @__PURE__ */ new Set();
614
- for (const slots of Object.values(module.g)) for (const entries of Object.values(slots)) for (const [entryKind, name] of entries) {
615
- if (entryKind !== kind || name[0] === "e") continue;
616
- if (name[0] === "m") memos.add(name);
617
- else if (!memosOnly) others.add(name);
621
+ for (const [source, slots] of Object.entries(module.g)) for (const [slot, entries] of Object.entries(slots)) {
622
+ if (onlyWritten && !written.has(`${id}:${source}:${slot}`)) continue;
623
+ for (const [entryKind, name] of entries) {
624
+ if (entryKind !== kind || name[0] === "e") continue;
625
+ if (name[0] === "m") {
626
+ if (withMemos) memos.add(name);
627
+ } else others.add(name);
628
+ }
618
629
  }
619
630
  return [...memos, ...others];
620
631
  }
@@ -628,7 +639,7 @@ function insertHTML(before, html) {
628
639
  if (typeof html === "string") fragments = [parseHTML(html, "parent" in before ? before.parent : before)];
629
640
  else fragments = Array.isArray(html) ? html : [html];
630
641
  if (HAS_LATE_MARKUP && markerObserver) indexAdded(markerObserver.takeRecords());
631
- const client = rendered.splice(0);
642
+ rendered.length = 0;
632
643
  const fromServer = !cloned && SERVER_SCOPES.test(html);
633
644
  const ids = fromServer ? /* @__PURE__ */ new Set() : void 0;
634
645
  const markup = clonedMarkup;
@@ -670,11 +681,14 @@ function insertHTML(before, html) {
670
681
  afterInsert.length = 0;
671
682
  }
672
683
  if (server.length > 0) refresh(server);
673
- const live = [];
674
- for (const scope of client) if (scopes.has(scope.id)) live.push(scope);
675
- if (live.length > 0) refresh(live, true);
676
684
  }
677
- /** True when a clone holds markup that it rendered as HTML, whose markers its insert indexes. */
685
+ /**
686
+ * True when a clone holds markup that it rendered as HTML, or markers and `<template>` elements
687
+ * of its own (`clone` of an indexed template), whose markers its insert indexes. The flag is
688
+ * global and the next insert takes it, so an insert that runs between such a clone and its own
689
+ * insert would take it instead and the clone would not be indexed. No render does that today:
690
+ * a render makes its clones and returns them, and the insert comes after all of them.
691
+ */
678
692
  let clonedMarkup = false;
679
693
  /** Notes that a clone holds markup that it rendered as HTML. */
680
694
  function markCloned() {
@@ -730,6 +744,12 @@ function holdPlace(out) {
730
744
  }
731
745
  //#endregion
732
746
  //#region src/runtime/client/references.ts
747
+ /**
748
+ * The handlers that the core makes from references, with their references,
749
+ * so a spread in markup that the browser renders passes them on in `b-on`,
750
+ * as a spread on the server does.
751
+ */
752
+ const handlerReferences = /* @__PURE__ */ new WeakMap();
733
753
  /** Waits forever once the page loads again, so no error shows before it goes. */
734
754
  let reloading;
735
755
  async function resolve$1(ref) {
@@ -768,18 +788,45 @@ let inPass = (run) => run();
768
788
  function setPass(pass) {
769
789
  inPass = pass;
770
790
  }
771
- let waiting$1 = 0;
791
+ let waiting$2 = 0;
772
792
  /**
773
793
  * Calls a function of another component at once, as a pass, when its code has loaded and no call
774
794
  * waits before it, so the caller reads what the function wrote. Returns false when it did not
775
795
  * call, and `call` is the way then.
776
796
  */
777
797
  function callNow(ref, scope, args) {
778
- const fn = waiting$1 === 0 && !codeReady() ? loadedFunction(ref) : void 0;
798
+ const fn = waiting$2 === 0 && !codeReady() ? loadedFunction(ref) : void 0;
779
799
  if (!fn) return false;
780
- inPass(() => fn(scope, ...args));
800
+ track$1(inPass(() => fn(scope, ...args)));
781
801
  return true;
782
802
  }
803
+ const unsettled = /* @__PURE__ */ new Set();
804
+ /** Holds the result of a setter, when it is a promise, until it settles. */
805
+ function track$1(result) {
806
+ if (HAS_BINDINGS && result && typeof result.then === "function") {
807
+ let open;
808
+ const gate = new Promise((done) => {
809
+ open = done;
810
+ });
811
+ unsettled.add(gate);
812
+ result.then(() => {
813
+ unsettled.delete(gate);
814
+ open();
815
+ }, (error) => {
816
+ unsettled.delete(gate);
817
+ open();
818
+ throw error;
819
+ });
820
+ }
821
+ }
822
+ /**
823
+ * Resolves once the setter calls made so far have settled, whether they kept the write or not.
824
+ * Returns undefined when none waits or runs, so the caller can act at once.
825
+ */
826
+ function whenSettled() {
827
+ if (unsettled.size === 0) return;
828
+ return Promise.all(unsettled).then(() => {});
829
+ }
783
830
  let lastCall = Promise.resolve();
784
831
  /**
785
832
  * Calls a function of another component, such as a function prop or a provided function. The
@@ -790,9 +837,9 @@ let lastCall = Promise.resolve();
790
837
  function call(ref, scope, args) {
791
838
  const code = codeReady();
792
839
  const loaded = code ? Promise.all([resolve$1(ref), code]).then(([fn]) => fn) : resolve$1(ref);
793
- waiting$1++;
840
+ waiting$2++;
794
841
  const started = lastCall.then(() => loaded).finally(() => {
795
- waiting$1--;
842
+ waiting$2--;
796
843
  }).then((fn) => ({ value: inPass(() => fn(scope, ...args)) }));
797
844
  lastCall = started.catch(() => {});
798
845
  return started.then((result) => result.value);
@@ -809,9 +856,23 @@ function templateReference(ref, scope) {
809
856
  return render ? insert(render(scope, ...args), void 0, at) : "";
810
857
  });
811
858
  }
859
+ /**
860
+ * A call of a `#template` of the file, which an insert can update in place. `render` is the
861
+ * template's code, and `owner` the scope that holds the template. The call finds its contexts
862
+ * where the template is written, as the output of a template does, so it does not render as
863
+ * children of the owner.
864
+ */
865
+ function templateCall(ref, owner, render, args) {
866
+ return new TemplateCall(ref, owner, args, (at) => insert(render(...args), void 0, at), true);
867
+ }
812
868
  /** Renders a value inserted in markup. Children render here, at `scope`, for their contexts. */
813
869
  function insert(value, _ctx, scope) {
814
870
  linkCalls(value, scope);
871
+ if (HAS_TEMPLATES && Array.isArray(value)) {
872
+ let out = "";
873
+ for (const item of value) out += insert(item, void 0, scope);
874
+ return out;
875
+ }
815
876
  if (!((HAS_CHILDREN || HAS_TEMPLATES) && value instanceof Children)) return insertValue(value);
816
877
  const out = value.render(resolveScope(scope));
817
878
  return HAS_CLIENT_HTML ? holdPlace(out) : out;
@@ -872,8 +933,8 @@ var TemplateCall = class extends Children {
872
933
  /** The scope of the component that wrote the template. */
873
934
  owner;
874
935
  args;
875
- constructor(ref, owner, args, html) {
876
- super(owner, html);
936
+ constructor(ref, owner, args, html, lexical = false) {
937
+ super(lexical ? void 0 : owner, html);
877
938
  this.ref = ref;
878
939
  this.owner = owner;
879
940
  this.args = args;
@@ -959,10 +1020,11 @@ function children(from, html) {
959
1020
  * `#try` around the scope of the code, through the parents and the owners of
960
1021
  * scopes. A template's scope goes on from the scope where it was called.
961
1022
  * Without a `#try`, the page gets a `brumate:error` event on `window`, with
962
- * the error and the scope, and the error is logged.
1023
+ * the error and the scope, and the error is logged. `onError` hears it first. With `uncaught`,
1024
+ * it hears only an error that no `#try` catches, as on the server.
963
1025
  */
964
- function fail(scope, error) {
965
- options.onError?.(error, { scope: scope?.id });
1026
+ function fail(scope, error, uncaught) {
1027
+ if (!uncaught || !HAS_TRIES) options.onError?.(error, { scope: scope?.id });
966
1028
  if (!HAS_TRIES) {
967
1029
  unhandled(error, scope);
968
1030
  return;
@@ -985,6 +1047,7 @@ function fail(scope, error) {
985
1047
  return;
986
1048
  }
987
1049
  }
1050
+ if (uncaught) options.onError?.(error, { scope: scope?.id });
988
1051
  unhandled(error, scope);
989
1052
  })();
990
1053
  }
@@ -1018,13 +1081,13 @@ function replaceTry(key) {
1018
1081
  * one scope can hold the same promise.
1019
1082
  */
1020
1083
  const reported = /* @__PURE__ */ new WeakMap();
1021
- /** `fail`, once per error and scope. */
1084
+ /** `fail`, once per error and scope, for the rejection of a memo that a wait or an `await` reads. */
1022
1085
  function reportOnce(scope, error) {
1023
1086
  if (typeof error === "object" && error !== null) {
1024
1087
  if (reported.has(error) && reported.get(error) === scope) return;
1025
1088
  reported.set(error, scope);
1026
1089
  }
1027
- fail(scope, error);
1090
+ fail(scope, error, true);
1028
1091
  }
1029
1092
  /** Reports the error of a `#loading` body that failed on the server, with no `#try` around it. */
1030
1093
  function failBoundary(error) {
@@ -1079,6 +1142,7 @@ let writes = 0;
1079
1142
  /** Starts the count of writes again. */
1080
1143
  function resetWrites() {
1081
1144
  writes = 0;
1145
+ written.clear();
1082
1146
  }
1083
1147
  /**
1084
1148
  * Writes a slot from code of a component. A prop that a parent bound with
@@ -1112,10 +1176,13 @@ function send(bound, value) {
1112
1176
  const element = findElement(value.scope, value.anchor);
1113
1177
  if (element) send(bound, element);
1114
1178
  });
1115
- else if (bound instanceof FunctionReference) {
1116
- const args = [...bound.args ?? [], value];
1117
- if (!callNow(bound.ref, scopes.get(bound.scope), args)) call(bound.ref, scopes.get(bound.scope), args);
1118
- } else if (typeof bound === "function") bound(value);
1179
+ else if (bound instanceof FunctionReference || typeof bound === "function") {
1180
+ const reference = bound instanceof FunctionReference ? bound : handlerReferences.get(bound);
1181
+ if (reference) {
1182
+ const args = [...reference.args ?? [], value];
1183
+ if (!callNow(reference.ref, scopes.get(reference.scope), args)) track$1(call(reference.ref, scopes.get(reference.scope), args));
1184
+ } else if (typeof bound === "function") track$1(bound(value));
1185
+ }
1119
1186
  }
1120
1187
  /** The setters that were given each element, so an update of a spread does not call them again. */
1121
1188
  const given = /* @__PURE__ */ new WeakMap();
@@ -1132,6 +1199,7 @@ function give$1(bound, element) {
1132
1199
  function writeSlot(scope, slot, value) {
1133
1200
  if (!Object.is(scope.s[slot], value)) {
1134
1201
  writes++;
1202
+ written.add(`${findRoot(scope).m}:${scope.k}:${slot}`);
1135
1203
  scope.s[slot] = value;
1136
1204
  if (DEV) devtools()?.write?.(scope, slot, value);
1137
1205
  trigger(scope, slot);
@@ -1224,8 +1292,9 @@ function isThenable(value) {
1224
1292
  return value !== null && typeof value === "object" && typeof value.then === "function";
1225
1293
  }
1226
1294
  /**
1227
- * Reports the rejection of a memo that the browser renders and nothing reads, so it has no slot.
1228
- * The error reaches the nearest `#try` around the scope, or `onError`.
1295
+ * Reports the rejection of a memo that the browser renders and that only an `await` reads, so it
1296
+ * has no slot. The server throws the error at the `await`. It reaches the nearest `#try` around
1297
+ * the scope, or `onError`. A memo that nothing reads is not declared at all.
1229
1298
  */
1230
1299
  function unreadMemo(scope, value) {
1231
1300
  if (isThenable(value)) {
@@ -1268,6 +1337,7 @@ function asyncMemo(scope, slot, promise) {
1268
1337
  }
1269
1338
  })();
1270
1339
  }, failed);
1340
+ return load;
1271
1341
  }
1272
1342
  /** Thrown when a memo reads a value that is still loading. */
1273
1343
  var NotReady = class extends Error {
@@ -1359,11 +1429,6 @@ function memoSignal() {
1359
1429
  function memo(scope, slot, compute) {
1360
1430
  const key = `${scope.id}:${slot}`;
1361
1431
  if (guesses?.same(key)) return;
1362
- const rendered = scope.s[slot];
1363
- if (renderedLoads.delete(key)) {
1364
- if (isThenable(rendered)) asyncMemo(scope, slot, Promise.resolve(rendered));
1365
- return;
1366
- }
1367
1432
  let value;
1368
1433
  let threw = false;
1369
1434
  memoControllers.get(key)?.abort();
@@ -1420,8 +1485,8 @@ function trigger(scope, slot) {
1420
1485
  pass(() => queueWrite(scope, slot));
1421
1486
  return;
1422
1487
  }
1423
- if (waiting) {
1424
- waiting.push([
1488
+ if (waiting$1) {
1489
+ waiting$1.push([
1425
1490
  scope,
1426
1491
  slot,
1427
1492
  loadModule(id).then(() => childrenReady(scope)).catch((error) => fail(scope, error))
@@ -1431,7 +1496,7 @@ function trigger(scope, slot) {
1431
1496
  const from = origin;
1432
1497
  const via = viaContext;
1433
1498
  const list = [[scope, slot]];
1434
- if (running > 0) waiting = list;
1499
+ if (running > 0) waiting$1 = list;
1435
1500
  const loading = loadModule(id).then(async () => {
1436
1501
  const waits = [children];
1437
1502
  for (const [target, , load] of list) waits.push(...codeAbove(target), load);
@@ -1459,7 +1524,7 @@ function trigger(scope, slot) {
1459
1524
  });
1460
1525
  }
1461
1526
  /** The writes of the pass that runs that wait for code, to run as one pass of their own. */
1462
- let waiting;
1527
+ let waiting$1;
1463
1528
  /** The updates that wait for their code. */
1464
1529
  const loadingUpdates = /* @__PURE__ */ new Set();
1465
1530
  /**
@@ -1500,8 +1565,8 @@ function pass(write) {
1500
1565
  if (--running === 0) {
1501
1566
  for (const level of levels.reverse()) for (const [key, runEffect] of level?.e ?? []) pendingEffects.set(key, runEffect);
1502
1567
  levels = [];
1503
- held = waiting !== void 0;
1504
- waiting = void 0;
1568
+ held = waiting$1 !== void 0;
1569
+ waiting$1 = void 0;
1505
1570
  depths.clear();
1506
1571
  failed = false;
1507
1572
  stuck = false;
@@ -1534,6 +1599,7 @@ function flush() {
1534
1599
  if (running > 0 && !draining) drain();
1535
1600
  }
1536
1601
  globalThis[Symbol.for("brumate.flush")] = flush;
1602
+ if (HAS_BINDINGS) globalThis[Symbol.for("brumate.settled")] = whenSettled;
1537
1603
  /**
1538
1604
  * Queues the updates that read a slot, on the scope and on its descendants of
1539
1605
  * each kind, once the code of the component has loaded.
@@ -1837,12 +1903,6 @@ function resetGuesses() {
1837
1903
  }
1838
1904
  //#endregion
1839
1905
  //#region src/runtime/client/handlers.ts
1840
- /**
1841
- * The handlers that the core makes from references, with their references,
1842
- * so a spread in markup that the browser renders passes them on in `b-on`,
1843
- * as a spread on the server does.
1844
- */
1845
- const handlerReferences = /* @__PURE__ */ new WeakMap();
1846
1906
  /** The modifiers that the wrappers of `brumate/events` put on a handler. */
1847
1907
  const MODIFIERS = Symbol.for("brumate.modifiers");
1848
1908
  /**
@@ -1990,12 +2050,12 @@ function action(name, id, method, result) {
1990
2050
  * call loads, so the core holds only this.
1991
2051
  */
1992
2052
  function submitAction(form, submitter) {
1993
- import("./rpc-BYYAj1vV.js").then((module) => module.sendAction(form, submitter));
2053
+ import("./rpc-C_znDZ_w.js").then((module) => module.sendAction(form, submitter));
1994
2054
  }
1995
2055
  /** Calls a server function. */
1996
2056
  async function rpc(id, args) {
1997
2057
  const signal = memoSignal();
1998
- return track(import("./rpc-BYYAj1vV.js").then((module) => module.call(rpcPrefix, id, args, signal)));
2058
+ return track(import("./rpc-C_znDZ_w.js").then((module) => module.call(rpcPrefix, id, args, signal)));
1999
2059
  }
2000
2060
  /** A function prop rendered on the client calls the parent's exported handler. */
2001
2061
  function handlerProp(value, ref, scope, bound = [], modifiers) {
@@ -2026,6 +2086,10 @@ function pushRecords(...added) {
2026
2086
  for (const record of added) readRecord(record);
2027
2087
  return 0;
2028
2088
  }
2089
+ /** True for the root of a `#defer` body, which the server names `d` and a number. */
2090
+ function isDeferRoot(root) {
2091
+ return root[0] === "d";
2092
+ }
2029
2093
  /**
2030
2094
  * Reads a state record. The first record holds the page state, and later
2031
2095
  * records settle the promises in it.
@@ -2047,7 +2111,7 @@ function readRecord([script, code]) {
2047
2111
  if (script.hasAttribute("b-scopes")) {
2048
2112
  const unpacked = unpackState(decoded);
2049
2113
  const added = addScopes(hooks.record ? hooks.record(script, unpacked) : unpacked, root);
2050
- if (writes > 0) refresh(added);
2114
+ if (writes > 0) refresh(added, isDeferRoot(root));
2051
2115
  }
2052
2116
  }
2053
2117
  /** Reads the groups of scope records back into one record per scope. See `PackedState`. */
@@ -2265,7 +2329,6 @@ function leavePage() {
2265
2329
  loadingSlots.clear();
2266
2330
  for (const memoController of memoControllers.values()) memoController.abort();
2267
2331
  memoControllers.clear();
2268
- renderedLoads.clear();
2269
2332
  for (const { timer } of timers.values()) clearTimeout(timer);
2270
2333
  timers.clear();
2271
2334
  guesses?.map.clear();
@@ -2336,11 +2399,12 @@ function init(value) {
2336
2399
  //#endregion
2337
2400
  //#region src/runtime/client/templates.ts
2338
2401
  /** A template of the markup of a render, which `clone` parses once. */
2339
- function template(html, count, foreign) {
2402
+ function template(html, count, foreign, indexed) {
2340
2403
  return {
2341
2404
  html,
2342
2405
  count,
2343
- foreign
2406
+ foreign,
2407
+ m: indexed
2344
2408
  };
2345
2409
  }
2346
2410
  /**
@@ -2371,7 +2435,7 @@ function parseTemplate(source) {
2371
2435
  const mark = /^x(\d+)$/.exec(node.data);
2372
2436
  if (mark) paths[Number(mark[1])] = findPath(node);
2373
2437
  }
2374
- options?.listen(root);
2438
+ if (!source.m) options?.listen(root);
2375
2439
  source.t = element;
2376
2440
  return paths;
2377
2441
  }
@@ -2423,6 +2487,7 @@ function encodeWalk(paths) {
2423
2487
  */
2424
2488
  function clone(source) {
2425
2489
  const walk = source.walk ??= encodeWalk(parseTemplate(source));
2490
+ if (source.m) markCloned();
2426
2491
  const fragment = source.t.content.cloneNode(true);
2427
2492
  const cloned = new Array(source.count + 1);
2428
2493
  cloned[source.count] = fragment;
@@ -2686,24 +2751,58 @@ function dynamic(tag, attributes, inner, _ctx, scope, ref) {
2686
2751
  const open = `<${name}${startAttributes(attributes)}>`;
2687
2752
  return VOID_ELEMENTS.has(name) ? open : `${open}${inner ? insert(inner, void 0, scope) : ""}</${name}>`;
2688
2753
  }
2754
+ /** The promises and streams that `renderMemo` made, which `setSlots` loads as memos. */
2755
+ const memoLoads = /* @__PURE__ */ new WeakMap();
2756
+ /**
2757
+ * Computes a memo of a render. A promise or a stream is marked, so `setSlots` starts its load
2758
+ * once the scope is in the page. A throw is held in a `MemoError`, as the server holds the error
2759
+ * of a memo until a read.
2760
+ */
2761
+ function renderMemo(compute) {
2762
+ let value;
2763
+ try {
2764
+ value = compute();
2765
+ } catch (error) {
2766
+ return new MemoError(error);
2767
+ }
2768
+ if (isThenable(value) || isAsyncIterable(value)) memoLoads.set(value, (memoLoads.get(value) ?? 0) + 1);
2769
+ return value;
2770
+ }
2771
+ /** Reads a memo of a render: the error that a throw held is thrown at the read. */
2772
+ function readMemo(value) {
2773
+ if (value instanceof MemoError) throw value.error;
2774
+ return value;
2775
+ }
2689
2776
  function setSlots(id, values) {
2690
- scopes.get(id).s = values;
2777
+ const own = scopes.get(id);
2778
+ own.s = values;
2779
+ const counted = /* @__PURE__ */ new Map();
2691
2780
  for (let slot = 0; slot < values.length; slot++) {
2692
2781
  const value = values[slot];
2693
- if (value instanceof Promise && scopes.get(id).props?.includes(value) && values.indexOf(value) === slot) {
2694
- (scopes.get(id).plain ??= /* @__PURE__ */ new Set()).add(slot);
2782
+ const made = memoLoads.get(value);
2783
+ let loading = false;
2784
+ if (value instanceof Promise && own.props?.includes(value) && values.indexOf(value) === slot) {
2785
+ (own.plain ??= /* @__PURE__ */ new Set()).add(slot);
2695
2786
  value.catch(noop$1);
2696
- } else if (isThenable(value)) {
2697
- const key = `${id}:${slot}`;
2698
- renderedLoads.add(key);
2787
+ loading = made !== void 0 && values.lastIndexOf(value) === slot;
2788
+ } else if (made !== void 0) {
2789
+ loading = (counted.get(value) ?? 0) < made;
2790
+ counted.set(value, (counted.get(value) ?? 0) + 1);
2791
+ }
2792
+ const key = `${id}:${slot}`;
2793
+ let started;
2794
+ if (loading) afterInsert.push(() => {
2795
+ if (scopes.get(id) === own) started = asyncMemo(own, slot, Promise.resolve(value));
2796
+ });
2797
+ if (isThenable(value) && !own.plain?.has(slot)) {
2699
2798
  loadingValues.add(value);
2700
2799
  Promise.resolve(value).then((result) => {
2701
2800
  const scope = scopes.get(id);
2702
- if (scope?.s[slot] === value && !loads.has(key)) set(scope, slot, result);
2801
+ if (scope?.s[slot] === value && (!loads.has(key) || loads.get(key) === started)) set(scope, slot, result);
2703
2802
  }, noop$1);
2704
2803
  }
2705
2804
  }
2706
- scopes.get(id).props = void 0;
2805
+ own.props = void 0;
2707
2806
  }
2708
2807
  function setItem(id, value) {
2709
2808
  scopes.get(id).i = value;
@@ -2772,8 +2871,16 @@ function portalTo(scope, target, render, kinds = [], holderKind, holderAnchor) {
2772
2871
  const element = typeof target === "string" ? document.querySelector(target) : target;
2773
2872
  if (!(element instanceof Element)) return;
2774
2873
  const id = nextId;
2775
- const body = inPlace(scope, render, holderKind, holderAnchor);
2776
- insertHTML({ parent: element }, `<!--P${id}-->${body(scope)}<!--/P-->`);
2874
+ const out = inPlace(scope, render, holderKind, holderAnchor)(scope);
2875
+ if (typeof out === "string") {
2876
+ insertHTML({ parent: element }, `<!--P${id}-->${out}<!--/P-->`);
2877
+ return;
2878
+ }
2879
+ const start = document.createComment("");
2880
+ nameComment(start, `P${id}`);
2881
+ out.prepend(start);
2882
+ out.append(document.createComment("/P"));
2883
+ insertHTML({ parent: element }, out);
2777
2884
  }
2778
2885
  /** Writes an inserted value between `<!--t…-->` and `<!--/t-->`. */
2779
2886
  function text(scope, anchor, value) {
@@ -2818,8 +2925,9 @@ function write(parent, first, end, value, at, key, anchor) {
2818
2925
  const firstWrite = key !== void 0 && !writtenInserts.has(key);
2819
2926
  if (HAS_CHILDREN && refreshing && firstWrite && value instanceof RenderedChildren && value.at !== void 0 && value.at === at?.id && value.anchor === anchor) return;
2820
2927
  if (key) writtenInserts.add(key);
2928
+ const replaced = HAS_TEMPLATES && key ? templateInserts.get(key)?.scope : void 0;
2821
2929
  if (HAS_TEMPLATES && key && value instanceof TemplateCall) {
2822
- const known = templateInserts.get(key) ?? (firstWrite ? renderedTemplate(value, at, loadedFunction(`${value.ref}k`)) : void 0);
2930
+ const known = templateInserts.get(key) ?? (firstWrite ? renderedTemplate(value, at, loadedFunction(`${value.ref}k`), first, end) : void 0);
2823
2931
  const getSlots = loadedFunction(`${value.ref}a`);
2824
2932
  if (known && getSlots && known.ref === value.ref && scopes.has(known.scope.id)) {
2825
2933
  templateInserts.set(key, known);
@@ -2834,6 +2942,10 @@ function write(parent, first, end, value, at, key, anchor) {
2834
2942
  else if (first.data !== data) first.data = data;
2835
2943
  return;
2836
2944
  }
2945
+ if (HAS_CHILDREN || HAS_TEMPLATES) {
2946
+ if (replaced) destroy(replaced);
2947
+ destroyNodes(at, first, end);
2948
+ }
2837
2949
  while (first && first !== end) {
2838
2950
  const next = first.nextSibling;
2839
2951
  first.remove();
@@ -2841,7 +2953,7 @@ function write(parent, first, end, value, at, key, anchor) {
2841
2953
  }
2842
2954
  const made = nextId;
2843
2955
  linkCalls(value, at);
2844
- insertHTML(end ?? { parent }, (HAS_CHILDREN || HAS_TEMPLATES) && value instanceof Children ? value.render(at) : insertValue(value));
2956
+ insertHTML(end ?? { parent }, (HAS_CHILDREN || HAS_TEMPLATES) && value instanceof Children ? value.render(at) : insert(value, void 0, at));
2845
2957
  if (HAS_TEMPLATES && key) {
2846
2958
  const scope = value instanceof TemplateCall ? scopes.get(made) : void 0;
2847
2959
  if (scope) templateInserts.set(key, {
@@ -2859,10 +2971,10 @@ const writtenInserts = /* @__PURE__ */ new WeakSet();
2859
2971
  * The scope of a template that the server rendered at an insert: the scope that the template's
2860
2972
  * component made, and that finds its contexts from the insert.
2861
2973
  */
2862
- function renderedTemplate(call, at, k) {
2974
+ function renderedTemplate(call, at, k, first, end) {
2863
2975
  if (k === void 0) return;
2864
2976
  let found;
2865
- for (const scope of scopes.values()) if (call.owner && scope.p === call.owner && scope.t === at && scope.k === k) {
2977
+ for (const scope of scopes.values()) if (call.owner && scope.p === call.owner && scope.k === k && (scope.t === at || scope.l === at && inRange(scope, first, end))) {
2866
2978
  if (found) return;
2867
2979
  found = scope;
2868
2980
  }
@@ -2871,6 +2983,17 @@ function renderedTemplate(call, at, k) {
2871
2983
  scope: found
2872
2984
  };
2873
2985
  }
2986
+ /** True if an anchor of the scope, a comment, an element or a kept node, is in the range. */
2987
+ function inRange(scope, first, end) {
2988
+ const comment = `t${scope.id}:`;
2989
+ const element = `${scope.id}:`;
2990
+ for (let node = first; node && node !== end; node = node.nextSibling) {
2991
+ const walker = document.createTreeWalker(node, 129);
2992
+ for (let item = node; item; item = walker.nextNode()) if (item.nodeType === 8 ? item.data.startsWith(comment) : item.nodeType === 1 && item.getAttribute("b-b")?.startsWith(element)) return true;
2993
+ for (const kept of scope.n ?? []) if (kept && (kept === node || node.contains(kept))) return true;
2994
+ }
2995
+ return false;
2996
+ }
2874
2997
  /** The `value` and `checked` that updates last wrote to each field. */
2875
2998
  const fieldValues = /* @__PURE__ */ new WeakMap();
2876
2999
  function setAttribute(element, name, value, spread = false) {
@@ -2973,8 +3096,6 @@ function updateSpreadEntries(element, values) {
2973
3096
  }
2974
3097
  //#endregion
2975
3098
  //#region src/runtime/client/waits.ts
2976
- /** The slots of a scope whose awaits settled, until the insert that shows the scope. */
2977
- const settledSlots = /* @__PURE__ */ new WeakMap();
2978
3099
  /** The boundary of the render that runs, if any. */
2979
3100
  let boundary;
2980
3101
  /** The scope whose rest of a render runs after a wait, if any. */
@@ -2995,7 +3116,7 @@ function within$1(own, render) {
2995
3116
  * so the insert of anything else does not take them. `give` puts them back before the body goes
2996
3117
  * in, and the caller sets `done`, and `f` if it handles failures, before any wait settles.
2997
3118
  */
2998
- function bound(body) {
3119
+ function bound$1(body) {
2999
3120
  const own = {
3000
3121
  n: 0,
3001
3122
  c: writes,
@@ -3023,7 +3144,7 @@ function give(own) {
3023
3144
  return;
3024
3145
  }
3025
3146
  if (own.c === writes) rendered.push(...made);
3026
- else queued.push(() => refresh(made));
3147
+ else queued.push(() => refresh(made, false, false));
3027
3148
  afterInsert.push(...queued);
3028
3149
  }
3029
3150
  /**
@@ -3034,7 +3155,7 @@ function give(own) {
3034
3155
  */
3035
3156
  function attempt(body) {
3036
3157
  if (!boundary) return toNodes(body());
3037
- const [out, own] = bound(body);
3158
+ const [out, own] = bound$1(body);
3038
3159
  if (own) {
3039
3160
  const outer = join();
3040
3161
  own.done = () => {
@@ -3226,7 +3347,9 @@ function wait(id, slots, slot, rest) {
3226
3347
  const promise = Promise.resolve(first);
3227
3348
  slots[slot] = void 0;
3228
3349
  const props = scope.props;
3350
+ const queued = afterInsert.length;
3229
3351
  setSlots(id, slots);
3352
+ afterInsert.length = queued;
3230
3353
  scope.props = props;
3231
3354
  scope.s[slot] = promise;
3232
3355
  loadingValues.add(promise);
@@ -3245,20 +3368,17 @@ function wait(id, slots, slot, rest) {
3245
3368
  }
3246
3369
  const value = scope.s[slot];
3247
3370
  if (value instanceof MemoError) {
3248
- fail(scope, value.error);
3371
+ fail(scope, value.error, true);
3249
3372
  fault(own, value.error);
3250
3373
  return;
3251
3374
  }
3252
- let shown = false;
3253
3375
  try {
3254
3376
  fillRange(own, end, () => {
3255
3377
  rendered.push(scope);
3256
3378
  const outer = resting;
3257
3379
  resting = scope;
3258
3380
  try {
3259
- const out = updating(() => rest(scope.s));
3260
- shown = rendered.includes(scope);
3261
- return out;
3381
+ return updating(() => rest(scope.s));
3262
3382
  } finally {
3263
3383
  resting = outer;
3264
3384
  }
@@ -3268,13 +3388,6 @@ function wait(id, slots, slot, rest) {
3268
3388
  fault(own, error);
3269
3389
  return;
3270
3390
  }
3271
- const done = settledSlots.get(scope) ?? [];
3272
- done.push(slot);
3273
- settledSlots.set(scope, done);
3274
- if (shown) {
3275
- settledSlots.delete(scope);
3276
- for (const settled of done) if (settled < scope.s.length) renderedLoads.add(`${scope.id}:${settled}`);
3277
- }
3278
3391
  leave(own);
3279
3392
  }
3280
3393
  const check = until(own, scope, end, () => !pending(scope, slot), settle);
@@ -3348,7 +3461,7 @@ function hold(at, key, render, show) {
3348
3461
  return;
3349
3462
  }
3350
3463
  drop(at);
3351
- const [out, own] = bound(render);
3464
+ const [out, own] = bound$1(render);
3352
3465
  if (!own) {
3353
3466
  show(out);
3354
3467
  return;
@@ -3395,7 +3508,7 @@ function release(at) {
3395
3508
  * not render it again.
3396
3509
  */
3397
3510
  function holdRow(list, render) {
3398
- const [out, own] = bound(render);
3511
+ const [out, own] = bound$1(render);
3399
3512
  if (!own) return out;
3400
3513
  let row;
3401
3514
  for (const scope of own.w[0]) if (scope.p === list) row ??= scope;
@@ -3501,7 +3614,7 @@ function renderLoading(group, body, fallback) {
3501
3614
  const made = rendered.length;
3502
3615
  const queued = afterInsert.length;
3503
3616
  const turn = group && !(group.o === "natural" || group.o === "sequential" && group.m.length === 0);
3504
- const result = bound(body);
3617
+ const result = bound$1(body);
3505
3618
  const nodes = toNodes(result[0]);
3506
3619
  let own = result[1];
3507
3620
  if (!own) {
@@ -4195,6 +4308,143 @@ function addStyle(id, css) {
4195
4308
  return "";
4196
4309
  }
4197
4310
  //#endregion
4311
+ //#region src/runtime/client/search.ts
4312
+ /** The signals of the page that follow a parameter, by scope and slot. */
4313
+ const bound = /* @__PURE__ */ new Map();
4314
+ /** The slots whose effect ran once. The first run is the load of the page. */
4315
+ const loaded = /* @__PURE__ */ new WeakMap();
4316
+ /** The changes of the URL that wait for the end of the writes of one pass. */
4317
+ const waiting = /* @__PURE__ */ new Map();
4318
+ /** `$searchParam` in the browser: the parameter of the URL of the page. */
4319
+ function searchParam(name, options) {
4320
+ return readParam(new URLSearchParams(location.search), name, options);
4321
+ }
4322
+ /**
4323
+ * The effect of `$searchParam`: it writes the URL when the signal changes, and follows the
4324
+ * history while the scope lives.
4325
+ */
4326
+ function paramEffect(scope, slot, name, options) {
4327
+ return () => {
4328
+ const key = `${scope.id}:${slot}`;
4329
+ if (!options?.server) {
4330
+ bound.set(key, {
4331
+ scope,
4332
+ slot,
4333
+ name,
4334
+ options
4335
+ });
4336
+ globalThis[HOOK] = follow;
4337
+ }
4338
+ let started = loaded.get(scope);
4339
+ if (!started) {
4340
+ started = /* @__PURE__ */ new Set();
4341
+ loaded.set(scope, started);
4342
+ }
4343
+ const first = !started.has(slot);
4344
+ started.add(slot);
4345
+ const text = writeParam(get(scope, slot), options);
4346
+ const current = readParam(new URLSearchParams(location.search), name, options);
4347
+ if (writeParam(current, options) !== text) {
4348
+ if (first && !options?.server) {
4349
+ set(scope, slot, current);
4350
+ return () => void bound.delete(key);
4351
+ }
4352
+ if (waiting.size === 0) queueMicrotask(commit);
4353
+ waiting.set(name, {
4354
+ text,
4355
+ options
4356
+ });
4357
+ }
4358
+ return () => void bound.delete(key);
4359
+ };
4360
+ }
4361
+ /** The key of the hook with which the loader asks whether a change of the URL is ours. */
4362
+ const HOOK = Symbol.for("brumate.search");
4363
+ /** Writes the changes of one pass to the URL, as one entry of the history. */
4364
+ function commit() {
4365
+ const url = new URL(location.href);
4366
+ let push = false;
4367
+ let server = false;
4368
+ const changes = /* @__PURE__ */ new Map();
4369
+ for (const [name, { text, options }] of waiting) {
4370
+ changes.set(name, text);
4371
+ push ||= options?.history === "push";
4372
+ server ||= options?.server === true;
4373
+ }
4374
+ const names = new Set(waiting.keys());
4375
+ waiting.clear();
4376
+ url.search = editQuery(url.search, changes);
4377
+ if (server) {
4378
+ navigate(url.href, {
4379
+ replace: !push,
4380
+ scroll: false
4381
+ });
4382
+ return;
4383
+ }
4384
+ if (push) history.pushState({}, "", url);
4385
+ else history.replaceState(history.state, "", url);
4386
+ pass(() => {
4387
+ for (const { scope, slot, name, options } of bound.values()) if (names.has(name)) set(scope, slot, readParam(url.searchParams, name, options));
4388
+ });
4389
+ document.dispatchEvent(new Event("brumate:search"));
4390
+ updateRoute();
4391
+ }
4392
+ /** The names of the parameters in a query string, as the URL reads them. */
4393
+ function queryName(piece) {
4394
+ return new URLSearchParams(piece).keys().next().value ?? "";
4395
+ }
4396
+ /**
4397
+ * The query string with the changes made, and every other parameter as it was written. The
4398
+ * first piece of a changed name takes the new text, and its other pieces go.
4399
+ */
4400
+ function editQuery(search, changes) {
4401
+ const pieces = [];
4402
+ const done = /* @__PURE__ */ new Set();
4403
+ for (const piece of search.slice(1).split("&")) {
4404
+ const name = piece === "" ? "" : queryName(piece);
4405
+ if (!changes.has(name)) {
4406
+ if (piece !== "") pieces.push(piece);
4407
+ continue;
4408
+ }
4409
+ const text = changes.get(name);
4410
+ if (text !== null && !done.has(name)) pieces.push(new URLSearchParams({ [name]: text }).toString());
4411
+ done.add(name);
4412
+ }
4413
+ for (const [name, text] of changes) if (text !== null && !done.has(name)) pieces.push(new URLSearchParams({ [name]: text }).toString());
4414
+ return pieces.length > 0 ? `?${pieces.join("&")}` : "";
4415
+ }
4416
+ /**
4417
+ * Writes the signals whose parameter changed, from `from` to the URL now. False when another
4418
+ * parameter changed, or the path did: the page loads then.
4419
+ */
4420
+ function follow(from) {
4421
+ const before = new URL(from);
4422
+ const now = new URL(location.href);
4423
+ if (before.pathname !== now.pathname) return false;
4424
+ const names = /* @__PURE__ */ new Set([...before.searchParams.keys(), ...now.searchParams.keys()]);
4425
+ const changed = [];
4426
+ for (const name of names) {
4427
+ if (same(before.searchParams.getAll(name), now.searchParams.getAll(name))) continue;
4428
+ let owned = false;
4429
+ for (const item of bound.values()) if (item.name === name) {
4430
+ changed.push(item);
4431
+ owned = true;
4432
+ }
4433
+ if (!owned) return false;
4434
+ }
4435
+ pass(() => {
4436
+ for (const { scope, slot, name, options } of changed) set(scope, slot, readParam(now.searchParams, name, options));
4437
+ });
4438
+ updateRoute();
4439
+ return true;
4440
+ }
4441
+ /** True for two lists of texts that are equal item by item. */
4442
+ function same(a, b) {
4443
+ if (a.length !== b.length) return false;
4444
+ for (let index = 0; index < a.length; index++) if (a[index] !== b[index]) return false;
4445
+ return true;
4446
+ }
4447
+ //#endregion
4198
4448
  //#region src/runtime/client.ts
4199
4449
  /**
4200
4450
  * What the loader calls. It is one export, so the loader's import of the core
@@ -4210,6 +4460,6 @@ const loader = {
4210
4460
  };
4211
4461
  function noop() {}
4212
4462
  //#endregion
4213
- 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 };
4463
+ export { branchNodes as $, templateCall as $t, started as A, consumeContext as At, spreadProps as B, get as Bt, fillAttrs as C, handle as Ct, keepValue as D, submitAction as Dt, fillValue as E, spread as Et, portalTo as F, asyncMemo as Ft, elementAt as G, set as Gt, componentNodes as H, memo as Ht, restRef as I, binding as It, readMemo as J, update as Jt, foreignNodes as K, timed as Kt, text as L, bindings as Lt, attr as M, setGlobal as Mt, attrs as N, updateContext as Nt, loading as O, guess as Ot, content as P, updateRoute as Pt, appendText as Q, insert as Qt, writeText as R, cells as Rt, countLoads as S, action as St, fillSpread as T, rpc as Tt, dynamic as U, pending as Ut, component as V, isBound as Vt, dynamicNodes as W, resolve as Wt, setItem as X, fail as Xt, renderMemo as Y, updated as Yt, setSlots as Z, children as Zt, rekey as _, init as _t, addPortal as a, makeId as an, listNodes as at, after as b, remount as bt, setVar as c, sink as cn, putText as ct, windowList as d, DEVTOOLS as dn, setContent as dt, title as en, clone as et, windowStart as f, build as fn, setOn as ft, offscreen as g, skew as gn, forget as gt, held as h, scopes as hn, dispose as ht, addHead as i, getScope as in, keepText as it, wait as j, provideValue as jt, reveal as k, track as kt, list as l, loadModule as ln, setAttr as lt, fill as m, rpcPrefix as mn, template as mt, paramEffect as n, createScope as nn, fillList as nt, addStyle as o, removeScope as on, markBlock as ot, branch as p, hooks as pn, setSpread as pt, place as q, unreadMemo as qt, searchParam as r, descendants as rn, keep as rt, deferInBrowser as s, setOwner as sn, nodes as st, loader as t, afterInsert as tn, fillBranch as tt, toList as u, nameComment as un, setAttrText as ut, reset as v, leavePage as vt, fillSettled as w, handlerProp as wt, attempt as x, removeRoot as xt, retag as y, leaveRoutes as yt, prop as z, effect as zt };
4214
4464
 
4215
- //# sourceMappingURL=client-De-7aGlO.js.map
4465
+ //# sourceMappingURL=client-C3vRNuLi.js.map