@digdir/designsystemet 1.0.3 → 1.0.4

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 (186) hide show
  1. package/dist/bin/designsystemet.js +4264 -45
  2. package/dist/bin/options.js +5 -4
  3. package/dist/src/colors/colorMetadata.js +5 -4
  4. package/dist/src/colors/index.js +470 -4
  5. package/dist/src/colors/theme.js +286 -20
  6. package/dist/src/colors/utils.js +16 -15
  7. package/dist/{bin → src}/config.d.ts +46 -1
  8. package/dist/src/config.d.ts.map +1 -0
  9. package/dist/src/config.js +377 -0
  10. package/dist/src/index.js +3666 -2
  11. package/dist/src/migrations/beta-to-v1.js +85 -4
  12. package/dist/src/migrations/codemods/css/plugins.js +5 -4
  13. package/dist/src/migrations/codemods/css/run.d.ts.map +1 -1
  14. package/dist/src/migrations/codemods/css/run.js +18 -4
  15. package/dist/src/migrations/color-rename-next49.js +77 -6
  16. package/dist/src/migrations/index.d.ts +0 -1
  17. package/dist/src/migrations/index.d.ts.map +1 -1
  18. package/dist/src/migrations/index.js +461 -6
  19. package/dist/src/scripts/createJsonSchema.js +1608 -4
  20. package/dist/src/scripts/update-design-tokens.d.ts +2 -0
  21. package/dist/src/scripts/update-design-tokens.d.ts.map +1 -0
  22. package/dist/src/scripts/update-design-tokens.js +36 -0
  23. package/dist/src/{tokens/template.d.ts → scripts/update-template.d.ts} +1 -1
  24. package/dist/src/scripts/update-template.d.ts.map +1 -0
  25. package/dist/src/scripts/update-template.js +1200 -0
  26. package/dist/src/tokens/build.d.ts +2 -19
  27. package/dist/src/tokens/build.d.ts.map +1 -1
  28. package/dist/src/tokens/build.js +1511 -70
  29. package/dist/src/tokens/create/defaults.d.ts +7 -0
  30. package/dist/src/tokens/create/defaults.d.ts.map +1 -0
  31. package/dist/src/tokens/create/defaults.js +994 -0
  32. package/dist/src/tokens/create/generators/$designsystemet.d.ts +5 -0
  33. package/dist/src/tokens/create/generators/$designsystemet.d.ts.map +1 -0
  34. package/dist/src/tokens/create/generators/$designsystemet.js +100 -0
  35. package/dist/src/tokens/create/generators/$metadata.d.ts +8 -0
  36. package/dist/src/tokens/create/generators/$metadata.d.ts.map +1 -0
  37. package/dist/src/tokens/{write/generate$metadata.js → create/generators/$metadata.js} +3 -2
  38. package/dist/src/tokens/create/generators/$themes.d.ts +12 -0
  39. package/dist/src/tokens/create/generators/$themes.d.ts.map +1 -0
  40. package/dist/src/tokens/create/generators/$themes.js +333 -0
  41. package/dist/src/tokens/create/generators/color.d.ts +5 -0
  42. package/dist/src/tokens/create/generators/color.d.ts.map +1 -0
  43. package/dist/src/tokens/create/generators/color.js +374 -0
  44. package/dist/src/tokens/create/generators/semantic.d.ts +296 -0
  45. package/dist/src/tokens/create/generators/semantic.d.ts.map +1 -0
  46. package/dist/src/tokens/create/generators/semantic.js +483 -0
  47. package/dist/src/tokens/create/generators/theme.d.ts +3 -0
  48. package/dist/src/tokens/create/generators/theme.d.ts.map +1 -0
  49. package/dist/src/tokens/create/generators/theme.js +168 -0
  50. package/dist/src/tokens/create/generators/typography.d.ts +3 -0
  51. package/dist/src/tokens/create/generators/typography.d.ts.map +1 -0
  52. package/dist/src/tokens/create/generators/typography.js +33 -0
  53. package/dist/src/tokens/{write.d.ts → create/write.d.ts} +2 -2
  54. package/dist/src/tokens/create/write.d.ts.map +1 -0
  55. package/dist/src/tokens/create/write.js +546 -0
  56. package/dist/src/tokens/create.d.ts +4 -2
  57. package/dist/src/tokens/create.d.ts.map +1 -1
  58. package/dist/src/tokens/create.js +2049 -59
  59. package/dist/src/tokens/format.d.ts +16 -0
  60. package/dist/src/tokens/format.d.ts.map +1 -0
  61. package/dist/src/tokens/format.js +3514 -0
  62. package/dist/src/tokens/index.d.ts +1 -0
  63. package/dist/src/tokens/index.d.ts.map +1 -1
  64. package/dist/src/tokens/index.js +3526 -2
  65. package/dist/src/tokens/process/configs/color.d.ts +12 -0
  66. package/dist/src/tokens/process/configs/color.d.ts.map +1 -0
  67. package/dist/src/tokens/process/configs/color.js +823 -0
  68. package/dist/src/tokens/process/configs/semantic.d.ts +3 -0
  69. package/dist/src/tokens/process/configs/semantic.d.ts.map +1 -0
  70. package/dist/src/tokens/process/configs/semantic.js +367 -0
  71. package/dist/src/tokens/process/configs/shared.d.ts +10 -0
  72. package/dist/src/tokens/process/configs/shared.d.ts.map +1 -0
  73. package/dist/src/tokens/process/configs/shared.js +99 -0
  74. package/dist/src/tokens/process/configs/storefront.d.ts +3 -0
  75. package/dist/src/tokens/process/configs/storefront.d.ts.map +1 -0
  76. package/dist/src/tokens/process/configs/storefront.js +220 -0
  77. package/dist/src/tokens/process/configs/typography.d.ts +3 -0
  78. package/dist/src/tokens/process/configs/typography.d.ts.map +1 -0
  79. package/dist/src/tokens/process/configs/typography.js +369 -0
  80. package/dist/src/tokens/{build → process}/configs.d.ts +3 -11
  81. package/dist/src/tokens/process/configs.d.ts.map +1 -0
  82. package/dist/src/tokens/process/configs.js +976 -0
  83. package/dist/src/tokens/process/formats/css/color.d.ts +4 -0
  84. package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -0
  85. package/dist/src/tokens/process/formats/css/color.js +128 -0
  86. package/dist/src/tokens/process/formats/css/semantic.d.ts +17 -0
  87. package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -0
  88. package/dist/src/tokens/process/formats/css/semantic.js +109 -0
  89. package/dist/src/tokens/process/formats/css/typography.d.ts +3 -0
  90. package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -0
  91. package/dist/src/tokens/process/formats/css/typography.js +32 -0
  92. package/dist/src/tokens/process/formats/css.d.ts +8 -0
  93. package/dist/src/tokens/process/formats/css.d.ts.map +1 -0
  94. package/dist/src/tokens/{build → process}/formats/css.js +94 -57
  95. package/dist/src/tokens/process/formats/js-tokens.d.ts.map +1 -0
  96. package/dist/src/tokens/process/formats/js-tokens.js +109 -0
  97. package/dist/src/tokens/process/platform.d.ts +87 -0
  98. package/dist/src/tokens/process/platform.d.ts.map +1 -0
  99. package/dist/src/tokens/process/platform.js +1090 -0
  100. package/dist/src/tokens/process/transformers.d.ts.map +1 -0
  101. package/dist/src/tokens/{build → process}/transformers.js +29 -6
  102. package/dist/src/tokens/{build → process}/utils/getMultidimensionalThemes.d.ts +3 -3
  103. package/dist/src/tokens/process/utils/getMultidimensionalThemes.d.ts.map +1 -0
  104. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +922 -0
  105. package/dist/src/tokens/template/design-tokens/primitives/globals.js +5 -0
  106. package/dist/src/tokens/template/design-tokens/primitives/modes/size/global.js +5 -0
  107. package/dist/src/tokens/template/design-tokens/primitives/modes/size/large.js +5 -0
  108. package/dist/src/tokens/template/design-tokens/primitives/modes/size/medium.js +5 -0
  109. package/dist/src/tokens/template/design-tokens/primitives/modes/size/small.js +5 -0
  110. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/large.js +5 -0
  111. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/medium.js +5 -0
  112. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/size/small.js +5 -0
  113. package/dist/src/tokens/template/design-tokens/primitives/modes/typography/typography.template.js +5 -0
  114. package/dist/src/tokens/template/design-tokens/semantic/color.base.template.js +5 -0
  115. package/dist/src/tokens/template/design-tokens/semantic/color.template.js +5 -0
  116. package/dist/src/tokens/template/design-tokens/semantic/modes/color.template.js +5 -0
  117. package/dist/src/tokens/template/design-tokens/semantic/style.js +5 -0
  118. package/dist/src/tokens/template/design-tokens/themes/theme.base.template.js +5 -0
  119. package/dist/src/tokens/template/design-tokens/themes/theme.template.js +5 -0
  120. package/dist/src/tokens/types.d.ts +54 -38
  121. package/dist/src/tokens/types.d.ts.map +1 -1
  122. package/dist/src/tokens/types.js +8 -0
  123. package/dist/src/tokens/utils.d.ts +30 -5
  124. package/dist/src/tokens/utils.d.ts.map +1 -1
  125. package/dist/src/tokens/utils.js +36 -50
  126. package/dist/src/utils.d.ts +18 -0
  127. package/dist/src/utils.d.ts.map +1 -0
  128. package/dist/src/utils.js +63 -0
  129. package/dist/typography.template-4N5YLH7F.json +22 -0
  130. package/package.json +17 -16
  131. package/dist/bin/config.d.ts.map +0 -1
  132. package/dist/bin/config.js +0 -71
  133. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts +0 -10
  134. package/dist/src/migrations/codemods/jsx/classname-prefix.d.ts.map +0 -1
  135. package/dist/src/migrations/codemods/jsx/classname-prefix.js +0 -64
  136. package/dist/src/migrations/codemods/jsx/run.d.ts +0 -7
  137. package/dist/src/migrations/codemods/jsx/run.d.ts.map +0 -1
  138. package/dist/src/migrations/codemods/jsx/run.js +0 -22
  139. package/dist/src/migrations/react-beta-to-v1.d.ts +0 -3
  140. package/dist/src/migrations/react-beta-to-v1.d.ts.map +0 -1
  141. package/dist/src/migrations/react-beta-to-v1.js +0 -5
  142. package/dist/src/scripts/copy-internal-tokens.d.ts +0 -2
  143. package/dist/src/scripts/copy-internal-tokens.d.ts.map +0 -1
  144. package/dist/src/scripts/copy-internal-tokens.js +0 -28
  145. package/dist/src/tokens/build/configs.d.ts.map +0 -1
  146. package/dist/src/tokens/build/configs.js +0 -280
  147. package/dist/src/tokens/build/formats/css.d.ts +0 -53
  148. package/dist/src/tokens/build/formats/css.d.ts.map +0 -1
  149. package/dist/src/tokens/build/formats/js-tokens.d.ts.map +0 -1
  150. package/dist/src/tokens/build/formats/js-tokens.js +0 -48
  151. package/dist/src/tokens/build/transformers.d.ts.map +0 -1
  152. package/dist/src/tokens/build/types.d.ts +0 -48
  153. package/dist/src/tokens/build/types.d.ts.map +0 -1
  154. package/dist/src/tokens/build/types.js +0 -7
  155. package/dist/src/tokens/build/utils/entryfile.d.ts +0 -12
  156. package/dist/src/tokens/build/utils/entryfile.d.ts.map +0 -1
  157. package/dist/src/tokens/build/utils/entryfile.js +0 -67
  158. package/dist/src/tokens/build/utils/getMultidimensionalThemes.d.ts.map +0 -1
  159. package/dist/src/tokens/build/utils/getMultidimensionalThemes.js +0 -112
  160. package/dist/src/tokens/design-tokens/template/$metadata.json +0 -25
  161. package/dist/src/tokens/design-tokens/template/$themes.json +0 -1498
  162. package/dist/src/tokens/template.d.ts.map +0 -1
  163. package/dist/src/tokens/template.js +0 -99
  164. package/dist/src/tokens/write/generate$metadata.d.ts +0 -9
  165. package/dist/src/tokens/write/generate$metadata.d.ts.map +0 -1
  166. package/dist/src/tokens/write/generate$themes.d.ts +0 -12
  167. package/dist/src/tokens/write/generate$themes.d.ts.map +0 -1
  168. package/dist/src/tokens/write/generate$themes.js +0 -161
  169. package/dist/src/tokens/write.d.ts.map +0 -1
  170. package/dist/src/tokens/write.js +0 -177
  171. /package/dist/{src/tokens/design-tokens/template/semantic/color-base-file.json → color.base.template-M7BHS4OV.json} +0 -0
  172. /package/dist/{src/tokens/design-tokens/template/semantic/modes/category-color/category-color-template.json → color.template-LMPUQ72A.json} +0 -0
  173. /package/dist/{src/tokens/design-tokens/template/semantic/semantic-color-template.json → color.template-XQNSHLTU.json} +0 -0
  174. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/global.json → global-XVXVBKM6.json} +0 -0
  175. /package/dist/{src/tokens/design-tokens/default/primitives/globals.json → globals-76VAFMDF.json} +0 -0
  176. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/large.json → large-CIIHO7AY.json} +0 -0
  177. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/large.json → large-UUOZ6DYI.json} +0 -0
  178. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/medium.json → medium-OQ7S7P4P.json} +0 -0
  179. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/medium.json → medium-VSB2S4X3.json} +0 -0
  180. /package/dist/{src/tokens/design-tokens/default/primitives/modes/typography/size/small.json → small-AEXJ6U7Z.json} +0 -0
  181. /package/dist/{src/tokens/design-tokens/default/primitives/modes/size/small.json → small-ZY4KOJWX.json} +0 -0
  182. /package/dist/src/tokens/{build → process}/formats/js-tokens.d.ts +0 -0
  183. /package/dist/src/tokens/{build → process}/transformers.d.ts +0 -0
  184. /package/dist/{src/tokens/design-tokens/default/semantic/style.json → style-FP5XVCUD.json} +0 -0
  185. /package/dist/{src/tokens/design-tokens/template/themes/theme-base-file.json → theme.base.template-Y4RMFBQY.json} +0 -0
  186. /package/dist/{src/tokens/design-tokens/template/themes/theme-color-template.json → theme.template-CTQRNOMO.json} +0 -0
