@digdir/designsystemet 1.0.0-next.33 → 1.0.0-next.34

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.
@@ -1,10 +1,10 @@
1
- import { register } from "@tokens-studio/sd-transforms";
1
+ import { expandTypesMap, register } from "@tokens-studio/sd-transforms";
2
2
  import * as R from "ramda";
3
3
  import StyleDictionary from "style-dictionary";
4
4
  import { outputReferencesFilter } from "style-dictionary/utils";
5
5
  import * as formats from "./formats/css.js";
6
6
  import { jsTokens } from "./formats/js-tokens.js";
7
- import { nameKebab, sizeRem, typographyShorthand } from "./transformers.js";
7
+ import { nameKebab, sizeRem, typographyName } from "./transformers.js";
8
8
  import { permutateThemes as permutateThemes_ } from "./utils/permutateThemes.js";
9
9
  import { pathStartsWithOneOf, typeEquals } from "./utils/utils.js";
10
10
  void register(StyleDictionary, { withSDBuiltins: false });
@@ -15,7 +15,7 @@ const separator = "_";
15
15
  const fileHeader = () => [`These files are generated from design tokens defind using Token Studio`];
16
16
  StyleDictionary.registerTransform(sizeRem);
17
17
  StyleDictionary.registerTransform(nameKebab);
18
- StyleDictionary.registerTransform(typographyShorthand);
18
+ StyleDictionary.registerTransform(typographyName);
19
19
  StyleDictionary.registerFormat(jsTokens);
20
20
  StyleDictionary.registerFormat(formats.colormode);
21
21
  StyleDictionary.registerFormat(formats.semantic);
@@ -26,7 +26,7 @@ const dsTransformers = [
26
26
  "ts/size/px",
27
27
  sizeRem.name,
28
28
  "ts/typography/fontWeight",
29
- typographyShorthand.name,
29
+ typographyName.name,
30
30
  "ts/color/modifiers",
31
31
  "ts/color/css/hexrgba",
32
32
  "ts/size/lineheight",
@@ -102,7 +102,7 @@ const semanticVariables = ({ outPath, theme }) => {
102
102
  {
103
103
  destination: `semantic.css`,
104
104
  format: formats.semantic.name,
105
- filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily"], token)
105
+ filter: (token) => (!token.isSource || isCalculatedToken(token)) && !typeEquals(["color", "fontWeight", "fontFamily", "typography"], token)
106
106
  }
107
107
  ],
108
108
  options: {
@@ -146,13 +146,17 @@ const typescriptTokens = ({ mode = "unknown", outPath, theme }) => {
146
146
  }
147
147
  };
148
148
  };
