@oddsquad/vite-plugin-lit 0.6.1 → 0.8.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 +68 -0
- package/LICENSE +1 -1
- package/README.md +40 -17
- package/bin.mjs +89 -13
- package/client.d.ts +0 -6
- package/dist/client/assets/{browser-agent-rpc-BXhoSh1z-F2EfZsFX.js → browser-agent-rpc-BXhoSh1z-ybEeG-x9.js} +2 -2
- package/dist/client/assets/{browser-agent-rpc-BXhoSh1z-F2EfZsFX.js.map → browser-agent-rpc-BXhoSh1z-ybEeG-x9.js.map} +1 -1
- package/dist/client/assets/{index-B2HYO7lk.js → index-CgkhETVR.js} +22 -145
- package/dist/client/assets/index-CgkhETVR.js.map +1 -0
- package/dist/client/index.html +1 -1
- package/dist/standalone/lit-devtools.js +6717 -0
- package/index.d.ts +0 -5
- package/index.d.ts.map +1 -1
- package/index.js +1 -5
- package/index.js.map +1 -1
- package/lib/color-scheme.d.ts +0 -5
- package/lib/color-scheme.d.ts.map +1 -1
- package/lib/color-scheme.js +0 -5
- package/lib/color-scheme.js.map +1 -1
- package/lib/confine.d.ts +0 -5
- package/lib/confine.d.ts.map +1 -1
- package/lib/confine.js +0 -5
- package/lib/confine.js.map +1 -1
- package/lib/devframe/allowed-origins.d.ts +21 -0
- package/lib/devframe/allowed-origins.d.ts.map +1 -0
- package/lib/devframe/allowed-origins.js +58 -0
- package/lib/devframe/allowed-origins.js.map +1 -0
- package/lib/devframe/definition.d.ts +7 -3
- package/lib/devframe/definition.d.ts.map +1 -1
- package/lib/devframe/definition.js +1 -6
- package/lib/devframe/definition.js.map +1 -1
- package/lib/devframe/icon.d.ts +0 -5
- package/lib/devframe/icon.d.ts.map +1 -1
- package/lib/devframe/icon.js +0 -5
- package/lib/devframe/icon.js.map +1 -1
- package/lib/devframe/launch-editor.d.ts +0 -5
- package/lib/devframe/launch-editor.d.ts.map +1 -1
- package/lib/devframe/launch-editor.js +0 -5
- package/lib/devframe/launch-editor.js.map +1 -1
- package/lib/devframe/paths.d.ts +8 -3
- package/lib/devframe/paths.d.ts.map +1 -1
- package/lib/devframe/paths.js +0 -5
- package/lib/devframe/paths.js.map +1 -1
- package/lib/devframe/protocol.d.ts +6 -3
- package/lib/devframe/protocol.d.ts.map +1 -1
- package/lib/devframe/protocol.js +0 -5
- package/lib/devframe/protocol.js.map +1 -1
- package/lib/devframe/rpc-source.d.ts +15 -3
- package/lib/devframe/rpc-source.d.ts.map +1 -1
- package/lib/devframe/rpc-source.js +0 -5
- package/lib/devframe/rpc-source.js.map +1 -1
- package/lib/devframe/source.d.ts +0 -5
- package/lib/devframe/source.d.ts.map +1 -1
- package/lib/devframe/source.js +7 -3
- package/lib/devframe/source.js.map +1 -1
- package/lib/devframe/vite.d.ts +0 -5
- package/lib/devframe/vite.d.ts.map +1 -1
- package/lib/devframe/vite.js +16 -3
- package/lib/devframe/vite.js.map +1 -1
- package/lib/http.d.ts +0 -5
- package/lib/http.d.ts.map +1 -1
- package/lib/http.js +0 -5
- package/lib/http.js.map +1 -1
- package/lib/icons.d.ts +0 -5
- package/lib/icons.d.ts.map +1 -1
- package/lib/icons.js +0 -5
- package/lib/icons.js.map +1 -1
- package/lib/options.d.ts +26 -5
- package/lib/options.d.ts.map +1 -1
- package/lib/options.js +19 -5
- package/lib/options.js.map +1 -1
- package/lib/override-baselines.d.ts +0 -5
- package/lib/override-baselines.d.ts.map +1 -1
- package/lib/override-baselines.js +0 -5
- package/lib/override-baselines.js.map +1 -1
- package/lib/plugin.d.ts +0 -5
- package/lib/plugin.d.ts.map +1 -1
- package/lib/plugin.js +3 -5
- package/lib/plugin.js.map +1 -1
- package/lib/plugins/css-literals.d.ts +0 -5
- package/lib/plugins/css-literals.d.ts.map +1 -1
- package/lib/plugins/css-literals.js +0 -5
- package/lib/plugins/css-literals.js.map +1 -1
- package/lib/plugins/css-queries.d.ts +0 -5
- package/lib/plugins/css-queries.d.ts.map +1 -1
- package/lib/plugins/css-queries.js +0 -5
- package/lib/plugins/css-queries.js.map +1 -1
- package/lib/plugins/open-in-editor.d.ts +0 -5
- package/lib/plugins/open-in-editor.d.ts.map +1 -1
- package/lib/plugins/open-in-editor.js +0 -5
- package/lib/plugins/open-in-editor.js.map +1 -1
- package/lib/plugins/private-fields.d.ts +22 -0
- package/lib/plugins/private-fields.d.ts.map +1 -0
- package/lib/plugins/private-fields.js +254 -0
- package/lib/plugins/private-fields.js.map +1 -0
- package/lib/plugins/shared.d.ts +0 -5
- package/lib/plugins/shared.d.ts.map +1 -1
- package/lib/plugins/shared.js +0 -5
- package/lib/plugins/shared.js.map +1 -1
- package/lib/plugins/timeline-virtual.d.ts +0 -5
- package/lib/plugins/timeline-virtual.d.ts.map +1 -1
- package/lib/plugins/timeline-virtual.js +0 -5
- package/lib/plugins/timeline-virtual.js.map +1 -1
- package/lib/runtime/child-state.d.ts +95 -0
- package/lib/runtime/child-state.d.ts.map +1 -0
- package/lib/runtime/child-state.js +461 -0
- package/lib/runtime/child-state.js.map +1 -0
- package/lib/runtime/css.d.ts +14 -3
- package/lib/runtime/css.d.ts.map +1 -1
- package/lib/runtime/css.js +3 -5
- package/lib/runtime/css.js.map +1 -1
- package/lib/runtime/edge-panel.d.ts +8 -3
- package/lib/runtime/edge-panel.d.ts.map +1 -1
- package/lib/runtime/edge-panel.js +0 -5
- package/lib/runtime/edge-panel.js.map +1 -1
- package/lib/runtime/fonts.d.ts +0 -5
- package/lib/runtime/fonts.d.ts.map +1 -1
- package/lib/runtime/fonts.js +0 -5
- package/lib/runtime/fonts.js.map +1 -1
- package/lib/runtime/indicator.d.ts +3 -3
- package/lib/runtime/indicator.js +0 -5
- package/lib/runtime/indicator.js.map +1 -1
- package/lib/runtime/inspector/collect.d.ts +3 -3
- package/lib/runtime/inspector/collect.d.ts.map +1 -1
- package/lib/runtime/inspector/collect.js +0 -5
- package/lib/runtime/inspector/collect.js.map +1 -1
- package/lib/runtime/inspector/highlight.d.ts +10 -3
- package/lib/runtime/inspector/highlight.d.ts.map +1 -1
- package/lib/runtime/inspector/highlight.js +0 -5
- package/lib/runtime/inspector/highlight.js.map +1 -1
- package/lib/runtime/inspector/install.d.ts +6 -3
- package/lib/runtime/inspector/install.d.ts.map +1 -1
- package/lib/runtime/inspector/install.js +4 -6
- package/lib/runtime/inspector/install.js.map +1 -1
- package/lib/runtime/inspector/serialize.d.ts +4 -3
- package/lib/runtime/inspector/serialize.d.ts.map +1 -1
- package/lib/runtime/inspector/serialize.js +0 -5
- package/lib/runtime/inspector/serialize.js.map +1 -1
- package/lib/runtime/intern.d.ts +11 -3
- package/lib/runtime/intern.d.ts.map +1 -1
- package/lib/runtime/intern.js +11 -3
- package/lib/runtime/intern.js.map +1 -1
- package/lib/runtime/overrides.d.ts +3 -3
- package/lib/runtime/overrides.d.ts.map +1 -1
- package/lib/runtime/overrides.js +0 -5
- package/lib/runtime/overrides.js.map +1 -1
- package/lib/runtime/page-channel.d.ts +0 -5
- package/lib/runtime/page-channel.d.ts.map +1 -1
- package/lib/runtime/page-channel.js +13 -3
- package/lib/runtime/page-channel.js.map +1 -1
- package/lib/runtime/patch.d.ts +22 -3
- package/lib/runtime/patch.d.ts.map +1 -1
- package/lib/runtime/patch.js +22 -6
- package/lib/runtime/patch.js.map +1 -1
- package/lib/runtime/rpc-transport.d.ts +21 -3
- package/lib/runtime/rpc-transport.d.ts.map +1 -1
- package/lib/runtime/rpc-transport.js +4 -5
- package/lib/runtime/rpc-transport.js.map +1 -1
- package/lib/runtime/source-meta.d.ts +0 -5
- package/lib/runtime/source-meta.d.ts.map +1 -1
- package/lib/runtime/source-meta.js +0 -5
- package/lib/runtime/source-meta.js.map +1 -1
- package/lib/runtime/source-overlay/editors.d.ts +0 -5
- package/lib/runtime/source-overlay/editors.d.ts.map +1 -1
- package/lib/runtime/source-overlay/editors.js +9 -9
- package/lib/runtime/source-overlay/editors.js.map +1 -1
- package/lib/runtime/source-overlay/mask-path.d.ts +0 -5
- package/lib/runtime/source-overlay/mask-path.d.ts.map +1 -1
- package/lib/runtime/source-overlay/mask-path.js +0 -5
- package/lib/runtime/source-overlay/mask-path.js.map +1 -1
- package/lib/runtime/source-overlay/overlay-element.d.ts +0 -5
- package/lib/runtime/source-overlay/overlay-element.d.ts.map +1 -1
- package/lib/runtime/source-overlay/overlay-element.js +0 -5
- package/lib/runtime/source-overlay/overlay-element.js.map +1 -1
- package/lib/runtime/source-overlay/source-host.d.ts +0 -5
- package/lib/runtime/source-overlay/source-host.d.ts.map +1 -1
- package/lib/runtime/source-overlay/source-host.js +0 -5
- package/lib/runtime/source-overlay/source-host.js.map +1 -1
- package/lib/runtime/source-overlay/template.d.ts +0 -5
- package/lib/runtime/source-overlay/template.d.ts.map +1 -1
- package/lib/runtime/source-overlay/template.js +0 -5
- package/lib/runtime/source-overlay/template.js.map +1 -1
- package/lib/runtime/source-overlay.d.ts +0 -5
- package/lib/runtime/source-overlay.d.ts.map +1 -1
- package/lib/runtime/source-overlay.js +0 -5
- package/lib/runtime/source-overlay.js.map +1 -1
- package/lib/runtime/standalone.d.ts +22 -0
- package/lib/runtime/standalone.d.ts.map +1 -0
- package/lib/runtime/standalone.js +45 -0
- package/lib/runtime/standalone.js.map +1 -0
- package/lib/runtime/timeline/chrome-tracks.d.ts +0 -5
- package/lib/runtime/timeline/chrome-tracks.d.ts.map +1 -1
- package/lib/runtime/timeline/chrome-tracks.js +5 -3
- package/lib/runtime/timeline/chrome-tracks.js.map +1 -1
- package/lib/runtime/timeline/clock.d.ts +7 -3
- package/lib/runtime/timeline/clock.d.ts.map +1 -1
- package/lib/runtime/timeline/clock.js +0 -5
- package/lib/runtime/timeline/clock.js.map +1 -1
- package/lib/runtime/timeline/flash.d.ts +0 -5
- package/lib/runtime/timeline/flash.d.ts.map +1 -1
- package/lib/runtime/timeline/flash.js +15 -3
- package/lib/runtime/timeline/flash.js.map +1 -1
- package/lib/runtime/timeline/identity.d.ts +0 -5
- package/lib/runtime/timeline/identity.d.ts.map +1 -1
- package/lib/runtime/timeline/identity.js +9 -3
- package/lib/runtime/timeline/identity.js.map +1 -1
- package/lib/runtime/timeline/input.d.ts +0 -5
- package/lib/runtime/timeline/input.d.ts.map +1 -1
- package/lib/runtime/timeline/input.js +2 -3
- package/lib/runtime/timeline/input.js.map +1 -1
- package/lib/runtime/timeline/install.d.ts +11 -3
- package/lib/runtime/timeline/install.d.ts.map +1 -1
- package/lib/runtime/timeline/install.js +4 -7
- package/lib/runtime/timeline/install.js.map +1 -1
- package/lib/runtime/timeline/lifecycle.d.ts +13 -3
- package/lib/runtime/timeline/lifecycle.d.ts.map +1 -1
- package/lib/runtime/timeline/lifecycle.js +5 -6
- package/lib/runtime/timeline/lifecycle.js.map +1 -1
- package/lib/runtime/timeline/public-api.d.ts +6 -3
- package/lib/runtime/timeline/public-api.d.ts.map +1 -1
- package/lib/runtime/timeline/public-api.js +0 -5
- package/lib/runtime/timeline/public-api.js.map +1 -1
- package/lib/runtime/timeline/render.d.ts +0 -5
- package/lib/runtime/timeline/render.d.ts.map +1 -1
- package/lib/runtime/timeline/render.js +21 -3
- package/lib/runtime/timeline/render.js.map +1 -1
- package/lib/runtime/timeline/transport.d.ts +0 -5
- package/lib/runtime/timeline/transport.d.ts.map +1 -1
- package/lib/runtime/timeline/transport.js +10 -3
- package/lib/runtime/timeline/transport.js.map +1 -1
- package/lib/segmented-tabs.d.ts +0 -5
- package/lib/segmented-tabs.d.ts.map +1 -1
- package/lib/segmented-tabs.js +0 -5
- package/lib/segmented-tabs.js.map +1 -1
- package/lib/snapshot.d.ts +11 -3
- package/lib/snapshot.d.ts.map +1 -1
- package/lib/snapshot.js +0 -5
- package/lib/snapshot.js.map +1 -1
- package/lib/source-meta.d.ts +0 -5
- package/lib/source-meta.d.ts.map +1 -1
- package/lib/source-meta.js +0 -5
- package/lib/source-meta.js.map +1 -1
- package/lib/timeline/derive.d.ts +0 -5
- package/lib/timeline/derive.d.ts.map +1 -1
- package/lib/timeline/derive.js +22 -3
- package/lib/timeline/derive.js.map +1 -1
- package/lib/timeline/filter.d.ts +0 -5
- package/lib/timeline/filter.d.ts.map +1 -1
- package/lib/timeline/filter.js +6 -3
- package/lib/timeline/filter.js.map +1 -1
- package/lib/timeline/tracks.d.ts +0 -5
- package/lib/timeline/tracks.d.ts.map +1 -1
- package/lib/timeline/tracks.js +12 -3
- package/lib/timeline/tracks.js.map +1 -1
- package/lib/tokens.d.ts +0 -5
- package/lib/tokens.d.ts.map +1 -1
- package/lib/tokens.js +0 -5
- package/lib/tokens.js.map +1 -1
- package/lib/transform.d.ts +0 -5
- package/lib/transform.d.ts.map +1 -1
- package/lib/transform.js +0 -5
- package/lib/transform.js.map +1 -1
- package/lib/types.d.ts +10 -5
- package/lib/types.d.ts.map +1 -1
- package/lib/types.js +0 -5
- package/lib/types.js.map +1 -1
- package/lib/wrap-table.d.ts +0 -5
- package/lib/wrap-table.d.ts.map +1 -1
- package/lib/wrap-table.js +12 -3
- package/lib/wrap-table.js.map +1 -1
- package/package.json +14 -10
- package/types/hmr-incompatibility.d.ts +0 -5
- package/types/hmr-incompatibility.d.ts.map +1 -1
- package/types/hmr-incompatibility.js +13 -3
- package/types/hmr-incompatibility.js.map +1 -1
- package/types/in-page.d.ts +0 -5
- package/types/in-page.d.ts.map +1 -1
- package/types/in-page.js +0 -5
- package/types/in-page.js.map +1 -1
- package/types/inspector.d.ts +0 -5
- package/types/inspector.d.ts.map +1 -1
- package/types/inspector.js +13 -3
- package/types/inspector.js.map +1 -1
- package/types/snapshot.d.ts +0 -5
- package/types/snapshot.d.ts.map +1 -1
- package/types/snapshot.js +12 -3
- package/types/snapshot.js.map +1 -1
- package/types/timeline.d.ts +4 -6
- package/types/timeline.d.ts.map +1 -1
- package/types/timeline.js +0 -5
- package/types/timeline.js.map +1 -1
- package/dist/client/assets/index-B2HYO7lk.js.map +0 -1
|
@@ -0,0 +1,461 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Carries child element state across a template re-instantiation.
|
|
3
|
+
*
|
|
4
|
+
* When a hot patch changes a template's text, lit-html sees a new template,
|
|
5
|
+
* clones fresh DOM and swaps it in: every custom element inside the edited
|
|
6
|
+
* template is re-created and starts from its defaults. For a short window
|
|
7
|
+
* after a hot patch this module pairs each element dropped from a root with
|
|
8
|
+
* the next freshly created element of the same tag connected in that root
|
|
9
|
+
* (FIFO, i.e. document order), then either copies the old element's state
|
|
10
|
+
* onto the new one (`'transfer'`) or, where the new element carries no
|
|
11
|
+
* bindings, puts the old element back in its place (`'reuse'`).
|
|
12
|
+
*
|
|
13
|
+
* Dependency-free and duck-typed like `patch.ts`. The lit-html internals it
|
|
14
|
+
* reads (`_$litPart$`, `_$committedValue`, `_$template`, `_$parts`,
|
|
15
|
+
* `_$startNode`, `_$endNode`) are looked up by their development names first
|
|
16
|
+
* and then by the stable minified names lit's prod build gives them
|
|
17
|
+
* (`_$AH`, `_$AD`, `_$AV`, `_$AA`, `_$AB`). Every access is guarded; when the
|
|
18
|
+
* part tree can't be read, transfer skips only attribute-driven keys and
|
|
19
|
+
* reuse falls back to transfer.
|
|
20
|
+
*/
|
|
21
|
+
/** `Symbol.for` description prefix of the dev-only `#private` rewrite. */
|
|
22
|
+
export const PRIVATE_KEY_PREFIX = '@oddsquad/vite-plugin-lit#private:';
|
|
23
|
+
/** Hard cap on how long a transfer window stays open. */
|
|
24
|
+
export const WINDOW_CAP_MS = 1000;
|
|
25
|
+
const ATTRIBUTE_PART = 1;
|
|
26
|
+
const CHILD_PART = 2;
|
|
27
|
+
const PROPERTY_PART = 3;
|
|
28
|
+
const BOOLEAN_PART = 4;
|
|
29
|
+
/** Dev name, then the stable minified name from lit-html's prod build. */
|
|
30
|
+
const COMMITTED = ['_$committedValue', '_$AH'];
|
|
31
|
+
const TEMPLATE = ['_$template', '_$AD'];
|
|
32
|
+
const PARTS = ['_$parts', '_$AV'];
|
|
33
|
+
const START = ['_$startNode', '_$AA'];
|
|
34
|
+
const END = ['_$endNode', '_$AB'];
|
|
35
|
+
const LIT_PART = '_$litPart$';
|
|
36
|
+
const internal = (o, [dev, prod]) => {
|
|
37
|
+
if (o === null || typeof o !== 'object') {
|
|
38
|
+
return undefined;
|
|
39
|
+
}
|
|
40
|
+
const r = o;
|
|
41
|
+
return dev in r ? r[dev] : r[prod];
|
|
42
|
+
};
|
|
43
|
+
const isPart = (p) =>
|
|
44
|
+
p !== null && typeof p === 'object' && typeof p.type === 'number';
|
|
45
|
+
const MAX_PARTS = 100_000;
|
|
46
|
+
/** Pushes `part` and, through child parts' committed values, every part below. */
|
|
47
|
+
const walkParts = (part, out) => {
|
|
48
|
+
if (out.length > MAX_PARTS) {
|
|
49
|
+
throw new Error('part tree too large');
|
|
50
|
+
}
|
|
51
|
+
out.push(part);
|
|
52
|
+
if (part.type !== CHILD_PART) {
|
|
53
|
+
return;
|
|
54
|
+
}
|
|
55
|
+
const value = internal(part, COMMITTED);
|
|
56
|
+
if (Array.isArray(value)) {
|
|
57
|
+
// An iterable's committed value is an array of ChildParts.
|
|
58
|
+
for (const child of value) {
|
|
59
|
+
if (isPart(child)) {
|
|
60
|
+
walkParts(child, out);
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
const parts = internal(value, PARTS);
|
|
66
|
+
if (Array.isArray(parts) && internal(value, TEMPLATE) !== undefined) {
|
|
67
|
+
for (const child of parts) {
|
|
68
|
+
// Entries may be undefined (parts removed by the polyfill/hydration).
|
|
69
|
+
if (isPart(child)) {
|
|
70
|
+
walkParts(child, out);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
};
|
|
75
|
+
/**
|
|
76
|
+
* Every lit-html part rendered into the tree `el` lives in: the parts of each
|
|
77
|
+
* render container (`_$litPart$`) among `el`'s ancestors up to its root.
|
|
78
|
+
* `undefined` when `el` isn't in a tree or the walk hits a surprise.
|
|
79
|
+
*/
|
|
80
|
+
export const partsAround = (el) => {
|
|
81
|
+
try {
|
|
82
|
+
const out = [];
|
|
83
|
+
let node = el.parentNode;
|
|
84
|
+
if (node === null) {
|
|
85
|
+
return undefined;
|
|
86
|
+
}
|
|
87
|
+
while (node !== null) {
|
|
88
|
+
const root = node[LIT_PART];
|
|
89
|
+
if (isPart(root)) {
|
|
90
|
+
walkParts(root, out);
|
|
91
|
+
}
|
|
92
|
+
node = node.parentNode;
|
|
93
|
+
}
|
|
94
|
+
return out;
|
|
95
|
+
} catch {
|
|
96
|
+
return undefined;
|
|
97
|
+
}
|
|
98
|
+
};
|
|
99
|
+
/** Attribute name → reactive property key for an element's class. */
|
|
100
|
+
const attributeMap = (ctor) => {
|
|
101
|
+
// Dev builds keep the name; prod mangles it, so rebuild from options.
|
|
102
|
+
const own = ctor.__attributeToPropertyMap;
|
|
103
|
+
if (own instanceof Map) {
|
|
104
|
+
return own;
|
|
105
|
+
}
|
|
106
|
+
const map = new Map();
|
|
107
|
+
const props = ctor.elementProperties;
|
|
108
|
+
if (!(props instanceof Map)) {
|
|
109
|
+
return map;
|
|
110
|
+
}
|
|
111
|
+
for (const [key, options] of props) {
|
|
112
|
+
const attribute = options?.attribute;
|
|
113
|
+
if (attribute === false) {
|
|
114
|
+
continue;
|
|
115
|
+
}
|
|
116
|
+
if (typeof attribute === 'string') {
|
|
117
|
+
map.set(attribute, key);
|
|
118
|
+
} else if (typeof key === 'string') {
|
|
119
|
+
map.set(key.toLowerCase(), key);
|
|
120
|
+
}
|
|
121
|
+
}
|
|
122
|
+
return map;
|
|
123
|
+
};
|
|
124
|
+
const propertyKeys = (ctor) => {
|
|
125
|
+
const props = ctor?.elementProperties;
|
|
126
|
+
return props instanceof Map ? [...props.keys()] : [];
|
|
127
|
+
};
|
|
128
|
+
/**
|
|
129
|
+
* Reactive property keys the new element already got from its template:
|
|
130
|
+
* keys whose attribute is present on it (static attributes), plus, when the
|
|
131
|
+
* part tree could be read, keys bound by a property, boolean or attribute
|
|
132
|
+
* part targeting it.
|
|
133
|
+
*/
|
|
134
|
+
export const templateDrivenKeys = (el, parts) => {
|
|
135
|
+
const keys = new Set();
|
|
136
|
+
const ctor = el.constructor;
|
|
137
|
+
const attrs = attributeMap(ctor);
|
|
138
|
+
try {
|
|
139
|
+
for (const attr of Array.from(el.attributes)) {
|
|
140
|
+
const key = attrs.get(attr.name.toLowerCase());
|
|
141
|
+
if (key !== undefined) {
|
|
142
|
+
keys.add(key);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
} catch {
|
|
146
|
+
// No attributes to read.
|
|
147
|
+
}
|
|
148
|
+
for (const part of parts ?? []) {
|
|
149
|
+
if (part.element !== el || typeof part.name !== 'string') {
|
|
150
|
+
continue;
|
|
151
|
+
}
|
|
152
|
+
if (part.type === PROPERTY_PART) {
|
|
153
|
+
keys.add(part.name);
|
|
154
|
+
} else if (part.type === ATTRIBUTE_PART || part.type === BOOLEAN_PART) {
|
|
155
|
+
keys.add(attrs.get(part.name.toLowerCase()) ?? part.name);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
return keys;
|
|
159
|
+
};
|
|
160
|
+
/** Own symbol keys of `el` minted by the dev-only `#private` rewrite. */
|
|
161
|
+
export const privateKeys = (el) =>
|
|
162
|
+
Object.getOwnPropertySymbols(el).filter((sym) =>
|
|
163
|
+
(Symbol.keyFor(sym) ?? '').startsWith(PRIVATE_KEY_PREFIX)
|
|
164
|
+
);
|
|
165
|
+
/**
|
|
166
|
+
* Copies `from`'s state onto `to`: reactive properties not driven by `to`'s
|
|
167
|
+
* template, and the `#private` members the dev rewrite turned into
|
|
168
|
+
* `Symbol.for` keys. Nothing else — Lit's own bookkeeping lives in string
|
|
169
|
+
* keys and must stay per-instance.
|
|
170
|
+
*/
|
|
171
|
+
export const transferState = (from, to, parts) => {
|
|
172
|
+
const skip = templateDrivenKeys(to, parts);
|
|
173
|
+
const keys = new Set([
|
|
174
|
+
...propertyKeys(to.constructor),
|
|
175
|
+
...propertyKeys(from.constructor),
|
|
176
|
+
]);
|
|
177
|
+
const src = from;
|
|
178
|
+
const dst = to;
|
|
179
|
+
for (const key of keys) {
|
|
180
|
+
if (skip.has(key)) {
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
try {
|
|
184
|
+
dst[key] = src[key];
|
|
185
|
+
} catch {
|
|
186
|
+
// A throwing setter; leave the default.
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
for (const sym of privateKeys(from)) {
|
|
190
|
+
try {
|
|
191
|
+
Object.defineProperty(
|
|
192
|
+
to,
|
|
193
|
+
sym,
|
|
194
|
+
Object.getOwnPropertyDescriptor(from, sym)
|
|
195
|
+
);
|
|
196
|
+
} catch {
|
|
197
|
+
// Non-configurable on the target; leave it.
|
|
198
|
+
}
|
|
199
|
+
}
|
|
200
|
+
};
|
|
201
|
+
const inside = (el, node) =>
|
|
202
|
+
node !== null &&
|
|
203
|
+
typeof node === 'object' &&
|
|
204
|
+
typeof node.nodeType === 'number' &&
|
|
205
|
+
el.contains(node);
|
|
206
|
+
/**
|
|
207
|
+
* Whether `el` (and its light DOM) carries no bindings, so another element
|
|
208
|
+
* can take its place without lit-html noticing: no part targets it or an
|
|
209
|
+
* element inside it, no child part's markers or parent lie inside it, and
|
|
210
|
+
* nothing rendered into it as a container. `false` when `parts` is unknown.
|
|
211
|
+
*/
|
|
212
|
+
export const isReuseSafe = (el, parts) => {
|
|
213
|
+
if (parts === undefined) {
|
|
214
|
+
return false;
|
|
215
|
+
}
|
|
216
|
+
try {
|
|
217
|
+
if (LIT_PART in el) {
|
|
218
|
+
return false;
|
|
219
|
+
}
|
|
220
|
+
for (const part of parts) {
|
|
221
|
+
if (inside(el, part.element)) {
|
|
222
|
+
return false;
|
|
223
|
+
}
|
|
224
|
+
if (part.type === CHILD_PART) {
|
|
225
|
+
const start = internal(part, START);
|
|
226
|
+
const end = internal(part, END);
|
|
227
|
+
if (
|
|
228
|
+
inside(el, start) ||
|
|
229
|
+
inside(el, end) ||
|
|
230
|
+
inside(el, start?.parentNode) ||
|
|
231
|
+
inside(el, end?.parentNode)
|
|
232
|
+
) {
|
|
233
|
+
return false;
|
|
234
|
+
}
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
return true;
|
|
238
|
+
} catch {
|
|
239
|
+
return false;
|
|
240
|
+
}
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Puts `old` back where `fresh` is: `old` takes `fresh`'s attributes and
|
|
244
|
+
* light-DOM children, then replaces it. `old` keeps its identity, state,
|
|
245
|
+
* shadow DOM and controllers, and reconnects.
|
|
246
|
+
*/
|
|
247
|
+
export const swapBack = (old, fresh) => {
|
|
248
|
+
for (const attr of Array.from(old.attributes)) {
|
|
249
|
+
if (!fresh.hasAttribute(attr.name)) {
|
|
250
|
+
old.removeAttribute(attr.name);
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
for (const attr of Array.from(fresh.attributes)) {
|
|
254
|
+
if (old.getAttribute(attr.name) !== attr.value) {
|
|
255
|
+
old.setAttribute(attr.name, attr.value);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
old.replaceChildren(...Array.from(fresh.childNodes));
|
|
259
|
+
fresh.replaceWith(old);
|
|
260
|
+
};
|
|
261
|
+
export const createChildState = (options) => {
|
|
262
|
+
const capMs = options.capMs ?? WINDOW_CAP_MS;
|
|
263
|
+
/** The root each element was last connected in. */
|
|
264
|
+
const rootOf = new WeakMap();
|
|
265
|
+
let current;
|
|
266
|
+
const close = (w) => {
|
|
267
|
+
if (current !== w) {
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
current = undefined;
|
|
271
|
+
clearTimeout(w.idle);
|
|
272
|
+
clearTimeout(w.cap);
|
|
273
|
+
// Reuse only once everything we waited on has settled; on the hard cap
|
|
274
|
+
// with updates still outstanding, the transferred state stands.
|
|
275
|
+
if (w.mode !== 'reuse' || w.waiting > 0) {
|
|
276
|
+
return;
|
|
277
|
+
}
|
|
278
|
+
for (const [old, fresh] of w.pairs) {
|
|
279
|
+
// A pair inside an element that was itself swapped back is moot:
|
|
280
|
+
// the old element's shadow DOM came back intact with it.
|
|
281
|
+
if (!fresh.isConnected || old.isConnected) {
|
|
282
|
+
continue;
|
|
283
|
+
}
|
|
284
|
+
try {
|
|
285
|
+
if (isReuseSafe(fresh, partsAround(fresh))) {
|
|
286
|
+
swapBack(old, fresh);
|
|
287
|
+
}
|
|
288
|
+
} catch {
|
|
289
|
+
// Leave the new element (it already has the transferred state).
|
|
290
|
+
}
|
|
291
|
+
}
|
|
292
|
+
};
|
|
293
|
+
/** Close once a macrotask passes with no tracked activity. */
|
|
294
|
+
const settle = (w) => {
|
|
295
|
+
if (current !== w || w.waiting > 0) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
clearTimeout(w.idle);
|
|
299
|
+
w.idle = setTimeout(() => close(w), 0);
|
|
300
|
+
};
|
|
301
|
+
/** The pending-queue root for an element now connected in `root`. */
|
|
302
|
+
const keyRoot = (w, root) => {
|
|
303
|
+
const host = root.host;
|
|
304
|
+
const old = host === undefined ? undefined : w.pairOf.get(host);
|
|
305
|
+
if (old !== undefined) {
|
|
306
|
+
// Re-created inside a new element's shadow: match against what was
|
|
307
|
+
// dropped from the old element's shadow.
|
|
308
|
+
const oldRoot = old.renderRoot ?? old.shadowRoot;
|
|
309
|
+
if (oldRoot !== undefined && oldRoot !== null && w.pending.has(oldRoot)) {
|
|
310
|
+
return oldRoot;
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
return root;
|
|
314
|
+
};
|
|
315
|
+
const unqueue = (w, el) => {
|
|
316
|
+
const at = w.pendingOf.get(el);
|
|
317
|
+
if (at === undefined) {
|
|
318
|
+
return;
|
|
319
|
+
}
|
|
320
|
+
w.pendingOf.delete(el);
|
|
321
|
+
const queue = w.pending.get(at.root)?.get(at.tag);
|
|
322
|
+
const i = queue?.indexOf(el) ?? -1;
|
|
323
|
+
if (i >= 0) {
|
|
324
|
+
queue.splice(i, 1);
|
|
325
|
+
}
|
|
326
|
+
};
|
|
327
|
+
const pair = (w, fresh, root) => {
|
|
328
|
+
const queue = w.pending.get(keyRoot(w, root))?.get(fresh.localName);
|
|
329
|
+
const old = queue?.shift();
|
|
330
|
+
if (old === undefined) {
|
|
331
|
+
return;
|
|
332
|
+
}
|
|
333
|
+
w.pendingOf.delete(old);
|
|
334
|
+
w.pairOf.set(fresh, old);
|
|
335
|
+
const origin = w.originOf.get(old) ?? old;
|
|
336
|
+
w.originOf.set(fresh, origin);
|
|
337
|
+
w.pairs.push([origin, fresh]);
|
|
338
|
+
// lit-html assigns the new template instance to its part only after the
|
|
339
|
+
// fragment is inserted, so the parts targeting `fresh` aren't reachable
|
|
340
|
+
// yet. Queued before the original connectedCallback enables updating,
|
|
341
|
+
// this runs ahead of `fresh`'s first update.
|
|
342
|
+
queueMicrotask(() => {
|
|
343
|
+
try {
|
|
344
|
+
transferState(old, fresh, partsAround(fresh));
|
|
345
|
+
} catch {
|
|
346
|
+
// Keep the defaults.
|
|
347
|
+
}
|
|
348
|
+
});
|
|
349
|
+
};
|
|
350
|
+
return {
|
|
351
|
+
connected(el, fresh) {
|
|
352
|
+
let root;
|
|
353
|
+
try {
|
|
354
|
+
root = el.getRootNode();
|
|
355
|
+
} catch {
|
|
356
|
+
root = undefined;
|
|
357
|
+
}
|
|
358
|
+
const w = current;
|
|
359
|
+
if (w !== undefined) {
|
|
360
|
+
try {
|
|
361
|
+
if (fresh && root !== undefined && el.hasUpdated !== true) {
|
|
362
|
+
pair(w, el, root);
|
|
363
|
+
} else {
|
|
364
|
+
// Moved, not re-created: it can't be anyone's replacement.
|
|
365
|
+
unqueue(w, el);
|
|
366
|
+
}
|
|
367
|
+
} catch {
|
|
368
|
+
// Pairing is best-effort.
|
|
369
|
+
}
|
|
370
|
+
settle(w);
|
|
371
|
+
}
|
|
372
|
+
if (root !== undefined) {
|
|
373
|
+
rootOf.set(el, root);
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
disconnected(el) {
|
|
377
|
+
const w = current;
|
|
378
|
+
if (w === undefined) {
|
|
379
|
+
return;
|
|
380
|
+
}
|
|
381
|
+
const root = rootOf.get(el);
|
|
382
|
+
if (root !== undefined) {
|
|
383
|
+
const tag = el.localName;
|
|
384
|
+
let byTag = w.pending.get(root);
|
|
385
|
+
if (byTag === undefined) {
|
|
386
|
+
w.pending.set(root, (byTag = new Map()));
|
|
387
|
+
}
|
|
388
|
+
let queue = byTag.get(tag);
|
|
389
|
+
if (queue === undefined) {
|
|
390
|
+
byTag.set(tag, (queue = []));
|
|
391
|
+
}
|
|
392
|
+
unqueue(w, el);
|
|
393
|
+
queue.push(el);
|
|
394
|
+
w.pendingOf.set(el, {root, tag});
|
|
395
|
+
}
|
|
396
|
+
settle(w);
|
|
397
|
+
},
|
|
398
|
+
open() {
|
|
399
|
+
const mode = options.mode();
|
|
400
|
+
if (mode !== 'transfer' && mode !== 'reuse') {
|
|
401
|
+
return;
|
|
402
|
+
}
|
|
403
|
+
let w = current;
|
|
404
|
+
if (w === undefined) {
|
|
405
|
+
w = current = {
|
|
406
|
+
mode,
|
|
407
|
+
pending: new Map(),
|
|
408
|
+
pendingOf: new Map(),
|
|
409
|
+
pairs: [],
|
|
410
|
+
pairOf: new Map(),
|
|
411
|
+
originOf: new Map(),
|
|
412
|
+
waiting: 0,
|
|
413
|
+
};
|
|
414
|
+
}
|
|
415
|
+
w.mode = mode;
|
|
416
|
+
clearTimeout(w.cap);
|
|
417
|
+
const opened = w;
|
|
418
|
+
w.cap = setTimeout(() => close(opened), capMs);
|
|
419
|
+
settle(w);
|
|
420
|
+
},
|
|
421
|
+
watch(els) {
|
|
422
|
+
const w = current;
|
|
423
|
+
if (w === undefined) {
|
|
424
|
+
return;
|
|
425
|
+
}
|
|
426
|
+
const promises = [];
|
|
427
|
+
for (const el of els) {
|
|
428
|
+
try {
|
|
429
|
+
const p = el.updateComplete;
|
|
430
|
+
if (p instanceof Promise) {
|
|
431
|
+
promises.push(p);
|
|
432
|
+
}
|
|
433
|
+
} catch {
|
|
434
|
+
// No update promise to wait on.
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
w.waiting++;
|
|
438
|
+
clearTimeout(w.idle);
|
|
439
|
+
let left = promises.length + 1;
|
|
440
|
+
const done = () => {
|
|
441
|
+
if (--left === 0) {
|
|
442
|
+
w.waiting--;
|
|
443
|
+
settle(w);
|
|
444
|
+
}
|
|
445
|
+
};
|
|
446
|
+
for (const p of promises) {
|
|
447
|
+
// Rethrow: a failed update must still surface as an unhandled
|
|
448
|
+
// rejection, exactly as it would with nobody watching.
|
|
449
|
+
void p.then(done, (e) => {
|
|
450
|
+
done();
|
|
451
|
+
throw e;
|
|
452
|
+
});
|
|
453
|
+
}
|
|
454
|
+
queueMicrotask(done);
|
|
455
|
+
},
|
|
456
|
+
get active() {
|
|
457
|
+
return current !== undefined;
|
|
458
|
+
},
|
|
459
|
+
};
|
|
460
|
+
};
|
|
461
|
+
//# sourceMappingURL=child-state.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"child-state.js","sourceRoot":"","sources":["../../src/lib/runtime/child-state.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;GAmBG;AAIH,0EAA0E;AAC1E,MAAM,CAAC,MAAM,kBAAkB,GAAG,oCAAoC,CAAC;AAEvE,yDAAyD;AACzD,MAAM,CAAC,MAAM,aAAa,GAAG,IAAI,CAAC;AAElC,MAAM,cAAc,GAAG,CAAC,CAAC;AACzB,MAAM,UAAU,GAAG,CAAC,CAAC;AACrB,MAAM,aAAa,GAAG,CAAC,CAAC;AACxB,MAAM,YAAY,GAAG,CAAC,CAAC;AAEvB,0EAA0E;AAC1E,MAAM,SAAS,GAAG,CAAC,kBAAkB,EAAE,MAAM,CAAU,CAAC;AACxD,MAAM,QAAQ,GAAG,CAAC,YAAY,EAAE,MAAM,CAAU,CAAC;AACjD,MAAM,KAAK,GAAG,CAAC,SAAS,EAAE,MAAM,CAAU,CAAC;AAC3C,MAAM,KAAK,GAAG,CA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AC/B,MAAM,IAAI,GAAG,GAAG,EAAE;gBAChB,IAAI,EAAE,IAAI,KAAK,CAAC,EAAE,CAAC;oBACjB,CAAC,CAAC,OAAO,EAAE,CAAC;oBACZ,MAAM,CAAC,CAAC,CAAC,CAAC;gBACZ,CAAC;YACH,CAAC,CAAC;YACF,KAAK,MAAM,CAAC,IAAI,QAAQ,EAAE,CAAC;gBACzB,8DAA8D;gBAC9D,uDAAuD;gBACvD,KAAK,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC,CAAU,EAAE,EAAE;oBAC/B,IAAI,EAAE,CAAC;oBACP,MAAM,CAAC,CAAC;gBACV,CAAC,CAAC,CAAC;YACL,CAAC;YACD,cAAc,CAAC,IAAI,CAAC,CAAC;QACvB,CAAC;QACD,IAAI,MAAM;YACR,OAAO,OAAO,KAAK,SAAS,CAAC;QAC/B,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/**\n * Carries child element state across a template re-instantiation.\n *\n * When a hot patch changes a template's text, lit-html sees a new template,\n * clones fresh DOM and swaps it in: every custom element inside the edited\n * template is re-created and starts from its defaults. For a short window\n * after a hot patch this module pairs each element dropped from a root with\n * the next freshly created element of the same tag connected in that root\n * (FIFO, i.e. document order), then either copies the old element's state\n * onto the new one (`'transfer'`) or, where the new element carries no\n * bindings, puts the old element back in its place (`'reuse'`).\n *\n * Dependency-free and duck-typed like `patch.ts`. The lit-html internals it\n * reads (`_$litPart$`, `_$committedValue`, `_$template`, `_$parts`,\n * `_$startNode`, `_$endNode`) are looked up by their development names first\n * and then by the stable minified names lit's prod build gives them\n * (`_$AH`, `_$AD`, `_$AV`, `_$AA`, `_$AB`). Every access is guarded; when the\n * part tree can't be read, transfer skips only attribute-driven keys and\n * reuse falls back to transfer.\n */\n\nexport type ChildStateMode = 'reset' | 'transfer' | 'reuse';\n\n/** `Symbol.for` description prefix of the dev-only `#private` rewrite. */\nexport const PRIVATE_KEY_PREFIX = '@oddsquad/vite-plugin-lit#private:';\n\n/** Hard cap on how long a transfer window stays open. */\nexport const WINDOW_CAP_MS = 1000;\n\nconst ATTRIBUTE_PART = 1;\nconst CHILD_PART = 2;\nconst PROPERTY_PART = 3;\nconst BOOLEAN_PART = 4;\n\n/** Dev name, then the stable minified name from lit-html's prod build. */\nconst COMMITTED = ['_$committedValue', '_$AH'] as const;\nconst TEMPLATE = ['_$template', '_$AD'] as const;\nconst PARTS = ['_$parts', '_$AV'] as const;\nconst START = ['_$startNode', '_$AA'] as const;\nconst END = ['_$endNode', '_$AB'] as const;\nconst LIT_PART = '_$litPart$';\n\n/** Duck-typed lit-html part. */\nexport interface PartLike {\n type: number;\n element?: unknown;\n name?: unknown;\n}\n\n/** Duck-typed element the window works with. */\nexport type ElementLike = HTMLElement & {\n renderRoot?: unknown;\n hasUpdated?: boolean;\n updateComplete?: unknown;\n};\n\ninterface CtorLike {\n elementProperties?: Map<PropertyKey, {attribute?: unknown} | undefined>;\n __attributeToPropertyMap?: unknown;\n}\n\nconst internal = (\n o: unknown,\n [dev, prod]: readonly [string, string]\n): unknown => {\n if (o === null || typeof o !== 'object') {\n return undefined;\n }\n const r = o as Record<string, unknown>;\n return dev in r ? r[dev] : r[prod];\n};\n\nconst isPart = (p: unknown): p is PartLike =>\n p !== null &&\n typeof p === 'object' &&\n typeof (p as PartLike).type === 'number';\n\nconst MAX_PARTS = 100_000;\n\n/** Pushes `part` and, through child parts' committed values, every part below. */\nconst walkParts = (part: PartLike, out: PartLike[]): void => {\n if (out.length > MAX_PARTS) {\n throw new Error('part tree too large');\n }\n out.push(part);\n if (part.type !== CHILD_PART) {\n return;\n }\n const value = internal(part, COMMITTED);\n if (Array.isArray(value)) {\n // An iterable's committed value is an array of ChildParts.\n for (const child of value) {\n if (isPart(child)) {\n walkParts(child, out);\n }\n }\n return;\n }\n const parts = internal(value, PARTS);\n if (Array.isArray(parts) && internal(value, TEMPLATE) !== undefined) {\n for (const child of parts) {\n // Entries may be undefined (parts removed by the polyfill/hydration).\n if (isPart(child)) {\n walkParts(child, out);\n }\n }\n }\n};\n\n/**\n * Every lit-html part rendered into the tree `el` lives in: the parts of each\n * render container (`_$litPart$`) among `el`'s ancestors up to its root.\n * `undefined` when `el` isn't in a tree or the walk hits a surprise.\n */\nexport const partsAround = (el: Node): PartLike[] | undefined => {\n try {\n const out: PartLike[] = [];\n let node: Node | null = el.parentNode;\n if (node === null) {\n return undefined;\n }\n while (node !== null) {\n const root = (node as unknown as Record<string, unknown>)[LIT_PART];\n if (isPart(root)) {\n walkParts(root, out);\n }\n node = node.parentNode;\n }\n return out;\n } catch {\n return undefined;\n }\n};\n\n/** Attribute name → reactive property key for an element's class. */\nconst attributeMap = (ctor: CtorLike): Map<string, PropertyKey> => {\n // Dev builds keep the name; prod mangles it, so rebuild from options.\n const own = ctor.__attributeToPropertyMap;\n if (own instanceof Map) {\n return own as Map<string, PropertyKey>;\n }\n const map = new Map<string, PropertyKey>();\n const props = ctor.elementProperties;\n if (!(props instanceof Map)) {\n return map;\n }\n for (const [key, options] of props) {\n const attribute = options?.attribute;\n if (attribute === false) {\n continue;\n }\n if (typeof attribute === 'string') {\n map.set(attribute, key);\n } else if (typeof key === 'string') {\n map.set(key.toLowerCase(), key);\n }\n }\n return map;\n};\n\nconst propertyKeys = (ctor: CtorLike | undefined): PropertyKey[] => {\n const props = ctor?.elementProperties;\n return props instanceof Map ? [...props.keys()] : [];\n};\n\n/**\n * Reactive property keys the new element already got from its template:\n * keys whose attribute is present on it (static attributes), plus, when the\n * part tree could be read, keys bound by a property, boolean or attribute\n * part targeting it.\n */\nexport const templateDrivenKeys = (\n el: ElementLike,\n parts: readonly PartLike[] | undefined\n): Set<PropertyKey> => {\n const keys = new Set<PropertyKey>();\n const ctor = el.constructor as CtorLike;\n const attrs = attributeMap(ctor);\n try {\n for (const attr of Array.from(el.attributes)) {\n const key = attrs.get(attr.name.toLowerCase());\n if (key !== undefined) {\n keys.add(key);\n }\n }\n } catch {\n // No attributes to read.\n }\n for (const part of parts ?? []) {\n if (part.element !== el || typeof part.name !== 'string') {\n continue;\n }\n if (part.type === PROPERTY_PART) {\n keys.add(part.name);\n } else if (part.type === ATTRIBUTE_PART || part.type === BOOLEAN_PART) {\n keys.add(attrs.get(part.name.toLowerCase()) ?? part.name);\n }\n }\n return keys;\n};\n\n/** Own symbol keys of `el` minted by the dev-only `#private` rewrite. */\nexport const privateKeys = (el: object): symbol[] =>\n Object.getOwnPropertySymbols(el).filter((sym) =>\n (Symbol.keyFor(sym) ?? '').startsWith(PRIVATE_KEY_PREFIX)\n );\n\n/**\n * Copies `from`'s state onto `to`: reactive properties not driven by `to`'s\n * template, and the `#private` members the dev rewrite turned into\n * `Symbol.for` keys. Nothing else — Lit's own bookkeeping lives in string\n * keys and must stay per-instance.\n */\nexport const transferState = (\n from: ElementLike,\n to: ElementLike,\n parts: readonly PartLike[] | undefined\n): void => {\n const skip = templateDrivenKeys(to, parts);\n const keys = new Set<PropertyKey>([\n ...propertyKeys(to.constructor as CtorLike),\n ...propertyKeys(from.constructor as CtorLike),\n ]);\n const src = from as unknown as Record<PropertyKey, unknown>;\n const dst = to as unknown as Record<PropertyKey, unknown>;\n for (const key of keys) {\n if (skip.has(key)) {\n continue;\n }\n try {\n dst[key] = src[key];\n } catch {\n // A throwing setter; leave the default.\n }\n }\n for (const sym of privateKeys(from)) {\n try {\n Object.defineProperty(\n to,\n sym,\n Object.getOwnPropertyDescriptor(from, sym)!\n );\n } catch {\n // Non-configurable on the target; leave it.\n }\n }\n};\n\nconst inside = (el: Node, node: unknown): boolean =>\n node !== null &&\n typeof node === 'object' &&\n typeof (node as Node).nodeType === 'number' &&\n el.contains(node as Node);\n\n/**\n * Whether `el` (and its light DOM) carries no bindings, so another element\n * can take its place without lit-html noticing: no part targets it or an\n * element inside it, no child part's markers or parent lie inside it, and\n * nothing rendered into it as a container. `false` when `parts` is unknown.\n */\nexport const isReuseSafe = (\n el: ElementLike,\n parts: readonly PartLike[] | undefined\n): boolean => {\n if (parts === undefined) {\n return false;\n }\n try {\n if (LIT_PART in el) {\n return false;\n }\n for (const part of parts) {\n if (inside(el, part.element)) {\n return false;\n }\n if (part.type === CHILD_PART) {\n const start = internal(part, START) as Node | null | undefined;\n const end = internal(part, END) as Node | null | undefined;\n if (\n inside(el, start) ||\n inside(el, end) ||\n inside(el, start?.parentNode) ||\n inside(el, end?.parentNode)\n ) {\n return false;\n }\n }\n }\n return true;\n } catch {\n return false;\n }\n};\n\n/**\n * Puts `old` back where `fresh` is: `old` takes `fresh`'s attributes and\n * light-DOM children, then replaces it. `old` keeps its identity, state,\n * shadow DOM and controllers, and reconnects.\n */\nexport const swapBack = (old: ElementLike, fresh: ElementLike): void => {\n for (const attr of Array.from(old.attributes)) {\n if (!fresh.hasAttribute(attr.name)) {\n old.removeAttribute(attr.name);\n }\n }\n for (const attr of Array.from(fresh.attributes)) {\n if (old.getAttribute(attr.name) !== attr.value) {\n old.setAttribute(attr.name, attr.value);\n }\n }\n old.replaceChildren(...Array.from(fresh.childNodes));\n fresh.replaceWith(old);\n};\n\ninterface Pending {\n root: Node;\n tag: string;\n}\n\ninterface TransferWindow {\n mode: 'transfer' | 'reuse';\n /** Elements dropped during the window, by root then tag, in drop order. */\n pending: Map<Node, Map<string, ElementLike[]>>;\n pendingOf: Map<ElementLike, Pending>;\n /** (old, new) in pairing order; `old` is the chain's original element. */\n pairs: Array<[ElementLike, ElementLike]>;\n /** New element → the element it replaced (immediate predecessor). */\n pairOf: Map<ElementLike, ElementLike>;\n /** New element → the first element of its replacement chain. */\n originOf: Map<ElementLike, ElementLike>;\n /** Outstanding `watch()` batches. */\n waiting: number;\n idle?: ReturnType<typeof setTimeout>;\n cap?: ReturnType<typeof setTimeout>;\n}\n\nexport interface ChildStateOptions {\n /** Read at every `open()`. */\n mode: () => ChildStateMode;\n /** Hard cap on a window's lifetime. Defaults to {@link WINDOW_CAP_MS}. */\n capMs?: number;\n}\n\nexport interface ChildState {\n /**\n * From the instrumented `connectedCallback`, before the original runs.\n * `fresh` is whether the element has never been connected before.\n */\n connected(el: ElementLike, fresh: boolean): void;\n /** From the instrumented `disconnectedCallback`. */\n disconnected(el: ElementLike): void;\n /** A hot patch is about to re-render instances: open (or extend) a window. */\n open(): void;\n /** Keep the window open until these instances' updates complete. */\n watch(els: Iterable<ElementLike>): void;\n /** Whether a window is currently open. */\n readonly active: boolean;\n}\n\nexport const createChildState = (options: ChildStateOptions): ChildState => {\n const capMs = options.capMs ?? WINDOW_CAP_MS;\n /** The root each element was last connected in. */\n const rootOf = new WeakMap<ElementLike, Node>();\n let current: TransferWindow | undefined;\n\n const close = (w: TransferWindow): void => {\n if (current !== w) {\n return;\n }\n current = undefined;\n clearTimeout(w.idle);\n clearTimeout(w.cap);\n // Reuse only once everything we waited on has settled; on the hard cap\n // with updates still outstanding, the transferred state stands.\n if (w.mode !== 'reuse' || w.waiting > 0) {\n return;\n }\n for (const [old, fresh] of w.pairs) {\n // A pair inside an element that was itself swapped back is moot:\n // the old element's shadow DOM came back intact with it.\n if (!fresh.isConnected || old.isConnected) {\n continue;\n }\n try {\n if (isReuseSafe(fresh, partsAround(fresh))) {\n swapBack(old, fresh);\n }\n } catch {\n // Leave the new element (it already has the transferred state).\n }\n }\n };\n\n /** Close once a macrotask passes with no tracked activity. */\n const settle = (w: TransferWindow): void => {\n if (current !== w || w.waiting > 0) {\n return;\n }\n clearTimeout(w.idle);\n w.idle = setTimeout(() => close(w), 0);\n };\n\n /** The pending-queue root for an element now connected in `root`. */\n const keyRoot = (w: TransferWindow, root: Node): Node => {\n const host = (root as Partial<ShadowRoot>).host as ElementLike | undefined;\n const old = host === undefined ? undefined : w.pairOf.get(host);\n if (old !== undefined) {\n // Re-created inside a new element's shadow: match against what was\n // dropped from the old element's shadow.\n const oldRoot = (old.renderRoot ?? old.shadowRoot) as Node | undefined;\n if (oldRoot !== undefined && oldRoot !== null && w.pending.has(oldRoot)) {\n return oldRoot;\n }\n }\n return root;\n };\n\n const unqueue = (w: TransferWindow, el: ElementLike): void => {\n const at = w.pendingOf.get(el);\n if (at === undefined) {\n return;\n }\n w.pendingOf.delete(el);\n const queue = w.pending.get(at.root)?.get(at.tag);\n const i = queue?.indexOf(el) ?? -1;\n if (i >= 0) {\n queue!.splice(i, 1);\n }\n };\n\n const pair = (w: TransferWindow, fresh: ElementLike, root: Node): void => {\n const queue = w.pending.get(keyRoot(w, root))?.get(fresh.localName);\n const old = queue?.shift();\n if (old === undefined) {\n return;\n }\n w.pendingOf.delete(old);\n w.pairOf.set(fresh, old);\n const origin = w.originOf.get(old) ?? old;\n w.originOf.set(fresh, origin);\n w.pairs.push([origin, fresh]);\n // lit-html assigns the new template instance to its part only after the\n // fragment is inserted, so the parts targeting `fresh` aren't reachable\n // yet. Queued before the original connectedCallback enables updating,\n // this runs ahead of `fresh`'s first update.\n queueMicrotask(() => {\n try {\n transferState(old, fresh, partsAround(fresh));\n } catch {\n // Keep the defaults.\n }\n });\n };\n\n return {\n connected(el, fresh) {\n let root: Node | undefined;\n try {\n root = el.getRootNode();\n } catch {\n root = undefined;\n }\n const w = current;\n if (w !== undefined) {\n try {\n if (fresh && root !== undefined && el.hasUpdated !== true) {\n pair(w, el, root);\n } else {\n // Moved, not re-created: it can't be anyone's replacement.\n unqueue(w, el);\n }\n } catch {\n // Pairing is best-effort.\n }\n settle(w);\n }\n if (root !== undefined) {\n rootOf.set(el, root);\n }\n },\n disconnected(el) {\n const w = current;\n if (w === undefined) {\n return;\n }\n const root = rootOf.get(el);\n if (root !== undefined) {\n const tag = el.localName;\n let byTag = w.pending.get(root);\n if (byTag === undefined) {\n w.pending.set(root, (byTag = new Map()));\n }\n let queue = byTag.get(tag);\n if (queue === undefined) {\n byTag.set(tag, (queue = []));\n }\n unqueue(w, el);\n queue.push(el);\n w.pendingOf.set(el, {root, tag});\n }\n settle(w);\n },\n open() {\n const mode = options.mode();\n if (mode !== 'transfer' && mode !== 'reuse') {\n return;\n }\n let w = current;\n if (w === undefined) {\n w = current = {\n mode,\n pending: new Map(),\n pendingOf: new Map(),\n pairs: [],\n pairOf: new Map(),\n originOf: new Map(),\n waiting: 0,\n };\n }\n w.mode = mode;\n clearTimeout(w.cap);\n const opened = w;\n w.cap = setTimeout(() => close(opened), capMs);\n settle(w);\n },\n watch(els) {\n const w = current;\n if (w === undefined) {\n return;\n }\n const promises: Promise<unknown>[] = [];\n for (const el of els) {\n try {\n const p = el.updateComplete;\n if (p instanceof Promise) {\n promises.push(p);\n }\n } catch {\n // No update promise to wait on.\n }\n }\n w.waiting++;\n clearTimeout(w.idle);\n let left = promises.length + 1;\n const done = () => {\n if (--left === 0) {\n w.waiting--;\n settle(w);\n }\n };\n for (const p of promises) {\n // Rethrow: a failed update must still surface as an unhandled\n // rejection, exactly as it would with nobody watching.\n void p.then(done, (e: unknown) => {\n done();\n throw e;\n });\n }\n queueMicrotask(done);\n },\n get active() {\n return current !== undefined;\n },\n };\n};\n"]}
|
package/lib/runtime/css.d.ts
CHANGED
|
@@ -1,7 +1,18 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Browser helpers for referencing CSS files from shadow roots via Vite's
|
|
3
|
+
* `?url` imports.
|
|
4
|
+
*
|
|
5
|
+
* A `?url` import yields a real stylesheet URL — the dev server serves the
|
|
6
|
+
* file as CSS, and `vite build` emits it as a hashed `.css` asset. That
|
|
7
|
+
* makes it the right base for `<link>` hrefs and `@import url()`s inside
|
|
8
|
+
* shadow roots. The one gap is dev HMR: the imported URL string is identical
|
|
9
|
+
* across module re-executions, so the browser would keep the stale
|
|
10
|
+
* stylesheet. These helpers close that gap.
|
|
11
|
+
*
|
|
12
|
+
* This module is dependency-free and must stay safe to load in any
|
|
13
|
+
* environment.
|
|
14
|
+
*
|
|
15
|
+
* @module
|
|
5
16
|
*/
|
|
6
17
|
/**
|
|
7
18
|
* Appends a cache-busting query to a `?url`-imported CSS file URL in dev.
|
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":"
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../src/lib/runtime/css.ts"],"names":[],"mappings":"AACA;;;;;;;;;;;;;;;GAeG;AAaH;;;;;;;;;;;;;;;;;;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
|
@@ -1,8 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
* @license
|
|
3
|
-
* Copyright 2026 Google LLC
|
|
4
|
-
* SPDX-License-Identifier: BSD-3-Clause
|
|
5
|
-
*/
|
|
1
|
+
/* @ts-self-types="./css.d.ts" */
|
|
6
2
|
/**
|
|
7
3
|
* Browser helpers for referencing CSS files from shadow roots via Vite's
|
|
8
4
|
* `?url` imports.
|
|
@@ -16,6 +12,8 @@
|
|
|
16
12
|
*
|
|
17
13
|
* This module is dependency-free and must stay safe to load in any
|
|
18
14
|
* environment.
|
|
15
|
+
*
|
|
16
|
+
* @module
|
|
19
17
|
*/
|
|
20
18
|
/**
|
|
21
19
|
* Vite's dev flag. Accessed as a direct member expression (`import.meta.env.DEV`)
|
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
|
|
1
|
+
{"version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AK,CAAC,QAAQ,CAAC,CAAC,MAAM,EAAE,CAAC,CAAC;YAC/C,OAAO,CAAC,CAAC,IAAI,EAAE,CAAC;QAClB,CAAC,CAAC;aACD,IAAI,CAAC,CAAC,GAAG,EAAE,EAAE;YACZ,IAAI,KAAK,KAAK,MAAM,EAAE,CAAC;gBACrB,KAAK,CAAC,WAAW,CAAC,GAAG,CAAC,CAAC;YACzB,CAAC;QACH,CAAC,CAAC;aACD,KAAK,CAAC,CAAC,GAAY,EAAE,EAAE;YACtB,kEAAkE;YAClE,OAAO,CAAC,IAAI,CAAC,yCAAyC,IAAI,GAAG,EAAE,GAAG,CAAC,CAAC;QACtE,CAAC,CAAC,CAAC;IACP,CAAC,CAAC;IACF,KAAK,MAAM,CAAC,GAAG,CAAC,CAAC;IACjB,OAAO;QACL,KAAK;QACL,WAAW,EAAE,CAAC,GAAG,EAAE,EAAE;YACnB,MAAM,IAAI,GAAG,GAAG,EAAE,CAAC,SAAS,CAAC,CAAC;YAC9B,IAAI,OAAO,IAAI,KAAK,QAAQ,EAAE,CAAC;gBAC7B,KAAK,MAAM,CAAC,IAAI,CAAC,CAAC;YACpB,CAAC;QACH,CAAC;KACF,CAAC;AACJ,CAAC,CAAC","sourcesContent":["/* @ts-self-types=\"./css.d.ts\" */\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 * @module\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,7 +1,12 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Keeps our on-page dev UI (HMR indicator, source-overlay tooltip) clear of the
|
|
3
|
+
* Vite DevTools edge panel so they don't sit on top of it.
|
|
4
|
+
*
|
|
5
|
+
* The panel is `#vite-devtools-edge-panel` inside the open shadow root of the
|
|
6
|
+
* `<vite-devtools-dock-embedded>` host, and only exists while the dock is
|
|
7
|
+
* docked to an edge (it can be moved/resized). We report the inset, in px, that
|
|
8
|
+
* the panel occupies on each viewport edge it touches — plus a small gap — so
|
|
9
|
+
* callers can offset themselves.
|
|
5
10
|
*/
|
|
6
11
|
export interface EdgeInsets {
|
|
7
12
|
top: number;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"edge-panel.d.ts","sourceRoot":"","sources":["../../src/lib/runtime/edge-panel.ts"],"names":[],"mappings":"AAAA
|
|
1
|
+
{"version":3,"file":"edge-panel.d.ts","sourceRoot":"","sources":["../../src/lib/runtime/edge-panel.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AASH,MAAM,WAAW,UAAU;IACzB,GAAG,EAAE,MAAM,CAAC;IACZ,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;CACd;AAyCD;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,aAClB,CAAC,MAAM,EAAE,UAAU,KAAK,IAAI,KACrC,CAAC,MAAM,IAAI,CA+Db,CAAC"}
|