@madgex/design-system 5.11.3 → 6.0.1

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 (69) hide show
  1. package/README.md +5 -21
  2. package/dist/_tokens/css/_tokens.css +62 -96
  3. package/dist/_tokens/js/_tokens-module.js +1342 -1406
  4. package/dist/_tokens/sketch/_tokens.sketchpalette +1 -1
  5. package/dist/assets/icons.json +1 -1
  6. package/dist/css/index.css +1 -1
  7. package/dist/js/index-fractal.js +1 -1
  8. package/dist/js/index.js +1 -1
  9. package/package.json +4 -4
  10. package/src/components/_preview.njk +1 -0
  11. package/src/components/button/button.scss +50 -37
  12. package/src/components/card/README.md +1 -1
  13. package/src/components/card/_template.njk +1 -1
  14. package/src/components/card/card.config.js +1 -2
  15. package/src/components/card/card.scss +29 -39
  16. package/src/components/icons/README.md +3 -3
  17. package/src/components/icons/icons.scss +26 -19
  18. package/src/components/inputs/_form-elements.scss +44 -44
  19. package/src/components/inputs/checkbox-pill/checkbox-pill.scss +14 -14
  20. package/src/components/inputs/combobox/combobox.scss +13 -13
  21. package/src/components/inputs/file-upload/file-upload.scss +14 -14
  22. package/src/components/inputs/input-number/input-number.scss +10 -10
  23. package/src/components/inputs/text-editor/text-editor.scss +16 -16
  24. package/src/components/modal/modal.js +1 -1
  25. package/src/components/modal/modal.scss +4 -4
  26. package/src/components/notification/notification.scss +1 -1
  27. package/src/components/pagination/pagination.scss +8 -8
  28. package/src/components/popover/popover.js +1 -1
  29. package/src/components/popover/popover.scss +13 -13
  30. package/src/components/section-title/section-title.scss +1 -1
  31. package/src/components/skip-link/skip-link.scss +4 -4
  32. package/src/components/tabs/tabs.js +1 -1
  33. package/src/components/tabs/tabs.scss +16 -16
  34. package/src/components/toggle-button-links/toggle-button-links.scss +20 -20
  35. package/src/helpers/spacing/README.md +2 -2
  36. package/src/layout/grid/README.md +4 -4
  37. package/src/scss/constants/__index.scss +2 -0
  38. package/src/scss/constants/_sd-tokens.scss +81 -0
  39. package/src/scss/constants/_vars.scss +4 -0
  40. package/src/scss/core/_containers.scss +35 -38
  41. package/src/scss/core/_defaults.scss +14 -8
  42. package/src/scss/core/_grid.scss +20 -23
  43. package/src/scss/core/_lists.scss +13 -13
  44. package/src/scss/core/_message.scss +32 -32
  45. package/src/scss/core/_typography.scss +13 -13
  46. package/src/scss/functions/__index.scss +0 -2
  47. package/src/scss/functions/_media-queries.scss +4 -4
  48. package/src/scss/functions/_text-contrast.scss +6 -7
  49. package/src/scss/helpers/_borders.scss +5 -38
  50. package/src/scss/helpers/_display.scss +0 -1
  51. package/src/scss/helpers/_edited-text.scss +5 -5
  52. package/src/scss/helpers/_floats.scss +0 -1
  53. package/src/scss/helpers/_font-types.scss +15 -15
  54. package/src/scss/helpers/_spacing.scss +33 -36
  55. package/src/scss/helpers/_text-align.scss +0 -1
  56. package/src/scss/helpers/_vertical-align.scss +0 -2
  57. package/src/scss/helpers/_width-height.scss +4 -6
  58. package/src/scss/import.scss +1 -0
  59. package/src/scss/index.scss +0 -2
  60. package/src/tokens/_config.js +24 -10
  61. package/src/tokens/_constants.json +130 -0
  62. package/src/tokens/color.json +8 -76
  63. package/src/tokens/custom.json +0 -8
  64. package/src/tokens/size.json +0 -16
  65. package/src/tokens/typography.json +3 -1
  66. package/tasks/registerTransforms.js +28 -1
  67. package/dist/_tokens/scss/_tokens.scss +0 -741
  68. package/src/scss/functions/_color.scss +0 -0
  69. package/src/scss/functions/_px2rem.scss +0 -20
@@ -1,4 +1,3 @@
1
- $breakpoints: map-get(map-get($tokens, 'size'), 'breakpoint');
2
1
  $positions: left, right, none;
