brumate 0.1.1 → 0.2.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/dist/{boot-DN1ZU8Hg.d.ts → boot-D-IdPy7B.d.ts} +24 -2
- package/dist/cli.js +2 -2
- package/dist/client-C0UCNL3J.js +1643 -0
- package/dist/client-C0UCNL3J.js.map +1 -0
- package/dist/{client-DwJInP_a.d.ts → client-MD0ZmcFR.d.ts} +101 -26
- package/dist/{client-routes-DakuM32C.js → client-routes-JTbGtukf.js} +28 -15
- package/dist/client-routes-JTbGtukf.js.map +1 -0
- package/dist/context-CTiSzQRc.js +27 -0
- package/dist/context-CTiSzQRc.js.map +1 -0
- package/dist/context-btHuB01Z.d.ts +42 -0
- package/dist/defer-D0bo1Gqx.js +52 -0
- package/dist/defer-D0bo1Gqx.js.map +1 -0
- package/dist/{devtools-BKjnHrnv.js → devtools-C50VH8gZ.js} +2 -2
- package/dist/devtools-C50VH8gZ.js.map +1 -0
- package/dist/{devtools-panel-AWOn0VK2.js → devtools-panel-AYjfwPhj.js} +4 -3
- package/dist/devtools-panel-AYjfwPhj.js.map +1 -0
- package/dist/events-BKWRqtMg.js +52 -0
- package/dist/events-BKWRqtMg.js.map +1 -0
- package/dist/{files-DdT84mPy.js → files-Bnn1JqHx.js} +18 -3
- package/dist/files-Bnn1JqHx.js.map +1 -0
- package/dist/{html-DEeoepg3.js → html-bHZbkK-h.js} +26 -8
- package/dist/html-bHZbkK-h.js.map +1 -0
- package/dist/{html-Du8jY2Cc.d.ts → html-y1q7-t7D.d.ts} +12 -5
- package/dist/index.d.ts +77 -29
- package/dist/index.js +12 -4
- package/dist/index.js.map +1 -1
- package/dist/{inspect-BPchdWbU.js → inspect-BJtACnQp.js} +784 -82
- package/dist/inspect-BJtACnQp.js.map +1 -0
- package/dist/{loader-Dc9OwY5I.js → loader-B18i3_-T.js} +46 -11
- package/dist/loader-B18i3_-T.js.map +1 -0
- package/dist/{navigate-CzLjnoPH.js → navigate-BwuZveDF.js} +71 -12
- package/dist/navigate-BwuZveDF.js.map +1 -0
- package/dist/{produce-BRGHP7e0.js → produce-CWfJ4byV.js} +43 -2
- package/dist/produce-CWfJ4byV.js.map +1 -0
- package/dist/{produce-CtZ32UGG.d.ts → produce-D4K7qpaL.d.ts} +23 -11
- package/dist/routes-BZNt7DSZ.d.ts +38 -0
- package/dist/{rpc-9fSqL_YK.js → rpc-B-Zkn6Ch.js} +24 -18
- package/dist/rpc-B-Zkn6Ch.js.map +1 -0
- package/dist/runtime/batch.d.ts +23 -0
- package/dist/runtime/batch.js +69 -0
- package/dist/runtime/batch.js.map +1 -0
- package/dist/runtime/client.d.ts +5 -5
- package/dist/runtime/client.js +5 -1345
- package/dist/runtime/context.d.ts +2 -2
- package/dist/runtime/context.js +1 -1
- package/dist/runtime/devtools.d.ts +5 -4
- package/dist/runtime/devtools.js +1 -1
- package/dist/runtime/env.d.ts +44 -0
- package/dist/runtime/env.js +61 -0
- package/dist/runtime/env.js.map +1 -0
- package/dist/runtime/events.d.ts +27 -0
- package/dist/runtime/events.js +1 -0
- package/dist/runtime/hot.d.ts +1 -1
- package/dist/runtime/html.d.ts +2 -2
- package/dist/runtime/html.js +1 -1
- package/dist/runtime/loader.d.ts +2 -2
- package/dist/runtime/loader.js +2 -2
- package/dist/runtime/routes.d.ts +2 -21
- package/dist/runtime/routes.js +31 -1
- package/dist/runtime/routes.js.map +1 -1
- package/dist/runtime/server.d.ts +6 -5
- package/dist/runtime/server.js +5 -6
- package/dist/runtime/signals.d.ts +22 -1
- package/dist/runtime/signals.js +29 -1
- 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/testing.d.ts +46 -5
- package/dist/runtime/testing.js +240 -33
- package/dist/runtime/testing.js.map +1 -1
- package/dist/secrets-BxagsJxJ.js +23 -0
- package/dist/secrets-BxagsJxJ.js.map +1 -0
- package/dist/{server-BxqjLUnV.d.ts → server-BA9SJ2Vm.d.ts} +544 -106
- package/dist/server-BqfM95r1.js +2762 -0
- package/dist/server-BqfM95r1.js.map +1 -0
- package/dist/skew-FRmAy9iy.js +49 -0
- package/dist/skew-FRmAy9iy.js.map +1 -0
- package/dist/standard-schema-BNY82yX3.d.ts +63 -0
- package/dist/{static-loader-BcFh4ebX.d.ts → static-loader-BzE9SRaj.d.ts} +2 -2
- package/dist/{static-loader-ClNkHZGn.js → static-loader-DOygOFj5.js} +52 -21
- package/dist/static-loader-DOygOFj5.js.map +1 -0
- package/dist/{stream-bgNCMcaA.js → stream-JaMHMdBD.js} +126 -61
- package/dist/stream-JaMHMdBD.js.map +1 -0
- package/dist/vite.d.ts +42 -1
- package/dist/vite.js +435 -55
- package/dist/vite.js.map +1 -1
- package/package.json +15 -2
- package/types.d.ts +9 -1
- package/dist/client-routes-DakuM32C.js.map +0 -1
- package/dist/context-BG8KCF3v.js +0 -15
- package/dist/context-BG8KCF3v.js.map +0 -1
- package/dist/context-aeo9esY9.d.ts +0 -16
- package/dist/devtools-BKjnHrnv.js.map +0 -1
- package/dist/devtools-panel-AWOn0VK2.js.map +0 -1
- package/dist/files-DdT84mPy.js.map +0 -1
- package/dist/html-DEeoepg3.js.map +0 -1
- package/dist/inspect-BPchdWbU.js.map +0 -1
- package/dist/loader-Dc9OwY5I.js.map +0 -1
- package/dist/navigate-CzLjnoPH.js.map +0 -1
- package/dist/produce-BRGHP7e0.js.map +0 -1
- package/dist/rpc-9fSqL_YK.js.map +0 -1
- package/dist/runtime/client.js.map +0 -1
- package/dist/server-DZsgnPKS.js +0 -1615
- package/dist/server-DZsgnPKS.js.map +0 -1
- package/dist/shared-CWYOd0H3.js +0 -40
- package/dist/shared-CWYOd0H3.js.map +0 -1
- package/dist/static-loader-ClNkHZGn.js.map +0 -1
- package/dist/stream-bgNCMcaA.js.map +0 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "brumate",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.2.0",
|
|
4
4
|
"description": "A component language and compiler for resumable web apps",
|
|
5
5
|
"homepage": "https://github.com/lxsmnsyc/brumate",
|
|
6
6
|
"bugs": "https://github.com/lxsmnsyc/brumate/issues",
|
|
@@ -63,6 +63,14 @@
|
|
|
63
63
|
"types": "./dist/runtime/routes.d.ts",
|
|
64
64
|
"default": "./dist/runtime/routes.js"
|
|
65
65
|
},
|
|
66
|
+
"./batch": {
|
|
67
|
+
"types": "./dist/runtime/batch.d.ts",
|
|
68
|
+
"default": "./dist/runtime/batch.js"
|
|
69
|
+
},
|
|
70
|
+
"./events": {
|
|
71
|
+
"types": "./dist/runtime/events.d.ts",
|
|
72
|
+
"default": "./dist/runtime/events.js"
|
|
73
|
+
},
|
|
66
74
|
"./devtools": {
|
|
67
75
|
"types": "./dist/runtime/devtools.d.ts",
|
|
68
76
|
"default": "./dist/runtime/devtools.js"
|
|
@@ -75,6 +83,10 @@
|
|
|
75
83
|
"types": "./dist/runtime/testing.d.ts",
|
|
76
84
|
"default": "./dist/runtime/testing.js"
|
|
77
85
|
},
|
|
86
|
+
"./env": {
|
|
87
|
+
"types": "./dist/runtime/env.d.ts",
|
|
88
|
+
"default": "./dist/runtime/env.js"
|
|
89
|
+
},
|
|
78
90
|
"./package.json": "./package.json"
|
|
79
91
|
},
|
|
80
92
|
"publishConfig": {
|
|
@@ -84,7 +96,8 @@
|
|
|
84
96
|
"oxc-parser": "^0.154.0",
|
|
85
97
|
"postcss": "^8.5.31",
|
|
86
98
|
"postcss-selector-parser": "^7.1.6",
|
|
87
|
-
"seroval": "^1.7.0"
|
|
99
|
+
"seroval": "^1.7.0",
|
|
100
|
+
"seroval-plugins": "^1.7.0"
|
|
88
101
|
},
|
|
89
102
|
"devDependencies": {
|
|
90
103
|
"@oxc-project/types": "^0.154.0",
|
package/types.d.ts
CHANGED
|
@@ -12,6 +12,11 @@ declare module 'virtual:brumate/testing' {
|
|
|
12
12
|
* the app, until the returned function restores `fetch`.
|
|
13
13
|
*/
|
|
14
14
|
export function answerCalls(options?: import('brumate/testing').AnswerOptions): () => void;
|
|
15
|
+
/**
|
|
16
|
+
* Visits a path of the app, as a browser that runs scripts does. The
|
|
17
|
+
* routes of the app answer the page and every request that it makes.
|
|
18
|
+
*/
|
|
19
|
+
export const visit: import('brumate/testing').Visit;
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
declare module '*.brm' {
|
|
@@ -29,7 +34,10 @@ declare module 'virtual:brumate/manifest' {
|
|
|
29
34
|
|
|
30
35
|
declare module 'virtual:brumate/server' {
|
|
31
36
|
export const functions: Record<string, (...args: any[]) => unknown>;
|
|
32
|
-
export function handle(
|
|
37
|
+
export function handle(
|
|
38
|
+
request: Request,
|
|
39
|
+
options?: import('brumate/server').RequestOptions,
|
|
40
|
+
): Promise<Response | undefined>;
|
|
33
41
|
}
|
|
34
42
|
|
|
35
43
|
declare module 'virtual:brumate/routes' {
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"client-routes-DakuM32C.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 { PageState, ScopeState } from './shared.ts';\n\n/** The parts of the core that this module uses. */\ntype Core = Pick<\n typeof Client,\n 'ElementReference' | 'FunctionReference' | 'hooks' | 'removeScope' | 'scopes'\n>;\n\n/** Adds a number to the scope IDs of a state record. */\nfunction shiftState(core: Core, state: PageState, by: number): PageState {\n const { ElementReference, FunctionReference } = core;\n const seen = new Set<object>();\n // References to elements and client functions name the scope of their markup.\n const shiftValue = (value: unknown): unknown => {\n if (value instanceof ElementReference) {\n return new ElementReference(value.scope + by, value.anchor);\n }\n if (value instanceof FunctionReference) {\n return new FunctionReference(value.ref, value.scope + by);\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 value.forEach((item, index) => {\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 const result: PageState = {};\n for (const [key, record] of Object.entries(state)) {\n result[Number(key) + by] = {\n ...record,\n p: record.p === undefined ? undefined : record.p + by,\n o: record.o === undefined ? undefined : record.o + by,\n c:\n record.c &&\n Object.fromEntries(Object.entries(record.c).map(([anchor, id]) => [anchor, id + by])),\n s: record.s?.map(shiftValue),\n };\n }\n return result;\n}\n\n/** Removes scopes and the scopes inside them, and runs their cleanups. */\nfunction dropScopes(core: Core, roots: Set<number>): void {\n const 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, state, offset) : state;\n const drop = script.getAttribute('b-drop');\n if (drop) {\n dropScopes(core, new Set(drop.split(',').map(Number)));\n }\n const list = script.getAttribute('b-roots');\n if (list === null) {\n return value;\n }\n const roots = new Set(list.split(',').filter(Boolean).map(Number));\n const alias = new Map<number, number>();\n for (const pair of (script.getAttribute('b-alias') ?? '').split(',').filter(Boolean)) {\n const [from, to] = pair.split(':').map(Number) as [number, number];\n alias.set(from, to);\n }\n const kept = (id: number): boolean => {\n for (let current: number | 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 const resolve = (id: number | undefined): number | undefined =>\n id === undefined ? undefined : (alias.get(id) ?? id);\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 if (kept(Number(key))) {\n result[Number(key)] = { ...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 ({ ElementReference, FunctionReference, hooks, leavePage, leaveRoutes, removeScope, scopes }) => {\n const core = { ElementReference, FunctionReference, hooks, removeScope, scopes };\n hooks.record = (script, state) => routeRecord(core, script, state);\n return (partial) => (partial ? leaveRoutes() : leavePage());\n },\n);\n"],"mappings":";;AAsBA,SAAS,WAAW,MAAY,OAAkB,IAAuB;CACvE,MAAM,EAAE,kBAAkB,sBAAsB;CAChD,MAAM,uBAAO,IAAI,IAAY;CAE7B,MAAM,cAAc,UAA4B;EAC9C,IAAI,iBAAiB,kBACnB,OAAO,IAAI,iBAAiB,MAAM,QAAQ,IAAI,MAAM,MAAM;EAE5D,IAAI,iBAAiB,mBACnB,OAAO,IAAI,kBAAkB,MAAM,KAAK,MAAM,QAAQ,EAAE;EAG1D,IAAI,iBAAiB,SACnB,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EAAkB;EAAmB;EAAO;EAAa;CAAO;CAC/E,MAAM,UAAU,QAAQ,UAAU,YAAY,MAAM,QAAQ,KAAK;CACjE,QAAQ,YAAa,UAAU,YAAY,IAAI,UAAU;AAC3D,CACF"}
|
package/dist/context-BG8KCF3v.js
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/context.ts
|
|
2
|
-
/**
|
|
3
|
-
* Creates a context. `key` names it in the page state, so it must be unique
|
|
4
|
-
* in the app and the same on the server and the client.
|
|
5
|
-
*/
|
|
6
|
-
function createContext(key, defaultValue) {
|
|
7
|
-
return {
|
|
8
|
-
key,
|
|
9
|
-
defaultValue
|
|
10
|
-
};
|
|
11
|
-
}
|
|
12
|
-
//#endregion
|
|
13
|
-
export { createContext as t };
|
|
14
|
-
|
|
15
|
-
//# sourceMappingURL=context-BG8KCF3v.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"context-BG8KCF3v.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 /** The value of a component that reads the context without a provider above it. */\n readonly defaultValue: 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, defaultValue: T): Context<T> {\n return { key, defaultValue };\n}\n"],"mappings":";;;;;AAYA,SAAgB,cAAiB,KAAa,cAA6B;CACzE,OAAO;EAAE;EAAK;CAAa;AAC7B"}
|
|
@@ -1,16 +0,0 @@
|
|
|
1
|
-
//#region src/runtime/context.d.ts
|
|
2
|
-
/** A value that a component provides to the components inside it. */
|
|
3
|
-
interface Context<T> {
|
|
4
|
-
/** The same on the server and the client, so the page state can name the context. */
|
|
5
|
-
readonly key: string;
|
|
6
|
-
/** The value of a component that reads the context without a provider above it. */
|
|
7
|
-
readonly defaultValue: T;
|
|
8
|
-
}
|
|
9
|
-
/**
|
|
10
|
-
* Creates a context. `key` names it in the page state, so it must be unique
|
|
11
|
-
* in the app and the same on the server and the client.
|
|
12
|
-
*/
|
|
13
|
-
declare function createContext<T>(key: string, defaultValue: T): Context<T>;
|
|
14
|
-
//#endregion
|
|
15
|
-
export { createContext as n, Context as t };
|
|
16
|
-
//# sourceMappingURL=context-aeo9esY9.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-BKjnHrnv.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 { DevtoolsHooks, Scope } from './client.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' | 'part' | 'write' | 'call';\n text: string;\n /** The scope of a write, so the panel can mark it. */\n scope?: number;\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\nexport interface DevtoolsState {\n scopes?: Map<number, Scope>;\n /** Writes a slot, as a handler does, so the page updates. */\n set?: (scope: Scope, slot: number, value: unknown) => void;\n log: DevtoolsEntry[];\n /** The scopes written since the panel last drew, by scope ID. */\n written: Set<number>;\n /** The URL prefix of the inspect endpoint of the dev server. */\n endpoint: string;\n /** Called after each change, while the panel is open. */\n changed?: () => void;\n}\n\nconst MAX_LOG = 300;\n\n/** The root scope of a scope, whose `m` names its component. */\nexport function rootOf(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/** Listens to the core, and adds the button that opens the panel. */\nexport function installDevtools(endpoint = '/__brumate/inspect', rpc = '/_brumate'): DevtoolsState {\n const state: DevtoolsState = { log: [], written: new Set(), endpoint };\n const 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.changed?.();\n },\n handler(ref, element, event) {\n add({\n kind: 'handler',\n text: `${event?.type ?? 'call'} on <${element.tagName.toLowerCase()}>: ${ref}`,\n });\n },\n part(component, name) {\n add({ kind: 'part', text: `loaded ${component} ${name}` });\n },\n write(scope, slot, value) {\n state.written.add(scope.id);\n const root = rootOf(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 // 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 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 add({\n kind: 'call',\n text: `${name}: ${redirect ? `redirect to ${redirect}` : response.status} in ${took} ms`,\n });\n return response;\n } catch (error) {\n add({\n kind: 'call',\n text: `${name}: failed, ${error instanceof Error ? error.message : String(error)}`,\n });\n throw error;\n }\n };\n\n const host = document.createElement('brumate-devtools');\n const root = host.attachShadow({ mode: 'open' });\n const button = document.createElement('button');\n button.textContent = 'brm';\n button.title = 'Open the brumate devtools';\n button.setAttribute(\n 'style',\n 'position:fixed;right:12px;bottom:12px;z-index:2147483647;font:600 12px ui-monospace,monospace;padding:6px 10px;border-radius:999px;border:1px solid #8884;background:#111;color:#fff;cursor:pointer',\n );\n button.addEventListener('click', () => {\n void import('./devtools-panel.ts').then(({ togglePanel }) => togglePanel(root, state));\n });\n root.append(button);\n const 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":";AAOA,MAAM,WAAW,OAAO,IAAI,kBAAkB;AA0B9C,MAAM,UAAU;;AAGhB,SAAgB,OAAO,OAAqB;CAC1C,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;;AAGA,SAAgB,gBAAgB,WAAW,sBA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,OAAO,mBAAmB,IAAI,SAAS,MAAM,IAAI,SAAS,CAAC,CAAC;EAClE,MAAM,UAAU,YAAY,IAAI;EAChC,IAAI;GACF,MAAM,WAAW,MAAM,SAAS,OAAO,IAAI;GAC3C,MAAM,OAAO,KAAK,MAAM,YAAY,IAAI,IAAI,OAAO;GACnD,MAAM,WAAW,SAAS,QAAQ,IAAI,oBAAoB;GAC1D,IAAI;IACF,MAAM;IACN,MAAM,GAAG,KAAK,IAAI,WAAW,eAAe,aAAa,SAAS,OAAO,MAAM,KAAK;GACtF,CAAC;GACD,OAAO;EACT,SAAS,OAAO;GACd,IAAI;IACF,MAAM;IACN,MAAM,GAAG,KAAK,YAAY,iBAAiB,QAAQ,MAAM,UAAU,OAAO,KAAK;GACjF,CAAC;GACD,MAAM;EACR;CACF;CAEA,MAAM,OAAO,SAAS,cAAc,kBAAkB;CACtD,MAAM,OAAO,KAAK,aAAa,EAAE,MAAM,OAAO,CAAC;CAC/C,MAAM,SAAS,SAAS,cAAc,QAAQ;CAC9C,OAAO,cAAc;CACrB,OAAO,QAAQ;CACf,OAAO,aACL,SACA,qMACF;CACA,OAAO,iBAAiB,eAAe;EACrC,OAAY,+BAAsB,CAAC,MAAM,EAAE,kBAAkB,YAAY,MAAM,KAAK,CAAC;CACvF,CAAC;CACD,KAAK,OAAO,MAAM;CAClB,MAAM,eAAqB;EAEzB,SAAS,gBAAgB,OAAO,IAAI;CACtC;CACA,IAAI,SAAS,eAAe,WAC1B,SAAS,iBAAiB,oBAAoB,MAAM;MAEpD,OAAO;CAET,OAAO;AACT"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"devtools-panel-AWOn0VK2.js","names":[],"sources":["../src/runtime/devtools-panel.ts"],"sourcesContent":["// The panel of the devtools overlay. It reads the core through the hooks in\n// `devtools.ts`, and asks the dev server about each component.\n//\n// - Scopes: each component on the page, its scopes and the value of each\n// slot by name. A value can be edited, which writes it as a handler does.\n// Hovering a scope outlines its elements, and Pick finds the scope of an\n// element of the page.\n// - Graph: the values and markup of a component that change in the\n// browser, and what reads what. A write marks its node and the nodes after it.\n// - Log: handlers, loaded parts, writes and server function calls.\n// - Report: the inspect report of a component.\n\nimport type { Scope } from './client.ts';\nimport { preview, rootOf } from './devtools.ts';\nimport type { DevtoolsEntry, DevtoolsState } from './devtools.ts';\n\n/** What the dev server tells about a component: see the inspect endpoint of the plugin. */\ninterface ComponentInfo {\n name: string;\n file: string;\n /** Each scope of the component, by its number in the compiled component. */\n scopes: Record<number, { label: string; slots: string[] }>;\n graph?: {\n nodes: { kind: string; label: string; scope: number; slot?: number }[];\n /** Pairs of node indexes: the first is read by the second. */\n edges: [number, number][];\n };\n /** The inspect report as text. */\n text: string;\n}\n\nconst STYLE = `\n:host { all: initial; }\n.panel { position: fixed; right: 12px; bottom: 52px; z-index: 2147483647; width: min(520px, calc(100vw - 24px)); height: min(64vh, 620px); display: flex; flex-direction: column; background: #111; color: #eee; font: 12px/1.5 ui-monospace, monospace; border: 1px solid #8884; border-radius: 8px; box-shadow: 0 8px 32px #0006; overflow: hidden; }\n.bar { display: flex; gap: 4px; padding: 6px; border-bottom: 1px solid #8883; align-items: center; flex-wrap: wrap; }\nbutton, select { font: inherit; color: inherit; background: none; border: 1px solid transparent; border-radius: 4px; padding: 2px 8px; cursor: pointer; }\nselect { border-color: #8884; background: #111; }\n.bar .tab[aria-selected=\"true\"], .bar button[aria-pressed=\"true\"] { border-color: #8886; background: #fff1; }\n.bar .end { margin-left: auto; }\n.body { flex: 1; overflow: auto; padding: 8px; }\n.component { margin-bottom: 10px; }\n.component > button { font-weight: 600; color: #9cf; padding: 0; }\n.scope { margin-left: 12px; padding-left: 8px; border-left: 1px solid #8883; }\n.scope.selected { border-left-color: #9cf; background: #9cf1; }\n.scope-label { color: #aaa; cursor: default; }\n.slot { white-space: pre; }\n.slot .name { color: #fc9; }\n.slot .value { cursor: text; border-bottom: 1px dotted #8886; }\n.slot input { font: inherit; color: inherit; background: #000; border: 1px solid #9cf; border-radius: 3px; padding: 0 4px; width: 60%; }\n.written { animation: flash 0.8s; }\n@keyframes flash { from { background: #fd04; } to { background: transparent; } }\n.entry { white-space: pre-wrap; border-bottom: 1px solid #8882; padding: 2px 0; }\n.entry .time { color: #888; margin-right: 6px; }\n.entry.handler .kind { color: #9cf; }\n.entry.part .kind { color: #9e9; }\n.entry.write .kind { color: #fc9; }\n.entry.call .kind { color: #f9c; }\n.filters label { display: inline-flex; gap: 3px; align-items: center; margin-right: 6px; }\npre { margin: 0; white-space: pre-wrap; }\n.empty { color: #888; }\nsvg text { fill: #eee; font: 11px ui-monospace, monospace; }\nsvg rect { fill: #222; stroke: #8886; }\nsvg .kind-signal rect, svg .kind-prop rect { stroke: #9cf; }\nsvg .kind-memo rect { stroke: #c9f; }\nsvg .kind-effect rect { stroke: #9e9; }\nsvg .hot rect { fill: #fd03; stroke: #fd0; }\n.legend { color: #aaa; margin: 6px 0; }\n.legend b { font-weight: normal; }\n.legend .signal { color: #9cf; } .legend .memo { color: #c9f; } .legend .effect { color: #9e9; } .legend .hot { color: #fd0; }\nsvg line { stroke: #8886; }\nsvg .hot-edge { stroke: #fd0; }\n.outline { position: fixed; pointer-events: none; border: 2px solid #9cf; background: #9cf2; border-radius: 3px; z-index: 2147483646; }\n`;\n\ntype Tab = 'scopes' | 'graph' | 'log' | 'report';\nconst KINDS: DevtoolsEntry['kind'][] = ['handler', 'part', 'write', 'call'];\n/** How long a write marks the nodes of the graph. */\nconst HOT_MS = 1500;\n\nconst components = new Map<string, Promise<ComponentInfo | undefined>>();\nconst known = new Map<string, ComponentInfo>();\n\n/** Asks the dev server about a component, once. */\nfunction componentInfo(state: DevtoolsState, id: string): Promise<ComponentInfo | undefined> {\n let info = components.get(id);\n if (!info) {\n info = fetch(`${state.endpoint}/${encodeURIComponent(id)}`)\n .then((response) => (response.ok ? (response.json() as Promise<ComponentInfo>) : undefined))\n .then((value) => {\n if (value) {\n known.set(id, value);\n }\n return value;\n })\n .catch(() => undefined);\n components.set(id, info);\n }\n return info;\n}\n\nfunction element<K extends keyof HTMLElementTagNameMap>(\n tag: K,\n attributes: Record<string, string> = {},\n ...children: (Node | string)[]\n): HTMLElementTagNameMap[K] {\n const node = document.createElement(tag);\n for (const [name, value] of Object.entries(attributes)) {\n node.setAttribute(name, value);\n }\n node.append(...children);\n return node;\n}\n\nfunction svg(\n tag: string,\n attributes: Record<string, string | number>,\n ...children: Node[]\n): SVGElement {\n const node = document.createElementNS('http://www.w3.org/2000/svg', tag);\n for (const [name, value] of Object.entries(attributes)) {\n node.setAttribute(name, String(value));\n }\n node.append(...children);\n return node;\n}\n\n/** A value that can be edited as text: what JSON can hold. */\nfunction editable(value: unknown): boolean {\n if (value === null || ['string', 'number', 'boolean'].includes(typeof value)) {\n return true;\n }\n if (typeof value !== 'object' || value instanceof Element) {\n return false;\n }\n try {\n JSON.stringify(value);\n return true;\n } catch {\n return false;\n }\n}\n\n/** Reads what a person typed: JSON, or else the text as a string. */\nfunction parseValue(text: string): unknown {\n try {\n return JSON.parse(text);\n } catch {\n return text;\n }\n}\n\n/** A write with the name of its slot, once the dev server has said what it is. */\nfunction describe(entry: DevtoolsEntry): string {\n const write = entry.write;\n const info = write && known.get(write.component);\n const name = info?.scopes[write!.k]?.slots[write!.slot];\n return name\n ? `${info!.name} ${name} = ${entry.text.split(' = ').slice(1).join(' = ')}`\n : entry.text;\n}\n\nlet panel: HTMLElement | undefined;\n\n/** Opens the panel, or closes it when it is open. */\nexport function togglePanel(root: ShadowRoot, state: DevtoolsState): void {\n if (panel) {\n panel.remove();\n panel = undefined;\n state.changed = undefined;\n return;\n }\n let tab: Tab = 'scopes';\n let selected: string | undefined;\n let selectedScope: number | undefined;\n let editing: { scope: number; slot: number } | undefined;\n let paused = false;\n const shown = new Set<DevtoolsEntry['kind']>(KINDS);\n // The log as it was when Pause was pressed.\n let frozen: DevtoolsEntry[] | undefined;\n\n const body = element('div', { class: 'body' });\n const bar = element('div', { class: 'bar', role: 'tablist' });\n for (const [name, label] of [\n ['scopes', 'Scopes'],\n ['graph', 'Graph'],\n ['log', 'Log'],\n ['report', 'Report'],\n ] as const) {\n const button = element('button', { class: 'tab', role: 'tab', 'data-tab': name }, label);\n button.addEventListener('click', () => {\n tab = name;\n draw();\n });\n bar.append(button);\n }\n const pick = element(\n 'button',\n {\n class: 'end',\n 'aria-pressed': 'false',\n title: 'Click an element of the page to find its scope',\n },\n 'Pick',\n );\n bar.append(pick);\n panel = element('div', { class: 'panel' }, element('style', {}, STYLE), bar, body);\n root.append(panel);\n // Without an event, the core has not loaded yet, and nothing knows the components of the page.\n if (!state.scopes) {\n document.dispatchEvent(new Event('brumate:core'));\n }\n\n // Outlines the elements of a scope on the page.\n const outlines: HTMLElement[] = [];\n const outline = (scope?: number): void => {\n for (const box of outlines.splice(0)) {\n box.remove();\n }\n if (scope === undefined) {\n return;\n }\n for (const target of document.querySelectorAll(`[b-b^=\"${scope}:\"]`)) {\n const rect = target.getBoundingClientRect();\n const box = element('div', {\n class: 'outline',\n style: `left:${rect.left}px;top:${rect.top}px;width:${rect.width}px;height:${rect.height}px`,\n });\n root.append(box);\n outlines.push(box);\n }\n };\n\n // Pick: the next click on the page selects the scope of its element.\n const onPick = (event: MouseEvent): void => {\n const target = (event.target as Element | null)?.closest?.('[b-b]');\n if (!target || event.composedPath().includes(panel!)) {\n return;\n }\n event.preventDefault();\n event.stopImmediatePropagation();\n stopPicking();\n selectedScope = Number(target.getAttribute('b-b')!.split(':')[0]);\n const scope = state.scopes?.get(selectedScope);\n selected = scope ? rootOf(scope).m : selected;\n tab = 'scopes';\n draw();\n };\n const stopPicking = (): void => {\n pick.setAttribute('aria-pressed', 'false');\n window.removeEventListener('click', onPick, true);\n document.documentElement.style.cursor = '';\n };\n pick.addEventListener('click', () => {\n if (pick.getAttribute('aria-pressed') === 'true') {\n stopPicking();\n return;\n }\n pick.setAttribute('aria-pressed', 'true');\n document.documentElement.style.cursor = 'crosshair';\n // On the window, so it runs before the listeners of the loader on the document.\n window.addEventListener('click', onPick, true);\n });\n\n /** A slot with its name and value. A value that JSON can hold can be edited. */\n const drawSlot = (scope: Scope, slot: number, name: string): HTMLElement => {\n const value = scope.s[slot];\n const line = element('div', { class: 'slot' }, element('span', { class: 'name' }, name), ' = ');\n if (editing?.scope === scope.id && editing.slot === slot) {\n const input = element('input', { 'aria-label': `New value of ${name}` });\n input.value = JSON.stringify(value) ?? '';\n input.addEventListener('keydown', (event) => {\n if (event.key === 'Enter') {\n editing = undefined;\n state.set?.(scope, slot, parseValue(input.value));\n draw();\n } else if (event.key === 'Escape') {\n editing = undefined;\n draw();\n }\n });\n line.append(input);\n queueMicrotask(() => input.focus());\n return line;\n }\n const canEdit = editable(value) && state.set !== undefined;\n const text = element('span', { class: canEdit ? 'value' : '' }, preview(value));\n if (canEdit) {\n text.title = 'Click to edit. Enter JSON, or text for a string.';\n text.addEventListener('click', () => {\n editing = { scope: scope.id, slot };\n draw();\n });\n }\n line.append(text);\n return line;\n };\n\n /** A scope with its slots and the scopes inside it, other than components. */\n const drawScope = (scope: Scope, info: ComponentInfo | undefined): HTMLElement => {\n const plan = info?.scopes[scope.k];\n const classes = ['scope'];\n if (state.written.has(scope.id)) {\n classes.push('written');\n }\n if (selectedScope === scope.id) {\n classes.push('selected');\n }\n const label = element(\n 'div',\n { class: 'scope-label' },\n // A hidden `#offscreen` body keeps its scope and its slots.\n `scope ${scope.id}${plan ? ` · ${plan.label}` : ''}${scope.h ? ' · hidden' : ''}`,\n );\n label.addEventListener('mouseenter', () => outline(scope.id));\n label.addEventListener('mouseleave', () => outline());\n const box = element('div', { class: classes.join(' ') }, label);\n scope.s.forEach((_, slot) =>\n box.append(drawSlot(scope, slot, plan?.slots[slot] ?? `slot ${slot}`)),\n );\n for (const child of scope.children) {\n if (child.m === undefined) {\n box.append(drawScope(child, info));\n }\n }\n return box;\n };\n\n const roots = (): Scope[] =>\n [...(state.scopes?.values() ?? [])].filter((scope) => scope.m !== undefined);\n\n const drawScopes = async (): Promise<void> => {\n const list = roots();\n const infos = await Promise.all(list.map((scope) => componentInfo(state, scope.m!)));\n const content = element('div');\n list.forEach((scope, index) => {\n const info = infos[index];\n const name = element('button', {}, info ? `${info.name} (${info.file})` : scope.m!);\n name.title = 'Show the graph of this component';\n name.addEventListener('click', () => {\n selected = scope.m;\n tab = 'graph';\n draw();\n });\n content.append(element('div', { class: 'component' }, name, drawScope(scope, info)));\n });\n if (list.length === 0) {\n content.append(\n element('div', { class: 'empty' }, 'No scopes yet. The first event loads them.'),\n );\n }\n body.replaceChildren(content);\n body.querySelector('.selected')?.scrollIntoView({ block: 'nearest' });\n };\n\n /** A select of the components on the page, for Graph and Report. */\n const chooser = (current: string | undefined): HTMLElement => {\n const select = element('select', { 'aria-label': 'Component' });\n for (const id of new Set(roots().map((scope) => scope.m!))) {\n const option = element('option', { value: id }, known.get(id)?.name ?? id);\n option.selected = id === current;\n select.append(option);\n }\n select.addEventListener('change', () => {\n selected = select.value;\n draw();\n });\n return element('div', {}, select);\n };\n\n let cooling: ReturnType<typeof setTimeout> | undefined;\n\n const drawGraph = async (): Promise<void> => {\n const id = selected ?? roots()[0]?.m;\n const info = id ? await componentInfo(state, id) : undefined;\n if (!id || !info) {\n body.replaceChildren(element('div', { class: 'empty' }, 'No component yet.'));\n return;\n }\n if (!info.graph) {\n body.replaceChildren(\n chooser(id),\n element(\n 'div',\n { class: 'empty' },\n 'The dev server sent no graph. It runs an older brumate than this panel: restart it.',\n ),\n );\n return;\n }\n const { nodes, edges } = info.graph;\n // The current value of each value node, from the first instance of the component.\n const instance = roots().find((scope) => scope.m === id);\n // The first scope of the instance for each scope in the compiled component.\n const scopeOfNode = new Map<number, Scope>();\n const visit = (scope: Scope): void => {\n if (!scopeOfNode.has(scope.k)) {\n scopeOfNode.set(scope.k, scope);\n }\n for (const child of scope.children) {\n if (child.m === undefined) {\n visit(child);\n }\n }\n };\n if (instance) {\n visit(instance);\n }\n // Nodes that a recent write reached: the written value, and what reads it.\n const now = performance.now();\n const hot = new Set<number>();\n for (const entry of state.log) {\n if (entry.write?.component === id && now - entry.time < HOT_MS) {\n nodes.forEach((node, index) => {\n if (node.scope === entry.write!.k && node.slot === entry.write!.slot) {\n hot.add(index);\n }\n });\n }\n }\n for (let grew = true; grew;) {\n grew = false;\n for (const [from, to] of edges) {\n if (hot.has(from) && !hot.has(to)) {\n hot.add(to);\n grew = true;\n }\n }\n }\n // Columns by the longest path from a value that nothing feeds.\n const depth = nodes.map(() => 0);\n for (let round = 0, changed = true; changed && round < nodes.length; round++) {\n changed = false;\n for (const [from, to] of edges) {\n if (depth[from]! + 1 > depth[to]!) {\n depth[to] = depth[from]! + 1;\n changed = true;\n }\n }\n }\n const rows = new Map<number, number>();\n const position = nodes.map((_, index) => {\n const column = depth[index]!;\n const row = rows.get(column) ?? 0;\n rows.set(column, row + 1);\n return { x: 8 + column * 150, y: 8 + row * 34 };\n });\n const width = 8 + (Math.max(0, ...depth) + 1) * 150;\n const height = 8 + Math.max(1, ...rows.values()) * 34;\n const graph = svg('svg', { width, height, role: 'img', 'aria-label': `Graph of ${info.name}` });\n for (const [from, to] of edges) {\n const a = position[from]!;\n const b = position[to]!;\n graph.append(\n svg('line', {\n x1: a.x + 132,\n y1: a.y + 12,\n x2: b.x,\n y2: b.y + 12,\n class: hot.has(from) && hot.has(to) ? 'hot-edge' : '',\n }),\n );\n }\n nodes.forEach((node, index) => {\n const { x, y } = position[index]!;\n const text = svg('text', { x: x + 6, y: y + 16 });\n const owner = node.slot === undefined ? undefined : scopeOfNode.get(node.scope);\n const value = owner && node.slot !== undefined ? ` = ${preview(owner.s[node.slot])}` : '';\n text.textContent = `${node.label}${value}`.slice(0, 22);\n const title = svg('title', {});\n title.textContent = `${node.kind} ${node.label}${value}`;\n graph.append(\n svg(\n 'g',\n { class: `kind-${node.kind}${hot.has(index) ? ' hot' : ''}` },\n svg('rect', { x, y, width: 132, height: 24, rx: 4 }),\n text,\n title,\n ),\n );\n });\n const legend = element(\n 'div',\n { class: 'legend' },\n 'What reads what, left to right: ',\n element('b', { class: 'signal' }, 'signals and props'),\n ', ',\n element('b', { class: 'memo' }, 'memos'),\n ', markup and ',\n element('b', { class: 'effect' }, 'effects'),\n '. A change lights up in ',\n element('b', { class: 'hot' }, 'yellow'),\n ' what it reaches.',\n );\n body.replaceChildren(\n chooser(id),\n ...(nodes.length > 0\n ? [legend, graph]\n : [\n element('div', { class: 'empty' }, 'Nothing in this component changes in the browser.'),\n ]),\n );\n // Draws again when the marks of the last write expire.\n if (hot.size > 0) {\n clearTimeout(cooling);\n cooling = setTimeout(() => state.changed?.(), HOT_MS);\n }\n };\n\n const drawLog = (): void => {\n const filters = element('div', { class: 'filters' });\n for (const kind of KINDS) {\n const box = element('input', { type: 'checkbox' });\n box.checked = shown.has(kind);\n box.addEventListener('change', () => {\n if (box.checked) {\n shown.add(kind);\n } else {\n shown.delete(kind);\n }\n draw();\n });\n filters.append(element('label', {}, box, kind));\n }\n const pause = element(\n 'button',\n { 'aria-pressed': String(paused) },\n paused ? 'Resume' : 'Pause',\n );\n pause.addEventListener('click', () => {\n paused = !paused;\n frozen = paused ? [...state.log] : undefined;\n draw();\n });\n const clear = element('button', {}, 'Clear');\n clear.addEventListener('click', () => {\n state.log.length = 0;\n frozen = paused ? [] : undefined;\n draw();\n });\n filters.append(pause, clear);\n const list = element('div');\n const entries = (frozen ?? state.log).filter((entry) => shown.has(entry.kind));\n for (const entry of entries.toReversed()) {\n list.append(\n element(\n 'div',\n { class: `entry ${entry.kind}` },\n element('span', { class: 'time' }, `${(entry.time / 1000).toFixed(2)}s`),\n element('span', { class: 'kind' }, entry.kind),\n ` ${entry.kind === 'write' ? describe(entry) : entry.text}`,\n ),\n );\n }\n if (entries.length === 0) {\n list.append(element('div', { class: 'empty' }, 'Nothing to show.'));\n }\n body.replaceChildren(filters, list);\n };\n\n const drawReport = async (): Promise<void> => {\n const id = selected ?? roots()[0]?.m;\n const info = id ? await componentInfo(state, id) : undefined;\n body.replaceChildren(\n ...(info\n ? [chooser(id), element('pre', {}, info.text)]\n : [element('div', { class: 'empty' }, 'No component yet.')]),\n );\n };\n\n let queued = false;\n const draw = (): void => {\n for (const button of bar.querySelectorAll('.tab')) {\n button.setAttribute('aria-selected', String((button as HTMLElement).dataset.tab === tab));\n }\n if (tab === 'log') {\n drawLog();\n return;\n }\n const drawn = tab === 'scopes' ? drawScopes() : tab === 'graph' ? drawGraph() : drawReport();\n // Marks of writes show once, on the next draw of the scopes.\n void drawn.then(() => {\n if (tab === 'scopes') {\n state.written.clear();\n }\n });\n };\n // Changes come in bursts, so the panel draws once per frame. It waits while a value is edited.\n state.changed = () => {\n if (!queued && !editing && !(paused && tab === 'log')) {\n queued = true;\n requestAnimationFrame(() => {\n queued = false;\n if (panel) {\n draw();\n }\n });\n }\n };\n draw();\n}\n"],"mappings":";;AA+BA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4Cd,MAAM,QAAiC;CAAC;CAAW;CAAQ;CAAS;AAAM;;AAE1E,MAAM,SAAS;AAEf,MAAM,6BAAa,IAAI,IAAgD;AACvE,MAAM,wBAAQ,IAAI,IAA2B;;AAG7C,SAAS,cAAc,OAAsB,IAAgD;CAC3F,IAAI,OAAO,WAAW,IAAI,EAAE;CAC5B,IAAI,CAAC,MAAM;EACT,OAAO,MAAM,GAAG,MAAM,SAAS,GAAG,mBAAmB,EAAE,GAAG,CAAC,CACxD,MAAM,aAAc,SAAS,KAAM,SAAS,KAAK,IAA+B,KAAA,CAAU,CAAC,CAC3F,MAAM,UAAU;GACf,IAAI,OACF,MAAM,IAAI,IAAI,KAAK;GAErB,OAAO;EACT,CAAC,CAAC,CACD,YAAY,KAAA,CAAS;EACxB,WAAW,IAAI,IAAI,IAAI;CACzB;CACA,OAAO;AACT;AAEA,SAAS,QACP,KACA,aAAqC,CAAC,GACtC,GAAG,UACuB;CAC1B,MAAM,OAAO,SAAS,cAAc,GAAG;CACvC,KAAK,MAAM,CAAC,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K,MAAM,cAAc,OAAO,EAAE,IAAI,KAAA;EACnD,KAAK,gBACH,GAAI,OACA,CAAC,QAAQ,EAAE,GAAG,QAAQ,OAAO,CAAC,GAAG,KAAK,IAAI,CAAC,IAC3C,CAAC,QAAQ,OAAO,EAAE,OAAO,QAAQ,GAAG,mBAAmB,CAAC,CAC9D;CACF;CAEA,IAAI,SAAS;CACb,MAAM,aAAmB;EACvB,KAAK,MAAM,UAAU,IAAI,iBAAiB,MAAM,GAC9C,OAAO,aAAa,iBAAiB,OAAQ,OAAuB,QAAQ,QAAQ,GAAG,CAAC;EAE1F,IAAI,QAAQ,OAAO;GACjB,QAAQ;GACR;EACF;EAGA,CAFc,QAAQ,WAAW,WAAW,IAAI,QAAQ,UAAU,UAAU,IAAI,WAAW,EAAA,CAEhF,WAAW;GACpB,IAAI,QAAQ,UACV,MAAM,QAAQ,MAAM;EAExB,CAAC;CACH;CAEA,MAAM,gBAAgB;EACpB,IAAI,CAAC,UAAU,CAAC,WAAW,EAAE,UAAU,QAAQ,QAAQ;GACrD,SAAS;GACT,4BAA4B;IAC1B,SAAS;IACT,IAAI,OACF,KAAK;GAET,CAAC;EACH;CACF;CACA,KAAK;AACP"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"files-DdT84mPy.js","names":[],"sources":["../src/server-files.ts","../src/files.ts"],"sourcesContent":["// Files of server functions. A `.ts` or `.js` file whose first statement is\n// `'use server'` holds functions that only run on the server. Its exports are\n// server functions: the browser gets a stub for each one, which calls the\n// server, and the code of the file never ships.\n\nimport { parseSync } from 'oxc-parser';\nimport { functionId } from './plan.ts';\n\n/** The import of the stubs, which call server functions with `rpc` of the core. */\nconst CLIENT = 'brumate/client';\n\n/** True for a file whose first statement is `'use server'`, after comments. */\nexport function hasUseServer(source: string): boolean {\n return /^(?:\\s|\\/\\/[^\\n]*\\n|\\/\\*[\\s\\S]*?\\*\\/)*(['\"])use server\\1/.test(source);\n}\n\n/** True for a path that can be a file of server functions. */\nexport function isScriptFile(path: string): boolean {\n return (\n /\\.[cm]?[jt]sx?$/.test(path) && !path.endsWith('.d.ts') && !/\\.brm\\.[cm]?[jt]s$/.test(path)\n );\n}\n\n/** True for a function expression or an arrow. */\nfunction isFunction(node: { type: string } | null | undefined): boolean {\n return node?.type === 'ArrowFunctionExpression' || node?.type === 'FunctionExpression';\n}\n\n/**\n * The names of the functions that a file of server functions exports.\n * Throws for an export that is not a function, because the browser can only\n * call a server function through its stub.\n */\nexport function serverExports(source: string, filename: string): string[] {\n const { program, errors } = parseSync(filename, source, { lang: 'ts' });\n if (errors[0]) {\n throw new Error(`${errors[0].message} (${filename})`);\n }\n const functions = new Set<string>();\n const values = new Set<string>();\n const local = new Map<string, 'function' | 'value'>();\n for (const statement of program.body) {\n const declaration =\n statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n local.set(declaration.id.name, 'function');\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier') {\n local.set(declarator.id.name, isFunction(declarator.init) ? 'function' : 'value');\n }\n }\n }\n }\n for (const statement of program.body) {\n if (statement.type === 'ExportDefaultDeclaration') {\n const value = statement.declaration;\n if (value.type === 'FunctionDeclaration' || isFunction(value)) {\n functions.add('default');\n } else {\n values.add('default');\n }\n } else if (statement.type === 'ExportNamedDeclaration') {\n if (statement.exportKind === 'type') {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n functions.add(declaration.id.name);\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier') {\n (isFunction(declarator.init) ? functions : values).add(declarator.id.name);\n }\n }\n } else if (declaration && !declaration.type.startsWith('TS')) {\n values.add('a class');\n }\n for (const specifier of statement.specifiers) {\n if (specifier.exportKind === 'type') {\n continue;\n }\n const name =\n specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value;\n const from = specifier.local.type === 'Identifier' ? specifier.local.name : '';\n (local.get(from) === 'function' && !statement.source ? functions : values).add(name);\n }\n } else if (statement.type === 'ExportAllDeclaration') {\n values.add('*');\n }\n }\n if (values.size > 0) {\n throw new Error(\n `A 'use server' file exports only functions, because the browser calls them on the server. ${[...values].join(', ')} of ${filename} is not one`,\n );\n }\n return [...functions];\n}\n\n/** The module that the browser gets in place of a file of server functions. */\nexport function serverStubs(\n source: string,\n filename: string,\n id: string,\n hideNames = false,\n): string {\n const lines = [`import { rpc } from ${JSON.stringify(CLIENT)};`];\n for (const name of serverExports(source, filename)) {\n const call = `(...args) => rpc(${JSON.stringify(functionId(id, name, hideNames))}, args)`;\n lines.push(name === 'default' ? `export default ${call};` : `export const ${name} = ${call};`);\n }\n return `${lines.join('\\n')}\\n`;\n}\n\n/**\n * The module that the server runs for a file of server functions: the file,\n * with each exported function wrapped, so its calls while a page renders\n * share a result when their arguments are the same. Offsets stay the same.\n */\nexport function serverModule(source: string, filename: string, id: string): string {\n const { program } = parseSync(filename, source, { lang: 'ts' });\n // Local names of exported functions, with the name that each is exported as.\n const wrapped = new Map<string, string>();\n const declarations = new Map<string, 'function' | 'const'>();\n let code = source;\n for (const statement of program.body) {\n const declaration =\n statement.type === 'ExportNamedDeclaration' ? statement.declaration : statement;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n declarations.set(declaration.id.name, 'function');\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier' && isFunction(declarator.init)) {\n declarations.set(declarator.id.name, 'const');\n }\n }\n }\n }\n const letOf = (declaration: { start: number; kind: string }): void => {\n // `const` becomes `let `, so the function can be wrapped and offsets stay the same.\n if (declaration.kind === 'const') {\n code = `${code.slice(0, declaration.start)}let ${code.slice(declaration.start + 5)}`;\n }\n };\n for (const statement of program.body) {\n if (\n statement.type !== 'ExportNamedDeclaration' ||\n statement.source ||\n statement.exportKind === 'type'\n ) {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id) {\n wrapped.set(declaration.id.name, declaration.id.name);\n } else if (declaration?.type === 'VariableDeclaration') {\n for (const declarator of declaration.declarations) {\n if (declarator.id.type === 'Identifier' && isFunction(declarator.init)) {\n wrapped.set(declarator.id.name, declarator.id.name);\n letOf(declaration);\n }\n }\n }\n for (const specifier of statement.specifiers) {\n const local = specifier.local.type === 'Identifier' ? specifier.local.name : '';\n const exported =\n specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value;\n if (declarations.has(local)) {\n wrapped.set(local, exported);\n }\n }\n }\n // A `const` arrow that `export { name }` exports is declared with `let` too.\n for (const statement of program.body) {\n if (statement.type === 'VariableDeclaration') {\n for (const declarator of statement.declarations) {\n if (declarator.id.type === 'Identifier' && wrapped.has(declarator.id.name)) {\n letOf(statement);\n }\n }\n }\n }\n if (wrapped.size === 0) {\n return source;\n }\n const lines = [\"import { dedupe as __brumateDedupe } from 'brumate/server';\"];\n for (const [local, exported] of wrapped) {\n lines.push(`${local} = __brumateDedupe(${local}, ${JSON.stringify(`${id}#${exported}`)});`);\n }\n return `${code}\\n${lines.join('\\n')}\\n`;\n}\n","import { readFile, readdir } from 'node:fs/promises';\nimport path from 'node:path';\nimport { hasUseServer, isScriptFile } from './server-files.ts';\n\n/** Skips `node_modules`, `dist` and hidden directories when looking for `.brm` files. */\nexport function defaultExclude(directory: string): boolean {\n return directory === 'node_modules' || directory === 'dist' || directory.startsWith('.');\n}\n\n/** Finds every `.brm` file under a directory, as absolute paths with forward slashes. */\nexport async function findFiles(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const directories: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n directories.push(visit(file));\n }\n } else if (entry.name.endsWith('.brm')) {\n result.push(file.split(path.sep).join('/'));\n }\n }\n await Promise.all(directories);\n };\n await visit(root);\n return result.toSorted();\n}\n\n/**\n * Finds every file of server functions under a directory: a script whose\n * first statement is `'use server'`.\n */\nexport async function findServerFiles(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const pending: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n pending.push(visit(file));\n }\n } else if (isScriptFile(entry.name)) {\n pending.push(\n readFile(file, 'utf8').then((source) => {\n if (hasUseServer(source)) {\n result.push(file.split(path.sep).join('/'));\n }\n }),\n );\n }\n }\n await Promise.all(pending);\n };\n await visit(root);\n return result.toSorted();\n}\n\n/**\n * Finds every script under a directory, such as `.ts` and `.brm.ts` files, as\n * absolute paths with forward slashes, without reading them.\n */\nexport async function findScripts(\n root: string,\n exclude: (directory: string) => boolean,\n): Promise<string[]> {\n const result: string[] = [];\n const visit = async (directory: string): Promise<void> => {\n const directories: Promise<void>[] = [];\n for (const entry of await readdir(directory, { withFileTypes: true })) {\n const file = path.join(directory, entry.name);\n if (entry.isDirectory()) {\n if (!exclude(entry.name)) {\n directories.push(visit(file));\n }\n } else if (/\\.[cm]?[jt]sx?$/.test(entry.name) && !entry.name.endsWith('.d.ts')) {\n result.push(file.split(path.sep).join('/'));\n }\n }\n await Promise.all(directories);\n };\n await visit(root);\n return result.toSorted();\n}\n"],"mappings":";;;;;;AASA,MAAM,SAAS;;AAGf,SAAgB,aAAa,QAAyB;CACpD,OAAO,2DAA2D,KAAK,MAAM;AAC/E;;AAGA,SAAgB,aAAa,MAAuB;CAClD,OACE,kBAAkB,KAAK,IAAI,KAAK,CAAC,KAAK,SAAS,OAAO,KAAK,CAAC,qBAAqB,KAAK,IAAI;AAE9F;;AAGA,SAAS,WAAW,MAAoD;C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IAAI,GACrB,QAAQ,KAAK,MAAM,IAAI,CAAC;GAAA,OAErB,IAAI,aAAa,MAAM,IAAI,GAChC,QAAQ,KACN,SAAS,MAAM,MAAM,CAAC,CAAC,MAAM,WAAW;IACtC,IAAI,aAAa,MAAM,GACrB,OAAO,KAAK,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;GAE9C,CAAC,CACH;EAEJ;EACA,MAAM,QAAQ,IAAI,OAAO;CAC3B;CACA,MAAM,MAAM,IAAI;CAChB,OAAO,OAAO,SAAS;AACzB;;;;;AAMA,eAAsB,YACpB,MACA,SACmB;CACnB,MAAM,SAAmB,CAAC;CAC1B,MAAM,QAAQ,OAAO,cAAqC;EACxD,MAAM,cAA+B,CAAC;EACtC,KAAK,MAAM,SAAS,MAAM,QAAQ,WAAW,EAAE,eAAe,KAAK,CAAC,GAAG;GACrE,MAAM,OAAO,KAAK,KAAK,WAAW,MAAM,IAAI;GAC5C,IAAI,MAAM,YAAY,GAChB;QAAA,CAAC,QAAQ,MAAM,IAAI,GACrB,YAAY,KAAK,MAAM,IAAI,CAAC;GAAA,OAEzB,IAAI,kBAAkB,KAAK,MAAM,IAAI,KAAK,CAAC,MAAM,KAAK,SAAS,OAAO,GAC3E,OAAO,KAAK,KAAK,MAAM,KAAK,GAAG,CAAC,CAAC,KAAK,GAAG,CAAC;EAE9C;EACA,MAAM,QAAQ,IAAI,WAAW;CAC/B;CACA,MAAM,MAAM,IAAI;CAChB,OAAO,OAAO,SAAS;AACzB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"html-DEeoepg3.js","names":[],"sources":["../src/runtime/html.ts"],"sourcesContent":["// HTML string helpers that the server and the client both use.\n\nconst RAW: unique symbol = Symbol.for('brumate.raw');\n\n/** HTML that is inserted as it is, such as the output of a template. */\nexport interface Raw {\n [RAW]: string;\n}\n\n// A class, not an object literal, so serializers can skip their test for raw HTML on plain objects.\nclass RawHTML implements Raw {\n readonly [RAW]: string;\n\n constructor(html: string) {\n this[RAW] = html;\n }\n}\n\nexport function raw(html: string): Raw {\n return new RawHTML(html);\n}\n\nexport function isRaw(value: unknown): value is Raw {\n return typeof value === 'object' && value !== null && RAW in value;\n}\n\nexport function rawHTML(value: Raw): string {\n return value[RAW];\n}\n\nconst ESCAPES: Record<string, string> = { '&': '&', '<': '<', '>': '>', '\"': '"' };\n\nconst toEscape = (char: string): string => ESCAPES[char]!;\n\n// Most text has nothing to escape, so a test without the global flag skips the replace.\nexport function escape(value: string): string {\n return /[&<>]/.test(value) ? value.replace(/[&<>]/g, toEscape) : value;\n}\n\nexport function escapeAttribute(value: string): string {\n return /[&<\"]/.test(value) ? value.replace(/[&<\"]/g, toEscape) : value;\n}\n\n/** Renders a value inserted in markup. Promises are not awaited. */\nexport function insertValue(value: unknown): string {\n if (isRaw(value)) {\n return value[RAW];\n }\n if (value === null || value === undefined || typeof value === 'boolean') {\n return '';\n }\n if (Array.isArray(value)) {\n return value.map(insertValue).join('');\n }\n return escape(String(value));\n}\n\n/**\n * Renders a value as the text of an element whose content is text, such as\n * a `<textarea>`, as `insertValue` does but without escaping.\n */\nexport function textValue(value: unknown): string {\n if (isRaw(value)) {\n return value[RAW];\n }\n if (value === null || value === undefined || typeof value === 'boolean') {\n return '';\n }\n if (Array.isArray(value)) {\n return value.map(textValue).join('');\n }\n return String(value);\n}\n\nfunction toKebabCase(name: string): string {\n return name.startsWith('--') ? name : name.replace(/[A-Z]/g, (char) => `-${char.toLowerCase()}`);\n}\n\nexport function classValue(value: unknown): string {\n if (typeof value !== 'object' || value === null) {\n return value ? String(value) : '';\n }\n let text = '';\n if (Array.isArray(value)) {\n for (const item of value) {\n const part = classValue(item);\n if (part !== '') {\n text = text === '' ? part : `${text} ${part}`;\n }\n }\n return text;\n }\n // An empty name still adds a space between its neighbours, as in a join.\n let first = true;\n for (const name in value) {\n if (Object.hasOwn(value, name) && (value as Record<string, unknown>)[name]) {\n text = first ? name : `${text} ${name}`;\n first = false;\n }\n }\n return text;\n}\n\n/**\n * Renders a `class` attribute from classes that each have a space before\n * them, which the compiler builds from a literal class value. The classes\n * are escaped already. No class renders nothing.\n */\nexport function classAttribute(classes: string): string {\n return classes === '' ? '' : ` class=\"${classes.slice(1)}\"`;\n}\n\nfunction styleValue(value: unknown): string {\n if (typeof value === 'object' && value !== null) {\n return Object.entries(value)\n .filter(([, item]) => item !== null && item !== undefined && item !== false)\n .map(([name, item]) => `${toKebabCase(name)}:${String(item)}`)\n .join(';');\n }\n return String(value);\n}\n\n/**\n * Returns the text of an attribute, or undefined if the attribute is not\n * rendered. `true` renders as an empty value.\n */\nexport function attributeText(name: string, value: unknown): string | undefined {\n if (value === null || value === undefined || value === false || typeof value === 'function') {\n return undefined;\n }\n if (value === true) {\n return '';\n }\n if (name === 'class') {\n const text = classValue(value);\n return text === '' ? undefined : text;\n }\n return name === 'style' ? styleValue(value) : String(value);\n}\n\n/** Renders one attribute, with a leading space. */\nexport function attribute(name: string, value: unknown): string {\n const text = attributeText(name, value);\n if (text === undefined) {\n return '';\n }\n return value === true ? ` ${name}` : ` ${name}=\"${escapeAttribute(text)}\"`;\n}\n\n/**\n * Returns the value of a style variable with text around it, such as `12px`\n * for `${size}px`. A value that sets no variable stays as it is.\n */\nexport function affix(prefix: string, value: unknown, suffix: string): unknown {\n return value === null || value === undefined || value === false\n ? value\n : `${prefix}${String(value)}${suffix}`;\n}\n\n/** Returns a style with custom properties before an element's own style. */\nexport function vars(variables: Record<string, unknown>, own: unknown): string {\n const parts: string[] = [];\n for (const [name, value] of Object.entries(variables)) {\n if (value !== null && value !== undefined && value !== false) {\n parts.push(`${name}:${String(value)}`);\n }\n }\n const rest = own === null || own === undefined || own === false ? '' : styleValue(own);\n if (rest) {\n parts.push(rest);\n }\n return parts.join(';');\n}\n\n/** Returns a `<style>` element for a component's stylesheet. */\nexport function styleElement(id: string, css: string): string {\n return `<style b-style=\"${escapeAttribute(id)}\">${css.replace(/<\\/style/gi, '<\\\\/style')}</style>`;\n}\n\n/** Renders an object of attributes. */\nexport function spread(attributes: Record<string, unknown>): string {\n let result = '';\n for (const [name, value] of Object.entries(attributes)) {\n if (name !== 'children' && !/^on[A-Z]/.test(name)) {\n result += attribute(name, value);\n }\n }\n return result;\n}\n\nexport const VOID_ELEMENTS: Set<string> = new Set([\n 'area',\n 'base',\n 'br',\n 'col',\n 'embed',\n 'hr',\n 'img',\n 'input',\n 'link',\n 'meta',\n 'source',\n 'track',\n 'wbr',\n]);\n\n/**\n * Renders the attributes of a form that posts to a server function, such as\n * ` action=\"/_brumate/App_1abc%23save\" method=\"post\"`. `method` is the name of\n * the method attribute to add, if the element has none.\n */\nexport function actionAttributes(\n prefix: string,\n name: string,\n id: string,\n method?: string,\n result?: string,\n): string {\n const methodText = method ? ` ${method}=\"post\"` : '';\n if (result !== undefined) {\n // The form posts to its page, which renders with the result. With the\n // loader, the result is written into the `$action` at `result` instead.\n return ` ${name}=\"?__action=${encodeURIComponent(id)}\"${methodText} b-action=\"${escapeAttribute(id)}\" b-result=\"${escapeAttribute(result)}\"`;\n }\n const url = `${prefix}/${encodeURIComponent(id)}`;\n return ` ${name}=\"${escapeAttribute(url)}\"${methodText}`;\n}\n"],"mappings":";AAEA,MAAM,MAAqB,OAAO,IAAI,aAAa;AAQnD,IAAM,UAAN,MAA6B;CAC3B,CAAU;CAEV,YAAY,MAAc;EACxB,KAAK,OAAO;CACd;AACF;AAEA,SAAgB,IAAI,MAAmB;CACrC,OAAO,IAAI,QAAQ,IAAI;AACzB;AAEA,SAAgB,MAAM,OAA8B;CAClD,OAAO,OAAO,UAAU,YAAY,UAAU,QAAQ,OAAO;AAC/D;AAEA,SAAgB,QAAQ,OAAoB;CAC1C,OAAO,MAAM;AACf;AAEA,MAAM,UAAkC;CAAE,KAAK;CAAS,KAAK;CAAQ,KAAK;CAAQ,MAAK;AAAS;AAEhG,MAAM,YAAY,SAAyB,QAAQ;AAGnD,SAAgB,OAAO,OAAuB;CAC5C,OAAO,QAAQ,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