single-file-core 1.0.62 → 1.0.63
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/package.json
CHANGED
|
@@ -43,6 +43,8 @@
|
|
|
43
43
|
const FETCH_REQUEST_EVENT = "single-file-request-fetch";
|
|
44
44
|
const FETCH_ACK_EVENT = "single-file-ack-fetch";
|
|
45
45
|
const FETCH_RESPONSE_EVENT = "single-file-response-fetch";
|
|
46
|
+
const GET_ADOPTED_STYLESHEETS_REQUEST_EVENT = "single-file-request-get-adopted-stylesheets";
|
|
47
|
+
const GET_ADOPTED_STYLESHEETS_RESPONSE_EVENT = "single-file-response-get-adopted-stylesheets";
|
|
46
48
|
const NEW_FONT_FACE_EVENT = "single-file-new-font-face";
|
|
47
49
|
const DELETE_FONT_EVENT = "single-file-delete-font";
|
|
48
50
|
const CLEAR_FONTS_EVENT = "single-file-clear-fonts";
|
|
@@ -310,6 +312,14 @@
|
|
|
310
312
|
dispatchEvent(new CustomEvent(FETCH_RESPONSE_EVENT, { detail }));
|
|
311
313
|
});
|
|
312
314
|
|
|
315
|
+
addEventListener(GET_ADOPTED_STYLESHEETS_REQUEST_EVENT, event => {
|
|
316
|
+
const shadowRoot = event.target.shadowRoot;
|
|
317
|
+
const adoptedStyleSheets = Array.from(shadowRoot.adoptedStyleSheets).map(stylesheet => Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n"));
|
|
318
|
+
if (adoptedStyleSheets.length) {
|
|
319
|
+
event.target.dispatchEvent(new CustomEvent(GET_ADOPTED_STYLESHEETS_RESPONSE_EVENT, { detail: { adoptedStyleSheets } }));
|
|
320
|
+
}
|
|
321
|
+
}, { capture: true });
|
|
322
|
+
|
|
313
323
|
if (globalThis.FontFace) {
|
|
314
324
|
const FontFace = globalThis.FontFace;
|
|
315
325
|
globalThis.FontFace = function () {
|
package/single-file-helper.js
CHANGED
|
@@ -28,6 +28,8 @@ import * as hooksFrames from "./processors/hooks/content/content-hooks-frames.js
|
|
|
28
28
|
|
|
29
29
|
const ON_BEFORE_CAPTURE_EVENT_NAME = "single-file-on-before-capture";
|
|
30
30
|
const ON_AFTER_CAPTURE_EVENT_NAME = "single-file-on-after-capture";
|
|
31
|
+
const GET_ADOPTED_STYLESHEETS_REQUEST_EVENT = "single-file-request-get-adopted-stylesheets";
|
|
32
|
+
const GET_ADOPTED_STYLESHEETS_RESPONSE_EVENT = "single-file-response-get-adopted-stylesheets";
|
|
31
33
|
const REMOVED_CONTENT_ATTRIBUTE_NAME = "data-single-file-removed-content";
|
|
32
34
|
const HIDDEN_CONTENT_ATTRIBUTE_NAME = "data-single-file-hidden-content";
|
|
33
35
|
const KEPT_CONTENT_ATTRIBUTE_NAME = "data-single-file-kept-content";
|
|
@@ -228,8 +230,15 @@ function getElementsInfo(win, doc, element, options, data = { usedFonts: new Map
|
|
|
228
230
|
shadowRootInfo.content = shadowRoot.innerHTML;
|
|
229
231
|
shadowRootInfo.mode = shadowRoot.mode;
|
|
230
232
|
try {
|
|
231
|
-
if (shadowRoot.adoptedStyleSheets
|
|
232
|
-
|
|
233
|
+
if (shadowRoot.adoptedStyleSheets) {
|
|
234
|
+
if (shadowRoot.adoptedStyleSheets.length) {
|
|
235
|
+
shadowRootInfo.adoptedStyleSheets = Array.from(shadowRoot.adoptedStyleSheets).map(stylesheet => Array.from(stylesheet.cssRules).map(cssRule => cssRule.cssText).join("\n"));
|
|
236
|
+
} else if (shadowRoot.adoptedStyleSheets.length === undefined) {
|
|
237
|
+
const listener = event => shadowRootInfo.adoptedStyleSheets = event.detail.adoptedStyleSheets;
|
|
238
|
+
element.addEventListener(GET_ADOPTED_STYLESHEETS_RESPONSE_EVENT, listener);
|
|
239
|
+
element.dispatchEvent(new CustomEvent(GET_ADOPTED_STYLESHEETS_REQUEST_EVENT, { options: { bubbles: true, composed: true }}));
|
|
240
|
+
element.removeEventListener(GET_ADOPTED_STYLESHEETS_RESPONSE_EVENT, listener);
|
|
241
|
+
}
|
|
233
242
|
}
|
|
234
243
|
} catch (error) {
|
|
235
244
|
// ignored
|
|
@@ -177,14 +177,16 @@ function parse(value) {
|
|
|
177
177
|
while (tokenNode && tokenNode.data.type == "Operator" && tokenNode.data.value == ",") {
|
|
178
178
|
tokenNode = tokenNode.next;
|
|
179
179
|
}
|
|
180
|
-
if (tokenNode
|
|
181
|
-
|
|
182
|
-
|
|
180
|
+
if (tokenNode) {
|
|
181
|
+
if (tokenNode.data.type == "Identifier") {
|
|
182
|
+
while (tokenNode && tokenNode.data.type == "Identifier") {
|
|
183
|
+
familyName += " " + cssTree.generate(tokenNode.data);
|
|
184
|
+
tokenNode = tokenNode.next;
|
|
185
|
+
}
|
|
186
|
+
} else {
|
|
187
|
+
familyName = removeQuotes(cssTree.generate(tokenNode.data));
|
|
183
188
|
tokenNode = tokenNode.next;
|
|
184
189
|
}
|
|
185
|
-
} else {
|
|
186
|
-
familyName = removeQuotes(cssTree.generate(tokenNode.data));
|
|
187
|
-
tokenNode = tokenNode.next;
|
|
188
190
|
}
|
|
189
191
|
familyName = familyName.trim();
|
|
190
192
|
if (familyName) {
|