@atlaskit/tokens 1.13.1 → 1.13.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 (82) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/custom-theme.js +17 -13
  3. package/dist/cjs/get-global-theme.js +4 -3
  4. package/dist/cjs/get-ssr-auto-script.js +21 -0
  5. package/dist/cjs/get-theme-html-attrs.js +76 -0
  6. package/dist/cjs/get-theme-styles.js +139 -0
  7. package/dist/cjs/get-token-value.js +1 -1
  8. package/dist/cjs/get-token.js +1 -1
  9. package/dist/cjs/index.js +15 -15
  10. package/dist/cjs/set-global-theme.js +9 -242
  11. package/dist/cjs/theme-config.js +23 -1
  12. package/dist/cjs/theme-mutation-observer.js +4 -4
  13. package/dist/cjs/{utils/theme-state-transformer.js → theme-state-transformer.js} +1 -1
  14. package/dist/cjs/use-theme-observer.js +7 -6
  15. package/dist/cjs/utils/get-theme-preferences.js +35 -0
  16. package/dist/cjs/utils/theme-loading.js +4 -2
  17. package/dist/cjs/version.json +1 -1
  18. package/dist/es2019/custom-theme.js +10 -10
  19. package/dist/es2019/get-global-theme.js +4 -3
  20. package/dist/es2019/get-ssr-auto-script.js +23 -0
  21. package/dist/es2019/get-theme-html-attrs.js +62 -0
  22. package/dist/es2019/get-theme-styles.js +72 -0
  23. package/dist/es2019/get-token-value.js +1 -1
  24. package/dist/es2019/get-token.js +1 -1
  25. package/dist/es2019/index.js +9 -6
  26. package/dist/es2019/set-global-theme.js +5 -185
  27. package/dist/es2019/theme-config.js +21 -0
  28. package/dist/es2019/theme-mutation-observer.js +2 -2
  29. package/dist/es2019/{utils/theme-state-transformer.js → theme-state-transformer.js} +1 -1
  30. package/dist/es2019/use-theme-observer.js +5 -4
  31. package/dist/es2019/utils/get-theme-preferences.js +28 -0
  32. package/dist/es2019/utils/theme-loading.js +2 -1
  33. package/dist/es2019/version.json +1 -1
  34. package/dist/esm/custom-theme.js +15 -11
  35. package/dist/esm/get-global-theme.js +4 -3
  36. package/dist/esm/get-ssr-auto-script.js +15 -0
  37. package/dist/esm/get-theme-html-attrs.js +68 -0
  38. package/dist/esm/get-theme-styles.js +126 -0
  39. package/dist/esm/get-token-value.js +1 -1
  40. package/dist/esm/get-token.js +1 -1
  41. package/dist/esm/index.js +9 -6
  42. package/dist/esm/set-global-theme.js +6 -233
  43. package/dist/esm/theme-config.js +21 -0
  44. package/dist/esm/theme-mutation-observer.js +4 -3
  45. package/dist/esm/{utils/theme-state-transformer.js → theme-state-transformer.js} +1 -1
  46. package/dist/esm/use-theme-observer.js +5 -4
  47. package/dist/esm/utils/get-theme-preferences.js +27 -0
  48. package/dist/esm/utils/theme-loading.js +2 -1
  49. package/dist/esm/version.json +1 -1
  50. package/dist/types/custom-theme.d.ts +4 -9
  51. package/dist/types/get-global-theme.d.ts +2 -1
  52. package/dist/types/get-ssr-auto-script.d.ts +11 -0
  53. package/dist/types/get-theme-html-attrs.d.ts +17 -0
  54. package/dist/types/get-theme-styles.d.ts +24 -0
  55. package/dist/types/index.d.ts +10 -9
  56. package/dist/types/set-global-theme.d.ts +1 -58
  57. package/dist/types/theme-config.d.ts +24 -0
  58. package/dist/types/theme-mutation-observer.d.ts +1 -1
  59. package/dist/{types-ts4.5/utils → types}/theme-state-transformer.d.ts +1 -1
  60. package/dist/types/use-theme-observer.d.ts +2 -1
  61. package/dist/types/utils/custom-theme-loading-utils.d.ts +2 -3
  62. package/dist/types/utils/generate-custom-color-ramp.d.ts +1 -2
  63. package/dist/types/utils/get-theme-preferences.d.ts +2 -0
  64. package/dist/types/utils/theme-loading.d.ts +1 -0
  65. package/dist/types-ts4.5/custom-theme.d.ts +4 -9
  66. package/dist/types-ts4.5/get-global-theme.d.ts +2 -1
  67. package/dist/types-ts4.5/get-ssr-auto-script.d.ts +11 -0
  68. package/dist/types-ts4.5/get-theme-html-attrs.d.ts +17 -0
  69. package/dist/types-ts4.5/get-theme-styles.d.ts +24 -0
  70. package/dist/types-ts4.5/index.d.ts +10 -9
  71. package/dist/types-ts4.5/set-global-theme.d.ts +1 -58
  72. package/dist/types-ts4.5/theme-config.d.ts +24 -0
  73. package/dist/types-ts4.5/theme-mutation-observer.d.ts +1 -1
  74. package/dist/{types/utils → types-ts4.5}/theme-state-transformer.d.ts +1 -1
  75. package/dist/types-ts4.5/use-theme-observer.d.ts +2 -1
  76. package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +2 -3
  77. package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +1 -2
  78. package/dist/types-ts4.5/utils/get-theme-preferences.d.ts +2 -0
  79. package/dist/types-ts4.5/utils/theme-loading.d.ts +1 -0
  80. package/package.json +1 -1
  81. package/report.api.md +8 -8
  82. package/tmp/api-report-tmp.d.ts +1158 -0