149
- const typographyCSS = ({ outPath, theme, typography }) => {
149
+ const typographyVariables = ({ outPath, theme, typography }) => {
150
150
  const selector = `${typography === "primary" ? ":root, " : ""}[data-ds-typography="${typography}"]`;
151
151
  const layer = `ds.theme.typography.${typography}`;
152
152
  return {
153
153
  usesDtcg: true,
154
154
  log: { verbosity: "silent" },
155
155
  preprocessors: ["tokens-studio"],
156
+ expand: {
157
+ include: ["typography"],
158
+ typesMap: { ...expandTypesMap, typography: { ...expandTypesMap.typography, letterSpacing: "dimension" } }
159
+ },
156
160
  platforms: {
157
161
  css: {
158
162
  prefix,
@@ -161,7 +165,14 @@ const typographyCSS = ({ outPath, theme, typography }) => {
161
165
  layer,
162
166
  buildPath: `${outPath}/${theme}/`,
163
167
  basePxFontSize,
164
- transforms: [nameKebab.name, "ts/size/px", sizeRem.name, "ts/size/lineheight", "ts/typography/fontWeight"],
168
+ transforms: [
169
+ nameKebab.name,
170
+ "ts/size/px",
171
+ sizeRem.name,
172
+ "ts/size/lineheight",
173
+ "ts/typography/fontWeight",
174
+ typographyName.name
175
+ ],
165
176
  files: [
166
177
  {
167
178
  destination: `typography/${typography}.css`,
@@ -223,5 +234,5 @@ export {
223
234
  semanticVariables,
224
235
  separator,
225
236
  typescriptTokens,
226
- typographyCSS
237
+ typographyVariables
227
238
  };
@@ -1,7 +1,6 @@
1
1
  import * as R from "ramda";
2
- import { createPropertyFormatter, fileHeader, getReferences, usesReferences } from "style-dictionary/utils";
3
- import { prefix } from "../configs.js";
4
- import { getValue, typeEquals } from "../utils/utils.js";
2
+ import { createPropertyFormatter, fileHeader, usesReferences } from "style-dictionary/utils";
3
+ import { getValue } from "../utils/utils.js";
5
4
  const prefersColorScheme = (mode, content) => `
6
5
  @media (prefers-color-scheme: ${mode}) {
7
6
  [data-ds-color-mode="auto"] ${content}
@@ -21,10 +20,12 @@ const colormode = {
21
20
  format: "css",
22
21
  usesDtcg
23
22
  });
24
- const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `color-scheme: ${mode_};
23
+ const colorSchemeProperty = mode_ === "dark" || mode_ === "light" ? `
24
+ color-scheme: ${mode_};
25
25
  ` : "";
26
+ const formattedTokens = dictionary.allTokens.map(format).join("\n");
26
27
  const content = `{
27
- ${allTokens.map(format).join("\n")}
28
+ ${formattedTokens}
28
29
  ${colorSchemeProperty}}
29
30
  `;
30
31
  const autoSelectorContent = ["light", "dark"].includes(mode_) ? prefersColorScheme(mode_, content) : "";
@@ -40,7 +41,6 @@ const calculatedVariable = R.pipe(R.split(/:(.*?);/g), (split) => `${split[0]}:
40
41
  const semantic = {
41
42
  name: "ds/css-semantic",
42
43
  format: async ({ dictionary, file, options, platform }) => {
43
- const { allTokens } = dictionary;
44
44
  const { outputReferences, usesDtcg } = options;
45
45
  const { selector, isCalculatedToken, layer } = platform;
46
46
  const header = await fileHeader({ file });
@@ -50,7 +50,7 @@ const semantic = {
50
50
  format: "css",
51
51
  usesDtcg
52
52
  });
53
- const formatTokens = R.map((token) => {
53
+ const formattedTokens = R.map((token) => {
54
54
  const originalValue = getValue(token.original);
55
55
  if (usesReferences(originalValue) && typeof outputReferences === "function" && outputReferences?.(token, { dictionary })) {
56
56
  if (isCalculatedToken?.(token, options)) {
@@ -58,10 +58,9 @@ const semantic = {
58
58
  }
59
59
  }
60
60
  return format(token);
61
- });
62
- const formattedVariables = formatTokens(allTokens);
61
+ }, dictionary.allTokens);
63
62
  const content = `{
64
- ${formattedVariables.join("\n")}
63
+ ${formattedTokens.join("\n")}
65
64
  }
66
65
  `;
67
66
  const body = R.isNotNil(layer) ? `@layer ${layer} {
@@ -72,28 +71,9 @@ ${selector} ${content}
72
71
  return header + body;
73
72
  }
74
73
  };
75
- const sortByType = R.sortBy((token) => token?.$type === "typography");
76
- const getVariableName = R.pipe(
77
- R.split(":"),
78
- R.head,
79
- R.defaultTo(""),
80
- R.trim,
81
- (name) => `var(${name})`
82
- );
83
- const bemify = R.pipe(
84
- (path) => {
85
- const filteredPath = path.filter((p) => p !== "typography");
86
- const withPrefix = R.concat([prefix], R.remove(0, 0, filteredPath));
87
- const [rest, last] = R.splitAt(-1, withPrefix);
88
- const className = `${rest.join("-")}--${R.head(last)}`;
89
- return className;
90
- },
91
- R.trim,
92
- R.toLower
93
- );
94
- const classSelector = R.pipe(R.prop("path"), bemify);
95
- const sortTypographyLast = R.sortWith([
96
- R.ascend((token) => typeEquals("typography")(token) ? 1 : 0)
74
+ const typographyFontFamilyPredicate = R.allPass([
75
+ R.pathSatisfies(R.includes("typography"), ["path"]),
76
+ R.pathSatisfies(R.includes("fontFamily"), ["path"])
97
77
  ]);
98
78
  const typography = {
99
79
  name: "ds/css-typography",
@@ -107,67 +87,12 @@ const typography = {
107
87
  format: "css",
108
88
  usesDtcg
109
89
  });
110
- const sortedTokens = sortTypographyLast(dictionary.allTokens);
111
- const formattedTokens = R.pipe(
112
- sortByType,
113
- R.reduce(
114
- (acc, token) => {
115
- if (typeEquals("fontweight", token)) {
116
- const className = `
117
- .${classSelector(token)} {
118
- font-weight: ${getValue(token)};
119
- }`;
120
- return Object.assign(acc, {
121
- variables: [...acc.variables, format(token)],
122
- classes: [...acc.classes, className]
123
- });
124
- }
125
- if (typeEquals("lineheight", token)) {
126
- const className = `
127
- .${classSelector(token)} {
128
- line-height: ${getValue(token)};
129
- }`;
130
- return Object.assign(acc, {
131
- variables: [...acc.variables, format(token)],
132
- classes: [...acc.classes, className]
133
- });
134
- }
135
- if (typeEquals("typography", token)) {
136
- let references = [];
137
- try {
138
- references = getReferences(getValue(token.original), dictionary.tokens);
139
- } catch (error) {
140
- console.error("Error getting references", error);
141
- throw new Error(JSON.stringify(token, null, 2));
142
- }
143
- const fontweight = R.find(typeEquals(["fontweight"]))(references);
144
- const lineheight = R.find(typeEquals(["lineheight"]))(references);
145
- const fontsize = R.find(typeEquals(["fontsize"]))(references);
146
- const letterSpacing = R.find(typeEquals(["dimension"]))(references);
147
- const fontSizeVar = fontsize ? getVariableName(format(fontsize)) : null;
148
- const fontWeightVar = fontweight ? getVariableName(format(fontweight)) : null;
149
- const lineheightVar = lineheight ? getVariableName(format(lineheight)) : null;
150
- const letterSpacingVar = letterSpacing ? getVariableName(format(letterSpacing)) : null;
151
- const className = `
152
- .${classSelector(token)} {
153
- ${fontSizeVar ? `font-size: ${fontSizeVar};` : ""}
154
- ${lineheightVar ? `line-height: ${lineheightVar};` : ""}
155
- ${fontWeightVar ? `font-weight: ${fontWeightVar};` : ""}
156
- ${letterSpacingVar ? `letter-spacing: ${letterSpacingVar};` : ""}
157
- }`;
158
- return Object.assign(acc, { classes: [className, ...acc.classes] });
159
- }
160
- return Object.assign(acc, { variables: [...acc.variables, format(token)] });
161
- },
162
- { variables: [], classes: [] }
163
- )
164
- )(sortedTokens);
165
- const classes = formattedTokens.classes.join("\n");
166
- const variables = formattedTokens.variables.join("\n");
90
+ console.log("dictionary.allTokens", dictionary.allTokens);
91
+ const filteredTokens = R.reject(typographyFontFamilyPredicate, dictionary.allTokens);
92
+ const formattedTokens = R.pipe(R.map(format), R.join("\n"))(filteredTokens);
167
93
  const content = selector ? `${selector} {
168
- ${variables}
169
- ${classes}
170
- }` : classes;
94
+ ${formattedTokens}
95
+ }` : formattedTokens;
171
96
  const body = R.isNotNil(layer) ? `@layer ${layer} {
172
97
  ${content}
173
98
  }` : content;
@@ -34,18 +34,18 @@ const nameKebab = {
34
34
  });
35
35
  }
36
36
  };
37
- const typographyShorthand = {
38
- name: "typography/shorthand",
39
- type: "value",
37
+ const typographyName = {
38
+ name: "name/typography",
39
+ type: "name",
40
40
  transitive: true,
41
- filter: (token) => typeEquals("typography", token),
41
+ // expanded tokens have different type so we match on path instead
42
+ filter: (token) => pathStartsWithOneOf(["typography"], token),
42
43
  transform: (token) => {
43
- const typography = getValue(token);
44
- return `${typography.fontWeight} ${typography.fontSize}/${typography.lineHeight} '${typography.fontFamily}'`;
44
+ return token.name.replace("-typography", "");
45
45
  }
46
46
  };
47
47
  export {
48
48
  nameKebab,
49
49
  sizeRem,
50
- typographyShorthand
50
+ typographyName
51
51
  };
@@ -23,7 +23,7 @@ async function buildTokens(options) {
23
23
  const semanticThemes = R.filter((val) => val.mode === "light" && val.typography === "primary", themes);
24
24
  const colorModeConfigs = getConfigs(configs.colorModeVariables, outPath, tokensDir, colormodeThemes);
25
25
  const semanticConfigs = getConfigs(configs.semanticVariables, outPath, tokensDir, semanticThemes);
26
- const typographyConfigs = getConfigs(configs.typographyCSS, outPath, tokensDir, typographyThemes);
26
+ const typographyConfigs = getConfigs(configs.typographyVariables, outPath, tokensDir, typographyThemes);
27
27
  const storefrontConfigs = getConfigs(configs.typescriptTokens, storefrontOutDir, tokensDir, colormodeThemes);
28
28
  if (typographyConfigs.length > 0) {
29
29
  console.log(`
@@ -17,7 +17,7 @@ type GetConfig = (options: {
17
17
  export declare const colorModeVariables: GetConfig;
18
18
  export declare const semanticVariables: GetConfig;
19
19
  export declare const typescriptTokens: GetConfig;
20
- export declare const typographyCSS: GetConfig;
20
+ export declare const typographyVariables: GetConfig;
21
21
  type getConfigs = (getConfig: GetConfig, outPath: string, tokensDir: string, themes: PermutatedThemes) => {
22
22
  mode: string;
23
23
  theme: string;
@@ -1 +1 @@
1
- {"version":3,"file":"configs.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/configs.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,sBAAsB,CAAC;AAGxD,OAAO,KAAK,EAAE,MAAM,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAC;AAOvE,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,4BAA4B,CAAC;AAQnE,eAAO,MAAM,MAAM,OAAO,CAAC;AAC3B,eAAO,MAAM,cAAc,KAAK,CAAC;AACjC,eAAO,MA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ources":["../../../../../../src/tokens/build/formats/css.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,EAAE,MAAM,wBAAwB,CAAC;AAarD,eAAO,MAAM,SAAS,EAAE,MA4BvB,CAAC;AAIF,eAAO,MAAM,QAAQ,EAAE,MAsCtB,CAAC;AAsCF,eAAO,MAAM,UAAU,EAAE,MAuFxB,CAAC"}
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;AAarD,eAAO,MAAM,SAAS,EAAE,MA6BvB,CAAC;AAIF,eAAO,MAAM,QAAQ,EAAE,MAoCtB,CAAC;AAQF,eAAO,MAAM,UAAU,EAAE,MA0BxB,CAAC"}
@@ -1,5 +1,5 @@
1
1
  import type { Transform } from 'style-dictionary/types';
2
2
  export declare const sizeRem: Transform;
3
3
  export declare const nameKebab: Transform;
4
- export declare const typographyShorthand: Transform;
4
+ export declare const typographyName: Transform;
5
5
  //# sourceMappingURL=transformers.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AAOxD,eAAO,MAAM,OAAO,EAAE,SAyBrB,CAAC;AAEF,eAAO,MAAM,SAAS,EAAE,SASvB,CAAC;AASF,eAAO,MAAM,mBAAmB,EAAE,SASjC,CAAC"}
1
+ {"version":3,"file":"transformers.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/build/transformers.ts"],"names":[],"mappings":"AACA,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"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@digdir/designsystemet",
3
- "version": "1.0.0-next.33",
3
+ "version": "1.0.0-next.34",
4
4
  "description": "CLI for Designsystemet",
5
5
  "author": "Designsystemet team",
6
6
  "repository": {