clear
This commit is contained in:
30
node_modules/clean-css/lib/urls/rebase.js
generated
vendored
Normal file
30
node_modules/clean-css/lib/urls/rebase.js
generated
vendored
Normal file
@@ -0,0 +1,30 @@
|
||||
var path = require('path');
|
||||
|
||||
var rewriteUrls = require('./rewrite');
|
||||
|
||||
function rebaseUrls(data, context) {
|
||||
var rebaseOpts = {
|
||||
absolute: context.options.explicitRoot,
|
||||
relative: !context.options.explicitRoot && context.options.explicitTarget,
|
||||
fromBase: context.options.relativeTo
|
||||
};
|
||||
|
||||
if (!rebaseOpts.absolute && !rebaseOpts.relative)
|
||||
return data;
|
||||
|
||||
if (rebaseOpts.absolute && context.options.explicitTarget)
|
||||
context.warnings.push('Both \'root\' and output file given so rebasing URLs as absolute paths');
|
||||
|
||||
if (rebaseOpts.absolute)
|
||||
rebaseOpts.toBase = path.resolve(context.options.root);
|
||||
|
||||
if (rebaseOpts.relative)
|
||||
rebaseOpts.toBase = path.resolve(context.options.target);
|
||||
|
||||
if (!rebaseOpts.fromBase || !rebaseOpts.toBase)
|
||||
return data;
|
||||
|
||||
return rewriteUrls(data, rebaseOpts, context);
|
||||
}
|
||||
|
||||
module.exports = rebaseUrls;
|
||||
154
node_modules/clean-css/lib/urls/reduce.js
generated
vendored
Normal file
154
node_modules/clean-css/lib/urls/reduce.js
generated
vendored
Normal file
@@ -0,0 +1,154 @@
|
||||
var split = require('../utils/split');
|
||||
|
||||
var URL_PREFIX = 'url(';
|
||||
var UPPERCASE_URL_PREFIX = 'URL(';
|
||||
var URL_SUFFIX = ')';
|
||||
var SINGLE_QUOTE_URL_SUFFIX = '\')';
|
||||
var DOUBLE_QUOTE_URL_SUFFIX = '")';
|
||||
|
||||
var DATA_URI_PREFIX_PATTERN = /^\s*['"]?\s*data:/;
|
||||
var DATA_URI_TRAILER_PATTERN = /[\s\};,\/!]/;
|
||||
|
||||
var IMPORT_URL_PREFIX = '@import';
|
||||
var UPPERCASE_IMPORT_URL_PREFIX = '@IMPORT';
|
||||
|
||||
var COMMENT_END_MARKER = /\*\//;
|
||||
|
||||
function byUrl(data, context, callback) {
|
||||
var nextStart = 0;
|
||||
var nextStartUpperCase = 0;
|
||||
var nextEnd = 0;
|
||||
var firstMatch;
|
||||
var isDataURI = false;
|
||||
var cursor = 0;
|
||||
var tempData = [];
|
||||
var hasUppercaseUrl = data.indexOf(UPPERCASE_URL_PREFIX) > -1;
|
||||
|
||||
for (; nextEnd < data.length;) {
|
||||
nextStart = data.indexOf(URL_PREFIX, nextEnd);
|
||||
nextStartUpperCase = hasUppercaseUrl ? data.indexOf(UPPERCASE_URL_PREFIX, nextEnd) : -1;
|
||||
if (nextStart == -1 && nextStartUpperCase == -1)
|
||||
break;
|
||||
|
||||
if (nextStart == -1 && nextStartUpperCase > -1)
|
||||
nextStart = nextStartUpperCase;
|
||||
|
||||
if (data[nextStart + URL_PREFIX.length] == '"') {
|
||||
nextEnd = data.indexOf(DOUBLE_QUOTE_URL_SUFFIX, nextStart);
|
||||
} else if (data[nextStart + URL_PREFIX.length] == '\'') {
|
||||
nextEnd = data.indexOf(SINGLE_QUOTE_URL_SUFFIX, nextStart);
|
||||
} else {
|
||||
isDataURI = DATA_URI_PREFIX_PATTERN.test(data.substring(nextStart + URL_PREFIX.length));
|
||||
|
||||
if (isDataURI) {
|
||||
firstMatch = split(data.substring(nextStart), DATA_URI_TRAILER_PATTERN, false, '(', ')', true).pop();
|
||||
|
||||
if (firstMatch && firstMatch[firstMatch.length - 1] == URL_SUFFIX) {
|
||||
nextEnd = nextStart + firstMatch.length - URL_SUFFIX.length;
|
||||
} else {
|
||||
nextEnd = -1;
|
||||
}
|
||||
} else {
|
||||
nextEnd = data.indexOf(URL_SUFFIX, nextStart);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// Following lines are a safety mechanism to ensure
|
||||
// incorrectly terminated urls are processed correctly.
|
||||
if (nextEnd == -1) {
|
||||
nextEnd = data.indexOf('}', nextStart);
|
||||
|
||||
if (nextEnd == -1)
|
||||
nextEnd = data.length;
|
||||
else
|
||||
nextEnd--;
|
||||
|
||||
context.warnings.push('Broken URL declaration: \'' + data.substring(nextStart, nextEnd + 1) + '\'.');
|
||||
} else {
|
||||
if (data[nextEnd] != URL_SUFFIX)
|
||||
nextEnd = data.indexOf(URL_SUFFIX, nextEnd);
|
||||
}
|
||||
|
||||
tempData.push(data.substring(cursor, nextStart));
|
||||
|
||||
var url = data.substring(nextStart, nextEnd + 1);
|
||||
callback(url, tempData);
|
||||
|
||||
cursor = nextEnd + 1;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
}
|
||||
|
||||
function byImport(data, context, callback) {
|
||||
var nextImport = 0;
|
||||
var nextImportUpperCase = 0;
|
||||
var nextStart = 0;
|
||||
var nextEnd = 0;
|
||||
var cursor = 0;
|
||||
var tempData = [];
|
||||
var nextSingleQuote = 0;
|
||||
var nextDoubleQuote = 0;
|
||||
var untilNextQuote;
|
||||
var withQuote;
|
||||
var SINGLE_QUOTE = '\'';
|
||||
var DOUBLE_QUOTE = '"';
|
||||
|
||||
for (; nextEnd < data.length;) {
|
||||
nextImport = data.indexOf(IMPORT_URL_PREFIX, nextEnd);
|
||||
nextImportUpperCase = data.indexOf(UPPERCASE_IMPORT_URL_PREFIX, nextEnd);
|
||||
if (nextImport == -1 && nextImportUpperCase == -1)
|
||||
break;
|
||||
|
||||
if (nextImport > -1 && nextImportUpperCase > -1 && nextImportUpperCase < nextImport)
|
||||
nextImport = nextImportUpperCase;
|
||||
|
||||
nextSingleQuote = data.indexOf(SINGLE_QUOTE, nextImport);
|
||||
nextDoubleQuote = data.indexOf(DOUBLE_QUOTE, nextImport);
|
||||
|
||||
if (nextSingleQuote > -1 && nextDoubleQuote > -1 && nextSingleQuote < nextDoubleQuote) {
|
||||
nextStart = nextSingleQuote;
|
||||
withQuote = SINGLE_QUOTE;
|
||||
} else if (nextSingleQuote > -1 && nextDoubleQuote > -1 && nextSingleQuote > nextDoubleQuote) {
|
||||
nextStart = nextDoubleQuote;
|
||||
withQuote = DOUBLE_QUOTE;
|
||||
} else if (nextSingleQuote > -1) {
|
||||
nextStart = nextSingleQuote;
|
||||
withQuote = SINGLE_QUOTE;
|
||||
} else if (nextDoubleQuote > -1) {
|
||||
nextStart = nextDoubleQuote;
|
||||
withQuote = DOUBLE_QUOTE;
|
||||
} else {
|
||||
break;
|
||||
}
|
||||
|
||||
tempData.push(data.substring(cursor, nextStart));
|
||||
nextEnd = data.indexOf(withQuote, nextStart + 1);
|
||||
|
||||
untilNextQuote = data.substring(nextImport, nextEnd);
|
||||
if (nextEnd == -1 || /^@import\s+(url\(|__ESCAPED)/i.test(untilNextQuote) || COMMENT_END_MARKER.test(untilNextQuote)) {
|
||||
cursor = nextStart;
|
||||
break;
|
||||
}
|
||||
|
||||
var url = data.substring(nextStart, nextEnd + 1);
|
||||
callback(url, tempData);
|
||||
|
||||
cursor = nextEnd + 1;
|
||||
}
|
||||
|
||||
return tempData.length > 0 ?
|
||||
tempData.join('') + data.substring(cursor, data.length) :
|
||||
data;
|
||||
}
|
||||
|
||||
function reduceAll(data, context, callback) {
|
||||
data = byUrl(data, context, callback);
|
||||
data = byImport(data, context, callback);
|
||||
return data;
|
||||
}
|
||||
|
||||
module.exports = reduceAll;
|
||||
107
node_modules/clean-css/lib/urls/rewrite.js
generated
vendored
Normal file
107
node_modules/clean-css/lib/urls/rewrite.js
generated
vendored
Normal file
@@ -0,0 +1,107 @@
|
||||
var path = require('path');
|
||||
var url = require('url');
|
||||
|
||||
var reduceUrls = require('./reduce');
|
||||
|
||||
var isWindows = process.platform == 'win32';
|
||||
|
||||
function isAbsolute(uri) {
|
||||
return uri[0] == '/';
|
||||
}
|
||||
|
||||
function isSVGMarker(uri) {
|
||||
return uri[0] == '#';
|
||||
}
|
||||
|
||||
function isEscaped(uri) {
|
||||
return uri.indexOf('__ESCAPED_URL_CLEAN_CSS__') === 0;
|
||||
}
|
||||
|
||||
function isInternal(uri) {
|
||||
return /^\w+:\w+/.test(uri);
|
||||
}
|
||||
|
||||
function isRemote(uri) {
|
||||
return /^[^:]+?:\/\//.test(uri) || uri.indexOf('//') === 0;
|
||||
}
|
||||
|
||||
function isSameOrigin(uri1, uri2) {
|
||||
return url.parse(uri1).protocol == url.parse(uri2).protocol &&
|
||||
url.parse(uri1).host == url.parse(uri2).host;
|
||||
}
|
||||
|
||||
function isImport(uri) {
|
||||
return uri.lastIndexOf('.css') === uri.length - 4;
|
||||
}
|
||||
|
||||
function isData(uri) {
|
||||
return uri.indexOf('data:') === 0;
|
||||
}
|
||||
|
||||
function absolute(uri, options) {
|
||||
return path
|
||||
.resolve(path.join(options.fromBase || '', uri))
|
||||
.replace(options.toBase, '');
|
||||
}
|
||||
|
||||
function relative(uri, options) {
|
||||
return path.relative(options.toBase, path.join(options.fromBase || '', uri));
|
||||
}
|
||||
|
||||
function normalize(uri) {
|
||||
return isWindows ? uri.replace(/\\/g, '/') : uri;
|
||||
}
|
||||
|
||||
function rebase(uri, options) {
|
||||
if (isAbsolute(uri) || isSVGMarker(uri) || isEscaped(uri) || isInternal(uri))
|
||||
return uri;
|
||||
|
||||
if (options.rebase === false && !isImport(uri))
|
||||
return uri;
|
||||
|
||||
if (!options.imports && isImport(uri))
|
||||
return uri;
|
||||
|
||||
if (isData(uri))
|
||||
return '\'' + uri + '\'';
|
||||
|
||||
if (isRemote(uri) && !isRemote(options.toBase))
|
||||
return uri;
|
||||
|
||||
if (isRemote(uri) && !isSameOrigin(uri, options.toBase))
|
||||
return uri;
|
||||
|
||||
if (!isRemote(uri) && isRemote(options.toBase))
|
||||
return url.resolve(options.toBase, uri);
|
||||
|
||||
return options.absolute ?
|
||||
normalize(absolute(uri, options)) :
|
||||
normalize(relative(uri, options));
|
||||
}
|
||||
|
||||
function quoteFor(url) {
|
||||
if (url.indexOf('\'') > -1)
|
||||
return '"';
|
||||
else if (url.indexOf('"') > -1)
|
||||
return '\'';
|
||||
else if (/\s/.test(url) || /[\(\)]/.test(url))
|
||||
return '\'';
|
||||
else
|
||||
return '';
|
||||
}
|
||||
|
||||
function rewriteUrls(data, options, context) {
|
||||
return reduceUrls(data, context, function (originUrl, tempData) {
|
||||
var url = originUrl.replace(/^(url\()?\s*['"]?|['"]?\s*\)?$/g, '');
|
||||
var match = originUrl.match(/^(url\()?\s*(['"]).*?(['"])\s*\)?$/);
|
||||
var quote;
|
||||
if (!!options.urlQuotes && match && match[2] === match[3]) {
|
||||
quote = match[2];
|
||||
} else {
|
||||
quote = quoteFor(url);
|
||||
}
|
||||
tempData.push('url(' + quote + rebase(url, options) + quote + ')');
|
||||
});
|
||||
}
|
||||
|
||||
module.exports = rewriteUrls;
|
||||
Reference in New Issue
Block a user