@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
@@ -1,7 +1,6 @@
1
- 'use strict';
2
- Object.defineProperty(exports, '__esModule', { value: true });
3
- exports.ABNEY_CORRECTION = void 0;
4
- exports.ABNEY_CORRECTION = {
1
+ import type { GeneratorColorAbneyCorrection } from '../../types/tokens-base-generator.js';
2
+
3
+ export const ABNEY_CORRECTION: GeneratorColorAbneyCorrection = {
5
4
  20: {
6
5
  0: 0,
7
6
  8: 0,
@@ -0,0 +1,2 @@
1
+ import type { GeneratorColorChromaParamsGroup } from '../../types/tokens-base-generator.js';
2
+ export declare const CHROMA_PARAMS: GeneratorColorChromaParamsGroup;
@@ -0,0 +1,102 @@
1
+ export var CHROMA_PARAMS = {
2
+ 20: {
3
+ vivid: { rel: 100, max: 12 },
4
+ normal: { rel: 66, min: 4.4, max: 8 },
5
+ dim: { rel: 46, min: 2, max: 4.4 },
6
+ },
7
+ 24: {
8
+ vivid: { rel: 100, max: 14.2 },
9
+ normal: { rel: 68, min: 5.7, max: 10 },
10
+ dim: { rel: 48, min: 2.8, max: 5.7 },
11
+ },
12
+ 28: {
13
+ vivid: { rel: 100, max: 15.8 },
14
+ normal: { rel: 70, min: 7, max: 11.8 },
15
+ dim: { rel: 50, min: 3.6, max: 7 },
16
+ },
17
+ 32: {
18
+ vivid: { rel: 100, max: 17.1 },
19
+ normal: { rel: 72, min: 8.2, max: 13.2 },
20
+ dim: { rel: 52, min: 4.4, max: 8.2 },
21
+ },
22
+ 36: {
23
+ vivid: { rel: 100, max: 18 },
24
+ normal: { rel: 74, min: 9.4, max: 14.4 },
25
+ dim: { rel: 54, min: 5.2, max: 9.4 },
26
+ },
27
+ 40: {
28
+ vivid: { rel: 100, max: 18.8 },
29
+ normal: { rel: 76, min: 10.6, max: 15.6 },
30
+ dim: { rel: 56, min: 6, max: 10.6 },
31
+ },
32
+ 44: {
33
+ vivid: { rel: 100, max: 19.6 },
34
+ normal: { rel: 78, min: 11.7, max: 16.6 },
35
+ dim: { rel: 58, min: 6.8, max: 11.7 },
36
+ },
37
+ 48: {
38
+ vivid: { rel: 100, max: 20.3 },
39
+ normal: { rel: 80, min: 12.8, max: 17.5 },
40
+ dim: { rel: 60, min: 7.6, max: 12.8 },
41
+ },
42
+ 52: {
43
+ vivid: { rel: 100, max: 21 },
44
+ normal: { rel: 82, min: 13.9, max: 18.4 },
45
+ dim: { rel: 62, min: 8.4, max: 13.9 },
46
+ },
47
+ 56: {
48
+ vivid: { rel: 100, max: 21.6 },
49
+ normal: { rel: 84, min: 15, max: 19.2 },
50
+ dim: { rel: 64, min: 9.2, max: 15 },
51
+ },
52
+ 60: {
53
+ vivid: { rel: 100, max: 22 },
54
+ normal: { rel: 86, min: 15.9, max: 19.9 },
55
+ dim: { rel: 66, min: 9.9, max: 15.9 },
56
+ },
57
+ 64: {
58
+ vivid: { rel: 100, max: 22.2 },
59
+ normal: { rel: 88, min: 16.2, max: 20.2 },
60
+ dim: { rel: 68, min: 10.2, max: 16.2 },
61
+ },
62
+ 68: {
63
+ vivid: { rel: 100, max: 21.9 },
64
+ normal: { rel: 90, min: 15.8, max: 19.8 },
65
+ dim: { rel: 70, min: 9.6, max: 15.8 },
66
+ },
67
+ 72: {
68
+ vivid: { rel: 100, max: 21.2 },
69
+ normal: { rel: 92, min: 14.8, max: 18.8 },
70
+ dim: { rel: 72, min: 8.4, max: 14.8 },
71
+ },
72
+ 76: {
73
+ vivid: { rel: 100, max: 20.3 },
74
+ normal: { rel: 90, min: 13.1, max: 17.5 },
75
+ dim: { rel: 70, min: 7, max: 13.1 },
76
+ },
77
+ 80: {
78
+ vivid: { rel: 100, max: 19 },
79
+ normal: { rel: 88, min: 11.2, max: 15.6 },
80
+ dim: { rel: 68, min: 5.6, max: 11.2 },
81
+ },
82
+ 84: {
83
+ vivid: { rel: 100, max: 17.1 },
84
+ normal: { rel: 86, min: 9, max: 13.4 },
85
+ dim: { rel: 66, min: 4.4, max: 9 },
86
+ },
87
+ 88: {
88
+ vivid: { rel: 100, max: 14.2 },
89
+ normal: { rel: 84, min: 6.7, max: 10.4 },
90
+ dim: { rel: 64, min: 3.2, max: 6.7 },
91
+ },
92
+ 92: {
93
+ vivid: { rel: 100, max: 11 },
94
+ normal: { rel: 82, min: 4.4, max: 7.4 },
95
+ dim: { rel: 62, min: 2.2, max: 4.4 },
96
+ },
97
+ 96: {
98
+ vivid: { rel: 100, max: 7 },
99
+ normal: { rel: 80, min: 2.6, max: 4.4 },
100
+ dim: { rel: 60, min: 1.5, max: 2.6 },
101
+ },
102
+ };
@@ -1,4 +1,6 @@
1
- export var CHROMA_SETTINGS = {
1
+ import type { GeneratorColorChromaParamsGroup } from '../../types/tokens-base-generator.js';
2
+
3
+ export const CHROMA_PARAMS: GeneratorColorChromaParamsGroup = {
2
4
  20: {
3
5
  vivid: { rel: 100, max: 12 },
4
6
  normal: { rel: 66, min: 4.4, max: 8 },
@@ -0,0 +1,9 @@
1
+ export const HOVER_LIGHT_L = -4;
2
+ export const HOVER_LIGHT_C = 0;
3
+ export const HOVER_DARK_L = +4;
4
+ export const HOVER_DARK_C = 0;
5
+
6
+ export const PRESSED_LIGHT_L = -8;
7
+ export const PRESSED_LIGHT_C = -0.03;
8
+ export const PRESSED_DARK_L = -4;
9
+ export const PRESSED_DARK_C = -0.03;
@@ -0,0 +1 @@
1
+ export declare const LOGO_LIGHTNESS_MIN = 64;
@@ -0,0 +1 @@
1
+ export var LOGO_LIGHTNESS_MIN = 64;
@@ -0,0 +1 @@
1
+ export const LOGO_LIGHTNESS_MIN = 64;
@@ -1,3 +1,3 @@
1
1
  export declare const PROMO_HUE_SHIFTS: {
2
- [hueRange: number]: number;
2
+ [hueRange: number]: number;
3
3
  };
@@ -0,0 +1,11 @@
1
+ export var PROMO_HUE_SHIFTS = {
2
+ 0: -24,
3
+ 25: -32,
4
+ 44: -35,
5
+ 148: 40,
6
+ 177: 51,
7
+ 253: 11,
8
+ 264: 14,
9
+ 294: 0,
10
+ 319: -24,
11
+ };
@@ -1,4 +1,4 @@
1
- export var PROMO_HUE_SHIFTS = {
1
+ export const PROMO_HUE_SHIFTS: { [hueRange: number]: number } = {
2
2
  0: -24,
3
3
  25: -32,
4
4
  44: -35,
@@ -1,3 +1,3 @@
1
1
  export declare const WARNING_HUE_PATCH: {
2
- [lightness: number]: number;
2
+ [lightness: number]: number;
3
3
  };
@@ -0,0 +1,22 @@
1
+ export var WARNING_HUE_PATCH = {
2
+ 96: 0,
3
+ 92: 0,
4
+ 88: 0,
5
+ 84: 0,
6
+ 80: 0,
7
+ 76: 0,
8
+ 72: -4,
9
+ 68: -8,
10
+ 64: -12,
11
+ 60: -8,
12
+ 56: -4,
13
+ 52: -2,
14
+ 48: 0,
15
+ 44: 0,
16
+ 40: 0,
17
+ 36: 0,
18
+ 32: 0,
19
+ 28: 0,
20
+ 24: 0,
21
+ 20: 0,
22
+ };
@@ -1,4 +1,4 @@
1
- export var WARNING_HUE_PATCH = {
1
+ export const WARNING_HUE_PATCH: { [lightness: number]: number } = {
2
2
  96: 0,
3
3
  92: 0,
4
4
  88: 0,
@@ -0,0 +1,11 @@
1
+ import { type ColorFormat } from './utils/convert-color.js';
2
+ import * as DEFAULT_SWATCH from './consts/default-swatch.js';
3
+ import type { TokensBase } from './types/tokens-base.js';
4
+ export type PresetOrCustom<T extends string> = T | (string & Record<never, never>);
5
+ export interface ConfigOptions {
6
+ brand: PresetOrCustom<keyof typeof DEFAULT_SWATCH.brand>;
7
+ accent: PresetOrCustom<'brand' | 'gray'>;
8
+ system?: typeof DEFAULT_SWATCH.system;
9
+ format?: ColorFormat;
10
+ }
11
+ export declare function getColorsBase({ brand, accent, system, format, }: ConfigOptions): TokensBase;
@@ -0,0 +1,78 @@
1
+ import { calcOnBrand, getPalette } from './helpers/get-palette.js';
2
+ import { getHover, getPressed } from './helpers/get-interactions.js';
3
+ import { getLogo } from './helpers/get-logo.js';
4
+ import { getPromo } from './helpers/get-promo.js';
5
+ import { convertColorFormat } from './utils/convert-color.js';
6
+ import * as DEFAULT_SWATCH from './consts/default-swatch.js';
7
+ export function getColorsBase(_a) {
8
+ var brand = _a.brand, accent = _a.accent, _b = _a.system, system = _b === void 0 ? DEFAULT_SWATCH.system : _b, _c = _a.format, format = _c === void 0 ? 'hex/rgba' : _c;
9
+ var isPresetColor = brand in DEFAULT_SWATCH.brand;
10
+ var brandColor;
11
+ if (isPresetColor) {
12
+ brandColor = DEFAULT_SWATCH.brand[brand];
13
+ }
14
+ else {
15
+ brandColor = brand;
16
+ }
17
+ var accentColor;
18
+ if (accent === 'brand') {
19
+ accentColor = brandColor;
20
+ }
21
+ else if (accent !== 'gray') {
22
+ accentColor = accent;
23
+ }
24
+ var brandPalette = getPalette({ color: brandColor });
25
+ var accentPalette;
26
+ if (accent === 'brand') {
27
+ accentPalette = brandPalette;
28
+ }
29
+ else if (accent !== 'gray' && accentColor) {
30
+ accentPalette = getPalette({ color: accentColor });
31
+ }
32
+ var customizablePalettes = {};
33
+ for (var colorKey in DEFAULT_SWATCH.customizable) {
34
+ var key = colorKey;
35
+ if (key === brand && isPresetColor) {
36
+ customizablePalettes[key] = brandPalette;
37
+ continue;
38
+ }
39
+ customizablePalettes[key] = getPalette({
40
+ color: DEFAULT_SWATCH.customizable[key],
41
+ });
42
+ }
43
+ var result = {
44
+ brand: {
45
+ logo: getLogo(brandColor),
46
+ promo: getPromo(brandColor),
47
+ original: brandColor,
48
+ interactions: {
49
+ hover: getHover(brandColor),
50
+ pressed: getPressed(brandColor),
51
+ },
52
+ palette: brandPalette,
53
+ },
54
+ accent: accentColor
55
+ ? {
56
+ original: {
57
+ light: accentColor,
58
+ dark: accentColor,
59
+ },
60
+ interactions: {
61
+ hover: getHover(accentColor),
62
+ pressed: getPressed(accentColor),
63
+ },
64
+ palette: accentPalette,
65
+ }
66
+ : undefined,
67
+ warning: getPalette({ color: system.warning }),
68
+ error: getPalette({ color: system.error }),
69
+ success: getPalette({ color: system.success }),
70
+ gray: DEFAULT_SWATCH.gray,
71
+ whiteAlpha: DEFAULT_SWATCH.whiteAlpha,
72
+ blackAlpha: DEFAULT_SWATCH.blackAlpha,
73
+ onBrand: calcOnBrand(brandColor),
74
+ onAccent: accentColor ? calcOnBrand(accentColor) : undefined,
75
+ customizable: customizablePalettes,
76
+ };
77
+ return convertColorFormat(result, format);
78
+ }
@@ -0,0 +1,99 @@
1
+ import { calcOnBrand, getPalette } from './helpers/get-palette.js';
2
+ import { getHover, getPressed } from './helpers/get-interactions.js';
3
+ import { getLogo } from './helpers/get-logo.js';
4
+ import { getPromo } from './helpers/get-promo.js';
5
+ import { type ColorFormat, convertColorFormat } from './utils/convert-color.js';
6
+ import { type ColorStructure } from './types/tokens.js';
7
+ import * as DEFAULT_SWATCH from './consts/default-swatch.js';
8
+ import type { TokensBase, ColorPalette } from './types/tokens-base.js';
9
+
10
+ export type PresetOrCustom<T extends string> = T | (string & Record<never, never>);
11
+
12
+ export interface ConfigOptions {
13
+ brand: PresetOrCustom<keyof typeof DEFAULT_SWATCH.brand>;
14
+ accent: PresetOrCustom<'brand' | 'gray'>;
15
+ system?: typeof DEFAULT_SWATCH.system;
16
+ format?: ColorFormat;
17
+ }
18
+
19
+ export function getColorsBase({
20
+ brand,
21
+ accent,
22
+ system = DEFAULT_SWATCH.system,
23
+ format = 'hex/rgba',
24
+ }: ConfigOptions): TokensBase {
25
+ const isPresetColor = brand in DEFAULT_SWATCH.brand;
26
+ let brandColor;
27
+ if (isPresetColor) {
28
+ brandColor = DEFAULT_SWATCH.brand[brand as keyof typeof DEFAULT_SWATCH.brand];
29
+ } else {
30
+ brandColor = brand;
31
+ }
32
+
33
+ let accentColor;
34
+ if (accent === 'brand') {
35
+ accentColor = brandColor;
36
+ } else if (accent !== 'gray') {
37
+ accentColor = accent;
38
+ }
39
+
40
+ const brandPalette = getPalette({ color: brandColor }) as ColorPalette;
41
+ let accentPalette;
42
+ if (accent === 'brand') {
43
+ accentPalette = brandPalette;
44
+ } else if (accent !== 'gray' && accentColor) {
45
+ accentPalette = getPalette({ color: accentColor }) as ColorPalette;
46
+ }
47
+
48
+ const customizablePalettes: TokensBase['customizable'] = {} as TokensBase['customizable'];
49
+
50
+ for (const colorKey in DEFAULT_SWATCH.customizable) {
51
+ const key = colorKey as keyof TokensBase['customizable'];
52
+
53
+ if (key === brand && isPresetColor) {
54
+ customizablePalettes[key] = brandPalette;
55
+ continue;
56
+ }
57
+
58
+ customizablePalettes[key] = getPalette({
59
+ color: DEFAULT_SWATCH.customizable[key],
60
+ }) as ColorPalette;
61
+ }
62
+
63
+ const result = {
64
+ brand: {
65
+ logo: getLogo(brandColor),
66
+ promo: getPromo(brandColor),
67
+ original: brandColor,
68
+ interactions: {
69
+ hover: getHover(brandColor),
70
+ pressed: getPressed(brandColor),
71
+ },
72
+ palette: brandPalette,
73
+ },
74
+ accent: accentColor
75
+ ? {
76
+ original: {
77
+ light: accentColor,
78
+ dark: accentColor,
79
+ },
80
+ interactions: {
81
+ hover: getHover(accentColor),
82
+ pressed: getPressed(accentColor),
83
+ },
84
+ palette: accentPalette,
85
+ }
86
+ : undefined,
87
+ warning: getPalette({ color: system.warning }) as ColorPalette,
88
+ error: getPalette({ color: system.error }) as ColorPalette,
89
+ success: getPalette({ color: system.success }) as ColorPalette,
90
+ gray: DEFAULT_SWATCH.gray,
91
+ whiteAlpha: DEFAULT_SWATCH.whiteAlpha,
92
+ blackAlpha: DEFAULT_SWATCH.blackAlpha,
93
+ onBrand: calcOnBrand(brandColor),
94
+ onAccent: accentColor ? calcOnBrand(accentColor) : undefined,
95
+ customizable: customizablePalettes,
96
+ } as unknown as ColorStructure;
97
+
98
+ return convertColorFormat(result, format) as unknown as TokensBase;
99
+ }