@primer/primitives 10.0.0 → 10.1.0-rc.45b16c3b

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 (46) hide show
  1. package/dist/build/filters/isColor.js +0 -3
  2. package/dist/build/formats/typescriptExportDefinition.js +2 -2
  3. package/dist/build/platforms/css.d.ts +1 -1
  4. package/dist/build/platforms/css.js +4 -0
  5. package/dist/build/platforms/deprecatedJson.d.ts +1 -1
  6. package/dist/build/platforms/docJson.d.ts +1 -1
  7. package/dist/build/platforms/docJson.js +5 -1
  8. package/dist/build/platforms/fallbacks.d.ts +1 -1
  9. package/dist/build/platforms/figma.d.ts +1 -1
  10. package/dist/build/platforms/figma.js +6 -3
  11. package/dist/build/platforms/javascript.d.ts +1 -1
  12. package/dist/build/platforms/javascript.js +5 -1
  13. package/dist/build/platforms/json.d.ts +1 -1
  14. package/dist/build/platforms/json.js +5 -1
  15. package/dist/build/platforms/styleLint.d.ts +1 -1
  16. package/dist/build/platforms/styleLint.js +5 -1
  17. package/dist/build/platforms/typeDefinitions.d.ts +1 -1
  18. package/dist/build/platforms/typeDefinitions.js +5 -1
  19. package/dist/build/platforms/typescript.d.ts +1 -1
  20. package/dist/build/platforms/typescript.js +5 -1
  21. package/dist/build/preprocessors/themeOverrides.d.ts +2 -0
  22. package/dist/build/preprocessors/themeOverrides.js +22 -0
  23. package/dist/build/preprocessors/utilities/transformTokens.d.ts +8 -0
  24. package/dist/build/preprocessors/utilities/transformTokens.js +22 -0
  25. package/dist/build/{PrimerStyleDictionary.js → primerStyleDictionary.js} +2 -0
  26. package/dist/build/schemas/colorToken.d.ts +75 -0
  27. package/dist/build/schemas/colorToken.js +23 -0
  28. package/dist/build/transformers/figmaAttributes.js +1 -1
  29. package/dist/build/transformers/utilities/invalidTokenError.js +0 -2
  30. package/dist/build/types/{StyleDictionaryConfigGenerator.d.ts → styleDictionaryConfigGenerator.d.ts} +1 -0
  31. package/dist/build/types/{TokenBuildInput.d.ts → tokenBuildInput.d.ts} +2 -0
  32. package/dist/build/utilities/lowerCaseFirstCharacter.d.ts +8 -0
  33. package/dist/build/utilities/lowerCaseFirstCharacter.js +10 -0
  34. package/dist/figma/figma.json +0 -8
  35. package/package.json +11 -10
  36. /package/dist/build/{PrimerStyleDictionary.d.ts → primerStyleDictionary.d.ts} +0 -0
  37. /package/dist/build/types/{Border.d.ts → border.d.ts} +0 -0
  38. /package/dist/build/types/{BorderTokenValue.d.ts → borderTokenValue.d.ts} +0 -0
  39. /package/dist/build/types/{ColorHex.d.ts → colorHex.d.ts} +0 -0
  40. /package/dist/build/types/{PlatformInitializer.d.ts → platformInitializer.d.ts} +0 -0
  41. /package/dist/build/types/{Shadow.d.ts → shadow.d.ts} +0 -0
  42. /package/dist/build/types/{ShadowTokenValue.d.ts → shadowTokenValue.d.ts} +0 -0
  43. /package/dist/build/types/{SizeEm.d.ts → sizeEm.d.ts} +0 -0
  44. /package/dist/build/types/{SizePx.d.ts → sizePx.d.ts} +0 -0
  45. /package/dist/build/types/{SizeRem.d.ts → sizeRem.d.ts} +0 -0
  46. /package/dist/build/types/{TypographyTokenValue.d.ts → typographyTokenValue.d.ts} +0 -0
@@ -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
  };
@@ -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,6 +19,7 @@ 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',
@@ -34,6 +35,9 @@ export const css = (outputFile, prefix, buildPath, options) => {
34
35
  ],
35
36
  options: {
36
37
  basePxFontSize: 16,
38
+ themeOverrides: {
39
+ theme: options === null || options === void 0 ? void 0 : options.theme,
40
+ },
37
41
  },
