@digdir/designsystemet 0.0.0-chore-remove-cli-tsx-20260701060359
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 +104 -0
- package/dist/bin/config.d.ts +14 -0
- package/dist/bin/config.d.ts.map +1 -0
- package/dist/bin/config.js +58 -0
- package/dist/bin/config.js.map +1 -0
- package/dist/bin/designsystemet.d.ts +1 -0
- package/dist/bin/designsystemet.js +174 -0
- package/dist/bin/designsystemet.js.map +1 -0
- package/dist/bin/options.d.ts +24 -0
- package/dist/bin/options.d.ts.map +1 -0
- package/dist/bin/options.js +25 -0
- package/dist/bin/options.js.map +1 -0
- package/dist/config.schema.json +181 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +11 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +10 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +15 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +12 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +12 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +55 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +16 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.d.ts +11 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.d.ts.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +11 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +34 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +17 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js.map +1 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/ThemeObject.d.ts +16 -0
- package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/ThemeObject.d.ts.map +1 -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 +7 -0
- package/dist/package.js.map +1 -0
- package/dist/src/automigrate.d.ts +5 -0
- package/dist/src/automigrate.d.ts.map +1 -0
- package/dist/src/automigrate.js +35 -0
- package/dist/src/automigrate.js.map +1 -0
- package/dist/src/colors/colorMetadata.d.ts +60 -0
- package/dist/src/colors/colorMetadata.d.ts.map +1 -0
- package/dist/src/colors/colorMetadata.js +261 -0
- package/dist/src/colors/colorMetadata.js.map +1 -0
- package/dist/src/colors/index.d.ts +5 -0
- package/dist/src/colors/index.js +5 -0
- package/dist/src/colors/theme.d.ts +34 -0
- package/dist/src/colors/theme.d.ts.map +1 -0
- package/dist/src/colors/theme.js +113 -0
- package/dist/src/colors/theme.js.map +1 -0
- package/dist/src/colors/types.d.ts +67 -0
- package/dist/src/colors/types.d.ts.map +1 -0
- package/dist/src/colors/types.js +26 -0
- package/dist/src/colors/types.js.map +1 -0
- package/dist/src/colors/utils.d.ts +132 -0
- package/dist/src/colors/utils.d.ts.map +1 -0
- package/dist/src/colors/utils.js +246 -0
- package/dist/src/colors/utils.js.map +1 -0
- package/dist/src/index.d.ts +10 -0
- package/dist/src/index.js +11 -0
- package/dist/src/migrations/beta-to-v1.d.ts +5 -0
- package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
- package/dist/src/migrations/beta-to-v1.js +342 -0
- package/dist/src/migrations/beta-to-v1.js.map +1 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts +9 -0
- package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/plugins.js +37 -0
- package/dist/src/migrations/codemods/css/plugins.js.map +1 -0
- package/dist/src/migrations/codemods/css/run.d.ts +14 -0
- package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
- package/dist/src/migrations/codemods/css/run.js +25 -0
- package/dist/src/migrations/codemods/css/run.js.map +1 -0
- package/dist/src/migrations/color-rename-next49.d.ts +5 -0
- package/dist/src/migrations/color-rename-next49.d.ts.map +1 -0
- package/dist/src/migrations/color-rename-next49.js +48 -0
- package/dist/src/migrations/color-rename-next49.js.map +1 -0
- package/dist/src/migrations/flatten-color-categories.d.ts +12 -0
- package/dist/src/migrations/flatten-color-categories.d.ts.map +1 -0
- package/dist/src/migrations/flatten-color-categories.js +58 -0
- package/dist/src/migrations/flatten-color-categories.js.map +1 -0
- package/dist/src/migrations/index.d.ts +17 -0
- package/dist/src/migrations/index.d.ts.map +1 -0
- package/dist/src/migrations/index.js +13 -0
- package/dist/src/migrations/index.js.map +1 -0
- package/dist/src/schemas/helpers.d.ts +42 -0
- package/dist/src/schemas/helpers.d.ts.map +1 -0
- package/dist/src/schemas/helpers.js +96 -0
- package/dist/src/schemas/helpers.js.map +1 -0
- package/dist/src/schemas/v1/schema.d.ts +173 -0
- package/dist/src/schemas/v1/schema.d.ts.map +1 -0
- package/dist/src/schemas/v1/schema.js +65 -0
- package/dist/src/schemas/v1/schema.js.map +1 -0
- package/dist/src/schemas/v1.1/schema.d.ts +165 -0
- package/dist/src/schemas/v1.1/schema.d.ts.map +1 -0
- package/dist/src/schemas/v1.1/schema.js +56 -0
- package/dist/src/schemas/v1.1/schema.js.map +1 -0
- package/dist/src/tokens/build.d.ts +8 -0
- package/dist/src/tokens/build.d.ts.map +1 -0
- package/dist/src/tokens/build.js +43 -0
- package/dist/src/tokens/build.js.map +1 -0
- package/dist/src/tokens/create/files.d.ts +19 -0
- package/dist/src/tokens/create/files.d.ts.map +1 -0
- package/dist/src/tokens/create/files.js +48 -0
- package/dist/src/tokens/create/files.js.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts +8 -0
- package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$designsystemet.js +12 -0
- package/dist/src/tokens/create/generators/$designsystemet.js.map +1 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts +15 -0
- package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/$metadata.js +25 -0
- package/dist/src/tokens/create/generators/$metadata.js.map +1 -0
- package/dist/src/tokens/create/generators/$themes.d.ts +28 -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/$themes.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts +9 -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/color-scheme.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts +7 -0
- package/dist/src/tokens/create/generators/primitives/globals.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/globals.js +144 -0
- package/dist/src/tokens/create/generators/primitives/globals.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts +8 -0
- package/dist/src/tokens/create/generators/primitives/size.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/size.js +149 -0
- package/dist/src/tokens/create/generators/primitives/size.js.map +1 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts +10 -0
- package/dist/src/tokens/create/generators/primitives/typography.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/primitives/typography.js +218 -0
- package/dist/src/tokens/create/generators/primitives/typography.js.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts +7 -0
- package/dist/src/tokens/create/generators/semantic/color.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/color.js +19 -0
- package/dist/src/tokens/create/generators/semantic/color.js.map +1 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts +7 -0
- package/dist/src/tokens/create/generators/semantic/style.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/semantic/style.js +420 -0
- package/dist/src/tokens/create/generators/semantic/style.js.map +1 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts +7 -0
- package/dist/src/tokens/create/generators/themes/theme.d.ts.map +1 -0
- package/dist/src/tokens/create/generators/themes/theme.js +105 -0
- package/dist/src/tokens/create/generators/themes/theme.js.map +1 -0
- package/dist/src/tokens/create.d.ts +10 -0
- package/dist/src/tokens/create.d.ts.map +1 -0
- package/dist/src/tokens/create.js +40 -0
- package/dist/src/tokens/create.js.map +1 -0
- package/dist/src/tokens/format.d.ts +19 -0
- package/dist/src/tokens/format.d.ts.map +1 -0
- package/dist/src/tokens/format.js +42 -0
- package/dist/src/tokens/format.js.map +1 -0
- package/dist/src/tokens/generate-config.d.ts +14 -0
- package/dist/src/tokens/generate-config.d.ts.map +1 -0
- package/dist/src/tokens/generate-config.js +154 -0
- package/dist/src/tokens/generate-config.js.map +1 -0
- package/dist/src/tokens/index.d.ts +5 -0
- package/dist/src/tokens/index.js +4 -0
- package/dist/src/tokens/process/configs/color.d.ts +8 -0
- package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/color.js +50 -0
- package/dist/src/tokens/process/configs/color.js.map +1 -0
- package/dist/src/tokens/process/configs/semantic.d.ts +7 -0
- package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/semantic.js +49 -0
- package/dist/src/tokens/process/configs/semantic.js.map +1 -0
- package/dist/src/tokens/process/configs/shared.d.ts +14 -0
- package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/shared.js +21 -0
- package/dist/src/tokens/process/configs/shared.js.map +1 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts +7 -0
- package/dist/src/tokens/process/configs/size-mode.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size-mode.js +30 -0
- package/dist/src/tokens/process/configs/size-mode.js.map +1 -0
- package/dist/src/tokens/process/configs/size.d.ts +7 -0
- package/dist/src/tokens/process/configs/size.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/size.js +36 -0
- package/dist/src/tokens/process/configs/size.js.map +1 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts +7 -0
- package/dist/src/tokens/process/configs/type-scale.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/type-scale.js +51 -0
- package/dist/src/tokens/process/configs/type-scale.js.map +1 -0
- package/dist/src/tokens/process/configs/typography.d.ts +7 -0
- package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/configs/typography.js +66 -0
- package/dist/src/tokens/process/configs/typography.js.map +1 -0
- package/dist/src/tokens/process/configs.d.ts +18 -0
- package/dist/src/tokens/process/configs.d.ts.map +1 -0
- package/dist/src/tokens/process/configs.js +74 -0
- package/dist/src/tokens/process/configs.js.map +1 -0
- package/dist/src/tokens/process/formats/css/color.d.ts +8 -0
- package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/color.js +64 -0
- package/dist/src/tokens/process/formats/css/color.js.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts +7 -0
- package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/semantic.js +31 -0
- package/dist/src/tokens/process/formats/css/semantic.js.map +1 -0
- package/dist/src/tokens/process/formats/css/size-mode.d.ts +7 -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 +52 -0
- package/dist/src/tokens/process/formats/css/size-mode.js.map +1 -0
- package/dist/src/tokens/process/formats/css/size.d.ts +16 -0
- package/dist/src/tokens/process/formats/css/size.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/size.js +95 -0
- package/dist/src/tokens/process/formats/css/size.js.map +1 -0
- package/dist/src/tokens/process/formats/css/type-scale.d.ts +7 -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 +57 -0
- package/dist/src/tokens/process/formats/css/type-scale.js.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts +7 -0
- package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css/typography.js +31 -0
- package/dist/src/tokens/process/formats/css/typography.js.map +1 -0
- package/dist/src/tokens/process/formats/css.d.ts +15 -0
- package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
- package/dist/src/tokens/process/formats/css.js +20 -0
- package/dist/src/tokens/process/formats/css.js.map +1 -0
- package/dist/src/tokens/process/output/declarations.d.ts +9 -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/declarations.js.map +1 -0
- package/dist/src/tokens/process/output/tailwind.d.ts +7 -0
- package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
- package/dist/src/tokens/process/output/tailwind.js +47 -0
- package/dist/src/tokens/process/output/tailwind.js.map +1 -0
- package/dist/src/tokens/process/output/theme.d.ts +31 -0
- package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
- package/dist/src/tokens/process/output/theme.js +85 -0
- package/dist/src/tokens/process/output/theme.js.map +1 -0
- package/dist/src/tokens/process/platform.d.ts +69 -0
- package/dist/src/tokens/process/platform.d.ts.map +1 -0
- package/dist/src/tokens/process/platform.js +128 -0
- package/dist/src/tokens/process/platform.js.map +1 -0
- package/dist/src/tokens/process/transformers.d.ts +10 -0
- package/dist/src/tokens/process/transformers.d.ts.map +1 -0
- package/dist/src/tokens/process/transformers.js +56 -0
- package/dist/src/tokens/process/transformers.js.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +38 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +112 -0
- package/dist/src/tokens/process/utils/getMultidimensionalThemes.js.map +1 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts +8 -0
- package/dist/src/tokens/process/utils/kebab-case.d.ts.map +1 -0
- package/dist/src/tokens/process/utils/kebab-case.js +11 -0
- package/dist/src/tokens/process/utils/kebab-case.js.map +1 -0
- package/dist/src/tokens/types.d.ts +71 -0
- package/dist/src/tokens/types.d.ts.map +1 -0
- package/dist/src/tokens/types.js +1 -0
- package/dist/src/tokens/utils.d.ts +62 -0
- package/dist/src/tokens/utils.d.ts.map +1 -0
- package/dist/src/tokens/utils.js +123 -0
- package/dist/src/tokens/utils.js.map +1 -0
- package/dist/src/types.d.ts +1 -0
- package/dist/src/types.js +10 -0
- package/dist/src/types.js.map +1 -0
- package/dist/src/utils/filesystem.d.ts +47 -0
- package/dist/src/utils/filesystem.d.ts.map +1 -0
- package/dist/src/utils/filesystem.js +117 -0
- package/dist/src/utils/filesystem.js.map +1 -0
- package/package.json +87 -0
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size-mode.d.ts","names":[],"sources":["../../../../../../src/tokens/process/formats/css/size-mode.ts"],"mappings":";;;cAiBa,QAAA,EAAU,MAsDtB"}
|
|
@@ -0,0 +1,52 @@
|
|
|
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 };
|
|
51
|
+
|
|
52
|
+
//# sourceMappingURL=size-mode.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size-mode.js","names":[],"sources":["../../../../../../src/tokens/process/formats/css/size-mode.ts"],"sourcesContent":["import * as R from 'ramda';\nimport type { TransformedToken } from 'style-dictionary';\nimport type { Format } from 'style-dictionary/types';\nimport { createPropertyFormatter } from 'style-dictionary/utils';\nimport { orderBySize, shortSizeName } from '../../../utils.ts';\nimport { basePxFontSize } from '../../configs/shared.ts';\nimport { buildOptions } from '../../platform.ts';\n\nconst formatBaseSizeToken =\n (size: string) =>\n (token: TransformedToken): TransformedToken & { originalName: string } => ({\n ...token,\n originalName: token.name,\n name: `${token.name}--${shortSizeName(size)}`,\n $value: token.$value / basePxFontSize,\n });\n\nexport const sizeMode: Format = {\n name: 'ds/css-size-mode',\n format: async ({ dictionary, file, options, platform }) => {\n const { outputReferences, usesDtcg } = options;\n const { selector, layer, size } = platform;\n const destination = file.destination as string;\n\n const format = createPropertyFormatter({\n outputReferences,\n dictionary,\n format: 'css',\n usesDtcg,\n });\n\n const sizeSpecificTokens = dictionary.allTokens.map(formatBaseSizeToken(size));\n const sizeSpecificVariables = sizeSpecificTokens.map(format).join('\\n');\n\n const formattedMap = sizeSpecificTokens.map((token) => ({\n token,\n formatted: format({\n ...token,\n // Remove the `--<size>` suffix for the token listing, since that is the only token we actually use\n name: token.originalName,\n }),\n }));\n\n buildOptions.buildTokenFormats[destination] = formattedMap;\n\n const content = `${selector} /* ${size} */ {\\n${sizeSpecificVariables}\\n}`;\n const body = wrapInLayer(content, layer);\n\n /*\n * The following CSS is only generated once, not per mode\n */\n const sizes = orderBySize(buildOptions?.sizeModes ?? []).map(shortSizeName);\n const defaultSize = shortSizeName(buildOptions?.defaultSize ?? '');\n\n const sizingToggles = `:root, [data-size] {\n --ds-size: var(--ds-size--${defaultSize});\n${sizes.map((size) => ` --ds-size--${size}: var(--ds-size,);`).join('\\n')}\n --ds-size-mode-font-size:\n${sizes.map((size) => ` var(--ds-size--${size}, var(--ds-size-mode-font-size--${size}))`).join('\\n')};\n}`;\n const sizingHelpers = sizes\n .map((size) => `[data-size='${size}'] { --ds-size: var(--ds-size--${size}); }`)\n .join('\\n');\n const sharedContent = `${sizingToggles}\\n\\n${sizingHelpers}`;\n const sharedBody = shortSizeName(size) === R.last(sizes) ? `\\n${wrapInLayer(sharedContent, layer)}` : '';\n /*\n * End of generated-once CSS\n */\n\n return body + sharedBody;\n },\n};\n\nfunction wrapInLayer(content: string, layer?: string) {\n return R.isNotNil(layer) ? `@layer ${layer} {\\n${content}\\n}\\n` : `${content}\\n`;\n}\n"],"mappings":";;;;;;AAQA,MAAM,uBACH,UACA,WAA0E;CACzE,GAAG;CACH,cAAc,MAAM;CACpB,MAAM,GAAG,MAAM,KAAK,IAAI,cAAc,IAAI;CAC1C,QAAQ,MAAM,SAAA;AAChB;AAEF,MAAa,WAAmB;CAC9B,MAAM;CACN,QAAQ,OAAO,EAAE,YAAY,MAAM,SAAS,eAAe;EACzD,MAAM,EAAE,kBAAkB,aAAa;EACvC,MAAM,EAAE,UAAU,OAAO,SAAS;EAClC,MAAM,cAAc,KAAK;EAEzB,MAAM,SAAS,wBAAwB;GACrC;GACA;GACA,QAAQ;GACR;EACF,CAAC;EAED,MAAM,qBAAqB,WAAW,UAAU,IAAI,oBAAoB,IAAI,CAAC;EAC7E,MAAM,wBAAwB,mBAAmB,IAAI,MAAM,CAAC,CAAC,KAAK,IAAI;EAEtE,MAAM,eAAe,mBAAmB,KAAK,WAAW;GACtD;GACA,WAAW,OAAO;IAChB,GAAG;IAEH,MAAM,MAAM;GACd,CAAC;EACH,EAAE;EAEF,aAAa,kBAAkB,eAAe;EAG9C,MAAM,OAAO,YAAY,GADN,SAAS,MAAM,KAAK,SAAS,sBAAsB,MACpC,KAAK;EAKvC,MAAM,QAAQ,YAAY,cAAc,aAAa,CAAC,CAAC,CAAC,CAAC,IAAI,aAAa;EAY1E,MAAM,gBAAgB,GAAG;8BAXL,cAAc,cAAc,eAAe,EAG3B,EAAE;EACxC,MAAM,KAAK,SAAS,gBAAgB,KAAK,mBAAmB,CAAC,CAAC,KAAK,IAAI,EAAE;;EAEzE,MAAM,KAAK,SAAS,sBAAsB,KAAK,kCAAkC,KAAK,GAAG,CAAC,CAAC,KAAK,IAAI,EAAE;GAK7D,MAHjB,MACnB,KAAK,SAAS,eAAe,KAAK,iCAAiC,KAAK,KAAK,CAAC,CAC9E,KAAK,IACiD;EAMzD,OAAO,QALY,cAAc,IAAI,MAAM,EAAE,KAAK,KAAK,IAAI,KAAK,YAAY,eAAe,KAAK,MAAM;CAMxG;AACF;AAEA,SAAS,YAAY,SAAiB,OAAgB;CACpD,OAAO,EAAE,SAAS,KAAK,IAAI,UAAU,MAAM,MAAM,QAAQ,SAAS,GAAG,QAAQ;AAC/E"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { TransformedToken } from "style-dictionary";
|
|
2
|
+
import { Format } from "style-dictionary/types";
|
|
3
|
+
|
|
4
|
+
//#region src/tokens/process/formats/css/size.d.ts
|
|
5
|
+
declare const isInlineTokens: (t: TransformedToken) => boolean;
|
|
6
|
+
declare const sizingTemplate: ({
|
|
7
|
+
round,
|
|
8
|
+
calc
|
|
9
|
+
}: {
|
|
10
|
+
round: string[];
|
|
11
|
+
calc: string[];
|
|
12
|
+
}) => string;
|
|
13
|
+
declare const size: Format;
|
|
14
|
+
//#endregion
|
|
15
|
+
export { isInlineTokens, size, sizingTemplate };
|
|
16
|
+
//# sourceMappingURL=size.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.d.ts","names":[],"sources":["../../../../../../src/tokens/process/formats/css/size.ts"],"mappings":";;;;cAWa,cAAA,GAAc,CAJ4B,EAAhB,gBAAgB;AAAA,cAwD1C,cAAA;EAAkB,KAAA;EAAA;AAAA;EAAmB,KAAA;EAAiB,IAAA;AAAA;AAAA,cAStD,IAAA,EAAM,MAyClB"}
|
|
@@ -0,0 +1,95 @@
|
|
|
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, size, sizingTemplate };
|
|
94
|
+
|
|
95
|
+
//# sourceMappingURL=size.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"size.js","names":[],"sources":["../../../../../../src/tokens/process/formats/css/size.ts"],"sourcesContent":["import * as R from 'ramda';\nimport type { TransformedToken } from 'style-dictionary';\nimport type { Format } from 'style-dictionary/types';\nimport { createPropertyFormatter } from 'style-dictionary/utils';\nimport { inlineTokens, isDigit, pathStartsWithOneOf } from '../../../utils.ts';\nimport { buildOptions } from '../../platform.ts';\n\nconst isNumericBorderRadiusToken = (t: TransformedToken) => t.path[0] === 'border-radius' && isDigit(t.path[1]);\nconst isNumericSizeToken = (t: TransformedToken) => pathStartsWithOneOf(['size'], t) && isDigit(t.path[1]);\nconst isSizeToken = (t: TransformedToken) => pathStartsWithOneOf(['size'], t);\n\nexport const isInlineTokens = R.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);\n\n/**\n * Overrides the default sizing formula with a custom one that supports [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.\n *\n * @param format - Function to format a token into a CSS property string.\n * @param tokens - Array of transformed tokens to format.\n * @returns Object with formatted CSS strings for calc and round.\n */\nconst overrideSizingFormula = (format: (t: TransformedToken) => string, token: TransformedToken) => {\n const [name, value] = format(token).replace(/;$/, '').split(': ');\n\n let calc: string;\n let round: string | undefined;\n if (token.path[1] === 'unit') {\n calc = `calc(1rem * ${value})`;\n } else if (value.startsWith('floor')) {\n calc = value.replace(/^floor\\((.*)\\)$/, 'calc($1)');\n round = `round(down, ${calc}, 1px)`;\n } else {\n calc = value.includes('*') ? `calc(${value})` : value;\n }\n\n return {\n name,\n round: round ?? calc,\n calc,\n };\n};\n\n/**\n * Formats sizing tokens into CSS properties with support for rounding.\n *\n * @param format - Function to format a token into a CSS property string.\n * @param tokens - Array of transformed tokens to format.\n * @returns Formatted CSS string with default calc and [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.\n */\nconst formatSizingTokens = (format: (t: TransformedToken) => string, tokens: TransformedToken[]) =>\n R.reduce(\n (acc, token) => {\n const { round, calc, name } = overrideSizingFormula(format, token);\n\n return {\n tokens: [...acc.tokens, token],\n round: [...acc.round, `${name}: ${round};`],\n calc: [...acc.calc, `${name}: ${calc};`],\n };\n },\n { tokens: [], round: [], calc: [] } as { tokens: TransformedToken[]; round: string[]; calc: string[] },\n tokens,\n );\n\nexport const sizingTemplate = ({ round, calc }: { round: string[]; calc: string[] }) => {\n const usesRounding = round.filter((val, i) => val !== calc[i]);\n return `\n${calc.join('\\n')}\\n\n @supports (width: round(down, .1em, 1px)) {\n ${usesRounding.join('\\n ')}\n }`;\n};\n\nexport const size: Format = {\n name: 'ds/css-size',\n format: async ({ dictionary, file, options, platform }) => {\n const { outputReferences, usesDtcg } = options;\n const { selector, layer } = platform;\n const destination = file.destination as string;\n\n const format = createPropertyFormatter({\n outputReferences,\n dictionary,\n format: 'css',\n usesDtcg,\n });\n\n const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);\n const filteredTokens = R.reject((token) => R.equals(['_size', 'mode-font-size'], token.path), tokens);\n const [sizingTokens, restTokens] = R.partition(\n (t: TransformedToken) => pathStartsWithOneOf(['_size'], t) && (isDigit(t.path[1]) || t.path[1] === 'unit'),\n filteredTokens,\n );\n const formattedSizingTokens = formatSizingTokens(format, sizingTokens);\n\n const formattedMap = restTokens.map((token) => ({\n token,\n formatted: format(token),\n }));\n\n const formattedSizingMap = formattedSizingTokens.round.map((t, i) => ({\n token: formattedSizingTokens.tokens[i],\n formatted: t,\n }));\n\n buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];\n\n const formattedTokens = [formattedMap.map(R.prop('formatted')).join('\\n'), sizingTemplate(formattedSizingTokens)];\n\n const content = `${selector} {\\n${formattedTokens.join('\\n')}\\n}\\n`;\n const body = R.isNotNil(layer) ? `@layer ${layer} {\\n${content}\\n}\\n` : `${content}\\n`;\n\n return body;\n },\n};\n"],"mappings":";;;;;AAOA,MAAM,8BAA8B,MAAwB,EAAE,KAAK,OAAO,mBAAmB,QAAQ,EAAE,KAAK,EAAE;AAC9G,MAAM,sBAAsB,MAAwB,oBAAoB,CAAC,MAAM,GAAG,CAAC,KAAK,QAAQ,EAAE,KAAK,EAAE;AACzG,MAAM,eAAe,MAAwB,oBAAoB,CAAC,MAAM,GAAG,CAAC;AAE5E,MAAa,iBAAiB,EAAE,QAAQ;CAAC;CAA4B;CAAoB;AAAW,CAAC;;;;;;;;AASrG,MAAM,yBAAyB,QAAyC,UAA4B;CAClG,MAAM,CAAC,MAAM,SAAS,OAAO,KAAK,CAAC,CAAC,QAAQ,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI;CAEhE,IAAI;CACJ,IAAI;CACJ,IAAI,MAAM,KAAK,OAAO,QACpB,OAAO,eAAe,MAAM;MACvB,IAAI,MAAM,WAAW,OAAO,GAAG;EACpC,OAAO,MAAM,QAAQ,mBAAmB,UAAU;EAClD,QAAQ,eAAe,KAAK;CAC9B,OACE,OAAO,MAAM,SAAS,GAAG,IAAI,QAAQ,MAAM,KAAK;CAGlD,OAAO;EACL;EACA,OAAO,SAAS;EAChB;CACF;AACF;;;;;;;;AASA,MAAM,sBAAsB,QAAyC,WACnE,EAAE,QACC,KAAK,UAAU;CACd,MAAM,EAAE,OAAO,MAAM,SAAS,sBAAsB,QAAQ,KAAK;CAEjE,OAAO;EACL,QAAQ,CAAC,GAAG,IAAI,QAAQ,KAAK;EAC7B,OAAO,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,IAAI,MAAM,EAAE;EAC1C,MAAM,CAAC,GAAG,IAAI,MAAM,GAAG,KAAK,IAAI,KAAK,EAAE;CACzC;AACF,GACA;CAAE,QAAQ,CAAC;CAAG,OAAO,CAAC;CAAG,MAAM,CAAC;AAAE,GAClC,MACF;AAEF,MAAa,kBAAkB,EAAE,OAAO,WAAgD;CACtF,MAAM,eAAe,MAAM,QAAQ,KAAK,MAAM,QAAQ,KAAK,EAAE;CAC7D,OAAO;EACP,KAAK,KAAK,IAAI,EAAE;;IAEd,aAAa,KAAK,MAAM,EAAE;;AAE9B;AAEA,MAAa,OAAe;CAC1B,MAAM;CACN,QAAQ,OAAO,EAAE,YAAY,MAAM,SAAS,eAAe;EACzD,MAAM,EAAE,kBAAkB,aAAa;EACvC,MAAM,EAAE,UAAU,UAAU;EAC5B,MAAM,cAAc,KAAK;EAEzB,MAAM,SAAS,wBAAwB;GACrC;GACA;GACA,QAAQ;GACR;EACF,CAAC;EAED,MAAM,SAAS,aAAa,gBAAgB,WAAW,SAAS;EAChE,MAAM,iBAAiB,EAAE,QAAQ,UAAU,EAAE,OAAO,CAAC,SAAS,gBAAgB,GAAG,MAAM,IAAI,GAAG,MAAM;EACpG,MAAM,CAAC,cAAc,cAAc,EAAE,WAClC,MAAwB,oBAAoB,CAAC,OAAO,GAAG,CAAC,MAAM,QAAQ,EAAE,KAAK,EAAE,KAAK,EAAE,KAAK,OAAO,SACnG,cACF;EACA,MAAM,wBAAwB,mBAAmB,QAAQ,YAAY;EAErE,MAAM,eAAe,WAAW,KAAK,WAAW;GAC9C;GACA,WAAW,OAAO,KAAK;EACzB,EAAE;EAEF,MAAM,qBAAqB,sBAAsB,MAAM,KAAK,GAAG,OAAO;GACpE,OAAO,sBAAsB,OAAO;GACpC,WAAW;EACb,EAAE;EAEF,aAAa,kBAAkB,eAAe,CAAC,GAAG,cAAc,GAAG,kBAAkB;EAIrF,MAAM,UAAU,GAAG,SAAS,MAAM,CAFT,aAAa,IAAI,EAAE,KAAK,WAAW,CAAC,CAAC,CAAC,KAAK,IAAI,GAAG,eAAe,qBAAqB,CAE/D,CAAC,CAAC,KAAK,IAAI,EAAE;EAG7D,OAFa,EAAE,SAAS,KAAK,IAAI,UAAU,MAAM,MAAM,QAAQ,SAAS,GAAG,QAAQ;CAGrF;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-scale.d.ts","names":[],"sources":["../../../../../../src/tokens/process/formats/css/type-scale.ts"],"mappings":";;;cA4Ca,SAAA,EAAW,MA8BvB"}
|
|
@@ -0,0 +1,57 @@
|
|
|
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 };
|
|
56
|
+
|
|
57
|
+
//# sourceMappingURL=type-scale.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"type-scale.js","names":[],"sources":["../../../../../../src/tokens/process/formats/css/type-scale.ts"],"sourcesContent":["import * as R from 'ramda';\nimport type { Format, TransformedToken } from 'style-dictionary/types';\nimport { createPropertyFormatter } from 'style-dictionary/utils';\nimport { basePxFontSize } from '../../configs/shared.ts';\nimport { buildOptions } from '../../platform.ts';\nimport { sizingTemplate } from './size.ts';\n\n// Predicate to filter tokens with .path array that includes both typography and fontFamily\nconst isTypographyFontFamilyToken = R.allPass([\n R.pathSatisfies(R.includes('typography'), ['path']),\n R.pathSatisfies(R.includes('fontFamily'), ['path']),\n]);\n\ntype TokensWithCalcAndRoundFormatting = { tokens: TransformedToken[]; calc: string[]; round: string[] };\n\nconst formatTypographySizeToken = (\n format: (t: TransformedToken) => string,\n token: TransformedToken,\n): { name: string; calc: string; round: string } => {\n const [name, value] = format(token).replace(/;$/, '').split(': ');\n let calc: string;\n let round: string | undefined;\n if (R.startsWith(['font-size'], token.path)) {\n calc = `calc(${value} * var(--_ds-font-size-factor))`;\n round = `round(${calc}, 1px)`;\n } else {\n calc = value;\n }\n return { name, calc, round: round ?? calc };\n};\n\nconst formatTypographySizeTokens = (format: (t: TransformedToken) => string, tokens: TransformedToken[]) =>\n R.reduce<TransformedToken, TokensWithCalcAndRoundFormatting>(\n (acc, token) => {\n const { name, calc, round } = formatTypographySizeToken(format, token);\n acc.tokens.push(token);\n acc.calc.push(`${name}: ${calc};`);\n acc.round.push(`${name}: ${round};`);\n return acc;\n },\n { tokens: [], calc: [], round: [] },\n tokens,\n );\n\nexport const typeScale: Format = {\n name: 'ds/css-type-scale',\n format: async ({ dictionary, file, options, platform }) => {\n const { outputReferences, usesDtcg } = options;\n const { selector, layer } = platform as { selector: string; layer: string };\n const destination = file.destination as string;\n\n const format = createPropertyFormatter({\n outputReferences,\n dictionary,\n format: 'css',\n usesDtcg,\n });\n\n const filteredTokens = R.reject(R.anyPass([isTypographyFontFamilyToken]), dictionary.allTokens);\n const formattedTokens = formatTypographySizeTokens(format, filteredTokens);\n\n const formattedMap = formattedTokens.round.map((t, i) => ({\n token: formattedTokens.tokens[i],\n formatted: t,\n }));\n\n buildOptions.buildTokenFormats[destination] = formattedMap;\n\n const sizeFactor = ` --_ds-font-size-factor: calc(var(--ds-size-mode-font-size) / (var(--ds-size-base) / ${basePxFontSize}));`;\n const content = `${selector} {\\n${sizeFactor}${sizingTemplate(formattedTokens)}\\n}`;\n const body = R.isNotNil(layer) ? `@layer ${layer} {\\n${content}\\n}` : content;\n\n return body;\n },\n};\n"],"mappings":";;;;;;AAQA,MAAM,8BAA8B,EAAE,QAAQ,CAC5C,EAAE,cAAc,EAAE,SAAS,YAAY,GAAG,CAAC,MAAM,CAAC,GAClD,EAAE,cAAc,EAAE,SAAS,YAAY,GAAG,CAAC,MAAM,CAAC,CACpD,CAAC;AAID,MAAM,6BACJ,QACA,UACkD;CAClD,MAAM,CAAC,MAAM,SAAS,OAAO,KAAK,CAAC,CAAC,QAAQ,MAAM,EAAE,CAAC,CAAC,MAAM,IAAI;CAChE,IAAI;CACJ,IAAI;CACJ,IAAI,EAAE,WAAW,CAAC,WAAW,GAAG,MAAM,IAAI,GAAG;EAC3C,OAAO,QAAQ,MAAM;EACrB,QAAQ,SAAS,KAAK;CACxB,OACE,OAAO;CAET,OAAO;EAAE;EAAM;EAAM,OAAO,SAAS;CAAK;AAC5C;AAEA,MAAM,8BAA8B,QAAyC,WAC3E,EAAE,QACC,KAAK,UAAU;CACd,MAAM,EAAE,MAAM,MAAM,UAAU,0BAA0B,QAAQ,KAAK;CACrE,IAAI,OAAO,KAAK,KAAK;CACrB,IAAI,KAAK,KAAK,GAAG,KAAK,IAAI,KAAK,EAAE;CACjC,IAAI,MAAM,KAAK,GAAG,KAAK,IAAI,MAAM,EAAE;CACnC,OAAO;AACT,GACA;CAAE,QAAQ,CAAC;CAAG,MAAM,CAAC;CAAG,OAAO,CAAC;AAAE,GAClC,MACF;AAEF,MAAa,YAAoB;CAC/B,MAAM;CACN,QAAQ,OAAO,EAAE,YAAY,MAAM,SAAS,eAAe;EACzD,MAAM,EAAE,kBAAkB,aAAa;EACvC,MAAM,EAAE,UAAU,UAAU;EAC5B,MAAM,cAAc,KAAK;EAUzB,MAAM,kBAAkB,2BART,wBAAwB;GACrC;GACA;GACA,QAAQ;GACR;EACF,CAGwD,GADjC,EAAE,OAAO,EAAE,QAAQ,CAAC,2BAA2B,CAAC,GAAG,WAAW,SACb,CAAC;EAEzE,MAAM,eAAe,gBAAgB,MAAM,KAAK,GAAG,OAAO;GACxD,OAAO,gBAAgB,OAAO;GAC9B,WAAW;EACb,EAAE;EAEF,aAAa,kBAAkB,eAAe;EAG9C,MAAM,UAAU,GAAG,SAAS,iGAAmB,eAAe,eAAe,EAAE;EAG/E,OAFa,EAAE,SAAS,KAAK,IAAI,UAAU,MAAM,MAAM,QAAQ,OAAO;CAGxE;AACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typography.d.ts","names":[],"sources":["../../../../../../src/tokens/process/formats/css/typography.ts"],"mappings":";;;cAWa,UAAA,EAAY,MA8BxB"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { buildOptions } from "../../platform.js";
|
|
2
|
+
import * as R from "ramda";
|
|
3
|
+
import { createPropertyFormatter } from "style-dictionary/utils";
|
|
4
|
+
//#region src/tokens/process/formats/css/typography.ts
|
|
5
|
+
const typographyFontFamilyPredicate = R.allPass([R.pathSatisfies(R.includes("typography"), ["path"]), R.pathSatisfies(R.includes("fontFamily"), ["path"])]);
|
|
6
|
+
const typography = {
|
|
7
|
+
name: "ds/css-typography",
|
|
8
|
+
format: async ({ dictionary, file, options, platform }) => {
|
|
9
|
+
const { outputReferences, usesDtcg } = options;
|
|
10
|
+
const { selector, layer } = platform;
|
|
11
|
+
const destination = file.destination;
|
|
12
|
+
const format = createPropertyFormatter({
|
|
13
|
+
outputReferences,
|
|
14
|
+
dictionary,
|
|
15
|
+
format: "css",
|
|
16
|
+
usesDtcg
|
|
17
|
+
});
|
|
18
|
+
const formattedMap = R.reject(typographyFontFamilyPredicate, dictionary.allTokens).map((token) => ({
|
|
19
|
+
token,
|
|
20
|
+
formatted: format(token)
|
|
21
|
+
}));
|
|
22
|
+
buildOptions.buildTokenFormats[destination] = formattedMap;
|
|
23
|
+
const formattedTokens = formattedMap.map(R.view(R.lensProp("formatted"))).join("\n");
|
|
24
|
+
const content = selector ? `${selector} {\n${formattedTokens}\n}` : formattedTokens;
|
|
25
|
+
return R.isNotNil(layer) ? `@layer ${layer} {\n${content}\n}` : content;
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
//#endregion
|
|
29
|
+
export { typography };
|
|
30
|
+
|
|
31
|
+
//# sourceMappingURL=typography.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"typography.js","names":[],"sources":["../../../../../../src/tokens/process/formats/css/typography.ts"],"sourcesContent":["import * as R from 'ramda';\nimport type { Format, TransformedToken } from 'style-dictionary/types';\nimport { createPropertyFormatter } from 'style-dictionary/utils';\nimport { buildOptions } from '../../platform.ts';\n\n// Predicate to filter tokens with .path array that includes both typography and fontFamily\nconst typographyFontFamilyPredicate = R.allPass([\n R.pathSatisfies(R.includes('typography'), ['path']),\n R.pathSatisfies(R.includes('fontFamily'), ['path']),\n]);\n\nexport const typography: Format = {\n name: 'ds/css-typography',\n format: async ({ dictionary, file, options, platform }) => {\n const { outputReferences, usesDtcg } = options;\n const { selector, layer } = platform;\n const destination = file.destination as string;\n\n const format = createPropertyFormatter({\n outputReferences,\n dictionary,\n format: 'css',\n usesDtcg,\n });\n\n const filteredTokens = R.reject(typographyFontFamilyPredicate, dictionary.allTokens);\n\n const formattedMap = filteredTokens.map((token: TransformedToken) => ({\n token,\n formatted: format(token),\n }));\n\n buildOptions.buildTokenFormats[destination] = formattedMap;\n\n const formattedTokens = formattedMap.map(R.view(R.lensProp('formatted'))).join('\\n');\n\n const content = selector ? `${selector} {\\n${formattedTokens}\\n}` : formattedTokens;\n const body = R.isNotNil(layer) ? `@layer ${layer} {\\n${content}\\n}` : content;\n\n return body;\n },\n};\n"],"mappings":";;;;AAMA,MAAM,gCAAgC,EAAE,QAAQ,CAC9C,EAAE,cAAc,EAAE,SAAS,YAAY,GAAG,CAAC,MAAM,CAAC,GAClD,EAAE,cAAc,EAAE,SAAS,YAAY,GAAG,CAAC,MAAM,CAAC,CACpD,CAAC;AAED,MAAa,aAAqB;CAChC,MAAM;CACN,QAAQ,OAAO,EAAE,YAAY,MAAM,SAAS,eAAe;EACzD,MAAM,EAAE,kBAAkB,aAAa;EACvC,MAAM,EAAE,UAAU,UAAU;EAC5B,MAAM,cAAc,KAAK;EAEzB,MAAM,SAAS,wBAAwB;GACrC;GACA;GACA,QAAQ;GACR;EACF,CAAC;EAID,MAAM,eAFiB,EAAE,OAAO,+BAA+B,WAAW,SAExC,CAAC,CAAC,KAAK,WAA6B;GACpE;GACA,WAAW,OAAO,KAAK;EACzB,EAAE;EAEF,aAAa,kBAAkB,eAAe;EAE9C,MAAM,kBAAkB,aAAa,IAAI,EAAE,KAAK,EAAE,SAAS,WAAW,CAAC,CAAC,CAAC,CAAC,KAAK,IAAI;EAEnF,MAAM,UAAU,WAAW,GAAG,SAAS,MAAM,gBAAgB,OAAO;EAGpE,OAFa,EAAE,SAAS,KAAK,IAAI,UAAU,MAAM,MAAM,QAAQ,OAAO;CAGxE;AACF"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Format } from "style-dictionary/types";
|
|
2
|
+
|
|
3
|
+
//#region src/tokens/process/formats/css.d.ts
|
|
4
|
+
declare const formats: {
|
|
5
|
+
colorScheme: Format;
|
|
6
|
+
colorCategory: Format;
|
|
7
|
+
semantic: Format;
|
|
8
|
+
sizeMode: Format;
|
|
9
|
+
size: Format;
|
|
10
|
+
typography: Format;
|
|
11
|
+
typeScale: Format;
|
|
12
|
+
};
|
|
13
|
+
//#endregion
|
|
14
|
+
export { formats };
|
|
15
|
+
//# sourceMappingURL=css.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.d.ts","names":[],"sources":["../../../../../src/tokens/process/formats/css.ts"],"mappings":";;;cASa,OAAA"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { colorCategory, colorScheme } from "./css/color.js";
|
|
2
|
+
import { size } from "./css/size.js";
|
|
3
|
+
import { semantic } from "./css/semantic.js";
|
|
4
|
+
import { sizeMode } from "./css/size-mode.js";
|
|
5
|
+
import { typography } from "./css/typography.js";
|
|
6
|
+
import { typeScale } from "./css/type-scale.js";
|
|
7
|
+
//#region src/tokens/process/formats/css.ts
|
|
8
|
+
const formats = {
|
|
9
|
+
colorScheme,
|
|
10
|
+
colorCategory,
|
|
11
|
+
semantic,
|
|
12
|
+
sizeMode,
|
|
13
|
+
size,
|
|
14
|
+
typography,
|
|
15
|
+
typeScale
|
|
16
|
+
};
|
|
17
|
+
//#endregion
|
|
18
|
+
export { formats };
|
|
19
|
+
|
|
20
|
+
//# sourceMappingURL=css.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"css.js","names":[],"sources":["../../../../../src/tokens/process/formats/css.ts"],"sourcesContent":["import type { Format } from 'style-dictionary/types';\n\nimport { colorCategory, colorScheme } from '../formats/css/color.ts';\nimport { semantic } from '../formats/css/semantic.ts';\nimport { size } from '../formats/css/size.ts';\nimport { sizeMode } from '../formats/css/size-mode.ts';\nimport { typography } from '../formats/css/typography.ts';\nimport { typeScale } from './css/type-scale.ts';\n\nexport const formats = {\n colorScheme,\n colorCategory,\n semantic,\n sizeMode,\n size,\n typography,\n typeScale,\n} satisfies Record<string, Format>;\n"],"mappings":";;;;;;;AASA,MAAa,UAAU;CACrB;CACA;CACA;CACA;CACA;CACA;CACA;AACF"}
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { OutputFile } from "../../types.js";
|
|
2
|
+
import { ProcessedThemeObject } from "../utils/getMultidimensionalThemes.js";
|
|
3
|
+
|
|
4
|
+
//#region src/tokens/process/output/declarations.d.ts
|
|
5
|
+
declare const defaultFileHeader: string;
|
|
6
|
+
declare const createTypeDeclarationFiles: (processed$themes: ProcessedThemeObject[]) => OutputFile[];
|
|
7
|
+
//#endregion
|
|
8
|
+
export { createTypeDeclarationFiles, defaultFileHeader };
|
|
9
|
+
//# sourceMappingURL=declarations.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.d.ts","names":[],"sources":["../../../../../src/tokens/process/output/declarations.ts"],"mappings":";;;;cAMa,iBAAA;AAAA,cAEA,0BAAA,GAA8B,gBAAA,EAAkB,oBAAA,OAAyB,UAAU"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { baseColors } from "../../../colors/colorMetadata.js";
|
|
2
|
+
import { version } from "../../../../package.js";
|
|
3
|
+
import { getThemeColors } from "../utils/getMultidimensionalThemes.js";
|
|
4
|
+
import pc from "picocolors";
|
|
5
|
+
//#region src/tokens/process/output/declarations.ts
|
|
6
|
+
const defaultFileHeader = `build: v${version}`;
|
|
7
|
+
const createTypeDeclarationFiles = (processed$themes) => {
|
|
8
|
+
const typeDeclaration = createColorTypeDeclaration(getThemeColors(processed$themes));
|
|
9
|
+
return [{
|
|
10
|
+
output: `/* This file is deprecated and will be removed in a future release. Use types.d.ts instead */\n${typeDeclaration}`,
|
|
11
|
+
destination: "colors.d.ts"
|
|
12
|
+
}, {
|
|
13
|
+
output: typeDeclaration,
|
|
14
|
+
destination: "types.d.ts"
|
|
15
|
+
}];
|
|
16
|
+
};
|
|
17
|
+
function createColorTypeDeclaration(colors) {
|
|
18
|
+
console.log(`\n🍱 Building ${pc.green("type declarations")}`);
|
|
19
|
+
const severityColors = Object.keys(baseColors);
|
|
20
|
+
return `
|
|
21
|
+
/* ${defaultFileHeader} */
|
|
22
|
+
import type {} from '@digdir/designsystemet-types';
|
|
23
|
+
|
|
24
|
+
// Augment types based on theme
|
|
25
|
+
declare module '@digdir/designsystemet-types' {
|
|
26
|
+
export interface ColorDefinitions {
|
|
27
|
+
${colors.filter((color) => !severityColors.includes(color)).map((color) => ` ${color.includes("-") ? `'${color}'` : color}: never;`).join("\n")}
|
|
28
|
+
}
|
|
29
|
+
export interface SeverityColorDefinitions {
|
|
30
|
+
${severityColors.map((color) => ` ${color}: never;`).join("\n")}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
`.trimStart();
|
|
34
|
+
}
|
|
35
|
+
//#endregion
|
|
36
|
+
export { createTypeDeclarationFiles, defaultFileHeader };
|
|
37
|
+
|
|
38
|
+
//# sourceMappingURL=declarations.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"declarations.js","names":["pkg.version"],"sources":["../../../../../src/tokens/process/output/declarations.ts"],"sourcesContent":["import pc from 'picocolors';\nimport pkg from '../../../../package.json' with { type: 'json' };\nimport { baseColors } from '../../../colors/colorMetadata.ts';\nimport type { OutputFile } from '../../types.ts';\nimport { getThemeColors, type ProcessedThemeObject } from '../utils/getMultidimensionalThemes.ts';\n\nexport const defaultFileHeader = `build: v${pkg.version}`;\n\nexport const createTypeDeclarationFiles = (processed$themes: ProcessedThemeObject[]): OutputFile[] => {\n const colors = getThemeColors(processed$themes);\n const typeDeclaration = createColorTypeDeclaration(colors);\n return [\n {\n output: `/* This file is deprecated and will be removed in a future release. Use types.d.ts instead */\\n${typeDeclaration}`,\n destination: 'colors.d.ts',\n },\n {\n output: typeDeclaration,\n destination: 'types.d.ts',\n },\n ];\n};\n\nfunction createColorTypeDeclaration(colors: string[]) {\n console.log(`\\n🍱 Building ${pc.green('type declarations')}`);\n\n const severityColors = Object.keys(baseColors);\n const colorsWithoutSeverity = colors.filter((color) => !severityColors.includes(color));\n\n const typeDeclaration = `\n/* ${defaultFileHeader} */\nimport type {} from '@digdir/designsystemet-types';\n\n// Augment types based on theme\ndeclare module '@digdir/designsystemet-types' {\n export interface ColorDefinitions {\n${colorsWithoutSeverity.map((color) => ` ${color.includes('-') ? `'${color}'` : color}: never;`).join('\\n')}\n }\n export interface SeverityColorDefinitions {\n${severityColors.map((color) => ` ${color}: never;`).join('\\n')}\n }\n}\n`.trimStart();\n\n return typeDeclaration;\n}\n"],"mappings":";;;;;AAMA,MAAa,oBAAoB,WAAWA;AAE5C,MAAa,8BAA8B,qBAA2D;CAEpG,MAAM,kBAAkB,2BADT,eAAe,gBAC0B,CAAC;CACzD,OAAO,CACL;EACE,QAAQ,kGAAkG;EAC1G,aAAa;CACf,GACA;EACE,QAAQ;EACR,aAAa;CACf,CACF;AACF;AAEA,SAAS,2BAA2B,QAAkB;CACpD,QAAQ,IAAI,iBAAiB,GAAG,MAAM,mBAAmB,GAAG;CAE5D,MAAM,iBAAiB,OAAO,KAAK,UAAU;CAkB7C,OAfwB;KACrB,kBAAkB;;;;;;EAHS,OAAO,QAAQ,UAAU,CAAC,eAAe,SAAS,KAAK,CASjE,CAAC,CAAC,KAAK,UAAU,OAAO,MAAM,SAAS,GAAG,IAAI,IAAI,MAAM,KAAK,MAAM,SAAS,CAAC,CAAC,KAAK,IAAI,EAAE;;;EAG7G,eAAe,KAAK,UAAU,OAAO,MAAM,SAAS,CAAC,CAAC,KAAK,IAAI,EAAE;;;EAGjE,UAEqB;AACvB"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { OutputFile } from "../../types.js";
|
|
2
|
+
|
|
3
|
+
//#region src/tokens/process/output/tailwind.d.ts
|
|
4
|
+
declare const createTailwindCSSFiles: (cssFiles: OutputFile[]) => OutputFile[];
|
|
5
|
+
//#endregion
|
|
6
|
+
export { createTailwindCSSFiles };
|
|
7
|
+
//# sourceMappingURL=tailwind.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tailwind.d.ts","names":[],"sources":["../../../../../src/tokens/process/output/tailwind.ts"],"mappings":";;;cAEa,sBAAA,GAA0B,QAAA,EAAU,UAAA,OAAe,UAAU"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
//#region src/tokens/process/output/tailwind.ts
|
|
2
|
+
const createTailwindCSSFiles = (cssFiles) => {
|
|
3
|
+
console.log("\n🍱 Creating Tailwind Config");
|
|
4
|
+
return cssFiles.map((file) => {
|
|
5
|
+
if (file.destination) {
|
|
6
|
+
const tailwindConfig = generateTailwind(file.output);
|
|
7
|
+
return {
|
|
8
|
+
destination: file.destination.replace(".css", ".tailwind.css"),
|
|
9
|
+
output: tailwindConfig
|
|
10
|
+
};
|
|
11
|
+
}
|
|
12
|
+
}).filter((item) => item !== void 0);
|
|
13
|
+
};
|
|
14
|
+
const generateTailwind = (css) => {
|
|
15
|
+
const tailwind = ["--font-sans: var(--ds-font-family)"];
|
|
16
|
+
const tokens = Array.from(new Set(css.match(/--ds-[^:)]+/g)), (m) => m).sort((a, b) => a.localeCompare(b, void 0, {
|
|
17
|
+
numeric: true,
|
|
18
|
+
sensitivity: "base"
|
|
19
|
+
}));
|
|
20
|
+
for (const token of tokens) if (token.startsWith("--ds-color-") && !token.startsWith("--ds-color-focus")) tailwind.push(`--color-${token.replace("--ds-color-", "")}: var(${token})`);
|
|
21
|
+
else if (token.startsWith("--ds-font-weight-")) tailwind.push(`--font-weight-${token.replace("--ds-font-weight-", "")}: var(${token})`);
|
|
22
|
+
else if (token.match(/--ds-border-radius-(sm|md|lg|xl)/)) tailwind.push(`--radius-${token.replace("--ds-border-radius-", "")}: var(${token})`);
|
|
23
|
+
else if (token.match(/--ds-body-(sm|mg|lg)-body-font-size/)) tailwind.push(`--text-${token.replace("--ds-body-", "").replace("-font-size", "")}: var(${token})`);
|
|
24
|
+
else if (token.match(/^--ds-size-\d+$/)) tailwind.push(`--spacing-${token.replace("--ds-size-", "")}: var(${token})`);
|
|
25
|
+
return `@theme {${tailwind.map((str) => `\n ${str};`).join("")}\n}\n[data-color] {
|
|
26
|
+
--color-background-default: var(--ds-color-background-default);
|
|
27
|
+
--color-background-tinted: var(--ds-color-background-tinted);
|
|
28
|
+
--color-surface-default: var(--ds-color-surface-default);
|
|
29
|
+
--color-surface-tinted: var(--ds-color-surface-tinted);
|
|
30
|
+
--color-surface-hover: var(--ds-color-surface-hover);
|
|
31
|
+
--color-surface-active: var(--ds-color-surface-active);
|
|
32
|
+
--color-border-subtle: var(--ds-color-border-subtle);
|
|
33
|
+
--color-border-default: var(--ds-color-border-default);
|
|
34
|
+
--color-border-strong: var(--ds-color-border-strong);
|
|
35
|
+
--color-text-subtle: var(--ds-color-text-subtle);
|
|
36
|
+
--color-text-default: var(--ds-color-text-default);
|
|
37
|
+
--color-base-default: var(--ds-color-base-default);
|
|
38
|
+
--color-base-hover: var(--ds-color-base-hover);
|
|
39
|
+
--color-base-active: var(--ds-color-base-active);
|
|
40
|
+
--color-base-contrast-subtle: var(--ds-color-base-contrast-subtle);
|
|
41
|
+
--color-base-contrast-default: var(--ds-color-base-contrast-default);
|
|
42
|
+
}`;
|
|
43
|
+
};
|
|
44
|
+
//#endregion
|
|
45
|
+
export { createTailwindCSSFiles };
|
|
46
|
+
|
|
47
|
+
//# sourceMappingURL=tailwind.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"tailwind.js","names":[],"sources":["../../../../../src/tokens/process/output/tailwind.ts"],"sourcesContent":["import type { OutputFile } from '../../types.ts';\n\nexport const createTailwindCSSFiles = (cssFiles: OutputFile[]): OutputFile[] => {\n console.log('\\n🍱 Creating Tailwind Config');\n return cssFiles\n .map((file) => {\n if (file.destination) {\n const tailwindConfig = generateTailwind(file.output);\n const tailwindFile = {\n destination: file.destination.replace('.css', '.tailwind.css'),\n output: tailwindConfig,\n };\n return tailwindFile;\n }\n return undefined;\n })\n .filter((item) => item !== undefined);\n};\n\nconst generateTailwind = (css: string): string => {\n const tailwind: string[] = ['--font-sans: var(--ds-font-family)'];\n const tokens = Array.from(new Set(css.match(/--ds-[^:)]+/g)), (m) => m).sort((a, b) =>\n a.localeCompare(b, undefined, { numeric: true, sensitivity: 'base' }),\n );\n\n // Scrape tokens relevant for Tailwind\n for (const token of tokens) {\n if (token.startsWith('--ds-color-') && !token.startsWith('--ds-color-focus')) {\n tailwind.push(`--color-${token.replace('--ds-color-', '')}: var(${token})`);\n } else if (token.startsWith('--ds-font-weight-')) {\n tailwind.push(`--font-weight-${token.replace('--ds-font-weight-', '')}: var(${token})`);\n } else if (token.match(/--ds-border-radius-(sm|md|lg|xl)/)) {\n // Not including \"full\" as this crashes with Tailwind\n tailwind.push(`--radius-${token.replace('--ds-border-radius-', '')}: var(${token})`);\n } else if (token.match(/--ds-body-(sm|mg|lg)-body-font-size/)) {\n tailwind.push(`--text-${token.replace('--ds-body-', '').replace('-font-size', '')}: var(${token})`);\n } else if (token.match(/^--ds-size-\\d+$/)) {\n tailwind.push(`--spacing-${token.replace('--ds-size-', '')}: var(${token})`);\n }\n }\n\n // Make [data-colors] dynamically change also Tailwind colors\n const dynamicColors = `[data-color] {\n --color-background-default: var(--ds-color-background-default);\n --color-background-tinted: var(--ds-color-background-tinted);\n --color-surface-default: var(--ds-color-surface-default);\n --color-surface-tinted: var(--ds-color-surface-tinted);\n --color-surface-hover: var(--ds-color-surface-hover);\n --color-surface-active: var(--ds-color-surface-active);\n --color-border-subtle: var(--ds-color-border-subtle);\n --color-border-default: var(--ds-color-border-default);\n --color-border-strong: var(--ds-color-border-strong);\n --color-text-subtle: var(--ds-color-text-subtle);\n --color-text-default: var(--ds-color-text-default);\n --color-base-default: var(--ds-color-base-default);\n --color-base-hover: var(--ds-color-base-hover);\n --color-base-active: var(--ds-color-base-active);\n --color-base-contrast-subtle: var(--ds-color-base-contrast-subtle);\n --color-base-contrast-default: var(--ds-color-base-contrast-default);\n }`;\n\n return `@theme {${tailwind.map((str) => `\\n ${str};`).join('')}\\n}\\n${dynamicColors}`;\n};\n"],"mappings":";AAEA,MAAa,0BAA0B,aAAyC;CAC9E,QAAQ,IAAI,+BAA+B;CAC3C,OAAO,SACJ,KAAK,SAAS;EACb,IAAI,KAAK,aAAa;GACpB,MAAM,iBAAiB,iBAAiB,KAAK,MAAM;GAKnD,OAAO;IAHL,aAAa,KAAK,YAAY,QAAQ,QAAQ,eAAe;IAC7D,QAAQ;GAEQ;EACpB;CAEF,CAAC,CAAC,CACD,QAAQ,SAAS,SAAS,KAAA,CAAS;AACxC;AAEA,MAAM,oBAAoB,QAAwB;CAChD,MAAM,WAAqB,CAAC,oCAAoC;CAChE,MAAM,SAAS,MAAM,KAAK,IAAI,IAAI,IAAI,MAAM,cAAc,CAAC,IAAI,MAAM,CAAC,CAAC,CAAC,MAAM,GAAG,MAC/E,EAAE,cAAc,GAAG,KAAA,GAAW;EAAE,SAAS;EAAM,aAAa;CAAO,CAAC,CACtE;CAGA,KAAK,MAAM,SAAS,QAClB,IAAI,MAAM,WAAW,aAAa,KAAK,CAAC,MAAM,WAAW,kBAAkB,GACzE,SAAS,KAAK,WAAW,MAAM,QAAQ,eAAe,EAAE,EAAE,QAAQ,MAAM,EAAE;MACrE,IAAI,MAAM,WAAW,mBAAmB,GAC7C,SAAS,KAAK,iBAAiB,MAAM,QAAQ,qBAAqB,EAAE,EAAE,QAAQ,MAAM,EAAE;MACjF,IAAI,MAAM,MAAM,kCAAkC,GAEvD,SAAS,KAAK,YAAY,MAAM,QAAQ,uBAAuB,EAAE,EAAE,QAAQ,MAAM,EAAE;MAC9E,IAAI,MAAM,MAAM,qCAAqC,GAC1D,SAAS,KAAK,UAAU,MAAM,QAAQ,cAAc,EAAE,CAAC,CAAC,QAAQ,cAAc,EAAE,EAAE,QAAQ,MAAM,EAAE;MAC7F,IAAI,MAAM,MAAM,iBAAiB,GACtC,SAAS,KAAK,aAAa,MAAM,QAAQ,cAAc,EAAE,EAAE,QAAQ,MAAM,EAAE;CAwB/E,OAAO,WAAW,SAAS,KAAK,QAAQ,OAAO,IAAI,EAAE,CAAC,CAAC,KAAK,EAAE,EAAE;;;;;;;;;;;;;;;;;;AAClE"}
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
import { OutputFile } from "../../types.js";
|
|
2
|
+
import { ProcessReturn } from "../platform.js";
|
|
3
|
+
|
|
4
|
+
//#region src/tokens/process/output/theme.d.ts
|
|
5
|
+
declare const defaultFileHeader: string;
|
|
6
|
+
type CreateThemeCSSFiles = {
|
|
7
|
+
/** The processed build results containing formatted CSS outputs grouped by themes and other permutations. */processedBuilds: ProcessReturn; /** Optional header to be included in the generated CSS files. */
|
|
8
|
+
fileHeader?: string;
|
|
9
|
+
};
|
|
10
|
+
/**
|
|
11
|
+
* Generates theme-specific CSS files from Style Dictionary build results.
|
|
12
|
+
*
|
|
13
|
+
* @param processedBuilds - The processed build results containing formatted CSS outputs
|
|
14
|
+
* grouped by themes and other permutations.
|
|
15
|
+
* @param fileHeader - Optional header to be included in the generated CSS files.
|
|
16
|
+
* @returns An array of `OutputFile` objects, each representing a theme-specific CSS file
|
|
17
|
+
* with its destination and content.
|
|
18
|
+
*
|
|
19
|
+
* @remarks
|
|
20
|
+
* - The function groups the build results by theme and ensures a deterministic order
|
|
21
|
+
* for the sections of the entry CSS file using a predefined sort order.
|
|
22
|
+
* - If a CSS section does not have a defined sort order the section is added to the end of the entry file.
|
|
23
|
+
* - The generated CSS files include a header with metadata and layer definitions.
|
|
24
|
+
*/
|
|
25
|
+
declare const createThemeCSSFiles: ({
|
|
26
|
+
processedBuilds,
|
|
27
|
+
fileHeader
|
|
28
|
+
}: CreateThemeCSSFiles) => OutputFile[];
|
|
29
|
+
//#endregion
|
|
30
|
+
export { createThemeCSSFiles, defaultFileHeader };
|
|
31
|
+
//# sourceMappingURL=theme.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"theme.d.ts","names":[],"sources":["../../../../../src/tokens/process/output/theme.ts"],"mappings":";;;;cAOa,iBAAA;AAAA,KAER,mBAAA;EAFQ,6GAIX,eAAA,EAAiB,aAAa;EAE9B,UAAA;AAAA;AANwD;;;;;;;;AAM9C;AAuBZ;;;;;;AA7B0D,cA6B7C,mBAAA;EAAuB,eAAA;EAAA;AAAA,GAGjC,mBAAA,KAAsB,UAAA"}
|