diff options
Diffstat (limited to 'node_modules/clean-css/lib')
5 files changed, 76 insertions, 18 deletions
diff --git a/node_modules/clean-css/lib/optimizer/level-1/optimize.js b/node_modules/clean-css/lib/optimizer/level-1/optimize.js index 5a6da47c0..82cb9531d 100644 --- a/node_modules/clean-css/lib/optimizer/level-1/optimize.js +++ b/node_modules/clean-css/lib/optimizer/level-1/optimize.js @@ -98,11 +98,11 @@ function optimizeColors(name, value, compatibility) { .replace(/hsl\((-?\d+),(-?\d+)%?,(-?\d+)%?\)/g, function (match, hue, saturation, lightness) { return shortenHsl(hue, saturation, lightness); }) - .replace(/(^|[^='"])#([0-9a-f]{6})/gi, function (match, prefix, color) { + .replace(/(^|[^='"])#([0-9a-f]{6})($|[^0-9a-f])/gi, function (match, prefix, color, suffix) { if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) { - return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase(); + return (prefix + '#' + color[0] + color[2] + color[4]).toLowerCase() + suffix; } else { - return (prefix + '#' + color).toLowerCase(); + return (prefix + '#' + color).toLowerCase() + suffix; } }) .replace(/(^|[^='"])#([0-9a-f]{3})/gi, function (match, prefix, color) { @@ -269,7 +269,7 @@ function optimizeUnits(name, value, unitsRegexp) { return value; } - if (value.indexOf('%') > 0 && (name == 'height' || name == 'max-height')) { + if (value.indexOf('%') > 0 && (name == 'height' || name == 'max-height' || name == 'width' || name == 'max-width')) { return value; } @@ -491,10 +491,7 @@ function optimizeBody(properties, context) { restoreFromOptimizing(_properties); removeUnused(_properties); - - if (_properties.length != properties.length) { - removeComments(properties, options); - } + removeComments(properties, options); } function removeComments(tokens, options) { @@ -654,7 +651,7 @@ function level1Optimize(tokens, context) { break; } - if (levelOptions.removeEmpty && (token[1].length === 0 || (token[2] && token[2].length === 0))) { + if (token[0] == Token.COMMENT && token[1].length === 0 || levelOptions.removeEmpty && (token[1].length === 0 || (token[2] && token[2].length === 0))) { tokens.splice(i, 1); i--; l--; diff --git a/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js b/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js index b47ed6b79..0af3b2fe7 100644 --- a/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js +++ b/node_modules/clean-css/lib/optimizer/level-1/tidy-rules.js @@ -70,7 +70,7 @@ function removeWhitespace(value, format) { isNewLineNix = character == Marker.NEW_LINE_NIX; isNewLineWin = character == Marker.NEW_LINE_NIX && value[i - 1] == Marker.NEW_LINE_WIN; isQuoted = isSingleQuoted || isDoubleQuoted; - isRelation = !isEscaped && roundBracketLevel === 0 && RELATION_PATTERN.test(character); + isRelation = !isAttribute && !isEscaped && roundBracketLevel === 0 && RELATION_PATTERN.test(character); isWhitespace = WHITESPACE_PATTERN.test(character); if (wasEscaped && isQuoted && isNewLineWin) { diff --git a/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js b/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js index e60d5e7c2..7285991a4 100644 --- a/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js +++ b/node_modules/clean-css/lib/optimizer/level-2/remove-unused-at-rules.js @@ -19,7 +19,8 @@ function removeUnusedAtRules(tokens, context) { function removeUnusedAtRule(tokens, matchCallback, markCallback, context) { var atRules = {}; var atRule; - var token; + var atRuleTokens; + var atRuleToken; var zeroAt; var i, l; @@ -34,9 +35,13 @@ function removeUnusedAtRule(tokens, matchCallback, markCallback, context) { markUsedAtRules(tokens, markCallback, atRules, context); for (atRule in atRules) { - token = atRules[atRule]; - zeroAt = token[0] == Token.AT_RULE ? 1 : 2; - token[zeroAt] = []; + atRuleTokens = atRules[atRule]; + + for (i = 0, l = atRuleTokens.length; i < l; i++) { + atRuleToken = atRuleTokens[i]; + zeroAt = atRuleToken[0] == Token.AT_RULE ? 1 : 2; + atRuleToken[zeroAt] = []; + } } } @@ -60,7 +65,8 @@ function matchCounterStyle(token, atRules) { if (token[0] == Token.AT_RULE_BLOCK && token[1][0][1].indexOf('@counter-style') === 0) { match = token[1][0][1].split(' ')[1]; - atRules[match] = token; + atRules[match] = atRules[match] || []; + atRules[match].push(token); } } @@ -102,7 +108,8 @@ function matchFontFace(token, atRules) { if (property[1][1] == 'font-family') { match = property[2][1].toLowerCase(); - atRules[match] = token; + atRules[match] = atRules[match] || []; + atRules[match].push(token); break; } } @@ -155,7 +162,8 @@ function matchKeyframe(token, atRules) { if (token[0] == Token.NESTED_BLOCK && keyframeRegex.test(token[1][0][1])) { match = token[1][0][1].split(' ')[1]; - atRules[match] = token; + atRules[match] = atRules[match] || []; + atRules[match].push(token); } } @@ -200,7 +208,8 @@ function matchNamespace(token, atRules) { if (token[0] == Token.AT_RULE && token[1].indexOf('@namespace') === 0) { match = token[1].split(' ')[1]; - atRules[match] = token; + atRules[match] = atRules[match] || []; + atRules[match].push(token); } } diff --git a/node_modules/clean-css/lib/tokenizer/tokenize.js b/node_modules/clean-css/lib/tokenizer/tokenize.js index 7c071dd93..018b89de8 100644 --- a/node_modules/clean-css/lib/tokenizer/tokenize.js +++ b/node_modules/clean-css/lib/tokenizer/tokenize.js @@ -28,6 +28,34 @@ var BLOCK_RULES = [ '@supports' ]; +var PAGE_MARGIN_BOXES = [ + '@bottom-center', + '@bottom-left', + '@bottom-left-corner', + '@bottom-right', + '@bottom-right-corner', + '@left-bottom', + '@left-middle', + '@left-top', + '@right-bottom', + '@right-middle', + '@right-top', + '@top-center', + '@top-left', + '@top-left-corner', + '@top-right', + '@top-right-corner' +]; + +var EXTRA_PAGE_BOXES = [ + '@footnote', + '@footnotes', + '@left', + '@page-float-bottom', + '@page-float-top', + '@right' +]; + var REPEAT_PATTERN = /^\[\s*\d+\s*\]$/; var RULE_WORD_SEPARATOR_PATTERN = /[\s\(]/; var TAIL_BROKEN_VALUE_PATTERN = /[\s|\}]*$/; @@ -221,6 +249,18 @@ function intoTokens(source, externalContext, internalContext, isNested) { levels.push(level); level = Level.RULE; seekingValue = false; + } else if (character == Marker.OPEN_CURLY_BRACKET && level == Level.RULE && isPageMarginBox(buffer)) { + // open brace opening page-margin box at rule level, e.g. @page{@top-center{<-- + serializedBuffer = buffer.join('').trim(); + ruleTokens.push(ruleToken); + ruleToken = [Token.AT_RULE_BLOCK, [], []]; + ruleToken[1].push([Token.AT_RULE_BLOCK_SCOPE, serializedBuffer, [originalMetadata(metadata, serializedBuffer, externalContext)]]); + newTokens.push(ruleToken); + newTokens = ruleToken[2]; + + levels.push(level); + level = Level.RULE; + buffer = []; } else if (character == Marker.COLON && level == Level.RULE && !seekingValue) { // colon at rule level, e.g. a{color:<-- serializedBuffer = buffer.join('').trim(); @@ -467,6 +507,12 @@ function tokenScopeFrom(tokenType) { } } +function isPageMarginBox(buffer) { + var serializedBuffer = buffer.join('').trim(); + + return PAGE_MARGIN_BOXES.indexOf(serializedBuffer) > -1 || EXTRA_PAGE_BOXES.indexOf(serializedBuffer) > -1; +} + function isRepeatToken(buffer) { return REPEAT_PATTERN.test(buffer.join('') + Marker.CLOSE_SQUARE_BRACKET); } diff --git a/node_modules/clean-css/lib/writer/helpers.js b/node_modules/clean-css/lib/writer/helpers.js index ab08633e8..da13cf6eb 100644 --- a/node_modules/clean-css/lib/writer/helpers.js +++ b/node_modules/clean-css/lib/writer/helpers.js @@ -87,6 +87,12 @@ function property(context, tokens, position, lastPropertyAt) { store(context, token); store(context, semicolon(context, Breaks.AfterProperty, false)); break; + case Token.AT_RULE_BLOCK: + rules(context, token[1]); + store(context, openBrace(context, Breaks.AfterRuleBegins, true)); + body(context, token[2]); + store(context, closeBrace(context, Breaks.AfterRuleEnds, false, isLast)); + break; case Token.COMMENT: store(context, token); break; |