@jskit-ai/shell-web 0.2.19 → 0.2.21

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,108 @@
1
+ import { computed, nextTick, onBeforeUnmount, onMounted, ref, watch } from "vue";
2
+ import { PAGE_TITLE_ID } from "../navigation/shellNavigationRuntime.js";
3
+ import { resolveTopRightItemsInMenu } from "../support/topRightOverflow.js";
4
+
5
+ // Material 3's icon button: the width of an item, or of the overflow button, that the bar has not drawn yet.
6
+ const ICON_BUTTON_WIDTH = 48;
7
+
8
+ /**
9
+ * The title's whole width: its box when the text fits (ShellLayout sizes the h1 to its text), else the text it clips,
10
+ * a pixel more, since scrollWidth is a whole number and a rounding must never make a clipped title fit.
11
+ * @param {HTMLElement} title
12
+ */
13
+ function wholeTitleWidth(title) {
14
+ return title.scrollWidth > title.clientWidth ? title.scrollWidth + 1 : title.getBoundingClientRect().width;
15
+ }
16
+
17
+ /**
18
+ * How many of a compact top app bar's top-right items (from the first, the farthest from the corner) ShellLayout
19
+ * moves into the bar's overflow menu: as few as leave the page title whole beside the rest
20
+ * (resolveTopRightItemsInMenu), measured on the bar as drawn. It measures again when the bar's content changes (a new
21
+ * title, an item's count, a page action), when the bar is resized and when fonts load. An item in the menu keeps the
22
+ * width it had in the bar. Medium and wider bars, and a layout's own top-right slot, keep every item (`enabled`).
23
+ * @param {object} options
24
+ * @param {import("vue").Ref<boolean>} options.enabled
25
+ * @param {import("vue").Ref<readonly { id: string }[]>} options.placements The top-right placements, in bar order.
26
+ * @param {import("../support/pageActions.js").ShellPageActionsRegistry} options.pageActions The bar's page actions.
27
+ * @param {import("vue").Ref<HTMLElement | null>} options.row The bar's row, whose width is the bar's.
28
+ * @param {import("vue").Ref<HTMLElement | null>} options.headline The title's box.
29
+ * @param {import("vue").Ref<HTMLElement | null>} options.items The box of the top-right items in the bar, each a child
30
+ * with `data-placement-id`.
31
+ * @param {string} options.menuId The id of the element in the overflow menu that the items move into.
32
+ * @returns {{ inMenu: import("vue").ComputedRef<number> }}
33
+ */
34
+ function useShellTopRightOverflow({ enabled, placements, pageActions, row, headline, items, menuId }) {
35
+ const measured = ref(0);
36
+ const widths = new Map();
37
+ let menuButtonWidth = ICON_BUTTON_WIDTH;
38
+ let resizeObserver = null;
39
+ let mutationObserver = null;
40
+ const keepLast = computed(() => !pageActions.hasPrimary.value);
41
+ const inMenu = computed(() => {
42
+ if (!enabled.value) {
43
+ return 0;
44
+ }
45
+ return Math.min(measured.value, Math.max(placements.value.length - (keepLast.value ? 1 : 0), 0));
46
+ });
47
+
48
+ function fit() {
49
+ const rowElement = row.value;
50
+ const headlineElement = headline.value;
51
+ const itemsElement = items.value;
52
+ const title = headlineElement ? headlineElement.querySelector(`#${PAGE_TITLE_ID}`) : null;
53
+ // The items move into the menu only once it is there to take them.
54
+ if (!enabled.value || !rowElement || !itemsElement || !title || !document.getElementById(menuId)) {
55
+ measured.value = 0;
56
+ return;
57
+ }
58
+ let inBar = 0;
59
+ for (const element of itemsElement.querySelectorAll(":scope > [data-placement-id]")) {
60
+ const width = element.getBoundingClientRect().width;
61
+ widths.set(element.dataset.placementId, width);
62
+ inBar += width;
63
+ }
64
+ const menuButton = rowElement.querySelector(".shell-page-actions-overflow");
65
+ if (menuButton) {
66
+ menuButtonWidth = menuButton.getBoundingClientRect().width;
67
+ }
68
+ const style = window.getComputedStyle(headlineElement);
69
+ const titleRoom = headlineElement.clientWidth -
70
+ Number.parseFloat(style.paddingInlineStart) -
71
+ Number.parseFloat(style.paddingInlineEnd);
72
+ measured.value = resolveTopRightItemsInMenu({
73
+ room: titleRoom + inBar + (menuButton ? menuButtonWidth : 0),
74
+ title: wholeTitleWidth(title),
75
+ items: placements.value.map((entry) => widths.get(entry.id) ?? ICON_BUTTON_WIDTH),
76
+ menuButton: menuButtonWidth,
77
+ menuShown: pageActions.menuEntries.value.length > 0,
78
+ keepLast: keepLast.value
79
+ });
80
+ }
81
+
82
+ watch(
83
+ [enabled, () => placements.value.map((entry) => entry.id).join("\n"), keepLast, () => pageActions.menuEntries.value.length],
84
+ fit,
85
+ { flush: "post" }
86
+ );
87
+
88
+ onMounted(() => {
89
+ // The row is as wide as the bar whatever its items do, so a fit in its callback never resizes what it observes.
90
+ resizeObserver = new ResizeObserver(fit);
91
+ resizeObserver.observe(row.value);
92
+ // A change inside the bar (the title, an item's count, a page action, an item moving) can change what fits.
93
+ mutationObserver = new MutationObserver(fit);
94
+ mutationObserver.observe(row.value, { childList: true, subtree: true, characterData: true });
95
+ document.fonts.addEventListener("loadingdone", fit);
96
+ void nextTick().then(fit);
97
+ });
98
+
99
+ onBeforeUnmount(() => {
100
+ resizeObserver.disconnect();
101
+ mutationObserver.disconnect();
102
+ document.fonts.removeEventListener("loadingdone", fit);
103
+ });
104
+
105
+ return { inMenu };
106
+ }
107
+
108
+ export { useShellTopRightOverflow };
@@ -0,0 +1,28 @@
1
+ /**
2
+ * How many of a compact top app bar's own items (its top-right placements, in bar order) go into its overflow menu:
3
+ * the fewest, farthest from the corner first, that leave the page title its whole width beside the rest, so a short
4
+ * title keeps every item that fits. The item nearest the corner (the account avatar) stays unless the page's primary
5
+ * action holds the bar's trailing place, so a title too long for the bar is clipped beside it.
6
+ * @param {object} options
7
+ * @param {number} options.room The width the title, the items in the bar and the overflow button share.
8
+ * @param {number} options.title The title's whole width.
9
+ * @param {readonly number[]} options.items Each item's width, in bar order.
10
+ * @param {number} options.menuButton The overflow button's width.
11
+ * @param {boolean} options.menuShown Whether the bar shows the overflow button anyway, for page actions in its menu.
12
+ * @param {boolean} options.keepLast Whether the item nearest the corner stays in the bar whatever room is left.
13
+ * @returns {number} How many items, from the first, are in the menu.
14
+ */
15
+ function resolveTopRightItemsInMenu({ room, title, items, menuButton, menuShown, keepLast }) {
16
+ const most = Math.max(items.length - (keepLast ? 1 : 0), 0);
17
+ let inBar = items.reduce((total, width) => total + width, 0);
18
+ for (let inMenu = 0; inMenu < most; inMenu += 1) {
19
+ const button = menuShown || inMenu > 0 ? menuButton : 0;
20
+ if (title + inBar + button <= room) {
21
+ return inMenu;
22
+ }
23
+ inBar -= items[inMenu];
24
+ }
25
+ return most;
26
+ }
27
+
28
+ export { resolveTopRightItemsInMenu };
@@ -1,3 +1,5 @@
1
+ import { MAXIMUM_SHELL_DRAWER_WIDTH, MINIMUM_SHELL_DRAWER_WIDTH } from "../client/support/drawerWidth.js";
2
+
1
3
  const DEFAULT_SMOKE_PATH = String(process.env.JSKIT_PLAYWRIGHT_SMOKE_PATH || "/home");