@@ -0,0 +1,126 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
3
+ import _regeneratorRuntime from "@babel/runtime/regenerator";
4
+ import { themeIdsWithOverrides, themeStateDefaults } from './theme-config';
5
+ import { isValidBrandHex } from './utils/color-utils';
6
+ import { getThemePreferences } from './utils/get-theme-preferences';
7
+ import { loadThemeCss } from './utils/theme-loading';
8
+ /**
9
+ * Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
10
+ * Only supplies the color themes necessary for initial render, based on the current themeState. I.e. if in light mode, dark mode themes are not returned.
11
+ *
12
+ * @param {Object<string, string>} themeState The themes and color mode that should be applied.
13
+ * @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
14
+ * @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
15
+ * @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
16
+ * @param {string} themeState.shape The shape theme to be applied.
17
+ * @param {string} themeState.spacing The spacing theme to be applied.
18
+ * @param {string} themeState.typography The typography theme to be applied.
19
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
20
+ *
21
+ * @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
22
+ * If an error is encountered while loading themes, the themes array will be empty.
23
+ */
24
+ var getThemeStyles = /*#__PURE__*/function () {
25
+ var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(preferences) {
26
+ var themePreferences, results;
27
+ return _regeneratorRuntime.wrap(function _callee3$(_context3) {
28
+ while (1) switch (_context3.prev = _context3.next) {
29
+ case 0:
30
+ if (preferences === 'all') {
31
+ themePreferences = themeIdsWithOverrides;
32
+ } else {
33
+ themePreferences = getThemePreferences({
34
+ colorMode: (preferences === null || preferences === void 0 ? void 0 : preferences.colorMode) || themeStateDefaults['colorMode'],
35
+ dark: (preferences === null || preferences === void 0 ? void 0 : preferences.dark) || themeStateDefaults['dark'],
36
+ light: (preferences === null || preferences === void 0 ? void 0 : preferences.light) || themeStateDefaults['light'],
37
+ shape: (preferences === null || preferences === void 0 ? void 0 : preferences.shape) || themeStateDefaults['shape'],
38
+ spacing: (preferences === null || preferences === void 0 ? void 0 : preferences.spacing) || themeStateDefaults['spacing'],
39
+ typography: (preferences === null || preferences === void 0 ? void 0 : preferences.typography) || themeStateDefaults['typography']
40
+ });
41
+ }
42
+ _context3.next = 3;
43
+ return Promise.all([].concat(_toConsumableArray(themePreferences.map( /*#__PURE__*/function () {
44
+ var _ref2 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(themeId) {
45
+ var css;
46
+ return _regeneratorRuntime.wrap(function _callee$(_context) {
47
+ while (1) switch (_context.prev = _context.next) {
48
+ case 0:
49
+ _context.prev = 0;
50
+ _context.next = 3;
51
+ return loadThemeCss(themeId);
52
+ case 3:
53
+ css = _context.sent;
54
+ return _context.abrupt("return", {
55
+ id: themeId,
56
+ attrs: {
57
+ 'data-theme': themeId
58
+ },
59
+ css: css
60
+ });
61
+ case 7:
62
+ _context.prev = 7;
63
+ _context.t0 = _context["catch"](0);
64
+ return _context.abrupt("return", undefined);
65
+ case 10:
66
+ case "end":
67
+ return _context.stop();
68
+ }
69
+ }, _callee, null, [[0, 7]]);
70
+ }));
71
+ return function (_x2) {
72
+ return _ref2.apply(this, arguments);
73
+ };
74
+ }())), [
75
+ // Add custom themes if they're present
76
+ _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
77
+ var _preferences$UNSAFE_t;
78
+ var _yield$import, getCustomThemeStyles, customThemeStyles;
79
+ return _regeneratorRuntime.wrap(function _callee2$(_context2) {
80
+ while (1) switch (_context2.prev = _context2.next) {
81
+ case 0:
82
+ if (!(preferences !== 'all' && preferences !== null && preferences !== void 0 && preferences.UNSAFE_themeOptions && isValidBrandHex(preferences === null || preferences === void 0 ? void 0 : (_preferences$UNSAFE_t = preferences.UNSAFE_themeOptions) === null || _preferences$UNSAFE_t === void 0 ? void 0 : _preferences$UNSAFE_t.brandColor))) {
83
+ _context2.next = 15;
84
+ break;
85
+ }
86
+ _context2.prev = 1;
87
+ _context2.next = 4;
88
+ return import( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
89
+ './custom-theme');
90
+ case 4:
91
+ _yield$import = _context2.sent;
92
+ getCustomThemeStyles = _yield$import.getCustomThemeStyles;
93
+ _context2.next = 8;
94
+ return getCustomThemeStyles({
95
+ colorMode: (preferences === null || preferences === void 0 ? void 0 : preferences.colorMode) || themeStateDefaults['colorMode'],
96
+ UNSAFE_themeOptions: preferences === null || preferences === void 0 ? void 0 : preferences.UNSAFE_themeOptions
97
+ });
98
+ case 8:
99
+ customThemeStyles = _context2.sent;
100
+ return _context2.abrupt("return", customThemeStyles);
101
+ case 12:
102
+ _context2.prev = 12;
103
+ _context2.t0 = _context2["catch"](1);
104
+ return _context2.abrupt("return", undefined);
105
+ case 15:
106
+ case "end":
107
+ return _context2.stop();
108
+ }
109
+ }, _callee2, null, [[1, 12]]);
110
+ }))()]));
111
+ case 3:
112
+ results = _context3.sent;
113
+ return _context3.abrupt("return", results.flat().filter(function (theme) {
114
+ return theme !== undefined;
115
+ }));
116
+ case 5:
117
+ case "end":
118
+ return _context3.stop();
119
+ }
120
+ }, _callee3);
121
+ }));
122
+ return function getThemeStyles(_x) {
123
+ return _ref.apply(this, arguments);
124
+ };
125
+ }();
126
+ export default getThemeStyles;
@@ -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.13.1";
4
+ var version = "1.13.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.13.1";
5
+ var version = "1.13.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.
package/dist/esm/index.js CHANGED
@@ -1,8 +1,11 @@
1
+ export { default as themeConfig } from './theme-config';
1
2
  export { default as token } from './get-token';
