less 4.2.2 → 4.4.0

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/dist/less.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Less - Leaner CSS v4.2.2
2
+ * Less - Leaner CSS v4.4.0
3
3
  * http://lesscss.org
4
4
  *
5
5
  * Copyright (c) 2009-2025, Alexis Sellier <self@cloudhead.net>
@@ -856,6 +856,47 @@
856
856
  }).join(''));
857
857
  }
858
858
 
859
+ /******************************************************************************
860
+ Copyright (c) Microsoft Corporation.
861
+
862
+ Permission to use, copy, modify, and/or distribute this software for any
863
+ purpose with or without fee is hereby granted.
864
+
865
+ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
866
+ REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
867
+ AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
868
+ INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
869
+ LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
870
+ OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
871
+ PERFORMANCE OF THIS SOFTWARE.
872
+ ***************************************************************************** */
873
+
874
+ var __assign = function() {
875
+ __assign = Object.assign || function __assign(t) {
876
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
877
+ s = arguments[i];
878
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
879
+ }
880
+ return t;
881
+ };
882
+ return __assign.apply(this, arguments);
883
+ };
884
+
885
+ function __spreadArray(to, from, pack) {
886
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
887
+ if (ar || !(i in from)) {
888
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
889
+ ar[i] = from[i];
890
+ }
891
+ }
892
+ return to.concat(ar || Array.prototype.slice.call(from));
893
+ }
894
+
895
+ typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
896
+ var e = new Error(message);
897
+ return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
898
+ };
899
+
859
900
  var Paren = function (node) {
860
901
  this.value = node;
861
902
  };
@@ -962,47 +1003,6 @@
962
1003
  ALL: 2
963
1004
  };
964
1005
 
965
- /******************************************************************************
966
- Copyright (c) Microsoft Corporation.
967
-
968
- Permission to use, copy, modify, and/or distribute this software for any
969
- purpose with or without fee is hereby granted.
970
-
971
- THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
972
- REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
973
- AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
974
- INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
975
- LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
976
- OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
977
- PERFORMANCE OF THIS SOFTWARE.
978
- ***************************************************************************** */
979
-
980
- var __assign = function() {
981
- __assign = Object.assign || function __assign(t) {
982
- for (var s, i = 1, n = arguments.length; i < n; i++) {
983
- s = arguments[i];
984
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
985
- }
986
- return t;
987
- };
988
- return __assign.apply(this, arguments);
989
- };
990
-
991
- function __spreadArray(to, from, pack) {
992
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
993
- if (ar || !(i in from)) {
994
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
995
- ar[i] = from[i];
996
- }
997
- }
998
- return to.concat(ar || Array.prototype.slice.call(from));
999
- }
1000
-
1001
- typeof SuppressedError === "function" ? SuppressedError : function (error, suppressed, message) {
1002
- var e = new Error(message);
1003
- return e.name = "SuppressedError", e.error = error, e.suppressed = suppressed, e;
1004
- };
1005
-
1006
1006
  /**
1007
1007
  * Returns the object type of the given payload
1008
1008
  *
@@ -1034,7 +1034,7 @@
1034
1034
  }
1035
1035
 
1036
1036
  function assignProp(carry, key, newVal, originalObject, includeNonenumerable) {
1037
- var propType = {}.propertyIsEnumerable.call(originalObject, key)
1037
+ const propType = {}.propertyIsEnumerable.call(originalObject, key)
1038
1038
  ? 'enumerable'
1039
1039
  : 'nonenumerable';
1040
1040
  if (propType === 'enumerable')
@@ -1058,22 +1058,21 @@
1058
1058
  * @returns {T} the target with replaced values
1059
1059
  * @export
1060
1060
  */
1061
- function copy(target, options) {
1062
- if (options === void 0) { options = {}; }
1061
+ function copy(target, options = {}) {
1063
1062
  if (isArray(target)) {
1064
- return target.map(function (item) { return copy(item, options); });
1063
+ return target.map((item) => copy(item, options));
1065
1064
  }
1066
1065
  if (!isPlainObject(target)) {
1067
1066
  return target;
1068
1067
  }
1069
- var props = Object.getOwnPropertyNames(target);
1070
- var symbols = Object.getOwnPropertySymbols(target);
1071
- return __spreadArray(__spreadArray([], props, true), symbols, true).reduce(function (carry, key) {
1068
+ const props = Object.getOwnPropertyNames(target);
1069
+ const symbols = Object.getOwnPropertySymbols(target);
1070
+ return [...props, ...symbols].reduce((carry, key) => {
1072
1071
  if (isArray(options.props) && !options.props.includes(key)) {
1073
1072
  return carry;
1074
1073
  }
1075
- var val = target[key];
1076
- var newVal = copy(val, options);
1074
+ const val = target[key];
1075
+ const newVal = copy(val, options);
1077
1076
  assignProp(carry, key, newVal, target, options.nonenumerable);
1078
1077
  return carry;
1079
1078
  }, {});
@@ -1299,20 +1298,24 @@
1299
1298
  * @returns {string}
1300
1299
  */
1301
1300
  LessError.prototype.toString = function (options) {
1301
+ var _a;
1302
1302
  options = options || {};
1303
+ var isWarning = ((_a = this.type) !== null && _a !== void 0 ? _a : '').toLowerCase().includes('warning');
1304
+ var type = isWarning ? this.type : "".concat(this.type, "Error");
1305
+ var color = isWarning ? 'yellow' : 'red';
1303
1306
  var message = '';
1304
1307
  var extract = this.extract || [];
1305
1308
  var error = [];
1306
1309
  var stylize = function (str) { return str; };
1307
1310
  if (options.stylize) {
1308
- var type = typeof options.stylize;
1309
- if (type !== 'function') {
1310
- throw Error("options.stylize should be a function, got a ".concat(type, "!"));
1311
+ var type_1 = typeof options.stylize;
1312
+ if (type_1 !== 'function') {
1313
+ throw Error("options.stylize should be a function, got a ".concat(type_1, "!"));
1311
1314
  }
1312
1315
  stylize = options.stylize;
1313
1316
  }
1314
1317
  if (this.line !== null) {
1315
- if (typeof extract[0] === 'string') {
1318
+ if (!isWarning && typeof extract[0] === 'string') {
1316
1319
  error.push(stylize("".concat(this.line - 1, " ").concat(extract[0]), 'grey'));
1317
1320
  }
1318
1321
  if (typeof extract[1] === 'string') {
@@ -1324,21 +1327,21 @@
1324
1327
  }
1325
1328
  error.push(errorTxt);
1326
1329
  }
1327
- if (typeof extract[2] === 'string') {
1330
+ if (!isWarning && typeof extract[2] === 'string') {
1328
1331
  error.push(stylize("".concat(this.line + 1, " ").concat(extract[2]), 'grey'));
1329
1332
  }
1330
1333
  error = "".concat(error.join('\n') + stylize('', 'reset'), "\n");
1331
1334
  }
1332
- message += stylize("".concat(this.type, "Error: ").concat(this.message), 'red');
1335
+ message += stylize("".concat(type, ": ").concat(this.message), color);
1333
1336
  if (this.filename) {
1334
- message += stylize(' in ', 'red') + this.filename;
1337
+ message += stylize(' in ', color) + this.filename;
1335
1338
  }
1336
1339
  if (this.line) {
1337
1340
  message += stylize(" on line ".concat(this.line, ", column ").concat(this.column + 1, ":"), 'grey');
1338
1341
  }
1339
1342
  message += "\n".concat(error);
1340
1343
  if (this.callLine) {
1341
- message += "".concat(stylize('from ', 'red') + (this.filename || ''), "/n");
1344
+ message += "".concat(stylize('from ', color) + (this.filename || ''), "/n");
1342
1345
  message += "".concat(stylize(this.callLine, 'grey'), " ").concat(this.callExtract, "/n");
1343
1346
  }
1344
1347
  return message;
@@ -1519,7 +1522,8 @@
1519
1522
  // context
1520
1523
  'processImports',
1521
1524
  // Used by the import manager to stop multiple import visitors being created.
1522
- 'pluginManager' // Used as the plugin manager for the session
1525
+ 'pluginManager',
1526
+ 'quiet', // option - whether to log warnings
1523
1527
  ];
1524
1528
  contexts.Parse = function (options) {
1525
1529
  copyFromOriginal(options, this, parseCopyProperties);
@@ -1830,7 +1834,20 @@
1830
1834
  }
1831
1835
  },
1832
1836
  visitAtRule: function (atRuleNode, visitArgs) {
1833
- this.context.frames.unshift(atRuleNode);
1837
+ if (atRuleNode.value) {
1838
+ this.context.frames.unshift(atRuleNode);
1839
+ }
1840
+ else if (atRuleNode.declarations && atRuleNode.declarations.length) {
1841
+ if (atRuleNode.isRooted) {
1842
+ this.context.frames.unshift(atRuleNode);
1843
+ }
1844
+ else {
1845
+ this.context.frames.unshift(atRuleNode.declarations[0]);
1846
+ }
1847
+ }
1848
+ else if (atRuleNode.rules && atRuleNode.rules.length) {
1849
+ this.context.frames.unshift(atRuleNode);
1850
+ }
1834
1851
  },
1835
1852
  visitAtRuleOut: function (atRuleNode) {
1836
1853
  this.context.frames.shift();
@@ -2006,7 +2023,12 @@
2006
2023
  catch (_) { }
2007
2024
  if (!indices["".concat(extend.index, " ").concat(selector)]) {
2008
2025
  indices["".concat(extend.index, " ").concat(selector)] = true;
2009
- logger$1.warn("extend '".concat(selector, "' has no matches"));
2026
+ /**
2027
+ * @todo Shouldn't this be an error? To alert the developer
2028
+ * that they may have made an error in the selector they are
2029
+ * targeting?
2030
+ */
2031
+ logger$1.warn("WARNING: extend '".concat(selector, "' has no matches"));
2010
2032
  }
2011
2033
  });
2012
2034
  };
@@ -2367,7 +2389,10 @@
2367
2389
  };
2368
2390
  JoinSelectorVisitor.prototype.visitAtRule = function (atRuleNode, visitArgs) {
2369
2391
  var context = this.contexts[this.contexts.length - 1];
2370
- if (atRuleNode.rules && atRuleNode.rules.length) {
2392
+ if (atRuleNode.declarations && atRuleNode.declarations.length) {
2393
+ atRuleNode.declarations[0].root = (context.length === 0 || context[0].multiMedia);
2394
+ }
2395
+ else if (atRuleNode.rules && atRuleNode.rules.length) {
2371
2396
  atRuleNode.rules[0].root = (atRuleNode.isRooted || context.length === 0 || null);
2372
2397
  }
2373
2398
  };
@@ -3310,6 +3335,22 @@
3310
3335
  message: msg
3311
3336
  }, imports);
3312
3337
  }
