@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
|
@@ -22,6 +22,7 @@ export const getLuminance = ({
|
|
|
22
22
|
g,
|
|
23
23
|
b
|
|
24
24
|
}) => (r * 299 + g * 587 + b * 114) / 1000;
|
|
25
|
+
|
|
25
26
|
/**
|
|
26
27
|
* Returns an accessible hard-coded text color based on the color contrast with
|
|
27
28
|
* the background.
|
|
@@ -31,7 +32,6 @@ export const getLuminance = ({
|
|
|
31
32
|
* of a hard-coded color. This is to support more transparent backgrounds
|
|
32
33
|
* to allow the text to invert colors depending on the current theme's surface color.
|
|
33
34
|
*/
|
|
34
|
-
|
|
35
35
|
export const getTextColorForBackground = (hex, opts) => {
|
|
36
36
|
const {
|
|
37
37
|
r,
|
|
@@ -50,22 +50,20 @@ export const getTextColorForBackground = (hex, opts) => {
|
|
|
50
50
|
dark: a > alphaLimit
|
|
51
51
|
};
|
|
52
52
|
const alphaLimitExceeded = (opts === null || opts === void 0 ? void 0 : opts.hardcodedSurface) && alphaConditionsPerSurface[opts.hardcodedSurface];
|
|
53
|
-
|
|
54
53
|
if (!(opts !== null && opts !== void 0 && opts.hardcodedSurface) && a < alphaLimit) {
|
|
55
54
|
// This color is transparent, so the text will mainly cast onto the surface behind.
|
|
56
55
|
// Needs to use tokens otherwise Dark mode would cause black text on black surface
|
|
57
56
|
return token('color.text', 'black');
|
|
58
57
|
}
|
|
59
|
-
|
|
60
58
|
return lum > 150 && !a || a && alphaLimitExceeded ? 'black' : 'white';
|
|
61
59
|
};
|
|
60
|
+
|
|
62
61
|
/**
|
|
63
62
|
* Returns a border if determined to be required based on the color contrast with
|
|
64
63
|
* the background.
|
|
65
64
|
*
|
|
66
65
|
* @param hex - The Hex color code of the background
|
|
67
66
|
*/
|
|
68
|
-
|
|
69
67
|
export const getBorderForBackground = hex => {
|
|
70
68
|
const {
|
|
71
69
|
r,
|
|
@@ -80,12 +78,12 @@ export const getBorderForBackground = hex => {
|
|
|
80
78
|
});
|
|
81
79
|
return lum > 240 || a < 0.2 ? `1px solid ${token('color.border', '#091E4224')}` : undefined;
|
|
82
80
|
};
|
|
81
|
+
|
|
83
82
|
/**
|
|
84
83
|
* Returns a box shadow formatted for CSS from a ShadowToken raw value.
|
|
85
84
|
*
|
|
86
85
|
* @param rawShadow - ShadowToken raw value
|
|
87
86
|
*/
|
|
88
|
-
|
|
89
87
|
export const getBoxShadow = rawShadow => rawShadow.map(({
|
|
90
88
|
radius,
|
|
91
89
|
offset,
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import themeImportMap from '../artifacts/theme-import-map';
|
|
2
|
+
import { THEME_DATA_ATTRIBUTE } from '../constants';
|
|
3
|
+
export const loadAndAppendThemeCss = async themeId => {
|
|
4
|
+
if (document.head.querySelector(`style[${THEME_DATA_ATTRIBUTE}="${themeId}"]`)) {
|
|
5
|
+
return;
|
|
6
|
+
}
|
|
7
|
+
const themeCss = await loadThemeCss(themeId);
|
|
8
|
+
const style = document.createElement('style');
|
|
9
|
+
style.textContent = themeCss;
|
|
10
|
+
style.dataset.theme = themeId;
|
|
11
|
+
document.head.appendChild(style);
|
|
12
|
+
};
|
|
13
|
+
export const loadThemeCss = async themeId => {
|
|
14
|
+
const {
|
|
15
|
+
default: themeCss
|
|
16
|
+
} = await themeImportMap[themeId]();
|
|
17
|
+
return themeCss;
|
|
18
|
+
};
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { themeIds } from '../theme-config';
|
|
2
|
+
const themeKinds = ['light', 'dark', 'spacing', 'typography'];
|
|
3
|
+
const isThemeKind = themeKind => {
|
|
4
|
+
return themeKinds.find(kind => kind === themeKind) !== undefined;
|
|
5
|
+
};
|
|
6
|
+
const isThemeIds = themeId => {
|
|
7
|
+
return themeIds.find(id => id === themeId) !== undefined;
|
|
8
|
+
};
|
|
9
|
+
const isColorMode = modeId => {
|
|
10
|
+
return ['light', 'dark', 'auto'].includes(modeId);
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Converts a string that is formatted for the `data-theme` HTML attribute
|
|
14
|
+
* to an object that can be passed to `setGlobalTheme`.
|
|
15
|
+
*
|
|
16
|
+
* @param {string} themes The themes that should be applied.
|
|
17
|
+
*
|
|
18
|
+
* @example
|
|
19
|
+
* ```
|
|
20
|
+
* themeStringToObject('dark:dark light:legacy-light spacing:spacing');
|
|
21
|
+
* // returns { dark: 'dark', light: 'legacy-light', spacing: 'spacing' }
|
|
22
|
+
* ```
|
|
23
|
+
*/
|
|
24
|
+
export const themeStringToObject = themeState => {
|
|
25
|
+
return themeState.split(' ').map(theme => theme.split(':')).reduce((themeObject, [kind, id]) => {
|
|
26
|
+
if (kind === 'colorMode' && isColorMode(id)) {
|
|
27
|
+
themeObject[kind] = id;
|
|
28
|
+
}
|
|
29
|
+
if (isThemeKind(kind) && isThemeIds(id)) {
|
|
30
|
+
themeObject[kind] = id;
|
|
31
|
+
}
|
|
32
|
+
return themeObject;
|
|
33
|
+
}, {});
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* Converts a theme object to a string formatted for the `data-theme` HTML attribute.
|
|
38
|
+
*
|
|
39
|
+
* @param {object} themes The themes that should be applied.
|
|
40
|
+
*
|
|
41
|
+
* @example
|
|
42
|
+
* ```
|
|
43
|
+
* themeObjectToString({ dark: 'dark', light: 'legacy-light', spacing: 'spacing' });
|
|
44
|
+
* // returns 'dark:dark light:legacy-light spacing:spacing'
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export const themeObjectToString = themeState => Object.entries(themeState).reduce((themeString, [kind, id]) => (kind === 'colorMode' || isThemeKind(kind)) && (isThemeIds(id) || isColorMode(id)) ? themeString + `${themeString ? ' ' : ''}` + `${kind}:${id}` : themeString, '');
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CSS_PREFIX, CSS_VAR_FULL } from '../constants';
|
|
2
|
+
|
|
2
3
|
/**
|
|
3
4
|
* Transforms a style dictionary token path to a CSS custom property.
|
|
4
5
|
*
|
|
@@ -13,13 +14,14 @@ import { CSS_PREFIX, CSS_VAR_FULL } from '../constants';
|
|
|
13
14
|
* // Returns ds-background-bold
|
|
14
15
|
* getCSSCustomProperty('color.background.bold.[default]')
|
|
15
16
|
*/
|
|
16
|
-
|
|
17
17
|
export const getCSSCustomProperty = path => {
|
|
18
|
-
const normalizedPath = typeof path === 'string' ? path.split('.') : path;
|
|
18
|
+
const normalizedPath = typeof path === 'string' ? path.split('.') : path;
|
|
19
19
|
|
|
20
|
+
// Opacity and other 'shallow' groups are more readable when not trimmed
|
|
20
21
|
const slice = CSS_VAR_FULL.includes(path[0]) ? 0 : 1;
|
|
21
22
|
return `--${[CSS_PREFIX, ...normalizedPath.slice(slice)].filter(el => el !== '[default]').join('-')}`;
|
|
22
23
|
};
|
|
24
|
+
|
|
23
25
|
/**
|
|
24
26
|
* Transforms a style dictionary token path to a shorthand token id
|
|
25
27
|
* These ids will be typically be how tokens are interacted with via typescript and css
|
|
@@ -34,11 +36,11 @@ export const getCSSCustomProperty = path => {
|
|
|
34
36
|
* // Returns color.background.bold
|
|
35
37
|
* getTokenId('color.background.bold.[default]')
|
|
36
38
|
*/
|
|
37
|
-
|
|
38
39
|
export const getTokenId = path => {
|
|
39
40
|
const normalizedPath = typeof path === 'string' ? path.split('.') : path;
|
|
40
41
|
return normalizedPath.filter(el => el !== '[default]').join('.');
|
|
41
42
|
};
|
|
43
|
+
|
|
42
44
|
/**
|
|
43
45
|
* Transforms a style dictionary token path to a fully qualified token id
|
|
44
46
|
* These Ids are intended to be used internal to this package by style-dictionary
|
|
@@ -49,5 +51,4 @@ export const getTokenId = path => {
|
|
|
49
51
|
* // Returns color.background.bold.[default]
|
|
50
52
|
* getFullyQualifiedTokenId(['color', 'background', 'bold', '[default]'])
|
|
51
53
|
*/
|
|
52
|
-
|
|
53
54
|
export const getFullyQualifiedTokenId = path => path.join('.');
|