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