brumate 0.6.1 → 0.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/check.d.ts +3 -3
- package/dist/{boot-DkbcqdUz.d.ts → boot-Cs_P8cDu.d.ts} +2 -2
- package/dist/cli.js +77 -6
- package/dist/cli.js.map +1 -1
- package/dist/{client-CqGDbWd_.d.ts → client-BDPsTd4q.d.ts} +40 -14
- package/dist/{client-C3vRNuLi.js → client-DYIZ7BYK.js} +271 -112
- package/dist/client-DYIZ7BYK.js.map +1 -0
- package/dist/{client-routes-BtGpYCef.js → client-routes-BmPvNr4s.js} +10 -1
- package/dist/client-routes-BmPvNr4s.js.map +1 -0
- package/dist/{context-btHuB01Z.d.ts → context-BNgBXVUQ.d.ts} +7 -5
- package/dist/{context-CTiSzQRc.js → context-CU4Fpn5a.js} +10 -13
- package/dist/context-CU4Fpn5a.js.map +1 -0
- package/dist/{defer-M18UKyfG.js → defer-7JDhFxQq.js} +2 -2
- package/dist/{defer-M18UKyfG.js.map → defer-7JDhFxQq.js.map} +1 -1
- package/dist/{devtools-YnvrZ6D8.js → devtools-CzSp1GGq.js} +34 -24
- package/dist/devtools-CzSp1GGq.js.map +1 -0
- package/dist/{devtools-panel-DRcKclEG.js → devtools-panel-DugGrz7L.js} +32 -9
- package/dist/devtools-panel-DugGrz7L.js.map +1 -0
- package/dist/{features-CbgII-o7.js → features-DwMYKBIC.js} +6 -2
- package/dist/features-DwMYKBIC.js.map +1 -0
- package/dist/{files-HzPDUyTY.js → files-XX5yW3KL.js} +94 -3
- package/dist/files-XX5yW3KL.js.map +1 -0
- package/dist/index.d.ts +49 -0
- package/dist/index.js +3 -3
- package/dist/index.js.map +1 -1
- package/dist/{inspect-Q5W0A66e.js → inspect-B9cRF6AM.js} +2767 -2077
- package/dist/inspect-B9cRF6AM.js.map +1 -0
- package/dist/{loader-C-S3yzep.js → loader-BGSXt_Eb.js} +5 -5
- package/dist/{loader-C-S3yzep.js.map → loader-BGSXt_Eb.js.map} +1 -1
- package/dist/{rpc-C_znDZ_w.js → rpc-B9EkaPdU.js} +3 -3
- package/dist/{rpc-C_znDZ_w.js.map → rpc-B9EkaPdU.js.map} +1 -1
- package/dist/runtime/bundles.d.ts +1 -1
- package/dist/runtime/bundles.js +2 -0
- package/dist/runtime/bundles.js.map +1 -1
- package/dist/runtime/client.d.ts +4 -4
- package/dist/runtime/client.js +4 -4
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.js +1 -1
- package/dist/runtime/devtools.d.ts +15 -2
- package/dist/runtime/devtools.js +2 -2
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.d.ts +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/server.d.ts +4 -4
- package/dist/runtime/server.js +4 -4
- package/dist/runtime/signals.d.ts +2 -2
- package/dist/runtime/signals.js +43 -5
- package/dist/runtime/signals.js.map +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 -0
- package/dist/runtime/store.js +1 -0
- package/dist/runtime/testing.d.ts +2 -2
- package/dist/runtime/testing.js +2 -2
- package/dist/{search-params-CM1RWR2P.js → search-params-Cy3uRphR.js} +33 -8
- package/dist/search-params-Cy3uRphR.js.map +1 -0
- package/dist/{server-BcT9icQ4.js → server-C1OTFH4r.js} +127 -14
- package/dist/server-C1OTFH4r.js.map +1 -0
- package/dist/{server-dP_ucRiJ.d.ts → server-CavhuoFI.d.ts} +32 -8
- package/dist/{shared-CzbnWkVA.d.ts → shared-CRduzyi3.d.ts} +15 -2
- package/dist/{signals-BwD4u22K.d.ts → signals-DBnq9QRW.d.ts} +46 -6
- package/dist/{static-loader-DysAET-w.d.ts → static-loader-D5hvLQK7.d.ts} +2 -2
- package/dist/{static-loader-Bt2WDkY1.js → static-loader-XGXMzfJR.js} +3 -3
- package/dist/{static-loader-Bt2WDkY1.js.map → static-loader-XGXMzfJR.js.map} +1 -1
- package/dist/store-BIBAYZo-.js +293 -0
- package/dist/store-BIBAYZo-.js.map +1 -0
- package/dist/store-xlTzAM_r.d.ts +171 -0
- package/dist/{stream-DRjx0keF.js → stream-BBnArf_5.js} +89 -3
- package/dist/stream-BBnArf_5.js.map +1 -0
- package/dist/vite.d.ts +1 -1
- package/dist/vite.js +128 -13
- package/dist/vite.js.map +1 -1
- package/elements.d.ts +268 -21
- package/package.json +5 -1
- package/skills/brumate/SKILL.md +1 -1
- package/skills/brumate/references/errors.md +127 -9
- package/skills/brumate/references/signals.md +37 -30
- package/skills/brumate/references/state.md +3 -2
- package/dist/client-C3vRNuLi.js.map +0 -1
- package/dist/client-routes-BtGpYCef.js.map +0 -1
- package/dist/context-CTiSzQRc.js.map +0 -1
- package/dist/devtools-YnvrZ6D8.js.map +0 -1
- package/dist/devtools-panel-DRcKclEG.js.map +0 -1
- package/dist/features-CbgII-o7.js.map +0 -1
- package/dist/files-HzPDUyTY.js.map +0 -1
- package/dist/inspect-Q5W0A66e.js.map +0 -1
- package/dist/search-params-CM1RWR2P.js.map +0 -1
- package/dist/server-BcT9icQ4.js.map +0 -1
- package/dist/stream-DRjx0keF.js.map +0 -1
|
@@ -35,6 +35,15 @@ function shiftState(ids, state, by) {
|
|
|
35
35
|
return moved;
|
|
36
36
|
}
|
|
37
37
|
for (const type of holders) if (value instanceof type) return Object.assign(Object.create(Object.getPrototypeOf(value)), mapValues(value, shiftValue));
|
|
38
|
+
if (value?.k === "brumate.store") {
|
|
39
|
+
const store = value;
|
|
40
|
+
if (!seen.has(store)) {
|
|
41
|
+
seen.add(store);
|
|
42
|
+
if (store.o) store.o = [shiftId(store.o[0], by), ...store.o.slice(1)];
|
|
43
|
+
store.v = shiftValue(store.v);
|
|
44
|
+
}
|
|
45
|
+
return value;
|
|
46
|
+
}
|
|
38
47
|
if (value instanceof Promise) return value.then(shiftValue);
|
|
39
48
|
if (typeof value === "object" && value !== null && !seen.has(value)) {
|
|
40
49
|
seen.add(value);
|
|
@@ -134,4 +143,4 @@ const ready = import("./runtime/client.js").then(({ hooks, leavePage, leaveRoute
|
|
|
134
143
|
//#endregion
|
|
135
144
|
export { ready };
|
|
136
145
|
|
|
137
|
-
//# sourceMappingURL=client-routes-
|
|
146
|
+
//# sourceMappingURL=client-routes-BmPvNr4s.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-routes-BmPvNr4s.js","names":[],"sources":["../src/runtime/client-routes.ts"],"sourcesContent":["// What the core needs to read the pages that client navigation adds. Only\n// `navigate.ts` writes the attributes that this module reads, so the loader\n// imports it when it navigates or finds such a record, and a page that never\n// navigates does not load it. Importing it sets the core's `record` hook.\n//\n// It reads the core with `import()`, as `rpc.ts` does, and imports nothing\n// else. A static import of the core would make the package build move the\n// core into a chunk behind a module that only re-exports it, and a static\n// import of `shared.ts` would split that module out of the core of a page.\n// The core is loaded already, or loads with this module.\n\nimport type * as Client from './client.ts';\nimport type { Scope } from './client.ts';\nimport type { FieldKind, PageState, ScopeId, ScopeState } from './shared.ts';\n\n/** The parts of the core that this module uses. */\ntype Core = Pick<typeof Client, 'hooks' | 'removeScope' | 'scopeIds' | 'scopes'>;\n\n/** Reads an ID, as `parseId` in `shared.ts` does. This module imports no code of its own. */\nfunction readId(text: string): ScopeId {\n return /^-?\\d+$/.test(text) ? Number(text) : text;\n}\n\n/** Reads a list of scope IDs from text. An empty item is left out when `skipEmpty` is set. */\nfunction readIds(text: string, separator: string, skipEmpty: boolean): ScopeId[] {\n const ids: ScopeId[] = [];\n for (const part of text.split(separator)) {\n if (skipEmpty && !part) {\n continue;\n }\n ids.push(readId(part));\n }\n return ids;\n}\n\n/** Adds a number to an ID, as `shiftId` in `shared.ts` does. */\nfunction 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/** Makes an object with the same keys and the values that `map` returns. */\nfunction mapValues(object: object, map: (value: unknown) => unknown): object {\n const entries: [string, unknown][] = [];\n for (const [key, value] of Object.entries(object)) {\n entries.push([key, map(value)]);\n }\n return Object.fromEntries(entries);\n}\n\n/** Adds a number to the scope IDs of a state record, in the places that the table names. */\nexport function shiftState(ids: Core['scopeIds'], state: PageState, by: number): PageState {\n const { fields, references, holders } = ids;\n const seen = new Set<object>();\n function shiftValue(value: unknown): unknown {\n // A reference is copied with its own fields, and its scope moved.\n for (const type of references) {\n if (value instanceof type) {\n const moved = Object.assign(Object.create(Object.getPrototypeOf(value)), value, {\n scope: shiftId(value.scope, by),\n });\n // Children name the scope where the server rendered them too.\n if (moved.at !== undefined) {\n moved.at = shiftId(moved.at, by);\n }\n return moved;\n }\n }\n // A holder is copied with every field moved.\n for (const type of holders) {\n if (value instanceof type) {\n return Object.assign(\n Object.create(Object.getPrototypeOf(value)),\n mapValues(value, shiftValue),\n );\n }\n }\n // A store keeps its identity, so it moves in place: its origin, and its value, which can\n // hold references.\n // The mark is the one of `isStore` in `store.ts`, which this module does not import.\n if ((value as { k?: unknown } | null)?.k === 'brumate.store') {\n const store = value as { o?: [ScopeId, ...number[]]; v: unknown };\n if (!seen.has(store)) {\n seen.add(store);\n if (store.o) {\n store.o = [shiftId(store.o[0], by), ...store.o.slice(1)] as [ScopeId, ...number[]];\n }\n store.v = shiftValue(store.v);\n }\n return value;\n }\n // A later record settles it, with a value whose IDs move too.\n if (value instanceof Promise) {\n return value.then(shiftValue);\n }\n if (typeof value === 'object' && value !== null && !seen.has(value)) {\n seen.add(value);\n if (Array.isArray(value)) {\n for (const [index, item] of value.entries()) {\n // A hole stays a hole.\n if (!(index in value)) {\n continue;\n }\n value[index] = shiftValue(item);\n }\n } else if (Object.getPrototypeOf(value) === Object.prototype) {\n for (const [key, item] of Object.entries(value)) {\n (value as Record<string, unknown>)[key] = shiftValue(item);\n }\n }\n }\n return value;\n }\n function shiftField(field: unknown, kind: FieldKind): unknown {\n if (kind === 'id') {\n return shiftId(field as ScopeId, by);\n }\n if (kind === 'ids') {\n return mapValues(field as object, (id) => shiftId(id as ScopeId, by));\n }\n if (kind === 'values') {\n const moved: unknown[] = [];\n for (const item of field as unknown[]) {\n moved.push(shiftValue(item));\n }\n return moved;\n }\n return kind === 'map' ? mapValues(field as object, shiftValue) : shiftValue(field);\n }\n const result: PageState = {};\n for (const [key, record] of Object.entries(state)) {\n const moved: Record<string, unknown> = { ...record };\n for (const [name, kind] of Object.entries(fields)) {\n if (moved[name] !== undefined && kind !== 'none') {\n moved[name] = shiftField(moved[name], kind);\n }\n }\n result[shiftId(readId(key), by)] = moved as ScopeState;\n }\n return result;\n}\n\n/** Removes scopes and the scopes inside them, and runs their cleanups. */\nfunction dropScopes(core: Core, roots: Set<ScopeId>): void {\n function inside(scope: Scope): boolean {\n for (let current: Scope | undefined = scope; current; current = current.p ?? current.o) {\n if (roots.has(current.id)) {\n return true;\n }\n }\n return false;\n }\n // Deleting from a map while iterating it is safe.\n for (const scope of core.scopes.values()) {\n if (inside(scope)) {\n core.removeScope(scope);\n }\n }\n}\n\n/**\n * Reads the attributes that navigation set on a state record. A page whose\n * IDs started at another number, such as a prerendered file, has them moved\n * with `b-offset`. A page that replaced only some routes of the one before\n * it drops the old routes with `b-drop`, and adds only the scopes inside\n * `b-roots`, with the scopes of the kept layouts in place of the new\n * page's copies of them, by `b-alias`.\n */\nfunction routeRecord(core: Core, script: Element, state: PageState): PageState {\n // Only records with scopes hold IDs. Later records settle promises, which `shiftState` wraps.\n const offset = Number(script.getAttribute('b-offset') ?? 0);\n const value = offset ? shiftState(core.scopeIds, state, offset) : state;\n const drop = script.getAttribute('b-drop');\n if (drop) {\n dropScopes(core, new Set(readIds(drop, ',', false)));\n }\n const list = script.getAttribute('b-roots');\n if (list === null) {\n return value;\n }\n const roots = new Set(readIds(list, ',', true));\n const alias = new Map<ScopeId, ScopeId>();\n for (const pair of (script.getAttribute('b-alias') ?? '').split(',')) {\n if (!pair) {\n continue;\n }\n const [from, to] = readIds(pair, ':', false) as [ScopeId, ScopeId];\n alias.set(from, to);\n }\n function kept(id: ScopeId): boolean {\n for (let current: ScopeId | undefined = id; current !== undefined;) {\n if (roots.has(current)) {\n return true;\n }\n const record: ScopeState | undefined = value[current];\n current = record?.p ?? record?.o;\n }\n return false;\n }\n function resolve(id: ScopeId | undefined): ScopeId | undefined {\n return id === undefined ? undefined : (alias.get(id) ?? id);\n }\n const result: PageState = {};\n for (const [key, record] of Object.entries(value)) {\n // The new page renders the kept layouts again. Their scopes are not added.\n const id = readId(key);\n if (kept(id)) {\n result[id] = { ...record, p: resolve(record.p), o: resolve(record.o) };\n }\n }\n return result;\n}\n\n/**\n * Settles once the core reads records with this module, with the function\n * that forgets the page before navigation replaces it, or only stops reading\n * when layouts stay.\n */\nexport const ready: Promise<(partial: boolean) => void> = import('./client.ts').then(\n ({ hooks, leavePage, leaveRoutes, removeScope, scopeIds, scopes }) => {\n const core = {\n hooks,\n removeScope,\n scopeIds,\n scopes,\n };\n hooks.record = (script, state) => routeRecord(core, script, state);\n return (partial) => (partial ? leaveRoutes() : leavePage());\n },\n);\n"],"mappings":";;AAmBA,SAAS,OAAO,MAAuB;CACrC,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI;AAC/C;;AAGA,SAAS,QAAQ,MAAc,WAAmB,WAA+B;CAC/E,MAAM,MAAiB,CAAC;CACxB,KAAK,MAAM,QAAQ,KAAK,MAAM,SAAS,GAAG;EACxC,IAAI,aAAa,CAAC,MAChB;EAEF,IAAI,KAAK,OAAO,IAAI,CAAC;CACvB;CACA,OAAO;AACT;;AAGA,SAAS,QAAQ,IAAa,IAAqB;CACjD,IAAI,OAAO,OAAO,UAChB,OAAO,KAAK;CAEd,MAAM,MAAM,GAAG,QAAQ,GAAG;CAC1B,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,GAAG,CAAC,IAAI,KAAK,GAAG,MAAM,GAAG;AACxD;;AAGA,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O,sBAAc,CAAC,MAC7E,EAAE,OAAO,WAAW,aAAa,aAAa,UAAU,aAAa;CACpE,MAAM,OAAO;EACX;EACA;EACA;EACA;CACF;CACA,MAAM,UAAU,QAAQ,UAAU,YAAY,MAAM,QAAQ,KAAK;CACjE,QAAQ,YAAa,UAAU,YAAY,IAAI,UAAU;AAC3D,CACF"}
|
|
@@ -3,14 +3,16 @@
|
|
|
3
3
|
interface Context<T> {
|
|
4
4
|
/** The same on the server and the client, so the page state can name the context. */
|
|
5
5
|
readonly key: string;
|
|
6
|
-
/**
|
|
7
|
-
readonly
|
|
6
|
+
/** Only for the type: a context holds no value, and a component reads the value that a provider gave. */
|
|
7
|
+
readonly __type?: T;
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
10
|
* Creates a context. `key` names it in the page state, so it must be unique
|
|
11
11
|
* in the app and the same on the server and the client.
|
|
12
12
|
*/
|
|
13
|
-
declare function createContext<T>(key: string
|
|
13
|
+
declare function createContext<T>(key: string): Context<T>;
|
|
14
|
+
/** The error of a read of a context that no provider above the reader set. */
|
|
15
|
+
declare function missingContext(key: string): Error;
|
|
14
16
|
/** The route of the page, for `$route`. */
|
|
15
17
|
interface Route<P = Record<string, string>> {
|
|
16
18
|
/** The URL of the page. */
|
|
@@ -38,5 +40,5 @@ declare const routeContext: Context<Route>;
|
|
|
38
40
|
/** The context that `$navigation` reads. The loader writes it while a page loads. */
|
|
39
41
|
declare const navigationContext: Context<NavigationState>;
|
|
40
42
|
//#endregion
|
|
41
|
-
export { Route as a,
|
|
42
|
-
//# sourceMappingURL=context-
|
|
43
|
+
export { Route as a, navigationContext as c, ROUTE_KEY as i, routeContext as l, NAVIGATION_KEY as n, createContext as o, NavigationState as r, missingContext as s, Context as t };
|
|
44
|
+
//# sourceMappingURL=context-BNgBXVUQ.d.ts.map
|
|
@@ -3,25 +3,22 @@
|
|
|
3
3
|
* Creates a context. `key` names it in the page state, so it must be unique
|
|
4
4
|
* in the app and the same on the server and the client.
|
|
5
5
|
*/
|
|
6
|
-
function createContext(key
|
|
7
|
-
return {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
6
|
+
function createContext(key) {
|
|
7
|
+
return { key };
|
|
8
|
+
}
|
|
9
|
+
/** The error of a read of a context that no provider above the reader set. */
|
|
10
|
+
function missingContext(key) {
|
|
11
|
+
return /* @__PURE__ */ new Error(`The context "${key}" has no provider above this component. Provide it with $setContext, or in a parent that does`);
|
|
11
12
|
}
|
|
12
13
|
/** The key of the context of `$route`. The server and the loader write it. */
|
|
13
14
|
const ROUTE_KEY = "brumate.route";
|
|
14
15
|
/** The key of the context of `$navigation`. The loader writes it. */
|
|
15
16
|
const NAVIGATION_KEY = "brumate.navigation";
|
|
16
17
|
/** The context that `$route` reads. Its value comes from the request on the server, and from `location` in the browser. */
|
|
17
|
-
const routeContext = createContext(ROUTE_KEY
|
|
18
|
-
url: new URL("http://localhost/"),
|
|
19
|
-
search: new URLSearchParams(),
|
|
20
|
-
params: {}
|
|
21
|
-
});
|
|
18
|
+
const routeContext = createContext(ROUTE_KEY);
|
|
22
19
|
/** The context that `$navigation` reads. The loader writes it while a page loads. */
|
|
23
|
-
const navigationContext = createContext(NAVIGATION_KEY
|
|
20
|
+
const navigationContext = createContext(NAVIGATION_KEY);
|
|
24
21
|
//#endregion
|
|
25
|
-
export {
|
|
22
|
+
export { navigationContext as a, missingContext as i, ROUTE_KEY as n, routeContext as o, createContext as r, NAVIGATION_KEY as t };
|
|
26
23
|
|
|
27
|
-
//# sourceMappingURL=context-
|
|
24
|
+
//# sourceMappingURL=context-CU4Fpn5a.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-CU4Fpn5a.js","names":[],"sources":["../src/runtime/context.ts"],"sourcesContent":["/** A value that a component provides to the components inside it. */\nexport interface Context<T> {\n /** The same on the server and the client, so the page state can name the context. */\n readonly key: string;\n /** Only for the type: a context holds no value, and a component reads the value that a provider gave. */\n readonly __type?: T;\n}\n\n/**\n * Creates a context. `key` names it in the page state, so it must be unique\n * in the app and the same on the server and the client.\n */\nexport function createContext<T>(key: string): Context<T> {\n return { key };\n}\n\n/** The error of a read of a context that no provider above the reader set. */\nexport function missingContext(key: string): Error {\n return new Error(\n `The context \"${key}\" has no provider above this component. Provide it with $setContext, or in a parent that does`,\n );\n}\n\n/** The route of the page, for `$route`. */\nexport interface Route<P = Record<string, string>> {\n /** The URL of the page. */\n url: URL;\n /** The query string of the page, as `url.searchParams`. */\n search: URLSearchParams;\n /** The params of the route, such as `{ id: '3' }` for `/issues/[id]`. */\n params: P;\n}\n\n/** The navigation that loads, for `$navigation`. */\nexport interface NavigationState {\n /** True while a page loads without a full page load. */\n pending: boolean;\n /** The URL of the page that is left, while one loads. */\n from?: string;\n /** The URL of the page that loads. */\n to?: string;\n}\n\n/** The key of the context of `$route`. The server and the loader write it. */\nexport const ROUTE_KEY = 'brumate.route';\n/** The key of the context of `$navigation`. The loader writes it. */\nexport const NAVIGATION_KEY = 'brumate.navigation';\n\n/** The context that `$route` reads. Its value comes from the request on the server, and from `location` in the browser. */\nexport const routeContext: Context<Route> = createContext(ROUTE_KEY);\n\n/** The context that `$navigation` reads. The loader writes it while a page loads. */\nexport const navigationContext: Context<NavigationState> = createContext(NAVIGATION_KEY);\n"],"mappings":";;;;;AAYA,SAAgB,cAAiB,KAAyB;CACxD,OAAO,EAAE,IAAI;AACf;;AAGA,SAAgB,eAAe,KAAoB;CACjD,uBAAO,IAAI,MACT,gBAAgB,IAAI,8FACtB;AACF;;AAuBA,MAAa,YAAY;;AAEzB,MAAa,iBAAiB;;AAG9B,MAAa,eAA+B,cAAc,SAAS;;AAGnE,MAAa,oBAA8C,cAAc,cAAc"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { hn as build, yn as skew } from "./client-DYIZ7BYK.js";
|
|
2
2
|
import { n as trustedHTML, r as trustedScript } from "./skew-FRmAy9iy.js";
|
|
3
3
|
//#region src/runtime/defer.ts
|
|
4
4
|
/** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */
|
|
@@ -53,4 +53,4 @@ async function loadDeferred(template) {
|
|
|
53
53
|
//#endregion
|
|
54
54
|
export { loadDeferred };
|
|
55
55
|
|
|
56
|
-
//# sourceMappingURL=defer-
|
|
56
|
+
//# sourceMappingURL=defer-7JDhFxQq.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"defer-
|
|
1
|
+
{"version":3,"file":"defer-7JDhFxQq.js","names":[],"sources":["../src/runtime/defer.ts"],"sourcesContent":["// Loads the body of a `#defer` block. The loader imports this module when\n// the block's trigger fires, so a page without `#defer` does not load it.\n//\n// The server renders the route again for the request and answers with what\n// it streams for a `#loading` body that is ready: the body in a\n// `<template b-l>`, the script that swaps it in, and its state records.\n// This module adds that markup to the page and runs its scripts, in order.\n\nimport { build, skew } from './client.ts';\nimport { trustedHTML, trustedScript } from './trusted.ts';\n/** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */\nfunction readNonce(script: HTMLScriptElement): string | null {\n return script.nonce || script.getAttribute('nonce');\n}\n\n/** The Content Security Policy nonce of the page, which the scripts of the answer need to run. */\nfunction pageNonce(): string | undefined {\n for (const script of document.querySelectorAll('script')) {\n const nonce = readNonce(script);\n if (nonce) {\n return nonce;\n }\n }\n return undefined;\n}\n\n/** The templates whose bodies were asked for. */\nconst requested = new WeakSet<Element>();\n\n/**\n * Asks the server for the body of the `#defer` block of a `<template\n * b-defer>`, and puts it in place of the fallback. When the server cannot\n * render it, such as a page that changed since it loaded, or a static host\n * that answers with the whole page, the fallback stays.\n */\nexport async function loadDeferred(template: Element): Promise<void> {\n // Once, so the devtools can fire the trigger before the loader does.\n if (requested.has(template)) {\n return;\n }\n requested.add(template);\n const [, boundary, base] = template.getAttribute('b-defer')!.split(':') as [\n string,\n string,\n string,\n ];\n const response = await fetch(location.href, {\n headers: {\n 'x-brumate-defer': `${boundary} ${template.getAttribute('b-b')}`,\n 'x-brumate-base': base,\n ...(build === undefined ? {} : { 'x-brumate-build': build }),\n },\n });\n if (response.status === 409 && response.headers.get('x-brumate-build')) {\n // The site changed since the page loaded. The fallback stays, and the next page loads in full.\n skew('defer');\n return;\n }\n if (!response.ok || response.headers.get('x-brumate-defer') !== boundary) {\n return;\n }\n const parsed = document.createElement('template');\n parsed.innerHTML = trustedHTML(await response.text());\n const nonce = pageNonce();\n // A copy, because appending moves nodes out of the live list.\n for (const node of Array.from(parsed.content.childNodes)) {\n if (node.nodeName !== 'SCRIPT') {\n document.body.append(node);\n continue;\n }\n // A script from `innerHTML` does not run, so a copy goes in its place.\n const script = node as HTMLScriptElement;\n const copy = document.createElement('script');\n for (const attribute of script.attributes) {\n if (attribute.name !== 'nonce') {\n copy.setAttribute(attribute.name, attribute.value);\n }\n }\n if (nonce) {\n copy.nonce = nonce;\n }\n copy.textContent = trustedScript(script.textContent ?? '');\n document.body.append(copy);\n }\n}\n"],"mappings":";;;;AAWA,SAAS,UAAU,QAA0C;CAC3D,OAAO,OAAO,SAAS,OAAO,aAAa,OAAO;AACpD;;AAGA,SAAS,YAAgC;CACvC,KAAK,MAAM,UAAU,SAAS,iBAAiB,QAAQ,GAAG;EACxD,MAAM,QAAQ,UAAU,MAAM;EAC9B,IAAI,OACF,OAAO;CAEX;AAEF;;AAGA,MAAM,4BAAY,IAAI,QAAiB;;;;;;;AAQvC,eAAsB,aAAa,UAAkC;CAEnE,IAAI,UAAU,IAAI,QAAQ,GACxB;CAEF,UAAU,IAAI,QAAQ;CACtB,MAAM,GAAG,UAAU,QAAQ,SAAS,aAAa,SAAS,CAAC,CAAE,MAAM,GAAG;CAKtE,MAAM,WAAW,MAAM,MAAM,SAAS,MAAM,EAC1C,SAAS;EACP,mBAAmB,GAAG,SAAS,GAAG,SAAS,aAAa,KAAK;EAC7D,kBAAkB;EAClB,GAAI,UAAU,KAAA,IAAY,CAAC,IAAI,EAAE,mBAAmB,MAAM;CAC5D,EACF,CAAC;CACD,IAAI,SAAS,WAAW,OAAO,SAAS,QAAQ,IAAI,iBAAiB,GAAG;EAEtE,KAAK,OAAO;EACZ;CACF;CACA,IAAI,CAAC,SAAS,MAAM,SAAS,QAAQ,IAAI,iBAAiB,MAAM,UAC9D;CAEF,MAAM,SAAS,SAAS,cAAc,UAAU;CAChD,OAAO,YAAY,YAAY,MAAM,SAAS,KAAK,CAAC;CACpD,MAAM,QAAQ,UAAU;CAExB,KAAK,MAAM,QAAQ,MAAM,KAAK,OAAO,QAAQ,UAAU,GAAG;EACxD,IAAI,KAAK,aAAa,UAAU;GAC9B,SAAS,KAAK,OAAO,IAAI;GACzB;EACF;EAEA,MAAM,SAAS;EACf,MAAM,OAAO,SAAS,cAAc,QAAQ;EAC5C,KAAK,MAAM,aAAa,OAAO,YAC7B,IAAI,UAAU,SAAS,SACrB,KAAK,aAAa,UAAU,MAAM,UAAU,KAAK;EAGrD,IAAI,OACF,KAAK,QAAQ;EAEf,KAAK,cAAc,cAAc,OAAO,eAAe,EAAE;EACzD,SAAS,KAAK,OAAO,IAAI;CAC3B;AACF"}
|
|
@@ -21,6 +21,25 @@ function preview(value) {
|
|
|
21
21
|
return String(value);
|
|
22
22
|
}
|
|
23
23
|
/**
|
|
24
|
+
* The state of a block after an event. A rendered block stays rendered. A `#defer` loads when
|
|
25
|
+
* it fires, and fails when its request settles with the fallback still shown. A `$client`
|
|
26
|
+
* callback has rendered once it fired. A `#client` block waits for its marker.
|
|
27
|
+
*/
|
|
28
|
+
function nextBlockState(block, event) {
|
|
29
|
+
if (block.state === "rendered" || event === "rendered") return "rendered";
|
|
30
|
+
if (event === "settled") return block.state === "loading" ? "failed" : block.state;
|
|
31
|
+
if (block.kind === "defer") return "loading";
|
|
32
|
+
return block.kind === "$client" ? "rendered" : block.state;
|
|
33
|
+
}
|
|
34
|
+
/** Moves a block to its state after an event. Returns true when the state changed. */
|
|
35
|
+
function moveBlock(block, event, now) {
|
|
36
|
+
const next = nextBlockState(block, event);
|
|
37
|
+
if (next === block.state) return false;
|
|
38
|
+
block.state = next;
|
|
39
|
+
if (next === "rendered") block.rendered = now;
|
|
40
|
+
return true;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
24
43
|
* Reads the blocks of the page from their markers, and updates their state.
|
|
25
44
|
* Returns true when something changed.
|
|
26
45
|
*
|
|
@@ -42,7 +61,7 @@ function scanBlocks(state) {
|
|
|
42
61
|
else if (/^b-?[\d.]+:\d+/.test(data)) markers.set(data.slice(1).split(":").slice(0, 2).join(":"), node);
|
|
43
62
|
}
|
|
44
63
|
const seen = /* @__PURE__ */ new Set();
|
|
45
|
-
function update(key, make,
|
|
64
|
+
function update(key, make, rendered) {
|
|
46
65
|
seen.add(key);
|
|
47
66
|
let block = state.blocks.get(key);
|
|
48
67
|
if (!block) {
|
|
@@ -50,11 +69,7 @@ function scanBlocks(state) {
|
|
|
50
69
|
state.blocks.set(key, block);
|
|
51
70
|
changed = true;
|
|
52
71
|
}
|
|
53
|
-
if (block
|
|
54
|
-
if (block.state === "loading" && next === "waiting") return;
|
|
55
|
-
block.state = next;
|
|
56
|
-
if (next === "rendered") block.rendered = now;
|
|
57
|
-
changed = true;
|
|
72
|
+
if (rendered && moveBlock(block, "rendered", now)) changed = true;
|
|
58
73
|
}
|
|
59
74
|
const deferBoundaries = /* @__PURE__ */ new Set();
|
|
60
75
|
for (const template of document.querySelectorAll("template[b-defer]")) {
|
|
@@ -67,14 +82,14 @@ function scanBlocks(state) {
|
|
|
67
82
|
template,
|
|
68
83
|
state: "waiting",
|
|
69
84
|
seen: now
|
|
70
|
-
}), open.has(boundary)
|
|
85
|
+
}), !open.has(boundary));
|
|
71
86
|
}
|
|
72
87
|
for (const boundary of open.keys()) if (!deferBoundaries.has(boundary)) update(`loading:${boundary}`, () => ({
|
|
73
88
|
kind: "loading",
|
|
74
89
|
id: boundary,
|
|
75
90
|
state: "streaming",
|
|
76
91
|
seen: now
|
|
77
|
-
}),
|
|
92
|
+
}), false);
|
|
78
93
|
for (const template of document.querySelectorAll("template[b-client]")) {
|
|
79
94
|
const [trigger, ref] = template.getAttribute("b-client").split("=");
|
|
80
95
|
const id = template.getAttribute("b-b") ?? "";
|
|
@@ -88,16 +103,12 @@ function scanBlocks(state) {
|
|
|
88
103
|
template,
|
|
89
104
|
state: "waiting",
|
|
90
105
|
seen: now
|
|
91
|
-
}), (block ? marker && marker.data.split(":").length > 2 : state.blocks.get(`client:${id}`)?.fired)
|
|
106
|
+
}), Boolean(block ? marker && marker.data.split(":").length > 2 : state.blocks.get(`client:${id}`)?.fired));
|
|
92
107
|
}
|
|
93
108
|
for (const [key, block] of state.blocks) {
|
|
94
109
|
if (seen.has(key)) continue;
|
|
95
110
|
if (block.kind === "loading") {
|
|
96
|
-
if (block
|
|
97
|
-
block.state = "rendered";
|
|
98
|
-
block.rendered = now;
|
|
99
|
-
changed = true;
|
|
100
|
-
}
|
|
111
|
+
if (moveBlock(block, "rendered", now)) changed = true;
|
|
101
112
|
} else if (!block.template?.isConnected) {
|
|
102
113
|
state.blocks.delete(key);
|
|
103
114
|
changed = true;
|
|
@@ -136,7 +147,7 @@ function reportError(state, payload, source) {
|
|
|
136
147
|
}
|
|
137
148
|
/** The code of the panel, which loads when it opens. */
|
|
138
149
|
function panelModule() {
|
|
139
|
-
return import("./devtools-panel-
|
|
150
|
+
return import("./devtools-panel-DugGrz7L.js");
|
|
140
151
|
}
|
|
141
152
|
/** Where the choice to outline changed elements is kept. */
|
|
142
153
|
const FLASH_KEY = "brumate:devtools:flash";
|
|
@@ -309,10 +320,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
309
320
|
}
|
|
310
321
|
if (block && block.fired === void 0) {
|
|
311
322
|
block.fired = performance.now();
|
|
312
|
-
|
|
313
|
-
block.state = "rendered";
|
|
314
|
-
block.rendered = block.fired;
|
|
315
|
-
}
|
|
323
|
+
moveBlock(block, "fired", block.fired);
|
|
316
324
|
}
|
|
317
325
|
}
|
|
318
326
|
add({
|
|
@@ -428,17 +436,19 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
428
436
|
block = item;
|
|
429
437
|
break;
|
|
430
438
|
}
|
|
439
|
+
const asked = block !== void 0 && block.state !== "loading";
|
|
431
440
|
if (block) {
|
|
432
441
|
block.fired ??= performance.now();
|
|
433
|
-
block
|
|
442
|
+
moveBlock(block, "fired", block.fired);
|
|
434
443
|
}
|
|
435
444
|
done.finally(() => {
|
|
436
445
|
scanBlocks(state);
|
|
446
|
+
if (block && asked) moveBlock(block, "settled", performance.now());
|
|
437
447
|
state.changed?.();
|
|
438
448
|
});
|
|
439
449
|
}
|
|
440
450
|
state.fire = (block) => {
|
|
441
|
-
if (block.kind === "defer" && block.template) deferred(block.template, import("./defer-
|
|
451
|
+
if (block.kind === "defer" && block.template) deferred(block.template, import("./defer-7JDhFxQq.js").then((module) => module.loadDeferred(block.template)));
|
|
442
452
|
else if (block.template && block.ref) state.handle?.(block.template, block.ref);
|
|
443
453
|
};
|
|
444
454
|
if (typeof MutationObserver !== "undefined") {
|
|
@@ -543,7 +553,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
543
553
|
}
|
|
544
554
|
});
|
|
545
555
|
state.open = (tab) => {
|
|
546
|
-
import("./devtools-panel-
|
|
556
|
+
import("./devtools-panel-DugGrz7L.js").then(({ openPanel }) => openPanel(root, state, tab));
|
|
547
557
|
};
|
|
548
558
|
root.append(style, button);
|
|
549
559
|
installFlash(state, root, host);
|
|
@@ -592,6 +602,6 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate", met
|
|
|
592
602
|
return state;
|
|
593
603
|
}
|
|
594
604
|
//#endregion
|
|
595
|
-
export {
|
|
605
|
+
export { preview as a, nextBlockState as i, installDevtools as n, reportError as o, moveBlock as r, scanBlocks as s, findRootScope as t };
|
|
596
606
|
|
|
597
|
-
//# sourceMappingURL=devtools-
|
|
607
|
+
//# sourceMappingURL=devtools-CzSp1GGq.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools-CzSp1GGq.js","names":[],"sources":["../src/runtime/devtools.ts"],"sourcesContent":["// The devtools overlay of development builds. This module only listens to\n// the core and shows a button. The panel loads when the button is pressed,\n// so the page behaves as in production until then.\n\nimport type { NavigationReport } from './navigate.ts';\nimport type { DevtoolsHooks, Scope } from './client.ts';\nimport type * as Panel from './devtools-panel.ts';\nimport type { ScopeId } from './shared.ts';\n\n// The same key as the core's, without importing the core.\nconst DEVTOOLS = Symbol.for('brumate.devtools');\n\n/** Something that happened on the page, for the log of the panel. */\nexport interface DevtoolsEntry {\n time: number;\n kind: 'handler' | 'write' | 'call';\n text: string;\n /** The scope of a write, so the panel can mark it. */\n scope?: ScopeId;\n /** For a write: the component, the scope in the compiled component, and the slot. */\n write?: { component: string; k: number; slot: number };\n}\n\n/** What the plugin tells the devtools about the dev server. */\nexport interface DevtoolsMeta {\n version?: string;\n vite?: string;\n}\n\n/** An error for the Errors tab: of a render on the server, of Vite, or of code in the browser. */\nexport interface ErrorEntry {\n time: number;\n source: 'server' | 'compile' | 'browser';\n message: string;\n stack?: string;\n /** The lines around the error, as Vite's overlay shows them. */\n frame?: string;\n /** The place of the error, such as a compile error in a `.brm` file. */\n loc?: { file: string; line: number; column: number };\n /** The plugin that threw it, such as `brumate`. */\n plugin?: string;\n}\n\n/** What Vite's overlay gets, and what `errorPage` sends. */\nexport interface ErrorPayload {\n message: string;\n stack?: string;\n frame?: string;\n plugin?: string;\n id?: string;\n loc?: { file?: string; line: number; column: number };\n}\n\n/** The part of `import.meta.hot` that the devtools listen to. */\ninterface HotContext {\n on(event: string, listener: (payload: never) => void): void;\n}\n\n/** A server function call, for the Timeline tab. */\nexport interface CallTiming {\n name: string;\n start: number;\n end?: number;\n /** The status of the answer, `redirect` for a redirect, or `failed`. */\n status?: number | 'redirect' | 'failed';\n /** How long the function took on the server, from the `Server-Timing` of the dev server. */\n server?: number;\n}\n\n/** A batch of updates that a write ran, with its effects. */\nexport interface UpdateTiming {\n count: number;\n start: number;\n end: number;\n}\n\n/**\n * A handler that ran, for the Timeline tab: when its event came, when its\n * code was ready and the handlers before it had started, when its call\n * returned, and when the promise of an async handler settled. The server\n * calls and the updates that ran meanwhile are its own.\n */\nexport interface Interaction {\n ref: string;\n /** What happened, such as `click on <button>`. */\n label: string;\n begun: number;\n ready: number;\n end: number;\n settled?: number;\n failed?: boolean;\n calls: CallTiming[];\n updates: UpdateTiming[];\n}\n\n/** A block of the page that renders later, for the Blocks tab. */\nexport interface BlockEntry {\n kind: 'loading' | 'defer' | 'client' | '$client';\n /** The boundary of `#loading` and `#defer`, or the `b-b` of the template of the others. */\n id: string;\n /** The trigger of `#defer`, `#client` and `$client`. */\n trigger?: string;\n /** The reference that `#client` and `$client` run. */\n ref?: string;\n /** The template that the loader reads for `#defer`, `#client` and `$client`. */\n template?: Element;\n state: 'waiting' | 'loading' | 'streaming' | 'rendered' | 'failed';\n /** When the panel first saw the block, when its trigger fired, and when it rendered. */\n seen: number;\n fired?: number;\n rendered?: number;\n /** True while the devtools show its fallback in place of its body. */\n fallback?: boolean;\n}\n\n/** An effect or a `$client` callback of a scope, with how it ran. */\nexport interface EffectEntry {\n scope: ScopeId;\n /** The ID of the component of the scope, and the scope's number in it. */\n component: string;\n k: number;\n /** Its name in the update code: `e<n>` for an effect, `c<n>` for a `$client` callback. */\n name: string;\n runs: number;\n /** When its last runs were, the newest last, at most 50. */\n recent: number[];\n /** The time of all its runs, in milliseconds. */\n time: number;\n cleanups: number;\n lastCleanup?: number;\n /** False once its cleanup ran and it has not run again, such as in a removed scope. */\n active: boolean;\n}\n\nexport interface DevtoolsState {\n scopes?: Map<ScopeId, Scope>;\n /** Writes a slot, as a handler does, so the page updates. */\n set?: (scope: Scope, slot: number, value: unknown) => void;\n /** Runs a reference for an element, as the loader does for a trigger. */\n handle?: (element: Element, ref: string, event?: Event) => Promise<unknown>;\n log: DevtoolsEntry[];\n /** The blocks of the page, by kind and ID. */\n blocks: Map<string, BlockEntry>;\n /** Asks the server for the body of a `#defer` block now. */\n fire?: (block: BlockEntry) => void;\n /**\n * Shows the fallback of a `#loading` or `#defer` block in place of its\n * body, or its body again. False when the page did not keep its fallback.\n */\n showFallback?: (block: BlockEntry, on: boolean) => boolean;\n /** The scopes written since the panel last drew, by scope ID. */\n written: Set<ScopeId>;\n /** The URL prefix of the inspect endpoint of the dev server. */\n endpoint: string;\n /** The versions of brumate and Vite, from the plugin. */\n meta: DevtoolsMeta;\n /** The errors of the page, oldest first. */\n errors: ErrorEntry[];\n /** The handlers that ran, oldest first, with their calls and updates. */\n timeline: Interaction[];\n /** The effects and `$client` callbacks that ran, by scope and name. */\n effects: Map<string, EffectEntry>;\n /** The client navigations of the page, newest last, at most 20. */\n navigations: NavigationReport[];\n /** Opens the panel on a tab, such as `errors`. */\n open?: (tab: string) => void;\n /** Shows the number of errors on the tab. */\n errorCount?: () => void;\n /** True while the elements that change are outlined on the page. */\n flash: boolean;\n /** Turns the outlines of changed elements on or off, and keeps the choice. */\n setFlash?: (on: boolean) => void;\n /** While the panel is open: sets its top edge to a place of the pointer, and keeps it. */\n resize?: (clientY: number) => void;\n resized?: () => void;\n /** Called after each change, while the panel is open. */\n changed?: () => void;\n}\n\nconst MAX_LOG = 300;\n\nimport { LOGO } from './logo.ts';\n\nexport { LOGO };\n\n/** The root scope of a scope, whose `m` names its component. */\nexport function findRootScope(scope: Scope): Scope {\n let root = scope;\n while (root.p) {\n root = root.p;\n }\n return root;\n}\n\n/** A short text for a value in the log. */\nexport function preview(value: unknown): string {\n if (typeof value === 'string') {\n return JSON.stringify(value.length > 40 ? `${value.slice(0, 40)}…` : value);\n }\n if (typeof value === 'function') {\n return 'function';\n }\n if (Array.isArray(value)) {\n return `Array(${value.length})`;\n }\n if (value instanceof Element) {\n return `<${value.tagName.toLowerCase()}>`;\n }\n if (value !== null && typeof value === 'object') {\n const name = value.constructor?.name;\n return name && name !== 'Object' ? name : `{${Object.keys(value).slice(0, 3).join(', ')}}`;\n }\n return String(value);\n}\n\n/**\n * What happens to a block. `rendered`: the markers of the page show its body. `fired`: its trigger\n * fired. `settled`: the request for the body of a `#defer` settled.\n */\nexport type BlockEvent = 'rendered' | 'fired' | 'settled';\n\n/**\n * The state of a block after an event. A rendered block stays rendered. A `#defer` loads when\n * it fires, and fails when its request settles with the fallback still shown. A `$client`\n * callback has rendered once it fired. A `#client` block waits for its marker.\n */\nexport function nextBlockState(block: BlockEntry, event: BlockEvent): BlockEntry['state'] {\n if (block.state === 'rendered' || event === 'rendered') {\n return 'rendered';\n }\n if (event === 'settled') {\n return block.state === 'loading' ? 'failed' : block.state;\n }\n if (block.kind === 'defer') {\n return 'loading';\n }\n return block.kind === '$client' ? 'rendered' : block.state;\n}\n\n/** Moves a block to its state after an event. Returns true when the state changed. */\nexport function moveBlock(block: BlockEntry, event: BlockEvent, now: number): boolean {\n const next = nextBlockState(block, event);\n if (next === block.state) {\n return false;\n }\n block.state = next;\n if (next === 'rendered') {\n block.rendered = now;\n }\n return true;\n}\n\n/**\n * Reads the blocks of the page from their markers, and updates their state.\n * Returns true when something changed.\n *\n * - `#defer`: a `<template b-defer>`, and `<!--l…-->` around its fallback until its body arrives.\n * - `#loading`: `<!--l…-->` around its fallback until the server streams its body.\n * - `#client`: a `<template b-client>` with a `#k` reference, and a marker that gets `:1` once\n * its body rendered.\n * - `$client`: a `<template b-client>` with a `#c` reference.\n */\nexport function scanBlocks(state: DevtoolsState): boolean {\n const now = performance.now();\n let changed = false;\n const open = new Map<string, Comment>();\n const markers = new Map<string, Comment>();\n const walker = document.createTreeWalker(document, NodeFilter.SHOW_COMMENT);\n for (let node = walker.nextNode(); node; node = walker.nextNode()) {\n const data = (node as Comment).data;\n if (/^l[\\d.-]+$/.test(data)) {\n open.set(data.slice(1), node as Comment);\n } else if (/^b-?[\\d.]+:\\d+/.test(data)) {\n markers.set(data.slice(1).split(':').slice(0, 2).join(':'), node as Comment);\n }\n }\n const seen = new Set<string>();\n function update(key: string, make: () => BlockEntry, rendered: boolean): void {\n seen.add(key);\n let block = state.blocks.get(key);\n if (!block) {\n block = make();\n state.blocks.set(key, block);\n changed = true;\n }\n if (rendered && moveBlock(block, 'rendered', now)) {\n changed = true;\n }\n }\n const deferBoundaries = new Set<string>();\n for (const template of document.querySelectorAll('template[b-defer]')) {\n const [trigger, boundary] = template.getAttribute('b-defer')!.split(':') as [string, string];\n deferBoundaries.add(boundary);\n update(\n `defer:${boundary}`,\n () => ({ kind: 'defer', id: boundary, trigger, template, state: 'waiting', seen: now }),\n !open.has(boundary),\n );\n }\n for (const boundary of open.keys()) {\n if (!deferBoundaries.has(boundary)) {\n update(\n `loading:${boundary}`,\n () => ({ kind: 'loading', id: boundary, state: 'streaming', seen: now }),\n false,\n );\n }\n }\n for (const template of document.querySelectorAll('template[b-client]')) {\n const [trigger, ref] = template.getAttribute('b-client')!.split('=') as [string, string];\n const id = template.getAttribute('b-b') ?? '';\n const block = /#k\\d+$/.test(ref);\n const marker = markers.get(id);\n update(\n `client:${id}`,\n () => ({\n kind: block ? 'client' : '$client',\n id,\n trigger,\n ref,\n template,\n state: 'waiting',\n seen: now,\n }),\n // A `$client` callback has run once its trigger fired.\n Boolean(\n block\n ? marker && marker.data.split(':').length > 2\n : state.blocks.get(`client:${id}`)?.fired,\n ),\n );\n }\n // A `#loading` block whose markers are gone rendered its body. Other blocks that left the page,\n // such as on navigation, are dropped.\n for (const [key, block] of state.blocks) {\n if (seen.has(key)) {\n continue;\n }\n if (block.kind === 'loading') {\n if (moveBlock(block, 'rendered', now)) {\n changed = true;\n }\n } else if (!block.template?.isConnected) {\n state.blocks.delete(key);\n changed = true;\n }\n }\n return changed;\n}\n\n/**\n * Adds an error to the Errors tab. An error of the server or of Vite opens\n * the panel on it, as Vite's overlay would. An error of the browser only\n * counts on the button.\n */\nexport function reportError(\n state: DevtoolsState,\n payload: ErrorPayload,\n source: ErrorEntry['source'],\n): void {\n const file = payload.loc?.file ?? payload.id;\n const entry: ErrorEntry = {\n time: performance.now(),\n // An error of a plugin, such as a compile error, is one, even when a render met it.\n source: source === 'server' && payload.plugin ? 'compile' : source,\n message: payload.message,\n ...(payload.stack ? { stack: payload.stack } : {}),\n ...(payload.frame ? { frame: payload.frame } : {}),\n ...(payload.plugin ? { plugin: payload.plugin } : {}),\n ...(payload.loc && file\n ? { loc: { file, line: payload.loc.line, column: payload.loc.column } }\n : {}),\n };\n // The same error again, such as on each request for the page, counts once.\n const last = state.errors.at(-1);\n if (last?.message !== entry.message || last.stack !== entry.stack) {\n state.errors.push(entry);\n if (state.errors.length > 50) {\n state.errors.shift();\n }\n }\n state.errorCount?.();\n state.changed?.();\n if (source !== 'browser') {\n state.open?.('errors');\n }\n}\n\n/** The code of the panel, which loads when it opens. */\nfunction panelModule(): Promise<typeof Panel> {\n return import('./devtools-panel.ts');\n}\n\n/** Where the choice to outline changed elements is kept. */\nconst FLASH_KEY = 'brumate:devtools:flash';\n/** How long an outline shows. */\nconst FLASH_MS = 700;\n/** The most outlines that one frame draws, so a big change does not stall the page. */\nconst MAX_FLASHES = 200;\n\n/** The class of an outline, by how many times the element changed in the last second. */\nfunction heatClass(count: number): string {\n if (count >= 5) {\n return 'hot';\n }\n return count >= 2 ? 'warm' : '';\n}\n\n/**\n * Outlines the elements that change, as an update writes them: green for an\n * element that changes now and then, yellow and red for one that changes\n * often. A MutationObserver sees every change of the page, so it needs no\n * hook of the core. The outlines are drawn in the shadow root, so the page\n * itself does not change.\n */\nfunction installFlash(state: DevtoolsState, root: ShadowRoot, host: Element): void {\n const layer = document.createElement('div');\n layer.className = 'flashes';\n root.append(layer);\n // How many times each element changed lately, for its colour.\n const heat = new WeakMap<Element, { count: number; time: number }>();\n const pending = new Set<Element>();\n let frame = 0;\n function draw(): void {\n frame = 0;\n let drawn = 0;\n for (const target of pending) {\n if (drawn >= MAX_FLASHES) {\n break;\n }\n const rect = target.getBoundingClientRect();\n if (rect.width === 0 && rect.height === 0) {\n continue;\n }\n const now = performance.now();\n const last = heat.get(target);\n const count = last && now - last.time < 1000 ? last.count + 1 : 1;\n heat.set(target, { count, time: now });\n const box = document.createElement('div');\n box.className = `flash ${heatClass(count)}`;\n box.style.cssText = `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`;\n layer.append(box);\n setTimeout(() => box.remove(), FLASH_MS);\n drawn++;\n }\n pending.clear();\n }\n const observer = new MutationObserver((records) => {\n for (const record of records) {\n let target: Node | null = record.target;\n if (record.type === 'childList') {\n // The elements that came in, or else the element that lost some.\n let added = 0;\n for (const node of record.addedNodes) {\n if (node.nodeType === 1) {\n pending.add(node as Element);\n added++;\n }\n }\n if (added > 0) {\n continue;\n }\n }\n if (target.nodeType !== 1) {\n target = target.parentElement;\n }\n if (\n target &&\n target !== host &&\n target !== document.documentElement &&\n target !== document.body\n ) {\n pending.add(target as Element);\n }\n }\n for (const target of pending) {\n // The devtools change their own markup, and the host carries their styles.\n if (target === host || host.contains(target)) {\n pending.delete(target);\n }\n }\n if (pending.size > 0 && frame === 0) {\n frame = requestAnimationFrame(draw);\n }\n });\n state.setFlash = (on) => {\n state.flash = on;\n if (on) {\n observer.observe(document.documentElement, {\n subtree: true,\n childList: true,\n attributes: true,\n characterData: true,\n });\n } else {\n observer.disconnect();\n pending.clear();\n layer.replaceChildren();\n }\n try {\n localStorage.setItem(FLASH_KEY, on ? '1' : '0');\n } catch {\n // Storage can be off.\n }\n state.changed?.();\n };\n let saved = false;\n try {\n saved = localStorage.getItem(FLASH_KEY) === '1';\n } catch {\n // Storage can be off.\n }\n if (saved) {\n state.setFlash(true);\n }\n}\n\n/** True for an error of code that is not of the page, such as of a browser extension. */\nfunction foreign(stack: string | undefined, file = ''): boolean {\n return (\n /^[a-z-]+-extension:/.test(file) ||\n (stack !== undefined &&\n /[a-z-]+-extension:\\/\\//.test(stack) &&\n !stack.includes(location.origin))\n );\n}\n\n/** Listens to the core, and adds the button that opens the panel. */\nexport function installDevtools(\n endpoint = '/__brumate/inspect',\n rpc = '/_brumate',\n meta: DevtoolsMeta = {},\n hot?: HotContext,\n): DevtoolsState {\n const state: DevtoolsState = {\n log: [],\n blocks: new Map(),\n written: new Set(),\n endpoint,\n meta,\n errors: [],\n timeline: [],\n effects: new Map(),\n navigations: [],\n flash: false,\n };\n /** The handler that a server call or an update that starts now belongs to. */\n function owner(time: number): Interaction | undefined {\n for (let index = state.timeline.length - 1; index >= 0; index--) {\n const run = state.timeline[index]!;\n // An update of the answer of a call comes a moment after the handler settled.\n if (run.begun <= time && (run.settled === undefined || time <= run.settled + 32)) {\n return run;\n }\n }\n return undefined;\n }\n function add(entry: Omit<DevtoolsEntry, 'time'>): void {\n state.log.push({ ...entry, time: performance.now() });\n if (state.log.length > MAX_LOG) {\n state.log.splice(0, state.log.length - MAX_LOG);\n }\n state.changed?.();\n }\n const hooks: DevtoolsHooks = {\n attach(core) {\n state.scopes = core.scopes;\n state.set = core.set;\n state.handle = core.handle;\n state.changed?.();\n },\n handled(run) {\n const entry: Interaction = {\n ref: run.ref,\n label: `${run.event ?? 'call'} on <${run.element.tagName.toLowerCase()}>`,\n begun: run.begun,\n ready: run.ready,\n end: run.end,\n calls: [],\n updates: [],\n };\n if (run.result instanceof Promise) {\n run.result.then(\n () => {\n entry.settled = performance.now();\n state.changed?.();\n },\n () => {\n entry.settled = performance.now();\n entry.failed = true;\n state.changed?.();\n },\n );\n } else {\n entry.settled = run.end;\n }\n state.timeline.push(entry);\n if (state.timeline.length > 100) {\n state.timeline.shift();\n }\n state.changed?.();\n },\n updated(count, start, end) {\n if (count > 0) {\n owner(start)?.updates.push({ count, start, end });\n }\n },\n defer(template, done) {\n deferred(template, done);\n },\n handler(ref, element, event) {\n if (element.tagName === 'TEMPLATE') {\n let block: BlockEntry | undefined;\n for (const item of state.blocks.values()) {\n if (item.template === element) {\n block = item;\n break;\n }\n }\n if (block && block.fired === undefined) {\n block.fired = performance.now();\n moveBlock(block, 'fired', block.fired);\n }\n }\n add({\n kind: 'handler',\n text: `${event?.type ?? 'call'} on <${element.tagName.toLowerCase()}>: ${ref}`,\n });\n },\n effect(scope, name, kind, time) {\n const key = `${scope.id}:${name}`;\n let entry = state.effects.get(key);\n if (!entry) {\n entry = {\n scope: scope.id,\n component: findRootScope(scope).m ?? '',\n k: scope.k,\n name,\n runs: 0,\n recent: [],\n time: 0,\n cleanups: 0,\n active: false,\n };\n state.effects.set(key, entry);\n }\n const now = performance.now();\n if (kind === 'run') {\n entry.runs++;\n entry.time += time;\n entry.recent.push(now);\n if (entry.recent.length > 50) {\n entry.recent.shift();\n }\n entry.active = true;\n } else {\n entry.cleanups++;\n entry.lastCleanup = now;\n entry.active = false;\n }\n state.changed?.();\n },\n navigated(report) {\n state.navigations.push(report);\n if (state.navigations.length > 20) {\n state.navigations.shift();\n }\n state.changed?.();\n },\n write(scope, slot, value) {\n state.written.add(scope.id);\n const root = findRootScope(scope);\n add({\n kind: 'write',\n text: `scope ${scope.id} slot ${slot} = ${preview(value)}`,\n scope: scope.id,\n write: { component: root.m ?? '', k: scope.k, slot },\n });\n },\n };\n (globalThis as Record<symbol, DevtoolsHooks | undefined>)[DEVTOOLS] = hooks;\n\n // The swap of a body keeps its fallback in development, by boundary, so the fallback can show\n // again. While it shows, the body is out of the page, and updates of its nodes wait there.\n state.showFallback = (block, on) => {\n const kept = (globalThis as { $bD?: Record<string, { f: Node[]; b: Node[] }> }).$bD?.[block.id];\n if (!kept || (block.fallback ?? false) === on) {\n return false;\n }\n const [shown, hidden] = on ? [kept.b, kept.f] : [kept.f, kept.b];\n let anchor: Node | undefined;\n for (const node of shown) {\n if (node.parentNode) {\n anchor = node;\n break;\n }\n }\n if (!anchor) {\n return false;\n }\n for (const node of hidden) {\n anchor.parentNode!.insertBefore(node, anchor);\n }\n for (const node of shown) {\n node.parentNode?.removeChild(node);\n }\n block.fallback = on;\n state.changed?.();\n return true;\n };\n\n // Server function calls, with how long each took and how it answered.\n const original = globalThis.fetch.bind(globalThis);\n globalThis.fetch = async (input, init) => {\n const url = new URL(input instanceof Request ? input.url : String(input), location.href);\n if (url.origin !== location.origin || !url.pathname.startsWith(`${rpc}/`)) {\n return original(input, init);\n }\n const name = decodeURIComponent(url.pathname.slice(rpc.length + 1));\n const started = performance.now();\n const call: CallTiming = { name, start: started };\n owner(started)?.calls.push(call);\n try {\n const response = await original(input, init);\n const took = Math.round(performance.now() - started);\n const redirect = response.headers.get('x-brumate-redirect');\n call.end = performance.now();\n call.status = redirect ? 'redirect' : response.status;\n const server = /brumate;dur=([\\d.]+)/.exec(response.headers.get('server-timing') ?? '');\n if (server) {\n call.server = Number(server[1]);\n }\n state.changed?.();\n add({\n kind: 'call',\n text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`,\n });\n return response;\n } catch (error) {\n call.end = performance.now();\n call.status = 'failed';\n add({\n kind: 'call',\n text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`,\n });\n throw error;\n }\n };\n\n // Blocks: the markers of the page tell their state, so the panel follows the changes of the DOM.\n function deferred(template: Element, done: Promise<unknown>): void {\n let block: BlockEntry | undefined;\n for (const item of state.blocks.values()) {\n if (item.template === template) {\n block = item;\n break;\n }\n }\n // The loader asks once, so a block that is already loading waits for its first request.\n const asked = block !== undefined && block.state !== 'loading';\n if (block) {\n block.fired ??= performance.now();\n moveBlock(block, 'fired', block.fired);\n }\n void done.finally(() => {\n scanBlocks(state);\n // A body that arrived rendered the block in the scan, so one still loading got none.\n if (block && asked) {\n moveBlock(block, 'settled', performance.now());\n }\n state.changed?.();\n });\n }\n state.fire = (block) => {\n if (block.kind === 'defer' && block.template) {\n deferred(\n block.template,\n import('./defer.ts').then((module) => module.loadDeferred(block.template!)),\n );\n } else if (block.template && block.ref) {\n void state.handle?.(block.template, block.ref);\n }\n };\n if (typeof MutationObserver !== 'undefined') {\n let queued = false;\n new MutationObserver(() => {\n if (!queued) {\n queued = true;\n queueMicrotask(() => {\n queued = false;\n if (scanBlocks(state)) {\n state.changed?.();\n }\n });\n }\n }).observe(document, { childList: true, subtree: true, characterData: true });\n }\n scanBlocks(state);\n\n const host = document.createElement('brumate-devtools');\n const root = host.attachShadow({ mode: 'open' });\n const style = document.createElement('style');\n style.textContent = `\n.open { position: fixed; left: 50%; bottom: 0; z-index: 2147483647; transform: translateX(-50%); display: flex; justify-content: center; padding: 8px 16px 0; border: 0; background: none; color: #ece8e4; font: 600 12px/1 system-ui, -apple-system, sans-serif; cursor: pointer; touch-action: none; outline: none; }\n.open[hidden] { display: none; }\n.grip { width: 40px; height: 5px; border-radius: 4px 4px 0 0; background: rgb(25 24 26 / 0.88); box-shadow: 0 0 0 1px rgb(255 255 255 / 0.3); transition: opacity 150ms cubic-bezier(0.4, 0, 0.2, 1), width 150ms cubic-bezier(0.4, 0, 0.2, 1); }\n.open[data-errors] .grip { width: 56px; background: #e5484d; }\n.content { position: absolute; left: 50%; bottom: 0; transform: translate(-50%, 100%); display: flex; align-items: center; gap: 8px; padding: 5px 8px 5px 10px; white-space: nowrap; background: #222023; border: 1px solid #2f2c31; border-bottom: 0; border-radius: 10px 10px 0 0; box-shadow: 0 -4px 16px rgb(0 0 0 / 0.3); opacity: 0; pointer-events: none; transition: transform 150ms cubic-bezier(0.4, 0, 0.2, 1), opacity 150ms cubic-bezier(0.4, 0, 0.2, 1); }\n.open:hover .content, .open:focus-visible .content, .open:active .content { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }\n.open:hover .grip, .open:focus-visible .grip, .open:active .grip { opacity: 0; }\n.open:focus-visible .content { border-color: #ee7a3e; }\n.mark { display: inline-flex; width: 16px; height: 16px; }\n.version { padding: 1px 8px; border-radius: 999px; background: rgb(238 122 62 / 0.16); color: #ffb48a; font: 600 12px/20px ui-monospace, SFMono-Regular, Menlo, monospace; }\n.chevron { width: 12px; height: 12px; color: #a39a92; }\n.count { min-width: 18px; padding: 0 5px; box-sizing: border-box; border-radius: 999px; background: #e5484d; color: #fff; font: 600 11px/18px system-ui, sans-serif; text-align: center; }\n.count:empty { display: none; }\n.flashes { position: fixed; inset: 0; pointer-events: none; z-index: 2147483646; }\n.flash { position: fixed; box-sizing: border-box; border: 2px solid #7fd99a; border-radius: 3px; background: rgb(127 217 154 / 0.08); animation: flash 700ms ease-out forwards; }\n.flash.warm { border-color: #ffd166; background: rgb(255 209 102 / 0.1); }\n.flash.hot { border-color: #ff7a7a; background: rgb(255 122 122 / 0.12); }\n@keyframes flash { from { opacity: 1; } to { opacity: 0; } }\n@media (prefers-reduced-motion: reduce) { .flash { animation: none; } }\n@media (prefers-reduced-motion: reduce) { .grip, .content { transition: none; } }\n`;\n // The closed panel: a grip on the bottom edge that grows into a pull tab on hover or focus, so\n // it covers almost none of the page. A click, or a drag up, opens the panel.\n const button = document.createElement('button');\n button.type = 'button';\n button.className = 'open';\n button.title = 'brumate devtools (Alt+Shift+D)';\n button.innerHTML = `<span class=\"grip\"></span><span class=\"content\"><span class=\"mark\">${LOGO}</span><span class=\"version\"></span><span class=\"count\"></span><svg class=\"chevron\" viewBox=\"0 0 12 12\" aria-hidden=\"true\"><path d=\"M3 7.5 6 4.5 9 7.5\" fill=\"none\" stroke=\"currentColor\" stroke-width=\"1.6\" stroke-linecap=\"round\" stroke-linejoin=\"round\"/></svg></span>`;\n // The version of brumate, next to its mark.\n button.querySelector('.version')!.textContent = meta.version ? `v${meta.version}` : 'brumate';\n function label(): void {\n const errors = state.errors.length;\n button.setAttribute(\n 'aria-label',\n `Open the brumate devtools${meta.version ? `, version ${meta.version}` : ''}${errors > 0 ? `, ${errors} errors` : ''}`,\n );\n }\n label();\n // The number of errors, in red on the tab, and a red grip, so an error shows while it is closed.\n const count = button.querySelector<HTMLElement>('.count')!;\n state.errorCount = (): void => {\n count.textContent = state.errors.length > 0 ? String(state.errors.length) : '';\n button.toggleAttribute('data-errors', state.errors.length > 0);\n label();\n };\n // Dragging the tab up past a few pixels opens the panel under the pointer. A press that does not\n // move is left to the click.\n let dragged = false;\n button.addEventListener('pointerdown', (event) => {\n if (event.button !== 0) {\n return;\n }\n const start = event.clientY;\n let opened = false;\n dragged = false;\n function move(next: PointerEvent): void {\n if (!opened) {\n if (start - next.clientY < 4) {\n return;\n }\n opened = true;\n dragged = true;\n void panelModule().then(({ openPanel }) => {\n openPanel(root, state, 'overview');\n state.resize?.(next.clientY);\n });\n return;\n }\n state.resize?.(next.clientY);\n }\n // The tab hides as the panel opens, so the pointer is followed on the window.\n function end(): void {\n removeEventListener('pointermove', move);\n removeEventListener('pointerup', end);\n removeEventListener('pointercancel', end);\n if (opened) {\n state.resized?.();\n }\n }\n addEventListener('pointermove', move);\n addEventListener('pointerup', end);\n addEventListener('pointercancel', end);\n });\n button.addEventListener('click', () => {\n if (dragged) {\n dragged = false;\n return;\n }\n void panelModule().then(({ togglePanel }) => togglePanel(root, state));\n });\n // Alt+Shift+D opens and closes the panel. `code`, because Alt changes the key on macOS.\n addEventListener('keydown', (event) => {\n if (event.altKey && event.shiftKey && event.code === 'KeyD') {\n event.preventDefault();\n void panelModule().then(({ togglePanel }) => togglePanel(root, state));\n }\n });\n state.open = (tab) => {\n void import('./devtools-panel.ts').then(({ openPanel }) => openPanel(root, state, tab));\n };\n root.append(style, button);\n installFlash(state, root, host);\n\n // Errors of code of the page in the browser. Errors of other code are left out.\n addEventListener('error', (event) => {\n const stack = (event.error as Error | undefined)?.stack;\n if (foreign(stack, event.filename)) {\n return;\n }\n const error = event.error as Error | undefined;\n // The message of the error, without the `Uncaught` that the browser puts before it.\n reportError(\n state,\n { message: error?.message ?? event.message, stack: error?.stack },\n 'browser',\n );\n });\n addEventListener('unhandledrejection', (event) => {\n const reason = event.reason as Error | undefined;\n if (foreign(reason?.stack)) {\n return;\n }\n reportError(\n state,\n { message: reason?.message ?? String(event.reason), stack: reason?.stack },\n 'browser',\n );\n });\n // Errors of handlers and updates that no `#try` caught. The core catches them, so they do not\n // reach the listeners above.\n addEventListener('brumate:error', (event) => {\n const error = (event as CustomEvent<{ error: unknown }>).detail.error as Error | undefined;\n reportError(\n state,\n { message: error?.message ?? String(error), stack: error?.stack },\n 'browser',\n );\n });\n // Errors of Vite, such as a compile error after an edit, which its overlay would show. A good\n // update after them clears them.\n hot?.on('vite:error', (payload: { err: ErrorPayload }) => {\n reportError(state, payload.err, 'compile');\n });\n hot?.on('vite:afterUpdate', () => {\n const before = state.errors.length;\n const remaining: ErrorEntry[] = [];\n for (const error of state.errors) {\n if (error.source !== 'compile') {\n remaining.push(error);\n }\n }\n state.errors = remaining;\n if (state.errors.length !== before) {\n state.errorCount?.();\n state.changed?.();\n }\n });\n function append(): void {\n // Navigation replaces the body, so the button goes on the document element.\n document.documentElement.append(host);\n }\n if (document.readyState === 'loading') {\n document.addEventListener('DOMContentLoaded', append);\n } else {\n append();\n }\n return state;\n}\n"],"mappings":";;AAUA,MAAM,WAAW,OAAO,IAAI,kBAAkB;AAyK9C,MAAM,UAAU;;AAOhB,SAAgB,cAAc,OAAqB;CACjD,IAAI,OAAO;CACX,OAAO,KAAK,GACV,OAAO,KAAK;CAEd,OAAO;AACT;;AAGA,SAAgB,QAAQ,OAAwB;CAC9C,IAAI,OAAO,UAAU,UACnB,OAAO,KAAK,UAAU,MAAM,SAAS,KAAK,GAAG,MAAM,MAAM,GAAG,EAAE,EAAE,KAAK,KAAK;CAE5E,IAAI,OAAO,UAAU,YACnB,OAAO;CAET,IAAI,MAAM,QAAQ,KAAK,GACrB,OAAO,SAAS,MAAM,OAAO;CAE/B,IAAI,iBAAiB,SACnB,OAAO,IAAI,MAAM,QAAQ,YAAY,EAAE;CAEzC,IAAI,UAAU,QAAQ,OAAO,UAAU,UAAU;EAC/C,MAAM,OAAO,MAAM,aAAa;EAChC,OAAO,QAAQ,SAAS,WAAW,OAAO,IAAI,OAAO,KAAK,KAAK,CAAC,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,KAAK,IAAI,EAAE;CAC1F;CACA,OAAO,OAAO,KAAK;AACrB;;;;;;AAaA,SAAgB,eAAe,OAAmB,OAAwC;CACxF,IAAI,MAAM,UAAU,cAAc,UAAU,YAC1C,OAAO;CAET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MAAM,SAAS,MAAM,OAAO;EAC5B,MAAM,YAA0B,CAAC;EACjC,KAAK,MAAM,SAAS,MAAM,QACxB,IAAI,MAAM,WAAW,WACnB,UAAU,KAAK,KAAK;EAGxB,MAAM,SAAS;EACf,IAAI,MAAM,OAAO,WAAW,QAAQ;GAClC,MAAM,aAAa;GACnB,MAAM,UAAU;EAClB;CACF,CAAC;CACD,SAAS,SAAe;EAEtB,SAAS,gBAAgB,OAAO,IAAI;CACtC;CACA,IAAI,SAAS,eAAe,WAC1B,SAAS,iBAAiB,oBAAoB,MAAM;MAEpD,OAAO;CAET,OAAO;AACT"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as LOGO } from "./logo-DQ_OYhBi.js";
|
|
2
|
-
import {
|
|
2
|
+
import { a as preview, t as findRootScope } from "./devtools-CzSp1GGq.js";
|
|
3
3
|
//#region src/runtime/devtools-panel.ts
|
|
4
4
|
const STYLE = `
|
|
5
5
|
:host { all: initial; }
|
|
@@ -452,6 +452,20 @@ function source(info, at = "1:1") {
|
|
|
452
452
|
});
|
|
453
453
|
return open;
|
|
454
454
|
}
|
|
455
|
+
/** A button that opens the place of a graph node in the editor. */
|
|
456
|
+
function place(info, at) {
|
|
457
|
+
const label = `line ${at.line}`;
|
|
458
|
+
const file = at.file ?? info.path;
|
|
459
|
+
if (!file) return element("span", { class: "mono sub" }, label);
|
|
460
|
+
const open = element("button", {
|
|
461
|
+
class: "link",
|
|
462
|
+
title: `Open ${at.file ?? info.file}:${at.line}:${at.column}`
|
|
463
|
+
}, label, icon("open", 12));
|
|
464
|
+
open.addEventListener("click", () => {
|
|
465
|
+
fetch(`/__open-in-editor?file=${encodeURIComponent(`${file}:${at.line}:${at.column}`)}`);
|
|
466
|
+
});
|
|
467
|
+
return open;
|
|
468
|
+
}
|
|
455
469
|
/**
|
|
456
470
|
* Places the nodes of a graph in columns, left to right, by the longest
|
|
457
471
|
* path from a value that nothing feeds. Within a column, nodes are ordered
|
|
@@ -1351,16 +1365,16 @@ function togglePanel(root, state, initial = "overview") {
|
|
|
1351
1365
|
}
|
|
1352
1366
|
const parts = [];
|
|
1353
1367
|
for (const node of nodes) {
|
|
1354
|
-
const at =
|
|
1368
|
+
const at = node.at ? `${node.at.line}:${node.at.column}` : void 0;
|
|
1355
1369
|
const owner = node.slot === void 0 ? void 0 : scopeOfNode.get(node.scope);
|
|
1356
1370
|
const value = owner && node.slot !== void 0 ? preview(owner.s[node.slot]) : void 0;
|
|
1357
|
-
let meta = at ? `${node.kind} · ${at
|
|
1371
|
+
let meta = at ? `${node.kind} · ${at}` : node.kind;
|
|
1358
1372
|
if (value !== void 0) meta = `= ${value}`;
|
|
1359
1373
|
parts.push({
|
|
1360
|
-
name:
|
|
1374
|
+
name: node.label,
|
|
1361
1375
|
meta,
|
|
1362
1376
|
value,
|
|
1363
|
-
at
|
|
1377
|
+
at
|
|
1364
1378
|
});
|
|
1365
1379
|
}
|
|
1366
1380
|
function getNodeWidth(index) {
|
|
@@ -1427,7 +1441,7 @@ function togglePanel(root, state, initial = "overview") {
|
|
|
1427
1441
|
});
|
|
1428
1442
|
meta.textContent = clip(part.meta);
|
|
1429
1443
|
const title = svg("title", {});
|
|
1430
|
-
title.textContent = `${node.kind} ${node.label}${part.value === void 0 ? "" : ` = ${part.value}`}`;
|
|
1444
|
+
title.textContent = `${node.kind} ${node.label}${part.value === void 0 ? "" : ` = ${part.value}`}${part.at ? `, line ${node.at.line}` : ""}`;
|
|
1431
1445
|
const group = svg("g", {
|
|
1432
1446
|
class: classes.join(" "),
|
|
1433
1447
|
"data-node": index
|
|
@@ -1534,7 +1548,16 @@ function togglePanel(root, state, initial = "overview") {
|
|
|
1534
1548
|
function list(indexes) {
|
|
1535
1549
|
if (indexes.length === 0) return element("div", { class: "sub" }, "nothing");
|
|
1536
1550
|
const labels = [];
|
|
1537
|
-
for (const index of indexes)
|
|
1551
|
+
for (const index of indexes) {
|
|
1552
|
+
const { label } = nodes[index];
|
|
1553
|
+
const at = parts[index].at;
|
|
1554
|
+
let shared = false;
|
|
1555
|
+
for (const [i, other] of nodes.entries()) if (i !== index && other.label === label) {
|
|
1556
|
+
shared = true;
|
|
1557
|
+
break;
|
|
1558
|
+
}
|
|
1559
|
+
labels.push(element("div", { class: "mono" }, shared && at ? `${label} ${at}` : label));
|
|
1560
|
+
}
|
|
1538
1561
|
return element("div", {}, ...labels);
|
|
1539
1562
|
}
|
|
1540
1563
|
const reads = [];
|
|
@@ -1544,7 +1567,7 @@ function togglePanel(root, state, initial = "overview") {
|
|
|
1544
1567
|
if (from === graphNode) readBy.push(to);
|
|
1545
1568
|
}
|
|
1546
1569
|
const color = nodeColor(node.kind, node.slot);
|
|
1547
|
-
side.append(element("h2", {}, part.name), element("div", { class: "toolbar" }, pill(node.kind, color),
|
|
1570
|
+
side.append(element("h2", {}, part.name), element("div", { class: "toolbar" }, pill(node.kind, color), node.at ? place(info, node.at) : ""), ...part.value === void 0 ? [] : [element("h3", {}, "Value"), element("div", { class: "mono" }, part.value)], element("h3", {}, "Reads"), list(reads), element("h3", {}, "Read by"), list(readBy));
|
|
1548
1571
|
} else side.append(element("h2", {}, info.name), element("p", {
|
|
1549
1572
|
class: "sub",
|
|
1550
1573
|
style: "margin-top: 0"
|
|
@@ -1991,4 +2014,4 @@ function togglePanel(root, state, initial = "overview") {
|
|
|
1991
2014
|
//#endregion
|
|
1992
2015
|
export { layoutGraph, openPanel, togglePanel };
|
|
1993
2016
|
|
|
1994
|
-
//# sourceMappingURL=devtools-panel-
|
|
2017
|
+
//# sourceMappingURL=devtools-panel-DugGrz7L.js.map
|