@atlaskit/tokens 1.14.0 → 1.14.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 (44) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/cjs/artifacts/token-default-values.js +4 -1
  3. package/dist/cjs/babel-plugin/plugin.js +34 -3
  4. package/dist/cjs/constants.js +1 -3
  5. package/dist/cjs/custom-theme.js +1 -1
  6. package/dist/cjs/get-token-value.js +1 -1
  7. package/dist/cjs/get-token.js +1 -1
  8. package/dist/cjs/utils/custom-theme-loading-utils.js +1 -1
  9. package/dist/cjs/utils/custom-theme-token-contrast-check.js +15 -3
  10. package/dist/cjs/utils/generate-custom-color-ramp.js +30 -10
  11. package/dist/es2019/artifacts/token-default-values.js +4 -1
  12. package/dist/es2019/babel-plugin/plugin.js +34 -4
  13. package/dist/es2019/constants.js +0 -1
  14. package/dist/es2019/custom-theme.js +1 -1
  15. package/dist/es2019/get-token-value.js +1 -1
  16. package/dist/es2019/get-token.js +1 -1
  17. package/dist/es2019/utils/custom-theme-loading-utils.js +1 -1
  18. package/dist/es2019/utils/custom-theme-token-contrast-check.js +15 -3
  19. package/dist/es2019/utils/generate-custom-color-ramp.js +31 -10
  20. package/dist/esm/artifacts/token-default-values.js +4 -1
  21. package/dist/esm/babel-plugin/plugin.js +34 -3
  22. package/dist/esm/constants.js +0 -1
  23. package/dist/esm/custom-theme.js +1 -1
  24. package/dist/esm/get-token-value.js +1 -1
  25. package/dist/esm/get-token.js +1 -1
  26. package/dist/esm/utils/custom-theme-loading-utils.js +1 -1
  27. package/dist/esm/utils/custom-theme-token-contrast-check.js +15 -3
  28. package/dist/esm/utils/generate-custom-color-ramp.js +30 -10
  29. package/dist/types/artifacts/token-default-values.d.ts +4 -1
  30. package/dist/types/babel-plugin/plugin.d.ts +3 -0
  31. package/dist/types/constants.d.ts +0 -1
  32. package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -1
  33. package/dist/types/utils/custom-theme-token-contrast-check.d.ts +1 -1
  34. package/dist/types/utils/generate-custom-color-ramp.d.ts +5 -2
  35. package/dist/types-ts4.5/artifacts/token-default-values.d.ts +4 -1
  36. package/dist/types-ts4.5/babel-plugin/plugin.d.ts +3 -0
  37. package/dist/types-ts4.5/constants.d.ts +0 -1
  38. package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -1
  39. package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +1 -1
  40. package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +5 -2
  41. package/package.json +1 -1
  42. package/dist/cjs/version.json +0 -7
  43. package/dist/es2019/version.json +0 -7
  44. package/dist/esm/version.json +0 -7
package/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  # @atlaskit/tokens
2
2
 
3
+ ## 1.14.2
4
+
5
+ ### Patch Changes
6
+
7
+ - [`8e1667c2c03`](https://bitbucket.org/atlassian/atlassian-frontend/commits/8e1667c2c03) - Adds the ability to specify a fallback theme in the tokens Babel plugin via the `defaultTheme` option. Also adds 'legacy-light' as one of the available themes, while keeping 'light' as the default if nothing is provided.
8
+
9
+ ## 1.14.1
10
+
11
+ ### Patch Changes
12
+
13
+ - [`b423f118bb8`](https://bitbucket.org/atlassian/atlassian-frontend/commits/b423f118bb8) - Adjusted color generation system for custom theming to improve accessibility.
14
+
3
15
  ## 1.14.0
4
16
 
5
17
  ### Minor Changes
@@ -7,10 +7,13 @@ exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
9
  *
10
+ * DEPRECATED, PLEASE DO NOT USE.
11
+ * Default values can now be based on either light or legacy-light themes, whereas this only contains light theme values.
12
+ *
10
13
  * Token names mapped to their value in the default Atlassian themes ('light').
11
14
  * These default values are used by the Babel plugin to optionally provide automatic fallbacks.
12
15
  *
13
- * @codegen <<SignedSource::cd2ec139d4552898a3fc16a50aac159c>>
16
+ * @codegen <<SignedSource::b5a6322ad7a59d086ea12e85ec78c8f0>>
14
17
  * @codegenCommand yarn build tokens
15
18
  */
16
19
  var defaultTokenValues = {
@@ -6,11 +6,40 @@ Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
8
  exports.default = plugin;
9
+ var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
9
10
  var t = _interopRequireWildcard(require("@babel/types"));
10
- var _tokenDefaultValues = _interopRequireDefault(require("../artifacts/token-default-values"));
11
11
  var _tokenNames = _interopRequireDefault(require("../artifacts/token-names"));
12
+ var _atlassianLegacyLight = _interopRequireDefault(require("../artifacts/tokens-raw/atlassian-legacy-light"));
13
+ var _atlassianLight = _interopRequireDefault(require("../artifacts/tokens-raw/atlassian-light"));
12
14
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
13
15
  function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
+ 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; }
17
+ 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) { (0, _defineProperty2.default)(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; }
18
+ // Convert raw tokens to key-value pairs { token: value }
19
+ var getThemeValues = function getThemeValues(theme) {
20
+ var tokensToMap = theme === 'light' ? _atlassianLight.default : _atlassianLegacyLight.default;
21
+ return tokensToMap.reduce(function (formatted, rawToken) {
22
+ var value;
23
+ if (typeof rawToken.value === 'string') {
24
+ value = rawToken.value;
25
+ } else if (typeof rawToken.value === 'number') {
26
+ value = rawToken.value.toString();
27
+ } else {
28
+ // If it's a box shadow, it'll be an array of values that needs to be
29
+ // formatted to look like '0px 0px 8px #091e4229, 0px 0px 1px #091e421F'
30
+ value = rawToken.value.reduce(function (prev, curr, index) {
31
+ var value = "".concat(curr.offset.x, "px ").concat(curr.offset.y, "px ").concat(curr.radius, "px ").concat(curr.color);
32
+ if (index === 0) {
33
+ value += ", ";
34
+ }
35
+ return prev + value;
36
+ }, '');
37
+ }
38
+ return _objectSpread(_objectSpread({}, formatted), {}, (0, _defineProperty2.default)({}, rawToken.cleanName, value));
39
+ }, {});
40
+ };
41
+ var lightValues = getThemeValues('light');
42
+ var legacyLightValues = getThemeValues('legacy-light');
14
43
  function plugin() {
15
44
  return {
16
45
  visitor: {
@@ -55,7 +84,7 @@ function plugin() {
55
84
  // if no fallback is set, optionally find one from the default theme
56
85
  if (path.node.arguments.length < 2) {
57
86
  if (state.opts.shouldUseAutoFallback) {
58
- replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ", ").concat(getDefaultFallback(tokenName), ")"));
87
+ replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ", ").concat(getDefaultFallback(tokenName, state.opts.defaultTheme), ")"));
59
88
  } else {
60
89
  replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ")"));
61
90
  }
@@ -120,7 +149,9 @@ function plugin() {
120
149
  };
121
150
  }
