@workday/canvas-kit-codemod 14.0.0-alpha.1151-next.0 → 14.0.0-alpha.1156-next.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 (43) hide show
  1. package/dist/es6/v13.2/index.d.ts +4 -0
  2. package/dist/es6/v13.2/index.d.ts.map +1 -0
  3. package/dist/es6/v13.2/index.js +9 -0
  4. package/dist/es6/v13.2/mapping/index.d.ts +234 -0
  5. package/dist/es6/v13.2/mapping/index.d.ts.map +1 -0
  6. package/dist/es6/v13.2/mapping/index.js +166 -0
  7. package/dist/es6/v13.2/mapping/typeProps.d.ts +2 -0
  8. package/dist/es6/v13.2/mapping/typeProps.d.ts.map +1 -0
  9. package/dist/es6/v13.2/mapping/typeProps.js +1 -0
  10. package/dist/es6/v13.2/migrateColorTokens.d.ts +4 -0
  11. package/dist/es6/v13.2/migrateColorTokens.d.ts.map +1 -0
  12. package/dist/es6/v13.2/migrateColorTokens.js +62 -0
  13. package/dist/es6/v13.2/migrateDepthTokens.d.ts +4 -0
  14. package/dist/es6/v13.2/migrateDepthTokens.d.ts.map +1 -0
  15. package/dist/es6/v13.2/migrateDepthTokens.js +101 -0
  16. package/dist/es6/v13.2/migrateOtherTokens.d.ts +4 -0
  17. package/dist/es6/v13.2/migrateOtherTokens.d.ts.map +1 -0
  18. package/dist/es6/v13.2/migrateOtherTokens.js +109 -0
  19. package/dist/es6/v13.2/migrateTypeTokens.d.ts +4 -0
  20. package/dist/es6/v13.2/migrateTypeTokens.d.ts.map +1 -0
  21. package/dist/es6/v13.2/migrateTypeTokens.js +136 -0
  22. package/dist/es6/v13.2/utils/addMissingImports.d.ts +2 -0
  23. package/dist/es6/v13.2/utils/addMissingImports.d.ts.map +1 -0
  24. package/dist/es6/v13.2/utils/addMissingImports.js +30 -0
  25. package/dist/es6/v13.2/utils/expectTransformFactory.d.ts +3 -0
  26. package/dist/es6/v13.2/utils/expectTransformFactory.d.ts.map +1 -0
  27. package/dist/es6/v13.2/utils/expectTransformFactory.js +4 -0
  28. package/dist/es6/v13.2/utils/filterOutImports.d.ts +3 -0
  29. package/dist/es6/v13.2/utils/filterOutImports.d.ts.map +1 -0
  30. package/dist/es6/v13.2/utils/filterOutImports.js +19 -0
  31. package/dist/es6/v13.2/utils/generateLevelTokens.d.ts +8 -0
  32. package/dist/es6/v13.2/utils/generateLevelTokens.d.ts.map +1 -0
  33. package/dist/es6/v13.2/utils/generateLevelTokens.js +20 -0
  34. package/dist/es6/v13.2/utils/index.d.ts +7 -0
  35. package/dist/es6/v13.2/utils/index.d.ts.map +1 -0
  36. package/dist/es6/v13.2/utils/index.js +6 -0
  37. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts +4 -0
  38. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.d.ts.map +1 -0
  39. package/dist/es6/v13.2/utils/transformObjectPropertyRecursively.js +74 -0
  40. package/dist/es6/v13.2/utils/varToMemberExpression.d.ts +2 -0
  41. package/dist/es6/v13.2/utils/varToMemberExpression.d.ts.map +1 -0
  42. package/dist/es6/v13.2/utils/varToMemberExpression.js +9 -0
  43. package/package.json +2 -2
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAMtC,QAAA,MAAM,SAAS,EAAE,SAGhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,9 @@
1
+ import migrateColorTokens from './migrateColorTokens';
2
+ import migrateDepthTokens from './migrateDepthTokens';
3
+ import migrateOtherTokens from './migrateOtherTokens';
4
+ import migrateTypeTokens from './migrateTypeTokens';
5
+ const transform = (file, api, options) => {
6
+ const fixes = [migrateColorTokens, migrateDepthTokens, migrateTypeTokens, migrateOtherTokens];
7
+ return fixes.reduce((source, fix) => fix({ ...file, source }, api, options), file.source);
8
+ };
9
+ export default transform;
@@ -0,0 +1,234 @@
1
+ export declare const mapping: {
2
+ readonly colors: {
3
+ readonly type: "base";
4
+ readonly name: "colors";
5
+ };
6
+ readonly borderRadius: {
7
+ readonly name: "shape";
8
+ readonly type: "system";
9
+ readonly keys: {
10
+ zero: string;
11
+ s: string;
12
+ m: string;
13
+ l: string;
14
+ circle: string;
15
+ };
16
+ };
17
+ readonly space: {
18
+ readonly name: "space";
19
+ readonly type: "system";
20
+ readonly keys: {
21
+ zero: string;
22
+ xxxs: string;
23
+ xxs: string;
24
+ xs: string;
25
+ s: string;
26
+ m: string;
27
+ l: string;
28
+ xl: string;
29
+ xxl: string;
30
+ xxxl: string;
31
+ };
32
+ };
33
+ readonly type: {
34
+ readonly type: "system";
35
+ readonly name: "type";
36
+ readonly keys: {
37
+ fontFamilies: {
38
+ name: string;
39
+ values: {
40
+ default: string;
41
+ monospace: string;
42
+ };
43
+ };
44
+ fontSizes: {
45
+ name: string;
46
+ values: {
47
+ 10: string;
48
+ 12: string;
49
+ 14: string;
50
+ 16: string;
51
+ 18: string;
52
+ 20: string;
53
+ 24: string;
54
+ 28: string;
55
+ 32: string;
56
+ 40: string;
57
+ 48: string;
58
+ 56: string;
59
+ };
60
+ };
61
+ fontWeights: {
62
+ name: string;
63
+ values: {
64
+ regular: string;
65
+ medium: string;
66
+ bold: string;
67
+ };
68
+ };
69
+ levels: {
70
+ name: string;
71
+ values: {
72
+ subtext: {
73
+ small: {
74
+ fontFamily?: string | undefined;
75
+ fontSize?: string | undefined;
76
+ lineHeight?: string | undefined;
77
+ fontWeight?: string | undefined;
78
+ color?: string | undefined;
79
+ };
80
+ medium: {
81
+ fontFamily?: string | undefined;
82
+ fontSize?: string | undefined;
83
+ lineHeight?: string | undefined;
84
+ fontWeight?: string | undefined;
85
+ color?: string | undefined;
86
+ };
87
+ large: {
88
+ fontFamily?: string | undefined;
89
+ fontSize?: string | undefined;
90
+ lineHeight?: string | undefined;
91
+ fontWeight?: string | undefined;
92
+ color?: string | undefined;
93
+ };
94
+ };
95
+ body: {
96
+ small: {
97
+ fontFamily?: string | undefined;
98
+ fontSize?: string | undefined;
99
+ lineHeight?: string | undefined;
100
+ fontWeight?: string | undefined;
101
+ color?: string | undefined;
102
+ };
103
+ medium: {
104
+ fontFamily?: string | undefined;
105
+ fontSize?: string | undefined;
106
+ lineHeight?: string | undefined;
107
+ fontWeight?: string | undefined;
108
+ color?: string | undefined;
109
+ };
110
+ large: {
111
+ fontFamily?: string | undefined;
112
+ fontSize?: string | undefined;
113
+ lineHeight?: string | undefined;
114
+ fontWeight?: string | undefined;
115
+ color?: string | undefined;
116
+ };
117
+ };
118
+ heading: {
119
+ small: {
120
+ fontFamily?: string | undefined;
121
+ fontSize?: string | undefined;
122
+ lineHeight?: string | undefined;
123
+ fontWeight?: string | undefined;
124
+ color?: string | undefined;
125
+ };
126
+ medium: {
127
+ fontFamily?: string | undefined;
128
+ fontSize?: string | undefined;
129
+ lineHeight?: string | undefined;
130
+ fontWeight?: string | undefined;
131
+ color?: string | undefined;
132
+ };
133
+ large: {
134
+ fontFamily?: string | undefined;
135
+ fontSize?: string | undefined;
136
+ lineHeight?: string | undefined;
137
+ fontWeight?: string | undefined;
138
+ color?: string | undefined;
139
+ };
140
+ };
141
+ title: {
142
+ small: {
143
+ fontFamily?: string | undefined;
144
+ fontSize?: string | undefined;
145
+ lineHeight?: string | undefined;
146
+ fontWeight?: string | undefined;
147
+ color?: string | undefined;
148
+ };
149
+ medium: {
150
+ fontFamily?: string | undefined;
151
+ fontSize?: string | undefined;
152
+ lineHeight?: string | undefined;
153
+ fontWeight?: string | undefined;
154
+ color?: string | undefined;
155
+ };
156
+ large: {
157
+ fontFamily?: string | undefined;
158
+ fontSize?: string | undefined;
159
+ lineHeight?: string | undefined;
160
+ fontWeight?: string | undefined;
161
+ color?: string | undefined;
162
+ };
163
+ };
164
+ };
165
+ };
166
+ };
167
+ };
168
+ readonly depth: {
169
+ readonly type: "system";
170
+ readonly name: "depth";
171
+ readonly keys: {};
172
+ };
173
+ };
174
+ export declare const systemColors: {
175
+ 'background,backgroundColor,backgroundColorHover,backgroundColorFocus,backgroundColorActive': {
176
+ blackPepper400: string;
177
+ blackPepper500: string;
178
+ blueberry200: string;
179
+ blueberry400: string;
180
+ blueberry500: string;
181
+ blueberry600: string;
182
+ cantaloupe100: string;
183
+ cantaloupe400: string;
184
+ cantaloupe500: string;
185
+ cantaloupe600: string;
186
+ cinnamon100: string;
187
+ cinnamon500: string;
188
+ cinnamon600: string;
189
+ frenchVanilla100: string;
190
+ greenApple100: string;
191
+ greenApple400: string;
192
+ greenApple500: string;
193
+ greenApple600: string;
194
+ licorice100: string;
195
+ licorice200: string;
196
+ licorice300: string;
197
+ licorice500: string;
198
+ soap100: string;
199
+ soap200: string;
200
+ soap300: string;
201
+ soap400: string;
202
+ soap500: string;
203
+ };
204
+ 'color,fill,colorFocus,colorHover,colorActive,icon,iconColor': {
205
+ blackPepper300: string;
206
+ blackPepper400: string;
207
+ blackPepper500: string;
208
+ blueberry400: string;
209
+ blueberry500: string;
210
+ cinnamon500: string;
211
+ frenchVanilla100: string;
212
+ licorice100: string;
213
+ licorice200: string;
214
+ licorice300: string;
215
+ licorice400: string;
216
+ licorice500: string;
217
+ };
218
+ 'border,borderColor,borderTopColor,borderRightColor,borderBottomColor,borderLeftColor,borderInlineColor,borderBlockColor,borderInlineStartColor,borderInlineEndColor,borderBlockStartColor,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
219
+ blackPepper400: string;
220
+ blackPepper500: string;
221
+ blueberry400: string;
222
+ cantaloupe400: string;
223
+ cantaloupe600: string;
224
+ cinnamon500: string;
225
+ frenchVanilla100: string;
226
+ licorice100: string;
227
+ licorice200: string;
228
+ licorice500: string;
229
+ soap300: string;
230
+ soap400: string;
231
+ soap500: string;
232
+ };
233
+ };
234
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/mapping/index.ts"],"names":[],"mappings":"AAqFA,eAAO,MAAM,OAAO;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAyBV,CAAC;AAEX,eAAO,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CA4DxB,CAAC"}
@@ -0,0 +1,166 @@
1
+ import { generateLevelTokens } from '../utils/generateLevelTokens';
2
+ const typeLevelsMap = {
3
+ subtext: {
4
+ small: generateLevelTokens(['subtext', 'small']),
5
+ medium: generateLevelTokens(['subtext', 'medium']),
6
+ large: generateLevelTokens(['subtext', 'large']),
7
+ },
8
+ body: {
9
+ small: generateLevelTokens(['body', 'small']),
10
+ medium: generateLevelTokens(['body', 'medium']),
11
+ large: generateLevelTokens(['body', 'large']),
12
+ },
13
+ heading: {
14
+ small: generateLevelTokens(['heading', 'small']),
15
+ medium: generateLevelTokens(['heading', 'medium']),
16
+ large: generateLevelTokens(['heading', 'large']),
17
+ },
18
+ title: {
19
+ small: generateLevelTokens(['title', 'small']),
20
+ medium: generateLevelTokens(['title', 'medium']),
21
+ large: generateLevelTokens(['title', 'large']),
22
+ },
23
+ };
24
+ const shapeMap = {
25
+ zero: 'zero',
26
+ s: 'half',
27
+ m: 'x1',
28
+ l: 'x2',
29
+ circle: 'round',
30
+ };
31
+ const spaceMap = {
32
+ zero: 'zero',
33
+ xxxs: 'x1',
34
+ xxs: 'x2',
35
+ xs: 'x3',
36
+ s: 'x4',
37
+ m: 'x6',
38
+ l: 'x8',
39
+ xl: 'x10',
40
+ xxl: 'x16',
41
+ xxxl: 'x20',
42
+ };
43
+ const typeMap = {
44
+ fontFamilies: {
45
+ name: 'fontFamily',
46
+ values: {
47
+ default: 'default',
48
+ monospace: 'mono',
49
+ },
50
+ },
51
+ fontSizes: {
52
+ name: 'fontSize',
53
+ values: {
54
+ 10: 'subtext.small',
55
+ 12: 'subtext.medium',
56
+ 14: 'subtext.large',
57
+ 16: 'body.small',
58
+ 18: 'body.medium',
59
+ 20: 'body.large',
60
+ 24: 'heading.small',
61
+ 28: 'heading.medium',
62
+ 32: 'heading.large',
63
+ 40: 'title.small',
64
+ 48: 'title.medium',
65
+ 56: 'title.large',
66
+ },
67
+ },
68
+ fontWeights: {
69
+ name: 'fontWeight',
70
+ values: {
71
+ regular: 'regular',
72
+ medium: 'medium',
73
+ bold: 'bold',
74
+ },
75
+ },
76
+ levels: {
77
+ name: 'type',
78
+ values: typeLevelsMap,
79
+ },
80
+ };
81
+ export const mapping = {
82
+ colors: {
83
+ type: 'base',
84
+ name: 'colors',
85
+ },
86
+ borderRadius: {
87
+ name: 'shape',
88
+ type: 'system',
89
+ keys: shapeMap,
90
+ },
91
+ space: {
92
+ name: 'space',
93
+ type: 'system',
94
+ keys: spaceMap,
95
+ },
96
+ type: {
97
+ type: 'system',
98
+ name: 'type',
99
+ keys: typeMap,
100
+ },
101
+ depth: {
102
+ type: 'system',
103
+ name: 'depth',
104
+ keys: {},
105
+ },
106
+ };
107
+ export const systemColors = {
108
+ 'background,backgroundColor,backgroundColorHover,backgroundColorFocus,backgroundColorActive': {
109
+ blackPepper400: 'system.color.bg.contrast.default',
110
+ blackPepper500: 'system.color.bg.contrast.strong',
111
+ blueberry200: 'system.color.bg.primary.soft',
112
+ blueberry400: 'system.color.bg.primary.default',
113
+ blueberry500: 'system.color.bg.primary.strong',
114
+ blueberry600: 'system.color.bg.primary.stronger',
115
+ cantaloupe100: 'system.color.bg.caution.softer',
116
+ cantaloupe400: 'system.color.bg.caution.default',
117
+ cantaloupe500: 'system.color.bg.caution.strong',
118
+ cantaloupe600: 'system.color.bg.caution.stronger',
119
+ cinnamon100: 'system.color.bg.critical.softer',
120
+ cinnamon500: 'system.color.bg.critical.default',
121
+ cinnamon600: 'system.color.bg.critical.strong',
122
+ frenchVanilla100: 'system.color.bg.default',
123
+ greenApple100: 'system.color.bg.positive.softer',
124
+ greenApple400: 'system.color.bg.positive.default',
125
+ greenApple500: 'system.color.bg.positive.strong',
126
+ greenApple600: 'system.color.bg.positive.stronger',
127
+ licorice100: 'system.color.bg.muted.softer',
128
+ licorice200: 'system.color.bg.muted.soft',
129
+ licorice300: 'system.color.bg.muted.default',
130
+ licorice500: 'system.color.bg.muted.strong',
131
+ soap100: 'system.color.bg.alt.softer',
132
+ soap200: 'system.color.bg.alt.soft',
133
+ soap300: 'system.color.bg.alt.default',
134
+ soap400: 'system.color.bg.alt.strong',
135
+ soap500: 'system.color.bg.alt.stronger',
136
+ },
137
+ 'color,fill,colorFocus,colorHover,colorActive,icon,iconColor': {
138
+ blackPepper300: 'system.color.fg.default',
139
+ blackPepper400: 'system.color.fg.strong',
140
+ blackPepper500: 'system.color.fg.stronger',
141
+ blueberry400: 'system.color.fg.primary.default',
142
+ blueberry500: 'system.color.fg.primary.strong',
143
+ cinnamon500: 'system.color.fg.critical.default',
144
+ frenchVanilla100: 'system.color.fg.inverse',
145
+ licorice100: 'system.color.fg.disabled',
146
+ licorice200: 'system.color.fg.muted.soft',
147
+ licorice300: 'system.color.fg.muted.default',
148
+ licorice400: 'system.color.fg.muted.strong',
149
+ licorice500: 'system.color.fg.muted.stronger',
150
+ },
151
+ 'border,borderColor,borderTopColor,borderRightColor,borderBottomColor,borderLeftColor,borderInlineColor,borderBlockColor,borderInlineStartColor,borderInlineEndColor,borderBlockStartColor,borderBlockEndColor,borderColorFocus,borderColorHover,borderColorActive': {
152
+ blackPepper400: 'system.color.border.contrast.default',
153
+ blackPepper500: 'system.color.border.contrast.strong',
154
+ blueberry400: 'system.color.border.primary.default',
155
+ cantaloupe400: 'system.color.border.caution.default',
156
+ cantaloupe600: 'system.color.border.caution.strong',
157
+ cinnamon500: 'system.color.border.critical.default',
158
+ frenchVanilla100: 'system.color.border.inverse',
159
+ licorice100: 'system.color.border.input.disabled',
160
+ licorice200: 'system.color.border.input.default',
161
+ licorice500: 'system.color.border.input.strong',
162
+ soap300: 'system.color.border.input.inverse',
163
+ soap400: 'system.color.border.divider',
164
+ soap500: 'system.color.border.container',
165
+ },
166
+ };
@@ -0,0 +1,2 @@
1
+ export declare const typeProps: readonly ["fontFamily", "fontSize", "lineHeight", "fontWeight", "color"];
2
+ //# sourceMappingURL=typeProps.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typeProps.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/mapping/typeProps.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,SAAS,0EAA2E,CAAC"}
@@ -0,0 +1 @@
1
+ export const typeProps = ['fontFamily', 'fontSize', 'lineHeight', 'fontWeight', 'color'];
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=migrateColorTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateColorTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateColorTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAa,SAAS,EAAC,MAAM,aAAa,CAAC;AAQlD,QAAA,MAAM,SAAS,EAAE,SAwFhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,62 @@
1
+ import { addMissingImports, filterOutImports, transformObjectPropertyRecursively } from './utils';
2
+ import { mapping } from './mapping';
3
+ const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
4
+ const transform = (file, api) => {
5
+ const j = api.jscodeshift;
6
+ const root = j(file.source);
7
+ let importDeclaration = {};
8
+ const checkImport = (value) => Object.keys(importDeclaration).includes(value);
9
+ root
10
+ .find(j.ImportDeclaration, {
11
+ source: { value: (value) => canvasImportSources.includes(value) },
12
+ })
13
+ .forEach(nodePath => {
14
+ importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
15
+ });
16
+ root
17
+ .find(j.CallExpression, {
18
+ callee: {
19
+ type: 'Identifier',
20
+ },
21
+ })
22
+ .forEach(nodePath => {
23
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
24
+ const name = nodePath.value.callee.name;
25
+ const stylesDeclaration = nodePath.value.arguments[0];
26
+ const isCanvasKitStyling = importDeclaration[name] === 'createStyles' || importDeclaration[name] === 'createStencil';
27
+ if (stylesDeclaration.type === 'ObjectExpression') {
28
+ stylesDeclaration.properties = stylesDeclaration.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling));
29
+ }
30
+ });
31
+ root.find(j.ObjectExpression).forEach(nodePath => {
32
+ nodePath.value.properties = nodePath.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration));
33
+ });
34
+ root
35
+ .find(j.MemberExpression, (value) => {
36
+ return (value.type === 'MemberExpression' &&
37
+ ((value.object.type === 'MemberExpression' &&
38
+ value.object.object.type === 'MemberExpression' &&
39
+ checkImport(value.object.object.object.name)) ||
40
+ checkImport(value.object.name)));
41
+ })
42
+ .replaceWith(nodePath => {
43
+ const mainWrapper = nodePath.value.object;
44
+ if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
45
+ const mainObject = mainWrapper;
46
+ const mainName = mainObject.name;
47
+ const lowestProperty = nodePath.value.property;
48
+ const importedName = importDeclaration[mainName];
49
+ const map = mapping[importedName];
50
+ if (map.type === 'base' && lowestProperty.type === 'Identifier') {
51
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['base'] });
52
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
53
+ return j.callExpression(j.identifier('cssVar'), [
54
+ j.memberExpression(j.identifier(map.type), j.identifier(lowestProperty.name)),
55
+ ]);
56
+ }
57
+ }
58
+ return nodePath;
59
+ });
60
+ return root.toSource();
61
+ };
62
+ export default transform;
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=migrateDepthTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateDepthTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateDepthTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,aAAa,CAAC;AAOtC,QAAA,MAAM,SAAS,EAAE,SAgKhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,101 @@
1
+ import { addMissingImports, filterOutImports } from './utils';
2
+ const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
3
+ const transform = (file, api) => {
4
+ const j = api.jscodeshift;
5
+ const root = j(file.source);
6
+ let importDeclaration = {};
7
+ const checkImport = (value) => Object.keys(importDeclaration).includes(value);
8
+ root
9
+ .find(j.ImportDeclaration, {
10
+ source: { value: (value) => canvasImportSources.includes(value) },
11
+ })
12
+ .forEach(nodePath => {
13
+ importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
14
+ });
15
+ root
16
+ .find(j.SpreadElement, {
17
+ argument: {
18
+ type: 'MemberExpression',
19
+ object: {
20
+ type: 'Identifier',
21
+ name: 'depth',
22
+ },
23
+ property: {
24
+ type: 'NumericLiteral',
25
+ },
26
+ },
27
+ })
28
+ .replaceWith(nodePath => {
29
+ const argument = nodePath.value.argument;
30
+ if (argument.type === 'MemberExpression' && argument.property.type === 'NumericLiteral') {
31
+ const depthValue = argument.property.value;
32
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
33
+ if (depthValue > 0) {
34
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
35
+ }
36
+ return depthValue > 0
37
+ ? j.objectProperty(j.identifier('boxShadow'), j.callExpression(j.identifier('cssVar'), [
38
+ j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(depthValue), true),
39
+ ]))
40
+ : j.objectProperty(j.identifier('boxShadow'), j.literal('none'));
41
+ }
42
+ return nodePath;
43
+ });
44
+ root
45
+ .find(j.MemberExpression, (value) => {
46
+ return (value.type === 'MemberExpression' &&
47
+ value.property.name === 'boxShadow' &&
48
+ checkImport(value.object.object.name));
49
+ })
50
+ .replaceWith(nodePath => {
51
+ if (nodePath.value.object.type === 'MemberExpression' &&
52
+ nodePath.value.object.object.type === 'Identifier' &&
53
+ nodePath.value.object.property.type === 'NumericLiteral') {
54
+ const value = nodePath.value.object.property.value;
55
+ if (value.toString() !== '0') {
56
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
57
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
58
+ }
59
+ return value.toString() === '0'
60
+ ? j.literal('none')
61
+ : j.callExpression(j.identifier('cssVar'), [
62
+ j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(value), true),
63
+ ]);
64
+ }
65
+ return nodePath;
66
+ });
67
+ root
68
+ .find(j.MemberExpression, (value) => {
69
+ return (value.type === 'MemberExpression' &&
70
+ ((value.object.type === 'MemberExpression' &&
71
+ value.object.object.type === 'MemberExpression' &&
72
+ checkImport(value.object.object.object.name)) ||
73
+ checkImport(value.object.name)));
74
+ })
75
+ .replaceWith(nodePath => {
76
+ const mainWrapper = nodePath.value.object;
77
+ if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
78
+ const mainObject = mainWrapper;
79
+ const mainName = mainObject.name;
80
+ const lowestProperty = nodePath.value.property;
81
+ const importedName = importDeclaration[mainName];
82
+ if (importedName === 'depth' && lowestProperty.type === 'NumericLiteral') {
83
+ const isZero = lowestProperty.value.toString() === '0';
84
+ if (!isZero) {
85
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
86
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
87
+ }
88
+ return j.objectExpression([
89
+ j.property('init', j.identifier('boxShadow'), isZero
90
+ ? j.literal('none')
91
+ : j.callExpression(j.identifier('cssVar'), [
92
+ j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('depth')), j.numericLiteral(lowestProperty.value), true),
93
+ ])),
94
+ ]);
95
+ }
96
+ }
97
+ return nodePath;
98
+ });
99
+ return root.toSource();
100
+ };
101
+ export default transform;
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=migrateOtherTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateOtherTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateOtherTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AAQpE,QAAA,MAAM,SAAS,EAAE,SAsKhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,109 @@
1
+ import { addMissingImports, filterOutImports, varToMemberExpression } from './utils';
2
+ import { mapping, systemColors } from './mapping';
3
+ const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
4
+ const transform = (file, api) => {
5
+ const j = api.jscodeshift;
6
+ const root = j(file.source);
7
+ let importDeclaration = {};
8
+ const checkImport = (value) => Object.keys(importDeclaration).includes(value);
9
+ root
10
+ .find(j.ImportDeclaration, {
11
+ source: { value: (value) => canvasImportSources.includes(value) },
12
+ })
13
+ .forEach(nodePath => {
14
+ importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
15
+ });
16
+ root
17
+ .find(j.CallExpression, {
18
+ callee: {
19
+ type: 'Identifier',
20
+ },
21
+ })
22
+ .forEach(nodePath => {
23
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
24
+ const name = nodePath.value.callee.name;
25
+ const stylesDeclaration = nodePath.value.arguments[0];
26
+ const isCanvasKitStyling = importDeclaration[name] === 'createStyles' || importDeclaration[name] === 'createStencil';
27
+ if (stylesDeclaration.type === 'ObjectExpression') {
28
+ const transformProperty = (property) => {
29
+ var _a;
30
+ if (property.type === 'ObjectProperty' &&
31
+ property.key.type === 'Identifier' &&
32
+ property.value.type === 'MemberExpression' &&
33
+ property.value.object.type === 'Identifier' &&
34
+ property.value.property.type === 'Identifier' &&
35
+ importDeclaration[property.value.object.name] === 'colors') {
36
+ const key = property.key.name;
37
+ const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === key))) === null || _a === void 0 ? void 0 : _a[1];
38
+ const { property: value } = property.value;
39
+ const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[value.name];
40
+ if (colorToken) {
41
+ if (!isCanvasKitStyling) {
42
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
43
+ }
44
+ return j.objectProperty(j.identifier(key), isCanvasKitStyling
45
+ ? varToMemberExpression(j, colorToken)
46
+ : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
47
+ }
48
+ }
49
+ if (property.type === 'ObjectProperty' && property.value.type === 'TemplateLiteral') {
50
+ const templateLiteral = property.value;
51
+ const transformedQuasis = templateLiteral.quasis.map((quasi) => quasi);
52
+ const transformedExpressions = templateLiteral.expressions.map((expr) => {
53
+ var _a;
54
+ if (expr.type === 'MemberExpression' &&
55
+ expr.object.type === 'Identifier' &&
56
+ expr.property.type === 'Identifier' &&
57
+ importDeclaration[expr.object.name] === 'colors') {
58
+ const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _a === void 0 ? void 0 : _a[1];
59
+ const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
60
+ if (colorToken) {
61
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
62
+ return j.callExpression(j.identifier('cssVar'), [
63
+ varToMemberExpression(j, colorToken),
64
+ ]);
65
+ }
66
+ }
67
+ return expr;
68
+ });
69
+ return j.objectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
70
+ }
71
+ if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
72
+ return j.objectProperty(property.key, j.objectExpression(property.value.properties.map(transformProperty)));
73
+ }
74
+ return property;
75
+ };
76
+ stylesDeclaration.properties = stylesDeclaration.properties.map(transformProperty);
77
+ }
78
+ });
79
+ root
80
+ .find(j.MemberExpression, (value) => {
81
+ return (value.type === 'MemberExpression' &&
82
+ ((value.object.type === 'MemberExpression' &&
83
+ value.object.object.type === 'MemberExpression' &&
84
+ checkImport(value.object.object.object.name)) ||
85
+ checkImport(value.object.name)));
86
+ })
87
+ .replaceWith(nodePath => {
88
+ const mainWrapper = nodePath.value.object;
89
+ if (mainWrapper.type === 'Identifier' && importDeclaration[mainWrapper.name] !== 'type') {
90
+ const mainObject = mainWrapper;
91
+ const mainName = mainObject.name;
92
+ const lowestProperty = nodePath.value.property;
93
+ const importedName = importDeclaration[mainName];
94
+ const map = mapping[importedName];
95
+ if (importedName !== 'depth') {
96
+ if (map.type === 'system' && lowestProperty.type === 'Identifier') {
97
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
98
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
99
+ return j.callExpression(j.identifier('cssVar'), [
100
+ j.memberExpression(j.memberExpression(j.identifier(map.type), j.identifier(map.name)), j.identifier(map.keys[lowestProperty.name])),
101
+ ]);
102
+ }
103
+ }
104
+ }
105
+ return nodePath;
106
+ });
107
+ return root.toSource();
108
+ };
109
+ export default transform;
@@ -0,0 +1,4 @@
1
+ import { Transform } from 'jscodeshift';
2
+ declare const transform: Transform;
3
+ export default transform;
4
+ //# sourceMappingURL=migrateTypeTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"migrateTypeTokens.d.ts","sourceRoot":"","sources":["../../../lib/v13.2/migrateTypeTokens.ts"],"names":[],"mappings":"AAAA,OAAO,EAA+B,SAAS,EAAC,MAAM,aAAa,CAAC;AASpE,QAAA,MAAM,SAAS,EAAE,SA6NhB,CAAC;AAEF,eAAe,SAAS,CAAC"}
@@ -0,0 +1,136 @@
1
+ import { addMissingImports, filterOutImports, varToMemberExpression } from './utils';
2
+ import { typeProps } from './mapping/typeProps';
3
+ import { mapping } from './mapping';
4
+ const canvasImportSources = ['@workday/canvas-kit-styling', '@workday/canvas-kit-react/tokens'];
5
+ const transform = (file, api) => {
6
+ const j = api.jscodeshift;
7
+ const root = j(file.source);
8
+ let importDeclaration = {};
9
+ const checkImport = (value) => Object.keys(importDeclaration).includes(value);
10
+ root
11
+ .find(j.ImportDeclaration, {
12
+ source: { value: (value) => canvasImportSources.includes(value) },
13
+ })
14
+ .forEach(nodePath => {
15
+ importDeclaration = { ...importDeclaration, ...filterOutImports(nodePath) };
16
+ });
17
+ root
18
+ .find(j.SpreadElement, {
19
+ argument: {
20
+ type: 'MemberExpression',
21
+ object: {
22
+ type: 'MemberExpression',
23
+ object: {
24
+ type: 'MemberExpression',
25
+ object: {
26
+ name: 'type',
27
+ },
28
+ property: {
29
+ name: 'levels',
30
+ },
31
+ },
32
+ },
33
+ },
34
+ })
35
+ .replaceWith(nodePath => {
36
+ const argument = nodePath.value.argument;
37
+ const object = argument.object;
38
+ const level = object.property.name;
39
+ const size = argument.property.name;
40
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
41
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
42
+ nodePath.insertAfter(j.objectProperty(j.identifier('color'), j.callExpression(j.identifier('cssVar'), [
43
+ j.memberExpression(j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('color')), j.identifier('fg')), j.identifier(['heading', 'title'].includes(level) ? 'strong' : 'default')),
44
+ ])));
45
+ return [
46
+ j.spreadElement(j.memberExpression(j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier('type')), j.identifier(level)), j.identifier(size))),
47
+ ];
48
+ });
49
+ root
50
+ .find(j.MemberExpression, (value) => {
51
+ return (value.type === 'MemberExpression' &&
52
+ typeProps.includes(value.property.name) &&
53
+ value.object.type === 'MemberExpression' &&
54
+ value.object.object.type === 'MemberExpression' &&
55
+ value.object.object.object.type === 'MemberExpression' &&
56
+ value.object.object.object.object.type === 'Identifier' &&
57
+ checkImport(value.object.object.object.object.name));
58
+ })
59
+ .replaceWith(nodePath => {
60
+ const mainWrapper = nodePath.value.object;
61
+ const property = nodePath.value.property;
62
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
63
+ if (mainWrapper.type === 'MemberExpression' &&
64
+ mainWrapper.object.type === 'MemberExpression' &&
65
+ mainWrapper.object.object.type === 'MemberExpression' &&
66
+ mainWrapper.object.object.object.type === 'Identifier' &&
67
+ checkImport(mainWrapper.object.object.object.name)) {
68
+ const level = mainWrapper.object.property.name;
69
+ const size = mainWrapper.property.name;
70
+ const prop = property.name;
71
+ const { values } = mapping.type.keys.levels;
72
+ const levels = values[level];
73
+ const tokens = levels[size];
74
+ const value = tokens[prop];
75
+ if (value) {
76
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
77
+ return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]);
78
+ }
79
+ }
80
+ return nodePath;
81
+ });
82
+ root
83
+ .find(j.MemberExpression, (value) => {
84
+ return (value.type === 'MemberExpression' &&
85
+ ((value.object.type === 'MemberExpression' &&
86
+ value.object.object.type === 'MemberExpression' &&
87
+ checkImport(value.object.object.object.name)) ||
88
+ checkImport(value.object.name)));
89
+ })
90
+ .replaceWith(nodePath => {
91
+ const mainWrapper = nodePath.value.object;
92
+ if (mainWrapper.type === 'MemberExpression' &&
93
+ mainWrapper.object.type === 'MemberExpression') {
94
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
95
+ const mainProperty = mainWrapper.object.property;
96
+ const innerProperty = mainWrapper.property;
97
+ const lowestProperty = nodePath.value.property;
98
+ if (mainProperty.type === 'Identifier' &&
99
+ innerProperty.type === 'Identifier' &&
100
+ (lowestProperty.type === 'Identifier' || lowestProperty.type === 'NumericLiteral')) {
101
+ const lowestPropertyValue = lowestProperty.type === 'Identifier' ? lowestProperty.name : lowestProperty.value;
102
+ const innerKey = innerProperty.name;
103
+ if (mainProperty.name === 'properties') {
104
+ const { name, values } = mapping.type.keys[innerKey];
105
+ const newValue = values[lowestPropertyValue];
106
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
107
+ if (newValue.includes('.')) {
108
+ const [first, second] = newValue.split('.');
109
+ return j.callExpression(j.identifier('cssVar'), [
110
+ j.memberExpression(j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier(name)), j.identifier(first)), j.identifier(second)),
111
+ ]);
112
+ }
113
+ else {
114
+ return j.callExpression(j.identifier('cssVar'), [
115
+ j.memberExpression(j.memberExpression(j.identifier('system'), j.identifier(name)), j.identifier(newValue)),
116
+ ]);
117
+ }
118
+ }
119
+ else if (mainProperty.name === 'levels') {
120
+ const { values } = mapping.type.keys.levels;
121
+ const levels = values[innerKey];
122
+ const lowestKey = lowestPropertyValue;
123
+ const tokens = levels[lowestKey];
124
+ const props = Object.entries(tokens).map(([key, value]) => {
125
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
126
+ return j.property('init', j.identifier(key), j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, value)]));
127
+ });
128
+ return j.objectExpression(props);
129
+ }
130
+ }
131
+ }
132
+ return nodePath;
133
+ });
134
+ return root.toSource();
135
+ };
136
+ export default transform;
@@ -0,0 +1,2 @@
1
+ export declare const addMissingImports: ({ j, root }: any, { importPath, specifiers, localName }: any) => void;
2
+ //# sourceMappingURL=addMissingImports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"addMissingImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/addMissingImports.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,iBAAiB,gBAAe,GAAG,yCAAuC,GAAG,SA4CzF,CAAC"}
@@ -0,0 +1,30 @@
1
+ export const addMissingImports = ({ j, root }, { importPath, specifiers, localName }) => {
2
+ const [existingImport] = root
3
+ .find(j.ImportDeclaration, {
4
+ source: {
5
+ value: (value) => value.includes(importPath),
6
+ },
7
+ })
8
+ .nodes();
9
+ if (existingImport) {
10
+ specifiers.forEach((specifier) => {
11
+ var _a;
12
+ if (!((_a = existingImport.specifiers) === null || _a === void 0 ? void 0 : _a.some((existingSpecifier) => existingSpecifier.type === 'ImportSpecifier' &&
13
+ existingSpecifier.imported.name === specifier))) {
14
+ existingImport.specifiers.push(j.importSpecifier(j.identifier(specifier), j.identifier(localName || specifier)));
15
+ existingImport.specifiers.sort((a, b) => {
16
+ return a.imported.name.toString().localeCompare(b.imported.name.toString());
17
+ });
18
+ }
19
+ });
20
+ return;
21
+ }
22
+ const newImport = j.importDeclaration(specifiers.map((specifier) => j.importSpecifier(j.identifier(specifier), j.identifier(localName || specifier))), j.stringLiteral(importPath));
23
+ const firstImport = root.find(j.ImportDeclaration).paths()[0];
24
+ if (firstImport) {
25
+ firstImport.insertAfter(newImport);
26
+ }
27
+ else {
28
+ root.get().node.program.body.unshift(newImport);
29
+ }
30
+ };
@@ -0,0 +1,3 @@
1
+ import { Options, Transform } from 'jscodeshift';
2
+ export declare const expectTransformFactory: (fn: Transform) => (input: string, expected: string, options?: Options) => string;
3
+ //# sourceMappingURL=expectTransformFactory.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"expectTransformFactory.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/expectTransformFactory.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,SAAS,EAAC,MAAM,aAAa,CAAC;AAG/C,eAAO,MAAM,sBAAsB,OAC5B,SAAS,aACN,MAAM,YAAY,MAAM,YAAW,OAAO,WAEjD,CAAC"}
@@ -0,0 +1,4 @@
1
+ import { runInlineTest } from 'jscodeshift/src/testUtils';
2
+ export const expectTransformFactory = (fn) => (input, expected, options = {}) => {
3
+ return runInlineTest(fn, options, { source: input }, expected, { parser: 'tsx' });
4
+ };
@@ -0,0 +1,3 @@
1
+ import { ASTPath, ImportDeclaration } from 'jscodeshift';
2
+ export declare const filterOutImports: (nodePath: ASTPath<ImportDeclaration>) => Record<string, string>;
3
+ //# sourceMappingURL=filterOutImports.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filterOutImports.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/filterOutImports.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAE,iBAAiB,EAAC,MAAM,aAAa,CAAC;AAEvD,eAAO,MAAM,gBAAgB,aAAc,QAAQ,iBAAiB,CAAC,2BAwBpE,CAAC"}
@@ -0,0 +1,19 @@
1
+ export const filterOutImports = (nodePath) => {
2
+ var _a, _b;
3
+ const importName = {};
4
+ nodePath.value.specifiers = (_a = nodePath.value.specifiers) === null || _a === void 0 ? void 0 : _a.filter(specifier => {
5
+ var _a;
6
+ if (specifier.type === 'ImportSpecifier' && specifier.local) {
7
+ const localName = specifier.local.name.toString();
8
+ const importedName = specifier.imported.name.toString();
9
+ importName[localName] = importedName;
10
+ return !(typeof nodePath.value.source.value === 'string' &&
11
+ ((_a = nodePath.value.source.value) === null || _a === void 0 ? void 0 : _a.endsWith('tokens')));
12
+ }
13
+ return true;
14
+ });
15
+ if (!((_b = nodePath.value.specifiers) === null || _b === void 0 ? void 0 : _b.length)) {
16
+ nodePath.prune();
17
+ }
18
+ return importName;
19
+ };
@@ -0,0 +1,8 @@
1
+ export declare const generateLevelTokens: ([level, size]: string[]) => {
2
+ fontFamily?: string | undefined;
3
+ fontSize?: string | undefined;
4
+ lineHeight?: string | undefined;
5
+ fontWeight?: string | undefined;
6
+ color?: string | undefined;
7
+ };
8
+ //# sourceMappingURL=generateLevelTokens.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generateLevelTokens.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/generateLevelTokens.ts"],"names":[],"mappings":"AAEA,eAAO,MAAM,mBAAmB,kBAAmB,MAAM,EAAE;;;;;;CAkB1D,CAAC"}
@@ -0,0 +1,20 @@
1
+ import { typeProps } from '../mapping/typeProps';
2
+ export const generateLevelTokens = ([level, size]) => {
3
+ const isHeadingStyle = ['heading', 'title'].includes(level);
4
+ return typeProps.reduce((acc, prop) => {
5
+ switch (prop) {
6
+ case 'color':
7
+ acc.color = `system.color.fg.${isHeadingStyle ? 'strong' : 'default'}`;
8
+ break;
9
+ case 'fontWeight':
10
+ acc.fontWeight = `system.fontWeight.${isHeadingStyle ? 'bold' : 'regular'}`;
11
+ break;
12
+ case 'fontFamily':
13
+ acc.fontFamily = 'system.fontFamily.default';
14
+ break;
15
+ default:
16
+ acc[prop] = `system.${prop}.${level}.${size}`;
17
+ }
18
+ return acc;
19
+ }, {});
20
+ };
@@ -0,0 +1,7 @@
1
+ export * from './addMissingImports';
2
+ export * from './filterOutImports';
3
+ export * from './generateLevelTokens';
4
+ export * from './expectTransformFactory';
5
+ export * from './varToMemberExpression';
6
+ export * from './transformObjectPropertyRecursively';
7
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/index.ts"],"names":[],"mappings":"AAAA,cAAc,qBAAqB,CAAC;AACpC,cAAc,oBAAoB,CAAC;AACnC,cAAc,uBAAuB,CAAC;AACtC,cAAc,0BAA0B,CAAC;AACzC,cAAc,yBAAyB,CAAC;AACxC,cAAc,sCAAsC,CAAC"}
@@ -0,0 +1,6 @@
1
+ export * from './addMissingImports';
2
+ export * from './filterOutImports';
3
+ export * from './generateLevelTokens';
4
+ export * from './expectTransformFactory';
5
+ export * from './varToMemberExpression';
6
+ export * from './transformObjectPropertyRecursively';
@@ -0,0 +1,4 @@
1
+ export declare const transformObjectPropertyRecursively: ({ j, root }: any, property: any, importDeclaration: {
2
+ [key: string]: any;
3
+ }, isCanvasKitStyling?: boolean) => any;
4
+ //# sourceMappingURL=transformObjectPropertyRecursively.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformObjectPropertyRecursively.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/transformObjectPropertyRecursively.ts"],"names":[],"mappings":"AAKA,eAAO,MAAM,kCAAkC,gBAClC,GAAG,YACJ,GAAG;;wBAEQ,OAAO,KAC3B,GAsIF,CAAC"}
@@ -0,0 +1,74 @@
1
+ import { systemColors } from '../mapping';
2
+ import { addMissingImports } from './addMissingImports';
3
+ import { varToMemberExpression } from './varToMemberExpression';
4
+ export const transformObjectPropertyRecursively = ({ j, root }, property, importDeclaration, isCanvasKitStyling) => {
5
+ var _a, _b, _c;
6
+ if (property.type === 'ObjectProperty' &&
7
+ property.key.type === 'Identifier' &&
8
+ property.value.type === 'MemberExpression' &&
9
+ property.value.object.type === 'Identifier' &&
10
+ property.value.property.type === 'Identifier' &&
11
+ importDeclaration[property.value.object.name] === 'colors') {
12
+ const key = property.key.name;
13
+ const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === key))) === null || _a === void 0 ? void 0 : _a[1];
14
+ const { property: value } = property.value;
15
+ const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[value.name];
16
+ if (colorToken) {
17
+ if (!isCanvasKitStyling) {
18
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
19
+ }
20
+ return j.objectProperty(j.identifier(key), isCanvasKitStyling
21
+ ? varToMemberExpression(j, colorToken)
22
+ : j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]));
23
+ }
24
+ }
25
+ if (property.type === 'ObjectProperty' && property.value.type === 'TemplateLiteral') {
26
+ const templateLiteral = property.value;
27
+ const transformedQuasis = templateLiteral.quasis.map((quasi) => quasi);
28
+ const transformedExpressions = templateLiteral.expressions.map((expr) => {
29
+ var _a;
30
+ if (expr.type === 'MemberExpression' &&
31
+ expr.object.type === 'Identifier' &&
32
+ expr.property.type === 'Identifier' &&
33
+ importDeclaration[expr.object.name] === 'colors') {
34
+ const tokens = (_a = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _a === void 0 ? void 0 : _a[1];
35
+ const colorToken = tokens === null || tokens === void 0 ? void 0 : tokens[expr.property.name];
36
+ if (colorToken) {
37
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
38
+ return j.callExpression(j.identifier('cssVar'), [varToMemberExpression(j, colorToken)]);
39
+ }
40
+ }
41
+ return expr;
42
+ });
43
+ return j.objectProperty(property.key, j.templateLiteral(transformedQuasis, transformedExpressions));
44
+ }
45
+ if (property.type === 'ObjectProperty' && property.value.type === 'ConditionalExpression') {
46
+ const { test, consequent, alternate } = property.value;
47
+ if (consequent.type === 'MemberExpression' &&
48
+ consequent.object.type === 'Identifier' &&
49
+ consequent.property.type === 'Identifier' &&
50
+ importDeclaration[consequent.object.name] === 'colors' &&
51
+ alternate.type === 'MemberExpression' &&
52
+ alternate.object.type === 'Identifier' &&
53
+ alternate.property.type === 'Identifier' &&
54
+ importDeclaration[alternate.object.name] === 'colors') {
55
+ const consequentTokens = (_b = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _b === void 0 ? void 0 : _b[1];
56
+ const alternateTokens = (_c = Object.entries(systemColors).find(([blockKey]) => blockKey.split(',').some(prop => prop === property.key.name))) === null || _c === void 0 ? void 0 : _c[1];
57
+ const consequentColorToken = consequentTokens === null || consequentTokens === void 0 ? void 0 : consequentTokens[consequent.property.name];
58
+ const alternateColorToken = alternateTokens === null || alternateTokens === void 0 ? void 0 : alternateTokens[alternate.property.name];
59
+ if (consequentColorToken && alternateColorToken) {
60
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-kit-styling', specifiers: ['cssVar'] });
61
+ addMissingImports({ j, root }, { importPath: '@workday/canvas-tokens-web', specifiers: ['system'] });
62
+ return j.objectProperty(property.key, j.conditionalExpression(test, j.callExpression(j.identifier('cssVar'), [
63
+ varToMemberExpression(j, consequentColorToken),
64
+ ]), j.callExpression(j.identifier('cssVar'), [
65
+ varToMemberExpression(j, alternateColorToken),
66
+ ])));
67
+ }
68
+ }
69
+ }
70
+ if (property.type === 'ObjectProperty' && property.value.type === 'ObjectExpression') {
71
+ return j.objectProperty(property.key, j.objectExpression(property.value.properties.map((prop) => transformObjectPropertyRecursively({ j, root }, prop, importDeclaration, isCanvasKitStyling))));
72
+ }
73
+ return property;
74
+ };
@@ -0,0 +1,2 @@
1
+ export declare const varToMemberExpression: (j: any, value: string) => any;
2
+ //# sourceMappingURL=varToMemberExpression.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"varToMemberExpression.d.ts","sourceRoot":"","sources":["../../../../lib/v13.2/utils/varToMemberExpression.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,qBAAqB,MAAO,GAAG,SAAS,MAAM,QAQ1D,CAAC"}
@@ -0,0 +1,9 @@
1
+ export const varToMemberExpression = (j, value) => {
2
+ const valuesKeys = value.split('.');
3
+ return valuesKeys.reduce((acc, key, index) => {
4
+ if (index === 0) {
5
+ return j.identifier(key);
6
+ }
7
+ return j.memberExpression(acc, j.identifier(key));
8
+ }, null);
9
+ };
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@workday/canvas-kit-codemod",
3
3
  "author": "Workday, Inc. (https://www.workday.com)",
4
4
  "license": "Apache-2.0",
5
- "version": "14.0.0-alpha.1151-next.0",
5
+ "version": "14.0.0-alpha.1156-next.0",
6
6
  "description": "A collection of codemods for use on Workday Canvas Kit packages.",
7
7
  "main": "dist/es6/index.js",
8
8
  "sideEffects": false,
@@ -46,5 +46,5 @@
46
46
  "resolutions": {
47
47
  "recast": "0.20.4"
48
48
  },
49
- "gitHead": "891b0d79a8054c5cd3799eb8dd2e0c3b0f15a47b"
49
+ "gitHead": "e5711be8fa7794a67a880925c1b582a1abbcfbf6"
50
50
  }