@skbkontur/colors 1.1.2-b2742.0 → 1.1.2-bdb5e.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 +69 -101
- package/dist/cjs/get-default-tokens.d.ts +130 -92
- package/dist/cjs/get-default-tokens.js +257 -219
- package/dist/cjs/helpers/get-palette.js +59 -65
- package/dist/cjs/helpers/get-promo.js +21 -27
- package/dist/cjs/types/base-tokens.d.ts +5 -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 +67 -95
- package/dist/esm/get-default-tokens.d.ts +130 -92
- package/dist/esm/get-default-tokens.js +257 -219
- package/dist/esm/helpers/get-palette.js +59 -65
- package/dist/esm/helpers/get-promo.js +21 -27
- package/dist/esm/types/base-tokens.d.ts +5 -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-green_accent-brand.css +444 -0
- package/dist/tokens/base/css/brand-green_accent-gray.css +354 -0
- package/dist/tokens/base/css/brand-orange_accent-brand.css +444 -0
- package/dist/tokens/base/css/brand-orange_accent-gray.css +354 -0
- package/dist/tokens/base/css/brand-red_accent-brand.css +444 -0
- package/dist/tokens/base/css/brand-red_accent-gray.css +354 -0
- package/dist/tokens/base/js/brand-green_accent-brand.js +444 -0
- package/dist/tokens/base/js/brand-green_accent-gray.js +352 -0
- package/dist/tokens/base/js/brand-orange_accent-brand.js +444 -0
- package/dist/tokens/base/js/brand-orange_accent-gray.js +352 -0
- package/dist/tokens/base/js/brand-red_accent-brand.js +444 -0
- package/dist/tokens/base/js/brand-red_accent-gray.js +352 -0
- package/dist/tokens/base/js-tree/brand-green_accent-brand.tree.js +515 -0
- package/dist/tokens/base/js-tree/brand-green_accent-gray.tree.js +403 -0
- package/dist/tokens/base/js-tree/brand-orange_accent-brand.tree.js +515 -0
- package/dist/tokens/base/js-tree/brand-orange_accent-gray.tree.js +403 -0
- package/dist/tokens/base/js-tree/brand-red_accent-brand.tree.js +515 -0
- package/dist/tokens/base/js-tree/brand-red_accent-gray.tree.js +403 -0
- package/dist/tokens/base/json/brand-green_accent-brand.json +444 -0
- package/dist/tokens/base/json/brand-green_accent-gray.json +352 -0
- package/dist/tokens/base/json/brand-orange_accent-brand.json +444 -0
- package/dist/tokens/base/json/brand-orange_accent-gray.json +352 -0
- package/dist/tokens/base/json/brand-red_accent-brand.json +444 -0
- package/dist/tokens/base/json/brand-red_accent-gray.json +352 -0
- package/dist/tokens/base/json-tree/brand-green_accent-brand.tree.json +515 -0
- package/dist/tokens/base/json-tree/brand-green_accent-gray.tree.json +403 -0
- package/dist/tokens/base/json-tree/brand-orange_accent-brand.tree.json +515 -0
- package/dist/tokens/base/json-tree/brand-orange_accent-gray.tree.json +403 -0
- package/dist/tokens/base/json-tree/brand-red_accent-brand.tree.json +515 -0
- package/dist/tokens/base/json-tree/brand-red_accent-gray.tree.json +403 -0
- package/dist/tokens/base/less/brand-green_accent-brand.less +442 -0
- package/dist/tokens/base/less/brand-green_accent-gray.less +352 -0
- package/dist/tokens/base/less/brand-orange_accent-brand.less +442 -0
- package/dist/tokens/base/less/brand-orange_accent-gray.less +352 -0
- package/dist/tokens/base/less/brand-red_accent-brand.less +442 -0
- package/dist/tokens/base/less/brand-red_accent-gray.less +352 -0
- package/dist/tokens/base/scss/brand-green_accent-brand.scss +442 -0
- package/dist/tokens/base/scss/brand-green_accent-gray.scss +352 -0
- package/dist/tokens/base/scss/brand-orange_accent-brand.scss +442 -0
- package/dist/tokens/base/scss/brand-orange_accent-gray.scss +352 -0
- package/dist/tokens/base/scss/brand-red_accent-brand.scss +442 -0
- package/dist/tokens/base/scss/brand-red_accent-gray.scss +352 -0
- package/package.json +4 -4
|
@@ -160,81 +160,75 @@ 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) {
|
|
235
229
|
var whiteContrast = Number((0, apca_w3_1.calcAPCA)('#fff', hex));
|
|
236
230
|
var blackContrast = Number((0, apca_w3_1.calcAPCA)('#000', hex));
|
|
237
|
-
if (whiteContrast - 10
|
|
231
|
+
if (whiteContrast - 10 <= blackContrast) {
|
|
238
232
|
return DefaultSwatch.whiteAlpha;
|
|
239
233
|
}
|
|
240
234
|
return DefaultSwatch.blackAlpha;
|
|
@@ -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;
|
|
@@ -24,6 +24,7 @@ export interface BaseTokens {
|
|
|
24
24
|
whiteAlpha: ColorWithScale<AlphaScale>;
|
|
25
25
|
blackAlpha: ColorWithScale<AlphaScale>;
|
|
26
26
|
onBrand: ColorWithScale<AlphaScale>;
|
|
27
|
+
onAccent?: ColorWithScale<AlphaScale>;
|
|
27
28
|
customizable: {
|
|
28
29
|
red: ColorPalette;
|
|
29
30
|
orange: ColorPalette;
|
|
@@ -41,13 +42,13 @@ export interface ColorPalette {
|
|
|
41
42
|
normal: ColorWithScale<ChromaScale>;
|
|
42
43
|
dim: ColorWithScale<ChromaScale>;
|
|
43
44
|
}
|
|
44
|
-
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;
|
|
45
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;
|
|
46
|
-
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;
|
|
47
48
|
type ColorWithScale<T extends string | number> = {
|
|
48
49
|
[K in T]: string;
|
|
49
50
|
};
|
|
50
|
-
interface ThemedValue {
|
|
51
|
+
export interface ThemedValue {
|
|
51
52
|
light: string;
|
|
52
53
|
dark: string;
|
|
53
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
|
+
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,47 +1,36 @@
|
|
|
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
|
+
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 brandColor
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
break;
|
|
27
|
-
case 'gray':
|
|
28
|
-
default:
|
|
29
|
-
accentPalette = undefined;
|
|
10
|
+
var brandColor;
|
|
11
|
+
if (brand in DEFAULT_SWATCH) {
|
|
12
|
+
brandColor = DEFAULT_SWATCH.brand[brand];
|
|
13
|
+
}
|
|
14
|
+
else {
|
|
15
|
+
brandColor = brand;
|
|
30
16
|
}
|
|
31
|
-
var
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
}
|
|
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 = accent === 'brand' ? brandPalette : undefined;
|
|
38
26
|
var customizable = {};
|
|
39
27
|
for (var colorKey in DEFAULT_SWATCH.customizable) {
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
28
|
+
var key = colorKey;
|
|
29
|
+
if (key && brand && brand in DEFAULT_SWATCH) {
|
|
30
|
+
customizable[key] = getPalette({
|
|
31
|
+
color: DEFAULT_SWATCH.customizable[key],
|
|
32
|
+
});
|
|
33
|
+
}
|
|
45
34
|
}
|
|
46
35
|
return {
|
|
47
36
|
brand: {
|
|
@@ -54,75 +43,69 @@ export function getBaseTokens(_a) {
|
|
|
54
43
|
},
|
|
55
44
|
palette: brandPalette,
|
|
56
45
|
},
|
|
57
|
-
accent:
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
46
|
+
accent: accentColor
|
|
47
|
+
? {
|
|
48
|
+
original: {
|
|
49
|
+
light: accentColor,
|
|
50
|
+
dark: accentColor,
|
|
51
|
+
},
|
|
52
|
+
interactions: {
|
|
53
|
+
hover: getHover(accentColor),
|
|
54
|
+
pressed: getPressed(accentColor),
|
|
55
|
+
},
|
|
56
|
+
palette: accentPalette,
|
|
57
|
+
}
|
|
58
|
+
: undefined,
|
|
59
|
+
warning: getPalette({ color: system.warning }),
|
|
60
|
+
error: getPalette({ color: system.error }),
|
|
61
|
+
success: getPalette({ color: system.success }),
|
|
72
62
|
gray: DEFAULT_SWATCH.gray,
|
|
73
63
|
whiteAlpha: DEFAULT_SWATCH.whiteAlpha,
|
|
74
64
|
blackAlpha: DEFAULT_SWATCH.blackAlpha,
|
|
75
65
|
onBrand: calcOnBrand(brandColor),
|
|
66
|
+
onAccent: accentColor ? calcOnBrand(accentColor) : undefined,
|
|
76
67
|
customizable: customizable,
|
|
77
68
|
};
|
|
78
69
|
}
|
|
79
|
-
export var colorToHex = function (color) {
|
|
80
|
-
if (DEFAULT_SWATCH.brand[color]) {
|
|
81
|
-
return DEFAULT_SWATCH.brand[color];
|
|
82
|
-
}
|
|
83
|
-
return color;
|
|
84
|
-
};
|
|
85
|
-
export var camelCaseToKebabCase = function (str) {
|
|
86
|
-
return str.replace(/[A-Z]/g, function (match) { return "-".concat(match.toLowerCase()); });
|
|
87
|
-
};
|
|
88
|
-
export var kebabCaseToCamelCase = function (str) {
|
|
89
|
-
return str.replace(/-(\w)/g, function (_, c) { return c.toUpperCase(); });
|
|
90
|
-
};
|
|
91
70
|
export function convertOklchToHex(obj) {
|
|
92
71
|
if (typeof obj !== 'object' || obj === null) {
|
|
93
72
|
return obj;
|
|
94
73
|
}
|
|
95
74
|
if (Array.isArray(obj)) {
|
|
96
|
-
return obj.map(function (item) {
|
|
75
|
+
return obj.map(function (item) {
|
|
76
|
+
if (typeof item === 'object' && item !== null) {
|
|
77
|
+
return convertOklchToHex(item);
|
|
78
|
+
}
|
|
79
|
+
return item;
|
|
80
|
+
});
|
|
97
81
|
}
|
|
98
82
|
var newObj = {};
|
|
99
83
|
for (var key in obj) {
|
|
100
84
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
101
85
|
var value = obj[key];
|
|
102
86
|
if (typeof value === 'string' && value.startsWith('oklch(') && !value.includes('/')) {
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
87
|
+
var oklchColor = converter('oklch')(value);
|
|
88
|
+
var rgbColor = converter('rgb')(oklchColor);
|
|
89
|
+
value = formatHex(rgbColor);
|
|
90
|
+
}
|
|
91
|
+
if (typeof value === 'object' && value !== null) {
|
|
92
|
+
newObj[key] = convertOklchToHex(value);
|
|
93
|
+
}
|
|
94
|
+
else {
|
|
95
|
+
newObj[key] = value;
|
|
110
96
|
}
|
|
111
|
-
newObj[key] = convertOklchToHex(value);
|
|
112
97
|
}
|
|
113
98
|
}
|
|
114
99
|
return newObj;
|
|
115
100
|
}
|
|
116
101
|
export var convertOklchToRgba = function (oklchString) {
|
|
102
|
+
var _a;
|
|
117
103
|
var oklch = converter('oklch')(oklchString);
|
|
118
104
|
var rgb = converter('rgb')(oklch);
|
|
119
|
-
if (!rgb) {
|
|
120
|
-
throw new Error("Invalid color format: ".concat(oklchString));
|
|
121
|
-
}
|
|
122
105
|
var r = Math.round(rgb.r * 255);
|
|
123
106
|
var g = Math.round(rgb.g * 255);
|
|
124
107
|
var b = Math.round(rgb.b * 255);
|
|
125
|
-
var alpha = oklch.alpha;
|
|
108
|
+
var alpha = (_a = oklch.alpha) !== null && _a !== void 0 ? _a : 1;
|
|
126
109
|
return "rgba(".concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(alpha, ")");
|
|
127
110
|
};
|
|
128
111
|
export function convertAlphaOklchToRgba(obj) {
|
|
@@ -130,38 +113,27 @@ export function convertAlphaOklchToRgba(obj) {
|
|
|
130
113
|
return obj;
|
|
131
114
|
}
|
|
132
115
|
if (Array.isArray(obj)) {
|
|
133
|
-
return obj.map(function (item) {
|
|
116
|
+
return obj.map(function (item) {
|
|
117
|
+
if (typeof item === 'object' && item !== null) {
|
|
118
|
+
return convertAlphaOklchToRgba(item);
|
|
119
|
+
}
|
|
120
|
+
return item;
|
|
121
|
+
});
|
|
134
122
|
}
|
|
135
123
|
var newObj = {};
|
|
136
124
|
for (var key in obj) {
|
|
137
125
|
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
138
126
|
var value = obj[key];
|
|
139
127
|
if (typeof value === 'string' && value.includes('oklch(')) {
|
|
140
|
-
|
|
141
|
-
value = convertOklchToRgba(value);
|
|
142
|
-
}
|
|
143
|
-
catch (e) {
|
|
144
|
-
console.error("Failed to convert OKLCH with alpha to rgba: ".concat(value), e);
|
|
145
|
-
}
|
|
128
|
+
value = convertOklchToRgba(value);
|
|
146
129
|
}
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
}
|
|
150
|
-
return newObj;
|
|
151
|
-
}
|
|
152
|
-
export function flattenObject(obj, prefix) {
|
|
153
|
-
if (prefix === void 0) { prefix = ''; }
|
|
154
|
-
var result = {};
|
|
155
|
-
for (var key in obj) {
|
|
156
|
-
if (Object.prototype.hasOwnProperty.call(obj, key)) {
|
|
157
|
-
var newKey = prefix ? "".concat(prefix, "-").concat(camelCaseToKebabCase(key)) : key;
|
|
158
|
-
if (typeof obj[key] === 'object' && !Array.isArray(obj[key])) {
|
|
159
|
-
result = __assign(__assign({}, result), flattenObject(obj[key], newKey));
|
|
130
|
+
if (typeof value === 'object' && value !== null) {
|
|
131
|
+
newObj[key] = convertAlphaOklchToRgba(value);
|
|
160
132
|
}
|
|
161
133
|
else {
|
|
162
|
-
|
|
134
|
+
newObj[key] = value;
|
|
163
135
|
}
|
|
164
136
|
}
|
|
165
137
|
}
|
|
166
|
-
return
|
|
138
|
+
return newObj;
|
|
167
139
|
}
|