Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/guides/develop-a-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -240,6 +240,12 @@ what broke and where), or skipped:
It trims the text's box to its capitals and baseline and pads it back to its
line height, so whatever centres it centres the capitals. Extra room goes in
`--pk-label-inset`.
- **Centred on whole pixels** — An icon, pill or mark centred in a bar, chip or
button has whole, equal gaps either side, never a half pixel (a 28px control
in a 32px row, not a 31px one). A `pk-label`'s line box is rounded up to a
whole pixel and icons are even squares, so a bar sized by them centres them on
whole pixels; size any other bar so its room around a centred box is whole and
even.
- **Legend shown once** — Render at most one legend, and omit it altogether when
the host already draws one.
- **No horizontal overflow at phone width** — The page must never scroll
Expand Down
7 changes: 4 additions & 3 deletions docs/guides/renderer-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -163,9 +163,10 @@ only the detected code spans (`identifierParts`) in monospace.
of its capitals, differently in each engine. Put a chip, bar or button's text in
its own `pk-label` (a block or flex item, in the text's own font): it trims the
box to the capitals and baseline (`text-box`) and pads it back to its line
height, so whatever centres it centres the capitals. Extra room goes in
`--pk-label-inset`; the `label-centring` renderer check holds every chip, bar
and button to it.
height, rounded up to a whole pixel, so whatever centres it centres the
capitals; with the SDK's even icons (`round(1em, 2px)`), a band sized by them
centres an icon on whole pixels (`centred-pixels`). Extra room goes in
`--pk-label-inset`; `label-centring` holds every chip, bar and button to it.

Protocol text that already marks code spans in backticks—reasons, summaries,
notices, diagnostics, and details (see
Expand Down
2 changes: 1 addition & 1 deletion packages/renderers/agentic-workflows/src/card.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ function Meta({item, diff}: {item: WorkflowItem; diff: boolean}) {
status === undefined ? undefined : (
<span className="aw-lock" data-lock={status}>
{status !== 'current' && <Icon name="warning" className="aw-icon" />}
{lockText(status)}
<span className="pk-label">{lockText(status)}</span>
</span>
)
return (
Expand Down
14 changes: 13 additions & 1 deletion packages/renderers/agentic-workflows/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,22 @@
align-items: baseline;
gap: var(--projections-space-1);
}
/* The icon is centred on the line, and the words give the lock its baseline, so it sits on the line around it. */
/* In a line of prose, the icon is centred on the line, and the words give the lock its baseline. */
.aw-lock > .pk-icon {
align-self: center;
}
/*
* In a pill the lock is the label: its words are one (`pk-label`), and its icon centres beside them, both on whole
* pixels, so the pill's own label holds the lock's box rather than trimming a line around it.
*/
.pk .pk-pill-label.pk-label:has(> .aw-lock) {
display: flex;
text-box: none;
padding-block: 0;
}
.pk-pill-label > .aw-lock {
align-items: center;
}
.aw-lock:not([data-lock='current']) {
color: var(--text);
font-weight: var(--projections-font-weight-semibold);
Expand Down
9 changes: 9 additions & 0 deletions packages/renderers/database/src/styles.css
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,15 @@
.database-glyph .pk-status-text {
gap: 0;
}
/*
* A row's status icon is odd, its name's size (13px): a row is 32px, its top rule takes one, and an icon centres on
* whole pixels only in room whose leftover is even, so in the 31px under the rule an even icon would sit a half pixel
* off. Rows keep their 32px rhythm.
*/
.database-column .database-glyph .pk-icon {
width: calc(round(nearest, 1em, 2px) + 1px);
height: calc(round(nearest, 1em, 2px) + 1px);
}
.database-row {
cursor: pointer;
}
Expand Down
52 changes: 51 additions & 1 deletion packages/renderers/harness/browser/labels.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import {expect, test} from '@playwright/test'
import {openStage, type OffCentreLabel} from '@githubnext/projections-renderer-testing/playwright'
import {openStage, type OffCentreLabel, type OffPixelChild} from '@githubnext/projections-renderer-testing/playwright'
import {harnessInspector} from '@githubnext/projections-renderer-harness/playwright'
import {scenarios} from './scenarios.js'

Expand Down Expand Up @@ -94,3 +94,53 @@ test('a label of mixed prose keeps the UI font around its code', async ({page},
expect(notes.length).toBeGreaterThan(0)
expect(new Set(notes)).toEqual(new Set([fonts.ui]))
})

/**
* Centred on whole pixels: a label's line box is rounded up to a whole pixel and icons are even squares, so
* a band's icon centres at whole gaps. Undone (a 13px icon, a 19.5px line), the probe finds it off them.
*/
test('the centred-pixels probe finds an icon a half pixel off in its band, and none with even room', async ({page}, info) => {
test.skip(info.project.name !== 'chromium-desktop', 'One engine shows the probe works; the checks run in every one.')
const stage = await openStage(page, harnessInspector(), {scenario: 'runtime-policy/deployment', progress: 1, comparisonMode: 'diff'})
await stage.measure('settle')
expect(await stage.measure<OffPixelChild[]>('pixels')).toEqual([])
await stage.frame.locator('head').evaluate(head => {
const style = document.createElement('style')
style.textContent =
'.pk [data-icon] { width: 1em !important; height: 1em !important } .pk .pk-label.pk-label { min-height: calc(1lh + 2 * var(--pk-label-inset, 0px)) !important; padding-block: calc((1lh - 1cap) / 2 - 0.5px + var(--pk-label-inset, 0px)) !important }'
head.append(style)
})
await stage.measure('settle')
const found = (await stage.measure<OffPixelChild[]>('pixels')).map(child => `${child.element} in ${child.holder}`)
expect(found).toEqual(expect.arrayContaining([expect.stringMatching(/^span\.pk-icon in header\.pk-group-header/u)]))
})

/**
* What the centred-pixels probe holds and how it measures: an image is a box though it's inline; a box inside an
* invisible container isn't seen; a collapsed table cell's room is inside half of each rule it shares, the one under it
* drawn by the cell below it, not the next row's widest.
*/
test('the centred-pixels probe sees inline images, skips invisible boxes and measures collapsed cells inside half their rules', async ({
page,
}, info) => {
test.skip(info.project.name !== 'chromium-desktop', 'One engine shows the probe works; the checks run in every one.')
const stage = await openStage(page, harnessInspector(), {scenario: 'runtime-policy/deployment', progress: 1, comparisonMode: 'diff'})
await stage.measure('settle')
await stage.frame.locator('body').evaluate(body => {
const fixture = document.createElement('div')
const square = (size: number, name: string) =>
`<span class="${name}" style="display:block;margin:auto;width:${size}px;height:${size}px;background:#333"></span>`
const cell = (style: string, content = '') => `<td style="border:1px solid #888;padding:0;${style}">${content}</td>`
fixture.innerHTML = `
<div style="opacity:0"><div style="display:flex;align-items:center;width:32px;height:32px;background:#eee">${square(13, 'px-hidden')}</div></div>
<div style="width:32px;height:32px;background:#eee;text-align:center;line-height:0"><img class="px-image" width="13" height="13" src="data:image/gif;base64,R0lGODlhAQABAAAAACw="></div>
<table style="border-collapse:collapse;border-spacing:0">
<tr>${cell('width:32px;height:33px', square(14, 'px-cell'))}${cell('width:32px;height:33px')}</tr>
<tr>${cell('height:8px')}${cell('height:8px;border-top-width:3px')}</tr>
</table>`
fixture.style.cssText = 'position:absolute;top:0;left:0;z-index:10;background:#fff'
body.append(fixture)
})
const found = (await stage.measure<OffPixelChild[]>('pixels')).map(child => `${child.element} ${child.axis}`)
expect(found).toEqual(['img.px-image horizontal'])
})
11 changes: 4 additions & 7 deletions packages/renderers/kit/styles/layout.css
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@
.pk .pk-group-title {
display: flex;
flex: 0 1 auto;
align-items: baseline;
align-items: center;
gap: var(--projections-space-1);
min-width: 0;
margin: 0 0 0 calc(-1 * var(--projections-space-1));
Expand All @@ -111,18 +111,15 @@
*/
/*
* The subject's icon leads the title, muted, at the band's inset (cancelling the heading's negative margin), so it
* lines up with the cells under it and the title follows it. Its box is a line in the title's font, so it sits on the
* title's baseline; the icon is lowered from the baseline by half the difference between its square and the cap
* height, so it is centred on the capitals.
* lines up with the cells under it and the title follows it. The title centres it with its words, which are labels
* (`pk-label`) centred on their capitals, so it is centred on the capitals, on whole pixels in the band.
*/
.pk .pk-group-icon {
display: flex;
flex: none;
margin-inline-start: var(--projections-space-1);
color: var(--muted);
}
.pk .pk-group-icon > [data-icon] {
vertical-align: calc(0.5cap - 0.5em);
}
.pk .pk-group-label {
flex: 0 1 auto;
padding: var(--projections-space-1);
Expand Down
11 changes: 6 additions & 5 deletions packages/renderers/kit/styles/status.css
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,22 @@
}
/*
* A label centred on its capitals: its text box trimmed to the capitals' top and the baseline, then padded back to its
* line height, so it keeps its size and whatever centres it (a flex row, a pill's line) centres the capitals: a capital
* E has as much room above it as below. Put it on the element holding the text, a block or a flex item (an inline box
* line height, rounded up to a whole pixel, so whatever centres it (a flex row, a pill's line) centres the
* capitals: a capital E has as much room above it as below, and the box it sizes (a pill, a band) is whole, so an
* even icon beside it centres on whole pixels too where the room around it is even. Put it on the element holding the text, a block or a flex item (an inline box
* isn't trimmed). It owns its block padding (the doubled class outweighs a component's own padding); room of its own
* goes in `--pk-label-inset`. Without `text-box` it is an ordinary line.
*/
@supports (text-box: trim-both cap alphabetic) {
.pk .pk-label.pk-label {
text-box: trim-both cap alphabetic;
/*
* Its box is its line height exactly, whatever capitals the engine trims to and however it rounds the padding: at
* Its box is its line height, rounded up to a whole pixel, exactly, whatever capitals the engine trims to and however it rounds the padding: at
* least that tall, its text centred in it, padded half a pixel short of centring it alone so it never grows past it.
*/
box-sizing: border-box;
min-height: calc(1lh + 2 * var(--pk-label-inset, 0px));
padding-block: calc((1lh - 1cap) / 2 - 0.5px + var(--pk-label-inset, 0px));
min-height: calc(round(up, 1lh, 1px) + 2 * var(--pk-label-inset, 0px));
padding-block: calc((round(up, 1lh, 1px) - 1cap) / 2 - 0.5px + var(--pk-label-inset, 0px));
align-content: center;
}
}
Expand Down
3 changes: 3 additions & 0 deletions packages/renderers/sdk/icons.css
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,9 @@
flex: none;
width: 1em;
height: 1em;
/* An even square, so it centres on whole pixels in a whole, even box (a 13px font's icon is 14px). */
width: round(nearest, 1em, 2px);
height: round(nearest, 1em, 2px);
vertical-align: -0.125em;
background-color: currentColor;
-webkit-mask: var(--projections-icon) center / contain no-repeat;
Expand Down
7 changes: 7 additions & 0 deletions packages/renderers/testing/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,13 @@ Build the bundle before the tests. The checks:
number beside a wrapped line), aren't labels. The kit's `pk-label` passes it.
A box with text in several sizes is centred on its main text, its largest
capitals. Checked at full width in the diff (or the extraction).
- `centred-pixels`: A painted box centred in a bar, chip or button (an icon, a
pill, a mark) sits at equal, whole-pixel gaps either side; a half pixel either
side, or one more on one side, is drawn unevenly once snapped. Room is whole
and even with the kit's `pk-label` (its line box is rounded up to a whole
pixel) and the SDK's even icons. Measured on painted HTML boxes centred within
a pixel in their nearest painted ancestor up to 48 px across, with up to 16 px
either side; a collapsed table rule counts half to each cell.
- `link-routes`: Every link a renderer routes between cards (marked
`data-projections-route`) goes around the cards in its way. When none can, the
renderer draws the route that overlaps them least, marks it
Expand Down
3 changes: 3 additions & 0 deletions packages/renderers/testing/src/checks/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ export const checkTitles: Record<CheckId, string> = {
'nested-accents': 'No change colors inside change colors',
'frame-edges': 'Rounded edges drawn over what fills their corners',
'label-centring': 'Labels centred on their capitals',
'centred-pixels': 'Centred on whole pixels',
'link-routes': 'Links routed around cards',
}

Expand Down Expand Up @@ -141,6 +142,8 @@ export const checkDescriptions: Record<CheckId, string> = {
"A box with rounded corners and an edge (a border, or an outline inside it) whose painted contents reach a corner draws its edge over them: as the kit's frame (`pk-frame`, or a `Group`, which draws its border again above its contents), or as an outline its contents sit under. Where a fill's curve meets the edge's, whichever is painted last dilutes the other's antialiased pixels, so an edge painted first comes out thinner around the curve than along its sides, even where the fill follows the inner radius. A kit frame's `::after` is that edge: a renderer's rule may recolor it, but one that draws there (content, a fill, a size) fails, as its drawing loses to the kit's or moves the edge.",
'label-centring':
"A chip, bar or button's text is centred on its capitals: a capital E has as much room above it as below it, within half a pixel. A line of text centred by its line height sits a little high or low, by how its font's ascent, descent and cap height compare; the kit's `pk-label` trims the text's box to its capitals and baseline and pads it back to its line height, so whatever centres the box centres the capitals. Measured from the font's metrics on every HTML element up to 48px tall that paints a background (or edges above and below) under one line of its own text, by its main text (its largest font size); text in SVG is not checked. Checked at full width in the light theme.",
'centred-pixels':
"A painted box centred in a bar, chip or button (an icon, a pill, a mark) sits at equal, whole-pixel gaps either side: a half pixel either side, or a pixel more on one side, is drawn unevenly once snapped to device pixels. A box centres on whole pixels in whole, even room: the kit's `pk-label` gives a label a whole line box, and icons are even squares. Measured on every painted HTML box centred, within a pixel, in its nearest painted ancestor at most 48px across that way, with at most 16px either side; a collapsed table rule counts half to each cell. Checked at full width in the diff (or the extraction).",
'link-routes':
'Every link a renderer routes between cards (marked data-projections-route) goes around the cards in its way. When no route around them exists, the renderer draws the one that overlaps them least and marks it data-projections-route="crossing", naming the cards in data-projections-route-crosses, and this check reports it. Checked at full width in the diff and at the end of the animation; skipped for a renderer that routes no links.',
}
Expand Down
20 changes: 18 additions & 2 deletions packages/renderers/testing/src/checks/labels.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
// The check that a chip, bar or button centres its text on its capitals (probe call `labels`).
import type {OffCentreLabel} from '../types.js'
import type {OffCentreLabel, OffPixelChild} from '../types.js'
import {limit, primaryMode, type Checks} from './support.js'

export const labelChecks: Pick<Checks, 'label-centring'> = {
export const labelChecks: Pick<Checks, 'label-centring' | 'centred-pixels'> = {
async 'label-centring'(driver, subject, {modes}) {
await driver.load(subject, {progress: 1, ...primaryMode(subject, modes)})
await driver.measure('settle')
Expand All @@ -18,4 +18,20 @@ export const labelChecks: Pick<Checks, 'label-centring'> = {
const lines = [...failures.values()].map(({line, count}) => (count > 1 ? `${line} (${count} like it)` : line))
return lines.length > limit ? [...lines.slice(0, limit), `… and ${lines.length - limit} more.`] : lines
},

async 'centred-pixels'(driver, subject, {modes}) {
await driver.load(subject, {progress: 1, ...primaryMode(subject, modes)})
await driver.measure('settle')
const failures = new Map<string, {line: string; count: number}>()
for (const {element, holder, axis, before, after} of await driver.measure<OffPixelChild[]>('pixels')) {
const sides = axis === 'vertical' ? ['above', 'below'] : ['left', 'right']
const line = `${element} sits ${before}px ${sides[0]} and ${after}px ${sides[1]} in ${holder}: centre it on whole pixels, in whole, even room (the kit's \`pk-label\` and even icons)`
const key = line.replaceAll(/\[data-entity-id="[^"]*"\]/gu, '').replaceAll(/[\d.]+px/gu, '')
const found = failures.get(key)
if (found) found.count += 1
else failures.set(key, {line, count: 1})
}
const lines = [...failures.values()].map(({line, count}) => (count > 1 ? `${line} (${count} like it)` : line))
return lines.length > limit ? [...lines.slice(0, limit), `… and ${lines.length - limit} more.`] : lines
},
}
1 change: 1 addition & 0 deletions packages/renderers/testing/src/measure.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export {nestedAccents} from './measure/accents.js'
export {coveredFrames} from './measure/frames.js'
export {claimedOverlays} from './measure/frames/claimed.js'
export {offCentreLabels} from './measure/labels.js'
export {offPixelChildren} from './measure/pixels.js'
export {linkRoutes} from './measure/routes.js'
25 changes: 20 additions & 5 deletions packages/renderers/testing/src/measure/labels.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,22 @@ function surfaceOf(element: Element, root: Element): HTMLElement | undefined {
return undefined
}

/** The columns a table cell covers, from its row's cells before it (a cell spanning rows from above isn't counted). */
function columns(cell: HTMLTableCellElement): [number, number] {
let start = 0
for (const before of cell.parentElement instanceof HTMLTableRowElement ? cell.parentElement.cells : []) {
if (before === cell) break
start += before.colSpan
}
return [start, start + cell.colSpan]
}

/**
* A surface's inner top and bottom: inside its borders, or in a table that collapses them, inside half of each rule
* (which straddles the cells' edge), the one under it drawn by the cell below.
* (which straddles the cells' edge), the one under it drawn by the cells below it, in the next row of the table
* (another section's first included); the table's last row has no rule under it.
*/
function innerEdges(surface: HTMLElement, box: DOMRect, scale = 1): {top: number; bottom: number} {
export function innerEdges(surface: HTMLElement, box: DOMRect, scale = 1): {top: number; bottom: number} {
const style = getComputedStyle(surface)
// Borders are laid out widths; the box is drawn, scaled.
const width = (value: string) => px(value) * scale
Expand All @@ -43,9 +54,13 @@ function innerEdges(surface: HTMLElement, box: DOMRect, scale = 1): {top: number
if (!(surface instanceof HTMLTableCellElement) || !table || getComputedStyle(table).borderCollapse !== 'collapse') {
return {top: box.top + top, bottom: box.bottom - bottom}
}
const next = surface.parentElement?.nextElementSibling
const under = next instanceof HTMLTableRowElement ? next.cells[surface.cellIndex] : undefined
return {top: box.top + top / 2, bottom: box.bottom - Math.max(bottom, under ? width(getComputedStyle(under).borderTopWidth) : 0) / 2}
const row = surface.parentElement
const next = row instanceof HTMLTableRowElement && table instanceof HTMLTableElement ? table.rows[row.rowIndex + 1] : undefined
// The rule under it, from the next row's cells over its columns: one may span them (a section's title).
const [from, to] = columns(surface)
const below = next ? [...next.cells].filter(cell => columns(cell)[0] < to && columns(cell)[1] > from) : []
const under = Math.max(0, ...below.map(cell => width(getComputedStyle(cell).borderTopWidth)))
return {top: box.top + top / 2, bottom: box.bottom - Math.max(bottom, under) / 2}
}

/**
Expand Down
Loading
Loading