@digdir/designsystemet 1.0.5 → 1.0.7

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 (49) hide show
  1. package/LICENSE +7 -0
  2. package/configs/digdir.config.json +59 -0
  3. package/configs/test-tokens.config.json +45 -0
  4. package/dist/bin/designsystemet.js +82 -88
  5. package/dist/config.schema.json +38 -27
  6. package/dist/src/colors/index.js +32 -0
  7. package/dist/src/colors/theme.js +1 -0
  8. package/dist/src/colors/utils.d.ts +13 -0
  9. package/dist/src/colors/utils.d.ts.map +1 -1
  10. package/dist/src/colors/utils.js +32 -0
  11. package/dist/src/config.d.ts +24 -176
  12. package/dist/src/config.d.ts.map +1 -1
  13. package/dist/src/config.js +23 -32
  14. package/dist/src/index.js +85 -50
  15. package/dist/src/migrations/beta-to-v1.js +2 -2
  16. package/dist/src/migrations/codemods/css/run.js +2 -2
  17. package/dist/src/migrations/color-rename-next49.js +2 -2
  18. package/dist/src/migrations/index.js +2 -2
  19. package/dist/src/scripts/createJsonSchema.js +33 -1292
  20. package/dist/src/scripts/update-design-tokens.js +4 -4
  21. package/dist/src/scripts/update-template.js +7 -7
  22. package/dist/src/tokens/build.js +56 -53
  23. package/dist/src/tokens/create/generators/$designsystemet.js +27 -25
  24. package/dist/src/tokens/create/generators/$themes.js +10 -10
  25. package/dist/src/tokens/create/generators/color.js +1 -0
  26. package/dist/src/tokens/create/write.js +39 -37
  27. package/dist/src/tokens/create.js +1 -0
  28. package/dist/src/tokens/format.js +54 -50
  29. package/dist/src/tokens/index.js +54 -50
  30. package/dist/src/tokens/process/configs/color.js +26 -22
  31. package/dist/src/tokens/process/configs/semantic.js +16 -12
  32. package/dist/src/tokens/process/configs/shared.js +16 -12
  33. package/dist/src/tokens/process/configs/storefront.js +16 -12
  34. package/dist/src/tokens/process/configs/typography.js +16 -12
  35. package/dist/src/tokens/process/configs.js +26 -22
  36. package/dist/src/tokens/process/formats/css/color.js +16 -12
  37. package/dist/src/tokens/process/formats/css/semantic.js +16 -12
  38. package/dist/src/tokens/process/formats/css.js +16 -12
  39. package/dist/src/tokens/process/formats/js-tokens.js +16 -12
  40. package/dist/src/tokens/process/platform.js +26 -22
  41. package/dist/src/tokens/process/theme.d.ts.map +1 -1
  42. package/dist/src/tokens/process/theme.js +27 -28
  43. package/dist/src/tokens/process/transformers.js +16 -12
  44. package/dist/src/tokens/process/utils/getMultidimensionalThemes.js +26 -22
  45. package/dist/src/tokens/utils.d.ts +2 -2
  46. package/dist/src/tokens/utils.d.ts.map +1 -1
  47. package/dist/src/tokens/utils.js +16 -12
  48. package/dist/src/utils.js +1 -1
  49. package/package.json +35 -33
package/dist/src/index.js CHANGED
@@ -1,5 +1,6 @@
1
1
  // src/colors/utils.ts
2
2
  import chroma from "chroma-js";
3
+ import Colorjs from "colorjs.io";
3
4
  import { Hsluv } from "hsluv";
