less 4.9.0 → 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 (131) hide show
  1. package/README.md +19 -5
  2. package/bin/lessc +190 -630
  3. package/dist/less-node.cjs +399 -14570
  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 +34 -40
  13. package/dist/less.cjs +0 -15215
  14. package/dist/less.js +0 -15215
  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 -39
  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/lookup-pattern.js +0 -26
  52. package/lib/less/parser/parser-input.js +0 -400
  53. package/lib/less/parser/parser.js +0 -2998
  54. package/lib/less/plugin-manager.js +0 -168
  55. package/lib/less/render.js +0 -41
  56. package/lib/less/source-map-builder.js +0 -82
  57. package/lib/less/source-map-output.js +0 -151
  58. package/lib/less/transform-tree.js +0 -102
  59. package/lib/less/tree/anonymous.js +0 -61
  60. package/lib/less/tree/assignment.js +0 -48
  61. package/lib/less/tree/atrule-syntax.js +0 -8
  62. package/lib/less/tree/atrule.js +0 -340
  63. package/lib/less/tree/attribute.js +0 -63
  64. package/lib/less/tree/call.js +0 -132
  65. package/lib/less/tree/color.js +0 -285
  66. package/lib/less/tree/combinator.js +0 -38
  67. package/lib/less/tree/comment.js +0 -48
  68. package/lib/less/tree/condition.js +0 -65
  69. package/lib/less/tree/container.js +0 -104
  70. package/lib/less/tree/debug-info.js +0 -80
  71. package/lib/less/tree/declaration.js +0 -139
  72. package/lib/less/tree/detached-ruleset.js +0 -45
  73. package/lib/less/tree/dimension.js +0 -215
  74. package/lib/less/tree/element.js +0 -93
  75. package/lib/less/tree/expression.js +0 -100
  76. package/lib/less/tree/extend.js +0 -88
  77. package/lib/less/tree/import.js +0 -299
  78. package/lib/less/tree/index.js +0 -56
  79. package/lib/less/tree/interpolated-variable.js +0 -106
  80. package/lib/less/tree/javascript.js +0 -45
  81. package/lib/less/tree/js-eval-node.js +0 -80
  82. package/lib/less/tree/keyword.js +0 -28
  83. package/lib/less/tree/media.js +0 -90
  84. package/lib/less/tree/merge-rules.js +0 -47
  85. package/lib/less/tree/mixin-call.js +0 -283
  86. package/lib/less/tree/mixin-definition.js +0 -319
  87. package/lib/less/tree/namespace-value.js +0 -95
  88. package/lib/less/tree/negative.js +0 -37
  89. package/lib/less/tree/nested-at-rule.js +0 -239
  90. package/lib/less/tree/node.js +0 -310
  91. package/lib/less/tree/operation.js +0 -81
  92. package/lib/less/tree/paren.js +0 -41
  93. package/lib/less/tree/property.js +0 -96
  94. package/lib/less/tree/query-in-parens.js +0 -64
  95. package/lib/less/tree/quoted.js +0 -131
  96. package/lib/less/tree/ruleset.js +0 -1068
  97. package/lib/less/tree/selector.js +0 -201
  98. package/lib/less/tree/unicode-descriptor.js +0 -14
  99. package/lib/less/tree/unit.js +0 -170
  100. package/lib/less/tree/url.js +0 -83
  101. package/lib/less/tree/value.js +0 -60
  102. package/lib/less/tree/variable-call.js +0 -60
  103. package/lib/less/tree/variable.js +0 -85
  104. package/lib/less/utils.js +0 -126
  105. package/lib/less/visitors/extend-visitor.js +0 -505
  106. package/lib/less/visitors/import-sequencer.js +0 -56
  107. package/lib/less/visitors/import-visitor.js +0 -203
  108. package/lib/less/visitors/index.js +0 -15
  109. package/lib/less/visitors/join-selector-visitor.js +0 -65
  110. package/lib/less/visitors/set-tree-visibility-visitor.js +0 -57
  111. package/lib/less/visitors/to-css-visitor.js +0 -332
  112. package/lib/less/visitors/visitor.js +0 -165
  113. package/lib/less-browser/add-default-options.js +0 -53
  114. package/lib/less-browser/bootstrap.js +0 -67
  115. package/lib/less-browser/browser.js +0 -65
  116. package/lib/less-browser/cache.js +0 -43
  117. package/lib/less-browser/error-reporting.js +0 -170
  118. package/lib/less-browser/file-manager.js +0 -112
  119. package/lib/less-browser/image-size.js +0 -28
  120. package/lib/less-browser/index.js +0 -284
  121. package/lib/less-browser/log-listener.js +0 -42
  122. package/lib/less-browser/plugin-loader.js +0 -24
  123. package/lib/less-browser/utils.js +0 -30
  124. package/lib/less-node/environment.js +0 -43
  125. package/lib/less-node/file-manager.js +0 -156
  126. package/lib/less-node/fs.js +0 -14
  127. package/lib/less-node/image-size.js +0 -78
  128. package/lib/less-node/index.js +0 -31
  129. package/lib/less-node/lessc-helper.js +0 -95
  130. package/lib/less-node/plugin-loader.js +0 -62
  131. package/lib/less-node/url-file-manager.js +0 -60
