@microsoft/webui-framework 0.0.24 → 0.0.26
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/README.md +209 -53
- package/dist/component-asset/asset.d.ts +4 -2
- package/dist/component-asset/asset.js +19 -3
- package/dist/component-asset/generated-manifest.d.ts +1 -0
- package/dist/component-asset/generated-manifest.js +32 -0
- package/dist/component-asset/loader.d.ts +2 -1
- package/dist/component-asset/loader.js +98 -22
- package/dist/component-asset/manifest.d.ts +2 -1
- package/dist/component-asset.d.ts +1 -1
- package/dist/component-asset.js +12 -2
- package/dist/element/link-styles.d.ts +20 -0
- package/dist/element/link-styles.js +1030 -0
- package/dist/element/markers.d.ts +4 -0
- package/dist/element/markers.js +60 -5
- package/dist/element/styles.d.ts +39 -1
- package/dist/element/styles.js +623 -13
- package/dist/element/types.d.ts +5 -3
- package/dist/element.js +9 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.js +1 -0
- package/dist/interaction-hydration.d.ts +8 -0
- package/dist/interaction-hydration.js +167 -0
- package/dist/static-host.js +43 -1
- package/dist/streaming-activation.d.ts +2 -2
- package/dist/streaming-activation.js +4 -2
- package/dist/streaming-bootstrap.d.ts +2 -2
- package/dist/streaming-bootstrap.js +7 -1
- package/dist/streaming-cleanup.d.ts +1 -0
- package/dist/streaming-cleanup.js +66 -14
- package/dist/streaming-coordinator.d.ts +3 -2
- package/dist/streaming-coordinator.js +107 -47
- package/dist/streaming-deferred.d.ts +14 -4
- package/dist/streaming-deferred.js +200 -87
- package/dist/streaming-dom.d.ts +12 -3
- package/dist/streaming-dom.js +41 -27
- package/dist/streaming-mode.d.ts +5 -0
- package/dist/streaming-mode.js +4 -0
- package/dist/streaming-protocol.d.ts +19 -3
- package/dist/streaming-protocol.js +4 -3
- package/dist/streaming-spans.d.ts +9 -0
- package/dist/streaming-spans.js +200 -0
- package/dist/template-content.d.ts +17 -0
- package/dist/template-content.js +106 -0
- package/dist/template-element.d.ts +17 -2
- package/dist/template-element.js +493 -177
- package/dist/template-events.d.ts +7 -0
- package/dist/template-events.js +7 -1
- package/dist/template-types.d.ts +1 -2
- package/dist/template.d.ts +15 -8
- package/dist/template.js +79 -16
- package/package.json +9 -3
- package/dist/component-asset/resources.d.ts +0 -4
- package/dist/component-asset/resources.js +0 -83
|
@@ -0,0 +1,1030 @@
|
|
|
1
|
+
import { templateHtmlMayContainLink, getTemplateStylesheets, } from '../template-content.js';
|
|
2
|
+
const READY = Promise.resolve();
|
|
3
|
+
const NO_DESCRIPTORS = Object.freeze([]);
|
|
4
|
+
const NO_LINK_STYLE_STATE = {
|
|
5
|
+
descriptors: NO_DESCRIPTORS,
|
|
6
|
+
ready: READY,
|
|
7
|
+
};
|
|
8
|
+
const CSS_IMPORT_RULE = 3;
|
|
9
|
+
const STYLESHEET_PREPARATION_TIMEOUT_MS = 3_000;
|
|
10
|
+
const SPECULATIVE_PRELOAD_TTL_MS = 3_000;
|
|
11
|
+
const GUARD_CSS = '@layer{:host{transition:none!important;visibility:hidden!important}}';
|
|
12
|
+
const templateLinkStyles = new WeakMap();
|
|
13
|
+
const activeStyleMounts = new WeakMap();
|
|
14
|
+
let speculativeStylesheetPreloads;
|
|
15
|
+
export function prepareTemplateLinkStyles(meta) {
|
|
16
|
+
const ready = getTemplateLinkStyleState(meta).ready;
|
|
17
|
+
return ready === READY ? undefined : ready;
|
|
18
|
+
}
|
|
19
|
+
export function prepareRegisteredLinkStyles(templates) {
|
|
20
|
+
const names = Object.keys(templates);
|
|
21
|
+
let pending;
|
|
22
|
+
for (let i = 0; i < names.length; i++) {
|
|
23
|
+
const ready = prepareTemplateLinkStyles(templates[names[i]]);
|
|
24
|
+
if (!ready)
|
|
25
|
+
continue;
|
|
26
|
+
(pending ??= []).push(ready);
|
|
27
|
+
}
|
|
28
|
+
return pending ? Promise.all(pending).then(ignorePromiseResults) : undefined;
|
|
29
|
+
}
|
|
30
|
+
export function prepareComponentStyleLinks(styles) {
|
|
31
|
+
if (styles.strategy !== 'link')
|
|
32
|
+
return undefined;
|
|
33
|
+
const ids = Object.keys(styles.resources);
|
|
34
|
+
if (ids.length === 0)
|
|
35
|
+
return undefined;
|
|
36
|
+
const hrefs = [];
|
|
37
|
+
const seen = new Set();
|
|
38
|
+
for (let i = 0; i < ids.length; i++) {
|
|
39
|
+
const resource = styles.resources[ids[i]];
|
|
40
|
+
if (resource.kind !== 'link' || seen.has(resource.href))
|
|
41
|
+
continue;
|
|
42
|
+
seen.add(resource.href);
|
|
43
|
+
hrefs.push(resource.href);
|
|
44
|
+
}
|
|
45
|
+
return preloadComponentAssetStyles(hrefs);
|
|
46
|
+
}
|
|
47
|
+
export function preloadComponentAssetStyles(hrefs) {
|
|
48
|
+
if (hrefs.length === 0 || !supportsConstructableStylesheets())
|
|
49
|
+
return undefined;
|
|
50
|
+
const preloads = (speculativeStylesheetPreloads ??= new Map());
|
|
51
|
+
let pending;
|
|
52
|
+
for (let i = 0; i < hrefs.length; i++) {
|
|
53
|
+
if (hrefs[i].length === 0)
|
|
54
|
+
continue;
|
|
55
|
+
const href = resolveHref(hrefs[i]);
|
|
56
|
+
const existing = preloads.get(href);
|
|
57
|
+
if (existing) {
|
|
58
|
+
(pending ??= []).push(existing.ready);
|
|
59
|
+
continue;
|
|
60
|
+
}
|
|
61
|
+
if (hasDocumentStylesheetPreload(href))
|
|
62
|
+
continue;
|
|
63
|
+
const link = createStylesheetPreload(href);
|
|
64
|
+
const startedAt = performanceNow();
|
|
65
|
+
const preload = {
|
|
66
|
+
claimed: false,
|
|
67
|
+
link,
|
|
68
|
+
ready: waitForStylesheetPreload(link, href),
|
|
69
|
+
startedAt,
|
|
70
|
+
};
|
|
71
|
+
preloads.set(href, preload);
|
|
72
|
+
(pending ??= []).push(preload.ready);
|
|
73
|
+
preload.cleanupTimer = setTimeout(() => {
|
|
74
|
+
releaseStylesheetPreload(link);
|
|
75
|
+
}, SPECULATIVE_PRELOAD_TTL_MS);
|
|
76
|
+
}
|
|
77
|
+
return pending ? Promise.all(pending).then(ignorePromiseResults) : undefined;
|
|
78
|
+
}
|
|
79
|
+
export function installComponentLinkStyles(host, root, links) {
|
|
80
|
+
if (links.length === 0 || !supportsConstructableStylesheets())
|
|
81
|
+
return;
|
|
82
|
+
const mountStartedAt = performanceNow();
|
|
83
|
+
let timingStartedAt = mountStartedAt;
|
|
84
|
+
const preloads = [];
|
|
85
|
+
const pendingPreloads = [];
|
|
86
|
+
for (let i = 0; i < links.length; i++) {
|
|
87
|
+
const speculative = speculativeStylesheetPreloads?.get(resolveHref(links[i].href));
|
|
88
|
+
if (!speculative)
|
|
89
|
+
continue;
|
|
90
|
+
speculative.claimed = true;
|
|
91
|
+
preloads.push(speculative);
|
|
92
|
+
pendingPreloads.push(speculative.ready);
|
|
93
|
+
timingStartedAt = Math.min(timingStartedAt, speculative.startedAt);
|
|
94
|
+
}
|
|
95
|
+
const guard = installGuard(host, root);
|
|
96
|
+
const settled = new Uint8Array(links.length);
|
|
97
|
+
const loadHandlers = new Array(links.length);
|
|
98
|
+
const errorHandlers = new Array(links.length);
|
|
99
|
+
let remaining = 0;
|
|
100
|
+
let cancelled = false;
|
|
101
|
+
const releasePreloads = () => {
|
|
102
|
+
for (let i = 0; i < preloads.length; i++) {
|
|
103
|
+
releaseStylesheetPreload(preloads[i].link);
|
|
104
|
+
}
|
|
105
|
+
};
|
|
106
|
+
const cleanup = () => {
|
|
107
|
+
for (let i = 0; i < links.length; i++) {
|
|
108
|
+
const onLoad = loadHandlers[i];
|
|
109
|
+
const onError = errorHandlers[i];
|
|
110
|
+
if (onLoad)
|
|
111
|
+
links[i].removeEventListener('load', onLoad);
|
|
112
|
+
if (onError)
|
|
113
|
+
links[i].removeEventListener('error', onError);
|
|
114
|
+
}
|
|
115
|
+
releasePreloads();
|
|
116
|
+
};
|
|
117
|
+
const fail = () => {
|
|
118
|
+
if (cancelled)
|
|
119
|
+
return;
|
|
120
|
+
cancelled = true;
|
|
121
|
+
cleanup();
|
|
122
|
+
guard.release();
|
|
123
|
+
};
|
|
124
|
+
const finish = () => {
|
|
125
|
+
if (cancelled || remaining !== 0)
|
|
126
|
+
return;
|
|
127
|
+
void Promise.all(pendingPreloads).then(results => {
|
|
128
|
+
if (cancelled || results.some(result => result !== undefined)) {
|
|
129
|
+
fail();
|
|
130
|
+
return;
|
|
131
|
+
}
|
|
132
|
+
const sheets = constructComponentStylesheets(links, timingStartedAt);
|
|
133
|
+
if (!sheets || !adoptPreparedSheets(root, sheets)) {
|
|
134
|
+
fail();
|
|
135
|
+
return;
|
|
136
|
+
}
|
|
137
|
+
deactivatePromotedLinks(links);
|
|
138
|
+
cancelled = true;
|
|
139
|
+
cleanup();
|
|
140
|
+
guard.release();
|
|
141
|
+
});
|
|
142
|
+
};
|
|
143
|
+
const settle = (index) => {
|
|
144
|
+
if (cancelled || settled[index] !== 0)
|
|
145
|
+
return;
|
|
146
|
+
settled[index] = 1;
|
|
147
|
+
remaining -= 1;
|
|
148
|
+
const onLoad = loadHandlers[index];
|
|
149
|
+
const onError = errorHandlers[index];
|
|
150
|
+
if (onLoad)
|
|
151
|
+
links[index].removeEventListener('load', onLoad);
|
|
152
|
+
if (onError)
|
|
153
|
+
links[index].removeEventListener('error', onError);
|
|
154
|
+
finish();
|
|
155
|
+
};
|
|
156
|
+
for (let i = 0; i < links.length; i++) {
|
|
157
|
+
if (!requiresNativeLoad(links[i])) {
|
|
158
|
+
settled[i] = 1;
|
|
159
|
+
continue;
|
|
160
|
+
}
|
|
161
|
+
if (links[i].sheet) {
|
|
162
|
+
settled[i] = 1;
|
|
163
|
+
continue;
|
|
164
|
+
}
|
|
165
|
+
remaining += 1;
|
|
166
|
+
const onLoad = () => settle(i);
|
|
167
|
+
const onError = () => fail();
|
|
168
|
+
loadHandlers[i] = onLoad;
|
|
169
|
+
errorHandlers[i] = onError;
|
|
170
|
+
links[i].addEventListener('load', onLoad, { once: true });
|
|
171
|
+
links[i].addEventListener('error', onError, { once: true });
|
|
172
|
+
}
|
|
173
|
+
if (remaining === 0)
|
|
174
|
+
finish();
|
|
175
|
+
}
|
|
176
|
+
export function templateMayContainLinkStyles(meta) {
|
|
177
|
+
return getTemplateLinkStyleState(meta) !== NO_LINK_STYLE_STATE;
|
|
178
|
+
}
|
|
179
|
+
export function installTemplateLinkStyles(host, meta, shadowRoot, stagingRoot, bindings, deferredCallbacks) {
|
|
180
|
+
if (!shadowRoot)
|
|
181
|
+
return false;
|
|
182
|
+
const root = shadowRoot;
|
|
183
|
+
const links = collectStylesheetLinks(stagingRoot);
|
|
184
|
+
if (links.length === 0)
|
|
185
|
+
return false;
|
|
186
|
+
activeStyleMounts.get(root)?.();
|
|
187
|
+
const state = getTemplateLinkStyleState(meta);
|
|
188
|
+
let nativeOnly = hasBoundStylesheetLink(links, bindings) ||
|
|
189
|
+
hasEventStylesheetLink(meta, state.descriptors);
|
|
190
|
+
if (!nativeOnly &&
|
|
191
|
+
state.sheets &&
|
|
192
|
+
!deferredCallbacks?.hasAuthorHydrationLifecycle &&
|
|
193
|
+
!hasAuthorStyle(root, stagingRoot)) {
|
|
194
|
+
if (state.sheets.length === links.length && adoptPreparedSheets(root, state.sheets)) {
|
|
195
|
+
deactivatePromotedLinks(links);
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
nativeOnly = true;
|
|
199
|
+
}
|
|
200
|
+
const settled = new Uint8Array(links.length);
|
|
201
|
+
const loadHandlers = new Array(links.length);
|
|
202
|
+
const errorHandlers = new Array(links.length);
|
|
203
|
+
const mountStartedAt = performanceNow();
|
|
204
|
+
const timingStartedAt = state.preloadStartedAt === undefined
|
|
205
|
+
? mountStartedAt
|
|
206
|
+
: Math.min(state.preloadStartedAt, mountStartedAt);
|
|
207
|
+
let remaining = 0;
|
|
208
|
+
for (let i = 0; i < links.length; i++) {
|
|
209
|
+
if (requiresNativeLoad(links[i])) {
|
|
210
|
+
remaining += 1;
|
|
211
|
+
}
|
|
212
|
+
else {
|
|
213
|
+
settled[i] = 1;
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
if (remaining === 0)
|
|
217
|
+
return false;
|
|
218
|
+
let failed = false;
|
|
219
|
+
let cancelled = false;
|
|
220
|
+
let contentAppended = false;
|
|
221
|
+
let deferContent = false;
|
|
222
|
+
let guardStyle;
|
|
223
|
+
let releaseGuard;
|
|
224
|
+
const settle = (index) => {
|
|
225
|
+
if (cancelled || failed || settled[index] !== 0)
|
|
226
|
+
return;
|
|
227
|
+
settled[index] = 1;
|
|
228
|
+
remaining -= 1;
|
|
229
|
+
removeLinkListeners(index);
|
|
230
|
+
if (remaining === 0)
|
|
231
|
+
finishMount(true);
|
|
232
|
+
};
|
|
233
|
+
const fail = (index) => {
|
|
234
|
+
if (cancelled || failed)
|
|
235
|
+
return;
|
|
236
|
+
failed = true;
|
|
237
|
+
nativeOnly = true;
|
|
238
|
+
removeAllLinkListeners();
|
|
239
|
+
removeStylesheetPreloads(state);
|
|
240
|
+
const result = state.descriptors.length === links.length
|
|
241
|
+
? state.results?.[index]
|
|
242
|
+
: undefined;
|
|
243
|
+
const href = result?.href || links[index].href;
|
|
244
|
+
let reason = '';
|
|
245
|
+
if (result?.reason) {
|
|
246
|
+
reason = ` Constructable preparation failed: ${result.reason}.`;
|
|
247
|
+
}
|
|
248
|
+
console.error(`[WebUI] Stylesheet "${href}" failed to load for <${host.localName}>.${reason} ` +
|
|
249
|
+
'The component will continue with its native stylesheet links and may be unstyled.');
|
|
250
|
+
finishMount(false);
|
|
251
|
+
};
|
|
252
|
+
const tryAdoptNativeSheets = () => {
|
|
253
|
+
if (cancelled || nativeOnly)
|
|
254
|
+
return;
|
|
255
|
+
if (state.descriptors.length !== links.length) {
|
|
256
|
+
nativeOnly = true;
|
|
257
|
+
return;
|
|
258
|
+
}
|
|
259
|
+
let sheets = state.sheets;
|
|
260
|
+
if (!sheets) {
|
|
261
|
+
sheets = constructNativeStylesheets(links, state.descriptors, timingStartedAt);
|
|
262
|
+
if (!sheets) {
|
|
263
|
+
nativeOnly = true;
|
|
264
|
+
return;
|
|
265
|
+
}
|
|
266
|
+
state.sheets = sheets;
|
|
267
|
+
}
|
|
268
|
+
if (!adoptPreparedSheets(root, sheets)) {
|
|
269
|
+
nativeOnly = true;
|
|
270
|
+
return;
|
|
271
|
+
}
|
|
272
|
+
deactivatePromotedLinks(links);
|
|
273
|
+
};
|
|
274
|
+
function removeLinkListeners(index) {
|
|
275
|
+
const load = loadHandlers[index];
|
|
276
|
+
const error = errorHandlers[index];
|
|
277
|
+
if (load)
|
|
278
|
+
links[index].removeEventListener('load', load);
|
|
279
|
+
if (error)
|
|
280
|
+
links[index].removeEventListener('error', error);
|
|
281
|
+
}
|
|
282
|
+
function removeAllLinkListeners() {
|
|
283
|
+
for (let i = 0; i < links.length; i++)
|
|
284
|
+
removeLinkListeners(i);
|
|
285
|
+
}
|
|
286
|
+
function armLink(index) {
|
|
287
|
+
const onLoad = () => {
|
|
288
|
+
if (settled[index] === 0)
|
|
289
|
+
settle(index);
|
|
290
|
+
};
|
|
291
|
+
const onError = () => {
|
|
292
|
+
if (cancelled)
|
|
293
|
+
return;
|
|
294
|
+
fail(index);
|
|
295
|
+
};
|
|
296
|
+
loadHandlers[index] = onLoad;
|
|
297
|
+
errorHandlers[index] = onError;
|
|
298
|
+
links[index].addEventListener('load', onLoad, { once: true });
|
|
299
|
+
links[index].addEventListener('error', onError, { once: true });
|
|
300
|
+
}
|
|
301
|
+
function rearmChangedLinks(previousKeys) {
|
|
302
|
+
let rearmed = false;
|
|
303
|
+
for (let i = 0; i < links.length; i++) {
|
|
304
|
+
if (previousKeys[i] === nativeLoadKey(links[i]))
|
|
305
|
+
continue;
|
|
306
|
+
removeLinkListeners(i);
|
|
307
|
+
if (!requiresNativeLoad(links[i])) {
|
|
308
|
+
settled[i] = 1;
|
|
309
|
+
continue;
|
|
310
|
+
}
|
|
311
|
+
settled[i] = 0;
|
|
312
|
+
remaining += 1;
|
|
313
|
+
armLink(i);
|
|
314
|
+
rearmed = true;
|
|
315
|
+
}
|
|
316
|
+
return rearmed;
|
|
317
|
+
}
|
|
318
|
+
function clearActiveMount() {
|
|
319
|
+
if (activeStyleMounts.get(root) === cancel) {
|
|
320
|
+
activeStyleMounts.delete(root);
|
|
321
|
+
}
|
|
322
|
+
}
|
|
323
|
+
function appendDeferredContent() {
|
|
324
|
+
if (!deferContent || contentAppended)
|
|
325
|
+
return false;
|
|
326
|
+
contentAppended = true;
|
|
327
|
+
while (stagingRoot.firstChild) {
|
|
328
|
+
root.appendChild(stagingRoot.firstChild);
|
|
329
|
+
}
|
|
330
|
+
return true;
|
|
331
|
+
}
|
|
332
|
+
function finishMount(reconcileLinks) {
|
|
333
|
+
if (deferContent && !contentAppended) {
|
|
334
|
+
const loadKeys = reconcileLinks ? captureNativeLoadKeys(links) : undefined;
|
|
335
|
+
deferredCallbacks?.beforeAppend?.();
|
|
336
|
+
if (loadKeys && rearmChangedLinks(loadKeys))
|
|
337
|
+
return;
|
|
338
|
+
}
|
|
339
|
+
const appended = appendDeferredContent();
|
|
340
|
+
if (appended) {
|
|
341
|
+
try {
|
|
342
|
+
deferredCallbacks?.afterAppend?.();
|
|
343
|
+
}
|
|
344
|
+
finally {
|
|
345
|
+
finishStyleMount();
|
|
346
|
+
}
|
|
347
|
+
}
|
|
348
|
+
else {
|
|
349
|
+
finishStyleMount();
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
function finishStyleMount() {
|
|
353
|
+
const hasAuthoredStyle = !nativeOnly && hasAuthorStyle(root, stagingRoot, guardStyle);
|
|
354
|
+
releaseGuard?.();
|
|
355
|
+
releaseGuard = undefined;
|
|
356
|
+
removeStylesheetPreloads(state);
|
|
357
|
+
clearActiveMount();
|
|
358
|
+
if (!nativeOnly &&
|
|
359
|
+
!hasAuthoredStyle &&
|
|
360
|
+
state.descriptors.length === links.length) {
|
|
361
|
+
tryAdoptNativeSheets();
|
|
362
|
+
}
|
|
363
|
+
}
|
|
364
|
+
const cancel = (discardRoot = false) => {
|
|
365
|
+
if (cancelled)
|
|
366
|
+
return;
|
|
367
|
+
cancelled = true;
|
|
368
|
+
removeAllLinkListeners();
|
|
369
|
+
releaseGuard?.();
|
|
370
|
+
releaseGuard = undefined;
|
|
371
|
+
removeStylesheetPreloads(state);
|
|
372
|
+
if (discardRoot)
|
|
373
|
+
root.replaceChildren();
|
|
374
|
+
clearActiveMount();
|
|
375
|
+
};
|
|
376
|
+
activeStyleMounts.set(root, cancel);
|
|
377
|
+
const guard = installGuard(host, root);
|
|
378
|
+
guardStyle = guard.style;
|
|
379
|
+
releaseGuard = guard.release;
|
|
380
|
+
deferContent = !guard.effective;
|
|
381
|
+
for (let i = 0; i < links.length; i++) {
|
|
382
|
+
if (settled[i] !== 0)
|
|
383
|
+
continue;
|
|
384
|
+
armLink(i);
|
|
385
|
+
}
|
|
386
|
+
if (deferContent) {
|
|
387
|
+
for (let i = 0; i < links.length; i++)
|
|
388
|
+
root.appendChild(links[i]);
|
|
389
|
+
}
|
|
390
|
+
return deferContent;
|
|
391
|
+
}
|
|
392
|
+
export function cancelTemplateLinkStyleMount(root) {
|
|
393
|
+
const cancel = activeStyleMounts.get(root);
|
|
394
|
+
if (!cancel)
|
|
395
|
+
return false;
|
|
396
|
+
cancel(true);
|
|
397
|
+
return true;
|
|
398
|
+
}
|
|
399
|
+
export function rewriteCssUrls(cssText, stylesheetHref) {
|
|
400
|
+
let quote = 0;
|
|
401
|
+
let output = '';
|
|
402
|
+
let copiedThrough = 0;
|
|
403
|
+
for (let i = 0; i < cssText.length; i++) {
|
|
404
|
+
const code = cssText.charCodeAt(i);
|
|
405
|
+
if (quote !== 0) {
|
|
406
|
+
if (code === 92) {
|
|
407
|
+
i += 1;
|
|
408
|
+
}
|
|
409
|
+
else if (code === quote) {
|
|
410
|
+
quote = 0;
|
|
411
|
+
}
|
|
412
|
+
continue;
|
|
413
|
+
}
|
|
414
|
+
if (code === 34 || code === 39) {
|
|
415
|
+
quote = code;
|
|
416
|
+
continue;
|
|
417
|
+
}
|
|
418
|
+
if (code === 47 && cssText.charCodeAt(i + 1) === 42) {
|
|
419
|
+
i = skipComment(cssText, i + 2);
|
|
420
|
+
continue;
|
|
421
|
+
}
|
|
422
|
+
if (code === 92)
|
|
423
|
+
return undefined;
|
|
424
|
+
if (matchesCssFunction(cssText, i, 'image-set') ||
|
|
425
|
+
matchesCssFunction(cssText, i, '-webkit-image-set')) {
|
|
426
|
+
return undefined;
|
|
427
|
+
}
|
|
428
|
+
if (!matchesCssFunction(cssText, i, 'url'))
|
|
429
|
+
continue;
|
|
430
|
+
const token = readUrlToken(cssText, i + 3);
|
|
431
|
+
if (!token)
|
|
432
|
+
return undefined;
|
|
433
|
+
const value = cssText.slice(token.valueStart, token.valueEnd);
|
|
434
|
+
if (value.length > 0 && value.charCodeAt(0) !== 35) {
|
|
435
|
+
let resolved;
|
|
436
|
+
try {
|
|
437
|
+
resolved = new URL(value, stylesheetHref).href;
|
|
438
|
+
}
|
|
439
|
+
catch {
|
|
440
|
+
return undefined;
|
|
441
|
+
}
|
|
442
|
+
output += cssText.slice(copiedThrough, token.valueStart);
|
|
443
|
+
output += token.quoted
|
|
444
|
+
? escapeCssString(resolved, token.quote)
|
|
445
|
+
: `"${escapeCssString(resolved, 34)}"`;
|
|
446
|
+
copiedThrough = token.valueEnd;
|
|
447
|
+
}
|
|
448
|
+
i = token.closeIndex;
|
|
449
|
+
}
|
|
450
|
+
if (copiedThrough === 0)
|
|
451
|
+
return cssText;
|
|
452
|
+
output += cssText.slice(copiedThrough);
|
|
453
|
+
return output;
|
|
454
|
+
}
|
|
455
|
+
function getTemplateLinkStyleState(meta) {
|
|
456
|
+
const cached = templateLinkStyles.get(meta);
|
|
457
|
+
if (cached)
|
|
458
|
+
return cached;
|
|
459
|
+
if (!templateHtmlMayContainLink(meta.h)) {
|
|
460
|
+
templateLinkStyles.set(meta, NO_LINK_STYLE_STATE);
|
|
461
|
+
return NO_LINK_STYLE_STATE;
|
|
462
|
+
}
|
|
463
|
+
const descriptors = getTemplateStylesheets(meta);
|
|
464
|
+
if (!descriptors) {
|
|
465
|
+
templateLinkStyles.set(meta, NO_LINK_STYLE_STATE);
|
|
466
|
+
return NO_LINK_STYLE_STATE;
|
|
467
|
+
}
|
|
468
|
+
const state = {
|
|
469
|
+
descriptors,
|
|
470
|
+
ready: READY,
|
|
471
|
+
};
|
|
472
|
+
templateLinkStyles.set(meta, state);
|
|
473
|
+
if (descriptors.length === 0)
|
|
474
|
+
return state;
|
|
475
|
+
if (!supportsConstructableStylesheets()) {
|
|
476
|
+
state.results = fallbackResults(descriptors, 'Constructable stylesheets are unavailable');
|
|
477
|
+
return state;
|
|
478
|
+
}
|
|
479
|
+
const pending = new Array(descriptors.length);
|
|
480
|
+
for (let i = 0; i < descriptors.length; i++) {
|
|
481
|
+
pending[i] = warmStylesheet(descriptors[i], state);
|
|
482
|
+
}
|
|
483
|
+
state.ready = Promise.all(pending).then(results => {
|
|
484
|
+
state.results = results;
|
|
485
|
+
});
|
|
486
|
+
return state;
|
|
487
|
+
}
|
|
488
|
+
function supportsConstructableStylesheets() {
|
|
489
|
+
return (typeof CSSStyleSheet === 'function' &&
|
|
490
|
+
typeof ShadowRoot === 'function' &&
|
|
491
|
+
'adoptedStyleSheets' in ShadowRoot.prototype &&
|
|
492
|
+
typeof CSSStyleSheet.prototype.replaceSync === 'function' &&
|
|
493
|
+
typeof document === 'object' &&
|
|
494
|
+
document.head !== null);
|
|
495
|
+
}
|
|
496
|
+
function performanceNow() {
|
|
497
|
+
return typeof performance === 'object' && typeof performance.now === 'function'
|
|
498
|
+
? performance.now()
|
|
499
|
+
: Number.POSITIVE_INFINITY;
|
|
500
|
+
}
|
|
501
|
+
function removeStylesheetPreloads(state) {
|
|
502
|
+
const preloads = state.preloads;
|
|
503
|
+
if (!preloads)
|
|
504
|
+
return;
|
|
505
|
+
state.preloads = undefined;
|
|
506
|
+
void state.ready.then(() => {
|
|
507
|
+
for (let i = 0; i < preloads.length; i++) {
|
|
508
|
+
releaseStylesheetPreload(preloads[i]);
|
|
509
|
+
}
|
|
510
|
+
});
|
|
511
|
+
}
|
|
512
|
+
function warmStylesheet(descriptor, state) {
|
|
513
|
+
const href = resolveHref(descriptor.href);
|
|
514
|
+
const fallbackReason = unsupportedLinkReason(descriptor);
|
|
515
|
+
const speculative = speculativeStylesheetPreloads?.get(href);
|
|
516
|
+
if (fallbackReason) {
|
|
517
|
+
if (speculative && !speculative.claimed) {
|
|
518
|
+
releaseStylesheetPreload(speculative.link);
|
|
519
|
+
}
|
|
520
|
+
return Promise.resolve({ href, reason: fallbackReason });
|
|
521
|
+
}
|
|
522
|
+
if (speculative && hasDefaultPreloadAttributes(descriptor)) {
|
|
523
|
+
speculative.claimed = true;
|
|
524
|
+
trackStylesheetPreload(state, speculative.link, speculative.startedAt);
|
|
525
|
+
return speculative.ready;
|
|
526
|
+
}
|
|
527
|
+
if (speculative && !speculative.claimed) {
|
|
528
|
+
releaseStylesheetPreload(speculative.link);
|
|
529
|
+
}
|
|
530
|
+
const preload = createStylesheetPreload(href, descriptor);
|
|
531
|
+
const startedAt = performanceNow();
|
|
532
|
+
trackStylesheetPreload(state, preload, startedAt);
|
|
533
|
+
return waitForStylesheetPreload(preload, href);
|
|
534
|
+
}
|
|
535
|
+
function createStylesheetPreload(href, descriptor) {
|
|
536
|
+
const preload = document.createElement('link');
|
|
537
|
+
preload.rel = 'preload';
|
|
538
|
+
preload.as = 'style';
|
|
539
|
+
preload.href = href;
|
|
540
|
+
if (descriptor?.crossOrigin !== null && descriptor?.crossOrigin !== undefined) {
|
|
541
|
+
preload.crossOrigin = descriptor.crossOrigin;
|
|
542
|
+
}
|
|
543
|
+
if (descriptor?.integrity)
|
|
544
|
+
preload.integrity = descriptor.integrity;
|
|
545
|
+
if (descriptor?.referrerPolicy) {
|
|
546
|
+
preload.referrerPolicy = descriptor.referrerPolicy;
|
|
547
|
+
}
|
|
548
|
+
return preload;
|
|
549
|
+
}
|
|
550
|
+
function waitForStylesheetPreload(preload, href) {
|
|
551
|
+
return new Promise(resolve => {
|
|
552
|
+
let settled = false;
|
|
553
|
+
const finish = (reason) => {
|
|
554
|
+
if (settled)
|
|
555
|
+
return;
|
|
556
|
+
settled = true;
|
|
557
|
+
clearTimeout(timeout);
|
|
558
|
+
preload.onload = null;
|
|
559
|
+
preload.onerror = null;
|
|
560
|
+
resolve(reason ? { href, reason } : undefined);
|
|
561
|
+
};
|
|
562
|
+
const timeout = setTimeout(() => {
|
|
563
|
+
finish(`preparation timed out after ${STYLESHEET_PREPARATION_TIMEOUT_MS}ms`);
|
|
564
|
+
}, STYLESHEET_PREPARATION_TIMEOUT_MS);
|
|
565
|
+
preload.onload = () => finish();
|
|
566
|
+
preload.onerror = () => finish('stylesheet preload failed');
|
|
567
|
+
try {
|
|
568
|
+
document.head.appendChild(preload);
|
|
569
|
+
}
|
|
570
|
+
catch (error) {
|
|
571
|
+
finish(errorMessage(error));
|
|
572
|
+
}
|
|
573
|
+
});
|
|
574
|
+
}
|
|
575
|
+
function trackStylesheetPreload(state, preload, startedAt) {
|
|
576
|
+
(state.preloads ??= []).push(preload);
|
|
577
|
+
state.preloadStartedAt = state.preloadStartedAt === undefined
|
|
578
|
+
? startedAt
|
|
579
|
+
: Math.min(state.preloadStartedAt, startedAt);
|
|
580
|
+
}
|
|
581
|
+
function releaseStylesheetPreload(preload) {
|
|
582
|
+
const speculative = speculativeStylesheetPreloads?.get(preload.href);
|
|
583
|
+
if (speculative?.link === preload) {
|
|
584
|
+
if (speculative.cleanupTimer !== undefined) {
|
|
585
|
+
clearTimeout(speculative.cleanupTimer);
|
|
586
|
+
}
|
|
587
|
+
speculativeStylesheetPreloads?.delete(preload.href);
|
|
588
|
+
}
|
|
589
|
+
preload.remove();
|
|
590
|
+
}
|
|
591
|
+
function hasDocumentStylesheetPreload(href) {
|
|
592
|
+
const head = document.head;
|
|
593
|
+
if (typeof head.querySelectorAll !== 'function')
|
|
594
|
+
return false;
|
|
595
|
+
const candidates = head.querySelectorAll('link[rel="preload"][as="style"]');
|
|
596
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
597
|
+
if (resolveHref(candidates[i].href) === href)
|
|
598
|
+
return true;
|
|
599
|
+
}
|
|
600
|
+
return false;
|
|
601
|
+
}
|
|
602
|
+
function hasDefaultPreloadAttributes(descriptor) {
|
|
603
|
+
return (descriptor.crossOrigin === null &&
|
|
604
|
+
descriptor.integrity.length === 0 &&
|
|
605
|
+
descriptor.referrerPolicy.length === 0);
|
|
606
|
+
}
|
|
607
|
+
function fallbackResults(descriptors, reason) {
|
|
608
|
+
const results = new Array(descriptors.length);
|
|
609
|
+
for (let i = 0; i < descriptors.length; i++) {
|
|
610
|
+
results[i] = {
|
|
611
|
+
href: resolveHref(descriptors[i].href),
|
|
612
|
+
reason,
|
|
613
|
+
};
|
|
614
|
+
}
|
|
615
|
+
return results;
|
|
616
|
+
}
|
|
617
|
+
function unsupportedLinkReason(descriptor) {
|
|
618
|
+
if (descriptor.disabled)
|
|
619
|
+
return 'disabled stylesheets require native link loading';
|
|
620
|
+
if (descriptor.title)
|
|
621
|
+
return 'titled stylesheets require native link loading';
|
|
622
|
+
if (descriptor.hasUnsupportedAttributes) {
|
|
623
|
+
return 'unsupported link attributes require native link loading';
|
|
624
|
+
}
|
|
625
|
+
if (descriptor.hasInlineStyles) {
|
|
626
|
+
return 'mixed inline and external shadow styles require native link cascade order';
|
|
627
|
+
}
|
|
628
|
+
if (descriptor.type && descriptor.type.toLowerCase() !== 'text/css') {
|
|
629
|
+
return `stylesheet type "${descriptor.type}" requires native link loading`;
|
|
630
|
+
}
|
|
631
|
+
if (descriptor.referrerPolicy &&
|
|
632
|
+
!isReferrerPolicy(descriptor.referrerPolicy)) {
|
|
633
|
+
return 'unsupported referrer policy requires native link loading';
|
|
634
|
+
}
|
|
635
|
+
return undefined;
|
|
636
|
+
}
|
|
637
|
+
function resolveHref(href) {
|
|
638
|
+
try {
|
|
639
|
+
return new URL(href, document.baseURI).href;
|
|
640
|
+
}
|
|
641
|
+
catch {
|
|
642
|
+
return href;
|
|
643
|
+
}
|
|
644
|
+
}
|
|
645
|
+
function collectStylesheetLinks(root) {
|
|
646
|
+
const candidates = root.querySelectorAll('link[rel]');
|
|
647
|
+
const links = [];
|
|
648
|
+
for (let i = 0; i < candidates.length; i++) {
|
|
649
|
+
const link = candidates[i];
|
|
650
|
+
if (link.relList.contains('stylesheet') &&
|
|
651
|
+
!link.relList.contains('alternate') &&
|
|
652
|
+
link.hasAttribute('href')) {
|
|
653
|
+
links.push(link);
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
return links;
|
|
657
|
+
}
|
|
658
|
+
function requiresNativeLoad(link) {
|
|
659
|
+
if (!link.relList.contains('stylesheet') ||
|
|
660
|
+
link.relList.contains('alternate') ||
|
|
661
|
+
!link.hasAttribute('href')) {
|
|
662
|
+
return false;
|
|
663
|
+
}
|
|
664
|
+
if (link.disabled)
|
|
665
|
+
return false;
|
|
666
|
+
const type = link.type.toLowerCase();
|
|
667
|
+
return type.length === 0 || type === 'text/css';
|
|
668
|
+
}
|
|
669
|
+
function captureNativeLoadKeys(links) {
|
|
670
|
+
const keys = new Array(links.length);
|
|
671
|
+
for (let i = 0; i < links.length; i++)
|
|
672
|
+
keys[i] = nativeLoadKey(links[i]);
|
|
673
|
+
return keys;
|
|
674
|
+
}
|
|
675
|
+
function nativeLoadKey(link) {
|
|
676
|
+
return [
|
|
677
|
+
link.disabled ? '1' : '0',
|
|
678
|
+
link.rel,
|
|
679
|
+
link.href,
|
|
680
|
+
link.type,
|
|
681
|
+
link.crossOrigin ?? '',
|
|
682
|
+
link.integrity,
|
|
683
|
+
link.referrerPolicy,
|
|
684
|
+
].join('\0');
|
|
685
|
+
}
|
|
686
|
+
function deactivatePromotedLinks(links) {
|
|
687
|
+
for (let i = 0; i < links.length; i++)
|
|
688
|
+
links[i].disabled = true;
|
|
689
|
+
}
|
|
690
|
+
function hasBoundStylesheetLink(links, bindings) {
|
|
691
|
+
for (let i = 0; i < bindings.length; i++) {
|
|
692
|
+
const element = bindings[i].element;
|
|
693
|
+
for (let linkIndex = 0; linkIndex < links.length; linkIndex++) {
|
|
694
|
+
if (element === links[linkIndex])
|
|
695
|
+
return true;
|
|
696
|
+
}
|
|
697
|
+
}
|
|
698
|
+
return false;
|
|
699
|
+
}
|
|
700
|
+
function hasEventStylesheetLink(meta, descriptors) {
|
|
701
|
+
const groups = meta.eg;
|
|
702
|
+
if (!groups)
|
|
703
|
+
return false;
|
|
704
|
+
for (let groupIndex = 0; groupIndex < groups.length; groupIndex++) {
|
|
705
|
+
const eventBindings = groups[groupIndex][1];
|
|
706
|
+
for (let bindingIndex = 0; bindingIndex < eventBindings.length; bindingIndex++) {
|
|
707
|
+
const target = eventBindings[bindingIndex][2];
|
|
708
|
+
for (let descriptorIndex = 0; descriptorIndex < descriptors.length; descriptorIndex++) {
|
|
709
|
+
if (descriptors[descriptorIndex].elementIndex === target)
|
|
710
|
+
return true;
|
|
711
|
+
}
|
|
712
|
+
}
|
|
713
|
+
}
|
|
714
|
+
return false;
|
|
715
|
+
}
|
|
716
|
+
function constructNativeStylesheets(links, descriptors, mountStartedAt) {
|
|
717
|
+
const sheets = new Array(links.length);
|
|
718
|
+
for (let i = 0; i < links.length; i++) {
|
|
719
|
+
if (unsupportedLinkReason(descriptors[i]))
|
|
720
|
+
return undefined;
|
|
721
|
+
const cssText = readNativeStylesheet(links[i], mountStartedAt);
|
|
722
|
+
if (cssText === undefined)
|
|
723
|
+
return undefined;
|
|
724
|
+
const options = { baseURL: links[i].href };
|
|
725
|
+
if (descriptors[i].media)
|
|
726
|
+
options.media = descriptors[i].media;
|
|
727
|
+
try {
|
|
728
|
+
const sheet = new CSSStyleSheet(options);
|
|
729
|
+
sheet.replaceSync(cssText);
|
|
730
|
+
sheets[i] = sheet;
|
|
731
|
+
}
|
|
732
|
+
catch {
|
|
733
|
+
return undefined;
|
|
734
|
+
}
|
|
735
|
+
}
|
|
736
|
+
return sheets;
|
|
737
|
+
}
|
|
738
|
+
function constructComponentStylesheets(links, mountStartedAt) {
|
|
739
|
+
const sheets = new Array(links.length);
|
|
740
|
+
for (let i = 0; i < links.length; i++) {
|
|
741
|
+
const cssText = readNativeStylesheet(links[i], mountStartedAt);
|
|
742
|
+
if (cssText === undefined)
|
|
743
|
+
return undefined;
|
|
744
|
+
try {
|
|
745
|
+
const sheet = new CSSStyleSheet({ baseURL: links[i].href });
|
|
746
|
+
sheet.replaceSync(cssText);
|
|
747
|
+
sheets[i] = sheet;
|
|
748
|
+
}
|
|
749
|
+
catch {
|
|
750
|
+
return undefined;
|
|
751
|
+
}
|
|
752
|
+
}
|
|
753
|
+
return sheets;
|
|
754
|
+
}
|
|
755
|
+
function readNativeStylesheet(link, mountStartedAt) {
|
|
756
|
+
if (!hasUnredirectedNativeTiming(link, mountStartedAt))
|
|
757
|
+
return undefined;
|
|
758
|
+
const sheet = link.sheet;
|
|
759
|
+
if (!sheet)
|
|
760
|
+
return undefined;
|
|
761
|
+
let rules;
|
|
762
|
+
try {
|
|
763
|
+
rules = sheet.cssRules;
|
|
764
|
+
}
|
|
765
|
+
catch {
|
|
766
|
+
return undefined;
|
|
767
|
+
}
|
|
768
|
+
const rewritten = new Array(rules.length);
|
|
769
|
+
for (let i = 0; i < rules.length; i++) {
|
|
770
|
+
const rule = rules[i];
|
|
771
|
+
if (rule.type === CSS_IMPORT_RULE)
|
|
772
|
+
return undefined;
|
|
773
|
+
const cssText = rewriteCssUrls(rule.cssText, link.href);
|
|
774
|
+
if (cssText === undefined)
|
|
775
|
+
return undefined;
|
|
776
|
+
rewritten[i] = cssText;
|
|
777
|
+
}
|
|
778
|
+
return rewritten.join('\n');
|
|
779
|
+
}
|
|
780
|
+
function hasUnredirectedNativeTiming(link, mountStartedAt) {
|
|
781
|
+
if (typeof performance !== 'object' ||
|
|
782
|
+
typeof performance.getEntriesByName !== 'function') {
|
|
783
|
+
return false;
|
|
784
|
+
}
|
|
785
|
+
const entries = performance.getEntriesByName(link.href, 'resource');
|
|
786
|
+
for (let i = entries.length - 1; i >= 0; i--) {
|
|
787
|
+
const entry = entries[i];
|
|
788
|
+
if (entry.initiatorType !== 'link' ||
|
|
789
|
+
entry.startTime + 1 < mountStartedAt) {
|
|
790
|
+
continue;
|
|
791
|
+
}
|
|
792
|
+
if (entry.redirectStart !== 0 || entry.redirectEnd !== 0)
|
|
793
|
+
return false;
|
|
794
|
+
if (entry.workerStart !== 0)
|
|
795
|
+
return false;
|
|
796
|
+
const status = entry.responseStatus;
|
|
797
|
+
if (typeof status === 'number' && status !== 0) {
|
|
798
|
+
return status >= 200 && status < 300;
|
|
799
|
+
}
|
|
800
|
+
return (entry.transferSize > 0 ||
|
|
801
|
+
entry.encodedBodySize > 0 ||
|
|
802
|
+
entry.decodedBodySize > 0);
|
|
803
|
+
}
|
|
804
|
+
return false;
|
|
805
|
+
}
|
|
806
|
+
function adoptPreparedSheets(root, sheets) {
|
|
807
|
+
if (!('adoptedStyleSheets' in root))
|
|
808
|
+
return false;
|
|
809
|
+
const current = root.adoptedStyleSheets;
|
|
810
|
+
if (current.length === 0) {
|
|
811
|
+
try {
|
|
812
|
+
root.adoptedStyleSheets = sheets;
|
|
813
|
+
return true;
|
|
814
|
+
}
|
|
815
|
+
catch {
|
|
816
|
+
return false;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
819
|
+
let retained = 0;
|
|
820
|
+
for (let i = 0; i < current.length; i++) {
|
|
821
|
+
let prepared = false;
|
|
822
|
+
for (let sheetIndex = 0; sheetIndex < sheets.length; sheetIndex++) {
|
|
823
|
+
if (current[i] === sheets[sheetIndex]) {
|
|
824
|
+
prepared = true;
|
|
825
|
+
break;
|
|
826
|
+
}
|
|
827
|
+
}
|
|
828
|
+
if (!prepared)
|
|
829
|
+
retained += 1;
|
|
830
|
+
}
|
|
831
|
+
const next = new Array(sheets.length + retained);
|
|
832
|
+
for (let i = 0; i < sheets.length; i++)
|
|
833
|
+
next[i] = sheets[i];
|
|
834
|
+
let index = sheets.length;
|
|
835
|
+
for (let i = 0; i < current.length; i++) {
|
|
836
|
+
let prepared = false;
|
|
837
|
+
for (let sheetIndex = 0; sheetIndex < sheets.length; sheetIndex++) {
|
|
838
|
+
if (current[i] === sheets[sheetIndex]) {
|
|
839
|
+
prepared = true;
|
|
840
|
+
break;
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
if (!prepared) {
|
|
844
|
+
next[index] = current[i];
|
|
845
|
+
index += 1;
|
|
846
|
+
}
|
|
847
|
+
}
|
|
848
|
+
try {
|
|
849
|
+
root.adoptedStyleSheets = next;
|
|
850
|
+
return true;
|
|
851
|
+
}
|
|
852
|
+
catch {
|
|
853
|
+
return false;
|
|
854
|
+
}
|
|
855
|
+
}
|
|
856
|
+
function hasAuthorStyle(root, stagingRoot, guard) {
|
|
857
|
+
const mounted = root.querySelectorAll('style');
|
|
858
|
+
for (let i = 0; i < mounted.length; i++) {
|
|
859
|
+
if (mounted[i] !== guard)
|
|
860
|
+
return true;
|
|
861
|
+
}
|
|
862
|
+
return stagingRoot.querySelector('style') !== null;
|
|
863
|
+
}
|
|
864
|
+
function installGuard(host, root) {
|
|
865
|
+
const style = document.createElement('style');
|
|
866
|
+
const nonce = window.__webui?.nonce;
|
|
867
|
+
if (typeof nonce === 'string' && nonce)
|
|
868
|
+
style.nonce = nonce;
|
|
869
|
+
style.textContent = GUARD_CSS;
|
|
870
|
+
root.prepend(style);
|
|
871
|
+
let effective = false;
|
|
872
|
+
try {
|
|
873
|
+
effective = (style.sheet?.cssRules.length ?? 0) > 0;
|
|
874
|
+
}
|
|
875
|
+
catch {
|
|
876
|
+
effective = false;
|
|
877
|
+
}
|
|
878
|
+
const previousTransitionValue = host.style.getPropertyValue('transition-property');
|
|
879
|
+
const previousTransitionPriority = host.style.getPropertyPriority('transition-property');
|
|
880
|
+
const previousValue = host.style.getPropertyValue('visibility');
|
|
881
|
+
const previousPriority = host.style.getPropertyPriority('visibility');
|
|
882
|
+
host.style.setProperty('transition-property', 'none', 'important');
|
|
883
|
+
host.style.setProperty('visibility', 'hidden', 'important');
|
|
884
|
+
return {
|
|
885
|
+
effective,
|
|
886
|
+
release: () => {
|
|
887
|
+
style.remove();
|
|
888
|
+
if (host.style.getPropertyValue('visibility') === 'hidden' &&
|
|
889
|
+
host.style.getPropertyPriority('visibility') === 'important') {
|
|
890
|
+
if (previousValue) {
|
|
891
|
+
host.style.setProperty('visibility', previousValue, previousPriority);
|
|
892
|
+
}
|
|
893
|
+
else {
|
|
894
|
+
host.style.removeProperty('visibility');
|
|
895
|
+
}
|
|
896
|
+
}
|
|
897
|
+
if (host.style.getPropertyValue('transition-property') === 'none' &&
|
|
898
|
+
host.style.getPropertyPriority('transition-property') === 'important') {
|
|
899
|
+
if (previousTransitionValue) {
|
|
900
|
+
host.style.setProperty('transition-property', previousTransitionValue, previousTransitionPriority);
|
|
901
|
+
}
|
|
902
|
+
else {
|
|
903
|
+
host.style.removeProperty('transition-property');
|
|
904
|
+
}
|
|
905
|
+
}
|
|
906
|
+
},
|
|
907
|
+
style,
|
|
908
|
+
};
|
|
909
|
+
}
|
|
910
|
+
function skipComment(cssText, start) {
|
|
911
|
+
for (let i = start; i < cssText.length - 1; i++) {
|
|
912
|
+
if (cssText.charCodeAt(i) === 42 && cssText.charCodeAt(i + 1) === 47) {
|
|
913
|
+
return i + 1;
|
|
914
|
+
}
|
|
915
|
+
}
|
|
916
|
+
return cssText.length;
|
|
917
|
+
}
|
|
918
|
+
function readUrlToken(cssText, openIndex) {
|
|
919
|
+
let cursor = openIndex + 1;
|
|
920
|
+
while (isCssWhitespace(cssText.charCodeAt(cursor)))
|
|
921
|
+
cursor += 1;
|
|
922
|
+
const quote = cssText.charCodeAt(cursor);
|
|
923
|
+
if (quote === 34 || quote === 39) {
|
|
924
|
+
const valueStart = cursor + 1;
|
|
925
|
+
cursor = valueStart;
|
|
926
|
+
while (cursor < cssText.length) {
|
|
927
|
+
const code = cssText.charCodeAt(cursor);
|
|
928
|
+
if (code === 92)
|
|
929
|
+
return undefined;
|
|
930
|
+
if (code === quote)
|
|
931
|
+
break;
|
|
932
|
+
cursor += 1;
|
|
933
|
+
}
|
|
934
|
+
if (cursor >= cssText.length)
|
|
935
|
+
return undefined;
|
|
936
|
+
const valueEnd = cursor;
|
|
937
|
+
cursor += 1;
|
|
938
|
+
while (isCssWhitespace(cssText.charCodeAt(cursor)))
|
|
939
|
+
cursor += 1;
|
|
940
|
+
if (cssText.charCodeAt(cursor) !== 41)
|
|
941
|
+
return undefined;
|
|
942
|
+
return {
|
|
943
|
+
closeIndex: cursor,
|
|
944
|
+
quote,
|
|
945
|
+
quoted: true,
|
|
946
|
+
valueEnd,
|
|
947
|
+
valueStart,
|
|
948
|
+
};
|
|
949
|
+
}
|
|
950
|
+
const valueStart = cursor;
|
|
951
|
+
while (cursor < cssText.length && cssText.charCodeAt(cursor) !== 41) {
|
|
952
|
+
const code = cssText.charCodeAt(cursor);
|
|
953
|
+
if (code === 34 ||
|
|
954
|
+
code === 39 ||
|
|
955
|
+
code === 40 ||
|
|
956
|
+
code === 92 ||
|
|
957
|
+
(code === 47 && cssText.charCodeAt(cursor + 1) === 42)) {
|
|
958
|
+
return undefined;
|
|
959
|
+
}
|
|
960
|
+
cursor += 1;
|
|
961
|
+
}
|
|
962
|
+
if (cursor >= cssText.length)
|
|
963
|
+
return undefined;
|
|
964
|
+
let valueEnd = cursor;
|
|
965
|
+
while (valueEnd > valueStart &&
|
|
966
|
+
isCssWhitespace(cssText.charCodeAt(valueEnd - 1))) {
|
|
967
|
+
valueEnd -= 1;
|
|
968
|
+
}
|
|
969
|
+
return {
|
|
970
|
+
closeIndex: cursor,
|
|
971
|
+
quote: 0,
|
|
972
|
+
quoted: false,
|
|
973
|
+
valueEnd,
|
|
974
|
+
valueStart,
|
|
975
|
+
};
|
|
976
|
+
}
|
|
977
|
+
function matchesCssFunction(cssText, start, name) {
|
|
978
|
+
if (start > 0 && isCssNameCode(cssText.charCodeAt(start - 1)))
|
|
979
|
+
return false;
|
|
980
|
+
if (start + name.length >= cssText.length)
|
|
981
|
+
return false;
|
|
982
|
+
for (let i = 0; i < name.length; i++) {
|
|
983
|
+
let code = cssText.charCodeAt(start + i);
|
|
984
|
+
if (code >= 65 && code <= 90)
|
|
985
|
+
code += 32;
|
|
986
|
+
if (code !== name.charCodeAt(i))
|
|
987
|
+
return false;
|
|
988
|
+
}
|
|
989
|
+
return cssText.charCodeAt(start + name.length) === 40;
|
|
990
|
+
}
|
|
991
|
+
function isCssWhitespace(code) {
|
|
992
|
+
return code === 9 || code === 10 || code === 12 || code === 13 || code === 32;
|
|
993
|
+
}
|
|
994
|
+
function escapeCssString(value, quote) {
|
|
995
|
+
let escaped = '';
|
|
996
|
+
let copiedThrough = 0;
|
|
997
|
+
for (let i = 0; i < value.length; i++) {
|
|
998
|
+
const code = value.charCodeAt(i);
|
|
999
|
+
if (code !== quote && code !== 92)
|
|
1000
|
+
continue;
|
|
1001
|
+
escaped += value.slice(copiedThrough, i);
|
|
1002
|
+
escaped += code === 92 ? '\\\\' : `\\${String.fromCharCode(code)}`;
|
|
1003
|
+
copiedThrough = i + 1;
|
|
1004
|
+
}
|
|
1005
|
+
return copiedThrough === 0
|
|
1006
|
+
? value
|
|
1007
|
+
: escaped + value.slice(copiedThrough);
|
|
1008
|
+
}
|
|
1009
|
+
function isCssNameCode(code) {
|
|
1010
|
+
return ((code >= 48 && code <= 57) ||
|
|
1011
|
+
(code >= 65 && code <= 90) ||
|
|
1012
|
+
(code >= 97 && code <= 122) ||
|
|
1013
|
+
code === 45 ||
|
|
1014
|
+
code === 95 ||
|
|
1015
|
+
code >= 128);
|
|
1016
|
+
}
|
|
1017
|
+
function isReferrerPolicy(value) {
|
|
1018
|
+
return (value === 'no-referrer' ||
|
|
1019
|
+
value === 'no-referrer-when-downgrade' ||
|
|
1020
|
+
value === 'origin' ||
|
|
1021
|
+
value === 'origin-when-cross-origin' ||
|
|
1022
|
+
value === 'same-origin' ||
|
|
1023
|
+
value === 'strict-origin' ||
|
|
1024
|
+
value === 'strict-origin-when-cross-origin' ||
|
|
1025
|
+
value === 'unsafe-url');
|
|
1026
|
+
}
|
|
1027
|
+
function ignorePromiseResults() { }
|
|
1028
|
+
function errorMessage(error) {
|
|
1029
|
+
return error instanceof Error ? error.message : String(error);
|
|
1030
|
+
}
|