4
5
  var hexToCssHsl = (hex, valuesOnly = false) => {
5
6
  const [h, s, l] = chroma(hex).hsl();
@@ -72,6 +73,9 @@ var getLuminanceFromLightness = (lightness) => {
72
73
  conv.hsluvToHex();
73
74
  return chroma(conv.hex).luminance();
74
75
  };
76
+ var getLuminanceFromColor = (color) => {
77
+ return chroma(color).luminance();
78
+ };
75
79
  var getLightnessFromHex = (hex) => {
76
80
  const conv = new Hsluv();
77
81
  conv.hex = hex;
@@ -106,6 +110,32 @@ var rgbToHex = (rgb) => {
106
110
  return hex.length === 1 ? "0" + hex : hex;
107
111
  }).join("")}`;
108
112
  };
113
+ var convertColor = (cssColor, format) => {
114
+ const color = new Colorjs(cssColor);
115
+ switch (format) {
116
+ case "rgb":
117
+ case "rgba":
118
+ return color.toString({
119
+ format: {
120
+ name: format,
121
+ coords: ["<number>[0, 255]", "<number>[0, 255]", "<number>[0, 255]"]
122
+ },
123
+ precision: 3
124
+ });
125
+ case "hex":
126
+ return color.toString({ format, precision: 3 });
127
+ case "hct":
128
+ return color.to(format).toString({
129
+ format: {
130
+ name: format,
131
+ coords: ["<number>", "<number>", "<number>"]
132
+ },
133
+ precision: 3
134
+ });
135
+ default:
136
+ return color.to(format).toString({ precision: 3 });
137
+ }
138
+ };
109
139
 
110
140
  // src/colors/theme.ts
111
141
  import chroma2 from "chroma-js";
@@ -2203,14 +2233,14 @@ var createTokens = async (opts) => {
2203
2233
  // src/tokens/format.ts
2204
2234
  import * as R20 from "ramda";
2205
2235
 
2206
- // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
2236
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowTypes.js
2207
2237
  var BoxShadowTypes;
2208
2238
  (function(BoxShadowTypes2) {
2209
2239
  BoxShadowTypes2["DROP_SHADOW"] = "dropShadow";
2210
2240
  BoxShadowTypes2["INNER_SHADOW"] = "innerShadow";
2211
2241
  })(BoxShadowTypes || (BoxShadowTypes = {}));
2212
2242
 
2213
- // ../../node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
2243
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorModifierTypes.js
2214
2244
  var ColorModifierTypes;
2215
2245
  (function(ColorModifierTypes2) {
2216
2246
  ColorModifierTypes2["LIGHTEN"] = "lighten";
@@ -2219,7 +2249,7 @@ var ColorModifierTypes;
2219
2249
  ColorModifierTypes2["ALPHA"] = "alpha";
2220
2250
  })(ColorModifierTypes || (ColorModifierTypes = {}));
2221
2251
 
2222
- // ../../node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
2252
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/ColorSpaceTypes.js
2223
2253
  var ColorSpaceTypes;
2224
2254
  (function(ColorSpaceTypes2) {
2225
2255
  ColorSpaceTypes2["LCH"] = "lch";
@@ -2228,7 +2258,7 @@ var ColorSpaceTypes;
2228
2258
  ColorSpaceTypes2["HSL"] = "hsl";
2229
2259
  })(ColorSpaceTypes || (ColorSpaceTypes = {}));
2230
2260
 
2231
- // ../../node_modules/@tokens-studio/types/dist/constants/Properties.js
2261
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/Properties.js
2232
2262
  var Properties;
2233
2263
  (function(Properties2) {
2234
2264
  Properties2["sizing"] = "sizing";
@@ -2280,7 +2310,7 @@ var Properties;
2280
2310
  Properties2["description"] = "description";
2281
2311
  })(Properties || (Properties = {}));
2282
2312
 
2283
- // ../../node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
2313
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenSetStatus.js
2284
2314
  var TokenSetStatus;
2285
2315
  (function(TokenSetStatus2) {
2286
2316
  TokenSetStatus2["DISABLED"] = "disabled";
@@ -2288,7 +2318,7 @@ var TokenSetStatus;
2288
2318
  TokenSetStatus2["ENABLED"] = "enabled";
2289
2319
  })(TokenSetStatus || (TokenSetStatus = {}));
2290
2320
 
2291
- // ../../node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
2321
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TokenTypes.js
2292
2322
  var TokenTypes;
2293
2323
  (function(TokenTypes2) {
2294
2324
  TokenTypes2["OTHER"] = "other";
@@ -2319,7 +2349,7 @@ var TokenTypes;
2319
2349
  TokenTypes2["NUMBER"] = "number";
2320
2350
  })(TokenTypes || (TokenTypes = {}));
2321
2351
 
2322
- // ../../node_modules/@tokens-studio/types/dist/constants/BorderValues.js
2352
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BorderValues.js
2323
2353
  var BorderValues;
2324
2354
  (function(BorderValues2) {
2325
2355
  BorderValues2["BORDER_COLOR"] = "color";
@@ -2327,7 +2357,7 @@ var BorderValues;
2327
2357
  BorderValues2["BORDER_STYLE"] = "style";
2328
2358
  })(BorderValues || (BorderValues = {}));
2329
2359
 
2330
- // ../../node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
2360
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/StrokeStyleValues.js
2331
2361
  var StrokeStyleValues;
2332
2362
  (function(StrokeStyleValues2) {
2333
2363
  StrokeStyleValues2["SOLID"] = "solid";
@@ -2340,7 +2370,7 @@ var StrokeStyleValues;
2340
2370
  StrokeStyleValues2["INSET"] = "inset";
2341
2371
  })(StrokeStyleValues || (StrokeStyleValues = {}));
2342
2372
 
2343
- // ../../node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
2373
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/BoxShadowValues.js
2344
2374
  var BoxShadowValues;
2345
2375
  (function(BoxShadowValues2) {
2346
2376
  BoxShadowValues2["TYPE"] = "type";
@@ -2352,7 +2382,7 @@ var BoxShadowValues;
2352
2382
  BoxShadowValues2["BLEND_MODE"] = "blendMode";
2353
2383
  })(BoxShadowValues || (BoxShadowValues = {}));
2354
2384
 
2355
- // ../../node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
2385
+ // ../../node_modules/.pnpm/@tokens-studio+types@0.5.2/node_modules/@tokens-studio/types/dist/constants/TypographyValues.js
2356
2386
  var TypographyValues;
2357
2387
  (function(TypographyValues2) {
2358
2388
  TypographyValues2["FONT_FAMILY"] = "fontFamily";
@@ -2556,20 +2586,24 @@ var mapToLowerCase = R7.map(R7.toLower);
2556
2586
  var hasAnyTruth = R7.any(R7.equals(true));
2557
2587
  var getType = (token) => (token.$type ?? token.type) || "";
2558
2588
  var getValue = (token) => token.$value ?? token.value;
2559
- var typeEquals = R7.curry((types, token) => {
2560
- if (R7.isNil(token)) {
2561
- return false;
2589
+ var typeEquals = R7.curry(
2590
+ (types, token) => {
2591
+ if (R7.isNil(token)) {
2592
+ return false;
2593
+ }
2594
+ return R7.includes(R7.toLower(getType(token)), R7.map(R7.toLower, Array.isArray(types) ? types : [types]));
2562
2595
  }
2563
- return R7.includes(R7.toLower(getType(token)), R7.map(R7.toLower, Array.isArray(types) ? types : [types]));
2564
- });
2565
- var pathStartsWithOneOf = R7.curry((paths, token) => {
2566
- if (R7.isNil(token)) {
2567
- return false;
2596
+ );
2597
+ var pathStartsWithOneOf = R7.curry(
2598
+ (paths, token) => {
2599
+ if (R7.isNil(token)) {
2600
+ return false;
2601
+ }
2602
+ const tokenPath = mapToLowerCase(token.path);
2603
+ const matchPathsStartingWith = R7.map((path) => R7.startsWith([path], tokenPath), mapToLowerCase(paths));
2604
+ return hasAnyTruth(matchPathsStartingWith);
2568
2605
  }
2569
- const tokenPath = mapToLowerCase(token.path);
2570
- const matchPathsStartingWith = R7.map((path) => R7.startsWith([path], tokenPath), mapToLowerCase(paths));
2571
- return hasAnyTruth(matchPathsStartingWith);
2572
- });
2606
+ );
2573
2607
  function isSemanticToken(token) {
2574
2608
  return token.filePath.includes("semantic/");
2575
2609
  }
@@ -3465,11 +3499,11 @@ import chalk3 from "chalk";
3465
3499
  // package.json
3466
3500
  var package_default = {
3467
3501
  name: "@digdir/designsystemet",
3468
- version: "1.0.5",
3502
+ version: "1.0.7",
3469
3503
  description: "CLI for Designsystemet",
3470
3504
  author: "Designsystemet team",
3471
3505
  engines: {
3472
- node: ">=22.14.0"
3506
+ node: ">=22.16.0"
3473
3507
  },
3474
3508
  repository: {
3475
3509
  type: "git",
@@ -3480,7 +3514,8 @@ var package_default = {
3480
3514
  type: "module",
3481
3515
  main: "./dist/src/index.js",
3482
3516
  files: [
3483
- "./dist/**"
3517
+ "./dist/**",
3518
+ "./configs/**"
3484
3519
  ],
3485
3520
  bin: "dist/bin/designsystemet.js",
3486
3521
  exports: {
@@ -3499,57 +3534,58 @@ var package_default = {
3499
3534
  },
3500
3535
  scripts: {
3501
3536
  designsystemet: "tsx ./bin/designsystemet.ts",
3502
- "build:tokens": "yarn designsystemet tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
3503
- "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../design-tokens -o ../../packages/theme/brand --clean",
3504
- build: "tsup && yarn build:types && yarn build:json-schema",
3537
+ "build:tokens": "pnpm run designsystemet tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
3538
+ "build:tokens:debug": "tsx --inspect-brk ./bin/designsystemet.ts tokens build -p -t ../../internal/design-tokens -o ../../packages/theme/brand --clean",
3539
+ build: "tsup && pnpm build:types && pnpm build:json-schema",
3505
3540
  "build:types": "tsc --emitDeclarationOnly --declaration",
3506
3541
  "build:json-schema": "tsx ./src/scripts/createJsonSchema.ts",
3507
3542
  types: "tsc --noEmit",
3508
- "test:tokens-create-options": "yarn designsystemet tokens create -m dominant:#007682 -n #003333 -b 99 -o ./test-tokens/options --theme options --clean",
3509
- "test:tokens-create-config": "yarn designsystemet tokens create --config ./test/test-tokens.config.json",
3510
- "test:tokens-build": "yarn designsystemet tokens build -t ./test-tokens/options -o ./test-tokens/options-build --clean",
3511
- "test:tokens-build-config": "yarn designsystemet tokens build -t ./test-tokens/config -o ./test-tokens/config-build --clean",
3512
- "test:tokens-create-and-build-options": "yarn test:tokens-create-options && yarn test:tokens-build",
3513
- "test:tokens-create-and-build-config": "yarn test:tokens-create-config && yarn test:tokens-build-config",
3514
- test: "yarn test:tokens-create-and-build-options && yarn test:tokens-create-and-build-config",
3515
- "internal:tokens-create": "yarn designsystemet tokens create --config ./internal.config.json",
3543
+ "test:tokens-create-options": 'pnpm run designsystemet tokens create -m dominant:"#007682" -n "#003333" -b 99 -o ./temp/options/design-tokens --theme options --clean',
3544
+ "test:tokens-create-config": "pnpm run designsystemet tokens create --config ./configs/test-tokens.config.json",
3545
+ "test:tokens-build": "pnpm run designsystemet tokens build -t ./temp/options/design-tokens -o ./temp/options/build --clean",
3546
+ "test:tokens-build-config": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean",
3547
+ "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
3548
+ "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
3549
+ test: "pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
3550
+ "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
3516
3551
  "update:template": "tsx ./src/scripts/update-template.ts",
3517
- "update:design-tokens": "yarn internal:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
3518
- verify: "yarn test && yarn update:template && yarn update:design-tokens"
3552
+ "update:design-tokens": "pnpm digdir:tokens-create && tsx ./src/scripts/update-design-tokens.ts",
3553
+ verify: "pnpm test && pnpm update:template && pnpm update:design-tokens"
3519
3554
  },
3520
3555
  dependencies: {
3521
3556
  "@commander-js/extra-typings": "^13.1.0",
3522
- "@tokens-studio/sd-transforms": "1.2.12",
3557
+ "@tokens-studio/sd-transforms": "1.3.0",
3523
3558
  "apca-w3": "^0.1.9",
3524
3559
  chalk: "^5.4.1",
3525
3560
  "change-case": "^5.4.4",
3526
3561
  "chroma-js": "^3.1.2",
3562
+ "colorjs.io": "^0.6.0-alpha.1",
3527
3563
  commander: "^13.1.0",
3528
3564
  "fast-glob": "^3.3.3",
3529
3565
  hsluv: "^1.0.1",
3530
3566
  "object-hash": "^3.0.0",
3531
3567
  postcss: "^8.5.3",
3532
3568
  ramda: "^0.30.1",
3533
- "style-dictionary": "^4.3.3",
3534
- zod: "^3.24.2",
3535
- "zod-validation-error": "^3.4.0"
3569
+ "style-dictionary": "^4.4.0",
3570
+ zod: "^3.25.30",
3571
+ "zod-validation-error": "^3.4.1"
3536
3572
  },
3537
3573
  devDependencies: {
3574
+ "@tokens-studio/types": "0.5.2",
3538
3575
  "@types/apca-w3": "^0.1.3",
3539
3576
  "@types/chroma-js": "^3.1.1",
3540
3577
  "@types/fs-extra": "^11.0.4",
3541
3578
  "@types/glob": "^8.1.0",
3542
3579
  "@types/jscodeshift": "^0.12.0",
3543
- "@types/node": "^22.14.0",
3580
+ "@types/node": "^22.15.21",
3544
3581
  "@types/object-hash": "^3.0.6",
3545
3582
  "@types/ramda": "^0.30.2",
3546
3583
  "fs-extra": "^11.3.0",
3547
3584
  "ts-toolbelt": "^9.6.0",
3548
3585
  tslib: "^2.8.1",
3549
- tsup: "^8.4.0",
3550
- tsx: "^4.19.3",
3551
- typescript: "^5.8.2",
3552
- "zod-to-json-schema": "^3.24.5"
3586
+ tsup: "^8.5.0",
3587
+ tsx: "^4.19.4",
3588
+ typescript: "^5.8.3"
3553
3589
  }
3554
3590
  };
3555
3591
 
@@ -3603,9 +3639,6 @@ order may change due to nondeterminism.`.trim()
3603
3639
  return sortIndex;
