@digdir/designsystemet 0.0.0-deps-tsdown-20260421103939
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/LICENSE +7 -0
- package/README.md +115 -0
- package/configs/test-tokens.config.json +82 -0
- package/dist/bin/config.d.ts +12 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +58 -0
- package/dist/bin/designsystemet.d.ts +3 -0
- package/dist/bin/designsystemet.d.ts.map +1 -0
- package/dist/bin/designsystemet.js +156 -0
- package/dist/bin/options.d.ts +21 -0
- package/dist/bin/options.d.ts.map +1 -0
- package/dist/bin/options.js +23 -0
- package/dist/config.schema.json +209 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +9 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +8 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +13 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +53 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +14 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +9 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +32 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +15 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/index.js +11 -0
- package/dist/package.js +5 -0
- package/dist/src/colors/colorMetadata.d.ts +56 -0
- package/dist/src/colors/colorMetadata.d.ts.map +1 -0
- package/dist/src/colors/colorMetadata.js +259 -0
- package/dist/src/colors/index.d.ts +5 -0
- package/dist/src/colors/index.d.ts.map +1 -0
- package/dist/src/colors/index.js +5 -0
- package/dist/src/colors/theme.d.ts +30 -0
- package/dist/src/colors/theme.d.ts.map +1 -0
- package/dist/src/colors/theme.js +111 -0
- package/dist/src/colors/types.d.ts +69 -0
- package/dist/src/colors/types.d.ts.map +1 -0
- package/dist/src/colors/types.js +24 -0
- package/dist/src/colors/utils.d.ts +128 -0
- package/dist/src/colors/utils.d.ts.map +1 -0
- package/dist/src/colors/utils.js +244 -0
- package/dist/src/config.d.ts +181 -0
- package/dist/src/config.d.ts.map +1 -0
- package/dist/src/config.js +118 -0
- package/dist/src/index.d.ts +4 -0
- package/dist/src/index.d.ts.map +1 -0
- package/dist/src/index.js +10 -0
- package/dist/src/migrations/beta-to-v1.d.ts +3 -0
- package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
- package/dist/src/migrations/beta-to-v1.js +340 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts +6 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/plugins.js +35 -0
- package/dist/src/migrations/codemods/css/run.d.ts +8 -0
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/run.js +23 -0
- package/dist/src/migrations/color-rename-next49.d.ts +3 -0
- package/dist/src/migrations/color-rename-next49.d.ts.map +1 -0
- package/dist/src/migrations/color-rename-next49.js +46 -0
- package/dist/src/migrations/index.d.ts +6 -0
- package/dist/src/migrations/index.d.ts.map +1 -0
- package/dist/src/migrations/index.js +9 -0
- package/dist/src/scripts/createJsonSchema.d.ts +2 -0
- package/dist/src/scripts/createJsonSchema.d.ts.map +1 -0
- package/dist/src/scripts/update-preview-tokens.d.ts +3 -0
- package/dist/src/scripts/update-preview-tokens.d.ts.map +1 -0
- package/dist/src/tokens/build.d.ts +4 -0
- package/dist/src/tokens/build.d.ts.map +1 -0
- package/dist/src/tokens/build.js +41 -0
- package/dist/src/tokens/create/files.d.ts +11 -0
- package/dist/src/tokens/create/files.d.ts.map +1 -0
- package/dist/src/tokens/create/files.js +44 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.js +10 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$metadata.js +19 -0
- package/dist/src/tokens/create/generators/$themes.d.ts +27 -0
- package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$themes.js +158 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts +5 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.js +71 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts +3 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/globals.js +142 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts +4 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/size.js +147 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts +4 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/typography.js +216 -0
- package/dist/src/tokens/create/generators/semantic/color-modes.d.ts +8 -0
- package/dist/src/tokens/create/generators/semantic/color-modes.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color-modes.js +26 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts +5 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color.js +46 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts +3 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/style.js +381 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts +3 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/themes/theme.js +112 -0
- package/dist/src/tokens/create.d.ts +21 -0
- package/dist/src/tokens/create.d.ts.map +1 -0
- package/dist/src/tokens/create.js +47 -0
- package/dist/src/tokens/format.d.ts +15 -0
- package/dist/src/tokens/format.d.ts.map +1 -0
- package/dist/src/tokens/format.js +41 -0
- package/dist/src/tokens/generate-config.d.ts +10 -0
- package/dist/src/tokens/generate-config.d.ts.map +1 -0
- package/dist/src/tokens/generate-config.js +178 -0
- package/dist/src/tokens/index.d.ts +4 -0
- package/dist/src/tokens/index.d.ts.map +1 -0
- package/dist/src/tokens/index.js +3 -0
- package/dist/src/tokens/process/configs/color.d.ts +12 -0
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/color.js +51 -0
- package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/semantic.js +47 -0
- package/dist/src/tokens/process/configs/shared.d.ts +10 -0
- package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/shared.js +19 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts +3 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size-mode.js +28 -0
- package/dist/src/tokens/process/configs/size.d.ts +3 -0
- package/dist/src/tokens/process/configs/size.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size.js +34 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts +3 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/type-scale.js +49 -0
- package/dist/src/tokens/process/configs/typography.d.ts +3 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/typography.js +64 -0
- package/dist/src/tokens/process/configs.d.ts +20 -0
- package/dist/src/tokens/process/configs.d.ts.map +1 -0
- package/dist/src/tokens/process/configs.js +90 -0
- package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/color.js +63 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.js +29 -0
- package/dist/src/tokens/process/formats/css/size-mode.d.ts +4 -0
- package/dist/src/tokens/process/formats/css/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size-mode.js +50 -0
- package/dist/src/tokens/process/formats/css/size.d.ts +21 -0
- package/dist/src/tokens/process/formats/css/size.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size.js +93 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/type-scale.js +55 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.js +29 -0
- package/dist/src/tokens/process/formats/css.d.ts +11 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css.js +18 -0
- package/dist/src/tokens/process/output/declarations.d.ts +5 -0
- package/dist/src/tokens/process/output/declarations.d.ts.map +1 -0
- package/dist/src/tokens/process/output/declarations.js +38 -0
- package/dist/src/tokens/process/output/tailwind.d.ts +3 -0
- package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
- package/dist/src/tokens/process/output/tailwind.js +45 -0
- package/dist/src/tokens/process/output/theme.d.ts +27 -0
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
- package/dist/src/tokens/process/output/theme.js +83 -0
- package/dist/src/tokens/process/platform.d.ts +106 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -0
- package/dist/src/tokens/process/platform.js +168 -0
- package/dist/src/tokens/process/transformers.d.ts +6 -0
- package/dist/src/tokens/process/transformers.d.ts.map +1 -0
- package/dist/src/tokens/process/transformers.js +54 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +36 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +114 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts +5 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/kebab-case.js +9 -0
- package/dist/src/tokens/types.d.ts +74 -0
- package/dist/src/tokens/types.d.ts.map +1 -0
- package/dist/src/tokens/types.js +7 -0
- package/dist/src/tokens/utils.d.ts +63 -0
- package/dist/src/tokens/utils.d.ts.map +1 -0
- package/dist/src/tokens/utils.js +121 -0
- package/dist/src/types.d.ts +6 -0
- package/dist/src/types.d.ts.map +1 -0
- package/dist/src/types.js +2 -0
- package/dist/src/utils/filesystem.d.ts +40 -0
- package/dist/src/utils/filesystem.d.ts.map +1 -0
- package/dist/src/utils/filesystem.js +115 -0
- package/package.json +87 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
import { isDigit, pathStartsWithOneOf } from "../../utils.js";
|
|
2
|
+
import { dsTransformers } from "./shared.js";
|
|
3
|
+
import { formats } from "../formats/css.js";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
import { outputReferencesFilter } from "style-dictionary/utils";
|
|
6
|
+
//#region src/tokens/process/configs/size.ts
|
|
7
|
+
const sizeVariables = ({ theme }) => {
|
|
8
|
+
return {
|
|
9
|
+
preprocessors: ["tokens-studio"],
|
|
10
|
+
platforms: { css: {
|
|
11
|
+
theme,
|
|
12
|
+
basePxFontSize: 16,
|
|
13
|
+
selector: `:root, [data-size]`,
|
|
14
|
+
layer: `ds.theme.size`,
|
|
15
|
+
prefix: "ds",
|
|
16
|
+
buildPath: `${theme}/`,
|
|
17
|
+
transforms: dsTransformers,
|
|
18
|
+
files: [{
|
|
19
|
+
destination: `size.css`,
|
|
20
|
+
format: formats.size.name,
|
|
21
|
+
filter: (token) => {
|
|
22
|
+
const isUwantedToken = R.anyPass([R.includes("primitives/global")])(token.filePath);
|
|
23
|
+
const isPrivateToken = R.includes("_", token.path);
|
|
24
|
+
return pathStartsWithOneOf(["size", "_size"], token) && !(isUwantedToken || isPrivateToken);
|
|
25
|
+
}
|
|
26
|
+
}],
|
|
27
|
+
options: { outputReferences: (token, options) => {
|
|
28
|
+
return pathStartsWithOneOf(["size", "_size"], token) && (isDigit(token.path[1]) || token.path[1] === "unit") && outputReferencesFilter(token, options);
|
|
29
|
+
} }
|
|
30
|
+
} }
|
|
31
|
+
};
|
|
32
|
+
};
|
|
33
|
+
//#endregion
|
|
34
|
+
export { sizeVariables };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-scale.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/type-scale.ts"],"names":[],"mappings":"AAGA,OAAO,EAAkB,KAAK,wBAAwB,EAAU,MAAM,aAAa,CAAC;AAEpF,eAAO,MAAM,kBAAkB,EAAE,wBAiDhC,CAAC"}
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
import { pathStartsWithOneOf, typeEquals } from "../../utils.js";
|
|
2
|
+
import { sizeRem, typographyName } from "../transformers.js";
|
|
3
|
+
import "./shared.js";
|
|
4
|
+
import { formats } from "../formats/css.js";
|
|
5
|
+
//#region src/tokens/process/configs/type-scale.ts
|
|
6
|
+
const typeScaleVariables = ({ theme }) => {
|
|
7
|
+
return {
|
|
8
|
+
usesDtcg: true,
|
|
9
|
+
preprocessors: ["tokens-studio"],
|
|
10
|
+
expand: { include: ["typography"] },
|
|
11
|
+
platforms: { css: {
|
|
12
|
+
prefix: "ds",
|
|
13
|
+
selector: ":root, [data-size]",
|
|
14
|
+
layer: `ds.theme.type-scale`,
|
|
15
|
+
buildPath: `${theme}/`,
|
|
16
|
+
basePxFontSize: 16,
|
|
17
|
+
transforms: [
|
|
18
|
+
"name/kebab",
|
|
19
|
+
"ts/size/px",
|
|
20
|
+
sizeRem.name,
|
|
21
|
+
"ts/size/lineheight",
|
|
22
|
+
"ts/typography/fontWeight",
|
|
23
|
+
typographyName.name
|
|
24
|
+
],
|
|
25
|
+
files: [{
|
|
26
|
+
destination: `type-scale.css`,
|
|
27
|
+
format: formats.typeScale.name,
|
|
28
|
+
filter: (token) => {
|
|
29
|
+
const included = typeEquals([
|
|
30
|
+
"typography",
|
|
31
|
+
"dimension",
|
|
32
|
+
"fontsize"
|
|
33
|
+
], token);
|
|
34
|
+
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
35
|
+
return included && !pathStartsWithOneOf([
|
|
36
|
+
"spacing",
|
|
37
|
+
"sizing",
|
|
38
|
+
"size",
|
|
39
|
+
"border-width",
|
|
40
|
+
"border-radius"
|
|
41
|
+
], token) && (pathStartsWithOneOf(["font-size"], token) || token.path.includes("fontSize"));
|
|
42
|
+
}
|
|
43
|
+
}],
|
|
44
|
+
options: { outputReferences: (token) => pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize") }
|
|
45
|
+
} }
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
//#endregion
|
|
49
|
+
export { typeScaleVariables };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typography.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/typography.ts"],"names":[],"mappings":"AAKA,OAAO,EAAkB,KAAK,wBAAwB,EAAU,MAAM,aAAa,CAAC;AAEpF,eAAO,MAAM,mBAAmB,EAAE,wBAiDjC,CAAC"}
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
import { pathStartsWithOneOf, typeEquals } from "../../utils.js";
|
|
2
|
+
import { sizeRem, typographyName } from "../transformers.js";
|
|
3
|
+
import "./shared.js";
|
|
4
|
+
import { formats } from "../formats/css.js";
|
|
5
|
+
import { expandTypesMap } from "@tokens-studio/sd-transforms";
|
|
6
|
+
//#region src/tokens/process/configs/typography.ts
|
|
7
|
+
const typographyVariables = ({ theme, typography }) => {
|
|
8
|
+
const selector = `${typography === "primary" ? ":root, " : ""}[data-typography="${typography}"]`;
|
|
9
|
+
const layer = `ds.theme.typography.${typography}`;
|
|
10
|
+
return {
|
|
11
|
+
usesDtcg: true,
|
|
12
|
+
preprocessors: ["tokens-studio"],
|
|
13
|
+
expand: {
|
|
14
|
+
include: ["typography"],
|
|
15
|
+
typesMap: {
|
|
16
|
+
...expandTypesMap,
|
|
17
|
+
typography: {
|
|
18
|
+
...expandTypesMap.typography,
|
|
19
|
+
letterSpacing: "dimension"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
},
|
|
23
|
+
platforms: { css: {
|
|
24
|
+
prefix: "ds",
|
|
25
|
+
typography,
|
|
26
|
+
selector,
|
|
27
|
+
layer,
|
|
28
|
+
buildPath: `${theme}/`,
|
|
29
|
+
basePxFontSize: 16,
|
|
30
|
+
transforms: [
|
|
31
|
+
"name/kebab",
|
|
32
|
+
"ts/size/px",
|
|
33
|
+
sizeRem.name,
|
|
34
|
+
"ts/size/lineheight",
|
|
35
|
+
"ts/typography/fontWeight",
|
|
36
|
+
"ts/size/css/letterspacing",
|
|
37
|
+
typographyName.name
|
|
38
|
+
],
|
|
39
|
+
files: [{
|
|
40
|
+
destination: `typography/${typography}.css`,
|
|
41
|
+
format: formats.typography.name,
|
|
42
|
+
filter: (token) => {
|
|
43
|
+
const included = typeEquals([
|
|
44
|
+
"fontweight",
|
|
45
|
+
"fontFamily",
|
|
46
|
+
"lineHeight",
|
|
47
|
+
"dimension"
|
|
48
|
+
], token);
|
|
49
|
+
if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
|
|
50
|
+
return included && !pathStartsWithOneOf([
|
|
51
|
+
"spacing",
|
|
52
|
+
"sizing",
|
|
53
|
+
"size",
|
|
54
|
+
"_size",
|
|
55
|
+
"border-width",
|
|
56
|
+
"border-radius"
|
|
57
|
+
], token) && !(pathStartsWithOneOf(["typography"], token) && token.path.includes("fontSize"));
|
|
58
|
+
}
|
|
59
|
+
}]
|
|
60
|
+
} }
|
|
61
|
+
};
|
|
62
|
+
};
|
|
63
|
+
//#endregion
|
|
64
|
+
export { typographyVariables };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import type { GetSDConfigOptions, SDConfigForThemePermutation, ThemeDimension } from '../types.js';
|
|
2
|
+
import type { GetStyleDictionaryConfig } from './configs/shared.js';
|
|
3
|
+
import { type ProcessedThemeObject } from './utils/getMultidimensionalThemes.js';
|
|
4
|
+
export declare const configs: {
|
|
5
|
+
colorSchemeVariables: GetStyleDictionaryConfig;
|
|
6
|
+
mainColorVariables: GetStyleDictionaryConfig;
|
|
7
|
+
supportColorVariables: GetStyleDictionaryConfig;
|
|
8
|
+
neutralColorVariables: GetStyleDictionaryConfig;
|
|
9
|
+
successColorVariables: GetStyleDictionaryConfig;
|
|
10
|
+
dangerColorVariables: GetStyleDictionaryConfig;
|
|
11
|
+
warningColorVariables: GetStyleDictionaryConfig;
|
|
12
|
+
infoColorVariables: GetStyleDictionaryConfig;
|
|
13
|
+
sizeModeVariables: GetStyleDictionaryConfig;
|
|
14
|
+
sizeVariables: GetStyleDictionaryConfig;
|
|
15
|
+
typographyVariables: GetStyleDictionaryConfig;
|
|
16
|
+
typeScaleVariables: GetStyleDictionaryConfig;
|
|
17
|
+
semanticVariables: GetStyleDictionaryConfig;
|
|
18
|
+
};
|
|
19
|
+
export declare const getConfigsForThemeDimensions: (getConfig: GetStyleDictionaryConfig, processed$themes: ProcessedThemeObject[], dimensions: ThemeDimension[], options: GetSDConfigOptions) => SDConfigForThemePermutation[];
|
|
20
|
+
//# sourceMappingURL=configs.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/process/configs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAInG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAQpE,OAAO,EAA6B,KAAK,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAa5G,eAAO,MAAM,OAAO;;;;;;;;;;;;;;CAcnB,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,WAAW,wBAAwB,EACnC,kBAAkB,oBAAoB,EAAE,EACxC,YAAY,cAAc,EAAE,EAC5B,SAAS,kBAAkB,KAC1B,2BAA2B,EAoD7B,CAAC"}
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import { traverseObj } from "../utils.js";
|
|
2
|
+
import { resolveMath, sizeRem, typographyName, unitless } from "./transformers.js";
|
|
3
|
+
import { formats } from "./formats/css.js";
|
|
4
|
+
import { colorCategoryVariables, colorSchemeVariables } from "./configs/color.js";
|
|
5
|
+
import { semanticVariables } from "./configs/semantic.js";
|
|
6
|
+
import { sizeVariables } from "./configs/size.js";
|
|
7
|
+
import { sizeModeVariables } from "./configs/size-mode.js";
|
|
8
|
+
import { typeScaleVariables } from "./configs/type-scale.js";
|
|
9
|
+
import { typographyVariables } from "./configs/typography.js";
|
|
10
|
+
import { getMultidimensionalThemes } from "./utils/getMultidimensionalThemes.js";
|
|
11
|
+
import { buildOptions } from "./platform.js";
|
|
12
|
+
import * as R from "ramda";
|
|
13
|
+
import StyleDictionary from "style-dictionary";
|
|
14
|
+
import { register } from "@tokens-studio/sd-transforms";
|
|
15
|
+
//#region src/tokens/process/configs.ts
|
|
16
|
+
register(StyleDictionary, { withSDBuiltins: false });
|
|
17
|
+
StyleDictionary.registerTransform(sizeRem);
|
|
18
|
+
StyleDictionary.registerTransform(typographyName);
|
|
19
|
+
StyleDictionary.registerTransform(resolveMath);
|
|
20
|
+
StyleDictionary.registerTransform(unitless);
|
|
21
|
+
for (const format of Object.values(formats)) StyleDictionary.registerFormat(format);
|
|
22
|
+
const configs = {
|
|
23
|
+
colorSchemeVariables,
|
|
24
|
+
mainColorVariables: colorCategoryVariables({ category: "main" }),
|
|
25
|
+
supportColorVariables: colorCategoryVariables({ category: "support" }),
|
|
26
|
+
neutralColorVariables: colorCategoryVariables({
|
|
27
|
+
category: "builtin",
|
|
28
|
+
color: "neutral"
|
|
29
|
+
}),
|
|
30
|
+
successColorVariables: colorCategoryVariables({
|
|
31
|
+
category: "builtin",
|
|
32
|
+
color: "success"
|
|
33
|
+
}),
|
|
34
|
+
dangerColorVariables: colorCategoryVariables({
|
|
35
|
+
category: "builtin",
|
|
36
|
+
color: "danger"
|
|
37
|
+
}),
|
|
38
|
+
warningColorVariables: colorCategoryVariables({
|
|
39
|
+
category: "builtin",
|
|
40
|
+
color: "warning"
|
|
41
|
+
}),
|
|
42
|
+
infoColorVariables: colorCategoryVariables({
|
|
43
|
+
category: "builtin",
|
|
44
|
+
color: "info"
|
|
45
|
+
}),
|
|
46
|
+
sizeModeVariables,
|
|
47
|
+
sizeVariables,
|
|
48
|
+
typographyVariables,
|
|
49
|
+
typeScaleVariables,
|
|
50
|
+
semanticVariables
|
|
51
|
+
};
|
|
52
|
+
const getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, options) => {
|
|
53
|
+
const { tokensDir, tokenSets } = options;
|
|
54
|
+
return getMultidimensionalThemes(processed$themes, dimensions).flatMap(({ selectedTokenSets, permutation }) => {
|
|
55
|
+
const tokenSource = {
|
|
56
|
+
source: void 0,
|
|
57
|
+
tokens: {}
|
|
58
|
+
};
|
|
59
|
+
if (tokenSets) for (const tokenSet of selectedTokenSets) {
|
|
60
|
+
const tokens = tokenSets.get(tokenSet);
|
|
61
|
+
if (tokens) {
|
|
62
|
+
const tokensWithFilePath = traverseObj(tokens, (obj) => {
|
|
63
|
+
if (Object.hasOwn(obj, `$value`) && !obj.filePath) obj.filePath = tokenSet;
|
|
64
|
+
});
|
|
65
|
+
tokenSource.tokens = R.mergeDeepRight(tokenSource.tokens, tokensWithFilePath);
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
else tokenSource.source = selectedTokenSets.map((x) => `${tokensDir}/${x}.json`);
|
|
69
|
+
const configOrConfigs = getConfig(permutation);
|
|
70
|
+
return (Array.isArray(configOrConfigs) ? configOrConfigs : [{ config: configOrConfigs }]).map(({ config, permutationOverrides }) => {
|
|
71
|
+
return {
|
|
72
|
+
permutation: {
|
|
73
|
+
...permutation,
|
|
74
|
+
...permutationOverrides
|
|
75
|
+
},
|
|
76
|
+
config: {
|
|
77
|
+
...config,
|
|
78
|
+
usesDtcg: true,
|
|
79
|
+
log: {
|
|
80
|
+
...config?.log,
|
|
81
|
+
verbosity: buildOptions?.verbose ? "verbose" : "silent"
|
|
82
|
+
},
|
|
83
|
+
...tokenSource
|
|
84
|
+
}
|
|
85
|
+
};
|
|
86
|
+
});
|
|
87
|
+
}).sort();
|
|
88
|
+
};
|
|
89
|
+
//#endregion
|
|
90
|
+
export { configs, getConfigsForThemeDimensions };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/color.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAarD,eAAO,MAAM,WAAW,EAAE,MAgDzB,CAAC;AAEF,eAAO,MAAM,aAAa,EAAE,MAwC3B,CAAC"}
|
|
@@ -0,0 +1,63 @@
|
|
|
1
|
+
import { colorCategories } from "../../../types.js";
|
|
2
|
+
import { isColorCategoryToken, isGlobalColorToken, isSemanticToken } from "../../../utils.js";
|
|
3
|
+
import { buildOptions } from "../../platform.js";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
6
|
+
//#region src/tokens/process/formats/css/color.ts
|
|
7
|
+
const prefersColorScheme = (colorScheme, content) => `
|
|
8
|
+
@media (prefers-color-scheme: ${colorScheme}) {
|
|
9
|
+
[data-color-scheme="auto"] ${content}
|
|
10
|
+
}
|
|
11
|
+
`;
|
|
12
|
+
const colorScheme = {
|
|
13
|
+
name: "ds/css-colorscheme",
|
|
14
|
+
format: async ({ dictionary, options, platform }) => {
|
|
15
|
+
const { allTokens } = dictionary;
|
|
16
|
+
const { outputReferences, usesDtcg } = options;
|
|
17
|
+
const { selector, colorScheme, layer } = platform;
|
|
18
|
+
const colorScheme_ = colorScheme;
|
|
19
|
+
const format = createPropertyFormatter({
|
|
20
|
+
outputReferences,
|
|
21
|
+
dictionary,
|
|
22
|
+
format: "css",
|
|
23
|
+
usesDtcg
|
|
24
|
+
});
|
|
25
|
+
const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `\n color-scheme: ${colorScheme_};\n` : "";
|
|
26
|
+
const content = `{\n${allTokens.filter(R.allPass([R.anyPass([isSemanticToken, isGlobalColorToken]), (t) => !isColorCategoryToken(t)])).map((token) => ({
|
|
27
|
+
token,
|
|
28
|
+
formatted: format(token)
|
|
29
|
+
})).map(R.view(R.lensProp("formatted"))).join("\n")}\n${colorSchemeProperty}}\n`;
|
|
30
|
+
const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
|
|
31
|
+
return R.isNotNil(layer) ? `@layer ${layer} {\n${selector} ${content} ${autoSelectorContent}\n}\n` : `${selector} ${content} ${autoSelectorContent}\n`;
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
const colorCategory = {
|
|
35
|
+
name: "ds/css-colorcategory",
|
|
36
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
37
|
+
const { outputReferences, usesDtcg } = options;
|
|
38
|
+
const { selector, layer } = platform;
|
|
39
|
+
const destination = file.destination;
|
|
40
|
+
const format = R.compose(createPropertyFormatter({
|
|
41
|
+
outputReferences,
|
|
42
|
+
dictionary,
|
|
43
|
+
format: "css",
|
|
44
|
+
usesDtcg
|
|
45
|
+
}), (token) => ({
|
|
46
|
+
...token,
|
|
47
|
+
name: token.name.replace(/color-\w+-/, "color-"),
|
|
48
|
+
original: {
|
|
49
|
+
...token.original,
|
|
50
|
+
$value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
|
|
51
|
+
}
|
|
52
|
+
}));
|
|
53
|
+
const formattedMap = dictionary.allTokens.map((token) => ({
|
|
54
|
+
token,
|
|
55
|
+
formatted: format(token)
|
|
56
|
+
}));
|
|
57
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
58
|
+
const content = `{\n${formattedMap.map(R.view(R.lensProp("formatted"))).join("\n")}\n}\n`;
|
|
59
|
+
return R.isNotNil(layer) ? `@layer ${layer} {\n${selector} ${content}\n}\n` : `${selector} ${content}\n`;
|
|
60
|
+
}
|
|
61
|
+
};
|
|
62
|
+
//#endregion
|
|
63
|
+
export { colorCategory, colorScheme };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"semantic.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/semantic.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAMrD,eAAO,MAAM,QAAQ,EAAE,MA8BtB,CAAC"}
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import { inlineTokens } from "../../../utils.js";
|
|
2
|
+
import { isInlineTokens } from "./size.js";
|
|
3
|
+
import { buildOptions } from "../../platform.js";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
6
|
+
//#region src/tokens/process/formats/css/semantic.ts
|
|
7
|
+
const semantic = {
|
|
8
|
+
name: "ds/css-semantic",
|
|
9
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
10
|
+
const { outputReferences, usesDtcg } = options;
|
|
11
|
+
const { selector, layer } = platform;
|
|
12
|
+
const destination = file.destination;
|
|
13
|
+
const format = createPropertyFormatter({
|
|
14
|
+
outputReferences,
|
|
15
|
+
dictionary,
|
|
16
|
+
format: "css",
|
|
17
|
+
usesDtcg
|
|
18
|
+
});
|
|
19
|
+
const formattedMap = inlineTokens(isInlineTokens, dictionary.allTokens).map((token) => ({
|
|
20
|
+
token,
|
|
21
|
+
formatted: format(token)
|
|
22
|
+
}));
|
|
23
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
24
|
+
const content = `${selector} {\n${formattedMap.map(R.prop("formatted")).join("\n")}\n}\n`;
|
|
25
|
+
return R.isNotNil(layer) ? `@layer ${layer} {\n${content}\n}\n` : `${content}\n`;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { semantic };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size-mode.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/size-mode.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAerD,eAAO,MAAM,QAAQ,EAAE,MAsDtB,CAAC;AAEF,wBAAgB,WAAW,CAAC,OAAO,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,UAE1D"}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { orderBySize, shortSizeName } from "../../../utils.js";
|
|
2
|
+
import "../../configs/shared.js";
|
|
3
|
+
import { buildOptions } from "../../platform.js";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
6
|
+
//#region src/tokens/process/formats/css/size-mode.ts
|
|
7
|
+
const formatBaseSizeToken = (size) => (token) => ({
|
|
8
|
+
...token,
|
|
9
|
+
originalName: token.name,
|
|
10
|
+
name: `${token.name}--${shortSizeName(size)}`,
|
|
11
|
+
$value: token.$value / 16
|
|
12
|
+
});
|
|
13
|
+
const sizeMode = {
|
|
14
|
+
name: "ds/css-size-mode",
|
|
15
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
16
|
+
const { outputReferences, usesDtcg } = options;
|
|
17
|
+
const { selector, layer, size } = platform;
|
|
18
|
+
const destination = file.destination;
|
|
19
|
+
const format = createPropertyFormatter({
|
|
20
|
+
outputReferences,
|
|
21
|
+
dictionary,
|
|
22
|
+
format: "css",
|
|
23
|
+
usesDtcg
|
|
24
|
+
});
|
|
25
|
+
const sizeSpecificTokens = dictionary.allTokens.map(formatBaseSizeToken(size));
|
|
26
|
+
const sizeSpecificVariables = sizeSpecificTokens.map(format).join("\n");
|
|
27
|
+
const formattedMap = sizeSpecificTokens.map((token) => ({
|
|
28
|
+
token,
|
|
29
|
+
formatted: format({
|
|
30
|
+
...token,
|
|
31
|
+
name: token.originalName
|
|
32
|
+
})
|
|
33
|
+
}));
|
|
34
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
35
|
+
const body = wrapInLayer(`${selector} /* ${size} */ {\n${sizeSpecificVariables}\n}`, layer);
|
|
36
|
+
const sizes = orderBySize(buildOptions?.sizeModes ?? []).map(shortSizeName);
|
|
37
|
+
const sharedContent = `${`:root, [data-size] {
|
|
38
|
+
--ds-size: var(--ds-size--${shortSizeName(buildOptions?.defaultSize ?? "")});
|
|
39
|
+
${sizes.map((size) => ` --ds-size--${size}: var(--ds-size,);`).join("\n")}
|
|
40
|
+
--ds-size-mode-font-size:
|
|
41
|
+
${sizes.map((size) => ` var(--ds-size--${size}, var(--ds-size-mode-font-size--${size}))`).join("\n")};
|
|
42
|
+
}`}\n\n${sizes.map((size) => `[data-size='${size}'] { --ds-size: var(--ds-size--${size}); }`).join("\n")}`;
|
|
43
|
+
return body + (shortSizeName(size) === R.last(sizes) ? `\n${wrapInLayer(sharedContent, layer)}` : "");
|
|
44
|
+
}
|
|
45
|
+
};
|
|
46
|
+
function wrapInLayer(content, layer) {
|
|
47
|
+
return R.isNotNil(layer) ? `@layer ${layer} {\n${content}\n}\n` : `${content}\n`;
|
|
48
|
+
}
|
|
49
|
+
//#endregion
|
|
50
|
+
export { sizeMode, wrapInLayer };
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { TransformedToken } from 'style-dictionary';
|
|
2
|
+
import type { Format } from 'style-dictionary/types';
|
|
3
|
+
export declare const isInlineTokens: (t: TransformedToken) => boolean;
|
|
4
|
+
/**
|
|
5
|
+
* Overrides the default sizing formula with a custom one that supports [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.
|
|
6
|
+
*
|
|
7
|
+
* @param format - Function to format a token into a CSS property string.
|
|
8
|
+
* @param tokens - Array of transformed tokens to format.
|
|
9
|
+
* @returns Object with formatted CSS strings for calc and round.
|
|
10
|
+
*/
|
|
11
|
+
export declare const overrideSizingFormula: (format: (t: TransformedToken) => string, token: TransformedToken) => {
|
|
12
|
+
name: string;
|
|
13
|
+
round: string;
|
|
14
|
+
calc: string;
|
|
15
|
+
};
|
|
16
|
+
export declare const sizingTemplate: ({ round, calc }: {
|
|
17
|
+
round: string[];
|
|
18
|
+
calc: string[];
|
|
19
|
+
}) => string;
|
|
20
|
+
export declare const size: Format;
|
|
21
|
+
//# sourceMappingURL=size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/size.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AASrD,eAAO,MAAM,cAAc,MAJY,gBAAgB,YAI+C,CAAC;AAEvG;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,GAAI,QAAQ,CAAC,CAAC,EAAE,gBAAgB,KAAK,MAAM,EAAE,OAAO,gBAAgB;;;;CAmBrG,CAAC;AAwBF,eAAO,MAAM,cAAc,GAAI,iBAAiB;IAAE,KAAK,EAAE,MAAM,EAAE,CAAC;IAAC,IAAI,EAAE,MAAM,EAAE,CAAA;CAAE,WAOlF,CAAC;AAEF,eAAO,MAAM,IAAI,EAAE,MAyClB,CAAC"}
|
|
@@ -0,0 +1,93 @@
|
|
|
1
|
+
import { inlineTokens, isDigit, pathStartsWithOneOf } from "../../../utils.js";
|
|
2
|
+
import { buildOptions } from "../../platform.js";
|
|
3
|
+
import * as R from "ramda";
|
|
4
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
5
|
+
//#region src/tokens/process/formats/css/size.ts
|
|
6
|
+
const isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
|
|
7
|
+
const isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
|
|
8
|
+
const isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
|
|
9
|
+
const isInlineTokens = R.anyPass([
|
|
10
|
+
isNumericBorderRadiusToken,
|
|
11
|
+
isNumericSizeToken,
|
|
12
|
+
isSizeToken
|
|
13
|
+
]);
|
|
14
|
+
/**
|
|
15
|
+
* Overrides the default sizing formula with a custom one that supports [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.
|
|
16
|
+
*
|
|
17
|
+
* @param format - Function to format a token into a CSS property string.
|
|
18
|
+
* @param tokens - Array of transformed tokens to format.
|
|
19
|
+
* @returns Object with formatted CSS strings for calc and round.
|
|
20
|
+
*/
|
|
21
|
+
const overrideSizingFormula = (format, token) => {
|
|
22
|
+
const [name, value] = format(token).replace(/;$/, "").split(": ");
|
|
23
|
+
let calc;
|
|
24
|
+
let round;
|
|
25
|
+
if (token.path[1] === "unit") calc = `calc(1rem * ${value})`;
|
|
26
|
+
else if (value.startsWith("floor")) {
|
|
27
|
+
calc = value.replace(/^floor\((.*)\)$/, "calc($1)");
|
|
28
|
+
round = `round(down, ${calc}, 1px)`;
|
|
29
|
+
} else calc = value.includes("*") ? `calc(${value})` : value;
|
|
30
|
+
return {
|
|
31
|
+
name,
|
|
32
|
+
round: round ?? calc,
|
|
33
|
+
calc
|
|
34
|
+
};
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Formats sizing tokens into CSS properties with support for rounding.
|
|
38
|
+
*
|
|
39
|
+
* @param format - Function to format a token into a CSS property string.
|
|
40
|
+
* @param tokens - Array of transformed tokens to format.
|
|
41
|
+
* @returns Formatted CSS string with default calc and [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.
|
|
42
|
+
*/
|
|
43
|
+
const formatSizingTokens = (format, tokens) => R.reduce((acc, token) => {
|
|
44
|
+
const { round, calc, name } = overrideSizingFormula(format, token);
|
|
45
|
+
return {
|
|
46
|
+
tokens: [...acc.tokens, token],
|
|
47
|
+
round: [...acc.round, `${name}: ${round};`],
|
|
48
|
+
calc: [...acc.calc, `${name}: ${calc};`]
|
|
49
|
+
};
|
|
50
|
+
}, {
|
|
51
|
+
tokens: [],
|
|
52
|
+
round: [],
|
|
53
|
+
calc: []
|
|
54
|
+
}, tokens);
|
|
55
|
+
const sizingTemplate = ({ round, calc }) => {
|
|
56
|
+
const usesRounding = round.filter((val, i) => val !== calc[i]);
|
|
57
|
+
return `
|
|
58
|
+
${calc.join("\n")}\n
|
|
59
|
+
@supports (width: round(down, .1em, 1px)) {
|
|
60
|
+
${usesRounding.join("\n ")}
|
|
61
|
+
}`;
|
|
62
|
+
};
|
|
63
|
+
const size = {
|
|
64
|
+
name: "ds/css-size",
|
|
65
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
66
|
+
const { outputReferences, usesDtcg } = options;
|
|
67
|
+
const { selector, layer } = platform;
|
|
68
|
+
const destination = file.destination;
|
|
69
|
+
const format = createPropertyFormatter({
|
|
70
|
+
outputReferences,
|
|
71
|
+
dictionary,
|
|
72
|
+
format: "css",
|
|
73
|
+
usesDtcg
|
|
74
|
+
});
|
|
75
|
+
const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
|
|
76
|
+
const filteredTokens = R.reject((token) => R.equals(["_size", "mode-font-size"], token.path), tokens);
|
|
77
|
+
const [sizingTokens, restTokens] = R.partition((t) => pathStartsWithOneOf(["_size"], t) && (isDigit(t.path[1]) || t.path[1] === "unit"), filteredTokens);
|
|
78
|
+
const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
|
|
79
|
+
const formattedMap = restTokens.map((token) => ({
|
|
80
|
+
token,
|
|
81
|
+
formatted: format(token)
|
|
82
|
+
}));
|
|
83
|
+
const formattedSizingMap = formattedSizingTokens.round.map((t, i) => ({
|
|
84
|
+
token: formattedSizingTokens.tokens[i],
|
|
85
|
+
formatted: t
|
|
86
|
+
}));
|
|
87
|
+
buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
|
|
88
|
+
const content = `${selector} {\n${[formattedMap.map(R.prop("formatted")).join("\n"), sizingTemplate(formattedSizingTokens)].join("\n")}\n}\n`;
|
|
89
|
+
return R.isNotNil(layer) ? `@layer ${layer} {\n${content}\n}\n` : `${content}\n`;
|
|
90
|
+
}
|
|
91
|
+
};
|
|
92
|
+
//#endregion
|
|
93
|
+
export { isInlineTokens, overrideSizingFormula, size, sizingTemplate };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-scale.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/type-scale.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;AA2CvE,eAAO,MAAM,SAAS,EAAE,MA8BvB,CAAC"}
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import { sizingTemplate } from "./size.js";
|
|
2
|
+
import "../../configs/shared.js";
|
|
3
|
+
import { buildOptions } from "../../platform.js";
|
|
4
|
+
import * as R from "ramda";
|
|
5
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
6
|
+
//#region src/tokens/process/formats/css/type-scale.ts
|
|
7
|
+
const isTypographyFontFamilyToken = R.allPass([R.pathSatisfies(R.includes("typography"), ["path"]), R.pathSatisfies(R.includes("fontFamily"), ["path"])]);
|
|
8
|
+
const formatTypographySizeToken = (format, token) => {
|
|
9
|
+
const [name, value] = format(token).replace(/;$/, "").split(": ");
|
|
10
|
+
let calc;
|
|
11
|
+
let round;
|
|
12
|
+
if (R.startsWith(["font-size"], token.path)) {
|
|
13
|
+
calc = `calc(${value} * var(--_ds-font-size-factor))`;
|
|
14
|
+
round = `round(${calc}, 1px)`;
|
|
15
|
+
} else calc = value;
|
|
16
|
+
return {
|
|
17
|
+
name,
|
|
18
|
+
calc,
|
|
19
|
+
round: round ?? calc
|
|
20
|
+
};
|
|
21
|
+
};
|
|
22
|
+
const formatTypographySizeTokens = (format, tokens) => R.reduce((acc, token) => {
|
|
23
|
+
const { name, calc, round } = formatTypographySizeToken(format, token);
|
|
24
|
+
acc.tokens.push(token);
|
|
25
|
+
acc.calc.push(`${name}: ${calc};`);
|
|
26
|
+
acc.round.push(`${name}: ${round};`);
|
|
27
|
+
return acc;
|
|
28
|
+
}, {
|
|
29
|
+
tokens: [],
|
|
30
|
+
calc: [],
|
|
31
|
+
round: []
|
|
32
|
+
}, tokens);
|
|
33
|
+
const typeScale = {
|
|
34
|
+
name: "ds/css-type-scale",
|
|
35
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
36
|
+
const { outputReferences, usesDtcg } = options;
|
|
37
|
+
const { selector, layer } = platform;
|
|
38
|
+
const destination = file.destination;
|
|
39
|
+
const formattedTokens = formatTypographySizeTokens(createPropertyFormatter({
|
|
40
|
+
outputReferences,
|
|
41
|
+
dictionary,
|
|
42
|
+
format: "css",
|
|
43
|
+
usesDtcg
|
|
44
|
+
}), R.reject(R.anyPass([isTypographyFontFamilyToken]), dictionary.allTokens));
|
|
45
|
+
const formattedMap = formattedTokens.round.map((t, i) => ({
|
|
46
|
+
token: formattedTokens.tokens[i],
|
|
47
|
+
formatted: t
|
|
48
|
+
}));
|
|
49
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
50
|
+
const content = `${selector} {\n --_ds-font-size-factor: calc(var(--ds-size-mode-font-size) / (var(--ds-size-base) / 16));${sizingTemplate(formattedTokens)}\n}`;
|
|
51
|
+
return R.isNotNil(layer) ? `@layer ${layer} {\n${content}\n}` : content;
|
|
52
|
+
}
|
|
53
|
+
};
|
|
54
|
+
//#endregion
|
|
55
|
+
export { typeScale };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typography.d.ts","sourceRoot":"","sources":["../../../../../../src/tokens/process/formats/css/typography.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;AAUvE,eAAO,MAAM,UAAU,EAAE,MA8BxB,CAAC"}
|