@jskit-ai/auth-web 0.2.20 → 0.2.22

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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jskit-ai/auth-web",
3
- "version": "0.2.20",
3
+ "version": "0.2.22",
4
4
  "type": "module",
5
5
  "scripts": {
6
6
  "test": "jskit test"
@@ -25,10 +25,10 @@
25
25
  "./locales/en.json": "./locales/en.json"
26
26
  },
27
27
  "peerDependencies": {
28
- "@jskit-ai/auth-core": "0.2.15",
29
- "@jskit-ai/http-runtime": "0.2.15",
30
- "@jskit-ai/kernel": "0.2.15",
31
- "@jskit-ai/shell-web": "0.2.18",
28
+ "@jskit-ai/auth-core": "0.2.16",
29
+ "@jskit-ai/http-runtime": "0.2.16",
30
+ "@jskit-ai/kernel": "0.2.16",
31
+ "@jskit-ai/shell-web": "0.2.20",
32
32
  "@tanstack/vue-query": "^5.90.5",
33
33
  "pinia": "^4.0.3",
34
34
  "vue": "^3.5.44",
@@ -305,6 +305,6 @@
305
305
  }
306
306
  },
307
307
  "devDependencies": {
308
- "@jskit-ai/material-web": "0.1.3"
308
+ "@jskit-ai/material-web": "0.1.4"
309
309
  }
310
310
  }
@@ -620,6 +620,116 @@ test("every auth screen has its one h1, sign-in's included", options, async () =
620
620
  await finish(api);
621
621
  });
622
622
 
