@madgex/design-system 9.3.1 → 10.0.0
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.
- package/README.md +52 -1
- package/dist/_tokens/css/{_tokens.css → variables.css} +3 -4
- package/dist/_tokens/js/_tokens-module.js +2599 -3884
- package/dist/_tokens/json/{_tokens-flat.json → variables-flat.json} +2 -28
- package/dist/_tokens/json/variables.json +331 -0
- package/dist/assets/icons.json +1 -1
- package/dist/js/index.js +1 -1
- package/package.json +14 -17
- package/src/components/_preview.njk +1 -1
- package/src/components/modal/modal.js +1 -1
- package/src/components/popover/popover.js +1 -1
- package/src/components/tabs/tabs.js +1 -1
- package/src/scss/constants/_sd-tokens.scss +1 -2
- package/src/tokens/_constants.json +35 -33
- package/src/tokens/color.json +64 -63
- package/src/tokens/custom.json +11 -7
- package/src/tokens/effects.json +4 -3
- package/src/tokens/email.json +30 -27
- package/src/tokens/size.json +16 -15
- package/src/tokens/typography.json +68 -62
- package/style-dictionary/color-transforms.js +143 -0
- package/style-dictionary/index.js +215 -0
- package/tasks/tokens.js +8 -26
- package/dist/_tokens/json/_tokens-nested.json +0 -4024
- package/src/tokens/_config.js +0 -181
- package/tasks/colorTransforms.js +0 -65
- package/tasks/registerTransforms.js +0 -17
package/src/tokens/email.json
CHANGED
|
@@ -1,62 +1,63 @@
|
|
|
1
1
|
{
|
|
2
2
|
"email": {
|
|
3
3
|
"color": {
|
|
4
|
+
"$type": "color",
|
|
4
5
|
"link": {
|
|
5
6
|
"base": {
|
|
6
|
-
"value"
|
|
7
|
+
"$value": "{color.link.base}"
|
|
7
8
|
},
|
|
8
9
|
"hover": {
|
|
9
|
-
"value"
|
|
10
|
+
"$value": "{color.link.hover}"
|
|
10
11
|
}
|
|
11
12
|
},
|
|
12
13
|
"button": {
|
|
13
14
|
"bg": {
|
|
14
15
|
"base": {
|
|
15
|
-
"value"
|
|
16
|
+
"$value": "{color.button.bg.base}"
|
|
16
17
|
},
|
|
17
18
|
"hover": {
|
|
18
|
-
"value"
|
|
19
|
+
"$value": "{color.button.bg.hover}"
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
"text": {
|
|
22
23
|
"base": {
|
|
23
|
-
"value"
|
|
24
|
+
"$value": "{color.button.text.base}"
|
|
24
25
|
},
|
|
25
26
|
"hover": {
|
|
26
|
-
"value"
|
|
27
|
+
"$value": "{color.button.text.hover}"
|
|
27
28
|
}
|
|
28
29
|
},
|
|
29
30
|
"border": {
|
|
30
31
|
"base": {
|
|
31
|
-
"value"
|
|
32
|
+
"$value": "{color.button.border.base}"
|
|
32
33
|
},
|
|
33
34
|
"top": {
|
|
34
|
-
"value"
|
|
35
|
+
"$value": "{color.button.border.top}"
|
|
35
36
|
},
|
|
36
37
|
"right": {
|
|
37
|
-
"value"
|
|
38
|
+
"$value": "{color.button.border.right}"
|
|
38
39
|
},
|
|
39
40
|
"bottom": {
|
|
40
|
-
"value"
|
|
41
|
+
"$value": "{color.button.border.bottom}"
|
|
41
42
|
},
|
|
42
43
|
"left": {
|
|
43
|
-
"value"
|
|
44
|
+
"$value": "{color.button.border.left}"
|
|
44
45
|
},
|
|
45
46
|
"hover": {
|
|
46
47
|
"base": {
|
|
47
|
-
"value"
|
|
48
|
+
"$value": "{color.button.border.hover.base}"
|
|
48
49
|
},
|
|
49
50
|
"top": {
|
|
50
|
-
"value"
|
|
51
|
+
"$value": "{color.button.border.hover.top}"
|
|
51
52
|
},
|
|
52
53
|
"right": {
|
|
53
|
-
"value"
|
|
54
|
+
"$value": "{color.button.border.hover.right}"
|
|
54
55
|
},
|
|
55
56
|
"bottom": {
|
|
56
|
-
"value"
|
|
57
|
+
"$value": "{color.button.border.hover.bottom}"
|
|
57
58
|
},
|
|
58
59
|
"left": {
|
|
59
|
-
"value"
|
|
60
|
+
"$value": "{color.button.border.hover.left}"
|
|
60
61
|
}
|
|
61
62
|
}
|
|
62
63
|
}
|
|
@@ -64,33 +65,35 @@
|
|
|
64
65
|
},
|
|
65
66
|
"font": {
|
|
66
67
|
"family": {
|
|
68
|
+
"$type": "fontFamily",
|
|
67
69
|
"heading": {
|
|
68
|
-
"base"
|
|
69
|
-
"value": "{font.family.heading.base
|
|
70
|
+
"base": {
|
|
71
|
+
"$value": "{font.family.heading.base}"
|
|
70
72
|
},
|
|
71
|
-
"1"
|
|
72
|
-
"value": "{font.family.heading.1
|
|
73
|
+
"1": {
|
|
74
|
+
"$value": "{font.family.heading.1}"
|
|
73
75
|
},
|
|
74
|
-
"2"
|
|
75
|
-
"value": "{font.family.heading.2
|
|
76
|
+
"2": {
|
|
77
|
+
"$value": "{font.family.heading.2}"
|
|
76
78
|
},
|
|
77
|
-
"3"
|
|
78
|
-
"value": "{font.family.heading.3
|
|
79
|
+
"3": {
|
|
80
|
+
"$value": "{font.family.heading.3}"
|
|
79
81
|
}
|
|
80
82
|
}
|
|
81
83
|
}
|
|
82
84
|
},
|
|
83
85
|
"size": {
|
|
86
|
+
"$type": "dimension",
|
|
84
87
|
"button": {
|
|
85
88
|
"border": {
|
|
86
89
|
"radius": {
|
|
87
|
-
"value": "{size.border.radius.button
|
|
90
|
+
"$value": "{size.border.radius.button}"
|
|
88
91
|
},
|
|
89
92
|
"width": {
|
|
90
|
-
"value": "{size.border.width.button
|
|
93
|
+
"$value": "{size.border.width.button}"
|
|
91
94
|
}
|
|
92
95
|
}
|
|
93
96
|
}
|
|
94
97
|
}
|
|
95
98
|
}
|
|
96
|
-
}
|
|
99
|
+
}
|
package/src/tokens/size.json
CHANGED
|
@@ -1,66 +1,67 @@
|
|
|
1
1
|
{
|
|
2
2
|
"size": {
|
|
3
|
+
"$type": "dimension",
|
|
3
4
|
"border": {
|
|
4
5
|
"width": {
|
|
5
6
|
"base": {
|
|
6
|
-
"value": "1px"
|
|
7
|
+
"$value": "1px"
|
|
7
8
|
},
|
|
8
9
|
"button": {
|
|
9
|
-
"value": "{size.border.width.base
|
|
10
|
+
"$value": "{size.border.width.base}"
|
|
10
11
|
}
|
|
11
12
|
},
|
|
12
13
|
"radius": {
|
|
13
14
|
"base": {
|
|
14
|
-
"value": "4px"
|
|
15
|
+
"$value": "4px"
|
|
15
16
|
},
|
|
16
17
|
"button": {
|
|
17
|
-
"value": "{size.border.radius.base
|
|
18
|
+
"$value": "{size.border.radius.base}"
|
|
18
19
|
},
|
|
19
20
|
"main": {
|
|
20
|
-
"value": "0"
|
|
21
|
+
"$value": "0"
|
|
21
22
|
}
|
|
22
23
|
}
|
|
23
24
|
},
|
|
24
25
|
"container": {
|
|
25
26
|
"width": {
|
|
26
|
-
"value": "100%"
|
|
27
|
+
"$value": "100%"
|
|
27
28
|
},
|
|
28
29
|
"min-width": {
|
|
29
|
-
"value": "0"
|
|
30
|
+
"$value": "0"
|
|
30
31
|
},
|
|
31
32
|
"max-width": {
|
|
32
|
-
"value": "100%"
|
|
33
|
+
"$value": "100%"
|
|
33
34
|
}
|
|
34
35
|
},
|
|
35
36
|
"wrapper": {
|
|
36
37
|
"width": {
|
|
37
|
-
"value": "97%"
|
|
38
|
+
"$value": "97%"
|
|
38
39
|
},
|
|
39
40
|
"max-width": {
|
|
40
|
-
"value": "1240px"
|
|
41
|
+
"$value": "1240px"
|
|
41
42
|
}
|
|
42
43
|
},
|
|
43
44
|
"surface": {
|
|
44
45
|
"padding": {
|
|
45
|
-
"value": "16px"
|
|
46
|
+
"$value": "16px"
|
|
46
47
|
}
|
|
47
48
|
},
|
|
48
49
|
"main": {
|
|
49
50
|
"max-width": {
|
|
50
|
-
"value": "100%"
|
|
51
|
+
"$value": "100%"
|
|
51
52
|
},
|
|
52
53
|
"padding": {
|
|
53
|
-
"value": "0"
|
|
54
|
+
"$value": "0"
|
|
54
55
|
},
|
|
55
56
|
"margin": {
|
|
56
|
-
"value": "0 auto"
|
|
57
|
+
"$value": "0 auto"
|
|
57
58
|
}
|
|
58
59
|
},
|
|
59
60
|
"height": {
|
|
60
61
|
"ad-container": {
|
|
61
62
|
"leaderboard": {
|
|
62
63
|
"min": {
|
|
63
|
-
"value": "0"
|
|
64
|
+
"$value": "0"
|
|
64
65
|
}
|
|
65
66
|
}
|
|
66
67
|
}
|
|
@@ -1,206 +1,212 @@
|
|
|
1
1
|
{
|
|
2
2
|
"font": {
|
|
3
3
|
"family": {
|
|
4
|
+
"$type": "fontFamily",
|
|
4
5
|
"base": {
|
|
5
|
-
"value": "\"Helvetica\", Arial, sans-serif"
|
|
6
|
+
"$value": "\"Helvetica\", Arial, sans-serif"
|
|
6
7
|
},
|
|
7
8
|
"heading": {
|
|
8
9
|
"base": {
|
|
9
|
-
"value": "{font.family.base
|
|
10
|
+
"$value": "{font.family.base}"
|
|
10
11
|
},
|
|
11
12
|
"1": {
|
|
12
|
-
"value": "{font.family.heading.base
|
|
13
|
+
"$value": "{font.family.heading.base}"
|
|
13
14
|
},
|
|
14
15
|
"2": {
|
|
15
|
-
"value": "{font.family.heading.base
|
|
16
|
+
"$value": "{font.family.heading.base}"
|
|
16
17
|
},
|
|
17
18
|
"3": {
|
|
18
|
-
"value": "{font.family.heading.base
|
|
19
|
+
"$value": "{font.family.heading.base}"
|
|
19
20
|
}
|
|
20
21
|
},
|
|
21
22
|
"button": {
|
|
22
23
|
"base": {
|
|
23
|
-
"value": "{font.family.base
|
|
24
|
+
"$value": "{font.family.base}"
|
|
24
25
|
}
|
|
25
26
|
}
|
|
26
27
|
},
|
|
27
28
|
"weight": {
|
|
29
|
+
"$type": "fontWeight",
|
|
28
30
|
"base": {
|
|
29
|
-
"value": "400"
|
|
31
|
+
"$value": "400"
|
|
30
32
|
},
|
|
31
33
|
"heading": {
|
|
32
34
|
"base": {
|
|
33
|
-
"value": "{font.weight.base
|
|
35
|
+
"$value": "{font.weight.base}"
|
|
34
36
|
},
|
|
35
37
|
"1": {
|
|
36
|
-
"value": "{font.weight.heading.base
|
|
38
|
+
"$value": "{font.weight.heading.base}"
|
|
37
39
|
},
|
|
38
40
|
"2": {
|
|
39
|
-
"value": "{font.weight.heading.base
|
|
41
|
+
"$value": "{font.weight.heading.base}"
|
|
40
42
|
},
|
|
41
43
|
"3": {
|
|
42
|
-
"value": "{font.weight.heading.base
|
|
44
|
+
"$value": "{font.weight.heading.base}"
|
|
43
45
|
}
|
|
44
46
|
},
|
|
45
47
|
"button": {
|
|
46
48
|
"base": {
|
|
47
|
-
"value": "{font.weight.base
|
|
49
|
+
"$value": "{font.weight.base}"
|
|
48
50
|
}
|
|
49
51
|
},
|
|
50
52
|
"link": {
|
|
51
53
|
"base": {
|
|
52
|
-
"value": "inherit"
|
|
54
|
+
"$value": "inherit"
|
|
53
55
|
}
|
|
54
56
|
}
|
|
55
57
|
},
|
|
56
58
|
"spacing": {
|
|
59
|
+
"$type": "letterSpacing",
|
|
57
60
|
"base": {
|
|
58
|
-
"value": "normal"
|
|
61
|
+
"$value": "normal"
|
|
59
62
|
},
|
|
60
63
|
"heading": {
|
|
61
64
|
"base": {
|
|
62
|
-
"value": "{font.spacing.base
|
|
65
|
+
"$value": "{font.spacing.base}"
|
|
63
66
|
},
|
|
64
67
|
"1": {
|
|
65
|
-
"value": "{font.spacing.heading.base
|
|
68
|
+
"$value": "{font.spacing.heading.base}"
|
|
66
69
|
},
|
|
67
70
|
"2": {
|
|
68
|
-
"value": "{font.spacing.heading.base
|
|
71
|
+
"$value": "{font.spacing.heading.base}"
|
|
69
72
|
},
|
|
70
73
|
"3": {
|
|
71
|
-
"value": "{font.spacing.heading.base
|
|
74
|
+
"$value": "{font.spacing.heading.base}"
|
|
72
75
|
}
|
|
73
76
|
},
|
|
74
77
|
"button": {
|
|
75
|
-
"value": "{font.spacing.base
|
|
78
|
+
"$value": "{font.spacing.base}"
|
|
76
79
|
}
|
|
77
80
|
},
|
|
78
81
|
"type": {
|
|
82
|
+
"$type": "dimension",
|
|
79
83
|
"s-2": {
|
|
80
84
|
"size": {
|
|
81
|
-
"value": "0.75rem"
|
|
85
|
+
"$value": "0.75rem"
|
|
82
86
|
},
|
|
83
|
-
"line-height": {
|
|
84
|
-
"value": "1.35"
|
|
87
|
+
"line-height": {
|
|
88
|
+
"$value": "1.35"
|
|
85
89
|
}
|
|
86
90
|
},
|
|
87
91
|
"s-1": {
|
|
88
92
|
"size": {
|
|
89
|
-
"value": "0.875rem"
|
|
93
|
+
"$value": "0.875rem"
|
|
90
94
|
},
|
|
91
|
-
"line-height": {
|
|
92
|
-
"value": "1.35"
|
|
95
|
+
"line-height": {
|
|
96
|
+
"$value": "1.35"
|
|
93
97
|
}
|
|
94
98
|
},
|
|
95
99
|
"s0": {
|
|
96
100
|
"size": {
|
|
97
|
-
"value": "1rem"
|
|
101
|
+
"$value": "1rem"
|
|
98
102
|
},
|
|
99
|
-
"line-height": {
|
|
100
|
-
"value": "1.4"
|
|
103
|
+
"line-height": {
|
|
104
|
+
"$value": "1.4"
|
|
101
105
|
}
|
|
102
106
|
},
|
|
103
107
|
"s1": {
|
|
104
108
|
"size": {
|
|
105
|
-
"value": "clamp(1.067rem, 1.0468rem + 0.1009vi, 1.125rem)"
|
|
109
|
+
"$value": "clamp(1.067rem, 1.0468rem + 0.1009vi, 1.125rem)"
|
|
106
110
|
},
|
|
107
|
-
"line-height": {
|
|
108
|
-
"value": "1.4"
|
|
111
|
+
"line-height": {
|
|
112
|
+
"$value": "1.4"
|
|
109
113
|
}
|
|
110
114
|
},
|
|
111
115
|
"s2": {
|
|
112
116
|
"size": {
|
|
113
|
-
"value": "clamp(1.1385rem, 1.0943rem + 0.2211vi, 1.2656rem)"
|
|
117
|
+
"$value": "clamp(1.1385rem, 1.0943rem + 0.2211vi, 1.2656rem)"
|
|
114
118
|
},
|
|
115
|
-
"line-height": {
|
|
116
|
-
"value": "1.2"
|
|
119
|
+
"line-height": {
|
|
120
|
+
"$value": "1.2"
|
|
117
121
|
}
|
|
118
122
|
},
|
|
119
123
|
"s3": {
|
|
120
124
|
"size": {
|
|
121
|
-
"value": "clamp(1.2148rem, 1.1421rem + 0.3636vi, 1.4238rem)"
|
|
125
|
+
"$value": "clamp(1.2148rem, 1.1421rem + 0.3636vi, 1.4238rem)"
|
|
122
126
|
},
|
|
123
|
-
"line-height": {
|
|
124
|
-
"value": "1.2"
|
|
127
|
+
"line-height": {
|
|
128
|
+
"$value": "1.2"
|
|
125
129
|
}
|
|
126
130
|
},
|
|
127
131
|
"s4": {
|
|
128
132
|
"size": {
|
|
129
|
-
"value": "clamp(1.2962rem, 1.1898rem + 0.5316vi, 1.6018rem)"
|
|
133
|
+
"$value": "clamp(1.2962rem, 1.1898rem + 0.5316vi, 1.6018rem)"
|
|
130
134
|
},
|
|
131
|
-
"line-height": {
|
|
132
|
-
"value": "1.2"
|
|
135
|
+
"line-height": {
|
|
136
|
+
"$value": "1.2"
|
|
133
137
|
}
|
|
134
138
|
},
|
|
135
139
|
"s5": {
|
|
136
140
|
"size": {
|
|
137
|
-
"value": "clamp(1.383rem, 1.2372rem + 0.7288vi, 1.802rem)"
|
|
141
|
+
"$value": "clamp(1.383rem, 1.2372rem + 0.7288vi, 1.802rem)"
|
|
138
142
|
},
|
|
139
|
-
"line-height": {
|
|
140
|
-
"value": "1.2"
|
|
143
|
+
"line-height": {
|
|
144
|
+
"$value": "1.2"
|
|
141
145
|
}
|
|
142
146
|
},
|
|
143
147
|
"s6": {
|
|
144
148
|
"size": {
|
|
145
|
-
"value": "clamp(1.4757rem, 1.2838rem + 0.9593vi, 2.0273rem)"
|
|
149
|
+
"$value": "clamp(1.4757rem, 1.2838rem + 0.9593vi, 2.0273rem)"
|
|
146
150
|
},
|
|
147
|
-
"line-height": {
|
|
148
|
-
"value": "1.15"
|
|
151
|
+
"line-height": {
|
|
152
|
+
"$value": "1.15"
|
|
149
153
|
}
|
|
150
154
|
},
|
|
151
155
|
"s7": {
|
|
152
156
|
"size": {
|
|
153
|
-
"value": "clamp(1.5745rem, 1.3289rem + 1.2281vi, 2.2807rem)"
|
|
157
|
+
"$value": "clamp(1.5745rem, 1.3289rem + 1.2281vi, 2.2807rem)"
|
|
154
158
|
},
|
|
155
|
-
"line-height": {
|
|
156
|
-
"value": "1.15"
|
|
159
|
+
"line-height": {
|
|
160
|
+
"$value": "1.15"
|
|
157
161
|
}
|
|
158
162
|
},
|
|
159
163
|
"s8": {
|
|
160
164
|
"size": {
|
|
161
|
-
"value": "clamp(1.68rem, 1.3719rem + 1.5405vi, 2.5658rem)"
|
|
165
|
+
"$value": "clamp(1.68rem, 1.3719rem + 1.5405vi, 2.5658rem)"
|
|
162
166
|
},
|
|
163
|
-
"line-height": {
|
|
164
|
-
"value": "1.15"
|
|
167
|
+
"line-height": {
|
|
168
|
+
"$value": "1.15"
|
|
165
169
|
}
|
|
166
170
|
},
|
|
167
171
|
"s9": {
|
|
168
172
|
"size": {
|
|
169
|
-
"value": "clamp(1.7926rem, 1.4121rem + 1.9025vi, 2.8865rem)"
|
|
173
|
+
"$value": "clamp(1.7926rem, 1.4121rem + 1.9025vi, 2.8865rem)"
|
|
170
174
|
},
|
|
171
|
-
"line-height": {
|
|
172
|
-
"value": "1.15"
|
|
175
|
+
"line-height": {
|
|
176
|
+
"$value": "1.15"
|
|
173
177
|
}
|
|
174
178
|
}
|
|
175
179
|
}
|
|
176
180
|
},
|
|
177
181
|
"text": {
|
|
178
182
|
"transform": {
|
|
183
|
+
"$type": "textTransform",
|
|
179
184
|
"heading": {
|
|
180
185
|
"base": {
|
|
181
|
-
"value": "none"
|
|
186
|
+
"$value": "none"
|
|
182
187
|
},
|
|
183
188
|
"1": {
|
|
184
|
-
"value": "{text.transform.heading.base
|
|
189
|
+
"$value": "{text.transform.heading.base}"
|
|
185
190
|
},
|
|
186
191
|
"2": {
|
|
187
|
-
"value": "{text.transform.heading.base
|
|
192
|
+
"$value": "{text.transform.heading.base}"
|
|
188
193
|
},
|
|
189
194
|
"3": {
|
|
190
|
-
"value": "{text.transform.heading.base
|
|
195
|
+
"$value": "{text.transform.heading.base}"
|
|
191
196
|
}
|
|
192
197
|
},
|
|
193
198
|
"button": {
|
|
194
|
-
"value": "none"
|
|
199
|
+
"$value": "none"
|
|
195
200
|
}
|
|
196
201
|
},
|
|
197
202
|
"decoration": {
|
|
203
|
+
"$type": "textDecoration",
|
|
198
204
|
"link": {
|
|
199
205
|
"base": {
|
|
200
|
-
"value": "underline"
|
|
206
|
+
"$value": "underline"
|
|
201
207
|
},
|
|
202
208
|
"hover": {
|
|
203
|
-
"value": "underline"
|
|
209
|
+
"$value": "underline"
|
|
204
210
|
}
|
|
205
211
|
}
|
|
206
212
|
}
|
|
@@ -0,0 +1,143 @@
|
|
|
1
|
+
const crypto = require('node:crypto');
|
|
2
|
+
const path = require('node:path');
|
|
3
|
+
const os = require('node:os');
|
|
4
|
+
const fs = require('node:fs/promises');
|
|
5
|
+
const { TinyColor } = require('@ctrl/tinycolor');
|
|
6
|
+
|
|
7
|
+
const TRANSFORM_AMOUNTS = {
|
|
8
|
+
LIGHT: 10,
|
|
9
|
+
LIGHTEST: 95,
|
|
10
|
+
DARK: 10,
|
|
11
|
+
DARKEST: 12,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* @typedef ColorGroupItem
|
|
16
|
+
* @type {object}
|
|
17
|
+
* @property {string} $value
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* @typedef ColorGroupInput
|
|
22
|
+
* @type {object}
|
|
23
|
+
* @property {!ColorGroupItem} base
|
|
24
|
+
* @property {?ColorGroupItem} light
|
|
25
|
+
* @property {?ColorGroupItem} lightest
|
|
26
|
+
* @property {?ColorGroupItem} dark
|
|
27
|
+
* @property {?ColorGroupItem} darkest
|
|
28
|
+
*/
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Replicates Sass lightness($color) function
|
|
32
|
+
|
|
33
|
+
* @param {TinyColor} color
|
|
34
|
+
* @returns {number}
|
|
35
|
+
*/
|
|
36
|
+
function lightness(color) {
|
|
37
|
+
const { l } = color.toHsl();
|
|
38
|
+
|
|
39
|
+
return l * 100;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
/**
|
|
43
|
+
* adds `light`, `lightest`, `dark` and `darkest` to a token colour group, derived from `colorGroup.base.$value`.
|
|
44
|
+
*
|
|
45
|
+
* If keys already exist, they are **not** overwritten.
|
|
46
|
+
*
|
|
47
|
+
* @param {ColorGroupInput} colorGroup {base, light?, lightest?, dark?, darkest? }
|
|
48
|
+
* @returns {ColorGroupInput} {base, light, lightest, dark, darkest }
|
|
49
|
+
*/
|
|
50
|
+
function createColorsFromBase(colorGroup) {
|
|
51
|
+
const { base = {}, light = {}, lightest = {}, dark = {}, darkest = {} } = colorGroup;
|
|
52
|
+
const asTinyColor = new TinyColor(base.$value);
|
|
53
|
+
|
|
54
|
+
return {
|
|
55
|
+
base,
|
|
56
|
+
light: {
|
|
57
|
+
...light,
|
|
58
|
+
$value: light.$value || asTinyColor.lighten(TRANSFORM_AMOUNTS.LIGHT).toHexString(),
|
|
59
|
+
},
|
|
60
|
+
lightest: {
|
|
61
|
+
...lightest,
|
|
62
|
+
$value: lightest.$value || asTinyColor.lighten(TRANSFORM_AMOUNTS.LIGHTEST - lightness(asTinyColor)).toHexString(),
|
|
63
|
+
},
|
|
64
|
+
dark: {
|
|
65
|
+
...dark,
|
|
66
|
+
$value: dark?.$value || asTinyColor.darken(TRANSFORM_AMOUNTS.DARK).toHexString(),
|
|
67
|
+
},
|
|
68
|
+
darkest: {
|
|
69
|
+
...darkest,
|
|
70
|
+
$value: darkest?.$value || asTinyColor.darken(lightness(asTinyColor) - TRANSFORM_AMOUNTS.DARKEST).toHexString(),
|
|
71
|
+
},
|
|
72
|
+
};
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
/**
|
|
76
|
+
* For each `tokensObject.color.brand.*`, add lightness tokens, if they dont already exist
|
|
77
|
+
*
|
|
78
|
+
* @param {object} tokensObject
|
|
79
|
+
* @returns {object} modified tokensObject
|
|
80
|
+
*/
|
|
81
|
+
function addBrandColorLightnessTokens(tokensObject) {
|
|
82
|
+
const { brand } = tokensObject.color;
|
|
83
|
+
|
|
84
|
+
return {
|
|
85
|
+
...tokensObject,
|
|
86
|
+
color: {
|
|
87
|
+
...tokensObject.color,
|
|
88
|
+
/**
|
|
89
|
+
* focus on `brand` object
|
|
90
|
+
*
|
|
91
|
+
* loop through all brand group keys e.g. "1", "2", "3"
|
|
92
|
+
*
|
|
93
|
+
* apply `createColorsFromBase` to each color group
|
|
94
|
+
*/
|
|
95
|
+
brand: Object.keys(brand).reduce((accu, brandKey) => {
|
|
96
|
+
const colorGroup = brand[brandKey];
|
|
97
|
+
const populatedColorGroup = createColorsFromBase(colorGroup);
|
|
98
|
+
// eslint-disable-next-line no-param-reassign
|
|
99
|
+
accu[brandKey] = { ...colorGroup, ...populatedColorGroup };
|
|
100
|
+
return accu;
|
|
101
|
+
}, {}),
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
module.exports.addBrandColorLightnessTokens = addBrandColorLightnessTokens;
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Although `addBrandColorLightnessTokens` does the job of adding lighten tokens to `color.brand.*` JSON, this function purely
|
|
110
|
+
* exists to: read, transform, and then write the result to a new temporary file.
|
|
111
|
+
*
|
|
112
|
+
* For use in Style Dictionary `source` array. Style Dictionary only supports files written to disk for `source` 🥲
|
|
113
|
+
*
|
|
114
|
+
* @param {string} originalFilePath path to original tokens json file
|
|
115
|
+
* @returns {string} new file path
|
|
116
|
+
*/
|
|
117
|
+
async function writeTransformedFileBrandColorLightnessTokens(originalFilePath) {
|
|
118
|
+
// construct new unique temp file path name where we will save new json file to disk
|
|
119
|
+
const TMP_DIR = await fs.realpath(os.tmpdir());
|
|
120
|
+
const filename = path.parse(originalFilePath).name;
|
|
121
|
+
const newTempFilePath = path.join(
|
|
122
|
+
TMP_DIR,
|
|
123
|
+
`/madgex-design-system/${filename}-transformed-${crypto.randomUUID()}.json`
|
|
124
|
+
);
|
|
125
|
+
const tmpDirPath = path.dirname(newTempFilePath);
|
|
126
|
+
|
|
127
|
+
// create temp folder if it doesn't exist
|
|
128
|
+
try {
|
|
129
|
+
await fs.access(tmpDirPath);
|
|
130
|
+
} catch (error) {
|
|
131
|
+
await fs.mkdir(tmpDirPath, { recursive: true });
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
// read original tokens file
|
|
135
|
+
const colorTokens = await fs.readFile(originalFilePath, { encoding: 'utf8' });
|
|
136
|
+
// transform tokens
|
|
137
|
+
const transformed = JSON.stringify(addBrandColorLightnessTokens(JSON.parse(colorTokens)), null, ' ');
|
|
138
|
+
// write new file with transformed tokens
|
|
139
|
+
await fs.writeFile(newTempFilePath, transformed);
|
|
140
|
+
// return new file name for use in createStyleDictionary
|
|
141
|
+
return newTempFilePath;
|
|
142
|
+
}
|
|
143
|
+
module.exports.writeTransformedFileBrandColorLightnessTokens = writeTransformedFileBrandColorLightnessTokens;
|