@atlaskit/tokens 1.11.3 → 1.13.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/CHANGELOG.md +30 -0
- package/dist/cjs/artifacts/atlassian-dark-token-value-for-contrast-check.js +25 -0
- package/dist/cjs/artifacts/atlassian-light-token-value-for-contrast-check.js +25 -0
- package/dist/cjs/artifacts/generated-pairs.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-legacy-dark.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-legacy-light.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-light.js +2 -2
- package/dist/cjs/artifacts/token-default-values.js +7 -1
- package/dist/cjs/artifacts/token-names.js +7 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +137 -5
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-dark.js +137 -5
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-light.js +137 -5
- package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +137 -5
- package/dist/cjs/constants.js +3 -1
- package/dist/cjs/custom-theme.js +108 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/set-global-theme.js +156 -59
- package/dist/cjs/tokens/atlassian-dark/color/background.js +22 -0
- package/dist/cjs/tokens/atlassian-legacy-dark/color/background.js +22 -0
- package/dist/cjs/tokens/atlassian-legacy-light/color/background.js +22 -0
- package/dist/cjs/tokens/atlassian-light/color/background.js +22 -0
- package/dist/cjs/tokens/default/color/background.js +54 -2
- package/dist/cjs/utils/color-utils.js +178 -0
- package/dist/cjs/utils/custom-theme-loading-utils.js +47 -0
- package/dist/cjs/utils/custom-theme-token-contrast-check.js +74 -0
- package/dist/cjs/utils/generate-custom-color-ramp.js +222 -0
- package/dist/cjs/utils/hash.js +17 -0
- package/dist/cjs/utils/hct-color-utils/color-utils.js +310 -0
- package/dist/cjs/utils/hct-color-utils/contrast.js +188 -0
- package/dist/cjs/utils/hct-color-utils/hct.js +1036 -0
- package/dist/cjs/utils/hct-color-utils/index.js +32 -0
- package/dist/cjs/utils/hct-color-utils/math-utils.js +159 -0
- package/dist/cjs/utils/theme-loading.js +1 -1
- package/dist/cjs/utils/theme-state-transformer.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/artifacts/atlassian-dark-token-value-for-contrast-check.js +18 -0
- package/dist/es2019/artifacts/atlassian-light-token-value-for-contrast-check.js +18 -0
- package/dist/es2019/artifacts/generated-pairs.js +2 -2
- package/dist/es2019/artifacts/themes/atlassian-dark.js +7 -1
- package/dist/es2019/artifacts/themes/atlassian-legacy-dark.js +7 -1
- package/dist/es2019/artifacts/themes/atlassian-legacy-light.js +7 -1
- package/dist/es2019/artifacts/themes/atlassian-light.js +7 -1
- package/dist/es2019/artifacts/token-default-values.js +7 -1
- package/dist/es2019/artifacts/token-names.js +7 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +137 -5
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-dark.js +137 -5
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-light.js +137 -5
- package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +137 -5
- package/dist/es2019/constants.js +1 -0
- package/dist/es2019/custom-theme.js +77 -0
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/set-global-theme.js +67 -13
- package/dist/es2019/tokens/atlassian-dark/color/background.js +22 -0
- package/dist/es2019/tokens/atlassian-legacy-dark/color/background.js +22 -0
- package/dist/es2019/tokens/atlassian-legacy-light/color/background.js +22 -0
- package/dist/es2019/tokens/atlassian-light/color/background.js +22 -0
- package/dist/es2019/tokens/default/color/background.js +54 -2
- package/dist/es2019/utils/color-utils.js +154 -0
- package/dist/es2019/utils/custom-theme-loading-utils.js +31 -0
- package/dist/es2019/utils/custom-theme-token-contrast-check.js +68 -0
- package/dist/es2019/utils/generate-custom-color-ramp.js +198 -0
- package/dist/es2019/utils/hash.js +10 -0
- package/dist/es2019/utils/hct-color-utils/color-utils.js +286 -0
- package/dist/es2019/utils/hct-color-utils/contrast.js +161 -0
- package/dist/es2019/utils/hct-color-utils/hct.js +931 -0
- package/dist/es2019/utils/hct-color-utils/index.js +3 -0
- package/dist/es2019/utils/hct-color-utils/math-utils.js +145 -0
- package/dist/es2019/utils/theme-loading.js +2 -2
- package/dist/es2019/utils/theme-state-transformer.js +3 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/artifacts/atlassian-dark-token-value-for-contrast-check.js +18 -0
- package/dist/esm/artifacts/atlassian-light-token-value-for-contrast-check.js +18 -0
- package/dist/esm/artifacts/generated-pairs.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-legacy-dark.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-legacy-light.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-light.js +2 -2
- package/dist/esm/artifacts/token-default-values.js +7 -1
- package/dist/esm/artifacts/token-names.js +7 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +137 -5
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-dark.js +137 -5
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-light.js +137 -5
- package/dist/esm/artifacts/tokens-raw/atlassian-light.js +137 -5
- package/dist/esm/constants.js +1 -0
- package/dist/esm/custom-theme.js +98 -0
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/set-global-theme.js +149 -60
- package/dist/esm/tokens/atlassian-dark/color/background.js +22 -0
- package/dist/esm/tokens/atlassian-legacy-dark/color/background.js +22 -0
- package/dist/esm/tokens/atlassian-legacy-light/color/background.js +22 -0
- package/dist/esm/tokens/atlassian-light/color/background.js +22 -0
- package/dist/esm/tokens/default/color/background.js +54 -2
- package/dist/esm/utils/color-utils.js +162 -0
- package/dist/esm/utils/custom-theme-loading-utils.js +38 -0
- package/dist/esm/utils/custom-theme-token-contrast-check.js +65 -0
- package/dist/esm/utils/generate-custom-color-ramp.js +211 -0
- package/dist/esm/utils/hash.js +10 -0
- package/dist/esm/utils/hct-color-utils/color-utils.js +285 -0
- package/dist/esm/utils/hct-color-utils/contrast.js +181 -0
- package/dist/esm/utils/hct-color-utils/hct.js +1029 -0
- package/dist/esm/utils/hct-color-utils/index.js +3 -0
- package/dist/esm/utils/hct-color-utils/math-utils.js +145 -0
- package/dist/esm/utils/theme-loading.js +2 -2
- package/dist/esm/utils/theme-state-transformer.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +18 -0
- package/dist/types/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +18 -0
- package/dist/types/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-legacy-dark.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-legacy-light.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types/artifacts/token-default-values.d.ts +7 -1
- package/dist/types/artifacts/token-names.d.ts +13 -1
- package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-dark.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-light.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types/artifacts/types-internal.d.ts +2 -2
- package/dist/types/artifacts/types.d.ts +2 -2
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/custom-theme.d.ts +30 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/set-global-theme.d.ts +9 -3
- package/dist/types/types.d.ts +10 -0
- package/dist/types/utils/color-utils.d.ts +10 -0
- package/dist/types/utils/custom-theme-loading-utils.d.ts +11 -0
- package/dist/types/utils/custom-theme-token-contrast-check.d.ts +20 -0
- package/dist/types/utils/generate-custom-color-ramp.d.ts +19 -0
- package/dist/types/utils/hash.d.ts +1 -0
- package/dist/types/utils/hct-color-utils/color-utils.d.ts +131 -0
- package/dist/types/utils/hct-color-utils/contrast.d.ts +78 -0
- package/dist/types/utils/hct-color-utils/hct.d.ts +137 -0
- package/dist/types/utils/hct-color-utils/index.d.ts +3 -0
- package/dist/types/utils/hct-color-utils/math-utils.d.ts +86 -0
- package/dist/types-ts4.5/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +18 -0
- package/dist/types-ts4.5/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +18 -0
- package/dist/types-ts4.5/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-legacy-dark.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-legacy-light.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/token-default-values.d.ts +7 -1
- package/dist/types-ts4.5/artifacts/token-names.d.ts +13 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-legacy-dark.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-legacy-light.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types-internal.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/types.d.ts +2 -2
- package/dist/types-ts4.5/constants.d.ts +1 -0
- package/dist/types-ts4.5/custom-theme.d.ts +30 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/set-global-theme.d.ts +9 -3
- package/dist/types-ts4.5/types.d.ts +10 -0
- package/dist/types-ts4.5/utils/color-utils.d.ts +27 -0
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +11 -0
- package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +20 -0
- package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +19 -0
- package/dist/types-ts4.5/utils/hash.d.ts +1 -0
- package/dist/types-ts4.5/utils/hct-color-utils/color-utils.d.ts +131 -0
- package/dist/types-ts4.5/utils/hct-color-utils/contrast.d.ts +78 -0
- package/dist/types-ts4.5/utils/hct-color-utils/hct.d.ts +137 -0
- package/dist/types-ts4.5/utils/hct-color-utils/index.d.ts +3 -0
- package/dist/types-ts4.5/utils/hct-color-utils/math-utils.d.ts +86 -0
- package/figma/atlassian-dark.json +56 -2
- package/figma/atlassian-legacy-dark.json +56 -2
- package/figma/atlassian-legacy-light.json +56 -2
- package/figma/atlassian-light.json +56 -2
- package/package.json +36 -37
- package/report.api.md +48 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark-iteration.js +0 -902
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark-iteration.js +0 -895
- package/dist/esm/artifacts/tokens-raw/atlassian-dark-iteration.js +0 -895
- package/dist/types/artifacts/tokens-raw/atlassian-dark-iteration.d.ts +0 -91
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-iteration.d.ts +0 -91
- package/tmp/api-report-tmp.d.ts +0 -1132
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
// valid hex color with 6 digits
|
|
2
|
+
export var isValidBrandHex = function isValidBrandHex(hex) {
|
|
3
|
+
return /^#[0-9A-F]{6}$/i.test(hex);
|
|
4
|
+
};
|
|
5
|
+
|
|
6
|
+
// valid hex color with 4, 6 or 8 digits
|
|
7
|
+
var isValidHex = function isValidHex(hex) {
|
|
8
|
+
return /^#([A-Fa-f0-9]{3,4}){1,2}$/.test(hex);
|
|
9
|
+
};
|
|
10
|
+
export function rgbToHex(r, g, b) {
|
|
11
|
+
return '#' + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1);
|
|
12
|
+
}
|
|
13
|
+
export function getAlpha(hex) {
|
|
14
|
+
if (hex.length === 9) {
|
|
15
|
+
var int = parseInt(hex.slice(7, 9), 16) / 255;
|
|
16
|
+
return Number(parseFloat(int.toString()).toFixed(2));
|
|
17
|
+
}
|
|
18
|
+
return 1;
|
|
19
|
+
}
|
|
20
|
+
export function hexToRgbA(hex) {
|
|
21
|
+
if (!isValidHex(hex)) {
|
|
22
|
+
throw new Error('Invalid HEX');
|
|
23
|
+
}
|
|
24
|
+
var c;
|
|
25
|
+
c = hex.substring(1).split('');
|
|
26
|
+
if (c.length === 3) {
|
|
27
|
+
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
|
|
28
|
+
}
|
|
29
|
+
c = '0x' + c.join('');
|
|
30
|
+
return [c >> 16 & 255, c >> 8 & 255, c & 255, getAlpha(hex)];
|
|
31
|
+
}
|
|
32
|
+
export function hexToRgb(hex) {
|
|
33
|
+
if (!isValidHex(hex)) {
|
|
34
|
+
throw new Error('Invalid HEX');
|
|
35
|
+
}
|
|
36
|
+
var c;
|
|
37
|
+
c = hex.substring(1).split('');
|
|
38
|
+
if (c.length === 3) {
|
|
39
|
+
c = [c[0], c[0], c[1], c[1], c[2], c[2]];
|
|
40
|
+
}
|
|
41
|
+
c = '0x' + c.join('');
|
|
42
|
+
return [c >> 16 & 255, c >> 8 & 255, c & 255];
|
|
43
|
+
}
|
|
44
|
+
export function hexToHSL(hex) {
|
|
45
|
+
if (!isValidHex(hex)) {
|
|
46
|
+
throw new Error('Invalid HEX');
|
|
47
|
+
}
|
|
48
|
+
var r = 0,
|
|
49
|
+
g = 0,
|
|
50
|
+
b = 0;
|
|
51
|
+
if (hex.length === 4) {
|
|
52
|
+
r = '0x' + hex[1] + hex[1];
|
|
53
|
+
g = '0x' + hex[2] + hex[2];
|
|
54
|
+
b = '0x' + hex[3] + hex[3];
|
|
55
|
+
} else if (hex.length === 7) {
|
|
56
|
+
r = '0x' + hex[1] + hex[2];
|
|
57
|
+
g = '0x' + hex[3] + hex[4];
|
|
58
|
+
b = '0x' + hex[5] + hex[6];
|
|
59
|
+
}
|
|
60
|
+
// Then to HSL
|
|
61
|
+
r /= 255;
|
|
62
|
+
g /= 255;
|
|
63
|
+
b /= 255;
|
|
64
|
+
var cmin = Math.min(r, g, b),
|
|
65
|
+
cmax = Math.max(r, g, b),
|
|
66
|
+
delta = cmax - cmin,
|
|
67
|
+
h = 0,
|
|
68
|
+
s = 0,
|
|
69
|
+
l = 0;
|
|
70
|
+
if (delta === 0) {
|
|
71
|
+
h = 0;
|
|
72
|
+
} else if (cmax === r) {
|
|
73
|
+
h = (g - b) / delta % 6;
|
|
74
|
+
} else if (cmax === g) {
|
|
75
|
+
h = (b - r) / delta + 2;
|
|
76
|
+
} else {
|
|
77
|
+
h = (r - g) / delta + 4;
|
|
78
|
+
}
|
|
79
|
+
h = Math.round(h * 60);
|
|
80
|
+
if (h < 0) {
|
|
81
|
+
h += 360;
|
|
82
|
+
}
|
|
83
|
+
l = (cmax + cmin) / 2;
|
|
84
|
+
s = delta === 0 ? 0 : delta / (1 - Math.abs(2 * l - 1));
|
|
85
|
+
s = +(s * 100).toFixed(1);
|
|
86
|
+
l = +(l * 100).toFixed(1);
|
|
87
|
+
return [h, s, l];
|
|
88
|
+
}
|
|
89
|
+
export function HSLToRGB(h, s, l) {
|
|
90
|
+
s /= 100;
|
|
91
|
+
l /= 100;
|
|
92
|
+
var k = function k(n) {
|
|
93
|
+
return (n + h / 30) % 12;
|
|
94
|
+
};
|
|
95
|
+
var a = s * Math.min(l, 1 - l);
|
|
96
|
+
var f = function f(n) {
|
|
97
|
+
return l - a * Math.max(-1, Math.min(k(n) - 3, Math.min(9 - k(n), 1)));
|
|
98
|
+
};
|
|
99
|
+
return [255 * f(0), 255 * f(8), 255 * f(4)];
|
|
100
|
+
}
|
|
101
|
+
export function relativeLuminanceW3C(r, g, b) {
|
|
102
|
+
var RsRGB = r / 255;
|
|
103
|
+
var GsRGB = g / 255;
|
|
104
|
+
var BsRGB = b / 255;
|
|
105
|
+
var R = RsRGB <= 0.03928 ? RsRGB / 12.92 : Math.pow((RsRGB + 0.055) / 1.055, 2.4);
|
|
106
|
+
var G = GsRGB <= 0.03928 ? GsRGB / 12.92 : Math.pow((GsRGB + 0.055) / 1.055, 2.4);
|
|
107
|
+
var B = BsRGB <= 0.03928 ? BsRGB / 12.92 : Math.pow((BsRGB + 0.055) / 1.055, 2.4);
|
|
108
|
+
|
|
109
|
+
// For the sRGB colorspace, the relative luminance of a color is defined as:
|
|
110
|
+
var L = 0.2126 * R + 0.7152 * G + 0.0722 * B;
|
|
111
|
+
return L;
|
|
112
|
+
}
|
|
113
|
+
export function getContrastRatio(foreground, background) {
|
|
114
|
+
if (!isValidHex(foreground) || !isValidHex(background)) {
|
|
115
|
+
throw new Error('Invalid HEX');
|
|
116
|
+
}
|
|
117
|
+
var foregroundRgb = hexToRgb(foreground);
|
|
118
|
+
var backgroundRgb = hexToRgb(background);
|
|
119
|
+
var foregroundLuminance = relativeLuminanceW3C(foregroundRgb[0], foregroundRgb[1], foregroundRgb[2]);
|
|
120
|
+
var backgroundLuminance = relativeLuminanceW3C(backgroundRgb[0], backgroundRgb[1], backgroundRgb[2]);
|
|
121
|
+
// calculate the color contrast ratio
|
|
122
|
+
var brightest = Math.max(foregroundLuminance, backgroundLuminance);
|
|
123
|
+
var darkest = Math.min(foregroundLuminance, backgroundLuminance);
|
|
124
|
+
return (brightest + 0.05) / (darkest + 0.05);
|
|
125
|
+
}
|
|
126
|
+
export function deltaE(rgbA, rgbB) {
|
|
127
|
+
var labA = rgbToLab(rgbA);
|
|
128
|
+
var labB = rgbToLab(rgbB);
|
|
129
|
+
var deltaL = labA[0] - labB[0];
|
|
130
|
+
var deltaA = labA[1] - labB[1];
|
|
131
|
+
var deltaB = labA[2] - labB[2];
|
|
132
|
+
var c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
|
|
133
|
+
var c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
|
|
134
|
+
var deltaC = c1 - c2;
|
|
135
|
+
var deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
|
|
136
|
+
deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
|
|
137
|
+
var sc = 1.0 + 0.045 * c1;
|
|
138
|
+
var sh = 1.0 + 0.015 * c1;
|
|
139
|
+
var deltaLKlsl = deltaL / 1.0;
|
|
140
|
+
var deltaCkcsc = deltaC / sc;
|
|
141
|
+
var deltaHkhsh = deltaH / sh;
|
|
142
|
+
var i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
|
|
143
|
+
return i < 0 ? 0 : Math.sqrt(i);
|
|
144
|
+
}
|
|
145
|
+
function rgbToLab(rgb) {
|
|
146
|
+
var r = rgb[0] / 255,
|
|
147
|
+
g = rgb[1] / 255,
|
|
148
|
+
b = rgb[2] / 255,
|
|
149
|
+
x,
|
|
150
|
+
y,
|
|
151
|
+
z;
|
|
152
|
+
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
|
153
|
+
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
|
154
|
+
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
|
155
|
+
x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
|
|
156
|
+
y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.0;
|
|
157
|
+
z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
|
|
158
|
+
x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
|
|
159
|
+
y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
|
|
160
|
+
z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
|
|
161
|
+
return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
|
|
162
|
+
}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
3
|
+
import tokens from '../artifacts/token-names';
|
|
4
|
+
import { CUSTOM_THEME_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from '../constants';
|
|
5
|
+
import { hash } from './hash';
|
|
6
|
+
export function findMissingCustomStyleElements(UNSAFE_themeOptions, mode) {
|
|
7
|
+
var optionString = JSON.stringify(UNSAFE_themeOptions);
|
|
8
|
+
var uniqueId = hash(optionString);
|
|
9
|
+
var attrOfMissingCustomStyles = [];
|
|
10
|
+
(mode === 'auto' ? ['light', 'dark'] : [mode]).forEach(function (themeId) {
|
|
11
|
+
var element = document.head.querySelector("style[".concat(CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(THEME_DATA_ATTRIBUTE, "=\"").concat(themeId, "\"]"));
|
|
12
|
+
if (element) {
|
|
13
|
+
// Append the existing custom styles to take precedence over others
|
|
14
|
+
document.head.appendChild(element);
|
|
15
|
+
} else {
|
|
16
|
+
attrOfMissingCustomStyles.push(themeId);
|
|
17
|
+
}
|
|
18
|
+
});
|
|
19
|
+
return attrOfMissingCustomStyles;
|
|
20
|
+
}
|
|
21
|
+
export function limitSizeOfCustomStyleElements(sizeThreshold) {
|
|
22
|
+
var styleTags = _toConsumableArray(document.head.querySelectorAll("style[".concat(CUSTOM_THEME_ATTRIBUTE, "][").concat(THEME_DATA_ATTRIBUTE, "]")));
|
|
23
|
+
if (styleTags.length < sizeThreshold) {
|
|
24
|
+
return;
|
|
25
|
+
}
|
|
26
|
+
styleTags.slice(0, styleTags.length - (sizeThreshold - 1)).forEach(function (element) {
|
|
27
|
+
return element.remove();
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
export function reduceTokenMap(tokenMap, themeRamp) {
|
|
31
|
+
return Object.entries(tokenMap).reduce(function (acc, _ref) {
|
|
32
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
33
|
+
key = _ref2[0],
|
|
34
|
+
value = _ref2[1];
|
|
35
|
+
var cssVar = tokens[key];
|
|
36
|
+
return cssVar ? "".concat(acc, "\n ").concat(cssVar, ": ").concat(themeRamp[value], ";") : acc;
|
|
37
|
+
}, '');
|
|
38
|
+
}
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import tokenValuesDark from '../artifacts/atlassian-dark-token-value-for-contrast-check';
|
|
2
|
+
import tokenValuesLight from '../artifacts/atlassian-light-token-value-for-contrast-check';
|
|
3
|
+
import { getContrastRatio } from './color-utils';
|
|
4
|
+
export var additionalChecks = [{
|
|
5
|
+
foreground: 'color.text.brand',
|
|
6
|
+
backgroundLight: 'elevation.surface.sunken',
|
|
7
|
+
backgroundDark: 'elevation.surface.overlay',
|
|
8
|
+
desiredContrast: 4.5,
|
|
9
|
+
updatedTokens: [
|
|
10
|
+
// In light mode: darken the following tokens by one base token
|
|
11
|
+
// In dark mode: lighten the following tokens by one base token
|
|
12
|
+
'color.text.brand', 'color.text.selected', 'color.link', 'color.link.pressed', 'color.icon.brand', 'color.icon.selected']
|
|
13
|
+
}, {
|
|
14
|
+
foreground: 'color.text.selected',
|
|
15
|
+
backgroundLight: 'color.background.selected',
|
|
16
|
+
backgroundDark: 'color.background.selected',
|
|
17
|
+
desiredContrast: 4.5,
|
|
18
|
+
// In light mode: darken the following tokens by one base token
|
|
19
|
+
// In dark mode: lighten the following tokens by one base token
|
|
20
|
+
updatedTokens: ['color.text.selected', 'color.icon.selected']
|
|
21
|
+
}, {
|
|
22
|
+
foreground: 'color.border.brand',
|
|
23
|
+
backgroundLight: 'elevation.surface.sunken',
|
|
24
|
+
backgroundDark: 'elevation.surface.overlay',
|
|
25
|
+
desiredContrast: 3,
|
|
26
|
+
// In light mode: darken the following tokens by one base token
|
|
27
|
+
// In dark mode: lighten the following tokens by one base toke
|
|
28
|
+
updatedTokens: ['color.border.brand', 'color.border.selected']
|
|
29
|
+
}, {
|
|
30
|
+
foreground: 'color.chart.brand',
|
|
31
|
+
backgroundLight: 'elevation.surface.sunken',
|
|
32
|
+
backgroundDark: 'elevation.surface.overlay',
|
|
33
|
+
desiredContrast: 3,
|
|
34
|
+
// In light mode: darken the following tokens by one base token
|
|
35
|
+
// In dark mode: lighten the following tokens by one base token
|
|
36
|
+
updatedTokens: ['color.chart.brand', 'color.chart.brand.hovered']
|
|
37
|
+
}];
|
|
38
|
+
var getColorFromTokenRaw = function getColorFromTokenRaw(tokenName, mode) {
|
|
39
|
+
return mode === 'light' ? tokenValuesLight[tokenName] : tokenValuesDark[tokenName];
|
|
40
|
+
};
|
|
41
|
+
export var additionalContrastChecker = function additionalContrastChecker(_ref) {
|
|
42
|
+
var customThemeTokenMap = _ref.customThemeTokenMap,
|
|
43
|
+
mode = _ref.mode,
|
|
44
|
+
themeRamp = _ref.themeRamp;
|
|
45
|
+
var updatedCustomThemeTokenMap = {};
|
|
46
|
+
var brandTokens = Object.keys(customThemeTokenMap);
|
|
47
|
+
additionalChecks.forEach(function (pairing) {
|
|
48
|
+
var backgroundLight = pairing.backgroundLight,
|
|
49
|
+
backgroundDark = pairing.backgroundDark,
|
|
50
|
+
foreground = pairing.foreground,
|
|
51
|
+
desiredContrast = pairing.desiredContrast,
|
|
52
|
+
updatedTokens = pairing.updatedTokens;
|
|
53
|
+
var background = mode === 'light' ? backgroundLight : backgroundDark;
|
|
54
|
+
var foregroundColor = brandTokens.includes(foreground) ? themeRamp[customThemeTokenMap[foreground]] : getColorFromTokenRaw(foreground, mode);
|
|
55
|
+
var backgroundColor = brandTokens.includes(background) ? themeRamp[customThemeTokenMap[background]] : getColorFromTokenRaw(background, mode);
|
|
56
|
+
var contrast = getContrastRatio(foregroundColor, backgroundColor);
|
|
57
|
+
if (contrast <= desiredContrast) {
|
|
58
|
+
updatedTokens.forEach(function (token) {
|
|
59
|
+
var rampValue = customThemeTokenMap[token];
|
|
60
|
+
updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
|
|
61
|
+
});
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return updatedCustomThemeTokenMap;
|
|
65
|
+
};
|
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
+
import rawTokensDark from '../artifacts/atlassian-dark-token-value-for-contrast-check';
|
|
7
|
+
import { deltaE, getContrastRatio, hexToHSL, hexToRgb, hexToRgbA, HSLToRGB, relativeLuminanceW3C, rgbToHex } from './color-utils';
|
|
8
|
+
import { additionalContrastChecker } from './custom-theme-token-contrast-check';
|
|
9
|
+
import { argbFromRgba, Contrast, Hct, rgbaFromArgb } from './hct-color-utils';
|
|
10
|
+
var lowLuminanceContrastRatios = [1.12, 1.33, 2.03, 2.73, 3.33, 4.27, 5.2, 6.62, 12.46, 14.25];
|
|
11
|
+
var highLuminanceContrastRatios = [1.08, 1.24, 1.55, 1.99, 2.45, 3.34, 4.64, 6.1, 10.19, 12.6];
|
|
12
|
+
export var getClosestColorIndex = function getClosestColorIndex(themeRamp, brandColor) {
|
|
13
|
+
// Iterate over themeRamp and find whichever color is closest to brandColor
|
|
14
|
+
var closestColorIndex = 0;
|
|
15
|
+
var closestColorDistance = null;
|
|
16
|
+
themeRamp.forEach(function (value, index) {
|
|
17
|
+
var distance = deltaE(hexToRgb(value), hexToRgb(brandColor));
|
|
18
|
+
if (closestColorDistance === null || distance < closestColorDistance) {
|
|
19
|
+
closestColorIndex = index;
|
|
20
|
+
closestColorDistance = distance;
|
|
21
|
+
}
|
|
22
|
+
});
|
|
23
|
+
return closestColorIndex;
|
|
24
|
+
};
|
|
25
|
+
export var generateColors = function generateColors(brandColor) {
|
|
26
|
+
// Determine luminance
|
|
27
|
+
var HSLBrandColorHue = hexToHSL(brandColor)[0];
|
|
28
|
+
var baseRgb = HSLToRGB(HSLBrandColorHue, 100, 60);
|
|
29
|
+
var isLowLuminance = relativeLuminanceW3C(baseRgb[0], baseRgb[1], baseRgb[2]) < 0.4;
|
|
30
|
+
// Choose right palette
|
|
31
|
+
var themeRatios = isLowLuminance ? lowLuminanceContrastRatios : highLuminanceContrastRatios;
|
|
32
|
+
var brandRgba = hexToRgbA(brandColor);
|
|
33
|
+
var hctColor = Hct.fromInt(argbFromRgba({
|
|
34
|
+
r: brandRgba[0],
|
|
35
|
+
g: brandRgba[1],
|
|
36
|
+
b: brandRgba[2],
|
|
37
|
+
a: brandRgba[3]
|
|
38
|
+
}));
|
|
39
|
+
var themeRamp = themeRatios.map(function (contrast) {
|
|
40
|
+
var rgbaColor = rgbaFromArgb(Hct.from(hctColor.hue, hctColor.chroma, Contrast.darker(100, contrast) + 0.25 // Material's utils provide an offset
|
|
41
|
+
).toInt());
|
|
42
|
+
return rgbToHex(rgbaColor.r, rgbaColor.g, rgbaColor.b);
|
|
43
|
+
});
|
|
44
|
+
var closestColorIndex = getClosestColorIndex(themeRamp, brandColor);
|
|
45
|
+
|
|
46
|
+
// Replace closet color with brandColor
|
|
47
|
+
var updatedThemeRamp = _toConsumableArray(themeRamp);
|
|
48
|
+
updatedThemeRamp[closestColorIndex] = brandColor;
|
|
49
|
+
return updatedThemeRamp;
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
/**
|
|
53
|
+
* Return the interaction tokens for a color, given its ramp position and the number of
|
|
54
|
+
* needed interaction states. Use higher-indexed colors (i.e. darker colors) if possible;
|
|
55
|
+
* if there's not enough room to shift up for the required number of interaction tokens,
|
|
56
|
+
* it goes as far as it can, then returns lighter colors lower down the ramp instead.
|
|
57
|
+
*
|
|
58
|
+
* Returns an array of the resulting colors
|
|
59
|
+
*/
|
|
60
|
+
function getInteractionStates(rampPosition, number, colors) {
|
|
61
|
+
var result = [];
|
|
62
|
+
for (var i = 1; i <= number; i++) {
|
|
63
|
+
if (rampPosition + i < colors.length) {
|
|
64
|
+
result.push(rampPosition + i);
|
|
65
|
+
} else {
|
|
66
|
+
result.push(rampPosition - (i - (colors.length - 1 - rampPosition)));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
export var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
|
|
72
|
+
var colors = themeRamp || generateColors(brandColor);
|
|
73
|
+
var closestColorIndex = getClosestColorIndex(colors, brandColor);
|
|
74
|
+
var customThemeTokenMapLight = {};
|
|
75
|
+
var customThemeTokenMapDark = {};
|
|
76
|
+
var inputContrast = getContrastRatio(brandColor, '#FFFFFF');
|
|
77
|
+
// Branch based on brandColor's contrast against white
|
|
78
|
+
if (inputContrast >= 4.5) {
|
|
79
|
+
/**
|
|
80
|
+
* Generate interaction tokens for
|
|
81
|
+
* - color.background.brand.bold
|
|
82
|
+
* - color.background.selected.bold
|
|
83
|
+
*/
|
|
84
|
+
var _getInteractionStates = getInteractionStates(closestColorIndex, 2, colors),
|
|
85
|
+
_getInteractionStates2 = _slicedToArray(_getInteractionStates, 2),
|
|
86
|
+
brandBoldSelectedHoveredIndex = _getInteractionStates2[0],
|
|
87
|
+
brandBoldSelectedPressedIndex = _getInteractionStates2[1];
|
|
88
|
+
|
|
89
|
+
/**
|
|
90
|
+
* Generate interaction token for color.link:
|
|
91
|
+
* If inputted color replaces X1000
|
|
92
|
+
* - Pressed = X900
|
|
93
|
+
*
|
|
94
|
+
* If inputted color replaces X700-X900
|
|
95
|
+
* - Shift one 1 step darker
|
|
96
|
+
*/
|
|
97
|
+
var _getInteractionStates3 = getInteractionStates(closestColorIndex, 1, colors),
|
|
98
|
+
_getInteractionStates4 = _slicedToArray(_getInteractionStates3, 1),
|
|
99
|
+
linkPressed = _getInteractionStates4[0];
|
|
100
|
+
customThemeTokenMapLight = {
|
|
101
|
+
'color.text.brand': closestColorIndex,
|
|
102
|
+
'color.icon.brand': closestColorIndex,
|
|
103
|
+
'color.background.brand.subtlest': 0,
|
|
104
|
+
'color.background.brand.subtlest.hovered': 1,
|
|
105
|
+
'color.background.brand.subtlest.pressed': 2,
|
|
106
|
+
'color.background.brand.bold': closestColorIndex,
|
|
107
|
+
'color.background.brand.bold.hovered': brandBoldSelectedHoveredIndex,
|
|
108
|
+
'color.background.brand.bold.pressed': brandBoldSelectedPressedIndex,
|
|
109
|
+
'color.background.brand.boldest': 9,
|
|
110
|
+
'color.background.brand.boldest.hovered': 8,
|
|
111
|
+
'color.background.brand.boldest.pressed': 7,
|
|
112
|
+
'color.border.brand': closestColorIndex,
|
|
113
|
+
'color.text.selected': closestColorIndex,
|
|
114
|
+
'color.icon.selected': closestColorIndex,
|
|
115
|
+
'color.background.selected.bold': closestColorIndex,
|
|
116
|
+
'color.background.selected.bold.hovered': brandBoldSelectedHoveredIndex,
|
|
117
|
+
'color.background.selected.bold.pressed': brandBoldSelectedPressedIndex,
|
|
118
|
+
'color.border.selected': closestColorIndex,
|
|
119
|
+
'color.link': closestColorIndex,
|
|
120
|
+
'color.link.pressed': linkPressed,
|
|
121
|
+
'color.chart.brand': 5,
|
|
122
|
+
'color.chart.brand.hovered': 6,
|
|
123
|
+
'color.background.selected': 0,
|
|
124
|
+
'color.background.selected.hovered': 1,
|
|
125
|
+
'color.background.selected.pressed': 2
|
|
126
|
+
};
|
|
127
|
+
} else {
|
|
128
|
+
customThemeTokenMapLight = {
|
|
129
|
+
'color.background.brand.subtlest': 0,
|
|
130
|
+
'color.background.brand.subtlest.hovered': 1,
|
|
131
|
+
'color.background.brand.subtlest.pressed': 2,
|
|
132
|
+
'color.background.brand.bold': 6,
|
|
133
|
+
'color.background.brand.bold.hovered': 7,
|
|
134
|
+
'color.background.brand.bold.pressed': 8,
|
|
135
|
+
'color.background.brand.boldest': 9,
|
|
136
|
+
'color.background.brand.boldest.hovered': 8,
|
|
137
|
+
'color.background.brand.boldest.pressed': 7,
|
|
138
|
+
'color.border.brand': 6,
|
|
139
|
+
'color.background.selected.bold': 6,
|
|
140
|
+
'color.background.selected.bold.hovered': 7,
|
|
141
|
+
'color.background.selected.bold.pressed': 8,
|
|
142
|
+
'color.text.brand': 6,
|
|
143
|
+
'color.icon.brand': 6,
|
|
144
|
+
'color.chart.brand': 5,
|
|
145
|
+
'color.chart.brand.hovered': 6,
|
|
146
|
+
'color.text.selected': 6,
|
|
147
|
+
'color.icon.selected': 6,
|
|
148
|
+
'color.border.selected': 6,
|
|
149
|
+
'color.background.selected': 0,
|
|
150
|
+
'color.background.selected.hovered': 1,
|
|
151
|
+
'color.background.selected.pressed': 2,
|
|
152
|
+
'color.link': 6,
|
|
153
|
+
'color.link.pressed': 7
|
|
154
|
+
};
|
|
155
|
+
}
|
|
156
|
+
if (mode === 'light') {
|
|
157
|
+
return {
|
|
158
|
+
light: customThemeTokenMapLight
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
/**
|
|
163
|
+
* Generate dark mode values using rule of symmetry
|
|
164
|
+
*/
|
|
165
|
+
Object.entries(customThemeTokenMapLight).forEach(function (_ref) {
|
|
166
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
167
|
+
key = _ref2[0],
|
|
168
|
+
value = _ref2[1];
|
|
169
|
+
customThemeTokenMapDark[key] = 9 - value;
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
/**
|
|
173
|
+
* If the input brand color < 4.5, and it meets 4.5 contrast again inverse text color
|
|
174
|
+
* in dark mode, shift color.background.brand.bold to the brand color
|
|
175
|
+
*/
|
|
176
|
+
if (inputContrast < 4.5) {
|
|
177
|
+
var inverseTextColor = rawTokensDark['color.text.inverse'];
|
|
178
|
+
if (getContrastRatio(inverseTextColor, brandColor) >= 4.5 && closestColorIndex >= 2) {
|
|
179
|
+
customThemeTokenMapDark['color.background.brand.bold'] = closestColorIndex;
|
|
180
|
+
customThemeTokenMapDark['color.background.brand.bold.hovered'] = closestColorIndex - 1;
|
|
181
|
+
customThemeTokenMapDark['color.background.brand.bold.pressed'] = closestColorIndex - 2;
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
if (mode === 'dark') {
|
|
185
|
+
return {
|
|
186
|
+
dark: customThemeTokenMapDark
|
|
187
|
+
};
|
|
188
|
+
}
|
|
189
|
+
return {
|
|
190
|
+
light: customThemeTokenMapLight,
|
|
191
|
+
dark: customThemeTokenMapDark
|
|
192
|
+
};
|
|
193
|
+
};
|
|
194
|
+
export var generateTokenMapWithContrastCheck = function generateTokenMapWithContrastCheck(brandColor, mode, themeRamp) {
|
|
195
|
+
var colors = themeRamp || generateColors(brandColor);
|
|
196
|
+
var tokenMaps = generateTokenMap(brandColor, mode, colors);
|
|
197
|
+
var result = {};
|
|
198
|
+
Object.entries(tokenMaps).forEach(function (_ref3) {
|
|
199
|
+
var _ref4 = _slicedToArray(_ref3, 2),
|
|
200
|
+
mode = _ref4[0],
|
|
201
|
+
map = _ref4[1];
|
|
202
|
+
if (mode === 'light' || mode === 'dark') {
|
|
203
|
+
result[mode] = _objectSpread(_objectSpread({}, map), additionalContrastChecker({
|
|
204
|
+
customThemeTokenMap: map,
|
|
205
|
+
mode: mode,
|
|
206
|
+
themeRamp: colors
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
return result;
|
|
211
|
+
};
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
export var hash = function hash(str) {
|
|
2
|
+
var hash = 0;
|
|
3
|
+
for (var i = 0; i < str.length; i++) {
|
|
4
|
+
var char = str.charCodeAt(i);
|
|
5
|
+
hash = (hash << 5) - hash + char;
|
|
6
|
+
hash &= hash; // Convert to 32bit integer
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
return new Uint32Array([hash])[0].toString(36);
|
|
10
|
+
};
|