UNPKG

@helpwave/hightide

Version:

helpwave's component and theming library

1 lines 3.12 kB
{"version":3,"sources":["../../src/coloring/shading.ts","../../src/coloring/types.ts"],"sourcesContent":["import tinycolor from 'tinycolor2'\nimport type { ShadedColors } from './types'\nimport { shadingColorValues } from './types'\n\n// Function to generate a full shading of several colors\nexport const generateShadingColors = (partialShading: Omit<Partial<ShadedColors>, '0' | '1000'>): ShadedColors => {\n const shading: ShadedColors = {\n 0: '#FFFFFF',\n 1000: '#000000'\n } as ShadedColors\n\n let index = 1\n while (index < shadingColorValues.length - 1) {\n const previous = shadingColorValues[index - 1]!\n const current = shadingColorValues[index]!\n\n if (partialShading[current] !== undefined) {\n shading[current] = partialShading[current]\n index++\n continue\n }\n\n let j: number = index + 1\n while (j < shadingColorValues.length) {\n if (partialShading[shadingColorValues[j]!] !== undefined) {\n break\n }\n j++\n }\n if (j === shadingColorValues.length) {\n j = shadingColorValues.length - 1\n }\n\n const nextFound = shadingColorValues[j]!\n const interval = nextFound - previous\n for (let k = index; k < j; k++) {\n const current = shadingColorValues[k]!\n const previousValue = partialShading[previous] ?? shading[previous]\n const nextValue = partialShading[nextFound] ?? shading[nextFound]\n shading[current] = tinycolor.mix(tinycolor(previousValue), tinycolor(nextValue), (current - previous) / interval * 100).toHexString()\n }\n index = j\n }\n\n return shading\n}\n","export const shadingColorValues = [0, 50, 100, 150, 200, 250, 300, 350, 400, 450, 500, 550, 600, 650, 700, 750, 800, 850, 900, 950, 1000] as const\nexport type ColorShadingValue = typeof shadingColorValues[number]\nexport type ShadedColors = Record<ColorShadingValue, string>\n\nexport type ColoringStyle = 'background' | 'tonal' | 'tonal-opaque' | 'text' | 'text-border'\nexport type ColorMode = 'light' | 'dark'\n\nexport type Coloring = {\n color: '',\n style?: ColoringStyle,\n mode?: ColorMode,\n hover?: boolean,\n}\n"],"mappings":";AAAA,OAAO,eAAe;;;ACAf,IAAM,qBAAqB,CAAC,GAAG,IAAI,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,KAAK,GAAI;;;ADKjI,IAAM,wBAAwB,CAAC,mBAA4E;AAChH,QAAM,UAAwB;AAAA,IAC5B,GAAG;AAAA,IACH,KAAM;AAAA,EACR;AAEA,MAAI,QAAQ;AACZ,SAAO,QAAQ,mBAAmB,SAAS,GAAG;AAC5C,UAAM,WAAW,mBAAmB,QAAQ,CAAC;AAC7C,UAAM,UAAU,mBAAmB,KAAK;AAExC,QAAI,eAAe,OAAO,MAAM,QAAW;AACzC,cAAQ,OAAO,IAAI,eAAe,OAAO;AACzC;AACA;AAAA,IACF;AAEA,QAAI,IAAY,QAAQ;AACxB,WAAO,IAAI,mBAAmB,QAAQ;AACpC,UAAI,eAAe,mBAAmB,CAAC,CAAE,MAAM,QAAW;AACxD;AAAA,MACF;AACA;AAAA,IACF;AACA,QAAI,MAAM,mBAAmB,QAAQ;AACnC,UAAI,mBAAmB,SAAS;AAAA,IAClC;AAEA,UAAM,YAAY,mBAAmB,CAAC;AACtC,UAAM,WAAW,YAAY;AAC7B,aAAS,IAAI,OAAO,IAAI,GAAG,KAAK;AAC9B,YAAMA,WAAU,mBAAmB,CAAC;AACpC,YAAM,gBAAgB,eAAe,QAAQ,KAAK,QAAQ,QAAQ;AAClE,YAAM,YAAY,eAAe,SAAS,KAAK,QAAQ,SAAS;AAChE,cAAQA,QAAO,IAAI,UAAU,IAAI,UAAU,aAAa,GAAG,UAAU,SAAS,IAAIA,WAAU,YAAY,WAAW,GAAG,EAAE,YAAY;AAAA,IACtI;AACA,YAAQ;AAAA,EACV;AAEA,SAAO;AACT;","names":["current"]}