@atlaskit/tokens 0.13.5 → 1.1.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.
Files changed (196) hide show
  1. package/CHANGELOG.md +305 -0
  2. package/README.md +7 -16
  3. package/dist/cjs/artifacts/palettes-raw/legacy-palette.js +0 -1
  4. package/dist/cjs/artifacts/palettes-raw/palette.js +0 -1
  5. package/dist/cjs/artifacts/palettes-raw/spacing-scale.js +0 -1
  6. package/dist/cjs/artifacts/palettes-raw/typography-palette.js +0 -1
  7. package/dist/cjs/artifacts/replacement-mapping.js +3 -611
  8. package/dist/cjs/artifacts/theme-import-map.js +56 -0
  9. package/dist/cjs/artifacts/themes/atlassian-dark.js +13 -0
  10. package/dist/cjs/artifacts/themes/atlassian-legacy-dark.js +13 -0
  11. package/dist/cjs/artifacts/themes/atlassian-legacy-light.js +13 -0
  12. package/dist/cjs/artifacts/themes/atlassian-light.js +13 -0
  13. package/dist/cjs/artifacts/themes/atlassian-spacing.js +13 -0
  14. package/dist/cjs/artifacts/themes/atlassian-typography.js +13 -0
  15. package/dist/cjs/artifacts/token-default-values.js +2 -170
  16. package/dist/cjs/artifacts/token-names.js +2 -170
  17. package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +1354 -4261
  18. package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-dark.js +1352 -4259
  19. package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-light.js +1396 -4283
  20. package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +1365 -4252
  21. package/dist/cjs/artifacts/tokens-raw/atlassian-spacing.js +1 -1582
  22. package/dist/cjs/artifacts/tokens-raw/atlassian-typography.js +0 -1
  23. package/dist/cjs/artifacts/typescript/atlassian-dark-token-names.js +0 -1
  24. package/dist/cjs/artifacts/typescript/atlassian-light-token-names.js +0 -1
  25. package/dist/cjs/babel-plugin/index.js +0 -2
  26. package/dist/cjs/babel-plugin/plugin.js +17 -43
  27. package/dist/cjs/entry-points/babel-plugin.js +0 -2
  28. package/dist/cjs/entry-points/palettes-raw.js +0 -2
  29. package/dist/cjs/entry-points/rename-mapping.js +0 -2
  30. package/dist/cjs/entry-points/token-ids.js +0 -1
  31. package/dist/cjs/entry-points/token-names.js +0 -2
  32. package/dist/cjs/entry-points/tokens-raw.js +0 -5
  33. package/dist/cjs/get-global-theme.js +30 -0
  34. package/dist/cjs/get-token-value.js +1 -10
  35. package/dist/cjs/get-token.js +3 -13
  36. package/dist/cjs/index.js +46 -10
  37. package/dist/cjs/palettes/legacy-palette.js +1 -1
  38. package/dist/cjs/palettes/spacing-scale.js +1 -1
  39. package/dist/cjs/palettes/typography-palette.js +0 -5
  40. package/dist/cjs/set-global-theme.js +265 -39
  41. package/dist/cjs/theme-config.js +8 -23
  42. package/dist/cjs/{theme-change-observer.js → theme-mutation-observer.js} +5 -57
  43. package/dist/cjs/tokens/atlassian-dark/utility/utility.js +1 -4
  44. package/dist/cjs/tokens/atlassian-legacy-dark/utility/utility.js +1 -4
  45. package/dist/cjs/tokens/atlassian-legacy-light/utility/utility.js +1 -4
  46. package/dist/cjs/tokens/atlassian-light/utility/utility.js +1 -4
  47. package/dist/cjs/tokens/atlassian-spacing/spacing.js +0 -228
  48. package/dist/cjs/tokens/default/spacing/spacing.js +0 -621
  49. package/dist/cjs/tokens/default/utility/utility.js +1 -9
  50. package/dist/cjs/use-theme-observer.js +41 -0
  51. package/dist/cjs/utils/color-detection.js +23 -43
  52. package/dist/cjs/utils/theme-loading.js +69 -0
  53. package/dist/cjs/utils/theme-state-transformer.js +73 -0
  54. package/dist/cjs/utils/token-ids.js +4 -12
  55. package/dist/cjs/version.json +1 -1
  56. package/dist/es2019/artifacts/replacement-mapping.js +3 -610
  57. package/dist/es2019/artifacts/theme-import-map.js +27 -0
  58. package/dist/es2019/artifacts/themes/atlassian-dark.js +296 -0
  59. package/dist/es2019/artifacts/themes/atlassian-legacy-dark.js +296 -0
  60. package/dist/es2019/artifacts/themes/atlassian-legacy-light.js +296 -0
  61. package/dist/es2019/artifacts/themes/atlassian-light.js +296 -0
  62. package/dist/es2019/artifacts/themes/atlassian-spacing.js +23 -0
  63. package/{css/atlassian-typography.css → dist/es2019/artifacts/themes/atlassian-typography.js} +4 -2
  64. package/dist/es2019/artifacts/token-default-values.js +2 -169
  65. package/dist/es2019/artifacts/token-names.js +2 -169
  66. package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +1354 -4260
  67. package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-dark.js +1349 -4255
  68. package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-light.js +1397 -4283
  69. package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +1360 -4246
  70. package/dist/es2019/artifacts/tokens-raw/atlassian-spacing.js +1 -1581
  71. package/dist/es2019/babel-plugin/plugin.js +17 -37
  72. package/dist/es2019/get-global-theme.js +20 -0
  73. package/dist/es2019/get-token-value.js +1 -6
  74. package/dist/es2019/get-token.js +3 -8
  75. package/dist/es2019/index.js +5 -2
  76. package/dist/es2019/palettes/legacy-palette.js +1 -0
  77. package/dist/es2019/palettes/spacing-scale.js +1 -0
  78. package/dist/es2019/palettes/typography-palette.js +2 -1
  79. package/dist/es2019/set-global-theme.js +162 -32
  80. package/dist/es2019/theme-config.js +5 -21
  81. package/dist/es2019/{theme-change-observer.js → theme-mutation-observer.js} +4 -37
  82. package/dist/es2019/tokens/atlassian-dark/utility/utility.js +1 -4
  83. package/dist/es2019/tokens/atlassian-legacy-dark/utility/utility.js +1 -4
  84. package/dist/es2019/tokens/atlassian-legacy-light/utility/utility.js +1 -4
  85. package/dist/es2019/tokens/atlassian-light/utility/utility.js +1 -4
  86. package/dist/es2019/tokens/atlassian-spacing/spacing.js +0 -227
  87. package/dist/es2019/tokens/default/spacing/spacing.js +0 -620
  88. package/dist/es2019/tokens/default/utility/utility.js +1 -9
  89. package/dist/es2019/use-theme-observer.js +26 -0
  90. package/dist/es2019/utils/color-detection.js +3 -5
  91. package/dist/es2019/utils/theme-loading.js +18 -0
  92. package/dist/es2019/utils/theme-state-transformer.js +47 -0
  93. package/dist/es2019/utils/token-ids.js +5 -4
  94. package/dist/es2019/version.json +1 -1
  95. package/dist/esm/artifacts/replacement-mapping.js +3 -610
  96. package/dist/esm/artifacts/theme-import-map.js +39 -0
  97. package/dist/esm/artifacts/themes/atlassian-dark.js +6 -0
  98. package/dist/esm/artifacts/themes/atlassian-legacy-dark.js +6 -0
  99. package/dist/esm/artifacts/themes/atlassian-legacy-light.js +6 -0
  100. package/dist/esm/artifacts/themes/atlassian-light.js +6 -0
  101. package/dist/esm/artifacts/themes/atlassian-spacing.js +6 -0
  102. package/dist/esm/artifacts/themes/atlassian-typography.js +6 -0
  103. package/dist/esm/artifacts/token-default-values.js +2 -169
  104. package/dist/esm/artifacts/token-names.js +2 -169
  105. package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +1354 -4260
  106. package/dist/esm/artifacts/tokens-raw/atlassian-legacy-dark.js +1349 -4255
  107. package/dist/esm/artifacts/tokens-raw/atlassian-legacy-light.js +1397 -4283
  108. package/dist/esm/artifacts/tokens-raw/atlassian-light.js +1360 -4246
  109. package/dist/esm/artifacts/tokens-raw/atlassian-spacing.js +1 -1581
  110. package/dist/esm/babel-plugin/plugin.js +17 -35
  111. package/dist/esm/get-global-theme.js +22 -0
  112. package/dist/esm/get-token-value.js +1 -6
  113. package/dist/esm/get-token.js +3 -8
  114. package/dist/esm/index.js +5 -2
  115. package/dist/esm/palettes/legacy-palette.js +1 -0
  116. package/dist/esm/palettes/spacing-scale.js +1 -0
  117. package/dist/esm/palettes/typography-palette.js +0 -3
  118. package/dist/esm/set-global-theme.js +263 -37
  119. package/dist/esm/theme-config.js +5 -21
  120. package/dist/esm/{theme-change-observer.js → theme-mutation-observer.js} +4 -49
  121. package/dist/esm/tokens/atlassian-dark/utility/utility.js +1 -4
  122. package/dist/esm/tokens/atlassian-legacy-dark/utility/utility.js +1 -4
  123. package/dist/esm/tokens/atlassian-legacy-light/utility/utility.js +1 -4
  124. package/dist/esm/tokens/atlassian-light/utility/utility.js +1 -4
  125. package/dist/esm/tokens/atlassian-spacing/spacing.js +0 -227
  126. package/dist/esm/tokens/default/spacing/spacing.js +0 -620
  127. package/dist/esm/tokens/default/utility/utility.js +1 -9
  128. package/dist/esm/use-theme-observer.js +34 -0
  129. package/dist/esm/utils/color-detection.js +23 -30
  130. package/dist/esm/utils/theme-loading.js +60 -0
  131. package/dist/esm/utils/theme-state-transformer.js +64 -0
  132. package/dist/esm/utils/token-ids.js +5 -4
  133. package/dist/esm/version.json +1 -1
  134. package/dist/types/artifacts/replacement-mapping.d.ts +1 -1
  135. package/dist/types/artifacts/theme-import-map.d.ts +16 -0
  136. package/dist/types/artifacts/themes/atlassian-dark.d.ts +7 -0
  137. package/dist/types/artifacts/themes/atlassian-legacy-dark.d.ts +7 -0
  138. package/dist/types/artifacts/themes/atlassian-legacy-light.d.ts +7 -0
  139. package/dist/types/artifacts/themes/atlassian-light.d.ts +7 -0
  140. package/dist/types/artifacts/themes/atlassian-spacing.d.ts +7 -0
  141. package/dist/types/artifacts/themes/atlassian-typography.d.ts +7 -0
  142. package/dist/types/artifacts/token-default-values.d.ts +2 -169
  143. package/dist/types/artifacts/token-names.d.ts +3 -337
  144. package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -115
  145. package/dist/types/artifacts/tokens-raw/atlassian-legacy-dark.d.ts +1 -115
  146. package/dist/types/artifacts/tokens-raw/atlassian-legacy-light.d.ts +1 -91
  147. package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -91
  148. package/dist/types/artifacts/tokens-raw/atlassian-spacing.d.ts +1 -89
  149. package/dist/types/artifacts/types-internal.d.ts +2 -2
  150. package/dist/types/artifacts/types.d.ts +2 -2
  151. package/dist/types/get-global-theme.d.ts +2 -0
  152. package/dist/types/index.d.ts +7 -3
  153. package/dist/types/set-global-theme.d.ts +63 -7
  154. package/dist/types/theme-config.d.ts +10 -7
  155. package/dist/types/{theme-change-observer.d.ts → theme-mutation-observer.d.ts} +2 -16
  156. package/dist/types/types.d.ts +1 -286
  157. package/dist/types/use-theme-observer.d.ts +15 -0
  158. package/dist/types/utils/theme-loading.d.ts +3 -0
  159. package/dist/types/utils/theme-state-transformer.d.ts +26 -0
  160. package/figma/atlassian-dark.json +1 -102
  161. package/figma/atlassian-legacy-dark.json +1 -102
  162. package/figma/atlassian-legacy-light.json +1 -102
  163. package/figma/atlassian-light.json +1 -102
  164. package/figma/atlassian-spacing.json +1 -761
  165. package/package.json +5 -8
  166. package/report.api.md +85 -351
  167. package/tmp/api-report-tmp.d.ts +58 -342
  168. package/css/atlassian-dark.css +0 -786
  169. package/css/atlassian-legacy-dark.css +0 -786
  170. package/css/atlassian-legacy-light.css +0 -786
  171. package/css/atlassian-light.css +0 -786
  172. package/css/atlassian-spacing.css +0 -87
  173. package/dist/cjs/artifacts/typescript/atlassian-light-token-default-values.js +0 -407
  174. package/dist/cjs/tokens/atlassian-dark/deprecated/deprecated.js +0 -435
  175. package/dist/cjs/tokens/atlassian-legacy-dark/deprecated/deprecated.js +0 -532
  176. package/dist/cjs/tokens/atlassian-legacy-light/deprecated/deprecated.js +0 -523
  177. package/dist/cjs/tokens/atlassian-light/deprecated/deprecated.js +0 -421
  178. package/dist/cjs/tokens/default/deprecated/deprecated.js +0 -1186
  179. package/dist/es2019/artifacts/typescript/atlassian-light-token-default-values.js +0 -399
  180. package/dist/es2019/tokens/atlassian-dark/deprecated/deprecated.js +0 -428
  181. package/dist/es2019/tokens/atlassian-legacy-dark/deprecated/deprecated.js +0 -525
  182. package/dist/es2019/tokens/atlassian-legacy-light/deprecated/deprecated.js +0 -516
  183. package/dist/es2019/tokens/atlassian-light/deprecated/deprecated.js +0 -414
  184. package/dist/es2019/tokens/default/deprecated/deprecated.js +0 -1217
  185. package/dist/esm/artifacts/typescript/atlassian-light-token-default-values.js +0 -399
  186. package/dist/esm/tokens/atlassian-dark/deprecated/deprecated.js +0 -428
  187. package/dist/esm/tokens/atlassian-legacy-dark/deprecated/deprecated.js +0 -525
  188. package/dist/esm/tokens/atlassian-legacy-light/deprecated/deprecated.js +0 -516
  189. package/dist/esm/tokens/atlassian-light/deprecated/deprecated.js +0 -414
  190. package/dist/esm/tokens/default/deprecated/deprecated.js +0 -1179
  191. package/dist/types/artifacts/typescript/atlassian-light-token-default-values.d.ts +0 -399
  192. package/dist/types/tokens/atlassian-dark/deprecated/deprecated.d.ts +0 -4
  193. package/dist/types/tokens/atlassian-legacy-dark/deprecated/deprecated.d.ts +0 -4
  194. package/dist/types/tokens/atlassian-legacy-light/deprecated/deprecated.d.ts +0 -4
  195. package/dist/types/tokens/atlassian-light/deprecated/deprecated.d.ts +0 -4
  196. package/dist/types/tokens/default/deprecated/deprecated.d.ts +0 -4
