@jskit-ai/shell-web 0.2.52 → 0.2.54

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,22 @@
1
+ <script setup>
2
+ // A button in each colour that has a container role and each variant, for its label's contrast at rest, hovered,
3
+ // focused and pressed: a state layer is drawn under the label, so it is part of what the label is read against.
4
+ const COLORS = Object.freeze(["primary", "secondary", "tertiary", "error", "success", "warning", "info"]);
5
+ const VARIANTS = Object.freeze(["flat", "elevated", "tonal", "outlined", "text"]);
6
+ </script>
7
+
8
+ <template>
9
+ <section class="d-flex flex-column ga-2 pa-4">
10
+ <div v-for="color in COLORS" :key="color" class="d-flex flex-wrap ga-2">
11
+ <v-btn
12
+ v-for="variant in VARIANTS"
13
+ :key="variant"
14
+ :color="color"
15
+ :variant="variant"
16
+ :data-testid="`contrast-${color}-${variant}`"
17
+ >
18
+ {{ variant }}
19
+ </v-btn>
20
+ </div>
21
+ </section>
22
+ </template>
@@ -11,6 +11,7 @@ import { shellScrollBehavior } from "@jskit-ai/kernel/client";
11
11
  import App from "./App.vue";
12
12
  import ActionsFormPage from "./ActionsFormPage.vue";
13
13
  import ActionsPage from "./ActionsPage.vue";
14
+ import ButtonContrastPage from "./ButtonContrastPage.vue";
14
15
  import ButtonStatesPage from "./ButtonStatesPage.vue";
15
16
  import ButtonsPage from "./ButtonsPage.vue";
16
17
  import ComponentsPage from "./ComponentsPage.vue";
@@ -350,6 +351,7 @@ const routes = [
350
351
  },
351
352
  { path: "/home/buttons", component: ButtonsPage, meta: { jskit: { title: "Buttons" } } },
352
353
  { path: "/home/button-states", component: ButtonStatesPage, meta: { jskit: { title: "Button states" } } },
354
+ { path: "/home/button-contrast", component: ButtonContrastPage, meta: { jskit: { title: "Button contrast" } } },
353
355
  { path: "/home/components", component: ComponentsPage, meta: { jskit: { title: "Components" } } },
354
356
  { path: "/home/actions", component: ActionsPage, meta: { jskit: { title: "Actions" } } },
355
357
  { path: "/home/actions/new", component: ActionsFormPage, meta: { jskit: { title: "New entry", parent: "/actions" } } },
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/shell-web",
3
- "version": "0.2.52",
3
+ "version": "0.2.54",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -51,7 +51,7 @@
51
51
  "@jskit-ai/architecture-inspector": "0.1.34"
52
52
  },
53
53
  "devDependencies": {
54
- "@jskit-ai/material-web": "0.1.11",
54
+ "@jskit-ai/material-web": "0.1.13",
55
55
  "@vue/compiler-sfc": "3.5.44"
56
56
  },
