Something went wrong. Try again.
a tool for shared writing and social publishing
Something went wrong. Try again.
1.0 kB · 28 lines
TypeScript
1234567891011121314151617181920212223242526272829import { parse, ColorSpace, sRGB, distance, OKLab } from "colorjs.io/fn";
// define the color defaults for everythingexport const ThemeDefaults = { "theme/page-background": "#FDFCFA", "theme/card-background": "#FFFFFF", "theme/primary": "#272727", "theme/highlight-1": "#FFFFFF", "theme/highlight-2": "#EDD280", "theme/highlight-3": "#FFCDC3",
//everywhere else, accent-background = accent-1 and accent-text = accent-2. // we just need to create a migration pipeline before we can change this "theme/accent-text": "#FFFFFF", "theme/accent-background": "#0000FF", "theme/accent-contrast": "#0000FF",};
// used to calculate the contrast between page and accent1, accent2, and determin which is higher contrastexport function getColorDifference(color1: string, color2: string) { ColorSpace.register(sRGB); ColorSpace.register(OKLab);
let parsedColor1 = parse(`rgb(${color1})`); let parsedColor2 = parse(`rgb(${color2})`);
return distance(parsedColor1, parsedColor2, "oklab");}