@@ -22,6 +22,7 @@ export const getLuminance = ({
22
22
  g,
23
23
  b
24
24
  }) => (r * 299 + g * 587 + b * 114) / 1000;
25
+
25
26
  /**
26
27
  * Returns an accessible hard-coded text color based on the color contrast with
27
28
  * the background.
@@ -31,7 +32,6 @@ export const getLuminance = ({
31
32
  * of a hard-coded color. This is to support more transparent backgrounds
32
33
  * to allow the text to invert colors depending on the current theme's surface color.
33
34
  */
34
-
35
35
  export const getTextColorForBackground = (hex, opts) => {
36
36
  const {
37
37
  r,
@@ -50,22 +50,20 @@ export const getTextColorForBackground = (hex, opts) => {
50
50
  dark: a > alphaLimit
51
51
  };
52
52
  const alphaLimitExceeded = (opts === null || opts === void 0 ? void 0 : opts.hardcodedSurface) && alphaConditionsPerSurface[opts.hardcodedSurface];
53
-
54
53
  if (!(opts !== null && opts !== void 0 && opts.hardcodedSurface) && a < alphaLimit) {
55
54
  // This color is transparent, so the text will mainly cast onto the surface behind.
56
55
  // Needs to use tokens otherwise Dark mode would cause black text on black surface
57
56
  return token('color.text', 'black');
58
57
  }
59
-
60
58
  return lum > 150 && !a || a && alphaLimitExceeded ? 'black' : 'white';
61
59
  };
60
+
62
61
  /**
63
62
  * Returns a border if determined to be required based on the color contrast with
64
63
  * the background.
65
64
  *
66
65
  * @param hex - The Hex color code of the background
67
66
  */
68
-
69
67
  export const getBorderForBackground = hex => {
70
68
  const {
71
69
  r,
@@ -80,12 +78,12 @@ export const getBorderForBackground = hex => {
80
78
  });
81
79
  return lum > 240 || a < 0.2 ? `1px solid ${token('color.border', '#091E4224')}` : undefined;
82
80
  };
81
+
83
82
  /**
84
83
  * Returns a box shadow formatted for CSS from a ShadowToken raw value.
85
84
  *
86
85
  * @param rawShadow - ShadowToken raw value
87
86
  */
88
-
89
87
  export const getBoxShadow = rawShadow => rawShadow.map(({
90
88
  radius,
91
89
  offset,
@@ -0,0 +1,18 @@
1
+ import themeImportMap from '../artifacts/theme-import-map';
2
+ import { THEME_DATA_ATTRIBUTE } from '../constants';
3
+ export const loadAndAppendThemeCss = async themeId => {
4
+ if (document.head.querySelector(`style[${THEME_DATA_ATTRIBUTE}="${themeId}"]`)) {
5
+ return;
6
+ }
7
+ const themeCss = await loadThemeCss(themeId);
8
+ const style = document.createElement('style');
9
+ style.textContent = themeCss;
10
+ style.dataset.theme = themeId;
11
+ document.head.appendChild(style);
12
+ };
13
+ export const loadThemeCss = async themeId => {
14
+ const {
15
+ default: themeCss
16
+ } = await themeImportMap[themeId]();
17
+ return themeCss;
18
+ };
@@ -0,0 +1,47 @@
1
+ import { themeIds } from '../theme-config';
2
+ const themeKinds = ['light', 'dark', 'spacing', 'typography'];
3
+ const isThemeKind = themeKind => {
4
+ return themeKinds.find(kind => kind === themeKind) !== undefined;
5
+ };
6
+ const isThemeIds = themeId => {
7
+ return themeIds.find(id => id === themeId) !== undefined;
8
+ };
9
+ const isColorMode = modeId => {
10
+ return ['light', 'dark', 'auto'].includes(modeId);
11
+ };
12
+ /**
13
+ * Converts a string that is formatted for the `data-theme` HTML attribute
14
+ * to an object that can be passed to `setGlobalTheme`.
15
+ *
16
+ * @param {string} themes The themes that should be applied.
17
+ *
18
+ * @example
19
+ * ```
20
+ * themeStringToObject('dark:dark light:legacy-light spacing:spacing');
21
+ * // returns { dark: 'dark', light: 'legacy-light', spacing: 'spacing' }
22
+ * ```
23
+ */
24
+ export const themeStringToObject = themeState => {
25
+ return themeState.split(' ').map(theme => theme.split(':')).reduce((themeObject, [kind, id]) => {
26
+ if (kind === 'colorMode' && isColorMode(id)) {
27
+ themeObject[kind] = id;
28
+ }
29
+ if (isThemeKind(kind) && isThemeIds(id)) {
30
+ themeObject[kind] = id;
31
+ }
32
+ return themeObject;
33
+ }, {});
34
+ };
35
+
36
+ /**
37
+ * Converts a theme object to a string formatted for the `data-theme` HTML attribute.
38
+ *
39
+ * @param {object} themes The themes that should be applied.
40
+ *
41
+ * @example
42
+ * ```
43
+ * themeObjectToString({ dark: 'dark', light: 'legacy-light', spacing: 'spacing' });
44
+ * // returns 'dark:dark light:legacy-light spacing:spacing'
45
+ * ```
46
+ */
47
+ export const themeObjectToString = themeState => Object.entries(themeState).reduce((themeString, [kind, id]) => (kind === 'colorMode' || isThemeKind(kind)) && (isThemeIds(id) || isColorMode(id)) ? themeString + `${themeString ? ' ' : ''}` + `${kind}:${id}` : themeString, '');
@@ -1,4 +1,5 @@
1
1
  import { CSS_PREFIX, CSS_VAR_FULL } from '../constants';
2
+
2
3
  /**
3
4
  * Transforms a style dictionary token path to a CSS custom property.
4
5
  *
@@ -13,13 +14,14 @@ import { CSS_PREFIX, CSS_VAR_FULL } from '../constants';
13
14
  * // Returns ds-background-bold
14
15
  * getCSSCustomProperty('color.background.bold.[default]')
15
16
  */
16
-
17
17
  export const getCSSCustomProperty = path => {
18
- const normalizedPath = typeof path === 'string' ? path.split('.') : path; // Opacity and other 'shallow' groups are more readable when not trimmed
18
+ const normalizedPath = typeof path === 'string' ? path.split('.') : path;
19
19
 
20
+ // Opacity and other 'shallow' groups are more readable when not trimmed
20
21
  const slice = CSS_VAR_FULL.includes(path[0]) ? 0 : 1;
21
22
  return `--${[CSS_PREFIX, ...normalizedPath.slice(slice)].filter(el => el !== '[default]').join('-')}`;
22
23
  };
24
+
23
25
  /**
24
26
  * Transforms a style dictionary token path to a shorthand token id
25
27
  * These ids will be typically be how tokens are interacted with via typescript and css
@@ -34,11 +36,11 @@ export const getCSSCustomProperty = path => {
34
36
  * // Returns color.background.bold
35
37
  * getTokenId('color.background.bold.[default]')
36
38
  */
37
-
38
39
  export const getTokenId = path => {
39
40
  const normalizedPath = typeof path === 'string' ? path.split('.') : path;
40
41
  return normalizedPath.filter(el => el !== '[default]').join('.');
41
42
  };
43
+
42
44
  /**
43
45
  * Transforms a style dictionary token path to a fully qualified token id
44
46
  * These Ids are intended to be used internal to this package by style-dictionary
@@ -49,5 +51,4 @@ export const getTokenId = path => {
49
51
  * // Returns color.background.bold.[default]
50
52
  * getFullyQualifiedTokenId(['color', 'background', 'bold', '[default]'])
51
53
  */
52
-
53
54
  export const getFullyQualifiedTokenId = path => path.join('.');
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "0.13.5",
3
+ "version": "1.1.0",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]