Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion packages/less/lib/less/functions/color.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import Quoted from '../tree/quoted.js';
import Anonymous from '../tree/anonymous.js';
import Expression from '../tree/expression.js';
import Operation from '../tree/operation.js';
import Keyword from '../tree/keyword.js';
let colorFunctions;

function clamp(val) {
Expand Down Expand Up @@ -427,12 +428,17 @@ colorFunctions = {
return new Anonymous(color.toARGB());
},
color: function(c) {
// CSS color(), e.g. color(display-p3 1 1 1), should be kept as is
if (arguments.length === 1 && c instanceof Expression && c.value[0] instanceof Keyword &&
/^(from|srgb|srgb-linear|display-p3|display-p3-linear|a98-rgb|prophoto-rgb|rec2020|xyz|xyz-d50|xyz-d65|--.+)$/i.test(c.value[0].value)) {
return null;
}
if ((c instanceof Quoted) &&
(/^#([A-Fa-f0-9]{8}|[A-Fa-f0-9]{6}|[A-Fa-f0-9]{3,4})$/i.test(c.value))) {
const val = c.value.slice(1);
return new Color(val, undefined, `#${val}`);
}
if ((c instanceof Color) || (c = Color.fromKeyword(c.value))) {
if ((c instanceof Color) || (typeof c.value === 'string' && (c = Color.fromKeyword(c.value)))) {
c.value = undefined;
return c;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.test-rule {
color: color(garbage 1 1 1);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
ArgumentError: Error evaluating function `color`: argument must be a color keyword or 3|4|6|8 digit hex e.g. #FFF in {path}color-func-invalid-color-3.less on line 2, column 10:
1 .test-rule {
2 color: color(garbage 1 1 1);
3 }
3 changes: 3 additions & 0 deletions packages/test-data/tests-unit/functions/functions.css
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,9 @@
color-quoted-keyword: #dda0dd;
color-color: #dda0dd;
color-keyword: #dda0dd;
color-css: color(display-p3 1 0.5 0);
color-css-p3-linear: color(display-p3-linear 1 0.5 0);
color-css-alpha: color(srgb 0.5 0 1 / 50%);
tint: #898989;
tint-full: #ffffff;
tint-percent: #898989;
Expand Down
3 changes: 3 additions & 0 deletions packages/test-data/tests-unit/functions/functions.less
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,9 @@
color-quoted-keyword: color("plum");
color-color: color(#dda0dd);
color-keyword: color(plum);
color-css: color(display-p3 1 0.5 0);
color-css-p3-linear: color(display-p3-linear 1 0.5 0);
color-css-alpha: color(srgb 0.5 0 1 / 50%);
Comment thread
akysil marked this conversation as resolved.
Resolved
tint: tint(#777777, 13);
tint-full: tint(#777777, 100);
tint-percent: tint(#777777, 13%);
Expand Down
Loading