single-file-core 1.5.2 → 1.5.4
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.
|
@@ -185,9 +185,7 @@ class ProcessorHelperCommon {
|
|
|
185
185
|
} else if (ruleData.block && ruleData.block.children) {
|
|
186
186
|
if (ruleData.type == "Rule") {
|
|
187
187
|
promises.push(processorHelper.processStyle(ruleData, options, resources, batchRequest));
|
|
188
|
-
} else if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports")) {
|
|
189
|
-
promises.push(processorHelper.processStylesheet(ruleData.block.children, baseURI, options, resources, batchRequest));
|
|
190
|
-
} else if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "layer")) {
|
|
188
|
+
} else if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer" || ruleData.name == "container")) {
|
|
191
189
|
promises.push(processorHelper.processStylesheet(ruleData.block.children, baseURI, options, resources, batchRequest));
|
|
192
190
|
} else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
193
191
|
promises.push(processFontFaceRule(ruleData));
|
|
@@ -507,24 +507,28 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
507
507
|
new Promise(resolve => timeout = globalThis.setTimeout(() => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
|
|
508
508
|
]);
|
|
509
509
|
} catch (error) {
|
|
510
|
-
|
|
511
|
-
|
|
512
|
-
|
|
513
|
-
const
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
510
|
+
if (error.name == "NetworkError") {
|
|
511
|
+
source.valid = true;
|
|
512
|
+
} else {
|
|
513
|
+
const urlNodes = cssTree.findAll(srcDeclaration.data, node => node.type == "Url");
|
|
514
|
+
const declarationFontURLs = Array.from(fontDeclarations).find(([node]) => urlNodes.includes(node) && node.value == source.fontUrl);
|
|
515
|
+
if (declarationFontURLs && declarationFontURLs[1].length) {
|
|
516
|
+
const fontURL = declarationFontURLs[1][0];
|
|
517
|
+
if (fontURL) {
|
|
518
|
+
const fontFace = new FontFace("test-font", "url(" + fontURL + ")");
|
|
519
|
+
try {
|
|
520
|
+
let timeout;
|
|
521
|
+
await Promise.race([
|
|
522
|
+
fontFace.load().then(() => fontFace.loaded).then(() => { source.valid = true; globalThis.clearTimeout(timeout); }),
|
|
523
|
+
new Promise(resolve => timeout = globalThis.setTimeout(() => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
|
|
524
|
+
]);
|
|
525
|
+
} catch (error) {
|
|
526
|
+
// ignored
|
|
527
|
+
}
|
|
524
528
|
}
|
|
529
|
+
} else {
|
|
530
|
+
source.valid = true;
|
|
525
531
|
}
|
|
526
|
-
} else {
|
|
527
|
-
source.valid = true;
|
|
528
532
|
}
|
|
529
533
|
}
|
|
530
534
|
} else {
|
|
@@ -418,15 +418,19 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
418
418
|
new Promise(resolve => timeout = globalThis.setTimeout(() => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
|
|
419
419
|
]);
|
|
420
420
|
} catch (error) {
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
421
|
+
if (error.name == "NetworkError") {
|
|
422
|
+
source.valid = true;
|
|
423
|
+
} else {
|
|
424
|
+
const fontFace = new FontFace("test-font", "url(" + resource.url + ")");
|
|
425
|
+
try {
|
|
426
|
+
let timeout;
|
|
427
|
+
await Promise.race([
|
|
428
|
+
fontFace.load().then(() => fontFace.loaded).then(() => { source.valid = true; globalThis.clearTimeout(timeout); }),
|
|
429
|
+
new Promise(resolve => timeout = globalThis.setTimeout(() => { source.valid = true; resolve(); }, FONT_MAX_LOAD_DELAY))
|
|
430
|
+
]);
|
|
431
|
+
} catch (error) {
|
|
432
|
+
// ignored
|
|
433
|
+
}
|
|
430
434
|
}
|
|
431
435
|
}
|
|
432
436
|
} else {
|
|
@@ -113,7 +113,7 @@ function process(doc, stylesheets, styles, options) {
|
|
|
113
113
|
|
|
114
114
|
function getFontsInfo(cssRules, fontsInfo, options) {
|
|
115
115
|
cssRules.forEach(ruleData => {
|
|
116
|
-
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer") && ruleData.block && ruleData.block.children) {
|
|
116
|
+
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer" || ruleData.name == "container") && ruleData.block && ruleData.block.children) {
|
|
117
117
|
getFontsInfo(ruleData.block.children, fontsInfo, options);
|
|
118
118
|
} else if (ruleData.type == "Rule") {
|
|
119
119
|
const fontFamilyNames = getFontFamilyNames(ruleData.block, options);
|
|
@@ -141,7 +141,7 @@ function filterUnusedFonts(cssRules, declaredFonts, unusedFonts, filteredUsedFon
|
|
|
141
141
|
const ruleData = cssRule.data;
|
|
142
142
|
if (ruleData.type == "Atrule" && ruleData.name == "import" && ruleData.prelude && ruleData.prelude.children && ruleData.prelude.children.head.data.importedChildren) {
|
|
143
143
|
filterUnusedFonts(ruleData.prelude.children.head.data.importedChildren, declaredFonts, unusedFonts, filteredUsedFonts, docChars);
|
|
144
|
-
} else if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer") && ruleData.block && ruleData.block.children) {
|
|
144
|
+
} else if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer" || ruleData.name == "container") && ruleData.block && ruleData.block.children) {
|
|
145
145
|
filterUnusedFonts(ruleData.block.children, declaredFonts, unusedFonts, filteredUsedFonts, docChars);
|
|
146
146
|
} else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
147
147
|
const fontFamily = helper.normalizeFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
|
|
@@ -369,7 +369,7 @@ function findAscendingFontWeight(fontWeight, fontWeights) {
|
|
|
369
369
|
function getRulesTextContent(doc, cssRules, workStylesheet, content) {
|
|
370
370
|
cssRules.forEach(ruleData => {
|
|
371
371
|
if (ruleData.block && ruleData.block.children && ruleData.prelude && ruleData.prelude.children) {
|
|
372
|
-
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer")) {
|
|
372
|
+
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer" || ruleData.name == "container")) {
|
|
373
373
|
content = getRulesTextContent(doc, ruleData.block.children, workStylesheet, content);
|
|
374
374
|
} else if (ruleData.type == "Rule") {
|
|
375
375
|
content = getDeclarationsTextContent(ruleData.block.children, workStylesheet, content);
|