single-file-core 1.3.13 → 1.3.14

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.
@@ -187,6 +187,8 @@ class ProcessorHelperCommon {
187
187
  promises.push(processorHelper.processStyle(ruleData, options, resources, batchRequest));
188
188
  } else if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "supports")) {
189
189
  promises.push(processorHelper.processStylesheet(ruleData.block.children, baseURI, options, resources, batchRequest));
190
+ } else if (ruleData.type == "Atrule" && (ruleData.name == "media" || ruleData.name == "layer")) {
191
+ promises.push(processorHelper.processStylesheet(ruleData.block.children, baseURI, options, resources, batchRequest));
190
192
  } else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
191
193
  promises.push(processFontFaceRule(ruleData));
192
194
  }
@@ -396,7 +398,8 @@ class ProcessorHelperCommon {
396
398
  const fontsDetails = {
397
399
  fonts: new Map(),
398
400
  medias: new Map(),
399
- supports: new Map()
401
+ supports: new Map(),
402
+ layers: new Map()
400
403
  };
401
404
  const stats = { rules: { processed: 0, discarded: 0 }, fonts: { processed: 0, discarded: 0 } };
402
405
  let sheetIndex = 0;
@@ -433,7 +436,7 @@ class ProcessorHelperCommon {
433
436
 
434
437
  async processFontFaceRules(cssRules, sheetIndex, fontsDetails, fonts, fontTests, stats) {
435
438
  const removedRules = [];
436
- let mediaIndex = 0, supportsIndex = 0;
439
+ let mediaIndex = 0, supportsIndex = 0, layerIndex = 0;
437
440
  for (let cssRule = cssRules.head; cssRule; cssRule = cssRule.next) {
438
441
  const ruleData = cssRule.data;
439
442
  if (ruleData.type == "Atrule" && ruleData.name == "media" && ruleData.block && ruleData.block.children && ruleData.prelude) {
@@ -444,6 +447,10 @@ class ProcessorHelperCommon {
444
447
  const supportsText = cssTree.generate(ruleData.prelude);
445
448
  await this.processFontFaceRules(ruleData.block.children, sheetIndex, fontsDetails.supports.get("supports-" + sheetIndex + "-" + supportsIndex + "-" + supportsText), fonts, fontTests, stats);
446
449
  supportsIndex++;
450
+ } else if (ruleData.type == "Atrule" && ruleData.name == "layer" && ruleData.block && ruleData.block.children && ruleData.prelude) {
451
+ const layerText = cssTree.generate(ruleData.prelude);
452
+ await this.processFontFaceRules(ruleData.block.children, sheetIndex, fontsDetails.layers.get("layer-" + sheetIndex + "-" + layerIndex + "-" + layerText), fonts, fontTests, stats);
453
+ layerIndex++;
447
454
  } else if (ruleData.type == "Atrule" && ruleData.name == "font-face") {
448
455
  const key = this.getFontKey(ruleData);
449
456
  const fontInfo = fontsDetails.fonts.get(key);
@@ -458,7 +465,7 @@ class ProcessorHelperCommon {
458
465
  }
459
466
 
460
467
  getFontsDetails(doc, cssRules, sheetIndex, mediaFontsDetails) {
461
- let mediaIndex = 0, supportsIndex = 0;
468
+ let mediaIndex = 0, supportsIndex = 0, layerIndex = 0;
462
469
  cssRules.forEach(ruleData => {
463
470
  if (ruleData.type == "Atrule" && ruleData.name == "media" && ruleData.block && ruleData.block.children && ruleData.prelude) {
464
471
  const mediaText = cssTree.generate(ruleData.prelude);
@@ -472,6 +479,12 @@ class ProcessorHelperCommon {
472
479
  mediaFontsDetails.supports.set("supports-" + sheetIndex + "-" + supportsIndex + "-" + supportsText, fontsDetails);
473
480
  supportsIndex++;
474
481
  this.getFontsDetails(doc, ruleData.block.children, sheetIndex, fontsDetails);
482
+ } else if (ruleData.type == "Atrule" && ruleData.name == "layer" && ruleData.block && ruleData.block.children && ruleData.prelude) {
483
+ const layerText = cssTree.generate(ruleData.prelude);
484
+ const fontsDetails = this.createFontsDetailsInfo();
485
+ mediaFontsDetails.layers.set("layer-" + sheetIndex + "-" + layerIndex + "-" + layerText, fontsDetails);
486
+ layerIndex++;
487
+ this.getFontsDetails(doc, ruleData.block.children, sheetIndex, fontsDetails);
475
488
  } else if (ruleData.type == "Atrule" && ruleData.name == "font-face" && ruleData.block && ruleData.block.children) {
476
489
  const fontKey = this.getFontKey(ruleData);
477
490
  let fontInfo = mediaFontsDetails.fonts.get(fontKey);
@@ -499,7 +512,8 @@ class ProcessorHelperCommon {
499
512
  return {
500
513
  fonts: new Map(),
501
514
  medias: new Map(),
502
- supports: new Map()
515
+ supports: new Map(),
516
+ layers: new Map()
503
517
  };
504
518
  }
505
519
 
@@ -574,9 +588,11 @@ function processFontDetails(fontsDetails, fontResources) {
574
588
  if (fontResources) {
575
589
  fontsDetails.medias.forEach(mediaFontsDetails => processFontDetails(mediaFontsDetails, fontResources));
576
590
  fontsDetails.supports.forEach(supportsFontsDetails => processFontDetails(supportsFontsDetails, fontResources));
591
+ fontsDetails.layers.forEach(layerFontsDetails => processFontDetails(layerFontsDetails, fontResources));
577
592
  } else {
578
593
  fontsDetails.medias.forEach(mediaFontsDetails => processFontDetails(mediaFontsDetails));
579
594
  fontsDetails.supports.forEach(supportsFontsDetails => processFontDetails(supportsFontsDetails));
595
+ fontsDetails.layers.forEach(layerFontsDetails => processFontDetails(layerFontsDetails));
580
596
  }
581
597
  }
582
598
 
@@ -533,7 +533,7 @@ function getProcessorHelperClass(utilInstance) {
533
533
  fontTests.set(source.src, source.valid);
534
534
  }
535
535
  }));
536
- const findSourceByFormat = (fontFormat, testValidity) => fontInfo.findLast(source => !source.src.match(EMPTY_URL_SOURCE) && source.format == fontFormat && (!testValidity || source.valid));
536
+ const findSourceByFormat = (fontFormat, testValidity) => util.findLast(fontInfo, source => !source.src.match(EMPTY_URL_SOURCE) && source.format == fontFormat && (!testValidity || source.valid));
537
537
  const filterSources = fontSource => fontInfo.filter(source => source == fontSource || source.src.startsWith(LOCAL_SOURCE));
538
538
  stats.fonts.processed += fontInfo.length;
539
539
  stats.fonts.discarded += fontInfo.length;
@@ -437,8 +437,8 @@ function getProcessorHelperClass(utilInstance) {
437
437
  fontTests.set(source.src, source.valid);
438
438
  }
439
439
  }));
440
- const findSourceByFormat = (fontFormat, testValidity) => fontInfo.findLast(source => !source.src.match(EMPTY_URL_SOURCE) && source.format == fontFormat && (!testValidity || source.valid));
441
- const findSourceByContentType = (contentType, testValidity) => fontInfo.findLast(source => !source.src.match(EMPTY_URL_SOURCE) && source.contentType == contentType && (!testValidity || source.valid));
440
+ const findSourceByFormat = (fontFormat, testValidity) => util.findLast(fontInfo, source => !source.src.match(EMPTY_URL_SOURCE) && source.format == fontFormat && (!testValidity || source.valid));
441
+ const findSourceByContentType = (contentType, testValidity) => util.findLast(fontInfo, source => !source.src.match(EMPTY_URL_SOURCE) && source.contentType == contentType && (!testValidity || source.valid));
442
442
  const filterSources = fontSource => fontInfo.filter(source => source == fontSource || source.src.startsWith(LOCAL_SOURCE));
443
443
  stats.fonts.processed += fontInfo.length;
444
444
  stats.fonts.discarded += fontInfo.length;
package/core/util.js CHANGED
@@ -196,6 +196,18 @@ function getInstance(utilOptions) {
196
196
  appendInfobar(doc, options) {
197
197
  return helper.appendInfobar(doc, options);
198
198
  },
199
+ findLast(array, callback) {
200
+ if (array.findLast && typeof array.findLast == "function") {
201
+ return array.findLast(callback);
202
+ } else {
203
+ let index = array.length;
204
+ while (index--) {
205
+ if (callback(array[index], index, array)) {
206
+ return array[index];
207
+ }
208
+ }
209
+ }
210
+ },
199
211
  ON_BEFORE_CAPTURE_EVENT_NAME: helper.ON_BEFORE_CAPTURE_EVENT_NAME,
200
212
  ON_AFTER_CAPTURE_EVENT_NAME: helper.ON_AFTER_CAPTURE_EVENT_NAME,
201
213
  WIN_ID_ATTRIBUTE_NAME: helper.WIN_ID_ATTRIBUTE_NAME,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "single-file-core",
3
- "version": "1.3.13",
3
+ "version": "1.3.14",
4
4
  "description": "SingleFile Core",
5
5
  "author": "Gildas Lormeau",
6
6
  "license": "AGPL-3.0-or-later",