less 3.8.0 → 3.8.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 (33) hide show
  1. package/Gruntfile.js +1 -3
  2. package/dist/less.js +2352 -98
  3. package/dist/less.min.js +7 -7
  4. package/lib/less/functions/color.js +84 -41
  5. package/lib/less/index.js +1 -1
  6. package/lib/less/parser/parser.js +2 -9
  7. package/lib/less/source-map-output.js +2 -2
  8. package/lib/less/tree/color.js +58 -18
  9. package/lib/less/utils.js +12 -19
  10. package/lib/less-browser/index.js +7 -1
  11. package/package.json +5 -2
  12. package/test/browser/less.js +2352 -98
  13. package/test/css/colors.css +20 -3
  14. package/test/css/css-escapes.css +3 -0
  15. package/test/css/functions.css +4 -4
  16. package/test/less/colors.less +18 -0
  17. package/test/less/css-escapes.less +4 -0
  18. package/test/less/errors/color-func-invalid-color.txt +1 -1
  19. package/test/less/sourcemaps/custom-props.less +8 -0
  20. package/test/less-bom/colors.less +18 -0
  21. package/test/less-bom/css-escapes.less +4 -0
  22. package/test/less-bom/errors/color-func-invalid-color.txt +1 -1
  23. package/test/less-bom/sourcemaps/custom-props.less +8 -0
  24. package/test/less-test.js +26 -12
  25. package/test/sourcemaps/custom-props.json +1 -0
  26. package/test/less/errors/color-invalid-hex-code.less +0 -4
  27. package/test/less/errors/color-invalid-hex-code.txt +0 -4
  28. package/test/less/errors/color-invalid-hex-code2.less +0 -4
  29. package/test/less/errors/color-invalid-hex-code2.txt +0 -4
  30. package/test/less-bom/errors/color-invalid-hex-code.less +0 -4
  31. package/test/less-bom/errors/color-invalid-hex-code.txt +0 -4
  32. package/test/less-bom/errors/color-invalid-hex-code2.less +0 -4
  33. package/test/less-bom/errors/color-invalid-hex-code2.txt +0 -4
@@ -8,8 +8,17 @@ var Dimension = require('../tree/dimension'),
8
8
  function clamp(val) {
9
9
  return Math.min(1, Math.max(0, val));
10
10
  }