57
57
  "peerDependencies": {
@@ -124,25 +124,92 @@ test("a menu mounted while closed covers nothing, and still opens and closes wit
124
124
  await items.evaluate((element) => Promise.all(element.closest(".v-overlay__content").getAnimations().map((animation) => animation.finished)));
125
125
 
126
126
  // Frame by frame from Escape until the overlay is gone: its content animates out while the overlay is still drawn.
127
- const frames = items.evaluate(async (element) => {
127
+ // The page takes the first frame before Escape is pressed: a sampler started beside the key press ran only after a
128
+ // second round trip, which the press overtook, and on a busy host found the menu already closed.
129
+ await items.evaluate((element) => {
128
130
  const content = element.closest(".v-overlay__content");
129
131
  const overlay = content.parentElement;
130
- const seen = [];
131
- const started = performance.now();
132
- while (performance.now() - started < 3000) {
133
- const animating = content.getAnimations().some((animation) => animation.playState === "running");
134
- seen.push({ overlay: getComputedStyle(overlay).display, content: content.style.display || "shown", animating });
135
- if (seen.at(-1).overlay === "none") {
136
- break;
132
+ globalThis.closingMenuFrames = (async () => {
133
+ const seen = [];
134
+ const started = performance.now();
135
+ while (performance.now() - started < 3000) {
136
+ const animating = content.getAnimations().some((animation) => animation.playState === "running");
137
+ seen.push({ overlay: getComputedStyle(overlay).display, content: content.style.display || "shown", animating });
138
+ if (seen.at(-1).overlay === "none") {
139
+ break;
140
+ }
141
+ await new Promise((resolve) => requestAnimationFrame(resolve));
137
142
  }
138
- await new Promise((resolve) => requestAnimationFrame(resolve));
139
- }
140
- return seen;
143
+ return seen;
144
+ })();
141
145
  });
142
146
  await page.keyboard.press("Escape");
143
- const seen = await frames;
147
+ const seen = await page.evaluate(() => globalThis.closingMenuFrames);
144
148
  assert.ok(seen.some((frame) => frame.overlay !== "none" && frame.content === "shown" && frame.animating),
145
149
  `the menu animates out while its overlay is drawn: ${JSON.stringify(seen.filter((_, index) => index % 4 === 0))}`);
146
150
  assert.equal(seen.at(-1).overlay, "none", "once closed, the menu's overlay is gone again");
147
151
  await expect(items).toBeAttached();
148
152
  });
153
+
154
+ // A state layer lies under the label, so a hovered, focused or pressed button's label is read against its container
155
+ // with the layer over it. Material 3's layers (hover 8%, focus and pressed 10%) keep every label at 4.5:1: a filled
156
+ // button's on-colour over its colour, a tonal button's on-container colour over its tint.
157
+ test("every button's label keeps 4.5:1 at rest, hovered, focused and pressed, in each colour, variant and theme", {
158
+ skip: SKIP,
159
+ timeout: 180_000
160
+ }, async (t) => {
161
+ const { vite, browser } = await open(t);
162
+ const failures = [];
163
+ let judged = 0;
164
+ for (const theme of ["light", "dark"]) {
165
+ const page = await browser.newPage({
166
+ baseURL: vite.baseURL,
167
+ colorScheme: theme,
168
+ viewport: { width: 390, height: 844 },
169
+ reducedMotion: "reduce"
170
+ });
171
+ t.after(() => page.close());
172
+ await page.goto(`/home/button-contrast?theme=${theme}`);
173
+ await expect(page.getByTestId("jskit-shell-page-title")).toHaveText("Button contrast");
174
+ await page.addScriptTag({ path: AXE_PATH });
175
+ const buttons = await page.locator("[data-testid^=contrast-]").all();
176
+ assert.equal(buttons.length, 35, "seven colours in five variants");
177
+ for (const button of buttons) {
178
+ const name = await button.getAttribute("data-testid");
179
+ for (const state of ["rest", "hover", "focus", "pressed"]) {
180
+ if (state === "hover") {
181
+ await button.hover();
182
+ } else if (state === "focus") {
183
+ // A key press first, so the focus shows as keyboard focus.
184
+ await page.keyboard.press("Shift");
185
+ await button.focus();
186
+ } else if (state === "pressed") {
187
+ await button.hover();
188
+ await page.mouse.down();
189
+ }
190
+ const found = await button.evaluate(async (element) => {
191
+ const results = await globalThis.axe.run(element, { runOnly: { type: "rule", values: ["color-contrast"] } });
192
+ const nodes = (outcome) => outcome.flatMap((rule) => rule.nodes);
193
+ return [
194
+ ...nodes(results.violations).map((node) => `${node.any.map((check) => check.data?.contrastRatio).join("|")}:1 ` +
195
+ `(${node.any.map((check) => `${check.data?.fgColor} on ${check.data?.bgColor}`).join("|")})`),
196
+ ...nodes(results.incomplete).map((node) => `unjudged: ${node.any.map((check) => check.data?.messageKey).join("|")}`)
197
+ ];
198
+ });
199
+ judged += 1;
200
+ for (const finding of found) {
201
+ failures.push(`${theme} ${name} ${state}: ${finding}`);
202
+ }
203
+ if (state === "pressed") {
204
+ await page.mouse.up();
205
+ }
206
+ await button.blur();
207
+ await page.mouse.move(1, 300);
208
+ // A released press leaves its ripple fading out for a moment; the next state starts once it has gone.
209
+ await expect(page.locator(".v-ripple__container")).toHaveCount(0);
210
+ }
211
+ }
212
+ }
213
+ assert.equal(judged, 280, "every button judged in four states and two themes");
214
+ assert.deepEqual(failures, [], "every label at 4.5:1 or more in every state");
215
+ });