@primer/primitives 10.0.0 → 10.1.0-rc.3e576ad9
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/dist/build/filters/isColor.js +0 -3
- package/dist/build/formats/typescriptExportDefinition.js +2 -2
- package/dist/build/platforms/css.d.ts +1 -1
- package/dist/build/platforms/css.js +10 -6
- package/dist/build/platforms/deprecatedJson.d.ts +1 -1
- package/dist/build/platforms/docJson.d.ts +1 -1
- package/dist/build/platforms/docJson.js +5 -1
- package/dist/build/platforms/fallbacks.d.ts +1 -1
- package/dist/build/platforms/figma.d.ts +1 -1
- package/dist/build/platforms/figma.js +6 -3
- package/dist/build/platforms/javascript.d.ts +1 -1
- package/dist/build/platforms/javascript.js +5 -1
- package/dist/build/platforms/json.d.ts +1 -1
- package/dist/build/platforms/json.js +5 -1
- package/dist/build/platforms/styleLint.d.ts +1 -1
- package/dist/build/platforms/styleLint.js +5 -1
- package/dist/build/platforms/typeDefinitions.d.ts +1 -1
- package/dist/build/platforms/typeDefinitions.js +5 -1
- package/dist/build/platforms/typescript.d.ts +1 -1
- package/dist/build/platforms/typescript.js +5 -1
- package/dist/build/preprocessors/themeOverrides.d.ts +2 -0
- package/dist/build/preprocessors/themeOverrides.js +22 -0
- package/dist/build/preprocessors/utilities/transformTokens.d.ts +8 -0
- package/dist/build/preprocessors/utilities/transformTokens.js +22 -0
- package/dist/build/{PrimerStyleDictionary.js → primerStyleDictionary.js} +8 -1
- package/dist/build/schemas/colorToken.d.ts +75 -0
- package/dist/build/schemas/colorToken.js +23 -0
- package/dist/build/transformers/borderToCss.js +2 -2
- package/dist/build/transformers/figmaAttributes.js +1 -1
- package/dist/build/transformers/utilities/invalidTokenError.js +0 -2
- package/dist/build/types/{StyleDictionaryConfigGenerator.d.ts → styleDictionaryConfigGenerator.d.ts} +1 -0
- package/dist/build/types/{TokenBuildInput.d.ts → tokenBuildInput.d.ts} +2 -0
- package/dist/build/utilities/lowerCaseFirstCharacter.d.ts +8 -0
- package/dist/build/utilities/lowerCaseFirstCharacter.js +10 -0
- package/dist/css/functional/size/border.css +7 -6
- package/dist/css/functional/themes/dark-colorblind.css +56 -2
- package/dist/css/functional/themes/dark-dimmed.css +56 -2
- package/dist/css/functional/themes/dark-high-contrast.css +56 -2
- package/dist/css/functional/themes/dark-tritanopia.css +56 -2
- package/dist/css/functional/themes/dark.css +56 -2
- package/dist/css/functional/themes/light-colorblind.css +56 -2
- package/dist/css/functional/themes/light-high-contrast.css +56 -2
- package/dist/css/functional/themes/light-tritanopia.css +56 -2
- package/dist/css/functional/themes/light.css +56 -2
- package/dist/css/primitives.css +7 -6
- package/dist/docs/base/size/size.json +19 -19
- package/dist/docs/base/typography/typography.json +4 -4
- package/dist/docs/functional/size/border.json +41 -28
- package/dist/docs/functional/size/breakpoints.json +6 -6
- package/dist/docs/functional/size/size-coarse.json +3 -3
- package/dist/docs/functional/size/size-fine.json +3 -3
- package/dist/docs/functional/size/size.json +66 -66
- package/dist/docs/functional/size/viewport.json +6 -6
- package/dist/docs/functional/themes/dark-colorblind.json +450 -7
- package/dist/docs/functional/themes/dark-dimmed.json +450 -7
- package/dist/docs/functional/themes/dark-high-contrast.json +450 -7
- package/dist/docs/functional/themes/dark-tritanopia.json +450 -7
- package/dist/docs/functional/themes/dark.json +450 -7
- package/dist/docs/functional/themes/light-colorblind.json +445 -2
- package/dist/docs/functional/themes/light-high-contrast.json +445 -2
- package/dist/docs/functional/themes/light-tritanopia.json +445 -2
- package/dist/docs/functional/themes/light.json +445 -2
- package/dist/docs/functional/typography/typography.json +46 -46
- package/dist/fallbacks/functional/size/border.json +7 -6
- package/dist/figma/figma.json +0 -8
- package/dist/internalCss/dark-colorblind.css +84 -2
- package/dist/internalCss/dark-dimmed.css +84 -2
- package/dist/internalCss/dark-high-contrast.css +84 -2
- package/dist/internalCss/dark-tritanopia.css +84 -2
- package/dist/internalCss/dark.css +84 -2
- package/dist/internalCss/light-colorblind.css +84 -2
- package/dist/internalCss/light-high-contrast.css +84 -2
- package/dist/internalCss/light-tritanopia.css +84 -2
- package/dist/internalCss/light.css +84 -2
- package/dist/styleLint/base/size/size.json +19 -19
- package/dist/styleLint/base/typography/typography.json +4 -4
- package/dist/styleLint/functional/size/border.json +41 -28
- package/dist/styleLint/functional/size/breakpoints.json +6 -6
- package/dist/styleLint/functional/size/size-coarse.json +3 -3
- package/dist/styleLint/functional/size/size-fine.json +3 -3
- package/dist/styleLint/functional/size/size.json +66 -66
- package/dist/styleLint/functional/size/viewport.json +6 -6
- package/dist/styleLint/functional/themes/dark-colorblind.json +450 -7
- package/dist/styleLint/functional/themes/dark-dimmed.json +450 -7
- package/dist/styleLint/functional/themes/dark-high-contrast.json +450 -7
- package/dist/styleLint/functional/themes/dark-tritanopia.json +450 -7
- package/dist/styleLint/functional/themes/dark.json +450 -7
- package/dist/styleLint/functional/themes/light-colorblind.json +445 -2
- package/dist/styleLint/functional/themes/light-high-contrast.json +445 -2
- package/dist/styleLint/functional/themes/light-tritanopia.json +445 -2
- package/dist/styleLint/functional/themes/light.json +445 -2
- package/dist/styleLint/functional/typography/typography.json +46 -46
- package/package.json +11 -10
- package/src/tokens/base/typography/typography.json5 +48 -0
- package/src/tokens/functional/border/border.json5 +236 -0
- package/src/tokens/functional/color/dark/primitives-dark.json5 +0 -1
- package/src/tokens/functional/size/border.json5 +115 -0
- package/src/tokens/functional/typography/typography.json5 +527 -0
- package/src/tokens/base/typography/typography.json +0 -48
- package/src/tokens/functional/border/dark.json5 +0 -12
- package/src/tokens/functional/border/light.json5 +0 -12
- package/src/tokens/functional/color/dark/patterns-dark.json +0 -3963
- package/src/tokens/functional/size/border.json +0 -111
- package/src/tokens/functional/typography/typography.json +0 -527
- /package/dist/build/{PrimerStyleDictionary.d.ts → primerStyleDictionary.d.ts} +0 -0
- /package/dist/build/types/{Border.d.ts → border.d.ts} +0 -0
- /package/dist/build/types/{BorderTokenValue.d.ts → borderTokenValue.d.ts} +0 -0
- /package/dist/build/types/{ColorHex.d.ts → colorHex.d.ts} +0 -0
- /package/dist/build/types/{PlatformInitializer.d.ts → platformInitializer.d.ts} +0 -0
- /package/dist/build/types/{Shadow.d.ts → shadow.d.ts} +0 -0
- /package/dist/build/types/{ShadowTokenValue.d.ts → shadowTokenValue.d.ts} +0 -0
- /package/dist/build/types/{SizeEm.d.ts → sizeEm.d.ts} +0 -0
- /package/dist/build/types/{SizePx.d.ts → sizePx.d.ts} +0 -0
- /package/dist/build/types/{SizeRem.d.ts → sizeRem.d.ts} +0 -0
- /package/dist/build/types/{TypographyTokenValue.d.ts → typographyTokenValue.d.ts} +0 -0
- /package/src/tokens/base/size/{size.json → size.json5} +0 -0
- /package/src/tokens/functional/size/{breakpoints.json → breakpoints.json5} +0 -0
- /package/src/tokens/functional/size/{size-coarse.json → size-coarse.json5} +0 -0
- /package/src/tokens/functional/size/{size-fine.json → size-fine.json5} +0 -0
- /package/src/tokens/functional/size/{size.json → size.json5} +0 -0
- /package/src/tokens/functional/size/{viewport.json → viewport.json5} +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/
|
|
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
|
{
|
|
@@ -43,8 +47,8 @@ export const css = (outputFile, prefix, buildPath, options) => {
|
|
|
43
47
|
(options === null || options === void 0 ? void 0 : options.themed) === true &&
|
|
44
48
|
token.$type !== 'custom-viewportRange' &&
|
|
45
49
|
!isFromFile(token, [
|
|
46
|
-
'src/tokens/functional/size/size-coarse.
|
|
47
|
-
'src/tokens/functional/size/size-fine.
|
|
50
|
+
'src/tokens/functional/size/size-coarse.json5',
|
|
51
|
+
'src/tokens/functional/size/size-fine.json5',
|
|
48
52
|
]),
|
|
49
53
|
options: Object.assign({ showFileHeader: false, outputReferences: false, descriptions: false, queries: getCssSelectors(outputFile) }, options === null || options === void 0 ? void 0 : options.options),
|
|
50
54
|
},
|
|
@@ -55,8 +59,8 @@ export const css = (outputFile, prefix, buildPath, options) => {
|
|
|
55
59
|
(options === null || options === void 0 ? void 0 : options.themed) !== true &&
|
|
56
60
|
token.$type !== 'custom-viewportRange' &&
|
|
57
61
|
!isFromFile(token, [
|
|
58
|
-
'src/tokens/functional/size/size-coarse.
|
|
59
|
-
'src/tokens/functional/size/size-fine.
|
|
62
|
+
'src/tokens/functional/size/size-coarse.json5',
|
|
63
|
+
'src/tokens/functional/size/size-fine.json5',
|
|
60
64
|
]),
|
|
61
65
|
options: Object.assign({ showFileHeader: false, descriptions: false }, options === null || options === void 0 ? void 0 : options.options),
|
|
62
66
|
},
|
|
@@ -73,8 +77,8 @@ export const css = (outputFile, prefix, buildPath, options) => {
|
|
|
73
77
|
format: `css/advanced`,
|
|
74
78
|
filter: token => isSource(token) &&
|
|
75
79
|
isFromFile(token, [
|
|
76
|
-
'src/tokens/functional/size/size-coarse.
|
|
77
|
-
'src/tokens/functional/size/size-fine.
|
|
80
|
+
'src/tokens/functional/size/size-coarse.json5',
|
|
81
|
+
'src/tokens/functional/size/size-fine.json5',
|
|
78
82
|
]),
|
|
79
83
|
options: {
|
|
80
84
|
descriptions: false,
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { PlatformInitializer } from '../types/
|
|
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/
|
|
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/
|
|
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/
|
|
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
|
-
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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/
|
|
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,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
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
|
|
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
|
*
|
|
@@ -78,3 +84,4 @@ PrimerStyleDictionary.registerTransform(typographyToCss);
|
|
|
78
84
|
PrimerStyleDictionary.registerTransform(fontWeightToNumber);
|
|
79
85
|
PrimerStyleDictionary.registerTransform(fontFamilyToCss);
|
|
80
86
|
PrimerStyleDictionary.registerTransform(fontFamilyToFigma);
|
|
87
|
+
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
|
})
|
|
@@ -32,7 +32,7 @@ export const borderToCss = {
|
|
|
32
32
|
if (!checkForBorderTokenProperties(value)) {
|
|
33
33
|
throw new Error(`Invalid border token property ${JSON.stringify(value)}. Must be an object with color, width and style properties.`);
|
|
34
34
|
}
|
|
35
|
-
/*
|
|
36
|
-
return `${value.
|
|
35
|
+
/* width | style | color */
|
|
36
|
+
return `${value.width} ${value.style} ${value.color}`;
|
|
37
37
|
},
|
|
38
38
|
};
|
|
@@ -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:
|
|
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 {
|
|
@@ -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
|
+
};
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
:root {
|
|
2
|
-
--boxShadow-thin: inset 0 0 0
|
|
3
|
-
--boxShadow-thick: inset 0 0 0
|
|
4
|
-
--boxShadow-thicker: inset 0 0 0
|
|
5
|
-
--borderWidth-
|
|
6
|
-
--borderWidth-
|
|
7
|
-
--borderWidth-
|
|
2
|
+
--boxShadow-thin: inset 0 0 0 0.0625rem; /* Thin shadow for borders */
|
|
3
|
+
--boxShadow-thick: inset 0 0 0 0.125rem;
|
|
4
|
+
--boxShadow-thicker: inset 0 0 0 0.25rem;
|
|
5
|
+
--borderWidth-default: 0.0625rem;
|
|
6
|
+
--borderWidth-thin: 0.0625rem;
|
|
7
|
+
--borderWidth-thick: 0.125rem;
|
|
8
|
+
--borderWidth-thicker: 0.25rem;
|
|
8
9
|
--borderRadius-small: 0.1875rem;
|
|
9
10
|
--borderRadius-medium: 0.375rem;
|
|
10
11
|
--borderRadius-large: 0.75rem;
|