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
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"client-routes-JTbGtukf.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, ScopeId, 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/** 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/** 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/** 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(shiftId(value.scope, by), value.anchor);\n }\n if (value instanceof FunctionReference) {\n return new FunctionReference(value.ref, shiftId(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[shiftId(readId(key), by)] = {\n ...record,\n p: record.p === undefined ? undefined : shiftId(record.p, by),\n o: record.o === undefined ? undefined : shiftId(record.o, by),\n c:\n record.c &&\n Object.fromEntries(\n Object.entries(record.c).map(([anchor, id]) => [anchor, shiftId(id, by)]),\n ),\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<ScopeId>): 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(readId)));\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(readId));\n const alias = new Map<ScopeId, ScopeId>();\n for (const pair of (script.getAttribute('b-alias') ?? '').split(',').filter(Boolean)) {\n const [from, to] = pair.split(':').map(readId) as [ScopeId, ScopeId];\n alias.set(from, to);\n }\n const 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 const resolve = (id: ScopeId | undefined): ScopeId | 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 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 ({ 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,OAAO,MAAuB;CACrC,OAAO,UAAU,KAAK,IAAI,IAAI,OAAO,IAAI,IAAI;AAC/C;;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,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,QAAQ,MAAM,OAAO,EAAE,GAAG,MAAM,MAAM;EAEpE,IAAI,iBAAiB,mBACnB,OAAO,IAAI,kBAAkB,MAAM,KAAK,QAAQ,MAAM,OAAO,EAAE,CAAC;EAGlE,IAAI,iBA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E,EAAE,kBAAkB,mBAAmB,OAAO,WAAW,aAAa,aAAa,aAAa;CAC/F,MAAM,OAAO;EAAE;EAAkB;EAAmB;EAAO;EAAa;CAAO;CAC/E,MAAM,UAAU,QAAQ,UAAU,YAAY,MAAM,QAAQ,KAAK;CACjE,QAAQ,YAAa,UAAU,YAAY,IAAI,UAAU;AAC3D,CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
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
|
+
/** The key of the context of `$route`. The server and the loader write it. */
|
|
13
|
+
const ROUTE_KEY = "brumate.route";
|
|
14
|
+
/** The key of the context of `$navigation`. The loader writes it. */
|
|
15
|
+
const NAVIGATION_KEY = "brumate.navigation";
|
|
16
|
+
/** 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
|
+
});
|
|
22
|
+
/** The context that `$navigation` reads. The loader writes it while a page loads. */
|
|
23
|
+
const navigationContext = createContext(NAVIGATION_KEY, { pending: false });
|
|
24
|
+
//#endregion
|
|
25
|
+
export { routeContext as a, navigationContext as i, ROUTE_KEY as n, createContext as r, NAVIGATION_KEY as t };
|
|
26
|
+
|
|
27
|
+
//# sourceMappingURL=context-CTiSzQRc.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"context-CTiSzQRc.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\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 url: new URL('http://localhost/'),\n search: new URLSearchParams(),\n params: {},\n});\n\n/** The context that `$navigation` reads. The loader writes it while a page loads. */\nexport const navigationContext: Context<NavigationState> = createContext(NAVIGATION_KEY, {\n pending: false,\n});\n"],"mappings":";;;;;AAYA,SAAgB,cAAiB,KAAa,cAA6B;CACzE,OAAO;EAAE;EAAK;CAAa;AAC7B;;AAuBA,MAAa,YAAY;;AAEzB,MAAa,iBAAiB;;AAG9B,MAAa,eAA+B,cAAc,WAAW;CACnE,KAAK,IAAI,IAAI,mBAAmB;CAChC,QAAQ,IAAI,gBAAgB;CAC5B,QAAQ,CAAC;AACX,CAAC;;AAGD,MAAa,oBAA8C,cAAc,gBAAgB,EACvF,SAAS,MACX,CAAC"}
|
|
@@ -0,0 +1,42 @@
|
|
|
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
|
+
/** The route of the page, for `$route`. */
|
|
15
|
+
interface Route<P = Record<string, string>> {
|
|
16
|
+
/** The URL of the page. */
|
|
17
|
+
url: URL;
|
|
18
|
+
/** The query string of the page, as `url.searchParams`. */
|
|
19
|
+
search: URLSearchParams;
|
|
20
|
+
/** The params of the route, such as `{ id: '3' }` for `/issues/[id]`. */
|
|
21
|
+
params: P;
|
|
22
|
+
}
|
|
23
|
+
/** The navigation that loads, for `$navigation`. */
|
|
24
|
+
interface NavigationState {
|
|
25
|
+
/** True while a page loads without a full page load. */
|
|
26
|
+
pending: boolean;
|
|
27
|
+
/** The URL of the page that is left, while one loads. */
|
|
28
|
+
from?: string;
|
|
29
|
+
/** The URL of the page that loads. */
|
|
30
|
+
to?: string;
|
|
31
|
+
}
|
|
32
|
+
/** The key of the context of `$route`. The server and the loader write it. */
|
|
33
|
+
declare const ROUTE_KEY = "brumate.route";
|
|
34
|
+
/** The key of the context of `$navigation`. The loader writes it. */
|
|
35
|
+
declare const NAVIGATION_KEY = "brumate.navigation";
|
|
36
|
+
/** The context that `$route` reads. Its value comes from the request on the server, and from `location` in the browser. */
|
|
37
|
+
declare const routeContext: Context<Route>;
|
|
38
|
+
/** The context that `$navigation` reads. The loader writes it while a page loads. */
|
|
39
|
+
declare const navigationContext: Context<NavigationState>;
|
|
40
|
+
//#endregion
|
|
41
|
+
export { Route as a, routeContext as c, ROUTE_KEY as i, NAVIGATION_KEY as n, createContext as o, NavigationState as r, navigationContext as s, Context as t };
|
|
42
|
+
//# sourceMappingURL=context-btHuB01Z.d.ts.map
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
import { n as trustedHTML, r as trustedScript } from "./skew-FRmAy9iy.js";
|
|
2
|
+
import { ct as skew, d as build } from "./client-C0UCNL3J.js";
|
|
3
|
+
//#region src/runtime/defer.ts
|
|
4
|
+
/** The nonce of a script. Browsers hide the attribute once the page loads, and keep the property. */
|
|
5
|
+
function nonceOf(script) {
|
|
6
|
+
return script.nonce || script.getAttribute("nonce");
|
|
7
|
+
}
|
|
8
|
+
/** The Content Security Policy nonce of the page, which the scripts of the answer need to run. */
|
|
9
|
+
function pageNonce() {
|
|
10
|
+
for (const script of document.querySelectorAll("script")) {
|
|
11
|
+
const nonce = nonceOf(script);
|
|
12
|
+
if (nonce) return nonce;
|
|
13
|
+
}
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Asks the server for the body of the `#defer` block of a `<template
|
|
17
|
+
* b-defer>`, and puts it in place of the fallback. When the server cannot
|
|
18
|
+
* render it, such as a page that changed since it loaded, or a static host
|
|
19
|
+
* that answers with the whole page, the fallback stays.
|
|
20
|
+
*/
|
|
21
|
+
async function loadDeferred(template) {
|
|
22
|
+
const [, boundary, base] = template.getAttribute("b-defer").split(":");
|
|
23
|
+
const response = await fetch(location.href, { headers: {
|
|
24
|
+
"x-brumate-defer": `${boundary} ${template.getAttribute("b-b")}`,
|
|
25
|
+
"x-brumate-base": base,
|
|
26
|
+
...build === void 0 ? {} : { "x-brumate-build": build }
|
|
27
|
+
} });
|
|
28
|
+
if (response.status === 409 && response.headers.get("x-brumate-build")) {
|
|
29
|
+
skew("defer");
|
|
30
|
+
return;
|
|
31
|
+
}
|
|
32
|
+
if (!response.ok || response.headers.get("x-brumate-defer") !== boundary) return;
|
|
33
|
+
const parsed = document.createElement("template");
|
|
34
|
+
parsed.innerHTML = trustedHTML(await response.text());
|
|
35
|
+
const nonce = pageNonce();
|
|
36
|
+
for (const node of Array.from(parsed.content.childNodes)) {
|
|
37
|
+
if (node.nodeName !== "SCRIPT") {
|
|
38
|
+
document.body.append(node);
|
|
39
|
+
continue;
|
|
40
|
+
}
|
|
41
|
+
const script = node;
|
|
42
|
+
const copy = document.createElement("script");
|
|
43
|
+
for (const attribute of script.attributes) if (attribute.name !== "nonce") copy.setAttribute(attribute.name, attribute.value);
|
|
44
|
+
if (nonce) copy.nonce = nonce;
|
|
45
|
+
copy.textContent = trustedScript(script.textContent ?? "");
|
|
46
|
+
document.body.append(copy);
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { loadDeferred };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=defer-D0bo1Gqx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"defer-D0bo1Gqx.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 nonceOf(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 = nonceOf(script);\n if (nonce) {\n return nonce;\n }\n }\n return undefined;\n}\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 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,QAAQ,QAA0C;CACzD,OAAO,OAAO,SAAS,OAAO,aAAa,OAAO;AACpD;;AAGA,SAAS,YAAgC;CACvC,KAAK,MAAM,UAAU,SAAS,iBAAiB,QAAQ,GAAG;EACxD,MAAM,QAAQ,QAAQ,MAAM;EAC5B,IAAI,OACF,OAAO;CAEX;AAEF;;;;;;;AAQA,eAAsB,aAAa,UAAkC;CACnE,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"}
|
|
@@ -97,7 +97,7 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate") {
|
|
|
97
97
|
button.title = "Open the brumate devtools";
|
|
98
98
|
button.setAttribute("style", "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");
|
|
99
99
|
button.addEventListener("click", () => {
|
|
100
|
-
import("./devtools-panel-
|
|
100
|
+
import("./devtools-panel-AYjfwPhj.js").then(({ togglePanel }) => togglePanel(root, state));
|
|
101
101
|
});
|
|
102
102
|
root.append(button);
|
|
103
103
|
const append = () => {
|
|
@@ -110,4 +110,4 @@ function installDevtools(endpoint = "/__brumate/inspect", rpc = "/_brumate") {
|
|
|
110
110
|
//#endregion
|
|
111
111
|
export { preview as n, rootOf as r, installDevtools as t };
|
|
112
112
|
|
|
113
|
-
//# sourceMappingURL=devtools-
|
|
113
|
+
//# sourceMappingURL=devtools-C50VH8gZ.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools-C50VH8gZ.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';\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' | 'part' | '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\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 log: DevtoolsEntry[];\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 /** 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":";AAQA,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,sBAAsB,MAAM,aAA4B;CACjG,MAAM,QAAuB;EAAE,KAAK,CAAC;EAAG,yBAAS,IAAI,IAAI;EAAG;CAAS;CACrE,MAAM,OAAO,UAA6C;EACxD,MAAM,I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AO,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,4 +1,4 @@
|
|
|
1
|
-
import { n as preview, r as rootOf } from "./devtools-
|
|
1
|
+
import { n as preview, r as rootOf } from "./devtools-C50VH8gZ.js";
|
|
2
2
|
//#region src/runtime/devtools-panel.ts
|
|
3
3
|
const STYLE = `
|
|
4
4
|
:host { all: initial; }
|
|
@@ -173,7 +173,8 @@ function togglePanel(root, state) {
|
|
|
173
173
|
event.preventDefault();
|
|
174
174
|
event.stopImmediatePropagation();
|
|
175
175
|
stopPicking();
|
|
176
|
-
|
|
176
|
+
const id = target.getAttribute("b-b").split(":")[0];
|
|
177
|
+
selectedScope = /^-?\d+$/.test(id) ? Number(id) : id;
|
|
177
178
|
const scope = state.scopes?.get(selectedScope);
|
|
178
179
|
selected = scope ? rootOf(scope).m : selected;
|
|
179
180
|
tab = "scopes";
|
|
@@ -431,4 +432,4 @@ function togglePanel(root, state) {
|
|
|
431
432
|
//#endregion
|
|
432
433
|
export { togglePanel };
|
|
433
434
|
|
|
434
|
-
//# sourceMappingURL=devtools-panel-
|
|
435
|
+
//# sourceMappingURL=devtools-panel-AYjfwPhj.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"devtools-panel-AYjfwPhj.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 type { ScopeId } from './shared.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: ScopeId | undefined;\n let editing: { scope: ScopeId; 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?: ScopeId): 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 const id = target.getAttribute('b-b')!.split(':')[0]!;\n selectedScope = /^-?\\d+$/.test(id) ? Number(id) : id;\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":";;AAgCA,MAAM,QAAQ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AA4Cd,MAAM,QAA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C;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"}
|
|
@@ -0,0 +1,52 @@
|
|
|
1
|
+
//#region src/runtime/events.ts
|
|
2
|
+
/** The keys that `prevent` can name, by their `event.key`. `Space` is the space bar. */
|
|
3
|
+
const KEY_NAMES = [
|
|
4
|
+
"Enter",
|
|
5
|
+
"Escape",
|
|
6
|
+
"Tab",
|
|
7
|
+
"Space",
|
|
8
|
+
"Backspace",
|
|
9
|
+
"Delete",
|
|
10
|
+
"Insert",
|
|
11
|
+
"ArrowUp",
|
|
12
|
+
"ArrowDown",
|
|
13
|
+
"ArrowLeft",
|
|
14
|
+
"ArrowRight",
|
|
15
|
+
"Home",
|
|
16
|
+
"End",
|
|
17
|
+
"PageUp",
|
|
18
|
+
"PageDown",
|
|
19
|
+
"ContextMenu",
|
|
20
|
+
...Array.from({ length: 12 }, (_, index) => `F${index + 1}`)
|
|
21
|
+
];
|
|
22
|
+
/** The modifiers of a handler, which `spread` writes into `b-on`. A symbol of the registry. */
|
|
23
|
+
const MODIFIERS = Symbol.for("brumate.modifiers");
|
|
24
|
+
function tagged(handler, modifier) {
|
|
25
|
+
const copy = ((...args) => handler(...args));
|
|
26
|
+
copy[MODIFIERS] = [...handler[MODIFIERS] ?? [], modifier];
|
|
27
|
+
return copy;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Prevents the default action of the event, before the handler's code
|
|
31
|
+
* loads. With keys, on a keyboard event, it prevents only those keys, and
|
|
32
|
+
* the handler still runs for every key.
|
|
33
|
+
*/
|
|
34
|
+
function prevent(handler, ...keys) {
|
|
35
|
+
return tagged(handler, keys.length > 0 ? `prevent(${keys.join(",")})` : "prevent");
|
|
36
|
+
}
|
|
37
|
+
/** Stops the event at this element, so the handlers of the elements around it do not run. */
|
|
38
|
+
function stop(handler) {
|
|
39
|
+
return tagged(handler, "stop");
|
|
40
|
+
}
|
|
41
|
+
/** Runs the handler for the first event only. */
|
|
42
|
+
function once(handler) {
|
|
43
|
+
return tagged(handler, "once");
|
|
44
|
+
}
|
|
45
|
+
/** Runs the handler before the handlers of the elements inside, as a listener in the capture phase. */
|
|
46
|
+
function capture(handler) {
|
|
47
|
+
return tagged(handler, "capture");
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { prevent as a, once as i, MODIFIERS as n, stop as o, capture as r, KEY_NAMES as t };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=events-BKWRqtMg.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"events-BKWRqtMg.js","names":[],"sources":["../src/runtime/events.ts"],"sourcesContent":["// Wrappers for event handlers that act before the handler's code loads. The\n// compiler reads the calls in markup and writes them into `b-on`, so the\n// loader applies them on the first event. At run time, each returns a copy of\n// the handler that carries its modifiers, so a handler passed on as a prop\n// keeps them.\n\n/** The keys that `prevent` can name, by their `event.key`. `Space` is the space bar. */\nexport const KEY_NAMES: readonly string[] = [\n 'Enter',\n 'Escape',\n 'Tab',\n 'Space',\n 'Backspace',\n 'Delete',\n 'Insert',\n 'ArrowUp',\n 'ArrowDown',\n 'ArrowLeft',\n 'ArrowRight',\n 'Home',\n 'End',\n 'PageUp',\n 'PageDown',\n 'ContextMenu',\n ...Array.from({ length: 12 }, (_, index) => `F${index + 1}`),\n];\n\ntype Letter =\n | 'a'\n | 'b'\n | 'c'\n | 'd'\n | 'e'\n | 'f'\n | 'g'\n | 'h'\n | 'i'\n | 'j'\n | 'k'\n | 'l'\n | 'm'\n | 'n'\n | 'o'\n | 'p'\n | 'q'\n | 'r'\n | 's'\n | 't'\n | 'u'\n | 'v'\n | 'w'\n | 'x'\n | 'y'\n | 'z';\ntype Digit = '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9';\ntype FunctionKey = `F${1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12}`;\n\n/** A key by its `event.key`: a named key, a letter or a digit. */\nexport type KeyName =\n | 'Enter'\n | 'Escape'\n | 'Tab'\n | 'Space'\n | 'Backspace'\n | 'Delete'\n | 'Insert'\n | 'ArrowUp'\n | 'ArrowDown'\n | 'ArrowLeft'\n | 'ArrowRight'\n | 'Home'\n | 'End'\n | 'PageUp'\n | 'PageDown'\n | 'ContextMenu'\n | FunctionKey\n | Letter\n | Uppercase<Letter>\n | Digit;\n\n/** The modifiers of a handler, which `spread` writes into `b-on`. A symbol of the registry. */\nexport const MODIFIERS: unique symbol = Symbol.for('brumate.modifiers');\n\n/** A handler with the modifiers of its wrappers. */\n// oxlint-disable-next-line typescript/no-explicit-any -- Handlers take any event.\ntype Handler = (...args: any[]) => unknown;\n\nfunction tagged<H extends Handler>(handler: H, modifier: string): H {\n const copy = ((...args: unknown[]) => handler(...args)) as H & { [MODIFIERS]?: string[] };\n copy[MODIFIERS] = [...((handler as { [MODIFIERS]?: string[] })[MODIFIERS] ?? []), modifier];\n return copy;\n}\n\n/**\n * Prevents the default action of the event, before the handler's code\n * loads. With keys, on a keyboard event, it prevents only those keys, and\n * the handler still runs for every key.\n */\nexport function prevent<H extends Handler>(handler: H, ...keys: KeyName[]): H {\n return tagged(handler, keys.length > 0 ? `prevent(${keys.join(',')})` : 'prevent');\n}\n\n/** Stops the event at this element, so the handlers of the elements around it do not run. */\nexport function stop<H extends Handler>(handler: H): H {\n return tagged(handler, 'stop');\n}\n\n/** Runs the handler for the first event only. */\nexport function once<H extends Handler>(handler: H): H {\n return tagged(handler, 'once');\n}\n\n/** Runs the handler before the handlers of the elements inside, as a listener in the capture phase. */\nexport function capture<H extends Handler>(handler: H): H {\n return tagged(handler, 'capture');\n}\n"],"mappings":";;AAOA,MAAa,YAA+B;CAC1C;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA,GAAG,MAAM,KAAK,EAAE,QAAQ,GAAG,IAAI,GAAG,UAAU,IAAI,QAAQ,GAAG;AAC7D;;AAwDA,MAAa,YAA2B,OAAO,IAAI,mBAAmB;AAMtE,SAAS,OAA0B,SAAY,UAAqB;CAClE,MAAM,SAAS,GAAG,SAAoB,QAAQ,GAAG,IAAI;CACrD,KAAK,aAAa,CAAC,GAAK,QAAuC,cAAc,CAAC,GAAI,QAAQ;CAC1F,OAAO;AACT;;;;;;AAOA,SAAgB,QAA2B,SAAY,GAAG,MAAoB;CAC5E,OAAO,OAAO,SAAS,KAAK,SAAS,IAAI,WAAW,KAAK,KAAK,GAAG,EAAE,KAAK,SAAS;AACnF;;AAGA,SAAgB,KAAwB,SAAe;CACrD,OAAO,OAAO,SAAS,MAAM;AAC/B;;AAGA,SAAgB,KAAwB,SAAe;CACrD,OAAO,OAAO,SAAS,MAAM;AAC/B;;AAGA,SAAgB,QAA2B,SAAe;CACxD,OAAO,OAAO,SAAS,SAAS;AAClC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { g as functionId } from "./inspect-
|
|
1
|
+
import { g as functionId } from "./inspect-BJtACnQp.js";
|
|
2
2
|
import { parseSync } from "oxc-parser";
|
|
3
3
|
import { readFile, readdir } from "node:fs/promises";
|
|
4
4
|
import path from "node:path";
|
|
@@ -54,8 +54,23 @@ function serverExports(source, filename) {
|
|
|
54
54
|
}
|
|
55
55
|
} else if (statement.type === "ExportAllDeclaration") values.add("*");
|
|
56
56
|
if (values.size > 0) throw new Error(`A 'use server' file exports only functions, because the browser calls them on the server. ${[...values].join(", ")} of ${filename} is not one`);
|
|
57
|
+
functions.delete(MIDDLEWARE);
|
|
57
58
|
return [...functions];
|
|
58
59
|
}
|
|
60
|
+
/** The export of a file of server functions that runs before each of them. */
|
|
61
|
+
const MIDDLEWARE = "middleware";
|
|
62
|
+
/** True if a file of server functions exports `middleware`. */
|
|
63
|
+
function hasServerMiddleware(source, filename) {
|
|
64
|
+
const { program } = parseSync(filename, source, { lang: "ts" });
|
|
65
|
+
for (const statement of program.body) {
|
|
66
|
+
if (statement.type !== "ExportNamedDeclaration" || statement.exportKind === "type") continue;
|
|
67
|
+
const declaration = statement.declaration;
|
|
68
|
+
if (declaration?.type === "FunctionDeclaration" && declaration.id?.name === "middleware") return true;
|
|
69
|
+
if (declaration?.type === "VariableDeclaration" && declaration.declarations.some((declarator) => declarator.id.type === "Identifier" && declarator.id.name === "middleware")) return true;
|
|
70
|
+
if (statement.specifiers.some((specifier) => specifier.exportKind !== "type" && (specifier.exported.type === "Identifier" ? specifier.exported.name : specifier.exported.value) === "middleware")) return true;
|
|
71
|
+
}
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
59
74
|
/** The module that the browser gets in place of a file of server functions. */
|
|
60
75
|
function serverStubs(source, filename, id, hideNames = false) {
|
|
61
76
|
const lines = [`import { rpc } from ${JSON.stringify(CLIENT)};`];
|
|
@@ -172,6 +187,6 @@ async function findScripts(root, exclude) {
|
|
|
172
187
|
return result.toSorted();
|
|
173
188
|
}
|
|
174
189
|
//#endregion
|
|
175
|
-
export {
|
|
190
|
+
export { hasServerMiddleware as a, serverExports as c, findServerFiles as i, serverModule as l, findFiles as n, hasUseServer as o, findScripts as r, isScriptFile as s, defaultExclude as t, serverStubs as u };
|
|
176
191
|
|
|
177
|
-
//# sourceMappingURL=files-
|
|
192
|
+
//# sourceMappingURL=files-Bnn1JqHx.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"files-Bnn1JqHx.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 // The middleware of the file runs before its functions. The browser cannot call it.\n functions.delete(MIDDLEWARE);\n return [...functions];\n}\n\n/** The export of a file of server functions that runs before each of them. */\nexport const MIDDLEWARE = 'middleware';\n\n/** True if a file of server functions exports `middleware`. */\nexport function hasServerMiddleware(source: string, filename: string): boolean {\n const { program } = parseSync(filename, source, { lang: 'ts' });\n for (const statement of program.body) {\n if (statement.type !== 'ExportNamedDeclaration' || statement.exportKind === 'type') {\n continue;\n }\n const declaration = statement.declaration;\n if (declaration?.type === 'FunctionDeclaration' && declaration.id?.name === MIDDLEWARE) {\n return true;\n }\n if (\n declaration?.type === 'VariableDeclaration' &&\n declaration.declarations.some(\n (declarator) => declarator.id.type === 'Identifier' && declarator.id.name === MIDDLEWARE,\n )\n ) {\n return true;\n }\n if (\n statement.specifiers.some(\n (specifier) =>\n specifier.exportKind !== 'type' &&\n (specifier.exported.type === 'Identifier'\n ? specifier.exported.name\n : specifier.exported.value) === MIDDLEWARE,\n )\n ) {\n return true;\n }\n }\n return false;\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;CACtE,OAAO,MAAM,SAAS,6BAA6B,MAAM,SAAS;AACpE;;;;;;AAOA,SAAgB,cAAc,QAAgB,UAA4B;CACxE,MAAM,EAAE,SAAS,WAAW,UAAU,UAAU,QAAQ,EAAE,MAAM,KAAK,CAAC;CACtE,IAAI,OAAO,IACT,MAAM,IAAI,MAAM,GAAG,OAAO,EAAE,CAAC,QAAQ,IAAI,SAAS,EAAE;CAEtD,MAAM,4BAAY,IAAI,IAAY;CAClC,MAAM,yBAAS,IAAI,IAAY;CAC/B,MAAM,wBAAQ,IAAI,IAAkC;CACpD,KAAK,MAAM,aAAa,QAAQ,MAAM;EACpC,MAAM,cACJ,UAAU,SAAS,2BAA2B,UAAU,cAAc;EACx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+
/**
|
|
94
|
+
* A name that HTML reads as one attribute. A spread takes its names from
|
|
95
|
+
* data, so a name with a space, a quote, `>`, `/` or `=` could write other
|
|
96
|
+
* attributes or markup.
|
|
97
|
+
*/
|
|
98
|
+
const ATTRIBUTE_NAME = /^[^\s"'>/=\x00-\x1f\x7f]+$/;
|
|
99
|
+
/** Renders one attribute, with a leading space. A name that is not one attribute renders nothing. */
|
|
94
100
|
function attribute(name, value) {
|
|
95
101
|
const text = attributeText(name, value);
|
|
96
|
-
if (text === void 0) return "";
|
|
102
|
+
if (text === void 0 || !ATTRIBUTE_NAME.test(name)) return "";
|
|
97
103
|
return value === true ? ` ${name}` : ` ${name}="${escapeAttribute(text)}"`;
|
|
98
104
|
}
|
|
99
105
|
/**
|
|
@@ -115,6 +121,15 @@ function vars(variables, own) {
|
|
|
115
121
|
function styleElement(id, css) {
|
|
116
122
|
return `<style b-style="${escapeAttribute(id)}">${css.replace(/<\/style/gi, "<\\/style")}</style>`;
|
|
117
123
|
}
|
|
124
|
+
/**
|
|
125
|
+
* Merges the attributes of an element that has spreads, in their order: a
|
|
126
|
+
* later value wins, except `class`, whose values all apply.
|
|
127
|
+
*/
|
|
128
|
+
function mergeAttributes(parts) {
|
|
129
|
+
const result = {};
|
|
130
|
+
for (const part of parts) for (const [name, value] of Object.entries(part ?? {})) result[name] = name === "class" && result.class !== void 0 && value !== void 0 ? [result.class, value] : value;
|
|
131
|
+
return result;
|
|
132
|
+
}
|
|
118
133
|
/** Renders an object of attributes. */
|
|
119
134
|
function spread(attributes) {
|
|
120
135
|
let result = "";
|
|
@@ -139,14 +154,17 @@ const VOID_ELEMENTS = /* @__PURE__ */ new Set([
|
|
|
139
154
|
/**
|
|
140
155
|
* Renders the attributes of a form that posts to a server function, such as
|
|
141
156
|
* ` action="/_brumate/App_1abc%23save" method="post"`. `method` is the name of
|
|
142
|
-
* the method attribute to add, if the element has none.
|
|
157
|
+
* the method attribute to add, if the element has none. `build` is the ID
|
|
158
|
+
* of the build of the page, which the URL carries as `__build`, so the
|
|
159
|
+
* server can tell a post from before a deploy without scripts.
|
|
143
160
|
*/
|
|
144
|
-
function actionAttributes(prefix, name, id, method, result) {
|
|
161
|
+
function actionAttributes(prefix, name, id, method, result, build) {
|
|
145
162
|
const methodText = method ? ` ${method}="post"` : "";
|
|
146
|
-
|
|
147
|
-
return ` ${name}="${escapeAttribute(
|
|
163
|
+
const query = build === void 0 ? "" : `__build=${encodeURIComponent(build)}`;
|
|
164
|
+
if (result !== void 0) return ` ${name}="${escapeAttribute(`?__action=${encodeURIComponent(id)}${query ? `&${query}` : ""}`)}"${methodText} b-action="${escapeAttribute(id)}" b-result="${escapeAttribute(result)}"`;
|
|
165
|
+
return ` ${name}="${escapeAttribute(`${prefix}/${encodeURIComponent(id)}${query ? `?${query}` : ""}`)}"${methodText}`;
|
|
148
166
|
}
|
|
149
167
|
//#endregion
|
|
150
|
-
export {
|
|
168
|
+
export { textValue as _, attributeText as a, escape as c, isRaw as d, mergeAttributes as f, styleElement as g, spread as h, attribute as i, escapeAttribute as l, rawHTML as m, actionAttributes as n, classAttribute as o, raw as p, affix as r, classValue as s, VOID_ELEMENTS as t, insertValue as u, vars as v };
|
|
151
169
|
|
|
152
|
-
//# sourceMappingURL=html-
|
|
170
|
+
//# sourceMappingURL=html-bHZbkK-h.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"html-bHZbkK-h.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/**\n * A name that HTML reads as one attribute. A spread takes its names from\n * data, so a name with a space, a quote, `>`, `/` or `=` could write other\n * attributes or markup.\n */\n// oxlint-disable-next-line no-control-regex -- HTML reads no control character in a name.\nconst ATTRIBUTE_NAME = /^[^\\s\"'>/=\\x00-\\x1f\\x7f]+$/;\n\n/** Renders one attribute, with a leading space. A name that is not one attribute renders nothing. */\nexport function attribute(name: string, value: unknown): string {\n const text = attributeText(name, value);\n if (text === undefined || !ATTRIBUTE_NAME.test(name)) {\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/**\n * Merges the attributes of an element that has spreads, in their order: a\n * later value wins, except `class`, whose values all apply.\n */\nexport function mergeAttributes(parts: Record<string, unknown>[]): Record<string, unknown> {\n const result: Record<string, unknown> = {};\n for (const part of parts) {\n for (const [name, value] of Object.entries(part ?? {})) {\n result[name] =\n name === 'class' && result.class !== undefined && value !== undefined\n ? [result.class, value]\n : value;\n }\n }\n return result;\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. `build` is the ID\n * of the build of the page, which the URL carries as `__build`, so the\n * server can tell a post from before a deploy without scripts.\n */\nexport function actionAttributes(\n prefix: string,\n name: string,\n id: string,\n method?: string,\n result?: string,\n build?: string,\n): string {\n const methodText = method ? ` ${method}=\"post\"` : '';\n const query = build === undefined ? '' : `__build=${encodeURIComponent(build)}`;\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 const url = `?__action=${encodeURIComponent(id)}${query ? `&${query}` : ''}`;\n return ` ${name}=\"${escapeAttribute(url)}\"${methodText} b-action=\"${escapeAttribute(id)}\" b-result=\"${escapeAttribute(result)}\"`;\n }\n const url = `${prefix}/${encodeURIComponent(id)}${query ? `?${query}` : ''}`;\n return ` ${name}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AAO,YAA6C;CAClE,IAAI,SAAS;CACb,KAAK,MAAM,CAAC,MAAM,UAAU,OAAO,QAAQ,UAAU,GACnD,IAAI,SAAS,cAAc,CAAC,WAAW,KAAK,IAAI,GAC9C,UAAU,UAAU,MAAM,KAAK;CAGnC,OAAO;AACT;AAEA,MAAa,gCAA6B,IAAI,IAAI;CAChD;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;CACA;AACF,CAAC;;;;;;;;AASD,SAAgB,iBACd,QACA,MACA,IACA,QACA,QACA,OACQ;CACR,MAAM,aAAa,SAAS,IAAI,OAAO,WAAW;CAClD,MAAM,QAAQ,UAAU,KAAA,IAAY,KAAK,WAAW,mBAAmB,KAAK;CAC5E,IAAI,WAAW,KAAA,GAIb,OAAO,IAAI,KAAK,IAAI,gBAAgB,aADX,mBAAmB,EAAE,IAAI,QAAQ,IAAI,UAAU,IACjC,EAAE,GAAG,WAAW,aAAa,gBAAgB,EAAE,EAAE,cAAc,gBAAgB,MAAM,EAAE;CAGhI,OAAO,IAAI,KAAK,IAAI,gBAAgB,GADrB,OAAO,GAAG,mBAAmB,EAAE,IAAI,QAAQ,IAAI,UAAU,IACjC,EAAE,GAAG;AAC9C"}
|
|
@@ -28,7 +28,7 @@ declare function classAttribute(classes: string): string;
|
|
|
28
28
|
* rendered. `true` renders as an empty value.
|
|
29
29
|
*/
|
|
30
30
|
declare function attributeText(name: string, value: unknown): string | undefined;
|
|
31
|
-
/** Renders one attribute, with a leading space. */
|
|
31
|
+
/** Renders one attribute, with a leading space. A name that is not one attribute renders nothing. */
|
|
32
32
|
declare function attribute(name: string, value: unknown): string;
|
|
33
33
|
/**
|
|
34
34
|
* Returns the value of a style variable with text around it, such as `12px`
|
|
@@ -39,15 +39,22 @@ declare function affix(prefix: string, value: unknown, suffix: string): unknown;
|
|
|
39
39
|
declare function vars(variables: Record<string, unknown>, own: unknown): string;
|
|
40
40
|
/** Returns a `<style>` element for a component's stylesheet. */
|
|
41
41
|
declare function styleElement(id: string, css: string): string;
|
|
42
|
+
/**
|
|
43
|
+
* Merges the attributes of an element that has spreads, in their order: a
|
|
44
|
+
* later value wins, except `class`, whose values all apply.
|
|
45
|
+
*/
|
|
46
|
+
declare function mergeAttributes(parts: Record<string, unknown>[]): Record<string, unknown>;
|
|
42
47
|
/** Renders an object of attributes. */
|
|
43
48
|
declare function spread(attributes: Record<string, unknown>): string;
|
|
44
49
|
declare const VOID_ELEMENTS: Set<string>;
|
|
45
50
|
/**
|
|
46
51
|
* Renders the attributes of a form that posts to a server function, such as
|
|
47
52
|
* ` action="/_brumate/App_1abc%23save" method="post"`. `method` is the name of
|
|
48
|
-
* the method attribute to add, if the element has none.
|
|
53
|
+
* the method attribute to add, if the element has none. `build` is the ID
|
|
54
|
+
* of the build of the page, which the URL carries as `__build`, so the
|
|
55
|
+
* server can tell a post from before a deploy without scripts.
|
|
49
56
|
*/
|
|
50
|
-
declare function actionAttributes(prefix: string, name: string, id: string, method?: string, result?: string): string;
|
|
57
|
+
declare function actionAttributes(prefix: string, name: string, id: string, method?: string, result?: string, build?: string): string;
|
|
51
58
|
//#endregion
|
|
52
|
-
export {
|
|
53
|
-
//# sourceMappingURL=html-
|
|
59
|
+
export { styleElement as _, attribute as a, classValue as c, insertValue as d, isRaw as f, spread as g, rawHTML as h, affix as i, escape as l, raw as m, VOID_ELEMENTS as n, attributeText as o, mergeAttributes as p, actionAttributes as r, classAttribute as s, Raw as t, escapeAttribute as u, textValue as v, vars as y };
|
|
60
|
+
//# sourceMappingURL=html-y1q7-t7D.d.ts.map
|