2
3
  export { default as getTokenValue } from './get-token-value';
3
- export { default as setGlobalTheme, getThemeStyles, getThemeHtmlAttrs, getSSRAutoScript } from './set-global-theme';
4
- export { default as themeConfig } from './theme-config';
5
- export { useThemeObserver } from './use-theme-observer';
6
- export { ThemeMutationObserver } from './theme-mutation-observer';
7
- export { getGlobalTheme } from './get-global-theme';
8
- export { themeStringToObject, themeObjectToString } from './utils/theme-state-transformer';
4
+ export { default as setGlobalTheme } from './set-global-theme';
5
+ export { default as getThemeStyles } from './get-theme-styles';
6
+ export { default as getThemeHtmlAttrs } from './get-theme-html-attrs';
7
+ export { default as getSSRAutoScript } from './get-ssr-auto-script';
8
+ export { default as useThemeObserver } from './use-theme-observer';
9
+ export { default as ThemeMutationObserver } from './theme-mutation-observer';
10
+ export { default as getGlobalTheme } from './get-global-theme';
11
+ export { themeStringToObject, themeObjectToString } from './theme-state-transformer';
@@ -1,35 +1,22 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
3
- import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
4
2
  import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
3
+ import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
5
4
  import _regeneratorRuntime from "@babel/runtime/regenerator";
6
5
  import { bind } from 'bind-event-listener';
7
6
  import noop from '@atlaskit/ds-lib/noop';
