@skbkontur/colors 2.0.0-alpha.2 → 2.0.0-alpha.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (174) hide show
  1. package/README.md +104 -171
  2. package/colors.less +319 -0
  3. package/colors.scss +319 -0
  4. package/lib/consts/default-swatch.d.ts +108 -0
  5. package/lib/consts/default-swatch.js +108 -0
  6. package/{dist/esm/constants/default-swatch.js → lib/consts/default-swatch.ts} +11 -7
  7. package/lib/consts/params/abney-correction.d.ts +2 -0
  8. package/lib/consts/params/abney-correction.js +1102 -0
  9. package/{dist/cjs/constants/abney-correction.js → lib/consts/params/abney-correction.ts} +3 -4
  10. package/lib/consts/params/chroma-params.d.ts +2 -0
  11. package/lib/consts/params/chroma-params.js +102 -0
  12. package/{dist/esm/constants/chroma-settings.js → lib/consts/params/chroma-params.ts} +3 -1
  13. package/lib/consts/params/interactions.ts +9 -0
  14. package/lib/consts/params/logo-lightness.d.ts +1 -0
  15. package/lib/consts/params/logo-lightness.js +1 -0
  16. package/lib/consts/params/logo-lightness.ts +1 -0
  17. package/{dist/cjs/constants → lib/consts/params}/promo-hue-shift.d.ts +1 -1
  18. package/lib/consts/params/promo-hue-shift.js +11 -0
  19. package/{dist/esm/constants/promo-hue-shift.js → lib/consts/params/promo-hue-shift.ts} +1 -1
  20. package/{dist/cjs/constants → lib/consts/params}/warning-hue-patch.d.ts +1 -1
  21. package/lib/consts/params/warning-hue-patch.js +22 -0
  22. package/{dist/esm/constants/warning-hue-patch.js → lib/consts/params/warning-hue-patch.ts} +1 -1
  23. package/lib/get-colors-base.d.ts +11 -0
  24. package/lib/get-colors-base.js +78 -0
  25. package/lib/get-colors-base.ts +99 -0
  26. package/lib/get-colors-default-tokens.d.ts +645 -0
  27. package/lib/get-colors-default-tokens.js +647 -0
  28. package/lib/get-colors-default-tokens.ts +646 -0
  29. package/lib/get-colors.d.ts +40 -0
  30. package/lib/get-colors.js +28 -0
  31. package/lib/get-colors.ts +65 -0
  32. package/{dist/cjs → lib}/helpers/get-interactions.d.ts +2 -2
  33. package/lib/helpers/get-interactions.js +35 -0
  34. package/lib/helpers/get-interactions.ts +64 -0
  35. package/{dist/cjs → lib}/helpers/get-logo.d.ts +2 -2
  36. package/lib/helpers/get-logo.js +25 -0
  37. package/lib/helpers/get-logo.ts +40 -0
  38. package/lib/helpers/get-palette.d.ts +51 -0
  39. package/lib/helpers/get-palette.js +204 -0
  40. package/lib/helpers/get-palette.ts +261 -0
  41. package/lib/helpers/get-promo.d.ts +6 -0
  42. package/lib/helpers/get-promo.js +47 -0
  43. package/lib/helpers/get-promo.ts +55 -0
  44. package/lib/types/tokens-base-generator.d.ts +43 -0
  45. package/{dist/cjs/types/generator-tokens.d.ts → lib/types/tokens-base-generator.ts} +12 -17
  46. package/lib/types/tokens-base.d.ts +55 -0
  47. package/{dist/esm/types/base-tokens.d.ts → lib/types/tokens-base.ts} +7 -2
  48. package/lib/types/tokens.d.ts +12 -0
  49. package/lib/types/tokens.js +1 -0
  50. package/lib/types/tokens.ts +18 -0
  51. package/lib/utils/convert-color.d.ts +3 -0
  52. package/lib/utils/convert-color.js +144 -0
  53. package/lib/utils/convert-color.ts +163 -0
  54. package/lib/utils/format-variable.js +6 -0
  55. package/lib/utils/format-variable.ts +7 -0
  56. package/package.json +44 -19
  57. package/{dist/tokens → tokens}/brand-blue-deep_accent-brand.css +33 -33
  58. package/{dist/tokens → tokens}/brand-blue-deep_accent-gray.css +33 -33
  59. package/{dist/tokens → tokens}/brand-blue_accent-brand.css +33 -33
  60. package/{dist/tokens → tokens}/brand-blue_accent-gray.css +33 -33
  61. package/{dist/tokens → tokens}/brand-green_accent-brand.css +33 -33
  62. package/{dist/tokens → tokens}/brand-green_accent-gray.css +33 -33
  63. package/{dist/tokens → tokens}/brand-mint_accent-brand.css +33 -33
  64. package/{dist/tokens → tokens}/brand-mint_accent-gray.css +33 -33
  65. package/{dist/tokens → tokens}/brand-orange_accent-gray.css +33 -33
  66. package/{dist/tokens → tokens}/brand-purple_accent-brand.css +33 -33
  67. package/{dist/tokens → tokens}/brand-purple_accent-gray.css +33 -33
  68. package/{dist/tokens → tokens}/brand-red_accent-gray.css +33 -33
  69. package/{dist/tokens → tokens}/brand-violet_accent-brand.css +33 -33
  70. package/{dist/tokens → tokens}/brand-violet_accent-gray.css +33 -33
  71. package/tokens-mobile/brand-blue-deep_accent-brand.json +718 -0
  72. package/tokens-mobile/brand-blue-deep_accent-gray.json +718 -0
  73. package/tokens-mobile/brand-blue_accent-brand.json +718 -0
  74. package/tokens-mobile/brand-blue_accent-gray.json +718 -0
  75. package/tokens-mobile/brand-green_accent-brand.json +718 -0
  76. package/tokens-mobile/brand-green_accent-gray.json +718 -0
  77. package/tokens-mobile/brand-mint_accent-brand.json +718 -0
  78. package/tokens-mobile/brand-mint_accent-gray.json +718 -0
  79. package/tokens-mobile/brand-orange_accent-gray.json +718 -0
  80. package/tokens-mobile/brand-purple_accent-brand.json +718 -0
  81. package/tokens-mobile/brand-purple_accent-gray.json +718 -0
  82. package/tokens-mobile/brand-red_accent-gray.json +718 -0
  83. package/tokens-mobile/brand-violet_accent-brand.json +718 -0
  84. package/tokens-mobile/brand-violet_accent-gray.json +718 -0
  85. package/dist/cjs/constants/abney-correction.d.ts +0 -2
  86. package/dist/cjs/constants/chroma-settings.d.ts +0 -2
  87. package/dist/cjs/constants/chroma-settings.js +0 -105
  88. package/dist/cjs/constants/default-swatch.d.ts +0 -109
  89. package/dist/cjs/constants/default-swatch.js +0 -112
  90. package/dist/cjs/constants/interaction-settings.js +0 -19
  91. package/dist/cjs/constants/logo-lightness.d.ts +0 -1
  92. package/dist/cjs/constants/logo-lightness.js +0 -4
  93. package/dist/cjs/constants/promo-hue-shift.js +0 -14
  94. package/dist/cjs/constants/warning-hue-patch.js +0 -25
  95. package/dist/cjs/get-base-tokens.d.ts +0 -26
  96. package/dist/cjs/get-base-tokens.js +0 -319
  97. package/dist/cjs/get-colors.d.ts +0 -20
  98. package/dist/cjs/get-colors.js +0 -20
  99. package/dist/cjs/get-default-tokens.d.ts +0 -645
  100. package/dist/cjs/get-default-tokens.js +0 -996
  101. package/dist/cjs/helpers/get-interactions.js +0 -61
  102. package/dist/cjs/helpers/get-logo.js +0 -32
  103. package/dist/cjs/helpers/get-palette.d.ts +0 -76
  104. package/dist/cjs/helpers/get-palette.js +0 -287
  105. package/dist/cjs/helpers/get-promo.d.ts +0 -12
  106. package/dist/cjs/helpers/get-promo.js +0 -56
  107. package/dist/cjs/types/base-tokens.d.ts +0 -125
  108. package/dist/cjs/types/base-tokens.js +0 -2
  109. package/dist/cjs/types/generator-tokens.js +0 -2
  110. package/dist/cjs/utils/format-variable.js +0 -15
  111. package/dist/colors.default-dark.js +0 -332
  112. package/dist/colors.default-light.js +0 -336
  113. package/dist/colors.less +0 -319
  114. package/dist/colors.scss +0 -319
  115. package/dist/esm/constants/abney-correction.d.ts +0 -2
  116. package/dist/esm/constants/abney-correction.js +0 -1102
  117. package/dist/esm/constants/chroma-settings.d.ts +0 -2
  118. package/dist/esm/constants/default-swatch.d.ts +0 -109
  119. package/dist/esm/constants/interaction-settings.d.ts +0 -8
  120. package/dist/esm/constants/logo-lightness.d.ts +0 -1
  121. package/dist/esm/constants/logo-lightness.js +0 -1
  122. package/dist/esm/constants/promo-hue-shift.d.ts +0 -3
  123. package/dist/esm/constants/warning-hue-patch.d.ts +0 -3
  124. package/dist/esm/get-base-tokens.d.ts +0 -26
  125. package/dist/esm/get-base-tokens.js +0 -257
  126. package/dist/esm/get-colors.d.ts +0 -20
  127. package/dist/esm/get-colors.js +0 -16
  128. package/dist/esm/get-default-tokens.d.ts +0 -645
  129. package/dist/esm/get-default-tokens.js +0 -992
  130. package/dist/esm/helpers/get-interactions.d.ts +0 -7
  131. package/dist/esm/helpers/get-interactions.js +0 -49
  132. package/dist/esm/helpers/get-logo.d.ts +0 -6
  133. package/dist/esm/helpers/get-logo.js +0 -28
  134. package/dist/esm/helpers/get-palette.d.ts +0 -76
  135. package/dist/esm/helpers/get-palette.js +0 -232
  136. package/dist/esm/helpers/get-promo.d.ts +0 -12
  137. package/dist/esm/helpers/get-promo.js +0 -51
  138. package/dist/esm/types/generator-tokens.d.ts +0 -43
  139. package/dist/esm/utils/format-variable.d.ts +0 -2
  140. package/dist/esm/utils/format-variable.js +0 -10
  141. package/dist/tokens-js/brand-blue-deep_accent-brand.js +0 -644
  142. package/dist/tokens-js/brand-blue-deep_accent-gray.js +0 -644
  143. package/dist/tokens-js/brand-blue_accent-brand.js +0 -644
  144. package/dist/tokens-js/brand-blue_accent-gray.js +0 -644
  145. package/dist/tokens-js/brand-green_accent-brand.js +0 -644
  146. package/dist/tokens-js/brand-green_accent-gray.js +0 -644
  147. package/dist/tokens-js/brand-mint_accent-brand.js +0 -644
  148. package/dist/tokens-js/brand-mint_accent-gray.js +0 -644
  149. package/dist/tokens-js/brand-orange_accent-gray.js +0 -644
  150. package/dist/tokens-js/brand-purple_accent-brand.js +0 -644
  151. package/dist/tokens-js/brand-purple_accent-gray.js +0 -644
  152. package/dist/tokens-js/brand-red_accent-gray.js +0 -644
  153. package/dist/tokens-js/brand-violet_accent-brand.js +0 -644
  154. package/dist/tokens-js/brand-violet_accent-gray.js +0 -644
  155. package/dist/tokens-mobile/brand-blue-deep_accent-brand.json +0 -718
  156. package/dist/tokens-mobile/brand-blue-deep_accent-gray.json +0 -718
  157. package/dist/tokens-mobile/brand-blue_accent-brand.json +0 -718
  158. package/dist/tokens-mobile/brand-blue_accent-gray.json +0 -718
  159. package/dist/tokens-mobile/brand-green_accent-brand.json +0 -718
  160. package/dist/tokens-mobile/brand-green_accent-gray.json +0 -718
  161. package/dist/tokens-mobile/brand-mint_accent-brand.json +0 -718
  162. package/dist/tokens-mobile/brand-mint_accent-gray.json +0 -718
  163. package/dist/tokens-mobile/brand-orange_accent-gray.json +0 -718
  164. package/dist/tokens-mobile/brand-purple_accent-brand.json +0 -718
  165. package/dist/tokens-mobile/brand-purple_accent-gray.json +0 -718
  166. package/dist/tokens-mobile/brand-red_accent-gray.json +0 -718
  167. package/dist/tokens-mobile/brand-violet_accent-brand.json +0 -718
  168. package/dist/tokens-mobile/brand-violet_accent-gray.json +0 -718
  169. /package/{dist/colors.js → colors.js} +0 -0
  170. /package/{dist/cjs/constants/interaction-settings.d.ts → lib/consts/params/interactions.d.ts} +0 -0
  171. /package/{dist/esm/constants/interaction-settings.js → lib/consts/params/interactions.js} +0 -0
  172. /package/{dist/esm/types/base-tokens.js → lib/types/tokens-base-generator.js} +0 -0
  173. /package/{dist/esm/types/generator-tokens.js → lib/types/tokens-base.js} +0 -0
  174. /package/{dist/cjs → lib}/utils/format-variable.d.ts +0 -0
