@primer/primitives 10.0.0 → 10.1.0-rc.3495b605

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 (155) hide show
  1. package/README.md +0 -21
  2. package/dist/build/filters/index.d.ts +0 -1
  3. package/dist/build/filters/index.js +0 -1
  4. package/dist/build/filters/isColor.js +0 -3
  5. package/dist/build/formats/jsonFigma.js +1 -2
  6. package/dist/build/formats/typescriptExportDefinition.js +2 -2
  7. package/dist/build/platforms/css.d.ts +1 -1
  8. package/dist/build/platforms/css.js +10 -7
  9. package/dist/build/platforms/deprecatedJson.d.ts +1 -1
  10. package/dist/build/platforms/docJson.d.ts +1 -1
  11. package/dist/build/platforms/docJson.js +5 -2
  12. package/dist/build/platforms/fallbacks.d.ts +1 -1
  13. package/dist/build/platforms/fallbacks.js +0 -1
  14. package/dist/build/platforms/figma.d.ts +1 -1
  15. package/dist/build/platforms/figma.js +6 -3
  16. package/dist/build/platforms/javascript.d.ts +1 -1
  17. package/dist/build/platforms/javascript.js +5 -2
  18. package/dist/build/platforms/json.d.ts +1 -1
  19. package/dist/build/platforms/json.js +5 -2
  20. package/dist/build/platforms/styleLint.d.ts +1 -1
  21. package/dist/build/platforms/styleLint.js +5 -2
  22. package/dist/build/platforms/typeDefinitions.d.ts +1 -1
  23. package/dist/build/platforms/typeDefinitions.js +5 -1
  24. package/dist/build/platforms/typescript.d.ts +1 -1
  25. package/dist/build/platforms/typescript.js +5 -2
  26. package/dist/build/preprocessors/themeOverrides.d.ts +2 -0
  27. package/dist/build/preprocessors/themeOverrides.js +22 -0
  28. package/dist/build/preprocessors/utilities/transformTokens.d.ts +8 -0
  29. package/dist/build/preprocessors/utilities/transformTokens.js +22 -0
  30. package/dist/build/{PrimerStyleDictionary.js → primerStyleDictionary.js} +9 -3
  31. package/dist/build/schemas/colorToken.d.ts +75 -18
  32. package/dist/build/schemas/colorToken.js +23 -7
  33. package/dist/build/transformers/borderToCss.js +2 -2
  34. package/dist/build/transformers/colorToRgbaFloat.js +2 -12
  35. package/dist/build/transformers/figmaAttributes.js +1 -1
  36. package/dist/build/transformers/index.d.ts +0 -1
  37. package/dist/build/transformers/index.js +0 -1
  38. package/dist/build/transformers/utilities/invalidTokenError.js +0 -2
  39. package/dist/build/types/{StyleDictionaryConfigGenerator.d.ts → styleDictionaryConfigGenerator.d.ts} +1 -0
  40. package/dist/build/types/{TokenBuildInput.d.ts → tokenBuildInput.d.ts} +2 -0
  41. package/dist/build/utilities/lowerCaseFirstCharacter.d.ts +8 -0
  42. package/dist/build/utilities/lowerCaseFirstCharacter.js +10 -0
  43. package/dist/css/functional/size/border.css +7 -6
  44. package/dist/css/functional/themes/dark-colorblind.css +60 -6
  45. package/dist/css/functional/themes/dark-dimmed.css +60 -6
  46. package/dist/css/functional/themes/dark-high-contrast.css +60 -6
  47. package/dist/css/functional/themes/dark-tritanopia.css +60 -6
  48. package/dist/css/functional/themes/dark.css +60 -6
  49. package/dist/css/functional/themes/light-colorblind.css +60 -6
  50. package/dist/css/functional/themes/light-high-contrast.css +60 -6
  51. package/dist/css/functional/themes/light-tritanopia.css +60 -6
  52. package/dist/css/functional/themes/light.css +60 -6
  53. package/dist/css/primitives.css +7 -6
  54. package/dist/docs/base/size/size.json +19 -19
  55. package/dist/docs/base/typography/typography.json +4 -4
  56. package/dist/docs/functional/size/border.json +41 -28
  57. package/dist/docs/functional/size/breakpoints.json +6 -6
  58. package/dist/docs/functional/size/size-coarse.json +3 -3
  59. package/dist/docs/functional/size/size-fine.json +3 -3
  60. package/dist/docs/functional/size/size.json +66 -66
  61. package/dist/docs/functional/size/viewport.json +6 -6
  62. package/dist/docs/functional/themes/dark-colorblind.json +475 -128
  63. package/dist/docs/functional/themes/dark-dimmed.json +519 -444
  64. package/dist/docs/functional/themes/dark-high-contrast.json +490 -241
  65. package/dist/docs/functional/themes/dark-tritanopia.json +485 -200
  66. package/dist/docs/functional/themes/dark.json +469 -102
  67. package/dist/docs/functional/themes/light-colorblind.json +463 -94
  68. package/dist/docs/functional/themes/light-high-contrast.json +487 -274
  69. package/dist/docs/functional/themes/light-tritanopia.json +463 -102
  70. package/dist/docs/functional/themes/light.json +460 -105
  71. package/dist/docs/functional/typography/typography.json +46 -46
  72. package/dist/fallbacks/functional/size/border.json +7 -6
  73. package/dist/figma/figma.json +0 -8
  74. package/dist/figma/themes/dark-colorblind.json +14 -54
  75. package/dist/figma/themes/dark-dimmed.json +15 -356
  76. package/dist/figma/themes/dark-high-contrast.json +10 -129
  77. package/dist/figma/themes/dark-tritanopia.json +14 -111
  78. package/dist/figma/themes/dark.json +14 -34
  79. package/dist/figma/themes/light-colorblind.json +10 -20
  80. package/dist/figma/themes/light-high-contrast.json +10 -177
  81. package/dist/figma/themes/light-tritanopia.json +10 -24
  82. package/dist/figma/themes/light.json +10 -32
  83. package/dist/internalCss/dark-colorblind.css +88 -6
  84. package/dist/internalCss/dark-dimmed.css +88 -6
  85. package/dist/internalCss/dark-high-contrast.css +88 -6
  86. package/dist/internalCss/dark-tritanopia.css +88 -6
  87. package/dist/internalCss/dark.css +88 -6
  88. package/dist/internalCss/light-colorblind.css +88 -6
  89. package/dist/internalCss/light-high-contrast.css +88 -6
  90. package/dist/internalCss/light-tritanopia.css +88 -6
  91. package/dist/internalCss/light.css +88 -6
  92. package/dist/styleLint/base/size/size.json +19 -19
  93. package/dist/styleLint/base/typography/typography.json +4 -4
  94. package/dist/styleLint/functional/size/border.json +41 -28
  95. package/dist/styleLint/functional/size/breakpoints.json +6 -6
  96. package/dist/styleLint/functional/size/size-coarse.json +3 -3
  97. package/dist/styleLint/functional/size/size-fine.json +3 -3
  98. package/dist/styleLint/functional/size/size.json +66 -66
  99. package/dist/styleLint/functional/size/viewport.json +6 -6
  100. package/dist/styleLint/functional/themes/dark-colorblind.json +475 -128
  101. package/dist/styleLint/functional/themes/dark-dimmed.json +519 -444
  102. package/dist/styleLint/functional/themes/dark-high-contrast.json +490 -241
  103. package/dist/styleLint/functional/themes/dark-tritanopia.json +485 -200
  104. package/dist/styleLint/functional/themes/dark.json +469 -102
  105. package/dist/styleLint/functional/themes/light-colorblind.json +463 -94
  106. package/dist/styleLint/functional/themes/light-high-contrast.json +487 -274
  107. package/dist/styleLint/functional/themes/light-tritanopia.json +463 -102
  108. package/dist/styleLint/functional/themes/light.json +460 -105
  109. package/dist/styleLint/functional/typography/typography.json +46 -46
  110. package/package.json +11 -10
  111. package/src/tokens/base/typography/typography.json5 +48 -0
  112. package/src/tokens/functional/border/border.json5 +236 -0
  113. package/src/tokens/functional/color/dark/app-dark.json5 +0 -2
  114. package/src/tokens/functional/color/dark/overrides/dark.dimmed.json5 +120 -6
  115. package/src/tokens/functional/color/dark/overrides/dark.high-contrast.json5 +46 -29
  116. package/src/tokens/functional/color/dark/overrides/dark.protanopia-deuteranopia.json5 +15 -20
  117. package/src/tokens/functional/color/dark/overrides/dark.tritanopia.json5 +32 -18
  118. package/src/tokens/functional/color/dark/patterns-dark.json5 +13 -45
  119. package/src/tokens/functional/color/dark/primitives-dark.json5 +1 -6
  120. package/src/tokens/functional/color/light/overrides/light.high-contrast.json5 +67 -20
  121. package/src/tokens/functional/color/light/overrides/light.protanopia-deuteranopia.json5 +4 -21
  122. package/src/tokens/functional/color/light/overrides/light.tritanopia.json5 +3 -16
  123. package/src/tokens/functional/color/light/patterns-light.json5 +11 -47
  124. package/src/tokens/functional/color/light/primitives-light.json5 +2 -10
  125. package/src/tokens/functional/size/border.json5 +115 -0
  126. package/src/tokens/functional/typography/typography.json5 +527 -0
  127. package/dist/build/filters/isColorWithMix.d.ts +0 -7
  128. package/dist/build/filters/isColorWithMix.js +0 -24
  129. package/dist/build/transformers/colorToHexMix.d.ts +0 -8
  130. package/dist/build/transformers/colorToHexMix.js +0 -20
  131. package/dist/build/transformers/utilities/mix.d.ts +0 -5
  132. package/dist/build/transformers/utilities/mix.js +0 -38
  133. package/src/tokens/base/typography/typography.json +0 -48
  134. package/src/tokens/functional/border/dark.json5 +0 -12
  135. package/src/tokens/functional/border/light.json5 +0 -12
  136. package/src/tokens/functional/color/dark/patterns-dark.json +0 -3963
  137. package/src/tokens/functional/size/border.json +0 -111
  138. package/src/tokens/functional/typography/typography.json +0 -527
  139. /package/dist/build/{PrimerStyleDictionary.d.ts → primerStyleDictionary.d.ts} +0 -0
  140. /package/dist/build/types/{Border.d.ts → border.d.ts} +0 -0
  141. /package/dist/build/types/{BorderTokenValue.d.ts → borderTokenValue.d.ts} +0 -0
  142. /package/dist/build/types/{ColorHex.d.ts → colorHex.d.ts} +0 -0
  143. /package/dist/build/types/{PlatformInitializer.d.ts → platformInitializer.d.ts} +0 -0
  144. /package/dist/build/types/{Shadow.d.ts → shadow.d.ts} +0 -0
  145. /package/dist/build/types/{ShadowTokenValue.d.ts → shadowTokenValue.d.ts} +0 -0
  146. /package/dist/build/types/{SizeEm.d.ts → sizeEm.d.ts} +0 -0
  147. /package/dist/build/types/{SizePx.d.ts → sizePx.d.ts} +0 -0
  148. /package/dist/build/types/{SizeRem.d.ts → sizeRem.d.ts} +0 -0
  149. /package/dist/build/types/{TypographyTokenValue.d.ts → typographyTokenValue.d.ts} +0 -0
  150. /package/src/tokens/base/size/{size.json → size.json5} +0 -0
  151. /package/src/tokens/functional/size/{breakpoints.json → breakpoints.json5} +0 -0
  152. /package/src/tokens/functional/size/{size-coarse.json → size-coarse.json5} +0 -0
  153. /package/src/tokens/functional/size/{size-fine.json → size-fine.json5} +0 -0
  154. /package/src/tokens/functional/size/{size.json → size.json5} +0 -0
  155. /package/src/tokens/functional/size/{viewport.json → viewport.json5} +0 -0
