Skip to content
Open
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
3 changes: 2 additions & 1 deletion docs/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ the same tasks: [explore](agents/explore.md), [install](agents/install.md),
[develop a renderer](guides/develop-a-renderer.md), the
[renderer kit guide](guides/renderer-kit.md) (including
[graphs](guides/renderer-kit-graphs.md) and
[components](guides/renderer-kit-components.md)), and the
[components](guides/renderer-kit-components.md) and
[change emphasis](guides/change-emphasis.md)), and the
[renderer SDK guide](guides/renderer-sdk.md). When you need API details, check
the [renderer kit API](reference/renderer-kit.md), the
[renderer SDK API](reference/renderer-sdk.md),
Expand Down
106 changes: 106 additions & 0 deletions docs/guides/change-emphasis.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
# Change emphasis and the checks

How a renderer shows each item's change so that the renderer checks agree with
it. It assumes the [renderer kit](renderer-kit.md).

Three renderer checks read how an item shows its change, and they pull in
different directions until you see the one rule behind them: **each item has one
emphasis, between 0 and 1, and everything that shows its change (color, status
words, a status tab) follows it.**

- **Neutral endpoints** (`neutral-endpoints`): at progress 0 and 1 every item is
painted exactly as in an unchanged comparison of that revision. The check
compares every painted part of the item, so an extra empty element counts too.
- **Change status as text** (`status-text`): with highlighting on, every change
is named in words: in the diff; after each step when animated; and, for a
renderer with side by side but no animation, at progress 0 (Before names
removals) and 1 (After names additions and changes).
- **No layout shift** (`stable-layout`): turning highlighting on or off moves or
resizes nothing, in the diff and through the transition.

The recipe:

1. **Take the emphasis from the shell.** `props.emphasis(row, id)` is the
step-scoped emphasis: the host's highlighting once a change's step begins,
and the host's highlighting directly in a held side-by-side or swipe pane.
With automatic highlighting, the default and what `neutral-endpoints` loads,
the host's highlighting is 0 at both endpoints of the animation, so the
emphasis is too; a person who turns highlighting on sees changes there, as
they asked. Use it in the diff and, if the renderer animates, everywhere.
2. **Without animated mode, use `presentedEmphasis` outside the diff.** The
checks present a side-by-side-only renderer's two panes as progress 0 and 1
with highlighting on, so its Before must name removals at progress 0, where a
step-scoped emphasis is still 0. `presentedEmphasis(row, props.highlighting)`
is the host's highlighting for every changed row; with automatic highlighting
it is 0 at the endpoints, so the item stays neutral there. The built-in
`api`, `agentic-workflows` and `runtime-policy` renderers do this.
3. **Show status only above 0.01, in room that is always there.** Draw status
words and tabs only when the emphasis is above 0.01 (the kit's components
already do). Reserve their room for every item alike, changed or not, so
showing them moves nothing. Mount a `StatusTab` in every pill, as the
`database` renderer's tags do, and let it draw nothing at 0, never only in
changed pills: its room (`.pk-status-tab-room`) is part of what the pill
paints, so mounting it only where something changed makes an endpoint differ
from an unchanged comparison. The tab hangs below the pill, so the pill is
positioned (`position: relative`) and every pill has room below it as tall as
`--pk-tab-height`, and is at least as wide as its tab (`StatusTab`'s
`measure` draws it at full width for measuring). The `database` renderer's
tags (`packages/renderers/database/src/tags.tsx`) measure and lay them out
this way. The tab is hidden from assistive technology, so the pill's
accessible name says its status too, at the same emphasis.
4. **Let emphasis change paint, never boxes.** Fade color and words with it (the
kit's `--emphasis` custom property on the item, `edgePaint` for lines); keep
borders, padding and sizes the same at every emphasis.

```tsx
import type {Entity} from '@githubnext/projections/schemas'
import type {EntityChange} from '@githubnext/projections/renderer'
import {describeChange, isChanged, presentedEmphasis} from '@githubnext/projections/kit'
import {StatusTab, type RendererProps} from '@githubnext/projections/kit/react'

type Row = EntityChange<Entity> & {label: string}

// This renderer declares comparisonModes: ['diff', 'side-by-side'], no animated.
function emphasisOf(props: RendererProps, row: Row): number {
if (!props.comparing || !isChanged(row)) return 0
return props.diff ? props.emphasis(row, row.id) : presentedEmphasis(row, props.highlighting)
}

function Pill({props, row}: {props: RendererProps; row: Row}) {
const emphasis = emphasisOf(props, row)
return (
<div className="my-pill-slot">
<button
data-entity-id={row.id}
className="my-pill"
aria-label={emphasis > 0.01 ? `${row.label}, ${describeChange(row)}` : row.label}
style={{'--emphasis': emphasis} as React.CSSProperties}
>
{row.label}
{/* In every pill: it draws nothing for an unchanged row, or at 0. */}
<StatusTab change={row} emphasis={emphasis} />
</button>
</div>
)
}
```

```css
/* Each pill keeps room for its tab below it, changed or not, so nothing moves when status appears. */
.my-pill-slot {
display: flex;
flex-direction: column;
}
.my-pill-slot::after {
content: '';
height: calc(var(--pk-tab-height) - var(--projections-border-width));
}
/* The tab hangs off the pill. */
.my-pill {
position: relative;
}
```

When `neutral-endpoints` fails, its message names the property that changed, or
the part one side draws and the other doesn't. Run just that check while you fix
it: `projections check -p <id> --scenario <id> --only neutral-endpoints`.
4 changes: 4 additions & 0 deletions docs/guides/develop-a-renderer.md
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,10 @@ These checks work on any renderer that marks entities with `data-entity-id` and
units with `data-projections-unit`, which the SDK's interaction helpers add for
you.

Neutral endpoints, change status as text and no layout shift all read how an
item shows its change; [Change emphasis and the checks](change-emphasis.md) is
the recipe that passes all three.

## 4. Test it in CI

You can run the exact same checks in Playwright inside the real host frame using
Expand Down
4 changes: 2 additions & 2 deletions docs/guides/renderer-kit.md
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,8 @@ via `client.error`), and passes `RendererProps` to your component:
- `progress`, `highlighting`, and `direction` — Current host playback position
(single extractions pass 1, 0, 1).
- `emphasis(row, id?)` — Change emphasis for a row (`stepEmphasis`): 0 until its
own step begins, then the host's highlighting (or the host's highlighting
directly inside a held pane).
step begins, then the host's highlighting (directly, in a held pane); see
[change emphasis](change-emphasis.md) for the recipe the checks hold it to.
- `schedule` — Comparison steps mapped onto the progress axis for the active
direction.
- `rendererName` — `init.projection.renderer`, useful when one bundle serves
Expand Down