@skbkontur/colors 1.1.2-34230.0 → 1.1.2-6463e.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.
- package/dist/cjs/get-base-tokens.d.ts +9 -7
- package/dist/cjs/get-base-tokens.js +77 -102
- package/dist/cjs/get-default-tokens.d.ts +98 -78
- package/dist/cjs/get-default-tokens.js +197 -177
- package/dist/cjs/helpers/get-palette.js +58 -64
- package/dist/cjs/helpers/get-promo.js +21 -27
- package/dist/cjs/types/base-tokens.d.ts +4 -4
- package/dist/cjs/utils/format-variable.d.ts +2 -0
- package/dist/cjs/utils/format-variable.js +11 -0
- package/dist/esm/get-base-tokens.d.ts +9 -7
- package/dist/esm/get-base-tokens.js +75 -96
- package/dist/esm/get-default-tokens.d.ts +98 -78
- package/dist/esm/get-default-tokens.js +197 -177
- package/dist/esm/helpers/get-palette.js +58 -64
- package/dist/esm/helpers/get-promo.js +21 -27
- package/dist/esm/types/base-tokens.d.ts +4 -4
- package/dist/esm/utils/format-variable.d.ts +2 -0
- package/dist/esm/utils/format-variable.js +6 -0
- package/dist/tokens/base/css/brand-blue-deep_accent-gray.css +1 -7
- package/dist/tokens/base/css/brand-blue_accent-gray.css +1 -7
- package/dist/tokens/base/css/brand-green_accent-gray.css +1 -7
- package/dist/tokens/base/css/brand-mint_accent-gray.css +1 -7
- package/dist/tokens/base/css/brand-orange_accent-gray.css +1 -7
- package/dist/tokens/base/css/brand-purple_accent-gray.css +1 -7
- package/dist/tokens/base/css/brand-red_accent-gray.css +1 -7
- package/dist/tokens/base/css/brand-violet_accent-gray.css +1 -7
- package/dist/tokens/base/js/brand-blue-deep_accent-gray.js +0 -6
- package/dist/tokens/base/js/brand-blue_accent-gray.js +0 -6
- package/dist/tokens/base/js/brand-green_accent-gray.js +0 -6
- package/dist/tokens/base/js/brand-mint_accent-gray.js +0 -6
- package/dist/tokens/base/js/brand-orange_accent-gray.js +0 -6
- package/dist/tokens/base/js/brand-purple_accent-gray.js +0 -6
- package/dist/tokens/base/js/brand-red_accent-gray.js +0 -6
- package/dist/tokens/base/js/brand-violet_accent-gray.js +0 -6
- package/dist/tokens/base/js-tree/brand-blue-deep_accent-gray.tree.js +0 -16
- package/dist/tokens/base/js-tree/brand-blue_accent-gray.tree.js +0 -16
- package/dist/tokens/base/js-tree/brand-green_accent-gray.tree.js +0 -16
- package/dist/tokens/base/js-tree/brand-mint_accent-gray.tree.js +0 -16
- package/dist/tokens/base/js-tree/brand-orange_accent-gray.tree.js +0 -16
- package/dist/tokens/base/js-tree/brand-purple_accent-gray.tree.js +0 -16
- package/dist/tokens/base/js-tree/brand-red_accent-gray.tree.js +0 -16
- package/dist/tokens/base/js-tree/brand-violet_accent-gray.tree.js +0 -16
- package/dist/tokens/base/json/brand-blue-deep_accent-gray.json +0 -6
- package/dist/tokens/base/json/brand-blue_accent-gray.json +0 -6
- package/dist/tokens/base/json/brand-green_accent-gray.json +0 -6
- package/dist/tokens/base/json/brand-mint_accent-gray.json +0 -6
- package/dist/tokens/base/json/brand-orange_accent-gray.json +0 -6
- package/dist/tokens/base/json/brand-purple_accent-gray.json +0 -6
- package/dist/tokens/base/json/brand-red_accent-gray.json +0 -6
- package/dist/tokens/base/json/brand-violet_accent-gray.json +0 -6
- package/dist/tokens/base/json-tree/brand-blue-deep_accent-gray.tree.json +0 -16
- package/dist/tokens/base/json-tree/brand-blue_accent-gray.tree.json +0 -16
- package/dist/tokens/base/json-tree/brand-green_accent-gray.tree.json +0 -16
- package/dist/tokens/base/json-tree/brand-mint_accent-gray.tree.json +0 -16
- package/dist/tokens/base/json-tree/brand-orange_accent-gray.tree.json +0 -16
- package/dist/tokens/base/json-tree/brand-purple_accent-gray.tree.json +0 -16
- package/dist/tokens/base/json-tree/brand-red_accent-gray.tree.json +0 -16
- package/dist/tokens/base/json-tree/brand-violet_accent-gray.tree.json +0 -16
- package/dist/tokens/base/less/brand-blue-deep_accent-gray.less +1 -7
- package/dist/tokens/base/less/brand-blue_accent-gray.less +1 -7
- package/dist/tokens/base/less/brand-green_accent-gray.less +1 -7
- package/dist/tokens/base/less/brand-mint_accent-gray.less +1 -7
- package/dist/tokens/base/less/brand-orange_accent-gray.less +1 -7
- package/dist/tokens/base/less/brand-purple_accent-gray.less +1 -7
- package/dist/tokens/base/less/brand-red_accent-gray.less +1 -7
- package/dist/tokens/base/less/brand-violet_accent-gray.less +1 -7
- package/dist/tokens/base/scss/brand-blue-deep_accent-gray.scss +1 -7
- package/dist/tokens/base/scss/brand-blue_accent-gray.scss +1 -7
- package/dist/tokens/base/scss/brand-green_accent-gray.scss +1 -7
- package/dist/tokens/base/scss/brand-mint_accent-gray.scss +1 -7
- package/dist/tokens/base/scss/brand-orange_accent-gray.scss +1 -7
- package/dist/tokens/base/scss/brand-purple_accent-gray.scss +1 -7
- package/dist/tokens/base/scss/brand-red_accent-gray.scss +1 -7
- package/dist/tokens/base/scss/brand-violet_accent-gray.scss +1 -7
- package/dist/tokens/semantic/css/brand-blue-deep_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-blue-deep_accent-gray.css +126 -106
- package/dist/tokens/semantic/css/brand-blue_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-blue_accent-gray.css +126 -106
- package/dist/tokens/semantic/css/brand-green_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-green_accent-gray.css +126 -106
- package/dist/tokens/semantic/css/brand-mint_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-mint_accent-gray.css +126 -106
- package/dist/tokens/semantic/css/brand-orange_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-orange_accent-gray.css +126 -106
- package/dist/tokens/semantic/css/brand-purple_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-purple_accent-gray.css +126 -106
- package/dist/tokens/semantic/css/brand-red_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-red_accent-gray.css +126 -106
- package/dist/tokens/semantic/css/brand-violet_accent-brand.css +104 -84
- package/dist/tokens/semantic/css/brand-violet_accent-gray.css +126 -106
- package/dist/tokens/semantic/js/brand-blue-deep_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-blue-deep_accent-gray.js +120 -106
- package/dist/tokens/semantic/js/brand-blue_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-blue_accent-gray.js +120 -106
- package/dist/tokens/semantic/js/brand-green_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-green_accent-gray.js +120 -106
- package/dist/tokens/semantic/js/brand-mint_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-mint_accent-gray.js +120 -106
- package/dist/tokens/semantic/js/brand-orange_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-orange_accent-gray.js +120 -106
- package/dist/tokens/semantic/js/brand-purple_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-purple_accent-gray.js +120 -106
- package/dist/tokens/semantic/js/brand-red_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-red_accent-gray.js +120 -106
- package/dist/tokens/semantic/js/brand-violet_accent-brand.js +104 -84
- package/dist/tokens/semantic/js/brand-violet_accent-gray.js +120 -106
- package/dist/tokens/semantic/json/brand-blue-deep_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-blue-deep_accent-gray.json +58 -30
- package/dist/tokens/semantic/json/brand-blue_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-blue_accent-gray.json +58 -30
- package/dist/tokens/semantic/json/brand-green_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-green_accent-gray.json +58 -30
- package/dist/tokens/semantic/json/brand-mint_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-mint_accent-gray.json +58 -30
- package/dist/tokens/semantic/json/brand-orange_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-orange_accent-gray.json +58 -30
- package/dist/tokens/semantic/json/brand-purple_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-purple_accent-gray.json +58 -30
- package/dist/tokens/semantic/json/brand-red_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-red_accent-gray.json +58 -30
- package/dist/tokens/semantic/json/brand-violet_accent-brand.json +54 -22
- package/dist/tokens/semantic/json/brand-violet_accent-gray.json +58 -30
- package/dist/tokens/semantic/less/semantic.less +46 -36
- package/dist/tokens/semantic/scss/semantic.scss +46 -36
- package/package.json +1 -1
|
@@ -160,75 +160,69 @@ function findClosestLightnessStep(targetL, availableLightnessSteps) {
|
|
|
160
160
|
return closestStep;
|
|
161
161
|
}
|
|
162
162
|
function calculateBaseHueAndCorrectionRange(inputColorString, abneyData) {
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
var
|
|
188
|
-
|
|
189
|
-
var rawHue = Number(rawHueStr);
|
|
190
|
-
return {
|
|
191
|
-
rawHue: rawHue,
|
|
192
|
-
shift: shift,
|
|
193
|
-
correctedHue: (rawHue + shift + 360) % 360,
|
|
194
|
-
};
|
|
195
|
-
});
|
|
196
|
-
correctedHueMap_1.sort(function (a, b) {
|
|
197
|
-
if (a.correctedHue !== b.correctedHue) {
|
|
198
|
-
return a.correctedHue - b.correctedHue;
|
|
199
|
-
}
|
|
200
|
-
return a.rawHue - b.rawHue;
|
|
201
|
-
});
|
|
202
|
-
if (correctedHueMap_1.length === 0) {
|
|
203
|
-
console.warn("No hue ranges defined for lightness ".concat(closestLightness, "."));
|
|
204
|
-
return null;
|
|
205
|
-
}
|
|
206
|
-
var findCorrectRange = function () {
|
|
207
|
-
var nextRangeIndex = correctedHueMap_1.findIndex(function (range) { return range.correctedHue > targetHue_1; });
|
|
208
|
-
if (nextRangeIndex === 0) {
|
|
209
|
-
return correctedHueMap_1[correctedHueMap_1.length - 1];
|
|
210
|
-
}
|
|
211
|
-
if (nextRangeIndex > 0) {
|
|
212
|
-
return correctedHueMap_1[nextRangeIndex - 1];
|
|
213
|
-
}
|
|
214
|
-
return correctedHueMap_1[correctedHueMap_1.length - 1];
|
|
215
|
-
};
|
|
216
|
-
var selectedRange = findCorrectRange();
|
|
217
|
-
if (!selectedRange) {
|
|
218
|
-
console.error('Could not determine the correct hue range.');
|
|
219
|
-
return null;
|
|
220
|
-
}
|
|
221
|
-
var baseHue = (targetHue_1 - selectedRange.shift + 360) % 360;
|
|
163
|
+
var toOklch = (0, culori_1.converter)('oklch');
|
|
164
|
+
var oklch = toOklch(inputColorString);
|
|
165
|
+
if (!oklch) {
|
|
166
|
+
console.warn("Could not parse color string: ".concat(inputColorString));
|
|
167
|
+
return null;
|
|
168
|
+
}
|
|
169
|
+
var targetLightness = Math.round(oklch.l * 100);
|
|
170
|
+
var targetHue = oklch.h;
|
|
171
|
+
if (isNaN(targetHue)) {
|
|
172
|
+
console.warn("Achromatic color detected (".concat(inputColorString, "). Defaulting hue to 0."));
|
|
173
|
+
targetHue = 0;
|
|
174
|
+
}
|
|
175
|
+
var availableLightnessSteps = Object.keys(abneyData).map(Number);
|
|
176
|
+
if (availableLightnessSteps.length === 0) {
|
|
177
|
+
console.warn('Abney correction data is empty, cannot calculate base hue.');
|
|
178
|
+
return null;
|
|
179
|
+
}
|
|
180
|
+
var closestLightness = findClosestLightnessStep(targetLightness, availableLightnessSteps);
|
|
181
|
+
var lightnessCorrectionData = abneyData[closestLightness];
|
|
182
|
+
if (!lightnessCorrectionData) {
|
|
183
|
+
console.warn("No Abney correction data for lightness ".concat(closestLightness, "."));
|
|
184
|
+
return null;
|
|
185
|
+
}
|
|
186
|
+
var correctedHueMap = Object.entries(lightnessCorrectionData).map(function (_a) {
|
|
187
|
+
var rawHueStr = _a[0], shift = _a[1];
|
|
188
|
+
var rawHue = Number(rawHueStr);
|
|
222
189
|
return {
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
190
|
+
rawHue: rawHue,
|
|
191
|
+
shift: shift,
|
|
192
|
+
correctedHue: (rawHue + shift + 360) % 360,
|
|
226
193
|
};
|
|
194
|
+
});
|
|
195
|
+
correctedHueMap.sort(function (a, b) {
|
|
196
|
+
if (a.correctedHue !== b.correctedHue) {
|
|
197
|
+
return a.correctedHue - b.correctedHue;
|
|
198
|
+
}
|
|
199
|
+
return a.rawHue - b.rawHue;
|
|
200
|
+
});
|
|
201
|
+
if (correctedHueMap.length === 0) {
|
|
202
|
+
console.warn("No hue ranges defined for lightness ".concat(closestLightness, "."));
|
|
203
|
+
return null;
|
|
227
204
|
}
|
|
228
|
-
|
|
229
|
-
|
|
205
|
+
var findCorrectRange = function () {
|
|
206
|
+
var nextRangeIndex = correctedHueMap.findIndex(function (range) { return range.correctedHue > targetHue; });
|
|
207
|
+
if (nextRangeIndex === 0) {
|
|
208
|
+
return correctedHueMap[correctedHueMap.length - 1];
|
|
209
|
+
}
|
|
210
|
+
if (nextRangeIndex > 0) {
|
|
211
|
+
return correctedHueMap[nextRangeIndex - 1];
|
|
212
|
+
}
|
|
213
|
+
return correctedHueMap[correctedHueMap.length - 1];
|
|
214
|
+
};
|
|
215
|
+
var selectedRange = findCorrectRange();
|
|
216
|
+
if (!selectedRange) {
|
|
217
|
+
console.error('Could not determine the correct hue range.');
|
|
230
218
|
return null;
|
|
231
219
|
}
|
|
220
|
+
var baseHue = (targetHue - selectedRange.shift + 360) % 360;
|
|
221
|
+
return {
|
|
222
|
+
baseHue: baseHue,
|
|
223
|
+
correctionLightness: closestLightness,
|
|
224
|
+
correctionHueRange: selectedRange.rawHue,
|
|
225
|
+
};
|
|
232
226
|
}
|
|
233
227
|
exports.calculateBaseHueAndCorrectionRange = calculateBaseHueAndCorrectionRange;
|
|
234
228
|
function calcOnBrand(hex) {
|
|
@@ -5,35 +5,29 @@ var culori_1 = require("culori");
|
|
|
5
5
|
var promo_hue_shift_1 = require("../constants/promo-hue-shift");
|
|
6
6
|
function getPromo(color, hueShifts) {
|
|
7
7
|
if (hueShifts === void 0) { hueShifts = promo_hue_shift_1.PROMO_HUE_SHIFTS; }
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
throw new Error("Invalid color string: ".concat(color));
|
|
13
|
-
}
|
|
14
|
-
var currentHue = oklchColor.h;
|
|
15
|
-
var promoHueShift = getPromoHueShift(currentHue, hueShifts);
|
|
16
|
-
var correctedHue = (currentHue + promoHueShift + 360) % 360;
|
|
17
|
-
var promoLightness = oklchColor.l * 100;
|
|
18
|
-
if (promoLightness >= 50) {
|
|
19
|
-
promoLightness = promoLightness - 32;
|
|
20
|
-
}
|
|
21
|
-
promoLightness = Math.min(Math.max(promoLightness, 30), 34);
|
|
22
|
-
var promoChroma = 0.1;
|
|
23
|
-
var finalLightness = Math.round(promoLightness) / 100;
|
|
24
|
-
var finalChroma = Math.round(promoChroma * 100) / 100;
|
|
25
|
-
var promoOklch = {
|
|
26
|
-
mode: 'oklch',
|
|
27
|
-
l: finalLightness,
|
|
28
|
-
c: finalChroma,
|
|
29
|
-
h: correctedHue,
|
|
30
|
-
};
|
|
31
|
-
return (0, culori_1.formatHex)((0, culori_1.clampChroma)(promoOklch, 'oklch'));
|
|
8
|
+
var toOklch = (0, culori_1.converter)('oklch');
|
|
9
|
+
var oklchColor = toOklch(color);
|
|
10
|
+
if (!oklchColor) {
|
|
11
|
+
throw new Error("Invalid color string: ".concat(color));
|
|
32
12
|
}
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
13
|
+
var currentHue = oklchColor.h;
|
|
14
|
+
var promoHueShift = getPromoHueShift(currentHue, hueShifts);
|
|
15
|
+
var correctedHue = (currentHue + promoHueShift + 360) % 360;
|
|
16
|
+
var promoLightness = oklchColor.l * 100;
|
|
17
|
+
if (promoLightness >= 50) {
|
|
18
|
+
promoLightness = promoLightness - 32;
|
|
36
19
|
}
|
|
20
|
+
promoLightness = Math.min(Math.max(promoLightness, 30), 34);
|
|
21
|
+
var promoChroma = 0.1;
|
|
22
|
+
var finalLightness = Math.round(promoLightness) / 100;
|
|
23
|
+
var finalChroma = Math.round(promoChroma * 100) / 100;
|
|
24
|
+
var promoOklch = {
|
|
25
|
+
mode: 'oklch',
|
|
26
|
+
l: finalLightness,
|
|
27
|
+
c: finalChroma,
|
|
28
|
+
h: correctedHue,
|
|
29
|
+
};
|
|
30
|
+
return (0, culori_1.formatHex)((0, culori_1.clampChroma)(promoOklch, 'oklch'));
|
|
37
31
|
}
|
|
38
32
|
exports.getPromo = getPromo;
|
|
39
33
|
function getPromoHueShift(currentHue, promoHueShifts) {
|
|
@@ -9,7 +9,7 @@ export interface BaseTokens {
|
|
|
9
9
|
};
|
|
10
10
|
palette: ColorPalette;
|
|
11
11
|
};
|
|
12
|
-
accent
|
|
12
|
+
accent?: {
|
|
13
13
|
original: ThemedValue;
|
|
14
14
|
interactions: {
|
|
15
15
|
hover: ThemedValue;
|
|
@@ -42,13 +42,13 @@ export interface ColorPalette {
|
|
|
42
42
|
normal: ColorWithScale<ChromaScale>;
|
|
43
43
|
dim: ColorWithScale<ChromaScale>;
|
|
44
44
|
}
|
|
45
|
-
type ChromaScale = 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | 96;
|
|
45
|
+
export type ChromaScale = 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | 96;
|
|
46
46
|
type AlphaScale = 4 | 6 | 8 | 12 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | 96 | 100;
|
|
47
|
-
type GrayScale = 0 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | 96 | 98 | 100;
|
|
47
|
+
export type GrayScale = 0 | 16 | 20 | 24 | 28 | 32 | 36 | 40 | 44 | 48 | 52 | 56 | 60 | 64 | 68 | 72 | 76 | 80 | 84 | 88 | 92 | 96 | 98 | 100;
|
|
48
48
|
type ColorWithScale<T extends string | number> = {
|
|
49
49
|
[K in T]: string;
|
|
50
50
|
};
|
|
51
|
-
interface ThemedValue {
|
|
51
|
+
export interface ThemedValue {
|
|
52
52
|
light: string;
|
|
53
53
|
dark: string;
|
|
54
54
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.kebabCaseToCamelCase = exports.camelCaseToKebabCase = void 0;
|
|
4
|
+
var camelCaseToKebabCase = function (str) {
|
|
5
|
+
return str.replace(/[A-Z]/g, function (match) { return "-".concat(match.toLowerCase()); });
|
|
6
|
+
};
|
|
7
|
+
exports.camelCaseToKebabCase = camelCaseToKebabCase;
|
|
8
|
+
var kebabCaseToCamelCase = function (str) {
|
|
9
|
+
return str.replace(/-(\w)/g, function (_, c) { return c.toUpperCase(); });
|
|
10
|
+
};
|
|
11
|
+
exports.kebabCaseToCamelCase = kebabCaseToCamelCase;
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import * as DEFAULT_SWATCH from './constants/default-swatch';
|
|
2
2
|
import type { BaseTokens } from './types/base-tokens';
|
|
3
3
|
type PresetOrCustom<T extends string> = T | (string & Record<never, never>);
|
|
4
|
+
export declare const ACCENT_PARAMS: string[];
|
|
5
|
+
export interface ColorObject {
|
|
6
|
+
[key: string]: ColorValue;
|
|
7
|
+
}
|
|
8
|
+
export type ColorValue = string | ColorObject | ColorValue[];
|
|
9
|
+
type ColorStructure = ColorObject | ColorValue[];
|
|
4
10
|
export interface ConfigOptions {
|
|
5
11
|
brand: PresetOrCustom<keyof typeof DEFAULT_SWATCH.brand>;
|
|
6
|
-
accent: PresetOrCustom<
|
|
12
|
+
accent: PresetOrCustom<(typeof ACCENT_PARAMS)[number]>;
|
|
7
13
|
system?: typeof DEFAULT_SWATCH.system;
|
|
8
14
|
}
|
|
9
15
|
export declare function getBaseTokens({ brand, accent, system }: ConfigOptions): BaseTokens;
|
|
10
|
-
export declare
|
|
11
|
-
export declare const camelCaseToKebabCase: (str: string) => string;
|
|
12
|
-
export declare const kebabCaseToCamelCase: (str: string) => string;
|
|
13
|
-
export declare function convertOklchToHex(obj: any): any;
|
|
16
|
+
export declare function convertOklchToHex(obj: ColorStructure): ColorStructure;
|
|
14
17
|
export declare const convertOklchToRgba: (oklchString: string) => string;
|
|
15
|
-
export declare function convertAlphaOklchToRgba(obj:
|
|
16
|
-
export declare function flattenObject(obj: any, prefix?: string): any;
|
|
18
|
+
export declare function convertAlphaOklchToRgba(obj: ColorStructure): ColorStructure;
|
|
17
19
|
export {};
|
|
@@ -1,46 +1,44 @@
|
|
|
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
1
|
import { converter, formatHex } from 'culori';
|
|
13
2
|
import { calcOnBrand, getPalette } from './helpers/get-palette';
|
|
14
3
|
import { getPromo } from './helpers/get-promo';
|
|
15
4
|
import * as DEFAULT_SWATCH from './constants/default-swatch';
|
|
16
5
|
import { getLogo } from './helpers/get-logo';
|
|
17
6
|
import { getHover, getPressed } from './helpers/get-interactions';
|
|
7
|
+
export var ACCENT_PARAMS = ['brand', 'gray'];
|
|
18
8
|
export function getBaseTokens(_a) {
|
|
19
9
|
var brand = _a.brand, _b = _a.accent, accent = _b === void 0 ? 'gray' : _b, _c = _a.system, system = _c === void 0 ? DEFAULT_SWATCH.system : _c;
|
|
20
|
-
var
|
|
10
|
+
var isPresetColor = brand in DEFAULT_SWATCH.brand;
|
|
11
|
+
var brandColor;
|
|
12
|
+
if (isPresetColor) {
|
|
13
|
+
brandColor = DEFAULT_SWATCH.brand[brand];
|
|
14
|
+
}
|
|
15
|
+
else {
|
|
16
|
+
brandColor = brand;
|
|
17
|
+
}
|
|
18
|
+
var accentColor;
|
|
19
|
+
if (accent === 'brand') {
|
|
20
|
+
accentColor = brandColor;
|
|
21
|
+
}
|
|
22
|
+
else if (accent !== 'gray') {
|
|
23
|
+
accentColor = accent;
|
|
24
|
+
}
|
|
21
25
|
var brandPalette = getPalette({ color: brandColor });
|
|
22
26
|
var accentPalette;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
accentPalette = brandPalette;
|
|
26
|
-
break;
|
|
27
|
-
case 'gray':
|
|
28
|
-
default:
|
|
29
|
-
accentPalette = undefined;
|
|
27
|
+
if (accent === 'brand') {
|
|
28
|
+
accentPalette = brandPalette;
|
|
30
29
|
}
|
|
31
|
-
|
|
32
|
-
color:
|
|
33
|
-
}
|
|
34
|
-
var
|
|
35
|
-
var successPalette = getPalette({
|
|
36
|
-
color: system.success,
|
|
37
|
-
});
|
|
38
|
-
var customizable = {};
|
|
30
|
+
else if (accent !== 'gray' && accentColor) {
|
|
31
|
+
accentPalette = getPalette({ color: accentColor });
|
|
32
|
+
}
|
|
33
|
+
var customizablePalettes = {};
|
|
39
34
|
for (var colorKey in DEFAULT_SWATCH.customizable) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
35
|
+
var key = colorKey;
|
|
36
|
+
if (key === brand && isPresetColor) {
|
|
37
|
+
customizablePalettes[key] = brandPalette;
|
|
38
|
+
continue;
|
|
39
|
+
}
|
|
40
|
+
customizablePalettes[key] = getPalette({
|
|
41
|
+
color: DEFAULT_SWATCH.customizable[key],
|
|
44
42
|
});
|
|
45
43
|
}
|
|
46
44
|
return {
|
|
@@ -54,77 +52,69 @@ export function getBaseTokens(_a) {
|
|
|
54
52
|
},
|
|
55
53
|
palette: brandPalette,
|
|
56
54
|
},
|
|
57
|
-
accent:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
55
|
+
accent: accentColor
|
|
56
|
+
? {
|
|
57
|
+
original: {
|
|
58
|
+
light: accentColor,
|
|
59
|
+
dark: accentColor,
|
|
60
|
+
},
|
|
61
|
+
interactions: {
|
|
62
|
+
hover: getHover(accentColor),
|
|
63
|
+
pressed: getPressed(accentColor),
|
|
64
|
+
},
|
|
65
|
+
palette: accentPalette,
|
|
66
|
+
}
|
|
67
|
+
: undefined,
|
|
68
|
+
warning: getPalette({ color: system.warning }),
|
|
69
|
+
error: getPalette({ color: system.error }),
|
|
70
|
+
success: getPalette({ color: system.success }),
|
|
72
71
|
gray: DEFAULT_SWATCH.gray,
|
|
73
72
|
whiteAlpha: DEFAULT_SWATCH.whiteAlpha,
|
|
74
73
|
blackAlpha: DEFAULT_SWATCH.blackAlpha,
|
|
75
74
|
onBrand: calcOnBrand(brandColor),
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
customizable: customizable,
|
|
75
|
+
onAccent: accentColor ? calcOnBrand(accentColor) : undefined,
|
|
76
|
+
customizable: customizablePalettes,
|
|
79
77
|
};
|
|
80
78
|
}
|
|
81
|
-
export var colorToHex = function (color) {
|
|
82
|
-
if (DEFAULT_SWATCH.brand[color]) {
|
|
83
|
-
return DEFAULT_SWATCH.brand[color];
|
|
84
|
-
}
|
|
85
|
-
return color;
|
|
86
|
-
};
|
|
87
|
-
export var camelCaseToKebabCase = function (str) {
|
|
88
|
-
return str.replace(/[A-Z]/g, function (match) { return "-".concat(match.toLowerCase()); });
|
|
89
|
-
};
|
|
90
|
-
export var kebabCaseToCamelCase = function (str) {
|
|
91
|
-
return str.replace(/-(\w)/g, function (_, c) { return c.toUpperCase(); });
|
|
92
|
-
};
|
|
93
79
|
export function convertOklchToHex(obj) {
|
|
94
80
|
if (typeof obj !== 'object' || obj === null) {
|
|
95
81
|
return obj;
|
|
96
82
|
}
|
|
97
83
|
if (Array.isArray(obj)) {
|
|
98
|
-
return obj.map(function (item) {
|
|
84
|
+
return obj.map(function (item) {
|
|
85
|
+
if (typeof item === 'object' && item !== null) {
|
|
86
|
+
return convertOklchToHex(item);
|
|
87
|
+
}
|
|
88
|
+
return item;
|
|
89
|
+
});
|
|
99
90
|
}
|
|
100
91
|
var newObj = {};
|
|
101
92
|
for (var key in obj) {
|
|
102
93
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
103
94
|
var value = obj[key];
|
|
104
95
|
if (typeof value === 'string' && value.startsWith('oklch(') && !value.includes('/')) {
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
96
|
+
var oklchColor = converter('oklch')(value);
|
|
97
|
+
var rgbColor = converter('rgb')(oklchColor);
|
|
98
|
+
value = formatHex(rgbColor);
|
|
99
|
+
}
|
|
100
|
+
if (typeof value === 'object' && value !== null) {
|
|
101
|
+
newObj[key] = convertOklchToHex(value);
|
|
102
|
+
}
|
|
103
|
+
else {
|
|
104
|
+
newObj[key] = value;
|
|
112
105
|
}
|
|
113
|
-
newObj[key] = convertOklchToHex(value);
|
|
114
106
|
}
|
|
115
107
|
}
|
|
116
108
|
return newObj;
|
|
117
109
|
}
|
|
118
110
|
export var convertOklchToRgba = function (oklchString) {
|
|
111
|
+
var _a;
|
|
119
112
|
var oklch = converter('oklch')(oklchString);
|
|
120
113
|
var rgb = converter('rgb')(oklch);
|
|
121
|
-
if (!rgb) {
|
|
122
|
-
throw new Error("Invalid color format: ".concat(oklchString));
|
|
123
|
-
}
|
|
124
114
|
var r = Math.round(rgb.r * 255);
|
|
125
115
|
var g = Math.round(rgb.g * 255);
|
|
126
116
|
var b = Math.round(rgb.b * 255);
|
|
127
|
-
var alpha = oklch.alpha;
|
|
117
|
+
var alpha = (_a = oklch.alpha) !== null && _a !== void 0 ? _a : 1;
|
|
128
118
|
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alpha, ")");
|
|
129
119
|
};
|
|
130
120
|
export function convertAlphaOklchToRgba(obj) {
|
|
@@ -132,38 +122,27 @@ export function convertAlphaOklchToRgba(obj) {
|
|
|
132
122
|
return obj;
|
|
133
123
|
}
|
|
134
124
|
if (Array.isArray(obj)) {
|
|
135
|
-
return obj.map(function (item) {
|
|
125
|
+
return obj.map(function (item) {
|
|
126
|
+
if (typeof item === 'object' && item !== null) {
|
|
127
|
+
return convertAlphaOklchToRgba(item);
|
|
128
|
+
}
|
|
129
|
+
return item;
|
|
130
|
+
});
|
|
136
131
|
}
|
|
137
132
|
var newObj = {};
|
|
138
133
|
for (var key in obj) {
|
|
139
134
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
140
135
|
var value = obj[key];
|
|
141
136
|
if (typeof value === 'string' && value.includes('oklch(')) {
|
|
142
|
-
|
|
143
|
-
value = convertOklchToRgba(value);
|
|
144
|
-
}
|
|
145
|
-
catch (e) {
|
|
146
|
-
console.error("Failed to convert OKLCH with alpha to rgba: ".concat(value), e);
|
|
147
|
-
}
|
|
137
|
+
value = convertOklchToRgba(value);
|
|
148
138
|
}
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
}
|
|
152
|
-
return newObj;
|
|
153
|
-
}
|
|
154
|
-
export function flattenObject(obj, prefix) {
|
|
155
|
-
if (prefix === void 0) { prefix = ''; }
|
|
156
|
-
var result = {};
|
|
157
|
-
for (var key in obj) {
|
|
158
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
159
|
-
var newKey = prefix ? "".concat(prefix, "-").concat(camelCaseToKebabCase(key)) : key;
|
|
160
|
-
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
|
|
161
|
-
result = __assign(__assign({}, result), flattenObject(obj[key], newKey));
|
|
139
|
+
if (typeof value === 'object' && value !== null) {
|
|
140
|
+
newObj[key] = convertAlphaOklchToRgba(value);
|
|
162
141
|
}
|
|
163
142
|
else {
|
|
164
|
-
|
|
143
|
+
newObj[key] = value;
|
|
165
144
|
}
|
|
166
145
|
}
|
|
167
146
|
}
|
|
168
|
-
return
|
|
147
|
+
return newObj;
|
|
169
148
|
}
|