@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.
- package/README.md +104 -171
- package/colors.less +319 -0
- package/colors.scss +319 -0
- package/lib/consts/default-swatch.d.ts +108 -0
- package/lib/consts/default-swatch.js +108 -0
- package/{dist/esm/constants/default-swatch.js → lib/consts/default-swatch.ts} +11 -7
- package/lib/consts/params/abney-correction.d.ts +2 -0
- package/lib/consts/params/abney-correction.js +1102 -0
- package/{dist/cjs/constants/abney-correction.js → lib/consts/params/abney-correction.ts} +3 -4
- package/lib/consts/params/chroma-params.d.ts +2 -0
- package/lib/consts/params/chroma-params.js +102 -0
- package/{dist/esm/constants/chroma-settings.js → lib/consts/params/chroma-params.ts} +3 -1
- package/lib/consts/params/interactions.ts +9 -0
- package/lib/consts/params/logo-lightness.d.ts +1 -0
- package/lib/consts/params/logo-lightness.js +1 -0
- package/lib/consts/params/logo-lightness.ts +1 -0
- package/{dist/cjs/constants → lib/consts/params}/promo-hue-shift.d.ts +1 -1
- package/lib/consts/params/promo-hue-shift.js +11 -0
- package/{dist/esm/constants/promo-hue-shift.js → lib/consts/params/promo-hue-shift.ts} +1 -1
- package/{dist/cjs/constants → lib/consts/params}/warning-hue-patch.d.ts +1 -1
- package/lib/consts/params/warning-hue-patch.js +22 -0
- package/{dist/esm/constants/warning-hue-patch.js → lib/consts/params/warning-hue-patch.ts} +1 -1
- package/lib/get-colors-base.d.ts +11 -0
- package/lib/get-colors-base.js +78 -0
- package/lib/get-colors-base.ts +99 -0
- package/lib/get-colors-default-tokens.d.ts +645 -0
- package/lib/get-colors-default-tokens.js +647 -0
- package/lib/get-colors-default-tokens.ts +646 -0
- package/lib/get-colors.d.ts +40 -0
- package/lib/get-colors.js +28 -0
- package/lib/get-colors.ts +65 -0
- package/{dist/cjs → lib}/helpers/get-interactions.d.ts +2 -2
- package/lib/helpers/get-interactions.js +35 -0
- package/lib/helpers/get-interactions.ts +64 -0
- package/{dist/cjs → lib}/helpers/get-logo.d.ts +2 -2
- package/lib/helpers/get-logo.js +25 -0
- package/lib/helpers/get-logo.ts +40 -0
- package/lib/helpers/get-palette.d.ts +51 -0
- package/lib/helpers/get-palette.js +204 -0
- package/lib/helpers/get-palette.ts +261 -0
- package/lib/helpers/get-promo.d.ts +6 -0
- package/lib/helpers/get-promo.js +47 -0
- package/lib/helpers/get-promo.ts +55 -0
- package/lib/types/tokens-base-generator.d.ts +43 -0
- package/{dist/cjs/types/generator-tokens.d.ts → lib/types/tokens-base-generator.ts} +12 -17
- package/lib/types/tokens-base.d.ts +55 -0
- package/{dist/esm/types/base-tokens.d.ts → lib/types/tokens-base.ts} +7 -2
- package/lib/types/tokens.d.ts +12 -0
- package/lib/types/tokens.js +1 -0
- package/lib/types/tokens.ts +18 -0
- package/lib/utils/convert-color.d.ts +3 -0
- package/lib/utils/convert-color.js +144 -0
- package/lib/utils/convert-color.ts +163 -0
- package/lib/utils/format-variable.js +6 -0
- package/lib/utils/format-variable.ts +7 -0
- package/package.json +44 -19
- package/{dist/tokens → tokens}/brand-blue-deep_accent-brand.css +33 -33
- package/{dist/tokens → tokens}/brand-blue-deep_accent-gray.css +33 -33
- package/{dist/tokens → tokens}/brand-blue_accent-brand.css +33 -33
- package/{dist/tokens → tokens}/brand-blue_accent-gray.css +33 -33
- package/{dist/tokens → tokens}/brand-green_accent-brand.css +33 -33
- package/{dist/tokens → tokens}/brand-green_accent-gray.css +33 -33
- package/{dist/tokens → tokens}/brand-mint_accent-brand.css +33 -33
- package/{dist/tokens → tokens}/brand-mint_accent-gray.css +33 -33
- package/{dist/tokens → tokens}/brand-orange_accent-gray.css +33 -33
- package/{dist/tokens → tokens}/brand-purple_accent-brand.css +33 -33
- package/{dist/tokens → tokens}/brand-purple_accent-gray.css +33 -33
- package/{dist/tokens → tokens}/brand-red_accent-gray.css +33 -33
- package/{dist/tokens → tokens}/brand-violet_accent-brand.css +33 -33
- package/{dist/tokens → tokens}/brand-violet_accent-gray.css +33 -33
- package/tokens-mobile/brand-blue-deep_accent-brand.json +718 -0
- package/tokens-mobile/brand-blue-deep_accent-gray.json +718 -0
- package/tokens-mobile/brand-blue_accent-brand.json +718 -0
- package/tokens-mobile/brand-blue_accent-gray.json +718 -0
- package/tokens-mobile/brand-green_accent-brand.json +718 -0
- package/tokens-mobile/brand-green_accent-gray.json +718 -0
- package/tokens-mobile/brand-mint_accent-brand.json +718 -0
- package/tokens-mobile/brand-mint_accent-gray.json +718 -0
- package/tokens-mobile/brand-orange_accent-gray.json +718 -0
- package/tokens-mobile/brand-purple_accent-brand.json +718 -0
- package/tokens-mobile/brand-purple_accent-gray.json +718 -0
- package/tokens-mobile/brand-red_accent-gray.json +718 -0
- package/tokens-mobile/brand-violet_accent-brand.json +718 -0
- package/tokens-mobile/brand-violet_accent-gray.json +718 -0
- package/dist/cjs/constants/abney-correction.d.ts +0 -2
- package/dist/cjs/constants/chroma-settings.d.ts +0 -2
- package/dist/cjs/constants/chroma-settings.js +0 -105
- package/dist/cjs/constants/default-swatch.d.ts +0 -109
- package/dist/cjs/constants/default-swatch.js +0 -112
- package/dist/cjs/constants/interaction-settings.js +0 -19
- package/dist/cjs/constants/logo-lightness.d.ts +0 -1
- package/dist/cjs/constants/logo-lightness.js +0 -4
- package/dist/cjs/constants/promo-hue-shift.js +0 -14
- package/dist/cjs/constants/warning-hue-patch.js +0 -25
- package/dist/cjs/get-base-tokens.d.ts +0 -26
- package/dist/cjs/get-base-tokens.js +0 -319
- package/dist/cjs/get-colors.d.ts +0 -20
- package/dist/cjs/get-colors.js +0 -20
- package/dist/cjs/get-default-tokens.d.ts +0 -645
- package/dist/cjs/get-default-tokens.js +0 -996
- package/dist/cjs/helpers/get-interactions.js +0 -61
- package/dist/cjs/helpers/get-logo.js +0 -32
- package/dist/cjs/helpers/get-palette.d.ts +0 -76
- package/dist/cjs/helpers/get-palette.js +0 -287
- package/dist/cjs/helpers/get-promo.d.ts +0 -12
- package/dist/cjs/helpers/get-promo.js +0 -56
- package/dist/cjs/types/base-tokens.d.ts +0 -125
- package/dist/cjs/types/base-tokens.js +0 -2
- package/dist/cjs/types/generator-tokens.js +0 -2
- package/dist/cjs/utils/format-variable.js +0 -15
- package/dist/colors.default-dark.js +0 -332
- package/dist/colors.default-light.js +0 -336
- package/dist/colors.less +0 -319
- package/dist/colors.scss +0 -319
- package/dist/esm/constants/abney-correction.d.ts +0 -2
- package/dist/esm/constants/abney-correction.js +0 -1102
- package/dist/esm/constants/chroma-settings.d.ts +0 -2
- package/dist/esm/constants/default-swatch.d.ts +0 -109
- package/dist/esm/constants/interaction-settings.d.ts +0 -8
- package/dist/esm/constants/logo-lightness.d.ts +0 -1
- package/dist/esm/constants/logo-lightness.js +0 -1
- package/dist/esm/constants/promo-hue-shift.d.ts +0 -3
- package/dist/esm/constants/warning-hue-patch.d.ts +0 -3
- package/dist/esm/get-base-tokens.d.ts +0 -26
- package/dist/esm/get-base-tokens.js +0 -257
- package/dist/esm/get-colors.d.ts +0 -20
- package/dist/esm/get-colors.js +0 -16
- package/dist/esm/get-default-tokens.d.ts +0 -645
- package/dist/esm/get-default-tokens.js +0 -992
- package/dist/esm/helpers/get-interactions.d.ts +0 -7
- package/dist/esm/helpers/get-interactions.js +0 -49
- package/dist/esm/helpers/get-logo.d.ts +0 -6
- package/dist/esm/helpers/get-logo.js +0 -28
- package/dist/esm/helpers/get-palette.d.ts +0 -76
- package/dist/esm/helpers/get-palette.js +0 -232
- package/dist/esm/helpers/get-promo.d.ts +0 -12
- package/dist/esm/helpers/get-promo.js +0 -51
- package/dist/esm/types/generator-tokens.d.ts +0 -43
- package/dist/esm/utils/format-variable.d.ts +0 -2
- package/dist/esm/utils/format-variable.js +0 -10
- package/dist/tokens-js/brand-blue-deep_accent-brand.js +0 -644
- package/dist/tokens-js/brand-blue-deep_accent-gray.js +0 -644
- package/dist/tokens-js/brand-blue_accent-brand.js +0 -644
- package/dist/tokens-js/brand-blue_accent-gray.js +0 -644
- package/dist/tokens-js/brand-green_accent-brand.js +0 -644
- package/dist/tokens-js/brand-green_accent-gray.js +0 -644
- package/dist/tokens-js/brand-mint_accent-brand.js +0 -644
- package/dist/tokens-js/brand-mint_accent-gray.js +0 -644
- package/dist/tokens-js/brand-orange_accent-gray.js +0 -644
- package/dist/tokens-js/brand-purple_accent-brand.js +0 -644
- package/dist/tokens-js/brand-purple_accent-gray.js +0 -644
- package/dist/tokens-js/brand-red_accent-gray.js +0 -644
- package/dist/tokens-js/brand-violet_accent-brand.js +0 -644
- package/dist/tokens-js/brand-violet_accent-gray.js +0 -644
- package/dist/tokens-mobile/brand-blue-deep_accent-brand.json +0 -718
- package/dist/tokens-mobile/brand-blue-deep_accent-gray.json +0 -718
- package/dist/tokens-mobile/brand-blue_accent-brand.json +0 -718
- package/dist/tokens-mobile/brand-blue_accent-gray.json +0 -718
- package/dist/tokens-mobile/brand-green_accent-brand.json +0 -718
- package/dist/tokens-mobile/brand-green_accent-gray.json +0 -718
- package/dist/tokens-mobile/brand-mint_accent-brand.json +0 -718
- package/dist/tokens-mobile/brand-mint_accent-gray.json +0 -718
- package/dist/tokens-mobile/brand-orange_accent-gray.json +0 -718
- package/dist/tokens-mobile/brand-purple_accent-brand.json +0 -718
- package/dist/tokens-mobile/brand-purple_accent-gray.json +0 -718
- package/dist/tokens-mobile/brand-red_accent-gray.json +0 -718
- package/dist/tokens-mobile/brand-violet_accent-brand.json +0 -718
- package/dist/tokens-mobile/brand-violet_accent-gray.json +0 -718
- /package/{dist/colors.js → colors.js} +0 -0
- /package/{dist/cjs/constants/interaction-settings.d.ts → lib/consts/params/interactions.d.ts} +0 -0
- /package/{dist/esm/constants/interaction-settings.js → lib/consts/params/interactions.js} +0 -0
- /package/{dist/esm/types/base-tokens.js → lib/types/tokens-base-generator.js} +0 -0
- /package/{dist/esm/types/generator-tokens.js → lib/types/tokens-base.js} +0 -0
- /package/{dist/cjs → lib}/utils/format-variable.d.ts +0 -0
|
@@ -1,49 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,28 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,76 +0,0 @@
|
|
|
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 {};
|
|
@@ -1,232 +0,0 @@
|
|
|
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 = Math.abs(Number(calcAPCA('#fff', hex)));
|
|
227
|
-
var blackContrast = Math.abs(Number(calcAPCA('#000', hex)));
|
|
228
|
-
if (whiteContrast + 10 >= blackContrast) {
|
|
229
|
-
return DefaultSwatch.whiteAlpha;
|
|
230
|
-
}
|
|
231
|
-
return DefaultSwatch.blackAlpha;
|
|
232
|
-
}
|
|
@@ -1,51 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,43 +0,0 @@
|
|
|
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
|
-
}
|
|
@@ -1,10 +0,0 @@
|
|
|
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
|
-
};
|