Organism · stable · v1.0.0 · owner: Site system lead · contract 19 of 20 points (open: figma)
Do and don't
Do: The comparison
Rendered by before-after.tsOpen example: Before and after tokens · Do: The comparison Use the full-page example to follow page links.
Do: With the chain
Rendered by before-after.tsOpen example: Before and after tokens · Do: With the chain Use the full-page example to follow page links.
Don't: Claiming full automation
Rendered by before-after.tsOpen example: Before and after tokens · Don't: Claiming full automation Use the full-page example to follow page links.
Don't: Without the computed check
Rendered by before-after.tsOpen example: Before and after tokens · Don't: Without the computed check Use the full-page example to follow page links.
Rules
| Rule | Why | Check |
|---|---|---|
| Before and after tokens is computed by Loom's code from an open-source notes app's base button rule and the tokens Loom generated for it, not drawn by hand. | A showcase is proof only if the product's own code produced what it shows. | Automated: scripts/site/interactives/check.ts (recomputes the showcase data and fails on drift) |
| The match is computed in the browser, not asserted. | Only a measurement proves the look stayed the same. | Automated: tests/site/demos.spec.ts (both buttons compute the same styles) |
API
| Prop | Type | Required | Default | What it does |
|---|---|---|---|---|
lang | en | ja | No | "en" | Root interface locale; changing it requires disposal and preparation. Existing source output and static explanatory copy remain English. |
instanceKey | string | No | Optional deterministic unique key for repeated static specimens; letter first, then letters, digits, underscore or hyphen, up to64 characters. Omit for the existing singleton anchors; duplicate explicit keys are unsupported. |
Contract details
The full contract: identity, anatomy, variants, states, tokens, layout, motion, accessibility, content, tests
Identity
| Aspect | Value |
|---|---|
| Id | before-after |
| Layer | Organisms |
| Category | showcase |
| Owner | Site system lead |
| Status | stable |
| Version | 1.0.0 |
| Source | apps/showcase/site/system/organisms/before-after.ts (private repository; the contract and the render function are this one module) |
| Version | Date | Change |
|---|---|---|
| 1.0.0 | 2026-10-26 | Before and after tokens: computed by Loom's code from an open-source notes app's base button rule and the tokens Loom generated for it. |
Use when
- Shape and its demo page. Why: It proves the conversion keeps the product's look.
Do not use when
- To claim every rule converts automatically. Why: The rule shown was written from the generated tokens; the caption says so.
Anatomy
| Part | What it is |
|---|---|
| root | div.demo-ba |
| panes | Before and after code |
| preview | The two buttons with a scrubber |
| result | Computed styles comparison |
| chain | Token → semantic → primitive chain |
| caption | Sample from a real open-source app |
Made of: showcase-frame, code-block, control, caption.
Used in: pages directly.
Variants
| Variant | When | Why |
|---|---|---|
| full | On its demo page and its section. | The whole experience where the claim is made. |
States
| State | Rendered or not applicable |
|---|---|
| default | Static comparison/caption remains readable before prepared conversion data and root-local locale enhance the scrubber. |
| hover | Native range and endpoint buttons use their hover affordances. |
| focus-visible | The native comparison range and endpoint buttons show focus; keyboard changes retain their control focus. |
| active | The reader scrubs directly or selects a before/after endpoint; the one visible sweep is a motion profile, not a Play/Pause state. |
| disabled | Not applicable: The comparison has no disabled-controls state; enhancement failure leaves its static specimen. |
| loading | Required conversion data and root-local locale prepare before synchronous managed initialization; the original static comparison remains readable. |
| empty | Not applicable: Required conversion data is validated before DOM initialization; no empty comparison UI is invented. |
| error | Preparation/chunk/init failure preserves or restores the static comparison and records failed; remount may retry. Computed visual differences are comparison results, not transport failure. |
| current | Range value and aria-valuetext name Before, After or a percentage after; code/caption reflect the selected comparison. |
| visited | Not applicable: No visited state on this root; any contained native links retain their own browser history. |
| expanded | Not applicable: No disclosure state on this root; replacing a view is not aria-expanded. |
Tokens
| Part | Token |
|---|---|
| pane.ground | --term-bg |
| result.same | --teal-ink word |
| result.diff | --madder-ink word |
| --before-after-border-radius-radius | var(--radius) |
| --before-after-border-line | var(--line) |
| --before-after-gap-space-3 | var(--space-3) |
| --before-after-font-size-fs-label | var(--fs-label) |
| --before-after-gap-space-4 | var(--space-4) |
| --before-after-font-type-label | var(--type-label) |
| --before-after-color-teal-ink | var(--teal-ink) |
| --before-after-gap-space-5 | var(--space-5) |
| --before-after-font-type-small | var(--type-small) |
| --before-after-color-madder-ink | var(--madder-ink) |
| --before-after-gap-space-6 | var(--space-6) |
| --before-after-accent-color-indigo-ink | var(--indigo-ink) |
| --before-after-border-line-strong | var(--line-strong) |
| --before-after-color-ink-2 | var(--ink-2) |
| --before-after-padding-space-6 | var(--space-6) |
| --before-after-background-term-bg | var(--term-bg) |
| --before-after-color-term-fg | var(--term-fg) |
| --before-after-font-size-fs-body | var(--fs-body) |
| --before-after-background-madder-ink | var(--madder-ink) |
| --before-after-padding-space-1 | var(--space-1) |
| --before-after-background-teal-ink | var(--teal-ink) |
| --before-after-color-term-muted | var(--term-muted) |
| --before-after-padding-space-2 | var(--space-2) |
| --before-after-padding-space-7 | var(--space-7) |
| --before-after-background-sample-on | var(--sample-on) |
| --before-after-color-sample-1 | var(--sample-1) |
| --before-after-font-family-font-sample | var(--font-sample) |
| --before-after-font-size-fs-small | var(--fs-small) |
| --before-after-margin-top-space-2 | var(--space-2) |
| --before-after-scrollbar-color-term-accent | var(--term-accent) |
| --before-after-scrollbar-color-term-fg | var(--term-fg) |
Layout
| Aspect | Value |
|---|---|
| breakpoints | Required review at 390, 768, 1024 and 1440 px; execution is not implied by this declaration; columns stack under 768 px and controls fill the row on phones. |
| wrapping | Text wraps; code panes scroll inside their own focusable region. |
| textExpansion | Japanese strings come from the i18n tables and wrap; engine output stays English. |
Spacing and rhythm
| Aspect | Value |
|---|---|
| internal | Inside the Showcase frame's padding, controls and caption at its foot. |
| external | Full width of its section. |
| rhythm | One showcase per section, after the section's claim (D-SITE-008). |
Motion
| Aspect | Value |
|---|---|
| moves | One automatic sweep on first visible entry or a manual endpoint animation; direct range input follows the reader. |
| trigger | One IntersectionObserver entry at threshold0.5; native endpoint buttons or range input. |
| duration | 700ms interpolation; automatic return begins after1300ms, per the existing before-after profile. |
| easing | 1-(1-progress)^3 for endpoint interpolation; direct range input has none. |
| interruptible | Manual input cancels pending automatic return. Hidden/offscreen/live reduced preference settles the current target and cancels RAF/return timer. |
| reduced | No automatic sweep or animated interpolation; native controls remain direct. |
| why | Preserves the authored comparison and lets the reader inspect the same visual result. |
Runtime and reuse
stylesheet: /css/site.css. Built Site tokens, core and registered element CSS; preserve modes, focus and responsive rules.
stylesheet: /css/demos.css. Existing legacy demo styles where the rendered specimen uses them.
font: /fonts/. Self-hosted files referenced by Site @font-face, with licences; Japanese locale overrides remain applicable.
data: /i18n/ja.json. Required for a Japanese root; English interface fallbacks are authored in source. Root language changes require disposal and fresh preparation.
data: /data/conversion-button.json. Required first-party native source data; fetch aborts with the mount and invalid consumed fields reject before DOM initialization.
Static fallback: Original build-time specimen remains readable before loading and after chunk/initialization failure; enhancement controls retain authored hidden state.
Before DOM initialization the configured host awaits apps/showcase/site/demos/before-after.ts#prepare for this root with a mount-owned AbortSignal. Preparation must throw on missing/invalid data; disposal/replacement aborts pending work, and a stale result cannot initialize or claim ready.
Configured initializer: apps/showcase/site/demos/before-after.ts#init. The host owns transactional static-markup restoration and runtime state.
Consumer module (imports relative to the configured source root): import { createRuntimeHost } from "./src/workflows/runtime-host"; import { SITE_RUNTIMES } from "./apps/showcase/site/runtime-registry"; const definition = SITE_RUNTIMES.find(entry => entry.binding.id === "before-after"); if (!definition || definition.binding.lifecycle.kind !== "managed") throw new Error("Managed runtime binding unavailable"); const host = createRuntimeHost([definition]); export function mountRuntime(container: ParentNode) { return host.mountAll(container); }After inserting the rendered markup, call mountRuntime(container) for the container holding [data-demo="before-after"]. Retain the returned disposal function and call it before removing, replacing or remounting, including every Storybook args render. The configured host restores captured static markup/attributes on disposal or caught load/initialization failure; retry starts a fresh managed remount.
Accessibility passport
| Aspect | Value |
|---|---|
| role | region with a heading, or a figure |
| name | Its heading or caption |
| keyboard | Tab to the comparison range or endpoint buttons; native range arrows/Home/End scrub; endpoint buttons use Enter/Space. |
| focus | Reader-operated controls keep focus; no playback-control focus order is implied. |
| screenReader | The range names Before/After/percentage; the comparison result states actual computed style agreement. |
| contrast | Ink on surface 14:1; state dyes only as marks with words. |
| target | Controls are 44 px. |
Content
| Slot | Length | Voice |
|---|---|---|
| caption | 2 sentences | What was compared and how |
Good: “The browser compares the computed styles of both buttons, and they match.”
Bad: “Pixel perfect, always”
Japanese: English only; the Japanese Shape page describes it.
Icons and illustrations
None: this element uses no icon or illustration of its own.
Decisions and exceptions
Usage
138 uses across the built pages (measured by npm run site:system).
Tests
| Aspect | Value |
|---|---|
| unit | tests/unit/site-system.test.ts: renders every do and don't example through the registry and checks the classes it owns |
| visual | Not yet: there are no screenshot baselines; the Library page is checked for sideways scroll at 1440 px by tests/site/system.spec.ts |
| a11y | tests/site/system.spec.ts: axe (0 serious or critical) on the element's Library page in light and dark |
| parity | scripts/site/system/check.ts: Library examples are rendered by the same render function the site imports |
Figma
not-yet: The Loom Site Figma library is the last stage of the plan; this element is not mapped yet.