@jskit-ai/material-web 0.1.9 → 0.1.11
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 +10 -0
- package/README.md +35 -5
- package/package.json +1 -1
- package/src/client/colorSchemes.js +166 -46
- package/src/client/defaults.js +23 -0
- package/src/client/material.css +75 -6
- package/test/accessibility.browser.test.js +31 -0
- package/test/chips.browser.test.js +71 -0
- package/test/fixtures/chips/index.html +2 -0
- package/test/fixtures/chips/main.js +27 -0
- package/test/fixtures/chips/vite.config.js +7 -0
- package/test/materialWeb.test.js +138 -2
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,16 @@
|
|
|
2
2
|
|
|
3
3
|
## Unreleased
|
|
4
4
|
|
|
5
|
+
- A chip's label longer than its chip ends in an ellipsis inside it, as a button's does: material.css lets a chip's text-only content shrink and clip (`.v-chip > .v-chip__content:not(:has(> *))`). Vuetify's inline-flex content could not shrink, so a long label was cut mid-word at the chip's edge, or drawn past it on a chip you press. A chip whose label holds elements of its own (an icon or avatar in its default slot) keeps Vuetify's layout; a short label is drawn as before.
|
|
6
|
+
- A tooltip opened by focus closes when its button loses focus to nothing, as `blur()` takes it. Vuetify 4.3.2 ignores such a blur (it keeps it for a click on an empty area inside an open menu), so the tooltip a keyboard user opened stayed over the page, and neither hovering nor leaving its button closed it (mobilynet's screen check met one). The `VTooltip` default's `activatorProps` listens for the `focusout` that follows and hands Vuetify's handler the blur it acts on, unless the pointer is on the tooltip itself, and the focus stays where `blur()` put it; a tooltip given its own `activator-props` replaces it. See the README's Upstream workarounds.
|
|
7
|
+
- axe judges the contrast of every text on a page again. Two things hid every text from it (color-contrast "incomplete", bgOverlap), so even text no one can read passed an accessibility check: a closed menu that stays mounted (`eager`, as shell-web's overflow menu does to keep the app bar's own items mounted on a phone) left Vuetify's overlay root over the whole window at z-index 2000, and Vuetify draws a button's, chip's, list item's, card's and avatar's state layer and underlay over its label. `material.css` now hides any overlay whose content is hidden (the rule it already had for tooltips, generalised), so a closing menu still animates out and its overlay goes once its content has; and draws state layers and tints under the content, as Material 3 orders them: each of those controls is its own stacking context with its layers at z-index -1, and its content parts are positioned (axe-core 4.14 reads the first, 4.11 the second; each alone still found layers over labels). Judged, three texts failed and are fixed or named:
|
|
8
|
+
- A tonal card of the default colour has `on-surface` text, tinted with `on-surface`: the `VCard` default `color` (`surface-container-low`) was its text colour, 1.04:1 on the page. Outlined, text and plain cards on the default colour get the same text colour.
|
|
9
|
+
- A filled or elevated button has no activated state layer (Material 3 gives it none): Vuetify's, the label's colour at 10% over the container, took a primary button's label to 4.11:1, under WCAG's 4.5:1, for as long as it stayed active. Hovered or focused, it shows that state's layer alone; a selected segmented button stays `secondary-container`.
|
|
10
|
+
- A disabled chip's label is Material 3's disabled colour (1.8:1), which WCAG 1.4.3 exempts as part of an inactive control, but Vuetify marks the chip disabled only with a `disabled` attribute on a span, which axe does not read: an app's contrast check names it as an exemption. So is an outlined field's text under its own outline (Vuetify's outline boxes are transparent but for their borders).
|
|
11
|
+
shell-web's `colorContrast.browser.test.js` runs axe on its fixture's pages at 390 and 1280: a deliberately unreadable line must be the one failure, and nothing else may stay unjudged.
|
|
12
|
+
|
|
13
|
+
- 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.
|
|
14
|
+
|
|
5
15
|
- 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.
|
|
6
16
|
- 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.
|
|
7
17
|
- 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`).
|
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`,
|
|
@@ -89,13 +97,19 @@ export const theme = {
|
|
|
89
97
|
character counters, radio group labels, checkbox, radio and switch
|
|
90
98
|
descriptions, and list item and card subtitles in on-surface-variant
|
|
91
99
|
at full strength (an invalid field's counter in error, as its messages),
|
|
92
|
-
one-line labels that
|
|
100
|
+
one-line button and chip labels that
|
|
93
101
|
end in an ellipsis, 12dp card corners, 28dp dialogs on
|
|
94
102
|
`surface-container-high` at level 3 and bottom sheets with a square card on
|
|
95
103
|
`surface-container-low`, square full-screen dialogs on `surface`, a 48dp touch target on clickable chips,
|
|
96
|
-
inverse-surface tooltips
|
|
97
|
-
|
|
98
|
-
|
|
104
|
+
inverse-surface tooltips, and every other overlay (menu, dialog, snackbar),
|
|
105
|
+
hidden whole while their content is (Vuetify keeps a mounted overlay around
|
|
106
|
+
its hidden content: a hidden tooltip was an empty tooltip to assistive
|
|
107
|
+
technology, and a closed eager menu lay over the whole page, so axe judged the
|
|
108
|
+
contrast of no text under it), state layers and tints under the label on
|
|
109
|
+
buttons, chips, list items, cards and avatars (axe judges the label's
|
|
110
|
+
contrast), no activated state layer on a filled or elevated button (it took a
|
|
111
|
+
primary button's label under 4.5:1), `on-surface` text on a tonal card of the
|
|
112
|
+
default colour, 40dp outlined segmented buttons and outlined
|
|
99
113
|
filter chips that lead with a check when selected (chips with
|
|
100
114
|
`aria-pressed` too), fixed tabs that share the width or else scroll, dialog
|
|
101
115
|
actions 24dp from the edges, a menu's own list as its container
|
|
@@ -147,6 +161,22 @@ Each one comes off when the upstream fix ships; its test says when.
|
|
|
147
161
|
would make an inline style). shell-web's browser test "a virtual-scroll list
|
|
148
162
|
in a dialog reaches its last item after the page around it re-renders"
|
|
149
163
|
guards it; it fails with `VDialog: { VCard: {} }` in the defaults.
|
|
164
|
+
- **Vuetify 4.3.2 (measured): a tooltip opened by focus stays open when its
|
|
165
|
+
activator loses focus to nothing.** Its activator ignores a blur with no
|
|
166
|
+
`relatedTarget` (as `blur()` gives), which it keeps for a click on an empty
|
|
167
|
+
area inside an open menu, so the tooltip a keyboard user opened stayed over
|
|
168
|
+
the page, and neither hovering nor leaving its button closed it. JSKIT's
|
|
169
|
+
`VTooltip` default `activatorProps` listens for the `focusout` that follows
|
|
170
|
+
(an event Vuetify's activator does not use) and hands Vuetify's handler the
|
|
171
|
+
blur it acts on, with the page as where focus went, unless the pointer is on
|
|
172
|
+
the tooltip itself. It first sets the tooltip's click-outside record
|
|
173
|
+
(`lastMousedownWasOutside`, as a click elsewhere does), so the closing
|
|
174
|
+
overlay leaves the focus where `blur()` put it instead of handing it back to
|
|
175
|
+
the activator. material-web's browser test "a tooltip opened by focus closes
|
|
176
|
+
when its button loses focus to nothing" guards both; it fails without the
|
|
177
|
+
default, and without the record the button is focused again. Drop the default once a Vuetify release passes that test
|
|
178
|
+
without it. A tooltip given its own `activator-props` replaces the default
|
|
179
|
+
and keeps Vuetify's behaviour.
|
|
150
180
|
- **Vuetify 4.3.2 and 4.3.3 (measured): idle loaders read layout as they
|
|
151
181
|
mount.** Every field built on `VField` (`v-text-field`, `v-select`,
|
|
152
182
|
`v-textarea` and the others) mounts an idle `VProgressLinear` in its loader
|
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.11",
|
|
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/defaults.js
CHANGED
|
@@ -7,6 +7,28 @@
|
|
|
7
7
|
// props cannot set, are in material.css. No VMenu sub-component defaults: under them, in Vuetify 4.2.1 to 4.3.2, an
|
|
8
8
|
// ancestor's re-render makes the menu's virtual list lose its item heights, so a v-select's typeahead never scrolls to
|
|
9
9
|
// its match (https://github.com/vuetifyjs/vuetify/issues/23366; README, Upstream workarounds).
|
|
10
|
+
// A tooltip opened by focus closes when its activator loses focus to nothing, as blur() takes it. Vuetify 4.3.2's
|
|
11
|
+
// activator ignores a blur with no relatedTarget, which it keeps for a click on an empty area inside an open menu, so
|
|
12
|
+
// the tooltip stayed over the page, and neither hovering nor leaving its activator closed it. On the focusout that
|
|
13
|
+
// follows (an event Vuetify's activator does not use, so this adds a listener rather than replacing or merging with
|
|
14
|
+
// Vuetify's own), Vuetify's handler gets the blur it acts on, with the page as where focus went, unless the pointer is
|
|
15
|
+
// on the tooltip itself (an interactive tooltip being clicked). The tooltip's overlay first records the focus as gone,
|
|
16
|
+
// as its click-outside record does after a click elsewhere, so closing leaves the focus where blur() put it: an overlay
|
|
17
|
+
// opened from its focused activator otherwise hands the focus back to the activator when it closes with the focus on
|
|
18
|
+
// the page.
|
|
19
|
+
function closeTooltipOnFocusLoss(event) {
|
|
20
|
+
if (event.relatedTarget || !event.isTrusted) return;
|
|
21
|
+
const activator = event.currentTarget;
|
|
22
|
+
const tooltips = String(activator.getAttribute("aria-describedby") || "").split(/\s+/u)
|
|
23
|
+
.filter(Boolean).map((id) => document.getElementById(id)).filter((element) => element?.classList.contains("v-tooltip"));
|
|
24
|
+
if (tooltips.some((tooltip) => tooltip.matches(":hover"))) return;
|
|
25
|
+
for (const tooltip of tooltips) {
|
|
26
|
+
const clickOutside = tooltip.querySelector(":scope > .v-overlay__content")?._clickOutside;
|
|
27
|
+
if (clickOutside) clickOutside.lastMousedownWasOutside = true;
|
|
28
|
+
}
|
|
29
|
+
activator.dispatchEvent(new FocusEvent("blur", { relatedTarget: document.body }));
|
|
30
|
+
}
|
|
31
|
+
|
|
10
32
|
const materialDefaults = Object.freeze({
|
|
11
33
|
VAppBar: {
|
|
12
34
|
color: "surface",
|
|
@@ -135,6 +157,7 @@ const materialDefaults = Object.freeze({
|
|
|
135
157
|
color: "surface"
|
|
136
158
|
},
|
|
137
159
|
VTooltip: {
|
|
160
|
+
activatorProps: { onFocusout: closeTooltipOnFocusLoss },
|
|
138
161
|
location: "bottom"
|
|
139
162
|
}
|
|
140
163
|
});
|
package/src/client/material.css
CHANGED
|
@@ -166,6 +166,47 @@
|
|
|
166
166
|
border-radius: inherit;
|
|
167
167
|
}
|
|
168
168
|
|
|
169
|
+
/* A control's state layer and container tint lie under its content, as Material 3 orders them. Vuetify draws a
|
|
170
|
+
button's, chip's, list item's, card's and avatar's overlay and underlay over the label, so axe found a layer over
|
|
171
|
+
every label and judged the contrast of none (color-contrast incomplete, bgOverlap). Each control is its own
|
|
172
|
+
stacking context with its layers at z-index -1 in it, and its content parts are positioned: axe-core 4.14 reads
|
|
173
|
+
the first, 4.11 the second, and each still found layers over labels with only one of the two. */
|
|
174
|
+
:is(.v-btn, .v-chip, .v-list-item, .v-card, .v-avatar) {
|
|
175
|
+
isolation: isolate;
|
|
176
|
+
}
|
|
177
|
+
|
|
178
|
+
.v-btn > :is(.v-btn__overlay, .v-btn__underlay),
|
|
179
|
+
.v-chip > :is(.v-chip__overlay, .v-chip__underlay),
|
|
180
|
+
.v-list-item > :is(.v-list-item__overlay, .v-list-item__underlay),
|
|
181
|
+
.v-card > :is(.v-card__overlay, .v-card__underlay),
|
|
182
|
+
.v-avatar > .v-avatar__underlay {
|
|
183
|
+
z-index: -1;
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
.v-btn > :is(.v-btn__prepend, .v-btn__content, .v-btn__append),
|
|
187
|
+
.v-chip > :is(.v-chip__filter, .v-chip__prepend, .v-chip__content, .v-chip__append, .v-chip__close),
|
|
188
|
+
.v-list-item > :is(.v-list-item__prepend, .v-list-item__content, .v-list-item__append),
|
|
189
|
+
.v-card > :is(.v-card-item, .v-card-title, .v-card-subtitle, .v-card-text, .v-card-actions),
|
|
190
|
+
.v-avatar > :not(.v-avatar__underlay) {
|
|
191
|
+
position: relative;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/* A filled or elevated button has no activated state layer: Material 3 gives these buttons none (a selected
|
|
195
|
+
segment is secondary-container), and Vuetify's, the label's colour at 10% over the container, took a primary
|
|
196
|
+
button's white label under WCAG's 4.5:1 (4.11:1 in JSKIT's fixture theme) for as long as the button stayed
|
|
197
|
+
active, as one whose route is current does. Hovered or focused, it shows that state's layer alone. */
|
|
198
|
+
.v-btn--active:is(.v-btn--variant-flat, .v-btn--variant-elevated) > .v-btn__overlay {
|
|
199
|
+
opacity: 0;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
.v-btn--active:is(.v-btn--variant-flat, .v-btn--variant-elevated):hover > .v-btn__overlay {
|
|
203
|
+
opacity: calc(var(--v-hover-opacity) * var(--v-theme-overlay-multiplier));
|
|
204
|
+
}
|
|
205
|
+
|
|
206
|
+
.v-btn--active:is(.v-btn--variant-flat, .v-btn--variant-elevated):focus-visible > .v-btn__overlay {
|
|
207
|
+
opacity: calc(var(--v-focus-opacity) * var(--v-theme-overlay-multiplier));
|
|
208
|
+
}
|
|
209
|
+
|
|
169
210
|
/* A label stays on one line, as Material 3 draws it; one longer than its button ends in an ellipsis. */
|
|
170
211
|
.v-btn:not(.v-btn--stacked, .v-btn--icon) > .v-btn__content:not(:has(> *)) {
|
|
171
212
|
display: block;
|
|
@@ -174,6 +215,17 @@
|
|
|
174
215
|
text-overflow: ellipsis;
|
|
175
216
|
}
|
|
176
217
|
|
|
218
|
+
/* So does a chip's: a chip is at most as wide as its container and its label stays on one line, but Vuetify's
|
|
219
|
+
inline-flex content cannot shrink, so a longer label was cut mid-word at the chip's edge (or drawn past it on a
|
|
220
|
+
chip you press, which the touch target unclips). A label holding elements of its own (an icon or avatar in the
|
|
221
|
+
chip's default slot) keeps Vuetify's inline-flex content, which lays them out. */
|
|
222
|
+
.v-chip > .v-chip__content:not(:has(> *)) {
|
|
223
|
+
display: block;
|
|
224
|
+
min-width: 0;
|
|
225
|
+
overflow: hidden;
|
|
226
|
+
text-overflow: ellipsis;
|
|
227
|
+
}
|
|
228
|
+
|
|
177
229
|
/* Outlined buttons and outlined chips draw the outline role. */
|
|
178
230
|
.v-btn--variant-outlined:not([class*=" text-"]) {
|
|
179
231
|
border-color: rgb(var(--v-theme-outline));
|
|
@@ -282,12 +334,16 @@
|
|
|
282
334
|
padding: 4px 8px;
|
|
283
335
|
}
|
|
284
336
|
|
|
285
|
-
/* A hidden tooltip is hidden whole. Vuetify
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
337
|
+
/* A hidden overlay (tooltip, menu, dialog, snackbar) is hidden whole. Vuetify hides only an overlay's content when
|
|
338
|
+
it closes, and keeps the overlay around it whenever the content stays mounted: a tooltip, which Vuetify 4.3 mounts
|
|
339
|
+
before it first shows, or an eager menu, such as ShellLayout's overflow menu holding the app bar's own items on a
|
|
340
|
+
phone. A hidden tooltip's role="tooltip" overlay was an empty tooltip to assistive technology (axe
|
|
341
|
+
aria-tooltip-name), and its activator's aria-describedby read nothing, since hidden text counts only when the
|
|
342
|
+
element the activator names is hidden itself. A closed menu's overlay lay over the whole window at z-index 2000,
|
|
343
|
+
so axe found it over every text on the page and judged the contrast of none (color-contrast incomplete,
|
|
344
|
+
bgOverlap), letting text no one can read pass. The overlay hides only once its content has, so an opening or
|
|
345
|
+
closing one still animates. */
|
|
346
|
+
.v-overlay:has(> .v-overlay__content[style*="display: none"]) {
|
|
291
347
|
display: none;
|
|
292
348
|
}
|
|
293
349
|
|
|
@@ -680,6 +736,19 @@
|
|
|
680
736
|
color: rgb(var(--v-theme-on-surface-container-high));
|
|
681
737
|
}
|
|
682
738
|
|
|
739
|
+
/* A tonal card (or an outlined, text or plain one) draws its text and its tint in its colour, which for the default
|
|
740
|
+
surface-container-low colour was near-white on the near-white page: a tonal card's text read 1.04:1. Such a card
|
|
741
|
+
has on-surface text, tinted with on-surface, and on-surface-variant supporting text. A card given its own colour
|
|
742
|
+
keeps it. */
|
|
743
|
+
.v-card.text-surface-container-low {
|
|
744
|
+
color: rgb(var(--v-theme-on-surface));
|
|
745
|
+
}
|
|
746
|
+
|
|
747
|
+
.v-card.text-surface-container-low > .v-card-subtitle:not([class*=" text-"]),
|
|
748
|
+
.v-card.text-surface-container-low > .v-card-item > .v-card-item__content > .v-card-subtitle:not([class*=" text-"]) {
|
|
749
|
+
color: rgb(var(--v-theme-on-surface-variant));
|
|
750
|
+
}
|
|
751
|
+
|
|
683
752
|
.text-on-background {
|
|
684
753
|
color: rgb(var(--v-theme-on-background));
|
|
685
754
|
}
|
|
@@ -101,6 +101,37 @@ test("a hidden tooltip leaves no tooltip without a name and still describes its
|
|
|
101
101
|
await expect(button).toHaveAccessibleDescription("Delete this report");
|
|
102
102
|
});
|
|
103
103
|
|
|
104
|
+
// A tooltip opened by focus closes when its button loses focus, wherever focus goes, and leaves the focus there.
|
|
105
|
+
// Vuetify 4.3.2 kept it open when blur() took the focus nowhere, as it keeps a menu open for a click on an empty area
|
|
106
|
+
// inside it, so the tooltip stayed over the page, and neither hovering nor leaving the button closed it. A click on an
|
|
107
|
+
// empty part of the page closes it as a click outside.
|
|
108
|
+
test("a tooltip opened by focus closes when its button loses focus to nothing", {
|
|
109
|
+
skip: SKIP,
|
|
110
|
+
timeout: 120_000
|
|
111
|
+
}, async (t) => {
|
|
112
|
+
const { vite, browser } = await open(t);
|
|
113
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, reducedMotion: "reduce" });
|
|
114
|
+
t.after(() => page.close());
|
|
115
|
+
const button = page.getByTestId("tooltip-activator");
|
|
116
|
+
const tooltip = page.getByRole("tooltip", { name: "Delete this report" });
|
|
117
|
+
// Each way of losing focus on a fresh page: Vuetify ignores focus for 50ms after a tooltip closes.
|
|
118
|
+
const losses = [
|
|
119
|
+
["a click on an empty part of the page", () => page.mouse.click(4, 4)],
|
|
120
|
+
["the button's blur()", () => button.evaluate((element) => element.blur())]
|
|
121
|
+
];
|
|
122
|
+
for (const [loss, loseFocus] of losses) {
|
|
123
|
+
await page.goto("/");
|
|
124
|
+
await expect(button).toBeVisible();
|
|
125
|
+
await page.keyboard.press("Tab");
|
|
126
|
+
await expect(button).toBeFocused();
|
|
127
|
+
await expect(tooltip).toBeVisible();
|
|
128
|
+
await loseFocus();
|
|
129
|
+
await expect(tooltip, `closed after ${loss}`).toBeHidden();
|
|
130
|
+
// Closing leaves the focus where it went, rather than handing it back to the button.
|
|
131
|
+
await expect(button, `not focused again once closed after ${loss}`).not.toBeFocused();
|
|
132
|
+
}
|
|
133
|
+
});
|
|
134
|
+
|
|
104
135
|
// A card's subtitle is its supporting text, at full strength: on-surface-variant on a surface card or one without a
|
|
105
136
|
// 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
137
|
// medium-emphasis opacity it measured 4.35:1 on JSKIT's default surface-container-low card, under WCAG's 4.5:1.
|
|
@@ -0,0 +1,71 @@
|
|
|
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 { sharedBrowserFixture } from "../../../tooling/testUtils/browserFixture.mjs";
|
|
6
|
+
|
|
7
|
+
const SKIP = process.env.JSKIT_MATERIAL_WEB_BROWSER === "1" ? false : "set JSKIT_MATERIAL_WEB_BROWSER=1";
|
|
8
|
+
const open = sharedBrowserFixture({
|
|
9
|
+
fixtureRoot: fileURLToPath(new URL("./fixtures/chips", import.meta.url)),
|
|
10
|
+
configFile: "vite.config.js"
|
|
11
|
+
});
|
|
12
|
+
|
|
13
|
+
// Where a chip, its content and its label's text are drawn (left, top, right, bottom, to a tenth of a pixel), and how
|
|
14
|
+
// its content lays out and clips.
|
|
15
|
+
function chipGeometry(locator) {
|
|
16
|
+
return locator.evaluate((chip) => {
|
|
17
|
+
const content = chip.querySelector(":scope > .v-chip__content");
|
|
18
|
+
const text = document.createRange();
|
|
19
|
+
text.selectNodeContents(content);
|
|
20
|
+
const box = (rect) => [rect.left, rect.top, rect.right, rect.bottom].map((value) => Math.round(value * 10) / 10);
|
|
21
|
+
const style = getComputedStyle(content);
|
|
22
|
+
return {
|
|
23
|
+
chip: box(chip.getBoundingClientRect()),
|
|
24
|
+
content: box(content.getBoundingClientRect()),
|
|
25
|
+
text: box(text.getBoundingClientRect()),
|
|
26
|
+
display: style.display,
|
|
27
|
+
overflow: style.overflowX,
|
|
28
|
+
textOverflow: style.textOverflow,
|
|
29
|
+
clipped: content.scrollWidth > content.clientWidth
|
|
30
|
+
};
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
// Vuetify's own chip content (inline-flex, unclipped), unlayered so it wins over material.css's layers.
|
|
35
|
+
const VUETIFY_CHIP_CONTENT = ".v-chip > .v-chip__content { display: inline-flex; min-width: auto; overflow: visible; text-overflow: clip; }";
|
|
36
|
+
|
|
37
|
+
// A chip is at most as wide as its container, and its label stays on one line, so a label longer than the chip was cut
|
|
38
|
+
// mid-word at the chip's edge, or drawn past it on a chip you press. It ends in an ellipsis inside the chip, as a
|
|
39
|
+
// button's does; a chip whose label holds elements of its own keeps Vuetify's layout, and a short label is unchanged.
|
|
40
|
+
test("a chip's label longer than its chip ends in an ellipsis inside it; a short label and one holding an element are drawn as before", {
|
|
41
|
+
skip: SKIP,
|
|
42
|
+
timeout: 120_000
|
|
43
|
+
}, async (t) => {
|
|
44
|
+
const { vite, browser } = await open(t);
|
|
45
|
+
const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 }, reducedMotion: "reduce" });
|
|
46
|
+
t.after(() => page.close());
|
|
47
|
+
await page.goto("/");
|
|
48
|
+
await page.getByTestId("slot-chip").waitFor();
|
|
49
|
+
const column = await page.getByTestId("column").evaluate((element) => element.getBoundingClientRect().right);
|
|
50
|
+
|
|
51
|
+
for (const testId of ["long-chip", "long-pressable-chip"]) {
|
|
52
|
+
const drawn = await chipGeometry(page.getByTestId(testId));
|
|
53
|
+
assert.ok(drawn.chip[2] <= column, `${testId} ends at ${drawn.chip[2]}, inside its ${column}px column`);
|
|
54
|
+
assert.ok(drawn.content[2] <= drawn.chip[2], `${testId}'s label ends at ${drawn.content[2]}, inside the chip (${drawn.chip[2]})`);
|
|
55
|
+
assert.deepEqual([drawn.overflow, drawn.textOverflow, drawn.clipped], ["hidden", "ellipsis", true],
|
|
56
|
+
`${testId}'s label is clipped with an ellipsis`);
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
const unchanged = ["short-chip", "icon-chip", "slot-chip"];
|
|
60
|
+
const ours = [];
|
|
61
|
+
for (const testId of unchanged) ours.push(await chipGeometry(page.getByTestId(testId)));
|
|
62
|
+
// Vuetify's inline-flex content, as the chip's flex item, computes to flex; material.css's text-only content is block.
|
|
63
|
+
assert.deepEqual(ours.map(({ display }) => display), ["block", "block", "flex"],
|
|
64
|
+
"a text-only label is clipped as a block; one holding an element keeps Vuetify's inline-flex content");
|
|
65
|
+
await page.addStyleTag({ content: VUETIFY_CHIP_CONTENT });
|
|
66
|
+
for (const [index, testId] of unchanged.entries()) {
|
|
67
|
+
const theirs = await chipGeometry(page.getByTestId(testId));
|
|
68
|
+
const where = ({ chip, content, text }) => ({ chip, content, text });
|
|
69
|
+
assert.deepEqual(where(ours[index]), where(theirs), `${testId} is drawn as with Vuetify's own chip content`);
|
|
70
|
+
}
|
|
71
|
+
});
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
import { createApp, h } from "vue";
|
|
2
|
+
import { createVuetify } from "vuetify";
|
|
3
|
+
import { VApp } from "vuetify/components/VApp";
|
|
4
|
+
import { VChip } from "vuetify/components/VChip";
|
|
5
|
+
import { VIcon } from "vuetify/components/VIcon";
|
|
6
|
+
import { VMain } from "vuetify/components/VMain";
|
|
7
|
+
import "vuetify/styles";
|
|
8
|
+
import "../../../src/client/material.css";
|
|
9
|
+
import { createMaterialVuetifyOptions } from "../../../src/client/index.js";
|
|
10
|
+
|
|
11
|
+
// Chips in a column narrower than a long label, with JSKIT's Material 3 options and stylesheet, as an app draws them
|
|
12
|
+
// (chips.browser.test.js): a long label on a chip and on a chip you press (whose touch target unclips it), a short one,
|
|
13
|
+
// a short one with a leading icon, and one whose label holds an element of its own (an icon in its default slot).
|
|
14
|
+
const LONG = "Quarterly invoices for the North Atlantic shipping project, second half";
|
|
15
|
+
const chips = [
|
|
16
|
+
{ testId: "long-chip", props: { text: LONG } },
|
|
17
|
+
{ testId: "long-pressable-chip", props: { text: LONG, link: true } },
|
|
18
|
+
{ testId: "short-chip", props: { text: "Draft" } },
|
|
19
|
+
{ testId: "icon-chip", props: { text: "Shared", prependIcon: "$info" } },
|
|
20
|
+
{ testId: "slot-chip", props: {}, label: () => [h(VIcon, { icon: "$info", start: true }), "Shared"] }
|
|
21
|
+
];
|
|
22
|
+
|
|
23
|
+
const App = () => h(VApp, () => h(VMain, { class: "pa-6" }, () => h("div", { style: "width: 240px", "data-testid": "column" }, (
|
|
24
|
+
chips.map(({ testId, props, label }) => h("div", { class: "mb-2" }, h(VChip, { ...props, "data-testid": testId }, label)))
|
|
25
|
+
))));
|
|
26
|
+
|
|
27
|
+
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);
|
|
@@ -349,8 +485,8 @@ test("material.css draws segmented buttons, filter chips, fixed tabs and dialog
|
|
|
349
485
|
css,
|
|
350
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
|
|
351
487
|
);
|
|
352
|
-
//
|
|
353
|
-
assert.match(css, /\.v-
|
|
488
|
+
// An overlay (a tooltip, a closed eager menu) is hidden whole while its content is.
|
|
489
|
+
assert.match(css, /\.v-overlay:has\(> \.v-overlay__content\[style\*="display: none"\]\) \{\s*display: none;\s*\}/u);
|
|
354
490
|
// A disabled container button is on-surface 12% and 38%, unlayered over its colour class.
|
|
355
491
|
assert.match(
|
|
356
492
|
css,
|