Skip to content

Commit

Permalink
feat(color): update CSS_NAMES
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jan 23, 2021
1 parent 7b1eeff commit 7ea0cf0
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 1 deletion.
5 changes: 4 additions & 1 deletion packages/color/src/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,10 @@ export type CSSColorName =
| "white"
| "whitesmoke"
| "yellow"
| "yellowgreen";
| "yellowgreen"
// additions
| "transparent"
| "rebeccapurple";

export type ColorRangePreset =
| "light"
Expand Down
4 changes: 4 additions & 0 deletions packages/color/src/hsla-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,9 @@ export const hslaCss = (src: ReadonlyColor) => {
const s = PC(clamp01(src[1]));
const l = PC(clamp01(src[2]));
const a = ensureAlpha(src[3]);
// TODO update to new syntax once CSS Color L4 is more widely supported
// https://drafts.csswg.org/css-color/#serializing-lab-lch
// https://test.csswg.org/harness/results/css-color-4_dev/grouped/ (test reports)
// return `hsl(${h} ${s} ${l}` + (a < 1 ? `/${FF(a)})` : ")");
return a < 1 ? `hsla(${h},${s},${l},${FF(a)})` : `hsl(${h},${s},${l})`;
};
3 changes: 3 additions & 0 deletions packages/color/src/names.ts
Original file line number Diff line number Diff line change
Expand Up @@ -148,4 +148,7 @@ export const CSS_NAMES: Record<CSSColorName, string> = {
whitesmoke: "f5f5f5",
yellow: "ff0",
yellowgreen: "9acd32",
// additions
transparent: "0000",
rebeccapurple: "639",
};
1 change: 1 addition & 0 deletions packages/color/src/rgba-css.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ export const rgbaCss = (src: ReadonlyColor) => {
const g = (clamp01(src[1]) * 0xff + 0.5) | 0;
const b = (clamp01(src[2]) * 0xff + 0.5) | 0;
const a = ensureAlpha(src[3]);
// TODO update to `rgb(${r} ${g} ${b}/${FF(a)})` (CSS L4 syntax)
return a < 1
? `rgba(${r},${g},${b},${FF(a)})`
: `#${U24((r << 16) | (g << 8) | b)}`;
Expand Down

0 comments on commit 7ea0cf0

Please sign in to comment.