less 4.5.1 → 4.6.1

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.
Files changed (340) hide show
  1. package/README.md +70 -5
  2. package/bin/lessc +37 -23
  3. package/dist/less.js +14501 -11745
  4. package/dist/less.min.js +4 -4
  5. package/dist/less.min.js.map +1 -1
  6. package/index.cjs +41 -0
  7. package/lib/less/constants.js +5 -7
  8. package/lib/less/contexts.js +71 -55
  9. package/lib/less/data/colors.js +150 -153
  10. package/lib/less/data/index.js +4 -7
  11. package/lib/less/data/unit-conversions.js +2 -5
  12. package/lib/less/default-options.js +36 -26
  13. package/lib/less/deprecation.js +67 -0
  14. package/lib/less/environment/abstract-file-manager.js +62 -50
  15. package/lib/less/environment/abstract-plugin-loader.js +69 -46
  16. package/lib/less/environment/environment-api.ts +21 -0
  17. package/lib/less/environment/environment.js +34 -30
  18. package/lib/less/environment/file-manager-api.ts +77 -0
  19. package/lib/less/functions/boolean.js +13 -13
  20. package/lib/less/functions/color-blending.js +39 -31
  21. package/lib/less/functions/color.js +153 -137
  22. package/lib/less/functions/data-uri.js +73 -64
  23. package/lib/less/functions/default.js +9 -11
  24. package/lib/less/functions/function-caller.js +35 -34
  25. package/lib/less/functions/function-registry.js +16 -17
  26. package/lib/less/functions/index.js +33 -33
  27. package/lib/less/functions/list.js +88 -75
  28. package/lib/less/functions/math-helper.js +8 -11
  29. package/lib/less/functions/math.js +21 -21
  30. package/lib/less/functions/number.js +42 -53
  31. package/lib/less/functions/string.js +18 -22
  32. package/lib/less/functions/style.js +21 -20
  33. package/lib/less/functions/svg.js +83 -82
  34. package/lib/less/functions/types.js +28 -32
  35. package/lib/less/import-manager.js +73 -64
  36. package/lib/less/index.js +65 -65
  37. package/lib/less/less-error.js +63 -45
  38. package/lib/less/logger.js +11 -14
  39. package/lib/less/parse-tree.js +52 -53
  40. package/lib/less/parse.js +44 -44
  41. package/lib/less/parser/parser-input.js +151 -113
  42. package/lib/less/parser/parser.js +864 -658
  43. package/lib/less/plugin-manager.js +57 -46
  44. package/lib/less/render.js +17 -23
  45. package/lib/less/source-map-builder.js +52 -43
  46. package/lib/less/source-map-output.js +56 -43
  47. package/lib/less/transform-tree.js +40 -30
  48. package/lib/less/tree/anonymous.js +52 -28
  49. package/lib/less/tree/assignment.js +44 -27
  50. package/lib/less/tree/atrule-syntax.js +4 -6
  51. package/lib/less/tree/atrule.js +247 -140
  52. package/lib/less/tree/attribute.js +55 -24
  53. package/lib/less/tree/call.js +70 -42
  54. package/lib/less/tree/color.js +194 -145
  55. package/lib/less/tree/combinator.js +31 -21
  56. package/lib/less/tree/comment.js +44 -23
  57. package/lib/less/tree/condition.js +61 -36
  58. package/lib/less/tree/container.js +90 -34
  59. package/lib/less/tree/debug-info.js +28 -15
  60. package/lib/less/tree/declaration.js +97 -52
  61. package/lib/less/tree/detached-ruleset.js +42 -24
  62. package/lib/less/tree/dimension.js +127 -71
  63. package/lib/less/tree/element.js +82 -52
  64. package/lib/less/tree/expression.js +75 -50
  65. package/lib/less/tree/extend.js +71 -42
  66. package/lib/less/tree/import.js +184 -110
  67. package/lib/less/tree/index.js +52 -81
  68. package/lib/less/tree/javascript.js +43 -32
  69. package/lib/less/tree/js-eval-node.js +46 -32
  70. package/lib/less/tree/keyword.js +25 -17
  71. package/lib/less/tree/media.js +77 -35
  72. package/lib/less/tree/merge-rules.js +47 -0
  73. package/lib/less/tree/mixin-call.js +181 -98
  74. package/lib/less/tree/mixin-definition.js +211 -117
  75. package/lib/less/tree/namespace-value.js +63 -44
  76. package/lib/less/tree/negative.js +34 -21
  77. package/lib/less/tree/nested-at-rule.js +149 -66
  78. package/lib/less/tree/node.js +225 -90
  79. package/lib/less/tree/operation.js +59 -34
  80. package/lib/less/tree/paren.js +34 -17
  81. package/lib/less/tree/property.js +66 -35
  82. package/lib/less/tree/query-in-parens.js +52 -60
  83. package/lib/less/tree/quoted.js +93 -44
  84. package/lib/less/tree/ruleset.js +632 -318
  85. package/lib/less/tree/selector.js +151 -77
  86. package/lib/less/tree/unicode-descriptor.js +14 -12
  87. package/lib/less/tree/unit.js +111 -63
  88. package/lib/less/tree/url.js +62 -38
  89. package/lib/less/tree/value.js +50 -34
  90. package/lib/less/tree/variable-call.js +47 -30
  91. package/lib/less/tree/variable.js +53 -31
  92. package/lib/less/utils.js +44 -47
  93. package/lib/less/visitors/extend-visitor.js +233 -172
  94. package/lib/less/visitors/import-sequencer.js +24 -24
  95. package/lib/less/visitors/import-visitor.js +62 -52
  96. package/lib/less/visitors/index.js +14 -17
  97. package/lib/less/visitors/join-selector-visitor.js +40 -37
  98. package/lib/less/visitors/set-tree-visibility-visitor.js +32 -18
  99. package/lib/less/visitors/to-css-visitor.js +135 -128
  100. package/lib/less/visitors/visitor.js +60 -45
  101. package/lib/less-browser/add-default-options.js +23 -13
  102. package/lib/less-browser/bootstrap.js +23 -17
  103. package/lib/less-browser/browser.js +24 -21
  104. package/lib/less-browser/cache.js +17 -19
  105. package/lib/less-browser/error-reporting.js +52 -44
  106. package/lib/less-browser/file-manager.js +52 -42
  107. package/lib/less-browser/image-size.js +12 -12
  108. package/lib/less-browser/index.js +131 -105
  109. package/lib/less-browser/log-listener.js +30 -31
  110. package/lib/less-browser/plugin-loader.js +10 -10
  111. package/lib/less-browser/utils.js +19 -21
  112. package/lib/less-node/environment.js +32 -8
  113. package/lib/less-node/file-manager.js +62 -45
  114. package/lib/less-node/fs.js +11 -8
  115. package/lib/less-node/image-size.js +40 -31
  116. package/lib/less-node/index.js +28 -19
  117. package/lib/less-node/lessc-helper.js +20 -21
  118. package/lib/less-node/plugin-loader.js +35 -27
  119. package/lib/less-node/url-file-manager.js +33 -31
  120. package/package.json +29 -18
  121. package/.eslintignore +0 -6
  122. package/.eslintrc.js +0 -63
  123. package/Gruntfile.js +0 -403
  124. package/bower.json +0 -22
  125. package/lib/less/constants.js.map +0 -1
  126. package/lib/less/contexts.js.map +0 -1
  127. package/lib/less/data/colors.js.map +0 -1
  128. package/lib/less/data/index.js.map +0 -1
  129. package/lib/less/data/unit-conversions.js.map +0 -1
  130. package/lib/less/default-options.js.map +0 -1
  131. package/lib/less/environment/abstract-file-manager.js.map +0 -1
  132. package/lib/less/environment/abstract-plugin-loader.js.map +0 -1
  133. package/lib/less/environment/environment-api.js +0 -3
  134. package/lib/less/environment/environment-api.js.map +0 -1
  135. package/lib/less/environment/environment.js.map +0 -1
  136. package/lib/less/environment/file-manager-api.js +0 -3
  137. package/lib/less/environment/file-manager-api.js.map +0 -1
  138. package/lib/less/functions/boolean.js.map +0 -1
  139. package/lib/less/functions/color-blending.js.map +0 -1
  140. package/lib/less/functions/color.js.map +0 -1
  141. package/lib/less/functions/data-uri.js.map +0 -1
  142. package/lib/less/functions/default.js.map +0 -1
  143. package/lib/less/functions/function-caller.js.map +0 -1
  144. package/lib/less/functions/function-registry.js.map +0 -1
  145. package/lib/less/functions/index.js.map +0 -1
  146. package/lib/less/functions/list.js.map +0 -1
  147. package/lib/less/functions/math-helper.js.map +0 -1
  148. package/lib/less/functions/math.js.map +0 -1
  149. package/lib/less/functions/number.js.map +0 -1
  150. package/lib/less/functions/string.js.map +0 -1
  151. package/lib/less/functions/style.js.map +0 -1
  152. package/lib/less/functions/svg.js.map +0 -1
  153. package/lib/less/functions/types.js.map +0 -1
  154. package/lib/less/import-manager.js.map +0 -1
  155. package/lib/less/index.js.map +0 -1
  156. package/lib/less/less-error.js.map +0 -1
  157. package/lib/less/logger.js.map +0 -1
  158. package/lib/less/parse-tree.js.map +0 -1
  159. package/lib/less/parse.js.map +0 -1
  160. package/lib/less/parser/parser-input.js.map +0 -1
  161. package/lib/less/parser/parser.js.map +0 -1
  162. package/lib/less/plugin-manager.js.map +0 -1
  163. package/lib/less/render.js.map +0 -1
  164. package/lib/less/source-map-builder.js.map +0 -1
  165. package/lib/less/source-map-output.js.map +0 -1
  166. package/lib/less/transform-tree.js.map +0 -1
  167. package/lib/less/tree/anonymous.js.map +0 -1
  168. package/lib/less/tree/assignment.js.map +0 -1
  169. package/lib/less/tree/atrule-syntax.js.map +0 -1
  170. package/lib/less/tree/atrule.js.map +0 -1
  171. package/lib/less/tree/attribute.js.map +0 -1
  172. package/lib/less/tree/call.js.map +0 -1
  173. package/lib/less/tree/color.js.map +0 -1
  174. package/lib/less/tree/combinator.js.map +0 -1
  175. package/lib/less/tree/comment.js.map +0 -1
  176. package/lib/less/tree/condition.js.map +0 -1
  177. package/lib/less/tree/container.js.map +0 -1
  178. package/lib/less/tree/debug-info.js.map +0 -1
  179. package/lib/less/tree/declaration.js.map +0 -1
  180. package/lib/less/tree/detached-ruleset.js.map +0 -1
  181. package/lib/less/tree/dimension.js.map +0 -1
  182. package/lib/less/tree/element.js.map +0 -1
  183. package/lib/less/tree/expression.js.map +0 -1
  184. package/lib/less/tree/extend.js.map +0 -1
  185. package/lib/less/tree/import.js.map +0 -1
  186. package/lib/less/tree/index.js.map +0 -1
  187. package/lib/less/tree/javascript.js.map +0 -1
  188. package/lib/less/tree/js-eval-node.js.map +0 -1
  189. package/lib/less/tree/keyword.js.map +0 -1
  190. package/lib/less/tree/media.js.map +0 -1
  191. package/lib/less/tree/mixin-call.js.map +0 -1
  192. package/lib/less/tree/mixin-definition.js.map +0 -1
  193. package/lib/less/tree/namespace-value.js.map +0 -1
  194. package/lib/less/tree/negative.js.map +0 -1
  195. package/lib/less/tree/nested-at-rule.js.map +0 -1
  196. package/lib/less/tree/node.js.map +0 -1
  197. package/lib/less/tree/operation.js.map +0 -1
  198. package/lib/less/tree/paren.js.map +0 -1
  199. package/lib/less/tree/property.js.map +0 -1
  200. package/lib/less/tree/query-in-parens.js.map +0 -1
  201. package/lib/less/tree/quoted.js.map +0 -1
  202. package/lib/less/tree/ruleset.js.map +0 -1
  203. package/lib/less/tree/selector.js.map +0 -1
  204. package/lib/less/tree/unicode-descriptor.js.map +0 -1
  205. package/lib/less/tree/unit.js.map +0 -1
  206. package/lib/less/tree/url.js.map +0 -1
  207. package/lib/less/tree/value.js.map +0 -1
  208. package/lib/less/tree/variable-call.js.map +0 -1
  209. package/lib/less/tree/variable.js.map +0 -1
  210. package/lib/less/utils.js.map +0 -1
  211. package/lib/less/visitors/extend-visitor.js.map +0 -1
  212. package/lib/less/visitors/import-sequencer.js.map +0 -1
  213. package/lib/less/visitors/import-visitor.js.map +0 -1
  214. package/lib/less/visitors/index.js.map +0 -1
  215. package/lib/less/visitors/join-selector-visitor.js.map +0 -1
  216. package/lib/less/visitors/set-tree-visibility-visitor.js.map +0 -1
  217. package/lib/less/visitors/to-css-visitor.js.map +0 -1
  218. package/lib/less/visitors/visitor.js.map +0 -1
  219. package/lib/less-browser/add-default-options.js.map +0 -1
  220. package/lib/less-browser/bootstrap.js.map +0 -1
  221. package/lib/less-browser/browser.js.map +0 -1
  222. package/lib/less-browser/cache.js.map +0 -1
  223. package/lib/less-browser/error-reporting.js.map +0 -1
  224. package/lib/less-browser/file-manager.js.map +0 -1
  225. package/lib/less-browser/image-size.js.map +0 -1
  226. package/lib/less-browser/index.js.map +0 -1
  227. package/lib/less-browser/log-listener.js.map +0 -1
  228. package/lib/less-browser/plugin-loader.js.map +0 -1
  229. package/lib/less-browser/utils.js.map +0 -1
  230. package/lib/less-node/environment.js.map +0 -1
  231. package/lib/less-node/file-manager.js.map +0 -1
  232. package/lib/less-node/fs.js.map +0 -1
  233. package/lib/less-node/image-size.js.map +0 -1
  234. package/lib/less-node/index.js.map +0 -1
  235. package/lib/less-node/lessc-helper.js.map +0 -1
  236. package/lib/less-node/plugin-loader.js.map +0 -1
  237. package/lib/less-node/url-file-manager.js.map +0 -1
  238. package/scripts/coverage-lines.js +0 -207
  239. package/scripts/coverage-report.js +0 -158
  240. package/scripts/postinstall.js +0 -61
  241. package/test/.eslintrc.json +0 -9
  242. package/test/README.md +0 -3
  243. package/test/browser/common.js +0 -251
  244. package/test/browser/css/global-vars/simple.css +0 -3
  245. package/test/browser/css/modify-vars/simple.css +0 -8
  246. package/test/browser/css/plugin/plugin.css +0 -3
  247. package/test/browser/css/postProcessor/postProcessor.css +0 -4
  248. package/test/browser/css/relative-urls/urls.css +0 -36
  249. package/test/browser/css/rewrite-urls/urls.css +0 -36
  250. package/test/browser/css/rootpath/urls.css +0 -35
  251. package/test/browser/css/rootpath-relative/urls.css +0 -35
  252. package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
  253. package/test/browser/css/urls.css +0 -54
  254. package/test/browser/generator/benchmark.config.js +0 -50
  255. package/test/browser/generator/generate.js +0 -78
  256. package/test/browser/generator/runner.config.js +0 -184
  257. package/test/browser/generator/runner.js +0 -2
  258. package/test/browser/generator/template.js +0 -104
  259. package/test/browser/generator/utils.js +0 -14
  260. package/test/browser/less/console-errors/test-error.less +0 -3
  261. package/test/browser/less/console-errors/test-error.txt +0 -2
  262. package/test/browser/less/errors/image-height-error.less +0 -3
  263. package/test/browser/less/errors/image-height-error.txt +0 -4
  264. package/test/browser/less/errors/image-size-error.less +0 -3
  265. package/test/browser/less/errors/image-size-error.txt +0 -4
  266. package/test/browser/less/errors/image-width-error.less +0 -3
  267. package/test/browser/less/errors/image-width-error.txt +0 -4
  268. package/test/browser/less/global-vars/simple.less +0 -3
  269. package/test/browser/less/imports/urls.less +0 -4
  270. package/test/browser/less/imports/urls2.less +0 -4
  271. package/test/browser/less/modify-vars/imports/simple2.less +0 -4
  272. package/test/browser/less/modify-vars/simple.less +0 -8
  273. package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
  274. package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
  275. package/test/browser/less/plugin/plugin.js +0 -4
  276. package/test/browser/less/plugin/plugin.less +0 -4
  277. package/test/browser/less/postProcessor/postProcessor.less +0 -4
  278. package/test/browser/less/relative-urls/urls.less +0 -34
  279. package/test/browser/less/rewrite-urls/urls.less +0 -34
  280. package/test/browser/less/rootpath/urls.less +0 -33
  281. package/test/browser/less/rootpath-relative/urls.less +0 -33
  282. package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
  283. package/test/browser/less/urls.less +0 -62
  284. package/test/browser/runner-VisitorPlugin-options.js +0 -3
  285. package/test/browser/runner-VisitorPlugin.js +0 -3
  286. package/test/browser/runner-browser-options.js +0 -51
  287. package/test/browser/runner-browser-spec.js +0 -12
  288. package/test/browser/runner-console-errors.js +0 -5
  289. package/test/browser/runner-errors-options.js +0 -6
  290. package/test/browser/runner-errors-spec.js +0 -3
  291. package/test/browser/runner-filemanagerPlugin-options.js +0 -5
  292. package/test/browser/runner-filemanagerPlugin.js +0 -3
  293. package/test/browser/runner-global-vars-options.js +0 -7
  294. package/test/browser/runner-global-vars-spec.js +0 -3
  295. package/test/browser/runner-main-options.js +0 -17
  296. package/test/browser/runner-main-spec.js +0 -7
  297. package/test/browser/runner-modify-vars-options.js +0 -5
  298. package/test/browser/runner-modify-vars-spec.js +0 -33
  299. package/test/browser/runner-no-js-errors-options.js +0 -4
  300. package/test/browser/runner-no-js-errors-spec.js +0 -3
  301. package/test/browser/runner-postProcessorPlugin-options.js +0 -3
  302. package/test/browser/runner-postProcessorPlugin.js +0 -3
  303. package/test/browser/runner-preProcessorPlugin-options.js +0 -3
  304. package/test/browser/runner-preProcessorPlugin.js +0 -3
  305. package/test/browser/runner-production-options.js +0 -3
  306. package/test/browser/runner-production-spec.js +0 -5
  307. package/test/browser/runner-relative-urls-options.js +0 -3
  308. package/test/browser/runner-relative-urls-spec.js +0 -3
  309. package/test/browser/runner-rewrite-urls-options.js +0 -3
  310. package/test/browser/runner-rewrite-urls-spec.js +0 -3
  311. package/test/browser/runner-rootpath-options.js +0 -3
  312. package/test/browser/runner-rootpath-relative-options.js +0 -4
  313. package/test/browser/runner-rootpath-relative-spec.js +0 -3
  314. package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
  315. package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
  316. package/test/browser/runner-rootpath-spec.js +0 -3
  317. package/test/browser/runner-strict-units-options.js +0 -5
  318. package/test/browser/runner-strict-units-spec.js +0 -3
  319. package/test/index.js +0 -307
  320. package/test/less-test.js +0 -984
  321. package/test/mocha-playwright/runner.js +0 -210
  322. package/test/modify-vars.js +0 -28
  323. package/test/plugins/filemanager/index.js +0 -19
  324. package/test/plugins/postprocess/index.js +0 -14
  325. package/test/plugins/preprocess/index.js +0 -19
  326. package/test/plugins/visitor/index.js +0 -24
  327. package/test/sourcemaps/basic.json +0 -1
  328. package/test/sourcemaps/comprehensive.json +0 -1
  329. package/test/sourcemaps/custom-props.json +0 -1
  330. package/test/sourcemaps/index.html +0 -17
  331. package/test/sourcemaps/sourcemaps-basepath.json +0 -1
  332. package/test/sourcemaps/sourcemaps-include-source.json +0 -1
  333. package/test/sourcemaps/sourcemaps-rootpath.json +0 -1
  334. package/test/sourcemaps/sourcemaps-url.json +0 -1
  335. package/test/sourcemaps-disable-annotation/basic.json +0 -1
  336. package/test/sourcemaps-variable-selector/basic.json +0 -1
  337. package/test/test-es6.ts +0 -17
  338. package/test.less +0 -1
  339. package/tsconfig.build.json +0 -7
  340. package/tsconfig.json +0 -21
