@atlaskit/tokens 1.49.1 → 1.51.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 (115) hide show
  1. package/CHANGELOG.md +1593 -1594
  2. package/README.md +14 -8
  3. package/codemods/css-to-design-tokens/lib/colors.tsx +47 -49
  4. package/codemods/css-to-design-tokens/lib/declaration.tsx +26 -26
  5. package/codemods/css-to-design-tokens/lib/legacy-colors.tsx +326 -326
  6. package/codemods/css-to-design-tokens/lib/meta.tsx +116 -122
  7. package/codemods/css-to-design-tokens/lib/tokens.tsx +28 -35
  8. package/codemods/css-to-design-tokens/lib/value.tsx +70 -72
  9. package/codemods/css-to-design-tokens/transform.tsx +68 -72
  10. package/codemods/hypermod.config.tsx +5 -5
  11. package/codemods/remove-fallbacks-color/transform.tsx +16 -18
  12. package/codemods/theme-to-design-tokens/transform.tsx +505 -588
  13. package/codemods/theme-to-design-tokens/utils/ast-meta.tsx +139 -147
  14. package/codemods/theme-to-design-tokens/utils/ast.tsx +23 -34
  15. package/codemods/theme-to-design-tokens/utils/color.tsx +25 -26
  16. package/codemods/theme-to-design-tokens/utils/css-utils.tsx +27 -30
  17. package/codemods/theme-to-design-tokens/utils/fuzzy-search.tsx +272 -290
  18. package/codemods/theme-to-design-tokens/utils/legacy-colors.tsx +224 -224
  19. package/codemods/theme-to-design-tokens/utils/named-colors.tsx +148 -148
  20. package/codemods/theme-to-design-tokens/utils/string-utils.tsx +10 -16
  21. package/codemods/utils/tokens.tsx +371 -371
  22. package/dist/cjs/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
  23. package/dist/cjs/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
  24. package/dist/cjs/artifacts/generated-pairs.js +1 -1
  25. package/dist/cjs/artifacts/theme-import-map.js +1 -1
  26. package/dist/cjs/artifacts/themes/atlassian-typography-minor3.js +2 -2
  27. package/dist/cjs/artifacts/token-default-values.js +1 -1
  28. package/dist/cjs/artifacts/token-names.js +1 -1
  29. package/dist/cjs/artifacts/tokens-raw/atlassian-typography-minor3.js +3 -3
  30. package/dist/es2019/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
  31. package/dist/es2019/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
  32. package/dist/es2019/artifacts/generated-pairs.js +1 -1
  33. package/dist/es2019/artifacts/theme-import-map.js +1 -1
  34. package/dist/es2019/artifacts/themes/atlassian-typography-minor3.js +2 -2
  35. package/dist/es2019/artifacts/token-default-values.js +1 -1
  36. package/dist/es2019/artifacts/token-names.js +1 -1
  37. package/dist/es2019/artifacts/tokens-raw/atlassian-typography-minor3.js +3 -3
  38. package/dist/esm/artifacts/atlassian-dark-token-value-for-contrast-check.js +1 -1
  39. package/dist/esm/artifacts/atlassian-light-token-value-for-contrast-check.js +1 -1
  40. package/dist/esm/artifacts/generated-pairs.js +1 -1
  41. package/dist/esm/artifacts/theme-import-map.js +1 -1
  42. package/dist/esm/artifacts/themes/atlassian-typography-minor3.js +2 -2
  43. package/dist/esm/artifacts/token-default-values.js +1 -1
  44. package/dist/esm/artifacts/token-names.js +1 -1
  45. package/dist/esm/artifacts/tokens-raw/atlassian-typography-minor3.js +3 -3
  46. package/dist/types/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +1 -1
  47. package/dist/types/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +1 -1
  48. package/dist/types/artifacts/generated-pairs.d.ts +1 -1
  49. package/dist/types/artifacts/theme-import-map.d.ts +2 -2
  50. package/dist/types/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
  51. package/dist/types/artifacts/token-default-values.d.ts +1 -1
  52. package/dist/types/artifacts/token-names.d.ts +1 -1
  53. package/dist/types/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
  54. package/dist/types/artifacts/types-internal.d.ts +1 -1
  55. package/dist/types/artifacts/types.d.ts +1 -1
  56. package/dist/types/babel-plugin/plugin.d.ts +1 -1
  57. package/dist/types/custom-theme.d.ts +2 -2
  58. package/dist/types/enable-global-theme.d.ts +2 -2
  59. package/dist/types/entry-points/css-type-schema.codegen.d.ts +1 -1
  60. package/dist/types/entry-points/token-ids.d.ts +1 -1
  61. package/dist/types/get-global-theme.d.ts +1 -1
  62. package/dist/types/get-ssr-auto-script.d.ts +1 -1
  63. package/dist/types/get-theme-html-attrs.d.ts +1 -1
  64. package/dist/types/get-theme-styles.d.ts +1 -1
  65. package/dist/types/get-token.d.ts +1 -1
  66. package/dist/types/index.d.ts +1 -1
  67. package/dist/types/load-custom-theme-styles.d.ts +1 -1
  68. package/dist/types/set-global-theme.d.ts +2 -2
  69. package/dist/types/theme-state-transformer.d.ts +1 -1
  70. package/dist/types/utils/color-detection.d.ts +1 -1
  71. package/dist/types/utils/color-mode-listeners.d.ts +1 -1
  72. package/dist/types/utils/configure-page.d.ts +1 -1
  73. package/dist/types/utils/contrast-mode-listeners.d.ts +1 -1
  74. package/dist/types/utils/custom-theme-loading-utils.d.ts +1 -1
  75. package/dist/types/utils/custom-theme-token-contrast-check.d.ts +1 -1
  76. package/dist/types/utils/generate-custom-color-ramp.d.ts +2 -2
  77. package/dist/types/utils/get-increased-contrast-theme.d.ts +1 -1
  78. package/dist/types/utils/get-theme-preferences.d.ts +1 -1
  79. package/dist/types/utils/theme-loading.d.ts +1 -1
  80. package/dist/types-ts4.5/artifacts/atlassian-dark-token-value-for-contrast-check.d.ts +1 -1
  81. package/dist/types-ts4.5/artifacts/atlassian-light-token-value-for-contrast-check.d.ts +1 -1
  82. package/dist/types-ts4.5/artifacts/generated-pairs.d.ts +1 -1
  83. package/dist/types-ts4.5/artifacts/theme-import-map.d.ts +2 -2
  84. package/dist/types-ts4.5/artifacts/themes/atlassian-typography-minor3.d.ts +2 -2
  85. package/dist/types-ts4.5/artifacts/token-default-values.d.ts +1 -1
  86. package/dist/types-ts4.5/artifacts/token-names.d.ts +1 -1
  87. package/dist/types-ts4.5/artifacts/tokens-raw/atlassian-typography-minor3.d.ts +1 -1
  88. package/dist/types-ts4.5/artifacts/types-internal.d.ts +1 -1
  89. package/dist/types-ts4.5/artifacts/types.d.ts +1 -1
  90. package/dist/types-ts4.5/babel-plugin/plugin.d.ts +1 -1
  91. package/dist/types-ts4.5/custom-theme.d.ts +2 -2
  92. package/dist/types-ts4.5/enable-global-theme.d.ts +2 -2
  93. package/dist/types-ts4.5/entry-points/css-type-schema.codegen.d.ts +1 -1
  94. package/dist/types-ts4.5/entry-points/token-ids.d.ts +1 -1
  95. package/dist/types-ts4.5/get-global-theme.d.ts +1 -1
  96. package/dist/types-ts4.5/get-ssr-auto-script.d.ts +1 -1
  97. package/dist/types-ts4.5/get-theme-html-attrs.d.ts +1 -1
  98. package/dist/types-ts4.5/get-theme-styles.d.ts +1 -1
  99. package/dist/types-ts4.5/get-token.d.ts +1 -1
  100. package/dist/types-ts4.5/index.d.ts +1 -1
  101. package/dist/types-ts4.5/load-custom-theme-styles.d.ts +1 -1
  102. package/dist/types-ts4.5/set-global-theme.d.ts +2 -2
  103. package/dist/types-ts4.5/theme-state-transformer.d.ts +1 -1
  104. package/dist/types-ts4.5/utils/color-detection.d.ts +1 -1
  105. package/dist/types-ts4.5/utils/color-mode-listeners.d.ts +1 -1
  106. package/dist/types-ts4.5/utils/configure-page.d.ts +1 -1
  107. package/dist/types-ts4.5/utils/contrast-mode-listeners.d.ts +1 -1
  108. package/dist/types-ts4.5/utils/custom-theme-loading-utils.d.ts +1 -1
  109. package/dist/types-ts4.5/utils/custom-theme-token-contrast-check.d.ts +1 -1
  110. package/dist/types-ts4.5/utils/generate-custom-color-ramp.d.ts +2 -2
  111. package/dist/types-ts4.5/utils/get-increased-contrast-theme.d.ts +1 -1
  112. package/dist/types-ts4.5/utils/get-theme-preferences.d.ts +1 -1
  113. package/dist/types-ts4.5/utils/theme-loading.d.ts +1 -1
  114. package/package.json +138 -140
  115. package/report.api.md +2071 -2090