8
- import { getBooleanFF } from '@atlaskit/platform-feature-flags';
9
- import { COLOR_MODE_ATTRIBUTE, CUSTOM_THEME_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
10
- import { themeIdsWithOverrides } from './theme-config';
7
+ import { COLOR_MODE_ATTRIBUTE } from './constants';
8
+ import getThemeHtmlAttrs from './get-theme-html-attrs';
9
+ import { themeStateDefaults } from './theme-config';
11
10
  import { isValidBrandHex } from './utils/color-utils';
12
11
  import { findMissingCustomStyleElements } from './utils/custom-theme-loading-utils';
13
- import { hash } from './utils/hash';
14
- import { loadAndAppendThemeCss, loadThemeCss } from './utils/theme-loading';
15
- import { themeObjectToString } from './utils/theme-state-transformer';
12
+ import { getThemePreferences } from './utils/get-theme-preferences';
13
+ import { darkModeMediaQuery, loadAndAppendThemeCss } from './utils/theme-loading';
16
14
 
17
15
  // Represents theme state once mounted to the page (auto is hidden from observers)
18
16
 
19
- var defaultColorMode = 'light';
20
17
  var isMatchMediaAvailable = typeof window !== 'undefined' && 'matchMedia' in window;
21
- var darkModeMediaQuery = '(prefers-color-scheme: dark)';
22
18
  var darkModeMql = isMatchMediaAvailable && window.matchMedia(darkModeMediaQuery);
23
19
  var unbindThemeChangeListener = noop;
24
- export var themeStateDefaults = {
25
- colorMode: 'auto',
26
- dark: 'dark',
27
- light: 'light',
28
- shape: undefined,
29
- spacing: undefined,
30
- typography: undefined,
31
- UNSAFE_themeOptions: undefined
32
- };
33
20
 
34
21
  /**
35
22
  * Updates the current theme when the system theme changes. Should be bound
@@ -40,31 +27,6 @@ var checkNativeListener = function checkNativeListener(e) {
40
27
  var element = document.documentElement;
41
28
  element.setAttribute(COLOR_MODE_ATTRIBUTE, e.matches ? 'dark' : 'light');
42
29
  };
43
- var getThemePreferences = function getThemePreferences(themeState) {
44
- var colorMode = themeState.colorMode,
45
- dark = themeState.dark,
46
- light = themeState.light,
47
- shape = themeState.shape,
48
- spacing = themeState.spacing,
49
- typography = themeState.typography;
50
- var themePreferences = colorMode === 'auto' ? [light, dark] : [themeState[colorMode]];
51
- [shape, spacing, typography].forEach(function (themeId) {
52
- if (themeId) {
53
- themePreferences.push(themeId);
54
- }
55
- });
56
- if (getBooleanFF('platform.design-system-team.border-checkbox_nyoiu')) {
57
- themePreferences.push("".concat(themePreferences.includes('dark') ? 'dark' : 'light', "-new-input-border"));
58
- }
59
-
60
- // Load shape and spacing by default, currently behind a feature flag
61
- if (getBooleanFF('platform.design-system-team.space-and-shape-tokens_q5me6')) {
62
- if (!themePreferences.includes('spacing')) {
63
- themePreferences.push('spacing');
64
- }
65
- }
66
- return _toConsumableArray(new Set(themePreferences));
67
- };
68
30
 
69
31
  /**
70
32
  * Sets the theme globally at runtime. This updates the `data-theme` and `data-color-mode` attributes on your page's <html> tag.
@@ -215,193 +177,4 @@ var setGlobalTheme = /*#__PURE__*/function () {
215
177
  return _ref.apply(this, arguments);
216
178
  };
217
179
  }();
