@atlaskit/tokens 1.2.4 → 1.2.6
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 +12 -0
- package/dist/cjs/entry-points/token-order.js +12 -0
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/cjs/utils/color-detection.js +11 -84
- package/dist/cjs/utils/token-order.js +46 -0
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/entry-points/token-order.js +1 -0
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/es2019/utils/color-detection.js +0 -71
- package/dist/es2019/utils/token-order.js +39 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/entry-points/token-order.js +1 -0
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/esm/utils/color-detection.js +9 -78
- package/dist/esm/utils/token-order.js +39 -0
- package/dist/esm/version.json +1 -1
- package/dist/types/entry-points/token-order.d.ts +1 -0
- package/dist/types/index.d.ts +2 -0
- package/dist/types/utils/color-detection.d.ts +0 -25
- package/dist/types/utils/token-order.d.ts +7 -0
- package/package.json +6 -5
- package/report.api.md +860 -0
- package/tmp/api-report-tmp.d.ts +196 -0
- package/token-order/package.json +17 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @atlaskit/tokens
|
|
2
2
|
|
|
3
|
+
## 1.2.6
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`cfe48bb7ece`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cfe48bb7ece) - Internal change only. Replace usages of Inline/Stack with stable version from `@atlaskit/primitives`.
|
|
8
|
+
|
|
9
|
+
## 1.2.5
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`d1adc718599`](https://bitbucket.org/atlassian/atlassian-frontend/commits/d1adc718599) - Added token-order entry-point, exported ActiveTokens type.
|
|
14
|
+
|
|
3
15
|
## 1.2.4
|
|
4
16
|
|
|
5
17
|
### Patch Changes
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
Object.defineProperty(exports, "tokenOrder", {
|
|
7
|
+
enumerable: true,
|
|
8
|
+
get: function get() {
|
|
9
|
+
return _tokenOrder.tokenOrder;
|
|
10
|
+
}
|
|
11
|
+
});
|
|
12
|
+
var _tokenOrder = require("../utils/token-order");
|
|
@@ -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.2.
|
|
11
|
+
var version = "1.2.6";
|
|
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.2.
|
|
12
|
+
var version = "1.2.6";
|
|
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.
|
|
@@ -3,8 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.hexToRGBAValues = exports.
|
|
7
|
-
var _index = require("../index");
|
|
6
|
+
exports.hexToRGBAValues = exports.getBoxShadow = void 0;
|
|
8
7
|
var hexToRGBAValues = function hexToRGBAValues(hex) {
|
|
9
8
|
var hexColor = hex.replace('#', '');
|
|
10
9
|
return {
|
|
@@ -14,95 +13,23 @@ var hexToRGBAValues = function hexToRGBAValues(hex) {
|
|
|
14
13
|
a: parseFloat((parseInt(hexColor.slice(6, 8), 16) / 255).toFixed(2))
|
|
15
14
|
};
|
|
16
15
|
};
|
|
17
|
-
exports.hexToRGBAValues = hexToRGBAValues;
|
|
18
|
-
var hexToRGBA = function hexToRGBA(hex) {
|
|
19
|
-
var _hexToRGBAValues = hexToRGBAValues(hex),
|
|
20
|
-
r = _hexToRGBAValues.r,
|
|
21
|
-
g = _hexToRGBAValues.g,
|
|
22
|
-
b = _hexToRGBAValues.b,
|
|
23
|
-
a = _hexToRGBAValues.a;
|
|
24
|
-
return "rgb".concat(a ? 'a' : '', "(").concat(r, ",").concat(g, ",").concat(b).concat(a ? ",".concat(a) : '', ")");
|
|
25
|
-
};
|
|
26
|
-
exports.hexToRGBA = hexToRGBA;
|
|
27
|
-
var getLuminance = function getLuminance(_ref) {
|
|
28
|
-
var r = _ref.r,
|
|
29
|
-
g = _ref.g,
|
|
30
|
-
b = _ref.b;
|
|
31
|
-
return (r * 299 + g * 587 + b * 114) / 1000;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
/**
|
|
35
|
-
* Returns an accessible hard-coded text color based on the color contrast with
|
|
36
|
-
* the background.
|
|
37
|
-
*
|
|
38
|
-
* @param hex - The Hex color code of the background
|
|
39
|
-
* @param [opts.hardcodedSurface] - If set, a design token will be returned instead
|
|
40
|
-
* of a hard-coded color. This is to support more transparent backgrounds
|
|
41
|
-
* to allow the text to invert colors depending on the current theme's surface color.
|
|
42
|
-
*/
|
|
43
|
-
exports.getLuminance = getLuminance;
|
|
44
|
-
var getTextColorForBackground = function getTextColorForBackground(hex, opts) {
|
|
45
|
-
var _hexToRGBAValues2 = hexToRGBAValues(hex),
|
|
46
|
-
r = _hexToRGBAValues2.r,
|
|
47
|
-
g = _hexToRGBAValues2.g,
|
|
48
|
-
b = _hexToRGBAValues2.b,
|
|
49
|
-
a = _hexToRGBAValues2.a;
|
|
50
|
-
var lum = getLuminance({
|
|
51
|
-
r: r,
|
|
52
|
-
g: g,
|
|
53
|
-
b: b
|
|
54
|
-
});
|
|
55
|
-
var alphaLimit = 0.42;
|
|
56
|
-
var alphaConditionsPerSurface = {
|
|
57
|
-
light: a < alphaLimit,
|
|
58
|
-
dark: a > alphaLimit
|
|
59
|
-
};
|
|
60
|
-
var alphaLimitExceeded = (opts === null || opts === void 0 ? void 0 : opts.hardcodedSurface) && alphaConditionsPerSurface[opts.hardcodedSurface];
|
|
61
|
-
if (!(opts !== null && opts !== void 0 && opts.hardcodedSurface) && a < alphaLimit) {
|
|
62
|
-
// This color is transparent, so the text will mainly cast onto the surface behind.
|
|
63
|
-
// Needs to use tokens otherwise Dark mode would cause black text on black surface
|
|
64
|
-
return (0, _index.token)('color.text', 'black');
|
|
65
|
-
}
|
|
66
|
-
return lum > 150 && !a || a && alphaLimitExceeded ? 'black' : 'white';
|
|
67
|
-
};
|
|
68
|
-
|
|
69
|
-
/**
|
|
70
|
-
* Returns a border if determined to be required based on the color contrast with
|
|
71
|
-
* the background.
|
|
72
|
-
*
|
|
73
|
-
* @param hex - The Hex color code of the background
|
|
74
|
-
*/
|
|
75
|
-
exports.getTextColorForBackground = getTextColorForBackground;
|
|
76
|
-
var getBorderForBackground = function getBorderForBackground(hex) {
|
|
77
|
-
var _hexToRGBAValues3 = hexToRGBAValues(hex),
|
|
78
|
-
r = _hexToRGBAValues3.r,
|
|
79
|
-
g = _hexToRGBAValues3.g,
|
|
80
|
-
b = _hexToRGBAValues3.b,
|
|
81
|
-
a = _hexToRGBAValues3.a;
|
|
82
|
-
var lum = getLuminance({
|
|
83
|
-
r: r,
|
|
84
|
-
g: g,
|
|
85
|
-
b: b
|
|
86
|
-
});
|
|
87
|
-
return lum > 240 || a < 0.2 ? "1px solid ".concat((0, _index.token)('color.border', '#091E4224')) : undefined;
|
|
88
|
-
};
|
|
89
16
|
|
|
90
17
|
/**
|
|
91
18
|
* Returns a box shadow formatted for CSS from a ShadowToken raw value.
|
|
92
19
|
*
|
|
93
20
|
* @param rawShadow - ShadowToken raw value
|
|
94
21
|
*/
|
|
95
|
-
exports.
|
|
22
|
+
exports.hexToRGBAValues = hexToRGBAValues;
|
|
96
23
|
var getBoxShadow = function getBoxShadow(rawShadow) {
|
|
97
|
-
return rawShadow.map(function (
|
|
98
|
-
var radius =
|
|
99
|
-
offset =
|
|
100
|
-
color =
|
|
101
|
-
opacity =
|
|
102
|
-
var
|
|
103
|
-
r =
|
|
104
|
-
g =
|
|
105
|
-
b =
|
|
24
|
+
return rawShadow.map(function (_ref) {
|
|
25
|
+
var radius = _ref.radius,
|
|
26
|
+
offset = _ref.offset,
|
|
27
|
+
color = _ref.color,
|
|
28
|
+
opacity = _ref.opacity;
|
|
29
|
+
var _hexToRGBAValues = hexToRGBAValues(color),
|
|
30
|
+
r = _hexToRGBAValues.r,
|
|
31
|
+
g = _hexToRGBAValues.g,
|
|
32
|
+
b = _hexToRGBAValues.b;
|
|
106
33
|
return "".concat(offset.x, "px ").concat(offset.y, "px ").concat(radius, "px rgba(").concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(opacity, ")");
|
|
107
34
|
}).join(',');
|
|
108
35
|
};
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.tokenOrder = void 0;
|
|
7
|
+
/**
|
|
8
|
+
* Create specific rules for ordering tokens based on their root path and subpath.
|
|
9
|
+
*/
|
|
10
|
+
var tokenOrder = [{
|
|
11
|
+
path: 'color',
|
|
12
|
+
subpaths: ['text', 'link', 'icon', 'border', 'background', 'blanket', 'interaction', 'skeleton', 'chart',
|
|
13
|
+
// deleted ↓
|
|
14
|
+
'accent', 'iconBorder', 'overlay']
|
|
15
|
+
}, {
|
|
16
|
+
path: 'elevation',
|
|
17
|
+
subpaths: ['surface', 'shadow']
|
|
18
|
+
}, {
|
|
19
|
+
path: 'opacity',
|
|
20
|
+
subpaths: []
|
|
21
|
+
}, {
|
|
22
|
+
path: 'shadow',
|
|
23
|
+
subpaths: ['card', 'overlay']
|
|
24
|
+
},
|
|
25
|
+
// Deleted
|
|
26
|
+
{
|
|
27
|
+
path: 'utility',
|
|
28
|
+
subpaths: []
|
|
29
|
+
}, {
|
|
30
|
+
path: 'shape',
|
|
31
|
+
subpaths: ['radius', 'width']
|
|
32
|
+
}, {
|
|
33
|
+
path: 'space',
|
|
34
|
+
subpaths: []
|
|
35
|
+
}, {
|
|
36
|
+
path: 'font',
|
|
37
|
+
subpaths: ['family', 'size', 'weight', 'lineHeight']
|
|
38
|
+
}, {
|
|
39
|
+
path: 'typography',
|
|
40
|
+
subpaths: []
|
|
41
|
+
}, {
|
|
42
|
+
path: 'value',
|
|
43
|
+
// Legacy palette
|
|
44
|
+
subpaths: []
|
|
45
|
+
}];
|
|
46
|
+
exports.tokenOrder = tokenOrder;
|
package/dist/cjs/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { tokenOrder } from '../utils/token-order';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import warnOnce from '@atlaskit/ds-lib/warn-once';
|
|
2
2
|
import tokens from './artifacts/token-names';
|
|
3
3
|
const name = "@atlaskit/tokens";
|
|
4
|
-
const version = "1.2.
|
|
4
|
+
const version = "1.2.6";
|
|
5
5
|
/**
|
|
6
6
|
* Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
|
|
7
7
|
* resulting CSS Custom Property.
|
package/dist/es2019/get-token.js
CHANGED
|
@@ -2,7 +2,7 @@ import warnOnce from '@atlaskit/ds-lib/warn-once';
|
|
|
2
2
|
import tokens from './artifacts/token-names';
|
|
3
3
|
import { TOKEN_NOT_FOUND_CSS_VAR } from './constants';
|
|
4
4
|
const name = "@atlaskit/tokens";
|
|
5
|
-
const version = "1.2.
|
|
5
|
+
const version = "1.2.6";
|
|
6
6
|
/**
|
|
7
7
|
* Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
|
|
8
8
|
* This should be used to implement design decisions throughout your application.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { token } from '../index';
|
|
2
1
|
export const hexToRGBAValues = hex => {
|
|
3
2
|
const hexColor = hex.replace('#', '');
|
|
4
3
|
return {
|
|
@@ -8,76 +7,6 @@ export const hexToRGBAValues = hex => {
|
|
|
8
7
|
a: parseFloat((parseInt(hexColor.slice(6, 8), 16) / 255).toFixed(2))
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
|
-
export const hexToRGBA = hex => {
|
|
12
|
-
const {
|
|
13
|
-
r,
|
|
14
|
-
g,
|
|
15
|
-
b,
|
|
16
|
-
a
|
|
17
|
-
} = hexToRGBAValues(hex);
|
|
18
|
-
return `rgb${a ? 'a' : ''}(${r},${g},${b}${a ? `,${a}` : ''})`;
|
|
19
|
-
};
|
|
20
|
-
export const getLuminance = ({
|
|
21
|
-
r,
|
|
22
|
-
g,
|
|
23
|
-
b
|
|
24
|
-
}) => (r * 299 + g * 587 + b * 114) / 1000;
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns an accessible hard-coded text color based on the color contrast with
|
|
28
|
-
* the background.
|
|
29
|
-
*
|
|
30
|
-
* @param hex - The Hex color code of the background
|
|
31
|
-
* @param [opts.hardcodedSurface] - If set, a design token will be returned instead
|
|
32
|
-
* of a hard-coded color. This is to support more transparent backgrounds
|
|
33
|
-
* to allow the text to invert colors depending on the current theme's surface color.
|
|
34
|
-
*/
|
|
35
|
-
export const getTextColorForBackground = (hex, opts) => {
|
|
36
|
-
const {
|
|
37
|
-
r,
|
|
38
|
-
g,
|
|
39
|
-
b,
|
|
40
|
-
a
|
|
41
|
-
} = hexToRGBAValues(hex);
|
|
42
|
-
const lum = getLuminance({
|
|
43
|
-
r,
|
|
44
|
-
g,
|
|
45
|
-
b
|
|
46
|
-
});
|
|
47
|
-
const alphaLimit = 0.42;
|
|
48
|
-
const alphaConditionsPerSurface = {
|
|
49
|
-
light: a < alphaLimit,
|
|
50
|
-
dark: a > alphaLimit
|
|
51
|
-
};
|
|
52
|
-
const alphaLimitExceeded = (opts === null || opts === void 0 ? void 0 : opts.hardcodedSurface) && alphaConditionsPerSurface[opts.hardcodedSurface];
|
|
53
|
-
if (!(opts !== null && opts !== void 0 && opts.hardcodedSurface) && a < alphaLimit) {
|
|
54
|
-
// This color is transparent, so the text will mainly cast onto the surface behind.
|
|
55
|
-
// Needs to use tokens otherwise Dark mode would cause black text on black surface
|
|
56
|
-
return token('color.text', 'black');
|
|
57
|
-
}
|
|
58
|
-
return lum > 150 && !a || a && alphaLimitExceeded ? 'black' : 'white';
|
|
59
|
-
};
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Returns a border if determined to be required based on the color contrast with
|
|
63
|
-
* the background.
|
|
64
|
-
*
|
|
65
|
-
* @param hex - The Hex color code of the background
|
|
66
|
-
*/
|
|
67
|
-
export const getBorderForBackground = hex => {
|
|
68
|
-
const {
|
|
69
|
-
r,
|
|
70
|
-
g,
|
|
71
|
-
b,
|
|
72
|
-
a
|
|
73
|
-
} = hexToRGBAValues(hex);
|
|
74
|
-
const lum = getLuminance({
|
|
75
|
-
r,
|
|
76
|
-
g,
|
|
77
|
-
b
|
|
78
|
-
});
|
|
79
|
-
return lum > 240 || a < 0.2 ? `1px solid ${token('color.border', '#091E4224')}` : undefined;
|
|
80
|
-
};
|
|
81
10
|
|
|
82
11
|
/**
|
|
83
12
|
* Returns a box shadow formatted for CSS from a ShadowToken raw value.
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create specific rules for ordering tokens based on their root path and subpath.
|
|
3
|
+
*/
|
|
4
|
+
export const tokenOrder = [{
|
|
5
|
+
path: 'color',
|
|
6
|
+
subpaths: ['text', 'link', 'icon', 'border', 'background', 'blanket', 'interaction', 'skeleton', 'chart',
|
|
7
|
+
// deleted ↓
|
|
8
|
+
'accent', 'iconBorder', 'overlay']
|
|
9
|
+
}, {
|
|
10
|
+
path: 'elevation',
|
|
11
|
+
subpaths: ['surface', 'shadow']
|
|
12
|
+
}, {
|
|
13
|
+
path: 'opacity',
|
|
14
|
+
subpaths: []
|
|
15
|
+
}, {
|
|
16
|
+
path: 'shadow',
|
|
17
|
+
subpaths: ['card', 'overlay']
|
|
18
|
+
},
|
|
19
|
+
// Deleted
|
|
20
|
+
{
|
|
21
|
+
path: 'utility',
|
|
22
|
+
subpaths: []
|
|
23
|
+
}, {
|
|
24
|
+
path: 'shape',
|
|
25
|
+
subpaths: ['radius', 'width']
|
|
26
|
+
}, {
|
|
27
|
+
path: 'space',
|
|
28
|
+
subpaths: []
|
|
29
|
+
}, {
|
|
30
|
+
path: 'font',
|
|
31
|
+
subpaths: ['family', 'size', 'weight', 'lineHeight']
|
|
32
|
+
}, {
|
|
33
|
+
path: 'typography',
|
|
34
|
+
subpaths: []
|
|
35
|
+
}, {
|
|
36
|
+
path: 'value',
|
|
37
|
+
// Legacy palette
|
|
38
|
+
subpaths: []
|
|
39
|
+
}];
|
package/dist/es2019/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { tokenOrder } from '../utils/token-order';
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import warnOnce from '@atlaskit/ds-lib/warn-once';
|
|
2
2
|
import tokens from './artifacts/token-names';
|
|
3
3
|
var name = "@atlaskit/tokens";
|
|
4
|
-
var version = "1.2.
|
|
4
|
+
var version = "1.2.6";
|
|
5
5
|
/**
|
|
6
6
|
* Takes a dot-separated token name and and an optional fallback, and returns the current computed CSS value for the
|
|
7
7
|
* resulting CSS Custom Property.
|
package/dist/esm/get-token.js
CHANGED
|
@@ -2,7 +2,7 @@ import warnOnce from '@atlaskit/ds-lib/warn-once';
|
|
|
2
2
|
import tokens from './artifacts/token-names';
|
|
3
3
|
import { TOKEN_NOT_FOUND_CSS_VAR } from './constants';
|
|
4
4
|
var name = "@atlaskit/tokens";
|
|
5
|
-
var version = "1.2.
|
|
5
|
+
var version = "1.2.6";
|
|
6
6
|
/**
|
|
7
7
|
* Takes a dot-separated token name and an optional fallback, and returns the CSS custom property for the corresponding token.
|
|
8
8
|
* This should be used to implement design decisions throughout your application.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { token } from '../index';
|
|
2
1
|
export var hexToRGBAValues = function hexToRGBAValues(hex) {
|
|
3
2
|
var hexColor = hex.replace('#', '');
|
|
4
3
|
return {
|
|
@@ -8,74 +7,6 @@ export var hexToRGBAValues = function hexToRGBAValues(hex) {
|
|
|
8
7
|
a: parseFloat((parseInt(hexColor.slice(6, 8), 16) / 255).toFixed(2))
|
|
9
8
|
};
|
|
10
9
|
};
|
|
11
|
-
export var hexToRGBA = function hexToRGBA(hex) {
|
|
12
|
-
var _hexToRGBAValues = hexToRGBAValues(hex),
|
|
13
|
-
r = _hexToRGBAValues.r,
|
|
14
|
-
g = _hexToRGBAValues.g,
|
|
15
|
-
b = _hexToRGBAValues.b,
|
|
16
|
-
a = _hexToRGBAValues.a;
|
|
17
|
-
return "rgb".concat(a ? 'a' : '', "(").concat(r, ",").concat(g, ",").concat(b).concat(a ? ",".concat(a) : '', ")");
|
|
18
|
-
};
|
|
19
|
-
export var getLuminance = function getLuminance(_ref) {
|
|
20
|
-
var r = _ref.r,
|
|
21
|
-
g = _ref.g,
|
|
22
|
-
b = _ref.b;
|
|
23
|
-
return (r * 299 + g * 587 + b * 114) / 1000;
|
|
24
|
-
};
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* Returns an accessible hard-coded text color based on the color contrast with
|
|
28
|
-
* the background.
|
|
29
|
-
*
|
|
30
|
-
* @param hex - The Hex color code of the background
|
|
31
|
-
* @param [opts.hardcodedSurface] - If set, a design token will be returned instead
|
|
32
|
-
* of a hard-coded color. This is to support more transparent backgrounds
|
|
33
|
-
* to allow the text to invert colors depending on the current theme's surface color.
|
|
34
|
-
*/
|
|
35
|
-
export var getTextColorForBackground = function getTextColorForBackground(hex, opts) {
|
|
36
|
-
var _hexToRGBAValues2 = hexToRGBAValues(hex),
|
|
37
|
-
r = _hexToRGBAValues2.r,
|
|
38
|
-
g = _hexToRGBAValues2.g,
|
|
39
|
-
b = _hexToRGBAValues2.b,
|
|
40
|
-
a = _hexToRGBAValues2.a;
|
|
41
|
-
var lum = getLuminance({
|
|
42
|
-
r: r,
|
|
43
|
-
g: g,
|
|
44
|
-
b: b
|
|
45
|
-
});
|
|
46
|
-
var alphaLimit = 0.42;
|
|
47
|
-
var alphaConditionsPerSurface = {
|
|
48
|
-
light: a < alphaLimit,
|
|
49
|
-
dark: a > alphaLimit
|
|
50
|
-
};
|
|
51
|
-
var alphaLimitExceeded = (opts === null || opts === void 0 ? void 0 : opts.hardcodedSurface) && alphaConditionsPerSurface[opts.hardcodedSurface];
|
|
52
|
-
if (!(opts !== null && opts !== void 0 && opts.hardcodedSurface) && a < alphaLimit) {
|
|
53
|
-
// This color is transparent, so the text will mainly cast onto the surface behind.
|
|
54
|
-
// Needs to use tokens otherwise Dark mode would cause black text on black surface
|
|
55
|
-
return token('color.text', 'black');
|
|
56
|
-
}
|
|
57
|
-
return lum > 150 && !a || a && alphaLimitExceeded ? 'black' : 'white';
|
|
58
|
-
};
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Returns a border if determined to be required based on the color contrast with
|
|
62
|
-
* the background.
|
|
63
|
-
*
|
|
64
|
-
* @param hex - The Hex color code of the background
|
|
65
|
-
*/
|
|
66
|
-
export var getBorderForBackground = function getBorderForBackground(hex) {
|
|
67
|
-
var _hexToRGBAValues3 = hexToRGBAValues(hex),
|
|
68
|
-
r = _hexToRGBAValues3.r,
|
|
69
|
-
g = _hexToRGBAValues3.g,
|
|
70
|
-
b = _hexToRGBAValues3.b,
|
|
71
|
-
a = _hexToRGBAValues3.a;
|
|
72
|
-
var lum = getLuminance({
|
|
73
|
-
r: r,
|
|
74
|
-
g: g,
|
|
75
|
-
b: b
|
|
76
|
-
});
|
|
77
|
-
return lum > 240 || a < 0.2 ? "1px solid ".concat(token('color.border', '#091E4224')) : undefined;
|
|
78
|
-
};
|
|
79
10
|
|
|
80
11
|
/**
|
|
81
12
|
* Returns a box shadow formatted for CSS from a ShadowToken raw value.
|
|
@@ -83,15 +14,15 @@ export var getBorderForBackground = function getBorderForBackground(hex) {
|
|
|
83
14
|
* @param rawShadow - ShadowToken raw value
|
|
84
15
|
*/
|
|
85
16
|
export var getBoxShadow = function getBoxShadow(rawShadow) {
|
|
86
|
-
return rawShadow.map(function (
|
|
87
|
-
var radius =
|
|
88
|
-
offset =
|
|
89
|
-
color =
|
|
90
|
-
opacity =
|
|
91
|
-
var
|
|
92
|
-
r =
|
|
93
|
-
g =
|
|
94
|
-
b =
|
|
17
|
+
return rawShadow.map(function (_ref) {
|
|
18
|
+
var radius = _ref.radius,
|
|
19
|
+
offset = _ref.offset,
|
|
20
|
+
color = _ref.color,
|
|
21
|
+
opacity = _ref.opacity;
|
|
22
|
+
var _hexToRGBAValues = hexToRGBAValues(color),
|
|
23
|
+
r = _hexToRGBAValues.r,
|
|
24
|
+
g = _hexToRGBAValues.g,
|
|
25
|
+
b = _hexToRGBAValues.b;
|
|
95
26
|
return "".concat(offset.x, "px ").concat(offset.y, "px ").concat(radius, "px rgba(").concat(r, ", ").concat(g, ", ").concat(b, ", ").concat(opacity, ")");
|
|
96
27
|
}).join(',');
|
|
97
28
|
};
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Create specific rules for ordering tokens based on their root path and subpath.
|
|
3
|
+
*/
|
|
4
|
+
export var tokenOrder = [{
|
|
5
|
+
path: 'color',
|
|
6
|
+
subpaths: ['text', 'link', 'icon', 'border', 'background', 'blanket', 'interaction', 'skeleton', 'chart',
|
|
7
|
+
// deleted ↓
|
|
8
|
+
'accent', 'iconBorder', 'overlay']
|
|
9
|
+
}, {
|
|
10
|
+
path: 'elevation',
|
|
11
|
+
subpaths: ['surface', 'shadow']
|
|
12
|
+
}, {
|
|
13
|
+
path: 'opacity',
|
|
14
|
+
subpaths: []
|
|
15
|
+
}, {
|
|
16
|
+
path: 'shadow',
|
|
17
|
+
subpaths: ['card', 'overlay']
|
|
18
|
+
},
|
|
19
|
+
// Deleted
|
|
20
|
+
{
|
|
21
|
+
path: 'utility',
|
|
22
|
+
subpaths: []
|
|
23
|
+
}, {
|
|
24
|
+
path: 'shape',
|
|
25
|
+
subpaths: ['radius', 'width']
|
|
26
|
+
}, {
|
|
27
|
+
path: 'space',
|
|
28
|
+
subpaths: []
|
|
29
|
+
}, {
|
|
30
|
+
path: 'font',
|
|
31
|
+
subpaths: ['family', 'size', 'weight', 'lineHeight']
|
|
32
|
+
}, {
|
|
33
|
+
path: 'typography',
|
|
34
|
+
subpaths: []
|
|
35
|
+
}, {
|
|
36
|
+
path: 'value',
|
|
37
|
+
// Legacy palette
|
|
38
|
+
subpaths: []
|
|
39
|
+
}];
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { tokenOrder } from '../utils/token-order';
|
package/dist/types/index.d.ts
CHANGED
|
@@ -3,7 +3,9 @@ export { default as getTokenValue } from './get-token-value';
|
|
|
3
3
|
export { default as setGlobalTheme, getThemeStyles, getThemeHtmlAttrs, getSSRAutoScript, } from './set-global-theme';
|
|
4
4
|
export type { ThemeState } from './set-global-theme';
|
|
5
5
|
export type { CSSToken } from './artifacts/token-names';
|
|
6
|
+
export type { ActiveTokens } from './artifacts/types';
|
|
6
7
|
export type { ThemeColorModes, Themes, ThemeIds } from './theme-config';
|
|
8
|
+
export type { Groups, OpacityToken, PaintToken, RawToken, ShadowToken, SpacingToken, } from './types';
|
|
7
9
|
export { default as themeConfig } from './theme-config';
|
|
8
10
|
export { useThemeObserver } from './use-theme-observer';
|
|
9
11
|
export { ThemeMutationObserver } from './theme-mutation-observer';
|
|
@@ -5,31 +5,6 @@ export declare const hexToRGBAValues: (hex: string) => {
|
|
|
5
5
|
b: number;
|
|
6
6
|
a: number;
|
|
7
7
|
};
|
|
8
|
-
export declare const hexToRGBA: (hex: string) => string;
|
|
9
|
-
export declare const getLuminance: ({ r, g, b, }: {
|
|
10
|
-
r: number;
|
|
11
|
-
b: number;
|
|
12
|
-
g: number;
|
|
13
|
-
}) => number;
|
|
14
|
-
/**
|
|
15
|
-
* Returns an accessible hard-coded text color based on the color contrast with
|
|
16
|
-
* the background.
|
|
17
|
-
*
|
|
18
|
-
* @param hex - The Hex color code of the background
|
|
19
|
-
* @param [opts.hardcodedSurface] - If set, a design token will be returned instead
|
|
20
|
-
* of a hard-coded color. This is to support more transparent backgrounds
|
|
21
|
-
* to allow the text to invert colors depending on the current theme's surface color.
|
|
22
|
-
*/
|
|
23
|
-
export declare const getTextColorForBackground: (hex: string, opts?: {
|
|
24
|
-
hardcodedSurface?: "light" | "dark" | undefined;
|
|
25
|
-
} | undefined) => string;
|
|
26
|
-
/**
|
|
27
|
-
* Returns a border if determined to be required based on the color contrast with
|
|
28
|
-
* the background.
|
|
29
|
-
*
|
|
30
|
-
* @param hex - The Hex color code of the background
|
|
31
|
-
*/
|
|
32
|
-
export declare const getBorderForBackground: (hex: string) => string | undefined;
|
|
33
8
|
/**
|
|
34
9
|
* Returns a box shadow formatted for CSS from a ShadowToken raw value.
|
|
35
10
|
*
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/tokens",
|
|
3
|
-
"version": "1.2.
|
|
3
|
+
"version": "1.2.6",
|
|
4
4
|
"author": "Atlassian Pty Ltd",
|
|
5
5
|
"description": "Design tokens are the single source of truth to name and store design decisions.",
|
|
6
6
|
"license": "Apache-2.0",
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"./tokens-raw": "./src/entry-points/tokens-raw.tsx",
|
|
40
40
|
"./token-ids": "./src/entry-points/token-ids.tsx",
|
|
41
41
|
"./token-names": "./src/entry-points/token-names.tsx",
|
|
42
|
+
"./token-order": "./src/entry-points/token-order.tsx",
|
|
42
43
|
"./rename-mapping": "./src/entry-points/rename-mapping.tsx",
|
|
43
44
|
"./babel-plugin": "./src/entry-points/babel-plugin.tsx"
|
|
44
45
|
},
|
|
@@ -60,13 +61,13 @@
|
|
|
60
61
|
"devDependencies": {
|
|
61
62
|
"@af/accessibility-testing": "*",
|
|
62
63
|
"@af/codegen": "*",
|
|
63
|
-
"@atlaskit/avatar": "^21.
|
|
64
|
+
"@atlaskit/avatar": "^21.2.0",
|
|
64
65
|
"@atlaskit/badge": "^15.0.11",
|
|
65
66
|
"@atlaskit/button": "^16.5.0",
|
|
66
67
|
"@atlaskit/checkbox": "^12.4.0",
|
|
67
|
-
"@atlaskit/code": "^14.
|
|
68
|
+
"@atlaskit/code": "^14.5.0",
|
|
68
69
|
"@atlaskit/docs": "^9.0.10",
|
|
69
|
-
"@atlaskit/dropdown-menu": "^11.
|
|
70
|
+
"@atlaskit/dropdown-menu": "^11.7.0",
|
|
70
71
|
"@atlaskit/ds-explorations": "^2.0.0",
|
|
71
72
|
"@atlaskit/dynamic-table": "^14.8.0",
|
|
72
73
|
"@atlaskit/empty-state": "^7.4.0",
|
|
@@ -83,7 +84,7 @@
|
|
|
83
84
|
"@atlaskit/textfield": "^5.3.0",
|
|
84
85
|
"@atlaskit/theme": "^12.2.0",
|
|
85
86
|
"@atlaskit/toggle": "^12.5.0",
|
|
86
|
-
"@atlaskit/tooltip": "^17.
|
|
87
|
+
"@atlaskit/tooltip": "^17.7.0",
|
|
87
88
|
"@atlassian/atlassian-frontend-prettier-config-1.0.1": "npm:@atlassian/atlassian-frontend-prettier-config@1.0.1",
|
|
88
89
|
"@babel/core": "^7.12.3",
|
|
89
90
|
"@emotion/core": "^10.0.9",
|