less 2.4.0 → 2.5.0

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