@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,129 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.hexToRGBAValues = exports.hexToRGBA = exports.getTextColorForBackground = exports.getLuminance = exports.getBoxShadow = exports.getBorderForBackground = void 0;
7
+
8
+ var _index = require("../index");
9
+
10
+ var hexToRGBAValues = function hexToRGBAValues(hex) {
11
+ var hexColor = hex.replace('#', '');
12
+ return {
13
+ r: parseInt(hexColor.slice(0, 2), 16),
14
+ g: parseInt(hexColor.slice(2, 4), 16),
15
+ b: parseInt(hexColor.slice(4, 6), 16),
16
+ a: parseFloat((parseInt(hexColor.slice(6, 8), 16) / 255).toFixed(2))
17
+ };
18
+ };
19
+
20
+ exports.hexToRGBAValues = hexToRGBAValues;
21
+
22
+ var hexToRGBA = function hexToRGBA(hex) {
23
+ var _hexToRGBAValues = hexToRGBAValues(hex),
24
+ r = _hexToRGBAValues.r,
25
+ g = _hexToRGBAValues.g,
26
+ b = _hexToRGBAValues.b,
27
+ a = _hexToRGBAValues.a;
28
+
29
+ return "rgb".concat(a ? 'a' : '', "(").concat(r, ",").concat(g, ",").concat(b).concat(a ? ",".concat(a) : '', ")");
30
+ };
31
+
32
+ exports.hexToRGBA = hexToRGBA;
33
+
34
+ var getLuminance = function getLuminance(_ref) {
35
+ var r = _ref.r,
36
+ g = _ref.g,
37
+ b = _ref.b;
38
+ return (r * 299 + g * 587 + b * 114) / 1000;
39
+ };
40
+ /**
41
+ * Returns an accessible hard-coded text color based on the color contrast with
42
+ * the background.
43
+ *
44
+ * @param hex - The Hex color code of the background
45
+ * @param [opts.hardcodedSurface] - If set, a design token will be returned instead
46
+ * of a hard-coded color. This is to support more transparent backgrounds
47
+ * to allow the text to invert colors depending on the current theme's surface color.
48
+ */
49
+
50
+
51
+ exports.getLuminance = getLuminance;
52
+
53
+ var getTextColorForBackground = function getTextColorForBackground(hex, opts) {
54
+ var _hexToRGBAValues2 = hexToRGBAValues(hex),
55
+ r = _hexToRGBAValues2.r,
56
+ g = _hexToRGBAValues2.g,
57
+ b = _hexToRGBAValues2.b,
58
+ a = _hexToRGBAValues2.a;
59
+
60
+ var lum = getLuminance({
61
+ r: r,
62
+ g: g,
63
+ b: b
64
+ });
65
+ var alphaLimit = 0.42;
66
+ var alphaConditionsPerSurface = {
67
+ light: a < alphaLimit,
68
+ dark: a > alphaLimit
69
+ };
70
+ var alphaLimitExceeded = (opts === null || opts === void 0 ? void 0 : opts.hardcodedSurface) && alphaConditionsPerSurface[opts.hardcodedSurface];
71
+
72
+ if (!(opts !== null && opts !== void 0 && opts.hardcodedSurface) && a < alphaLimit) {
73
+ // This color is transparent, so the text will mainly cast onto the surface behind.
74
+ // Needs to use tokens otherwise Dark mode would cause black text on black surface
75
+ return (0, _index.token)('color.text', 'black');
76
+ }
77
+
78
+ return lum > 150 && !a || a && alphaLimitExceeded ? 'black' : 'white';
79
+ };
80
+ /**
81
+ * Returns a border if determined to be required based on the color contrast with
82
+ * the background.
83
+ *
84
+ * @param hex - The Hex color code of the background
85
+ */
86
+
87
+
88
+ exports.getTextColorForBackground = getTextColorForBackground;
89
+
90
+ var getBorderForBackground = function getBorderForBackground(hex) {
91
+ var _hexToRGBAValues3 = hexToRGBAValues(hex),
92
+ r = _hexToRGBAValues3.r,
93
+ g = _hexToRGBAValues3.g,
94
+ b = _hexToRGBAValues3.b,
95
+ a = _hexToRGBAValues3.a;
96
+
97
+ var lum = getLuminance({
98
+ r: r,
99
+ g: g,
100
+ b: b
101
+ });
102
+ return lum > 240 || a < 0.2 ? "1px solid ".concat((0, _index.token)('color.border', '#091E4224')) : undefined;
103
+ };
104
+ /**
105
+ * Returns a box shadow formatted for CSS from a ShadowToken raw value.
106
+ *
107
+ * @param rawShadow - ShadowToken raw value
108
+ */
109
+
110
+
111
+ exports.getBorderForBackground = getBorderForBackground;
112
+
113
+ var getBoxShadow = function getBoxShadow(rawShadow) {
114
+ return rawShadow.map(function (_ref2) {
115
+ var radius = _ref2.radius,
116
+ offset = _ref2.offset,
117
+ color = _ref2.color,
118
+ opacity = _ref2.opacity;
119
+
120
+ var _hexToRGBAValues4 = hexToRGBAValues(color),
121
+ r = _hexToRGBAValues4.r,
122
+ g = _hexToRGBAValues4.g,
123
+ b = _hexToRGBAValues4.b;
124
+
125
+ return "".concat(offset.x, "px ").concat(offset.y, "px ").concat(radius, "px rgba(").concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(opacity, ")");
126
+ }).join(',');
127
+ };
128
+
129
+ exports.getBoxShadow = getBoxShadow;
@@ -9,7 +9,7 @@ exports.getTokenId = exports.getFullyQualifiedTokenId = exports.getCSSCustomProp
9
9
 
10
10
  var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
11
11
 
12
- var _constants = require("./constants");
12
+ var _constants = require("../constants");
13
13
 
14
14
  /**
15
15
  * Transforms a style dictionary token path to a CSS custom property.
@@ -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
  ]