less 4.4.2 → 4.6.0
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.
- package/bin/lessc +67 -58
- package/dist/less.js +14496 -11811
- package/dist/less.min.js +4 -4
- package/dist/less.min.js.map +1 -1
- package/lib/less/constants.js +5 -7
- package/lib/less/contexts.js +71 -56
- package/lib/less/data/colors.js +150 -153
- package/lib/less/data/index.js +4 -7
- package/lib/less/data/unit-conversions.js +2 -5
- package/lib/less/default-options.js +52 -23
- package/lib/less/deprecation.js +67 -0
- package/lib/less/environment/abstract-file-manager.js +62 -50
- package/lib/less/environment/abstract-plugin-loader.js +69 -46
- package/lib/less/environment/environment-api.ts +21 -0
- package/lib/less/environment/environment.js +34 -30
- package/lib/less/environment/file-manager-api.ts +77 -0
- package/lib/less/functions/boolean.js +13 -13
- package/lib/less/functions/color-blending.js +39 -31
- package/lib/less/functions/color.js +153 -137
- package/lib/less/functions/data-uri.js +73 -64
- package/lib/less/functions/default.js +9 -11
- package/lib/less/functions/function-caller.js +35 -34
- package/lib/less/functions/function-registry.js +16 -17
- package/lib/less/functions/index.js +33 -33
- package/lib/less/functions/list.js +88 -75
- package/lib/less/functions/math-helper.js +8 -11
- package/lib/less/functions/math.js +21 -21
- package/lib/less/functions/number.js +42 -53
- package/lib/less/functions/string.js +18 -22
- package/lib/less/functions/style.js +21 -20
- package/lib/less/functions/svg.js +83 -82
- package/lib/less/functions/types.js +28 -32
- package/lib/less/import-manager.js +73 -64
- package/lib/less/index.js +65 -65
- package/lib/less/less-error.js +65 -46
- package/lib/less/logger.js +11 -14
- package/lib/less/parse-tree.js +94 -38
- package/lib/less/parse.js +44 -44
- package/lib/less/parser/parser-input.js +152 -131
- package/lib/less/parser/parser.js +866 -672
- package/lib/less/plugin-manager.js +57 -46
- package/lib/less/render.js +17 -23
- package/lib/less/source-map-builder.js +52 -43
- package/lib/less/source-map-output.js +57 -44
- package/lib/less/transform-tree.js +40 -30
- package/lib/less/tree/anonymous.js +52 -28
- package/lib/less/tree/assignment.js +44 -27
- package/lib/less/tree/atrule-syntax.js +4 -6
- package/lib/less/tree/atrule.js +247 -140
- package/lib/less/tree/attribute.js +55 -24
- package/lib/less/tree/call.js +70 -42
- package/lib/less/tree/color.js +194 -145
- package/lib/less/tree/combinator.js +31 -21
- package/lib/less/tree/comment.js +44 -23
- package/lib/less/tree/condition.js +61 -36
- package/lib/less/tree/container.js +90 -34
- package/lib/less/tree/debug-info.js +53 -11
- package/lib/less/tree/declaration.js +97 -52
- package/lib/less/tree/detached-ruleset.js +42 -24
- package/lib/less/tree/dimension.js +127 -71
- package/lib/less/tree/element.js +82 -52
- package/lib/less/tree/expression.js +75 -50
- package/lib/less/tree/extend.js +71 -42
- package/lib/less/tree/import.js +184 -110
- package/lib/less/tree/index.js +52 -81
- package/lib/less/tree/javascript.js +43 -32
- package/lib/less/tree/js-eval-node.js +46 -32
- package/lib/less/tree/keyword.js +25 -17
- package/lib/less/tree/media.js +77 -35
- package/lib/less/tree/merge-rules.js +47 -0
- package/lib/less/tree/mixin-call.js +181 -98
- package/lib/less/tree/mixin-definition.js +211 -117
- package/lib/less/tree/namespace-value.js +63 -44
- package/lib/less/tree/negative.js +34 -21
- package/lib/less/tree/nested-at-rule.js +149 -66
- package/lib/less/tree/node.js +225 -90
- package/lib/less/tree/operation.js +59 -34
- package/lib/less/tree/paren.js +34 -17
- package/lib/less/tree/property.js +66 -35
- package/lib/less/tree/query-in-parens.js +52 -60
- package/lib/less/tree/quoted.js +93 -44
- package/lib/less/tree/ruleset.js +632 -318
- package/lib/less/tree/selector.js +151 -77
- package/lib/less/tree/unicode-descriptor.js +14 -12
- package/lib/less/tree/unit.js +111 -63
- package/lib/less/tree/url.js +62 -38
- package/lib/less/tree/value.js +50 -34
- package/lib/less/tree/variable-call.js +47 -30
- package/lib/less/tree/variable.js +53 -31
- package/lib/less/utils.js +44 -47
- package/lib/less/visitors/extend-visitor.js +233 -172
- package/lib/less/visitors/import-sequencer.js +24 -24
- package/lib/less/visitors/import-visitor.js +62 -52
- package/lib/less/visitors/index.js +14 -17
- package/lib/less/visitors/join-selector-visitor.js +40 -37
- package/lib/less/visitors/set-tree-visibility-visitor.js +32 -18
- package/lib/less/visitors/to-css-visitor.js +135 -128
- package/lib/less/visitors/visitor.js +60 -45
- package/lib/less-browser/add-default-options.js +23 -13
- package/lib/less-browser/bootstrap.js +23 -17
- package/lib/less-browser/browser.js +24 -21
- package/lib/less-browser/cache.js +17 -19
- package/lib/less-browser/error-reporting.js +52 -44
- package/lib/less-browser/file-manager.js +52 -42
- package/lib/less-browser/image-size.js +12 -12
- package/lib/less-browser/index.js +131 -105
- package/lib/less-browser/log-listener.js +30 -31
- package/lib/less-browser/plugin-loader.js +10 -10
- package/lib/less-browser/utils.js +19 -21
- package/lib/less-node/environment.js +32 -8
- package/lib/less-node/file-manager.js +62 -45
- package/lib/less-node/fs.js +11 -8
- package/lib/less-node/image-size.js +40 -31
- package/lib/less-node/index.js +28 -19
- package/lib/less-node/lessc-helper.js +28 -28
- package/lib/less-node/plugin-loader.js +35 -27
- package/lib/less-node/url-file-manager.js +33 -31
- package/package.json +31 -19
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -63
- package/Gruntfile.js +0 -404
- package/bower.json +0 -22
- package/lib/less/constants.js.map +0 -1
- package/lib/less/contexts.js.map +0 -1
- package/lib/less/data/colors.js.map +0 -1
- package/lib/less/data/index.js.map +0 -1
- package/lib/less/data/unit-conversions.js.map +0 -1
- package/lib/less/default-options.js.map +0 -1
- package/lib/less/environment/abstract-file-manager.js.map +0 -1
- package/lib/less/environment/abstract-plugin-loader.js.map +0 -1
- package/lib/less/environment/environment-api.js +0 -3
- package/lib/less/environment/environment-api.js.map +0 -1
- package/lib/less/environment/environment.js.map +0 -1
- package/lib/less/environment/file-manager-api.js +0 -3
- package/lib/less/environment/file-manager-api.js.map +0 -1
- package/lib/less/functions/boolean.js.map +0 -1
- package/lib/less/functions/color-blending.js.map +0 -1
- package/lib/less/functions/color.js.map +0 -1
- package/lib/less/functions/data-uri.js.map +0 -1
- package/lib/less/functions/default.js.map +0 -1
- package/lib/less/functions/function-caller.js.map +0 -1
- package/lib/less/functions/function-registry.js.map +0 -1
- package/lib/less/functions/index.js.map +0 -1
- package/lib/less/functions/list.js.map +0 -1
- package/lib/less/functions/math-helper.js.map +0 -1
- package/lib/less/functions/math.js.map +0 -1
- package/lib/less/functions/number.js.map +0 -1
- package/lib/less/functions/string.js.map +0 -1
- package/lib/less/functions/style.js.map +0 -1
- package/lib/less/functions/svg.js.map +0 -1
- package/lib/less/functions/types.js.map +0 -1
- package/lib/less/import-manager.js.map +0 -1
- package/lib/less/index.js.map +0 -1
- package/lib/less/less-error.js.map +0 -1
- package/lib/less/logger.js.map +0 -1
- package/lib/less/parse-tree.js.map +0 -1
- package/lib/less/parse.js.map +0 -1
- package/lib/less/parser/chunker.js +0 -148
- package/lib/less/parser/chunker.js.map +0 -1
- package/lib/less/parser/parser-input.js.map +0 -1
- package/lib/less/parser/parser.js.map +0 -1
- package/lib/less/plugin-manager.js.map +0 -1
- package/lib/less/render.js.map +0 -1
- package/lib/less/source-map-builder.js.map +0 -1
- package/lib/less/source-map-output.js.map +0 -1
- package/lib/less/transform-tree.js.map +0 -1
- package/lib/less/tree/anonymous.js.map +0 -1
- package/lib/less/tree/assignment.js.map +0 -1
- package/lib/less/tree/atrule-syntax.js.map +0 -1
- package/lib/less/tree/atrule.js.map +0 -1
- package/lib/less/tree/attribute.js.map +0 -1
- package/lib/less/tree/call.js.map +0 -1
- package/lib/less/tree/color.js.map +0 -1
- package/lib/less/tree/combinator.js.map +0 -1
- package/lib/less/tree/comment.js.map +0 -1
- package/lib/less/tree/condition.js.map +0 -1
- package/lib/less/tree/container.js.map +0 -1
- package/lib/less/tree/debug-info.js.map +0 -1
- package/lib/less/tree/declaration.js.map +0 -1
- package/lib/less/tree/detached-ruleset.js.map +0 -1
- package/lib/less/tree/dimension.js.map +0 -1
- package/lib/less/tree/element.js.map +0 -1
- package/lib/less/tree/expression.js.map +0 -1
- package/lib/less/tree/extend.js.map +0 -1
- package/lib/less/tree/import.js.map +0 -1
- package/lib/less/tree/index.js.map +0 -1
- package/lib/less/tree/javascript.js.map +0 -1
- package/lib/less/tree/js-eval-node.js.map +0 -1
- package/lib/less/tree/keyword.js.map +0 -1
- package/lib/less/tree/media.js.map +0 -1
- package/lib/less/tree/mixin-call.js.map +0 -1
- package/lib/less/tree/mixin-definition.js.map +0 -1
- package/lib/less/tree/namespace-value.js.map +0 -1
- package/lib/less/tree/negative.js.map +0 -1
- package/lib/less/tree/nested-at-rule.js.map +0 -1
- package/lib/less/tree/node.js.map +0 -1
- package/lib/less/tree/operation.js.map +0 -1
- package/lib/less/tree/paren.js.map +0 -1
- package/lib/less/tree/property.js.map +0 -1
- package/lib/less/tree/query-in-parens.js.map +0 -1
- package/lib/less/tree/quoted.js.map +0 -1
- package/lib/less/tree/ruleset.js.map +0 -1
- package/lib/less/tree/selector.js.map +0 -1
- package/lib/less/tree/unicode-descriptor.js.map +0 -1
- package/lib/less/tree/unit.js.map +0 -1
- package/lib/less/tree/url.js.map +0 -1
- package/lib/less/tree/value.js.map +0 -1
- package/lib/less/tree/variable-call.js.map +0 -1
- package/lib/less/tree/variable.js.map +0 -1
- package/lib/less/utils.js.map +0 -1
- package/lib/less/visitors/extend-visitor.js.map +0 -1
- package/lib/less/visitors/import-sequencer.js.map +0 -1
- package/lib/less/visitors/import-visitor.js.map +0 -1
- package/lib/less/visitors/index.js.map +0 -1
- package/lib/less/visitors/join-selector-visitor.js.map +0 -1
- package/lib/less/visitors/set-tree-visibility-visitor.js.map +0 -1
- package/lib/less/visitors/to-css-visitor.js.map +0 -1
- package/lib/less/visitors/visitor.js.map +0 -1
- package/lib/less-browser/add-default-options.js.map +0 -1
- package/lib/less-browser/bootstrap.js.map +0 -1
- package/lib/less-browser/browser.js.map +0 -1
- package/lib/less-browser/cache.js.map +0 -1
- package/lib/less-browser/error-reporting.js.map +0 -1
- package/lib/less-browser/file-manager.js.map +0 -1
- package/lib/less-browser/image-size.js.map +0 -1
- package/lib/less-browser/index.js.map +0 -1
- package/lib/less-browser/log-listener.js.map +0 -1
- package/lib/less-browser/plugin-loader.js.map +0 -1
- package/lib/less-browser/utils.js.map +0 -1
- package/lib/less-node/environment.js.map +0 -1
- package/lib/less-node/file-manager.js.map +0 -1
- package/lib/less-node/fs.js.map +0 -1
- package/lib/less-node/image-size.js.map +0 -1
- package/lib/less-node/index.js.map +0 -1
- package/lib/less-node/lessc-helper.js.map +0 -1
- package/lib/less-node/plugin-loader.js.map +0 -1
- package/lib/less-node/url-file-manager.js.map +0 -1
- package/test/.eslintrc.json +0 -9
- package/test/README.md +0 -3
- package/test/browser/common.js +0 -230
- package/test/browser/css/global-vars/simple.css +0 -3
- package/test/browser/css/modify-vars/simple.css +0 -8
- package/test/browser/css/plugin/plugin.css +0 -3
- package/test/browser/css/postProcessor/postProcessor.css +0 -4
- package/test/browser/css/relative-urls/urls.css +0 -36
- package/test/browser/css/rewrite-urls/urls.css +0 -36
- package/test/browser/css/rootpath/urls.css +0 -35
- package/test/browser/css/rootpath-relative/urls.css +0 -35
- package/test/browser/css/rootpath-rewrite-urls/urls.css +0 -35
- package/test/browser/css/urls.css +0 -54
- package/test/browser/generator/benchmark.config.js +0 -50
- package/test/browser/generator/generate.js +0 -78
- package/test/browser/generator/runner.config.js +0 -188
- package/test/browser/generator/runner.js +0 -2
- package/test/browser/generator/template.js +0 -93
- package/test/browser/generator/utils.js +0 -14
- package/test/browser/less/console-errors/test-error.less +0 -3
- package/test/browser/less/console-errors/test-error.txt +0 -2
- package/test/browser/less/errors/image-height-error.less +0 -3
- package/test/browser/less/errors/image-height-error.txt +0 -4
- package/test/browser/less/errors/image-size-error.less +0 -3
- package/test/browser/less/errors/image-size-error.txt +0 -4
- package/test/browser/less/errors/image-width-error.less +0 -3
- package/test/browser/less/errors/image-width-error.txt +0 -4
- package/test/browser/less/global-vars/simple.less +0 -3
- package/test/browser/less/imports/urls.less +0 -4
- package/test/browser/less/imports/urls2.less +0 -4
- package/test/browser/less/modify-vars/imports/simple2.less +0 -4
- package/test/browser/less/modify-vars/simple.less +0 -8
- package/test/browser/less/nested-gradient-with-svg-gradient/mixin-consumer.less +0 -5
- package/test/browser/less/nested-gradient-with-svg-gradient/svg-gradient-mixin.less +0 -15
- package/test/browser/less/plugin/plugin.js +0 -4
- package/test/browser/less/plugin/plugin.less +0 -4
- package/test/browser/less/postProcessor/postProcessor.less +0 -4
- package/test/browser/less/relative-urls/urls.less +0 -34
- package/test/browser/less/rewrite-urls/urls.less +0 -34
- package/test/browser/less/rootpath/urls.less +0 -33
- package/test/browser/less/rootpath-relative/urls.less +0 -33
- package/test/browser/less/rootpath-rewrite-urls/urls.less +0 -33
- package/test/browser/less/urls.less +0 -62
- package/test/browser/runner-VisitorPlugin-options.js +0 -3
- package/test/browser/runner-VisitorPlugin.js +0 -3
- package/test/browser/runner-browser-options.js +0 -51
- package/test/browser/runner-browser-spec.js +0 -12
- package/test/browser/runner-console-errors.js +0 -5
- package/test/browser/runner-errors-options.js +0 -6
- package/test/browser/runner-errors-spec.js +0 -3
- package/test/browser/runner-filemanagerPlugin-options.js +0 -5
- package/test/browser/runner-filemanagerPlugin.js +0 -3
- package/test/browser/runner-global-vars-options.js +0 -7
- package/test/browser/runner-global-vars-spec.js +0 -3
- package/test/browser/runner-legacy-options.js +0 -6
- package/test/browser/runner-legacy-spec.js +0 -3
- package/test/browser/runner-main-options.js +0 -17
- package/test/browser/runner-main-spec.js +0 -7
- package/test/browser/runner-modify-vars-options.js +0 -5
- package/test/browser/runner-modify-vars-spec.js +0 -33
- package/test/browser/runner-no-js-errors-options.js +0 -4
- package/test/browser/runner-no-js-errors-spec.js +0 -3
- package/test/browser/runner-postProcessorPlugin-options.js +0 -3
- package/test/browser/runner-postProcessorPlugin.js +0 -3
- package/test/browser/runner-preProcessorPlugin-options.js +0 -3
- package/test/browser/runner-preProcessorPlugin.js +0 -3
- package/test/browser/runner-production-options.js +0 -3
- package/test/browser/runner-production-spec.js +0 -5
- package/test/browser/runner-relative-urls-options.js +0 -3
- package/test/browser/runner-relative-urls-spec.js +0 -3
- package/test/browser/runner-rewrite-urls-options.js +0 -3
- package/test/browser/runner-rewrite-urls-spec.js +0 -3
- package/test/browser/runner-rootpath-options.js +0 -3
- package/test/browser/runner-rootpath-relative-options.js +0 -4
- package/test/browser/runner-rootpath-relative-spec.js +0 -3
- package/test/browser/runner-rootpath-rewrite-urls-options.js +0 -4
- package/test/browser/runner-rootpath-rewrite-urls-spec.js +0 -3
- package/test/browser/runner-rootpath-spec.js +0 -3
- package/test/browser/runner-strict-units-options.js +0 -5
- package/test/browser/runner-strict-units-spec.js +0 -3
- package/test/index.js +0 -112
- package/test/less-test.js +0 -625
- package/test/mocha-playwright/runner.js +0 -210
- package/test/modify-vars.js +0 -28
- package/test/plugins/filemanager/index.js +0 -19
- package/test/plugins/postprocess/index.js +0 -14
- package/test/plugins/preprocess/index.js +0 -19
- package/test/plugins/visitor/index.js +0 -24
- package/test/sourcemaps/basic.json +0 -1
- package/test/sourcemaps/custom-props.json +0 -1
- package/test/sourcemaps/index.html +0 -17
- package/test/sourcemaps-disable-annotation/basic.json +0 -1
- package/test/sourcemaps-variable-selector/basic.json +0 -1
- package/test/test-es6.ts +0 -17
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -21
package/lib/less/tree/call.js
CHANGED
|
@@ -1,26 +1,37 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
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
|
-
|
|
36
|
-
|
|
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
|
-
|
|
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
|
-
|
|
46
|
-
|
|
59
|
+
|
|
60
|
+
const exitCalc = () => {
|
|
61
|
+
if (this.calc || context.inCalc) {
|
|
47
62
|
context.exitCalc();
|
|
48
63
|
}
|
|
49
64
|
context.mathOn = currentMathContext;
|
|
50
65
|
};
|
|
51
|
-
|
|
52
|
-
|
|
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:
|
|
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
|
|
94
|
+
if (!(result instanceof Node)) {
|
|
77
95
|
if (!result || result === true) {
|
|
78
|
-
result = new
|
|
96
|
+
result = new Anonymous(null);
|
|
79
97
|
}
|
|
80
98
|
else {
|
|
81
|
-
result = new
|
|
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
|
-
|
|
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
|
-
|
|
93
|
-
|
|
94
|
-
|
|
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
|
-
|
|
104
|
-
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
export default Call;
|
package/lib/less/tree/color.js
CHANGED
|
@@ -1,94 +1,119 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
})
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
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
|
-
|
|
48
|
-
|
|
49
|
-
|
|
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
|
-
|
|
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
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
-
|
|
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
|
-
|
|
106
|
-
|
|
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
|
|
137
|
+
return `${colorFunction}(${args.join(`,${compress ? '' : ' '}`)})`;
|
|
112
138
|
}
|
|
139
|
+
|
|
113
140
|
color = this.toRGB();
|
|
141
|
+
|
|
114
142
|
if (compress) {
|
|
115
|
-
|
|
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 =
|
|
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
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
toRGB() {
|
|
138
175
|
return toHex(this.rgb);
|
|
139
|
-
}
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
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
|
-
|
|
155
|
-
|
|
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
|
|
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
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
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
|
-
|
|
188
|
-
|
|
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
|
|
199
|
-
}
|
|
200
|
-
|
|
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
|
-
|
|
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
|
|
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
|
-
|
|
222
|
-
|
|
223
|
-
|
|
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
|
|
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
|
-
|
|
236
|
-
|
|
284
|
+
|
|
285
|
+
export default Color;
|
|
@@ -1,28 +1,38 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
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
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
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
|
-
|
|
28
|
-
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
export default Combinator;
|