문제: :root의 scrollbar-gutter: stable(1105/15-05)은 일반 스크롤바를 쓰는 브라우저에서 문서가 스크롤되지 않아도 오른쪽 15 px를 비워 둔다. 그 자리에는 root의 배경색이 보인다. 고정 위치 상자와 top layer의 ::backdrop은 그 자리 앞에서 끝나서, drawer·modal을 열면 오른쪽 끝에 가림막이 덮지 않은 밝은 세로 띠가 남는다. compact 골든(390 px, drawer 열림)이 가림막이 375 px에서 끝나는 모습을 정답으로 고정했다. header 띠도 같은 자리 앞에서 끝난다. 고른 방법: - modal이 열린 동안 root 배경색을 가림막을 페이지 바탕 위에 겹친 불투명한 색으로 바꾼다. primitives.css의 :root:has(.ui-dialog[open])이 background-color: var(--dialog-backdrop-on-surface)를 쓴다. - 새 컴포넌트 토큰 셋(component.css). --dialog-backdrop-weight(55%)를 --dialog-backdrop(::backdrop이 칠하는 반투명 가림막, 값은 전과 같다)과 --dialog-backdrop-on-surface(color-mix in srgb로 페이지 바탕과 섞은 색)가 같이 읽는다. 브라우저는 반투명 색을 sRGB에서 겹치므로 두 색이 맞는다. - body가 페이지 바탕(--color-surface)을 직접 칠한다. 그래서 root 배경은 스크롤바 자리(와 overscroll)에만 보이고, 열린 modal 아래 페이지가 두 번 어두워지지 않는다. modal이 없으면 둘이 같은 색이라 화면이 그대로다. - 검사: tests/visual/scrollbar-gutter.visual.spec.ts. 시각 프로젝트에서 Chromium을 --hide-scrollbars 없이 띄우고, 스크롤되지 않는 /not-found (390x844)에서 스크롤바 자리와 바로 옆 가림막의 평균 픽셀 색을 비교한다. 닫힘 → drawer 열림 → 다시 닫힘 세 번 본다. 실패 메시지에 root의 계산된 배경(색·이미지)과 열린 .ui-dialog 수를 적어, 규칙이 안 맞은 것과 맞았는데 그 자리에 안 그려진 것을 구분한다. 08-R2 probe의 잘못된 단언 둘을 고쳤다. 자리가 비어 있으면 clientWidth가 창 폭이라 자리 위치는 body의 오른쪽 끝으로 찾는다. 그 자리의 hit test는 늘 null이라 픽셀을 본다. 허용 차이 12는 drawer 그림자(70 px blur)가 옆 띠를 약 3단계 어둡게 하는 몫이다. 덮지 않은 띠는 약 120 차이 난다. - header 띠는 받아들이고 design-system-platform.md 8.2에 적었다. header 색으로 칠하려면 root 배경이 셸의 header 높이·색을 알아야 하고, 셸이 없는 화면에서는 그 띠를 빼야 한다. 완료 기준은 가림막만 요구한다. 버린 대안: - 첫 시도: :root:has(.ui-dialog:modal)에서 가림막 색 gradient 한 겹을 페이지 바탕 위에 얹었다. desktop batch에서 그 자리가 페이지 바탕색 그대로였다 (gutter rgb(248 250 252), 옆 가림막 rgb(122 128 136)). 그 실행만으로는 규칙이 안 맞았는지(:modal의 :has() 무효화), 이미지 층이 그 자리에 안 그려졌는지 가를 수 없다. 그래서 둘 다 피한다. 배경색 자체를 바꾸고, showModal()이 세우는 [open] 속성으로 고른다. Dialog primitive는 브라우저에서 늘 showModal()로 열기 때문에 열린 .ui-dialog는 modal이다. - ::backdrop에 음수 inset(right: -N px): 스크롤바 자리는 viewport의 padding box 밖이라 고정 위치 상자가 잘린다(스펙 기준, 화면 확인은 안 함). - scrollbar-gutter를 거두기: 15-05의 첫 화면 shift를 다시 연다. - modal이 열린 동안 root 배경만 바꾸고 body를 비워 두기: 페이지 전체가 가림막 아래에서 한 번 더 어두워진다. 위험·한계: :has()를 모르는 브라우저(Firefox 121 미만 등)는 이 규칙을 버리고 전처럼 띠가 남는다. 그 자리 색은 가림막의 blur(2px)를 따르지 않는 평평한 색이다. 오른쪽 drawer(placement="end")는 drawer와 창 끝 사이에 가림막 색 띠가 남는다(템플릿은 쓰지 않음, 미확인). RTL, Firefox, WebKit은 보지 않았다. 문서가 스크롤되면 그 자리의 스크롤바는 전처럼 가림막 밖이다. --hide-scrollbars로 찍는 compact 골든은 전체 페이지(1377 px)를 찍으므로, 열린 modal 동안 어두워진 root 배경이 창 높이(844 px) 아래의 오른쪽 15 px 띠에도 보인다. 실제 브라우저에서 그 부분은 스크롤바 아래에 있다. compact 골든 1장은 desktop에서 다시 찍었다(test:visual:update). 바뀐 것은 x 375~390 띠가 높이 전체에서 가림막 색이 된 것뿐이다. 나머지 골든 4장은 바뀌지 않았다(body와 root가 같은 색). 레이아웃은 바꾸지 않았다. 검증: desktop batch에서 확인. corepack pnpm test:visual tests/visual/scrollbar-gutter.visual.spec.ts corepack pnpm test:visual:update 뒤 corepack pnpm test:visual node scripts/r5-15-scrollbar.mjs 3 <out.json> (15-R3, 첫 화면 shift 0 유지) Refs: 1106/08-03
166 lines
6.2 KiB
TypeScript
166 lines
6.2 KiB
TypeScript
import { fileURLToPath } from "node:url";
|
|
|
|
import {
|
|
expect,
|
|
test,
|
|
type Page,
|
|
} from "../support/browser/strict-browser-test.ts";
|
|
import { KO_MESSAGES } from "../../src/presentation/i18n/catalog.ts";
|
|
|
|
/**
|
|
* 1106/08-03. `scrollbar-gutter: stable` (base.css, 1105/15-05) keeps a
|
|
* classic scrollbar's strip on the right even when the page does not scroll.
|
|
* Only the root background paints that strip; the page and every fixed box,
|
|
* the modal `::backdrop` included, end at its left edge. The goldens run with
|
|
* Playwright's `--hide-scrollbars`, so this spec starts Chromium with the
|
|
* scrollbar most Windows and Linux desktops draw and reads the drawn pixels.
|
|
* Hit testing is no evidence here: the strip answers `null` either way.
|
|
*/
|
|
test.use({
|
|
launchOptions: {
|
|
// `test.use` replaces the config's launchOptions whole: the font pin
|
|
// from playwright.visual.config.ts is repeated.
|
|
env: {
|
|
...process.env,
|
|
FONTCONFIG_FILE: fileURLToPath(new URL("./fonts.conf", import.meta.url)),
|
|
},
|
|
ignoreDefaultArgs: ["--hide-scrollbars"],
|
|
},
|
|
});
|
|
|
|
type Colour = readonly number[];
|
|
type Strip = Readonly<{ x: number; width: number }>;
|
|
|
|
/**
|
|
* The largest channel difference the gutter may show against the strip
|
|
* beside it. The drawer's shadow (`--shadow-dialog`, 70 px blur) still
|
|
* darkens the strip beside the gutter by about 3 levels; rounding adds 1 or
|
|
* 2. In the light theme a gutter the scrim does not cover
|
|
* (the page surface against 55% of the content colour over it) differs by
|
|
* about 120.
|
|
*/
|
|
const SAME_COLOUR = 12;
|
|
|
|
/** The mean colour of each strip, from one screenshot of the band. */
|
|
async function stripColours(
|
|
page: Page,
|
|
band: Readonly<{ y: number; height: number }>,
|
|
strips: readonly Strip[],
|
|
): Promise<Colour[]> {
|
|
const left = Math.min(...strips.map((strip) => strip.x));
|
|
const right = Math.max(...strips.map((strip) => strip.x + strip.width));
|
|
const png = await page.screenshot({
|
|
animations: "disabled",
|
|
clip: { x: left, y: band.y, width: right - left, height: band.height },
|
|
scale: "css",
|
|
});
|
|
// Decoded in a blank page, so the page under test runs nothing extra.
|
|
const decoder = await page.context().newPage();
|
|
try {
|
|
return await decoder.evaluate(
|
|
async ({ base64, offsets }) => {
|
|
const bytes = Uint8Array.from(atob(base64), (character) =>
|
|
character.charCodeAt(0),
|
|
);
|
|
const bitmap = await createImageBitmap(
|
|
new Blob([bytes], { type: "image/png" }),
|
|
);
|
|
const canvas = new OffscreenCanvas(bitmap.width, bitmap.height);
|
|
const context = canvas.getContext("2d");
|
|
if (context === null) throw new Error("no 2d canvas context");
|
|
context.drawImage(bitmap, 0, 0);
|
|
return offsets.map(({ x, width }) => {
|
|
const { data } = context.getImageData(x, 0, width, bitmap.height);
|
|
const sums = [0, 0, 0];
|
|
for (let index = 0; index < data.length; index += 4) {
|
|
for (let channel = 0; channel < 3; channel += 1) {
|
|
sums[channel] += data[index + channel];
|
|
}
|
|
}
|
|
return sums.map((sum) => Math.round(sum / (data.length / 4)));
|
|
});
|
|
},
|
|
{
|
|
base64: png.toString("base64"),
|
|
offsets: strips.map((strip) => ({ x: strip.x - left, width: strip.width })),
|
|
},
|
|
);
|
|
} finally {
|
|
await decoder.close();
|
|
}
|
|
}
|
|
|
|
async function expectGutterLikeBeside(
|
|
page: Page,
|
|
geometry: Readonly<{
|
|
band: Readonly<{ y: number; height: number }>;
|
|
beside: Strip;
|
|
gutter: Strip;
|
|
}>,
|
|
what: string,
|
|
) {
|
|
const [beside, gutter] = await stripColours(page, geometry.band, [
|
|
geometry.beside,
|
|
geometry.gutter,
|
|
]);
|
|
const difference = Math.max(
|
|
...gutter.map((value, channel) => Math.abs(value - beside[channel])),
|
|
);
|
|
// On failure, tells a rule that did not match from a colour not drawn.
|
|
const root = await page.evaluate(() => {
|
|
const style = getComputedStyle(document.documentElement);
|
|
return `${style.backgroundColor} / ${style.backgroundImage}, open dialogs ${document.querySelectorAll(".ui-dialog[open]").length}`;
|
|
});
|
|
expect(
|
|
difference,
|
|
`${what}: gutter rgb(${gutter.join(" ")}), beside it rgb(${beside.join(" ")}); root background ${root}`,
|
|
).toBeLessThanOrEqual(SAME_COLOUR);
|
|
}
|
|
|
|
test("the open drawer's scrim covers the classic scrollbar gutter on a page that does not scroll", async ({
|
|
page,
|
|
}) => {
|
|
await page.setViewportSize({ width: 390, height: 844 });
|
|
await page.goto("/not-found");
|
|
await expect(page.getByRole("heading", { level: 1 })).toHaveText(
|
|
KO_MESSAGES["page.notFound.title"],
|
|
);
|
|
|
|
const layout = await page.evaluate(() => ({
|
|
windowWidth: window.innerWidth,
|
|
windowHeight: window.innerHeight,
|
|
// With the gutter empty, documentElement.clientWidth is the window
|
|
// width (08-R2); the page's own box ends at the gutter.
|
|
pageRight: Math.round(document.body.getBoundingClientRect().right),
|
|
scrolls:
|
|
document.documentElement.scrollHeight >
|
|
document.documentElement.clientHeight,
|
|
}));
|
|
expect(layout.scrolls, "a page that scrolls draws its scrollbar in the gutter").toBe(
|
|
false,
|
|
);
|
|
expect(
|
|
layout.windowWidth - layout.pageRight,
|
|
"Chromium without --hide-scrollbars reserves a classic scrollbar's gutter",
|
|
).toBeGreaterThanOrEqual(10);
|
|
|
|
// A band at mid-height. The strip beside the gutter lies in the page's own
|
|
// padding, 5 px in from its edge so the scrim's 2 px blur stays inside it;
|
|
// the gutter strip keeps 3 px off both of its edges.
|
|
const geometry = {
|
|
band: { y: Math.round(layout.windowHeight / 2) - 20, height: 40 },
|
|
beside: { x: layout.pageRight - 10, width: 5 },
|
|
gutter: { x: layout.pageRight + 3, width: layout.windowWidth - layout.pageRight - 6 },
|
|
};
|
|
await expectGutterLikeBeside(page, geometry, "closed, the gutter shows the page surface");
|
|
|
|
const menu = page.getByRole("button", { name: KO_MESSAGES["shell.menu"], exact: true });
|
|
await menu.click();
|
|
await expect(page.locator(".ui-drawer")).toHaveJSProperty("open", true);
|
|
await expectGutterLikeBeside(page, geometry, "open, the scrim reaches the window edge");
|
|
|
|
await page.keyboard.press("Escape");
|
|
await expect(page.locator(".ui-drawer")).toHaveJSProperty("open", false);
|
|
await expectGutterLikeBeside(page, geometry, "closed again, the gutter shows the page surface");
|
|
});
|