CssColorFormat.parse
import { CssColorFormat } from "https://raw.githubusercontent.com/i-xi-dev/color.es/5.2.10/mod.ts";
const { parse } = CssColorFormat;
Creates a new instance of RgbColor
from a CSS color value.
The following CSS Color Level 3 values are supported:
<hex-color>
<named-color>
transparent
<rgb()>
<rgba()>
<hsl()>
<hsla()>
The following CSS Color Level 4 values are experimentally supported:
<rgb()>
<hsl()>
@example
const color = CssColorFormat.parse("#ff0000");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("#f00");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("#ff0000ff");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("rgb(255, 0, 0)");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("rgba(255, 0, 0, 1)");
// color.toHexString()
// → "#FF0000FF"
@example
// parse the notation for CSS color level 4
const color = CssColorFormat.parse("rgb(255 0 0 / 1)");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("hsl(0, 100%, 50%)");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("hsla(0, 100%, 50%, 1)");
// color.toHexString()
// → "#FF0000FF"
@example
// parse the notation for CSS color level 4
const color = CssColorFormat.parse("hsl(0 100% 50% / 1)");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("red");
// color.toHexString()
// → "#FF0000FF"
@example
const color = CssColorFormat.parse("transparent");
// color.toHexString()
// → "#00000000"