@digdir/designsystemet 1.0.0-next.44 → 1.0.0-next.46

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 (97) hide show
  1. package/dist/bin/config.d.ts +156 -0
  2. package/dist/bin/config.d.ts.map +1 -0
  3. package/dist/bin/designsystemet.js +124 -18
  4. package/dist/bin/options.d.ts +16 -0
  5. package/dist/bin/options.d.ts.map +1 -0
  6. package/dist/config.schema.json +78 -0
  7. package/dist/src/build-scripts/createJsonSchema.d.ts +2 -0
  8. package/dist/src/build-scripts/createJsonSchema.d.ts.map +1 -0
  9. package/dist/src/build-scripts/createJsonSchema.js +15 -0
  10. package/dist/src/colors/theme.d.ts.map +1 -1
  11. package/dist/src/colors/theme.js +1 -1
  12. package/dist/src/migrations/beta-to-v1.js +40 -40
  13. package/dist/src/tokens/build/configs.d.ts.map +1 -1
  14. package/dist/src/tokens/build/configs.js +39 -26
  15. package/dist/src/tokens/build/formats/css.d.ts +40 -0
  16. package/dist/src/tokens/build/formats/css.d.ts.map +1 -1
  17. package/dist/src/tokens/build/formats/css.js +68 -15
  18. package/dist/src/tokens/build/formats/js-tokens.d.ts.map +1 -1
  19. package/dist/src/tokens/build/formats/js-tokens.js +22 -9
  20. package/dist/src/tokens/build/transformers.d.ts +1 -1
  21. package/dist/src/tokens/build/transformers.d.ts.map +1 -1
  22. package/dist/src/tokens/build/transformers.js +10 -14
  23. package/dist/src/tokens/build.js +1 -1
  24. package/dist/src/tokens/create.d.ts +15 -11
  25. package/dist/src/tokens/create.d.ts.map +1 -1
  26. package/dist/src/tokens/create.js +15 -6
  27. package/dist/src/tokens/design-tokens/default/Figma/components.json +3 -3
  28. package/dist/src/tokens/design-tokens/default/primitives/globals.json +0 -12
  29. package/dist/src/tokens/design-tokens/default/primitives/modes/size/global.json +96 -0
  30. package/dist/src/tokens/design-tokens/default/primitives/modes/size/large.json +16 -0
  31. package/dist/src/tokens/design-tokens/default/primitives/modes/size/medium.json +16 -0
  32. package/dist/src/tokens/design-tokens/default/primitives/modes/size/small.json +16 -0
  33. package/dist/src/tokens/design-tokens/default/primitives/{size/default.json → modes/typography/size/large.json} +11 -86
  34. package/dist/src/{init/template/default-files/design-tokens/primitives/size/default.json → tokens/design-tokens/default/primitives/modes/typography/size/medium.json} +0 -75
  35. package/dist/src/tokens/design-tokens/default/primitives/modes/typography/size/small.json +100 -0
  36. package/dist/src/tokens/design-tokens/default/semantic/style.json +58 -136
  37. package/dist/src/tokens/design-tokens/template/$metadata.json +7 -2
  38. package/dist/src/tokens/design-tokens/template/$themes.json +1319 -1196
  39. package/dist/src/tokens/design-tokens/template/semantic/color-base-file.json +1 -1
  40. package/dist/src/tokens/design-tokens/template/themes/theme-base-file.json +15 -11
  41. package/dist/src/tokens/index.d.ts +2 -1
  42. package/dist/src/tokens/index.d.ts.map +1 -1
  43. package/dist/src/tokens/index.js +2 -2
  44. package/dist/src/tokens/template.d.ts.map +1 -1
  45. package/dist/src/tokens/template.js +2 -1
  46. package/dist/src/tokens/types.d.ts +6 -0
  47. package/dist/src/tokens/types.d.ts.map +1 -1
  48. package/dist/src/tokens/utils.d.ts +1 -0
  49. package/dist/src/tokens/utils.d.ts.map +1 -1
  50. package/dist/src/tokens/utils.js +2 -0
  51. package/dist/src/tokens/write/generate$metadata.d.ts.map +1 -1
  52. package/dist/src/tokens/write/generate$metadata.js +7 -1
  53. package/dist/src/tokens/write/generate$themes.d.ts +1 -0
  54. package/dist/src/tokens/write/generate$themes.d.ts.map +1 -1
  55. package/dist/src/tokens/write/generate$themes.js +141 -3
  56. package/dist/src/tokens/write.d.ts +2 -3
  57. package/dist/src/tokens/write.d.ts.map +1 -1
  58. package/dist/src/tokens/write.js +9 -2
  59. package/package.json +17 -7
  60. package/dist/src/init/createTokensPackage.d.ts +0 -5
  61. package/dist/src/init/createTokensPackage.d.ts.map +0 -1
  62. package/dist/src/init/createTokensPackage.js +0 -273
  63. package/dist/src/init/generateMetadataJson.d.ts +0 -6
  64. package/dist/src/init/generateMetadataJson.d.ts.map +0 -1
  65. package/dist/src/init/generateMetadataJson.js +0 -24
  66. package/dist/src/init/generateThemesJson.d.ts +0 -3
  67. package/dist/src/init/generateThemesJson.d.ts.map +0 -1
  68. package/dist/src/init/generateThemesJson.js +0 -103
  69. package/dist/src/init/index.d.ts +0 -3
  70. package/dist/src/init/index.d.ts.map +0 -1
  71. package/dist/src/init/index.js +0 -10
  72. package/dist/src/init/nextStepsMarkdown.d.ts +0 -3
  73. package/dist/src/init/nextStepsMarkdown.d.ts.map +0 -1
  74. package/dist/src/init/nextStepsMarkdown.js +0 -92
  75. package/dist/src/init/template/default-files/README.md +0 -10
  76. package/dist/src/init/template/default-files/design-tokens/Figma/components.json +0 -22
  77. package/dist/src/init/template/default-files/design-tokens/README.md +0 -3
  78. package/dist/src/init/template/default-files/design-tokens/primitives/globals.json +0 -161
  79. package/dist/src/init/template/default-files/design-tokens/semantic/color.json +0 -572
  80. package/dist/src/init/template/default-files/design-tokens/semantic/style.json +0 -564
  81. package/dist/src/init/template/default-files/design-tokens/themes/theme.json +0 -334
  82. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/contrast/global.json +0 -376
  83. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/contrast/theme-template.json +0 -314
  84. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/global.json +0 -376
  85. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/dark/theme-template.json +0 -314
  86. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/global.json +0 -376
  87. package/dist/src/init/template/template-files/design-tokens/primitives/modes/colors/light/theme-template.json +0 -314
  88. package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/primary/theme-template.json +0 -30
  89. package/dist/src/init/template/template-files/design-tokens/primitives/modes/typography/secondary/theme-template.json +0 -30
  90. package/dist/src/init/template/template-files/design-tokens/themes/theme-template.json +0 -334
  91. package/dist/src/init/template/template-files/package.json +0 -24
  92. package/dist/src/init/utils.d.ts +0 -4
  93. package/dist/src/init/utils.d.ts.map +0 -1
  94. package/dist/src/init/utils.js +0 -15
  95. package/dist/src/tokens/build/utils/noCase.d.ts +0 -11
  96. package/dist/src/tokens/build/utils/noCase.d.ts.map +0 -1
  97. package/dist/src/tokens/build/utils/noCase.js +0 -24
