From bbff7403fbf46f9ad92240ac213df8d30ef31b64 Mon Sep 17 00:00:00 2001 From: Florian Dold Date: Thu, 20 Sep 2018 02:56:13 +0200 Subject: update packages --- node_modules/html-minifier/src/htmlminifier.js | 425 +++++++++++++------------ 1 file changed, 225 insertions(+), 200 deletions(-) (limited to 'node_modules/html-minifier/src/htmlminifier.js') diff --git a/node_modules/html-minifier/src/htmlminifier.js b/node_modules/html-minifier/src/htmlminifier.js index 6910e15dd..ecf06eba1 100644 --- a/node_modules/html-minifier/src/htmlminifier.js +++ b/node_modules/html-minifier/src/htmlminifier.js @@ -8,20 +8,13 @@ var TokenChain = require('./tokenchain'); var UglifyJS = require('uglify-js'); var utils = require('./utils'); -var trimWhitespace = String.prototype.trim ? function(str) { - if (typeof str !== 'string') { - return str; - } - return str.trim(); -} : function(str) { - if (typeof str !== 'string') { - return str; - } - return str.replace(/^\s+/, '').replace(/\s+$/, ''); -}; +function trimWhitespace(str) { + return str && str.replace(/^[ \n\r\t\f]+/, '').replace(/[ \n\r\t\f]+$/, ''); +} function collapseWhitespaceAll(str) { - return str && str.replace(/\s+/g, function(spaces) { + // Non-breaking space is specifically handled inside the replacer function here: + return str && str.replace(/[ \n\r\t\f\xA0]+/g, function(spaces) { return spaces === '\t' ? '\t' : spaces.replace(/(^|\xA0+)[^\xA0]+/g, '$1 '); }); } @@ -30,17 +23,18 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll) { var lineBreakBefore = '', lineBreakAfter = ''; if (options.preserveLineBreaks) { - str = str.replace(/^\s*?[\n\r]\s*/, function() { + str = str.replace(/^[ \n\r\t\f]*?[\n\r][ \n\r\t\f]*/, function() { lineBreakBefore = '\n'; return ''; - }).replace(/\s*?[\n\r]\s*$/, function() { + }).replace(/[ \n\r\t\f]*?[\n\r][ \n\r\t\f]*$/, function() { lineBreakAfter = '\n'; return ''; }); } if (trimLeft) { - str = str.replace(/^\s+/, function(spaces) { + // Non-breaking space is specifically handled inside the replacer function here: + str = str.replace(/^[ \n\r\t\f\xA0]+/, function(spaces) { var conservative = !lineBreakBefore && options.conservativeCollapse; if (conservative && spaces === '\t') { return '\t'; @@ -50,7 +44,8 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll) { } if (trimRight) { - str = str.replace(/\s+$/, function(spaces) { + // Non-breaking space is specifically handled inside the replacer function here: + str = str.replace(/[ \n\r\t\f\xA0]+$/, function(spaces) { var conservative = !lineBreakAfter && options.conservativeCollapse; if (conservative && spaces === '\t') { return '\t'; @@ -69,9 +64,9 @@ function collapseWhitespace(str, options, trimLeft, trimRight, collapseAll) { var createMapFromString = utils.createMapFromString; // non-empty tags that will maintain whitespace around them -var inlineTags = createMapFromString('a,abbr,acronym,b,bdi,bdo,big,button,cite,code,del,dfn,em,font,i,ins,kbd,mark,math,nobr,q,rt,rp,s,samp,small,span,strike,strong,sub,sup,svg,time,tt,u,var'); +var inlineTags = createMapFromString('a,abbr,acronym,b,bdi,bdo,big,button,cite,code,del,dfn,em,font,i,ins,kbd,label,mark,math,nobr,object,q,rp,rt,rtc,ruby,s,samp,select,small,span,strike,strong,sub,sup,svg,textarea,time,tt,u,var'); // non-empty tags that will maintain whitespace within them -var inlineTextTags = createMapFromString('a,abbr,acronym,b,big,del,em,font,i,ins,kbd,mark,nobr,s,samp,small,span,strike,strong,sub,sup,time,tt,u,var'); +var inlineTextTags = createMapFromString('a,abbr,acronym,b,big,del,em,font,i,ins,kbd,mark,nobr,rp,s,samp,small,span,strike,strong,sub,sup,time,tt,u,var'); // self-closing tags that will maintain whitespace around them var selfClosingInlineTags = createMapFromString('comment,img,input,wbr'); @@ -114,7 +109,7 @@ function isEventAttribute(attrName, options) { } function canRemoveAttributeQuotes(value) { - // http://mathiasbynens.be/notes/unquoted-attribute-values + // https://mathiasbynens.be/notes/unquoted-attribute-values return /^[^ \t\n\f\r"'`=<>]+$/.test(value); } @@ -260,7 +255,7 @@ function isSrcset(attrName, tag) { } function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { - if (attrValue && isEventAttribute(attrName, options)) { + if (isEventAttribute(attrName, options)) { attrValue = trimWhitespace(attrValue).replace(/^javascript:\s*/i, ''); return options.minifyJS(attrValue, true); } @@ -285,9 +280,9 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { attrValue = trimWhitespace(attrValue); if (attrValue) { if (/;$/.test(attrValue) && !/&#?[0-9a-zA-Z]+;$/.test(attrValue)) { - attrValue = attrValue.replace(/\s*;$/, ''); + attrValue = attrValue.replace(/\s*;$/, ';'); } - attrValue = unwrapInlineCSS(options.minifyCSS(wrapInlineCSS(attrValue))); + attrValue = options.minifyCSS(attrValue, 'inline'); } return attrValue; } @@ -316,7 +311,7 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { return (+numString).toString(); }); } - else if (attrValue && options.customAttrCollapse && options.customAttrCollapse.test(attrName)) { + else if (options.customAttrCollapse && options.customAttrCollapse.test(attrName)) { attrValue = attrValue.replace(/\n+|\r+|\s{2,}/g, ''); } else if (tag === 'script' && attrName === 'type') { @@ -324,7 +319,7 @@ function cleanAttributeValue(tag, attrName, attrValue, options, attrs) { } else if (isMediaQuery(tag, attrs, attrName)) { attrValue = trimWhitespace(attrValue); - return unwrapMediaQuery(options.minifyCSS(wrapMediaQuery(attrValue))); + return options.minifyCSS(attrValue, 'media'); } return attrValue; } @@ -340,23 +335,33 @@ function isMetaViewport(tag, attrs) { } } -// Wrap CSS declarations for CleanCSS > 3.x -// See https://github.com/jakubpawlowicz/clean-css/issues/418 -function wrapInlineCSS(text) { - return '*{' + text + '}'; -} - -function unwrapInlineCSS(text) { - var matches = text.match(/^\*\{([\s\S]*)\}$/); - return matches ? matches[1] : text; +function ignoreCSS(id) { + return '/* clean-css ignore:start */' + id + '/* clean-css ignore:end */'; } -function wrapMediaQuery(text) { - return '@media ' + text + '{a{top:0}}'; +// Wrap CSS declarations for CleanCSS > 3.x +// See https://github.com/jakubpawlowicz/clean-css/issues/418 +function wrapCSS(text, type) { + switch (type) { + case 'inline': + return '*{' + text + '}'; + case 'media': + return '@media ' + text + '{a{top:0}}'; + default: + return text; + } } -function unwrapMediaQuery(text) { - var matches = text.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/); +function unwrapCSS(text, type) { + var matches; + switch (type) { + case 'inline': + matches = text.match(/^\*\{([\s\S]*)\}$/); + break; + case 'media': + matches = text.match(/^@media ([\s\S]*?)\s*{[\s\S]*}$/); + break; + } return matches ? matches[1] : text; } @@ -379,7 +384,7 @@ function processScript(text, options, currentAttrs) { // Tag omission rules from https://html.spec.whatwg.org/multipage/syntax.html#optional-tags // with the following deviations: // - retain if followed by