3338
+ /**
3339
+ *
3340
+ * @param {string} msg
3341
+ * @param {number} index
3342
+ * @param {string} type
3343
+ */
3344
+ function warn(msg, index, type) {
3345
+ if (!context.quiet) {
3346
+ logger$1.warn((new LessError({
3347
+ index: index !== null && index !== void 0 ? index : parserInput.i,
3348
+ filename: fileInfo.filename,
3349
+ type: type ? "".concat(type.toUpperCase(), " WARNING") : 'WARNING',
3350
+ message: msg
3351
+ }, imports)).toString());
3352
+ }
3353
+ }
3313
3354
  function expect(arg, msg) {
3314
3355
  // some older browsers return typeof 'function' for RegExp
3315
3356
  var result = (arg instanceof Function) ? arg.call(parsers) : parserInput.$re(arg);
@@ -4017,11 +4058,20 @@
4017
4058
  do {
4018
4059
  option = null;
4019
4060
  elements = null;
4020
- while (!(option = parserInput.$re(/^(all)(?=\s*(\)|,))/))) {
4061
+ var first = true;
4062
+ while (!(option = parserInput.$re(/^(!?all)(?=\s*(\)|,))/))) {
4021
4063
  e = this.element();
4022
4064
  if (!e) {
4023
4065
  break;
4024
4066
  }
4067
+ /**
4068
+ * @note - This will not catch selectors in pseudos like :is() and :where() because
4069
+ * they don't currently parse their contents as selectors.
4070
+ */
4071
+ if (!first && e.combinator.value) {
4072
+ warn('Targeting complex selectors can have unexpected behavior, and this behavior may change in the future.', index);
4073
+ }
4074
+ first = false;
4025
4075
  if (elements) {
4026
4076
  elements.push(e);
4027
4077
  }
@@ -4081,16 +4131,23 @@
4081
4131
  var elements;
4082
4132
  var args;
4083
4133
  var hasParens;
4134
+ var parensIndex;
4135
+ var parensWS = false;
4084
4136
  if (s !== '.' && s !== '#') {
4085
4137
  return;
4086
4138
  }
4087
4139
  parserInput.save(); // stop us absorbing part of an invalid selector
4088
4140
  elements = this.elements();
4089
4141
  if (elements) {
4142
+ parensIndex = parserInput.i;
4090
4143
  if (parserInput.$char('(')) {
4144
+ parensWS = parserInput.isWhitespace(-2);
4091
4145
  args = this.args(true).args;
4092
4146
  expectChar(')');
4093
4147
  hasParens = true;
4148
+ if (parensWS) {
4149
+ warn('Whitespace between a mixin name and parentheses for a mixin call is deprecated', parensIndex, 'DEPRECATED');
4150
+ }
4094
4151
  }
4095
4152
  if (getLookup !== false) {
4096
4153
  lookups = this.ruleLookups();
@@ -4114,6 +4171,9 @@
4114
4171
  return new tree.NamespaceValue(mixin, lookups);
4115
4172
  }
4116
4173
  else {
4174
+ if (!hasParens) {
4175
+ warn('Calling a mixin without parentheses is deprecated', parensIndex, 'DEPRECATED');
4176
+ }
4117
4177
  return mixin;
4118
4178
  }
4119
4179
  }
@@ -4403,24 +4463,25 @@
4403
4463
  expectChar(')');
4404
4464
  return new tree.Quoted('', "alpha(opacity=".concat(value, ")"));
4405
4465
  },
4406
- //
4407
- // A Selector Element
4408
- //
4409
- // div
4410
- // + h1
4411
- // #socks
4412
- // input[type="text"]
4413
- //
4414
- // Elements are the building blocks for Selectors,
4415
- // they are made out of a `Combinator` (see combinator rule),
4416
- // and an element name, such as a tag a class, or `*`.
4417
- //
4466
+ /**
4467
+ * A Selector Element
4468
+ *
4469
+ * div
4470
+ * + h1
4471
+ * #socks
4472
+ * input[type="text"]
4473
+ *
4474
+ * Elements are the building blocks for Selectors,
4475
+ * they are made out of a `Combinator` (see combinator rule),
4476
+ * and an element name, such as a tag a class, or `*`.
4477
+ */
4418
4478
  element: function () {
4419
4479
  var e;
4420
4480
  var c;
4421
4481
  var v;
4422
4482
  var index = parserInput.i;
4423
4483
  c = this.combinator();
4484
+ /** This selector parser is quite simplistic and will pass a number of invalid selectors. */
4424
4485
  e = parserInput.$re(/^(?:\d+\.\d+|\d+)%/) ||
4425
4486
  // eslint-disable-next-line no-control-regex
4426
4487
  parserInput.$re(/^(?:[.#]?|:*)(?:[\w-]|[^\x00-\x9f]|\\(?:[A-Fa-f0-9]{1,6} ?|[^A-Fa-f0-9]))+/) ||
@@ -4721,7 +4782,7 @@
4721
4782
  value = new Anonymous('');
4722
4783
  }
4723
4784
  else {
4724
- value = this.permissiveValue(/[;}]/);
4785
+ value = this.permissiveValue(/[;}]/, true);
4725
4786
  }
4726
4787
  }
4727
4788
  // Try to store values as anonymous
@@ -4741,7 +4802,12 @@
4741
4802
  important = this.important();
4742
4803
  }
4743
4804
  else if (isVariable) {
4744
- // As a last resort, try permissiveValue
4805
+ /**
4806
+ * As a last resort, try permissiveValue
4807
+ *
4808
+ * @todo - This has created some knock-on problems of not
4809
+ * flagging incorrect syntax or detecting user intent.
4810
+ */
4745
4811
  value = this.permissiveValue();
4746
4812
  }
4747
4813
  }
@@ -4772,6 +4838,8 @@
4772
4838
  * First, it will try to parse comments and entities to reach
4773
4839
  * the end. This is mostly like the Expression parser except no
4774
4840
  * math is allowed.