package/README.md CHANGED
@@ -80,27 +80,6 @@ You can create color tokens that inherit a color but have a different alpha valu
80
80
  }
81
81
  ```
82
82
 
83
- #### Mix
84
-
85
- In rare cases, you may need to create a color between two steps in the color scale, e.g. between `gray.4` and `gray.5`. A common example are interactive states, like `hover` where a full step on the color scale would be to much. For those cases you can use the `mix` property.
86
-
87
- The `mix` proeprty mixes the color it gets into the main color from the `$value` attribute. The amount added is controlled by the `weight`. A weight of `0.1` adds 10% of the color, and a weight of `0.75` adds 75%.
88
-
89
- A `mix` proprty must always have a `color` and a `weight` child. `color` can be a `hex` value or a reference to a valid color. The `weight` property must receive a value between `0.0` and `1`.
90
-
91
- ```json5
92
- {
93
- control: {
94
- $value: '{base.color.gray.4}', // main color
95
- $type: 'color',
96
- mix: {
97
- color: '{base.color.gray.5}', // color to mix into the main color
98
- weight: 0.2, // amount of the mix color that is added === 20% of gray.5 is mix into gray.4
99
- },
100
- },
101
- }
102
- ```
103
-
104
83
  #### Extensions property
105
84
 
106
85
  According to the [w3c design token specs](https://design-tokens.github.io/community-group/format/#design-token), the [`$extensions`](https://design-tokens.github.io/community-group/format/#extensions) property is used for additional meta data.
@@ -1,7 +1,6 @@
1
1
  export { isBorder } from './isBorder.js';
2
2
  export { isColor } from './isColor.js';
3
3
  export { isColorWithAlpha } from './isColorWithAlpha.js';
4
- export { isColorWithMix } from './isColorWithMix.js';
5
4
  export { isDimension } from './isDimension.js';
6
5
  export { isDeprecated } from './isDeprecated.js';
7
6
  export { isDuration } from './isDuration.js';
@@ -1,7 +1,6 @@
1
1
  export { isBorder } from './isBorder.js';
2
2
  export { isColor } from './isColor.js';
3
3
  export { isColorWithAlpha } from './isColorWithAlpha.js';
4
- export { isColorWithMix } from './isColorWithMix.js';
5
4
  export { isDimension } from './isDimension.js';
6
5
  export { isDeprecated } from './isDeprecated.js';
7
6
  export { isDuration } from './isDuration.js';
@@ -6,8 +6,5 @@
6
6
  export const isColor = (token) => {
7
7
  var _a;
8
8
  const typeValue = (_a = token.$type) !== null && _a !== void 0 ? _a : token.type;
9
- // if (token.path.join('-') === 'control-transparent-bgColor-selected') {
10
- // console.log(typeValue === 'color', token)
11
- // }
12
9
  return typeValue === 'color';
13
10
  };
@@ -76,7 +76,7 @@ export const jsonFigma = (_a) => __awaiter(void 0, [_a], void 0, function* ({ di
76
76
  // loop through tokens sorted by reference
77
77
  for (const token of sortedTokens) {
78
78
  // deconstruct token
79
- const { attributes, $value: value, $type, $description: description, original, alpha, mix } = token;
79
+ const { attributes, $value: value, $type, $description: description, original, alpha } = token;
80
80
  const { mode, collection, scopes, group, codeSyntax } = attributes || {};
81
81
  // early escape if no type is present
82
82
  if (!$type)
@@ -102,7 +102,6 @@ export const jsonFigma = (_a) => __awaiter(void 0, [_a], void 0, function* ({ di
102
102
  value,
103
103
  type: getFigmaType($type),
104
104
  alpha,
105
- isMix: mix ? true : undefined,
106
105
  description,
107
106
  refId: [collection, token.name].filter(Boolean).join('/'),
108
107
  reference: getReference(dictionary, original.$value, platform),
@@ -14,6 +14,7 @@ import { treeWalker } from '../utilities/treeWalker.js';
14
14
  import { prefixTokens } from './utilities/prefixTokens.js';
15
15
  import { fileHeader } from 'style-dictionary/utils';
16
16
  import { getPropName } from './utilities/getPropName.js';
17
+ import { lowerCaseFirstCharacter } from '../utilities/lowerCaseFirstCharacter.js';
17
18
  /**
18
19
  * unquoteTypes
19
20
  * @description extract types from designTokenTypes (string with type definitions from file) and replace quoted types "Color" with unquoted Color
@@ -38,7 +39,6 @@ const getTokenType = (tokenTypesPath) => {
38
39
  return designTokenType;
39
40
  }
40
41
  catch (error) {
41
- // eslint-disable-next-line no-console
42
42
  throw new Error(`Error trying to load design token type from file "${tokenTypesPath}". Error: ${error}`);
43
43
  }
44
44
  };
@@ -147,7 +147,7 @@ const getTypeDefinition = (tokens, options) => {
147
147
  for (const type of usedTypes) {
148
148
  // path to type files without trailing slash
149
149
  const typePath = tokenTypesPath.replace(new RegExp(/\/$/, 'g'), '');
150
- designTokenTypes.push(getTokenType(`${typePath}/${type}.d.ts`));
150
+ designTokenTypes.push(getTokenType(`${typePath}/${lowerCaseFirstCharacter(type)}.d.ts`));
151
151
  }
152
152
  // build output
153
153
  const output = `${designTokenTypes.join('\n')}
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.ts';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const css: PlatformInitializer;
@@ -19,10 +19,10 @@ export const css = (outputFile, prefix, buildPath, options) => {
19
19
  return {
20
20
  prefix,
21
21
  buildPath,
22
+ preprocessors: ['themeOverrides'],
22
23
  transforms: [
23
24
  'name/pathToKebabCase',
24
25
  'color/hex',
25
- 'color/hexMix',
26
26
  'cubicBezier/css',
27
27
  'dimension/rem',
28
28
  'duration/css',
@@ -34,6 +34,9 @@ export const css = (outputFile, prefix, buildPath, options) => {
34
34
  ],
35
35
  options: {
36
36
  basePxFontSize: 16,
37
+ themeOverrides: {
38
+ theme: options === null || options === void 0 ? void 0 : options.theme,
39
+ },
37
40
  },
38
41
  files: [
39
42
  {
@@ -43,8 +46,8 @@ export const css = (outputFile, prefix, buildPath, options) => {
43
46
  (options === null || options === void 0 ? void 0 : options.themed) === true &&
44
47
  token.$type !== 'custom-viewportRange' &&
45
48
  !isFromFile(token, [
46
- 'src/tokens/functional/size/size-coarse.json',
47
- 'src/tokens/functional/size/size-fine.json',
49
+ 'src/tokens/functional/size/size-coarse.json5',
50
+ 'src/tokens/functional/size/size-fine.json5',
48
51
  ]),
49
52
  options: Object.assign({ showFileHeader: false, outputReferences: false, descriptions: false, queries: getCssSelectors(outputFile) }, options === null || options === void 0 ? void 0 : options.options),
50
53
  },
@@ -55,8 +58,8 @@ export const css = (outputFile, prefix, buildPath, options) => {
55
58
  (options === null || options === void 0 ? void 0 : options.themed) !== true &&
56
59
  token.$type !== 'custom-viewportRange' &&
57
60
  !isFromFile(token, [
58
- 'src/tokens/functional/size/size-coarse.json',
59
- 'src/tokens/functional/size/size-fine.json',
61
+ 'src/tokens/functional/size/size-coarse.json5',
62
+ 'src/tokens/functional/size/size-fine.json5',
60
63
  ]),
61
64
  options: Object.assign({ showFileHeader: false, descriptions: false }, options === null || options === void 0 ? void 0 : options.options),
62
65
  },
@@ -73,8 +76,8 @@ export const css = (outputFile, prefix, buildPath, options) => {
73
76
  format: `css/advanced`,
74
77
  filter: token => isSource(token) &&
75
78
  isFromFile(token, [
76
- 'src/tokens/functional/size/size-coarse.json',
77
- 'src/tokens/functional/size/size-fine.json',
79
+ 'src/tokens/functional/size/size-coarse.json5',
80
+ 'src/tokens/functional/size/size-fine.json5',
78
81
  ]),
79
82
  options: {
80
83
  descriptions: false,
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const deprecatedJson: PlatformInitializer;
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const docJson: PlatformInitializer;
@@ -1,11 +1,11 @@
1
1
  import { isSource } from '../filters/index.js';
2
- export const docJson = (outputFile, prefix, buildPath) => ({
2
+ export const docJson = (outputFile, prefix, buildPath, options) => ({
3
3
  prefix,
4
4
  buildPath,
5
+ preprocessors: ['themeOverrides'],
5
6
  transforms: [
6
7
  'name/pathToKebabCase',
7
8
  'color/hex',
8
- 'color/hexMix',
9
9
  'dimension/rem',
10
10
  'shadow/css',
11
11
  'border/css',
@@ -20,6 +20,9 @@ export const docJson = (outputFile, prefix, buildPath) => ({
20
20
  $type: 'type',
21
21
  $description: 'description',
22
22
  },
23
+ themeOverrides: {
24
+ theme: options === null || options === void 0 ? void 0 : options.theme,
25
+ },
23
26
  },
24
27
  files: [
25
28
  {
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const fallbacks: PlatformInitializer;
@@ -5,7 +5,6 @@ export const fallbacks = (outputFile, prefix, buildPath) => ({
5
5
  transforms: [
6
6
  'name/pathToKebabCase',
7
7
  'color/hex',
8
- 'color/hexMix',
9
8
  'dimension/rem',
10
9
  'shadow/css',
11
10
  'border/css',
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const figma: PlatformInitializer;
@@ -27,6 +27,7 @@ const validFigmaToken = (token, options) => __awaiter(void 0, void 0, void 0, fu
27
27
  export const figma = (outputFile, prefix, buildPath, options) => ({
28
28
  prefix,
29
29
  buildPath,
30
+ preprocessors: ['themeOverrides'],
30
31
  transforms: [
31
32
  'color/rgbaFloat',
32
33
  'fontFamily/figma',
@@ -38,12 +39,14 @@ export const figma = (outputFile, prefix, buildPath, options) => ({
38
39
  'figma/attributes',
39
40
  'name/pathToFigma',
40
41
  ],
41
- options: Object.assign({ basePxFontSize: 16, fontFamilies: {
42
+ options: Object.assign(Object.assign({ basePxFontSize: 16, fontFamilies: {
42
43
  'fontStack/system': 'SF Pro Text',
43
44
  'fontStack/sansSerif': 'SF Pro Text',
44
45
  'fontStack/sansSerifDisplay': 'SF Pro Display',
45
46
  'fontStack/monospace': 'SF Mono',
46
- } }, options),
47
+ } }, options), { themeOverrides: {
48
+ theme: options === null || options === void 0 ? void 0 : options.theme,
49
+ } }),
47
50
  files: [
48
51
  {
49
52
  destination: outputFile,
@@ -53,7 +56,7 @@ export const figma = (outputFile, prefix, buildPath, options) => ({
53
56
  format: `json/figma`,
54
57
  options: {
55
58
  outputReferences: true,
56
- mode: options === null || options === void 0 ? void 0 : options.mode,
59
+ theme: options === null || options === void 0 ? void 0 : options.theme,
57
60
  },
58
61
  },
59
62
  ],
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const javascript: PlatformInitializer;
@@ -1,10 +1,10 @@
1
1
  import { isSource } from '../filters/index.js';
2
- export const javascript = (outputFile, prefix, buildPath) => ({
2
+ export const javascript = (outputFile, prefix, buildPath, options) => ({
3
3
  prefix,
4
4
  buildPath,
5
+ preprocessors: ['themeOverrides'],
5
6
  transforms: [
6
7
  'color/hex',
7
- 'color/hexMix',
8
8
  'dimension/rem',
9
9
  'shadow/css',
10
10
  'border/css',
@@ -15,6 +15,9 @@ export const javascript = (outputFile, prefix, buildPath) => ({
15
15
  options: {
16
16
  showFileHeader: false,
17
17
  basePxFontSize: 16,
18
+ themeOverrides: {
19
+ theme: options === null || options === void 0 ? void 0 : options.theme,
20
+ },
18
21
  },
19
22
  files: [
20
23
  {
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const json: PlatformInitializer;
@@ -1,10 +1,10 @@
1
1
  import { isSource } from '../filters/index.js';
2
- export const json = (outputFile, prefix, buildPath) => ({
2
+ export const json = (outputFile, prefix, buildPath, options) => ({
3
3
  prefix,
4
4
  buildPath,
5
+ preprocessors: ['themeOverrides'],
5
6
  transforms: [
6
7
  'color/hex',
7
- 'color/hexMix',
8
8
  'dimension/rem',
9
9
  'shadow/css',
10
10
  'border/css',
@@ -14,6 +14,9 @@ export const json = (outputFile, prefix, buildPath) => ({
14
14
  ],
15
15
  options: {
16
16
  basePxFontSize: 16,
17
+ themeOverrides: {
18
+ theme: options === null || options === void 0 ? void 0 : options.theme,
19
+ },
17
20
  },
18
21
  files: [
19
22
  {
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const styleLint: PlatformInitializer;
@@ -1,11 +1,11 @@
1
1
  import { isSource } from '../filters/index.js';
2
- export const styleLint = (outputFile, prefix, buildPath) => ({
2
+ export const styleLint = (outputFile, prefix, buildPath, options) => ({
3
3
  prefix,
4
4
  buildPath,
5
+ preprocessors: ['themeOverrides'],
5
6
  transforms: [
6
7
  'name/pathToKebabCase',
7
8
  'color/hex',
8
- 'color/hexMix',
9
9
  'dimension/remPxArray',
10
10
  'shadow/css',
11
11
  'border/css',
@@ -15,6 +15,9 @@ export const styleLint = (outputFile, prefix, buildPath) => ({
15
15
  ],
16
16
  options: {
17
17
  basePxFontSize: 16,
18
+ themeOverrides: {
19
+ theme: options === null || options === void 0 ? void 0 : options.theme,
20
+ },
18
21
  },
19
22
  files: [
20
23
  {
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const typeDefinitions: PlatformInitializer;
@@ -1,8 +1,9 @@
1
1
  import { isSource } from '../filters/index.js';
2
2
  import { upperCaseFirstCharacter } from '../utilities/index.js';
3
- export const typeDefinitions = (outputFile, prefix, buildPath) => ({
3
+ export const typeDefinitions = (outputFile, prefix, buildPath, options) => ({
4
4
  prefix,
5
5
  buildPath,
6
+ preprocessors: ['themeOverrides'],
6
7
  transforms: [
7
8
  'color/hex',
8
9
  'shadow/css',
@@ -20,6 +21,9 @@ export const typeDefinitions = (outputFile, prefix, buildPath) => ({
20
21
  options: {
21
22
  tokenTypesPath: './src/types/',
22
23
  moduleName: `${upperCaseFirstCharacter(outputFile)}DesignTokens`,
24
+ themeOverrides: {
25
+ theme: options === null || options === void 0 ? void 0 : options.theme,
26
+ },
23
27
  },
24
28
  },
25
29
  ],
@@ -1,2 +1,2 @@
1
- import type { PlatformInitializer } from '../types/PlatformInitializer.js';
1
+ import type { PlatformInitializer } from '../types/platformInitializer.js';
2
2
  export declare const typescript: PlatformInitializer;
@@ -1,10 +1,10 @@
1
1
  import { isSource } from '../filters/index.js';
2
- export const typescript = (outputFile, prefix, buildPath) => ({
2
+ export const typescript = (outputFile, prefix, buildPath, options) => ({
3
3
  prefix,
4
4
  buildPath,
5
+ preprocessors: ['themeOverrides'],
5
6
  transforms: [
6
7
  'color/hex',
7
- 'color/hexMix',
8
8
  'dimension/rem',
9
9
  'shadow/css',
10
10
  'border/css',
@@ -15,6 +15,9 @@ export const typescript = (outputFile, prefix, buildPath) => ({
15
15
  options: {
16
16
  showFileHeader: false,
17
17
  basePxFontSize: 16,
18
+ themeOverrides: {
19
+ theme: options === null || options === void 0 ? void 0 : options.theme,
20
+ },
18
21
  },
19
22
  files: [
20
23
  {
@@ -0,0 +1,2 @@
1
+ import type { Preprocessor } from 'style-dictionary/types';
2
+ export declare const themeOverrides: Preprocessor;
@@ -0,0 +1,22 @@
1
+ import { transformTokens } from './utilities/transformTokens.js';
2
+ export const themeOverrides = {
3
+ name: 'themeOverrides',
4
+ preprocessor: (dictionary, config) => {
5
+ var _a, _b, _c, _d, _e, _f;
6
+ const extensionProp = ((_b = (_a = config.options) === null || _a === void 0 ? void 0 : _a.themeOverrides) === null || _b === void 0 ? void 0 : _b.extensionProp) || 'org.primer.overrides';
7
+ const valueProp = ((_d = (_c = config.options) === null || _c === void 0 ? void 0 : _c.themeOverrides) === null || _d === void 0 ? void 0 : _d.valueProp) || '$value';
8
+ const currentTheme = (_f = (_e = config.options) === null || _e === void 0 ? void 0 : _e.themeOverrides) === null || _f === void 0 ? void 0 : _f.theme;
9
+ const tokens = transformTokens(dictionary, token => {
10
+ var _a, _b, _c;
11
+ // return early if no theme value is set
12
+ if (!currentTheme || !((_a = token.$extensions) === null || _a === void 0 ? void 0 : _a[extensionProp]) || !((_b = token.$extensions) === null || _b === void 0 ? void 0 : _b[extensionProp][currentTheme])) {
13
+ return token;
14
+ }
15
+ // get override
16
+ const override = (_c = token.$extensions) === null || _c === void 0 ? void 0 : _c[extensionProp][currentTheme];
17
+ // token an theme value exist
18
+ return Object.assign(Object.assign({}, token), (typeof override === 'object' ? override : { [valueProp]: override }));
19
+ });
20
+ return tokens;
21
+ },
22
+ };
@@ -0,0 +1,8 @@
1
+ import type { DesignToken } from 'style-dictionary/types';
2
+ /**
3
+ * jsonToNestedValue
4
+ * @description creates a nested json tree where every final value is the `.value` prop
5
+ * @param token StyleDictionary.DesignToken
6
+ * @returns nested json three
7
+ */
8
+ export declare const transformTokens: (token: DesignToken | Record<string, unknown>, transform: (token: DesignToken) => DesignToken) => {};
@@ -0,0 +1,22 @@
1
+ /**
2
+ * jsonToNestedValue
3
+ * @description creates a nested json tree where every final value is the `.value` prop
4
+ * @param token StyleDictionary.DesignToken
5
+ * @returns nested json three
6
+ */
7
+ export const transformTokens = (token, transform) => {
8
+ // is non-object value
9
+ if (typeof token !== 'object')
10
+ return token;
11
+ // is design token
12
+ if ('$value' in token || 'value' in token) {
13
+ return transform(token);
14
+ }
15
+ // is obj
16
+ const nextObj = {};
17
+ for (const [prop, value] of Object.entries(token)) {
18
+ // @ts-expect-error: can't predict type
19
+ nextObj[prop] = transformTokens(value, transform);
20
+ }
21
+ return nextObj;
22
+ };
@@ -1,13 +1,19 @@
1
1
  import StyleDictionary from 'style-dictionary';
2
- import { borderToCss, colorToRgbAlpha, colorToHex, colorToHexMix, colorToRgbaFloat, cubicBezierToCss, dimensionToRem, dimensionToPixelUnitless, durationToCss, figmaAttributes, fontFamilyToCss, fontFamilyToFigma, fontWeightToNumber, jsonDeprecated, namePathToDotNotation, namePathToCamelCase, namePathToPascalCase, namePathToKebabCase, namePathToSlashNotation, namePathToFigma, shadowToCss, typographyToCss, dimensionToRemPxArray, floatToPixel, floatToPixelUnitless, } from './transformers/index.js';
2
+ import { borderToCss, colorToRgbAlpha, colorToHex, colorToRgbaFloat, cubicBezierToCss, dimensionToRem, dimensionToPixelUnitless, durationToCss, figmaAttributes, fontFamilyToCss, fontFamilyToFigma, fontWeightToNumber, jsonDeprecated, namePathToDotNotation, namePathToCamelCase, namePathToPascalCase, namePathToKebabCase, namePathToSlashNotation, namePathToFigma, shadowToCss, typographyToCss, dimensionToRemPxArray, floatToPixel, floatToPixelUnitless, } from './transformers/index.js';
3
3
  import { javascriptCommonJs, javascriptEsm, typescriptExportDefinition, jsonNestedPrefixed, cssCustomMedia, jsonOneDimensional, jsonPostCssFallback, cssAdvanced, jsonFigma, } from './formats/index.js';
4
+ import { themeOverrides } from './preprocessors/themeOverrides.js';
4
5
  /**
5
6
  * @name {@link PrimerStyleDictionary}
6
7
  * @description Returns style dictionary object with primer preset that includes parsers, formats and transformers
7
8
  * @formats [javascript/esm](https://github.com/primer/primitives/blob/main/config/formats/javascript-esm.ts), [javascript/commonJs](https://github.com/primer/primitives/blob/main/config/formats/javascript-commonJs.ts), [typescript/export-definition](https://github.com/primer/primitives/blob/main/config/formats/typescript-export-defition.ts)
8
9
  * @transformers [color/rgbAlpha](https://github.com/primer/primitives/blob/main/config/tranformers/color-to-rgb-alpha.ts), [color/hexAlpha](https://github.com/primer/primitives/blob/main/config/tranformers/color-to-hex-alpha.ts), [color/hex](https://github.com/primer/primitives/blob/main/config/tranformers/color-to-hex6.ts), [json/deprecated](https://github.com/primer/primitives/blob/main/config/tranformers/json-deprecated.ts), [name/pathToDotNotation](https://github.com/primer/primitives/blob/main/config/tranformers/name-path-to-dot-notation.ts)
9
10
  */
10
- export const PrimerStyleDictionary = new StyleDictionary();
11
+ export const PrimerStyleDictionary = new StyleDictionary({
12
+ // these are the defaults
13
+ log: {
14
+ verbosity: 'default', // 'default' | 'silent' | 'verbose'
15
+ },
16
+ });
11
17
  /**
12
18
  * Formats
13
19
  *
@@ -54,7 +60,6 @@ PrimerStyleDictionary.registerFormat({
54
60
  */
55
61
  PrimerStyleDictionary.registerTransform(colorToRgbAlpha);
56
62
  PrimerStyleDictionary.registerTransform(colorToRgbaFloat);
57
- PrimerStyleDictionary.registerTransform(colorToHexMix);
58
63
  PrimerStyleDictionary.registerTransform(colorToHex);
59
64
  PrimerStyleDictionary.registerTransform(cubicBezierToCss);
60
65
  PrimerStyleDictionary.registerTransform(floatToPixel);
@@ -78,3 +83,4 @@ PrimerStyleDictionary.registerTransform(typographyToCss);
78
83
  PrimerStyleDictionary.registerTransform(fontWeightToNumber);
79
84
  PrimerStyleDictionary.registerTransform(fontFamilyToCss);
80
85
  PrimerStyleDictionary.registerTransform(fontFamilyToFigma);
86
+ PrimerStyleDictionary.registerPreprocessor(themeOverrides);
@@ -6,16 +6,6 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
6
6
  $value: z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>;
7
7
  $type: z.ZodLiteral<"string" | "number" | "border" | "color" | "fontFamily" | "fontWeight" | "dimension" | "duration" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange">;
8
8
  alpha: z.ZodNullable<z.ZodOptional<z.ZodEffects<z.ZodAny, any, any>>>;
9
- mix: z.ZodOptional<z.ZodNullable<z.ZodObject<{
10
- color: z.ZodString;
11
- weight: z.ZodNumber;
12
- }, "strip", z.ZodTypeAny, {
13
- color: string;
14
- weight: number;
15
- }, {
16
- color: string;
17
- weight: number;
18
- }>>>;
19
9
  $extensions: z.ZodOptional<z.ZodObject<{
20
10
  alpha: z.ZodNullable<z.ZodOptional<z.ZodNumber>>;
21
11
  'org.primer.figma': z.ZodOptional<z.ZodObject<{
@@ -34,6 +24,37 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
34
24
  modeOverride?: string | undefined;
35
25
  scopes?: string[] | undefined;
36
26
  }>>;
27
+ 'org.primer.overrides': z.ZodOptional<z.ZodObject<{
28
+ light: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
29
+ 'light-tritanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
30
+ 'light-deutranopia-protanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
31
+ 'light-high-contrast': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
32
+ dark: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
33
+ 'dark-tritanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
34
+ 'dark-deutranopia-protanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
35
+ 'dark-high-contrast': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
36
+ 'dark-dimmed': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
37
+ }, "strict", z.ZodTypeAny, {
38
+ light?: string | undefined;
39
+ dark?: string | undefined;
40
+ 'light-tritanopia'?: string | undefined;
41
+ 'light-deutranopia-protanopia'?: string | undefined;
42
+ 'light-high-contrast'?: string | undefined;
43
+ 'dark-tritanopia'?: string | undefined;
44
+ 'dark-deutranopia-protanopia'?: string | undefined;
45
+ 'dark-high-contrast'?: string | undefined;
46
+ 'dark-dimmed'?: string | undefined;
47
+ }, {
48
+ light?: string | undefined;
49
+ dark?: string | undefined;
50
+ 'light-tritanopia'?: string | undefined;
51
+ 'light-deutranopia-protanopia'?: string | undefined;
52
+ 'light-high-contrast'?: string | undefined;
53
+ 'dark-tritanopia'?: string | undefined;
54
+ 'dark-deutranopia-protanopia'?: string | undefined;
55
+ 'dark-high-contrast'?: string | undefined;
56
+ 'dark-dimmed'?: string | undefined;
57
+ }>>;
37
58
  }, "strip", z.ZodTypeAny, {
38
59
  alpha?: number | null | undefined;
39
60
  'org.primer.figma'?: {
@@ -42,6 +63,17 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
42
63
  modeOverride?: string | undefined;
43
64
  scopes?: string[] | undefined;
44
65
  } | undefined;
66
+ 'org.primer.overrides'?: {
67
+ light?: string | undefined;
68
+ dark?: string | undefined;
69
+ 'light-tritanopia'?: string | undefined;
70
+ 'light-deutranopia-protanopia'?: string | undefined;
71
+ 'light-high-contrast'?: string | undefined;
72
+ 'dark-tritanopia'?: string | undefined;
73
+ 'dark-deutranopia-protanopia'?: string | undefined;
74
+ 'dark-high-contrast'?: string | undefined;
75
+ 'dark-dimmed'?: string | undefined;
76
+ } | undefined;
45
77
  }, {
46
78
  alpha?: number | null | undefined;
47
79
  'org.primer.figma'?: {
@@ -50,16 +82,23 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
50
82
  modeOverride?: string | undefined;
51
83
  scopes?: string[] | undefined;
52
84
  } | undefined;
85
+ 'org.primer.overrides'?: {
86
+ light?: string | undefined;
87
+ dark?: string | undefined;
88
+ 'light-tritanopia'?: string | undefined;
89
+ 'light-deutranopia-protanopia'?: string | undefined;
90
+ 'light-high-contrast'?: string | undefined;
91
+ 'dark-tritanopia'?: string | undefined;
92
+ 'dark-deutranopia-protanopia'?: string | undefined;
93
+ 'dark-high-contrast'?: string | undefined;
94
+ 'dark-dimmed'?: string | undefined;
95
+ } | undefined;
53
96
  }>>;
54
97
  }>, "strict", z.ZodTypeAny, {
55
98
  $value: string;
56
99
  $type: "string" | "number" | "border" | "color" | "fontFamily" | "fontWeight" | "dimension" | "duration" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange";
57
100
  alpha?: any;
58
101
  $description?: string | undefined;
59
- mix?: {
60
- color: string;
61
- weight: number;
62
- } | null | undefined;
63
102
  $deprecated?: string | boolean | undefined;
64
103
  $extensions?: {
65
104
  alpha?: number | null | undefined;
@@ -69,16 +108,23 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
69
108
  modeOverride?: string | undefined;
70
109
  scopes?: string[] | undefined;
71
110
  } | undefined;
111
+ 'org.primer.overrides'?: {
112
+ light?: string | undefined;
113
+ dark?: string | undefined;
114
+ 'light-tritanopia'?: string | undefined;
115
+ 'light-deutranopia-protanopia'?: string | undefined;
116
+ 'light-high-contrast'?: string | undefined;
117
+ 'dark-tritanopia'?: string | undefined;
118
+ 'dark-deutranopia-protanopia'?: string | undefined;
119
+ 'dark-high-contrast'?: string | undefined;
120
+ 'dark-dimmed'?: string | undefined;
121
+ } | undefined;
72
122
  } | undefined;
73
123
  }, {
74
124
  $value: string;
75
125
  $type: "string" | "number" | "border" | "color" | "fontFamily" | "fontWeight" | "dimension" | "duration" | "shadow" | "typography" | "cubicBezier" | "custom-viewportRange";
76
126
  alpha?: any;
77
127
  $description?: string | undefined;
78
- mix?: {
79
- color: string;
80
- weight: number;
81
- } | null | undefined;
82
128
  $deprecated?: string | boolean | undefined;
83
129
  $extensions?: {
84
130
  alpha?: number | null | undefined;
@@ -88,5 +134,16 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
88
134
  modeOverride?: string | undefined;
89
135
  scopes?: string[] | undefined;
90
136
  } | undefined;
137
+ 'org.primer.overrides'?: {
138
+ light?: string | undefined;
139
+ dark?: string | undefined;
140
+ 'light-tritanopia'?: string | undefined;
141
+ 'light-deutranopia-protanopia'?: string | undefined;
142
+ 'light-high-contrast'?: string | undefined;
143
+ 'dark-tritanopia'?: string | undefined;
144
+ 'dark-deutranopia-protanopia'?: string | undefined;
145
+ 'dark-high-contrast'?: string | undefined;
146
+ 'dark-dimmed'?: string | undefined;
147
+ } | undefined;
91
148
  } | undefined;
92
149
  }>;