@atlaskit/codemod-cli 0.8.3 → 0.8.4
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 +8 -0
- package/README.md +12 -2
- package/dist/cjs/main.js +3 -3
- package/dist/cjs/presets/index.js +4 -2
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +181 -0
- package/dist/cjs/presets/theme-to-design-tokens/types.js +5 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +104 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +19 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/color-difference.js +174 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/color-palette-tokens-map.js +129 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/color-to-token.js +88 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +59 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +348 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +81 -0
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +8 -0
- package/dist/cjs/types.js +4 -2
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/presets/index.js +2 -1
- package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +137 -0
- package/dist/es2019/presets/theme-to-design-tokens/types.js +1 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +70 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast.js +10 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/color-difference.js +150 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/color-palette-tokens-map.js +122 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/color-to-token.js +75 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +35 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +336 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/legacy-colors.js +72 -0
- package/dist/es2019/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
- package/dist/es2019/version.json +1 -1
- package/dist/esm/main.js +3 -3
- package/dist/esm/presets/index.js +3 -2
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +165 -0
- package/dist/esm/presets/theme-to-design-tokens/types.js +1 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +88 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/ast.js +10 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/color-difference.js +160 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/color-palette-tokens-map.js +122 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/color-to-token.js +78 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/color.js +39 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +340 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/legacy-colors.js +72 -0
- package/dist/esm/presets/theme-to-design-tokens/utils/named-colors.js +1 -0
- package/dist/esm/types.js +3 -2
- package/dist/esm/version.json +1 -1
- package/dist/types/presets/index.d.ts +1 -0
- package/dist/types/presets/theme-to-design-tokens/theme-to-design-tokens.d.ts +2 -0
- package/dist/types/presets/theme-to-design-tokens/types.d.ts +2 -0
- package/dist/types/presets/theme-to-design-tokens/utils/ast-meta.d.ts +4 -0
- package/dist/types/presets/theme-to-design-tokens/utils/ast.d.ts +3 -0
- package/dist/types/presets/theme-to-design-tokens/utils/color-difference.d.ts +66 -0
- package/dist/types/presets/theme-to-design-tokens/utils/color-palette-tokens-map.d.ts +21 -0
- package/dist/types/presets/theme-to-design-tokens/utils/color-to-token.d.ts +12 -0
- package/dist/types/presets/theme-to-design-tokens/utils/color.d.ts +4 -0
- package/dist/types/presets/theme-to-design-tokens/utils/fuzzy-search.d.ts +5 -0
- package/dist/types/presets/theme-to-design-tokens/utils/legacy-colors.d.ts +3 -0
- package/dist/types/presets/theme-to-design-tokens/utils/named-colors.d.ts +1 -0
- package/package.json +3 -1
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
import _toConsumableArray from "@babel/runtime/helpers/toConsumableArray";
|
|
2
|
+
import designTokens from '@atlaskit/tokens/token-names';
|
|
3
|
+
var tokens = Object.keys(designTokens);
|
|
4
|
+
export var getUniqueWordsFromTokens = tokens.reduce(function (accum, val) {
|
|
5
|
+
return [].concat(_toConsumableArray(accum), _toConsumableArray(val.split('.')));
|
|
6
|
+
}, []).reduce(function (accum, val) {
|
|
7
|
+
return [].concat(_toConsumableArray(accum), _toConsumableArray(val.split(/(?=[A-Z])/g).map(function (e) {
|
|
8
|
+
return e.toLowerCase();
|
|
9
|
+
})));
|
|
10
|
+
}, []).reduce(function (accum, val) {
|
|
11
|
+
if (!accum.includes(val)) {
|
|
12
|
+
accum.push(val);
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
return accum;
|
|
16
|
+
}, []);
|
|
17
|
+
export function getMetaFromAncestors(j, path) {
|
|
18
|
+
var meta = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : [];
|
|
19
|
+
var parent = path.parentPath;
|
|
20
|
+
var grandParent = parent && parent.parentPath;
|
|
21
|
+
|
|
22
|
+
if (parent && parent.value.type === 'ObjectProperty') {
|
|
23
|
+
var value = '';
|
|
24
|
+
|
|
25
|
+
if (parent.value.key.type === 'Literal' || parent.value.key.type === 'StringLiteral' || parent.value.key.type === 'NumericLiteral') {
|
|
26
|
+
value = parent.value.key.value.toString();
|
|
27
|
+
} else {
|
|
28
|
+
value = parent.value.key.name;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
meta.push(value);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
35
|
+
var expressionIndex = grandParent.value.expressions.findIndex(function (exp) {
|
|
36
|
+
return exp.name === path.value.name;
|
|
37
|
+
});
|
|
38
|
+
var quasi = grandParent.value.quasis[expressionIndex];
|
|
39
|
+
var propertyName = (quasi.value.cooked || quasi.value.raw || '').replace(/\n/g, '').split(/;|{|}/).filter(function (el) {
|
|
40
|
+
return !el.match(/\.|\@|\(|\)/);
|
|
41
|
+
}).pop().replace(/:/g, '').trim();
|
|
42
|
+
grandParent.value.quasis.slice(0, expressionIndex + 1).map(function (q) {
|
|
43
|
+
return q.value.cooked;
|
|
44
|
+
}) // We reverse so the most nested one is first which we're more likely than not interested in
|
|
45
|
+
.reverse().forEach(function (str) {
|
|
46
|
+
var result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
47
|
+
|
|
48
|
+
if (result) {
|
|
49
|
+
meta.push(result[0]);
|
|
50
|
+
}
|
|
51
|
+
});
|
|
52
|
+
meta.push(propertyName);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (parent && parent.value.type === 'JSXAttribute') {
|
|
56
|
+
if (!['css', 'styles', 'style'].includes(parent.value.name.name)) {
|
|
57
|
+
meta.push(parent.value.name.name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
62
|
+
meta.push(parent.value.id.name);
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
if (parent) {
|
|
66
|
+
return getMetaFromAncestors(j, parent, meta);
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
return meta;
|
|
70
|
+
}
|
|
71
|
+
export function cleanMeta(meta) {
|
|
72
|
+
return meta.reduce(function (accum, val) {
|
|
73
|
+
return [].concat(_toConsumableArray(accum), _toConsumableArray(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
74
|
+
return e.toLowerCase();
|
|
75
|
+
}) : []));
|
|
76
|
+
}, []).reduce(function (accum, val) {
|
|
77
|
+
accum.push(val.replace(/:/g, '').replace(/,/g, '').replace('grey', 'neutral').replace('texts', 'text').replace('error', 'danger').replace('invalid', 'danger').replace('removed', 'danger').replace('removal', 'danger').replace('remove', 'danger').replace('valid', 'success').replace('successful', 'success').replace('risk', 'warning').replace('primary', 'bold').replace('info', 'bold').replace('secondary', 'subtle').replace('hyperlink', 'link').replace('focused', 'focus').replace('active', 'pressed').replace('hovered', 'hover').replace('background-color', 'background').replace('color', 'text').replace('stroke', 'border').replace('border-left', 'border').replace('border-right', 'border').replace('box-shadow', 'shadow'));
|
|
78
|
+
return accum;
|
|
79
|
+
}, []).filter(function (val) {
|
|
80
|
+
return getUniqueWordsFromTokens.includes(val);
|
|
81
|
+
}).reduce(function (accum, val) {
|
|
82
|
+
if (!accum.includes(val)) {
|
|
83
|
+
accum.push(val);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
return accum;
|
|
87
|
+
}, []);
|
|
88
|
+
}
|
|
@@ -0,0 +1,160 @@
|
|
|
1
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
2
|
+
|
|
3
|
+
/* eslint-disable @atlassian/tangerine/import/entry-points */
|
|
4
|
+
import { convert } from 'chromatism'; // Design token values are not currently exposed from @atlaskit/tokens
|
|
5
|
+
// In a follow up ticket we will expose them again via another entrypoint.
|
|
6
|
+
|
|
7
|
+
import defaultTokenValues from '@atlaskit/tokens/token-names';
|
|
8
|
+
export var legacyColorPalette = {
|
|
9
|
+
R50: '#FFEBE6',
|
|
10
|
+
R75: '#FFBDAD',
|
|
11
|
+
R100: '#FF8F73',
|
|
12
|
+
R200: '#FF7452',
|
|
13
|
+
R300: '#FF5630',
|
|
14
|
+
R400: '#DE350B',
|
|
15
|
+
R500: '#BF2600',
|
|
16
|
+
Y50: '#FFFAE6',
|
|
17
|
+
Y75: '#FFF0B3',
|
|
18
|
+
Y100: '#FFE380',
|
|
19
|
+
Y200: '#FFC400',
|
|
20
|
+
Y300: '#FFAB00',
|
|
21
|
+
Y400: '#FF991F',
|
|
22
|
+
Y500: '#FF8B00',
|
|
23
|
+
G50: '#E3FCEF',
|
|
24
|
+
G75: '#ABF5D1',
|
|
25
|
+
G100: '#79F2C0',
|
|
26
|
+
G200: '#57D9A3',
|
|
27
|
+
G300: '#36B37E',
|
|
28
|
+
G400: '#00875A',
|
|
29
|
+
G500: '#006644',
|
|
30
|
+
B50: '#DEEBFF',
|
|
31
|
+
B75: '#B3D4FF',
|
|
32
|
+
B100: '#4C9AFF',
|
|
33
|
+
B200: '#2684FF',
|
|
34
|
+
B300: '#0065FF',
|
|
35
|
+
B400: '#0052CC',
|
|
36
|
+
B500: '#0747A6',
|
|
37
|
+
P50: '#EAE6FF',
|
|
38
|
+
P75: '#C0B6F2',
|
|
39
|
+
P100: '#998DD9',
|
|
40
|
+
P200: '#8777D9',
|
|
41
|
+
P300: '#6554C0',
|
|
42
|
+
P400: '#5243AA',
|
|
43
|
+
P500: '#403294',
|
|
44
|
+
T50: '#E6FCFF',
|
|
45
|
+
T75: '#B3F5FF',
|
|
46
|
+
T100: '#79E2F2',
|
|
47
|
+
T200: '#00C7E6',
|
|
48
|
+
T300: '#00B8D9',
|
|
49
|
+
T400: '#00A3BF',
|
|
50
|
+
T500: '#008DA6',
|
|
51
|
+
N0: '#FFFFFF',
|
|
52
|
+
N10: '#FAFBFC',
|
|
53
|
+
N20: '#F4F5F7',
|
|
54
|
+
N30: '#EBECF0',
|
|
55
|
+
N40: '#DFE1E6',
|
|
56
|
+
N50: '#C1C7D0',
|
|
57
|
+
N60: '#B3BAC5',
|
|
58
|
+
N70: '#A5ADBA',
|
|
59
|
+
N80: '#97A0AF',
|
|
60
|
+
N90: '#8993A4',
|
|
61
|
+
N100: '#7A869A',
|
|
62
|
+
N200: '#6B778C',
|
|
63
|
+
N300: '#5E6C84',
|
|
64
|
+
N400: '#505F79',
|
|
65
|
+
N500: '#42526E',
|
|
66
|
+
N600: '#344563',
|
|
67
|
+
N700: '#253858',
|
|
68
|
+
N800: '#172B4D',
|
|
69
|
+
N900: '#091E42'
|
|
70
|
+
};
|
|
71
|
+
export function findClosetMatchingToken(paletteName) {
|
|
72
|
+
var paletteColor = legacyColorPalette[paletteName];
|
|
73
|
+
|
|
74
|
+
if (!paletteColor) {
|
|
75
|
+
return undefined;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
var tokens = Object.entries(defaultTokenValues).map(function (_ref) {
|
|
79
|
+
var _ref2 = _slicedToArray(_ref, 2),
|
|
80
|
+
key = _ref2[0],
|
|
81
|
+
value = _ref2[1];
|
|
82
|
+
|
|
83
|
+
try {
|
|
84
|
+
var _diff = deltaE(paletteColor, value);
|
|
85
|
+
|
|
86
|
+
return [key, _diff];
|
|
87
|
+
} catch (e) {
|
|
88
|
+
return [key, 99999];
|
|
89
|
+
}
|
|
90
|
+
}).sort(function (a, b) {
|
|
91
|
+
var left = a[1];
|
|
92
|
+
var right = b[1];
|
|
93
|
+
return left - right;
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
var _tokens$ = _slicedToArray(tokens[0], 2),
|
|
97
|
+
token = _tokens$[0],
|
|
98
|
+
diff = _tokens$[1];
|
|
99
|
+
|
|
100
|
+
if (diff < 10) {
|
|
101
|
+
return token;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
return undefined;
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
function toRgbArray(color) {
|
|
108
|
+
var colr = convert(color);
|
|
109
|
+
return [colr.rgb.r, colr.rgb.g, colr.rgb.b];
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Color difference function ripped from https://stackoverflow.com/a/52453462
|
|
113
|
+
*
|
|
114
|
+
* **Color difference**
|
|
115
|
+
* - <= 1.0 not perceptible by human eyes
|
|
116
|
+
* - 1-2 Perceptible through close observation
|
|
117
|
+
* - 2-10 Perceptible at a glance
|
|
118
|
+
* - 11-49 Colors are more similar than opposite
|
|
119
|
+
* - 100 Colors are opposite
|
|
120
|
+
*/
|
|
121
|
+
|
|
122
|
+
|
|
123
|
+
function deltaE(rgbA, rgbB) {
|
|
124
|
+
var labA = rgb2lab(toRgbArray(rgbA));
|
|
125
|
+
var labB = rgb2lab(toRgbArray(rgbB));
|
|
126
|
+
var deltaL = labA[0] - labB[0];
|
|
127
|
+
var deltaA = labA[1] - labB[1];
|
|
128
|
+
var deltaB = labA[2] - labB[2];
|
|
129
|
+
var c1 = Math.sqrt(labA[1] * labA[1] + labA[2] * labA[2]);
|
|
130
|
+
var c2 = Math.sqrt(labB[1] * labB[1] + labB[2] * labB[2]);
|
|
131
|
+
var deltaC = c1 - c2;
|
|
132
|
+
var deltaH = deltaA * deltaA + deltaB * deltaB - deltaC * deltaC;
|
|
133
|
+
deltaH = deltaH < 0 ? 0 : Math.sqrt(deltaH);
|
|
134
|
+
var sc = 1.0 + 0.045 * c1;
|
|
135
|
+
var sh = 1.0 + 0.015 * c1;
|
|
136
|
+
var deltaLKlsl = deltaL / 1.0;
|
|
137
|
+
var deltaCkcsc = deltaC / sc;
|
|
138
|
+
var deltaHkhsh = deltaH / sh;
|
|
139
|
+
var i = deltaLKlsl * deltaLKlsl + deltaCkcsc * deltaCkcsc + deltaHkhsh * deltaHkhsh;
|
|
140
|
+
return i < 0 ? 0 : Math.sqrt(i);
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
function rgb2lab(rgb) {
|
|
144
|
+
var r = rgb[0] / 255,
|
|
145
|
+
g = rgb[1] / 255,
|
|
146
|
+
b = rgb[2] / 255,
|
|
147
|
+
x,
|
|
148
|
+
y,
|
|
149
|
+
z;
|
|
150
|
+
r = r > 0.04045 ? Math.pow((r + 0.055) / 1.055, 2.4) : r / 12.92;
|
|
151
|
+
g = g > 0.04045 ? Math.pow((g + 0.055) / 1.055, 2.4) : g / 12.92;
|
|
152
|
+
b = b > 0.04045 ? Math.pow((b + 0.055) / 1.055, 2.4) : b / 12.92;
|
|
153
|
+
x = (r * 0.4124 + g * 0.3576 + b * 0.1805) / 0.95047;
|
|
154
|
+
y = (r * 0.2126 + g * 0.7152 + b * 0.0722) / 1.0;
|
|
155
|
+
z = (r * 0.0193 + g * 0.1192 + b * 0.9505) / 1.08883;
|
|
156
|
+
x = x > 0.008856 ? Math.pow(x, 1 / 3) : 7.787 * x + 16 / 116;
|
|
157
|
+
y = y > 0.008856 ? Math.pow(y, 1 / 3) : 7.787 * y + 16 / 116;
|
|
158
|
+
z = z > 0.008856 ? Math.pow(z, 1 / 3) : 7.787 * z + 16 / 116;
|
|
159
|
+
return [116 * y - 16, 500 * (x - y), 200 * (y - z)];
|
|
160
|
+
}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
var colorMap = {
|
|
2
|
+
resting: {
|
|
3
|
+
text: {
|
|
4
|
+
B300: ['color.text.selected', 'color.text.link.resting', 'color.iconBorder.brand'],
|
|
5
|
+
B400: ['color.text.selected', 'color.text.link.resting', 'color.iconBorder.brand'],
|
|
6
|
+
R300: ['color.text.danger', 'color.iconBorder.danger'],
|
|
7
|
+
R400: ['color.text.danger', 'color.iconBorder.danger'],
|
|
8
|
+
Y300: ['color.text.warning', 'color.iconBorder.warning'],
|
|
9
|
+
Y400: ['color.text.warning', 'color.iconBorder.warning'],
|
|
10
|
+
P300: ['color.text.discovery', 'color.iconBorder.discovery'],
|
|
11
|
+
P400: ['color.text.discovery', 'color.iconBorder.discovery'],
|
|
12
|
+
G300: ['color.text.success', 'color.iconBorder.success'],
|
|
13
|
+
G400: ['color.text.success', 'color.iconBorder.success'],
|
|
14
|
+
N0: ['color.text.onBold'],
|
|
15
|
+
N70: ['color.text.lowEmphasis'],
|
|
16
|
+
N80: ['color.text.lowEmphasis'],
|
|
17
|
+
N90: ['color.text.lowEmphasis'],
|
|
18
|
+
N100: ['color.text.lowEmphasis'],
|
|
19
|
+
N200: ['color.text.lowEmphasis'],
|
|
20
|
+
N300: ['color.text.lowEmphasis'],
|
|
21
|
+
N400: ['color.text.mediumEmphasis'],
|
|
22
|
+
N500: ['color.text.mediumEmphasis'],
|
|
23
|
+
N600: ['color.text.mediumEmphasis'],
|
|
24
|
+
N700: ['color.text.highEmphasis'],
|
|
25
|
+
N800: ['color.text.highEmphasis'],
|
|
26
|
+
N900: ['color.text.highEmphasis']
|
|
27
|
+
},
|
|
28
|
+
background: {
|
|
29
|
+
B75: ['color.background.selected.resting'],
|
|
30
|
+
N40: ['color.background.subtleNeutral.resting', 'color.background.sunken'],
|
|
31
|
+
B50: ['color.background.subtleBrand.resting', 'color.background.selected.resting'],
|
|
32
|
+
Y75: ['color.background.subtleWarning.resting'],
|
|
33
|
+
P50: ['color.background.subtleDiscovery.resting'],
|
|
34
|
+
R50: ['color.background.subtleDanger.resting'],
|
|
35
|
+
G50: ['color.background.subtleSuccess.resting'],
|
|
36
|
+
P300: ['color.background.boldDiscovery.resting'],
|
|
37
|
+
P400: ['color.background.boldDiscovery.resting'],
|
|
38
|
+
G300: ['color.background.boldSuccess.resting'],
|
|
39
|
+
Y300: ['color.background.boldWarning.resting'],
|
|
40
|
+
Y500: ['color.background.boldWarning.resting'],
|
|
41
|
+
R400: ['color.background.boldDanger.resting'],
|
|
42
|
+
B400: ['color.background.boldBrand.resting'],
|
|
43
|
+
N0: ['color.background.default', 'color.background.overlay', 'color.background.card']
|
|
44
|
+
},
|
|
45
|
+
border: {
|
|
46
|
+
N10: ['color.border.neutral'],
|
|
47
|
+
N20: ['color.border.neutral'],
|
|
48
|
+
N30: ['color.border.neutral'],
|
|
49
|
+
N40: ['color.border.neutral'],
|
|
50
|
+
N50: ['color.border.neutral'],
|
|
51
|
+
N60: ['color.border.neutral'],
|
|
52
|
+
N70: ['color.border.neutral'],
|
|
53
|
+
B100: ['color.border.focus'],
|
|
54
|
+
B300: ['color.iconBorder.brand', 'color.text.selected'],
|
|
55
|
+
B400: ['color.iconBorder.brand', 'color.text.selected'],
|
|
56
|
+
R300: ['color.iconBorder.danger'],
|
|
57
|
+
R400: ['color.iconBorder.danger'],
|
|
58
|
+
Y300: ['color.iconBorder.warning'],
|
|
59
|
+
Y400: ['color.iconBorder.warning'],
|
|
60
|
+
P300: ['color.iconBorder.discovery'],
|
|
61
|
+
P400: ['color.iconBorder.discovery'],
|
|
62
|
+
G300: ['color.iconBorder.success'],
|
|
63
|
+
G400: ['color.iconBorder.success']
|
|
64
|
+
}
|
|
65
|
+
},
|
|
66
|
+
hover: {
|
|
67
|
+
text: {
|
|
68
|
+
B300: ['color.text.link.resting'],
|
|
69
|
+
B400: ['color.text.link.resting']
|
|
70
|
+
},
|
|
71
|
+
background: {
|
|
72
|
+
B50: ['color.background.selected.hover'],
|
|
73
|
+
B75: ['color.background.selected.hover'],
|
|
74
|
+
P200: ['color.background.boldDiscovery.hover'],
|
|
75
|
+
P300: ['color.background.boldDiscovery.hover'],
|
|
76
|
+
G200: ['color.background.boldSuccess.hover'],
|
|
77
|
+
R300: ['color.background.boldDanger.hover'],
|
|
78
|
+
Y200: ['color.background.boldWarning.hover'],
|
|
79
|
+
B300: ['color.background.boldBrand.hover']
|
|
80
|
+
},
|
|
81
|
+
border: {}
|
|
82
|
+
},
|
|
83
|
+
pressed: {
|
|
84
|
+
text: {
|
|
85
|
+
B300: ['color.text.link.pressed'],
|
|
86
|
+
B400: ['color.text.link.pressed']
|
|
87
|
+
},
|
|
88
|
+
background: {
|
|
89
|
+
B50: ['color.background.selected.pressed'],
|
|
90
|
+
B75: ['color.background.selected.pressed'],
|
|
91
|
+
P400: ['color.background.boldDiscovery.pressed'],
|
|
92
|
+
P500: ['color.background.boldDiscovery.pressed'],
|
|
93
|
+
G400: ['color.background.boldSuccess.pressed'],
|
|
94
|
+
R500: ['color.background.boldDanger.pressed'],
|
|
95
|
+
Y400: ['color.background.boldWarning.pressed'],
|
|
96
|
+
B500: ['color.background.boldBrand.pressed']
|
|
97
|
+
},
|
|
98
|
+
border: {}
|
|
99
|
+
},
|
|
100
|
+
disabled: {
|
|
101
|
+
text: {
|
|
102
|
+
N60: ['color.text.disabled'],
|
|
103
|
+
N70: ['color.text.disabled'],
|
|
104
|
+
N80: ['color.text.disabled'],
|
|
105
|
+
N90: ['color.text.disabled'],
|
|
106
|
+
N100: ['color.text.disabled']
|
|
107
|
+
},
|
|
108
|
+
background: {
|
|
109
|
+
N10: ['color.background.disabled'],
|
|
110
|
+
N20: ['color.background.disabled'],
|
|
111
|
+
N30: ['color.background.disabled'],
|
|
112
|
+
N40: ['color.background.disabled']
|
|
113
|
+
},
|
|
114
|
+
border: {
|
|
115
|
+
N10: ['color.background.disabled'],
|
|
116
|
+
N20: ['color.background.disabled'],
|
|
117
|
+
N30: ['color.background.disabled'],
|
|
118
|
+
N40: ['color.background.disabled']
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
};
|
|
122
|
+
export default colorMap;
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
import { findClosetMatchingToken } from './color-difference';
|
|
2
|
+
import colorTokensMap from './color-palette-tokens-map';
|
|
3
|
+
|
|
4
|
+
function normalizeName(name) {
|
|
5
|
+
if (!name) {
|
|
6
|
+
return 'unknown';
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
if (name.startsWith('background')) {
|
|
10
|
+
return 'background';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (name.toLowerCase().includes('color') || name === 'color' || name === 'fill' || name === 'stroke') {
|
|
14
|
+
return 'text';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (name.startsWith('border') || name.toLowerCase().replace('-', '') === 'boxshadow') {
|
|
18
|
+
return 'border';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return 'unknown';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function colorToToken(paletteName, _ref) {
|
|
25
|
+
var _ref$state = _ref.state,
|
|
26
|
+
state = _ref$state === void 0 ? 'resting' : _ref$state,
|
|
27
|
+
propertyName = _ref.propertyName;
|
|
28
|
+
var getLowConfidenceFuzzyResult = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
|
|
29
|
+
return [];
|
|
30
|
+
};
|
|
31
|
+
var normalizedPropertyName = normalizeName(propertyName);
|
|
32
|
+
var value = paletteName.toUpperCase();
|
|
33
|
+
var tokenSuggestionProperties = colorTokensMap[state];
|
|
34
|
+
var tokenSuggestionProperty = tokenSuggestionProperties && normalizedPropertyName !== 'unknown' && tokenSuggestionProperties[normalizedPropertyName];
|
|
35
|
+
var tokenSuggestionValue = tokenSuggestionProperty && tokenSuggestionProperty[value];
|
|
36
|
+
|
|
37
|
+
if (tokenSuggestionValue && tokenSuggestionValue.length === 1) {
|
|
38
|
+
return {
|
|
39
|
+
confidence: 'high',
|
|
40
|
+
suggestion: tokenSuggestionValue,
|
|
41
|
+
fallbackNeeded: true
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
if (tokenSuggestionValue && tokenSuggestionValue.length > 2) {
|
|
46
|
+
return {
|
|
47
|
+
confidence: 'medium',
|
|
48
|
+
suggestion: tokenSuggestionValue,
|
|
49
|
+
fallbackNeeded: true
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
var closestTokenName = findClosetMatchingToken(value);
|
|
54
|
+
|
|
55
|
+
if (closestTokenName) {
|
|
56
|
+
return {
|
|
57
|
+
confidence: 'low',
|
|
58
|
+
suggestion: [closestTokenName],
|
|
59
|
+
fallbackNeeded: true
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var fuzzyResult = getLowConfidenceFuzzyResult();
|
|
64
|
+
|
|
65
|
+
if (fuzzyResult.length) {
|
|
66
|
+
return {
|
|
67
|
+
confidence: 'low',
|
|
68
|
+
suggestion: fuzzyResult,
|
|
69
|
+
fallbackNeeded: true
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
return {
|
|
74
|
+
confidence: 'unknown',
|
|
75
|
+
suggestion: [],
|
|
76
|
+
fallbackNeeded: true
|
|
77
|
+
};
|
|
78
|
+
}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
import { legacyColorMixins, legacyColors } from './legacy-colors';
|
|
2
|
+
import { namedColors } from './named-colors';
|
|
3
|
+
export var isLegacyColor = function isLegacyColor(value) {
|
|
4
|
+
return legacyColors.includes(value);
|
|
5
|
+
};
|
|
6
|
+
export var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
7
|
+
return legacyColorMixins.includes(value);
|
|
8
|
+
};
|
|
9
|
+
export var includesHardCodedColor = function includesHardCodedColor(raw) {
|
|
10
|
+
var value = raw.toLowerCase();
|
|
11
|
+
|
|
12
|
+
if (/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|hsl)a?\([^\)]*\)/.exec(value.toLowerCase())) {
|
|
13
|
+
return true;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
for (var i = 0; i < namedColors.length; i++) {
|
|
17
|
+
if (value.includes("".concat(namedColors[i], ";"))) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
return false;
|
|
23
|
+
};
|
|
24
|
+
export var isHardCodedColor = function isHardCodedColor(value) {
|
|
25
|
+
if (namedColors.includes(value.toLowerCase())) {
|
|
26
|
+
return true;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (value.startsWith('rgb(') || value.startsWith('rgba(') || value.startsWith('hsl(') || value.startsWith('hsla(') || value.startsWith('lch(') || value.startsWith('lab(') || value.startsWith('color(')) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
if (value.startsWith('#') && ( // short hex, hex, or hex with alpha
|
|
34
|
+
value.length === 4 || value.length === 7 || value.length === 9)) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
return false;
|
|
39
|
+
};
|