4841
+ *
4842
+ * @param {RexExp} untilTokens - Characters to stop parsing at
4775
4843
  */
4776
4844
  permissiveValue: function (untilTokens) {
4777
4845
  var i;
@@ -4833,6 +4901,7 @@
4833
4901
  parserInput.forget();
4834
4902
  return new tree.Anonymous('', index);
4835
4903
  }
4904
+ /** @type {string} */
4836
4905
  var item = void 0;
4837
4906
  for (i = 0; i < value.length; i++) {
4838
4907
  item = value[i];
@@ -4846,10 +4915,16 @@
4846
4915
  }
4847
4916
  // Treat like quoted values, but replace vars like unquoted expressions
4848
4917
  var quote = new tree.Quoted('\'', item, true, index, fileInfo);
4849
- if (!item.startsWith('@{')) {
4850
- quote.variableRegex = /@([\w-]+)/g;
4918
+ var variableRegex = /@([\w-]+)/g;
4919
+ var propRegex = /\$([\w-]+)/g;
4920
+ if (variableRegex.test(item)) {
4921
+ warn('@[ident] in unknown values will not be evaluated as variables in the future. Use @{[ident]}', index, 'DEPRECATED');
4851
4922
  }
4852
- quote.propRegex = /\$([\w-]+)/g;
4923
+ if (propRegex.test(item)) {
4924
+ warn('$[ident] in unknown values will not be evaluated as property references in the future. Use ${[ident]}', index, 'DEPRECATED');
4925
+ }
4926
+ quote.variableRegex = /@([\w-]+)|@{([\w-]+)}/g;
4927
+ quote.propRegex = /\$([\w-]+)|\${([\w-]+)}/g;
4853
4928
  result.push(quote);
4854
4929
  }
4855
4930
  }
@@ -5104,6 +5179,7 @@
5104
5179
  var hasUnknown;
5105
5180
  var hasBlock = true;
5106
5181
  var isRooted = true;
5182
+ var isKeywordList = false;
5107
5183
  if (parserInput.currentChar() !== '@') {
5108
5184
  return;
5109
5185
  }
@@ -5138,6 +5214,12 @@
5138
5214
  hasUnknown = true;
5139
5215
  isRooted = false;
5140
5216
  break;
5217
+ case '@starting-style':
5218
+ isRooted = false;
5219
+ break;
5220
+ case '@layer':
5221
+ isRooted = false;
5222
+ break;
5141
5223
  default:
5142
5224
  hasUnknown = true;
5143
5225
  break;
@@ -5169,8 +5251,33 @@
5169
5251
  }
5170
5252
  if (hasBlock) {
5171
5253
  rules = this.blockRuleset();
5254
+ parserInput.save();
5255
+ if (!rules && !isRooted) {
5256
+ value = this.entity();
5257
+ rules = this.blockRuleset();
5258
+ }
5259
+ if (!rules && !isRooted) {
5260
+ parserInput.restore();
5261
+ var e = [];
5262
+ value = this.entity();
5263
+ while (parserInput.$char(',')) {
5264
+ e.push(value);
5265
+ value = this.entity();
5266
+ }
5267
+ if (value && e.length > 0) {
5268
+ e.push(value);
5269
+ value = e;
5270
+ isKeywordList = true;
5271
+ }
5272
+ else {
5273
+ rules = this.blockRuleset();
5274
+ }
5275
+ }
5276
+ else {
5277
+ parserInput.forget();
5278
+ }
5172
5279
  }
5173
- if (rules || (!hasBlock && value && parserInput.$char(';'))) {
5280
+ if (rules || isKeywordList || (!hasBlock && value && parserInput.$char(';'))) {
5174
5281
  parserInput.forget();
5175
5282
  return new (tree.AtRule)(name, value, rules, index + currentIndex, fileInfo, context.dumpLineNumbers ? getDebugInfo(index) : null, isRooted);
5176
5283
  }
@@ -5223,6 +5330,15 @@
5223
5330
  }
5224
5331
  parserInput.restore();
5225
5332
  },
5333
+ colorOperand: function () {
5334
+ parserInput.save();
5335
+ // hsl or rgb or lch operand
5336
+ var match = parserInput.$re(/^[lchrgbs]\s+/);
5337
+ if (match) {
5338
+ return new tree.Keyword(match[0]);
5339
+ }
5340
+ parserInput.restore();
5341
+ },
5226
5342
  multiplication: function () {
5227
5343
  var m;
5228
5344
  var a;
@@ -5237,7 +5353,14 @@
5237
5353
  break;
5238
5354
  }
5239
5355
  parserInput.save();
5240
- op = parserInput.$char('/') || parserInput.$char('*') || parserInput.$str('./');
5356
+ op = parserInput.$char('/') || parserInput.$char('*');
5357
+ if (!op) {
5358
+ var index = parserInput.i;
5359
+ op = parserInput.$str('./');
5360
+ if (op) {
5361
+ warn('./ operator is deprecated', index, 'DEPRECATED');
5362
+ }
5363
+ }
5241
5364
  if (!op) {
5242
5365
  parserInput.forget();
5243
5366
  break;
@@ -5477,7 +5600,7 @@
5477
5600
  entities.color() || entities.variable() ||
5478
5601
  entities.property() || entities.call() ||
5479
5602
  entities.quoted(true) || entities.colorKeyword() ||
5480
- entities.mixinLookup();
5603
+ this.colorOperand() || entities.mixinLookup();
5481
5604
  if (negate) {
5482
5605
  o.parensInOp = true;
5483
5606
  o = new (tree.Negative)(o);
@@ -6654,207 +6777,60 @@
6654
6777
  }
6655
6778
  });
6656
6779
 
