@atlaskit/tokens 0.8.3 → 0.9.2

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.
Files changed (72) hide show
  1. package/CHANGELOG.md +18 -0
  2. package/babel-plugin/package.json +3 -0
  3. package/css/atlassian-dark.css +1 -0
  4. package/css/atlassian-light.css +1 -0
  5. package/dist/cjs/artifacts/palettes-raw.js +1983 -0
  6. package/dist/cjs/artifacts/token-default-values.js +1 -0
  7. package/dist/cjs/artifacts/token-names.js +1 -0
  8. package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +395 -0
  9. package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +395 -0
  10. package/dist/cjs/entry-points/palettes-raw.js +15 -0
  11. package/dist/cjs/entry-points/token-ids.js +1 -1
  12. package/dist/cjs/get-token.js +1 -1
  13. package/dist/cjs/tokens/atlassian-dark/color/border.js +3 -0
  14. package/dist/cjs/tokens/atlassian-light/color/border.js +3 -0
  15. package/dist/cjs/tokens/default/color/border.js +8 -0
  16. package/dist/cjs/tokens/default/deprecated/deprecated.js +187 -0
  17. package/dist/cjs/tokens/palette.js +232 -116
  18. package/dist/cjs/utils/color-detection.js +129 -0
  19. package/dist/cjs/{token-ids.js → utils/token-ids.js} +1 -1
  20. package/dist/cjs/version.json +1 -1
  21. package/dist/es2019/artifacts/palettes-raw.js +1976 -0
  22. package/dist/es2019/artifacts/token-default-values.js +1 -0
  23. package/dist/es2019/artifacts/token-names.js +1 -0
  24. package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +395 -0
  25. package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +395 -0
  26. package/dist/es2019/entry-points/palettes-raw.js +1 -0
  27. package/dist/es2019/entry-points/token-ids.js +1 -1
  28. package/dist/es2019/get-token.js +1 -1
  29. package/dist/es2019/tokens/atlassian-dark/color/border.js +3 -0
  30. package/dist/es2019/tokens/atlassian-light/color/border.js +3 -0
  31. package/dist/es2019/tokens/default/color/border.js +8 -0
  32. package/dist/es2019/tokens/default/deprecated/deprecated.js +187 -0
  33. package/dist/es2019/tokens/palette.js +232 -116
  34. package/dist/es2019/utils/color-detection.js +101 -0
  35. package/dist/es2019/{token-ids.js → utils/token-ids.js} +1 -1
  36. package/dist/es2019/version.json +1 -1
  37. package/dist/esm/artifacts/palettes-raw.js +1976 -0
  38. package/dist/esm/artifacts/token-default-values.js +1 -0
  39. package/dist/esm/artifacts/token-names.js +1 -0
  40. package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +395 -0
  41. package/dist/esm/artifacts/tokens-raw/atlassian-light.js +395 -0
  42. package/dist/esm/entry-points/palettes-raw.js +1 -0
  43. package/dist/esm/entry-points/token-ids.js +1 -1
  44. package/dist/esm/get-token.js +1 -1
  45. package/dist/esm/tokens/atlassian-dark/color/border.js +3 -0
  46. package/dist/esm/tokens/atlassian-light/color/border.js +3 -0
  47. package/dist/esm/tokens/default/color/border.js +8 -0
  48. package/dist/esm/tokens/default/deprecated/deprecated.js +187 -0
  49. package/dist/esm/tokens/palette.js +232 -116
  50. package/dist/esm/utils/color-detection.js +104 -0
  51. package/dist/esm/{token-ids.js → utils/token-ids.js} +1 -1
  52. package/dist/esm/version.json +1 -1
  53. package/dist/types/artifacts/palettes-raw.d.ts +19 -0
  54. package/dist/types/artifacts/token-default-values.d.ts +1 -0
  55. package/dist/types/artifacts/token-names.d.ts +2 -0
  56. package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +43 -0
  57. package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +43 -0
  58. package/dist/types/artifacts/types-internal.d.ts +1 -1
  59. package/dist/types/artifacts/types.d.ts +1 -1
  60. package/dist/types/entry-points/palettes-raw.d.ts +1 -0
  61. package/dist/types/entry-points/token-ids.d.ts +1 -1
  62. package/dist/types/tokens/atlassian-dark/utility/utility.d.ts +2 -10
  63. package/dist/types/tokens/atlassian-light/utility/utility.d.ts +2 -10
  64. package/dist/types/tokens/default/utility/utility.d.ts +2 -142
  65. package/dist/types/types.d.ts +23 -7
  66. package/dist/types/utils/color-detection.d.ts +38 -0
  67. package/dist/types/{token-ids.d.ts → utils/token-ids.d.ts} +0 -0
  68. package/package.json +18 -4
  69. package/palettes-raw/package.json +10 -0
  70. package/rename-mapping/package.json +3 -0
  71. package/token-ids/package.json +3 -0
  72. 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(',');
@@ -1,4 +1,4 @@
1
- import { CSS_PREFIX } from './constants';
1
+ import { CSS_PREFIX } from '../constants';
2
2
  /**
3
3
  * Transforms a style dictionary token path to a CSS custom property.
4
4
  *
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "0.8.3",
3
+ "version": "0.9.2",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]