38
42
  files: [
39
43
  {
@@ -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,7 +1,8 @@
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',
@@ -20,6 +21,9 @@ export const docJson = (outputFile, prefix, buildPath) => ({
20
21
  $type: 'type',
21
22
  $description: 'description',
22
23
  },
24
+ themeOverrides: {
25
+ theme: options === null || options === void 0 ? void 0 : options.theme,
26
+ },
23
27
  },
24
28
  files: [
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 fallbacks: 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 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,7 +1,8 @@
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
8
  'color/hexMix',
@@ -15,6 +16,9 @@ export const javascript = (outputFile, prefix, buildPath) => ({
15
16
  options: {
16
17
  showFileHeader: false,
17
18
  basePxFontSize: 16,
19
+ themeOverrides: {
20
+ theme: options === null || options === void 0 ? void 0 : options.theme,
21
+ },
18
22
  },
19
23
  files: [
20
24
  {
@@ -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,7 +1,8 @@
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
8
  'color/hexMix',
@@ -14,6 +15,9 @@ export const json = (outputFile, prefix, buildPath) => ({
14
15
  ],
15
16
  options: {
16
17
  basePxFontSize: 16,
18
+ themeOverrides: {
19
+ theme: options === null || options === void 0 ? void 0 : options.theme,
20
+ },
17
21
  },
18
22
  files: [
19
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 styleLint: PlatformInitializer;
@@ -1,7 +1,8 @@
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',
@@ -15,6 +16,9 @@ export const styleLint = (outputFile, prefix, buildPath) => ({
15
16
  ],
16
17
  options: {
17
18
  basePxFontSize: 16,
19
+ themeOverrides: {
20
+ theme: options === null || options === void 0 ? void 0 : options.theme,
21
+ },
18
22
  },
19
23
  files: [
20
24
  {
@@ -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,7 +1,8 @@
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
8
  'color/hexMix',
@@ -15,6 +16,9 @@ export const typescript = (outputFile, prefix, buildPath) => ({
15
16
  options: {
16
17
  showFileHeader: false,
17
18
  basePxFontSize: 16,
19
+ themeOverrides: {
20
+ theme: options === null || options === void 0 ? void 0 : options.theme,
21
+ },
18
22
  },
19
23
  files: [
20
24
  {
@@ -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,6 +1,7 @@
1
1
  import StyleDictionary from 'style-dictionary';
2
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';
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
@@ -78,3 +79,4 @@ PrimerStyleDictionary.registerTransform(typographyToCss);
78
79
  PrimerStyleDictionary.registerTransform(fontWeightToNumber);
79
80
  PrimerStyleDictionary.registerTransform(fontFamilyToCss);
80
81
  PrimerStyleDictionary.registerTransform(fontFamilyToFigma);
82
+ PrimerStyleDictionary.registerPreprocessor(themeOverrides);
@@ -34,6 +34,37 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
34
34
  modeOverride?: string | undefined;
35
35
  scopes?: string[] | undefined;
36
36
  }>>;
37
+ 'org.primer.overrides': z.ZodOptional<z.ZodObject<{
38
+ light: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
39
+ 'light-tritanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
40
+ 'light-deutranopia-protanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
41
+ 'light-high-contrast': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
42
+ dark: z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
43
+ 'dark-tritanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
44
+ 'dark-deutranopia-protanopia': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
45
+ 'dark-high-contrast': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
46
+ 'dark-dimmed': z.ZodOptional<z.ZodUnion<[z.ZodEffects<z.ZodString, string, string>, z.ZodEffects<z.ZodString, string, string>]>>;
47
+ }, "strict", z.ZodTypeAny, {
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
+ }, {
58
+ light?: string | undefined;
59
+ dark?: string | undefined;
60
+ 'light-tritanopia'?: string | undefined;
61
+ 'light-deutranopia-protanopia'?: string | undefined;
62
+ 'light-high-contrast'?: string | undefined;
63
+ 'dark-tritanopia'?: string | undefined;
64
+ 'dark-deutranopia-protanopia'?: string | undefined;
65
+ 'dark-high-contrast'?: string | undefined;
66
+ 'dark-dimmed'?: string | undefined;
67
+ }>>;
37
68
  }, "strip", z.ZodTypeAny, {
38
69
  alpha?: number | null | undefined;
39
70
  'org.primer.figma'?: {
@@ -42,6 +73,17 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
42
73
  modeOverride?: string | undefined;
43
74
  scopes?: string[] | undefined;
44
75
  } | undefined;
76
+ 'org.primer.overrides'?: {
77
+ light?: string | undefined;
78
+ dark?: string | undefined;
79
+ 'light-tritanopia'?: string | undefined;
80
+ 'light-deutranopia-protanopia'?: string | undefined;
81
+ 'light-high-contrast'?: string | undefined;
82
+ 'dark-tritanopia'?: string | undefined;
83
+ 'dark-deutranopia-protanopia'?: string | undefined;
84
+ 'dark-high-contrast'?: string | undefined;
85
+ 'dark-dimmed'?: string | undefined;
86
+ } | undefined;
45
87
  }, {
46
88
  alpha?: number | null | undefined;
47
89
  'org.primer.figma'?: {
@@ -50,6 +92,17 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
50
92
  modeOverride?: string | undefined;
51
93
  scopes?: string[] | undefined;
52
94
  } | undefined;
95
+ 'org.primer.overrides'?: {
96
+ light?: string | undefined;
97
+ dark?: string | undefined;
98
+ 'light-tritanopia'?: string | undefined;
99
+ 'light-deutranopia-protanopia'?: string | undefined;
100
+ 'light-high-contrast'?: string | undefined;
101
+ 'dark-tritanopia'?: string | undefined;
102
+ 'dark-deutranopia-protanopia'?: string | undefined;
103
+ 'dark-high-contrast'?: string | undefined;
104
+ 'dark-dimmed'?: string | undefined;
105
+ } | undefined;
53
106
  }>>;
54
107
  }>, "strict", z.ZodTypeAny, {
55
108
  $value: string;
@@ -69,6 +122,17 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
69
122
  modeOverride?: string | undefined;
70
123
  scopes?: string[] | undefined;
71
124
  } | undefined;
125
+ 'org.primer.overrides'?: {
126
+ light?: string | undefined;
127
+ dark?: string | undefined;
128
+ 'light-tritanopia'?: string | undefined;
129
+ 'light-deutranopia-protanopia'?: string | undefined;
130
+ 'light-high-contrast'?: string | undefined;
131
+ 'dark-tritanopia'?: string | undefined;
132
+ 'dark-deutranopia-protanopia'?: string | undefined;
133
+ 'dark-high-contrast'?: string | undefined;
134
+ 'dark-dimmed'?: string | undefined;
135
+ } | undefined;
72
136
  } | undefined;
73
137
  }, {
74
138
  $value: string;
@@ -88,5 +152,16 @@ export declare const colorToken: z.ZodObject<z.objectUtil.extendShape<{
88
152
  modeOverride?: string | undefined;
89
153
  scopes?: string[] | undefined;
90
154
  } | undefined;
155
+ 'org.primer.overrides'?: {
156
+ light?: string | undefined;
157
+ dark?: string | undefined;
158
+ 'light-tritanopia'?: string | undefined;
159
+ 'light-deutranopia-protanopia'?: string | undefined;
160
+ 'light-high-contrast'?: string | undefined;
161
+ 'dark-tritanopia'?: string | undefined;
162
+ 'dark-deutranopia-protanopia'?: string | undefined;
163
+ 'dark-high-contrast'?: string | undefined;
164
+ 'dark-dimmed'?: string | undefined;
165
+ } | undefined;
91
166
  } | undefined;
92
167
  }>;
@@ -47,6 +47,29 @@ export const colorToken = baseToken
47
47
  group: z.string().optional(),
48
48
  })
49
49
  .optional(),
50
+ 'org.primer.overrides': z
51
+ .object({
52
+ light: z.union([colorHexValue, referenceValue]).optional(),
53
+ 'light-tritanopia': z.union([colorHexValue, referenceValue]).optional(),
54
+ 'light-deutranopia-protanopia': z.union([colorHexValue, referenceValue]).optional(),
55
+ 'light-high-contrast': z.union([colorHexValue, referenceValue]).optional(),
56
+ dark: z.union([colorHexValue, referenceValue]).optional(),
57
+ 'dark-tritanopia': z.union([colorHexValue, referenceValue]).optional(),
58
+ 'dark-deutranopia-protanopia': z.union([colorHexValue, referenceValue]).optional(),
59
+ 'dark-high-contrast': z.union([colorHexValue, referenceValue]).optional(),
60
+ 'dark-dimmed': z.union([colorHexValue, referenceValue]).optional(),
61
+ }, {
62
+ errorMap: e => {
63
+ if (e.code === 'unrecognized_keys') {
64
+ return {
65
+ message: `Unrecognized key: "${e.keys.join(', ')}", must be one of: light, light-tritanopia, light-deutranopia-protanopia, light-high-contrast, dark, dark-tritanopia, dark-deutranopia-protanopia, dark-high-contrast, dark-dimmed`,
66
+ };
67
+ }
68
+ return { message: `Error: ${e.code}` };
69
+ },
70
+ })
71
+ .strict()
72
+ .optional(),
50
73
  })
51
74
  .optional(),
52
75
  })
@@ -45,7 +45,7 @@ export const figmaAttributes = {
45
45
  var _a, _b;
46
46
  const { modeOverride, collection, scopes, group, codeSyntax } = ((_a = token.$extensions) === null || _a === void 0 ? void 0 : _a['org.primer.figma']) || {};
47
47
  return {
48
- mode: modeOverride || ((_b = platform.options) === null || _b === void 0 ? void 0 : _b.mode) || 'default',
48
+ mode: ((_b = platform.options) === null || _b === void 0 ? void 0 : _b.theme) || modeOverride || 'default',
49
49
  collection,
50
50
  group: group || collection,
51
51
  scopes: getScopes(scopes),
@@ -3,14 +3,12 @@ const composeValueErrorMessage = (token) => {
3
3
  var _a, _b;
4
4
  const originalValue = (_a = token.original.$value) !== null && _a !== void 0 ? _a : token.original.value;
5
5
  const value = (_b = token.$value) !== null && _b !== void 0 ? _b : token.value;
6
- // eslint-disable-next-line i18n-text/no-en
7
6
  return `Invalid token "${namePathToDotNotation.transform(token, {}, {})}" in file "${token.filePath}". Transformed value: "${JSON.stringify(value)}". ${originalValue ? `Original value: "${JSON.stringify(originalValue)}" ` : ''}This may be due to referencing a token that does not exists.`;
8
7
  };
9
8
  const composeValuePropertyErrorMessage = (token, property) => {
10
9
  var _a, _b;
11
10
  const originalValue = (_a = token.original.$value) !== null && _a !== void 0 ? _a : token.original.value;
12
11
  const value = (_b = token.$value) !== null && _b !== void 0 ? _b : token.value;
13
- // eslint-disable-next-line i18n-text/no-en
14
12
  return `Invalid property "${property}" of token "${namePathToDotNotation.transform(token, {}, {})}" in file "${token.filePath}". Transformed property value: "${value[property]}". ${originalValue ? `Original value: "${originalValue[property]}" ` : ''}This may be due to referencing a token that does not exists.`;
15
13
  };
16
14
  export class invalidTokenValueError extends Error {
@@ -4,6 +4,7 @@ export type ConfigGeneratorOptions = {
4
4
  buildPath: string
5
5
  prefix?: string
6
6
  themed?: boolean
7
+ theme?: string
7
8
  }
8
9
 
9
10
  export type StyleDictionaryConfigGenerator = (
@@ -3,6 +3,8 @@ export type TokenBuildInput = {
3
3
  filename: string
4
4
  // Array of `filepaths` to token files that should be converted and included in the output. Accepts relative or glob paths.
5
5
  source: string[]
6
+ // The mode of the theme
7
+ theme?: string
6
8
  // Array of `filepaths` to token fils that should NOT be included in the output, but should be available to reference during compilation e.g. base color scales
7
9
  include: string[]
8
10
  }
@@ -0,0 +1,8 @@
1
+ /**
2
+ * lowerCaseFirstCharacter
3
+ * @scope custom implementation should only be used within `name path to ...` transformer
4
+ * @description changes first letter to uppercase but keeps the rest of the word as is
5
+ * @param string
6
+ * @returns string
7
+ */
8
+ export declare const lowerCaseFirstCharacter: ([firstLetter, ...restOfWord]: string) => string;
@@ -0,0 +1,10 @@
1
+ /**
2
+ * lowerCaseFirstCharacter
3
+ * @scope custom implementation should only be used within `name path to ...` transformer
4
+ * @description changes first letter to uppercase but keeps the rest of the word as is
5
+ * @param string
6
+ * @returns string
7
+ */
8
+ export const lowerCaseFirstCharacter = ([firstLetter, ...restOfWord]) => {
9
+ return firstLetter.toLowerCase() + restOfWord.join('');
10
+ };
@@ -101,14 +101,6 @@
101
101
  "groups": [
102
102
  "typography"
103
103
  ]
104
- },
105
- "undefined": {
106
- "modes": [
107
- null
108
- ],
109
- "groups": [
110
- null
111
- ]
112
104
  }
113
105
  },
114
106
  "files": [
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@primer/primitives",
3
- "version": "10.0.0",
3
+ "version": "10.1.0-rc.45b16c3b",
4
4
  "description": "Typography, spacing, and color primitives for Primer design system",
5
5
  "type": "module",
6
6
  "files": [
@@ -30,11 +30,11 @@
30
30
  "build:config": "tsc -p build.tsconfig.jsonc && tsx ./scripts/copyDir.ts src/types dist/build/types",
31
31
  "clean": "rm -rf dist",
32
32
  "validate:tokenJson": "tsx scripts/diffThemes.ts && tsx scripts/diffTokenProps.ts",
33
- "validate:contrast": "tsx scripts/color-contrast.ts",
33
+ "validate:contrast": "tsx scripts/colorContrast.ts",
34
34
  "format": "prettier --check '**/*.{js,jsx,ts,tsx,md,mdx,css}'",
35
35
  "format:fix": "prettier --write '**/*.{js,jsx,ts,tsx,md,mdx,css}'",
36
- "lint": "ESLINT_USE_FLAT_CONFIG=false eslint '**/*.{js,ts,tsx,md,mdx}' --config .eslintrc.cjs && npm run lint:tokens",
37
- "lint:fix": "eslint '**/*.{js,ts,tsx,md,mdx}' --fix --max-warnings=0 --config .eslintrc.cjs",
36
+ "lint": "eslint '**/*.{js,ts,tsx,md,mdx}' --config eslint.config.mjs && npm run lint:tokens",
37
+ "lint:fix": "eslint '**/*.{js,ts,tsx,md,mdx}' --fix --max-warnings=0 --config eslint.config.mjs",
38
38
  "lint:tokens": "tsx ./scripts/validateTokenJson.ts",
39
39
  "test": "npm run test:unit && npm run test:integration",
40
40
  "test:unit": "vitest run --coverage",
@@ -60,25 +60,26 @@
60
60
  "color-blend": "^4.0.0",
61
61
  "color2k": "^2.0.3",
62
62
  "console-table-printer": "^2.12.1",
63
- "eslint": "^8.57.0",
63
+ "eslint": "9.16",
64
64
  "eslint-config-prettier": "^9.1.0",
65
+ "eslint-plugin-react": "7.37",
65
66
  "eslint-import-resolver-typescript": "3.6",
66
- "eslint-plugin-github": "5.1",
67
+ "eslint-plugin-github": "^5.1.3",
67
68
  "eslint-plugin-jsx-a11y": "6.10",
68
- "eslint-plugin-mdx": "^3.1.5",
69
- "eslint-plugin-react": "7.37",
70
- "eslint-plugin-react-hooks": "^4.6.2",
69
+ "eslint-plugin-react-hooks": "^5.0.0",
71
70
  "json5": "^2.2.1",
72
71
  "markdown-table-ts": "^1.0.3",
73
72
  "prettier": "^3.3.3",
74
73
  "style-dictionary": "^4.1.3",
75
74
  "tsx": "^4.19.0",
76
75
  "typescript": "5.6",
76
+ "typescript-eslint": "^8.16.0",
77
77
  "vitest": "^2.0.3",
78
78
  "zod": "3.23",
79
79
  "zod-validation-error": "3.4"
80
80
  },
81
81
  "optionalDependencies": {
82
- "@rollup/rollup-linux-x64-gnu": "^4.22.0"
82
+ "@rollup/rollup-linux-x64-gnu": "^4.22.0",
83
+ "@esbuild/linux-x64": "0.24.0"
83
84
  }
84
85
  }
File without changes
File without changes
File without changes
File without changes
File without changes