@@ -1,452 +0,0 @@
1
- import Dimension from '../tree/dimension.js';
2
- import Color from '../tree/color.js';
3
- import Quoted from '../tree/quoted.js';
4
- import Anonymous from '../tree/anonymous.js';
5
- import Expression from '../tree/expression.js';
6
- import Operation from '../tree/operation.js';
7
- let colorFunctions;
8
-
9
- function clamp(val) {
10
- return Math.min(1, Math.max(0, val));
11
- }
12
- function hsla(origColor, hsl) {
13
- const color = colorFunctions.hsla(hsl.h, hsl.s, hsl.l, hsl.a);
14
- if (color) {
15
- if (origColor.value &&
16
- /^(rgb|hsl)/.test(origColor.value)) {
17
- color.value = origColor.value;
18
- } else {
19
- color.value = 'rgb';
20
- }
21
- return color;
22
- }
23
- }
24
- function toHSL(color) {
25
- if (color.toHSL) {
26
- return color.toHSL();
27
- } else {
28
- throw new Error('Argument cannot be evaluated to a color');
29
- }
30
- }
31
-
32
- function toHSV(color) {
33
- if (color.toHSV) {
34
- return color.toHSV();
35
- } else {
36
- throw new Error('Argument cannot be evaluated to a color');
37
- }
38
- }
39
-
40
- function number(n) {
41
- if (n instanceof Dimension) {
42
- return parseFloat(n.unit.is('%') ? n.value / 100 : n.value);
43
- } else if (typeof n === 'number') {
44
- return n;
45
- } else {
46
- throw {
47
- type: 'Argument',
48
- message: 'color functions take numbers as parameters'
49
- };
50
- }
51
- }
52
- function scaled(n, size) {
53
- if (n instanceof Dimension && n.unit.is('%')) {
54
- return parseFloat(n.value * size / 100);
55
- } else {
56
- return number(n);
57
- }
58
- }
59
- colorFunctions = {
60
- rgb: function (r, g, b) {
61
- let a = 1
62
- /**
63
- * Comma-less syntax
64
- * e.g. rgb(0 128 255 / 50%)
65
- */
66
- if (r instanceof Expression) {
67
- const val = r.value
68
- r = val[0]
69
- g = val[1]
70
- b = val[2]
71
- /**
72
- * @todo - should this be normalized in
73
- * function caller? Or parsed differently?
74
- */
75
- if (b instanceof Operation) {
76
- const op = b
77
- b = op.operands[0]
78
- a = op.operands[1]
79
- }
80
- }
81
- const color = colorFunctions.rgba(r, g, b, a);
82
- if (color) {
83
- color.value = 'rgb';
84
- return color;
85
- }
86
- },
87
- rgba: function (r, g, b, a) {
88
- try {
89
- if (r instanceof Color) {
90
- if (g) {
91
- a = number(g);
92
- } else {
93
- a = r.alpha;
94
- }
95
- return new Color(r.rgb, a, 'rgba');
96
- }
97
- const rgb = [r, g, b].map(c => scaled(c, 255));
98
- a = number(a);
99
- return new Color(rgb, a, 'rgba');
100
- }
101
- catch (e) {}
102
- },
103
- hsl: function (h, s, l) {
104
- let a = 1
105
- if (h instanceof Expression) {
106
- const val = h.value
107
- h = val[0]
108
- s = val[1]
109
- l = val[2]
110
-
111
- if (l instanceof Operation) {
112
- const op = l
113
- l = op.operands[0]
114
- a = op.operands[1]
115
- }
116
- }
117
- const color = colorFunctions.hsla(h, s, l, a);
118
- if (color) {
119
- color.value = 'hsl';
120
- return color;
121
- }
122
- },
123
- hsla: function (h, s, l, a) {
124
- let m1;
125
- let m2;
126
-
127
- function hue(h) {
128
- h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
129
- if (h * 6 < 1) {
130
- return m1 + (m2 - m1) * h * 6;
131
- }
132
- else if (h * 2 < 1) {
133
- return m2;
134
- }
135
- else if (h * 3 < 2) {
136
- return m1 + (m2 - m1) * (2 / 3 - h) * 6;
137
- }
138
- else {
139
- return m1;
140
- }
141
- }
142
-
143
- try {
144
- if (h instanceof Color) {
145
- if (s) {
146
- a = number(s);
147
- } else {
148
- a = h.alpha;
149
- }
150
- return new Color(h.rgb, a, 'hsla');
151
- }
152
-
153
- h = (number(h) % 360) / 360;
154
- s = clamp(number(s));l = clamp(number(l));a = clamp(number(a));
155
-
156
- m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
157
- m1 = l * 2 - m2;
158
-
159
- const rgb = [
160
- hue(h + 1 / 3) * 255,
161
- hue(h) * 255,
162
- hue(h - 1 / 3) * 255
163
- ];
164
- a = number(a);
165
- return new Color(rgb, a, 'hsla');
166
- }
167
- catch (e) {}
168
- },
169
-
170
- hsv: function(h, s, v) {
171
- return colorFunctions.hsva(h, s, v, 1.0);
172
- },
173
-
174
- hsva: function(h, s, v, a) {
175
- h = ((number(h) % 360) / 360) * 360;
176
- s = number(s);v = number(v);a = number(a);
177
-
178
- let i;
179
- let f;
180
- i = Math.floor((h / 60) % 6);
181
- f = (h / 60) - i;
182
-
183
- const vs = [v,
184
- v * (1 - s),
185
- v * (1 - f * s),
186
- v * (1 - (1 - f) * s)];
187
- const perm = [[0, 3, 1],
188
- [2, 0, 1],
189
- [1, 0, 3],
190
- [1, 2, 0],
191
- [3, 1, 0],
192
- [0, 1, 2]];
193
-
194
- return colorFunctions.rgba(vs[perm[i][0]] * 255,
195
- vs[perm[i][1]] * 255,
196
- vs[perm[i][2]] * 255,
197
- a);
198
- },
199
-
200
- hue: function (color) {
201
- return new Dimension(toHSL(color).h);
202
- },
203
- saturation: function (color) {
204
- return new Dimension(toHSL(color).s * 100, '%');
205
- },
206
- lightness: function (color) {
207
- return new Dimension(toHSL(color).l * 100, '%');
208
- },
209
- hsvhue: function(color) {
210
- return new Dimension(toHSV(color).h);
211
- },
212
- hsvsaturation: function (color) {
213
- return new Dimension(toHSV(color).s * 100, '%');
214
- },
215
- hsvvalue: function (color) {
216
- return new Dimension(toHSV(color).v * 100, '%');
217
- },
218
- red: function (color) {
219
- return new Dimension(color.rgb[0]);
220
- },
221
- green: function (color) {
222
- return new Dimension(color.rgb[1]);
223
- },
224
- blue: function (color) {
225
- return new Dimension(color.rgb[2]);
226
- },
227
- alpha: function (color) {
228
- return new Dimension(toHSL(color).a);
229
- },
230
- luma: function (color) {
231
- return new Dimension(color.luma() * color.alpha * 100, '%');
232
- },
233
- luminance: function (color) {
234
- const luminance =
235
- (0.2126 * color.rgb[0] / 255) +
236
- (0.7152 * color.rgb[1] / 255) +
237
- (0.0722 * color.rgb[2] / 255);
238
-
239
- return new Dimension(luminance * color.alpha * 100, '%');
240
- },
241
- saturate: function (color, amount, method) {
242
- // filter: saturate(3.2);
243
- // should be kept as is, so check for color
244
- if (!color.rgb) {
245
- return null;
246
- }
247
- const hsl = toHSL(color);
248
-
249
- if (typeof method !== 'undefined' && method.value === 'relative') {
250
- hsl.s += hsl.s * amount.value / 100;
251
- }
252
- else {
253
- hsl.s += amount.value / 100;
254
- }
255
- hsl.s = clamp(hsl.s);
256
- return hsla(color, hsl);
257
- },
258
- desaturate: function (color, amount, method) {
259
- const hsl = toHSL(color);
260
-
261
- if (typeof method !== 'undefined' && method.value === 'relative') {
262
- hsl.s -= hsl.s * amount.value / 100;
263
- }
264
- else {
265
- hsl.s -= amount.value / 100;
266
- }
267
- hsl.s = clamp(hsl.s);
268
- return hsla(color, hsl);
269
- },
270
- lighten: function (color, amount, method) {
271
- const hsl = toHSL(color);
272
-
273
- if (typeof method !== 'undefined' && method.value === 'relative') {
274
- hsl.l += hsl.l * amount.value / 100;
275
- }
276
- else {
277
- hsl.l += amount.value / 100;
278
- }
279
- hsl.l = clamp(hsl.l);
280
- return hsla(color, hsl);
281
- },
282
- darken: function (color, amount, method) {
283
- const hsl = toHSL(color);
284
-
285
- if (typeof method !== 'undefined' && method.value === 'relative') {
286
- hsl.l -= hsl.l * amount.value / 100;
287
- }
288
- else {
289
- hsl.l -= amount.value / 100;
290
- }
291
- hsl.l = clamp(hsl.l);
292
- return hsla(color, hsl);
293
- },
294
- fadein: function (color, amount, method) {
295
- const hsl = toHSL(color);
296
-
297
- if (typeof method !== 'undefined' && method.value === 'relative') {
298
- hsl.a += hsl.a * amount.value / 100;
299
- }
300
- else {
301
- hsl.a += amount.value / 100;
302
- }
303
- hsl.a = clamp(hsl.a);
304
- return hsla(color, hsl);
305
- },
306
- fadeout: function (color, amount, method) {
307
- const hsl = toHSL(color);
308
-
309
- if (typeof method !== 'undefined' && method.value === 'relative') {
310
- hsl.a -= hsl.a * amount.value / 100;
311
- }
312
- else {
313
- hsl.a -= amount.value / 100;
314
- }
315
- hsl.a = clamp(hsl.a);
316
- return hsla(color, hsl);
317
- },
318
- fade: function (color, amount) {
319
- const hsl = toHSL(color);
320
-
321
- hsl.a = amount.value / 100;
322
- hsl.a = clamp(hsl.a);
323
- return hsla(color, hsl);
324
- },
325
- spin: function (color, amount) {
326
- const hsl = toHSL(color);
327
- const hue = (hsl.h + amount.value) % 360;
328
-
329
- hsl.h = hue < 0 ? 360 + hue : hue;
330
-
331
- return hsla(color, hsl);
332
- },
333
- //
334
- // Copyright (c) 2006-2009 Hampton Catlin, Natalie Weizenbaum, and Chris Eppstein
335
- // http://sass-lang.com
336
- //
337
- mix: function (color1, color2, weight) {
338
- if (!weight) {
339
- weight = new Dimension(50);
340
- }
341
- const p = weight.value / 100.0;
342
- const w = p * 2 - 1;
343
- const a = toHSL(color1).a - toHSL(color2).a;
344
-
345
- const w1 = (((w * a == -1) ? w : (w + a) / (1 + w * a)) + 1) / 2.0;
346
- const w2 = 1 - w1;
347
-
348
- const rgb = [color1.rgb[0] * w1 + color2.rgb[0] * w2,
349
- color1.rgb[1] * w1 + color2.rgb[1] * w2,
350
- color1.rgb[2] * w1 + color2.rgb[2] * w2];
351
-
352
- const alpha = color1.alpha * p + color2.alpha * (1 - p);
353
-
354
- return new Color(rgb, alpha);
355
- },
356
- greyscale: function (color) {
357
- return colorFunctions.desaturate(color, new Dimension(100));
358
- },
359
- contrast: function (color, dark, light, threshold) {
360
- // filter: contrast(3.2);
361
- // should be kept as is, so check for color
362
- if (!color.rgb) {
363
- return null;
364
- }
365
- if (typeof light === 'undefined') {
366
- light = colorFunctions.rgba(255, 255, 255, 1.0);
367
- }
368
- if (typeof dark === 'undefined') {
369
- dark = colorFunctions.rgba(0, 0, 0, 1.0);
370
- }
371
- // Figure out which is actually light and dark:
372
- if (dark.luma() > light.luma()) {
373
- const t = light;
374
- light = dark;
375
- dark = t;
376
- }
377
- if (typeof threshold === 'undefined') {
378
- threshold = 0.43;
379
- } else {
380
- threshold = number(threshold);
381
- }
382
- if (color.luma() < threshold) {
383
- return light;
384
- } else {
385
- return dark;
386
- }
387
- },
388
- // Changes made in 2.7.0 - Reverted in 3.0.0
389
- // contrast: function (color, color1, color2, threshold) {
390
- // // Return which of `color1` and `color2` has the greatest contrast with `color`
391
- // // according to the standard WCAG contrast ratio calculation.
392
- // // http://www.w3.org/TR/WCAG20/#contrast-ratiodef
393
- // // The threshold param is no longer used, in line with SASS.
394
- // // filter: contrast(3.2);
395
- // // should be kept as is, so check for color
396
- // if (!color.rgb) {
397
- // return null;
398
- // }
399
- // if (typeof color1 === 'undefined') {
400
- // color1 = colorFunctions.rgba(0, 0, 0, 1.0);
401
- // }
402
- // if (typeof color2 === 'undefined') {
403
- // color2 = colorFunctions.rgba(255, 255, 255, 1.0);
404
- // }
405
- // var contrast1, contrast2;
406
- // var luma = color.luma();
407
- // var luma1 = color1.luma();
408
- // var luma2 = color2.luma();
409
- // // Calculate contrast ratios for each color
410
- // if (luma > luma1) {
411
- // contrast1 = (luma + 0.05) / (luma1 + 0.05);
412
- // } else {
413
- // contrast1 = (luma1 + 0.05) / (luma + 0.05);
414
- // }
415
- // if (luma > luma2) {
416
- // contrast2 = (luma + 0.05) / (luma2 + 0.05);
417
- // } else {
418
- // contrast2 = (luma2 + 0.05) / (luma + 0.05);
419
- // }
420
- // if (contrast1 > contrast2) {
421
- // return color1;
422
- // } else {
423
- // return color2;
424
- // }
425
- // },
426
- argb: function (color) {
427
- return new Anonymous(color.toARGB());
428
- },
429
- color: function(c) {
430
- if ((c instanceof Quoted) &&
431
- (/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})$/i.test(c.value))) {
432
- const val = c.value.slice(1);
433
- return new Color(val, undefined, `#${val}`);
434
- }
435
- if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) {
436
- c.value = undefined;
437
- return c;
438
- }
439
- throw {
440
- type: 'Argument',
441
- message: 'argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF'
442
- };
443
- },
444
- tint: function(color, amount) {
445
- return colorFunctions.mix(colorFunctions.rgb(255, 255, 255), color, amount);
446
- },
447
- shade: function(color, amount) {
448
- return colorFunctions.mix(colorFunctions.rgb(0, 0, 0), color, amount);
449
- }
450
- };
451
-
452
- export default colorFunctions;
@@ -1,74 +0,0 @@
1
- import Quoted from '../tree/quoted.js';
2
- import URL from '../tree/url.js';
3
- import * as utils from '../utils.js';
4
- import logger from '../logger.js';
5
-
6
- export default environment => {
7
-
8
- const fallback = (functionThis, node) => new URL(node, functionThis.index, functionThis.currentFileInfo).eval(functionThis.context);
9
-
10
- return { 'data-uri': function(mimetypeNode, filePathNode) {
11
-
12
- if (!filePathNode) {
13
- filePathNode = mimetypeNode;
14
- mimetypeNode = null;
15
- }
16
-
17
- let mimetype = mimetypeNode && mimetypeNode.value;
18
- let filePath = filePathNode.value;
19
- const currentFileInfo = this.currentFileInfo;
20
- const currentDirectory = currentFileInfo.rewriteUrls ?
21
- currentFileInfo.currentDirectory : currentFileInfo.entryPath;
22
-
23
- const fragmentStart = filePath.indexOf('#');
24
- let fragment = '';
25
- if (fragmentStart !== -1) {
26
- fragment = filePath.slice(fragmentStart);
27
- filePath = filePath.slice(0, fragmentStart);
28
- }
29
- const context = utils.clone(this.context);
30
- context.rawBuffer = true;
31
-
32
- const fileManager = environment.getFileManager(filePath, currentDirectory, context, environment, true);
33
-
34
- if (!fileManager) {
35
- return fallback(this, filePathNode);
36
- }
37
-
38
- let useBase64 = false;
39
-
40
- // detect the mimetype if not given
41
- if (!mimetypeNode) {
42
-
43
- mimetype = environment.mimeLookup(filePath);
44
-
45
- if (mimetype === 'image/svg+xml') {
46
- useBase64 = false;
47
- } else {
48
- // use base 64 unless it's an ASCII or UTF-8 format
49
- const charset = environment.charsetLookup(mimetype);
50
- useBase64 = ['US-ASCII', 'UTF-8'].indexOf(charset) < 0;
51
- }
52
- if (useBase64) { mimetype += ';base64'; }
53
- }
54
- else {
55
- useBase64 = /;base64$/.test(mimetype);
56
- }
57
-
58
- const fileSync = fileManager.loadFileSync(filePath, currentDirectory, context, environment);
59
- if (!fileSync.contents) {
60
- logger.warn(`Skipped data-uri embedding of ${filePath} because file not found`);
61
- return fallback(this, filePathNode || mimetypeNode);
62
- }
63
- let buf = fileSync.contents;
64
- if (useBase64 && !environment.encodeBase64) {
65
- return fallback(this, filePathNode);
66
- }
67
-
68
- buf = useBase64 ? environment.encodeBase64(buf) : encodeURIComponent(buf);
69
-
70
- const uri = `data:${mimetype},${buf}${fragment}`;
71
-
72
- return new URL(new Quoted(`"${uri}"`, uri, false, this.index, this.currentFileInfo), this.index, this.currentFileInfo);
73
- }};
74
- };
@@ -1,26 +0,0 @@
1
- import Keyword from '../tree/keyword.js';
2
- import * as utils from '../utils.js';
3
-
4
- const defaultFunc = {
5
- eval: function () {
6
- const v = this.value_;
7
- const e = this.error_;
8
- if (e) {
9
- throw e;
10
- }
11
- if (!utils.isNullOrUndefined(v)) {
12
- return v ? Keyword.True : Keyword.False;
13
- }
14
- },
15
- value: function (v) {
16
- this.value_ = v;
17
- },
18
- error: function (e) {
19
- this.error_ = e;
20
- },
21
- reset: function () {
22
- this.value_ = this.error_ = null;
23
- }
24
- };
25
-
26
- export default defaultFunc;
@@ -1,55 +0,0 @@
1
- import Expression from '../tree/expression.js';
2
-
3
- class functionCaller {
4
- constructor(name, context, index, currentFileInfo) {
5
- this.name = name.toLowerCase();
6
- this.index = index;
7
- this.context = context;
8
- this.currentFileInfo = currentFileInfo;
9
-
10
- this.func = context.frames[0].functionRegistry.get(this.name);
11
- }
12
-
13
- isValid() {
14
- return Boolean(this.func);
15
- }
16
-
17
- call(args) {
18
- if (!(Array.isArray(args))) {
19
- args = [args];
20
- }
21
- const evalArgs = this.func.evalArgs;
22
- if (evalArgs !== false) {
23
- args = args.map(a => a.eval(this.context));
24
- }
25
- const commentFilter = item => !(item.type === 'Comment');
26
-
27
- // This code is terrible and should be replaced as per this issue...
28
- // https://github.com/less/less.js/issues/2477
29
- args = args
30
- .filter(commentFilter)
31
- .map(item => {
32
- if (item.type === 'Expression') {
33
- const subNodes = item.value.filter(commentFilter);
34
- if (subNodes.length === 1) {
35
- // https://github.com/less/less.js/issues/3616
36
- if (item.parens && subNodes[0].op === '/') {
37
- return item;
38
- }
39
- return subNodes[0];
40
- } else {
41
- return new Expression(subNodes);
42
- }
43
- }
44
- return item;
45
- });
46
-
47
- if (evalArgs === false) {
48
- return this.func(this.context, ...args);
49
- }
50
-
51
- return this.func(...args);
52
- }
53
- }
54
-
55
- export default functionCaller;
@@ -1,36 +0,0 @@
1
- function makeRegistry( base ) {
2
- return {
3
- _data: {},
4
- add: function(name, func) {
5
- // precautionary case conversion, as later querying of
6
- // the registry by function-caller uses lower case as well.
7
- name = name.toLowerCase();
8
-
9
- // eslint-disable-next-line no-prototype-builtins
10
- if (this._data.hasOwnProperty(name)) {
11
- // TODO warn
12
- }
13
- this._data[name] = func;
14
- },
15
- addMultiple: function(functions) {
16
- Object.keys(functions).forEach(
17
- name => {
18
- this.add(name, functions[name]);
19
- });
20
- },
21
- get: function(name) {
22
- return this._data[name] || ( base && base.get( name ));
23
- },
24
- getLocalFunctions: function() {
25
- return this._data;
26
- },
27
- inherit: function() {
28
- return makeRegistry( this );
29
- },
30
- create: function(base) {
31
- return makeRegistry(base);
32
- }
33
- };
34
- }
35
-
36
- export default makeRegistry( null );
@@ -1,35 +0,0 @@
1
- import functionRegistry from './function-registry.js';
2
- import functionCaller from './function-caller.js';
3
-
4
- import boolean from './boolean.js';
5
- import defaultFunc from './default.js';
6
- import color from './color.js';
7
- import colorBlending from './color-blending.js';
8
- import dataUri from './data-uri.js';
9
- import list from './list.js';
10
- import math from './math.js';
11
- import number from './number.js';
12
- import string from './string.js';
13
- import svg from './svg.js';
14
- import types from './types.js';
15
- import style from './style.js';
16
-
17
- export default environment => {
18
- const functions = { functionRegistry, functionCaller };
19
-
20
- // register functions
21
- functionRegistry.addMultiple(boolean);
22
- functionRegistry.add('default', defaultFunc.eval.bind(defaultFunc));
23
- functionRegistry.addMultiple(color);
24
- functionRegistry.addMultiple(colorBlending);
25
- functionRegistry.addMultiple(dataUri(environment));
26
- functionRegistry.addMultiple(list);
27
- functionRegistry.addMultiple(math);
28
- functionRegistry.addMultiple(number);
29
- functionRegistry.addMultiple(string);
30
- functionRegistry.addMultiple(svg(environment));
31
- functionRegistry.addMultiple(types);
32
- functionRegistry.addMultiple(style);
33
-
34
- return functions;
35
- };