6657
- var AtRule = function (name, value, rules, index, currentFileInfo, debugInfo, isRooted, visibilityInfo) {
6658
- var i;
6659
- this.name = name;
6660
- this.value = (value instanceof Node) ? value : (value ? new Anonymous(value) : value);
6661
- if (rules) {
6662
- if (Array.isArray(rules)) {
6663
- this.rules = rules;
6664
- }
6665
- else {
6666
- this.rules = [rules];
6667
- this.rules[0].selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
6668
- }
6669
- for (i = 0; i < this.rules.length; i++) {
6670
- this.rules[i].allowImports = true;
6671
- }
6672
- this.setParent(this.rules, this);
6780
+ var Unit = function (numerator, denominator, backupUnit) {
6781
+ this.numerator = numerator ? copyArray(numerator).sort() : [];
6782
+ this.denominator = denominator ? copyArray(denominator).sort() : [];
6783
+ if (backupUnit) {
6784
+ this.backupUnit = backupUnit;
6785
+ }
6786
+ else if (numerator && numerator.length) {
6787
+ this.backupUnit = numerator[0];
6673
6788
  }
6674
- this._index = index;
6675
- this._fileInfo = currentFileInfo;
6676
- this.debugInfo = debugInfo;
6677
- this.isRooted = isRooted || false;
6678
- this.copyVisibilityInfo(visibilityInfo);
6679
- this.allowRoot = true;
6680
6789
  };
6681
- AtRule.prototype = Object.assign(new Node(), {
6682
- type: 'AtRule',
6683
- accept: function (visitor) {
6684
- var value = this.value, rules = this.rules;
6685
- if (rules) {
6686
- this.rules = visitor.visitArray(rules);
6687
- }
6688
- if (value) {
6689
- this.value = visitor.visit(value);
6690
- }
6691
- },
6692
- isRulesetLike: function () {
6693
- return this.rules || !this.isCharset();
6694
- },
6695
- isCharset: function () {
6696
- return '@charset' === this.name;
6790
+ Unit.prototype = Object.assign(new Node(), {
6791
+ type: 'Unit',
6792
+ clone: function () {
6793
+ return new Unit(copyArray(this.numerator), copyArray(this.denominator), this.backupUnit);
6697
6794
  },
6698
6795
  genCSS: function (context, output) {
6699
- var value = this.value, rules = this.rules;
6700
- output.add(this.name, this.fileInfo(), this.getIndex());
6701
- if (value) {
6702
- output.add(' ');
6703
- value.genCSS(context, output);
6796
+ // Dimension checks the unit is singular and throws an error if in strict math mode.
6797
+ var strictUnits = context && context.strictUnits;
6798
+ if (this.numerator.length === 1) {
6799
+ output.add(this.numerator[0]); // the ideal situation
6704
6800
  }
6705
- if (rules) {
6706
- this.outputRuleset(context, output, rules);
6801
+ else if (!strictUnits && this.backupUnit) {
6802
+ output.add(this.backupUnit);
6707
6803
  }
6708
- else {
6709
- output.add(';');
6804
+ else if (!strictUnits && this.denominator.length) {
6805
+ output.add(this.denominator[0]);
6710
6806
  }
6711
6807
  },
6712
- eval: function (context) {
6713
- var mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules;
6714
- // media stored inside other atrule should not bubble over it
6715
- // backpup media bubbling information
6716
- mediaPathBackup = context.mediaPath;
6717
- mediaBlocksBackup = context.mediaBlocks;
6718
- // deleted media bubbling information
6719
- context.mediaPath = [];
6720
- context.mediaBlocks = [];
6721
- if (value) {
6722
- value = value.eval(context);
6723
- }
6724
- if (rules) {
6725
- // assuming that there is only one rule at this point - that is how parser constructs the rule
6726
- rules = [rules[0].eval(context)];
6727
- rules[0].root = true;
6808
+ toString: function () {
6809
+ var i, returnStr = this.numerator.join('*');
6810
+ for (i = 0; i < this.denominator.length; i++) {
6811
+ returnStr += "/".concat(this.denominator[i]);
6728
6812
  }
6729
- // restore media bubbling information
6730
- context.mediaPath = mediaPathBackup;
6731
- context.mediaBlocks = mediaBlocksBackup;
6732
- return new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
6813
+ return returnStr;
6733
6814
  },
6734
- variable: function (name) {
6735
- if (this.rules) {
6736
- // assuming that there is only one rule at this point - that is how parser constructs the rule
6737
- return Ruleset.prototype.variable.call(this.rules[0], name);
6738
- }
6815
+ compare: function (other) {
6816
+ return this.is(other.toString()) ? 0 : undefined;
6739
6817
  },
6740
- find: function () {
6741
- if (this.rules) {
6742
- // assuming that there is only one rule at this point - that is how parser constructs the rule
6743
- return Ruleset.prototype.find.apply(this.rules[0], arguments);
6744
- }
6818
+ is: function (unitString) {
6819
+ return this.toString().toUpperCase() === unitString.toUpperCase();
6745
6820
  },
6746
- rulesets: function () {
6747
- if (this.rules) {
6748
- // assuming that there is only one rule at this point - that is how parser constructs the rule
6749
- return Ruleset.prototype.rulesets.apply(this.rules[0]);
6750
- }
6821
+ isLength: function () {
6822
+ return RegExp('^(px|em|ex|ch|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'gi').test(this.toCSS());
6751
6823
  },
6752
- outputRuleset: function (context, output, rules) {
6753
- var ruleCnt = rules.length;
6824
+ isEmpty: function () {
6825
+ return this.numerator.length === 0 && this.denominator.length === 0;
6826
+ },
6827
+ isSingular: function () {
6828
+ return this.numerator.length <= 1 && this.denominator.length === 0;
6829
+ },
6830
+ map: function (callback) {
6754
6831
  var i;
6755
- context.tabLevel = (context.tabLevel | 0) + 1;
6756
- // Compressed
6757
- if (context.compress) {
6758
- output.add('{');
6759
- for (i = 0; i < ruleCnt; i++) {
6760
- rules[i].genCSS(context, output);
6761
- }
6762
- output.add('}');
6763
- context.tabLevel--;
6764
- return;
6765
- }
6766
- // Non-compressed
6767
- var tabSetStr = "\n".concat(Array(context.tabLevel).join(' ')), tabRuleStr = "".concat(tabSetStr, " ");
6768
- if (!ruleCnt) {
6769
- output.add(" {".concat(tabSetStr, "}"));
6770
- }
6771
- else {
6772
- output.add(" {".concat(tabRuleStr));
6773
- rules[0].genCSS(context, output);
6774
- for (i = 1; i < ruleCnt; i++) {
6775
- output.add(tabRuleStr);
6776
- rules[i].genCSS(context, output);
6777
- }
6778
- output.add("".concat(tabSetStr, "}"));
6779
- }
6780
- context.tabLevel--;
6781
- }
6782
- });
6783
-
6784
- var DetachedRuleset = function (ruleset, frames) {
6785
- this.ruleset = ruleset;
6786
- this.frames = frames;
6787
- this.setParent(this.ruleset, this);
6788
- };
6789
- DetachedRuleset.prototype = Object.assign(new Node(), {
6790
- type: 'DetachedRuleset',
6791
- evalFirst: true,
6792
- accept: function (visitor) {
6793
- this.ruleset = visitor.visit(this.ruleset);
6794
- },
6795
- eval: function (context) {
6796
- var frames = this.frames || copyArray(context.frames);
6797
- return new DetachedRuleset(this.ruleset, frames);
6798
- },
6799
- callEval: function (context) {
6800
- return this.ruleset.eval(this.frames ? new contexts.Eval(context, this.frames.concat(context.frames)) : context);
6801
- }
6802
- });
6803
-
6804
- var Unit = function (numerator, denominator, backupUnit) {
6805
- this.numerator = numerator ? copyArray(numerator).sort() : [];
6806
- this.denominator = denominator ? copyArray(denominator).sort() : [];
6807
- if (backupUnit) {
6808
- this.backupUnit = backupUnit;
6809
- }
6810
- else if (numerator && numerator.length) {
6811
- this.backupUnit = numerator[0];
6812
- }
6813
- };
6814
- Unit.prototype = Object.assign(new Node(), {
6815
- type: 'Unit',
6816
- clone: function () {
6817
- return new Unit(copyArray(this.numerator), copyArray(this.denominator), this.backupUnit);
6818
- },
6819
- genCSS: function (context, output) {
6820
- // Dimension checks the unit is singular and throws an error if in strict math mode.
6821
- var strictUnits = context && context.strictUnits;
6822
- if (this.numerator.length === 1) {
6823
- output.add(this.numerator[0]); // the ideal situation
6824
- }
6825
- else if (!strictUnits && this.backupUnit) {
6826
- output.add(this.backupUnit);
6827
- }
6828
- else if (!strictUnits && this.denominator.length) {
6829
- output.add(this.denominator[0]);
6830
- }
6831
- },
6832
- toString: function () {
6833
- var i, returnStr = this.numerator.join('*');
6834
- for (i = 0; i < this.denominator.length; i++) {
6835
- returnStr += "/".concat(this.denominator[i]);
6836
- }
6837
- return returnStr;
6838
- },
6839
- compare: function (other) {
6840
- return this.is(other.toString()) ? 0 : undefined;
6841
- },
6842
- is: function (unitString) {
6843
- return this.toString().toUpperCase() === unitString.toUpperCase();
6844
- },
6845
- isLength: function () {
6846
- return RegExp('^(px|em|ex|ch|rem|in|cm|mm|pc|pt|ex|vw|vh|vmin|vmax)$', 'gi').test(this.toCSS());
6847
- },
6848
- isEmpty: function () {
6849
- return this.numerator.length === 0 && this.denominator.length === 0;
6850
- },
6851
- isSingular: function () {
6852
- return this.numerator.length <= 1 && this.denominator.length === 0;
6853
- },
6854
- map: function (callback) {
6855
- var i;
6856
- for (i = 0; i < this.numerator.length; i++) {
6857
- this.numerator[i] = callback(this.numerator[i], false);
6832
+ for (i = 0; i < this.numerator.length; i++) {
6833
+ this.numerator[i] = callback(this.numerator[i], false);
6858
6834
  }
6859
6835
  for (i = 0; i < this.denominator.length; i++) {
6860
6836
  this.denominator[i] = callback(this.denominator[i], true);
@@ -7007,61 +6983,456 @@
7007
6983
  if (!(other instanceof Dimension)) {
7008
6984
  return undefined;
7009
6985
  }
7010
- if (this.unit.isEmpty() || other.unit.isEmpty()) {
7011
- a = this;
7012
- b = other;
6986
+ if (this.unit.isEmpty() || other.unit.isEmpty()) {
6987
+ a = this;
6988
+ b = other;
6989
+ }
6990
+ else {
6991
+ a = this.unify();
6992
+ b = other.unify();
6993
+ if (a.unit.compare(b.unit) !== 0) {
6994
+ return undefined;
6995
+ }
6996
+ }
6997
+ return Node.numericCompare(a.value, b.value);
6998
+ },
6999
+ unify: function () {
7000
+ return this.convertTo({ length: 'px', duration: 's', angle: 'rad' });
7001
+ },
7002
+ convertTo: function (conversions) {
7003
+ var value = this.value;
7004
+ var unit = this.unit.clone();
7005
+ var i;
7006
+ var groupName;
7007
+ var group;
7008
+ var targetUnit;
7009
+ var derivedConversions = {};
7010
+ var applyUnit;
7011
+ if (typeof conversions === 'string') {
7012
+ for (i in unitConversions) {
7013
+ if (unitConversions[i].hasOwnProperty(conversions)) {
7014
+ derivedConversions = {};
7015
+ derivedConversions[i] = conversions;
7016
+ }
7017
+ }
7018
+ conversions = derivedConversions;
7019
+ }
7020
+ applyUnit = function (atomicUnit, denominator) {
7021
+ if (group.hasOwnProperty(atomicUnit)) {
7022
+ if (denominator) {
7023
+ value = value / (group[atomicUnit] / group[targetUnit]);
7024
+ }
7025
+ else {
7026
+ value = value * (group[atomicUnit] / group[targetUnit]);
7027
+ }
7028
+ return targetUnit;
7029
+ }
7030
+ return atomicUnit;
7031
+ };
7032
+ for (groupName in conversions) {
7033
+ if (conversions.hasOwnProperty(groupName)) {
7034
+ targetUnit = conversions[groupName];
7035
+ group = unitConversions[groupName];
7036
+ unit.map(applyUnit);
7037
+ }
7038
+ }
7039
+ unit.cancel();
7040
+ return new Dimension(value, unit);
7041
+ }
7042
+ });
7043
+
7044
+ var Expression = function (value, noSpacing) {
7045
+ this.value = value;
7046
+ this.noSpacing = noSpacing;
7047
+ if (!value) {
7048
+ throw new Error('Expression requires an array parameter');
7049
+ }
7050
+ };
7051
+ Expression.prototype = Object.assign(new Node(), {
7052
+ type: 'Expression',
7053
+ accept: function (visitor) {
7054
+ this.value = visitor.visitArray(this.value);
7055
+ },
7056
+ eval: function (context) {
7057
+ var noSpacing = this.noSpacing;
7058
+ var returnValue;
7059
+ var mathOn = context.isMathOn();
7060
+ var inParenthesis = this.parens;
7061
+ var doubleParen = false;
7062
+ if (inParenthesis) {
7063
+ context.inParenthesis();
7064
+ }
7065
+ if (this.value.length > 1) {
7066
+ returnValue = new Expression(this.value.map(function (e) {
7067
+ if (!e.eval) {
7068
+ return e;
7069
+ }
7070
+ return e.eval(context);
7071
+ }), this.noSpacing);
7072
+ }
7073
+ else if (this.value.length === 1) {
7074
+ if (this.value[0].parens && !this.value[0].parensInOp && !context.inCalc) {
7075
+ doubleParen = true;
7076
+ }
7077
+ returnValue = this.value[0].eval(context);
7078
+ }
7079
+ else {
7080
+ returnValue = this;
7081
+ }
7082
+ if (inParenthesis) {
7083
+ context.outOfParenthesis();
7084
+ }
7085
+ if (this.parens && this.parensInOp && !mathOn && !doubleParen
7086
+ && (!(returnValue instanceof Dimension))) {
7087
+ returnValue = new Paren(returnValue);
7088
+ }
7089
+ returnValue.noSpacing = returnValue.noSpacing || noSpacing;
7090
+ return returnValue;
7091
+ },
7092
+ genCSS: function (context, output) {
7093
+ for (var i_1 = 0; i_1 < this.value.length; i_1++) {
7094
+ this.value[i_1].genCSS(context, output);
7095
+ if (!this.noSpacing && i_1 + 1 < this.value.length) {
7096
+ if (i_1 + 1 < this.value.length && !(this.value[i_1 + 1] instanceof Anonymous) ||
7097
+ this.value[i_1 + 1] instanceof Anonymous && this.value[i_1 + 1].value !== ',') {
7098
+ output.add(' ');
7099
+ }
7100
+ }
7101
+ }
7102
+ },
7103
+ throwAwayComments: function () {
7104
+ this.value = this.value.filter(function (v) {
7105
+ return !(v instanceof Comment);
7106
+ });
7107
+ }
7108
+ });
7109
+
7110
+ var NestableAtRulePrototype = {
7111
+ isRulesetLike: function () {
7112
+ return true;
7113
+ },
7114
+ accept: function (visitor) {
7115
+ if (this.features) {
7116
+ this.features = visitor.visit(this.features);
7117
+ }
7118
+ if (this.rules) {
7119
+ this.rules = visitor.visitArray(this.rules);
7120
+ }
7121
+ },
7122
+ evalTop: function (context) {
7123
+ var result = this;
7124
+ // Render all dependent Media blocks.
7125
+ if (context.mediaBlocks.length > 1) {
7126
+ var selectors = (new Selector([], null, null, this.getIndex(), this.fileInfo())).createEmptySelectors();
7127
+ result = new Ruleset(selectors, context.mediaBlocks);
7128
+ result.multiMedia = true;
7129
+ result.copyVisibilityInfo(this.visibilityInfo());
7130
+ this.setParent(result, this);
7131
+ }
7132
+ delete context.mediaBlocks;
7133
+ delete context.mediaPath;
7134
+ return result;
7135
+ },
7136
+ evalNested: function (context) {
7137
+ var i;
7138
+ var value;
7139
+ var path = context.mediaPath.concat([this]);
7140
+ // Extract the media-query conditions separated with `,` (OR).
7141
+ for (i = 0; i < path.length; i++) {
7142
+ if (path[i].type !== this.type) {
7143
+ context.mediaBlocks.splice(i, 1);
7144
+ return this;
7145
+ }
7146
+ value = path[i].features instanceof Value ?
7147
+ path[i].features.value : path[i].features;
7148
+ path[i] = Array.isArray(value) ? value : [value];
7149
+ }
7150
+ // Trace all permutations to generate the resulting media-query.
7151
+ //
7152
+ // (a, b and c) with nested (d, e) ->
7153
+ // a and d
7154
+ // a and e
7155
+ // b and c and d
7156
+ // b and c and e
7157
+ this.features = new Value(this.permute(path).map(function (path) {
7158
+ path = path.map(function (fragment) { return fragment.toCSS ? fragment : new Anonymous(fragment); });
7159
+ for (i = path.length - 1; i > 0; i--) {
7160
+ path.splice(i, 0, new Anonymous('and'));
7161
+ }
7162
+ return new Expression(path);
7163
+ }));
7164
+ this.setParent(this.features, this);
7165
+ // Fake a tree-node that doesn't output anything.
7166
+ return new Ruleset([], []);
7167
+ },
7168
+ permute: function (arr) {
7169
+ if (arr.length === 0) {
7170
+ return [];
7171
+ }
7172
+ else if (arr.length === 1) {
7173
+ return arr[0];
7174
+ }
7175
+ else {
7176
+ var result = [];
7177
+ var rest = this.permute(arr.slice(1));
7178
+ for (var i_1 = 0; i_1 < rest.length; i_1++) {
7179
+ for (var j = 0; j < arr[0].length; j++) {
7180
+ result.push([arr[0][j]].concat(rest[i_1]));
7181
+ }
7182
+ }
7183
+ return result;
7184
+ }
7185
+ },
7186
+ bubbleSelectors: function (selectors) {
7187
+ if (!selectors) {
7188
+ return;
7189
+ }
7190
+ this.rules = [new Ruleset(copyArray(selectors), [this.rules[0]])];
7191
+ this.setParent(this.rules, this);
7192
+ }
7193
+ };
7194
+
7195
+ var AtRule = function (name, value, rules, index, currentFileInfo, debugInfo, isRooted, visibilityInfo) {
7196
+ var _this = this;
7197
+ var i;
7198
+ var selectors = (new Selector([], null, null, this._index, this._fileInfo)).createEmptySelectors();
7199
+ this.name = name;
7200
+ this.value = (value instanceof Node) ? value : (value ? new Anonymous(value) : value);
7201
+ if (rules) {
7202
+ if (Array.isArray(rules)) {
7203
+ var allDeclarations = this.declarationsBlock(rules);
7204
+ var allRulesetDeclarations_1 = true;
7205
+ rules.forEach(function (rule) {
7206
+ if (rule.type === 'Ruleset' && rule.rules)
7207
+ allRulesetDeclarations_1 = allRulesetDeclarations_1 && _this.declarationsBlock(rule.rules, true);
7208
+ });
7209
+ if (allDeclarations && !isRooted) {
7210
+ this.simpleBlock = true;
7211
+ this.declarations = rules;
7212
+ }
7213
+ else if (allRulesetDeclarations_1 && rules.length === 1 && !isRooted && !value) {
7214
+ this.simpleBlock = true;
7215
+ this.declarations = rules[0].rules ? rules[0].rules : rules;
7216
+ }
7217
+ else {
7218
+ this.rules = rules;
7219
+ }
7220
+ }
7221
+ else {
7222
+ var allDeclarations = this.declarationsBlock(rules.rules);
7223
+ if (allDeclarations && !isRooted && !value) {
7224
+ this.simpleBlock = true;
7225
+ this.declarations = rules.rules;
7226
+ }
7227
+ else {
7228
+ this.rules = [rules];
7229
+ this.rules[0].selectors = (new Selector([], null, null, index, currentFileInfo)).createEmptySelectors();
7230
+ }
7231
+ }
7232
+ if (!this.simpleBlock) {
7233
+ for (i = 0; i < this.rules.length; i++) {
7234
+ this.rules[i].allowImports = true;
7235
+ }
7236
+ }
7237
+ this.setParent(selectors, this);
7238
+ this.setParent(this.rules, this);
7239
+ }
7240
+ this._index = index;
7241
+ this._fileInfo = currentFileInfo;
7242
+ this.debugInfo = debugInfo;
7243
+ this.isRooted = isRooted || false;
7244
+ this.copyVisibilityInfo(visibilityInfo);
7245
+ this.allowRoot = true;
7246
+ };
7247
+ AtRule.prototype = Object.assign(new Node(), __assign(__assign({ type: 'AtRule' }, NestableAtRulePrototype), { declarationsBlock: function (rules, mergeable) {
7248
+ if (mergeable === void 0) { mergeable = false; }
7249
+ if (!mergeable) {
7250
+ return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment') && !node.merge; }).length === rules.length;
7251
+ }
7252
+ else {
7253
+ return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment'); }).length === rules.length;
7254
+ }
7255
+ }, keywordList: function (rules) {
7256
+ if (!Array.isArray(rules)) {
7257
+ return false;
7258
+ }
7259
+ else {
7260
+ return rules.filter(function (node) { return (node.type === 'Keyword' || node.type === 'Comment'); }).length === rules.length;
7261
+ }
7262
+ }, accept: function (visitor) {
7263
+ var value = this.value, rules = this.rules, declarations = this.declarations;
7264
+ if (rules) {
7265
+ this.rules = visitor.visitArray(rules);
7266
+ }
7267
+ else if (declarations) {
7268
+ this.declarations = visitor.visitArray(declarations);
7269
+ }
7270
+ if (value) {
7271
+ this.value = visitor.visit(value);
7272
+ }
7273
+ }, isRulesetLike: function () {
7274
+ return this.rules || !this.isCharset();
7275
+ }, isCharset: function () {
7276
+ return '@charset' === this.name;
7277
+ }, genCSS: function (context, output) {
7278
+ var value = this.value, rules = this.rules || this.declarations;
7279
+ output.add(this.name, this.fileInfo(), this.getIndex());
7280
+ if (value) {
7281
+ output.add(' ');
7282
+ value.genCSS(context, output);
7283
+ }
7284
+ if (this.simpleBlock) {
7285
+ this.outputRuleset(context, output, this.declarations);
7286
+ }
7287
+ else if (rules) {
7288
+ this.outputRuleset(context, output, rules);
7289
+ }
7290
+ else {
7291
+ output.add(';');
7292
+ }
7293
+ }, eval: function (context) {
7294
+ var mediaPathBackup, mediaBlocksBackup, value = this.value, rules = this.rules || this.declarations;
7295
+ // media stored inside other atrule should not bubble over it
7296
+ // backpup media bubbling information
7297
+ mediaPathBackup = context.mediaPath;
7298
+ mediaBlocksBackup = context.mediaBlocks;
7299
+ // deleted media bubbling information
7300
+ context.mediaPath = [];
7301
+ context.mediaBlocks = [];
7302
+ if (value) {
7303
+ value = value.eval(context);
7304
+ if (value.value && this.keywordList(value.value)) {
7305
+ value = new Anonymous(value.value.map(function (keyword) { return keyword.value; }).join(', '), this.getIndex(), this.fileInfo());
7306
+ }
7307
+ }
7308
+ if (rules) {
7309
+ rules = this.evalRoot(context, rules);
7310
+ }
7311
+ if (Array.isArray(rules) && rules[0].rules && Array.isArray(rules[0].rules) && rules[0].rules.length) {
7312
+ var allMergeableDeclarations = this.declarationsBlock(rules[0].rules, true);
7313
+ if (allMergeableDeclarations && !this.isRooted && !value) {
7314
+ var mergeRules = context.pluginManager.less.visitors.ToCSSVisitor.prototype._mergeRules;
7315
+ mergeRules(rules[0].rules);
7316
+ rules = rules[0].rules;
7317
+ rules.forEach(function (rule) { return rule.merge = false; });
7318
+ }
7319
+ }
7320
+ if (this.simpleBlock && rules) {
7321
+ rules[0].functionRegistry = context.frames[0].functionRegistry.inherit();
7322
+ rules = rules.map(function (rule) { return rule.eval(context); });
7323
+ }
7324
+ // restore media bubbling information
7325
+ context.mediaPath = mediaPathBackup;
7326
+ context.mediaBlocks = mediaBlocksBackup;
7327
+ return new AtRule(this.name, value, rules, this.getIndex(), this.fileInfo(), this.debugInfo, this.isRooted, this.visibilityInfo());
7328
+ }, evalRoot: function (context, rules) {
7329
+ var ampersandCount = 0;
7330
+ var noAmpersandCount = 0;
7331
+ var noAmpersands = true;
7332
+ var allAmpersands = false;
7333
+ if (!this.simpleBlock) {
7334
+ rules = [rules[0].eval(context)];
7335
+ }
7336
+ var precedingSelectors = [];
7337
+ if (context.frames.length > 0) {
7338
+ var _loop_1 = function (index) {
7339
+ var frame = context.frames[index];
7340
+ if (frame.type === 'Ruleset' &&
7341
+ frame.rules &&
7342
+ frame.rules.length > 0) {
7343
+ if (frame && !frame.root && frame.selectors && frame.selectors.length > 0) {
7344
+ precedingSelectors = precedingSelectors.concat(frame.selectors);
7345
+ }
7346
+ }
7347
+ if (precedingSelectors.length > 0) {
7348
+ var value_1 = '';
7349
+ var output = { add: function (s) { value_1 += s; } };
7350
+ for (var i_1 = 0; i_1 < precedingSelectors.length; i_1++) {
7351
+ precedingSelectors[i_1].genCSS(context, output);
7352
+ }
7353
+ if (/^&+$/.test(value_1.replace(/\s+/g, ''))) {
7354
+ noAmpersands = false;
7355
+ noAmpersandCount++;
7356
+ }
7357
+ else {
7358
+ allAmpersands = false;
7359
+ ampersandCount++;
7360
+ }
7361
+ }
7362
+ };
7363
+ for (var index = 0; index < context.frames.length; index++) {
7364
+ _loop_1(index);
7365
+ }
7366
+ }
7367
+ var mixedAmpersands = ampersandCount > 0 && noAmpersandCount > 0 && !allAmpersands && !noAmpersands;
7368
+ if ((this.isRooted && ampersandCount > 0 && noAmpersandCount === 0 && !allAmpersands && noAmpersands)
7369
+ || !mixedAmpersands) {
7370
+ rules[0].root = true;
7371
+ }
7372
+ return rules;
7373
+ }, variable: function (name) {
7374
+ if (this.rules) {
7375
+ // assuming that there is only one rule at this point - that is how parser constructs the rule
7376
+ return Ruleset.prototype.variable.call(this.rules[0], name);
7377
+ }
7378
+ }, find: function () {
7379
+ if (this.rules) {
7380
+ // assuming that there is only one rule at this point - that is how parser constructs the rule
7381
+ return Ruleset.prototype.find.apply(this.rules[0], arguments);
7382
+ }
7383
+ }, rulesets: function () {
7384
+ if (this.rules) {
7385
+ // assuming that there is only one rule at this point - that is how parser constructs the rule
7386
+ return Ruleset.prototype.rulesets.apply(this.rules[0]);
7387
+ }
7388
+ }, outputRuleset: function (context, output, rules) {
7389
+ var ruleCnt = rules.length;
7390
+ var i;
7391
+ context.tabLevel = (context.tabLevel | 0) + 1;
7392
+ // Compressed
7393
+ if (context.compress) {
7394
+ output.add('{');
7395
+ for (i = 0; i < ruleCnt; i++) {
7396
+ rules[i].genCSS(context, output);
7397
+ }
7398
+ output.add('}');
7399
+ context.tabLevel--;
7400
+ return;
7401
+ }
7402
+ // Non-compressed
7403
+ var tabSetStr = "\n".concat(Array(context.tabLevel).join(' ')), tabRuleStr = "".concat(tabSetStr, " ");
7404
+ if (!ruleCnt) {
7405
+ output.add(" {".concat(tabSetStr, "}"));
7013
7406
  }
7014
7407
  else {
7015
- a = this.unify();
7016
- b = other.unify();
7017
- if (a.unit.compare(b.unit) !== 0) {
7018
- return undefined;
7408
+ output.add(" {".concat(tabRuleStr));
7409
+ rules[0].genCSS(context, output);
7410
+ for (i = 1; i < ruleCnt; i++) {
7411
+ output.add(tabRuleStr);
7412
+ rules[i].genCSS(context, output);
7019
7413
  }
7414
+ output.add("".concat(tabSetStr, "}"));
7020
7415
  }
7021
- return Node.numericCompare(a.value, b.value);
7416
+ context.tabLevel--;
7417
+ } }));
7418
+
7419
+ var DetachedRuleset = function (ruleset, frames) {
7420
+ this.ruleset = ruleset;
7421
+ this.frames = frames;
7422
+ this.setParent(this.ruleset, this);
7423
+ };
7424
+ DetachedRuleset.prototype = Object.assign(new Node(), {
7425
+ type: 'DetachedRuleset',
7426
+ evalFirst: true,
7427
+ accept: function (visitor) {
7428
+ this.ruleset = visitor.visit(this.ruleset);
7022
7429
  },
7023
- unify: function () {
7024
- return this.convertTo({ length: 'px', duration: 's', angle: 'rad' });
7430
+ eval: function (context) {
7431
+ var frames = this.frames || copyArray(context.frames);
7432
+ return new DetachedRuleset(this.ruleset, frames);
7025
7433
  },
7026
- convertTo: function (conversions) {
7027
- var value = this.value;
7028
- var unit = this.unit.clone();
7029
- var i;
7030
- var groupName;
7031
- var group;
7032
- var targetUnit;
7033
- var derivedConversions = {};
7034
- var applyUnit;
7035
- if (typeof conversions === 'string') {
7036
- for (i in unitConversions) {
7037
- if (unitConversions[i].hasOwnProperty(conversions)) {
7038
- derivedConversions = {};
7039
- derivedConversions[i] = conversions;
7040
- }
7041
- }
7042
- conversions = derivedConversions;
7043
- }
7044
- applyUnit = function (atomicUnit, denominator) {
7045
- if (group.hasOwnProperty(atomicUnit)) {
7046
- if (denominator) {
7047
- value = value / (group[atomicUnit] / group[targetUnit]);
7048
- }
7049
- else {
7050
- value = value * (group[atomicUnit] / group[targetUnit]);
7051
- }
7052
- return targetUnit;
7053
- }
7054
- return atomicUnit;
7055
- };
7056
- for (groupName in conversions) {
7057
- if (conversions.hasOwnProperty(groupName)) {
7058
- targetUnit = conversions[groupName];
7059
- group = unitConversions[groupName];
7060
- unit.map(applyUnit);
7061
- }
7062
- }
7063
- unit.cancel();
7064
- return new Dimension(value, unit);
7434
+ callEval: function (context) {
7435
+ return this.ruleset.eval(this.frames ? new contexts.Eval(context, this.frames.concat(context.frames)) : context);
7065
7436
  }
7066
7437
  });
7067
7438
 
@@ -7113,70 +7484,6 @@
7113
7484
  }
7114
7485
  });
7115
7486
 
7116
- var Expression = function (value, noSpacing) {
7117
- this.value = value;
7118
- this.noSpacing = noSpacing;
7119
- if (!value) {
7120
- throw new Error('Expression requires an array parameter');
7121
- }
7122
- };
7123
- Expression.prototype = Object.assign(new Node(), {
7124
- type: 'Expression',
7125
- accept: function (visitor) {
7126
- this.value = visitor.visitArray(this.value);
7127
- },
7128
- eval: function (context) {
7129
- var returnValue;
7130
- var mathOn = context.isMathOn();
7131
- var inParenthesis = this.parens;
7132
- var doubleParen = false;
7133
- if (inParenthesis) {
7134
- context.inParenthesis();
7135
- }
7136
- if (this.value.length > 1) {
7137
- returnValue = new Expression(this.value.map(function (e) {
7138
- if (!e.eval) {
7139
- return e;
7140
- }
7141
- return e.eval(context);
7142
- }), this.noSpacing);
7143
- }
7144
- else if (this.value.length === 1) {
7145
- if (this.value[0].parens && !this.value[0].parensInOp && !context.inCalc) {
7146
- doubleParen = true;
7147
- }
7148
- returnValue = this.value[0].eval(context);
7149
- }
7150
- else {
7151
- returnValue = this;
7152
- }
7153
- if (inParenthesis) {
7154
- context.outOfParenthesis();
7155
- }
7156
- if (this.parens && this.parensInOp && !mathOn && !doubleParen
7157
- && (!(returnValue instanceof Dimension))) {
7158
- returnValue = new Paren(returnValue);
7159
- }
7160
- return returnValue;
7161
- },
7162
- genCSS: function (context, output) {
7163
- for (var i_1 = 0; i_1 < this.value.length; i_1++) {
7164
- this.value[i_1].genCSS(context, output);
7165
- if (!this.noSpacing && i_1 + 1 < this.value.length) {
7166
- if (i_1 + 1 < this.value.length && !(this.value[i_1 + 1] instanceof Anonymous) ||
7167
- this.value[i_1 + 1] instanceof Anonymous && this.value[i_1 + 1].value !== ',') {
7168
- output.add(' ');
7169
- }
7170
- }
7171
- }
7172
- },
7173
- throwAwayComments: function () {
7174
- this.value = this.value.filter(function (v) {
7175
- return !(v instanceof Comment);
7176
- });
7177
- }
7178
- });
7179
-
7180
7487
  var functionCaller = /** @class */ (function () {
7181
7488
  function functionCaller(name, context, index, currentFileInfo) {
7182
7489
  this.name = name.toLowerCase();
@@ -7493,12 +7800,12 @@
7493
7800
  eval: function (context) {
7494
7801
  var that = this;
7495
7802
  var value = this.value;
7496
- var variableReplacement = function (_, name) {
7497
- var v = new Variable("@".concat(name), that.getIndex(), that.fileInfo()).eval(context, true);
7803
+ var variableReplacement = function (_, name1, name2) {
7804
+ var v = new Variable("@".concat(name1 !== null && name1 !== void 0 ? name1 : name2), that.getIndex(), that.fileInfo()).eval(context, true);
7498
7805
  return (v instanceof Quoted) ? v.value : v.toCSS();
7499
7806
  };
7500
- var propertyReplacement = function (_, name) {
7501
- var v = new Property("$".concat(name), that.getIndex(), that.fileInfo()).eval(context, true);
7807
+ var propertyReplacement = function (_, name1, name2) {
7808
+ var v = new Property("$".concat(name1 !== null && name1 !== void 0 ? name1 : name2), that.getIndex(), that.fileInfo()).eval(context, true);
7502
7809
  return (v instanceof Quoted) ? v.value : v.toCSS();
7503
7810
  };
7504
7811
  function iterativeReplace(value, regexp, replacementFnc) {
@@ -7578,91 +7885,6 @@
7578
7885
  }
7579
7886
  });
7580
7887
 
7581
- var NestableAtRulePrototype = {
7582
- isRulesetLike: function () {
7583
- return true;
7584
- },
7585
- accept: function (visitor) {
7586
- if (this.features) {
7587
- this.features = visitor.visit(this.features);
7588
- }
7589
- if (this.rules) {
7590
- this.rules = visitor.visitArray(this.rules);
7591
- }
7592
- },
7593
- evalTop: function (context) {
7594
- var result = this;
7595
- // Render all dependent Media blocks.
7596
- if (context.mediaBlocks.length > 1) {
7597
- var selectors = (new Selector([], null, null, this.getIndex(), this.fileInfo())).createEmptySelectors();
7598
- result = new Ruleset(selectors, context.mediaBlocks);
7599
- result.multiMedia = true;
7600
- result.copyVisibilityInfo(this.visibilityInfo());
7601
- this.setParent(result, this);
7602
- }
7603
- delete context.mediaBlocks;
7604
- delete context.mediaPath;
7605
- return result;
7606
- },
7607
- evalNested: function (context) {
7608
- var i;
7609
- var value;
7610
- var path = context.mediaPath.concat([this]);
7611
- // Extract the media-query conditions separated with `,` (OR).
7612
- for (i = 0; i < path.length; i++) {
7613
- if (path[i].type !== this.type) {
7614
- context.mediaBlocks.splice(i, 1);
7615
- return this;
7616
- }
7617
- value = path[i].features instanceof Value ?
7618
- path[i].features.value : path[i].features;
7619
- path[i] = Array.isArray(value) ? value : [value];
7620
- }
7621
- // Trace all permutations to generate the resulting media-query.
7622
- //
7623
- // (a, b and c) with nested (d, e) ->
7624
- // a and d
7625
- // a and e
7626
- // b and c and d
7627
- // b and c and e
7628
- this.features = new Value(this.permute(path).map(function (path) {
7629
- path = path.map(function (fragment) { return fragment.toCSS ? fragment : new Anonymous(fragment); });
7630
- for (i = path.length - 1; i > 0; i--) {
7631
- path.splice(i, 0, new Anonymous('and'));
7632
- }
7633
- return new Expression(path);
7634
- }));
7635
- this.setParent(this.features, this);
7636
- // Fake a tree-node that doesn't output anything.
7637
- return new Ruleset([], []);
7638
- },
7639
- permute: function (arr) {
7640
- if (arr.length === 0) {
7641
- return [];
7642
- }
7643
- else if (arr.length === 1) {
7644
- return arr[0];
7645
- }
7646
- else {
7647
- var result = [];
7648
- var rest = this.permute(arr.slice(1));
7649
- for (var i_1 = 0; i_1 < rest.length; i_1++) {
7650
- for (var j = 0; j < arr[0].length; j++) {
7651
- result.push([arr[0][j]].concat(rest[i_1]));
7652
- }
7653
- }
7654
- return result;
7655
- }
7656
- },
7657
- bubbleSelectors: function (selectors) {
7658
- if (!selectors) {
7659
- return;
7660
- }
7661
- this.rules = [new Ruleset(copyArray(selectors), [this.rules[0]])];
7662
- this.setParent(this.rules, this);
7663
- }
7664
- };
7665
-
7666
7888
  var Media = function (value, features, index, currentFileInfo, visibilityInfo) {
7667
7889
  this._index = index;
7668
7890
  this._fileInfo = currentFileInfo;
@@ -7836,6 +8058,20 @@
7836
8058
  return [];
7837
8059
  }
7838
8060
  }
8061
+ if (this.features) {
8062
+ var featureValue = this.features.value;
8063
+ if (Array.isArray(featureValue) && featureValue.length >= 1) {
8064
+ var expr = featureValue[0];
8065
+ if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
8066
+ featureValue = expr.value;
8067
+ var isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
8068
+ && featureValue[1].type === 'Paren';
8069
+ if (isLayer) {
8070
+ this.css = false;
8071
+ }
8072
+ }
8073
+ }
8074
+ }
7839
8075
  if (this.options.inline) {
7840
8076
  var contents = new Anonymous(this.root, 0, {
7841
8077
  filename: this.importedFilename,
@@ -7843,19 +8079,58 @@
7843
8079
  }, true, true);
7844
8080
  return this.features ? new Media([contents], this.features.value) : [contents];
7845
8081
  }
7846
- else if (this.css) {
8082
+ else if (this.css || this.layerCss) {
7847
8083
  var newImport = new Import(this.evalPath(context), features, this.options, this._index);
8084
+ if (this.layerCss) {
8085
+ newImport.css = this.layerCss;
8086
+ newImport.path._fileInfo = this._fileInfo;
8087
+ }
7848
8088
  if (!newImport.css && this.error) {
7849
8089
  throw this.error;
7850
8090
  }
7851
8091
  return newImport;
7852
8092
  }
7853
8093
  else if (this.root) {
8094
+ if (this.features) {
8095
+ var featureValue = this.features.value;
8096
+ if (Array.isArray(featureValue) && featureValue.length === 1) {
8097
+ var expr = featureValue[0];
8098
+ if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
8099
+ featureValue = expr.value;
8100
+ var isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
8101
+ && featureValue[1].type === 'Paren';
8102
+ if (isLayer) {
8103
+ this.layerCss = true;
8104
+ featureValue[0] = new Expression(featureValue.slice(0, 2));
8105
+ featureValue.splice(1, 1);
8106
+ featureValue[0].noSpacing = true;
8107
+ return this;
8108
+ }
8109
+ }
8110
+ }
8111
+ }
7854
8112
  ruleset = new Ruleset(null, copyArray(this.root.rules));
7855
8113
  ruleset.evalImports(context);
7856
8114
  return this.features ? new Media(ruleset.rules, this.features.value) : ruleset.rules;
7857
8115
  }
7858
8116
  else {
8117
+ if (this.features) {
8118
+ var featureValue = this.features.value;
8119
+ if (Array.isArray(featureValue) && featureValue.length >= 1) {
8120
+ featureValue = featureValue[0].value;
8121
+ if (Array.isArray(featureValue) && featureValue.length >= 2) {
8122
+ var isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
8123
+ && featureValue[1].type === 'Paren';
8124
+ if (isLayer) {
8125
+ this.css = true;
8126
+ featureValue[0] = new Expression(featureValue.slice(0, 2));
8127
+ featureValue.splice(1, 1);
8128
+ featureValue[0].noSpacing = true;
8129
+ return this;
8130
+ }
8131
+ }
8132
+ }
8133
+ }
7859
8134
  return [];
7860
8135
  }
7861
8136
  }
@@ -8140,6 +8415,7 @@
8140
8415
  this.copyVisibilityInfo(visibilityInfo);
8141
8416
  this.allowRoot = true;
8142
8417
  switch (option) {
8418
+ case '!all':
8143
8419
  case 'all':
8144
8420
  this.allowBefore = true;
8145
8421
  this.allowAfter = true;
@@ -10852,22 +11128,25 @@
10852
11128
  return render;
10853
11129
  }
10854
11130
 
10855
- var version = "4.2.2";
11131
+ var version = "4.4.0";
11132
+
11133
+ function parseNodeVersion(version) {
11134
+ var match = version.match(/^v(\d{1,2})\.(\d{1,2})\.(\d{1,2})(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$/); // eslint-disable-line max-len
11135
+ if (!match) {
11136
+ throw new Error('Unable to parse: ' + version);
11137
+ }
11138
+
11139
+ var res = {
11140
+ major: parseInt(match[1], 10),
11141
+ minor: parseInt(match[2], 10),
11142
+ patch: parseInt(match[3], 10),
11143
+ pre: match[4] || '',
11144
+ build: match[5] || '',
11145
+ };
11146
+
11147
+ return res;
11148
+ }
10856
11149
 
10857
- function parseNodeVersion(version) {
10858
- var match = version.match(/^v(\d{1,2})\.(\d{1,2})\.(\d{1,2})(?:-([0-9A-Za-z-.]+))?(?:\+([0-9A-Za-z-.]+))?$/); // eslint-disable-line max-len
10859
- if (!match) {
10860
- throw new Error('Unable to parse: ' + version);
10861
- }
10862
- var res = {
10863
- major: parseInt(match[1], 10),
10864
- minor: parseInt(match[2], 10),
10865
- patch: parseInt(match[3], 10),
10866
- pre: match[4] || '',
10867
- build: match[5] || '',
10868
- };
10869
- return res;
10870
- }
10871
11150
  var parseNodeVersion_1 = parseNodeVersion;
10872
11151
 
10873
11152
  function lessRoot (environment, fileManagers) {