package/README.md CHANGED
@@ -16,12 +16,14 @@ yarn add @atlaskit/tokens
16
16
 
17
17
  A babel plugin to optimise performance and support fallbacks for Design System tokens.
18
18
 
19
- It replaces any calls to the `@atlaskit/tokens` token() function with the CSS value the function would return (i.e. var(--token-name) or
20
- variations with fallbacks).
19
+ It replaces any calls to the `@atlaskit/tokens` token() function with the CSS value the function
20
+ would return (i.e. var(--token-name) or variations with fallbacks).
21
21
 
22
- If there’s no fallback, the plugin (optionally) finds the token’s value from the default Atlassian theme, and sets it as the fallback.
22
+ If there’s no fallback, the plugin (optionally) finds the token’s value from the default Atlassian
23
+ theme, and sets it as the fallback.
23
24
 
24
- If there is a fallback defined in code, it’s inserted into the style (expressions are inserted using template strings).
25
+ If there is a fallback defined in code, it’s inserted into the style (expressions are inserted using
26
+ template strings).
25
27
 
26
28
  ## Usage
27
29
 
@@ -29,13 +31,17 @@ Add the plugin to your babel configuration:
29
31
 
30
32
  ```
31
33
  {
32
- "plugins": ["@atlaskit/tokens/babel-plugin"]
34
+ "plugins": [
35
+ ["@atlaskit/tokens/babel-plugin", { "shouldUseAutoFallback": true }]
36
+ ]
33
37
  }
34
38
  ```
