import type { Color, Oklch, Rgb } from 'culori' import { converter, parse } from 'culori' export type ColorScheme = 'light' | 'dark' // Every light/dark pair goes through this: bind the mode once, then flip pairs with it. export const light_dark_of = (mode: ColorScheme) => (light: T, dark: T): T => mode === 'light' ? light : dark const to_oklch = converter('oklch') const hue_of = (color: Color) => to_oklch(color).h as number // CSS's oklch() colors, with lightness in percent like variables.css. export const oklch = (l: number, c: number, h: number): Oklch => ({ mode: 'oklch', l: l / 100, c, h, }) const hex = (value: string) => parse(value) as Rgb export const HUE = 122 // The raw linkplay.space colors in OKLCH, before any gamut mapping; the build clips them to each // output's gamut the way browsers render out-of-gamut OKLCH, so they match the site. export const source = (mode: ColorScheme) => { const light_dark = light_dark_of(mode) // linkplay.space's variables.css, with stops of its --in-colour wheel. const site = { accent: oklch(92, 0.27, HUE), back_1: light_dark(oklch(97, 0.05, HUE), oklch(20, 0.22, HUE)), back_2: light_dark(oklch(92, 0.08, HUE), oklch(40, 0.3, HUE)), text_1: light_dark(oklch(20, 0.22, HUE), oklch(97, 0.05, HUE)), text_2: light_dark(oklch(32, 0.41, HUE), oklch(92, 0.08, HUE)), text_3: light_dark(oklch(40, 0.3, HUE), oklch(73, 0.08, HUE)), in_colour_red: hex('#cb2d3b'), in_colour_orange: hex('#e18036'), in_colour_yellow: hex('#f5d74c'), in_colour_green: hex('#4a9b4b'), in_colour_cyan: hex('#4e9f9c'), in_colour_blue: hex('#489ad2'), in_colour_purple: hex('#542974'), in_colour_violet: hex('#7d287a'), } const hues = { red: hue_of(site.in_colour_red), orange: hue_of(site.in_colour_orange), yellow: hue_of(site.in_colour_yellow), green: hue_of(site.in_colour_green), cyan: hue_of(site.in_colour_cyan), blue: hue_of(site.in_colour_blue), magenta: hue_of(site.in_colour_purple), violet: hue_of(site.in_colour_violet), // Not an --in-colour stop: the hue furthest from both the diff red and green, for the find match. lavender: 285, } // Steps beyond linkplay.space's back-1/2 and text-1/3, with the same light/dark flip. const steps = { back_0: light_dark(oklch(100, 0, 0), oklch(14, 0.04, HUE)), back_3: light_dark(oklch(88, 0.1, HUE), oklch(48, 0.12, HUE)), back_4: light_dark(oklch(82, 0.07, HUE), oklch(35, 0.07, HUE)), back_5: light_dark(site.back_2, oklch(30, 0.1, HUE)), text_4: light_dark(oklch(58, 0.06, HUE), oklch(55, 0.06, HUE)), text_5: light_dark(oklch(62, 0.08, HUE), oklch(52, 0.08, HUE)), text_6: light_dark(oklch(72, 0.08, HUE), oklch(47, 0.08, HUE)), shadow_1: light_dark(hex('#00000026'), hex('#00000080')), shadow_2: light_dark(hex('#0000000d'), hex('#00000040')), // Not flipped: the terminal's black and white, and text on the accent. black: oklch(35, 0.04, HUE), white: light_dark(oklch(75, 0.04, HUE), oklch(85, 0.04, HUE)), on_accent: (hue: number) => oklch(45, 0.15, hue), // The same steps for each --in-colour hue. hue_text_1: (hue: number) => light_dark(oklch(45, 0.15, hue), oklch(75, 0.13, hue)), hue_text_2: (hue: number) => light_dark(oklch(60, 0.17, hue), oklch(85, 0.11, hue)), hue_text_3: (hue: number) => light_dark(oklch(52, 0.17, hue), oklch(67, 0.15, hue)), hue_back_1: (hue: number) => light_dark(oklch(88, 0.1, hue), oklch(35, 0.08, hue)), } return { site, hues, steps } }