@atlaskit/tokens 0.9.0 → 0.9.3
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 +18 -0
- package/babel-plugin/package.json +3 -0
- package/css/atlassian-dark.css +2 -2
- package/css/atlassian-light.css +2 -2
- package/dist/cjs/artifacts/palettes-raw.js +1983 -0
- package/dist/cjs/artifacts/token-default-values.js +2 -2
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +378 -4
- package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +378 -4
- package/dist/cjs/entry-points/palettes-raw.js +15 -0
- package/dist/cjs/entry-points/token-ids.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/tokens/atlassian-dark/color/background.js +2 -2
- package/dist/cjs/tokens/atlassian-light/color/background.js +2 -2
- package/dist/cjs/tokens/default/deprecated/deprecated.js +187 -0
- package/dist/cjs/tokens/palette.js +232 -116
- package/dist/cjs/utils/color-detection.js +129 -0
- package/dist/cjs/{token-ids.js → utils/token-ids.js} +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/artifacts/palettes-raw.js +1976 -0
- package/dist/es2019/artifacts/token-default-values.js +2 -2
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +378 -4
- package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +378 -4
- package/dist/es2019/entry-points/palettes-raw.js +1 -0
- package/dist/es2019/entry-points/token-ids.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/tokens/atlassian-dark/color/background.js +2 -2
- package/dist/es2019/tokens/atlassian-light/color/background.js +2 -2
- package/dist/es2019/tokens/default/deprecated/deprecated.js +187 -0
- package/dist/es2019/tokens/palette.js +232 -116
- package/dist/es2019/utils/color-detection.js +101 -0
- package/dist/es2019/{token-ids.js → utils/token-ids.js} +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/artifacts/palettes-raw.js +1976 -0
- package/dist/esm/artifacts/token-default-values.js +2 -2
- package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +378 -4
- package/dist/esm/artifacts/tokens-raw/atlassian-light.js +378 -4
- package/dist/esm/entry-points/palettes-raw.js +1 -0
- package/dist/esm/entry-points/token-ids.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/tokens/atlassian-dark/color/background.js +2 -2
- package/dist/esm/tokens/atlassian-light/color/background.js +2 -2
- package/dist/esm/tokens/default/deprecated/deprecated.js +187 -0
- package/dist/esm/tokens/palette.js +232 -116
- package/dist/esm/utils/color-detection.js +104 -0
- package/dist/esm/{token-ids.js → utils/token-ids.js} +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/artifacts/palettes-raw.d.ts +19 -0
- package/dist/types/artifacts/token-default-values.d.ts +2 -2
- package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +43 -0
- package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +43 -0
- package/dist/types/entry-points/palettes-raw.d.ts +1 -0
- package/dist/types/entry-points/token-ids.d.ts +1 -1
- package/dist/types/tokens/atlassian-dark/utility/utility.d.ts +2 -10
- package/dist/types/tokens/atlassian-light/utility/utility.d.ts +2 -10
- package/dist/types/tokens/default/utility/utility.d.ts +2 -142
- package/dist/types/types.d.ts +22 -7
- package/dist/types/utils/color-detection.d.ts +38 -0
- package/dist/types/{token-ids.d.ts → utils/token-ids.d.ts} +0 -0
- package/package.json +15 -5
- package/palettes-raw/package.json +10 -0
- package/rename-mapping/package.json +3 -0
- package/token-ids/package.json +3 -0
- package/token-names/package.json +3 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { token } from '../index';
|
|
2
|
+
export const hexToRGBAValues = hex => {
|
|
3
|
+
const hexColor = hex.replace('#', '');
|
|
4
|
+
return {
|
|
5
|
+
r: parseInt(hexColor.slice(0, 2), 16),
|
|
6
|
+
g: parseInt(hexColor.slice(2, 4), 16),
|
|
7
|
+
b: parseInt(hexColor.slice(4, 6), 16),
|
|
8
|
+
a: parseFloat((parseInt(hexColor.slice(6, 8), 16) / 255).toFixed(2))
|
|
9
|
+
};
|
|
10
|
+
};
|
|
11
|
+
export const hexToRGBA = hex => {
|
|
12
|
+
const {
|
|
13
|
+
r,
|
|
14
|
+
g,
|
|
15
|
+
b,
|
|
16
|
+
a
|
|
17
|
+
} = hexToRGBAValues(hex);
|
|
18
|
+
return `rgb${a ? 'a' : ''}(${r},${g},${b}${a ? `,${a}` : ''})`;
|
|
19
|
+
};
|
|
20
|
+
export const getLuminance = ({
|
|
21
|
+
r,
|
|
22
|
+
g,
|
|
23
|
+
b
|
|
24
|
+
}) => (r * 299 + g * 587 + b * 114) / 1000;
|
|
25
|
+
/**
|
|
26
|
+
* Returns an accessible hard-coded text color based on the color contrast with
|
|
27
|
+
* the background.
|
|
28
|
+
*
|
|
29
|
+
* @param hex - The Hex color code of the background
|
|
30
|
+
* @param [opts.hardcodedSurface] - If set, a design token will be returned instead
|
|
31
|
+
* of a hard-coded color. This is to support more transparent backgrounds
|
|
32
|
+
* to allow the text to invert colors depending on the current theme's surface color.
|
|
33
|
+
*/
|
|
34
|
+
|
|
35
|
+
export const getTextColorForBackground = (hex, opts) => {
|
|
36
|
+
const {
|
|
37
|
+
r,
|
|
38
|
+
g,
|
|
39
|
+
b,
|
|
40
|
+
a
|
|
41
|
+
} = hexToRGBAValues(hex);
|
|
42
|
+
const lum = getLuminance({
|
|
43
|
+
r,
|
|
44
|
+
g,
|
|
45
|
+
b
|
|
46
|
+
});
|
|
47
|
+
const alphaLimit = 0.42;
|
|
48
|
+
const alphaConditionsPerSurface = {
|
|
49
|
+
light: a < alphaLimit,
|
|
50
|
+
dark: a > alphaLimit
|
|
51
|
+
};
|
|
52
|
+
const alphaLimitExceeded = (opts === null || opts === void 0 ? void 0 : opts.hardcodedSurface) && alphaConditionsPerSurface[opts.hardcodedSurface];
|
|
53
|
+
|
|
54
|
+
if (!(opts !== null && opts !== void 0 && opts.hardcodedSurface) && a < alphaLimit) {
|
|
55
|
+
// This color is transparent, so the text will mainly cast onto the surface behind.
|
|
56
|
+
// Needs to use tokens otherwise Dark mode would cause black text on black surface
|
|
57
|
+
return token('color.text', 'black');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
return lum > 150 && !a || a && alphaLimitExceeded ? 'black' : 'white';
|
|
61
|
+
};
|
|
62
|
+
/**
|
|
63
|
+
* Returns a border if determined to be required based on the color contrast with
|
|
64
|
+
* the background.
|
|
65
|
+
*
|
|
66
|
+
* @param hex - The Hex color code of the background
|
|
67
|
+
*/
|
|
68
|
+
|
|
69
|
+
export const getBorderForBackground = hex => {
|
|
70
|
+
const {
|
|
71
|
+
r,
|
|
72
|
+
g,
|
|
73
|
+
b,
|
|
74
|
+
a
|
|
75
|
+
} = hexToRGBAValues(hex);
|
|
76
|
+
const lum = getLuminance({
|
|
77
|
+
r,
|
|
78
|
+
g,
|
|
79
|
+
b
|
|
80
|
+
});
|
|
81
|
+
return lum > 240 || a < 0.2 ? `1px solid ${token('color.border', '#091E4224')}` : undefined;
|
|
82
|
+
};
|
|
83
|
+
/**
|
|
84
|
+
* Returns a box shadow formatted for CSS from a ShadowToken raw value.
|
|
85
|
+
*
|
|
86
|
+
* @param rawShadow - ShadowToken raw value
|
|
87
|
+
*/
|
|
88
|
+
|
|
89
|
+
export const getBoxShadow = rawShadow => rawShadow.map(({
|
|
90
|
+
radius,
|
|
91
|
+
offset,
|
|
92
|
+
color,
|
|
93
|
+
opacity
|
|
94
|
+
}) => {
|
|
95
|
+
const {
|
|
96
|
+
r,
|
|
97
|
+
g,
|
|
98
|
+
b
|
|
99
|
+
} = hexToRGBAValues(color);
|
|
100
|
+
return `${offset.x}px ${offset.y}px ${radius}px rgba(${r}, ${g}, ${b}, ${opacity})`;
|
|
101
|
+
}).join(',');
|