single-file-core 1.2.32 → 1.2.33
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/core/index.js
CHANGED
|
@@ -837,7 +837,13 @@ class Processor {
|
|
|
837
837
|
const originalElement = templateElement.content.firstChild;
|
|
838
838
|
if (originalElement) {
|
|
839
839
|
if (originalElement.hasAttributes()) {
|
|
840
|
-
Array.from(originalElement.attributes).forEach(attribute =>
|
|
840
|
+
Array.from(originalElement.attributes).forEach(attribute => {
|
|
841
|
+
try {
|
|
842
|
+
placeHolderElement.setAttribute(attribute.name, attribute.value);
|
|
843
|
+
} catch (error) {
|
|
844
|
+
// ignored
|
|
845
|
+
}
|
|
846
|
+
});
|
|
841
847
|
}
|
|
842
848
|
originalElement.childNodes.forEach(childNode => placeHolderElement.appendChild(childNode.cloneNode(true)));
|
|
843
849
|
}
|
|
@@ -112,7 +112,7 @@ function process(doc, stylesheets, styles, options) {
|
|
|
112
112
|
|
|
113
113
|
function getFontsInfo(cssRules, fontsInfo) {
|
|
114
114
|
cssRules.forEach(ruleData => {
|
|
115
|
-
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports") && ruleData.block && ruleData.block.children) {
|
|
115
|
+
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer") && ruleData.block && ruleData.block.children) {
|
|
116
116
|
getFontsInfo(ruleData.block.children, fontsInfo);
|
|
117
117
|
} else if (ruleData.type == "Rule") {
|
|
118
118
|
const fontFamilyNames = getFontFamilyNames(ruleData.block);
|
|
@@ -138,7 +138,7 @@ function filterUnusedFonts(cssRules, declaredFonts, unusedFonts, filteredUsedFon
|
|
|
138
138
|
const removedRules = [];
|
|
139
139
|
for (let cssRule = cssRules.head; cssRule; cssRule = cssRule.next) {
|
|
140
140
|
const ruleData = cssRule.data;
|
|
141
|
-
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports") && ruleData.block && ruleData.block.children) {
|
|
141
|
+
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer") && ruleData.block && ruleData.block.children) {
|
|
142
142
|
filterUnusedFonts(ruleData.block.children, declaredFonts, unusedFonts, filteredUsedFonts, docContent);
|
|
143
143
|
} else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
|
|
144
144
|
const fontFamily = helper.normalizeFontFamily(getDeclarationValue(ruleData.block.children, "font-family"));
|
|
@@ -171,8 +171,8 @@ function testUsedFont(ruleData, familyName, declaredFonts, filteredUsedFonts) {
|
|
|
171
171
|
const fontWeight = helper.getFontWeight(getDeclarationValue(ruleData.block.children, "font-weight") || "400");
|
|
172
172
|
const declaredFontsWeights = declaredFonts
|
|
173
173
|
.filter(fontInfo => fontInfo.fontFamily == familyName && fontInfo.fontStyle == fontStyle)
|
|
174
|
-
.map(fontInfo => fontInfo.fontWeight)
|
|
175
|
-
.sort((weight1, weight2) => Number.parseInt(weight1, 10) - Number.parseInt(weight2, 10));
|
|
174
|
+
.map(fontInfo => fontInfo.fontWeight.split(" "))
|
|
175
|
+
.sort((weight1, weight2) => Number.parseInt(weight1[0], 10) - Number.parseInt(weight2[0], 10));
|
|
176
176
|
let usedFontWeights = optionalUsedFonts.map(fontInfo => getUsedFontWeight(fontInfo, fontStyle, declaredFontsWeights));
|
|
177
177
|
test = testFontweight(fontWeight, usedFontWeights);
|
|
178
178
|
if (!test) {
|
|
@@ -202,8 +202,8 @@ function testUsedFont(ruleData, familyName, declaredFonts, filteredUsedFonts) {
|
|
|
202
202
|
|
|
203
203
|
function testFontweight(fontWeight, usedFontWeights) {
|
|
204
204
|
let test;
|
|
205
|
-
for (const value of fontWeight.split(
|
|
206
|
-
test = test || usedFontWeights.includes(helper.getFontWeight(helper.removeQuotes(value)));
|
|
205
|
+
for (const value of fontWeight.split(",")) {
|
|
206
|
+
test = test || usedFontWeights.includes(helper.getFontWeight(helper.removeQuotes(value.trim())));
|
|
207
207
|
}
|
|
208
208
|
return test;
|
|
209
209
|
}
|
|
@@ -289,12 +289,12 @@ function parseFamilyNames(fontFamilyNameTokenData, fontFamilyNames) {
|
|
|
289
289
|
|
|
290
290
|
function getUsedFontWeight(fontInfo, fontStyle, fontWeights) {
|
|
291
291
|
let foundWeight;
|
|
292
|
-
fontWeights = fontWeights.map(
|
|
292
|
+
fontWeights = fontWeights.map(weights => weights.map(value => String(Number.parseInt(value, 10))));
|
|
293
293
|
if (fontInfo[2] == fontStyle) {
|
|
294
294
|
let fontWeight = Number(fontInfo[1]);
|
|
295
295
|
if (fontWeights.length > 1) {
|
|
296
296
|
if (fontWeight >= 400 && fontWeight <= 500) {
|
|
297
|
-
foundWeight = fontWeights.find(
|
|
297
|
+
foundWeight = fontWeights.find(weights => weights[0] >= fontWeight && weights[weights.length - 1] <= 500);
|
|
298
298
|
if (!foundWeight) {
|
|
299
299
|
foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
300
300
|
}
|
|
@@ -303,13 +303,13 @@ function getUsedFontWeight(fontInfo, fontStyle, fontWeights) {
|
|
|
303
303
|
}
|
|
304
304
|
}
|
|
305
305
|
if (fontWeight < 400) {
|
|
306
|
-
foundWeight = fontWeights.slice().reverse().find(
|
|
306
|
+
foundWeight = fontWeights.slice().reverse().find(weights => weights[weights.length - 1] <= fontWeight);
|
|
307
307
|
if (!foundWeight) {
|
|
308
308
|
foundWeight = findAscendingFontWeight(fontWeight, fontWeights);
|
|
309
309
|
}
|
|
310
310
|
}
|
|
311
311
|
if (fontWeight > 500) {
|
|
312
|
-
foundWeight = fontWeights.find(
|
|
312
|
+
foundWeight = fontWeights.find(weights => weights[0] >= fontWeight);
|
|
313
313
|
if (!foundWeight) {
|
|
314
314
|
foundWeight = findDescendingFontWeight(fontWeight, fontWeights);
|
|
315
315
|
}
|
|
@@ -318,21 +318,21 @@ function getUsedFontWeight(fontInfo, fontStyle, fontWeights) {
|
|
|
318
318
|
foundWeight = fontWeights[0];
|
|
319
319
|
}
|
|
320
320
|
}
|
|
321
|
-
return foundWeight;
|
|
321
|
+
return foundWeight ? foundWeight.join(" ") : undefined;
|
|
322
322
|
}
|
|
323
323
|
|
|
324
324
|
function findDescendingFontWeight(fontWeight, fontWeights) {
|
|
325
|
-
return fontWeights.slice().reverse().find(
|
|
325
|
+
return fontWeights.slice().reverse().find(weights => weights[weights.length - 1] < fontWeight);
|
|
326
326
|
}
|
|
327
327
|
|
|
328
328
|
function findAscendingFontWeight(fontWeight, fontWeights) {
|
|
329
|
-
return fontWeights.find(
|
|
329
|
+
return fontWeights.find(weights => weights[0] > fontWeight);
|
|
330
330
|
}
|
|
331
331
|
|
|
332
332
|
function getRulesTextContent(doc, cssRules, workStylesheet, content) {
|
|
333
333
|
cssRules.forEach(ruleData => {
|
|
334
334
|
if (ruleData.block && ruleData.block.children && ruleData.prelude && ruleData.prelude.children) {
|
|
335
|
-
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports")) {
|
|
335
|
+
if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports" || ruleData.name == "layer")) {
|
|
336
336
|
content = getRulesTextContent(doc, ruleData.block.children, workStylesheet, content);
|
|
337
337
|
} else if (ruleData.type == "Rule") {
|
|
338
338
|
content = getDeclarationsTextContent(ruleData.block.children, workStylesheet, content);
|
package/package.json
CHANGED
|
@@ -164,11 +164,6 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
164
164
|
}
|
|
165
165
|
}
|
|
166
166
|
}));
|
|
167
|
-
if (filename.match(REGEXP_MATCH_INDEX) || filename.match(REGEXP_MATCH_FRAMES) || noBlobURL) {
|
|
168
|
-
resource.content = await getDataURI(textContent, mimeType);
|
|
169
|
-
} else {
|
|
170
|
-
resource.content = URL.createObjectURL(new Blob([textContent], { type: mimeType }));
|
|
171
|
-
}
|
|
172
167
|
resource.textContent = textContent;
|
|
173
168
|
}
|
|
174
169
|
if (filename.match(REGEXP_MATCH_INDEX)) {
|
|
@@ -176,6 +171,11 @@ async function extract(content, { password, prompt = () => { }, shadowRootScript
|
|
|
176
171
|
resource.textContent = textContent.replace(/<script data-template-shadow-root.*<\/script>/g, "<script data-template-shadow-root src=" + shadowRootScriptURL + "></" + "script>");
|
|
177
172
|
}
|
|
178
173
|
}
|
|
174
|
+
if (filename.match(REGEXP_MATCH_INDEX) || filename.match(REGEXP_MATCH_FRAMES) || noBlobURL) {
|
|
175
|
+
resource.content = await getDataURI(textContent, mimeType);
|
|
176
|
+
} else {
|
|
177
|
+
resource.content = URL.createObjectURL(new Blob([textContent], { type: mimeType }));
|
|
178
|
+
}
|
|
179
179
|
if (filename.match(REGEXP_MATCH_ROOT_INDEX)) {
|
|
180
180
|
docContent = textContent;
|
|
181
181
|
url = resource.url;
|