diff --git a/packages/app/src/platform/dom/import-dialog.ts b/packages/app/src/platform/dom/import-dialog.ts index be54725..43a2f9b 100644 --- a/packages/app/src/platform/dom/import-dialog.ts +++ b/packages/app/src/platform/dom/import-dialog.ts @@ -1,4 +1,4 @@ -import { define, sheet } from "@nibling/web/internals"; +import { adopt, define, sheet } from "@nibling/web/internals"; import "@nibling/web/tree"; import type { TreeNode } from "@nibling/web/tree/model"; import { ImportPicker, type ImportTarget } from "../import-picker.ts"; @@ -94,7 +94,7 @@ export class ImportDialogElement extends HTMLElement { constructor() { super(); - this.#root.adoptedStyleSheets = [importSheet]; + adopt(this.#root, importSheet); this.#dialog.setAttribute("aria-labelledby", "import-title"); this.#dialog.addEventListener("cancel", (event) => { if (!this.#model || this.#model.step === "repo") return; diff --git a/packages/app/tests/grid.spec.ts b/packages/app/tests/grid.spec.ts new file mode 100644 index 0000000..34d34c7 --- /dev/null +++ b/packages/app/tests/grid.spec.ts @@ -0,0 +1,31 @@ +import { expect, test } from "@playwright/test"; + +/** + * Bars sit side by side across stacks, so one that's a pixel off its token shows as a seam where + * their borders meet. Every bar's outer height lands on the 8px grid, borders included. + */ +test("every bar's outer height is on the 8px grid", async ({ page }) => { + await page.goto("/new?reset"); + await expect(page.locator("nib-tree")).toBeVisible(); + await page.evaluate(() => (globalThis as unknown as { workbench: import("../src/shell/index.ts").Workbench }).workbench.open({ kind: "browser", input: { url: "http://localhost:3000/" } })); + await expect(page.locator("nib-browser").filter({ hasText: "Waiting for localhost:3000" })).toBeVisible(); + + const heights = await page.evaluate(() => { + const bars: Record = {}; + const walk = (root: Document | ShadowRoot) => { + for (const el of root.querySelectorAll("*")) { + const part = el.getAttribute("part")?.split(" ") ?? []; + const name = el.localName === "nib-tablist" ? "tablist" : (["chrome", "section-header", "bar"].find((p) => part.includes(p)) ?? null); + if (name && el.checkVisibility()) (bars[name] ??= []).push(el.getBoundingClientRect().height); + if (el.shadowRoot) walk(el.shadowRoot); + } + }; + walk(document); + return bars; + }); + + expect(Object.keys(heights).sort()).toEqual(["bar", "chrome", "section-header", "tablist"]); + for (const [name, values] of Object.entries(heights)) { + for (const height of values) expect(height % 8, `${name} is ${height}px`).toBe(0); + } +}); diff --git a/packages/web/src/internals.ts b/packages/web/src/internals.ts index 19f1ef1..bab4554 100644 --- a/packages/web/src/internals.ts +++ b/packages/web/src/internals.ts @@ -25,6 +25,9 @@ export function sheet(css: string): CSSStyleSheet { return result; } +/** Size tokens name outer sizes on the grid, so a border or padding never adds to a declared size. */ +const base = sheet(`:host, *, ::before, ::after { box-sizing: border-box; }`); + const adopted = new WeakMap(); const copies = new WeakMap>(); @@ -34,7 +37,7 @@ const copies = new WeakMap>(); * different one, so `define`'s `adoptedCallback` re-adopts these as copies built in the new document. */ export function adopt(root: ShadowRoot, ...sheets: CSSStyleSheet[]): void { - adopted.set(root, sheets); + adopted.set(root, [base, ...sheets]); restyle(root); }