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