@@ -3,10 +3,10 @@ import * as R from "ramda";
3
3
  import StyleDictionary from "style-dictionary";
4
4
  import { outputReferencesFilter } from "style-dictionary/utils";
5
5
  import { DEFAULT_COLOR, buildOptions } from "../build.js";
6
- import { isColorCategoryToken, pathStartsWithOneOf, typeEquals } from "../utils.js";
6
+ import { isColorCategoryToken, isDigit, pathStartsWithOneOf, typeEquals } from "../utils.js";
7
7
  import { formats } from "./formats/css.js";
8
8
  import { jsTokens } from "./formats/js-tokens.js";
9
- import { nameKebab, resolveMath, sizeRem, typographyName } from "./transformers.js";
9
+ import { resolveMath, sizeRem, typographyName, unitless } from "./transformers.js";
10
10
  import { getMultidimensionalThemes } from "./utils/getMultidimensionalThemes.js";
11
11
  void register(StyleDictionary, { withSDBuiltins: false });
12
12
  const usesDtcg = true;
@@ -14,18 +14,19 @@ const prefix = "ds";
14
14
  const basePxFontSize = 16;
15
15
  const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
16
16
  StyleDictionary.registerTransform(sizeRem);
17
- StyleDictionary.registerTransform(nameKebab);
18
17
  StyleDictionary.registerTransform(typographyName);
