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,27 +1,45 @@
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 contexts_1 = tslib_1.__importDefault(require("../contexts"));
6
- var utils = tslib_1.__importStar(require("../utils"));
7
- var DetachedRuleset = function (ruleset, frames) {
8
- this.ruleset = ruleset;
9
- this.frames = frames;
10
- this.setParent(this.ruleset, this);
11
- };
12
- DetachedRuleset.prototype = Object.assign(new node_1.default(), {
13
- type: 'DetachedRuleset',
14
- evalFirst: true,
15
- accept: function (visitor) {
1
+ // @ts-check
2
+ /** @import { EvalContext, TreeVisitor } from './node.js' */
3
+ import Node from './node.js';
4
+ import contexts from '../contexts.js';
5
+ import * as utils from '../utils.js';
6
+
7
+ class DetachedRuleset extends Node {
8
+ get type() { return 'DetachedRuleset'; }
9
+
10
+ /**
11
+ * @param {Node} ruleset
12
+ * @param {Node[]} [frames]
13
+ */
14
+ constructor(ruleset, frames) {
15
+ super();
16
+ this.ruleset = ruleset;
17
+ this.frames = frames;
18
+ this.evalFirst = true;
19
+ this.setParent(this.ruleset, this);
20
+ }
21
+
22
+ /** @param {TreeVisitor} visitor */
23
+ accept(visitor) {
16
24
  this.ruleset = visitor.visit(this.ruleset);
17
- },
18
- eval: function (context) {
19
- var frames = this.frames || utils.copyArray(context.frames);
25
+ }
26
+
27
+ /**
28
+ * @param {EvalContext} context
29
+ * @returns {DetachedRuleset}
30
+ */
31
+ eval(context) {
32
+ const frames = this.frames || utils.copyArray(context.frames);
20
33
  return new DetachedRuleset(this.ruleset, frames);
21
- },
22
- callEval: function (context) {
23
- return this.ruleset.eval(this.frames ? new contexts_1.default.Eval(context, this.frames.concat(context.frames)) : context);
24
34
  }
25
- });
26
- exports.default = DetachedRuleset;
27
- //# sourceMappingURL=detached-ruleset.js.map
35
+
36
+ /**
37
+ * @param {EvalContext} context
38
+ * @returns {Node}
39
+ */
40
+ callEval(context) {
41
+ return this.ruleset.eval(this.frames ? new contexts.Eval(context, this.frames.concat(context.frames)) : context);
42
+ }
43
+ }
44
+
45
+ export default DetachedRuleset;
@@ -1,131 +1,182 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- var tslib_1 = require("tslib");
1
+ // @ts-check
4
2
  /* eslint-disable no-prototype-builtins */
5
- var node_1 = tslib_1.__importDefault(require("./node"));
6
- var unit_conversions_1 = tslib_1.__importDefault(require("../data/unit-conversions"));
7
- var unit_1 = tslib_1.__importDefault(require("./unit"));
8
- var color_1 = tslib_1.__importDefault(require("./color"));
3
+ import Node from './node.js';
4
+ import unitConversions from '../data/unit-conversions.js';
5
+ import Unit from './unit.js';
6
+ import Color from './color.js';
7
+
8
+ /** @import { EvalContext, CSSOutput } from './node.js' */
9
+
9
10
  //
10
11
  // A number with a unit
11
12
  //
12
- var Dimension = function (value, unit) {
13
- this.value = parseFloat(value);
14
- if (isNaN(this.value)) {
15
- throw new Error('Dimension is not a number.');
13
+ class Dimension extends Node {
14
+ get type() { return 'Dimension'; }
15
+
16
+ /**
17
+ * @param {number | string} value
18
+ * @param {Unit | string} [unit]
19
+ */
20
+ constructor(value, unit) {
21
+ super();
22
+ /** @type {number} */
23
+ this.value = parseFloat(/** @type {string} */ (value));
24
+ if (isNaN(this.value)) {
25
+ throw new Error('Dimension is not a number.');
26
+ }
27
+ /** @type {Unit} */
28
+ this.unit = (unit && unit instanceof Unit) ? unit :
29
+ new Unit(unit ? [/** @type {string} */ (unit)] : undefined);
30
+ this.setParent(this.unit, this);
31
+ }
32
+
33
+ /**
34
+ * @param {import('./node.js').TreeVisitor} visitor
35
+ */
36
+ accept(visitor) {
37
+ this.unit = /** @type {Unit} */ (visitor.visit(this.unit));
16
38
  }
17
- this.unit = (unit && unit instanceof unit_1.default) ? unit :
18
- new unit_1.default(unit ? [unit] : undefined);
19
- this.setParent(this.unit, this);
20
- };
21
- Dimension.prototype = Object.assign(new node_1.default(), {
22
- type: 'Dimension',
23
- accept: function (visitor) {
24
- this.unit = visitor.visit(this.unit);
25
- },
39
+
26
40
  // remove when Nodes have JSDoc types
27
41
  // eslint-disable-next-line no-unused-vars
28
- eval: function (context) {
42
+ /** @param {EvalContext} context */
43
+ eval(context) {
29
44
  return this;
30
- },
31
- toColor: function () {
32
- return new color_1.default([this.value, this.value, this.value]);
33
- },
34
- genCSS: function (context, output) {
45
+ }
46
+
47
+ toColor() {
48
+ const v = /** @type {number} */ (this.value);
49
+ return new Color([v, v, v]);
50
+ }
51
+
52
+ /**
53
+ * @param {EvalContext} context
54
+ * @param {CSSOutput} output
55
+ */
56
+ genCSS(context, output) {
35
57
  if ((context && context.strictUnits) && !this.unit.isSingular()) {
36
- throw new Error("Multiple units in dimension. Correct the units or use the unit function. Bad unit: ".concat(this.unit.toString()));
58
+ throw new Error(`Multiple units in dimension. Correct the units or use the unit function. Bad unit: ${this.unit.toString()}`);
37
59
  }
38
- var value = this.fround(context, this.value);
39
- var strValue = String(value);
60
+
61
+ const value = this.fround(context, /** @type {number} */ (this.value));
62
+ let strValue = String(value);
63
+
40
64
  if (value !== 0 && value < 0.000001 && value > -0.000001) {
41
65
  // would be output 1e-6 etc.
42
66
  strValue = value.toFixed(20).replace(/0+$/, '');
43
67
  }
68
+
44
69
  if (context && context.compress) {
45
70
  // Zero values doesn't need a unit
46
71
  if (value === 0 && this.unit.isLength()) {
47
72
  output.add(strValue);
48
73
  return;
49
74
  }
75
+
50
76
  // Float values doesn't need a leading zero
51
77
  if (value > 0 && value < 1) {
52
- strValue = (strValue).substr(1);
78
+ strValue = (strValue).slice(1);
53
79
  }
54
80
  }
81
+
55
82
  output.add(strValue);
56
83
  this.unit.genCSS(context, output);
57
- },
84
+ }
85
+
58
86
  // In an operation between two Dimensions,
59
87
  // we default to the first Dimension's unit,
60
88
  // so `1px + 2` will yield `3px`.
61
- operate: function (context, op, other) {
89
+ /**
90
+ * @param {EvalContext} context
91
+ * @param {string} op
92
+ * @param {Dimension} other
93
+ */
94
+ operate(context, op, other) {
62
95
  /* jshint noempty:false */
63
- var value = this._operate(context, op, this.value, other.value);
64
- var unit = this.unit.clone();
96
+ let value = this._operate(context, op, /** @type {number} */ (this.value), /** @type {number} */ (other.value));
97
+ let unit = this.unit.clone();
98
+
65
99
  if (op === '+' || op === '-') {
66
100
  if (unit.numerator.length === 0 && unit.denominator.length === 0) {
67
101
  unit = other.unit.clone();
68
102
  if (this.unit.backupUnit) {
69
103
  unit.backupUnit = this.unit.backupUnit;
70
104
  }
71
- }
72
- else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {
105
+ } else if (other.unit.numerator.length === 0 && unit.denominator.length === 0) {
73
106
  // do nothing
74
- }
75
- else {
107
+ } else {
76
108
  other = other.convertTo(this.unit.usedUnits());
109
+
77
110
  if (context.strictUnits && other.unit.toString() !== unit.toString()) {
78
111
  throw new Error('Incompatible units. Change the units or use the unit function. '
79
- + "Bad units: '".concat(unit.toString(), "' and '").concat(other.unit.toString(), "'."));
112
+ + `Bad units: '${unit.toString()}' and '${other.unit.toString()}'.`);
80
113
  }
81
- value = this._operate(context, op, this.value, other.value);
114
+
115
+ value = this._operate(context, op, /** @type {number} */ (this.value), /** @type {number} */ (other.value));
82
116
  }
83
- }
84
- else if (op === '*') {
117
+ } else if (op === '*') {
85
118
  unit.numerator = unit.numerator.concat(other.unit.numerator).sort();
86
119
  unit.denominator = unit.denominator.concat(other.unit.denominator).sort();
87
120
  unit.cancel();
88
- }
89
- else if (op === '/') {
121
+ } else if (op === '/') {
90
122
  unit.numerator = unit.numerator.concat(other.unit.denominator).sort();
91
123
  unit.denominator = unit.denominator.concat(other.unit.numerator).sort();
92
124
  unit.cancel();
93
125
  }
94
- return new Dimension(value, unit);
95
- },
96
- compare: function (other) {
97
- var a, b;
126
+ return new Dimension(/** @type {number} */ (value), unit);
127
+ }
128
+
129
+ /**
130
+ * @param {Node} other
131
+ * @returns {number | undefined}
132
+ */
133
+ compare(other) {
134
+ let a, b;
135
+
98
136
  if (!(other instanceof Dimension)) {
99
137
  return undefined;
100
138
  }
139
+
101
140
  if (this.unit.isEmpty() || other.unit.isEmpty()) {
102
141
  a = this;
103
142
  b = other;
104
- }
105
- else {
143
+ } else {
106
144
  a = this.unify();
107
145
  b = other.unify();
108
146
  if (a.unit.compare(b.unit) !== 0) {
109
147
  return undefined;
110
148
  }
111
149
  }
112
- return node_1.default.numericCompare(a.value, b.value);
113
- },
114
- unify: function () {
150
+
151
+ return Node.numericCompare(/** @type {number} */ (a.value), /** @type {number} */ (b.value));
152
+ }
153
+
154
+ unify() {
115
155
  return this.convertTo({ length: 'px', duration: 's', angle: 'rad' });
116
- },
117
- convertTo: function (conversions) {
118
- var value = this.value;
119
- var unit = this.unit.clone();
120
- var i;
121
- var groupName;
122
- var group;
123
- var targetUnit;
124
- var derivedConversions = {};
125
- var applyUnit;
156
+ }
157
+
158
+ /**
159
+ * @param {string | { [groupName: string]: string }} conversions
160
+ * @returns {Dimension}
161
+ */
162
+ convertTo(conversions) {
163
+ let value = /** @type {number} */ (this.value);
164
+ const unit = this.unit.clone();
165
+ let i;
166
+ /** @type {string} */
167
+ let groupName;
168
+ /** @type {{ [unitName: string]: number }} */
169
+ let group;
170
+ /** @type {string} */
171
+ let targetUnit;
172
+ /** @type {{ [groupName: string]: string }} */
173
+ let derivedConversions = {};
174
+ /** @type {(atomicUnit: string, denominator: boolean) => string} */
175
+ let applyUnit;
176
+
126
177
  if (typeof conversions === 'string') {
127
- for (i in unit_conversions_1.default) {
128
- if (unit_conversions_1.default[i].hasOwnProperty(conversions)) {
178
+ for (i in unitConversions) {
179
+ if (unitConversions[/** @type {keyof typeof unitConversions} */ (i)].hasOwnProperty(conversions)) {
129
180
  derivedConversions = {};
130
181
  derivedConversions[i] = conversions;
131
182
  }
@@ -136,24 +187,29 @@ Dimension.prototype = Object.assign(new node_1.default(), {
136
187
  if (group.hasOwnProperty(atomicUnit)) {
137
188
  if (denominator) {
138
189
  value = value / (group[atomicUnit] / group[targetUnit]);
139
- }
140
- else {
190
+ } else {
141
191
  value = value * (group[atomicUnit] / group[targetUnit]);
142
192
  }
193
+
143
194
  return targetUnit;
144
195
  }
196
+
145
197
  return atomicUnit;
146
198
  };
199
+
147
200
  for (groupName in conversions) {
148
201
  if (conversions.hasOwnProperty(groupName)) {
149
202
  targetUnit = conversions[groupName];
150
- group = unit_conversions_1.default[groupName];
203
+ group = /** @type {{ [unitName: string]: number }} */ (unitConversions[/** @type {keyof typeof unitConversions} */ (groupName)]);
204
+
151
205
  unit.map(applyUnit);
152
206
  }
153
207
  }
208
+
154
209
  unit.cancel();
210
+
155
211
  return new Dimension(value, unit);
156
212
  }
157
- });
158
- exports.default = Dimension;
159
- //# sourceMappingURL=dimension.js.map
213
+ }
214
+
215
+ export default Dimension;
@@ -1,63 +1,93 @@
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 paren_1 = tslib_1.__importDefault(require("./paren"));
6
- var combinator_1 = tslib_1.__importDefault(require("./combinator"));
7
- var Element = function (combinator, value, isVariable, index, currentFileInfo, visibilityInfo) {
8
- this.combinator = combinator instanceof combinator_1.default ?
9
- combinator : new combinator_1.default(combinator);
10
- if (typeof value === 'string') {
11
- this.value = value.trim();
12
- }
13
- else if (value) {
14
- this.value = value;
15
- }
16
- else {
17
- this.value = '';
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo, VisibilityInfo } from './node.js' */
3
+ import Node from './node.js';
4
+ import Paren from './paren.js';
5
+ import Combinator from './combinator.js';
6
+
7
+ class Element extends Node {
8
+ get type() { return 'Element'; }
9
+
10
+ /**
11
+ * @param {Combinator | string} combinator
12
+ * @param {string | Node} value
13
+ * @param {boolean} [isVariable]
14
+ * @param {number} [index]
15
+ * @param {FileInfo} [currentFileInfo]
16
+ * @param {VisibilityInfo} [visibilityInfo]
17
+ */
18
+ constructor(combinator, value, isVariable, index, currentFileInfo, visibilityInfo) {
19
+ super();
20
+ this.combinator = combinator instanceof Combinator ?
21
+ combinator : new Combinator(combinator);
22
+
23
+ if (typeof value === 'string') {
24
+ this.value = value.trim();
25
+ } else if (value) {
26
+ this.value = value;
27
+ } else {
28
+ this.value = '';
29
+ }
30
+ /** @type {boolean | undefined} */
31
+ this.isVariable = isVariable;
32
+ this._index = index;
33
+ this._fileInfo = currentFileInfo;
34
+ this.copyVisibilityInfo(visibilityInfo);
35
+ this.setParent(this.combinator, this);
18
36
  }
19
- this.isVariable = isVariable;
20
- this._index = index;
21
- this._fileInfo = currentFileInfo;
22
- this.copyVisibilityInfo(visibilityInfo);
23
- this.setParent(this.combinator, this);
24
- };
25
- Element.prototype = Object.assign(new node_1.default(), {
26
- type: 'Element',
27
- accept: function (visitor) {
28
- var value = this.value;
29
- this.combinator = visitor.visit(this.combinator);
37
+
38
+ /** @param {TreeVisitor} visitor */
39
+ accept(visitor) {
40
+ const value = this.value;
41
+ this.combinator = /** @type {Combinator} */ (visitor.visit(this.combinator));
30
42
  if (typeof value === 'object') {
31
- this.value = visitor.visit(value);
43
+ this.value = visitor.visit(/** @type {Node} */ (value));
32
44
  }
33
- },
34
- eval: function (context) {
35
- return new Element(this.combinator, this.value.eval ? this.value.eval(context) : this.value, this.isVariable, this.getIndex(), this.fileInfo(), this.visibilityInfo());
36
- },
37
- clone: function () {
38
- return new Element(this.combinator, this.value, this.isVariable, this.getIndex(), this.fileInfo(), this.visibilityInfo());
39
- },
40
- genCSS: function (context, output) {
45
+ }
46
+
47
+ /** @param {EvalContext} context */
48
+ eval(context) {
49
+ return new Element(this.combinator,
50
+ /** @type {Node} */ (this.value).eval ? /** @type {Node} */ (this.value).eval(context) : /** @type {string} */ (this.value),
51
+ this.isVariable,
52
+ this.getIndex(),
53
+ this.fileInfo(), this.visibilityInfo());
54
+ }
55
+
56
+ clone() {
57
+ return new Element(this.combinator,
58
+ /** @type {string | Node} */ (this.value),
59
+ this.isVariable,
60
+ this.getIndex(),
61
+ this.fileInfo(), this.visibilityInfo());
62
+ }
63
+
64
+ /**
65
+ * @param {EvalContext} context
66
+ * @param {CSSOutput} output
67
+ */
68
+ genCSS(context, output) {
41
69
  output.add(this.toCSS(context), this.fileInfo(), this.getIndex());
42
- },
43
- toCSS: function (context) {
44
- context = context || {};
45
- var value = this.value;
46
- var firstSelector = context.firstSelector;
47
- if (value instanceof paren_1.default) {
70
+ }
71
+
72
+ /** @param {EvalContext} [context] */
73
+ toCSS(context) {
74
+ /** @type {EvalContext & { firstSelector?: boolean }} */
75
+ const ctx = context || {};
76
+ let value = this.value;
77
+ const firstSelector = ctx.firstSelector;
78
+ if (value instanceof Paren) {
48
79
  // selector in parens should not be affected by outer selector
49
80
  // flags (breaks only interpolated selectors - see #1973)
50
- context.firstSelector = true;
81
+ ctx.firstSelector = true;
51
82
  }
52
- value = value.toCSS ? value.toCSS(context) : value;
53
- context.firstSelector = firstSelector;
83
+ value = /** @type {Node} */ (value).toCSS ? /** @type {Node} */ (value).toCSS(ctx) : /** @type {string} */ (value);
84
+ ctx.firstSelector = firstSelector;
54
85
  if (value === '' && this.combinator.value.charAt(0) === '&') {
55
86
  return '';
56
- }
57
- else {
58
- return this.combinator.toCSS(context) + value;
87
+ } else {
88
+ return this.combinator.toCSS(ctx) + value;
59
89
  }
60
90
  }
61
- });
62
- exports.default = Element;
63
- //# sourceMappingURL=element.js.map
91
+ }
92
+
93
+ export default Element;
@@ -1,75 +1,100 @@
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 paren_1 = tslib_1.__importDefault(require("./paren"));
6
- var comment_1 = tslib_1.__importDefault(require("./comment"));
7
- var dimension_1 = tslib_1.__importDefault(require("./dimension"));
8
- var anonymous_1 = tslib_1.__importDefault(require("./anonymous"));
9
- var Expression = function (value, noSpacing) {
10
- this.value = value;
11
- this.noSpacing = noSpacing;
12
- if (!value) {
13
- throw new Error('Expression requires an array parameter');
1
+ // @ts-check
2
+ /** @import { EvalContext, CSSOutput, TreeVisitor } from './node.js' */
3
+ import Node from './node.js';
4
+ import Paren from './paren.js';
5
+ import Comment from './comment.js';
6
+ import Dimension from './dimension.js';
7
+ import Anonymous from './anonymous.js';
8
+
9
+ class Expression extends Node {
10
+ get type() { return 'Expression'; }
11
+
12
+ /**
13
+ * @param {Node[]} value
14
+ * @param {boolean} [noSpacing]
15
+ */
16
+ constructor(value, noSpacing) {
17
+ super();
18
+ this.value = value;
19
+ /** @type {boolean | undefined} */
20
+ this.noSpacing = noSpacing;
21
+ /** @type {boolean | undefined} */
22
+ this.parens = undefined;
23
+ /** @type {boolean | undefined} */
24
+ this.parensInOp = undefined;
25
+ if (!value) {
26
+ throw new Error('Expression requires an array parameter');
27
+ }
28
+ }
29
+
30
+ /** @param {TreeVisitor} visitor */
31
+ accept(visitor) {
32
+ this.value = visitor.visitArray(/** @type {Node[]} */ (this.value));
14
33
  }
15
- };
16
- Expression.prototype = Object.assign(new node_1.default(), {
17
- type: 'Expression',
18
- accept: function (visitor) {
19
- this.value = visitor.visitArray(this.value);
20
- },
21
- eval: function (context) {
22
- var noSpacing = this.noSpacing;
23
- var returnValue;
24
- var mathOn = context.isMathOn();
25
- var inParenthesis = this.parens;
26
- var doubleParen = false;
34
+
35
+ /** @param {EvalContext} context */
36
+ eval(context) {
37
+ const noSpacing = this.noSpacing;
38
+ /** @type {Node | Expression} */
39
+ let returnValue;
40
+ const mathOn = context.isMathOn();
41
+ const inParenthesis = this.parens;
42
+
43
+ let doubleParen = false;
27
44
  if (inParenthesis) {
28
45
  context.inParenthesis();
29
46
  }
30
- if (this.value.length > 1) {
31
- returnValue = new Expression(this.value.map(function (e) {
47
+ const value = /** @type {Node[]} */ (this.value);
48
+ if (value.length > 1) {
49
+ returnValue = new Expression(value.map(function (e) {
32
50
  if (!e.eval) {
33
51
  return e;
34
52
  }
35
53
  return e.eval(context);
36
54
  }), this.noSpacing);
37
- }
38
- else if (this.value.length === 1) {
39
- if (this.value[0].parens && !this.value[0].parensInOp && !context.inCalc) {
55
+ } else if (value.length === 1) {
56
+ const first = /** @type {Expression} */ (value[0]);
57
+ if (first.parens && !first.parensInOp && !context.inCalc) {
40
58
  doubleParen = true;
41
59
  }
42
- returnValue = this.value[0].eval(context);
43
- }
44
- else {
60
+ returnValue = value[0].eval(context);
61
+ } else {
45
62
  returnValue = this;
46
63
  }
47
64
  if (inParenthesis) {
48
65
  context.outOfParenthesis();
49
66
  }
50
67
  if (this.parens && this.parensInOp && !mathOn && !doubleParen
51
- && (!(returnValue instanceof dimension_1.default))) {
52
- returnValue = new paren_1.default(returnValue);
68
+ && (!(returnValue instanceof Dimension))) {
69
+ returnValue = new Paren(returnValue);
53
70
  }
54
- returnValue.noSpacing = returnValue.noSpacing || noSpacing;
71
+ /** @type {Expression} */ (returnValue).noSpacing =
72
+ /** @type {Expression} */ (returnValue).noSpacing || noSpacing;
55
73
  return returnValue;
56
- },
57
- genCSS: function (context, output) {
58
- for (var i = 0; i < this.value.length; i++) {
59
- this.value[i].genCSS(context, output);
60
- if (!this.noSpacing && i + 1 < this.value.length) {
61
- if (i + 1 < this.value.length && !(this.value[i + 1] instanceof anonymous_1.default) ||
62
- this.value[i + 1] instanceof anonymous_1.default && this.value[i + 1].value !== ',') {
74
+ }
75
+
76
+ /**
77
+ * @param {EvalContext} context
78
+ * @param {CSSOutput} output
79
+ */
80
+ genCSS(context, output) {
81
+ const value = /** @type {Node[]} */ (this.value);
82
+ for (let i = 0; i < value.length; i++) {
83
+ value[i].genCSS(context, output);
84
+ if (!this.noSpacing && i + 1 < value.length) {
85
+ if (!(value[i + 1] instanceof Anonymous) ||
86
+ value[i + 1] instanceof Anonymous && /** @type {string} */ (value[i + 1].value) !== ',') {
63
87
  output.add(' ');
64
88
  }
65
89
  }
66
90
  }
67
- },
68
- throwAwayComments: function () {
69
- this.value = this.value.filter(function (v) {
70
- return !(v instanceof comment_1.default);
91
+ }
92
+
93
+ throwAwayComments() {
94
+ this.value = /** @type {Node[]} */ (this.value).filter(function(v) {
95
+ return !(v instanceof Comment);
71
96
  });
72
97
  }
73
- });
74
- exports.default = Expression;
75
- //# sourceMappingURL=expression.js.map
98
+ }
99
+
100
+ export default Expression;