@atlaskit/tokens 1.11.2 → 1.12.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 (116) hide show
  1. package/CHANGELOG.md +20 -0
  2. package/dist/cjs/artifacts/atlassian-dark-token-value-for-contrast-check.js +24 -0
  3. package/dist/cjs/artifacts/atlassian-light-token-value-for-contrast-check.js +24 -0
  4. package/dist/cjs/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
  5. package/dist/cjs/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
  6. package/dist/cjs/constants.js +3 -1
  7. package/dist/cjs/custom-theme.js +108 -0
  8. package/dist/cjs/get-token-value.js +1 -1
  9. package/dist/cjs/get-token.js +1 -1
  10. package/dist/cjs/set-global-theme.js +156 -59
  11. package/dist/cjs/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
  12. package/dist/cjs/utils/color-utils.js +178 -0
  13. package/dist/cjs/utils/custom-theme-loading-utils.js +47 -0
  14. package/dist/cjs/utils/custom-theme-token-contrast-check.js +74 -0
  15. package/dist/cjs/utils/generate-custom-color-ramp.js +213 -0
  16. package/dist/cjs/utils/hash.js +17 -0
  17. package/dist/cjs/utils/hct-color-utils/color-utils.js +310 -0
  18. package/dist/cjs/utils/hct-color-utils/contrast.js +188 -0
  19. package/dist/cjs/utils/hct-color-utils/hct.js +1036 -0
  20. package/dist/cjs/utils/hct-color-utils/index.js +32 -0
  21. package/dist/cjs/utils/hct-color-utils/math-utils.js +159 -0
  22. package/dist/cjs/utils/theme-loading.js +1 -1
  23. package/dist/cjs/utils/theme-state-transformer.js +1 -1
  24. package/dist/cjs/version.json +1 -1
  25. package/dist/es2019/artifacts/atlassian-dark-token-value-for-contrast-check.js +17 -0
  26. package/dist/es2019/artifacts/atlassian-light-token-value-for-contrast-check.js +17 -0
  27. package/dist/es2019/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
  28. package/dist/es2019/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
  29. package/dist/es2019/constants.js +1 -0
  30. package/dist/es2019/custom-theme.js +77 -0
  31. package/dist/es2019/get-token-value.js +1 -1
  32. package/dist/es2019/get-token.js +1 -1
  33. package/dist/es2019/set-global-theme.js +67 -13
  34. package/dist/es2019/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
  35. package/dist/es2019/utils/color-utils.js +154 -0
  36. package/dist/es2019/utils/custom-theme-loading-utils.js +31 -0
  37. package/dist/es2019/utils/custom-theme-token-contrast-check.js +68 -0
  38. package/dist/es2019/utils/generate-custom-color-ramp.js +187 -0
  39. package/dist/es2019/utils/hash.js +10 -0
  40. package/dist/es2019/utils/hct-color-utils/color-utils.js +286 -0
  41. package/dist/es2019/utils/hct-color-utils/contrast.js +161 -0
  42. package/dist/es2019/utils/hct-color-utils/hct.js +931 -0
  43. package/dist/es2019/utils/hct-color-utils/index.js +3 -0
  44. package/dist/es2019/utils/hct-color-utils/math-utils.js +145 -0
  45. package/dist/es2019/utils/theme-loading.js +2 -2
  46. package/dist/es2019/utils/theme-state-transformer.js +3 -1
  47. package/dist/es2019/version.json +1 -1
  48. package/dist/esm/artifacts/atlassian-dark-token-value-for-contrast-check.js +17 -0
  49. package/dist/esm/artifacts/atlassian-light-token-value-for-contrast-check.js +17 -0
  50. package/dist/esm/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
  51. package/dist/esm/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
  52. package/dist/esm/constants.js +1 -0
  53. package/dist/esm/custom-theme.js +98 -0
  54. package/dist/esm/get-token-value.js +1 -1
  55. package/dist/esm/get-token.js +1 -1
  56. package/dist/esm/set-global-theme.js +149 -60
  57. package/dist/esm/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
  58. package/dist/esm/utils/color-utils.js +162 -0
  59. package/dist/esm/utils/custom-theme-loading-utils.js +38 -0
  60. package/dist/esm/utils/custom-theme-token-contrast-check.js +65 -0
  61. package/dist/esm/utils/generate-custom-color-ramp.js +202 -0
  62. package/dist/esm/utils/hash.js +10 -0
  63. package/dist/esm/utils/hct-color-utils/color-utils.js +285 -0
  64. package/dist/esm/utils/hct-color-utils/contrast.js +181 -0
  65. package/dist/esm/utils/hct-color-utils/hct.js +1029 -0
  66. package/dist/esm/utils/hct-color-utils/index.js +3 -0
  67. package/dist/esm/utils/hct-color-utils/math-utils.js +145 -0
  68. package/dist/esm/utils/theme-loading.js +2 -2
  69. package/dist/esm/utils/theme-state-transformer.js +1 -1
  70. package/dist/esm/version.json +1 -1
  71. package/dist/types/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +17 -0
  72. package/dist/types/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +17 -0
  73. package/dist/types/artifacts/themes/atlassian-dark-new-input-border.d.ts +2 -2
  74. package/dist/types/artifacts/tokens-raw/atlassian-dark-new-input-border.d.ts +1 -1
  75. package/dist/types/constants.d.ts +1 -0
  76. package/dist/types/custom-theme.d.ts +30 -0
  77. package/dist/types/index.d.ts +1 -0
  78. package/dist/types/set-global-theme.d.ts +9 -3
  79. package/dist/types/tokens/atlassian-dark/utility/utility.d.ts +1 -1
  80. package/dist/types/tokens/atlassian-light/utility/utility.d.ts +1 -1
  81. package/dist/types/tokens/default/utility/utility.d.ts +1 -1
  82. package/dist/types/utils/color-utils.d.ts +10 -0
  83. package/dist/types/utils/custom-theme-loading-utils.d.ts +11 -0
  84. package/dist/types/utils/custom-theme-token-contrast-check.d.ts +20 -0
  85. package/dist/types/utils/generate-custom-color-ramp.d.ts +19 -0
  86. package/dist/types/utils/hash.d.ts +1 -0
  87. package/dist/types/utils/hct-color-utils/color-utils.d.ts +131 -0
  88. package/dist/types/utils/hct-color-utils/contrast.d.ts +78 -0
  89. package/dist/types/utils/hct-color-utils/hct.d.ts +137 -0
  90. package/dist/types/utils/hct-color-utils/index.d.ts +3 -0
  91. package/dist/types/utils/hct-color-utils/math-utils.d.ts +86 -0
  92. package/dist/types-ts4.5/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +17 -0
  93. package/dist/types-ts4.5/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +17 -0
  94. package/dist/types-ts4.5/artifacts/themes/atlassian-dark-new-input-border.d.ts +2 -2
  95. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-new-input-border.d.ts +1 -1
  96. package/dist/types-ts4.5/constants.d.ts +1 -0
  97. package/dist/types-ts4.5/custom-theme.d.ts +30 -0
  98. package/dist/types-ts4.5/index.d.ts +1 -0
  99. package/dist/types-ts4.5/set-global-theme.d.ts +9 -3
  100. package/dist/types-ts4.5/tokens/atlassian-dark/utility/utility.d.ts +1 -1
  101. package/dist/types-ts4.5/tokens/atlassian-light/utility/utility.d.ts +1 -1
  102. package/dist/types-ts4.5/tokens/default/utility/utility.d.ts +1 -1
  103. package/dist/types-ts4.5/utils/color-utils.d.ts +27 -0
  104. package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +11 -0
  105. package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +20 -0
  106. package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +19 -0
  107. package/dist/types-ts4.5/utils/hash.d.ts +1 -0
  108. package/dist/types-ts4.5/utils/hct-color-utils/color-utils.d.ts +131 -0
  109. package/dist/types-ts4.5/utils/hct-color-utils/contrast.d.ts +78 -0
  110. package/dist/types-ts4.5/utils/hct-color-utils/hct.d.ts +137 -0
  111. package/dist/types-ts4.5/utils/hct-color-utils/index.d.ts +3 -0
  112. package/dist/types-ts4.5/utils/hct-color-utils/math-utils.d.ts +86 -0
  113. package/figma/atlassian-dark-new-input-border.json +1 -1
  114. package/package.json +35 -40
  115. package/report.api.md +24 -1
  116. package/tmp/api-report-tmp.d.ts +0 -1132