3
2
 
4
3
  @each $position in $positions {
@@ -1,5 +1,7 @@
1
- // getting the font-types from the tokens
2
- $font-types: map-get(map-get($tokens, 'font'), 'type');
1
+ $font-types: 'canon', 'trafalgar', 'paragon', 'double-pica', 'great-primer', 'body-copy', 'body-copy-bulk', 'pica',
2
+ 'long-primer', 'brevier', 'minion';
3
+
4
+ $breakpoint-names: map-keys(map-remove($breakpoints, 'xl'));
3
5
 
4
6
  // loop will create all the classes for the font types in the tokens array
5
7
  // it will also generate the media queries related to each font type, using the mq helper
@@ -7,30 +9,28 @@ $font-types: map-get(map-get($tokens, 'font'), 'type');
7
9
  // .mds-font-canon{
8
10
  // font-size: 28px;
9
11
  // line-height: 1.15;
10
- // @media (min-width: $mds-size-breakpoint-sm){
12
+ // @media (min-width: $scss-var-size-breakpoint-sm){
11
13
  // font-size: 32px;
12
14
  // line-height: 1.13;
13
15
  // }
14
- // @media (min-width: $mds-size-breakpoint-md){
16
+ // @media (min-width: $scss-var-size-breakpoint-md){
15
17
  // font-size: 52px;
16
18
  // line-height: 1.08;
17
19
  // }
18
- // @media (min-width: $mds-size-breakpoint-lg){
20
+ // @media (min-width: $scss-var-size-breakpoint-lg){
19
21
  // font-size: 44px;
20
22
  // line-height: 1.1;
21
23
  // }
22
24
  // }
23
- @each $typename, $typevalue in $font-types {
25
+ @each $typename in $font-types {
24
26
  .mds-font-#{$typename} {
25
- @each $bpname, $props in $typevalue {
26
- @if $bpname == 'default' {
27
- font-size: px2rem(map-get($props, 'size'));
28
- line-height: map-get($props, 'line-height');
29
- } @else {
30
- @include mq($from: $bpname) {
31
- font-size: px2rem(map-get($props, 'size'));
32
- line-height: map-get($props, 'line-height');
33
- }
27
+ @each $bpname in $breakpoint-names {
28
+ font-size: var(--mds-font-type-#{$typename}-default-size);
29
+ line-height: var(--mds-font-type-#{$typename}-default-line-height);
30
+
31
+ @include mq($from: $bpname) {
32
+ font-size: var(--mds-font-type-#{$typename}-#{$bpname}-size);
33
+ line-height: var(--mds-font-type-#{$typename}-#{$bpname}-line-height);
34
34
  }
35
35
  }
36
36
  }
@@ -1,4 +1,3 @@
1
- $breakpoints: map-get(map-get($tokens, 'size'), 'breakpoint');
2
1
  $positions: top, right, bottom, left;
3
2
 
4
3
  // There are 2 loops as the more specific classes with positions have to be declared before the shorthand ones
@@ -6,10 +5,10 @@ $positions: top, right, bottom, left;
6
5
 
7
6
  @for $i from 0 through 10 {
8
7
  .mds-padding-b#{$i} {
9
- padding: $mds-size-baseline * $i;
8
+ padding: $scss-var-size-baseline * $i;
10
9
  }
11
10
  .mds-margin-b#{$i} {
12
- margin: $mds-size-baseline * $i;
11
+ margin: $scss-var-size-baseline * $i;
13
12
  }
14
13
  }
15
14
 
@@ -17,10 +16,10 @@ $positions: top, right, bottom, left;
17
16
  @each $bpname, $value in $breakpoints {
18
17
  @include mq($from: $bpname) {
19
18
  .mds-padding-#{$bpname}-b#{$i} {
20
- padding: $mds-size-baseline * $i;
19
+ padding: $scss-var-size-baseline * $i;
21
20
  }
22
21
  .mds-margin-#{$bpname}-b#{$i} {
23
- margin: $mds-size-baseline * $i;
22
+ margin: $scss-var-size-baseline * $i;
24
23
  }
25
24
  }
26
25
  }
@@ -29,28 +28,28 @@ $positions: top, right, bottom, left;
29
28
  @for $i from 0 through 10 {
30
29
  @each $position in $positions {
31
30
  .mds-padding-#{$position}-b#{$i} {
32
- padding-#{$position}: $mds-size-baseline * $i;
31
+ padding-#{$position}: $scss-var-size-baseline * $i;
33
32
  }
34
33
  .mds-margin-#{$position}-b#{$i} {
35
- margin-#{$position}: $mds-size-baseline * $i;
34
+ margin-#{$position}: $scss-var-size-baseline * $i;
36
35
  }
37
36
  }
38
37
  .mds-padding-x-b#{$i} {
39
- padding-left: $mds-size-baseline * $i;
40
- padding-right: $mds-size-baseline * $i;
38
+ padding-left: $scss-var-size-baseline * $i;
39
+ padding-right: $scss-var-size-baseline * $i;
41
40
  }
42
41
  .mds-padding-y-b#{$i} {
43
- padding-top: $mds-size-baseline * $i;
44
- padding-bottom: $mds-size-baseline * $i;
42
+ padding-top: $scss-var-size-baseline * $i;
43
+ padding-bottom: $scss-var-size-baseline * $i;
45
44
  }
46
45
 
47
46
  .mds-margin-x-b#{$i} {
48
- margin-left: $mds-size-baseline * $i;
49
- margin-right: $mds-size-baseline * $i;
47
+ margin-left: $scss-var-size-baseline * $i;
48
+ margin-right: $scss-var-size-baseline * $i;
50
49
  }
