single-file-core 1.0.10 → 1.0.13

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.
@@ -226,9 +226,9 @@ async function processFontFaceRule(ruleData, fontInfo, fontDeclarations, fontTes
226
226
  ]);
227
227
  } catch (error) {
228
228
  const urlNodes = cssTree.findAll(srcDeclaration.data, node => node.type == "Url");
229
- const declarationFontURLs = Array.from(fontDeclarations).find(([node]) => urlNodes.includes(node) && node.value == source.fontUrl)[1];
230
- if (declarationFontURLs.length) {
231
- const fontURL = declarationFontURLs[0];
229
+ const declarationFontURLs = Array.from(fontDeclarations).find(([node]) => urlNodes.includes(node) && node.value == source.fontUrl);
230
+ if (declarationFontURLs && declarationFontURLs[1].length) {
231
+ const fontURL = declarationFontURLs[1][0];
232
232
  if (fontURL) {
233
233
  const fontFace = new FontFace("test-font", "url(" + fontURL + ")");
234
234
  try {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.0.10",
3
+ "version": "1.0.13",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",
@@ -1082,7 +1082,10 @@ class Processor {
1082
1082
  stylesheet = await ProcessorHelper.resolveLinkStylesheetURLs(element.href, baseURI, options, workStyleElement);
1083
1083
  } else {
1084
1084
  stylesheet = cssTree.parse(element.textContent, { context: "stylesheet", parseCustomProperty: true });
1085
- await ProcessorHelper.resolveImportURLs(stylesheet, baseURI, options, workStyleElement);
1085
+ const importFound = await ProcessorHelper.resolveImportURLs(stylesheet, baseURI, options, workStyleElement);
1086
+ if (importFound) {
1087
+ stylesheet = cssTree.parse(cssTree.generate(stylesheet), { context: "stylesheet", parseCustomProperty: true });
1088
+ }
1086
1089
  }
1087
1090
  }
1088
1091
  return stylesheet;
@@ -1685,6 +1688,7 @@ class ProcessorHelper {
1685
1688
  }
1686
1689
 
1687
1690
  static async resolveImportURLs(stylesheet, baseURI, options, workStylesheet, importedStyleSheets = new Set()) {
1691
+ let importFound;
1688
1692
  ProcessorHelper.resolveStylesheetURLs(stylesheet, baseURI, workStylesheet);
1689
1693
  const imports = getImportFunctions(stylesheet);
1690
1694
  await Promise.all(imports.map(async node => {
@@ -1708,16 +1712,18 @@ class ProcessorHelper {
1708
1712
  if (mediaQueryListNode) {
1709
1713
  content.data = wrapMediaQuery(content.data, cssTree.generate(mediaQueryListNode));
1710
1714
  }
1711
- const stylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1715
+ const importedStylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1712
1716
  const ancestorStyleSheets = new Set(importedStyleSheets);
1713
1717
  ancestorStyleSheets.add(resourceURL);
1714
- await ProcessorHelper.resolveImportURLs(stylesheet, resourceURL, options, workStylesheet, ancestorStyleSheets);
1715
- for (let keyName of Object.keys(stylesheet.children.head.data)) {
1716
- node[keyName] = stylesheet.children.head.data[keyName];
1718
+ await ProcessorHelper.resolveImportURLs(importedStylesheet, resourceURL, options, workStylesheet, ancestorStyleSheets);
1719
+ for (let keyName of Object.keys(importedStylesheet)) {
1720
+ node[keyName] = importedStylesheet[keyName];
1717
1721
  }
1722
+ importFound = true;
1718
1723
  }
1719
1724
  }
1720
1725
  }));
1726
+ return importFound;
1721
1727
 
1722
1728
  async function getStylesheetContent(resourceURL) {
1723
1729
  const content = await util.getContent(resourceURL, {
@@ -1808,8 +1814,11 @@ class ProcessorHelper {
1808
1814
  if (content.data && content.data.match(/^<!doctype /i)) {
1809
1815
  content.data = "";
1810
1816
  }
1811
- const stylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1812
- await ProcessorHelper.resolveImportURLs(stylesheet, resourceURL, options, workStylesheet);
1817
+ let stylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
1818
+ const importFound = await ProcessorHelper.resolveImportURLs(stylesheet, resourceURL, options, workStylesheet);
1819
+ if (importFound) {
1820
+ stylesheet = cssTree.parse(cssTree.generate(stylesheet), { context: "stylesheet", parseCustomProperty: true });
1821
+ }
1813
1822
  return stylesheet;
1814
1823
  }
1815
1824
  }