@digdir/designsystemet 1.0.0-next.43 → 1.0.0-next.45
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 +8 -6
- package/dist/src/colors/theme.d.ts.map +1 -1
- package/dist/src/colors/theme.js +1 -1
- package/dist/src/migrations/beta-to-v1.js +40 -40
- package/dist/src/tokens/build/configs.d.ts.map +1 -1
- package/dist/src/tokens/build/configs.js +25 -23
- package/dist/src/tokens/build/formats/css.d.ts +38 -0
- package/dist/src/tokens/build/formats/css.d.ts.map +1 -1
- package/dist/src/tokens/build/formats/css.js +60 -15
- package/dist/src/tokens/build/formats/js-tokens.d.ts.map +1 -1
- package/dist/src/tokens/build/formats/js-tokens.js +19 -9
- package/dist/src/tokens/build/transformers.d.ts +1 -0
- package/dist/src/tokens/build/transformers.d.ts.map +1 -1
- package/dist/src/tokens/build/transformers.js +10 -2
- package/dist/src/tokens/build.js +1 -1
- package/dist/src/tokens/create.d.ts +1 -1
- package/dist/src/tokens/create.d.ts.map +1 -1
- package/dist/src/tokens/create.js +1 -1
- package/dist/src/tokens/design-tokens/default/Figma/components.json +3 -3
- package/dist/src/tokens/design-tokens/default/primitives/globals.json +1 -13
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/global.json +96 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/large.json +16 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/medium.json +16 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/size/small.json +16 -0
- package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/large.json +100 -0
- package/dist/src/tokens/design-tokens/default/primitives/{size/default.json → modes/typography/size/medium.json} +0 -75
- package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/small.json +100 -0
- package/dist/src/tokens/design-tokens/default/semantic/style.json +6 -166
- package/dist/src/tokens/design-tokens/template/$metadata.json +7 -2
- package/dist/src/tokens/design-tokens/template/$themes.json +1319 -1196
- package/dist/src/tokens/design-tokens/template/themes/theme-base-file.json +8 -4
- package/dist/src/tokens/template.d.ts.map +1 -1
- package/dist/src/tokens/template.js +2 -1
- package/dist/src/tokens/types.d.ts +12 -0
- package/dist/src/tokens/types.d.ts.map +1 -1
- package/dist/src/tokens/write/generate$metadata.d.ts.map +1 -1
- package/dist/src/tokens/write/generate$metadata.js +7 -1
- package/dist/src/tokens/write/generate$themes.d.ts +1 -0
- package/dist/src/tokens/write/generate$themes.d.ts.map +1 -1
- package/dist/src/tokens/write/generate$themes.js +141 -3
- package/dist/src/tokens/write.d.ts +2 -3
- package/dist/src/tokens/write.d.ts.map +1 -1
- package/dist/src/tokens/write.js +9 -2
- package/package.json +2 -2
|
@@ -22,12 +22,13 @@ function makeTokenCommands() {
|
|
|
22
22
|
}
|
|
23
23
|
return buildTokens({ tokens, outDir, preview, verbose, dry });
|
|
24
24
|
});
|
|
25
|
-
tokenCmd.command("create").description("Create Designsystemet tokens").requiredOption(`-m, --${colorCliOptions.main} <name:hex...>`, `Main colors`, parseColorValues).requiredOption(`-s, --${colorCliOptions.support} <name:hex...>`, `Support colors`, parseColorValues).requiredOption(`-n, --${colorCliOptions.neutral} <hex>`, `Neutral hex color`, convertToHex).option("-o, --out-dir <string>", `Output directory for created ${chalk.blue("design-tokens")}`, DEFAULT_TOKENS_DIR).option("--dry [boolean]", `Dry run for created ${chalk.blue("design-tokens")}`, false).option("-f, --font-family <string>", `Font family`, "Inter").option("--theme <string>", `Theme name`, "theme").action(async (opts) => {
|
|
25
|
+
tokenCmd.command("create").description("Create Designsystemet tokens").requiredOption(`-m, --${colorCliOptions.main} <name:hex...>`, `Main colors`, parseColorValues).requiredOption(`-s, --${colorCliOptions.support} <name:hex...>`, `Support colors`, parseColorValues).requiredOption(`-n, --${colorCliOptions.neutral} <hex>`, `Neutral hex color`, convertToHex).option("-o, --out-dir <string>", `Output directory for created ${chalk.blue("design-tokens")}`, DEFAULT_TOKENS_DIR).option("--dry [boolean]", `Dry run for created ${chalk.blue("design-tokens")}`, false).option("-f, --font-family <string>", `Font family`, "Inter").option("-b, --border-radius <number>", `Unitless base border-radius in px`, "4").option("--theme <string>", `Theme name`, "theme").action(async (opts) => {
|
|
26
26
|
const { theme, fontFamily, outDir } = opts;
|
|
27
27
|
const dry = Boolean(opts.dry);
|
|
28
|
+
const borderRadius = Number(opts.borderRadius);
|
|
28
29
|
console.log(`Creating tokens with options ${chalk.green(JSON.stringify(opts, null, 2))}`);
|
|
29
|
-
const
|
|
30
|
-
|
|
30
|
+
const themeOptions = {
|
|
31
|
+
name: theme,
|
|
31
32
|
colors: {
|
|
32
33
|
main: opts.mainColors,
|
|
33
34
|
support: opts.supportColors,
|
|
@@ -35,13 +36,14 @@ function makeTokenCommands() {
|
|
|
35
36
|
},
|
|
36
37
|
typography: {
|
|
37
38
|
fontFamily
|
|
38
|
-
}
|
|
39
|
+
},
|
|
40
|
+
borderRadius
|
|
39
41
|
};
|
|
40
42
|
if (dry) {
|
|
41
43
|
console.log(`Performing dry run, no files will be written`);
|
|
42
44
|
}
|
|
43
|
-
const tokens = createTokens(
|
|
44
|
-
await writeTokens({ outDir, tokens,
|
|
45
|
+
const tokens = createTokens(themeOptions);
|
|
46
|
+
await writeTokens({ outDir, tokens, theme: themeOptions, dry });
|
|
45
47
|
return Promise.resolve();
|
|
46
48
|
});
|
|
47
49
|
return tokenCmd;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/colors/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG/F,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,YAAY,EAAE,QAAQ,CAOrD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,UAAW,QAAQ,eAAe,WAAW,KAAG,SAAS,EA8BvF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,UAAW,QAAQ,KAAG,SAIrD,CAAC;
|
|
1
|
+
{"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../src/colors/theme.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAI3C,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,YAAY,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAG/F,eAAO,MAAM,UAAU,EAAE,MAAM,CAAC,YAAY,EAAE,QAAQ,CAOrD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,kBAAkB,UAAW,QAAQ,eAAe,WAAW,KAAG,SAAS,EA8BvF,CAAC;AAEF;;;;GAIG;AACH,eAAO,MAAM,oBAAoB,UAAW,QAAQ,KAAG,SAIrD,CAAC;AAgCH;;;;GAIG;AACH,eAAO,MAAM,kBAAkB,UAAW,QAAQ,KAAG,QAC2C,CAAC;AAEjG;;;;GAIG;AACH,eAAO,MAAM,iBAAiB,UAAW,QAAQ,KAAG,QAQnD,CAAC;AAEF;;;;;GAKG;AACH,eAAO,MAAM,cAAc,cAAe,MAAM,eAAe,WAAW,WAEzE,CAAC"}
|
package/dist/src/colors/theme.js
CHANGED
|
@@ -46,7 +46,7 @@ const getBaseColors = (color, colorScheme) => {
|
|
|
46
46
|
const modifier = colorLightness <= 30 || colorLightness >= 49 && colorLightness <= 65 ? -8 : 8;
|
|
47
47
|
const calculateLightness = (base, mod) => base - mod;
|
|
48
48
|
return {
|
|
49
|
-
baseDefault: chroma(color).luminance(getLuminanceFromLightness(colorLightness)).hex(),
|
|
49
|
+
baseDefault: colorScheme === "light" ? color : chroma(color).luminance(getLuminanceFromLightness(colorLightness)).hex(),
|
|
50
50
|
baseHover: chroma(color).luminance(getLuminanceFromLightness(calculateLightness(colorLightness, modifier))).hex(),
|
|
51
51
|
baseActive: chroma(color).luminance(getLuminanceFromLightness(calculateLightness(colorLightness, modifier * 2))).hex()
|
|
52
52
|
};
|
|
@@ -236,46 +236,46 @@ var beta_to_v1_default = (glob) => runCssCodemod({
|
|
|
236
236
|
"--fds-shadow-medium": "--ds-shadow-md",
|
|
237
237
|
"--fds-shadow-large": "--ds-shadow-lg",
|
|
238
238
|
"--fds-shadow-xlarge": "--ds-shadow-xl",
|
|
239
|
-
"--fds-spacing-0": "--ds-
|
|
240
|
-
"--fds-spacing-1": "--ds-
|
|
241
|
-
"--fds-spacing-2": "--ds-
|
|
242
|
-
"--fds-spacing-3": "--ds-
|
|
243
|
-
"--fds-spacing-4": "--ds-
|
|
244
|
-
"--fds-spacing-5": "--ds-
|
|
245
|
-
"--fds-spacing-6": "--ds-
|
|
246
|
-
"--fds-spacing-7": "--ds-
|
|
247
|
-
"--fds-spacing-8": "--ds-
|
|
248
|
-
"--fds-spacing-9": "--ds-
|
|
249
|
-
"--fds-spacing-10": "--ds-
|
|
250
|
-
"--fds-spacing-11": "--ds-
|
|
251
|
-
"--fds-spacing-12": "--ds-
|
|
252
|
-
"--fds-spacing-13": "--ds-
|
|
253
|
-
"--fds-spacing-14": "--ds-
|
|
254
|
-
"--fds-spacing-15": "--ds-
|
|
255
|
-
"--fds-spacing-18": "--ds-
|
|
256
|
-
"--fds-spacing-22": "--ds-
|
|
257
|
-
"--fds-spacing-26": "--ds-
|
|
258
|
-
"--fds-spacing-30": "--ds-
|
|
259
|
-
"--fds-sizing-0": "--ds-
|
|
260
|
-
"--fds-sizing-1": "--ds-
|
|
261
|
-
"--fds-sizing-2": "--ds-
|
|
262
|
-
"--fds-sizing-3": "--ds-
|
|
263
|
-
"--fds-sizing-4": "--ds-
|
|
264
|
-
"--fds-sizing-5": "--ds-
|
|
265
|
-
"--fds-sizing-6": "--ds-
|
|
266
|
-
"--fds-sizing-7": "--ds-
|
|
267
|
-
"--fds-sizing-8": "--ds-
|
|
268
|
-
"--fds-sizing-9": "--ds-
|
|
269
|
-
"--fds-sizing-10": "--ds-
|
|
270
|
-
"--fds-sizing-11": "--ds-
|
|
271
|
-
"--fds-sizing-12": "--ds-
|
|
272
|
-
"--fds-sizing-13": "--ds-
|
|
273
|
-
"--fds-sizing-14": "--ds-
|
|
274
|
-
"--fds-sizing-15": "--ds-
|
|
275
|
-
"--fds-sizing-18": "--ds-
|
|
276
|
-
"--fds-sizing-22": "--ds-
|
|
277
|
-
"--fds-sizing-26": "--ds-
|
|
278
|
-
"--fds-sizing-30": "--ds-
|
|
239
|
+
"--fds-spacing-0": "--ds-size-0",
|
|
240
|
+
"--fds-spacing-1": "--ds-size-1",
|
|
241
|
+
"--fds-spacing-2": "--ds-size-2",
|
|
242
|
+
"--fds-spacing-3": "--ds-size-3",
|
|
243
|
+
"--fds-spacing-4": "--ds-size-4",
|
|
244
|
+
"--fds-spacing-5": "--ds-size-5",
|
|
245
|
+
"--fds-spacing-6": "--ds-size-6",
|
|
246
|
+
"--fds-spacing-7": "--ds-size-7",
|
|
247
|
+
"--fds-spacing-8": "--ds-size-8",
|
|
248
|
+
"--fds-spacing-9": "--ds-size-9",
|
|
249
|
+
"--fds-spacing-10": "--ds-size-10",
|
|
250
|
+
"--fds-spacing-11": "--ds-size-11",
|
|
251
|
+
"--fds-spacing-12": "--ds-size-12",
|
|
252
|
+
"--fds-spacing-13": "--ds-size-13",
|
|
253
|
+
"--fds-spacing-14": "--ds-size-14",
|
|
254
|
+
"--fds-spacing-15": "--ds-size-15",
|
|
255
|
+
"--fds-spacing-18": "--ds-size-18",
|
|
256
|
+
"--fds-spacing-22": "--ds-size-22",
|
|
257
|
+
"--fds-spacing-26": "--ds-size-26",
|
|
258
|
+
"--fds-spacing-30": "--ds-size-30",
|
|
259
|
+
"--fds-sizing-0": "--ds-size-0",
|
|
260
|
+
"--fds-sizing-1": "--ds-size-1",
|
|
261
|
+
"--fds-sizing-2": "--ds-size-2",
|
|
262
|
+
"--fds-sizing-3": "--ds-size-3",
|
|
263
|
+
"--fds-sizing-4": "--ds-size-4",
|
|
264
|
+
"--fds-sizing-5": "--ds-size-5",
|
|
265
|
+
"--fds-sizing-6": "--ds-size-6",
|
|
266
|
+
"--fds-sizing-7": "--ds-size-7",
|
|
267
|
+
"--fds-sizing-8": "--ds-size-8",
|
|
268
|
+
"--fds-sizing-9": "--ds-size-9",
|
|
269
|
+
"--fds-sizing-10": "--ds-size-10",
|
|
270
|
+
"--fds-sizing-11": "--ds-size-11",
|
|
271
|
+
"--fds-sizing-12": "--ds-size-12",
|
|
272
|
+
"--fds-sizing-13": "--ds-size-13",
|
|
273
|
+
"--fds-sizing-14": "--ds-size-14",
|
|
274
|
+
"--fds-sizing-15": "--ds-size-15",
|
|
275
|
+
"--fds-sizing-18": "--ds-size-18",
|
|
276
|
+
"--fds-sizing-22": "--ds-size-22",
|
|
277
|
+
"--fds-sizing-26": "--ds-size-26",
|
|
278
|
+
"--fds-sizing-30": "--ds-size-30",
|
|
279
279
|
"--fds-opacity-disabled": "--ds-disabled-opacity",
|
|
280
280
|
"--fds-colors-blue-100": "--ds-global-blue-1",
|
|
281
281
|
"--fds-colors-blue-200": "--ds-global-blue-2",
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/configs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAoB,MAAM,wBAAwB,CAAC;AAQhG,OAAO,KAAK,EAEV,kBAAkB,
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/configs.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,IAAI,qBAAqB,EAAoB,MAAM,wBAAwB,CAAC;AAQhG,OAAO,KAAK,EAEV,kBAAkB,EAClB,2BAA2B,EAC3B,cAAc,EACd,gBAAgB,EACjB,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,oBAAoB,EAA6B,MAAM,sCAAsC,CAAC;AAO5G,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,cAAc,KAAK,CAAC;AA+BjC,MAAM,MAAM,wBAAwB,GAAG,CACrC,WAAW,EAAE,gBAAgB,EAC7B,OAAO,EAAE;IACP,OAAO,CAAC,EAAE,MAAM,CAAC;CAClB,KACE,qBAAqB,GAAG;IAAE,MAAM,EAAE,qBAAqB,CAAC;IAAC,oBAAoB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,CAAA;CAAE,EAAE,CAAC;AAoPnH,eAAO,MAAM,OAAO;;;;;;;CAOnB,CAAC;AAEF,eAAO,MAAM,4BAA4B,cAC5B,wBAAwB,UAC3B,oBAAoB,EAAE,cAClB,cAAc,EAAE,WACnB,kBAAkB,KAC1B,2BAA2B,EA8B7B,CAAC"}
|
|
@@ -6,7 +6,7 @@ import { DEFAULT_COLOR, buildOptions } from "../build.js";
|
|
|
6
6
|
import { isColorCategoryToken, pathStartsWithOneOf, typeEquals } from "../utils.js";
|
|
7
7
|
import { formats } from "./formats/css.js";
|
|
8
8
|
import { jsTokens } from "./formats/js-tokens.js";
|
|
9
|
-
import { nameKebab, resolveMath, sizeRem, typographyName } from "./transformers.js";
|
|
9
|
+
import { nameKebab, resolveMath, sizeRem, typographyName, unitless } from "./transformers.js";
|
|
10
10
|
import { getMultidimensionalThemes } from "./utils/getMultidimensionalThemes.js";
|
|
11
11
|
void register(StyleDictionary, { withSDBuiltins: false });
|
|
12
12
|
const usesDtcg = true;
|
|
@@ -17,6 +17,7 @@ StyleDictionary.registerTransform(sizeRem);
|
|
|
17
17
|
StyleDictionary.registerTransform(nameKebab);
|
|
18
18
|
StyleDictionary.registerTransform(typographyName);
|
|
19
19
|
StyleDictionary.registerTransform(resolveMath);
|
|
20
|
+
StyleDictionary.registerTransform(unitless);
|
|
20
21
|
StyleDictionary.registerFormat(jsTokens);
|
|
21
22
|
for (const format of Object.values(formats)) {
|
|
22
23
|
StyleDictionary.registerFormat(format);
|
|
@@ -26,6 +27,7 @@ const dsTransformers = [
|
|
|
26
27
|
resolveMath.name,
|
|
27
28
|
"ts/size/px",
|
|
28
29
|
sizeRem.name,
|
|
30
|
+
unitless.name,
|
|
29
31
|
"ts/typography/fontWeight",
|
|
30
32
|
typographyName.name,
|
|
31
33
|
"ts/color/modifiers",
|
|
@@ -34,12 +36,6 @@ const dsTransformers = [
|
|
|
34
36
|
"shadow/css/shorthand"
|
|
35
37
|
];
|
|
36
38
|
const paritionPrimitives = R.partition(R.test(/(?!.*global\.json).*primitives.*/));
|
|
37
|
-
const outputColorReferences = (token) => {
|
|
38
|
-
if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) && R.includes("semantic/color", token.filePath)) {
|
|
39
|
-
return true;
|
|
40
|
-
}
|
|
41
|
-
return false;
|
|
42
|
-
};
|
|
43
39
|
const colorSchemeVariables = ({ "color-scheme": colorScheme = "light", theme }, { outPath }) => {
|
|
44
40
|
const selector = `${colorScheme === "light" ? ":root, " : ""}[data-color-scheme="${colorScheme}"]`;
|
|
45
41
|
const layer = `ds.theme.color-scheme.${colorScheme}`;
|
|
@@ -134,7 +130,6 @@ const colorCategoryVariables = (category) => ({ "color-scheme": colorScheme, the
|
|
|
134
130
|
const semanticVariables = ({ theme }, { outPath }) => {
|
|
135
131
|
const selector = `:root`;
|
|
136
132
|
const layer = `ds.theme.semantic`;
|
|
137
|
-
const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing"], token);
|
|
138
133
|
return {
|
|
139
134
|
usesDtcg,
|
|
140
135
|
preprocessors: ["tokens-studio"],
|
|
@@ -144,7 +139,6 @@ const semanticVariables = ({ theme }, { outPath }) => {
|
|
|
144
139
|
outPath,
|
|
145
140
|
theme,
|
|
146
141
|
basePxFontSize,
|
|
147
|
-
isCalculatedToken,
|
|
148
142
|
selector,
|
|
149
143
|
layer,
|
|
150
144
|
//
|
|
@@ -155,14 +149,19 @@ const semanticVariables = ({ theme }, { outPath }) => {
|
|
|
155
149
|
{
|
|
156
150
|
destination: `semantic.css`,
|
|
157
151
|
format: formats.semantic.name,
|
|
158
|
-
filter: (token) =>
|
|
152
|
+
filter: (token) => {
|
|
153
|
+
const unwantedPaths = pathStartsWithOneOf(["font-size", "line-height", "letter-spacing"], token);
|
|
154
|
+
const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
|
|
155
|
+
const unwantedTokens = !(unwantedPaths || unwantedTypes);
|
|
156
|
+
return !token.isSource && unwantedTokens;
|
|
157
|
+
}
|
|
159
158
|
}
|
|
160
159
|
],
|
|
161
160
|
options: {
|
|
162
161
|
fileHeader,
|
|
163
162
|
outputReferences: (token, options) => {
|
|
164
|
-
const include = pathStartsWithOneOf(["border-radius"], token);
|
|
165
|
-
return
|
|
163
|
+
const include = pathStartsWithOneOf(["border-radius", "size"], token);
|
|
164
|
+
return include && outputReferencesFilter(token, options);
|
|
166
165
|
}
|
|
167
166
|
}
|
|
168
167
|
}
|
|
@@ -183,26 +182,29 @@ const typescriptTokens = ({ "color-scheme": colorScheme, theme }, { outPath }) =
|
|
|
183
182
|
{
|
|
184
183
|
destination: `${colorScheme}.ts`,
|
|
185
184
|
format: jsTokens.name,
|
|
186
|
-
outputReferences: outputColorReferences,
|
|
187
185
|
filter: (token) => {
|
|
188
|
-
if (R.
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
return
|
|
186
|
+
if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R.includes("semantic", token.filePath))
|
|
187
|
+
return false;
|
|
188
|
+
const isSemanticColor = R.includes("semantic", token.filePath) && typeEquals(["color"], token);
|
|
189
|
+
const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
|
|
190
|
+
const isNotPrivate = R.not(R.any((path) => path.startsWith("_"))(token.path));
|
|
191
|
+
return (isSemanticColor || wantedTypes) && isNotPrivate;
|
|
194
192
|
}
|
|
195
193
|
}
|
|
196
194
|
],
|
|
197
195
|
options: {
|
|
198
|
-
fileHeader
|
|
196
|
+
fileHeader,
|
|
197
|
+
outputReferences: (token, options) => {
|
|
198
|
+
const include = pathStartsWithOneOf(["border-radius", "size"], token);
|
|
199
|
+
return include && outputReferencesFilter(token, options);
|
|
200
|
+
}
|
|
199
201
|
}
|
|
200
202
|
}
|
|
201
203
|
}
|
|
202
204
|
};
|
|
203
205
|
};
|
|
204
206
|
const typographyVariables = ({ theme, typography }, { outPath }) => {
|
|
205
|
-
const selector = `${typography === "primary" ? ":root, " : ""}[data-
|
|
207
|
+
const selector = `${typography === "primary" ? ":root, " : ""}[data-typography="${typography}"]`;
|
|
206
208
|
const layer = `ds.theme.typography.${typography}`;
|
|
207
209
|
return {
|
|
208
210
|
usesDtcg: true,
|
|
@@ -233,11 +235,11 @@ const typographyVariables = ({ theme, typography }, { outPath }) => {
|
|
|
233
235
|
format: formats.typography.name,
|
|
234
236
|
filter: (token) => {
|
|
235
237
|
const included = typeEquals(
|
|
236
|
-
["typography", "fontweight", "fontFamily", "
|
|
238
|
+
["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
|
|
237
239
|
token
|
|
238
240
|
);
|
|
239
241
|
return included && !pathStartsWithOneOf(
|
|
240
|
-
["spacing", "sizing", "border-width", "border-radius", "theme", "theme2", "theme3", "theme4"],
|
|
242
|
+
["spacing", "sizing", "size", "border-width", "border-radius", "theme", "theme2", "theme3", "theme4"],
|
|
241
243
|
token
|
|
242
244
|
);
|
|
243
245
|
}
|
|
@@ -1,9 +1,47 @@
|
|
|
1
|
+
import type { TransformedToken } from 'style-dictionary';
|
|
1
2
|
import type { Format } from 'style-dictionary/types';
|
|
3
|
+
/**
|
|
4
|
+
* In the given tokens array, inline and remove tokens that match the predicate
|
|
5
|
+
*
|
|
6
|
+
* Example: In pseudo-code, given the predicate `(token) => token.path === ['size', '1']` and the following tokens
|
|
7
|
+
* ```js
|
|
8
|
+
* [
|
|
9
|
+
* { path: ['size', 'base'], original: { $value: '8px' } },
|
|
10
|
+
* { path: ['size', '1'], original: { $value: '{size.base} * 2' } },
|
|
11
|
+
* { path: ['size', 'sm']: original: { $value: 'min({size.1}, 12px)' } }
|
|
12
|
+
* ]
|
|
13
|
+
* ```
|
|
14
|
+
* would return
|
|
15
|
+
* ```js
|
|
16
|
+
* [
|
|
17
|
+
* { path: ['size', 'base'], original: { $value: '8px' } },
|
|
18
|
+
* { path: ['size', 'sm']: original: { $value: 'min({size.base} * 2, 12px)' } }
|
|
19
|
+
* ]
|
|
20
|
+
* ```
|
|
21
|
+
*
|
|
22
|
+
* @param shouldInline - predicate to determine if token should be inlined
|
|
23
|
+
* @param tokens - array of tokens to transform
|
|
24
|
+
* @returns copy of `tokens` without those that matched the predicate,
|
|
25
|
+
* where references to the matching tokens have been inlined
|
|
26
|
+
*/
|
|
27
|
+
export declare function inlineTokens(shouldInline: (t: TransformedToken) => boolean, tokens: TransformedToken[]): import("style-dictionary/types").TransformedToken[];
|
|
2
28
|
declare module 'style-dictionary/types' {
|
|
3
29
|
interface LocalOptions {
|
|
4
30
|
replaceCategoryWith?: string;
|
|
5
31
|
}
|
|
6
32
|
}
|
|
33
|
+
/**
|
|
34
|
+
* Overrides the default sizing formula with a custom one that supports [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.
|
|
35
|
+
*
|
|
36
|
+
* @param format - Function to format a token into a CSS property string.
|
|
37
|
+
* @param tokens - Array of transformed tokens to format.
|
|
38
|
+
* @returns Object with formatted CSS strings for calc and round.
|
|
39
|
+
*/
|
|
40
|
+
export declare const overrideSizingFormula: (format: (t: TransformedToken) => string, token: TransformedToken) => {
|
|
41
|
+
name: string;
|
|
42
|
+
round: string;
|
|
43
|
+
calc: string;
|
|
44
|
+
};
|
|
7
45
|
export declare const formats: {
|
|
8
46
|
colorScheme: Format;
|
|
9
47
|
colorCategory: Format;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/css.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/css.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAYrD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,uDAYtG;AAsDD,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,YAAY;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B;CACF;AAuCD;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,WAAY,CAAC,CAAC,EAAE,gBAAgB,KAAK,MAAM,SAAS,gBAAgB;;;;CAYrG,CAAC;AAyFF,eAAO,MAAM,OAAO;;;;;CAKc,CAAC"}
|
|
@@ -1,7 +1,25 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
|
-
import { createPropertyFormatter, fileHeader
|
|
3
|
-
import {
|
|
2
|
+
import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
|
|
3
|
+
import {
|
|
4
|
+
getValue,
|
|
5
|
+
isColorCategoryToken,
|
|
6
|
+
isGlobalColorToken,
|
|
7
|
+
isSemanticToken,
|
|
8
|
+
pathStartsWithOneOf
|
|
9
|
+
} from "../../utils.js";
|
|
4
10
|
import { colorCategories } from "../types.js";
|
|
11
|
+
function inlineTokens(shouldInline, tokens) {
|
|
12
|
+
const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
|
|
13
|
+
return otherTokens.map((token) => {
|
|
14
|
+
let transformed = getValue(token.original);
|
|
15
|
+
for (const ref of inlineableTokens) {
|
|
16
|
+
const refName = ref.path.join(".");
|
|
17
|
+
transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
|
|
18
|
+
}
|
|
19
|
+
const tokenWithInlinedRefs = R.set(R.lensPath(["original", "$value"]), transformed, token);
|
|
20
|
+
return tokenWithInlinedRefs;
|
|
21
|
+
});
|
|
22
|
+
}
|
|
5
23
|
const prefersColorScheme = (colorScheme2, content) => `
|
|
6
24
|
@media (prefers-color-scheme: ${colorScheme2}) {
|
|
7
25
|
[data-color-scheme="auto"] ${content}
|
|
@@ -84,12 +102,43 @@ ${selector} ${content}
|
|
|
84
102
|
return header + body;
|
|
85
103
|
}
|
|
86
104
|
};
|
|
87
|
-
const
|
|
105
|
+
const isDigit = (s) => /^\d+$/.test(s);
|
|
106
|
+
const isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
107
|
+
const isUwantedTokens = R.anyPass([isNumericBorderRadiusToken]);
|
|
108
|
+
const overrideSizingFormula = (format, token) => {
|
|
109
|
+
const [name, value] = format(token).split(":");
|
|
110
|
+
const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1);");
|
|
111
|
+
const round = `round(down, ${calc}, 0.0625rem)`;
|
|
112
|
+
return {
|
|
113
|
+
name,
|
|
114
|
+
round,
|
|
115
|
+
calc
|
|
116
|
+
};
|
|
117
|
+
};
|
|
118
|
+
const formatSizingTokens = (format, tokens) => {
|
|
119
|
+
const { round, calc } = R.reduce(
|
|
120
|
+
(acc, token) => {
|
|
121
|
+
const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
|
|
122
|
+
return {
|
|
123
|
+
round: [...acc.round, `${name}: ${round2}`],
|
|
124
|
+
calc: [...acc.calc, `${name}: ${calc2}`]
|
|
125
|
+
};
|
|
126
|
+
},
|
|
127
|
+
{ round: [], calc: [] },
|
|
128
|
+
tokens
|
|
129
|
+
);
|
|
130
|
+
return `
|
|
131
|
+
${calc.join("\n")}
|
|
132
|
+
|
|
133
|
+
@supports (width: round(down, .1em, 1px)) {
|
|
134
|
+
${round.join("\n")}
|
|
135
|
+
}`;
|
|
136
|
+
};
|
|
88
137
|
const semantic = {
|
|
89
138
|
name: "ds/css-semantic",
|
|
90
139
|
format: async ({ dictionary, file, options, platform }) => {
|
|
91
140
|
const { outputReferences, usesDtcg } = options;
|
|
92
|
-
const { selector,
|
|
141
|
+
const { selector, layer } = platform;
|
|
93
142
|
const header = await fileHeader({ file });
|
|
94
143
|
const format = createPropertyFormatter({
|
|
95
144
|
outputReferences,
|
|
@@ -97,16 +146,10 @@ const semantic = {
|
|
|
97
146
|
format: "css",
|
|
98
147
|
usesDtcg
|
|
99
148
|
});
|
|
100
|
-
const
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
return calculatedVariable(format(token));
|
|
105
|
-
}
|
|
106
|
-
return format(token);
|
|
107
|
-
}
|
|
108
|
-
return format(token);
|
|
109
|
-
}, dictionary.allTokens);
|
|
149
|
+
const tokens = inlineTokens(isUwantedTokens, dictionary.allTokens);
|
|
150
|
+
const filteredTokens = R.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
|
|
151
|
+
const [sizingTokens, restTokens] = R.partition(pathStartsWithOneOf(["size"]), filteredTokens);
|
|
152
|
+
const formattedTokens = [R.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
|
|
110
153
|
const content = `{
|
|
111
154
|
${formattedTokens.join("\n")}
|
|
112
155
|
}
|
|
@@ -153,5 +196,7 @@ const formats = {
|
|
|
153
196
|
typography
|
|
154
197
|
};
|
|
155
198
|
export {
|
|
156
|
-
formats
|
|
199
|
+
formats,
|
|
200
|
+
inlineTokens,
|
|
201
|
+
overrideSizingFormula
|
|
157
202
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"js-tokens.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/js-tokens.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;
|
|
1
|
+
{"version":3,"file":"js-tokens.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/js-tokens.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;AAiBvE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAuCtB,CAAC"}
|
|
@@ -1,26 +1,36 @@
|
|
|
1
1
|
import * as R from "ramda";
|
|
2
2
|
import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
|
|
3
|
-
import { getType, isColorCategoryToken } from "../../utils.js";
|
|
3
|
+
import { getType, isColorCategoryToken, pathStartsWithOneOf } from "../../utils.js";
|
|
4
|
+
import { overrideSizingFormula } from "./css.js";
|
|
4
5
|
const groupByType = R.groupBy((token) => getType(token));
|
|
5
|
-
const removeUnwatedTokens = R.filter(
|
|
6
|
-
(token) => !["ds-base-spacing", "ds-base-sizing"].includes(token.name) && !isColorCategoryToken(token)
|
|
7
|
-
);
|
|
6
|
+
const removeUnwatedTokens = R.filter((token) => !isColorCategoryToken(token));
|
|
8
7
|
const dissocExtensions = R.pipe(R.dissoc("$extensions"), R.dissocPath(["original", "$extensions"]));
|
|
9
8
|
const removeUnwatedProps = R.map((token) => dissocExtensions(token));
|
|
10
9
|
const toCssVarName = R.pipe(R.split(":"), R.head, R.trim);
|
|
11
10
|
const jsTokens = {
|
|
12
11
|
name: "ds/js-tokens",
|
|
13
12
|
format: async ({ dictionary, file, options }) => {
|
|
14
|
-
const { usesDtcg } = options;
|
|
13
|
+
const { usesDtcg, outputReferences } = options;
|
|
15
14
|
const format = createPropertyFormatter({
|
|
15
|
+
outputReferences,
|
|
16
16
|
dictionary,
|
|
17
17
|
format: "css",
|
|
18
18
|
usesDtcg
|
|
19
19
|
});
|
|
20
|
-
const formatTokens = R.map((token) =>
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
const formatTokens = R.map((token) => {
|
|
21
|
+
if (pathStartsWithOneOf(["size"], token)) {
|
|
22
|
+
const { calc, name } = overrideSizingFormula(format, token);
|
|
23
|
+
return {
|
|
24
|
+
...token,
|
|
25
|
+
name: name.trim(),
|
|
26
|
+
$value: calc.trim()
|
|
27
|
+
};
|
|
28
|
+
}
|
|
29
|
+
return {
|
|
30
|
+
...token,
|
|
31
|
+
name: toCssVarName(format(token))
|
|
32
|
+
};
|
|
33
|
+
});
|
|
24
34
|
const processTokens = R.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
|
|
25
35
|
const tokens = processTokens(dictionary.allTokens);
|
|
26
36
|
const content = Object.entries(tokens).map(
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD,eAAO,MAAM,OAAO,EAAE,SAyBrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,SASvB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,SAS5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,SAWzB,CAAC"}
|
|
1
|
+
{"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD,eAAO,MAAM,OAAO,EAAE,SAyBrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,SASvB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,SAS5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,SAWzB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,SAMtB,CAAC"}
|
|
@@ -50,15 +50,23 @@ const resolveMath = {
|
|
|
50
50
|
type: "value",
|
|
51
51
|
transitive: true,
|
|
52
52
|
filter: (token) => {
|
|
53
|
-
const isValidValue = ["string", "object"].includes(typeof (token
|
|
53
|
+
const isValidValue = ["string", "object"].includes(typeof getValue(token));
|
|
54
54
|
const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
|
|
55
55
|
return isValidValue && isTokenOfInterest;
|
|
56
56
|
},
|
|
57
57
|
transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
|
|
58
58
|
};
|
|
59
|
+
const unitless = {
|
|
60
|
+
name: "ds/unitless",
|
|
61
|
+
type: "value",
|
|
62
|
+
transitive: true,
|
|
63
|
+
filter: (token) => pathStartsWithOneOf(["size"], token),
|
|
64
|
+
transform: (token) => parseInt(getValue(token))
|
|
65
|
+
};
|
|
59
66
|
export {
|
|
60
67
|
nameKebab,
|
|
61
68
|
resolveMath,
|
|
62
69
|
sizeRem,
|
|
63
|
-
typographyName
|
|
70
|
+
typographyName,
|
|
71
|
+
unitless
|
|
64
72
|
};
|
package/dist/src/tokens/build.js
CHANGED
|
@@ -47,7 +47,7 @@ async function buildTokens(options) {
|
|
|
47
47
|
const targetDir = path.resolve(options.outDir);
|
|
48
48
|
buildOptions = options;
|
|
49
49
|
const $themes = JSON.parse(await fs.readFile(path.resolve(`${tokensDir}/$themes.json`), "utf-8")).map(processThemeObject);
|
|
50
|
-
const relevant$themes = $themes.filter((theme) => R.not(theme.group === "size" && theme.name !== "
|
|
50
|
+
const relevant$themes = $themes.filter((theme) => R.not(theme.group === "size" && theme.name !== "medium"));
|
|
51
51
|
if (!buildOptions.accentColor) {
|
|
52
52
|
const accentOrFirstMainColor = relevant$themes.find((theme) => theme.name === DEFAULT_COLOR) || relevant$themes.find((theme) => theme.group === "main-color");
|
|
53
53
|
buildOptions.accentColor = accentOrFirstMainColor?.name;
|
|
@@ -7,7 +7,7 @@ export declare const colorCliOptions: {
|
|
|
7
7
|
export type CreateTokensOptions = {
|
|
8
8
|
colors: Colors;
|
|
9
9
|
typography: Typography;
|
|
10
|
-
|
|
10
|
+
name: string;
|
|
11
11
|
};
|
|
12
12
|
export declare const createTokens: (opts: CreateTokensOptions) => Tokens;
|
|
13
13
|
//# sourceMappingURL=create.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAyB,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpF,eAAO,MAAM,eAAe;;;;CAIlB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,
|
|
1
|
+
{"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAyB,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpF,eAAO,MAAM,eAAe;;;;CAIlB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,IAAI,EAAE,MAAM,CAAC;CACd,CAAC;AAgFF,eAAO,MAAM,YAAY,SAAU,mBAAmB,WAqBrD,CAAC"}
|
|
@@ -3,15 +3,15 @@
|
|
|
3
3
|
"circle": {
|
|
4
4
|
"small": {
|
|
5
5
|
"$type": "sizing",
|
|
6
|
-
"$value": "{
|
|
6
|
+
"$value": "{size.5} - {switch.border}"
|
|
7
7
|
},
|
|
8
8
|
"medium": {
|
|
9
9
|
"$type": "sizing",
|
|
10
|
-
"$value": "{
|
|
10
|
+
"$value": "{size.6} - {switch.border}"
|
|
11
11
|
},
|
|
12
12
|
"large": {
|
|
13
13
|
"$type": "sizing",
|
|
14
|
-
"$value": "{
|
|
14
|
+
"$value": "{size.7} - {switch.border}"
|
|
15
15
|
}
|
|
16
16
|
},
|
|
17
17
|
"border": {
|
|
@@ -139,17 +139,5 @@
|
|
|
139
139
|
"$type": "opacity",
|
|
140
140
|
"$value": "30%"
|
|
141
141
|
}
|
|
142
|
-
},
|
|
143
|
-
"sizing": {
|
|
144
|
-
"scale": {
|
|
145
|
-
"$type": "sizing",
|
|
146
|
-
"$value": "4"
|
|
147
|
-
}
|
|
148
|
-
},
|
|
149
|
-
"spacing": {
|
|
150
|
-
"scale": {
|
|
151
|
-
"$type": "spacing",
|
|
152
|
-
"$value": "4"
|
|
153
|
-
}
|
|
154
142
|
}
|
|
155
|
-
}
|
|
143
|
+
}
|