51
50
  .mds-margin-y-b#{$i} {
52
- margin-top: $mds-size-baseline * $i;
53
- margin-bottom: $mds-size-baseline * $i;
51
+ margin-top: $scss-var-size-baseline * $i;
52
+ margin-bottom: $scss-var-size-baseline * $i;
54
53
  }
55
54
  }
56
55
 
@@ -59,35 +58,33 @@ $positions: top, right, bottom, left;
59
58
  @each $bpname, $value in $breakpoints {
60
59
  @include mq($from: $bpname) {
61
60
  .mds-padding-#{$position}-#{$bpname}-b#{$i} {
62
- padding-#{$position}: $mds-size-baseline * $i;
61
+ padding-#{$position}: $scss-var-size-baseline * $i;
63
62
  }
64
63
  .mds-margin-#{$position}-#{$bpname}-b#{$i} {
65
- margin-#{$position}: $mds-size-baseline * $i;
64
+ margin-#{$position}: $scss-var-size-baseline * $i;
66
65
  }
67
66
  }
68
67
  }
69
68
  }
70
69
  @each $bpname, $value in $breakpoints {
71
70
  @include mq($from: $bpname) {
71
+ .mds-padding-x-#{$bpname}-b#{$i} {
72
+ padding-left: $scss-var-size-baseline * $i;
73
+ padding-right: $scss-var-size-baseline * $i;
74
+ }
75
+ .mds-padding-y-#{$bpname}-b#{$i} {
76
+ padding-top: $scss-var-size-baseline * $i;
77
+ padding-bottom: $scss-var-size-baseline * $i;
78
+ }
72
79
 
73
- .mds-padding-x-#{$bpname}-b#{$i} {
74
- padding-left: $mds-size-baseline * $i;
75
- padding-right: $mds-size-baseline * $i;
76
- }
77
- .mds-padding-y-#{$bpname}-b#{$i} {
78
- padding-top: $mds-size-baseline * $i;
79
- padding-bottom: $mds-size-baseline * $i;
80
- }
81
-
82
- .mds-margin-x-#{$bpname}-b#{$i} {
83
- margin-left: $mds-size-baseline * $i;
84
- margin-right: $mds-size-baseline * $i;
85
- }
86
- .mds-margin-y-#{$bpname}-b#{$i} {
87
- margin-top: $mds-size-baseline * $i;
88
- margin-bottom: $mds-size-baseline * $i;
80
+ .mds-margin-x-#{$bpname}-b#{$i} {
81
+ margin-left: $scss-var-size-baseline * $i;
82
+ margin-right: $scss-var-size-baseline * $i;
83
+ }
84
+ .mds-margin-y-#{$bpname}-b#{$i} {
85
+ margin-top: $scss-var-size-baseline * $i;
86
+ margin-bottom: $scss-var-size-baseline * $i;
87
+ }
88
+ }
89
89
  }
90
90
  }
91
- }
92
-
93
- }
@@ -1,4 +1,3 @@
1
- $breakpoints: map-get(map-get($tokens, 'size'), 'breakpoint');
2
1
  $positions: left, right, center;
3
2
 
