@skbkontur/colors 2.0.0-alpha.3 → 2.0.0-alpha.5

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 (130) hide show
  1. package/README.md +3 -3
  2. package/colors.d.ts +319 -0
  3. package/colors.js +319 -0
  4. package/colors.less +319 -0
  5. package/colors.scss +319 -0
  6. package/lib/consts/default-swatch.d.ts +108 -0
  7. package/lib/consts/default-swatch.js +108 -0
  8. package/{dist/esm/consts/default-swatch.js → lib/consts/default-swatch.ts} +11 -7
  9. package/lib/consts/params/abney-correction.js +1102 -0
  10. package/{dist/esm/consts/params/abney-correction.js → lib/consts/params/abney-correction.ts} +3 -1
  11. package/lib/consts/params/chroma-params.js +102 -0
  12. package/{dist/esm/consts/params/chroma-params.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.ts +1 -0
  15. package/{dist/esm → lib}/consts/params/promo-hue-shift.d.ts +1 -1
  16. package/lib/consts/params/promo-hue-shift.js +11 -0
  17. package/{dist/esm/consts/params/promo-hue-shift.js → lib/consts/params/promo-hue-shift.ts} +1 -1
  18. package/{dist/esm → lib}/consts/params/warning-hue-patch.d.ts +1 -1
  19. package/lib/consts/params/warning-hue-patch.js +22 -0
  20. package/{dist/esm/consts/params/warning-hue-patch.js → lib/consts/params/warning-hue-patch.ts} +1 -1
  21. package/lib/get-colors-base.d.ts +11 -0
  22. package/lib/get-colors-base.js +78 -0
  23. package/{dist/esm/get-colors-base.js → lib/get-colors-base.ts} +44 -26
  24. package/lib/get-colors-default-tokens.d.ts +645 -0
  25. package/lib/get-colors-default-tokens.js +647 -0
  26. package/lib/get-colors-default-tokens.ts +646 -0
  27. package/lib/get-colors.d.ts +39 -0
  28. package/lib/get-colors.js +24 -0
  29. package/lib/get-colors.ts +59 -0
  30. package/{dist/esm → lib}/helpers/get-interactions.d.ts +2 -2
  31. package/lib/helpers/get-interactions.js +35 -0
  32. package/lib/helpers/get-interactions.ts +64 -0
  33. package/{dist/esm → lib}/helpers/get-logo.d.ts +2 -2
  34. package/lib/helpers/get-logo.js +25 -0
  35. package/lib/helpers/get-logo.ts +40 -0
  36. package/lib/helpers/get-palette.d.ts +51 -0
  37. package/lib/helpers/get-palette.js +204 -0
  38. package/lib/helpers/get-palette.ts +261 -0
  39. package/lib/helpers/get-promo.d.ts +6 -0
  40. package/lib/helpers/get-promo.js +47 -0
  41. package/lib/helpers/get-promo.ts +55 -0
  42. package/lib/types/tokens-base-generator.d.ts +43 -0
  43. package/{dist/esm/types/tokens-base-generator.d.ts → lib/types/tokens-base-generator.ts} +10 -15
  44. package/lib/types/tokens-base.d.ts +55 -0
  45. package/{dist/esm/types/tokens-base.d.ts → lib/types/tokens-base.ts} +7 -2
  46. package/lib/types/tokens.d.ts +12 -0
  47. package/{dist/esm/types/tokens.d.ts → lib/types/tokens.ts} +6 -0
  48. package/lib/utils/convert-color.js +144 -0
  49. package/lib/utils/convert-color.ts +163 -0
  50. package/lib/utils/format-variable.js +6 -0
  51. package/lib/utils/format-variable.ts +7 -0
  52. package/package.json +66 -7
  53. package/{dist/tokens → tokens}/brand-blue-deep_accent-brand.css +2 -2
  54. package/{dist/tokens → tokens}/brand-blue-deep_accent-gray.css +2 -2
  55. package/{dist/tokens → tokens}/brand-blue_accent-brand.css +2 -2
  56. package/{dist/tokens → tokens}/brand-blue_accent-gray.css +2 -2
  57. package/{dist/tokens → tokens}/brand-green_accent-brand.css +2 -2
  58. package/{dist/tokens → tokens}/brand-green_accent-gray.css +2 -2
  59. package/{dist/tokens → tokens}/brand-mint_accent-brand.css +2 -2
  60. package/{dist/tokens → tokens}/brand-mint_accent-gray.css +2 -2
  61. package/{dist/tokens → tokens}/brand-orange_accent-gray.css +2 -2
  62. package/{dist/tokens → tokens}/brand-purple_accent-brand.css +2 -2
  63. package/{dist/tokens → tokens}/brand-purple_accent-gray.css +2 -2
  64. package/{dist/tokens → tokens}/brand-red_accent-gray.css +2 -2
  65. package/{dist/tokens → tokens}/brand-violet_accent-brand.css +2 -2
  66. package/{dist/tokens → tokens}/brand-violet_accent-gray.css +2 -2
  67. package/{dist/tokens-mobile → tokens-mobile}/brand-blue-deep_accent-brand.json +117 -117
  68. package/{dist/tokens-mobile → tokens-mobile}/brand-blue-deep_accent-gray.json +135 -135
  69. package/{dist/tokens-mobile → tokens-mobile}/brand-blue_accent-brand.json +117 -117
  70. package/{dist/tokens-mobile → tokens-mobile}/brand-blue_accent-gray.json +135 -135
  71. package/{dist/tokens-mobile → tokens-mobile}/brand-green_accent-brand.json +117 -117
  72. package/{dist/tokens-mobile → tokens-mobile}/brand-green_accent-gray.json +135 -135
  73. package/{dist/tokens-mobile → tokens-mobile}/brand-mint_accent-brand.json +117 -117
  74. package/{dist/tokens-mobile → tokens-mobile}/brand-mint_accent-gray.json +135 -135
  75. package/{dist/tokens-mobile → tokens-mobile}/brand-orange_accent-gray.json +135 -135
  76. package/{dist/tokens-mobile → tokens-mobile}/brand-purple_accent-brand.json +117 -117
  77. package/{dist/tokens-mobile → tokens-mobile}/brand-purple_accent-gray.json +135 -135
  78. package/{dist/tokens-mobile → tokens-mobile}/brand-red_accent-gray.json +135 -135
  79. package/{dist/tokens-mobile → tokens-mobile}/brand-violet_accent-brand.json +117 -117
  80. package/{dist/tokens-mobile → tokens-mobile}/brand-violet_accent-gray.json +135 -135
  81. package/CHANGELOG.md +0 -84
  82. package/dist/colors.default-dark.js +0 -332
  83. package/dist/colors.default-light.js +0 -336
  84. package/dist/colors.less +0 -319
  85. package/dist/colors.scss +0 -319
  86. package/dist/esm/consts/default-swatch.d.ts +0 -109
  87. package/dist/esm/get-colors-base.d.ts +0 -12
  88. package/dist/esm/get-colors-default-tokens.d.ts +0 -645
  89. package/dist/esm/get-colors-default-tokens.js +0 -992
  90. package/dist/esm/get-colors.d.ts +0 -13
  91. package/dist/esm/get-colors.js +0 -14
  92. package/dist/esm/get-default-tokens.d.ts +0 -645
  93. package/dist/esm/get-default-tokens.js +0 -992
  94. package/dist/esm/helpers/get-interactions.js +0 -49
  95. package/dist/esm/helpers/get-logo.js +0 -28
  96. package/dist/esm/helpers/get-palette.d.ts +0 -76
  97. package/dist/esm/helpers/get-palette.js +0 -232
  98. package/dist/esm/helpers/get-promo.d.ts +0 -12
  99. package/dist/esm/helpers/get-promo.js +0 -51
  100. package/dist/esm/utils/convert-color.js +0 -133
  101. package/dist/esm/utils/format-variable.js +0 -10
  102. package/dist/tokens-js/brand-blue-deep_accent-brand.js +0 -644
  103. package/dist/tokens-js/brand-blue-deep_accent-gray.js +0 -644
  104. package/dist/tokens-js/brand-blue_accent-brand.js +0 -644
  105. package/dist/tokens-js/brand-blue_accent-gray.js +0 -644
  106. package/dist/tokens-js/brand-green_accent-brand.js +0 -644
  107. package/dist/tokens-js/brand-green_accent-gray.js +0 -644
  108. package/dist/tokens-js/brand-mint_accent-brand.js +0 -644
  109. package/dist/tokens-js/brand-mint_accent-gray.js +0 -644
  110. package/dist/tokens-js/brand-orange_accent-gray.js +0 -644
  111. package/dist/tokens-js/brand-purple_accent-brand.js +0 -644
  112. package/dist/tokens-js/brand-purple_accent-gray.js +0 -644
  113. package/dist/tokens-js/brand-red_accent-gray.js +0 -644
  114. package/dist/tokens-js/brand-violet_accent-brand.js +0 -644
  115. package/dist/tokens-js/brand-violet_accent-gray.js +0 -644
  116. package/scripts/babel-register.js +0 -4
  117. package/scripts/tokens-base.json +0 -3499
  118. package/scripts/tokens.json +0 -710
  119. /package/{dist/colors.js → colors.ts} +0 -0
  120. /package/{dist/esm → lib}/consts/params/abney-correction.d.ts +0 -0
  121. /package/{dist/esm → lib}/consts/params/chroma-params.d.ts +0 -0
  122. /package/{dist/esm → lib}/consts/params/interactions.d.ts +0 -0
  123. /package/{dist/esm → lib}/consts/params/interactions.js +0 -0
  124. /package/{dist/esm → lib}/consts/params/logo-lightness.d.ts +0 -0
  125. /package/{dist/esm → lib}/consts/params/logo-lightness.js +0 -0
  126. /package/{dist/esm → lib}/types/tokens-base-generator.js +0 -0
  127. /package/{dist/esm → lib}/types/tokens-base.js +0 -0
  128. /package/{dist/esm → lib}/types/tokens.js +0 -0
  129. /package/{dist/esm → lib}/utils/convert-color.d.ts +0 -0
  130. /package/{dist/esm → lib}/utils/format-variable.d.ts +0 -0
@@ -0,0 +1,39 @@
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 { DefaultTokens, 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
+ /**
15
+ * Возвращать токены для конкретной темы или для всех сразу
16
+ */
17
+ theme: 'light' | 'dark';
18
+ /** Объект с образцами цветов warning, error, success */
19
+ system?: typeof DEFAULT_SWATCH.system;
20
+ /**
21
+ * Формат выгрузки токенов
22
+ * @default 'hex/rgba'
23
+ */
24
+ format?: ColorFormat;
25
+ /**
26
+ * Колбэк для формирования кастомного списка семантических токенов
27
+ * @param base Ссылки на базовые токены
28
+ * @param defaults Токены по умолчанию
29
+ * @param params Параметры переданные в getColors
30
+ */
31
+ overrides?: (base?: TokensBase, defaults?: DefaultTokensFull, params?: SemanticConfigOptions<T>) => Themed<T>;
32
+ }
33
+ /**
34
+ * Получение списка семантических токенов
35
+ *
36
+ * @param {SemanticConfigOptions<T>} params - Конфигурация генерации
37
+ * @returns {DefaultTokensFull | Themed<T>} Список токенов для light, dark или вместе
38
+ */
39
+ export declare function getColors<T>(params: SemanticConfigOptions<T>): DefaultTokens;
@@ -0,0 +1,24 @@
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 | Themed<T>} Список токенов для light, dark или вместе
9
+ */
10
+ export function getColors(params) {
11
+ var base = getColorsBase(params);
12
+ var defaults = getColorsDefaultTokens(base);
13
+ var result;
14
+ if (params.overrides) {
15
+ result = params.overrides(base, defaults, params);
16
+ }
17
+ else {
18
+ result = defaults;
19
+ }
20
+ if (params.format) {
21
+ result = convertColorFormat(result, params.format);
22
+ }
23
+ return result[params.theme];
24
+ }
@@ -0,0 +1,59 @@
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 { DefaultTokens, 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
+ /**
17
+ * Возвращать токены для конкретной темы или для всех сразу
18
+ */
19
+ theme: 'light' | 'dark';
20
+ /** Объект с образцами цветов warning, error, success */
21
+ system?: typeof DEFAULT_SWATCH.system;
22
+ /**
23
+ * Формат выгрузки токенов
24
+ * @default 'hex/rgba'
25
+ */
26
+ format?: ColorFormat;
27
+ /**
28
+ * Колбэк для формирования кастомного списка семантических токенов
29
+ * @param base Ссылки на базовые токены
30
+ * @param defaults Токены по умолчанию
31
+ * @param params Параметры переданные в getColors
32
+ */
33
+ overrides?: (base?: TokensBase, defaults?: DefaultTokensFull, params?: SemanticConfigOptions<T>) => Themed<T>;
34
+ }
35
+
36
+ /**
37
+ * Получение списка семантических токенов
38
+ *
39
+ * @param {SemanticConfigOptions<T>} params - Конфигурация генерации
40
+ * @returns {DefaultTokensFull | Themed<T>} Список токенов для light, dark или вместе
41
+ */
42
+ export function getColors<T>(params: SemanticConfigOptions<T>): DefaultTokens {
43
+ const base = getColorsBase(params);
44
+ const defaults = getColorsDefaultTokens(base);
45
+
46
+ let result: any;
47
+
48
+ if (params.overrides) {
49
+ result = params.overrides(base, defaults, params);
50
+ } else {
51
+ result = defaults;
52
+ }
53
+
54
+ if (params.format) {
55
+ result = convertColorFormat(result, params.format);
56
+ }
57
+
58
+ return result[params.theme];
59
+ }
@@ -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
+ }