less 4.8.1 → 5.0.0-alpha.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (129) hide show
  1. package/README.md +19 -5
  2. package/bin/lessc +190 -630
  3. package/dist/less-node.cjs +398 -14282
  4. package/index.cjs +5 -2
  5. package/lib/index.js +164 -0
  6. package/lib/lessc-helper.js +52 -0
  7. package/lib/logger.js +76 -0
  8. package/lib/options.d.ts +46 -0
  9. package/lib/options.js +145 -0
  10. package/lib/types.js +20 -0
  11. package/lib/version.js +19 -0
  12. package/package.json +33 -40
  13. package/dist/less.cjs +0 -14929
  14. package/dist/less.js +0 -14929
  15. package/dist/less.min.js +0 -11
  16. package/dist/less.min.js.map +0 -1
  17. package/lib/less/constants.js +0 -13
  18. package/lib/less/contexts.js +0 -165
  19. package/lib/less/data/colors.js +0 -150
  20. package/lib/less/data/index.js +0 -4
  21. package/lib/less/data/unit-conversions.js +0 -21
  22. package/lib/less/default-options.js +0 -89
  23. package/lib/less/deprecation.js +0 -82
  24. package/lib/less/environment/abstract-file-manager.js +0 -140
  25. package/lib/less/environment/abstract-plugin-loader.js +0 -185
  26. package/lib/less/environment/environment-api.ts +0 -21
  27. package/lib/less/environment/environment.js +0 -59
  28. package/lib/less/environment/file-manager-api.ts +0 -77
  29. package/lib/less/functions/boolean.js +0 -29
  30. package/lib/less/functions/color-blending.js +0 -85
  31. package/lib/less/functions/color.js +0 -452
  32. package/lib/less/functions/data-uri.js +0 -74
  33. package/lib/less/functions/default.js +0 -26
  34. package/lib/less/functions/function-caller.js +0 -55
  35. package/lib/less/functions/function-registry.js +0 -36
  36. package/lib/less/functions/index.js +0 -35
  37. package/lib/less/functions/list.js +0 -158
  38. package/lib/less/functions/math-helper.js +0 -22
  39. package/lib/less/functions/math.js +0 -30
  40. package/lib/less/functions/number.js +0 -95
  41. package/lib/less/functions/string.js +0 -36
  42. package/lib/less/functions/style.js +0 -29
  43. package/lib/less/functions/svg.js +0 -87
  44. package/lib/less/functions/types.js +0 -70
  45. package/lib/less/import-manager.js +0 -183
  46. package/lib/less/index.js +0 -95
  47. package/lib/less/less-error.js +0 -166
  48. package/lib/less/logger.js +0 -34
  49. package/lib/less/parse-tree.js +0 -124
  50. package/lib/less/parse.js +0 -87
  51. package/lib/less/parser/parser-input.js +0 -400
  52. package/lib/less/parser/parser.js +0 -2894
  53. package/lib/less/plugin-manager.js +0 -168
  54. package/lib/less/render.js +0 -41
  55. package/lib/less/source-map-builder.js +0 -82
  56. package/lib/less/source-map-output.js +0 -151
  57. package/lib/less/transform-tree.js +0 -102
  58. package/lib/less/tree/anonymous.js +0 -57
  59. package/lib/less/tree/assignment.js +0 -48
  60. package/lib/less/tree/atrule-syntax.js +0 -8
  61. package/lib/less/tree/atrule.js +0 -340
  62. package/lib/less/tree/attribute.js +0 -63
  63. package/lib/less/tree/call.js +0 -132
  64. package/lib/less/tree/color.js +0 -285
  65. package/lib/less/tree/combinator.js +0 -38
  66. package/lib/less/tree/comment.js +0 -48
  67. package/lib/less/tree/condition.js +0 -65
  68. package/lib/less/tree/container.js +0 -104
  69. package/lib/less/tree/debug-info.js +0 -80
  70. package/lib/less/tree/declaration.js +0 -139
  71. package/lib/less/tree/detached-ruleset.js +0 -45
  72. package/lib/less/tree/dimension.js +0 -215
  73. package/lib/less/tree/element.js +0 -93
  74. package/lib/less/tree/expression.js +0 -100
  75. package/lib/less/tree/extend.js +0 -88
  76. package/lib/less/tree/import.js +0 -299
  77. package/lib/less/tree/index.js +0 -56
  78. package/lib/less/tree/javascript.js +0 -45
  79. package/lib/less/tree/js-eval-node.js +0 -74
  80. package/lib/less/tree/keyword.js +0 -28
  81. package/lib/less/tree/media.js +0 -90
  82. package/lib/less/tree/merge-rules.js +0 -47
  83. package/lib/less/tree/mixin-call.js +0 -283
  84. package/lib/less/tree/mixin-definition.js +0 -319
  85. package/lib/less/tree/namespace-value.js +0 -95
  86. package/lib/less/tree/negative.js +0 -37
  87. package/lib/less/tree/nested-at-rule.js +0 -198
  88. package/lib/less/tree/node.js +0 -310
  89. package/lib/less/tree/operation.js +0 -81
  90. package/lib/less/tree/paren.js +0 -41
  91. package/lib/less/tree/property.js +0 -96
  92. package/lib/less/tree/query-in-parens.js +0 -64
  93. package/lib/less/tree/quoted.js +0 -114
  94. package/lib/less/tree/ruleset.js +0 -1066
  95. package/lib/less/tree/selector.js +0 -201
  96. package/lib/less/tree/unicode-descriptor.js +0 -14
  97. package/lib/less/tree/unit.js +0 -170
  98. package/lib/less/tree/url.js +0 -83
  99. package/lib/less/tree/value.js +0 -60
  100. package/lib/less/tree/variable-call.js +0 -60
  101. package/lib/less/tree/variable.js +0 -85
  102. package/lib/less/utils.js +0 -126
  103. package/lib/less/visitors/extend-visitor.js +0 -505
  104. package/lib/less/visitors/import-sequencer.js +0 -56
  105. package/lib/less/visitors/import-visitor.js +0 -203
  106. package/lib/less/visitors/index.js +0 -15
  107. package/lib/less/visitors/join-selector-visitor.js +0 -65
  108. package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
  109. package/lib/less/visitors/to-css-visitor.js +0 -332
  110. package/lib/less/visitors/visitor.js +0 -165
  111. package/lib/less-browser/add-default-options.js +0 -53
  112. package/lib/less-browser/bootstrap.js +0 -67
  113. package/lib/less-browser/browser.js +0 -65
  114. package/lib/less-browser/cache.js +0 -43
  115. package/lib/less-browser/error-reporting.js +0 -170
  116. package/lib/less-browser/file-manager.js +0 -112
  117. package/lib/less-browser/image-size.js +0 -28
  118. package/lib/less-browser/index.js +0 -284
  119. package/lib/less-browser/log-listener.js +0 -42
  120. package/lib/less-browser/plugin-loader.js +0 -24
  121. package/lib/less-browser/utils.js +0 -30
  122. package/lib/less-node/environment.js +0 -43
  123. package/lib/less-node/file-manager.js +0 -156
  124. package/lib/less-node/fs.js +0 -14
  125. package/lib/less-node/image-size.js +0 -78
  126. package/lib/less-node/index.js +0 -31
  127. package/lib/less-node/lessc-helper.js +0 -95
  128. package/lib/less-node/plugin-loader.js +0 -62
  129. package/lib/less-node/url-file-manager.js +0 -60
