@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
@@ -0,0 +1,32 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ Object.defineProperty(exports, "Contrast", {
7
+ enumerable: true,
8
+ get: function get() {
9
+ return _contrast.Contrast;
10
+ }
11
+ });
12
+ Object.defineProperty(exports, "Hct", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _hct.Hct;
16
+ }
17
+ });
18
+ Object.defineProperty(exports, "argbFromRgba", {
19
+ enumerable: true,
20
+ get: function get() {
21
+ return _colorUtils.argbFromRgba;
22
+ }
23
+ });
24
+ Object.defineProperty(exports, "rgbaFromArgb", {
25
+ enumerable: true,
26
+ get: function get() {
27
+ return _colorUtils.rgbaFromArgb;
28
+ }
29
+ });
30
+ var _hct = require("./hct");
31
+ var _contrast = require("./contrast");
32
+ var _colorUtils = require("./color-utils");
@@ -0,0 +1,159 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.clampDouble = clampDouble;
7
+ exports.clampInt = clampInt;
8
+ exports.differenceDegrees = differenceDegrees;
9
+ exports.lerp = lerp;
10
+ exports.matrixMultiply = matrixMultiply;
11
+ exports.rotationDirection = rotationDirection;
12
+ exports.sanitizeDegreesDouble = sanitizeDegreesDouble;
13
+ exports.sanitizeDegreesInt = sanitizeDegreesInt;
14
+ exports.signum = signum;
15
+ /**
16
+ * Below lines are copied from @material/material-color-utilities.
17
+ * Do not modify it.
18
+ */
19
+
20
+ /**
21
+ * @license
22
+ * Copyright 2021 Google LLC
23
+ *
24
+ * Licensed under the Apache License, Version 2.0 (the "License");
25
+ * you may not use this file except in compliance with the License.
26
+ * You may obtain a copy of the License at
27
+ *
28
+ * http://www.apache.org/licenses/LICENSE-2.0
29
+ *
30
+ * Unless required by applicable law or agreed to in writing, software
31
+ * distributed under the License is distributed on an "AS IS" BASIS,
32
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33
+ * See the License for the specific language governing permissions and
34
+ * limitations under the License.
35
+ */
36
+
37
+ // This file is automatically generated. Do not modify it.
38
+
39
+ /**
40
+ * Utility methods for mathematical operations.
41
+ */
42
+
43
+ /**
44
+ * The signum function.
45
+ *
46
+ * @return 1 if num > 0, -1 if num < 0, and 0 if num = 0
47
+ */
48
+ function signum(num) {
49
+ if (num < 0) {
50
+ return -1;
51
+ } else if (num === 0) {
52
+ return 0;
53
+ } else {
54
+ return 1;
55
+ }
56
+ }
57
+
58
+ /**
59
+ * The linear interpolation function.
60
+ *
61
+ * @return start if amount = 0 and stop if amount = 1
62
+ */
63
+ function lerp(start, stop, amount) {
64
+ return (1.0 - amount) * start + amount * stop;
65
+ }
66
+
67
+ /**
68
+ * Clamps an integer between two integers.
69
+ *
70
+ * @return input when min <= input <= max, and either min or max
71
+ * otherwise.
72
+ */
73
+ function clampInt(min, max, input) {
74
+ if (input < min) {
75
+ return min;
76
+ } else if (input > max) {
77
+ return max;
78
+ }
79
+ return input;
80
+ }
81
+
82
+ /**
83
+ * Clamps an integer between two floating-point numbers.
84
+ *
85
+ * @return input when min <= input <= max, and either min or max
86
+ * otherwise.
87
+ */
88
+ function clampDouble(min, max, input) {
89
+ if (input < min) {
90
+ return min;
91
+ } else if (input > max) {
92
+ return max;
93
+ }
94
+ return input;
95
+ }
96
+
97
+ /**
98
+ * Sanitizes a degree measure as an integer.
99
+ *
100
+ * @return a degree measure between 0 (inclusive) and 360
101
+ * (exclusive).
102
+ */
103
+ function sanitizeDegreesInt(degrees) {
104
+ degrees = degrees % 360;
105
+ if (degrees < 0) {
106
+ degrees = degrees + 360;
107
+ }
108
+ return degrees;
109
+ }
110
+
111
+ /**
112
+ * Sanitizes a degree measure as a floating-point number.
113
+ *
114
+ * @return a degree measure between 0.0 (inclusive) and 360.0
115
+ * (exclusive).
116
+ */
117
+ function sanitizeDegreesDouble(degrees) {
118
+ degrees = degrees % 360.0;
119
+ if (degrees < 0) {
120
+ degrees = degrees + 360.0;
121
+ }
122
+ return degrees;
123
+ }
124
+
125
+ /**
126
+ * Sign of direction change needed to travel from one angle to
127
+ * another.
128
+ *
129
+ * For angles that are 180 degrees apart from each other, both
130
+ * directions have the same travel distance, so either direction is
131
+ * shortest. The value 1.0 is returned in this case.
132
+ *
133
+ * @param from The angle travel starts from, in degrees.
134
+ * @param to The angle travel ends at, in degrees.
135
+ * @return -1 if decreasing from leads to the shortest travel
136
+ * distance, 1 if increasing from leads to the shortest travel
137
+ * distance.
138
+ */
139
+ function rotationDirection(from, to) {
140
+ var increasingDifference = sanitizeDegreesDouble(to - from);
141
+ return increasingDifference <= 180.0 ? 1.0 : -1.0;
142
+ }
143
+
144
+ /**
145
+ * Distance of two points on a circle, represented using degrees.
146
+ */
147
+ function differenceDegrees(a, b) {
148
+ return 180.0 - Math.abs(Math.abs(a - b) - 180.0);
149
+ }
150
+
151
+ /**
152
+ * Multiplies a 1x3 row vector with a 3x3 matrix.
153
+ */
154
+ function matrixMultiply(row, matrix) {
155
+ var a = row[0] * matrix[0][0] + row[1] * matrix[0][1] + row[2] * matrix[0][2];
156
+ var b = row[0] * matrix[1][0] + row[1] * matrix[1][1] + row[2] * matrix[1][2];
157
+ var c = row[0] * matrix[2][0] + row[1] * matrix[2][1] + row[2] * matrix[2][2];
158
+ return [a, b, c];
159
+ }
@@ -15,7 +15,7 @@ var loadAndAppendThemeCss = /*#__PURE__*/function () {
15
15
  return _regenerator.default.wrap(function _callee$(_context) {
16
16
  while (1) switch (_context.prev = _context.next) {
17
17
  case 0:
18
- if (!document.head.querySelector("style[".concat(_constants.THEME_DATA_ATTRIBUTE, "=\"").concat(themeId, "\"]"))) {
18
+ if (!document.head.querySelector("style[".concat(_constants.THEME_DATA_ATTRIBUTE, "=\"").concat(themeId, "\"]:not([").concat(_constants.CUSTOM_THEME_ATTRIBUTE, "])"))) {
19
19
  _context.next = 2;
20
20
  break;
21
21
  }
@@ -68,7 +68,7 @@ var themeObjectToString = function themeObjectToString(themeState) {
68
68
  var _ref4 = (0, _slicedToArray2.default)(_ref3, 2),
69
69
  kind = _ref4[0],
70
70
  id = _ref4[1];
71
- return (kind === 'colorMode' || isThemeKind(kind)) && (isThemeIds(id) || isColorMode(id)) ? themeString + "".concat(themeString ? ' ' : '') + "".concat(kind, ":").concat(id) : themeString;
71
+ return (kind === 'colorMode' || isThemeKind(kind)) && typeof id === 'string' && (isThemeIds(id) || isColorMode(id)) ? themeString + "".concat(themeString ? ' ' : '') + "".concat(kind, ":").concat(id) : themeString;
72
72
  }, '');
73
73
  };
74
74
  exports.themeObjectToString = themeObjectToString;
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/tokens",
3
- "version": "1.11.2",
3
+ "version": "1.12.0",
4
4
  "sideEffects": [
5
5
  "**/*.css"
6
6
  ]
@@ -0,0 +1,17 @@
1
+ /**
2
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
+ *
4
+ * Token names mapped to their values, used for contrast checking when generating custom themes
5
+ *
6
+ * @codegen <<SignedSource::1ddd5cd744975e8df5a191332ec8a42c>>
7
+ * @codegenCommand yarn build tokens
8
+ */
9
+ const tokenValues = {
10
+ 'color.text.brand': '#579DFF',
11
+ 'elevation.surface.overlay': '#282E33',
12
+ 'color.text.selected': '#579DFF',
13
+ 'color.background.selected': '#092957',
14
+ 'color.border.brand': '#579DFF',
15
+ 'color.chart.brand': '#388BFF'
16
+ };
17
+ export default tokenValues;
@@ -0,0 +1,17 @@
1
+ /**
2
+ * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
+ *
4
+ * Token names mapped to their values, used for contrast checking when generating custom themes
5
+ *
6
+ * @codegen <<SignedSource::b59877585fad151840dbf6c212c56e34>>
7
+ * @codegenCommand yarn build tokens
8
+ */
9
+ const tokenValues = {
10
+ 'color.text.brand': '#0C66E4',
11
+ 'elevation.surface.sunken': '#F7F8F9',
12
+ 'color.text.selected': '#0C66E4',
13
+ 'color.background.selected': '#E9F2FF',
14
+ 'color.border.brand': '#0C66E4',
15
+ 'color.chart.brand': '#1D7AFC'
16
+ };
17
+ export default tokenValues;
@@ -1,12 +1,12 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::b255ff03ae4f781bb3016003a111bed0>>
3
+ * @codegen <<SignedSource::cadad94754b78a066c340ab42eca9721>>
4
4
  * @codegenCommand yarn build tokens
5
5
  */
6
6
  export default `
7
7
  html[data-color-mode="light"][data-theme~="light:dark"],
8
8
  html[data-color-mode="dark"][data-theme~="dark:dark"] {
9
9
  color-scheme: dark;
10
- --ds-border-input: #596773;
10
+ --ds-border-input: #738496;
11
11
  }
12
12
  `;
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
3
- * @codegen <<SignedSource::2c7e6a36e75ad8b32981cc4bbaa378db>>
3
+ * @codegen <<SignedSource::a87638614efbe4415e8ffd370dd4ce76>>
4
4
  * @codegenCommand yarn build tokens
5
5
  */
6
6
  const tokens = [{
@@ -10,7 +10,7 @@ const tokens = [{
10
10
  "introduced": "0.6.0",
11
11
  "description": "Use for borders of form UI elements, such as text fields, checkboxes, and radio buttons."
12
12
  },
13
- "value": "#596773",
13
+ "value": "#738496",
14
14
  "filePath": "src/tokens/atlassian-dark-new-input-border/color/border.tsx",
15
15
  "isSource": true,
16
16
  "original": {
@@ -20,7 +20,7 @@ const tokens = [{
20
20
  "introduced": "0.6.0",
21
21
  "description": "Use for borders of form UI elements, such as text fields, checkboxes, and radio buttons."
22
22
  },
23
- "value": "DarkNeutral500"
23
+ "value": "DarkNeutral600"
24
24
  },
25
25
  "name": "color.border.input",
26
26
  "path": ["color", "border", "input"],
@@ -1,5 +1,6 @@
1
1
  export const THEME_DATA_ATTRIBUTE = 'data-theme';
2
2
  export const COLOR_MODE_ATTRIBUTE = 'data-color-mode';
3
+ export const CUSTOM_THEME_ATTRIBUTE = 'data-custom-theme';
3
4
  export const DEFAULT_THEME = 'light';
4
5
  export const CSS_PREFIX = 'ds';
5
6
  export const CSS_VAR_FULL = ['opacity', 'font', 'space', 'border'];
@@ -0,0 +1,77 @@
1
+ import { COLOR_MODE_ATTRIBUTE, CUSTOM_THEME_ATTRIBUTE } from './constants';
2
+ import { themeStateDefaults } from './set-global-theme';
3
+ import { limitSizeOfCustomStyleElements, reduceTokenMap } from './utils/custom-theme-loading-utils';
4
+ import { generateColors, generateTokenMapWithContrastCheck } from './utils/generate-custom-color-ramp';
5
+ import { hash } from './utils/hash';
6
+ export const CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = 10;
7
+ /**
8
+ *
9
+ * @param themeSchema The schema of available themes
10
+ * @returns a string with the CSS for the custom theme
11
+ */
12
+ /**
13
+ * Takes a color mode and custom branding options, and returns an array of objects for use in applying custom styles to the document head.
14
+ * 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.
15
+ *
16
+ * @param {Object<string, string>} themeState The themes and color mode that should be applied.
17
+ * @param {string} themeState.colorMode Determines which color theme is 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
+ export async function getCustomThemeStyles(themeState) {
24
+ var _themeState$UNSAFE_th;
25
+ const 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;
26
+ const mode = (themeState === null || themeState === void 0 ? void 0 : themeState.colorMode) || themeStateDefaults['colorMode'];
27
+ const optionString = JSON.stringify(themeState === null || themeState === void 0 ? void 0 : themeState.UNSAFE_themeOptions);
28
+ const uniqueId = hash(optionString);
29
+ const themeRamp = generateColors(brandColor);
30
+
31
+ // outputs object to generate to CSS from
32
+ const themes = [];
33
+ const tokenMaps = generateTokenMapWithContrastCheck(brandColor, mode, themeRamp);
34
+ if ((mode === 'light' || mode === 'auto') && tokenMaps.light) {
35
+ // Light mode theming
36
+ themes.push({
37
+ id: 'light',
38
+ attrs: {
39
+ 'data-theme': 'light',
40
+ 'data-custom-theme': uniqueId
41
+ },
42
+ css: `
43
+ html[${CUSTOM_THEME_ATTRIBUTE}="${uniqueId}"][${COLOR_MODE_ATTRIBUTE}="light"][data-theme~="light:light"] {
44
+ /* Branded tokens */
45
+ ${reduceTokenMap(tokenMaps.light, themeRamp)}
46
+ }`
47
+ });
48
+ }
49
+ if ((mode === 'dark' || mode === 'auto') && tokenMaps.dark) {
50
+ // Dark mode theming
51
+ themes.push({
52
+ id: 'dark',
53
+ attrs: {
54
+ 'data-theme': 'dark',
55
+ 'data-custom-theme': uniqueId
56
+ },
57
+ css: `
58
+ html[${CUSTOM_THEME_ATTRIBUTE}="${uniqueId}"][${COLOR_MODE_ATTRIBUTE}="dark"][data-theme~="dark:dark"] {
59
+ /* Branded tokens */
60
+ ${reduceTokenMap(tokenMaps.dark, themeRamp)}
61
+ }`
62
+ });
63
+ }
64
+ return themes;
65
+ }
66
+ export async function loadAndAppendCustomThemeCss(themeState) {
67
+ getCustomThemeStyles(themeState).then(themes => {
68
+ limitSizeOfCustomStyleElements(CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD);
69
+ themes.map(theme => {
70
+ const styleTag = document.createElement('style');
71
+ document.head.appendChild(styleTag);
72
+ styleTag.dataset.theme = theme.attrs['data-theme'];
73
+ styleTag.dataset.customTheme = theme.attrs['data-custom-theme'];
74
+ styleTag.textContent = theme.css;
75
+ });
76
+ });
77
+ }
@@ -1,7 +1,7 @@
1
1
  import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  const name = "@atlaskit/tokens";
4
- const version = "1.11.2";
4
+ const version = "1.12.0";
5
5
  /**
6
6
  * Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
7
7
  * resulting CSS Custom Property.
@@ -2,7 +2,7 @@ import warnOnce from '@atlaskit/ds-lib/warn-once';
2
2
  import tokens from './artifacts/token-names';
3
3
  import { TOKEN_NOT_FOUND_CSS_VAR } from './constants';
4
4
  const name = "@atlaskit/tokens";
5
- const version = "1.11.2";
5
+ const version = "1.12.0";
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.
@@ -1,8 +1,11 @@
1
1
  import { bind } from 'bind-event-listener';
2
2
  import noop from '@atlaskit/ds-lib/noop';
3
3
  import { getBooleanFF } from '@atlaskit/platform-feature-flags';
4
- import { COLOR_MODE_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
4
+ import { COLOR_MODE_ATTRIBUTE, CUSTOM_THEME_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
5
5
  import { themeIdsWithOverrides } from './theme-config';
6
+ import { isValidBrandHex } from './utils/color-utils';
7
+ import { findMissingCustomStyleElements } from './utils/custom-theme-loading-utils';
8
+ import { hash } from './utils/hash';
6
9
  import { loadAndAppendThemeCss, loadThemeCss } from './utils/theme-loading';
7
10
  import { themeObjectToString } from './utils/theme-state-transformer';
8
11
 
@@ -13,13 +16,14 @@ const isMatchMediaAvailable = typeof window !== 'undefined' && 'matchMedia' in w
13
16
  const darkModeMediaQuery = '(prefers-color-scheme: dark)';
14
17
  const darkModeMql = isMatchMediaAvailable && window.matchMedia(darkModeMediaQuery);
15
18
  let unbindThemeChangeListener = noop;
16
- const themeStateDefaults = {
19
+ export const themeStateDefaults = {
17
20
  colorMode: 'auto',
18
21
  dark: 'dark',
19
22
  light: 'light',
20
23
  shape: undefined,
21
24
  spacing: undefined,
22
- typography: undefined
25
+ typography: undefined,
26
+ UNSAFE_themeOptions: undefined
23
27
  };
24
28
 
25
29
  /**
@@ -69,6 +73,7 @@ const getThemePreferences = themeState => {
69
73
  * @param {string} themeState.shape The shape theme to be applied.
70
74
  * @param {string} themeState.spacing The spacing theme to be applied.
71
75
  * @param {string} themeState.typography The typography theme to be applied.
76
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
72
77
  * @param {function} themeLoader Callback function used to override the default theme loading functionality.
73
78
  *
74
79
  * @returns A Promise of an unbind function, that can be used to stop listening for changes to system theme.
@@ -84,7 +89,8 @@ const setGlobalTheme = async ({
84
89
  light = themeStateDefaults['light'],
85
90
  shape = themeStateDefaults['shape'],
86
91
  spacing = themeStateDefaults['spacing'],
87
- typography = themeStateDefaults['typography']
92
+ typography = themeStateDefaults['typography'],
93
+ UNSAFE_themeOptions = themeStateDefaults['UNSAFE_themeOptions']
88
94
  } = {}, themeLoader) => {
89
95
  const themePreferences = getThemePreferences({
90
96
  colorMode,
@@ -95,7 +101,25 @@ const setGlobalTheme = async ({
95
101
  typography
96
102
  });
97
103
  const loadingStrategy = themeLoader ? themeLoader : loadAndAppendThemeCss;
98
- await Promise.all(themePreferences.map(async themeId => await loadingStrategy(themeId)));
104
+ await Promise.all([...themePreferences.map(async themeId => await loadingStrategy(themeId)), (async () => {
105
+ if (!themeLoader && UNSAFE_themeOptions && isValidBrandHex(UNSAFE_themeOptions === null || UNSAFE_themeOptions === void 0 ? void 0 : UNSAFE_themeOptions.brandColor)) {
106
+ const mode = colorMode || themeStateDefaults['colorMode'];
107
+ const attrOfMissingCustomStyles = findMissingCustomStyleElements(UNSAFE_themeOptions, mode);
108
+ if (attrOfMissingCustomStyles.length === 0) {
109
+ return false;
110
+ }
111
+ const {
112
+ loadAndAppendCustomThemeCss
113
+ } = await import( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
114
+ './custom-theme');
115
+ await loadAndAppendCustomThemeCss({
116
+ colorMode: attrOfMissingCustomStyles.length === 2 ? 'auto' :
117
+ // only load the missing custom theme styles
118
+ attrOfMissingCustomStyles[0],
119
+ UNSAFE_themeOptions
120
+ });
121
+ }
122
+ })()]);
99
123
  if (colorMode === 'auto' && darkModeMql) {
100
124
  colorMode = darkModeMql.matches ? 'dark' : 'light';
101
125
  // Add an event listener for changes to the system theme.
@@ -113,7 +137,8 @@ const setGlobalTheme = async ({
113
137
  light,
114
138
  shape,
115
139
  spacing,
116
- typography
140
+ typography,
141
+ UNSAFE_themeOptions: themeLoader ? undefined : UNSAFE_themeOptions
117
142
  });
118
143
  Object.entries(themeAttributes).forEach(([key, value]) => {
119
144
  document.documentElement.setAttribute(key, value);
@@ -131,9 +156,10 @@ const setGlobalTheme = async ({
131
156
  * @param {string} themeState.shape The shape theme to be applied.
132
157
  * @param {string} themeState.spacing The spacing theme to be applied.
133
158
  * @param {string} themeState.typography The typography theme to be applied.
159
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
134
160
  *
135
161
  * @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
136
- * If an error is encountered while loading themes, the themes arrav will be emptv.
162
+ * If an error is encountered while loading themes, the themes array will be empty.
137
163
  */
138
164
  export const getThemeStyles = async preferences => {
139
165
  let themePreferences;
@@ -149,7 +175,7 @@ export const getThemeStyles = async preferences => {
149
175
  typography: (preferences === null || preferences === void 0 ? void 0 : preferences.typography) || themeStateDefaults['typography']
150
176
  });
151
177
  }
152
- const results = await Promise.all(themePreferences.map(async themeId => {
178
+ const results = await Promise.all([...themePreferences.map(async themeId => {
153
179
  try {
154
180
  const css = await loadThemeCss(themeId);
155
181
  return {
@@ -160,11 +186,31 @@ export const getThemeStyles = async preferences => {
160
186
  css
161
187
  };
162
188
  } catch {
163
- // Return an empty string if there's an error loading it.
189
+ // Return undefined if there's an error loading it, will be filtered out later.
164
190
  return undefined;
165
191
  }
166
- }));
167
- return results.filter(theme => theme !== undefined);
192
+ }),
193
+ // Add custom themes if they're present
194
+ (async () => {
195
+ var _preferences$UNSAFE_t;
196
+ 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)) {
197
+ try {
198
+ const {
199
+ getCustomThemeStyles
200
+ } = await import( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
201
+ './custom-theme');
202
+ const customThemeStyles = await getCustomThemeStyles({
203
+ colorMode: (preferences === null || preferences === void 0 ? void 0 : preferences.colorMode) || themeStateDefaults['colorMode'],
204
+ UNSAFE_themeOptions: preferences === null || preferences === void 0 ? void 0 : preferences.UNSAFE_themeOptions
205
+ });
206
+ return customThemeStyles;
207
+ } catch {
208
+ // Return undefined if there's an error loading it, will be filtered out later.
209
+ return undefined;
210
+ }
211
+ }
212
+ })()]);
213
+ return results.flat().filter(theme => theme !== undefined);
168
214
  };
169
215
 
170
216
  /**
@@ -177,6 +223,7 @@ export const getThemeStyles = async preferences => {
177
223
  * @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
178
224
  * @param {string} themeState.spacing The spacing theme to be applied.
179
225
  * @param {string} themeState.typography The typography theme to be applied.
226
+ * @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
180
227
  *
181
228
  * @returns {Object} Object of HTML attributes to be applied to the document root
182
229
  */
@@ -186,7 +233,8 @@ export const getThemeHtmlAttrs = ({
186
233
  light = themeStateDefaults['light'],
187
234
  shape = themeStateDefaults['shape'],
188
235
  spacing = themeStateDefaults['spacing'],
189
- typography = themeStateDefaults['typography']
236
+ typography = themeStateDefaults['typography'],
237
+ UNSAFE_themeOptions = themeStateDefaults['UNSAFE_themeOptions']
190
238
  } = {}) => {
191
239
  let themePreferences = {
192
240
  dark,
@@ -207,10 +255,16 @@ export const getThemeHtmlAttrs = ({
207
255
  };
208
256
  }
209
257
  const themeAttribute = themeObjectToString(themePreferences);
210
- return {
258
+ const result = {
211
259
  [THEME_DATA_ATTRIBUTE]: themeAttribute,
212
260
  [COLOR_MODE_ATTRIBUTE]: colorMode === 'auto' ? defaultColorMode : colorMode
213
261
  };
262
+ if (UNSAFE_themeOptions && isValidBrandHex(UNSAFE_themeOptions.brandColor)) {
263
+ const optionString = JSON.stringify(UNSAFE_themeOptions);
264
+ const uniqueId = hash(optionString);
265
+ result[CUSTOM_THEME_ATTRIBUTE] = uniqueId;
266
+ }
267
+ return result;
214
268
  };
215
269
 
216
270
  /**
@@ -2,7 +2,7 @@ const color = {
2
2
  color: {
3
3
  border: {
4
4
  input: {
5
- value: 'DarkNeutral500'
5
+ value: 'DarkNeutral600'
6
6
  }
7
7
  }
8
8
  }