4
3
  @each $position in $positions {
@@ -1,5 +1,3 @@
1
-
2
- $breakpoints: map-get(map-get($tokens, 'size'), 'breakpoint');
3
1
  $positions: top, middle, bottom;
4
2
 
5
3
  @each $position in $positions {
@@ -1,10 +1,8 @@
1
- $breakpoints: map-get(map-get($tokens, 'size'), 'breakpoint');
2
-
3
1
  .mds-width-full {
4
- width: 100%;
2
+ width: 100%;
5
3
  }
6
4
  .mds-width-auto {
7
- width: auto;
5
+ width: auto;
8
6
  }
9
7
 
10
8
  @each $bpname, $value in $breakpoints {
@@ -13,11 +11,11 @@ $breakpoints: map-get(map-get($tokens, 'size'), 'breakpoint');
13
11
  width: 100%;
14
12
  }
15
13
  .mds-width-#{$bpname}-auto {
16
- width: auto;
14
+ width: auto;
17
15
  }
18
16
  }
19
17
  }
20
18
 
21
19
  .mds-height-full {
22
20
  height: 100%;
23
- }
21
+ }
@@ -1,4 +1,5 @@
1
1
  @use "sass:math";
2
+ @import 'constants/_index';
2
3
  @import 'vendor/normalize';
3
4
  @import 'resets/_index';
4
5
  @import 'functions/_index';
@@ -1,3 +1 @@
1
- @import '~../../dist/_tokens/scss/tokens';
2
-
3
1
  @import './import.scss';
@@ -1,31 +1,45 @@
1
1
  const path = require('path');
2
2
 
