@atlaskit/codemod-cli 0.8.0 → 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 +26 -0
- package/README.md +12 -2
- package/dist/cjs/cli.js +3 -2
- package/dist/cjs/index.js +4 -4
- package/dist/cjs/main.js +6 -4
- 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/transforms.js +1 -1
- package/dist/cjs/types.js +5 -3
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/cli.js +3 -2
- package/dist/es2019/main.js +3 -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/cli.js +3 -2
- package/dist/esm/main.js +6 -4
- 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 +4 -2
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
var colorMap = {
|
|
8
|
+
resting: {
|
|
9
|
+
text: {
|
|
10
|
+
B300: ['color.text.selected', 'color.text.link.resting', 'color.iconBorder.brand'],
|
|
11
|
+
B400: ['color.text.selected', 'color.text.link.resting', 'color.iconBorder.brand'],
|
|
12
|
+
R300: ['color.text.danger', 'color.iconBorder.danger'],
|
|
13
|
+
R400: ['color.text.danger', 'color.iconBorder.danger'],
|
|
14
|
+
Y300: ['color.text.warning', 'color.iconBorder.warning'],
|
|
15
|
+
Y400: ['color.text.warning', 'color.iconBorder.warning'],
|
|
16
|
+
P300: ['color.text.discovery', 'color.iconBorder.discovery'],
|
|
17
|
+
P400: ['color.text.discovery', 'color.iconBorder.discovery'],
|
|
18
|
+
G300: ['color.text.success', 'color.iconBorder.success'],
|
|
19
|
+
G400: ['color.text.success', 'color.iconBorder.success'],
|
|
20
|
+
N0: ['color.text.onBold'],
|
|
21
|
+
N70: ['color.text.lowEmphasis'],
|
|
22
|
+
N80: ['color.text.lowEmphasis'],
|
|
23
|
+
N90: ['color.text.lowEmphasis'],
|
|
24
|
+
N100: ['color.text.lowEmphasis'],
|
|
25
|
+
N200: ['color.text.lowEmphasis'],
|
|
26
|
+
N300: ['color.text.lowEmphasis'],
|
|
27
|
+
N400: ['color.text.mediumEmphasis'],
|
|
28
|
+
N500: ['color.text.mediumEmphasis'],
|
|
29
|
+
N600: ['color.text.mediumEmphasis'],
|
|
30
|
+
N700: ['color.text.highEmphasis'],
|
|
31
|
+
N800: ['color.text.highEmphasis'],
|
|
32
|
+
N900: ['color.text.highEmphasis']
|
|
33
|
+
},
|
|
34
|
+
background: {
|
|
35
|
+
B75: ['color.background.selected.resting'],
|
|
36
|
+
N40: ['color.background.subtleNeutral.resting', 'color.background.sunken'],
|
|
37
|
+
B50: ['color.background.subtleBrand.resting', 'color.background.selected.resting'],
|
|
38
|
+
Y75: ['color.background.subtleWarning.resting'],
|
|
39
|
+
P50: ['color.background.subtleDiscovery.resting'],
|
|
40
|
+
R50: ['color.background.subtleDanger.resting'],
|
|
41
|
+
G50: ['color.background.subtleSuccess.resting'],
|
|
42
|
+
P300: ['color.background.boldDiscovery.resting'],
|
|
43
|
+
P400: ['color.background.boldDiscovery.resting'],
|
|
44
|
+
G300: ['color.background.boldSuccess.resting'],
|
|
45
|
+
Y300: ['color.background.boldWarning.resting'],
|
|
46
|
+
Y500: ['color.background.boldWarning.resting'],
|
|
47
|
+
R400: ['color.background.boldDanger.resting'],
|
|
48
|
+
B400: ['color.background.boldBrand.resting'],
|
|
49
|
+
N0: ['color.background.default', 'color.background.overlay', 'color.background.card']
|
|
50
|
+
},
|
|
51
|
+
border: {
|
|
52
|
+
N10: ['color.border.neutral'],
|
|
53
|
+
N20: ['color.border.neutral'],
|
|
54
|
+
N30: ['color.border.neutral'],
|
|
55
|
+
N40: ['color.border.neutral'],
|
|
56
|
+
N50: ['color.border.neutral'],
|
|
57
|
+
N60: ['color.border.neutral'],
|
|
58
|
+
N70: ['color.border.neutral'],
|
|
59
|
+
B100: ['color.border.focus'],
|
|
60
|
+
B300: ['color.iconBorder.brand', 'color.text.selected'],
|
|
61
|
+
B400: ['color.iconBorder.brand', 'color.text.selected'],
|
|
62
|
+
R300: ['color.iconBorder.danger'],
|
|
63
|
+
R400: ['color.iconBorder.danger'],
|
|
64
|
+
Y300: ['color.iconBorder.warning'],
|
|
65
|
+
Y400: ['color.iconBorder.warning'],
|
|
66
|
+
P300: ['color.iconBorder.discovery'],
|
|
67
|
+
P400: ['color.iconBorder.discovery'],
|
|
68
|
+
G300: ['color.iconBorder.success'],
|
|
69
|
+
G400: ['color.iconBorder.success']
|
|
70
|
+
}
|
|
71
|
+
},
|
|
72
|
+
hover: {
|
|
73
|
+
text: {
|
|
74
|
+
B300: ['color.text.link.resting'],
|
|
75
|
+
B400: ['color.text.link.resting']
|
|
76
|
+
},
|
|
77
|
+
background: {
|
|
78
|
+
B50: ['color.background.selected.hover'],
|
|
79
|
+
B75: ['color.background.selected.hover'],
|
|
80
|
+
P200: ['color.background.boldDiscovery.hover'],
|
|
81
|
+
P300: ['color.background.boldDiscovery.hover'],
|
|
82
|
+
G200: ['color.background.boldSuccess.hover'],
|
|
83
|
+
R300: ['color.background.boldDanger.hover'],
|
|
84
|
+
Y200: ['color.background.boldWarning.hover'],
|
|
85
|
+
B300: ['color.background.boldBrand.hover']
|
|
86
|
+
},
|
|
87
|
+
border: {}
|
|
88
|
+
},
|
|
89
|
+
pressed: {
|
|
90
|
+
text: {
|
|
91
|
+
B300: ['color.text.link.pressed'],
|
|
92
|
+
B400: ['color.text.link.pressed']
|
|
93
|
+
},
|
|
94
|
+
background: {
|
|
95
|
+
B50: ['color.background.selected.pressed'],
|
|
96
|
+
B75: ['color.background.selected.pressed'],
|
|
97
|
+
P400: ['color.background.boldDiscovery.pressed'],
|
|
98
|
+
P500: ['color.background.boldDiscovery.pressed'],
|
|
99
|
+
G400: ['color.background.boldSuccess.pressed'],
|
|
100
|
+
R500: ['color.background.boldDanger.pressed'],
|
|
101
|
+
Y400: ['color.background.boldWarning.pressed'],
|
|
102
|
+
B500: ['color.background.boldBrand.pressed']
|
|
103
|
+
},
|
|
104
|
+
border: {}
|
|
105
|
+
},
|
|
106
|
+
disabled: {
|
|
107
|
+
text: {
|
|
108
|
+
N60: ['color.text.disabled'],
|
|
109
|
+
N70: ['color.text.disabled'],
|
|
110
|
+
N80: ['color.text.disabled'],
|
|
111
|
+
N90: ['color.text.disabled'],
|
|
112
|
+
N100: ['color.text.disabled']
|
|
113
|
+
},
|
|
114
|
+
background: {
|
|
115
|
+
N10: ['color.background.disabled'],
|
|
116
|
+
N20: ['color.background.disabled'],
|
|
117
|
+
N30: ['color.background.disabled'],
|
|
118
|
+
N40: ['color.background.disabled']
|
|
119
|
+
},
|
|
120
|
+
border: {
|
|
121
|
+
N10: ['color.background.disabled'],
|
|
122
|
+
N20: ['color.background.disabled'],
|
|
123
|
+
N30: ['color.background.disabled'],
|
|
124
|
+
N40: ['color.background.disabled']
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
};
|
|
128
|
+
var _default = colorMap;
|
|
129
|
+
exports.default = _default;
|
|
@@ -0,0 +1,88 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = colorToToken;
|
|
9
|
+
|
|
10
|
+
var _colorDifference = require("./color-difference");
|
|
11
|
+
|
|
12
|
+
var _colorPaletteTokensMap = _interopRequireDefault(require("./color-palette-tokens-map"));
|
|
13
|
+
|
|
14
|
+
function normalizeName(name) {
|
|
15
|
+
if (!name) {
|
|
16
|
+
return 'unknown';
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
if (name.startsWith('background')) {
|
|
20
|
+
return 'background';
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
if (name.toLowerCase().includes('color') || name === 'color' || name === 'fill' || name === 'stroke') {
|
|
24
|
+
return 'text';
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
if (name.startsWith('border') || name.toLowerCase().replace('-', '') === 'boxshadow') {
|
|
28
|
+
return 'border';
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return 'unknown';
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
function colorToToken(paletteName, _ref) {
|
|
35
|
+
var _ref$state = _ref.state,
|
|
36
|
+
state = _ref$state === void 0 ? 'resting' : _ref$state,
|
|
37
|
+
propertyName = _ref.propertyName;
|
|
38
|
+
var getLowConfidenceFuzzyResult = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : function () {
|
|
39
|
+
return [];
|
|
40
|
+
};
|
|
41
|
+
var normalizedPropertyName = normalizeName(propertyName);
|
|
42
|
+
var value = paletteName.toUpperCase();
|
|
43
|
+
var tokenSuggestionProperties = _colorPaletteTokensMap.default[state];
|
|
44
|
+
var tokenSuggestionProperty = tokenSuggestionProperties && normalizedPropertyName !== 'unknown' && tokenSuggestionProperties[normalizedPropertyName];
|
|
45
|
+
var tokenSuggestionValue = tokenSuggestionProperty && tokenSuggestionProperty[value];
|
|
46
|
+
|
|
47
|
+
if (tokenSuggestionValue && tokenSuggestionValue.length === 1) {
|
|
48
|
+
return {
|
|
49
|
+
confidence: 'high',
|
|
50
|
+
suggestion: tokenSuggestionValue,
|
|
51
|
+
fallbackNeeded: true
|
|
52
|
+
};
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (tokenSuggestionValue && tokenSuggestionValue.length > 2) {
|
|
56
|
+
return {
|
|
57
|
+
confidence: 'medium',
|
|
58
|
+
suggestion: tokenSuggestionValue,
|
|
59
|
+
fallbackNeeded: true
|
|
60
|
+
};
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
var closestTokenName = (0, _colorDifference.findClosetMatchingToken)(value);
|
|
64
|
+
|
|
65
|
+
if (closestTokenName) {
|
|
66
|
+
return {
|
|
67
|
+
confidence: 'low',
|
|
68
|
+
suggestion: [closestTokenName],
|
|
69
|
+
fallbackNeeded: true
|
|
70
|
+
};
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
var fuzzyResult = getLowConfidenceFuzzyResult();
|
|
74
|
+
|
|
75
|
+
if (fuzzyResult.length) {
|
|
76
|
+
return {
|
|
77
|
+
confidence: 'low',
|
|
78
|
+
suggestion: fuzzyResult,
|
|
79
|
+
fallbackNeeded: true
|
|
80
|
+
};
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
return {
|
|
84
|
+
confidence: 'unknown',
|
|
85
|
+
suggestion: [],
|
|
86
|
+
fallbackNeeded: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.isLegacyNamedColor = exports.isLegacyColor = exports.isHardCodedColor = exports.includesHardCodedColor = void 0;
|
|
7
|
+
|
|
8
|
+
var _legacyColors = require("./legacy-colors");
|
|
9
|
+
|
|
10
|
+
var _namedColors = require("./named-colors");
|
|
11
|
+
|
|
12
|
+
var isLegacyColor = function isLegacyColor(value) {
|
|
13
|
+
return _legacyColors.legacyColors.includes(value);
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
exports.isLegacyColor = isLegacyColor;
|
|
17
|
+
|
|
18
|
+
var isLegacyNamedColor = function isLegacyNamedColor(value) {
|
|
19
|
+
return _legacyColors.legacyColorMixins.includes(value);
|
|
20
|
+
};
|
|
21
|
+
|
|
22
|
+
exports.isLegacyNamedColor = isLegacyNamedColor;
|
|
23
|
+
|
|
24
|
+
var includesHardCodedColor = function includesHardCodedColor(raw) {
|
|
25
|
+
var value = raw.toLowerCase();
|
|
26
|
+
|
|
27
|
+
if (/#(?:[a-f0-9]{3}|[a-f0-9]{6}|[a-f0-9]{8})\b|(?:rgb|hsl)a?\([^\)]*\)/.exec(value.toLowerCase())) {
|
|
28
|
+
return true;
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
for (var i = 0; i < _namedColors.namedColors.length; i++) {
|
|
32
|
+
if (value.includes("".concat(_namedColors.namedColors[i], ";"))) {
|
|
33
|
+
return true;
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
return false;
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
exports.includesHardCodedColor = includesHardCodedColor;
|
|
41
|
+
|
|
42
|
+
var isHardCodedColor = function isHardCodedColor(value) {
|
|
43
|
+
if (_namedColors.namedColors.includes(value.toLowerCase())) {
|
|
44
|
+
return true;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
if (value.startsWith('rgb(') || value.startsWith('rgba(') || value.startsWith('hsl(') || value.startsWith('hsla(') || value.startsWith('lch(') || value.startsWith('lab(') || value.startsWith('color(')) {
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
if (value.startsWith('#') && ( // short hex, hex, or hex with alpha
|
|
52
|
+
value.length === 4 || value.length === 7 || value.length === 9)) {
|
|
53
|
+
return true;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return false;
|
|
57
|
+
};
|
|
58
|
+
|
|
59
|
+
exports.isHardCodedColor = isHardCodedColor;
|
|
@@ -0,0 +1,348 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = void 0;
|
|
7
|
+
|
|
8
|
+
/* eslint-disable */
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Fuzzy search ripped from the internet.
|
|
12
|
+
*/
|
|
13
|
+
var FuzzySet = function FuzzySet() {
|
|
14
|
+
var arr = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
15
|
+
var useLevenshtein = arguments.length > 1 ? arguments[1] : undefined;
|
|
16
|
+
var gramSizeLower = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : 2;
|
|
17
|
+
var gramSizeUpper = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : 3;
|
|
18
|
+
var fuzzyset = {
|
|
19
|
+
gramSizeLower: gramSizeLower,
|
|
20
|
+
gramSizeUpper: gramSizeUpper,
|
|
21
|
+
useLevenshtein: typeof useLevenshtein !== 'boolean' ? true : useLevenshtein,
|
|
22
|
+
exactSet: {},
|
|
23
|
+
matchDict: {},
|
|
24
|
+
items: {}
|
|
25
|
+
};
|
|
26
|
+
|
|
27
|
+
var levenshtein = function levenshtein(str1, str2) {
|
|
28
|
+
var current = [];
|
|
29
|
+
var prev;
|
|
30
|
+
var value;
|
|
31
|
+
|
|
32
|
+
for (var i = 0; i <= str2.length; i++) {
|
|
33
|
+
for (var j = 0; j <= str1.length; j++) {
|
|
34
|
+
if (i && j) {
|
|
35
|
+
if (str1.charAt(j - 1) === str2.charAt(i - 1)) {
|
|
36
|
+
// @ts-expect-error
|
|
37
|
+
value = prev;
|
|
38
|
+
} else {
|
|
39
|
+
// @ts-expect-error
|
|
40
|
+
value = Math.min(current[j], current[j - 1], prev) + 1;
|
|
41
|
+
}
|
|
42
|
+
} else {
|
|
43
|
+
value = i + j;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
prev = current[j];
|
|
47
|
+
current[j] = value;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
return current.pop();
|
|
52
|
+
}; // return an edit distance from 0 to 1
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
var _distance = function _distance(str1, str2) {
|
|
56
|
+
if (str1 === null && str2 === null) {
|
|
57
|
+
throw new Error('Trying to compare two null values');
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
if (str1 === null || str2 === null) {
|
|
61
|
+
return 0;
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
str1 = String(str1);
|
|
65
|
+
str2 = String(str2);
|
|
66
|
+
var distance = levenshtein(str1, str2);
|
|
67
|
+
|
|
68
|
+
if (str1.length > str2.length) {
|
|
69
|
+
return 1 - distance / str1.length;
|
|
70
|
+
} else {
|
|
71
|
+
return 1 - distance / str2.length;
|
|
72
|
+
}
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
var _nonWordRe = /[^a-zA-Z0-9\u00C0-\u00FF, ]+/g;
|
|
76
|
+
|
|
77
|
+
var _iterateGrams = function _iterateGrams(value, gramSize) {
|
|
78
|
+
gramSize = gramSize || 2;
|
|
79
|
+
var simplified = '-' + value.toLowerCase().replace(_nonWordRe, '') + '-',
|
|
80
|
+
lenDiff = gramSize - simplified.length,
|
|
81
|
+
results = [];
|
|
82
|
+
|
|
83
|
+
if (lenDiff > 0) {
|
|
84
|
+
for (var i = 0; i < lenDiff; ++i) {
|
|
85
|
+
simplified += '-';
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
for (var i = 0; i < simplified.length - gramSize + 1; ++i) {
|
|
90
|
+
results.push(simplified.slice(i, i + gramSize));
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
return results;
|
|
94
|
+
};
|
|
95
|
+
|
|
96
|
+
var _gramCounter = function _gramCounter(value, gramSize) {
|
|
97
|
+
// return an object where key=gram, value=number of occurrences
|
|
98
|
+
gramSize = gramSize || 2;
|
|
99
|
+
|
|
100
|
+
var result = {},
|
|
101
|
+
grams = _iterateGrams(value, gramSize),
|
|
102
|
+
i = 0;
|
|
103
|
+
|
|
104
|
+
for (i; i < grams.length; ++i) {
|
|
105
|
+
if (grams[i] in result) {
|
|
106
|
+
// @ts-expect-error
|
|
107
|
+
result[grams[i]] += 1;
|
|
108
|
+
} else {
|
|
109
|
+
// @ts-expect-error
|
|
110
|
+
result[grams[i]] = 1;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
return result;
|
|
115
|
+
}; // the main functions
|
|
116
|
+
|
|
117
|
+
|
|
118
|
+
fuzzyset.get = function (value, defaultValue, minMatchScore) {
|
|
119
|
+
// check for value in set, returning defaultValue or null if none found
|
|
120
|
+
if (minMatchScore === undefined) {
|
|
121
|
+
minMatchScore = 0.33;
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
var result = this._get(value, minMatchScore);
|
|
125
|
+
|
|
126
|
+
if (!result && typeof defaultValue !== 'undefined') {
|
|
127
|
+
return defaultValue;
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
return result;
|
|
131
|
+
};
|
|
132
|
+
|
|
133
|
+
fuzzyset._get = function (value, minMatchScore) {
|
|
134
|
+
var results = []; // start with high gram size and if there are no results, go to lower gram sizes
|
|
135
|
+
|
|
136
|
+
for (var gramSize = this.gramSizeUpper; gramSize >= this.gramSizeLower; --gramSize) {
|
|
137
|
+
results = this.__get(value, gramSize, minMatchScore);
|
|
138
|
+
|
|
139
|
+
if (results && results.length > 0) {
|
|
140
|
+
return results;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return null;
|
|
145
|
+
};
|
|
146
|
+
|
|
147
|
+
fuzzyset.__get = function (value, gramSize, minMatchScore) {
|
|
148
|
+
var normalizedValue = this._normalizeStr(value),
|
|
149
|
+
matches = {},
|
|
150
|
+
gramCounts = _gramCounter(normalizedValue, gramSize),
|
|
151
|
+
items = this.items[gramSize],
|
|
152
|
+
sumOfSquareGramCounts = 0,
|
|
153
|
+
gram,
|
|
154
|
+
gramCount,
|
|
155
|
+
i,
|
|
156
|
+
index,
|
|
157
|
+
otherGramCount;
|
|
158
|
+
|
|
159
|
+
for (gram in gramCounts) {
|
|
160
|
+
// @ts-expect-error
|
|
161
|
+
gramCount = gramCounts[gram];
|
|
162
|
+
sumOfSquareGramCounts += Math.pow(gramCount, 2);
|
|
163
|
+
|
|
164
|
+
if (gram in this.matchDict) {
|
|
165
|
+
for (i = 0; i < this.matchDict[gram].length; ++i) {
|
|
166
|
+
index = this.matchDict[gram][i][0];
|
|
167
|
+
otherGramCount = this.matchDict[gram][i][1];
|
|
168
|
+
|
|
169
|
+
if (index in matches) {
|
|
170
|
+
// @ts-expect-error
|
|
171
|
+
matches[index] += gramCount * otherGramCount;
|
|
172
|
+
} else {
|
|
173
|
+
// @ts-expect-error
|
|
174
|
+
matches[index] = gramCount * otherGramCount;
|
|
175
|
+
}
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
function isEmptyObject(obj) {
|
|
181
|
+
for (var prop in obj) {
|
|
182
|
+
if (obj.hasOwnProperty(prop)) {
|
|
183
|
+
return false;
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
|
|
187
|
+
return true;
|
|
188
|
+
}
|
|
189
|
+
|
|
190
|
+
if (isEmptyObject(matches)) {
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
var vectorNormal = Math.sqrt(sumOfSquareGramCounts),
|
|
195
|
+
results = [],
|
|
196
|
+
matchScore; // build a results list of [score, str]
|
|
197
|
+
|
|
198
|
+
for (var matchIndex in matches) {
|
|
199
|
+
// @ts-expect-error
|
|
200
|
+
matchScore = matches[matchIndex];
|
|
201
|
+
results.push([matchScore / (vectorNormal * items[matchIndex][0]), items[matchIndex][1]]);
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
var sortDescending = function sortDescending(a, b) {
|
|
205
|
+
if (a[0] < b[0]) {
|
|
206
|
+
return 1;
|
|
207
|
+
} else if (a[0] > b[0]) {
|
|
208
|
+
return -1;
|
|
209
|
+
} else {
|
|
210
|
+
return 0;
|
|
211
|
+
}
|
|
212
|
+
};
|
|
213
|
+
|
|
214
|
+
results.sort(sortDescending);
|
|
215
|
+
|
|
216
|
+
if (this.useLevenshtein) {
|
|
217
|
+
var newResults = [],
|
|
218
|
+
endIndex = Math.min(50, results.length); // truncate somewhat arbitrarily to 50
|
|
219
|
+
// @ts-expect-error
|
|
220
|
+
|
|
221
|
+
for (var i = 0; i < endIndex; ++i) {
|
|
222
|
+
// @ts-expect-error
|
|
223
|
+
newResults.push([_distance(results[i][1], normalizedValue), results[i][1]]);
|
|
224
|
+
}
|
|
225
|
+
|
|
226
|
+
results = newResults;
|
|
227
|
+
results.sort(sortDescending);
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
newResults = [];
|
|
231
|
+
results.forEach(function (scoreWordPair) {
|
|
232
|
+
if (scoreWordPair[0] >= minMatchScore) {
|
|
233
|
+
// @ts-expect-error
|
|
234
|
+
newResults.push([scoreWordPair[0], this.exactSet[scoreWordPair[1]]]);
|
|
235
|
+
}
|
|
236
|
+
}.bind(this));
|
|
237
|
+
return newResults;
|
|
238
|
+
};
|
|
239
|
+
|
|
240
|
+
fuzzyset.add = function (value) {
|
|
241
|
+
var normalizedValue = this._normalizeStr(value);
|
|
242
|
+
|
|
243
|
+
if (normalizedValue in this.exactSet) {
|
|
244
|
+
return false;
|
|
245
|
+
}
|
|
246
|
+
|
|
247
|
+
var i = this.gramSizeLower;
|
|
248
|
+
|
|
249
|
+
for (i; i < this.gramSizeUpper + 1; ++i) {
|
|
250
|
+
this._add(value, i);
|
|
251
|
+
}
|
|
252
|
+
};
|
|
253
|
+
|
|
254
|
+
fuzzyset._add = function (value, gramSize) {
|
|
255
|
+
var normalizedValue = this._normalizeStr(value),
|
|
256
|
+
items = this.items[gramSize] || [],
|
|
257
|
+
index = items.length;
|
|
258
|
+
|
|
259
|
+
items.push(0);
|
|
260
|
+
|
|
261
|
+
var gramCounts = _gramCounter(normalizedValue, gramSize);
|
|
262
|
+
|
|
263
|
+
var sumOfSquareGramCounts = 0;
|
|
264
|
+
var gram;
|
|
265
|
+
var gramCount;
|
|
266
|
+
|
|
267
|
+
for (gram in gramCounts) {
|
|
268
|
+
// @ts-expect-error
|
|
269
|
+
gramCount = gramCounts[gram];
|
|
270
|
+
sumOfSquareGramCounts += Math.pow(gramCount, 2);
|
|
271
|
+
|
|
272
|
+
if (gram in this.matchDict) {
|
|
273
|
+
this.matchDict[gram].push([index, gramCount]);
|
|
274
|
+
} else {
|
|
275
|
+
this.matchDict[gram] = [[index, gramCount]];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
|
|
279
|
+
var vectorNormal = Math.sqrt(sumOfSquareGramCounts);
|
|
280
|
+
items[index] = [vectorNormal, normalizedValue];
|
|
281
|
+
this.items[gramSize] = items;
|
|
282
|
+
this.exactSet[normalizedValue] = value;
|
|
283
|
+
};
|
|
284
|
+
|
|
285
|
+
fuzzyset._normalizeStr = function (str) {
|
|
286
|
+
if (Object.prototype.toString.call(str) !== '[object String]') {
|
|
287
|
+
throw new Error('Must use a string as argument to FuzzySet functions');
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
return str.toLowerCase();
|
|
291
|
+
}; // return length of items in set
|
|
292
|
+
|
|
293
|
+
|
|
294
|
+
fuzzyset.length = function () {
|
|
295
|
+
var count = 0,
|
|
296
|
+
prop;
|
|
297
|
+
|
|
298
|
+
for (prop in this.exactSet) {
|
|
299
|
+
if (this.exactSet.hasOwnProperty(prop)) {
|
|
300
|
+
count += 1;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
return count;
|
|
305
|
+
}; // return is set is empty
|
|
306
|
+
|
|
307
|
+
|
|
308
|
+
fuzzyset.isEmpty = function () {
|
|
309
|
+
for (var prop in this.exactSet) {
|
|
310
|
+
if (this.exactSet.hasOwnProperty(prop)) {
|
|
311
|
+
return false;
|
|
312
|
+
}
|
|
313
|
+
}
|
|
314
|
+
|
|
315
|
+
return true;
|
|
316
|
+
}; // return list of values loaded into set
|
|
317
|
+
|
|
318
|
+
|
|
319
|
+
fuzzyset.values = function () {
|
|
320
|
+
var values = [],
|
|
321
|
+
prop;
|
|
322
|
+
|
|
323
|
+
for (prop in this.exactSet) {
|
|
324
|
+
if (this.exactSet.hasOwnProperty(prop)) {
|
|
325
|
+
values.push(this.exactSet[prop]);
|
|
326
|
+
}
|
|
327
|
+
}
|
|
328
|
+
|
|
329
|
+
return values;
|
|
330
|
+
}; // initialization
|
|
331
|
+
|
|
332
|
+
|
|
333
|
+
var i = fuzzyset.gramSizeLower;
|
|
334
|
+
|
|
335
|
+
for (i; i < fuzzyset.gramSizeUpper + 1; ++i) {
|
|
336
|
+
fuzzyset.items[i] = [];
|
|
337
|
+
} // add all the items to the set
|
|
338
|
+
|
|
339
|
+
|
|
340
|
+
for (i = 0; i < arr.length; ++i) {
|
|
341
|
+
fuzzyset.add(arr[i]);
|
|
342
|
+
}
|
|
343
|
+
|
|
344
|
+
return fuzzyset;
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
var _default = FuzzySet;
|
|
348
|
+
exports.default = _default;
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.legacyColors = exports.legacyColorMixins = exports.legacyColorMetaMap = void 0;
|
|
7
|
+
var legacyColors = ['R50', 'R75', 'R100', 'R200', 'R300', 'R400', 'R500', 'Y50', 'Y75', 'Y100', 'Y200', 'Y300', 'Y400', 'Y500', 'G50', 'G75', 'G100', 'G200', 'G300', 'G400', 'G500', 'B50', 'B75', 'B100', 'B200', 'B300', 'B400', 'B500', 'P50', 'P75', 'P100', 'P200', 'P300', 'P400', 'P500', 'T50', 'T75', 'T100', 'T200', 'T300', 'T400', 'T500', 'N0', 'N10', 'N20', 'N30', 'N40', 'N50', 'N60', 'N70', 'N80', 'N90', 'N100', 'N200', 'N300', 'N400', 'N500', 'N600', 'N700', 'N800', 'N900', 'N10A', 'N20A', 'N30A', 'N40A', 'N50A', 'N60A', 'N70A', 'N80A', 'N90A', 'N100A', 'N200A', 'N300A', 'N400A', 'N500A', 'N600A', 'N700A', 'N800A', 'DN900', 'DN800', 'DN700', 'DN600', 'DN500', 'DN400', 'DN300', 'DN200', 'DN100', 'DN90', 'DN80', 'DN70', 'DN60', 'DN50', 'DN40', 'DN30', 'DN20', 'DN10', 'DN0', 'DN800A', 'DN700A', 'DN600A', 'DN500A', 'DN400A', 'DN300A', 'DN200A', 'DN100A', 'DN90A', 'DN80A', 'DN70A', 'DN60A', 'DN50A', 'DN40A', 'DN30A', 'DN20A', 'DN10A'];
|
|
8
|
+
exports.legacyColors = legacyColors;
|
|
9
|
+
var legacyColorMixins = ['background', 'backgroundActive', 'backgroundHover', 'backgroundOnLayer', 'text', 'textHover', 'textActive', 'subtleText', 'placeholderText', 'heading', 'subtleHeading', 'codeBlock', 'link', 'linkHover', 'linkActive', 'linkOutline', 'primary', 'blue', 'teal', 'purple', 'red', 'yellow', 'green', 'skeleton'];
|
|
10
|
+
exports.legacyColorMixins = legacyColorMixins;
|
|
11
|
+
var legacyColorMetaMap = {
|
|
12
|
+
R50: ['danger'],
|
|
13
|
+
R75: ['danger'],
|
|
14
|
+
R100: ['danger'],
|
|
15
|
+
R200: ['danger'],
|
|
16
|
+
R300: ['danger'],
|
|
17
|
+
R400: ['danger'],
|
|
18
|
+
R500: ['danger'],
|
|
19
|
+
Y50: ['warning'],
|
|
20
|
+
Y75: ['warning'],
|
|
21
|
+
Y100: ['warning'],
|
|
22
|
+
Y200: ['warning'],
|
|
23
|
+
Y300: ['warning'],
|
|
24
|
+
Y400: ['warning'],
|
|
25
|
+
Y500: ['warning'],
|
|
26
|
+
G50: ['success'],
|
|
27
|
+
G75: ['success'],
|
|
28
|
+
G100: ['success'],
|
|
29
|
+
G200: ['success'],
|
|
30
|
+
G300: ['success'],
|
|
31
|
+
G400: ['success'],
|
|
32
|
+
G500: ['success'],
|
|
33
|
+
B50: ['brand'],
|
|
34
|
+
B75: ['brand'],
|
|
35
|
+
B100: ['brand'],
|
|
36
|
+
B200: ['brand'],
|
|
37
|
+
B300: ['brand'],
|
|
38
|
+
B400: ['brand'],
|
|
39
|
+
B500: ['brand'],
|
|
40
|
+
P50: ['discovery'],
|
|
41
|
+
P75: ['discovery'],
|
|
42
|
+
P100: ['discovery'],
|
|
43
|
+
P200: ['discovery'],
|
|
44
|
+
P300: ['discovery'],
|
|
45
|
+
P400: ['discovery'],
|
|
46
|
+
P500: ['discovery'],
|
|
47
|
+
T50: ['accent', 'teal'],
|
|
48
|
+
T75: ['accent', 'teal'],
|
|
49
|
+
T100: ['accent', 'teal'],
|
|
50
|
+
T200: ['accent', 'teal'],
|
|
51
|
+
T300: ['accent', 'teal'],
|
|
52
|
+
T400: ['accent', 'teal'],
|
|
53
|
+
T500: ['accent', 'teal'],
|
|
54
|
+
N0: ['onBold'],
|
|
55
|
+
N800: ['text'],
|
|
56
|
+
background: ['background', 'default'],
|
|
57
|
+
backgroundActive: ['background', 'selected'],
|
|
58
|
+
backgroundHover: ['background', 'hovered'],
|
|
59
|
+
backgroundOnLayer: ['background', 'blanket'],
|
|
60
|
+
text: ['text'],
|
|
61
|
+
textHover: ['text', 'subtle'],
|
|
62
|
+
textActive: ['text', 'link', 'pressed'],
|
|
63
|
+
subtleText: ['text', 'subtlest'],
|
|
64
|
+
placeholderText: ['text', 'subtlest'],
|
|
65
|
+
heading: ['text'],
|
|
66
|
+
subtleHeading: ['text', 'subtle'],
|
|
67
|
+
link: ['text', 'link'],
|
|
68
|
+
linkHover: ['text', 'link', 'hovered'],
|
|
69
|
+
linkActive: ['text', 'link', 'pressed'],
|
|
70
|
+
linkOutline: ['border', 'selected'],
|
|
71
|
+
primary: ['brand'],
|
|
72
|
+
blue: ['accent', 'blue'],
|
|
73
|
+
teal: ['accent', 'teal'],
|
|
74
|
+
purple: ['accent', 'purple'],
|
|
75
|
+
red: ['accent', 'red'],
|
|
76
|
+
yellow: ['accent', 'orange'],
|
|
77
|
+
green: ['accent', 'green'],
|
|
78
|
+
grey: ['background', 'neutral'],
|
|
79
|
+
skeleton: ['background', 'neutral']
|
|
80
|
+
};
|
|
81
|
+
exports.legacyColorMetaMap = legacyColorMetaMap;
|