Skip to content

Commit 384e208

Browse files
committed
feat(color): updated named colors.
1 parent dbf4cf3 commit 384e208

2 files changed

Lines changed: 38 additions & 7 deletions

File tree

src/color/manipulation.ts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// Helper functions for color calculations
22

33
import type { RgbColor } from './types';
4-
import { FOREGROUND_COLORS } from './palette';
4+
import { NAMED_COLORS } from './palette';
55

66
// sRGB gamma correction
77
export function gammaCorrect(channel: number): number {
@@ -522,12 +522,12 @@ export function shade(
522522
}
523523

524524
/**
525-
* Return true if `s` is a named color from the FOREGROUND_COLORS palette
525+
* Return true if `s` is a named color from the NAMED_COLORS palette
526526
* (e.g. "red", "blue", "dark-grey") or "transparent".
527527
*/
528528
export function isNamedColor(s: string): boolean {
529529
const str = s.trim().toLowerCase();
530-
return str === 'transparent' || str in FOREGROUND_COLORS;
530+
return str === 'transparent' || str in NAMED_COLORS;
531531
}
532532

533533
/**
@@ -538,7 +538,7 @@ export function isNamedColor(s: string): boolean {
538538
* - oklch: oklch(l c h / a) or oklch(l c h) or oklch(l, c, h / a) or oklch(l, c, h), when l is a percentage, c is a number between 0 and 0.4, and h is a number between 0 and 360, for example "oklch(50% 0.3 240 / 0.8)" or "oklch(50% 0.3 240 / 80%)"
539539
* - oklab: oklab(L a b / alpha) or oklab(L a b), where L is 0-1 (or percentage), a is ~-0.4 to 0.4, b is ~-0.4 to 0.4
540540
* - hsl: hsl(h, s, l) or hsl(h, s, l / a) or hsl(h s l / a) or hsl(h s l), where h is a number between 0 and 360, s is a percentage, l is a percentage and a is a percentage
541-
* - named: color names from the FOREGROUND_COLORS palette (e.g. "red", "blue", "cyan", "dark-grey") or "transparent"
541+
* - named: color names from the NAMED_COLORS palette (e.g. "red", "blue", "cyan", "dark-grey") or "transparent"
542542
*/
543543

544544
export function parseColor(s: string): number {
@@ -730,8 +730,8 @@ export function parseColor(s: string): number {
730730
if (str === 'transparent') return 0;
731731

732732
// Named color lookup
733-
if (str in FOREGROUND_COLORS)
734-
return parseColor(FOREGROUND_COLORS[str as keyof typeof FOREGROUND_COLORS]);
733+
if (str in NAMED_COLORS)
734+
return parseColor(NAMED_COLORS[str as keyof typeof NAMED_COLORS]);
735735

736736
console.warn(`parseColor: unrecognized color "${s}"`);
737737
return 0;

src/color/palette.ts

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ export const BACKGROUND_COLORS = {
1919
'grey': '#D0D0D0',
2020
'light-grey': '#F0F0F0',
2121
'white': '#ffffff',
22-
};
22+
} as const;
2323

2424
// Colors from Chromatic 500 (and 600, 700) design scale
2525
export const FOREGROUND_COLORS = {
@@ -40,3 +40,34 @@ export const FOREGROUND_COLORS = {
4040
'light-grey': '#d4d5d2',
4141
'white': '#ffffff',
4242
};
43+
44+
export const NAMED_COLORS = {
45+
'red': '#d7170b', //<- 700, 500 ->'#f21c0d'
46+
'orange': '#fe8a2b',
47+
'yellow': '#ffc02b', // <- 600, 500 -> '#ffcf33',
48+
'lime': '#63b215',
49+
'green': '#21ba3a',
50+
'teal': '#17cfcf',
51+
'cyan': '#13a7ec',
52+
'blue': '#0d80f2',
53+
'indigo': '#63c',
54+
'purple': '#a219e6',
55+
'magenta': '#eb4799',
56+
'brown': '#8c564b',
57+
'olive': '#8a8f2a',
58+
'midnight': '#2c4670',
59+
'sky': '#d2dce9',
60+
'black': '#000',
61+
'white': '#ffffff',
62+
'carbon': '#111111', // near-black, high-contrast text
63+
'charcoal': '#333333', // primary axis / label color
64+
'slate': '#555555', // secondary text, major gridlines
65+
'dark-grey': '#666',
66+
'graphite': '#777777', // minor gridlines
67+
'stone': '#999999', // de-emphasized strokes
68+
'grey': '#A6A6A6',
69+
'light-grey': '#d4d5d2',
70+
'ash': '#E6E6E6', // subtle fills, light strokes
71+
'mist': '#F3F3F3', // light background tint
72+
'snow': '#FFFFFF', // pure white
73+
} as const;

0 commit comments

Comments
 (0)