wxt 0.20.2 → 0.20.3
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.
|
@@ -55,11 +55,11 @@ export function devHtmlPrerender(config, server) {
|
|
|
55
55
|
const inlineScripts = document.querySelectorAll("script:not([src])");
|
|
56
56
|
inlineScripts.forEach((script) => {
|
|
57
57
|
const textContent = script.textContent ?? "";
|
|
58
|
-
const
|
|
59
|
-
inlineScriptContents[
|
|
58
|
+
const key = hash(textContent);
|
|
59
|
+
inlineScriptContents[key] = textContent;
|
|
60
60
|
const virtualScript = document.createElement("script");
|
|
61
61
|
virtualScript.type = "module";
|
|
62
|
-
virtualScript.src = `${server.origin}/@id/${virtualInlineScript}?${
|
|
62
|
+
virtualScript.src = `${server.origin}/@id/${virtualInlineScript}?${key}`;
|
|
63
63
|
script.replaceWith(virtualScript);
|
|
64
64
|
});
|
|
65
65
|
const viteClientScript = document.querySelector(
|
|
@@ -76,7 +76,7 @@ export function devHtmlPrerender(config, server) {
|
|
|
76
76
|
}
|
|
77
77
|
},
|
|
78
78
|
{
|
|
79
|
-
name: "wxt:virtualize-
|
|
79
|
+
name: "wxt:virtualize-inline-scripts",
|
|
80
80
|
apply: "serve",
|
|
81
81
|
resolveId(id) {
|
|
82
82
|
if (id.startsWith(virtualInlineScript)) {
|
|
@@ -88,8 +88,8 @@ export function devHtmlPrerender(config, server) {
|
|
|
88
88
|
},
|
|
89
89
|
load(id) {
|
|
90
90
|
if (id.startsWith(resolvedVirtualInlineScript)) {
|
|
91
|
-
const
|
|
92
|
-
return inlineScriptContents[
|
|
91
|
+
const key = id.substring(id.indexOf("?") + 1);
|
|
92
|
+
return inlineScriptContents[key];
|
|
93
93
|
}
|
|
94
94
|
if (id === "\0noop") {
|
|
95
95
|
return "";
|
|
@@ -2,7 +2,9 @@ import { browser } from "wxt/browser";
|
|
|
2
2
|
import { createIsolatedElement } from "@webext-core/isolated-element";
|
|
3
3
|
import { applyPosition, createMountFunctions, mountUi } from "./shared.mjs";
|
|
4
4
|
import { logger } from "../internal/logger.mjs";
|
|
5
|
+
import { splitShadowRootCss } from "../split-shadow-root-css.mjs";
|
|
5
6
|
export async function createShadowRootUi(ctx, options) {
|
|
7
|
+
const instanceId = crypto.randomUUID();
|
|
6
8
|
const css = [];
|
|
7
9
|
if (!options.inheritStyles) {
|
|
8
10
|
css.push(`/* WXT Shadow Root Reset */ body{all:initial;}`);
|
|
@@ -14,6 +16,7 @@ export async function createShadowRootUi(ctx, options) {
|
|
|
14
16
|
const entryCss = await loadCss();
|
|
15
17
|
css.push(entryCss.replaceAll(":root", ":host"));
|
|
16
18
|
}
|
|
19
|
+
const { shadowCss, documentCss } = splitShadowRootCss(css.join("\n").trim());
|
|
17
20
|
const {
|
|
18
21
|
isolatedElement: uiContainer,
|
|
19
22
|
parentElement: shadowHost,
|
|
@@ -21,7 +24,7 @@ export async function createShadowRootUi(ctx, options) {
|
|
|
21
24
|
} = await createIsolatedElement({
|
|
22
25
|
name: options.name,
|
|
23
26
|
css: {
|
|
24
|
-
textContent:
|
|
27
|
+
textContent: shadowCss
|
|
25
28
|
},
|
|
26
29
|
mode: options.mode ?? "open",
|
|
27
30
|
isolateEvents: options.isolateEvents
|
|
@@ -31,11 +34,23 @@ export async function createShadowRootUi(ctx, options) {
|
|
|
31
34
|
const mount = () => {
|
|
32
35
|
mountUi(shadowHost, options);
|
|
33
36
|
applyPosition(shadowHost, shadow.querySelector("html"), options);
|
|
37
|
+
if (documentCss && !document.querySelector(
|
|
38
|
+
`style[wxt-shadow-root-document-styles="${instanceId}"]`
|
|
39
|
+
)) {
|
|
40
|
+
const style = document.createElement("style");
|
|
41
|
+
style.textContent = documentCss;
|
|
42
|
+
style.setAttribute("wxt-shadow-root-document-styles", instanceId);
|
|
43
|
+
(document.head ?? document.body).append(style);
|
|
44
|
+
}
|
|
34
45
|
mounted = options.onMount(uiContainer, shadow, shadowHost);
|
|
35
46
|
};
|
|
36
47
|
const remove = () => {
|
|
37
48
|
options.onRemove?.(mounted);
|
|
38
49
|
shadowHost.remove();
|
|
50
|
+
const documentStyle = document.querySelector(
|
|
51
|
+
`style[wxt-shadow-root-document-styles="${instanceId}"]`
|
|
52
|
+
);
|
|
53
|
+
documentStyle?.remove();
|
|
39
54
|
while (uiContainer.lastChild)
|
|
40
55
|
uiContainer.removeChild(uiContainer.lastChild);
|
|
41
56
|
mounted = void 0;
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Given a CSS string that will be loaded into a shadow root, split it into two parts:
|
|
3
|
+
* - `documentCss`: CSS that needs to be applied to the document (like `@property`)
|
|
4
|
+
* - `shadowCss`: CSS that needs to be applied to the shadow root
|
|
5
|
+
* @param css
|
|
6
|
+
*/
|
|
7
|
+
export declare function splitShadowRootCss(css: string): {
|
|
8
|
+
documentCss: string;
|
|
9
|
+
shadowCss: string;
|
|
10
|
+
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export function splitShadowRootCss(css) {
|
|
2
|
+
let shadowCss = css;
|
|
3
|
+
let documentCss = "";
|
|
4
|
+
const rulesRegex = /(\s*@property[\s\S]*?{[\s\S]*?})/gm;
|
|
5
|
+
let match;
|
|
6
|
+
while ((match = rulesRegex.exec(css)) !== null) {
|
|
7
|
+
documentCss += match[1];
|
|
8
|
+
shadowCss = shadowCss.replace(match[1], "");
|
|
9
|
+
}
|
|
10
|
+
return {
|
|
11
|
+
documentCss: documentCss.trim(),
|
|
12
|
+
shadowCss: shadowCss.trim()
|
|
13
|
+
};
|
|
14
|
+
}
|
package/dist/version.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export const version = "0.20.
|
|
1
|
+
export const version = "0.20.3";
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "wxt",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.20.
|
|
4
|
+
"version": "0.20.3",
|
|
5
5
|
"description": "⚡ Next-gen Web Extension Framework",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"dependencies": {
|
|
@@ -156,6 +156,10 @@
|
|
|
156
156
|
"types": "./dist/utils/match-patterns.d.ts",
|
|
157
157
|
"default": "./dist/utils/match-patterns.mjs"
|
|
158
158
|
},
|
|
159
|
+
"./utils/split-shadow-root-css": {
|
|
160
|
+
"types": "./dist/utils/split-shadow-root-css.d.ts",
|
|
161
|
+
"default": "./dist/utils/split-shadow-root-css.mjs"
|
|
162
|
+
},
|
|
159
163
|
"./utils/storage": {
|
|
160
164
|
"types": "./dist/utils/storage.d.ts",
|
|
161
165
|
"default": "./dist/utils/storage.mjs"
|