@@ -0,0 +1,40 @@
1
+ import { type ConfigOptions, type PresetOrCustom } from './get-colors-base.js';
2
+ import type { TokensBase } from './types/tokens-base.js';
3
+ import { type ColorFormat } from './utils/convert-color.js';
4
+ import type { DefaultTokensFull, Themed } from './types/tokens.js';
5
+ import type * as DEFAULT_SWATCH from './consts/default-swatch.js';
6
+ export interface SemanticConfigOptions<T> extends ConfigOptions {
7
+ /** Брендовый цвет из палитры или кастомная строка */
8
+ brand: PresetOrCustom<keyof typeof DEFAULT_SWATCH.brand>;
9
+ /**
10
+ * Акцентный цвет.
11
+ * `brand` — совпадает с брендовым, `gray` — в оттенках серого
12
+ */
13
+ accent: PresetOrCustom<'brand' | 'gray'>;
14
+ /** Объект с образцами цветов warning, error, success */
15
+ system?: typeof DEFAULT_SWATCH.system;
16
+ /**
17
+ * Формат выгрузки токенов
18
+ * @default 'hex/rgba'
19
+ */
20
+ format?: ColorFormat;
21
+ /**
22
+ * Возвращать токены для конкретной темы или для всех сразу
23
+ * @default 'all'
24
+ */
25
+ theme?: 'all' | 'light' | 'dark';
26
+ /**
27
+ * Колбэк для формирования кастомного списка семантических токенов
28
+ * @param base Ссылки на базовые токены
29
+ * @param defaults Токены по умолчанию
30
+ * @param params Параметры переданные в getColors
31
+ */
32
+ overrides?: (base?: TokensBase, defaults?: DefaultTokensFull, params?: SemanticConfigOptions<T>) => Themed<T>;
33
+ }
34
+ /**
35
+ * Получение списка семантических токенов
36
+ *
37
+ * @param {SemanticConfigOptions<T>} params - Конфигурация генерации
38
+ * @returns {DefaultTokensFull | T | Themed<T>} Список токенов для light, dark или вместе
39
+ */
40
+ export declare function getColors<T>(params: SemanticConfigOptions<T>): any;
@@ -0,0 +1,28 @@
1
+ import { getColorsDefaultTokens } from './get-colors-default-tokens.js';
2
+ import { getColorsBase } from './get-colors-base.js';
3
+ import { convertColorFormat } from './utils/convert-color.js';
4
+ /**
5
+ * Получение списка семантических токенов
6
+ *
7
+ * @param {SemanticConfigOptions<T>} params - Конфигурация генерации
8
+ * @returns {DefaultTokensFull | T | Themed<T>} Список токенов для light, dark или вместе
9
+ */
10
+ export function getColors(params) {
11
+ var theme = params.theme || 'all';
12
+ var base = getColorsBase(params);
13
+ var defaults = getColorsDefaultTokens(base);
14
+ var result;
15
+ if (params.overrides) {
16
+ result = params.overrides(base, defaults, params);
17
+ }
18
+ else {
19
+ result = defaults;
20
+ }
21
+ if (params.format) {
22
+ result = convertColorFormat(result, params.format);
23
+ }
24
+ if (theme === 'all') {
25
+ return result;
26
+ }
27
+ return result[theme];
28
+ }
@@ -0,0 +1,65 @@
1
+ import { getColorsDefaultTokens } from './get-colors-default-tokens.js';
2
+ import { type ConfigOptions, type PresetOrCustom, getColorsBase } from './get-colors-base.js';
3
+ import type { TokensBase } from './types/tokens-base.js';
4
+ import { convertColorFormat, type ColorFormat } from './utils/convert-color.js';
5
+ import type { DefaultTokensFull, Themed } from './types/tokens.js';
6
+ import type * as DEFAULT_SWATCH from './consts/default-swatch.js';
7
+
8
+ export interface SemanticConfigOptions<T> extends ConfigOptions {
9
+ /** Брендовый цвет из палитры или кастомная строка */
10
+ brand: PresetOrCustom<keyof typeof DEFAULT_SWATCH.brand>;
11
+ /**
12
+ * Акцентный цвет.
13
+ * `brand` — совпадает с брендовым, `gray` — в оттенках серого
14
+ */
15
+ accent: PresetOrCustom<'brand' | 'gray'>;
16
+ /** Объект с образцами цветов warning, error, success */
17
+ system?: typeof DEFAULT_SWATCH.system;
18
+ /**
19
+ * Формат выгрузки токенов
20
+ * @default 'hex/rgba'
21
+ */
22
+ format?: ColorFormat;
23
+ /**
24
+ * Возвращать токены для конкретной темы или для всех сразу
25
+ * @default 'all'
26
+ */
27
+ theme?: 'all' | 'light' | 'dark';
28
+ /**
29
+ * Колбэк для формирования кастомного списка семантических токенов
30
+ * @param base Ссылки на базовые токены
31
+ * @param defaults Токены по умолчанию
32
+ * @param params Параметры переданные в getColors
33
+ */
34
+ overrides?: (base?: TokensBase, defaults?: DefaultTokensFull, params?: SemanticConfigOptions<T>) => Themed<T>;
35
+ }
36
+
37
+ /**
38
+ * Получение списка семантических токенов
39
+ *
40
+ * @param {SemanticConfigOptions<T>} params - Конфигурация генерации
41
+ * @returns {DefaultTokensFull | T | Themed<T>} Список токенов для light, dark или вместе
42
+ */
43
+ export function getColors<T>(params: SemanticConfigOptions<T>) {
44
+ const theme = params.theme || 'all';
45
+ const base = getColorsBase(params);
46
+ const defaults = getColorsDefaultTokens(base);
47
+
48
+ let result: any;
49
+
50
+ if (params.overrides) {
51
+ result = params.overrides(base, defaults, params);
52
+ } else {
53
+ result = defaults;
54
+ }
55
+
56
+ if (params.format) {
57
+ result = convertColorFormat(result, params.format);
58
+ }
59
+
60
+ if (theme === 'all') {
61
+ return result;
62
+ }
63
+
64
+ return result[theme];
65
+ }
@@ -1,6 +1,6 @@
1
1
  interface InteractionColors {
2
- light: string;
3
- dark: string;
2
+ light: string;
3
+ dark: string;
4
4
  }