623
+ // Every text the page draws that reads under WCAG's contrast minimum against the background behind it (4.5:1, or 3:1
624
+ // for text of 24px, or 18.66px bold), as "text ratio:1, foreground on background". Disabled controls are exempt.
625
+ function unreadableText(page) {
626
+ return page.evaluate(() => {
627
+ const canvas = document.createElement("canvas");
628
+ canvas.width = 1;
629
+ canvas.height = 1;
630
+ const context = canvas.getContext("2d", { willReadFrequently: true });
631
+ // Any computed colour (rgb(), color-mix(), oklch(), ...) as the sRGB pixel it paints.
632
+ const pixel = (color) => {
633
+ context.clearRect(0, 0, 1, 1);
634
+ context.fillStyle = color;
635
+ context.fillRect(0, 0, 1, 1);
636
+ const [r, g, b, a] = context.getImageData(0, 0, 1, 1).data;
637
+ return { r, g, b, a: a / 255 };
638
+ };
639
+ const over = (top, alpha, base) => ({
640
+ r: top.r * alpha + base.r * (1 - alpha),
641
+ g: top.g * alpha + base.g * (1 - alpha),
642
+ b: top.b * alpha + base.b * (1 - alpha),
643
+ a: 1
644
+ });
645
+ const luminance = ({ r, g, b }) => {
646
+ const [red, green, blue] = [r, g, b].map((channel) => {
647
+ const value = channel / 255;
648
+ return value <= 0.03928 ? value / 12.92 : ((value + 0.055) / 1.055) ** 2.4;
649
+ });
650
+ return 0.2126 * red + 0.7152 * green + 0.0722 * blue;
651
+ };
652
+ const hex = ({ r, g, b }) => `#${[r, g, b].map((channel) => Math.round(channel).toString(16).padStart(2, "0")).join("")}`;
653
+ const exempt = "[disabled], [aria-disabled='true'], .v-btn--disabled, .v-input--disabled, script, style, template";
654
+ const findings = new Map();
655
+ const walker = document.createTreeWalker(document.body, NodeFilter.SHOW_TEXT);
656
+ for (let node = walker.nextNode(); node; node = walker.nextNode()) {
657
+ const text = String(node.textContent || "").replace(/\s+/gu, " ").trim();
658
+ const element = node.parentElement;
659
+ if (!text || !element || element.closest(exempt) || findings.has(text)) continue;
660
+ if (!element.checkVisibility({ checkVisibilityCSS: true, visibilityProperty: true })) continue;
661
+ const range = document.createRange();
662
+ range.selectNodeContents(node);
663
+ const box = range.getBoundingClientRect();
664
+ if (box.width < 1 || box.height < 1) continue;
665
+ // The text's opacity is every ancestor's; its background, the backgrounds behind it down to the first opaque one.
666
+ let opacity = 1;
667
+ let opaque = false;
668
+ const layers = [];
669
+ for (let current = element; current; current = current.parentElement) {
670
+ const style = window.getComputedStyle(current);
671
+ opacity *= Number(style.opacity);
672
+ if (opaque) continue;
673
+ const background = pixel(style.backgroundColor);
674
+ if (background.a > 0) layers.push(background);
675
+ opaque = background.a >= 1;
676
+ }
677
+ if (opacity < 0.01) continue;
678
+ let background = { r: 255, g: 255, b: 255, a: 1 };
679
+ for (const layer of layers.reverse()) background = over(layer, layer.a, background);
680
+ const style = window.getComputedStyle(element);
681
+ const color = pixel(style.color);
682
+ const foreground = over(color, color.a * opacity, background);
683
+ const [lighter, darker] = [luminance(foreground), luminance(background)].sort((left, right) => right - left);
684
+ const ratio = (lighter + 0.05) / (darker + 0.05);
685
+ const size = Number.parseFloat(style.fontSize);
686
+ const large = size >= 24 || (size >= 18.66 && Number(style.fontWeight) >= 700);
687
+ if (ratio < (large ? 3 : 4.5)) {
688
+ findings.set(text, `"${text.slice(0, 60)}" ${ratio.toFixed(2)}:1, ${hex(foreground)} on ${hex(background)}`);
689
+ }
690
+ }
691
+ return [...findings.values()];
692
+ });
693
+ }
694
+
695
+ test("every auth screen's text, its field labels and hints included, reads at WCAG contrast in light and dark", options, async () => {
696
+ const api = await openApp({
697
+ routes: { "POST /api/register": { json: { requiresEmailConfirmation: true, username: "Ada" } } }
698
+ });
699
+ const { page } = api;
700
+ const failures = [];
701
+ const readable = async (where) => {
702
+ // The modes fade and move their labels in; a text that stays under the minimum is a finding.
703
+ await expect.poll(() => unreadableText(page), { timeout: 5_000 }).toEqual([]).catch(() => undefined);
704
+ failures.push(...(await unreadableText(page)).map((finding) => `${where}: ${finding}`));
705
+ };
706
+ for (const colorScheme of ["light", "dark"]) {
707
+ await page.emulateMedia({ colorScheme });
708
+ await page.goto("/auth/login");
709
+ await expect(page.getByRole("heading", { level: 1, name: "Sign in" })).toBeVisible();
710
+ await readable(`${colorScheme} sign in`);
711
+ await page.getByLabel("Email").fill("ada@example.com");
712
+ await readable(`${colorScheme} sign in with an email`);
713
+ await page.getByRole("button", { name: "Forgot password?" }).click();
714
+ await expect(page.getByRole("heading", { level: 1, name: "Reset your password" })).toBeVisible();
715
+ await readable(`${colorScheme} reset`);
716
+ await page.getByRole("button", { name: "Back to sign in" }).click();
717
+ await page.getByRole("button", { name: "Use one-time code" }).click();
718
+ await readable(`${colorScheme} one-time code`);
719
+ await page.goto("/auth/login?mode=register");
720
+ await expect(page.getByRole("heading", { level: 1, name: "Create your account" })).toBeVisible();
721
+ await readable(`${colorScheme} register`);
722
+ await page.getByLabel("Email").fill("ada@example.com");
723
+ await page.getByLabel("Password", { exact: true }).fill("Correct-horse-1");
724
+ await page.getByLabel("Confirm password", { exact: true }).fill("Correct-horse-1");
725
+ await page.getByTestId("auth-submit").click();
726
+ await expect(page.getByRole("heading", { level: 1, name: "Confirm your email" })).toBeVisible();
727
+ await readable(`${colorScheme} confirm email`);
728
+ }
729
+ assert.deepEqual(failures, []);
730
+ await finish(api);
731
+ });
732
+
623
733
  test("an app's brand shows in a pane beside the card on wide windows and in a row above it on phones", options, async () => {
624
734
  for (const viewport of [{ width: 1280, height: 900 }, { width: 390, height: 844 }]) {
625
735
  const at = `${viewport.width}px`;