218
- /**
219
- * Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
220
- * Only supplies the color themes necessary for initial render, based on the current themeState. I.e. if in light mode, dark mode themes are not returned.
221
- *
222
- * @param {Object<string, string>} themeState The themes and color mode that should be applied.
223
- * @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
224
- * @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
225
- * @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
226
- * @param {string} themeState.shape The shape theme to be applied.
227
- * @param {string} themeState.spacing The spacing theme to be applied.
228
- * @param {string} themeState.typography The typography theme to be applied.
229
- * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
230
- *
231
- * @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
232
- * If an error is encountered while loading themes, the themes array will be empty.
233
- */
234
- export var getThemeStyles = /*#__PURE__*/function () {
235
- var _ref7 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee6(preferences) {
236
- var themePreferences, results;
237
- return _regeneratorRuntime.wrap(function _callee6$(_context6) {
238
- while (1) switch (_context6.prev = _context6.next) {
239
- case 0:
240
- if (preferences === 'all') {
241
- themePreferences = themeIdsWithOverrides;
242
- } else {
243
- themePreferences = getThemePreferences({
244
- colorMode: (preferences === null || preferences === void 0 ? void 0 : preferences.colorMode) || themeStateDefaults['colorMode'],
245
- dark: (preferences === null || preferences === void 0 ? void 0 : preferences.dark) || themeStateDefaults['dark'],
246
- light: (preferences === null || preferences === void 0 ? void 0 : preferences.light) || themeStateDefaults['light'],
247
- shape: (preferences === null || preferences === void 0 ? void 0 : preferences.shape) || themeStateDefaults['shape'],
248
- spacing: (preferences === null || preferences === void 0 ? void 0 : preferences.spacing) || themeStateDefaults['spacing'],
249
- typography: (preferences === null || preferences === void 0 ? void 0 : preferences.typography) || themeStateDefaults['typography']
250
- });
251
- }
252
- _context6.next = 3;
253
- return Promise.all([].concat(_toConsumableArray(themePreferences.map( /*#__PURE__*/function () {
254
- var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4(themeId) {
255
- var css;
256
- return _regeneratorRuntime.wrap(function _callee4$(_context4) {
257
- while (1) switch (_context4.prev = _context4.next) {
258
- case 0:
259
- _context4.prev = 0;
260
- _context4.next = 3;
261
- return loadThemeCss(themeId);
262
- case 3:
263
- css = _context4.sent;
264
- return _context4.abrupt("return", {
265
- id: themeId,
266
- attrs: {
267
- 'data-theme': themeId
268
- },
269
- css: css
270
- });
271
- case 7:
272
- _context4.prev = 7;
273
- _context4.t0 = _context4["catch"](0);
274
- return _context4.abrupt("return", undefined);
275
- case 10:
276
- case "end":
277
- return _context4.stop();
278
- }
279
- }, _callee4, null, [[0, 7]]);
280
- }));
281
- return function (_x3) {
282
- return _ref8.apply(this, arguments);
283
- };
284
- }())), [
285
- // Add custom themes if they're present
286
- _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee5() {
287
- var _preferences$UNSAFE_t;
288
- var _yield$import2, getCustomThemeStyles, customThemeStyles;
289
- return _regeneratorRuntime.wrap(function _callee5$(_context5) {
290
- while (1) switch (_context5.prev = _context5.next) {
291
- case 0:
292
- if (!(preferences !== 'all' && preferences !== null && preferences !== void 0 && preferences.UNSAFE_themeOptions && isValidBrandHex(preferences === null || preferences === void 0 ? void 0 : (_preferences$UNSAFE_t = preferences.UNSAFE_themeOptions) === null || _preferences$UNSAFE_t === void 0 ? void 0 : _preferences$UNSAFE_t.brandColor))) {
293
- _context5.next = 15;
294
- break;
295
- }
296
- _context5.prev = 1;
297
- _context5.next = 4;
298
- return import( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
299
- './custom-theme');
300
- case 4:
301
- _yield$import2 = _context5.sent;
302
- getCustomThemeStyles = _yield$import2.getCustomThemeStyles;
303
- _context5.next = 8;
304
- return getCustomThemeStyles({
305
- colorMode: (preferences === null || preferences === void 0 ? void 0 : preferences.colorMode) || themeStateDefaults['colorMode'],
306
- UNSAFE_themeOptions: preferences === null || preferences === void 0 ? void 0 : preferences.UNSAFE_themeOptions
307
- });
308
- case 8:
309
- customThemeStyles = _context5.sent;
310
- return _context5.abrupt("return", customThemeStyles);
311
- case 12:
312
- _context5.prev = 12;
313
- _context5.t0 = _context5["catch"](1);
314
- return _context5.abrupt("return", undefined);
315
- case 15:
316
- case "end":
317
- return _context5.stop();
318
- }
319
- }, _callee5, null, [[1, 12]]);
320
- }))()]));
321
- case 3:
322
- results = _context6.sent;
323
- return _context6.abrupt("return", results.flat().filter(function (theme) {
324
- return theme !== undefined;
325
- }));
326
- case 5:
327
- case "end":
328
- return _context6.stop();
329
- }
330
- }, _callee6);
331
- }));
332
- return function getThemeStyles(_x2) {
333
- return _ref7.apply(this, arguments);
334
- };
335
- }();
336
-
337
- /**
338
- * Server-side rendering utility. Generates the valid HTML attributes for a given theme.
339
- * Note: this utility does not handle automatic theme switching.
340
- *
341
- * @param {Object<string, string>} themeOptions - Theme options object
342
- * @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
343
- * @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
344
- * @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
345
- * @param {string} themeState.spacing The spacing theme to be applied.
346
- * @param {string} themeState.typography The typography theme to be applied.
347
- * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
348
- *
349
- * @returns {Object} Object of HTML attributes to be applied to the document root
350
- */
351
- export var getThemeHtmlAttrs = function getThemeHtmlAttrs() {
352
- var _result;
353
- var _ref10 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
354
- _ref10$colorMode = _ref10.colorMode,
355
- colorMode = _ref10$colorMode === void 0 ? themeStateDefaults['colorMode'] : _ref10$colorMode,
356
- _ref10$dark = _ref10.dark,
357
- dark = _ref10$dark === void 0 ? themeStateDefaults['dark'] : _ref10$dark,
358
- _ref10$light = _ref10.light,
359
- light = _ref10$light === void 0 ? themeStateDefaults['light'] : _ref10$light,
360
- _ref10$shape = _ref10.shape,
361
- shape = _ref10$shape === void 0 ? themeStateDefaults['shape'] : _ref10$shape,
362
- _ref10$spacing = _ref10.spacing,
363
- spacing = _ref10$spacing === void 0 ? themeStateDefaults['spacing'] : _ref10$spacing,
364
- _ref10$typography = _ref10.typography,
365
- typography = _ref10$typography === void 0 ? themeStateDefaults['typography'] : _ref10$typography,
366
- _ref10$UNSAFE_themeOp = _ref10.UNSAFE_themeOptions,
367
- UNSAFE_themeOptions = _ref10$UNSAFE_themeOp === void 0 ? themeStateDefaults['UNSAFE_themeOptions'] : _ref10$UNSAFE_themeOp;
368
- var themePreferences = {
369
- dark: dark,
370
- light: light,
371
- shape: shape,
372
- spacing: spacing,
373
- typography: typography
374
- };
375
-
376
- // Load spacing by default, currently behind a feature flag
377
- if (getBooleanFF('platform.design-system-team.space-and-shape-tokens_q5me6')) {
378
- themePreferences = {
379
- dark: dark,
380
- light: light,
381
- shape: shape,
382
- spacing: 'spacing',
383
- typography: typography
384
- };
385
- }
386
- var themeAttribute = themeObjectToString(themePreferences);
387
- var result = (_result = {}, _defineProperty(_result, THEME_DATA_ATTRIBUTE, themeAttribute), _defineProperty(_result, COLOR_MODE_ATTRIBUTE, colorMode === 'auto' ? defaultColorMode : colorMode), _result);
388
- if (UNSAFE_themeOptions && isValidBrandHex(UNSAFE_themeOptions.brandColor)) {
389
- var optionString = JSON.stringify(UNSAFE_themeOptions);
390
- var uniqueId = hash(optionString);
391
- result[CUSTOM_THEME_ATTRIBUTE] = uniqueId;
392
- }
393
- return result;
394
- };
395
-
396
- /**
397
- * Provides a script that, when executed before paint, sets the `data-color-mode` attribute based on the current system theme,
398
- * to enable SSR support for automatic theme switching, avoid a flash of un-themed content on first paint.
399
- *
400
- * @param {string} colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
401
- *
402
- * @returns {string} A string to be added to the innerHTML of a script tag in the document head
403
- */
404
- export var getSSRAutoScript = function getSSRAutoScript(colorMode) {
405
- return colorMode === 'auto' ? "(\n () => {\n try {\n const mql = window.matchMedia('".concat(darkModeMediaQuery, "');\n const colorMode = mql.matches ? 'dark' : 'light';\n document.documentElement.setAttribute('").concat(COLOR_MODE_ATTRIBUTE, "', colorMode);\n } catch (e) {}\n }\n)()") : undefined;
406
- };
407
180
  export default setGlobalTheme;
