@kanso-labs/kanso-ui-core 0.5.0 → 0.6.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 +31 -7
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/{defaults-BllR5oU-.js → product-theme-CfDDgv7F.js} +537 -70
- package/dist/product-theme-CfDDgv7F.js.map +1 -0
- package/dist/{defaults-Bzm8IVEs.d.ts → product-theme-D117EbtF.d.ts} +70 -7
- package/dist/themes.d.ts +14 -2
- package/dist/themes.js +36 -2
- package/dist/themes.js.map +1 -1
- package/dist/tokens.css +0 -68
- package/dist/tokens.json +2 -85
- package/package.json +2 -2
- package/dist/defaults-BllR5oU-.js.map +0 -1
package/README.md
CHANGED
|
@@ -14,13 +14,37 @@ they read, so an app installs one of them rather than this.
|
|
|
14
14
|
|
|
15
15
|
## What it publishes
|
|
16
16
|
|
|
17
|
-
| Import | What it is
|
|
18
|
-
| --------------------------------------- |
|
|
19
|
-
| `@kanso-labs/kanso-ui-core` | `light` and `dark`, every `--kui-*` property at its value in each scheme; `
|
|
20
|
-
| `@kanso-labs/kanso-ui-core/glyphs` | The path data of the glyphs both libraries draw inside their controls, one `<name>Path` constant each, and the 24-unit `gridSize`
|
|
21
|
-
| `@kanso-labs/kanso-ui-core/themes` | `demoThemes`, the seven demo schemes both libraries' Storybooks render, each a `KuiTheme` with a label and a description
|
|
22
|
-
| `@kanso-labs/kanso-ui-core/tokens.css` | The `--kui-*` custom properties at their defaults, the dark colours and shadows under `prefers-color-scheme: dark`,
|
|
23
|
-
| `@kanso-labs/kanso-ui-core/tokens.json` | The design tokens themselves, in the W3C Design Tokens format
|
|
17
|
+
| Import | What it is |
|
|
18
|
+
| --------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ |
|
|
19
|
+
| `@kanso-labs/kanso-ui-core` | `light` and `dark`, every `--kui-*` property at its value in each scheme; `defineProductTheme`, which builds a product's theme from its own colours and checks their contrast; `breakpoints`, the window size classes; the `KuiTheme` type |
|
|
20
|
+
| `@kanso-labs/kanso-ui-core/glyphs` | The path data of the glyphs both libraries draw inside their controls, one `<name>Path` constant each, and the 24-unit `gridSize` |
|
|
21
|
+
| `@kanso-labs/kanso-ui-core/themes` | `demoThemes`, the seven demo schemes both libraries' Storybooks render, each a `KuiTheme` with a label and a description; `demoProductThemes`, the sample product colour, violet |
|
|
22
|
+
| `@kanso-labs/kanso-ui-core/tokens.css` | The `--kui-*` custom properties at their defaults, the dark colours and shadows under `prefers-color-scheme: dark`, as both libraries publish them |
|
|
23
|
+
| `@kanso-labs/kanso-ui-core/tokens.json` | The design tokens themselves, in the W3C Design Tokens format |
|
|
24
|
+
|
|
25
|
+
## A product's own colour
|
|
26
|
+
|
|
27
|
+
Kanso's brand is ink and paper, with no colour of its own, so the base draws the
|
|
28
|
+
product roles in ink. A product brings one colour for them: it keeps its
|
|
29
|
+
palette, the twelve product roles in light and in dark, as data in its own
|
|
30
|
+
package, and builds its theme once.
|
|
31
|
+
|
|
32
|
+
```ts
|
|
33
|
+
import { defineProductTheme } from '@kanso-labs/kanso-ui-core'
|
|
34
|
+
|
|
35
|
+
const productTheme = defineProductTheme({
|
|
36
|
+
dark: { accent: '#cdb0f5', onAccent: '#2a0d4a' /* …the other ten roles */ },
|
|
37
|
+
light: { accent: '#6b3fa0', onAccent: '#ffffff' /* … */ },
|
|
38
|
+
})
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
Every colour that reads a product role follows it, `primary` and `focus-ring`
|
|
42
|
+
among them. `defineProductTheme` holds the colours to Kanso's contrast targets,
|
|
43
|
+
WCAG 2's 4.5:1 for text and 3:1 for the rest, in both schemes, and throws a
|
|
44
|
+
`ProductThemeError` naming each pair that misses one. The theme it returns holds
|
|
45
|
+
`light` and `dark`, every property at its value in that scheme, and `changes`,
|
|
46
|
+
only the colours the product moves. Both libraries' `ThemeScope` is to take it
|
|
47
|
+
as `productTheme`.
|
|
24
48
|
|
|
25
49
|
## Development
|
|
26
50
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as light, i as
|
|
2
|
-
export { type KuiTheme,
|
|
1
|
+
import { a as ProductThemeError, c as ProductRole, d as light, f as productRoles, i as ProductTheme, l as breakpoints, n as ProductColors, o as defineProductTheme, r as ProductPalette, s as KuiTheme, t as ContrastFailure, u as dark } from "./product-theme-D117EbtF.js";
|
|
2
|
+
export { type ContrastFailure, type KuiTheme, type ProductColors, type ProductPalette, type ProductRole, type ProductTheme, ProductThemeError, breakpoints, dark, defineProductTheme, light, productRoles };
|
package/dist/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as
|
|
1
|
+
export { t as ProductThemeError, r as breakpoints, i as dark, n as defineProductTheme, a as light, o as productRoles } from "./product-theme-CfDDgv7F.js";
|
|
@@ -1,3 +1,358 @@
|
|
|
1
|
+
// src/contrast.ts
|
|
2
|
+
/** WCAG 2's bar for text and the glyphs that carry meaning. */
|
|
3
|
+
const TEXT = 4.5;
|
|
4
|
+
const kansoPairs = [
|
|
5
|
+
...[
|
|
6
|
+
"paper",
|
|
7
|
+
"kanso-surface",
|
|
8
|
+
"surface-sunken",
|
|
9
|
+
"container"
|
|
10
|
+
].flatMap((ground) => [[
|
|
11
|
+
"ink",
|
|
12
|
+
ground,
|
|
13
|
+
TEXT
|
|
14
|
+
], [
|
|
15
|
+
"ink-muted",
|
|
16
|
+
ground,
|
|
17
|
+
TEXT
|
|
18
|
+
]]),
|
|
19
|
+
[
|
|
20
|
+
"on-ink",
|
|
21
|
+
"ink",
|
|
22
|
+
TEXT
|
|
23
|
+
],
|
|
24
|
+
[
|
|
25
|
+
"accent",
|
|
26
|
+
"paper",
|
|
27
|
+
TEXT
|
|
28
|
+
],
|
|
29
|
+
[
|
|
30
|
+
"accent",
|
|
31
|
+
"kanso-surface",
|
|
32
|
+
TEXT
|
|
33
|
+
],
|
|
34
|
+
[
|
|
35
|
+
"on-accent",
|
|
36
|
+
"accent",
|
|
37
|
+
TEXT
|
|
38
|
+
],
|
|
39
|
+
[
|
|
40
|
+
"on-accent-soft",
|
|
41
|
+
"accent-soft",
|
|
42
|
+
TEXT
|
|
43
|
+
],
|
|
44
|
+
[
|
|
45
|
+
"accent-on-ink",
|
|
46
|
+
"ink",
|
|
47
|
+
TEXT
|
|
48
|
+
],
|
|
49
|
+
[
|
|
50
|
+
"on-spotlight",
|
|
51
|
+
"spotlight",
|
|
52
|
+
TEXT
|
|
53
|
+
],
|
|
54
|
+
[
|
|
55
|
+
"on-spotlight-muted",
|
|
56
|
+
"spotlight",
|
|
57
|
+
TEXT
|
|
58
|
+
],
|
|
59
|
+
[
|
|
60
|
+
"on-spotlight",
|
|
61
|
+
"spotlight-tonal over spotlight",
|
|
62
|
+
TEXT
|
|
63
|
+
],
|
|
64
|
+
[
|
|
65
|
+
"on-spotlight-button",
|
|
66
|
+
"spotlight-button",
|
|
67
|
+
TEXT
|
|
68
|
+
],
|
|
69
|
+
[
|
|
70
|
+
"spotlight-line",
|
|
71
|
+
"spotlight",
|
|
72
|
+
3
|
|
73
|
+
],
|
|
74
|
+
[
|
|
75
|
+
"positive",
|
|
76
|
+
"paper",
|
|
77
|
+
TEXT
|
|
78
|
+
],
|
|
79
|
+
[
|
|
80
|
+
"positive",
|
|
81
|
+
"kanso-surface",
|
|
82
|
+
TEXT
|
|
83
|
+
],
|
|
84
|
+
[
|
|
85
|
+
"on-positive-soft",
|
|
86
|
+
"positive-soft",
|
|
87
|
+
TEXT
|
|
88
|
+
],
|
|
89
|
+
[
|
|
90
|
+
"caution",
|
|
91
|
+
"paper",
|
|
92
|
+
TEXT
|
|
93
|
+
],
|
|
94
|
+
[
|
|
95
|
+
"caution",
|
|
96
|
+
"kanso-surface",
|
|
97
|
+
TEXT
|
|
98
|
+
],
|
|
99
|
+
[
|
|
100
|
+
"caution",
|
|
101
|
+
"caution-soft",
|
|
102
|
+
3
|
|
103
|
+
],
|
|
104
|
+
[
|
|
105
|
+
"on-caution-soft",
|
|
106
|
+
"caution-soft",
|
|
107
|
+
TEXT
|
|
108
|
+
],
|
|
109
|
+
[
|
|
110
|
+
"negative",
|
|
111
|
+
"paper",
|
|
112
|
+
TEXT
|
|
113
|
+
],
|
|
114
|
+
[
|
|
115
|
+
"negative",
|
|
116
|
+
"kanso-surface",
|
|
117
|
+
TEXT
|
|
118
|
+
],
|
|
119
|
+
[
|
|
120
|
+
"on-negative-soft",
|
|
121
|
+
"negative-soft",
|
|
122
|
+
TEXT
|
|
123
|
+
],
|
|
124
|
+
[
|
|
125
|
+
"critical",
|
|
126
|
+
"paper",
|
|
127
|
+
TEXT
|
|
128
|
+
],
|
|
129
|
+
[
|
|
130
|
+
"critical",
|
|
131
|
+
"kanso-surface",
|
|
132
|
+
TEXT
|
|
133
|
+
],
|
|
134
|
+
[
|
|
135
|
+
"on-critical",
|
|
136
|
+
"critical",
|
|
137
|
+
TEXT
|
|
138
|
+
],
|
|
139
|
+
[
|
|
140
|
+
"on-critical-soft",
|
|
141
|
+
"critical-soft",
|
|
142
|
+
TEXT
|
|
143
|
+
],
|
|
144
|
+
[
|
|
145
|
+
"outline",
|
|
146
|
+
"paper",
|
|
147
|
+
3
|
|
148
|
+
],
|
|
149
|
+
[
|
|
150
|
+
"outline",
|
|
151
|
+
"kanso-surface",
|
|
152
|
+
3
|
|
153
|
+
],
|
|
154
|
+
[
|
|
155
|
+
"focus-ring",
|
|
156
|
+
"paper",
|
|
157
|
+
3
|
|
158
|
+
]
|
|
159
|
+
];
|
|
160
|
+
const ROLE_GROUNDS = [
|
|
161
|
+
"surface",
|
|
162
|
+
"surface-container-lowest",
|
|
163
|
+
"surface-container-low",
|
|
164
|
+
"surface-container",
|
|
165
|
+
"surface-container-high",
|
|
166
|
+
"surface-container-highest",
|
|
167
|
+
"surface-variant"
|
|
168
|
+
];
|
|
169
|
+
const FILLS = [
|
|
170
|
+
"primary",
|
|
171
|
+
"primary-container",
|
|
172
|
+
"secondary",
|
|
173
|
+
"secondary-container",
|
|
174
|
+
"tertiary",
|
|
175
|
+
"tertiary-container",
|
|
176
|
+
"error",
|
|
177
|
+
"error-container",
|
|
178
|
+
"positive",
|
|
179
|
+
"positive-container",
|
|
180
|
+
"negative",
|
|
181
|
+
"negative-container"
|
|
182
|
+
];
|
|
183
|
+
const rolePairs = [
|
|
184
|
+
...ROLE_GROUNDS.flatMap((ground) => [
|
|
185
|
+
[
|
|
186
|
+
"on-surface",
|
|
187
|
+
ground,
|
|
188
|
+
TEXT
|
|
189
|
+
],
|
|
190
|
+
[
|
|
191
|
+
"on-surface-variant",
|
|
192
|
+
ground,
|
|
193
|
+
TEXT
|
|
194
|
+
],
|
|
195
|
+
[
|
|
196
|
+
"outline",
|
|
197
|
+
ground,
|
|
198
|
+
3
|
|
199
|
+
]
|
|
200
|
+
]),
|
|
201
|
+
...FILLS.map((fill) => [
|
|
202
|
+
`on-${fill}`,
|
|
203
|
+
fill,
|
|
204
|
+
TEXT
|
|
205
|
+
]),
|
|
206
|
+
[
|
|
207
|
+
"inverse-on-surface",
|
|
208
|
+
"inverse-surface",
|
|
209
|
+
TEXT
|
|
210
|
+
],
|
|
211
|
+
[
|
|
212
|
+
"inverse-primary",
|
|
213
|
+
"inverse-surface",
|
|
214
|
+
TEXT
|
|
215
|
+
],
|
|
216
|
+
[
|
|
217
|
+
"inverse-error",
|
|
218
|
+
"inverse-surface",
|
|
219
|
+
TEXT
|
|
220
|
+
],
|
|
221
|
+
[
|
|
222
|
+
"primary",
|
|
223
|
+
"surface",
|
|
224
|
+
TEXT
|
|
225
|
+
],
|
|
226
|
+
[
|
|
227
|
+
"primary",
|
|
228
|
+
"surface-container-low",
|
|
229
|
+
TEXT
|
|
230
|
+
],
|
|
231
|
+
[
|
|
232
|
+
"primary",
|
|
233
|
+
"surface-container-highest",
|
|
234
|
+
TEXT
|
|
235
|
+
],
|
|
236
|
+
[
|
|
237
|
+
"primary",
|
|
238
|
+
"primary-container",
|
|
239
|
+
TEXT
|
|
240
|
+
],
|
|
241
|
+
[
|
|
242
|
+
"secondary",
|
|
243
|
+
"secondary-container",
|
|
244
|
+
TEXT
|
|
245
|
+
],
|
|
246
|
+
[
|
|
247
|
+
"error",
|
|
248
|
+
"surface",
|
|
249
|
+
TEXT
|
|
250
|
+
],
|
|
251
|
+
[
|
|
252
|
+
"error",
|
|
253
|
+
"surface-container-highest",
|
|
254
|
+
TEXT
|
|
255
|
+
],
|
|
256
|
+
[
|
|
257
|
+
"positive",
|
|
258
|
+
"surface",
|
|
259
|
+
TEXT
|
|
260
|
+
],
|
|
261
|
+
[
|
|
262
|
+
"negative",
|
|
263
|
+
"surface",
|
|
264
|
+
TEXT
|
|
265
|
+
],
|
|
266
|
+
[
|
|
267
|
+
"secondary",
|
|
268
|
+
"surface",
|
|
269
|
+
3
|
|
270
|
+
]
|
|
271
|
+
];
|
|
272
|
+
/** WCAG 2's contrast ratio between two opaque colours, 1 to 21. */
|
|
273
|
+
function contrast(first, second) {
|
|
274
|
+
const [lighter = 0, darker = 0] = [luminance(first), luminance(second)].toSorted((a, b) => b - a);
|
|
275
|
+
return (lighter + .05) / (darker + .05);
|
|
276
|
+
}
|
|
277
|
+
/** Whether a value is a colour the contrast check can read. */
|
|
278
|
+
function isColor(value) {
|
|
279
|
+
if (typeof value !== "string") return false;
|
|
280
|
+
try {
|
|
281
|
+
parseColor(value);
|
|
282
|
+
return true;
|
|
283
|
+
} catch {
|
|
284
|
+
return false;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
function luminance([red, green, blue]) {
|
|
288
|
+
const [r = 0, g = 0, b = 0] = [
|
|
289
|
+
red,
|
|
290
|
+
green,
|
|
291
|
+
blue
|
|
292
|
+
].map((channel) => {
|
|
293
|
+
const value = channel / 255;
|
|
294
|
+
return value <= .04045 ? value / 12.92 : ((value + .055) / 1.055) ** 2.4;
|
|
295
|
+
});
|
|
296
|
+
return .2126 * r + .7152 * g + .0722 * b;
|
|
297
|
+
}
|
|
298
|
+
/** A colour painted over an opaque ground, as the eye sees it. */
|
|
299
|
+
function over(color, ground) {
|
|
300
|
+
const [red, green, blue, alpha] = parseColor(color);
|
|
301
|
+
const mix = (top, bottom) => top * alpha + bottom * (1 - alpha);
|
|
302
|
+
return [
|
|
303
|
+
mix(red, ground[0]),
|
|
304
|
+
mix(green, ground[1]),
|
|
305
|
+
mix(blue, ground[2]),
|
|
306
|
+
1
|
|
307
|
+
];
|
|
308
|
+
}
|
|
309
|
+
/**
|
|
310
|
+
* A `#rrggbb` or `rgba(r, g, b, a)` colour, as the token file writes them, as
|
|
311
|
+
* its channels, 0 to 255, and its alpha. Throws for anything else.
|
|
312
|
+
*/
|
|
313
|
+
function parseColor(color) {
|
|
314
|
+
const hex = /^#([\da-f]{2})([\da-f]{2})([\da-f]{2})$/iu.exec(color);
|
|
315
|
+
if (hex) {
|
|
316
|
+
const [, red = "", green = "", blue = ""] = hex;
|
|
317
|
+
return [
|
|
318
|
+
Number.parseInt(red, 16),
|
|
319
|
+
Number.parseInt(green, 16),
|
|
320
|
+
Number.parseInt(blue, 16),
|
|
321
|
+
1
|
|
322
|
+
];
|
|
323
|
+
}
|
|
324
|
+
const rgba = /^rgba\((\d{1,3}), (\d{1,3}), (\d{1,3}), (0|1|0?\.\d+|1\.0+)\)$/u.exec(color);
|
|
325
|
+
if (rgba) {
|
|
326
|
+
const [, red = "", green = "", blue = "", alpha = ""] = rgba;
|
|
327
|
+
const channels = [
|
|
328
|
+
Number(red),
|
|
329
|
+
Number(green),
|
|
330
|
+
Number(blue)
|
|
331
|
+
];
|
|
332
|
+
if (channels.every((channel) => channel <= 255)) {
|
|
333
|
+
const [r = 0, g = 0, b = 0] = channels;
|
|
334
|
+
return [
|
|
335
|
+
r,
|
|
336
|
+
g,
|
|
337
|
+
b,
|
|
338
|
+
Number(alpha)
|
|
339
|
+
];
|
|
340
|
+
}
|
|
341
|
+
}
|
|
342
|
+
throw new TypeError(`not a #rrggbb or rgba() colour: ${color}`);
|
|
343
|
+
}
|
|
344
|
+
/** A pair's ratio in a scheme, its ground resolved first. */
|
|
345
|
+
function ratioOf(scheme, foreground, ground) {
|
|
346
|
+
const colorOf = (name) => {
|
|
347
|
+
const value = scheme[`--kui-color-${name}`];
|
|
348
|
+
if (value === void 0) throw new Error(`no colour ${name}`);
|
|
349
|
+
return value;
|
|
350
|
+
};
|
|
351
|
+
const [top = "", under = top] = ground.split(" over ");
|
|
352
|
+
const base = parseColor(colorOf(under));
|
|
353
|
+
const grounded = top === under ? base : over(colorOf(top), base);
|
|
354
|
+
return contrast(over(colorOf(foreground), grounded), grounded);
|
|
355
|
+
}
|
|
1
356
|
// src/tokens/defaults.ts
|
|
2
357
|
/** Every property at its value in the light scheme, as `tokens.css` declares it. */
|
|
3
358
|
const light = {
|
|
@@ -466,80 +821,192 @@ const breakpoints = {
|
|
|
466
821
|
extraLarge: 1600
|
|
467
822
|
};
|
|
468
823
|
/**
|
|
469
|
-
*
|
|
470
|
-
* the
|
|
471
|
-
*
|
|
472
|
-
|
|
473
|
-
|
|
824
|
+
* The roles a product brings its own colour for, in light and in dark: the
|
|
825
|
+
* accent and the spotlight, each with what is drawn on it. The base fills them
|
|
826
|
+
* from the neutrals, since Kanso's brand is ink and paper.
|
|
827
|
+
*/
|
|
828
|
+
const productRoles = [
|
|
829
|
+
"accent",
|
|
830
|
+
"onAccent",
|
|
831
|
+
"accentSoft",
|
|
832
|
+
"onAccentSoft",
|
|
833
|
+
"accentOnInk",
|
|
834
|
+
"spotlight",
|
|
835
|
+
"onSpotlight",
|
|
836
|
+
"onSpotlightMuted",
|
|
837
|
+
"spotlightButton",
|
|
838
|
+
"onSpotlightButton",
|
|
839
|
+
"spotlightTonal",
|
|
840
|
+
"spotlightLine"
|
|
841
|
+
];
|
|
842
|
+
/**
|
|
843
|
+
* Every colour that follows a product role, in each scheme, and the role it
|
|
844
|
+
* follows, in the scheme it reads it from: `primary` and `focus-ring`
|
|
845
|
+
* follow the accent, `on-primary` the on-accent, and so on. A product role
|
|
846
|
+
* follows itself.
|
|
474
847
|
*/
|
|
475
|
-
const
|
|
848
|
+
const productFollowers = {
|
|
476
849
|
dark: {
|
|
477
|
-
|
|
478
|
-
"--kui-color-accent": "
|
|
479
|
-
"--kui-color-accent-
|
|
480
|
-
"--kui-color-
|
|
481
|
-
"--kui-color-
|
|
482
|
-
"--kui-color-
|
|
483
|
-
"--kui-color-on-accent": "
|
|
484
|
-
"--kui-color-on-
|
|
485
|
-
"--kui-color-on-primary": "
|
|
486
|
-
"--kui-color-on-primary-
|
|
487
|
-
"--kui-color-on-primary-fixed": "
|
|
488
|
-
"--kui-color-on-
|
|
489
|
-
"--kui-color-on-secondary-fixed": "
|
|
490
|
-
"--kui-color-on-
|
|
491
|
-
"--kui-color-on-spotlight-button": "
|
|
492
|
-
"--kui-color-on-
|
|
493
|
-
"--kui-color-on-tertiary
|
|
494
|
-
"--kui-color-on-tertiary-
|
|
495
|
-
"--kui-color-on-tertiary-fixed
|
|
496
|
-
"--kui-color-
|
|
497
|
-
"--kui-color-primary
|
|
498
|
-
"--kui-color-primary-
|
|
499
|
-
"--kui-color-primary-fixed
|
|
500
|
-
"--kui-color-
|
|
501
|
-
"--kui-color-secondary-fixed
|
|
502
|
-
"--kui-color-
|
|
503
|
-
"--kui-color-
|
|
504
|
-
"--kui-color-
|
|
505
|
-
"--kui-color-
|
|
506
|
-
"--kui-color-
|
|
507
|
-
"--kui-color-
|
|
850
|
+
"--kui-color-accent": ["dark", "accent"],
|
|
851
|
+
"--kui-color-accent-on-ink": ["dark", "accentOnInk"],
|
|
852
|
+
"--kui-color-accent-soft": ["dark", "accentSoft"],
|
|
853
|
+
"--kui-color-focus-ring": ["dark", "accent"],
|
|
854
|
+
"--kui-color-inverse-primary": ["dark", "accentOnInk"],
|
|
855
|
+
"--kui-color-on-accent": ["dark", "onAccent"],
|
|
856
|
+
"--kui-color-on-accent-soft": ["dark", "onAccentSoft"],
|
|
857
|
+
"--kui-color-on-primary": ["dark", "onAccent"],
|
|
858
|
+
"--kui-color-on-primary-container": ["dark", "onAccentSoft"],
|
|
859
|
+
"--kui-color-on-primary-fixed": ["dark", "onAccentSoft"],
|
|
860
|
+
"--kui-color-on-primary-fixed-variant": ["dark", "onAccentSoft"],
|
|
861
|
+
"--kui-color-on-secondary-fixed": ["dark", "onAccentSoft"],
|
|
862
|
+
"--kui-color-on-secondary-fixed-variant": ["dark", "onAccentSoft"],
|
|
863
|
+
"--kui-color-on-spotlight": ["dark", "onSpotlight"],
|
|
864
|
+
"--kui-color-on-spotlight-button": ["dark", "onSpotlightButton"],
|
|
865
|
+
"--kui-color-on-spotlight-muted": ["dark", "onSpotlightMuted"],
|
|
866
|
+
"--kui-color-on-tertiary": ["dark", "onAccentSoft"],
|
|
867
|
+
"--kui-color-on-tertiary-container": ["dark", "onAccentSoft"],
|
|
868
|
+
"--kui-color-on-tertiary-fixed": ["dark", "onAccentSoft"],
|
|
869
|
+
"--kui-color-on-tertiary-fixed-variant": ["dark", "onAccentSoft"],
|
|
870
|
+
"--kui-color-primary": ["dark", "accent"],
|
|
871
|
+
"--kui-color-primary-container": ["dark", "accentSoft"],
|
|
872
|
+
"--kui-color-primary-fixed": ["dark", "accentSoft"],
|
|
873
|
+
"--kui-color-primary-fixed-dim": ["dark", "accentSoft"],
|
|
874
|
+
"--kui-color-secondary-fixed": ["dark", "accentSoft"],
|
|
875
|
+
"--kui-color-secondary-fixed-dim": ["dark", "accentSoft"],
|
|
876
|
+
"--kui-color-spotlight": ["dark", "spotlight"],
|
|
877
|
+
"--kui-color-spotlight-button": ["dark", "spotlightButton"],
|
|
878
|
+
"--kui-color-spotlight-line": ["dark", "spotlightLine"],
|
|
879
|
+
"--kui-color-spotlight-tonal": ["dark", "spotlightTonal"],
|
|
880
|
+
"--kui-color-surface-tint": ["dark", "accent"],
|
|
881
|
+
"--kui-color-tertiary": ["dark", "accentSoft"],
|
|
882
|
+
"--kui-color-tertiary-container": ["dark", "accentSoft"],
|
|
883
|
+
"--kui-color-tertiary-fixed": ["dark", "accentSoft"],
|
|
884
|
+
"--kui-color-tertiary-fixed-dim": ["dark", "accentSoft"]
|
|
508
885
|
},
|
|
509
886
|
light: {
|
|
510
|
-
|
|
511
|
-
"--kui-color-accent": "
|
|
512
|
-
"--kui-color-accent-
|
|
513
|
-
"--kui-color-
|
|
514
|
-
"--kui-color-
|
|
515
|
-
"--kui-color-
|
|
516
|
-
"--kui-color-on-accent": "
|
|
517
|
-
"--kui-color-on-
|
|
518
|
-
"--kui-color-on-primary": "
|
|
519
|
-
"--kui-color-on-primary-
|
|
520
|
-
"--kui-color-on-primary-fixed": "
|
|
521
|
-
"--kui-color-on-
|
|
522
|
-
"--kui-color-on-secondary-fixed": "
|
|
523
|
-
"--kui-color-on-
|
|
524
|
-
"--kui-color-on-spotlight-button": "
|
|
525
|
-
"--kui-color-on-
|
|
526
|
-
"--kui-color-on-tertiary
|
|
527
|
-
"--kui-color-on-tertiary-
|
|
528
|
-
"--kui-color-on-tertiary-fixed
|
|
529
|
-
"--kui-color-
|
|
530
|
-
"--kui-color-primary
|
|
531
|
-
"--kui-color-primary-
|
|
532
|
-
"--kui-color-primary-fixed
|
|
533
|
-
"--kui-color-
|
|
534
|
-
"--kui-color-secondary-fixed
|
|
535
|
-
"--kui-color-
|
|
536
|
-
"--kui-color-
|
|
537
|
-
"--kui-color-
|
|
538
|
-
"--kui-color-
|
|
539
|
-
"--kui-color-
|
|
540
|
-
"--kui-color-
|
|
887
|
+
"--kui-color-accent": ["light", "accent"],
|
|
888
|
+
"--kui-color-accent-on-ink": ["light", "accentOnInk"],
|
|
889
|
+
"--kui-color-accent-soft": ["light", "accentSoft"],
|
|
890
|
+
"--kui-color-focus-ring": ["light", "accent"],
|
|
891
|
+
"--kui-color-inverse-primary": ["light", "accentOnInk"],
|
|
892
|
+
"--kui-color-on-accent": ["light", "onAccent"],
|
|
893
|
+
"--kui-color-on-accent-soft": ["light", "onAccentSoft"],
|
|
894
|
+
"--kui-color-on-primary": ["light", "onAccent"],
|
|
895
|
+
"--kui-color-on-primary-container": ["light", "onAccentSoft"],
|
|
896
|
+
"--kui-color-on-primary-fixed": ["light", "onAccentSoft"],
|
|
897
|
+
"--kui-color-on-primary-fixed-variant": ["light", "onAccentSoft"],
|
|
898
|
+
"--kui-color-on-secondary-fixed": ["light", "onAccentSoft"],
|
|
899
|
+
"--kui-color-on-secondary-fixed-variant": ["light", "onAccentSoft"],
|
|
900
|
+
"--kui-color-on-spotlight": ["light", "onSpotlight"],
|
|
901
|
+
"--kui-color-on-spotlight-button": ["light", "onSpotlightButton"],
|
|
902
|
+
"--kui-color-on-spotlight-muted": ["light", "onSpotlightMuted"],
|
|
903
|
+
"--kui-color-on-tertiary": ["light", "onAccentSoft"],
|
|
904
|
+
"--kui-color-on-tertiary-container": ["light", "onAccentSoft"],
|
|
905
|
+
"--kui-color-on-tertiary-fixed": ["light", "onAccentSoft"],
|
|
906
|
+
"--kui-color-on-tertiary-fixed-variant": ["light", "onAccentSoft"],
|
|
907
|
+
"--kui-color-primary": ["light", "accent"],
|
|
908
|
+
"--kui-color-primary-container": ["light", "accentSoft"],
|
|
909
|
+
"--kui-color-primary-fixed": ["light", "accentSoft"],
|
|
910
|
+
"--kui-color-primary-fixed-dim": ["light", "accentSoft"],
|
|
911
|
+
"--kui-color-secondary-fixed": ["light", "accentSoft"],
|
|
912
|
+
"--kui-color-secondary-fixed-dim": ["light", "accentSoft"],
|
|
913
|
+
"--kui-color-spotlight": ["light", "spotlight"],
|
|
914
|
+
"--kui-color-spotlight-button": ["light", "spotlightButton"],
|
|
915
|
+
"--kui-color-spotlight-line": ["light", "spotlightLine"],
|
|
916
|
+
"--kui-color-spotlight-tonal": ["light", "spotlightTonal"],
|
|
917
|
+
"--kui-color-surface-tint": ["light", "accent"],
|
|
918
|
+
"--kui-color-tertiary": ["light", "accentSoft"],
|
|
919
|
+
"--kui-color-tertiary-container": ["light", "accentSoft"],
|
|
920
|
+
"--kui-color-tertiary-fixed": ["light", "accentSoft"],
|
|
921
|
+
"--kui-color-tertiary-fixed-dim": ["light", "accentSoft"]
|
|
541
922
|
}
|
|
542
923
|
};
|
|
543
|
-
|
|
924
|
+
// src/product-theme.ts
|
|
925
|
+
/** Thrown by {@link defineProductTheme} for a palette below a contrast target. */
|
|
926
|
+
var ProductThemeError = class extends Error {
|
|
927
|
+
/** Every pair below its target, in light and then in dark. */
|
|
928
|
+
failures;
|
|
929
|
+
constructor(failures) {
|
|
930
|
+
super(["The product colours miss these contrast targets:", ...failures.map(({ foreground, ground, ratio, scheme, target }) => ` ${scheme}: ${foreground} on ${ground} at ${ratio.toFixed(2)}:1, below ${target}:1`)].join("\n"));
|
|
931
|
+
this.name = "ProductThemeError";
|
|
932
|
+
this.failures = failures;
|
|
933
|
+
}
|
|
934
|
+
};
|
|
935
|
+
const DEFAULTS = {
|
|
936
|
+
dark,
|
|
937
|
+
light
|
|
938
|
+
};
|
|
939
|
+
/** A theme read by any property name, as the contrast pairs name them. */
|
|
940
|
+
function read(map) {
|
|
941
|
+
return map;
|
|
942
|
+
}
|
|
943
|
+
const SCHEMES = ["light", "dark"];
|
|
944
|
+
/**
|
|
945
|
+
* Builds a product's theme from its colours: every colour that follows a
|
|
946
|
+
* product role takes the product's value of it, `primary`, `focus-ring` and
|
|
947
|
+
* the other Material Design roles that alias the accent included, and
|
|
948
|
+
* everything else keeps its default.
|
|
949
|
+
*
|
|
950
|
+
* The colours are held to Kanso's contrast targets, WCAG 2's 4.5:1 for text
|
|
951
|
+
* and 3:1 for the rest, in both schemes, over the same pairs the base clears:
|
|
952
|
+
* those Kanso's usage notes name and those both libraries draw. A palette
|
|
953
|
+
* below one throws a {@link ProductThemeError} naming every pair; one missing
|
|
954
|
+
* a scheme or a role, naming one it does not have, or holding a value that is not a
|
|
955
|
+
* `#rrggbb` or `rgba()` colour throws a `TypeError`.
|
|
956
|
+
*
|
|
957
|
+
* Build it once, as a constant: both libraries' `ThemeScope` is to keep what
|
|
958
|
+
* it resolves for each theme object it is handed.
|
|
959
|
+
*
|
|
960
|
+
* ```ts
|
|
961
|
+
* const productTheme = defineProductTheme({ dark: { accent: '#cdb0f5', … }, light: { accent: '#6b3fa0', … } })
|
|
962
|
+
*
|
|
963
|
+
* <ThemeScope productTheme={productTheme}>…</ThemeScope>
|
|
964
|
+
* ```
|
|
965
|
+
*/
|
|
966
|
+
function defineProductTheme(palette) {
|
|
967
|
+
for (const scheme of SCHEMES) {
|
|
968
|
+
const given = palette[scheme];
|
|
969
|
+
if (typeof given !== "object" || given === null) throw new TypeError(`the palette has no ${scheme} colours`);
|
|
970
|
+
const colors = new Map(Object.entries(given));
|
|
971
|
+
const roles = productRoles;
|
|
972
|
+
const unknown = [...colors.keys()].filter((role) => !roles.includes(role));
|
|
973
|
+
if (unknown.length > 0) throw new TypeError(`${scheme} has no product role ${unknown.join(", ")}; the roles are ${roles.join(", ")}`);
|
|
974
|
+
for (const role of productRoles) if (!isColor(colors.get(role))) throw new TypeError(`${scheme}.${role} takes a #rrggbb or rgba() colour, not ${String(colors.get(role))}`);
|
|
975
|
+
}
|
|
976
|
+
const followed = (scheme) => ({
|
|
977
|
+
...DEFAULTS[scheme],
|
|
978
|
+
...Object.fromEntries(Object.entries(productFollowers[scheme]).map(([property, from]) => [property, palette[from[0]][from[1]]]))
|
|
979
|
+
});
|
|
980
|
+
const maps = {
|
|
981
|
+
dark: followed("dark"),
|
|
982
|
+
light: followed("light")
|
|
983
|
+
};
|
|
984
|
+
const failures = SCHEMES.flatMap((scheme) => [...kansoPairs, ...rolePairs].flatMap(([foreground, ground, target]) => {
|
|
985
|
+
const ratio = ratioOf(maps[scheme], foreground, ground);
|
|
986
|
+
return ratio < target ? [{
|
|
987
|
+
foreground,
|
|
988
|
+
ground,
|
|
989
|
+
ratio,
|
|
990
|
+
scheme,
|
|
991
|
+
target
|
|
992
|
+
}] : [];
|
|
993
|
+
}));
|
|
994
|
+
if (failures.length > 0) throw new ProductThemeError(failures);
|
|
995
|
+
const moved = Object.keys(maps.light).filter((property) => SCHEMES.some((scheme) => read(maps[scheme])[property] !== read(DEFAULTS[scheme])[property]));
|
|
996
|
+
const changesIn = (scheme) => Object.freeze(Object.fromEntries(moved.map((property) => [property, read(maps[scheme])[property]])));
|
|
997
|
+
return Object.freeze({
|
|
998
|
+
changes: Object.freeze({
|
|
999
|
+
dark: changesIn("dark"),
|
|
1000
|
+
light: changesIn("light")
|
|
1001
|
+
}),
|
|
1002
|
+
dark: Object.freeze(maps.dark),
|
|
1003
|
+
light: Object.freeze(maps.light),
|
|
1004
|
+
palette: Object.freeze({
|
|
1005
|
+
dark: Object.freeze({ ...palette.dark }),
|
|
1006
|
+
light: Object.freeze({ ...palette.light })
|
|
1007
|
+
})
|
|
1008
|
+
});
|
|
1009
|
+
}
|
|
1010
|
+
export { light as a, dark as i, defineProductTheme as n, productRoles as o, breakpoints as r, ProductThemeError as t };
|
|
544
1011
|
|
|
545
|
-
//# sourceMappingURL=
|
|
1012
|
+
//# sourceMappingURL=product-theme-CfDDgv7F.js.map
|