3
3
  const config = {
4
- source: [path.resolve(__dirname, '../tokens/*.json')],
4
+ // This source path needs to be in posix because combineJSON util inside style dictionary only accepts that
5
+ source: [path.resolve(__dirname, '../tokens/*.json').split(path.sep).join(path.posix.sep)],
5
6
  platforms: {
6
7
  'css-variables': {
7
8
  // transformGroup: 'css',
8
- transforms: ['attribute/cti', 'name/cti/kebab', 'time/seconds', 'content/icon', 'color/css', 'css/rawData'],
9
+ transforms: [
10
+ 'attribute/cti',
11
+ 'name/cti/kebab',
12
+ 'time/seconds',
13
+ 'content/icon',
14
+ 'color/css',
15
+ 'css/rawData',
16
+ 'custom/pxToRem',
17
+ ],
9
18
  buildPath: `${path.resolve(__dirname, '../../dist/_tokens/css/')}/`,
10
19
  prefix: 'mds',
11
20
  files: [
12
21
  {
13
22
  destination: '_tokens.css',
14
23
  format: 'css/variables',
24
+ filter: 'removePrivate',
15
25
  },
16
26
  ],
17
27
  },
18
28
  'scss-variables': {
19
- // transformGroup: 'web',
20
- // transforms: ['size/px']
21
- transforms: ['attribute/cti', 'name/cti/kebab', 'color/css', 'css/rawData'],
22
- buildPath: `${path.resolve(__dirname, '../../dist/_tokens/scss/')}/`,
23
- prefix: 'mds',
29
+ transforms: ['attribute/cti', 'name/cti/kebab'],
30
+ buildPath: `${path.resolve(__dirname, '../scss/constants/')}/`,
31
+ prefix: 'scss-var',
24
32
  files: [
25
33
  {
26
- destination: '_tokens.scss',
27
- // format: 'scss/variables',
34
+ destination: '_sd-tokens.scss',
28
35
  format: 'scss/map-deep',
36
+ options: {
37
+ themeable: false,
38
+ },
39
+ filter(token) {
40
+ // only keep "private" tokens aka constants
41
+ return !!(token && token.private);
42
+ },
29
43
  },
30
44
  ],
31
45
  },
@@ -67,7 +81,7 @@ const config = {
67
81
  // ],
68
82
  // },
69
83
  'js-module': {
70
- transformGroup: 'js',
84
+ transforms: ['attribute/cti', 'name/cti/pascal', 'custom/pxToRem'],
71
85
  buildPath: `${path.resolve(__dirname, '../../dist/_tokens/js/')}/`,
72
86
  prefix: 'mds',
73
87
  files: [
@@ -0,0 +1,130 @@
1
+ {
2
+ "color": {
3
+ "neutral": {
4
+ "white": {
5
+ "value" : "#FFFFFF",
6
+ "private": true
7
+ },
8
+ "black": {
9
+ "value" : "#000000",
10
+ "private": true
11
+ },
12
+ "base": {
13
+ "value" : "#707070",
14
+ "private": true
15
+ },
16
+ "light": {
17
+ "value" : "#949494",
18
+ "private": true
19
+ },
20
+ "lighter": {
21
+ "value" : "#DDDDDD",
22
+ "private": true
23
+ },
24
+ "lightest": {
25
+ "value" : "#F8F8F8",
26
+ "private": true
27
+ },
28
+ "darker": {
29
+ "value" : "#333333",
30
+ "private": true
31
+ }
32
+ },
33
+ "status": {
34
+ "error": {
35
+ "light": {
36
+ "value" : "#fd0826",
37
+ "private": true
38
+ },
39
+ "lightest": {
40
+ "value" : "#ffe3e6",
41
+ "private": true
42
+ },
43
+ "dark": {
44
+ "value" : "#d0021b",
45
+ "private": true
46
+ },
47
+ "darkest": {
48
+ "value" : "#ae0216",
49
+ "private": true
50
+ },
51
+ "base": {
52
+ "value" : "#e1021d",
53
+ "private": true
54
+ }
55
+ },
56
+ "success": {
57
+ "light": {
58
+ "value" : "#6ac52d",
59
+ "private": true
60
+ },
61
+ "lightest": {
62
+ "value" : "#f0faea",
63
+ "private": true
64
+ },
65
+ "dark": {
66
+ "value" : "#549b24",
67
+ "private": true
68
+ },
69
+ "darkest": {
70
+ "value" : "#40791B",
71
+ "private": true
72
+ },
73
+ "base": {
74
+ "value" : "#5ba927",
75
+ "private": true
76
+ }
77
+ },
78
+ "info": {
79
+ "light": {
80
+ "value" : "#ffc442",
81
+ "private": true
82
+ },
83
+ "lightest": {
84
+ "value" : "#fff7e5",
85
+ "private": true
86
+ },
87
+ "dark": {
88
+ "value" : "#f4aa08",
89
+ "private": true
90
+ },
91
+ "darkest": {
92
+ "value" : "#946500",
93
+ "private": true
94
+ },
95
+ "base": {
96
+ "value" : "#ffb411",
97
+ "private": true
98
+ }
99
+ }
100
+ }
101
+ },
102
+ "size": {
103
+ "baseline": {
104
+ "value": "4px",
105
+ "private": true
106
+ },
107
+ "breakpoint": {
108
+ "sm": {
109
+ "value": "400px",
110
+ "private": true
111
+ },
112
+ "md": {
113
+ "value": "600px",
114
+ "private": true
115
+ },
116
+ "lg": {
117
+ "value": "1008px",
118
+ "private": true
119
+ },
120
+ "xl": {
121
+ "value": "1280px",
122
+ "private": true
123
+ }
124
+ },
125
+ "gutter-width": {
126
+ "value": "20px",
127
+ "private": true
128
+ }
129
+ }
130
+ }
@@ -53,59 +53,6 @@
53
53
  }
54
54
  }
55
55
  },
56
- "status": {
57
- "error": {
58
- "light": {
59
- "value" : "#fd0826"
60
- },
61
- "lightest": {
62
- "value" : "#ffe3e6"
63
- },
64
- "dark": {
65
- "value" : "#d0021b"
66
- },
67
- "darkest": {
68
- "value" : "#ae0216"
69
- },
70
- "base": {
71
- "value" : "#e1021d"
72
- }
73
- },
74
- "success": {
75
- "light": {
76
- "value" : "#6ac52d"
77
- },
78
- "lightest": {
79
- "value" : "#f0faea"
80
- },
81
- "dark": {
82
- "value" : "#549b24"
83
- },
84
- "darkest": {
85
- "value" : "#40791B"
86
- },
87
- "base": {
88
- "value" : "#5ba927"
89
- }
90
- },
91
- "info": {
92
- "light": {
93
- "value" : "#ffc442"
94
- },
95
- "lightest": {
96
- "value" : "#fff7e5"
97
- },
98
- "dark": {
99
- "value" : "#f4aa08"
100
- },
101
- "darkest": {
102
- "value" : "#946500"
103
- },
104
- "base": {
105
- "value" : "#ffb411"
106
- }
107
- }
108
- },
109
56
  "background": {
110
57
  "body": {
111
58
  "value" : "{color.neutral.white.value}"
@@ -120,29 +67,6 @@
120
67
  "value" : "rgba(0,0,0,0)"
121
68
  }
122
69
  },
123
- "neutral": {
124
- "white": {
125
- "value" : "#FFFFFF"
126
- },
127
- "black": {
128
- "value" : "#000000"
129
- },
130
- "base": {
131
- "value" : "#707070"
132
- },
133
- "light": {
134
- "value" : "#949494"
135
- },
136
- "lighter": {
137
- "value" : "#DDDDDD"
138
- },
139
- "lightest": {
140
- "value" : "#F8F8F8"
141
- },
142
- "darker": {
143
- "value" : "#333333"
144
- }
145
- },
146
70
  "text": {
147
71
  "base": {
148
72
  "value" : "#343433"
@@ -281,6 +205,14 @@
281
205
  "value" : "{color.pill.text.base.value}"
282
206
  }
283
207
  }
208
+ },
209
+ "new-badge": {
210
+ "background": {
211
+ "value" : "#40791B"
212
+ },
213
+ "text": {
214
+ "value" : "#fff"
215
+ }
284
216
  }
285
217
  }
