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.
- package/README.md +70 -5
- package/bin/lessc +37 -23
- package/dist/less.js +14501 -11745
- package/dist/less.min.js +4 -4
- package/dist/less.min.js.map +1 -1
- package/index.cjs +41 -0
- package/lib/less/constants.js +5 -7
- package/lib/less/contexts.js +71 -55
- 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 +36 -26
- 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 +63 -45
- package/lib/less/logger.js +11 -14
- package/lib/less/parse-tree.js +52 -53
- package/lib/less/parse.js +44 -44
- package/lib/less/parser/parser-input.js +151 -113
- package/lib/less/parser/parser.js +864 -658
- 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 +56 -43
- 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 +28 -15
- 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 +20 -21
- package/lib/less-node/plugin-loader.js +35 -27
- package/lib/less-node/url-file-manager.js +33 -31
- package/package.json +29 -18
- package/.eslintignore +0 -6
- package/.eslintrc.js +0 -63
- package/Gruntfile.js +0 -403
- 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/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/scripts/coverage-lines.js +0 -207
- package/scripts/coverage-report.js +0 -158
- package/scripts/postinstall.js +0 -61
- package/test/.eslintrc.json +0 -9
- package/test/README.md +0 -3
- package/test/browser/common.js +0 -251
- 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 -184
- package/test/browser/generator/runner.js +0 -2
- package/test/browser/generator/template.js +0 -104
- 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-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 -307
- package/test/less-test.js +0 -984
- 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/comprehensive.json +0 -1
- package/test/sourcemaps/custom-props.json +0 -1
- package/test/sourcemaps/index.html +0 -17
- package/test/sourcemaps/sourcemaps-basepath.json +0 -1
- package/test/sourcemaps/sourcemaps-include-source.json +0 -1
- package/test/sourcemaps/sourcemaps-rootpath.json +0 -1
- package/test/sourcemaps/sourcemaps-url.json +0 -1
- 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/test.less +0 -1
- package/tsconfig.build.json +0 -7
- package/tsconfig.json +0 -21
|
@@ -1,27 +1,47 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
import Node from './node.js';
|
|
3
|
+
import Element from './element.js';
|
|
4
|
+
import LessError from '../less-error.js';
|
|
5
|
+
import * as utils from '../utils.js';
|
|
6
|
+
import Parser from '../parser/parser.js';
|
|
7
|
+
|
|
8
|
+
/** @import { EvalContext, CSSOutput, FileInfo, VisibilityInfo, TreeVisitor } from './node.js' */
|
|
9
|
+
|
|
10
|
+
class Selector extends Node {
|
|
11
|
+
get type() { return 'Selector'; }
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* @param {(Element | Selector)[] | string} [elements]
|
|
15
|
+
* @param {Node[] | null} [extendList]
|
|
16
|
+
* @param {Node | null} [condition]
|
|
17
|
+
* @param {number} [index]
|
|
18
|
+
* @param {FileInfo} [currentFileInfo]
|
|
19
|
+
* @param {VisibilityInfo} [visibilityInfo]
|
|
20
|
+
*/
|
|
21
|
+
constructor(elements, extendList, condition, index, currentFileInfo, visibilityInfo) {
|
|
22
|
+
super();
|
|
23
|
+
/** @type {Node[] | null | undefined} */
|
|
24
|
+
this.extendList = extendList;
|
|
25
|
+
/** @type {Node | null | undefined} */
|
|
26
|
+
this.condition = condition;
|
|
27
|
+
/** @type {boolean | Node} */
|
|
28
|
+
this.evaldCondition = !condition;
|
|
29
|
+
this._index = index;
|
|
30
|
+
this._fileInfo = currentFileInfo;
|
|
31
|
+
/** @type {Element[]} */
|
|
32
|
+
this.elements = this.getElements(elements);
|
|
33
|
+
/** @type {string[] | undefined} */
|
|
34
|
+
this.mixinElements_ = undefined;
|
|
35
|
+
/** @type {boolean | undefined} */
|
|
36
|
+
this.mediaEmpty = undefined;
|
|
37
|
+
this.copyVisibilityInfo(visibilityInfo);
|
|
38
|
+
this.setParent(this.elements, this);
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
/** @param {TreeVisitor} visitor */
|
|
42
|
+
accept(visitor) {
|
|
23
43
|
if (this.elements) {
|
|
24
|
-
this.elements = visitor.visitArray(this.elements);
|
|
44
|
+
this.elements = /** @type {Element[]} */ (visitor.visitArray(this.elements));
|
|
25
45
|
}
|
|
26
46
|
if (this.extendList) {
|
|
27
47
|
this.extendList = visitor.visitArray(this.extendList);
|
|
@@ -29,99 +49,153 @@ Selector.prototype = Object.assign(new node_1.default(), {
|
|
|
29
49
|
if (this.condition) {
|
|
30
50
|
this.condition = visitor.visit(this.condition);
|
|
31
51
|
}
|
|
32
|
-
}
|
|
33
|
-
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* @param {Element[]} elements
|
|
56
|
+
* @param {Node[] | null} [extendList]
|
|
57
|
+
* @param {boolean | Node} [evaldCondition]
|
|
58
|
+
*/
|
|
59
|
+
createDerived(elements, extendList, evaldCondition) {
|
|
34
60
|
elements = this.getElements(elements);
|
|
35
|
-
|
|
61
|
+
const newSelector = new Selector(elements, extendList || this.extendList,
|
|
62
|
+
null, this.getIndex(), this.fileInfo(), this.visibilityInfo());
|
|
36
63
|
newSelector.evaldCondition = (!utils.isNullOrUndefined(evaldCondition)) ? evaldCondition : this.evaldCondition;
|
|
37
64
|
newSelector.mediaEmpty = this.mediaEmpty;
|
|
38
65
|
return newSelector;
|
|
39
|
-
}
|
|
40
|
-
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* @param {(Element | Selector)[] | string | null | undefined} els
|
|
70
|
+
* @returns {Element[]}
|
|
71
|
+
*/
|
|
72
|
+
getElements(els) {
|
|
41
73
|
if (!els) {
|
|
42
|
-
return [new
|
|
74
|
+
return [new Element('', '&', false, this._index, this._fileInfo)];
|
|
43
75
|
}
|
|
44
76
|
if (typeof els === 'string') {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
77
|
+
const fileInfo = this._fileInfo;
|
|
78
|
+
const parse = this.parse;
|
|
79
|
+
new (/** @type {new (...args: unknown[]) => { parseNode: Function }} */ (/** @type {unknown} */ (Parser)))(parse.context, parse.importManager, fileInfo, this._index).parseNode(
|
|
80
|
+
els,
|
|
81
|
+
['selector'],
|
|
82
|
+
function(/** @type {{ index: number, message: string } | null} */ err, /** @type {Selector[]} */ result) {
|
|
83
|
+
if (err) {
|
|
84
|
+
throw new LessError({
|
|
85
|
+
index: err.index,
|
|
86
|
+
message: err.message
|
|
87
|
+
}, parse.imports, /** @type {string} */ (/** @type {FileInfo} */ (fileInfo).filename));
|
|
88
|
+
}
|
|
89
|
+
els = result[0].elements;
|
|
90
|
+
});
|
|
54
91
|
}
|
|
55
|
-
return els;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
92
|
+
return /** @type {Element[]} */ (els);
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
createEmptySelectors() {
|
|
96
|
+
const el = new Element('', '&', false, this._index, this._fileInfo), sels = [new Selector([el], null, null, this._index, this._fileInfo)];
|
|
59
97
|
sels[0].mediaEmpty = true;
|
|
60
98
|
return sels;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* @param {Selector} other
|
|
103
|
+
* @returns {number}
|
|
104
|
+
*/
|
|
105
|
+
match(other) {
|
|
106
|
+
const elements = this.elements;
|
|
107
|
+
const len = elements.length;
|
|
108
|
+
let olen;
|
|
109
|
+
let i;
|
|
110
|
+
|
|
111
|
+
/** @type {string[]} */
|
|
112
|
+
const mixinEls = other.mixinElements();
|
|
113
|
+
olen = mixinEls.length;
|
|
69
114
|
if (olen === 0 || len < olen) {
|
|
70
115
|
return 0;
|
|
71
|
-
}
|
|
72
|
-
else {
|
|
116
|
+
} else {
|
|
73
117
|
for (i = 0; i < olen; i++) {
|
|
74
|
-
if (elements[i].value !==
|
|
118
|
+
if (elements[i].value !== mixinEls[i]) {
|
|
75
119
|
return 0;
|
|
76
120
|
}
|
|
77
121
|
}
|
|
78
122
|
}
|
|
123
|
+
|
|
79
124
|
return olen; // return number of matched elements
|
|
80
|
-
}
|
|
81
|
-
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** @returns {string[]} */
|
|
128
|
+
mixinElements() {
|
|
82
129
|
if (this.mixinElements_) {
|
|
83
130
|
return this.mixinElements_;
|
|
84
131
|
}
|
|
85
|
-
|
|
86
|
-
|
|
132
|
+
|
|
133
|
+
/** @type {string[] | null} */
|
|
134
|
+
let elements = this.elements.map( function(v) {
|
|
135
|
+
return /** @type {string} */ (v.combinator.value) + (/** @type {{ value: string }} */ (v.value).value || v.value);
|
|
87
136
|
}).join('').match(/[,&#*.\w-]([\w-]|(\\.))*/g);
|
|
137
|
+
|
|
88
138
|
if (elements) {
|
|
89
139
|
if (elements[0] === '&') {
|
|
90
140
|
elements.shift();
|
|
91
141
|
}
|
|
92
|
-
}
|
|
93
|
-
else {
|
|
142
|
+
} else {
|
|
94
143
|
elements = [];
|
|
95
144
|
}
|
|
145
|
+
|
|
96
146
|
return (this.mixinElements_ = elements);
|
|
97
|
-
}
|
|
98
|
-
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
isJustParentSelector() {
|
|
99
150
|
return !this.mediaEmpty &&
|
|
100
151
|
this.elements.length === 1 &&
|
|
101
152
|
this.elements[0].value === '&' &&
|
|
102
153
|
(this.elements[0].combinator.value === ' ' || this.elements[0].combinator.value === '');
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
elements = elements
|
|
109
|
-
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** @param {EvalContext} context */
|
|
157
|
+
eval(context) {
|
|
158
|
+
const evaldCondition = this.condition && this.condition.eval(context);
|
|
159
|
+
let elements = this.elements;
|
|
160
|
+
/** @type {Node[] | null | undefined} */
|
|
161
|
+
let extendList = this.extendList;
|
|
162
|
+
|
|
163
|
+
if (elements) {
|
|
164
|
+
const evaldElements = new Array(elements.length);
|
|
165
|
+
for (let i = 0; i < elements.length; i++) {
|
|
166
|
+
evaldElements[i] = elements[i].eval(context);
|
|
167
|
+
}
|
|
168
|
+
elements = evaldElements;
|
|
169
|
+
}
|
|
170
|
+
if (extendList) {
|
|
171
|
+
const evaldExtends = new Array(extendList.length);
|
|
172
|
+
for (let i = 0; i < extendList.length; i++) {
|
|
173
|
+
evaldExtends[i] = extendList[i].eval(context);
|
|
174
|
+
}
|
|
175
|
+
extendList = evaldExtends;
|
|
176
|
+
}
|
|
177
|
+
|
|
110
178
|
return this.createDerived(elements, extendList, evaldCondition);
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
179
|
+
}
|
|
180
|
+
|
|
181
|
+
/**
|
|
182
|
+
* @param {EvalContext} context
|
|
183
|
+
* @param {CSSOutput} output
|
|
184
|
+
*/
|
|
185
|
+
genCSS(context, output) {
|
|
186
|
+
let i, element;
|
|
187
|
+
if ((!context || !/** @type {EvalContext & { firstSelector?: boolean }} */ (context).firstSelector) && this.elements[0].combinator.value === '') {
|
|
115
188
|
output.add(' ', this.fileInfo(), this.getIndex());
|
|
116
189
|
}
|
|
117
190
|
for (i = 0; i < this.elements.length; i++) {
|
|
118
191
|
element = this.elements[i];
|
|
119
192
|
element.genCSS(context, output);
|
|
120
193
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
getIsOutput() {
|
|
123
197
|
return this.evaldCondition;
|
|
124
198
|
}
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
export default Selector;
|
|
@@ -1,12 +1,14 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
import Node from './node.js';
|
|
3
|
+
|
|
4
|
+
class UnicodeDescriptor extends Node {
|
|
5
|
+
get type() { return 'UnicodeDescriptor'; }
|
|
6
|
+
|
|
7
|
+
/** @param {string} value */
|
|
8
|
+
constructor(value) {
|
|
9
|
+
super();
|
|
10
|
+
this.value = value;
|
|
11
|
+
}
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default UnicodeDescriptor;
|
package/lib/less/tree/unit.js
CHANGED
|
@@ -1,122 +1,170 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
import Node from './node.js';
|
|
3
|
+
import unitConversions from '../data/unit-conversions.js';
|
|
4
|
+
import * as utils from '../utils.js';
|
|
5
|
+
|
|
6
|
+
/** @import { EvalContext, CSSOutput } from './node.js' */
|
|
7
|
+
|
|
8
|
+
class Unit extends Node {
|
|
9
|
+
get type() { return 'Unit'; }
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @param {string[]} [numerator]
|
|
13
|
+
* @param {string[]} [denominator]
|
|
14
|
+
* @param {string} [backupUnit]
|
|
15
|
+
*/
|
|
16
|
+
constructor(numerator, denominator, backupUnit) {
|
|
17
|
+
super();
|
|
18
|
+
/** @type {string[]} */
|
|
19
|
+
this.numerator = numerator ? utils.copyArray(numerator).sort() : [];
|
|
20
|
+
/** @type {string[]} */
|
|
21
|
+
this.denominator = denominator ? utils.copyArray(denominator).sort() : [];
|
|
22
|
+
if (backupUnit) {
|
|
23
|
+
/** @type {string | undefined} */
|
|
24
|
+
this.backupUnit = backupUnit;
|
|
25
|
+
} else if (numerator && numerator.length) {
|
|
26
|
+
this.backupUnit = numerator[0];
|
|
27
|
+
}
|
|
15
28
|
}
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
type: 'Unit',
|
|
19
|
-
clone: function () {
|
|
29
|
+
|
|
30
|
+
clone() {
|
|
20
31
|
return new Unit(utils.copyArray(this.numerator), utils.copyArray(this.denominator), this.backupUnit);
|
|
21
|
-
}
|
|
22
|
-
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* @param {EvalContext} context
|
|
36
|
+
* @param {CSSOutput} output
|
|
37
|
+
*/
|
|
38
|
+
genCSS(context, output) {
|
|
23
39
|
// Dimension checks the unit is singular and throws an error if in strict math mode.
|
|
24
|
-
|
|
40
|
+
const strictUnits = context && context.strictUnits;
|
|
25
41
|
if (this.numerator.length === 1) {
|
|
26
42
|
output.add(this.numerator[0]); // the ideal situation
|
|
27
|
-
}
|
|
28
|
-
else if (!strictUnits && this.backupUnit) {
|
|
43
|
+
} else if (!strictUnits && this.backupUnit) {
|
|
29
44
|
output.add(this.backupUnit);
|
|
30
|
-
}
|
|
31
|
-
else if (!strictUnits && this.denominator.length) {
|
|
45
|
+
} else if (!strictUnits && this.denominator.length) {
|
|
32
46
|
output.add(this.denominator[0]);
|
|
33
47
|
}
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
toString() {
|
|
51
|
+
let i, returnStr = this.numerator.join('*');
|
|
37
52
|
for (i = 0; i < this.denominator.length; i++) {
|
|
38
|
-
returnStr +=
|
|
53
|
+
returnStr += `/${this.denominator[i]}`;
|
|
39
54
|
}
|
|
40
55
|
return returnStr;
|
|
41
|
-
}
|
|
42
|
-
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* @param {Unit} other
|
|
60
|
+
* @returns {0 | undefined}
|
|
61
|
+
*/
|
|
62
|
+
compare(other) {
|
|
43
63
|
return this.is(other.toString()) ? 0 : undefined;
|
|
44
|
-
}
|
|
45
|
-
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** @param {string} unitString */
|
|
67
|
+
is(unitString) {
|
|
46
68
|
return this.toString().toUpperCase() === unitString.toUpperCase();
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
isLength() {
|
|
72
|
+
return RegExp('^(px|em|ex|ch|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'gi').test(this.toCSS(/** @type {import('./node.js').EvalContext} */ ({})));
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
isEmpty() {
|
|
52
76
|
return this.numerator.length === 0 && this.denominator.length === 0;
|
|
53
|
-
}
|
|
54
|
-
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
isSingular() {
|
|
55
80
|
return this.numerator.length <= 1 && this.denominator.length === 0;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/** @param {(atomicUnit: string, denominator: boolean) => string} callback */
|
|
84
|
+
map(callback) {
|
|
85
|
+
let i;
|
|
86
|
+
|
|
59
87
|
for (i = 0; i < this.numerator.length; i++) {
|
|
60
88
|
this.numerator[i] = callback(this.numerator[i], false);
|
|
61
89
|
}
|
|
90
|
+
|
|
62
91
|
for (i = 0; i < this.denominator.length; i++) {
|
|
63
92
|
this.denominator[i] = callback(this.denominator[i], true);
|
|
64
93
|
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/** @returns {{ [groupName: string]: string }} */
|
|
97
|
+
usedUnits() {
|
|
98
|
+
/** @type {{ [unitName: string]: number }} */
|
|
99
|
+
let group;
|
|
100
|
+
/** @type {{ [groupName: string]: string }} */
|
|
101
|
+
const result = {};
|
|
102
|
+
/** @type {(atomicUnit: string) => string} */
|
|
103
|
+
let mapUnit;
|
|
104
|
+
/** @type {string} */
|
|
105
|
+
let groupName;
|
|
106
|
+
|
|
71
107
|
mapUnit = function (atomicUnit) {
|
|
72
108
|
// eslint-disable-next-line no-prototype-builtins
|
|
73
109
|
if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
|
|
74
110
|
result[groupName] = atomicUnit;
|
|
75
111
|
}
|
|
112
|
+
|
|
76
113
|
return atomicUnit;
|
|
77
114
|
};
|
|
78
|
-
|
|
115
|
+
|
|
116
|
+
for (groupName in unitConversions) {
|
|
79
117
|
// eslint-disable-next-line no-prototype-builtins
|
|
80
|
-
if (
|
|
81
|
-
group =
|
|
118
|
+
if (unitConversions.hasOwnProperty(groupName)) {
|
|
119
|
+
group = /** @type {{ [unitName: string]: number }} */ (unitConversions[/** @type {keyof typeof unitConversions} */ (groupName)]);
|
|
120
|
+
|
|
82
121
|
this.map(mapUnit);
|
|
83
122
|
}
|
|
84
123
|
}
|
|
124
|
+
|
|
85
125
|
return result;
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
126
|
+
}
|
|
127
|
+
|
|
128
|
+
cancel() {
|
|
129
|
+
/** @type {{ [unit: string]: number }} */
|
|
130
|
+
const counter = {};
|
|
131
|
+
/** @type {string} */
|
|
132
|
+
let atomicUnit;
|
|
133
|
+
let i;
|
|
134
|
+
|
|
91
135
|
for (i = 0; i < this.numerator.length; i++) {
|
|
92
136
|
atomicUnit = this.numerator[i];
|
|
93
137
|
counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
|
|
94
138
|
}
|
|
139
|
+
|
|
95
140
|
for (i = 0; i < this.denominator.length; i++) {
|
|
96
141
|
atomicUnit = this.denominator[i];
|
|
97
142
|
counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
|
|
98
143
|
}
|
|
144
|
+
|
|
99
145
|
this.numerator = [];
|
|
100
146
|
this.denominator = [];
|
|
147
|
+
|
|
101
148
|
for (atomicUnit in counter) {
|
|
102
149
|
// eslint-disable-next-line no-prototype-builtins
|
|
103
150
|
if (counter.hasOwnProperty(atomicUnit)) {
|
|
104
|
-
|
|
151
|
+
const count = counter[atomicUnit];
|
|
152
|
+
|
|
105
153
|
if (count > 0) {
|
|
106
154
|
for (i = 0; i < count; i++) {
|
|
107
155
|
this.numerator.push(atomicUnit);
|
|
108
156
|
}
|
|
109
|
-
}
|
|
110
|
-
else if (count < 0) {
|
|
157
|
+
} else if (count < 0) {
|
|
111
158
|
for (i = 0; i < -count; i++) {
|
|
112
159
|
this.denominator.push(atomicUnit);
|
|
113
160
|
}
|
|
114
161
|
}
|
|
115
162
|
}
|
|
116
163
|
}
|
|
164
|
+
|
|
117
165
|
this.numerator.sort();
|
|
118
166
|
this.denominator.sort();
|
|
119
167
|
}
|
|
120
|
-
}
|
|
121
|
-
|
|
122
|
-
|
|
168
|
+
}
|
|
169
|
+
|
|
170
|
+
export default Unit;
|
package/lib/less/tree/url.js
CHANGED
|
@@ -1,59 +1,83 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {string} path
|
|
7
|
+
* @returns {string}
|
|
8
|
+
*/
|
|
5
9
|
function escapePath(path) {
|
|
6
|
-
return path.replace(/[()'"\s]/g, function
|
|
10
|
+
return path.replace(/[()'"\s]/g, function(match) { return `\\${match}`; });
|
|
7
11
|
}
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
12
|
+
|
|
13
|
+
class URL extends Node {
|
|
14
|
+
get type() { return 'Url'; }
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* @param {Node} val
|
|
18
|
+
* @param {number} index
|
|
19
|
+
* @param {FileInfo} currentFileInfo
|
|
20
|
+
* @param {boolean} [isEvald]
|
|
21
|
+
*/
|
|
22
|
+
constructor(val, index, currentFileInfo, isEvald) {
|
|
23
|
+
super();
|
|
24
|
+
this.value = val;
|
|
25
|
+
this._index = index;
|
|
26
|
+
this._fileInfo = currentFileInfo;
|
|
27
|
+
/** @type {boolean | undefined} */
|
|
28
|
+
this.isEvald = isEvald;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** @param {TreeVisitor} visitor */
|
|
32
|
+
accept(visitor) {
|
|
33
|
+
this.value = visitor.visit(/** @type {Node} */ (this.value));
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {EvalContext} context
|
|
38
|
+
* @param {CSSOutput} output
|
|
39
|
+
*/
|
|
40
|
+
genCSS(context, output) {
|
|
20
41
|
output.add('url(');
|
|
21
|
-
this.value.genCSS(context, output);
|
|
42
|
+
/** @type {Node} */ (this.value).genCSS(context, output);
|
|
22
43
|
output.add(')');
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** @param {EvalContext} context */
|
|
47
|
+
eval(context) {
|
|
48
|
+
const val = /** @type {Node} */ (this.value).eval(context);
|
|
49
|
+
let rootpath;
|
|
50
|
+
|
|
27
51
|
if (!this.isEvald) {
|
|
28
52
|
// Add the rootpath if the URL requires a rewrite
|
|
29
53
|
rootpath = this.fileInfo() && this.fileInfo().rootpath;
|
|
30
54
|
if (typeof rootpath === 'string' &&
|
|
31
55
|
typeof val.value === 'string' &&
|
|
32
|
-
context.pathRequiresRewrite(val.value)) {
|
|
33
|
-
if (
|
|
56
|
+
context.pathRequiresRewrite(/** @type {string} */ (val.value))) {
|
|
57
|
+
if (!/** @type {import('./quoted.js').default} */ (val).quote) {
|
|
34
58
|
rootpath = escapePath(rootpath);
|
|
35
59
|
}
|
|
36
|
-
val.value = context.rewritePath(val.value, rootpath);
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
val.value = context.normalizePath(val.value);
|
|
60
|
+
val.value = context.rewritePath(/** @type {string} */ (val.value), rootpath);
|
|
61
|
+
} else {
|
|
62
|
+
val.value = context.normalizePath(/** @type {string} */ (val.value));
|
|
40
63
|
}
|
|
64
|
+
|
|
41
65
|
// Add url args if enabled
|
|
42
66
|
if (context.urlArgs) {
|
|
43
|
-
if (
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
if (val.value.indexOf('#') !== -1) {
|
|
47
|
-
val.value = val.value.replace('#',
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
67
|
+
if (!/** @type {string} */ (val.value).match(/^\s*data:/)) {
|
|
68
|
+
const delimiter = /** @type {string} */ (val.value).indexOf('?') === -1 ? '?' : '&';
|
|
69
|
+
const urlArgs = delimiter + context.urlArgs;
|
|
70
|
+
if (/** @type {string} */ (val.value).indexOf('#') !== -1) {
|
|
71
|
+
val.value = /** @type {string} */ (val.value).replace('#', `${urlArgs}#`);
|
|
72
|
+
} else {
|
|
50
73
|
val.value += urlArgs;
|
|
51
74
|
}
|
|
52
75
|
}
|
|
53
76
|
}
|
|
54
77
|
}
|
|
78
|
+
|
|
55
79
|
return new URL(val, this.getIndex(), this.fileInfo(), true);
|
|
56
80
|
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
export default URL;
|