35
39
 
36
40
  ### Options
37
41
 
38
- Currently the plugin supports one option, `shouldUseAutoFallback`. When enabled, the plugin will fetch the token's value in the default
39
- Atlassian theme (currently `atlassian-light`) and use it as the fallback value.
42
+ Currently the plugin supports one option, `shouldUseAutoFallback`. When enabled, the plugin will
43
+ fetch the token's value in the default Atlassian theme (currently `atlassian-light`) and use it as
44
+ the fallback value.
40
45
 
41
- This is useful for cases where tokens are in use, but token definitions aren't present in the top-level page CSS.
46
+ This is useful for cases where tokens are in use, but token definitions aren't guaranteed to be
47
+ present in the top-level page CSS.
@@ -3,69 +3,67 @@ import { knownNamedColors, knownVariables } from './legacy-colors';
3
3
  const NAMED_COLORS = Object.keys(knownNamedColors);
4
4
  const GRADIENT_TYPES = ['linear', 'radial', 'conic'] as const;
5
5
  const LESS_COLOR_FUNCTIONS = [
6
- 'lighten',
7
- 'darken',
8
- 'saturate',
9
- 'desaturate',
10
- 'fadein',
11
- 'fadeout',
12
- 'fade',
13
- 'spin',
14
- 'mix',
15
- 'greyscale',
16
- 'contrast',
17
- 'multiply',
18
- 'screen',
19
- 'overlay',
20
- 'softlight',
21
- 'hardlight',
22
- 'difference',
23
- 'exclusion',
24
- 'average',
25
- 'negation',
26
- 'tint',
27
- 'shade',
28
- 'luma',
29
- 'hue',
30
- 'saturation',
31
- 'lightness',
32
- 'alpha',
33
- 'red',
34
- 'green',
35
- 'blue',
6
+ 'lighten',
7
+ 'darken',
8
+ 'saturate',
9
+ 'desaturate',
10
+ 'fadein',
11
+ 'fadeout',
12
+ 'fade',
13
+ 'spin',
14
+ 'mix',
15
+ 'greyscale',
16
+ 'contrast',
17
+ 'multiply',
18
+ 'screen',
19
+ 'overlay',
20
+ 'softlight',
21
+ 'hardlight',
22
+ 'difference',
23
+ 'exclusion',
24
+ 'average',
25
+ 'negation',
26
+ 'tint',
27
+ 'shade',
28
+ 'luma',
29
+ 'hue',
30
+ 'saturation',
31
+ 'lightness',
32
+ 'alpha',
33
+ 'red',
34
+ 'green',
35
+ 'blue',
36
36
  ];
