@digdir/designsystemet 1.7.1 → 1.7.3

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.
@@ -382,21 +382,26 @@ var colorCategorySchema = z.record(
382
382
  error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
383
383
  }).describe("An object with one or more color definitions. The property name is used as the color name.");
384
384
  var colorModeOverrideSchema = z.object({
385
- light: colorSchema.optional(),
386
- dark: colorSchema.optional()
385
+ light: colorSchema.optional().describe("A hex color that overrides light mode"),
386
+ dark: colorSchema.optional().describe("A hex color that overrides dark mode")
387
387
  }).describe('Override values for semantic color tokens like "background-subtle", "border-default", etc.');
388
388
  var colorWeightOverrideSchema = z.partialRecord(z.enum([...colorNames]), colorModeOverrideSchema).describe('The name of the color to add overrides for, e.g. "accent"');
389
389
  var semanticColorOverrideSchema = z.record(z.string(), colorWeightOverrideSchema).describe("An object with color names as keys");
390
390
  var severityColorOverrideSchema = z.partialRecord(z.enum(baseColorNames), colorSchema.describe("A hex color, which is used for creating a color scale")).optional().describe("An object with severity color names as keys");
391
+ var linkVisitedOverrideSchema = z.object({
392
+ light: colorSchema.optional().describe("A hex color that overrides light mode"),
393
+ dark: colorSchema.optional().describe("A hex color that overrides dark mode")
394
+ }).describe('Overrides for the "link-visited" color');
391
395
  var overridesSchema = z.object({
392
396
  colors: semanticColorOverrideSchema.optional(),
393
- severity: severityColorOverrideSchema.optional()
397
+ severity: severityColorOverrideSchema.optional(),
398
+ linkVisited: linkVisitedOverrideSchema.optional()
394
399
  }).describe("Overrides for generated design tokens. Currently only supports colors defined in your theme").optional();