5
5
  export declare function getHover(hex: string): InteractionColors;
6
6
  export declare function getPressed(hex: string): InteractionColors;
@@ -0,0 +1,35 @@
1
+ import { converter } from 'culori';
2
+ import { HOVER_LIGHT_L, HOVER_LIGHT_C, HOVER_DARK_L, HOVER_DARK_C, PRESSED_LIGHT_L, PRESSED_LIGHT_C, PRESSED_DARK_L, PRESSED_DARK_C, } from '../consts/params/interactions.js';
3
+ function applyOklchDelta(oklchColor, dL, dC) {
4
+ var _a = oklchColor.l, l = _a === void 0 ? 0 : _a, _b = oklchColor.c, c = _b === void 0 ? 0 : _b, _c = oklchColor.h, h = _c === void 0 ? 0 : _c;
5
+ var safeH = h === undefined || isNaN(h) ? 0 : h;
6
+ var newL = Math.max(0, Math.min(1, l + dL / 100));
7
+ var newC = Math.max(0, c + dC);
8
+ return "oklch(".concat(newL.toFixed(3), " ").concat(newC.toFixed(3), " ").concat(safeH.toFixed(0), ")");
9
+ }
10
+ export function getHover(hex) {
11
+ var toOklch = converter('oklch');
12
+ var oklchColor = toOklch(hex);
13
+ if (!oklchColor) {
14
+ return { light: hex, dark: hex };
15
+ }
16
+ var lightHoverColor = applyOklchDelta(oklchColor, HOVER_LIGHT_L, HOVER_LIGHT_C);
17
+ var darkHoverColor = applyOklchDelta(oklchColor, HOVER_DARK_L, HOVER_DARK_C);
18
+ return {
19
+ light: lightHoverColor,
20
+ dark: darkHoverColor,
21
+ };
22
+ }
23
+ export function getPressed(hex) {
24
+ var toOklch = converter('oklch');
25
+ var oklchColor = toOklch(hex);
26
+ if (!oklchColor) {
27
+ return { light: hex, dark: hex };
28
+ }
29
+ var lightPressedColor = applyOklchDelta(oklchColor, PRESSED_LIGHT_L, PRESSED_LIGHT_C);
30
+ var darkPressedColor = applyOklchDelta(oklchColor, PRESSED_DARK_L, PRESSED_DARK_C);
31
+ return {
32
+ light: lightPressedColor,
33
+ dark: darkPressedColor,
34
+ };
35
+ }
@@ -0,0 +1,64 @@
1
+ import { converter, type Oklch } from 'culori';
2
+
3
+ import {
4
+ HOVER_LIGHT_L,
5
+ HOVER_LIGHT_C,
6
+ HOVER_DARK_L,
7
+ HOVER_DARK_C,
8
+ PRESSED_LIGHT_L,
9
+ PRESSED_LIGHT_C,
10
+ PRESSED_DARK_L,
11
+ PRESSED_DARK_C,
12
+ } from '../consts/params/interactions.js';
13
+
14
+ interface InteractionColors {
15
+ light: string;
16
+ dark: string;
17
+ }
18
+
19
+ function applyOklchDelta(oklchColor: Oklch, dL: number, dC: number): string {
20
+ const { l = 0, c = 0, h = 0 } = oklchColor;
21
+
22
+ const safeH = h === undefined || isNaN(h) ? 0 : h;
23
+
24
+ const newL = Math.max(0, Math.min(1, l + dL / 100));
25
+ const newC = Math.max(0, c + dC);
26
+
27
+ return `oklch(${newL.toFixed(3)} ${newC.toFixed(3)} ${safeH.toFixed(0)})`;
28
+ }
29
+
30
+ export function getHover(hex: string): InteractionColors {
31
+ const toOklch = converter('oklch');
32
+ const oklchColor = toOklch(hex);
33
+
34
+ if (!oklchColor) {
35
+ return { light: hex, dark: hex };
36
+ }
37
+
38
+ const lightHoverColor = applyOklchDelta(oklchColor, HOVER_LIGHT_L, HOVER_LIGHT_C);
39
+
40
+ const darkHoverColor = applyOklchDelta(oklchColor, HOVER_DARK_L, HOVER_DARK_C);
41
+
42
+ return {
43
+ light: lightHoverColor,
44
+ dark: darkHoverColor,
45
+ };
46
+ }
47
+
48
+ export function getPressed(hex: string): InteractionColors {
49
+ const toOklch = converter('oklch');
50
+ const oklchColor = toOklch(hex);
51
+
52
+ if (!oklchColor) {
53
+ return { light: hex, dark: hex };
54
+ }
55
+
56
+ const lightPressedColor = applyOklchDelta(oklchColor, PRESSED_LIGHT_L, PRESSED_LIGHT_C);
57
+
58
+ const darkPressedColor = applyOklchDelta(oklchColor, PRESSED_DARK_L, PRESSED_DARK_C);
59
+
60
+ return {
61
+ light: lightPressedColor,
62
+ dark: darkPressedColor,
63
+ };
64
+ }
@@ -1,6 +1,6 @@
1
1
  interface LogoColors {
2
- light: string;
3
- dark: string;
2
+ light: string;
3
+ dark: string;
4
4
  }
