@atlaskit/codemod-cli 0.11.4 → 0.12.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 +17 -0
- package/dist/cjs/cli.js +72 -75
- package/dist/cjs/filepath.js +29 -83
- package/dist/cjs/index.js +3 -6
- package/dist/cjs/main.js +165 -441
- package/dist/cjs/presets/css-to-design-tokens/css-to-design-tokens.js +44 -135
- package/dist/cjs/presets/css-to-design-tokens/utils/legacy-colors.js +3 -4
- package/dist/cjs/presets/css-to-design-tokens/utils/meta.js +6 -29
- package/dist/cjs/presets/index.js +2 -9
- package/dist/cjs/presets/styled-to-emotion/styled-to-emotion.js +13 -25
- package/dist/cjs/presets/theme-to-design-tokens/theme-to-design-tokens.js +34 -82
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast-meta.js +14 -41
- package/dist/cjs/presets/theme-to-design-tokens/utils/ast.js +0 -2
- package/dist/cjs/presets/theme-to-design-tokens/utils/color.js +9 -28
- package/dist/cjs/presets/theme-to-design-tokens/utils/fuzzy-search.js +44 -106
- package/dist/cjs/presets/theme-to-design-tokens/utils/legacy-colors.js +3 -3
- package/dist/cjs/presets/theme-to-design-tokens/utils/named-colors.js +1 -1
- package/dist/cjs/presets/theme-to-design-tokens/utils/tokens.js +2 -22
- package/dist/cjs/sinceRef.js +36 -92
- package/dist/cjs/transforms.js +27 -72
- package/dist/cjs/types.js +2 -45
- package/dist/cjs/utils.js +7 -20
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/filepath.js +7 -5
- package/dist/es2019/main.js +17 -51
- package/dist/es2019/presets/css-to-design-tokens/css-to-design-tokens.js +19 -51
- package/dist/es2019/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
- package/dist/es2019/presets/css-to-design-tokens/utils/meta.js +0 -6
- package/dist/es2019/presets/index.js +1 -1
- package/dist/es2019/presets/styled-to-emotion/styled-to-emotion.js +1 -4
- package/dist/es2019/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -14
- package/dist/es2019/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
- package/dist/es2019/presets/theme-to-design-tokens/utils/color.js +2 -7
- package/dist/es2019/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
- package/dist/es2019/presets/theme-to-design-tokens/utils/tokens.js +0 -1
- package/dist/es2019/sinceRef.js +2 -11
- package/dist/es2019/transforms.js +3 -13
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/utils.js +1 -12
- package/dist/es2019/version.json +1 -1
- package/dist/esm/cli.js +53 -57
- package/dist/esm/filepath.js +51 -63
- package/dist/esm/main.js +221 -322
- package/dist/esm/presets/css-to-design-tokens/css-to-design-tokens.js +33 -71
- package/dist/esm/presets/css-to-design-tokens/utils/legacy-colors.js +0 -1
- package/dist/esm/presets/css-to-design-tokens/utils/meta.js +0 -6
- package/dist/esm/presets/index.js +1 -1
- package/dist/esm/presets/styled-to-emotion/styled-to-emotion.js +1 -4
- package/dist/esm/presets/theme-to-design-tokens/theme-to-design-tokens.js +4 -15
- package/dist/esm/presets/theme-to-design-tokens/utils/ast-meta.js +2 -11
- package/dist/esm/presets/theme-to-design-tokens/utils/color.js +2 -7
- package/dist/esm/presets/theme-to-design-tokens/utils/fuzzy-search.js +38 -95
- package/dist/esm/presets/theme-to-design-tokens/utils/tokens.js +0 -1
- package/dist/esm/sinceRef.js +49 -65
- package/dist/esm/transforms.js +4 -14
- package/dist/esm/types.js +1 -11
- package/dist/esm/utils.js +1 -12
- package/dist/esm/version.json +1 -1
- package/package.json +2 -2
- package/tmp/api-report-tmp.d.ts +0 -66
|
@@ -1,145 +1,97 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
4
|
Object.defineProperty(exports, "__esModule", {
|
|
6
5
|
value: true
|
|
7
6
|
});
|
|
8
7
|
exports.default = transformer;
|
|
9
|
-
|
|
10
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
11
|
-
|
|
12
8
|
var _ast = require("./utils/ast");
|
|
13
|
-
|
|
14
9
|
var _astMeta = require("./utils/ast-meta");
|
|
15
|
-
|
|
16
10
|
var _color = require("./utils/color");
|
|
17
|
-
|
|
18
11
|
var _fuzzySearch = _interopRequireDefault(require("./utils/fuzzy-search"));
|
|
19
|
-
|
|
20
12
|
var _legacyColors = require("./utils/legacy-colors");
|
|
21
|
-
|
|
22
13
|
var _tokens = require("./utils/tokens");
|
|
23
|
-
|
|
24
14
|
/* eslint-disable no-console */
|
|
25
|
-
var search = (0, _fuzzySearch.default)(_tokens.tokens, false);
|
|
26
15
|
|
|
16
|
+
const search = (0, _fuzzySearch.default)(_tokens.tokens, false);
|
|
27
17
|
function hasImportDeclaration(j, source, sourcePath) {
|
|
28
|
-
return !!source.find(j.ImportDeclaration).filter(
|
|
29
|
-
return path.node.source.value === sourcePath;
|
|
30
|
-
}).length;
|
|
18
|
+
return !!source.find(j.ImportDeclaration).filter(path => path.node.source.value === sourcePath).length;
|
|
31
19
|
}
|
|
32
|
-
|
|
33
20
|
function hasImportSpecifier(j, source, specifier, sourcePath) {
|
|
34
|
-
return !!source.find(j.ImportDeclaration).filter(
|
|
35
|
-
return path.node.source.value === sourcePath;
|
|
36
|
-
}).find(j.ImportSpecifier, {
|
|
21
|
+
return !!source.find(j.ImportDeclaration).filter(path => path.node.source.value === sourcePath).find(j.ImportSpecifier, {
|
|
37
22
|
local: {
|
|
38
23
|
name: specifier
|
|
39
24
|
}
|
|
40
25
|
}).length;
|
|
41
26
|
}
|
|
42
|
-
|
|
43
27
|
function insertTokenImport(j, source) {
|
|
44
28
|
if (hasImportDeclaration(j, source, '@atlaskit/tokens')) {
|
|
45
29
|
return;
|
|
46
30
|
}
|
|
47
|
-
|
|
48
|
-
var newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
31
|
+
const newImport = j.importDeclaration([j.importSpecifier(j.identifier('token'))], j.stringLiteral('@atlaskit/tokens'));
|
|
49
32
|
source.get().node.program.body.unshift(newImport);
|
|
50
33
|
}
|
|
51
|
-
|
|
52
34
|
function buildToken(j, tokenId, node) {
|
|
53
|
-
|
|
35
|
+
const callExpr = j.callExpression(j.identifier('token'), [j.stringLiteral(tokenId), node].filter(Boolean));
|
|
54
36
|
return callExpr;
|
|
55
37
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
var results = search.get(meta.join(' '));
|
|
62
|
-
var tokenId = ['utility.UNSAFE_util.MISSING_TOKEN'];
|
|
63
|
-
|
|
38
|
+
function getTokenFromNode(j, path, baseMeta = []) {
|
|
39
|
+
const foundMeta = (0, _astMeta.getMetaFromAncestors)(j, path);
|
|
40
|
+
const meta = (0, _astMeta.cleanMeta)([...foundMeta, ...baseMeta]);
|
|
41
|
+
const results = search.get(meta.join(' '));
|
|
42
|
+
let tokenId = ['MISSING_TOKEN'];
|
|
64
43
|
if (results) {
|
|
65
|
-
tokenId = results.map(
|
|
66
|
-
return result[1];
|
|
67
|
-
});
|
|
44
|
+
tokenId = results.map(result => result[1]);
|
|
68
45
|
}
|
|
69
|
-
|
|
70
46
|
return tokenId[0];
|
|
71
47
|
}
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
.find(j.MemberExpression).filter(function (path) {
|
|
48
|
+
function transformer(file, api, debug = false) {
|
|
49
|
+
const j = api.jscodeshift;
|
|
50
|
+
const source = j(file.source);
|
|
51
|
+
let transformed = false;
|
|
52
|
+
source
|
|
53
|
+
// Handle colors.N100
|
|
54
|
+
.find(j.MemberExpression).filter(path => {
|
|
80
55
|
return path.value.object.type === 'Identifier' && path.value.object.name === 'colors' && path.value.property.type === 'Identifier' && (0, _color.isLegacyColor)(path.value.property.name);
|
|
81
|
-
}).filter(
|
|
82
|
-
return !(0, _ast.isDecendantOfToken)(j, path);
|
|
83
|
-
}).forEach(function (path) {
|
|
56
|
+
}).filter(path => !(0, _ast.isDecendantOfToken)(j, path)).forEach(path => {
|
|
84
57
|
debug && console.log('file:', file.path);
|
|
85
58
|
insertTokenImport(j, source);
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
59
|
+
const key = path.value.property.type === 'Identifier' ? path.value.property.name : undefined;
|
|
60
|
+
const colorMeta = _legacyColors.legacyColorMetaMap[key] || [];
|
|
61
|
+
const tokenId = getTokenFromNode(j, path, colorMeta);
|
|
89
62
|
j(path).replaceWith(buildToken(j, tokenId, path.value));
|
|
90
63
|
transformed = true;
|
|
91
64
|
});
|
|
92
|
-
source.find(j.ObjectProperty).filter(
|
|
93
|
-
|
|
94
|
-
}).filter(function (path) {
|
|
95
|
-
return hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme/colors');
|
|
96
|
-
}).filter(function (path) {
|
|
97
|
-
return !(0, _ast.isDecendantOfToken)(j, path.value.value);
|
|
98
|
-
}).forEach(function (path) {
|
|
99
|
-
var valuePath = path.get('value');
|
|
65
|
+
source.find(j.ObjectProperty).filter(path => path.value.value.type === 'Identifier' && ((0, _color.isLegacyColor)(path.value.value.name) || (0, _color.isLegacyNamedColor)(path.value.value.name))).filter(path => hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.value.type === 'Identifier' ? path.value.value.name : '', '@atlaskit/theme/colors')).filter(path => !(0, _ast.isDecendantOfToken)(j, path.value.value)).forEach(path => {
|
|
66
|
+
const valuePath = path.get('value');
|
|
100
67
|
debug && console.log('file:', file.path);
|
|
101
68
|
insertTokenImport(j, source);
|
|
102
|
-
|
|
103
|
-
|
|
69
|
+
const colorMeta = _legacyColors.legacyColorMetaMap[valuePath.name] || [];
|
|
70
|
+
const tokenId = getTokenFromNode(j, valuePath, colorMeta);
|
|
104
71
|
j(path).replaceWith(j.objectProperty(path.value.key, buildToken(j, tokenId, valuePath.value)));
|
|
105
72
|
transformed = true;
|
|
106
73
|
});
|
|
107
|
-
source.find(j.Identifier).filter(
|
|
108
|
-
return (0, _color.isLegacyColor)(path.value.name) || (0, _color.isLegacyNamedColor)(path.value.name);
|
|
109
|
-
}).filter(function (path) {
|
|
110
|
-
return hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme/colors');
|
|
111
|
-
}).filter(function (path) {
|
|
112
|
-
return !['ImportSpecifier', 'MemberExpression', 'ObjectProperty'].includes(path.parentPath.value.type);
|
|
113
|
-
}).filter(function (path) {
|
|
114
|
-
return !(0, _ast.isDecendantOfToken)(j, path);
|
|
115
|
-
}).forEach(function (path) {
|
|
74
|
+
source.find(j.Identifier).filter(path => (0, _color.isLegacyColor)(path.value.name) || (0, _color.isLegacyNamedColor)(path.value.name)).filter(path => hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme') || hasImportSpecifier(j, source, path.value.name, '@atlaskit/theme/colors')).filter(path => !['ImportSpecifier', 'MemberExpression', 'ObjectProperty'].includes(path.parentPath.value.type)).filter(path => !(0, _ast.isDecendantOfToken)(j, path)).forEach(path => {
|
|
116
75
|
debug && console.log('file:', file.path);
|
|
117
76
|
insertTokenImport(j, source);
|
|
118
|
-
|
|
119
|
-
|
|
77
|
+
const colorMeta = _legacyColors.legacyColorMetaMap[path.value.name] || [];
|
|
78
|
+
const tokenId = getTokenFromNode(j, path, colorMeta);
|
|
120
79
|
j(path).replaceWith(buildToken(j, tokenId, path.value));
|
|
121
80
|
transformed = true;
|
|
122
81
|
});
|
|
123
|
-
source.find(j.Literal).filter(
|
|
124
|
-
return typeof path.value.value === 'string' && ((0, _color.includesHardCodedColor)(path.value.value) || (0, _color.isHardCodedColor)(path.value.value));
|
|
125
|
-
}).filter(function (path) {
|
|
126
|
-
return !(0, _ast.isDecendantOfToken)(j, path);
|
|
127
|
-
}).forEach(function (path) {
|
|
82
|
+
source.find(j.Literal).filter(path => typeof path.value.value === 'string' && ((0, _color.includesHardCodedColor)(path.value.value) || (0, _color.isHardCodedColor)(path.value.value))).filter(path => !(0, _ast.isDecendantOfToken)(j, path)).forEach(path => {
|
|
128
83
|
var _path$value, _path$value$value;
|
|
129
|
-
|
|
130
84
|
debug && console.log('file:', file.path);
|
|
131
85
|
insertTokenImport(j, source);
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
86
|
+
const value = path === null || path === void 0 ? void 0 : (_path$value = path.value) === null || _path$value === void 0 ? void 0 : (_path$value$value = _path$value.value) === null || _path$value$value === void 0 ? void 0 : _path$value$value.toString();
|
|
87
|
+
const colorMeta = _legacyColors.legacyColorMetaMap[value] || [];
|
|
88
|
+
const tokenId = getTokenFromNode(j, path, colorMeta);
|
|
89
|
+
const tokenNode = buildToken(j, tokenId, path.value);
|
|
136
90
|
j(path).replaceWith((0, _ast.isDecendantOfType)(j, path, j.JSXAttribute) ? j.jsxExpressionContainer(tokenNode) : tokenNode);
|
|
137
91
|
transformed = true;
|
|
138
92
|
});
|
|
139
|
-
|
|
140
93
|
if (transformed) {
|
|
141
94
|
return source.toSource();
|
|
142
95
|
}
|
|
143
|
-
|
|
144
96
|
return file.source;
|
|
145
97
|
}
|
|
@@ -1,48 +1,31 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
3
|
Object.defineProperty(exports, "__esModule", {
|
|
6
4
|
value: true
|
|
7
5
|
});
|
|
8
6
|
exports.cleanMeta = cleanMeta;
|
|
9
7
|
exports.getMetaFromAncestors = getMetaFromAncestors;
|
|
10
|
-
|
|
11
|
-
var _toConsumableArray2 = _interopRequireDefault(require("@babel/runtime/helpers/toConsumableArray"));
|
|
12
|
-
|
|
13
8
|
var _tokens = require("./tokens");
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
var parent = path.parentPath;
|
|
18
|
-
var grandParent = parent && parent.parentPath;
|
|
19
|
-
|
|
9
|
+
function getMetaFromAncestors(j, path, meta = []) {
|
|
10
|
+
const parent = path.parentPath;
|
|
11
|
+
const grandParent = parent && parent.parentPath;
|
|
20
12
|
if (parent && parent.value.type === 'ObjectProperty') {
|
|
21
|
-
|
|
22
|
-
|
|
13
|
+
let value = '';
|
|
23
14
|
if (parent.value.key.type === 'Literal' || parent.value.key.type === 'StringLiteral' || parent.value.key.type === 'NumericLiteral') {
|
|
24
15
|
value = parent.value.key.value.toString();
|
|
25
16
|
} else {
|
|
26
17
|
value = parent.value.key.name;
|
|
27
18
|
}
|
|
28
|
-
|
|
29
19
|
meta.push(value);
|
|
30
20
|
}
|
|
31
|
-
|
|
32
21
|
if (parent && grandParent && grandParent.value.type === 'TemplateLiteral') {
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
});
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
grandParent.value.quasis.slice(0, expressionIndex + 1).map(function (q) {
|
|
41
|
-
return q.value.cooked;
|
|
42
|
-
}) // We reverse so the most nested one is first which we're more likely than not interested in
|
|
43
|
-
.reverse().some(function (str) {
|
|
44
|
-
var result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
45
|
-
|
|
22
|
+
const expressionIndex = grandParent.value.expressions.findIndex(exp => exp.name === path.value.name);
|
|
23
|
+
const quasi = grandParent.value.quasis[expressionIndex];
|
|
24
|
+
const propertyName = (quasi.value.cooked || quasi.value.raw || '').replace(/\n/g, '').split(/;|{|}/).filter(el => !el.match(/\.|\@|\(|\)/)).pop().split(/:/g)[0].trim();
|
|
25
|
+
grandParent.value.quasis.slice(0, expressionIndex + 1).map(q => q.value.cooked)
|
|
26
|
+
// We reverse so the most nested one is first which we're more likely than not interested in
|
|
27
|
+
.reverse().some(str => {
|
|
28
|
+
const result = /(hover|active|disabled|focus)/.exec(str.toLowerCase());
|
|
46
29
|
if (result) {
|
|
47
30
|
meta.push(result[0]);
|
|
48
31
|
return true;
|
|
@@ -50,39 +33,29 @@ function getMetaFromAncestors(j, path) {
|
|
|
50
33
|
});
|
|
51
34
|
meta.push(propertyName);
|
|
52
35
|
}
|
|
53
|
-
|
|
54
36
|
if (parent && parent.value.type === 'JSXAttribute') {
|
|
55
37
|
if (!['css', 'styles', 'style'].includes(parent.value.name.name)) {
|
|
56
38
|
meta.push(parent.value.name.name);
|
|
57
39
|
}
|
|
58
40
|
}
|
|
59
|
-
|
|
60
41
|
if (parent && parent.value.type === 'VariableDeclarator') {
|
|
61
42
|
meta.push(parent.value.id.name);
|
|
62
43
|
}
|
|
63
|
-
|
|
64
44
|
if (parent) {
|
|
65
45
|
return getMetaFromAncestors(j, parent, meta);
|
|
66
46
|
}
|
|
67
|
-
|
|
68
47
|
return meta;
|
|
69
48
|
}
|
|
70
|
-
|
|
71
49
|
function cleanMeta(meta) {
|
|
72
|
-
return meta.reduce(
|
|
73
|
-
return [].concat((0, _toConsumableArray2.default)(accum), (0, _toConsumableArray2.default)(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(function (e) {
|
|
74
|
-
return e.toLowerCase();
|
|
75
|
-
}) : []));
|
|
76
|
-
}, []).reduce(function (accum, val) {
|
|
50
|
+
return meta.reduce((accum, val) => [...accum, ...(typeof val === 'string' ? val.split(/(?=[A-Z])/g).map(e => e.toLowerCase()) : [])], []).reduce((accum, val) => {
|
|
77
51
|
accum.push(val.replace(/:/g, '').replace(/,/g, '').replace('grey', 'neutral').replace('skeleton', 'neutral').replace('texts', 'text').replace('red', 'danger').replace('error', 'danger').replace('invalid', 'danger').replace('removed', 'danger').replace('removal', 'danger').replace('remove', 'danger').replace('focus', 'focused').replace('valid', 'success').replace('successful', 'success').replace('risk', 'warning').replace('caution', 'warning').replace('warn', 'warning').replace('primary', 'bold').replace('info', 'bold').replace('secondary', 'subtle').replace('hyperlink', 'link').replace('anchor', 'link').replace('active', 'pressed').replace('hover', 'hovered').replace('dragged', 'overlay').replace('dragging', 'overlay').replace('drag', 'overlay').replace('background-color', 'background').replace('color', 'text').replace('icons', 'icon').replace('glyph', 'icon').replace('stroke', 'border').replace('border-left', 'border').replace('border-right', 'border').replace('border-top', 'border').replace('border-bottom', 'border').replace('box-shadow', 'shadow'));
|
|
78
52
|
return accum;
|
|
79
|
-
}, []).filter(
|
|
53
|
+
}, []).filter(val => {
|
|
80
54
|
return _tokens.getUniqueWordsFromTokens.includes(val);
|
|
81
|
-
}).reduce(
|
|
55
|
+
}).reduce((accum, val) => {
|
|
82
56
|
if (!accum.includes(val)) {
|
|
83
57
|
accum.push(val);
|
|
84
58
|
}
|
|
85
|
-
|
|
86
59
|
return accum;
|
|
87
60
|
}, []);
|
|
88
61
|
}
|
|
@@ -5,7 +5,6 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.isDecendantOfToken = isDecendantOfToken;
|
|
7
7
|
exports.isDecendantOfType = isDecendantOfType;
|
|
8
|
-
|
|
9
8
|
function isDecendantOfToken(j, path) {
|
|
10
9
|
return j(path).closest(j.CallExpression, {
|
|
11
10
|
callee: {
|
|
@@ -13,7 +12,6 @@ function isDecendantOfToken(j, path) {
|
|
|
13
12
|
}
|
|
14
13
|
}).length > 0;
|
|
15
14
|
}
|
|
16
|
-
|
|
17
15
|
function isDecendantOfType(j, path, type) {
|
|
18
16
|
return j(path).closest(type).length > 0;
|
|
19
17
|
}
|
|
@@ -4,56 +4,37 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
6
|
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.includesHardCodedColor = void 0;
|
|
7
|
-
|
|
8
7
|
var _legacyColors = require("./legacy-colors");
|
|
9
|
-
|
|
10
8
|
var _namedColors = require("./named-colors");
|
|
11
|
-
|
|
12
|
-
var isLegacyColor = function isLegacyColor(value) {
|
|
13
|
-
return _legacyColors.legacyColors.includes(value);
|
|
14
|
-
};
|
|
15
|
-
|
|
9
|
+
const isLegacyColor = value => _legacyColors.legacyColors.includes(value);
|
|
16
10
|
exports.isLegacyColor = isLegacyColor;
|
|
17
|
-
|
|
18
|
-
var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
19
|
-
return _legacyColors.legacyColorMixins.includes(value);
|
|
20
|
-
};
|
|
21
|
-
|
|
11
|
+
const isLegacyNamedColor = value => _legacyColors.legacyColorMixins.includes(value);
|
|
22
12
|
exports.isLegacyNamedColor = isLegacyNamedColor;
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
var value = raw.toLowerCase();
|
|
26
|
-
|
|
13
|
+
const includesHardCodedColor = raw => {
|
|
14
|
+
const value = raw.toLowerCase();
|
|
27
15
|
if (/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|hsl)a?\([^\)]*\)/.exec(value.toLowerCase())) {
|
|
28
16
|
return true;
|
|
29
17
|
}
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
if (value.includes("".concat(_namedColors.namedColors[i], ";"))) {
|
|
18
|
+
for (let i = 0; i < _namedColors.namedColors.length; i++) {
|
|
19
|
+
if (value.includes(`${_namedColors.namedColors[i]};`)) {
|
|
33
20
|
return true;
|
|
34
21
|
}
|
|
35
22
|
}
|
|
36
|
-
|
|
37
23
|
return false;
|
|
38
24
|
};
|
|
39
|
-
|
|
40
25
|
exports.includesHardCodedColor = includesHardCodedColor;
|
|
41
|
-
|
|
42
|
-
var isHardCodedColor = function isHardCodedColor(value) {
|
|
26
|
+
const isHardCodedColor = value => {
|
|
43
27
|
if (_namedColors.namedColors.includes(value.toLowerCase())) {
|
|
44
28
|
return true;
|
|
45
29
|
}
|
|
46
|
-
|
|
47
30
|
if (value.startsWith('rgb(') || value.startsWith('rgba(') || value.startsWith('hsl(') || value.startsWith('hsla(') || value.startsWith('lch(') || value.startsWith('lab(') || value.startsWith('color(')) {
|
|
48
31
|
return true;
|
|
49
32
|
}
|
|
50
|
-
|
|
51
|
-
|
|
33
|
+
if (value.startsWith('#') && (
|
|
34
|
+
// short hex, hex, or hex with alpha
|
|
52
35
|
value.length === 4 || value.length === 7 || value.length === 9)) {
|
|
53
36
|
return true;
|
|
54
37
|
}
|
|
55
|
-
|
|
56
38
|
return false;
|
|
57
39
|
};
|
|
58
|
-
|
|
59
40
|
exports.isHardCodedColor = isHardCodedColor;
|