@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.
Files changed (195) hide show
  1. package/LICENSE +7 -0
  2. package/README.md +115 -0
  3. package/configs/test-tokens.config.json +82 -0
  4. package/dist/bin/config.d.ts +12 -0
  5. package/dist/bin/config.d.ts.map +1 -0
  6. package/dist/bin/config.js +58 -0
  7. package/dist/bin/designsystemet.d.ts +3 -0
  8. package/dist/bin/designsystemet.d.ts.map +1 -0
  9. package/dist/bin/designsystemet.js +156 -0
  10. package/dist/bin/options.d.ts +21 -0
  11. package/dist/bin/options.d.ts.map +1 -0
  12. package/dist/bin/options.js +23 -0
  13. package/dist/config.schema.json +209 -0
  14. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js +9 -0
  15. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js +8 -0
  16. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js +13 -0
  17. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js +10 -0
  18. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js +10 -0
  19. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js +53 -0
  20. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js +14 -0
  21. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js +9 -0
  22. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js +32 -0
  23. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js +15 -0
  24. package/dist/node_modules/.pnpm/@tokens-studio_types@0.5.2/node_modules/@tokens-studio/types/dist/types/index.js +11 -0
  25. package/dist/package.js +5 -0
  26. package/dist/src/colors/colorMetadata.d.ts +56 -0
  27. package/dist/src/colors/colorMetadata.d.ts.map +1 -0
  28. package/dist/src/colors/colorMetadata.js +259 -0
  29. package/dist/src/colors/index.d.ts +5 -0
  30. package/dist/src/colors/index.d.ts.map +1 -0
  31. package/dist/src/colors/index.js +5 -0
  32. package/dist/src/colors/theme.d.ts +30 -0
  33. package/dist/src/colors/theme.d.ts.map +1 -0
  34. package/dist/src/colors/theme.js +111 -0
  35. package/dist/src/colors/types.d.ts +69 -0
  36. package/dist/src/colors/types.d.ts.map +1 -0
  37. package/dist/src/colors/types.js +24 -0
  38. package/dist/src/colors/utils.d.ts +128 -0
  39. package/dist/src/colors/utils.d.ts.map +1 -0
  40. package/dist/src/colors/utils.js +244 -0
  41. package/dist/src/config.d.ts +181 -0
  42. package/dist/src/config.d.ts.map +1 -0
  43. package/dist/src/config.js +118 -0
  44. package/dist/src/index.d.ts +4 -0
  45. package/dist/src/index.d.ts.map +1 -0
  46. package/dist/src/index.js +10 -0
  47. package/dist/src/migrations/beta-to-v1.d.ts +3 -0
  48. package/dist/src/migrations/beta-to-v1.d.ts.map +1 -0
  49. package/dist/src/migrations/beta-to-v1.js +340 -0
  50. package/dist/src/migrations/codemods/css/plugins.d.ts +6 -0
  51. package/dist/src/migrations/codemods/css/plugins.d.ts.map +1 -0
  52. package/dist/src/migrations/codemods/css/plugins.js +35 -0
  53. package/dist/src/migrations/codemods/css/run.d.ts +8 -0
  54. package/dist/src/migrations/codemods/css/run.d.ts.map +1 -0
  55. package/dist/src/migrations/codemods/css/run.js +23 -0
  56. package/dist/src/migrations/color-rename-next49.d.ts +3 -0
  57. package/dist/src/migrations/color-rename-next49.d.ts.map +1 -0
  58. package/dist/src/migrations/color-rename-next49.js +46 -0
  59. package/dist/src/migrations/index.d.ts +6 -0
  60. package/dist/src/migrations/index.d.ts.map +1 -0
  61. package/dist/src/migrations/index.js +9 -0
  62. package/dist/src/scripts/createJsonSchema.d.ts +2 -0
  63. package/dist/src/scripts/createJsonSchema.d.ts.map +1 -0
  64. package/dist/src/scripts/update-preview-tokens.d.ts +3 -0
  65. package/dist/src/scripts/update-preview-tokens.d.ts.map +1 -0
  66. package/dist/src/tokens/build.d.ts +4 -0
  67. package/dist/src/tokens/build.d.ts.map +1 -0
  68. package/dist/src/tokens/build.js +41 -0
  69. package/dist/src/tokens/create/files.d.ts +11 -0
  70. package/dist/src/tokens/create/files.d.ts.map +1 -0
  71. package/dist/src/tokens/create/files.js +44 -0
  72. package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
  73. package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
  74. package/dist/src/tokens/create/generators/$designsystemet.js +10 -0
  75. package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
  76. package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
  77. package/dist/src/tokens/create/generators/$metadata.js +19 -0
  78. package/dist/src/tokens/create/generators/$themes.d.ts +27 -0
  79. package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
  80. package/dist/src/tokens/create/generators/$themes.js +158 -0
  81. package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts +5 -0
  82. package/dist/src/tokens/create/generators/primitives/color-scheme.d.ts.map +1 -0
  83. package/dist/src/tokens/create/generators/primitives/color-scheme.js +71 -0
  84. package/dist/src/tokens/create/generators/primitives/globals.d.ts +3 -0
  85. package/dist/src/tokens/create/generators/primitives/globals.d.ts.map +1 -0
  86. package/dist/src/tokens/create/generators/primitives/globals.js +142 -0
  87. package/dist/src/tokens/create/generators/primitives/size.d.ts +4 -0
  88. package/dist/src/tokens/create/generators/primitives/size.d.ts.map +1 -0
  89. package/dist/src/tokens/create/generators/primitives/size.js +147 -0
  90. package/dist/src/tokens/create/generators/primitives/typography.d.ts +4 -0
  91. package/dist/src/tokens/create/generators/primitives/typography.d.ts.map +1 -0
  92. package/dist/src/tokens/create/generators/primitives/typography.js +216 -0
  93. package/dist/src/tokens/create/generators/semantic/color-modes.d.ts +8 -0
  94. package/dist/src/tokens/create/generators/semantic/color-modes.d.ts.map +1 -0
  95. package/dist/src/tokens/create/generators/semantic/color-modes.js +26 -0
  96. package/dist/src/tokens/create/generators/semantic/color.d.ts +5 -0
  97. package/dist/src/tokens/create/generators/semantic/color.d.ts.map +1 -0
  98. package/dist/src/tokens/create/generators/semantic/color.js +46 -0
  99. package/dist/src/tokens/create/generators/semantic/style.d.ts +3 -0
  100. package/dist/src/tokens/create/generators/semantic/style.d.ts.map +1 -0
  101. package/dist/src/tokens/create/generators/semantic/style.js +381 -0
  102. package/dist/src/tokens/create/generators/themes/theme.d.ts +3 -0
  103. package/dist/src/tokens/create/generators/themes/theme.d.ts.map +1 -0
  104. package/dist/src/tokens/create/generators/themes/theme.js +112 -0
  105. package/dist/src/tokens/create.d.ts +21 -0
  106. package/dist/src/tokens/create.d.ts.map +1 -0
  107. package/dist/src/tokens/create.js +47 -0
  108. package/dist/src/tokens/format.d.ts +15 -0
  109. package/dist/src/tokens/format.d.ts.map +1 -0
  110. package/dist/src/tokens/format.js +41 -0
  111. package/dist/src/tokens/generate-config.d.ts +10 -0
  112. package/dist/src/tokens/generate-config.d.ts.map +1 -0
  113. package/dist/src/tokens/generate-config.js +178 -0
  114. package/dist/src/tokens/index.d.ts +4 -0
  115. package/dist/src/tokens/index.d.ts.map +1 -0
  116. package/dist/src/tokens/index.js +3 -0
  117. package/dist/src/tokens/process/configs/color.d.ts +12 -0
  118. package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
  119. package/dist/src/tokens/process/configs/color.js +51 -0
  120. package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
  121. package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
  122. package/dist/src/tokens/process/configs/semantic.js +47 -0
  123. package/dist/src/tokens/process/configs/shared.d.ts +10 -0
  124. package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
  125. package/dist/src/tokens/process/configs/shared.js +19 -0
  126. package/dist/src/tokens/process/configs/size-mode.d.ts +3 -0
  127. package/dist/src/tokens/process/configs/size-mode.d.ts.map +1 -0
  128. package/dist/src/tokens/process/configs/size-mode.js +28 -0
  129. package/dist/src/tokens/process/configs/size.d.ts +3 -0
  130. package/dist/src/tokens/process/configs/size.d.ts.map +1 -0
  131. package/dist/src/tokens/process/configs/size.js +34 -0
  132. package/dist/src/tokens/process/configs/type-scale.d.ts +3 -0
  133. package/dist/src/tokens/process/configs/type-scale.d.ts.map +1 -0
  134. package/dist/src/tokens/process/configs/type-scale.js +49 -0
  135. package/dist/src/tokens/process/configs/typography.d.ts +3 -0
  136. package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
  137. package/dist/src/tokens/process/configs/typography.js +64 -0
  138. package/dist/src/tokens/process/configs.d.ts +20 -0
  139. package/dist/src/tokens/process/configs.d.ts.map +1 -0
  140. package/dist/src/tokens/process/configs.js +90 -0
  141. package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
  142. package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
  143. package/dist/src/tokens/process/formats/css/color.js +63 -0
  144. package/dist/src/tokens/process/formats/css/semantic.d.ts +3 -0
  145. package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
  146. package/dist/src/tokens/process/formats/css/semantic.js +29 -0
  147. package/dist/src/tokens/process/formats/css/size-mode.d.ts +4 -0
  148. package/dist/src/tokens/process/formats/css/size-mode.d.ts.map +1 -0
  149. package/dist/src/tokens/process/formats/css/size-mode.js +50 -0
  150. package/dist/src/tokens/process/formats/css/size.d.ts +21 -0
  151. package/dist/src/tokens/process/formats/css/size.d.ts.map +1 -0
  152. package/dist/src/tokens/process/formats/css/size.js +93 -0
  153. package/dist/src/tokens/process/formats/css/type-scale.d.ts +3 -0
  154. package/dist/src/tokens/process/formats/css/type-scale.d.ts.map +1 -0
  155. package/dist/src/tokens/process/formats/css/type-scale.js +55 -0
  156. package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
  157. package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
  158. package/dist/src/tokens/process/formats/css/typography.js +29 -0
  159. package/dist/src/tokens/process/formats/css.d.ts +11 -0
  160. package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
  161. package/dist/src/tokens/process/formats/css.js +18 -0
  162. package/dist/src/tokens/process/output/declarations.d.ts +5 -0
  163. package/dist/src/tokens/process/output/declarations.d.ts.map +1 -0
  164. package/dist/src/tokens/process/output/declarations.js +38 -0
  165. package/dist/src/tokens/process/output/tailwind.d.ts +3 -0
  166. package/dist/src/tokens/process/output/tailwind.d.ts.map +1 -0
  167. package/dist/src/tokens/process/output/tailwind.js +45 -0
  168. package/dist/src/tokens/process/output/theme.d.ts +27 -0
  169. package/dist/src/tokens/process/output/theme.d.ts.map +1 -0
  170. package/dist/src/tokens/process/output/theme.js +83 -0
  171. package/dist/src/tokens/process/platform.d.ts +106 -0
  172. package/dist/src/tokens/process/platform.d.ts.map +1 -0
  173. package/dist/src/tokens/process/platform.js +168 -0
  174. package/dist/src/tokens/process/transformers.d.ts +6 -0
  175. package/dist/src/tokens/process/transformers.d.ts.map +1 -0
  176. package/dist/src/tokens/process/transformers.js +54 -0
  177. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts +36 -0
  178. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
  179. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +114 -0
  180. package/dist/src/tokens/process/utils/kebab-case.d.ts +5 -0
  181. package/dist/src/tokens/process/utils/kebab-case.d.ts.map +1 -0
  182. package/dist/src/tokens/process/utils/kebab-case.js +9 -0
  183. package/dist/src/tokens/types.d.ts +74 -0
  184. package/dist/src/tokens/types.d.ts.map +1 -0
  185. package/dist/src/tokens/types.js +7 -0
  186. package/dist/src/tokens/utils.d.ts +63 -0
  187. package/dist/src/tokens/utils.d.ts.map +1 -0
  188. package/dist/src/tokens/utils.js +121 -0
  189. package/dist/src/types.d.ts +6 -0
  190. package/dist/src/types.d.ts.map +1 -0
  191. package/dist/src/types.js +2 -0
  192. package/dist/src/utils/filesystem.d.ts +40 -0
  193. package/dist/src/utils/filesystem.d.ts.map +1 -0
  194. package/dist/src/utils/filesystem.js +115 -0
  195. package/package.json +87 -0