package/CHANGELOG.md CHANGED
@@ -1,5 +1,25 @@
1
1
  # @atlaskit/tokens
2
2
 
3
+ ## 1.12.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`beba2779d31`](https://bitbucket.org/atlassian/atlassian-frontend/commits/beba2779d31) - Add experimental support for custom theming via the `UNSAFE_themeOptions` field in `themeState`.
8
+
9
+ This option is supported in the following functions:
10
+
11
+ - `setGlobalTheme()`: optionally generates and loads customized themes based on the options provided, and sets the `data-custom-theme` attribute on page's HTML tag.
12
+ - `getThemeStyles()`: returns additional style objects for constructing custom theme `<style>` tags.
13
+ - `getThemeHtmlAttrs()`: now supports the `data-custom-theme` attribute.
14
+
15
+ Custom themes are generated at runtime based on the options provided. The theme generation logic is lazy-loaded only when `UNSAFE_themeOptions` is set.
16
+
17
+ ## 1.11.3
18
+
19
+ ### Patch Changes
20
+
21
+ - [`1b40a9ff426`](https://bitbucket.org/atlassian/atlassian-frontend/commits/1b40a9ff426) - update border.input.color to DarkNeutral600
22
+
3
23
  ## 1.11.2
4
24
 
5
25
  ### Patch Changes
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
+ *
10
+ * Token names mapped to their values, used for contrast checking when generating custom themes
11
+ *
12
+ * @codegen <<SignedSource::1ddd5cd744975e8df5a191332ec8a42c>>
13
+ * @codegenCommand yarn build tokens
14
+ */
15
+ var tokenValues = {
16
+ 'color.text.brand': '#579DFF',
17
+ 'elevation.surface.overlay': '#282E33',
18
+ 'color.text.selected': '#579DFF',
19
+ 'color.background.selected': '#092957',
20
+ 'color.border.brand': '#579DFF',
21
+ 'color.chart.brand': '#388BFF'
22
+ };
23
+ var _default = tokenValues;
24
+ exports.default = _default;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ /**
8
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
+ *
10
+ * Token names mapped to their values, used for contrast checking when generating custom themes
11
+ *
12
+ * @codegen <<SignedSource::b59877585fad151840dbf6c212c56e34>>
13
+ * @codegenCommand yarn build tokens
14
+ */
15
+ var tokenValues = {
16
+ 'color.text.brand': '#0C66E4',
17
+ 'elevation.surface.sunken': '#F7F8F9',
18
+ 'color.text.selected': '#0C66E4',
19
+ 'color.background.selected': '#E9F2FF',
20
+ 'color.border.brand': '#0C66E4',
21
+ 'color.chart.brand': '#1D7AFC'
22
+ };
23
+ var _default = tokenValues;
24
+ exports.default = _default;
@@ -6,8 +6,8 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::b255ff03ae4f781bb3016003a111bed0>>
9
+ * @codegen <<SignedSource::cadad94754b78a066c340ab42eca9721>>
10
10
  * @codegenCommand yarn build tokens
11
11
  */
12
- var _default = "\nhtml[data-color-mode=\"light\"][data-theme~=\"light:dark\"],\nhtml[data-color-mode=\"dark\"][data-theme~=\"dark:dark\"] {\n color-scheme: dark;\n --ds-border-input: #596773;\n}\n";
12
+ var _default = "\nhtml[data-color-mode=\"light\"][data-theme~=\"light:dark\"],\nhtml[data-color-mode=\"dark\"][data-theme~=\"dark:dark\"] {\n color-scheme: dark;\n --ds-border-input: #738496;\n}\n";
13
13
  exports.default = _default;
@@ -6,7 +6,7 @@ Object.defineProperty(exports, "__esModule", {
6
6
  exports.default = void 0;
7
7
  /**
8
8
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
9
- * @codegen <<SignedSource::2c7e6a36e75ad8b32981cc4bbaa378db>>
9
+ * @codegen <<SignedSource::a87638614efbe4415e8ffd370dd4ce76>>
10
10
  * @codegenCommand yarn build tokens
11
11
  */
12
12
  var tokens = [{
@@ -16,7 +16,7 @@ var tokens = [{
16
16
  "introduced": "0.6.0",
17
17
  "description": "Use for borders of form UI elements, such as text fields, checkboxes, and radio buttons."
18
18
  },
19
- "value": "#596773",
19
+ "value": "#738496",
20
20
  "filePath": "src/tokens/atlassian-dark-new-input-border/color/border.tsx",
21
21
  "isSource": true,
22
22
  "original": {
@@ -26,7 +26,7 @@ var tokens = [{
26
26
  "introduced": "0.6.0",
27
27
  "description": "Use for borders of form UI elements, such as text fields, checkboxes, and radio buttons."
28
28
  },
29
- "value": "DarkNeutral500"
29
+ "value": "DarkNeutral600"
30
30
  },
31
31
  "name": "color.border.input",
32
32
  "path": ["color", "border", "input"],
@@ -3,11 +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.CSS_VAR_FULL = exports.CSS_PREFIX = exports.COLOR_MODE_ATTRIBUTE = void 0;
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;
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
+ var CUSTOM_THEME_ATTRIBUTE = 'data-custom-theme';
12
+ exports.CUSTOM_THEME_ATTRIBUTE = CUSTOM_THEME_ATTRIBUTE;
11
13
  var DEFAULT_THEME = 'light';
12
14
  exports.DEFAULT_THEME = DEFAULT_THEME;
13
15
  var CSS_PREFIX = 'ds';
@@ -0,0 +1,108 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ Object.defineProperty(exports, "__esModule", {
5
+ value: true
6
+ });
7
+ exports.CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = void 0;
8
+ exports.getCustomThemeStyles = getCustomThemeStyles;
9
+ exports.loadAndAppendCustomThemeCss = loadAndAppendCustomThemeCss;
10
+ var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
11
+ var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
12
+ var _constants = require("./constants");
13
+ var _setGlobalTheme = require("./set-global-theme");
14
+ var _customThemeLoadingUtils = require("./utils/custom-theme-loading-utils");
15
+ var _generateCustomColorRamp = require("./utils/generate-custom-color-ramp");
16
+ var _hash = require("./utils/hash");
17
+ var CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = 10;
18
+ exports.CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD;
19
+ /**
20
+ *
21
+ * @param themeSchema The schema of available themes
22
+ * @returns a string with the CSS for the custom theme
23
+ */
24
+ /**
25
+ * Takes a color mode and custom branding options, and returns an array of objects for use in applying custom styles to the document head.
26
+ * 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.
27
+ *
28
+ * @param {Object<string, string>} themeState The themes and color mode that should be applied.
29
+ * @param {string} themeState.colorMode Determines which color theme is applied
30
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
31
+ *
32
+ * @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
33
+ * If an error is encountered while loading themes, the themes array will be empty.
34
+ */
35
+ function getCustomThemeStyles(_x) {
36
+ return _getCustomThemeStyles.apply(this, arguments);
37
+ }
38
+ function _getCustomThemeStyles() {
39
+ _getCustomThemeStyles = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(themeState) {
40
+ var _themeState$UNSAFE_th;
41
+ var brandColor, mode, optionString, uniqueId, themeRamp, themes, tokenMaps;
42
+ return _regenerator.default.wrap(function _callee$(_context) {
43
+ while (1) switch (_context.prev = _context.next) {
44
+ case 0:
45
+ brandColor = themeState === null || themeState === void 0 ? void 0 : (_themeState$UNSAFE_th = themeState.UNSAFE_themeOptions) === null || _themeState$UNSAFE_th === void 0 ? void 0 : _themeState$UNSAFE_th.brandColor;
46
+ mode = (themeState === null || themeState === void 0 ? void 0 : themeState.colorMode) || _setGlobalTheme.themeStateDefaults['colorMode'];
47
+ optionString = JSON.stringify(themeState === null || themeState === void 0 ? void 0 : themeState.UNSAFE_themeOptions);
48
+ uniqueId = (0, _hash.hash)(optionString);
49
+ themeRamp = (0, _generateCustomColorRamp.generateColors)(brandColor); // outputs object to generate to CSS from
50
+ themes = [];
51
+ tokenMaps = (0, _generateCustomColorRamp.generateTokenMapWithContrastCheck)(brandColor, mode, themeRamp);
52
+ if ((mode === 'light' || mode === 'auto') && tokenMaps.light) {
53
+ // Light mode theming
54
+ themes.push({
55
+ id: 'light',
56
+ attrs: {
57
+ 'data-theme': 'light',
58
+ 'data-custom-theme': uniqueId
59
+ },
60
+ css: "\nhtml[".concat(_constants.CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(_constants.COLOR_MODE_ATTRIBUTE, "=\"light\"][data-theme~=\"light:light\"] {\n /* Branded tokens */\n ").concat((0, _customThemeLoadingUtils.reduceTokenMap)(tokenMaps.light, themeRamp), "\n}")
61
+ });
62
+ }
63
+ if ((mode === 'dark' || mode === 'auto') && tokenMaps.dark) {
64
+ // Dark mode theming
65
+ themes.push({
66
+ id: 'dark',
67
+ attrs: {
68
+ 'data-theme': 'dark',
69
+ 'data-custom-theme': uniqueId
70
+ },
71
+ css: "\nhtml[".concat(_constants.CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(_constants.COLOR_MODE_ATTRIBUTE, "=\"dark\"][data-theme~=\"dark:dark\"] {\n /* Branded tokens */\n ").concat((0, _customThemeLoadingUtils.reduceTokenMap)(tokenMaps.dark, themeRamp), "\n}")
72
+ });
73
+ }
74
+ return _context.abrupt("return", themes);
75
+ case 10:
76
+ case "end":
77
+ return _context.stop();
78
+ }
79
+ }, _callee);
80
+ }));
81
+ return _getCustomThemeStyles.apply(this, arguments);
82
+ }
83
+ function loadAndAppendCustomThemeCss(_x2) {
84
+ return _loadAndAppendCustomThemeCss.apply(this, arguments);
85
+ }
86
+ function _loadAndAppendCustomThemeCss() {
87
+ _loadAndAppendCustomThemeCss = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2(themeState) {
88
+ return _regenerator.default.wrap(function _callee2$(_context2) {
89
+ while (1) switch (_context2.prev = _context2.next) {
90
+ case 0:
91
+ getCustomThemeStyles(themeState).then(function (themes) {
92
+ (0, _customThemeLoadingUtils.limitSizeOfCustomStyleElements)(CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD);
93
+ themes.map(function (theme) {
94
+ var styleTag = document.createElement('style');
95
+ document.head.appendChild(styleTag);
96
+ styleTag.dataset.theme = theme.attrs['data-theme'];
97
+ styleTag.dataset.customTheme = theme.attrs['data-custom-theme'];
98
+ styleTag.textContent = theme.css;
99
+ });
100
+ });
101
+ case 1:
102
+ case "end":
103
+ return _context2.stop();
104
+ }
105
+ }, _callee2);
106
+ }));
107
+ return _loadAndAppendCustomThemeCss.apply(this, arguments);
108
+ }
@@ -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.11.2";
11
+ var version = "1.12.0";
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.11.2";
12
+ var version = "1.12.0";
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.
@@ -1,10 +1,11 @@
1
1
  "use strict";
2
2
 
3
3
  var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+ var _typeof = require("@babel/runtime/helpers/typeof");
4
5
  Object.defineProperty(exports, "__esModule", {
5
6
  value: true
6
7
  });
7
- exports.getThemeStyles = exports.getThemeHtmlAttrs = exports.getSSRAutoScript = exports.default = void 0;
8
+ exports.themeStateDefaults = exports.getThemeStyles = exports.getThemeHtmlAttrs = exports.getSSRAutoScript = exports.default = void 0;
8
9
  var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
9
10
  var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
10
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
@@ -15,8 +16,13 @@ var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
15
16
  var _platformFeatureFlags = require("@atlaskit/platform-feature-flags");
16
17
  var _constants = require("./constants");
17
18
  var _themeConfig = require("./theme-config");
19
+ var _colorUtils = require("./utils/color-utils");
20
+ var _customThemeLoadingUtils = require("./utils/custom-theme-loading-utils");
21
+ var _hash = require("./utils/hash");
18
22
  var _themeLoading = require("./utils/theme-loading");
19
23
  var _themeStateTransformer = require("./utils/theme-state-transformer");
24
+ 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); }
25
+ 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; }
20
26
  // Represents theme state once mounted to the page (auto is hidden from observers)
21
27
 
22
28
  var defaultColorMode = 'light';
@@ -30,7 +36,8 @@ var themeStateDefaults = {
30
36
  light: 'light',
31
37
  shape: undefined,
32
38
  spacing: undefined,
33
- typography: undefined
39
+ typography: undefined,
40
+ UNSAFE_themeOptions: undefined
34
41
  };
35
42
 
36
43
  /**
@@ -38,6 +45,7 @@ var themeStateDefaults = {
38
45
  * to an event listener listening on the '(prefers-color-scheme: dark)' query
39
46
  * @param e The event representing a change in system theme.
40
47
  */
48
+ exports.themeStateDefaults = themeStateDefaults;
41
49
  var checkNativeListener = function checkNativeListener(e) {
42
50
  var element = document.documentElement;
43
51
  element.setAttribute(_constants.COLOR_MODE_ATTRIBUTE, e.matches ? 'dark' : 'light');
@@ -78,6 +86,7 @@ var getThemePreferences = function getThemePreferences(themeState) {
78
86
  * @param {string} themeState.shape The shape theme to be applied.
79
87
  * @param {string} themeState.spacing The spacing theme to be applied.
80
88
  * @param {string} themeState.typography The typography theme to be applied.
89
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
81
90
  * @param {function} themeLoader Callback function used to override the default theme loading functionality.
82
91
  *
83
92
  * @returns A Promise of an unbind function, that can be used to stop listening for changes to system theme.
@@ -88,7 +97,7 @@ var getThemePreferences = function getThemePreferences(themeState) {
88
97
  * ```
89
98
  */
90
99
  var setGlobalTheme = /*#__PURE__*/function () {
91
- var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
100
+ var _ref = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3() {
92
101
  var _ref2,
93
102
  _ref2$colorMode,
94
103
  colorMode,
@@ -102,16 +111,18 @@ var setGlobalTheme = /*#__PURE__*/function () {
102
111
  spacing,
103
112
  _ref2$typography,
104
113
  typography,
114
+ _ref2$UNSAFE_themeOpt,
115
+ UNSAFE_themeOptions,
105
116
  themeLoader,
106
117
  themePreferences,
107
118
  loadingStrategy,
108
119
  themeAttributes,
109
- _args2 = arguments;
110
- return _regenerator.default.wrap(function _callee2$(_context2) {
111
- while (1) switch (_context2.prev = _context2.next) {
120
+ _args3 = arguments;
121
+ return _regenerator.default.wrap(function _callee3$(_context3) {
122
+ while (1) switch (_context3.prev = _context3.next) {
112
123
  case 0:
113
- _ref2 = _args2.length > 0 && _args2[0] !== undefined ? _args2[0] : {}, _ref2$colorMode = _ref2.colorMode, colorMode = _ref2$colorMode === void 0 ? themeStateDefaults['colorMode'] : _ref2$colorMode, _ref2$dark = _ref2.dark, dark = _ref2$dark === void 0 ? themeStateDefaults['dark'] : _ref2$dark, _ref2$light = _ref2.light, light = _ref2$light === void 0 ? themeStateDefaults['light'] : _ref2$light, _ref2$shape = _ref2.shape, shape = _ref2$shape === void 0 ? themeStateDefaults['shape'] : _ref2$shape, _ref2$spacing = _ref2.spacing, spacing = _ref2$spacing === void 0 ? themeStateDefaults['spacing'] : _ref2$spacing, _ref2$typography = _ref2.typography, typography = _ref2$typography === void 0 ? themeStateDefaults['typography'] : _ref2$typography;
114
- themeLoader = _args2.length > 1 ? _args2[1] : undefined;
124
+ _ref2 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref2$colorMode = _ref2.colorMode, colorMode = _ref2$colorMode === void 0 ? themeStateDefaults['colorMode'] : _ref2$colorMode, _ref2$dark = _ref2.dark, dark = _ref2$dark === void 0 ? themeStateDefaults['dark'] : _ref2$dark, _ref2$light = _ref2.light, light = _ref2$light === void 0 ? themeStateDefaults['light'] : _ref2$light, _ref2$shape = _ref2.shape, shape = _ref2$shape === void 0 ? themeStateDefaults['shape'] : _ref2$shape, _ref2$spacing = _ref2.spacing, spacing = _ref2$spacing === void 0 ? themeStateDefaults['spacing'] : _ref2$spacing, _ref2$typography = _ref2.typography, typography = _ref2$typography === void 0 ? themeStateDefaults['typography'] : _ref2$typography, _ref2$UNSAFE_themeOpt = _ref2.UNSAFE_themeOptions, UNSAFE_themeOptions = _ref2$UNSAFE_themeOpt === void 0 ? themeStateDefaults['UNSAFE_themeOptions'] : _ref2$UNSAFE_themeOpt;
125
+ themeLoader = _args3.length > 1 ? _args3[1] : undefined;
115
126
  themePreferences = getThemePreferences({
116
127
  colorMode: colorMode,
117
128
  dark: dark,
@@ -121,8 +132,8 @@ var setGlobalTheme = /*#__PURE__*/function () {
121
132
  typography: typography
122
133
  });
123
134
  loadingStrategy = themeLoader ? themeLoader : _themeLoading.loadAndAppendThemeCss;
124
- _context2.next = 6;
125
- return Promise.all(themePreferences.map( /*#__PURE__*/function () {
135
+ _context3.next = 6;
136
+ return Promise.all([].concat((0, _toConsumableArray2.default)(themePreferences.map( /*#__PURE__*/function () {
126
137
  var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(themeId) {
127
138
  return _regenerator.default.wrap(function _callee$(_context) {
128
139
  while (1) switch (_context.prev = _context.next) {
@@ -140,7 +151,44 @@ var setGlobalTheme = /*#__PURE__*/function () {
140
151
  return function (_x) {
141
152
  return _ref3.apply(this, arguments);
142
153
  };
143
- }()));
154
+ }())), [(0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
155
+ var mode, attrOfMissingCustomStyles, _yield$import, loadAndAppendCustomThemeCss;
156
+ return _regenerator.default.wrap(function _callee2$(_context2) {
157
+ while (1) switch (_context2.prev = _context2.next) {
158
+ case 0:
159
+ if (!(!themeLoader && UNSAFE_themeOptions && (0, _colorUtils.isValidBrandHex)(UNSAFE_themeOptions === null || UNSAFE_themeOptions === void 0 ? void 0 : UNSAFE_themeOptions.brandColor))) {
160
+ _context2.next = 11;
161
+ break;
162
+ }
163
+ mode = colorMode || themeStateDefaults['colorMode'];
164
+ attrOfMissingCustomStyles = (0, _customThemeLoadingUtils.findMissingCustomStyleElements)(UNSAFE_themeOptions, mode);
165
+ if (!(attrOfMissingCustomStyles.length === 0)) {
166
+ _context2.next = 5;
167
+ break;
168
+ }
169
+ return _context2.abrupt("return", false);
170
+ case 5:
171
+ _context2.next = 7;
172
+ return Promise.resolve().then(function () {
173
+ return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
174
+ './custom-theme'));
175
+ });
176
+ case 7:
177
+ _yield$import = _context2.sent;
178
+ loadAndAppendCustomThemeCss = _yield$import.loadAndAppendCustomThemeCss;
179
+ _context2.next = 11;
180
+ return loadAndAppendCustomThemeCss({
181
+ colorMode: attrOfMissingCustomStyles.length === 2 ? 'auto' :
182
+ // only load the missing custom theme styles
183
+ attrOfMissingCustomStyles[0],
184
+ UNSAFE_themeOptions: UNSAFE_themeOptions
185
+ });
186
+ case 11:
187
+ case "end":
188
+ return _context2.stop();
189
+ }
190
+ }, _callee2);
191
+ }))()]));
144
192
  case 6:
145
193
  if (colorMode === 'auto' && darkModeMql) {
146
194
  colorMode = darkModeMql.matches ? 'dark' : 'light';
@@ -159,20 +207,21 @@ var setGlobalTheme = /*#__PURE__*/function () {
159
207
  light: light,
160
208
  shape: shape,
161
209
  spacing: spacing,
162
- typography: typography
210
+ typography: typography,
211
+ UNSAFE_themeOptions: themeLoader ? undefined : UNSAFE_themeOptions
163
212
  });
164
- Object.entries(themeAttributes).forEach(function (_ref4) {
165
- var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
166
- key = _ref5[0],
167
- value = _ref5[1];
213
+ Object.entries(themeAttributes).forEach(function (_ref5) {
214
+ var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
215
+ key = _ref6[0],
216
+ value = _ref6[1];
168
217
  document.documentElement.setAttribute(key, value);
169
218
  });
170
- return _context2.abrupt("return", unbindThemeChangeListener);
219
+ return _context3.abrupt("return", unbindThemeChangeListener);
171
220
  case 10:
172
221
  case "end":
173
- return _context2.stop();
222
+ return _context3.stop();
174
223
  }
175
- }, _callee2);
224
+ }, _callee3);
176
225
  }));
177
226
  return function setGlobalTheme() {
178
227
  return _ref.apply(this, arguments);
@@ -189,15 +238,16 @@ var setGlobalTheme = /*#__PURE__*/function () {
189
238
  * @param {string} themeState.shape The shape theme to be applied.
190
239
  * @param {string} themeState.spacing The spacing theme to be applied.
191
240
  * @param {string} themeState.typography The typography theme to be applied.
241
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
192
242
  *
193
243
  * @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
194
- * If an error is encountered while loading themes, the themes arrav will be emptv.
244
+ * If an error is encountered while loading themes, the themes array will be empty.
195
245
  */
196
246
  var getThemeStyles = /*#__PURE__*/function () {
197
- var _ref6 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(preferences) {
247
+ var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee6(preferences) {
198
248
  var themePreferences, results;
199
- return _regenerator.default.wrap(function _callee4$(_context4) {
200
- while (1) switch (_context4.prev = _context4.next) {
249
+ return _regenerator.default.wrap(function _callee6$(_context6) {
250
+ while (1) switch (_context6.prev = _context6.next) {
201
251
  case 0:
202
252
  if (preferences === 'all') {
203
253
  themePreferences = _themeConfig.themeIdsWithOverrides;
@@ -211,19 +261,19 @@ var getThemeStyles = /*#__PURE__*/function () {
211
261
  typography: (preferences === null || preferences === void 0 ? void 0 : preferences.typography) || themeStateDefaults['typography']
212
262
  });
213
263
  }
214
- _context4.next = 3;
215
- return Promise.all(themePreferences.map( /*#__PURE__*/function () {
216
- var _ref7 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee3(themeId) {
264
+ _context6.next = 3;
265
+ return Promise.all([].concat((0, _toConsumableArray2.default)(themePreferences.map( /*#__PURE__*/function () {
266
+ var _ref8 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee4(themeId) {
217
267
  var css;
218
- return _regenerator.default.wrap(function _callee3$(_context3) {
219
- while (1) switch (_context3.prev = _context3.next) {
268
+ return _regenerator.default.wrap(function _callee4$(_context4) {
269
+ while (1) switch (_context4.prev = _context4.next) {
220
270
  case 0:
221
- _context3.prev = 0;
222
- _context3.next = 3;
271
+ _context4.prev = 0;
272
+ _context4.next = 3;
223
273
  return (0, _themeLoading.loadThemeCss)(themeId);
224
274
  case 3:
225
- css = _context3.sent;
226
- return _context3.abrupt("return", {
275
+ css = _context4.sent;
276
+ return _context4.abrupt("return", {
227
277
  id: themeId,
228
278
  attrs: {
229
279
  'data-theme': themeId
@@ -231,32 +281,70 @@ var getThemeStyles = /*#__PURE__*/function () {
231
281
  css: css
232
282
  });
233
283
  case 7:
234
- _context3.prev = 7;
235
- _context3.t0 = _context3["catch"](0);
236
- return _context3.abrupt("return", undefined);
284
+ _context4.prev = 7;
285
+ _context4.t0 = _context4["catch"](0);
286
+ return _context4.abrupt("return", undefined);
237
287
  case 10:
238
288
  case "end":
239
- return _context3.stop();
289
+ return _context4.stop();
240
290
  }
241
- }, _callee3, null, [[0, 7]]);
291
+ }, _callee4, null, [[0, 7]]);
242
292
  }));
243
293
  return function (_x3) {
244
- return _ref7.apply(this, arguments);
294
+ return _ref8.apply(this, arguments);
245
295
  };
246
- }()));
296
+ }())), [
297
+ // Add custom themes if they're present
298
+ (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee5() {
299
+ var _preferences$UNSAFE_t;
300
+ var _yield$import2, getCustomThemeStyles, customThemeStyles;
301
+ return _regenerator.default.wrap(function _callee5$(_context5) {
302
+ while (1) switch (_context5.prev = _context5.next) {
303
+ case 0:
304
+ if (!(preferences !== 'all' && preferences !== null && preferences !== void 0 && preferences.UNSAFE_themeOptions && (0, _colorUtils.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))) {
305
+ _context5.next = 15;
306
+ break;
307
+ }
308
+ _context5.prev = 1;
309
+ _context5.next = 4;
310
+ return Promise.resolve().then(function () {
311
+ return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
312
+ './custom-theme'));
313
+ });
314
+ case 4:
315
+ _yield$import2 = _context5.sent;
316
+ getCustomThemeStyles = _yield$import2.getCustomThemeStyles;
317
+ _context5.next = 8;
318
+ return getCustomThemeStyles({
319
+ colorMode: (preferences === null || preferences === void 0 ? void 0 : preferences.colorMode) || themeStateDefaults['colorMode'],
320
+ UNSAFE_themeOptions: preferences === null || preferences === void 0 ? void 0 : preferences.UNSAFE_themeOptions
321
+ });
322
+ case 8:
323
+ customThemeStyles = _context5.sent;
324
+ return _context5.abrupt("return", customThemeStyles);
325
+ case 12:
326
+ _context5.prev = 12;
327
+ _context5.t0 = _context5["catch"](1);
328
+ return _context5.abrupt("return", undefined);
329
+ case 15:
330
+ case "end":
331
+ return _context5.stop();
332
+ }
333
+ }, _callee5, null, [[1, 12]]);
334
+ }))()]));
247
335
  case 3:
248
- results = _context4.sent;
249
- return _context4.abrupt("return", results.filter(function (theme) {
336
+ results = _context6.sent;
337
+ return _context6.abrupt("return", results.flat().filter(function (theme) {
250
338
  return theme !== undefined;
251
339
  }));
252
340
  case 5:
253
341
  case "end":
254
- return _context4.stop();
342
+ return _context6.stop();
255
343
  }
256
- }, _callee4);
344
+ }, _callee6);
257
345
  }));
258
346
  return function getThemeStyles(_x2) {
259
- return _ref6.apply(this, arguments);
347
+ return _ref7.apply(this, arguments);
260
348
  };
261
349
  }();
262
350
 
@@ -270,25 +358,28 @@ var getThemeStyles = /*#__PURE__*/function () {
270
358
  * @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
271
359
  * @param {string} themeState.spacing The spacing theme to be applied.
272
360
  * @param {string} themeState.typography The typography theme to be applied.
361
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
273
362
  *
274
363
  * @returns {Object} Object of HTML attributes to be applied to the document root
275
364
  */
276
365
  exports.getThemeStyles = getThemeStyles;
277
366
  var getThemeHtmlAttrs = function getThemeHtmlAttrs() {
278
- var _ref9;
279
- var _ref8 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
280
- _ref8$colorMode = _ref8.colorMode,
281
- colorMode = _ref8$colorMode === void 0 ? themeStateDefaults['colorMode'] : _ref8$colorMode,
282
- _ref8$dark = _ref8.dark,
283
- dark = _ref8$dark === void 0 ? themeStateDefaults['dark'] : _ref8$dark,
284
- _ref8$light = _ref8.light,
285
- light = _ref8$light === void 0 ? themeStateDefaults['light'] : _ref8$light,
286
- _ref8$shape = _ref8.shape,
287
- shape = _ref8$shape === void 0 ? themeStateDefaults['shape'] : _ref8$shape,
288
- _ref8$spacing = _ref8.spacing,
289
- spacing = _ref8$spacing === void 0 ? themeStateDefaults['spacing'] : _ref8$spacing,
290
- _ref8$typography = _ref8.typography,
291
- typography = _ref8$typography === void 0 ? themeStateDefaults['typography'] : _ref8$typography;
367
+ var _result;
368
+ var _ref10 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
369
+ _ref10$colorMode = _ref10.colorMode,
370
+ colorMode = _ref10$colorMode === void 0 ? themeStateDefaults['colorMode'] : _ref10$colorMode,
371
+ _ref10$dark = _ref10.dark,
372
+ dark = _ref10$dark === void 0 ? themeStateDefaults['dark'] : _ref10$dark,
373
+ _ref10$light = _ref10.light,
374
+ light = _ref10$light === void 0 ? themeStateDefaults['light'] : _ref10$light,
375
+ _ref10$shape = _ref10.shape,
376
+ shape = _ref10$shape === void 0 ? themeStateDefaults['shape'] : _ref10$shape,
377
+ _ref10$spacing = _ref10.spacing,
378
+ spacing = _ref10$spacing === void 0 ? themeStateDefaults['spacing'] : _ref10$spacing,
379
+ _ref10$typography = _ref10.typography,
380
+ typography = _ref10$typography === void 0 ? themeStateDefaults['typography'] : _ref10$typography,
381
+ _ref10$UNSAFE_themeOp = _ref10.UNSAFE_themeOptions,
382
+ UNSAFE_themeOptions = _ref10$UNSAFE_themeOp === void 0 ? themeStateDefaults['UNSAFE_themeOptions'] : _ref10$UNSAFE_themeOp;
292
383
  var themePreferences = {
293
384
  dark: dark,
294
385
  light: light,
@@ -308,7 +399,13 @@ var getThemeHtmlAttrs = function getThemeHtmlAttrs() {
308
399
  };
309
400
  }
310
401
  var themeAttribute = (0, _themeStateTransformer.themeObjectToString)(themePreferences);
311
- return _ref9 = {}, (0, _defineProperty2.default)(_ref9, _constants.THEME_DATA_ATTRIBUTE, themeAttribute), (0, _defineProperty2.default)(_ref9, _constants.COLOR_MODE_ATTRIBUTE, colorMode === 'auto' ? defaultColorMode : colorMode), _ref9;
402
+ var result = (_result = {}, (0, _defineProperty2.default)(_result, _constants.THEME_DATA_ATTRIBUTE, themeAttribute), (0, _defineProperty2.default)(_result, _constants.COLOR_MODE_ATTRIBUTE, colorMode === 'auto' ? defaultColorMode : colorMode), _result);
403
+ if (UNSAFE_themeOptions && (0, _colorUtils.isValidBrandHex)(UNSAFE_themeOptions.brandColor)) {
404
+ var optionString = JSON.stringify(UNSAFE_themeOptions);
405
+ var uniqueId = (0, _hash.hash)(optionString);
406
+ result[_constants.CUSTOM_THEME_ATTRIBUTE] = uniqueId;
407
+ }
408
+ return result;
312
409
  };
313
410
 
314
411
  /**
@@ -8,7 +8,7 @@ var color = {
8
8
  color: {
9
9
  border: {
10
10
  input: {
11
- value: 'DarkNeutral500'
11
+ value: 'DarkNeutral600'
12
12
  }
13
13
  }
14
14
  }