@digdir/designsystemet 0.1.0-alpha.9 → 0.1.0-next.21
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/bin/designsystemet.js +34 -0
- package/dist/src/colors/colorUtils.js +242 -0
- package/dist/src/colors/index.js +3 -0
- package/dist/src/colors/themeUtils.js +245 -0
- package/dist/src/colors/types.js +0 -0
- package/dist/src/init/createTokensPackage.js +250 -0
- package/dist/src/init/generateMetadataJson.js +19 -0
- package/dist/src/init/generateThemesJson.js +52 -0
- package/dist/src/init/index.js +10 -0
- package/dist/src/init/nextStepsMarkdown.js +92 -0
- package/dist/src/init/template/default-files/README.md +10 -0
- package/dist/src/init/template/default-files/design-tokens/README.md +3 -0
- package/dist/src/init/template/default-files/design-tokens/primitives/globals.json +197 -0
- package/dist/src/init/template/default-files/design-tokens/primitives/typography/default.json +86 -0
- package/dist/src/init/template/default-files/design-tokens/semantic/color.json +562 -0
- package/dist/src/init/template/default-files/design-tokens/semantic/style.json +543 -0
- package/dist/src/init/template/prettier.config.js +5 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/contrast/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/dark/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/global.json +376 -0
- package/dist/src/init/template/template-files/design-tokens/primitives/colors/light/theme-template.json +314 -0
- package/dist/src/init/template/template-files/design-tokens/themes/theme-template.json +314 -0
- package/dist/src/init/template/template-files/package.json +24 -0
- package/dist/src/init/utils.js +15 -0
- package/dist/src/migrations/beta-to-v1.js +344 -0
- package/dist/src/migrations/codemods/css/plugins.js +47 -0
- package/dist/src/migrations/codemods/css/run.js +19 -0
- package/dist/src/migrations/codemods/jsx/classname-prefix.js +63 -0
- package/dist/src/migrations/codemods/jsx/run.js +22 -0
- package/dist/src/migrations/index.js +9 -0
- package/dist/src/migrations/react-beta-to-v1.js +5 -0
- package/dist/src/tokens/actions.js +33 -0
- package/dist/src/tokens/build.js +74 -0
- package/dist/src/tokens/configs.js +223 -0
- package/dist/src/tokens/formats/css.js +170 -0
- package/dist/src/tokens/formats/js-tokens.js +31 -0
- package/dist/src/tokens/transformers.js +47 -0
- package/dist/src/tokens/utils/noCase.js +24 -0
- package/dist/src/tokens/utils/permutateThemes.js +64 -0
- package/dist/src/tokens/utils/utils.js +14 -0
- package/package.json +21 -13
- package/LICENSE +0 -7
- package/dist/build/bin/designsystemet.js +0 -50
- package/dist/build/src/colors/colorUtils.js +0 -314
- package/dist/build/src/colors/index.js +0 -3
- package/dist/build/src/colors/themeUtils.js +0 -290
- package/dist/build/src/colors/types.js +0 -1
- package/dist/build/src/migrations/beta-to-v1.js +0 -341
- package/dist/build/src/migrations/codemods/css/plugins.js +0 -45
- package/dist/build/src/migrations/codemods/css/run.js +0 -17
- package/dist/build/src/migrations/codemods/jsx/classname-prefix.js +0 -80
- package/dist/build/src/migrations/codemods/jsx/run.js +0 -19
- package/dist/build/src/migrations/index.js +0 -6
- package/dist/build/src/migrations/react-beta-to-v1.js +0 -2
- package/dist/build/src/test/jsx-test.js +0 -10
- package/dist/build/src/tokens/actions.js +0 -20
- package/dist/build/src/tokens/build.js +0 -63
- package/dist/build/src/tokens/configs.js +0 -229
- package/dist/build/src/tokens/formats/css-classes.js +0 -50
- package/dist/build/src/tokens/formats/css-variables.js +0 -39
- package/dist/build/src/tokens/formats/js-tokens.js +0 -29
- package/dist/build/src/tokens/transformers.js +0 -42
- package/dist/build/src/tokens/utils/noCase.js +0 -30
- package/dist/build/src/tokens/utils/permutateThemes.js +0 -56
- package/dist/build/src/tokens/utils/utils.js +0 -21
- package/dist/build/tsconfig.tsbuildinfo +0 -1
- package/dist/types/bin/designsystemet.d.ts +0 -3
- package/dist/types/bin/designsystemet.d.ts.map +0 -1
- package/dist/types/src/colors/colorUtils.d.ts +0 -118
- package/dist/types/src/colors/colorUtils.d.ts.map +0 -1
- package/dist/types/src/colors/index.d.ts +0 -4
- package/dist/types/src/colors/index.d.ts.map +0 -1
- package/dist/types/src/colors/themeUtils.d.ts +0 -101
- package/dist/types/src/colors/themeUtils.d.ts.map +0 -1
- package/dist/types/src/colors/types.d.ts +0 -16
- package/dist/types/src/colors/types.d.ts.map +0 -1
- package/dist/types/src/migrations/beta-to-v1.d.ts +0 -3
- package/dist/types/src/migrations/beta-to-v1.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/css/plugins.d.ts +0 -6
- package/dist/types/src/migrations/codemods/css/plugins.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/css/run.d.ts +0 -8
- package/dist/types/src/migrations/codemods/css/run.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
- package/dist/types/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
- package/dist/types/src/migrations/codemods/jsx/run.d.ts +0 -7
- package/dist/types/src/migrations/codemods/jsx/run.d.ts.map +0 -1
- package/dist/types/src/migrations/index.d.ts +0 -6
- package/dist/types/src/migrations/index.d.ts.map +0 -1
- package/dist/types/src/migrations/react-beta-to-v1.d.ts +0 -3
- package/dist/types/src/migrations/react-beta-to-v1.d.ts.map +0 -1
- package/dist/types/src/test/jsx-test.d.ts +0 -4
- package/dist/types/src/test/jsx-test.d.ts.map +0 -1
- package/dist/types/src/tokens/actions.d.ts +0 -3
- package/dist/types/src/tokens/actions.d.ts.map +0 -1
- package/dist/types/src/tokens/build.d.ts +0 -11
- package/dist/types/src/tokens/build.d.ts.map +0 -1
- package/dist/types/src/tokens/configs.d.ts +0 -23
- package/dist/types/src/tokens/configs.d.ts.map +0 -1
- package/dist/types/src/tokens/formats/css-classes.d.ts +0 -6
- package/dist/types/src/tokens/formats/css-classes.d.ts.map +0 -1
- package/dist/types/src/tokens/formats/css-variables.d.ts +0 -3
- package/dist/types/src/tokens/formats/css-variables.d.ts.map +0 -1
- package/dist/types/src/tokens/formats/js-tokens.d.ts +0 -6
- package/dist/types/src/tokens/formats/js-tokens.d.ts.map +0 -1
- package/dist/types/src/tokens/transformers.d.ts +0 -5
- package/dist/types/src/tokens/transformers.d.ts.map +0 -1
- package/dist/types/src/tokens/utils/noCase.d.ts +0 -11
- package/dist/types/src/tokens/utils/noCase.d.ts.map +0 -1
- package/dist/types/src/tokens/utils/permutateThemes.d.ts +0 -7
- package/dist/types/src/tokens/utils/permutateThemes.d.ts.map +0 -1
- package/dist/types/src/tokens/utils/utils.d.ts +0 -17
- package/dist/types/src/tokens/utils/utils.d.ts.map +0 -1
|
@@ -1,229 +0,0 @@
|
|
|
1
|
-
import * as tokenStudio from '@tokens-studio/sd-transforms';
|
|
2
|
-
import StyleDictionary from 'style-dictionary';
|
|
3
|
-
import { outputReferencesFilter } from 'style-dictionary/utils';
|
|
4
|
-
import * as R from 'ramda';
|
|
5
|
-
import { permutateThemes as permutateThemes_ } from './utils/permutateThemes';
|
|
6
|
-
import { nameKebab, typographyShorthand, sizeRem } from './transformers.js';
|
|
7
|
-
import { jsTokens } from './formats/js-tokens.js';
|
|
8
|
-
import { cssVariables } from './formats/css-variables.js';
|
|
9
|
-
import { cssClassesTypography } from './formats/css-classes';
|
|
10
|
-
import { makeEntryFile } from './actions.js';
|
|
11
|
-
import { typeEquals } from './utils/utils';
|
|
12
|
-
void tokenStudio.registerTransforms(StyleDictionary);
|
|
13
|
-
const prefix = 'ds';
|
|
14
|
-
const basePxFontSize = 16;
|
|
15
|
-
const separator = '_';
|
|
16
|
-
const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
|
|
17
|
-
StyleDictionary.registerTransform(sizeRem);
|
|
18
|
-
StyleDictionary.registerTransform(nameKebab);
|
|
19
|
-
StyleDictionary.registerTransform(typographyShorthand);
|
|
20
|
-
StyleDictionary.registerFormat(jsTokens);
|
|
21
|
-
StyleDictionary.registerFormat(cssVariables);
|
|
22
|
-
StyleDictionary.registerFormat(cssClassesTypography);
|
|
23
|
-
StyleDictionary.registerAction(makeEntryFile);
|
|
24
|
-
const dsTransformers = [
|
|
25
|
-
nameKebab.name,
|
|
26
|
-
`ts/resolveMath`,
|
|
27
|
-
'ts/size/px',
|
|
28
|
-
sizeRem.name,
|
|
29
|
-
'ts/typography/fontWeight',
|
|
30
|
-
typographyShorthand.name,
|
|
31
|
-
'ts/color/modifiers',
|
|
32
|
-
'ts/color/css/hexrgba',
|
|
33
|
-
'ts/size/lineheight',
|
|
34
|
-
'ts/shadow/css/shorthand',
|
|
35
|
-
];
|
|
36
|
-
const processThemeName = R.pipe(R.replace(`${separator}semantic`, ''), R.toLower, R.split(separator));
|
|
37
|
-
const outputColorReferences = (token) => {
|
|
38
|
-
if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) &&
|
|
39
|
-
R.includes('semantic/color', token.filePath)) {
|
|
40
|
-
return true;
|
|
41
|
-
}
|
|
42
|
-
return false;
|
|
43
|
-
};
|
|
44
|
-
export const permutateThemes = ($themes) => permutateThemes_($themes, {
|
|
45
|
-
separator,
|
|
46
|
-
});
|
|
47
|
-
export const colorModeVariables = ({ mode = 'light', outPath, theme }) => {
|
|
48
|
-
const selector = `${mode === 'light' ? ':root, ' : ''}[data-ds-color-mode="${mode}"]`;
|
|
49
|
-
return {
|
|
50
|
-
log: { verbosity: 'silent' },
|
|
51
|
-
preprocessors: ['tokens-studio'],
|
|
52
|
-
platforms: {
|
|
53
|
-
css: {
|
|
54
|
-
// custom
|
|
55
|
-
outPath,
|
|
56
|
-
mode,
|
|
57
|
-
theme,
|
|
58
|
-
selector,
|
|
59
|
-
//
|
|
60
|
-
prefix,
|
|
61
|
-
buildPath: `${outPath}/${theme}/`,
|
|
62
|
-
transforms: dsTransformers,
|
|
63
|
-
actions: [makeEntryFile.name],
|
|
64
|
-
files: [
|
|
65
|
-
{
|
|
66
|
-
destination: `color-mode/${mode}.css`,
|
|
67
|
-
format: cssVariables.name,
|
|
68
|
-
filter: (token) => !token.isSource && typeEquals('color', token),
|
|
69
|
-
},
|
|
70
|
-
],
|
|
71
|
-
options: {
|
|
72
|
-
fileHeader,
|
|
73
|
-
outputReferences: (token, options) => outputColorReferences(token) && outputReferencesFilter(token, options),
|
|
74
|
-
},
|
|
75
|
-
},
|
|
76
|
-
},
|
|
77
|
-
};
|
|
78
|
-
};
|
|
79
|
-
export const semanticVariables = ({ outPath, theme }) => {
|
|
80
|
-
const selector = `:root`;
|
|
81
|
-
/**
|
|
82
|
-
* This is a workaround for our formatters to support transative transformers while retaining outputReference.
|
|
83
|
-
*
|
|
84
|
-
* This function will wrap formatted token in `calc()`
|
|
85
|
-
*
|
|
86
|
-
* @example --ds-spacing-1: var(--ds-spacing-base)*1; -> --ds-spacing-0: calc(var(--ds-spacing-base)*1);
|
|
87
|
-
*/
|
|
88
|
-
const isCalculatedToken = (token) => typeEquals(['spacing', 'sizing', 'borderRadius'], token);
|
|
89
|
-
return {
|
|
90
|
-
log: { verbosity: 'silent' },
|
|
91
|
-
preprocessors: ['tokens-studio'],
|
|
92
|
-
platforms: {
|
|
93
|
-
css: {
|
|
94
|
-
// custom
|
|
95
|
-
outPath,
|
|
96
|
-
theme,
|
|
97
|
-
basePxFontSize,
|
|
98
|
-
isCalculatedToken,
|
|
99
|
-
selector,
|
|
100
|
-
//
|
|
101
|
-
prefix,
|
|
102
|
-
buildPath: `${outPath}/${theme}/`,
|
|
103
|
-
transforms: dsTransformers,
|
|
104
|
-
actions: [makeEntryFile.name],
|
|
105
|
-
files: [
|
|
106
|
-
{
|
|
107
|
-
destination: `semantic.css`,
|
|
108
|
-
format: cssVariables.name,
|
|
109
|
-
filter: (token) => (!token.isSource || isCalculatedToken(token)) &&
|
|
110
|
-
!typeEquals(['color', 'fontWeights', 'fontFamilies'], token),
|
|
111
|
-
},
|
|
112
|
-
],
|
|
113
|
-
options: {
|
|
114
|
-
fileHeader,
|
|
115
|
-
outputReferences: (token, options) => isCalculatedToken(token) && outputReferencesFilter(token, options),
|
|
116
|
-
},
|
|
117
|
-
},
|
|
118
|
-
},
|
|
119
|
-
};
|
|
120
|
-
};
|
|
121
|
-
export const typescriptTokens = ({ mode = 'unknown', outPath, theme }) => {
|
|
122
|
-
return {
|
|
123
|
-
log: { verbosity: 'silent' },
|
|
124
|
-
preprocessors: ['tokens-studio'],
|
|
125
|
-
platforms: {
|
|
126
|
-
ts: {
|
|
127
|
-
prefix,
|
|
128
|
-
basePxFontSize,
|
|
129
|
-
transforms: dsTransformers,
|
|
130
|
-
buildPath: `${outPath}/${theme}/`,
|
|
131
|
-
files: [
|
|
132
|
-
{
|
|
133
|
-
destination: `${mode}.ts`,
|
|
134
|
-
format: jsTokens.name,
|
|
135
|
-
outputReferences: outputColorReferences,
|
|
136
|
-
filter: (token) => {
|
|
137
|
-
if (R.test(/primitives\/modes|\/themes/, token.filePath)) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) ||
|
|
141
|
-
R.includes('semantic', token.filePath)) {
|
|
142
|
-
return true;
|
|
143
|
-
}
|
|
144
|
-
return false;
|
|
145
|
-
},
|
|
146
|
-
},
|
|
147
|
-
],
|
|
148
|
-
options: {
|
|
149
|
-
fileHeader,
|
|
150
|
-
},
|
|
151
|
-
},
|
|
152
|
-
},
|
|
153
|
-
};
|
|
154
|
-
};
|
|
155
|
-
export const typographyCSS = ({ outPath, theme, typography }) => {
|
|
156
|
-
// const selector = `${typography === 'default' ? ':root, ' : ''}[data-ds-typography="${typography}"]`;
|
|
157
|
-
return {
|
|
158
|
-
log: { verbosity: 'silent' },
|
|
159
|
-
preprocessors: ['tokens-studio'],
|
|
160
|
-
hooks: {
|
|
161
|
-
transforms: {
|
|
162
|
-
typographyClassName: {
|
|
163
|
-
type: 'name',
|
|
164
|
-
filter: (token) => typeEquals('typography', token),
|
|
165
|
-
transform: (token) => {
|
|
166
|
-
const name = R.pipe((list) => {
|
|
167
|
-
const withPrefix = R.concat([prefix], R.remove(0, 0, list));
|
|
168
|
-
const [rest, last] = R.splitAt(-1, withPrefix);
|
|
169
|
-
return `${rest.join('-')}--${R.head(last)}`;
|
|
170
|
-
}, R.trim, R.toLower)(token.path);
|
|
171
|
-
return name;
|
|
172
|
-
},
|
|
173
|
-
},
|
|
174
|
-
},
|
|
175
|
-
},
|
|
176
|
-
platforms: {
|
|
177
|
-
css: {
|
|
178
|
-
prefix,
|
|
179
|
-
typography,
|
|
180
|
-
// selector,
|
|
181
|
-
buildPath: `${outPath}/${theme}/`,
|
|
182
|
-
basePxFontSize,
|
|
183
|
-
transforms: [
|
|
184
|
-
nameKebab.name,
|
|
185
|
-
'ts/size/px',
|
|
186
|
-
sizeRem.name,
|
|
187
|
-
'typographyClassName',
|
|
188
|
-
'ts/size/lineheight',
|
|
189
|
-
'ts/typography/fontWeight',
|
|
190
|
-
],
|
|
191
|
-
files: [
|
|
192
|
-
{
|
|
193
|
-
destination: `typography.css`,
|
|
194
|
-
format: cssClassesTypography.name,
|
|
195
|
-
filter: (token) => {
|
|
196
|
-
return (typeEquals(['typography', 'fontweights', 'fontfamilies', 'lineheights', 'fontsizes'], token) &&
|
|
197
|
-
!(token.path[0] || '').startsWith('theme'));
|
|
198
|
-
},
|
|
199
|
-
},
|
|
200
|
-
],
|
|
201
|
-
options: {
|
|
202
|
-
fileHeader,
|
|
203
|
-
},
|
|
204
|
-
},
|
|
205
|
-
},
|
|
206
|
-
};
|
|
207
|
-
};
|
|
208
|
-
export const getConfigs = (getConfig, outPath, tokensDir, themes) => Object.entries(themes)
|
|
209
|
-
.map(([name, tokensets]) => {
|
|
210
|
-
const setsWithPaths = tokensets.map((x) => `${tokensDir}/${x}.json`);
|
|
211
|
-
const [mode, theme, semantic, fontSize, typography] = processThemeName(name);
|
|
212
|
-
const paritionPrimitives = /(?!.*global\.json).*primitives.*/;
|
|
213
|
-
const [source, include] = R.partition(R.test(paritionPrimitives), setsWithPaths);
|
|
214
|
-
const config_ = getConfig({
|
|
215
|
-
outPath,
|
|
216
|
-
theme,
|
|
217
|
-
mode,
|
|
218
|
-
semantic,
|
|
219
|
-
fontSize,
|
|
220
|
-
typography,
|
|
221
|
-
});
|
|
222
|
-
const config = {
|
|
223
|
-
...config_,
|
|
224
|
-
source,
|
|
225
|
-
include,
|
|
226
|
-
};
|
|
227
|
-
return { name: `${theme}-${mode}`, config };
|
|
228
|
-
})
|
|
229
|
-
.sort();
|
|
@@ -1,50 +0,0 @@
|
|
|
1
|
-
import * as R from 'ramda';
|
|
2
|
-
import { fileHeader, createPropertyFormatter, getReferences } from 'style-dictionary/utils';
|
|
3
|
-
import { getValue, getType, typeEquals } from '../utils/utils';
|
|
4
|
-
const sortByType = R.sortBy((token) => token?.type === 'typography');
|
|
5
|
-
const getVariableName = R.pipe(R.split(':'), R.head, R.defaultTo(''), R.trim);
|
|
6
|
-
/**
|
|
7
|
-
* Creates CSS classes from typography tokens
|
|
8
|
-
*/
|
|
9
|
-
export const cssClassesTypography = {
|
|
10
|
-
name: 'ds/css-classes-typography',
|
|
11
|
-
format: async function ({ dictionary, file, options, platform }) {
|
|
12
|
-
const { outputReferences } = options;
|
|
13
|
-
const { selector } = platform;
|
|
14
|
-
const header = await fileHeader({ file });
|
|
15
|
-
const format = createPropertyFormatter({
|
|
16
|
-
outputReferences,
|
|
17
|
-
dictionary,
|
|
18
|
-
format: 'css',
|
|
19
|
-
});
|
|
20
|
-
const formattedTokens = R.pipe(sortByType, R.reduce((acc, token) => {
|
|
21
|
-
const type = getType(token);
|
|
22
|
-
if (type === 'typography') {
|
|
23
|
-
const classSelector = R.replace('-typography', '', token.name);
|
|
24
|
-
const references = getReferences(getValue(token.original), dictionary.tokens);
|
|
25
|
-
const fontweight = R.find(R.curry(typeEquals)(['fontweights']))(references);
|
|
26
|
-
const lineheight = R.find(R.curry(typeEquals)(['lineheights']))(references);
|
|
27
|
-
const lineheightValue = R.isNotNil(lineheight) ? getValue(lineheight) : '';
|
|
28
|
-
const fontsize = R.find(R.curry(typeEquals)(['fontsizes']))(references);
|
|
29
|
-
const fontSizeValue = R.isNotNil(fontsize) ? getValue(fontsize) : '';
|
|
30
|
-
let fontWeightName = '';
|
|
31
|
-
if (fontweight) {
|
|
32
|
-
fontWeightName = getVariableName(format(fontweight));
|
|
33
|
-
}
|
|
34
|
-
const className = `
|
|
35
|
-
.${classSelector} {
|
|
36
|
-
font-size: ${fontSizeValue};
|
|
37
|
-
line-height: ${lineheightValue};
|
|
38
|
-
${fontWeightName && `font-weight: var(${fontWeightName});`}
|
|
39
|
-
}`;
|
|
40
|
-
return { ...acc, classes: [...acc.classes, className] };
|
|
41
|
-
}
|
|
42
|
-
return { ...acc, variables: [...acc.variables, format(token)] };
|
|
43
|
-
}, { variables: [], classes: [] }))(dictionary.allTokens);
|
|
44
|
-
const classes = formattedTokens.classes.join('\n');
|
|
45
|
-
const variables = formattedTokens.variables.join('\n');
|
|
46
|
-
const variables_ = `:root {\n${variables}\n}\n`;
|
|
47
|
-
const content = selector ? `${selector} {\n${classes}\n}` : classes;
|
|
48
|
-
return header + `@layer ds.typography {\n${variables_}\n${content}\n}\n`;
|
|
49
|
-
},
|
|
50
|
-
};
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import * as R from 'ramda';
|
|
2
|
-
import { fileHeader, createPropertyFormatter, usesReferences } from 'style-dictionary/utils';
|
|
3
|
-
import { getValue } from '../utils/utils';
|
|
4
|
-
const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}: calc(${R.trim(split[1])});`);
|
|
5
|
-
const prefersColorScheme = (mode, content) => `
|
|
6
|
-
@media (prefers-color-scheme: ${mode}) {
|
|
7
|
-
[data-ds-color-mode="auto"] ${content}
|
|
8
|
-
}
|
|
9
|
-
`;
|
|
10
|
-
export const cssVariables = {
|
|
11
|
-
name: 'ds/css-variables',
|
|
12
|
-
format: async function ({ dictionary, file, options, platform }) {
|
|
13
|
-
const { allTokens } = dictionary;
|
|
14
|
-
const { outputReferences } = options;
|
|
15
|
-
const { selector, isCalculatedToken, mode } = platform;
|
|
16
|
-
const mode_ = mode;
|
|
17
|
-
const header = await fileHeader({ file });
|
|
18
|
-
const format = createPropertyFormatter({
|
|
19
|
-
outputReferences,
|
|
20
|
-
dictionary,
|
|
21
|
-
format: 'css',
|
|
22
|
-
});
|
|
23
|
-
const formatTokens = R.map((token) => {
|
|
24
|
-
const originalValue = getValue(token.original);
|
|
25
|
-
if (usesReferences(originalValue) &&
|
|
26
|
-
typeof outputReferences === 'function' &&
|
|
27
|
-
outputReferences?.(token, { dictionary })) {
|
|
28
|
-
if (isCalculatedToken?.(token, options)) {
|
|
29
|
-
return calculatedVariable(format(token));
|
|
30
|
-
}
|
|
31
|
-
}
|
|
32
|
-
return format(token);
|
|
33
|
-
});
|
|
34
|
-
const formattedVariables = formatTokens(allTokens);
|
|
35
|
-
const content = `{\n${formattedVariables.join('\n')}\n}\n`;
|
|
36
|
-
const autoSelectorContent = ['light', 'dark'].includes(mode_) ? prefersColorScheme(mode_, content) : '';
|
|
37
|
-
return header + `${selector} ${content}` + autoSelectorContent;
|
|
38
|
-
},
|
|
39
|
-
};
|
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import * as R from 'ramda';
|
|
2
|
-
import { fileHeader, createPropertyFormatter } from 'style-dictionary/utils';
|
|
3
|
-
import { getType } from '../utils/utils';
|
|
4
|
-
const groupByType = R.groupBy((token) => getType(token));
|
|
5
|
-
/** Add token name with prefix to list for removal */
|
|
6
|
-
const removeUnwatedTokens = R.filter((token) => !['fds-base_spacing', 'fds-base_sizing'].includes(token.name));
|
|
7
|
-
const toCssVarName = R.pipe(R.split(':'), R.head, R.trim);
|
|
8
|
-
/**
|
|
9
|
-
* Format for displaying tokens in storefront
|
|
10
|
-
*/
|
|
11
|
-
export const jsTokens = {
|
|
12
|
-
name: 'ds/js-tokens',
|
|
13
|
-
format: async function ({ dictionary, file }) {
|
|
14
|
-
const format = createPropertyFormatter({
|
|
15
|
-
dictionary,
|
|
16
|
-
format: 'css',
|
|
17
|
-
});
|
|
18
|
-
const formatTokens = R.map((token) => ({
|
|
19
|
-
...token,
|
|
20
|
-
name: toCssVarName(format(token)),
|
|
21
|
-
}));
|
|
22
|
-
const processTokens = R.pipe(removeUnwatedTokens, formatTokens, groupByType);
|
|
23
|
-
const tokens = processTokens(dictionary.allTokens);
|
|
24
|
-
const content = Object.entries(tokens)
|
|
25
|
-
.map(([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, '$1:')} \n`)
|
|
26
|
-
.join('\n');
|
|
27
|
-
return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
|
|
28
|
-
},
|
|
29
|
-
};
|
|
@@ -1,42 +0,0 @@
|
|
|
1
|
-
import * as R from 'ramda';
|
|
2
|
-
import { noCase } from './utils/noCase';
|
|
3
|
-
import { getValue, typeEquals } from './utils/utils';
|
|
4
|
-
const isPx = R.test(/\b\d+px\b/g);
|
|
5
|
-
export const sizeRem = {
|
|
6
|
-
name: 'ds/size/toRem',
|
|
7
|
-
type: 'value',
|
|
8
|
-
transitive: true,
|
|
9
|
-
filter: (token) => typeEquals(['sizing', 'spacing', 'borderRadius', 'fontsizes'], token),
|
|
10
|
-
transform: (token, config) => {
|
|
11
|
-
const value = getValue(token);
|
|
12
|
-
if (isPx(value)) {
|
|
13
|
-
const baseFont = config.basePxFontSize || 16;
|
|
14
|
-
const size = parseInt(value);
|
|
15
|
-
if (size === 0) {
|
|
16
|
-
return '0';
|
|
17
|
-
}
|
|
18
|
-
return `${size / baseFont}rem`;
|
|
19
|
-
}
|
|
20
|
-
return value;
|
|
21
|
-
},
|
|
22
|
-
};
|
|
23
|
-
export const nameKebab = {
|
|
24
|
-
name: 'name/cti/hierarchical-kebab',
|
|
25
|
-
type: 'name',
|
|
26
|
-
transform: (token, options) => {
|
|
27
|
-
return noCase([options?.prefix].concat(token.path).join('-'), {
|
|
28
|
-
delimiter: '-',
|
|
29
|
-
stripRegexp: /[^A-Z0-9_]+/gi,
|
|
30
|
-
});
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
export const typographyShorthand = {
|
|
34
|
-
name: 'typography/shorthand',
|
|
35
|
-
type: 'value',
|
|
36
|
-
transitive: true,
|
|
37
|
-
filter: (token) => token.type === 'typography',
|
|
38
|
-
transform: (token) => {
|
|
39
|
-
const typography = getValue(token);
|
|
40
|
-
return `${typography.fontWeight} ${typography.fontSize}/${typography.lineHeight} '${typography.fontFamily}'`;
|
|
41
|
-
},
|
|
42
|
-
};
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
// Copied from https://github.com/blakeembrey/change-case/blob/change-case%404.1.2/packages/no-case/src/index.ts
|
|
2
|
-
const lowerCase = (text = '') => text.toLowerCase();
|
|
3
|
-
// Support camel case ("camelCase" -> "camel Case" and "CAMELCase" -> "CAMEL Case").
|
|
4
|
-
const DEFAULT_SPLIT_REGEXP = [/([a-z0-9])([A-Z])/g, /([A-Z])([A-Z][a-z])/g];
|
|
5
|
-
// Remove all non-word characters.
|
|
6
|
-
const DEFAULT_STRIP_REGEXP = /[^A-Z0-9]+/gi;
|
|
7
|
-
/**
|
|
8
|
-
* Normalize the string into something other libraries can manipulate easier.
|
|
9
|
-
*/
|
|
10
|
-
export function noCase(input, options = {}) {
|
|
11
|
-
const { splitRegexp = DEFAULT_SPLIT_REGEXP, stripRegexp = DEFAULT_STRIP_REGEXP, transform = lowerCase, delimiter = ' ', } = options;
|
|
12
|
-
const result = replace(replace(input, splitRegexp, '$1\0$2'), stripRegexp, '\0');
|
|
13
|
-
let start = 0;
|
|
14
|
-
let end = result.length;
|
|
15
|
-
// Trim the delimiter from around the output string.
|
|
16
|
-
while (result.charAt(start) === '\0')
|
|
17
|
-
start++;
|
|
18
|
-
while (result.charAt(end - 1) === '\0')
|
|
19
|
-
end--;
|
|
20
|
-
// Transform each token independently.
|
|
21
|
-
return result.slice(start, end).split('\0').map(transform).join(delimiter);
|
|
22
|
-
}
|
|
23
|
-
/**
|
|
24
|
-
* Replace `re` in the input string with the replacement value.
|
|
25
|
-
*/
|
|
26
|
-
function replace(input, re, value) {
|
|
27
|
-
if (re instanceof RegExp)
|
|
28
|
-
return input.replace(re, value);
|
|
29
|
-
return re.reduce((input, re) => input.replace(re, value), input);
|
|
30
|
-
}
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
import { TokenSetStatus } from '@tokens-studio/types';
|
|
2
|
-
function mapThemesToSetsObject(themes) {
|
|
3
|
-
return Object.fromEntries(themes.map((theme) => [theme.name, filterTokenSets(theme.selectedTokenSets)]));
|
|
4
|
-
}
|
|
5
|
-
export function permutateThemes(themes, { separator = '-' } = {}) {
|
|
6
|
-
if (themes.some((theme) => theme.group)) {
|
|
7
|
-
// Sort themes by groups
|
|
8
|
-
const groups = {};
|
|
9
|
-
themes.forEach((theme) => {
|
|
10
|
-
if (theme.group) {
|
|
11
|
-
groups[theme.group] = [...(groups[theme.group] ?? []), theme];
|
|
12
|
-
}
|
|
13
|
-
else {
|
|
14
|
-
throw new Error(`Theme ${theme.name} does not have a group property, which is required for multi-dimensional theming.`);
|
|
15
|
-
}
|
|
16
|
-
});
|
|
17
|
-
if (Object.keys(groups).length <= 1) {
|
|
18
|
-
return mapThemesToSetsObject(themes);
|
|
19
|
-
}
|
|
20
|
-
// Create theme permutations
|
|
21
|
-
const permutations = cartesian(Object.values(groups));
|
|
22
|
-
return Object.fromEntries(permutations.map((perm) => {
|
|
23
|
-
// 1) concat the names of the theme groups to create the permutation theme name
|
|
24
|
-
// 2) merge the selectedTokenSets together from the different theme group parts
|
|
25
|
-
const reduced = perm.reduce((acc, curr) => [
|
|
26
|
-
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
|
|
27
|
-
`${acc[0]}${acc[0] ? separator : ''}${curr.name}`,
|
|
28
|
-
[...acc[1], ...filterTokenSets(curr.selectedTokenSets)],
|
|
29
|
-
], ['', []]);
|
|
30
|
-
// Dedupe the tokensets, return as entries [name, sets]
|
|
31
|
-
return [reduced[0], [...new Set(reduced[1])]];
|
|
32
|
-
}));
|
|
33
|
-
}
|
|
34
|
-
else {
|
|
35
|
-
return mapThemesToSetsObject(themes);
|
|
36
|
-
}
|
|
37
|
-
}
|
|
38
|
-
function filterTokenSets(tokensets) {
|
|
39
|
-
return (Object.entries(tokensets)
|
|
40
|
-
.filter(([, val]) => val !== TokenSetStatus.DISABLED)
|
|
41
|
-
// ensure source type sets are always ordered before enabled type sets
|
|
42
|
-
.sort((a, b) => {
|
|
43
|
-
if (a[1] === TokenSetStatus.SOURCE && b[1] === TokenSetStatus.ENABLED) {
|
|
44
|
-
return -1;
|
|
45
|
-
}
|
|
46
|
-
else if (a[1] === TokenSetStatus.ENABLED && b[1] === TokenSetStatus.SOURCE) {
|
|
47
|
-
return 1;
|
|
48
|
-
}
|
|
49
|
-
return 0;
|
|
50
|
-
})
|
|
51
|
-
.map((entry) => entry[0]));
|
|
52
|
-
}
|
|
53
|
-
// cartesian permutations: [[1,2], [3,4]] -> [[1,3], [1,4], [2,3], [2,4]]
|
|
54
|
-
function cartesian(a) {
|
|
55
|
-
return a.reduce((a, b) => a.flatMap((d) => b.map((e) => [d, e].flat())));
|
|
56
|
-
}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import * as R from 'ramda';
|
|
2
|
-
/**
|
|
3
|
-
* Returns type based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
4
|
-
* @param token Transformed token
|
|
5
|
-
* @returns type
|
|
6
|
-
*/
|
|
7
|
-
export const getType = (token) => (token.$type ?? token.type) || '';
|
|
8
|
-
/**
|
|
9
|
-
* Returns value based on design token format used. Read more:https://v4.styledictionary.com/info/dtcg/
|
|
10
|
-
*
|
|
11
|
-
* Use generic (`<T>`) to define return value type
|
|
12
|
-
* @param token Transformed or Design token
|
|
13
|
-
* @returns value
|
|
14
|
-
*/
|
|
15
|
-
export const getValue = (token) => (token.$value ?? token.value);
|
|
16
|
-
export const typeEquals = (types, token) => {
|
|
17
|
-
if (R.isNil(token)) {
|
|
18
|
-
return false;
|
|
19
|
-
}
|
|
20
|
-
return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
|
|
21
|
-
};
|