@vector-im/compound-design-tokens 10.2.2 → 10.2.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.
@@ -0,0 +1,258 @@
1
+ @import url("https://fonts.googleapis.com/css2?family=Inter:wght@400..900&display=swap");
2
+
3
+ /*
4
+ Inter Dynamic Metrics
5
+ https://rsms.me/inter/dynmetrics/
6
+ */
7
+ :root {
8
+ --f-ls-14: -0.006em;
9
+ --f-ls-16: -0.011em;
10
+ --f-ls-24: -0.019em;
11
+ }
12
+
13
+ html {
14
+ box-sizing: border-box;
15
+ font-size: 100%;
16
+ }
17
+
18
+ *,
19
+ *::before,
20
+ *::after {
21
+ box-sizing: inherit;
22
+ }
23
+
24
+ body {
25
+ -webkit-font-smoothing: antialiased;
26
+ -moz-osx-font-smoothing: grayscale;
27
+ font-family: Inter, system-ui;
28
+ font-size: 1rem;
29
+ color: var(--color-gray-1400-light);
30
+ margin: 16px;
31
+ }
32
+
33
+ summary:hover {
34
+ cursor: pointer;
35
+ }
36
+
37
+ details[open] summary {
38
+ margin-bottom: 8px;
39
+ }
40
+
41
+ pre {
42
+ font-family:
43
+ ui-monospace,
44
+ SFMono-Regular,
45
+ SF Mono,
46
+ Menlo,
47
+ Consolas,
48
+ "Liberation Mono",
49
+ monospace;
50
+ }
51
+
52
+ .flex {
53
+ display: flex;
54
+ }
55
+
56
+ .flex-row {
57
+ flex-direction: row;
58
+ }
59
+
60
+ .grid {
61
+ display: grid;
62
+ }
63
+
64
+ .grid-cols-3 {
65
+ grid-template-columns: repeat(3, 1fr);
66
+ }
67
+
68
+ .gap-0_5 {
69
+ gap: 0.5rem;
70
+ }
71
+
72
+ .gap-1 {
73
+ gap: 1rem;
74
+ }
75
+
76
+ .m-b-1 {
77
+ margin-block-end: 1rem;
78
+ }
79
+
80
+ .tokens-studio {
81
+ display: flex;
82
+ flex-direction: column;
83
+ gap: 1rem;
84
+ }
85
+
86
+ .key-colors {
87
+ border-radius: 8px;
88
+ display: flex;
89
+ gap: 16px;
90
+ padding: 16px;
91
+ }
92
+
93
+ .key-colors__swatch {
94
+ height: 24px;
95
+ width: 40px;
96
+ }
97
+
98
+ .key-colors__picker {
99
+ display: flex;
100
+ flex-direction: column;
101
+ align-items: center;
102
+ }
103
+
104
+ .key-colors__picker input[type="color"] {
105
+ width: 40px;
106
+ height: 24px;
107
+ border: none;
108
+ padding: 0;
109
+ margin: 0;
110
+ appearance: none;
111
+ }
112
+
113
+ .themes,
114
+ .themes-alpha {
115
+ display: flex;
116
+ flex-direction: row;
117
+ gap: 8px;
118
+ }
119
+
120
+ .theme {
121
+ border-radius: 8px;
122
+ display: flex;
123
+ gap: 16px;
124
+ padding: 16px;
125
+ }
126
+
127
+ .theme__action {
128
+ transition: transform 250ms ease;
129
+ }
130
+
131
+ .theme__action:hover {
132
+ transform: scale(1.1);
133
+ }
134
+
135
+ .theme__swatch {
136
+ height: 24px;
137
+ width: 40px;
138
+ }
139
+
140
+ .tests__case {
141
+ display: flex;
142
+ flex-direction: column;
143
+ gap: 16px;
144
+ margin-bottom: 16px;
145
+ }
146
+
147
+ .bg {
148
+ border-radius: 8px;
149
+ padding: 16px;
150
+ }
151
+
152
+ .bg--light {
153
+ background-color: var(--color-bg-light);
154
+ }
155
+
156
+ .bg--lightHc {
157
+ background-color: var(--color-bg-lightHc);
158
+ }
159
+
160
+ .bg--dark {
161
+ background-color: var(--color-bg-dark);
162
+ }
163
+
164
+ .bg--darkHc {
165
+ background-color: var(--color-bg-darkHc);
166
+ }
167
+
168
+ .button {
169
+ align-items: center;
170
+ border-radius: 9999px;
171
+ display: inline-flex;
172
+ font-size: 1rem;
173
+ font-weight: 500;
174
+ height: 44px;
175
+ letter-spacing: var(--f-ls-16);
176
+ padding: 8px 24px;
177
+ }
178
+
179
+ .button:hover {
180
+ cursor: pointer;
181
+ }
182
+
183
+ /*
184
+ .button--{colorName}-{themeName} {
185
+ background-color: var(--color-{colorName}-900-{themeName});
186
+ color: var(--color-bg-{themeName});
187
+ }`;
188
+ */
189
+
190
+ .button--gray-light {
191
+ background-color: var(--color-gray-1400-light);
192
+ color: var(--color-bg-light);
193
+ }
194
+
195
+ .button--gray-lightHc {
196
+ background-color: var(--color-gray-1400-lightHc);
197
+ color: var(--color-bg-lightHc);
198
+ }
199
+
200
+ .button--gray-dark {
201
+ background-color: var(--color-gray-1400-dark);
202
+ color: var(--color-bg-dark);
203
+ }
204
+
205
+ .button--gray-darkHc {
206
+ background-color: var(--color-gray-1400-darkHc);
207
+ color: var(--color-bg-darkHc);
208
+ }
209
+
210
+ .label {
211
+ align-items: center;
212
+ border-radius: 8px;
213
+ border-style: solid;
214
+ border-width: 1px;
215
+ display: inline-flex;
216
+ font-size: 0.875rem;
217
+ font-weight: 400;
218
+ height: 32px;
219
+ letter-spacing: var(--f-ls-14);
220
+ padding: 4px 12px;
221
+ }
222
+
223
+ .label:hover {
224
+ cursor: pointer;
225
+ }
226
+
227
+ /*
228
+ .label--{colorName}-{themeName} {
229
+ background-color: var(--color-{colorName}-300-{themeName});
230
+ border-color: var(--color-{colorName}-700-{themeName});
231
+ color: var(--color-{colorName}-900-{themeName});
232
+ }
233
+ */
234
+
235
+ .text-heading {
236
+ font-size: 1.5rem;
237
+ letter-spacing: var(--f-ls-24);
238
+ margin-top: 0;
239
+ }
240
+
241
+ .text-body-md {
242
+ font-size: 1rem;
243
+ letter-spacing: var(--f-ls-16);
244
+ }
245
+
246
+ .text-body-sm {
247
+ font-size: 0.875rem;
248
+ letter-spacing: var(--f-ls-14);
249
+ }
250
+
251
+ /*
252
+ .text--primary-{themeName} {
253
+ color: var(--color-{colorName}-1400-light);
254
+ }
255
+ .text--secondary-{themeName} {
256
+ color: var(--color-{colorName}-900-light);
257
+ }
258
+ */
@@ -0,0 +1,239 @@
1
+ import { BackgroundColor, Color, Theme } from "@adobe/leonardo-contrast-colors";
2
+ import chroma from "chroma-js";
3
+ import { getAlphaColor, hslaToHex } from "./alphredo.js";
4
+
5
+ // Color spaces for color interpolation
6
+ // CAM02, CAM02p, LCH, LAB, HSL, HSLuv, HSV, RGB, OKLAB, OKLCH
7
+
8
+ // OKLCH, false
9
+ // CAM02p, true
10
+ // LAB, true
11
+ // RGB, true
12
+
13
+ export const leonardoConfig = {
14
+ backgroundColor: "gray",
15
+ colorSpace: "OKLCH",
16
+ colorSmoothing: false,
17
+ formula: "wcag2",
18
+ output: "HEX",
19
+ colors: {
20
+ gray: [hslToHex(215, 20, 90), hslToHex(215, 8, 50), hslToHex(215, 6, 25)],
21
+ red: [hslToHex(358, 100, 58), hslToHex(350, 100, 30)],
22
+ orange: [hslToHex(32, 100, 48), hslToHex(12, 100, 30)],
23
+ yellow: [hslToHex(50, 100, 50), hslToHex(25, 100, 20)],
24
+ lime: [hslToHex(100, 68, 50), hslToHex(115, 86, 25)],
25
+ green: [hslToHex(163, 87, 42), hslToHex(168, 100, 25)],
26
+ cyan: [hslToHex(185, 80, 45), hslToHex(200, 98, 35)],
27
+ blue: [hslToHex(212, 98, 46), hslToHex(222, 95, 25)],
28
+ purple: [hslToHex(258, 94, 64), hslToHex(265, 100, 35)],
29
+ fuchsia: [hslToHex(295, 56, 50), hslToHex(285, 80, 25)],
30
+ pink: [hslToHex(334, 90, 50), hslToHex(330, 91, 25)],
31
+ },
32
+ themes: {
33
+ light: {
34
+ ratios: [
35
+ 1.03, 1.06, 1.12, 1.25, 1.5, 1.75, 2.25, 3.5, 5.25, 6.5, 8, 10.5, 13.75,
36
+ 16.75,
37
+ ],
38
+ contrast: 1,
39
+ lightness: 100,
40
+ saturation: 100,
41
+ },
42
+ dark: {
43
+ ratios: [
44
+ 1.03, 1.06, 1.12, 1.25, 1.5, 1.75, 2.25, 3.5, 5.25, 6.5, 8, 10.5, 13.75,
45
+ 16,
46
+ ],
47
+ contrast: 1,
48
+ lightness: 6,
49
+ saturation: 97,
50
+ },
51
+ lightHc: {
52
+ ratios: [
53
+ 1.06, 1.12, 1.25, 1.37, 1.75, 2.25, 3.25, 4.75, 8.87, 10, 11.75, 13.25,
54
+ 16, 17,
55
+ ],
56
+ contrast: 1,
57
+ lightness: 100,
58
+ saturation: 100,
59
+ },
60
+ darkHc: {
61
+ ratios: [
62
+ 1.06, 1.12, 1.25, 1.37, 1.75, 2.25, 3.25, 4.75, 8.87, 10, 11.75, 13.25,
63
+ 16, 17,
64
+ ],
65
+ contrast: 1,
66
+ lightness: 6,
67
+ saturation: 97,
68
+ },
69
+ },
70
+ };
71
+
72
+ export function hslToHex(h, s, l) {
73
+ return chroma.hsl(h, s / 100, l / 100).hex();
74
+ }
75
+
76
+ function generateThemeJson(leonardoConfig, theme) {
77
+ const colorSpace = leonardoConfig.colorSpace;
78
+ const colorSmoothing = leonardoConfig.colorSmoothing;
79
+ const contrastRatios = leonardoConfig.themes[theme].ratios;
80
+
81
+ const gray = new BackgroundColor({
82
+ name: "gray",
83
+ colorKeys: leonardoConfig.colors.gray,
84
+ colorspace: colorSpace,
85
+ ratios: contrastRatios,
86
+ smooth: colorSmoothing,
87
+ });
88
+
89
+ const blue = new Color({
90
+ name: "blue",
91
+ colorKeys: leonardoConfig.colors.blue,
92
+ colorspace: colorSpace,
93
+ ratios: contrastRatios,
94
+ smooth: colorSmoothing,
95
+ });
96
+
97
+ const cyan = new Color({
98
+ name: "cyan",
99
+ colorKeys: leonardoConfig.colors.cyan,
100
+ colorspace: colorSpace,
101
+ ratios: contrastRatios,
102
+ smooth: colorSmoothing,
103
+ });
104
+
105
+ const fuchsia = new Color({
106
+ name: "fuchsia",
107
+ colorKeys: leonardoConfig.colors.fuchsia,
108
+ colorspace: colorSpace,
109
+ ratios: contrastRatios,
110
+ smooth: colorSmoothing,
111
+ });
112
+
113
+ const green = new Color({
114
+ name: "green",
115
+ colorKeys: leonardoConfig.colors.green,
116
+ colorspace: colorSpace,
117
+ ratios: contrastRatios,
118
+ smooth: colorSmoothing,
119
+ });
120
+
121
+ const lime = new Color({
122
+ name: "lime",
123
+ colorKeys: leonardoConfig.colors.lime,
124
+ colorspace: colorSpace,
125
+ ratios: contrastRatios,
126
+ smooth: colorSmoothing,
127
+ });
128
+
129
+ const orange = new Color({
130
+ name: "orange",
131
+ colorKeys: leonardoConfig.colors.orange,
132
+ colorspace: colorSpace,
133
+ ratios: contrastRatios,
134
+ smooth: colorSmoothing,
135
+ });
136
+
137
+ const pink = new Color({
138
+ name: "pink",
139
+ colorKeys: leonardoConfig.colors.pink,
140
+ colorspace: colorSpace,
141
+ ratios: contrastRatios,
142
+ smooth: colorSmoothing,
143
+ });
144
+
145
+ const purple = new Color({
146
+ name: "purple",
147
+ colorKeys: leonardoConfig.colors.purple,
148
+ colorspace: colorSpace,
149
+ ratios: contrastRatios,
150
+ smooth: colorSmoothing,
151
+ });
152
+
153
+ const red = new Color({
154
+ name: "red",
155
+ colorKeys: leonardoConfig.colors.red,
156
+ colorspace: colorSpace,
157
+ ratios: contrastRatios,
158
+ smooth: colorSmoothing,
159
+ });
160
+
161
+ const yellow = new Color({
162
+ name: "yellow",
163
+ colorKeys: leonardoConfig.colors.yellow,
164
+ colorspace: colorSpace,
165
+ ratios: contrastRatios,
166
+ smooth: colorSmoothing,
167
+ });
168
+
169
+ const colorMap = {
170
+ gray,
171
+ red,
172
+ orange,
173
+ yellow,
174
+ lime,
175
+ green,
176
+ cyan,
177
+ blue,
178
+ purple,
179
+ fuchsia,
180
+ pink,
181
+ };
182
+
183
+ // Add in the custom colour at the end if it has been set.
184
+ if (leonardoConfig.colors.custom) {
185
+ colorMap.custom = new Color({
186
+ name: "custom",
187
+ colorKeys: leonardoConfig.colors.custom,
188
+ colorspace: colorSpace,
189
+ ratios: contrastRatios,
190
+ smooth: colorSmoothing,
191
+ });
192
+ }
193
+
194
+ const leonardoTheme = new Theme({
195
+ colors: Object.values(colorMap),
196
+ backgroundColor: colorMap[leonardoConfig.backgroundColor],
197
+ contrast: leonardoConfig.themes[theme].contrast,
198
+ lightness: leonardoConfig.themes[theme].lightness,
199
+ saturation: leonardoConfig.themes[theme].saturation,
200
+ output: leonardoConfig.output,
201
+ formula: leonardoConfig.formula,
202
+ });
203
+
204
+ return leonardoTheme.contrastColors;
205
+ }
206
+
207
+ export function generateThemesJson(leonardoConfig) {
208
+ const output = {};
209
+ for (const theme of Object.keys(leonardoConfig.themes)) {
210
+ output[theme] = generateThemeJson(leonardoConfig, theme);
211
+ }
212
+ return output;
213
+ }
214
+
215
+ export function generateCustomColors(customColorHex) {
216
+ leonardoConfig.colors.custom = [customColorHex];
217
+ const themes = generateThemesJson(leonardoConfig);
218
+
219
+ return Object.fromEntries(
220
+ Object.entries(themes).map(([theme, contrastColors]) => {
221
+ const customColors = contrastColors.find(
222
+ (item) => item && item.name === "custom",
223
+ );
224
+
225
+ const baseMap = Object.fromEntries(
226
+ customColors.values.map(({ name, value }) => [name, value]),
227
+ );
228
+
229
+ // include the alpha variants too
230
+ for (const [name, value] of Object.entries(baseMap)) {
231
+ const alphaColor = getAlphaColor(value, contrastColors[0].background);
232
+ baseMap[`alpha${name.charAt(0).toUpperCase() + name.slice(1)}`] =
233
+ hslaToHex(alphaColor.h, alphaColor.s, alphaColor.l, alphaColor.a);
234
+ }
235
+
236
+ return [theme, baseMap];
237
+ }),
238
+ );
239
+ }