less 4.3.0 → 4.4.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.
package/dist/less.js CHANGED
@@ -1,5 +1,5 @@
1
1
  /**
2
- * Less - Leaner CSS v4.3.0
2
+ * Less - Leaner CSS v4.4.1
3
3
  * http://lesscss.org
4
4
  *
5
5
  * Copyright (c) 2009-2025, Alexis Sellier <self@cloudhead.net>
@@ -908,7 +908,11 @@
908
908
  output.add(')');
909
909
  },
910
910
  eval: function (context) {
911
- return new Paren(this.value.eval(context));
911
+ var paren = new Paren(this.value.eval(context));
912
+ if (this.noSpacing) {
913
+ paren.noSpacing = true;
914
+ }
915
+ return paren;
912
916
  }
913
917
  });
914
918
 
@@ -5010,8 +5014,14 @@
5010
5014
  var e;
5011
5015
  var p;
5012
5016
  var rangeP;
5017
+ var spacing = false;
5013
5018
  parserInput.save();
5014
5019
  do {
5020
+ parserInput.save();
5021
+ if (parserInput.$re(/^[0-9a-z-]*\s+\(/)) {
5022
+ spacing = true;
5023
+ }
5024
+ parserInput.restore();
5015
5025
  e = entities.declarationCall.bind(this)() || entities.keyword() || entities.variable() || entities.mixinLookup();
5016
5026
  if (e) {
5017
5027
  nodes.push(e);
@@ -5039,9 +5049,14 @@
5039
5049
  }
5040
5050
  else if (p && e) {
5041
5051
  nodes.push(new (tree.Paren)(new (tree.Declaration)(p, e, null, null, parserInput.i + currentIndex, fileInfo, true)));
5052
+ if (!spacing) {
5053
+ nodes[nodes.length - 1].noSpacing = true;
5054
+ }
5055
+ spacing = false;
5042
5056
  }
5043
5057
  else if (e) {
5044
5058
  nodes.push(new (tree.Paren)(e));
5059
+ spacing = false;
5045
5060
  }
5046
5061
  else {
5047
5062
  error('badly formed media feature definition');
@@ -5163,6 +5178,48 @@
5163
5178
  return null;
5164
5179
  }
5165
5180
  },
5181
+ atruleUnknown: function (value, name, hasBlock) {
5182
+ value = this.permissiveValue(/^[{;]/);
5183
+ hasBlock = (parserInput.currentChar() === '{');
5184
+ if (!value) {
5185
+ if (!hasBlock && parserInput.currentChar() !== ';') {
5186
+ error(''.concat(name, ' rule is missing block or ending semi-colon'));
5187
+ }
5188
+ }
5189
+ else if (!value.value) {
5190
+ value = null;
5191
+ }
5192
+ return [value, hasBlock];
5193
+ },
5194
+ atruleBlock: function (rules, value, isRooted, isKeywordList) {
5195
+ rules = this.blockRuleset();
5196
+ parserInput.save();
5197
+ if (!rules && !isRooted) {
5198
+ value = this.entity();
5199
+ rules = this.blockRuleset();
5200
+ }
5201
+ if (!rules && !isRooted) {
5202
+ parserInput.restore();
5203
+ var e = [];
5204
+ value = this.entity();
5205
+ while (parserInput.$char(',')) {
5206
+ e.push(value);
5207
+ value = this.entity();
5208
+ }
5209
+ if (value && e.length > 0) {
5210
+ e.push(value);
5211
+ value = e;
5212
+ isKeywordList = true;
5213
+ }
5214
+ else {
5215
+ rules = this.blockRuleset();
5216
+ }
5217
+ }
5218
+ else {
5219
+ parserInput.forget();
5220
+ }
5221
+ return [rules, value, isKeywordList];
5222
+ },
5166
5223
  //
5167
5224
  // A CSS AtRule
5168
5225
  //
@@ -5179,6 +5236,7 @@
5179
5236
  var hasUnknown;
5180
5237
  var hasBlock = true;
5181
5238
  var isRooted = true;
5239
+ var isKeywordList = false;
5182
5240
  if (parserInput.currentChar() !== '@') {
5183
5241
  return;
5184
5242
  }
@@ -5216,6 +5274,9 @@
5216
5274
  case '@starting-style':
5217
5275
  isRooted = false;
5218
5276
  break;
5277
+ case '@layer':
5278
+ isRooted = false;
5279
+ break;
5219
5280
  default:
5220
5281
  hasUnknown = true;
5221
5282
  break;
@@ -5234,21 +5295,30 @@
5234
5295
  }
5235
5296
  }
5236
5297
  else if (hasUnknown) {
5237
- value = this.permissiveValue(/^[{;]/);
5238
- hasBlock = (parserInput.currentChar() === '{');
5239
- if (!value) {
5240
- if (!hasBlock && parserInput.currentChar() !== ';') {
5241
- error("".concat(name, " rule is missing block or ending semi-colon"));
5242
- }
5243
- }
5244
- else if (!value.value) {
5245
- value = null;
5246
- }
5298
+ var unknownPackage = this.atruleUnknown(value, name, hasBlock);
5299
+ value = unknownPackage[0];
5300
+ hasBlock = unknownPackage[1];
5247
5301
  }
5248
5302
  if (hasBlock) {
5249
- rules = this.blockRuleset();
5303
+ var blockPackage = this.atruleBlock(rules, value, isRooted, isKeywordList);
5304
+ rules = blockPackage[0];
5305
+ value = blockPackage[1];
5306
+ isKeywordList = blockPackage[2];
5307
+ if (!rules && !hasUnknown) {
5308
+ parserInput.restore();
5309
+ name = parserInput.$re(/^@[a-z-]+/);
5310
+ var unknownPackage = this.atruleUnknown(value, name, hasBlock);
5311
+ value = unknownPackage[0];
5312
+ hasBlock = unknownPackage[1];
5313
+ if (hasBlock) {
5314
+ blockPackage = this.atruleBlock(rules, value, isRooted, isKeywordList);
5315
+ rules = blockPackage[0];
5316
+ value = blockPackage[1];
5317
+ isKeywordList = blockPackage[2];
5318
+ }
5319
+ }
5250
5320
  }
5251
- if (rules || (!hasBlock && value && parserInput.$char(';'))) {
5321
+ if (rules || isKeywordList || (!hasBlock && value && parserInput.$char(';'))) {
5252
5322
  parserInput.forget();
5253
5323
  return new (tree.AtRule)(name, value, rules, index + currentIndex, fileInfo, context.dumpLineNumbers ? getDebugInfo(index) : null, isRooted);
5254
5324
  }
@@ -5301,6 +5371,15 @@
5301
5371
  }
5302
5372
  parserInput.restore();
5303
5373
  },
5374
+ colorOperand: function () {
5375
+ parserInput.save();
5376
+ // hsl or rgb or lch operand
5377
+ var match = parserInput.$re(/^[lchrgbs]\s+/);
5378
+ if (match) {
5379
+ return new tree.Keyword(match[0]);
5380
+ }
5381
+ parserInput.restore();
5382
+ },
5304
5383
  multiplication: function () {
5305
5384
  var m;
5306
5385
  var a;
@@ -5562,7 +5641,7 @@
5562
5641
  entities.color() || entities.variable() ||
5563
5642
  entities.property() || entities.call() ||
5564
5643
  entities.quoted(true) || entities.colorKeyword() ||
5565
- entities.mixinLookup();
5644
+ this.colorOperand() || entities.mixinLookup();
5566
5645
  if (negate) {
5567
5646
  o.parensInOp = true;
5568
5647
  o = new (tree.Negative)(o);
@@ -7016,6 +7095,7 @@
7016
7095
  this.value = visitor.visitArray(this.value);
7017
7096
  },
7018
7097
  eval: function (context) {
7098
+ var noSpacing = this.noSpacing;
7019
7099
  var returnValue;
7020
7100
  var mathOn = context.isMathOn();
7021
7101
  var inParenthesis = this.parens;
@@ -7047,6 +7127,7 @@
7047
7127
  && (!(returnValue instanceof Dimension))) {
7048
7128
  returnValue = new Paren(returnValue);
7049
7129
  }
7130
+ returnValue.noSpacing = returnValue.noSpacing || noSpacing;
7050
7131
  return returnValue;
7051
7132
  },
7052
7133
  genCSS: function (context, output) {
@@ -7079,7 +7160,26 @@
7079
7160
  this.rules = visitor.visitArray(this.rules);
7080
7161
  }
7081
7162
  },
7163
+ evalFunction: function () {
7164
+ if (!this.features || !Array.isArray(this.features.value) || this.features.value.length < 1) {
7165
+ return;
7166
+ }
7167
+ var exprValues = this.features.value;
7168
+ var expr, paren;
7169
+ for (var index = 0; index < exprValues.length; ++index) {
7170
+ expr = exprValues[index];
7171
+ if (expr.type === 'Keyword' && index + 1 < exprValues.length) {
7172
+ paren = exprValues[index + 1];
7173
+ if (paren.type === 'Paren' && paren.noSpacing) {
7174
+ exprValues[index] = new Expression([expr, paren]);
7175
+ exprValues.splice(index + 1, 1);
7176
+ exprValues[index].noSpacing = true;
7177
+ }
7178
+ }
7179
+ }
7180
+ },
7082
7181
  evalTop: function (context) {
7182
+ this.evalFunction();
7083
7183
  var result = this;
7084
7184
  // Render all dependent Media blocks.
7085
7185
  if (context.mediaBlocks.length > 1) {
@@ -7094,6 +7194,7 @@
7094
7194
  return result;
7095
7195
  },
7096
7196
  evalNested: function (context) {
7197
+ this.evalFunction();
7097
7198
  var i;
7098
7199
  var value;
7099
7200
  var path = context.mediaPath.concat([this]);
@@ -7212,6 +7313,13 @@
7212
7313
  else {
7213
7314
  return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment'); }).length === rules.length;
7214
7315
  }
7316
+ }, keywordList: function (rules) {
7317
+ if (!Array.isArray(rules)) {
7318
+ return false;
7319
+ }
7320
+ else {
7321
+ return rules.filter(function (node) { return (node.type === 'Keyword' || node.type === 'Comment'); }).length === rules.length;
7322
+ }
7215
7323
  }, accept: function (visitor) {
7216
7324
  var value = this.value, rules = this.rules, declarations = this.declarations;
7217
7325
  if (rules) {
@@ -7254,6 +7362,9 @@
7254
7362
  context.mediaBlocks = [];
7255
7363
  if (value) {
7256
7364
  value = value.eval(context);
7365
+ if (value.value && this.keywordList(value.value)) {
7366
+ value = new Anonymous(value.value.map(function (keyword) { return keyword.value; }).join(', '), this.getIndex(), this.fileInfo());
7367
+ }
7257
7368
  }
7258
7369
  if (rules) {
7259
7370
  rules = this.evalRoot(context, rules);
@@ -8008,6 +8119,20 @@
8008
8119
  return [];
8009
8120
  }
8010
8121
  }
8122
+ if (this.features) {
8123
+ var featureValue = this.features.value;
8124
+ if (Array.isArray(featureValue) && featureValue.length >= 1) {
8125
+ var expr = featureValue[0];
8126
+ if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
8127
+ featureValue = expr.value;
8128
+ var isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
8129
+ && featureValue[1].type === 'Paren';
8130
+ if (isLayer) {
8131
+ this.css = false;
8132
+ }
8133
+ }
8134
+ }
8135
+ }
8011
8136
  if (this.options.inline) {
8012
8137
  var contents = new Anonymous(this.root, 0, {
8013
8138
  filename: this.importedFilename,
@@ -8015,19 +8140,58 @@
8015
8140
  }, true, true);
8016
8141
  return this.features ? new Media([contents], this.features.value) : [contents];
8017
8142
  }
8018
- else if (this.css) {
8143
+ else if (this.css || this.layerCss) {
8019
8144
  var newImport = new Import(this.evalPath(context), features, this.options, this._index);
8145
+ if (this.layerCss) {
8146
+ newImport.css = this.layerCss;
8147
+ newImport.path._fileInfo = this._fileInfo;
8148
+ }
8020
8149
  if (!newImport.css && this.error) {
8021
8150
  throw this.error;
8022
8151
  }
8023
8152
  return newImport;
8024
8153
  }
8025
8154
  else if (this.root) {
8155
+ if (this.features) {
8156
+ var featureValue = this.features.value;
8157
+ if (Array.isArray(featureValue) && featureValue.length === 1) {
8158
+ var expr = featureValue[0];
8159
+ if (expr.type === 'Expression' && Array.isArray(expr.value) && expr.value.length >= 2) {
8160
+ featureValue = expr.value;
8161
+ var isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
8162
+ && featureValue[1].type === 'Paren';
8163
+ if (isLayer) {
8164
+ this.layerCss = true;
8165
+ featureValue[0] = new Expression(featureValue.slice(0, 2));
8166
+ featureValue.splice(1, 1);
8167
+ featureValue[0].noSpacing = true;
8168
+ return this;
8169
+ }
8170
+ }
8171
+ }
8172
+ }
8026
8173
  ruleset = new Ruleset(null, copyArray(this.root.rules));
8027
8174
  ruleset.evalImports(context);
8028
8175
  return this.features ? new Media(ruleset.rules, this.features.value) : ruleset.rules;
8029
8176
  }
8030
8177
  else {
8178
+ if (this.features) {
8179
+ var featureValue = this.features.value;
8180
+ if (Array.isArray(featureValue) && featureValue.length >= 1) {
8181
+ featureValue = featureValue[0].value;
8182
+ if (Array.isArray(featureValue) && featureValue.length >= 2) {
8183
+ var isLayer = featureValue[0].type === 'Keyword' && featureValue[0].value === 'layer'
8184
+ && featureValue[1].type === 'Paren';
8185
+ if (isLayer) {
8186
+ this.css = true;
8187
+ featureValue[0] = new Expression(featureValue.slice(0, 2));
8188
+ featureValue.splice(1, 1);
8189
+ featureValue[0].noSpacing = true;
8190
+ return this;
8191
+ }
8192
+ }
8193
+ }
8194
+ }
8031
8195
  return [];
8032
8196
  }
8033
8197
  }
@@ -11025,7 +11189,7 @@
11025
11189
  return render;
11026
11190
  }
11027
11191
 
11028
- var version = "4.3.0";
11192
+ var version = "4.4.1";
11029
11193
 
11030
11194
  function parseNodeVersion(version) {
11031
11195
  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