|
1 | 1 | /** |
2 | | - * Less - Leaner CSS v4.3.0 |
| 2 | + * Less - Leaner CSS v4.4.0 |
3 | 3 | * http://lesscss.org |
4 | 4 | * |
5 | 5 | * Copyright (c) 2009-2025, Alexis Sellier <[email protected]> |
|
5179 | 5179 | var hasUnknown; |
5180 | 5180 | var hasBlock = true; |
5181 | 5181 | var isRooted = true; |
| 5182 | + var isKeywordList = false; |
5182 | 5183 | if (parserInput.currentChar() !== '@') { |
5183 | 5184 | return; |
5184 | 5185 | } |
|
5216 | 5217 | case '@starting-style': |
5217 | 5218 | isRooted = false; |
5218 | 5219 | break; |
| 5220 | + case '@layer': |
| 5221 | + isRooted = false; |
| 5222 | + break; |
5219 | 5223 | default: |
5220 | 5224 | hasUnknown = true; |
5221 | 5225 | break; |
|
5247 | 5251 | } |
5248 | 5252 | if (hasBlock) { |
5249 | 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 | + } |
5250 | 5279 | } |
5251 | | - if (rules || (!hasBlock && value && parserInput.$char(';'))) { |
| 5280 | + if (rules || isKeywordList || (!hasBlock && value && parserInput.$char(';'))) { |
5252 | 5281 | parserInput.forget(); |
5253 | 5282 | return new (tree.AtRule)(name, value, rules, index + currentIndex, fileInfo, context.dumpLineNumbers ? getDebugInfo(index) : null, isRooted); |
5254 | 5283 | } |
|
5301 | 5330 | } |
5302 | 5331 | parserInput.restore(); |
5303 | 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 | + }, |
5304 | 5342 | multiplication: function () { |
5305 | 5343 | var m; |
5306 | 5344 | var a; |
|
5562 | 5600 | entities.color() || entities.variable() || |
5563 | 5601 | entities.property() || entities.call() || |
5564 | 5602 | entities.quoted(true) || entities.colorKeyword() || |
5565 | | - entities.mixinLookup(); |
| 5603 | + this.colorOperand() || entities.mixinLookup(); |
5566 | 5604 | if (negate) { |
5567 | 5605 | o.parensInOp = true; |
5568 | 5606 | o = new (tree.Negative)(o); |
|
7016 | 7054 | this.value = visitor.visitArray(this.value); |
7017 | 7055 | }, |
7018 | 7056 | eval: function (context) { |
| 7057 | + var noSpacing = this.noSpacing; |
7019 | 7058 | var returnValue; |
7020 | 7059 | var mathOn = context.isMathOn(); |
7021 | 7060 | var inParenthesis = this.parens; |
|
7047 | 7086 | && (!(returnValue instanceof Dimension))) { |
7048 | 7087 | returnValue = new Paren(returnValue); |
7049 | 7088 | } |
| 7089 | + returnValue.noSpacing = returnValue.noSpacing || noSpacing; |
7050 | 7090 | return returnValue; |
7051 | 7091 | }, |
7052 | 7092 | genCSS: function (context, output) { |
|
7212 | 7252 | else { |
7213 | 7253 | return rules.filter(function (node) { return (node.type === 'Declaration' || node.type === 'Comment'); }).length === rules.length; |
7214 | 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 | + } |
7215 | 7262 | }, accept: function (visitor) { |
7216 | 7263 | var value = this.value, rules = this.rules, declarations = this.declarations; |
7217 | 7264 | if (rules) { |
|
7254 | 7301 | context.mediaBlocks = []; |
7255 | 7302 | if (value) { |
7256 | 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 | + } |
7257 | 7307 | } |
7258 | 7308 | if (rules) { |
7259 | 7309 | rules = this.evalRoot(context, rules); |
|
8008 | 8058 | return []; |
8009 | 8059 | } |
8010 | 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 | + } |
8011 | 8075 | if (this.options.inline) { |
8012 | 8076 | var contents = new Anonymous(this.root, 0, { |
8013 | 8077 | filename: this.importedFilename, |
8014 | 8078 | reference: this.path._fileInfo && this.path._fileInfo.reference |
8015 | 8079 | }, true, true); |
8016 | 8080 | return this.features ? new Media([contents], this.features.value) : [contents]; |
8017 | 8081 | } |
8018 | | - else if (this.css) { |
| 8082 | + else if (this.css || this.layerCss) { |
8019 | 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 | + } |
8020 | 8088 | if (!newImport.css && this.error) { |
8021 | 8089 | throw this.error; |
8022 | 8090 | } |
8023 | 8091 | return newImport; |
8024 | 8092 | } |
8025 | 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 | + } |
8026 | 8112 | ruleset = new Ruleset(null, copyArray(this.root.rules)); |
8027 | 8113 | ruleset.evalImports(context); |
8028 | 8114 | return this.features ? new Media(ruleset.rules, this.features.value) : ruleset.rules; |
8029 | 8115 | } |
8030 | 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 | + } |
8031 | 8134 | return []; |
8032 | 8135 | } |
8033 | 8136 | } |
|
11025 | 11128 | return render; |
11026 | 11129 | } |
11027 | 11130 |
|
11028 | | - var version = "4.3.0"; |
| 11131 | + var version = "4.4.0"; |
11029 | 11132 |
|
11030 | 11133 | function parseNodeVersion(version) { |
11031 | 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 |
|
0 commit comments