5
5
  export declare function getLogo(hex: string): LogoColors;
6
6
  export {};
@@ -0,0 +1,25 @@
1
+ import { converter } from 'culori';
2
+ import { LOGO_LIGHTNESS_MIN } from '../consts/params/logo-lightness.js';
3
+ export function getLogo(hex) {
4
+ var toOklch = converter('oklch');
5
+ var oklchColor = toOklch(hex);
6
+ var lightThemeLogoColor = hex;
7
+ if (!oklchColor) {
8
+ var fallbackColor = "oklch(".concat(LOGO_LIGHTNESS_MIN, "% 0 0)");
9
+ return { light: hex, dark: fallbackColor };
10
+ }
11
+ var _a = oklchColor.l, l = _a === void 0 ? 0 : _a, _b = oklchColor.c, c = _b === void 0 ? 0 : _b;
12
+ var h = oklchColor.h;
13
+ var safeH = h === undefined || isNaN(h) ? 0 : h;
14
+ l = l || 0;
15
+ c = c || 0;
16
+ var percentL = l * 100;
17
+ if (percentL < LOGO_LIGHTNESS_MIN) {
18
+ l = LOGO_LIGHTNESS_MIN / 100;
19
+ }
20
+ var darkThemeLogoColor = "oklch(".concat(l.toFixed(3), " ").concat(c.toFixed(3), " ").concat(safeH.toFixed(0), ")");
21
+ return {
22
+ light: lightThemeLogoColor,
23
+ dark: darkThemeLogoColor,
24
+ };
25
+ }
@@ -0,0 +1,40 @@
1
+ import { converter, type Oklch } from 'culori';
2
+
3
+ import { LOGO_LIGHTNESS_MIN } from '../consts/params/logo-lightness.js';
4
+
5
+ interface LogoColors {
6
+ light: string;
7
+ dark: string;
8
+ }
9
+
10
+ export function getLogo(hex: string): LogoColors {
11
+ const toOklch = converter('oklch');
12
+ const oklchColor = toOklch(hex) as Oklch | undefined;
13
+
14
+ const lightThemeLogoColor = hex;
15
+
16
+ if (!oklchColor) {
17
+ const fallbackColor = `oklch(${LOGO_LIGHTNESS_MIN}% 0 0)`;
18
+ return { light: hex, dark: fallbackColor };
19
+ }
20
+
21
+ let { l = 0, c = 0 } = oklchColor;
22
+ const { h } = oklchColor;
23
+
24
+ const safeH = h === undefined || isNaN(h) ? 0 : h;
25
+
26
+ l = l || 0;
27
+ c = c || 0;
28
+
29
+ const percentL = l * 100;
30
+ if (percentL < LOGO_LIGHTNESS_MIN) {
31
+ l = LOGO_LIGHTNESS_MIN / 100;
32
+ }
33
+
34
+ const darkThemeLogoColor = `oklch(${l.toFixed(3)} ${c.toFixed(3)} ${safeH.toFixed(0)})`;
35
+
36
+ return {
37
+ light: lightThemeLogoColor,
38
+ dark: darkThemeLogoColor,
39
+ };
40
+ }
@@ -0,0 +1,51 @@
1
+ import type { GeneratorColorAbneyCorrection, GeneratorColorChromaParamsGroup, GeneratorColorPalette, GeneratorColorWarningHuePatch } from '../types/tokens-base-generator.js';
2
+ interface GeneratePaletteParams {
3
+ color: string;
4
+ type?: 'default' | 'warning';
5
+ settings?: {
6
+ chromaSettings?: GeneratorColorChromaParamsGroup;
7
+ abneyCorrection?: GeneratorColorAbneyCorrection;
8
+ promoHueShifts?: {
9
+ [hueRange: number]: number;
10
+ };
11
+ warningHuePatch?: GeneratorColorWarningHuePatch;
12
+ };
13
+ }
14
+ export declare function getPalette({ color, type, settings: customSettings, }: GeneratePaletteParams): GeneratorColorPalette;
15
+ export declare function getAbneyHueShift(lightness: number, currentHue: number, abneyData: GeneratorColorAbneyCorrection): number;
16
+ export declare function applyAbneyShift(lightness: number, currentHue: number, abneyData: GeneratorColorAbneyCorrection): number;
17
+ export declare function applyWarningHuePatch(currentHue: number, lightness: number, warningHuePatchData: GeneratorColorWarningHuePatch, isWarningMode: boolean): number;
18
+ export declare function calculateBaseHueAndCorrectionRange(inputColorString: string, abneyData: GeneratorColorAbneyCorrection): {
19
+ baseHue: number;
20
+ correctionLightness: number;
21
+ correctionHueRange: number;
22
+ } | null;
23
+ export declare function calcOnBrand(hex: string): {
24
+ 4: string;
25
+ 6: string;
26
+ 8: string;
27
+ 12: string;
28
+ 16: string;
29
+ 20: string;
30
+ 24: string;
31
+ 28: string;
32
+ 32: string;
33
+ 36: string;
34
+ 40: string;
35
+ 44: string;
36
+ 48: string;
37
+ 52: string;
38
+ 56: string;
39
+ 60: string;
40
+ 64: string;
41
+ 68: string;
42
+ 72: string;
43
+ 76: string;
44
+ 80: string;
45
+ 84: string;
46
+ 88: string;
47
+ 92: string;
48
+ 96: string;
49
+ 100: string;
50
+ };
51
+ export {};
@@ -0,0 +1,204 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
12
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
13
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
14
+ if (ar || !(i in from)) {
15
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
16
+ ar[i] = from[i];
17
+ }
18
+ }
19
+ return to.concat(ar || Array.prototype.slice.call(from));
20
+ };
21
+ import { clampChroma, converter } from 'culori';
22
+ import { calcAPCA } from 'apca-w3';
23
+ import * as DefaultSwatch from '../consts/default-swatch.js';
24
+ import { CHROMA_PARAMS } from '../consts/params/chroma-params.js';
25
+ import { ABNEY_CORRECTION } from '../consts/params/abney-correction.js';
26
+ import { PROMO_HUE_SHIFTS } from '../consts/params/promo-hue-shift.js';
27
+ import { WARNING_HUE_PATCH } from '../consts/params/warning-hue-patch.js';
28
+ export function getPalette(_a) {
29
+ var color = _a.color, _b = _a.type, type = _b === void 0 ? 'default' : _b, customSettings = _a.settings;
30
+ var defaultSettings = {
31
+ chromaSettings: CHROMA_PARAMS,
32
+ abneyCorrection: ABNEY_CORRECTION,
33
+ promoHueShifts: PROMO_HUE_SHIFTS,
34
+ warningHuePatch: WARNING_HUE_PATCH,
35
+ };
36
+ var settings = __assign(__assign({}, defaultSettings), customSettings);
37
+ var toOklch = converter('oklch');
38
+ var oklchColor = toOklch(color);
39
+ var currentHue = (oklchColor === null || oklchColor === void 0 ? void 0 : oklchColor.h) || 0;
40
+ var toNorm = function (x) { return x / 100; };
41
+ var calculateChromaValue = function (rel, min, max, baseChromaMax) {
42
+ var raw = (baseChromaMax * rel) / 100;
43
+ var value = raw;
44
+ if (min !== undefined) {
45
+ value = Math.max(toNorm(min), value);
46
+ }
47
+ if (max !== undefined) {
48
+ value = Math.min(toNorm(max), value);
49
+ }
50
+ return Math.min(value, baseChromaMax);
51
+ };
52
+ var result = {
53
+ vivid: {},
54
+ normal: {},
55
+ dim: {},
56
+ };
57
+ var isWarning = type === 'warning';
58
+ for (var Lstr in settings.chromaSettings) {
59
+ var L = +Lstr;
60
+ if (L === 100) {
61
+ result.vivid[L] = "oklch(100% 0 0)";
62
+ result.normal[L] = "oklch(100% 0 0)";
63
+ result.dim[L] = "oklch(100% 0 0)";
64
+ continue;
65
+ }
66
+ var hueAfterWarningPatch = applyWarningHuePatch(currentHue, L, settings.warningHuePatch, isWarning);
67
+ var appliedHueShift = applyAbneyShift(L, hueAfterWarningPatch, settings.abneyCorrection);
68
+ var chromaMax = clampChroma({ mode: 'oklch', l: L / 100, c: 1, h: appliedHueShift }, 'oklch').c;
69
+ var currentParams = settings.chromaSettings[L];
70
+ var vividN = calculateChromaValue(currentParams.vivid.rel, currentParams.vivid.min, currentParams.vivid.max, chromaMax);
71
+ var normN = calculateChromaValue(currentParams.normal.rel, currentParams.normal.min, currentParams.normal.max, chromaMax);
72
+ var dimN = calculateChromaValue(currentParams.dim.rel, currentParams.dim.min, currentParams.dim.max, chromaMax);
73
+ result.vivid[L] = "oklch(".concat(L, "% ").concat(vividN.toFixed(3), " ").concat(appliedHueShift.toFixed(0), ")");
74
+ result.normal[L] = "oklch(".concat(L, "% ").concat(normN.toFixed(3), " ").concat(appliedHueShift.toFixed(0), ")");
75
+ result.dim[L] = "oklch(".concat(L, "% ").concat(dimN.toFixed(3), " ").concat(appliedHueShift.toFixed(0), ")");
76
+ }
77
+ return result;
78
+ }
79
+ export function getAbneyHueShift(lightness, currentHue, abneyData) {
80
+ var lightnessData = abneyData[lightness];
81
+ if (!lightnessData) {
82
+ return 0;
83
+ }
84
+ var hueRanges = Object.keys(lightnessData)
85
+ .map(Number)
86
+ .sort(function (a, b) { return a - b; });
87
+ var selectedHueRange = hueRanges[0];
88
+ for (var i = 0; i < hueRanges.length; i++) {
89
+ var startRange = hueRanges[i];
90
+ var endRange = hueRanges[i + 1] !== undefined ? hueRanges[i + 1] : 360;
91
+ if (currentHue >= startRange && currentHue < endRange) {
92
+ selectedHueRange = startRange;
93
+ break;
94
+ }
95
+ if (i === hueRanges.length - 1 && currentHue >= startRange && currentHue < 360) {
96
+ selectedHueRange = startRange;
97
+ break;
98
+ }
99
+ }
100
+ return lightnessData[selectedHueRange] !== undefined ? lightnessData[selectedHueRange] : 0;
101
+ }
102
+ export function applyAbneyShift(lightness, currentHue, abneyData) {
103
+ var abneyShift = getAbneyHueShift(lightness, currentHue, abneyData);
104
+ return (currentHue + abneyShift + 360) % 360;
105
+ }
106
+ export function applyWarningHuePatch(currentHue, lightness, warningHuePatchData, isWarningMode) {
107
+ if (isWarningMode) {
108
+ var patch = warningHuePatchData[lightness];
109
+ if (patch !== undefined) {
110
+ return (currentHue + patch + 360) % 360;
111
+ }
112
+ }
113
+ return currentHue;
114
+ }
115
+ function findClosestLightnessStep(targetL, availableLightnessSteps) {
116
+ if (availableLightnessSteps.length === 0) {
117
+ return targetL;
118
+ }
119
+ var sortedSteps = __spreadArray([], availableLightnessSteps, true).sort(function (a, b) { return a - b; });
120
+ var closestStep = sortedSteps[0];
121
+ var minDiff = Math.abs(targetL - closestStep);
122
+ for (var i = 1; i < sortedSteps.length; i++) {
123
+ var currentStep = sortedSteps[i];
124
+ var diff = Math.abs(targetL - currentStep);
125
+ if (diff < minDiff || (diff === minDiff && currentStep > closestStep)) {
126
+ minDiff = diff;
127
+ closestStep = currentStep;
128
+ }
129
+ }
130
+ return closestStep;
131
+ }
132
+ export function calculateBaseHueAndCorrectionRange(inputColorString, abneyData) {
133
+ var toOklch = converter('oklch');
134
+ var oklch = toOklch(inputColorString);
135
+ if (!oklch) {
136
+ console.warn("Could not parse color string: ".concat(inputColorString));
137
+ return null;
138
+ }
139
+ var targetLightness = Math.round(oklch.l * 100);
140
+ var targetHue = oklch.h;
141
+ if (isNaN(targetHue)) {
142
+ console.warn("Achromatic color detected (".concat(inputColorString, "). Defaulting hue to 0."));
143
+ targetHue = 0;
144
+ }
145
+ var availableLightnessSteps = Object.keys(abneyData).map(Number);
146
+ if (availableLightnessSteps.length === 0) {
147
+ console.warn('Abney correction data is empty, cannot calculate base hue.');
148
+ return null;
149
+ }
150
+ var closestLightness = findClosestLightnessStep(targetLightness, availableLightnessSteps);
151
+ var lightnessCorrectionData = abneyData[closestLightness];
152
+ if (!lightnessCorrectionData) {
153
+ console.warn("No Abney correction data for lightness ".concat(closestLightness, "."));
154
+ return null;
155
+ }
156
+ var correctedHueMap = Object.entries(lightnessCorrectionData).map(function (_a) {
157
+ var rawHueStr = _a[0], shift = _a[1];
158
+ var rawHue = Number(rawHueStr);
159
+ return {
160
+ rawHue: rawHue,
161
+ shift: shift,
162
+ correctedHue: (rawHue + shift + 360) % 360,
163
+ };
164
+ });
165
+ correctedHueMap.sort(function (a, b) {
166
+ if (a.correctedHue !== b.correctedHue) {
167
+ return a.correctedHue - b.correctedHue;
168
+ }
169
+ return a.rawHue - b.rawHue;
170
+ });
171
+ if (correctedHueMap.length === 0) {
172
+ console.warn("No hue ranges defined for lightness ".concat(closestLightness, "."));
173
+ return null;
174
+ }
175
+ var findCorrectRange = function () {
176
+ var nextRangeIndex = correctedHueMap.findIndex(function (range) { return range.correctedHue > targetHue; });
177
+ if (nextRangeIndex === 0) {
178
+ return correctedHueMap[correctedHueMap.length - 1];
179
+ }
180
+ if (nextRangeIndex > 0) {
181
+ return correctedHueMap[nextRangeIndex - 1];
182
+ }
183
+ return correctedHueMap[correctedHueMap.length - 1];
184
+ };
185
+ var selectedRange = findCorrectRange();
186
+ if (!selectedRange) {
187
+ console.error('Could not determine the correct hue range.');
188
+ return null;
189
+ }
190
+ var baseHue = (targetHue - selectedRange.shift + 360) % 360;
191
+ return {
192
+ baseHue: baseHue,
193
+ correctionLightness: closestLightness,
194
+ correctionHueRange: selectedRange.rawHue,
195
+ };
196
+ }
197
+ export function calcOnBrand(hex) {
198
+ var whiteContrast = Math.abs(Number(calcAPCA('#fff', hex)));
199
+ var blackContrast = Math.abs(Number(calcAPCA('#000', hex)));
200
+ if (whiteContrast + 10 >= blackContrast) {
201
+ return DefaultSwatch.whiteAlpha;
202
+ }
203
+ return DefaultSwatch.blackAlpha;
204
+ }