37
37
 
38
38
  const REGEXES = {
39
- // The CSS regular expression matches CSS variable declarations.
40
- // It looks for the string "var(" followed by any characters except a closing parenthesis, and ending with a closing parenthesis.
41
- CSS: /var\([^\)]+\)/g,
42
- // The RAW_COLOR regular expression matches various CSS color formats including hexadecimal, RGB(A), HSL(A), LAB, LCH, and HWB.
43
- // It allows for optional leading and trailing white spaces.
44
- // For RGBA and HSLA, it allows any number (including negative numbers and numbers greater than 1) for the alpha channel.
45
- // For RGB, HSL, LAB, LCH, and HWB, it expects three comma-separated values.
46
- // It also allows optional white spaces around the commas and the values.
47
- RAW_COLOR:
48
- /^\s*(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\s*\d{1,3}%?\s*(,\s*\d{1,3}%?\s*){2},\s*-?\d*\.?\d+\s*\)|(rgb|hsl)\(\s*\d{1,3}%?\s*(,\s*\d{1,3}%?\s*){2}\)\s*|(lab|lch)\(\s*\d{1,3}%?\s+\d{1,3}%?\s+\d{1,3}%?\s*\)|hwb\(\s*\d{1,3}\s+\d{1,3}%?\s+\d{1,3}%?\s*\))\s*$/i,
39
+ // The CSS regular expression matches CSS variable declarations.
40
+ // It looks for the string "var(" followed by any characters except a closing parenthesis, and ending with a closing parenthesis.
41
+ CSS: /var\([^\)]+\)/g,
42
+ // The RAW_COLOR regular expression matches various CSS color formats including hexadecimal, RGB(A), HSL(A), LAB, LCH, and HWB.
43
+ // It allows for optional leading and trailing white spaces.
44
+ // For RGBA and HSLA, it allows any number (including negative numbers and numbers greater than 1) for the alpha channel.
45
+ // For RGB, HSL, LAB, LCH, and HWB, it expects three comma-separated values.
46
+ // It also allows optional white spaces around the commas and the values.
47
+ RAW_COLOR:
48
+ /^\s*(#([0-9a-f]{3}){1,2}|(rgba|hsla)\(\s*\d{1,3}%?\s*(,\s*\d{1,3}%?\s*){2},\s*-?\d*\.?\d+\s*\)|(rgb|hsl)\(\s*\d{1,3}%?\s*(,\s*\d{1,3}%?\s*){2}\)\s*|(lab|lch)\(\s*\d{1,3}%?\s+\d{1,3}%?\s+\d{1,3}%?\s*\)|hwb\(\s*\d{1,3}\s+\d{1,3}%?\s+\d{1,3}%?\s*\))\s*$/i,
49
49
  };
