less 1.2.2 → 1.3.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/.npmignore +1 -0
- package/CHANGELOG.md +118 -0
- package/CONTRIBUTING.md +50 -0
- package/Makefile +14 -2
- package/benchmark/benchmark.less +11 -11
- package/benchmark/less-benchmark.js +1 -1
- package/bin/lessc +77 -21
- package/build/amd.js +6 -0
- package/build/ecma-5.js +120 -0
- package/build/header.js +7 -0
- package/build/require-rhino.js +7 -0
- package/build/require.js +7 -0
- package/lib/less/browser.js +192 -53
- package/lib/less/colors.js +1 -0
- package/lib/less/functions.js +159 -10
- package/lib/less/index.js +125 -56
- package/lib/less/lessc_helper.js +62 -0
- package/lib/less/parser.js +391 -154
- package/lib/less/rhino.js +84 -23
- package/lib/less/tree/anonymous.js +15 -1
- package/lib/less/tree/assignment.js +3 -1
- package/lib/less/tree/call.js +12 -6
- package/lib/less/tree/color.js +10 -0
- package/lib/less/tree/dimension.js +3 -1
- package/lib/less/tree/directive.js +10 -10
- package/lib/less/tree/element.js +8 -7
- package/lib/less/tree/import.js +17 -14
- package/lib/less/tree/media.js +121 -0
- package/lib/less/tree/mixin.js +133 -45
- package/lib/less/tree/operation.js +5 -0
- package/lib/less/tree/quoted.js +15 -1
- package/lib/less/tree/ratio.js +13 -0
- package/lib/less/tree/rule.js +7 -0
- package/lib/less/tree/ruleset.js +236 -37
- package/lib/less/tree/selector.js +21 -11
- package/lib/less/tree/unicode-descriptor.js +13 -0
- package/lib/less/tree/url.js +16 -14
- package/lib/less/tree/variable.js +13 -1
- package/lib/less/tree.js +28 -0
- package/package.json +13 -3
- package/test/browser/common.js +74 -0
- package/test/browser/css/relative-urls/urls.css +36 -0
- package/test/browser/css/rootpath/urls.css +36 -0
- package/test/browser/css/rootpath-relative/urls.css +36 -0
- package/test/browser/css/urls.css +36 -0
- package/test/browser/jasmine-html.js +681 -0
- package/test/browser/jasmine.css +82 -0
- package/test/browser/jasmine.js +2600 -0
- package/test/browser/less/imports/urls.less +4 -0
- package/test/browser/less/imports/urls2.less +4 -0
- package/test/browser/less/relative-urls/urls.less +33 -0
- package/test/browser/less/rootpath/urls.less +33 -0
- package/test/browser/less/rootpath-relative/urls.less +33 -0
- package/test/browser/less/urls.less +33 -0
- package/test/browser/phantom-runner.js +139 -0
- package/test/browser/runner-browser.js +3 -0
- package/test/browser/runner-main.js +15 -0
- package/test/browser/runner-relative-urls.js +4 -0
- package/test/browser/runner-rootpath-relative.js +5 -0
- package/test/browser/runner-rootpath.js +4 -0
- package/test/browser/template.htm +10 -0
- package/test/browser-test-prepare.js +29 -0
- package/test/css/charsets.css +1 -0
- package/test/css/colors.css +22 -0
- package/test/css/comments.css +7 -0
- package/test/css/css-3.css +57 -2
- package/test/css/css-escapes.css +4 -0
- package/test/css/css.css +11 -11
- package/test/css/debug/linenumbers-all.css +43 -0
- package/test/css/debug/linenumbers-comments.css +35 -0
- package/test/css/debug/linenumbers-mediaquery.css +35 -0
- package/test/css/functions.css +59 -2
- package/test/css/ie-filters.css +7 -3
- package/test/css/import-once.css +3 -0
- package/test/css/import.css +7 -9
- package/test/css/javascript.css +3 -2
- package/test/css/media.css +168 -0
- package/test/css/mixins-args.css +35 -4
- package/test/css/mixins-guards.css +13 -0
- package/test/css/mixins-important.css +21 -0
- package/test/css/mixins-named-args.css +27 -0
- package/test/css/mixins-pattern.css +4 -6
- package/test/css/mixins.css +50 -0
- package/test/css/scope.css +20 -0
- package/test/css/selectors.css +76 -0
- package/test/css/static-urls/urls.css +42 -0
- package/test/css/strings.css +2 -2
- package/test/css/urls.css +42 -0
- package/test/css/variables.css +0 -1
- package/test/css/whitespace.css +4 -0
- package/test/less/charsets.less +3 -0
- package/test/less/colors.less +27 -0
- package/test/less/comments.less +12 -0
- package/test/less/css-3.less +54 -6
- package/test/less/css-escapes.less +6 -1
- package/test/less/css.less +14 -12
- package/test/less/debug/import/test.less +25 -0
- package/test/less/debug/linenumbers.less +23 -0
- package/test/less/errors/bad-variable-declaration1.less +1 -0
- package/test/less/errors/bad-variable-declaration1.txt +2 -0
- package/test/less/errors/comment-in-selector.less +1 -0
- package/test/less/errors/comment-in-selector.txt +2 -0
- package/test/less/errors/import-missing.less +1 -0
- package/test/less/errors/import-missing.txt +3 -0
- package/test/less/errors/import-no-semi.less +1 -0
- package/test/less/errors/import-no-semi.txt +2 -0
- package/test/less/errors/import-subfolder1.less +1 -0
- package/test/less/errors/import-subfolder1.txt +3 -0
- package/test/less/errors/import-subfolder2.less +1 -0
- package/test/less/errors/import-subfolder2.txt +2 -0
- package/test/less/errors/imports/import-subfolder1.less +1 -0
- package/test/less/errors/imports/import-subfolder2.less +1 -0
- package/test/less/errors/imports/import-test.less +4 -0
- package/test/less/errors/imports/subfolder/mixin-not-defined.less +1 -0
- package/test/less/errors/imports/subfolder/parse-error-curly-bracket.less +1 -0
- package/test/less/errors/javascript-error.less +3 -0
- package/test/less/errors/javascript-error.txt +4 -0
- package/test/less/errors/mixed-mixin-definition-args-1.less +6 -0
- package/test/less/errors/mixed-mixin-definition-args-1.txt +4 -0
- package/test/less/errors/mixed-mixin-definition-args-2.less +6 -0
- package/test/less/errors/mixed-mixin-definition-args-2.txt +4 -0
- package/test/less/errors/mixin-not-defined.less +11 -0
- package/test/less/errors/mixin-not-defined.txt +3 -0
- package/test/less/errors/mixin-not-matched.less +6 -0
- package/test/less/errors/mixin-not-matched.txt +3 -0
- package/test/less/errors/mixin-not-matched2.less +6 -0
- package/test/less/errors/mixin-not-matched2.txt +3 -0
- package/test/less/errors/parse-error-curly-bracket.less +1 -0
- package/test/less/errors/parse-error-curly-bracket.txt +2 -0
- package/test/less/errors/parse-error-missing-bracket.less +2 -0
- package/test/less/errors/parse-error-missing-bracket.txt +2 -0
- package/test/less/errors/parse-error-with-import.less +13 -0
- package/test/less/errors/parse-error-with-import.txt +4 -0
- package/test/less/errors/property-ie5-hack.less +3 -0
- package/test/less/errors/property-ie5-hack.txt +4 -0
- package/test/less/errors/recursive-variable.less +1 -0
- package/test/less/errors/recursive-variable.txt +2 -0
- package/test/less/functions.less +64 -2
- package/test/less/ie-filters.less +7 -0
- package/test/less/import/deeper/import-once-test-a.less +1 -0
- package/test/less/import/import-and-relative-paths-test.less +6 -0
- package/test/less/import/import-charset-test.less +1 -0
- package/test/less/import/import-once-test-c.less +6 -0
- package/test/less/import/import-test-a.less +1 -0
- package/test/less/import/import-test-c.less +0 -1
- package/test/less/import/imports/font.less +8 -0
- package/test/less/import/imports/logo.less +5 -0
- package/test/less/import/urls.less +1 -0
- package/test/less/import-once.less +4 -0
- package/test/less/import.less +2 -1
- package/test/less/javascript.less +4 -2
- package/test/less/media.less +169 -1
- package/test/less/mixins-args.less +54 -11
- package/test/less/mixins-guards.less +30 -0
- package/test/less/mixins-important.less +4 -0
- package/test/less/mixins-named-args.less +36 -0
- package/test/less/mixins-pattern.less +3 -0
- package/test/less/mixins.less +47 -0
- package/test/less/scope.less +48 -1
- package/test/less/selectors.less +88 -0
- package/test/less/static-urls/urls.less +33 -0
- package/test/less/strings.less +1 -1
- package/test/less/urls.less +33 -0
- package/test/less/variables.less +0 -1
- package/test/less/whitespace.less +7 -0
- package/test/less-test.js +145 -36
- package/bench.css +0 -5943
- package/benchmark/b1.less +0 -3980
- package/dist/less-1.1.0.js +0 -2695
- package/dist/less-1.1.0.min.js +0 -16
- package/dist/less-1.1.1.js +0 -2710
- package/dist/less-1.1.1.min.js +0 -16
- package/dist/less-1.1.2.js +0 -2712
- package/dist/less-1.1.2.min.js +0 -16
- package/dist/less-1.1.3.js +0 -2721
- package/dist/less-1.1.3.min.js +0 -16
- package/dist/less-1.1.4.js +0 -2769
- package/dist/less-1.1.4.min.js +0 -16
- package/dist/less-1.1.5.js +0 -2805
- package/dist/less-1.1.5.min.js +0 -9
- package/dist/less-1.1.6.js +0 -3004
- package/dist/less-1.1.6.min.js +0 -9
- package/dist/less-1.2.0.js +0 -3293
- package/dist/less-1.2.0.min.js +0 -9
- package/dist/less-1.2.1.js +0 -3318
- package/dist/less-1.2.1.min.js +0 -9
- package/dist/less-1.2.2.js +0 -3337
- package/dist/less-1.2.2.min.js +0 -9
- package/dist/less-rhino-1.1.3.js +0 -2460
- package/dist/less-rhino-1.1.5.js +0 -2481
- package/foo.less +0 -2
- package/lib/less/cssmin.js +0 -355
- package/test/html/index.html +0 -10
- package/test/html/less.js +0 -3333
- package/test/html/lib.less +0 -2
- package/test/html/styles.less +0 -8
- package/x.less +0 -4
package/lib/less/rhino.js
CHANGED
|
@@ -1,20 +1,27 @@
|
|
|
1
1
|
var name;
|
|
2
2
|
|
|
3
3
|
function loadStyleSheet(sheet, callback, reload, remaining) {
|
|
4
|
-
var
|
|
5
|
-
|
|
4
|
+
var endOfPath = Math.max(name.lastIndexOf('/'), name.lastIndexOf('\\')),
|
|
5
|
+
sheetName = name.slice(0, endOfPath + 1) + sheet.href,
|
|
6
|
+
contents = sheet.contents || {},
|
|
7
|
+
input = readFile(sheetName);
|
|
8
|
+
|
|
9
|
+
contents[sheetName] = input;
|
|
10
|
+
|
|
6
11
|
var parser = new less.Parser({
|
|
7
|
-
paths: [sheet.href.replace(/[\w\.-]+$/, '')]
|
|
12
|
+
paths: [sheet.href.replace(/[\w\.-]+$/, '')],
|
|
13
|
+
contents: contents
|
|
8
14
|
});
|
|
9
15
|
parser.parse(input, function (e, root) {
|
|
10
16
|
if (e) {
|
|
11
|
-
|
|
12
|
-
|
|
17
|
+
return error(e, sheetName);
|
|
18
|
+
}
|
|
19
|
+
try {
|
|
20
|
+
callback(e, root, input, sheet, { local: false, lastModified: 0, remaining: remaining }, sheetName);
|
|
21
|
+
} catch(e) {
|
|
22
|
+
error(e, sheetName);
|
|
13
23
|
}
|
|
14
|
-
callback(root, sheet, { local: false, lastModified: 0, remaining: remaining });
|
|
15
24
|
});
|
|
16
|
-
|
|
17
|
-
// callback({}, sheet, { local: true, remaining: remaining });
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
function writeFile(filename, content) {
|
|
@@ -26,8 +33,26 @@ function writeFile(filename, content) {
|
|
|
26
33
|
|
|
27
34
|
// Command line integration via Rhino
|
|
28
35
|
(function (args) {
|
|
29
|
-
|
|
30
|
-
|
|
36
|
+
var output,
|
|
37
|
+
compress = false,
|
|
38
|
+
i;
|
|
39
|
+
|
|
40
|
+
for(i = 0; i < args.length; i++) {
|
|
41
|
+
switch(args[i]) {
|
|
42
|
+
case "-x":
|
|
43
|
+
compress = true;
|
|
44
|
+
break;
|
|
45
|
+
default:
|
|
46
|
+
if (!name) {
|
|
47
|
+
name = args[i];
|
|
48
|
+
} else if (!output) {
|
|
49
|
+
output = args[i];
|
|
50
|
+
} else {
|
|
51
|
+
print("unrecognised parameters");
|
|
52
|
+
print("input_file [output_file] [-x]");
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
31
56
|
|
|
32
57
|
if (!name) {
|
|
33
58
|
print('No files present in the fileset; Check your pattern match in build.xml');
|
|
@@ -43,20 +68,56 @@ function writeFile(filename, content) {
|
|
|
43
68
|
}
|
|
44
69
|
|
|
45
70
|
var result;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
if (output) {
|
|
53
|
-
writeFile(output, result);
|
|
54
|
-
print("Written to " + output);
|
|
71
|
+
try {
|
|
72
|
+
var parser = new less.Parser();
|
|
73
|
+
parser.parse(input, function (e, root) {
|
|
74
|
+
if (e) {
|
|
75
|
+
error(e, name);
|
|
76
|
+
quit(1);
|
|
55
77
|
} else {
|
|
56
|
-
|
|
78
|
+
result = root.toCSS({compress: compress || false});
|
|
79
|
+
if (output) {
|
|
80
|
+
writeFile(output, result);
|
|
81
|
+
print("Written to " + output);
|
|
82
|
+
} else {
|
|
83
|
+
print(result);
|
|
84
|
+
}
|
|
85
|
+
quit(0);
|
|
57
86
|
}
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
catch(e) {
|
|
90
|
+
error(e, name);
|
|
91
|
+
quit(1);
|
|
92
|
+
}
|
|
61
93
|
print("done");
|
|
62
94
|
}(arguments));
|
|
95
|
+
|
|
96
|
+
function error(e, filename) {
|
|
97
|
+
|
|
98
|
+
var content = "Error : " + filename + "\n";
|
|
99
|
+
|
|
100
|
+
filename = e.filename || filename;
|
|
101
|
+
|
|
102
|
+
if (e.message) {
|
|
103
|
+
content += e.message + "\n";
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
var errorline = function (e, i, classname) {
|
|
107
|
+
if (e.extract[i]) {
|
|
108
|
+
content +=
|
|
109
|
+
String(parseInt(e.line) + (i - 1)) +
|
|
110
|
+
":" + e.extract[i] + "\n";
|
|
111
|
+
}
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
if (e.stack) {
|
|
115
|
+
content += e.stack;
|
|
116
|
+
} else if (e.extract) {
|
|
117
|
+
content += 'on line ' + e.line + ', column ' + (e.column + 1) + ':\n';
|
|
118
|
+
errorline(e, 0);
|
|
119
|
+
errorline(e, 1);
|
|
120
|
+
errorline(e, 2);
|
|
121
|
+
}
|
|
122
|
+
print(content);
|
|
123
|
+
}
|
|
@@ -7,7 +7,21 @@ tree.Anonymous.prototype = {
|
|
|
7
7
|
toCSS: function () {
|
|
8
8
|
return this.value;
|
|
9
9
|
},
|
|
10
|
-
eval: function () { return this }
|
|
10
|
+
eval: function () { return this },
|
|
11
|
+
compare: function (x) {
|
|
12
|
+
if (!x.toCSS) {
|
|
13
|
+
return -1;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
var left = this.toCSS(),
|
|
17
|
+
right = x.toCSS();
|
|
18
|
+
|
|
19
|
+
if (left === right) {
|
|
20
|
+
return 0;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return left < right ? -1 : 1;
|
|
24
|
+
}
|
|
11
25
|
};
|
|
12
26
|
|
|
13
27
|
})(require('../tree'));
|
|
@@ -9,7 +9,9 @@ tree.Assignment.prototype = {
|
|
|
9
9
|
return this.key + '=' + (this.value.toCSS ? this.value.toCSS() : this.value);
|
|
10
10
|
},
|
|
11
11
|
eval: function (env) {
|
|
12
|
-
if (this.value.eval) {
|
|
12
|
+
if (this.value.eval) {
|
|
13
|
+
return new(tree.Assignment)(this.key, this.value.eval(env));
|
|
14
|
+
}
|
|
13
15
|
return this;
|
|
14
16
|
}
|
|
15
17
|
};
|
package/lib/less/tree/call.js
CHANGED
|
@@ -14,7 +14,8 @@ tree.Call.prototype = {
|
|
|
14
14
|
// When evaluating a function call,
|
|
15
15
|
// we either find the function in `tree.functions` [1],
|
|
16
16
|
// in which case we call it, passing the evaluated arguments,
|
|
17
|
-
//
|
|
17
|
+
// if this returns null or we cannot find the function, we
|
|
18
|
+
// simply print it out as it appeared originally [2].
|
|
18
19
|
//
|
|
19
20
|
// The *functions.js* file contains the built-in functions.
|
|
20
21
|
//
|
|
@@ -23,21 +24,26 @@ tree.Call.prototype = {
|
|
|
23
24
|
// The function should receive the value, not the variable.
|
|
24
25
|
//
|
|
25
26
|
eval: function (env) {
|
|
26
|
-
var args = this.args.map(function (a) { return a.eval(env) })
|
|
27
|
+
var args = this.args.map(function (a) { return a.eval(env) }),
|
|
28
|
+
result;
|
|
27
29
|
|
|
28
30
|
if (this.name in tree.functions) { // 1.
|
|
29
31
|
try {
|
|
30
|
-
|
|
32
|
+
result = tree.functions[this.name].apply(tree.functions, args);
|
|
33
|
+
if (result != null) {
|
|
34
|
+
return result;
|
|
35
|
+
}
|
|
31
36
|
} catch (e) {
|
|
32
37
|
throw { type: e.type || "Runtime",
|
|
33
38
|
message: "error evaluating function `" + this.name + "`" +
|
|
34
39
|
(e.message ? ': ' + e.message : ''),
|
|
35
40
|
index: this.index, filename: this.filename };
|
|
36
41
|
}
|
|
37
|
-
} else { // 2.
|
|
38
|
-
return new(tree.Anonymous)(this.name +
|
|
39
|
-
"(" + args.map(function (a) { return a.toCSS() }).join(', ') + ")");
|
|
40
42
|
}
|
|
43
|
+
|
|
44
|
+
// 2.
|
|
45
|
+
return new(tree.Anonymous)(this.name +
|
|
46
|
+
"(" + args.map(function (a) { return a.toCSS(env) }).join(', ') + ")");
|
|
41
47
|
},
|
|
42
48
|
|
|
43
49
|
toCSS: function (env) {
|
package/lib/less/tree/color.js
CHANGED
|
@@ -94,6 +94,16 @@ tree.Color.prototype = {
|
|
|
94
94
|
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
|
|
95
95
|
return i.length === 1 ? '0' + i : i;
|
|
96
96
|
}).join('');
|
|
97
|
+
},
|
|
98
|
+
compare: function (x) {
|
|
99
|
+
if (!x.rgb) {
|
|
100
|
+
return -1;
|
|
101
|
+
}
|
|
102
|
+
|
|
103
|
+
return (x.rgb[0] === this.rgb[0] &&
|
|
104
|
+
x.rgb[1] === this.rgb[1] &&
|
|
105
|
+
x.rgb[2] === this.rgb[2] &&
|
|
106
|
+
x.alpha === this.alpha) ? 0 : -1;
|
|
97
107
|
}
|
|
98
108
|
};
|
|
99
109
|
|
|
@@ -30,7 +30,6 @@ tree.Dimension.prototype = {
|
|
|
30
30
|
this.unit || other.unit);
|
|
31
31
|
},
|
|
32
32
|
|
|
33
|
-
// TODO: Perform unit conversion before comparing
|
|
34
33
|
compare: function (other) {
|
|
35
34
|
if (other instanceof tree.Dimension) {
|
|
36
35
|
if (other.value > this.value) {
|
|
@@ -38,6 +37,9 @@ tree.Dimension.prototype = {
|
|
|
38
37
|
} else if (other.value < this.value) {
|
|
39
38
|
return 1;
|
|
40
39
|
} else {
|
|
40
|
+
if (other.unit && this.unit !== other.unit) {
|
|
41
|
+
return -1;
|
|
42
|
+
}
|
|
41
43
|
return 0;
|
|
42
44
|
}
|
|
43
45
|
} else {
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
(function (tree) {
|
|
2
2
|
|
|
3
|
-
tree.Directive = function (name, value
|
|
3
|
+
tree.Directive = function (name, value) {
|
|
4
4
|
this.name = name;
|
|
5
|
-
this.features = features && new(tree.Value)(features);
|
|
6
5
|
|
|
7
6
|
if (Array.isArray(value)) {
|
|
8
7
|
this.ruleset = new(tree.Ruleset)([], value);
|
|
@@ -13,11 +12,9 @@ tree.Directive = function (name, value, features) {
|
|
|
13
12
|
};
|
|
14
13
|
tree.Directive.prototype = {
|
|
15
14
|
toCSS: function (ctx, env) {
|
|
16
|
-
var features = this.features ? ' ' + this.features.toCSS(env) : '';
|
|
17
|
-
|
|
18
15
|
if (this.ruleset) {
|
|
19
16
|
this.ruleset.root = true;
|
|
20
|
-
return this.name +
|
|
17
|
+
return this.name + (env.compress ? '{' : ' {\n ') +
|
|
21
18
|
this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
|
|
22
19
|
(env.compress ? '}': '\n}\n');
|
|
23
20
|
} else {
|
|
@@ -25,11 +22,14 @@ tree.Directive.prototype = {
|
|
|
25
22
|
}
|
|
26
23
|
},
|
|
27
24
|
eval: function (env) {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
25
|
+
var evaldDirective = this;
|
|
26
|
+
if (this.ruleset) {
|
|
27
|
+
env.frames.unshift(this);
|
|
28
|
+
evaldDirective = new(tree.Directive)(this.name);
|
|
29
|
+
evaldDirective.ruleset = this.ruleset.eval(env);
|
|
30
|
+
env.frames.shift();
|
|
31
|
+
}
|
|
32
|
+
return evaldDirective;
|
|
33
33
|
},
|
|
34
34
|
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
|
|
35
35
|
find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
|
package/lib/less/tree/element.js
CHANGED
|
@@ -19,14 +19,17 @@ tree.Element.prototype.eval = function (env) {
|
|
|
19
19
|
this.index);
|
|
20
20
|
};
|
|
21
21
|
tree.Element.prototype.toCSS = function (env) {
|
|
22
|
-
|
|
22
|
+
var value = (this.value.toCSS ? this.value.toCSS(env) : this.value);
|
|
23
|
+
if (value == '' && this.combinator.value.charAt(0) == '&') {
|
|
24
|
+
return '';
|
|
25
|
+
} else {
|
|
26
|
+
return this.combinator.toCSS(env || {}) + value;
|
|
27
|
+
}
|
|
23
28
|
};
|
|
24
29
|
|
|
25
30
|
tree.Combinator = function (value) {
|
|
26
31
|
if (value === ' ') {
|
|
27
32
|
this.value = ' ';
|
|
28
|
-
} else if (value === '& ') {
|
|
29
|
-
this.value = '& ';
|
|
30
33
|
} else {
|
|
31
34
|
this.value = value ? value.trim() : "";
|
|
32
35
|
}
|
|
@@ -35,13 +38,11 @@ tree.Combinator.prototype.toCSS = function (env) {
|
|
|
35
38
|
return {
|
|
36
39
|
'' : '',
|
|
37
40
|
' ' : ' ',
|
|
38
|
-
'&' : '',
|
|
39
|
-
'& ' : ' ',
|
|
40
41
|
':' : ' :',
|
|
41
|
-
'::': '::',
|
|
42
42
|
'+' : env.compress ? '+' : ' + ',
|
|
43
43
|
'~' : env.compress ? '~' : ' ~ ',
|
|
44
|
-
'>' : env.compress ? '>' : ' > '
|
|
44
|
+
'>' : env.compress ? '>' : ' > ',
|
|
45
|
+
'|' : env.compress ? '|' : ' | '
|
|
45
46
|
}[this.value];
|
|
46
47
|
};
|
|
47
48
|
|
package/lib/less/tree/import.js
CHANGED
|
@@ -11,26 +11,29 @@
|
|
|
11
11
|
// `import,push`, we also pass it a callback, which it'll call once
|
|
12
12
|
// the file has been fetched, and parsed.
|
|
13
13
|
//
|
|
14
|
-
tree.Import = function (path, imports, features, index) {
|
|
14
|
+
tree.Import = function (path, imports, features, once, index, rootpath) {
|
|
15
15
|
var that = this;
|
|
16
16
|
|
|
17
|
+
this.once = once;
|
|
17
18
|
this.index = index;
|
|
18
19
|
this._path = path;
|
|
19
20
|
this.features = features && new(tree.Value)(features);
|
|
20
|
-
|
|
21
|
+
this.rootpath = rootpath;
|
|
22
|
+
|
|
21
23
|
// The '.less' extension is optional
|
|
22
24
|
if (path instanceof tree.Quoted) {
|
|
23
|
-
this.path =
|
|
25
|
+
this.path = /(\.[a-z]*$)|([\?;].*)$/.test(path.value) ? path.value : path.value + '.less';
|
|
24
26
|
} else {
|
|
25
27
|
this.path = path.value.value || path.value;
|
|
26
28
|
}
|
|
27
29
|
|
|
28
|
-
this.css = /css(
|
|
30
|
+
this.css = /css([\?;].*)?$/.test(this.path);
|
|
29
31
|
|
|
30
32
|
// Only pre-compile .less files
|
|
31
33
|
if (! this.css) {
|
|
32
|
-
imports.push(this.path, function (e, root) {
|
|
34
|
+
imports.push(this.path, function (e, root, imported) {
|
|
33
35
|
if (e) { e.index = index }
|
|
36
|
+
if (imported && that.once) that.skip = imported;
|
|
34
37
|
that.root = root || new(tree.Ruleset)([], []);
|
|
35
38
|
});
|
|
36
39
|
}
|
|
@@ -50,6 +53,10 @@ tree.Import.prototype = {
|
|
|
50
53
|
var features = this.features ? ' ' + this.features.toCSS(env) : '';
|
|
51
54
|
|
|
52
55
|
if (this.css) {
|
|
56
|
+
// Add the base path if the import is relative
|
|
57
|
+
if (typeof this._path.value === "string" && !/^(?:[a-z-]+:|\/)/.test(this._path.value)) {
|
|
58
|
+
this._path.value = this.rootpath + this._path.value;
|
|
59
|
+
}
|
|
53
60
|
return "@import " + this._path.toCSS() + features + ';\n';
|
|
54
61
|
} else {
|
|
55
62
|
return "";
|
|
@@ -58,20 +65,16 @@ tree.Import.prototype = {
|
|
|
58
65
|
eval: function (env) {
|
|
59
66
|
var ruleset, features = this.features && this.features.eval(env);
|
|
60
67
|
|
|
68
|
+
if (this.skip) return [];
|
|
69
|
+
|
|
61
70
|
if (this.css) {
|
|
62
71
|
return this;
|
|
63
72
|
} else {
|
|
64
73
|
ruleset = new(tree.Ruleset)([], this.root.rules.slice(0));
|
|
65
74
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
.splice
|
|
70
|
-
.apply(ruleset.rules,
|
|
71
|
-
[i, 1].concat(ruleset.rules[i].eval(env)));
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
return this.features ? new(tree.Directive)('@media', ruleset.rules, this.features.value) : ruleset.rules;
|
|
75
|
+
ruleset.evalImports(env);
|
|
76
|
+
|
|
77
|
+
return this.features ? new(tree.Media)(ruleset.rules, this.features.value) : ruleset.rules;
|
|
75
78
|
}
|
|
76
79
|
}
|
|
77
80
|
};
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
(function (tree) {
|
|
2
|
+
|
|
3
|
+
tree.Media = function (value, features) {
|
|
4
|
+
var selectors = this.emptySelectors();
|
|
5
|
+
|
|
6
|
+
this.features = new(tree.Value)(features);
|
|
7
|
+
this.ruleset = new(tree.Ruleset)(selectors, value);
|
|
8
|
+
this.ruleset.allowImports = true;
|
|
9
|
+
};
|
|
10
|
+
tree.Media.prototype = {
|
|
11
|
+
toCSS: function (ctx, env) {
|
|
12
|
+
var features = this.features.toCSS(env);
|
|
13
|
+
|
|
14
|
+
this.ruleset.root = (ctx.length === 0 || ctx[0].multiMedia);
|
|
15
|
+
return '@media ' + features + (env.compress ? '{' : ' {\n ') +
|
|
16
|
+
this.ruleset.toCSS(ctx, env).trim().replace(/\n/g, '\n ') +
|
|
17
|
+
(env.compress ? '}': '\n}\n');
|
|
18
|
+
},
|
|
19
|
+
eval: function (env) {
|
|
20
|
+
if (!env.mediaBlocks) {
|
|
21
|
+
env.mediaBlocks = [];
|
|
22
|
+
env.mediaPath = [];
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
var media = new(tree.Media)([], []);
|
|
26
|
+
if(this.debugInfo) {
|
|
27
|
+
this.ruleset.debugInfo = this.debugInfo;
|
|
28
|
+
media.debugInfo = this.debugInfo;
|
|
29
|
+
}
|
|
30
|
+
media.features = this.features.eval(env);
|
|
31
|
+
|
|
32
|
+
env.mediaPath.push(media);
|
|
33
|
+
env.mediaBlocks.push(media);
|
|
34
|
+
|
|
35
|
+
env.frames.unshift(this.ruleset);
|
|
36
|
+
media.ruleset = this.ruleset.eval(env);
|
|
37
|
+
env.frames.shift();
|
|
38
|
+
|
|
39
|
+
env.mediaPath.pop();
|
|
40
|
+
|
|
41
|
+
return env.mediaPath.length === 0 ? media.evalTop(env) :
|
|
42
|
+
media.evalNested(env)
|
|
43
|
+
},
|
|
44
|
+
variable: function (name) { return tree.Ruleset.prototype.variable.call(this.ruleset, name) },
|
|
45
|
+
find: function () { return tree.Ruleset.prototype.find.apply(this.ruleset, arguments) },
|
|
46
|
+
rulesets: function () { return tree.Ruleset.prototype.rulesets.apply(this.ruleset) },
|
|
47
|
+
emptySelectors: function() {
|
|
48
|
+
var el = new(tree.Element)('', '&', 0);
|
|
49
|
+
return [new(tree.Selector)([el])];
|
|
50
|
+
},
|
|
51
|
+
|
|
52
|
+
evalTop: function (env) {
|
|
53
|
+
var result = this;
|
|
54
|
+
|
|
55
|
+
// Render all dependent Media blocks.
|
|
56
|
+
if (env.mediaBlocks.length > 1) {
|
|
57
|
+
var selectors = this.emptySelectors();
|
|
58
|
+
result = new(tree.Ruleset)(selectors, env.mediaBlocks);
|
|
59
|
+
result.multiMedia = true;
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
delete env.mediaBlocks;
|
|
63
|
+
delete env.mediaPath;
|
|
64
|
+
|
|
65
|
+
return result;
|
|
66
|
+
},
|
|
67
|
+
evalNested: function (env) {
|
|
68
|
+
var i, value,
|
|
69
|
+
path = env.mediaPath.concat([this]);
|
|
70
|
+
|
|
71
|
+
// Extract the media-query conditions separated with `,` (OR).
|
|
72
|
+
for (i = 0; i < path.length; i++) {
|
|
73
|
+
value = path[i].features instanceof tree.Value ?
|
|
74
|
+
path[i].features.value : path[i].features;
|
|
75
|
+
path[i] = Array.isArray(value) ? value : [value];
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// Trace all permutations to generate the resulting media-query.
|
|
79
|
+
//
|
|
80
|
+
// (a, b and c) with nested (d, e) ->
|
|
81
|
+
// a and d
|
|
82
|
+
// a and e
|
|
83
|
+
// b and c and d
|
|
84
|
+
// b and c and e
|
|
85
|
+
this.features = new(tree.Value)(this.permute(path).map(function (path) {
|
|
86
|
+
path = path.map(function (fragment) {
|
|
87
|
+
return fragment.toCSS ? fragment : new(tree.Anonymous)(fragment);
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
for(i = path.length - 1; i > 0; i--) {
|
|
91
|
+
path.splice(i, 0, new(tree.Anonymous)("and"));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
return new(tree.Expression)(path);
|
|
95
|
+
}));
|
|
96
|
+
|
|
97
|
+
// Fake a tree-node that doesn't output anything.
|
|
98
|
+
return new(tree.Ruleset)([], []);
|
|
99
|
+
},
|
|
100
|
+
permute: function (arr) {
|
|
101
|
+
if (arr.length === 0) {
|
|
102
|
+
return [];
|
|
103
|
+
} else if (arr.length === 1) {
|
|
104
|
+
return arr[0];
|
|
105
|
+
} else {
|
|
106
|
+
var result = [];
|
|
107
|
+
var rest = this.permute(arr.slice(1));
|
|
108
|
+
for (var i = 0; i < rest.length; i++) {
|
|
109
|
+
for (var j = 0; j < arr[0].length; j++) {
|
|
110
|
+
result.push([arr[0][j]].concat(rest[i]));
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
return result;
|
|
114
|
+
}
|
|
115
|
+
},
|
|
116
|
+
bubbleSelectors: function (selectors) {
|
|
117
|
+
this.ruleset = new(tree.Ruleset)(selectors.slice(0), [this.ruleset]);
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
|
|
121
|
+
})(require('../tree'));
|