11
- function hsla(color) {
12
- return colorFunctions.hsla(color.h, color.s, color.l, color.a);
11
+ function hsla(origColor, hsl) {
12
+ var color = colorFunctions.hsla(hsl.h, hsl.s, hsl.l, hsl.a);
13
+ if (color) {
14
+ if (origColor.value &&
15
+ /^(rgb|hsl)/.test(origColor.value)) {
16
+ color.value = origColor.value;
17
+ } else {
18
+ color.value = 'rgb';
19
+ }
20
+ return color;
21
+ }
13
22
  }
14
23
  function number(n) {
15
24
  if (n instanceof Dimension) {
@@ -32,46 +41,79 @@ function scaled(n, size) {
32
41
  }
33
42
  colorFunctions = {
34
43
  rgb: function (r, g, b) {
35
- return colorFunctions.rgba(r, g, b, 1.0);
44
+ var color = colorFunctions.rgba(r, g, b, 1.0);
45
+ if (color) {
46
+ color.value = 'rgb';
47
+ return color;
48
+ }
36
49
  },
37
50
  rgba: function (r, g, b, a) {
38
- var rgb = [r, g, b].map(function (c) { return scaled(c, 255); });
39
- a = number(a);
40
- return new Color(rgb, a);
51
+ try {
52
+ if (r instanceof Color) {
53
+ if (g) {
54
+ a = number(g);
55
+ } else {
56
+ a = r.alpha;
57
+ }
58
+ return new Color(r.rgb, a, 'rgba');
59
+ }
60
+ var rgb = [r, g, b].map(function (c) { return scaled(c, 255); });
61
+ a = number(a);
62
+ return new Color(rgb, a, 'rgba');
63
+ }
64
+ catch (e) {}
41
65
  },
42
66
  hsl: function (h, s, l) {
43
- return colorFunctions.hsla(h, s, l, 1.0);
67
+ var color = colorFunctions.hsla(h, s, l, 1.0);
68
+ if (color) {
69
+ color.value = 'hsl';
70
+ return color;
71
+ }
44
72
  },
45
73
  hsla: function (h, s, l, a) {
74
+ try {
75
+ if (h instanceof Color) {
76
+ if (s) {
77
+ a = number(s);
78
+ } else {
79
+ a = h.alpha;
80
+ }
81
+ return new Color(h.rgb, a, 'hsla');
82
+ }
46
83
 
47
- var m1, m2;
84
+ var m1, m2;
48
85
 
49
- function hue(h) {
50
- h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
51
- if (h * 6 < 1) {
52
- return m1 + (m2 - m1) * h * 6;
53
- }
54
- else if (h * 2 < 1) {
55
- return m2;
56
- }
57
- else if (h * 3 < 2) {
58
- return m1 + (m2 - m1) * (2 / 3 - h) * 6;
59
- }
60
- else {
61
- return m1;
86
+ function hue(h) {
87
+ h = h < 0 ? h + 1 : (h > 1 ? h - 1 : h);
88
+ if (h * 6 < 1) {
89
+ return m1 + (m2 - m1) * h * 6;
90
+ }
91
+ else if (h * 2 < 1) {
92
+ return m2;
93
+ }
94
+ else if (h * 3 < 2) {
95
+ return m1 + (m2 - m1) * (2 / 3 - h) * 6;
96
+ }
97
+ else {
98
+ return m1;
99
+ }
62
100
  }
63
- }
64
101
 
65
- h = (number(h) % 360) / 360;
66
- s = clamp(number(s)); l = clamp(number(l)); a = clamp(number(a));
102
+ h = (number(h) % 360) / 360;
103
+ s = clamp(number(s)); l = clamp(number(l)); a = clamp(number(a));
67
104
 
68
- m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
69
- m1 = l * 2 - m2;
105
+ m2 = l <= 0.5 ? l * (s + 1) : l + s - l * s;
106
+ m1 = l * 2 - m2;
70
107
 
71
- return colorFunctions.rgba(hue(h + 1 / 3) * 255,
72
- hue(h) * 255,
73
- hue(h - 1 / 3) * 255,
74
- a);
108
+ var rgb = [
109
+ hue(h + 1 / 3) * 255,
110
+ hue(h) * 255,
111
+ hue(h - 1 / 3) * 255
112
+ ];
113
+ a = number(a);
114
+ return new Color(rgb, a, 'hsla');
115
+ }
116
+ catch (e) {}
75
117
  },
76
118
 
77
119
  hsv: function(h, s, v) {
@@ -159,7 +201,7 @@ colorFunctions = {
159
201
  hsl.s += amount.value / 100;
160
202
  }
161
203
  hsl.s = clamp(hsl.s);
162
- return hsla(hsl);
204
+ return hsla(color, hsl);
163
205
  },
164
206
  desaturate: function (color, amount, method) {
165
207
  var hsl = color.toHSL();
@@ -171,7 +213,7 @@ colorFunctions = {
171
213
  hsl.s -= amount.value / 100;
172
214
  }
173
215
  hsl.s = clamp(hsl.s);
174
- return hsla(hsl);
216
+ return hsla(color, hsl);
175
217
  },
176
218
  lighten: function (color, amount, method) {
177
219
  var hsl = color.toHSL();
@@ -183,7 +225,7 @@ colorFunctions = {
183
225
  hsl.l += amount.value / 100;
184
226
  }
185
227
  hsl.l = clamp(hsl.l);
186
- return hsla(hsl);
228
+ return hsla(color, hsl);
187
229
  },
188
230
  darken: function (color, amount, method) {
189
231
  var hsl = color.toHSL();
@@ -195,7 +237,7 @@ colorFunctions = {
195
237
  hsl.l -= amount.value / 100;
196
238
  }
197
239
  hsl.l = clamp(hsl.l);
198
- return hsla(hsl);
240
+ return hsla(color, hsl);
199
241
  },
200
242
  fadein: function (color, amount, method) {
201
243
  var hsl = color.toHSL();
@@ -207,7 +249,7 @@ colorFunctions = {
207
249
  hsl.a += amount.value / 100;
208
250
  }
209
251
  hsl.a = clamp(hsl.a);
210
- return hsla(hsl);
252
+ return hsla(color, hsl);
211
253
  },
212
254
  fadeout: function (color, amount, method) {
213
255
  var hsl = color.toHSL();
@@ -219,14 +261,14 @@ colorFunctions = {
219
261
  hsl.a -= amount.value / 100;
220
262
  }
221
263
  hsl.a = clamp(hsl.a);
222
- return hsla(hsl);
264
+ return hsla(color, hsl);
223
265
  },
224
266
  fade: function (color, amount) {
225
267
  var hsl = color.toHSL();
226
268
 
227
269
  hsl.a = amount.value / 100;
228
270
  hsl.a = clamp(hsl.a);
229
- return hsla(hsl);
271
+ return hsla(color, hsl);
230
272
  },
231
273
  spin: function (color, amount) {
232
274
  var hsl = color.toHSL();
@@ -234,7 +276,7 @@ colorFunctions = {
234
276
 
235
277
  hsl.h = hue < 0 ? 360 + hue : hue;
236
278
 
237
- return hsla(hsl);
279
+ return hsla(color, hsl);
238
280
  },
239
281
  //
240
282
  // Copyright (c) 2006-2009 Hampton Catlin, Natalie Weizenbaum, and Chris Eppstein
@@ -338,8 +380,9 @@ colorFunctions = {
338
380
  },
339
381
  color: function(c) {
340
382
  if ((c instanceof Quoted) &&
341
- (/^#([a-f0-9]{6}|[a-f0-9]{3})$/i.test(c.value))) {
342
- return new Color(c.value.slice(1));
383
+ (/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})$/i.test(c.value))) {
384
+ var val = c.value.slice(1);
385
+ return new Color(val, undefined, '#' + val);
343
386
  }
344
387
  if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) {
345
388
  c.value = undefined;
@@ -347,7 +390,7 @@ colorFunctions = {
347
390
  }
348
391
  throw {
349
392
  type: 'Argument',
350
- message: 'argument must be a color keyword or 3/6 digit hex e.g. #FFF'
393
+ message: 'argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF'
351
394
  };
352
395
  },
353
396
  tint: function(color, amount) {
package/lib/less/index.js CHANGED
@@ -2,7 +2,7 @@ module.exports = function(environment, fileManagers) {
2
2
  var SourceMapOutput, SourceMapBuilder, ParseTree, ImportManager, Environment;
3
3
 
4
4
  var initial = {
5
- version: [3, 8, 0],
5
+ version: [3, 8, 1],
6
6
  data: require('./data'),
7
7
  tree: require('./tree'),
8
8
  Environment: (Environment = require('./environment/environment')),
@@ -636,15 +636,8 @@ var Parser = function Parser(context, imports, fileInfo) {
636
636
  color: function () {
637
637
  var rgb;
638
638
 
639
- if (parserInput.currentChar() === '#' && (rgb = parserInput.$re(/^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})/))) {
640
- // strip colons, brackets, whitespaces and other characters that should not
641
- // definitely be part of color string
642
- var colorCandidateString = rgb.input.match(/^#([\w]+).*/);
643
- colorCandidateString = colorCandidateString[1];
644
- if (!colorCandidateString.match(/^[A-Fa-f0-9]+$/)) { // verify if candidate consists only of allowed HEX characters
645
- error('Invalid HEX color code');
646
- }
647
- return new(tree.Color)(rgb[1], undefined, '#' + colorCandidateString);
639
+ if (parserInput.currentChar() === '#' && (rgb = parserInput.$re(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})/))) {
640
+ return new(tree.Color)(rgb[1], undefined, rgb[0]);
648
641
  }
649
642
  },
650
643
 
@@ -58,7 +58,7 @@ module.exports = function (environment) {
58
58
  sourceColumns,
59
59
  i;
60
60
 
61
- if (fileInfo) {
61
+ if (fileInfo && fileInfo.filename) {
62
62
  var inputSource = this._contentsMap[fileInfo.filename];
63
63
 
64
64
  // remove vars/banner added to the top of the file
@@ -77,7 +77,7 @@ module.exports = function (environment) {
77
77
  lines = chunk.split('\n');
78
78
  columns = lines[lines.length - 1];
79
79
 
80
- if (fileInfo) {
80
+ if (fileInfo && fileInfo.filename) {
81
81
  if (!mapLines) {
82
82
  this._sourceMapGenerator.addMapping({ generated: { line: this._lineNumber + 1, column: this._column},
83
83
  original: { line: sourceLines.length, column: sourceColumns.length},
@@ -5,6 +5,7 @@ var Node = require('./node'),
5
5
  // RGB Colors - #ff0014, #eee
6
6
  //
7
7
  var Color = function (rgb, a, originalForm) {
8
+ var self = this;
8
9
  //
9
10
  // The end goal here, is to parse the arguments
10
11
  // into an integer triplet, such as `128, 255, 0`
@@ -13,16 +14,26 @@ var Color = function (rgb, a, originalForm) {
13
14
  //
14
15
  if (Array.isArray(rgb)) {
15
16
  this.rgb = rgb;
16
- } else if (rgb.length == 6) {
17
- this.rgb = rgb.match(/.{2}/g).map(function (c) {
18
- return parseInt(c, 16);
17
+ } else if (rgb.length >= 6) {
18
+ this.rgb = [];
19
+ rgb.match(/.{2}/g).map(function (c, i) {
20
+ if (i < 3) {
21
+ self.rgb.push(parseInt(c, 16));
22
+ } else {
23
+ self.alpha = (parseInt(c, 16)) / 255;
24
+ }
19
25
  });
20
26
  } else {
21
- this.rgb = rgb.split('').map(function (c) {
22
- return parseInt(c + c, 16);
27
+ this.rgb = [];
28
+ rgb.split('').map(function (c, i) {
29
+ if (i < 3) {
30
+ self.rgb.push(parseInt(c + c, 16));
31
+ } else {
32
+ self.alpha = (parseInt(c + c, 16)) / 255;
33
+ }
23
34
  });
24
35
  }
25
- this.alpha = typeof a === 'number' ? a : 1;
36
+ this.alpha = this.alpha || (typeof a === 'number' ? a : 1);
26
37
  if (typeof originalForm !== 'undefined') {
27
38
  this.value = originalForm;
28
39
  }
@@ -57,25 +68,54 @@ Color.prototype.genCSS = function (context, output) {
57
68
  output.add(this.toCSS(context));
58
69
  };
59
70
  Color.prototype.toCSS = function (context, doNotCompress) {
60
- var compress = context && context.compress && !doNotCompress, color, alpha;
71
+ var compress = context && context.compress && !doNotCompress, color, alpha,
72
+ colorFunction, args = [];
61
73
 
62
74
  // `value` is set if this color was originally
63
75
  // converted from a named color string so we need
64
76
  // to respect this and try to output named color too.
77
+ alpha = this.fround(context, this.alpha);
78
+
65
79
  if (this.value) {
66
- return this.value;
80
+ if (this.value.indexOf('rgb') === 0) {
81
+ if (alpha < 1) {
82
+ colorFunction = 'rgba';
83
+ }
84
+ } else if (this.value.indexOf('hsl') === 0) {
85
+ if (alpha < 1) {
86
+ colorFunction = 'hsla';
87
+ } else {
88
+ colorFunction = 'hsl';
89
+ }
90
+ } else {
91
+ return this.value;
92
+ }
93
+ } else {
94
+ if (alpha < 1) {
95
+ colorFunction = 'rgba';
96
+ }
67
97
  }
68
98
 
69
- // If we have some transparency, the only way to represent it
70
- // is via `rgba`. Otherwise, we use the hex representation,
71
- // which has better compatibility with older browsers.
72
- // Values are capped between `0` and `255`, rounded and zero-padded.
73
- alpha = this.fround(context, this.alpha);
74
- if (alpha < 1) {
75
- return 'rgba(' + this.rgb.map(function (c) {
76
- return clamp(Math.round(c), 255);
77
- }).concat(clamp(alpha, 1))
78
- .join(',' + (compress ? '' : ' ')) + ')';
99
+ switch (colorFunction) {
100
+ case 'rgba':
101
+ args = this.rgb.map(function (c) {
102
+ return clamp(Math.round(c), 255);
103
+ }).concat(clamp(alpha, 1));
104
+ break;
105
+ case 'hsla':
106
+ args.push(clamp(alpha, 1));
107
+ case 'hsl':
108
+ color = this.toHSL();
109
+ args = [
110
+ this.fround(context, color.h),
111
+ this.fround(context, color.s * 100) + '%',
112
+ this.fround(context, color.l * 100) + '%'
113
+ ].concat(args);
114
+ }
115
+
116
+ if (colorFunction) {
117
+ // Values are capped between `0` and `255`, rounded and zero-padded.
118
+ return colorFunction + '(' + args.join(',' + (compress ? '' : ' ')) + ')';
79
119
  }
80
120
 
81
121
  color = this.toRGB();
package/lib/less/utils.js CHANGED
@@ -1,5 +1,6 @@
1
1
  /* jshint proto: true */
2
2
  var Constants = require('./constants');
3
+ var clone = require('clone');
3
4
 
4
5
  var utils = {
5
6
  getLocation: function(index, inputStream) {
@@ -39,6 +40,9 @@ var utils = {
39
40
  return cloned;
40
41
  },
41
42
  copyOptions: function(obj1, obj2) {
43
+ if (obj2 && obj2._defaults) {
44
+ return obj2;
45
+ }
42
46
  var opts = utils.defaults(obj1, obj2);
43
47
  if (opts.strictMath) {
44
48
  opts.math = Constants.Math.STRICT_LEGACY;
@@ -79,26 +83,15 @@ var utils = {
79
83
  return opts;
80
84
  },
81
85
  defaults: function(obj1, obj2) {
82
- if (!obj2._defaults || obj2._defaults !== obj1) {
83
- for (var prop in obj1) {
84
- if (obj1.hasOwnProperty(prop)) {
85
- if (!obj2.hasOwnProperty(prop)) {
86
- obj2[prop] = obj1[prop];
87
- }
88
- else if (Array.isArray(obj1[prop])
89
- && Array.isArray(obj2[prop])) {
90
-
91
- obj1[prop].forEach(function(p) {
92
- if (obj2[prop].indexOf(p) === -1) {
93
- obj2[prop].push(p);
94
- }
95
- });
96
- }
97
- }
98
- }
86
+ var newObj = obj2 || {};
87
+ if (!obj2._defaults) {
88
+ newObj = {};
89
+ var defaults = clone(obj1);
90
+ newObj._defaults = defaults;
91
+ var cloned = obj2 ? clone(obj2) : {};
92
+ Object.assign(newObj, defaults, cloned);
99
93
  }
100
- obj2._defaults = obj1;
101
- return obj2;
94
+ return newObj;
102
95
  },
103
96
  merge: function(obj1, obj2) {
104
97
  for (var prop in obj2) {
@@ -30,7 +30,13 @@ module.exports = function(window, options) {
30
30
  var typePattern = /^text\/(x-)?less$/;
31
31
 
32
32
  function clone(obj) {
33
- return JSON.parse(JSON.stringify(obj || {}));
33
+ var cloned = {};
34
+ for (var prop in obj) {
35
+ if (obj.hasOwnProperty(prop)) {
36
+ cloned[prop] = obj[prop];
37
+ }
38
+ }
39
+ return cloned;
34
40
  }
35
41
 
36
42
  // only really needed for phantom
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "less",
3
- "version": "3.8.0",
3
+ "version": "3.8.1",
4
4
  "description": "Leaner CSS",
5
5
  "homepage": "http://lesscss.org",
6
6
  "author": {
@@ -71,6 +71,7 @@
71
71
  "less-plugin-autoprefix": "^1.5.1",
72
72
  "less-plugin-clean-css": "^1.5.1",
73
73
  "performance-now": "^0.2.0",
74
+ "phantomjs-polyfill-object-assign": "0.0.2",
74
75
  "phantomjs-prebuilt": "^2.1.16",
75
76
  "phin": "^2.2.3",
76
77
  "promise": "^7.1.1",
@@ -104,5 +105,7 @@
104
105
  ],
105
106
  "rawcurrent": "https://raw.github.com/less/less.js/v",
106
107
  "sourcearchive": "https://github.com/less/less.js/archive/v",
107
- "dependencies": {}
108
+ "dependencies": {
109
+ "clone": "^2.1.2"
110
+ }
108
111
  }