3604
3640
  });
3605
3641
  const header = `@charset "UTF-8";
3606
-
3607
- @layer ds.theme, ds.base, ds.utilities, ds.components;
3608
-
3609
3642
  /*
3610
3643
  ${fileHeader2}
3611
3644
  */
@@ -3659,6 +3692,7 @@ export {
3659
3692
  canTextBeUsedOnColors,
3660
3693
  cliOptions,
3661
3694
  colorMetadata,
3695
+ convertColor,
3662
3696
  convertToHex,
3663
3697
  createTokens,
3664
3698
  formatThemeCSS,
@@ -3671,6 +3705,7 @@ export {
3671
3705
  getContrastFromLightness,
3672
3706
  getCssVariable,
3673
3707
  getLightnessFromHex,
3708
+ getLuminanceFromColor,
3674
3709
  getLuminanceFromLightness,
3675
3710
  hexToCssHsl,
3676
3711
  hexToHSL,
@@ -42,12 +42,12 @@ var cssVarRename = (dictionary) => ({
42
42
  });
43
43
 
44
44
  // src/migrations/codemods/css/run.ts
45
- import fs2 from "node:fs";
45
+ import fs2 from "fs";
46
46
  import glob from "fast-glob";
47
47
  import postcss from "postcss";
48
48
 
49
49
  // src/utils.ts
50
- import fs from "node:fs/promises";
50
+ import fs from "fs/promises";
51
51
  import chalk2 from "chalk";
52
52
  var readFile = async (path, dry) => {
53
53
  if (dry) {
@@ -1,10 +1,10 @@
1
1
  // src/migrations/codemods/css/run.ts
2
- import fs2 from "node:fs";
2
+ import fs2 from "fs";
3
3
  import glob from "fast-glob";
4
4
  import postcss from "postcss";
5
5
 
6
6
  // src/utils.ts
7
- import fs from "node:fs/promises";
7
+ import fs from "fs/promises";
8
8
  import chalk from "chalk";
9
9
  var readFile = async (path, dry) => {
10
10
  if (dry) {
@@ -33,12 +33,12 @@ var cssVarRename = (dictionary) => ({
33
33
  });
34
34
 
35
35
  // src/migrations/codemods/css/run.ts
36
- import fs2 from "node:fs";
36
+ import fs2 from "fs";
37
37
  import glob from "fast-glob";
38
38
  import postcss from "postcss";
39
39
 
40
40
  // src/utils.ts
41
- import fs from "node:fs/promises";
41
+ import fs from "fs/promises";
42
42
  import chalk2 from "chalk";
43
43
  var readFile = async (path, dry) => {
44
44
  if (dry) {
@@ -42,12 +42,12 @@ var cssVarRename = (dictionary) => ({
42
42
  });
43
43
 
44
44
  // src/migrations/codemods/css/run.ts
45
- import fs2 from "node:fs";
45
+ import fs2 from "fs";
46
46
  import glob from "fast-glob";
47
47
  import postcss from "postcss";
48
48
 
49
49
  // src/utils.ts
50
- import fs from "node:fs/promises";
50
+ import fs from "fs/promises";
51
51
  import chalk2 from "chalk";
52
52
  var readFile = async (path, dry) => {
53
53
  if (dry) {