@atlaskit/tokens 0.13.5 → 1.1.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 +305 -0
- package/README.md +7 -16
- package/dist/cjs/artifacts/palettes-raw/legacy-palette.js +0 -1
- package/dist/cjs/artifacts/palettes-raw/palette.js +0 -1
- package/dist/cjs/artifacts/palettes-raw/spacing-scale.js +0 -1
- package/dist/cjs/artifacts/palettes-raw/typography-palette.js +0 -1
- package/dist/cjs/artifacts/replacement-mapping.js +3 -611
- package/dist/cjs/artifacts/theme-import-map.js +56 -0
- package/dist/cjs/artifacts/themes/atlassian-dark.js +13 -0
- package/dist/cjs/artifacts/themes/atlassian-legacy-dark.js +13 -0
- package/dist/cjs/artifacts/themes/atlassian-legacy-light.js +13 -0
- package/dist/cjs/artifacts/themes/atlassian-light.js +13 -0
- package/dist/cjs/artifacts/themes/atlassian-spacing.js +13 -0
- package/dist/cjs/artifacts/themes/atlassian-typography.js +13 -0
- package/dist/cjs/artifacts/token-default-values.js +2 -170
- package/dist/cjs/artifacts/token-names.js +2 -170
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +1354 -4261
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-dark.js +1352 -4259
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-light.js +1396 -4283
- package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +1365 -4252
- package/dist/cjs/artifacts/tokens-raw/atlassian-spacing.js +1 -1582
- package/dist/cjs/artifacts/tokens-raw/atlassian-typography.js +0 -1
- package/dist/cjs/artifacts/typescript/atlassian-dark-token-names.js +0 -1
- package/dist/cjs/artifacts/typescript/atlassian-light-token-names.js +0 -1
- package/dist/cjs/babel-plugin/index.js +0 -2
- package/dist/cjs/babel-plugin/plugin.js +17 -43
- package/dist/cjs/entry-points/babel-plugin.js +0 -2
- package/dist/cjs/entry-points/palettes-raw.js +0 -2
- package/dist/cjs/entry-points/rename-mapping.js +0 -2
- package/dist/cjs/entry-points/token-ids.js +0 -1
- package/dist/cjs/entry-points/token-names.js +0 -2
- package/dist/cjs/entry-points/tokens-raw.js +0 -5
- package/dist/cjs/get-global-theme.js +30 -0
- package/dist/cjs/get-token-value.js +1 -10
- package/dist/cjs/get-token.js +3 -13
- package/dist/cjs/index.js +46 -10
- package/dist/cjs/palettes/legacy-palette.js +1 -1
- package/dist/cjs/palettes/spacing-scale.js +1 -1
- package/dist/cjs/palettes/typography-palette.js +0 -5
- package/dist/cjs/set-global-theme.js +265 -39
- package/dist/cjs/theme-config.js +8 -23
- package/dist/cjs/{theme-change-observer.js → theme-mutation-observer.js} +5 -57
- package/dist/cjs/tokens/atlassian-dark/utility/utility.js +1 -4
- package/dist/cjs/tokens/atlassian-legacy-dark/utility/utility.js +1 -4
- package/dist/cjs/tokens/atlassian-legacy-light/utility/utility.js +1 -4
- package/dist/cjs/tokens/atlassian-light/utility/utility.js +1 -4
- package/dist/cjs/tokens/atlassian-spacing/spacing.js +0 -228
- package/dist/cjs/tokens/default/spacing/spacing.js +0 -621
- package/dist/cjs/tokens/default/utility/utility.js +1 -9
- package/dist/cjs/use-theme-observer.js +41 -0
- package/dist/cjs/utils/color-detection.js +23 -43
- package/dist/cjs/utils/theme-loading.js +69 -0
- package/dist/cjs/utils/theme-state-transformer.js +73 -0
- package/dist/cjs/utils/token-ids.js +4 -12
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/artifacts/replacement-mapping.js +3 -610
- package/dist/es2019/artifacts/theme-import-map.js +27 -0
- package/dist/es2019/artifacts/themes/atlassian-dark.js +296 -0
- package/dist/es2019/artifacts/themes/atlassian-legacy-dark.js +296 -0
- package/dist/es2019/artifacts/themes/atlassian-legacy-light.js +296 -0
- package/dist/es2019/artifacts/themes/atlassian-light.js +296 -0
- package/dist/es2019/artifacts/themes/atlassian-spacing.js +23 -0
- package/{css/atlassian-typography.css → dist/es2019/artifacts/themes/atlassian-typography.js} +4 -2
- package/dist/es2019/artifacts/token-default-values.js +2 -169
- package/dist/es2019/artifacts/token-names.js +2 -169
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +1354 -4260
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-dark.js +1349 -4255
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-light.js +1397 -4283
- package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +1360 -4246
- package/dist/es2019/artifacts/tokens-raw/atlassian-spacing.js +1 -1581
- package/dist/es2019/babel-plugin/plugin.js +17 -37
- package/dist/es2019/get-global-theme.js +20 -0
- package/dist/es2019/get-token-value.js +1 -6
- package/dist/es2019/get-token.js +3 -8
- package/dist/es2019/index.js +5 -2
- package/dist/es2019/palettes/legacy-palette.js +1 -0
- package/dist/es2019/palettes/spacing-scale.js +1 -0
- package/dist/es2019/palettes/typography-palette.js +2 -1
- package/dist/es2019/set-global-theme.js +162 -32
- package/dist/es2019/theme-config.js +5 -21
- package/dist/es2019/{theme-change-observer.js → theme-mutation-observer.js} +4 -37
- package/dist/es2019/tokens/atlassian-dark/utility/utility.js +1 -4
- package/dist/es2019/tokens/atlassian-legacy-dark/utility/utility.js +1 -4
- package/dist/es2019/tokens/atlassian-legacy-light/utility/utility.js +1 -4
- package/dist/es2019/tokens/atlassian-light/utility/utility.js +1 -4
- package/dist/es2019/tokens/atlassian-spacing/spacing.js +0 -227
- package/dist/es2019/tokens/default/spacing/spacing.js +0 -620
- package/dist/es2019/tokens/default/utility/utility.js +1 -9
- package/dist/es2019/use-theme-observer.js +26 -0
- package/dist/es2019/utils/color-detection.js +3 -5
- package/dist/es2019/utils/theme-loading.js +18 -0
- package/dist/es2019/utils/theme-state-transformer.js +47 -0
- package/dist/es2019/utils/token-ids.js +5 -4
- package/dist/es2019/version.json +1 -1
- package/dist/esm/artifacts/replacement-mapping.js +3 -610
- package/dist/esm/artifacts/theme-import-map.js +39 -0
- package/dist/esm/artifacts/themes/atlassian-dark.js +6 -0
- package/dist/esm/artifacts/themes/atlassian-legacy-dark.js +6 -0
- package/dist/esm/artifacts/themes/atlassian-legacy-light.js +6 -0
- package/dist/esm/artifacts/themes/atlassian-light.js +6 -0
- package/dist/esm/artifacts/themes/atlassian-spacing.js +6 -0
- package/dist/esm/artifacts/themes/atlassian-typography.js +6 -0
- package/dist/esm/artifacts/token-default-values.js +2 -169
- package/dist/esm/artifacts/token-names.js +2 -169
- package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +1354 -4260
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-dark.js +1349 -4255
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-light.js +1397 -4283
- package/dist/esm/artifacts/tokens-raw/atlassian-light.js +1360 -4246
- package/dist/esm/artifacts/tokens-raw/atlassian-spacing.js +1 -1581
- package/dist/esm/babel-plugin/plugin.js +17 -35
- package/dist/esm/get-global-theme.js +22 -0
- package/dist/esm/get-token-value.js +1 -6
- package/dist/esm/get-token.js +3 -8
- package/dist/esm/index.js +5 -2
- package/dist/esm/palettes/legacy-palette.js +1 -0
- package/dist/esm/palettes/spacing-scale.js +1 -0
- package/dist/esm/palettes/typography-palette.js +0 -3
- package/dist/esm/set-global-theme.js +263 -37
- package/dist/esm/theme-config.js +5 -21
- package/dist/esm/{theme-change-observer.js → theme-mutation-observer.js} +4 -49
- package/dist/esm/tokens/atlassian-dark/utility/utility.js +1 -4
- package/dist/esm/tokens/atlassian-legacy-dark/utility/utility.js +1 -4
- package/dist/esm/tokens/atlassian-legacy-light/utility/utility.js +1 -4
- package/dist/esm/tokens/atlassian-light/utility/utility.js +1 -4
- package/dist/esm/tokens/atlassian-spacing/spacing.js +0 -227
- package/dist/esm/tokens/default/spacing/spacing.js +0 -620
- package/dist/esm/tokens/default/utility/utility.js +1 -9
- package/dist/esm/use-theme-observer.js +34 -0
- package/dist/esm/utils/color-detection.js +23 -30
- package/dist/esm/utils/theme-loading.js +60 -0
- package/dist/esm/utils/theme-state-transformer.js +64 -0
- package/dist/esm/utils/token-ids.js +5 -4
- package/dist/esm/version.json +1 -1
- package/dist/types/artifacts/replacement-mapping.d.ts +1 -1
- package/dist/types/artifacts/theme-import-map.d.ts +16 -0
- package/dist/types/artifacts/themes/atlassian-dark.d.ts +7 -0
- package/dist/types/artifacts/themes/atlassian-legacy-dark.d.ts +7 -0
- package/dist/types/artifacts/themes/atlassian-legacy-light.d.ts +7 -0
- package/dist/types/artifacts/themes/atlassian-light.d.ts +7 -0
- package/dist/types/artifacts/themes/atlassian-spacing.d.ts +7 -0
- package/dist/types/artifacts/themes/atlassian-typography.d.ts +7 -0
- package/dist/types/artifacts/token-default-values.d.ts +2 -169
- package/dist/types/artifacts/token-names.d.ts +3 -337
- package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -115
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-dark.d.ts +1 -115
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-light.d.ts +1 -91
- package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -91
- package/dist/types/artifacts/tokens-raw/atlassian-spacing.d.ts +1 -89
- package/dist/types/artifacts/types-internal.d.ts +2 -2
- package/dist/types/artifacts/types.d.ts +2 -2
- package/dist/types/get-global-theme.d.ts +2 -0
- package/dist/types/index.d.ts +7 -3
- package/dist/types/set-global-theme.d.ts +63 -7
- package/dist/types/theme-config.d.ts +10 -7
- package/dist/types/{theme-change-observer.d.ts → theme-mutation-observer.d.ts} +2 -16
- package/dist/types/types.d.ts +1 -286
- package/dist/types/use-theme-observer.d.ts +15 -0
- package/dist/types/utils/theme-loading.d.ts +3 -0
- package/dist/types/utils/theme-state-transformer.d.ts +26 -0
- package/figma/atlassian-dark.json +1 -102
- package/figma/atlassian-legacy-dark.json +1 -102
- package/figma/atlassian-legacy-light.json +1 -102
- package/figma/atlassian-light.json +1 -102
- package/figma/atlassian-spacing.json +1 -761
- package/package.json +5 -8
- package/report.api.md +85 -351
- package/tmp/api-report-tmp.d.ts +58 -342
- package/css/atlassian-dark.css +0 -786
- package/css/atlassian-legacy-dark.css +0 -786
- package/css/atlassian-legacy-light.css +0 -786
- package/css/atlassian-light.css +0 -786
- package/css/atlassian-spacing.css +0 -87
- package/dist/cjs/artifacts/typescript/atlassian-light-token-default-values.js +0 -407
- package/dist/cjs/tokens/atlassian-dark/deprecated/deprecated.js +0 -435
- package/dist/cjs/tokens/atlassian-legacy-dark/deprecated/deprecated.js +0 -532
- package/dist/cjs/tokens/atlassian-legacy-light/deprecated/deprecated.js +0 -523
- package/dist/cjs/tokens/atlassian-light/deprecated/deprecated.js +0 -421
- package/dist/cjs/tokens/default/deprecated/deprecated.js +0 -1186
- package/dist/es2019/artifacts/typescript/atlassian-light-token-default-values.js +0 -399
- package/dist/es2019/tokens/atlassian-dark/deprecated/deprecated.js +0 -428
- package/dist/es2019/tokens/atlassian-legacy-dark/deprecated/deprecated.js +0 -525
- package/dist/es2019/tokens/atlassian-legacy-light/deprecated/deprecated.js +0 -516
- package/dist/es2019/tokens/atlassian-light/deprecated/deprecated.js +0 -414
- package/dist/es2019/tokens/default/deprecated/deprecated.js +0 -1217
- package/dist/esm/artifacts/typescript/atlassian-light-token-default-values.js +0 -399
- package/dist/esm/tokens/atlassian-dark/deprecated/deprecated.js +0 -428
- package/dist/esm/tokens/atlassian-legacy-dark/deprecated/deprecated.js +0 -525
- package/dist/esm/tokens/atlassian-legacy-light/deprecated/deprecated.js +0 -516
- package/dist/esm/tokens/atlassian-light/deprecated/deprecated.js +0 -414
- package/dist/esm/tokens/default/deprecated/deprecated.js +0 -1179
- package/dist/types/artifacts/typescript/atlassian-light-token-default-values.d.ts +0 -399
- package/dist/types/tokens/atlassian-dark/deprecated/deprecated.d.ts +0 -4
- package/dist/types/tokens/atlassian-legacy-dark/deprecated/deprecated.d.ts +0 -4
- package/dist/types/tokens/atlassian-legacy-light/deprecated/deprecated.d.ts +0 -4
- package/dist/types/tokens/atlassian-light/deprecated/deprecated.d.ts +0 -4
- package/dist/types/tokens/default/deprecated/deprecated.d.ts +0 -4
|
@@ -11,49 +11,44 @@ export default function plugin() {
|
|
|
11
11
|
function CallExpression(_x) {
|
|
12
12
|
return _CallExpression.apply(this, arguments);
|
|
13
13
|
}
|
|
14
|
-
|
|
15
14
|
CallExpression.toString = function () {
|
|
16
15
|
return _CallExpression.toString();
|
|
17
16
|
};
|
|
18
|
-
|
|
19
17
|
return CallExpression;
|
|
20
18
|
}(function (path) {
|
|
21
19
|
var tokenImportScope = getTokenImportScope(path);
|
|
22
|
-
|
|
23
20
|
if (!tokenImportScope) {
|
|
24
21
|
return;
|
|
25
|
-
}
|
|
26
|
-
|
|
22
|
+
}
|
|
27
23
|
|
|
24
|
+
// Check arguments have correct format
|
|
28
25
|
if (!path.node.arguments[0]) {
|
|
29
26
|
throw new Error("token() requires at least one argument");
|
|
30
27
|
} else if (!t.isStringLiteral(path.node.arguments[0])) {
|
|
31
28
|
throw new Error("token() must have a string as the first argument");
|
|
32
29
|
} else if (path.node.arguments.length > 2) {
|
|
33
30
|
throw new Error("token() does not accept ".concat(path.node.arguments.length, " arguments"));
|
|
34
|
-
}
|
|
35
|
-
|
|
31
|
+
}
|
|
36
32
|
|
|
33
|
+
// Check the token exists
|
|
37
34
|
var tokenName = path.node.arguments[0].value;
|
|
38
35
|
var cssTokenValue = tokenNames[tokenName];
|
|
39
|
-
|
|
40
36
|
if (!cssTokenValue) {
|
|
41
37
|
throw new Error("token '".concat(tokenName, "' does not exist"));
|
|
42
38
|
}
|
|
39
|
+
var replacementNode;
|
|
43
40
|
|
|
44
|
-
|
|
45
|
-
|
|
41
|
+
// if no fallback is set, optionally find one from the default theme
|
|
46
42
|
if (path.node.arguments.length < 2) {
|
|
47
43
|
if (state.opts.shouldUseAutoFallback) {
|
|
48
44
|
replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ", ").concat(getDefaultFallback(tokenName), ")"));
|
|
49
45
|
} else {
|
|
50
46
|
replacementNode = t.stringLiteral("var(".concat(cssTokenValue, ")"));
|
|
51
47
|
}
|
|
52
|
-
}
|
|
53
|
-
|
|
48
|
+
}
|
|
54
49
|
|
|
50
|
+
// Handle fallbacks
|
|
55
51
|
var fallback = path.node.arguments[1];
|
|
56
|
-
|
|
57
52
|
if (t.isStringLiteral(fallback)) {
|
|
58
53
|
// String literals can be concatenated into css variable call
|
|
59
54
|
// Empty string fallbacks are ignored. For now, as the user did specify a fallback, no default is inserted
|
|
@@ -68,11 +63,11 @@ export default function plugin() {
|
|
|
68
63
|
raw: ')',
|
|
69
64
|
cooked: ')'
|
|
70
65
|
}, true)], [fallback]);
|
|
71
|
-
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
replacementNode && path.replaceWith(replacementNode); // @ts-ignore crawl is a valid property
|
|
66
|
+
}
|
|
75
67
|
|
|
68
|
+
// Replace path and call scope.crawl() to refresh the scope bindings + references
|
|
69
|
+
replacementNode && path.replaceWith(replacementNode);
|
|
70
|
+
// @ts-ignore crawl is a valid property
|
|
76
71
|
tokenImportScope.crawl();
|
|
77
72
|
})
|
|
78
73
|
});
|
|
@@ -84,23 +79,22 @@ export default function plugin() {
|
|
|
84
79
|
if (path.node.source.value !== '@atlaskit/tokens') {
|
|
85
80
|
return;
|
|
86
81
|
}
|
|
87
|
-
|
|
88
82
|
path.get('specifiers').forEach(function (specifier) {
|
|
89
83
|
if (!specifier.isImportSpecifier()) {
|
|
90
84
|
return;
|
|
91
85
|
}
|
|
92
|
-
|
|
93
86
|
if (getNonAliasedImportName(specifier.node) !== 'token') {
|
|
94
87
|
return;
|
|
95
88
|
}
|
|
89
|
+
var binding = path.scope.bindings[getAliasedImportName(specifier.node)];
|
|
96
90
|
|
|
97
|
-
|
|
98
|
-
|
|
91
|
+
// if no longer used, remove
|
|
99
92
|
if (!binding.referenced) {
|
|
100
93
|
specifier.remove();
|
|
101
94
|
}
|
|
102
|
-
});
|
|
95
|
+
});
|
|
103
96
|
|
|
97
|
+
// remove '@atlaskit/tokens' import if it is no longer needed
|
|
104
98
|
if (path.get('specifiers').length === 0) {
|
|
105
99
|
path.remove();
|
|
106
100
|
}
|
|
@@ -111,55 +105,43 @@ export default function plugin() {
|
|
|
111
105
|
}
|
|
112
106
|
};
|
|
113
107
|
}
|
|
114
|
-
|
|
115
108
|
function getDefaultFallback(tokenName) {
|
|
116
109
|
return tokenDefaultValues[tokenName];
|
|
117
110
|
}
|
|
118
|
-
|
|
119
111
|
function getNonAliasedImportName(node) {
|
|
120
112
|
if (t.isIdentifier(node.imported)) {
|
|
121
113
|
return node.imported.name;
|
|
122
114
|
}
|
|
123
|
-
|
|
124
115
|
return node.imported.value;
|
|
125
116
|
}
|
|
126
|
-
|
|
127
117
|
function getAliasedImportName(node) {
|
|
128
118
|
return node.local.name;
|
|
129
119
|
}
|
|
120
|
+
|
|
130
121
|
/**
|
|
131
122
|
* Determine if the current call is to a token function, and
|
|
132
123
|
* return the relevant scope
|
|
133
124
|
*/
|
|
134
|
-
|
|
135
|
-
|
|
136
125
|
function getTokenImportScope(path) {
|
|
137
126
|
var callee = path.node.callee;
|
|
138
|
-
|
|
139
127
|
if (!t.isIdentifier(callee)) {
|
|
140
128
|
return undefined;
|
|
141
129
|
}
|
|
142
|
-
|
|
143
130
|
var binding = getTokenBinding(path.scope, callee.name);
|
|
144
|
-
|
|
145
131
|
if (!binding || !t.isImportSpecifier(binding.path.node)) {
|
|
146
132
|
return undefined;
|
|
147
133
|
}
|
|
148
|
-
|
|
149
134
|
if (binding.path.parent && t.isImportDeclaration(binding.path.parent)) {
|
|
150
135
|
if (binding.path.parent.source.value !== '@atlaskit/tokens') {
|
|
151
136
|
return undefined;
|
|
152
137
|
}
|
|
153
138
|
}
|
|
154
|
-
|
|
155
139
|
return getNonAliasedImportName(binding.path.node) === 'token' ? binding.scope : undefined;
|
|
156
140
|
}
|
|
157
|
-
|
|
158
141
|
function getTokenBinding(scope, name) {
|
|
159
142
|
if (!scope) {
|
|
160
143
|
return undefined;
|
|
161
144
|
}
|
|
162
|
-
|
|
163
145
|
if (scope.bindings[name]) {
|
|
164
146
|
return scope.bindings[name];
|
|
165
147
|
} else {
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
3
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
4
|
+
import { COLOR_MODE_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
|
|
5
|
+
import { themeColorModes } from './theme-config';
|
|
6
|
+
import { themeStringToObject } from './utils/theme-state-transformer';
|
|
7
|
+
var isThemeColorMode = function isThemeColorMode(colorMode) {
|
|
8
|
+
return themeColorModes.find(function (mode) {
|
|
9
|
+
return mode === colorMode;
|
|
10
|
+
}) !== undefined;
|
|
11
|
+
};
|
|
12
|
+
export var getGlobalTheme = function getGlobalTheme() {
|
|
13
|
+
if (typeof document === 'undefined') {
|
|
14
|
+
return {};
|
|
15
|
+
}
|
|
16
|
+
var element = document.documentElement;
|
|
17
|
+
var colorMode = element.getAttribute(COLOR_MODE_ATTRIBUTE) || '';
|
|
18
|
+
var theme = element.getAttribute(THEME_DATA_ATTRIBUTE) || '';
|
|
19
|
+
return _objectSpread(_objectSpread({}, themeStringToObject(theme)), isThemeColorMode(colorMode) && {
|
|
20
|
+
colorMode: colorMode
|
|
21
|
+
});
|
|
22
|
+
};
|
|
@@ -1,8 +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 = "
|
|
5
|
-
|
|
4
|
+
var version = "1.1.0";
|
|
6
5
|
/**
|
|
7
6
|
* Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
|
|
8
7
|
* resulting CSS Custom Property.
|
|
@@ -28,18 +27,14 @@ function getTokenValue(tokenId) {
|
|
|
28
27
|
var fallback = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '';
|
|
29
28
|
var token = tokens[tokenId];
|
|
30
29
|
var tokenValue = fallback;
|
|
31
|
-
|
|
32
30
|
if (process.env.NODE_ENV !== 'production' && !token) {
|
|
33
31
|
warnOnce("Unknown token id at path: ".concat(tokenId, " for ").concat(name, "@").concat(version));
|
|
34
32
|
}
|
|
35
|
-
|
|
36
33
|
if (typeof window === 'undefined') {
|
|
37
34
|
return tokenValue;
|
|
38
35
|
}
|
|
39
|
-
|
|
40
36
|
tokenValue = window.getComputedStyle(document.documentElement).getPropertyValue(token);
|
|
41
37
|
tokenValue = tokenValue || fallback;
|
|
42
38
|
return tokenValue;
|
|
43
39
|
}
|
|
44
|
-
|
|
45
40
|
export default getTokenValue;
|
package/dist/esm/get-token.js
CHANGED
|
@@ -2,8 +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 = "
|
|
6
|
-
|
|
5
|
+
var version = "1.1.0";
|
|
7
6
|
/**
|
|
8
7
|
* Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
|
|
9
8
|
* This should be used to implement design decisions throughout your application.
|
|
@@ -28,19 +27,15 @@ var version = "0.13.5";
|
|
|
28
27
|
*/
|
|
29
28
|
function token(path, fallback) {
|
|
30
29
|
var token = tokens[path];
|
|
31
|
-
|
|
32
30
|
if (process.env.NODE_ENV !== 'production' && !token) {
|
|
33
|
-
token = tokens['utility.UNSAFE_util.MISSING_TOKEN'];
|
|
34
31
|
warnOnce("Unknown token id at path: ".concat(path, " for ").concat(name, "@").concat(version));
|
|
35
|
-
}
|
|
36
|
-
|
|
32
|
+
}
|
|
37
33
|
|
|
34
|
+
// if the token is not found - replacing it with variable name without any value, to avoid it being undefined which would result in invalid css
|
|
38
35
|
if (!token) {
|
|
39
36
|
token = TOKEN_NOT_FOUND_CSS_VAR;
|
|
40
37
|
}
|
|
41
|
-
|
|
42
38
|
var tokenCall = fallback ? "var(".concat(token, ", ").concat(fallback, ")") : "var(".concat(token, ")");
|
|
43
39
|
return tokenCall;
|
|
44
40
|
}
|
|
45
|
-
|
|
46
41
|
export default token;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
export { default as token } from './get-token';
|
|
2
2
|
export { default as getTokenValue } from './get-token-value';
|
|
3
|
-
export { default as setGlobalTheme } from './set-global-theme';
|
|
3
|
+
export { default as setGlobalTheme, getThemeStyles, getThemeHtmlAttrs, getSSRAutoScript } from './set-global-theme';
|
|
4
4
|
export { default as themeConfig } from './theme-config';
|
|
5
|
-
export { useThemeObserver
|
|
5
|
+
export { useThemeObserver } from './use-theme-observer';
|
|
6
|
+
export { ThemeMutationObserver } from './theme-mutation-observer';
|
|
7
|
+
export { getGlobalTheme } from './get-global-theme';
|
|
8
|
+
export { themeStringToObject, themeObjectToString } from './utils/theme-state-transformer';
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
4
|
var lineHeightScale = {
|
|
8
5
|
lineHeight: {
|
|
9
6
|
LineHeight100: {
|
|
@@ -1,49 +1,275 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
4
|
+
import _asyncToGenerator from "@babel/runtime/helpers/asyncToGenerator";
|
|
5
|
+
import _regeneratorRuntime from "@babel/runtime/regenerator";
|
|
6
|
+
import { bind } from 'bind-event-listener';
|
|
7
|
+
import noop from '@atlaskit/ds-lib/noop';
|
|
1
8
|
import { COLOR_MODE_ATTRIBUTE, THEME_DATA_ATTRIBUTE } from './constants';
|
|
2
|
-
import
|
|
9
|
+
import { loadAndAppendThemeCss, loadThemeCss } from './utils/theme-loading';
|
|
10
|
+
import { themeObjectToString } from './utils/theme-state-transformer';
|
|
11
|
+
var defaultColorMode = 'light';
|
|
12
|
+
var isMatchMediaAvailable = typeof window !== 'undefined' && 'matchMedia' in window;
|
|
13
|
+
var darkModeMediaQuery = '(prefers-color-scheme: dark)';
|
|
14
|
+
var darkModeMql = isMatchMediaAvailable && window.matchMedia(darkModeMediaQuery);
|
|
15
|
+
var unbindThemeChangeListener = noop;
|
|
16
|
+
var themeStateDefaults = {
|
|
17
|
+
colorMode: 'auto',
|
|
18
|
+
dark: 'dark',
|
|
19
|
+
light: 'light',
|
|
20
|
+
spacing: undefined,
|
|
21
|
+
typography: undefined
|
|
22
|
+
};
|
|
23
|
+
|
|
24
|
+
/**
|
|
25
|
+
* Updates the current theme when the system theme changes. Should be bound
|
|
26
|
+
* to an event listener listening on the '(prefers-color-scheme: dark)' query
|
|
27
|
+
* @param e The event representing a change in system theme.
|
|
28
|
+
*/
|
|
29
|
+
var checkNativeListener = function checkNativeListener(e) {
|
|
30
|
+
var element = document.documentElement;
|
|
31
|
+
element.setAttribute(COLOR_MODE_ATTRIBUTE, e.matches ? 'dark' : 'light');
|
|
32
|
+
};
|
|
33
|
+
|
|
3
34
|
/**
|
|
4
|
-
* Sets the theme globally at runtime. This updates the `data-theme` and `data-color-
|
|
35
|
+
* Sets the theme globally at runtime. This updates the `data-theme` and `data-color-mode` attributes on your page's <html> tag.
|
|
5
36
|
*
|
|
6
|
-
* @param {string}
|
|
7
|
-
* @param {string}
|
|
37
|
+
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
38
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
39
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
40
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
41
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
42
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
43
|
+
*
|
|
44
|
+
* @returns A Promise of an unbind function, that can be used to stop listening for changes to system theme.
|
|
8
45
|
*
|
|
9
46
|
* @example
|
|
10
47
|
* ```
|
|
11
|
-
*
|
|
12
|
-
* setGlobalTheme('light', true);
|
|
48
|
+
* setGlobalTheme({colorMode: 'auto', light: 'light', dark: 'dark', spacing: 'spacing'});
|
|
13
49
|
* ```
|
|
14
50
|
*/
|
|
51
|
+
var setGlobalTheme = /*#__PURE__*/function () {
|
|
52
|
+
var _ref = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee2() {
|
|
53
|
+
var _ref2,
|
|
54
|
+
_ref2$colorMode,
|
|
55
|
+
colorMode,
|
|
56
|
+
_ref2$dark,
|
|
57
|
+
dark,
|
|
58
|
+
_ref2$light,
|
|
59
|
+
light,
|
|
60
|
+
_ref2$spacing,
|
|
61
|
+
spacing,
|
|
62
|
+
_ref2$typography,
|
|
63
|
+
typography,
|
|
64
|
+
themePreferences,
|
|
65
|
+
themeAttributes,
|
|
66
|
+
_args2 = arguments;
|
|
67
|
+
return _regeneratorRuntime.wrap(function _callee2$(_context2) {
|
|
68
|
+
while (1) {
|
|
69
|
+
switch (_context2.prev = _context2.next) {
|
|
70
|
+
case 0:
|
|
71
|
+
_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$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;
|
|
72
|
+
// Dedupe list of themes to avoid race condition
|
|
73
|
+
themePreferences = new Set([dark, light, spacing, typography]);
|
|
74
|
+
_context2.next = 4;
|
|
75
|
+
return Promise.all(_toConsumableArray(themePreferences).filter(function (themeId) {
|
|
76
|
+
return themeId !== undefined;
|
|
77
|
+
}).map( /*#__PURE__*/function () {
|
|
78
|
+
var _ref3 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee(themeId) {
|
|
79
|
+
return _regeneratorRuntime.wrap(function _callee$(_context) {
|
|
80
|
+
while (1) {
|
|
81
|
+
switch (_context.prev = _context.next) {
|
|
82
|
+
case 0:
|
|
83
|
+
_context.next = 2;
|
|
84
|
+
return loadAndAppendThemeCss(themeId);
|
|
85
|
+
case 2:
|
|
86
|
+
return _context.abrupt("return", _context.sent);
|
|
87
|
+
case 3:
|
|
88
|
+
case "end":
|
|
89
|
+
return _context.stop();
|
|
90
|
+
}
|
|
91
|
+
}
|
|
92
|
+
}, _callee);
|
|
93
|
+
}));
|
|
94
|
+
return function (_x) {
|
|
95
|
+
return _ref3.apply(this, arguments);
|
|
96
|
+
};
|
|
97
|
+
}()));
|
|
98
|
+
case 4:
|
|
99
|
+
if (colorMode === 'auto' && darkModeMql) {
|
|
100
|
+
colorMode = darkModeMql.matches ? 'dark' : 'light';
|
|
101
|
+
// Add an event listener for changes to the system theme.
|
|
102
|
+
// If the function exists, it will not be added again.
|
|
103
|
+
unbindThemeChangeListener = bind(darkModeMql, {
|
|
104
|
+
type: 'change',
|
|
105
|
+
listener: checkNativeListener
|
|
106
|
+
});
|
|
107
|
+
} else {
|
|
108
|
+
unbindThemeChangeListener();
|
|
109
|
+
}
|
|
110
|
+
themeAttributes = getThemeHtmlAttrs({
|
|
111
|
+
colorMode: colorMode,
|
|
112
|
+
dark: dark,
|
|
113
|
+
light: light,
|
|
114
|
+
spacing: spacing,
|
|
115
|
+
typography: typography
|
|
116
|
+
});
|
|
117
|
+
Object.entries(themeAttributes).forEach(function (_ref4) {
|
|
118
|
+
var _ref5 = _slicedToArray(_ref4, 2),
|
|
119
|
+
key = _ref5[0],
|
|
120
|
+
value = _ref5[1];
|
|
121
|
+
document.documentElement.setAttribute(key, value);
|
|
122
|
+
});
|
|
123
|
+
return _context2.abrupt("return", unbindThemeChangeListener);
|
|
124
|
+
case 8:
|
|
125
|
+
case "end":
|
|
126
|
+
return _context2.stop();
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}, _callee2);
|
|
130
|
+
}));
|
|
131
|
+
return function setGlobalTheme() {
|
|
132
|
+
return _ref.apply(this, arguments);
|
|
133
|
+
};
|
|
134
|
+
}();
|
|
135
|
+
/**
|
|
136
|
+
* Takes an object containing theme preferences, and returns an array of objects for use in applying styles to the document head.
|
|
137
|
+
* 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.
|
|
138
|
+
*
|
|
139
|
+
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
140
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
141
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
142
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
143
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
144
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
145
|
+
*
|
|
146
|
+
* @returns A Promise of an object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
|
|
147
|
+
* If an error is encountered while loading themes, the themes arrav will be emptv.
|
|
148
|
+
*/
|
|
149
|
+
export var getThemeStyles = /*#__PURE__*/function () {
|
|
150
|
+
var _ref6 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee4() {
|
|
151
|
+
var _ref7,
|
|
152
|
+
_ref7$colorMode,
|
|
153
|
+
colorMode,
|
|
154
|
+
_ref7$dark,
|
|
155
|
+
dark,
|
|
156
|
+
_ref7$light,
|
|
157
|
+
light,
|
|
158
|
+
_ref7$spacing,
|
|
159
|
+
spacing,
|
|
160
|
+
_ref7$typography,
|
|
161
|
+
typography,
|
|
162
|
+
themePreferences,
|
|
163
|
+
results,
|
|
164
|
+
_args4 = arguments;
|
|
165
|
+
return _regeneratorRuntime.wrap(function _callee4$(_context4) {
|
|
166
|
+
while (1) {
|
|
167
|
+
switch (_context4.prev = _context4.next) {
|
|
168
|
+
case 0:
|
|
169
|
+
_ref7 = _args4.length > 0 && _args4[0] !== undefined ? _args4[0] : {}, _ref7$colorMode = _ref7.colorMode, colorMode = _ref7$colorMode === void 0 ? themeStateDefaults['colorMode'] : _ref7$colorMode, _ref7$dark = _ref7.dark, dark = _ref7$dark === void 0 ? themeStateDefaults['dark'] : _ref7$dark, _ref7$light = _ref7.light, light = _ref7$light === void 0 ? themeStateDefaults['light'] : _ref7$light, _ref7$spacing = _ref7.spacing, spacing = _ref7$spacing === void 0 ? themeStateDefaults['spacing'] : _ref7$spacing, _ref7$typography = _ref7.typography, typography = _ref7$typography === void 0 ? themeStateDefaults['typography'] : _ref7$typography;
|
|
170
|
+
themePreferences = colorMode === 'auto' ? [light, dark] : [colorMode];
|
|
171
|
+
[spacing, typography].forEach(function (themeId) {
|
|
172
|
+
if (themeId) {
|
|
173
|
+
themePreferences.push(themeId);
|
|
174
|
+
}
|
|
175
|
+
});
|
|
176
|
+
_context4.next = 5;
|
|
177
|
+
return Promise.all(themePreferences.map( /*#__PURE__*/function () {
|
|
178
|
+
var _ref8 = _asyncToGenerator( /*#__PURE__*/_regeneratorRuntime.mark(function _callee3(themeId) {
|
|
179
|
+
var css;
|
|
180
|
+
return _regeneratorRuntime.wrap(function _callee3$(_context3) {
|
|
181
|
+
while (1) {
|
|
182
|
+
switch (_context3.prev = _context3.next) {
|
|
183
|
+
case 0:
|
|
184
|
+
_context3.prev = 0;
|
|
185
|
+
_context3.next = 3;
|
|
186
|
+
return loadThemeCss(themeId);
|
|
187
|
+
case 3:
|
|
188
|
+
css = _context3.sent;
|
|
189
|
+
return _context3.abrupt("return", {
|
|
190
|
+
id: themeId,
|
|
191
|
+
attrs: {
|
|
192
|
+
'data-theme': themeId
|
|
193
|
+
},
|
|
194
|
+
css: css
|
|
195
|
+
});
|
|
196
|
+
case 7:
|
|
197
|
+
_context3.prev = 7;
|
|
198
|
+
_context3.t0 = _context3["catch"](0);
|
|
199
|
+
return _context3.abrupt("return", undefined);
|
|
200
|
+
case 10:
|
|
201
|
+
case "end":
|
|
202
|
+
return _context3.stop();
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}, _callee3, null, [[0, 7]]);
|
|
206
|
+
}));
|
|
207
|
+
return function (_x2) {
|
|
208
|
+
return _ref8.apply(this, arguments);
|
|
209
|
+
};
|
|
210
|
+
}()));
|
|
211
|
+
case 5:
|
|
212
|
+
results = _context4.sent;
|
|
213
|
+
return _context4.abrupt("return", results.filter(function (theme) {
|
|
214
|
+
return theme !== undefined;
|
|
215
|
+
}));
|
|
216
|
+
case 7:
|
|
217
|
+
case "end":
|
|
218
|
+
return _context4.stop();
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
}, _callee4);
|
|
222
|
+
}));
|
|
223
|
+
return function getThemeStyles() {
|
|
224
|
+
return _ref6.apply(this, arguments);
|
|
225
|
+
};
|
|
226
|
+
}();
|
|
15
227
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
228
|
+
/**
|
|
229
|
+
* Server-side rendering utility. Generates the valid HTML attributes for a given theme.
|
|
230
|
+
* Note: this utility does not handle automatic theme switching.
|
|
231
|
+
*
|
|
232
|
+
* @param {Object<string, string>} themeOptions - Theme options object
|
|
233
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
234
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
235
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
236
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
237
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
238
|
+
*
|
|
239
|
+
* @returns {Object} Object of HTML attributes to be applied to the document root
|
|
240
|
+
*/
|
|
241
|
+
export var getThemeHtmlAttrs = function getThemeHtmlAttrs() {
|
|
242
|
+
var _ref10;
|
|
243
|
+
var _ref9 = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
244
|
+
_ref9$colorMode = _ref9.colorMode,
|
|
245
|
+
colorMode = _ref9$colorMode === void 0 ? themeStateDefaults['colorMode'] : _ref9$colorMode,
|
|
246
|
+
_ref9$dark = _ref9.dark,
|
|
247
|
+
dark = _ref9$dark === void 0 ? themeStateDefaults['dark'] : _ref9$dark,
|
|
248
|
+
_ref9$light = _ref9.light,
|
|
249
|
+
light = _ref9$light === void 0 ? themeStateDefaults['light'] : _ref9$light,
|
|
250
|
+
_ref9$spacing = _ref9.spacing,
|
|
251
|
+
spacing = _ref9$spacing === void 0 ? themeStateDefaults['spacing'] : _ref9$spacing,
|
|
252
|
+
_ref9$typography = _ref9.typography,
|
|
253
|
+
typography = _ref9$typography === void 0 ? themeStateDefaults['typography'] : _ref9$typography;
|
|
254
|
+
var themePreferences = {
|
|
255
|
+
dark: dark,
|
|
256
|
+
light: light,
|
|
257
|
+
spacing: spacing,
|
|
258
|
+
typography: typography
|
|
259
|
+
};
|
|
260
|
+
var themeAttribute = themeObjectToString(themePreferences);
|
|
261
|
+
return _ref10 = {}, _defineProperty(_ref10, THEME_DATA_ATTRIBUTE, themeAttribute), _defineProperty(_ref10, COLOR_MODE_ATTRIBUTE, colorMode === 'auto' ? defaultColorMode : colorMode), _ref10;
|
|
47
262
|
};
|
|
48
263
|
|
|
264
|
+
/**
|
|
265
|
+
* Provides a script that, when executed before paint, sets the `data-color-mode` attribute based on the current system theme,
|
|
266
|
+
* to enable SSR support for automatic theme switching, avoid a flash of un-themed content on first paint.
|
|
267
|
+
*
|
|
268
|
+
* @param {string} colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
269
|
+
*
|
|
270
|
+
* @returns {string} A string to be added to the innerHTML of a script tag in the document head
|
|
271
|
+
*/
|
|
272
|
+
export var getSSRAutoScript = function getSSRAutoScript(colorMode) {
|
|
273
|
+
return colorMode === 'auto' ? "(\n () => {\n try {\n const mql = window.matchMedia('".concat(darkModeMediaQuery, "');\n const colorMode = mql.matches ? 'dark' : 'light';\n document.documentElement.setAttribute('").concat(COLOR_MODE_ATTRIBUTE, "', colorMode);\n } catch (e) {}\n }\n)()") : undefined;
|
|
274
|
+
};
|
|
49
275
|
export default setGlobalTheme;
|
package/dist/esm/theme-config.js
CHANGED
|
@@ -16,34 +16,18 @@
|
|
|
16
16
|
|
|
17
17
|
/**
|
|
18
18
|
* Theme modes: The general purpose of a theme.
|
|
19
|
-
* This attr is used to apply the appropriate system-preference
|
|
19
|
+
* This attr is used to apply the appropriate system-preference option
|
|
20
20
|
* It may also be used as a selector for mode-specific overrides such as light/dark images.
|
|
21
21
|
* The idea is there may exist many color themes, but every theme must either fit into light or dark.
|
|
22
22
|
*/
|
|
23
|
-
|
|
23
|
+
export var themeColorModes = ['light', 'dark', 'auto'];
|
|
24
24
|
/**
|
|
25
|
-
* Theme ids: The value that will mounted to the DOM as a data attr
|
|
26
|
-
* For example: `data-theme="light"
|
|
25
|
+
* Theme ids: The value that will be mounted to the DOM as a data attr
|
|
26
|
+
* For example: `data-theme="light:light dark:dark spacing:spacing"
|
|
27
27
|
*
|
|
28
28
|
* These ids must be kebab case
|
|
29
29
|
*/
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Theme to use a base. This will create the theme as
|
|
33
|
-
* an extension with all token values marked as optional
|
|
34
|
-
* to allow tokens to be overridden as required.
|
|
35
|
-
*/
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Palettes: The set of base tokens a given theme may be populated with.
|
|
39
|
-
* For example: legacy light & dark themes use the "legacyPalette" containing colors from our
|
|
40
|
-
* previous color set.
|
|
41
|
-
*/
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* ThemeConfig: the source of truth for all theme meta-data.
|
|
45
|
-
* This object should be used whenever interfacing with themes.
|
|
46
|
-
*/
|
|
30
|
+
export var themeIds = ['light', 'dark', 'legacy-light', 'legacy-dark', 'spacing', 'typography'];
|
|
47
31
|
var themeConfig = {
|
|
48
32
|
'atlassian-light': {
|
|
49
33
|
id: 'light',
|