@jskit-ai/material-web 0.1.8 → 0.1.10
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/CHANGELOG.md +6 -0
- package/README.md +17 -4
- package/package.json +1 -1
- package/src/client/colorSchemes.js +166 -46
- package/src/client/material.css +45 -5
- package/test/accessibility.browser.test.js +201 -0
- package/test/fixtures/accessibility/index.html +2 -0
- package/test/fixtures/accessibility/main.js +80 -0
- package/test/fixtures/accessibility/vite.config.js +7 -0
- package/test/materialWeb.test.js +157 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- An app's start reuses the Material 3 colours an earlier start computed for the same theme. `materialThemes` (which `createMaterialVuetifyOptions` calls at every start) computed both schemes at every call: 30 ms in Chromium, 120 ms at 4x CPU slowdown, for a seed and two app colours (medians). The colours are now computed once per input, the seed (in any case) and the app's colours with their order and `blend`: a page or process reuses them, and a browser keeps the last four inputs' colours in `localStorage` (`jskit:material-themes`), so a later start takes 1.4 ms (6.6 ms at 4x). Computing them is quicker too, 23 ms (84 ms at 4x): it built three tonal-spot schemes where two are needed, one only to list the role names, and ran `customColor` once per scheme where one call gives both. The colours are the same, byte for byte (one sha256 of three inputs' light and dark themes before and after). A changed seed or colour is another input and is computed again. Stored colours that are not a complete set of hex roles, the scheme's and the input's app colours', or were stored under an earlier revision of the generator (`THEMES_REVISION` in `colorSchemes.js`, raised whenever the same input gives other colours) are computed again, and a browser that refuses storage computes them at each start, as a server does. materialWeb.test.js holds each revision's digest of the colours and fails when they change without a new revision. Measured with Chromium and Node 26 on a 20-thread test host under load, Vibe64's theme input; a seed alone went from 34 to 22 ms on a first visit and 27 to 1.3 ms on a later start.
|
|
6
|
+
|
|
7
|
+
- A radio group's own label and a checkbox's, radio's or switch's description are `on-surface-variant` at full strength, as a text field's label and supporting text are, instead of `on-surface` at Vuetify's medium-emphasis opacity: a group's label measured 4.19:1 in a dialog's `surface-container-high`, under WCAG's 4.5:1 (axe `color-contrast`). A control's own label was already `on-surface` at full strength, and a disabled group or control keeps its fade. `accessibility.browser.test.js` measures them in light and dark.
|
|
8
|
+
- A hidden tooltip is hidden whole: `material.css` hides a `v-tooltip` overlay while its text is hidden. Vuetify 4.3 mounts a tooltip before it first shows (`eager`), and hidden it was a `role="tooltip"` element whose text alone was hidden, an empty tooltip to assistive technology (axe `aria-tooltip-name`, WCAG 4.1.2), and its activator's `aria-describedby` read nothing, since hidden text counts only when the element named is hidden itself. Now no tooltip without a name is in the accessibility tree, and the activator is described by the tooltip's text whether it shows or not; a showing or fading tooltip is untouched. The shell's menu control, Up button and icon page actions all carry one.
|
|
9
|
+
- A card's subtitle is at full strength, as a list item's already was: `on-surface-variant`, Material 3's supporting text, on a surface card (JSKIT's default `surface-container-low` card included) or one without a colour, and the card's own text colour on a coloured card or one with a text colour class; a text colour class on the subtitle still wins. At Vuetify's medium-emphasis opacity it measured 4.35:1 on the default card, under WCAG 1.4.3's 4.5:1 (axe `color-contrast`).
|
|
10
|
+
- A text field's character counter is `on-surface-variant` at full strength beside its supporting text, and `error` on an invalid field, as its messages are and as Material 3 draws it; a counter past its limit stays `error`, and a disabled field's keeps its fade. It kept Vuetify's medium-emphasis opacity, 4.19:1 in a dialog's field, under WCAG 1.4.3's 4.5:1 (axe `color-contrast`), and Vuetify left an invalid field's counter faded in the field's text colour. material-web's new browser test (`accessibility.browser.test.js`) measures the tooltip's role, name and description, and the contrast of card subtitles and counters in light and dark.
|
|
5
11
|
- Skeleton loaders are pale placeholders again: every `v-skeleton-loader` bone (text, heading, avatar, image, button, chip, divider and ossein) is `surface-container-highest`, Material 3's most emphasized neutral container, in light and dark. They were solid `on-surface`, near black in light and near white in dark: Vuetify paints a bone in on-surface at the theme's `border-opacity`, which material-web sets to 1 so that Material 3's outline roles draw at full strength. Material 3 has no skeleton component; its one placeholder colour, Wear's `PlaceholderDefaults.color` (on-surface at 10% over surface-container), lands next to surface-container-highest in both schemes. Each bone's shimmer still sweeps over it, forced colours keep Vuetify's `canvastext` bones, and no app needs an override of its own.
|
|
6
12
|
- Linear progress indicators have Material 3's `secondary-container` track (a `VProgressLinear` default `bgColor`) beside the bar and stop indicator in the app's `color`: Vuetify paints the track in the bar's own colour at the same `border-opacity`, so the track was as solid as the bar, determinate, indeterminate and wavy alike. An app's `bg-color` still sets the track. material-web's browser test measures every coloured bone, its shimmer and each track, light and dark.
|
|
7
13
|
|
package/README.md
CHANGED
|
@@ -49,7 +49,15 @@ export const theme = {
|
|
|
49
49
|
instead (a skeleton loader's bones, a linear progress indicator's track, a
|
|
50
50
|
pagination's current page). There is no
|
|
51
51
|
hand-picked colour and no generator command: change the seed and both schemes
|
|
52
|
-
follow.
|
|
52
|
+
follow. The schemes are computed once per theme input, the seed (in any
|
|
53
|
+
case) and the app's colours with their order and `blend`: a page or process
|
|
54
|
+
reuses the ones it has, and a browser keeps the last four inputs' schemes in
|
|
55
|
+
`localStorage` (`jskit:material-themes`), so its next start computes none. A
|
|
56
|
+
changed seed or colour is another input and is computed again. Stored
|
|
57
|
+
schemes that are not complete sets of hex roles, or were stored under an
|
|
58
|
+
earlier revision of the generator (`THEMES_REVISION` in `colorSchemes.js`,
|
|
59
|
+
raised whenever the same input gives other colours), are computed again, and
|
|
60
|
+
a browser that refuses storage computes them at each start, as a server does.
|
|
53
61
|
- **Icons.** Every Vuetify alias and JSKIT's own aliases are Material Symbols
|
|
54
62
|
Rounded glyphs (outlined, Material Symbols' default; `$<name>Filled` for the
|
|
55
63
|
active navigation item). JSKIT names are the symbol in camelCase: `$arrowBack`,
|
|
@@ -85,12 +93,17 @@ export const theme = {
|
|
|
85
93
|
strength (Vuetify fades it to 24%) and a disabled slider in on-surface at
|
|
86
94
|
38% with its inactive track at 12%, a pagination's current page in the
|
|
87
95
|
activated layer, skeleton loader bones in `surface-container-highest` under
|
|
88
|
-
their shimmer, placeholders, text field labels
|
|
89
|
-
|
|
96
|
+
their shimmer, placeholders, text field labels, supporting text and
|
|
97
|
+
character counters, radio group labels, checkbox, radio and switch
|
|
98
|
+
descriptions, and list item and card subtitles in on-surface-variant
|
|
99
|
+
at full strength (an invalid field's counter in error, as its messages),
|
|
100
|
+
one-line labels that
|
|
90
101
|
end in an ellipsis, 12dp card corners, 28dp dialogs on
|
|
91
102
|
`surface-container-high` at level 3 and bottom sheets with a square card on
|
|
92
103
|
`surface-container-low`, square full-screen dialogs on `surface`, a 48dp touch target on clickable chips,
|
|
93
|
-
inverse-surface tooltips
|
|
104
|
+
inverse-surface tooltips hidden whole while their text is (Vuetify mounts a
|
|
105
|
+
tooltip before it shows, and its hidden overlay was an empty tooltip to
|
|
106
|
+
assistive technology), 40dp outlined segmented buttons and outlined
|
|
94
107
|
filter chips that lead with a check when selected (chips with
|
|
95
108
|
`aria-pressed` too), fixed tabs that share the width or else scroll, dialog
|
|
96
109
|
actions 24dp from the edges, a menu's own list as its container
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jskit-ai/material-web",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.10",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Exact Material 3 for JSKIT Vuetify apps: seed-generated light and dark schemes, Material Symbols Rounded icon aliases, Roboto Flex and Material 3 component defaults.",
|
|
6
6
|
"exports": {
|
|
@@ -110,6 +110,33 @@ const SURFACE_TONES = Object.freeze([
|
|
|
110
110
|
"surface-light"
|
|
111
111
|
]);
|
|
112
112
|
|
|
113
|
+
// Vuetify-only names, each the Material 3 role it takes.
|
|
114
|
+
const VUETIFY_ROLE_NAMES = Object.freeze({
|
|
115
|
+
// Vuetify paints fields, alerts, toolbars and timelines with surface-light; Material 3 uses the highest container.
|
|
116
|
+
"surface-light": "surface-container-highest",
|
|
117
|
+
// Content on every surface tone is on-surface in Material 3; Vuetify would otherwise pick black or white for a
|
|
118
|
+
// bg-surface-container-* or bg-surface-dim/bright element.
|
|
119
|
+
...Object.fromEntries(SURFACE_TONES.map((surface) => [`on-${surface}`, "on-surface"])),
|
|
120
|
+
"primary-darken-1": "on-primary-container",
|
|
121
|
+
"secondary-darken-1": "on-secondary-container"
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* The revision of the colours a theme input gives. A browser keeps the colours it computed for an input under this
|
|
126
|
+
* revision and its later starts reuse them, so bump it whenever the same input gives other colours (a role added or
|
|
127
|
+
* remapped, a status colour moved, another Material Color Utilities): every browser then computes them again.
|
|
128
|
+
* materialWeb.test.js holds the colours of each revision, read from what a browser stores, and fails when they change
|
|
129
|
+
* without it.
|
|
130
|
+
*/
|
|
131
|
+
const THEMES_REVISION = 1;
|
|
132
|
+
// The browser storage item that keeps the colours of the inputs computed last, newest first.
|
|
133
|
+
const STORAGE_ITEM = "jskit:material-themes";
|
|
134
|
+
const STORED_INPUTS = 4;
|
|
135
|
+
// How many inputs' colours one page or process keeps, for an app that calls with many (a seed picker, say).
|
|
136
|
+
const REMEMBERED_INPUTS = 16;
|
|
137
|
+
const HEX = /^#[0-9a-f]{6}$/u;
|
|
138
|
+
const ROLE_NAME = /^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/u;
|
|
139
|
+
|
|
113
140
|
function kebabCase(name) {
|
|
114
141
|
return name.replace(/[A-Z]/gu, (letter) => `-${letter.toLowerCase()}`);
|
|
115
142
|
}
|
|
@@ -128,75 +155,167 @@ function customColorRoleNames(name) {
|
|
|
128
155
|
return [role, `on-${role}`, `${role}-container`, `on-${role}-container`];
|
|
129
156
|
}
|
|
130
157
|
|
|
158
|
+
// Every role a scheme has before the app's own colours: an app colour may not take one of their names.
|
|
159
|
+
const SCHEME_ROLE_NAMES = new Set([
|
|
160
|
+
...ROLE_NAMES.map(kebabCase),
|
|
161
|
+
...Object.keys(STATUS_COLOR_HCT).flatMap(customColorRoleNames),
|
|
162
|
+
...Object.keys(VUETIFY_ROLE_NAMES)
|
|
163
|
+
]);
|
|
164
|
+
|
|
131
165
|
/**
|
|
132
|
-
* Adds a colour's four roles
|
|
133
|
-
* Builder's per-colour Blend toggle does.
|
|
134
|
-
* @param {Record<string, number>}
|
|
166
|
+
* Adds a colour's four roles to the light and the dark scheme, from one customColor (which gives both): harmonized
|
|
167
|
+
* toward the seed unless `blend` is false, as Material Theme Builder's per-colour Blend toggle does.
|
|
168
|
+
* @param {{ light: Record<string, number>, dark: Record<string, number> }} schemes
|
|
135
169
|
* @param {number} seedArgb
|
|
136
|
-
* @param {boolean} dark
|
|
137
170
|
* @param {string} name
|
|
138
171
|
* @param {number} argb
|
|
139
172
|
* @param {boolean} [blend]
|
|
140
173
|
*/
|
|
141
|
-
function addCustomColorRoles(
|
|
174
|
+
function addCustomColorRoles(schemes, seedArgb, name, argb, blend = true) {
|
|
142
175
|
const custom = customColor(seedArgb, { name, value: argb, blend });
|
|
143
|
-
const tones = dark ? custom.dark : custom.light;
|
|
144
176
|
const [role, onRole, containerRole, onContainerRole] = customColorRoleNames(name);
|
|
145
|
-
roles[
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
177
|
+
for (const [roles, tones] of [[schemes.light, custom.light], [schemes.dark, custom.dark]]) {
|
|
178
|
+
roles[role] = tones.color;
|
|
179
|
+
roles[onRole] = tones.onColor;
|
|
180
|
+
roles[containerRole] = tones.colorContainer;
|
|
181
|
+
roles[onContainerRole] = tones.onColorContainer;
|
|
182
|
+
}
|
|
149
183
|
}
|
|
150
184
|
|
|
151
185
|
/**
|
|
152
|
-
*
|
|
153
|
-
* containers, and the Vuetify-only names mapped onto Material 3 roles.
|
|
154
|
-
* @param {SchemeTonalSpot} scheme
|
|
186
|
+
* Every Material 3 role of one scheme in kebab-case.
|
|
155
187
|
* @param {number} seedArgb
|
|
156
188
|
* @param {boolean} dark
|
|
189
|
+
*/
|
|
190
|
+
function materialRoles(seedArgb, dark) {
|
|
191
|
+
const scheme = new SchemeTonalSpot(Hct.fromInt(seedArgb), dark, 0);
|
|
192
|
+
return Object.fromEntries(ROLE_NAMES.map((name) => [kebabCase(name), MaterialDynamicColors[name].getArgb(scheme)]));
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* Both schemes' colours as hex: every Material 3 role in kebab-case, the status colours and the app's own colours
|
|
197
|
+
* with their containers, and the Vuetify-only names mapped onto Material 3 roles. This is the Material Color
|
|
198
|
+
* Utilities work; each scheme and each custom colour is computed once.
|
|
199
|
+
* @param {number} seedArgb
|
|
157
200
|
* @param {Array<[string, number, boolean]>} appColors
|
|
201
|
+
* @returns {{ light: Record<string, string>, dark: Record<string, string> }}
|
|
158
202
|
*/
|
|
159
|
-
function
|
|
160
|
-
const
|
|
161
|
-
for (const name of ROLE_NAMES) {
|
|
162
|
-
roles[kebabCase(name)] = MaterialDynamicColors[name].getArgb(scheme);
|
|
163
|
-
}
|
|
203
|
+
function computeSchemeColors(seedArgb, appColors) {
|
|
204
|
+
const schemes = { light: materialRoles(seedArgb, false), dark: materialRoles(seedArgb, true) };
|
|
164
205
|
for (const [name, { hue, chroma, tone }] of Object.entries(STATUS_COLOR_HCT)) {
|
|
165
|
-
addCustomColorRoles(
|
|
206
|
+
addCustomColorRoles(schemes, seedArgb, name, Hct.from(hue, chroma, tone).toInt());
|
|
166
207
|
}
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
for (const surface of SURFACE_TONES) {
|
|
172
|
-
roles[`on-${surface}`] = roles["on-surface"];
|
|
208
|
+
for (const roles of Object.values(schemes)) {
|
|
209
|
+
for (const [name, role] of Object.entries(VUETIFY_ROLE_NAMES)) {
|
|
210
|
+
roles[name] = roles[role];
|
|
211
|
+
}
|
|
173
212
|
}
|
|
174
|
-
roles["primary-darken-1"] = roles["on-primary-container"];
|
|
175
|
-
roles["secondary-darken-1"] = roles["on-secondary-container"];
|
|
176
213
|
for (const [name, argb, blend] of appColors) {
|
|
177
|
-
addCustomColorRoles(
|
|
214
|
+
addCustomColorRoles(schemes, seedArgb, name, argb, blend);
|
|
215
|
+
}
|
|
216
|
+
const hex = (roles) => Object.fromEntries(Object.entries(roles).map(([name, value]) => [name, hexFromArgb(value)]));
|
|
217
|
+
return { light: hex(schemes.light), dark: hex(schemes.dark) };
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
/** A scheme's colours as a page reads them back from storage: kebab-case names, hex values and every scheme role. */
|
|
221
|
+
function storedColorsAreUsable(colors) {
|
|
222
|
+
return Boolean(
|
|
223
|
+
colors && typeof colors === "object" && !Array.isArray(colors) &&
|
|
224
|
+
Object.entries(colors).every(([name, value]) => ROLE_NAME.test(name) && HEX.test(value)) &&
|
|
225
|
+
[...SCHEME_ROLE_NAMES].every((name) => HEX.test(colors[name]))
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
|
|
229
|
+
/** This page's storage when it runs in a browser and may use it; null on a server or when the browser refuses it. */
|
|
230
|
+
function browserStorage() {
|
|
231
|
+
try {
|
|
232
|
+
return typeof window === "object" && window?.localStorage ? window.localStorage : null;
|
|
233
|
+
} catch {
|
|
234
|
+
return null;
|
|
235
|
+
}
|
|
236
|
+
}
|
|
237
|
+
|
|
238
|
+
/**
|
|
239
|
+
* The inputs' colours earlier starts stored, newest first, as `[input, { light, dark }]`: none when storage holds
|
|
240
|
+
* another revision's, cannot be read or is not what this module wrote.
|
|
241
|
+
* @param {Storage} storage
|
|
242
|
+
*/
|
|
243
|
+
function storedSchemeColors(storage) {
|
|
244
|
+
try {
|
|
245
|
+
const stored = JSON.parse(storage.getItem(STORAGE_ITEM) || "null");
|
|
246
|
+
if (stored?.revision !== THEMES_REVISION || !Array.isArray(stored.inputs)) {
|
|
247
|
+
return [];
|
|
248
|
+
}
|
|
249
|
+
return stored.inputs
|
|
250
|
+
.filter((entry) => typeof entry?.input === "string" && storedColorsAreUsable(entry.light) &&
|
|
251
|
+
storedColorsAreUsable(entry.dark))
|
|
252
|
+
.slice(0, STORED_INPUTS)
|
|
253
|
+
.map(({ input, light, dark }) => [input, { light, dark }]);
|
|
254
|
+
} catch {
|
|
255
|
+
return [];
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
// The colours this page or process has, by input, oldest first: a memo of computed and stored colours.
|
|
260
|
+
const rememberedSchemeColors = new Map();
|
|
261
|
+
|
|
262
|
+
function remember(input, colors) {
|
|
263
|
+
rememberedSchemeColors.delete(input);
|
|
264
|
+
rememberedSchemeColors.set(input, colors);
|
|
265
|
+
for (const oldest of [...rememberedSchemeColors.keys()].slice(0, -REMEMBERED_INPUTS)) {
|
|
266
|
+
rememberedSchemeColors.delete(oldest);
|
|
178
267
|
}
|
|
179
|
-
return roles;
|
|
180
268
|
}
|
|
181
269
|
|
|
182
270
|
/**
|
|
183
|
-
*
|
|
271
|
+
* The colours of one theme input: the ones this page or process has, or an earlier start in this browser stored,
|
|
272
|
+
* and otherwise computed once and stored for the next start. A changed seed or colour is another input.
|
|
273
|
+
* @param {string} input
|
|
184
274
|
* @param {number} seedArgb
|
|
185
|
-
* @param {boolean} dark
|
|
186
275
|
* @param {Array<[string, number, boolean]>} appColors
|
|
187
276
|
*/
|
|
188
|
-
function
|
|
189
|
-
const
|
|
190
|
-
|
|
191
|
-
|
|
277
|
+
function schemeColors(input, seedArgb, appColors) {
|
|
278
|
+
const remembered = rememberedSchemeColors.get(input);
|
|
279
|
+
if (remembered) {
|
|
280
|
+
return remembered;
|
|
281
|
+
}
|
|
282
|
+
const storage = browserStorage();
|
|
283
|
+
const stored = storage ? storedSchemeColors(storage) : [];
|
|
284
|
+
// The stored colours of this input, when they also hold every role of the app's own colours.
|
|
285
|
+
const appRoles = appColors.flatMap(([name]) => customColorRoleNames(name));
|
|
286
|
+
const reused = stored.find(([storedInput, { light, dark }]) => storedInput === input &&
|
|
287
|
+
appRoles.every((role) => HEX.test(light[role]) && HEX.test(dark[role])))?.[1];
|
|
288
|
+
const colors = reused || computeSchemeColors(seedArgb, appColors);
|
|
289
|
+
remember(input, colors);
|
|
290
|
+
if (storage && !reused) {
|
|
291
|
+
try {
|
|
292
|
+
storage.setItem(STORAGE_ITEM, JSON.stringify({
|
|
293
|
+
revision: THEMES_REVISION,
|
|
294
|
+
inputs: [[input, colors], ...stored.filter(([storedInput]) => storedInput !== input)].slice(0, STORED_INPUTS)
|
|
295
|
+
.map(([storedInput, { light, dark }]) => ({ input: storedInput, light, dark }))
|
|
296
|
+
}));
|
|
297
|
+
} catch {
|
|
298
|
+
// Full or refused storage: the next start computes the colours again.
|
|
299
|
+
}
|
|
300
|
+
}
|
|
301
|
+
return colors;
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
/**
|
|
305
|
+
* One Vuetify theme from one scheme's colours, its own objects each time.
|
|
306
|
+
* @param {Record<string, string>} schemeColorsByRole
|
|
307
|
+
* @param {boolean} dark
|
|
308
|
+
*/
|
|
309
|
+
function vuetifyTheme(schemeColorsByRole, dark) {
|
|
310
|
+
const colors = { ...schemeColorsByRole };
|
|
192
311
|
return {
|
|
193
312
|
dark,
|
|
194
313
|
colors,
|
|
195
314
|
variables: {
|
|
196
315
|
...STATE_LAYER_VARIABLES,
|
|
197
316
|
// Channel strings: Vuetify writes them as rgba(var(--v-border-color), var(--v-border-opacity)).
|
|
198
|
-
"border-color": channels(
|
|
199
|
-
"shadow-color": channels(
|
|
317
|
+
"border-color": channels(argbFromHex(colors["outline-variant"])),
|
|
318
|
+
"shadow-color": channels(argbFromHex(colors.shadow)),
|
|
200
319
|
"theme-kbd": colors["surface-container-highest"],
|
|
201
320
|
"theme-on-kbd": colors["on-surface"],
|
|
202
321
|
"theme-code": colors["surface-container"],
|
|
@@ -213,15 +332,14 @@ function vuetifyTheme(seedArgb, dark, appColors) {
|
|
|
213
332
|
* scheme roles, and each a six-digit hex value (harmonized toward the seed) or `{ value, blend }`, where
|
|
214
333
|
* `blend: false` keeps the colour's own hue.
|
|
215
334
|
* @param {Record<string, string | { value: string, blend?: boolean }>} colors
|
|
216
|
-
* @param {Set<string>} schemeRoles
|
|
217
335
|
* @returns {Array<[string, number, boolean]>}
|
|
218
336
|
*/
|
|
219
|
-
function normalizeAppColors(colors
|
|
337
|
+
function normalizeAppColors(colors) {
|
|
220
338
|
return Object.entries(colors).map(([name, value]) => {
|
|
221
339
|
if (!/^[a-z][A-Za-z0-9]*$/u.test(name)) {
|
|
222
340
|
throw new TypeError(`Theme colour "${name}" needs a camelCase name, such as "partner" or "brandAccent".`);
|
|
223
341
|
}
|
|
224
|
-
const clash = customColorRoleNames(name).find((role) =>
|
|
342
|
+
const clash = customColorRoleNames(name).find((role) => SCHEME_ROLE_NAMES.has(role));
|
|
225
343
|
if (clash) {
|
|
226
344
|
throw new TypeError(`Theme colour "${name}" would replace the scheme's "${clash}" role; choose another name.`);
|
|
227
345
|
}
|
|
@@ -243,7 +361,9 @@ function normalizeAppColors(colors, schemeRoles) {
|
|
|
243
361
|
* (SchemeTonalSpot, the Material 3 default), as Vuetify themes named light and dark. Each of the app's own colours
|
|
244
362
|
* adds four roles in both schemes, harmonized toward the seed as Material Theme Builder's custom colours are:
|
|
245
363
|
* `partner: "#0A7D3E"` gives partner, on-partner, partner-container and on-partner-container. A brand or partner
|
|
246
|
-
* colour that must keep its hue is `{ value: "#F5C518", blend: false }`, Theme Builder's Blend switched off.
|
|
364
|
+
* colour that must keep its hue is `{ value: "#F5C518", blend: false }`, Theme Builder's Blend switched off. The colours
|
|
365
|
+
* of one input are computed once: a page or process reuses them, and a browser keeps the last few inputs' colours for
|
|
366
|
+
* its later starts (see THEMES_REVISION); a changed seed or colour computes them again.
|
|
247
367
|
* @param {string} seed A hex colour such as "#6750A4".
|
|
248
368
|
* @param {Record<string, string | { value: string, blend?: boolean }>} [colors] The app's own colours by camelCase
|
|
249
369
|
* name: hex colours, or `{ value, blend }`.
|
|
@@ -253,12 +373,12 @@ function materialThemes(seed, colors = {}) {
|
|
|
253
373
|
if (!/^#[0-9a-f]{6}$/iu.test(normalizedSeed)) {
|
|
254
374
|
throw new TypeError(`The Material theme seed must be a six-digit hex colour, not "${normalizedSeed}".`);
|
|
255
375
|
}
|
|
256
|
-
const
|
|
257
|
-
const
|
|
258
|
-
const
|
|
376
|
+
const appColors = normalizeAppColors(colors);
|
|
377
|
+
const input = JSON.stringify([normalizedSeed.toLowerCase(), appColors]);
|
|
378
|
+
const { light, dark } = schemeColors(input, argbFromHex(normalizedSeed), appColors);
|
|
259
379
|
return {
|
|
260
|
-
light: vuetifyTheme(
|
|
261
|
-
dark: vuetifyTheme(
|
|
380
|
+
light: vuetifyTheme(light, false),
|
|
381
|
+
dark: vuetifyTheme(dark, true)
|
|
262
382
|
};
|
|
263
383
|
}
|
|
264
384
|
|
package/src/client/material.css
CHANGED
|
@@ -282,6 +282,15 @@
|
|
|
282
282
|
padding: 4px 8px;
|
|
283
283
|
}
|
|
284
284
|
|
|
285
|
+
/* A hidden tooltip is hidden whole. Vuetify 4.3 mounts a tooltip before it first shows (eager), and while it is
|
|
286
|
+
hidden only its text is: the role="tooltip" overlay around it stays drawn, an empty tooltip to assistive
|
|
287
|
+
technology (axe aria-tooltip-name), and its activator's aria-describedby reads nothing, since hidden text counts
|
|
288
|
+
only when the element the activator names is hidden itself. The overlay hides only while its text does, so a
|
|
289
|
+
showing or fading tooltip is untouched. */
|
|
290
|
+
.v-tooltip:has(> .v-overlay__content[style*="display: none"]) {
|
|
291
|
+
display: none;
|
|
292
|
+
}
|
|
293
|
+
|
|
285
294
|
/* Segmented buttons (v-btn-toggle): a 40dp pill in the outline role whose segments share its width, each with a 48dp
|
|
286
295
|
touch target. An unselected segment has no container; the selected one is secondary-container and leads with a
|
|
287
296
|
check, which takes the place of its icon. */
|
|
@@ -461,16 +470,34 @@
|
|
|
461
470
|
opacity: 1;
|
|
462
471
|
}
|
|
463
472
|
|
|
464
|
-
/* A text field's label
|
|
465
|
-
draws them, instead of Vuetify's on-surface at the medium-emphasis opacity: 4.4:1 on a
|
|
466
|
-
WCAG's 4.5:1. A focused field's label keeps the field's
|
|
467
|
-
and a
|
|
473
|
+
/* A text field's label, its supporting text and its character counter are on-surface-variant at full strength, as
|
|
474
|
+
Material 3's text field draws them, instead of Vuetify's on-surface at the medium-emphasis opacity: 4.4:1 on a
|
|
475
|
+
light surface and 4.19:1 for a counter in a dialog, under WCAG's 4.5:1. A focused field's label keeps the field's
|
|
476
|
+
colour, an invalid field's label, messages and counter are error, a counter past its limit is error too, and a
|
|
477
|
+
disabled field keeps its own fade. */
|
|
468
478
|
.v-field:not(.v-field--focused, .v-field--error) .v-label.v-field-label {
|
|
469
479
|
color: rgb(var(--v-theme-on-surface-variant));
|
|
470
480
|
opacity: 1;
|
|
471
481
|
}
|
|
472
482
|
|
|
473
|
-
.v-input:not(.v-input--error, .v-input--disabled) > .v-input__details .v-messages {
|
|
483
|
+
.v-input:not(.v-input--error, .v-input--disabled) > .v-input__details :is(.v-messages, .v-counter) {
|
|
484
|
+
color: rgb(var(--v-theme-on-surface-variant));
|
|
485
|
+
opacity: 1;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
/* Vuetify draws an invalid field's messages in error at full strength and leaves its counter faded; Material 3's
|
|
489
|
+
counter is error with them. */
|
|
490
|
+
.v-input--error:not(.v-input--disabled) > .v-input__details .v-counter {
|
|
491
|
+
color: rgb(var(--v-theme-error));
|
|
492
|
+
opacity: 1;
|
|
493
|
+
}
|
|
494
|
+
|
|
495
|
+
/* So are a radio group's own label and a checkbox's, radio's or switch's description, its supporting text, instead
|
|
496
|
+
of on-surface at the medium-emphasis opacity: 4.19:1 for a group's label in a dialog, under WCAG's 4.5:1. A
|
|
497
|
+
control's own label is already on-surface at full strength, Material 3's colour for it, and a disabled group or
|
|
498
|
+
control keeps its own fade. */
|
|
499
|
+
.v-radio-group:not(.v-input--disabled) > .v-input__control > .v-label,
|
|
500
|
+
.v-selection-control:not(.v-selection-control--disabled) .v-selection-control__description {
|
|
474
501
|
color: rgb(var(--v-theme-on-surface-variant));
|
|
475
502
|
opacity: 1;
|
|
476
503
|
}
|
|
@@ -488,6 +515,19 @@
|
|
|
488
515
|
color: rgb(var(--v-theme-on-surface-variant));
|
|
489
516
|
}
|
|
490
517
|
|
|
518
|
+
/* So is a card's subtitle, instead of the card's colour at the medium-emphasis opacity: 4.35:1 on the default
|
|
519
|
+
surface-container-low card, under WCAG's 4.5:1. On a surface card, or one without a colour, it is
|
|
520
|
+
on-surface-variant, Material 3's supporting text; a coloured card keeps its own on-colour, and so does a card with
|
|
521
|
+
its own text colour. A text colour class on the subtitle itself still wins. */
|
|
522
|
+
.v-card-subtitle {
|
|
523
|
+
opacity: 1;
|
|
524
|
+
}
|
|
525
|
+
|
|
526
|
+
.v-card:not([class*="bg-"], [class*=" text-"]) .v-card-subtitle,
|
|
527
|
+
.v-card[class*="bg-surface"]:not([class*=" text-"]) .v-card-subtitle {
|
|
528
|
+
color: rgb(var(--v-theme-on-surface-variant));
|
|
529
|
+
}
|
|
530
|
+
|
|
491
531
|
/* Dividers and table rules use outline-variant at full strength (the theme's border colour). Vuetify draws a
|
|
492
532
|
divider in the text colour, so one without a color prop takes outline-variant. */
|
|
493
533
|
.v-divider {
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import assert from "node:assert/strict";
|
|
2
|
+
import process from "node:process";
|
|
3
|
+
import test from "node:test";
|
|
4
|
+
import { fileURLToPath } from "node:url";
|
|
5
|
+
import { expect } from "@playwright/test";
|
|
6
|
+
import { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
7
|
+
import { materialThemes } from "../src/client/index.js";
|
|
8
|
+
|
|
9
|
+
const SKIP = process.env.JSKIT_MATERIAL_WEB_BROWSER === "1" ? false : "set JSKIT_MATERIAL_WEB_BROWSER=1";
|
|
10
|
+
const open = sharedBrowserFixture({
|
|
11
|
+
fixtureRoot: fileURLToPath(new URL("./fixtures/accessibility", import.meta.url)),
|
|
12
|
+
configFile: "vite.config.js"
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
// A theme colour as the "r, g, b" a drawn part is measured in.
|
|
16
|
+
const channels = (hex) => [1, 3, 5].map((start) => Number.parseInt(hex.slice(start, start + 2), 16)).join(", ");
|
|
17
|
+
|
|
18
|
+
// What a piece of text shows on the page: its colour, the background under it and its contrast ratio, as axe's
|
|
19
|
+
// color-contrast measures it. Colours are painted on a canvas so that rgb(), color(srgb ...) and color-mix() all read
|
|
20
|
+
// as 8-bit channels. The text's opacity is its colour's alpha times its own opacity and every ancestor's; the
|
|
21
|
+
// background is the nearest opaque one, under a tonal card's underlay.
|
|
22
|
+
function drawnText(locator) {
|
|
23
|
+
return locator.evaluate((text) => {
|
|
24
|
+
const context = document.createElement("canvas").getContext("2d", { willReadFrequently: true });
|
|
25
|
+
const paint = (value) => {
|
|
26
|
+
context.clearRect(0, 0, 1, 1);
|
|
27
|
+
context.fillStyle = value;
|
|
28
|
+
context.fillRect(0, 0, 1, 1);
|
|
29
|
+
const [red, green, blue, alpha] = context.getImageData(0, 0, 1, 1).data;
|
|
30
|
+
return { red, green, blue, alpha: alpha / 255 };
|
|
31
|
+
};
|
|
32
|
+
const mix = (top, bottom, alpha) => ({
|
|
33
|
+
red: top.red * alpha + bottom.red * (1 - alpha),
|
|
34
|
+
green: top.green * alpha + bottom.green * (1 - alpha),
|
|
35
|
+
blue: top.blue * alpha + bottom.blue * (1 - alpha),
|
|
36
|
+
alpha: 1
|
|
37
|
+
});
|
|
38
|
+
const luminance = ({ red, green, blue }) => {
|
|
39
|
+
const linear = (channel) => {
|
|
40
|
+
const value = channel / 255;
|
|
41
|
+
return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
|
|
42
|
+
};
|
|
43
|
+
return 0.2126 * linear(red) + 0.7152 * linear(green) + 0.0722 * linear(blue);
|
|
44
|
+
};
|
|
45
|
+
let background = null;
|
|
46
|
+
const underlays = [];
|
|
47
|
+
for (let node = text; node && !background; node = node.parentElement) {
|
|
48
|
+
const underlay = node.querySelector(":scope > .v-card__underlay");
|
|
49
|
+
if (underlay) underlays.unshift(underlay);
|
|
50
|
+
const colour = paint(getComputedStyle(node).backgroundColor);
|
|
51
|
+
if (colour.alpha === 1) background = colour;
|
|
52
|
+
}
|
|
53
|
+
for (const underlay of underlays) {
|
|
54
|
+
const layer = paint(getComputedStyle(underlay).backgroundColor);
|
|
55
|
+
background = mix(layer, background, layer.alpha * Number(getComputedStyle(underlay).opacity));
|
|
56
|
+
}
|
|
57
|
+
let opacity = 1;
|
|
58
|
+
for (let node = text; node; node = node.parentElement) opacity *= Number(getComputedStyle(node).opacity);
|
|
59
|
+
const colour = paint(getComputedStyle(text).color);
|
|
60
|
+
const shown = mix(colour, background, colour.alpha * opacity);
|
|
61
|
+
const [lighter, darker] = [luminance(shown), luminance(background)].sort((a, b) => b - a);
|
|
62
|
+
return {
|
|
63
|
+
color: `${colour.red}, ${colour.green}, ${colour.blue}`,
|
|
64
|
+
opacity: Math.round(colour.alpha * opacity * 1000) / 1000,
|
|
65
|
+
background: `${Math.round(background.red)}, ${Math.round(background.green)}, ${Math.round(background.blue)}`,
|
|
66
|
+
ratio: Math.round(((lighter + 0.05) / (darker + 0.05)) * 100) / 100
|
|
67
|
+
};
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
// Vuetify 4.3 mounts a tooltip before it first shows (eager): hidden, it is a role="tooltip" overlay whose text alone
|
|
72
|
+
// is hidden, so assistive technology met an empty tooltip (axe aria-tooltip-name), and the activator's
|
|
73
|
+
// aria-describedby, which names that overlay, read nothing. material.css hides the overlay whole while its text is
|
|
74
|
+
// hidden: no tooltip without a name, and the activator described by the tooltip's text, hidden or shown.
|
|
75
|
+
test("a hidden tooltip leaves no tooltip without a name and still describes its button: WCAG 4.1.2 (axe aria-tooltip-name)", {
|
|
76
|
+
skip: SKIP,
|
|
77
|
+
timeout: 120_000
|
|
78
|
+
}, async (t) => {
|
|
79
|
+
const { vite, browser } = await open(t);
|
|
80
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, reducedMotion: "reduce" });
|
|
81
|
+
await page.goto("/");
|
|
82
|
+
const button = page.getByTestId("tooltip-activator");
|
|
83
|
+
await expect(button).toBeVisible();
|
|
84
|
+
// Vuetify has mounted the tooltip with its text hidden inside it before it ever showed.
|
|
85
|
+
const content = page.locator(".v-tooltip > .v-overlay__content");
|
|
86
|
+
await expect(content).toHaveCount(1);
|
|
87
|
+
await expect(content).toHaveText("Delete this report");
|
|
88
|
+
await expect(content).toBeHidden();
|
|
89
|
+
|
|
90
|
+
await expect(page.getByRole("tooltip"), "no tooltip in the accessibility tree while hidden").toHaveCount(0);
|
|
91
|
+
await expect(button).toHaveAccessibleName("Delete");
|
|
92
|
+
await expect(button).toHaveAccessibleDescription("Delete this report");
|
|
93
|
+
|
|
94
|
+
await button.hover();
|
|
95
|
+
await expect(page.getByRole("tooltip", { name: "Delete this report" })).toBeVisible();
|
|
96
|
+
await expect(button).toHaveAccessibleDescription("Delete this report");
|
|
97
|
+
|
|
98
|
+
await page.mouse.move(0, 0);
|
|
99
|
+
await expect(content).toBeHidden();
|
|
100
|
+
await expect(page.getByRole("tooltip"), "none again once it hides").toHaveCount(0);
|
|
101
|
+
await expect(button).toHaveAccessibleDescription("Delete this report");
|
|
102
|
+
});
|
|
103
|
+
|
|
104
|
+
// A card's subtitle is its supporting text, at full strength: on-surface-variant on a surface card or one without a
|
|
105
|
+
// colour, the card's own text colour on a coloured card, and its own class's colour when it has one. At Vuetify's
|
|
106
|
+
// medium-emphasis opacity it measured 4.35:1 on JSKIT's default surface-container-low card, under WCAG's 4.5:1.
|
|
107
|
+
test("a card's subtitle reads at 4.5:1 or more on every card, in light and dark: WCAG 1.4.3 (axe color-contrast)", {
|
|
108
|
+
skip: SKIP,
|
|
109
|
+
timeout: 120_000
|
|
110
|
+
}, async (t) => {
|
|
111
|
+
const { vite, browser } = await open(t);
|
|
112
|
+
for (const scheme of ["light", "dark"]) {
|
|
113
|
+
const { colors } = materialThemes("#6750A4")[scheme];
|
|
114
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, colorScheme: scheme, reducedMotion: "reduce" });
|
|
115
|
+
await page.goto("/");
|
|
116
|
+
const subtitles = {
|
|
117
|
+
"default-card": ["on-surface-variant", "surface-container-low"],
|
|
118
|
+
"surface-card": ["on-surface-variant", "surface-container-high"],
|
|
119
|
+
"uncoloured-card": ["on-surface-variant", "surface"],
|
|
120
|
+
"primary-card": ["on-primary", "primary"],
|
|
121
|
+
"tonal-card": ["primary"],
|
|
122
|
+
"subtitle-class-card": ["error", "surface-container-low"]
|
|
123
|
+
};
|
|
124
|
+
for (const [testId, [role, background]] of Object.entries(subtitles)) {
|
|
125
|
+
const at = `${scheme} ${testId}`;
|
|
126
|
+
const subtitle = await drawnText(page.getByTestId(testId).locator(".v-card-subtitle"));
|
|
127
|
+
assert.ok(subtitle.ratio >= 4.5, `${at}: the subtitle's contrast was ${subtitle.ratio}:1`);
|
|
128
|
+
assert.equal(subtitle.opacity, 1, `${at}: the subtitle is at full strength`);
|
|
129
|
+
assert.equal(subtitle.color, channels(colors[role]), `${at}: the subtitle is ${role}`);
|
|
130
|
+
if (background) assert.equal(subtitle.background, channels(colors[background]), `${at}: on ${background}`);
|
|
131
|
+
}
|
|
132
|
+
await page.close();
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
// A text field's character counter is supporting text beside its messages, at full strength: on-surface-variant on
|
|
137
|
+
// a valid field, error on an invalid one or past its limit, and a disabled field's keeps its fade. At Vuetify's
|
|
138
|
+
// medium-emphasis opacity it measured 4.19:1 on a dialog's surface-container-high, under WCAG's 4.5:1.
|
|
139
|
+
test("a text field's character counter reads at 4.5:1 or more on a dialog's surface, in light and dark: WCAG 1.4.3 (axe color-contrast)", {
|
|
140
|
+
skip: SKIP,
|
|
141
|
+
timeout: 120_000
|
|
142
|
+
}, async (t) => {
|
|
143
|
+
const { vite, browser } = await open(t);
|
|
144
|
+
for (const scheme of ["light", "dark"]) {
|
|
145
|
+
const { colors } = materialThemes("#6750A4")[scheme];
|
|
146
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, colorScheme: scheme, reducedMotion: "reduce" });
|
|
147
|
+
await page.goto("/");
|
|
148
|
+
const counters = {
|
|
149
|
+
"counter-field": ["on-surface-variant", "3 / 20"],
|
|
150
|
+
"invalid-counter-field": ["error", "2 / 20"],
|
|
151
|
+
"over-counter-field": ["error", "7 / 4"]
|
|
152
|
+
};
|
|
153
|
+
for (const [testId, [role, text]] of Object.entries(counters)) {
|
|
154
|
+
const at = `${scheme} ${testId}`;
|
|
155
|
+
const counter = page.getByTestId(testId).locator(".v-counter");
|
|
156
|
+
await expect(counter, at).toHaveText(text);
|
|
157
|
+
const drawn = await drawnText(counter);
|
|
158
|
+
assert.ok(drawn.ratio >= 4.5, `${at}: the counter's contrast was ${drawn.ratio}:1`);
|
|
159
|
+
assert.equal(drawn.opacity, 1, `${at}: the counter is at full strength`);
|
|
160
|
+
assert.equal(drawn.color, channels(colors[role]), `${at}: the counter is ${role}`);
|
|
161
|
+
assert.equal(drawn.background, channels(colors["surface-container-high"]), `${at}: on surface-container-high`);
|
|
162
|
+
}
|
|
163
|
+
// WCAG exempts a disabled control's text: it keeps the field's own fade.
|
|
164
|
+
const disabled = await drawnText(page.getByTestId("disabled-counter-field").locator(".v-counter"));
|
|
165
|
+
assert.ok(disabled.opacity < 1, `${scheme}: a disabled field's counter keeps its fade (${disabled.opacity})`);
|
|
166
|
+
await page.close();
|
|
167
|
+
}
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
// A radio group's own label and a selection control's description are supporting text, at full strength in
|
|
171
|
+
// on-surface-variant; a checkbox's own label is on-surface, as Vuetify already draws it. At Vuetify's medium-emphasis
|
|
172
|
+
// opacity a group's label measured 4.19:1 in a dialog's surface-container-high ("Flag to raise"), under WCAG's 4.5:1.
|
|
173
|
+
test("a radio group's label and a checkbox's label and description read at 4.5:1 or more on a dialog's surface, in light and dark: WCAG 1.4.3 (axe color-contrast)", {
|
|
174
|
+
skip: SKIP,
|
|
175
|
+
timeout: 120_000
|
|
176
|
+
}, async (t) => {
|
|
177
|
+
const { vite, browser } = await open(t);
|
|
178
|
+
for (const scheme of ["light", "dark"]) {
|
|
179
|
+
const { colors } = materialThemes("#6750A4")[scheme];
|
|
180
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, colorScheme: scheme, reducedMotion: "reduce" });
|
|
181
|
+
await page.goto("/");
|
|
182
|
+
const texts = {
|
|
183
|
+
"radio group's label": [page.getByTestId("radio-group-field").locator(".v-input__control > .v-label"), "on-surface-variant", "Flag to raise"],
|
|
184
|
+
"checkbox's label": [page.getByTestId("checkbox-field").locator(".v-selection-control .v-label"), "on-surface", "Include archived records"],
|
|
185
|
+
"checkbox's description": [page.getByTestId("checkbox-field").locator(".v-selection-control__description"), "on-surface-variant", "Archived records are read-only"]
|
|
186
|
+
};
|
|
187
|
+
for (const [name, [locator, role, text]] of Object.entries(texts)) {
|
|
188
|
+
const at = `${scheme} ${name}`;
|
|
189
|
+
await expect(locator, at).toHaveText(text);
|
|
190
|
+
const drawn = await drawnText(locator);
|
|
191
|
+
assert.ok(drawn.ratio >= 4.5, `${at}: the contrast was ${drawn.ratio}:1`);
|
|
192
|
+
assert.equal(drawn.opacity, 1, `${at}: at full strength`);
|
|
193
|
+
assert.equal(drawn.color, channels(colors[role]), `${at}: ${role}`);
|
|
194
|
+
assert.equal(drawn.background, channels(colors["surface-container-high"]), `${at}: on surface-container-high`);
|
|
195
|
+
}
|
|
196
|
+
// WCAG exempts a disabled control's text: a disabled group's label keeps its fade.
|
|
197
|
+
const disabled = await drawnText(page.getByTestId("disabled-radio-group-field").locator(".v-input__control > .v-label"));
|
|
198
|
+
assert.ok(disabled.opacity < 1, `${scheme}: a disabled radio group's label keeps its fade (${disabled.opacity})`);
|
|
199
|
+
await page.close();
|
|
200
|
+
}
|
|
201
|
+
});
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
import { createApp, h } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VApp } from "vuetify/components/VApp";
|
|
4
|
+
import { VBtn } from "vuetify/components/VBtn";
|
|
5
|
+
import { VCard, VCardItem, VCardSubtitle, VCardText, VCardTitle } from "vuetify/components/VCard";
|
|
6
|
+
import { VCheckbox } from "vuetify/components/VCheckbox";
|
|
7
|
+
import { VIcon } from "vuetify/components/VIcon";
|
|
8
|
+
import { VMain } from "vuetify/components/VMain";
|
|
9
|
+
import { VRadio } from "vuetify/components/VRadio";
|
|
10
|
+
import { VRadioGroup } from "vuetify/components/VRadioGroup";
|
|
11
|
+
import { VTextField } from "vuetify/components/VTextField";
|
|
12
|
+
import { VTooltip } from "vuetify/components/VTooltip";
|
|
13
|
+
import "vuetify/styles";
|
|
14
|
+
import "../../../src/client/material.css";
|
|
15
|
+
import { createMaterialVuetifyOptions } from "../../../src/client/index.js";
|
|
16
|
+
|
|
17
|
+
// What axe measures on an app's screens, with JSKIT's Material 3 options and stylesheet, as an app draws them, in the
|
|
18
|
+
// browser's light or dark scheme (accessibility.browser.test.js):
|
|
19
|
+
// - an icon button with Vuetify's tooltip as its own child, as the shell's menu control has; the tooltip keeps
|
|
20
|
+
// Vuetify's defaults, so it is mounted before it first shows;
|
|
21
|
+
// - cards with a title and a subtitle: JSKIT's default (flat on surface-container-low), another surface container,
|
|
22
|
+
// one without a colour, a coloured one, a tonal one (its colour is its text colour) and a default one whose subtitle
|
|
23
|
+
// has a colour class of its own;
|
|
24
|
+
// - text fields with a character counter on a dialog's surface-container-high: a valid one, an invalid one, one past
|
|
25
|
+
// its limit and a disabled one;
|
|
26
|
+
// - beside them, a radio group with its own label, a disabled one, and a checkbox with a label and a description.
|
|
27
|
+
const cards = [
|
|
28
|
+
{ testId: "default-card", props: {} },
|
|
29
|
+
{ testId: "surface-card", props: { color: "surface-container-high" } },
|
|
30
|
+
{ testId: "uncoloured-card", props: { color: null } },
|
|
31
|
+
{ testId: "primary-card", props: { color: "primary" } },
|
|
32
|
+
{ testId: "tonal-card", props: { color: "primary", variant: "tonal" } },
|
|
33
|
+
{ testId: "subtitle-class-card", props: {}, subtitleClass: "text-error" }
|
|
34
|
+
];
|
|
35
|
+
|
|
36
|
+
const fields = [
|
|
37
|
+
{ testId: "counter-field", props: { label: "Name", modelValue: "Ana" } },
|
|
38
|
+
{ testId: "invalid-counter-field", props: { label: "Code", modelValue: "AB", errorMessages: ["Use four letters"] } },
|
|
39
|
+
{ testId: "over-counter-field", props: { label: "Initials", modelValue: "ABCDEFG", counter: 4 } },
|
|
40
|
+
{ testId: "disabled-counter-field", props: { label: "Team", modelValue: "Blue", disabled: true } }
|
|
41
|
+
];
|
|
42
|
+
|
|
43
|
+
const tooltipButton = () => h(VBtn, { icon: true, variant: "text", "aria-label": "Delete", "data-testid": "tooltip-activator" }, () => [
|
|
44
|
+
h(VIcon, { icon: "$delete" }),
|
|
45
|
+
h(VTooltip, { activator: "parent", location: "bottom", text: "Delete this report" })
|
|
46
|
+
]);
|
|
47
|
+
|
|
48
|
+
const card = ({ testId, props, subtitleClass }) => h(VCard, { ...props, class: "mb-4", "data-testid": testId }, () => (
|
|
49
|
+
h(VCardItem, null, () => [
|
|
50
|
+
h(VCardTitle, null, () => "Quarterly report"),
|
|
51
|
+
h(VCardSubtitle, { class: subtitleClass }, () => "Updated yesterday")
|
|
52
|
+
])
|
|
53
|
+
));
|
|
54
|
+
|
|
55
|
+
const radioGroup = (testId, props) => h(VRadioGroup, { label: "Flag to raise", modelValue: "review", ...props, "data-testid": testId }, () => [
|
|
56
|
+
h(VRadio, { label: "Needs review", value: "review" }),
|
|
57
|
+
h(VRadio, { label: "Duplicate", value: "duplicate" })
|
|
58
|
+
]);
|
|
59
|
+
|
|
60
|
+
const fieldsCard = () => h(VCard, { color: "surface-container-high", "data-testid": "fields-card" }, () => (
|
|
61
|
+
h(VCardText, null, () => [
|
|
62
|
+
...fields.map(({ testId, props }) => h(VTextField, { counter: 20, persistentCounter: true, ...props, "data-testid": testId })),
|
|
63
|
+
radioGroup("radio-group-field", {}),
|
|
64
|
+
radioGroup("disabled-radio-group-field", { disabled: true }),
|
|
65
|
+
h(VCheckbox, {
|
|
66
|
+
label: "Include archived records",
|
|
67
|
+
description: "Archived records are read-only",
|
|
68
|
+
modelValue: true,
|
|
69
|
+
"data-testid": "checkbox-field"
|
|
70
|
+
})
|
|
71
|
+
])
|
|
72
|
+
));
|
|
73
|
+
|
|
74
|
+
const App = () => h(VApp, () => h(VMain, { class: "pa-6" }, () => [
|
|
75
|
+
h("div", { class: "mb-6" }, tooltipButton()),
|
|
76
|
+
...cards.map(card),
|
|
77
|
+
fieldsCard()
|
|
78
|
+
]));
|
|
79
|
+
|
|
80
|
+
createApp(App).use(createVuetify(createMaterialVuetifyOptions())).mount("#app");
|
package/test/materialWeb.test.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import assert from "node:assert/strict";
|
|
2
|
+
import { createHash } from "node:crypto";
|
|
2
3
|
import { readFile } from "node:fs/promises";
|
|
3
4
|
import { createRequire } from "node:module";
|
|
4
5
|
import path from "node:path";
|
|
@@ -122,6 +123,141 @@ test("theme variables carry Material 3 state layers and channel strings for bord
|
|
|
122
123
|
assert.equal(light.variables["border-color"], "202, 196, 207");
|
|
123
124
|
});
|
|
124
125
|
|
|
126
|
+
// A browser's localStorage for one origin; `refuse` makes it throw as blocked or full storage does.
|
|
127
|
+
function browserStorage({ refuse = false } = {}) {
|
|
128
|
+
const items = new Map();
|
|
129
|
+
const check = () => {
|
|
130
|
+
if (refuse) throw new Error("SecurityError: storage is disabled");
|
|
131
|
+
};
|
|
132
|
+
return {
|
|
133
|
+
items,
|
|
134
|
+
getItem(key) { check(); return items.has(key) ? items.get(key) : null; },
|
|
135
|
+
setItem(key, value) { check(); items.set(key, String(value)); },
|
|
136
|
+
removeItem(key) { check(); items.delete(key); }
|
|
137
|
+
};
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
let pageStarts = 0;
|
|
141
|
+
/** One app start in a browser that has `storage`: colorSchemes.js loads afresh, as on every page load. */
|
|
142
|
+
async function browserStart(t, storage) {
|
|
143
|
+
globalThis.window = { localStorage: storage };
|
|
144
|
+
t.after(() => delete globalThis.window);
|
|
145
|
+
pageStarts += 1;
|
|
146
|
+
return import(`../src/client/colorSchemes.js?start=${pageStarts}`);
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
const VIBE64_INPUT = ["#1867C0", { learning: { value: "#F5C518", blend: false }, subsystem: { value: "#367E70", blend: false } }];
|
|
150
|
+
|
|
151
|
+
test("a later start reuses the colours an earlier start computed for the same theme, without computing them", async (t) => {
|
|
152
|
+
const storage = browserStorage();
|
|
153
|
+
const first = (await browserStart(t, storage)).materialThemes(...VIBE64_INPUT);
|
|
154
|
+
assert.deepEqual(first, materialThemes(...VIBE64_INPUT));
|
|
155
|
+
assert.equal(storage.items.size, 1, "the first start keeps its colours for the next");
|
|
156
|
+
const [[item, stored]] = storage.items;
|
|
157
|
+
// Changed where the first start stored it, a colour the next start shows is the stored one: it was not computed.
|
|
158
|
+
storage.setItem(item, stored.replaceAll(`"${first.light.colors.primary}"`, '"#010203"'));
|
|
159
|
+
const later = await browserStart(t, storage);
|
|
160
|
+
const reused = later.materialThemes(...VIBE64_INPUT);
|
|
161
|
+
assert.equal(reused.light.colors.primary, "#010203");
|
|
162
|
+
assert.deepEqual(reused.dark.colors.learning, first.dark.colors.learning);
|
|
163
|
+
assert.equal(reused.light.variables["border-color"], first.light.variables["border-color"]);
|
|
164
|
+
// Each call has its own objects, so an app that changes a theme changes only its own.
|
|
165
|
+
reused.light.colors.primary = "#ffffff";
|
|
166
|
+
reused.light.variables["hover-opacity"] = 1;
|
|
167
|
+
const again = later.materialThemes(...VIBE64_INPUT);
|
|
168
|
+
assert.equal(again.light.colors.primary, "#010203");
|
|
169
|
+
assert.equal(again.light.variables["hover-opacity"], 0.08);
|
|
170
|
+
});
|
|
171
|
+
|
|
172
|
+
test("a changed seed or colour computes the theme again and keeps the last four inputs", async (t) => {
|
|
173
|
+
const storage = browserStorage();
|
|
174
|
+
(await browserStart(t, storage)).materialThemes(...VIBE64_INPUT);
|
|
175
|
+
const [[item, stored]] = storage.items;
|
|
176
|
+
// The light scheme's primary, the first one stored.
|
|
177
|
+
storage.setItem(item, stored.replace(/"primary":"#[0-9a-f]{6}"/u, '"primary":"#010203"'));
|
|
178
|
+
const start = await browserStart(t, storage);
|
|
179
|
+
// The seed's case is not another input: the stored colours are reused for it.
|
|
180
|
+
assert.equal(start.materialThemes("#1867c0", VIBE64_INPUT[1]).light.colors.primary, "#010203");
|
|
181
|
+
const inputs = [
|
|
182
|
+
["#B3261E", VIBE64_INPUT[1]],
|
|
183
|
+
["#1867C0", { ...VIBE64_INPUT[1], learning: { value: "#F5C518", blend: true } }],
|
|
184
|
+
["#1867c0", { subsystem: VIBE64_INPUT[1].subsystem, learning: VIBE64_INPUT[1].learning }],
|
|
185
|
+
["#6750A4"]
|
|
186
|
+
];
|
|
187
|
+
for (const input of inputs) {
|
|
188
|
+
assert.deepEqual(start.materialThemes(...input), materialThemes(...input), JSON.stringify(input));
|
|
189
|
+
}
|
|
190
|
+
const kept = JSON.parse(storage.getItem(item));
|
|
191
|
+
assert.equal(kept.inputs.length, 4);
|
|
192
|
+
const next = await browserStart(t, storage);
|
|
193
|
+
for (const input of inputs) {
|
|
194
|
+
assert.deepEqual(next.materialThemes(...input), materialThemes(...input), JSON.stringify(input));
|
|
195
|
+
}
|
|
196
|
+
// The oldest input fell out of storage, so the next start computes it again.
|
|
197
|
+
assert.deepEqual(next.materialThemes(...VIBE64_INPUT), materialThemes(...VIBE64_INPUT));
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
test("colours stored under another revision, or that are not a scheme's, are computed again", async (t) => {
|
|
201
|
+
const computed = materialThemes(...VIBE64_INPUT);
|
|
202
|
+
const tampered = (change) => {
|
|
203
|
+
const storage = browserStorage();
|
|
204
|
+
return browserStart(t, storage).then(({ materialThemes: themes }) => {
|
|
205
|
+
themes(...VIBE64_INPUT);
|
|
206
|
+
const [[item, stored]] = storage.items;
|
|
207
|
+
storage.setItem(item, JSON.stringify(change(JSON.parse(stored))));
|
|
208
|
+
return storage;
|
|
209
|
+
});
|
|
210
|
+
};
|
|
211
|
+
const cases = {
|
|
212
|
+
"an older revision": (stored) => ({ ...stored, revision: stored.revision - 1, inputs: stored.inputs.map((entry) => ({ ...entry, light: { ...entry.light, primary: "#010203" } })) }),
|
|
213
|
+
"a value that is not a hex colour": (stored) => ({ ...stored, inputs: stored.inputs.map((entry) => ({ ...entry, light: { ...entry.light, primary: "red; } body { display: none" } })) }),
|
|
214
|
+
"a role name that is not one": (stored) => ({ ...stored, inputs: stored.inputs.map((entry) => ({ ...entry, light: { ...entry.light, "x} body {": "#010203" } })) }),
|
|
215
|
+
"a missing role": (stored) => ({
|
|
216
|
+
...stored,
|
|
217
|
+
inputs: stored.inputs.map((entry) => ({ ...entry, light: Object.fromEntries(Object.entries(entry.light).filter(([role]) => role !== "primary")) }))
|
|
218
|
+
}),
|
|
219
|
+
"a missing role of an app colour": (stored) => ({
|
|
220
|
+
...stored,
|
|
221
|
+
inputs: stored.inputs.map((entry) => ({ ...entry, dark: Object.fromEntries(Object.entries(entry.dark).filter(([role]) => role !== "on-learning-container")) }))
|
|
222
|
+
}),
|
|
223
|
+
"not this module's": () => ["#010203"]
|
|
224
|
+
};
|
|
225
|
+
for (const [name, change] of Object.entries(cases)) {
|
|
226
|
+
const storage = await tampered(change);
|
|
227
|
+
assert.deepEqual((await browserStart(t, storage)).materialThemes(...VIBE64_INPUT), computed, name);
|
|
228
|
+
// The computed colours replace the unusable ones: the input is stored once.
|
|
229
|
+
assert.equal(JSON.parse(storage.getItem("jskit:material-themes")).inputs.length, 1, name);
|
|
230
|
+
}
|
|
231
|
+
const garbage = browserStorage();
|
|
232
|
+
garbage.setItem("jskit:material-themes", "{not json");
|
|
233
|
+
assert.deepEqual((await browserStart(t, garbage)).materialThemes(...VIBE64_INPUT), computed);
|
|
234
|
+
assert.equal(JSON.parse(garbage.getItem("jskit:material-themes")).inputs.length, 1);
|
|
235
|
+
});
|
|
236
|
+
|
|
237
|
+
// The colours of each stored revision: one digest of three inputs' light and dark themes.
|
|
238
|
+
const REVISION_COLOURS = Object.freeze({ 1: "8e0c647d52f4394c311b8d49bfaa699997ad23a17579d8da75944818b873db63" });
|
|
239
|
+
|
|
240
|
+
test("the colours a theme input gives change only with the revision browsers store them under", async (t) => {
|
|
241
|
+
const storage = browserStorage();
|
|
242
|
+
const { materialThemes: themes } = await browserStart(t, storage);
|
|
243
|
+
const colours = [themes("#6750A4"), themes(...VIBE64_INPUT), themes("#B3261E", { partner: "#0A7D3E", brandAccent: "#FF6D00" })];
|
|
244
|
+
const { revision } = JSON.parse(storage.getItem("jskit:material-themes"));
|
|
245
|
+
// A browser keeps showing the colours it stored until the revision changes.
|
|
246
|
+
assert.equal(createHash("sha256").update(JSON.stringify(colours)).digest("hex"), REVISION_COLOURS[revision],
|
|
247
|
+
`The colours differ from revision ${revision}'s: bump THEMES_REVISION in colorSchemes.js and record its digest here.`);
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
test("a browser that refuses storage still gets its theme", async (t) => {
|
|
251
|
+
const { materialThemes: themes } = await browserStart(t, browserStorage({ refuse: true }));
|
|
252
|
+
assert.deepEqual(themes(...VIBE64_INPUT), materialThemes(...VIBE64_INPUT));
|
|
253
|
+
globalThis.window = {
|
|
254
|
+
get localStorage() { throw new Error("SecurityError: the document is sandboxed"); }
|
|
255
|
+
};
|
|
256
|
+
pageStarts += 1;
|
|
257
|
+
const sandboxed = await import(`../src/client/colorSchemes.js?start=${pageStarts}`);
|
|
258
|
+
assert.deepEqual(sandboxed.materialThemes(...VIBE64_INPUT), materialThemes(...VIBE64_INPUT));
|
|
259
|
+
});
|
|
260
|
+
|
|
125
261
|
test("a seed that is not a six-digit hex colour is refused", () => {
|
|
126
262
|
assert.throws(() => materialThemes("purple"), /six-digit hex/u);
|
|
127
263
|
assert.throws(() => createMaterialVuetifyOptions({ seed: "#123" }), /six-digit hex/u);
|
|
@@ -320,9 +456,20 @@ test("material.css draws segmented buttons, filter chips, fixed tabs and dialog
|
|
|
320
456
|
css,
|
|
321
457
|
/\.v-field:not\(\.v-field--focused, \.v-field--error\) \.v-label\.v-field-label \{\s*color: rgb\(var\(--v-theme-on-surface-variant\)\);\s*opacity: 1;/u
|
|
322
458
|
);
|
|
459
|
+
// Its character counter is with its supporting text; an invalid field's counter is error, as its messages are
|
|
460
|
+
// (accessibility.browser.test.js measures them).
|
|
323
461
|
assert.match(
|
|
324
462
|
css,
|
|
325
|
-
/\.v-input:not\(\.v-input--error, \.v-input--disabled\) > \.v-input__details \.v-messages \{\s*color: rgb\(var\(--v-theme-on-surface-variant\)\);\s*opacity: 1;/u
|
|
463
|
+
/\.v-input:not\(\.v-input--error, \.v-input--disabled\) > \.v-input__details :is\(\.v-messages, \.v-counter\) \{\s*color: rgb\(var\(--v-theme-on-surface-variant\)\);\s*opacity: 1;/u
|
|
464
|
+
);
|
|
465
|
+
assert.match(
|
|
466
|
+
css,
|
|
467
|
+
/\.v-input--error:not\(\.v-input--disabled\) > \.v-input__details \.v-counter \{\s*color: rgb\(var\(--v-theme-error\)\);\s*opacity: 1;/u
|
|
468
|
+
);
|
|
469
|
+
// So are a radio group's own label and a selection control's description.
|
|
470
|
+
assert.match(
|
|
471
|
+
css,
|
|
472
|
+
/\.v-radio-group:not\(\.v-input--disabled\) > \.v-input__control > \.v-label,\s*\.v-selection-control:not\(\.v-selection-control--disabled\) \.v-selection-control__description \{\s*color: rgb\(var\(--v-theme-on-surface-variant\)\);\s*opacity: 1;/u
|
|
326
473
|
);
|
|
327
474
|
// So is an inactive, uncoloured list item's subtitle; every enabled item's subtitle, an active one's included, is
|
|
328
475
|
// at full strength in the item's own colour.
|
|
@@ -331,6 +478,15 @@ test("material.css draws segmented buttons, filter chips, fixed tabs and dialog
|
|
|
331
478
|
/\.v-list-item:not\(\.v-list-item--active, \.v-list-item--disabled, \[class\*=" text-"\]\) \.v-list-item-subtitle \{\s*color: rgb\(var\(--v-theme-on-surface-variant\)\);\s*\}/u
|
|
332
479
|
);
|
|
333
480
|
assert.match(css, /\.v-list-item:not\(\.v-list-item--disabled\) \.v-list-item-subtitle \{\s*opacity: 1;\s*\}/u);
|
|
481
|
+
// And a card's subtitle: on-surface-variant on a surface card or one without a colour, unless the card has a text
|
|
482
|
+
// colour of its own.
|
|
483
|
+
assert.match(css, /\n {2}\.v-card-subtitle \{\s*opacity: 1;\s*\}/u);
|
|
484
|
+
assert.match(
|
|
485
|
+
css,
|
|
486
|
+
/\.v-card:not\(\[class\*="bg-"\], \[class\*=" text-"\]\) \.v-card-subtitle,\s*\.v-card\[class\*="bg-surface"\]:not\(\[class\*=" text-"\]\) \.v-card-subtitle \{\s*color: rgb\(var\(--v-theme-on-surface-variant\)\);\s*\}/u
|
|
487
|
+
);
|
|
488
|
+
// A tooltip is hidden whole while its text is.
|
|
489
|
+
assert.match(css, /\.v-tooltip:has\(> \.v-overlay__content\[style\*="display: none"\]\) \{\s*display: none;\s*\}/u);
|
|
334
490
|
// A disabled container button is on-surface 12% and 38%, unlayered over its colour class.
|
|
335
491
|
assert.match(
|
|
336
492
|
css,
|