19
18
  StyleDictionary.registerTransform(resolveMath);
19
+ StyleDictionary.registerTransform(unitless);
20
20
  StyleDictionary.registerFormat(jsTokens);
21
21
  for (const format of Object.values(formats)) {
22
22
  StyleDictionary.registerFormat(format);
23
23
  }
24
24
  const dsTransformers = [
25
- nameKebab.name,
25
+ "name/kebab",
26
26
  resolveMath.name,
27
27
  "ts/size/px",
28
28
  sizeRem.name,
29
+ unitless.name,
29
30
  "ts/typography/fontWeight",
30
31
  typographyName.name,
31
32
  "ts/color/modifiers",
@@ -34,12 +35,6 @@ const dsTransformers = [
34
35
  "shadow/css/shorthand"
35
36
  ];
36
37
  const paritionPrimitives = R.partition(R.test(/(?!.*global\.json).*primitives.*/));
37
- const outputColorReferences = (token) => {
38
- if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) && R.includes("semantic/color", token.filePath)) {
39
- return true;
40
- }
41
- return false;
42
- };
43
38
  const colorSchemeVariables = ({ "color-scheme": colorScheme = "light", theme }, { outPath }) => {
44
39
  const selector = `${colorScheme === "light" ? ":root, " : ""}[data-color-scheme="${colorScheme}"]`;
45
40
  const layer = `ds.theme.color-scheme.${colorScheme}`;
@@ -134,7 +129,6 @@ const colorCategoryVariables = (category) => ({ "color-scheme": colorScheme, the
134
129
  const semanticVariables = ({ theme }, { outPath }) => {
135
130
  const selector = `:root`;
136
131
  const layer = `ds.theme.semantic`;
137
- const isCalculatedToken = (token) => pathStartsWithOneOf(["spacing", "sizing"], token);
138
132
  return {
139
133
  usesDtcg,
140
134
  preprocessors: ["tokens-studio"],
@@ -144,7 +138,6 @@ const semanticVariables = ({ theme }, { outPath }) => {
144
138
  outPath,
145
139
  theme,
146
140
  basePxFontSize,
147
- isCalculatedToken,
148
141
  selector,
149
142
  layer,
150
143
  //
@@ -155,14 +148,20 @@ const semanticVariables = ({ theme }, { outPath }) => {
155
148
  {
156
149
  destination: `semantic.css`,
157
150
  format: formats.semantic.name,
158
- filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily", "typography"], token)
151
+ filter: (token) => {
152
+ const unwantedPaths = pathStartsWithOneOf(["font-size", "line-height", "letter-spacing"], token);
153
+ const unwantedTypes = typeEquals(["color", "fontWeight", "fontFamily", "typography"], token);
154
+ const unwantedTokens = !(unwantedPaths || unwantedTypes);
155
+ return !token.isSource && unwantedTokens;
156
+ }
159
157
  }
160
158
  ],
161
159
  options: {
162
160
  fileHeader,
163
161
  outputReferences: (token, options) => {
164
162
  const include = pathStartsWithOneOf(["border-radius"], token);
165
- return (include || isCalculatedToken(token)) && outputReferencesFilter(token, options);
163
+ const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
164
+ return (include || isWantedSize) && outputReferencesFilter(token, options);
166
165
  }
167
166
  }
168
167
  }
@@ -183,26 +182,29 @@ const typescriptTokens = ({ "color-scheme": colorScheme, theme }, { outPath }) =
183
182
  {
184
183
  destination: `${colorScheme}.ts`,
185
184
  format: jsTokens.name,
186
- outputReferences: outputColorReferences,
187
185
  filter: (token) => {
188
- if (R.test(/primitives\/modes|\/themes/, token.filePath)) return false;
189
- if (pathStartsWithOneOf(["border-width"], token)) return false;
190
- if (R.test(/accent|neutral|brand1|brand2|brand3|success|danger|warning/, token.name) || R.includes("semantic", token.filePath)) {
191
- return true;
192
- }
193
- return false;
186
+ if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R.includes("semantic", token.filePath))
187
+ return false;
188
+ const isSemanticColor = R.includes("semantic", token.filePath) && typeEquals(["color"], token);
189
+ const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
190
+ return isSemanticColor || wantedTypes;
194
191
  }
195
192
  }
196
193
  ],
197
194
  options: {
198
- fileHeader
195
+ fileHeader,
196
+ outputReferences: (token, options) => {
197
+ const include = pathStartsWithOneOf(["border-radius"], token);
198
+ const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
199
+ return (include || isWantedSize) && outputReferencesFilter(token, options);
200
+ }
199
201
  }
200
202
  }
201
203
  }
202
204
  };
