clear
This commit is contained in:
12
node_modules/clean-css/lib/utils/clone-array.js
generated
vendored
Normal file
12
node_modules/clean-css/lib/utils/clone-array.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
function cloneArray(array) {
|
||||
var cloned = array.slice(0);
|
||||
|
||||
for (var i = 0, l = cloned.length; i < l; i++) {
|
||||
if (Array.isArray(cloned[i]))
|
||||
cloned[i] = cloneArray(cloned[i]);
|
||||
}
|
||||
|
||||
return cloned;
|
||||
}
|
||||
|
||||
module.exports = cloneArray;
|
||||
162
node_modules/clean-css/lib/utils/compatibility.js
generated
vendored
Normal file
162
node_modules/clean-css/lib/utils/compatibility.js
generated
vendored
Normal file
@@ -0,0 +1,162 @@
|
||||
var util = require('util');
|
||||
|
||||
var DEFAULTS = {
|
||||
'*': {
|
||||
colors: {
|
||||
opacity: true // rgba / hsla
|
||||
},
|
||||
properties: {
|
||||
backgroundClipMerging: false, // background-clip to shorthand
|
||||
backgroundOriginMerging: false, // background-origin to shorthand
|
||||
backgroundSizeMerging: false, // background-size to shorthand
|
||||
colors: true, // any kind of color transformations, like `#ff00ff` to `#f0f` or `#fff` into `red`
|
||||
ieBangHack: false, // !ie suffix hacks on IE<8
|
||||
iePrefixHack: false, // underscore / asterisk prefix hacks on IE
|
||||
ieSuffixHack: true, // \9 suffix hacks on IE6-9
|
||||
merging: true, // merging properties into one
|
||||
shorterLengthUnits: false, // optimize pixel units into `pt`, `pc` or `in` units
|
||||
spaceAfterClosingBrace: true, // 'url() no-repeat' to 'url()no-repeat'
|
||||
urlQuotes: false, // whether to wrap content of `url()` into quotes or not
|
||||
zeroUnits: true // 0[unit] -> 0
|
||||
},
|
||||
selectors: {
|
||||
adjacentSpace: false, // div+ nav Android stock browser hack
|
||||
ie7Hack: false, // *+html hack
|
||||
special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:dir\([a-z-]*\)|:first(?![a-z-])|:fullscreen|:left|:read-only|:read-write|:right|:placeholder|:host|:content|\/deep\/|:shadow|:selection|^,)/ // special selectors which prevent merging
|
||||
},
|
||||
units: {
|
||||
ch: true,
|
||||
in: true,
|
||||
pc: true,
|
||||
pt: true,
|
||||
rem: true,
|
||||
vh: true,
|
||||
vm: true, // vm is vmin on IE9+ see https://developer.mozilla.org/en-US/docs/Web/CSS/length
|
||||
vmax: true,
|
||||
vmin: true,
|
||||
vw: true
|
||||
}
|
||||
},
|
||||
'ie8': {
|
||||
colors: {
|
||||
opacity: false
|
||||
},
|
||||
properties: {
|
||||
backgroundClipMerging: false,
|
||||
backgroundOriginMerging: false,
|
||||
backgroundSizeMerging: false,
|
||||
colors: true,
|
||||
ieBangHack: false,
|
||||
iePrefixHack: true,
|
||||
ieSuffixHack: true,
|
||||
merging: false,
|
||||
shorterLengthUnits: false,
|
||||
spaceAfterClosingBrace: true,
|
||||
urlQuotes: false,
|
||||
zeroUnits: true
|
||||
},
|
||||
selectors: {
|
||||
adjacentSpace: false,
|
||||
ie7Hack: false,
|
||||
special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not|:placeholder|:host|::content|\/deep\/|::shadow|^,)/
|
||||
},
|
||||
units: {
|
||||
ch: false,
|
||||
in: true,
|
||||
pc: true,
|
||||
pt: true,
|
||||
rem: false,
|
||||
vh: false,
|
||||
vm: false,
|
||||
vmax: false,
|
||||
vmin: false,
|
||||
vw: false
|
||||
}
|
||||
},
|
||||
'ie7': {
|
||||
colors: {
|
||||
opacity: false
|
||||
},
|
||||
properties: {
|
||||
backgroundClipMerging: false,
|
||||
backgroundOriginMerging: false,
|
||||
backgroundSizeMerging: false,
|
||||
colors: true,
|
||||
ieBangHack: true,
|
||||
iePrefixHack: true,
|
||||
ieSuffixHack: true,
|
||||
merging: false,
|
||||
shorterLengthUnits: false,
|
||||
spaceAfterClosingBrace: true,
|
||||
urlQuotes: false,
|
||||
zeroUnits: true
|
||||
},
|
||||
selectors: {
|
||||
adjacentSpace: false,
|
||||
ie7Hack: true,
|
||||
special: /(\-moz\-|\-ms\-|\-o\-|\-webkit\-|:focus|:before|:after|:root|:nth|:first\-of|:last|:only|:empty|:target|:checked|::selection|:enabled|:disabled|:not|:placeholder|:host|::content|\/deep\/|::shadow|^,)/
|
||||
},
|
||||
units: {
|
||||
ch: false,
|
||||
in: true,
|
||||
pc: true,
|
||||
pt: true,
|
||||
rem: false,
|
||||
vh: false,
|
||||
vm: false,
|
||||
vmax: false,
|
||||
vmin: false,
|
||||
vw: false,
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
function Compatibility(source) {
|
||||
this.source = source || {};
|
||||
}
|
||||
|
||||
function merge(source, target) {
|
||||
for (var key in source) {
|
||||
var value = source[key];
|
||||
|
||||
if (typeof value === 'object' && !util.isRegExp(value))
|
||||
target[key] = merge(value, target[key] || {});
|
||||
else
|
||||
target[key] = key in target ? target[key] : value;
|
||||
}
|
||||
|
||||
return target;
|
||||
}
|
||||
|
||||
function calculateSource(source) {
|
||||
if (typeof source == 'object')
|
||||
return source;
|
||||
|
||||
if (!/[,\+\-]/.test(source))
|
||||
return DEFAULTS[source] || DEFAULTS['*'];
|
||||
|
||||
var parts = source.split(',');
|
||||
var template = parts[0] in DEFAULTS ?
|
||||
DEFAULTS[parts.shift()] :
|
||||
DEFAULTS['*'];
|
||||
|
||||
source = {};
|
||||
|
||||
parts.forEach(function (part) {
|
||||
var isAdd = part[0] == '+';
|
||||
var key = part.substring(1).split('.');
|
||||
var group = key[0];
|
||||
var option = key[1];
|
||||
|
||||
source[group] = source[group] || {};
|
||||
source[group][option] = isAdd;
|
||||
});
|
||||
|
||||
return merge(template, source);
|
||||
}
|
||||
|
||||
Compatibility.prototype.toOptions = function () {
|
||||
return merge(DEFAULTS['*'], calculateSource(this.source));
|
||||
};
|
||||
|
||||
module.exports = Compatibility;
|
||||
284
node_modules/clean-css/lib/utils/input-source-map-tracker.js
generated
vendored
Normal file
284
node_modules/clean-css/lib/utils/input-source-map-tracker.js
generated
vendored
Normal file
@@ -0,0 +1,284 @@
|
||||
var SourceMapConsumer = require('source-map').SourceMapConsumer;
|
||||
|
||||
var fs = require('fs');
|
||||
var path = require('path');
|
||||
var http = require('http');
|
||||
var https = require('https');
|
||||
var url = require('url');
|
||||
|
||||
var override = require('../utils/object.js').override;
|
||||
|
||||
var MAP_MARKER = /\/\*# sourceMappingURL=(\S+) \*\//;
|
||||
var REMOTE_RESOURCE = /^(https?:)?\/\//;
|
||||
var DATA_URI = /^data:(\S*?)?(;charset=[^;]+)?(;[^,]+?)?,(.+)/;
|
||||
|
||||
var unescape = global.unescape;
|
||||
|
||||
function InputSourceMapStore(outerContext) {
|
||||
this.options = outerContext.options;
|
||||
this.errors = outerContext.errors;
|
||||
this.warnings = outerContext.warnings;
|
||||
this.sourceTracker = outerContext.sourceTracker;
|
||||
this.timeout = this.options.inliner.timeout;
|
||||
this.requestOptions = this.options.inliner.request;
|
||||
this.localOnly = outerContext.localOnly;
|
||||
this.relativeTo = outerContext.options.target || process.cwd();
|
||||
|
||||
this.maps = {};
|
||||
this.sourcesContent = {};
|
||||
}
|
||||
|
||||
function fromString(self, _, whenDone) {
|
||||
self.trackLoaded(undefined, undefined, self.options.sourceMap);
|
||||
return whenDone();
|
||||
}
|
||||
|
||||
function fromSource(self, data, whenDone, context) {
|
||||
var nextAt = 0;
|
||||
|
||||
function proceedToNext() {
|
||||
context.cursor += nextAt + 1;
|
||||
fromSource(self, data, whenDone, context);
|
||||
}
|
||||
|
||||
while (context.cursor < data.length) {
|
||||
var fragment = data.substring(context.cursor);
|
||||
|
||||
var markerStartMatch = self.sourceTracker.nextStart(fragment) || { index: -1 };
|
||||
var markerEndMatch = self.sourceTracker.nextEnd(fragment) || { index: -1 };
|
||||
var mapMatch = MAP_MARKER.exec(fragment) || { index: -1 };
|
||||
var sourceMapFile = mapMatch[1];
|
||||
|
||||
nextAt = data.length;
|
||||
if (markerStartMatch.index > -1)
|
||||
nextAt = markerStartMatch.index;
|
||||
if (markerEndMatch.index > -1 && markerEndMatch.index < nextAt)
|
||||
nextAt = markerEndMatch.index;
|
||||
if (mapMatch.index > -1 && mapMatch.index < nextAt)
|
||||
nextAt = mapMatch.index;
|
||||
|
||||
if (nextAt == data.length)
|
||||
break;
|
||||
|
||||
if (nextAt == markerStartMatch.index) {
|
||||
context.files.push(markerStartMatch.filename);
|
||||
} else if (nextAt == markerEndMatch.index) {
|
||||
context.files.pop();
|
||||
} else if (nextAt == mapMatch.index) {
|
||||
var isRemote = /^https?:\/\//.test(sourceMapFile) || /^\/\//.test(sourceMapFile);
|
||||
var isDataUri = DATA_URI.test(sourceMapFile);
|
||||
|
||||
if (isRemote) {
|
||||
return fetchMapFile(self, sourceMapFile, context, proceedToNext);
|
||||
} else {
|
||||
var sourceFile = context.files[context.files.length - 1];
|
||||
var sourceMapPath, sourceMapData;
|
||||
var sourceDir = sourceFile ? path.dirname(sourceFile) : self.options.relativeTo;
|
||||
|
||||
if (isDataUri) {
|
||||
// source map's path is the same as the source file it comes from
|
||||
sourceMapPath = path.resolve(self.options.root, sourceFile || '');
|
||||
sourceMapData = fromDataUri(sourceMapFile);
|
||||
} else {
|
||||
sourceMapPath = path.resolve(self.options.root, path.join(sourceDir || '', sourceMapFile));
|
||||
sourceMapData = fs.readFileSync(sourceMapPath, 'utf-8');
|
||||
}
|
||||
self.trackLoaded(sourceFile || undefined, sourceMapPath, sourceMapData);
|
||||
}
|
||||
}
|
||||
|
||||
context.cursor += nextAt + 1;
|
||||
}
|
||||
|
||||
return whenDone();
|
||||
}
|
||||
|
||||
function fromDataUri(uriString) {
|
||||
var match = DATA_URI.exec(uriString);
|
||||
var charset = match[2] ? match[2].split(/[=;]/)[2] : 'us-ascii';
|
||||
var encoding = match[3] ? match[3].split(';')[1] : 'utf8';
|
||||
var data = encoding == 'utf8' ? unescape(match[4]) : match[4];
|
||||
|
||||
var buffer = new Buffer(data, encoding);
|
||||
buffer.charset = charset;
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
function fetchMapFile(self, sourceUrl, context, done) {
|
||||
fetch(self, sourceUrl, function (data) {
|
||||
self.trackLoaded(context.files[context.files.length - 1] || undefined, sourceUrl, data);
|
||||
done();
|
||||
}, function (message) {
|
||||
context.errors.push('Broken source map at "' + sourceUrl + '" - ' + message);
|
||||
return done();
|
||||
});
|
||||
}
|
||||
|
||||
function fetch(self, path, onSuccess, onFailure) {
|
||||
var protocol = path.indexOf('https') === 0 ? https : http;
|
||||
var requestOptions = override(url.parse(path), self.requestOptions);
|
||||
var errorHandled = false;
|
||||
|
||||
protocol
|
||||
.get(requestOptions, function (res) {
|
||||
if (res.statusCode < 200 || res.statusCode > 299)
|
||||
return onFailure(res.statusCode);
|
||||
|
||||
var chunks = [];
|
||||
res.on('data', function (chunk) {
|
||||
chunks.push(chunk.toString());
|
||||
});
|
||||
res.on('end', function () {
|
||||
onSuccess(chunks.join(''));
|
||||
});
|
||||
})
|
||||
.on('error', function (res) {
|
||||
if (errorHandled)
|
||||
return;
|
||||
|
||||
onFailure(res.message);
|
||||
errorHandled = true;
|
||||
})
|
||||
.on('timeout', function () {
|
||||
if (errorHandled)
|
||||
return;
|
||||
|
||||
onFailure('timeout');
|
||||
errorHandled = true;
|
||||
})
|
||||
.setTimeout(self.timeout);
|
||||
}
|
||||
|
||||
function originalPositionIn(trackedSource, line, column, token, allowNFallbacks) {
|
||||
var originalPosition;
|
||||
var maxRange = token.length;
|
||||
var position = {
|
||||
line: line,
|
||||
column: column + maxRange
|
||||
};
|
||||
|
||||
while (maxRange-- > 0) {
|
||||
position.column--;
|
||||
originalPosition = trackedSource.data.originalPositionFor(position);
|
||||
|
||||
if (originalPosition)
|
||||
break;
|
||||
}
|
||||
|
||||
if (originalPosition.line === null && line > 1 && allowNFallbacks > 0)
|
||||
return originalPositionIn(trackedSource, line - 1, column, token, allowNFallbacks - 1);
|
||||
|
||||
if (trackedSource.path && originalPosition.source) {
|
||||
originalPosition.source = REMOTE_RESOURCE.test(trackedSource.path) ?
|
||||
url.resolve(trackedSource.path, originalPosition.source) :
|
||||
path.join(trackedSource.path, originalPosition.source);
|
||||
|
||||
originalPosition.sourceResolved = true;
|
||||
}
|
||||
|
||||
return originalPosition;
|
||||
}
|
||||
|
||||
function trackContentSources(self, sourceFile) {
|
||||
var consumer = self.maps[sourceFile].data;
|
||||
var isRemote = REMOTE_RESOURCE.test(sourceFile);
|
||||
var sourcesMapping = {};
|
||||
|
||||
consumer.sources.forEach(function (file, index) {
|
||||
var uniquePath = isRemote ?
|
||||
url.resolve(path.dirname(sourceFile), file) :
|
||||
path.relative(self.relativeTo, path.resolve(path.dirname(sourceFile || '.'), file));
|
||||
|
||||
sourcesMapping[uniquePath] = consumer.sourcesContent && consumer.sourcesContent[index];
|
||||
});
|
||||
self.sourcesContent[sourceFile] = sourcesMapping;
|
||||
}
|
||||
|
||||
function _resolveSources(self, remaining, whenDone) {
|
||||
function processNext() {
|
||||
return _resolveSources(self, remaining, whenDone);
|
||||
}
|
||||
|
||||
if (remaining.length === 0)
|
||||
return whenDone();
|
||||
|
||||
var current = remaining.shift();
|
||||
var sourceFile = current[0];
|
||||
var originalFile = current[1];
|
||||
var isRemote = REMOTE_RESOURCE.test(sourceFile);
|
||||
|
||||
if (isRemote && self.localOnly) {
|
||||
self.warnings.push('No callback given to `#minify` method, cannot fetch a remote file from "' + originalFile + '"');
|
||||
return processNext();
|
||||
}
|
||||
|
||||
if (isRemote) {
|
||||
fetch(self, originalFile, function (data) {
|
||||
self.sourcesContent[sourceFile][originalFile] = data;
|
||||
processNext();
|
||||
}, function (message) {
|
||||
self.warnings.push('Broken original source file at "' + originalFile + '" - ' + message);
|
||||
processNext();
|
||||
});
|
||||
} else {
|
||||
var fullPath = path.join(self.options.root, originalFile);
|
||||
if (fs.existsSync(fullPath))
|
||||
self.sourcesContent[sourceFile][originalFile] = fs.readFileSync(fullPath, 'utf-8');
|
||||
else
|
||||
self.warnings.push('Missing original source file at "' + fullPath + '".');
|
||||
return processNext();
|
||||
}
|
||||
}
|
||||
|
||||
InputSourceMapStore.prototype.track = function (data, whenDone) {
|
||||
return typeof this.options.sourceMap == 'string' ?
|
||||
fromString(this, data, whenDone) :
|
||||
fromSource(this, data, whenDone, { files: [], cursor: 0, errors: this.errors });
|
||||
};
|
||||
|
||||
InputSourceMapStore.prototype.trackLoaded = function (sourcePath, mapPath, mapData) {
|
||||
var relativeTo = this.options.explicitTarget ? this.options.target : this.options.root;
|
||||
var isRemote = REMOTE_RESOURCE.test(sourcePath);
|
||||
|
||||
if (mapPath) {
|
||||
mapPath = isRemote ?
|
||||
path.dirname(mapPath) :
|
||||
path.dirname(path.relative(relativeTo, mapPath));
|
||||
}
|
||||
|
||||
this.maps[sourcePath] = {
|
||||
path: mapPath,
|
||||
data: new SourceMapConsumer(mapData)
|
||||
};
|
||||
|
||||
trackContentSources(this, sourcePath);
|
||||
};
|
||||
|
||||
InputSourceMapStore.prototype.isTracking = function (source) {
|
||||
return !!this.maps[source];
|
||||
};
|
||||
|
||||
InputSourceMapStore.prototype.originalPositionFor = function (sourceInfo, token, allowNFallbacks) {
|
||||
return originalPositionIn(this.maps[sourceInfo.source], sourceInfo.line, sourceInfo.column, token, allowNFallbacks);
|
||||
};
|
||||
|
||||
InputSourceMapStore.prototype.sourcesContentFor = function (contextSource) {
|
||||
return this.sourcesContent[contextSource];
|
||||
};
|
||||
|
||||
InputSourceMapStore.prototype.resolveSources = function (whenDone) {
|
||||
var toResolve = [];
|
||||
|
||||
for (var sourceFile in this.sourcesContent) {
|
||||
var contents = this.sourcesContent[sourceFile];
|
||||
for (var originalFile in contents) {
|
||||
if (!contents[originalFile])
|
||||
toResolve.push([sourceFile, originalFile]);
|
||||
}
|
||||
}
|
||||
|
||||
return _resolveSources(this, toResolve, whenDone);
|
||||
};
|
||||
|
||||
module.exports = InputSourceMapStore;
|
||||
11
node_modules/clean-css/lib/utils/object.js
generated
vendored
Normal file
11
node_modules/clean-css/lib/utils/object.js
generated
vendored
Normal file
@@ -0,0 +1,11 @@
|
||||
module.exports = {
|
||||
override: function (source1, source2) {
|
||||
var target = {};
|
||||
for (var key1 in source1)
|
||||
target[key1] = source1[key1];
|
||||
for (var key2 in source2)
|
||||
target[key2] = source2[key2];
|
||||
|
||||
return target;
|
||||
}
|
||||
};
|
||||
119
node_modules/clean-css/lib/utils/quote-scanner.js
generated
vendored
Normal file
119
node_modules/clean-css/lib/utils/quote-scanner.js
generated
vendored
Normal file
@@ -0,0 +1,119 @@
|
||||
var COMMENT_START_MARK = '/*';
|
||||
|
||||
function QuoteScanner(data) {
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
var findQuoteEnd = function (data, matched, cursor, oldCursor) {
|
||||
var commentEndMark = '*/';
|
||||
var escapeMark = '\\';
|
||||
var blockEndMark = '}';
|
||||
var dataPrefix = data.substring(oldCursor, cursor);
|
||||
var commentEndedAt = dataPrefix.lastIndexOf(commentEndMark, cursor);
|
||||
var commentStartedAt = findLastCommentStartedAt(dataPrefix, cursor);
|
||||
var commentStarted = false;
|
||||
|
||||
if (commentEndedAt >= cursor && commentStartedAt > -1)
|
||||
commentStarted = true;
|
||||
if (commentStartedAt < cursor && commentStartedAt > commentEndedAt)
|
||||
commentStarted = true;
|
||||
|
||||
if (commentStarted) {
|
||||
var commentEndsAt = data.indexOf(commentEndMark, cursor);
|
||||
if (commentEndsAt > -1)
|
||||
return commentEndsAt;
|
||||
|
||||
commentEndsAt = data.indexOf(blockEndMark, cursor);
|
||||
return commentEndsAt > -1 ? commentEndsAt - 1 : data.length;
|
||||
}
|
||||
|
||||
while (true) {
|
||||
if (data[cursor] === undefined)
|
||||
break;
|
||||
if (data[cursor] == matched && (data[cursor - 1] != escapeMark || data[cursor - 2] == escapeMark))
|
||||
break;
|
||||
|
||||
cursor++;
|
||||
}
|
||||
|
||||
return cursor;
|
||||
};
|
||||
|
||||
function findLastCommentStartedAt(data, cursor) {
|
||||
var position = cursor;
|
||||
|
||||
while (position > -1) {
|
||||
position = data.lastIndexOf(COMMENT_START_MARK, position);
|
||||
|
||||
if (position > -1 && data[position - 1] != '*') {
|
||||
break;
|
||||
} else {
|
||||
position--;
|
||||
}
|
||||
}
|
||||
|
||||
return position;
|
||||
}
|
||||
|
||||
function findNext(data, mark, startAt) {
|
||||
var escapeMark = '\\';
|
||||
var candidate = startAt;
|
||||
|
||||
while (true) {
|
||||
candidate = data.indexOf(mark, candidate + 1);
|
||||
if (candidate == -1)
|
||||
return -1;
|
||||
if (data[candidate - 1] != escapeMark)
|
||||
return candidate;
|
||||
}
|
||||
}
|
||||
|
||||
QuoteScanner.prototype.each = function (callback) {
|
||||
var data = this.data;
|
||||
var tempData = [];
|
||||
var nextStart = 0;
|
||||
var nextEnd = 0;
|
||||
var cursor = 0;
|
||||
var matchedMark = null;
|
||||
var singleMark = '\'';
|
||||
var doubleMark = '"';
|
||||
var dataLength = data.length;
|
||||
|
||||
for (; nextEnd < data.length;) {
|
||||
var nextStartSingle = findNext(data, singleMark, nextEnd);
|
||||
var nextStartDouble = findNext(data, doubleMark, nextEnd);
|
||||
|
||||
if (nextStartSingle == -1)
|
||||
nextStartSingle = dataLength;
|
||||
if (nextStartDouble == -1)
|
||||
nextStartDouble = dataLength;
|
||||
|
||||
if (nextStartSingle < nextStartDouble) {
|
||||
nextStart = nextStartSingle;
|
||||
matchedMark = singleMark;
|
||||
} else {
|
||||
nextStart = nextStartDouble;
|
||||
matchedMark = doubleMark;
|
||||
}
|
||||
|
||||
if (nextStart == -1)
|
||||
break;
|
||||
|
||||
nextEnd = findQuoteEnd(data, matchedMark, nextStart + 1, cursor);
|
||||
if (nextEnd == -1)
|
||||
break;
|
||||
|
||||
var text = data.substring(nextStart, nextEnd + 1);
|
||||
tempData.push(data.substring(cursor, nextStart));
|
||||
if (text.length > 0)
|
||||
callback(text, tempData, nextStart);
|
||||
|
||||
cursor = nextEnd + 1;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
};
|
||||
|
||||
module.exports = QuoteScanner;
|
||||
96
node_modules/clean-css/lib/utils/source-reader.js
generated
vendored
Normal file
96
node_modules/clean-css/lib/utils/source-reader.js
generated
vendored
Normal file
@@ -0,0 +1,96 @@
|
||||
var path = require('path');
|
||||
var rewriteUrls = require('../urls/rewrite');
|
||||
|
||||
var REMOTE_RESOURCE = /^(https?:)?\/\//;
|
||||
|
||||
function SourceReader(context, data) {
|
||||
this.outerContext = context;
|
||||
this.data = data;
|
||||
this.sources = {};
|
||||
}
|
||||
|
||||
SourceReader.prototype.sourceAt = function (path) {
|
||||
return this.sources[path];
|
||||
};
|
||||
|
||||
SourceReader.prototype.trackSource = function (path, source) {
|
||||
this.sources[path] = {};
|
||||
this.sources[path][path] = source;
|
||||
};
|
||||
|
||||
SourceReader.prototype.toString = function () {
|
||||
if (typeof this.data == 'string')
|
||||
return fromString(this);
|
||||
if (Buffer.isBuffer(this.data))
|
||||
return fromBuffer(this);
|
||||
if (Array.isArray(this.data))
|
||||
return fromArray(this);
|
||||
|
||||
return fromHash(this);
|
||||
};
|
||||
|
||||
function fromString(self) {
|
||||
var data = self.data;
|
||||
self.trackSource(undefined, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
function fromBuffer(self) {
|
||||
var data = self.data.toString();
|
||||
self.trackSource(undefined, data);
|
||||
return data;
|
||||
}
|
||||
|
||||
function fromArray(self) {
|
||||
return self.data
|
||||
.map(function (source) {
|
||||
return self.outerContext.options.processImport === false ?
|
||||
source + '@shallow' :
|
||||
source;
|
||||
})
|
||||
.map(function (source) {
|
||||
return !self.outerContext.options.relativeTo || /^https?:\/\//.test(source) ?
|
||||
source :
|
||||
path.relative(self.outerContext.options.relativeTo, source);
|
||||
})
|
||||
.map(function (source) { return '@import url(' + source + ');'; })
|
||||
.join('');
|
||||
}
|
||||
|
||||
function fromHash(self) {
|
||||
var data = [];
|
||||
var toBase = path.resolve(self.outerContext.options.target || self.outerContext.options.root);
|
||||
|
||||
for (var source in self.data) {
|
||||
var styles = self.data[source].styles;
|
||||
var inputSourceMap = self.data[source].sourceMap;
|
||||
var isRemote = REMOTE_RESOURCE.test(source);
|
||||
var absoluteSource = isRemote ? source : path.resolve(source);
|
||||
var absoluteSourcePath = path.dirname(absoluteSource);
|
||||
|
||||
var rewriteOptions = {
|
||||
absolute: self.outerContext.options.explicitRoot,
|
||||
relative: !self.outerContext.options.explicitRoot,
|
||||
imports: true,
|
||||
rebase: self.outerContext.options.rebase,
|
||||
fromBase: absoluteSourcePath,
|
||||
toBase: isRemote ? absoluteSourcePath : toBase,
|
||||
urlQuotes: self.outerContext.options.compatibility.properties.urlQuotes
|
||||
};
|
||||
styles = rewriteUrls(styles, rewriteOptions, self.outerContext);
|
||||
|
||||
self.trackSource(source, styles);
|
||||
|
||||
styles = self.outerContext.sourceTracker.store(source, styles);
|
||||
|
||||
// here we assume source map lies in the same directory as `source` does
|
||||
if (self.outerContext.options.sourceMap && inputSourceMap)
|
||||
self.outerContext.inputSourceMapTracker.trackLoaded(source, source, inputSourceMap);
|
||||
|
||||
data.push(styles);
|
||||
}
|
||||
|
||||
return data.join('');
|
||||
}
|
||||
|
||||
module.exports = SourceReader;
|
||||
31
node_modules/clean-css/lib/utils/source-tracker.js
generated
vendored
Normal file
31
node_modules/clean-css/lib/utils/source-tracker.js
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
function SourceTracker() {
|
||||
this.sources = [];
|
||||
}
|
||||
|
||||
SourceTracker.prototype.store = function (filename, data) {
|
||||
this.sources.push(filename);
|
||||
|
||||
return '__ESCAPED_SOURCE_CLEAN_CSS' + (this.sources.length - 1) + '__' +
|
||||
data +
|
||||
'__ESCAPED_SOURCE_END_CLEAN_CSS__';
|
||||
};
|
||||
|
||||
SourceTracker.prototype.nextStart = function (data) {
|
||||
var next = /__ESCAPED_SOURCE_CLEAN_CSS(\d+)__/.exec(data);
|
||||
|
||||
return next ?
|
||||
{ index: next.index, filename: this.sources[~~next[1]] } :
|
||||
null;
|
||||
};
|
||||
|
||||
SourceTracker.prototype.nextEnd = function (data) {
|
||||
return /__ESCAPED_SOURCE_END_CLEAN_CSS__/g.exec(data);
|
||||
};
|
||||
|
||||
SourceTracker.prototype.removeAll = function (data) {
|
||||
return data
|
||||
.replace(/__ESCAPED_SOURCE_CLEAN_CSS\d+__/g, '')
|
||||
.replace(/__ESCAPED_SOURCE_END_CLEAN_CSS__/g, '');
|
||||
};
|
||||
|
||||
module.exports = SourceTracker;
|
||||
53
node_modules/clean-css/lib/utils/split.js
generated
vendored
Normal file
53
node_modules/clean-css/lib/utils/split.js
generated
vendored
Normal file
@@ -0,0 +1,53 @@
|
||||
function split(value, separator, includeSeparator, openLevel, closeLevel, firstOnly) {
|
||||
var withRegex = typeof separator != 'string';
|
||||
var hasSeparator = withRegex ?
|
||||
separator.test(value) :
|
||||
value.indexOf(separator);
|
||||
|
||||
if (!hasSeparator)
|
||||
return [value];
|
||||
|
||||
openLevel = openLevel || '(';
|
||||
closeLevel = closeLevel || ')';
|
||||
|
||||
if (value.indexOf(openLevel) == -1 && !includeSeparator && !firstOnly)
|
||||
return value.split(separator);
|
||||
|
||||
var level = 0;
|
||||
var cursor = 0;
|
||||
var lastStart = 0;
|
||||
var len = value.length;
|
||||
var tokens = [];
|
||||
|
||||
while (cursor < len) {
|
||||
if (value[cursor] == openLevel) {
|
||||
level++;
|
||||
} else if (value[cursor] == closeLevel) {
|
||||
level--;
|
||||
}
|
||||
|
||||
if (level === 0 && cursor > 0 && cursor + 1 < len && (withRegex ? separator.test(value[cursor]) : value[cursor] == separator)) {
|
||||
tokens.push(value.substring(lastStart, cursor + (includeSeparator ? 1 : 0)));
|
||||
lastStart = cursor + 1;
|
||||
|
||||
if (firstOnly && tokens.length == 1) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
cursor++;
|
||||
}
|
||||
|
||||
if (lastStart < cursor + 1) {
|
||||
var lastValue = value.substring(lastStart);
|
||||
var lastCharacter = lastValue[lastValue.length - 1];
|
||||
if (!includeSeparator && (withRegex ? separator.test(lastCharacter) : lastCharacter == separator))
|
||||
lastValue = lastValue.substring(0, lastValue.length - 1);
|
||||
|
||||
tokens.push(lastValue);
|
||||
}
|
||||
|
||||
return tokens;
|
||||
}
|
||||
|
||||
module.exports = split;
|
||||
Reference in New Issue
Block a user