@skbkontur/colors 1.1.2-dc095.0 → 2.0.0-alpha.0

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 (124) hide show
  1. package/README.md +1 -1
  2. package/dist/cjs/constants/abney-correction.d.ts +2 -0
  3. package/dist/cjs/constants/abney-correction.js +1105 -0
  4. package/dist/cjs/constants/chroma-settings.d.ts +2 -0
  5. package/dist/cjs/constants/chroma-settings.js +105 -0
  6. package/dist/cjs/constants/default-swatch.d.ts +109 -0
  7. package/dist/cjs/constants/default-swatch.js +112 -0
  8. package/dist/cjs/constants/interaction-settings.d.ts +8 -0
  9. package/dist/cjs/constants/interaction-settings.js +19 -0
  10. package/dist/cjs/constants/logo-lightness.d.ts +1 -0
  11. package/dist/cjs/constants/logo-lightness.js +4 -0
  12. package/dist/cjs/constants/promo-hue-shift.d.ts +3 -0
  13. package/dist/cjs/constants/promo-hue-shift.js +14 -0
  14. package/dist/cjs/constants/warning-hue-patch.d.ts +3 -0
  15. package/dist/cjs/constants/warning-hue-patch.js +25 -0
  16. package/dist/cjs/get-base-tokens.d.ts +19 -0
  17. package/dist/cjs/get-base-tokens.js +199 -0
  18. package/dist/cjs/get-colors.d.ts +19 -0
  19. package/dist/cjs/get-colors.js +16 -0
  20. package/dist/cjs/get-default-tokens.d.ts +645 -0
  21. package/dist/cjs/get-default-tokens.js +997 -0
  22. package/dist/cjs/helpers/get-interactions.d.ts +7 -0
  23. package/dist/cjs/helpers/get-interactions.js +61 -0
  24. package/dist/cjs/helpers/get-logo.d.ts +6 -0
  25. package/dist/cjs/helpers/get-logo.js +32 -0
  26. package/dist/cjs/helpers/get-palette.d.ts +76 -0
  27. package/dist/cjs/helpers/get-palette.js +287 -0
  28. package/dist/cjs/helpers/get-promo.d.ts +12 -0
  29. package/dist/cjs/helpers/get-promo.js +56 -0
  30. package/dist/cjs/types/base-tokens.d.ts +125 -0
  31. package/dist/cjs/types/base-tokens.js +2 -0
  32. package/dist/cjs/types/generator-tokens.d.ts +43 -0
  33. package/dist/cjs/types/generator-tokens.js +2 -0
  34. package/dist/cjs/utils/format-variable.d.ts +2 -0
  35. package/dist/cjs/utils/format-variable.js +15 -0
  36. package/dist/colors.default-dark.js +325 -0
  37. package/dist/colors.default-light.js +326 -0
  38. package/dist/colors.js +319 -0
  39. package/dist/colors.less +319 -0
  40. package/dist/colors.scss +319 -0
  41. package/dist/esm/constants/abney-correction.d.ts +2 -0
  42. package/dist/esm/constants/abney-correction.js +1102 -0
  43. package/dist/esm/constants/chroma-settings.d.ts +2 -0
  44. package/dist/esm/constants/chroma-settings.js +102 -0
  45. package/dist/esm/constants/default-swatch.d.ts +109 -0
  46. package/dist/esm/constants/default-swatch.js +109 -0
  47. package/dist/esm/constants/interaction-settings.d.ts +8 -0
  48. package/dist/esm/constants/interaction-settings.js +8 -0
  49. package/dist/esm/constants/logo-lightness.d.ts +1 -0
  50. package/dist/esm/constants/logo-lightness.js +1 -0
  51. package/dist/esm/constants/promo-hue-shift.d.ts +3 -0
  52. package/dist/esm/constants/promo-hue-shift.js +11 -0
  53. package/dist/esm/constants/warning-hue-patch.d.ts +3 -0
  54. package/dist/esm/constants/warning-hue-patch.js +22 -0
  55. package/dist/esm/get-base-tokens.d.ts +19 -0
  56. package/dist/esm/get-base-tokens.js +147 -0
  57. package/dist/esm/get-colors.d.ts +19 -0
  58. package/dist/esm/get-colors.js +12 -0
  59. package/dist/esm/get-default-tokens.d.ts +645 -0
  60. package/dist/esm/get-default-tokens.js +993 -0
  61. package/dist/esm/helpers/get-interactions.d.ts +7 -0
  62. package/dist/esm/helpers/get-interactions.js +49 -0
  63. package/dist/esm/helpers/get-logo.d.ts +6 -0
  64. package/dist/esm/helpers/get-logo.js +28 -0
  65. package/dist/esm/helpers/get-palette.d.ts +76 -0
  66. package/dist/esm/helpers/get-palette.js +232 -0
  67. package/dist/esm/helpers/get-promo.d.ts +12 -0
  68. package/dist/esm/helpers/get-promo.js +51 -0
  69. package/dist/esm/types/base-tokens.d.ts +125 -0
  70. package/dist/esm/types/base-tokens.js +1 -0
  71. package/dist/esm/types/generator-tokens.d.ts +43 -0
  72. package/dist/esm/types/generator-tokens.js +1 -0
  73. package/dist/esm/utils/format-variable.d.ts +2 -0
  74. package/dist/esm/utils/format-variable.js +10 -0
  75. package/dist/tokens/brand-blue-deep_accent-brand.css +643 -0
  76. package/dist/tokens/brand-blue-deep_accent-gray.css +643 -0
  77. package/dist/tokens/brand-blue_accent-brand.css +643 -0
  78. package/dist/tokens/brand-blue_accent-gray.css +643 -0
  79. package/dist/tokens/brand-green_accent-brand.css +643 -0
  80. package/dist/tokens/brand-green_accent-gray.css +643 -0
  81. package/dist/tokens/brand-mint_accent-brand.css +643 -0
  82. package/dist/tokens/brand-mint_accent-gray.css +643 -0
  83. package/dist/tokens/brand-orange_accent-gray.css +643 -0
  84. package/dist/tokens/brand-purple_accent-brand.css +643 -0
  85. package/dist/tokens/brand-purple_accent-gray.css +643 -0
  86. package/dist/tokens/brand-red_accent-gray.css +643 -0
  87. package/dist/tokens/brand-violet_accent-brand.css +643 -0
  88. package/dist/tokens/brand-violet_accent-gray.css +643 -0
  89. package/dist/tokens-js/brand-blue-deep_accent-brand.js +644 -0
  90. package/dist/tokens-js/brand-blue-deep_accent-gray.js +644 -0
  91. package/dist/tokens-js/brand-blue_accent-brand.js +644 -0
  92. package/dist/tokens-js/brand-blue_accent-gray.js +644 -0
  93. package/dist/tokens-js/brand-green_accent-brand.js +644 -0
  94. package/dist/tokens-js/brand-green_accent-gray.js +644 -0
  95. package/dist/tokens-js/brand-mint_accent-brand.js +644 -0
  96. package/dist/tokens-js/brand-mint_accent-gray.js +644 -0
  97. package/dist/tokens-js/brand-orange_accent-gray.js +644 -0
  98. package/dist/tokens-js/brand-purple_accent-brand.js +644 -0
  99. package/dist/tokens-js/brand-purple_accent-gray.js +644 -0
  100. package/dist/tokens-js/brand-red_accent-gray.js +644 -0
  101. package/dist/tokens-js/brand-violet_accent-brand.js +644 -0
  102. package/dist/tokens-js/brand-violet_accent-gray.js +644 -0
  103. package/dist/tokens-mobile/brand-blue-deep_accent-brand.json +718 -0
  104. package/dist/tokens-mobile/brand-blue-deep_accent-gray.json +718 -0
  105. package/dist/tokens-mobile/brand-blue_accent-brand.json +718 -0
  106. package/dist/tokens-mobile/brand-blue_accent-gray.json +718 -0
  107. package/dist/tokens-mobile/brand-green_accent-brand.json +718 -0
  108. package/dist/tokens-mobile/brand-green_accent-gray.json +718 -0
  109. package/dist/tokens-mobile/brand-mint_accent-brand.json +718 -0
  110. package/dist/tokens-mobile/brand-mint_accent-gray.json +718 -0
  111. package/dist/tokens-mobile/brand-orange_accent-gray.json +718 -0
  112. package/dist/tokens-mobile/brand-purple_accent-brand.json +718 -0
  113. package/dist/tokens-mobile/brand-purple_accent-gray.json +718 -0
  114. package/dist/tokens-mobile/brand-red_accent-gray.json +718 -0
  115. package/dist/tokens-mobile/brand-violet_accent-brand.json +718 -0
  116. package/dist/tokens-mobile/brand-violet_accent-gray.json +718 -0
  117. package/package.json +13 -7
  118. package/colors.css +0 -160
  119. package/colors.less +0 -158
  120. package/colors.scss +0 -158
  121. package/dist/cjs/colors.d.ts +0 -161
  122. package/dist/cjs/colors.js +0 -163
  123. package/dist/esm/colors.d.ts +0 -161
  124. package/dist/esm/colors.js +0 -163