@@ -1,37 +0,0 @@
1
- // @ts-check
2
- /** @import { EvalContext, CSSOutput } from './node.js' */
3
- import Node from './node.js';
4
- import Operation from './operation.js';
5
- import Dimension from './dimension.js';
6
-
7
- class Negative extends Node {
8
- get type() { return 'Negative'; }
9
-
10
- /** @param {Node} node */
11
- constructor(node) {
12
- super();
13
- this.value = node;
14
- }
15
-
16
- /**
17
- * @param {EvalContext} context
18
- * @param {CSSOutput} output
19
- */
20
- genCSS(context, output) {
21
- output.add('-');
22
- /** @type {Node} */ (this.value).genCSS(context, output);
23
- }
24
-
25
- /**
26
- * @param {EvalContext} context
27
- * @returns {Node}
28
- */
29
- eval(context) {
30
- if (context.isMathOn('*')) {
31
- return (new Operation('*', [new Dimension(-1), /** @type {Node} */ (this.value)], false)).eval(context);
32
- }
33
- return new Negative(/** @type {Node} */ (this.value).eval(context));
34
- }
35
- }
36
-
37
- export default Negative;
@@ -1,198 +0,0 @@
1
- // @ts-check
2
- /** @import { EvalContext, CSSOutput, TreeVisitor, FileInfo, VisibilityInfo } from './node.js' */
3
- import Ruleset from './ruleset.js';
4
- import Value from './value.js';
5
- import Selector from './selector.js';
6
- import Anonymous from './anonymous.js';
7
- import Expression from './expression.js';
8
- import * as utils from '../utils.js';
9
- import Node from './node.js';
10
-
11
- /**
12
- * @typedef {object} FunctionRegistry
13
- * @property {(name: string, func: Function) => void} add
14
- * @property {(functions: Object) => void} addMultiple
15
- * @property {(name: string) => Function} get
16
- * @property {() => Object} getLocalFunctions
17
- * @property {() => FunctionRegistry} inherit
18
- * @property {(base: FunctionRegistry) => FunctionRegistry} create
19
- */
20
-
21
- /**
22
- * @typedef {Node & {
23
- * features: Value,
24
- * rules: Ruleset[],
25
- * type: string,
26
- * functionRegistry?: FunctionRegistry,
27
- * multiMedia?: boolean,
28
- * debugInfo?: { lineNumber: number, fileName: string },
29
- * allowRoot?: boolean,
30
- * _evaluated?: boolean,
31
- * evalFunction: () => void,
32
- * evalTop: (context: EvalContext) => Node | Ruleset,
33
- * evalNested: (context: EvalContext) => Node | Ruleset,
34
- * permute: (arr: Node[][]) => Node[][],
35
- * bubbleSelectors: (selectors: Selector[] | undefined) => void,
36
- * outputRuleset: (context: EvalContext, output: CSSOutput, rules: Node[]) => void
37
- * }} NestableAtRuleThis
38
- */
39
-
40
- const NestableAtRulePrototype = {
41
-
42
- isRulesetLike() {
43
- return true;
44
- },
45
-
46
- /** @param {TreeVisitor} visitor */
47
- accept(visitor) {
48
- /** @type {NestableAtRuleThis} */
49
- const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
50
- if (self.features) {
51
- self.features = /** @type {Value} */ (visitor.visit(self.features));
52
- }
53
- if (self.rules) {
54
- self.rules = /** @type {Ruleset[]} */ (visitor.visitArray(self.rules));
55
- }
56
- },
57
-
58
- evalFunction: function () {
59
- /** @type {NestableAtRuleThis} */
60
- const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
61
- if (!self.features || !Array.isArray(self.features.value) || self.features.value.length < 1) {
62
- return;
63
- }
64
-
65
- const exprValues = /** @type {Node[]} */ (self.features.value);
66
- /** @type {Node | undefined} */
67
- let expr;
68
- /** @type {Node | undefined} */
69
- let paren;
70
-
71
- for (let index = 0; index < exprValues.length; ++index) {
72
- expr = exprValues[index];
73
-
74
- if ((expr.type === 'Keyword' || expr.type === 'Variable')
75
- && index + 1 < exprValues.length
76
- && (/** @type {Node & { noSpacing?: boolean }} */ (expr).noSpacing || /** @type {Node & { noSpacing?: boolean }} */ (expr).noSpacing == null)) {
77
- paren = exprValues[index + 1];
78
-
79
- if (paren.type === 'Paren' && /** @type {Node & { noSpacing?: boolean }} */ (paren).noSpacing) {
80
- exprValues[index]= new Expression([expr, paren]);
81
- exprValues.splice(index + 1, 1);
82
- /** @type {Node & { noSpacing?: boolean }} */ (exprValues[index]).noSpacing = true;
83
- }
84
- }
85
- }
86
- },
87
-
88
- /** @param {EvalContext} context */
89
- evalTop(context) {
90
- /** @type {NestableAtRuleThis} */
91
- const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
92
- self.evalFunction();
93
-
94
- /** @type {Node | Ruleset} */
95
- let result = self;
96
-
97
- // Render all dependent Media blocks.
98
- if (context.mediaBlocks.length > 1) {
99
- const selectors = (new Selector([], null, null, self.getIndex(), self.fileInfo())).createEmptySelectors();
100
- result = new Ruleset(selectors, context.mediaBlocks);
101
- /** @type {Ruleset & { multiMedia?: boolean }} */ (result).multiMedia = true;
102
- result.copyVisibilityInfo(self.visibilityInfo());
103
- self.setParent(result, self);
104
- }
105
-
106
- delete context.mediaBlocks;
107
- delete context.mediaPath;
108
-
109
- return result;
110
- },
111
-
112
- /** @param {EvalContext} context */
113
- evalNested(context) {
114
- /** @type {NestableAtRuleThis} */
115
- const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
116
- self.evalFunction();
117
-
118
- let i;
119
- /** @type {Node | Node[]} */
120
- let value;
121
- const path = context.mediaPath.concat([self]);
122
-
123
- // Extract the media-query conditions separated with `,` (OR).
124
- for (i = 0; i < path.length; i++) {
125
- if (path[i].type !== self.type) {
126
- const blockIndex = context.mediaBlocks.indexOf(self);
127
- if (blockIndex > -1) {
128
- context.mediaBlocks.splice(blockIndex, 1);
129
- }
130
- return self;
131
- }
132
-
133
- value = /** @type {NestableAtRuleThis} */ (path[i]).features instanceof Value ?
134
- /** @type {Node[]} */ (/** @type {NestableAtRuleThis} */ (path[i]).features.value) : /** @type {NestableAtRuleThis} */ (path[i]).features;
135
- path[i] = /** @type {Node} */ (/** @type {unknown} */ (Array.isArray(value) ? value : [value]));
136
- }
137
-
138
- // Trace all permutations to generate the resulting media-query.
139
- //
140
- // (a, b and c) with nested (d, e) ->
141
- // a and d
142
- // a and e
143
- // b and c and d
144
- // b and c and e
145
- self.features = new Value(self.permute(/** @type {Node[][]} */ (/** @type {unknown} */ (path))).map(
146
- /** @param {Node | Node[]} path */
147
- path => {
148
- path = /** @type {Node[]} */ (path).map(
149
- /** @param {Node & { toCSS?: Function }} fragment */
150
- fragment => fragment.toCSS ? fragment : new Anonymous(/** @type {string} */ (/** @type {unknown} */ (fragment))));
151
-
152
- for (i = /** @type {Node[]} */ (path).length - 1; i > 0; i--) {
153
- /** @type {Node[]} */ (path).splice(i, 0, new Anonymous('and'));
154
- }
155
-
156
- return new Expression(/** @type {Node[]} */ (path));
157
- }));
158
- self.setParent(self.features, self);
159
-
160
- // Fake a tree-node that doesn't output anything.
161
- return new Ruleset([], []);
162
- },
163
-
164
- /**
165
- * @param {Node[][]} arr
166
- * @returns {Node[][]}
167
- */
168
- permute(arr) {
169
- if (arr.length === 0) {
170
- return [];
171
- } else if (arr.length === 1) {
172
- return /** @type {Node[][]} */ (/** @type {unknown} */ (arr[0]));
173
- } else {
174
- /** @type {Node[][]} */
175
- const result = [];
176
- const rest = this.permute(arr.slice(1));
177
- for (let i = 0; i < rest.length; i++) {
178
- for (let j = 0; j < arr[0].length; j++) {
179
- result.push([arr[0][j]].concat(rest[i]));
180
- }
181
- }
182
- return result;
183
- }
184
- },
185
-
186
- /** @param {Selector[] | undefined} selectors */
187
- bubbleSelectors(selectors) {
188
- /** @type {NestableAtRuleThis} */
189
- const self = /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (this));
190
- if (!selectors) {
191
- return;
192
- }
193
- self.rules = [new Ruleset(utils.copyArray(selectors), [self.rules[0]])];
194
- self.setParent(self.rules, self);
195
- }
196
- };
197
-
198
- export default NestableAtRulePrototype;
@@ -1,310 +0,0 @@
1
- // @ts-check
2
- /**
3
- * @typedef {object} FileInfo
4
- * @property {string} [filename]
5
- * @property {string} [rootpath]
6
- * @property {string} [currentDirectory]
7
- * @property {string} [rootFilename]
8
- * @property {string} [entryPath]
9
- * @property {boolean} [reference]
10
- */
11
-
12
- /**
13
- * @typedef {object} VisibilityInfo
14
- * @property {number} [visibilityBlocks]
15
- * @property {boolean} [nodeVisible]
16
- */
17
-
18
- /**
19
- * @typedef {object} CSSOutput
20
- * @property {(chunk: string, fileInfo?: FileInfo, index?: number, mapLines?: boolean) => void} add
21
- * @property {() => boolean} isEmpty
22
- */
23
-
24
- /**
25
- * @typedef {object} EvalContext
26
- * @property {number} [numPrecision]
27
- * @property {(op?: string) => boolean} [isMathOn]
28
- * @property {number} [math]
29
- * @property {Node[]} [frames]
30
- * @property {Array<{important?: string}>} [importantScope]
31
- * @property {string[]} [paths]
32
- * @property {boolean} [compress]
33
- * @property {boolean} [strictUnits]
34
- * @property {boolean} [sourceMap]
35
- * @property {boolean} [importMultiple]
36
- * @property {string} [urlArgs]
37
- * @property {boolean} [javascriptEnabled]
38
- * @property {object} [pluginManager]
39
- * @property {number} [rewriteUrls]
40
- * @property {boolean} [inCalc]
41
- * @property {boolean} [mathOn]
42
- * @property {boolean[]} [calcStack]
43
- * @property {boolean[]} [parensStack]
44
- * @property {Node[]} [mediaBlocks]
45
- * @property {Node[]} [mediaPath]
46
- * @property {() => void} [inParenthesis]
47
- * @property {() => void} [outOfParenthesis]
48
- * @property {() => void} [enterCalc]
49
- * @property {() => void} [exitCalc]
50
- * @property {(path: string) => boolean} [pathRequiresRewrite]
51
- * @property {(path: string, rootpath?: string) => string} [rewritePath]
52
- * @property {(path: string) => string} [normalizePath]
53
- * @property {number} [tabLevel]
54
- * @property {boolean} [lastRule]
55
- */
56
-
57
- /**
58
- * @typedef {object} TreeVisitor
59
- * @property {(node: Node) => Node} visit
60
- * @property {(nodes: Node[], nonReplacing?: boolean) => Node[]} visitArray
61
- */
62
-
63
- /**
64
- * The reason why Node is a class and other nodes simply do not extend
65
- * from Node (since we're transpiling) is due to this issue:
66
- *
67
- * @see https://github.com/less/less.js/issues/3434
68
- */
69
- class Node {
70
- get type() { return ''; }
71
-
72
- constructor() {
73
- /** @type {Node | null} */
74
- this.parent = null;
75
- /** @type {number | undefined} */
76
- this.visibilityBlocks = undefined;
77
- /** @type {boolean | undefined} */
78
- this.nodeVisible = undefined;
79
- /** @type {Node | null} */
80
- this.rootNode = null;
81
- /** @type {Node | null} */
82
- this.parsed = null;
83
-
84
- /** @type {Node | Node[] | string | number | undefined} */
85
- this.value = undefined;
86
- /** @type {number | undefined} */
87
- this._index = undefined;
88
- /** @type {FileInfo | undefined} */
89
- this._fileInfo = undefined;
90
- }
91
-
92
- get currentFileInfo() {
93
- return this.fileInfo();
94
- }
95
-
96
- get index() {
97
- return this.getIndex();
98
- }
99
-
100
- /**
101
- * @param {Node | Node[]} nodes
102
- * @param {Node} parent
103
- */
104
- setParent(nodes, parent) {
105
- /** @param {Node} node */
106
- function set(node) {
107
- if (node && node instanceof Node) {
108
- node.parent = parent;
109
- }
110
- }
111
- if (Array.isArray(nodes)) {
112
- nodes.forEach(set);
113
- }
114
- else {
115
- set(nodes);
116
- }
117
- }
118
-
119
- /** @returns {number} */
120
- getIndex() {
121
- return this._index || (this.parent && this.parent.getIndex()) || 0;
122
- }
123
-
124
- /** @returns {FileInfo} */
125
- fileInfo() {
126
- return this._fileInfo || (this.parent && this.parent.fileInfo()) || {};
127
- }
128
-
129
- /** @returns {boolean} */
130
- isRulesetLike() { return false; }
131
-
132
- /**
133
- * @param {EvalContext} context
134
- * @returns {string}
135
- */
136
- toCSS(context) {
137
- /** @type {string[]} */
138
- const strs = [];
139
- this.genCSS(context, {
140
- add: function(chunk, fileInfo, index) {
141
- strs.push(chunk);
142
- },
143
- isEmpty: function () {
144
- return strs.length === 0;
145
- }
146
- });
147
- return strs.join('');
148
- }
149
-
150
- /**
151
- * @param {EvalContext} context
152
- * @param {CSSOutput} output
153
- */
154
- genCSS(context, output) {
155
- output.add(/** @type {string} */ (this.value));
156
- }
157
-
158
- /**
159
- * @param {TreeVisitor} visitor
160
- */
161
- accept(visitor) {
162
- this.value = visitor.visit(/** @type {Node} */ (this.value));
163
- }
164
-
165
- /**
166
- * @param {EvalContext} [context]
167
- * @returns {Node}
168
- */
169
- eval(context) { return this; }
170
-
171
- /**
172
- * @param {EvalContext} context
173
- * @param {string} op
174
- * @param {number} a
175
- * @param {number} b
176
- * @returns {number | undefined}
177
- */
178
- _operate(context, op, a, b) {
179
- switch (op) {
180
- case '+': return a + b;
181
- case '-': return a - b;
182
- case '*': return a * b;
183
- case '/': return a / b;
184
- }
185
- }
186
-
187
- /**
188
- * @param {EvalContext} context
189
- * @param {number} value
190
- * @returns {number}
191
- */
192
- fround(context, value) {
193
- const precision = context && context.numPrecision;
194
- // add "epsilon" to ensure numbers like 1.000000005 (represented as 1.000000004999...) are properly rounded:
195
- return (precision) ? Number((value + 2e-16).toFixed(precision)) : value;
196
- }
197
-
198
- /**
199
- * @param {Node & { compare?: (other: Node) => number | undefined }} a
200
- * @param {Node & { compare?: (other: Node) => number | undefined }} b
201
- * @returns {number | undefined}
202
- */
203
- static compare(a, b) {
204
- /* returns:
205
- -1: a < b
206
- 0: a = b
207
- 1: a > b
208
- and *any* other value for a != b (e.g. undefined, NaN, -2 etc.) */
209
-
210
- if ((a.compare) &&
211
- // for "symmetric results" force toCSS-based comparison
212
- // of Quoted or Anonymous if either value is one of those
213
- !(b.type === 'Quoted' || b.type === 'Anonymous')) {
214
- return a.compare(b);
215
- } else if (b.compare) {
216
- return -b.compare(a);
217
- } else if (a.type !== b.type) {
218
- return undefined;
219
- }
220
-
221
- let aVal = a.value;
222
- let bVal = b.value;
223
- if (!Array.isArray(aVal)) {
224
- return aVal === bVal ? 0 : undefined;
225
- }
226
- if (!Array.isArray(bVal)) {
227
- return undefined;
228
- }
229
- if (aVal.length !== bVal.length) {
230
- return undefined;
231
- }
232
- for (let i = 0; i < aVal.length; i++) {
233
- if (Node.compare(aVal[i], bVal[i]) !== 0) {
234
- return undefined;
235
- }
236
- }
237
- return 0;
238
- }
239
-
240
- /**
241
- * @param {number | string} a
242
- * @param {number | string} b
243
- * @returns {number | undefined}
244
- */
245
- static numericCompare(a, b) {
246
- return a < b ? -1
247
- : a === b ? 0
248
- : a > b ? 1 : undefined;
249
- }
250
-
251
- /** @returns {boolean} */
252
- blocksVisibility() {
253
- if (this.visibilityBlocks === undefined) {
254
- this.visibilityBlocks = 0;
255
- }
256
- return this.visibilityBlocks !== 0;
257
- }
258
-
259
- addVisibilityBlock() {
260
- if (this.visibilityBlocks === undefined) {
261
- this.visibilityBlocks = 0;
262
- }
263
- this.visibilityBlocks = this.visibilityBlocks + 1;
264
- }
265
-
266
- removeVisibilityBlock() {
267
- if (this.visibilityBlocks === undefined) {
268
- this.visibilityBlocks = 0;
269
- }
270
- this.visibilityBlocks = this.visibilityBlocks - 1;
271
- }
272
-
273
- ensureVisibility() {
274
- this.nodeVisible = true;
275
- }
276
-
277
- ensureInvisibility() {
278
- this.nodeVisible = false;
279
- }
280
-
281
- /** @returns {boolean | undefined} */
282
- isVisible() {
283
- return this.nodeVisible;
284
- }
285
-
286
- /** @returns {VisibilityInfo} */
287
- visibilityInfo() {
288
- return {
289
- visibilityBlocks: this.visibilityBlocks,
290
- nodeVisible: this.nodeVisible
291
- };
292
- }
293
-
294
- /** @param {VisibilityInfo} info */
295
- copyVisibilityInfo(info) {
296
- if (!info) {
297
- return;
298
- }
299
- this.visibilityBlocks = info.visibilityBlocks;
300
- this.nodeVisible = info.nodeVisible;
301
- }
302
- }
303
-
304
- /**
305
- * Set by the parser at runtime on Node.prototype.
306
- * @type {{ context: EvalContext, importManager: object, imports: object } | undefined}
307
- */
308
- Node.prototype.parse = undefined;
309
-
310
- export default Node;
@@ -1,81 +0,0 @@
1
- // @ts-check
2
- /** @import { EvalContext, CSSOutput, TreeVisitor } from './node.js' */
3
- import Node from './node.js';
4
- import Color from './color.js';
5
- import Dimension from './dimension.js';
6
- import * as Constants from '../constants.js';
7
- const MATH = Constants.Math;
8
-
9
- class Operation extends Node {
10
- get type() { return 'Operation'; }
11
-
12
- /**
13
- * @param {string} op
14
- * @param {Node[]} operands
15
- * @param {boolean} isSpaced
16
- */
17
- constructor(op, operands, isSpaced) {
18
- super();
19
- this.op = op.trim();
20
- this.operands = operands;
21
- this.isSpaced = isSpaced;
22
- }
23
-
24
- /** @param {TreeVisitor} visitor */
25
- accept(visitor) {
26
- this.operands = visitor.visitArray(this.operands);
27
- }
28
-
29
- /**
30
- * @param {EvalContext} context
31
- * @returns {Node}
32
- */
33
- eval(context) {
34
- let a = this.operands[0].eval(context), b = this.operands[1].eval(context), op;
35
-
36
- if (context.isMathOn(this.op)) {
37
- op = this.op === './' ? '/' : this.op;
38
- if (a instanceof Dimension && b instanceof Color) {
39
- a = /** @type {Dimension} */ (a).toColor();
40
- }
41
- if (b instanceof Dimension && a instanceof Color) {
42
- b = /** @type {Dimension} */ (b).toColor();
43
- }
44
- if (!/** @type {Dimension | Color} */ (a).operate || !/** @type {Dimension | Color} */ (b).operate) {
45
- if (
46
- (a instanceof Operation || b instanceof Operation)
47
- && /** @type {Operation} */ (a).op === '/' && context.math === MATH.PARENS_DIVISION
48
- ) {
49
- return new Operation(this.op, [a, b], this.isSpaced);
50
- }
51
- throw { type: 'Operation',
52
- message: 'Operation on an invalid type' };
53
- }
54
-
55
- if (a instanceof Dimension) {
56
- return a.operate(context, op, /** @type {Dimension} */ (b));
57
- }
58
- return /** @type {Color} */ (a).operate(context, op, /** @type {Color} */ (b));
59
- } else {
60
- return new Operation(this.op, [a, b], this.isSpaced);
61
- }
62
- }
63
-
64
- /**
65
- * @param {EvalContext} context
66
- * @param {CSSOutput} output
67
- */
68
- genCSS(context, output) {
69
- this.operands[0].genCSS(context, output);
70
- if (this.isSpaced) {
71
- output.add(' ');
72
- }
73
- output.add(this.op);
74
- if (this.isSpaced) {
75
- output.add(' ');
76
- }
77
- this.operands[1].genCSS(context, output);
78
- }
79
- }
80
-
81
- export default Operation;
@@ -1,41 +0,0 @@
1
- // @ts-check
2
- /** @import { EvalContext, CSSOutput } from './node.js' */
3
- import Node from './node.js';
4
-
5
- class Paren extends Node {
6
- get type() { return 'Paren'; }
7
-
8
- /** @param {Node} node */
9
- constructor(node) {
10
- super();
11
- this.value = node;
12
- /** @type {boolean | undefined} */
13
- this.noSpacing = undefined;
14
- }
15
-
16
- /**
17
- * @param {EvalContext} context
18
- * @param {CSSOutput} output
19
- */
20
- genCSS(context, output) {
21
- output.add('(');
22
- /** @type {Node} */ (this.value).genCSS(context, output);
23
- output.add(')');
24
- }
25
-
26
- /**
27
- * @param {EvalContext} context
28
- * @returns {Paren}
29
- */
30
- eval(context) {
31
- const paren = new Paren(/** @type {Node} */ (this.value).eval(context));
32
-
33
- if (this.noSpacing) {
34
- paren.noSpacing = true;
35
- }
36
-
37
- return paren;
38
- }
39
- }
40
-
41
- export default Paren;