2
4
  const DEFAULT_VIEWPORTS = Object.freeze([
3
5
  Object.freeze({ name: "compact", width: 390, height: 844 }),
@@ -94,12 +96,14 @@ async function readConfiguredWidth(drawer, attribute) {
94
96
  return width;
95
97
  }
96
98
 
97
- async function expectDrawerWidth(drawer, expect, expectedWidth) {
99
+ // The element settles at the width the drawer reports in `attribute`, read again on each poll: a drawer that fits its
100
+ // labels measures them once it shows, and again once the fonts load, so the width it reports can change as it opens.
101
+ async function expectDrawerWidth(element, expect, drawer, attribute) {
98
102
  await expect.poll(async () => {
99
- const box = await drawer.boundingBox();
100
- return box ? Math.abs(box.width - expectedWidth) : Number.POSITIVE_INFINITY;
103
+ const box = await element.boundingBox();
104
+ return box ? Math.abs(box.width - await readConfiguredWidth(drawer, attribute)) : Number.POSITIVE_INFINITY;
101
105
  }, {
102
- message: `Shell drawer did not settle at ${expectedWidth}px.`
106
+ message: `Shell drawer did not settle at its ${attribute}.`
103
107
  }).toBeLessThanOrEqual(1);
104
108
  }
105
109
 
@@ -120,6 +124,18 @@ async function expectContentAwareDrawerFit(drawer, expect) {
120
124
  const innerEnd = rightToLeft
121
125
  ? drawerRect.left + endBorderWidth
122
126
  : drawerRect.right - endBorderWidth;
127
+ // The identity at the drawer's top (a workspace switcher) at the width its content wants, as the shell measures it.
128
+ const identity = element.querySelector(".shell-layout__identity");
129
+ let identityEndGap = null;
130
+ if (identity && window.getComputedStyle(identity).display !== "none") {
131
+ const { width, maxWidth } = identity.style;
132
+ identity.style.width = "max-content";
133
+ identity.style.maxWidth = "none";
134
+ const identityRect = identity.getBoundingClientRect();
135
+ identity.style.width = width;
136
+ identity.style.maxWidth = maxWidth;
137
+ identityEndGap = rightToLeft ? identityRect.left - innerEnd : innerEnd - identityRect.right;
138
+ }
123
139
  const labels = Array.from(element.querySelectorAll(".v-list-item-title"))
124
140
  .filter((label) => {
125
141
  const style = window.getComputedStyle(label);
@@ -162,6 +178,8 @@ async function expectContentAwareDrawerFit(drawer, expect) {
162
178
  }, null);
163
179
  return {
164
180
  clipped: labels.some((label) => label.clipped),
181
+ drawerWidth: drawerRect.width,
182
+ identityEndGap,
165
183
  endGap: rightToLeft
166
184
  ? furthestLabel.logicalEnd - innerEnd
167
185
  : innerEnd - furthestLabel.logicalEnd,
@@ -173,7 +191,19 @@ async function expectContentAwareDrawerFit(drawer, expect) {
173
191
 
174
192
  expect(fit).not.toBeNull();
175
193
  expect(fit.clipped).toBe(false);
176
- expect(Math.abs(fit.endGap - configuredSpacing)).toBeLessThanOrEqual(1.1);
194
+ expect(fit.endGap).toBeGreaterThanOrEqual(configuredSpacing - 1.1);
195
+ // The widest label ends the spacing from the drawer's end, unless the drawer is at its narrowest or the identity at its
196
+ // top is wider than the labels: it then ends at the drawer's end, or is cut there by the widest drawer.
197
+ const fittedToLabels = Math.abs(fit.endGap - configuredSpacing) <= 1.1;
198
+ const fittedToIdentity = fit.identityEndGap !== null && (
199
+ Math.abs(fit.identityEndGap) <= 1.1 ||
200
+ (fit.identityEndGap < 0 && fit.drawerWidth >= MAXIMUM_SHELL_DRAWER_WIDTH - 1)
201
+ );
202
+ const atMinimum = fit.drawerWidth <= MINIMUM_SHELL_DRAWER_WIDTH + 1;
203
+ expect(
204
+ fittedToLabels || fittedToIdentity || atMinimum,
205
+ `The drawer is ${fit.drawerWidth}px wide, its widest label ${fit.endGap}px from its end and its identity ${fit.identityEndGap}px.`
206
+ ).toBe(true);
177
207
  expect(fit.iconLabelGaps.length).toBeGreaterThan(0);
178
208
  for (const gap of fit.iconLabelGaps) {
179
209
  expect(Math.abs(gap - configuredSpacing)).toBeLessThanOrEqual(1);
@@ -345,11 +375,11 @@ async function runAdaptiveShellSmokeCase({
345
375
  const rail = page.getByTestId("jskit-shell-rail");
346
376
  await expect(rail).toBeVisible();
347
377
  await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
348
- await expectDrawerWidth(rail, expect, await readConfiguredWidth(drawer, "data-rail-width"));
378
+ await expectDrawerWidth(rail, expect, drawer, "data-rail-width");
349
379
  await toggle.click();
350
380
  await expect(drawer).toHaveAttribute("data-presentation", "modal");
351
381
  await expectElementVisibility(page, expect, "jskit-shell-drawer", true);
352
- await expectDrawerWidth(drawer, expect, await readConfiguredWidth(drawer, "data-drawer-width"));
382
+ await expectDrawerWidth(drawer, expect, drawer, "data-drawer-width");
353
383
  const drawerIconCenters = await readNavigationIconCenters(drawer, expect);
354
384
  await page.keyboard.press("Escape");
355
385
  await expectElementVisibility(page, expect, "jskit-shell-drawer", false);
@@ -362,7 +392,7 @@ async function runAdaptiveShellSmokeCase({
362
392
  await toggle.click();
363
393
  }
364
394
  await expect(drawer).toHaveAttribute("data-presentation", "drawer");
365
- await expectDrawerWidth(drawer, expect, await readConfiguredWidth(drawer, "data-drawer-width"));
395
+ await expectDrawerWidth(drawer, expect, drawer, "data-drawer-width");
366
396
  await expectContentAwareDrawerFit(drawer, expect);
367
397
  const expandedIconCenters = await readNavigationIconCenters(drawer, expect);
368
398
  await page.keyboard.press("Escape");
@@ -370,7 +400,7 @@ async function runAdaptiveShellSmokeCase({
370
400
 
371
401
  await toggle.click();
372
402
  await expect(drawer).toHaveAttribute("data-presentation", "rail");
373
- await expectDrawerWidth(drawer, expect, await readConfiguredWidth(drawer, "data-rail-width"));
403
+ await expectDrawerWidth(drawer, expect, drawer, "data-rail-width");
374
404
  await expectCentredRailNavigation(page, drawer, expect, expandedIconCenters);
375
405
  await expectNoHorizontalOverflow(page, expect);
376
406
  }
@@ -269,15 +269,18 @@ test("shell-web adaptive navigation passes package-owned browser contracts", {
269
269
 
270
270
  const railPage = await context.newPage();
271
271
  await railPage.setViewportSize({ width: 1280, height: 900 });
272
- await railPage.goto("/w/acme/admin/bookings?theme=light");
272
+ // drawerWidth="material" asks for Material 3's full width in place of the fitted one.
273
+ await railPage.goto("/w/acme/admin/bookings?theme=light&drawerWidth=material");
274
+ await expect(railPage.getByTestId("jskit-shell-drawer")).toHaveAttribute("data-drawer-width-mode", "fixed");
273
275
  await expect(railPage.getByTestId("jskit-shell-drawer")).toHaveAttribute("data-drawer-width", "360");
274
276
  await assertRailKeyboardAndSelection(railPage);
275
277
  await railPage.close();
276
278
 
279
+ // Without a drawerWidth the drawer fits its labels.
277
280
  const configuredPage = await context.newPage();
278
281
  await configuredPage.setViewportSize({ width: 1280, height: 900 });
279
282
  await configuredPage.goto(
280
- "/w/acme/admin/bookings?theme=light&railWidth=64&navigationItemSpacing=8&drawerWidth=content"
283
+ "/w/acme/admin/bookings?theme=light&railWidth=64&navigationItemSpacing=8"
281
284
  );
282
285
  const configuredDrawer = configuredPage.getByTestId("jskit-shell-drawer");
283
286
  await expect(configuredDrawer).toHaveAttribute("data-navigation-item-spacing", "8");
@@ -502,15 +505,15 @@ test("a snackbar never covers the FAB, the navigation bar or a form's Save, so S
502
505
  }
503
506
  });
504
507
 
505
- // A content-sized drawer fits a long name in its identity (a workspace switcher, say) as well as its labels.
506
- test("a content-sized drawer is wide enough for its identity's name", {
508
+ // The drawer fits a long name in its identity (a workspace switcher, say) as well as its labels.
509
+ test("the drawer is wide enough for its identity's name", {
507
510
  skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
508
511
  timeout: 90_000
509
512
  }, async (t) => {
510
513
  const { vite, browser } = await startFixture(t);
511
514
  const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 1280, height: 900 } });
512
515
  const name = "Northwind Regional Distribution";
513
- await page.goto(`/home?drawerWidth=content&identity=${encodeURIComponent(name)}`);
516
+ await page.goto(`/home?identity=${encodeURIComponent(name)}`);
514
517
  const drawer = page.getByTestId("jskit-shell-drawer");
515
518
  await expect(drawer).toHaveAttribute("data-presentation", "drawer");
516
519
  await expect(drawer.getByRole("button", { name })).toBeVisible();
@@ -546,7 +549,7 @@ test("a content-sized drawer is wide enough for its identity's name", {
546
549
  await settle();
547
550
  assert.equal((await fit()).width, settled);
548
551
  // Without the long name the drawer fits its labels again.
549
- await page.goto("/home?drawerWidth=content");
552
+ await page.goto("/home");
550
553
  await expect.poll(async () => Math.round((await drawer.boundingBox())?.width || 0)).toBeLessThan(settled);
551
554
  await page.close();
552
555
  });
@@ -765,7 +768,7 @@ test("a page's section tabs are Material 3 primary tabs at every width, and the
765
768
  await expect(page.getByTestId("fixture-section-tabs").getByRole("link", { name: "Activity" })).toHaveAttribute("aria-current", "page");
766
769
  if (viewport.name === "compact") {
767
770
  // The navigation bar's destinations keep their 64x32 indicators.
768
- const indicator = page.getByTestId("jskit-shell-bottom-nav").locator(".tab-link-item__indicator").first();
771
+ const indicator = page.getByTestId("jskit-shell-bottom-nav").locator(".tab-link-item .v-icon").first();
769
772
  const box = await indicator.boundingBox();
770
773
  assert.deepEqual([Math.round(box.width), Math.round(box.height)], [64, 32], `${at}: a navigation bar destination`);
771
774
  }
@@ -1174,72 +1177,95 @@ test("a nested component's title gives the page's own title back, and Save retur
1174
1177
  }
1175
1178
  });
1176
1179
 
1177
- test("on a phone, the bar keeps one trailing item and moves the page actions and its other items into one menu", {
1180
+ test("on a phone, the bar keeps the items that fit beside the whole title, moves the rest into its menu and keeps each one mounted", {
1178
1181
  skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1179
1182
  timeout: 90_000
1180
- }, async () => {
1181
- const vite = await startViteFixture({ fixtureRoot: FIXTURE_ROOT });
1182
- let browser;
1183
- try {
1184
- browser = await chromium.launch(createChromiumLaunchOptions());
1185
- const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
1186
- // Tools, status and the account avatar: the list keeps the avatar, nearest the corner, and the overflow menu holds
1187
- // every page action, then the tools and the status.
1188
- await page.goto("/home/actions?topRight=3");
1189
- const bar = page.getByTestId("jskit-shell-app-bar");
1190
- const overflow = bar.getByTestId("jskit-shell-page-actions-overflow");
1191
- const barItems = () =>
1192
- bar.locator(".shell-layout__top-right [data-testid=fixture-status]").evaluateAll((items) =>
1193
- items.map((item) => item.getAttribute("aria-label"))
1194
- );
1195
- assert.deepEqual(await barItems(), ["Account"]);
1196
- await expect(bar.locator(".shell-page-action")).toHaveCount(0);
1197
- await overflow.click();
1198
- await expect(page.getByRole("menu")).toBeVisible();
1199
- await expect(page.getByRole("menuitem")).toHaveText(["Edit", "Export", "Open site", "Delete", "Duplicate"]);
1200
- const items = page.getByTestId("jskit-shell-page-actions-overflow-items");
1201
- await expect(items.getByTestId("fixture-status")).toHaveCount(2);
1202
- await expect(items.getByRole("button", { name: "Tools", exact: true })).toBeVisible();
1203
- await expect(items.getByRole("button", { name: "Status", exact: true })).toBeVisible();
1204
- await page.keyboard.press("Escape");
1205
- await expect(page.getByRole("menu")).toBeHidden();
1206
- const room = () =>
1207
- page.evaluate(() => {
1208
- const title = document.querySelector("[data-testid=jskit-shell-page-title]");
1209
- const trailing = Array.from(document.querySelectorAll("[data-testid=jskit-shell-app-bar] .v-btn")).at(-1);
1210
- return {
1211
- title: Math.round(title.getBoundingClientRect().width),
1212
- clipped: title.scrollWidth > title.clientWidth + 1,
1213
- right: Math.round(trailing.getBoundingClientRect().right)
1214
- };
1215
- });
1216
- const list = await room();
1217
- assert.ok(list.title >= 96 && !list.clipped, `the list's title keeps its room (${list.title}px)`);
1218
- assert.ok(list.right <= 390, `the avatar is in the window (${list.right}px)`);
1219
-
1220
- // A form's Save is its one trailing item, so the avatar joins the tools and the status in the menu.
1221
- await page.getByRole("link", { name: "New entry", exact: true }).click();
1222
- await expect(bar.getByRole("button", { name: "Save", exact: true })).toBeVisible();
1223
- await expect(page.getByTestId("jskit-shell-back")).toHaveAttribute("data-action", "close");
1224
- assert.deepEqual(await barItems(), []);
1225
- await overflow.click();
1226
- await expect(items.getByTestId("fixture-status")).toHaveCount(3);
1227
- await expect(page.getByRole("menuitem")).toHaveCount(0);
1228
- await expect(items.getByRole("button", { name: "Account", exact: true })).toBeVisible();
1229
- await page.keyboard.press("Escape");
1230
- await expect(items).toBeHidden();
1231
- const form = await room();
1232
- assert.ok(form.title >= 96 && !form.clipped, `the form's title keeps its room (${form.title}px)`);
1233
- assert.ok(form.right <= 390, `Save is in the window (${form.right}px)`);
1234
-
1235
- // Wider windows keep every item in the bar.
1236
- await page.setViewportSize({ width: 1280, height: 900 });
1237
- await expect(bar.getByTestId("fixture-status")).toHaveCount(3);
1238
- await page.close();
1239
- } finally {
1240
- await browser?.close();
1241
- await stopProcess(vite);
1242
- }
1183
+ }, async (t) => {
1184
+ const { vite, browser } = await startFixture(t);
1185
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
1186
+ const bar = page.getByTestId("jskit-shell-app-bar");
1187
+ const overflow = bar.getByTestId("jskit-shell-page-actions-overflow");
1188
+ const items = page.getByTestId("jskit-shell-page-actions-overflow-items");
1189
+ const barItems = () =>
1190
+ bar.locator(".shell-layout__top-right [data-testid=fixture-status]").evaluateAll((elements) =>
1191
+ elements.map((element) => element.getAttribute("aria-label"))
1192
+ );
1193
+ const room = () =>
1194
+ page.evaluate(() => {
1195
+ const title = document.querySelector("[data-testid=jskit-shell-page-title]");
1196
+ const trailing = Array.from(document.querySelectorAll("[data-testid=jskit-shell-app-bar] .v-btn")).at(-1);
1197
+ return {
1198
+ title: Math.round(title.getBoundingClientRect().width),
1199
+ clipped: title.scrollWidth > title.clientWidth + 1,
1200
+ right: Math.round(trailing.getBoundingClientRect().right)
1201
+ };
1202
+ });
1203
+ // Every item, in the bar or the menu, mounted once and never unmounted.
1204
+ const lifecycle = () => page.evaluate(() => window.__fixtureStatusLifecycle);
1205
+ const mountedOnce = { "Tools mounted": 1, "Status mounted": 1, "Account mounted": 1 };
1206
+
1207
+ // Tools, status and the account avatar beside a short title and the page actions' menu: all three fit, so all three
1208
+ // stay in the bar, and the menu holds only the page actions.
1209
+ await page.goto("/home/actions?topRight=3&title=Actions");
1210
+ await expect(shellPageTitle(page)).toHaveText("Actions");
1211
+ await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
1212
+ await expect(bar.locator(".shell-page-action")).toHaveCount(0);
1213
+ const short = await room();
1214
+ assert.ok(!short.clipped, `the short title is whole (${short.title}px)`);
1215
+ assert.ok(short.right <= 390, `the avatar is in the window (${short.right}px)`);
1216
+ await overflow.click();
1217
+ await expect(page.getByRole("menu")).toBeVisible();
1218
+ await expect(page.getByRole("menuitem")).toHaveText(["Edit", "Export", "Open site", "Delete", "Duplicate"]);
1219
+ await expect(items).toBeHidden();
1220
+ await page.keyboard.press("Escape");
1221
+ await expect(page.getByRole("menu")).toBeHidden();
1222
+
1223
+ // A title too long for the bar: the items farthest from the corner move into the menu, after the page actions, and
1224
+ // the avatar stays. The status's own surface stays on the page while its button is in the closed menu.
1225
+ await page.getByTestId("fixture-toggle-long-title").click();
1226
+ await expect(shellPageTitle(page)).toHaveText("Quarterly statements for every supplier");
1227
+ await expect.poll(barItems).toEqual(["Account"]);
1228
+ await expect(page.getByTestId("fixture-status")).toHaveCount(3);
1229
+ await expect(page.getByTestId("fixture-status-surface")).toBeVisible();
1230
+ const long = await room();
1231
+ assert.ok(long.right <= 390, `the avatar is in the window (${long.right}px)`);
1232
+ await overflow.click();
1233
+ await expect(page.getByRole("menuitem")).toHaveText(["Edit", "Export", "Open site", "Delete", "Duplicate"]);
1234
+ await expect(items.getByTestId("fixture-status")).toHaveCount(2);
1235
+ await expect(items.getByRole("button", { name: "Tools", exact: true })).toBeVisible();
1236
+ await expect(items.getByRole("button", { name: "Status", exact: true })).toBeVisible();
1237
+ await page.keyboard.press("Escape");
1238
+ await expect(items).toBeHidden();
1239
+ await expect(page.getByTestId("fixture-status-surface")).toBeVisible();
1240
+
1241
+ // The short title again: the items come back to the bar.
1242
+ await page.getByTestId("fixture-toggle-long-title").click();
1243
+ await expect(shellPageTitle(page)).toHaveText("Actions");
1244
+ await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
1245
+ assert.deepEqual(await lifecycle(), mountedOnce);
1246
+
1247
+ // A form's Save is a trailing item too: whatever does not fit beside it and the whole title, the avatar included,
1248
+ // is in the menu, and nothing remounts.
1249
+ await page.getByRole("link", { name: "New entry", exact: true }).click();
1250
+ await expect(bar.getByRole("button", { name: "Save", exact: true })).toBeVisible();
1251
+ await expect(page.getByTestId("jskit-shell-back")).toHaveAttribute("data-action", "close");
1252
+ await expect(page.getByTestId("fixture-status")).toHaveCount(3);
1253
+ const form = await room();
1254
+ const formItems = await barItems();
1255
+ assert.ok(!form.clipped || formItems.length === 0, `the form's title is whole, or the bar holds none of its items (${formItems})`);
1256
+ assert.ok(form.right <= 390, `the bar's trailing item is in the window (${form.right}px)`);
1257
+ assert.deepEqual(formItems, ["Tools", "Status", "Account"].slice(3 - formItems.length), "the bar keeps the items nearest the corner");
1258
+ await page.getByTestId("jskit-shell-back").click();
1259
+ await expect(shellPageTitle(page)).toHaveText("Actions");
1260
+ await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
1261
+
1262
+ // Wider windows keep every item in the bar, the same instances.
1263
+ await page.setViewportSize({ width: 1280, height: 900 });
1264
+ await expect(bar.getByTestId("fixture-status")).toHaveCount(3);
1265
+ await page.setViewportSize({ width: 390, height: 844 });
1266
+ await expect.poll(barItems).toEqual(["Tools", "Status", "Account"]);
1267
+ assert.deepEqual(await lifecycle(), mountedOnce);
1268
+ await page.close();
1243
1269
  });
1244
1270
 
1245
1271
  function shellPageActionButton(page, name) {
@@ -1317,6 +1343,166 @@ test("a virtual-scroll list in a dialog reaches its last item after the page aro
1317
1343
  }
1318
1344
  });
1319
1345
 
1346
+ // A list item's subtitle is at full strength, as Material 3's list draws its supporting text: on-surface-variant on an
1347
+ // item at rest, the item's own colour on an active one, over the card and the active item's selected state layer.
1348
+ // Vuetify's medium-emphasis opacity measured 4.35:1 at rest and 4.45:1 active on the card, under WCAG's 4.5:1.
1349
+ test("a list item's subtitle is readable at rest and active, in light and dark", {
1350
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1351
+ timeout: 60_000
1352
+ }, async (t) => {
1353
+ const { vite, browser } = await startFixture(t);
1354
+ for (const theme of ["light", "dark"]) {
1355
+ const page = await browser.newPage({ baseURL: vite.baseURL, colorScheme: theme, viewport: { width: 390, height: 844 } });
1356
+ await page.goto(`/home/components?theme=${theme}`);
1357
+ const onSurfaceVariant = await readRoleColor(page, "on-surface-variant");
1358
+ for (const testId of ["fixture-active-item", "fixture-rest-item"]) {
1359
+ const item = await page.getByTestId(testId).evaluate((element) => {
1360
+ const style = (node) => window.getComputedStyle(node);
1361
+ const overlay = element.querySelector(".v-list-item__overlay");
1362
+ const subtitle = element.querySelector(".v-list-item-subtitle");
1363
+ return {
1364
+ card: style(element.closest(".v-card")).backgroundColor,
1365
+ color: style(element).color,
1366
+ // Vuetify draws a state layer only on an item that is active or can be clicked.
1367
+ overlay: overlay ? [style(overlay).backgroundColor, Number(style(overlay).opacity)] : ["rgb(0, 0, 0)", 0],
1368
+ subtitle: [style(subtitle).color, Number(style(subtitle).opacity)]
1369
+ };
1370
+ });
1371
+ const at = `${testId} in ${theme}`;
1372
+ // What shows under the subtitle: the card, then the item's state layer at its opacity.
1373
+ const card = parseRgb(item.card);
1374
+ const layer = parseRgb(item.overlay[0]);
1375
+ const mix = (top, bottom, alpha) => ({
1376
+ red: top.red * alpha + bottom.red * (1 - alpha),
1377
+ green: top.green * alpha + bottom.green * (1 - alpha),
1378
+ blue: top.blue * alpha + bottom.blue * (1 - alpha)
1379
+ });
1380
+ const background = mix(layer, card, layer.alpha * item.overlay[1]);
1381
+ const text = parseRgb(item.subtitle[0]);
1382
+ const ratio = contrastRatio(mix(text, background, text.alpha * item.subtitle[1]), background);
1383
+ assert.equal(item.subtitle[1], 1, `${at}: the subtitle is at full strength`);
1384
+ assert.equal(item.subtitle[0], testId === "fixture-rest-item" ? onSurfaceVariant : item.color, `${at}: its colour`);
1385
+ assert.ok(ratio >= 4.5, `${at}: the subtitle's contrast was ${ratio.toFixed(2)}:1`);
1386
+ }
1387
+ await page.close();
1388
+ }
1389
+ });
1390
+
1391
+ test("an app's own v-bottom-navigation is Material 3's navigation bar: a 64x32 indicator around a 24dp icon, in light and dark", {
1392
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1393
+ timeout: 60_000
1394
+ }, async (t) => {
1395
+ const { vite, browser } = await startFixture(t);
1396
+ for (const theme of ["light", "dark"]) {
1397
+ const page = await browser.newPage({ baseURL: vite.baseURL, colorScheme: theme, viewport: { width: 390, height: 844 } });
1398
+ await page.goto(`/home/components?theme=${theme}`);
1399
+ const roles = {};
1400
+ for (const role of ["secondary-container", "on-secondary-container", "on-surface", "on-surface-variant"]) {
1401
+ roles[role] = await readRoleColor(page, role);
1402
+ }
1403
+ const read = (testId) => page.getByTestId(testId).evaluate((button) => {
1404
+ const style = (node) => window.getComputedStyle(node);
1405
+ const icon = button.querySelector(".v-icon");
1406
+ // A label in a span of its own beside an icon in the content, or the content itself beside a prepend-icon.
1407
+ const label = button.querySelector(".v-btn__content > span") || button.querySelector(".v-btn__content");
1408
+ const box = (node) => node.getBoundingClientRect();
1409
+ const visible = (node) => node && style(node).display !== "none";
1410
+ return {
1411
+ indicator: [Math.round(box(icon).width), Math.round(box(icon).height), style(icon).borderTopLeftRadius],
1412
+ glyph: Math.round(box(icon.querySelector("svg")).width),
1413
+ colors: [style(icon).backgroundColor, style(icon).color, style(label).color],
1414
+ stateLayer: style(icon).backgroundImage,
1415
+ label: [style(label).fontSize, style(label).lineHeight, style(label).fontWeight],
1416
+ gap: Math.round(box(label).top - box(icon).bottom),
1417
+ // The state layer is the indicator's, not Vuetify's across the whole button.
1418
+ buttonLayers: [".v-btn__overlay", ".v-btn__underlay"].some((selector) => visible(button.querySelector(`:scope > ${selector}`)))
1419
+ };
1420
+ });
1421
+ const at = (name) => `${name} in ${theme}`;
1422
+ const active = await read("fixture-navigation-active");
1423
+ const rest = await read("fixture-navigation-rest");
1424
+ for (const [name, destination] of [["active", active], ["rest", rest]]) {
1425
+ assert.deepEqual(destination.indicator, [64, 32, "16px"], at(`${name}: the indicator`));
1426
+ assert.equal(destination.glyph, 24, at(`${name}: the icon`));
1427
+ assert.deepEqual(destination.label, ["12px", "16px", "500"], at(`${name}: label-medium`));
1428
+ assert.equal(destination.gap, 4, at(`${name}: the label 4dp below the indicator`));
1429
+ assert.equal(destination.buttonLayers, false, at(`${name}: no whole-button state layer`));
1430
+ }
1431
+ assert.deepEqual(active.colors, [roles["secondary-container"], roles["on-secondary-container"], roles["on-surface"]], at("active"));
1432
+ assert.deepEqual(rest.colors, ["rgba(0, 0, 0, 0)", roles["on-surface-variant"], roles["on-surface-variant"]], at("rest"));
1433
+ // Hovered, the destination's indicator takes its state layer.
1434
+ await page.getByTestId("fixture-navigation-rest").hover();
1435
+ await expect.poll(() => page.getByTestId("fixture-navigation-rest").locator(".v-icon")
1436
+ .evaluate((icon) => window.getComputedStyle(icon).backgroundImage)).not.toBe(rest.stateLayer);
1437
+ await page.close();
1438
+ }
1439
+ });
1440
+
1441
+ test("an app's colours win over the navigation bar's, and a denser bar, a badge and an append icon keep its shape", {
1442
+ skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1443
+ timeout: 60_000
1444
+ }, async (t) => {
1445
+ const { vite, browser } = await startFixture(t);
1446
+ const page = await browser.newPage({ baseURL: vite.baseURL, viewport: { width: 390, height: 844 } });
1447
+ await page.goto("/home/components");
1448
+ const roles = {};
1449
+ for (const role of ["primary", "on-primary", "secondary-container", "on-surface-variant"]) {
1450
+ roles[role] = await readRoleColor(page, role);
1451
+ }
1452
+ const transparent = "rgba(0, 0, 0, 0)";
1453
+ const read = (testId) => page.getByTestId(testId).evaluate((button) => {
1454
+ const style = (node) => window.getComputedStyle(node);
1455
+ const box = (node) => node.getBoundingClientRect();
1456
+ const bar = box(button.closest(".v-bottom-navigation"));
1457
+ // The destination's icon, a prepend-icon or one in a badge; its label, in a span or the content itself.
1458
+ const icon = button.querySelector(".v-btn__prepend > .v-icon, .v-badge__wrapper > .v-icon");
1459
+ const label = button.querySelector(".v-btn__content > span") || button.querySelector(".v-btn__content");
1460
+ return {
1461
+ indicator: [Math.round(box(icon).width), Math.round(box(icon).height)],
1462
+ colors: [style(icon).backgroundColor, style(icon).color, style(label).color],
1463
+ fits: box(icon).top >= bar.top - 0.5 && box(label).bottom <= bar.bottom + 0.5,
1464
+ // An append icon and a badge's own icon are not the destination's.
1465
+ otherIcons: Array.from(button.querySelectorAll(".v-btn__append .v-icon, .v-badge__badge .v-icon"))
1466
+ .map((other) => Math.round(box(other).width))
1467
+ };
1468
+ });
1469
+
1470
+ // A bar the app colours: every destination takes the bar's on-primary, and the active indicator is drawn in it.
1471
+ const coloured = { active: await read("fixture-navigation-coloured-active"), rest: await read("fixture-navigation-coloured-rest") };
1472
+ assert.deepEqual(coloured.active.colors.slice(1), [roles["on-primary"], roles["on-primary"]], "coloured bar: active");
1473
+ assert.ok(![transparent, roles["secondary-container"]].includes(coloured.active.colors[0]), `coloured bar: ${coloured.active.colors[0]}`);
1474
+ assert.deepEqual(coloured.rest.colors, [transparent, roles["on-primary"], roles["on-primary"]], "coloured bar: rest");
1475
+
1476
+ // A bar whose color tints its active destination: that one is primary, the rest keep Material 3's colours.
1477
+ const tinted = { active: await read("fixture-navigation-tinted-active"), rest: await read("fixture-navigation-tinted-rest") };
1478
+ assert.deepEqual(tinted.active.colors.slice(1), [roles.primary, roles.primary], "tinted bar: active");
1479
+ assert.ok(![transparent, roles["secondary-container"]].includes(tinted.active.colors[0]), `tinted bar: ${tinted.active.colors[0]}`);
1480
+ assert.deepEqual(tinted.rest.colors, [transparent, roles["on-surface-variant"], roles["on-surface-variant"]], "tinted bar: rest");
1481
+
1482
+ // Denser bars fit their destinations: a comfortable one (48dp) drops the label's 4dp, a compact one (40dp) has a
1483
+ // 24dp indicator. The badge's icon and an append icon (below the label of a stacked button) keep their own size.
1484
+ for (const [density, indicator] of [["comfortable", [64, 32]], ["compact", [64, 24]]]) {
1485
+ for (const name of ["active", "rest"]) {
1486
+ const destination = await read(`fixture-navigation-${density}-${name}`);
1487
+ assert.deepEqual(destination.indicator, indicator, `${density} ${name}: the indicator`);
1488
+ assert.equal(destination.fits, true, `${density} ${name}: the indicator and label inside the bar`);
1489
+ }
1490
+ for (const name of ["active", "append"]) {
1491
+ const destination = await read(`fixture-navigation-${density}-${name}`);
1492
+ assert.deepEqual(destination.indicator, indicator, `${density} ${name}: the indicator`);
1493
+ assert.equal(destination.otherIcons.length, 1, `${density} ${name}: its badge or append icon`);
1494
+ assert.ok(destination.otherIcons[0] < 64, `${density} ${name}: ${destination.otherIcons}`);
1495
+ }
1496
+ }
1497
+
1498
+ // A horizontal bar lays its destinations flat, as Vuetify draws them: no indicator around the icon.
1499
+ for (const name of ["active", "rest"]) {
1500
+ const destination = await read(`fixture-navigation-horizontal-${name}`);
1501
+ assert.ok(destination.indicator[0] < 64, `horizontal ${name}: ${destination.indicator}`);
1502
+ }
1503
+ await page.close();
1504
+ });
1505
+
1320
1506
  test("segmented buttons, filter chips, fixed tabs, menus and dialog actions take Material 3's shapes and colours", {
1321
1507
  skip: RUN_BROWSER_TEST ? false : "set JSKIT_SHELL_WEB_BROWSER_INTEGRATION=1",
1322
1508
  timeout: 90_000