clear
This commit is contained in:
167
node_modules/clean-css/lib/stringifier/helpers.js
generated
vendored
Normal file
167
node_modules/clean-css/lib/stringifier/helpers.js
generated
vendored
Normal file
@@ -0,0 +1,167 @@
|
||||
var lineBreak = require('os').EOL;
|
||||
|
||||
var AT_RULE = 'at-rule';
|
||||
var PROPERTY_SEPARATOR = ';';
|
||||
|
||||
function hasMoreProperties(tokens, index) {
|
||||
for (var i = index, l = tokens.length; i < l; i++) {
|
||||
if (typeof tokens[i] != 'string')
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function supportsAfterClosingBrace(token) {
|
||||
return token[0][0] == 'background' || token[0][0] == 'transform' || token[0][0] == 'src';
|
||||
}
|
||||
|
||||
function afterClosingBrace(token, valueIndex) {
|
||||
return token[valueIndex][0][token[valueIndex][0].length - 1] == ')' || token[valueIndex][0].indexOf('__ESCAPED_URL_CLEAN_CSS') === 0;
|
||||
}
|
||||
|
||||
function afterComma(token, valueIndex) {
|
||||
return token[valueIndex][0] == ',';
|
||||
}
|
||||
|
||||
function afterSlash(token, valueIndex) {
|
||||
return token[valueIndex][0] == '/';
|
||||
}
|
||||
|
||||
function beforeComma(token, valueIndex) {
|
||||
return token[valueIndex + 1] && token[valueIndex + 1][0] == ',';
|
||||
}
|
||||
|
||||
function beforeSlash(token, valueIndex) {
|
||||
return token[valueIndex + 1] && token[valueIndex + 1][0] == '/';
|
||||
}
|
||||
|
||||
function inFilter(token) {
|
||||
return token[0][0] == 'filter' || token[0][0] == '-ms-filter';
|
||||
}
|
||||
|
||||
function inSpecialContext(token, valueIndex, context) {
|
||||
return !context.spaceAfterClosingBrace && supportsAfterClosingBrace(token) && afterClosingBrace(token, valueIndex) ||
|
||||
beforeSlash(token, valueIndex) ||
|
||||
afterSlash(token, valueIndex) ||
|
||||
beforeComma(token, valueIndex) ||
|
||||
afterComma(token, valueIndex);
|
||||
}
|
||||
|
||||
function selectors(tokens, context) {
|
||||
var store = context.store;
|
||||
|
||||
for (var i = 0, l = tokens.length; i < l; i++) {
|
||||
store(tokens[i], context);
|
||||
|
||||
if (i < l - 1)
|
||||
store(',', context);
|
||||
}
|
||||
}
|
||||
|
||||
function body(tokens, context) {
|
||||
for (var i = 0, l = tokens.length; i < l; i++) {
|
||||
property(tokens, i, i == l - 1, context);
|
||||
}
|
||||
}
|
||||
|
||||
function property(tokens, position, isLast, context) {
|
||||
var store = context.store;
|
||||
var token = tokens[position];
|
||||
|
||||
if (typeof token == 'string') {
|
||||
store(token, context);
|
||||
} else if (token[0] == AT_RULE) {
|
||||
propertyAtRule(token[1], isLast, context);
|
||||
} else {
|
||||
store(token[0], context);
|
||||
store(':', context);
|
||||
value(tokens, position, isLast, context);
|
||||
}
|
||||
}
|
||||
|
||||
function propertyAtRule(value, isLast, context) {
|
||||
var store = context.store;
|
||||
|
||||
store(value, context);
|
||||
if (!isLast)
|
||||
store(PROPERTY_SEPARATOR, context);
|
||||
}
|
||||
|
||||
function value(tokens, position, isLast, context) {
|
||||
var store = context.store;
|
||||
var token = tokens[position];
|
||||
var isVariableDeclaration = token[0][0].indexOf('--') === 0;
|
||||
var isBlockVariable = isVariableDeclaration && Array.isArray(token[1][0]);
|
||||
|
||||
if (isVariableDeclaration && isBlockVariable && atRulesOrProperties(token[1])) {
|
||||
store('{', context);
|
||||
body(token[1], context);
|
||||
store('};', context);
|
||||
return;
|
||||
}
|
||||
|
||||
for (var j = 1, m = token.length; j < m; j++) {
|
||||
store(token[j], context);
|
||||
|
||||
if (j < m - 1 && (inFilter(token) || !inSpecialContext(token, j, context))) {
|
||||
store(' ', context);
|
||||
} else if (j == m - 1 && !isLast && hasMoreProperties(tokens, position + 1)) {
|
||||
store(PROPERTY_SEPARATOR, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function atRulesOrProperties(values) {
|
||||
for (var i = 0, l = values.length; i < l; i++) {
|
||||
if (values[i][0] == AT_RULE || Array.isArray(values[i][0]))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function all(tokens, context) {
|
||||
var joinCharacter = context.keepBreaks ? lineBreak : '';
|
||||
var store = context.store;
|
||||
|
||||
for (var i = 0, l = tokens.length; i < l; i++) {
|
||||
var token = tokens[i];
|
||||
|
||||
switch (token[0]) {
|
||||
case 'at-rule':
|
||||
case 'text':
|
||||
store(token[1][0], context);
|
||||
store(joinCharacter, context);
|
||||
break;
|
||||
case 'block':
|
||||
selectors([token[1]], context);
|
||||
store('{', context);
|
||||
all(token[2], context);
|
||||
store('}', context);
|
||||
store(joinCharacter, context);
|
||||
break;
|
||||
case 'flat-block':
|
||||
selectors([token[1]], context);
|
||||
store('{', context);
|
||||
body(token[2], context);
|
||||
store('}', context);
|
||||
store(joinCharacter, context);
|
||||
break;
|
||||
default:
|
||||
selectors(token[1], context);
|
||||
store('{', context);
|
||||
body(token[2], context);
|
||||
store('}', context);
|
||||
store(joinCharacter, context);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
all: all,
|
||||
body: body,
|
||||
property: property,
|
||||
selectors: selectors,
|
||||
value: value
|
||||
};
|
||||
50
node_modules/clean-css/lib/stringifier/one-time.js
generated
vendored
Normal file
50
node_modules/clean-css/lib/stringifier/one-time.js
generated
vendored
Normal file
@@ -0,0 +1,50 @@
|
||||
var helpers = require('./helpers');
|
||||
|
||||
function store(token, context) {
|
||||
context.output.push(typeof token == 'string' ? token : token[0]);
|
||||
}
|
||||
|
||||
function context() {
|
||||
return {
|
||||
output: [],
|
||||
store: store
|
||||
};
|
||||
}
|
||||
|
||||
function all(tokens) {
|
||||
var fakeContext = context();
|
||||
helpers.all(tokens, fakeContext);
|
||||
return fakeContext.output.join('');
|
||||
}
|
||||
|
||||
function body(tokens) {
|
||||
var fakeContext = context();
|
||||
helpers.body(tokens, fakeContext);
|
||||
return fakeContext.output.join('');
|
||||
}
|
||||
|
||||
function property(tokens, position) {
|
||||
var fakeContext = context();
|
||||
helpers.property(tokens, position, true, fakeContext);
|
||||
return fakeContext.output.join('');
|
||||
}
|
||||
|
||||
function selectors(tokens) {
|
||||
var fakeContext = context();
|
||||
helpers.selectors(tokens, fakeContext);
|
||||
return fakeContext.output.join('');
|
||||
}
|
||||
|
||||
function value(tokens, position) {
|
||||
var fakeContext = context();
|
||||
helpers.value(tokens, position, true, fakeContext);
|
||||
return fakeContext.output.join('');
|
||||
}
|
||||
|
||||
module.exports = {
|
||||
all: all,
|
||||
body: body,
|
||||
property: property,
|
||||
selectors: selectors,
|
||||
value: value
|
||||
};
|
||||
22
node_modules/clean-css/lib/stringifier/simple.js
generated
vendored
Normal file
22
node_modules/clean-css/lib/stringifier/simple.js
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
var all = require('./helpers').all;
|
||||
|
||||
function store(token, context) {
|
||||
context.output.push(typeof token == 'string' ? token : token[0]);
|
||||
}
|
||||
|
||||
function stringify(tokens, options, restoreCallback) {
|
||||
var context = {
|
||||
keepBreaks: options.keepBreaks,
|
||||
output: [],
|
||||
spaceAfterClosingBrace: options.compatibility.properties.spaceAfterClosingBrace,
|
||||
store: store
|
||||
};
|
||||
|
||||
all(tokens, context, false);
|
||||
|
||||
return {
|
||||
styles: restoreCallback(context.output.join('')).trim()
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = stringify;
|
||||
96
node_modules/clean-css/lib/stringifier/source-maps.js
generated
vendored
Normal file
96
node_modules/clean-css/lib/stringifier/source-maps.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
var SourceMapGenerator = require('source-map').SourceMapGenerator;
|
||||
var all = require('./helpers').all;
|
||||
|
||||
var isWindows = process.platform == 'win32';
|
||||
var unknownSource = '$stdin';
|
||||
|
||||
function store(element, context) {
|
||||
var fromString = typeof element == 'string';
|
||||
var value = fromString ? element : element[0];
|
||||
|
||||
if (value.indexOf('_') > -1)
|
||||
value = context.restore(value, prefixContentFrom(context.output));
|
||||
|
||||
track(value, fromString ? null : element, context);
|
||||
context.output.push(value);
|
||||
}
|
||||
|
||||
function prefixContentFrom(values) {
|
||||
var content = [];
|
||||
|
||||
for (var i = values.length - 1; i >= 0; i--) {
|
||||
var value = values[i];
|
||||
content.unshift(value);
|
||||
|
||||
if (value == '{' || value == ';')
|
||||
break;
|
||||
}
|
||||
|
||||
return content.join('');
|
||||
}
|
||||
|
||||
function track(value, element, context) {
|
||||
if (element)
|
||||
trackAllMappings(element, context);
|
||||
|
||||
var parts = value.split('\n');
|
||||
context.line += parts.length - 1;
|
||||
context.column = parts.length > 1 ? 0 : (context.column + parts.pop().length);
|
||||
}
|
||||
|
||||
function trackAllMappings(element, context) {
|
||||
var mapping = element[element.length - 1];
|
||||
|
||||
if (!Array.isArray(mapping))
|
||||
return;
|
||||
|
||||
for (var i = 0, l = mapping.length; i < l; i++) {
|
||||
trackMapping(mapping[i], context);
|
||||
}
|
||||
}
|
||||
|
||||
function trackMapping(mapping, context) {
|
||||
var source = mapping[2] || unknownSource;
|
||||
|
||||
if (isWindows)
|
||||
source = source.replace(/\\/g, '/');
|
||||
|
||||
context.outputMap.addMapping({
|
||||
generated: {
|
||||
line: context.line,
|
||||
column: context.column
|
||||
},
|
||||
source: source,
|
||||
original: {
|
||||
line: mapping[0],
|
||||
column: mapping[1]
|
||||
}
|
||||
});
|
||||
|
||||
if (mapping[3])
|
||||
context.outputMap.setSourceContent(source, mapping[3][mapping[2]]);
|
||||
}
|
||||
|
||||
function stringify(tokens, options, restoreCallback, inputMapTracker) {
|
||||
var context = {
|
||||
column: 0,
|
||||
inputMapTracker: inputMapTracker,
|
||||
keepBreaks: options.keepBreaks,
|
||||
line: 1,
|
||||
output: [],
|
||||
outputMap: new SourceMapGenerator(),
|
||||
restore: restoreCallback,
|
||||
sourceMapInlineSources: options.sourceMapInlineSources,
|
||||
spaceAfterClosingBrace: options.compatibility.properties.spaceAfterClosingBrace,
|
||||
store: store
|
||||
};
|
||||
|
||||
all(tokens, context, false);
|
||||
|
||||
return {
|
||||
sourceMap: context.outputMap,
|
||||
styles: context.output.join('').trim()
|
||||
};
|
||||
}
|
||||
|
||||
module.exports = stringify;
|
||||
Reference in New Issue
Block a user