@@ -141,4 +141,25 @@ var themeConfig = {
141
141
  }
142
142
  }
143
143
  };
144
+
145
+ /**
146
+ * ThemeOptionsSchema: additional configuration options used to customize Atlassian's themes
147
+ */
148
+
149
+ /**
150
+ * ThemeState: the standard representation of an app's current theme and preferences
151
+ */
152
+
153
+ /**
154
+ * themeStateDefaults: the default values for ThemeState used by theming utilities
155
+ */
156
+ export var themeStateDefaults = {
157
+ colorMode: 'auto',
158
+ dark: 'dark',
159
+ light: 'light',
160
+ shape: undefined,
161
+ spacing: undefined,
162
+ typography: undefined,
163
+ UNSAFE_themeOptions: undefined
164
+ };
144
165
  export default themeConfig;
@@ -2,7 +2,7 @@ import _classCallCheck from "@babel/runtime/helpers/classCallCheck";
2
2
  import _createClass from "@babel/runtime/helpers/createClass";
3
3
  import _defineProperty from "@babel/runtime/helpers/defineProperty";
4
4
  import { COLOR_MODE_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
5
- import { getGlobalTheme } from './get-global-theme';
5
+ import getGlobalTheme from './get-global-theme';
6
6
  /**
7
7
  * A MutationObserver which watches the `<html>` element for changes to the theme.
8
8
  *
@@ -16,7 +16,7 @@ import { getGlobalTheme } from './get-global-theme';
16
16
  * observer.observe();
17
17
  * ```
18
18
  */
19
- export var ThemeMutationObserver = /*#__PURE__*/function () {
19
+ var ThemeMutationObserver = /*#__PURE__*/function () {
20
20
  function ThemeMutationObserver(callback) {
21
21
  _classCallCheck(this, ThemeMutationObserver);
22
22
  _defineProperty(this, "observer", null);
@@ -43,4 +43,5 @@ export var ThemeMutationObserver = /*#__PURE__*/function () {
43
43
  }
44
44
  }]);
45
45
  return ThemeMutationObserver;
46
- }();
46
+ }();
47
+ export { ThemeMutationObserver as default };
@@ -1,5 +1,5 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
- import { themeIds } from '../theme-config';
2
+ import { themeIds } from './theme-config';
3
3
  var themeKinds = ['light', 'dark', 'spacing', 'typography', 'shape'];
