Skip to content

Commit b8e9bd1

Browse files
committed
allow CSS Color Module Level 5
1 parent 64edc66 commit b8e9bd1

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

src/options.js

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import {parse as isoParse} from "isoformat";
2-
import {color, descending, range as rangei, quantile} from "d3";
2+
import {descending, range as rangei, quantile} from "d3";
33
import {maybeTimeInterval, maybeUtcInterval} from "./time.js";
44

55
// https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/TypedArray
@@ -396,20 +396,20 @@ export function isEvery(values, is) {
396396
return every;
397397
}
398398

399-
// Mostly relies on d3-color, with a few extra color keywords. Currently this
400-
// strictly requires that the value be a string; we might want to apply string
401-
// coercion here, though note that d3-color instances would need to support
402-
// valueOf to work correctly with InternMap.
399+
const namedColors = new Set("none,currentcolor,transparent,aliceblue,antiquewhite,aqua,aquamarine,azure,beige,bisque,black,blanchedalmond,blue,blueviolet,brown,burlywood,cadetblue,chartreuse,chocolate,coral,cornflowerblue,cornsilk,crimson,cyan,darkblue,darkcyan,darkgoldenrod,darkgray,darkgreen,darkgrey,darkkhaki,darkmagenta,darkolivegreen,darkorange,darkorchid,darkred,darksalmon,darkseagreen,darkslateblue,darkslategray,darkslategrey,darkturquoise,darkviolet,deeppink,deepskyblue,dimgray,dimgrey,dodgerblue,firebrick,floralwhite,forestgreen,fuchsia,gainsboro,ghostwhite,gold,goldenrod,gray,green,greenyellow,grey,honeydew,hotpink,indianred,indigo,ivory,khaki,lavender,lavenderblush,lawngreen,lemonchiffon,lightblue,lightcoral,lightcyan,lightgoldenrodyellow,lightgray,lightgreen,lightgrey,lightpink,lightsalmon,lightseagreen,lightskyblue,lightslategray,lightslategrey,lightsteelblue,lightyellow,lime,limegreen,linen,magenta,maroon,mediumaquamarine,mediumblue,mediumorchid,mediumpurple,mediumseagreen,mediumslateblue,mediumspringgreen,mediumturquoise,mediumvioletred,midnightblue,mintcream,mistyrose,moccasin,navajowhite,navy,oldlace,olive,olivedrab,orange,orangered,orchid,palegoldenrod,palegreen,paleturquoise,palevioletred,papayawhip,peachpuff,peru,pink,plum,powderblue,purple,rebeccapurple,red,rosybrown,royalblue,saddlebrown,salmon,sandybrown,seagreen,seashell,sienna,silver,skyblue,slateblue,slategray,slategrey,snow,springgreen,steelblue,tan,teal,thistle,tomato,turquoise,violet,wheat,white,whitesmoke,yellow".split(",")); // prettier-ignore
400+
401+
// Returns true if value is a valid CSS color string. This is intentionally lax
402+
// because the CSS color spec keeps growing, and we don’t need to parse these
403+
// colors—we just need to disambiguate them from column names.
403404
// https://www.w3.org/TR/SVG11/painting.html#SpecifyingPaint
405+
// https://www.w3.org/TR/css-color-5/
404406
export function isColor(value) {
405407
if (typeof value !== "string") return false;
406408
value = value.toLowerCase().trim();
407409
return (
408-
value === "none" ||
409-
value === "currentcolor" ||
410-
(value.startsWith("url(") && value.endsWith(")")) || // <funciri>, e.g. pattern or gradient
411-
(value.startsWith("var(") && value.endsWith(")")) || // CSS variable
412-
color(value) !== null
410+
/^#[0-9a-f]{3,8}$/.test(value) || // hex rgb, rgba, rrggbb, rrggbbaa
411+
/^(?:url|var|rgb|rgba|hsl|hsla|hwb|lab|lch|oklab|oklch|color|color-mix)\(.*\)$/.test(value) || // <funciri>, CSS variable, color, etc.
412+
namedColors.has(value) // currentColor, red, etc.
413413
);
414414
}
415415

0 commit comments

Comments
 (0)