mirror of
https://github.com/less/less.js.git
synced 2026-01-26 07:38:38 -05:00
Merge branch '1.5.0-wip'
This commit is contained in:
2
.gitignore
vendored
2
.gitignore
vendored
@@ -6,3 +6,5 @@ node_modules
|
||||
.idea
|
||||
test/browser/less.js
|
||||
test/browser/test-runner-*.htm
|
||||
test/sourcemaps/*.map
|
||||
test/sourcemaps/*.css
|
||||
|
||||
5
.jshintignore
Normal file
5
.jshintignore
Normal file
@@ -0,0 +1,5 @@
|
||||
benchmark/
|
||||
build/
|
||||
dist/
|
||||
node_modules/
|
||||
test/browser/
|
||||
11
.jshintrc
Normal file
11
.jshintrc
Normal file
@@ -0,0 +1,11 @@
|
||||
{
|
||||
"evil": true,
|
||||
"boss": true,
|
||||
"expr": true,
|
||||
"laxbreak": true,
|
||||
"latedef": true,
|
||||
"node": true,
|
||||
"undef": true,
|
||||
"unused": "vars",
|
||||
"noarg": true
|
||||
}
|
||||
26
CHANGELOG.md
26
CHANGELOG.md
@@ -1,3 +1,25 @@
|
||||
# 1.5.0 Beta 1
|
||||
|
||||
2013-09-01
|
||||
|
||||
- sourcemap support
|
||||
- support for import inline option to include css that you do NOT want less to parse e.g. `@import (inline) "file.css";`
|
||||
- better support for modifyVars (refresh styles with new variables, using a file cache), is now more resiliant
|
||||
- support for import reference option to reference external css, but not output it. Any mixin calls or extend's will be output.
|
||||
- support for guards on selectors (currently only if you have a single selector)
|
||||
- Added min/max functions
|
||||
- fix bad spaces between namespace operators
|
||||
- do not compress comment if it begins with an exclamation mark
|
||||
- change to not throw exceptions in toCSS - always return an error object
|
||||
- allow property merging through the +: syntax
|
||||
- Fix the saturate function to pass through when using the CSS syntax
|
||||
- Added svg-gradient function
|
||||
- Added no-js option to lessc (in browser, use javascriptEnabled: false) which disallows JavaScript in less files
|
||||
- switched from the little supported and buggy cssmin (previously ycssmin) to clean-css
|
||||
- Browser: added logLevel option to control logging (2 = everything, 1 = errors only, 0 = no logging)
|
||||
- Browser: added errorReporting option which can be "html" (default) or "console" or a function
|
||||
- A few bug fixes for media queries and extends
|
||||
|
||||
# 1.4.2
|
||||
|
||||
2013-07-20
|
||||
@@ -22,7 +44,7 @@
|
||||
- fix passing of strict maths option
|
||||
|
||||
# 1.4.0 Beta 4
|
||||
|
||||
|
||||
2013-05-04
|
||||
|
||||
- change strictMaths to strictMath. Enable this with --strict-math=on in lessc and strictMath:true in JavaScript.
|
||||
@@ -55,7 +77,7 @@
|
||||
- significant bug fixes to our debug options
|
||||
- other parameters can be used as defaults in mixins e.g. .a(@a, @b:@a)
|
||||
- an error is shown if properties are used outside of a ruleset
|
||||
- added extract function which picks a value out of a list, e.g. extract(12 13 14, 3) => 3
|
||||
- added extract function which picks a value out of a list, e.g. extract(12 13 14, 3) => 14
|
||||
- added luma, hsvhue, hsvsaturation, hsvvalue functions
|
||||
- added pow, pi, mod, tan, sin, cos, atan, asin, acos and sqrt math functions
|
||||
- added convert function, e.g. convert(1rad, deg) => value in degrees
|
||||
|
||||
14
Makefile
14
Makefile
@@ -35,15 +35,17 @@ less:
|
||||
@@cat ${HEADER} | sed s/@VERSION/${VERSION}/ > ${DIST}
|
||||
@@echo "(function (window, undefined) {" >> ${DIST}
|
||||
@@cat build/require.js\
|
||||
build/browser-header.js\
|
||||
${SRC}/parser.js\
|
||||
${SRC}/functions.js\
|
||||
${SRC}/colors.js\
|
||||
${SRC}/tree/*.js\
|
||||
${SRC}/tree.js\
|
||||
${SRC}/tree/*.js\
|
||||
${SRC}/env.js\
|
||||
${SRC}/visitor.js\
|
||||
${SRC}/import-visitor.js\
|
||||
${SRC}/join-selector-visitor.js\
|
||||
${SRC}/to-css-visitor.js\
|
||||
${SRC}/extend-visitor.js\
|
||||
${SRC}/browser.js\
|
||||
build/amd.js >> ${DIST}
|
||||
@@ -59,15 +61,25 @@ browser-test: browser-prepare
|
||||
browser-test-server: browser-prepare
|
||||
phantomjs test/browser/phantom-runner.js --no-tests
|
||||
|
||||
jshint:
|
||||
node_modules/.bin/jshint --config ./.jshintrc .
|
||||
|
||||
test-sourcemaps:
|
||||
node bin/lessc --source-map --source-map-inline test/less/import.less test/sourcemaps/import.css
|
||||
node bin/lessc --source-map --source-map-inline test/less/sourcemaps/basic.less test/sourcemaps/basic.css
|
||||
node node_modules/http-server/bin/http-server test/sourcemaps -p 8083
|
||||
|
||||
rhino:
|
||||
@@mkdir -p dist
|
||||
@@touch ${RHINO}
|
||||
@@cat build/require-rhino.js\
|
||||
build/rhino-header.js\
|
||||
${SRC}/parser.js\
|
||||
${SRC}/env.js\
|
||||
${SRC}/visitor.js\
|
||||
${SRC}/import-visitor.js\
|
||||
${SRC}/join-selector-visitor.js\
|
||||
${SRC}/to-css-visitor.js\
|
||||
${SRC}/extend-visitor.js\
|
||||
${SRC}/functions.js\
|
||||
${SRC}/colors.js\
|
||||
|
||||
58
bin/lessc
58
bin/lessc
@@ -11,7 +11,7 @@ var args = process.argv.slice(1);
|
||||
var options = {
|
||||
depends: false,
|
||||
compress: false,
|
||||
yuicompress: false,
|
||||
cleancss: false,
|
||||
max_line_len: -1,
|
||||
optimization: 1,
|
||||
silent: false,
|
||||
@@ -52,6 +52,8 @@ var checkBooleanArg = function(arg) {
|
||||
return Boolean(onOff[2]);
|
||||
};
|
||||
|
||||
var warningMessages = "";
|
||||
|
||||
args = args.filter(function (arg) {
|
||||
var match;
|
||||
|
||||
@@ -95,7 +97,11 @@ args = args.filter(function (arg) {
|
||||
options.depends = true;
|
||||
break;
|
||||
case 'yui-compress':
|
||||
options.yuicompress = true;
|
||||
warningMessages += "yui-compress option has been removed. assuming clean-css.";
|
||||
options.cleancss = true;
|
||||
break;
|
||||
case 'clean-css':
|
||||
options.cleancss = true;
|
||||
break;
|
||||
case 'max-line-len':
|
||||
if (checkArgFunc(arg, match[2])) {
|
||||
@@ -111,6 +117,9 @@ args = args.filter(function (arg) {
|
||||
case 'no-ie-compat':
|
||||
options.ieCompat = false;
|
||||
break;
|
||||
case 'no-js':
|
||||
options.javascriptEnabled = false;
|
||||
break;
|
||||
case 'include-path':
|
||||
if (checkArgFunc(arg, match[2])) {
|
||||
options.paths = match[2].split(os.type().match(/Windows/) ? ';' : ':')
|
||||
@@ -129,6 +138,21 @@ args = args.filter(function (arg) {
|
||||
options.dumpLineNumbers = match[2];
|
||||
}
|
||||
break;
|
||||
case 'source-map':
|
||||
if (!match[2]) {
|
||||
options.sourceMap = true;
|
||||
} else {
|
||||
options.sourceMap = match[2];
|
||||
}
|
||||
break;
|
||||
case 'source-map-rootpath':
|
||||
if (checkArgFunc(arg, match[2])) {
|
||||
options.sourceMapRootpath = match[2];
|
||||
}
|
||||
break;
|
||||
case 'source-map-inline':
|
||||
options.outputSourceFiles = true;
|
||||
break;
|
||||
case 'rp':
|
||||
case 'rootpath':
|
||||
if (checkArgFunc(arg, match[2])) {
|
||||
@@ -166,7 +190,22 @@ if (input && input != '-') {
|
||||
var output = args[2];
|
||||
var outputbase = args[2];
|
||||
if (output) {
|
||||
options.sourceMapOutputFilename = output;
|
||||
output = path.resolve(process.cwd(), output);
|
||||
if (warningMessages) {
|
||||
sys.puts(warningMessages);
|
||||
}
|
||||
}
|
||||
|
||||
options.sourceMapBasepath = process.cwd();
|
||||
|
||||
if (options.sourceMap === true) {
|
||||
if (!output) {
|
||||
sys.puts("the sourcemap option only has an optional filename if the css filename is given");
|
||||
return;
|
||||
}
|
||||
options.sourceMapFullFilename = options.sourceMapOutputFilename + ".map";
|
||||
options.sourceMap = path.basename(options.sourceMapFullFilename);
|
||||
}
|
||||
|
||||
if (! input) {
|
||||
@@ -199,6 +238,12 @@ if (options.depends) {
|
||||
sys.print(outputbase + ": ");
|
||||
}
|
||||
|
||||
var writeSourceMap = function(output) {
|
||||
var filename = options.sourceMapFullFilename || options.sourceMap;
|
||||
ensureDirectory(filename);
|
||||
fs.writeFileSync(filename, output, 'utf8');
|
||||
};
|
||||
|
||||
var parseLessFile = function (e, data) {
|
||||
if (e) {
|
||||
sys.puts("lessc: " + e.message);
|
||||
@@ -227,7 +272,14 @@ var parseLessFile = function (e, data) {
|
||||
verbose: options.verbose,
|
||||
ieCompat: options.ieCompat,
|
||||
compress: options.compress,
|
||||
yuicompress: options.yuicompress,
|
||||
cleancss: options.cleancss,
|
||||
sourceMap: Boolean(options.sourceMap),
|
||||
sourceMapFilename: options.sourceMap,
|
||||
sourceMapOutputFilename: options.sourceMapOutputFilename,
|
||||
sourceMapBasepath: options.sourceMapBasepath,
|
||||
sourceMapRootpath: options.sourceMapRootpath || "",
|
||||
outputSourceFiles: options.outputSourceFiles,
|
||||
writeSourceMap: writeSourceMap,
|
||||
maxLineLen: options.maxLineLen,
|
||||
strictMath: options.strictMath,
|
||||
strictUnits: options.strictUnits
|
||||
|
||||
4
build/browser-header.js
Normal file
4
build/browser-header.js
Normal file
@@ -0,0 +1,4 @@
|
||||
if (typeof(window.less) === 'undefined' || typeof(window.less.nodeType) !== 'undefined') { window.less = {}; }
|
||||
less = window.less;
|
||||
tree = window.less.tree = {};
|
||||
less.mode = 'browser';
|
||||
4
build/rhino-header.js
Normal file
4
build/rhino-header.js
Normal file
@@ -0,0 +1,4 @@
|
||||
if (typeof(window) === 'undefined') { less = {} }
|
||||
else { less = window.less = {} }
|
||||
tree = less.tree = {};
|
||||
less.mode = 'rhino';
|
||||
6660
dist/less-1.5.0.js
vendored
Normal file
6660
dist/less-1.5.0.js
vendored
Normal file
File diff suppressed because it is too large
Load Diff
11
dist/less-1.5.0.min.js
vendored
Normal file
11
dist/less-1.5.0.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
@@ -1,6 +1,7 @@
|
||||
//
|
||||
// browser.js - client-side engine
|
||||
//
|
||||
/*global less, window, document, XMLHttpRequest, location */
|
||||
|
||||
var isFileProtocol = /^(file|chrome(-extension)?|resource|qrc|app):/.test(location.protocol);
|
||||
|
||||
@@ -11,6 +12,19 @@ less.env = less.env || (location.hostname == '127.0.0.1' ||
|
||||
isFileProtocol ? 'development'
|
||||
: 'production');
|
||||
|
||||
var logLevel = {
|
||||
info: 2,
|
||||
errors: 1,
|
||||
none: 0
|
||||
};
|
||||
|
||||
// The amount of logging in the javascript console.
|
||||
// 2 - Information and errors
|
||||
// 1 - Errors
|
||||
// 0 - None
|
||||
// Defaults to 2
|
||||
less.logLevel = typeof(less.logLevel) != 'undefined' ? less.logLevel : logLevel.info;
|
||||
|
||||
// Load styles asynchronously (default: false)
|
||||
//
|
||||
// This is set to `false` by default, so that the body
|
||||
@@ -35,303 +49,49 @@ if (dumpLineNumbers) {
|
||||
less.dumpLineNumbers = dumpLineNumbers[1];
|
||||
}
|
||||
|
||||
//
|
||||
// Watch mode
|
||||
//
|
||||
less.watch = function () {
|
||||
if (!less.watchMode ){
|
||||
less.env = 'development';
|
||||
initRunningMode();
|
||||
}
|
||||
return this.watchMode = true
|
||||
};
|
||||
|
||||
less.unwatch = function () {clearInterval(less.watchTimer); return this.watchMode = false; };
|
||||
|
||||
function initRunningMode(){
|
||||
if (less.env === 'development') {
|
||||
less.optimization = 0;
|
||||
less.watchTimer = setInterval(function () {
|
||||
if (less.watchMode) {
|
||||
loadStyleSheets(function (e, root, _, sheet, env) {
|
||||
if (e) {
|
||||
error(e, sheet.href);
|
||||
} else if (root) {
|
||||
createCSS(root.toCSS(less), sheet, env.lastModified);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, less.poll);
|
||||
} else {
|
||||
less.optimization = 3;
|
||||
}
|
||||
}
|
||||
|
||||
if (/!watch/.test(location.hash)) {
|
||||
less.watch();
|
||||
}
|
||||
|
||||
var cache = null;
|
||||
|
||||
if (less.env != 'development') {
|
||||
try {
|
||||
cache = (typeof(window.localStorage) === 'undefined') ? null : window.localStorage;
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
//
|
||||
// Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
|
||||
//
|
||||
var links = document.getElementsByTagName('link');
|
||||
var typePattern = /^text\/(x-)?less$/;
|
||||
var cache = null;
|
||||
var fileCache = {};
|
||||
|
||||
less.sheets = [];
|
||||
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
|
||||
(links[i].type.match(typePattern)))) {
|
||||
less.sheets.push(links[i]);
|
||||
function log(str, level) {
|
||||
if (less.env == 'development' && typeof(console) !== 'undefined' && less.logLevel >= level) {
|
||||
console.log('less: ' + str);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// With this function, it's possible to alter variables and re-render
|
||||
// CSS without reloading less-files
|
||||
//
|
||||
var session_cache = '';
|
||||
less.modifyVars = function(record) {
|
||||
var str = session_cache;
|
||||
for (var name in record) {
|
||||
str += ((name.slice(0,1) === '@')? '' : '@') + name +': '+
|
||||
((record[name].slice(-1) === ';')? record[name] : record[name] +';');
|
||||
}
|
||||
new(less.Parser)(new less.tree.parseEnv(less)).parse(str, function (e, root) {
|
||||
if (e) {
|
||||
error(e, "session_cache");
|
||||
} else {
|
||||
createCSS(root.toCSS(less), less.sheets[less.sheets.length - 1]);
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
less.refresh = function (reload) {
|
||||
var startTime, endTime;
|
||||
startTime = endTime = new(Date);
|
||||
|
||||
loadStyleSheets(function (e, root, _, sheet, env) {
|
||||
if (e) {
|
||||
return error(e, sheet.href);
|
||||
}
|
||||
if (env.local) {
|
||||
log("loading " + sheet.href + " from cache.");
|
||||
} else {
|
||||
log("parsed " + sheet.href + " successfully.");
|
||||
createCSS(root.toCSS(less), sheet, env.lastModified);
|
||||
}
|
||||
log("css for " + sheet.href + " generated in " + (new(Date) - endTime) + 'ms');
|
||||
(env.remaining === 0) && log("css generated in " + (new(Date) - startTime) + 'ms');
|
||||
endTime = new(Date);
|
||||
}, reload);
|
||||
|
||||
loadStyles();
|
||||
};
|
||||
less.refreshStyles = loadStyles;
|
||||
|
||||
less.refresh(less.env === 'development');
|
||||
|
||||
function loadStyles() {
|
||||
var styles = document.getElementsByTagName('style');
|
||||
for (var i = 0; i < styles.length; i++) {
|
||||
if (styles[i].type.match(typePattern)) {
|
||||
var env = new less.tree.parseEnv(less);
|
||||
env.filename = document.location.href.replace(/#.*$/, '');
|
||||
|
||||
new(less.Parser)(env).parse(styles[i].innerHTML || '', function (e, cssAST) {
|
||||
if (e) {
|
||||
return error(e, "inline");
|
||||
}
|
||||
var css = cssAST.toCSS(less);
|
||||
var style = styles[i];
|
||||
style.type = 'text/css';
|
||||
if (style.styleSheet) {
|
||||
style.styleSheet.cssText = css;
|
||||
} else {
|
||||
style.innerHTML = css;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function loadStyleSheets(callback, reload) {
|
||||
for (var i = 0; i < less.sheets.length; i++) {
|
||||
loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1));
|
||||
}
|
||||
}
|
||||
|
||||
function pathDiff(url, baseUrl) {
|
||||
// diff between two paths to create a relative path
|
||||
|
||||
var urlParts = extractUrlParts(url),
|
||||
baseUrlParts = extractUrlParts(baseUrl),
|
||||
i, max, urlDirectories, baseUrlDirectories, diff = "";
|
||||
if (urlParts.hostPart !== baseUrlParts.hostPart) {
|
||||
return "";
|
||||
}
|
||||
max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
|
||||
for(i = 0; i < max; i++) {
|
||||
if (baseUrlParts.directories[i] !== urlParts.directories[i]) { break; }
|
||||
}
|
||||
baseUrlDirectories = baseUrlParts.directories.slice(i);
|
||||
urlDirectories = urlParts.directories.slice(i);
|
||||
for(i = 0; i < baseUrlDirectories.length-1; i++) {
|
||||
diff += "../";
|
||||
}
|
||||
for(i = 0; i < urlDirectories.length-1; i++) {
|
||||
diff += urlDirectories[i] + "/";
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
function extractUrlParts(url, baseUrl) {
|
||||
// urlParts[1] = protocol&hostname || /
|
||||
// urlParts[2] = / if path relative to host base
|
||||
// urlParts[3] = directories
|
||||
// urlParts[4] = filename
|
||||
// urlParts[5] = parameters
|
||||
|
||||
var urlPartsRegex = /^((?:[a-z-]+:)?\/+?(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i,
|
||||
urlParts = url.match(urlPartsRegex),
|
||||
returner = {}, directories = [], i, baseUrlParts;
|
||||
|
||||
if (!urlParts) {
|
||||
throw new Error("Could not parse sheet href - '"+url+"'");
|
||||
}
|
||||
|
||||
// Stylesheets in IE don't always return the full path
|
||||
if (!urlParts[1] || urlParts[2]) {
|
||||
baseUrlParts = baseUrl.match(urlPartsRegex);
|
||||
if (!baseUrlParts) {
|
||||
throw new Error("Could not parse page url - '"+baseUrl+"'");
|
||||
}
|
||||
urlParts[1] = urlParts[1] || baseUrlParts[1] || "";
|
||||
if (!urlParts[2]) {
|
||||
urlParts[3] = baseUrlParts[3] + urlParts[3];
|
||||
}
|
||||
}
|
||||
|
||||
if (urlParts[3]) {
|
||||
directories = urlParts[3].replace(/\\/g, "/").split("/");
|
||||
|
||||
// extract out . before .. so .. doesn't absorb a non-directory
|
||||
for(i = 0; i < directories.length; i++) {
|
||||
if (directories[i] === ".") {
|
||||
directories.splice(i, 1);
|
||||
i -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < directories.length; i++) {
|
||||
if (directories[i] === ".." && i > 0) {
|
||||
directories.splice(i-1, 2);
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returner.hostPart = urlParts[1];
|
||||
returner.directories = directories;
|
||||
returner.path = urlParts[1] + directories.join("/");
|
||||
returner.fileUrl = returner.path + (urlParts[4] || "");
|
||||
returner.url = returner.fileUrl + (urlParts[5] || "");
|
||||
return returner;
|
||||
}
|
||||
|
||||
function loadStyleSheet(sheet, callback, reload, remaining) {
|
||||
|
||||
// sheet may be set to the stylesheet for the initial load or a collection of properties including
|
||||
// some env variables for imports
|
||||
var hrefParts = extractUrlParts(sheet.href, window.location.href);
|
||||
var href = hrefParts.url;
|
||||
var css = cache && cache.getItem(href);
|
||||
var timestamp = cache && cache.getItem(href + ':timestamp');
|
||||
var styles = { css: css, timestamp: timestamp };
|
||||
var env;
|
||||
var newFileInfo = {
|
||||
relativeUrls: less.relativeUrls,
|
||||
currentDirectory: hrefParts.path,
|
||||
filename: href
|
||||
};
|
||||
|
||||
if (sheet instanceof less.tree.parseEnv) {
|
||||
env = new less.tree.parseEnv(sheet);
|
||||
newFileInfo.entryPath = env.currentFileInfo.entryPath;
|
||||
newFileInfo.rootpath = env.currentFileInfo.rootpath;
|
||||
newFileInfo.rootFilename = env.currentFileInfo.rootFilename;
|
||||
} else {
|
||||
env = new less.tree.parseEnv(less);
|
||||
env.mime = sheet.type;
|
||||
newFileInfo.entryPath = hrefParts.path;
|
||||
newFileInfo.rootpath = less.rootpath || hrefParts.path;
|
||||
newFileInfo.rootFilename = href;
|
||||
}
|
||||
|
||||
if (env.relativeUrls) {
|
||||
//todo - this relies on option being set on less object rather than being passed in as an option
|
||||
// - need an originalRootpath
|
||||
if (less.rootpath) {
|
||||
newFileInfo.rootpath = extractUrlParts(less.rootpath + pathDiff(hrefParts.path, newFileInfo.entryPath)).path;
|
||||
} else {
|
||||
newFileInfo.rootpath = hrefParts.path;
|
||||
}
|
||||
}
|
||||
|
||||
xhr(href, sheet.type, function (data, lastModified) {
|
||||
// Store data this session
|
||||
session_cache += data.replace(/@import .+?;/ig, '');
|
||||
|
||||
if (!reload && styles && lastModified &&
|
||||
(new(Date)(lastModified).valueOf() ===
|
||||
new(Date)(styles.timestamp).valueOf())) {
|
||||
// Use local copy
|
||||
createCSS(styles.css, sheet);
|
||||
callback(null, null, data, sheet, { local: true, remaining: remaining }, href);
|
||||
} else {
|
||||
// Use remote copy (re-parse)
|
||||
try {
|
||||
env.contents[href] = data; // Updating content cache
|
||||
env.paths = [hrefParts.path];
|
||||
env.currentFileInfo = newFileInfo;
|
||||
|
||||
new(less.Parser)(env).parse(data, function (e, root) {
|
||||
if (e) { return callback(e, null, null, sheet); }
|
||||
try {
|
||||
callback(e, root, data, sheet, { local: false, lastModified: lastModified, remaining: remaining }, href);
|
||||
//TODO - there must be a better way? A generic less-to-css function that can both call error
|
||||
//and removeNode where appropriate
|
||||
//should also add tests
|
||||
if (env.currentFileInfo.rootFilename === href) {
|
||||
removeNode(document.getElementById('less-error-message:' + extractId(href)));
|
||||
}
|
||||
} catch (e) {
|
||||
callback(e, null, null, sheet);
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
callback(e, null, null, sheet);
|
||||
}
|
||||
}
|
||||
}, function (status, url) {
|
||||
callback({ type: 'File', message: "'" + url + "' wasn't found (" + status + ")" }, null, null, sheet);
|
||||
});
|
||||
}
|
||||
|
||||
function extractId(href) {
|
||||
return href.replace(/^[a-z-]+:\/+?[^\/]+/, '' ) // Remove protocol & domain
|
||||
.replace(/^\//, '' ) // Remove root /
|
||||
.replace(/\.[a-zA-Z]+$/, '' ) // Remove simple extension
|
||||
.replace(/[^\.\w-]+/g, '-') // Replace illegal characters
|
||||
.replace(/\./g, ':'); // Replace dots with colons(for valid id)
|
||||
.replace(/^\//, '' ) // Remove root /
|
||||
.replace(/\.[a-zA-Z]+$/, '' ) // Remove simple extension
|
||||
.replace(/[^\.\w-]+/g, '-') // Replace illegal characters
|
||||
.replace(/\./g, ':'); // Replace dots with colons(for valid id)
|
||||
}
|
||||
|
||||
function errorConsole(e, rootHref) {
|
||||
var template = '{line} {content}';
|
||||
var filename = e.filename || rootHref;
|
||||
var errors = [];
|
||||
var content = (e.type || "Syntax") + "Error: " + (e.message || 'There is an error in your .less file') +
|
||||
" in " + filename + " ";
|
||||
|
||||
var errorline = function (e, i, classname) {
|
||||
if (e.extract[i] !== undefined) {
|
||||
errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
|
||||
.replace(/\{class\}/, classname)
|
||||
.replace(/\{content\}/, e.extract[i]));
|
||||
}
|
||||
};
|
||||
|
||||
if (e.extract) {
|
||||
errorline(e, 0, '');
|
||||
errorline(e, 1, 'line');
|
||||
errorline(e, 2, '');
|
||||
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n' +
|
||||
errors.join('\n');
|
||||
} else if (e.stack) {
|
||||
content += e.stack;
|
||||
}
|
||||
log(content, logLevel.errors);
|
||||
}
|
||||
|
||||
function createCSS(styles, sheet, lastModified) {
|
||||
@@ -371,89 +131,35 @@ function createCSS(styles, sheet, lastModified) {
|
||||
|
||||
// If there is no oldCss, just append; otherwise, only append if we need
|
||||
// to replace oldCss with an updated stylesheet
|
||||
if (oldCss == null || keepOldCss === false) {
|
||||
if (oldCss === null || keepOldCss === false) {
|
||||
var nextEl = sheet && sheet.nextSibling || null;
|
||||
(nextEl || document.getElementsByTagName('head')[0]).parentNode.insertBefore(css, nextEl);
|
||||
if (nextEl) {
|
||||
nextEl.parentNode.insertBefore(css, nextEl);
|
||||
} else {
|
||||
head.appendChild(css);
|
||||
}
|
||||
}
|
||||
if (oldCss && keepOldCss === false) {
|
||||
head.removeChild(oldCss);
|
||||
oldCss.parentNode.removeChild(oldCss);
|
||||
}
|
||||
|
||||
// Don't update the local store if the file wasn't modified
|
||||
if (lastModified && cache) {
|
||||
log('saving ' + href + ' to cache.');
|
||||
log('saving ' + href + ' to cache.', logLevel.info);
|
||||
try {
|
||||
cache.setItem(href, styles);
|
||||
cache.setItem(href + ':timestamp', lastModified);
|
||||
} catch(e) {
|
||||
//TODO - could do with adding more robust error handling
|
||||
log('failed to save');
|
||||
log('failed to save', logLevel.errors);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function xhr(url, type, callback, errback) {
|
||||
var xhr = getXMLHttpRequest();
|
||||
var async = isFileProtocol ? less.fileAsync : less.async;
|
||||
|
||||
if (typeof(xhr.overrideMimeType) === 'function') {
|
||||
xhr.overrideMimeType('text/css');
|
||||
}
|
||||
xhr.open('GET', url, async);
|
||||
xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
|
||||
xhr.send(null);
|
||||
|
||||
if (isFileProtocol && !less.fileAsync) {
|
||||
if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
|
||||
callback(xhr.responseText);
|
||||
} else {
|
||||
errback(xhr.status, url);
|
||||
}
|
||||
} else if (async) {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
handleResponse(xhr, callback, errback);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
handleResponse(xhr, callback, errback);
|
||||
}
|
||||
|
||||
function handleResponse(xhr, callback, errback) {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
callback(xhr.responseText,
|
||||
xhr.getResponseHeader("Last-Modified"));
|
||||
} else if (typeof(errback) === 'function') {
|
||||
errback(xhr.status, url);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function getXMLHttpRequest() {
|
||||
if (window.XMLHttpRequest) {
|
||||
return new(XMLHttpRequest);
|
||||
} else {
|
||||
try {
|
||||
return new(ActiveXObject)("MSXML2.XMLHTTP.3.0");
|
||||
} catch (e) {
|
||||
log("browser doesn't support AJAX.");
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function removeNode(node) {
|
||||
return node && node.parentNode.removeChild(node);
|
||||
}
|
||||
|
||||
function log(str) {
|
||||
if (less.env == 'development' && typeof(console) !== "undefined") { console.log('less: ' + str) }
|
||||
}
|
||||
|
||||
function error(e, rootHref) {
|
||||
function errorHTML(e, rootHref) {
|
||||
var id = 'less-error-message:' + extractId(rootHref || "");
|
||||
var template = '<li><label>{line}</label><pre class="{class}">{content}</pre></li>';
|
||||
var elem = document.createElement('div'), timer, content, error = [];
|
||||
var elem = document.createElement('div'), timer, content, errors = [];
|
||||
var filename = e.filename || rootHref;
|
||||
var filenameNoPath = filename.match(/([^\/]+(\?.*)?)$/)[1];
|
||||
|
||||
@@ -461,13 +167,13 @@ function error(e, rootHref) {
|
||||
elem.className = "less-error-message";
|
||||
|
||||
content = '<h3>' + (e.type || "Syntax") + "Error: " + (e.message || 'There is an error in your .less file') +
|
||||
'</h3>' + '<p>in <a href="' + filename + '">' + filenameNoPath + "</a> ";
|
||||
'</h3>' + '<p>in <a href="' + filename + '">' + filenameNoPath + "</a> ";
|
||||
|
||||
var errorline = function (e, i, classname) {
|
||||
if (e.extract[i] != undefined) {
|
||||
error.push(template.replace(/\{line\}/, (parseInt(e.line) || 0) + (i - 1))
|
||||
.replace(/\{class\}/, classname)
|
||||
.replace(/\{content\}/, e.extract[i]));
|
||||
if (e.extract[i] !== undefined) {
|
||||
errors.push(template.replace(/\{line\}/, (parseInt(e.line, 10) || 0) + (i - 1))
|
||||
.replace(/\{class\}/, classname)
|
||||
.replace(/\{content\}/, e.extract[i]));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -476,7 +182,7 @@ function error(e, rootHref) {
|
||||
errorline(e, 1, 'line');
|
||||
errorline(e, 2, '');
|
||||
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':</p>' +
|
||||
'<ul>' + error.join('') + '</ul>';
|
||||
'<ul>' + errors.join('') + '</ul>';
|
||||
} else if (e.stack) {
|
||||
content += '<br/>' + e.stack.split('\n').slice(1).join('<br/>');
|
||||
}
|
||||
@@ -485,40 +191,40 @@ function error(e, rootHref) {
|
||||
// CSS for error messages
|
||||
createCSS([
|
||||
'.less-error-message ul, .less-error-message li {',
|
||||
'list-style-type: none;',
|
||||
'margin-right: 15px;',
|
||||
'padding: 4px 0;',
|
||||
'margin: 0;',
|
||||
'list-style-type: none;',
|
||||
'margin-right: 15px;',
|
||||
'padding: 4px 0;',
|
||||
'margin: 0;',
|
||||
'}',
|
||||
'.less-error-message label {',
|
||||
'font-size: 12px;',
|
||||
'margin-right: 15px;',
|
||||
'padding: 4px 0;',
|
||||
'color: #cc7777;',
|
||||
'font-size: 12px;',
|
||||
'margin-right: 15px;',
|
||||
'padding: 4px 0;',
|
||||
'color: #cc7777;',
|
||||
'}',
|
||||
'.less-error-message pre {',
|
||||
'color: #dd6666;',
|
||||
'padding: 4px 0;',
|
||||
'margin: 0;',
|
||||
'display: inline-block;',
|
||||
'color: #dd6666;',
|
||||
'padding: 4px 0;',
|
||||
'margin: 0;',
|
||||
'display: inline-block;',
|
||||
'}',
|
||||
'.less-error-message pre.line {',
|
||||
'color: #ff0000;',
|
||||
'color: #ff0000;',
|
||||
'}',
|
||||
'.less-error-message h3 {',
|
||||
'font-size: 20px;',
|
||||
'font-weight: bold;',
|
||||
'padding: 15px 0 5px 0;',
|
||||
'margin: 0;',
|
||||
'font-size: 20px;',
|
||||
'font-weight: bold;',
|
||||
'padding: 15px 0 5px 0;',
|
||||
'margin: 0;',
|
||||
'}',
|
||||
'.less-error-message a {',
|
||||
'color: #10a',
|
||||
'color: #10a',
|
||||
'}',
|
||||
'.less-error-message .error {',
|
||||
'color: red;',
|
||||
'font-weight: bold;',
|
||||
'padding-bottom: 2px;',
|
||||
'border-bottom: 1px dashed red;',
|
||||
'color: red;',
|
||||
'font-weight: bold;',
|
||||
'padding-bottom: 2px;',
|
||||
'border-bottom: 1px dashed red;',
|
||||
'}'
|
||||
].join('\n'), { title: 'error-message' });
|
||||
|
||||
@@ -547,3 +253,414 @@ function error(e, rootHref) {
|
||||
}, 10);
|
||||
}
|
||||
}
|
||||
|
||||
function error(e, rootHref) {
|
||||
if (!less.errorReporting || less.errorReporting === "html") {
|
||||
errorHTML(e, rootHref);
|
||||
} else if (less.errorReporting === "console") {
|
||||
errorConsole(e, rootHref);
|
||||
} else if (typeof less.errorReporting === 'function') {
|
||||
less.errorReporting("add", e, rootHref);
|
||||
}
|
||||
}
|
||||
|
||||
function removeErrorHTML(path) {
|
||||
var node = document.getElementById('less-error-message:' + extractId(path));
|
||||
if (node) {
|
||||
node.parentNode.removeChild(node);
|
||||
}
|
||||
}
|
||||
|
||||
function removeErrorConsole(path) {
|
||||
//no action
|
||||
}
|
||||
|
||||
function removeError(path) {
|
||||
if (!less.errorReporting || less.errorReporting === "html") {
|
||||
removeErrorHTML(path);
|
||||
} else if (less.errorReporting === "console") {
|
||||
removeErrorConsole(path);
|
||||
} else if (typeof less.errorReporting === 'function') {
|
||||
less.errorReporting("remove", path);
|
||||
}
|
||||
}
|
||||
|
||||
function loadStyles(newVars) {
|
||||
var styles = document.getElementsByTagName('style'),
|
||||
style;
|
||||
for (var i = 0; i < styles.length; i++) {
|
||||
style = styles[i];
|
||||
if (style.type.match(typePattern)) {
|
||||
var env = new less.tree.parseEnv(less),
|
||||
lessText = style.innerHTML || '';
|
||||
env.filename = document.location.href.replace(/#.*$/, '');
|
||||
if (newVars) {
|
||||
env.useFileCache = true;
|
||||
lessText += "\n" + newVars;
|
||||
}
|
||||
|
||||
/*jshint loopfunc:true */
|
||||
// use closure to store current value of i
|
||||
var callback = (function(style) {
|
||||
return function (e, cssAST) {
|
||||
if (e) {
|
||||
return error(e, "inline");
|
||||
}
|
||||
var css = cssAST.toCSS(less);
|
||||
style.type = 'text/css';
|
||||
if (style.styleSheet) {
|
||||
style.styleSheet.cssText = css;
|
||||
} else {
|
||||
style.innerHTML = css;
|
||||
}
|
||||
};
|
||||
})(style);
|
||||
new(less.Parser)(env).parse(lessText, callback);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function extractUrlParts(url, baseUrl) {
|
||||
// urlParts[1] = protocol&hostname || /
|
||||
// urlParts[2] = / if path relative to host base
|
||||
// urlParts[3] = directories
|
||||
// urlParts[4] = filename
|
||||
// urlParts[5] = parameters
|
||||
|
||||
var urlPartsRegex = /^((?:[a-z-]+:)?\/+?(?:[^\/\?#]*\/)|([\/\\]))?((?:[^\/\\\?#]*[\/\\])*)([^\/\\\?#]*)([#\?].*)?$/i,
|
||||
urlParts = url.match(urlPartsRegex),
|
||||
returner = {}, directories = [], i, baseUrlParts;
|
||||
|
||||
if (!urlParts) {
|
||||
throw new Error("Could not parse sheet href - '"+url+"'");
|
||||
}
|
||||
|
||||
// Stylesheets in IE don't always return the full path
|
||||
if (!urlParts[1] || urlParts[2]) {
|
||||
baseUrlParts = baseUrl.match(urlPartsRegex);
|
||||
if (!baseUrlParts) {
|
||||
throw new Error("Could not parse page url - '"+baseUrl+"'");
|
||||
}
|
||||
urlParts[1] = urlParts[1] || baseUrlParts[1] || "";
|
||||
if (!urlParts[2]) {
|
||||
urlParts[3] = baseUrlParts[3] + urlParts[3];
|
||||
}
|
||||
}
|
||||
|
||||
if (urlParts[3]) {
|
||||
directories = urlParts[3].replace(/\\/g, "/").split("/");
|
||||
|
||||
// extract out . before .. so .. doesn't absorb a non-directory
|
||||
for(i = 0; i < directories.length; i++) {
|
||||
if (directories[i] === ".") {
|
||||
directories.splice(i, 1);
|
||||
i -= 1;
|
||||
}
|
||||
}
|
||||
|
||||
for(i = 0; i < directories.length; i++) {
|
||||
if (directories[i] === ".." && i > 0) {
|
||||
directories.splice(i-1, 2);
|
||||
i -= 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
returner.hostPart = urlParts[1];
|
||||
returner.directories = directories;
|
||||
returner.path = urlParts[1] + directories.join("/");
|
||||
returner.fileUrl = returner.path + (urlParts[4] || "");
|
||||
returner.url = returner.fileUrl + (urlParts[5] || "");
|
||||
return returner;
|
||||
}
|
||||
|
||||
function pathDiff(url, baseUrl) {
|
||||
// diff between two paths to create a relative path
|
||||
|
||||
var urlParts = extractUrlParts(url),
|
||||
baseUrlParts = extractUrlParts(baseUrl),
|
||||
i, max, urlDirectories, baseUrlDirectories, diff = "";
|
||||
if (urlParts.hostPart !== baseUrlParts.hostPart) {
|
||||
return "";
|
||||
}
|
||||
max = Math.max(baseUrlParts.directories.length, urlParts.directories.length);
|
||||
for(i = 0; i < max; i++) {
|
||||
if (baseUrlParts.directories[i] !== urlParts.directories[i]) { break; }
|
||||
}
|
||||
baseUrlDirectories = baseUrlParts.directories.slice(i);
|
||||
urlDirectories = urlParts.directories.slice(i);
|
||||
for(i = 0; i < baseUrlDirectories.length-1; i++) {
|
||||
diff += "../";
|
||||
}
|
||||
for(i = 0; i < urlDirectories.length-1; i++) {
|
||||
diff += urlDirectories[i] + "/";
|
||||
}
|
||||
return diff;
|
||||
}
|
||||
|
||||
function getXMLHttpRequest() {
|
||||
if (window.XMLHttpRequest) {
|
||||
return new XMLHttpRequest();
|
||||
} else {
|
||||
try {
|
||||
/*global ActiveXObject */
|
||||
return new ActiveXObject("MSXML2.XMLHTTP.3.0");
|
||||
} catch (e) {
|
||||
log("browser doesn't support AJAX.", logLevel.errors);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function doXHR(url, type, callback, errback) {
|
||||
var xhr = getXMLHttpRequest();
|
||||
var async = isFileProtocol ? less.fileAsync : less.async;
|
||||
|
||||
if (typeof(xhr.overrideMimeType) === 'function') {
|
||||
xhr.overrideMimeType('text/css');
|
||||
}
|
||||
log("XHR: Getting '" + url + "'", logLevel.info);
|
||||
xhr.open('GET', url, async);
|
||||
xhr.setRequestHeader('Accept', type || 'text/x-less, text/css; q=0.9, */*; q=0.5');
|
||||
xhr.send(null);
|
||||
|
||||
function handleResponse(xhr, callback, errback) {
|
||||
if (xhr.status >= 200 && xhr.status < 300) {
|
||||
callback(xhr.responseText,
|
||||
xhr.getResponseHeader("Last-Modified"));
|
||||
} else if (typeof(errback) === 'function') {
|
||||
errback(xhr.status, url);
|
||||
}
|
||||
}
|
||||
|
||||
if (isFileProtocol && !less.fileAsync) {
|
||||
if (xhr.status === 0 || (xhr.status >= 200 && xhr.status < 300)) {
|
||||
callback(xhr.responseText);
|
||||
} else {
|
||||
errback(xhr.status, url);
|
||||
}
|
||||
} else if (async) {
|
||||
xhr.onreadystatechange = function () {
|
||||
if (xhr.readyState == 4) {
|
||||
handleResponse(xhr, callback, errback);
|
||||
}
|
||||
};
|
||||
} else {
|
||||
handleResponse(xhr, callback, errback);
|
||||
}
|
||||
}
|
||||
|
||||
function loadFile(originalHref, currentFileInfo, callback, env, newVars) {
|
||||
|
||||
if (currentFileInfo && currentFileInfo.currentDirectory && !/^([a-z-]+:)?\//.test(originalHref)) {
|
||||
originalHref = currentFileInfo.currentDirectory + originalHref;
|
||||
}
|
||||
|
||||
// sheet may be set to the stylesheet for the initial load or a collection of properties including
|
||||
// some env variables for imports
|
||||
var hrefParts = extractUrlParts(originalHref, window.location.href);
|
||||
var href = hrefParts.url;
|
||||
var newFileInfo = {
|
||||
currentDirectory: hrefParts.path,
|
||||
filename: href
|
||||
};
|
||||
|
||||
if (currentFileInfo) {
|
||||
newFileInfo.entryPath = currentFileInfo.entryPath;
|
||||
newFileInfo.rootpath = currentFileInfo.rootpath;
|
||||
newFileInfo.rootFilename = currentFileInfo.rootFilename;
|
||||
newFileInfo.relativeUrls = currentFileInfo.relativeUrls;
|
||||
} else {
|
||||
newFileInfo.entryPath = hrefParts.path;
|
||||
newFileInfo.rootpath = less.rootpath || hrefParts.path;
|
||||
newFileInfo.rootFilename = href;
|
||||
newFileInfo.relativeUrls = env.relativeUrls;
|
||||
}
|
||||
|
||||
if (newFileInfo.relativeUrls) {
|
||||
if (env.rootpath) {
|
||||
newFileInfo.rootpath = extractUrlParts(env.rootpath + pathDiff(hrefParts.path, newFileInfo.entryPath)).path;
|
||||
} else {
|
||||
newFileInfo.rootpath = hrefParts.path;
|
||||
}
|
||||
}
|
||||
|
||||
if (env.useFileCache && fileCache[href]) {
|
||||
try {
|
||||
var lessText = fileCache[href];
|
||||
if (newVars) {
|
||||
lessText += "\n" + newVars;
|
||||
}
|
||||
callback(null, lessText, href, newFileInfo, { lastModified: new Date() });
|
||||
} catch (e) {
|
||||
callback(e, null, href);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
doXHR(href, env.mime, function (data, lastModified) {
|
||||
// per file cache
|
||||
fileCache[href] = data;
|
||||
|
||||
// Use remote copy (re-parse)
|
||||
try {
|
||||
callback(null, data, href, newFileInfo, { lastModified: lastModified });
|
||||
} catch (e) {
|
||||
callback(e, null, href);
|
||||
}
|
||||
}, function (status, url) {
|
||||
callback({ type: 'File', message: "'" + url + "' wasn't found (" + status + ")" }, null, href);
|
||||
});
|
||||
}
|
||||
|
||||
function loadStyleSheet(sheet, callback, reload, remaining, newVars) {
|
||||
|
||||
var env = new less.tree.parseEnv(less);
|
||||
env.mime = sheet.type;
|
||||
|
||||
if (newVars) {
|
||||
env.useFileCache = true;
|
||||
}
|
||||
|
||||
loadFile(sheet.href, null, function(e, data, path, newFileInfo, webInfo) {
|
||||
|
||||
if (webInfo) {
|
||||
webInfo.remaining = remaining;
|
||||
|
||||
var css = cache && cache.getItem(path),
|
||||
timestamp = cache && cache.getItem(path + ':timestamp');
|
||||
|
||||
if (!reload && timestamp && webInfo.lastModified &&
|
||||
(new(Date)(webInfo.lastModified).valueOf() ===
|
||||
new(Date)(timestamp).valueOf())) {
|
||||
// Use local copy
|
||||
createCSS(css, sheet);
|
||||
webInfo.local = true;
|
||||
callback(null, null, data, sheet, webInfo, path);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
//TODO add tests around how this behaves when reloading
|
||||
removeError(path);
|
||||
|
||||
if (data) {
|
||||
env.currentFileInfo = newFileInfo;
|
||||
new(less.Parser)(env).parse(data, function (e, root) {
|
||||
if (e) { return callback(e, null, null, sheet); }
|
||||
try {
|
||||
callback(e, root, data, sheet, webInfo, path);
|
||||
} catch (e) {
|
||||
callback(e, null, null, sheet);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
callback(e, null, null, sheet, webInfo, path);
|
||||
}
|
||||
}, env, newVars);
|
||||
}
|
||||
|
||||
function loadStyleSheets(callback, reload, newVars) {
|
||||
for (var i = 0; i < less.sheets.length; i++) {
|
||||
loadStyleSheet(less.sheets[i], callback, reload, less.sheets.length - (i + 1), newVars);
|
||||
}
|
||||
}
|
||||
|
||||
function initRunningMode(){
|
||||
if (less.env === 'development') {
|
||||
less.optimization = 0;
|
||||
less.watchTimer = setInterval(function () {
|
||||
if (less.watchMode) {
|
||||
loadStyleSheets(function (e, root, _, sheet, env) {
|
||||
if (e) {
|
||||
error(e, sheet.href);
|
||||
} else if (root) {
|
||||
createCSS(root.toCSS(less), sheet, env.lastModified);
|
||||
}
|
||||
});
|
||||
}
|
||||
}, less.poll);
|
||||
} else {
|
||||
less.optimization = 3;
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// Watch mode
|
||||
//
|
||||
less.watch = function () {
|
||||
if (!less.watchMode ){
|
||||
less.env = 'development';
|
||||
initRunningMode();
|
||||
}
|
||||
return this.watchMode = true;
|
||||
};
|
||||
|
||||
less.unwatch = function () {clearInterval(less.watchTimer); return this.watchMode = false; };
|
||||
|
||||
if (/!watch/.test(location.hash)) {
|
||||
less.watch();
|
||||
}
|
||||
|
||||
if (less.env != 'development') {
|
||||
try {
|
||||
cache = (typeof(window.localStorage) === 'undefined') ? null : window.localStorage;
|
||||
} catch (_) {}
|
||||
}
|
||||
|
||||
//
|
||||
// Get all <link> tags with the 'rel' attribute set to "stylesheet/less"
|
||||
//
|
||||
var links = document.getElementsByTagName('link');
|
||||
|
||||
less.sheets = [];
|
||||
|
||||
for (var i = 0; i < links.length; i++) {
|
||||
if (links[i].rel === 'stylesheet/less' || (links[i].rel.match(/stylesheet/) &&
|
||||
(links[i].type.match(typePattern)))) {
|
||||
less.sheets.push(links[i]);
|
||||
}
|
||||
}
|
||||
|
||||
//
|
||||
// With this function, it's possible to alter variables and re-render
|
||||
// CSS without reloading less-files
|
||||
//
|
||||
less.modifyVars = function(record) {
|
||||
var newVars = "";
|
||||
for (var name in record) {
|
||||
newVars += ((name.slice(0,1) === '@')? '' : '@') + name +': '+
|
||||
((record[name].slice(-1) === ';')? record[name] : record[name] +';');
|
||||
}
|
||||
less.refresh(false, newVars);
|
||||
};
|
||||
|
||||
less.refresh = function (reload, newVars) {
|
||||
var startTime, endTime;
|
||||
startTime = endTime = new Date();
|
||||
|
||||
loadStyleSheets(function (e, root, _, sheet, env) {
|
||||
if (e) {
|
||||
return error(e, sheet.href);
|
||||
}
|
||||
if (env.local) {
|
||||
log("loading " + sheet.href + " from cache.", logLevel.info);
|
||||
} else {
|
||||
log("parsed " + sheet.href + " successfully.", logLevel.info);
|
||||
createCSS(root.toCSS(less), sheet, env.lastModified);
|
||||
}
|
||||
log("css for " + sheet.href + " generated in " + (new Date() - endTime) + 'ms', logLevel.info);
|
||||
if (env.remaining === 0) {
|
||||
log("css generated in " + (new Date() - startTime) + 'ms', logLevel.info);
|
||||
}
|
||||
endTime = new Date();
|
||||
}, reload, newVars);
|
||||
|
||||
loadStyles(newVars);
|
||||
};
|
||||
|
||||
less.refreshStyles = loadStyles;
|
||||
|
||||
less.Parser.fileLoader = loadFile;
|
||||
|
||||
less.refresh(less.env === 'development');
|
||||
|
||||
@@ -6,12 +6,15 @@
|
||||
'files', // list of files that have been imported, used for import-once
|
||||
'contents', // browser-only, contents of all the files
|
||||
'relativeUrls', // option - whether to adjust URL's to be relative
|
||||
'rootpath', // option - rootpath to append to URL's
|
||||
'strictImports', // option -
|
||||
'dumpLineNumbers', // option - whether to dump line numbers
|
||||
'compress', // option - whether to compress
|
||||
'processImports', // option - whether to process imports. if false then imports will not be imported
|
||||
'syncImport', // option - whether to import synchronously
|
||||
'javascriptEnabled',// option - whether JavaScript is enabled. if undefined, defaults to true
|
||||
'mime', // browser only - mime type for sheet import
|
||||
'useFileCache', // browser only - whether to use the per file session cache
|
||||
'currentFileInfo' // information about the current file - for error reporting and importing and making urls relative etc.
|
||||
];
|
||||
|
||||
@@ -21,7 +24,8 @@
|
||||
// 'rootpath' - path to append to normal URLs for this node
|
||||
// 'currentDirectory' - path to the current file, absolute
|
||||
// 'rootFilename' - filename of the base file
|
||||
// 'entryPath' = absolute path to the entry file
|
||||
// 'entryPath' - absolute path to the entry file
|
||||
// 'reference' - whether the file should not be output and only output parts that are referenced
|
||||
|
||||
tree.parseEnv = function(options) {
|
||||
copyFromOriginal(options, this, parseCopyProperties);
|
||||
@@ -46,14 +50,6 @@
|
||||
}
|
||||
};
|
||||
|
||||
tree.parseEnv.prototype.toSheet = function (path) {
|
||||
var env = new tree.parseEnv(this);
|
||||
env.href = path;
|
||||
//env.title = path;
|
||||
env.type = this.mime;
|
||||
return env;
|
||||
};
|
||||
|
||||
var evalCopyProperties = [
|
||||
'silent', // whether to swallow errors and warnings
|
||||
'verbose', // whether to log more activity
|
||||
@@ -61,7 +57,9 @@
|
||||
'yuicompress', // whether to compress with the outside tool yui compressor
|
||||
'ieCompat', // whether to enforce IE compatibility (IE8 data-uri)
|
||||
'strictMath', // whether math has to be within parenthesis
|
||||
'strictUnits' // whether units need to evaluate correctly
|
||||
'strictUnits', // whether units need to evaluate correctly
|
||||
'cleancss', // whether to compress with clean-css
|
||||
'sourceMap' // whether to output a source map
|
||||
];
|
||||
|
||||
tree.evalEnv = function(options, frames) {
|
||||
@@ -89,6 +87,33 @@
|
||||
return !/^(?:[a-z-]+:|\/)/.test(path);
|
||||
};
|
||||
|
||||
tree.evalEnv.prototype.normalizePath = function( path ) {
|
||||
var
|
||||
segments = path.split("/").reverse(),
|
||||
segment;
|
||||
|
||||
path = [];
|
||||
while (segments.length !== 0 ) {
|
||||
segment = segments.pop();
|
||||
switch( segment ) {
|
||||
case ".":
|
||||
break;
|
||||
case "..":
|
||||
if ((path.length === 0) || (path[path.length - 1] === "..")) {
|
||||
path.push( segment );
|
||||
} else {
|
||||
path.pop();
|
||||
}
|
||||
break;
|
||||
default:
|
||||
path.push( segment );
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
return path.join("/");
|
||||
};
|
||||
|
||||
//todo - do the same for the toCSS env
|
||||
//tree.toCSSEnv = function (options) {
|
||||
//};
|
||||
@@ -101,5 +126,6 @@
|
||||
destination[propertiesToCopy[i]] = original[propertiesToCopy[i]];
|
||||
}
|
||||
}
|
||||
}
|
||||
})(require('./tree'));
|
||||
};
|
||||
|
||||
})(require('./tree'));
|
||||
|
||||
@@ -1,4 +1,6 @@
|
||||
(function (tree) {
|
||||
/*jshint loopfunc:true */
|
||||
|
||||
tree.extendFinderVisitor = function() {
|
||||
this._visitor = new tree.visitor(this);
|
||||
this.contexts = [];
|
||||
@@ -246,7 +248,7 @@
|
||||
haystackElement = hackstackSelector.elements[hackstackElementIndex];
|
||||
|
||||
// if we allow elements before our match we can add a potential match every time. otherwise only at the first element.
|
||||
if (extend.allowBefore || (haystackSelectorIndex == 0 && hackstackElementIndex == 0)) {
|
||||
if (extend.allowBefore || (haystackSelectorIndex === 0 && hackstackElementIndex === 0)) {
|
||||
potentialMatches.push({pathIndex: haystackSelectorIndex, index: hackstackElementIndex, matched: 0, initialCombinator: haystackElement.combinator});
|
||||
}
|
||||
|
||||
@@ -257,7 +259,7 @@
|
||||
// then each selector in haystackSelectorPath has a space before it added in the toCSS phase. so we need to work out
|
||||
// what the resulting combinator will be
|
||||
targetCombinator = haystackElement.combinator.value;
|
||||
if (targetCombinator == '' && hackstackElementIndex === 0) {
|
||||
if (targetCombinator === '' && hackstackElementIndex === 0) {
|
||||
targetCombinator = ' ';
|
||||
}
|
||||
|
||||
@@ -325,7 +327,8 @@
|
||||
matchIndex,
|
||||
selector,
|
||||
firstElement,
|
||||
match;
|
||||
match,
|
||||
newElements;
|
||||
|
||||
for (matchIndex = 0; matchIndex < matches.length; matchIndex++) {
|
||||
match = matches[matchIndex];
|
||||
@@ -333,7 +336,8 @@
|
||||
firstElement = new tree.Element(
|
||||
match.initialCombinator,
|
||||
replacementSelector.elements[0].value,
|
||||
replacementSelector.elements[0].index
|
||||
replacementSelector.elements[0].index,
|
||||
replacementSelector.elements[0].currentFileInfo
|
||||
);
|
||||
|
||||
if (match.pathIndex > currentSelectorPathIndex && currentSelectorPathElementIndex > 0) {
|
||||
@@ -342,17 +346,24 @@
|
||||
currentSelectorPathIndex++;
|
||||
}
|
||||
|
||||
path = path.concat(selectorPath.slice(currentSelectorPathIndex, match.pathIndex));
|
||||
newElements = selector.elements
|
||||
.slice(currentSelectorPathElementIndex, match.index)
|
||||
.concat([firstElement])
|
||||
.concat(replacementSelector.elements.slice(1));
|
||||
|
||||
path.push(new tree.Selector(
|
||||
selector.elements
|
||||
.slice(currentSelectorPathElementIndex, match.index)
|
||||
.concat([firstElement])
|
||||
.concat(replacementSelector.elements.slice(1))
|
||||
));
|
||||
if (currentSelectorPathIndex === match.pathIndex && matchIndex > 0) {
|
||||
path[path.length - 1].elements =
|
||||
path[path.length - 1].elements.concat(newElements);
|
||||
} else {
|
||||
path = path.concat(selectorPath.slice(currentSelectorPathIndex, match.pathIndex));
|
||||
|
||||
path.push(new tree.Selector(
|
||||
newElements
|
||||
));
|
||||
}
|
||||
currentSelectorPathIndex = match.endPathIndex;
|
||||
currentSelectorPathElementIndex = match.endPathElementIndex;
|
||||
if (currentSelectorPathElementIndex >= selector.elements.length) {
|
||||
if (currentSelectorPathElementIndex >= selectorPath[currentSelectorPathIndex].elements.length) {
|
||||
currentSelectorPathElementIndex = 0;
|
||||
currentSelectorPathIndex++;
|
||||
}
|
||||
@@ -388,4 +399,4 @@
|
||||
}
|
||||
};
|
||||
|
||||
})(require('./tree'));
|
||||
})(require('./tree'));
|
||||
|
||||
@@ -13,6 +13,14 @@ tree.functions = {
|
||||
return this.hsla(h, s, l, 1.0);
|
||||
},
|
||||
hsla: function (h, s, l, a) {
|
||||
function hue(h) {
|
||||
h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
|
||||
if (h * 6 < 1) { return m1 + (m2 - m1) * h * 6; }
|
||||
else if (h * 2 < 1) { return m2; }
|
||||
else if (h * 3 < 2) { return m1 + (m2 - m1) * (2/3 - h) * 6; }
|
||||
else { return m1; }
|
||||
}
|
||||
|
||||
h = (number(h) % 360) / 360;
|
||||
s = clamp(number(s)); l = clamp(number(l)); a = clamp(number(a));
|
||||
|
||||
@@ -23,14 +31,6 @@ tree.functions = {
|
||||
hue(h) * 255,
|
||||
hue(h - 1/3) * 255,
|
||||
a);
|
||||
|
||||
function hue(h) {
|
||||
h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
|
||||
if (h * 6 < 1) return m1 + (m2 - m1) * h * 6;
|
||||
else if (h * 2 < 1) return m2;
|
||||
else if (h * 3 < 2) return m1 + (m2 - m1) * (2/3 - h) * 6;
|
||||
else return m1;
|
||||
}
|
||||
},
|
||||
|
||||
hsv: function(h, s, v) {
|
||||
@@ -96,6 +96,11 @@ tree.functions = {
|
||||
return new(tree.Dimension)(Math.round(color.luma() * color.alpha * 100), '%');
|
||||
},
|
||||
saturate: function (color, amount) {
|
||||
// filter: saturate(3.2);
|
||||
// should be kept as is, so check for color
|
||||
if (!color.rgb) {
|
||||
return null;
|
||||
}
|
||||
var hsl = color.toHSL();
|
||||
|
||||
hsl.s += amount.value / 100;
|
||||
@@ -218,6 +223,7 @@ tree.functions = {
|
||||
str = quoted.value;
|
||||
|
||||
for (var i = 0; i < args.length; i++) {
|
||||
/*jshint loopfunc:true */
|
||||
str = str.replace(/%[sda]/i, function(token) {
|
||||
var value = token.match(/s/i) ? args[i].value : args[i].toCSS();
|
||||
return token.match(/[A-Z]$/) ? encodeURIComponent(value) : value;
|
||||
@@ -254,6 +260,7 @@ tree.functions = {
|
||||
},
|
||||
_math: function (fn, unit, n) {
|
||||
if (n instanceof tree.Dimension) {
|
||||
/*jshint eqnull:true */
|
||||
return new(tree.Dimension)(fn(parseFloat(n.value)), unit == null ? n.unit : unit);
|
||||
} else if (typeof(n) === 'number') {
|
||||
return fn(n);
|
||||
@@ -261,6 +268,49 @@ tree.functions = {
|
||||
throw { type: "Argument", message: "argument must be a number" };
|
||||
}
|
||||
},
|
||||
_minmax: function (isMin, args) {
|
||||
args = Array.prototype.slice.call(args);
|
||||
switch(args.length) {
|
||||
case 0: throw { type: "Argument", message: "one or more arguments required" };
|
||||
case 1: return args[0];
|
||||
}
|
||||
var i, j, current, currentUnified, referenceUnified, unit,
|
||||
order = [], // elems only contains original argument values.
|
||||
values = {}; // key is the unit.toString() for unified tree.Dimension values,
|
||||
// value is the index into the order array.
|
||||
for (i = 0; i < args.length; i++) {
|
||||
current = args[i];
|
||||
if (!(current instanceof tree.Dimension)) {
|
||||
order.push(current);
|
||||
continue;
|
||||
}
|
||||
currentUnified = current.unify();
|
||||
unit = currentUnified.unit.toString();
|
||||
j = values[unit];
|
||||
if (j === undefined) {
|
||||
values[unit] = order.length;
|
||||
order.push(current);
|
||||
continue;
|
||||
}
|
||||
referenceUnified = order[j].unify();
|
||||
if ( isMin && currentUnified.value < referenceUnified.value ||
|
||||
!isMin && currentUnified.value > referenceUnified.value) {
|
||||
order[j] = current;
|
||||
}
|
||||
}
|
||||
if (order.length == 1) {
|
||||
return order[0];
|
||||
}
|
||||
args = order.map(function (a) { return a.toCSS(this.env); })
|
||||
.join(this.env.compress ? "," : ", ");
|
||||
return new(tree.Anonymous)((isMin ? "min" : "max") + "(" + args + ")");
|
||||
},
|
||||
min: function () {
|
||||
return this._minmax(true, arguments);
|
||||
},
|
||||
max: function () {
|
||||
return this._minmax(false, arguments);
|
||||
},
|
||||
argb: function (color) {
|
||||
return new(tree.Anonymous)(color.toARGB());
|
||||
|
||||
@@ -415,10 +465,10 @@ tree.functions = {
|
||||
// use base 64 unless it's an ASCII or UTF-8 format
|
||||
var charset = mime.charsets.lookup(mimetype);
|
||||
useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
|
||||
if (useBase64) mimetype += ';base64';
|
||||
if (useBase64) { mimetype += ';base64'; }
|
||||
}
|
||||
else {
|
||||
useBase64 = /;base64$/.test(mimetype)
|
||||
useBase64 = /;base64$/.test(mimetype);
|
||||
}
|
||||
|
||||
var buf = fs.readFileSync(filePath);
|
||||
@@ -446,6 +496,83 @@ tree.functions = {
|
||||
|
||||
var uri = "'data:" + mimetype + ',' + buf + "'";
|
||||
return new(tree.URL)(new(tree.Anonymous)(uri));
|
||||
},
|
||||
|
||||
"svg-gradient": function(direction) {
|
||||
|
||||
function throwArgumentDescriptor() {
|
||||
throw { type: "Argument", message: "svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position]" };
|
||||
}
|
||||
|
||||
if (arguments.length < 3) {
|
||||
throwArgumentDescriptor();
|
||||
}
|
||||
var stops = Array.prototype.slice.call(arguments, 1),
|
||||
gradientDirectionSvg,
|
||||
gradientType = "linear",
|
||||
rectangleDimension = 'x="0" y="0" width="1" height="1"',
|
||||
useBase64 = true,
|
||||
renderEnv = {compress: false},
|
||||
returner,
|
||||
directionValue = direction.toCSS(renderEnv),
|
||||
i, color, position, positionValue, alpha;
|
||||
|
||||
switch (directionValue) {
|
||||
case "to bottom":
|
||||
gradientDirectionSvg = 'x1="0%" y1="0%" x2="0%" y2="100%"';
|
||||
break;
|
||||
case "to right":
|
||||
gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="0%"';
|
||||
break;
|
||||
case "to bottom right":
|
||||
gradientDirectionSvg = 'x1="0%" y1="0%" x2="100%" y2="100%"';
|
||||
break;
|
||||
case "to top right":
|
||||
gradientDirectionSvg = 'x1="0%" y1="100%" x2="100%" y2="0%"';
|
||||
break;
|
||||
case "ellipse":
|
||||
case "ellipse at center":
|
||||
gradientType = "radial";
|
||||
gradientDirectionSvg = 'cx="50%" cy="50%" r="75%"';
|
||||
rectangleDimension = 'x="-50" y="-50" width="101" height="101"';
|
||||
break;
|
||||
default:
|
||||
throw { type: "Argument", message: "svg-gradient direction must be 'to bottom', 'to right', 'to bottom right', 'to top right' or 'ellipse at center'" };
|
||||
}
|
||||
returner = '<?xml version="1.0" ?>' +
|
||||
'<svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none">' +
|
||||
'<' + gradientType + 'Gradient id="gradient" gradientUnits="userSpaceOnUse" ' + gradientDirectionSvg + '>';
|
||||
|
||||
for (i = 0; i < stops.length; i+= 1) {
|
||||
if (stops[i].value) {
|
||||
color = stops[i].value[0];
|
||||
position = stops[i].value[1];
|
||||
} else {
|
||||
color = stops[i];
|
||||
position = undefined;
|
||||
}
|
||||
|
||||
if (!(color instanceof tree.Color) || (!((i === 0 || i+1 === stops.length) && position === undefined) && !(position instanceof tree.Dimension))) {
|
||||
throwArgumentDescriptor();
|
||||
}
|
||||
positionValue = position ? position.toCSS(renderEnv) : i === 0 ? "0%" : "100%";
|
||||
alpha = color.alpha;
|
||||
returner += '<stop offset="' + positionValue + '" stop-color="' + color.toRGB() + '"' + (alpha < 1 ? ' stop-opacity="' + alpha + '"' : '') + '/>';
|
||||
}
|
||||
returner += '</' + gradientType + 'Gradient>' +
|
||||
'<rect ' + rectangleDimension + ' fill="url(#gradient)" /></svg>';
|
||||
|
||||
if (useBase64) {
|
||||
// only works in node, needs interface to what is supported in environment
|
||||
try {
|
||||
returner = new Buffer(returner).toString('base64');
|
||||
} catch(e) {
|
||||
useBase64 = false;
|
||||
}
|
||||
}
|
||||
|
||||
returner = "'data:image/svg+xml" + (useBase64 ? ";base64" : "") + "," + returner + "'";
|
||||
return new(tree.URL)(new(tree.Anonymous)(returner));
|
||||
}
|
||||
};
|
||||
|
||||
@@ -482,6 +609,7 @@ var mathFunctions = [{name:"ceil"}, {name:"floor"}, {name: "sqrt"}, {name:"abs"}
|
||||
{name:"atan", unit: "rad"}, {name:"asin", unit: "rad"}, {name:"acos", unit: "rad"}],
|
||||
createMathFunction = function(name, unit) {
|
||||
return function(n) {
|
||||
/*jshint eqnull:true */
|
||||
if (unit != null) {
|
||||
n = n.unify();
|
||||
}
|
||||
|
||||
@@ -27,9 +27,10 @@
|
||||
},
|
||||
visitImport: function (importNode, visitArgs) {
|
||||
var importVisitor = this,
|
||||
evaldImportNode;
|
||||
evaldImportNode,
|
||||
inlineCSS = importNode.options.inline;
|
||||
|
||||
if (!importNode.css) {
|
||||
if (!importNode.css || inlineCSS) {
|
||||
|
||||
try {
|
||||
evaldImportNode = importNode.evalForImport(this.env);
|
||||
@@ -41,11 +42,12 @@
|
||||
importNode.error = e;
|
||||
}
|
||||
|
||||
if (evaldImportNode && !evaldImportNode.css) {
|
||||
if (evaldImportNode && (!evaldImportNode.css || inlineCSS)) {
|
||||
importNode = evaldImportNode;
|
||||
this.importCount++;
|
||||
var env = new tree.evalEnv(this.env, this.env.frames.slice(0));
|
||||
this._importer.push(importNode.getPath(), importNode.currentFileInfo, function (e, root, imported) {
|
||||
|
||||
this._importer.push(importNode.getPath(), importNode.currentFileInfo, importNode.options, function (e, root, imported) {
|
||||
if (e && !e.filename) { e.index = importNode.index; e.filename = importNode.currentFileInfo.filename; }
|
||||
if (imported && !importNode.options.multiple) { importNode.skip = imported; }
|
||||
|
||||
@@ -59,11 +61,14 @@
|
||||
|
||||
if (root) {
|
||||
importNode.root = root;
|
||||
new(tree.importVisitor)(importVisitor._importer, subFinish, env)
|
||||
.run(root);
|
||||
} else {
|
||||
subFinish();
|
||||
if (!inlineCSS && !importNode.skip) {
|
||||
new(tree.importVisitor)(importVisitor._importer, subFinish, env)
|
||||
.run(root);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
subFinish();
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,9 +5,8 @@ var path = require('path'),
|
||||
fs = require('fs');
|
||||
|
||||
var less = {
|
||||
version: [1, 4, 2],
|
||||
version: [1, 5, "0-b1"],
|
||||
Parser: require('./parser').Parser,
|
||||
importer: require('./parser').importer,
|
||||
tree: require('./tree'),
|
||||
render: function (input, options, callback) {
|
||||
options = options || {};
|
||||
@@ -21,15 +20,17 @@ var less = {
|
||||
|
||||
if (callback) {
|
||||
parser.parse(input, function (e, root) {
|
||||
callback(e, root && root.toCSS && root.toCSS(options));
|
||||
try { callback(e, root && root.toCSS && root.toCSS(options)); }
|
||||
catch (err) { callback(err); }
|
||||
});
|
||||
} else {
|
||||
ee = new(require('events').EventEmitter);
|
||||
ee = new (require('events').EventEmitter)();
|
||||
|
||||
process.nextTick(function () {
|
||||
parser.parse(input, function (e, root) {
|
||||
if (e) { ee.emit('error', e) }
|
||||
else { ee.emit('success', root.toCSS(options)) }
|
||||
if (e) { return ee.emit('error', e); }
|
||||
try { ee.emit('success', root.toCSS(options)); }
|
||||
catch (err) { ee.emit('error', err); }
|
||||
});
|
||||
});
|
||||
return ee;
|
||||
@@ -41,10 +42,10 @@ var less = {
|
||||
var message = "";
|
||||
var extract = ctx.extract;
|
||||
var error = [];
|
||||
var stylize = options.color ? require('./lessc_helper').stylize : function (str) { return str };
|
||||
var stylize = options.color ? require('./lessc_helper').stylize : function (str) { return str; };
|
||||
|
||||
// only output a stack if it isn't a less error
|
||||
if (ctx.stack && !ctx.type) { return stylize(ctx.stack, 'red') }
|
||||
if (ctx.stack && !ctx.type) { return stylize(ctx.stack, 'red'); }
|
||||
|
||||
if (!ctx.hasOwnProperty('index') || !extract) {
|
||||
return ctx.stack || ctx.message;
|
||||
@@ -84,7 +85,7 @@ var less = {
|
||||
},
|
||||
writeError: function (ctx, options) {
|
||||
options = options || {};
|
||||
if (options.silent) { return }
|
||||
if (options.silent) { return; }
|
||||
sys.error(less.formatError(ctx, options));
|
||||
}
|
||||
};
|
||||
@@ -103,7 +104,7 @@ var less = {
|
||||
|
||||
var isUrlRe = /^(?:https?:)?\/\//i;
|
||||
|
||||
less.Parser.importer = function (file, currentFileInfo, callback, env) {
|
||||
less.Parser.fileLoader = function (file, currentFileInfo, callback, env) {
|
||||
var pathname, dirname, data,
|
||||
newFileInfo = {
|
||||
relativeUrls: env.relativeUrls,
|
||||
@@ -112,12 +113,7 @@ less.Parser.importer = function (file, currentFileInfo, callback, env) {
|
||||
rootFilename: currentFileInfo.rootFilename
|
||||
};
|
||||
|
||||
function parseFile(e, data) {
|
||||
if (e) { return callback(e); }
|
||||
|
||||
env = new less.tree.parseEnv(env);
|
||||
env.processImports = false;
|
||||
|
||||
function handleDataAndCallCallback(data) {
|
||||
var j = file.lastIndexOf('/');
|
||||
|
||||
// Pass on an updated rootpath if path of imported file is relative and file
|
||||
@@ -135,12 +131,8 @@ less.Parser.importer = function (file, currentFileInfo, callback, env) {
|
||||
newFileInfo.currentDirectory = pathname.replace(/[^\\\/]*$/, "");
|
||||
newFileInfo.filename = pathname;
|
||||
|
||||
env.contents[pathname] = data; // Updating top importing parser content cache.
|
||||
env.currentFileInfo = newFileInfo;
|
||||
new(less.Parser)(env).parse(data, function (e, root) {
|
||||
callback(e, root, pathname);
|
||||
});
|
||||
};
|
||||
callback(null, data, pathname, newFileInfo);
|
||||
}
|
||||
|
||||
var isUrl = isUrlRe.test( file );
|
||||
if (isUrl || isUrlRe.test(currentFileInfo.currentDirectory)) {
|
||||
@@ -154,12 +146,7 @@ less.Parser.importer = function (file, currentFileInfo, callback, env) {
|
||||
}
|
||||
|
||||
var urlStr = isUrl ? file : url.resolve(currentFileInfo.currentDirectory, file),
|
||||
urlObj = url.parse(urlStr),
|
||||
req = {
|
||||
host: urlObj.hostname,
|
||||
port: urlObj.port || 80,
|
||||
path: urlObj.pathname + (urlObj.search||'')
|
||||
};
|
||||
urlObj = url.parse(urlStr);
|
||||
|
||||
request.get(urlStr, function (error, res, body) {
|
||||
if (res.statusCode === 404) {
|
||||
@@ -174,7 +161,7 @@ less.Parser.importer = function (file, currentFileInfo, callback, env) {
|
||||
}
|
||||
pathname = urlStr;
|
||||
dirname = urlObj.protocol +'//'+ urlObj.host + urlObj.pathname.replace(/[^\/]*$/, '');
|
||||
parseFile(null, body);
|
||||
handleDataAndCallCallback(body);
|
||||
});
|
||||
} else {
|
||||
|
||||
@@ -202,15 +189,18 @@ less.Parser.importer = function (file, currentFileInfo, callback, env) {
|
||||
if (env.syncImport) {
|
||||
try {
|
||||
data = fs.readFileSync(pathname, 'utf-8');
|
||||
parseFile(null, data);
|
||||
handleDataAndCallCallback(data);
|
||||
} catch (e) {
|
||||
parseFile(e);
|
||||
callback(e);
|
||||
}
|
||||
} else {
|
||||
fs.readFile(pathname, 'utf-8', parseFile);
|
||||
fs.readFile(pathname, 'utf-8', function(e, data) {
|
||||
if (e) { callback(e); }
|
||||
handleDataAndCallCallback(data);
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
require('./env');
|
||||
require('./functions');
|
||||
@@ -219,5 +209,7 @@ require('./visitor.js');
|
||||
require('./import-visitor.js');
|
||||
require('./extend-visitor.js');
|
||||
require('./join-selector-visitor.js');
|
||||
require('./to-css-visitor.js');
|
||||
require('./source-map-output.js');
|
||||
|
||||
for (var k in less) { exports[k] = less[k]; }
|
||||
|
||||
@@ -21,6 +21,10 @@
|
||||
this.contexts.push(paths);
|
||||
|
||||
if (! rulesetNode.root) {
|
||||
rulesetNode.selectors = rulesetNode.selectors.filter(function(selector) { return selector.getIsOutput(); });
|
||||
if (rulesetNode.selectors.length === 0) {
|
||||
rulesetNode.rules.length = 0;
|
||||
}
|
||||
rulesetNode.joinSelectors(paths, context, rulesetNode.selectors);
|
||||
rulesetNode.paths = paths;
|
||||
}
|
||||
@@ -30,7 +34,7 @@
|
||||
},
|
||||
visitMedia: function (mediaNode, visitArgs) {
|
||||
var context = this.contexts[this.contexts.length - 1];
|
||||
mediaNode.ruleset.root = (context.length === 0 || context[0].multiMedia);
|
||||
mediaNode.rules[0].root = (context.length === 0 || context[0].multiMedia);
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -33,14 +33,14 @@ var lessc_helper = {
|
||||
sys.puts(" -M, --depends Output a makefile import dependency list to stdout");
|
||||
sys.puts(" --no-color Disable colorized output.");
|
||||
sys.puts(" --no-ie-compat Disable IE compatibility checks.");
|
||||
sys.puts(" --no-js Disable JavaScript in less files");
|
||||
sys.puts(" -l, --lint Syntax check only (lint).");
|
||||
sys.puts(" -s, --silent Suppress output of error messages.");
|
||||
sys.puts(" --strict-imports Force evaluation of imports.");
|
||||
sys.puts(" --verbose Be verbose.");
|
||||
sys.puts(" -v, --version Print version number and exit.");
|
||||
sys.puts(" -x, --compress Compress output by removing some whitespaces.");
|
||||
sys.puts(" --yui-compress Compress output using ycssmin");
|
||||
sys.puts(" --max-line-len=LINELEN Max line length used by ycssmin");
|
||||
sys.puts(" --clean-css Compress output using clean-css");
|
||||
sys.puts(" -O0, -O1, -O2 Set the parser's optimization level. The lower");
|
||||
sys.puts(" the number, the less nodes it will create in the");
|
||||
sys.puts(" tree. This could matter for debugging, or if you");
|
||||
@@ -51,6 +51,9 @@ var lessc_helper = {
|
||||
sys.puts(" that will output the information within a fake");
|
||||
sys.puts(" media query which is compatible with the SASS");
|
||||
sys.puts(" format, and 'all' which will do both.");
|
||||
sys.puts(" --source-map[=FILENAME] Outputs a v3 sourcemap to the filename (or output filename.map)");
|
||||
sys.puts(" --source-map-rootpath=X adds this path onto the sourcemap filename and less file paths");
|
||||
sys.puts(" --source-map-inline puts the less files into the map instead of referencing them");
|
||||
sys.puts(" -rp, --rootpath=URL Set rootpath for url rewriting in relative imports and urls.");
|
||||
sys.puts(" Works with or without the relative-urls option.");
|
||||
sys.puts(" -ru, --relative-urls re-write relative urls to the base less file.");
|
||||
@@ -60,12 +63,10 @@ var lessc_helper = {
|
||||
sys.puts(" -su=on|off Allow mixed units, e.g. 1px+1em or 1px*1px which have units");
|
||||
sys.puts(" --strict-units=on|off that cannot be represented.");
|
||||
sys.puts("");
|
||||
sys.puts("Report bugs to: http://github.com/cloudhead/less.js/issues");
|
||||
sys.puts("Report bugs to: http://github.com/less/less.js/issues");
|
||||
sys.puts("Home page: <http://lesscss.org/>");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
// Exports helper functions
|
||||
for (var h in lessc_helper) { exports[h] = lessc_helper[h] }
|
||||
for (var h in lessc_helper) { exports[h] = lessc_helper[h]; }
|
||||
|
||||
@@ -1,23 +1,10 @@
|
||||
var less, tree, charset;
|
||||
var less, tree;
|
||||
|
||||
if (typeof environment === "object" && ({}).toString.call(environment) === "[object Environment]") {
|
||||
// Rhino
|
||||
// Details on how to detect Rhino: https://github.com/ringo/ringojs/issues/88
|
||||
if (typeof(window) === 'undefined') { less = {} }
|
||||
else { less = window.less = {} }
|
||||
tree = less.tree = {};
|
||||
less.mode = 'rhino';
|
||||
} else if (typeof(window) === 'undefined') {
|
||||
// Node.js
|
||||
less = exports,
|
||||
// Node.js does not have a header file added which defines less
|
||||
if (less === undefined) {
|
||||
less = exports;
|
||||
tree = require('./tree');
|
||||
less.mode = 'node';
|
||||
} else {
|
||||
// Browser
|
||||
if (typeof(window.less) === 'undefined') { window.less = {} }
|
||||
less = window.less,
|
||||
tree = window.less.tree = {};
|
||||
less.mode = 'browser';
|
||||
}
|
||||
//
|
||||
// less.js - parser
|
||||
@@ -63,8 +50,6 @@ less.Parser = function Parser(env) {
|
||||
current, // index of current chunk, in `input`
|
||||
parser;
|
||||
|
||||
var that = this;
|
||||
|
||||
// Top parser on an import tree must be sure there is one "env"
|
||||
// which will then be passed around by reference.
|
||||
if (!(env instanceof tree.parseEnv)) {
|
||||
@@ -78,24 +63,47 @@ less.Parser = function Parser(env) {
|
||||
contents: env.contents, // Holds the imported file contents
|
||||
mime: env.mime, // MIME type of .less files
|
||||
error: null, // Error in parsing/evaluating an import
|
||||
push: function (path, currentFileInfo, callback) {
|
||||
var parserImporter = this;
|
||||
push: function (path, currentFileInfo, importOptions, callback) {
|
||||
var parserImports = this;
|
||||
this.queue.push(path);
|
||||
|
||||
//
|
||||
// Import a file asynchronously
|
||||
//
|
||||
less.Parser.importer(path, currentFileInfo, function (e, root, fullPath) {
|
||||
parserImporter.queue.splice(parserImporter.queue.indexOf(path), 1); // Remove the path from the queue
|
||||
var fileParsedFunc = function (e, root, fullPath) {
|
||||
parserImports.queue.splice(parserImports.queue.indexOf(path), 1); // Remove the path from the queue
|
||||
|
||||
var imported = fullPath in parserImporter.files;
|
||||
var importedPreviously = fullPath in parserImports.files;
|
||||
|
||||
parserImporter.files[fullPath] = root; // Store the root
|
||||
parserImports.files[fullPath] = root; // Store the root
|
||||
|
||||
if (e && !parserImporter.error) { parserImporter.error = e; }
|
||||
|
||||
callback(e, root, imported);
|
||||
}, env);
|
||||
if (e && !parserImports.error) { parserImports.error = e; }
|
||||
|
||||
callback(e, root, importedPreviously);
|
||||
};
|
||||
|
||||
if (less.Parser.importer) {
|
||||
less.Parser.importer(path, currentFileInfo, fileParsedFunc, env);
|
||||
} else {
|
||||
less.Parser.fileLoader(path, currentFileInfo, function(e, contents, fullPath, newFileInfo) {
|
||||
if (e) {fileParsedFunc(e); return;}
|
||||
|
||||
var newEnv = new tree.parseEnv(env);
|
||||
|
||||
newEnv.currentFileInfo = newFileInfo;
|
||||
newEnv.processImports = false;
|
||||
newEnv.contents[fullPath] = contents;
|
||||
|
||||
if (currentFileInfo.reference || importOptions.reference) {
|
||||
newFileInfo.reference = true;
|
||||
}
|
||||
|
||||
if (importOptions.inline) {
|
||||
fileParsedFunc(null, contents, fullPath);
|
||||
} else {
|
||||
new(less.Parser)(newEnv).parse(contents, function (e, root) {
|
||||
fileParsedFunc(e, root, fullPath);
|
||||
});
|
||||
}
|
||||
}, env);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@@ -117,7 +125,7 @@ less.Parser = function Parser(env) {
|
||||
// Parse from a token, regexp or string, and move forward if match
|
||||
//
|
||||
function $(tok) {
|
||||
var match, args, length, index, k;
|
||||
var match, length;
|
||||
|
||||
//
|
||||
// Non-terminal
|
||||
@@ -166,13 +174,13 @@ less.Parser = function Parser(env) {
|
||||
mem = i += length;
|
||||
|
||||
while (i < endIndex) {
|
||||
if (! isWhitespace(input.charAt(i))) { break }
|
||||
if (! isWhitespace(input.charAt(i))) { break; }
|
||||
i++;
|
||||
}
|
||||
chunks[j] = chunks[j].slice(length + (i - mem));
|
||||
current = i;
|
||||
|
||||
if (chunks[j].length === 0 && j < chunks.length - 1) { j++ }
|
||||
if (chunks[j].length === 0 && j < chunks.length - 1) { j++; }
|
||||
|
||||
return oldi !== i || oldj !== j;
|
||||
}
|
||||
@@ -200,11 +208,7 @@ less.Parser = function Parser(env) {
|
||||
if (typeof(tok) === 'string') {
|
||||
return input.charAt(i) === tok;
|
||||
} else {
|
||||
if (tok.test(chunks[j])) {
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return tok.test(chunks[j]);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -216,13 +220,23 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
}
|
||||
|
||||
function getLocation(index, input) {
|
||||
for (var n = index, column = -1;
|
||||
n >= 0 && input.charAt(n) !== '\n';
|
||||
n--) { column++ }
|
||||
function getLocation(index, inputStream) {
|
||||
var n = index + 1,
|
||||
line = null,
|
||||
column = -1;
|
||||
|
||||
return { line: typeof(index) === 'number' ? (input.slice(0, index).match(/\n/g) || "").length : null,
|
||||
column: column };
|
||||
while (--n >= 0 && inputStream.charAt(n) !== '\n') {
|
||||
column++;
|
||||
}
|
||||
|
||||
if (typeof index === 'number') {
|
||||
line = (inputStream.slice(0, index).match(/\n/g) || "").length;
|
||||
}
|
||||
|
||||
return {
|
||||
line: line,
|
||||
column: column
|
||||
};
|
||||
}
|
||||
|
||||
function getDebugInfo(index, inputStream, env) {
|
||||
@@ -242,6 +256,7 @@ less.Parser = function Parser(env) {
|
||||
loc = getLocation(e.index, input),
|
||||
line = loc.line,
|
||||
col = loc.column,
|
||||
callLine = e.call && getLocation(e.call, input).line,
|
||||
lines = input.split('\n');
|
||||
|
||||
this.type = e.type || 'Syntax';
|
||||
@@ -249,8 +264,8 @@ less.Parser = function Parser(env) {
|
||||
this.filename = e.filename || env.currentFileInfo.filename;
|
||||
this.index = e.index;
|
||||
this.line = typeof(line) === 'number' ? line + 1 : null;
|
||||
this.callLine = e.call && (getLocation(e.call, input).line + 1);
|
||||
this.callExtract = lines[getLocation(e.call, input).line];
|
||||
this.callLine = callLine + 1;
|
||||
this.callExtract = lines[callLine];
|
||||
this.stack = e.stack;
|
||||
this.column = col;
|
||||
this.extract = [
|
||||
@@ -282,7 +297,7 @@ less.Parser = function Parser(env) {
|
||||
// call `callback` when done.
|
||||
//
|
||||
parse: function (str, callback) {
|
||||
var root, start, end, zone, line, lines, buff = [], c, error = null;
|
||||
var root, line, lines, error = null;
|
||||
|
||||
i = j = current = furthest = 0;
|
||||
input = str.replace(/\r\n/g, '\n');
|
||||
@@ -290,6 +305,8 @@ less.Parser = function Parser(env) {
|
||||
// Remove potential UTF Byte Order Mark
|
||||
input = input.replace(/^\uFEFF/, '');
|
||||
|
||||
parser.imports.contents[env.currentFileInfo.filename] = input;
|
||||
|
||||
// Split the input into chunks.
|
||||
chunks = (function (chunks) {
|
||||
var j = 0,
|
||||
@@ -334,16 +351,42 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
|
||||
switch (c) {
|
||||
case '{': if (! inParam) { level ++; chunk.push(c); break }
|
||||
case '}': if (! inParam) { level --; chunk.push(c); chunks[++j] = chunk = []; break }
|
||||
case '(': if (! inParam) { inParam = true; chunk.push(c); break }
|
||||
case ')': if ( inParam) { inParam = false; chunk.push(c); break }
|
||||
default: chunk.push(c);
|
||||
case '{':
|
||||
if (!inParam) {
|
||||
level++;
|
||||
chunk.push(c);
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case '}':
|
||||
if (!inParam) {
|
||||
level--;
|
||||
chunk.push(c);
|
||||
chunks[++j] = chunk = [];
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case '(':
|
||||
if (!inParam) {
|
||||
inParam = true;
|
||||
chunk.push(c);
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
case ')':
|
||||
if (inParam) {
|
||||
inParam = false;
|
||||
chunk.push(c);
|
||||
break;
|
||||
}
|
||||
/* falls through */
|
||||
default:
|
||||
chunk.push(c);
|
||||
}
|
||||
|
||||
i++;
|
||||
}
|
||||
if (level != 0) {
|
||||
if (level !== 0) {
|
||||
error = new(LessError)({
|
||||
index: i-1,
|
||||
type: 'Parse',
|
||||
@@ -352,7 +395,7 @@ less.Parser = function Parser(env) {
|
||||
}, env);
|
||||
}
|
||||
|
||||
return chunks.map(function (c) { return c.join('') });;
|
||||
return chunks.map(function (c) { return c.join(''); });
|
||||
})([[]]);
|
||||
|
||||
if (error) {
|
||||
@@ -372,11 +415,10 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
|
||||
root.toCSS = (function (evaluate) {
|
||||
var line, lines, column;
|
||||
|
||||
return function (options, variables) {
|
||||
options = options || {};
|
||||
var importError,
|
||||
var evaldRoot,
|
||||
css,
|
||||
evalEnv = new tree.evalEnv(options);
|
||||
|
||||
//
|
||||
@@ -402,13 +444,13 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
value = new(tree.Value)([value]);
|
||||
}
|
||||
return new(tree.Rule)('@' + k, value, false, 0);
|
||||
return new(tree.Rule)('@' + k, value, false, null, 0);
|
||||
});
|
||||
evalEnv.frames = [new(tree.Ruleset)(null, variables)];
|
||||
}
|
||||
|
||||
try {
|
||||
var evaldRoot = evaluate.call(this, evalEnv);
|
||||
evaldRoot = evaluate.call(this, evalEnv);
|
||||
|
||||
new(tree.joinSelectorVisitor)()
|
||||
.run(evaldRoot);
|
||||
@@ -416,7 +458,24 @@ less.Parser = function Parser(env) {
|
||||
new(tree.processExtendsVisitor)()
|
||||
.run(evaldRoot);
|
||||
|
||||
var css = evaldRoot.toCSS({
|
||||
new(tree.toCSSVisitor)({compress: Boolean(options.compress)})
|
||||
.run(evaldRoot);
|
||||
|
||||
if (options.sourceMap) {
|
||||
evaldRoot = new tree.sourceMapOutput(
|
||||
{
|
||||
writeSourceMap: options.writeSourceMap,
|
||||
rootNode: evaldRoot,
|
||||
contentsMap: parser.imports.contents,
|
||||
sourceMapFilename: options.sourceMapFilename,
|
||||
outputFilename: options.sourceMapOutputFilename,
|
||||
sourceMapBasepath: options.sourceMapBasepath,
|
||||
sourceMapRootpath: options.sourceMapRootpath,
|
||||
outputSourceFiles: options.outputSourceFiles
|
||||
});
|
||||
}
|
||||
|
||||
css = evaldRoot.toCSS({
|
||||
compress: Boolean(options.compress),
|
||||
dumpLineNumbers: env.dumpLineNumbers,
|
||||
strictUnits: Boolean(options.strictUnits)});
|
||||
@@ -424,10 +483,10 @@ less.Parser = function Parser(env) {
|
||||
throw new(LessError)(e, env);
|
||||
}
|
||||
|
||||
if (options.yuicompress && less.mode === 'node') {
|
||||
return require('ycssmin').cssmin(css, options.maxLineLen);
|
||||
if (options.cleancss && less.mode === 'node') {
|
||||
return require('clean-css').process(css);
|
||||
} else if (options.compress) {
|
||||
return css.replace(/(\s)+/g, "$1");
|
||||
return css.replace(/(^(\s)+)|((\s)+$)/g, "");
|
||||
} else {
|
||||
return css;
|
||||
}
|
||||
@@ -444,10 +503,9 @@ less.Parser = function Parser(env) {
|
||||
// and the part which didn't), so we can color them differently.
|
||||
if (i < input.length - 1) {
|
||||
i = furthest;
|
||||
var loc = getLocation(i, input);
|
||||
lines = input.split('\n');
|
||||
line = (input.slice(0, i).match(/\n/g) || "").length + 1;
|
||||
|
||||
for (var n = i, column = -1; n >= 0 && input.charAt(n) !== '\n'; n--) { column++ }
|
||||
line = loc.line + 1;
|
||||
|
||||
error = {
|
||||
type: "Parse",
|
||||
@@ -455,7 +513,7 @@ less.Parser = function Parser(env) {
|
||||
index: i,
|
||||
filename: env.currentFileInfo.filename,
|
||||
line: line,
|
||||
column: column,
|
||||
column: loc.column,
|
||||
extract: [
|
||||
lines[line - 2],
|
||||
lines[line - 1],
|
||||
@@ -549,15 +607,25 @@ less.Parser = function Parser(env) {
|
||||
comment: function () {
|
||||
var comment;
|
||||
|
||||
if (input.charAt(i) !== '/') return;
|
||||
if (input.charAt(i) !== '/') { return; }
|
||||
|
||||
if (input.charAt(i + 1) === '/') {
|
||||
return new(tree.Comment)($(/^\/\/.*/), true);
|
||||
return new(tree.Comment)($(/^\/\/.*/), true, i, env.currentFileInfo);
|
||||
} else if (comment = $(/^\/\*(?:[^*]|\*+[^\/*])*\*+\/\n?/)) {
|
||||
return new(tree.Comment)(comment);
|
||||
return new(tree.Comment)(comment, false, i, env.currentFileInfo);
|
||||
}
|
||||
},
|
||||
|
||||
comments: function () {
|
||||
var comment, comments = [];
|
||||
|
||||
while(comment = $(this.comment)) {
|
||||
comments.push(comment);
|
||||
}
|
||||
|
||||
return comments;
|
||||
},
|
||||
|
||||
//
|
||||
// Entities are tokens which can be found inside an Expression
|
||||
//
|
||||
@@ -570,8 +638,8 @@ less.Parser = function Parser(env) {
|
||||
quoted: function () {
|
||||
var str, j = i, e, index = i;
|
||||
|
||||
if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
|
||||
if (input.charAt(j) !== '"' && input.charAt(j) !== "'") return;
|
||||
if (input.charAt(j) === '~') { j++, e = true; } // Escaped strings
|
||||
if (input.charAt(j) !== '"' && input.charAt(j) !== "'") { return; }
|
||||
|
||||
e && $('~');
|
||||
|
||||
@@ -611,13 +679,13 @@ less.Parser = function Parser(env) {
|
||||
call: function () {
|
||||
var name, nameLC, args, alpha_ret, index = i;
|
||||
|
||||
if (! (name = /^([\w-]+|%|progid:[\w\.]+)\(/.exec(chunks[j]))) return;
|
||||
if (! (name = /^([\w-]+|%|progid:[\w\.]+)\(/.exec(chunks[j]))) { return; }
|
||||
|
||||
name = name[1];
|
||||
nameLC = name.toLowerCase();
|
||||
|
||||
if (nameLC === 'url') { return null }
|
||||
else { i += name.length }
|
||||
if (nameLC === 'url') { return null; }
|
||||
else { i += name.length; }
|
||||
|
||||
if (nameLC === 'alpha') {
|
||||
alpha_ret = $(this.alpha);
|
||||
@@ -641,7 +709,9 @@ less.Parser = function Parser(env) {
|
||||
|
||||
while (arg = $(this.entities.assignment) || $(this.expression)) {
|
||||
args.push(arg);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
return args;
|
||||
},
|
||||
@@ -675,12 +745,16 @@ less.Parser = function Parser(env) {
|
||||
url: function () {
|
||||
var value;
|
||||
|
||||
if (input.charAt(i) !== 'u' || !$(/^url\(/)) return;
|
||||
if (input.charAt(i) !== 'u' || !$(/^url\(/)) {
|
||||
return;
|
||||
}
|
||||
|
||||
value = $(this.entities.quoted) || $(this.entities.variable) ||
|
||||
$(/^(?:(?:\\[\(\)'"])|[^\(\)'"])+/) || "";
|
||||
|
||||
expect(')');
|
||||
|
||||
/*jshint eqnull:true */
|
||||
return new(tree.URL)((value.value != null || value instanceof tree.Variable)
|
||||
? value : new(tree.Anonymous)(value), env.currentFileInfo);
|
||||
},
|
||||
@@ -703,7 +777,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
// A variable entity useing the protective {} e.g. @{var}
|
||||
variableCurly: function () {
|
||||
var name, curly, index = i;
|
||||
var curly, index = i;
|
||||
|
||||
if (input.charAt(i) === '@' && (curly = $(/^@\{([\w-]+)\}/))) {
|
||||
return new(tree.Variable)("@" + curly[1], index, env.currentFileInfo);
|
||||
@@ -733,7 +807,9 @@ less.Parser = function Parser(env) {
|
||||
dimension: function () {
|
||||
var value, c = input.charCodeAt(i);
|
||||
//Is the first char of the dimension 0-9, '.', '+' or '-'
|
||||
if ((c > 57 || c < 43) || c === 47 || c == 44) return;
|
||||
if ((c > 57 || c < 43) || c === 47 || c == 44) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (value = $(/^([+-]?\d*\.?\d+)(%|[a-z]+)?/)) {
|
||||
return new(tree.Dimension)(value[1], value[2]);
|
||||
@@ -761,10 +837,13 @@ less.Parser = function Parser(env) {
|
||||
javascript: function () {
|
||||
var str, j = i, e;
|
||||
|
||||
if (input.charAt(j) === '~') { j++, e = true } // Escaped strings
|
||||
if (input.charAt(j) !== '`') { return }
|
||||
if (input.charAt(j) === '~') { j++; e = true; } // Escaped strings
|
||||
if (input.charAt(j) !== '`') { return; }
|
||||
if (env.javascriptEnabled !== undefined && !env.javascriptEnabled) {
|
||||
error("You are using JavaScript, which has been disabled.");
|
||||
}
|
||||
|
||||
e && $('~');
|
||||
if (e) { $('~'); }
|
||||
|
||||
if (str = $(/^`([^`]*)`/)) {
|
||||
return new(tree.JavaScript)(str[1], i, e);
|
||||
@@ -780,7 +859,7 @@ less.Parser = function Parser(env) {
|
||||
variable: function () {
|
||||
var name;
|
||||
|
||||
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1] }
|
||||
if (input.charAt(i) === '@' && (name = $(/^(@[\w-]+)\s*:/))) { return name[1]; }
|
||||
},
|
||||
|
||||
//
|
||||
@@ -806,7 +885,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
extendList.push(new(tree.Extend)(new(tree.Selector)(elements), option, index));
|
||||
|
||||
} while($(","))
|
||||
} while($(","));
|
||||
|
||||
expect(/^\)/);
|
||||
|
||||
@@ -840,14 +919,14 @@ less.Parser = function Parser(env) {
|
||||
// selector for now.
|
||||
//
|
||||
call: function () {
|
||||
var elements = [], e, c, args, delim, arg, index = i, s = input.charAt(i), important = false;
|
||||
var elements = [], e, c, args, index = i, s = input.charAt(i), important = false;
|
||||
|
||||
if (s !== '.' && s !== '#') { return }
|
||||
if (s !== '.' && s !== '#') { return; }
|
||||
|
||||
save(); // stop us absorbing part of an invalid selector
|
||||
|
||||
while (e = $(/^[#.](?:[\w-]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/)) {
|
||||
elements.push(new(tree.Element)(c, e, i));
|
||||
elements.push(new(tree.Element)(c, e, i, env.currentFileInfo));
|
||||
c = $('>');
|
||||
}
|
||||
if ($('(')) {
|
||||
@@ -874,7 +953,7 @@ less.Parser = function Parser(env) {
|
||||
if (isCall) {
|
||||
arg = $(this.expression);
|
||||
} else {
|
||||
$(this.comment);
|
||||
$(this.comments);
|
||||
if (input.charAt(i) === '.' && $(/^\.{3}/)) {
|
||||
returner.variadic = true;
|
||||
if ($(";") && !isSemiColonSeperated) {
|
||||
@@ -902,7 +981,7 @@ less.Parser = function Parser(env) {
|
||||
if (isCall) {
|
||||
// Variable
|
||||
if (arg.value.length == 1) {
|
||||
var val = arg.value[0];
|
||||
val = arg.value[0];
|
||||
}
|
||||
} else {
|
||||
val = arg;
|
||||
@@ -951,7 +1030,7 @@ less.Parser = function Parser(env) {
|
||||
isSemiColonSeperated = true;
|
||||
|
||||
if (expressions.length > 1) {
|
||||
value = new (tree.Value)(expressions);
|
||||
value = new(tree.Value)(expressions);
|
||||
}
|
||||
argsSemiColon.push({ name:name, value:value });
|
||||
|
||||
@@ -984,9 +1063,11 @@ less.Parser = function Parser(env) {
|
||||
// the `{...}` block.
|
||||
//
|
||||
definition: function () {
|
||||
var name, params = [], match, ruleset, param, value, cond, variadic = false;
|
||||
var name, params = [], match, ruleset, cond, variadic = false;
|
||||
if ((input.charAt(i) !== '.' && input.charAt(i) !== '#') ||
|
||||
peek(/^[^{]*\}/)) return;
|
||||
peek(/^[^{]*\}/)) {
|
||||
return;
|
||||
}
|
||||
|
||||
save();
|
||||
|
||||
@@ -1004,7 +1085,7 @@ less.Parser = function Parser(env) {
|
||||
restore();
|
||||
}
|
||||
|
||||
$(this.comment);
|
||||
$(this.comments);
|
||||
|
||||
if ($(/^when/)) { // Guard
|
||||
cond = expect(this.conditions, 'expected condition');
|
||||
@@ -1048,7 +1129,7 @@ less.Parser = function Parser(env) {
|
||||
alpha: function () {
|
||||
var value;
|
||||
|
||||
if (! $(/^\(opacity=/i)) return;
|
||||
if (! $(/^\(opacity=/i)) { return; }
|
||||
if (value = $(/^\d+/) || $(this.entities.variable)) {
|
||||
expect(')');
|
||||
return new(tree.Alpha)(value);
|
||||
@@ -1068,7 +1149,7 @@ less.Parser = function Parser(env) {
|
||||
// and an element name, such as a tag a class, or `*`.
|
||||
//
|
||||
element: function () {
|
||||
var e, t, c, v;
|
||||
var e, c, v;
|
||||
|
||||
c = $(this.combinator);
|
||||
|
||||
@@ -1084,7 +1165,7 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
}
|
||||
|
||||
if (e) { return new(tree.Element)(c, e, i) }
|
||||
if (e) { return new(tree.Element)(c, e, i, env.currentFileInfo); }
|
||||
},
|
||||
|
||||
//
|
||||
@@ -1101,7 +1182,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
if (c === '>' || c === '+' || c === '~' || c === '|') {
|
||||
i++;
|
||||
while (input.charAt(i).match(/\s/)) { i++ }
|
||||
while (input.charAt(i).match(/\s/)) { i++; }
|
||||
return new(tree.Combinator)(c);
|
||||
} else if (input.charAt(i - 1).match(/\s/)) {
|
||||
return new(tree.Combinator)(" ");
|
||||
@@ -1109,7 +1190,13 @@ less.Parser = function Parser(env) {
|
||||
return new(tree.Combinator)(null);
|
||||
}
|
||||
},
|
||||
|
||||
//
|
||||
// A CSS selector (see selector below)
|
||||
// with less extensions e.g. the ability to extend and guard
|
||||
//
|
||||
lessSelector: function () {
|
||||
return this.selector(true);
|
||||
},
|
||||
//
|
||||
// A CSS Selector
|
||||
//
|
||||
@@ -1118,30 +1205,36 @@ less.Parser = function Parser(env) {
|
||||
//
|
||||
// Selectors are made out of one or more Elements, see above.
|
||||
//
|
||||
selector: function () {
|
||||
var sel, e, elements = [], c, extend, extendList = [];
|
||||
selector: function (isLess) {
|
||||
var e, elements = [], c, extend, extendList = [], when, condition;
|
||||
|
||||
while ((extend = $(this.extend)) || (e = $(this.element))) {
|
||||
if (extend) {
|
||||
while ((isLess && (extend = $(this.extend))) || (isLess && (when = $(/^when/))) || (e = $(this.element))) {
|
||||
if (when) {
|
||||
condition = expect(this.conditions, 'expected condition');
|
||||
} else if (condition) {
|
||||
error("CSS guard can only be used at the end of selector");
|
||||
} else if (extend) {
|
||||
extendList.push.apply(extendList, extend);
|
||||
} else {
|
||||
if (extendList.length) {
|
||||
error("Extend can only be used at the end of selector");
|
||||
}
|
||||
c = input.charAt(i);
|
||||
elements.push(e)
|
||||
elements.push(e);
|
||||
e = null;
|
||||
}
|
||||
if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') { break }
|
||||
if (c === '{' || c === '}' || c === ';' || c === ',' || c === ')') {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (elements.length > 0) { return new(tree.Selector)(elements, extendList); }
|
||||
if (elements.length > 0) { return new(tree.Selector)(elements, extendList, condition, i, env.currentFileInfo); }
|
||||
if (extendList.length) { error("Extend must be used to extend a selector, it cannot be used on its own"); }
|
||||
},
|
||||
attribute: function () {
|
||||
var attr = '', key, val, op;
|
||||
var key, val, op;
|
||||
|
||||
if (! $('[')) return;
|
||||
if (! $('[')) { return; }
|
||||
|
||||
if (!(key = $(this.entities.variableCurly))) {
|
||||
key = expect(/^(?:[_A-Za-z0-9-\*]*\|)?(?:[_A-Za-z0-9-]|\\.)+/);
|
||||
@@ -1175,20 +1268,25 @@ less.Parser = function Parser(env) {
|
||||
|
||||
save();
|
||||
|
||||
if (env.dumpLineNumbers)
|
||||
if (env.dumpLineNumbers) {
|
||||
debugInfo = getDebugInfo(i, input, env);
|
||||
}
|
||||
|
||||
while (s = $(this.selector)) {
|
||||
while (s = $(this.lessSelector)) {
|
||||
selectors.push(s);
|
||||
$(this.comment);
|
||||
if (! $(',')) { break }
|
||||
$(this.comment);
|
||||
$(this.comments);
|
||||
if (! $(',')) { break; }
|
||||
if (s.condition) {
|
||||
error("Guards are only currently allowed on a single selector");
|
||||
}
|
||||
$(this.comments);
|
||||
}
|
||||
|
||||
if (selectors.length > 0 && (rules = $(this.block))) {
|
||||
var ruleset = new(tree.Ruleset)(selectors, rules, env.strictImports);
|
||||
if (env.dumpLineNumbers)
|
||||
if (env.dumpLineNumbers) {
|
||||
ruleset.debugInfo = debugInfo;
|
||||
}
|
||||
return ruleset;
|
||||
} else {
|
||||
// Backtrack
|
||||
@@ -1197,22 +1295,27 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
},
|
||||
rule: function (tryAnonymous) {
|
||||
var name, value, c = input.charAt(i), important;
|
||||
var name, value, c = input.charAt(i), important, merge = false;
|
||||
save();
|
||||
|
||||
if (c === '.' || c === '#' || c === '&') { return }
|
||||
if (c === '.' || c === '#' || c === '&') { return; }
|
||||
|
||||
if (name = $(this.variable) || $(this.property)) {
|
||||
if (name = $(this.variable) || $(this.ruleProperty)) {
|
||||
// prefer to try to parse first if its a variable or we are compressing
|
||||
// but always fallback on the other one
|
||||
value = !tryAnonymous && (env.compress || (name.charAt(0) === '@')) ?
|
||||
($(this.value) || $(this.anonymousValue)) :
|
||||
($(this.anonymousValue) || $(this.value));
|
||||
|
||||
|
||||
important = $(this.important);
|
||||
if (name[name.length-1] === "+") {
|
||||
merge = true;
|
||||
name = name.substr(0, name.length - 1);
|
||||
}
|
||||
|
||||
if (value && $(this.end)) {
|
||||
return new(tree.Rule)(name, value, important, memo, env.currentFileInfo);
|
||||
return new (tree.Rule)(name, value, important, merge, memo, env.currentFileInfo);
|
||||
} else {
|
||||
furthest = i;
|
||||
restore();
|
||||
@@ -1280,7 +1383,7 @@ less.Parser = function Parser(env) {
|
||||
break;
|
||||
}
|
||||
options[optionName] = value;
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
}
|
||||
} while (o);
|
||||
expect(')');
|
||||
@@ -1288,7 +1391,7 @@ less.Parser = function Parser(env) {
|
||||
},
|
||||
|
||||
importOption: function() {
|
||||
var opt = $(/^(less|css|multiple|once)/);
|
||||
var opt = $(/^(less|css|multiple|once|inline|reference)/);
|
||||
if (opt) {
|
||||
return opt[1];
|
||||
}
|
||||
@@ -1305,13 +1408,13 @@ less.Parser = function Parser(env) {
|
||||
e = $(this.value);
|
||||
if ($(')')) {
|
||||
if (p && e) {
|
||||
nodes.push(new(tree.Paren)(new(tree.Rule)(p, e, null, i, env.currentFileInfo, true)));
|
||||
nodes.push(new(tree.Paren)(new(tree.Rule)(p, e, null, null, i, env.currentFileInfo, true)));
|
||||
} else if (e) {
|
||||
nodes.push(new(tree.Paren)(e));
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
} else { return null }
|
||||
} else { return null; }
|
||||
}
|
||||
} while (e);
|
||||
|
||||
@@ -1326,10 +1429,10 @@ less.Parser = function Parser(env) {
|
||||
do {
|
||||
if (e = $(this.mediaFeature)) {
|
||||
features.push(e);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
} else if (e = $(this.entities.variable)) {
|
||||
features.push(e);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
}
|
||||
} while (e);
|
||||
|
||||
@@ -1339,16 +1442,18 @@ less.Parser = function Parser(env) {
|
||||
media: function () {
|
||||
var features, rules, media, debugInfo;
|
||||
|
||||
if (env.dumpLineNumbers)
|
||||
if (env.dumpLineNumbers) {
|
||||
debugInfo = getDebugInfo(i, input, env);
|
||||
}
|
||||
|
||||
if ($(/^@media/)) {
|
||||
features = $(this.mediaFeatures);
|
||||
|
||||
if (rules = $(this.block)) {
|
||||
media = new(tree.Media)(rules, features);
|
||||
if(env.dumpLineNumbers)
|
||||
media = new(tree.Media)(rules, features, i, env.currentFileInfo);
|
||||
if (env.dumpLineNumbers) {
|
||||
media.debugInfo = debugInfo;
|
||||
}
|
||||
return media;
|
||||
}
|
||||
}
|
||||
@@ -1360,10 +1465,10 @@ less.Parser = function Parser(env) {
|
||||
// @charset "utf-8";
|
||||
//
|
||||
directive: function () {
|
||||
var name, value, rules, identifier, e, nodes, nonVendorSpecificName,
|
||||
var name, value, rules, nonVendorSpecificName,
|
||||
hasBlock, hasIdentifier, hasExpression;
|
||||
|
||||
if (input.charAt(i) !== '@') return;
|
||||
if (input.charAt(i) !== '@') { return; }
|
||||
|
||||
if (value = $(this['import']) || $(this.media)) {
|
||||
return value;
|
||||
@@ -1373,7 +1478,7 @@ less.Parser = function Parser(env) {
|
||||
|
||||
name = $(/^@[a-z-]+/);
|
||||
|
||||
if (!name) return;
|
||||
if (!name) { return; }
|
||||
|
||||
nonVendorSpecificName = name;
|
||||
if (name.charAt(1) == '-' && name.indexOf('-', 2) > 0) {
|
||||
@@ -1422,11 +1527,11 @@ less.Parser = function Parser(env) {
|
||||
if (hasBlock)
|
||||
{
|
||||
if (rules = $(this.block)) {
|
||||
return new(tree.Directive)(name, rules);
|
||||
return new(tree.Directive)(name, rules, i, env.currentFileInfo);
|
||||
}
|
||||
} else {
|
||||
if ((value = hasExpression ? $(this.expression) : $(this.entity)) && $(';')) {
|
||||
var directive = new(tree.Directive)(name, value);
|
||||
var directive = new(tree.Directive)(name, value, i, env.currentFileInfo);
|
||||
if (env.dumpLineNumbers) {
|
||||
directive.debugInfo = getDebugInfo(i, input, env);
|
||||
}
|
||||
@@ -1446,11 +1551,11 @@ less.Parser = function Parser(env) {
|
||||
// and before the `;`.
|
||||
//
|
||||
value: function () {
|
||||
var e, expressions = [], important;
|
||||
var e, expressions = [];
|
||||
|
||||
while (e = $(this.expression)) {
|
||||
expressions.push(e);
|
||||
if (! $(',')) { break }
|
||||
if (! $(',')) { break; }
|
||||
}
|
||||
|
||||
if (expressions.length > 0) {
|
||||
@@ -1475,7 +1580,7 @@ less.Parser = function Parser(env) {
|
||||
}
|
||||
},
|
||||
multiplication: function () {
|
||||
var m, a, op, operation, isSpaced, expression = [];
|
||||
var m, a, op, operation, isSpaced;
|
||||
if (m = $(this.operand)) {
|
||||
isSpaced = isWhitespace(input.charAt(i - 1));
|
||||
while (!peek(/^\/[*\/]/) && (op = ($('/') || $('*')))) {
|
||||
@@ -1518,7 +1623,7 @@ less.Parser = function Parser(env) {
|
||||
condition: function () {
|
||||
var a, b, c, op, index = i, negate = false;
|
||||
|
||||
if ($(/^not/)) { negate = true }
|
||||
if ($(/^not/)) { negate = true; }
|
||||
expect('(');
|
||||
if (a = $(this.addition) || $(this.entities.keyword) || $(this.entities.quoted)) {
|
||||
if (op = $(/^(?:>=|=<|[<=>])/)) {
|
||||
@@ -1542,7 +1647,7 @@ less.Parser = function Parser(env) {
|
||||
operand: function () {
|
||||
var negate, p = input.charAt(i + 1);
|
||||
|
||||
if (input.charAt(i) === '-' && (p === '@' || p === '(')) { negate = $('-') }
|
||||
if (input.charAt(i) === '-' && (p === '@' || p === '(')) { negate = $('-'); }
|
||||
var o = $(this.sub) || $(this.entities.dimension) ||
|
||||
$(this.entities.color) || $(this.entities.variable) ||
|
||||
$(this.entities.call);
|
||||
@@ -1563,7 +1668,7 @@ less.Parser = function Parser(env) {
|
||||
// @var * 2
|
||||
//
|
||||
expression: function () {
|
||||
var e, delim, entities = [], d;
|
||||
var e, delim, entities = [];
|
||||
|
||||
while (e = $(this.addition) || $(this.entity)) {
|
||||
entities.push(e);
|
||||
@@ -1582,30 +1687,15 @@ less.Parser = function Parser(env) {
|
||||
if (name = $(/^(\*?-?[_a-zA-Z0-9-]+)\s*:/)) {
|
||||
return name[1];
|
||||
}
|
||||
},
|
||||
ruleProperty: function () {
|
||||
var name;
|
||||
|
||||
if (name = $(/^(\*?-?[_a-zA-Z0-9-]+)\s*(\+?)\s*:/)) {
|
||||
return name[1] + (name[2] || "");
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
if (less.mode === 'browser' || less.mode === 'rhino') {
|
||||
//
|
||||
// Used by `@import` directives
|
||||
//
|
||||
less.Parser.importer = function (path, currentFileInfo, callback, env) {
|
||||
if (!/^([a-z-]+:)?\//.test(path) && currentFileInfo.currentDirectory) {
|
||||
path = currentFileInfo.currentDirectory + path;
|
||||
}
|
||||
var sheetEnv = env.toSheet(path);
|
||||
sheetEnv.processImports = false;
|
||||
sheetEnv.currentFileInfo = currentFileInfo;
|
||||
|
||||
// We pass `true` as 3rd argument, to force the reload of the import.
|
||||
// This is so we can get the syntax tree as opposed to just the CSS output,
|
||||
// as we need this to evaluate the current stylesheet.
|
||||
loadStyleSheet(sheetEnv,
|
||||
function (e, root, data, sheet, _, path) {
|
||||
callback.call(null, e, root, path);
|
||||
}, true);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,36 @@
|
||||
/*jshint rhino:true, unused: false */
|
||||
/*global name:true, less, loadStyleSheet */
|
||||
var name;
|
||||
|
||||
function error(e, filename) {
|
||||
|
||||
var content = "Error : " + filename + "\n";
|
||||
|
||||
filename = e.filename || filename;
|
||||
|
||||
if (e.message) {
|
||||
content += e.message + "\n";
|
||||
}
|
||||
|
||||
var errorline = function (e, i, classname) {
|
||||
if (e.extract[i]) {
|
||||
content +=
|
||||
String(parseInt(e.line, 10) + (i - 1)) +
|
||||
":" + e.extract[i] + "\n";
|
||||
}
|
||||
};
|
||||
|
||||
if (e.stack) {
|
||||
content += e.stack;
|
||||
} else if (e.extract) {
|
||||
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n';
|
||||
errorline(e, 0);
|
||||
errorline(e, 1);
|
||||
errorline(e, 2);
|
||||
}
|
||||
print(content);
|
||||
}
|
||||
|
||||
function loadStyleSheet(sheet, callback, reload, remaining) {
|
||||
var endOfPath = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\')),
|
||||
sheetName = name.slice(0, endOfPath + 1) + sheet.href,
|
||||
@@ -61,7 +92,7 @@ function writeFile(filename, content) {
|
||||
print('No files present in the fileset; Check your pattern match in build.xml');
|
||||
quit(1);
|
||||
}
|
||||
path = name.split("/");path.pop();path=path.join("/")
|
||||
path = name.split("/");path.pop();path=path.join("/");
|
||||
|
||||
var input = readFile(name);
|
||||
|
||||
@@ -94,33 +125,4 @@ function writeFile(filename, content) {
|
||||
quit(1);
|
||||
}
|
||||
print("done");
|
||||
}(arguments));
|
||||
|
||||
function error(e, filename) {
|
||||
|
||||
var content = "Error : " + filename + "\n";
|
||||
|
||||
filename = e.filename || filename;
|
||||
|
||||
if (e.message) {
|
||||
content += e.message + "\n";
|
||||
}
|
||||
|
||||
var errorline = function (e, i, classname) {
|
||||
if (e.extract[i]) {
|
||||
content +=
|
||||
String(parseInt(e.line) + (i - 1)) +
|
||||
":" + e.extract[i] + "\n";
|
||||
}
|
||||
};
|
||||
|
||||
if (e.stack) {
|
||||
content += e.stack;
|
||||
} else if (e.extract) {
|
||||
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n';
|
||||
errorline(e, 0);
|
||||
errorline(e, 1);
|
||||
errorline(e, 2);
|
||||
}
|
||||
print(content);
|
||||
}
|
||||
}(arguments));
|
||||
84
lib/less/source-map-output.js
Normal file
84
lib/less/source-map-output.js
Normal file
@@ -0,0 +1,84 @@
|
||||
(function (tree) {
|
||||
var sourceMap = require("source-map");
|
||||
|
||||
tree.sourceMapOutput = function (options) {
|
||||
this._css = [];
|
||||
this._rootNode = options.rootNode;
|
||||
this._writeSourceMap = options.writeSourceMap;
|
||||
this._contentsMap = options.contentsMap;
|
||||
this._sourceMapFilename = options.sourceMapFilename;
|
||||
this._outputFilename = options.outputFilename;
|
||||
this._sourceMapBasepath = options.sourceMapBasepath;
|
||||
this._sourceMapRootpath = options.sourceMapRootpath;
|
||||
this._outputSourceFiles = options.outputSourceFiles;
|
||||
|
||||
if (this._sourceMapRootpath && this._sourceMapRootpath.charAt(this._sourceMapRootpath.length-1) !== '/') {
|
||||
this._sourceMapRootpath += '/';
|
||||
}
|
||||
|
||||
this._lineNumber = 0;
|
||||
this._column = 0;
|
||||
};
|
||||
|
||||
tree.sourceMapOutput.prototype.normalizeFilename = function(filename) {
|
||||
if (this._sourceMapBasepath && filename.indexOf(this._sourceMapBasepath) === 0) {
|
||||
filename = filename.substring(this._sourceMapBasepath.length);
|
||||
if (filename.charAt(0) === '\\' || filename.charAt(0) === '/') {
|
||||
filename = filename.substring(1);
|
||||
}
|
||||
}
|
||||
return this._sourceMapRootpath + filename.replace(/\\/g, '/');
|
||||
};
|
||||
|
||||
tree.sourceMapOutput.prototype.add = function(chunk, fileInfo, index) {
|
||||
|
||||
if (!chunk) {
|
||||
//TODO what is calling this with undefined?
|
||||
return;
|
||||
}
|
||||
|
||||
var lines,
|
||||
columns;
|
||||
|
||||
if (fileInfo) {
|
||||
var inputSource = this._contentsMap[fileInfo.filename].substring(0, index);
|
||||
lines = inputSource.split("\n");
|
||||
columns = lines[lines.length-1];
|
||||
this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column},
|
||||
original: { line: lines.length, column: columns.length},
|
||||
source: this.normalizeFilename(fileInfo.filename)});
|
||||
}
|
||||
lines = chunk.split("\n");
|
||||
columns = lines[lines.length-1];
|
||||
|
||||
if (lines.length === 1) {
|
||||
this._column += columns.length;
|
||||
} else {
|
||||
this._lineNumber += lines.length - 1;
|
||||
this._column = columns.length;
|
||||
}
|
||||
|
||||
this._css.push(chunk);
|
||||
};
|
||||
|
||||
tree.sourceMapOutput.prototype.toCSS = function(env) {
|
||||
this._sourceMapGenerator = new sourceMap.SourceMapGenerator({ file: this._outputFilename, sourceRoot: null });
|
||||
|
||||
if (this._outputSourceFiles) {
|
||||
for(var filename in this._contentsMap) {
|
||||
this._sourceMapGenerator.setSourceContent(this.normalizeFilename(filename), this._contentsMap[filename]);
|
||||
}
|
||||
}
|
||||
|
||||
this._rootNode.genCSS(env, this);
|
||||
|
||||
this._writeSourceMap(JSON.stringify(this._sourceMapGenerator.toJSON()));
|
||||
|
||||
if (this._sourceMapFilename) {
|
||||
this._css.push("/*# sourceMappingURL=" + this._sourceMapRootpath + this._sourceMapFilename + " */");
|
||||
}
|
||||
|
||||
return this._css.join('');
|
||||
};
|
||||
|
||||
})(require('./tree'));
|
||||
199
lib/less/to-css-visitor.js
Normal file
199
lib/less/to-css-visitor.js
Normal file
@@ -0,0 +1,199 @@
|
||||
(function (tree) {
|
||||
tree.toCSSVisitor = function(env) {
|
||||
this._visitor = new tree.visitor(this);
|
||||
this._env = env;
|
||||
};
|
||||
|
||||
tree.toCSSVisitor.prototype = {
|
||||
isReplacing: true,
|
||||
run: function (root) {
|
||||
return this._visitor.visit(root);
|
||||
},
|
||||
|
||||
visitRule: function (ruleNode, visitArgs) {
|
||||
if (ruleNode.variable) {
|
||||
return [];
|
||||
}
|
||||
return ruleNode;
|
||||
},
|
||||
|
||||
visitMixinDefinition: function (mixinNode, visitArgs) {
|
||||
return [];
|
||||
},
|
||||
|
||||
visitExtend: function (extendNode, visitArgs) {
|
||||
return [];
|
||||
},
|
||||
|
||||
visitComment: function (commentNode, visitArgs) {
|
||||
if (commentNode.isSilent(this._env)) {
|
||||
return [];
|
||||
}
|
||||
return commentNode;
|
||||
},
|
||||
|
||||
visitMedia: function(mediaNode, visitArgs) {
|
||||
mediaNode.accept(this._visitor);
|
||||
visitArgs.visitDeeper = false;
|
||||
|
||||
if (!mediaNode.rules.length) {
|
||||
return [];
|
||||
}
|
||||
return mediaNode;
|
||||
},
|
||||
|
||||
visitDirective: function(directiveNode, visitArgs) {
|
||||
if (directiveNode.currentFileInfo.reference && !directiveNode.isReferenced) {
|
||||
return [];
|
||||
}
|
||||
if (directiveNode.name === "@charset") {
|
||||
// Only output the debug info together with subsequent @charset definitions
|
||||
// a comment (or @media statement) before the actual @charset directive would
|
||||
// be considered illegal css as it has to be on the first line
|
||||
if (this.charset) {
|
||||
if (directiveNode.debugInfo) {
|
||||
var comment = new tree.Comment("/* " + directiveNode.toCSS(this._env).replace(/\n/g, "")+" */\n");
|
||||
comment.debugInfo = directiveNode.debugInfo;
|
||||
return this._visitor.visit(comment);
|
||||
}
|
||||
return [];
|
||||
}
|
||||
this.charset = true;
|
||||
}
|
||||
return directiveNode;
|
||||
},
|
||||
|
||||
checkPropertiesInRoot: function(rules) {
|
||||
var ruleNode;
|
||||
for(var i = 0; i < rules.length; i++) {
|
||||
ruleNode = rules[i];
|
||||
if (ruleNode instanceof tree.Rule && !ruleNode.variable) {
|
||||
throw { message: "properties must be inside selector blocks, they cannot be in the root.",
|
||||
index: ruleNode.index, filename: ruleNode.currentFileInfo ? ruleNode.currentFileInfo.filename : null};
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
visitRuleset: function (rulesetNode, visitArgs) {
|
||||
var rule, rulesets = [];
|
||||
if (rulesetNode.firstRoot) {
|
||||
this.checkPropertiesInRoot(rulesetNode.rules);
|
||||
}
|
||||
if (! rulesetNode.root) {
|
||||
|
||||
rulesetNode.paths = rulesetNode.paths
|
||||
.filter(function(p) {
|
||||
var i;
|
||||
if (p[0].elements[0].combinator.value === ' ') {
|
||||
p[0].elements[0].combinator = new(tree.Combinator)('');
|
||||
}
|
||||
for(i = 0; i < p.length; i++) {
|
||||
if (p[i].getIsReferenced() && p[i].getIsOutput()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
// Compile rules and rulesets
|
||||
for (var i = 0; i < rulesetNode.rules.length; i++) {
|
||||
rule = rulesetNode.rules[i];
|
||||
|
||||
if (rule.rules) {
|
||||
// visit because we are moving them out from being a child
|
||||
rulesets.push(this._visitor.visit(rule));
|
||||
rulesetNode.rules.splice(i, 1);
|
||||
i--;
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// accept the visitor to remove rules and refactor itself
|
||||
// then we can decide now whether we want it or not
|
||||
if (rulesetNode.rules.length > 0) {
|
||||
rulesetNode.accept(this._visitor);
|
||||
}
|
||||
visitArgs.visitDeeper = false;
|
||||
|
||||
this._mergeRules(rulesetNode.rules);
|
||||
this._removeDuplicateRules(rulesetNode.rules);
|
||||
|
||||
// now decide whether we keep the ruleset
|
||||
if (rulesetNode.rules.length > 0 && rulesetNode.paths.length > 0) {
|
||||
rulesets.splice(0, 0, rulesetNode);
|
||||
}
|
||||
} else {
|
||||
rulesetNode.accept(this._visitor);
|
||||
visitArgs.visitDeeper = false;
|
||||
if (rulesetNode.firstRoot || rulesetNode.rules.length > 0) {
|
||||
rulesets.splice(0, 0, rulesetNode);
|
||||
}
|
||||
}
|
||||
if (rulesets.length === 1) {
|
||||
return rulesets[0];
|
||||
}
|
||||
return rulesets;
|
||||
},
|
||||
|
||||
_removeDuplicateRules: function(rules) {
|
||||
// remove duplicates
|
||||
var ruleCache = {},
|
||||
ruleList, rule, i;
|
||||
for(i = rules.length - 1; i >= 0 ; i--) {
|
||||
rule = rules[i];
|
||||
if (rule instanceof tree.Rule) {
|
||||
if (!ruleCache[rule.name]) {
|
||||
ruleCache[rule.name] = rule;
|
||||
} else {
|
||||
ruleList = ruleCache[rule.name];
|
||||
if (ruleList instanceof tree.Rule) {
|
||||
ruleList = ruleCache[rule.name] = [ruleCache[rule.name].toCSS(this._env)];
|
||||
}
|
||||
var ruleCSS = rule.toCSS(this._env);
|
||||
if (ruleList.indexOf(ruleCSS) !== -1) {
|
||||
rules.splice(i, 1);
|
||||
} else {
|
||||
ruleList.push(ruleCSS);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
_mergeRules: function (rules) {
|
||||
var groups = {},
|
||||
parts,
|
||||
rule,
|
||||
key;
|
||||
|
||||
for (var i = 0; i < rules.length; i++) {
|
||||
rule = rules[i];
|
||||
|
||||
if ((rule instanceof tree.Rule) && rule.merge) {
|
||||
key = [rule.name,
|
||||
rule.important ? "!" : ""].join(",");
|
||||
|
||||
if (!groups[key]) {
|
||||
parts = groups[key] = [];
|
||||
} else {
|
||||
rules.splice(i--, 1);
|
||||
}
|
||||
|
||||
parts.push(rule);
|
||||
}
|
||||
}
|
||||
|
||||
Object.keys(groups).map(function (k) {
|
||||
parts = groups[k];
|
||||
|
||||
if (parts.length > 1) {
|
||||
rule = parts[0];
|
||||
|
||||
rule.value = new (tree.Value)(parts.map(function (p) {
|
||||
return p.value;
|
||||
}));
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
})(require('./tree'));
|
||||
@@ -1,6 +1,6 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.debugInfo = function(env, ctx) {
|
||||
tree.debugInfo = function(env, ctx, lineSeperator) {
|
||||
var result="";
|
||||
if (env.dumpLineNumbers && !env.compress) {
|
||||
switch(env.dumpLineNumbers) {
|
||||
@@ -11,7 +11,7 @@ tree.debugInfo = function(env, ctx) {
|
||||
result = tree.debugInfo.asMediaQuery(ctx);
|
||||
break;
|
||||
case 'all':
|
||||
result = tree.debugInfo.asComment(ctx)+tree.debugInfo.asMediaQuery(ctx);
|
||||
result = tree.debugInfo.asComment(ctx) + (lineSeperator || "") + tree.debugInfo.asMediaQuery(ctx);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -24,22 +24,52 @@ tree.debugInfo.asComment = function(ctx) {
|
||||
|
||||
tree.debugInfo.asMediaQuery = function(ctx) {
|
||||
return '@media -sass-debug-info{filename{font-family:' +
|
||||
('file://' + ctx.debugInfo.fileName).replace(/([.:/\\])/g, function(a){if(a=='\\') a = '\/'; return '\\' + a}) +
|
||||
('file://' + ctx.debugInfo.fileName).replace(/([.:/\\])/g, function (a) {
|
||||
if (a == '\\') {
|
||||
a = '\/';
|
||||
}
|
||||
return '\\' + a;
|
||||
}) +
|
||||
'}line{font-family:\\00003' + ctx.debugInfo.lineNumber + '}}\n';
|
||||
};
|
||||
|
||||
tree.find = function (obj, fun) {
|
||||
for (var i = 0, r; i < obj.length; i++) {
|
||||
if (r = fun.call(obj, obj[i])) { return r }
|
||||
if (r = fun.call(obj, obj[i])) { return r; }
|
||||
}
|
||||
return null;
|
||||
};
|
||||
|
||||
tree.jsify = function (obj) {
|
||||
if (Array.isArray(obj.value) && (obj.value.length > 1)) {
|
||||
return '[' + obj.value.map(function (v) { return v.toCSS(false) }).join(', ') + ']';
|
||||
return '[' + obj.value.map(function (v) { return v.toCSS(false); }).join(', ') + ']';
|
||||
} else {
|
||||
return obj.toCSS(false);
|
||||
}
|
||||
};
|
||||
|
||||
tree.toCSS = function (env) {
|
||||
var strs = [];
|
||||
this.genCSS(env, {
|
||||
add: function(chunk, node) {
|
||||
strs.push(chunk);
|
||||
}
|
||||
});
|
||||
return strs.join('');
|
||||
};
|
||||
|
||||
tree.outputRuleset = function (env, output, rules) {
|
||||
output.add((env.compress ? '{' : ' {\n'));
|
||||
env.tabLevel = (env.tabLevel || 0) + 1;
|
||||
var tabRuleStr = env.compress ? '' : Array(env.tabLevel + 1).join(" "),
|
||||
tabSetStr = env.compress ? '' : Array(env.tabLevel).join(" ");
|
||||
for(var i = 0; i < rules.length; i++) {
|
||||
output.add(tabRuleStr);
|
||||
rules[i].genCSS(env, output);
|
||||
output.add(env.compress ? '' : '\n');
|
||||
}
|
||||
env.tabLevel--;
|
||||
output.add(tabSetStr + "}");
|
||||
};
|
||||
|
||||
})(require('./tree'));
|
||||
|
||||
@@ -9,13 +9,21 @@ tree.Alpha.prototype = {
|
||||
this.value = visitor.visit(this.value);
|
||||
},
|
||||
eval: function (env) {
|
||||
if (this.value.eval) { this.value = this.value.eval(env) }
|
||||
if (this.value.eval) { return new tree.Alpha(this.value.eval(env)); }
|
||||
return this;
|
||||
},
|
||||
toCSS: function () {
|
||||
return "alpha(opacity=" +
|
||||
(this.value.toCSS ? this.value.toCSS() : this.value) + ")";
|
||||
}
|
||||
genCSS: function (env, output) {
|
||||
output.add("alpha(opacity=");
|
||||
|
||||
if (this.value.genCSS) {
|
||||
this.value.genCSS(env, output);
|
||||
} else {
|
||||
output.add(this.value);
|
||||
}
|
||||
|
||||
output.add(")");
|
||||
},
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -5,10 +5,7 @@ tree.Anonymous = function (string) {
|
||||
};
|
||||
tree.Anonymous.prototype = {
|
||||
type: "Anonymous",
|
||||
toCSS: function () {
|
||||
return this.value;
|
||||
},
|
||||
eval: function () { return this },
|
||||
eval: function () { return this; },
|
||||
compare: function (x) {
|
||||
if (!x.toCSS) {
|
||||
return -1;
|
||||
@@ -22,7 +19,11 @@ tree.Anonymous.prototype = {
|
||||
}
|
||||
|
||||
return left < right ? -1 : 1;
|
||||
}
|
||||
},
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.value);
|
||||
},
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -9,15 +9,21 @@ tree.Assignment.prototype = {
|
||||
accept: function (visitor) {
|
||||
this.value = visitor.visit(this.value);
|
||||
},
|
||||
toCSS: function () {
|
||||
return this.key + '=' + (this.value.toCSS ? this.value.toCSS() : this.value);
|
||||
},
|
||||
eval: function (env) {
|
||||
if (this.value.eval) {
|
||||
return new(tree.Assignment)(this.key, this.value.eval(env));
|
||||
}
|
||||
return this;
|
||||
}
|
||||
},
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.key + '=');
|
||||
if (this.value.genCSS) {
|
||||
this.value.genCSS(env, output);
|
||||
} else {
|
||||
output.add(this.value);
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -36,6 +36,7 @@ tree.Call.prototype = {
|
||||
try {
|
||||
func = new tree.functionCall(env, this.currentFileInfo);
|
||||
result = func[nameLC].apply(func, args);
|
||||
/*jshint eqnull:true */
|
||||
if (result != null) {
|
||||
return result;
|
||||
}
|
||||
@@ -46,15 +47,24 @@ tree.Call.prototype = {
|
||||
index: this.index, filename: this.currentFileInfo.filename };
|
||||
}
|
||||
}
|
||||
|
||||
// 2.
|
||||
return new(tree.Anonymous)(this.name +
|
||||
"(" + args.map(function (a) { return a.toCSS(env); }).join(', ') + ")");
|
||||
|
||||
return new tree.Call(this.name, args, this.index, this.currentFileInfo);
|
||||
},
|
||||
|
||||
toCSS: function (env) {
|
||||
return this.eval(env).toCSS();
|
||||
}
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.name + "(", this.currentFileInfo, this.index);
|
||||
|
||||
for(var i = 0; i < this.args.length; i++) {
|
||||
this.args[i].genCSS(env, output);
|
||||
if (i + 1 < this.args.length) {
|
||||
output.add(", ");
|
||||
}
|
||||
}
|
||||
|
||||
output.add(")");
|
||||
},
|
||||
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -24,40 +24,36 @@ tree.Color = function (rgb, a) {
|
||||
};
|
||||
tree.Color.prototype = {
|
||||
type: "Color",
|
||||
eval: function () { return this },
|
||||
eval: function () { return this; },
|
||||
luma: function () { return (0.2126 * this.rgb[0] / 255) + (0.7152 * this.rgb[1] / 255) + (0.0722 * this.rgb[2] / 255); },
|
||||
|
||||
//
|
||||
// If we have some transparency, the only way to represent it
|
||||
// is via `rgba`. Otherwise, we use the hex representation,
|
||||
// which has better compatibility with older browsers.
|
||||
// Values are capped between `0` and `255`, rounded and zero-padded.
|
||||
//
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.toCSS(env));
|
||||
},
|
||||
toCSS: function (env, doNotCompress) {
|
||||
var compress = env && env.compress && !doNotCompress;
|
||||
|
||||
// If we have some transparency, the only way to represent it
|
||||
// is via `rgba`. Otherwise, we use the hex representation,
|
||||
// which has better compatibility with older browsers.
|
||||
// Values are capped between `0` and `255`, rounded and zero-padded.
|
||||
if (this.alpha < 1.0) {
|
||||
return "rgba(" + this.rgb.map(function (c) {
|
||||
return Math.round(c);
|
||||
}).concat(this.alpha).join(',' + (compress ? '' : ' ')) + ")";
|
||||
} else {
|
||||
var color = this.rgb.map(function (i) {
|
||||
i = Math.round(i);
|
||||
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
|
||||
return i.length === 1 ? '0' + i : i;
|
||||
}).join('');
|
||||
var color = this.toRGB();
|
||||
|
||||
if (compress) {
|
||||
color = color.split('');
|
||||
var splitcolor = color.split('');
|
||||
|
||||
// Convert color to short format
|
||||
if (color[0] == color[1] && color[2] == color[3] && color[4] == color[5]) {
|
||||
color = color[0] + color[2] + color[4];
|
||||
} else {
|
||||
color = color.join('');
|
||||
if (splitcolor[1] === splitcolor[2] && splitcolor[3] === splitcolor[4] && splitcolor[5] === splitcolor[6]) {
|
||||
color = '#' + splitcolor[1] + splitcolor[3] + splitcolor[5];
|
||||
}
|
||||
}
|
||||
|
||||
return '#' + color;
|
||||
return color;
|
||||
}
|
||||
},
|
||||
|
||||
@@ -80,6 +76,14 @@ tree.Color.prototype = {
|
||||
return new(tree.Color)(result, this.alpha + other.alpha);
|
||||
},
|
||||
|
||||
toRGB: function () {
|
||||
return '#' + this.rgb.map(function (i) {
|
||||
i = Math.round(i);
|
||||
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
|
||||
return i.length === 1 ? '0' + i : i;
|
||||
}).join('');
|
||||
},
|
||||
|
||||
toHSL: function () {
|
||||
var r = this.rgb[0] / 255,
|
||||
g = this.rgb[1] / 255,
|
||||
|
||||
@@ -1,15 +1,28 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Comment = function (value, silent) {
|
||||
tree.Comment = function (value, silent, index, currentFileInfo) {
|
||||
this.value = value;
|
||||
this.silent = !!silent;
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
};
|
||||
tree.Comment.prototype = {
|
||||
type: "Comment",
|
||||
toCSS: function (env) {
|
||||
return env.compress ? '' : this.value;
|
||||
genCSS: function (env, output) {
|
||||
if (this.debugInfo) {
|
||||
output.add(tree.debugInfo(env, this), this.currentFileInfo, this.index);
|
||||
}
|
||||
output.add(this.value.trim()); //TODO shouldn't need to trim, we shouldn't grab the \n
|
||||
},
|
||||
eval: function () { return this }
|
||||
toCSS: tree.toCSS,
|
||||
isSilent: function(env) {
|
||||
var isReference = (this.currentFileInfo && this.currentFileInfo.reference && !this.isReferenced),
|
||||
isCompressed = env.compress && !this.value.match(/^\/\*!/);
|
||||
return this.silent || isReference || isCompressed;
|
||||
},
|
||||
eval: function () { return this; },
|
||||
markReferenced: function () {
|
||||
this.isReferenced = true;
|
||||
}
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -19,7 +19,7 @@ tree.Condition.prototype = {
|
||||
|
||||
var i = this.index, result;
|
||||
|
||||
var result = (function (op) {
|
||||
result = (function (op) {
|
||||
switch (op) {
|
||||
case 'and':
|
||||
return a && b;
|
||||
|
||||
@@ -20,7 +20,7 @@ tree.Dimension.prototype = {
|
||||
toColor: function () {
|
||||
return new(tree.Color)([this.value, this.value, this.value]);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
genCSS: function (env, output) {
|
||||
if ((env && env.strictUnits) && !this.unit.isSingular()) {
|
||||
throw new Error("Multiple units in dimension. Correct the units or use the unit function. Bad unit: "+this.unit.toString());
|
||||
}
|
||||
@@ -35,8 +35,9 @@ tree.Dimension.prototype = {
|
||||
|
||||
if (env && env.compress) {
|
||||
// Zero values doesn't need a unit
|
||||
if (value === 0 && !this.unit.isAngle()) {
|
||||
return strValue;
|
||||
if (value === 0 && this.unit.isLength()) {
|
||||
output.add(strValue);
|
||||
return;
|
||||
}
|
||||
|
||||
// Float values doesn't need a leading zero
|
||||
@@ -45,13 +46,16 @@ tree.Dimension.prototype = {
|
||||
}
|
||||
}
|
||||
|
||||
return strValue + this.unit.toCSS(env);
|
||||
output.add(strValue);
|
||||
this.unit.genCSS(env, output);
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
|
||||
// In an operation between two Dimensions,
|
||||
// we default to the first Dimension's unit,
|
||||
// so `1px + 2` will yield `3px`.
|
||||
operate: function (env, op, other) {
|
||||
/*jshint noempty:false */
|
||||
var value = tree.operate(env, op, this.value, other.value),
|
||||
unit = this.unit.clone();
|
||||
|
||||
@@ -59,7 +63,7 @@ tree.Dimension.prototype = {
|
||||
if (unit.numerator.length === 0 && unit.denominator.length === 0) {
|
||||
unit.numerator = other.unit.numerator.slice(0);
|
||||
unit.denominator = other.unit.denominator.slice(0);
|
||||
} else if (other.unit.numerator.length == 0 && unit.denominator.length == 0) {
|
||||
} else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {
|
||||
// do nothing
|
||||
} else {
|
||||
other = other.convertTo(this.unit.usedUnits());
|
||||
@@ -104,202 +108,206 @@ tree.Dimension.prototype = {
|
||||
},
|
||||
|
||||
unify: function () {
|
||||
return this.convertTo({ length: 'm', duration: 's', angle: 'rad' });
|
||||
return this.convertTo({ length: 'm', duration: 's', angle: 'rad' });
|
||||
},
|
||||
|
||||
convertTo: function (conversions) {
|
||||
var value = this.value, unit = this.unit.clone(),
|
||||
i, groupName, group, conversion, targetUnit, derivedConversions = {};
|
||||
var value = this.value, unit = this.unit.clone(),
|
||||
i, groupName, group, targetUnit, derivedConversions = {}, applyUnit;
|
||||
|
||||
if (typeof conversions === 'string') {
|
||||
for(i in tree.UnitConversions) {
|
||||
if (tree.UnitConversions[i].hasOwnProperty(conversions)) {
|
||||
derivedConversions = {};
|
||||
derivedConversions[i] = conversions;
|
||||
}
|
||||
}
|
||||
conversions = derivedConversions;
|
||||
}
|
||||
|
||||
for (groupName in conversions) {
|
||||
if (conversions.hasOwnProperty(groupName)) {
|
||||
targetUnit = conversions[groupName];
|
||||
group = tree.UnitConversions[groupName];
|
||||
|
||||
unit.map(function (atomicUnit, denominator) {
|
||||
if (typeof conversions === 'string') {
|
||||
for(i in tree.UnitConversions) {
|
||||
if (tree.UnitConversions[i].hasOwnProperty(conversions)) {
|
||||
derivedConversions = {};
|
||||
derivedConversions[i] = conversions;
|
||||
}
|
||||
}
|
||||
conversions = derivedConversions;
|
||||
}
|
||||
applyUnit = function (atomicUnit, denominator) {
|
||||
/*jshint loopfunc:true */
|
||||
if (group.hasOwnProperty(atomicUnit)) {
|
||||
if (denominator) {
|
||||
value = value / (group[atomicUnit] / group[targetUnit]);
|
||||
} else {
|
||||
value = value * (group[atomicUnit] / group[targetUnit]);
|
||||
}
|
||||
if (denominator) {
|
||||
value = value / (group[atomicUnit] / group[targetUnit]);
|
||||
} else {
|
||||
value = value * (group[atomicUnit] / group[targetUnit]);
|
||||
}
|
||||
|
||||
return targetUnit;
|
||||
return targetUnit;
|
||||
}
|
||||
|
||||
return atomicUnit;
|
||||
});
|
||||
};
|
||||
|
||||
for (groupName in conversions) {
|
||||
if (conversions.hasOwnProperty(groupName)) {
|
||||
targetUnit = conversions[groupName];
|
||||
group = tree.UnitConversions[groupName];
|
||||
|
||||
unit.map(applyUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
unit.cancel();
|
||||
unit.cancel();
|
||||
|
||||
return new(tree.Dimension)(value, unit);
|
||||
return new(tree.Dimension)(value, unit);
|
||||
}
|
||||
};
|
||||
|
||||
// http://www.w3.org/TR/css3-values/#absolute-lengths
|
||||
tree.UnitConversions = {
|
||||
length: {
|
||||
'm': 1,
|
||||
'cm': 0.01,
|
||||
'mm': 0.001,
|
||||
'in': 0.0254,
|
||||
'pt': 0.0254 / 72,
|
||||
'pc': 0.0254 / 72 * 12
|
||||
},
|
||||
duration: {
|
||||
's': 1,
|
||||
'ms': 0.001
|
||||
},
|
||||
angle: {
|
||||
'rad': 1/(2*Math.PI),
|
||||
'deg': 1/360,
|
||||
'grad': 1/400,
|
||||
'turn': 1
|
||||
}
|
||||
length: {
|
||||
'm': 1,
|
||||
'cm': 0.01,
|
||||
'mm': 0.001,
|
||||
'in': 0.0254,
|
||||
'pt': 0.0254 / 72,
|
||||
'pc': 0.0254 / 72 * 12
|
||||
},
|
||||
duration: {
|
||||
's': 1,
|
||||
'ms': 0.001
|
||||
},
|
||||
angle: {
|
||||
'rad': 1/(2*Math.PI),
|
||||
'deg': 1/360,
|
||||
'grad': 1/400,
|
||||
'turn': 1
|
||||
}
|
||||
};
|
||||
|
||||
tree.Unit = function (numerator, denominator, backupUnit) {
|
||||
this.numerator = numerator ? numerator.slice(0).sort() : [];
|
||||
this.denominator = denominator ? denominator.slice(0).sort() : [];
|
||||
this.backupUnit = backupUnit;
|
||||
this.numerator = numerator ? numerator.slice(0).sort() : [];
|
||||
this.denominator = denominator ? denominator.slice(0).sort() : [];
|
||||
this.backupUnit = backupUnit;
|
||||
};
|
||||
|
||||
tree.Unit.prototype = {
|
||||
type: "Unit",
|
||||
clone: function () {
|
||||
return new tree.Unit(this.numerator.slice(0), this.denominator.slice(0), this.backupUnit);
|
||||
},
|
||||
type: "Unit",
|
||||
clone: function () {
|
||||
return new tree.Unit(this.numerator.slice(0), this.denominator.slice(0), this.backupUnit);
|
||||
},
|
||||
genCSS: function (env, output) {
|
||||
if (this.numerator.length >= 1) {
|
||||
output.add(this.numerator[0]);
|
||||
} else
|
||||
if (this.denominator.length >= 1) {
|
||||
output.add(this.denominator[0]);
|
||||
} else
|
||||
if ((!env || !env.strictUnits) && this.backupUnit) {
|
||||
output.add(this.backupUnit);
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
|
||||
toCSS: function (env) {
|
||||
if (this.numerator.length >= 1) {
|
||||
return this.numerator[0];
|
||||
}
|
||||
if (this.denominator.length >= 1) {
|
||||
return this.denominator[0];
|
||||
}
|
||||
if ((!env || !env.strictUnits) && this.backupUnit) {
|
||||
return this.backupUnit;
|
||||
}
|
||||
return "";
|
||||
},
|
||||
|
||||
toString: function () {
|
||||
toString: function () {
|
||||
var i, returnStr = this.numerator.join("*");
|
||||
for (i = 0; i < this.denominator.length; i++) {
|
||||
returnStr += "/" + this.denominator[i];
|
||||
}
|
||||
return returnStr;
|
||||
},
|
||||
|
||||
compare: function (other) {
|
||||
return this.is(other.toString()) ? 0 : -1;
|
||||
},
|
||||
},
|
||||
|
||||
is: function (unitString) {
|
||||
return this.toString() === unitString;
|
||||
},
|
||||
compare: function (other) {
|
||||
return this.is(other.toString()) ? 0 : -1;
|
||||
},
|
||||
|
||||
isAngle: function () {
|
||||
return tree.UnitConversions.angle.hasOwnProperty(this.toCSS());
|
||||
},
|
||||
is: function (unitString) {
|
||||
return this.toString() === unitString;
|
||||
},
|
||||
|
||||
isEmpty: function () {
|
||||
return this.numerator.length == 0 && this.denominator.length == 0;
|
||||
},
|
||||
isLength: function () {
|
||||
return Boolean(this.toCSS().match(/px|em|%|in|cm|mm|pc|pt|ex/));
|
||||
},
|
||||
|
||||
isSingular: function() {
|
||||
return this.numerator.length <= 1 && this.denominator.length == 0;
|
||||
},
|
||||
isEmpty: function () {
|
||||
return this.numerator.length === 0 && this.denominator.length === 0;
|
||||
},
|
||||
|
||||
map: function(callback) {
|
||||
var i;
|
||||
isSingular: function() {
|
||||
return this.numerator.length <= 1 && this.denominator.length === 0;
|
||||
},
|
||||
|
||||
for (i = 0; i < this.numerator.length; i++) {
|
||||
this.numerator[i] = callback(this.numerator[i], false);
|
||||
}
|
||||
map: function(callback) {
|
||||
var i;
|
||||
|
||||
for (i = 0; i < this.denominator.length; i++) {
|
||||
this.denominator[i] = callback(this.denominator[i], true);
|
||||
}
|
||||
},
|
||||
|
||||
usedUnits: function() {
|
||||
var group, groupName, result = {};
|
||||
|
||||
for (groupName in tree.UnitConversions) {
|
||||
if (tree.UnitConversions.hasOwnProperty(groupName)) {
|
||||
group = tree.UnitConversions[groupName];
|
||||
|
||||
this.map(function (atomicUnit) {
|
||||
if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
|
||||
result[groupName] = atomicUnit;
|
||||
}
|
||||
|
||||
return atomicUnit;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
return result;
|
||||
},
|
||||
|
||||
cancel: function () {
|
||||
var counter = {}, atomicUnit, i, backup;
|
||||
|
||||
for (i = 0; i < this.numerator.length; i++) {
|
||||
atomicUnit = this.numerator[i];
|
||||
if (!backup) {
|
||||
backup = atomicUnit;
|
||||
for (i = 0; i < this.numerator.length; i++) {
|
||||
this.numerator[i] = callback(this.numerator[i], false);
|
||||
}
|
||||
counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < this.denominator.length; i++) {
|
||||
atomicUnit = this.denominator[i];
|
||||
if (!backup) {
|
||||
backup = atomicUnit;
|
||||
for (i = 0; i < this.denominator.length; i++) {
|
||||
this.denominator[i] = callback(this.denominator[i], true);
|
||||
}
|
||||
counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
|
||||
}
|
||||
},
|
||||
|
||||
this.numerator = [];
|
||||
this.denominator = [];
|
||||
usedUnits: function() {
|
||||
var group, result = {}, mapUnit;
|
||||
|
||||
for (atomicUnit in counter) {
|
||||
if (counter.hasOwnProperty(atomicUnit)) {
|
||||
var count = counter[atomicUnit];
|
||||
mapUnit = function (atomicUnit) {
|
||||
/*jshint loopfunc:true */
|
||||
if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
|
||||
result[groupName] = atomicUnit;
|
||||
}
|
||||
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
this.numerator.push(atomicUnit);
|
||||
}
|
||||
} else if (count < 0) {
|
||||
for (i = 0; i < -count; i++) {
|
||||
this.denominator.push(atomicUnit);
|
||||
}
|
||||
return atomicUnit;
|
||||
};
|
||||
|
||||
for (var groupName in tree.UnitConversions) {
|
||||
if (tree.UnitConversions.hasOwnProperty(groupName)) {
|
||||
group = tree.UnitConversions[groupName];
|
||||
|
||||
this.map(mapUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.numerator.length === 0 && this.denominator.length === 0 && backup) {
|
||||
this.backupUnit = backup;
|
||||
}
|
||||
return result;
|
||||
},
|
||||
|
||||
this.numerator.sort();
|
||||
this.denominator.sort();
|
||||
}
|
||||
cancel: function () {
|
||||
var counter = {}, atomicUnit, i, backup;
|
||||
|
||||
for (i = 0; i < this.numerator.length; i++) {
|
||||
atomicUnit = this.numerator[i];
|
||||
if (!backup) {
|
||||
backup = atomicUnit;
|
||||
}
|
||||
counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
|
||||
}
|
||||
|
||||
for (i = 0; i < this.denominator.length; i++) {
|
||||
atomicUnit = this.denominator[i];
|
||||
if (!backup) {
|
||||
backup = atomicUnit;
|
||||
}
|
||||
counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
|
||||
}
|
||||
|
||||
this.numerator = [];
|
||||
this.denominator = [];
|
||||
|
||||
for (atomicUnit in counter) {
|
||||
if (counter.hasOwnProperty(atomicUnit)) {
|
||||
var count = counter[atomicUnit];
|
||||
|
||||
if (count > 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
this.numerator.push(atomicUnit);
|
||||
}
|
||||
} else if (count < 0) {
|
||||
for (i = 0; i < -count; i++) {
|
||||
this.denominator.push(atomicUnit);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (this.numerator.length === 0 && this.denominator.length === 0 && backup) {
|
||||
this.backupUnit = backup;
|
||||
}
|
||||
|
||||
this.numerator.sort();
|
||||
this.denominator.sort();
|
||||
}
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -1,44 +1,60 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Directive = function (name, value) {
|
||||
tree.Directive = function (name, value, index, currentFileInfo) {
|
||||
this.name = name;
|
||||
|
||||
if (Array.isArray(value)) {
|
||||
this.ruleset = new(tree.Ruleset)([], value);
|
||||
this.ruleset.allowImports = true;
|
||||
this.rules = [new(tree.Ruleset)([], value)];
|
||||
this.rules[0].allowImports = true;
|
||||
} else {
|
||||
this.value = value;
|
||||
}
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
|
||||
};
|
||||
tree.Directive.prototype = {
|
||||
type: "Directive",
|
||||
accept: function (visitor) {
|
||||
this.ruleset = visitor.visit(this.ruleset);
|
||||
this.rules = visitor.visit(this.rules);
|
||||
this.value = visitor.visit(this.value);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
if (this.ruleset) {
|
||||
this.ruleset.root = true;
|
||||
return this.name + (env.compress ? '{' : ' {\n ') +
|
||||
this.ruleset.toCSS(env).trim().replace(/\n/g, '\n ') +
|
||||
(env.compress ? '}': '\n}\n');
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.name, this.currentFileInfo, this.index);
|
||||
if (this.rules) {
|
||||
tree.outputRuleset(env, output, this.rules);
|
||||
} else {
|
||||
return this.name + ' ' + this.value.toCSS() + ';\n';
|
||||
output.add(' ');
|
||||
this.value.genCSS(env, output);
|
||||
output.add(';');
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (env) {
|
||||
var evaldDirective = this;
|
||||
if (this.ruleset) {
|
||||
if (this.rules) {
|
||||
env.frames.unshift(this);
|
||||
evaldDirective = new(tree.Directive)(this.name);
|
||||
evaldDirective.ruleset = this.ruleset.eval(env);
|
||||
evaldDirective = new(tree.Directive)(this.name, null, this.index, this.currentFileInfo);
|
||||
evaldDirective.rules = [this.rules[0].eval(env)];
|
||||
evaldDirective.rules[0].root = true;
|
||||
env.frames.shift();
|
||||
}
|
||||
return evaldDirective;
|
||||
},
|
||||
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
|
||||
find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
|
||||
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) }
|
||||
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.rules[0], name); },
|
||||
find: function () { return tree.Ruleset.prototype.find.apply(this.rules[0], arguments); },
|
||||
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.rules[0]); },
|
||||
markReferenced: function () {
|
||||
var i, rules;
|
||||
this.isReferenced = true;
|
||||
if (this.rules) {
|
||||
rules = this.rules[0].rules;
|
||||
for (i = 0; i < rules.length; i++) {
|
||||
if (rules[i].markReferenced) {
|
||||
rules[i].markReferenced();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Element = function (combinator, value, index) {
|
||||
tree.Element = function (combinator, value, index, currentFileInfo) {
|
||||
this.combinator = combinator instanceof tree.Combinator ?
|
||||
combinator : new(tree.Combinator)(combinator);
|
||||
|
||||
@@ -12,6 +12,7 @@ tree.Element = function (combinator, value, index) {
|
||||
this.value = "";
|
||||
}
|
||||
this.index = index;
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
};
|
||||
tree.Element.prototype = {
|
||||
type: "Element",
|
||||
@@ -22,11 +23,15 @@ tree.Element.prototype = {
|
||||
eval: function (env) {
|
||||
return new(tree.Element)(this.combinator,
|
||||
this.value.eval ? this.value.eval(env) : this.value,
|
||||
this.index);
|
||||
this.index,
|
||||
this.currentFileInfo);
|
||||
},
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.toCSS(env), this.currentFileInfo, this.index);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
var value = (this.value.toCSS ? this.value.toCSS(env) : this.value);
|
||||
if (value == '' && this.combinator.value.charAt(0) == '&') {
|
||||
if (value === '' && this.combinator.value.charAt(0) === '&') {
|
||||
return '';
|
||||
} else {
|
||||
return this.combinator.toCSS(env || {}) + value;
|
||||
@@ -48,6 +53,9 @@ tree.Attribute.prototype = {
|
||||
return new(tree.Attribute)(this.key.eval ? this.key.eval(env) : this.key,
|
||||
this.op, (this.value && this.value.eval) ? this.value.eval(env) : this.value);
|
||||
},
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.toCSS(env));
|
||||
},
|
||||
toCSS: function (env) {
|
||||
var value = this.key.toCSS ? this.key.toCSS(env) : this.key;
|
||||
|
||||
@@ -69,17 +77,28 @@ tree.Combinator = function (value) {
|
||||
};
|
||||
tree.Combinator.prototype = {
|
||||
type: "Combinator",
|
||||
toCSS: function (env) {
|
||||
return {
|
||||
'' : '',
|
||||
' ' : ' ',
|
||||
':' : ' :',
|
||||
'+' : env.compress ? '+' : ' + ',
|
||||
'~' : env.compress ? '~' : ' ~ ',
|
||||
'>' : env.compress ? '>' : ' > ',
|
||||
'|' : env.compress ? '|' : ' | '
|
||||
}[this.value];
|
||||
}
|
||||
_outputMap: {
|
||||
'' : '',
|
||||
' ' : ' ',
|
||||
':' : ' :',
|
||||
'+' : ' + ',
|
||||
'~' : ' ~ ',
|
||||
'>' : ' > ',
|
||||
'|' : '|'
|
||||
},
|
||||
_outputMapCompressed: {
|
||||
'' : '',
|
||||
' ' : ' ',
|
||||
':' : ' :',
|
||||
'+' : '+',
|
||||
'~' : '~',
|
||||
'>' : '>',
|
||||
'|' : '|'
|
||||
},
|
||||
genCSS: function (env, output) {
|
||||
output.add((env.compress ? this._outputMapCompressed : this._outputMap)[this.value]);
|
||||
},
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -33,11 +33,15 @@ tree.Expression.prototype = {
|
||||
}
|
||||
return returnValue;
|
||||
},
|
||||
toCSS: function (env) {
|
||||
return this.value.map(function (e) {
|
||||
return e.toCSS ? e.toCSS(env) : '';
|
||||
}).join(' ');
|
||||
genCSS: function (env, output) {
|
||||
for(var i = 0; i < this.value.length; i++) {
|
||||
this.value[i].genCSS(env, output);
|
||||
if (i + 1 < this.value.length) {
|
||||
output.add(" ");
|
||||
}
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
throwAwayComments: function () {
|
||||
this.value = this.value.filter(function(v) {
|
||||
return !(v instanceof tree.Comment);
|
||||
|
||||
@@ -12,16 +12,14 @@
|
||||
// the file has been fetched, and parsed.
|
||||
//
|
||||
tree.Import = function (path, features, options, index, currentFileInfo) {
|
||||
var that = this;
|
||||
|
||||
this.options = options;
|
||||
this.index = index;
|
||||
this.path = path;
|
||||
this.features = features;
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
|
||||
if (this.options.less !== undefined) {
|
||||
this.css = !this.options.less;
|
||||
if (this.options.less !== undefined || this.options.inline) {
|
||||
this.css = !this.options.less || this.options.inline;
|
||||
} else {
|
||||
var pathValue = this.getPath();
|
||||
if (pathValue && /css([\?;].*)?$/.test(pathValue)) {
|
||||
@@ -44,17 +42,22 @@ tree.Import.prototype = {
|
||||
accept: function (visitor) {
|
||||
this.features = visitor.visit(this.features);
|
||||
this.path = visitor.visit(this.path);
|
||||
this.root = visitor.visit(this.root);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
var features = this.features ? ' ' + this.features.toCSS(env) : '';
|
||||
|
||||
if (this.css) {
|
||||
return "@import " + this.path.toCSS() + features + ';\n';
|
||||
} else {
|
||||
return "";
|
||||
if (!this.options.inline) {
|
||||
this.root = visitor.visit(this.root);
|
||||
}
|
||||
},
|
||||
genCSS: function (env, output) {
|
||||
if (this.css) {
|
||||
output.add("@import ", this.currentFileInfo, this.index);
|
||||
this.path.genCSS(env, output);
|
||||
if (this.features) {
|
||||
output.add(" ");
|
||||
this.features.genCSS(env, output);
|
||||
}
|
||||
output.add(';');
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
getPath: function () {
|
||||
if (this.path instanceof tree.Quoted) {
|
||||
var path = this.path.value;
|
||||
@@ -70,13 +73,18 @@ tree.Import.prototype = {
|
||||
evalPath: function (env) {
|
||||
var path = this.path.eval(env);
|
||||
var rootpath = this.currentFileInfo && this.currentFileInfo.rootpath;
|
||||
if (rootpath && !(path instanceof tree.URL)) {
|
||||
var pathValue = path.value;
|
||||
// Add the base path if the import is relative
|
||||
if (pathValue && env.isPathRelative(pathValue)) {
|
||||
path.value = rootpath + pathValue;
|
||||
|
||||
if (!(path instanceof tree.URL)) {
|
||||
if (rootpath) {
|
||||
var pathValue = path.value;
|
||||
// Add the base path if the import is relative
|
||||
if (pathValue && env.isPathRelative(pathValue)) {
|
||||
path.value = rootpath + pathValue;
|
||||
}
|
||||
}
|
||||
path.value = env.normalizePath(path.value);
|
||||
}
|
||||
|
||||
return path;
|
||||
},
|
||||
eval: function (env) {
|
||||
@@ -84,7 +92,10 @@ tree.Import.prototype = {
|
||||
|
||||
if (this.skip) { return []; }
|
||||
|
||||
if (this.css) {
|
||||
if (this.options.inline) {
|
||||
var contents = new(tree.Anonymous)(this.root);
|
||||
return this.features ? new(tree.Media)([contents], this.features.value) : [contents];
|
||||
} else if (this.css) {
|
||||
var newImport = new(tree.Import)(this.evalPath(env), features, this.options, this.index);
|
||||
if (!newImport.css && this.error) {
|
||||
throw this.error;
|
||||
|
||||
@@ -19,11 +19,12 @@ tree.JavaScript.prototype = {
|
||||
try {
|
||||
expression = new(Function)('return (' + expression + ')');
|
||||
} catch (e) {
|
||||
throw { message: "JavaScript evaluation error: `" + expression + "`" ,
|
||||
throw { message: "JavaScript evaluation error: " + e.message + " from `" + expression + "`" ,
|
||||
index: this.index };
|
||||
}
|
||||
|
||||
for (var k in env.frames[0].variables()) {
|
||||
/*jshint loopfunc:true */
|
||||
context[k.slice(1)] = {
|
||||
value: env.frames[0].variables()[k].value,
|
||||
toJS: function () {
|
||||
|
||||
@@ -1,10 +1,13 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Keyword = function (value) { this.value = value };
|
||||
tree.Keyword = function (value) { this.value = value; };
|
||||
tree.Keyword.prototype = {
|
||||
type: "Keyword",
|
||||
eval: function () { return this; },
|
||||
toCSS: function () { return this.value; },
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.value);
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
compare: function (other) {
|
||||
if (other instanceof tree.Keyword) {
|
||||
return other.value === this.value ? 0 : 1;
|
||||
|
||||
@@ -1,34 +1,36 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Media = function (value, features) {
|
||||
tree.Media = function (value, features, index, currentFileInfo) {
|
||||
this.index = index;
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
|
||||
var selectors = this.emptySelectors();
|
||||
|
||||
this.features = new(tree.Value)(features);
|
||||
this.ruleset = new(tree.Ruleset)(selectors, value);
|
||||
this.ruleset.allowImports = true;
|
||||
this.rules = [new(tree.Ruleset)(selectors, value)];
|
||||
this.rules[0].allowImports = true;
|
||||
};
|
||||
tree.Media.prototype = {
|
||||
type: "Media",
|
||||
accept: function (visitor) {
|
||||
this.features = visitor.visit(this.features);
|
||||
this.ruleset = visitor.visit(this.ruleset);
|
||||
this.rules = visitor.visit(this.rules);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
var features = this.features.toCSS(env);
|
||||
|
||||
return '@media ' + features + (env.compress ? '{' : ' {\n ') +
|
||||
this.ruleset.toCSS(env).trim().replace(/\n/g, '\n ') +
|
||||
(env.compress ? '}': '\n}\n');
|
||||
genCSS: function (env, output) {
|
||||
output.add('@media ', this.currentFileInfo, this.index);
|
||||
this.features.genCSS(env, output);
|
||||
tree.outputRuleset(env, output, this.rules);
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (env) {
|
||||
if (!env.mediaBlocks) {
|
||||
env.mediaBlocks = [];
|
||||
env.mediaPath = [];
|
||||
}
|
||||
|
||||
var media = new(tree.Media)([], []);
|
||||
var media = new(tree.Media)([], [], this.index, this.currentFileInfo);
|
||||
if(this.debugInfo) {
|
||||
this.ruleset.debugInfo = this.debugInfo;
|
||||
this.rules[0].debugInfo = this.debugInfo;
|
||||
media.debugInfo = this.debugInfo;
|
||||
}
|
||||
var strictMathBypass = false;
|
||||
@@ -48,21 +50,30 @@ tree.Media.prototype = {
|
||||
env.mediaPath.push(media);
|
||||
env.mediaBlocks.push(media);
|
||||
|
||||
env.frames.unshift(this.ruleset);
|
||||
media.ruleset = this.ruleset.eval(env);
|
||||
env.frames.unshift(this.rules[0]);
|
||||
media.rules = [this.rules[0].eval(env)];
|
||||
env.frames.shift();
|
||||
|
||||
env.mediaPath.pop();
|
||||
|
||||
return env.mediaPath.length === 0 ? media.evalTop(env) :
|
||||
media.evalNested(env)
|
||||
media.evalNested(env);
|
||||
},
|
||||
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
|
||||
find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
|
||||
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) },
|
||||
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.rules[0], name); },
|
||||
find: function () { return tree.Ruleset.prototype.find.apply(this.rules[0], arguments); },
|
||||
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.rules[0]); },
|
||||
emptySelectors: function() {
|
||||
var el = new(tree.Element)('', '&', 0);
|
||||
return [new(tree.Selector)([el])];
|
||||
var el = new(tree.Element)('', '&', this.index, this.currentFileInfo);
|
||||
return [new(tree.Selector)([el], null, null, this.index, this.currentFileInfo)];
|
||||
},
|
||||
markReferenced: function () {
|
||||
var i, rules = this.rules[0].rules;
|
||||
this.isReferenced = true;
|
||||
for (i = 0; i < rules.length; i++) {
|
||||
if (rules[i].markReferenced) {
|
||||
rules[i].markReferenced();
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
evalTop: function (env) {
|
||||
@@ -130,7 +141,7 @@ tree.Media.prototype = {
|
||||
}
|
||||
},
|
||||
bubbleSelectors: function (selectors) {
|
||||
this.ruleset = new(tree.Ruleset)(selectors.slice(0), [this.ruleset]);
|
||||
this.rules = [new(tree.Ruleset)(selectors.slice(0), [this.rules[0]])];
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ tree.mixin.Call.prototype = {
|
||||
this.arguments = visitor.visit(this.arguments);
|
||||
},
|
||||
eval: function (env) {
|
||||
var mixins, mixin, args, rules = [], match = false, i, m, f, isRecursive, isOneFound;
|
||||
var mixins, mixin, args, rules = [], match = false, i, m, f, isRecursive, isOneFound, rule;
|
||||
|
||||
args = this.arguments && this.arguments.map(function (a) {
|
||||
return { name: a.name, value: a.value.eval(env) };
|
||||
@@ -39,6 +39,9 @@ tree.mixin.Call.prototype = {
|
||||
if (mixin.matchArgs(args, env)) {
|
||||
if (!mixin.matchCondition || mixin.matchCondition(args, env)) {
|
||||
try {
|
||||
if (!(mixin instanceof tree.mixin.Definition)) {
|
||||
mixin = new tree.mixin.Definition("", [], mixin.rules, null, false);
|
||||
}
|
||||
Array.prototype.push.apply(
|
||||
rules, mixin.eval(env, args, this.important).rules);
|
||||
} catch (e) {
|
||||
@@ -49,6 +52,14 @@ tree.mixin.Call.prototype = {
|
||||
}
|
||||
}
|
||||
if (match) {
|
||||
if (!this.currentFileInfo || !this.currentFileInfo.reference) {
|
||||
for (i = 0; i < rules.length; i++) {
|
||||
rule = rules[i];
|
||||
if (rule.markReferenced) {
|
||||
rule.markReferenced();
|
||||
}
|
||||
}
|
||||
}
|
||||
return rules;
|
||||
}
|
||||
}
|
||||
@@ -80,7 +91,7 @@ tree.mixin.Call.prototype = {
|
||||
|
||||
tree.mixin.Definition = function (name, params, rules, condition, variadic) {
|
||||
this.name = name;
|
||||
this.selectors = [new(tree.Selector)([new(tree.Element)(null, name)])];
|
||||
this.selectors = [new(tree.Selector)([new(tree.Element)(null, name, this.index, this.currentFileInfo)])];
|
||||
this.params = params;
|
||||
this.condition = condition;
|
||||
this.variadic = variadic;
|
||||
@@ -88,8 +99,8 @@ tree.mixin.Definition = function (name, params, rules, condition, variadic) {
|
||||
this.rules = rules;
|
||||
this._lookups = {};
|
||||
this.required = params.reduce(function (count, p) {
|
||||
if (!p.name || (p.name && !p.value)) { return count + 1 }
|
||||
else { return count }
|
||||
if (!p.name || (p.name && !p.value)) { return count + 1; }
|
||||
else { return count; }
|
||||
}, 0);
|
||||
this.parent = tree.Ruleset.prototype;
|
||||
this.frames = [];
|
||||
@@ -101,13 +112,13 @@ tree.mixin.Definition.prototype = {
|
||||
this.rules = visitor.visit(this.rules);
|
||||
this.condition = visitor.visit(this.condition);
|
||||
},
|
||||
toCSS: function () { return ""; },
|
||||
variable: function (name) { return this.parent.variable.call(this, name); },
|
||||
variables: function () { return this.parent.variables.call(this); },
|
||||
find: function () { return this.parent.find.apply(this, arguments); },
|
||||
rulesets: function () { return this.parent.rulesets.apply(this); },
|
||||
|
||||
evalParams: function (env, mixinEnv, args, evaldArguments) {
|
||||
/*jshint boss:true */
|
||||
var frame = new(tree.Ruleset)(null, []),
|
||||
varargs, arg,
|
||||
params = this.params.slice(0),
|
||||
@@ -143,7 +154,7 @@ tree.mixin.Definition.prototype = {
|
||||
}
|
||||
argIndex = 0;
|
||||
for (i = 0; i < params.length; i++) {
|
||||
if (evaldArguments[i]) continue;
|
||||
if (evaldArguments[i]) { continue; }
|
||||
|
||||
arg = args && args[argIndex];
|
||||
|
||||
@@ -185,7 +196,7 @@ tree.mixin.Definition.prototype = {
|
||||
var _arguments = [],
|
||||
mixinFrames = this.frames.concat(env.frames),
|
||||
frame = this.evalParams(env, new(tree.evalEnv)(env, mixinFrames), args, _arguments),
|
||||
context, rules, start, ruleset;
|
||||
rules, ruleset;
|
||||
|
||||
frame.rules.unshift(new(tree.Rule)('@arguments', new(tree.Expression)(_arguments).eval(env)));
|
||||
|
||||
@@ -208,12 +219,12 @@ tree.mixin.Definition.prototype = {
|
||||
return true;
|
||||
},
|
||||
matchArgs: function (args, env) {
|
||||
var argsLength = (args && args.length) || 0, len, frame;
|
||||
var argsLength = (args && args.length) || 0, len;
|
||||
|
||||
if (! this.variadic) {
|
||||
if (argsLength < this.required) { return false }
|
||||
if (argsLength > this.params.length) { return false }
|
||||
if ((this.required > 0) && (argsLength > this.params.length)) { return false }
|
||||
if (argsLength < this.required) { return false; }
|
||||
if (argsLength > this.params.length) { return false; }
|
||||
if ((this.required > 0) && (argsLength > this.params.length)) { return false; }
|
||||
}
|
||||
|
||||
len = Math.min(argsLength, this.arity);
|
||||
|
||||
@@ -8,9 +8,11 @@ tree.Negative.prototype = {
|
||||
accept: function (visitor) {
|
||||
this.value = visitor.visit(this.value);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
return '-' + this.value.toCSS(env);
|
||||
genCSS: function (env, output) {
|
||||
output.add('-');
|
||||
this.value.genCSS(env, output);
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (env) {
|
||||
if (env.isMathOn()) {
|
||||
return (new(tree.Operation)('*', [new(tree.Dimension)(-1), this.value])).eval(env);
|
||||
|
||||
@@ -34,10 +34,18 @@ tree.Operation.prototype = {
|
||||
return new(tree.Operation)(this.op, [a, b], this.isSpaced);
|
||||
}
|
||||
},
|
||||
toCSS: function (env) {
|
||||
var separator = this.isSpaced ? " " : "";
|
||||
return this.operands[0].toCSS() + separator + this.op + separator + this.operands[1].toCSS();
|
||||
}
|
||||
genCSS: function (env, output) {
|
||||
this.operands[0].genCSS(env, output);
|
||||
if (this.isSpaced) {
|
||||
output.add(" ");
|
||||
}
|
||||
output.add(this.op);
|
||||
if (this.isSpaced) {
|
||||
output.add(" ");
|
||||
}
|
||||
this.operands[1].genCSS(env, output);
|
||||
},
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
tree.operate = function (env, op, a, b) {
|
||||
|
||||
@@ -9,9 +9,12 @@ tree.Paren.prototype = {
|
||||
accept: function (visitor) {
|
||||
this.value = visitor.visit(this.value);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
return '(' + this.value.toCSS(env).trim() + ')';
|
||||
genCSS: function (env, output) {
|
||||
output.add('(');
|
||||
this.value.genCSS(env, output);
|
||||
output.add(')');
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (env) {
|
||||
return new(tree.Paren)(this.value.eval(env));
|
||||
}
|
||||
|
||||
@@ -9,13 +9,16 @@ tree.Quoted = function (str, content, escaped, index, currentFileInfo) {
|
||||
};
|
||||
tree.Quoted.prototype = {
|
||||
type: "Quoted",
|
||||
toCSS: function () {
|
||||
if (this.escaped) {
|
||||
return this.value;
|
||||
} else {
|
||||
return this.quote + this.value + this.quote;
|
||||
genCSS: function (env, output) {
|
||||
if (!this.escaped) {
|
||||
output.add(this.quote, this.currentFileInfo, this.index);
|
||||
}
|
||||
output.add(this.value);
|
||||
if (!this.escaped) {
|
||||
output.add(this.quote);
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (env) {
|
||||
var that = this;
|
||||
var value = this.value.replace(/`([^`]+)`/g, function (_, exp) {
|
||||
|
||||
@@ -1,16 +1,14 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Rule = function (name, value, important, index, currentFileInfo, inline) {
|
||||
tree.Rule = function (name, value, important, merge, index, currentFileInfo, inline) {
|
||||
this.name = name;
|
||||
this.value = (value instanceof tree.Value) ? value : new(tree.Value)([value]);
|
||||
this.important = important ? ' ' + important.trim() : '';
|
||||
this.merge = merge;
|
||||
this.index = index;
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
this.inline = inline || false;
|
||||
|
||||
if (name.charAt(0) === '@') {
|
||||
this.variable = true;
|
||||
} else { this.variable = false }
|
||||
this.variable = (name.charAt(0) === '@');
|
||||
};
|
||||
|
||||
tree.Rule.prototype = {
|
||||
@@ -18,21 +16,19 @@ tree.Rule.prototype = {
|
||||
accept: function (visitor) {
|
||||
this.value = visitor.visit(this.value);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
if (this.variable) { return "" }
|
||||
else {
|
||||
try {
|
||||
return this.name + (env.compress ? ':' : ': ') +
|
||||
this.value.toCSS(env) +
|
||||
this.important + (this.inline ? "" : ";");
|
||||
}
|
||||
catch(e) {
|
||||
e.index = this.index;
|
||||
e.filename = this.currentFileInfo.filename;
|
||||
throw e;
|
||||
}
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.name + (env.compress ? ':' : ': '), this.currentFileInfo, this.index);
|
||||
try {
|
||||
this.value.genCSS(env, output);
|
||||
}
|
||||
catch(e) {
|
||||
e.index = this.index;
|
||||
e.filename = this.currentFileInfo.filename;
|
||||
throw e;
|
||||
}
|
||||
output.add(this.important + ((this.inline || (env.lastRule && env.compress)) ? "" : ";"), this.currentFileInfo, this.index);
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (env) {
|
||||
var strictMathBypass = false;
|
||||
if (this.name === "font" && !env.strictMath) {
|
||||
@@ -43,6 +39,7 @@ tree.Rule.prototype = {
|
||||
return new(tree.Rule)(this.name,
|
||||
this.value.eval(env),
|
||||
this.important,
|
||||
this.merge,
|
||||
this.index, this.currentFileInfo, this.inline);
|
||||
}
|
||||
finally {
|
||||
@@ -55,6 +52,7 @@ tree.Rule.prototype = {
|
||||
return new(tree.Rule)(this.name,
|
||||
this.value,
|
||||
"!important",
|
||||
this.merge,
|
||||
this.index, this.currentFileInfo, this.inline);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -9,13 +9,21 @@ tree.Ruleset = function (selectors, rules, strictImports) {
|
||||
tree.Ruleset.prototype = {
|
||||
type: "Ruleset",
|
||||
accept: function (visitor) {
|
||||
this.selectors = visitor.visit(this.selectors);
|
||||
if (this.paths) {
|
||||
for(var i = 0; i < this.paths.length; i++) {
|
||||
this.paths[i] = visitor.visit(this.paths[i]);
|
||||
}
|
||||
} else {
|
||||
this.selectors = visitor.visit(this.selectors);
|
||||
}
|
||||
this.rules = visitor.visit(this.rules);
|
||||
},
|
||||
eval: function (env) {
|
||||
var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env) });
|
||||
var selectors = this.selectors && this.selectors.map(function (s) { return s.eval(env); });
|
||||
var ruleset = new(tree.Ruleset)(selectors, this.rules.slice(0), this.strictImports);
|
||||
var rules;
|
||||
var rule;
|
||||
var i;
|
||||
|
||||
ruleset.originalRuleset = this;
|
||||
ruleset.root = this.root;
|
||||
@@ -42,7 +50,7 @@ tree.Ruleset.prototype = {
|
||||
|
||||
// Store the frames around mixin definitions,
|
||||
// so they can be evaluated like closures when the time comes.
|
||||
for (var i = 0; i < ruleset.rules.length; i++) {
|
||||
for (i = 0; i < ruleset.rules.length; i++) {
|
||||
if (ruleset.rules[i] instanceof tree.mixin.Definition) {
|
||||
ruleset.rules[i].frames = env.frames.slice(0);
|
||||
}
|
||||
@@ -51,8 +59,9 @@ tree.Ruleset.prototype = {
|
||||
var mediaBlockCount = (env.mediaBlocks && env.mediaBlocks.length) || 0;
|
||||
|
||||
// Evaluate mixin calls.
|
||||
for (var i = 0; i < ruleset.rules.length; i++) {
|
||||
for (i = 0; i < ruleset.rules.length; i++) {
|
||||
if (ruleset.rules[i] instanceof tree.mixin.Call) {
|
||||
/*jshint loopfunc:true */
|
||||
rules = ruleset.rules[i].eval(env).filter(function(r) {
|
||||
if ((r instanceof tree.Rule) && r.variable) {
|
||||
// do not pollute the scope if the variable is
|
||||
@@ -69,7 +78,7 @@ tree.Ruleset.prototype = {
|
||||
}
|
||||
|
||||
// Evaluate everything else
|
||||
for (var i = 0, rule; i < ruleset.rules.length; i++) {
|
||||
for (i = 0; i < ruleset.rules.length; i++) {
|
||||
rule = ruleset.rules[i];
|
||||
|
||||
if (! (rule instanceof tree.mixin.Definition)) {
|
||||
@@ -82,7 +91,7 @@ tree.Ruleset.prototype = {
|
||||
env.selectors.shift();
|
||||
|
||||
if (env.mediaBlocks) {
|
||||
for(var i = mediaBlockCount; i < env.mediaBlocks.length; i++) {
|
||||
for (i = mediaBlockCount; i < env.mediaBlocks.length; i++) {
|
||||
env.mediaBlocks[i].bubbleSelectors(selectors);
|
||||
}
|
||||
}
|
||||
@@ -116,13 +125,23 @@ tree.Ruleset.prototype = {
|
||||
matchArgs: function (args) {
|
||||
return !args || args.length === 0;
|
||||
},
|
||||
matchCondition: function (args, env) {
|
||||
var lastSelector = this.selectors[this.selectors.length-1];
|
||||
if (lastSelector.condition &&
|
||||
!lastSelector.condition.eval(
|
||||
new(tree.evalEnv)(env,
|
||||
env.frames))) {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
},
|
||||
resetCache: function () {
|
||||
this._rulesets = null;
|
||||
this._variables = null;
|
||||
this._lookups = {};
|
||||
},
|
||||
variables: function () {
|
||||
if (this._variables) { return this._variables }
|
||||
if (this._variables) { return this._variables; }
|
||||
else {
|
||||
return this._variables = this.rules.reduce(function (hash, r) {
|
||||
if (r instanceof tree.Rule && r.variable === true) {
|
||||
@@ -142,10 +161,10 @@ tree.Ruleset.prototype = {
|
||||
},
|
||||
find: function (selector, self) {
|
||||
self = self || this;
|
||||
var rules = [], rule, match,
|
||||
var rules = [], match,
|
||||
key = selector.toCSS();
|
||||
|
||||
if (key in this._lookups) { return this._lookups[key] }
|
||||
if (key in this._lookups) { return this._lookups[key]; }
|
||||
|
||||
this.rulesets().forEach(function (rule) {
|
||||
if (rule !== self) {
|
||||
@@ -164,106 +183,104 @@ tree.Ruleset.prototype = {
|
||||
});
|
||||
return this._lookups[key] = rules;
|
||||
},
|
||||
//
|
||||
// Entry point for code generation
|
||||
//
|
||||
// `context` holds an array of arrays.
|
||||
//
|
||||
toCSS: function (env) {
|
||||
var css = [], // The CSS output
|
||||
rules = [], // node.Rule instances
|
||||
_rules = [], //
|
||||
rulesets = [], // node.Ruleset instances
|
||||
selector, // The fully rendered selector
|
||||
genCSS: function (env, output) {
|
||||
var i, j,
|
||||
ruleNodes = [],
|
||||
rulesetNodes = [],
|
||||
debugInfo, // Line number debugging
|
||||
rule;
|
||||
rule,
|
||||
firstRuleset = true,
|
||||
path;
|
||||
|
||||
// Compile rules and rulesets
|
||||
for (var i = 0; i < this.rules.length; i++) {
|
||||
rule = this.rules[i];
|
||||
env.tabLevel = (env.tabLevel || 0);
|
||||
|
||||
if (rule.rules || (rule instanceof tree.Media)) {
|
||||
rulesets.push(rule.toCSS(env));
|
||||
} else if (rule instanceof tree.Directive) {
|
||||
var cssValue = rule.toCSS(env);
|
||||
// Output only the first @charset definition as such - convert the others
|
||||
// to comments in case debug is enabled
|
||||
if (rule.name === "@charset") {
|
||||
// Only output the debug info together with subsequent @charset definitions
|
||||
// a comment (or @media statement) before the actual @charset directive would
|
||||
// be considered illegal css as it has to be on the first line
|
||||
if (env.charset) {
|
||||
if (rule.debugInfo) {
|
||||
rulesets.push(tree.debugInfo(env, rule));
|
||||
rulesets.push(new tree.Comment("/* "+cssValue.replace(/\n/g, "")+" */\n").toCSS(env));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
env.charset = true;
|
||||
}
|
||||
rulesets.push(cssValue);
|
||||
} else if (rule instanceof tree.Comment) {
|
||||
if (!rule.silent) {
|
||||
if (this.root) {
|
||||
rulesets.push(rule.toCSS(env));
|
||||
} else {
|
||||
rules.push(rule.toCSS(env));
|
||||
}
|
||||
}
|
||||
} else {
|
||||
if (rule.toCSS && !rule.variable) {
|
||||
if (this.firstRoot && rule instanceof tree.Rule) {
|
||||
throw { message: "properties must be inside selector blocks, they cannot be in the root.",
|
||||
index: rule.index, filename: rule.currentFileInfo ? rule.currentFileInfo.filename : null};
|
||||
}
|
||||
rules.push(rule.toCSS(env));
|
||||
} else if (rule.value && !rule.variable) {
|
||||
rules.push(rule.value.toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Remove last semicolon
|
||||
if (env.compress && rules.length) {
|
||||
rule = rules[rules.length - 1];
|
||||
if (rule.charAt(rule.length - 1) === ';') {
|
||||
rules[rules.length - 1] = rule.substring(0, rule.length - 1);
|
||||
}
|
||||
if (!this.root) {
|
||||
env.tabLevel++;
|
||||
}
|
||||
|
||||
rulesets = rulesets.join('');
|
||||
var tabRuleStr = env.compress ? '' : Array(env.tabLevel + 1).join(" "),
|
||||
tabSetStr = env.compress ? '' : Array(env.tabLevel).join(" ");
|
||||
|
||||
for (i = 0; i < this.rules.length; i++) {
|
||||
rule = this.rules[i];
|
||||
if (rule.rules || (rule instanceof tree.Media) || rule instanceof tree.Directive || (this.root && rule instanceof tree.Comment)) {
|
||||
rulesetNodes.push(rule);
|
||||
} else {
|
||||
ruleNodes.push(rule);
|
||||
}
|
||||
}
|
||||
|
||||
// If this is the root node, we don't render
|
||||
// a selector, or {}.
|
||||
// Otherwise, only output if this ruleset has rules.
|
||||
if (this.root) {
|
||||
css.push(rules.join(env.compress ? '' : '\n'));
|
||||
} else {
|
||||
if (rules.length > 0) {
|
||||
debugInfo = tree.debugInfo(env, this);
|
||||
selector = this.paths.map(function (p) {
|
||||
return p.map(function (s) {
|
||||
return s.toCSS(env);
|
||||
}).join('').trim();
|
||||
}).join(env.compress ? ',' : ',\n');
|
||||
if (!this.root) {
|
||||
debugInfo = tree.debugInfo(env, this, tabSetStr);
|
||||
|
||||
// Remove duplicates
|
||||
for (var i = rules.length - 1; i >= 0; i--) {
|
||||
if (rules[i].slice(0, 2) === "/*" || _rules.indexOf(rules[i]) === -1) {
|
||||
_rules.unshift(rules[i]);
|
||||
}
|
||||
if (debugInfo) {
|
||||
output.add(debugInfo);
|
||||
output.add(tabSetStr);
|
||||
}
|
||||
|
||||
for(i = 0; i < this.paths.length; i++) {
|
||||
path = this.paths[i];
|
||||
env.firstSelector = true;
|
||||
for(j = 0; j < path.length; j++) {
|
||||
output.add(path[j].genCSS(env, output));
|
||||
env.firstSelector = false;
|
||||
}
|
||||
rules = _rules;
|
||||
if (i + 1 < this.paths.length) {
|
||||
output.add(env.compress ? ',' : (',\n' + tabSetStr));
|
||||
}
|
||||
}
|
||||
|
||||
css.push(debugInfo + selector +
|
||||
(env.compress ? '{' : ' {\n ') +
|
||||
rules.join(env.compress ? '' : '\n ') +
|
||||
(env.compress ? '}' : '\n}\n'));
|
||||
output.add((env.compress ? '{' : ' {\n') + tabRuleStr);
|
||||
}
|
||||
|
||||
// Compile rules and rulesets
|
||||
for (i = 0; i < ruleNodes.length; i++) {
|
||||
rule = ruleNodes[i];
|
||||
|
||||
if (i + 1 === ruleNodes.length) {
|
||||
env.lastRule = true;
|
||||
}
|
||||
|
||||
if (rule.toCSS) {
|
||||
output.add(rule.genCSS(env, output));
|
||||
} else if (rule.value) {
|
||||
output.add(rule.value.toString());
|
||||
}
|
||||
|
||||
if (!env.lastRule) {
|
||||
output.add(env.compress ? '' : ('\n' + tabRuleStr));
|
||||
} else {
|
||||
env.lastRule = false;
|
||||
}
|
||||
}
|
||||
css.push(rulesets);
|
||||
|
||||
return css.join('') + (env.compress ? '\n' : '');
|
||||
if (!this.root) {
|
||||
output.add((env.compress ? '}' : '\n' + tabSetStr + '}'));
|
||||
env.tabLevel--;
|
||||
}
|
||||
|
||||
for (i = 0; i < rulesetNodes.length; i++) {
|
||||
if (ruleNodes.length && firstRuleset) {
|
||||
output.add("\n" + (this.root ? tabRuleStr : tabSetStr));
|
||||
}
|
||||
if (!firstRuleset) {
|
||||
output.add('\n' + (this.root ? tabRuleStr : tabSetStr));
|
||||
}
|
||||
firstRuleset = false;
|
||||
output.add(rulesetNodes[i].genCSS(env, output));
|
||||
}
|
||||
|
||||
output.add(!env.compress && this.firstRoot ? '\n' : '');
|
||||
},
|
||||
|
||||
toCSS: tree.toCSS,
|
||||
|
||||
markReferenced: function () {
|
||||
for (var s = 0; s < this.selectors.length; s++) {
|
||||
this.selectors[s].markReferenced();
|
||||
}
|
||||
},
|
||||
|
||||
joinSelectors: function (paths, context, selectors) {
|
||||
@@ -289,7 +306,7 @@ tree.Ruleset.prototype = {
|
||||
|
||||
if (!hasParentSelector) {
|
||||
if (context.length > 0) {
|
||||
for(i = 0; i < context.length; i++) {
|
||||
for (i = 0; i < context.length; i++) {
|
||||
paths.push(context[i].concat(selector));
|
||||
}
|
||||
}
|
||||
@@ -333,22 +350,22 @@ tree.Ruleset.prototype = {
|
||||
}
|
||||
|
||||
// loop through our current selectors
|
||||
for(j = 0; j < newSelectors.length; j++) {
|
||||
for (j = 0; j < newSelectors.length; j++) {
|
||||
sel = newSelectors[j];
|
||||
// if we don't have any parent paths, the & might be in a mixin so that it can be used
|
||||
// whether there are parents or not
|
||||
if (context.length == 0) {
|
||||
if (context.length === 0) {
|
||||
// the combinator used on el should now be applied to the next element instead so that
|
||||
// it is not lost
|
||||
if (sel.length > 0) {
|
||||
sel[0].elements = sel[0].elements.slice(0);
|
||||
sel[0].elements.push(new(tree.Element)(el.combinator, '', 0)); //new Element(el.Combinator, ""));
|
||||
sel[0].elements.push(new(tree.Element)(el.combinator, '', 0, el.index, el.currentFileInfo));
|
||||
}
|
||||
selectorsMultiplied.push(sel);
|
||||
}
|
||||
else {
|
||||
// and the parent selectors
|
||||
for(k = 0; k < context.length; k++) {
|
||||
for (k = 0; k < context.length; k++) {
|
||||
parentSel = context[k];
|
||||
// We need to put the current selectors
|
||||
// then join the last selector's elements on to the parents selectors
|
||||
@@ -364,11 +381,11 @@ tree.Ruleset.prototype = {
|
||||
if (sel.length > 0) {
|
||||
newSelectorPath = sel.slice(0);
|
||||
lastSelector = newSelectorPath.pop();
|
||||
newJoinedSelector = new(tree.Selector)(lastSelector.elements.slice(0), selector.extendList);
|
||||
newJoinedSelector = selector.createDerived(lastSelector.elements.slice(0));
|
||||
newJoinedSelectorEmpty = false;
|
||||
}
|
||||
else {
|
||||
newJoinedSelector = new(tree.Selector)([], selector.extendList);
|
||||
newJoinedSelector = selector.createDerived([]);
|
||||
}
|
||||
|
||||
//put together the parent selectors after the join
|
||||
@@ -380,7 +397,7 @@ tree.Ruleset.prototype = {
|
||||
newJoinedSelectorEmpty = false;
|
||||
|
||||
// join the elements so far with the first part of the parent
|
||||
newJoinedSelector.elements.push(new(tree.Element)(el.combinator, parentSel[0].elements[0].value, 0));
|
||||
newJoinedSelector.elements.push(new(tree.Element)(el.combinator, parentSel[0].elements[0].value, el.index, el.currentFileInfo));
|
||||
newJoinedSelector.elements = newJoinedSelector.elements.concat(parentSel[0].elements.slice(1));
|
||||
}
|
||||
|
||||
@@ -410,7 +427,7 @@ tree.Ruleset.prototype = {
|
||||
this.mergeElementsOnToSelectors(currentElements, newSelectors);
|
||||
}
|
||||
|
||||
for(i = 0; i < newSelectors.length; i++) {
|
||||
for (i = 0; i < newSelectors.length; i++) {
|
||||
if (newSelectors[i].length > 0) {
|
||||
paths.push(newSelectors[i]);
|
||||
}
|
||||
@@ -418,19 +435,19 @@ tree.Ruleset.prototype = {
|
||||
},
|
||||
|
||||
mergeElementsOnToSelectors: function(elements, selectors) {
|
||||
var i, sel, extendList;
|
||||
var i, sel;
|
||||
|
||||
if (selectors.length == 0) {
|
||||
if (selectors.length === 0) {
|
||||
selectors.push([ new(tree.Selector)(elements) ]);
|
||||
return;
|
||||
}
|
||||
|
||||
for(i = 0; i < selectors.length; i++) {
|
||||
for (i = 0; i < selectors.length; i++) {
|
||||
sel = selectors[i];
|
||||
|
||||
// if the previous thing in sel is a parent this needs to join on to it
|
||||
if (sel.length > 0) {
|
||||
sel[sel.length - 1] = new(tree.Selector)(sel[sel.length - 1].elements.concat(elements), sel[sel.length - 1].extendList);
|
||||
sel[sel.length - 1] = sel[sel.length - 1].createDerived(sel[sel.length - 1].elements.concat(elements));
|
||||
}
|
||||
else {
|
||||
sel.push(new(tree.Selector)(elements));
|
||||
|
||||
@@ -1,14 +1,28 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Selector = function (elements, extendList) {
|
||||
tree.Selector = function (elements, extendList, condition, index, currentFileInfo, isReferenced) {
|
||||
this.elements = elements;
|
||||
this.extendList = extendList || [];
|
||||
this.condition = condition;
|
||||
this.currentFileInfo = currentFileInfo || {};
|
||||
this.isReferenced = isReferenced;
|
||||
if (!condition) {
|
||||
this.evaldCondition = true;
|
||||
}
|
||||
};
|
||||
tree.Selector.prototype = {
|
||||
type: "Selector",
|
||||
accept: function (visitor) {
|
||||
this.elements = visitor.visit(this.elements);
|
||||
this.extendList = visitor.visit(this.extendList)
|
||||
this.extendList = visitor.visit(this.extendList);
|
||||
this.condition = visitor.visit(this.condition);
|
||||
},
|
||||
createDerived: function(elements, extendList, evaldCondition) {
|
||||
/*jshint eqnull:true */
|
||||
evaldCondition = evaldCondition != null ? evaldCondition : this.evaldCondition;
|
||||
var newSelector = new(tree.Selector)(elements, extendList || this.extendList, this.condition, this.index, this.currentFileInfo, this.isReferenced);
|
||||
newSelector.evaldCondition = evaldCondition;
|
||||
return newSelector;
|
||||
},
|
||||
match: function (other) {
|
||||
var elements = this.elements,
|
||||
@@ -32,30 +46,36 @@ tree.Selector.prototype = {
|
||||
return true;
|
||||
},
|
||||
eval: function (env) {
|
||||
return new(tree.Selector)(this.elements.map(function (e) {
|
||||
var evaldCondition = this.condition && this.condition.eval(env);
|
||||
|
||||
return this.createDerived(this.elements.map(function (e) {
|
||||
return e.eval(env);
|
||||
}), this.extendList.map(function(extend) {
|
||||
return extend.eval(env);
|
||||
}));
|
||||
}), evaldCondition);
|
||||
},
|
||||
toCSS: function (env) {
|
||||
if (this._css) { return this._css }
|
||||
|
||||
if (this.elements[0].combinator.value === "") {
|
||||
this._css = ' ';
|
||||
} else {
|
||||
this._css = '';
|
||||
genCSS: function (env, output) {
|
||||
var i, element;
|
||||
if ((!env || !env.firstSelector) && this.elements[0].combinator.value === "") {
|
||||
output.add(' ', this.currentFileInfo, this.index);
|
||||
}
|
||||
|
||||
this._css += this.elements.map(function (e) {
|
||||
if (typeof(e) === 'string') {
|
||||
return ' ' + e.trim();
|
||||
} else {
|
||||
return e.toCSS(env);
|
||||
if (!this._css) {
|
||||
//TODO caching? speed comparison?
|
||||
for(i = 0; i < this.elements.length; i++) {
|
||||
element = this.elements[i];
|
||||
element.genCSS(env, output);
|
||||
}
|
||||
}).join('');
|
||||
|
||||
return this._css;
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
markReferenced: function () {
|
||||
this.isReferenced = true;
|
||||
},
|
||||
getIsReferenced: function() {
|
||||
return !this.currentFileInfo.reference || this.isReferenced;
|
||||
},
|
||||
getIsOutput: function() {
|
||||
return this.evaldCondition;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -5,10 +5,11 @@ tree.UnicodeDescriptor = function (value) {
|
||||
};
|
||||
tree.UnicodeDescriptor.prototype = {
|
||||
type: "UnicodeDescriptor",
|
||||
toCSS: function (env) {
|
||||
return this.value;
|
||||
genCSS: function (env, output) {
|
||||
output.add(this.value);
|
||||
},
|
||||
eval: function () { return this }
|
||||
toCSS: tree.toCSS,
|
||||
eval: function () { return this; }
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -9,9 +9,12 @@ tree.URL.prototype = {
|
||||
accept: function (visitor) {
|
||||
this.value = visitor.visit(this.value);
|
||||
},
|
||||
toCSS: function () {
|
||||
return "url(" + this.value.toCSS() + ")";
|
||||
genCSS: function (env, output) {
|
||||
output.add("url(");
|
||||
this.value.genCSS(env, output);
|
||||
output.add(")");
|
||||
},
|
||||
toCSS: tree.toCSS,
|
||||
eval: function (ctx) {
|
||||
var val = this.value.eval(ctx), rootpath;
|
||||
|
||||
@@ -24,6 +27,8 @@ tree.URL.prototype = {
|
||||
val.value = rootpath + val.value;
|
||||
}
|
||||
|
||||
val.value = ctx.normalizePath(val.value);
|
||||
|
||||
return new(tree.URL)(val, null);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -17,11 +17,16 @@ tree.Value.prototype = {
|
||||
}));
|
||||
}
|
||||
},
|
||||
toCSS: function (env) {
|
||||
return this.value.map(function (e) {
|
||||
return e.toCSS(env);
|
||||
}).join(env.compress ? ',' : ', ');
|
||||
}
|
||||
genCSS: function (env, output) {
|
||||
var i;
|
||||
for(i = 0; i < this.value.length; i++) {
|
||||
this.value[i].genCSS(env, output);
|
||||
if (i+1 < this.value.length) {
|
||||
output.add((env && env.compress) ? ',' : ', ');
|
||||
}
|
||||
}
|
||||
},
|
||||
toCSS: tree.toCSS
|
||||
};
|
||||
|
||||
})(require('../tree'));
|
||||
|
||||
@@ -1,12 +1,16 @@
|
||||
(function (tree) {
|
||||
|
||||
tree.Variable = function (name, index, currentFileInfo) { this.name = name, this.index = index, this.currentFileInfo = currentFileInfo };
|
||||
tree.Variable = function (name, index, currentFileInfo) {
|
||||
this.name = name;
|
||||
this.index = index;
|
||||
this.currentFileInfo = currentFileInfo;
|
||||
};
|
||||
tree.Variable.prototype = {
|
||||
type: "Variable",
|
||||
eval: function (env) {
|
||||
var variable, v, name = this.name;
|
||||
|
||||
if (name.indexOf('@@') == 0) {
|
||||
if (name.indexOf('@@') === 0) {
|
||||
name = '@' + new(tree.Variable)(name.slice(1)).eval(env).value;
|
||||
}
|
||||
|
||||
|
||||
@@ -39,6 +39,7 @@
|
||||
for(i = 0; i < nodes.length; i++) {
|
||||
var evald = this.visit(nodes[i]);
|
||||
if (evald instanceof Array) {
|
||||
evald = this.flatten(evald);
|
||||
newNodes = newNodes.concat(evald);
|
||||
} else {
|
||||
newNodes.push(evald);
|
||||
@@ -48,6 +49,20 @@
|
||||
return newNodes;
|
||||
}
|
||||
return nodes;
|
||||
},
|
||||
doAccept: function (node) {
|
||||
node.accept(this);
|
||||
},
|
||||
flatten: function(arr, master) {
|
||||
return arr.reduce(this.flattenReduce.bind(this), master || []);
|
||||
},
|
||||
flattenReduce: function(sum, element) {
|
||||
if (element instanceof Array) {
|
||||
sum = this.flatten(element, sum);
|
||||
} else {
|
||||
sum.push(element);
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
10
package.json
10
package.json
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "less",
|
||||
"version": "1.4.2",
|
||||
"version": "1.5.0-b1",
|
||||
"description": "Leaner CSS",
|
||||
"homepage": "http://lesscss.org",
|
||||
"author": "Alexis Sellier <self@cloudhead.net>",
|
||||
@@ -28,16 +28,20 @@
|
||||
"node": ">=0.4.2"
|
||||
},
|
||||
"scripts": {
|
||||
"pretest": "make jshint",
|
||||
"test": "make test"
|
||||
},
|
||||
"optionalDependencies": {
|
||||
"mime": "1.2.x",
|
||||
"request": ">=2.12.0",
|
||||
"mkdirp": "~0.3.4",
|
||||
"ycssmin": ">=1.0.1"
|
||||
"clean-css": "1.0.x",
|
||||
"source-map": "0.1.x"
|
||||
},
|
||||
"devDependencies": {
|
||||
"diff": "~1.0"
|
||||
"diff": "~1.0",
|
||||
"jshint": "~2.1.4",
|
||||
"http-server": "~0.5.5"
|
||||
},
|
||||
"keywords": [
|
||||
"compile less",
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
var path = require('path'),
|
||||
fs = require('fs'),
|
||||
sys = require('util');
|
||||
fs = require('fs');
|
||||
|
||||
var readDirFilesSync = function(dir, regex, callback) {
|
||||
fs.readdirSync(dir).forEach(function (file) {
|
||||
if (! regex.test(file)) { return; }
|
||||
callback(file);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
|
||||
var output = '<html><head>\n';
|
||||
@@ -15,11 +14,11 @@ var createTestRunnerPage = function(dir, exclude, testSuiteName, dir2) {
|
||||
readDirFilesSync(path.join("test", dir, 'less', dir2 || ""), /\.less$/, function (file) {
|
||||
var name = path.basename(file, '.less'),
|
||||
id = (dir ? dir + '-' : "") + 'less-' + (dir2 ? dir2 + "-" : "") + name;
|
||||
|
||||
|
||||
if (exclude && name.match(exclude)) { return; }
|
||||
|
||||
output += '<link id="original-less:' + id + '" rel="stylesheet/less" type="text/css" href="/' + path.join(dir, 'less', dir2 || "", name) + '.less' +'">\n';
|
||||
output += '<link id="expected-less:' + id + '" rel="stylesheet" type="text/css" href="/' + path.join(dir, 'css', dir2 || "", name) + '.css' + '">\n';
|
||||
|
||||
output += '<link id="original-less:' + id + '" rel="stylesheet/less" type="text/css" href="/' + path.join(dir, 'less', dir2 || "", name).replace("\\", "/") + '.less' +'" />\n';
|
||||
output += '<link id="expected-less:' + id + '" rel="stylesheet" type="text/css" href="/' + path.join(dir, 'css', dir2 || "", name).replace("\\", "/") + '.css' + '" />\n';
|
||||
});
|
||||
|
||||
output += String(fs.readFileSync(path.join('test/browser', 'template.htm'))).replace("{runner-name}", testSuiteName);
|
||||
@@ -33,14 +32,17 @@ var removeFiles = function(dir, regex) {
|
||||
console.log("Failed to delete " + file);
|
||||
});
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
removeFiles("test/browser", /test-runner-[a-zA-Z-]*\.htm$/);
|
||||
createTestRunnerPage("", /javascript|urls/, "main");
|
||||
createTestRunnerPage("", null, "legacy", "legacy");
|
||||
createTestRunnerPage("", /javascript/, "errors", "errors");
|
||||
createTestRunnerPage("", null, "no-js-errors", "no-js-errors");
|
||||
createTestRunnerPage("browser", null, "console-errors", "console-errors");
|
||||
createTestRunnerPage("browser", null, "browser");
|
||||
createTestRunnerPage("browser", null, "relative-urls", "relative-urls");
|
||||
createTestRunnerPage("browser", null, "rootpath", "rootpath");
|
||||
createTestRunnerPage("browser", null, "rootpath-relative", "rootpath-relative");
|
||||
createTestRunnerPage("browser", null, "production");
|
||||
createTestRunnerPage("browser", null, "production");
|
||||
createTestRunnerPage("browser", null, "modify-vars", "modify-vars");
|
||||
|
||||
@@ -13,8 +13,8 @@ var testLessEqualsInDocument = function() {
|
||||
testLessInDocument(testSheet);
|
||||
};
|
||||
|
||||
var testLessErrorsInDocument = function() {
|
||||
testLessInDocument(testErrorSheet);
|
||||
var testLessErrorsInDocument = function(isConsole) {
|
||||
testLessInDocument(isConsole ? testErrorSheetConsole : testErrorSheet);
|
||||
};
|
||||
|
||||
var testLessInDocument = function(testFunc) {
|
||||
@@ -43,7 +43,7 @@ var testSheet = function(sheet) {
|
||||
|
||||
runs(function() {
|
||||
// use sheet to do testing
|
||||
expect(lessOutput).toEqual(expectedOutput.text);
|
||||
expect(expectedOutput.text).toEqual(lessOutput);
|
||||
});
|
||||
});
|
||||
};
|
||||
@@ -76,7 +76,7 @@ var testErrorSheet = function(sheet) {
|
||||
.replace("{pathrel}", "")
|
||||
.replace("{pathhref}", "http://localhost:8081/less/errors/")
|
||||
.replace("{404status}", " (404)");
|
||||
expect(actualErrorMsg).toEqual(errorTxt);
|
||||
expect(errorTxt).toEqual(actualErrorMsg);
|
||||
if (errorTxt == actualErrorMsg) {
|
||||
actualErrorElement.style.display = "none";
|
||||
}
|
||||
@@ -84,6 +84,41 @@ var testErrorSheet = function(sheet) {
|
||||
});
|
||||
};
|
||||
|
||||
var testErrorSheetConsole = function(sheet) {
|
||||
it(sheet.id + " should match an error", function() {
|
||||
var lessHref = sheet.href,
|
||||
id = sheet.id.replace(/^original-less:/, "less-error-message:"),
|
||||
errorHref = lessHref.replace(/.less$/, ".txt"),
|
||||
errorFile = loadFile(errorHref),
|
||||
actualErrorElement = document.getElementById(id),
|
||||
actualErrorMsg = logMessages[logMessages.length - 1];
|
||||
|
||||
describe("the error", function() {
|
||||
expect(actualErrorElement).toBe(null);
|
||||
|
||||
});
|
||||
|
||||
/*actualErrorMsg = actualErrorElement.innerText
|
||||
.replace(/\n\d+/g, function(lineNo) { return lineNo + " "; })
|
||||
.replace(/\n\s*in /g, " in ")
|
||||
.replace("\n\n", "\n");*/
|
||||
|
||||
waitsFor(function() {
|
||||
return errorFile.loaded;
|
||||
}, "failed to load expected outout", 10000);
|
||||
|
||||
runs(function() {
|
||||
var errorTxt = errorFile.text
|
||||
.replace("{path}", "")
|
||||
.replace("{pathrel}", "")
|
||||
.replace("{pathhref}", "http://localhost:8081/browser/less/")
|
||||
.replace("{404status}", " (404)")
|
||||
.trim();
|
||||
expect(errorTxt).toEqual(actualErrorMsg);
|
||||
});
|
||||
});
|
||||
};
|
||||
|
||||
var loadFile = function(href) {
|
||||
var request = new XMLHttpRequest(),
|
||||
response = { loaded: false, text: ""};
|
||||
|
||||
7
test/browser/css/modify-vars/simple.css
Normal file
7
test/browser/css/modify-vars/simple.css
Normal file
@@ -0,0 +1,7 @@
|
||||
.testisimported {
|
||||
color: gainsboro;
|
||||
}
|
||||
.test {
|
||||
color1: #008000;
|
||||
color2: #800080;
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
@import "http://localhost:8081/browser/less/imports/modify-this.css";
|
||||
|
||||
@import "http://localhost:8081/browser/less/imports/modify-again.css";
|
||||
.modify {
|
||||
my-url: url("http://localhost:8081/browser/less/imports/a.png");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@import "https://www.github.com/cloudhead/imports/modify-this.css";
|
||||
|
||||
@import "https://www.github.com/cloudhead/imports/modify-again.css";
|
||||
.modify {
|
||||
my-url: url("https://www.github.com/cloudhead/imports/a.png");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@import "https://www.github.com/modify-this.css";
|
||||
|
||||
@import "https://www.github.com/modify-again.css";
|
||||
.modify {
|
||||
my-url: url("https://www.github.com/a.png");
|
||||
|
||||
@@ -1,5 +1,4 @@
|
||||
@import "http://localhost:8081/browser/less/modify-this.css";
|
||||
|
||||
@import "http://localhost:8081/browser/less/modify-again.css";
|
||||
.modify {
|
||||
my-url: url("http://localhost:8081/browser/less/a.png");
|
||||
@@ -35,15 +34,20 @@
|
||||
url: url('http://localhost:8081/browser/less/Trebuchet');
|
||||
}
|
||||
#data-uri {
|
||||
uri: url('http://localhost:8081/browser/less/../../data/image.jpg');
|
||||
uri: url('http://localhost:8081/data/image.jpg');
|
||||
}
|
||||
#data-uri-guess {
|
||||
uri: url('http://localhost:8081/browser/less/../../data/image.jpg');
|
||||
uri: url('http://localhost:8081/data/image.jpg');
|
||||
}
|
||||
#data-uri-ascii {
|
||||
uri-1: url('http://localhost:8081/browser/less/../../data/page.html');
|
||||
uri-2: url('http://localhost:8081/browser/less/../../data/page.html');
|
||||
uri-1: url('http://localhost:8081/data/page.html');
|
||||
uri-2: url('http://localhost:8081/data/page.html');
|
||||
}
|
||||
#data-uri-toobig {
|
||||
uri: url('http://localhost:8081/browser/less/../../data/data-uri-fail.png');
|
||||
uri: url('http://localhost:8081/data/data-uri-fail.png');
|
||||
}
|
||||
#svg-functions {
|
||||
background-image: url('data:image/svg+xml,<?xml version="1.0" ?><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none"><linearGradient id="gradient" gradientUnits="userSpaceOnUse" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="#000000"/><stop offset="100%" stop-color="#ffffff"/></linearGradient><rect x="0" y="0" width="1" height="1" fill="url(#gradient)" /></svg>');
|
||||
background-image: url('data:image/svg+xml,<?xml version="1.0" ?><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none"><linearGradient id="gradient" gradientUnits="userSpaceOnUse" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="0%" stop-color="#000000"/><stop offset="3%" stop-color="#ffa500"/><stop offset="100%" stop-color="#ffffff"/></linearGradient><rect x="0" y="0" width="1" height="1" fill="url(#gradient)" /></svg>');
|
||||
background-image: url('data:image/svg+xml,<?xml version="1.0" ?><svg xmlns="http://www.w3.org/2000/svg" version="1.1" width="100%" height="100%" viewBox="0 0 1 1" preserveAspectRatio="none"><linearGradient id="gradient" gradientUnits="userSpaceOnUse" x1="0%" y1="0%" x2="0%" y2="100%"><stop offset="1%" stop-color="#c4c4c4"/><stop offset="3%" stop-color="#ffa500"/><stop offset="5%" stop-color="#008000"/><stop offset="95%" stop-color="#ffffff"/></linearGradient><rect x="0" y="0" width="1" height="1" fill="url(#gradient)" /></svg>');
|
||||
}
|
||||
|
||||
27
test/browser/es5.js
Normal file
27
test/browser/es5.js
Normal file
@@ -0,0 +1,27 @@
|
||||
/*
|
||||
PhantomJS does not implement bind. this is from
|
||||
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function/bind
|
||||
*/
|
||||
if (!Function.prototype.bind) {
|
||||
Function.prototype.bind = function (oThis) {
|
||||
if (typeof this !== "function") {
|
||||
// closest thing possible to the ECMAScript 5 internal IsCallable function
|
||||
throw new TypeError("Function.prototype.bind - what is trying to be bound is not callable");
|
||||
}
|
||||
|
||||
var aArgs = Array.prototype.slice.call(arguments, 1),
|
||||
fToBind = this,
|
||||
fNOP = function () {},
|
||||
fBound = function () {
|
||||
return fToBind.apply(this instanceof fNOP && oThis
|
||||
? this
|
||||
: oThis,
|
||||
aArgs.concat(Array.prototype.slice.call(arguments)));
|
||||
};
|
||||
|
||||
fNOP.prototype = this.prototype;
|
||||
fBound.prototype = new fNOP();
|
||||
|
||||
return fBound;
|
||||
};
|
||||
}
|
||||
3
test/browser/less/console-errors/test-error.less
Normal file
3
test/browser/less/console-errors/test-error.less
Normal file
@@ -0,0 +1,3 @@
|
||||
.a {
|
||||
prop: (3 / #fff);
|
||||
}
|
||||
2
test/browser/less/console-errors/test-error.txt
Normal file
2
test/browser/less/console-errors/test-error.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
less: OperationError: Can't substract or divide a color from a number in {pathhref}console-errors/test-error.less on line null, column 0:
|
||||
1 prop: (3 / #fff);
|
||||
4
test/browser/less/modify-vars/imports/simple2.less
Normal file
4
test/browser/less/modify-vars/imports/simple2.less
Normal file
@@ -0,0 +1,4 @@
|
||||
@var2: blue;
|
||||
.testisimported {
|
||||
color: gainsboro;
|
||||
}
|
||||
6
test/browser/less/modify-vars/simple.less
Normal file
6
test/browser/less/modify-vars/simple.less
Normal file
@@ -0,0 +1,6 @@
|
||||
@import "imports/simple2";
|
||||
@var1: red;
|
||||
.test {
|
||||
color1: @var1;
|
||||
color2: @var2;
|
||||
}
|
||||
@@ -47,3 +47,11 @@
|
||||
#data-uri-toobig {
|
||||
uri: data-uri('../../data/data-uri-fail.png');
|
||||
}
|
||||
#svg-functions {
|
||||
background-image: svg-gradient(to bottom, black, white);
|
||||
background-image: svg-gradient(to bottom, black, orange 3%, white);
|
||||
@green_5: green 5%;
|
||||
@orange_percentage: 3%;
|
||||
@orange_color: orange;
|
||||
background-image: svg-gradient(to bottom, (mix(black, white) + #444) 1%, @orange_color @orange_percentage, ((@green_5)), white 95%);
|
||||
}
|
||||
|
||||
@@ -1,7 +1,42 @@
|
||||
describe("less.js browser behaviour", function() {
|
||||
testLessEqualsInDocument();
|
||||
|
||||
|
||||
it("has some log messages", function() {
|
||||
expect(logMessages.length).toBeGreaterThan(0);
|
||||
});
|
||||
|
||||
// test inline less in style tags by grabbing an assortment of less files and doing `@import`s
|
||||
var testFiles = ['charsets', 'colors', 'comments', 'css-3', 'strings', 'media', 'mixins'],
|
||||
testSheets = [];
|
||||
|
||||
// setup style tags with less and link tags pointing to expected css output
|
||||
for (var i = 0; i < testFiles.length; i++) {
|
||||
var file = testFiles[i],
|
||||
lessPath = '/less/' + file + '.less',
|
||||
cssPath = '/css/' + file + '.css',
|
||||
lessStyle = document.createElement('style'),
|
||||
cssLink = document.createElement('link'),
|
||||
lessText = '@import "' + lessPath + '";';
|
||||
lessStyle.type = 'text/less';
|
||||
lessStyle.id = file;
|
||||
if (lessStyle.styleSheet) {
|
||||
lessStyle.styleSheet.cssText = lessText;
|
||||
} else {
|
||||
lessStyle.innerHTML = lessText;
|
||||
}
|
||||
cssLink.rel = 'stylesheet';
|
||||
cssLink.type = 'text/css';
|
||||
cssLink.href = cssPath;
|
||||
cssLink.id = 'expected-' + file;
|
||||
|
||||
var head = document.getElementsByTagName('head')[0];
|
||||
head.appendChild(lessStyle);
|
||||
head.appendChild(cssLink);
|
||||
testSheets[i] = lessStyle;
|
||||
}
|
||||
|
||||
for (var i = 0; i < testFiles.length; i++) {
|
||||
var sheet = testSheets[i];
|
||||
testSheet(sheet);
|
||||
}
|
||||
});
|
||||
5
test/browser/runner-console-errors.js
Normal file
5
test/browser/runner-console-errors.js
Normal file
@@ -0,0 +1,5 @@
|
||||
less.errorReporting = 'console';
|
||||
|
||||
describe("less.js error reporting console test", function() {
|
||||
testLessErrorsInDocument(true);
|
||||
});
|
||||
14
test/browser/runner-modify-vars.js
Normal file
14
test/browser/runner-modify-vars.js
Normal file
@@ -0,0 +1,14 @@
|
||||
|
||||
setTimeout(function(){
|
||||
less.modifyVars({var1: "green", var2: "purple"});
|
||||
}, 1000);
|
||||
|
||||
describe("less.js modify vars", function() {
|
||||
testLessEqualsInDocument();
|
||||
it("Should log only 2 XHR requests", function() {
|
||||
var xhrLogMessages = logMessages.filter(function(item) {
|
||||
return /XHR: Getting '/.test(item);
|
||||
})
|
||||
expect(xhrLogMessages.length).toEqual(2);
|
||||
});
|
||||
});
|
||||
6
test/browser/runner-no-js-errors.js
Normal file
6
test/browser/runner-no-js-errors.js
Normal file
@@ -0,0 +1,6 @@
|
||||
less.strictUnits = true;
|
||||
less.javascriptEnabled = false;
|
||||
|
||||
describe("less.js javascript disabled error tests", function() {
|
||||
testLessErrorsInDocument();
|
||||
});
|
||||
@@ -1,9 +1,10 @@
|
||||
<script src="/browser/jasmine.js" type="text/javascript"></script>
|
||||
<script src="/browser/jasmine-html.js" type="text/javascript"></script>
|
||||
<script src="/browser/common.js" type="text/javascript"></script>
|
||||
<script src="/browser/es5.js" type="text/javascript"></script>
|
||||
<script src="/browser/runner-{runner-name}.js" type="text/javascript"></script>
|
||||
<script src="/browser/less.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/browser/jasmine.css"></link>
|
||||
<link rel="stylesheet" type="text/css" href="/browser/jasmine.css" />
|
||||
</head>
|
||||
<body>
|
||||
</body>
|
||||
|
||||
@@ -26,12 +26,12 @@
|
||||
*/
|
||||
/* @group Variables
|
||||
------------------- */
|
||||
#comments {
|
||||
#comments,
|
||||
.comments {
|
||||
/**/
|
||||
color: red;
|
||||
/* A C-style comment */
|
||||
/* A C-style comment */
|
||||
|
||||
background-color: orange;
|
||||
font-size: 12px;
|
||||
/* lost comment */
|
||||
@@ -53,12 +53,17 @@
|
||||
-moz-border-radius: 8px /* moz only with operation */;
|
||||
}
|
||||
.test {
|
||||
color: 1px //put in @b - causes problems! --->;
|
||||
color: 1px;
|
||||
}
|
||||
#last {
|
||||
color: #0000ff;
|
||||
}
|
||||
/* *//* { *//* *//* *//* */#div {
|
||||
/* */
|
||||
/* { */
|
||||
/* */
|
||||
/* */
|
||||
/* */
|
||||
#div {
|
||||
color: #A33;
|
||||
}
|
||||
/* } */
|
||||
|
||||
@@ -1,2 +1,4 @@
|
||||
#colours{color1:#fea;color2:#fea;color3:rgba(255,238,170,0.1);string:"#ffeeaa"}
|
||||
dimensions{val:.1px;val:0;val:4cm;val:.2;val:5;angles-must-have-unit:0deg;width:auto\9}
|
||||
#colours{color1:#fea;color2:#fea;color3:rgba(255,238,170,0.1);string:"#ffeeaa";/*! but not this type
|
||||
Note preserved whitespace
|
||||
*/}
|
||||
dimensions{val:.1px;val:0;val:4cm;val:.2;val:5;angles-must-have-unit:0deg;durations-must-have-unit:0s;length-doesnt-have-unit:0;width:auto\9}
|
||||
@@ -97,16 +97,16 @@ p::before {
|
||||
font-size: 10px;
|
||||
}
|
||||
@namespace foo url(http://www.example.com);
|
||||
foo | h1 {
|
||||
foo|h1 {
|
||||
color: blue;
|
||||
}
|
||||
foo | * {
|
||||
foo|* {
|
||||
color: yellow;
|
||||
}
|
||||
| h1 {
|
||||
|h1 {
|
||||
color: red;
|
||||
}
|
||||
* | h1 {
|
||||
*|h1 {
|
||||
color: green;
|
||||
}
|
||||
h1 {
|
||||
|
||||
18
test/css/css-guards.css
Normal file
18
test/css/css-guards.css
Normal file
@@ -0,0 +1,18 @@
|
||||
.light {
|
||||
color: green;
|
||||
}
|
||||
.see-the {
|
||||
color: orange;
|
||||
}
|
||||
.hide-the {
|
||||
color: green;
|
||||
}
|
||||
.multiple-conditions-1 {
|
||||
color: red;
|
||||
}
|
||||
.inheritance .test {
|
||||
color: black;
|
||||
}
|
||||
.inheritance:hover {
|
||||
color: pink;
|
||||
}
|
||||
@@ -52,9 +52,9 @@ div.ext7,
|
||||
.c.replace + .replace .replace,
|
||||
.replace.replace .c,
|
||||
.c.replace + .replace .c,
|
||||
.rep_ace .rep_ace .rep_ace,
|
||||
.rep_ace.rep_ace .rep_ace,
|
||||
.c.rep_ace + .rep_ace .rep_ace,
|
||||
.rep_ace .rep_ace .c,
|
||||
.rep_ace.rep_ace .c,
|
||||
.c.rep_ace + .rep_ace .c {
|
||||
prop: copy-paste-replace;
|
||||
}
|
||||
@@ -70,3 +70,11 @@ div.ext7,
|
||||
.attributes .attributes .attribute-test {
|
||||
extend: attributes2;
|
||||
}
|
||||
.header .header-nav,
|
||||
.footer .footer-nav {
|
||||
background: red;
|
||||
}
|
||||
.header .header-nav:before,
|
||||
.footer .footer-nav:before {
|
||||
background: blue;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@
|
||||
luma-cyan: 79%;
|
||||
luma-white-alpha: 50%;
|
||||
contrast-filter: contrast(30%);
|
||||
saturate-filter: saturate(5%);
|
||||
contrast-white: #000000;
|
||||
contrast-black: #ffffff;
|
||||
contrast-red: #ffffff;
|
||||
@@ -80,6 +81,11 @@
|
||||
pow: 64px;
|
||||
pow: 64;
|
||||
pow: 27;
|
||||
min: 0;
|
||||
min: min("junk", 5);
|
||||
min: 3pt;
|
||||
max: 3;
|
||||
max: max(8%, 1cm);
|
||||
percentage: 20%;
|
||||
color: #ff0011;
|
||||
tint: #898989;
|
||||
|
||||
5
test/css/import-inline.css
Normal file
5
test/css/import-inline.css
Normal file
@@ -0,0 +1,5 @@
|
||||
this isn't very valid CSS.
|
||||
@media (min-width: 600px) {
|
||||
#css { color: yellow; }
|
||||
|
||||
}
|
||||
55
test/css/import-reference.css
Normal file
55
test/css/import-reference.css
Normal file
@@ -0,0 +1,55 @@
|
||||
/*
|
||||
The media statement above is invalid (no selector)
|
||||
We should ban invalid media queries with properties and no selector?
|
||||
*/
|
||||
.visible {
|
||||
color: red;
|
||||
}
|
||||
.visible .c {
|
||||
color: green;
|
||||
}
|
||||
.visible {
|
||||
color: green;
|
||||
}
|
||||
.visible:hover {
|
||||
color: green;
|
||||
}
|
||||
.visible {
|
||||
color: green;
|
||||
}
|
||||
.only-with-visible + .visible,
|
||||
.visible + .only-with-visible,
|
||||
.visible + .visible {
|
||||
color: green;
|
||||
}
|
||||
.only-with-visible + .visible .sub,
|
||||
.visible + .only-with-visible .sub,
|
||||
.visible + .visible .sub {
|
||||
color: green;
|
||||
}
|
||||
.b {
|
||||
color: red;
|
||||
color: green;
|
||||
}
|
||||
.b .c {
|
||||
color: green;
|
||||
}
|
||||
.b:hover {
|
||||
color: green;
|
||||
}
|
||||
.b {
|
||||
color: green;
|
||||
}
|
||||
.b + .b {
|
||||
color: green;
|
||||
}
|
||||
.b + .b .sub {
|
||||
color: green;
|
||||
}
|
||||
.y {
|
||||
pulled-in: yes;
|
||||
}
|
||||
/* comment pulled in */
|
||||
.visible {
|
||||
extend: test;
|
||||
}
|
||||
2
test/css/import.css
vendored
2
test/css/import.css
vendored
@@ -1,7 +1,5 @@
|
||||
@import url(http://fonts.googleapis.com/css?family=Open+Sans);
|
||||
|
||||
@import url(/absolute/something.css) screen and (color) and (max-width: 600px);
|
||||
|
||||
@import url("//ha.com/file.css") (min-width: 100px);
|
||||
#import-test {
|
||||
height: 10px;
|
||||
|
||||
@@ -52,9 +52,6 @@
|
||||
.sidebar {
|
||||
width: 500px;
|
||||
}
|
||||
}
|
||||
@media a {
|
||||
|
||||
}
|
||||
@media a and b {
|
||||
.first .second .third {
|
||||
@@ -106,7 +103,9 @@
|
||||
}
|
||||
}
|
||||
@media only screen and (max-width: 200px) {
|
||||
width: 480px;
|
||||
body {
|
||||
width: 480px;
|
||||
}
|
||||
}
|
||||
@media print {
|
||||
@page :left {
|
||||
@@ -119,7 +118,8 @@
|
||||
margin: 1cm;
|
||||
}
|
||||
@page :first {
|
||||
size: 8.5in 11in;@top-left {
|
||||
size: 8.5in 11in;
|
||||
@top-left {
|
||||
margin: 1cm;
|
||||
}
|
||||
@top-left-corner {
|
||||
@@ -201,3 +201,13 @@ body {
|
||||
font-size: 11px;
|
||||
}
|
||||
}
|
||||
@media (min-width: 480px) {
|
||||
.nav-justified > li {
|
||||
display: table-cell;
|
||||
}
|
||||
}
|
||||
@media (min-width: 768px) and (min-width: 480px) {
|
||||
.menu > li {
|
||||
display: table-cell;
|
||||
}
|
||||
}
|
||||
|
||||
22
test/css/merge.css
Normal file
22
test/css/merge.css
Normal file
@@ -0,0 +1,22 @@
|
||||
.test1 {
|
||||
transform: rotate(90deg), skew(30deg), scale(2, 4);
|
||||
}
|
||||
.test2 {
|
||||
transform: rotate(90deg), skew(30deg);
|
||||
transform: scaleX(45deg);
|
||||
}
|
||||
.test3 {
|
||||
transform: scaleX(45deg);
|
||||
background: url(data://img1.png);
|
||||
}
|
||||
.test4 {
|
||||
transform: rotate(90deg), skew(30deg);
|
||||
transform: scale(2, 4) !important;
|
||||
}
|
||||
.test5 {
|
||||
transform: rotate(90deg), skew(30deg);
|
||||
transform: scale(2, 4) !important;
|
||||
}
|
||||
.test6 {
|
||||
transform: scale(2, 4);
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
@import "folder (1)/../css/background.css";
|
||||
|
||||
@import "css/background.css";
|
||||
@import "folder (1)/import-test-d.css";
|
||||
@font-face {
|
||||
src: url("/fonts/garamond-pro.ttf");
|
||||
@@ -31,11 +30,11 @@
|
||||
#logo {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background: url('folder (1)/../assets/logo.png');
|
||||
background: url('assets/logo.png');
|
||||
}
|
||||
@font-face {
|
||||
font-family: xecret;
|
||||
src: url('folder (1)/../assets/xecret.ttf');
|
||||
src: url('assets/xecret.ttf');
|
||||
}
|
||||
#secret {
|
||||
font-family: xecret, sans-serif;
|
||||
|
||||
@@ -38,3 +38,6 @@
|
||||
color: #000000;
|
||||
color: #ffa500;
|
||||
}
|
||||
.watermark {
|
||||
family: Univers, Arial, Verdana, San-Serif;
|
||||
}
|
||||
|
||||
@@ -1,7 +1,5 @@
|
||||
@import "import/../css/background.css";
|
||||
|
||||
@import "css/background.css";
|
||||
@import "import/import-test-d.css";
|
||||
|
||||
@import "file.css";
|
||||
@font-face {
|
||||
src: url("/fonts/garamond-pro.ttf");
|
||||
@@ -35,11 +33,11 @@
|
||||
#logo {
|
||||
width: 100px;
|
||||
height: 100px;
|
||||
background: url('import/imports/../assets/logo.png');
|
||||
background: url('import/assets/logo.png');
|
||||
}
|
||||
@font-face {
|
||||
font-family: xecret;
|
||||
src: url('import/imports/../assets/xecret.ttf');
|
||||
src: url('import/assets/xecret.ttf');
|
||||
}
|
||||
#secret {
|
||||
font-family: xecret, sans-serif;
|
||||
@@ -57,3 +55,8 @@
|
||||
#data-uri-toobig {
|
||||
uri: url('../data/data-uri-fail.png');
|
||||
}
|
||||
#svg-functions {
|
||||
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZ3JhZGllbnQiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIvPjxzdG9wIG9mZnNldD0iMTAwJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIvPjwvbGluZWFyR3JhZGllbnQ+PHJlY3QgeD0iMCIgeT0iMCIgd2lkdGg9IjEiIGhlaWdodD0iMSIgZmlsbD0idXJsKCNncmFkaWVudCkiIC8+PC9zdmc+');
|
||||
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZ3JhZGllbnQiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iIzAwMDAwMCIvPjxzdG9wIG9mZnNldD0iMyUiIHN0b3AtY29sb3I9IiNmZmE1MDAiLz48c3RvcCBvZmZzZXQ9IjEwMCUiIHN0b3AtY29sb3I9IiNmZmZmZmYiLz48L2xpbmVhckdyYWRpZW50PjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9InVybCgjZ3JhZGllbnQpIiAvPjwvc3ZnPg==');
|
||||
background-image: url('data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/PjxzdmcgeG1sbnM9Imh0dHA6Ly93d3cudzMub3JnLzIwMDAvc3ZnIiB2ZXJzaW9uPSIxLjEiIHdpZHRoPSIxMDAlIiBoZWlnaHQ9IjEwMCUiIHZpZXdCb3g9IjAgMCAxIDEiIHByZXNlcnZlQXNwZWN0UmF0aW89Im5vbmUiPjxsaW5lYXJHcmFkaWVudCBpZD0iZ3JhZGllbnQiIGdyYWRpZW50VW5pdHM9InVzZXJTcGFjZU9uVXNlIiB4MT0iMCUiIHkxPSIwJSIgeDI9IjAlIiB5Mj0iMTAwJSI+PHN0b3Agb2Zmc2V0PSIxJSIgc3RvcC1jb2xvcj0iI2M0YzRjNCIvPjxzdG9wIG9mZnNldD0iMyUiIHN0b3AtY29sb3I9IiNmZmE1MDAiLz48c3RvcCBvZmZzZXQ9IjUlIiBzdG9wLWNvbG9yPSIjMDA4MDAwIi8+PHN0b3Agb2Zmc2V0PSI5NSUiIHN0b3AtY29sb3I9IiNmZmZmZmYiLz48L2xpbmVhckdyYWRpZW50PjxyZWN0IHg9IjAiIHk9IjAiIHdpZHRoPSIxIiBoZWlnaHQ9IjEiIGZpbGw9InVybCgjZ3JhZGllbnQpIiAvPjwvc3ZnPg==');
|
||||
}
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
/*jshint latedef: nofunc */
|
||||
var path = require('path'),
|
||||
fs = require('fs'),
|
||||
sys = require('util');
|
||||
@@ -9,6 +10,8 @@ var globals = Object.keys(global);
|
||||
|
||||
var oneTestOnly = process.argv[2];
|
||||
|
||||
var isVerbose = process.env.npm_config_loglevel === 'verbose';
|
||||
|
||||
var totalTests = 0,
|
||||
failedTests = 0,
|
||||
passedTests = 0;
|
||||
@@ -20,14 +23,60 @@ less.tree.functions.increment = function (a) {
|
||||
return new(less.tree.Dimension)(a.value + 1);
|
||||
};
|
||||
less.tree.functions._color = function (str) {
|
||||
if (str.value === "evil red") { return new(less.tree.Color)("600") }
|
||||
if (str.value === "evil red") { return new(less.tree.Color)("600"); }
|
||||
};
|
||||
|
||||
sys.puts("\n" + stylize("LESS", 'underline') + "\n");
|
||||
|
||||
runTestSet({strictMath: true, relativeUrls: true, silent: true});
|
||||
runTestSet({strictMath: true, strictUnits: true}, "errors/",
|
||||
testErrors, null, getErrorPathReplacementFunction("errors"));
|
||||
runTestSet({strictMath: true, strictUnits: true, javascriptEnabled: false}, "no-js-errors/",
|
||||
testErrors, null, getErrorPathReplacementFunction("no-js-errors"));
|
||||
runTestSet({strictMath: true, dumpLineNumbers: 'comments'}, "debug/", null,
|
||||
function(name) { return name + '-comments'; });
|
||||
runTestSet({strictMath: true, dumpLineNumbers: 'mediaquery'}, "debug/", null,
|
||||
function(name) { return name + '-mediaquery'; });
|
||||
runTestSet({strictMath: true, dumpLineNumbers: 'all'}, "debug/", null,
|
||||
function(name) { return name + '-all'; });
|
||||
runTestSet({strictMath: true, relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/");
|
||||
runTestSet({strictMath: true, compress: true}, "compression/");
|
||||
runTestSet({}, "legacy/");
|
||||
runTestSet({strictMath: true, strictUnits: true, sourceMap: true }, "sourcemaps/",
|
||||
testSourcemap, null, null, function(filename) { return path.join('test/sourcemaps', filename) + '.json'; });
|
||||
|
||||
runTestSet({strictMath: true, strictUnits: true}, "errors/", function(name, err, compiledLess, doReplacements) {
|
||||
testNoOptions();
|
||||
|
||||
function getErrorPathReplacementFunction(dir) {
|
||||
return function(input) {
|
||||
return input.replace(
|
||||
"{path}", path.join(process.cwd(), "/test/less/" + dir + "/"))
|
||||
.replace("{pathrel}", path.join("test", "less", dir + "/"))
|
||||
.replace("{pathhref}", "")
|
||||
.replace("{404status}", "")
|
||||
.replace(/\r\n/g, '\n');
|
||||
};
|
||||
}
|
||||
|
||||
function testSourcemap(name, err, compiledLess, doReplacements, sourcemap) {
|
||||
fs.readFile(path.join('test/', name) + '.json', 'utf8', function (e, expectedSourcemap) {
|
||||
sys.print("- " + name + ": ");
|
||||
if (sourcemap === expectedSourcemap) {
|
||||
ok('OK');
|
||||
} else if (err) {
|
||||
fail("ERROR: " + (err && err.message));
|
||||
if (isVerbose) {
|
||||
console.error();
|
||||
console.error(err.stack);
|
||||
}
|
||||
} else {
|
||||
difference("FAIL", expectedSourcemap, sourcemap);
|
||||
}
|
||||
sys.puts("");
|
||||
});
|
||||
}
|
||||
|
||||
function testErrors(name, err, compiledLess, doReplacements) {
|
||||
fs.readFile(path.join('test/less/', name) + '.txt', 'utf8', function (e, expectedErr) {
|
||||
sys.print("- " + name + ": ");
|
||||
expectedErr = doReplacements(expectedErr, 'test/less/errors/');
|
||||
@@ -40,31 +89,14 @@ runTestSet({strictMath: true, strictUnits: true}, "errors/", function(name, err,
|
||||
} else {
|
||||
var errMessage = less.formatError(err);
|
||||
if (errMessage === expectedErr) {
|
||||
ok('OK');
|
||||
ok('OK');
|
||||
} else {
|
||||
difference("FAIL", expectedErr, errMessage);
|
||||
}
|
||||
}
|
||||
sys.puts("");
|
||||
});}, null, function(input, directory) {
|
||||
return input.replace(
|
||||
"{path}", path.join(process.cwd(), "/test/less/errors/"))
|
||||
.replace("{pathrel}", path.join("test", "less", "errors/"))
|
||||
.replace("{pathhref}", "")
|
||||
.replace("{404status}", "")
|
||||
.replace(/\r\n/g, '\n');
|
||||
});
|
||||
|
||||
runTestSet({strictMath: true, dumpLineNumbers: 'comments'}, "debug/", null,
|
||||
function(name) { return name + '-comments'; });
|
||||
runTestSet({strictMath: true, dumpLineNumbers: 'mediaquery'}, "debug/", null,
|
||||
function(name) { return name + '-mediaquery'; });
|
||||
runTestSet({strictMath: true, dumpLineNumbers: 'all'}, "debug/", null,
|
||||
function(name) { return name + '-all'; });
|
||||
runTestSet({strictMath: true, relativeUrls: false, rootpath: "folder (1)/"}, "static-urls/");
|
||||
runTestSet({strictMath: true, compress: true}, "compression/");
|
||||
runTestSet({ }, "legacy/");
|
||||
testNoOptions();
|
||||
}
|
||||
|
||||
function globalReplacements(input, directory) {
|
||||
var p = path.join(process.cwd(), directory),
|
||||
@@ -85,14 +117,14 @@ function checkGlobalLeaks() {
|
||||
});
|
||||
}
|
||||
|
||||
function runTestSet(options, foldername, verifyFunction, nameModifier, doReplacements) {
|
||||
function runTestSet(options, foldername, verifyFunction, nameModifier, doReplacements, getFilename) {
|
||||
foldername = foldername || "";
|
||||
|
||||
if(!doReplacements)
|
||||
doReplacements = globalReplacements;
|
||||
|
||||
fs.readdirSync(path.join('test/less/', foldername)).forEach(function (file) {
|
||||
if (! /\.less/.test(file)) { return }
|
||||
if (! /\.less/.test(file)) { return; }
|
||||
|
||||
var name = foldername + path.basename(file, '.less');
|
||||
|
||||
@@ -100,20 +132,34 @@ function runTestSet(options, foldername, verifyFunction, nameModifier, doReplace
|
||||
|
||||
totalTests++;
|
||||
|
||||
if (options.sourceMap) {
|
||||
var sourceMapOutput;
|
||||
options.writeSourceMap = function(output) {
|
||||
sourceMapOutput = output;
|
||||
};
|
||||
options.sourceMapOutputFilename = name + ".css";
|
||||
options.sourceMapBasepath = path.join(process.cwd(), "test/less");
|
||||
options.sourceMapRootpath = "testweb/";
|
||||
}
|
||||
|
||||
toCSS(options, path.join('test/less/', foldername + file), function (err, less) {
|
||||
|
||||
if (verifyFunction) {
|
||||
return verifyFunction(name, err, less, doReplacements);
|
||||
return verifyFunction(name, err, less, doReplacements, sourceMapOutput);
|
||||
}
|
||||
var css_name = name;
|
||||
if(nameModifier) css_name=nameModifier(name);
|
||||
if(nameModifier) { css_name = nameModifier(name); }
|
||||
fs.readFile(path.join('test/css', css_name) + '.css', 'utf8', function (e, css) {
|
||||
sys.print("- " + css_name + ": ")
|
||||
sys.print("- " + css_name + ": ");
|
||||
|
||||
css = css && doReplacements(css, 'test/less/' + foldername);
|
||||
if (less === css) { ok('OK'); }
|
||||
else if (err) {
|
||||
fail("ERROR: " + (err && err.message));
|
||||
if (isVerbose) {
|
||||
console.error();
|
||||
console.error(err.stack);
|
||||
}
|
||||
} else {
|
||||
difference("FAIL", css, less);
|
||||
}
|
||||
@@ -127,7 +173,8 @@ function diff(left, right) {
|
||||
sys.puts("");
|
||||
require('diff').diffLines(left, right).forEach(function(item) {
|
||||
if(item.added || item.removed) {
|
||||
sys.print(stylize(item.value, item.added ? 'green' : 'red'));
|
||||
var text = item.value.replace("\n", String.fromCharCode(182) + "\n");
|
||||
sys.print(stylize(text, item.added ? 'green' : 'red'));
|
||||
} else {
|
||||
sys.print(item.value);
|
||||
}
|
||||
@@ -177,10 +224,10 @@ function endTest() {
|
||||
}
|
||||
|
||||
function toCSS(options, path, callback) {
|
||||
var tree, css;
|
||||
var css;
|
||||
options = options || {};
|
||||
fs.readFile(path, 'utf8', function (e, str) {
|
||||
if (e) { return callback(e) }
|
||||
if (e) { return callback(e); }
|
||||
|
||||
options.paths = [require('path').dirname(path)];
|
||||
options.filename = require('path').resolve(process.cwd(), path);
|
||||
@@ -205,7 +252,7 @@ function testNoOptions() {
|
||||
totalTests++;
|
||||
try {
|
||||
sys.print("- Integration - creating parser without options: ");
|
||||
new(less.Parser);
|
||||
new(less.Parser)();
|
||||
} catch(e) {
|
||||
fail(stylize("FAIL\n", "red"));
|
||||
return;
|
||||
|
||||
@@ -34,7 +34,13 @@
|
||||
|
||||
/* @group Variables
|
||||
------------------- */
|
||||
#comments /* boo */ {
|
||||
#comments /* boo *//* boo again*/,
|
||||
//.commented_out1
|
||||
//.commented_out2
|
||||
//.commented_out3
|
||||
.comments //end of comments1
|
||||
//end of comments2
|
||||
{
|
||||
/**/ // An empty comment
|
||||
color: red; /* A C-style comment */ /* A C-style comment */
|
||||
background-color: orange; // A little comment
|
||||
|
||||
@@ -4,6 +4,11 @@
|
||||
color3: rgba(255, 238, 170, 0.1);
|
||||
@color1: #fea;
|
||||
string: "@{color1}";
|
||||
/* comments are stripped */
|
||||
// both types!
|
||||
/*! but not this type
|
||||
Note preserved whitespace
|
||||
*/
|
||||
}
|
||||
dimensions {
|
||||
val: 0.1px;
|
||||
@@ -12,5 +17,7 @@ dimensions {
|
||||
val: 0.2;
|
||||
val: 5;
|
||||
angles-must-have-unit: 0deg;
|
||||
durations-must-have-unit: 0s;
|
||||
length-doesnt-have-unit: 0px;
|
||||
width: auto\9;
|
||||
}
|
||||
64
test/less/css-guards.less
Normal file
64
test/less/css-guards.less
Normal file
@@ -0,0 +1,64 @@
|
||||
|
||||
.light when (lightness(@a) > 50%) {
|
||||
color: green;
|
||||
}
|
||||
.dark when (lightness(@a) < 50%) {
|
||||
color: orange;
|
||||
}
|
||||
@a: #ddd;
|
||||
|
||||
.see-the {
|
||||
@a: #444; // this mirrors what mixins do - they evaluate guards at the point of execution
|
||||
.light();
|
||||
.dark();
|
||||
}
|
||||
|
||||
.hide-the {
|
||||
.light();
|
||||
.dark();
|
||||
}
|
||||
|
||||
.multiple-conditions-1 when (@b = 1), (@c = 2), (@d = 3) {
|
||||
color: red;
|
||||
}
|
||||
|
||||
.multiple-conditions-2 when (@b = 1), (@c = 2), (@d = 2) {
|
||||
color: blue;
|
||||
}
|
||||
|
||||
@b: 2;
|
||||
@c: 3;
|
||||
@d: 3;
|
||||
|
||||
.inheritance when (@b = 2) {
|
||||
.test {
|
||||
color: black;
|
||||
}
|
||||
&:hover {
|
||||
color: pink;
|
||||
}
|
||||
.hideme when (@b = 1) {
|
||||
color: green;
|
||||
}
|
||||
& when (@b = 1) {
|
||||
hideme: green;
|
||||
}
|
||||
}
|
||||
|
||||
.hideme when (@b = 1) {
|
||||
.test {
|
||||
color: black;
|
||||
}
|
||||
&:hover {
|
||||
color: pink;
|
||||
}
|
||||
.hideme when (@b = 1) {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
|
||||
& when (@b = 1) {
|
||||
.hideme {
|
||||
color: red;
|
||||
}
|
||||
}
|
||||
3
test/less/errors/svg-gradient1.less
Normal file
3
test/less/errors/svg-gradient1.less
Normal file
@@ -0,0 +1,3 @@
|
||||
.a {
|
||||
a: svg-gradient(horizontal, black, white);
|
||||
}
|
||||
4
test/less/errors/svg-gradient1.txt
Normal file
4
test/less/errors/svg-gradient1.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
ArgumentError: error evaluating function `svg-gradient`: svg-gradient direction must be 'to bottom', 'to right', 'to bottom right', 'to top right' or 'ellipse at center' in {path}svg-gradient1.less on line 2, column 6:
|
||||
1 .a {
|
||||
2 a: svg-gradient(horizontal, black, white);
|
||||
3 }
|
||||
3
test/less/errors/svg-gradient2.less
Normal file
3
test/less/errors/svg-gradient2.less
Normal file
@@ -0,0 +1,3 @@
|
||||
.a {
|
||||
a: svg-gradient(to bottom, black, orange, 45%, white);
|
||||
}
|
||||
4
test/less/errors/svg-gradient2.txt
Normal file
4
test/less/errors/svg-gradient2.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
ArgumentError: error evaluating function `svg-gradient`: svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position] in {path}svg-gradient2.less on line 2, column 6:
|
||||
1 .a {
|
||||
2 a: svg-gradient(to bottom, black, orange, 45%, white);
|
||||
3 }
|
||||
3
test/less/errors/svg-gradient3.less
Normal file
3
test/less/errors/svg-gradient3.less
Normal file
@@ -0,0 +1,3 @@
|
||||
.a {
|
||||
a: svg-gradient(black, orange);
|
||||
}
|
||||
4
test/less/errors/svg-gradient3.txt
Normal file
4
test/less/errors/svg-gradient3.txt
Normal file
@@ -0,0 +1,4 @@
|
||||
ArgumentError: error evaluating function `svg-gradient`: svg-gradient expects direction, start_color [start_position], [color position,]..., end_color [end_position] in {path}svg-gradient3.less on line 2, column 6:
|
||||
1 .a {
|
||||
2 a: svg-gradient(black, orange);
|
||||
3 }
|
||||
@@ -81,4 +81,19 @@ div.ext5,
|
||||
.attribute-test {
|
||||
&:extend([data="test3"] all);
|
||||
}
|
||||
}
|
||||
|
||||
.header {
|
||||
.header-nav {
|
||||
background: red;
|
||||
&:before {
|
||||
background: blue;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
.footer {
|
||||
.footer-nav {
|
||||
&:extend( .header .header-nav all );
|
||||
}
|
||||
}
|
||||
@@ -30,6 +30,7 @@
|
||||
luma-cyan: luma(#00ffff);
|
||||
luma-white-alpha: luma(rgba(255,255,255,0.5));
|
||||
contrast-filter: contrast(30%);
|
||||
saturate-filter: saturate(5%);
|
||||
contrast-white: contrast(#fff);
|
||||
contrast-black: contrast(#000);
|
||||
contrast-red: contrast(#ff0000);
|
||||
@@ -86,6 +87,11 @@
|
||||
pow: pow(8px, 2);
|
||||
pow: pow(4, 3);
|
||||
pow: pow(3, 3em);
|
||||
min: min(0);
|
||||
min: min("junk", 6, 5);
|
||||
min: min(1pc, 3pt);
|
||||
max: max(1, 3);
|
||||
max: max(3%, 1cm, 8%, 2mm);
|
||||
percentage: percentage((10px / 50));
|
||||
color: color("#ff0011");
|
||||
tint: tint(#777777, 13);
|
||||
|
||||
2
test/less/import-inline.less
Normal file
2
test/less/import-inline.less
Normal file
@@ -0,0 +1,2 @@
|
||||
@import (inline) url("import/import-test-d.css") (min-width:600px);
|
||||
@import (inline, css) url("import/invalid-css.less");
|
||||
18
test/less/import-reference.less
Normal file
18
test/less/import-reference.less
Normal file
@@ -0,0 +1,18 @@
|
||||
@import (reference) url("import-once.less");
|
||||
@import (reference) url("css-3.less");
|
||||
@import (reference) url("media.less");
|
||||
/*
|
||||
The media statement above is invalid (no selector)
|
||||
We should ban invalid media queries with properties and no selector?
|
||||
*/
|
||||
@import (reference) url("import/import-reference.less");
|
||||
|
||||
.b {
|
||||
.z();
|
||||
}
|
||||
|
||||
.zz();
|
||||
|
||||
.visible:extend(.z all) {
|
||||
extend: test;
|
||||
}
|
||||
43
test/less/import/import-reference.less
Normal file
43
test/less/import/import-reference.less
Normal file
@@ -0,0 +1,43 @@
|
||||
.z {
|
||||
color: red;
|
||||
.c {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
.only-with-visible,
|
||||
.z {
|
||||
color: green;
|
||||
&:hover {
|
||||
color: green;
|
||||
}
|
||||
& {
|
||||
color: green;
|
||||
}
|
||||
& + & {
|
||||
color: green;
|
||||
.sub {
|
||||
color: green;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
& {
|
||||
.hidden {
|
||||
hidden: true;
|
||||
}
|
||||
}
|
||||
|
||||
@media tv {
|
||||
.hidden {
|
||||
hidden: true;
|
||||
}
|
||||
}
|
||||
|
||||
/* comment is not output */
|
||||
|
||||
.zz {
|
||||
.y {
|
||||
pulled-in: yes;
|
||||
}
|
||||
/* comment pulled in */
|
||||
}
|
||||
1
test/less/import/invalid-css.less
Normal file
1
test/less/import/invalid-css.less
Normal file
@@ -0,0 +1 @@
|
||||
this isn't very valid CSS.
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user