less 2.4.0 → 2.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Changelog.md +4 -0
- data/Gemfile +1 -1
- data/less.gemspec +1 -1
- data/lib/less/defaults.rb +3 -3
- data/lib/less/java_script/v8_context.rb +1 -1
- data/lib/less/js/.gitattributes +3 -2
- data/lib/less/js/.gitignore +18 -2
- data/lib/less/js/.jshintrc +11 -0
- data/lib/less/js/CHANGELOG.md +87 -2
- data/lib/less/js/CONTRIBUTING.md +4 -3
- data/lib/less/js/Gruntfile.js +290 -0
- data/lib/less/js/README.md +342 -12
- data/lib/less/js/benchmark/benchmark.less +194 -194
- data/lib/less/js/benchmark/less-benchmark.js +9 -10
- data/lib/less/js/bin/lessc +154 -12
- data/lib/less/js/bower.json +18 -0
- data/lib/less/js/build.gradle +347 -0
- data/lib/less/js/build/README.md +350 -0
- data/lib/less/js/build/browser-header.js +4 -0
- data/lib/less/js/build/build.yml +160 -0
- data/lib/less/js/build/require-rhino.js +7 -2
- data/lib/less/js/build/rhino-header.js +4 -0
- data/lib/less/js/build/rhino-modules.js +131 -0
- data/lib/less/js/build/tasks/.gitkeep +1 -0
- data/lib/less/js/dist/less-1.5.0.js +6914 -0
- data/lib/less/js/dist/less-1.5.0.min.js +13 -0
- data/lib/less/js/dist/less-1.5.1.js +6941 -0
- data/lib/less/js/dist/less-1.5.1.min.js +13 -0
- data/lib/less/js/dist/less-1.6.0.js +7485 -0
- data/lib/less/js/dist/less-1.6.0.min.js +16 -0
- data/lib/less/js/dist/less-1.6.1.js +7513 -0
- data/lib/less/js/dist/less-1.6.1.min.js +16 -0
- data/lib/less/js/dist/less-1.6.2.js +7624 -0
- data/lib/less/js/dist/less-1.6.2.min.js +16 -0
- data/lib/less/js/dist/less-rhino-1.5.1.js +6831 -0
- data/lib/less/js/dist/less-rhino-1.6.2.js +9017 -0
- data/lib/less/js/dist/lessc-rhino-1.6.2.js +449 -0
- data/lib/less/js/gradle/wrapper/gradle-wrapper.jar +0 -0
- data/lib/less/js/gradle/wrapper/gradle-wrapper.properties +6 -0
- data/lib/less/js/gradlew +164 -0
- data/lib/less/js/gradlew.bat +90 -0
- data/lib/less/js/lib/less/browser.js +482 -367
- data/lib/less/js/lib/less/colors.js +0 -1
- data/lib/less/js/lib/less/encoder.js +4 -0
- data/lib/less/js/lib/less/env.js +50 -19
- data/lib/less/js/lib/less/extend-visitor.js +66 -41
- data/lib/less/js/lib/less/functions.js +309 -104
- data/lib/less/js/lib/less/import-visitor.js +21 -10
- data/lib/less/js/lib/less/index.js +90 -68
- data/lib/less/js/lib/less/join-selector-visitor.js +11 -4
- data/lib/less/js/lib/less/lessc_helper.js +56 -45
- data/lib/less/js/lib/less/parser.js +830 -460
- data/lib/less/js/lib/less/rhino.js +380 -58
- data/lib/less/js/lib/less/source-map-output.js +141 -0
- data/lib/less/js/lib/less/to-css-visitor.js +215 -0
- data/lib/less/js/lib/less/tree.js +57 -5
- data/lib/less/js/lib/less/tree/alpha.js +13 -5
- data/lib/less/js/lib/less/tree/anonymous.js +11 -5
- data/lib/less/js/lib/less/tree/assignment.js +11 -5
- data/lib/less/js/lib/less/tree/call.js +19 -8
- data/lib/less/js/lib/less/tree/color.js +59 -36
- data/lib/less/js/lib/less/tree/comment.js +17 -4
- data/lib/less/js/lib/less/tree/condition.js +3 -3
- data/lib/less/js/lib/less/tree/dimension.js +161 -153
- data/lib/less/js/lib/less/tree/directive.js +39 -18
- data/lib/less/js/lib/less/tree/element.js +41 -18
- data/lib/less/js/lib/less/tree/expression.js +11 -5
- data/lib/less/js/lib/less/tree/extend.js +11 -1
- data/lib/less/js/lib/less/tree/import.js +34 -20
- data/lib/less/js/lib/less/tree/javascript.js +16 -10
- data/lib/less/js/lib/less/tree/keyword.js +5 -2
- data/lib/less/js/lib/less/tree/media.js +39 -22
- data/lib/less/js/lib/less/tree/mixin.js +135 -56
- data/lib/less/js/lib/less/tree/negative.js +4 -2
- data/lib/less/js/lib/less/tree/operation.js +17 -12
- data/lib/less/js/lib/less/tree/paren.js +5 -2
- data/lib/less/js/lib/less/tree/quoted.js +9 -6
- data/lib/less/js/lib/less/tree/rule.js +39 -21
- data/lib/less/js/lib/less/tree/ruleset.js +229 -145
- data/lib/less/js/lib/less/tree/selector.js +101 -34
- data/lib/less/js/lib/less/tree/unicode-descriptor.js +4 -3
- data/lib/less/js/lib/less/tree/url.js +33 -11
- data/lib/less/js/lib/less/tree/value.js +13 -6
- data/lib/less/js/lib/less/tree/variable.js +13 -8
- data/lib/less/js/lib/less/visitor.js +117 -25
- data/lib/less/js/lib/source-map/source-map-0.1.31.js +1933 -0
- data/lib/less/js/lib/source-map/source-map-footer.js +4 -0
- data/lib/less/js/lib/source-map/source-map-header.js +3 -0
- data/lib/less/js/package.json +30 -15
- data/lib/less/js/test/browser/common.js +131 -56
- data/lib/less/js/test/browser/css/global-vars/simple.css +3 -0
- data/lib/less/js/test/browser/css/modify-vars/simple.css +8 -0
- data/lib/less/js/test/browser/css/relative-urls/urls.css +8 -9
- data/lib/less/js/test/browser/css/rootpath-relative/urls.css +0 -1
- data/lib/less/js/test/browser/css/rootpath/urls.css +0 -1
- data/lib/less/js/test/browser/css/urls.css +18 -14
- data/lib/less/js/test/browser/es5.js +27 -0
- data/lib/less/js/test/{less/errors/color-operation-error.less → browser/less/console-errors/test-error.less} +0 -0
- data/lib/less/js/test/browser/less/console-errors/test-error.txt +2 -0
- data/lib/less/js/test/browser/less/global-vars/simple.less +3 -0
- data/lib/less/js/test/browser/less/modify-vars/imports/simple2.less +4 -0
- data/lib/less/js/test/browser/less/modify-vars/simple.less +8 -0
- data/lib/less/js/test/browser/less/relative-urls/urls.less +1 -1
- data/lib/less/js/test/browser/less/rootpath-relative/urls.less +1 -1
- data/lib/less/js/test/browser/less/rootpath/urls.less +1 -1
- data/lib/less/js/test/browser/less/urls.less +9 -1
- data/lib/less/js/test/browser/phantom-runner.js +112 -103
- data/lib/less/js/test/browser/runner-browser-options.js +42 -0
- data/lib/less/js/test/browser/{runner-browser.js → runner-browser-spec.js} +7 -2
- data/lib/less/js/test/browser/runner-console-errors.js +5 -0
- data/lib/less/js/test/browser/runner-errors-options.js +5 -0
- data/lib/less/js/test/browser/runner-errors-spec.js +4 -0
- data/lib/less/js/test/browser/runner-global-vars-options.js +4 -0
- data/lib/less/js/test/browser/runner-global-vars-spec.js +3 -0
- data/lib/less/js/test/browser/runner-legacy-options.js +4 -0
- data/lib/less/js/test/browser/{runner-legacy.js → runner-legacy-spec.js} +1 -4
- data/lib/less/js/test/browser/runner-main-options.js +15 -0
- data/lib/less/js/test/browser/runner-main-spec.js +3 -0
- data/lib/less/js/test/browser/runner-modify-vars-options.js +2 -0
- data/lib/less/js/test/browser/runner-modify-vars-spec.js +43 -0
- data/lib/less/js/test/browser/runner-no-js-errors-options.js +4 -0
- data/lib/less/js/test/browser/runner-no-js-errors-spec.js +4 -0
- data/lib/less/js/test/browser/runner-production-options.js +3 -0
- data/lib/less/js/test/browser/{runner-production.js → runner-production-spec.js} +1 -3
- data/lib/less/js/test/browser/runner-relative-urls-options.js +3 -0
- data/lib/less/js/test/browser/{runner-relative-urls.js → runner-relative-urls-spec.js} +1 -2
- data/lib/less/js/test/browser/runner-rootpath-options.js +3 -0
- data/lib/less/js/test/browser/runner-rootpath-relative-options.js +4 -0
- data/lib/less/js/test/browser/{runner-rootpath-relative.js → runner-rootpath-relative-spec.js} +1 -3
- data/lib/less/js/test/browser/{runner-rootpath.js → runner-rootpath-spec.js} +1 -2
- data/lib/less/js/test/browser/test-runner-template.tmpl +47 -0
- data/lib/less/js/test/css/colors.css +7 -0
- data/lib/less/js/test/css/comments.css +9 -4
- data/lib/less/js/test/css/compression/compression.css +3 -2
- data/lib/less/js/test/css/css-3.css +17 -5
- data/lib/less/js/test/css/css-guards.css +37 -0
- data/lib/less/js/test/css/debug/linenumbers-all.css +6 -0
- data/lib/less/js/test/css/debug/linenumbers-comments.css +5 -0
- data/lib/less/js/test/css/debug/linenumbers-mediaquery.css +5 -0
- data/lib/less/js/test/css/empty.css +0 -0
- data/lib/less/js/test/css/extend-chaining.css +9 -0
- data/lib/less/js/test/css/extend-selector.css +10 -2
- data/lib/less/js/test/css/extract-and-length.css +133 -0
- data/lib/less/js/test/css/functions.css +23 -10
- data/lib/less/js/test/css/globalVars/extended.css +12 -0
- data/lib/less/js/test/css/globalVars/simple.css +6 -0
- data/lib/less/js/test/css/import-inline.css +5 -0
- data/lib/less/js/test/css/import-once.css +12 -0
- data/lib/less/js/test/css/import-reference.css +49 -0
- data/lib/less/js/test/css/import.css +0 -2
- data/lib/less/js/test/css/media.css +21 -5
- data/lib/less/js/test/css/merge.css +26 -0
- data/lib/less/js/test/css/mixins-guards-default-func.css +129 -0
- data/lib/less/js/test/css/mixins-guards.css +6 -0
- data/lib/less/js/test/css/mixins-important.css +7 -0
- data/lib/less/js/test/css/mixins-interpolated.css +39 -0
- data/lib/less/js/test/css/mixins.css +20 -0
- data/lib/less/js/test/css/modifyVars/extended.css +9 -0
- data/lib/less/js/test/css/no-output.css +0 -0
- data/lib/less/js/test/css/parens.css +3 -0
- data/lib/less/js/test/css/property-name-interp.css +20 -0
- data/lib/less/js/test/css/selectors.css +12 -0
- data/lib/less/js/test/css/static-urls/urls.css +7 -4
- data/lib/less/js/test/css/strings.css +3 -0
- data/lib/less/js/test/css/url-args/urls.css +56 -0
- data/lib/less/js/test/css/urls.css +21 -9
- data/lib/less/js/test/index.js +45 -0
- data/lib/less/js/test/less-test.js +234 -191
- data/lib/less/js/test/less/colors.less +6 -0
- data/lib/less/js/test/less/comments.less +7 -1
- data/lib/less/js/test/less/compression/compression.less +21 -1
- data/lib/less/js/test/less/css-3.less +12 -0
- data/lib/less/js/test/less/css-guards.less +99 -0
- data/lib/less/js/test/less/debug/linenumbers.less +11 -1
- data/lib/less/js/test/less/empty.less +0 -0
- data/lib/less/js/test/less/errors/add-mixed-units.txt +4 -2
- data/lib/less/js/test/less/errors/add-mixed-units2.txt +4 -2
- data/lib/less/js/test/less/errors/color-func-invalid-color.less +3 -0
- data/lib/less/js/test/less/errors/color-func-invalid-color.txt +4 -0
- data/lib/less/js/test/less/errors/css-guard-default-func.less +4 -0
- data/lib/less/js/test/less/errors/css-guard-default-func.txt +4 -0
- data/lib/less/js/test/less/errors/import-subfolder2.txt +4 -2
- data/lib/less/js/test/less/errors/javascript-undefined-var.less +3 -0
- data/lib/less/js/test/less/errors/javascript-undefined-var.txt +4 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-1.less +9 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-1.txt +4 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-2.less +9 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-2.txt +4 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-3.less +9 -0
- data/lib/less/js/test/less/errors/mixins-guards-default-func-3.txt +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors.less +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors.txt +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors2.less +4 -0
- data/lib/less/js/test/less/errors/multiple-guards-on-css-selectors2.txt +4 -0
- data/lib/less/js/test/less/errors/parse-error-curly-bracket.less +4 -1
- data/lib/less/js/test/less/errors/parse-error-curly-bracket.txt +4 -2
- data/lib/less/js/test/less/errors/parse-error-extra-parens.less +5 -0
- data/lib/less/js/test/less/errors/parse-error-extra-parens.txt +3 -0
- data/lib/less/js/test/less/errors/parse-error-missing-bracket.txt +2 -2
- data/lib/less/js/test/less/errors/parse-error-missing-parens.less +5 -0
- data/lib/less/js/test/less/errors/parse-error-missing-parens.txt +3 -0
- data/lib/less/js/test/less/errors/property-asterisk-only-name.less +3 -0
- data/lib/less/js/test/less/errors/property-asterisk-only-name.txt +4 -0
- data/lib/less/js/test/less/errors/property-interp-not-defined.less +1 -0
- data/lib/less/js/test/less/errors/property-interp-not-defined.txt +2 -0
- data/lib/less/js/test/less/errors/svg-gradient1.less +3 -0
- data/lib/less/js/test/less/errors/svg-gradient1.txt +4 -0
- data/lib/less/js/test/less/errors/svg-gradient2.less +3 -0
- data/lib/less/js/test/less/errors/svg-gradient2.txt +4 -0
- data/lib/less/js/test/less/errors/svg-gradient3.less +3 -0
- data/lib/less/js/test/less/errors/svg-gradient3.txt +4 -0
- data/lib/less/js/test/less/errors/unit-function.less +3 -0
- data/lib/less/js/test/less/errors/unit-function.txt +4 -0
- data/lib/less/js/test/less/extend-chaining.less +12 -0
- data/lib/less/js/test/less/extend-selector.less +15 -0
- data/lib/less/js/test/less/extract-and-length.less +133 -0
- data/lib/less/js/test/less/functions.less +15 -2
- data/lib/less/js/test/less/globalVars/extended.json +5 -0
- data/lib/less/js/test/less/globalVars/extended.less +10 -0
- data/lib/less/js/test/less/globalVars/simple.json +3 -0
- data/lib/less/js/test/less/globalVars/simple.less +3 -0
- data/lib/less/js/test/less/import-inline.less +2 -0
- data/lib/less/js/test/less/import-once.less +2 -0
- data/lib/less/js/test/less/import-reference.less +18 -0
- data/lib/less/js/test/less/import/import-and-relative-paths-test.less +11 -0
- data/lib/less/js/test/less/import/import-reference.less +43 -0
- data/lib/less/js/test/less/import/import-test-f.less +5 -0
- data/lib/less/js/test/less/import/invalid-css.less +1 -0
- data/lib/less/js/test/less/media.less +25 -1
- data/lib/less/js/test/less/merge.less +59 -0
- data/lib/less/js/test/less/mixins-args.less +10 -0
- data/lib/less/js/test/less/mixins-guards-default-func.less +195 -0
- data/lib/less/js/test/less/mixins-guards.less +16 -0
- data/lib/less/js/test/less/mixins-important.less +4 -1
- data/lib/less/js/test/less/mixins-interpolated.less +69 -0
- data/lib/less/js/test/less/mixins.less +27 -0
- data/lib/less/js/test/less/modifyVars/extended.json +5 -0
- data/lib/less/js/test/less/modifyVars/extended.less +11 -0
- data/lib/less/js/test/less/no-js-errors/no-js-errors.less +3 -0
- data/lib/less/js/test/less/no-js-errors/no-js-errors.txt +4 -0
- data/lib/less/js/test/less/no-output.less +2 -0
- data/lib/less/js/test/less/parens.less +4 -0
- data/lib/less/js/test/less/property-name-interp.less +53 -0
- data/lib/less/js/test/less/selectors.less +13 -0
- data/lib/less/js/test/less/sourcemaps/basic.json +3 -0
- data/lib/less/js/test/less/sourcemaps/basic.less +27 -0
- data/lib/less/js/test/less/sourcemaps/imported.css +7 -0
- data/lib/less/js/test/less/strings.less +6 -0
- data/lib/less/js/test/less/url-args/urls.less +63 -0
- data/lib/less/js/test/less/urls.less +15 -0
- data/lib/less/js/test/rhino/test-header.js +15 -0
- data/lib/less/js/test/sourcemaps/basic.json +1 -0
- data/lib/less/js/test/sourcemaps/index.html +17 -0
- data/lib/less/loader.rb +48 -40
- data/lib/less/version.rb +1 -1
- data/spec/less/parser_spec.rb +15 -15
- metadata +146 -40
- data/lib/less/js/Makefile +0 -102
- data/lib/less/js/build/header.js +0 -9
- data/lib/less/js/test/browser-test-prepare.js +0 -46
- data/lib/less/js/test/browser/runner-errors.js +0 -5
- data/lib/less/js/test/browser/runner-main.js +0 -15
- data/lib/less/js/test/browser/template.htm +0 -10
- data/lib/less/js/test/less/errors/color-operation-error.txt +0 -2
@@ -9,13 +9,21 @@ tree.Alpha.prototype = {
|
|
9
9
|
this.value = visitor.visit(this.value);
|
10
10
|
},
|
11
11
|
eval: function (env) {
|
12
|
-
if (this.value.eval) {
|
12
|
+
if (this.value.eval) { return new tree.Alpha(this.value.eval(env)); }
|
13
13
|
return this;
|
14
14
|
},
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
15
|
+
genCSS: function (env, output) {
|
16
|
+
output.add("alpha(opacity=");
|
17
|
+
|
18
|
+
if (this.value.genCSS) {
|
19
|
+
this.value.genCSS(env, output);
|
20
|
+
} else {
|
21
|
+
output.add(this.value);
|
22
|
+
}
|
23
|
+
|
24
|
+
output.add(")");
|
25
|
+
},
|
26
|
+
toCSS: tree.toCSS
|
19
27
|
};
|
20
28
|
|
21
29
|
})(require('../tree'));
|
@@ -1,14 +1,16 @@
|
|
1
1
|
(function (tree) {
|
2
2
|
|
3
|
-
tree.Anonymous = function (string) {
|
3
|
+
tree.Anonymous = function (string, index, currentFileInfo, mapLines) {
|
4
4
|
this.value = string.value || string;
|
5
|
+
this.index = index;
|
6
|
+
this.mapLines = mapLines;
|
7
|
+
this.currentFileInfo = currentFileInfo;
|
5
8
|
};
|
6
9
|
tree.Anonymous.prototype = {
|
7
10
|
type: "Anonymous",
|
8
|
-
|
9
|
-
return this.value;
|
11
|
+
eval: function () {
|
12
|
+
return new tree.Anonymous(this.value, this.index, this.currentFileInfo, this.mapLines);
|
10
13
|
},
|
11
|
-
eval: function () { return this },
|
12
14
|
compare: function (x) {
|
13
15
|
if (!x.toCSS) {
|
14
16
|
return -1;
|
@@ -22,7 +24,11 @@ tree.Anonymous.prototype = {
|
|
22
24
|
}
|
23
25
|
|
24
26
|
return left < right ? -1 : 1;
|
25
|
-
}
|
27
|
+
},
|
28
|
+
genCSS: function (env, output) {
|
29
|
+
output.add(this.value, this.currentFileInfo, this.index, this.mapLines);
|
30
|
+
},
|
31
|
+
toCSS: tree.toCSS
|
26
32
|
};
|
27
33
|
|
28
34
|
})(require('../tree'));
|
@@ -9,15 +9,21 @@ tree.Assignment.prototype = {
|
|
9
9
|
accept: function (visitor) {
|
10
10
|
this.value = visitor.visit(this.value);
|
11
11
|
},
|
12
|
-
toCSS: function () {
|
13
|
-
return this.key + '=' + (this.value.toCSS ? this.value.toCSS() : this.value);
|
14
|
-
},
|
15
12
|
eval: function (env) {
|
16
13
|
if (this.value.eval) {
|
17
14
|
return new(tree.Assignment)(this.key, this.value.eval(env));
|
18
15
|
}
|
19
16
|
return this;
|
20
|
-
}
|
17
|
+
},
|
18
|
+
genCSS: function (env, output) {
|
19
|
+
output.add(this.key + '=');
|
20
|
+
if (this.value.genCSS) {
|
21
|
+
this.value.genCSS(env, output);
|
22
|
+
} else {
|
23
|
+
output.add(this.value);
|
24
|
+
}
|
25
|
+
},
|
26
|
+
toCSS: tree.toCSS
|
21
27
|
};
|
22
28
|
|
23
|
-
})(require('../tree'));
|
29
|
+
})(require('../tree'));
|
@@ -12,7 +12,9 @@ tree.Call = function (name, args, index, currentFileInfo) {
|
|
12
12
|
tree.Call.prototype = {
|
13
13
|
type: "Call",
|
14
14
|
accept: function (visitor) {
|
15
|
-
|
15
|
+
if (this.args) {
|
16
|
+
this.args = visitor.visitArray(this.args);
|
17
|
+
}
|
16
18
|
},
|
17
19
|
//
|
18
20
|
// When evaluating a function call,
|
@@ -46,15 +48,24 @@ tree.Call.prototype = {
|
|
46
48
|
index: this.index, filename: this.currentFileInfo.filename };
|
47
49
|
}
|
48
50
|
}
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
|
52
|
+
return new tree.Call(this.name, args, this.index, this.currentFileInfo);
|
53
|
+
},
|
54
|
+
|
55
|
+
genCSS: function (env, output) {
|
56
|
+
output.add(this.name + "(", this.currentFileInfo, this.index);
|
57
|
+
|
58
|
+
for(var i = 0; i < this.args.length; i++) {
|
59
|
+
this.args[i].genCSS(env, output);
|
60
|
+
if (i + 1 < this.args.length) {
|
61
|
+
output.add(", ");
|
62
|
+
}
|
63
|
+
}
|
64
|
+
|
65
|
+
output.add(")");
|
53
66
|
},
|
54
67
|
|
55
|
-
toCSS:
|
56
|
-
return this.eval(env).toCSS();
|
57
|
-
}
|
68
|
+
toCSS: tree.toCSS
|
58
69
|
};
|
59
70
|
|
60
71
|
})(require('../tree'));
|
@@ -22,42 +22,46 @@ tree.Color = function (rgb, a) {
|
|
22
22
|
}
|
23
23
|
this.alpha = typeof(a) === 'number' ? a : 1;
|
24
24
|
};
|
25
|
+
|
26
|
+
var transparentKeyword = "transparent";
|
27
|
+
|
25
28
|
tree.Color.prototype = {
|
26
29
|
type: "Color",
|
27
|
-
eval: function () { return this },
|
30
|
+
eval: function () { return this; },
|
28
31
|
luma: function () { return (0.2126 * this.rgb[0] / 255) + (0.7152 * this.rgb[1] / 255) + (0.0722 * this.rgb[2] / 255); },
|
29
32
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
// which has better compatibility with older browsers.
|
34
|
-
// Values are capped between `0` and `255`, rounded and zero-padded.
|
35
|
-
//
|
33
|
+
genCSS: function (env, output) {
|
34
|
+
output.add(this.toCSS(env));
|
35
|
+
},
|
36
36
|
toCSS: function (env, doNotCompress) {
|
37
|
-
var compress = env && env.compress && !doNotCompress
|
38
|
-
|
37
|
+
var compress = env && env.compress && !doNotCompress,
|
38
|
+
alpha = tree.fround(env, this.alpha);
|
39
|
+
|
40
|
+
// If we have some transparency, the only way to represent it
|
41
|
+
// is via `rgba`. Otherwise, we use the hex representation,
|
42
|
+
// which has better compatibility with older browsers.
|
43
|
+
// Values are capped between `0` and `255`, rounded and zero-padded.
|
44
|
+
if (alpha < 1) {
|
45
|
+
if (alpha === 0 && this.isTransparentKeyword) {
|
46
|
+
return transparentKeyword;
|
47
|
+
}
|
39
48
|
return "rgba(" + this.rgb.map(function (c) {
|
40
|
-
return Math.round(c);
|
41
|
-
}).concat(
|
49
|
+
return clamp(Math.round(c), 255);
|
50
|
+
}).concat(clamp(alpha, 1))
|
51
|
+
.join(',' + (compress ? '' : ' ')) + ")";
|
42
52
|
} else {
|
43
|
-
var color = this.
|
44
|
-
i = Math.round(i);
|
45
|
-
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
|
46
|
-
return i.length === 1 ? '0' + i : i;
|
47
|
-
}).join('');
|
53
|
+
var color = this.toRGB();
|
48
54
|
|
49
55
|
if (compress) {
|
50
|
-
|
56
|
+
var splitcolor = color.split('');
|
51
57
|
|
52
58
|
// Convert color to short format
|
53
|
-
if (
|
54
|
-
color =
|
55
|
-
} else {
|
56
|
-
color = color.join('');
|
59
|
+
if (splitcolor[1] === splitcolor[2] && splitcolor[3] === splitcolor[4] && splitcolor[5] === splitcolor[6]) {
|
60
|
+
color = '#' + splitcolor[1] + splitcolor[3] + splitcolor[5];
|
57
61
|
}
|
58
62
|
}
|
59
63
|
|
60
|
-
return
|
64
|
+
return color;
|
61
65
|
}
|
62
66
|
},
|
63
67
|
|
@@ -68,16 +72,16 @@ tree.Color.prototype = {
|
|
68
72
|
// we create a new Color node to hold the result.
|
69
73
|
//
|
70
74
|
operate: function (env, op, other) {
|
71
|
-
var
|
72
|
-
|
73
|
-
if (! (other instanceof tree.Color)) {
|
74
|
-
other = other.toColor();
|
75
|
-
}
|
76
|
-
|
75
|
+
var rgb = [];
|
76
|
+
var alpha = this.alpha * (1 - other.alpha) + other.alpha;
|
77
77
|
for (var c = 0; c < 3; c++) {
|
78
|
-
|
78
|
+
rgb[c] = tree.operate(env, op, this.rgb[c], other.rgb[c]);
|
79
79
|
}
|
80
|
-
return new(tree.Color)(
|
80
|
+
return new(tree.Color)(rgb, alpha);
|
81
|
+
},
|
82
|
+
|
83
|
+
toRGB: function () {
|
84
|
+
return toHex(this.rgb);
|
81
85
|
},
|
82
86
|
|
83
87
|
toHSL: function () {
|
@@ -133,12 +137,7 @@ tree.Color.prototype = {
|
|
133
137
|
return { h: h * 360, s: s, v: v, a: a };
|
134
138
|
},
|
135
139
|
toARGB: function () {
|
136
|
-
|
137
|
-
return '#' + argb.map(function (i) {
|
138
|
-
i = Math.round(i);
|
139
|
-
i = (i > 255 ? 255 : (i < 0 ? 0 : i)).toString(16);
|
140
|
-
return i.length === 1 ? '0' + i : i;
|
141
|
-
}).join('');
|
140
|
+
return toHex([this.alpha * 255].concat(this.rgb));
|
142
141
|
},
|
143
142
|
compare: function (x) {
|
144
143
|
if (!x.rgb) {
|
@@ -152,5 +151,29 @@ tree.Color.prototype = {
|
|
152
151
|
}
|
153
152
|
};
|
154
153
|
|
154
|
+
tree.Color.fromKeyword = function(keyword) {
|
155
|
+
keyword = keyword.toLowerCase();
|
156
|
+
|
157
|
+
if (tree.colors.hasOwnProperty(keyword)) {
|
158
|
+
// detect named color
|
159
|
+
return new(tree.Color)(tree.colors[keyword].slice(1));
|
160
|
+
}
|
161
|
+
if (keyword === transparentKeyword) {
|
162
|
+
var transparent = new(tree.Color)([0, 0, 0], 0);
|
163
|
+
transparent.isTransparentKeyword = true;
|
164
|
+
return transparent;
|
165
|
+
}
|
166
|
+
};
|
167
|
+
|
168
|
+
function toHex(v) {
|
169
|
+
return '#' + v.map(function (c) {
|
170
|
+
c = clamp(Math.round(c), 255);
|
171
|
+
return (c < 16 ? '0' : '') + c.toString(16);
|
172
|
+
}).join('');
|
173
|
+
}
|
174
|
+
|
175
|
+
function clamp(v, max) {
|
176
|
+
return Math.min(Math.max(v, 0), max);
|
177
|
+
}
|
155
178
|
|
156
179
|
})(require('../tree'));
|
@@ -1,15 +1,28 @@
|
|
1
1
|
(function (tree) {
|
2
2
|
|
3
|
-
tree.Comment = function (value, silent) {
|
3
|
+
tree.Comment = function (value, silent, index, currentFileInfo) {
|
4
4
|
this.value = value;
|
5
5
|
this.silent = !!silent;
|
6
|
+
this.currentFileInfo = currentFileInfo;
|
6
7
|
};
|
7
8
|
tree.Comment.prototype = {
|
8
9
|
type: "Comment",
|
9
|
-
|
10
|
-
|
10
|
+
genCSS: function (env, output) {
|
11
|
+
if (this.debugInfo) {
|
12
|
+
output.add(tree.debugInfo(env, this), this.currentFileInfo, this.index);
|
13
|
+
}
|
14
|
+
output.add(this.value.trim()); //TODO shouldn't need to trim, we shouldn't grab the \n
|
11
15
|
},
|
12
|
-
|
16
|
+
toCSS: tree.toCSS,
|
17
|
+
isSilent: function(env) {
|
18
|
+
var isReference = (this.currentFileInfo && this.currentFileInfo.reference && !this.isReferenced),
|
19
|
+
isCompressed = env.compress && !this.value.match(/^\/\*!/);
|
20
|
+
return this.silent || isReference || isCompressed;
|
21
|
+
},
|
22
|
+
eval: function () { return this; },
|
23
|
+
markReferenced: function () {
|
24
|
+
this.isReferenced = true;
|
25
|
+
}
|
13
26
|
};
|
14
27
|
|
15
28
|
})(require('../tree'));
|
@@ -19,7 +19,7 @@ tree.Condition.prototype = {
|
|
19
19
|
|
20
20
|
var i = this.index, result;
|
21
21
|
|
22
|
-
|
22
|
+
result = (function (op) {
|
23
23
|
switch (op) {
|
24
24
|
case 'and':
|
25
25
|
return a && b;
|
@@ -36,8 +36,8 @@ tree.Condition.prototype = {
|
|
36
36
|
index: i };
|
37
37
|
}
|
38
38
|
switch (result) {
|
39
|
-
case -1: return op === '<' || op === '=<';
|
40
|
-
case 0: return op === '=' || op === '>=' || op === '=<';
|
39
|
+
case -1: return op === '<' || op === '=<' || op === '<=';
|
40
|
+
case 0: return op === '=' || op === '>=' || op === '=<' || op === '<=';
|
41
41
|
case 1: return op === '>' || op === '>=';
|
42
42
|
}
|
43
43
|
}
|
@@ -20,12 +20,12 @@ tree.Dimension.prototype = {
|
|
20
20
|
toColor: function () {
|
21
21
|
return new(tree.Color)([this.value, this.value, this.value]);
|
22
22
|
},
|
23
|
-
|
23
|
+
genCSS: function (env, output) {
|
24
24
|
if ((env && env.strictUnits) && !this.unit.isSingular()) {
|
25
25
|
throw new Error("Multiple units in dimension. Correct the units or use the unit function. Bad unit: "+this.unit.toString());
|
26
26
|
}
|
27
27
|
|
28
|
-
var value = this.value,
|
28
|
+
var value = tree.fround(env, this.value),
|
29
29
|
strValue = String(value);
|
30
30
|
|
31
31
|
if (value !== 0 && value < 0.000001 && value > -0.000001) {
|
@@ -35,8 +35,9 @@ tree.Dimension.prototype = {
|
|
35
35
|
|
36
36
|
if (env && env.compress) {
|
37
37
|
// Zero values doesn't need a unit
|
38
|
-
if (value === 0 &&
|
39
|
-
|
38
|
+
if (value === 0 && this.unit.isLength()) {
|
39
|
+
output.add(strValue);
|
40
|
+
return;
|
40
41
|
}
|
41
42
|
|
42
43
|
// Float values doesn't need a leading zero
|
@@ -45,13 +46,16 @@ tree.Dimension.prototype = {
|
|
45
46
|
}
|
46
47
|
}
|
47
48
|
|
48
|
-
|
49
|
+
output.add(strValue);
|
50
|
+
this.unit.genCSS(env, output);
|
49
51
|
},
|
52
|
+
toCSS: tree.toCSS,
|
50
53
|
|
51
54
|
// In an operation between two Dimensions,
|
52
55
|
// we default to the first Dimension's unit,
|
53
56
|
// so `1px + 2` will yield `3px`.
|
54
57
|
operate: function (env, op, other) {
|
58
|
+
/*jshint noempty:false */
|
55
59
|
var value = tree.operate(env, op, this.value, other.value),
|
56
60
|
unit = this.unit.clone();
|
57
61
|
|
@@ -59,7 +63,7 @@ tree.Dimension.prototype = {
|
|
59
63
|
if (unit.numerator.length === 0 && unit.denominator.length === 0) {
|
60
64
|
unit.numerator = other.unit.numerator.slice(0);
|
61
65
|
unit.denominator = other.unit.denominator.slice(0);
|
62
|
-
} else if (other.unit.numerator.length
|
66
|
+
} else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {
|
63
67
|
// do nothing
|
64
68
|
} else {
|
65
69
|
other = other.convertTo(this.unit.usedUnits());
|
@@ -104,202 +108,206 @@ tree.Dimension.prototype = {
|
|
104
108
|
},
|
105
109
|
|
106
110
|
unify: function () {
|
107
|
-
|
111
|
+
return this.convertTo({ length: 'm', duration: 's', angle: 'rad' });
|
108
112
|
},
|
109
113
|
|
110
114
|
convertTo: function (conversions) {
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
123
|
-
|
124
|
-
|
125
|
-
if (conversions.hasOwnProperty(groupName)) {
|
126
|
-
targetUnit = conversions[groupName];
|
127
|
-
group = tree.UnitConversions[groupName];
|
128
|
-
|
129
|
-
unit.map(function (atomicUnit, denominator) {
|
115
|
+
var value = this.value, unit = this.unit.clone(),
|
116
|
+
i, groupName, group, targetUnit, derivedConversions = {}, applyUnit;
|
117
|
+
|
118
|
+
if (typeof conversions === 'string') {
|
119
|
+
for(i in tree.UnitConversions) {
|
120
|
+
if (tree.UnitConversions[i].hasOwnProperty(conversions)) {
|
121
|
+
derivedConversions = {};
|
122
|
+
derivedConversions[i] = conversions;
|
123
|
+
}
|
124
|
+
}
|
125
|
+
conversions = derivedConversions;
|
126
|
+
}
|
127
|
+
applyUnit = function (atomicUnit, denominator) {
|
128
|
+
/*jshint loopfunc:true */
|
130
129
|
if (group.hasOwnProperty(atomicUnit)) {
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
130
|
+
if (denominator) {
|
131
|
+
value = value / (group[atomicUnit] / group[targetUnit]);
|
132
|
+
} else {
|
133
|
+
value = value * (group[atomicUnit] / group[targetUnit]);
|
134
|
+
}
|
136
135
|
|
137
|
-
|
136
|
+
return targetUnit;
|
138
137
|
}
|
139
138
|
|
140
139
|
return atomicUnit;
|
141
|
-
|
140
|
+
};
|
141
|
+
|
142
|
+
for (groupName in conversions) {
|
143
|
+
if (conversions.hasOwnProperty(groupName)) {
|
144
|
+
targetUnit = conversions[groupName];
|
145
|
+
group = tree.UnitConversions[groupName];
|
146
|
+
|
147
|
+
unit.map(applyUnit);
|
148
|
+
}
|
142
149
|
}
|
143
|
-
}
|
144
150
|
|
145
|
-
|
151
|
+
unit.cancel();
|
146
152
|
|
147
|
-
|
153
|
+
return new(tree.Dimension)(value, unit);
|
148
154
|
}
|
149
155
|
};
|
150
156
|
|
151
157
|
// http://www.w3.org/TR/css3-values/#absolute-lengths
|
152
158
|
tree.UnitConversions = {
|
153
|
-
|
154
|
-
|
155
|
-
|
156
|
-
|
157
|
-
|
158
|
-
|
159
|
-
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
159
|
+
length: {
|
160
|
+
'm': 1,
|
161
|
+
'cm': 0.01,
|
162
|
+
'mm': 0.001,
|
163
|
+
'in': 0.0254,
|
164
|
+
'pt': 0.0254 / 72,
|
165
|
+
'pc': 0.0254 / 72 * 12
|
166
|
+
},
|
167
|
+
duration: {
|
168
|
+
's': 1,
|
169
|
+
'ms': 0.001
|
170
|
+
},
|
171
|
+
angle: {
|
172
|
+
'rad': 1/(2*Math.PI),
|
173
|
+
'deg': 1/360,
|
174
|
+
'grad': 1/400,
|
175
|
+
'turn': 1
|
176
|
+
}
|
171
177
|
};
|
172
178
|
|
173
179
|
tree.Unit = function (numerator, denominator, backupUnit) {
|
174
|
-
|
175
|
-
|
176
|
-
|
180
|
+
this.numerator = numerator ? numerator.slice(0).sort() : [];
|
181
|
+
this.denominator = denominator ? denominator.slice(0).sort() : [];
|
182
|
+
this.backupUnit = backupUnit;
|
177
183
|
};
|
178
184
|
|
179
185
|
tree.Unit.prototype = {
|
180
|
-
|
181
|
-
|
182
|
-
|
183
|
-
|
184
|
-
|
185
|
-
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
}
|
195
|
-
|
196
|
-
},
|
186
|
+
type: "Unit",
|
187
|
+
clone: function () {
|
188
|
+
return new tree.Unit(this.numerator.slice(0), this.denominator.slice(0), this.backupUnit);
|
189
|
+
},
|
190
|
+
genCSS: function (env, output) {
|
191
|
+
if (this.numerator.length >= 1) {
|
192
|
+
output.add(this.numerator[0]);
|
193
|
+
} else
|
194
|
+
if (this.denominator.length >= 1) {
|
195
|
+
output.add(this.denominator[0]);
|
196
|
+
} else
|
197
|
+
if ((!env || !env.strictUnits) && this.backupUnit) {
|
198
|
+
output.add(this.backupUnit);
|
199
|
+
}
|
200
|
+
},
|
201
|
+
toCSS: tree.toCSS,
|
197
202
|
|
198
|
-
|
203
|
+
toString: function () {
|
199
204
|
var i, returnStr = this.numerator.join("*");
|
200
205
|
for (i = 0; i < this.denominator.length; i++) {
|
201
206
|
returnStr += "/" + this.denominator[i];
|
202
207
|
}
|
203
208
|
return returnStr;
|
204
|
-
|
205
|
-
|
206
|
-
compare: function (other) {
|
207
|
-
return this.is(other.toString()) ? 0 : -1;
|
208
|
-
},
|
209
|
+
},
|
209
210
|
|
210
|
-
|
211
|
-
|
212
|
-
|
211
|
+
compare: function (other) {
|
212
|
+
return this.is(other.toString()) ? 0 : -1;
|
213
|
+
},
|
213
214
|
|
214
|
-
|
215
|
-
|
216
|
-
|
215
|
+
is: function (unitString) {
|
216
|
+
return this.toString() === unitString;
|
217
|
+
},
|
217
218
|
|
218
|
-
|
219
|
-
|
220
|
-
|
219
|
+
isLength: function () {
|
220
|
+
return Boolean(this.toCSS().match(/px|em|%|in|cm|mm|pc|pt|ex/));
|
221
|
+
},
|
221
222
|
|
222
|
-
|
223
|
-
|
224
|
-
|
223
|
+
isEmpty: function () {
|
224
|
+
return this.numerator.length === 0 && this.denominator.length === 0;
|
225
|
+
},
|
225
226
|
|
226
|
-
|
227
|
-
|
227
|
+
isSingular: function() {
|
228
|
+
return this.numerator.length <= 1 && this.denominator.length === 0;
|
229
|
+
},
|
228
230
|
|
229
|
-
|
230
|
-
|
231
|
-
}
|
231
|
+
map: function(callback) {
|
232
|
+
var i;
|
232
233
|
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
},
|
234
|
+
for (i = 0; i < this.numerator.length; i++) {
|
235
|
+
this.numerator[i] = callback(this.numerator[i], false);
|
236
|
+
}
|
237
237
|
|
238
|
-
|
239
|
-
|
238
|
+
for (i = 0; i < this.denominator.length; i++) {
|
239
|
+
this.denominator[i] = callback(this.denominator[i], true);
|
240
|
+
}
|
241
|
+
},
|
240
242
|
|
241
|
-
|
242
|
-
|
243
|
-
group = tree.UnitConversions[groupName];
|
243
|
+
usedUnits: function() {
|
244
|
+
var group, result = {}, mapUnit;
|
244
245
|
|
245
|
-
|
246
|
-
|
247
|
-
result[groupName]
|
248
|
-
|
246
|
+
mapUnit = function (atomicUnit) {
|
247
|
+
/*jshint loopfunc:true */
|
248
|
+
if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
|
249
|
+
result[groupName] = atomicUnit;
|
250
|
+
}
|
249
251
|
|
250
|
-
|
251
|
-
}
|
252
|
-
|
253
|
-
|
252
|
+
return atomicUnit;
|
253
|
+
};
|
254
|
+
|
255
|
+
for (var groupName in tree.UnitConversions) {
|
256
|
+
if (tree.UnitConversions.hasOwnProperty(groupName)) {
|
257
|
+
group = tree.UnitConversions[groupName];
|
258
|
+
|
259
|
+
this.map(mapUnit);
|
260
|
+
}
|
261
|
+
}
|
254
262
|
|
255
|
-
|
256
|
-
|
263
|
+
return result;
|
264
|
+
},
|
257
265
|
|
258
|
-
|
259
|
-
|
266
|
+
cancel: function () {
|
267
|
+
var counter = {}, atomicUnit, i, backup;
|
260
268
|
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
269
|
+
for (i = 0; i < this.numerator.length; i++) {
|
270
|
+
atomicUnit = this.numerator[i];
|
271
|
+
if (!backup) {
|
272
|
+
backup = atomicUnit;
|
273
|
+
}
|
274
|
+
counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
|
265
275
|
}
|
266
|
-
counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
|
267
|
-
}
|
268
276
|
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
277
|
+
for (i = 0; i < this.denominator.length; i++) {
|
278
|
+
atomicUnit = this.denominator[i];
|
279
|
+
if (!backup) {
|
280
|
+
backup = atomicUnit;
|
281
|
+
}
|
282
|
+
counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
|
273
283
|
}
|
274
|
-
counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
|
275
|
-
}
|
276
284
|
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
285
|
+
this.numerator = [];
|
286
|
+
this.denominator = [];
|
287
|
+
|
288
|
+
for (atomicUnit in counter) {
|
289
|
+
if (counter.hasOwnProperty(atomicUnit)) {
|
290
|
+
var count = counter[atomicUnit];
|
291
|
+
|
292
|
+
if (count > 0) {
|
293
|
+
for (i = 0; i < count; i++) {
|
294
|
+
this.numerator.push(atomicUnit);
|
295
|
+
}
|
296
|
+
} else if (count < 0) {
|
297
|
+
for (i = 0; i < -count; i++) {
|
298
|
+
this.denominator.push(atomicUnit);
|
299
|
+
}
|
300
|
+
}
|
301
|
+
}
|
292
302
|
}
|
293
|
-
}
|
294
|
-
}
|
295
303
|
|
296
|
-
|
297
|
-
|
298
|
-
|
304
|
+
if (this.numerator.length === 0 && this.denominator.length === 0 && backup) {
|
305
|
+
this.backupUnit = backup;
|
306
|
+
}
|
299
307
|
|
300
|
-
|
301
|
-
|
302
|
-
|
308
|
+
this.numerator.sort();
|
309
|
+
this.denominator.sort();
|
310
|
+
}
|
303
311
|
};
|
304
312
|
|
305
313
|
})(require('../tree'));
|