single-file-core 1.3.2 → 1.3.3
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
|
@@ -1344,7 +1344,7 @@ class Processor {
|
|
|
1344
1344
|
}
|
|
1345
1345
|
if (testValidURL(resourceURL)) {
|
|
1346
1346
|
element.removeAttribute("src");
|
|
1347
|
-
await this.processorHelper.processScript(element, resourceURL, this.options, this.charset);
|
|
1347
|
+
await this.processorHelper.processScript(element, resourceURL, this.options, this.charset, this.batchRequest, this.resources);
|
|
1348
1348
|
if (element.getAttribute("async") == "async" || element.getAttribute(util.ASYNC_SCRIPT_ATTRIBUTE_NAME) == "") {
|
|
1349
1349
|
element.setAttribute("async", "");
|
|
1350
1350
|
}
|
|
@@ -21,6 +21,8 @@
|
|
|
21
21
|
* Source.
|
|
22
22
|
*/
|
|
23
23
|
|
|
24
|
+
/* global globalThis */
|
|
25
|
+
|
|
24
26
|
import {
|
|
25
27
|
normalizeFontFamily,
|
|
26
28
|
getFontWeight
|
|
@@ -59,6 +61,8 @@ const FONT_STRETCHES = {
|
|
|
59
61
|
"extra-expanded": "150%",
|
|
60
62
|
"ultra-expanded": "200%"
|
|
61
63
|
};
|
|
64
|
+
const Blob = globalThis.Blob;
|
|
65
|
+
const FileReader = globalThis.FileReader;
|
|
62
66
|
|
|
63
67
|
let util, cssTree;
|
|
64
68
|
|
|
@@ -74,7 +78,8 @@ export {
|
|
|
74
78
|
replaceOriginalURLs,
|
|
75
79
|
testIgnoredPath,
|
|
76
80
|
testValidPath,
|
|
77
|
-
testValidURL
|
|
81
|
+
testValidURL,
|
|
82
|
+
toDataURI
|
|
78
83
|
};
|
|
79
84
|
|
|
80
85
|
function getProcessorHelperCommonClass(utilInstance, cssTreeInstance) {
|
|
@@ -575,12 +580,10 @@ function processFontDetails(fontsDetails, fontResources) {
|
|
|
575
580
|
}
|
|
576
581
|
}
|
|
577
582
|
|
|
578
|
-
function getUpdatedResourceContent(resourceURL,
|
|
583
|
+
function getUpdatedResourceContent(resourceURL, options) {
|
|
579
584
|
if (options.rootDocument && options.updatedResources[resourceURL]) {
|
|
580
585
|
options.updatedResources[resourceURL].retrieved = true;
|
|
581
586
|
return options.updatedResources[resourceURL].content;
|
|
582
|
-
} else {
|
|
583
|
-
return content.data || "";
|
|
584
587
|
}
|
|
585
588
|
}
|
|
586
589
|
|
|
@@ -652,4 +655,13 @@ function getURL(urlFunction) {
|
|
|
652
655
|
|
|
653
656
|
function getFontStretch(stretch) {
|
|
654
657
|
return FONT_STRETCHES[stretch] || stretch;
|
|
658
|
+
}
|
|
659
|
+
|
|
660
|
+
function toDataURI(content, contentType, charset) {
|
|
661
|
+
return new Promise((resolve, reject) => {
|
|
662
|
+
const reader = new FileReader();
|
|
663
|
+
reader.onload = () => resolve(reader.result);
|
|
664
|
+
reader.onerror = () => reject(new Error(reader.error));
|
|
665
|
+
reader.readAsDataURL(new Blob([content], { type: (contentType || "") + (charset ? ";charset=" + charset : "") }));
|
|
666
|
+
});
|
|
655
667
|
}
|
|
@@ -59,7 +59,8 @@ import {
|
|
|
59
59
|
replaceOriginalURLs,
|
|
60
60
|
testIgnoredPath,
|
|
61
61
|
testValidPath,
|
|
62
|
-
testValidURL
|
|
62
|
+
testValidURL,
|
|
63
|
+
toDataURI
|
|
63
64
|
} from "./processor-helper-common.js";
|
|
64
65
|
|
|
65
66
|
export {
|
|
@@ -152,7 +153,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
152
153
|
options.inline = true;
|
|
153
154
|
const content = await this.getStylesheetContent(resourceURL, options);
|
|
154
155
|
resourceURL = content.resourceURL;
|
|
155
|
-
content.data = getUpdatedResourceContent(resourceURL,
|
|
156
|
+
content.data = getUpdatedResourceContent(resourceURL, options) || content.data;
|
|
156
157
|
if (content.data && content.data.match(/^<!doctype /i)) {
|
|
157
158
|
content.data = "";
|
|
158
159
|
}
|
|
@@ -200,13 +201,11 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
200
201
|
return this.resolveLinkStylesheetURLs(resourceURL, baseURI, options, workStylesheet);
|
|
201
202
|
}
|
|
202
203
|
resourceURL = content.resourceURL;
|
|
203
|
-
content.data = getUpdatedResourceContent(content.resourceURL,
|
|
204
|
+
content.data = getUpdatedResourceContent(content.resourceURL, options) || content.data;
|
|
204
205
|
if (content.data && content.data.match(/^<!doctype /i)) {
|
|
205
206
|
content.data = "";
|
|
206
207
|
}
|
|
207
|
-
|
|
208
208
|
content.data = content.data.replace(/:defined/gi, "*");
|
|
209
|
-
|
|
210
209
|
let stylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
|
|
211
210
|
const importFound = await this.resolveImportURLs(stylesheet, resourceURL, options, workStylesheet);
|
|
212
211
|
if (importFound) {
|
|
@@ -452,23 +451,28 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
452
451
|
return {};
|
|
453
452
|
}
|
|
454
453
|
|
|
455
|
-
async processScript(element, resourceURL, options, charset) {
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
|
|
454
|
+
async processScript(element, resourceURL, options, charset, batchRequest) {
|
|
455
|
+
let content = getUpdatedResourceContent(resourceURL, options);
|
|
456
|
+
if (content) {
|
|
457
|
+
content = await toDataURI(content, "text/javascript", charset);
|
|
458
|
+
} else {
|
|
459
|
+
const result = await batchRequest.addURL(resourceURL, {
|
|
460
|
+
asBinary: true,
|
|
461
|
+
inline: true,
|
|
462
|
+
charset: charset != UTF8_CHARSET && charset,
|
|
463
|
+
maxResourceSize: options.maxResourceSize,
|
|
464
|
+
maxResourceSizeEnabled: options.maxResourceSizeEnabled,
|
|
465
|
+
frameId: options.windowId,
|
|
466
|
+
resourceReferrer: options.resourceReferrer,
|
|
467
|
+
baseURI: options.baseURI,
|
|
468
|
+
blockMixedContent: options.blockMixedContent,
|
|
469
|
+
expectedType: "script",
|
|
470
|
+
acceptHeaders: options.acceptHeaders,
|
|
471
|
+
networkTimeout: options.networkTimeout
|
|
472
|
+
});
|
|
473
|
+
content = result.content;
|
|
474
|
+
}
|
|
475
|
+
element.setAttribute("src", content);
|
|
472
476
|
}
|
|
473
477
|
|
|
474
478
|
setMetaCSP(metaElement) {
|
|
@@ -154,7 +154,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
154
154
|
if (existingStylesheet) {
|
|
155
155
|
stylesheets.set({ urlNode }, { url: resourceURL, stylesheet: existingStylesheet[1].stylesheet, scoped });
|
|
156
156
|
} else {
|
|
157
|
-
content.data = getUpdatedResourceContent(resourceURL,
|
|
157
|
+
content.data = getUpdatedResourceContent(resourceURL, options) || content.data;
|
|
158
158
|
stylesheetInfo.stylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
|
|
159
159
|
await this.resolveImportURLs(stylesheetInfo, resourceURL, options, workStylesheet, resources, stylesheets);
|
|
160
160
|
stylesheets.set({ urlNode }, stylesheetInfo);
|
|
@@ -202,7 +202,7 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
202
202
|
mediaText: stylesheetInfo.mediaText
|
|
203
203
|
});
|
|
204
204
|
} else {
|
|
205
|
-
content.data = getUpdatedResourceContent(content.resourceURL,
|
|
205
|
+
content.data = getUpdatedResourceContent(content.resourceURL, options) || content.data;
|
|
206
206
|
stylesheetInfo.stylesheet = cssTree.parse(content.data, { context: "stylesheet", parseCustomProperty: true });
|
|
207
207
|
await this.resolveImportURLs(stylesheetInfo, resourceURL, options, workStylesheet, resources, stylesheets);
|
|
208
208
|
stylesheets.set({ element }, stylesheetInfo);
|
|
@@ -378,8 +378,8 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
378
378
|
};
|
|
379
379
|
}
|
|
380
380
|
|
|
381
|
-
async processScript(element, resourceURL, options, charset) {
|
|
382
|
-
|
|
381
|
+
async processScript(element, resourceURL, options, charset, batchRequest, resources) {
|
|
382
|
+
let { content, indexResource, extension, contentType } = await batchRequest.addURL(resourceURL, {
|
|
383
383
|
asBinary: true,
|
|
384
384
|
charset: charset != UTF8_CHARSET && charset,
|
|
385
385
|
maxResourceSize: options.maxResourceSize,
|
|
@@ -392,8 +392,10 @@ function getProcessorHelperClass(utilInstance) {
|
|
|
392
392
|
acceptHeaders: options.acceptHeaders,
|
|
393
393
|
networkTimeout: options.networkTimeout
|
|
394
394
|
});
|
|
395
|
-
content
|
|
396
|
-
|
|
395
|
+
content = getUpdatedResourceContent(resourceURL, options) || content;
|
|
396
|
+
const name = "scripts/" + indexResource + extension;
|
|
397
|
+
element.setAttribute("src", name);
|
|
398
|
+
resources.scripts.set(indexResource, { name, content, extension, contentType, url: resourceURL });
|
|
397
399
|
}
|
|
398
400
|
|
|
399
401
|
setMetaCSP(metaElement) {
|