@digdir/designsystemet 1.1.3 → 1.1.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 (41) hide show
  1. package/dist/bin/designsystemet.js +130 -186
  2. package/dist/src/index.js +88 -145
  3. package/dist/src/scripts/update-preview-tokens.d.ts +3 -0
  4. package/dist/src/scripts/update-preview-tokens.d.ts.map +1 -0
  5. package/dist/src/scripts/update-preview-tokens.js +3446 -0
  6. package/dist/src/tokens/build.d.ts +1 -1
  7. package/dist/src/tokens/build.d.ts.map +1 -1
  8. package/dist/src/tokens/build.js +98 -154
  9. package/dist/src/tokens/create/generators/$designsystemet.js +6 -6
  10. package/dist/src/tokens/create/write.js +6 -6
  11. package/dist/src/tokens/format.d.ts +1 -1
  12. package/dist/src/tokens/format.d.ts.map +1 -1
  13. package/dist/src/tokens/format.js +88 -145
  14. package/dist/src/tokens/index.js +88 -145
  15. package/dist/src/tokens/process/configs/color.js +234 -293
  16. package/dist/src/tokens/process/configs/semantic.js +509 -113
  17. package/dist/src/tokens/process/configs/typography.d.ts.map +1 -1
  18. package/dist/src/tokens/process/configs/typography.js +504 -110
  19. package/dist/src/tokens/process/configs.d.ts +0 -1
  20. package/dist/src/tokens/process/configs.d.ts.map +1 -1
  21. package/dist/src/tokens/process/configs.js +231 -290
  22. package/dist/src/tokens/process/formats/css/color.d.ts.map +1 -1
  23. package/dist/src/tokens/process/formats/css/color.js +644 -12
  24. package/dist/src/tokens/process/formats/css/semantic.d.ts.map +1 -1
  25. package/dist/src/tokens/process/formats/css/semantic.js +679 -23
  26. package/dist/src/tokens/process/formats/css/typography.d.ts.map +1 -1
  27. package/dist/src/tokens/process/formats/css/typography.js +741 -8
  28. package/dist/src/tokens/process/formats/css.js +549 -38
  29. package/dist/src/tokens/process/output/declarations.js +60 -121
  30. package/dist/src/tokens/process/output/theme.js +6 -6
  31. package/dist/src/tokens/process/platform.d.ts +9 -4
  32. package/dist/src/tokens/process/platform.d.ts.map +1 -1
  33. package/dist/src/tokens/process/platform.js +76 -133
  34. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +62 -123
  35. package/package.json +6 -6
  36. package/dist/src/tokens/process/configs/storefront.d.ts +0 -3
  37. package/dist/src/tokens/process/configs/storefront.d.ts.map +0 -1
  38. package/dist/src/tokens/process/configs/storefront.js +0 -234
  39. package/dist/src/tokens/process/formats/js-tokens.d.ts +0 -6
  40. package/dist/src/tokens/process/formats/js-tokens.d.ts.map +0 -1
  41. package/dist/src/tokens/process/formats/js-tokens.js +0 -123
@@ -1,6 +1,6 @@
1
1
  // src/tokens/process/platform.ts
2
2
  import chalk2 from "chalk";
3
- import * as R12 from "ramda";
3
+ import * as R10 from "ramda";
4
4
  import StyleDictionary2 from "style-dictionary";
5
5
 
6
6
  // src/tokens/types.ts
@@ -11,7 +11,7 @@ var colorCategories = {
11
11
 
12
12
  // src/tokens/process/configs.ts
13
13
  import { register } from "@tokens-studio/sd-transforms";
14
- import * as R11 from "ramda";
14
+ import * as R9 from "ramda";
15
15
  import StyleDictionary from "style-dictionary";
16
16
 
17
17
  // src/tokens/utils.ts
@@ -122,7 +122,11 @@ var colorScheme = {
122
122
  (t) => !isColorCategoryToken(t)
123
123
  ])
124
124
  );
