@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.
- package/CHANGELOG.md +20 -0
- package/dist/cjs/artifacts/atlassian-dark-token-value-for-contrast-check.js +24 -0
- package/dist/cjs/artifacts/atlassian-light-token-value-for-contrast-check.js +24 -0
- package/dist/cjs/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
- package/dist/cjs/constants.js +3 -1
- package/dist/cjs/custom-theme.js +108 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/set-global-theme.js +156 -59
- package/dist/cjs/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
- package/dist/cjs/utils/color-utils.js +178 -0
- package/dist/cjs/utils/custom-theme-loading-utils.js +47 -0
- package/dist/cjs/utils/custom-theme-token-contrast-check.js +74 -0
- package/dist/cjs/utils/generate-custom-color-ramp.js +213 -0
- package/dist/cjs/utils/hash.js +17 -0
- package/dist/cjs/utils/hct-color-utils/color-utils.js +310 -0
- package/dist/cjs/utils/hct-color-utils/contrast.js +188 -0
- package/dist/cjs/utils/hct-color-utils/hct.js +1036 -0
- package/dist/cjs/utils/hct-color-utils/index.js +32 -0
- package/dist/cjs/utils/hct-color-utils/math-utils.js +159 -0
- package/dist/cjs/utils/theme-loading.js +1 -1
- package/dist/cjs/utils/theme-state-transformer.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/artifacts/atlassian-dark-token-value-for-contrast-check.js +17 -0
- package/dist/es2019/artifacts/atlassian-light-token-value-for-contrast-check.js +17 -0
- package/dist/es2019/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
- package/dist/es2019/constants.js +1 -0
- package/dist/es2019/custom-theme.js +77 -0
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/set-global-theme.js +67 -13
- package/dist/es2019/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
- package/dist/es2019/utils/color-utils.js +154 -0
- package/dist/es2019/utils/custom-theme-loading-utils.js +31 -0
- package/dist/es2019/utils/custom-theme-token-contrast-check.js +68 -0
- package/dist/es2019/utils/generate-custom-color-ramp.js +187 -0
- package/dist/es2019/utils/hash.js +10 -0
- package/dist/es2019/utils/hct-color-utils/color-utils.js +286 -0
- package/dist/es2019/utils/hct-color-utils/contrast.js +161 -0
- package/dist/es2019/utils/hct-color-utils/hct.js +931 -0
- package/dist/es2019/utils/hct-color-utils/index.js +3 -0
- package/dist/es2019/utils/hct-color-utils/math-utils.js +145 -0
- package/dist/es2019/utils/theme-loading.js +2 -2
- package/dist/es2019/utils/theme-state-transformer.js +3 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/artifacts/atlassian-dark-token-value-for-contrast-check.js +17 -0
- package/dist/esm/artifacts/atlassian-light-token-value-for-contrast-check.js +17 -0
- package/dist/esm/artifacts/themes/atlassian-dark-new-input-border.js +2 -2
- package/dist/esm/artifacts/tokens-raw/atlassian-dark-new-input-border.js +3 -3
- package/dist/esm/constants.js +1 -0
- package/dist/esm/custom-theme.js +98 -0
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/set-global-theme.js +149 -60
- package/dist/esm/tokens/atlassian-dark-new-input-border/color/border.js +1 -1
- package/dist/esm/utils/color-utils.js +162 -0
- package/dist/esm/utils/custom-theme-loading-utils.js +38 -0
- package/dist/esm/utils/custom-theme-token-contrast-check.js +65 -0
- package/dist/esm/utils/generate-custom-color-ramp.js +202 -0
- package/dist/esm/utils/hash.js +10 -0
- package/dist/esm/utils/hct-color-utils/color-utils.js +285 -0
- package/dist/esm/utils/hct-color-utils/contrast.js +181 -0
- package/dist/esm/utils/hct-color-utils/hct.js +1029 -0
- package/dist/esm/utils/hct-color-utils/index.js +3 -0
- package/dist/esm/utils/hct-color-utils/math-utils.js +145 -0
- package/dist/esm/utils/theme-loading.js +2 -2
- package/dist/esm/utils/theme-state-transformer.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/types/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types/artifacts/themes/atlassian-dark-new-input-border.d.ts +2 -2
- package/dist/types/artifacts/tokens-raw/atlassian-dark-new-input-border.d.ts +1 -1
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/custom-theme.d.ts +30 -0
- package/dist/types/index.d.ts +1 -0
- package/dist/types/set-global-theme.d.ts +9 -3
- package/dist/types/tokens/atlassian-dark/utility/utility.d.ts +1 -1
- package/dist/types/tokens/atlassian-light/utility/utility.d.ts +1 -1
- package/dist/types/tokens/default/utility/utility.d.ts +1 -1
- package/dist/types/utils/color-utils.d.ts +10 -0
- package/dist/types/utils/custom-theme-loading-utils.d.ts +11 -0
- package/dist/types/utils/custom-theme-token-contrast-check.d.ts +20 -0
- package/dist/types/utils/generate-custom-color-ramp.d.ts +19 -0
- package/dist/types/utils/hash.d.ts +1 -0
- package/dist/types/utils/hct-color-utils/color-utils.d.ts +131 -0
- package/dist/types/utils/hct-color-utils/contrast.d.ts +78 -0
- package/dist/types/utils/hct-color-utils/hct.d.ts +137 -0
- package/dist/types/utils/hct-color-utils/index.d.ts +3 -0
- package/dist/types/utils/hct-color-utils/math-utils.d.ts +86 -0
- package/dist/types-ts4.5/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types-ts4.5/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +17 -0
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark-new-input-border.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark-new-input-border.d.ts +1 -1
- package/dist/types-ts4.5/constants.d.ts +1 -0
- package/dist/types-ts4.5/custom-theme.d.ts +30 -0
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/set-global-theme.d.ts +9 -3
- package/dist/types-ts4.5/tokens/atlassian-dark/utility/utility.d.ts +1 -1
- package/dist/types-ts4.5/tokens/atlassian-light/utility/utility.d.ts +1 -1
- package/dist/types-ts4.5/tokens/default/utility/utility.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-utils.d.ts +27 -0
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +11 -0
- package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +20 -0
- package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +19 -0
- package/dist/types-ts4.5/utils/hash.d.ts +1 -0
- package/dist/types-ts4.5/utils/hct-color-utils/color-utils.d.ts +131 -0
- package/dist/types-ts4.5/utils/hct-color-utils/contrast.d.ts +78 -0
- package/dist/types-ts4.5/utils/hct-color-utils/hct.d.ts +137 -0
- package/dist/types-ts4.5/utils/hct-color-utils/index.d.ts +3 -0
- package/dist/types-ts4.5/utils/hct-color-utils/math-utils.d.ts +86 -0
- package/figma/atlassian-dark-new-input-border.json +1 -1
- package/package.json +35 -40
- package/report.api.md +24 -1
- package/tmp/api-report-tmp.d.ts +0 -1132
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Below lines are copied from @material/material-color-utilities.
|
|
3
|
+
* Do not modify it.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* @license
|
|
8
|
+
* Copyright 2021 Google LLC
|
|
9
|
+
*
|
|
10
|
+
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
11
|
+
* you may not use this file except in compliance with the License.
|
|
12
|
+
* You may obtain a copy of the License at
|
|
13
|
+
*
|
|
14
|
+
* http://www.apache.org/licenses/LICENSE-2.0
|
|
15
|
+
*
|
|
16
|
+
* Unless required by applicable law or agreed to in writing, software
|
|
17
|
+
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
18
|
+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
19
|
+
* See the License for the specific language governing permissions and
|
|
20
|
+
* limitations under the License.
|
|
21
|
+
*/
|
|
22
|
+
|
|
23
|
+
// This file is automatically generated. Do not modify it.
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Utility methods for mathematical operations.
|
|
27
|
+
*/
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* The signum function.
|
|
31
|
+
*
|
|
32
|
+
* @return 1 if num > 0, -1 if num < 0, and 0 if num = 0
|
|
33
|
+
*/
|
|
34
|
+
export function signum(num) {
|
|
35
|
+
if (num < 0) {
|
|
36
|
+
return -1;
|
|
37
|
+
} else if (num === 0) {
|
|
38
|
+
return 0;
|
|
39
|
+
} else {
|
|
40
|
+
return 1;
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* The linear interpolation function.
|
|
46
|
+
*
|
|
47
|
+
* @return start if amount = 0 and stop if amount = 1
|
|
48
|
+
*/
|
|
49
|
+
export function lerp(start, stop, amount) {
|
|
50
|
+
return (1.0 - amount) * start + amount * stop;
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Clamps an integer between two integers.
|
|
55
|
+
*
|
|
56
|
+
* @return input when min <= input <= max, and either min or max
|
|
57
|
+
* otherwise.
|
|
58
|
+
*/
|
|
59
|
+
export function clampInt(min, max, input) {
|
|
60
|
+
if (input < min) {
|
|
61
|
+
return min;
|
|
62
|
+
} else if (input > max) {
|
|
63
|
+
return max;
|
|
64
|
+
}
|
|
65
|
+
return input;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Clamps an integer between two floating-point numbers.
|
|
70
|
+
*
|
|
71
|
+
* @return input when min <= input <= max, and either min or max
|
|
72
|
+
* otherwise.
|
|
73
|
+
*/
|
|
74
|
+
export function clampDouble(min, max, input) {
|
|
75
|
+
if (input < min) {
|
|
76
|
+
return min;
|
|
77
|
+
} else if (input > max) {
|
|
78
|
+
return max;
|
|
79
|
+
}
|
|
80
|
+
return input;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* Sanitizes a degree measure as an integer.
|
|
85
|
+
*
|
|
86
|
+
* @return a degree measure between 0 (inclusive) and 360
|
|
87
|
+
* (exclusive).
|
|
88
|
+
*/
|
|
89
|
+
export function sanitizeDegreesInt(degrees) {
|
|
90
|
+
degrees = degrees % 360;
|
|
91
|
+
if (degrees < 0) {
|
|
92
|
+
degrees = degrees + 360;
|
|
93
|
+
}
|
|
94
|
+
return degrees;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* Sanitizes a degree measure as a floating-point number.
|
|
99
|
+
*
|
|
100
|
+
* @return a degree measure between 0.0 (inclusive) and 360.0
|
|
101
|
+
* (exclusive).
|
|
102
|
+
*/
|
|
103
|
+
export function sanitizeDegreesDouble(degrees) {
|
|
104
|
+
degrees = degrees % 360.0;
|
|
105
|
+
if (degrees < 0) {
|
|
106
|
+
degrees = degrees + 360.0;
|
|
107
|
+
}
|
|
108
|
+
return degrees;
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
/**
|
|
112
|
+
* Sign of direction change needed to travel from one angle to
|
|
113
|
+
* another.
|
|
114
|
+
*
|
|
115
|
+
* For angles that are 180 degrees apart from each other, both
|
|
116
|
+
* directions have the same travel distance, so either direction is
|
|
117
|
+
* shortest. The value 1.0 is returned in this case.
|
|
118
|
+
*
|
|
119
|
+
* @param from The angle travel starts from, in degrees.
|
|
120
|
+
* @param to The angle travel ends at, in degrees.
|
|
121
|
+
* @return -1 if decreasing from leads to the shortest travel
|
|
122
|
+
* distance, 1 if increasing from leads to the shortest travel
|
|
123
|
+
* distance.
|
|
124
|
+
*/
|
|
125
|
+
export function rotationDirection(from, to) {
|
|
126
|
+
const increasingDifference = sanitizeDegreesDouble(to - from);
|
|
127
|
+
return increasingDifference <= 180.0 ? 1.0 : -1.0;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Distance of two points on a circle, represented using degrees.
|
|
132
|
+
*/
|
|
133
|
+
export function differenceDegrees(a, b) {
|
|
134
|
+
return 180.0 - Math.abs(Math.abs(a - b) - 180.0);
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Multiplies a 1x3 row vector with a 3x3 matrix.
|
|
139
|
+
*/
|
|
140
|
+
export function matrixMultiply(row, matrix) {
|
|
141
|
+
const a = row[0] * matrix[0][0] + row[1] * matrix[0][1] + row[2] * matrix[0][2];
|
|
142
|
+
const b = row[0] * matrix[1][0] + row[1] * matrix[1][1] + row[2] * matrix[1][2];
|
|
143
|
+
const c = row[0] * matrix[2][0] + row[1] * matrix[2][1] + row[2] * matrix[2][2];
|
|
144
|
+
return [a, b, c];
|
|
145
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import themeImportMap from '../artifacts/theme-import-map';
|
|
2
|
-
import { THEME_DATA_ATTRIBUTE } from '../constants';
|
|
2
|
+
import { CUSTOM_THEME_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from '../constants';
|
|
3
3
|
export const loadAndAppendThemeCss = async themeId => {
|
|
4
|
-
if (document.head.querySelector(`style[${THEME_DATA_ATTRIBUTE}="${themeId}"]`)) {
|
|
4
|
+
if (document.head.querySelector(`style[${THEME_DATA_ATTRIBUTE}="${themeId}"]:not([${CUSTOM_THEME_ATTRIBUTE}])`)) {
|
|
5
5
|
return;
|
|
6
6
|
}
|
|
7
7
|
const themeCss = await loadThemeCss(themeId);
|
|
@@ -45,4 +45,6 @@ export const themeStringToObject = themeState => {
|
|
|
45
45
|
* // returns 'dark:dark light:legacy-light spacing:spacing'
|
|
46
46
|
* ```
|
|
47
47
|
*/
|
|
48
|
-
export const themeObjectToString = themeState =>
|
|
48
|
+
export const themeObjectToString = themeState => {
|
|
49
|
+
return Object.entries(themeState).reduce((themeString, [kind, id]) => (kind === 'colorMode' || isThemeKind(kind)) && typeof id === 'string' && (isThemeIds(id) || isColorMode(id)) ? themeString + `${themeString ? ' ' : ''}` + `${kind}:${id}` : themeString, '');
|
|
50
|
+
};
|
package/dist/es2019/version.json
CHANGED
|
@@ -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
|
+
var 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
|
+
var 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,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* THIS FILE WAS CREATED VIA CODEGEN DO NOT MODIFY {@see http://go/af-codegen}
|
|
3
|
-
* @codegen <<SignedSource::
|
|
3
|
+
* @codegen <<SignedSource::cadad94754b78a066c340ab42eca9721>>
|
|
4
4
|
* @codegenCommand yarn build tokens
|
|
5
5
|
*/
|
|
6
|
-
export 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: #
|
|
6
|
+
export 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";
|
|
@@ -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::
|
|
3
|
+
* @codegen <<SignedSource::a87638614efbe4415e8ffd370dd4ce76>>
|
|
4
4
|
* @codegenCommand yarn build tokens
|
|
5
5
|
*/
|
|
6
6
|
var tokens = [{
|
|
@@ -10,7 +10,7 @@ var 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": "#
|
|
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 @@ var 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": "
|
|
23
|
+
"value": "DarkNeutral600"
|
|
24
24
|
},
|
|
25
25
|
"name": "color.border.input",
|
|
26
26
|
"path": ["color", "border", "input"],
|
package/dist/esm/constants.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
export var THEME_DATA_ATTRIBUTE = 'data-theme';
|
|
2
2
|
export var COLOR_MODE_ATTRIBUTE = 'data-color-mode';
|
|
3
|
+
export var CUSTOM_THEME_ATTRIBUTE = 'data-custom-theme';
|
|
3
4
|
export var DEFAULT_THEME = 'light';
|
|
4
5
|
export var CSS_PREFIX = 'ds';
|
|
5
6
|
export var CSS_VAR_FULL = ['opacity', 'font', 'space', 'border'];
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
2
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
3
|
+
import { COLOR_MODE_ATTRIBUTE, CUSTOM_THEME_ATTRIBUTE } from './constants';
|
|
4
|
+
import { themeStateDefaults } from './set-global-theme';
|
|
5
|
+
import { limitSizeOfCustomStyleElements, reduceTokenMap } from './utils/custom-theme-loading-utils';
|
|
6
|
+
import { generateColors, generateTokenMapWithContrastCheck } from './utils/generate-custom-color-ramp';
|
|
7
|
+
import { hash } from './utils/hash';
|
|
8
|
+
export var CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = 10;
|
|
9
|
+
/**
|
|
10
|
+
*
|
|
11
|
+
* @param themeSchema The schema of available themes
|
|
12
|
+
* @returns a string with the CSS for the custom theme
|
|
13
|
+
*/
|
|
14
|
+
/**
|
|
15
|
+
* Takes a color mode and custom branding options, and returns an array of objects for use in applying custom styles to the document head.
|
|
16
|
+
* 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.
|
|
17
|
+
*
|
|
18
|
+
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
19
|
+
* @param {string} themeState.colorMode Determines which color theme is applied
|
|
20
|
+
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
21
|
+
*
|
|
22
|
+
* @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
|
|
23
|
+
* If an error is encountered while loading themes, the themes array will be empty.
|
|
24
|
+
*/
|
|
25
|
+
export function getCustomThemeStyles(_x) {
|
|
26
|
+
return _getCustomThemeStyles.apply(this, arguments);
|
|
27
|
+
}
|
|
28
|
+
function _getCustomThemeStyles() {
|
|
29
|
+
_getCustomThemeStyles = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(themeState) {
|
|
30
|
+
var _themeState$UNSAFE_th;
|
|
31
|
+
var brandColor, mode, optionString, uniqueId, themeRamp, themes, tokenMaps;
|
|
32
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
33
|
+
while (1) switch (_context.prev = _context.next) {
|
|
34
|
+
case 0:
|
|
35
|
+
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;
|
|
36
|
+
mode = (themeState === null || themeState === void 0 ? void 0 : themeState.colorMode) || themeStateDefaults['colorMode'];
|
|
37
|
+
optionString = JSON.stringify(themeState === null || themeState === void 0 ? void 0 : themeState.UNSAFE_themeOptions);
|
|
38
|
+
uniqueId = hash(optionString);
|
|
39
|
+
themeRamp = generateColors(brandColor); // outputs object to generate to CSS from
|
|
40
|
+
themes = [];
|
|
41
|
+
tokenMaps = generateTokenMapWithContrastCheck(brandColor, mode, themeRamp);
|
|
42
|
+
if ((mode === 'light' || mode === 'auto') && tokenMaps.light) {
|
|
43
|
+
// Light mode theming
|
|
44
|
+
themes.push({
|
|
45
|
+
id: 'light',
|
|
46
|
+
attrs: {
|
|
47
|
+
'data-theme': 'light',
|
|
48
|
+
'data-custom-theme': uniqueId
|
|
49
|
+
},
|
|
50
|
+
css: "\nhtml[".concat(CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(COLOR_MODE_ATTRIBUTE, "=\"light\"][data-theme~=\"light:light\"] {\n /* Branded tokens */\n ").concat(reduceTokenMap(tokenMaps.light, themeRamp), "\n}")
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
if ((mode === 'dark' || mode === 'auto') && tokenMaps.dark) {
|
|
54
|
+
// Dark mode theming
|
|
55
|
+
themes.push({
|
|
56
|
+
id: 'dark',
|
|
57
|
+
attrs: {
|
|
58
|
+
'data-theme': 'dark',
|
|
59
|
+
'data-custom-theme': uniqueId
|
|
60
|
+
},
|
|
61
|
+
css: "\nhtml[".concat(CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(COLOR_MODE_ATTRIBUTE, "=\"dark\"][data-theme~=\"dark:dark\"] {\n /* Branded tokens */\n ").concat(reduceTokenMap(tokenMaps.dark, themeRamp), "\n}")
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
return _context.abrupt("return", themes);
|
|
65
|
+
case 10:
|
|
66
|
+
case "end":
|
|
67
|
+
return _context.stop();
|
|
68
|
+
}
|
|
69
|
+
}, _callee);
|
|
70
|
+
}));
|
|
71
|
+
return _getCustomThemeStyles.apply(this, arguments);
|
|
72
|
+
}
|
|
73
|
+
export function loadAndAppendCustomThemeCss(_x2) {
|
|
74
|
+
return _loadAndAppendCustomThemeCss.apply(this, arguments);
|
|
75
|
+
}
|
|
76
|
+
function _loadAndAppendCustomThemeCss() {
|
|
77
|
+
_loadAndAppendCustomThemeCss = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2(themeState) {
|
|
78
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
79
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
80
|
+
case 0:
|
|
81
|
+
getCustomThemeStyles(themeState).then(function (themes) {
|
|
82
|
+
limitSizeOfCustomStyleElements(CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD);
|
|
83
|
+
themes.map(function (theme) {
|
|
84
|
+
var styleTag = document.createElement('style');
|
|
85
|
+
document.head.appendChild(styleTag);
|
|
86
|
+
styleTag.dataset.theme = theme.attrs['data-theme'];
|
|
87
|
+
styleTag.dataset.customTheme = theme.attrs['data-custom-theme'];
|
|
88
|
+
styleTag.textContent = theme.css;
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
case 1:
|
|
92
|
+
case "end":
|
|
93
|
+
return _context2.stop();
|
|
94
|
+
}
|
|
95
|
+
}, _callee2);
|
|
96
|
+
}));
|
|
97
|
+
return _loadAndAppendCustomThemeCss.apply(this, arguments);
|
|
98
|
+
}
|
|
@@ -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.
|
|
4
|
+
var 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.
|
package/dist/esm/get-token.js
CHANGED
|
@@ -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.
|
|
5
|
+
var 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.
|