@oddsquad/vite-plugin-lit 0.3.0 → 0.5.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/CHANGELOG.md +118 -0
- package/README.md +26 -11
- package/bin.mjs +16 -12
- package/dist/client/assets/{browser-agent-rpc-BXhoSh1z-BvWe4sTJ.js → browser-agent-rpc-BXhoSh1z-CRHFLjFo.js} +2 -2
- package/dist/client/assets/{browser-agent-rpc-BXhoSh1z-BvWe4sTJ.js.map → browser-agent-rpc-BXhoSh1z-CRHFLjFo.js.map} +1 -1
- package/dist/client/assets/flow-DK8vmxvN.js +745 -0
- package/dist/client/assets/flow-DK8vmxvN.js.map +1 -0
- package/dist/client/assets/{index-CFrVgNfS.js → index-Gn4Hk_9s.js} +2749 -793
- package/dist/client/assets/index-Gn4Hk_9s.js.map +1 -0
- package/dist/client/index.html +11 -1
- package/lib/devframe/definition.d.ts +7 -0
- package/lib/devframe/definition.d.ts.map +1 -1
- package/lib/devframe/definition.js +56 -11
- package/lib/devframe/definition.js.map +1 -1
- package/lib/devframe/launch-editor.d.ts +20 -0
- package/lib/devframe/launch-editor.d.ts.map +1 -0
- package/lib/devframe/launch-editor.js +40 -0
- package/lib/devframe/launch-editor.js.map +1 -0
- package/lib/devframe/protocol.d.ts +31 -4
- package/lib/devframe/protocol.d.ts.map +1 -1
- package/lib/devframe/protocol.js +22 -3
- package/lib/devframe/protocol.js.map +1 -1
- package/lib/devframe/rpc-source.d.ts +44 -0
- package/lib/devframe/rpc-source.d.ts.map +1 -0
- package/lib/devframe/rpc-source.js +150 -0
- package/lib/devframe/rpc-source.js.map +1 -0
- package/lib/devframe/source.d.ts +12 -0
- package/lib/devframe/source.d.ts.map +1 -1
- package/lib/devframe/source.js +12 -0
- package/lib/devframe/source.js.map +1 -1
- package/lib/devframe/vite.d.ts +2 -0
- package/lib/devframe/vite.d.ts.map +1 -1
- package/lib/devframe/vite.js +3 -8
- package/lib/devframe/vite.js.map +1 -1
- package/lib/options.d.ts +136 -0
- package/lib/options.d.ts.map +1 -0
- package/lib/options.js +175 -0
- package/lib/options.js.map +1 -0
- package/lib/override-baselines.d.ts +17 -0
- package/lib/override-baselines.d.ts.map +1 -0
- package/lib/override-baselines.js +25 -0
- package/lib/override-baselines.js.map +1 -0
- package/lib/plugin.d.ts +6 -148
- package/lib/plugin.d.ts.map +1 -1
- package/lib/plugin.js +22 -477
- package/lib/plugin.js.map +1 -1
- package/lib/plugins/css-literals.d.ts +15 -0
- package/lib/plugins/css-literals.d.ts.map +1 -0
- package/lib/plugins/css-literals.js +154 -0
- package/lib/plugins/css-literals.js.map +1 -0
- package/lib/plugins/css-queries.d.ts +20 -0
- package/lib/plugins/css-queries.d.ts.map +1 -0
- package/lib/plugins/css-queries.js +139 -0
- package/lib/plugins/css-queries.js.map +1 -0
- package/lib/plugins/open-in-editor.d.ts +16 -0
- package/lib/plugins/open-in-editor.d.ts.map +1 -0
- package/lib/plugins/open-in-editor.js +96 -0
- package/lib/plugins/open-in-editor.js.map +1 -0
- package/lib/plugins/shared.d.ts +13 -0
- package/lib/plugins/shared.d.ts.map +1 -0
- package/lib/plugins/shared.js +23 -0
- package/lib/plugins/shared.js.map +1 -0
- package/lib/plugins/timeline-virtual.d.ts +19 -0
- package/lib/plugins/timeline-virtual.d.ts.map +1 -0
- package/lib/plugins/timeline-virtual.js +53 -0
- package/lib/plugins/timeline-virtual.js.map +1 -0
- package/lib/runtime/css.d.ts.map +1 -1
- package/lib/runtime/css.js +9 -2
- package/lib/runtime/css.js.map +1 -1
- package/lib/runtime/indicator.js.map +1 -1
- package/lib/runtime/inspector/install.js +65 -13
- package/lib/runtime/inspector/install.js.map +1 -1
- package/lib/runtime/inspector/serialize.d.ts.map +1 -1
- package/lib/runtime/inspector/serialize.js +20 -0
- package/lib/runtime/inspector/serialize.js.map +1 -1
- package/lib/runtime/overrides.d.ts +4 -10
- package/lib/runtime/overrides.d.ts.map +1 -1
- package/lib/runtime/overrides.js +5 -3
- package/lib/runtime/overrides.js.map +1 -1
- package/lib/runtime/page-channel.d.ts +52 -0
- package/lib/runtime/page-channel.d.ts.map +1 -0
- package/lib/runtime/page-channel.js +67 -0
- package/lib/runtime/page-channel.js.map +1 -0
- package/lib/runtime/patch.d.ts.map +1 -1
- package/lib/runtime/patch.js +2 -1
- package/lib/runtime/patch.js.map +1 -1
- package/lib/runtime/rpc-transport.d.ts +46 -0
- package/lib/runtime/rpc-transport.d.ts.map +1 -0
- package/lib/runtime/rpc-transport.js +82 -0
- package/lib/runtime/rpc-transport.js.map +1 -0
- package/lib/runtime/source-overlay/overlay-element.d.ts.map +1 -1
- package/lib/runtime/source-overlay/overlay-element.js +30 -7
- package/lib/runtime/source-overlay/overlay-element.js.map +1 -1
- package/lib/runtime/timeline/install.js +25 -9
- package/lib/runtime/timeline/install.js.map +1 -1
- package/lib/runtime/timeline/public-api.d.ts +2 -2
- package/lib/runtime/timeline/public-api.d.ts.map +1 -1
- package/lib/runtime/timeline/public-api.js +13 -5
- package/lib/runtime/timeline/public-api.js.map +1 -1
- package/lib/runtime/timeline/render.d.ts +15 -6
- package/lib/runtime/timeline/render.d.ts.map +1 -1
- package/lib/runtime/timeline/render.js +150 -11
- package/lib/runtime/timeline/render.js.map +1 -1
- package/lib/runtime/timeline/transport.d.ts +6 -9
- package/lib/runtime/timeline/transport.d.ts.map +1 -1
- package/lib/runtime/timeline/transport.js.map +1 -1
- package/lib/timeline/filter.d.ts +38 -0
- package/lib/timeline/filter.d.ts.map +1 -0
- package/lib/timeline/filter.js +44 -0
- package/lib/timeline/filter.js.map +1 -0
- package/lib/timeline/tracks.d.ts +113 -0
- package/lib/timeline/tracks.d.ts.map +1 -0
- package/lib/timeline/tracks.js +168 -0
- package/lib/timeline/tracks.js.map +1 -0
- package/package.json +9 -1
- package/types/timeline.d.ts +50 -1
- package/types/timeline.d.ts.map +1 -1
- package/types/timeline.js +4 -0
- package/types/timeline.js.map +1 -1
- package/dist/client/assets/index-CFrVgNfS.js.map +0 -1
- package/lib/timeline-plugin.d.ts +0 -72
- package/lib/timeline-plugin.d.ts.map +0 -1
- package/lib/timeline-plugin.js +0 -359
- package/lib/timeline-plugin.js.map +0 -1
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import {existsSync} from 'node:fs';
|
|
7
|
+
import {resolve as resolvePath, sep} from 'node:path';
|
|
8
|
+
import {toLaunchEditor} from '../devframe/launch-editor.js';
|
|
9
|
+
import {isTrustedRequest} from '../http.js';
|
|
10
|
+
export const OPEN_IN_EDITOR_PATH = '/__lit-open-in-editor';
|
|
11
|
+
export const createOpenInEditorMiddleware = (allowedRoots) => {
|
|
12
|
+
// First entry is the primary root: relative `file` params resolve against
|
|
13
|
+
// it. Every entry grants open access to files beneath it.
|
|
14
|
+
const roots = allowedRoots.map((r) => resolvePath(r));
|
|
15
|
+
return (req, res, next) => {
|
|
16
|
+
if (req.url === undefined) {
|
|
17
|
+
next();
|
|
18
|
+
return;
|
|
19
|
+
}
|
|
20
|
+
if (req.method !== undefined && req.method !== 'GET') {
|
|
21
|
+
res.statusCode = 405;
|
|
22
|
+
res.end('method not allowed');
|
|
23
|
+
return;
|
|
24
|
+
}
|
|
25
|
+
if (!isTrustedRequest(req.headers ?? {})) {
|
|
26
|
+
res.statusCode = 403;
|
|
27
|
+
res.end('forbidden');
|
|
28
|
+
return;
|
|
29
|
+
}
|
|
30
|
+
const query = req.url.includes('?')
|
|
31
|
+
? req.url.slice(req.url.indexOf('?') + 1)
|
|
32
|
+
: '';
|
|
33
|
+
const params = new URLSearchParams(query);
|
|
34
|
+
const file = params.get('file');
|
|
35
|
+
if (file === null) {
|
|
36
|
+
res.statusCode = 400;
|
|
37
|
+
res.end('missing file parameter');
|
|
38
|
+
return;
|
|
39
|
+
}
|
|
40
|
+
// Confine the open to the allowed roots: resolve the requested path and
|
|
41
|
+
// reject anything that escapes all of them (path traversal, absolute
|
|
42
|
+
// paths to arbitrary files). `launch-editor` spawns the user's editor on
|
|
43
|
+
// this path, so an unvalidated `file` is a local-file-open /
|
|
44
|
+
// arg-injection vector.
|
|
45
|
+
const resolved = resolvePath(roots[0] ?? process.cwd(), file);
|
|
46
|
+
const allowed = roots.some(
|
|
47
|
+
(root) => resolved === root || resolved.startsWith(root + sep)
|
|
48
|
+
);
|
|
49
|
+
if (!allowed) {
|
|
50
|
+
res.statusCode = 403;
|
|
51
|
+
res.end('file outside allowed roots');
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
if (!existsSync(resolved)) {
|
|
55
|
+
res.statusCode = 404;
|
|
56
|
+
res.end('file not found');
|
|
57
|
+
return;
|
|
58
|
+
}
|
|
59
|
+
// Coerce to integers so a crafted `line`/`column` can't smuggle extra
|
|
60
|
+
// shell-visible content through the `file:line:column` ref.
|
|
61
|
+
const line = String(
|
|
62
|
+
Math.max(1, Number.parseInt(params.get('line') ?? '1', 10) || 1)
|
|
63
|
+
);
|
|
64
|
+
const column = String(
|
|
65
|
+
Math.max(1, Number.parseInt(params.get('column') ?? '1', 10) || 1)
|
|
66
|
+
);
|
|
67
|
+
// The overlay names the editor it is using (the panel's override, else the
|
|
68
|
+
// configured one). Only keys `toLaunchEditor` knows become a command;
|
|
69
|
+
// anything else, or nothing, leaves `launch-editor` to auto-detect.
|
|
70
|
+
const editor = toLaunchEditor(params.get('editor') ?? undefined);
|
|
71
|
+
const fileRef = `${resolved}:${line}:${column}`;
|
|
72
|
+
import('launch-editor')
|
|
73
|
+
.then((mod) => {
|
|
74
|
+
const launch = mod.default ?? mod;
|
|
75
|
+
// `launch-editor` invokes the callback only on failure — synchronously
|
|
76
|
+
// when it can't guess an editor, later if the spawn errors. Reply `ok`
|
|
77
|
+
// right after launching; the guard keeps a sync failure's 500 first
|
|
78
|
+
// and drops a late async failure (the response is long gone).
|
|
79
|
+
let finished = false;
|
|
80
|
+
const finish = (statusCode, msg) => {
|
|
81
|
+
if (finished) return;
|
|
82
|
+
finished = true;
|
|
83
|
+
res.statusCode = statusCode;
|
|
84
|
+
res.end(msg);
|
|
85
|
+
};
|
|
86
|
+
launch(fileRef, editor, (_fileName, errorMessage) => {
|
|
87
|
+
if (errorMessage !== null) {
|
|
88
|
+
finish(500, errorMessage);
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
finish(200, 'ok');
|
|
92
|
+
})
|
|
93
|
+
.catch(next);
|
|
94
|
+
};
|
|
95
|
+
};
|
|
96
|
+
//# sourceMappingURL=open-in-editor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"open-in-editor.js","sourceRoot":"","sources":["../../src/lib/plugins/open-in-editor.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AACnC,OAAO,EAAC,OAAO,IAAI,WAAW,EAAE,GAAG,EAAC,MAAM,WAAW,CAAC;AACtD,OAAO,EAAC,cAAc,EAAC,MAAM,8BAA8B,CAAC;AAC5D,OAAO,EAAC,gBAAgB,EAAoB,MAAM,YAAY,CAAC;AAE/D,MAAM,CAAC,MAAM,mBAAmB,GAAG,uBAAuB,CAAC;AAE3D,MAAM,CAAC,MAAM,4BAA4B,GAAG,CAC1C,YAA+B,EAC/B,EAAE;IACF,0EAA0E;IAC1E,0DAA0D;IAC1D,MAAM,KAAK,GAAG,YAAY,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC;IACtD,OAAO,CACL,GAA4D,EAC5D,GAAqD,EACrD,IAA6B,EAC7B,EAAE;QACF,IAAI,GAAG,CAAC,GAAG,KAAK,SAAS,EAAE,CAAC;YAC1B,IAAI,EAAE,CAAC;YACP,OAAO;QACT,CAAC;QACD,IAAI,GAAG,CAAC,MAAM,KAAK,SAAS,IAAI,G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BACjD,IAAI,QAAQ;oBAAE,OAAO;gBACrB,QAAQ,GAAG,IAAI,CAAC;gBAChB,GAAG,CAAC,UAAU,GAAG,UAAU,CAAC;gBAC5B,GAAG,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACf,CAAC,CAAC;YACF,MAAM,CACJ,OAAO,EACP,MAAM,EACN,CAAC,SAAiB,EAAE,YAA2B,EAAE,EAAE;gBACjD,IAAI,YAAY,KAAK,IAAI,EAAE,CAAC;oBAC1B,MAAM,CAAC,GAAG,EAAE,YAAY,CAAC,CAAC;gBAC5B,CAAC;YACH,CAAC,CACF,CAAC;YACF,MAAM,CAAC,GAAG,EAAE,IAAI,CAAC,CAAC;QACpB,CAAC,CACF;aACA,KAAK,CAAC,IAAI,CAAC,CAAC;IACjB,CAAC,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {existsSync} from 'node:fs';\nimport {resolve as resolvePath, sep} from 'node:path';\nimport {toLaunchEditor} from '../devframe/launch-editor.js';\nimport {isTrustedRequest, type TrustHeaders} from '../http.js';\n\nexport const OPEN_IN_EDITOR_PATH = '/__lit-open-in-editor';\n\nexport const createOpenInEditorMiddleware = (\n allowedRoots: readonly string[]\n) => {\n // First entry is the primary root: relative `file` params resolve against\n // it. Every entry grants open access to files beneath it.\n const roots = allowedRoots.map((r) => resolvePath(r));\n return (\n req: {url?: string; method?: string; headers?: TrustHeaders},\n res: {statusCode: number; end: (msg: string) => void},\n next: (err?: unknown) => void\n ) => {\n if (req.url === undefined) {\n next();\n return;\n }\n if (req.method !== undefined && req.method !== 'GET') {\n res.statusCode = 405;\n res.end('method not allowed');\n return;\n }\n if (!isTrustedRequest(req.headers ?? {})) {\n res.statusCode = 403;\n res.end('forbidden');\n return;\n }\n const query = req.url.includes('?')\n ? req.url.slice(req.url.indexOf('?') + 1)\n : '';\n const params = new URLSearchParams(query);\n const file = params.get('file');\n if (file === null) {\n res.statusCode = 400;\n res.end('missing file parameter');\n return;\n }\n // Confine the open to the allowed roots: resolve the requested path and\n // reject anything that escapes all of them (path traversal, absolute\n // paths to arbitrary files). `launch-editor` spawns the user's editor on\n // this path, so an unvalidated `file` is a local-file-open /\n // arg-injection vector.\n const resolved = resolvePath(roots[0] ?? process.cwd(), file);\n const allowed = roots.some(\n (root) => resolved === root || resolved.startsWith(root + sep)\n );\n if (!allowed) {\n res.statusCode = 403;\n res.end('file outside allowed roots');\n return;\n }\n if (!existsSync(resolved)) {\n res.statusCode = 404;\n res.end('file not found');\n return;\n }\n // Coerce to integers so a crafted `line`/`column` can't smuggle extra\n // shell-visible content through the `file:line:column` ref.\n const line = String(\n Math.max(1, Number.parseInt(params.get('line') ?? '1', 10) || 1)\n );\n const column = String(\n Math.max(1, Number.parseInt(params.get('column') ?? '1', 10) || 1)\n );\n // The overlay names the editor it is using (the panel's override, else the\n // configured one). Only keys `toLaunchEditor` knows become a command;\n // anything else, or nothing, leaves `launch-editor` to auto-detect.\n const editor = toLaunchEditor(params.get('editor') ?? undefined);\n const fileRef = `${resolved}:${line}:${column}`;\n import('launch-editor')\n .then(\n (mod: {\n default?: (\n file: string,\n editor: string | undefined,\n cb: (fileName: string, errorMessage: string | null) => void\n ) => void;\n }) => {\n const launch = (mod.default ?? mod) as (\n file: string,\n editor: string | undefined,\n cb: (fileName: string, errorMessage: string | null) => void\n ) => void;\n // `launch-editor` invokes the callback only on failure — synchronously\n // when it can't guess an editor, later if the spawn errors. Reply `ok`\n // right after launching; the guard keeps a sync failure's 500 first\n // and drops a late async failure (the response is long gone).\n let finished = false;\n const finish = (statusCode: number, msg: string) => {\n if (finished) return;\n finished = true;\n res.statusCode = statusCode;\n res.end(msg);\n };\n launch(\n fileRef,\n editor,\n (_fileName: string, errorMessage: string | null) => {\n if (errorMessage !== null) {\n finish(500, errorMessage);\n }\n }\n );\n finish(200, 'ok');\n }\n )\n .catch(next);\n };\n};\n"]}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Resolves a runtime module to an absolute fs path (served via `/@fs/`), so
|
|
8
|
+
* the plugin works from any served root. Falls back from the built `.js` to
|
|
9
|
+
* the `.ts` source when running un-built (e.g. under vitest).
|
|
10
|
+
*/
|
|
11
|
+
export declare const resolveRuntimeModule: (name: string) => string;
|
|
12
|
+
export declare const JS_FILE_RE: RegExp;
|
|
13
|
+
//# sourceMappingURL=shared.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.d.ts","sourceRoot":"","sources":["../../src/lib/plugins/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAKH;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,SAAU,MAAM,KAAG,MAQnD,CAAC;AAEF,eAAO,MAAM,UAAU,QAAoB,CAAC"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import {existsSync} from 'node:fs';
|
|
7
|
+
import {fileURLToPath} from 'node:url';
|
|
8
|
+
/**
|
|
9
|
+
* Resolves a runtime module to an absolute fs path (served via `/@fs/`), so
|
|
10
|
+
* the plugin works from any served root. Falls back from the built `.js` to
|
|
11
|
+
* the `.ts` source when running un-built (e.g. under vitest).
|
|
12
|
+
*/
|
|
13
|
+
export const resolveRuntimeModule = (name) => {
|
|
14
|
+
for (const ext of ['js', 'ts']) {
|
|
15
|
+
const url = new URL(`../runtime/${name}.${ext}`, import.meta.url);
|
|
16
|
+
if (existsSync(url)) {
|
|
17
|
+
return fileURLToPath(url).replace(/\\/g, '/');
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
throw new Error(`[lit-plugin] runtime module not found: ${name}`);
|
|
21
|
+
};
|
|
22
|
+
export const JS_FILE_RE = /\.[cm]?[jt]sx?$/;
|
|
23
|
+
//# sourceMappingURL=shared.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"shared.js","sourceRoot":"","sources":["../../src/lib/plugins/shared.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAAC,UAAU,EAAC,MAAM,SAAS,CAAC;AACnC,OAAO,EAAC,aAAa,EAAC,MAAM,UAAU,CAAC;AAEvC;;;;GAIG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,CAAC,IAAY,EAAU,EAAE;IAC3D,KAAK,MAAM,GAAG,IAAI,CAAC,IAAI,EAAE,IAAI,CAAU,EAAE,CAAC;QACxC,MAAM,GAAG,GAAG,IAAI,GAAG,CAAC,cAAc,IAAI,IAAI,GAAG,EAAE,EAAE,OAAO,IAAI,CAAC,GAAG,CAAC,CAAC;QAClE,IAAI,UAAU,CAAC,GAAG,CAAC,EAAE,CAAC;YACpB,OAAO,aAAa,CAAC,GAAG,CAAC,CAAC,OAAO,CAAC,KAAK,EAAE,GAAG,CAAC,CAAC;QAChD,CAAC;IACH,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,0CAA0C,IAAI,EAAE,CAAC,CAAC;AACpE,CAAC,CAAC;AAEF,MAAM,CAAC,MAAM,UAAU,GAAG,iBAAiB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport {existsSync} from 'node:fs';\nimport {fileURLToPath} from 'node:url';\n\n/**\n * Resolves a runtime module to an absolute fs path (served via `/@fs/`), so\n * the plugin works from any served root. Falls back from the built `.js` to\n * the `.ts` source when running un-built (e.g. under vitest).\n */\nexport const resolveRuntimeModule = (name: string): string => {\n for (const ext of ['js', 'ts'] as const) {\n const url = new URL(`../runtime/${name}.${ext}`, import.meta.url);\n if (existsSync(url)) {\n return fileURLToPath(url).replace(/\\\\/g, '/');\n }\n }\n throw new Error(`[lit-plugin] runtime module not found: ${name}`);\n};\n\nexport const JS_FILE_RE = /\\.[cm]?[jt]sx?$/;\n"]}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import type { Plugin } from 'vite';
|
|
7
|
+
/**
|
|
8
|
+
* The public timeline API virtual module, served in dev and build alike:
|
|
9
|
+
* app code importing it must keep building under `vite build`, where the HMR
|
|
10
|
+
* plugin doesn't apply. While these hooks lived on that serve-only plugin,
|
|
11
|
+
* nothing claimed the specifier during a build and the bundler failed to
|
|
12
|
+
* resolve it.
|
|
13
|
+
*
|
|
14
|
+
* `getTimeline` is a getter, not a value: `litPlugin()` re-resolves its
|
|
15
|
+
* options against the loaded env in a `config` hook, which runs after the
|
|
16
|
+
* plugin array is built.
|
|
17
|
+
*/
|
|
18
|
+
export declare const litTimelineVirtual: (getTimeline?: () => boolean) => Plugin;
|
|
19
|
+
//# sourceMappingURL=timeline-virtual.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline-virtual.d.ts","sourceRoot":"","sources":["../../src/lib/plugins/timeline-virtual.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,MAAM,EAAC,MAAM,MAAM,CAAC;AASjC;;;;;;;;;;GAUG;AACH,eAAO,MAAM,kBAAkB,iBAChB,MAAM,OAAO,KACzB,MA6BF,CAAC"}
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import {resolveRuntimeModule} from './shared.js';
|
|
7
|
+
const TIMELINE_VIRTUAL_ID = 'virtual:lit-plugin/timeline';
|
|
8
|
+
const TIMELINE_RESOLVED_ID = '\0virtual:lit-plugin/timeline';
|
|
9
|
+
const TIMELINE_STUB =
|
|
10
|
+
'export const addTimelineEvent = () => {};\n' +
|
|
11
|
+
'export const addTimelineLayer = () => {};\n';
|
|
12
|
+
/**
|
|
13
|
+
* The public timeline API virtual module, served in dev and build alike:
|
|
14
|
+
* app code importing it must keep building under `vite build`, where the HMR
|
|
15
|
+
* plugin doesn't apply. While these hooks lived on that serve-only plugin,
|
|
16
|
+
* nothing claimed the specifier during a build and the bundler failed to
|
|
17
|
+
* resolve it.
|
|
18
|
+
*
|
|
19
|
+
* `getTimeline` is a getter, not a value: `litPlugin()` re-resolves its
|
|
20
|
+
* options against the loaded env in a `config` hook, which runs after the
|
|
21
|
+
* plugin array is built.
|
|
22
|
+
*/
|
|
23
|
+
export const litTimelineVirtual = (getTimeline = () => false) => {
|
|
24
|
+
let isBuild = false;
|
|
25
|
+
return {
|
|
26
|
+
name: 'lit-timeline-virtual',
|
|
27
|
+
configResolved(config) {
|
|
28
|
+
isBuild = config.command === 'build';
|
|
29
|
+
},
|
|
30
|
+
resolveId(id) {
|
|
31
|
+
return id === TIMELINE_VIRTUAL_ID ? TIMELINE_RESOLVED_ID : null;
|
|
32
|
+
},
|
|
33
|
+
load(id) {
|
|
34
|
+
if (id !== TIMELINE_RESOLVED_ID) {
|
|
35
|
+
return null;
|
|
36
|
+
}
|
|
37
|
+
// Under build the stub is unconditional, even with `timeline: true`.
|
|
38
|
+
// The runtime delivers only over `import.meta.hot`, so in a production
|
|
39
|
+
// bundle it is a queue that never drains; the stub keeps the transport
|
|
40
|
+
// out of the bundle and makes the documented "no-op in production"
|
|
41
|
+
// behavior true.
|
|
42
|
+
if (isBuild || !getTimeline()) {
|
|
43
|
+
return {code: TIMELINE_STUB, moduleType: 'js'};
|
|
44
|
+
}
|
|
45
|
+
const apiPath = resolveRuntimeModule('timeline/public-api');
|
|
46
|
+
return {
|
|
47
|
+
code: `export * from ${JSON.stringify(apiPath)};\n`,
|
|
48
|
+
moduleType: 'js',
|
|
49
|
+
};
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
//# sourceMappingURL=timeline-virtual.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"timeline-virtual.js","sourceRoot":"","sources":["../../src/lib/plugins/timeline-virtual.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAC,oBAAoB,EAAC,MAAM,aAAa,CAAC;AAEjD,MAAM,mBAAmB,GAAG,6BAA6B,CAAC;AAC1D,MAAM,oBAAoB,GAAG,+BAA+B,CAAC;AAC7D,MAAM,aAAa,GACjB,6CAA6C;IAC7C,6CAA6C,CAAC;AAEhD;;;;;;;;;;GAUG;AACH,MAAM,CAAC,MAAM,kBAAkB,GAAG,CAChC,WAAW,GAAkB,GAAG,EAAE,CAAC,KAAK,EAChC,EAAE;IACV,IAAI,OAAO,GAAG,KAAK,CAAC;IACpB,OAAO;QACL,IAAI,EAAE,sBAAsB;QAC5B,cAAc,CAAC,MAAM;YACnB,OAAO,GAAG,MAAM,CAAC,OAAO,KAAK,OAAO,CAAC;QACvC,CAAC;QACD,SAAS,CAAC,EAAE;YACV,OAAO,EAAE,KAAK,mBAAmB,CAAC,CAAC,CAAC,oBAAoB,CAAC,CAAC,CAAC,IAAI,CAAC;QAClE,CAAC;QACD,IAAI,CAAC,EAAE;YACL,IAAI,EAAE,KAAK,oBAAoB,EAAE,CAAC;gBAChC,OAAO,IAAI,CAAC;YACd,CAAC;YACD,qEAAqE;YACrE,uEAAuE;YACvE,uEAAuE;YACvE,mEAAmE;YACnE,iBAAiB;YACjB,IAAI,OAAO,IAAI,CAAC,WAAW,EAAE,EAAE,CAAC;gBAC9B,OAAO,EAAC,IAAI,EAAE,aAAa,EAAE,UAAU,EAAE,IAAI,EAAC,CAAC;YACjD,CAAC;YACD,MAAM,OAAO,GAAG,oBAAoB,CAAC,qBAAqB,CAAC,CAAC;YAC5D,OAAO;gBACL,IAAI,EAAE,iBAAiB,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,KAAK;gBACnD,UAAU,EAAE,IAAI;aACjB,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport type {Plugin} from 'vite';\nimport {resolveRuntimeModule} from './shared.js';\n\nconst TIMELINE_VIRTUAL_ID = 'virtual:lit-plugin/timeline';\nconst TIMELINE_RESOLVED_ID = '\\0virtual:lit-plugin/timeline';\nconst TIMELINE_STUB =\n 'export const addTimelineEvent = () => {};\\n' +\n 'export const addTimelineLayer = () => {};\\n';\n\n/**\n * The public timeline API virtual module, served in dev and build alike:\n * app code importing it must keep building under `vite build`, where the HMR\n * plugin doesn't apply. While these hooks lived on that serve-only plugin,\n * nothing claimed the specifier during a build and the bundler failed to\n * resolve it.\n *\n * `getTimeline` is a getter, not a value: `litPlugin()` re-resolves its\n * options against the loaded env in a `config` hook, which runs after the\n * plugin array is built.\n */\nexport const litTimelineVirtual = (\n getTimeline: () => boolean = () => false\n): Plugin => {\n let isBuild = false;\n return {\n name: 'lit-timeline-virtual',\n configResolved(config) {\n isBuild = config.command === 'build';\n },\n resolveId(id) {\n return id === TIMELINE_VIRTUAL_ID ? TIMELINE_RESOLVED_ID : null;\n },\n load(id) {\n if (id !== TIMELINE_RESOLVED_ID) {\n return null;\n }\n // Under build the stub is unconditional, even with `timeline: true`.\n // The runtime delivers only over `import.meta.hot`, so in a production\n // bundle it is a queue that never drains; the stub keeps the transport\n // out of the bundle and makes the documented \"no-op in production\"\n // behavior true.\n if (isBuild || !getTimeline()) {\n return {code: TIMELINE_STUB, moduleType: 'js'};\n }\n const apiPath = resolveRuntimeModule('timeline/public-api');\n return {\n code: `export * from ${JSON.stringify(apiPath)};\\n`,\n moduleType: 'js',\n };\n },\n };\n};\n"]}
|
package/lib/runtime/css.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/lib/runtime/css.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4BH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,QAAS,MAAM,KAAG,MAE1C,CAAC;AAqBF;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;;;OASG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;CACjE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/lib/runtime/css.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA4BH;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,YAAY,QAAS,MAAM,KAAG,MAE1C,CAAC;AAqBF;;;GAGG;AACH,MAAM,WAAW,QAAQ;IACvB;;;;;;;;;OASG;IACH,KAAK,EAAE,aAAa,CAAC;IACrB;;;;;;;;;;;;OAYG;IACH,WAAW,EAAE,CAAC,GAAG,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG,SAAS,KAAK,IAAI,CAAC;CACjE;AAED;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,eAAO,MAAM,QAAQ,QAAS,MAAM,KAAG,QAkCtC,CAAC"}
|
package/lib/runtime/css.js
CHANGED
|
@@ -97,13 +97,20 @@ export const urlSheet = (url) => {
|
|
|
97
97
|
const update = (next) => {
|
|
98
98
|
const token = ++latest;
|
|
99
99
|
return fetch(devDirect(next))
|
|
100
|
-
.then((r) =>
|
|
100
|
+
.then((r) => {
|
|
101
|
+
// A 404 still has a body (Vite's fallback page); don't adopt it as css.
|
|
102
|
+
if (!r.ok) throw new Error(`HTTP ${r.status}`);
|
|
103
|
+
return r.text();
|
|
104
|
+
})
|
|
101
105
|
.then((css) => {
|
|
102
106
|
if (token === latest) {
|
|
103
107
|
sheet.replaceSync(css);
|
|
104
108
|
}
|
|
105
109
|
})
|
|
106
|
-
.catch(() => {
|
|
110
|
+
.catch((err) => {
|
|
111
|
+
// Keep the last good sheet; just say why this update didn't land.
|
|
112
|
+
console.warn(`[lit-plugin] urlSheet: failed to load ${next}:`, err);
|
|
113
|
+
});
|
|
107
114
|
};
|
|
108
115
|
void update(url);
|
|
109
116
|
return {
|
package/lib/runtime/css.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.js","sourceRoot":"","sources":["../../src/lib/runtime/css.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;;;;;;;GAaG;AAEH;;;;;;;GAOG;AACH,MAAM,KAAK,GAAG,GAAY,EAAE,CACzB,OAAO,IAAgC,CAAC,GAAG,EAAE,GAAG,KAAK,IAAI,CAAC;AAE7D;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,CAAC,MAAM,YAAY,GAAG,CAAC,GAAW,EAAU,EAAE;IAClD,OAAO,KAAK,EAAE,CAAC,CAAC,CAAC,GAAG,GAAG,MAAM,IAAI,CAAC,GAAG,EAAE,EAAE,CAAC,CAAC,CAAC,GAAG,CAAC;AAClD,CAAC,CAAC;AAEF;;;;;;;;;;;GAWG;AACH,MAAM,SAAS,GAAG,CAAC,GAAW,EAAU,EAAE;IACxC,IAAI,CAAC,KAAK,EAAE,EAAE,CAAC;QACb,OAAO,GAAG,CAAC;IACb,CAAC;IACD,OAAO,GAAG,GAAG,GAAG,GAAG,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,GAAG,QAAQ,CAAC;A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AC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/**\n * Browser helpers for referencing CSS files from shadow roots via Vite's\n * `?url` imports.\n *\n * A `?url` import yields a real stylesheet URL — the dev server serves the\n * file as CSS, and `vite build` emits it as a hashed `.css` asset. That\n * makes it the right base for `<link>` hrefs and `@import url()`s inside\n * shadow roots. The one gap is dev HMR: the imported URL string is identical\n * across module re-executions, so the browser would keep the stale\n * stylesheet. These helpers close that gap.\n *\n * This module is dependency-free and must stay safe to load in any\n * environment.\n */\n\n/**\n * Vite's dev flag. Accessed as a direct member expression (`import.meta.env.DEV`)\n * so the bundler can statically replace it per key. Aliasing the whole object\n * (`const env = import.meta.env`) instead defeats that replacement and makes\n * Vite inline the ENTIRE serialized `import.meta.env` — every env var — into the\n * consumer bundle. Optional chaining keeps this safe where `import.meta.env` is\n * absent (non-Vite runtimes).\n */\nconst isDev = (): boolean =>\n (import.meta as {env?: {DEV?: boolean}}).env?.DEV === true;\n\n/**\n * Appends a cache-busting query to a `?url`-imported CSS file URL in dev.\n *\n * Call this at *module scope* (not in `render()`, where every render would\n * refetch): each HMR re-execution then yields a fresh href and the browser\n * refetches the changed stylesheet.\n *\n * In production builds the URL is a content-hashed asset, so the input is\n * returned unchanged.\n *\n * @example\n * ```ts\n * import cssUrl from './my-element.css?url';\n * import {devCacheBust} from '@oddsquad/vite-plugin-lit/css.js';\n *\n * const href = devCacheBust(cssUrl); // module scope\n * html`<link rel=\"stylesheet\" href=\"${href}\" />`;\n * ```\n */\nexport const devCacheBust = (url: string): string => {\n return isDev() ? `${url}?t=${Date.now()}` : url;\n};\n\n/**\n * In dev, turns a `?url`-imported CSS path into one that fetches the\n * *compiled CSS bytes* (`text/css`). Vite serves a `?url` CSS path as a JS\n * module (`__vite__updateStyle(…)`), so a plain `fetch().text()` returns\n * JavaScript; the `direct` query makes it return the stylesheet instead,\n * pipeline-processed the same way the build asset is. In production the URL\n * is already a real `.css` asset, so it's returned unchanged.\n *\n * Joined with `?` or `&` depending on whether the URL already carries a query\n * (a freshly started dev server yields a bare path; after an HMR cache-bust\n * it carries `?t=…`).\n */\nconst devDirect = (url: string): string => {\n if (!isDev()) {\n return url;\n }\n return `${url}${url.includes('?') ? '&' : '?'}direct`;\n};\n\n/**\n * A shared `CSSStyleSheet` backed by a `?url` CSS asset, plus the callback to\n * hot-swap it in place. Returned by {@link urlSheet}.\n */\nexport interface UrlSheet {\n /**\n * The constructed stylesheet. Adopt it from any number of components\n * (`static styles = [sheet]`); an edit to the source CSS re-fetches and\n * `replaceSync()`s it, updating every shadow root that adopted it without\n * re-rendering a component or reloading the page.\n *\n * It is empty until the first fetch resolves, so expect a brief flash of\n * unstyled content on initial load — the cost of keeping the CSS as a real\n * asset rather than inlining it into the JS bundle.\n */\n sheet: CSSStyleSheet;\n /**\n * Vite HMR accept callback for the `?url` dependency. Wire it up with the\n * *same literal specifier* you imported — Vite resolves accepted deps by\n * static analysis, so the string has to appear in your module:\n *\n * ```ts\n * import.meta.hot?.accept('./utils.css?url', onHotUpdate);\n * ```\n *\n * Typed to match Vite's accept callback (`ModuleNamespace | undefined`) so\n * it drops straight in; the new module's `default` export is the updated\n * `?url` string.\n */\n onHotUpdate: (mod: Record<string, unknown> | undefined) => void;\n}\n\n/**\n * Builds a {@link UrlSheet} from a `?url`-imported CSS asset: a single\n * constructed `CSSStyleSheet`, shareable across shadow roots via\n * `adoptedStyleSheets`, that hot-swaps in place on edits — no component\n * re-render, no full-page reload.\n *\n * `?url` keeps the stylesheet as a standalone, pipeline-processed `.css` file\n * in the build output (unlike `?inline`/`?raw`, which inline it into the JS\n * chunk). The file is read into the sheet at runtime via `fetch()`, with the\n * dev/build path difference handled internally.\n *\n * @example\n * ```ts\n * import {urlSheet} from '@oddsquad/vite-plugin-lit/css.js';\n * import sheetUrl from './utils.css?url';\n *\n * const {sheet, onHotUpdate} = urlSheet(sheetUrl);\n * export default sheet; // `static styles = [sheet]` in components\n *\n * import.meta.hot?.accept('./utils.css?url', onHotUpdate);\n * ```\n */\nexport const urlSheet = (url: string): UrlSheet => {\n const sheet = new CSSStyleSheet();\n // Guards against out-of-order fetch resolution: two rapid edits fire\n // overlapping fetches, and a slower earlier one must not land after (and\n // clobber) a newer one. Only the most recently issued request applies.\n let latest = 0;\n const update = (next: string): Promise<void> => {\n const token = ++latest;\n return fetch(devDirect(next))\n .then((r) => {\n // A 404 still has a body (Vite's fallback page); don't adopt it as css.\n if (!r.ok) throw new Error(`HTTP ${r.status}`);\n return r.text();\n })\n .then((css) => {\n if (token === latest) {\n sheet.replaceSync(css);\n }\n })\n .catch((err: unknown) => {\n // Keep the last good sheet; just say why this update didn't land.\n console.warn(`[lit-plugin] urlSheet: failed to load ${next}:`, err);\n });\n };\n void update(url);\n return {\n sheet,\n onHotUpdate: (mod) => {\n const next = mod?.['default'];\n if (typeof next === 'string') {\n void update(next);\n }\n },\n };\n};\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"indicator.js","sourceRoot":"","sources":["../../src/lib/runtime/indicator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;
|
|
1
|
+
{"version":3,"file":"indicator.js","sourceRoot":"","sources":["../../src/lib/runtime/indicator.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;GAIG;AAEH,OAAO,EAAC,aAAa,EAAC,MAAM,YAAY,CAAC;AACzC,OAAO,EAAC,UAAU,EAAC,MAAM,aAAa,CAAC;AACvC,OAAO,EAAC,iBAAiB,EAAC,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAC,iBAAiB,EAAC,MAAM,iBAAiB,CAAC;AAClD,OAAO,EAAC,YAAY,EAAC,MAAM,cA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,CAAC,CAAC,mBAAmB,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC;YAC3D,CAAC;YACD,IAAI,CAAC,CAAC,iBAAiB,KAAK,SAAS,EAAE,CAAC;gBACtC,IAAI,CAAC,SAAS,CAAC,CAAC,CAAC,iBAAiB,CAAC,CAAC;YACtC,CAAC;QACH,CAAC,CAAC,CAAC;QACH,8CAA8C;QAC9C,iBAAiB,CAAC,CAAC,MAAM,EAAE,EAAE;YAC3B,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,YAAY,EAAE,GAAG,MAAM,CAAC,GAAG,IAAI,CAAC,CAAC;YACxD,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,cAAc,EAAE,GAAG,MAAM,CAAC,KAAK,IAAI,CAAC,CAAC;YAC5D,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,eAAe,EAAE,GAAG,MAAM,CAAC,MAAM,IAAI,CAAC,CAAC;YAC9D,IAAI,CAAC,KAAK,CAAC,WAAW,CAAC,aAAa,EAAE,GAAG,MAAM,CAAC,IAAI,IAAI,CAAC,CAAC;QAC5D,CAAC,CAAC,CAAC;IACL,CAAC;CACF;AAED,cAAc,CAAC,MAAM,CAAC,4BAA4B,EAAE,oBAAoB,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/**\n * Custom element for the HMR update indicator.\n * Injected by the Vite plugin as an external module so that\n * `import.meta.hot` is available.\n */\n\nimport {FONT_MONO_VAR} from './fonts.js';\nimport {FLAME_ICON} from '../icons.js';\nimport {subscribeOverride} from './overrides.js';\nimport type {ViteHotLike} from './page-channel.js';\nimport {observeEdgeInsets} from './edge-panel.js';\nimport {injectTokens} from '../tokens.js';\n\n/** One entry of a Vite `vite:afterUpdate` payload. */\ninterface ViteUpdate {\n type?: string;\n path?: string;\n acceptedPath?: string;\n}\n\n/**\n * True when an HMR batch is purely a stylesheet swap — every update is either\n * a `css-update` or a `js-update` whose accepted module is a `.css` source\n * (the shared-sheet queries `?css-sheet`/`?raw`/`?url` all accept a `.css`\n * path). Such a batch restyles adopted sheets in place with no re-render.\n *\n * Heuristic: keyed on the accepted path ending in `.css`. Robust for this\n * plugin's own queries; a user hand-wiring `import.meta.hot.accept` on a raw\n * `.css` would also read as a style swap, which is the intended grouping. An\n * empty/missing payload can't be classified, so it counts as a re-render\n * rather than being silently dropped.\n */\nfunction isStyleSwap(data: unknown): boolean {\n const updates = (data as {updates?: ViteUpdate[]} | undefined)?.updates;\n if (!Array.isArray(updates) || updates.length === 0) return false;\n return updates.every((u) => {\n if (u.type === 'css-update') return true;\n if (u.type === 'js-update') {\n return (u.acceptedPath ?? u.path ?? '').split('?')[0].endsWith('.css');\n }\n return false;\n });\n}\n\nclass LitDevtoolsIndicator extends HTMLElement {\n #initialized = false;\n #count = 0;\n #container: HTMLElement;\n #countEl: HTMLElement | null = null;\n\n constructor() {\n super();\n const root = this.attachShadow({mode: 'closed'});\n // `--idle-op` is the at-rest opacity: 0 (invisible until a pulse) without a\n // count, .5 (count stays legible) with one. The count display and idle\n // opacity are both driven by the `.with-count` class so the panel can\n // toggle the count on/off live (see #setCount).\n root.innerHTML = `\n <style>\n @keyframes pulse{0%{opacity:var(--idle-op,0)}15%{opacity:1}80%{opacity:1}100%{opacity:var(--idle-op,0)}}\n :host{\n position:fixed;inset:0;display:grid;\n z-index:2147483647;pointer-events:none;\n /* Base padding plus the inset the Vite DevTools edge panel occupies\n on each edge (set from JS), so the indicator never sits on it. */\n padding:\n calc(var(--lit-devtools-hmr-indicator-padding,16px) + var(--edge-top,0px))\n calc(var(--lit-devtools-hmr-indicator-padding,16px) + var(--edge-right,0px))\n calc(var(--lit-devtools-hmr-indicator-padding,16px) + var(--edge-bottom,0px))\n calc(var(--lit-devtools-hmr-indicator-padding,16px) + var(--edge-left,0px))\n }\n #container{\n place-self:var(--lit-devtools-hmr-indicator-align,end end);\n display:flex;align-items:stretch;\n background:var(--lit-devtools-surface-elevated);color:var(--lit-devtools-text-strong);\n backdrop-filter:blur(8px);-webkit-backdrop-filter:blur(8px);\n border-radius:var(--lit-devtools-radius-md);\n font:12px/1 ${FONT_MONO_VAR};font-variant-numeric:tabular-nums;\n overflow:hidden;opacity:var(--idle-op,0)\n }\n #container.with-count{--idle-op:.5}\n #container.active{animation:pulse 2.5s ease-out forwards}\n #icon{display:flex;align-items:center;justify-content:center;padding:0 10px}\n #icon svg{width:16px;height:16px;display:block;fill:currentColor}\n #indicator{\n display:flex;align-items:center;gap:6px;\n padding:7px 12px;\n border-left:1px solid var(--lit-devtools-border-subtle)\n }\n .dot{width:8px;height:8px;border-radius:50%;background:var(--lit-devtools-success);flex-shrink:0}\n /* Style-only swaps (shared adopted stylesheet hot-swap, no re-render)\n pulse in the calmer info color and don't bump the count. */\n #container.style-swap .dot{background:var(--lit-devtools-info)}\n .count{display:none}\n #container.with-count .count{display:inline}\n </style>\n <div id=\"container\"><span id=\"icon\">${FLAME_ICON}</span><span id=\"indicator\"><span class=\"dot\"></span><span class=\"count\">0</span></span></div>\n `;\n this.#container = root.getElementById('container')!;\n this.#countEl = root.querySelector('.count');\n this.#setCount(this.hasAttribute('count'));\n }\n\n /** Show/hide the cumulative update count (and the at-rest opacity). */\n #setCount(enabled: boolean) {\n this.#container.classList.toggle('with-count', enabled);\n }\n\n connectedCallback() {\n if (this.#initialized) return;\n this.#initialized = true;\n injectTokens();\n const hot = (import.meta as {hot?: ViteHotLike}).hot;\n hot?.on('vite:afterUpdate', (data) => {\n // Count only updates that actually re-render/re-execute a component;\n // a pure shared-stylesheet swap (?css-sheet / ?raw / ?url adopted sheet)\n // restyles in place without re-rendering, so it pulses but doesn't count.\n const styleSwap = isStyleSwap(data);\n if (!styleSwap && this.#countEl !== null) {\n this.#countEl.textContent = String(++this.#count);\n }\n this.#container.classList.toggle('style-swap', styleSwap);\n this.#container.classList.remove('active');\n void this.#container.offsetWidth;\n this.#container.classList.add('active');\n });\n // Let the DevTools panel hide/show the indicator and its count live (and\n // across reloads).\n subscribeOverride(hot, (o) => {\n if (o.hmrIndicatorVisible !== undefined) {\n this.style.display = o.hmrIndicatorVisible ? '' : 'none';\n }\n if (o.hmrIndicatorCount !== undefined) {\n this.#setCount(o.hmrIndicatorCount);\n }\n });\n // Stay clear of the Vite DevTools edge panel.\n observeEdgeInsets((insets) => {\n this.style.setProperty('--edge-top', `${insets.top}px`);\n this.style.setProperty('--edge-right', `${insets.right}px`);\n this.style.setProperty('--edge-bottom', `${insets.bottom}px`);\n this.style.setProperty('--edge-left', `${insets.left}px`);\n });\n }\n}\n\ncustomElements.define('lit-devtools-hmr-indicator', LitDevtoolsIndicator);\n"]}
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
*/
|
|
14
14
|
import {createPageScriptChannel} from 'devframe/in-page-channel';
|
|
15
15
|
import {elementById} from '../timeline/identity.js';
|
|
16
|
+
import {pageChannel} from '../page-channel.js';
|
|
16
17
|
import {buildTree, collectDetails} from './collect.js';
|
|
17
18
|
import {clearHighlight, highlightById} from './highlight.js';
|
|
18
19
|
import {LIT_IN_PAGE_CHANNEL} from '../../../types/in-page.js';
|
|
@@ -21,6 +22,7 @@ import {
|
|
|
21
22
|
INSPECT_DATA_CHANNEL,
|
|
22
23
|
} from '../../../types/inspector.js';
|
|
23
24
|
const hot = import.meta.hot;
|
|
25
|
+
if (hot !== undefined) pageChannel.useViteHot(hot);
|
|
24
26
|
// The direct panel channel, outside the `hot` gate on purpose: it is the one
|
|
25
27
|
// part of the inspector that does not need a dev server, which is what lets
|
|
26
28
|
// the hover outline keep working in a static snapshot of the panel. Answering
|
|
@@ -40,7 +42,7 @@ if (typeof window !== 'undefined') {
|
|
|
40
42
|
if (hot !== undefined && typeof window !== 'undefined') {
|
|
41
43
|
const send = (msg) => {
|
|
42
44
|
try {
|
|
43
|
-
|
|
45
|
+
pageChannel.send(INSPECT_DATA_CHANNEL, msg);
|
|
44
46
|
} catch {
|
|
45
47
|
// HMR channel temporarily unavailable; the panel can re-request.
|
|
46
48
|
}
|
|
@@ -94,23 +96,33 @@ if (hot !== undefined && typeof window !== 'undefined') {
|
|
|
94
96
|
// fresh tree when the component hierarchy actually changes. Off by default.
|
|
95
97
|
// childList-only (no attributes), so cosmetic changes — including our own
|
|
96
98
|
// highlight box toggling — don't churn; identical rebuilds are also deduped.
|
|
99
|
+
// Batches that only move text or comment nodes (most Lit re-renders) are
|
|
100
|
+
// dropped before the debounce, and only added subtrees are walked for new
|
|
101
|
+
// shadow roots, so a busy page no longer costs a full-page walk per batch.
|
|
97
102
|
// -------------------------------------------------------------------------
|
|
98
103
|
let observer = null;
|
|
99
104
|
let observeTimer;
|
|
100
105
|
let lastTreeJson = '';
|
|
106
|
+
// Added elements whose subtrees still need their shadow roots observed.
|
|
107
|
+
let pendingRoots = [];
|
|
108
|
+
/** Observe every shadow root at or under `root` (and `root`'s subtree). */
|
|
109
|
+
const observeShadowRoots = (obs, root) => {
|
|
110
|
+
if (root instanceof Element && root.shadowRoot !== null) {
|
|
111
|
+
obs.observe(root.shadowRoot, {childList: true, subtree: true});
|
|
112
|
+
observeShadowRoots(obs, root.shadowRoot);
|
|
113
|
+
}
|
|
114
|
+
for (const el of root.querySelectorAll('*')) {
|
|
115
|
+
if (el.shadowRoot !== null) {
|
|
116
|
+
obs.observe(el.shadowRoot, {childList: true, subtree: true});
|
|
117
|
+
observeShadowRoots(obs, el.shadowRoot);
|
|
118
|
+
}
|
|
119
|
+
}
|
|
120
|
+
};
|
|
101
121
|
/** Re-attach the observer to the body and every shadow root in the page. */
|
|
102
122
|
const syncObserverTargets = (obs) => {
|
|
103
123
|
obs.disconnect();
|
|
104
124
|
obs.observe(document.body, {childList: true, subtree: true});
|
|
105
|
-
|
|
106
|
-
for (const el of root.querySelectorAll('*')) {
|
|
107
|
-
if (el.shadowRoot !== null) {
|
|
108
|
-
obs.observe(el.shadowRoot, {childList: true, subtree: true});
|
|
109
|
-
walk(el.shadowRoot);
|
|
110
|
-
}
|
|
111
|
-
}
|
|
112
|
-
};
|
|
113
|
-
walk(document);
|
|
125
|
+
observeShadowRoots(obs, document);
|
|
114
126
|
};
|
|
115
127
|
const pushTreeIfChanged = () => {
|
|
116
128
|
const roots = buildTree();
|
|
@@ -119,11 +131,50 @@ if (hot !== undefined && typeof window !== 'undefined') {
|
|
|
119
131
|
lastTreeJson = json;
|
|
120
132
|
send({type: 'tree', roots});
|
|
121
133
|
};
|
|
122
|
-
|
|
134
|
+
/** Whether a subtree holds anything the tree (or observer) cares about. */
|
|
135
|
+
const mayHoldComponents = (node) => {
|
|
136
|
+
if (!(node instanceof Element)) return false;
|
|
137
|
+
const matters = (el) =>
|
|
138
|
+
el.localName.includes('-') || el.shadowRoot !== null;
|
|
139
|
+
if (matters(node)) return true;
|
|
140
|
+
for (const el of node.querySelectorAll('*')) if (matters(el)) return true;
|
|
141
|
+
return false;
|
|
142
|
+
};
|
|
143
|
+
const onMutation = (records) => {
|
|
144
|
+
// The tree only has custom elements in it, so a batch that adds or
|
|
145
|
+
// removes none (text, comments, plain markup) can't change it.
|
|
146
|
+
let relevant = false;
|
|
147
|
+
for (const record of records) {
|
|
148
|
+
for (const node of record.addedNodes) {
|
|
149
|
+
if (mayHoldComponents(node)) {
|
|
150
|
+
pendingRoots.push(node);
|
|
151
|
+
relevant = true;
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
if (!relevant) {
|
|
155
|
+
for (const node of record.removedNodes) {
|
|
156
|
+
if (mayHoldComponents(node)) {
|
|
157
|
+
relevant = true;
|
|
158
|
+
break;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (!relevant) return;
|
|
123
164
|
if (observeTimer !== undefined) clearTimeout(observeTimer);
|
|
124
165
|
observeTimer = setTimeout(() => {
|
|
125
166
|
observeTimer = undefined;
|
|
126
|
-
|
|
167
|
+
// Walk added subtrees now rather than on arrival: a custom element
|
|
168
|
+
// attaches its shadow root when it upgrades, which can be after insert.
|
|
169
|
+
// Removed roots need no bookkeeping; a detached shadow root just stops
|
|
170
|
+
// producing records.
|
|
171
|
+
const roots = pendingRoots;
|
|
172
|
+
pendingRoots = [];
|
|
173
|
+
if (observer !== null) {
|
|
174
|
+
for (const root of roots) {
|
|
175
|
+
if (root.isConnected) observeShadowRoots(observer, root);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
127
178
|
pushTreeIfChanged();
|
|
128
179
|
}, 100);
|
|
129
180
|
};
|
|
@@ -136,6 +187,7 @@ if (hot !== undefined && typeof window !== 'undefined') {
|
|
|
136
187
|
} else if (observer !== null) {
|
|
137
188
|
observer.disconnect();
|
|
138
189
|
observer = null;
|
|
190
|
+
pendingRoots = [];
|
|
139
191
|
if (observeTimer !== undefined) {
|
|
140
192
|
clearTimeout(observeTimer);
|
|
141
193
|
observeTimer = undefined;
|
|
@@ -166,7 +218,7 @@ if (hot !== undefined && typeof window !== 'undefined') {
|
|
|
166
218
|
// -------------------------------------------------------------------------
|
|
167
219
|
// Command dispatch
|
|
168
220
|
// -------------------------------------------------------------------------
|
|
169
|
-
|
|
221
|
+
pageChannel.on(INSPECT_CMD_CHANNEL, (data) => {
|
|
170
222
|
const cmd = data;
|
|
171
223
|
switch (cmd.type) {
|
|
172
224
|
case 'tree': {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../../src/lib/runtime/inspector/install.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAC,uBAAuB,EAAC,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,cAAc,EAAE,aAAa,EAAC,MAAM,gBAAgB,CAAC;AAC7D,OAAO,EACL,mBAAmB,GAEpB,MAAM,2BAA2B,CAAC;AACnC,O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C,CAAC;gBACnC,CAAC;gBACD,MAAM;YACR,CAAC;YACD,KAAK,OAAO;gBACV,IAAI,GAAG,CAAC,EAAE,KAAK,IAAI;oBAAE,OAAO,EAAE,CAAC;;oBAC1B,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACnB,MAAM;YACR,KAAK,WAAW;gBACd,kEAAkE;gBAClE,8CAA8C;gBAC9C,aAAa,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;gBACtB,MAAM;YACR,KAAK,SAAS;gBACZ,YAAY,CAAC,GAAG,CAAC,OAAO,CAAC,CAAC;gBAC1B,MAAM;QACV,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,wEAAwE;IACxE,IAAI,CAAC,EAAC,IAAI,EAAE,OAAO,EAAC,CAAC,CAAC;AACxB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/**\n * Components inspector runtime.\n *\n * Injected into the host page (alongside the timeline runtime) when the\n * DevTools panel is enabled. Answers the panel's tree/details requests over the\n * Vite HMR channel, keeps a watched element's details fresh as it updates, and\n * outlines elements the panel hovers in its tree.\n */\n\nimport {createPageScriptChannel} from 'devframe/in-page-channel';\nimport {elementById} from '../timeline/identity.js';\nimport {buildTree, collectDetails} from './collect.js';\nimport {clearHighlight, highlightById} from './highlight.js';\nimport {\n LIT_IN_PAGE_CHANNEL,\n type LitInPageProtocol,\n} from '../../../types/in-page.js';\nimport {\n INSPECT_CMD_CHANNEL,\n INSPECT_DATA_CHANNEL,\n type InspectorCommand,\n type InspectorMessage,\n} from '../../../types/inspector.js';\n\ntype ViteHot = {\n send: (event: string, data: unknown) => void;\n on: (event: string, handler: (data: unknown) => void) => void;\n};\n\nconst hot = (import.meta as {hot?: ViteHot}).hot;\n\n// The direct panel channel, outside the `hot` gate on purpose: it is the one\n// part of the inspector that does not need a dev server, which is what lets\n// the hover outline keep working in a static snapshot of the panel. Answering\n// handshakes costs nothing until a panel actually sends one.\nif (typeof window !== 'undefined') {\n const channel = createPageScriptChannel<LitInPageProtocol>({\n name: LIT_IN_PAGE_CHANNEL,\n functions: {},\n events: {\n highlight: {handler: (id) => highlightById(id)},\n },\n });\n // A panel that goes away mid-hover never gets to send its `highlight(null)`,\n // and an outline left painted over the app is worse than a missing one.\n channel.events.on('panel:disconnected', () => clearHighlight());\n}\n\nif (hot !== undefined && typeof window !== 'undefined') {\n const send = (msg: InspectorMessage): void => {\n try {\n hot.send(INSPECT_DATA_CHANNEL, msg);\n } catch {\n // HMR channel temporarily unavailable; the panel can re-request.\n }\n };\n\n // -------------------------------------------------------------------------\n // Live-watch: re-push details whenever the watched element finishes updating.\n // We wrap the instance's `updated` (not the prototype) so the hook is scoped\n // to one element and trivially removable, and it works without the timeline's\n // recording gate.\n // -------------------------------------------------------------------------\n\n type Updatable = Element & {\n updated?: (changed: unknown) => void;\n };\n // Hold the watched element via a WeakRef so an active watch doesn't keep a\n // removed element alive: the override and `restore` only reach `el` through\n // the ref, leaving the DOM as its sole strong root.\n let watched: {ref: WeakRef<Updatable>; restore: () => void} | null = null;\n\n const unwatch = (): void => {\n watched?.restore();\n watched = null;\n };\n\n const watch = (id: number): void => {\n unwatch();\n const el = elementById(id) as Updatable | undefined;\n if (el === undefined) {\n send({type: 'gone', id});\n return;\n }\n const hadOwn = Object.prototype.hasOwnProperty.call(el, 'updated');\n // Only an *own* `updated` is stable across an HMR hot patch. A prototype\n // implementation is replaced in place on every patch (`syncOwnMembers` in\n // ../patch.ts), so caching it here would pin the watched instance to the\n // pre-edit code for the life of the watch — resolve it through the\n // prototype chain on each call instead. Our wrapper is an own property, so\n // the lookup skips it and cannot recurse.\n const ownPrev = hadOwn ? el.updated : undefined;\n const ref = new WeakRef(el);\n el.updated = function (this: Updatable, changed: unknown) {\n const current =\n ownPrev ?? (Object.getPrototypeOf(this) as Updatable | null)?.updated;\n current?.call(this, changed);\n const cur = ref.deref();\n if (cur !== undefined) {\n send({type: 'details', details: collectDetails(cur)});\n }\n };\n watched = {\n ref,\n restore: () => {\n const cur = ref.deref();\n if (cur === undefined) return;\n if (hadOwn) cur.updated = ownPrev;\n else delete cur.updated;\n },\n };\n // Push an immediate snapshot so the panel doesn't wait for the next update.\n send({type: 'details', details: collectDetails(el)});\n };\n\n // -------------------------------------------------------------------------\n // Opt-in live tree: watch the DOM (light + every shadow root) and push a\n // fresh tree when the component hierarchy actually changes. Off by default.\n // childList-only (no attributes), so cosmetic changes — including our own\n // highlight box toggling — don't churn; identical rebuilds are also deduped.\n // -------------------------------------------------------------------------\n\n let observer: MutationObserver | null = null;\n let observeTimer: ReturnType<typeof setTimeout> | undefined;\n let lastTreeJson = '';\n\n /** Re-attach the observer to the body and every shadow root in the page. */\n const syncObserverTargets = (obs: MutationObserver): void => {\n obs.disconnect();\n obs.observe(document.body, {childList: true, subtree: true});\n const walk = (root: ParentNode): void => {\n for (const el of root.querySelectorAll('*')) {\n if (el.shadowRoot !== null) {\n obs.observe(el.shadowRoot, {childList: true, subtree: true});\n walk(el.shadowRoot);\n }\n }\n };\n walk(document);\n };\n\n const pushTreeIfChanged = (): void => {\n const roots = buildTree();\n const json = JSON.stringify(roots);\n if (json === lastTreeJson) return;\n lastTreeJson = json;\n send({type: 'tree', roots});\n };\n\n const onMutation = (): void => {\n if (observeTimer !== undefined) clearTimeout(observeTimer);\n observeTimer = setTimeout(() => {\n observeTimer = undefined;\n if (observer !== null) syncObserverTargets(observer);\n pushTreeIfChanged();\n }, 100);\n };\n\n const setObserving = (enabled: boolean): void => {\n if (enabled) {\n if (observer === null) observer = new MutationObserver(onMutation);\n lastTreeJson = '';\n syncObserverTargets(observer);\n pushTreeIfChanged();\n } else if (observer !== null) {\n observer.disconnect();\n observer = null;\n if (observeTimer !== undefined) {\n clearTimeout(observeTimer);\n observeTimer = undefined;\n }\n }\n };\n\n // -------------------------------------------------------------------------\n // SPA navigation: a route change swaps the component tree without any HMR\n // or panel event, so the snapshot went stale until a manual refresh. Push a\n // deduped tree after each navigation — twice, since routes typically\n // lazy-load and render async. Redundant while the live observer watches.\n // -------------------------------------------------------------------------\n\n const onNavigation = (): void => {\n if (observer !== null) return;\n for (const delay of [150, 1000]) {\n setTimeout(pushTreeIfChanged, delay);\n }\n };\n window.addEventListener('popstate', onNavigation);\n window.addEventListener('hashchange', onNavigation);\n for (const method of ['pushState', 'replaceState'] as const) {\n const original = history[method].bind(history);\n history[method] = (...args: Parameters<History['pushState']>) => {\n original(...args);\n onNavigation();\n };\n }\n\n // -------------------------------------------------------------------------\n // Command dispatch\n // -------------------------------------------------------------------------\n\n hot.on(INSPECT_CMD_CHANNEL, (data) => {\n const cmd = data as InspectorCommand;\n switch (cmd.type) {\n case 'tree': {\n const roots = buildTree();\n lastTreeJson = JSON.stringify(roots);\n send({type: 'tree', roots});\n break;\n }\n case 'details': {\n const el = elementById(cmd.id);\n if (el !== undefined) {\n send({type: 'details', details: collectDetails(el)});\n } else {\n send({type: 'gone', id: cmd.id});\n }\n break;\n }\n case 'watch':\n if (cmd.id === null) unwatch();\n else watch(cmd.id);\n break;\n case 'highlight':\n // Fallback path. A panel that handshaked over the in-page channel\n // emits there instead and never reaches this.\n highlightById(cmd.id);\n break;\n case 'observe':\n setObserving(cmd.enabled);\n break;\n }\n });\n\n // Announce readiness so a panel that loaded first re-requests the tree.\n send({type: 'ready'});\n}\n"]}
|
|
1
|
+
{"version":3,"file":"install.js","sourceRoot":"","sources":["../../../src/lib/runtime/inspector/install.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH;;;;;;;GAOG;AAEH,OAAO,EAAC,uBAAuB,EAAC,MAAM,0BAA0B,CAAC;AACjE,OAAO,EAAC,WAAW,EAAC,MAAM,yBAAyB,CAAC;AACpD,OAAO,EAAC,WAAW,EAAC,MAAM,oBAAoB,CAAC;AAE/C,OAAO,EAAC,SAAS,EAAE,cAAc,EAAC,MAAM,cAAc,CAAC;AACvD,OAAO,EAAC,cAAc,EAAE,aAAa,EAAC,MAAM,gBAAgB,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,EAAE,OAAO,EAAC,CAAC,CAAC;AACxB,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\n/**\n * Components inspector runtime.\n *\n * Injected into the host page (alongside the timeline runtime) when the\n * DevTools panel is enabled. Answers the panel's tree/details requests over the\n * Vite HMR channel, keeps a watched element's details fresh as it updates, and\n * outlines elements the panel hovers in its tree.\n */\n\nimport {createPageScriptChannel} from 'devframe/in-page-channel';\nimport {elementById} from '../timeline/identity.js';\nimport {pageChannel} from '../page-channel.js';\nimport type {ViteHotLike} from '../page-channel.js';\nimport {buildTree, collectDetails} from './collect.js';\nimport {clearHighlight, highlightById} from './highlight.js';\nimport {\n LIT_IN_PAGE_CHANNEL,\n type LitInPageProtocol,\n} from '../../../types/in-page.js';\nimport {\n INSPECT_CMD_CHANNEL,\n INSPECT_DATA_CHANNEL,\n type InspectorCommand,\n type InspectorMessage,\n} from '../../../types/inspector.js';\n\nconst hot = (import.meta as {hot?: ViteHotLike}).hot;\nif (hot !== undefined) pageChannel.useViteHot(hot);\n\n// The direct panel channel, outside the `hot` gate on purpose: it is the one\n// part of the inspector that does not need a dev server, which is what lets\n// the hover outline keep working in a static snapshot of the panel. Answering\n// handshakes costs nothing until a panel actually sends one.\nif (typeof window !== 'undefined') {\n const channel = createPageScriptChannel<LitInPageProtocol>({\n name: LIT_IN_PAGE_CHANNEL,\n functions: {},\n events: {\n highlight: {handler: (id) => highlightById(id)},\n },\n });\n // A panel that goes away mid-hover never gets to send its `highlight(null)`,\n // and an outline left painted over the app is worse than a missing one.\n channel.events.on('panel:disconnected', () => clearHighlight());\n}\n\nif (hot !== undefined && typeof window !== 'undefined') {\n const send = (msg: InspectorMessage): void => {\n try {\n pageChannel.send(INSPECT_DATA_CHANNEL, msg);\n } catch {\n // HMR channel temporarily unavailable; the panel can re-request.\n }\n };\n\n // -------------------------------------------------------------------------\n // Live-watch: re-push details whenever the watched element finishes updating.\n // We wrap the instance's `updated` (not the prototype) so the hook is scoped\n // to one element and trivially removable, and it works without the timeline's\n // recording gate.\n // -------------------------------------------------------------------------\n\n type Updatable = Element & {\n updated?: (changed: unknown) => void;\n };\n // Hold the watched element via a WeakRef so an active watch doesn't keep a\n // removed element alive: the override and `restore` only reach `el` through\n // the ref, leaving the DOM as its sole strong root.\n let watched: {ref: WeakRef<Updatable>; restore: () => void} | null = null;\n\n const unwatch = (): void => {\n watched?.restore();\n watched = null;\n };\n\n const watch = (id: number): void => {\n unwatch();\n const el = elementById(id) as Updatable | undefined;\n if (el === undefined) {\n send({type: 'gone', id});\n return;\n }\n const hadOwn = Object.prototype.hasOwnProperty.call(el, 'updated');\n // Only an *own* `updated` is stable across an HMR hot patch. A prototype\n // implementation is replaced in place on every patch (`syncOwnMembers` in\n // ../patch.ts), so caching it here would pin the watched instance to the\n // pre-edit code for the life of the watch — resolve it through the\n // prototype chain on each call instead. Our wrapper is an own property, so\n // the lookup skips it and cannot recurse.\n const ownPrev = hadOwn ? el.updated : undefined;\n const ref = new WeakRef(el);\n el.updated = function (this: Updatable, changed: unknown) {\n const current =\n ownPrev ?? (Object.getPrototypeOf(this) as Updatable | null)?.updated;\n current?.call(this, changed);\n const cur = ref.deref();\n if (cur !== undefined) {\n send({type: 'details', details: collectDetails(cur)});\n }\n };\n watched = {\n ref,\n restore: () => {\n const cur = ref.deref();\n if (cur === undefined) return;\n if (hadOwn) cur.updated = ownPrev;\n else delete cur.updated;\n },\n };\n // Push an immediate snapshot so the panel doesn't wait for the next update.\n send({type: 'details', details: collectDetails(el)});\n };\n\n // -------------------------------------------------------------------------\n // Opt-in live tree: watch the DOM (light + every shadow root) and push a\n // fresh tree when the component hierarchy actually changes. Off by default.\n // childList-only (no attributes), so cosmetic changes — including our own\n // highlight box toggling — don't churn; identical rebuilds are also deduped.\n // Batches that only move text or comment nodes (most Lit re-renders) are\n // dropped before the debounce, and only added subtrees are walked for new\n // shadow roots, so a busy page no longer costs a full-page walk per batch.\n // -------------------------------------------------------------------------\n\n let observer: MutationObserver | null = null;\n let observeTimer: ReturnType<typeof setTimeout> | undefined;\n let lastTreeJson = '';\n // Added elements whose subtrees still need their shadow roots observed.\n let pendingRoots: Element[] = [];\n\n /** Observe every shadow root at or under `root` (and `root`'s subtree). */\n const observeShadowRoots = (\n obs: MutationObserver,\n root: ParentNode\n ): void => {\n if (root instanceof Element && root.shadowRoot !== null) {\n obs.observe(root.shadowRoot, {childList: true, subtree: true});\n observeShadowRoots(obs, root.shadowRoot);\n }\n for (const el of root.querySelectorAll('*')) {\n if (el.shadowRoot !== null) {\n obs.observe(el.shadowRoot, {childList: true, subtree: true});\n observeShadowRoots(obs, el.shadowRoot);\n }\n }\n };\n\n /** Re-attach the observer to the body and every shadow root in the page. */\n const syncObserverTargets = (obs: MutationObserver): void => {\n obs.disconnect();\n obs.observe(document.body, {childList: true, subtree: true});\n observeShadowRoots(obs, document);\n };\n\n const pushTreeIfChanged = (): void => {\n const roots = buildTree();\n const json = JSON.stringify(roots);\n if (json === lastTreeJson) return;\n lastTreeJson = json;\n send({type: 'tree', roots});\n };\n\n /** Whether a subtree holds anything the tree (or observer) cares about. */\n const mayHoldComponents = (node: Node): node is Element => {\n if (!(node instanceof Element)) return false;\n const matters = (el: Element): boolean =>\n el.localName.includes('-') || el.shadowRoot !== null;\n if (matters(node)) return true;\n for (const el of node.querySelectorAll('*')) if (matters(el)) return true;\n return false;\n };\n\n const onMutation = (records: MutationRecord[]): void => {\n // The tree only has custom elements in it, so a batch that adds or\n // removes none (text, comments, plain markup) can't change it.\n let relevant = false;\n for (const record of records) {\n for (const node of record.addedNodes) {\n if (mayHoldComponents(node)) {\n pendingRoots.push(node);\n relevant = true;\n }\n }\n if (!relevant) {\n for (const node of record.removedNodes) {\n if (mayHoldComponents(node)) {\n relevant = true;\n break;\n }\n }\n }\n }\n if (!relevant) return;\n if (observeTimer !== undefined) clearTimeout(observeTimer);\n observeTimer = setTimeout(() => {\n observeTimer = undefined;\n // Walk added subtrees now rather than on arrival: a custom element\n // attaches its shadow root when it upgrades, which can be after insert.\n // Removed roots need no bookkeeping; a detached shadow root just stops\n // producing records.\n const roots = pendingRoots;\n pendingRoots = [];\n if (observer !== null) {\n for (const root of roots) {\n if (root.isConnected) observeShadowRoots(observer, root);\n }\n }\n pushTreeIfChanged();\n }, 100);\n };\n\n const setObserving = (enabled: boolean): void => {\n if (enabled) {\n if (observer === null) observer = new MutationObserver(onMutation);\n lastTreeJson = '';\n syncObserverTargets(observer);\n pushTreeIfChanged();\n } else if (observer !== null) {\n observer.disconnect();\n observer = null;\n pendingRoots = [];\n if (observeTimer !== undefined) {\n clearTimeout(observeTimer);\n observeTimer = undefined;\n }\n }\n };\n\n // -------------------------------------------------------------------------\n // SPA navigation: a route change swaps the component tree without any HMR\n // or panel event, so the snapshot went stale until a manual refresh. Push a\n // deduped tree after each navigation — twice, since routes typically\n // lazy-load and render async. Redundant while the live observer watches.\n // -------------------------------------------------------------------------\n\n const onNavigation = (): void => {\n if (observer !== null) return;\n for (const delay of [150, 1000]) {\n setTimeout(pushTreeIfChanged, delay);\n }\n };\n window.addEventListener('popstate', onNavigation);\n window.addEventListener('hashchange', onNavigation);\n for (const method of ['pushState', 'replaceState'] as const) {\n const original = history[method].bind(history);\n history[method] = (...args: Parameters<History['pushState']>) => {\n original(...args);\n onNavigation();\n };\n }\n\n // -------------------------------------------------------------------------\n // Command dispatch\n // -------------------------------------------------------------------------\n\n pageChannel.on(INSPECT_CMD_CHANNEL, (data) => {\n const cmd = data as InspectorCommand;\n switch (cmd.type) {\n case 'tree': {\n const roots = buildTree();\n lastTreeJson = JSON.stringify(roots);\n send({type: 'tree', roots});\n break;\n }\n case 'details': {\n const el = elementById(cmd.id);\n if (el !== undefined) {\n send({type: 'details', details: collectDetails(el)});\n } else {\n send({type: 'gone', id: cmd.id});\n }\n break;\n }\n case 'watch':\n if (cmd.id === null) unwatch();\n else watch(cmd.id);\n break;\n case 'highlight':\n // Fallback path. A panel that handshaked over the in-page channel\n // emits there instead and never reaches this.\n highlightById(cmd.id);\n break;\n case 'observe':\n setObserving(cmd.enabled);\n break;\n }\n });\n\n // Announce readiness so a panel that loaded first re-requests the tree.\n send({type: 'ready'});\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/lib/runtime/inspector/serialize.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"serialize.d.ts","sourceRoot":"","sources":["../../../src/lib/runtime/inspector/serialize.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA0BH,gEAAgE;AAChE,eAAO,MAAM,OAAO,UAAW,OAAO,KAAG,MAaxC,CAAC;AAiGF,oEAAoE;AACpE,eAAO,MAAM,SAAS,UAAW,OAAO,KAAG,MAM1C,CAAC"}
|