203
205
  };
204
206
  const typographyVariables = ({ theme, typography }, { outPath }) => {
205
- const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
207
+ const selector = `${typography === "primary" ? ":root, " : ""}[data-typography="${typography}"]`;
206
208
  const layer = `ds.theme.typography.${typography}`;
207
209
  return {
208
210
  usesDtcg: true,
@@ -220,7 +222,7 @@ const typographyVariables = ({ theme, typography }, { outPath }) => {
220
222
  buildPath: `${outPath}/${theme}/`,
221
223
  basePxFontSize,
222
224
  transforms: [
223
- nameKebab.name,
225
+ "name/kebab",
224
226
  "ts/size/px",
225
227
  sizeRem.name,
226
228
  "ts/size/lineheight",
@@ -233,11 +235,22 @@ const typographyVariables = ({ theme, typography }, { outPath }) => {
233
235
  format: formats.typography.name,
234
236
  filter: (token) => {
235
237
  const included = typeEquals(
236
- ["typography", "fontweight", "fontFamily", "lineheight", "fontsize", "dimension", "font"],
238
+ ["typography", "fontweight", "fontFamily", "lineHeight", "dimension", "font", "fontsize"],
237
239
  token
238
240
  );
239
241
  return included && !pathStartsWithOneOf(
240
- ["spacing", "sizing", "border-width", "border-radius", "theme", "theme2", "theme3", "theme4"],
242
+ [
243
+ "spacing",
244
+ "sizing",
245
+ "size",
246
+ "_size",
247
+ "border-width",
248
+ "border-radius",
249
+ "theme",
250
+ "theme2",
251
+ "theme3",
252
+ "theme4"
253
+ ],
241
254
  token
242
255
  );
243
256
  }
@@ -1,9 +1,49 @@
1
+ import type { TransformedToken } from 'style-dictionary';
1
2
  import type { Format } from 'style-dictionary/types';
3
+ /**
4
+ * In the given tokens array, inline and remove tokens that match the predicate
5
+ *
6
+ * Example: In pseudo-code, given the predicate `(token) => token.path === ['size', '1']` and the following tokens
7
+ * ```js
8
+ * [
9
+ * { path: ['size', 'base'], original: { $value: '8px' } },
10
+ * { path: ['size', '1'], original: { $value: '{size.base} * 2' } },
11
+ * { path: ['size', 'sm']: original: { $value: 'min({size.1}, 12px)' } }
12
+ * ]
13
+ * ```
14
+ * would return
15
+ * ```js
16
+ * [
17
+ * { path: ['size', 'base'], original: { $value: '8px' } },
18
+ * { path: ['size', 'sm']: original: { $value: 'min({size.base} * 2, 12px)' } }
19
+ * ]
20
+ * ```
21
+ *
22
+ * @param shouldSquash - predicate to determine if token should be inlined
23
+ * @param tokens - array of tokens to transform
24
+ * @returns copy of `tokens` without those that matched the predicate,
25
+ * where references to the matching tokens have been inlined
26
+ */
27
+ export declare function squashTokens(shouldSquash: (t: TransformedToken) => boolean, tokens: TransformedToken[]): import("style-dictionary/types").TransformedToken[];
2
28
  declare module 'style-dictionary/types' {
3
29
  interface LocalOptions {
4
30
  replaceCategoryWith?: string;
5
31
  }
6
32
  }
33
+ export declare const isNumericSizeToken: (t: TransformedToken) => boolean;
34
+ export declare const isSquashTokens: (t: TransformedToken) => boolean;
35
+ /**
36
+ * Overrides the default sizing formula with a custom one that supports [round()](https://developer.mozilla.org/en-US/docs/Web/CSS/round) if supported.
37
+ *
38
+ * @param format - Function to format a token into a CSS property string.
39
+ * @param tokens - Array of transformed tokens to format.
40
+ * @returns Object with formatted CSS strings for calc and round.
41
+ */
42
+ export declare const overrideSizingFormula: (format: (t: TransformedToken) => string, token: TransformedToken) => {
43
+ name: string;
44
+ round: string;
45
+ calc: string;
46
+ };
7
47
  export declare const formats: {
8
48
  colorScheme: Format;
9
49
  colorCategory: Format;
@@ -1 +1 @@
1
- {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/css.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AA0DrD,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,YAAY;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B;CACF;AA2GD,eAAO,MAAM,OAAO;;;;;CAKc,CAAC"}
1
+ {"version":3,"file":"css.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/css.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,kBAAkB,CAAC;AACzD,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAarD;;;;;;;;;;;;;;;;;;;;;;;GAuBG;AACH,wBAAgB,YAAY,CAAC,YAAY,EAAE,CAAC,CAAC,EAAE,gBAAgB,KAAK,OAAO,EAAE,MAAM,EAAE,gBAAgB,EAAE,uDAetG;AAsDD,OAAO,QAAQ,wBAAwB,CAAC;IACtC,UAAiB,YAAY;QAC3B,mBAAmB,CAAC,EAAE,MAAM,CAAC;KAC9B;CACF;AAmCD,eAAO,MAAM,kBAAkB,MAAO,gBAAgB,YAA4D,CAAC;AAEnH,eAAO,MAAM,cAAc,MAHY,gBAAgB,YAGkC,CAAC;AAE1F;;;;;;GAMG;AACH,eAAO,MAAM,qBAAqB,WAAY,CAAC,CAAC,EAAE,gBAAgB,KAAK,MAAM,SAAS,gBAAgB;;;;CAYrG,CAAC;AA4FF,eAAO,MAAM,OAAO;;;;;CAKc,CAAC"}
@@ -1,7 +1,28 @@
1
1
  import * as R from "ramda";
2
- import { createPropertyFormatter, fileHeader, usesReferences } from "style-dictionary/utils";
3
- import { getValue, isColorCategoryToken, isGlobalColorToken, isSemanticToken } from "../../utils.js";
2
+ import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
3
+ import {
4
+ getValue,
5
+ isColorCategoryToken,
6
+ isDigit,
7
+ isGlobalColorToken,
8
+ isSemanticToken,
9
+ pathStartsWithOneOf
10
+ } from "../../utils.js";
4
11
  import { colorCategories } from "../types.js";
12
+ function squashTokens(shouldSquash, tokens) {
13
+ const [inlineableTokens, otherTokens] = R.partition(shouldSquash, tokens);
14
+ return otherTokens.map((token) => {
15
+ let transformed = getValue(token.original);
16
+ for (const ref of inlineableTokens) {
17
+ const refName = ref.path.join(".");
18
+ if (typeof transformed === "string") {
19
+ transformed = transformed.replaceAll(`{${refName}}`, getValue(ref.original));
20
+ }
21
+ }
22
+ const tokenWithInlinedRefs = R.set(R.lensPath(["original", "$value"]), transformed, token);
23
+ return tokenWithInlinedRefs;
24
+ });
25
+ }
5
26
  const prefersColorScheme = (colorScheme2, content) => `
6
27
  @media (prefers-color-scheme: ${colorScheme2}) {
7
28
  [data-color-scheme="auto"] ${content}
@@ -84,12 +105,43 @@ ${selector} ${content}
84
105
  return header + body;
85
106
  }
86
107
  };
87
- const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}: calc(${R.trim(split[1])});`);
108
+ const isNumericBorderRadiusToken = (t) => t.path[0] === "border-radius" && isDigit(t.path[1]);
109
+ const isNumericSizeToken = (t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]);
110
+ const isSquashTokens = R.anyPass([isNumericBorderRadiusToken, isNumericSizeToken]);
111
+ const overrideSizingFormula = (format, token) => {
112
+ const [name, value] = format(token).split(":");
113
+ const calc = value.replace(`var(--ds-size-mode-font-size)`, "1em").replace(/floor\((.*)\);/, "calc($1)");
114
+ const round = `round(down, ${calc}, 0.0625rem)`;
115
+ return {
116
+ name,
117
+ round,
118
+ calc
119
+ };
120
+ };
121
+ const formatSizingTokens = (format, tokens) => {
122
+ const { round, calc } = R.reduce(
123
+ (acc, token) => {
124
+ const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
125
+ return {
126
+ round: [...acc.round, `${name}: ${round2};`],
127
+ calc: [...acc.calc, `${name}: ${calc2};`]
128
+ };
129
+ },
130
+ { round: [], calc: [] },
131
+ tokens
132
+ );
133
+ return `
134
+ ${calc.join("\n")}
135
+
136
+ @supports (width: round(down, .1em, 1px)) {
137
+ ${round.join("\n")}
138
+ }`;
139
+ };
88
140
  const semantic = {
89
141
  name: "ds/css-semantic",
90
142
  format: async ({ dictionary, file, options, platform }) => {
91
143
  const { outputReferences, usesDtcg } = options;
92
- const { selector, isCalculatedToken, layer } = platform;
144
+ const { selector, layer } = platform;
93
145
  const header = await fileHeader({ file });
94
146
  const format = createPropertyFormatter({
95
147
  outputReferences,
@@ -97,16 +149,13 @@ const semantic = {
97
149
  format: "css",
98
150
  usesDtcg
99
151
  });
100
- const formattedTokens = R.map((token) => {
101
- const originalValue = getValue(token.original);
102
- if (usesReferences(originalValue) && typeof outputReferences === "function" && outputReferences?.(token, { dictionary })) {
103
- if (isCalculatedToken?.(token, options)) {
104
- return calculatedVariable(format(token));
105
- }
106
- return format(token);
107
- }
108
- return format(token);
109
- }, dictionary.allTokens);
152
+ const tokens = squashTokens(isSquashTokens, dictionary.allTokens);
153
+ const filteredTokens = R.reject((token) => token.name.includes("ds-size-mode-font-size"), tokens);
154
+ const [sizingTokens, restTokens] = R.partition(
155
+ (t) => pathStartsWithOneOf(["size", "_size"], t) && isDigit(t.path[1]),
156
+ filteredTokens
157
+ );
158
+ const formattedTokens = [R.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
110
159
  const content = `{
111
160
  ${formattedTokens.join("\n")}
112
161
  }
@@ -153,5 +202,9 @@ const formats = {
153
202
  typography
154
203
  };
155
204
  export {
156
- formats
205
+ formats,
206
+ isNumericSizeToken,
207
+ isSquashTokens,
208
+ overrideSizingFormula,
209
+ squashTokens
157
210
  };
@@ -1 +1 @@
1
- {"version":3,"file":"js-tokens.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/js-tokens.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;AAmBvE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MA2BtB,CAAC"}
1
+ {"version":3,"file":"js-tokens.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/formats/js-tokens.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,EAAoB,MAAM,wBAAwB,CAAC;AAoBvE;;GAEG;AACH,eAAO,MAAM,QAAQ,EAAE,MAuCtB,CAAC"}
@@ -1,9 +1,11 @@
1
1
  import * as R from "ramda";
2
2
  import { createPropertyFormatter, fileHeader } from "style-dictionary/utils";
3
- import { getType, isColorCategoryToken } from "../../utils.js";
3
+ import { getType, isColorCategoryToken, pathStartsWithOneOf } from "../../utils.js";
4
+ import { isSquashTokens, overrideSizingFormula, squashTokens } from "./css.js";
4
5
  const groupByType = R.groupBy((token) => getType(token));
5
- const removeUnwatedTokens = R.filter(
6
- (token) => !["ds-base-spacing", "ds-base-sizing"].includes(token.name) && !isColorCategoryToken(token)
6
+ const removeUnwatedTokens = R.pipe(
7
+ R.reject((token) => isColorCategoryToken(token)),
8
+ R.reject((token) => R.any((path) => path.startsWith("_"))(token.path))
7
9
  );
8
10
  const dissocExtensions = R.pipe(R.dissoc("$extensions"), R.dissocPath(["original", "$extensions"]));
9
11
  const removeUnwatedProps = R.map((token) => dissocExtensions(token));
@@ -11,18 +13,29 @@ const toCssVarName = R.pipe(R.split(":"), R.head, R.trim);
11
13
  const jsTokens = {
12
14
  name: "ds/js-tokens",
13
15
  format: async ({ dictionary, file, options }) => {
14
- const { usesDtcg } = options;
16
+ const { usesDtcg, outputReferences } = options;
15
17
  const format = createPropertyFormatter({
18
+ outputReferences,
16
19
  dictionary,
17
20
  format: "css",
18
21
  usesDtcg
19
22
  });
20
- const formatTokens = R.map((token) => ({
21
- ...token,
22
- name: toCssVarName(format(token))
23
- }));
23
+ const formatTokens = R.map((token) => {
24
+ if (pathStartsWithOneOf(["size", "_size"], token)) {
25
+ const { calc, name } = overrideSizingFormula(format, token);
26
+ return {
27
+ ...token,
28
+ name: name.trim(),
29
+ $value: calc.trim()
30
+ };
31
+ }
32
+ return {
33
+ ...token,
34
+ name: toCssVarName(format(token))
35
+ };
36
+ });
24
37
  const processTokens = R.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
25
- const tokens = processTokens(dictionary.allTokens);
38
+ const tokens = processTokens(squashTokens(isSquashTokens, dictionary.allTokens));
26
39
  const content = Object.entries(tokens).map(
27
40
  ([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
28
41
  `
@@ -1,6 +1,6 @@
1
1
  import type { Transform } from 'style-dictionary/types';
2
2
  export declare const sizeRem: Transform;
3
- export declare const nameKebab: Transform;
4
3
  export declare const typographyName: Transform;
5
4
  export declare const resolveMath: Transform;
5
+ export declare const unitless: Transform;
6
6
  //# sourceMappingURL=transformers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD,eAAO,MAAM,OAAO,EAAE,SAyBrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,SASvB,CAAC;AAEF,eAAO,MAAM,cAAc,EAAE,SAS5B,CAAC;AAEF,eAAO,MAAM,WAAW,EAAE,SAWzB,CAAC"}
1
+ {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;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"}
@@ -1,7 +1,6 @@
1
1
  import { checkAndEvaluateMath } from "@tokens-studio/sd-transforms";
2
2
  import * as R from "ramda";
3
3
  import { getValue, pathStartsWithOneOf, typeEquals } from "../utils.js";
4
- import { noCase } from "./utils/noCase.js";
5
4
  const isPx = R.test(/\b\d+px\b/g);
6
5
  const sizeRem = {
7
6
  name: "ds/size/toRem",
@@ -25,16 +24,6 @@ const sizeRem = {
25
24
  return value;
26
25
  }
27
26
  };
28
- const nameKebab = {
29
- name: "name/cti/hierarchical-kebab",
30
- type: "name",
31
- transform: (token, options) => {
32
- return noCase([options?.prefix].concat(token.path).join("-"), {
33
- delimiter: "-",
34
- stripRegexp: /[^A-Z0-9_]+/gi
35
- });
36
- }
37
- };
38
27
  const typographyName = {
39
28
  name: "name/typography",
40
29
  type: "name",
@@ -50,15 +39,22 @@ const resolveMath = {
50
39
  type: "value",
51
40
  transitive: true,
52
41
  filter: (token) => {
53
- const isValidValue = ["string", "object"].includes(typeof (token.$value ?? token.value));
42
+ const isValidValue = ["string", "object"].includes(typeof getValue(token));
54
43
  const isTokenOfInterest = !pathStartsWithOneOf(["border-radius"], token);
55
44
  return isValidValue && isTokenOfInterest;
56
45
  },
57
46
  transform: (token, platformCfg) => checkAndEvaluateMath(token, platformCfg.mathFractionDigits)
58
47
  };
48
+ const unitless = {
49
+ name: "ds/unitless",
50
+ type: "value",
51
+ transitive: true,
52
+ filter: (token) => pathStartsWithOneOf(["size", "_size"], token),
53
+ transform: (token) => parseInt(getValue(token))
54
+ };
59
55
  export {
60
- nameKebab,
61
56
  resolveMath,
62
57
  sizeRem,
63
- typographyName
58
+ typographyName,
59
+ unitless
64
60
  };
@@ -47,7 +47,7 @@ async function buildTokens(options) {
47
47
  const targetDir = path.resolve(options.outDir);
48
48
  buildOptions = options;
49
49
  const $themes = JSON.parse(await fs.readFile(path.resolve(`${tokensDir}/$themes.json`), "utf-8")).map(processThemeObject);
50
- const relevant$themes = $themes.filter((theme) => R.not(theme.group === "size" && theme.name !== "default"));
50
+ const relevant$themes = $themes.filter((theme) => R.not(theme.group === "size" && theme.name !== "medium"));
51
51
  if (!buildOptions.accentColor) {
52
52
  const accentOrFirstMainColor = relevant$themes.find((theme) => theme.name === DEFAULT_COLOR) || relevant$themes.find((theme) => theme.group === "main-color");
53
53
  buildOptions.accentColor = accentOrFirstMainColor?.name;
@@ -1,13 +1,17 @@
1
- import type { Colors, Tokens, Typography } from './types.js';
2
- export declare const colorCliOptions: {
3
- readonly main: "main-colors";
4
- readonly support: "support-colors";
5
- readonly neutral: "neutral-color";
1
+ import type { Theme, Tokens } from './types.js';
2
+ export declare const cliOptions: {
3
+ readonly outDir: "out-dir";
4
+ readonly theme: {
5
+ readonly colors: {
6
+ readonly main: "main-colors";
7
+ readonly support: "support-colors";
8
+ readonly neutral: "neutral-color";
9
+ };
10
+ readonly typography: {
11
+ readonly fontFamily: "font-family";
12
+ };
13
+ readonly borderRadius: "border-radius";
14
+ };
6
15
  };
7
- export type CreateTokensOptions = {
8
- colors: Colors;
9
- typography: Typography;
10
- themeName: string;
11
- };
12
- export declare const createTokens: (opts: CreateTokensOptions) => Tokens;
16
+ export declare const createTokens: (opts: Theme) => Tokens;
13
17
  //# sourceMappingURL=create.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,EAAyB,UAAU,EAAE,MAAM,YAAY,CAAC;AAEpF,eAAO,MAAM,eAAe;;;;CAIlB,CAAC;AAEX,MAAM,MAAM,mBAAmB,GAAG;IAChC,MAAM,EAAE,MAAM,CAAC;IACf,UAAU,EAAE,UAAU,CAAC;IACvB,SAAS,EAAE,MAAM,CAAC;CACnB,CAAC;AAgFF,eAAO,MAAM,YAAY,SAAU,mBAAmB,WAqBrD,CAAC"}
1
+ {"version":3,"file":"create.d.ts","sourceRoot":"","sources":["../../../src/tokens/create.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAU,KAAK,EAAE,MAAM,EAAqC,MAAM,YAAY,CAAC;AAE3F,eAAO,MAAM,UAAU;;;;;;;;;;;;;CAab,CAAC;AAgFX,eAAO,MAAM,YAAY,SAAU,KAAK,WAqBvC,CAAC"}
@@ -1,9 +1,18 @@
1
1
  import * as R from "ramda";
2
2
  import { baseColors, generateColorScale } from "../colors/index.js";
3
- const colorCliOptions = {
4
- main: "main-colors",
5
- support: "support-colors",
6
- neutral: "neutral-color"
3
+ const cliOptions = {
4
+ outDir: "out-dir",
5
+ theme: {
6
+ colors: {
7
+ main: "main-colors",
8
+ support: "support-colors",
9
+ neutral: "neutral-color"
10
+ },
11
+ typography: {
12
+ fontFamily: "font-family"
13
+ },
14
+ borderRadius: "border-radius"
15
+ }
7
16
  };
8
17
  const createColorTokens = (colorArray) => {
9
18
  const obj = {};
@@ -78,7 +87,7 @@ const generateGlobalTokens = (colorScheme) => {
78
87
  };
79
88
  };
80
89
  const createTokens = (opts) => {
81
- const { colors, typography, themeName: name } = opts;
90
+ const { colors, typography, name } = opts;
82
91
  const tokens = {
83
92
  colors: {
84
93
  light: {
@@ -98,6 +107,6 @@ const createTokens = (opts) => {
98
107
  return tokens;
99
108
  };
100
109
  export {
101
- colorCliOptions,
110
+ cliOptions,
102
111
  createTokens
103
112
  };
@@ -3,15 +3,15 @@
3
3
  "circle": {
4
4
  "small": {
5
5
  "$type": "sizing",
6
- "$value": "{sizing.5} - {switch.border}"
6
+ "$value": "{_size.5} - {switch.border}"
7
7
  },
8
8
  "medium": {
9
9
  "$type": "sizing",
10
- "$value": "{sizing.6} - {switch.border}"
10
+ "$value": "{_size.6} - {switch.border}"
11
11
  },
12
12
  "large": {
13
13
  "$type": "sizing",
14
- "$value": "{sizing.7} - {switch.border}"
14
+ "$value": "{_size.7} - {switch.border}"
15
15
  }
16
16
  },
17
17
  "border": {
@@ -139,17 +139,5 @@
139
139
  "$type": "opacity",
140
140
  "$value": "30%"
141
141
  }
142
- },
143
- "sizing": {
144
- "scale": {
145
- "$type": "sizing",
146
- "$value": "4"
147
- }
148
- },
149
- "spacing": {
150
- "scale": {
151
- "$type": "spacing",
152
- "$value": "4"
153
- }
154
142
  }
155
143
  }