395
400
  var themeSchema = z.object({
396
401
  colors: z.object({
397
402
  main: colorCategorySchema,
398
403
  support: colorCategorySchema.optional().default({}),
399
- neutral: colorSchema
404
+ neutral: colorSchema.describe("A hex color, which is used for creating a color scale.")
400
405
  }).meta({ description: "Defines the colors for this theme" }),
401
406
  typography: z.object({
402
407
  fontFamily: z.string().meta({ description: "Sets the font-family for this theme" })
package/dist/src/index.js CHANGED
@@ -1522,6 +1522,7 @@ var generateColorScheme = (themeName, colorScheme2, colors, overrides) => {
1522
1522
  baseColorsWithOverrides
1523
1523
  );
1524
1524
  const linkColor = generateColor(generateColorScale(dsLinkColor, colorScheme2));
1525
+ const linkOverride = overrides?.linkVisited?.[colorScheme2] ? { $type: "color", $value: overrides.linkVisited[colorScheme2] } : void 0;
1525
1526
  return {
1526
1527
  [themeName]: {
1527
1528
  ...main,
@@ -1529,7 +1530,7 @@ var generateColorScheme = (themeName, colorScheme2, colors, overrides) => {
1529
1530
  neutral,
1530
1531
  ...globalColors,
1531
1532
  link: {
1532
- visited: linkColor[12]
1533
+ visited: linkOverride || linkColor[12]
1533
1534
  }
1534
1535
  }
1535
1536
  };
@@ -2029,21 +2030,26 @@ var colorCategorySchema = z.record(
2029
2030
  error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
2030
2031
  }).describe("An object with one or more color definitions. The property name is used as the color name.");
2031
2032
  var colorModeOverrideSchema = z.object({
2032
- light: colorSchema.optional(),
2033
- dark: colorSchema.optional()
2033
+ light: colorSchema.optional().describe("A hex color that overrides light mode"),
2034
+ dark: colorSchema.optional().describe("A hex color that overrides dark mode")
2034
2035
  }).describe('Override values for semantic color tokens like "background-subtle", "border-default", etc.');
2035
2036
  var colorWeightOverrideSchema = z.partialRecord(z.enum([...colorNames]), colorModeOverrideSchema).describe('The name of the color to add overrides for, e.g. "accent"');
2036
2037
  var semanticColorOverrideSchema = z.record(z.string(), colorWeightOverrideSchema).describe("An object with color names as keys");
2037
2038
  var severityColorOverrideSchema = z.partialRecord(z.enum(baseColorNames), colorSchema.describe("A hex color, which is used for creating a color scale")).optional().describe("An object with severity color names as keys");
2039
+ var linkVisitedOverrideSchema = z.object({
2040
+ light: colorSchema.optional().describe("A hex color that overrides light mode"),
2041
+ dark: colorSchema.optional().describe("A hex color that overrides dark mode")
2042
+ }).describe('Overrides for the "link-visited" color');
2038
2043
  var overridesSchema = z.object({
2039
2044
  colors: semanticColorOverrideSchema.optional(),
2040
- severity: severityColorOverrideSchema.optional()
2045
+ severity: severityColorOverrideSchema.optional(),
2046
+ linkVisited: linkVisitedOverrideSchema.optional()
2041
2047
  }).describe("Overrides for generated design tokens. Currently only supports colors defined in your theme").optional();
2042
2048
  var themeSchema = z.object({
2043
2049
  colors: z.object({
2044
2050
  main: colorCategorySchema,
2045
2051
  support: colorCategorySchema.optional().default({}),
2046
- neutral: colorSchema
2052
+ neutral: colorSchema.describe("A hex color, which is used for creating a color scale.")
2047
2053
  }).meta({ description: "Defines the colors for this theme" }),
2048
2054
  typography: z.object({
2049
2055
  fontFamily: z.string().meta({ description: "Sets the font-family for this theme" })
@@ -2402,7 +2408,7 @@ import * as R9 from "ramda";
2402
2408
  // package.json
2403
2409
  var package_default = {
2404
2410
  name: "@digdir/designsystemet",
2405
- version: "1.7.1",
2411
+ version: "1.7.3",
2406
2412
  description: "CLI for Designsystemet",
2407
2413
  author: "Designsystemet team",
2408
2414
  engines: {
@@ -2454,7 +2460,8 @@ var package_default = {
2454
2460
  "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
2455
2461
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
2456
2462
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
2457
- test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
2463
+ "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../internal/design-tokens --dry",
2464
+ test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
2458
2465
  "digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
2459
2466
  "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
2460
2467
  "update:template": "tsx ./src/scripts/update-template.ts",
@@ -2469,7 +2476,7 @@ var package_default = {
2469
2476
  "change-case": "^5.4.4",
2470
2477
  "chroma-js": "^3.1.2",
2471
2478
  "colorjs.io": "^0.6.0-alpha.1",
2472
- commander: "^14.0.1",
2479
+ commander: "^14.0.2",
2473
2480
  "fast-glob": "^3.3.3",
2474
2481
  hsluv: "^1.0.1",
2475
2482
  "object-hash": "^3.0.0",
@@ -2483,9 +2490,9 @@ var package_default = {
2483
2490
  devDependencies: {
2484
2491
  "@tokens-studio/types": "0.5.2",
2485
2492
  "@types/apca-w3": "^0.1.3",
2486
- "@types/chroma-js": "^3.1.1",
2493
+ "@types/chroma-js": "^3.1.2",
2487
2494
  "@types/fs-extra": "^11.0.4",
2488
- "@types/node": "^22.18.11",
2495
+ "@types/node": "^22.19.0",
2489
2496
  "@types/object-hash": "^3.0.6",
2490
2497
  "@types/ramda": "^0.31.1",
2491
2498
  "fs-extra": "^11.3.2",
@@ -321,21 +321,26 @@ var colorCategorySchema = z.record(
321
321
  error: `Color names cannot include reserved names: ${RESERVED_COLORS.join(", ")}`
322
322
  }).describe("An object with one or more color definitions. The property name is used as the color name.");
323
323
  var colorModeOverrideSchema = z.object({
324
- light: colorSchema.optional(),
325
- dark: colorSchema.optional()
324
+ light: colorSchema.optional().describe("A hex color that overrides light mode"),
325
+ dark: colorSchema.optional().describe("A hex color that overrides dark mode")
326
326
  }).describe('Override values for semantic color tokens like "background-subtle", "border-default", etc.');
327
327
  var colorWeightOverrideSchema = z.partialRecord(z.enum([...colorNames]), colorModeOverrideSchema).describe('The name of the color to add overrides for, e.g. "accent"');
328
328
  var semanticColorOverrideSchema = z.record(z.string(), colorWeightOverrideSchema).describe("An object with color names as keys");
329
329
  var severityColorOverrideSchema = z.partialRecord(z.enum(baseColorNames), colorSchema.describe("A hex color, which is used for creating a color scale")).optional().describe("An object with severity color names as keys");
330
+ var linkVisitedOverrideSchema = z.object({
331
+ light: colorSchema.optional().describe("A hex color that overrides light mode"),
332
+ dark: colorSchema.optional().describe("A hex color that overrides dark mode")
333
+ }).describe('Overrides for the "link-visited" color');
330
334
  var overridesSchema = z.object({
331
335
  colors: semanticColorOverrideSchema.optional(),
332
- severity: severityColorOverrideSchema.optional()
336
+ severity: severityColorOverrideSchema.optional(),
337
+ linkVisited: linkVisitedOverrideSchema.optional()
333
338
  }).describe("Overrides for generated design tokens. Currently only supports colors defined in your theme").optional();
334
339
  var themeSchema = z.object({
335
340
  colors: z.object({
336
341
  main: colorCategorySchema,
337
342
  support: colorCategorySchema.optional().default({}),
338
- neutral: colorSchema
343
+ neutral: colorSchema.describe("A hex color, which is used for creating a color scale.")
339
344
  }).meta({ description: "Defines the colors for this theme" }),
340
345
  typography: z.object({
341
346
  fontFamily: z.string().meta({ description: "Sets the font-family for this theme" })
@@ -1783,6 +1783,7 @@ var generateColorScheme = (themeName, colorScheme2, colors, overrides) => {
1783
1783
  baseColorsWithOverrides
1784
1784
  );
1785
1785
  const linkColor = generateColor(generateColorScale(dsLinkColor, colorScheme2));
1786
+ const linkOverride = overrides?.linkVisited?.[colorScheme2] ? { $type: "color", $value: overrides.linkVisited[colorScheme2] } : void 0;
1786
1787
  return {
1787
1788
  [themeName]: {
1788
1789
  ...main,
@@ -1790,7 +1791,7 @@ var generateColorScheme = (themeName, colorScheme2, colors, overrides) => {
1790
1791
  neutral,
1791
1792
  ...globalColors,
1792
1793
  link: {
1793
- visited: linkColor[12]
1794
+ visited: linkOverride || linkColor[12]
1794
1795
  }
1795
1796
  }
1796
1797
  };
@@ -49,7 +49,7 @@ import pc4 from "picocolors";
49
49
  // package.json
50
50
  var package_default = {
51
51
  name: "@digdir/designsystemet",
52
- version: "1.7.1",
52
+ version: "1.7.3",
53
53
  description: "CLI for Designsystemet",
54
54
  author: "Designsystemet team",
55
55
  engines: {
@@ -101,7 +101,8 @@ var package_default = {
101
101
  "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
102
102
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
103
103
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
104
- test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
104
+ "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../internal/design-tokens --dry",
105
+ test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
105
106
  "digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
106
107
  "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
107
108
  "update:template": "tsx ./src/scripts/update-template.ts",
@@ -116,7 +117,7 @@ var package_default = {
116
117
  "change-case": "^5.4.4",
117
118
  "chroma-js": "^3.1.2",
118
119
  "colorjs.io": "^0.6.0-alpha.1",
119
- commander: "^14.0.1",
120
+ commander: "^14.0.2",
120
121
  "fast-glob": "^3.3.3",
121
122
  hsluv: "^1.0.1",
122
123
  "object-hash": "^3.0.0",
@@ -130,9 +131,9 @@ var package_default = {
130
131
  devDependencies: {
131
132
  "@tokens-studio/types": "0.5.2",
132
133
  "@types/apca-w3": "^0.1.3",
133
- "@types/chroma-js": "^3.1.1",
134
+ "@types/chroma-js": "^3.1.2",
134
135
  "@types/fs-extra": "^11.0.4",
135
- "@types/node": "^22.18.11",
136
+ "@types/node": "^22.19.0",
136
137
  "@types/object-hash": "^3.0.6",
137
138
  "@types/ramda": "^0.31.1",
138
139
  "fs-extra": "^11.3.2",
@@ -1,7 +1,7 @@
1
1
  // package.json
2
2
  var package_default = {
3
3
  name: "@digdir/designsystemet",
4
- version: "1.7.1",
4
+ version: "1.7.3",
5
5
  description: "CLI for Designsystemet",
6
6
  author: "Designsystemet team",
7
7
  engines: {
@@ -53,7 +53,8 @@ var package_default = {
53
53
  "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
54
54
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
55
55
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
56
- test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
56
+ "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../internal/design-tokens --dry",
57
+ test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
57
58
  "digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
58
59
  "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
59
60
  "update:template": "tsx ./src/scripts/update-template.ts",
@@ -68,7 +69,7 @@ var package_default = {
68
69
  "change-case": "^5.4.4",
69
70
  "chroma-js": "^3.1.2",
70
71
  "colorjs.io": "^0.6.0-alpha.1",
71
- commander: "^14.0.1",
72
+ commander: "^14.0.2",
72
73
  "fast-glob": "^3.3.3",
73
74
  hsluv: "^1.0.1",
74
75
  "object-hash": "^3.0.0",
@@ -82,9 +83,9 @@ var package_default = {
82
83
  devDependencies: {
83
84
  "@tokens-studio/types": "0.5.2",
84
85
  "@types/apca-w3": "^0.1.3",
85
- "@types/chroma-js": "^3.1.1",
86
+ "@types/chroma-js": "^3.1.2",
86
87
  "@types/fs-extra": "^11.0.4",
87
- "@types/node": "^22.18.11",
88
+ "@types/node": "^22.19.0",
88
89
  "@types/object-hash": "^3.0.6",
89
90
  "@types/ramda": "^0.31.1",
90
91
  "fs-extra": "^11.3.2",
@@ -1 +1 @@
1
- {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/create/generators/color.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAS,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAgBvD,eAAO,MAAM,mBAAmB,GAC9B,WAAW,MAAM,EACjB,aAAa,WAAW,EACxB,QAAQ,MAAM,EACd,YAAY,mBAAmB,KAC9B,QAkEF,CAAC"}
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../../src/tokens/create/generators/color.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAS,WAAW,EAAE,MAAM,0BAA0B,CAAC;AACnE,OAAO,KAAK,EAAE,mBAAmB,EAAE,MAAM,oBAAoB,CAAC;AAC9D,OAAO,KAAK,EAAE,MAAM,EAAS,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAgB9D,eAAO,MAAM,mBAAmB,GAC9B,WAAW,MAAM,EACjB,aAAa,WAAW,EACxB,QAAQ,MAAM,EACd,YAAY,mBAAmB,KAC9B,QAqEF,CAAC"}
@@ -389,6 +389,7 @@ var generateColorScheme = (themeName, colorScheme, colors, overrides) => {
389
389
  baseColorsWithOverrides
390
390
  );
391
391
  const linkColor = generateColor(generateColorScale(dsLinkColor, colorScheme));
392
+ const linkOverride = overrides?.linkVisited?.[colorScheme] ? { $type: "color", $value: overrides.linkVisited[colorScheme] } : void 0;
392
393
  return {
393
394
  [themeName]: {
394
395
  ...main,
@@ -396,7 +397,7 @@ var generateColorScheme = (themeName, colorScheme, colors, overrides) => {
396
397
  neutral,
397
398
  ...globalColors,
398
399
  link: {
399
- visited: linkColor[12]
400
+ visited: linkOverride || linkColor[12]
400
401
  }
401
402
  }
402
403
  };
@@ -46,7 +46,7 @@ var readFile = async (path2, dry, allowFileNotFound) => {
46
46
  // package.json
47
47
  var package_default = {
48
48
  name: "@digdir/designsystemet",
49
- version: "1.7.1",
49
+ version: "1.7.3",
50
50
  description: "CLI for Designsystemet",
51
51
  author: "Designsystemet team",
52
52
  engines: {
@@ -98,7 +98,8 @@ var package_default = {
98
98
  "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
99
99
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
100
100
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
101
- test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
101
+ "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../internal/design-tokens --dry",
102
+ test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
102
103
  "digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
103
104
  "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
104
105
  "update:template": "tsx ./src/scripts/update-template.ts",
@@ -113,7 +114,7 @@ var package_default = {
113
114
  "change-case": "^5.4.4",
114
115
  "chroma-js": "^3.1.2",
115
116
  "colorjs.io": "^0.6.0-alpha.1",
116
- commander: "^14.0.1",
117
+ commander: "^14.0.2",
117
118
  "fast-glob": "^3.3.3",
118
119
  hsluv: "^1.0.1",
119
120
  "object-hash": "^3.0.0",
@@ -127,9 +128,9 @@ var package_default = {
127
128
  devDependencies: {
128
129
  "@tokens-studio/types": "0.5.2",
129
130
  "@types/apca-w3": "^0.1.3",
130
- "@types/chroma-js": "^3.1.1",
131
+ "@types/chroma-js": "^3.1.2",
131
132
  "@types/fs-extra": "^11.0.4",
132
- "@types/node": "^22.18.11",
133
+ "@types/node": "^22.19.0",
133
134
  "@types/object-hash": "^3.0.6",
134
135
  "@types/ramda": "^0.31.1",
135
136
  "fs-extra": "^11.3.2",
@@ -1384,6 +1384,7 @@ var generateColorScheme = (themeName, colorScheme, colors, overrides) => {
1384
1384
  baseColorsWithOverrides
1385
1385
  );
1386
1386
  const linkColor = generateColor(generateColorScale(dsLinkColor, colorScheme));
1387
+ const linkOverride = overrides?.linkVisited?.[colorScheme] ? { $type: "color", $value: overrides.linkVisited[colorScheme] } : void 0;
1387
1388
  return {
1388
1389
  [themeName]: {
1389
1390
  ...main,
@@ -1391,7 +1392,7 @@ var generateColorScheme = (themeName, colorScheme, colors, overrides) => {
1391
1392
  neutral,
1392
1393
  ...globalColors,
1393
1394
  link: {
1394
- visited: linkColor[12]
1395
+ visited: linkOverride || linkColor[12]
1395
1396
  }
1396
1397
  }
1397
1398
  };
@@ -1717,6 +1717,7 @@ var generateColorScheme = (themeName, colorScheme2, colors, overrides) => {
1717
1717
  baseColorsWithOverrides
1718
1718
  );
1719
1719
  const linkColor = generateColor(generateColorScale(dsLinkColor, colorScheme2));
1720
+ const linkOverride = overrides?.linkVisited?.[colorScheme2] ? { $type: "color", $value: overrides.linkVisited[colorScheme2] } : void 0;
1720
1721
  return {
1721
1722
  [themeName]: {
1722
1723
  ...main,
@@ -1724,7 +1725,7 @@ var generateColorScheme = (themeName, colorScheme2, colors, overrides) => {
1724
1725
  neutral,
1725
1726
  ...globalColors,
1726
1727
  link: {
1727
- visited: linkColor[12]
1728
+ visited: linkOverride || linkColor[12]
1728
1729
  }
1729
1730
  }
1730
1731
  };
@@ -2190,7 +2191,7 @@ import * as R8 from "ramda";
2190
2191
  // package.json
2191
2192
  var package_default = {
2192
2193
  name: "@digdir/designsystemet",
2193
- version: "1.7.1",
2194
+ version: "1.7.3",
2194
2195
  description: "CLI for Designsystemet",
2195
2196
  author: "Designsystemet team",
2196
2197
  engines: {
@@ -2242,7 +2243,8 @@ var package_default = {
2242
2243
  "test:tokens-build-config-tailwind": "pnpm run designsystemet tokens build -t ./temp/config/design-tokens -o ./temp/config/build --clean --experimental-tailwind",
2243
2244
  "test:tokens-create-and-build-options": "pnpm test:tokens-create-options && pnpm test:tokens-build",
2244
2245
  "test:tokens-create-and-build-config": "pnpm test:tokens-create-config && pnpm test:tokens-build-config",
2245
- test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:tokens-create-and-build-config",
2246
+ "test:generate-config-from-tokens": "pnpm run designsystemet generate-config-from-tokens -d ../../internal/design-tokens --dry",
2247
+ test: "node -v && pnpm test:tokens-create-and-build-options && pnpm test:generate-config-from-tokens && pnpm test:tokens-create-and-build-config",
2246
2248
  "digdir:tokens-build": "pnpm run designsystemet tokens build -t ../../internal/design-tokens -o ../../packages/theme/brand --clean --experimental-tailwind",
2247
2249
  "digdir:tokens-create": "pnpm run designsystemet tokens create --config ./configs/digdir.config.json",
2248
2250
  "update:template": "tsx ./src/scripts/update-template.ts",
@@ -2257,7 +2259,7 @@ var package_default = {
2257
2259
  "change-case": "^5.4.4",
2258
2260
  "chroma-js": "^3.1.2",
2259
2261
  "colorjs.io": "^0.6.0-alpha.1",
2260
- commander: "^14.0.1",
2262
+ commander: "^14.0.2",
2261
2263
  "fast-glob": "^3.3.3",
2262
2264
  hsluv: "^1.0.1",
2263
2265
  "object-hash": "^3.0.0",
@@ -2271,9 +2273,9 @@ var package_default = {
2271
2273
  devDependencies: {
2272
2274
  "@tokens-studio/types": "0.5.2",
2273
2275
  "@types/apca-w3": "^0.1.3",
2274
- "@types/chroma-js": "^3.1.1",
2276
+ "@types/chroma-js": "^3.1.2",
2275
2277
  "@types/fs-extra": "^11.0.4",
2276
- "@types/node": "^22.18.11",
2278
+ "@types/node": "^22.19.0",
2277
2279
  "@types/object-hash": "^3.0.6",
2278
2280
  "@types/ramda": "^0.31.1",
2279
2281
  "fs-extra": "^11.3.2",
@@ -0,0 +1,11 @@
1
+ import type { CreateConfigSchema } from '../config.js';
2
+ export type GenerateConfigOptions = {
3
+ tokensDir: string;
4
+ outFile?: string;
5
+ dry?: boolean;
6
+ };
7
+ /**
8
+ * Generates a config file from existing design tokens
9
+ */
10
+ export declare function generateConfigFromTokens(options: GenerateConfigOptions): Promise<CreateConfigSchema>;
11
+ //# sourceMappingURL=generate-config.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"generate-config.d.ts","sourceRoot":"","sources":["../../../src/tokens/generate-config.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AA4MvD,MAAM,MAAM,qBAAqB,GAAG;IAClC,SAAS,EAAE,MAAM,CAAC;IAClB,OAAO,CAAC,EAAE,MAAM,CAAC;IACjB,GAAG,CAAC,EAAE,OAAO,CAAC;CACf,CAAC;AAEF;;GAEG;AACH,wBAAsB,wBAAwB,CAAC,OAAO,EAAE,qBAAqB,GAAG,OAAO,CAAC,kBAAkB,CAAC,CAoF1G"}
@@ -0,0 +1,202 @@
1
+ // src/tokens/generate-config.ts
2
+ import fs from "fs/promises";
3
+ import path from "path";
4
+ import pc from "picocolors";
5
+ async function readJsonFile(filePath) {
6
+ try {
7
+ const content = await fs.readFile(filePath, "utf-8");
8
+ return JSON.parse(content);
9
+ } catch (err) {
10
+ throw new Error(`Failed to read token file at ${filePath}: ${err instanceof Error ? err.message : String(err)}`);
11
+ }
12
+ }
13
+ function extractBaseColor(colorScale) {
14
+ if ("12" in colorScale && typeof colorScale["12"] === "object" && "$value" in colorScale["12"]) {
15
+ const token = colorScale["12"];
16
+ if (token.$type === "color") {
17
+ return token.$value;
18
+ }
19
+ }
20
+ return null;
21
+ }
22
+ async function discoverThemes(tokensDir) {
23
+ const lightModePath = path.join(tokensDir, "themes");
24
+ try {
25
+ const files = await fs.readdir(lightModePath);
26
+ const themes = files.filter((file) => file.endsWith(".json")).map((file) => file.replace(".json", ""));
27
+ return themes;
28
+ } catch {
29
+ throw new Error(`Could not find themes. Make sure ${pc.blue(lightModePath)} exists and contains theme JSON files.`);
30
+ }
31
+ }
32
+ async function readThemeTokens(tokensDir, themeName) {
33
+ const themePath = path.join(tokensDir, "primitives", "modes", "color-scheme", "light", `${themeName}.json`);
34
+ return readJsonFile(themePath);
35
+ }
36
+ async function readThemeConfig(tokensDir, themeName) {
37
+ const themeConfigPath = path.join(tokensDir, "themes", `${themeName}.json`);
38
+ try {
39
+ return await readJsonFile(themeConfigPath);
40
+ } catch {
41
+ return null;
42
+ }
43
+ }
44
+ function extractBorderRadius(themeConfig) {
45
+ if (!themeConfig || !("border-radius" in themeConfig)) {
46
+ return void 0;
47
+ }
48
+ const borderRadius = themeConfig["border-radius"];
49
+ if ("base" in borderRadius && typeof borderRadius.base === "object" && "$value" in borderRadius.base) {
50
+ const token = borderRadius.base;
51
+ return Number(token.$value);
52
+ }
53
+ return void 0;
54
+ }
55
+ function extractFontFamily(themeConfig) {
56
+ if (!themeConfig || !("font-family" in themeConfig)) {
57
+ return void 0;
58
+ }
59
+ const fontFamily = themeConfig["font-family"];
60
+ if (typeof fontFamily === "object" && "$value" in fontFamily) {
61
+ const token = fontFamily;
62
+ const value = token.$value;
63
+ if (value.startsWith("{") && value.endsWith("}")) {
64
+ return void 0;
65
+ }
66
+ return value;
67
+ }
68
+ return void 0;
69
+ }
70
+ async function readTypographyConfig(tokensDir, themeName) {
71
+ const typographyConfigPath = path.join(
72
+ tokensDir,
73
+ "primitives",
74
+ "modes",
75
+ "typography",
76
+ "primary",
77
+ `${themeName}.json`
78
+ );
79
+ try {
80
+ return await readJsonFile(typographyConfigPath);
81
+ } catch {
82
+ return null;
83
+ }
84
+ }
85
+ function extractFontFamilyFromPrimitives(typographyConfig, themeName) {
86
+ if (!typographyConfig) {
87
+ return void 0;
88
+ }
89
+ const themeTypography = typographyConfig[themeName];
90
+ if (!themeTypography || !("font-family" in themeTypography)) {
91
+ return void 0;
92
+ }
93
+ const fontFamily = themeTypography["font-family"];
94
+ if (typeof fontFamily === "object" && "$value" in fontFamily) {
95
+ const token = fontFamily;
96
+ return token.$value;
97
+ }
98
+ return void 0;
99
+ }
100
+ function categorizeColors(themeTokens, themeName) {
101
+ const main = {};
102
+ const support = {};
103
+ let neutral = null;
104
+ const builtInColors = ["neutral", "info", "success", "warning", "danger"];
105
+ const specialKeys = ["link"];
106
+ const themeColors = themeTokens[themeName];
107
+ if (!themeColors) {
108
+ return { main, support, neutral };
109
+ }
110
+ for (const [colorName, colorValue] of Object.entries(themeColors)) {
111
+ if (specialKeys.includes(colorName)) {
112
+ continue;
113
+ }
114
+ if (typeof colorValue === "object" && !("$value" in colorValue)) {
115
+ const baseColor = extractBaseColor(colorValue);
116
+ if (baseColor) {
117
+ if (colorName === "neutral") {
118
+ neutral = baseColor;
119
+ } else if (builtInColors.includes(colorName)) {
120
+ } else if (colorName === "accent") {
121
+ main[colorName] = baseColor;
122
+ } else {
123
+ support[colorName] = baseColor;
124
+ }
125
+ }
126
+ }
127
+ }
128
+ return { main, support, neutral };
129
+ }
130
+ async function generateConfigFromTokens(options) {
131
+ const { tokensDir, dry = false } = options;
132
+ console.log(`
133
+ Reading tokens from ${pc.blue(tokensDir)}`);
134
+ const themes = await discoverThemes(tokensDir);
135
+ if (themes.length === 0) {
136
+ throw new Error(`
137
+ No themes found in ${pc.blue(tokensDir)}`);
138
+ }
139
+ console.log(`
140
+ Found ${pc.green(String(themes.length))} theme(s): ${themes.map((t) => pc.cyan(t)).join(", ")}`);
141
+ const config = {
142
+ outDir: tokensDir,
143
+ themes: {}
144
+ };
145
+ for (const themeName of themes) {
146
+ console.log(`
147
+ Processing theme ${pc.cyan(themeName)}...`);
148
+ const themeTokens = await readThemeTokens(tokensDir, themeName);
149
+ const themeConfig = await readThemeConfig(tokensDir, themeName);
150
+ const typographyConfig = await readTypographyConfig(tokensDir, themeName);
151
+ const { main, support, neutral } = categorizeColors(themeTokens, themeName);
152
+ if (Object.keys(main).length === 0) {
153
+ console.warn(pc.yellow(`
154
+ Warning: No main colors found for theme ${themeName}`));
155
+ }
156
+ if (!neutral) {
157
+ console.warn(pc.yellow(`
158
+ Warning: No neutral color found for theme ${themeName}`));
159
+ continue;
160
+ }
161
+ const borderRadius = extractBorderRadius(themeConfig);
162
+ const fontFamily = extractFontFamily(themeConfig) ?? extractFontFamilyFromPrimitives(typographyConfig, themeName);
163
+ config.themes[themeName] = {
164
+ colors: {
165
+ main,
166
+ support,
167
+ neutral
168
+ },
169
+ borderRadius,
170
+ typography: fontFamily ? { fontFamily } : void 0
171
+ };
172
+ console.log(
173
+ `
174
+ \u2705 Main colors: ${Object.keys(main).map((c) => pc.cyan(c)).join(", ") || pc.dim("none")}`
175
+ );
176
+ console.log(
177
+ `
178
+ \u2705 Support colors: ${Object.keys(support).map((c) => pc.cyan(c)).join(", ") || pc.dim("none")}`
179
+ );
180
+ console.log(`
181
+ \u2705 Neutral: ${pc.cyan(neutral)}`);
182
+ if (borderRadius !== void 0) {
183
+ console.log(`
184
+ \u2705 Border radius: ${pc.cyan(String(borderRadius))}`);
185
+ }
186
+ if (fontFamily) {
187
+ console.log(`
188
+ \u2705 Font family: ${pc.cyan(fontFamily)}`);
189
+ }
190
+ }
191
+ if (!dry && options.outFile) {
192
+ const configJson = JSON.stringify(config, null, 2);
193
+ await fs.writeFile(options.outFile, configJson, "utf-8");
194
+ console.log();
195
+ console.log(`
196
+ \u2705 Config file written to ${pc.blue(options.outFile)}`);
197
+ }
198
+ return config;
199
+ }
200
+ export {
201
+ generateConfigFromTokens
202
+ };