@atlaskit/tokens 1.49.1 → 1.51.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 +1593 -1594
- package/README.md +14 -8
- package/codemods/css-to-design-tokens/lib/colors.tsx +47 -49
- package/codemods/css-to-design-tokens/lib/declaration.tsx +26 -26
- package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +326 -326
- package/codemods/css-to-design-tokens/lib/meta.tsx +116 -122
- package/codemods/css-to-design-tokens/lib/tokens.tsx +28 -35
- package/codemods/css-to-design-tokens/lib/value.tsx +70 -72
- package/codemods/css-to-design-tokens/transform.tsx +68 -72
- package/codemods/hypermod.config.tsx +5 -5
- package/codemods/remove-fallbacks-color/transform.tsx +16 -18
- package/codemods/theme-to-design-tokens/transform.tsx +505 -588
- package/codemods/theme-to-design-tokens/utils/ast-meta.tsx +139 -147
- package/codemods/theme-to-design-tokens/utils/ast.tsx +23 -34
- package/codemods/theme-to-design-tokens/utils/color.tsx +25 -26
- package/codemods/theme-to-design-tokens/utils/css-utils.tsx +27 -30
- package/codemods/theme-to-design-tokens/utils/fuzzy-search.tsx +272 -290
- package/codemods/theme-to-design-tokens/utils/legacy-colors.tsx +224 -224
- package/codemods/theme-to-design-tokens/utils/named-colors.tsx +148 -148
- package/codemods/theme-to-design-tokens/utils/string-utils.tsx +10 -16
- package/codemods/utils/tokens.tsx +371 -371
- package/dist/cjs/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
- package/dist/cjs/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
- package/dist/cjs/artifacts/generated-pairs.js +1 -1
- package/dist/cjs/artifacts/theme-import-map.js +1 -1
- package/dist/cjs/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/cjs/artifacts/token-default-values.js +1 -1
- package/dist/cjs/artifacts/token-names.js +1 -1
- package/dist/cjs/artifacts/tokens-raw/atlassian-typography-minor3.js +3 -3
- package/dist/es2019/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
- package/dist/es2019/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
- package/dist/es2019/artifacts/generated-pairs.js +1 -1
- package/dist/es2019/artifacts/theme-import-map.js +1 -1
- package/dist/es2019/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/es2019/artifacts/token-default-values.js +1 -1
- package/dist/es2019/artifacts/token-names.js +1 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-typography-minor3.js +3 -3
- package/dist/esm/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
- package/dist/esm/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
- package/dist/esm/artifacts/generated-pairs.js +1 -1
- package/dist/esm/artifacts/theme-import-map.js +1 -1
- package/dist/esm/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/esm/artifacts/token-default-values.js +1 -1
- package/dist/esm/artifacts/token-names.js +1 -1
- package/dist/esm/artifacts/tokens-raw/atlassian-typography-minor3.js +3 -3
- package/dist/types/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types/artifacts/theme-import-map.d.ts +2 -2
- package/dist/types/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
- package/dist/types/artifacts/token-default-values.d.ts +1 -1
- package/dist/types/artifacts/token-names.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
- package/dist/types/artifacts/types-internal.d.ts +1 -1
- package/dist/types/artifacts/types.d.ts +1 -1
- package/dist/types/babel-plugin/plugin.d.ts +1 -1
- package/dist/types/custom-theme.d.ts +2 -2
- package/dist/types/enable-global-theme.d.ts +2 -2
- package/dist/types/entry-points/css-type-schema.codegen.d.ts +1 -1
- package/dist/types/entry-points/token-ids.d.ts +1 -1
- package/dist/types/get-global-theme.d.ts +1 -1
- package/dist/types/get-ssr-auto-script.d.ts +1 -1
- package/dist/types/get-theme-html-attrs.d.ts +1 -1
- package/dist/types/get-theme-styles.d.ts +1 -1
- package/dist/types/get-token.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/load-custom-theme-styles.d.ts +1 -1
- package/dist/types/set-global-theme.d.ts +2 -2
- package/dist/types/theme-state-transformer.d.ts +1 -1
- package/dist/types/utils/color-detection.d.ts +1 -1
- package/dist/types/utils/color-mode-listeners.d.ts +1 -1
- package/dist/types/utils/configure-page.d.ts +1 -1
- package/dist/types/utils/contrast-mode-listeners.d.ts +1 -1
- package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -1
- package/dist/types/utils/custom-theme-token-contrast-check.d.ts +1 -1
- package/dist/types/utils/generate-custom-color-ramp.d.ts +2 -2
- package/dist/types/utils/get-increased-contrast-theme.d.ts +1 -1
- package/dist/types/utils/get-theme-preferences.d.ts +1 -1
- package/dist/types/utils/theme-loading.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/generated-pairs.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/theme-import-map.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/token-default-values.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/token-names.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types-internal.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types.d.ts +1 -1
- package/dist/types-ts4.5/babel-plugin/plugin.d.ts +1 -1
- package/dist/types-ts4.5/custom-theme.d.ts +2 -2
- package/dist/types-ts4.5/enable-global-theme.d.ts +2 -2
- package/dist/types-ts4.5/entry-points/css-type-schema.codegen.d.ts +1 -1
- package/dist/types-ts4.5/entry-points/token-ids.d.ts +1 -1
- package/dist/types-ts4.5/get-global-theme.d.ts +1 -1
- package/dist/types-ts4.5/get-ssr-auto-script.d.ts +1 -1
- package/dist/types-ts4.5/get-theme-html-attrs.d.ts +1 -1
- package/dist/types-ts4.5/get-theme-styles.d.ts +1 -1
- package/dist/types-ts4.5/get-token.d.ts +1 -1
- package/dist/types-ts4.5/index.d.ts +1 -1
- package/dist/types-ts4.5/load-custom-theme-styles.d.ts +1 -1
- package/dist/types-ts4.5/set-global-theme.d.ts +2 -2
- package/dist/types-ts4.5/theme-state-transformer.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-detection.d.ts +1 -1
- package/dist/types-ts4.5/utils/color-mode-listeners.d.ts +1 -1
- package/dist/types-ts4.5/utils/configure-page.d.ts +1 -1
- package/dist/types-ts4.5/utils/contrast-mode-listeners.d.ts +1 -1
- package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -1
- package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +1 -1
- package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +2 -2
- package/dist/types-ts4.5/utils/get-increased-contrast-theme.d.ts +1 -1
- package/dist/types-ts4.5/utils/get-theme-preferences.d.ts +1 -1
- package/dist/types-ts4.5/utils/theme-loading.d.ts +1 -1
- package/package.json +138 -140
- package/report.api.md +2071 -2090
|
@@ -5,155 +5,147 @@ import { uniqueWordsFromTokens } from '../../utils/tokens';
|
|
|
5
5
|
import { getClosestDecendantOfType } from './ast';
|
|
6
6
|
|
|
7
7
|
export function getMetaFromAncestors(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
8
|
+
j: core.JSCodeshift,
|
|
9
|
+
path: any,
|
|
10
|
+
meta: string[] = [],
|
|
11
11
|
): string[] {
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
if (parent) {
|
|
91
|
-
return getMetaFromAncestors(j, parent, meta);
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
return meta;
|
|
12
|
+
const parent = path.parentPath;
|
|
13
|
+
const grandParent = parent && parent.parentPath;
|
|
14
|
+
|
|
15
|
+
if (parent && parent.value.type === 'ObjectProperty') {
|
|
16
|
+
let value = '';
|
|
17
|
+
|
|
18
|
+
if (
|
|
19
|
+
parent.value.key.type === 'Literal' ||
|
|
20
|
+
parent.value.key.type === 'StringLiteral' ||
|
|
21
|
+
parent.value.key.type === 'NumericLiteral'
|
|
22
|
+
) {
|
|
23
|
+
value = parent.value.key.value.toString();
|
|
24
|
+
} else {
|
|
25
|
+
value = parent.value.key.name;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
meta.push(value);
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
32
|
+
const expressionIndex = grandParent.value.expressions.findIndex(
|
|
33
|
+
(exp: any) => exp.name === path.value.name,
|
|
34
|
+
);
|
|
35
|
+
const quasi = grandParent.value.quasis[expressionIndex];
|
|
36
|
+
const propertyName = (quasi.value.cooked || quasi.value.raw || '')
|
|
37
|
+
.replace(/\n/g, '')
|
|
38
|
+
.split(/;|{|}/)
|
|
39
|
+
.filter((el: string) => !el.match(/\.|\@|\(|\)/))
|
|
40
|
+
.pop()
|
|
41
|
+
.split(/:/g)[0]
|
|
42
|
+
.trim();
|
|
43
|
+
|
|
44
|
+
grandParent.value.quasis
|
|
45
|
+
.slice(0, expressionIndex + 1)
|
|
46
|
+
.map((q: any) => q.value.cooked)
|
|
47
|
+
// We reverse so the most nested one is first which we're more likely than not interested in
|
|
48
|
+
.reverse()
|
|
49
|
+
.some((str: string) => {
|
|
50
|
+
const result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
51
|
+
|
|
52
|
+
if (result) {
|
|
53
|
+
meta.push(result[0]);
|
|
54
|
+
return true;
|
|
55
|
+
}
|
|
56
|
+
});
|
|
57
|
+
|
|
58
|
+
meta.push(propertyName);
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (parent && parent.value.type === 'JSXAttribute') {
|
|
62
|
+
if (
|
|
63
|
+
!['css', 'styles', 'style', 'fill', 'stopColor', 'startColor'].includes(
|
|
64
|
+
parent.value.name.name,
|
|
65
|
+
)
|
|
66
|
+
) {
|
|
67
|
+
meta.push(parent.value.name.name);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
const closestJSXElement = getClosestDecendantOfType(j, path, j.JSXOpeningElement);
|
|
72
|
+
|
|
73
|
+
if (closestJSXElement) {
|
|
74
|
+
const jsxElementName = closestJSXElement.value.name.name;
|
|
75
|
+
const nameComponents = jsxElementName.replace(/([a-z])([A-Z])/g, '$1 $2').split(' ');
|
|
76
|
+
|
|
77
|
+
meta.push(...nameComponents);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
81
|
+
meta.push(parent.value.id.name);
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
if (parent) {
|
|
85
|
+
return getMetaFromAncestors(j, parent, meta);
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
return meta;
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
export function cleanMeta(meta: string[]) {
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
return accum;
|
|
158
|
-
}, []);
|
|
92
|
+
return meta
|
|
93
|
+
.reduce<string[]>(
|
|
94
|
+
(accum, val) => [
|
|
95
|
+
...accum,
|
|
96
|
+
...(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map((e) => e.toLowerCase()) : []),
|
|
97
|
+
],
|
|
98
|
+
[],
|
|
99
|
+
)
|
|
100
|
+
.reduce<string[]>((accum, val) => {
|
|
101
|
+
const cleanVal = val
|
|
102
|
+
.replace(/:/g, '')
|
|
103
|
+
.replace(/,/g, '')
|
|
104
|
+
.replace('grey', 'neutral')
|
|
105
|
+
.replace('skeleton', 'neutral')
|
|
106
|
+
.replace('texts', 'text')
|
|
107
|
+
.replace('red', 'danger')
|
|
108
|
+
.replace('error', 'danger')
|
|
109
|
+
.replace('invalid', 'danger')
|
|
110
|
+
.replace('removed', 'danger')
|
|
111
|
+
.replace('removal', 'danger')
|
|
112
|
+
.replace('remove', 'danger')
|
|
113
|
+
.replace('focus', 'focused')
|
|
114
|
+
.replace('valid', 'success')
|
|
115
|
+
.replace('successful', 'success')
|
|
116
|
+
.replace('risk', 'warning')
|
|
117
|
+
.replace('caution', 'warning')
|
|
118
|
+
.replace('primary', 'bold')
|
|
119
|
+
.replace('secondary', 'subtle')
|
|
120
|
+
.replace('hyperlink', 'link')
|
|
121
|
+
.replace('anchor', 'link')
|
|
122
|
+
.replace('active', 'pressed')
|
|
123
|
+
.replace('hover', 'hovered')
|
|
124
|
+
.replace('card', 'raised')
|
|
125
|
+
.replace('dragged', 'surface overlay')
|
|
126
|
+
.replace('dragging', 'surface overlay')
|
|
127
|
+
.replace('drag', 'surface overlay')
|
|
128
|
+
.replace('background-color', 'background')
|
|
129
|
+
.replace('color', 'text')
|
|
130
|
+
.replace('icons', 'icon')
|
|
131
|
+
.replace('glyph', 'icon')
|
|
132
|
+
.replace('stroke', 'border')
|
|
133
|
+
.replace('border-left', 'border')
|
|
134
|
+
.replace('border-right', 'border')
|
|
135
|
+
.replace('border-top', 'border')
|
|
136
|
+
.replace('border-bottom', 'border')
|
|
137
|
+
.replace('box-shadow', 'shadow');
|
|
138
|
+
|
|
139
|
+
accum.push(...cleanVal.split(' '));
|
|
140
|
+
|
|
141
|
+
return accum;
|
|
142
|
+
}, [])
|
|
143
|
+
.filter((val) => uniqueWordsFromTokens.includes(val))
|
|
144
|
+
.reduce<string[]>((accum, val) => {
|
|
145
|
+
if (!accum.includes(val)) {
|
|
146
|
+
accum.push(val);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
return accum;
|
|
150
|
+
}, []);
|
|
159
151
|
}
|
|
@@ -1,46 +1,35 @@
|
|
|
1
1
|
import { isDecendantOfType } from '@hypermod/utils';
|
|
2
2
|
import type { ASTNode, ASTPath, JSCodeshift } from 'jscodeshift';
|
|
3
3
|
|
|
4
|
-
export function isDecendantOfToken(
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
) {
|
|
14
|
-
return true;
|
|
15
|
-
}
|
|
4
|
+
export function isDecendantOfToken(j: JSCodeshift, path: ASTPath | ASTNode): boolean {
|
|
5
|
+
if (
|
|
6
|
+
'type' in path &&
|
|
7
|
+
path.type === 'CallExpression' &&
|
|
8
|
+
path.callee.type === 'Identifier' &&
|
|
9
|
+
path.callee.name === 'token'
|
|
10
|
+
) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
16
13
|
|
|
17
|
-
|
|
18
|
-
j(path).closest(j.CallExpression, { callee: { name: 'token' } }).length > 0
|
|
19
|
-
);
|
|
14
|
+
return j(path).closest(j.CallExpression, { callee: { name: 'token' } }).length > 0;
|
|
20
15
|
}
|
|
21
16
|
|
|
22
17
|
export function isParentOfToken(j: JSCodeshift, path: any): boolean {
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
18
|
+
if (
|
|
19
|
+
path.type === 'CallExpression' &&
|
|
20
|
+
path.callee.type === 'Identifier' &&
|
|
21
|
+
path.callee.name === 'token'
|
|
22
|
+
) {
|
|
23
|
+
return true;
|
|
24
|
+
}
|
|
30
25
|
|
|
31
|
-
|
|
32
|
-
j(path).find(j.CallExpression, { callee: { name: 'token' } }).length > 0
|
|
33
|
-
);
|
|
26
|
+
return j(path).find(j.CallExpression, { callee: { name: 'token' } }).length > 0;
|
|
34
27
|
}
|
|
35
28
|
|
|
36
|
-
export function getClosestDecendantOfType(
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
) {
|
|
41
|
-
if (!isDecendantOfType(j, path, type)) {
|
|
42
|
-
return;
|
|
43
|
-
}
|
|
29
|
+
export function getClosestDecendantOfType(j: JSCodeshift, path: ASTPath<any>, type: any) {
|
|
30
|
+
if (!isDecendantOfType(j, path, type)) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
44
33
|
|
|
45
|
-
|
|
34
|
+
return j(path).closest(type).get();
|
|
46
35
|
}
|
|
@@ -3,43 +3,42 @@ import { namedColors } from './named-colors';
|
|
|
3
3
|
|
|
4
4
|
export const isLegacyColor = (value: string) => legacyColors.includes(value);
|
|
5
5
|
|
|
6
|
-
export const isLegacyNamedColor = (value: string) =>
|
|
7
|
-
legacyColorMixins.includes(value);
|
|
6
|
+
export const isLegacyNamedColor = (value: string) => legacyColorMixins.includes(value);
|
|
8
7
|
|
|
9
8
|
const colorRegexp =
|
|
10
|
-
|
|
9
|
+
/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|rgba|hsl|hsla|lch|lab|color)\([^\)]*\)/;
|
|
11
10
|
|
|
12
11
|
export const includesHardCodedColor = (raw: string) => {
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
12
|
+
const value = raw.toLowerCase();
|
|
13
|
+
if (colorRegexp.exec(value)) {
|
|
14
|
+
return true;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
for (let i = 0; i < namedColors.length; i++) {
|
|
18
|
+
if (value.includes(`${namedColors[i]};`)) {
|
|
19
|
+
return true;
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
return false;
|
|
25
24
|
};
|
|
26
25
|
|
|
27
26
|
export const isHardCodedColor = (raw: string) => {
|
|
28
|
-
|
|
27
|
+
const value = raw.toLowerCase();
|
|
29
28
|
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
29
|
+
if (namedColors.includes(value)) {
|
|
30
|
+
return true;
|
|
31
|
+
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
33
|
+
const match = value.toLowerCase().match(colorRegexp);
|
|
34
|
+
if (match && match[0] === value) {
|
|
35
|
+
return true;
|
|
36
|
+
}
|
|
38
37
|
|
|
39
|
-
|
|
38
|
+
return false;
|
|
40
39
|
};
|
|
41
40
|
|
|
42
41
|
export function isBoldColor(color: string) {
|
|
43
|
-
|
|
44
|
-
|
|
42
|
+
const number = parseInt(color.replace(/^./, ''), 10);
|
|
43
|
+
return number > 300;
|
|
45
44
|
}
|
|
@@ -1,38 +1,35 @@
|
|
|
1
1
|
import { isColorRelatedProperty } from '../../css-to-design-tokens/lib/declaration';
|
|
2
2
|
|
|
3
3
|
export function containsReplaceableCSSDeclarations(input: string) {
|
|
4
|
-
|
|
4
|
+
const cssPattern = /(\S+)\s*:/g;
|
|
5
5
|
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
6
|
+
let match;
|
|
7
|
+
while ((match = cssPattern.exec(input)) !== null) {
|
|
8
|
+
if (isColorRelatedProperty(match[1])) {
|
|
9
|
+
return true;
|
|
10
|
+
}
|
|
11
|
+
}
|
|
12
|
+
return false;
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
-
export function findEndIndexOfCSSExpression(
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
// before that symbol.
|
|
22
|
-
const semicolonIndex = text.indexOf(';');
|
|
23
|
-
const braceIndex = text.indexOf('}');
|
|
15
|
+
export function findEndIndexOfCSSExpression(text: string, isAtEndOfInput: boolean): number | null {
|
|
16
|
+
// CSS expression can end *on* a semicolon or *before* a brace. In either
|
|
17
|
+
// case we treat the remaining part of the value to cover one character
|
|
18
|
+
// before that symbol.
|
|
19
|
+
const semicolonIndex = text.indexOf(';');
|
|
20
|
+
const braceIndex = text.indexOf('}');
|
|
24
21
|
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
22
|
+
if (semicolonIndex === -1 && braceIndex === -1) {
|
|
23
|
+
if (isAtEndOfInput) {
|
|
24
|
+
return text.length;
|
|
25
|
+
} else {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
} else if (semicolonIndex === -1) {
|
|
29
|
+
return braceIndex - 1;
|
|
30
|
+
} else if (braceIndex === -1) {
|
|
31
|
+
return semicolonIndex - 1;
|
|
32
|
+
} else {
|
|
33
|
+
return Math.min(semicolonIndex, braceIndex) - 1;
|
|
34
|
+
}
|
|
38
35
|
}
|