4
4
  var isThemeKind = function isThemeKind(themeKind) {
5
5
  return themeKinds.find(function (kind) {
@@ -1,7 +1,7 @@
1
1
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
2
2
  import { useEffect, useState } from 'react';
3
- import { getGlobalTheme } from './get-global-theme';
4
- import { ThemeMutationObserver } from './theme-mutation-observer';
3
+ import getGlobalTheme from './get-global-theme';
4
+ import ThemeMutationObserver from './theme-mutation-observer';
5
5
 
6
6
  /**
7
7
  * A React hook which returns the current themes and color-mode set on `<html>`.
@@ -16,7 +16,7 @@ import { ThemeMutationObserver } from './theme-mutation-observer';
16
16
  * }, [theme.colorMode]);
17
17
  * ```
18
18
  */
19
- export var useThemeObserver = function useThemeObserver() {
19
+ var useThemeObserver = function useThemeObserver() {
20
20
  var _useState = useState(getGlobalTheme()),
21
21
  _useState2 = _slicedToArray(_useState, 2),
22
22
  theme = _useState2[0],
@@ -31,4 +31,5 @@ export var useThemeObserver = function useThemeObserver() {
31
31
  };
32
32
  }, []);
33
33
  return theme;
34
- };
34
+ };
35
+ export default useThemeObserver;
@@ -0,0 +1,27 @@
1
+ import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
2
+ import { getBooleanFF } from '@atlaskit/platform-feature-flags';
3
+ export var getThemePreferences = function getThemePreferences(themeState) {
4
+ var colorMode = themeState.colorMode,
5
+ dark = themeState.dark,
6
+ light = themeState.light,
7
+ shape = themeState.shape,
8
+ spacing = themeState.spacing,
9
+ typography = themeState.typography;
10
+ var themePreferences = colorMode === 'auto' ? [light, dark] : [themeState[colorMode]];
11
+ [shape, spacing, typography].forEach(function (themeId) {
12
+ if (themeId) {
13
+ themePreferences.push(themeId);
14
+ }
15
+ });
16
+ if (getBooleanFF('platform.design-system-team.border-checkbox_nyoiu')) {
17
+ themePreferences.push("".concat(themePreferences.includes('dark') ? 'dark' : 'light', "-new-input-border"));
18
+ }
19
+
20
+ // Load shape and spacing by default, currently behind a feature flag
21
+ if (getBooleanFF('platform.design-system-team.space-and-shape-tokens_q5me6')) {
22
+ if (!themePreferences.includes('spacing')) {
23
+ themePreferences.push('spacing');
24
+ }
25
+ }
26
+ return _toConsumableArray(new Set(themePreferences));
27
+ };
@@ -53,4 +53,5 @@ export var loadThemeCss = /*#__PURE__*/function () {
53
53
  return function loadThemeCss(_x2) {
54
54
  return _ref2.apply(this, arguments);
55
55
  };
56
- }();
56
+ }();
57
+ export var darkModeMediaQuery = '(prefers-color-scheme: dark)';
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "1.13.1",
3
+ "version": "1.13.2",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
@@ -1,10 +1,6 @@
1
- import { ThemeState, ThemeStyles } from './set-global-theme';
1
+ import { ThemeStyles } from './get-theme-styles';
2
+ import { ThemeOptionsSchema, ThemeState } from './theme-config';
2
3
  export declare const CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = 10;