125
- const formattedTokens = filteredAllTokens.map(format).join("\n");
125
+ const formattedMap = filteredAllTokens.map((token) => ({
126
+ token,
127
+ formatted: format(token)
128
+ }));
129
+ const formattedTokens = formattedMap.map(R2.view(R2.lensProp("formatted"))).join("\n");
126
130
  const content = `{
127
131
  ${formattedTokens}
128
132
  ${colorSchemeProperty}}
@@ -140,7 +144,8 @@ var colorCategory = {
140
144
  name: "ds/css-colorcategory",
141
145
  format: async ({ dictionary, options, platform }) => {
142
146
  const { outputReferences, usesDtcg } = options;
143
- const { selector, layer } = platform;
147
+ const { selector, layer, files } = platform;
148
+ const destination = files?.[0]?.destination;
144
149
  const format = R2.compose(
145
150
  createPropertyFormatter({
146
151
  outputReferences,
@@ -157,7 +162,12 @@ var colorCategory = {
157
162
  }
158
163
  })
159
164
  );
160
- const formattedTokens = dictionary.allTokens.map(format).join("\n");
165
+ const formattedMap = dictionary.allTokens.map((token) => ({
166
+ token,
167
+ formatted: format(token)
168
+ }));
169
+ buildOptions.buildTokenFormats[destination] = formattedMap;
170
+ const formattedTokens = formattedMap.map(R2.view(R2.lensProp("formatted"))).join("\n");
161
171
  const content = `{
162
172
  ${formattedTokens}
163
173
  }
@@ -188,30 +198,30 @@ var overrideSizingFormula = (format, token) => {
188
198
  calc
189
199
  };
190
200
  };
