clear
This commit is contained in:
131
node_modules/clean-css/lib/text/comments-processor.js
generated
vendored
Normal file
131
node_modules/clean-css/lib/text/comments-processor.js
generated
vendored
Normal file
@@ -0,0 +1,131 @@
|
||||
var EscapeStore = require('./escape-store');
|
||||
var QuoteScanner = require('../utils/quote-scanner');
|
||||
|
||||
var SPECIAL_COMMENT_PREFIX = '/*!';
|
||||
var COMMENT_PREFIX = '/*';
|
||||
var COMMENT_SUFFIX = '*/';
|
||||
|
||||
var lineBreak = require('os').EOL;
|
||||
|
||||
function CommentsProcessor(context, keepSpecialComments, keepBreaks, saveWaypoints) {
|
||||
this.comments = new EscapeStore('COMMENT');
|
||||
this.specialComments = new EscapeStore('COMMENT_SPECIAL');
|
||||
|
||||
this.context = context;
|
||||
this.restored = 0;
|
||||
this.keepAll = keepSpecialComments == '*';
|
||||
this.keepOne = keepSpecialComments == '1' || keepSpecialComments === 1;
|
||||
this.keepBreaks = keepBreaks;
|
||||
this.saveWaypoints = saveWaypoints;
|
||||
}
|
||||
|
||||
function quoteScannerFor(data) {
|
||||
var quoteMap = [];
|
||||
new QuoteScanner(data).each(function (quotedString, _, startsAt) {
|
||||
quoteMap.push([startsAt, startsAt + quotedString.length]);
|
||||
});
|
||||
|
||||
return function (position) {
|
||||
for (var i = 0, l = quoteMap.length; i < l; i++) {
|
||||
if (quoteMap[i][0] < position && quoteMap[i][1] > position)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
};
|
||||
}
|
||||
|
||||
CommentsProcessor.prototype.escape = function (data) {
|
||||
var tempData = [];
|
||||
var nextStart = 0;
|
||||
var nextEnd = 0;
|
||||
var cursor = 0;
|
||||
var indent = 0;
|
||||
var breaksCount;
|
||||
var lastBreakAt;
|
||||
var newIndent;
|
||||
var isQuotedAt = quoteScannerFor(data);
|
||||
var saveWaypoints = this.saveWaypoints;
|
||||
|
||||
for (; nextEnd < data.length;) {
|
||||
nextStart = data.indexOf(COMMENT_PREFIX, cursor);
|
||||
if (nextStart == -1)
|
||||
break;
|
||||
|
||||
if (isQuotedAt(nextStart)) {
|
||||
tempData.push(data.substring(cursor, nextStart + COMMENT_PREFIX.length));
|
||||
cursor = nextStart + COMMENT_PREFIX.length;
|
||||
continue;
|
||||
}
|
||||
|
||||
nextEnd = data.indexOf(COMMENT_SUFFIX, nextStart + COMMENT_PREFIX.length);
|
||||
if (nextEnd == -1) {
|
||||
this.context.warnings.push('Broken comment: \'' + data.substring(nextStart) + '\'.');
|
||||
nextEnd = data.length - 2;
|
||||
}
|
||||
|
||||
tempData.push(data.substring(cursor, nextStart));
|
||||
|
||||
var comment = data.substring(nextStart, nextEnd + COMMENT_SUFFIX.length);
|
||||
var isSpecialComment = comment.indexOf(SPECIAL_COMMENT_PREFIX) === 0;
|
||||
|
||||
if (saveWaypoints) {
|
||||
breaksCount = comment.split(lineBreak).length - 1;
|
||||
lastBreakAt = comment.lastIndexOf(lineBreak);
|
||||
newIndent = lastBreakAt > 0 ?
|
||||
comment.substring(lastBreakAt + lineBreak.length).length :
|
||||
indent + comment.length;
|
||||
}
|
||||
|
||||
if (saveWaypoints || isSpecialComment) {
|
||||
var metadata = saveWaypoints ? [breaksCount, newIndent] : null;
|
||||
var placeholder = isSpecialComment ?
|
||||
this.specialComments.store(comment, metadata) :
|
||||
this.comments.store(comment, metadata);
|
||||
tempData.push(placeholder);
|
||||
}
|
||||
|
||||
if (saveWaypoints)
|
||||
indent = newIndent + 1;
|
||||
cursor = nextEnd + COMMENT_SUFFIX.length;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
};
|
||||
|
||||
function restore(context, data, from, isSpecial) {
|
||||
var tempData = [];
|
||||
var cursor = 0;
|
||||
|
||||
for (; cursor < data.length;) {
|
||||
var nextMatch = from.nextMatch(data, cursor);
|
||||
if (nextMatch.start < 0)
|
||||
break;
|
||||
|
||||
tempData.push(data.substring(cursor, nextMatch.start));
|
||||
var comment = from.restore(nextMatch.match);
|
||||
|
||||
if (isSpecial && (context.keepAll || (context.keepOne && context.restored === 0))) {
|
||||
context.restored++;
|
||||
tempData.push(comment);
|
||||
|
||||
cursor = nextMatch.end;
|
||||
} else {
|
||||
cursor = nextMatch.end + (context.keepBreaks && data.substring(nextMatch.end, nextMatch.end + lineBreak.length) == lineBreak ? lineBreak.length : 0);
|
||||
}
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
}
|
||||
|
||||
CommentsProcessor.prototype.restore = function (data) {
|
||||
data = restore(this, data, this.comments, false);
|
||||
data = restore(this, data, this.specialComments, true);
|
||||
return data;
|
||||
};
|
||||
|
||||
module.exports = CommentsProcessor;
|
||||
53
node_modules/clean-css/lib/text/escape-store.js
generated
vendored
Normal file
53
node_modules/clean-css/lib/text/escape-store.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
var placeholderBrace = '__';
|
||||
|
||||
function EscapeStore(placeholderRoot) {
|
||||
this.placeholderRoot = 'ESCAPED_' + placeholderRoot + '_CLEAN_CSS';
|
||||
this.placeholderToData = {};
|
||||
this.dataToPlaceholder = {};
|
||||
this.count = 0;
|
||||
this.restoreMatcher = new RegExp(this.placeholderRoot + '(\\d+)');
|
||||
}
|
||||
|
||||
EscapeStore.prototype._nextPlaceholder = function (metadata) {
|
||||
return {
|
||||
index: this.count,
|
||||
value: placeholderBrace + this.placeholderRoot + this.count++ + metadata + placeholderBrace
|
||||
};
|
||||
};
|
||||
|
||||
EscapeStore.prototype.store = function (data, metadata) {
|
||||
var encodedMetadata = metadata ?
|
||||
'(' + metadata.join(',') + ')' :
|
||||
'';
|
||||
var placeholder = this.dataToPlaceholder[data];
|
||||
|
||||
if (!placeholder) {
|
||||
var nextPlaceholder = this._nextPlaceholder(encodedMetadata);
|
||||
placeholder = nextPlaceholder.value;
|
||||
this.placeholderToData[nextPlaceholder.index] = data;
|
||||
this.dataToPlaceholder[data] = nextPlaceholder.value;
|
||||
}
|
||||
|
||||
if (metadata)
|
||||
placeholder = placeholder.replace(/\([^\)]+\)/, encodedMetadata);
|
||||
|
||||
return placeholder;
|
||||
};
|
||||
|
||||
EscapeStore.prototype.nextMatch = function (data, cursor) {
|
||||
var next = {};
|
||||
|
||||
next.start = data.indexOf(this.placeholderRoot, cursor) - placeholderBrace.length;
|
||||
next.end = data.indexOf(placeholderBrace, next.start + placeholderBrace.length) + placeholderBrace.length;
|
||||
if (next.start > -1 && next.end > -1)
|
||||
next.match = data.substring(next.start, next.end);
|
||||
|
||||
return next;
|
||||
};
|
||||
|
||||
EscapeStore.prototype.restore = function (placeholder) {
|
||||
var index = this.restoreMatcher.exec(placeholder)[1];
|
||||
return this.placeholderToData[index];
|
||||
};
|
||||
|
||||
module.exports = EscapeStore;
|
||||
117
node_modules/clean-css/lib/text/expressions-processor.js
generated
vendored
Normal file
117
node_modules/clean-css/lib/text/expressions-processor.js
generated
vendored
Normal file
@@ -0,0 +1,117 @@
|
||||
var EscapeStore = require('./escape-store');
|
||||
|
||||
var EXPRESSION_NAME = 'expression';
|
||||
var EXPRESSION_START = '(';
|
||||
var EXPRESSION_END = ')';
|
||||
var EXPRESSION_PREFIX = EXPRESSION_NAME + EXPRESSION_START;
|
||||
var BODY_START = '{';
|
||||
var BODY_END = '}';
|
||||
|
||||
var lineBreak = require('os').EOL;
|
||||
|
||||
function findEnd(data, start) {
|
||||
var end = start + EXPRESSION_NAME.length;
|
||||
var level = 0;
|
||||
var quoted = false;
|
||||
var braced = false;
|
||||
|
||||
while (true) {
|
||||
var current = data[end++];
|
||||
|
||||
if (quoted) {
|
||||
quoted = current != '\'' && current != '"';
|
||||
} else {
|
||||
quoted = current == '\'' || current == '"';
|
||||
|
||||
if (current == EXPRESSION_START)
|
||||
level++;
|
||||
if (current == EXPRESSION_END)
|
||||
level--;
|
||||
if (current == BODY_START)
|
||||
braced = true;
|
||||
if (current == BODY_END && !braced && level == 1) {
|
||||
end--;
|
||||
level--;
|
||||
}
|
||||
}
|
||||
|
||||
if (level === 0 && current == EXPRESSION_END)
|
||||
break;
|
||||
if (!current) {
|
||||
end = data.substring(0, end).lastIndexOf(BODY_END);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return end;
|
||||
}
|
||||
|
||||
function ExpressionsProcessor(saveWaypoints) {
|
||||
this.expressions = new EscapeStore('EXPRESSION');
|
||||
this.saveWaypoints = saveWaypoints;
|
||||
}
|
||||
|
||||
ExpressionsProcessor.prototype.escape = function (data) {
|
||||
var nextStart = 0;
|
||||
var nextEnd = 0;
|
||||
var cursor = 0;
|
||||
var tempData = [];
|
||||
var indent = 0;
|
||||
var breaksCount;
|
||||
var lastBreakAt;
|
||||
var newIndent;
|
||||
var saveWaypoints = this.saveWaypoints;
|
||||
|
||||
for (; nextEnd < data.length;) {
|
||||
nextStart = data.indexOf(EXPRESSION_PREFIX, nextEnd);
|
||||
if (nextStart == -1)
|
||||
break;
|
||||
|
||||
nextEnd = findEnd(data, nextStart);
|
||||
|
||||
var expression = data.substring(nextStart, nextEnd);
|
||||
if (saveWaypoints) {
|
||||
breaksCount = expression.split(lineBreak).length - 1;
|
||||
lastBreakAt = expression.lastIndexOf(lineBreak);
|
||||
newIndent = lastBreakAt > 0 ?
|
||||
expression.substring(lastBreakAt + lineBreak.length).length :
|
||||
indent + expression.length;
|
||||
}
|
||||
|
||||
var metadata = saveWaypoints ? [breaksCount, newIndent] : null;
|
||||
var placeholder = this.expressions.store(expression, metadata);
|
||||
tempData.push(data.substring(cursor, nextStart));
|
||||
tempData.push(placeholder);
|
||||
|
||||
if (saveWaypoints)
|
||||
indent = newIndent + 1;
|
||||
cursor = nextEnd;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
};
|
||||
|
||||
ExpressionsProcessor.prototype.restore = function (data) {
|
||||
var tempData = [];
|
||||
var cursor = 0;
|
||||
|
||||
for (; cursor < data.length;) {
|
||||
var nextMatch = this.expressions.nextMatch(data, cursor);
|
||||
if (nextMatch.start < 0)
|
||||
break;
|
||||
|
||||
tempData.push(data.substring(cursor, nextMatch.start));
|
||||
var comment = this.expressions.restore(nextMatch.match);
|
||||
tempData.push(comment);
|
||||
|
||||
cursor = nextMatch.end;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
};
|
||||
|
||||
module.exports = ExpressionsProcessor;
|
||||
98
node_modules/clean-css/lib/text/free-text-processor.js
generated
vendored
Normal file
98
node_modules/clean-css/lib/text/free-text-processor.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
var EscapeStore = require('./escape-store');
|
||||
var QuoteScanner = require('../utils/quote-scanner');
|
||||
|
||||
var lineBreak = require('os').EOL;
|
||||
|
||||
function FreeTextProcessor(saveWaypoints) {
|
||||
this.matches = new EscapeStore('FREE_TEXT');
|
||||
this.saveWaypoints = saveWaypoints;
|
||||
}
|
||||
|
||||
// Strip content tags by replacing them by the a special
|
||||
// marker for further restoring. It's done via string scanning
|
||||
// instead of regexps to speed up the process.
|
||||
FreeTextProcessor.prototype.escape = function (data) {
|
||||
var self = this;
|
||||
var breaksCount;
|
||||
var lastBreakAt;
|
||||
var indent;
|
||||
var metadata;
|
||||
var saveWaypoints = this.saveWaypoints;
|
||||
|
||||
return new QuoteScanner(data).each(function (match, store) {
|
||||
if (saveWaypoints) {
|
||||
breaksCount = match.split(lineBreak).length - 1;
|
||||
lastBreakAt = match.lastIndexOf(lineBreak);
|
||||
indent = lastBreakAt > 0 ?
|
||||
match.substring(lastBreakAt + lineBreak.length).length :
|
||||
match.length;
|
||||
metadata = [breaksCount, indent];
|
||||
}
|
||||
|
||||
var placeholder = self.matches.store(match, metadata);
|
||||
store.push(placeholder);
|
||||
});
|
||||
};
|
||||
|
||||
function normalize(text, data, prefixContext, cursor) {
|
||||
// FIXME: this is even a bigger hack now - see #407
|
||||
var searchIn = data;
|
||||
if (prefixContext) {
|
||||
searchIn = prefixContext + data.substring(0, data.indexOf('__ESCAPED_FREE_TEXT_CLEAN_CSS'));
|
||||
cursor = searchIn.length;
|
||||
}
|
||||
|
||||
var lastSemicolon = searchIn.lastIndexOf(';', cursor);
|
||||
var lastOpenBrace = searchIn.lastIndexOf('{', cursor);
|
||||
var lastOne = 0;
|
||||
|
||||
if (lastSemicolon > -1 && lastOpenBrace > -1)
|
||||
lastOne = Math.max(lastSemicolon, lastOpenBrace);
|
||||
else if (lastSemicolon == -1)
|
||||
lastOne = lastOpenBrace;
|
||||
else
|
||||
lastOne = lastSemicolon;
|
||||
|
||||
var context = searchIn.substring(lastOne + 1, cursor);
|
||||
|
||||
if (/\[[\w\d\-]+[\*\|\~\^\$]?=$/.test(context)) {
|
||||
text = text
|
||||
.replace(/\\\n|\\\r\n/g, '')
|
||||
.replace(/\n|\r\n/g, '');
|
||||
}
|
||||
|
||||
if (/^['"][a-zA-Z][a-zA-Z\d\-_]+['"]$/.test(text) && !/format\($/.test(context)) {
|
||||
var isFont = /^(font|font\-family):/.test(context);
|
||||
var isAttribute = /\[[\w\d\-]+[\*\|\~\^\$]?=$/.test(context);
|
||||
var isKeyframe = /@(-moz-|-o-|-webkit-)?keyframes /.test(context);
|
||||
var isAnimation = /^(-moz-|-o-|-webkit-)?animation(-name)?:/.test(context);
|
||||
|
||||
if (isFont || isAttribute || isKeyframe || isAnimation)
|
||||
text = text.substring(1, text.length - 1);
|
||||
}
|
||||
|
||||
return text;
|
||||
}
|
||||
|
||||
FreeTextProcessor.prototype.restore = function (data, prefixContext) {
|
||||
var tempData = [];
|
||||
var cursor = 0;
|
||||
|
||||
for (; cursor < data.length;) {
|
||||
var nextMatch = this.matches.nextMatch(data, cursor);
|
||||
if (nextMatch.start < 0)
|
||||
break;
|
||||
|
||||
tempData.push(data.substring(cursor, nextMatch.start));
|
||||
var text = normalize(this.matches.restore(nextMatch.match), data, prefixContext, nextMatch.start);
|
||||
tempData.push(text);
|
||||
|
||||
cursor = nextMatch.end;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
};
|
||||
|
||||
module.exports = FreeTextProcessor;
|
||||
75
node_modules/clean-css/lib/text/urls-processor.js
generated
vendored
Normal file
75
node_modules/clean-css/lib/text/urls-processor.js
generated
vendored
Normal file
@@ -0,0 +1,75 @@
|
||||
var EscapeStore = require('./escape-store');
|
||||
var reduceUrls = require('../urls/reduce');
|
||||
|
||||
var lineBreak = require('os').EOL;
|
||||
|
||||
function UrlsProcessor(context, saveWaypoints, keepUrlQuotes) {
|
||||
this.urls = new EscapeStore('URL');
|
||||
this.context = context;
|
||||
this.saveWaypoints = saveWaypoints;
|
||||
this.keepUrlQuotes = keepUrlQuotes;
|
||||
}
|
||||
|
||||
// Strip urls by replacing them by a special
|
||||
// marker for further restoring. It's done via string scanning
|
||||
// instead of regexps to speed up the process.
|
||||
UrlsProcessor.prototype.escape = function (data) {
|
||||
var breaksCount;
|
||||
var lastBreakAt;
|
||||
var indent;
|
||||
var saveWaypoints = this.saveWaypoints;
|
||||
var self = this;
|
||||
|
||||
return reduceUrls(data, this.context, function (url, tempData) {
|
||||
if (saveWaypoints) {
|
||||
breaksCount = url.split(lineBreak).length - 1;
|
||||
lastBreakAt = url.lastIndexOf(lineBreak);
|
||||
indent = lastBreakAt > 0 ?
|
||||
url.substring(lastBreakAt + lineBreak.length).length :
|
||||
url.length;
|
||||
}
|
||||
|
||||
var placeholder = self.urls.store(url, saveWaypoints ? [breaksCount, indent] : null);
|
||||
tempData.push(placeholder);
|
||||
});
|
||||
};
|
||||
|
||||
function normalize(url, keepUrlQuotes) {
|
||||
url = url
|
||||
.replace(/^url/gi, 'url')
|
||||
.replace(/\\?\n|\\?\r\n/g, '')
|
||||
.replace(/(\s{2,}|\s)/g, ' ')
|
||||
.replace(/^url\((['"])? /, 'url($1')
|
||||
.replace(/ (['"])?\)$/, '$1)');
|
||||
|
||||
if (/url\(".*'.*"\)/.test(url) || /url\('.*".*'\)/.test(url))
|
||||
return url;
|
||||
|
||||
if (!keepUrlQuotes && !/^['"].+['"]$/.test(url) && !/url\(.*[\s\(\)].*\)/.test(url) && !/url\(['"]data:[^;]+;charset/.test(url))
|
||||
url = url.replace(/["']/g, '');
|
||||
|
||||
return url;
|
||||
}
|
||||
|
||||
UrlsProcessor.prototype.restore = function (data) {
|
||||
var tempData = [];
|
||||
var cursor = 0;
|
||||
|
||||
for (; cursor < data.length;) {
|
||||
var nextMatch = this.urls.nextMatch(data, cursor);
|
||||
if (nextMatch.start < 0)
|
||||
break;
|
||||
|
||||
tempData.push(data.substring(cursor, nextMatch.start));
|
||||
var url = normalize(this.urls.restore(nextMatch.match), this.keepUrlQuotes);
|
||||
tempData.push(url);
|
||||
|
||||
cursor = nextMatch.end;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
};
|
||||
|
||||
module.exports = UrlsProcessor;
|
||||
Reference in New Issue
Block a user