@@ -0,0 +1,7 @@
1
+ interface InteractionColors {
2
+ light: string;
3
+ dark: string;
4
+ }
5
+ export declare function getHover(hex: string): InteractionColors;
6
+ export declare function getPressed(hex: string): InteractionColors;
7
+ export {};
@@ -0,0 +1,49 @@
1
+ import { converter } from 'culori';
2
+ import {
3
+ HOVER_LIGHT_L,
4
+ HOVER_LIGHT_C,
5
+ HOVER_DARK_L,
6
+ HOVER_DARK_C,
7
+ PRESSED_LIGHT_L,
8
+ PRESSED_LIGHT_C,
9
+ PRESSED_DARK_L,
10
+ PRESSED_DARK_C,
11
+ } from '../constants/interaction-settings';
12
+ function applyOklchDelta(oklchColor, dL, dC) {
13
+ var _a = oklchColor.l,
14
+ l = _a === void 0 ? 0 : _a,
15
+ _b = oklchColor.c,
16
+ c = _b === void 0 ? 0 : _b,
17
+ _c = oklchColor.h,
18
+ h = _c === void 0 ? 0 : _c;
19
+ var safeH = h === undefined || isNaN(h) ? 0 : h;
20
+ var newL = Math.max(0, Math.min(1, l + dL / 100));
21
+ var newC = Math.max(0, c + dC);
22
+ return 'oklch('.concat(newL.toFixed(3), ' ').concat(newC.toFixed(3), ' ').concat(safeH.toFixed(0), ')');
23
+ }
24
+ export function getHover(hex) {
25
+ var toOklch = converter('oklch');
26
+ var oklchColor = toOklch(hex);
27
+ if (!oklchColor) {
28
+ return { light: hex, dark: hex };
29
+ }
30
+ var lightHoverColor = applyOklchDelta(oklchColor, HOVER_LIGHT_L, HOVER_LIGHT_C);
31
+ var darkHoverColor = applyOklchDelta(oklchColor, HOVER_DARK_L, HOVER_DARK_C);
32
+ return {
33
+ light: lightHoverColor,
34
+ dark: darkHoverColor,
35
+ };
36
+ }
37
+ export function getPressed(hex) {
38
+ var toOklch = converter('oklch');
39
+ var oklchColor = toOklch(hex);
40
+ if (!oklchColor) {
41
+ return { light: hex, dark: hex };
42
+ }
43
+ var lightPressedColor = applyOklchDelta(oklchColor, PRESSED_LIGHT_L, PRESSED_LIGHT_C);
44
+ var darkPressedColor = applyOklchDelta(oklchColor, PRESSED_DARK_L, PRESSED_DARK_C);
45
+ return {
46
+ light: lightPressedColor,
47
+ dark: darkPressedColor,
48
+ };
49
+ }
@@ -0,0 +1,6 @@
1
+ interface LogoColors {
2
+ light: string;
3
+ dark: string;
4
+ }
5
+ export declare function getLogo(hex: string): LogoColors;
6
+ export {};
@@ -0,0 +1,28 @@
1
+ import { converter } from 'culori';
2
+ import { MIN_LOGO_LIGHTNESS } from '../constants/logo-lightness';
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(MIN_LOGO_LIGHTNESS, '% 0 0)');
9
+ return { light: hex, dark: fallbackColor };
10
+ }
11
+ var _a = oklchColor.l,
12
+ l = _a === void 0 ? 0 : _a,
13
+ _b = oklchColor.c,
14
+ c = _b === void 0 ? 0 : _b;
15
+ var h = oklchColor.h;
16
+ var safeH = h === undefined || isNaN(h) ? 0 : h;
17
+ l = l || 0;
18
+ c = c || 0;
19
+ var percentL = l * 100;
20
+ if (percentL < MIN_LOGO_LIGHTNESS) {
21
+ l = MIN_LOGO_LIGHTNESS / 100;
22
+ }
23
+ var darkThemeLogoColor = 'oklch('.concat(l.toFixed(3), ' ').concat(c.toFixed(3), ' ').concat(safeH.toFixed(0), ')');
24
+ return {
25
+ light: lightThemeLogoColor,
26
+ dark: darkThemeLogoColor,
27
+ };
28
+ }
@@ -0,0 +1,76 @@
1
+ import type {
2
+ GeneratorColorAbneyCorrection,
3
+ GeneratorColorChromaSettingsGroup,
4
+ GeneratorColorPalette,
5
+ GeneratorColorWarningHuePatch,
6
+ } from '../types/generator-tokens';
7
+ interface GeneratePaletteParams {
8
+ color: string;
9
+ type?: 'default' | 'warning';
10
+ settings?: {
11
+ chromaSettings?: GeneratorColorChromaSettingsGroup;
12
+ abneyCorrection?: GeneratorColorAbneyCorrection;
13
+ promoHueShifts?: {
14
+ [hueRange: number]: number;
15
+ };
16
+ warningHuePatch?: GeneratorColorWarningHuePatch;
17
+ };
18
+ }
19
+ export declare function getPalette({
20
+ color,
21
+ type,
22
+ settings: customSettings,
23
+ }: GeneratePaletteParams): GeneratorColorPalette;
24
+ export declare function getAbneyHueShift(
25
+ lightness: number,
26
+ currentHue: number,
27
+ abneyData: GeneratorColorAbneyCorrection
28
+ ): number;
29
+ export declare function applyAbneyShift(
30
+ lightness: number,
31
+ currentHue: number,
32
+ abneyData: GeneratorColorAbneyCorrection
33
+ ): number;
34
+ export declare function applyWarningHuePatch(
35
+ currentHue: number,
36
+ lightness: number,
37
+ warningHuePatchData: GeneratorColorWarningHuePatch,
38
+ isWarningMode: boolean
39
+ ): number;
40
+ export declare function calculateBaseHueAndCorrectionRange(
41
+ inputColorString: string,
42
+ abneyData: GeneratorColorAbneyCorrection
43
+ ): {
44
+ baseHue: number;
45
+ correctionLightness: number;
46
+ correctionHueRange: number;
47
+ } | null;
48
+ export declare function calcOnBrand(hex: string): {
49
+ 4: string;
50
+ 6: string;
51
+ 8: string;
52
+ 12: string;
53
+ 16: string;
54
+ 20: string;
55
+ 24: string;
56
+ 28: string;
57
+ 32: string;
58
+ 36: string;
59
+ 40: string;
60
+ 44: string;
61
+ 48: string;
62
+ 52: string;
63
+ 56: string;
64
+ 60: string;
65
+ 64: string;
66
+ 68: string;
67
+ 72: string;
68
+ 76: string;
69
+ 80: string;
70
+ 84: string;
71
+ 88: string;
72
+ 92: string;
73
+ 96: string;
74
+ 100: string;
75
+ };
76
+ export {};
@@ -0,0 +1,232 @@
1
+ var __assign =
2
+ (this && this.__assign) ||
3
+ function () {
4
+ __assign =
5
+ Object.assign ||
6
+ function (t) {
7
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
8
+ s = arguments[i];
9
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
10
+ }
11
+ return t;
12
+ };
13
+ return __assign.apply(this, arguments);
14
+ };
15
+ var __spreadArray =
16
+ (this && this.__spreadArray) ||
17
+ function (to, from, pack) {
18
+ if (pack || arguments.length === 2)
19
+ for (var i = 0, l = from.length, ar; i < l; i++) {
20
+ if (ar || !(i in from)) {
21
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
22
+ ar[i] = from[i];
23
+ }
24
+ }
25
+ return to.concat(ar || Array.prototype.slice.call(from));
26
+ };
27
+ import { clampChroma, converter } from 'culori';
28
+ import { calcAPCA } from 'apca-w3';
29
+ import * as DefaultSwatch from '../constants/default-swatch';
30
+ import { CHROMA_SETTINGS } from '../constants/chroma-settings';
31
+ import { ABNEY_CORRECTION } from '../constants/abney-correction';
32
+ import { PROMO_HUE_SHIFTS } from '../constants/promo-hue-shift';
33
+ import { WARNING_HUE_PATCH } from '../constants/warning-hue-patch';
34
+ export function getPalette(_a) {
35
+ var color = _a.color,
36
+ _b = _a.type,
37
+ type = _b === void 0 ? 'default' : _b,
38
+ customSettings = _a.settings;
39
+ var defaultSettings = {
40
+ chromaSettings: CHROMA_SETTINGS,
41
+ abneyCorrection: ABNEY_CORRECTION,
42
+ promoHueShifts: PROMO_HUE_SHIFTS,
43
+ warningHuePatch: WARNING_HUE_PATCH,
44
+ };
45
+ var settings = __assign(__assign({}, defaultSettings), customSettings);
46
+ var toOklch = converter('oklch');
47
+ var oklchColor = toOklch(color);
48
+ var currentHue = (oklchColor === null || oklchColor === void 0 ? void 0 : oklchColor.h) || 0;
49
+ var toNorm = function (x) {
50
+ return x / 100;
51
+ };
52
+ var calculateChromaValue = function (rel, min, max, baseChromaMax) {
53
+ var raw = (baseChromaMax * rel) / 100;
54
+ var value = raw;
55
+ if (min !== undefined) {
56
+ value = Math.max(toNorm(min), value);
57
+ }
58
+ if (max !== undefined) {
59
+ value = Math.min(toNorm(max), value);
60
+ }
61
+ return Math.min(value, baseChromaMax);
62
+ };
63
+ var result = {
64
+ vivid: {},
65
+ normal: {},
66
+ dim: {},
67
+ };
68
+ var isWarning = type === 'warning';
69
+ for (var Lstr in settings.chromaSettings) {
70
+ var L = +Lstr;
71
+ if (L === 100) {
72
+ result.vivid[L] = 'oklch(100% 0 0)';
73
+ result.normal[L] = 'oklch(100% 0 0)';
74
+ result.dim[L] = 'oklch(100% 0 0)';
75
+ continue;
76
+ }
77
+ var hueAfterWarningPatch = applyWarningHuePatch(currentHue, L, settings.warningHuePatch, isWarning);
78
+ var appliedHueShift = applyAbneyShift(L, hueAfterWarningPatch, settings.abneyCorrection);
79
+ var chromaMax = clampChroma({ mode: 'oklch', l: L / 100, c: 1, h: appliedHueShift }, 'oklch').c;
80
+ var currentParams = settings.chromaSettings[L];
81
+ var vividN = calculateChromaValue(
82
+ currentParams.vivid.rel,
83
+ currentParams.vivid.min,
84
+ currentParams.vivid.max,
85
+ chromaMax
86
+ );
87
+ var normN = calculateChromaValue(
88
+ currentParams.normal.rel,
89
+ currentParams.normal.min,
90
+ currentParams.normal.max,
91
+ chromaMax
92
+ );
93
+ var dimN = calculateChromaValue(currentParams.dim.rel, currentParams.dim.min, currentParams.dim.max, chromaMax);
94
+ result.vivid[L] = 'oklch('.concat(L, '% ').concat(vividN.toFixed(3), ' ').concat(appliedHueShift.toFixed(0), ')');
95
+ result.normal[L] = 'oklch('.concat(L, '% ').concat(normN.toFixed(3), ' ').concat(appliedHueShift.toFixed(0), ')');
96
+ result.dim[L] = 'oklch('.concat(L, '% ').concat(dimN.toFixed(3), ' ').concat(appliedHueShift.toFixed(0), ')');
97
+ }
98
+ return result;
99
+ }
100
+ export function getAbneyHueShift(lightness, currentHue, abneyData) {
101
+ var lightnessData = abneyData[lightness];
102
+ if (!lightnessData) {
103
+ return 0;
104
+ }
105
+ var hueRanges = Object.keys(lightnessData)
106
+ .map(Number)
107
+ .sort(function (a, b) {
108
+ return a - b;
109
+ });
110
+ var selectedHueRange = hueRanges[0];
111
+ for (var i = 0; i < hueRanges.length; i++) {
112
+ var startRange = hueRanges[i];
113
+ var endRange = hueRanges[i + 1] !== undefined ? hueRanges[i + 1] : 360;
114
+ if (currentHue >= startRange && currentHue < endRange) {
115
+ selectedHueRange = startRange;
116
+ break;
117
+ }
118
+ if (i === hueRanges.length - 1 && currentHue >= startRange && currentHue < 360) {
119
+ selectedHueRange = startRange;
120
+ break;
121
+ }
122
+ }
123
+ return lightnessData[selectedHueRange] !== undefined ? lightnessData[selectedHueRange] : 0;
124
+ }
125
+ export function applyAbneyShift(lightness, currentHue, abneyData) {
126
+ var abneyShift = getAbneyHueShift(lightness, currentHue, abneyData);
127
+ return (currentHue + abneyShift + 360) % 360;
128
+ }
129
+ export function applyWarningHuePatch(currentHue, lightness, warningHuePatchData, isWarningMode) {
130
+ if (isWarningMode) {
131
+ var patch = warningHuePatchData[lightness];
132
+ if (patch !== undefined) {
133
+ return (currentHue + patch + 360) % 360;
134
+ }
135
+ }
136
+ return currentHue;
137
+ }
138
+ function findClosestLightnessStep(targetL, availableLightnessSteps) {
139
+ if (availableLightnessSteps.length === 0) {
140
+ return targetL;
141
+ }
142
+ var sortedSteps = __spreadArray([], availableLightnessSteps, true).sort(function (a, b) {
143
+ return a - b;
144
+ });
145
+ var closestStep = sortedSteps[0];
146
+ var minDiff = Math.abs(targetL - closestStep);
147
+ for (var i = 1; i < sortedSteps.length; i++) {
148
+ var currentStep = sortedSteps[i];
149
+ var diff = Math.abs(targetL - currentStep);
150
+ if (diff < minDiff || (diff === minDiff && currentStep > closestStep)) {
151
+ minDiff = diff;
152
+ closestStep = currentStep;
153
+ }
154
+ }
155
+ return closestStep;
156
+ }
157
+ export function calculateBaseHueAndCorrectionRange(inputColorString, abneyData) {
158
+ var toOklch = converter('oklch');
159
+ var oklch = toOklch(inputColorString);
160
+ if (!oklch) {
161
+ console.warn('Could not parse color string: '.concat(inputColorString));
162
+ return null;
163
+ }
164
+ var targetLightness = Math.round(oklch.l * 100);
165
+ var targetHue = oklch.h;
166
+ if (isNaN(targetHue)) {
167
+ console.warn('Achromatic color detected ('.concat(inputColorString, '). Defaulting hue to 0.'));
168
+ targetHue = 0;
169
+ }
170
+ var availableLightnessSteps = Object.keys(abneyData).map(Number);
171
+ if (availableLightnessSteps.length === 0) {
172
+ console.warn('Abney correction data is empty, cannot calculate base hue.');
173
+ return null;
174
+ }
175
+ var closestLightness = findClosestLightnessStep(targetLightness, availableLightnessSteps);
176
+ var lightnessCorrectionData = abneyData[closestLightness];
177
+ if (!lightnessCorrectionData) {
178
+ console.warn('No Abney correction data for lightness '.concat(closestLightness, '.'));
179
+ return null;
180
+ }
181
+ var correctedHueMap = Object.entries(lightnessCorrectionData).map(function (_a) {
182
+ var rawHueStr = _a[0],
183
+ shift = _a[1];
184
+ var rawHue = Number(rawHueStr);
185
+ return {
186
+ rawHue: rawHue,
187
+ shift: shift,
188
+ correctedHue: (rawHue + shift + 360) % 360,
189
+ };
190
+ });
191
+ correctedHueMap.sort(function (a, b) {
192
+ if (a.correctedHue !== b.correctedHue) {
193
+ return a.correctedHue - b.correctedHue;
194
+ }
195
+ return a.rawHue - b.rawHue;
196
+ });
197
+ if (correctedHueMap.length === 0) {
198
+ console.warn('No hue ranges defined for lightness '.concat(closestLightness, '.'));
199
+ return null;
200
+ }
201
+ var findCorrectRange = function () {
202
+ var nextRangeIndex = correctedHueMap.findIndex(function (range) {
203
+ return range.correctedHue > targetHue;
204
+ });
205
+ if (nextRangeIndex === 0) {
206
+ return correctedHueMap[correctedHueMap.length - 1];
207
+ }
208
+ if (nextRangeIndex > 0) {
209
+ return correctedHueMap[nextRangeIndex - 1];
210
+ }
211
+ return correctedHueMap[correctedHueMap.length - 1];
212
+ };
213
+ var selectedRange = findCorrectRange();
214
+ if (!selectedRange) {
215
+ console.error('Could not determine the correct hue range.');
216
+ return null;
217
+ }
218
+ var baseHue = (targetHue - selectedRange.shift + 360) % 360;
219
+ return {
220
+ baseHue: baseHue,
221
+ correctionLightness: closestLightness,
222
+ correctionHueRange: selectedRange.rawHue,
223
+ };
224
+ }
225
+ export function calcOnBrand(hex) {
226
+ var whiteContrast = Number(calcAPCA('#fff', hex));
227
+ var blackContrast = Number(calcAPCA('#000', hex));
228
+ if (whiteContrast - 10 <= blackContrast) {
229
+ return DefaultSwatch.whiteAlpha;
230
+ }
231
+ return DefaultSwatch.blackAlpha;
232
+ }
@@ -0,0 +1,12 @@
1
+ export declare function getPromo(
2
+ color: string,
3
+ hueShifts?: {
4
+ [hueRange: number]: number;
5
+ }
6
+ ): string;
7
+ export declare function getPromoHueShift(
8
+ currentHue: number,
9
+ promoHueShifts: {
10
+ [hueRange: number]: number;
11
+ }
12
+ ): number;
@@ -0,0 +1,51 @@
1
+ import { clampChroma, converter, formatHex } from 'culori';
2
+ import { PROMO_HUE_SHIFTS } from '../constants/promo-hue-shift';
3
+ export function getPromo(color, hueShifts) {
4
+ if (hueShifts === void 0) {
5
+ hueShifts = PROMO_HUE_SHIFTS;
6
+ }
7
+ var toOklch = converter('oklch');
8
+ var oklchColor = toOklch(color);
9
+ if (!oklchColor) {
10
+ throw new Error('Invalid color string: '.concat(color));
11
+ }
12
+ var currentHue = oklchColor.h;
13
+ var promoHueShift = getPromoHueShift(currentHue, hueShifts);
14
+ var correctedHue = (currentHue + promoHueShift + 360) % 360;
15
+ var promoLightness = oklchColor.l * 100;
16
+ if (promoLightness >= 50) {
17
+ promoLightness = promoLightness - 32;
18
+ }
19
+ promoLightness = Math.min(Math.max(promoLightness, 30), 34);
20
+ var promoChroma = 0.1;
21
+ var finalLightness = Math.round(promoLightness) / 100;
22
+ var finalChroma = Math.round(promoChroma * 100) / 100;
23
+ var promoOklch = {
24
+ mode: 'oklch',
25
+ l: finalLightness,
26
+ c: finalChroma,
27
+ h: correctedHue,
28
+ };
29
+ return formatHex(clampChroma(promoOklch, 'oklch'));
30
+ }
31
+ export function getPromoHueShift(currentHue, promoHueShifts) {
32
+ var hueRanges = Object.keys(promoHueShifts)
33
+ .map(Number)
34
+ .sort(function (a, b) {
35
+ return a - b;
36
+ });
37
+ var selectedHueRange = hueRanges[0];
38
+ for (var i = 0; i < hueRanges.length; i++) {
39
+ var startRange = hueRanges[i];
40
+ var endRange = hueRanges[i + 1] !== undefined ? hueRanges[i + 1] : 360;
41
+ if (currentHue >= startRange && currentHue < endRange) {
42
+ selectedHueRange = startRange;
43
+ break;
44
+ }
45
+ if (i === hueRanges.length - 1 && (currentHue >= startRange || currentHue < hueRanges[0])) {
46
+ selectedHueRange = startRange;
47
+ break;
48
+ }
49
+ }
50
+ return promoHueShifts[selectedHueRange] !== undefined ? promoHueShifts[selectedHueRange] : 0;
51
+ }
@@ -0,0 +1,125 @@
1
+ export interface BaseTokens {
2
+ brand: {
3
+ logo: ThemedValue;
4
+ original: string;
5
+ promo: string;
6
+ interactions: {
7
+ hover: ThemedValue;
8
+ pressed: ThemedValue;
9
+ };
10
+ palette: ColorPalette;
11
+ };
12
+ accent?: {
13
+ original: ThemedValue;
14
+ interactions: {
15
+ hover: ThemedValue;
16
+ pressed: ThemedValue;
17
+ };
18
+ palette?: ColorPalette;
19
+ };
20
+ warning: ColorPalette;
21
+ error: ColorPalette;
22
+ success: ColorPalette;
23
+ gray: ColorWithScale<GrayScale>;
24
+ whiteAlpha: ColorWithScale<AlphaScale>;
25
+ blackAlpha: ColorWithScale<AlphaScale>;
26
+ onBrand: ColorWithScale<AlphaScale>;
27
+ onAccent?: ColorWithScale<AlphaScale>;
28
+ customizable: {
29
+ red: ColorPalette;
30
+ orange: ColorPalette;
31
+ green: ColorPalette;
32
+ mint: ColorPalette;
33
+ blue: ColorPalette;
34
+ blueDeep: ColorPalette;
35
+ violet: ColorPalette;
36
+ purple: ColorPalette;
37
+ yellow: ColorPalette;
38
+ };
39
+ }
40
+ export interface ColorPalette {
41
+ vivid: ColorWithScale<ChromaScale>;
42
+ normal: ColorWithScale<ChromaScale>;
43
+ dim: ColorWithScale<ChromaScale>;
44
+ }
45
+ export type ChromaScale =
46
+ | 20
47
+ | 24
48
+ | 28
49
+ | 32
50
+ | 36
51
+ | 40
52
+ | 44
53
+ | 48
54
+ | 52
55
+ | 56
56
+ | 60
57
+ | 64
58
+ | 68
59
+ | 72
60
+ | 76
61
+ | 80
62
+ | 84
63
+ | 88
64
+ | 92
65
+ | 96;
66
+ type AlphaScale =
67
+ | 4
68
+ | 6
69
+ | 8
70
+ | 12
71
+ | 16
72
+ | 20
73
+ | 24
74
+ | 28
75
+ | 32
76
+ | 36
77
+ | 40
78
+ | 44
79
+ | 48
80
+ | 52
81
+ | 56
82
+ | 60
83
+ | 64
84
+ | 68
85
+ | 72
86
+ | 76
87
+ | 80
88
+ | 84
89
+ | 88
90
+ | 92
91
+ | 96
92
+ | 100;
93
+ export type GrayScale =
94
+ | 0
95
+ | 16
96
+ | 20
97
+ | 24
98
+ | 28
99
+ | 32
100
+ | 36
101
+ | 40
102
+ | 44
103
+ | 48
104
+ | 52
105
+ | 56
106
+ | 60
107
+ | 64
108
+ | 68
109
+ | 72
110
+ | 76
111
+ | 80
112
+ | 84
113
+ | 88
114
+ | 92
115
+ | 96
116
+ | 98
117
+ | 100;
118
+ type ColorWithScale<T extends string | number> = {
119
+ [K in T]: string;
120
+ };
121
+ export interface ThemedValue {
122
+ light: string;
123
+ dark: string;
124
+ }
125
+ export {};
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,43 @@
1
+ export interface GeneratorColorChromaSettingsGroup {
2
+ [key: number]: {
3
+ vivid: GeneratorColorChromaSettings;
4
+ normal: GeneratorColorChromaSettings;
5
+ dim: GeneratorColorChromaSettings;
6
+ };
7
+ }
8
+ export interface GeneratorColorChromaSettings {
9
+ rel: number;
10
+ min?: number;
11
+ max?: number;
12
+ }
13
+ export interface GeneratorColorPalette {
14
+ vivid: {
15
+ [key: number]: string;
16
+ };
17
+ normal: {
18
+ [key: number]: string;
19
+ };
20
+ dim: {
21
+ [key: number]: string;
22
+ };
23
+ }
24
+ export interface GeneratorColorAbneyCorrection {
25
+ [lightness: number]: {
26
+ [hueShiftRange: number]: number;
27
+ };
28
+ }
29
+ export interface GeneratorColorWarningHuePatch {
30
+ [lightness: number]: number;
31
+ }
32
+ export interface GeneratorPaletteParams {
33
+ color: string;
34
+ type?: 'default' | 'warning' | 'promo';
35
+ settings?: {
36
+ chromaSettings?: GeneratorColorChromaSettingsGroup;
37
+ abneyCorrection?: GeneratorColorAbneyCorrection;
38
+ promoHueShifts?: {
39
+ [hueRange: number]: number;
40
+ };
41
+ warningHuePatch?: GeneratorColorWarningHuePatch;
42
+ };
43
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,2 @@
1
+ export declare const camelCaseToKebabCase: (str: string) => string;
2
+ export declare const kebabCaseToCamelCase: (str: string) => string;
@@ -0,0 +1,10 @@
1
+ export var camelCaseToKebabCase = function (str) {
2
+ return str.replace(/[A-Z]/g, function (match) {
3
+ return '-'.concat(match.toLowerCase());
4
+ });
5
+ };
6
+ export var kebabCaseToCamelCase = function (str) {
7
+ return str.replace(/-(\w)/g, function (_, c) {
8
+ return c.toUpperCase();
9
+ });
10
+ };