@@ -0,0 +1,29 @@
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 };
@@ -0,0 +1,11 @@
1
+ import type { Format } from 'style-dictionary/types';
2
+ export declare const formats: {
3
+ colorScheme: Format;
4
+ colorCategory: Format;
5
+ semantic: Format;
6
+ sizeMode: Format;
7
+ size: Format;
8
+ typography: Format;
9
+ typeScale: Format;
10
+ };
11
+ //# sourceMappingURL=css.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/formats/css.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AASrD,eAAO,MAAM,OAAO;;;;;;;;CAQc,CAAC"}
@@ -0,0 +1,18 @@
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 };
@@ -0,0 +1,5 @@
1
+ import type { OutputFile } from '../../types.js';
2
+ import { type ProcessedThemeObject } from '../utils/getMultidimensionalThemes.js';
3
+ export declare const defaultFileHeader: string;
4
+ export declare const createTypeDeclarationFiles: (processed$themes: ProcessedThemeObject[]) => OutputFile[];
5
+ //# sourceMappingURL=declarations.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"declarations.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/output/declarations.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,uCAAuC,CAAC;AAEnG,eAAO,MAAM,iBAAiB,QAA2B,CAAC;AAE1D,eAAO,MAAM,0BAA0B,GAAI,kBAAkB,oBAAoB,EAAE,KAAG,UAAU,EAe/F,CAAC"}
@@ -0,0 +1,38 @@
1
+ import { version } from "../../../../package.js";
2
+ import { getCustomColors } from "../utils/getMultidimensionalThemes.js";
3
+ import { buildOptions } from "../platform.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([...getCustomColors(processed$themes, buildOptions?.colorGroups || []), "neutral"]);
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
+ return `
20
+ /* ${defaultFileHeader} */
21
+ import type {} from '@digdir/designsystemet-types';
22
+
23
+ // Augment types based on theme
24
+ declare module '@digdir/designsystemet-types' {
25
+ export interface ColorDefinitions {
26
+ ${colors.map((color) => ` ${color.includes("-") ? `'${color}'` : color}: never;`).join("\n")}
27
+ }
28
+ export interface SeverityColorDefinitions {
29
+ info: never;
30
+ success: never;
31
+ warning: never;
32
+ danger: never;
33
+ }
34
+ }
35
+ `.trimStart();
36
+ }
37
+ //#endregion
38
+ export { createTypeDeclarationFiles, defaultFileHeader };
@@ -0,0 +1,3 @@
1
+ import type { OutputFile } from '../../types.js';
2
+ export declare const createTailwindCSSFiles: (cssFiles: OutputFile[]) => OutputFile[];
3
+ //# sourceMappingURL=tailwind.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tailwind.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/output/tailwind.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,eAAO,MAAM,sBAAsB,GAAI,UAAU,UAAU,EAAE,KAAG,UAAU,EAezE,CAAC"}
@@ -0,0 +1,45 @@
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 };
@@ -0,0 +1,27 @@
1
+ import type { OutputFile } from '../../types.js';
2
+ import type { ProcessReturn } from '../platform.js';
3
+ export declare const defaultFileHeader: string;
4
+ type CreateThemeCSSFiles = {
5
+ /** The processed build results containing formatted CSS outputs grouped by themes and other permutations. */
6
+ processedBuilds: ProcessReturn;
7
+ /** 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
+ export declare const createThemeCSSFiles: ({ processedBuilds, fileHeader, }: CreateThemeCSSFiles) => OutputFile[];
26
+ export {};
27
+ //# sourceMappingURL=theme.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"theme.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/output/theme.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAEjD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAEpD,eAAO,MAAM,iBAAiB,QAA2B,CAAC;AAE1D,KAAK,mBAAmB,GAAG;IACzB,6GAA6G;IAC7G,eAAe,EAAE,aAAa,CAAC;IAC/B,iEAAiE;IACjE,UAAU,CAAC,EAAE,MAAM,CAAC;CACrB,CAAC;AAOF;;;;;;;;;;;;;;GAcG;AACH,eAAO,MAAM,mBAAmB,GAAI,kCAGjC,mBAAmB,KAAG,UAAU,EAqFlC,CAAC"}
@@ -0,0 +1,83 @@
1
+ import { version } from "../../../../package.js";
2
+ import { sizeComparator } from "../../utils.js";
3
+ import pc from "picocolors";
4
+ import * as R from "ramda";
5
+ //#region src/tokens/process/output/theme.ts
6
+ const defaultFileHeader = `build: v${version}`;
7
+ const getFileNameWithoutExtension = (path) => {
8
+ const pathSegments = path.split("/");
9
+ return pathSegments[pathSegments.length - 1].split(".").slice(0, -1).join(".");
10
+ };
11
+ /**
12
+ * Generates theme-specific CSS files from Style Dictionary build results.
13
+ *
14
+ * @param processedBuilds - The processed build results containing formatted CSS outputs
15
+ * grouped by themes and other permutations.
16
+ * @param fileHeader - Optional header to be included in the generated CSS files.
17
+ * @returns An array of `OutputFile` objects, each representing a theme-specific CSS file
18
+ * with its destination and content.
19
+ *
20
+ * @remarks
21
+ * - The function groups the build results by theme and ensures a deterministic order
22
+ * for the sections of the entry CSS file using a predefined sort order.
23
+ * - If a CSS section does not have a defined sort order the section is added to the end of the entry file.
24
+ * - The generated CSS files include a header with metadata and layer definitions.
25
+ */
26
+ const createThemeCSSFiles = ({ processedBuilds, fileHeader = defaultFileHeader }) => {
27
+ const groupedByTheme = {};
28
+ for (const [_, buildResults] of Object.entries(processedBuilds)) for (const buildResult of buildResults) {
29
+ const themeName = buildResult.permutation.theme;
30
+ const newOutputs = buildResult.formatted;
31
+ if (R.isNotEmpty(newOutputs)) {
32
+ const currentOutputs = groupedByTheme[themeName] ?? [];
33
+ groupedByTheme[themeName] = R.concat(currentOutputs, newOutputs);
34
+ }
35
+ }
36
+ /**
37
+ * Defines a sort order for the sections of the entry CSS file.
38
+ * This ensures a deterministic order, whereas earlier this was nondeterministic
39
+ */
40
+ const sortOrder = [
41
+ "size-mode/",
42
+ "type-scale",
43
+ "color-scheme/light",
44
+ "typography/secondary",
45
+ "size",
46
+ "semantic",
47
+ "color-scheme/dark",
48
+ "color-scheme/contrast",
49
+ "typography/primary",
50
+ "color/"
51
+ ];
52
+ const sortByDefinedOrder = R.sortBy((file) => {
53
+ const filePath = file.destination || "";
54
+ const sortIndex = sortOrder.findIndex((sortElement) => {
55
+ if (sortElement.endsWith("/")) return filePath.includes(sortElement);
56
+ return filePath.includes(`${sortElement}.css`);
57
+ });
58
+ if (sortIndex === -1) {
59
+ console.error(pc.yellow(`WARNING: CSS section does not have a defined sort order: ${filePath.replace(".css", "")}`));
60
+ console.log(pc.dim(`
61
+ The section will currently be added to the end of the entry file, but the exact
62
+ order may change due to nondeterminism.`.trim()));
63
+ return Infinity;
64
+ }
65
+ return sortIndex;
66
+ });
67
+ const header = `@charset "UTF-8";
68
+ /*
69
+ ${fileHeader}
70
+ */
71
+
72
+ `;
73
+ const sortAlphabetically = R.sort(R.ascend((x) => x.destination || ""));
74
+ const sortBySize = R.sortBy(R.pipe((s) => getFileNameWithoutExtension(s.destination ?? ""), sizeComparator));
75
+ const pickOutputs = R.map(R.view(R.lensProp("output")));
76
+ const themeCSSFile = R.pipe(sortAlphabetically, sortBySize, sortByDefinedOrder, pickOutputs, R.join("\n"), (content) => header + content);
77
+ return Object.entries(groupedByTheme).map(([theme, files]) => ({
78
+ destination: `${theme}.css`,
79
+ output: themeCSSFile(files)
80
+ }));
81
+ };
82
+ //#endregion
83
+ export { createThemeCSSFiles, defaultFileHeader };
@@ -0,0 +1,106 @@
1
+ import type { TransformedToken } from 'style-dictionary/types';
2
+ import type { OutputFile, TokenSet } from '../types.js';
3
+ import { type ThemePermutation } from '../types.js';
4
+ import { type ProcessedThemeObject } from './utils/getMultidimensionalThemes.js';
5
+ type SharedOptions = {
6
+ /** Enable verbose output */
7
+ verbose: boolean;
8
+ /** Set the default color for ":root" */
9
+ defaultColor?: string;
10
+ /** Set the default size mode */
11
+ defaultSize?: string;
12
+ /** Set the available size modes */
13
+ sizeModes?: string[];
14
+ /** Token Studio `$themes.json` content */
15
+ processed$themes: ProcessedThemeObject[];
16
+ /** Color groups */
17
+ colorGroups?: string[];
18
+ /** Build token format map */
19
+ buildTokenFormats: Record<string, {
20
+ token: TransformedToken;
21
+ formatted: string;
22
+ }[]>;
23
+ };
24
+ export type BuildOptions = {
25
+ type: 'build';
26
+ /** Design tokens path */
27
+ tokensDir: string;
28
+ /** Tailwind CSS configuration */
29
+ tailwind?: boolean;
30
+ } & SharedOptions;
31
+ export type FormatOptions = {
32
+ type: 'format';
33
+ /** Tokensets */
34
+ tokenSets: Map<string, TokenSet>;
35
+ } & SharedOptions;
36
+ export type ProcessOptions = BuildOptions | FormatOptions;
37
+ type ProcessedBuildConfigs<T> = Record<keyof typeof buildConfigs, T>;
38
+ export type ProcessReturn = ProcessedBuildConfigs<BuildResult[]>;
39
+ type BuildResult = {
40
+ permutation: ThemePermutation;
41
+ formatted: OutputFile[];
42
+ tokens: TransformedToken[];
43
+ };
44
+ export declare let buildOptions: SharedOptions;
45
+ declare const buildConfigs: {
46
+ typography: {
47
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
48
+ dimensions: "typography"[];
49
+ };
50
+ sizeMode: {
51
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
52
+ dimensions: "size"[];
53
+ };
54
+ size: {
55
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
56
+ dimensions: "semantic"[];
57
+ };
58
+ typeScale: {
59
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
60
+ dimensions: "semantic"[];
61
+ };
62
+ 'color-scheme': {
63
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
64
+ dimensions: "color-scheme"[];
65
+ };
66
+ 'main-color': {
67
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
68
+ dimensions: "main-color"[];
69
+ };
70
+ 'support-color': {
71
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
72
+ dimensions: "support-color"[];
73
+ };
74
+ 'neutral-color': {
75
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
76
+ dimensions: "semantic"[];
77
+ log: ({ permutation: { theme } }: import("../types.js").SDConfigForThemePermutation) => string;
78
+ };
79
+ 'success-color': {
80
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
81
+ dimensions: "semantic"[];
82
+ log: ({ permutation: { theme } }: import("../types.js").SDConfigForThemePermutation) => string;
83
+ };
84
+ 'danger-color': {
85
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
86
+ dimensions: "semantic"[];
87
+ log: ({ permutation: { theme } }: import("../types.js").SDConfigForThemePermutation) => string;
88
+ };
89
+ 'warning-color': {
90
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
91
+ dimensions: "semantic"[];
92
+ log: ({ permutation: { theme } }: import("../types.js").SDConfigForThemePermutation) => string;
93
+ };
94
+ 'info-color': {
95
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
96
+ dimensions: "semantic"[];
97
+ log: ({ permutation: { theme } }: import("../types.js").SDConfigForThemePermutation) => string;
98
+ };
99
+ semantic: {
100
+ getConfig: import("./configs/shared.js").GetStyleDictionaryConfig;
101
+ dimensions: "semantic"[];
102
+ };
103
+ };
104
+ export declare function processPlatform(options: ProcessOptions): Promise<ProcessReturn>;
105
+ export {};
106
+ //# sourceMappingURL=platform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"platform.d.ts","sourceRoot":"","sources":["../../../../src/tokens/process/platform.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAC/D,OAAO,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,aAAa,CAAC;AACxD,OAAO,EAAqC,KAAK,gBAAgB,EAAE,MAAM,aAAa,CAAC;AAEvF,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,sCAAsC,CAAC;AAElG,KAAK,aAAa,GAAG;IACnB,4BAA4B;IAC5B,OAAO,EAAE,OAAO,CAAC;IACjB,wCAAwC;IACxC,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,gCAAgC;IAChC,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,mCAAmC;IACnC,SAAS,CAAC,EAAE,MAAM,EAAE,CAAC;IACrB,0CAA0C;IAC1C,gBAAgB,EAAE,oBAAoB,EAAE,CAAC;IACzC,mBAAmB;IACnB,WAAW,CAAC,EAAE,MAAM,EAAE,CAAC;IACvB,6BAA6B;IAC7B,iBAAiB,EAAE,MAAM,CAAC,MAAM,EAAE;QAAE,KAAK,EAAE,gBAAgB,CAAC;QAAC,SAAS,EAAE,MAAM,CAAA;KAAE,EAAE,CAAC,CAAC;CACrF,CAAC;AAEF,MAAM,MAAM,YAAY,GAAG;IACzB,IAAI,EAAE,OAAO,CAAC;IACd,yBAAyB;IACzB,SAAS,EAAE,MAAM,CAAC;IAClB,iCAAiC;IACjC,QAAQ,CAAC,EAAE,OAAO,CAAC;CACpB,GAAG,aAAa,CAAC;AAElB,MAAM,MAAM,aAAa,GAAG;IAC1B,IAAI,EAAE,QAAQ,CAAC;IACf,gBAAgB;IAChB,SAAS,EAAE,GAAG,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;CAClC,GAAG,aAAa,CAAC;AAElB,MAAM,MAAM,cAAc,GAAG,YAAY,GAAG,aAAa,CAAC;AAE1D,KAAK,qBAAqB,CAAC,CAAC,IAAI,MAAM,CAAC,MAAM,OAAO,YAAY,EAAE,CAAC,CAAC,CAAC;AAErE,MAAM,MAAM,aAAa,GAAG,qBAAqB,CAAC,WAAW,EAAE,CAAC,CAAC;AAEjE,KAAK,WAAW,GAAG;IACjB,WAAW,EAAE,gBAAgB,CAAC;IAC9B,SAAS,EAAE,UAAU,EAAE,CAAC;IACxB,MAAM,EAAE,gBAAgB,EAAE,CAAC;CAC5B,CAAC;AAgBF,eAAO,IAAI,YAAY,EAAE,aAIxB,CAAC;AAOF,QAAA,MAAM,YAAY;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;CAkCqB,CAAC;AAExC,wBAAsB,eAAe,CAAC,OAAO,EAAE,cAAc,GAAG,OAAO,CAAC,aAAa,CAAC,CA2IrF"}
@@ -0,0 +1,168 @@
1
+ import { colorCategories } from "../types.js";
2
+ import { getCustomColors } from "./utils/getMultidimensionalThemes.js";
3
+ import { configs, getConfigsForThemeDimensions } from "./configs.js";
4
+ import pc from "picocolors";
5
+ import * as R from "ramda";
6
+ import StyleDictionary from "style-dictionary";
7
+ //#region src/tokens/process/platform.ts
8
+ const initResult = {
9
+ formatted: [],
10
+ tokens: [],
11
+ permutation: {
12
+ "color-scheme": "",
13
+ "main-color": "",
14
+ "support-color": "",
15
+ semantic: "",
16
+ size: "",
17
+ theme: "",
18
+ typography: ""
19
+ }
20
+ };
21
+ let buildOptions = {
22
+ verbose: false,
23
+ processed$themes: [],
24
+ buildTokenFormats: {}
25
+ };
26
+ const sd = new StyleDictionary();
27
+ const buildConfigs = {
28
+ typography: {
29
+ getConfig: configs.typographyVariables,
30
+ dimensions: ["typography"]
31
+ },
32
+ sizeMode: {
33
+ getConfig: configs.sizeModeVariables,
34
+ dimensions: ["size"]
35
+ },
36
+ size: {
37
+ getConfig: configs.sizeVariables,
38
+ dimensions: ["semantic"]
39
+ },
40
+ typeScale: {
41
+ getConfig: configs.typeScaleVariables,
42
+ dimensions: ["semantic"]
43
+ },
44
+ "color-scheme": {
45
+ getConfig: configs.colorSchemeVariables,
46
+ dimensions: ["color-scheme"]
47
+ },
48
+ "main-color": {
49
+ getConfig: configs.mainColorVariables,
50
+ dimensions: ["main-color"]
51
+ },
52
+ "support-color": {
53
+ getConfig: configs.supportColorVariables,
54
+ dimensions: ["support-color"]
55
+ },
56
+ "neutral-color": {
57
+ getConfig: configs.neutralColorVariables,
58
+ dimensions: ["semantic"],
59
+ log: ({ permutation: { theme } }) => `${theme} - neutral`
60
+ },
61
+ "success-color": {
62
+ getConfig: configs.successColorVariables,
63
+ dimensions: ["semantic"],
64
+ log: ({ permutation: { theme } }) => `${theme} - success`
65
+ },
66
+ "danger-color": {
67
+ getConfig: configs.dangerColorVariables,
68
+ dimensions: ["semantic"],
69
+ log: ({ permutation: { theme } }) => `${theme} - danger`
70
+ },
71
+ "warning-color": {
72
+ getConfig: configs.warningColorVariables,
73
+ dimensions: ["semantic"],
74
+ log: ({ permutation: { theme } }) => `${theme} - warning`
75
+ },
76
+ "info-color": {
77
+ getConfig: configs.infoColorVariables,
78
+ dimensions: ["semantic"],
79
+ log: ({ permutation: { theme } }) => `${theme} - info`
80
+ },
81
+ semantic: {
82
+ getConfig: configs.semanticVariables,
83
+ dimensions: ["semantic"]
84
+ }
85
+ };
86
+ async function processPlatform(options) {
87
+ const { type, processed$themes } = options;
88
+ const platform = "css";
89
+ const tokenSets = type === "format" ? options.tokenSets : void 0;
90
+ const tokensDir = type === "build" ? options.tokensDir : void 0;
91
+ const UNSAFE_DEFAULT_COLOR = process.env.UNSAFE_DEFAULT_COLOR ?? "";
92
+ if (UNSAFE_DEFAULT_COLOR) console.warn(pc.yellow(`\n⚠️ UNSAFE_DEFAULT_COLOR is set to ${pc.blue(UNSAFE_DEFAULT_COLOR)}. This will override the default color.`));
93
+ const UNSAFE_COLOR_GROUPS = Array.from(process.env.UNSAFE_COLOR_GROUPS?.split(",") ?? []);
94
+ if (UNSAFE_COLOR_GROUPS.length > 0) console.warn(pc.yellow(`\n⚠️ UNSAFE_COLOR_GROUPS is set to ${pc.blue(`[${UNSAFE_COLOR_GROUPS.join(", ")}]`)}. This will override the default color groups.`));
95
+ const colorGroups = UNSAFE_COLOR_GROUPS.length > 0 ? UNSAFE_COLOR_GROUPS : [colorCategories.main, colorCategories.support].map((c) => `${c}-color`);
96
+ /** For sharing build options in other files */
97
+ buildOptions = options;
98
+ buildOptions.defaultColor = UNSAFE_DEFAULT_COLOR;
99
+ buildOptions.colorGroups = colorGroups;
100
+ if (!buildOptions.defaultColor) {
101
+ const customColors = getCustomColors(processed$themes, colorGroups);
102
+ const firstMainColor = R.head(customColors);
103
+ buildOptions.defaultColor = firstMainColor;
104
+ }
105
+ if (buildOptions.defaultColor) console.log(`\n🎨 Using ${pc.blue(buildOptions.defaultColor)} as default color`);
106
+ const sizeModes = processed$themes.filter((x) => x.group === "size").map((x) => x.name);
107
+ buildOptions.sizeModes = sizeModes;
108
+ if (!buildOptions.defaultSize) {
109
+ const defaultSize = R.head(sizeModes);
110
+ buildOptions.defaultSize = defaultSize;
111
+ }
112
+ if (buildOptions.defaultSize) console.log(`\n📏 Using ${pc.blue(buildOptions.defaultSize)} as default size`);
113
+ const buildAndSdConfigs = R.map((buildConfig) => {
114
+ const sdConfigs = getConfigsForThemeDimensions(buildConfig.getConfig, processed$themes, buildConfig.dimensions, {
115
+ tokensDir,
116
+ tokenSets
117
+ });
118
+ const unknownConfigs = buildConfig.dimensions.map((dimension) => sdConfigs.filter((x) => x.permutation[dimension] === "unknown"));
119
+ for (const unknowns of unknownConfigs) if (unknowns.length === sdConfigs.length) buildConfig.enabled = () => false;
120
+ return {
121
+ buildConfig,
122
+ sdConfigs
123
+ };
124
+ }, buildConfigs);
125
+ const processedBuilds = {
126
+ "color-scheme": [initResult],
127
+ "main-color": [initResult],
128
+ "support-color": [initResult],
129
+ "neutral-color": [initResult],
130
+ "success-color": [initResult],
131
+ "danger-color": [initResult],
132
+ "warning-color": [initResult],
133
+ "info-color": [initResult],
134
+ semantic: [initResult],
135
+ typography: [initResult],
136
+ sizeMode: [initResult],
137
+ size: [initResult],
138
+ typeScale: [initResult]
139
+ };
140
+ try {
141
+ for (const [buildName, { buildConfig, sdConfigs }] of R.toPairs(buildAndSdConfigs)) {
142
+ if (!(buildConfig.enabled?.() ?? true)) continue;
143
+ if (sdConfigs.length > 0) {
144
+ console.log(`\n🍱 Building ${pc.green(buildConfig.name ?? buildName)}`);
145
+ processedBuilds[buildName] = await Promise.all(sdConfigs.map(async (sdConfig) => {
146
+ const { config, permutation } = sdConfig;
147
+ const modeMessage = ["theme", ...buildConfig.dimensions].map((x) => permutation[x]).join(" - ");
148
+ const logMessage = R.isNil(buildConfig.log) ? modeMessage : buildConfig?.log(sdConfig);
149
+ console.log(logMessage);
150
+ const sdOptions = { cache: true };
151
+ const sdExtended = await sd.extend(config);
152
+ const result = {
153
+ permutation,
154
+ formatted: await sdExtended.formatPlatform(platform, sdOptions),
155
+ tokens: (await sdExtended.getPlatformTokens(platform, sdOptions)).allTokens
156
+ };
157
+ return Promise.resolve(result);
158
+ }));
159
+ }
160
+ }
161
+ } catch (err) {
162
+ if (err instanceof Error) err.message = err.message.replace("log.verbosity \"verbose\" or use ", "");
163
+ throw err;
164
+ }
165
+ return processedBuilds;
166
+ }
167
+ //#endregion
168
+ export { buildOptions, processPlatform };
@@ -0,0 +1,6 @@
1
+ import type { Transform } from 'style-dictionary/types';
2
+ export declare const sizeRem: Transform;
3
+ export declare const typographyName: Transform;
4
+ export declare const resolveMath: Transform;
5
+ export declare const unitless: Transform;
6
+ //# sourceMappingURL=transformers.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../src/tokens/process/transformers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAMxD,eAAO,MAAM,OAAO,EAAE,SAyBrB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,SAS5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,SAWzB,CAAC;AAEF,eAAO,MAAM,QAAQ,EAAE,SAMtB,CAAC"}
@@ -0,0 +1,54 @@
1
+ import { getValue, pathStartsWithOneOf, typeEquals } from "../utils.js";
2
+ import * as R from "ramda";
3
+ import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
4
+ //#region src/tokens/process/transformers.ts
5
+ const isPx = R.test(/\b\d+px\b/g);
6
+ const sizeRem = {
7
+ name: "ds/size/toRem",
8
+ type: "value",
9
+ transitive: true,
10
+ filter: (token) => {
11
+ const hasWantedType = typeEquals(["dimension", "fontsize"], token);
12
+ const hasWantedPath = pathStartsWithOneOf(["border-radius", "font-size"], token);
13
+ return hasWantedType && hasWantedPath;
14
+ },
15
+ transform: (token, config) => {
16
+ const value = getValue(token);
17
+ if (isPx(value)) {
18
+ const baseFont = config.basePxFontSize || 16;
19
+ const size = parseInt(value, 10);
20
+ if (size === 0) return "0";
21
+ return `${size / baseFont}rem`;
22
+ }
23
+ return value;
24
+ }
25
+ };
26
+ const typographyName = {
27
+ name: "name/typography",
28
+ type: "name",
29
+ transitive: true,
30
+ filter: (token) => pathStartsWithOneOf(["typography"], token),
31
+ transform: (token) => {
32
+ return token.name.replace("-typography", "");
33
+ }
34
+ };
35
+ const resolveMath = {
36
+ name: "ds/resolveMath",
37
+ type: "value",
38
+ transitive: true,
39
+ filter: (token) => {
40
+ const isValidValue = ["string", "object"].includes(typeof getValue(token));
41
+ const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
42
+ return isValidValue && isTokenOfInterest;
43
+ },
44
+ transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
45
+ };
46
+ const unitless = {
47
+ name: "ds/unitless",
48
+ type: "value",
49
+ transitive: true,
50
+ filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
51
+ transform: (token) => parseInt(getValue(token), 10)
52
+ };
53
+ //#endregion
54
+ export { resolveMath, sizeRem, typographyName, unitless };