@@ -1,24 +1,21 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var dimension_1 = tslib_1.__importDefault(require("../tree/dimension"));
5
- var color_1 = tslib_1.__importDefault(require("../tree/color"));
6
- var quoted_1 = tslib_1.__importDefault(require("../tree/quoted"));
7
- var anonymous_1 = tslib_1.__importDefault(require("../tree/anonymous"));
8
- var expression_1 = tslib_1.__importDefault(require("../tree/expression"));
9
- var operation_1 = tslib_1.__importDefault(require("../tree/operation"));
10
- var colorFunctions;
1
+ import Dimension from '../tree/dimension.js';
2
+ import Color from '../tree/color.js';
3
+ import Quoted from '../tree/quoted.js';
4
+ import Anonymous from '../tree/anonymous.js';
5
+ import Expression from '../tree/expression.js';
6
+ import Operation from '../tree/operation.js';
7
+ let colorFunctions;
8
+
11
9
  function clamp(val) {
12
10
  return Math.min(1, Math.max(0, val));
13
11
  }
14
12
  function hsla(origColor, hsl) {
15
- var color = colorFunctions.hsla(hsl.h, hsl.s, hsl.l, hsl.a);
13
+ const color = colorFunctions.hsla(hsl.h, hsl.s, hsl.l, hsl.a);
16
14
  if (color) {
17
- if (origColor.value &&
15
+ if (origColor.value &&
18
16
  /^(rgb|hsl)/.test(origColor.value)) {
19
17
  color.value = origColor.value;
20
- }
21
- else {
18
+ } else {
22
19
  color.value = 'rgb';
23
20
  }
24
21
  return color;
@@ -27,27 +24,25 @@ function hsla(origColor, hsl) {
27
24
  function toHSL(color) {
28
25
  if (color.toHSL) {
29
26
  return color.toHSL();
30
- }
31
- else {
27
+ } else {
32
28
  throw new Error('Argument cannot be evaluated to a color');
33
29
  }
34
30
  }
31
+
35
32
  function toHSV(color) {
36
33
  if (color.toHSV) {
37
34
  return color.toHSV();
38
- }
39
- else {
35
+ } else {
40
36
  throw new Error('Argument cannot be evaluated to a color');
41
37
  }
42
38
  }
39
+
43
40
  function number(n) {
44
- if (n instanceof dimension_1.default) {
41
+ if (n instanceof Dimension) {
45
42
  return parseFloat(n.unit.is('%') ? n.value / 100 : n.value);
46
- }
47
- else if (typeof n === 'number') {
43
+ } else if (typeof n === 'number') {
48
44
  return n;
49
- }
50
- else {
45
+ } else {
51
46
  throw {
52
47
  type: 'Argument',
53
48
  message: 'color functions take numbers as parameters'
@@ -55,36 +50,35 @@ function number(n) {
55
50
  }
56
51
  }
57
52
  function scaled(n, size) {
58
- if (n instanceof dimension_1.default && n.unit.is('%')) {
53
+ if (n instanceof Dimension && n.unit.is('%')) {
59
54
  return parseFloat(n.value * size / 100);
60
- }
61
- else {
55
+ } else {
62
56
  return number(n);
63
57
  }
64
58
  }
65
59
  colorFunctions = {
66
60
  rgb: function (r, g, b) {
67
- var a = 1;
61
+ let a = 1
68
62
  /**
69
63
  * Comma-less syntax
70
64
  * e.g. rgb(0 128 255 / 50%)
71
65
  */
72
- if (r instanceof expression_1.default) {
73
- var val = r.value;
74
- r = val[0];
75
- g = val[1];
76
- b = val[2];
77
- /**
66
+ if (r instanceof Expression) {
67
+ const val = r.value
68
+ r = val[0]
69
+ g = val[1]
70
+ b = val[2]
71
+ /**
78
72
  * @todo - should this be normalized in
79
73
  * function caller? Or parsed differently?
80
74
  */
81
- if (b instanceof operation_1.default) {
82
- var op = b;
83
- b = op.operands[0];
84
- a = op.operands[1];
75
+ if (b instanceof Operation) {
76
+ const op = b
77
+ b = op.operands[0]
78
+ a = op.operands[1]
85
79
  }
86
80
  }
87
- var color = colorFunctions.rgba(r, g, b, a);
81
+ const color = colorFunctions.rgba(r, g, b, a);
88
82
  if (color) {
89
83
  color.value = 'rgb';
90
84
  return color;
@@ -92,43 +86,44 @@ colorFunctions = {
92
86
  },
93
87
  rgba: function (r, g, b, a) {
94
88
  try {
95
- if (r instanceof color_1.default) {
89
+ if (r instanceof Color) {
96
90
  if (g) {
97
91
  a = number(g);
98
- }
99
- else {
92
+ } else {
100
93
  a = r.alpha;
101
94
  }
102
- return new color_1.default(r.rgb, a, 'rgba');
95
+ return new Color(r.rgb, a, 'rgba');
103
96
  }
104
- var rgb = [r, g, b].map(function (c) { return scaled(c, 255); });
97
+ const rgb = [r, g, b].map(c => scaled(c, 255));
105
98
  a = number(a);
106
- return new color_1.default(rgb, a, 'rgba');
99
+ return new Color(rgb, a, 'rgba');
107
100
  }
108
- catch (e) { }
101
+ catch (e) {}
109
102
  },
110
103
  hsl: function (h, s, l) {
111
- var a = 1;
112
- if (h instanceof expression_1.default) {
113
- var val = h.value;
114
- h = val[0];
115
- s = val[1];
116
- l = val[2];
117
- if (l instanceof operation_1.default) {
118
- var op = l;
119
- l = op.operands[0];
120
- a = op.operands[1];
104
+ let a = 1
105
+ if (h instanceof Expression) {
106
+ const val = h.value
107
+ h = val[0]
108
+ s = val[1]
109
+ l = val[2]
110
+
111
+ if (l instanceof Operation) {
112
+ const op = l
113
+ l = op.operands[0]
114
+ a = op.operands[1]
121
115
  }
122
116
  }
123
- var color = colorFunctions.hsla(h, s, l, a);
117
+ const color = colorFunctions.hsla(h, s, l, a);
124
118
  if (color) {
125
119
  color.value = 'hsl';
126
120
  return color;
127
121
  }
128
122
  },
129
123
  hsla: function (h, s, l, a) {
130
- var m1;
131
- var m2;
124
+ let m1;
125
+ let m2;
126
+
132
127
  function hue(h) {
133
128
  h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
134
129
  if (h * 6 < 1) {
@@ -144,94 +139,104 @@ colorFunctions = {
144
139
  return m1;
145
140
  }
146
141
  }
142
+
147
143
  try {
148
- if (h instanceof color_1.default) {
144
+ if (h instanceof Color) {
149
145
  if (s) {
150
146
  a = number(s);
151
- }
152
- else {
147
+ } else {
153
148
  a = h.alpha;
154
149
  }
155
- return new color_1.default(h.rgb, a, 'hsla');
150
+ return new Color(h.rgb, a, 'hsla');
156
151
  }
152
+
157
153
  h = (number(h) % 360) / 360;
158
- s = clamp(number(s));
159
- l = clamp(number(l));
160
- a = clamp(number(a));
154
+ s = clamp(number(s));l = clamp(number(l));a = clamp(number(a));
155
+
161
156
  m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
162
157
  m1 = l * 2 - m2;
163
- var rgb = [
158
+
159
+ const rgb = [
164
160
  hue(h + 1 / 3) * 255,
165
- hue(h) * 255,
161
+ hue(h) * 255,
166
162
  hue(h - 1 / 3) * 255
167
163
  ];
168
164
  a = number(a);
169
- return new color_1.default(rgb, a, 'hsla');
165
+ return new Color(rgb, a, 'hsla');
170
166
  }
171
- catch (e) { }
167
+ catch (e) {}
172
168
  },
173
- hsv: function (h, s, v) {
169
+
170
+ hsv: function(h, s, v) {
174
171
  return colorFunctions.hsva(h, s, v, 1.0);
175
172
  },
176
- hsva: function (h, s, v, a) {
173
+
174
+ hsva: function(h, s, v, a) {
177
175
  h = ((number(h) % 360) / 360) * 360;
178
- s = number(s);
179
- v = number(v);
180
- a = number(a);
181
- var i;
182
- var f;
176
+ s = number(s);v = number(v);a = number(a);
177
+
178
+ let i;
179
+ let f;
183
180
  i = Math.floor((h / 60) % 6);
184
181
  f = (h / 60) - i;
185
- var vs = [v,
182
+
183
+ const vs = [v,
186
184
  v * (1 - s),
187
185
  v * (1 - f * s),
188
186
  v * (1 - (1 - f) * s)];
189
- var perm = [[0, 3, 1],
187
+ const perm = [[0, 3, 1],
190
188
  [2, 0, 1],
191
189
  [1, 0, 3],
192
190
  [1, 2, 0],
193
191
  [3, 1, 0],
194
192
  [0, 1, 2]];
195
- return colorFunctions.rgba(vs[perm[i][0]] * 255, vs[perm[i][1]] * 255, vs[perm[i][2]] * 255, a);
193
+
194
+ return colorFunctions.rgba(vs[perm[i][0]] * 255,
195
+ vs[perm[i][1]] * 255,
196
+ vs[perm[i][2]] * 255,
197
+ a);
196
198
  },
199
+
197
200
  hue: function (color) {
198
- return new dimension_1.default(toHSL(color).h);
201
+ return new Dimension(toHSL(color).h);
199
202
  },
200
203
  saturation: function (color) {
201
- return new dimension_1.default(toHSL(color).s * 100, '%');
204
+ return new Dimension(toHSL(color).s * 100, '%');
202
205
  },
203
206
  lightness: function (color) {
204
- return new dimension_1.default(toHSL(color).l * 100, '%');
207
+ return new Dimension(toHSL(color).l * 100, '%');
205
208
  },
206
- hsvhue: function (color) {
207
- return new dimension_1.default(toHSV(color).h);
209
+ hsvhue: function(color) {
210
+ return new Dimension(toHSV(color).h);
208
211
  },
209
212
  hsvsaturation: function (color) {
210
- return new dimension_1.default(toHSV(color).s * 100, '%');
213
+ return new Dimension(toHSV(color).s * 100, '%');
211
214
  },
212
215
  hsvvalue: function (color) {
213
- return new dimension_1.default(toHSV(color).v * 100, '%');
216
+ return new Dimension(toHSV(color).v * 100, '%');
214
217
  },
215
218
  red: function (color) {
216
- return new dimension_1.default(color.rgb[0]);
219
+ return new Dimension(color.rgb[0]);
217
220
  },
218
221
  green: function (color) {
219
- return new dimension_1.default(color.rgb[1]);
222
+ return new Dimension(color.rgb[1]);
220
223
  },
221
224
  blue: function (color) {
222
- return new dimension_1.default(color.rgb[2]);
225
+ return new Dimension(color.rgb[2]);
223
226
  },
224
227
  alpha: function (color) {
225
- return new dimension_1.default(toHSL(color).a);
228
+ return new Dimension(toHSL(color).a);
226
229
  },
227
230
  luma: function (color) {
228
- return new dimension_1.default(color.luma() * color.alpha * 100, '%');
231
+ return new Dimension(color.luma() * color.alpha * 100, '%');
229
232
  },
230
233
  luminance: function (color) {
231
- var luminance = (0.2126 * color.rgb[0] / 255) +
232
- (0.7152 * color.rgb[1] / 255) +
233
- (0.0722 * color.rgb[2] / 255);
234
- return new dimension_1.default(luminance * color.alpha * 100, '%');
234
+ const luminance =
235
+ (0.2126 * color.rgb[0] / 255) +
236
+ (0.7152 * color.rgb[1] / 255) +
237
+ (0.0722 * color.rgb[2] / 255);
238
+
239
+ return new Dimension(luminance * color.alpha * 100, '%');
235
240
  },
236
241
  saturate: function (color, amount, method) {
237
242
  // filter: saturate(3.2);
@@ -239,9 +244,10 @@ colorFunctions = {
239
244
  if (!color.rgb) {
240
245
  return null;
241
246
  }
242
- var hsl = toHSL(color);
247
+ const hsl = toHSL(color);
248
+
243
249
  if (typeof method !== 'undefined' && method.value === 'relative') {
244
- hsl.s += hsl.s * amount.value / 100;
250
+ hsl.s += hsl.s * amount.value / 100;
245
251
  }
246
252
  else {
247
253
  hsl.s += amount.value / 100;
@@ -250,9 +256,10 @@ colorFunctions = {
250
256
  return hsla(color, hsl);
251
257
  },
252
258
  desaturate: function (color, amount, method) {
253
- var hsl = toHSL(color);
259
+ const hsl = toHSL(color);
260
+
254
261
  if (typeof method !== 'undefined' && method.value === 'relative') {
255
- hsl.s -= hsl.s * amount.value / 100;
262
+ hsl.s -= hsl.s * amount.value / 100;
256
263
  }
257
264
  else {
258
265
  hsl.s -= amount.value / 100;
@@ -261,9 +268,10 @@ colorFunctions = {
261
268
  return hsla(color, hsl);
262
269
  },
263
270
  lighten: function (color, amount, method) {
264
- var hsl = toHSL(color);
271
+ const hsl = toHSL(color);
272
+
265
273
  if (typeof method !== 'undefined' && method.value === 'relative') {
266
- hsl.l += hsl.l * amount.value / 100;
274
+ hsl.l += hsl.l * amount.value / 100;
267
275
  }
268
276
  else {
269
277
  hsl.l += amount.value / 100;
@@ -272,9 +280,10 @@ colorFunctions = {
272
280
  return hsla(color, hsl);
273
281
  },
274
282
  darken: function (color, amount, method) {
275
- var hsl = toHSL(color);
283
+ const hsl = toHSL(color);
284
+
276
285
  if (typeof method !== 'undefined' && method.value === 'relative') {
277
- hsl.l -= hsl.l * amount.value / 100;
286
+ hsl.l -= hsl.l * amount.value / 100;
278
287
  }
279
288
  else {
280
289
  hsl.l -= amount.value / 100;
@@ -283,9 +292,10 @@ colorFunctions = {
283
292
  return hsla(color, hsl);
284
293
  },
285
294
  fadein: function (color, amount, method) {
286
- var hsl = toHSL(color);
295
+ const hsl = toHSL(color);
296
+
287
297
  if (typeof method !== 'undefined' && method.value === 'relative') {
288
- hsl.a += hsl.a * amount.value / 100;
298
+ hsl.a += hsl.a * amount.value / 100;
289
299
  }
290
300
  else {
291
301
  hsl.a += amount.value / 100;
@@ -294,9 +304,10 @@ colorFunctions = {
294
304
  return hsla(color, hsl);
295
305
  },
296
306
  fadeout: function (color, amount, method) {
297
- var hsl = toHSL(color);
307
+ const hsl = toHSL(color);
308
+
298
309
  if (typeof method !== 'undefined' && method.value === 'relative') {
299
- hsl.a -= hsl.a * amount.value / 100;
310
+ hsl.a -= hsl.a * amount.value / 100;
300
311
  }
301
312
  else {
302
313
  hsl.a -= amount.value / 100;
@@ -305,15 +316,18 @@ colorFunctions = {
305
316
  return hsla(color, hsl);
306
317
  },
307
318
  fade: function (color, amount) {
308
- var hsl = toHSL(color);
319
+ const hsl = toHSL(color);
320
+
309
321
  hsl.a = amount.value / 100;
310
322
  hsl.a = clamp(hsl.a);
311
323
  return hsla(color, hsl);
312
324
  },
313
325
  spin: function (color, amount) {
314
- var hsl = toHSL(color);
315
- var hue = (hsl.h + amount.value) % 360;
326
+ const hsl = toHSL(color);
327
+ const hue = (hsl.h + amount.value) % 360;
328
+
316
329
  hsl.h = hue < 0 ? 360 + hue : hue;
330
+
317
331
  return hsla(color, hsl);
318
332
  },
319
333
  //
@@ -322,21 +336,25 @@ colorFunctions = {
322
336
  //
323
337
  mix: function (color1, color2, weight) {
324
338
  if (!weight) {
325
- weight = new dimension_1.default(50);
326
- }
327
- var p = weight.value / 100.0;
328
- var w = p * 2 - 1;
329
- var a = toHSL(color1).a - toHSL(color2).a;
330
- var w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
331
- var w2 = 1 - w1;
332
- var rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
339
+ weight = new Dimension(50);
340
+ }
341
+ const p = weight.value / 100.0;
342
+ const w = p * 2 - 1;
343
+ const a = toHSL(color1).a - toHSL(color2).a;
344
+
345
+ const w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
346
+ const w2 = 1 - w1;
347
+
348
+ const rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
333
349
  color1.rgb[1] * w1 + color2.rgb[1] * w2,
334
350
  color1.rgb[2] * w1 + color2.rgb[2] * w2];
335
- var alpha = color1.alpha * p + color2.alpha * (1 - p);
336
- return new color_1.default(rgb, alpha);
351
+
352
+ const alpha = color1.alpha * p + color2.alpha * (1 - p);
353
+
354
+ return new Color(rgb, alpha);
337
355
  },
338
356
  greyscale: function (color) {
339
- return colorFunctions.desaturate(color, new dimension_1.default(100));
357
+ return colorFunctions.desaturate(color, new Dimension(100));
340
358
  },
341
359
  contrast: function (color, dark, light, threshold) {
342
360
  // filter: contrast(3.2);
@@ -352,20 +370,18 @@ colorFunctions = {
352
370
  }
353
371
  // Figure out which is actually light and dark:
354
372
  if (dark.luma() > light.luma()) {
355
- var t = light;
373
+ const t = light;
356
374
  light = dark;
357
375
  dark = t;
358
376
  }
359
377
  if (typeof threshold === 'undefined') {
360
378
  threshold = 0.43;
361
- }
362
- else {
379
+ } else {
363
380
  threshold = number(threshold);
364
381
  }
365
382
  if (color.luma() < threshold) {
366
383
  return light;
367
- }
368
- else {
384
+ } else {
369
385
  return dark;
370
386
  }
371
387
  },
@@ -408,29 +424,29 @@ colorFunctions = {
408
424
  // }
409
425
  // },
410
426
  argb: function (color) {
411
- return new anonymous_1.default(color.toARGB());
427
+ return new Anonymous(color.toARGB());
412
428
  },
413
- color: function (c) {
414
- if ((c instanceof quoted_1.default) &&
429
+ color: function(c) {
430
+ if ((c instanceof Quoted) &&
415
431
  (/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})$/i.test(c.value))) {
416
- var val = c.value.slice(1);
417
- return new color_1.default(val, undefined, "#".concat(val));
432
+ const val = c.value.slice(1);
433
+ return new Color(val, undefined, `#${val}`);
418
434
  }
419
- if ((c instanceof color_1.default) || (c = color_1.default.fromKeyword(c.value))) {
435
+ if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) {
420
436
  c.value = undefined;
421
437
  return c;
422
438
  }
423
439
  throw {
424
- type: 'Argument',
440
+ type: 'Argument',
425
441
  message: 'argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF'
426
442
  };
427
443
  },
428
- tint: function (color, amount) {
444
+ tint: function(color, amount) {
429
445
  return colorFunctions.mix(colorFunctions.rgb(255, 255, 255), color, amount);
430
446
  },
431
- shade: function (color, amount) {
447
+ shade: function(color, amount) {
432
448
  return colorFunctions.mix(colorFunctions.rgb(0, 0, 0), color, amount);
433
449
  }
434
450
  };
435
- exports.default = colorFunctions;
436
- //# sourceMappingURL=color.js.map
451
+
452
+ export default colorFunctions;
@@ -1,65 +1,74 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var quoted_1 = tslib_1.__importDefault(require("../tree/quoted"));
5
- var url_1 = tslib_1.__importDefault(require("../tree/url"));
6
- var utils = tslib_1.__importStar(require("../utils"));
7
- var logger_1 = tslib_1.__importDefault(require("../logger"));
8
- exports.default = (function (environment) {
9
- var fallback = function (functionThis, node) { return new url_1.default(node, functionThis.index, functionThis.currentFileInfo).eval(functionThis.context); };
10
- return { 'data-uri': function (mimetypeNode, filePathNode) {
11
- if (!filePathNode) {
12
- filePathNode = mimetypeNode;
13
- mimetypeNode = null;
1
+ import Quoted from '../tree/quoted.js';
2
+ import URL from '../tree/url.js';
3
+ import * as utils from '../utils.js';
4
+ import logger from '../logger.js';
5
+
6
+ export default environment => {
7
+
8
+ const fallback = (functionThis, node) => new URL(node, functionThis.index, functionThis.currentFileInfo).eval(functionThis.context);
9
+
10
+ return { 'data-uri': function(mimetypeNode, filePathNode) {
11
+
12
+ if (!filePathNode) {
13
+ filePathNode = mimetypeNode;
14
+ mimetypeNode = null;
15
+ }
16
+
17
+ let mimetype = mimetypeNode && mimetypeNode.value;
18
+ let filePath = filePathNode.value;
19
+ const currentFileInfo = this.currentFileInfo;
20
+ const currentDirectory = currentFileInfo.rewriteUrls ?
21
+ currentFileInfo.currentDirectory : currentFileInfo.entryPath;
22
+
23
+ const fragmentStart = filePath.indexOf('#');
24
+ let fragment = '';
25
+ if (fragmentStart !== -1) {
26
+ fragment = filePath.slice(fragmentStart);
27
+ filePath = filePath.slice(0, fragmentStart);
28
+ }
29
+ const context = utils.clone(this.context);
30
+ context.rawBuffer = true;
31
+
32
+ const fileManager = environment.getFileManager(filePath, currentDirectory, context, environment, true);
33
+
34
+ if (!fileManager) {
35
+ return fallback(this, filePathNode);
36
+ }
37
+
38
+ let useBase64 = false;
39
+
40
+ // detect the mimetype if not given
41
+ if (!mimetypeNode) {
42
+
43
+ mimetype = environment.mimeLookup(filePath);
44
+
45
+ if (mimetype === 'image/svg+xml') {
46
+ useBase64 = false;
47
+ } else {
48
+ // use base 64 unless it's an ASCII or UTF-8 format
49
+ const charset = environment.charsetLookup(mimetype);
50
+ useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
14
51
  }
15
- var mimetype = mimetypeNode && mimetypeNode.value;
16
- var filePath = filePathNode.value;
17
- var currentFileInfo = this.currentFileInfo;
18
- var currentDirectory = currentFileInfo.rewriteUrls ?
19
- currentFileInfo.currentDirectory : currentFileInfo.entryPath;
20
- var fragmentStart = filePath.indexOf('#');
21
- var fragment = '';
22
- if (fragmentStart !== -1) {
23
- fragment = filePath.slice(fragmentStart);
24
- filePath = filePath.slice(0, fragmentStart);
25
- }
26
- var context = utils.clone(this.context);
27
- context.rawBuffer = true;
28
- var fileManager = environment.getFileManager(filePath, currentDirectory, context, environment, true);
29
- if (!fileManager) {
30
- return fallback(this, filePathNode);
31
- }
32
- var useBase64 = false;
33
- // detect the mimetype if not given
34
- if (!mimetypeNode) {
35
- mimetype = environment.mimeLookup(filePath);
36
- if (mimetype === 'image/svg+xml') {
37
- useBase64 = false;
38
- }
39
- else {
40
- // use base 64 unless it's an ASCII or UTF-8 format
41
- var charset = environment.charsetLookup(mimetype);
42
- useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
43
- }
44
- if (useBase64) {
45
- mimetype += ';base64';
46
- }
47
- }
48
- else {
49
- useBase64 = /;base64$/.test(mimetype);
50
- }
51
- var fileSync = fileManager.loadFileSync(filePath, currentDirectory, context, environment);
52
- if (!fileSync.contents) {
53
- logger_1.default.warn("Skipped data-uri embedding of ".concat(filePath, " because file not found"));
54
- return fallback(this, filePathNode || mimetypeNode);
55
- }
56
- var buf = fileSync.contents;
57
- if (useBase64 && !environment.encodeBase64) {
58
- return fallback(this, filePathNode);
59
- }
60
- buf = useBase64 ? environment.encodeBase64(buf) : encodeURIComponent(buf);
61
- var uri = "data:".concat(mimetype, ",").concat(buf).concat(fragment);
62
- return new url_1.default(new quoted_1.default("\"".concat(uri, "\""), uri, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
63
- } };
64
- });
65
- //# sourceMappingURL=data-uri.js.map
52
+ if (useBase64) { mimetype += ';base64'; }
53
+ }
54
+ else {
55
+ useBase64 = /;base64$/.test(mimetype);
56
+ }
57
+
58
+ const fileSync = fileManager.loadFileSync(filePath, currentDirectory, context, environment);
59
+ if (!fileSync.contents) {
60
+ logger.warn(`Skipped data-uri embedding of ${filePath} because file not found`);
61
+ return fallback(this, filePathNode || mimetypeNode);
62
+ }
63
+ let buf = fileSync.contents;
64
+ if (useBase64 && !environment.encodeBase64) {
65
+ return fallback(this, filePathNode);
66
+ }
67
+
68
+ buf = useBase64 ? environment.encodeBase64(buf) : encodeURIComponent(buf);
69
+
70
+ const uri = `data:${mimetype},${buf}${fragment}`;
71
+
72
+ return new URL(new Quoted(`"${uri}"`, uri, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
73
+ }};
74
+ };