Skip to content

Commit ffe4d15

Browse files
authored
refactor(theme): derive V1 hue angles from swatches (anomalyco#49839)
1 parent b186046 commit ffe4d15

1 file changed

Lines changed: 24 additions & 17 deletions

File tree

‎packages/theme/src/tui/v1-migrate.ts‎

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -13,27 +13,34 @@ const chromaticHues: readonly ChromaticHue[] = ["red", "orange", "yellow", "gree
1313
const categoricalTokens: readonly V1HueToken[] = ["secondary", "accent", "success", "warning", "primary", "error"]
1414
const minimumChroma = 0.03
1515
const lightThreshold = 0.6
16-
// Canonical OKLCH hue angles classify arbitrary V1 colors without coupling migration to a built-in theme.
17-
const hueAngles = {
16+
// Canonical swatches copied from the original default-theme classifier keep V1 migration self-contained.
17+
const hueReferences = {
1818
light: {
19-
red: 19.571,
20-
orange: 66.29,
21-
yellow: 98.111,
22-
green: 154.449,
23-
cyan: 207.078,
24-
blue: 251.813,
25-
purple: 306.383,
19+
red: "#fca5a5",
20+
orange: "#fdba74",
21+
yellow: "#fde047",
22+
green: "#86efac",
23+
cyan: "#67e8f9",
24+
blue: "#93c5fd",
25+
purple: "#d8b4fe",
2626
},
2727
dark: {
28-
red: 27.518,
29-
orange: 38.402,
30-
yellow: 66.442,
31-
green: 150.069,
32-
cyan: 223.128,
33-
blue: 264.376,
34-
purple: 301.924,
28+
red: "#b91c1c",
29+
orange: "#c2410c",
30+
yellow: "#a16207",
31+
green: "#15803d",
32+
cyan: "#0e7490",
33+
blue: "#1d4ed8",
34+
purple: "#7e22ce",
3535
},
36-
} satisfies Record<"light" | "dark", Record<ChromaticHue, number>>
36+
} satisfies Record<"light" | "dark", Record<ChromaticHue, string>>
37+
38+
const hueAngles = Object.fromEntries(
39+
Object.entries(hueReferences).map(([level, colors]) => [
40+
level,
41+
Object.fromEntries(Object.entries(colors).map(([name, color]) => [name, toOklch(RGBA.fromHex(color)).h])),
42+
]),
43+
) as Record<"light" | "dark", Record<ChromaticHue, number>>
3744

3845
export function migrateV1(theme: ThemeV1Json): ThemeDocument {
3946
const light = resolveV1(theme, "light")

0 commit comments

Comments
 (0)