brumate 0.7.2 → 0.8.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.
- package/dist/{boot-CMy0f_iC.d.ts → boot-DQuAhAd5.d.ts} +2 -2
- package/dist/cli.js +3 -2
- package/dist/cli.js.map +1 -1
- package/dist/{client-DnFF9_lv.d.ts → client-4eabQtYJ.d.ts} +38 -12
- package/dist/{client-COm1iA6w.js → client-CwVcmymi.js} +145 -28
- package/dist/client-CwVcmymi.js.map +1 -0
- package/dist/{defer-Cesb-k2Q.js → defer-BaXWydb0.js} +2 -2
- package/dist/{defer-Cesb-k2Q.js.map → defer-BaXWydb0.js.map} +1 -1
- package/dist/{devtools-C9IEkgc1.js → devtools-CMuj12yR.js} +257 -118
- package/dist/devtools-CMuj12yR.js.map +1 -0
- package/dist/devtools-calls-DGW6nLZ2.js +249 -0
- package/dist/devtools-calls-DGW6nLZ2.js.map +1 -0
- package/dist/devtools-panel-Cq8LpsyW.js +3978 -0
- package/dist/devtools-panel-Cq8LpsyW.js.map +1 -0
- package/dist/error-catalog-DakxjSgj.js +308 -0
- package/dist/error-catalog-DakxjSgj.js.map +1 -0
- package/dist/error-catalog-VxLbz-6p.js +1 -0
- package/dist/{files-BuQvpBwF.js → files-DXS8RAtZ.js} +2 -2
- package/dist/{files-BuQvpBwF.js.map → files-DXS8RAtZ.js.map} +1 -1
- package/dist/index.d.ts +73 -18
- package/dist/index.js +11 -1
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BSHv1_25.js → inspect-B5AoHh5O.js} +639 -412
- package/dist/inspect-B5AoHh5O.js.map +1 -0
- package/dist/{loader-CLKrJMqw.js → loader-CTeT6ie9.js} +4 -4
- package/dist/{loader-CLKrJMqw.js.map → loader-CTeT6ie9.js.map} +1 -1
- package/dist/{navigate-OHb0Uw1P.js → navigate-Bj73X4ZS.js} +22 -8
- package/dist/navigate-Bj73X4ZS.js.map +1 -0
- package/dist/{rpc-BAKbRWOT.js → rpc-kVB0Ujdx.js} +5 -4
- package/dist/rpc-kVB0Ujdx.js.map +1 -0
- package/dist/runtime/bundles.d.ts +3 -2
- package/dist/runtime/bundles.js +14 -3
- package/dist/runtime/bundles.js.map +1 -1
- package/dist/runtime/client.d.ts +2 -2
- package/dist/runtime/client.js +4 -3
- package/dist/runtime/devtools.d.ts +59 -1
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/hot.js +6 -2
- package/dist/runtime/hot.js.map +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +1 -1
- package/dist/runtime/server.js +3 -2
- package/dist/runtime/signals.d.ts +1 -1
- package/dist/runtime/static-loader.d.ts +2 -2
- package/dist/runtime/static-loader.js +1 -1
- package/dist/runtime/store.d.ts +2 -2
- package/dist/runtime/store.js +1 -1
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/search-params-Wg-0FsMj.js +148 -0
- package/dist/search-params-Wg-0FsMj.js.map +1 -0
- package/dist/{stream-RXLadXx1.js → serial-ioa17MuY.js} +67 -168
- package/dist/serial-ioa17MuY.js.map +1 -0
- package/dist/serial-ribg9NAj.js +1 -0
- package/dist/{server-BVObWh-w.js → server-BUuf7XPZ.js} +61 -16
- package/dist/server-BUuf7XPZ.js.map +1 -0
- package/dist/{server-0rS5vUW1.d.ts → server-DesBZv5g.d.ts} +8 -3
- package/dist/{search-params-C64liRBj.js → shared-CX_YacDm.js} +3 -148
- package/dist/shared-CX_YacDm.js.map +1 -0
- package/dist/{signals-DBnq9QRW.d.ts → signals-7VVD9C_H.d.ts} +2 -2
- package/dist/{static-loader-CxANokZ4.js → static-loader-BM0-wdIc.js} +2 -2
- package/dist/{static-loader-CxANokZ4.js.map → static-loader-BM0-wdIc.js.map} +1 -1
- package/dist/{static-loader-BYbXVJDY.d.ts → static-loader-BSAyFqG0.d.ts} +2 -2
- package/dist/{store-xlTzAM_r.d.ts → store-9_oa0HG1.d.ts} +15 -2
- package/dist/{store-BIBAYZo-.js → store-Cy4EEyZ7.js} +148 -2
- package/dist/store-Cy4EEyZ7.js.map +1 -0
- package/dist/stream-read-BTsYstJY.js +22 -0
- package/dist/stream-read-BTsYstJY.js.map +1 -0
- package/dist/stream-read-Dek3HnqO.js +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +37 -5
- package/dist/vite.js.map +1 -1
- package/package.json +7 -4
- package/skills/brumate/SKILL.md +6 -2
- package/skills/brumate/references/errors.md +21 -2
- package/skills/brumate/references/state.md +31 -0
- package/skills/brumate/references/syntax.md +45 -1
- package/dist/client-COm1iA6w.js.map +0 -1
- package/dist/devtools-C9IEkgc1.js.map +0 -1
- package/dist/devtools-panel-Doit__YG.js +0 -2018
- package/dist/devtools-panel-Doit__YG.js.map +0 -1
- package/dist/inspect-BSHv1_25.js.map +0 -1
- package/dist/navigate-OHb0Uw1P.js.map +0 -1
- package/dist/rpc-BAKbRWOT.js.map +0 -1
- package/dist/search-params-C64liRBj.js.map +0 -1
- package/dist/server-BVObWh-w.js.map +0 -1
- package/dist/store-BIBAYZo-.js.map +0 -1
- package/dist/stream-RXLadXx1.js.map +0 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { t as Context$1 } from "./context-BNgBXVUQ.js";
|
|
2
2
|
import { a as PageState, c as ScopeId, i as PackedState, l as ScopeState, m as Raw, n as ElementReference, o as PropSink, t as Binding } from "./shared-CuJdWifz.js";
|
|
3
|
-
import { a as Store } from "./store-
|
|
4
|
-
import { M as SearchParamOptions } from "./signals-
|
|
3
|
+
import { a as Store } from "./store-9_oa0HG1.js";
|
|
4
|
+
import { M as SearchParamOptions } from "./signals-7VVD9C_H.js";
|
|
5
5
|
import { t as StandardSchemaV1 } from "./standard-schema-BNY82yX3.js";
|
|
6
6
|
import { f as Intent, v as SubmissionResult } from "./forms-j1xPAR14.js";
|
|
7
7
|
//#region src/runtime/cookies.d.ts
|
|
@@ -154,6 +154,11 @@ declare class RequestEvent {
|
|
|
154
154
|
readonly address?: string;
|
|
155
155
|
/** True while the build prerenders the page. */
|
|
156
156
|
readonly prerender: boolean;
|
|
157
|
+
/**
|
|
158
|
+
* The Content Security Policy nonce of the render, from its `nonce` option. Undefined without
|
|
159
|
+
* one. A component that writes an inline script with `raw()` gives it this nonce.
|
|
160
|
+
*/
|
|
161
|
+
nonce?: string;
|
|
157
162
|
/**
|
|
158
163
|
* The pattern of the route files that matched the path, such as
|
|
159
164
|
* `/todos/[id]`. `handleRoute` sets it. Undefined for a path that no route
|
|
@@ -1644,4 +1649,4 @@ declare function handleRoute(tree: RouteNode, request: Request, options?: RouteO
|
|
|
1644
1649
|
declare function spread(attributes: Record<string, unknown>, on?: string[], names?: boolean): string | Promise<string>;
|
|
1645
1650
|
//#endregion
|
|
1646
1651
|
export { idempotent as $, defineMiddleware as $t, handleRoute as A, safeParse as At, renderToStream as B, searchParam as Bt, attribute as C, parseSubmission as Ct, component as D, fieldErrors as Dt, children as E, ValidationIssue as Et, memo as F, MiddlewareLoader as Ft, start as G, RequestEvent as Gt, settled as H, Locals as Ht, packState as I, RouteMatch as It, streamParts as J, ServerError as Jt, stateScript as K, RequestEventOptions as Kt, read as L, RouteNode as Lt, insert as M, Handler as Mt, isCrossSite as N, Loader as Nt, dynamic as O, parse as Ot, lazy as P, Middleware as Pt, IdempotentOptions as Q, dedupe as Qt, ready as R, RouteView as Rt, actionResult as S, SuccessfulSubmission as St, caught as T, ValidationError as Tt, spacerTag as U, Redirect as Ut, setClientBundles as V, EntryMiddleware as Vt, spread as W, RequestCall as Wt, wait as X, ServerErrorInfo as Xt, streamState as Y, ServerErrorHandler as Yt, waitAll as Z, ServerErrorKind as Zt, ScopeEntry as _, FailedSubmission as _t, DocumentOptions as a, Session as an, setCacheStore as at, StreamOptions as b, Submission as bt, Mark as c, parseCookies as cn, RateLimitConfig as ct, PageCache as d, RateLimitOptions as dt, getEvent as en, CacheStore as et, RenderOptions as f, RateLimitStore as ft, RouteOptions as g, rateLimit as gt, RevealOrder as h, configureRateLimit as ht, DeferTarget as i, CookieOptions as in, revalidate as it, inlineBodies as j, EndpointLoader as jt, handleRequest as k, parseForm as kt, Memo as l, serializeCookie as ln, RateLimitError as lt, RequestOptions as m, clientAddress as mt, Component as n, redirect as nn, cached as nt, ItemSource as o, SessionOptions as on, storageStore as ot, RenderResult as p, Window as pt, stateValue as q, RequestKind as qt, Context as r, withEvent as rn, memoryStore as rt, Lazy as s, createSession as sn, RateLimit as st, ClientBundles as t, isRedirect as tn, CachedOptions as tt, NotReady as u, toNodeHeaders as un, RateLimitMiddleware as ut, StateAttributes as v, IntentSubmission as vt, binding as w, ParseResult as wt, action as x, SubmissionOptions as xt, StateMap as y, ReplyOptions as yt, render as z, matchRoute as zt };
|
|
1647
|
-
//# sourceMappingURL=server-
|
|
1652
|
+
//# sourceMappingURL=server-DesBZv5g.d.ts.map
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import { b as ownValue, t as Internal, x as raw } from "./html-Cf5uKhLs.js";
|
|
2
2
|
import { a as HAS_CHILDREN, h as HAS_STORES, i as HAS_BRIDGES, n as HAS_BINDINGS } from "./features-DwMYKBIC.js";
|
|
3
|
-
import { n as Store, t as Bridged } from "./store-
|
|
4
|
-
import { o as routeContext } from "./context-CU4Fpn5a.js";
|
|
3
|
+
import { n as Store, t as Bridged } from "./store-Cy4EEyZ7.js";
|
|
5
4
|
//#region src/runtime/shared.ts
|
|
6
5
|
/** The plugins of values of the app, by tag, which the entry `src/serial.ts` exports. */
|
|
7
6
|
const valuePlugins = /* @__PURE__ */ new Map();
|
|
@@ -302,150 +301,6 @@ const SCOPE_IDS = {
|
|
|
302
301
|
holders: [Binding]
|
|
303
302
|
};
|
|
304
303
|
//#endregion
|
|
305
|
-
|
|
306
|
-
const DRAFT = Symbol("brumate.draft");
|
|
307
|
-
/** Plain objects and arrays can be drafted. Other values, such as `Map`, are used as they are. */
|
|
308
|
-
function isDraftable(value) {
|
|
309
|
-
if (typeof value !== "object" || value === null) return false;
|
|
310
|
-
if (Array.isArray(value)) return true;
|
|
311
|
-
const prototype = Object.getPrototypeOf(value);
|
|
312
|
-
return prototype === Object.prototype || prototype === null;
|
|
313
|
-
}
|
|
314
|
-
function latest(state) {
|
|
315
|
-
return state.copy ?? state.base;
|
|
316
|
-
}
|
|
317
|
-
/** Copies an object and its parents on the first change. */
|
|
318
|
-
function prepare(state) {
|
|
319
|
-
for (let current = state; current && !current.modified; current = current.parent) {
|
|
320
|
-
current.modified = true;
|
|
321
|
-
current.copy = Array.isArray(current.base) ? [...current.base] : { ...current.base };
|
|
322
|
-
}
|
|
323
|
-
return state.copy;
|
|
324
|
-
}
|
|
325
|
-
function getDraftState(value) {
|
|
326
|
-
return typeof value === "object" && value !== null ? value[DRAFT] : void 0;
|
|
327
|
-
}
|
|
328
|
-
function createDraft(base, parent) {
|
|
329
|
-
const state = {
|
|
330
|
-
base,
|
|
331
|
-
copy: void 0,
|
|
332
|
-
parent,
|
|
333
|
-
children: /* @__PURE__ */ new Map(),
|
|
334
|
-
modified: false
|
|
335
|
-
};
|
|
336
|
-
const target = Array.isArray(base) ? [] : Object.create(Object.getPrototypeOf(base));
|
|
337
|
-
state.proxy = new Proxy(target, {
|
|
338
|
-
get(_, key) {
|
|
339
|
-
if (key === DRAFT) return state;
|
|
340
|
-
const source = latest(state);
|
|
341
|
-
const value = source[key];
|
|
342
|
-
if (!Object.hasOwn(source, key) || !isDraftable(value) || value !== state.base[key]) return value;
|
|
343
|
-
let child = state.children.get(key);
|
|
344
|
-
if (!child) {
|
|
345
|
-
child = createDraft(value, state);
|
|
346
|
-
state.children.set(key, child);
|
|
347
|
-
}
|
|
348
|
-
return child.proxy;
|
|
349
|
-
},
|
|
350
|
-
set(_, key, value) {
|
|
351
|
-
const source = latest(state);
|
|
352
|
-
if (Object.is(source[key], value) && Object.hasOwn(source, key)) return true;
|
|
353
|
-
prepare(state)[key] = value;
|
|
354
|
-
state.children.delete(key);
|
|
355
|
-
return true;
|
|
356
|
-
},
|
|
357
|
-
deleteProperty(_, key) {
|
|
358
|
-
if (Object.hasOwn(latest(state), key)) {
|
|
359
|
-
delete prepare(state)[key];
|
|
360
|
-
state.children.delete(key);
|
|
361
|
-
}
|
|
362
|
-
return true;
|
|
363
|
-
},
|
|
364
|
-
has(_, key) {
|
|
365
|
-
return key in latest(state);
|
|
366
|
-
},
|
|
367
|
-
ownKeys() {
|
|
368
|
-
return Reflect.ownKeys(latest(state));
|
|
369
|
-
},
|
|
370
|
-
getOwnPropertyDescriptor(_, key) {
|
|
371
|
-
const descriptor = Reflect.getOwnPropertyDescriptor(latest(state), key);
|
|
372
|
-
if (descriptor && key !== "length") {
|
|
373
|
-
descriptor.configurable = true;
|
|
374
|
-
descriptor.writable = true;
|
|
375
|
-
}
|
|
376
|
-
return descriptor;
|
|
377
|
-
},
|
|
378
|
-
defineProperty(_, key, descriptor) {
|
|
379
|
-
prepare(state);
|
|
380
|
-
return Reflect.defineProperty(state.copy, key, descriptor);
|
|
381
|
-
}
|
|
382
|
-
});
|
|
383
|
-
return state;
|
|
384
|
-
}
|
|
385
|
-
/** Returns the final value of a draft: the base if nothing changed, or a new object that shares what did not. */
|
|
386
|
-
function finalize(state) {
|
|
387
|
-
if (!state.modified) {
|
|
388
|
-
for (const child of state.children.values()) if (child.modified) {
|
|
389
|
-
prepare(state);
|
|
390
|
-
break;
|
|
391
|
-
}
|
|
392
|
-
if (!state.modified) return state.base;
|
|
393
|
-
}
|
|
394
|
-
const copy = state.copy;
|
|
395
|
-
for (const [key, child] of state.children) if (copy[key] === child.base) copy[key] = finalize(child);
|
|
396
|
-
for (const key of Reflect.ownKeys(copy)) {
|
|
397
|
-
const draft = getDraftState(copy[key]);
|
|
398
|
-
if (draft) copy[key] = finalize(draft);
|
|
399
|
-
}
|
|
400
|
-
return copy;
|
|
401
|
-
}
|
|
402
|
-
/**
|
|
403
|
-
* Returns a changed copy of a value. The recipe changes a draft as if it
|
|
404
|
-
* were the value. Objects that it does not change keep their identity, and
|
|
405
|
-
* if it changes nothing, the value itself is returned. A recipe can also
|
|
406
|
-
* return a new value. Only plain objects and arrays are drafted.
|
|
407
|
-
*/
|
|
408
|
-
function produce(base, recipe) {
|
|
409
|
-
if (!isDraftable(base)) {
|
|
410
|
-
const result = recipe(base);
|
|
411
|
-
return result === void 0 ? base : result;
|
|
412
|
-
}
|
|
413
|
-
const state = createDraft(base, void 0);
|
|
414
|
-
const result = recipe(state.proxy);
|
|
415
|
-
if (result !== void 0 && result !== state.proxy) return resolve(result, /* @__PURE__ */ new Set());
|
|
416
|
-
return finalize(state);
|
|
417
|
-
}
|
|
418
|
-
/** Replaces the drafts in a value that a recipe returns, such as the result of `draft.filter(…)`. */
|
|
419
|
-
function resolve(value, seen) {
|
|
420
|
-
const draft = getDraftState(value);
|
|
421
|
-
if (draft) return finalize(draft);
|
|
422
|
-
if (!isDraftable(value) || seen.has(value)) return value;
|
|
423
|
-
seen.add(value);
|
|
424
|
-
for (const key of Reflect.ownKeys(value)) value[key] = resolve(value[key], seen);
|
|
425
|
-
return value;
|
|
426
|
-
}
|
|
427
|
-
//#endregion
|
|
428
|
-
//#region src/runtime/search-params.ts
|
|
429
|
-
/** The value of a parameter in a query string: its text parsed, or the default when it is absent. */
|
|
430
|
-
function readParam(search, name, options) {
|
|
431
|
-
const text = search.get(name);
|
|
432
|
-
if (text === null) return options?.default ?? null;
|
|
433
|
-
return options?.parse ? options.parse(text) : text;
|
|
434
|
-
}
|
|
435
|
-
/** The text of a value in the URL, or null for the default, which leaves the parameter out. */
|
|
436
|
-
function writeParam(value, options) {
|
|
437
|
-
const own = formatParam(value, options);
|
|
438
|
-
return own === formatParam(options?.default, options) ? null : own;
|
|
439
|
-
}
|
|
440
|
-
function formatParam(value, options) {
|
|
441
|
-
if (value === null || value === void 0) return null;
|
|
442
|
-
return options?.serialize ? options.serialize(value) : String(value);
|
|
443
|
-
}
|
|
444
|
-
/** `$searchParam` on the server: the parameter of the request's URL. */
|
|
445
|
-
function searchParam(context, name, options) {
|
|
446
|
-
return readParam(context.consume(routeContext, 0).search, name, options);
|
|
447
|
-
}
|
|
448
|
-
//#endregion
|
|
449
|
-
export { onSerialOptions as C, unbind as D, stateValues as E, useSerialEntry as O, mergeHandlers as S, parseId as T, isAsyncIterable as _, Binding as a, isSlotReference as b, ElementReference as c, PARTS as d, PropPromise as f, gateValue as g, addEntryHandlers as h, produce as i, FunctionReference as l, SlotReference as m, searchParam as n, CHILDREN_REF as o, SCOPE_IDS as p, writeParam as r, ChildrenReference as s, readParam as t, MemoError as u, isBinding as v, onValuePlugin as w, madeStores as x, isPropWrapper as y };
|
|
304
|
+
export { unbind as C, stateValues as S, madeStores as _, FunctionReference as a, onValuePlugin as b, PropPromise as c, addEntryHandlers as d, gateValue as f, isSlotReference as g, isPropWrapper as h, ElementReference as i, SCOPE_IDS as l, isBinding as m, CHILDREN_REF as n, MemoError as o, isAsyncIterable as p, ChildrenReference as r, PARTS as s, Binding as t, SlotReference as u, mergeHandlers as v, useSerialEntry as w, parseId as x, onSerialOptions as y };
|
|
450
305
|
|
|
451
|
-
//# sourceMappingURL=
|
|
306
|
+
//# sourceMappingURL=shared-CX_YacDm.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared-CX_YacDm.js","names":[],"sources":["../src/runtime/shared.ts"],"sourcesContent":["// Values and types that the server and the browser share. It does not import\n// seroval, so the core, which reads the page state without it, stays small.\n// The plugins that write and read these values are in `serial.ts`.\n\nimport { HAS_BINDINGS, HAS_BRIDGES, HAS_CHILDREN, HAS_STORES } from './features.ts';\nimport { Internal, ownValue, raw } from './html.ts';\nimport type { Raw } from './html.ts';\nimport { Bridged, Store } from './store.ts';\nimport type { SerialEntry, ValuePlugin } from './values.ts';\n\n/** The plugins of values of the app, by tag, which the entry `src/serial.ts` exports. */\nconst valuePlugins = new Map<string, ValuePlugin>();\nconst pluginListeners: ((plugin: ValuePlugin) => void)[] = [];\n/** The options of the entry, which the serializer reads when it loads. */\nlet entryOptions: Omit<SerialEntry, 'plugins'> = {};\nconst optionListeners: ((options: Omit<SerialEntry, 'plugins'>) => void)[] = [];\n\n/**\n * Takes the exports of the serial entry: its plugins and the options that it\n * changes. The server and the loader call it before the first value is\n * written or read.\n */\nexport function useSerialEntry(entry: SerialEntry): void {\n const { plugins = [], ...options } = entry;\n if (options.disabledFeatures !== undefined || options.depthLimit !== undefined) {\n entryOptions = options;\n for (const listener of optionListeners) {\n listener(options);\n }\n }\n registerValues(plugins);\n}\n\n/** Calls `listener` with the options of the entry, now and when they change. */\nexport function onSerialOptions(listener: (options: Omit<SerialEntry, 'plugins'>) => void): void {\n optionListeners.push(listener);\n listener(entryOptions);\n}\n\n/** Adds plugins of values of the app. */\nfunction registerValues(plugins: readonly ValuePlugin[]): void {\n for (const plugin of plugins) {\n if (valuePlugins.get(plugin.tag) === plugin) {\n continue;\n }\n valuePlugins.set(plugin.tag, plugin);\n for (const listener of pluginListeners) {\n listener(plugin);\n }\n }\n}\n\n/** Calls `listener` for each plugin of the app, those added so far and those added later. */\nexport function onValuePlugin(listener: (plugin: ValuePlugin) => void): void {\n pluginListeners.push(listener);\n for (const plugin of valuePlugins.values()) {\n listener(plugin);\n }\n}\n\n/**\n * The ID of a scope or of a `#loading` boundary. The rest of the page numbers\n * its scopes from the base of the render, such as `3`. A `#loading` body\n * numbers its own from 0 after the ID of its boundary and a dot, such as\n * `5.0` and `5.1`, so its IDs do not depend on when its data arrives.\n */\nexport type ScopeId = number | string;\n\n/** Reads a scope or boundary ID from markup. */\nexport function parseId(text: string): ScopeId {\n return /^-?\\d+$/.test(text) ? Number(text) : text;\n}\n\n/** Adds a number to an ID. An ID inside a boundary moves with its boundary. */\nexport function shiftId(id: ScopeId, by: number): ScopeId {\n if (typeof id === 'number') {\n return id + by;\n }\n const dot = id.indexOf('.');\n return `${Number(id.slice(0, dot)) + by}${id.slice(dot)}`;\n}\n\n/** An element that the server rendered. The client finds it by its anchor. */\nexport class ElementReference {\n readonly scope: ScopeId;\n readonly anchor: number;\n\n constructor(scope: ScopeId, anchor: number) {\n this.scope = scope;\n this.anchor = anchor;\n }\n}\n\n/** A client function: an export of a client module, and the scope it reads. */\n/** The key of the reference of children on the server, which the page state sends. */\nexport const CHILDREN_REF: unique symbol = Symbol.for('brumate.children') as never;\n\n/**\n * The children of a component in the page state: the export that renders them in the browser,\n * such as `Page_1a2b#n0`, and the scope that they were written in. Each insert renders them\n * again, with new scopes, as the body of a block does.\n */\nexport class ChildrenReference {\n readonly ref: string;\n readonly scope: ScopeId;\n /** The scope and the anchor of the insert where the server rendered them, if it did. */\n at: ScopeId | undefined;\n anchor: number | undefined;\n\n constructor(ref: string, scope: ScopeId, at?: ScopeId, anchor?: number) {\n this.ref = ref;\n this.scope = scope;\n this.at = at;\n this.anchor = anchor;\n }\n}\n\nexport class FunctionReference {\n /** `<component id>#<export name>`. */\n readonly ref: string;\n readonly scope: ScopeId;\n /** The arguments of a handler that `$handler` made, which come before the event. */\n readonly args: unknown[] | undefined;\n /** The modifiers of the wrappers of a handler, such as `prevent`, for the `b-on` of a spread. */\n readonly modifiers: string[] | undefined;\n\n constructor(ref: string, scope: ScopeId, args?: unknown[] | null, modifiers?: string[]) {\n this.ref = ref;\n this.scope = scope;\n this.args = args ?? undefined;\n this.modifiers = modifiers;\n }\n}\n\n/** The handlers that a merged handler calls, in order. A symbol of the registry. */\nexport const PARTS: unique symbol = Symbol.for('brumate.parts');\n\n// oxlint-disable-next-line typescript/no-explicit-any -- Handlers take any event.\ntype Handler = (...args: any[]) => unknown;\n\n/**\n * One handler that calls each of `handlers` in order, with the same arguments. A prop holds one\n * handler per event, and the browser takes one `b-on` entry for each part. Merged handlers in\n * `handlers` give their parts, so the list stays flat.\n */\nexport function mergeHandlers(handlers: Handler[]): Handler {\n const parts: Handler[] = [];\n for (const handler of handlers) {\n parts.push(...((handler as { [PARTS]?: Handler[] })[PARTS] ?? [handler]));\n }\n return Object.assign(\n (...args: unknown[]): void => {\n for (const part of parts) {\n part(...args);\n }\n },\n { [PARTS]: parts },\n );\n}\n\n/**\n * Adds a handler prop, such as `onClick`, for each entry of the scoped `b-on` of a dynamic tag\n * that names a component. `make` makes the handler of a reference. A handler of the same event in\n * `props`, such as a rest prop passed on, is merged with it and runs first.\n */\nexport function addEntryHandlers(\n props: Record<string, unknown>,\n entries: unknown,\n scope: ScopeId | undefined,\n make: (reference: FunctionReference) => Handler,\n): void {\n for (const entry of (ownValue('b-on', entries) as string | undefined)?.split(' ') ?? []) {\n const [event, target] = entry.split('=') as [string, string];\n const [name, ...modifiers] = event.split(':') as [string, ...string[]];\n const [ref, at] = target.split('@') as [string, string?];\n const handler = make(\n new FunctionReference(\n ref,\n /^\\d+$/.test(at ?? '') ? Number(at) : (at ?? scope!),\n undefined,\n modifiers.length > 0 ? modifiers : undefined,\n ),\n );\n const key = `on${name[0]!.toUpperCase()}${name.slice(1)}`;\n const before = props[key];\n props[key] =\n typeof before === 'function' ? mergeHandlers([before as Handler, handler]) : handler;\n }\n}\n\n// Brands of bindings and slot references, under keys of the registry, so two copies of the\n// runtime, such as a component's and the render context's, know each other's.\nconst BINDING = Symbol.for('brumate.binding');\nconst SLOT = Symbol.for('brumate.slot');\n\n/** A slot of a scope, which a write of a bound prop goes to. */\nexport class SlotReference {\n readonly scope: ScopeId;\n readonly slot: number;\n\n constructor(scope: ScopeId, slot: number) {\n this.scope = scope;\n this.slot = slot;\n }\n}\n\n(SlotReference.prototype as unknown as Record<symbol, boolean>)[SLOT] = true;\n\n/** True for a slot reference of any copy of the runtime. */\nexport function isSlotReference(value: unknown): value is SlotReference {\n return typeof value === 'object' && value !== null && SLOT in value;\n}\n\n/** True for a binding of any copy of the runtime. */\nexport function isBinding(value: unknown): value is Binding {\n return typeof value === 'object' && value !== null && BINDING in value;\n}\n\n/**\n * What `$bind(name)` passes a child: the value of the name, and its slot,\n * which the child's writes of the prop go to.\n */\nexport class Binding<T = unknown> {\n readonly value: T;\n readonly ref: SlotReference;\n /** The function of `$bind(name, fn)`, which a write calls in place of writing the slot. */\n readonly set: unknown;\n\n constructor(value: T, ref: SlotReference, set?: unknown) {\n this.value = value;\n this.ref = ref;\n this.set = set;\n }\n\n /** What a write of the bound prop goes to: the setter, or else the slot. */\n get target(): unknown {\n return this.set ?? this.ref;\n }\n}\n\n(Binding.prototype as unknown as Record<symbol, boolean>)[BINDING] = true;\n\n/**\n * The props that a component destructures, with the values of their\n * bindings. `names` are the props that it destructures by name: the others,\n * which a rest prop holds, keep their bindings, so a spread passes them on.\n * Without `names`, every binding gives its value. `omit` are props that a rest\n * leaves out, because another `$props()` call of the component names them.\n */\nexport function unbind(\n props: Record<string, unknown>,\n names?: readonly string[],\n omit?: readonly string[],\n sink?: PropSink,\n): Record<string, unknown> {\n let result: Record<string, unknown> | undefined;\n // The props that another `$props()` call of the component names, which a rest leaves out.\n if (omit) {\n result = { ...props };\n for (const key of omit) {\n delete result[key];\n }\n props = result;\n }\n for (const key of names ?? Object.keys(props)) {\n const value = props[key];\n if (sink && value instanceof Promise) {\n (sink.props ??= []).push(value);\n }\n if (isBinding(value)) {\n result ??= { ...props };\n result[key] = value.value;\n }\n }\n return result ?? props;\n}\n\n/**\n * What the slot of a memo holds while its compute throws or its promise rejects, and a memo that\n * failed on the server holds from the page state. Each read of the slot throws the error.\n */\nexport class MemoError {\n readonly error: unknown;\n\n constructor(error: unknown) {\n this.error = error;\n }\n}\n\n/**\n * A promise that a parent passed as a prop. It stays a promise in the child, so `await` and\n * `then` work on it. The page state holds it in this wrapper, so the browser knows the slot is\n * a prop and does not replace the promise with its value, as it does for a memo that streams.\n */\nexport class PropPromise {\n readonly promise: Promise<unknown>;\n\n constructor(promise: Promise<unknown>) {\n this.promise = promise;\n (this as Record<symbol, unknown>)[PROP_WRAPPER] = true;\n }\n}\n\n// Symbol.for, so copies of the runtime agree on the marks.\nconst PROP_WRAPPER = Symbol.for('brumate.propWrapper');\n\n/** A scope that collects the promise props that its component receives. */\nexport interface PropSink {\n props?: Promise<unknown>[] | undefined;\n}\n\n/** True for the wrapper that holds a promise prop in the page state. */\nexport function isPropWrapper(value: unknown): value is PropPromise {\n return typeof value === 'object' && value !== null && PROP_WRAPPER in value;\n}\n\n/** A component, which the compiler marks with its ID. */\nexport type ComponentValue = ((...args: never[]) => unknown) & { brumateId: string };\n\n/** The value of a feature that the build turned off, which no page state of it holds. */\nfunction unused(): never {\n throw new Error('The page state holds a value of a feature that no component of the build uses');\n}\n\n/**\n * Makes the values of brumate's plugins. A state record calls them as `$b`,\n * with one letter each, and the plugins read nodes of server function calls\n * with them too, so both give the same values.\n */\nexport const stateValues: {\n /** An element that the server rendered, by its scope and anchor. */\n e: (scope: ScopeId, anchor: number) => ElementReference;\n /** A client function, by its reference and scope. */\n f: (\n ref: string,\n scope: ScopeId,\n args?: unknown[] | null,\n modifiers?: string[],\n ) => FunctionReference;\n /** The parts of a merged handler, which `callable` makes one handler of. */\n m: (parts: FunctionReference[]) => FunctionReference[];\n /** A value of an attribute that brumate writes, such as the scope attribute of a style. */\n i: (value: unknown) => Internal;\n /** HTML that the client may insert again. */\n r: (html: string) => Raw;\n /** Children, by the export that renders them and their scope. */\n n: (ref: string, scope: ScopeId, at?: ScopeId, anchor?: number) => ChildrenReference;\n /**\n * A component, such as the value of a dynamic tag. The client gets a\n * function with the same ID that renders nothing. The client code that\n * changes the value uses the component's render module instead.\n */\n c: (id: string) => ComponentValue;\n /** A slot of a scope, which a bound prop writes. */\n l: (scope: ScopeId, slot: number) => SlotReference;\n /** A binding that a rest prop holds, with its value and its slot. */\n b: (value: unknown, scope: ScopeId, slot: number, set?: unknown) => Binding;\n /** A promise prop. See `PropPromise`. */\n q: (promise: Promise<unknown>) => PropPromise;\n /** The error of a memo that failed on the server. See `MemoError`. */\n x: (error: unknown) => MemoError;\n /** A value of the app, which a plugin of the entry makes from its data. */\n u: (tag: string, data: unknown) => unknown;\n /** A store, with its value, and where `$toStore` made it. See `madeStores`. */\n s: (value: unknown, scope?: ScopeId, site?: number, slot?: number) => Store<unknown>;\n /** A store of `bridge()`, with the data of the server and the name of its bridge. */\n g: (snapshot: unknown, id: string, writable?: number) => Bridged<unknown, unknown>;\n} = {\n e: (scope, anchor) => new ElementReference(scope, anchor),\n f: (ref, scope, args, modifiers) => new FunctionReference(ref, scope, args, modifiers),\n m: (parts) => Object.assign(parts, { [PARTS]: parts }),\n i: (value) => new Internal(value),\n r: raw,\n n: HAS_CHILDREN\n ? (ref, scope, at, anchor) => new ChildrenReference(ref, scope, at, anchor)\n : unused,\n c: (id) => Object.assign(() => '', { brumateId: id }),\n l: (scope, slot) => new SlotReference(scope, slot),\n b: HAS_BINDINGS\n ? (value, scope, slot, set) => new Binding(value, new SlotReference(scope, slot), set)\n : unused,\n q: (promise) => new PropPromise(promise),\n x: (error) => new MemoError(error),\n u: (tag, data) => {\n const plugin = valuePlugins.get(tag);\n if (!plugin) {\n throw new Error(\n `No plugin reads the value \"${tag}\". Export it in the plugins of the serial entry, src/serial.ts`,\n );\n }\n return plugin.fromData(data);\n },\n s: HAS_STORES\n ? (value, scope, site, slot) => {\n const made = new Store(value);\n if (scope !== undefined) {\n made.o = slot === undefined ? [scope, site!] : [scope, site!, slot];\n madeStores.push(made);\n }\n return made;\n }\n : unused,\n g: HAS_BRIDGES\n ? (snapshot, id, writable) =>\n new Bridged<unknown, unknown>(undefined, undefined, id, snapshot, writable === 1)\n : unused,\n};\n\n/**\n * The stores of providers that the page state made, until the core links them to their scopes:\n * a store of `$toStore(signal)` writes the signal of its provider.\n */\nexport const madeStores: Store<unknown>[] = [];\n\n/** The value of a `$gate`, which cannot be a promise or a stream. A throw is held like a memo error. */\nexport function gateValue<T>(value: T): T {\n if (\n (value !== null &&\n typeof value === 'object' &&\n typeof (value as { then?: unknown }).then === 'function') ||\n isAsyncIterable(value)\n ) {\n throw new TypeError(\n 'The value of $gate is a promise or a stream. Use $memo for a value that loads',\n );\n }\n return value;\n}\n\n/** True for a value that `for await` reads, such as the result of an async generator. */\nexport function isAsyncIterable(value: unknown): value is AsyncIterable<unknown> {\n return (\n value !== null &&\n typeof value === 'object' &&\n typeof (value as AsyncIterable<unknown>)[Symbol.asyncIterator] === 'function'\n );\n}\n\n/**\n * A read of `$store`: the key of the context, or the index of the source in the exports `z` of\n * the component; the slot; the key of the store in the value of the context; and 1 when `let`\n * writes the store.\n */\nexport type StoreRead = [from: string | number, slot: number, path?: string, write?: 1];\n\n/** The state of one scope in the page. */\nexport interface ScopeState {\n /** The scope's ID in the compiled component. */\n k?: number;\n /** The ID of the scope that contains this one. Component root scopes have none. */\n p?: ScopeId;\n /** The component ID of a component's root scope. */\n m?: string;\n /** The item of a list item scope. */\n i?: unknown;\n /** The scope that rendered a component's root scope, for finding contexts. */\n o?: ScopeId;\n /**\n * For a scope of children that a component inserted, the scope where they\n * are, which contexts are found from in place of `p` and `o`.\n */\n t?: ScopeId;\n /** For a component that passes its children on, the scope where they are finally inserted. */\n f?: ScopeId;\n /** For the scope of a template, the scope where it was called, which errors go to. */\n l?: ScopeId;\n /** The values that the scope provides, by context key. */\n v?: Record<string, unknown>;\n /** The slots that hold the contexts that the scope reads, by context key. */\n x?: Record<string, number>;\n /**\n * The slots that hold the values of stores that `$store` reads: the key of the context, the\n * slot, and the key of the context value that holds the store, when it is not the value.\n */\n z?: StoreRead[];\n /** Slot values, in the order of the scope's layout. */\n s?: unknown[];\n /** The scope IDs of child components, by anchor index. */\n c?: Record<number, ScopeId>;\n /**\n * What the bound props of a component write, by the slot of the prop: a\n * slot of a parent, or the function of `$bind(name, fn)`.\n */\n b?: Record<number, unknown>;\n /**\n * The setters of `ref=$bind(x, fn)` that reached an element through rest props, by the anchor\n * of the element. The client calls each once on resume.\n */\n r?: Record<number, unknown>;\n}\n\n/** The state of a page, by scope ID. */\nexport type PageState = Record<ScopeId, ScopeState>;\n\n/**\n * The flags of a group of scope records in `PackedState`:\n * - `ITEM_SLOT`: the item of each scope is its first slot.\n * - `ITEM`: each scope has its item after its slots.\n * - `CHILDREN`: each scope has its child components after that.\n * - `OWNER`: the scopes are component root scopes. `base` is the distance from the scope that\n * rendered each one, `o`, to the scope, and the first gap is from 0. Otherwise `base` is the\n * parent, `p`, of every scope.\n * - `MODULE`: the group has the component ID of its scopes after its header.\n * - `SOURCE`: the scopes are the items of a list whose list is a slot of an enclosing scope.\n * The header then has that scope's ID and the slot's index, and the items are not written:\n * the item of the scope at position `n` in the group is the value at `n` of the list, or of\n * `Array.from` of a Set. With `ITEM_SLOT`, each scope writes its slots after the first.\n * - `PREFIX`: the scopes are inside a `#loading` body. The header ends with the prefix of\n * their IDs, such as `5.`, and the gaps count the numbers after it.\n */\nexport const ITEM_SLOT = 1;\nexport const ITEM = 2;\nexport const CHILDREN = 4;\nexport const OWNER = 8;\nexport const MODULE = 16;\nexport const SOURCE = 32;\nexport const PREFIX = 64;\n\n/**\n * The page state as the server writes it. Records of scopes that share their\n * kind, their parent or owner, and their shape are in one group of `g`,\n * such as the items of a list, instead of one object each. A group is a flat\n * array: `[kind, base, flags, slotCount, module?, source?, sourceSlot?, prefix?, ...scopes]`, and each scope\n * is its ID as the gap from the one before it (the first from `base`), its\n * slots, and then its item and its child components, as `flags` says.\n */\nexport type PackedState = PageState & { g?: unknown[][] };\n\n/**\n * How a field of a state record holds scope IDs:\n * - `none`: no ID.\n * - `id`: the value is an ID.\n * - `ids`: an object whose values are IDs.\n * - `value`: a value that may hold references, such as an item.\n * - `values`: an array of such values.\n * - `map`: an object whose values are such values.\n */\nexport type FieldKind = 'none' | 'id' | 'ids' | 'value' | 'values' | 'map';\n\n/**\n * A table of the fields of a state record and the reference classes that hold\n * a scope ID, which each keep it in `scope`. Code that moves the IDs reads it.\n * A new field of `ScopeState` fails to compile until it is in `fields`, and\n * `holders` are the classes that keep references in their own fields, such as\n * `Binding`, whose `ref` and `set` hold IDs. `scope-ids.test.ts` parses this\n * file and fails for any class in it, of any shape, that is not in\n * `references` or `holders` or in the test's list of classes without IDs.\n * It checks class names only, so a person decides which list a new class\n * belongs in.\n */\nexport const SCOPE_IDS: {\n fields: Record<keyof ScopeState, FieldKind>;\n references: readonly (abstract new (...args: never[]) => { scope: ScopeId })[];\n holders: readonly (abstract new (...args: never[]) => object)[];\n} = {\n fields: {\n k: 'none',\n p: 'id',\n m: 'none',\n i: 'value',\n o: 'id',\n t: 'id',\n f: 'id',\n l: 'id',\n v: 'map',\n x: 'none',\n z: 'none',\n s: 'values',\n c: 'ids',\n b: 'map',\n r: 'map',\n },\n references: [ElementReference, FunctionReference, ChildrenReference, SlotReference],\n holders: [Binding],\n};\n"],"mappings":";;;;;AAWA,MAAM,+BAAe,IAAI,IAAyB;AAClD,MAAM,kBAAqD,CAAC;;AAE5D,IAAI,eAA6C,CAAC;AAClD,MAAM,kBAAuE,CAAC;;;;;;AAO9E,SAAgB,eAAe,OAA0B;CACvD,MAAM,EAAE,UAAU,CAAC,GAAG,GAAG,YAAY;CACrC,IAAI,QAAQ,qBAAqB,KAAA,KAAa,QAAQ,eAAe,KAAA,GAAW;EAC9E,eAAe;EACf,KAAK,MAAM,YAAY,iBACrB,SAAS,OAAO;CAEpB;CACA,eAAe,OAAO;AACxB;;AAGA,SAAgB,gBAAgB,UAAiE;CAC/F,gBAAgB,KAAK,QAAQ;CAC7B,SAAS,YAAY;AACvB;;AAGA,SAAS,eAAe,SAAuC;CAC7D,KAAK,MAAM,UAAU,SAAS;EAC5B,IAAI,aAAa,IAAI,OAAO,GAAG,MAAM,QACnC;EAEF,aAAa,IAAI,OAAO,KAAK,MAAM;EACnC,KAAK,MAAM,YAAY,iBACrB,SAAS,MAAM;CAEnB;AACF;;AAGA,SAAgB,cAAc,UAA+C;CAC3E,gBAAgB,KAAK,QAAQ;CAC7B,KAAK,MAAM,UAAU,aAAa,OAAO,GACvC,SAAS,MAAM;AAEnB;;AAWA,SAAgB,QAAQ,MAAuB;CAC7C,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI;AAC/C;;AAYA,IAAa,mB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C5B,MAAM,OAAO,IAAI,MAAM,KAAK;EAC5B,IAAI,UAAU,KAAA,GAAW;GACvB,KAAK,IAAI,SAAS,KAAA,IAAY,CAAC,OAAO,IAAK,IAAI;IAAC;IAAO;IAAO;GAAI;GAClE,WAAW,KAAK,IAAI;EACtB;EACA,OAAO;CACT,IACA;CACJ,GAAG,eACE,UAAU,IAAI,aACb,IAAI,QAA0B,KAAA,GAAW,KAAA,GAAW,IAAI,UAAU,aAAa,CAAC,IAClF;AACN;;;;;AAMA,MAAa,aAA+B,CAAC;;AAG7C,SAAgB,UAAa,OAAa;CACxC,IACG,UAAU,QACT,OAAO,UAAU,YACjB,OAAQ,MAA6B,SAAS,cAChD,gBAAgB,KAAK,GAErB,MAAM,IAAI,UACR,+EACF;CAEF,OAAO;AACT;;AAGA,SAAgB,gBAAgB,OAAiD;CAC/E,OACE,UAAU,QACV,OAAO,UAAU,YACjB,OAAQ,MAAiC,OAAO,mBAAmB;AAEvE;;;;;;;;;;;;AAkHA,MAAa,YAIT;CACF,QAAQ;EACN,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;EACH,GAAG;CACL;CACA,YAAY;EAAC;EAAkB;EAAmB;EAAmB;CAAa;CAClF,SAAS,CAAC,OAAO;AACnB"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as Route, r as NavigationState, t as Context } from "./context-BNgBXVUQ.js";
|
|
2
|
-
import { a as Store, o as StoreLike } from "./store-
|
|
2
|
+
import { a as Store, o as StoreLike } from "./store-9_oa0HG1.js";
|
|
3
3
|
import { n as RouteParams, r as RoutePath } from "./routes-BZNt7DSZ.js";
|
|
4
4
|
//#region src/runtime/signals.d.ts
|
|
5
5
|
declare const BINDABLE: unique symbol;
|
|
@@ -202,4 +202,4 @@ declare function $handler<A extends unknown[]>(fn: (...args: A) => unknown, ...a
|
|
|
202
202
|
declare function flush(): void;
|
|
203
203
|
//#endregion
|
|
204
204
|
export { BoundSignal as A, $store as C, $untrack as D, $toStore as E, flush as F, SearchParamOptions as M, Unbound as N, Bindable as O, WritableMark as P, $signal as S, $title as T, $props as _, $effect as a, $searchParam as b, $handler as c, $isPassed as d, $isPending as f, $produce as g, $optimistic as h, $debounced as i, MemoValue as j, BindableMark as k, $id as l, $navigation as m, $bind as n, $gate as o, $memo as p, $client as r, $getContext as s, $action as t, $isBound as u, $resolve as v, $throttled as w, $setContext as x, $route as y };
|
|
205
|
-
//# sourceMappingURL=signals-
|
|
205
|
+
//# sourceMappingURL=signals-7VVD9C_H.d.ts.map
|
|
@@ -209,7 +209,7 @@ function boot(options, navigate) {
|
|
|
209
209
|
run(template, ref);
|
|
210
210
|
return;
|
|
211
211
|
}
|
|
212
|
-
const done = import("./defer-
|
|
212
|
+
const done = import("./defer-BaXWydb0.js").then((module) => module.loadDeferred(template));
|
|
213
213
|
if (DEV) devtools()?.defer?.(template, done);
|
|
214
214
|
};
|
|
215
215
|
const near = template.getAttribute("b-near");
|
|
@@ -295,4 +295,4 @@ function startWithoutNavigation(options) {
|
|
|
295
295
|
//#endregion
|
|
296
296
|
export { boot as n, importCore as r, startWithoutNavigation as t };
|
|
297
297
|
|
|
298
|
-
//# sourceMappingURL=static-loader-
|
|
298
|
+
//# sourceMappingURL=static-loader-BM0-wdIc.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"static-loader-CxANokZ4.js","names":[],"sources":["../src/runtime/boot.ts","../src/runtime/static-loader.ts"],"sourcesContent":["// The loader's code that every page runs. `loader.ts` adds client navigation,\n// and `static-loader.ts` starts it without, so a site that turns navigation\n// off does not have its code, or the parts of the core that only it uses, in\n// its bundle.\n//\n// This file keeps its arrow functions and its Array methods, for size: the loader ships to every\n// page, and the function declarations and loops measured 20 to 50 bytes of gzip larger.\n\nimport { HAS_ACTIONS, HAS_BLOCKS, HAS_LATE_MARKUP, HAS_LISTENERS } from './features.ts';\nimport type * as Client from './client.ts';\nimport type { ClientModule, DevtoolsHooks } from './client.ts';\nimport type { SerialEntry } from './values.ts';\n\n/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\n/** The hooks of the devtools overlay, under the same key as the core's. */\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[Symbol.for('brumate.devtools')];\n}\n\nexport interface LoaderOptions {\n /**\n * Imports the client module of a component, by component ID. Undefined for\n * a component that has no client code.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /** The URL prefix of server function calls. */\n rpc?: string;\n /** Imports the serial entry, which the core takes before it reads the page state. */\n serial?: () => Promise<SerialEntry>;\n /**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Defaults to true.\n */\n navigate?: boolean | NavigateOptions;\n /**\n * The ID of the build of the page, for skew protection. The Vite plugin\n * sets it. Calls send it, and a page of another build, or a call that\n * answers 409 after a deploy, makes the next navigation a full page load.\n */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads, such as for a reporting\n * service. `scope` is the ID of the scope that the code belongs to. The\n * error then renders the `#catch` body of the nearest `#try`, or the page\n * gets a `brumate:error` event on `window` and the error is logged.\n */\n onError?: (error: unknown, info: { scope?: number | string }) => void;\n}\n\nexport interface NavigateOptions {\n /**\n * Swaps the page inside a view transition, where the browser has them.\n * CSS can tell links, the back and forward buttons and forms apart with\n * the types `push`, `traverse` and `form`. A redirect from a server\n * function has the type `form`.\n */\n transition?: boolean;\n /**\n * After a navigation, moves the focus to the first `<h1>` of the routes\n * that changed, or to `<main>`, as a full page load starts it at the top.\n * Defaults to true.\n */\n focus?: boolean;\n}\n\ninterface Entry {\n raw: string;\n type: string;\n modifiers: string[];\n ref: string;\n}\n\n// Parsed `b-on` values, so repeated events do not parse them again.\nconst parsed = new Map<string, Entry[]>();\n\nexport function entries(element: Element): Entry[] {\n const value = element.getAttribute('b-on') ?? '';\n return (parsed.get(value) ??\n parsed\n .set(\n value,\n value\n .split(' ')\n .filter(Boolean)\n .map((entry) => {\n const [name, ref] = entry.split('=') as [string, string];\n const [type, ...modifiers] = name.split(':') as [string, ...string[]];\n return { raw: entry, type, modifiers, ref };\n }),\n )\n .get(value))!;\n}\n\n/** The functions of the core that the loader calls. */\nexport type Core = (typeof Client)['loader'];\n\n/**\n * Imports the core. It reads one export by name, so a build keeps only it and\n * the helpers that compiled components call.\n */\nlet corePromise: Promise<Core> | undefined;\nexport const importCore = (): Promise<Core> =>\n (corePromise ??= import('./client.ts').then(\n (client) => client.loader,\n (error: unknown) => {\n // A load that fails can start again, such as after the network comes back.\n corePromise = undefined;\n throw error;\n },\n ));\n\n/** Runs a function when the browser is idle. */\nconst idle = (fn: () => void): unknown => (window.requestIdleCallback ?? setTimeout)(fn);\n\n/** What the loader gives the code that loads pages without a full page load. */\nexport interface Navigation {\n options: LoaderOptions;\n listen: (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ) => void;\n core: () => Promise<Core> | undefined;\n /** Starts the core, or returns the one that runs. */\n start: () => Promise<Core>;\n scan: (root: ParentNode) => void;\n}\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * `navigate` adds client navigation, and returns how to import the core.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function boot(\n options: LoaderOptions,\n navigate?: (navigation: Navigation) => () => Promise<Core>,\n): () => void {\n let core: Promise<Core> | undefined;\n // Once stopped, the loader starts nothing, also from markup that the core inserts later with the\n // hooks that this loader gave it. A new loader can reuse the IDs of client scopes, so a stale\n // start would run in a scope of the new page.\n let stopped = false;\n /** The event types that the document listens to, and whether each listener is passive. */\n const types = new Map<string, boolean>();\n const removers: (() => void)[] = [];\n const listen = (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ): void => {\n target.addEventListener(type, listener, flags);\n removers.push(() => target.removeEventListener(type, listener, flags));\n };\n\n // Client navigation imports the core with the code that reads the pages it adds.\n let load = importCore;\n // The modules that the loader asked for, which the core takes, so a handler whose\n // code loaded runs without another `import()`. In Chrome, an `import()` of a module that is\n // loaded already still resolves in a task of its own, which can wait for the next frame.\n const modules = new Map<string, Promise<ClientModule> | undefined>();\n const loadModule = (id: string): Promise<ClientModule> | undefined => {\n if (modules.has(id)) {\n return modules.get(id);\n }\n const promise = options.load(id);\n modules.set(id, promise);\n // A load that fails can start again, such as after the network comes back.\n promise?.catch(() => modules.delete(id));\n return promise;\n };\n // The serial entry loads with the core, so the core can make the values of the app.\n let serialLoad: Promise<SerialEntry> | undefined;\n const loadSerial = (): Promise<SerialEntry> | undefined => {\n serialLoad ??= options.serial?.();\n serialLoad?.catch(() => (serialLoad = undefined));\n return serialLoad;\n };\n const loadCore = (): Promise<Core> =>\n (core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {\n client.init({ ...options, load: loadModule, listen: scanInsert, inserted, serial });\n return client;\n }));\n\n // The devtools panel asks for the core when it opens, so it can show the page before any event.\n listen(document, 'brumate:core', () => void loadCore());\n\n const run = (element: Element, ref: string, event?: Event): void => {\n if (stopped) {\n return;\n }\n void loadCore().then((client) => client.handle(element, ref, event));\n };\n\n /**\n * A key of `prevent` matches its `event.key` while only the modifier that it names is held. A\n * key alone matches while Ctrl, Meta and Alt are up, so the shortcuts of the browser, such as\n * Cmd+Left or Alt+Left, keep their default. `Mod+` is Ctrl or Meta. Shift does not count. A\n * single letter after a modifier matches in either case, as the browser sends `k` for Cmd+K and\n * `K` for Cmd+Shift+K. A letter alone keeps its case, as `a` and `A` type different text.\n */\n const keyMatches = (key: string, event: KeyboardEvent): boolean => {\n const plus = key.indexOf('+', 1);\n const modifier = plus > 0 ? key.slice(0, plus) : '';\n let name = plus > 0 ? key.slice(plus + 1) : key;\n let pressed = event.key === ' ' ? 'Space' : event.key;\n if (plus > 0 && name.length === 1) {\n name = name.toLowerCase();\n pressed = pressed.toLowerCase();\n }\n if (pressed !== name) {\n return false;\n }\n switch (modifier) {\n case 'Mod':\n return (event.ctrlKey || event.metaKey) && !event.altKey;\n case 'Ctrl':\n return event.ctrlKey && !event.metaKey && !event.altKey;\n case 'Meta':\n return event.metaKey && !event.ctrlKey && !event.altKey;\n case 'Alt':\n return event.altKey && !event.ctrlKey && !event.metaKey;\n default:\n return !event.ctrlKey && !event.metaKey && !event.altKey;\n }\n };\n\n const apply = (event: Event, element: Element, entry: Entry): boolean => {\n for (const modifier of entry.modifiers) {\n // `prevent(ArrowDown,Enter)` prevents only these keys, by `event.key`. A key that commits\n // or moves within the text of an input method, such as Enter while it composes, is the\n // input method's, so it keeps its default.\n if (\n modifier === 'prevent' ||\n (modifier.startsWith('prevent(') &&\n !(event as KeyboardEvent).isComposing &&\n modifier\n .slice(8, -1)\n .split(',')\n .some((key) => keyMatches(key, event as KeyboardEvent)))\n ) {\n event.preventDefault();\n }\n }\n if (entry.modifiers.includes('once')) {\n element.setAttribute(\n 'b-on',\n entries(element)\n .map((item) => item.raw)\n .filter((raw) => raw !== entry.raw)\n .join(' '),\n );\n }\n run(element, entry.ref, event);\n return entry.modifiers.includes('stop');\n };\n\n /**\n * Handlers run as if each element had its own listener: those with\n * `capture` from the outside in, then the others from the target outwards.\n * An event that does not bubble, such as `focus`, reaches only the others\n * of its target. `stop` ends the event where it is.\n */\n const onEvent = (event: Event): void => {\n // The checks of `cancelWhen`, from the target up, run before any handler.\n for (let node = event.target as Node | null; node; node = node.parentNode) {\n for (const [type, check] of cancels.get(node as Element) ?? []) {\n if (type !== event.type) {\n continue;\n }\n let cancel = false;\n try {\n cancel = check(event);\n } catch (error) {\n // A check that throws cancels nothing, and the other checks and the handlers still run.\n console.error(error);\n }\n if (cancel) {\n event.preventDefault();\n return;\n }\n }\n }\n const path: Element[] = [];\n for (\n let node = event.target as Node | null;\n node && node !== document;\n node = node.parentNode\n ) {\n if (node.nodeType === 1 && (node as Element).hasAttribute('b-on')) {\n path.push(node as Element);\n }\n }\n const phase = (elements: Element[], capture: boolean): boolean => {\n for (const element of elements) {\n let stop = false;\n for (const entry of entries(element)) {\n if (\n entry.type === event.type &&\n entry.modifiers.includes('capture') === capture &&\n apply(event, element, entry)\n ) {\n stop = true;\n }\n }\n if (stop) {\n event.stopPropagation();\n return true;\n }\n }\n return false;\n };\n if (!phase([...path].reverse(), true)) {\n phase(event.bubbles ? path : path.filter((element) => element === event.target), false);\n }\n };\n\n // The checks of `cancelWhen`, by element. `events.ts` reaches them through a symbol of the registry.\n const cancels = new WeakMap<Node, Set<[string, (event: Event) => boolean]>>();\n (globalThis as { [key: symbol]: unknown })[Symbol.for('brumate.cancel')] = (\n element: Element,\n type: string,\n check: (event: Event) => boolean,\n ): (() => void) => {\n const entry: [string, typeof check] = [type, check];\n let set = cancels.get(element);\n if (!set) {\n cancels.set(element, (set = new Set()));\n }\n set.add(entry);\n delegate(type, false);\n return () => void set.delete(entry);\n };\n\n /** True for an entry that prevents the default action, which a passive listener cannot do. */\n const prevents = (entry: Entry): boolean =>\n entry.modifiers.some((modifier) => modifier.startsWith('prevent'));\n\n /**\n * Listens to an event type on the document. The listener is passive, so\n * scrolling does not wait for it, until an entry of the type prevents. `click` and `submit` never\n * scroll, so they are never passive: a `prevent` that is written after load cancels them.\n */\n const delegate = (type: string, cancel: boolean): void => {\n const prevent = cancel || type === 'click' || type === 'submit';\n const passive = types.get(type);\n if (passive === false || (passive === true && !prevent)) {\n return;\n }\n if (passive) {\n document.removeEventListener(type, onEvent, true);\n }\n types.set(type, !prevent);\n listen(document, type, onEvent, { capture: true, passive: !prevent });\n };\n\n // Templates are started once, even when markup is scanned again.\n const started = new WeakSet<Element>();\n const select = (root: ParentNode, selector: string): Element[] => {\n const found: Element[] = [];\n const add = (element: Element): void => {\n if (element.tagName === 'TEMPLATE') {\n if (started.has(element)) {\n return;\n }\n started.add(element);\n }\n found.push(element);\n };\n if ((root as Element).matches?.(selector)) {\n add(root as Element);\n }\n for (const element of root.querySelectorAll(selector)) {\n add(element);\n }\n return found;\n };\n\n // The values of `b-on` whose event types the document listens to already. The rows of a\n // list repeat the same few values.\n const delegated = new Set<string>();\n const onElement = (element: Element): void => {\n const value = element.getAttribute('b-on')!;\n if (!delegated.has(value)) {\n delegated.add(value);\n for (const entry of entries(element)) {\n delegate(entry.type, prevents(entry));\n }\n }\n };\n const onListener = (template: Element): void => {\n const target = template.getAttribute('b-listen') === 'window' ? window : document;\n for (const entry of entries(template)) {\n // Markup that is gone, such as a page that navigation replaced, no longer listens.\n listen(\n target,\n entry.type,\n (event) => {\n if (template.isConnected) {\n apply(event, template, entry);\n }\n },\n { capture: entry.modifiers.includes('capture'), passive: !prevents(entry) },\n );\n }\n };\n // A `#defer` block whose body the server sends in the same response, with `b-hole`, waits for it.\n const onBlock = (root: ParentNode, template: Element): void => {\n const client = template.getAttribute('b-client');\n const [trigger, ref] = (client ?? template.getAttribute('b-defer')!).split(\n client ? '=' : ':',\n ) as [string, string];\n // A `#defer` block asks the server for its body, with a module that only it needs.\n const go = (): void => {\n if (client) {\n run(template, ref);\n return;\n }\n const done = import('./defer.ts').then((module) => module.loadDeferred(template));\n if (DEV) {\n devtools()?.defer?.(template, done);\n }\n };\n // The element that a `$client` callback reads through `ref` (`b-b`), or that a component\n // forwards to its signal (`b-r`), or the one after the marker.\n // Other markers can follow it, and a template has no box, so it is never in view.\n const near = template.getAttribute('b-near');\n let after = template.nextElementSibling;\n while (after?.tagName === 'TEMPLATE') {\n after = after.nextElementSibling;\n }\n const selector = `[b-b=\"${near}\"],[b-r=\"${near}\"]`;\n const next =\n (near && (root.querySelector(selector) ?? document.querySelector(selector))) || after;\n if (trigger === 'idle') {\n idle(go);\n } else if (trigger === 'visible' && next && typeof IntersectionObserver !== 'undefined') {\n const observer = new IntersectionObserver((records) => {\n if (records.some((record) => record.isIntersecting)) {\n observer.disconnect();\n go();\n }\n });\n observer.observe(next);\n } else {\n go();\n }\n };\n const SCANNED = '[b-on],template[b-listen],template[b-client],template[b-defer]';\n // One query of the markup for everything that the loader starts. The blocks start after the\n // rest, as they did when each kind had its own query.\n const scan = (root: ParentNode): void => {\n if (stopped) {\n return;\n }\n const blocks: Element[] = [];\n for (const element of select(root, SCANNED)) {\n if (element.tagName === 'TEMPLATE') {\n if (HAS_LISTENERS && element.hasAttribute('b-listen')) {\n onListener(element);\n } else if (\n HAS_BLOCKS &&\n (element.hasAttribute('b-client') ||\n (element.hasAttribute('b-defer') && !element.hasAttribute('b-hole')))\n ) {\n blocks.push(element);\n }\n continue;\n }\n if (element.hasAttribute('b-on')) {\n onElement(element);\n }\n }\n for (const template of blocks) {\n onBlock(root, template);\n }\n };\n\n // A form of an `$action` sends its data with `fetch`, and the core writes the result into the page.\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n if (!HAS_ACTIONS || event.defaultPrevented || !form.hasAttribute?.('b-result')) {\n return;\n }\n event.preventDefault();\n const submitter = (event as SubmitEvent).submitter;\n void loadCore().then((client) => client.submitAction(form, submitter));\n });\n\n if (navigate) {\n load = navigate({ options, listen, core: () => core, start: loadCore, scan });\n } else {\n // A hot update whose markup changed loads the page again.\n listen(document, 'brumate:reload', () => location.reload());\n }\n\n scan(document);\n // Markup that streams in later, such as a `#loading` body, has handlers too.\n const scanAdded = (records: MutationRecord[]): void => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n scan(node as Element);\n }\n }\n }\n };\n // Without markup that others insert, the core scans all that comes into the page. The rest of\n // the page that the browser reads after an `async` script starts is scanned when it ends.\n const observer = HAS_LATE_MARKUP ? new MutationObserver(scanAdded) : undefined;\n observer?.observe(document, { childList: true, subtree: true });\n if (!HAS_LATE_MARKUP && document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', () => scan(document));\n }\n // The core scans the markup that it inserts before the insert, so the records of the insert\n // are dropped instead of scanned again. The markup that others inserted first is scanned\n // first.\n const scanInsert = (root: ParentNode): void => {\n if (observer) {\n scanAdded(observer.takeRecords());\n }\n scan(root);\n };\n const inserted = (): void => {\n observer?.takeRecords();\n };\n\n // The core starts at once and loads the code of the components on the page, so a call of a\n // function of another component, such as a function prop, runs at once and in order.\n void loadCore().catch(() => {});\n return () => {\n stopped = true;\n observer?.disconnect();\n for (const remove of removers.splice(0)) {\n remove();\n }\n void core?.then((client) => client.dispose());\n };\n}\n","// The loader without client navigation, for `navigate: false`. It is a module\n// of its own, so a bundle that starts it has no import of the navigation code,\n// and keeps none of the core's exports that only navigation reads.\n\nimport { boot } from './boot.ts';\nimport type { LoaderOptions } from './boot.ts';\n\nexport type { LoaderOptions } from './boot.ts';\n\n/**\n * `start` for a site that loads every page with a full page load, as with\n * `navigate: false`. A bundle that only calls it leaves out the code of\n * client navigation.\n */\nexport function startWithoutNavigation(options: LoaderOptions): () => void {\n return boot(options);\n}\n"],"mappings":";;;AAcA,MAAM,MAAO,YAA4C,KAAK;;AAG9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD,OAAO,IAAI,kBAAkB;AAChG;AA0DA,MAAM,yBAAS,IAAI,IAAqB;AAExC,SAAgB,QAAQ,SAA2B;CACjD,MAAM,QAAQ,QAAQ,aAAa,MAAM,KAAK;CAC9C,OAAQ,OAAO,IAAI,KAAK,KACtB,OACG,IACC,OACA,MACG,MAAM,GAAG,CAAC,CACV,OAAO,OAAO,CAAC,CACf,KAAK,UAAU;EACd,MAAM,CAAC,MAAM,OAAO,MAAM,MAAM,GAAG;EACnC,MAAM,CAAC,MAAM,GAAG,aAAa,KAAK,MAAM,GAAG;EAC3C,OAAO;GAAE,KAAK;GAAO;GAAM;GAAW;EAAI;CAC5C,CAAC,CACL,CAAC,CACA,IAAI,KAAK;AAChB;;;;;AASA,IAAI;AACJ,MAAa,mBACV,gBAAgB,OAAO,sBAAc,CAAC,MACpC,WAAW,OA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AAC;CAC9C;AACF;;;;;;;;AClhBA,SAAgB,uBAAuB,SAAoC;CACzE,OAAO,KAAK,OAAO;AACrB"}
|
|
1
|
+
{"version":3,"file":"static-loader-BM0-wdIc.js","names":[],"sources":["../src/runtime/boot.ts","../src/runtime/static-loader.ts"],"sourcesContent":["// The loader's code that every page runs. `loader.ts` adds client navigation,\n// and `static-loader.ts` starts it without, so a site that turns navigation\n// off does not have its code, or the parts of the core that only it uses, in\n// its bundle.\n//\n// This file keeps its arrow functions and its Array methods, for size: the loader ships to every\n// page, and the function declarations and loops measured 20 to 50 bytes of gzip larger.\n\nimport { HAS_ACTIONS, HAS_BLOCKS, HAS_LATE_MARKUP, HAS_LISTENERS } from './features.ts';\nimport type * as Client from './client.ts';\nimport type { ClientModule, DevtoolsHooks } from './client.ts';\nimport type { SerialEntry } from './values.ts';\n\n/** True on the dev server. A Vite build replaces it with `false`, so the devtools calls go. */\nconst DEV = (import.meta as { env?: { DEV?: boolean } }).env?.DEV;\n\n/** The hooks of the devtools overlay, under the same key as the core's. */\nfunction devtools(): DevtoolsHooks | undefined {\n return (globalThis as Record<symbol, DevtoolsHooks | undefined>)[Symbol.for('brumate.devtools')];\n}\n\nexport interface LoaderOptions {\n /**\n * Imports the client module of a component, by component ID. Undefined for\n * a component that has no client code.\n */\n load: (id: string) => Promise<ClientModule> | undefined;\n /** The URL prefix of server function calls. */\n rpc?: string;\n /** Imports the serial entry, which the core takes before it reads the page state. */\n serial?: () => Promise<SerialEntry>;\n /**\n * Loads pages without a full page load: links to the same origin, the back\n * and forward buttons, forms that post to a server function, and redirects\n * from server functions to the same origin. Defaults to true.\n */\n navigate?: boolean | NavigateOptions;\n /**\n * The ID of the build of the page, for skew protection. The Vite plugin\n * sets it. Calls send it, and a page of another build, or a call that\n * answers 409 after a deploy, makes the next navigation a full page load.\n */\n build?: string;\n /**\n * Receives every error of client code first: of a handler, an effect, a\n * `$client` callback or a memo that loads, such as for a reporting\n * service. `scope` is the ID of the scope that the code belongs to. The\n * error then renders the `#catch` body of the nearest `#try`, or the page\n * gets a `brumate:error` event on `window` and the error is logged.\n */\n onError?: (error: unknown, info: { scope?: number | string }) => void;\n}\n\nexport interface NavigateOptions {\n /**\n * Swaps the page inside a view transition, where the browser has them.\n * CSS can tell links, the back and forward buttons and forms apart with\n * the types `push`, `traverse` and `form`. A redirect from a server\n * function has the type `form`.\n */\n transition?: boolean;\n /**\n * After a navigation, moves the focus to the first `<h1>` of the routes\n * that changed, or to `<main>`, as a full page load starts it at the top.\n * Defaults to true.\n */\n focus?: boolean;\n}\n\ninterface Entry {\n raw: string;\n type: string;\n modifiers: string[];\n ref: string;\n}\n\n// Parsed `b-on` values, so repeated events do not parse them again.\nconst parsed = new Map<string, Entry[]>();\n\nexport function entries(element: Element): Entry[] {\n const value = element.getAttribute('b-on') ?? '';\n return (parsed.get(value) ??\n parsed\n .set(\n value,\n value\n .split(' ')\n .filter(Boolean)\n .map((entry) => {\n const [name, ref] = entry.split('=') as [string, string];\n const [type, ...modifiers] = name.split(':') as [string, ...string[]];\n return { raw: entry, type, modifiers, ref };\n }),\n )\n .get(value))!;\n}\n\n/** The functions of the core that the loader calls. */\nexport type Core = (typeof Client)['loader'];\n\n/**\n * Imports the core. It reads one export by name, so a build keeps only it and\n * the helpers that compiled components call.\n */\nlet corePromise: Promise<Core> | undefined;\nexport const importCore = (): Promise<Core> =>\n (corePromise ??= import('./client.ts').then(\n (client) => client.loader,\n (error: unknown) => {\n // A load that fails can start again, such as after the network comes back.\n corePromise = undefined;\n throw error;\n },\n ));\n\n/** Runs a function when the browser is idle. */\nconst idle = (fn: () => void): unknown => (window.requestIdleCallback ?? setTimeout)(fn);\n\n/** What the loader gives the code that loads pages without a full page load. */\nexport interface Navigation {\n options: LoaderOptions;\n listen: (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ) => void;\n core: () => Promise<Core> | undefined;\n /** Starts the core, or returns the one that runs. */\n start: () => Promise<Core>;\n scan: (root: ParentNode) => void;\n}\n\n/**\n * Starts resuming the page. Listens to the events in `b-on` attributes\n * and loads `brumate/client` and the component's module on the first one.\n * `navigate` adds client navigation, and returns how to import the core.\n * Returns a function that removes the listeners and stops the core.\n */\nexport function boot(\n options: LoaderOptions,\n navigate?: (navigation: Navigation) => () => Promise<Core>,\n): () => void {\n let core: Promise<Core> | undefined;\n // Once stopped, the loader starts nothing, also from markup that the core inserts later with the\n // hooks that this loader gave it. A new loader can reuse the IDs of client scopes, so a stale\n // start would run in a scope of the new page.\n let stopped = false;\n /** The event types that the document listens to, and whether each listener is passive. */\n const types = new Map<string, boolean>();\n const removers: (() => void)[] = [];\n const listen = (\n target: EventTarget,\n type: string,\n listener: (event: Event) => void,\n flags?: AddEventListenerOptions | boolean,\n ): void => {\n target.addEventListener(type, listener, flags);\n removers.push(() => target.removeEventListener(type, listener, flags));\n };\n\n // Client navigation imports the core with the code that reads the pages it adds.\n let load = importCore;\n // The modules that the loader asked for, which the core takes, so a handler whose\n // code loaded runs without another `import()`. In Chrome, an `import()` of a module that is\n // loaded already still resolves in a task of its own, which can wait for the next frame.\n const modules = new Map<string, Promise<ClientModule> | undefined>();\n const loadModule = (id: string): Promise<ClientModule> | undefined => {\n if (modules.has(id)) {\n return modules.get(id);\n }\n const promise = options.load(id);\n modules.set(id, promise);\n // A load that fails can start again, such as after the network comes back.\n promise?.catch(() => modules.delete(id));\n return promise;\n };\n // The serial entry loads with the core, so the core can make the values of the app.\n let serialLoad: Promise<SerialEntry> | undefined;\n const loadSerial = (): Promise<SerialEntry> | undefined => {\n serialLoad ??= options.serial?.();\n serialLoad?.catch(() => (serialLoad = undefined));\n return serialLoad;\n };\n const loadCore = (): Promise<Core> =>\n (core ??= Promise.all([load(), loadSerial()]).then(([client, serial]) => {\n client.init({ ...options, load: loadModule, listen: scanInsert, inserted, serial });\n return client;\n }));\n\n // The devtools panel asks for the core when it opens, so it can show the page before any event.\n listen(document, 'brumate:core', () => void loadCore());\n\n const run = (element: Element, ref: string, event?: Event): void => {\n if (stopped) {\n return;\n }\n void loadCore().then((client) => client.handle(element, ref, event));\n };\n\n /**\n * A key of `prevent` matches its `event.key` while only the modifier that it names is held. A\n * key alone matches while Ctrl, Meta and Alt are up, so the shortcuts of the browser, such as\n * Cmd+Left or Alt+Left, keep their default. `Mod+` is Ctrl or Meta. Shift does not count. A\n * single letter after a modifier matches in either case, as the browser sends `k` for Cmd+K and\n * `K` for Cmd+Shift+K. A letter alone keeps its case, as `a` and `A` type different text.\n */\n const keyMatches = (key: string, event: KeyboardEvent): boolean => {\n const plus = key.indexOf('+', 1);\n const modifier = plus > 0 ? key.slice(0, plus) : '';\n let name = plus > 0 ? key.slice(plus + 1) : key;\n let pressed = event.key === ' ' ? 'Space' : event.key;\n if (plus > 0 && name.length === 1) {\n name = name.toLowerCase();\n pressed = pressed.toLowerCase();\n }\n if (pressed !== name) {\n return false;\n }\n switch (modifier) {\n case 'Mod':\n return (event.ctrlKey || event.metaKey) && !event.altKey;\n case 'Ctrl':\n return event.ctrlKey && !event.metaKey && !event.altKey;\n case 'Meta':\n return event.metaKey && !event.ctrlKey && !event.altKey;\n case 'Alt':\n return event.altKey && !event.ctrlKey && !event.metaKey;\n default:\n return !event.ctrlKey && !event.metaKey && !event.altKey;\n }\n };\n\n const apply = (event: Event, element: Element, entry: Entry): boolean => {\n for (const modifier of entry.modifiers) {\n // `prevent(ArrowDown,Enter)` prevents only these keys, by `event.key`. A key that commits\n // or moves within the text of an input method, such as Enter while it composes, is the\n // input method's, so it keeps its default.\n if (\n modifier === 'prevent' ||\n (modifier.startsWith('prevent(') &&\n !(event as KeyboardEvent).isComposing &&\n modifier\n .slice(8, -1)\n .split(',')\n .some((key) => keyMatches(key, event as KeyboardEvent)))\n ) {\n event.preventDefault();\n }\n }\n if (entry.modifiers.includes('once')) {\n element.setAttribute(\n 'b-on',\n entries(element)\n .map((item) => item.raw)\n .filter((raw) => raw !== entry.raw)\n .join(' '),\n );\n }\n run(element, entry.ref, event);\n return entry.modifiers.includes('stop');\n };\n\n /**\n * Handlers run as if each element had its own listener: those with\n * `capture` from the outside in, then the others from the target outwards.\n * An event that does not bubble, such as `focus`, reaches only the others\n * of its target. `stop` ends the event where it is.\n */\n const onEvent = (event: Event): void => {\n // The checks of `cancelWhen`, from the target up, run before any handler.\n for (let node = event.target as Node | null; node; node = node.parentNode) {\n for (const [type, check] of cancels.get(node as Element) ?? []) {\n if (type !== event.type) {\n continue;\n }\n let cancel = false;\n try {\n cancel = check(event);\n } catch (error) {\n // A check that throws cancels nothing, and the other checks and the handlers still run.\n console.error(error);\n }\n if (cancel) {\n event.preventDefault();\n return;\n }\n }\n }\n const path: Element[] = [];\n for (\n let node = event.target as Node | null;\n node && node !== document;\n node = node.parentNode\n ) {\n if (node.nodeType === 1 && (node as Element).hasAttribute('b-on')) {\n path.push(node as Element);\n }\n }\n const phase = (elements: Element[], capture: boolean): boolean => {\n for (const element of elements) {\n let stop = false;\n for (const entry of entries(element)) {\n if (\n entry.type === event.type &&\n entry.modifiers.includes('capture') === capture &&\n apply(event, element, entry)\n ) {\n stop = true;\n }\n }\n if (stop) {\n event.stopPropagation();\n return true;\n }\n }\n return false;\n };\n if (!phase([...path].reverse(), true)) {\n phase(event.bubbles ? path : path.filter((element) => element === event.target), false);\n }\n };\n\n // The checks of `cancelWhen`, by element. `events.ts` reaches them through a symbol of the registry.\n const cancels = new WeakMap<Node, Set<[string, (event: Event) => boolean]>>();\n (globalThis as { [key: symbol]: unknown })[Symbol.for('brumate.cancel')] = (\n element: Element,\n type: string,\n check: (event: Event) => boolean,\n ): (() => void) => {\n const entry: [string, typeof check] = [type, check];\n let set = cancels.get(element);\n if (!set) {\n cancels.set(element, (set = new Set()));\n }\n set.add(entry);\n delegate(type, false);\n return () => void set.delete(entry);\n };\n\n /** True for an entry that prevents the default action, which a passive listener cannot do. */\n const prevents = (entry: Entry): boolean =>\n entry.modifiers.some((modifier) => modifier.startsWith('prevent'));\n\n /**\n * Listens to an event type on the document. The listener is passive, so\n * scrolling does not wait for it, until an entry of the type prevents. `click` and `submit` never\n * scroll, so they are never passive: a `prevent` that is written after load cancels them.\n */\n const delegate = (type: string, cancel: boolean): void => {\n const prevent = cancel || type === 'click' || type === 'submit';\n const passive = types.get(type);\n if (passive === false || (passive === true && !prevent)) {\n return;\n }\n if (passive) {\n document.removeEventListener(type, onEvent, true);\n }\n types.set(type, !prevent);\n listen(document, type, onEvent, { capture: true, passive: !prevent });\n };\n\n // Templates are started once, even when markup is scanned again.\n const started = new WeakSet<Element>();\n const select = (root: ParentNode, selector: string): Element[] => {\n const found: Element[] = [];\n const add = (element: Element): void => {\n if (element.tagName === 'TEMPLATE') {\n if (started.has(element)) {\n return;\n }\n started.add(element);\n }\n found.push(element);\n };\n if ((root as Element).matches?.(selector)) {\n add(root as Element);\n }\n for (const element of root.querySelectorAll(selector)) {\n add(element);\n }\n return found;\n };\n\n // The values of `b-on` whose event types the document listens to already. The rows of a\n // list repeat the same few values.\n const delegated = new Set<string>();\n const onElement = (element: Element): void => {\n const value = element.getAttribute('b-on')!;\n if (!delegated.has(value)) {\n delegated.add(value);\n for (const entry of entries(element)) {\n delegate(entry.type, prevents(entry));\n }\n }\n };\n const onListener = (template: Element): void => {\n const target = template.getAttribute('b-listen') === 'window' ? window : document;\n for (const entry of entries(template)) {\n // Markup that is gone, such as a page that navigation replaced, no longer listens.\n listen(\n target,\n entry.type,\n (event) => {\n if (template.isConnected) {\n apply(event, template, entry);\n }\n },\n { capture: entry.modifiers.includes('capture'), passive: !prevents(entry) },\n );\n }\n };\n // A `#defer` block whose body the server sends in the same response, with `b-hole`, waits for it.\n const onBlock = (root: ParentNode, template: Element): void => {\n const client = template.getAttribute('b-client');\n const [trigger, ref] = (client ?? template.getAttribute('b-defer')!).split(\n client ? '=' : ':',\n ) as [string, string];\n // A `#defer` block asks the server for its body, with a module that only it needs.\n const go = (): void => {\n if (client) {\n run(template, ref);\n return;\n }\n const done = import('./defer.ts').then((module) => module.loadDeferred(template));\n if (DEV) {\n devtools()?.defer?.(template, done);\n }\n };\n // The element that a `$client` callback reads through `ref` (`b-b`), or that a component\n // forwards to its signal (`b-r`), or the one after the marker.\n // Other markers can follow it, and a template has no box, so it is never in view.\n const near = template.getAttribute('b-near');\n let after = template.nextElementSibling;\n while (after?.tagName === 'TEMPLATE') {\n after = after.nextElementSibling;\n }\n const selector = `[b-b=\"${near}\"],[b-r=\"${near}\"]`;\n const next =\n (near && (root.querySelector(selector) ?? document.querySelector(selector))) || after;\n if (trigger === 'idle') {\n idle(go);\n } else if (trigger === 'visible' && next && typeof IntersectionObserver !== 'undefined') {\n const observer = new IntersectionObserver((records) => {\n if (records.some((record) => record.isIntersecting)) {\n observer.disconnect();\n go();\n }\n });\n observer.observe(next);\n } else {\n go();\n }\n };\n const SCANNED = '[b-on],template[b-listen],template[b-client],template[b-defer]';\n // One query of the markup for everything that the loader starts. The blocks start after the\n // rest, as they did when each kind had its own query.\n const scan = (root: ParentNode): void => {\n if (stopped) {\n return;\n }\n const blocks: Element[] = [];\n for (const element of select(root, SCANNED)) {\n if (element.tagName === 'TEMPLATE') {\n if (HAS_LISTENERS && element.hasAttribute('b-listen')) {\n onListener(element);\n } else if (\n HAS_BLOCKS &&\n (element.hasAttribute('b-client') ||\n (element.hasAttribute('b-defer') && !element.hasAttribute('b-hole')))\n ) {\n blocks.push(element);\n }\n continue;\n }\n if (element.hasAttribute('b-on')) {\n onElement(element);\n }\n }\n for (const template of blocks) {\n onBlock(root, template);\n }\n };\n\n // A form of an `$action` sends its data with `fetch`, and the core writes the result into the page.\n listen(document, 'submit', (event) => {\n const form = event.target as HTMLFormElement;\n if (!HAS_ACTIONS || event.defaultPrevented || !form.hasAttribute?.('b-result')) {\n return;\n }\n event.preventDefault();\n const submitter = (event as SubmitEvent).submitter;\n void loadCore().then((client) => client.submitAction(form, submitter));\n });\n\n if (navigate) {\n load = navigate({ options, listen, core: () => core, start: loadCore, scan });\n } else {\n // A hot update whose markup changed loads the page again.\n listen(document, 'brumate:reload', () => location.reload());\n }\n\n scan(document);\n // Markup that streams in later, such as a `#loading` body, has handlers too.\n const scanAdded = (records: MutationRecord[]): void => {\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n scan(node as Element);\n }\n }\n }\n };\n // Without markup that others insert, the core scans all that comes into the page. The rest of\n // the page that the browser reads after an `async` script starts is scanned when it ends.\n const observer = HAS_LATE_MARKUP ? new MutationObserver(scanAdded) : undefined;\n observer?.observe(document, { childList: true, subtree: true });\n if (!HAS_LATE_MARKUP && document.readyState === 'loading') {\n listen(document, 'DOMContentLoaded', () => scan(document));\n }\n // The core scans the markup that it inserts before the insert, so the records of the insert\n // are dropped instead of scanned again. The markup that others inserted first is scanned\n // first.\n const scanInsert = (root: ParentNode): void => {\n if (observer) {\n scanAdded(observer.takeRecords());\n }\n scan(root);\n };\n const inserted = (): void => {\n observer?.takeRecords();\n };\n\n // The core starts at once and loads the code of the components on the page, so a call of a\n // function of another component, such as a function prop, runs at once and in order.\n void loadCore().catch(() => {});\n return () => {\n stopped = true;\n observer?.disconnect();\n for (const remove of removers.splice(0)) {\n remove();\n }\n void core?.then((client) => client.dispose());\n };\n}\n","// The loader without client navigation, for `navigate: false`. It is a module\n// of its own, so a bundle that starts it has no import of the navigation code,\n// and keeps none of the core's exports that only navigation reads.\n\nimport { boot } from './boot.ts';\nimport type { LoaderOptions } from './boot.ts';\n\nexport type { LoaderOptions } from './boot.ts';\n\n/**\n * `start` for a site that loads every page with a full page load, as with\n * `navigate: false`. A bundle that only calls it leaves out the code of\n * client navigation.\n */\nexport function startWithoutNavigation(options: LoaderOptions): () => void {\n return boot(options);\n}\n"],"mappings":";;;AAcA,MAAM,MAAO,YAA4C,KAAK;;AAG9D,SAAS,WAAsC;CAC7C,OAAQ,WAAyD,OAAO,IAAI,kBAAkB;AAChG;AA0DA,MAAM,yBAAS,IAAI,IAAqB;AAExC,SAAgB,QAAQ,SAA2B;CACjD,MAAM,QAAQ,QAAQ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CAAK,CAAC;CAC9D,IAAI,CAAC,mBAAmB,SAAS,eAAe,WAC9C,OAAO,UAAU,0BAA0B,KAAK,QAAQ,CAAC;CAK3D,MAAM,cAAc,SAA2B;EAC7C,IAAI,UACF,UAAU,SAAS,YAAY,CAAC;EAElC,KAAK,IAAI;CACX;CACA,MAAM,iBAAuB;EAC3B,UAAU,YAAY;CACxB;CAIA,SAAc,CAAC,CAAC,YAAY,CAAC,CAAC;CAC9B,aAAa;EACX,UAAU;EACV,UAAU,WAAW;EACrB,KAAK,MAAM,UAAU,SAAS,OAAO,CAAC,GACpC,OAAO;EAET,MAAW,MAAM,WAAW,OAAO,QAAQ,CAAC;CAC9C;AACF;;;;;;;;AClhBA,SAAgB,uBAAuB,SAAoC;CACzE,OAAO,KAAK,OAAO;AACrB"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { t as LoaderOptions } from "./boot-
|
|
1
|
+
import { t as LoaderOptions } from "./boot-DQuAhAd5.js";
|
|
2
2
|
//#region src/runtime/static-loader.d.ts
|
|
3
3
|
/**
|
|
4
4
|
* `start` for a site that loads every page with a full page load, as with
|
|
@@ -8,4 +8,4 @@ import { t as LoaderOptions } from "./boot-CMy0f_iC.js";
|
|
|
8
8
|
declare function startWithoutNavigation(options: LoaderOptions): () => void;
|
|
9
9
|
//#endregion
|
|
10
10
|
export { startWithoutNavigation as t };
|
|
11
|
-
//# sourceMappingURL=static-loader-
|
|
11
|
+
//# sourceMappingURL=static-loader-BSAyFqG0.d.ts.map
|
|
@@ -66,6 +66,19 @@ declare function canSet(value: StoreLike<unknown>): boolean;
|
|
|
66
66
|
declare function store<T>(value: T): Store<T>;
|
|
67
67
|
/** Writes the value of a store and calls its listeners, in one pass of the page. */
|
|
68
68
|
declare function sendStore<T>(target: Store<T>, value: T, force?: boolean): void;
|
|
69
|
+
/** The stores that `derived` reads: one store, or an array of them. */
|
|
70
|
+
type Stores = StoreLike<any> | [StoreLike<any>, ...StoreLike<any>[]] | StoreLike<any>[];
|
|
71
|
+
/** The values of `Stores`: a value for one store, an array of values for an array. */
|
|
72
|
+
type StoresValues<S> = S extends StoreLike<infer U> ? U : { [K in keyof S]: S[K] extends StoreLike<infer U> ? U : never; };
|
|
73
|
+
/**
|
|
74
|
+
* A store computed from `sources`. With a function of one parameter, the result is the value. With
|
|
75
|
+
* two or three, the function calls `set` or `update`, and a function it returns runs before the
|
|
76
|
+
* next call and when the last subscriber leaves. It follows its sources only while it has
|
|
77
|
+
* subscribers; `get` computes from the sources otherwise. A source change that reaches it in one
|
|
78
|
+
* pass computes it once, after the stores it reads.
|
|
79
|
+
*/
|
|
80
|
+
declare function derived<S extends Stores, T>(sources: S, fn: (values: StoresValues<S>, set: (value: T) => void, update: (change: (value: T) => T) => void) => (() => void) | void, initial?: T): StoreLike<T>;
|
|
81
|
+
declare function derived<S extends Stores, T>(sources: S, fn: (values: StoresValues<S>) => T, initial?: T): StoreLike<T>;
|
|
69
82
|
/** What `bridge` takes. */
|
|
70
83
|
interface BridgeOptions<S, T> {
|
|
71
84
|
/**
|
|
@@ -167,5 +180,5 @@ declare class Bridged<S, T> implements BridgedStore<S, T> {
|
|
|
167
180
|
private make;
|
|
168
181
|
}
|
|
169
182
|
//#endregion
|
|
170
|
-
export {
|
|
171
|
-
//# sourceMappingURL=store-
|
|
183
|
+
export { setBridgeLoader as C, sentForeignStore as S, isForeignStore as _, Store as a, sameData as b, Stores as c, canSet as d, derived as f, isContract as g, isContext as h, BridgedStore as i, StoresValues as l, isBridged as m, BridgeOptions as n, StoreLike as o, findStored as p, Bridged as r, StoreOrigin as s, Bridge as t, bridge as u, isStore as v, store as w, sendStore as x, nameBridge as y };
|
|
184
|
+
//# sourceMappingURL=store-9_oa0HG1.d.ts.map
|
|
@@ -106,6 +106,152 @@ function sendStore(target, value, force) {
|
|
|
106
106
|
if (pass) pass(listeners);
|
|
107
107
|
else listeners();
|
|
108
108
|
}
|
|
109
|
+
/** The derived stores that heard of a change and wait to compute. */
|
|
110
|
+
const waiting = [];
|
|
111
|
+
/** The listener sets that have a trailing listener, which computes the waiting stores. */
|
|
112
|
+
const armed = /* @__PURE__ */ new Set();
|
|
113
|
+
/** True while the waiting stores compute. */
|
|
114
|
+
let flushing = false;
|
|
115
|
+
/** Computes the waiting derived stores, the ones that read the fewest derived stores first. */
|
|
116
|
+
function flushComputed() {
|
|
117
|
+
flushing = true;
|
|
118
|
+
try {
|
|
119
|
+
while (waiting.length > 0) {
|
|
120
|
+
let next = 0;
|
|
121
|
+
for (let i = 1; i < waiting.length; i++) if (waiting[i].level < waiting[next].level) next = i;
|
|
122
|
+
const [computed] = waiting.splice(next, 1);
|
|
123
|
+
computed.waits = false;
|
|
124
|
+
computed.run();
|
|
125
|
+
}
|
|
126
|
+
} catch (error) {
|
|
127
|
+
for (const computed of waiting) computed.waits = false;
|
|
128
|
+
waiting.length = 0;
|
|
129
|
+
throw error;
|
|
130
|
+
} finally {
|
|
131
|
+
flushing = false;
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
function derived(sources, fn, initial) {
|
|
135
|
+
const single = !Array.isArray(sources);
|
|
136
|
+
const list = single ? [sources] : sources;
|
|
137
|
+
for (const source of list) if (!source) throw new Error("derived() expects stores as input, got a falsy value");
|
|
138
|
+
const auto = fn.length < 2;
|
|
139
|
+
const out = new Store(initial);
|
|
140
|
+
const subscribers = /* @__PURE__ */ new Set();
|
|
141
|
+
let level = 1;
|
|
142
|
+
for (const source of list) level = Math.max(level, (source.d ?? 0) + 1);
|
|
143
|
+
let cleanup;
|
|
144
|
+
let started = false;
|
|
145
|
+
let starting = false;
|
|
146
|
+
let stops = [];
|
|
147
|
+
/** Runs `fn` over the current values of the sources. */
|
|
148
|
+
const compute = (write) => {
|
|
149
|
+
const values = [];
|
|
150
|
+
for (const source of list) values.push(source.get());
|
|
151
|
+
const set = write;
|
|
152
|
+
const update = (change) => write(change(out.v));
|
|
153
|
+
cleanup?.();
|
|
154
|
+
cleanup = void 0;
|
|
155
|
+
const result = fn(single ? values[0] : values, set, update);
|
|
156
|
+
if (auto) write(result);
|
|
157
|
+
else if (typeof result === "function") cleanup = result;
|
|
158
|
+
};
|
|
159
|
+
const send = (value) => {
|
|
160
|
+
if (starting) out.v = value;
|
|
161
|
+
else if (started) sendStore(out, value);
|
|
162
|
+
else out.v = value;
|
|
163
|
+
};
|
|
164
|
+
const state = {
|
|
165
|
+
level,
|
|
166
|
+
waits: false,
|
|
167
|
+
run() {
|
|
168
|
+
if (started) compute(send);
|
|
169
|
+
}
|
|
170
|
+
};
|
|
171
|
+
/**
|
|
172
|
+
* Called by a source. The store waits until the source has called all its listeners, so a store
|
|
173
|
+
* that reads this one and the source computes once, after this one.
|
|
174
|
+
*/
|
|
175
|
+
const heard = (source) => {
|
|
176
|
+
if (!started || state.waits) return;
|
|
177
|
+
state.waits = true;
|
|
178
|
+
waiting.push(state);
|
|
179
|
+
if (flushing) return;
|
|
180
|
+
const listeners = source.l;
|
|
181
|
+
if (!listeners || armed.has(listeners)) {
|
|
182
|
+
if (!listeners) flushComputed();
|
|
183
|
+
return;
|
|
184
|
+
}
|
|
185
|
+
const trail = () => {
|
|
186
|
+
listeners.delete(trail);
|
|
187
|
+
armed.delete(listeners);
|
|
188
|
+
flushComputed();
|
|
189
|
+
};
|
|
190
|
+
armed.add(listeners);
|
|
191
|
+
listeners.add(trail);
|
|
192
|
+
};
|
|
193
|
+
const start = () => {
|
|
194
|
+
starting = true;
|
|
195
|
+
started = true;
|
|
196
|
+
try {
|
|
197
|
+
compute(send);
|
|
198
|
+
for (const source of list) stops.push(source.subscribe(() => heard(source)));
|
|
199
|
+
} catch (error) {
|
|
200
|
+
started = false;
|
|
201
|
+
for (const end of stops) end();
|
|
202
|
+
stops = [];
|
|
203
|
+
cleanup?.();
|
|
204
|
+
cleanup = void 0;
|
|
205
|
+
throw error;
|
|
206
|
+
} finally {
|
|
207
|
+
starting = false;
|
|
208
|
+
}
|
|
209
|
+
};
|
|
210
|
+
const stop = () => {
|
|
211
|
+
started = false;
|
|
212
|
+
for (const end of stops) end();
|
|
213
|
+
stops = [];
|
|
214
|
+
cleanup?.();
|
|
215
|
+
cleanup = void 0;
|
|
216
|
+
if (state.waits) {
|
|
217
|
+
state.waits = false;
|
|
218
|
+
waiting.splice(waiting.indexOf(state), 1);
|
|
219
|
+
}
|
|
220
|
+
};
|
|
221
|
+
return Object.assign({
|
|
222
|
+
get() {
|
|
223
|
+
if (started) return out.v;
|
|
224
|
+
let value = out.v;
|
|
225
|
+
started = true;
|
|
226
|
+
try {
|
|
227
|
+
compute((next) => {
|
|
228
|
+
value = next;
|
|
229
|
+
});
|
|
230
|
+
} finally {
|
|
231
|
+
started = false;
|
|
232
|
+
cleanup?.();
|
|
233
|
+
cleanup = void 0;
|
|
234
|
+
}
|
|
235
|
+
return value;
|
|
236
|
+
},
|
|
237
|
+
subscribe(listener) {
|
|
238
|
+
const stopListening = out.subscribe(listener);
|
|
239
|
+
if (!started) try {
|
|
240
|
+
start();
|
|
241
|
+
} catch (error) {
|
|
242
|
+
stopListening();
|
|
243
|
+
throw error;
|
|
244
|
+
}
|
|
245
|
+
subscribers.add(stopListening);
|
|
246
|
+
return () => {
|
|
247
|
+
if (subscribers.delete(stopListening)) {
|
|
248
|
+
stopListening();
|
|
249
|
+
if (subscribers.size === 0) stop();
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
}
|
|
253
|
+
}, { d: level });
|
|
254
|
+
}
|
|
109
255
|
const BRIDGES = Symbol.for("brumate.bridges");
|
|
110
256
|
const BRIDGE_LOAD = Symbol.for("brumate.bridge-load");
|
|
111
257
|
/** The bridges by name, which any copy of the runtime shares. */
|
|
@@ -288,6 +434,6 @@ var Bridged = class {
|
|
|
288
434
|
}
|
|
289
435
|
};
|
|
290
436
|
//#endregion
|
|
291
|
-
export {
|
|
437
|
+
export { store as _, derived as a, isContext as c, isStore as d, nameBridge as f, setBridgeLoader as g, sentForeignStore as h, canSet as i, isContract as l, sendStore as m, Store as n, findStored as o, sameData as p, bridge as r, isBridged as s, Bridged as t, isForeignStore as u };
|
|
292
438
|
|
|
293
|
-
//# sourceMappingURL=store-
|
|
439
|
+
//# sourceMappingURL=store-Cy4EEyZ7.js.map
|