50
50
 
51
51
  export function isKnownCssVariable(value: string) {
52
- return value in knownVariables;
52
+ return value in knownVariables;
53
53
  }
54
54
  export function isRawColor(value: string) {
55
- return REGEXES.RAW_COLOR.test(value);
55
+ return REGEXES.RAW_COLOR.test(value);
56
56
  }
57
57
  export function isNamedColor(value: string) {
58
- return NAMED_COLORS.includes(value);
58
+ return NAMED_COLORS.includes(value);
59
59
  }
60
60
  export function isGradient(value: string) {
61
- return GRADIENT_TYPES.some((gradient) =>
62
- value.startsWith(`${gradient}-gradient(`),
63
- );
61
+ return GRADIENT_TYPES.some((gradient) => value.startsWith(`${gradient}-gradient(`));
64
62
  }
65
63
  export function extractBetweenParentheses(value: string) {
66
- const match = value.match(/\((.*?)\)/);
67
- return match ? match[1] : '';
64
+ const match = value.match(/\((.*?)\)/);
65
+ return match ? match[1] : '';
68
66
  }
69
67
  export function isLessFunction(value: string) {
70
- return LESS_COLOR_FUNCTIONS.some((func) => value.startsWith(`${func}(`));
68
+ return LESS_COLOR_FUNCTIONS.some((func) => value.startsWith(`${func}(`));
71
69
  }
@@ -1,43 +1,43 @@
1
1
  const COLOR_PROPERTIES = [
2
- 'color',
3
- 'background',
4
- 'background-color',
5
- 'box-shadow',
6
- 'border',
7
- 'border-left',
8
- 'border-right',
9
- 'border-top',
10
- 'border-bottom',
11
- 'border-color',
12
- 'border-left-color',
13
- 'border-right-color',
14
- 'border-top-color',
15
- 'border-bottom-color',
16
- 'outline',
17
- 'outline-color',
18
- 'accent-color',
19
- 'caret-color',
20
- 'scrollbar-color',
21
- 'text-stroke',
2
+ 'color',
3
+ 'background',
4
+ 'background-color',
5
+ 'box-shadow',
6
+ 'border',
7
+ 'border-left',
8
+ 'border-right',
9
+ 'border-top',
10
+ 'border-bottom',
11
+ 'border-color',
12
+ 'border-left-color',
13
+ 'border-right-color',
14
+ 'border-top-color',
15
+ 'border-bottom-color',
16
+ 'outline',
17
+ 'outline-color',
18
+ 'accent-color',
19
+ 'caret-color',
20
+ 'scrollbar-color',
21
+ 'text-stroke',
22
22
  ] as const;
23
23
 
24
24
  export function isColorRelatedProperty(prop: string) {
25
- return COLOR_PROPERTIES.some((property) => property === prop);
25
+ return COLOR_PROPERTIES.some((property) => property === prop);
26
26
  }
27
27
 
28
28
  export function isCssDeclaration(prop: string) {
29
- return prop.startsWith('--');
29
+ return prop.startsWith('--');
30
30
  }
31
31
 
32
32
  export function extractCssVarName(prop: string) {
33
- return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
33
+ return prop.substring(prop.indexOf('(') + 1).split(/\,|\)/)[0];
34
34
  }
35
35
 
36
36
  export function extractLessVarName(prop: string) {
37
- return prop.substring(1);
37
+ return prop.substring(1);
38
38
  }
39
39
 
40
40
  export function splitCssValue(value: string) {
41
- const regex = /(?:[^\s()]+|\((?:[^()]+|\([^()]*\))*\))+/g;
42
- return value.match(regex);
41
+ const regex = /(?:[^\s()]+|\((?:[^()]+|\([^()]*\))*\))+/g;
42
+ return value.match(regex);
43
43
  }