@atlaskit/tokens 1.22.1 → 1.24.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 +15 -0
- package/custom-themes/package.json +17 -0
- package/dist/cjs/artifacts/generated-pairs.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-legacy-dark.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-legacy-light.js +2 -2
- package/dist/cjs/artifacts/themes/atlassian-light.js +2 -2
- package/dist/cjs/artifacts/token-default-values.js +2 -1
- package/dist/cjs/artifacts/token-names.js +2 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-dark.js +23 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-dark.js +23 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-legacy-light.js +23 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-light.js +23 -1
- package/dist/cjs/constants.js +3 -1
- package/dist/cjs/custom-theme.js +45 -79
- package/dist/cjs/enable-global-theme.js +70 -0
- package/dist/cjs/entry-points/custom-themes.js +13 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/index.js +7 -0
- package/dist/cjs/load-custom-theme-styles.js +45 -0
- package/dist/cjs/set-global-theme.js +50 -94
- package/dist/cjs/theme-config.js +5 -0
- package/dist/cjs/tokens/atlassian-dark/color/text.js +3 -0
- package/dist/cjs/tokens/atlassian-legacy-dark/color/text.js +3 -0
- package/dist/cjs/tokens/atlassian-legacy-light/color/text.js +3 -0
- package/dist/cjs/tokens/atlassian-light/color/text.js +3 -0
- package/dist/cjs/tokens/default/color/text.js +8 -0
- package/dist/cjs/utils/color-mode-listeners.js +66 -0
- package/dist/cjs/utils/configure-page.js +34 -0
- package/dist/es2019/artifacts/generated-pairs.js +2 -2
- package/dist/es2019/artifacts/themes/atlassian-dark.js +2 -1
- package/dist/es2019/artifacts/themes/atlassian-legacy-dark.js +2 -1
- package/dist/es2019/artifacts/themes/atlassian-legacy-light.js +2 -1
- package/dist/es2019/artifacts/themes/atlassian-light.js +2 -1
- package/dist/es2019/artifacts/token-default-values.js +2 -1
- package/dist/es2019/artifacts/token-names.js +2 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-dark.js +23 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-dark.js +23 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-legacy-light.js +23 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-light.js +23 -1
- package/dist/es2019/constants.js +1 -0
- package/dist/es2019/custom-theme.js +4 -4
- package/dist/es2019/enable-global-theme.js +53 -0
- package/dist/es2019/entry-points/custom-themes.js +1 -0
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/index.js +1 -0
- package/dist/es2019/load-custom-theme-styles.js +37 -0
- package/dist/es2019/set-global-theme.js +34 -65
- package/dist/es2019/theme-config.js +6 -0
- package/dist/es2019/tokens/atlassian-dark/color/text.js +3 -0
- package/dist/es2019/tokens/atlassian-legacy-dark/color/text.js +3 -0
- package/dist/es2019/tokens/atlassian-legacy-light/color/text.js +3 -0
- package/dist/es2019/tokens/atlassian-light/color/text.js +3 -0
- package/dist/es2019/tokens/default/color/text.js +8 -0
- package/dist/es2019/utils/color-mode-listeners.js +48 -0
- package/dist/es2019/utils/configure-page.js +22 -0
- package/dist/esm/artifacts/generated-pairs.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-dark.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-legacy-dark.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-legacy-light.js +2 -2
- package/dist/esm/artifacts/themes/atlassian-light.js +2 -2
- package/dist/esm/artifacts/token-default-values.js +2 -1
- package/dist/esm/artifacts/token-names.js +2 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-dark.js +23 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-dark.js +23 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-legacy-light.js +23 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-light.js +23 -1
- package/dist/esm/constants.js +1 -0
- package/dist/esm/custom-theme.js +45 -78
- package/dist/esm/enable-global-theme.js +63 -0
- package/dist/esm/entry-points/custom-themes.js +1 -0
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/index.js +1 -0
- package/dist/esm/load-custom-theme-styles.js +39 -0
- package/dist/esm/set-global-theme.js +49 -93
- package/dist/esm/theme-config.js +6 -0
- package/dist/esm/tokens/atlassian-dark/color/text.js +3 -0
- package/dist/esm/tokens/atlassian-legacy-dark/color/text.js +3 -0
- package/dist/esm/tokens/atlassian-legacy-light/color/text.js +3 -0
- package/dist/esm/tokens/atlassian-light/color/text.js +3 -0
- package/dist/esm/tokens/default/color/text.js +8 -0
- package/dist/esm/utils/color-mode-listeners.js +58 -0
- package/dist/esm/utils/configure-page.js +28 -0
- package/dist/types/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-legacy-dark.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-legacy-light.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types/artifacts/token-default-values.d.ts +2 -1
- package/dist/types/artifacts/token-names.d.ts +3 -1
- package/dist/types/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-dark.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-legacy-light.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types/artifacts/types-internal.d.ts +2 -2
- package/dist/types/artifacts/types.d.ts +2 -2
- package/dist/types/constants.d.ts +1 -0
- package/dist/types/custom-theme.d.ts +3 -3
- package/dist/types/enable-global-theme.d.ts +25 -0
- package/dist/types/entry-points/custom-themes.d.ts +1 -0
- package/dist/types/get-global-theme.d.ts +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/load-custom-theme-styles.d.ts +17 -0
- package/dist/types/set-global-theme.d.ts +1 -4
- package/dist/types/theme-config.d.ts +7 -0
- package/dist/types/theme-mutation-observer.d.ts +1 -1
- package/dist/types/types.d.ts +1 -0
- package/dist/types/use-theme-observer.d.ts +1 -1
- package/dist/types/utils/color-mode-listeners.d.ts +13 -0
- package/dist/types/utils/configure-page.d.ts +6 -0
- package/dist/types-ts4.5/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/themes/atlassian-dark.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-legacy-dark.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-legacy-light.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-light.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/token-default-values.d.ts +2 -1
- package/dist/types-ts4.5/artifacts/token-names.d.ts +3 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-dark.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-legacy-dark.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-legacy-light.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-light.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types-internal.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/types.d.ts +2 -2
- package/dist/types-ts4.5/constants.d.ts +1 -0
- package/dist/types-ts4.5/custom-theme.d.ts +3 -3
- package/dist/types-ts4.5/enable-global-theme.d.ts +25 -0
- package/dist/types-ts4.5/entry-points/custom-themes.d.ts +1 -0
- package/dist/types-ts4.5/get-global-theme.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -0
- package/dist/types-ts4.5/load-custom-theme-styles.d.ts +17 -0
- package/dist/types-ts4.5/set-global-theme.d.ts +1 -4
- package/dist/types-ts4.5/theme-config.d.ts +7 -0
- package/dist/types-ts4.5/theme-mutation-observer.d.ts +1 -1
- package/dist/types-ts4.5/types.d.ts +1 -0
- package/dist/types-ts4.5/use-theme-observer.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-mode-listeners.d.ts +13 -0
- package/dist/types-ts4.5/utils/configure-page.d.ts +6 -0
- package/figma/atlassian-dark.json +9 -0
- package/figma/atlassian-legacy-dark.json +9 -0
- package/figma/atlassian-legacy-light.json +9 -0
- package/figma/atlassian-light.json +9 -0
- package/package.json +3 -2
- package/report.api.md +20 -2
- package/tmp/api-report-tmp.d.ts +9 -4
package/dist/cjs/custom-theme.js
CHANGED
|
@@ -1,14 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
3
|
Object.defineProperty(exports, "__esModule", {
|
|
5
4
|
value: true
|
|
6
5
|
});
|
|
7
6
|
exports.CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = void 0;
|
|
8
7
|
exports.getCustomThemeStyles = getCustomThemeStyles;
|
|
9
8
|
exports.loadAndAppendCustomThemeCss = loadAndAppendCustomThemeCss;
|
|
10
|
-
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
11
|
-
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
12
9
|
var _constants = require("./constants");
|
|
13
10
|
var _themeConfig = require("./theme-config");
|
|
14
11
|
var _customThemeLoadingUtils = require("./utils/custom-theme-loading-utils");
|
|
@@ -29,84 +26,53 @@ var CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = 10;
|
|
|
29
26
|
* @param {string} themeState.colorMode Determines which color theme is applied
|
|
30
27
|
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
31
28
|
*
|
|
32
|
-
* @returns
|
|
29
|
+
* @returns An object array, containing theme IDs, data-attributes to attach to the theme, and the theme CSS.
|
|
33
30
|
* If an error is encountered while loading themes, the themes array will be empty.
|
|
34
31
|
*/
|
|
35
32
|
exports.CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD = CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD;
|
|
36
|
-
function getCustomThemeStyles(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
'data-custom-theme': uniqueId
|
|
71
|
-
},
|
|
72
|
-
css: "\nhtml[".concat(_constants.CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(_constants.COLOR_MODE_ATTRIBUTE, "=\"dark\"][data-theme~=\"dark:dark\"] {\n /* Branded tokens */\n ").concat((0, _customThemeLoadingUtils.reduceTokenMap)(tokenMaps.dark, themeRamp), "\n}")
|
|
73
|
-
});
|
|
74
|
-
}
|
|
75
|
-
return _context.abrupt("return", themes);
|
|
76
|
-
case 10:
|
|
77
|
-
case "end":
|
|
78
|
-
return _context.stop();
|
|
79
|
-
}
|
|
80
|
-
}, _callee);
|
|
81
|
-
}));
|
|
82
|
-
return _getCustomThemeStyles.apply(this, arguments);
|
|
83
|
-
}
|
|
84
|
-
function loadAndAppendCustomThemeCss(_x2) {
|
|
85
|
-
return _loadAndAppendCustomThemeCss.apply(this, arguments);
|
|
33
|
+
function getCustomThemeStyles(themeState) {
|
|
34
|
+
var _themeState$UNSAFE_th;
|
|
35
|
+
var 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
|
+
var mode = (themeState === null || themeState === void 0 ? void 0 : themeState.colorMode) || _themeConfig.themeStateDefaults['colorMode'];
|
|
37
|
+
var optionString = JSON.stringify(themeState === null || themeState === void 0 ? void 0 : themeState.UNSAFE_themeOptions);
|
|
38
|
+
var uniqueId = (0, _hash.hash)(optionString);
|
|
39
|
+
var themeRamp = (0, _generateCustomColorRamp.generateColors)(brandColor).ramp;
|
|
40
|
+
|
|
41
|
+
// outputs object to generate to CSS from
|
|
42
|
+
var themes = [];
|
|
43
|
+
var tokenMaps = (0, _generateCustomColorRamp.generateTokenMapWithContrastCheck)(brandColor, mode, themeRamp);
|
|
44
|
+
if ((mode === 'light' || mode === 'auto') && tokenMaps.light) {
|
|
45
|
+
// Light mode theming
|
|
46
|
+
themes.push({
|
|
47
|
+
id: 'light',
|
|
48
|
+
attrs: {
|
|
49
|
+
'data-theme': 'light',
|
|
50
|
+
'data-custom-theme': uniqueId
|
|
51
|
+
},
|
|
52
|
+
css: "\nhtml[".concat(_constants.CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(_constants.COLOR_MODE_ATTRIBUTE, "=\"light\"][data-theme~=\"light:light\"] {\n /* Branded tokens */\n ").concat((0, _customThemeLoadingUtils.reduceTokenMap)(tokenMaps.light, themeRamp), "\n}")
|
|
53
|
+
});
|
|
54
|
+
}
|
|
55
|
+
if ((mode === 'dark' || mode === 'auto') && tokenMaps.dark) {
|
|
56
|
+
// Dark mode theming
|
|
57
|
+
themes.push({
|
|
58
|
+
id: 'dark',
|
|
59
|
+
attrs: {
|
|
60
|
+
'data-theme': 'dark',
|
|
61
|
+
'data-custom-theme': uniqueId
|
|
62
|
+
},
|
|
63
|
+
css: "\nhtml[".concat(_constants.CUSTOM_THEME_ATTRIBUTE, "=\"").concat(uniqueId, "\"][").concat(_constants.COLOR_MODE_ATTRIBUTE, "=\"dark\"][data-theme~=\"dark:dark\"] {\n /* Branded tokens */\n ").concat((0, _customThemeLoadingUtils.reduceTokenMap)(tokenMaps.dark, themeRamp), "\n}")
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
return themes;
|
|
86
67
|
}
|
|
87
|
-
function
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
(0, _customThemeLoadingUtils.limitSizeOfCustomStyleElements)(CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD);
|
|
98
|
-
themes.map(function (theme) {
|
|
99
|
-
var styleTag = document.createElement('style');
|
|
100
|
-
document.head.appendChild(styleTag);
|
|
101
|
-
styleTag.dataset.theme = theme.attrs['data-theme'];
|
|
102
|
-
styleTag.dataset.customTheme = theme.attrs['data-custom-theme'];
|
|
103
|
-
styleTag.textContent = theme.css;
|
|
104
|
-
});
|
|
105
|
-
case 5:
|
|
106
|
-
case "end":
|
|
107
|
-
return _context2.stop();
|
|
108
|
-
}
|
|
109
|
-
}, _callee2);
|
|
110
|
-
}));
|
|
111
|
-
return _loadAndAppendCustomThemeCss.apply(this, arguments);
|
|
68
|
+
function loadAndAppendCustomThemeCss(themeState) {
|
|
69
|
+
var themes = getCustomThemeStyles(themeState);
|
|
70
|
+
(0, _customThemeLoadingUtils.limitSizeOfCustomStyleElements)(CUSTOM_STYLE_ELEMENTS_SIZE_THRESHOLD);
|
|
71
|
+
themes.map(function (theme) {
|
|
72
|
+
var styleTag = document.createElement('style');
|
|
73
|
+
document.head.appendChild(styleTag);
|
|
74
|
+
styleTag.dataset.theme = theme.attrs['data-theme'];
|
|
75
|
+
styleTag.dataset.customTheme = theme.attrs['data-custom-theme'];
|
|
76
|
+
styleTag.textContent = theme.css;
|
|
77
|
+
});
|
|
112
78
|
}
|
|
@@ -0,0 +1,70 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
exports.default = void 0;
|
|
8
|
+
var _themeConfig = require("./theme-config");
|
|
9
|
+
var _configurePage = _interopRequireDefault(require("./utils/configure-page"));
|
|
10
|
+
var _getThemePreferences = require("./utils/get-theme-preferences");
|
|
11
|
+
/**
|
|
12
|
+
* Synchronously sets the theme globally at runtime. Themes are not loaded;
|
|
13
|
+
* use `getThemeStyles` and other server-side utilities to generate and load them.
|
|
14
|
+
*
|
|
15
|
+
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
16
|
+
* @param {string} themeState.colorMode Determines which color theme is applied. If set to `auto`, the theme applied will be determined by the OS setting.
|
|
17
|
+
* @param {string} themeState.dark The color theme to be applied when the color mode resolves to 'dark'.
|
|
18
|
+
* @param {string} themeState.light The color theme to be applied when the color mode resolves to 'light'.
|
|
19
|
+
* @param {string} themeState.shape The shape theme to be applied.
|
|
20
|
+
* @param {string} themeState.spacing The spacing theme to be applied.
|
|
21
|
+
* @param {string} themeState.typography The typography theme to be applied.
|
|
22
|
+
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
23
|
+
* @param {function} themeLoader Callback function used to override the default theme loading functionality.
|
|
24
|
+
*
|
|
25
|
+
* @returns An unbind function, that can be used to stop listening for changes to system theme.
|
|
26
|
+
*
|
|
27
|
+
* @example
|
|
28
|
+
* ```
|
|
29
|
+
* enableGlobalTheme({colorMode: 'auto', light: 'light', dark: 'dark', spacing: 'spacing'});
|
|
30
|
+
* ```
|
|
31
|
+
*/
|
|
32
|
+
var enableGlobalTheme = function enableGlobalTheme() {
|
|
33
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
34
|
+
_ref$colorMode = _ref.colorMode,
|
|
35
|
+
colorMode = _ref$colorMode === void 0 ? _themeConfig.themeStateDefaults['colorMode'] : _ref$colorMode,
|
|
36
|
+
_ref$dark = _ref.dark,
|
|
37
|
+
dark = _ref$dark === void 0 ? _themeConfig.themeStateDefaults['dark'] : _ref$dark,
|
|
38
|
+
_ref$light = _ref.light,
|
|
39
|
+
light = _ref$light === void 0 ? _themeConfig.themeStateDefaults['light'] : _ref$light,
|
|
40
|
+
_ref$shape = _ref.shape,
|
|
41
|
+
shape = _ref$shape === void 0 ? _themeConfig.themeStateDefaults['shape'] : _ref$shape,
|
|
42
|
+
_ref$spacing = _ref.spacing,
|
|
43
|
+
spacing = _ref$spacing === void 0 ? _themeConfig.themeStateDefaults['spacing'] : _ref$spacing,
|
|
44
|
+
_ref$typography = _ref.typography,
|
|
45
|
+
typography = _ref$typography === void 0 ? _themeConfig.themeStateDefaults['typography'] : _ref$typography,
|
|
46
|
+
_ref$UNSAFE_themeOpti = _ref.UNSAFE_themeOptions,
|
|
47
|
+
UNSAFE_themeOptions = _ref$UNSAFE_themeOpti === void 0 ? _themeConfig.themeStateDefaults['UNSAFE_themeOptions'] : _ref$UNSAFE_themeOpti;
|
|
48
|
+
var themeLoader = arguments.length > 1 ? arguments[1] : undefined;
|
|
49
|
+
var themeState = {
|
|
50
|
+
colorMode: colorMode,
|
|
51
|
+
dark: dark,
|
|
52
|
+
light: light,
|
|
53
|
+
shape: shape,
|
|
54
|
+
spacing: spacing,
|
|
55
|
+
typography: typography,
|
|
56
|
+
UNSAFE_themeOptions: themeLoader ? undefined : UNSAFE_themeOptions
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
// Determine what to load and call theme loader
|
|
60
|
+
var themePreferences = (0, _getThemePreferences.getThemePreferences)(themeState);
|
|
61
|
+
if (themeLoader) {
|
|
62
|
+
themePreferences.map(function (themeId) {
|
|
63
|
+
return themeLoader(themeId);
|
|
64
|
+
});
|
|
65
|
+
}
|
|
66
|
+
var autoUnbind = (0, _configurePage.default)(themeState);
|
|
67
|
+
return autoUnbind;
|
|
68
|
+
};
|
|
69
|
+
var _default = enableGlobalTheme;
|
|
70
|
+
exports.default = _default;
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
Object.defineProperty(exports, "__esModule", {
|
|
5
|
+
value: true
|
|
6
|
+
});
|
|
7
|
+
Object.defineProperty(exports, "UNSAFE_loadCustomThemeStyles", {
|
|
8
|
+
enumerable: true,
|
|
9
|
+
get: function get() {
|
|
10
|
+
return _loadCustomThemeStyles.default;
|
|
11
|
+
}
|
|
12
|
+
});
|
|
13
|
+
var _loadCustomThemeStyles = _interopRequireDefault(require("../load-custom-theme-styles"));
|
|
@@ -8,7 +8,7 @@ exports.default = void 0;
|
|
|
8
8
|
var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
|
|
9
9
|
var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
|
|
10
10
|
var name = "@atlaskit/tokens";
|
|
11
|
-
var version = "1.
|
|
11
|
+
var version = "1.24.0";
|
|
12
12
|
/**
|
|
13
13
|
* Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
|
|
14
14
|
* resulting CSS Custom Property.
|
package/dist/cjs/get-token.js
CHANGED
|
@@ -9,7 +9,7 @@ var _warnOnce = _interopRequireDefault(require("@atlaskit/ds-lib/warn-once"));
|
|
|
9
9
|
var _tokenNames = _interopRequireDefault(require("./artifacts/token-names"));
|
|
10
10
|
var _constants = require("./constants");
|
|
11
11
|
var name = "@atlaskit/tokens";
|
|
12
|
-
var version = "1.
|
|
12
|
+
var version = "1.24.0";
|
|
13
13
|
/**
|
|
14
14
|
* Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
|
|
15
15
|
* This should be used to implement design decisions throughout your application.
|
package/dist/cjs/index.js
CHANGED
|
@@ -16,6 +16,12 @@ Object.defineProperty(exports, "ThemeMutationObserver", {
|
|
|
16
16
|
return _themeMutationObserver.default;
|
|
17
17
|
}
|
|
18
18
|
});
|
|
19
|
+
Object.defineProperty(exports, "enableGlobalTheme", {
|
|
20
|
+
enumerable: true,
|
|
21
|
+
get: function get() {
|
|
22
|
+
return _enableGlobalTheme.default;
|
|
23
|
+
}
|
|
24
|
+
});
|
|
19
25
|
Object.defineProperty(exports, "getGlobalTheme", {
|
|
20
26
|
enumerable: true,
|
|
21
27
|
get: function get() {
|
|
@@ -86,6 +92,7 @@ var _themeConfig = _interopRequireDefault(require("./theme-config"));
|
|
|
86
92
|
var _getToken = _interopRequireDefault(require("./get-token"));
|
|
87
93
|
var _getTokenValue = _interopRequireDefault(require("./get-token-value"));
|
|
88
94
|
var _setGlobalTheme = _interopRequireDefault(require("./set-global-theme"));
|
|
95
|
+
var _enableGlobalTheme = _interopRequireDefault(require("./enable-global-theme"));
|
|
89
96
|
var _getThemeStyles = _interopRequireDefault(require("./get-theme-styles"));
|
|
90
97
|
var _getThemeHtmlAttrs = _interopRequireDefault(require("./get-theme-html-attrs"));
|
|
91
98
|
var _getSsrAutoScript = _interopRequireDefault(require("./get-ssr-auto-script"));
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var _customTheme = require("./custom-theme");
|
|
8
|
+
var _themeConfig = require("./theme-config");
|
|
9
|
+
var _colorUtils = require("./utils/color-utils");
|
|
10
|
+
var _customThemeLoadingUtils = require("./utils/custom-theme-loading-utils");
|
|
11
|
+
/**
|
|
12
|
+
* Synchronously generates and applies custom theme styles to the page.
|
|
13
|
+
*
|
|
14
|
+
* @param {Object<string, string>} themeState The themes and color mode that should be applied.
|
|
15
|
+
* @param {Object} themeState.UNSAFE_themeOptions The custom branding options to be used for custom theme generation
|
|
16
|
+
*
|
|
17
|
+
* @example
|
|
18
|
+
* ```
|
|
19
|
+
* UNSAFE_loadCustomThemeStyles({
|
|
20
|
+
* colorMode: 'auto',
|
|
21
|
+
* UNSAFE_themeOptions: { brandColor: '#FF0000' }
|
|
22
|
+
* });
|
|
23
|
+
* ```
|
|
24
|
+
*/
|
|
25
|
+
var UNSAFE_loadCustomThemeStyles = function UNSAFE_loadCustomThemeStyles() {
|
|
26
|
+
var _ref = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {},
|
|
27
|
+
_ref$colorMode = _ref.colorMode,
|
|
28
|
+
colorMode = _ref$colorMode === void 0 ? _themeConfig.themeStateDefaults['colorMode'] : _ref$colorMode,
|
|
29
|
+
_ref$UNSAFE_themeOpti = _ref.UNSAFE_themeOptions,
|
|
30
|
+
UNSAFE_themeOptions = _ref$UNSAFE_themeOpti === void 0 ? _themeConfig.themeStateDefaults['UNSAFE_themeOptions'] : _ref$UNSAFE_themeOpti;
|
|
31
|
+
// Load custom theme styles
|
|
32
|
+
if (UNSAFE_themeOptions && (0, _colorUtils.isValidBrandHex)(UNSAFE_themeOptions === null || UNSAFE_themeOptions === void 0 ? void 0 : UNSAFE_themeOptions.brandColor)) {
|
|
33
|
+
var attrOfMissingCustomStyles = (0, _customThemeLoadingUtils.findMissingCustomStyleElements)(UNSAFE_themeOptions, colorMode);
|
|
34
|
+
if (attrOfMissingCustomStyles.length !== 0) {
|
|
35
|
+
(0, _customTheme.loadAndAppendCustomThemeCss)({
|
|
36
|
+
colorMode: attrOfMissingCustomStyles.length === 2 ? 'auto' :
|
|
37
|
+
// only load the missing custom theme styles
|
|
38
|
+
attrOfMissingCustomStyles[0],
|
|
39
|
+
UNSAFE_themeOptions: UNSAFE_themeOptions
|
|
40
|
+
});
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
};
|
|
44
|
+
var _default = UNSAFE_loadCustomThemeStyles;
|
|
45
|
+
exports.default = _default;
|
|
@@ -7,36 +7,15 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
7
7
|
});
|
|
8
8
|
exports.default = void 0;
|
|
9
9
|
var _regenerator = _interopRequireDefault(require("@babel/runtime/regenerator"));
|
|
10
|
-
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
10
|
var _asyncToGenerator2 = _interopRequireDefault(require("@babel/runtime/helpers/asyncToGenerator"));
|
|
13
|
-
var _bindEventListener = require("bind-event-listener");
|
|
14
|
-
var _noop = _interopRequireDefault(require("@atlaskit/ds-lib/noop"));
|
|
15
|
-
var _constants = require("./constants");
|
|
16
|
-
var _getThemeHtmlAttrs = _interopRequireDefault(require("./get-theme-html-attrs"));
|
|
17
11
|
var _themeConfig = require("./theme-config");
|
|
18
12
|
var _colorUtils = require("./utils/color-utils");
|
|
13
|
+
var _configurePage = _interopRequireDefault(require("./utils/configure-page"));
|
|
19
14
|
var _customThemeLoadingUtils = require("./utils/custom-theme-loading-utils");
|
|
20
15
|
var _getThemePreferences = require("./utils/get-theme-preferences");
|
|
21
16
|
var _themeLoading = require("./utils/theme-loading");
|
|
22
17
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
23
18
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
24
|
-
// Represents theme state once mounted to the page (auto is hidden from observers)
|
|
25
|
-
|
|
26
|
-
var isMatchMediaAvailable = typeof window !== 'undefined' && 'matchMedia' in window;
|
|
27
|
-
var darkModeMql = isMatchMediaAvailable && window.matchMedia(_themeLoading.darkModeMediaQuery);
|
|
28
|
-
var unbindThemeChangeListener = _noop.default;
|
|
29
|
-
|
|
30
|
-
/**
|
|
31
|
-
* Updates the current theme when the system theme changes. Should be bound
|
|
32
|
-
* to an event listener listening on the '(prefers-color-scheme: dark)' query
|
|
33
|
-
* @param e The event representing a change in system theme.
|
|
34
|
-
*/
|
|
35
|
-
var checkNativeListener = function checkNativeListener(e) {
|
|
36
|
-
var element = document.documentElement;
|
|
37
|
-
element.setAttribute(_constants.COLOR_MODE_ATTRIBUTE, e.matches ? 'dark' : 'light');
|
|
38
|
-
};
|
|
39
|
-
|
|
40
19
|
/**
|
|
41
20
|
* Sets the theme globally at runtime. This updates the `data-theme` and `data-color-mode` attributes on your page's <html> tag.
|
|
42
21
|
*
|
|
@@ -75,26 +54,31 @@ var setGlobalTheme = /*#__PURE__*/function () {
|
|
|
75
54
|
_ref2$UNSAFE_themeOpt,
|
|
76
55
|
UNSAFE_themeOptions,
|
|
77
56
|
themeLoader,
|
|
57
|
+
themeState,
|
|
78
58
|
themePreferences,
|
|
79
59
|
loadingStrategy,
|
|
80
|
-
|
|
60
|
+
loadingTasks,
|
|
61
|
+
mode,
|
|
62
|
+
attrOfMissingCustomStyles,
|
|
63
|
+
autoUnbind,
|
|
81
64
|
_args3 = arguments;
|
|
82
65
|
return _regenerator.default.wrap(function _callee3$(_context3) {
|
|
83
66
|
while (1) switch (_context3.prev = _context3.next) {
|
|
84
67
|
case 0:
|
|
85
68
|
_ref2 = _args3.length > 0 && _args3[0] !== undefined ? _args3[0] : {}, _ref2$colorMode = _ref2.colorMode, colorMode = _ref2$colorMode === void 0 ? _themeConfig.themeStateDefaults['colorMode'] : _ref2$colorMode, _ref2$dark = _ref2.dark, dark = _ref2$dark === void 0 ? _themeConfig.themeStateDefaults['dark'] : _ref2$dark, _ref2$light = _ref2.light, light = _ref2$light === void 0 ? _themeConfig.themeStateDefaults['light'] : _ref2$light, _ref2$shape = _ref2.shape, shape = _ref2$shape === void 0 ? _themeConfig.themeStateDefaults['shape'] : _ref2$shape, _ref2$spacing = _ref2.spacing, spacing = _ref2$spacing === void 0 ? _themeConfig.themeStateDefaults['spacing'] : _ref2$spacing, _ref2$typography = _ref2.typography, typography = _ref2$typography === void 0 ? _themeConfig.themeStateDefaults['typography'] : _ref2$typography, _ref2$UNSAFE_themeOpt = _ref2.UNSAFE_themeOptions, UNSAFE_themeOptions = _ref2$UNSAFE_themeOpt === void 0 ? _themeConfig.themeStateDefaults['UNSAFE_themeOptions'] : _ref2$UNSAFE_themeOpt;
|
|
86
69
|
themeLoader = _args3.length > 1 ? _args3[1] : undefined;
|
|
87
|
-
|
|
70
|
+
themeState = {
|
|
88
71
|
colorMode: colorMode,
|
|
89
72
|
dark: dark,
|
|
90
73
|
light: light,
|
|
91
74
|
shape: shape,
|
|
92
75
|
spacing: spacing,
|
|
93
|
-
typography: typography
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
76
|
+
typography: typography,
|
|
77
|
+
UNSAFE_themeOptions: themeLoader ? undefined : UNSAFE_themeOptions
|
|
78
|
+
}; // Determine what to load and loading strategy
|
|
79
|
+
themePreferences = (0, _getThemePreferences.getThemePreferences)(themeState);
|
|
80
|
+
loadingStrategy = themeLoader ? themeLoader : _themeLoading.loadAndAppendThemeCss; // Load standard themes
|
|
81
|
+
loadingTasks = themePreferences.map( /*#__PURE__*/function () {
|
|
98
82
|
var _ref3 = (0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee(themeId) {
|
|
99
83
|
return _regenerator.default.wrap(function _callee$(_context) {
|
|
100
84
|
while (1) switch (_context.prev = _context.next) {
|
|
@@ -112,73 +96,45 @@ var setGlobalTheme = /*#__PURE__*/function () {
|
|
|
112
96
|
return function (_x) {
|
|
113
97
|
return _ref3.apply(this, arguments);
|
|
114
98
|
};
|
|
115
|
-
}())
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
99
|
+
}()); // Load custom themes if needed
|
|
100
|
+
if (!themeLoader && UNSAFE_themeOptions && (0, _colorUtils.isValidBrandHex)(UNSAFE_themeOptions === null || UNSAFE_themeOptions === void 0 ? void 0 : UNSAFE_themeOptions.brandColor)) {
|
|
101
|
+
mode = colorMode || _themeConfig.themeStateDefaults['colorMode'];
|
|
102
|
+
attrOfMissingCustomStyles = (0, _customThemeLoadingUtils.findMissingCustomStyleElements)(UNSAFE_themeOptions, mode);
|
|
103
|
+
if (attrOfMissingCustomStyles.length > 0) {
|
|
104
|
+
// Load custom theme styles
|
|
105
|
+
loadingTasks.push((0, _asyncToGenerator2.default)( /*#__PURE__*/_regenerator.default.mark(function _callee2() {
|
|
106
|
+
var _yield$import, loadAndAppendCustomThemeCss;
|
|
107
|
+
return _regenerator.default.wrap(function _callee2$(_context2) {
|
|
108
|
+
while (1) switch (_context2.prev = _context2.next) {
|
|
109
|
+
case 0:
|
|
110
|
+
_context2.next = 2;
|
|
111
|
+
return Promise.resolve().then(function () {
|
|
112
|
+
return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
|
|
113
|
+
'./custom-theme'));
|
|
114
|
+
});
|
|
115
|
+
case 2:
|
|
116
|
+
_yield$import = _context2.sent;
|
|
117
|
+
loadAndAppendCustomThemeCss = _yield$import.loadAndAppendCustomThemeCss;
|
|
118
|
+
loadAndAppendCustomThemeCss({
|
|
119
|
+
colorMode: attrOfMissingCustomStyles.length === 2 ? 'auto' :
|
|
120
|
+
// only load the missing custom theme styles
|
|
121
|
+
attrOfMissingCustomStyles[0],
|
|
122
|
+
UNSAFE_themeOptions: UNSAFE_themeOptions
|
|
123
|
+
});
|
|
124
|
+
case 5:
|
|
125
|
+
case "end":
|
|
126
|
+
return _context2.stop();
|
|
129
127
|
}
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
return Promise.resolve().then(function () {
|
|
134
|
-
return _interopRequireWildcard(require( /* webpackChunkName: "@atlaskit-internal_atlassian-custom-theme" */
|
|
135
|
-
'./custom-theme'));
|
|
136
|
-
});
|
|
137
|
-
case 7:
|
|
138
|
-
_yield$import = _context2.sent;
|
|
139
|
-
loadAndAppendCustomThemeCss = _yield$import.loadAndAppendCustomThemeCss;
|
|
140
|
-
_context2.next = 11;
|
|
141
|
-
return loadAndAppendCustomThemeCss({
|
|
142
|
-
colorMode: attrOfMissingCustomStyles.length === 2 ? 'auto' :
|
|
143
|
-
// only load the missing custom theme styles
|
|
144
|
-
attrOfMissingCustomStyles[0],
|
|
145
|
-
UNSAFE_themeOptions: UNSAFE_themeOptions
|
|
146
|
-
});
|
|
147
|
-
case 11:
|
|
148
|
-
case "end":
|
|
149
|
-
return _context2.stop();
|
|
150
|
-
}
|
|
151
|
-
}, _callee2);
|
|
152
|
-
}))()]));
|
|
153
|
-
case 6:
|
|
154
|
-
if (colorMode === 'auto' && darkModeMql) {
|
|
155
|
-
colorMode = darkModeMql.matches ? 'dark' : 'light';
|
|
156
|
-
// Add an event listener for changes to the system theme.
|
|
157
|
-
// If the function exists, it will not be added again.
|
|
158
|
-
unbindThemeChangeListener = (0, _bindEventListener.bind)(darkModeMql, {
|
|
159
|
-
type: 'change',
|
|
160
|
-
listener: checkNativeListener
|
|
161
|
-
});
|
|
162
|
-
} else {
|
|
163
|
-
unbindThemeChangeListener();
|
|
128
|
+
}, _callee2);
|
|
129
|
+
}))());
|
|
130
|
+
}
|
|
164
131
|
}
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
typography: typography,
|
|
172
|
-
UNSAFE_themeOptions: themeLoader ? undefined : UNSAFE_themeOptions
|
|
173
|
-
});
|
|
174
|
-
Object.entries(themeAttributes).forEach(function (_ref5) {
|
|
175
|
-
var _ref6 = (0, _slicedToArray2.default)(_ref5, 2),
|
|
176
|
-
key = _ref6[0],
|
|
177
|
-
value = _ref6[1];
|
|
178
|
-
document.documentElement.setAttribute(key, value);
|
|
179
|
-
});
|
|
180
|
-
return _context3.abrupt("return", unbindThemeChangeListener);
|
|
181
|
-
case 10:
|
|
132
|
+
_context3.next = 9;
|
|
133
|
+
return Promise.all(loadingTasks);
|
|
134
|
+
case 9:
|
|
135
|
+
autoUnbind = (0, _configurePage.default)(themeState);
|
|
136
|
+
return _context3.abrupt("return", autoUnbind);
|
|
137
|
+
case 11:
|
|
182
138
|
case "end":
|
|
183
139
|
return _context3.stop();
|
|
184
140
|
}
|
package/dist/cjs/theme-config.js
CHANGED
|
@@ -187,6 +187,11 @@ var themeStateDefaults = {
|
|
|
187
187
|
typography: undefined,
|
|
188
188
|
UNSAFE_themeOptions: undefined
|
|
189
189
|
};
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* Represents theme state once mounted to the page
|
|
193
|
+
* (the page doesn't have an "auto" color mode, it's either light or dark)
|
|
194
|
+
*/
|
|
190
195
|
exports.themeStateDefaults = themeStateDefaults;
|
|
191
196
|
var _default = themeConfig;
|
|
192
197
|
exports.default = _default;
|
|
@@ -130,6 +130,14 @@ var color = {
|
|
|
130
130
|
introduced: '0.6.0',
|
|
131
131
|
description: 'Use for links in a pressed state.'
|
|
132
132
|
}
|
|
133
|
+
},
|
|
134
|
+
visited: {
|
|
135
|
+
attributes: {
|
|
136
|
+
group: 'paint',
|
|
137
|
+
state: 'active',
|
|
138
|
+
introduced: '1.23.0',
|
|
139
|
+
description: 'Use for links in a visited state.'
|
|
140
|
+
}
|
|
133
141
|
}
|
|
134
142
|
}
|
|
135
143
|
}
|