@atlaskit/tokens 1.35.0 → 1.37.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 +12 -0
- package/codemods/css-to-design-tokens/__tests__/css-to-design-tokens.test.tsx +489 -0
- package/codemods/css-to-design-tokens/__tests__/utils.test.tsx +145 -0
- package/codemods/css-to-design-tokens/lib/colors.tsx +71 -0
- package/codemods/css-to-design-tokens/lib/declaration.tsx +43 -0
- package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +336 -0
- package/codemods/css-to-design-tokens/lib/meta.tsx +173 -0
- package/codemods/css-to-design-tokens/lib/tokens.tsx +54 -0
- package/codemods/css-to-design-tokens/lib/value.tsx +85 -0
- package/codemods/css-to-design-tokens/transform.tsx +99 -0
- package/codemods/hypermod.config.tsx +9 -0
- package/codemods/theme-to-design-tokens/__tests__/theme-to-design-tokens.test.tsx +1104 -0
- package/codemods/theme-to-design-tokens/transform.tsx +628 -0
- package/codemods/theme-to-design-tokens/utils/ast-meta.tsx +159 -0
- package/codemods/theme-to-design-tokens/utils/ast.tsx +46 -0
- package/codemods/theme-to-design-tokens/utils/color.tsx +45 -0
- package/codemods/theme-to-design-tokens/utils/css-utils.tsx +38 -0
- package/codemods/theme-to-design-tokens/utils/fuzzy-search.tsx +326 -0
- package/codemods/theme-to-design-tokens/utils/legacy-colors.tsx +232 -0
- package/codemods/theme-to-design-tokens/utils/named-colors.tsx +150 -0
- package/codemods/theme-to-design-tokens/utils/string-utils.tsx +22 -0
- package/codemods/utils/tokens.tsx +376 -0
- package/dist/cjs/artifacts/replacement-mapping.js +1 -13
- package/dist/cjs/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/cjs/artifacts/tokens-raw/atlassian-typography-adg3.js +17 -25
- package/dist/cjs/artifacts/tokens-raw/atlassian-typography-minor3.js +89 -1
- package/dist/cjs/get-token-value.js +1 -1
- package/dist/cjs/get-token.js +1 -1
- package/dist/es2019/artifacts/replacement-mapping.js +1 -13
- package/dist/es2019/artifacts/themes/atlassian-typography-minor3.js +5 -1
- package/dist/es2019/artifacts/tokens-raw/atlassian-typography-adg3.js +17 -25
- package/dist/es2019/artifacts/tokens-raw/atlassian-typography-minor3.js +89 -1
- package/dist/es2019/get-token-value.js +1 -1
- package/dist/es2019/get-token.js +1 -1
- package/dist/esm/artifacts/replacement-mapping.js +1 -13
- package/dist/esm/artifacts/themes/atlassian-typography-minor3.js +2 -2
- package/dist/esm/artifacts/tokens-raw/atlassian-typography-adg3.js +17 -25
- package/dist/esm/artifacts/tokens-raw/atlassian-typography-minor3.js +89 -1
- package/dist/esm/get-token-value.js +1 -1
- package/dist/esm/get-token.js +1 -1
- package/dist/types/artifacts/replacement-mapping.d.ts +1 -1
- package/dist/types/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
- package/dist/types/artifacts/tokens-raw/atlassian-typography-adg3.d.ts +1 -1
- package/dist/types/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
- package/dist/types/artifacts/types-internal.d.ts +2 -2
- package/dist/types/artifacts/types.d.ts +2 -2
- package/dist/types/types.d.ts +2 -3
- package/dist/types-ts4.5/artifacts/replacement-mapping.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-typography-adg3.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
- package/dist/types-ts4.5/artifacts/types-internal.d.ts +2 -2
- package/dist/types-ts4.5/artifacts/types.d.ts +2 -2
- package/dist/types-ts4.5/types.d.ts +2 -3
- package/figma/atlassian-typography-adg3.json +38 -1
- package/figma/atlassian-typography-minor3.json +38 -1
- package/package.json +5 -1
|
@@ -0,0 +1,85 @@
|
|
|
1
|
+
import {
|
|
2
|
+
extractBetweenParentheses,
|
|
3
|
+
isGradient,
|
|
4
|
+
isKnownCssVariable,
|
|
5
|
+
isLessFunction,
|
|
6
|
+
isNamedColor,
|
|
7
|
+
isRawColor,
|
|
8
|
+
} from './colors';
|
|
9
|
+
import { extractCssVarName } from './declaration';
|
|
10
|
+
import { getCssVarMeta, getNamedColorMeta, getRawColorMeta } from './meta';
|
|
11
|
+
import findToken from './tokens';
|
|
12
|
+
|
|
13
|
+
interface Value {
|
|
14
|
+
getReplacement: (additionalMeta?: string[]) => string;
|
|
15
|
+
getMeta: () => string[];
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
export default function parseValue(value: string): Value | null {
|
|
19
|
+
if (isLessFunction(value)) {
|
|
20
|
+
// eslint-disable-next-line no-console
|
|
21
|
+
console.warn(
|
|
22
|
+
'Cannot parse - less function detected, would cause compilation error',
|
|
23
|
+
);
|
|
24
|
+
return null;
|
|
25
|
+
}
|
|
26
|
+
if (isGradient(value)) {
|
|
27
|
+
return {
|
|
28
|
+
getReplacement(additionalMeta = []) {
|
|
29
|
+
const gradientContent = extractBetweenParentheses(value);
|
|
30
|
+
const values = gradientContent.split(',');
|
|
31
|
+
const replacedValues = values.map((val) => {
|
|
32
|
+
const parsedValue = parseValue(val.trim());
|
|
33
|
+
return parsedValue ? parsedValue.getReplacement(additionalMeta) : val;
|
|
34
|
+
});
|
|
35
|
+
return value.replace(gradientContent, replacedValues.join(', '));
|
|
36
|
+
},
|
|
37
|
+
getMeta() {
|
|
38
|
+
const BASE_META: string[] = [];
|
|
39
|
+
const gradientContent = extractBetweenParentheses(value);
|
|
40
|
+
const values = gradientContent.split(',');
|
|
41
|
+
const metas = values.reduce((acc, val) => {
|
|
42
|
+
const parsedValue = parseValue(val.trim());
|
|
43
|
+
return parsedValue ? [...acc, ...parsedValue.getMeta()] : acc;
|
|
44
|
+
}, BASE_META);
|
|
45
|
+
return metas;
|
|
46
|
+
},
|
|
47
|
+
};
|
|
48
|
+
}
|
|
49
|
+
if (isKnownCssVariable(extractCssVarName(value))) {
|
|
50
|
+
return {
|
|
51
|
+
getReplacement(additionalMeta = []) {
|
|
52
|
+
const token = findToken([...additionalMeta, ...this.getMeta()]);
|
|
53
|
+
return `var(${token}, ${value})`;
|
|
54
|
+
},
|
|
55
|
+
getMeta() {
|
|
56
|
+
return getCssVarMeta(value);
|
|
57
|
+
},
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
if (isRawColor(value)) {
|
|
61
|
+
return {
|
|
62
|
+
getReplacement(additionalMeta = []) {
|
|
63
|
+
const token = findToken([...additionalMeta, ...this.getMeta()]);
|
|
64
|
+
return `var(${token}, ${value})`;
|
|
65
|
+
},
|
|
66
|
+
getMeta() {
|
|
67
|
+
return getRawColorMeta(value);
|
|
68
|
+
},
|
|
69
|
+
};
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
if (isNamedColor(value)) {
|
|
73
|
+
return {
|
|
74
|
+
getReplacement(additionalMeta = []) {
|
|
75
|
+
const token = findToken([...additionalMeta, ...this.getMeta()]);
|
|
76
|
+
return `var(${token}, ${value})`;
|
|
77
|
+
},
|
|
78
|
+
getMeta() {
|
|
79
|
+
return getNamedColorMeta(value);
|
|
80
|
+
},
|
|
81
|
+
};
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
return null;
|
|
85
|
+
}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import type { FileInfo } from 'jscodeshift';
|
|
2
|
+
import postcss, { Plugin } from 'postcss';
|
|
3
|
+
// @ts-ignore
|
|
4
|
+
import lessSyntax from 'postcss-less';
|
|
5
|
+
|
|
6
|
+
import {
|
|
7
|
+
isColorRelatedProperty,
|
|
8
|
+
isCssDeclaration,
|
|
9
|
+
splitCssValue,
|
|
10
|
+
} from './lib/declaration';
|
|
11
|
+
import { getBaseDeclarationMeta } from './lib/meta';
|
|
12
|
+
import findToken from './lib/tokens';
|
|
13
|
+
import parseValue from './lib/value';
|
|
14
|
+
|
|
15
|
+
const POSTCSS_OPTIONS = { syntax: lessSyntax, from: undefined };
|
|
16
|
+
|
|
17
|
+
// https://github.com/postcss/postcss/blob/main/docs/writing-a-plugin.md
|
|
18
|
+
// https://astexplorer.net/#/2uBU1BLuJ1
|
|
19
|
+
const plugin = (): Plugin => {
|
|
20
|
+
const processed = Symbol('processed');
|
|
21
|
+
|
|
22
|
+
return {
|
|
23
|
+
postcssPlugin: 'UsingTokens',
|
|
24
|
+
AtRule(atRule) {
|
|
25
|
+
// @ts-expect-error
|
|
26
|
+
if (atRule[processed]) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
// @ts-expect-error: The 'variable' property does not exist on 'AtRule' according to the TypeScript definitions.
|
|
31
|
+
// However, the 'postcss-less' library adds a 'variable' property to 'AtRule' when parsing LESS variables.
|
|
32
|
+
// This property indicates whether the 'AtRule' is a LESS variable.
|
|
33
|
+
if (atRule.variable) {
|
|
34
|
+
// TODO https://hello.atlassian.net/browse/DCA11Y-637
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// @ts-expect-error
|
|
38
|
+
atRule[processed] = true;
|
|
39
|
+
},
|
|
40
|
+
Declaration: (decl) => {
|
|
41
|
+
// @ts-expect-error
|
|
42
|
+
if (decl[processed]) {
|
|
43
|
+
return;
|
|
44
|
+
}
|
|
45
|
+
if (decl.value === 'none') {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
const baseMeta = getBaseDeclarationMeta(decl);
|
|
50
|
+
|
|
51
|
+
if (isCssDeclaration(decl.prop)) {
|
|
52
|
+
// TODO https://hello.atlassian.net/browse/DCA11Y-637
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
if (isColorRelatedProperty(decl.prop)) {
|
|
56
|
+
const values = splitCssValue(decl.value);
|
|
57
|
+
if (!values) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
switch (decl.prop) {
|
|
62
|
+
case 'box-shadow':
|
|
63
|
+
const meta = values.reduce((acc: string[], curr: string) => {
|
|
64
|
+
const parsedValue = parseValue(curr);
|
|
65
|
+
if (!parsedValue) {
|
|
66
|
+
return acc;
|
|
67
|
+
}
|
|
68
|
+
return [...acc, ...parsedValue.getMeta()];
|
|
69
|
+
}, baseMeta);
|
|
70
|
+
|
|
71
|
+
const token = findToken(meta);
|
|
72
|
+
decl.value = `var(${token}, ${decl.value})`;
|
|
73
|
+
break;
|
|
74
|
+
default:
|
|
75
|
+
const replacedValues = values.map((value) => {
|
|
76
|
+
const parsedValue = parseValue(value);
|
|
77
|
+
if (!parsedValue) {
|
|
78
|
+
return value;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
return parsedValue.getReplacement(baseMeta);
|
|
82
|
+
});
|
|
83
|
+
decl.value = replacedValues.join(' ');
|
|
84
|
+
break;
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
|
|
88
|
+
// @ts-expect-error
|
|
89
|
+
decl[processed] = true;
|
|
90
|
+
},
|
|
91
|
+
};
|
|
92
|
+
};
|
|
93
|
+
|
|
94
|
+
export default async function transformer(file: FileInfo | string) {
|
|
95
|
+
const processor = postcss([plugin()]);
|
|
96
|
+
const src = typeof file === 'string' ? file : file.source;
|
|
97
|
+
const { css } = await processor.process(src, POSTCSS_OPTIONS);
|
|
98
|
+
return css;
|
|
99
|
+
}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import cssToDesignTokens from './css-to-design-tokens/transform';
|
|
2
|
+
import themeToDesignTokens from './theme-to-design-tokens/transform';
|
|
3
|
+
|
|
4
|
+
export default {
|
|
5
|
+
presets: {
|
|
6
|
+
'theme-to-design-tokens': themeToDesignTokens,
|
|
7
|
+
'css-to-design-tokens': cssToDesignTokens,
|
|
8
|
+
},
|
|
9
|
+
};
|