3
- type HEX = `#${string}`;
4
- export type CSSColor = HEX;
5
- export interface CustomBrandSchema {
6
- brandColor: CSSColor;
7
- }
8
4
  /**
9
5
  *
10
6
  * @param themeSchema The schema of available themes
@@ -22,9 +18,8 @@ export interface CustomBrandSchema {
22
18
  * If an error is encountered while loading themes, the themes array will be empty.
23
19
  */
24
20
  export declare function getCustomThemeStyles(themeState: Partial<ThemeState> & {
25
- UNSAFE_themeOptions: CustomBrandSchema;
21
+ UNSAFE_themeOptions: ThemeOptionsSchema;
26
22
  }): Promise<ThemeStyles[]>;
27
23
  export declare function loadAndAppendCustomThemeCss(themeState: Partial<ThemeState> & {
28
- UNSAFE_themeOptions: CustomBrandSchema;
24
+ UNSAFE_themeOptions: ThemeOptionsSchema;
29
25
  }): Promise<void>;
30
- export {};
@@ -1,2 +1,3 @@
1
1
  import { ActiveThemeState } from './set-global-theme';
2
- export declare const getGlobalTheme: () => Partial<ActiveThemeState>;
2
+ declare const getGlobalTheme: () => Partial<ActiveThemeState>;
3
+ export default getGlobalTheme;
@@ -0,0 +1,11 @@
1
+ import { ThemeState } from './theme-config';
2
+ /**
3
+ * Provides a script that, when executed before paint, sets the `data-color-mode` attribute based on the current system theme,
4
+ * to enable SSR support for automatic theme switching, avoid a flash of un-themed content on first paint.
5
+ *
6
+ * @param {string} colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
7
+ *
8
+ * @returns {string} A string to be added to the innerHTML of a script tag in the document head
9
+ */
10
+ declare const getSSRAutoScript: (colorMode: ThemeState['colorMode']) => string | undefined;
11
+ export default getSSRAutoScript;
@@ -0,0 +1,17 @@
1
+ import { ThemeState } from './theme-config';
2
+ /**
3
+ * Server-side rendering utility. Generates the valid HTML attributes for a given theme.
4
+ * Note: this utility does not handle automatic theme switching.
5
+ *
6
+ * @param {Object<string, string>} themeOptions - Theme options object
7
+ * @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
8
+ * @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
9
+ * @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
10
+ * @param {string} themeState.spacing The spacing theme to be applied.
11
+ * @param {string} themeState.typography The typography theme to be applied.
12
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
13
+ *
14
+ * @returns {Object} Object of HTML attributes to be applied to the document root
15
+ */
16
+ declare const getThemeHtmlAttrs: ({ colorMode, dark, light, shape, spacing, typography, UNSAFE_themeOptions, }?: Partial<ThemeState>) => Record<string, string>;
17
+ export default getThemeHtmlAttrs;
@@ -0,0 +1,24 @@
1
+ import { ThemeIdsWithOverrides, ThemeState } from './theme-config';
2
+ export interface ThemeStyles {
3
+ id: ThemeIdsWithOverrides;
4
+ attrs: Record<string, string>;
5
+ css: string;
6
+ }
7
+ /**
8
+ * Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
9
+ * Only supplies the color themes necessary for initial render, based on the current themeState. I.e. if in light mode, dark mode themes are not returned.
10
+ *
11
+ * @param {Object<string, string>} themeState The themes and color mode that should be applied.
12
+ * @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
13
+ * @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
14
+ * @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
15
+ * @param {string} themeState.shape The shape theme to be applied.
16
+ * @param {string} themeState.spacing The spacing theme to be applied.
17
+ * @param {string} themeState.typography The typography theme to be applied.
18
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
19
+ *
20
+ * @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
21
+ * If an error is encountered while loading themes, the themes array will be empty.
22
+ */
23
+ declare const getThemeStyles: (preferences?: Partial<ThemeState> | 'all') => Promise<ThemeStyles[]>;
24
+ export default getThemeStyles;