brumate 0.6.2 → 0.7.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 (89) hide show
  1. package/check.d.ts +3 -3
  2. package/dist/{boot-DkbcqdUz.d.ts → boot-Cs_P8cDu.d.ts} +2 -2
  3. package/dist/cli.js +77 -6
  4. package/dist/cli.js.map +1 -1
  5. package/dist/{client-CqGDbWd_.d.ts → client-BDPsTd4q.d.ts} +40 -14
  6. package/dist/{client-C3vRNuLi.js → client-DYIZ7BYK.js} +271 -112
  7. package/dist/client-DYIZ7BYK.js.map +1 -0
  8. package/dist/{client-routes-BtGpYCef.js → client-routes-BmPvNr4s.js} +10 -1
  9. package/dist/client-routes-BmPvNr4s.js.map +1 -0
  10. package/dist/{context-btHuB01Z.d.ts → context-BNgBXVUQ.d.ts} +7 -5
  11. package/dist/{context-CTiSzQRc.js → context-CU4Fpn5a.js} +10 -13
  12. package/dist/context-CU4Fpn5a.js.map +1 -0
  13. package/dist/{defer-M18UKyfG.js → defer-7JDhFxQq.js} +2 -2
  14. package/dist/{defer-M18UKyfG.js.map → defer-7JDhFxQq.js.map} +1 -1
  15. package/dist/{devtools-D9Q7a41M.js → devtools-CzSp1GGq.js} +4 -4
  16. package/dist/{devtools-D9Q7a41M.js.map → devtools-CzSp1GGq.js.map} +1 -1
  17. package/dist/{devtools-panel-DTQtljeA.js → devtools-panel-DugGrz7L.js} +32 -9
  18. package/dist/devtools-panel-DugGrz7L.js.map +1 -0
  19. package/dist/{features-CbgII-o7.js → features-DwMYKBIC.js} +6 -2
  20. package/dist/features-DwMYKBIC.js.map +1 -0
  21. package/dist/{files-DtDH5AR4.js → files-XX5yW3KL.js} +94 -3
  22. package/dist/files-XX5yW3KL.js.map +1 -0
  23. package/dist/index.d.ts +44 -0
  24. package/dist/index.js +3 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/{inspect-Bonq6EJO.js → inspect-B9cRF6AM.js} +2670 -2074
  27. package/dist/inspect-B9cRF6AM.js.map +1 -0
  28. package/dist/{loader-C-S3yzep.js → loader-BGSXt_Eb.js} +5 -5
  29. package/dist/{loader-C-S3yzep.js.map → loader-BGSXt_Eb.js.map} +1 -1
  30. package/dist/{rpc-C_znDZ_w.js → rpc-B9EkaPdU.js} +3 -3
  31. package/dist/{rpc-C_znDZ_w.js.map → rpc-B9EkaPdU.js.map} +1 -1
  32. package/dist/runtime/bundles.d.ts +1 -1
  33. package/dist/runtime/bundles.js +2 -0
  34. package/dist/runtime/bundles.js.map +1 -1
  35. package/dist/runtime/client.d.ts +4 -4
  36. package/dist/runtime/client.js +4 -4
  37. package/dist/runtime/context.d.ts +2 -2
  38. package/dist/runtime/context.js +1 -1
  39. package/dist/runtime/devtools.d.ts +2 -2
  40. package/dist/runtime/devtools.js +1 -1
  41. package/dist/runtime/hot.d.ts +1 -1
  42. package/dist/runtime/html.d.ts +1 -1
  43. package/dist/runtime/loader.d.ts +2 -2
  44. package/dist/runtime/loader.js +2 -2
  45. package/dist/runtime/server.d.ts +4 -4
  46. package/dist/runtime/server.js +4 -4
  47. package/dist/runtime/signals.d.ts +2 -2
  48. package/dist/runtime/signals.js +43 -5
  49. package/dist/runtime/signals.js.map +1 -1
  50. package/dist/runtime/static-loader.d.ts +2 -2
  51. package/dist/runtime/static-loader.js +1 -1
  52. package/dist/runtime/store.d.ts +2 -0
  53. package/dist/runtime/store.js +1 -0
  54. package/dist/runtime/testing.d.ts +2 -2
  55. package/dist/runtime/testing.js +2 -2
  56. package/dist/{search-params-CM1RWR2P.js → search-params-Cy3uRphR.js} +33 -8
  57. package/dist/search-params-Cy3uRphR.js.map +1 -0
  58. package/dist/{server-BcT9icQ4.js → server-C1OTFH4r.js} +127 -14
  59. package/dist/server-C1OTFH4r.js.map +1 -0
  60. package/dist/{server-dP_ucRiJ.d.ts → server-CavhuoFI.d.ts} +32 -8
  61. package/dist/{shared-CzbnWkVA.d.ts → shared-CRduzyi3.d.ts} +15 -2
  62. package/dist/{signals-BwD4u22K.d.ts → signals-DBnq9QRW.d.ts} +46 -6
  63. package/dist/{static-loader-DysAET-w.d.ts → static-loader-D5hvLQK7.d.ts} +2 -2
  64. package/dist/{static-loader-Bt2WDkY1.js → static-loader-XGXMzfJR.js} +3 -3
  65. package/dist/{static-loader-Bt2WDkY1.js.map → static-loader-XGXMzfJR.js.map} +1 -1
  66. package/dist/store-BIBAYZo-.js +293 -0
  67. package/dist/store-BIBAYZo-.js.map +1 -0
  68. package/dist/store-xlTzAM_r.d.ts +171 -0
  69. package/dist/{stream-DRjx0keF.js → stream-BBnArf_5.js} +89 -3
  70. package/dist/stream-BBnArf_5.js.map +1 -0
  71. package/dist/vite.d.ts +1 -1
  72. package/dist/vite.js +128 -13
  73. package/dist/vite.js.map +1 -1
  74. package/elements.d.ts +268 -21
  75. package/package.json +5 -1
  76. package/skills/brumate/SKILL.md +1 -1
  77. package/skills/brumate/references/errors.md +127 -9
  78. package/skills/brumate/references/signals.md +37 -30
  79. package/skills/brumate/references/state.md +3 -2
  80. package/dist/client-C3vRNuLi.js.map +0 -1
  81. package/dist/client-routes-BtGpYCef.js.map +0 -1
  82. package/dist/context-CTiSzQRc.js.map +0 -1
  83. package/dist/devtools-panel-DTQtljeA.js.map +0 -1
  84. package/dist/features-CbgII-o7.js.map +0 -1
  85. package/dist/files-DtDH5AR4.js.map +0 -1
  86. package/dist/inspect-Bonq6EJO.js.map +0 -1
  87. package/dist/search-params-CM1RWR2P.js.map +0 -1
  88. package/dist/server-BcT9icQ4.js.map +0 -1
  89. package/dist/stream-DRjx0keF.js.map +0 -1
