@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
package/lib/options.d.ts
ADDED
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import type { SourceOverlayOptions } from './types.js';
|
|
7
|
+
import type { FeatureSettings, SettingSources } from '../types/timeline.js';
|
|
8
|
+
/**
|
|
9
|
+
* On-page HMR feedback: a small pulsing indicator in the corner of the host
|
|
10
|
+
* page that briefly animates on each HMR update, for at-a-glance feedback
|
|
11
|
+
* without watching the console.
|
|
12
|
+
*/
|
|
13
|
+
export interface HmrIndicatorOptions {
|
|
14
|
+
/** Inject the indicator element. Defaults to `true` (when HMR is enabled). */
|
|
15
|
+
enabled?: boolean;
|
|
16
|
+
/**
|
|
17
|
+
* Show a cumulative update count next to the dot (idle opacity 0.5 instead
|
|
18
|
+
* of fully transparent). Defaults to `false`.
|
|
19
|
+
*/
|
|
20
|
+
count?: boolean;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* HMR for Lit component classes and its on-page feedback.
|
|
24
|
+
*/
|
|
25
|
+
export interface HmrOptions {
|
|
26
|
+
/**
|
|
27
|
+
* Enable in-place HMR for Lit component classes. When `false`, the plugin
|
|
28
|
+
* skips all HMR transforms and runtime injection. Defaults to `true`.
|
|
29
|
+
*/
|
|
30
|
+
enabled?: boolean;
|
|
31
|
+
/**
|
|
32
|
+
* Cycle `disconnectedCallback()`/`connectedCallback()` on live instances
|
|
33
|
+
* after a hot patch. Interning makes this mostly unnecessary, so it's
|
|
34
|
+
* opt-in. Defaults to `false`.
|
|
35
|
+
*/
|
|
36
|
+
reconnect?: boolean;
|
|
37
|
+
/**
|
|
38
|
+
* What to do when a component can't be hot-patched in place (e.g.
|
|
39
|
+
* standard `accessor` decorators). Defaults to `'reload'`.
|
|
40
|
+
*/
|
|
41
|
+
onIncompatible?: 'reload' | 'warn';
|
|
42
|
+
/**
|
|
43
|
+
* The on-page update indicator. `true` enables it without a count; an
|
|
44
|
+
* object configures it. Forced off when HMR itself is disabled. Defaults
|
|
45
|
+
* to enabled (without a count).
|
|
46
|
+
*/
|
|
47
|
+
indicator?: boolean | HmrIndicatorOptions;
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* What a `?css-sheet` import compiles to under `vite build`.
|
|
51
|
+
*
|
|
52
|
+
* - `'url'`: fetch-backed sheet over the emitted `.css` asset.
|
|
53
|
+
* - `'inline'`: css text embedded in the JS chunk, processed by the css
|
|
54
|
+
* pipeline (`?inline`).
|
|
55
|
+
* - `'inline-raw'`: css text embedded verbatim, skipping the css pipeline
|
|
56
|
+
* (`?raw`).
|
|
57
|
+
* - `'auto'`: `'inline'` when `build.lib` is set, `'url'` otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export type CssSheetBuild = 'auto' | 'url' | 'inline' | 'inline-raw';
|
|
60
|
+
/**
|
|
61
|
+
* Options for the Lit Vite plugin.
|
|
62
|
+
*
|
|
63
|
+
* Every option also resolves from environment variables (and `.env` files)
|
|
64
|
+
* with the `LIT_PLUGIN` prefix — e.g. `LIT_PLUGIN_HMR_INDICATOR=true`. Options
|
|
65
|
+
* passed here take precedence over env vars, which take precedence over the
|
|
66
|
+
* built-in defaults.
|
|
67
|
+
*/
|
|
68
|
+
export interface LitPluginOptions {
|
|
69
|
+
/**
|
|
70
|
+
* HMR for Lit components and its on-page feedback. `true`/`false` toggles
|
|
71
|
+
* the whole feature (patching and indicator); an object configures it.
|
|
72
|
+
* Defaults to enabled.
|
|
73
|
+
*/
|
|
74
|
+
hmr?: boolean | HmrOptions;
|
|
75
|
+
/**
|
|
76
|
+
* Dev-only click-to-open-in-IDE inspector for Lit custom elements.
|
|
77
|
+
* Toggle with Ctrl+Shift+S (configurable via `key`). Defaults to `false`.
|
|
78
|
+
*/
|
|
79
|
+
sourceOverlay?: boolean | SourceOverlayOptions;
|
|
80
|
+
/**
|
|
81
|
+
* Vite DevTools Timeline panel — a Vue DevTools–style layered event stream
|
|
82
|
+
* for Lit lifecycle, render, mouse, and keyboard events.
|
|
83
|
+
*
|
|
84
|
+
* Requires `@vitejs/devtools` in the Vite config and the `@vitejs/devtools`
|
|
85
|
+
* Vite plugin (`DevTools()`) to be active. Defaults to `false` while
|
|
86
|
+
* experimental.
|
|
87
|
+
*
|
|
88
|
+
* `true` enables all built-in layers with defaults.
|
|
89
|
+
*/
|
|
90
|
+
timeline?: boolean;
|
|
91
|
+
/**
|
|
92
|
+
* What a `?css-sheet` import compiles to under `vite build`.
|
|
93
|
+
* - `'url'`: fetch-backed sheet over the emitted `.css` asset
|
|
94
|
+
* - `'inline'`: css text embedded in the JS chunk, processed by the css
|
|
95
|
+
* pipeline (`?inline`)
|
|
96
|
+
* - `'inline-raw'`: css text embedded verbatim, skipping the css pipeline
|
|
97
|
+
* (`?raw`)
|
|
98
|
+
* - `'auto'`: `'inline'` when `build.lib` is set, `'url'` otherwise
|
|
99
|
+
*
|
|
100
|
+
* Dev is always the fetch-backed HMR form regardless of this setting.
|
|
101
|
+
* Defaults to `'auto'`.
|
|
102
|
+
*/
|
|
103
|
+
cssSheetBuild?: CssSheetBuild;
|
|
104
|
+
}
|
|
105
|
+
/** Plugin options after merging explicit options, env vars, and defaults. */
|
|
106
|
+
export interface ResolvedOptions {
|
|
107
|
+
hmrEnabled: boolean;
|
|
108
|
+
reconnect: boolean;
|
|
109
|
+
onIncompatible: 'reload' | 'warn';
|
|
110
|
+
indicator: false | {
|
|
111
|
+
count: boolean;
|
|
112
|
+
};
|
|
113
|
+
sourceOverlay: false | SourceOverlayOptions;
|
|
114
|
+
timeline: boolean;
|
|
115
|
+
cssSheetBuild: CssSheetBuild;
|
|
116
|
+
/**
|
|
117
|
+
* Which layer each panel-visible setting came from. Source-overlay keys are
|
|
118
|
+
* present only when the overlay is enabled.
|
|
119
|
+
*/
|
|
120
|
+
sources: SettingSources;
|
|
121
|
+
}
|
|
122
|
+
/** Env var prefix consumed at config time. */
|
|
123
|
+
export declare const ENV_PREFIX = "LIT_PLUGIN";
|
|
124
|
+
/**
|
|
125
|
+
* Merge explicit options over env vars over defaults (in that precedence) into
|
|
126
|
+
* the flat shape the plugin hooks consume.
|
|
127
|
+
*/
|
|
128
|
+
export declare const resolveOptions: (options: LitPluginOptions, env: Record<string, string>) => ResolvedOptions;
|
|
129
|
+
/**
|
|
130
|
+
* Flattens resolved options into the JSON-serializable shape the panel's
|
|
131
|
+
* Settings tab consumes (callback options like `exclude`/`onSelect` dropped;
|
|
132
|
+
* a custom editor object reported as `"custom"`). Default key/editor/throttle
|
|
133
|
+
* are applied here so the panel shows the effective values the runtime uses.
|
|
134
|
+
*/
|
|
135
|
+
export declare const toFeatureSettings: (r: ResolvedOptions) => FeatureSettings;
|
|
136
|
+
//# sourceMappingURL=options.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.d.ts","sourceRoot":"","sources":["../src/lib/options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,oBAAoB,EAAC,MAAM,YAAY,CAAC;AACrD,OAAO,KAAK,EACV,eAAe,EAEf,cAAc,EACf,MAAM,sBAAsB,CAAC;AAG9B;;;;GAIG;AACH,MAAM,WAAW,mBAAmB;IAClC,8EAA8E;IAC9E,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;OAGG;IACH,KAAK,CAAC,EAAE,OAAO,CAAC;CACjB;AAED;;GAEG;AACH,MAAM,WAAW,UAAU;IACzB;;;OAGG;IACH,OAAO,CAAC,EAAE,OAAO,CAAC;IAElB;;;;OAIG;IACH,SAAS,CAAC,EAAE,OAAO,CAAC;IAEpB;;;OAGG;IACH,cAAc,CAAC,EAAE,QAAQ,GAAG,MAAM,CAAC;IA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|
5
|
+
*/
|
|
6
|
+
import {BUILTIN_EDITORS} from './runtime/source-overlay/editors.js';
|
|
7
|
+
const CSS_SHEET_BUILD_MODES = ['auto', 'url', 'inline', 'inline-raw'];
|
|
8
|
+
/** Env var prefix consumed at config time. */
|
|
9
|
+
export const ENV_PREFIX = 'LIT_PLUGIN';
|
|
10
|
+
const ON_INCOMPATIBLE_MODES = ['reload', 'warn'];
|
|
11
|
+
/** Parse a boolean-ish env string; `undefined` when unset/unrecognized. */
|
|
12
|
+
const envBool = (v) =>
|
|
13
|
+
v === 'true' || v === '1'
|
|
14
|
+
? true
|
|
15
|
+
: v === 'false' || v === '0'
|
|
16
|
+
? false
|
|
17
|
+
: undefined;
|
|
18
|
+
/** Parse a numeric env string; `undefined` when unset/non-numeric. */
|
|
19
|
+
const envNum = (v) => {
|
|
20
|
+
if (v === undefined || v === '') return undefined;
|
|
21
|
+
const n = Number(v);
|
|
22
|
+
return Number.isNaN(n) ? undefined : n;
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* Parse a string against a closed set of values; `undefined` (with a warning)
|
|
26
|
+
* when set to something outside it, so a typo falls back to the default
|
|
27
|
+
* instead of silently disabling a feature.
|
|
28
|
+
*/
|
|
29
|
+
const envEnum = (v, allowed, source) => {
|
|
30
|
+
if (v === undefined || v === '') return undefined;
|
|
31
|
+
if (allowed.includes(v)) return v;
|
|
32
|
+
console.warn(
|
|
33
|
+
`[lit-plugin] ignoring ${source}=${JSON.stringify(v)}; expected one of ` +
|
|
34
|
+
allowed.map((a) => JSON.stringify(a)).join(', ')
|
|
35
|
+
);
|
|
36
|
+
return undefined;
|
|
37
|
+
};
|
|
38
|
+
/** Keys a `LIT_PLUGIN_SOURCE_OVERLAY_EDITOR` value may name. */
|
|
39
|
+
const EDITOR_KEYS = Object.keys(BUILTIN_EDITORS);
|
|
40
|
+
/** Which layer supplied a value: the first of option, env that is defined. */
|
|
41
|
+
const sourceOf = (option, env) =>
|
|
42
|
+
option !== undefined ? 'option' : env !== undefined ? 'env' : 'default';
|
|
43
|
+
/**
|
|
44
|
+
* Take the first defined of an explicit option and an env value, else the
|
|
45
|
+
* default, and record which layer won.
|
|
46
|
+
*/
|
|
47
|
+
const pick = (option, env, fallback) => ({
|
|
48
|
+
value: option ?? env ?? fallback,
|
|
49
|
+
source: sourceOf(option, env),
|
|
50
|
+
});
|
|
51
|
+
/**
|
|
52
|
+
* Merge explicit options over env vars over defaults (in that precedence) into
|
|
53
|
+
* the flat shape the plugin hooks consume.
|
|
54
|
+
*/
|
|
55
|
+
export const resolveOptions = (options, env) => {
|
|
56
|
+
const hmr = options.hmr;
|
|
57
|
+
const hmrObj = typeof hmr === 'object' ? hmr : undefined;
|
|
58
|
+
const hmrEnabled =
|
|
59
|
+
(typeof hmr === 'boolean' ? hmr : hmrObj?.enabled) ??
|
|
60
|
+
envBool(env[`${ENV_PREFIX}_HMR`]) ??
|
|
61
|
+
true;
|
|
62
|
+
const reconnect = pick(
|
|
63
|
+
hmrObj?.reconnect,
|
|
64
|
+
envBool(env[`${ENV_PREFIX}_HMR_RECONNECT`]),
|
|
65
|
+
false
|
|
66
|
+
);
|
|
67
|
+
const onIncompatible = pick(
|
|
68
|
+
hmrObj?.onIncompatible,
|
|
69
|
+
envEnum(
|
|
70
|
+
env[`${ENV_PREFIX}_HMR_ON_INCOMPATIBLE`],
|
|
71
|
+
ON_INCOMPATIBLE_MODES,
|
|
72
|
+
`${ENV_PREFIX}_HMR_ON_INCOMPATIBLE`
|
|
73
|
+
),
|
|
74
|
+
'reload'
|
|
75
|
+
);
|
|
76
|
+
const ind = hmrObj?.indicator;
|
|
77
|
+
const indObj = typeof ind === 'object' ? ind : undefined;
|
|
78
|
+
const indEnabled = pick(
|
|
79
|
+
typeof ind === 'boolean' ? ind : indObj?.enabled,
|
|
80
|
+
envBool(env[`${ENV_PREFIX}_HMR_INDICATOR`]),
|
|
81
|
+
true
|
|
82
|
+
);
|
|
83
|
+
const indCount = pick(
|
|
84
|
+
indObj?.count,
|
|
85
|
+
envBool(env[`${ENV_PREFIX}_HMR_INDICATOR_COUNT`]),
|
|
86
|
+
false
|
|
87
|
+
);
|
|
88
|
+
// The indicator is meaningless without HMR, so it follows the master toggle.
|
|
89
|
+
const indicator =
|
|
90
|
+
hmrEnabled && indEnabled.value ? {count: indCount.value} : false;
|
|
91
|
+
const sources = {
|
|
92
|
+
hmrReconnect: reconnect.source,
|
|
93
|
+
hmrOnIncompatible: onIncompatible.source,
|
|
94
|
+
hmrIndicatorVisible: indEnabled.source,
|
|
95
|
+
hmrIndicatorCount: indCount.source,
|
|
96
|
+
};
|
|
97
|
+
const so = options.sourceOverlay;
|
|
98
|
+
const soExplicit =
|
|
99
|
+
typeof so === 'boolean' ? so : so === undefined ? undefined : true;
|
|
100
|
+
const soEnabled =
|
|
101
|
+
soExplicit ?? envBool(env[`${ENV_PREFIX}_SOURCE_OVERLAY`]) ?? false;
|
|
102
|
+
let sourceOverlay = false;
|
|
103
|
+
if (soEnabled) {
|
|
104
|
+
const base = typeof so === 'object' ? {...so} : {};
|
|
105
|
+
// Defaults for these are applied later (toFeatureSettings / the runtime),
|
|
106
|
+
// so only option-vs-env is decided here; neither set means 'default'.
|
|
107
|
+
const envKey = env[`${ENV_PREFIX}_SOURCE_OVERLAY_KEY`] || undefined;
|
|
108
|
+
const envThrottle = envNum(env[`${ENV_PREFIX}_SOURCE_OVERLAY_THROTTLE_MS`]);
|
|
109
|
+
// Only read (and warn about) the env editor when no option supplies one.
|
|
110
|
+
const envEditor =
|
|
111
|
+
base.editor === undefined
|
|
112
|
+
? envEnum(
|
|
113
|
+
env[`${ENV_PREFIX}_SOURCE_OVERLAY_EDITOR`],
|
|
114
|
+
EDITOR_KEYS,
|
|
115
|
+
`${ENV_PREFIX}_SOURCE_OVERLAY_EDITOR`
|
|
116
|
+
)
|
|
117
|
+
: undefined;
|
|
118
|
+
sources.sourceOverlayKey = sourceOf(base.key, envKey);
|
|
119
|
+
sources.sourceOverlayEditor = sourceOf(base.editor, envEditor);
|
|
120
|
+
sources.sourceOverlayThrottleMs = sourceOf(base.throttleMs, envThrottle);
|
|
121
|
+
base.key ??= envKey;
|
|
122
|
+
base.editor ??= envEditor;
|
|
123
|
+
base.throttleMs ??= envThrottle;
|
|
124
|
+
sourceOverlay = base;
|
|
125
|
+
}
|
|
126
|
+
const timeline =
|
|
127
|
+
options.timeline ?? envBool(env[`${ENV_PREFIX}_TIMELINE`]) ?? false;
|
|
128
|
+
const cssSheetBuild =
|
|
129
|
+
envEnum(options.cssSheetBuild, CSS_SHEET_BUILD_MODES, 'cssSheetBuild') ??
|
|
130
|
+
envEnum(
|
|
131
|
+
env[`${ENV_PREFIX}_CSS_SHEET_BUILD`],
|
|
132
|
+
CSS_SHEET_BUILD_MODES,
|
|
133
|
+
`${ENV_PREFIX}_CSS_SHEET_BUILD`
|
|
134
|
+
) ??
|
|
135
|
+
'auto';
|
|
136
|
+
return {
|
|
137
|
+
hmrEnabled,
|
|
138
|
+
reconnect: reconnect.value,
|
|
139
|
+
onIncompatible: onIncompatible.value,
|
|
140
|
+
indicator,
|
|
141
|
+
sourceOverlay,
|
|
142
|
+
timeline,
|
|
143
|
+
cssSheetBuild,
|
|
144
|
+
sources,
|
|
145
|
+
};
|
|
146
|
+
};
|
|
147
|
+
/**
|
|
148
|
+
* Flattens resolved options into the JSON-serializable shape the panel's
|
|
149
|
+
* Settings tab consumes (callback options like `exclude`/`onSelect` dropped;
|
|
150
|
+
* a custom editor object reported as `"custom"`). Default key/editor/throttle
|
|
151
|
+
* are applied here so the panel shows the effective values the runtime uses.
|
|
152
|
+
*/
|
|
153
|
+
export const toFeatureSettings = (r) => {
|
|
154
|
+
const so = r.sourceOverlay;
|
|
155
|
+
const editor = so === false ? undefined : so.editor;
|
|
156
|
+
return {
|
|
157
|
+
hmr: {
|
|
158
|
+
enabled: r.hmrEnabled,
|
|
159
|
+
reconnect: r.reconnect,
|
|
160
|
+
onIncompatible: r.onIncompatible,
|
|
161
|
+
indicatorEnabled: r.indicator !== false,
|
|
162
|
+
indicatorCount: r.indicator !== false && r.indicator.count,
|
|
163
|
+
},
|
|
164
|
+
sourceOverlay: {
|
|
165
|
+
enabled: so !== false,
|
|
166
|
+
key: (so === false ? undefined : so.key) ?? 's',
|
|
167
|
+
editor:
|
|
168
|
+
typeof editor === 'string' ? editor : editor ? 'custom' : 'vscode',
|
|
169
|
+
throttleMs: (so === false ? undefined : so.throttleMs) ?? 50,
|
|
170
|
+
},
|
|
171
|
+
timeline: r.timeline,
|
|
172
|
+
sources: {...r.sources},
|
|
173
|
+
};
|
|
174
|
+
};
|
|
175
|
+
//# sourceMappingURL=options.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"options.js","sourceRoot":"","sources":["../src/lib/options.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAQH,OAAO,EAAC,eAAe,EAAC,MAAM,qCAAqC,CAAC;AA6DpE,MAAM,qBAAqB,GAA6B;IACtD,MAAM;IACN,KAAK;IACL,QAAQ;IACR,YAAY;CACb,CAAC;AAmEF,8CAA8C;AAC9C,MAAM,CAAC,MAAM,UAAU,GAAG,YAAY,CAAC;AAEvC,MAAM,qBAAqB,GAAmC;IAC5D,QAAQ;IACR,MAAM;CACP,CAAC;AAEF,2EAA2E;AAC3E,MAAM,OAAO,GAAG,CAAC,CAAqB,EAAuB,EAAE,CAC7D,CAAC,KAAK,MAAM,IAAI,CAAC,KAAK,GAAG;IACvB,CAAC,CAAC,IAAI;IACN,CAAC,CAAC,CAAC,KAAK,OAAO,IAAI,CAAC,KAAK,GAAG;QAC1B,CAAC,CAAC,KAAK;QACP,CAAC,CAAC,SAAS,CAAC;AAElB,sEAAsE;AACtE,MAAM,MAAM,GAAG,CAAC,CAAqB,EAAsB,EAAE;IAC3D,IAAI,CAAC,KAAK,SAAS,IAAI,CAAC,KAAK,EAAE;QAAE,OAAO,SAAS,CAAC;IAClD,MAAM,CAAC,GAAG,MAAM,CAAC,CAAC,CAAC,CA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AU;YACrB,SAAS,EAAE,CAAC,CAAC,SAAS;YACtB,cAAc,EAAE,CAAC,CAAC,cAAc;YAChC,gBAAgB,EAAE,CAAC,CAAC,SAAS,KAAK,KAAK;YACvC,cAAc,EAAE,CAAC,CAAC,SAAS,KAAK,KAAK,IAAI,CAAC,CAAC,SAAS,CAAC,KAAK;SAC3D;QACD,aAAa,EAAE;YACb,OAAO,EAAE,EAAE,KAAK,KAAK;YACrB,GAAG,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,IAAI,GAAG;YAC/C,MAAM,EACJ,OAAO,MAAM,KAAK,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,QAAQ,CAAC,CAAC,CAAC,QAAQ;YACpE,UAAU,EAAE,CAAC,EAAE,KAAK,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,EAAE,CAAC,UAAU,CAAC,IAAI,EAAE;SAC7D;QACD,QAAQ,EAAE,CAAC,CAAC,QAAQ;QACpB,OAAO,EAAE,EAAC,GAAG,CAAC,CAAC,OAAO,EAAC;KACxB,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport type {SourceOverlayOptions} from './types.js';\nimport type {\n FeatureSettings,\n SettingSource,\n SettingSources,\n} from '../types/timeline.js';\nimport {BUILTIN_EDITORS} from './runtime/source-overlay/editors.js';\n\n/**\n * On-page HMR feedback: a small pulsing indicator in the corner of the host\n * page that briefly animates on each HMR update, for at-a-glance feedback\n * without watching the console.\n */\nexport interface HmrIndicatorOptions {\n /** Inject the indicator element. Defaults to `true` (when HMR is enabled). */\n enabled?: boolean;\n\n /**\n * Show a cumulative update count next to the dot (idle opacity 0.5 instead\n * of fully transparent). Defaults to `false`.\n */\n count?: boolean;\n}\n\n/**\n * HMR for Lit component classes and its on-page feedback.\n */\nexport interface HmrOptions {\n /**\n * Enable in-place HMR for Lit component classes. When `false`, the plugin\n * skips all HMR transforms and runtime injection. Defaults to `true`.\n */\n enabled?: boolean;\n\n /**\n * Cycle `disconnectedCallback()`/`connectedCallback()` on live instances\n * after a hot patch. Interning makes this mostly unnecessary, so it's\n * opt-in. Defaults to `false`.\n */\n reconnect?: boolean;\n\n /**\n * What to do when a component can't be hot-patched in place (e.g.\n * standard `accessor` decorators). Defaults to `'reload'`.\n */\n onIncompatible?: 'reload' | 'warn';\n\n /**\n * The on-page update indicator. `true` enables it without a count; an\n * object configures it. Forced off when HMR itself is disabled. Defaults\n * to enabled (without a count).\n */\n indicator?: boolean | HmrIndicatorOptions;\n}\n\n/**\n * What a `?css-sheet` import compiles to under `vite build`.\n *\n * - `'url'`: fetch-backed sheet over the emitted `.css` asset.\n * - `'inline'`: css text embedded in the JS chunk, processed by the css\n * pipeline (`?inline`).\n * - `'inline-raw'`: css text embedded verbatim, skipping the css pipeline\n * (`?raw`).\n * - `'auto'`: `'inline'` when `build.lib` is set, `'url'` otherwise.\n */\nexport type CssSheetBuild = 'auto' | 'url' | 'inline' | 'inline-raw';\n\nconst CSS_SHEET_BUILD_MODES: readonly CssSheetBuild[] = [\n 'auto',\n 'url',\n 'inline',\n 'inline-raw',\n];\n\n/**\n * Options for the Lit Vite plugin.\n *\n * Every option also resolves from environment variables (and `.env` files)\n * with the `LIT_PLUGIN` prefix — e.g. `LIT_PLUGIN_HMR_INDICATOR=true`. Options\n * passed here take precedence over env vars, which take precedence over the\n * built-in defaults.\n */\nexport interface LitPluginOptions {\n /**\n * HMR for Lit components and its on-page feedback. `true`/`false` toggles\n * the whole feature (patching and indicator); an object configures it.\n * Defaults to enabled.\n */\n hmr?: boolean | HmrOptions;\n\n /**\n * Dev-only click-to-open-in-IDE inspector for Lit custom elements.\n * Toggle with Ctrl+Shift+S (configurable via `key`). Defaults to `false`.\n */\n sourceOverlay?: boolean | SourceOverlayOptions;\n\n /**\n * Vite DevTools Timeline panel — a Vue DevTools–style layered event stream\n * for Lit lifecycle, render, mouse, and keyboard events.\n *\n * Requires `@vitejs/devtools` in the Vite config and the `@vitejs/devtools`\n * Vite plugin (`DevTools()`) to be active. Defaults to `false` while\n * experimental.\n *\n * `true` enables all built-in layers with defaults.\n */\n timeline?: boolean;\n\n /**\n * What a `?css-sheet` import compiles to under `vite build`.\n * - `'url'`: fetch-backed sheet over the emitted `.css` asset\n * - `'inline'`: css text embedded in the JS chunk, processed by the css\n * pipeline (`?inline`)\n * - `'inline-raw'`: css text embedded verbatim, skipping the css pipeline\n * (`?raw`)\n * - `'auto'`: `'inline'` when `build.lib` is set, `'url'` otherwise\n *\n * Dev is always the fetch-backed HMR form regardless of this setting.\n * Defaults to `'auto'`.\n */\n cssSheetBuild?: CssSheetBuild;\n}\n\n/** Plugin options after merging explicit options, env vars, and defaults. */\nexport interface ResolvedOptions {\n hmrEnabled: boolean;\n reconnect: boolean;\n onIncompatible: 'reload' | 'warn';\n indicator: false | {count: boolean};\n sourceOverlay: false | SourceOverlayOptions;\n timeline: boolean;\n cssSheetBuild: CssSheetBuild;\n /**\n * Which layer each panel-visible setting came from. Source-overlay keys are\n * present only when the overlay is enabled.\n */\n sources: SettingSources;\n}\n\n/** Env var prefix consumed at config time. */\nexport const ENV_PREFIX = 'LIT_PLUGIN';\n\nconst ON_INCOMPATIBLE_MODES: readonly ('reload' | 'warn')[] = [\n 'reload',\n 'warn',\n];\n\n/** Parse a boolean-ish env string; `undefined` when unset/unrecognized. */\nconst envBool = (v: string | undefined): boolean | undefined =>\n v === 'true' || v === '1'\n ? true\n : v === 'false' || v === '0'\n ? false\n : undefined;\n\n/** Parse a numeric env string; `undefined` when unset/non-numeric. */\nconst envNum = (v: string | undefined): number | undefined => {\n if (v === undefined || v === '') return undefined;\n const n = Number(v);\n return Number.isNaN(n) ? undefined : n;\n};\n\n/**\n * Parse a string against a closed set of values; `undefined` (with a warning)\n * when set to something outside it, so a typo falls back to the default\n * instead of silently disabling a feature.\n */\nconst envEnum = <T extends string>(\n v: string | undefined,\n allowed: readonly T[],\n source: string\n): T | undefined => {\n if (v === undefined || v === '') return undefined;\n if ((allowed as readonly string[]).includes(v)) return v as T;\n console.warn(\n `[lit-plugin] ignoring ${source}=${JSON.stringify(v)}; expected one of ` +\n allowed.map((a) => JSON.stringify(a)).join(', ')\n );\n return undefined;\n};\n\n/** Keys a `LIT_PLUGIN_SOURCE_OVERLAY_EDITOR` value may name. */\nconst EDITOR_KEYS: readonly string[] = Object.keys(BUILTIN_EDITORS);\n\n/** Which layer supplied a value: the first of option, env that is defined. */\nconst sourceOf = (option: unknown, env: unknown): SettingSource =>\n option !== undefined ? 'option' : env !== undefined ? 'env' : 'default';\n\n/**\n * Take the first defined of an explicit option and an env value, else the\n * default, and record which layer won.\n */\nconst pick = <T>(\n option: T | undefined,\n env: T | undefined,\n fallback: T\n): {value: T; source: SettingSource} => ({\n value: option ?? env ?? fallback,\n source: sourceOf(option, env),\n});\n\n/**\n * Merge explicit options over env vars over defaults (in that precedence) into\n * the flat shape the plugin hooks consume.\n */\nexport const resolveOptions = (\n options: LitPluginOptions,\n env: Record<string, string>\n): ResolvedOptions => {\n const hmr = options.hmr;\n const hmrObj = typeof hmr === 'object' ? hmr : undefined;\n const hmrEnabled =\n (typeof hmr === 'boolean' ? hmr : hmrObj?.enabled) ??\n envBool(env[`${ENV_PREFIX}_HMR`]) ??\n true;\n const reconnect = pick(\n hmrObj?.reconnect,\n envBool(env[`${ENV_PREFIX}_HMR_RECONNECT`]),\n false\n );\n const onIncompatible = pick<'reload' | 'warn'>(\n hmrObj?.onIncompatible,\n envEnum(\n env[`${ENV_PREFIX}_HMR_ON_INCOMPATIBLE`],\n ON_INCOMPATIBLE_MODES,\n `${ENV_PREFIX}_HMR_ON_INCOMPATIBLE`\n ),\n 'reload'\n );\n\n const ind = hmrObj?.indicator;\n const indObj = typeof ind === 'object' ? ind : undefined;\n const indEnabled = pick(\n typeof ind === 'boolean' ? ind : indObj?.enabled,\n envBool(env[`${ENV_PREFIX}_HMR_INDICATOR`]),\n true\n );\n const indCount = pick(\n indObj?.count,\n envBool(env[`${ENV_PREFIX}_HMR_INDICATOR_COUNT`]),\n false\n );\n // The indicator is meaningless without HMR, so it follows the master toggle.\n const indicator =\n hmrEnabled && indEnabled.value ? {count: indCount.value} : false;\n\n const sources: SettingSources = {\n hmrReconnect: reconnect.source,\n hmrOnIncompatible: onIncompatible.source,\n hmrIndicatorVisible: indEnabled.source,\n hmrIndicatorCount: indCount.source,\n };\n\n const so = options.sourceOverlay;\n const soExplicit =\n typeof so === 'boolean' ? so : so === undefined ? undefined : true;\n const soEnabled =\n soExplicit ?? envBool(env[`${ENV_PREFIX}_SOURCE_OVERLAY`]) ?? false;\n let sourceOverlay: false | SourceOverlayOptions = false;\n if (soEnabled) {\n const base: SourceOverlayOptions = typeof so === 'object' ? {...so} : {};\n // Defaults for these are applied later (toFeatureSettings / the runtime),\n // so only option-vs-env is decided here; neither set means 'default'.\n const envKey = env[`${ENV_PREFIX}_SOURCE_OVERLAY_KEY`] || undefined;\n const envThrottle = envNum(env[`${ENV_PREFIX}_SOURCE_OVERLAY_THROTTLE_MS`]);\n // Only read (and warn about) the env editor when no option supplies one.\n const envEditor =\n base.editor === undefined\n ? envEnum(\n env[`${ENV_PREFIX}_SOURCE_OVERLAY_EDITOR`],\n EDITOR_KEYS,\n `${ENV_PREFIX}_SOURCE_OVERLAY_EDITOR`\n )\n : undefined;\n sources.sourceOverlayKey = sourceOf(base.key, envKey);\n sources.sourceOverlayEditor = sourceOf(base.editor, envEditor);\n sources.sourceOverlayThrottleMs = sourceOf(base.throttleMs, envThrottle);\n base.key ??= envKey;\n base.editor ??= envEditor;\n base.throttleMs ??= envThrottle;\n sourceOverlay = base;\n }\n\n const timeline =\n options.timeline ?? envBool(env[`${ENV_PREFIX}_TIMELINE`]) ?? false;\n\n const cssSheetBuild =\n envEnum(options.cssSheetBuild, CSS_SHEET_BUILD_MODES, 'cssSheetBuild') ??\n envEnum(\n env[`${ENV_PREFIX}_CSS_SHEET_BUILD`],\n CSS_SHEET_BUILD_MODES,\n `${ENV_PREFIX}_CSS_SHEET_BUILD`\n ) ??\n 'auto';\n\n return {\n hmrEnabled,\n reconnect: reconnect.value,\n onIncompatible: onIncompatible.value,\n indicator,\n sourceOverlay,\n timeline,\n cssSheetBuild,\n sources,\n };\n};\n\n/**\n * Flattens resolved options into the JSON-serializable shape the panel's\n * Settings tab consumes (callback options like `exclude`/`onSelect` dropped;\n * a custom editor object reported as `\"custom\"`). Default key/editor/throttle\n * are applied here so the panel shows the effective values the runtime uses.\n */\nexport const toFeatureSettings = (r: ResolvedOptions): FeatureSettings => {\n const so = r.sourceOverlay;\n const editor = so === false ? undefined : so.editor;\n return {\n hmr: {\n enabled: r.hmrEnabled,\n reconnect: r.reconnect,\n onIncompatible: r.onIncompatible,\n indicatorEnabled: r.indicator !== false,\n indicatorCount: r.indicator !== false && r.indicator.count,\n },\n sourceOverlay: {\n enabled: so !== false,\n key: (so === false ? undefined : so.key) ?? 's',\n editor:\n typeof editor === 'string' ? editor : editor ? 'custom' : 'vscode',\n throttleMs: (so === false ? undefined : so.throttleMs) ?? 50,\n },\n timeline: r.timeline,\n sources: {...r.sources},\n };\n};\n"]}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
import type { OverrideBaselines } from '../types/timeline.js';
|
|
7
|
+
/**
|
|
8
|
+
* Whether the config value an override was made against has since changed.
|
|
9
|
+
*
|
|
10
|
+
* `recorded` is `undefined` for a legacy override that predates baseline
|
|
11
|
+
* tracking, which never counts as a change (no false positives). Values are
|
|
12
|
+
* compared structurally. The source-overlay editor reports `'custom'` for an
|
|
13
|
+
* `EditorConfig` object, which can't be compared meaningfully, so any side
|
|
14
|
+
* being `'custom'` skips the check.
|
|
15
|
+
*/
|
|
16
|
+
export declare const baselineChanged: (key: keyof OverrideBaselines, recorded: unknown, current: unknown) => boolean;
|
|
17
|
+
//# sourceMappingURL=override-baselines.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"override-baselines.d.ts","sourceRoot":"","sources":["../src/lib/override-baselines.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,KAAK,EAAC,iBAAiB,EAAC,MAAM,sBAAsB,CAAC;AAE5D;;;;;;;;GAQG;AACH,eAAO,MAAM,eAAe,QACrB,MAAM,iBAAiB,YAClB,OAAO,WACR,OAAO,KACf,OASF,CAAC"}
|
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @license
|
|
3
|
+
* Copyright 2026 Google LLC
|
|
4
|
+
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
+
*/
|
|
6
|
+
/**
|
|
7
|
+
* Whether the config value an override was made against has since changed.
|
|
8
|
+
*
|
|
9
|
+
* `recorded` is `undefined` for a legacy override that predates baseline
|
|
10
|
+
* tracking, which never counts as a change (no false positives). Values are
|
|
11
|
+
* compared structurally. The source-overlay editor reports `'custom'` for an
|
|
12
|
+
* `EditorConfig` object, which can't be compared meaningfully, so any side
|
|
13
|
+
* being `'custom'` skips the check.
|
|
14
|
+
*/
|
|
15
|
+
export const baselineChanged = (key, recorded, current) => {
|
|
16
|
+
if (recorded === undefined || current === undefined) return false;
|
|
17
|
+
if (
|
|
18
|
+
key === 'sourceOverlayEditor' &&
|
|
19
|
+
(recorded === 'custom' || current === 'custom')
|
|
20
|
+
) {
|
|
21
|
+
return false;
|
|
22
|
+
}
|
|
23
|
+
return JSON.stringify(recorded) !== JSON.stringify(current);
|
|
24
|
+
};
|
|
25
|
+
//# sourceMappingURL=override-baselines.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"override-baselines.js","sourceRoot":"","sources":["../src/lib/override-baselines.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAIH;;;;;;;;GAQG;AACH,MAAM,CAAC,MAAM,eAAe,GAAG,CAC7B,GAA4B,EAC5B,QAAiB,EACjB,OAAgB,EACP,EAAE;IACX,IAAI,QAAQ,KAAK,SAAS,IAAI,OAAO,KAAK,SAAS;QAAE,OAAO,KAAK,CAAC;IAClE,IACE,GAAG,KAAK,qBAAqB;QAC7B,CAAC,QAAQ,KAAK,QAAQ,IAAI,OAAO,KAAK,QAAQ,CAAC,EAC/C,CAAC;QACD,OAAO,KAAK,CAAC;IACf,CAAC;IACD,OAAO,IAAI,CAAC,SAAS,CAAC,QAAQ,CAAC,KAAK,IAAI,CAAC,SAAS,CAAC,OAAO,CAAC,CAAC;AAC9D,CAAC,CAAC","sourcesContent":["/**\n * @license\n * Copyright 2026 Google LLC\n * SPDX-License-Identifier: BSD-3-Clause\n */\n\nimport type {OverrideBaselines} from '../types/timeline.js';\n\n/**\n * Whether the config value an override was made against has since changed.\n *\n * `recorded` is `undefined` for a legacy override that predates baseline\n * tracking, which never counts as a change (no false positives). Values are\n * compared structurally. The source-overlay editor reports `'custom'` for an\n * `EditorConfig` object, which can't be compared meaningfully, so any side\n * being `'custom'` skips the check.\n */\nexport const baselineChanged = (\n key: keyof OverrideBaselines,\n recorded: unknown,\n current: unknown\n): boolean => {\n if (recorded === undefined || current === undefined) return false;\n if (\n key === 'sourceOverlayEditor' &&\n (recorded === 'custom' || current === 'custom')\n ) {\n return false;\n }\n return JSON.stringify(recorded) !== JSON.stringify(current);\n};\n"]}
|
package/lib/plugin.d.ts
CHANGED
|
@@ -4,154 +4,12 @@
|
|
|
4
4
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
5
|
*/
|
|
6
6
|
import { type Plugin } from 'vite';
|
|
7
|
-
import { type
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
*/
|
|
14
|
-
export interface HmrIndicatorOptions {
|
|
15
|
-
/** Inject the indicator element. Defaults to `true` (when HMR is enabled). */
|
|
16
|
-
enabled?: boolean;
|
|
17
|
-
/**
|
|
18
|
-
* Show a cumulative update count next to the dot (idle opacity 0.5 instead
|
|
19
|
-
* of fully transparent). Defaults to `false`.
|
|
20
|
-
*/
|
|
21
|
-
count?: boolean;
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* HMR for Lit component classes and its on-page feedback.
|
|
25
|
-
*/
|
|
26
|
-
export interface HmrOptions {
|
|
27
|
-
/**
|
|
28
|
-
* Enable in-place HMR for Lit component classes. When `false`, the plugin
|
|
29
|
-
* skips all HMR transforms and runtime injection. Defaults to `true`.
|
|
30
|
-
*/
|
|
31
|
-
enabled?: boolean;
|
|
32
|
-
/**
|
|
33
|
-
* Cycle `disconnectedCallback()`/`connectedCallback()` on live instances
|
|
34
|
-
* after a hot patch. Interning makes this mostly unnecessary, so it's
|
|
35
|
-
* opt-in. Defaults to `false`.
|
|
36
|
-
*/
|
|
37
|
-
reconnect?: boolean;
|
|
38
|
-
/**
|
|
39
|
-
* What to do when a component can't be hot-patched in place (e.g.
|
|
40
|
-
* standard `accessor` decorators). Defaults to `'reload'`.
|
|
41
|
-
*/
|
|
42
|
-
onIncompatible?: 'reload' | 'warn';
|
|
43
|
-
/**
|
|
44
|
-
* The on-page update indicator. `true` enables it without a count; an
|
|
45
|
-
* object configures it. Forced off when HMR itself is disabled. Defaults
|
|
46
|
-
* to enabled (without a count).
|
|
47
|
-
*/
|
|
48
|
-
indicator?: boolean | HmrIndicatorOptions;
|
|
49
|
-
}
|
|
50
|
-
/**
|
|
51
|
-
* What a `?css-sheet` import compiles to under `vite build`.
|
|
52
|
-
*
|
|
53
|
-
* - `'url'`: fetch-backed sheet over the emitted `.css` asset.
|
|
54
|
-
* - `'inline'`: css text embedded in the JS chunk, processed by the css
|
|
55
|
-
* pipeline (`?inline`).
|
|
56
|
-
* - `'inline-raw'`: css text embedded verbatim, skipping the css pipeline
|
|
57
|
-
* (`?raw`).
|
|
58
|
-
* - `'auto'`: `'inline'` when `build.lib` is set, `'url'` otherwise.
|
|
59
|
-
*/
|
|
60
|
-
export type CssSheetBuild = 'auto' | 'url' | 'inline' | 'inline-raw';
|
|
61
|
-
/**
|
|
62
|
-
* Options for the Lit Vite plugin.
|
|
63
|
-
*
|
|
64
|
-
* Every option also resolves from environment variables (and `.env` files)
|
|
65
|
-
* with the `LIT_PLUGIN` prefix — e.g. `LIT_PLUGIN_HMR_INDICATOR=true`. Options
|
|
66
|
-
* passed here take precedence over env vars, which take precedence over the
|
|
67
|
-
* built-in defaults.
|
|
68
|
-
*/
|
|
69
|
-
export interface LitPluginOptions {
|
|
70
|
-
/**
|
|
71
|
-
* HMR for Lit components and its on-page feedback. `true`/`false` toggles
|
|
72
|
-
* the whole feature (patching and indicator); an object configures it.
|
|
73
|
-
* Defaults to enabled.
|
|
74
|
-
*/
|
|
75
|
-
hmr?: boolean | HmrOptions;
|
|
76
|
-
/**
|
|
77
|
-
* Dev-only click-to-open-in-IDE inspector for Lit custom elements.
|
|
78
|
-
* Toggle with Ctrl+Shift+S (configurable via `key`). Defaults to `false`.
|
|
79
|
-
*/
|
|
80
|
-
sourceOverlay?: boolean | SourceOverlayOptions;
|
|
81
|
-
/**
|
|
82
|
-
* Vite DevTools Timeline panel — a Vue DevTools–style layered event stream
|
|
83
|
-
* for Lit lifecycle, render, mouse, and keyboard events.
|
|
84
|
-
*
|
|
85
|
-
* Requires `@vitejs/devtools` in the Vite config and the `@vitejs/devtools`
|
|
86
|
-
* Vite plugin (`DevTools()`) to be active. Defaults to `false` while
|
|
87
|
-
* experimental.
|
|
88
|
-
*
|
|
89
|
-
* `true` enables all built-in layers with defaults.
|
|
90
|
-
*/
|
|
91
|
-
timeline?: boolean;
|
|
92
|
-
/**
|
|
93
|
-
* What a `?css-sheet` import compiles to under `vite build`.
|
|
94
|
-
* - `'url'`: fetch-backed sheet over the emitted `.css` asset
|
|
95
|
-
* - `'inline'`: css text embedded in the JS chunk, processed by the css
|
|
96
|
-
* pipeline (`?inline`)
|
|
97
|
-
* - `'inline-raw'`: css text embedded verbatim, skipping the css pipeline
|
|
98
|
-
* (`?raw`)
|
|
99
|
-
* - `'auto'`: `'inline'` when `build.lib` is set, `'url'` otherwise
|
|
100
|
-
*
|
|
101
|
-
* Dev is always the fetch-backed HMR form regardless of this setting.
|
|
102
|
-
* Defaults to `'auto'`.
|
|
103
|
-
*/
|
|
104
|
-
cssSheetBuild?: CssSheetBuild;
|
|
105
|
-
}
|
|
106
|
-
/** Plugin options after merging explicit options, env vars, and defaults. */
|
|
107
|
-
export interface ResolvedOptions {
|
|
108
|
-
hmrEnabled: boolean;
|
|
109
|
-
reconnect: boolean;
|
|
110
|
-
onIncompatible: 'reload' | 'warn';
|
|
111
|
-
indicator: false | {
|
|
112
|
-
count: boolean;
|
|
113
|
-
};
|
|
114
|
-
sourceOverlay: false | SourceOverlayOptions;
|
|
115
|
-
timeline: boolean;
|
|
116
|
-
cssSheetBuild: CssSheetBuild;
|
|
117
|
-
}
|
|
118
|
-
/**
|
|
119
|
-
* Merge explicit options over env vars over defaults (in that precedence) into
|
|
120
|
-
* the flat shape the plugin hooks consume.
|
|
121
|
-
*/
|
|
122
|
-
export declare const resolveOptions: (options: LitPluginOptions, env: Record<string, string>) => ResolvedOptions;
|
|
123
|
-
export declare const createOpenInEditorMiddleware: (allowedRoots: readonly string[]) => (req: {
|
|
124
|
-
url?: string;
|
|
125
|
-
method?: string;
|
|
126
|
-
headers?: TrustHeaders;
|
|
127
|
-
}, res: {
|
|
128
|
-
statusCode: number;
|
|
129
|
-
end: (msg: string) => void;
|
|
130
|
-
}, next: (err?: unknown) => void) => void;
|
|
131
|
-
/**
|
|
132
|
-
* Import-query support, served in dev and build alike (source code using
|
|
133
|
-
* `?hmr-url`/`?css-sheet` must keep working under `vite build`, where the HMR
|
|
134
|
-
* plugin doesn't apply). Exported for the baseline e2e run, which needs the
|
|
135
|
-
* queries working without the HMR plugin.
|
|
136
|
-
*
|
|
137
|
-
* `getCssSheetBuild` is a getter, not a value: `litPlugin()` re-resolves its
|
|
138
|
-
* options against the loaded env in a `config` hook, which runs after the
|
|
139
|
-
* plugin array is built. Standalone (no getter) it behaves like the `'auto'`
|
|
140
|
-
* default.
|
|
141
|
-
*/
|
|
142
|
-
export declare const litCssQueries: (getCssSheetBuild?: () => CssSheetBuild) => Plugin;
|
|
143
|
-
/**
|
|
144
|
-
* The public timeline API virtual module, served in dev and build alike:
|
|
145
|
-
* app code importing it must keep building under `vite build`, where the HMR
|
|
146
|
-
* plugin doesn't apply. While these hooks lived on that serve-only plugin,
|
|
147
|
-
* nothing claimed the specifier during a build and the bundler failed to
|
|
148
|
-
* resolve it.
|
|
149
|
-
*
|
|
150
|
-
* `getTimeline` is a getter, not a value: `litPlugin()` re-resolves its
|
|
151
|
-
* options against the loaded env in a `config` hook, which runs after the
|
|
152
|
-
* plugin array is built.
|
|
153
|
-
*/
|
|
154
|
-
export declare const litTimelineVirtual: (getTimeline?: () => boolean) => Plugin;
|
|
7
|
+
import { type LitPluginOptions } from './options.js';
|
|
8
|
+
export { createOpenInEditorMiddleware } from './plugins/open-in-editor.js';
|
|
9
|
+
export { litCssQueries } from './plugins/css-queries.js';
|
|
10
|
+
export { litTimelineVirtual } from './plugins/timeline-virtual.js';
|
|
11
|
+
export type { HmrIndicatorOptions, HmrOptions, CssSheetBuild, LitPluginOptions, ResolvedOptions, } from './options.js';
|
|
12
|
+
export { resolveOptions } from './options.js';
|
|
155
13
|
/**
|
|
156
14
|
* Vite plugin set providing HMR, CSS helpers, and Lightning CSS processing
|
|
157
15
|
* for Lit projects.
|
package/lib/plugin.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/lib/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;
|
|
1
|
+
{"version":3,"file":"plugin.d.ts","sourceRoot":"","sources":["../src/lib/plugin.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAGH,OAAO,EAAU,KAAK,MAAM,EAAC,MAAM,MAAM,CAAC;AAO1C,OAAO,EAEL,KAAK,gBAAgB,EAItB,MAAM,cAAc,CAAC;AAUtB,OAAO,EAAC,4BAA4B,EAAC,MAAM,6BAA6B,CAAC;AACzE,OAAO,EAAC,aAAa,EAAC,MAAM,0BAA0B,CAAC;AACvD,OAAO,EAAC,kBAAkB,EAAC,MAAM,+BAA+B,CAAC;AACjE,YAAY,EACV,mBAAmB,EACnB,UAAU,EACV,aAAa,EACb,gBAAgB,EAChB,eAAe,GAChB,MAAM,cAAc,CAAC;AACtB,OAAO,EAAC,cAAc,EAAC,MAAM,cAAc,CAAC;AAE5C;;;GAGG;AACH,eAAO,MAAM,SAAS,aAAa,gBAAgB,KAAQ,MAAM,EAuRhE,CAAC"}
|