|
|
@@ -18,49 +18,37 @@
|
|
|
* along with SingleFile. If not, see <http://www.gnu.org/licenses/>.
|
|
|
*/
|
|
|
|
|
|
-/* global
|
|
|
- cssMinifier,
|
|
|
- cssRulesMinifier,
|
|
|
- docHelper,
|
|
|
- fontsAltMinifier,
|
|
|
- fontsMinifier,
|
|
|
- htmlMinifier,
|
|
|
- imagesAltMinifier,
|
|
|
- matchedRules,
|
|
|
- mediasMinifier,
|
|
|
- serializer,
|
|
|
- srcsetParser,
|
|
|
- URL */
|
|
|
+/* global URL */
|
|
|
|
|
|
this.DocUtilCore = this.DocUtilCore || (() => {
|
|
|
|
|
|
- if (this.serializer === undefined) {
|
|
|
- this.serializer = {
|
|
|
- process(doc) {
|
|
|
- const docType = doc.doctype;
|
|
|
- let docTypeString = "";
|
|
|
- if (docType) {
|
|
|
- docTypeString = "<!DOCTYPE " + docType.nodeName;
|
|
|
- if (docType.publicId) {
|
|
|
- docTypeString += " PUBLIC \"" + docType.publicId + "\"";
|
|
|
- if (docType.systemId)
|
|
|
- docTypeString += " \"" + docType.systemId + "\"";
|
|
|
- } else if (docType.systemId)
|
|
|
- docTypeString += " SYSTEM \"" + docType.systemId + "\"";
|
|
|
- if (docType.internalSubset)
|
|
|
- docTypeString += " [" + docType.internalSubset + "]";
|
|
|
- docTypeString += "> ";
|
|
|
- }
|
|
|
- return docTypeString + doc.documentElement.outerHTML;
|
|
|
+ return {
|
|
|
+ getClass: (modules, domUtil) => {
|
|
|
+ if (modules.serializer === undefined) {
|
|
|
+ modules.serializer = {
|
|
|
+ process(doc) {
|
|
|
+ const docType = doc.doctype;
|
|
|
+ let docTypeString = "";
|
|
|
+ if (docType) {
|
|
|
+ docTypeString = "<!DOCTYPE " + docType.nodeName;
|
|
|
+ if (docType.publicId) {
|
|
|
+ docTypeString += " PUBLIC \"" + docType.publicId + "\"";
|
|
|
+ if (docType.systemId)
|
|
|
+ docTypeString += " \"" + docType.systemId + "\"";
|
|
|
+ } else if (docType.systemId)
|
|
|
+ docTypeString += " SYSTEM \"" + docType.systemId + "\"";
|
|
|
+ if (docType.internalSubset)
|
|
|
+ docTypeString += " [" + docType.internalSubset + "]";
|
|
|
+ docTypeString += "> ";
|
|
|
+ }
|
|
|
+ return docTypeString + doc.documentElement.outerHTML;
|
|
|
+ }
|
|
|
+ };
|
|
|
}
|
|
|
- };
|
|
|
- }
|
|
|
|
|
|
- return {
|
|
|
- getClass: (getContent, parseDocContent, parseSVGContent, isValidFontUrl, getContentSize, digestText) => {
|
|
|
return class DocUtl {
|
|
|
static async getContent(resourceURL, options) {
|
|
|
- return getContent(resourceURL, options);
|
|
|
+ return domUtil.getContent(resourceURL, options);
|
|
|
}
|
|
|
|
|
|
static parseURL(resourceURL, baseURI) {
|
|
|
@@ -72,103 +60,103 @@ this.DocUtilCore = this.DocUtilCore || (() => {
|
|
|
}
|
|
|
|
|
|
static parseDocContent(content, baseURI) {
|
|
|
- return parseDocContent(content, baseURI);
|
|
|
+ return domUtil.parseDocContent(content, baseURI);
|
|
|
}
|
|
|
|
|
|
static parseSVGContent(content) {
|
|
|
- return parseSVGContent(content);
|
|
|
+ return domUtil.parseSVGContent(content);
|
|
|
}
|
|
|
|
|
|
static async digest(algo, text) {
|
|
|
- return digestText(algo, text);
|
|
|
+ return domUtil.digestText(algo, text);
|
|
|
}
|
|
|
|
|
|
static getContentSize(content) {
|
|
|
- return getContentSize(content);
|
|
|
+ return domUtil.getContentSize(content);
|
|
|
}
|
|
|
|
|
|
static async validFont(urlFunction) {
|
|
|
- return isValidFontUrl(urlFunction);
|
|
|
+ return domUtil.isValidFontUrl(urlFunction);
|
|
|
}
|
|
|
|
|
|
static minifyHTML(doc, options) {
|
|
|
- return htmlMinifier.process(doc, options);
|
|
|
+ return modules.htmlMinifier.process(doc, options);
|
|
|
}
|
|
|
|
|
|
static postMinifyHTML(doc) {
|
|
|
- return htmlMinifier.postProcess(doc);
|
|
|
+ return modules.htmlMinifier.postProcess(doc);
|
|
|
}
|
|
|
|
|
|
static minifyCSSRules(stylesheets, styles, mediaAllInfo) {
|
|
|
- return cssRulesMinifier.process(stylesheets, styles, mediaAllInfo);
|
|
|
+ return modules.cssRulesMinifier.process(stylesheets, styles, mediaAllInfo);
|
|
|
}
|
|
|
|
|
|
static removeUnusedFonts(doc, stylesheets, styles, options) {
|
|
|
- return fontsMinifier.process(doc, stylesheets, styles, options);
|
|
|
+ return modules.fontsMinifier.process(doc, stylesheets, styles, options);
|
|
|
}
|
|
|
|
|
|
static removeAlternativeFonts(doc, stylesheets) {
|
|
|
- return fontsAltMinifier.process(doc, stylesheets);
|
|
|
+ return modules.fontsAltMinifier.process(doc, stylesheets);
|
|
|
}
|
|
|
|
|
|
static getMediaAllInfo(doc, stylesheets, styles) {
|
|
|
- return matchedRules.getMediaAllInfo(doc, stylesheets, styles);
|
|
|
+ return modules.matchedRules.getMediaAllInfo(doc, stylesheets, styles);
|
|
|
}
|
|
|
|
|
|
static compressCSS(content, options) {
|
|
|
- return cssMinifier.processString(content, options);
|
|
|
+ return modules.cssMinifier.processString(content, options);
|
|
|
}
|
|
|
|
|
|
static minifyMedias(stylesheets) {
|
|
|
- return mediasMinifier.process(stylesheets);
|
|
|
+ return modules.mediasMinifier.process(stylesheets);
|
|
|
}
|
|
|
|
|
|
static removeAlternativeImages(doc, options) {
|
|
|
- return imagesAltMinifier.process(doc, options);
|
|
|
+ return modules.imagesAltMinifier.process(doc, options);
|
|
|
}
|
|
|
|
|
|
static parseSrcset(srcset) {
|
|
|
- return srcsetParser.process(srcset);
|
|
|
+ return modules.srcsetParser.process(srcset);
|
|
|
}
|
|
|
|
|
|
static preProcessDoc(doc, win, options) {
|
|
|
- return docHelper.preProcessDoc(doc, win, options);
|
|
|
+ return modules.docHelper.preProcessDoc(doc, win, options);
|
|
|
}
|
|
|
|
|
|
static postProcessDoc(doc, options) {
|
|
|
- docHelper.postProcessDoc(doc, options);
|
|
|
+ modules.docHelper.postProcessDoc(doc, options);
|
|
|
}
|
|
|
|
|
|
static serialize(doc, compressHTML) {
|
|
|
- return serializer.process(doc, compressHTML);
|
|
|
+ return modules.serializer.process(doc, compressHTML);
|
|
|
}
|
|
|
|
|
|
static removeQuotes(string) {
|
|
|
- return docHelper.removeQuotes(string);
|
|
|
+ return modules.docHelper.removeQuotes(string);
|
|
|
}
|
|
|
|
|
|
static windowIdAttributeName(sessionId) {
|
|
|
- return docHelper.windowIdAttributeName(sessionId);
|
|
|
+ return modules.docHelper.windowIdAttributeName(sessionId);
|
|
|
}
|
|
|
|
|
|
static preservedSpaceAttributeName(sessionId) {
|
|
|
- return docHelper.preservedSpaceAttributeName(sessionId);
|
|
|
+ return modules.docHelper.preservedSpaceAttributeName(sessionId);
|
|
|
}
|
|
|
|
|
|
static removedContentAttributeName(sessionId) {
|
|
|
- return docHelper.removedContentAttributeName(sessionId);
|
|
|
+ return modules.docHelper.removedContentAttributeName(sessionId);
|
|
|
}
|
|
|
|
|
|
static imagesAttributeName(sessionId) {
|
|
|
- return docHelper.imagesAttributeName(sessionId);
|
|
|
+ return modules.docHelper.imagesAttributeName(sessionId);
|
|
|
}
|
|
|
|
|
|
static inputValueAttributeName(sessionId) {
|
|
|
- return docHelper.inputValueAttributeName(sessionId);
|
|
|
+ return modules.docHelper.inputValueAttributeName(sessionId);
|
|
|
}
|
|
|
|
|
|
static shadowRootAttributeName(sessionId) {
|
|
|
- return docHelper.shadowRootAttributeName(sessionId);
|
|
|
+ return modules.docHelper.shadowRootAttributeName(sessionId);
|
|
|
}
|
|
|
};
|
|
|
}
|