less 4.9.0 → 5.0.0-alpha.2
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 +19 -5
- package/bin/lessc +190 -630
- package/dist/less-node.cjs +399 -14570
- package/index.cjs +5 -2
- package/lib/index.js +164 -0
- package/lib/lessc-helper.js +52 -0
- package/lib/logger.js +76 -0
- package/lib/options.d.ts +46 -0
- package/lib/options.js +145 -0
- package/lib/types.js +20 -0
- package/lib/version.js +19 -0
- package/package.json +32 -39
- package/dist/less.cjs +0 -15215
- package/dist/less.js +0 -15215
- package/dist/less.min.js +0 -11
- package/dist/less.min.js.map +0 -1
- package/lib/less/constants.js +0 -13
- package/lib/less/contexts.js +0 -165
- package/lib/less/data/colors.js +0 -150
- package/lib/less/data/index.js +0 -4
- package/lib/less/data/unit-conversions.js +0 -21
- package/lib/less/default-options.js +0 -89
- package/lib/less/deprecation.js +0 -82
- package/lib/less/environment/abstract-file-manager.js +0 -140
- package/lib/less/environment/abstract-plugin-loader.js +0 -185
- package/lib/less/environment/environment-api.ts +0 -21
- package/lib/less/environment/environment.js +0 -59
- package/lib/less/environment/file-manager-api.ts +0 -77
- package/lib/less/functions/boolean.js +0 -29
- package/lib/less/functions/color-blending.js +0 -85
- package/lib/less/functions/color.js +0 -452
- package/lib/less/functions/data-uri.js +0 -74
- package/lib/less/functions/default.js +0 -26
- package/lib/less/functions/function-caller.js +0 -55
- package/lib/less/functions/function-registry.js +0 -36
- package/lib/less/functions/index.js +0 -35
- package/lib/less/functions/list.js +0 -158
- package/lib/less/functions/math-helper.js +0 -22
- package/lib/less/functions/math.js +0 -30
- package/lib/less/functions/number.js +0 -95
- package/lib/less/functions/string.js +0 -39
- package/lib/less/functions/style.js +0 -29
- package/lib/less/functions/svg.js +0 -87
- package/lib/less/functions/types.js +0 -70
- package/lib/less/import-manager.js +0 -183
- package/lib/less/index.js +0 -95
- package/lib/less/less-error.js +0 -166
- package/lib/less/logger.js +0 -34
- package/lib/less/parse-tree.js +0 -124
- package/lib/less/parse.js +0 -87
- package/lib/less/parser/lookup-pattern.js +0 -26
- package/lib/less/parser/parser-input.js +0 -400
- package/lib/less/parser/parser.js +0 -2998
- package/lib/less/plugin-manager.js +0 -168
- package/lib/less/render.js +0 -41
- package/lib/less/source-map-builder.js +0 -82
- package/lib/less/source-map-output.js +0 -151
- package/lib/less/transform-tree.js +0 -102
- package/lib/less/tree/anonymous.js +0 -61
- package/lib/less/tree/assignment.js +0 -48
- package/lib/less/tree/atrule-syntax.js +0 -8
- package/lib/less/tree/atrule.js +0 -340
- package/lib/less/tree/attribute.js +0 -63
- package/lib/less/tree/call.js +0 -132
- package/lib/less/tree/color.js +0 -285
- package/lib/less/tree/combinator.js +0 -38
- package/lib/less/tree/comment.js +0 -48
- package/lib/less/tree/condition.js +0 -65
- package/lib/less/tree/container.js +0 -104
- package/lib/less/tree/debug-info.js +0 -80
- package/lib/less/tree/declaration.js +0 -139
- package/lib/less/tree/detached-ruleset.js +0 -45
- package/lib/less/tree/dimension.js +0 -215
- package/lib/less/tree/element.js +0 -93
- package/lib/less/tree/expression.js +0 -100
- package/lib/less/tree/extend.js +0 -88
- package/lib/less/tree/import.js +0 -299
- package/lib/less/tree/index.js +0 -56
- package/lib/less/tree/interpolated-variable.js +0 -106
- package/lib/less/tree/javascript.js +0 -45
- package/lib/less/tree/js-eval-node.js +0 -80
- package/lib/less/tree/keyword.js +0 -28
- package/lib/less/tree/media.js +0 -90
- package/lib/less/tree/merge-rules.js +0 -47
- package/lib/less/tree/mixin-call.js +0 -283
- package/lib/less/tree/mixin-definition.js +0 -319
- package/lib/less/tree/namespace-value.js +0 -95
- package/lib/less/tree/negative.js +0 -37
- package/lib/less/tree/nested-at-rule.js +0 -239
- package/lib/less/tree/node.js +0 -310
- package/lib/less/tree/operation.js +0 -81
- package/lib/less/tree/paren.js +0 -41
- package/lib/less/tree/property.js +0 -96
- package/lib/less/tree/query-in-parens.js +0 -64
- package/lib/less/tree/quoted.js +0 -131
- package/lib/less/tree/ruleset.js +0 -1068
- package/lib/less/tree/selector.js +0 -201
- package/lib/less/tree/unicode-descriptor.js +0 -14
- package/lib/less/tree/unit.js +0 -170
- package/lib/less/tree/url.js +0 -83
- package/lib/less/tree/value.js +0 -60
- package/lib/less/tree/variable-call.js +0 -60
- package/lib/less/tree/variable.js +0 -85
- package/lib/less/utils.js +0 -126
- package/lib/less/visitors/extend-visitor.js +0 -505
- package/lib/less/visitors/import-sequencer.js +0 -56
- package/lib/less/visitors/import-visitor.js +0 -203
- package/lib/less/visitors/index.js +0 -15
- package/lib/less/visitors/join-selector-visitor.js +0 -65
- package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
- package/lib/less/visitors/to-css-visitor.js +0 -332
- package/lib/less/visitors/visitor.js +0 -165
- package/lib/less-browser/add-default-options.js +0 -53
- package/lib/less-browser/bootstrap.js +0 -67
- package/lib/less-browser/browser.js +0 -65
- package/lib/less-browser/cache.js +0 -43
- package/lib/less-browser/error-reporting.js +0 -170
- package/lib/less-browser/file-manager.js +0 -112
- package/lib/less-browser/image-size.js +0 -28
- package/lib/less-browser/index.js +0 -284
- package/lib/less-browser/log-listener.js +0 -42
- package/lib/less-browser/plugin-loader.js +0 -24
- package/lib/less-browser/utils.js +0 -30
- package/lib/less-node/environment.js +0 -43
- package/lib/less-node/file-manager.js +0 -156
- package/lib/less-node/fs.js +0 -14
- package/lib/less-node/image-size.js +0 -78
- package/lib/less-node/index.js +0 -31
- package/lib/less-node/lessc-helper.js +0 -95
- package/lib/less-node/plugin-loader.js +0 -62
- package/lib/less-node/url-file-manager.js +0 -60
|
@@ -1,201 +0,0 @@
|
|
|
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) {
|
|
43
|
-
if (this.elements) {
|
|
44
|
-
this.elements = /** @type {Element[]} */ (visitor.visitArray(this.elements));
|
|
45
|
-
}
|
|
46
|
-
if (this.extendList) {
|
|
47
|
-
this.extendList = visitor.visitArray(this.extendList);
|
|
48
|
-
}
|
|
49
|
-
if (this.condition) {
|
|
50
|
-
this.condition = visitor.visit(this.condition);
|
|
51
|
-
}
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
/**
|
|
55
|
-
* @param {Element[]} elements
|
|
56
|
-
* @param {Node[] | null} [extendList]
|
|
57
|
-
* @param {boolean | Node} [evaldCondition]
|
|
58
|
-
*/
|
|
59
|
-
createDerived(elements, extendList, evaldCondition) {
|
|
60
|
-
elements = this.getElements(elements);
|
|
61
|
-
const newSelector = new Selector(elements, extendList || this.extendList,
|
|
62
|
-
null, this.getIndex(), this.fileInfo(), this.visibilityInfo());
|
|
63
|
-
newSelector.evaldCondition = (!utils.isNullOrUndefined(evaldCondition)) ? evaldCondition : this.evaldCondition;
|
|
64
|
-
newSelector.mediaEmpty = this.mediaEmpty;
|
|
65
|
-
return newSelector;
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
/**
|
|
69
|
-
* @param {(Element | Selector)[] | string | null | undefined} els
|
|
70
|
-
* @returns {Element[]}
|
|
71
|
-
*/
|
|
72
|
-
getElements(els) {
|
|
73
|
-
if (!els) {
|
|
74
|
-
return [new Element('', '&', false, this._index, this._fileInfo)];
|
|
75
|
-
}
|
|
76
|
-
if (typeof els === 'string') {
|
|
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
|
-
});
|
|
91
|
-
}
|
|
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)];
|
|
97
|
-
sels[0].mediaEmpty = true;
|
|
98
|
-
return sels;
|
|
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;
|
|
114
|
-
if (olen === 0 || len < olen) {
|
|
115
|
-
return 0;
|
|
116
|
-
} else {
|
|
117
|
-
for (i = 0; i < olen; i++) {
|
|
118
|
-
if (elements[i].value !== mixinEls[i]) {
|
|
119
|
-
return 0;
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
return olen; // return number of matched elements
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
/** @returns {string[]} */
|
|
128
|
-
mixinElements() {
|
|
129
|
-
if (this.mixinElements_) {
|
|
130
|
-
return this.mixinElements_;
|
|
131
|
-
}
|
|
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);
|
|
136
|
-
}).join('').match(/[,&#*.\w-]([\w-]|(\\.))*/g);
|
|
137
|
-
|
|
138
|
-
if (elements) {
|
|
139
|
-
if (elements[0] === '&') {
|
|
140
|
-
elements.shift();
|
|
141
|
-
}
|
|
142
|
-
} else {
|
|
143
|
-
elements = [];
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
return (this.mixinElements_ = elements);
|
|
147
|
-
}
|
|
148
|
-
|
|
149
|
-
isJustParentSelector() {
|
|
150
|
-
return !this.mediaEmpty &&
|
|
151
|
-
this.elements.length === 1 &&
|
|
152
|
-
this.elements[0].value === '&' &&
|
|
153
|
-
(this.elements[0].combinator.value === ' ' || this.elements[0].combinator.value === '');
|
|
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
|
-
|
|
178
|
-
return this.createDerived(elements, extendList, evaldCondition);
|
|
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 === '') {
|
|
188
|
-
output.add(' ', this.fileInfo(), this.getIndex());
|
|
189
|
-
}
|
|
190
|
-
for (i = 0; i < this.elements.length; i++) {
|
|
191
|
-
element = this.elements[i];
|
|
192
|
-
element.genCSS(context, output);
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
|
|
196
|
-
getIsOutput() {
|
|
197
|
-
return this.evaldCondition;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
export default Selector;
|
|
@@ -1,14 +0,0 @@
|
|
|
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
DELETED
|
@@ -1,170 +0,0 @@
|
|
|
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
|
-
}
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
clone() {
|
|
31
|
-
return new Unit(utils.copyArray(this.numerator), utils.copyArray(this.denominator), this.backupUnit);
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* @param {EvalContext} context
|
|
36
|
-
* @param {CSSOutput} output
|
|
37
|
-
*/
|
|
38
|
-
genCSS(context, output) {
|
|
39
|
-
// Dimension checks the unit is singular and throws an error if in strict math mode.
|
|
40
|
-
const strictUnits = context && context.strictUnits;
|
|
41
|
-
if (this.numerator.length === 1) {
|
|
42
|
-
output.add(this.numerator[0]); // the ideal situation
|
|
43
|
-
} else if (!strictUnits && this.backupUnit) {
|
|
44
|
-
output.add(this.backupUnit);
|
|
45
|
-
} else if (!strictUnits && this.denominator.length) {
|
|
46
|
-
output.add(this.denominator[0]);
|
|
47
|
-
}
|
|
48
|
-
}
|
|
49
|
-
|
|
50
|
-
toString() {
|
|
51
|
-
let i, returnStr = this.numerator.join('*');
|
|
52
|
-
for (i = 0; i < this.denominator.length; i++) {
|
|
53
|
-
returnStr += `/${this.denominator[i]}`;
|
|
54
|
-
}
|
|
55
|
-
return returnStr;
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
/**
|
|
59
|
-
* @param {Unit} other
|
|
60
|
-
* @returns {0 | undefined}
|
|
61
|
-
*/
|
|
62
|
-
compare(other) {
|
|
63
|
-
return this.is(other.toString()) ? 0 : undefined;
|
|
64
|
-
}
|
|
65
|
-
|
|
66
|
-
/** @param {string} unitString */
|
|
67
|
-
is(unitString) {
|
|
68
|
-
return this.toString().toUpperCase() === unitString.toUpperCase();
|
|
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() {
|
|
76
|
-
return this.numerator.length === 0 && this.denominator.length === 0;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
isSingular() {
|
|
80
|
-
return this.numerator.length <= 1 && this.denominator.length === 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
/** @param {(atomicUnit: string, denominator: boolean) => string} callback */
|
|
84
|
-
map(callback) {
|
|
85
|
-
let i;
|
|
86
|
-
|
|
87
|
-
for (i = 0; i < this.numerator.length; i++) {
|
|
88
|
-
this.numerator[i] = callback(this.numerator[i], false);
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
for (i = 0; i < this.denominator.length; i++) {
|
|
92
|
-
this.denominator[i] = callback(this.denominator[i], true);
|
|
93
|
-
}
|
|
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
|
-
|
|
107
|
-
mapUnit = function (atomicUnit) {
|
|
108
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
109
|
-
if (group.hasOwnProperty(atomicUnit) && !result[groupName]) {
|
|
110
|
-
result[groupName] = atomicUnit;
|
|
111
|
-
}
|
|
112
|
-
|
|
113
|
-
return atomicUnit;
|
|
114
|
-
};
|
|
115
|
-
|
|
116
|
-
for (groupName in unitConversions) {
|
|
117
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
118
|
-
if (unitConversions.hasOwnProperty(groupName)) {
|
|
119
|
-
group = /** @type {{ [unitName: string]: number }} */ (unitConversions[/** @type {keyof typeof unitConversions} */ (groupName)]);
|
|
120
|
-
|
|
121
|
-
this.map(mapUnit);
|
|
122
|
-
}
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
return result;
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
cancel() {
|
|
129
|
-
/** @type {{ [unit: string]: number }} */
|
|
130
|
-
const counter = {};
|
|
131
|
-
/** @type {string} */
|
|
132
|
-
let atomicUnit;
|
|
133
|
-
let i;
|
|
134
|
-
|
|
135
|
-
for (i = 0; i < this.numerator.length; i++) {
|
|
136
|
-
atomicUnit = this.numerator[i];
|
|
137
|
-
counter[atomicUnit] = (counter[atomicUnit] || 0) + 1;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
for (i = 0; i < this.denominator.length; i++) {
|
|
141
|
-
atomicUnit = this.denominator[i];
|
|
142
|
-
counter[atomicUnit] = (counter[atomicUnit] || 0) - 1;
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
this.numerator = [];
|
|
146
|
-
this.denominator = [];
|
|
147
|
-
|
|
148
|
-
for (atomicUnit in counter) {
|
|
149
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
150
|
-
if (counter.hasOwnProperty(atomicUnit)) {
|
|
151
|
-
const count = counter[atomicUnit];
|
|
152
|
-
|
|
153
|
-
if (count > 0) {
|
|
154
|
-
for (i = 0; i < count; i++) {
|
|
155
|
-
this.numerator.push(atomicUnit);
|
|
156
|
-
}
|
|
157
|
-
} else if (count < 0) {
|
|
158
|
-
for (i = 0; i < -count; i++) {
|
|
159
|
-
this.denominator.push(atomicUnit);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
this.numerator.sort();
|
|
166
|
-
this.denominator.sort();
|
|
167
|
-
}
|
|
168
|
-
}
|
|
169
|
-
|
|
170
|
-
export default Unit;
|
package/lib/less/tree/url.js
DELETED
|
@@ -1,83 +0,0 @@
|
|
|
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
|
-
*/
|
|
9
|
-
function escapePath(path) {
|
|
10
|
-
return path.replace(/[()'"\s]/g, function(match) { return `\\${match}`; });
|
|
11
|
-
}
|
|
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) {
|
|
41
|
-
output.add('url(');
|
|
42
|
-
/** @type {Node} */ (this.value).genCSS(context, output);
|
|
43
|
-
output.add(')');
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/** @param {EvalContext} context */
|
|
47
|
-
eval(context) {
|
|
48
|
-
const val = /** @type {Node} */ (this.value).eval(context);
|
|
49
|
-
let rootpath;
|
|
50
|
-
|
|
51
|
-
if (!this.isEvald) {
|
|
52
|
-
// Add the rootpath if the URL requires a rewrite
|
|
53
|
-
rootpath = this.fileInfo() && this.fileInfo().rootpath;
|
|
54
|
-
if (typeof rootpath === 'string' &&
|
|
55
|
-
typeof val.value === 'string' &&
|
|
56
|
-
context.pathRequiresRewrite(/** @type {string} */ (val.value))) {
|
|
57
|
-
if (!/** @type {import('./quoted.js').default} */ (val).quote) {
|
|
58
|
-
rootpath = escapePath(rootpath);
|
|
59
|
-
}
|
|
60
|
-
val.value = context.rewritePath(/** @type {string} */ (val.value), rootpath);
|
|
61
|
-
} else {
|
|
62
|
-
val.value = context.normalizePath(/** @type {string} */ (val.value));
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
// Add url args if enabled
|
|
66
|
-
if (context.urlArgs) {
|
|
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 {
|
|
73
|
-
val.value += urlArgs;
|
|
74
|
-
}
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
return new URL(val, this.getIndex(), this.fileInfo(), true);
|
|
80
|
-
}
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
export default URL;
|
package/lib/less/tree/value.js
DELETED
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/** @import { EvalContext, CSSOutput, TreeVisitor } from './node.js' */
|
|
3
|
-
import Node from './node.js';
|
|
4
|
-
|
|
5
|
-
class Value extends Node {
|
|
6
|
-
get type() { return 'Value'; }
|
|
7
|
-
|
|
8
|
-
/** @param {Node[] | Node} value */
|
|
9
|
-
constructor(value) {
|
|
10
|
-
super();
|
|
11
|
-
if (!value) {
|
|
12
|
-
throw new Error('Value requires an array argument');
|
|
13
|
-
}
|
|
14
|
-
if (!Array.isArray(value)) {
|
|
15
|
-
this.value = [ value ];
|
|
16
|
-
}
|
|
17
|
-
else {
|
|
18
|
-
this.value = value;
|
|
19
|
-
}
|
|
20
|
-
}
|
|
21
|
-
|
|
22
|
-
/** @param {TreeVisitor} visitor */
|
|
23
|
-
accept(visitor) {
|
|
24
|
-
if (this.value) {
|
|
25
|
-
this.value = visitor.visitArray(/** @type {Node[]} */ (this.value));
|
|
26
|
-
}
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
/**
|
|
30
|
-
* @param {EvalContext} context
|
|
31
|
-
* @returns {Node}
|
|
32
|
-
*/
|
|
33
|
-
eval(context) {
|
|
34
|
-
const value = /** @type {Node[]} */ (this.value);
|
|
35
|
-
if (value.length === 1) {
|
|
36
|
-
return value[0].eval(context);
|
|
37
|
-
} else {
|
|
38
|
-
return new Value(value.map(function (v) {
|
|
39
|
-
return v.eval(context);
|
|
40
|
-
}));
|
|
41
|
-
}
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* @param {EvalContext} context
|
|
46
|
-
* @param {CSSOutput} output
|
|
47
|
-
*/
|
|
48
|
-
genCSS(context, output) {
|
|
49
|
-
const value = /** @type {Node[]} */ (this.value);
|
|
50
|
-
let i;
|
|
51
|
-
for (i = 0; i < value.length; i++) {
|
|
52
|
-
value[i].genCSS(context, output);
|
|
53
|
-
if (i + 1 < value.length) {
|
|
54
|
-
output.add((context && context.compress) ? ',' : ', ');
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export default Value;
|
|
@@ -1,60 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/** @import { EvalContext, FileInfo } from './node.js' */
|
|
3
|
-
import Node from './node.js';
|
|
4
|
-
import Variable from './variable.js';
|
|
5
|
-
import Ruleset from './ruleset.js';
|
|
6
|
-
import DetachedRuleset from './detached-ruleset.js';
|
|
7
|
-
import LessError from '../less-error.js';
|
|
8
|
-
|
|
9
|
-
class VariableCall extends Node {
|
|
10
|
-
get type() { return 'VariableCall'; }
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* @param {string} variable
|
|
14
|
-
* @param {number} index
|
|
15
|
-
* @param {FileInfo} currentFileInfo
|
|
16
|
-
*/
|
|
17
|
-
constructor(variable, index, currentFileInfo) {
|
|
18
|
-
super();
|
|
19
|
-
this.variable = variable;
|
|
20
|
-
this._index = index;
|
|
21
|
-
this._fileInfo = currentFileInfo;
|
|
22
|
-
this.allowRoot = true;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @param {EvalContext} context
|
|
27
|
-
* @returns {Node}
|
|
28
|
-
*/
|
|
29
|
-
eval(context) {
|
|
30
|
-
let rules;
|
|
31
|
-
/** @type {DetachedRuleset | Node} */
|
|
32
|
-
let detachedRuleset = new Variable(this.variable, this.getIndex(), this.fileInfo()).eval(context);
|
|
33
|
-
const error = new LessError({message: `Could not evaluate variable call ${this.variable}`});
|
|
34
|
-
|
|
35
|
-
if (!(/** @type {DetachedRuleset} */ (detachedRuleset)).ruleset) {
|
|
36
|
-
const dr = /** @type {Node & { rules?: Node[] }} */ (detachedRuleset);
|
|
37
|
-
if (dr.rules) {
|
|
38
|
-
rules = detachedRuleset;
|
|
39
|
-
}
|
|
40
|
-
else if (Array.isArray(detachedRuleset)) {
|
|
41
|
-
rules = new Ruleset(null, detachedRuleset);
|
|
42
|
-
}
|
|
43
|
-
else if (Array.isArray(detachedRuleset.value)) {
|
|
44
|
-
rules = new Ruleset(null, detachedRuleset.value);
|
|
45
|
-
}
|
|
46
|
-
else {
|
|
47
|
-
throw error;
|
|
48
|
-
}
|
|
49
|
-
detachedRuleset = new DetachedRuleset(rules);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const dr = /** @type {DetachedRuleset} */ (detachedRuleset);
|
|
53
|
-
if (dr.ruleset) {
|
|
54
|
-
return dr.callEval(context);
|
|
55
|
-
}
|
|
56
|
-
throw error;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
export default VariableCall;
|
|
@@ -1,85 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/** @import { EvalContext, FileInfo } from './node.js' */
|
|
3
|
-
import Node from './node.js';
|
|
4
|
-
import Call from './call.js';
|
|
5
|
-
import Ruleset from './ruleset.js';
|
|
6
|
-
|
|
7
|
-
class Variable extends Node {
|
|
8
|
-
get type() { return 'Variable'; }
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {string} name
|
|
12
|
-
* @param {number} [index]
|
|
13
|
-
* @param {FileInfo} [currentFileInfo]
|
|
14
|
-
*/
|
|
15
|
-
constructor(name, index, currentFileInfo) {
|
|
16
|
-
super();
|
|
17
|
-
this.name = name;
|
|
18
|
-
this._index = index;
|
|
19
|
-
this._fileInfo = currentFileInfo;
|
|
20
|
-
/** @type {boolean | undefined} */
|
|
21
|
-
this.evaluating = undefined;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/**
|
|
25
|
-
* @param {EvalContext} context
|
|
26
|
-
* @returns {Node}
|
|
27
|
-
*/
|
|
28
|
-
eval(context) {
|
|
29
|
-
let variable, name = this.name;
|
|
30
|
-
|
|
31
|
-
if (name.indexOf('@@') === 0) {
|
|
32
|
-
name = `@${new Variable(name.slice(1), this.getIndex(), this.fileInfo()).eval(context).value}`;
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (this.evaluating) {
|
|
36
|
-
throw { type: 'Name',
|
|
37
|
-
message: `Recursive variable definition for ${name}`,
|
|
38
|
-
filename: this.fileInfo().filename,
|
|
39
|
-
index: this.getIndex() };
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
this.evaluating = true;
|
|
43
|
-
|
|
44
|
-
variable = this.find(context.frames, function (frame) {
|
|
45
|
-
const v = /** @type {Ruleset} */ (frame).variable(name);
|
|
46
|
-
if (v) {
|
|
47
|
-
if (v.important) {
|
|
48
|
-
const importantScope = context.importantScope[context.importantScope.length - 1];
|
|
49
|
-
importantScope.important = v.important;
|
|
50
|
-
}
|
|
51
|
-
// If in calc, wrap vars in a function call to cascade evaluate args first
|
|
52
|
-
if (context.inCalc) {
|
|
53
|
-
return (new Call('_SELF', [v.value], 0, undefined)).eval(context);
|
|
54
|
-
}
|
|
55
|
-
else {
|
|
56
|
-
return v.value.eval(context);
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
});
|
|
60
|
-
if (variable) {
|
|
61
|
-
this.evaluating = false;
|
|
62
|
-
return variable;
|
|
63
|
-
} else {
|
|
64
|
-
throw { type: 'Name',
|
|
65
|
-
message: `variable ${name} is undefined`,
|
|
66
|
-
filename: this.fileInfo().filename,
|
|
67
|
-
index: this.getIndex() };
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* @param {Node[]} obj
|
|
73
|
-
* @param {(frame: Node) => Node | undefined} fun
|
|
74
|
-
* @returns {Node | null}
|
|
75
|
-
*/
|
|
76
|
-
find(obj, fun) {
|
|
77
|
-
for (let i = 0, r; i < obj.length; i++) {
|
|
78
|
-
r = fun.call(obj, obj[i]);
|
|
79
|
-
if (r) { return r; }
|
|
80
|
-
}
|
|
81
|
-
return null;
|
|
82
|
-
}
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
export default Variable;
|