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
package/lib/less/tree/color.js
DELETED
|
@@ -1,285 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import Node from './node.js';
|
|
3
|
-
import colors from '../data/colors.js';
|
|
4
|
-
|
|
5
|
-
/** @import { EvalContext, CSSOutput } from './node.js' */
|
|
6
|
-
|
|
7
|
-
//
|
|
8
|
-
// RGB Colors - #ff0014, #eee
|
|
9
|
-
//
|
|
10
|
-
class Color extends Node {
|
|
11
|
-
get type() { return 'Color'; }
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* @param {number[] | string} rgb
|
|
15
|
-
* @param {number} [a]
|
|
16
|
-
* @param {string} [originalForm]
|
|
17
|
-
*/
|
|
18
|
-
constructor(rgb, a, originalForm) {
|
|
19
|
-
super();
|
|
20
|
-
const self = this;
|
|
21
|
-
//
|
|
22
|
-
// The end goal here, is to parse the arguments
|
|
23
|
-
// into an integer triplet, such as `128, 255, 0`
|
|
24
|
-
//
|
|
25
|
-
// This facilitates operations and conversions.
|
|
26
|
-
//
|
|
27
|
-
if (Array.isArray(rgb)) {
|
|
28
|
-
/** @type {number[]} */
|
|
29
|
-
this.rgb = rgb;
|
|
30
|
-
} else if (rgb.length >= 6) {
|
|
31
|
-
/** @type {number[]} */
|
|
32
|
-
this.rgb = [];
|
|
33
|
-
/** @type {RegExpMatchArray} */ (rgb.match(/.{2}/g)).map(function (c, i) {
|
|
34
|
-
if (i < 3) {
|
|
35
|
-
self.rgb.push(parseInt(c, 16));
|
|
36
|
-
} else {
|
|
37
|
-
self.alpha = (parseInt(c, 16)) / 255;
|
|
38
|
-
}
|
|
39
|
-
});
|
|
40
|
-
} else {
|
|
41
|
-
/** @type {number[]} */
|
|
42
|
-
this.rgb = [];
|
|
43
|
-
rgb.split('').map(function (c, i) {
|
|
44
|
-
if (i < 3) {
|
|
45
|
-
self.rgb.push(parseInt(c + c, 16));
|
|
46
|
-
} else {
|
|
47
|
-
self.alpha = (parseInt(c + c, 16)) / 255;
|
|
48
|
-
}
|
|
49
|
-
});
|
|
50
|
-
}
|
|
51
|
-
/** @type {number} */
|
|
52
|
-
if (typeof this.alpha === 'undefined') {
|
|
53
|
-
this.alpha = (typeof a === 'number') ? a : 1;
|
|
54
|
-
}
|
|
55
|
-
if (typeof originalForm !== 'undefined') {
|
|
56
|
-
this.value = originalForm;
|
|
57
|
-
}
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
luma() {
|
|
61
|
-
let r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255;
|
|
62
|
-
|
|
63
|
-
r = (r <= 0.03928) ? r / 12.92 : Math.pow(((r + 0.055) / 1.055), 2.4);
|
|
64
|
-
g = (g <= 0.03928) ? g / 12.92 : Math.pow(((g + 0.055) / 1.055), 2.4);
|
|
65
|
-
b = (b <= 0.03928) ? b / 12.92 : Math.pow(((b + 0.055) / 1.055), 2.4);
|
|
66
|
-
|
|
67
|
-
return 0.2126 * r + 0.7152 * g + 0.0722 * b;
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* @param {EvalContext} context
|
|
72
|
-
* @param {CSSOutput} output
|
|
73
|
-
*/
|
|
74
|
-
genCSS(context, output) {
|
|
75
|
-
output.add(this.toCSS(context));
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* @param {EvalContext} context
|
|
80
|
-
* @param {boolean} [doNotCompress]
|
|
81
|
-
* @returns {string}
|
|
82
|
-
*/
|
|
83
|
-
toCSS(context, doNotCompress) {
|
|
84
|
-
const compress = context && context.compress && !doNotCompress;
|
|
85
|
-
let color;
|
|
86
|
-
let alpha;
|
|
87
|
-
/** @type {string | undefined} */
|
|
88
|
-
let colorFunction;
|
|
89
|
-
/** @type {(string | number)[]} */
|
|
90
|
-
let args = [];
|
|
91
|
-
|
|
92
|
-
// `value` is set if this color was originally
|
|
93
|
-
// converted from a named color string so we need
|
|
94
|
-
// to respect this and try to output named color too.
|
|
95
|
-
alpha = this.fround(context, this.alpha);
|
|
96
|
-
|
|
97
|
-
if (this.value) {
|
|
98
|
-
if (/** @type {string} */ (this.value).indexOf('rgb') === 0) {
|
|
99
|
-
if (alpha < 1) {
|
|
100
|
-
colorFunction = 'rgba';
|
|
101
|
-
}
|
|
102
|
-
} else if (/** @type {string} */ (this.value).indexOf('hsl') === 0) {
|
|
103
|
-
if (alpha < 1) {
|
|
104
|
-
colorFunction = 'hsla';
|
|
105
|
-
} else {
|
|
106
|
-
colorFunction = 'hsl';
|
|
107
|
-
}
|
|
108
|
-
} else {
|
|
109
|
-
return /** @type {string} */ (this.value);
|
|
110
|
-
}
|
|
111
|
-
} else {
|
|
112
|
-
if (alpha < 1) {
|
|
113
|
-
colorFunction = 'rgba';
|
|
114
|
-
}
|
|
115
|
-
}
|
|
116
|
-
|
|
117
|
-
switch (colorFunction) {
|
|
118
|
-
case 'rgba':
|
|
119
|
-
args = this.rgb.map(function (c) {
|
|
120
|
-
return clamp(Math.round(c), 255);
|
|
121
|
-
}).concat(clamp(alpha, 1));
|
|
122
|
-
break;
|
|
123
|
-
case 'hsla':
|
|
124
|
-
args.push(clamp(alpha, 1));
|
|
125
|
-
// eslint-disable-next-line no-fallthrough
|
|
126
|
-
case 'hsl':
|
|
127
|
-
color = this.toHSL();
|
|
128
|
-
args = [
|
|
129
|
-
this.fround(context, color.h),
|
|
130
|
-
`${this.fround(context, color.s * 100)}%`,
|
|
131
|
-
`${this.fround(context, color.l * 100)}%`
|
|
132
|
-
].concat(args);
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
if (colorFunction) {
|
|
136
|
-
// Values are capped between `0` and `255`, rounded and zero-padded.
|
|
137
|
-
return `${colorFunction}(${args.join(`,${compress ? '' : ' '}`)})`;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
color = this.toRGB();
|
|
141
|
-
|
|
142
|
-
if (compress) {
|
|
143
|
-
const splitcolor = color.split('');
|
|
144
|
-
|
|
145
|
-
// Convert color to short format
|
|
146
|
-
if (splitcolor[1] === splitcolor[2] && splitcolor[3] === splitcolor[4] && splitcolor[5] === splitcolor[6]) {
|
|
147
|
-
color = `#${splitcolor[1]}${splitcolor[3]}${splitcolor[5]}`;
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
return color;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
//
|
|
155
|
-
// Operations have to be done per-channel, if not,
|
|
156
|
-
// channels will spill onto each other. Once we have
|
|
157
|
-
// our result, in the form of an integer triplet,
|
|
158
|
-
// we create a new Color node to hold the result.
|
|
159
|
-
//
|
|
160
|
-
/**
|
|
161
|
-
* @param {EvalContext} context
|
|
162
|
-
* @param {string} op
|
|
163
|
-
* @param {Color} other
|
|
164
|
-
*/
|
|
165
|
-
operate(context, op, other) {
|
|
166
|
-
const rgb = new Array(3);
|
|
167
|
-
const alpha = this.alpha * (1 - other.alpha) + other.alpha;
|
|
168
|
-
for (let c = 0; c < 3; c++) {
|
|
169
|
-
rgb[c] = this._operate(context, op, this.rgb[c], other.rgb[c]);
|
|
170
|
-
}
|
|
171
|
-
return new Color(rgb, alpha);
|
|
172
|
-
}
|
|
173
|
-
|
|
174
|
-
toRGB() {
|
|
175
|
-
return toHex(this.rgb);
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
toHSL() {
|
|
179
|
-
const r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
|
|
180
|
-
|
|
181
|
-
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
182
|
-
/** @type {number} */
|
|
183
|
-
let h;
|
|
184
|
-
let s;
|
|
185
|
-
const l = (max + min) / 2;
|
|
186
|
-
const d = max - min;
|
|
187
|
-
|
|
188
|
-
if (max === min) {
|
|
189
|
-
h = s = 0;
|
|
190
|
-
} else {
|
|
191
|
-
s = l > 0.5 ? d / (2 - max - min) : d / (max + min);
|
|
192
|
-
|
|
193
|
-
switch (max) {
|
|
194
|
-
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
|
195
|
-
case g: h = (b - r) / d + 2; break;
|
|
196
|
-
case b: h = (r - g) / d + 4; break;
|
|
197
|
-
}
|
|
198
|
-
/** @type {number} */ (h) /= 6;
|
|
199
|
-
}
|
|
200
|
-
return { h: /** @type {number} */ (h) * 360, s, l, a };
|
|
201
|
-
}
|
|
202
|
-
|
|
203
|
-
// Adapted from http://mjijackson.com/2008/02/rgb-to-hsl-and-rgb-to-hsv-color-model-conversion-algorithms-in-javascript
|
|
204
|
-
toHSV() {
|
|
205
|
-
const r = this.rgb[0] / 255, g = this.rgb[1] / 255, b = this.rgb[2] / 255, a = this.alpha;
|
|
206
|
-
|
|
207
|
-
const max = Math.max(r, g, b), min = Math.min(r, g, b);
|
|
208
|
-
/** @type {number} */
|
|
209
|
-
let h;
|
|
210
|
-
let s;
|
|
211
|
-
const v = max;
|
|
212
|
-
|
|
213
|
-
const d = max - min;
|
|
214
|
-
if (max === 0) {
|
|
215
|
-
s = 0;
|
|
216
|
-
} else {
|
|
217
|
-
s = d / max;
|
|
218
|
-
}
|
|
219
|
-
|
|
220
|
-
if (max === min) {
|
|
221
|
-
h = 0;
|
|
222
|
-
} else {
|
|
223
|
-
switch (max) {
|
|
224
|
-
case r: h = (g - b) / d + (g < b ? 6 : 0); break;
|
|
225
|
-
case g: h = (b - r) / d + 2; break;
|
|
226
|
-
case b: h = (r - g) / d + 4; break;
|
|
227
|
-
}
|
|
228
|
-
/** @type {number} */ (h) /= 6;
|
|
229
|
-
}
|
|
230
|
-
return { h: /** @type {number} */ (h) * 360, s, v, a };
|
|
231
|
-
}
|
|
232
|
-
|
|
233
|
-
toARGB() {
|
|
234
|
-
return toHex([this.alpha * 255].concat(this.rgb));
|
|
235
|
-
}
|
|
236
|
-
|
|
237
|
-
/**
|
|
238
|
-
* @param {Node & { rgb?: number[], alpha?: number }} x
|
|
239
|
-
* @returns {0 | undefined}
|
|
240
|
-
*/
|
|
241
|
-
compare(x) {
|
|
242
|
-
return (x.rgb &&
|
|
243
|
-
x.rgb[0] === this.rgb[0] &&
|
|
244
|
-
x.rgb[1] === this.rgb[1] &&
|
|
245
|
-
x.rgb[2] === this.rgb[2] &&
|
|
246
|
-
x.alpha === this.alpha) ? 0 : undefined;
|
|
247
|
-
}
|
|
248
|
-
|
|
249
|
-
/** @param {string} keyword */
|
|
250
|
-
static fromKeyword(keyword) {
|
|
251
|
-
/** @type {Color | undefined} */
|
|
252
|
-
let c;
|
|
253
|
-
const key = keyword.toLowerCase();
|
|
254
|
-
// eslint-disable-next-line no-prototype-builtins
|
|
255
|
-
if (colors.hasOwnProperty(key)) {
|
|
256
|
-
c = new Color(/** @type {string} */ (colors[/** @type {keyof typeof colors} */ (key)]).slice(1));
|
|
257
|
-
}
|
|
258
|
-
else if (key === 'transparent') {
|
|
259
|
-
c = new Color([0, 0, 0], 0);
|
|
260
|
-
}
|
|
261
|
-
|
|
262
|
-
if (c) {
|
|
263
|
-
c.value = keyword;
|
|
264
|
-
return c;
|
|
265
|
-
}
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
/**
|
|
270
|
-
* @param {number} v
|
|
271
|
-
* @param {number} max
|
|
272
|
-
*/
|
|
273
|
-
function clamp(v, max) {
|
|
274
|
-
return Math.min(Math.max(v, 0), max);
|
|
275
|
-
}
|
|
276
|
-
|
|
277
|
-
/** @param {number[]} v */
|
|
278
|
-
function toHex(v) {
|
|
279
|
-
return `#${v.map(function (c) {
|
|
280
|
-
c = clamp(Math.round(c), 255);
|
|
281
|
-
return (c < 16 ? '0' : '') + c.toString(16);
|
|
282
|
-
}).join('')}`;
|
|
283
|
-
}
|
|
284
|
-
|
|
285
|
-
export default Color;
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
import Node from './node.js';
|
|
3
|
-
|
|
4
|
-
/** @import { EvalContext, CSSOutput } from './node.js' */
|
|
5
|
-
|
|
6
|
-
/** @type {Record<string, boolean>} */
|
|
7
|
-
const _noSpaceCombinators = {
|
|
8
|
-
'': true,
|
|
9
|
-
' ': true,
|
|
10
|
-
'|': true
|
|
11
|
-
};
|
|
12
|
-
|
|
13
|
-
class Combinator extends Node {
|
|
14
|
-
get type() { return 'Combinator'; }
|
|
15
|
-
|
|
16
|
-
/** @param {string} value */
|
|
17
|
-
constructor(value) {
|
|
18
|
-
super();
|
|
19
|
-
if (value === ' ') {
|
|
20
|
-
this.value = ' ';
|
|
21
|
-
this.emptyOrWhitespace = true;
|
|
22
|
-
} else {
|
|
23
|
-
this.value = value ? value.trim() : '';
|
|
24
|
-
this.emptyOrWhitespace = this.value === '';
|
|
25
|
-
}
|
|
26
|
-
}
|
|
27
|
-
|
|
28
|
-
/**
|
|
29
|
-
* @param {EvalContext} context
|
|
30
|
-
* @param {CSSOutput} output
|
|
31
|
-
*/
|
|
32
|
-
genCSS(context, output) {
|
|
33
|
-
const spaceOrEmpty = (context.compress || _noSpaceCombinators[/** @type {string} */ (this.value)]) ? '' : ' ';
|
|
34
|
-
output.add(spaceOrEmpty + this.value + spaceOrEmpty);
|
|
35
|
-
}
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
export default Combinator;
|
package/lib/less/tree/comment.js
DELETED
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/** @import { EvalContext, CSSOutput, FileInfo } from './node.js' */
|
|
3
|
-
/** @import { DebugInfoContext } from './debug-info.js' */
|
|
4
|
-
import Node from './node.js';
|
|
5
|
-
import getDebugInfo from './debug-info.js';
|
|
6
|
-
|
|
7
|
-
class Comment extends Node {
|
|
8
|
-
get type() { return 'Comment'; }
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* @param {string} value
|
|
12
|
-
* @param {boolean} isLineComment
|
|
13
|
-
* @param {number} index
|
|
14
|
-
* @param {FileInfo} currentFileInfo
|
|
15
|
-
*/
|
|
16
|
-
constructor(value, isLineComment, index, currentFileInfo) {
|
|
17
|
-
super();
|
|
18
|
-
this.value = value;
|
|
19
|
-
this.isLineComment = isLineComment;
|
|
20
|
-
this._index = index;
|
|
21
|
-
this._fileInfo = currentFileInfo;
|
|
22
|
-
this.allowRoot = true;
|
|
23
|
-
/** @type {{ lineNumber: number, fileName: string } | undefined} */
|
|
24
|
-
this.debugInfo = undefined;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
/**
|
|
28
|
-
* @param {EvalContext} context
|
|
29
|
-
* @param {CSSOutput} output
|
|
30
|
-
*/
|
|
31
|
-
genCSS(context, output) {
|
|
32
|
-
if (this.debugInfo) {
|
|
33
|
-
output.add(getDebugInfo(context, /** @type {DebugInfoContext} */ (this)), this.fileInfo(), this.getIndex());
|
|
34
|
-
}
|
|
35
|
-
output.add(/** @type {string} */ (this.value));
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* @param {EvalContext} context
|
|
40
|
-
* @returns {boolean}
|
|
41
|
-
*/
|
|
42
|
-
isSilent(context) {
|
|
43
|
-
const isCompressed = context.compress && /** @type {string} */ (this.value)[2] !== '!';
|
|
44
|
-
return this.isLineComment || isCompressed;
|
|
45
|
-
}
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
export default Comment;
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/** @import { EvalContext, TreeVisitor } from './node.js' */
|
|
3
|
-
import Node from './node.js';
|
|
4
|
-
|
|
5
|
-
class Condition extends Node {
|
|
6
|
-
get type() { return 'Condition'; }
|
|
7
|
-
|
|
8
|
-
/**
|
|
9
|
-
* @param {string} op
|
|
10
|
-
* @param {Node} l
|
|
11
|
-
* @param {Node} r
|
|
12
|
-
* @param {number} i
|
|
13
|
-
* @param {boolean} negate
|
|
14
|
-
*/
|
|
15
|
-
constructor(op, l, r, i, negate) {
|
|
16
|
-
super();
|
|
17
|
-
this.op = op.trim();
|
|
18
|
-
this.lvalue = l;
|
|
19
|
-
this.rvalue = r;
|
|
20
|
-
this._index = i;
|
|
21
|
-
this.negate = negate;
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
/** @param {TreeVisitor} visitor */
|
|
25
|
-
accept(visitor) {
|
|
26
|
-
this.lvalue = visitor.visit(this.lvalue);
|
|
27
|
-
this.rvalue = visitor.visit(this.rvalue);
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* @param {EvalContext} context
|
|
32
|
-
* @returns {boolean}
|
|
33
|
-
* @suppress {checkTypes}
|
|
34
|
-
*/
|
|
35
|
-
// @ts-ignore - Condition.eval returns boolean, not Node (used as guard condition)
|
|
36
|
-
eval(context) {
|
|
37
|
-
const a = this.lvalue.eval(context);
|
|
38
|
-
const b = this.rvalue.eval(context);
|
|
39
|
-
/** @type {boolean} */
|
|
40
|
-
let result;
|
|
41
|
-
|
|
42
|
-
switch (this.op) {
|
|
43
|
-
case 'and': result = Boolean(a && b); break;
|
|
44
|
-
case 'or': result = Boolean(a || b); break;
|
|
45
|
-
default:
|
|
46
|
-
switch (Node.compare(a, b)) {
|
|
47
|
-
case -1:
|
|
48
|
-
result = this.op === '<' || this.op === '=<' || this.op === '<=';
|
|
49
|
-
break;
|
|
50
|
-
case 0:
|
|
51
|
-
result = this.op === '=' || this.op === '>=' || this.op === '=<' || this.op === '<=';
|
|
52
|
-
break;
|
|
53
|
-
case 1:
|
|
54
|
-
result = this.op === '>' || this.op === '>=';
|
|
55
|
-
break;
|
|
56
|
-
default:
|
|
57
|
-
result = false;
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
return this.negate ? !result : result;
|
|
62
|
-
}
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
export default Condition;
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
/** @import { EvalContext, CSSOutput, FileInfo, VisibilityInfo } from './node.js' */
|
|
3
|
-
/** @import { FunctionRegistry, NestableAtRuleThis } from './nested-at-rule.js' */
|
|
4
|
-
import Node from './node.js';
|
|
5
|
-
import Ruleset from './ruleset.js';
|
|
6
|
-
import Value from './value.js';
|
|
7
|
-
import Selector from './selector.js';
|
|
8
|
-
import AtRule from './atrule.js';
|
|
9
|
-
import NestableAtRulePrototype from './nested-at-rule.js';
|
|
10
|
-
|
|
11
|
-
/**
|
|
12
|
-
* @typedef {Ruleset & {
|
|
13
|
-
* allowImports?: boolean,
|
|
14
|
-
* debugInfo?: { lineNumber: number, fileName: string },
|
|
15
|
-
* functionRegistry?: FunctionRegistry
|
|
16
|
-
* }} RulesetWithExtras
|
|
17
|
-
*/
|
|
18
|
-
|
|
19
|
-
class Container extends AtRule {
|
|
20
|
-
get type() { return 'Container'; }
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* @param {Node[] | null} value
|
|
24
|
-
* @param {Node[]} features
|
|
25
|
-
* @param {number} index
|
|
26
|
-
* @param {FileInfo} currentFileInfo
|
|
27
|
-
* @param {VisibilityInfo} visibilityInfo
|
|
28
|
-
*/
|
|
29
|
-
constructor(value, features, index, currentFileInfo, visibilityInfo) {
|
|
30
|
-
super();
|
|
31
|
-
this._index = index;
|
|
32
|
-
this._fileInfo = currentFileInfo;
|
|
33
|
-
|
|
34
|
-
const selectors = (new Selector([], null, null, this._index, this._fileInfo)).createEmptySelectors();
|
|
35
|
-
|
|
36
|
-
/** @type {Value} */
|
|
37
|
-
this.features = new Value(features);
|
|
38
|
-
/** @type {RulesetWithExtras[]} */
|
|
39
|
-
this.rules = [new Ruleset(selectors, value)];
|
|
40
|
-
this.rules[0].allowImports = true;
|
|
41
|
-
this.copyVisibilityInfo(visibilityInfo);
|
|
42
|
-
this.allowRoot = true;
|
|
43
|
-
this.setParent(selectors, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
44
|
-
this.setParent(this.features, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
45
|
-
this.setParent(this.rules, /** @type {Node} */ (/** @type {unknown} */ (this)));
|
|
46
|
-
|
|
47
|
-
/** @type {boolean | undefined} */
|
|
48
|
-
this._evaluated = undefined;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
/**
|
|
52
|
-
* @param {EvalContext} context
|
|
53
|
-
* @param {CSSOutput} output
|
|
54
|
-
*/
|
|
55
|
-
genCSS(context, output) {
|
|
56
|
-
output.add('@container ', this._fileInfo, this._index);
|
|
57
|
-
this.features.genCSS(context, output);
|
|
58
|
-
this.outputRuleset(context, output, this.rules);
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* @param {EvalContext} context
|
|
63
|
-
* @returns {Node}
|
|
64
|
-
*/
|
|
65
|
-
eval(context) {
|
|
66
|
-
if (this._evaluated) {
|
|
67
|
-
return /** @type {Node} */ (/** @type {unknown} */ (this));
|
|
68
|
-
}
|
|
69
|
-
if (!context.mediaBlocks) {
|
|
70
|
-
context.mediaBlocks = [];
|
|
71
|
-
context.mediaPath = [];
|
|
72
|
-
}
|
|
73
|
-
|
|
74
|
-
const media = new Container(null, [], this._index, this._fileInfo, this.visibilityInfo());
|
|
75
|
-
media._evaluated = true;
|
|
76
|
-
if (this.debugInfo) {
|
|
77
|
-
this.rules[0].debugInfo = this.debugInfo;
|
|
78
|
-
media.debugInfo = this.debugInfo;
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
media.features = /** @type {Value} */ (this.features.eval(context));
|
|
82
|
-
|
|
83
|
-
context.mediaPath.push(/** @type {Node} */ (/** @type {unknown} */ (media)));
|
|
84
|
-
context.mediaBlocks.push(/** @type {Node} */ (/** @type {unknown} */ (media)));
|
|
85
|
-
|
|
86
|
-
const fr = /** @type {RulesetWithExtras} */ (context.frames[0]).functionRegistry;
|
|
87
|
-
if (fr) {
|
|
88
|
-
this.rules[0].functionRegistry = fr.inherit();
|
|
89
|
-
}
|
|
90
|
-
context.frames.unshift(this.rules[0]);
|
|
91
|
-
media.rules = [/** @type {RulesetWithExtras} */ (this.rules[0].eval(context))];
|
|
92
|
-
context.frames.shift();
|
|
93
|
-
|
|
94
|
-
context.mediaPath.pop();
|
|
95
|
-
|
|
96
|
-
return context.mediaPath.length === 0 ? /** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (media)).evalTop(context) :
|
|
97
|
-
/** @type {NestableAtRuleThis} */ (/** @type {unknown} */ (media)).evalNested(context);
|
|
98
|
-
}
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
// Apply NestableAtRulePrototype methods (accept, isRulesetLike override AtRule's versions)
|
|
102
|
-
Object.assign(Container.prototype, NestableAtRulePrototype);
|
|
103
|
-
|
|
104
|
-
export default Container;
|
|
@@ -1,80 +0,0 @@
|
|
|
1
|
-
// @ts-check
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* @typedef {object} DebugInfoData
|
|
5
|
-
* @property {number} lineNumber
|
|
6
|
-
* @property {string} fileName
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
/**
|
|
10
|
-
* @typedef {object} DebugInfoContext
|
|
11
|
-
* @property {DebugInfoData} debugInfo
|
|
12
|
-
*/
|
|
13
|
-
|
|
14
|
-
/**
|
|
15
|
-
* @deprecated The dumpLineNumbers option is deprecated. Use sourcemaps instead.
|
|
16
|
-
* This will be removed in a future version.
|
|
17
|
-
*
|
|
18
|
-
* @param {DebugInfoContext} ctx - Context object with debugInfo
|
|
19
|
-
* @returns {string} Debug info as CSS comment
|
|
20
|
-
*/
|
|
21
|
-
function asComment(ctx) {
|
|
22
|
-
return `/* line ${ctx.debugInfo.lineNumber}, ${ctx.debugInfo.fileName} */\n`;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* @deprecated The dumpLineNumbers option is deprecated. Use sourcemaps instead.
|
|
27
|
-
* This function generates Sass-compatible debug info using @media -sass-debug-info syntax.
|
|
28
|
-
* This format had short-lived usage and is no longer recommended.
|
|
29
|
-
* This will be removed in a future version.
|
|
30
|
-
*
|
|
31
|
-
* @param {DebugInfoContext} ctx - Context object with debugInfo
|
|
32
|
-
* @returns {string} Sass-compatible debug info as @media query
|
|
33
|
-
*/
|
|
34
|
-
function asMediaQuery(ctx) {
|
|
35
|
-
let filenameWithProtocol = ctx.debugInfo.fileName;
|
|
36
|
-
if (!/^[a-z]+:\/\//i.test(filenameWithProtocol)) {
|
|
37
|
-
filenameWithProtocol = `file://${filenameWithProtocol}`;
|
|
38
|
-
}
|
|
39
|
-
return `@media -sass-debug-info{filename{font-family:${filenameWithProtocol.replace(/([.:/\\])/g, function (a) {
|
|
40
|
-
if (a == '\\') {
|
|
41
|
-
a = '/';
|
|
42
|
-
}
|
|
43
|
-
return `\\${a}`;
|
|
44
|
-
})}}line{font-family:\\00003${ctx.debugInfo.lineNumber}}}\n`;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
/**
|
|
48
|
-
* Generates debug information (line numbers) for CSS output.
|
|
49
|
-
*
|
|
50
|
-
* @param {{ dumpLineNumbers?: string, compress?: boolean }} context - Context object with dumpLineNumbers option
|
|
51
|
-
* @param {DebugInfoContext} ctx - Context object with debugInfo
|
|
52
|
-
* @param {string} [lineSeparator] - Separator between comment and media query (for 'all' mode)
|
|
53
|
-
* @returns {string} Debug info string
|
|
54
|
-
*
|
|
55
|
-
* @deprecated The dumpLineNumbers option is deprecated. Use sourcemaps instead.
|
|
56
|
-
* All modes ('comments', 'mediaquery', 'all') are deprecated and will be removed in a future version.
|
|
57
|
-
* The 'mediaquery' and 'all' modes generate Sass-compatible @media -sass-debug-info output
|
|
58
|
-
* which had short-lived usage and is no longer recommended.
|
|
59
|
-
*/
|
|
60
|
-
function debugInfo(context, ctx, lineSeparator) {
|
|
61
|
-
let result = '';
|
|
62
|
-
// Some nodes never receive a debugInfo during parsing (e.g. the implicit
|
|
63
|
-
// ruleset of a nested @supports/@document), so there is no line to emit.
|
|
64
|
-
if (context.dumpLineNumbers && !context.compress && ctx.debugInfo) {
|
|
65
|
-
switch (context.dumpLineNumbers) {
|
|
66
|
-
case 'comments':
|
|
67
|
-
result = asComment(ctx);
|
|
68
|
-
break;
|
|
69
|
-
case 'mediaquery':
|
|
70
|
-
result = asMediaQuery(ctx);
|
|
71
|
-
break;
|
|
72
|
-
case 'all':
|
|
73
|
-
result = asComment(ctx) + (lineSeparator || '') + asMediaQuery(ctx);
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
return result;
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
export default debugInfo;
|