@@ -0,0 +1,220 @@
1
+ // src/tokens/process/configs/storefront.ts
2
+ import * as R5 from "ramda";
3
+ import { outputReferencesFilter } from "style-dictionary/utils";
4
+
5
+ // src/tokens/utils.ts
6
+ import * as R from "ramda";
7
+ var mapToLowerCase = R.map(R.toLower);
8
+ var hasAnyTruth = R.any(R.equals(true));
9
+ var getType = (token) => (token.$type ?? token.type) || "";
10
+ var getValue = (token) => token.$value ?? token.value;
11
+ var typeEquals = R.curry((types, token) => {
12
+ if (R.isNil(token)) {
13
+ return false;
14
+ }
15
+ return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
16
+ });
17
+ var pathStartsWithOneOf = R.curry((paths, token) => {
18
+ if (R.isNil(token)) {
19
+ return false;
20
+ }
21
+ const tokenPath = mapToLowerCase(token.path);
22
+ const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
23
+ return hasAnyTruth(matchPathsStartingWith);
24
+ });
25
+ function isColorCategoryToken(token, category) {
26
+ if (!category) {
27
+ return ["main", "support"].some((c) => isColorCategoryToken(token, c));
28
+ }
29
+ return R.startsWith(["color", category], token.path);
30
+ }
31
+ var isDigit = (s) => /^\d+$/.test(s);
32
+ function inlineTokens(shouldInline, tokens) {
33
+ const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
34
+ return otherTokens.map((token) => {
35
+ let transformed = getValue(token.original);
36
+ for (const ref of inlineableTokens) {
37
+ const refName = ref.path.join(".");
38
+ if (typeof transformed === "string") {
39
+ transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
40
+ }
41
+ }
42
+ const tokenWithInlinedRefs = R.set(R.lensPath(["original", "$value"]), transformed, token);
43
+ return tokenWithInlinedRefs;
44
+ });
45
+ }
46
+
47
+ // src/tokens/process/formats/js-tokens.ts
48
+ import * as R3 from "ramda";
49
+ import { createPropertyFormatter as createPropertyFormatter2, fileHeader } from "style-dictionary/utils";
50
+
51
+ // src/tokens/process/formats/css/semantic.ts
52
+ import * as R2 from "ramda";
53
+ import { createPropertyFormatter } from "style-dictionary/utils";
54
+ var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
55
+ var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
56
+ var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
57
+ var isInlineTokens = R2.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
58
+ var overrideSizingFormula = (format, token) => {
59
+ const [name, value] = format(token).split(":");
60
+ const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
61
+ const round = `round(down, ${calc}, 0.0625rem)`;
62
+ return {
63
+ name,
64
+ round,
65
+ calc
66
+ };
67
+ };
68
+
69
+ // src/tokens/process/formats/js-tokens.ts
70
+ var groupByType = R3.groupBy((token) => getType(token));
71
+ var removeUnwatedTokens = R3.pipe(
72
+ R3.reject((token) => isColorCategoryToken(token)),
73
+ R3.reject((token) => R3.any((path) => path.startsWith("_"))(token.path))
74
+ );
75
+ var dissocExtensions = R3.pipe(R3.dissoc("$extensions"), R3.dissocPath(["original", "$extensions"]));
76
+ var removeUnwatedProps = R3.map((token) => dissocExtensions(token));
77
+ var toCssVarName = R3.pipe(R3.split(":"), R3.head, R3.trim);
78
+ var jsTokens = {
79
+ name: "ds/js-tokens",
80
+ format: async ({ dictionary, file, options }) => {
81
+ const { usesDtcg, outputReferences } = options;
82
+ const format = createPropertyFormatter2({
83
+ outputReferences,
84
+ dictionary,
85
+ format: "css",
86
+ usesDtcg
87
+ });
88
+ const formatTokens = R3.map((token) => {
89
+ if (pathStartsWithOneOf(["size", "_size"], token)) {
90
+ const { calc, name } = overrideSizingFormula(format, token);
91
+ return {
92
+ ...token,
93
+ name: name.trim(),
94
+ $value: calc.trim()
95
+ };
96
+ }
97
+ return {
98
+ ...token,
99
+ name: toCssVarName(format(token))
100
+ };
101
+ });
102
+ const processTokens = R3.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
103
+ const tokens = processTokens(inlineTokens(isInlineTokens, dictionary.allTokens));
104
+ const content = Object.entries(tokens).map(
105
+ ([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
106
+ `
107
+ ).join("\n");
108
+ return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
109
+ }
110
+ };
111
+
112
+ // src/tokens/process/transformers.ts
113
+ import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
114
+ import * as R4 from "ramda";
115
+ var isPx = R4.test(/\b\d+px\b/g);
116
+ var sizeRem = {
117
+ name: "ds/size/toRem",
118
+ type: "value",
119
+ transitive: true,
120
+ filter: (token) => {
121
+ const hasWantedType = typeEquals(["dimension", "fontsize"], token);
122
+ const hasWantedPath = pathStartsWithOneOf(["spacing", "sizing", "border-radius", "font-size"], token);
123
+ return hasWantedType && hasWantedPath;
124
+ },
125
+ transform: (token, config) => {
126
+ const value = getValue(token);
127
+ if (isPx(value)) {
128
+ const baseFont = config.basePxFontSize || 16;
129
+ const size = parseInt(value);
130
+ if (size === 0) {
131
+ return "0";
132
+ }
133
+ return `${size / baseFont}rem`;
134
+ }
135
+ return value;
136
+ }
137
+ };
138
+ var typographyName = {
139
+ name: "name/typography",
140
+ type: "name",
141
+ transitive: true,
142
+ // expanded tokens have different type so we match on path instead
143
+ filter: (token) => pathStartsWithOneOf(["typography"], token),
144
+ transform: (token) => {
145
+ return token.name.replace("-typography", "");
146
+ }
147
+ };
148
+ var resolveMath = {
149
+ name: "ds/resolveMath",
150
+ type: "value",
151
+ transitive: true,
152
+ filter: (token) => {
153
+ const isValidValue = ["string", "object"].includes(typeof getValue(token));
154
+ const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
155
+ return isValidValue && isTokenOfInterest;
156
+ },
157
+ transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
158
+ };
159
+ var unitless = {
160
+ name: "ds/unitless",
161
+ type: "value",
162
+ transitive: true,
163
+ filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
164
+ transform: (token) => parseInt(getValue(token))
165
+ };
166
+
167
+ // src/tokens/process/configs/shared.ts
168
+ var prefix = "ds";
169
+ var basePxFontSize = 16;
170
+ var dsTransformers = [
171
+ "name/kebab",
172
+ resolveMath.name,
173
+ "ts/size/px",
174
+ sizeRem.name,
175
+ unitless.name,
176
+ "ts/typography/fontWeight",
177
+ typographyName.name,
178
+ "ts/color/modifiers",
179
+ "ts/color/css/hexrgba",
180
+ "ts/size/lineheight",
181
+ "shadow/css/shorthand"
182
+ ];
183
+
184
+ // src/tokens/process/configs/storefront.ts
185
+ var typescriptTokens = ({ "color-scheme": colorScheme, theme }) => {
186
+ return {
187
+ preprocessors: ["tokens-studio"],
188
+ platforms: {
189
+ ts: {
190
+ prefix,
191
+ basePxFontSize,
192
+ transforms: dsTransformers,
193
+ buildPath: `${theme}/`,
194
+ files: [
195
+ {
196
+ destination: `${colorScheme}.ts`,
197
+ format: jsTokens.name,
198
+ filter: (token) => {
199
+ if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R5.includes("semantic", token.filePath))
200
+ return false;
201
+ const isSemanticColor = R5.includes("semantic", token.filePath) && typeEquals(["color"], token);
202
+ const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
203
+ return isSemanticColor || wantedTypes;
204
+ }
205
+ }
206
+ ],
207
+ options: {
208
+ outputReferences: (token, options) => {
209
+ const include = pathStartsWithOneOf(["border-radius"], token);
210
+ const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
211
+ return (include || isWantedSize) && outputReferencesFilter(token, options);
212
+ }
213
+ }
214
+ }
215
+ }
216
+ };
217
+ };
218
+ export {
219
+ typescriptTokens
220
+ };
@@ -0,0 +1,3 @@
1
+ import { type GetStyleDictionaryConfig } from './shared.js';
2
+ export declare const typographyVariables: GetStyleDictionaryConfig;
3
+ //# sourceMappingURL=typography.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"typography.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/process/configs/typography.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,KAAK,wBAAwB,EAA0B,MAAM,aAAa,CAAC;AAEpF,eAAO,MAAM,mBAAmB,EAAE,wBAkDjC,CAAC"}
@@ -0,0 +1,369 @@
1
+ // src/tokens/process/configs/typography.ts
2
+ import { expandTypesMap } from "@tokens-studio/sd-transforms";
3
+
4
+ // src/tokens/utils.ts
5
+ import * as R from "ramda";
6
+ var mapToLowerCase = R.map(R.toLower);
7
+ var hasAnyTruth = R.any(R.equals(true));
8
+ var getType = (token) => (token.$type ?? token.type) || "";
9
+ var getValue = (token) => token.$value ?? token.value;
10
+ var typeEquals = R.curry((types, token) => {
11
+ if (R.isNil(token)) {
12
+ return false;
13
+ }
14
+ return R.includes(R.toLower(getType(token)), R.map(R.toLower, Array.isArray(types) ? types : [types]));
15
+ });
16
+ var pathStartsWithOneOf = R.curry((paths, token) => {
17
+ if (R.isNil(token)) {
18
+ return false;
19
+ }
20
+ const tokenPath = mapToLowerCase(token.path);
21
+ const matchPathsStartingWith = R.map((path) => R.startsWith([path], tokenPath), mapToLowerCase(paths));
22
+ return hasAnyTruth(matchPathsStartingWith);
23
+ });
24
+ function isSemanticToken(token) {
25
+ return token.filePath.includes("semantic/");
26
+ }
27
+ function isGlobalColorToken(token) {
28
+ return typeEquals("color", token) && pathStartsWithOneOf(["global"], token);
29
+ }
30
+ function isColorCategoryToken(token, category) {
31
+ if (!category) {
32
+ return ["main", "support"].some((c) => isColorCategoryToken(token, c));
33
+ }
34
+ return R.startsWith(["color", category], token.path);
35
+ }
36
+ var isDigit = (s) => /^\d+$/.test(s);
37
+ function inlineTokens(shouldInline, tokens) {
38
+ const [inlineableTokens, otherTokens] = R.partition(shouldInline, tokens);
39
+ return otherTokens.map((token) => {
40
+ let transformed = getValue(token.original);
41
+ for (const ref of inlineableTokens) {
42
+ const refName = ref.path.join(".");
43
+ if (typeof transformed === "string") {
44
+ transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
45
+ }
46
+ }
47
+ const tokenWithInlinedRefs = R.set(R.lensPath(["original", "$value"]), transformed, token);
48
+ return tokenWithInlinedRefs;
49
+ });
50
+ }
51
+
52
+ // src/tokens/process/formats/css/color.ts
53
+ import * as R2 from "ramda";
54
+ import { createPropertyFormatter } from "style-dictionary/utils";
55
+
56
+ // src/tokens/types.ts
57
+ var colorCategories = {
58
+ main: "main",
59
+ support: "support"
60
+ };
61
+
62
+ // src/tokens/process/formats/css/color.ts
63
+ var prefersColorScheme = (colorScheme2, content) => `
64
+ @media (prefers-color-scheme: ${colorScheme2}) {
65
+ [data-color-scheme="auto"] ${content}
66
+ }
67
+ `;
68
+ var colorScheme = {
69
+ name: "ds/css-colorscheme",
70
+ format: async ({ dictionary, file, options, platform }) => {
71
+ const { allTokens } = dictionary;
72
+ const { outputReferences, usesDtcg } = options;
73
+ const { selector, colorScheme: colorScheme2, layer } = platform;
74
+ const colorScheme_ = colorScheme2;
75
+ const format = createPropertyFormatter({
76
+ outputReferences,
77
+ dictionary,
78
+ format: "css",
79
+ usesDtcg
80
+ });
81
+ const colorSchemeProperty = colorScheme_ === "dark" || colorScheme_ === "light" ? `
82
+ color-scheme: ${colorScheme_};
83
+ ` : "";
84
+ const filteredAllTokens = allTokens.filter(
85
+ R2.allPass([
86
+ R2.anyPass([
87
+ // Include semantic tokens in the output
88
+ isSemanticToken,
89
+ // Include global color tokens
90
+ isGlobalColorToken
91
+ ]),
92
+ // Don't include color category tokens -- they are exported separately
93
+ (t) => !isColorCategoryToken(t)
94
+ ])
95
+ );
96
+ const formattedTokens = filteredAllTokens.map(format).join("\n");
97
+ const content = `{
98
+ ${formattedTokens}
99
+ ${colorSchemeProperty}}
100
+ `;
101
+ const autoSelectorContent = ["light", "dark"].includes(colorScheme_) ? prefersColorScheme(colorScheme_, content) : "";
102
+ const body = R2.isNotNil(layer) ? `@layer ${layer} {
103
+ ${selector} ${content} ${autoSelectorContent}
104
+ }
105
+ ` : `${selector} ${content} ${autoSelectorContent}
106
+ `;
107
+ return body;
108
+ }
109
+ };
110
+ var colorCategory = {
111
+ name: "ds/css-colorcategory",
112
+ format: async ({ dictionary, file, options, platform }) => {
113
+ const { outputReferences, usesDtcg } = options;
114
+ const { selector, layer } = platform;
115
+ const format = R2.compose(
116
+ createPropertyFormatter({
117
+ outputReferences,
118
+ dictionary,
119
+ format: "css",
120
+ usesDtcg
121
+ }),
122
+ (token) => ({
123
+ ...token,
124
+ name: token.name.replace(/color-\w+-/, "color-"),
125
+ original: {
126
+ ...token.original,
127
+ $value: new RegExp(`color-(${colorCategories.main}|${colorCategories.support})-`).test(token.name) ? token.original.$value : `{${token.path.join(".")}}`
128
+ }
129
+ })
130
+ );
131
+ const formattedTokens = dictionary.allTokens.map(format).join("\n");
132
+ const content = `{
133
+ ${formattedTokens}
134
+ }
135
+ `;
136
+ const body = R2.isNotNil(layer) ? `@layer ${layer} {
137
+ ${selector} ${content}
138
+ }
139
+ ` : `${selector} ${content}
140
+ `;
141
+ return body;
142
+ }
143
+ };
144
+
145
+ // src/tokens/process/formats/css/semantic.ts
146
+ import * as R3 from "ramda";
147
+ import { createPropertyFormatter as createPropertyFormatter2 } from "style-dictionary/utils";
148
+ var isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
149
+ var isNumericSizeToken = (t) => pathStartsWithOneOf(["size"], t) && isDigit(t.path[1]);
150
+ var isSizeToken = (t) => pathStartsWithOneOf(["size"], t);
151
+ var isInlineTokens = R3.anyPass([isNumericBorderRadiusToken, isNumericSizeToken, isSizeToken]);
152
+ var overrideSizingFormula = (format, token) => {
153
+ const [name, value] = format(token).split(":");
154
+ const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
155
+ const round = `round(down, ${calc}, 0.0625rem)`;
156
+ return {
157
+ name,
158
+ round,
159
+ calc
160
+ };
161
+ };
162
+ var formatSizingTokens = (format, tokens) => {
163
+ const { round, calc } = R3.reduce(
164
+ (acc, token) => {
165
+ const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
166
+ return {
167
+ round: [...acc.round, `${name}: ${round2};`],
168
+ calc: [...acc.calc, `${name}: ${calc2};`]
169
+ };
170
+ },
171
+ { round: [], calc: [] },
172
+ tokens
173
+ );
174
+ return `
175
+ ${calc.join("\n")}
176
+
177
+ @supports (width: round(down, .1em, 1px)) {
178
+ ${round.join("\n")}
179
+ }`;
180
+ };
181
+ var semantic = {
182
+ name: "ds/css-semantic",
183
+ format: async ({ dictionary, file, options, platform }) => {
184
+ const { outputReferences, usesDtcg } = options;
185
+ const { selector, layer } = platform;
186
+ const format = createPropertyFormatter2({
187
+ outputReferences,
188
+ dictionary,
189
+ format: "css",
190
+ usesDtcg
191
+ });
192
+ const tokens = inlineTokens(isInlineTokens, dictionary.allTokens);
193
+ const filteredTokens = R3.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
194
+ const [sizingTokens, restTokens] = R3.partition(
195
+ (t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
196
+ filteredTokens
197
+ );
198
+ const formattedTokens = [R3.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
199
+ const content = `{
200
+ ${formattedTokens.join("\n")}
201
+ }
202
+ `;
203
+ const body = R3.isNotNil(layer) ? `@layer ${layer} {
204
+ ${selector} ${content}
205
+ }
206
+ ` : `${selector} ${content}
207
+ `;
208
+ return body;
209
+ }
210
+ };
211
+
212
+ // src/tokens/process/formats/css/typography.ts
213
+ import * as R4 from "ramda";
214
+ import { createPropertyFormatter as createPropertyFormatter3 } from "style-dictionary/utils";
215
+ var typographyFontFamilyPredicate = R4.allPass([
216
+ R4.pathSatisfies(R4.includes("typography"), ["path"]),
217
+ R4.pathSatisfies(R4.includes("fontFamily"), ["path"])
218
+ ]);
219
+ var typography = {
220
+ name: "ds/css-typography",
221
+ format: async ({ dictionary, file, options, platform }) => {
222
+ const { outputReferences, usesDtcg } = options;
223
+ const { selector, layer } = platform;
224
+ const format = createPropertyFormatter3({
225
+ outputReferences,
226
+ dictionary,
227
+ format: "css",
228
+ usesDtcg
229
+ });
230
+ const filteredTokens = R4.reject(typographyFontFamilyPredicate, dictionary.allTokens);
231
+ const formattedTokens = R4.pipe(R4.map(format), R4.join("\n"))(filteredTokens);
232
+ const content = selector ? `${selector} {
233
+ ${formattedTokens}
234
+ }` : formattedTokens;
235
+ const body = R4.isNotNil(layer) ? `@layer ${layer} {
236
+ ${content}
237
+ }` : content;
238
+ return body;
239
+ }
240
+ };
241
+
242
+ // src/tokens/process/formats/css.ts
243
+ var formats = {
244
+ colorScheme,
245
+ colorCategory,
246
+ semantic,
247
+ typography
248
+ };
249
+
250
+ // src/tokens/process/transformers.ts
251
+ import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
252
+ import * as R5 from "ramda";
253
+ var isPx = R5.test(/\b\d+px\b/g);
254
+ var sizeRem = {
255
+ name: "ds/size/toRem",
256
+ type: "value",
257
+ transitive: true,
258
+ filter: (token) => {
259
+ const hasWantedType = typeEquals(["dimension", "fontsize"], token);
260
+ const hasWantedPath = pathStartsWithOneOf(["spacing", "sizing", "border-radius", "font-size"], token);
261
+ return hasWantedType && hasWantedPath;
262
+ },
263
+ transform: (token, config) => {
264
+ const value = getValue(token);
265
+ if (isPx(value)) {
266
+ const baseFont = config.basePxFontSize || 16;
267
+ const size = parseInt(value);
268
+ if (size === 0) {
269
+ return "0";
270
+ }
271
+ return `${size / baseFont}rem`;
272
+ }
273
+ return value;
274
+ }
275
+ };
276
+ var typographyName = {
277
+ name: "name/typography",
278
+ type: "name",
279
+ transitive: true,
280
+ // expanded tokens have different type so we match on path instead
281
+ filter: (token) => pathStartsWithOneOf(["typography"], token),
282
+ transform: (token) => {
283
+ return token.name.replace("-typography", "");
284
+ }
285
+ };
286
+ var resolveMath = {
287
+ name: "ds/resolveMath",
288
+ type: "value",
289
+ transitive: true,
290
+ filter: (token) => {
291
+ const isValidValue = ["string", "object"].includes(typeof getValue(token));
292
+ const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
293
+ return isValidValue && isTokenOfInterest;
294
+ },
295
+ transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
296
+ };
297
+ var unitless = {
298
+ name: "ds/unitless",
299
+ type: "value",
300
+ transitive: true,
301
+ filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
302
+ transform: (token) => parseInt(getValue(token))
303
+ };
304
+
305
+ // src/tokens/process/configs/shared.ts
306
+ var prefix = "ds";
307
+ var basePxFontSize = 16;
308
+ var dsTransformers = [
309
+ "name/kebab",
310
+ resolveMath.name,
311
+ "ts/size/px",
312
+ sizeRem.name,
313
+ unitless.name,
314
+ "ts/typography/fontWeight",
315
+ typographyName.name,
316
+ "ts/color/modifiers",
317
+ "ts/color/css/hexrgba",
318
+ "ts/size/lineheight",
319
+ "shadow/css/shorthand"
320
+ ];
321
+
322
+ // src/tokens/process/configs/typography.ts
323
+ var typographyVariables = ({ theme, typography: typography2 }) => {
324
+ const selector = `${typography2 === "primary" ? ":root, " : ""}[data-typography="${typography2}"]`;
325
+ const layer = `ds.theme.typography.${typography2}`;
326
+ return {
327
+ usesDtcg: true,
328
+ preprocessors: ["tokens-studio"],
329
+ expand: {
330
+ include: ["typography"],
331
+ typesMap: { ...expandTypesMap, typography: { ...expandTypesMap.typography, letterSpacing: "dimension" } }
332
+ },
333
+ platforms: {
334
+ css: {
335
+ prefix,
336
+ typography: typography2,
337
+ selector,
338
+ layer,
339
+ buildPath: `${theme}/`,
340
+ basePxFontSize,
341
+ transforms: [
342
+ "name/kebab",
343
+ "ts/size/px",
344
+ sizeRem.name,
345
+ "ts/size/lineheight",
346
+ "ts/typography/fontWeight",
347
+ typographyName.name
348
+ ],
349
+ files: [
350
+ {
351
+ destination: `typography/${typography2}.css`,
352
+ format: formats.typography.name,
353
+ filter: (token) => {
354
+ const included = typeEquals(
355
+ ["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
356
+ token
357
+ );
358
+ if (/primitives\/modes\/typography\/(primary|secondary)/.test(token.filePath)) return false;
359
+ return included && !pathStartsWithOneOf(["spacing", "sizing", "size", "_size", "border-width", "border-radius"], token);
360
+ }
361
+ }
362
+ ]
363
+ }
364
+ }
365
+ };
366
+ };
367
+ export {
368
+ typographyVariables
369
+ };
@@ -1,14 +1,6 @@
1
- import type { Config as StyleDictionaryConfig } from 'style-dictionary/types';
2
- import type { GetSdConfigOptions, SDConfigForThemePermutation, ThemeDimension, ThemePermutation } from './types.js';
1
+ import type { GetSDConfigOptions, SDConfigForThemePermutation, ThemeDimension } from '../types.js';
2
+ import type { GetStyleDictionaryConfig } from './configs/shared.js';
3
3
  import { type ProcessedThemeObject } from './utils/getMultidimensionalThemes.js';
4
- export declare const prefix = "ds";
5
- export declare const basePxFontSize = 16;
6
- export type GetStyleDictionaryConfig = (permutation: ThemePermutation, options: {
7
- outPath?: string;
8
- }) => StyleDictionaryConfig | {
9
- config: StyleDictionaryConfig;
10
- permutationOverrides?: Partial<ThemePermutation>;
11
- }[];
12
4
  export declare const configs: {
13
5
  colorSchemeVariables: GetStyleDictionaryConfig;
14
6
  mainColorVariables: GetStyleDictionaryConfig;
@@ -22,5 +14,5 @@ export declare const configs: {
22
14
  semanticVariables: GetStyleDictionaryConfig;
23
15
  typescriptTokens: GetStyleDictionaryConfig;
24
16
  };
25
- export declare const getConfigsForThemeDimensions: (getConfig: GetStyleDictionaryConfig, themes: ProcessedThemeObject[], dimensions: ThemeDimension[], options: GetSdConfigOptions) => SDConfigForThemePermutation[];
17
+ export declare const getConfigsForThemeDimensions: (getConfig: GetStyleDictionaryConfig, processed$themes: ProcessedThemeObject[], dimensions: ThemeDimension[], options: GetSDConfigOptions) => SDConfigForThemePermutation[];
26
18
  //# sourceMappingURL=configs.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../src/tokens/process/configs.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,2BAA2B,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAInG,OAAO,KAAK,EAAE,wBAAwB,EAAE,MAAM,qBAAqB,CAAC;AAOpE,OAAO,EAAE,KAAK,oBAAoB,EAA6B,MAAM,sCAAsC,CAAC;AAc5G,eAAO,MAAM,OAAO;;;;;;;;;;;;CAYnB,CAAC;AAEF,eAAO,MAAM,4BAA4B,GACvC,WAAW,wBAAwB,EACnC,kBAAkB,oBAAoB,EAAE,EACxC,YAAY,cAAc,EAAE,EAC5B,SAAS,kBAAkB,KAC1B,2BAA2B,EAoD7B,CAAC"}