less 4.5.1 → 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 +37 -23
- package/dist/less.js +14497 -11745
- 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 -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 +25 -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
package/lib/less/tree/atrule.js
CHANGED
|
@@ -1,111 +1,188 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo, VisibilityInfo } from './node.js' */
|
|
3
|
+
/** @import { FunctionRegistry } from './nested-at-rule.js' */
|
|
4
|
+
import Node from './node.js';
|
|
5
|
+
import Selector from './selector.js';
|
|
6
|
+
import Ruleset from './ruleset.js';
|
|
7
|
+
import Anonymous from './anonymous.js';
|
|
8
|
+
import NestableAtRulePrototype from './nested-at-rule.js';
|
|
9
|
+
import mergeRules from './merge-rules.js';
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* @typedef {Node & {
|
|
13
|
+
* rules?: Node[],
|
|
14
|
+
* selectors?: Selector[],
|
|
15
|
+
* root?: boolean,
|
|
16
|
+
* allowImports?: boolean,
|
|
17
|
+
* functionRegistry?: FunctionRegistry,
|
|
18
|
+
* merge?: boolean,
|
|
19
|
+
* debugInfo?: { lineNumber: number, fileName: string },
|
|
20
|
+
* elements?: import('./element.js').default[]
|
|
21
|
+
* }} RulesetLikeNode
|
|
22
|
+
*/
|
|
23
|
+
|
|
24
|
+
class AtRule extends Node {
|
|
25
|
+
get type() { return 'AtRule'; }
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* @param {string} [name]
|
|
29
|
+
* @param {Node | string} [value]
|
|
30
|
+
* @param {Node[] | Ruleset} [rules]
|
|
31
|
+
* @param {number} [index]
|
|
32
|
+
* @param {FileInfo} [currentFileInfo]
|
|
33
|
+
* @param {{ lineNumber: number, fileName: string }} [debugInfo]
|
|
34
|
+
* @param {boolean} [isRooted]
|
|
35
|
+
* @param {VisibilityInfo} [visibilityInfo]
|
|
36
|
+
*/
|
|
37
|
+
constructor(
|
|
38
|
+
name,
|
|
39
|
+
value,
|
|
40
|
+
rules,
|
|
41
|
+
index,
|
|
42
|
+
currentFileInfo,
|
|
43
|
+
debugInfo,
|
|
44
|
+
isRooted,
|
|
45
|
+
visibilityInfo
|
|
46
|
+
) {
|
|
47
|
+
super();
|
|
48
|
+
let i;
|
|
49
|
+
var selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
|
|
50
|
+
|
|
51
|
+
/** @type {string | undefined} */
|
|
52
|
+
this.name = name;
|
|
53
|
+
this.value = (value instanceof Node) ? value : (value ? new Anonymous(value) : value);
|
|
54
|
+
/** @type {boolean | undefined} */
|
|
55
|
+
this.simpleBlock = undefined;
|
|
56
|
+
/** @type {RulesetLikeNode[] | undefined} */
|
|
57
|
+
this.declarations = undefined;
|
|
58
|
+
/** @type {RulesetLikeNode[] | undefined} */
|
|
59
|
+
this.rules = undefined;
|
|
60
|
+
if (rules) {
|
|
61
|
+
if (Array.isArray(rules)) {
|
|
62
|
+
const allDeclarations = this.declarationsBlock(rules);
|
|
63
|
+
|
|
64
|
+
let allRulesetDeclarations = true;
|
|
65
|
+
rules.forEach(rule => {
|
|
66
|
+
if (rule.type === 'Ruleset' && /** @type {RulesetLikeNode} */ (rule).rules) allRulesetDeclarations = allRulesetDeclarations && this.declarationsBlock(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rule).rules), true);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
if (allDeclarations && !isRooted) {
|
|
70
|
+
this.simpleBlock = true;
|
|
71
|
+
this.declarations = rules;
|
|
72
|
+
} else if (allRulesetDeclarations && rules.length === 1 && !isRooted && !value) {
|
|
73
|
+
this.simpleBlock = true;
|
|
74
|
+
this.declarations = /** @type {RulesetLikeNode} */ (rules[0]).rules ? /** @type {RulesetLikeNode} */ (rules[0]).rules : rules;
|
|
75
|
+
} else {
|
|
76
|
+
this.rules = rules;
|
|
77
|
+
}
|
|
78
|
+
} else {
|
|
79
|
+
const allDeclarations = this.declarationsBlock(/** @type {Node[]} */ (rules.rules));
|
|
80
|
+
|
|
81
|
+
if (allDeclarations && !isRooted && !value) {
|
|
82
|
+
this.simpleBlock = true;
|
|
83
|
+
this.declarations = rules.rules;
|
|
84
|
+
} else {
|
|
85
|
+
this.rules = [rules];
|
|
86
|
+
/** @type {RulesetLikeNode} */ (this.rules[0]).selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
|
|
87
|
+
}
|
|
30
88
|
}
|
|
31
|
-
|
|
32
|
-
this.rules
|
|
89
|
+
if (!this.simpleBlock) {
|
|
90
|
+
for (i = 0; i < this.rules.length; i++) {
|
|
91
|
+
/** @type {RulesetLikeNode} */ (this.rules[i]).allowImports = true;
|
|
92
|
+
}
|
|
33
93
|
}
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
var allDeclarations = this.declarationsBlock(rules.rules);
|
|
37
|
-
if (allDeclarations && !isRooted && !value) {
|
|
38
|
-
this.simpleBlock = true;
|
|
39
|
-
this.declarations = rules.rules;
|
|
94
|
+
if (this.declarations) {
|
|
95
|
+
this.setParent(this.declarations, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
40
96
|
}
|
|
41
|
-
|
|
42
|
-
this.rules
|
|
43
|
-
this.rules[0].selectors = (new selector_1.default([], null, null, index, currentFileInfo)).createEmptySelectors();
|
|
97
|
+
if (this.rules) {
|
|
98
|
+
this.setParent(this.rules, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
44
99
|
}
|
|
45
100
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
this.
|
|
52
|
-
this.
|
|
101
|
+
this._index = index;
|
|
102
|
+
this._fileInfo = currentFileInfo;
|
|
103
|
+
/** @type {{ lineNumber: number, fileName: string } | undefined} */
|
|
104
|
+
this.debugInfo = debugInfo;
|
|
105
|
+
/** @type {boolean} */
|
|
106
|
+
this.isRooted = isRooted || false;
|
|
107
|
+
this.copyVisibilityInfo(visibilityInfo);
|
|
108
|
+
this.allowRoot = true;
|
|
53
109
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
AtRule.prototype = Object.assign(new node_1.default(), tslib_1.__assign(tslib_1.__assign({ type: 'AtRule' }, nested_at_rule_1.default), { declarationsBlock: function (rules, mergeable) {
|
|
62
|
-
if (mergeable === void 0) { mergeable = false; }
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* @param {Node[]} rules
|
|
113
|
+
* @param {boolean} [mergeable]
|
|
114
|
+
* @returns {boolean}
|
|
115
|
+
*/
|
|
116
|
+
declarationsBlock(rules, mergeable = false) {
|
|
63
117
|
if (!mergeable) {
|
|
64
|
-
return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment') && !node.merge
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment'); }).length === rules.length;
|
|
118
|
+
return rules.filter(function (/** @type {Node & { merge?: boolean }} */ node) { return (node.type === 'Declaration' || node.type === 'Comment') && !node.merge}).length === rules.length;
|
|
119
|
+
} else {
|
|
120
|
+
return rules.filter(function (/** @type {Node} */ node) { return (node.type === 'Declaration' || node.type === 'Comment'); }).length === rules.length;
|
|
68
121
|
}
|
|
69
|
-
}
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* @param {Node[]} rules
|
|
126
|
+
* @returns {boolean}
|
|
127
|
+
*/
|
|
128
|
+
keywordList(rules) {
|
|
70
129
|
if (!Array.isArray(rules)) {
|
|
71
130
|
return false;
|
|
131
|
+
} else {
|
|
132
|
+
return rules.filter(function (/** @type {Node} */ node) { return (node.type === 'Keyword' || node.type === 'Comment'); }).length === rules.length;
|
|
72
133
|
}
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
134
|
+
}
|
|
135
|
+
|
|
136
|
+
/** @param {TreeVisitor} visitor */
|
|
137
|
+
accept(visitor) {
|
|
138
|
+
const value = this.value, rules = this.rules, declarations = this.declarations;
|
|
139
|
+
|
|
78
140
|
if (rules) {
|
|
79
141
|
this.rules = visitor.visitArray(rules);
|
|
80
|
-
}
|
|
81
|
-
else if (declarations) {
|
|
142
|
+
} else if (declarations) {
|
|
82
143
|
this.declarations = visitor.visitArray(declarations);
|
|
83
144
|
}
|
|
84
145
|
if (value) {
|
|
85
|
-
this.value = visitor.visit(value);
|
|
146
|
+
this.value = visitor.visit(/** @type {Node} */ (value));
|
|
86
147
|
}
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
/** @override @returns {boolean} */
|
|
151
|
+
isRulesetLike() {
|
|
152
|
+
return /** @type {boolean} */ (/** @type {unknown} */ (this.rules || !this.isCharset()));
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
isCharset() {
|
|
90
156
|
return '@charset' === this.name;
|
|
91
|
-
}
|
|
92
|
-
|
|
93
|
-
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
/**
|
|
160
|
+
* @param {EvalContext} context
|
|
161
|
+
* @param {CSSOutput} output
|
|
162
|
+
*/
|
|
163
|
+
genCSS(context, output) {
|
|
164
|
+
const value = this.value, rules = this.rules || this.declarations;
|
|
165
|
+
output.add(/** @type {string} */ (this.name), this.fileInfo(), this.getIndex());
|
|
94
166
|
if (value) {
|
|
95
167
|
output.add(' ');
|
|
96
|
-
value.genCSS(context, output);
|
|
168
|
+
/** @type {Node} */ (value).genCSS(context, output);
|
|
97
169
|
}
|
|
98
170
|
if (this.simpleBlock) {
|
|
99
|
-
this.outputRuleset(context, output, this.declarations);
|
|
100
|
-
}
|
|
101
|
-
else if (rules) {
|
|
171
|
+
this.outputRuleset(context, output, /** @type {Node[]} */ (this.declarations));
|
|
172
|
+
} else if (rules) {
|
|
102
173
|
this.outputRuleset(context, output, rules);
|
|
103
|
-
}
|
|
104
|
-
else {
|
|
174
|
+
} else {
|
|
105
175
|
output.add(';');
|
|
106
176
|
}
|
|
107
|
-
}
|
|
108
|
-
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @param {EvalContext} context
|
|
181
|
+
* @returns {Node}
|
|
182
|
+
*/
|
|
183
|
+
eval(context) {
|
|
184
|
+
let mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules || this.declarations;
|
|
185
|
+
|
|
109
186
|
// media stored inside other atrule should not bubble over it
|
|
110
187
|
// backpup media bubbling information
|
|
111
188
|
mediaPathBackup = context.mediaPath;
|
|
@@ -113,96 +190,120 @@ AtRule.prototype = Object.assign(new node_1.default(), tslib_1.__assign(tslib_1.
|
|
|
113
190
|
// deleted media bubbling information
|
|
114
191
|
context.mediaPath = [];
|
|
115
192
|
context.mediaBlocks = [];
|
|
193
|
+
|
|
116
194
|
if (value) {
|
|
117
|
-
value = value.eval(context);
|
|
118
|
-
if (value.value && this.keywordList(value.value)) {
|
|
119
|
-
value = new anonymous_1.default(value.value.map(function (keyword) { return keyword.value; }).join(', '), this.getIndex(), this.fileInfo());
|
|
120
|
-
}
|
|
195
|
+
value = /** @type {Node} */ (value).eval(context);
|
|
121
196
|
}
|
|
197
|
+
|
|
122
198
|
if (rules) {
|
|
123
199
|
rules = this.evalRoot(context, rules);
|
|
124
200
|
}
|
|
125
|
-
if (Array.isArray(rules) && rules[0].rules && Array.isArray(rules[0].rules) && rules[0].rules.length) {
|
|
126
|
-
|
|
201
|
+
if (Array.isArray(rules) && /** @type {RulesetLikeNode} */ (rules[0]).rules && Array.isArray(/** @type {RulesetLikeNode} */ (rules[0]).rules) && /** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules).length) {
|
|
202
|
+
const allMergeableDeclarations = this.declarationsBlock(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules), true);
|
|
127
203
|
if (allMergeableDeclarations && !this.isRooted && !value) {
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
rules =
|
|
131
|
-
rules.forEach(function (rule) { return rule.merge = false; });
|
|
204
|
+
mergeRules(/** @type {Node[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules));
|
|
205
|
+
rules = /** @type {RulesetLikeNode[]} */ (/** @type {RulesetLikeNode} */ (rules[0]).rules);
|
|
206
|
+
rules.forEach(/** @param {RulesetLikeNode} rule */ rule => { rule.merge = false; });
|
|
132
207
|
}
|
|
133
208
|
}
|
|
134
209
|
if (this.simpleBlock && rules) {
|
|
135
|
-
rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
|
|
136
|
-
rules = rules.map(function (rule) { return rule.eval(context); });
|
|
210
|
+
/** @type {RulesetLikeNode} */ (rules[0]).functionRegistry = /** @type {RulesetLikeNode} */ (context.frames[0]).functionRegistry.inherit();
|
|
211
|
+
rules = rules.map(function (/** @type {Node} */ rule) { return rule.eval(context); });
|
|
137
212
|
}
|
|
213
|
+
|
|
138
214
|
// restore media bubbling information
|
|
139
215
|
context.mediaPath = mediaPathBackup;
|
|
140
216
|
context.mediaBlocks = mediaBlocksBackup;
|
|
141
|
-
return new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
|
|
142
|
-
}
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
217
|
+
return /** @type {Node} */ (/** @type {unknown} */ (new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo())));
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/**
|
|
221
|
+
* @param {EvalContext} context
|
|
222
|
+
* @param {Node[]} rules
|
|
223
|
+
* @returns {Node[]}
|
|
224
|
+
*/
|
|
225
|
+
evalRoot(context, rules) {
|
|
226
|
+
let ampersandCount = 0;
|
|
227
|
+
let noAmpersandCount = 0;
|
|
228
|
+
let noAmpersands = true;
|
|
229
|
+
|
|
147
230
|
if (!this.simpleBlock) {
|
|
148
231
|
rules = [rules[0].eval(context)];
|
|
149
232
|
}
|
|
150
|
-
|
|
233
|
+
|
|
234
|
+
/** @type {Selector[]} */
|
|
235
|
+
let precedingSelectors = [];
|
|
151
236
|
if (context.frames.length > 0) {
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
if (
|
|
237
|
+
for (let index = 0; index < context.frames.length; index++) {
|
|
238
|
+
const frame = /** @type {RulesetLikeNode} */ (context.frames[index]);
|
|
239
|
+
if (
|
|
240
|
+
frame.type === 'Ruleset' &&
|
|
155
241
|
frame.rules &&
|
|
156
|
-
frame.rules.length > 0
|
|
242
|
+
frame.rules.length > 0
|
|
243
|
+
) {
|
|
157
244
|
if (frame && !frame.root && frame.selectors && frame.selectors.length > 0) {
|
|
158
245
|
precedingSelectors = precedingSelectors.concat(frame.selectors);
|
|
159
246
|
}
|
|
160
247
|
}
|
|
161
248
|
if (precedingSelectors.length > 0) {
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
249
|
+
const allAmpersandElements = precedingSelectors.every(
|
|
250
|
+
sel => sel.elements && sel.elements.length > 0 && sel.elements.every(
|
|
251
|
+
/** @param {import('./element.js').default} el */
|
|
252
|
+
el => el.value === '&'
|
|
253
|
+
)
|
|
254
|
+
);
|
|
255
|
+
if (allAmpersandElements) {
|
|
168
256
|
noAmpersands = false;
|
|
169
257
|
noAmpersandCount++;
|
|
170
|
-
}
|
|
171
|
-
else {
|
|
172
|
-
allAmpersands = false;
|
|
258
|
+
} else {
|
|
173
259
|
ampersandCount++;
|
|
174
260
|
}
|
|
175
261
|
}
|
|
176
|
-
};
|
|
177
|
-
for (var index = 0; index < context.frames.length; index++) {
|
|
178
|
-
_loop_1(index);
|
|
179
262
|
}
|
|
180
263
|
}
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
264
|
+
|
|
265
|
+
const mixedAmpersands = ampersandCount > 0 && noAmpersandCount > 0 && !noAmpersands;
|
|
266
|
+
if (
|
|
267
|
+
(this.isRooted && ampersandCount > 0 && noAmpersandCount === 0 && noAmpersands)
|
|
268
|
+
|| !mixedAmpersands
|
|
269
|
+
) {
|
|
270
|
+
/** @type {RulesetLikeNode} */ (rules[0]).root = true;
|
|
185
271
|
}
|
|
186
272
|
return rules;
|
|
187
|
-
}
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/** @param {string} name */
|
|
276
|
+
variable(name) {
|
|
188
277
|
if (this.rules) {
|
|
189
278
|
// assuming that there is only one rule at this point - that is how parser constructs the rule
|
|
190
|
-
return
|
|
279
|
+
return Ruleset.prototype.variable.call(this.rules[0], name);
|
|
191
280
|
}
|
|
192
|
-
}
|
|
281
|
+
}
|
|
282
|
+
|
|
283
|
+
find() {
|
|
193
284
|
if (this.rules) {
|
|
194
285
|
// assuming that there is only one rule at this point - that is how parser constructs the rule
|
|
195
|
-
return
|
|
286
|
+
return Ruleset.prototype.find.apply(this.rules[0], arguments);
|
|
196
287
|
}
|
|
197
|
-
}
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
rulesets() {
|
|
198
291
|
if (this.rules) {
|
|
199
292
|
// assuming that there is only one rule at this point - that is how parser constructs the rule
|
|
200
|
-
return
|
|
293
|
+
return Ruleset.prototype.rulesets.apply(this.rules[0]);
|
|
201
294
|
}
|
|
202
|
-
}
|
|
203
|
-
|
|
204
|
-
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* @param {EvalContext} context
|
|
299
|
+
* @param {CSSOutput} output
|
|
300
|
+
* @param {Node[]} rules
|
|
301
|
+
*/
|
|
302
|
+
outputRuleset(context, output, rules) {
|
|
303
|
+
const ruleCnt = rules.length;
|
|
304
|
+
let i;
|
|
205
305
|
context.tabLevel = (context.tabLevel | 0) + 1;
|
|
306
|
+
|
|
206
307
|
// Compressed
|
|
207
308
|
if (context.compress) {
|
|
208
309
|
output.add('{');
|
|
@@ -213,21 +314,27 @@ AtRule.prototype = Object.assign(new node_1.default(), tslib_1.__assign(tslib_1.
|
|
|
213
314
|
context.tabLevel--;
|
|
214
315
|
return;
|
|
215
316
|
}
|
|
317
|
+
|
|
216
318
|
// Non-compressed
|
|
217
|
-
|
|
319
|
+
const tabSetStr = `\n${Array(context.tabLevel).join(' ')}`, tabRuleStr = `${tabSetStr} `;
|
|
218
320
|
if (!ruleCnt) {
|
|
219
|
-
output.add(
|
|
220
|
-
}
|
|
221
|
-
|
|
222
|
-
output.add(" {".concat(tabRuleStr));
|
|
321
|
+
output.add(` {${tabSetStr}}`);
|
|
322
|
+
} else {
|
|
323
|
+
output.add(` {${tabRuleStr}`);
|
|
223
324
|
rules[0].genCSS(context, output);
|
|
224
325
|
for (i = 1; i < ruleCnt; i++) {
|
|
225
326
|
output.add(tabRuleStr);
|
|
226
327
|
rules[i].genCSS(context, output);
|
|
227
328
|
}
|
|
228
|
-
output.add(
|
|
329
|
+
output.add(`${tabSetStr}}`);
|
|
229
330
|
}
|
|
331
|
+
|
|
230
332
|
context.tabLevel--;
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
|
|
333
|
+
}
|
|
334
|
+
}
|
|
335
|
+
|
|
336
|
+
// Apply shared methods from NestableAtRulePrototype that AtRule doesn't override
|
|
337
|
+
const { evalFunction, evalTop, evalNested, permute, bubbleSelectors } = NestableAtRulePrototype;
|
|
338
|
+
Object.assign(AtRule.prototype, { evalFunction, evalTop, evalNested, permute, bubbleSelectors });
|
|
339
|
+
|
|
340
|
+
export default AtRule;
|
|
@@ -1,32 +1,63 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
}
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
1
|
+
// @ts-check
|
|
2
|
+
/** @import { EvalContext, CSSOutput } from './node.js' */
|
|
3
|
+
import Node from './node.js';
|
|
4
|
+
|
|
5
|
+
class Attribute extends Node {
|
|
6
|
+
get type() { return 'Attribute'; }
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* @param {string | Node} key
|
|
10
|
+
* @param {string} op
|
|
11
|
+
* @param {string | Node} value
|
|
12
|
+
* @param {string} cif
|
|
13
|
+
*/
|
|
14
|
+
constructor(key, op, value, cif) {
|
|
15
|
+
super();
|
|
16
|
+
this.key = key;
|
|
17
|
+
this.op = op;
|
|
18
|
+
this.value = value;
|
|
19
|
+
this.cif = cif;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @param {EvalContext} context
|
|
24
|
+
* @returns {Attribute}
|
|
25
|
+
*/
|
|
26
|
+
eval(context) {
|
|
27
|
+
return new Attribute(
|
|
28
|
+
/** @type {Node} */ (this.key).eval ? /** @type {Node} */ (this.key).eval(context) : /** @type {string} */ (this.key),
|
|
29
|
+
this.op,
|
|
30
|
+
(this.value && /** @type {Node} */ (this.value).eval) ? /** @type {Node} */ (this.value).eval(context) : this.value,
|
|
31
|
+
this.cif
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
* @param {EvalContext} context
|
|
37
|
+
* @param {CSSOutput} output
|
|
38
|
+
*/
|
|
39
|
+
genCSS(context, output) {
|
|
17
40
|
output.add(this.toCSS(context));
|
|
18
|
-
}
|
|
19
|
-
|
|
20
|
-
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* @param {EvalContext} context
|
|
45
|
+
* @returns {string}
|
|
46
|
+
*/
|
|
47
|
+
toCSS(context) {
|
|
48
|
+
let value = /** @type {Node} */ (this.key).toCSS ? /** @type {Node} */ (this.key).toCSS(context) : /** @type {string} */ (this.key);
|
|
49
|
+
|
|
21
50
|
if (this.op) {
|
|
22
51
|
value += this.op;
|
|
23
|
-
value += (this.value.toCSS ? this.value.toCSS(context) : this.value);
|
|
52
|
+
value += (/** @type {Node} */ (this.value).toCSS ? /** @type {Node} */ (this.value).toCSS(context) : /** @type {string} */ (this.value));
|
|
24
53
|
}
|
|
54
|
+
|
|
25
55
|
if (this.cif) {
|
|
26
56
|
value = value + ' ' + this.cif;
|
|
27
57
|
}
|
|
28
|
-
|
|
58
|
+
|
|
59
|
+
return `[${value}]`;
|
|
29
60
|
}
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
export default Attribute;
|