122
151
  function getDefaultFallback(tokenName) {
123
- return _tokenDefaultValues.default[tokenName];
152
+ var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'light';
153
+ var tokens = theme === 'legacy-light' ? legacyLightValues : lightValues;
154
+ return tokens[tokenName];
124
155
  }
125
156
  function getNonAliasedImportName(node) {
126
157
  if (t.isIdentifier(node.imported)) {
@@ -3,15 +3,13 @@
3
3
  Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
- exports.TOKEN_NOT_FOUND_CSS_VAR = exports.THEME_DATA_ATTRIBUTE = exports.DEFAULT_THEME = exports.CUSTOM_THEME_ATTRIBUTE = exports.CSS_VAR_FULL = exports.CSS_PREFIX = exports.COLOR_MODE_ATTRIBUTE = void 0;
6
+ exports.TOKEN_NOT_FOUND_CSS_VAR = exports.THEME_DATA_ATTRIBUTE = exports.CUSTOM_THEME_ATTRIBUTE = exports.CSS_VAR_FULL = exports.CSS_PREFIX = exports.COLOR_MODE_ATTRIBUTE = void 0;
7
7
  var THEME_DATA_ATTRIBUTE = 'data-theme';
8
8
  exports.THEME_DATA_ATTRIBUTE = THEME_DATA_ATTRIBUTE;
9
9
  var COLOR_MODE_ATTRIBUTE = 'data-color-mode';
10
10
  exports.COLOR_MODE_ATTRIBUTE = COLOR_MODE_ATTRIBUTE;
11
11
  var CUSTOM_THEME_ATTRIBUTE = 'data-custom-theme';
12
12
  exports.CUSTOM_THEME_ATTRIBUTE = CUSTOM_THEME_ATTRIBUTE;
13
- var DEFAULT_THEME = 'light';
14
- exports.DEFAULT_THEME = DEFAULT_THEME;
15
13
  var CSS_PREFIX = 'ds';
16
14
  exports.CSS_PREFIX = CSS_PREFIX;
17
15
  var CSS_VAR_FULL = ['opacity', 'font', 'space', 'border'];
@@ -47,7 +47,7 @@ function _getCustomThemeStyles() {
47
47
  mode = (themeState === null || themeState === void 0 ? void 0 : themeState.colorMode) || _themeConfig.themeStateDefaults['colorMode'];
48
48
  optionString = JSON.stringify(themeState === null || themeState === void 0 ? void 0 : themeState.UNSAFE_themeOptions);
49
49
  uniqueId = (0, _hash.hash)(optionString);
50
- themeRamp = (0, _generateCustomColorRamp.generateColors)(brandColor); // outputs object to generate to CSS from
50
+ themeRamp = (0, _generateCustomColorRamp.generateColors)(brandColor).ramp; // outputs object to generate to CSS from
51
51
  themes = [];
52
52
  tokenMaps = (0, _generateCustomColorRamp.generateTokenMapWithContrastCheck)(brandColor, mode, themeRamp);
53
53
  if ((mode === 'light' || mode === 'auto') && tokenMaps.light) {
@@ -8,7 +8,7 @@ exports.default = void 0;
8
8
  var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
9
9
  var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
10
10
  var name = "@atlaskit/tokens";
11
- var version = "1.14.0";
11
+ var version = "1.14.2";
12
12
  /**
13
13
  * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
14
14
  * resulting CSS Custom Property.
@@ -9,7 +9,7 @@ var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
9
9
  var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
10
10
  var _constants = require("./constants");
11
11
  var name = "@atlaskit/tokens";
12
- var version = "1.14.0";
12
+ var version = "1.14.2";
13
13
  /**
14
14
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
15
15
  * This should be used to implement design decisions throughout your application.
@@ -42,6 +42,6 @@ function reduceTokenMap(tokenMap, themeRamp) {
42
42
  key = _ref2[0],
43
43
  value = _ref2[1];
44
44
  var cssVar = _tokenNames.default[key];
45
- return cssVar ? "".concat(acc, "\n ").concat(cssVar, ": ").concat(themeRamp[value], ";") : acc;
45
+ return cssVar ? "".concat(acc, "\n ").concat(cssVar, ": ").concat(typeof value === 'string' ? value : themeRamp[value], ";") : acc;
46
46
  }, '');
47
47
  }
@@ -17,6 +17,14 @@ var additionalChecks = [{
17
17
  // In light mode: darken the following tokens by one base token
18
18
  // In dark mode: lighten the following tokens by one base token
19
19
  'color.text.brand', 'color.text.selected', 'color.link', 'color.link.pressed', 'color.icon.brand', 'color.icon.selected']
20
+ }, {
21
+ foreground: 'color.text.brand',
22
+ backgroundLight: 'color.background.selected',
23
+ backgroundDark: 'color.background.selected',
24
+ desiredContrast: 4.5,
25
+ // In light mode: darken the following tokens by one base token
26
+ // In dark mode: lighten the following tokens by one base toke
27
+ updatedTokens: ['color.text.brand', 'color.link', 'color.link.pressed']
20
28
  }, {
21
29
  foreground: 'color.text.selected',
22
30
  backgroundLight: 'color.background.selected',
@@ -59,13 +67,17 @@ var additionalContrastChecker = function additionalContrastChecker(_ref) {
59
67
  desiredContrast = pairing.desiredContrast,
60
68
  updatedTokens = pairing.updatedTokens;
61
69
  var background = mode === 'light' ? backgroundLight : backgroundDark;
62
- var foregroundColor = brandTokens.includes(foreground) ? themeRamp[customThemeTokenMap[foreground]] : getColorFromTokenRaw(foreground, mode);
63
- var backgroundColor = brandTokens.includes(background) ? themeRamp[customThemeTokenMap[background]] : getColorFromTokenRaw(background, mode);
70
+ var foregroundTokenValue = customThemeTokenMap[foreground];
71
+ var backgroundTokenValue = customThemeTokenMap[background];
72
+ var foregroundColor = brandTokens.includes(foreground) ? typeof foregroundTokenValue === 'string' ? foregroundTokenValue : themeRamp[foregroundTokenValue] : getColorFromTokenRaw(foreground, mode);
73
+ var backgroundColor = brandTokens.includes(background) ? typeof backgroundTokenValue === 'string' ? backgroundTokenValue : themeRamp[backgroundTokenValue] : getColorFromTokenRaw(background, mode);
64
74
  var contrast = (0, _colorUtils.getContrastRatio)(foregroundColor, backgroundColor);
65
75
  if (contrast <= desiredContrast) {
66
76
  updatedTokens.forEach(function (token) {
67
77
  var rampValue = customThemeTokenMap[token];
68
- updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
78
+ if (typeof rampValue === 'number') {
79
+ updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
80
+ }
69
81
  });
70
82
  }
71
83
  });
@@ -54,7 +54,11 @@ var generateColors = function generateColors(brandColor) {
54
54
  // Replace closet color with brandColor
55
55
  var updatedThemeRamp = (0, _toConsumableArray2.default)(themeRamp);
56
56
  updatedThemeRamp[closestColorIndex] = brandColor;
57
- return updatedThemeRamp;
57
+ return {
58
+ ramp: updatedThemeRamp,
59
+ // add the replaced color into the result
60
+ replacedColor: themeRamp[closestColorIndex]
61
+ };
58
62
  };
59
63
 
60
64
  /**
@@ -78,7 +82,10 @@ function getInteractionStates(rampPosition, number, colors) {
78
82
  return result;
79
83
  }
80
84
  var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
81
- var colors = themeRamp || generateColors(brandColor);
85
+ var _generateColors = generateColors(brandColor),
86
+ ramp = _generateColors.ramp,
87
+ replacedColor = _generateColors.replacedColor;
88
+ var colors = themeRamp || ramp;
82
89
  var closestColorIndex = getClosestColorIndex(colors, brandColor);
83
90
  var customThemeTokenMapLight = {};
84
91
  var customThemeTokenMapDark = {};
@@ -94,6 +101,12 @@ var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
94
101
  _getInteractionStates2 = (0, _slicedToArray2.default)(_getInteractionStates, 2),
95
102
  brandBoldSelectedHoveredIndex = _getInteractionStates2[0],
96
103
  brandBoldSelectedPressedIndex = _getInteractionStates2[1];
104
+ var brandTextIndex = closestColorIndex;
105
+ if (inputContrast < 5.4 && inputContrast >= 4.8 && closestColorIndex === 6) {
106
+ // Use the one-level darker closest color (X800) for color.text.brand
107
+ // and color.link to avoid contrast breaches
108
+ brandTextIndex = closestColorIndex + 1;
109
+ }
97
110
 
98
111
  /**
99
112
  * Generate interaction token for color.link:
@@ -103,11 +116,11 @@ var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
103
116
  * If inputted color replaces X700-X900
104
117
  * - Shift one 1 step darker
105
118
  */
106
- var _getInteractionStates3 = getInteractionStates(closestColorIndex, 1, colors),
119
+ var _getInteractionStates3 = getInteractionStates(brandTextIndex, 1, colors),
107
120
  _getInteractionStates4 = (0, _slicedToArray2.default)(_getInteractionStates3, 1),
108
121
  linkPressed = _getInteractionStates4[0];
109
122
  customThemeTokenMapLight = {
110
- 'color.text.brand': closestColorIndex,
123
+ 'color.text.brand': brandTextIndex,
111
124
  'color.icon.brand': closestColorIndex,
112
125
  'color.background.brand.subtlest': 0,
113
126
  'color.background.brand.subtlest.hovered': 1,
@@ -119,13 +132,13 @@ var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
119
132
  'color.background.brand.boldest.hovered': 8,
120
133
  'color.background.brand.boldest.pressed': 7,
121
134
  'color.border.brand': closestColorIndex,
122
- 'color.text.selected': closestColorIndex,
135
+ 'color.text.selected': brandTextIndex,
123
136
  'color.icon.selected': closestColorIndex,
124
137
  'color.background.selected.bold': closestColorIndex,
125
138
  'color.background.selected.bold.hovered': brandBoldSelectedHoveredIndex,
126
139
  'color.background.selected.bold.pressed': brandBoldSelectedPressedIndex,
127
140
  'color.border.selected': closestColorIndex,
128
- 'color.link': closestColorIndex,
141
+ 'color.link': brandTextIndex,
129
142
  'color.link.pressed': linkPressed,
130
143
  'color.chart.brand': 5,
131
144
  'color.chart.brand.hovered': 6,
@@ -134,18 +147,25 @@ var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
134
147
  'color.background.selected.pressed': 2
135
148
  };
136
149
  } else {
150
+ var brandBackgroundIndex = 6;
151
+ if (inputContrast < 4.5 && inputContrast >= 4 && closestColorIndex === 6) {
152
+ // Use the generated closest color instead of the input brand color for
153
+ // color.background.selected.bold and color.background.brand.bold
154
+ // to avoid contrast breaches
155
+ brandBackgroundIndex = replacedColor;
156
+ }
137
157
  customThemeTokenMapLight = {
138
158
  'color.background.brand.subtlest': 0,
139
159
  'color.background.brand.subtlest.hovered': 1,
140
160
  'color.background.brand.subtlest.pressed': 2,
141
- 'color.background.brand.bold': 6,
161
+ 'color.background.brand.bold': brandBackgroundIndex,
142
162
  'color.background.brand.bold.hovered': 7,
143
163
  'color.background.brand.bold.pressed': 8,
144
164
  'color.background.brand.boldest': 9,
145
165
  'color.background.brand.boldest.hovered': 8,
146
166
  'color.background.brand.boldest.pressed': 7,
147
167
  'color.border.brand': 6,
148
- 'color.background.selected.bold': 6,
168
+ 'color.background.selected.bold': brandBackgroundIndex,
149
169
  'color.background.selected.bold.hovered': 7,
150
170
  'color.background.selected.bold.pressed': 8,
151
171
  'color.text.brand': 6,
@@ -175,7 +195,7 @@ var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
175
195
  var _ref2 = (0, _slicedToArray2.default)(_ref, 2),
176
196
  key = _ref2[0],
177
197
  value = _ref2[1];
178
- customThemeTokenMapDark[key] = 9 - value;
198
+ customThemeTokenMapDark[key] = 9 - (typeof value === 'string' ? closestColorIndex : value);
179
199
  });
180
200
 
181
201
  /**
@@ -202,7 +222,7 @@ var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
202
222
  };
203
223
  exports.generateTokenMap = generateTokenMap;
204
224
  var generateTokenMapWithContrastCheck = function generateTokenMapWithContrastCheck(brandColor, mode, themeRamp) {
205
- var colors = themeRamp || generateColors(brandColor);
225
+ var colors = themeRamp || generateColors(brandColor).ramp;
206
226
  var tokenMaps = generateTokenMap(brandColor, mode, colors);
207
227
  var result = {};
208
228
  Object.entries(tokenMaps).forEach(function (_ref3) {
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
3
  *
4
+ * DEPRECATED, PLEASE DO NOT USE.
5
+ * Default values can now be based on either light or legacy-light themes, whereas this only contains light theme values.
6
+ *
4
7
  * Token names mapped to their value in the default Atlassian themes ('light').
5
8
  * These default values are used by the Babel plugin to optionally provide automatic fallbacks.
6
9
  *
7
- * @codegen <<SignedSource::cd2ec139d4552898a3fc16a50aac159c>>
10
+ * @codegen <<SignedSource::b5a6322ad7a59d086ea12e85ec78c8f0>>
8
11
  * @codegenCommand yarn build tokens
9
12
  */
10
13
  const defaultTokenValues = {
@@ -1,6 +1,35 @@
1
1
  import * as t from '@babel/types';
2
- import tokenDefaultValues from '../artifacts/token-default-values';
3
2
  import tokenNames from '../artifacts/token-names';
3
+ import legacyLight from '../artifacts/tokens-raw/atlassian-legacy-light';
4
+ import light from '../artifacts/tokens-raw/atlassian-light';
5
+ // Convert raw tokens to key-value pairs { token: value }
6
+ const getThemeValues = theme => {
7
+ const tokensToMap = theme === 'light' ? light : legacyLight;
8
+ return tokensToMap.reduce((formatted, rawToken) => {
9
+ let value;
10
+ if (typeof rawToken.value === 'string') {
11
+ value = rawToken.value;
12
+ } else if (typeof rawToken.value === 'number') {
13
+ value = rawToken.value.toString();
14
+ } else {
15
+ // If it's a box shadow, it'll be an array of values that needs to be
16
+ // formatted to look like '0px 0px 8px #091e4229, 0px 0px 1px #091e421F'
17
+ value = rawToken.value.reduce((prev, curr, index) => {
18
+ let value = `${curr.offset.x}px ${curr.offset.y}px ${curr.radius}px ${curr.color}`;
19
+ if (index === 0) {
20
+ value += `, `;
21
+ }
22
+ return prev + value;
23
+ }, '');
24
+ }
25
+ return {
26
+ ...formatted,
27
+ [rawToken.cleanName]: value
28
+ };
29
+ }, {});
30
+ };
31
+ const lightValues = getThemeValues('light');
32
+ const legacyLightValues = getThemeValues('legacy-light');
4
33
  export default function plugin() {
5
34
  return {
6
35
  visitor: {
@@ -37,7 +66,7 @@ export default function plugin() {
37
66
  // if no fallback is set, optionally find one from the default theme
38
67
  if (path.node.arguments.length < 2) {
39
68
  if (state.opts.shouldUseAutoFallback) {
40
- replacementNode = t.stringLiteral(`var(${cssTokenValue}, ${getDefaultFallback(tokenName)})`);
69
+ replacementNode = t.stringLiteral(`var(${cssTokenValue}, ${getDefaultFallback(tokenName, state.opts.defaultTheme)})`);
41
70
  } else {
42
71
  replacementNode = t.stringLiteral(`var(${cssTokenValue})`);
43
72
  }
@@ -101,8 +130,9 @@ export default function plugin() {
101
130
  }
102
131
  };
103
132
  }
104
- function getDefaultFallback(tokenName) {
105
- return tokenDefaultValues[tokenName];
133
+ function getDefaultFallback(tokenName, theme = 'light') {
134
+ const tokens = theme === 'legacy-light' ? legacyLightValues : lightValues;
135
+ return tokens[tokenName];
106
136
  }
107
137
  function getNonAliasedImportName(node) {
108
138
  if (t.isIdentifier(node.imported)) {
@@ -1,7 +1,6 @@
1
1
  export const THEME_DATA_ATTRIBUTE = 'data-theme';
2
2
  export const COLOR_MODE_ATTRIBUTE = 'data-color-mode';
3
3
  export const CUSTOM_THEME_ATTRIBUTE = 'data-custom-theme';
4
- export const DEFAULT_THEME = 'light';
5
4
  export const CSS_PREFIX = 'ds';
6
5
  export const CSS_VAR_FULL = ['opacity', 'font', 'space', 'border'];
7
6
  export const TOKEN_NOT_FOUND_CSS_VAR = `--${CSS_PREFIX}-token-not-found`;
@@ -27,7 +27,7 @@ export async function getCustomThemeStyles(themeState) {
27
27
  const mode = (themeState === null || themeState === void 0 ? void 0 : themeState.colorMode) || themeStateDefaults['colorMode'];
28
28
  const optionString = JSON.stringify(themeState === null || themeState === void 0 ? void 0 : themeState.UNSAFE_themeOptions);
29
29
  const uniqueId = hash(optionString);
30
- const themeRamp = generateColors(brandColor);
30
+ const themeRamp = generateColors(brandColor).ramp;
31
31
 
32
32
  // outputs object to generate to CSS from
33
33
  const themes = [];
@@ -1,7 +1,7 @@
1
1
  import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  const name = "@atlaskit/tokens";
4
- const version = "1.14.0";
4
+ const version = "1.14.2";
5
5
  /**
6
6
  * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
7
7
  * resulting CSS Custom Property.
@@ -2,7 +2,7 @@ import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  import { TOKEN_NOT_FOUND_CSS_VAR } from './constants';
4
4
  const name = "@atlaskit/tokens";
5
- const version = "1.14.0";
5
+ const version = "1.14.2";
6
6
  /**
7
7
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
8
8
  * This should be used to implement design decisions throughout your application.
@@ -26,6 +26,6 @@ export function limitSizeOfCustomStyleElements(sizeThreshold) {
26
26
  export function reduceTokenMap(tokenMap, themeRamp) {
27
27
  return Object.entries(tokenMap).reduce((acc, [key, value]) => {
28
28
  const cssVar = tokens[key];
29
- return cssVar ? `${acc}\n ${cssVar}: ${themeRamp[value]};` : acc;
29
+ return cssVar ? `${acc}\n ${cssVar}: ${typeof value === 'string' ? value : themeRamp[value]};` : acc;
30
30
  }, '');
31
31
  }
@@ -10,6 +10,14 @@ export const additionalChecks = [{
10
10
  // In light mode: darken the following tokens by one base token
11
11
  // In dark mode: lighten the following tokens by one base token
12
12
  'color.text.brand', 'color.text.selected', 'color.link', 'color.link.pressed', 'color.icon.brand', 'color.icon.selected']
13
+ }, {
14
+ foreground: 'color.text.brand',
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 toke
20
+ updatedTokens: ['color.text.brand', 'color.link', 'color.link.pressed']
13
21
  }, {
14
22
  foreground: 'color.text.selected',
15
23
  backgroundLight: 'color.background.selected',
@@ -54,13 +62,17 @@ export const additionalContrastChecker = ({
54
62
  updatedTokens
55
63
  } = pairing;
56
64
  const background = mode === 'light' ? backgroundLight : backgroundDark;
57
- const foregroundColor = brandTokens.includes(foreground) ? themeRamp[customThemeTokenMap[foreground]] : getColorFromTokenRaw(foreground, mode);
58
- const backgroundColor = brandTokens.includes(background) ? themeRamp[customThemeTokenMap[background]] : getColorFromTokenRaw(background, mode);
65
+ const foregroundTokenValue = customThemeTokenMap[foreground];
66
+ const backgroundTokenValue = customThemeTokenMap[background];
67
+ const foregroundColor = brandTokens.includes(foreground) ? typeof foregroundTokenValue === 'string' ? foregroundTokenValue : themeRamp[foregroundTokenValue] : getColorFromTokenRaw(foreground, mode);
68
+ const backgroundColor = brandTokens.includes(background) ? typeof backgroundTokenValue === 'string' ? backgroundTokenValue : themeRamp[backgroundTokenValue] : getColorFromTokenRaw(background, mode);
59
69
  const contrast = getContrastRatio(foregroundColor, backgroundColor);
60
70
  if (contrast <= desiredContrast) {
61
71
  updatedTokens.forEach(token => {
62
72
  const rampValue = customThemeTokenMap[token];
63
- updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
73
+ if (typeof rampValue === 'number') {
74
+ updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
75
+ }
64
76
  });
65
77
  }
66
78
  });
@@ -41,7 +41,11 @@ export const generateColors = brandColor => {
41
41
  // Replace closet color with brandColor
42
42
  const updatedThemeRamp = [...themeRamp];
43
43
  updatedThemeRamp[closestColorIndex] = brandColor;
44
- return updatedThemeRamp;
44
+ return {
45
+ ramp: updatedThemeRamp,
46
+ // add the replaced color into the result
47
+ replacedColor: themeRamp[closestColorIndex]
48
+ };
45
49
  };
46
50
 
47
51
  /**
@@ -64,7 +68,11 @@ function getInteractionStates(rampPosition, number, colors) {
64
68
  return result;
65
69
  }
66
70
  export const generateTokenMap = (brandColor, mode, themeRamp) => {
67
- const colors = themeRamp || generateColors(brandColor);
71
+ const {
72
+ ramp,
73
+ replacedColor
74
+ } = generateColors(brandColor);
75
+ const colors = themeRamp || ramp;
68
76
  const closestColorIndex = getClosestColorIndex(colors, brandColor);
69
77
  let customThemeTokenMapLight = {};
70
78
  let customThemeTokenMapDark = {};
@@ -77,6 +85,12 @@ export const generateTokenMap = (brandColor, mode, themeRamp) => {
77
85
  * - color.background.selected.bold
78
86
  */
79
87
  const [brandBoldSelectedHoveredIndex, brandBoldSelectedPressedIndex] = getInteractionStates(closestColorIndex, 2, colors);
88
+ let brandTextIndex = closestColorIndex;
89
+ if (inputContrast < 5.4 && inputContrast >= 4.8 && closestColorIndex === 6) {
90
+ // Use the one-level darker closest color (X800) for color.text.brand
91
+ // and color.link to avoid contrast breaches
92
+ brandTextIndex = closestColorIndex + 1;
93
+ }
80
94
 
81
95
  /**
82
96
  * Generate interaction token for color.link:
@@ -86,9 +100,9 @@ export const generateTokenMap = (brandColor, mode, themeRamp) => {
86
100
  * If inputted color replaces X700-X900
87
101
  * - Shift one 1 step darker
88
102
  */
89
- const [linkPressed] = getInteractionStates(closestColorIndex, 1, colors);
103
+ const [linkPressed] = getInteractionStates(brandTextIndex, 1, colors);
90
104
  customThemeTokenMapLight = {
91
- 'color.text.brand': closestColorIndex,
105
+ 'color.text.brand': brandTextIndex,
92
106
  'color.icon.brand': closestColorIndex,
93
107
  'color.background.brand.subtlest': 0,
94
108
  'color.background.brand.subtlest.hovered': 1,
@@ -100,13 +114,13 @@ export const generateTokenMap = (brandColor, mode, themeRamp) => {
100
114
  'color.background.brand.boldest.hovered': 8,
101
115
  'color.background.brand.boldest.pressed': 7,
102
116
  'color.border.brand': closestColorIndex,
103
- 'color.text.selected': closestColorIndex,
117
+ 'color.text.selected': brandTextIndex,
104
118
  'color.icon.selected': closestColorIndex,
105
119
  'color.background.selected.bold': closestColorIndex,
106
120
  'color.background.selected.bold.hovered': brandBoldSelectedHoveredIndex,
107
121
  'color.background.selected.bold.pressed': brandBoldSelectedPressedIndex,
108
122
  'color.border.selected': closestColorIndex,
109
- 'color.link': closestColorIndex,
123
+ 'color.link': brandTextIndex,
110
124
  'color.link.pressed': linkPressed,
111
125
  'color.chart.brand': 5,
112
126
  'color.chart.brand.hovered': 6,
@@ -115,18 +129,25 @@ export const generateTokenMap = (brandColor, mode, themeRamp) => {
115
129
  'color.background.selected.pressed': 2
116
130
  };
117
131
  } else {
132
+ let brandBackgroundIndex = 6;
133
+ if (inputContrast < 4.5 && inputContrast >= 4 && closestColorIndex === 6) {
134
+ // Use the generated closest color instead of the input brand color for
135
+ // color.background.selected.bold and color.background.brand.bold
136
+ // to avoid contrast breaches
137
+ brandBackgroundIndex = replacedColor;
138
+ }
118
139
  customThemeTokenMapLight = {
119
140
  'color.background.brand.subtlest': 0,
120
141
  'color.background.brand.subtlest.hovered': 1,
121
142
  'color.background.brand.subtlest.pressed': 2,
122
- 'color.background.brand.bold': 6,
143
+ 'color.background.brand.bold': brandBackgroundIndex,
123
144
  'color.background.brand.bold.hovered': 7,
124
145
  'color.background.brand.bold.pressed': 8,
125
146
  'color.background.brand.boldest': 9,
126
147
  'color.background.brand.boldest.hovered': 8,
127
148
  'color.background.brand.boldest.pressed': 7,
128
149
  'color.border.brand': 6,
129
- 'color.background.selected.bold': 6,
150
+ 'color.background.selected.bold': brandBackgroundIndex,
130
151
  'color.background.selected.bold.hovered': 7,
131
152
  'color.background.selected.bold.pressed': 8,
132
153
  'color.text.brand': 6,
@@ -153,7 +174,7 @@ export const generateTokenMap = (brandColor, mode, themeRamp) => {
153
174
  * Generate dark mode values using rule of symmetry
154
175
  */
155
176
  Object.entries(customThemeTokenMapLight).forEach(([key, value]) => {
156
- customThemeTokenMapDark[key] = 9 - value;
177
+ customThemeTokenMapDark[key] = 9 - (typeof value === 'string' ? closestColorIndex : value);
157
178
  });
158
179
 
159
180
  /**
@@ -179,7 +200,7 @@ export const generateTokenMap = (brandColor, mode, themeRamp) => {
179
200
  };
180
201
  };
181
202
  export const generateTokenMapWithContrastCheck = (brandColor, mode, themeRamp) => {
182
- const colors = themeRamp || generateColors(brandColor);
203
+ const colors = themeRamp || generateColors(brandColor).ramp;
183
204
  const tokenMaps = generateTokenMap(brandColor, mode, colors);
184
205
  const result = {};
185
206
  Object.entries(tokenMaps).forEach(([mode, map]) => {
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
3
  *
4
+ * DEPRECATED, PLEASE DO NOT USE.
5
+ * Default values can now be based on either light or legacy-light themes, whereas this only contains light theme values.
6
+ *
4
7
  * Token names mapped to their value in the default Atlassian themes ('light').
5
8
  * These default values are used by the Babel plugin to optionally provide automatic fallbacks.
6
9
  *
7
- * @codegen <<SignedSource::cd2ec139d4552898a3fc16a50aac159c>>
10
+ * @codegen <<SignedSource::b5a6322ad7a59d086ea12e85ec78c8f0>>
8
11
  * @codegenCommand yarn build tokens
9
12
  */
10
13
  var defaultTokenValues = {
@@ -1,6 +1,35 @@
1
+ import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
+ 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; }
3
+ 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; }
1
4
  import * as t from '@babel/types';
2
- import tokenDefaultValues from '../artifacts/token-default-values';
3
5
  import tokenNames from '../artifacts/token-names';
6
+ import legacyLight from '../artifacts/tokens-raw/atlassian-legacy-light';
7
+ import light from '../artifacts/tokens-raw/atlassian-light';
8
+ // Convert raw tokens to key-value pairs { token: value }
9
+ var getThemeValues = function getThemeValues(theme) {
10
+ var tokensToMap = theme === 'light' ? light : legacyLight;
11
+ return tokensToMap.reduce(function (formatted, rawToken) {
12
+ var value;
13
+ if (typeof rawToken.value === 'string') {
14
+ value = rawToken.value;
15
+ } else if (typeof rawToken.value === 'number') {
16
+ value = rawToken.value.toString();
17
+ } else {
18
+ // If it's a box shadow, it'll be an array of values that needs to be
19
+ // formatted to look like '0px 0px 8px #091e4229, 0px 0px 1px #091e421F'
20
+ value = rawToken.value.reduce(function (prev, curr, index) {
21
+ var value = "".concat(curr.offset.x, "px ").concat(curr.offset.y, "px ").concat(curr.radius, "px ").concat(curr.color);
22
+ if (index === 0) {
23
+ value += ", ";
24
+ }
25
+ return prev + value;
26
+ }, '');
27
+ }
28
+ return _objectSpread(_objectSpread({}, formatted), {}, _defineProperty({}, rawToken.cleanName, value));
29
+ }, {});
30
+ };
31
+ var lightValues = getThemeValues('light');
32
+ var legacyLightValues = getThemeValues('legacy-light');
4
33
  export default function plugin() {
5
34
  return {
6
35
  visitor: {
@@ -45,7 +74,7 @@ export default function plugin() {
45
74
  // if no fallback is set, optionally find one from the default theme
46
75
  if (path.node.arguments.length < 2) {
47
76
  if (state.opts.shouldUseAutoFallback) {
48
- replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ", ").concat(getDefaultFallback(tokenName), ")"));
77
+ replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ", ").concat(getDefaultFallback(tokenName, state.opts.defaultTheme), ")"));
49
78
  } else {
50
79
  replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ")"));
51
80
  }
@@ -110,7 +139,9 @@ export default function plugin() {
110
139
  };
111
140
  }
112
141
  function getDefaultFallback(tokenName) {
113
- return tokenDefaultValues[tokenName];
142
+ var theme = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : 'light';
143
+ var tokens = theme === 'legacy-light' ? legacyLightValues : lightValues;
144
+ return tokens[tokenName];
114
145
  }
115
146
  function getNonAliasedImportName(node) {
116
147
  if (t.isIdentifier(node.imported)) {
@@ -1,7 +1,6 @@
1
1
  export var THEME_DATA_ATTRIBUTE = 'data-theme';
2
2
  export var COLOR_MODE_ATTRIBUTE = 'data-color-mode';
3
3
  export var CUSTOM_THEME_ATTRIBUTE = 'data-custom-theme';
4
- export var DEFAULT_THEME = 'light';
5
4
  export var CSS_PREFIX = 'ds';
6
5
  export var CSS_VAR_FULL = ['opacity', 'font', 'space', 'border'];
7
6
  export var TOKEN_NOT_FOUND_CSS_VAR = "--".concat(CSS_PREFIX, "-token-not-found");
@@ -37,7 +37,7 @@ function _getCustomThemeStyles() {
37
37
  mode = (themeState === null || themeState === void 0 ? void 0 : themeState.colorMode) || themeStateDefaults['colorMode'];
38
38
  optionString = JSON.stringify(themeState === null || themeState === void 0 ? void 0 : themeState.UNSAFE_themeOptions);
39
39
  uniqueId = hash(optionString);
40
- themeRamp = generateColors(brandColor); // outputs object to generate to CSS from
40
+ themeRamp = generateColors(brandColor).ramp; // outputs object to generate to CSS from
41
41
  themes = [];
42
42
  tokenMaps = generateTokenMapWithContrastCheck(brandColor, mode, themeRamp);
43
43
  if ((mode === 'light' || mode === 'auto') && tokenMaps.light) {
@@ -1,7 +1,7 @@
1
1
  import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  var name = "@atlaskit/tokens";
4
- var version = "1.14.0";
4
+ var version = "1.14.2";
5
5
  /**
6
6
  * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
7
7
  * resulting CSS Custom Property.
@@ -2,7 +2,7 @@ import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  import { TOKEN_NOT_FOUND_CSS_VAR } from './constants';
4
4
  var name = "@atlaskit/tokens";
5
- var version = "1.14.0";
5
+ var version = "1.14.2";
6
6
  /**
7
7
  * Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
8
8
  * This should be used to implement design decisions throughout your application.
@@ -33,6 +33,6 @@ export function reduceTokenMap(tokenMap, themeRamp) {
33
33
  key = _ref2[0],
34
34
  value = _ref2[1];
35
35
  var cssVar = tokens[key];
36
- return cssVar ? "".concat(acc, "\n ").concat(cssVar, ": ").concat(themeRamp[value], ";") : acc;
36
+ return cssVar ? "".concat(acc, "\n ").concat(cssVar, ": ").concat(typeof value === 'string' ? value : themeRamp[value], ";") : acc;
37
37
  }, '');
38
38
  }
@@ -10,6 +10,14 @@ export var additionalChecks = [{
10
10
  // In light mode: darken the following tokens by one base token
11
11
  // In dark mode: lighten the following tokens by one base token
12
12
  'color.text.brand', 'color.text.selected', 'color.link', 'color.link.pressed', 'color.icon.brand', 'color.icon.selected']
13
+ }, {
14
+ foreground: 'color.text.brand',
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 toke
20
+ updatedTokens: ['color.text.brand', 'color.link', 'color.link.pressed']
13
21
  }, {
14
22
  foreground: 'color.text.selected',
15
23
  backgroundLight: 'color.background.selected',
@@ -51,13 +59,17 @@ export var additionalContrastChecker = function additionalContrastChecker(_ref)
51
59
  desiredContrast = pairing.desiredContrast,
52
60
  updatedTokens = pairing.updatedTokens;
53
61
  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);
62
+ var foregroundTokenValue = customThemeTokenMap[foreground];
63
+ var backgroundTokenValue = customThemeTokenMap[background];
64
+ var foregroundColor = brandTokens.includes(foreground) ? typeof foregroundTokenValue === 'string' ? foregroundTokenValue : themeRamp[foregroundTokenValue] : getColorFromTokenRaw(foreground, mode);
65
+ var backgroundColor = brandTokens.includes(background) ? typeof backgroundTokenValue === 'string' ? backgroundTokenValue : themeRamp[backgroundTokenValue] : getColorFromTokenRaw(background, mode);
56
66
  var contrast = getContrastRatio(foregroundColor, backgroundColor);
57
67
  if (contrast <= desiredContrast) {
58
68
  updatedTokens.forEach(function (token) {
59
69
  var rampValue = customThemeTokenMap[token];
60
- updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
70
+ if (typeof rampValue === 'number') {
71
+ updatedCustomThemeTokenMap[token] = mode === 'light' ? rampValue + 1 : rampValue - 1;
72
+ }
61
73
  });
62
74
  }
63
75
  });
@@ -46,7 +46,11 @@ export var generateColors = function generateColors(brandColor) {
46
46
  // Replace closet color with brandColor
47
47
  var updatedThemeRamp = _toConsumableArray(themeRamp);
48
48
  updatedThemeRamp[closestColorIndex] = brandColor;
49
- return updatedThemeRamp;
49
+ return {
50
+ ramp: updatedThemeRamp,
51
+ // add the replaced color into the result
52
+ replacedColor: themeRamp[closestColorIndex]
53
+ };
50
54
  };
51
55
 
52
56
  /**
@@ -69,7 +73,10 @@ function getInteractionStates(rampPosition, number, colors) {
69
73
  return result;
70
74
  }
71
75
  export var generateTokenMap = function generateTokenMap(brandColor, mode, themeRamp) {
72
- var colors = themeRamp || generateColors(brandColor);
76
+ var _generateColors = generateColors(brandColor),
77
+ ramp = _generateColors.ramp,
78
+ replacedColor = _generateColors.replacedColor;
79
+ var colors = themeRamp || ramp;
73
80
  var closestColorIndex = getClosestColorIndex(colors, brandColor);
74
81
  var customThemeTokenMapLight = {};
75
82
  var customThemeTokenMapDark = {};
@@ -85,6 +92,12 @@ export var generateTokenMap = function generateTokenMap(brandColor, mode, themeR
85
92
  _getInteractionStates2 = _slicedToArray(_getInteractionStates, 2),
86
93
  brandBoldSelectedHoveredIndex = _getInteractionStates2[0],
87
94
  brandBoldSelectedPressedIndex = _getInteractionStates2[1];
95
+ var brandTextIndex = closestColorIndex;
96
+ if (inputContrast < 5.4 && inputContrast >= 4.8 && closestColorIndex === 6) {
97
+ // Use the one-level darker closest color (X800) for color.text.brand
98
+ // and color.link to avoid contrast breaches
99
+ brandTextIndex = closestColorIndex + 1;
100
+ }
88
101
 
89
102
  /**
90
103
  * Generate interaction token for color.link:
@@ -94,11 +107,11 @@ export var generateTokenMap = function generateTokenMap(brandColor, mode, themeR
94
107
  * If inputted color replaces X700-X900
95
108
  * - Shift one 1 step darker
96
109
  */
97
- var _getInteractionStates3 = getInteractionStates(closestColorIndex, 1, colors),
110
+ var _getInteractionStates3 = getInteractionStates(brandTextIndex, 1, colors),
98
111
  _getInteractionStates4 = _slicedToArray(_getInteractionStates3, 1),
99
112
  linkPressed = _getInteractionStates4[0];
100
113
  customThemeTokenMapLight = {
101
- 'color.text.brand': closestColorIndex,
114
+ 'color.text.brand': brandTextIndex,
102
115
  'color.icon.brand': closestColorIndex,
103
116
  'color.background.brand.subtlest': 0,
104
117
  'color.background.brand.subtlest.hovered': 1,
@@ -110,13 +123,13 @@ export var generateTokenMap = function generateTokenMap(brandColor, mode, themeR
110
123
  'color.background.brand.boldest.hovered': 8,
111
124
  'color.background.brand.boldest.pressed': 7,
112
125
  'color.border.brand': closestColorIndex,
113
- 'color.text.selected': closestColorIndex,
126
+ 'color.text.selected': brandTextIndex,
114
127
  'color.icon.selected': closestColorIndex,
115
128
  'color.background.selected.bold': closestColorIndex,
116
129
  'color.background.selected.bold.hovered': brandBoldSelectedHoveredIndex,
117
130
  'color.background.selected.bold.pressed': brandBoldSelectedPressedIndex,
118
131
  'color.border.selected': closestColorIndex,
119
- 'color.link': closestColorIndex,
132
+ 'color.link': brandTextIndex,
120
133
  'color.link.pressed': linkPressed,
121
134
  'color.chart.brand': 5,
122
135
  'color.chart.brand.hovered': 6,
@@ -125,18 +138,25 @@ export var generateTokenMap = function generateTokenMap(brandColor, mode, themeR
125
138
  'color.background.selected.pressed': 2
126
139
  };
127
140
  } else {
141
+ var brandBackgroundIndex = 6;
142
+ if (inputContrast < 4.5 && inputContrast >= 4 && closestColorIndex === 6) {
143
+ // Use the generated closest color instead of the input brand color for
144
+ // color.background.selected.bold and color.background.brand.bold
145
+ // to avoid contrast breaches
146
+ brandBackgroundIndex = replacedColor;
147
+ }
128
148
  customThemeTokenMapLight = {
129
149
  'color.background.brand.subtlest': 0,
130
150
  'color.background.brand.subtlest.hovered': 1,
131
151
  'color.background.brand.subtlest.pressed': 2,
132
- 'color.background.brand.bold': 6,
152
+ 'color.background.brand.bold': brandBackgroundIndex,
133
153
  'color.background.brand.bold.hovered': 7,
134
154
  'color.background.brand.bold.pressed': 8,
135
155
  'color.background.brand.boldest': 9,
136
156
  'color.background.brand.boldest.hovered': 8,
137
157
  'color.background.brand.boldest.pressed': 7,
138
158
  'color.border.brand': 6,
139
- 'color.background.selected.bold': 6,
159
+ 'color.background.selected.bold': brandBackgroundIndex,
140
160
  'color.background.selected.bold.hovered': 7,
141
161
  'color.background.selected.bold.pressed': 8,
142
162
  'color.text.brand': 6,
@@ -166,7 +186,7 @@ export var generateTokenMap = function generateTokenMap(brandColor, mode, themeR
166
186
  var _ref2 = _slicedToArray(_ref, 2),
167
187
  key = _ref2[0],
168
188
  value = _ref2[1];
169
- customThemeTokenMapDark[key] = 9 - value;
189
+ customThemeTokenMapDark[key] = 9 - (typeof value === 'string' ? closestColorIndex : value);
170
190
  });
171
191
 
172
192
  /**
@@ -192,7 +212,7 @@ export var generateTokenMap = function generateTokenMap(brandColor, mode, themeR
192
212
  };
193
213
  };
194
214
  export var generateTokenMapWithContrastCheck = function generateTokenMapWithContrastCheck(brandColor, mode, themeRamp) {
195
- var colors = themeRamp || generateColors(brandColor);
215
+ var colors = themeRamp || generateColors(brandColor).ramp;
196
216
  var tokenMaps = generateTokenMap(brandColor, mode, colors);
197
217
  var result = {};
198
218
  Object.entries(tokenMaps).forEach(function (_ref3) {
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
3
  *
4
+ * DEPRECATED, PLEASE DO NOT USE.
5
+ * Default values can now be based on either light or legacy-light themes, whereas this only contains light theme values.
6
+ *
4
7
  * Token names mapped to their value in the default Atlassian themes ('light').
5
8
  * These default values are used by the Babel plugin to optionally provide automatic fallbacks.
6
9
  *
7
- * @codegen <<SignedSource::cd2ec139d4552898a3fc16a50aac159c>>
10
+ * @codegen <<SignedSource::b5a6322ad7a59d086ea12e85ec78c8f0>>
8
11
  * @codegenCommand yarn build tokens
9
12
  */
10
13
  declare const defaultTokenValues: {
@@ -1,14 +1,17 @@
1
1
  import { NodePath } from '@babel/traverse';
2
2
  import * as t from '@babel/types';
3
+ type DefaultTheme = 'light' | 'legacy-light';
3
4
  export default function plugin(): {
4
5
  visitor: {
5
6
  Program: {
6
7
  enter(path: NodePath<t.Program>, state: {
7
8
  opts: {
8
9
  shouldUseAutoFallback?: boolean;
10
+ defaultTheme?: DefaultTheme;
9
11
  };
10
12
  }): void;
11
13
  exit(path: NodePath<t.Program>): void;
12
14
  };
13
15
  };
14
16
  };
17
+ export {};
@@ -1,7 +1,6 @@
1
1
  export declare const THEME_DATA_ATTRIBUTE = "data-theme";
2
2
  export declare const COLOR_MODE_ATTRIBUTE = "data-color-mode";
3
3
  export declare const CUSTOM_THEME_ATTRIBUTE = "data-custom-theme";
4
- export declare const DEFAULT_THEME = "light";
5
4
  export declare const CSS_PREFIX = "ds";
6
5
  export declare const CSS_VAR_FULL: string[];
7
6
  export declare const TOKEN_NOT_FOUND_CSS_VAR: string;
@@ -5,6 +5,6 @@ type ThemeAttributeId = 'light' | 'dark';
5
5
  export declare function findMissingCustomStyleElements(UNSAFE_themeOptions: ThemeOptionsSchema, mode: ThemeColorModes): ThemeAttributeId[];
6
6
  export declare function limitSizeOfCustomStyleElements(sizeThreshold: number): void;
7
7
  export declare function reduceTokenMap(tokenMap: {
8
- [key in Token]?: number;
8
+ [key in Token]?: number | string;
9
9
  }, themeRamp: string[]): string;
10
10
  export {};
@@ -10,7 +10,7 @@ interface AdditionalContrastCheck {
10
10
  export declare const additionalChecks: AdditionalContrastCheck[];
11
11
  export declare const additionalContrastChecker: ({ customThemeTokenMap, mode, themeRamp, }: {
12
12
  customThemeTokenMap: {
13
- [key: string]: number;
13
+ [key: string]: string | number;
14
14
  };
15
15
  mode: 'light' | 'dark';
16
16
  themeRamp: string[];
@@ -2,11 +2,14 @@ import tokens from '../artifacts/token-names';
2
2
  import { CSSColor, ThemeColorModes } from '../theme-config';
3
3
  type Token = keyof typeof tokens;
4
4
  type TokenMap = {
5
- [key in Token]?: number;
5
+ [key in Token]?: number | string;
6
6
  };
7
7
  type Mode = 'light' | 'dark';
8
8
  export declare const getClosestColorIndex: (themeRamp: CSSColor[], brandColor: CSSColor) => number;
9
- export declare const generateColors: (brandColor: CSSColor) => CSSColor[];
9
+ export declare const generateColors: (brandColor: CSSColor) => {
10
+ ramp: CSSColor[];
11
+ replacedColor: CSSColor;
12
+ };
10
13
  export declare const generateTokenMap: (brandColor: CSSColor, mode: ThemeColorModes, themeRamp?: CSSColor[]) => {
11
14
  light?: TokenMap | undefined;
12
15
  dark?: TokenMap | undefined;
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
3
  *
4
+ * DEPRECATED, PLEASE DO NOT USE.
5
+ * Default values can now be based on either light or legacy-light themes, whereas this only contains light theme values.
6
+ *
4
7
  * Token names mapped to their value in the default Atlassian themes ('light').
5
8
  * These default values are used by the Babel plugin to optionally provide automatic fallbacks.
6
9
  *
7
- * @codegen <<SignedSource::cd2ec139d4552898a3fc16a50aac159c>>
10
+ * @codegen <<SignedSource::b5a6322ad7a59d086ea12e85ec78c8f0>>
8
11
  * @codegenCommand yarn build tokens
9
12
  */
10
13
  declare const defaultTokenValues: {
@@ -1,14 +1,17 @@
1
1
  import { NodePath } from '@babel/traverse';
2
2
  import * as t from '@babel/types';
3
+ type DefaultTheme = 'light' | 'legacy-light';
3
4
  export default function plugin(): {
4
5
  visitor: {
5
6
  Program: {
6
7
  enter(path: NodePath<t.Program>, state: {
7
8
  opts: {
8
9
  shouldUseAutoFallback?: boolean;
10
+ defaultTheme?: DefaultTheme;
9
11
  };
10
12
  }): void;
11
13
  exit(path: NodePath<t.Program>): void;
12
14
  };
13
15
  };
14
16
  };
17
+ export {};
@@ -1,7 +1,6 @@
1
1
  export declare const THEME_DATA_ATTRIBUTE = "data-theme";
2
2
  export declare const COLOR_MODE_ATTRIBUTE = "data-color-mode";
3
3
  export declare const CUSTOM_THEME_ATTRIBUTE = "data-custom-theme";
4
- export declare const DEFAULT_THEME = "light";
5
4
  export declare const CSS_PREFIX = "ds";
6
5
  export declare const CSS_VAR_FULL: string[];
7
6
  export declare const TOKEN_NOT_FOUND_CSS_VAR: string;
@@ -5,6 +5,6 @@ type ThemeAttributeId = 'light' | 'dark';
5
5
  export declare function findMissingCustomStyleElements(UNSAFE_themeOptions: ThemeOptionsSchema, mode: ThemeColorModes): ThemeAttributeId[];
6
6
  export declare function limitSizeOfCustomStyleElements(sizeThreshold: number): void;
7
7
  export declare function reduceTokenMap(tokenMap: {
8
- [key in Token]?: number;
8
+ [key in Token]?: number | string;
9
9
  }, themeRamp: string[]): string;
10
10
  export {};
@@ -10,7 +10,7 @@ interface AdditionalContrastCheck {
10
10
  export declare const additionalChecks: AdditionalContrastCheck[];
11
11
  export declare const additionalContrastChecker: ({ customThemeTokenMap, mode, themeRamp, }: {
12
12
  customThemeTokenMap: {
13
- [key: string]: number;
13
+ [key: string]: string | number;
14
14
  };
15
15
  mode: 'light' | 'dark';
16
16
  themeRamp: string[];
@@ -2,11 +2,14 @@ import tokens from '../artifacts/token-names';
2
2
  import { CSSColor, ThemeColorModes } from '../theme-config';
3
3
  type Token = keyof typeof tokens;
4
4
  type TokenMap = {
5
- [key in Token]?: number;
5
+ [key in Token]?: number | string;
6
6
  };
7
7
  type Mode = 'light' | 'dark';
8
8
  export declare const getClosestColorIndex: (themeRamp: CSSColor[], brandColor: CSSColor) => number;
9
- export declare const generateColors: (brandColor: CSSColor) => CSSColor[];
9
+ export declare const generateColors: (brandColor: CSSColor) => {
10
+ ramp: CSSColor[];
11
+ replacedColor: CSSColor;
12
+ };
10
13
  export declare const generateTokenMap: (brandColor: CSSColor, mode: ThemeColorModes, themeRamp?: CSSColor[]) => {
11
14
  light?: TokenMap | undefined;
12
15
  dark?: TokenMap | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "1.14.0",
3
+ "version": "1.14.2",
4
4
  "description": "Design tokens are the single source of truth to name and store design decisions.",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"
@@ -1,7 +0,0 @@
1
- {
2
- "name": "@atlaskit/tokens",
3
- "version": "1.14.0",
4
- "sideEffects": [
5
- "**/*.css"
6
- ]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "name": "@atlaskit/tokens",
3
- "version": "1.14.0",
4
- "sideEffects": [
5
- "**/*.css"
6
- ]
7
- }
@@ -1,7 +0,0 @@
1
- {
2
- "name": "@atlaskit/tokens",
3
- "version": "1.14.0",
4
- "sideEffects": [
5
- "**/*.css"
6
- ]
7
- }