191
- var formatSizingTokens = (format, tokens) => {
192
- const { round, calc } = R3.reduce(
193
- (acc, token) => {
194
- const { round: round2, calc: calc2, name } = overrideSizingFormula(format, token);
195
- return {
196
- round: [...acc.round, `${name}: ${round2};`],
197
- calc: [...acc.calc, `${name}: ${calc2};`]
198
- };
199
- },
200
- { round: [], calc: [] },
201
- tokens
202
- );
203
- return `
201
+ var formatSizingTokens = (format, tokens) => R3.reduce(
202
+ (acc, token) => {
203
+ const { round, calc, name } = overrideSizingFormula(format, token);
204
+ return {
205
+ tokens: [...acc.tokens, token],
206
+ round: [...acc.round, `${name}: ${round};`],
207
+ calc: [...acc.calc, `${name}: ${calc};`]
208
+ };
209
+ },
210
+ { tokens: [], round: [], calc: [] },
211
+ tokens
212
+ );
213
+ var sizingTemplate = ({ round, calc }) => `
204
214
  ${calc.join("\n")}
205
215
 
206
216
  @supports (width: round(down, .1em, 1px)) {
207
217
  ${round.join("\n")}
208
218
  }`;
209
- };
210
219
  var semantic = {
211
220
  name: "ds/css-semantic",
212
221
  format: async ({ dictionary, options, platform }) => {
213
222
  const { outputReferences, usesDtcg } = options;
214
- const { selector, layer } = platform;
223
+ const { selector, layer, files } = platform;
224
+ const destination = files?.[0]?.destination;
215
225
  const format = createPropertyFormatter2({
216
226
  outputReferences,
217
227
  dictionary,
@@ -224,7 +234,18 @@ var semantic = {
224
234
  (t) => pathStartsWithOneOf(["_size"], t) && isDigit(t.path[1]),
225
235
  filteredTokens
226
236
  );
227
- const formattedTokens = [R3.map(format, restTokens).join("\n"), formatSizingTokens(format, sizingTokens)];
237
+ const formattedSizingTokens = formatSizingTokens(format, sizingTokens);
238
+ const formattedMap = restTokens.map((token) => ({
239
+ token,
240
+ formatted: format(token)
241
+ }));
242
+ const formattedSizingMap = formattedSizingTokens.round.map((t, i) => ({
243
+ token: formattedSizingTokens.tokens[i],
244
+ formatted: t
245
+ }));
246
+ buildOptions.buildTokenFormats[destination] = [...formattedMap, ...formattedSizingMap];
247
+ const sizingSnippet = sizingTemplate(formattedSizingTokens);
248
+ const formattedTokens = formattedMap.map(R3.view(R3.lensProp("formatted"))).concat(sizingSnippet);
228
249
  const content = `{
229
250
  ${formattedTokens.join("\n")}
230
251
  }
@@ -249,7 +270,8 @@ var typography = {
249
270
  name: "ds/css-typography",
250
271
  format: async ({ dictionary, options, platform }) => {
251
272
  const { outputReferences, usesDtcg } = options;
252
- const { selector, layer } = platform;
273
+ const { selector, layer, files } = platform;
274
+ const destination = files?.[0]?.destination;
253
275
  const format = createPropertyFormatter3({
254
276
  outputReferences,
255
277
  dictionary,
@@ -257,7 +279,12 @@ var typography = {
257
279
  usesDtcg
258
280
  });
259
281
  const filteredTokens = R4.reject(typographyFontFamilyPredicate, dictionary.allTokens);
260
- const formattedTokens = R4.pipe(R4.map(format), R4.join("\n"))(filteredTokens);
282
+ const formattedMap = filteredTokens.map((token) => ({
283
+ token,
284
+ formatted: format(token)
285
+ }));
286
+ buildOptions.buildTokenFormats[destination] = formattedMap;
287
+ const formattedTokens = formattedMap.map(R4.view(R4.lensProp("formatted"))).join("\n");
261
288
  const content = selector ? `${selector} {
262
289
  ${formattedTokens}
263
290
  }` : formattedTokens;
@@ -464,90 +491,6 @@ var semanticVariables = ({ theme }) => {
464
491
  };
465
492
  };
466
493
 
467
- // src/tokens/process/configs/storefront.ts
468
- import * as R9 from "ramda";
469
- import { outputReferencesFilter as outputReferencesFilter2 } from "style-dictionary/utils";
470
-
471
- // src/tokens/process/formats/js-tokens.ts
472
- import * as R8 from "ramda";
473
- import { createPropertyFormatter as createPropertyFormatter4, fileHeader } from "style-dictionary/utils";
474
- var groupByType = R8.groupBy((token) => getType(token));
475
- var removeUnwatedTokens = R8.pipe(
476
- R8.reject((token) => isColorCategoryToken(token)),
477
- R8.reject((token) => R8.any((path) => path.startsWith("_"))(token.path))
478
- );
479
- var dissocExtensions = R8.pipe(R8.dissoc("$extensions"), R8.dissocPath(["original", "$extensions"]));
480
- var removeUnwatedProps = R8.map((token) => dissocExtensions(token));
481
- var toCssVarName = R8.pipe(R8.split(":"), R8.head, R8.trim);
482
- var jsTokens = {
483
- name: "ds/js-tokens",
484
- format: async ({ dictionary, file, options }) => {
485
- const { usesDtcg, outputReferences } = options;
486
- const format = createPropertyFormatter4({
487
- outputReferences,
488
- dictionary,
489
- format: "css",
490
- usesDtcg
491
- });
492
- const formatTokens = R8.map((token) => {
493
- if (pathStartsWithOneOf(["size", "_size"], token)) {
494
- const { calc, name } = overrideSizingFormula(format, token);
495
- return {
496
- ...token,
497
- name: name.trim(),
498
- $value: calc.trim()
499
- };
500
- }
501
- return {
502
- ...token,
503
- name: toCssVarName(format(token))
504
- };
505
- });
506
- const processTokens = R8.pipe(removeUnwatedTokens, removeUnwatedProps, formatTokens, groupByType);
507
- const tokens = processTokens(inlineTokens(isInlineTokens, dictionary.allTokens));
508
- const content = Object.entries(tokens).map(
509
- ([name, token]) => `export const ${name} = ${JSON.stringify(token, null, 2).replace(/"([^"]+)":/g, "$1:")}
510
- `
511
- ).join("\n");
512
- return fileHeader({ file }).then((fileHeaderText) => fileHeaderText + content);
513
- }
514
- };
515
-
516
- // src/tokens/process/configs/storefront.ts
517
- var typescriptTokens = ({ "color-scheme": colorScheme2, theme }) => {
518
- return {
519
- preprocessors: ["tokens-studio"],
520
- platforms: {
521
- ts: {
522
- prefix,
523
- basePxFontSize,
524
- transforms: dsTransformers,
525
- buildPath: `${theme}/`,
526
- files: [
527
- {
528
- destination: `${colorScheme2}.ts`,
529
- format: jsTokens.name,
530
- filter: (token) => {
531
- if (pathStartsWithOneOf(["border-width", "letter-spacing", "border-radius"], token) && !R9.includes("semantic", token.filePath))
532
- return false;
533
- const isSemanticColor = R9.includes("semantic", token.filePath) && typeEquals(["color"], token);
534
- const wantedTypes = typeEquals(["shadow", "dimension", "typography", "opacity"], token);
535
- return isSemanticColor || wantedTypes;
536
- }
537
- }
538
- ],
539
- options: {
540
- outputReferences: (token, options) => {
541
- const include = pathStartsWithOneOf(["border-radius"], token);
542
- const isWantedSize = pathStartsWithOneOf(["size", "_size"], token) && isDigit(token.path[1]);
543
- return (include || isWantedSize) && outputReferencesFilter2(token, options);
544
- }
545
- }
546
- }
547
- }
548
- };
549
- };
550
-
551
494
  // src/tokens/process/configs/typography.ts
552
495
  import { expandTypesMap } from "@tokens-studio/sd-transforms";
553
496
  var typographyVariables = ({ theme, typography: typography2 }) => {
@@ -574,6 +517,7 @@ var typographyVariables = ({ theme, typography: typography2 }) => {
574
517
  sizeRem.name,
575
518
  "ts/size/lineheight",
576
519
  "ts/typography/fontWeight",
520
+ "ts/size/css/letterspacing",
577
521
  typographyName.name
578
522
  ],
579
523
  files: [
@@ -761,13 +705,13 @@ var TypographyValues;
761
705
  // src/tokens/process/utils/getMultidimensionalThemes.ts
762
706
  import chalk from "chalk";
763
707
  import { kebabCase } from "change-case";
764
- import * as R10 from "ramda";
708
+ import * as R8 from "ramda";
765
709
  var getMultidimensionalThemes = (processed$themes, dimensions) => {
766
710
  const verboseLogging = buildOptions?.verbose;
767
711
  const grouped$themes = groupThemes(processed$themes);
768
712
  const permutations = permutateThemes(grouped$themes);
769
713
  const ALL_DEPENDENT_ON = ["theme"];
770
- const keys2 = R10.keys(grouped$themes);
714
+ const keys2 = R8.keys(grouped$themes);
771
715
  const nonDependentKeys = keys2.filter((x) => ![...ALL_DEPENDENT_ON, ...dimensions].includes(x));
772
716
  if (verboseLogging) {
773
717
  console.log(chalk.cyan(`\u{1F50E} Finding theme permutations for ${dimensions}`));
@@ -793,7 +737,7 @@ function groupThemes(themes) {
793
737
  }
794
738
  return groups;
795
739
  }
796
- var hasUnknownProps = R10.pipe(R10.values, R10.none(R10.equals("unknown")), R10.not);
740
+ var hasUnknownProps = R8.pipe(R8.values, R8.none(R8.equals("unknown")), R8.not);
797
741
  function permutateThemes(groups) {
798
742
  const separator = "_";
799
743
  const permutations = cartesian(Object.values(groups));
@@ -803,8 +747,8 @@ function permutateThemes(groups) {
803
747
  const { group, name, selectedTokenSets } = theme;
804
748
  let updatedPermutation = acc.permutation;
805
749
  if (group) {
806
- const groupProp = R10.lensProp(group);
807
- updatedPermutation = R10.set(groupProp, name, updatedPermutation);
750
+ const groupProp = R8.lensProp(group);
751
+ updatedPermutation = R8.set(groupProp, name, updatedPermutation);
808
752
  }
809
753
  const updatedName = `${String(acc.name)}${acc ? separator : ""}${name}`;
810
754
  const sets = [...acc.selectedTokenSets, ...filterTokenSets(selectedTokenSets)];
@@ -863,7 +807,6 @@ StyleDictionary.registerTransform(sizeRem);
863
807
  StyleDictionary.registerTransform(typographyName);
864
808
  StyleDictionary.registerTransform(resolveMath);
865
809
  StyleDictionary.registerTransform(unitless);
866
- StyleDictionary.registerFormat(jsTokens);
867
810
  for (const format of Object.values(formats)) {
868
811
  StyleDictionary.registerFormat(format);
869
812
  }
@@ -877,8 +820,7 @@ var configs = {
877
820
  warningColorVariables: colorCategoryVariables({ category: "builtin", color: "warning" }),
878
821
  infoColorVariables: colorCategoryVariables({ category: "builtin", color: "info" }),
879
822
  typographyVariables,
880
- semanticVariables,
881
- typescriptTokens
823
+ semanticVariables
882
824
  };
883
825
  var getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, options) => {
884
826
  const { tokensDir, tokenSets } = options;
@@ -894,7 +836,7 @@ var getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, opt
894
836
  obj.filePath = tokenSet;
895
837
  }
896
838
  });
897
- tokenSource.tokens = R11.mergeDeepRight(tokenSource.tokens, tokensWithFilePath);
839
+ tokenSource.tokens = R9.mergeDeepRight(tokenSource.tokens, tokensWithFilePath);
898
840
  }
899
841
  }
900
842
  } else {
@@ -926,6 +868,7 @@ var getConfigsForThemeDimensions = (getConfig, processed$themes, dimensions, opt
926
868
  // src/tokens/process/platform.ts
927
869
  var initResult = {
928
870
  formatted: [],
871
+ tokens: [],
929
872
  permutation: {
930
873
  "color-scheme": "",
931
874
  "main-color": "",
@@ -936,7 +879,11 @@ var initResult = {
936
879
  typography: ""
937
880
  }
938
881
  };
939
- var buildOptions;
882
+ var buildOptions = {
883
+ verbose: false,
884
+ processed$themes: [],
885
+ buildTokenFormats: {}
886
+ };
940
887
  var sd = new StyleDictionary2();
941
888
  var buildConfigs = {
942
889
  typography: { getConfig: configs.typographyVariables, dimensions: ["typography"] },
@@ -969,19 +916,15 @@ var buildConfigs = {
969
916
  log: ({ permutation: { theme } }) => `${theme} - info`
970
917
  },
971
918
  semantic: { getConfig: configs.semanticVariables, dimensions: ["semantic"] }
972
- // storefront: {
973
- // name: 'Storefront preview tokens',
974
- // getConfig: configs.typescriptTokens,
975
- // dimensions: ['color-scheme'],
976
- // options: { outPath: path.resolve('../../apps/storefront/tokens') },
977
- // enabled: () => buildOptions?.preview ?? false,
978
- // },
979
919
  };
980
920
  async function processPlatform(options) {
981
921
  const { type, processed$themes } = options;
982
922
  const platform = "css";
983
923
  const tokenSets = type === "format" ? options.tokenSets : void 0;
984
924
  const tokensDir = type === "build" ? options.tokensDir : void 0;
925
+ const filteredProcessed$themes = processed$themes.filter(
926
+ (theme) => R10.not(theme.group === "size" && theme.name !== "medium")
927
+ );
985
928
  const UNSAFE_DEFAULT_COLOR = process.env.UNSAFE_DEFAULT_COLOR ?? "";
986
929
  if (UNSAFE_DEFAULT_COLOR) {
987
930
  console.warn(
@@ -1004,19 +947,16 @@ async function processPlatform(options) {
1004
947
  buildOptions = options;
1005
948
  buildOptions.defaultColor = UNSAFE_DEFAULT_COLOR;
1006
949
  buildOptions.colorGroups = colorGroups;
1007
- const filteredProcessed$themes = processed$themes.filter(
1008
- (theme) => R12.not(theme.group === "size" && theme.name !== "medium")
1009
- );
1010
- const customColors = getCustomColors(filteredProcessed$themes, colorGroups);
1011
950
  if (!buildOptions.defaultColor) {
1012
- const firstMainColor = R12.head(customColors);
951
+ const customColors = getCustomColors(filteredProcessed$themes, colorGroups);
952
+ const firstMainColor = R10.head(customColors);
1013
953
  buildOptions.defaultColor = firstMainColor;
1014
954
  }
1015
955
  if (buildOptions.defaultColor) {
1016
956
  console.log(`
1017
957
  \u{1F3A8} Using ${chalk2.blue(buildOptions.defaultColor)} as default color`);
1018
958
  }
1019
- const buildAndSdConfigs = R12.map((buildConfig) => {
959
+ const buildAndSdConfigs = R10.map((buildConfig) => {
1020
960
  const sdConfigs = getConfigsForThemeDimensions(
1021
961
  buildConfig.getConfig,
1022
962
  filteredProcessed$themes,
@@ -1052,7 +992,7 @@ async function processPlatform(options) {
1052
992
  typography: [initResult]
1053
993
  };
1054
994
  try {
1055
- for (const [buildName, { buildConfig, sdConfigs }] of R12.toPairs(buildAndSdConfigs)) {
995
+ for (const [buildName, { buildConfig, sdConfigs }] of R10.toPairs(buildAndSdConfigs)) {
1056
996
  if (!(buildConfig.enabled?.() ?? true)) {
1057
997
  continue;
1058
998
  }
@@ -1064,13 +1004,16 @@ async function processPlatform(options) {
1064
1004
  const { config, permutation } = sdConfig;
1065
1005
  const modes = ["theme", ...buildConfig.dimensions];
1066
1006
  const modeMessage = modes.map((x) => permutation[x]).join(" - ");
1067
- const logMessage = R12.isNil(buildConfig.log) ? modeMessage : buildConfig?.log(sdConfig);
1007
+ const logMessage = R10.isNil(buildConfig.log) ? modeMessage : buildConfig?.log(sdConfig);
1068
1008
  console.log(logMessage);
1069
1009
  const sdOptions = { cache: true };
1070
1010
  const sdExtended = await sd.extend(config);
1011
+ const formatted = await sdExtended.formatPlatform(platform, sdOptions);
1012
+ const tokens = (await sdExtended.getPlatformTokens(platform, sdOptions)).allTokens;
1071
1013
  const result = {
1072
1014
  permutation,
1073
- formatted: await sdExtended.formatPlatform(platform, sdOptions)
1015
+ formatted,
1016
+ tokens
1074
1017
  };
1075
1018
  return Promise.resolve(result);
1076
1019
  })