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,26 +1,37 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var node_1 = tslib_1.__importDefault(require("./node"));
5
- var anonymous_1 = tslib_1.__importDefault(require("./anonymous"));
6
- var function_caller_1 = tslib_1.__importDefault(require("../functions/function-caller"));
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo } from './node.js' */
3
+ import Node from './node.js';
4
+ import Anonymous from './anonymous.js';
5
+ import FunctionCaller from '../functions/function-caller.js';
6
+
7
7
  //
8
8
  // A function call node.
9
9
  //
10
- var Call = function (name, args, index, currentFileInfo) {
11
- this.name = name;
12
- this.args = args;
13
- this.calc = name === 'calc';
14
- this._index = index;
15
- this._fileInfo = currentFileInfo;
16
- };
17
- Call.prototype = Object.assign(new node_1.default(), {
18
- type: 'Call',
19
- accept: function (visitor) {
10
+ class Call extends Node {
11
+ get type() { return 'Call'; }
12
+
13
+ /**
14
+ * @param {string} name
15
+ * @param {Node[]} args
16
+ * @param {number} index
17
+ * @param {FileInfo} currentFileInfo
18
+ */
19
+ constructor(name, args, index, currentFileInfo) {
20
+ super();
21
+ this.name = name;
22
+ this.args = args;
23
+ this.calc = name === 'calc';
24
+ this._index = index;
25
+ this._fileInfo = currentFileInfo;
26
+ }
27
+
28
+ /** @param {TreeVisitor} visitor */
29
+ accept(visitor) {
20
30
  if (this.args) {
21
31
  this.args = visitor.visitArray(this.args);
22
32
  }
23
- },
33
+ }
34
+
24
35
  //
25
36
  // When evaluating a function call,
26
37
  // we either find the function in the functionRegistry,
@@ -32,73 +43,90 @@ Call.prototype = Object.assign(new node_1.default(), {
32
43
  // we try to pass a variable to a function, like: `saturate(@color)`.
33
44
  // The function should receive the value, not the variable.
34
45
  //
35
- eval: function (context) {
36
- var _this = this;
46
+ /**
47
+ * @param {EvalContext} context
48
+ * @returns {Node}
49
+ */
50
+ eval(context) {
37
51
  /**
38
52
  * Turn off math for calc(), and switch back on for evaluating nested functions
39
53
  */
40
- var currentMathContext = context.mathOn;
54
+ const currentMathContext = context.mathOn;
41
55
  context.mathOn = !this.calc;
42
56
  if (this.calc || context.inCalc) {
43
57
  context.enterCalc();
44
58
  }
45
- var exitCalc = function () {
46
- if (_this.calc || context.inCalc) {
59
+
60
+ const exitCalc = () => {
61
+ if (this.calc || context.inCalc) {
47
62
  context.exitCalc();
48
63
  }
49
64
  context.mathOn = currentMathContext;
50
65
  };
51
- var result;
52
- var funcCaller = new function_caller_1.default(this.name, context, this.getIndex(), this.fileInfo());
66
+
67
+ /** @type {Node | string | boolean | null | undefined} */
68
+ let result;
69
+ const funcCaller = new FunctionCaller(this.name, context, this.getIndex(), this.fileInfo());
70
+
53
71
  if (funcCaller.isValid()) {
54
72
  try {
55
73
  result = funcCaller.call(this.args);
56
74
  exitCalc();
57
- }
58
- catch (e) {
75
+ } catch (e) {
59
76
  // eslint-disable-next-line no-prototype-builtins
60
- if (e.hasOwnProperty('line') && e.hasOwnProperty('column')) {
77
+ if (/** @type {Record<string, unknown>} */ (e).hasOwnProperty('line') && /** @type {Record<string, unknown>} */ (e).hasOwnProperty('column')) {
61
78
  throw e;
62
79
  }
63
80
  throw {
64
- type: e.type || 'Runtime',
65
- message: "Error evaluating function `".concat(this.name, "`").concat(e.message ? ": ".concat(e.message) : ''),
81
+ type: /** @type {Record<string, string>} */ (e).type || 'Runtime',
82
+ message: `Error evaluating function \`${this.name}\`${/** @type {Error} */ (e).message ? `: ${/** @type {Error} */ (e).message}` : ''}`,
66
83
  index: this.getIndex(),
67
84
  filename: this.fileInfo().filename,
68
- line: e.lineNumber,
69
- column: e.columnNumber
85
+ line: /** @type {Record<string, number>} */ (e).lineNumber,
86
+ column: /** @type {Record<string, number>} */ (e).columnNumber
70
87
  };
71
88
  }
72
89
  }
90
+
73
91
  if (result !== null && result !== undefined) {
74
92
  // Results that that are not nodes are cast as Anonymous nodes
75
93
  // Falsy values or booleans are returned as empty nodes
76
- if (!(result instanceof node_1.default)) {
94
+ if (!(result instanceof Node)) {
77
95
  if (!result || result === true) {
78
- result = new anonymous_1.default(null);
96
+ result = new Anonymous(null);
79
97
  }
80
98
  else {
81
- result = new anonymous_1.default(result.toString());
99
+ result = new Anonymous(result.toString());
82
100
  }
101
+
83
102
  }
84
103
  result._index = this._index;
85
104
  result._fileInfo = this._fileInfo;
86
105
  return result;
87
106
  }
88
- var args = this.args.map(function (a) { return a.eval(context); });
107
+
108
+ const args = this.args.map(a => a.eval(context));
89
109
  exitCalc();
110
+
90
111
  return new Call(this.name, args, this.getIndex(), this.fileInfo());
91
- },
92
- genCSS: function (context, output) {
93
- output.add("".concat(this.name, "("), this.fileInfo(), this.getIndex());
94
- for (var i = 0; i < this.args.length; i++) {
112
+ }
113
+
114
+ /**
115
+ * @param {EvalContext} context
116
+ * @param {CSSOutput} output
117
+ */
118
+ genCSS(context, output) {
119
+ output.add(`${this.name}(`, this.fileInfo(), this.getIndex());
120
+
121
+ for (let i = 0; i < this.args.length; i++) {
95
122
  this.args[i].genCSS(context, output);
96
123
  if (i + 1 < this.args.length) {
97
124
  output.add(', ');
98
125
  }
99
126
  }
127
+
100
128
  output.add(')');
101
129
  }
102
- });
103
- exports.default = Call;
104
- //# sourceMappingURL=call.js.map
130
+ }
131
+
132
+ export default Call;
@@ -1,94 +1,119 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var node_1 = tslib_1.__importDefault(require("./node"));
5
- var colors_1 = tslib_1.__importDefault(require("../data/colors"));
1
+ // @ts-check
2
+ import Node from './node.js';
3
+ import colors from '../data/colors.js';
4
+
5
+ /** @import { EvalContext, CSSOutput } from './node.js' */
6
+
6
7
  //
7
8
  // RGB Colors - #ff0014, #eee
8
9
  //
9
- var Color = function (rgb, a, originalForm) {
10
- var self = this;
11
- //
12
- // The end goal here, is to parse the arguments
13
- // into an integer triplet, such as `128, 255, 0`
14
- //
15
- // This facilitates operations and conversions.
16
- //
17
- if (Array.isArray(rgb)) {
18
- this.rgb = rgb;
19
- }
20
- else if (rgb.length >= 6) {
21
- this.rgb = [];
22
- rgb.match(/.{2}/g).map(function (c, i) {
23
- if (i < 3) {
24
- self.rgb.push(parseInt(c, 16));
25
- }
26
- else {
27
- self.alpha = (parseInt(c, 16)) / 255;
28
- }
29
- });
30
- }
31
- else {
32
- this.rgb = [];
33
- rgb.split('').map(function (c, i) {
34
- if (i < 3) {
35
- self.rgb.push(parseInt(c + c, 16));
36
- }
37
- else {
38
- self.alpha = (parseInt(c + c, 16)) / 255;
39
- }
40
- });
41
- }
42
- this.alpha = this.alpha || (typeof a === 'number' ? a : 1);
43
- if (typeof originalForm !== 'undefined') {
44
- this.value = originalForm;
10
+ class Color extends Node {
11
+ get type() { return 'Color'; }
12
+
13
+ /**
14
+ * @param {number[] | string} rgb
15
+ * @param {number} [a]
16
+ * @param {string} [originalForm]
17
+ */
18
+ constructor(rgb, a, originalForm) {
19
+ super();
20
+ const self = this;
21
+ //
22
+ // The end goal here, is to parse the arguments
23
+ // into an integer triplet, such as `128, 255, 0`
24
+ //
25
+ // This facilitates operations and conversions.
26
+ //
27
+ if (Array.isArray(rgb)) {
28
+ /** @type {number[]} */
29
+ this.rgb = rgb;
30
+ } else if (rgb.length >= 6) {
31
+ /** @type {number[]} */
32
+ this.rgb = [];
33
+ /** @type {RegExpMatchArray} */ (rgb.match(/.{2}/g)).map(function (c, i) {
34
+ if (i < 3) {
35
+ self.rgb.push(parseInt(c, 16));
36
+ } else {
37
+ self.alpha = (parseInt(c, 16)) / 255;
38
+ }
39
+ });
40
+ } else {
41
+ /** @type {number[]} */
42
+ this.rgb = [];
43
+ rgb.split('').map(function (c, i) {
44
+ if (i < 3) {
45
+ self.rgb.push(parseInt(c + c, 16));
46
+ } else {
47
+ self.alpha = (parseInt(c + c, 16)) / 255;
48
+ }
49
+ });
50
+ }
51
+ /** @type {number} */
52
+ if (typeof this.alpha === 'undefined') {
53
+ this.alpha = (typeof a === 'number') ? a : 1;
54
+ }
55
+ if (typeof originalForm !== 'undefined') {
56
+ this.value = originalForm;
57
+ }
45
58
  }
46
- };
47
- Color.prototype = Object.assign(new node_1.default(), {
48
- type: 'Color',
49
- luma: function () {
50
- var r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255;
59
+
60
+ luma() {
61
+ let r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255;
62
+
51
63
  r = (r <= 0.03928) ? r / 12.92 : Math.pow(((r + 0.055) / 1.055), 2.4);
52
64
  g = (g <= 0.03928) ? g / 12.92 : Math.pow(((g + 0.055) / 1.055), 2.4);
53
65
  b = (b <= 0.03928) ? b / 12.92 : Math.pow(((b + 0.055) / 1.055), 2.4);
66
+
54
67
  return 0.2126 * r + 0.7152 * g + 0.0722 * b;
55
- },
56
- genCSS: function (context, output) {
68
+ }
69
+
70
+ /**
71
+ * @param {EvalContext} context
72
+ * @param {CSSOutput} output
73
+ */
74
+ genCSS(context, output) {
57
75
  output.add(this.toCSS(context));
58
- },
59
- toCSS: function (context, doNotCompress) {
60
- var compress = context && context.compress && !doNotCompress;
61
- var color;
62
- var alpha;
63
- var colorFunction;
64
- var args = [];
76
+ }
77
+
78
+ /**
79
+ * @param {EvalContext} context
80
+ * @param {boolean} [doNotCompress]
81
+ * @returns {string}
82
+ */
83
+ toCSS(context, doNotCompress) {
84
+ const compress = context && context.compress && !doNotCompress;
85
+ let color;
86
+ let alpha;
87
+ /** @type {string | undefined} */
88
+ let colorFunction;
89
+ /** @type {(string | number)[]} */
90
+ let args = [];
91
+
65
92
  // `value` is set if this color was originally
66
93
  // converted from a named color string so we need
67
94
  // to respect this and try to output named color too.
68
95
  alpha = this.fround(context, this.alpha);
96
+
69
97
  if (this.value) {
70
- if (this.value.indexOf('rgb') === 0) {
98
+ if (/** @type {string} */ (this.value).indexOf('rgb') === 0) {
71
99
  if (alpha < 1) {
72
100
  colorFunction = 'rgba';
73
101
  }
74
- }
75
- else if (this.value.indexOf('hsl') === 0) {
102
+ } else if (/** @type {string} */ (this.value).indexOf('hsl') === 0) {
76
103
  if (alpha < 1) {
77
104
  colorFunction = 'hsla';
78
- }
79
- else {
105
+ } else {
80
106
  colorFunction = 'hsl';
81
107
  }
108
+ } else {
109
+ return /** @type {string} */ (this.value);
82
110
  }
83
- else {
84
- return this.value;
85
- }
86
- }
87
- else {
111
+ } else {
88
112
  if (alpha < 1) {
89
113
  colorFunction = 'rgba';
90
114
  }
91
115
  }
116
+
92
117
  switch (colorFunction) {
93
118
  case 'rgba':
94
119
  args = this.rgb.map(function (c) {
@@ -102,135 +127,159 @@ Color.prototype = Object.assign(new node_1.default(), {
102
127
  color = this.toHSL();
103
128
  args = [
104
129
  this.fround(context, color.h),
105
- "".concat(this.fround(context, color.s * 100), "%"),
106
- "".concat(this.fround(context, color.l * 100), "%")
130
+ `${this.fround(context, color.s * 100)}%`,
131
+ `${this.fround(context, color.l * 100)}%`
107
132
  ].concat(args);
108
133
  }
134
+
109
135
  if (colorFunction) {
110
136
  // Values are capped between `0` and `255`, rounded and zero-padded.
111
- return "".concat(colorFunction, "(").concat(args.join(",".concat(compress ? '' : ' ')), ")");
137
+ return `${colorFunction}(${args.join(`,${compress ? '' : ' '}`)})`;
112
138
  }
139
+
113
140
  color = this.toRGB();
141
+
114
142
  if (compress) {
115
- var splitcolor = color.split('');
143
+ const splitcolor = color.split('');
144
+
116
145
  // Convert color to short format
117
146
  if (splitcolor[1] === splitcolor[2] && splitcolor[3] === splitcolor[4] && splitcolor[5] === splitcolor[6]) {
118
- color = "#".concat(splitcolor[1]).concat(splitcolor[3]).concat(splitcolor[5]);
147
+ color = `#${splitcolor[1]}${splitcolor[3]}${splitcolor[5]}`;
119
148
  }
120
149
  }
150
+
121
151
  return color;
122
- },
152
+ }
153
+
123
154
  //
124
155
  // Operations have to be done per-channel, if not,
125
156
  // channels will spill onto each other. Once we have
126
157
  // our result, in the form of an integer triplet,
127
158
  // we create a new Color node to hold the result.
128
159
  //
129
- operate: function (context, op, other) {
130
- var rgb = new Array(3);
131
- var alpha = this.alpha * (1 - other.alpha) + other.alpha;
132
- for (var c = 0; c < 3; c++) {
160
+ /**
161
+ * @param {EvalContext} context
162
+ * @param {string} op
163
+ * @param {Color} other
164
+ */
165
+ operate(context, op, other) {
166
+ const rgb = new Array(3);
167
+ const alpha = this.alpha * (1 - other.alpha) + other.alpha;
168
+ for (let c = 0; c < 3; c++) {
133
169
  rgb[c] = this._operate(context, op, this.rgb[c], other.rgb[c]);
134
170
  }
135
171
  return new Color(rgb, alpha);
136
- },
137
- toRGB: function () {
172
+ }
173
+
174
+ toRGB() {
138
175
  return toHex(this.rgb);
139
- },
140
- toHSL: function () {
141
- var r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
142
- var max = Math.max(r, g, b), min = Math.min(r, g, b);
143
- var h;
144
- var s;
145
- var l = (max + min) / 2;
146
- var d = max - min;
176
+ }
177
+
178
+ toHSL() {
179
+ const r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
180
+
181
+ const max = Math.max(r, g, b), min = Math.min(r, g, b);
182
+ /** @type {number} */
183
+ let h;
184
+ let s;
185
+ const l = (max + min) / 2;
186
+ const d = max - min;
187
+
147
188
  if (max === min) {
148
189
  h = s = 0;
149
- }
150
- else {
190
+ } else {
151
191
  s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
192
+
152
193
  switch (max) {
153
- case r:
154
- h = (g - b) / d + (g < b ? 6 : 0);
155
- break;
156
- case g:
157
- h = (b - r) / d + 2;
158
- break;
159
- case b:
160
- h = (r - g) / d + 4;
161
- break;
194
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
195
+ case g: h = (b - r) / d + 2; break;
196
+ case b: h = (r - g) / d + 4; break;
162
197
  }
163
- h /= 6;
198
+ /** @type {number} */ (h) /= 6;
164
199
  }
165
- return { h: h * 360, s: s, l: l, a: a };
166
- },
200
+ return { h: /** @type {number} */ (h) * 360, s, l, a };
201
+ }
202
+
167
203
  // Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
168
- toHSV: function () {
169
- var r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
170
- var max = Math.max(r, g, b), min = Math.min(r, g, b);
171
- var h;
172
- var s;
173
- var v = max;
174
- var d = max - min;
204
+ toHSV() {
205
+ const r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
206
+
207
+ const max = Math.max(r, g, b), min = Math.min(r, g, b);
208
+ /** @type {number} */
209
+ let h;
210
+ let s;
211
+ const v = max;
212
+
213
+ const d = max - min;
175
214
  if (max === 0) {
176
215
  s = 0;
177
- }
178
- else {
216
+ } else {
179
217
  s = d / max;
180
218
  }
219
+
181
220
  if (max === min) {
182
221
  h = 0;
183
- }
184
- else {
222
+ } else {
185
223
  switch (max) {
186
- case r:
187
- h = (g - b) / d + (g < b ? 6 : 0);
188
- break;
189
- case g:
190
- h = (b - r) / d + 2;
191
- break;
192
- case b:
193
- h = (r - g) / d + 4;
194
- break;
224
+ case r: h = (g - b) / d + (g < b ? 6 : 0); break;
225
+ case g: h = (b - r) / d + 2; break;
226
+ case b: h = (r - g) / d + 4; break;
195
227
  }
196
- h /= 6;
228
+ /** @type {number} */ (h) /= 6;
197
229
  }
198
- return { h: h * 360, s: s, v: v, a: a };
199
- },
200
- toARGB: function () {
230
+ return { h: /** @type {number} */ (h) * 360, s, v, a };
231
+ }
232
+
233
+ toARGB() {
201
234
  return toHex([this.alpha * 255].concat(this.rgb));
202
- },
203
- compare: function (x) {
235
+ }
236
+
237
+ /**
238
+ * @param {Node & { rgb?: number[], alpha?: number }} x
239
+ * @returns {0 | undefined}
240
+ */
241
+ compare(x) {
204
242
  return (x.rgb &&
205
243
  x.rgb[0] === this.rgb[0] &&
206
244
  x.rgb[1] === this.rgb[1] &&
207
245
  x.rgb[2] === this.rgb[2] &&
208
- x.alpha === this.alpha) ? 0 : undefined;
209
- }
210
- });
211
- Color.fromKeyword = function (keyword) {
212
- var c;
213
- var key = keyword.toLowerCase();
214
- // eslint-disable-next-line no-prototype-builtins
215
- if (colors_1.default.hasOwnProperty(key)) {
216
- c = new Color(colors_1.default[key].slice(1));
217
- }
218
- else if (key === 'transparent') {
219
- c = new Color([0, 0, 0], 0);
246
+ x.alpha === this.alpha) ? 0 : undefined;
220
247
  }
221
- if (c) {
222
- c.value = keyword;
223
- return c;
248
+
249
+ /** @param {string} keyword */
250
+ static fromKeyword(keyword) {
251
+ /** @type {Color | undefined} */
252
+ let c;
253
+ const key = keyword.toLowerCase();
254
+ // eslint-disable-next-line no-prototype-builtins
255
+ if (colors.hasOwnProperty(key)) {
256
+ c = new Color(/** @type {string} */ (colors[/** @type {keyof typeof colors} */ (key)]).slice(1));
257
+ }
258
+ else if (key === 'transparent') {
259
+ c = new Color([0, 0, 0], 0);
260
+ }
261
+
262
+ if (c) {
263
+ c.value = keyword;
264
+ return c;
265
+ }
224
266
  }
225
- };
267
+ }
268
+
269
+ /**
270
+ * @param {number} v
271
+ * @param {number} max
272
+ */
226
273
  function clamp(v, max) {
227
274
  return Math.min(Math.max(v, 0), max);
228
275
  }
276
+
277
+ /** @param {number[]} v */
229
278
  function toHex(v) {
230
- return "#".concat(v.map(function (c) {
279
+ return `#${v.map(function (c) {
231
280
  c = clamp(Math.round(c), 255);
232
281
  return (c < 16 ? '0' : '') + c.toString(16);
233
- }).join(''));
282
+ }).join('')}`;
234
283
  }
235
- exports.default = Color;
236
- //# sourceMappingURL=color.js.map
284
+
285
+ export default Color;
@@ -1,28 +1,38 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
4
- var node_1 = tslib_1.__importDefault(require("./node"));
5
- var _noSpaceCombinators = {
1
+ // @ts-check
2
+ import Node from './node.js';
3
+
4
+ /** @import { EvalContext, CSSOutput } from './node.js' */
5
+
6
+ /** @type {Record<string, boolean>} */
7
+ const _noSpaceCombinators = {
6
8
  '': true,
7
9
  ' ': true,
8
10
  '|': true
9
11
  };
10
- var Combinator = function (value) {
11
- if (value === ' ') {
12
- this.value = ' ';
13
- this.emptyOrWhitespace = true;
12
+
13
+ class Combinator extends Node {
14
+ get type() { return 'Combinator'; }
15
+
16
+ /** @param {string} value */
17
+ constructor(value) {
18
+ super();
19
+ if (value === ' ') {
20
+ this.value = ' ';
21
+ this.emptyOrWhitespace = true;
22
+ } else {
23
+ this.value = value ? value.trim() : '';
24
+ this.emptyOrWhitespace = this.value === '';
25
+ }
14
26
  }
15
- else {
16
- this.value = value ? value.trim() : '';
17
- this.emptyOrWhitespace = this.value === '';
18
- }
19
- };
20
- Combinator.prototype = Object.assign(new node_1.default(), {
21
- type: 'Combinator',
22
- genCSS: function (context, output) {
23
- var spaceOrEmpty = (context.compress || _noSpaceCombinators[this.value]) ? '' : ' ';
27
+
28
+ /**
29
+ * @param {EvalContext} context
30
+ * @param {CSSOutput} output
31
+ */
32
+ genCSS(context, output) {
33
+ const spaceOrEmpty = (context.compress || _noSpaceCombinators[/** @type {string} */ (this.value)]) ? '' : ' ';
24
34
  output.add(spaceOrEmpty + this.value + spaceOrEmpty);
25
35
  }
26
- });
27
- exports.default = Combinator;
28
- //# sourceMappingURL=combinator.js.map
36
+ }
37
+
38
+ export default Combinator;