@@ -1,7 +1,8 @@
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 { _ 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
- import { n as ROUTE_KEY } from "./context-CTiSzQRc.js";
2
+ import { _ as HAS_TITLES, a as HAS_CHILDREN, c as HAS_FIELDS, d as HAS_LOADING, f as HAS_ROOT_WAIT, g as HAS_TEMPLATES, h as HAS_STORES, i as HAS_BRIDGES, l as HAS_LATE_MARKUP, n as HAS_BINDINGS, o as HAS_CLIENT_HTML, p as HAS_ROUTES, s as HAS_DYNAMIC, v as HAS_TRIES, y as HAS_WINDOWS } from "./features-DwMYKBIC.js";
3
+ import { a as findStored, f as sameData, h as setBridgeLoader, n as Store, o as isBridged, p as sendStore, u as isStore } from "./store-BIBAYZo-.js";
4
+ import { E as stateValues, O as useSerialEntry, S as mergeHandlers, T as parseId, _ as isAsyncIterable, a as Binding, b as isSlotReference, c as ElementReference, d as PARTS, g as gateValue, h as addEntryHandlers, l as FunctionReference, m as SlotReference, r as writeParam, s as ChildrenReference, t as readParam, u as MemoError, v as isBinding, x as madeStores, y as isPropWrapper } from "./search-params-Cy3uRphR.js";
5
+ import { i as missingContext, n as ROUTE_KEY, t as NAVIGATION_KEY } from "./context-CU4Fpn5a.js";
5
6
  import { n as trustedHTML, t as loadOnce } from "./skew-FRmAy9iy.js";
6
7
  import { n as navigate } from "./routes-D21FQyGF.js";
7
8
  //#region src/runtime/client/state.ts
@@ -99,6 +100,78 @@ function updating(run) {
99
100
  /** What `$resolve` waits in, with the scope of each, checked when a slot changes or a scope leaves. */
100
101
  const waiters = /* @__PURE__ */ new Map();
101
102
  //#endregion
103
+ //#region src/runtime/client/code.ts
104
+ function loadModule(id) {
105
+ let promise = loading$1.get(id);
106
+ if (!promise) {
107
+ promise = Promise.resolve(options.load(id)).then((loaded) => {
108
+ const module = loaded ?? {
109
+ id,
110
+ props: {},
111
+ g: {}
112
+ };
113
+ modules.set(id, module);
114
+ for (const render of module.components ?? []) valueRenders[render.brumateId] = render;
115
+ return module;
116
+ });
117
+ loading$1.set(id, promise);
118
+ }
119
+ return promise;
120
+ }
121
+ /** True for a reference to a `#template` that a component got as a prop, such as `Page#t3`. */
122
+ function isTemplate(ref) {
123
+ return /#t\d/.test(ref);
124
+ }
125
+ /**
126
+ * The code of the components on the page that is still loading. Handlers, updates and calls of
127
+ * functions of other components wait for it, so the code that they call has loaded.
128
+ */
129
+ const loadingCode = /* @__PURE__ */ new Set();
130
+ /** The same loads as `loadingCode`, by the ID of the component. */
131
+ const loadingComponents = /* @__PURE__ */ new Map();
132
+ /** The components whose code loads, or has loaded, with the page. */
133
+ const pageComponents = /* @__PURE__ */ new Set();
134
+ /** Loads the code of a component and all of its parts, as the page reads its scopes. */
135
+ function loadComponent(id) {
136
+ if (options === void 0 || pageComponents.has(id)) return;
137
+ pageComponents.add(id);
138
+ const code = loadModule(id).catch(() => {}).finally(() => {
139
+ loadingCode.delete(code);
140
+ loadingComponents.delete(id);
141
+ });
142
+ loadingCode.add(code);
143
+ loadingComponents.set(id, code);
144
+ }
145
+ /**
146
+ * The code that still loads for the components at a scope and above it. An update of the scope
147
+ * renders the templates and calls the function props of those components, never the code of a
148
+ * component below it, so a layout that stays updates while the code of a new page loads.
149
+ *
150
+ * The walk is the one of contexts. Children that a component C inserted go to C through `t`,
151
+ * and C goes to the parent P that wrote the children through `o`, so the code of P, which
152
+ * the templates and function props of the children come from, is on the walk too.
153
+ */
154
+ function codeAbove(scope) {
155
+ const waits = [];
156
+ if (loadingComponents.size === 0) return waits;
157
+ for (let current = scope; current; current = current.t ?? current.p ?? current.o) {
158
+ const code = current.m === void 0 ? void 0 : loadingComponents.get(current.m);
159
+ if (code) waits.push(code);
160
+ }
161
+ return waits;
162
+ }
163
+ /** Resolves when the code of the components on the page has loaded. */
164
+ function codeReady() {
165
+ return loadingCode.size > 0 ? Promise.allSettled(loadingCode) : void 0;
166
+ }
167
+ /** The function of a reference, such as `Page#h3`, once its code has loaded. */
168
+ function loadedFunction(ref) {
169
+ const [id, name] = ref.split("#");
170
+ const module = modules.get(id);
171
+ if (!module) return;
172
+ return module[name];
173
+ }
174
+ //#endregion
102
175
  //#region src/runtime/client/blocks.ts
103
176
  /**
104
177
  * Indexes the markers of markup that others insert, such as streamed
@@ -259,78 +332,6 @@ function clear(start, end) {
259
332
  range.deleteContents();
260
333
  }
261
334
  //#endregion
262
- //#region src/runtime/client/code.ts
263
- function loadModule(id) {
264
- let promise = loading$1.get(id);
265
- if (!promise) {
266
- promise = Promise.resolve(options.load(id)).then((loaded) => {
267
- const module = loaded ?? {
268
- id,
269
- props: {},
270
- g: {}
271
- };
272
- modules.set(id, module);
273
- for (const render of module.components ?? []) valueRenders[render.brumateId] = render;
274
- return module;
275
- });
276
- loading$1.set(id, promise);
277
- }
278
- return promise;
279
- }
280
- /** True for a reference to a `#template` that a component got as a prop, such as `Page#t3`. */
281
- function isTemplate(ref) {
282
- return /#t\d/.test(ref);
283
- }
284
- /**
285
- * The code of the components on the page that is still loading. Handlers, updates and calls of
286
- * functions of other components wait for it, so the code that they call has loaded.
287
- */
288
- const loadingCode = /* @__PURE__ */ new Set();
289
- /** The same loads as `loadingCode`, by the ID of the component. */
290
- const loadingComponents = /* @__PURE__ */ new Map();
291
- /** The components whose code loads, or has loaded, with the page. */
292
- const pageComponents = /* @__PURE__ */ new Set();
293
- /** Loads the code of a component and all of its parts, as the page reads its scopes. */
294
- function loadComponent(id) {
295
- if (options === void 0 || pageComponents.has(id)) return;
296
- pageComponents.add(id);
297
- const code = loadModule(id).catch(() => {}).finally(() => {
298
- loadingCode.delete(code);
299
- loadingComponents.delete(id);
300
- });
301
- loadingCode.add(code);
302
- loadingComponents.set(id, code);
303
- }
304
- /**
305
- * The code that still loads for the components at a scope and above it. An update of the scope
306
- * renders the templates and calls the function props of those components, never the code of a
307
- * component below it, so a layout that stays updates while the code of a new page loads.
308
- *
309
- * The walk is the one of contexts. Children that a component C inserted go to C through `t`,
310
- * and C goes to the parent P that wrote the children through `o`, so the code of P, which
311
- * the templates and function props of the children come from, is on the walk too.
312
- */
313
- function codeAbove(scope) {
314
- const waits = [];
315
- if (loadingComponents.size === 0) return waits;
316
- for (let current = scope; current; current = current.t ?? current.p ?? current.o) {
317
- const code = current.m === void 0 ? void 0 : loadingComponents.get(current.m);
318
- if (code) waits.push(code);
319
- }
320
- return waits;
321
- }
322
- /** Resolves when the code of the components on the page has loaded. */
323
- function codeReady() {
324
- return loadingCode.size > 0 ? Promise.allSettled(loadingCode) : void 0;
325
- }
326
- /** The function of a reference, such as `Page#h3`, once its code has loaded. */
327
- function loadedFunction(ref) {
328
- const [id, name] = ref.split("#");
329
- const module = modules.get(id);
330
- if (!module) return;
331
- return module[name];
332
- }
333
- //#endregion
334
335
  //#region src/runtime/client/scopes.ts
335
336
  let nextId = -1;
336
337
  /** Starts the IDs of the scopes that the client makes again, for a new page. */
@@ -380,6 +381,7 @@ function destroy(scope) {
380
381
  */
381
382
  function removeScope(scope) {
382
383
  if (scope.cleanups) for (const cleanup of scope.cleanups.values()) cleanup();
384
+ for (const stop of scope.stops ?? []) stop();
383
385
  const waiting = memoControllers.size + timers.size + loads.size + loadingSlots.size + (guesses?.map.size ?? 0);
384
386
  for (let slot = 0; waiting > 0 && slot < scope.s.length; slot++) {
385
387
  const key = `${scope.id}:${slot}`;
@@ -1186,15 +1188,34 @@ function send(bound, value) {
1186
1188
  }
1187
1189
  /** The setters that were given each element, so an update of a spread does not call them again. */
1188
1190
  const given = /* @__PURE__ */ new WeakMap();
1191
+ /**
1192
+ * A reference is new at each update, so its text is the key. The bound arguments of `$handler`
1193
+ * are not part of it, as `give` ignores them too.
1194
+ */
1195
+ function setterKey(bound) {
1196
+ let reference;
1197
+ if (bound instanceof FunctionReference) reference = bound;
1198
+ else if (typeof bound === "function") reference = handlerReferences.get(bound);
1199
+ return reference ? `${reference.scope}#${reference.ref}` : bound;
1200
+ }
1189
1201
  /** Calls the setter of a binding with an element, once for each element and setter. */
1190
1202
  function give$1(bound, element) {
1191
- const key = bound instanceof FunctionReference ? `${bound.scope}#${bound.ref}` : bound;
1203
+ const key = setterKey(bound);
1192
1204
  const seen = given.get(element) ?? /* @__PURE__ */ new Set();
1193
1205
  if (!seen.has(key)) {
1194
1206
  given.set(element, seen.add(key));
1195
1207
  send(bound, element);
1196
1208
  }
1197
1209
  }
1210
+ /**
1211
+ * Calls the setter that was given an element with `undefined`, so it can be given one again.
1212
+ * `next` is the setter that the element has now: the same setter stays.
1213
+ */
1214
+ function take$1(bound, element, next) {
1215
+ const key = setterKey(bound);
1216
+ if (next !== void 0 && setterKey(next) === key) return;
1217
+ if (given.get(element)?.delete(key)) send(bound, void 0);
1218
+ }
1198
1219
  /** Writes a slot, and updates what reads it. */
1199
1220
  function writeSlot(scope, slot, value) {
1200
1221
  if (!Object.is(scope.s[slot], value)) {
@@ -1463,6 +1484,18 @@ function memo(scope, slot, compute) {
1463
1484
  if (!Object.is(scope.s[slot], value)) set(scope, slot, value);
1464
1485
  else if (waited) trigger(scope, slot);
1465
1486
  }
1487
+ /**
1488
+ * Computes a memo of `$gate`. The new value replaces the old one only when the guard returns
1489
+ * true. Otherwise the memo gives its old value back, which the write skips. The first value
1490
+ * passes, and so does one after a held error.
1491
+ */
1492
+ function gate(scope, slot, guard, compute) {
1493
+ memo(scope, slot, () => {
1494
+ const next = gateValue(compute());
1495
+ const prev = scope.s[slot];
1496
+ return !(slot in scope.s) || prev instanceof MemoError || guard(prev, next) ? next : prev;
1497
+ });
1498
+ }
1466
1499
  /** True while a new value of a memo loads, or while the server still streams its value. */
1467
1500
  function pending(scope, slot) {
1468
1501
  return loadingSlots.has(`${scope.id}:${slot}`) || scope.s[slot] instanceof Promise && !scope.plain?.has(slot);
@@ -1580,6 +1613,7 @@ function pass(write) {
1580
1613
  return result;
1581
1614
  }
1582
1615
  setPass(pass);
1616
+ if (HAS_STORES) globalThis[Symbol.for("brumate.pass")] = pass;
1583
1617
  const dirty = /* @__PURE__ */ new Set();
1584
1618
  /** Computes the memos of a scope that wait, so code that reads one in a handler reads the new value. */
1585
1619
  function settle(scope) {
@@ -1781,28 +1815,20 @@ function noop$1() {}
1781
1815
  function findProvider(scope, key) {
1782
1816
  for (let current = scope.t ?? scope.p ?? scope.o; current; current = current.t ?? current.p ?? current.o) if (current.v && key in current.v) return current;
1783
1817
  }
1784
- /**
1785
- * Writes a provided value, and the slot of every scope that reads it from this provider. The
1786
- * provider can read the same context from above, which this does not write.
1787
- */
1788
- function updateContext(scope, context, value) {
1789
- scope.v ??= {};
1790
- scope.v[context.key] = value;
1791
- sendContext(() => {
1792
- for (const target of scopes.values()) {
1793
- const slot = target.x?.[context.key];
1794
- if (slot !== void 0 && findProvider(target, context.key) === scope) set(target, slot, value);
1795
- }
1796
- });
1797
- }
1798
1818
  /** Provides a value of a context to the scopes inside `scope`. */
1799
1819
  function provideValue(context, value, scope) {
1800
1820
  const target = resolveScope(scope);
1801
1821
  target.v ??= {};
1802
1822
  target.v[context.key] = value;
1803
1823
  }
1804
- /** Reads a context, and records its slot so that changes to the provided value reach it. */
1805
- function consumeContext(context, scope, slot) {
1824
+ /**
1825
+ * Reads a context. With a fallback, a read without a provider gives the fallback, or what it
1826
+ * returns when it is a function, in place of the error. With `slot`, which only `$route()` and
1827
+ * `$navigation()` pass, it records the slot so that `setGlobal` can write it. A provided value is
1828
+ * read once.
1829
+ */
1830
+ function consumeContext(context, scope, ...rest) {
1831
+ const [fallback, slot] = rest;
1806
1832
  const target = resolveScope(scope);
1807
1833
  if (slot !== void 0) {
1808
1834
  target.x ??= {};
@@ -1811,7 +1837,10 @@ function consumeContext(context, scope, slot) {
1811
1837
  const provider = findProvider(target, context.key);
1812
1838
  if (provider) return provider.v[context.key];
1813
1839
  if (HAS_ROUTES && context.key === "brumate.route" && !globals.has("brumate.route")) globals.set(ROUTE_KEY, currentRoute());
1814
- return globals.has(context.key) ? globals.get(context.key) : context.defaultValue;
1840
+ if (HAS_ROUTES && context.key === "brumate.navigation" && !globals.has("brumate.navigation")) globals.set(NAVIGATION_KEY, { pending: false });
1841
+ if (globals.has(context.key)) return globals.get(context.key);
1842
+ if (rest.length !== 1) throw missingContext(context.key);
1843
+ return typeof fallback === "function" ? fallback() : fallback;
1815
1844
  }
1816
1845
  /** The values of the contexts that the runtime provides to the whole page, by key. */
1817
1846
  const globals = /* @__PURE__ */ new Map();
@@ -1841,6 +1870,114 @@ function setGlobal(key, value) {
1841
1870
  function updateRoute() {
1842
1871
  setGlobal(ROUTE_KEY, currentRoute());
1843
1872
  }
1873
+ /** The store that a read finds from `scope` by the key of its context. */
1874
+ function findStore(scope, read) {
1875
+ const [key, , path, write] = read;
1876
+ const provider = findProvider(scope, key);
1877
+ if (!provider) throw missingContext(key);
1878
+ return findStored(provider.v[key], path, !!write, key);
1879
+ }
1880
+ /**
1881
+ * Subscribes a slot to a store, so a new value of the store writes the slot through the queued
1882
+ * send of contexts. With `write`, a write of the slot calls `set` of the store. With `repair`, a
1883
+ * value that changed since the server render is written now. The scope stops reading when it goes.
1884
+ */
1885
+ function subscribeSlot(scope, slot, found, repair, write) {
1886
+ const listener = (value) => {
1887
+ sendContext(() => writeSlot(scope, slot, value));
1888
+ };
1889
+ let bridged = false;
1890
+ let stop;
1891
+ if (HAS_BRIDGES && repair && isBridged(found)) {
1892
+ bridged = true;
1893
+ stop = found.subscribe(listener, scope.s[slot]);
1894
+ } else stop = found.subscribe(listener);
1895
+ (scope.stops ??= []).push(stop);
1896
+ if (write) (scope.b ??= {})[slot] = (value) => found.set(value);
1897
+ if (repair && !bridged && !sameData(found.get(), scope.s[slot])) sendContext(() => writeSlot(scope, slot, found.get()));
1898
+ }
1899
+ /** Links a read of `$store` that a scope resumed with. */
1900
+ function linkRead(scope, read) {
1901
+ subscribeSlot(scope, read[1], findStore(scope, read), true, read[3]);
1902
+ }
1903
+ /**
1904
+ * Subscribes the reads of `$store` of scopes that the page state added, and writes the value of
1905
+ * each store that changed since the server render, in one pass. A store that is not in a context
1906
+ * comes from its source in the exports `z` of the component, which runs once its code has loaded,
1907
+ * with the resumed values of the scope. Resume never calls `set`.
1908
+ */
1909
+ function resumeStoreReads(added, reads) {
1910
+ pass(() => {
1911
+ for (const scope of added) {
1912
+ const sourced = [];
1913
+ for (const read of reads(scope) ?? []) if (typeof read[0] === "string") linkRead(scope, read);
1914
+ else sourced.push(read);
1915
+ if (sourced.length === 0) continue;
1916
+ loadModule(findRoot(scope).m).then((module) => {
1917
+ if (scopes.get(scope.id) !== scope) return;
1918
+ pass(() => {
1919
+ for (const [link, slot, path, write] of sourced) {
1920
+ const found = findStored(module.z[link](scope), path, !!write);
1921
+ subscribeSlot(scope, slot, found, true, write);
1922
+ }
1923
+ });
1924
+ });
1925
+ }
1926
+ });
1927
+ }
1928
+ /** Links the stores of providers that the page state made to their scopes. See `madeStores`. */
1929
+ function linkMadeStores() {
1930
+ for (const made of madeStores) {
1931
+ const [id, site, slot] = made.o;
1932
+ const scope = scopes.get(id);
1933
+ if (!scope) {
1934
+ if (DEV) console.warn(`A store of the page state has no scope ${id} to belong to, so it is not linked`);
1935
+ continue;
1936
+ }
1937
+ (scope.st ??= {})[site] = made;
1938
+ if (slot === void 0) made.r = true;
1939
+ else made.w = (value) => set(scope, slot, value);
1940
+ }
1941
+ madeStores.length = 0;
1942
+ }
1943
+ /**
1944
+ * `$store(source)` in a component that the browser renders: the value, with its slot subscribed.
1945
+ * With no `link`, or with a `fallback`, the source is a context, whose provider gives the store, or
1946
+ * the fallback when none is above.
1947
+ */
1948
+ function consumeStore(source, scope, slot, path, link, write, fallback) {
1949
+ const target = resolveScope(scope);
1950
+ let value = source;
1951
+ let key;
1952
+ if (link === void 0 || fallback) {
1953
+ key = source.key;
1954
+ const provider = findProvider(target, key);
1955
+ if (provider) value = provider.v[key];
1956
+ else if (fallback) value = fallback();
1957
+ else throw missingContext(key);
1958
+ }
1959
+ const found = findStored(value, path, write, key);
1960
+ if (slot >= 0) subscribeSlot(target, slot, found, false, write);
1961
+ return found.get();
1962
+ }
1963
+ /** `$toStore(value)` in a provided value of a component that the browser renders. */
1964
+ function toStore(value, scope, site, slot) {
1965
+ const target = resolveScope(scope);
1966
+ const made = new Store(value);
1967
+ made.f = true;
1968
+ (target.st ??= {})[site] = made;
1969
+ if (slot === void 0) made.r = true;
1970
+ else made.w = (next) => set(target, slot, next);
1971
+ return made;
1972
+ }
1973
+ /** The update of `$toStore(value)`, in the binding stage: sends the new value to the readers. */
1974
+ function storeUpdate(scope, site, value) {
1975
+ const found = scope.st?.[site];
1976
+ if (!found) return;
1977
+ const first = found.f;
1978
+ found.f = void 0;
1979
+ if (!first || Object.is(found.v, value) || !sameData(found.v, value)) sendStore(found, value, true);
1980
+ }
1844
1981
  //#endregion
1845
1982
  //#region src/runtime/client/guesses.ts
1846
1983
  /** The values of promises that the server streamed, so a guess knows its source did not change. */
@@ -1944,16 +2081,22 @@ function callable(value, seen) {
1944
2081
  if (HAS_CHILDREN && value instanceof ChildrenReference) return new RenderedChildren(value.scope, value.ref, value.at, value.anchor);
1945
2082
  if (value instanceof FunctionReference) {
1946
2083
  if (HAS_TEMPLATES && isTemplate(value.ref)) return templateReference(value.ref, scopes.get(value.scope));
2084
+ let kept = scopes.get(value.scope);
1947
2085
  const handler = (...args) => {
2086
+ kept ??= scopes.get(value.scope);
1948
2087
  const fn = loadedFunction(value.ref);
1949
2088
  const all = [...value.args ?? [], ...args];
1950
- return fn ? fn(scopes.get(value.scope), ...all) : call(value.ref, scopes.get(value.scope), all);
2089
+ return fn ? fn(kept, ...all) : call(value.ref, kept, all);
1951
2090
  };
1952
2091
  handlerReferences.set(handler, value);
1953
2092
  return handler;
1954
2093
  }
1955
2094
  if (typeof value === "object" && value !== null && !seen.has(value)) {
1956
2095
  seen.add(value);
2096
+ if (HAS_STORES && isStore(value)) {
2097
+ value.v = callable(value.v, seen);
2098
+ return value;
2099
+ }
1957
2100
  const prototype = Object.getPrototypeOf(value);
1958
2101
  if (Array.isArray(value) || prototype === Object.prototype || prototype === null) {
1959
2102
  const record = value;
@@ -2050,12 +2193,12 @@ function action(name, id, method, result) {
2050
2193
  * call loads, so the core holds only this.
2051
2194
  */
2052
2195
  function submitAction(form, submitter) {
2053
- import("./rpc-C_znDZ_w.js").then((module) => module.sendAction(form, submitter));
2196
+ import("./rpc-B9EkaPdU.js").then((module) => module.sendAction(form, submitter));
2054
2197
  }
2055
2198
  /** Calls a server function. */
2056
2199
  async function rpc(id, args) {
2057
2200
  const signal = memoSignal();
2058
- return track(import("./rpc-C_znDZ_w.js").then((module) => module.call(rpcPrefix, id, args, signal)));
2201
+ return track(import("./rpc-B9EkaPdU.js").then((module) => module.call(rpcPrefix, id, args, signal)));
2059
2202
  }
2060
2203
  /** A function prop rendered on the client calls the parent's exported handler. */
2061
2204
  function handlerProp(value, ref, scope, bound = [], modifiers) {
@@ -2232,6 +2375,10 @@ function addScopes(state, root) {
2232
2375
  if (element) give$1(bound, element);
2233
2376
  }
2234
2377
  }
2378
+ if (HAS_STORES) {
2379
+ linkMadeStores();
2380
+ resumeStoreReads(added, (scope) => state[scope.id].z);
2381
+ }
2235
2382
  hooks.added?.(added);
2236
2383
  return added;
2237
2384
  }
@@ -2317,7 +2464,10 @@ function restoreRemounts(added) {
2317
2464
  */
2318
2465
  function leavePage() {
2319
2466
  dispose();
2320
- for (const scope of scopes.values()) for (const cleanup of scope.cleanups?.values() ?? []) cleanup();
2467
+ for (const scope of scopes.values()) {
2468
+ for (const cleanup of scope.cleanups?.values() ?? []) cleanup();
2469
+ for (const stop of scope.stops ?? []) stop();
2470
+ }
2321
2471
  scopes.clear();
2322
2472
  comments.clear();
2323
2473
  elements.clear();
@@ -2381,6 +2531,7 @@ function readFields() {
2381
2531
  /** Reads the page state. The loader calls it once, before the first handler. */
2382
2532
  function init(value) {
2383
2533
  configure(value);
2534
+ if (HAS_BRIDGES) setBridgeLoader(loadModule, failBoundary);
2384
2535
  if (value.serial) useSerialEntry(value.serial);
2385
2536
  const queue = stateQueue();
2386
2537
  queue.push = pushRecords;
@@ -2851,7 +3002,7 @@ function prop(scope, anchor, name, value) {
2851
3002
  const rest = module.props["..."];
2852
3003
  if (rest !== void 0) {
2853
3004
  const next = { ...get(child, rest) };
2854
- if (value === void 0) delete next[name];
3005
+ if (bound === void 0) delete next[name];
2855
3006
  else next[name] = bound;
2856
3007
  set(child, rest, next);
2857
3008
  }
@@ -3036,26 +3187,34 @@ function attr(scope, anchor, name, value) {
3036
3187
  }
3037
3188
  /** The attributes that the last update of a spread wrote, so the next one removes those it drops. */
3038
3189
  const spreadNames = /* @__PURE__ */ new WeakMap();
3190
+ /** The target of the `ref` that a spread gave each element to. */
3191
+ const forwarded = /* @__PURE__ */ new WeakMap();
3039
3192
  /**
3040
3193
  * Gives the element of a spread to the signal that a `ref` in its attributes is bound to, or to
3041
3194
  * the setter of the binding.
3042
3195
  */
3043
- function forwardRef(element, values) {
3196
+ function forwardRef(element, values, held) {
3197
+ if (!HAS_BINDINGS || !element) return;
3044
3198
  const bound = values.ref;
3045
- if (HAS_BINDINGS && element && isBinding(bound)) {
3046
- const { target } = bound;
3047
- if (isSlotReference(target)) {
3048
- const owner = scopes.get(target.scope);
3049
- if (owner) set(owner, target.slot, element);
3050
- } else give$1(target, element);
3051
- }
3199
+ const target = isBinding(bound) ? bound.target : void 0;
3200
+ let before = forwarded.get(element);
3201
+ if (!forwarded.has(element) && isBinding(held)) before = held.target;
3202
+ if (isSlotReference(before) && !(isSlotReference(target) && target.scope === before.scope && target.slot === before.slot)) {
3203
+ const owner = scopes.get(before.scope);
3204
+ if (owner) set(owner, before.slot, void 0);
3205
+ } else if (before && !isSlotReference(before)) take$1(before, element, target);
3206
+ forwarded.set(element, target);
3207
+ if (isSlotReference(target)) {
3208
+ const owner = scopes.get(target.scope);
3209
+ if (owner) set(owner, target.slot, element);
3210
+ } else if (target) give$1(target, element);
3052
3211
  }
3053
3212
  /** The element of a spread in markup that the browser renders goes to the `ref` of its attributes. */
3054
3213
  function restRef(values, scope, anchor, tag) {
3055
3214
  if (typeof tag !== "function") afterInsert.push(() => forwardRef(findElement(scope, anchor), values));
3056
3215
  return values;
3057
3216
  }
3058
- function attrs(scope, anchor, values, own = []) {
3217
+ function attrs(scope, anchor, values, own = [], held) {
3059
3218
  if (scope.c?.[anchor] !== void 0) {
3060
3219
  spreadProps(scope, anchor, values, []);
3061
3220
  return;
@@ -3076,7 +3235,7 @@ function attrs(scope, anchor, values, own = []) {
3076
3235
  for (const name of spreadNames.get(element) ?? []) if (!names.has(name)) setAttribute(element, name, void 0);
3077
3236
  spreadNames.set(element, names);
3078
3237
  updateSpreadEntries(element, values);
3079
- forwardRef(element, values);
3238
+ forwardRef(element, values, held);
3080
3239
  }
3081
3240
  }
3082
3241
  /**
@@ -3286,7 +3445,7 @@ function keepValue(id, anchor, place, value, at = id, append) {
3286
3445
  * The update of the spreads of an element whose values can be promises, as `attrs` writes them.
3287
3446
  * An attribute whose value is a promise keeps what it shows until the promise settles.
3288
3447
  */
3289
- function fillAttrs(scope, anchor, values, own) {
3448
+ function fillAttrs(scope, anchor, values, own, held) {
3290
3449
  const now = {};
3291
3450
  for (const [name, value] of Object.entries(values)) {
3292
3451
  const key = `${anchor} ${name}`;
@@ -3297,7 +3456,7 @@ function fillAttrs(scope, anchor, values, own) {
3297
3456
  now[name] = settled;
3298
3457
  });
3299
3458
  }
3300
- attrs(scope, anchor, now, own);
3459
+ attrs(scope, anchor, now, own, held);
3301
3460
  }
3302
3461
  /**
3303
3462
  * The spreads of an element of cloned markup whose values can be promises, as `setSpread` writes
@@ -4460,6 +4619,6 @@ const loader = {
4460
4619
  };
4461
4620
  function noop() {}
4462
4621
  //#endregion
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 };
4622
+ export { branchNodes as $, fail as $t, started as A, consumeContext as At, spreadProps as B, cells as Bt, fillAttrs as C, handle as Ct, keepValue as D, submitAction as Dt, fillValue as E, spread as Et, portalTo as F, toStore as Ft, elementAt as G, memo as Gt, componentNodes as H, gate as Ht, restRef as I, updateRoute as It, readMemo as J, set as Jt, foreignNodes as K, pending as Kt, text as L, asyncMemo as Lt, attr as M, provideValue as Mt, attrs as N, setGlobal as Nt, loading as O, guess as Ot, content as P, storeUpdate as Pt, appendText as Q, updated as Qt, writeText as R, binding as Rt, countLoads as S, action as St, fillSpread as T, rpc as Tt, dynamic as U, get as Ut, component as V, effect as Vt, dynamicNodes as W, isBound as Wt, setItem as X, unreadMemo as Xt, renderMemo as Y, timed as Yt, setSlots as Z, update as Zt, rekey as _, rpcPrefix as _n, init as _t, addPortal as a, createScope as an, listNodes as at, after as b, remount as bt, setVar as c, makeId as cn, putText as ct, windowList as d, sink as dn, setContent as dt, children as en, clone as et, windowStart as f, nameComment as fn, setOn as ft, offscreen as g, hooks as gn, forget as gt, held as h, build as hn, dispose as ht, addHead as i, afterInsert as in, keepText as it, wait as j, consumeStore as jt, reveal as k, track as kt, list as l, removeScope as ln, setAttr as lt, fill as m, DEVTOOLS as mn, template as mt, paramEffect as n, templateCall as nn, fillList as nt, addStyle as o, descendants as on, markBlock as ot, branch as p, loadModule as pn, setSpread as pt, place as q, resolve as qt, searchParam as r, title as rn, keep as rt, deferInBrowser as s, getScope as sn, nodes as st, loader as t, insert as tn, fillBranch as tt, toList as u, setOwner as un, setAttrText as ut, reset as v, scopes as vn, leavePage as vt, fillSettled as w, handlerProp as wt, attempt as x, removeRoot as xt, retag as y, skew as yn, leaveRoutes as yt, prop as z, bindings as zt };
4464
4623
 
4465
- //# sourceMappingURL=client-C3vRNuLi.js.map
4624
+ //# sourceMappingURL=client-DYIZ7BYK.js.map