Skip to content

Commit

Permalink
Add easy way to produce legacy CSS rgb()/rgba() functions, closes #203
Browse files Browse the repository at this point in the history
  • Loading branch information
LeaVerou committed Nov 3, 2022
1 parent bf36ebc commit 667c19a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/serialize.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ export default function serialize (color, {
alpha = util.toPrecision(alpha, precision);
}

let strAlpha = color.alpha < 1? `${format.commas? "," : " /"} ${alpha}` : "";
let strAlpha = color.alpha < 1 && !format.noAlpha? `${format.commas? "," : " /"} ${alpha}` : "";
ret = `${name}(${args.join(format.commas? ", " : " ")}${strAlpha})`;
}

Expand Down
12 changes: 12 additions & 0 deletions src/spaces/srgb.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import sRGBLinear from "./srgb-linear.js";
import KEYWORDS from "../keywords.js";

let coordGrammar = Array(3).fill("<percentage> | <number>[0, 255]");
let coordGrammarNumber = Array(3).fill("<number>[0, 255]");

export default new RGBColorSpace({
id: "srgb",
Expand Down Expand Up @@ -42,12 +43,23 @@ export default new RGBColorSpace({
"rgb": {
coords: coordGrammar,
},
"rgb_number": {
name: "rgb",
commas: true,
coords: coordGrammarNumber,
noAlpha: true,
},
"color": { /* use defaults */ },
"rgba": {
coords: coordGrammar,
commas: true,
lastAlpha: true,
},
"rgba_number": {
name: "rgba",
commas: true,
coords: coordGrammarNumber
},
"hex": {
type: "custom",
toGamut: true,
Expand Down

0 comments on commit 667c19a

Please sign in to comment.