286
218
  }
@@ -8,14 +8,6 @@
8
8
  "color": {
9
9
  "value" : "#fff"
10
10
  }
11
- },
12
- "2": {
13
- "background": {
14
- "value" : "#40791B"
15
- },
16
- "color": {
17
- "value" : "#fff"
18
- }
19
11
  }
20
12
  },
21
13
  "card": {
@@ -1,12 +1,5 @@
1
1
  {
2
2
  "size": {
3
- "baseline": { "value": "4px" },
4
- "breakpoint": {
5
- "sm": { "value": "400px" },
6
- "md": { "value": "600px" },
7
- "lg": { "value": "1008px" },
8
- "xl": { "value": "1280px" }
9
- },
10
3
  "border": {
11
4
  "width": {
12
5
  "base": {
@@ -28,7 +21,6 @@
28
21
  }
29
22
  }
30
23
  },
31
- "gutter-width": { "value": "20px" },
32
24
  "container": {
33
25
  "width": {
34
26
  "value": "100%"
@@ -64,14 +56,6 @@
64
56
  "value": "0 auto"
65
57
  }
66
58
  },
67
- "icon": {
68
- "default": { "value": "1em" },
69
- "sm": { "value": "16px" },
70
- "md": { "value": "24px" },
71
- "lg": { "value": "32px" },
72
- "xl": { "value": "48px" },
73
- "xxl": { "value": "72px" }
74
- },
75
59
  "height": {
76
60
  "ad-container": {
77
61
  "leaderboard": {
@@ -61,7 +61,9 @@
61
61
  "type": {
62
62
  "canon": {
63
63
  "default": {
64
- "size": { "value": "28px" },
64
+ "size": {
65
+ "value": "28px"
66
+ },
65
67
  "line-height": { "value": "1.15" }
66
68
  },
67
69
  "sm": {
@@ -1,4 +1,4 @@
1
- function registerTransforms(StyleDictionary) {
1
+ function registerTransforms(StyleDictionary, tokenBaseFontSize) {
2
2
  return new Promise((resolve) => {
3
3
  StyleDictionary.registerTransform({
4
4
  name: 'css/rawData',
@@ -10,6 +10,33 @@ function registerTransforms(StyleDictionary) {
10
10
  return prop.rawData;
11
11
  },
12
12
  });
13
+ StyleDictionary.registerTransform({
14
+ name: 'custom/pxToRem',
15
+ type: 'value',
16
+ matcher(token) {
17
+ return (
18
+ token.attributes.category === 'font' && token.attributes.type === 'type' && token.attributes.state === 'size'
19
+ );
20
+ },
21
+ transformer(token) {
22
+ const baseFontSize = tokenBaseFontSize ? parseFloat(tokenBaseFontSize) : 16; // default to 16px
23
+ const tokenValue = parseFloat(token.value);
24
+
25
+ if (Number.isNaN(tokenBaseFontSize)) {
26
+ throw new Error(`Invalid number for base font size: ${tokenBaseFontSize}`);
27
+ }
28
+
29
+ if (Number.isNaN(tokenValue)) {
30
+ throw new Error(`Invalid number: ${token.value}. Could not convert ${token.name} to rem`);
31
+ }
32
+
33
+ if (tokenValue === 0) {
34
+ return '0';
35
+ }
36
+
37
+ return `${tokenValue / baseFontSize}rem`;
38
+ },
39
+ });
13
40
  resolve('Transform registered');
14
41
  });
15
42
  }