single-file-core 1.3.13 → 1.3.15
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 +13 -6
- package/core/lib/processor-helper-common.js +20 -4
- package/core/lib/processor-helper-inline.js +1 -1
- package/core/lib/processor-helper.js +2 -2
- package/core/util.js +12 -0
- package/modules/template-formatter.js +8 -1
- package/package.json +1 -1
- package/processors/hooks/content/content-hooks-frames-web.js +1 -1
package/core/index.js
CHANGED
|
@@ -473,13 +473,20 @@ class Processor {
|
|
|
473
473
|
this.doc = util.parseDocContent(pageContent, this.baseURI);
|
|
474
474
|
if (this.options.saveRawPage) {
|
|
475
475
|
let charset;
|
|
476
|
-
this.doc.querySelectorAll("meta[charset]
|
|
477
|
-
|
|
478
|
-
|
|
479
|
-
charset = charsetDeclaration.split("=")[1].trim().toLowerCase();
|
|
476
|
+
this.doc.querySelectorAll("meta[charset]").forEach(element => {
|
|
477
|
+
if (!charset) {
|
|
478
|
+
charset = element.getAttribute("charset").trim().toLowerCase();
|
|
480
479
|
}
|
|
481
480
|
});
|
|
482
|
-
if (charset
|
|
481
|
+
if (!charset) {
|
|
482
|
+
this.doc.querySelectorAll("meta[http-equiv=\"content-type\"]").forEach(element => {
|
|
483
|
+
const charsetDeclaration = element.content.split(";")[1];
|
|
484
|
+
if (charsetDeclaration && !charset) {
|
|
485
|
+
charset = charsetDeclaration.split("=")[1].trim().toLowerCase();
|
|
486
|
+
}
|
|
487
|
+
});
|
|
488
|
+
}
|
|
489
|
+
if (charset && content.charset && charset != content.charset.toLowerCase()) {
|
|
483
490
|
return this.loadPage(pageContent, charset);
|
|
484
491
|
}
|
|
485
492
|
}
|
|
@@ -857,7 +864,7 @@ class Processor {
|
|
|
857
864
|
this.stats.set("discarded", "objects", objectElements.length);
|
|
858
865
|
this.stats.set("processed", "objects", objectElements.length);
|
|
859
866
|
objectElements.forEach(element => element.remove());
|
|
860
|
-
const replacedAttributeValue = this.doc.querySelectorAll("link[rel~=preconnect], link[rel~=prerender], link[rel~=dns-prefetch], link[rel~=preload], link[rel~=manifest], link[rel~=prefetch]");
|
|
867
|
+
const replacedAttributeValue = this.doc.querySelectorAll("link[rel~=preconnect], link[rel~=prerender], link[rel~=dns-prefetch], link[rel~=preload], link[rel~=manifest], link[rel~=prefetch], link[rel~=modulepreload]");
|
|
861
868
|
replacedAttributeValue.forEach(element => {
|
|
862
869
|
const relValue = element
|
|
863
870
|
.getAttribute("rel")
|
|
@@ -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) =>
|
|
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) =>
|
|
441
|
-
const findSourceByContentType = (contentType, testValidity) =>
|
|
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,
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
import { parse } from "./template-parser.js";
|
|
27
27
|
import { getContentSize, digest } from "./../core/helper.js";
|
|
28
28
|
|
|
29
|
-
const Blob = globalThis.Blob;
|
|
29
|
+
const Blob = globalThis.Blob;
|
|
30
30
|
const FileReader = globalThis.FileReader;
|
|
31
31
|
const URL = globalThis.URL;
|
|
32
32
|
const URLSearchParams = globalThis.URLSearchParams;
|
|
@@ -16991,6 +16991,10 @@ async function evalTemplate(template = "", options, content, doc, dontReplaceSla
|
|
|
16991
16991
|
"length": value => value.length,
|
|
16992
16992
|
"url-search-name": (index = 0) => params[index] && params[index][0],
|
|
16993
16993
|
"url-search-value": (index = 0) => params[index] && params[index][1],
|
|
16994
|
+
"url-search-named-value": name => {
|
|
16995
|
+
const param = params.find(param => param[0] == name);
|
|
16996
|
+
return (param && param[1]);
|
|
16997
|
+
},
|
|
16994
16998
|
"url-search": name => {
|
|
16995
16999
|
const param = params.find(param => param[0] == name);
|
|
16996
17000
|
return (param && param[1]);
|
|
@@ -17030,6 +17034,9 @@ async function evalTemplate(template = "", options, content, doc, dontReplaceSla
|
|
|
17030
17034
|
const fn = functions[name];
|
|
17031
17035
|
if (fn) {
|
|
17032
17036
|
argument = argument.replace(/\\\\(.)/g, "$1");
|
|
17037
|
+
if (!optionalArguments) {
|
|
17038
|
+
optionalArguments = [];
|
|
17039
|
+
}
|
|
17033
17040
|
optionalArguments = optionalArguments
|
|
17034
17041
|
.map(argument => argument.replace(/\\\\(.)/g, "$1"))
|
|
17035
17042
|
.filter(argument => argument != undefined && argument != null && argument != "");
|
package/package.json
CHANGED
|
@@ -191,7 +191,7 @@
|
|
|
191
191
|
const time = 0;
|
|
192
192
|
return { target, intersectionRatio, boundingClientRect, intersectionRect: boundingClientRect, isIntersecting, rootBounds, time };
|
|
193
193
|
});
|
|
194
|
-
observer.callback(params, intersectionObserver);
|
|
194
|
+
observer.callback.call(intersectionObserver, params, intersectionObserver);
|
|
195
195
|
}
|
|
196
196
|
});
|
|
197
197
|
}
|