# Shortcut sheet (Notchset): prompt.md (v1.2.0)

- id: `shortcut-sheet` · version 1.2.0 · component · free
- category: Overlays
- build: one set of files for every shadcn style
- install: `npx shadcn@latest add https://notchset.dev/r/shortcut-sheet.json`
- npm dependencies: none
- registry dependencies: utils, https://notchset.dev/r/notchset-foundation.json, @notchset/dialog, @notchset/keyboard-hint, @notchset/search-field
- docs: https://notchset.dev/components/shortcut-sheet
- The install command carries everything this item needs (files, CSS, tokens, npm and registry dependencies). Prefer it to copying source by hand.

The app's keys in their groups, fed by its own key map so it prints only keys that work. It opens with ? anywhere and ⌘/ inside a field; a find field filters it as you type, and pressing a key while the list has focus lights its row..

## Build it
- Stack: React 18.3 or 19, TypeScript, Tailwind CSS v4 utility classes on the foundation's roles, a components.json (imports use its aliases).
- Packages: none beyond `react` and `react-dom`.
- Files: `components/ui/notchset/shortcut-sheet.tsx`, `components/ui/notchset/key-cap-parts.tsx`; shared code: `lib/notchset/controllable.ts`, `lib/notchset/hit-area.ts`, `lib/notchset/layers.ts`, `lib/notchset/words.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`, `dialog`, `keyboard-hint`, `search-field`.
- Builds: one set of files, the same for every shadcn style.
- Exports to keep: `printChord`, `RESERVED_CHORDS`, `SHORTCUT_RECORDER_LABELS`, `SHORTCUT_SHEET_LABELS`, `ShortcutRecorder`, `ShortcutSheet`, `sayChord`, `useShortcutSheetKeys`, `asCtrl`, `capsOf`, `hintProps`, `isApple`, `KEY_CAP_LABELS`, `keyCap`, `keyCapTone`, `KeyCaps`, and every exported type.
- CSS: the install adds the notchset foundation (its roles, keyframes and motion switch, reading your shadcn tokens for colour) to your global stylesheet once. Nothing to import by hand.
- Re-running `add` (or `--overwrite`) re-applies those rules: put overrides in your own CSS, never in the installed rules.
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- This item reads `--ns-bad-ink`, `--ns-btn-ok`, `--ns-canvas`, `--ns-corner`, `--ns-ease`, `--ns-ease-arrive`, `--ns-ease-press`, `--ns-ease-spring`, `--ns-field`, `--ns-font-body`, `--ns-font-mono`, `--ns-hover`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-layer-bar`, `--ns-layer-modal`, `--ns-layer-panel`, `--ns-layer-popup`, `--ns-layer-sticky`, `--ns-layer-tip`, `--ns-layer-toast`, `--ns-line`, `--ns-line-soft`, `--ns-panel`, `--ns-press-min`, `--ns-radius`, `--ns-radius-lg`, `--ns-radius-sm`, `--ns-radius-xs`, `--ns-raised`, `--ns-selected`, `--ns-signal`, `--ns-text-body`, `--ns-text-meta`, `--ns-text-small`, `--ns-time-born`, `--ns-time-color`, `--ns-time-menu`, `--ns-time-quick`, `--ns-time-spring`, `--ns-weight-medium`, `--ns-weight-strong`.
- Retune it (on any ancestor) with the foundation's roles and hooks: `--ns-agent-b`, `--ns-agent-c`, `--ns-agent-d`, `--ns-agent-drift`, `--ns-agent-fill`, `--ns-agent-h1`, `--ns-agent-h2`, `--ns-agent-h3`, `--ns-agent-shift`, `--ns-avatar-card`, `--ns-avatar-lg`, `--ns-avatar-md`, `--ns-avatar-sm`, `--ns-avatar-xs`, `--ns-bad`, `--ns-bad-ink`, `--ns-band`, `--ns-band-edge`, `--ns-band-grade`, `--ns-band-optimal`, `--ns-banner-beat`, `--ns-banner-radius`, `--ns-beat`, `--ns-beat-ease`, `--ns-bezel`, `--ns-bloom-close`, `--ns-bloom-open`, `--ns-bloom-rise`, `--ns-btn-bad`, `--ns-btn-bad-hover`, `--ns-btn-bad-line`, `--ns-btn-bezel`, `--ns-btn-chosen`, `--ns-btn-gone`, `--ns-btn-morph`, `--ns-btn-ok`, `--ns-btn-press`, `--ns-btn-release`, `--ns-btn-result`, `--ns-btn-roll`, `--ns-btn-stagger`, `--ns-btn-stagger-step`, `--ns-btn-tick`, `--ns-btn-tonal`, `--ns-btn-tonal-edge`, `--ns-btn-tonal-hover`, `--ns-bulk-clear`, `--ns-button`, `--ns-button-field-inset`, `--ns-button-lg`, `--ns-button-sm`, `--ns-canvas`, `--ns-card-tilt`, `--ns-cat-1`, `--ns-cat-2`, `--ns-cat-3`, `--ns-cat-4`, `--ns-cat-5`, `--ns-cat-6`, `--ns-check`, `--ns-check-round`, `--ns-cheer-1`, `--ns-cheer-2`, `--ns-cheer-3`, `--ns-cheer-edge`, `--ns-cheer-fold`, `--ns-cheer-glow`, `--ns-cheer-lift`, `--ns-chip`, `--ns-chip-pick`, `--ns-control`, `--ns-control-lg`, `--ns-control-pad`, `--ns-control-sm`, `--ns-corner`, `--ns-danger`, `--ns-deep`, `--ns-deep-ink`, `--ns-deep-ink-2`, `--ns-deep-line`, `--ns-depth-card`, `--ns-depth-lift`, `--ns-depth-surface`, `--ns-dialog`, `--ns-dialog-grow`, `--ns-dialog-lg`, `--ns-dialog-max`, `--ns-dialog-shrink`, `--ns-dialog-sm`, `--ns-dialog-top`, `--ns-dock-bottom`, `--ns-drop`, `--ns-ease`, `--ns-ease-arrive`, `--ns-ease-breathe`, `--ns-ease-drum`, `--ns-ease-exit`, `--ns-ease-fling`, `--ns-ease-glide`, `--ns-ease-grow`, `--ns-ease-move`, `--ns-ease-panel`, `--ns-ease-pop`, `--ns-ease-press`, `--ns-ease-spring`, `--ns-ebg-arm`, `--ns-ebg-lit`, `--ns-emoji`, `--ns-emoji-md`, `--ns-emoji-sm`, `--ns-field`, `--ns-field-edge`, `--ns-field-h`, `--ns-fill`, `--ns-fill-time`, `--ns-flood-arc`, `--ns-flood-aurora`, `--ns-flood-behind-1`, `--ns-flood-behind-2`, `--ns-flood-bloom`, `--ns-flood-deep`, `--ns-flood-dial-bloom`, `--ns-flood-glass`, `--ns-flood-grain`, `--ns-flood-image`, `--ns-flood-ink`, `--ns-flood-ink-low`, `--ns-flood-light`, `--ns-flood-mid`, `--ns-flood-pale`, `--ns-flood-pane`, `--ns-flood-pane-edge`, `--ns-flood-pill-ink`, `--ns-flood-ribbon`, `--ns-flood-ribbon-core`, `--ns-flood-shadow`, `--ns-flood-sheen`, `--ns-flood-wash`, `--ns-font-body`, `--ns-font-display`, `--ns-font-mono`, `--ns-font-script`, `--ns-glass`, `--ns-glass-blur`, `--ns-glass-shadow`, `--ns-glow`, `--ns-glyph-pad`, `--ns-grain`, `--ns-gutter`, `--ns-header`, `--ns-help-max`, `--ns-hit`, `--ns-hover`, `--ns-icon`, `--ns-icon-lg`, `--ns-icon-sm`, `--ns-icon-stroke`, `--ns-info`, `--ns-info-ink`, `--ns-ink`, `--ns-ink-2`, `--ns-ink-3`, `--ns-ink-4`, `--ns-layer-bar`, `--ns-layer-modal`, `--ns-layer-panel`, `--ns-layer-popup`, `--ns-layer-sticky`, `--ns-layer-tip`, `--ns-layer-toast`, `--ns-layer-zoom`, `--ns-lead-body`, `--ns-lead-figure`, `--ns-lead-large`, `--ns-lead-meta`, `--ns-lead-small`, `--ns-lead-sub`, `--ns-lead-title`, `--ns-leading`, `--ns-leading-prose`, `--ns-leading-title`, `--ns-lift`, `--ns-light-1`, `--ns-light-2`, `--ns-light-3`, `--ns-light-spread`, `--ns-light-strength`, `--ns-line`, `--ns-line-soft`, `--ns-lit-edge`, `--ns-map-grass`, `--ns-map-water`, `--ns-mark-edge`, `--ns-mark-lifted`, `--ns-mark-rest`, `--ns-mark-swap`, `--ns-marker`, `--ns-marker-ink`, `--ns-mc-place`, `--ns-mc-roll`, `--ns-measure`, `--ns-menu-dy`, `--ns-menu-lit`, `--ns-menu-pad`, `--ns-menu-row`, `--ns-menu-rule`, `--ns-mesh`, `--ns-mesh-frost`, `--ns-nest-inset`, `--ns-nest-outer`, `--ns-nest-r`, `--ns-notch-ease`, `--ns-ok`, `--ns-ok-ink`, `--ns-on-fill`, `--ns-orb-body`, `--ns-orb-cool`, `--ns-orb-core`, `--ns-orb-dawn`, `--ns-orb-deep`, `--ns-orb-edge`, `--ns-orb-grain`, `--ns-orb-ground`, `--ns-orb-halo`, `--ns-orb-inner`, `--ns-orb-key`, `--ns-orb-lift`, `--ns-orb-limb`, `--ns-orb-limb-from`, `--ns-orb-rim`, `--ns-orb-skin-hi`, `--ns-orb-skin-lo`, `--ns-orb-skin-mid`, `--ns-orb-warm`, `--ns-palette-min`, `--ns-panel`, `--ns-panel-room`, `--ns-panel-w`, `--ns-panel-w-lg`, `--ns-pick-slot`, `--ns-pill-prop`, `--ns-play-fill`, `--ns-play-fill-color`, `--ns-play-lift`, `--ns-play-lift-y`, `--ns-play-open`, `--ns-play-open-content`, `--ns-play-press`, `--ns-play-press-box`, `--ns-play-reduced`, `--ns-play-ring`, `--ns-play-roll`, `--ns-play-shake`, `--ns-play-spring`, `--ns-play-swap`, `--ns-play-swap-blur`, `--ns-press-min`, `--ns-press-scale`, `--ns-press-x`, `--ns-press-y`, `--ns-primary-hover`, `--ns-primary-press`, `--ns-prism-edge`, `--ns-prism-glint`, `--ns-prism-sheen`, `--ns-prism-tint`, `--ns-pulse`, `--ns-radius`, `--ns-radius-2xl`, `--ns-radius-button`, `--ns-radius-button-lg`, `--ns-radius-button-sm`, `--ns-radius-card`, `--ns-radius-check`, `--ns-radius-control`, `--ns-radius-control-sm`, `--ns-radius-float`, `--ns-radius-full`, `--ns-radius-lg`, `--ns-radius-mark`, `--ns-radius-menu-row`, `--ns-radius-modal`, `--ns-radius-pill`, `--ns-radius-sm`, `--ns-radius-xl`, `--ns-radius-xs`, `--ns-raised`, `--ns-ramp-1`, `--ns-ramp-2`, `--ns-ramp-3`, `--ns-ramp-4`, `--ns-ramp-5`, `--ns-ramp-shine`, `--ns-range`, `--ns-rest-1`, `--ns-rest-2`, `--ns-rest-3`, `--ns-rise`, `--ns-row`, `--ns-row-compact`, `--ns-row-hue`, `--ns-scrim`, `--ns-search-h`, `--ns-segment`, `--ns-segment-inset`, `--ns-segment-lift`, `--ns-segment-sm`, `--ns-selected`, `--ns-series`, `--ns-series-core`, `--ns-series-glint`, `--ns-series-tint`, `--ns-shadow-dialog`, `--ns-shadow-float`, `--ns-shadow-lift`, `--ns-shadow-panel`, `--ns-sheet`, `--ns-sheet-back`, `--ns-sheet-bottom`, `--ns-sheet-drop`, `--ns-sheet-rise`, `--ns-shift`, `--ns-side`, `--ns-signal`, `--ns-signal-ink`, `--ns-signal-wash`, `--ns-sk-figure`, `--ns-sk-land`, `--ns-sk-p`, `--ns-sk-p0`, `--ns-sk-p1`, `--ns-sk-p2`, `--ns-sk-p3`, `--ns-sk-p4`, `--ns-sk-p5`, `--ns-sk-p6`, `--ns-sk-p7`, `--ns-sk-read`, `--ns-sk-sweep`, `--ns-skeleton`, `--ns-skeleton-bone`, `--ns-skeleton-bone-light`, `--ns-skeleton-light`, `--ns-slab`, `--ns-slab-edge`, `--ns-slab-ink`, `--ns-sleep-awake`, `--ns-sleep-deep`, `--ns-sleep-light`, `--ns-sleep-rem`, `--ns-space-1`, `--ns-space-2`, `--ns-space-3`, `--ns-space-4`, `--ns-space-5`, `--ns-space-6`, `--ns-space-8`, `--ns-space-section`, `--ns-stack-fan`, `--ns-stack-fan-gap`, `--ns-stack-fan-lag`, `--ns-stack-on`, `--ns-stagger-item`, `--ns-stagger-mark`, `--ns-stagger-max`, `--ns-standing-critical`, `--ns-standing-in`, `--ns-standing-out`, `--ns-state-doing`, `--ns-state-done`, `--ns-state-review`, `--ns-state-todo`, `--ns-step`, `--ns-step-from`, `--ns-step-sign`, `--ns-swipe-surface`, `--ns-switch-h`, `--ns-switch-w`, `--ns-text-body`, `--ns-text-control`, `--ns-text-control-lg`, `--ns-text-display`, `--ns-text-editorial`, `--ns-text-empty`, `--ns-text-figure`, `--ns-text-giant`, `--ns-text-heading`, `--ns-text-headline`, `--ns-text-input`, `--ns-text-large`, `--ns-text-lede`, `--ns-text-meta`, `--ns-text-record`, `--ns-text-sentence`, `--ns-text-small`, `--ns-text-sub`, `--ns-text-title`, `--ns-theme-fade`, `--ns-tile-shadow`, `--ns-time-born`, `--ns-time-color`, `--ns-time-confirm`, `--ns-time-dialog`, `--ns-time-fling`, `--ns-time-flip`, `--ns-time-glide`, `--ns-time-grow`, `--ns-time-hold`, `--ns-time-menu`, `--ns-time-page`, `--ns-time-panel`, `--ns-time-quick`, `--ns-time-roll`, `--ns-time-settle`, `--ns-time-snap`, `--ns-time-spin`, `--ns-time-spring`, `--ns-time-sweep`, `--ns-time-toast`, `--ns-tint`, `--ns-tint-c`, `--ns-tint-ease`, `--ns-tint-fill`, `--ns-tint-gap`, `--ns-tint-h1`, `--ns-tint-h2`, `--ns-tint-h3`, `--ns-tint-ink`, `--ns-tint-row`, `--ns-tip-fold`, `--ns-tip-grow`, `--ns-toast-bottom`, `--ns-toast-gap`, `--ns-toast-left`, `--ns-toast-lift`, `--ns-toast-peek`, `--ns-toast-scale`, `--ns-toast-w`, `--ns-touch`, `--ns-tracking-body`, `--ns-tracking-caps`, `--ns-tracking-control`, `--ns-tracking-display`, `--ns-tracking-headline`, `--ns-tracking-sub`, `--ns-tracking-title`, `--ns-warn`, `--ns-warn-ink`, `--ns-wash-clay`, `--ns-wash-dusk`, `--ns-wash-graphite`, `--ns-wash-ink`, `--ns-wash-sage`, `--ns-wash-sand`, `--ns-weight-light`, `--ns-weight-medium`, `--ns-weight-regular`, `--ns-weight-strong`, `--ns-well`, `--ns-width-lg`, `--ns-width-md`, `--ns-width-sm`, `--ns-width-xl`.
- Never add Tailwind colour classes inside the component.

```tsx
import { Button } from "@/components/ui/notchset/button";
```

## Parts
- A single export that takes props.

## Match the original
- Read `components/ui/notchset/shortcut-sheet.tsx`, `components/ui/notchset/key-cap-parts.tsx` as the reference implementation before changing or recreating anything, and match it: sizes, colours per theme, motion timings, copy and behaviour.
- If you deviate (a prop you can't honour, a style you changed, a dependency you swapped), say so in your reply, part by part.
- Keep the accessibility contract, the keyboard map and the motion levels listed below.

## Use it when
- Every app with keys: one sheet fed by the key map, opened by ? and from the Help group (HelpMenuItems onShortcuts).

### Not when
- A single key's hint belongs on its control's tooltip or menu row instead.

## Built from
- dialog (`dialog`), installed with it: reuse it, don't rebuild it
- keyboard-hint (`keyboard-hint`), installed with it: reuse it, don't rebuild it
- search-field (`search-field`), installed with it: reuse it, don't rebuild it
- Controllable (shared helper, ships with it)
- Hit area (shared helper, ships with it)
- Layers (shared helper, ships with it)
- Words (shared helper, ships with it)

## Mistakes
- Recreating the component instead of installing it

## Usage

```tsx
"use client";
import * as React from "react";
import { Keyboard } from "@/lib/notchset/icons";
import { Button } from "@/components/ui/notchset/button";
import { StageLayer } from "@/lib/notchset/portal";
import { ShortcutSheet, type ShortcutGroup } from "@/components/ui/notchset/shortcut-sheet";

/*
 * The sheet open at first paint over a plain frame that is its stage, centred and sized to its content, one scroller
 * when the frame is short. Fed by the app's key map, so it prints only keys that work. Find narrows it by words or by
 * pressing a key; a word that matches nothing says so. The knobs pick whose keys it holds (a CRM, an editor, a mail
 * app), the G-then chords, and its line under the title. The demo leaves ? and ⌘/ to the page around it (bindKeys off).
 * The frame grows to the whole sheet, every row in view, with room under it for the dialog's shadow, which it never cuts.
 */
/* the dialog sits 16px inside its layer; its shadow reaches 80px below it, so the frame keeps the rest under the layer */
const INSET = 16;
const SHADOW_ROOM = 64;
/* the sheet's whole height: the dialog as drawn, plus whatever its scroller still hides */
function sheetHeight(layer: HTMLElement) {
  const d = layer.querySelector<HTMLElement>("[role=dialog]");
  if (!d) return null;
  const scroller = [...d.querySelectorAll<HTMLElement>("*")].find((e) => e.scrollHeight > e.clientHeight + 1 && /auto|scroll/.test(getComputedStyle(e).overflowY));
  return Math.ceil(d.offsetHeight + (scroller ? scroller.scrollHeight - scroller.clientHeight : 0));
}
type Use = "crm" | "editor" | "mail";
const ANYWHERE: ShortcutGroup = ["Anywhere", [["⌘K", "Search and commands"], ["?", "This sheet"], ["⌘Z", "Undo the last change"], ["Esc", "Close the top layer"]]];
const SETS: Record<Use, { groups: ShortcutGroup[]; chords: ShortcutGroup }> = {
  crm: {
    groups: [["Lists and records", [["J", "Next, in lists and open records"], ["K", "Previous"], ["↵", "Open"], ["X", "Select"], ["C", "New record"]]]],
    chords: ["Go to", [[{ keys: "G", then: "H" }, "Home"], [{ keys: "G", then: "I" }, "Inbox"], [{ keys: "G", then: "P" }, "Pipeline"]]],
  },
  editor: {
    groups: [["Format", [["⌘B", "Bold"], ["⌘I", "Italic"], ["⌘K", "Link the selection"], ["⌘L", "Numbered list"]]], ["Blocks", [["/", "Insert a block"], ["⌘1", "Heading 1"], ["⌥↑", "Move the block up"]]]],
    chords: ["Go to", [[{ keys: "G", then: "D" }, "Documents"], [{ keys: "G", then: "S" }, "Shared with me"]]],
  },
  mail: {
    groups: [["Messages", [["J", "Next message"], ["K", "Previous message"], ["R", "Reply"], ["E", "Archive"], ["#", "Delete"]]]],
    chords: ["Go to", [[{ keys: "G", then: "I" }, "Inbox"], [{ keys: "G", then: "S" }, "Starred"], [{ keys: "G", then: "D" }, "Drafts"]]],
  },
};

export default function ShortcutSheetDemo() {
  const use = "crm" as Use;
  const chords = true;
  const line = false;
  const set = SETS[use];
  const [open, setOpen] = React.useState(true);
  const [layer, setLayer] = React.useState<HTMLDivElement | null>(null);
  /* the tallest the sheet has been for these knobs: Find narrowing it never pulls the frame in under the hand */
  const knobs = `${use}|${chords}|${line}`;
  const [kept, setKept] = React.useState({ knobs, tall: 0 });
  const tall = kept.knobs === knobs ? kept.tall : 0;
  React.useEffect(() => {
    if (!layer) return;
    const fit = () => {
      const h = sheetHeight(layer);
      if (!h) return;
      setKept((k) => {
        const next = Math.max(k.knobs === knobs ? k.tall : 0, h + 2 * INSET + SHADOW_ROOM);
        return k.knobs === knobs && k.tall === next ? k : { knobs, tall: next };
      });
    };
    fit();
    const mo = new MutationObserver(fit);
    mo.observe(layer, { childList: true, subtree: true });
    const ro = new ResizeObserver(fit);
    ro.observe(layer);
    return () => (mo.disconnect(), ro.disconnect());
  }, [layer, knobs]);
  const groups = [ANYWHERE, ...(chords ? [set.chords] : []), ...set.groups];
  return (
    <div className="relative isolate flex w-full max-w-[var(--ns-width-xl)] flex-col" style={{ height: open && tall ? tall : 470 }}>
      <div className="flex flex-1 items-center justify-center">
        {!open && (
          <Button size="sm" onClick={() => setOpen(true)}>
            <Keyboard />
            Keyboard shortcuts
          </Button>
        )}
      </div>
      {/* the stage's layer, its shadow left whole: the dialog centres in it and its shadow falls into the room below */}
      <div ref={setLayer} data-ns-stage-layer="" className="pointer-events-none absolute inset-x-0 top-0 z-[60] [contain:layout]" style={{ bottom: SHADOW_ROOM }} />
      {layer && (
        <StageLayer value={layer}>
          <ShortcutSheet key={use} open={open} onOpenChange={setOpen} groups={groups} description={line ? "Every key here works on this page; Find takes words or a key." : undefined} bindKeys={false} labels={{ tryIt: "" }} />
        </StageLayer>
      )}
    </div>
  );
}
```

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `groups` | `ShortcutGroup[]` |  | Required. |
| `open` | `boolean` |  | open (controlled, with onOpenChange); leave it out and use defaultOpen for a sheet that keeps its own state |
| `defaultOpen` | `boolean` |  | opened on arrival when uncontrolled |
| `onOpenChange` | `(open: boolean) => void` |  |  |
| `description` | `React.ReactNode` |  | One line under the title; says how to open the sheet when left out. |
| `bindKeys` | `boolean` | `true` | Bind ? (outside fields) and ⌘/ (anywhere) to open it. On by default; turn off where the host binds them. |
| `labels` | `Partial<ShortcutSheetLabels>` |  | its built-in words (SHORTCUT_SHEET_LABELS) |

Full docs: https://notchset.dev/components/shortcut-sheet

## Customising
- Colours: every part reads the foundation's roles (`--ns-canvas`, `--ns-ink`, `--ns-line`, `--ns-signal` …), which read your shadcn tokens (`--background`, `--foreground`, `--border`, `--destructive` …), plus the optional `--success` and `--warning`. Retheme on `:root` or any container; never add Tailwind colour classes inside the component.
- Dark mode follows the `.dark` class or `data-theme="dark"` on an ancestor (the shadcn and next-themes conventions).
- Update later: Commit or stash local changes first (or copy the files), so the update can be undone. Read https://notchset.dev/r/changelog.json for the new versions: a major version, an entry marked breaking or a merge says what to change. Then re-run the install with `--overwrite`, on a branch. It replaces the component's files, the shared helper files they import, and the item's CSS rules in the global stylesheet, so review the whole diff (components, shared files, CSS), re-apply your own edits, and run the app's typecheck, tests and build.

## Responsive

- phone: one column, the key line hidden on touch
- desktop: two columns
- dark (tokens)

## Motion inventory

| Interaction | What moves |
|---|---|
| a recorded key fades in | ns-fade on --ns-time-color, --ns-ease. Reduced motion: at once (data-ns-recorder). |
| a clash line rises in | ns-rise on --ns-time-menu, --ns-ease. Reduced motion: at once (data-ns-recorder). |
| a tried key's row lights, then fades | ns-mark-fade, --ns-time-born, --ns-ease. Reduced motion: fades as it is (a tint, nothing moves). |

## Accessibility contract (preserve when editing)
- A dialog titled Keyboard shortcuts with its find field focused; ↓ moves to the list region, which takes the keys you try; each group is a named section; what a tried key does is read from a polite live line; ? never opens it while typing.

## Install

```bash
# npm
npx shadcn@latest add https://notchset.dev/r/shortcut-sheet.json
# pnpm
pnpm dlx shadcn@latest add https://notchset.dev/r/shortcut-sheet.json
# yarn
yarn dlx shadcn@latest add https://notchset.dev/r/shortcut-sheet.json
# bun
bunx --bun shadcn@latest add https://notchset.dev/r/shortcut-sheet.json
```

Or add the `@notchset` registry to components.json and run `npx shadcn@latest add @notchset/shortcut-sheet`. Every components.json style gets the same files.

### Manual

1. Install the packages: none beyond `react` and `react-dom`.
2. Copy `components/ui/notchset/shortcut-sheet.tsx`, `lib/notchset/controllable.ts`, `lib/notchset/hit-area.ts`, `components/ui/notchset/key-cap-parts.tsx`, `lib/notchset/layers.ts`, `lib/notchset/words.ts` from https://notchset.dev/r/shortcut-sheet.json (each file's `content`, at its `target`), keeping the `@/` path alias of your tsconfig.
3. Add what it builds on: shadcn `utils` (cn), `notchset-foundation`, `dialog`, `keyboard-hint`, `search-field`.

## Continue the workflow

- [Bottom sheet](https://notchset.dev/components/bottom-sheet)
- [Command palette](https://notchset.dev/components/command-menu)
- [Dialog](https://notchset.dev/components/dialog)

## Source

### components/ui/notchset/shortcut-sheet.tsx

```tsx
// Notchset shortcut-sheet 1.2.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { useControllableOpen } from "@/lib/notchset/controllable";
import { cn } from "@/lib/utils";
import { HIT_AREA } from "@/lib/notchset/hit-area";
import { Dialog } from "@/components/ui/notchset/dialog";
import { KeyboardHint } from "@/components/ui/notchset/keyboard-hint";
import { hintProps, type Shortcut } from "@/components/ui/notchset/key-cap-parts";
import { asCtrl, capsOf, isApple, keyCap, keyCapTone } from "@/components/ui/notchset/key-cap-parts";
import { SearchField } from "@/components/ui/notchset/search-field";
import { inField, layerOpen } from "@/lib/notchset/layers";
import { fill, fillNodes } from "@/lib/notchset/words";

/*
 * Shortcut sheet: every key an app binds, in its groups, fed by the app's own key map so it can only print keys that
 * work. It opens with ? anywhere (and ⌘/ inside a text field) in every app; a find field filters it as you type
 * (the words or the key), and pressing a key while the list has focus lights its row and says what it does, so you
 * learn by trying. Keys print as the locked caps.
 *
 *   <ShortcutSheet open={open} onOpenChange={setOpen} groups={[["Anywhere", [["⌘K", "Search and commands"], [{ keys: "G", then: "P" }, "Go to Projects"]]]]} />
 */
/** a row: its keys, what they do, and optionally the key map's id (printed as data-key, for a test to find) */
export type ShortcutGroup = [label: string, rows: [keys: Shortcut, label: string, id?: string][]];
type ShortcutSheetProps = {
  groups: ShortcutGroup[];
  /** open (controlled, with onOpenChange); leave it out and use defaultOpen for a sheet that keeps its own state */
  open?: boolean | undefined;
  /** opened on arrival when uncontrolled */
  defaultOpen?: boolean | undefined;
  onOpenChange?: ((open: boolean) => void) | undefined;
  /** One line under the title; says how to open the sheet when left out. */
  description?: React.ReactNode;
  /** Bind ? (outside fields) and ⌘/ (anywhere) to open it. On by default; turn off where the host binds them. */
  bindKeys?: boolean | undefined;
  /** its built-in words (SHORTCUT_SHEET_LABELS) */
  labels?: Partial<ShortcutSheetLabels> | undefined;
};
/** The sheet's words, over the English defaults: `{key}` is the key that opens it, `{query}` what was typed. */
const SHORTCUT_SHEET_LABELS = {
  title: "Keyboard shortcuts",
  description: "Everything you do with a mouse, you can do from here. Open this sheet with {key} anywhere.",
  find: "Find a shortcut",
  list: "Shortcuts",
  nothing: "No shortcut for “{query}”. Try “next”, “new” or a key like J.",
  tryIt: "Press ↓, then any key, to try it here.",
};
type ShortcutSheetLabels = typeof SHORTCUT_SHEET_LABELS;

/* a layer already open over the page keeps its keys (layers.ts) */

/** Opens the sheet with ? (never while typing) and ⌘/ (also inside a field), while mounted. */
export function useShortcutSheetKeys(open: () => void, on = true) {
  const latest = React.useRef(open);
  React.useEffect(() => {
    latest.current = open;
  });
  React.useEffect(() => {
    if (!on) return;
    const down = (e: KeyboardEvent) => {
      if (e.isComposing || e.defaultPrevented) return;
      const slash = (e.metaKey || e.ctrlKey) && !e.altKey && e.key === "/";
      const q = e.key === "?" && !e.metaKey && !e.ctrlKey && !e.altKey && !inField(e.target);
      if (!slash && !q) return;
      if (layerOpen()) return;
      e.preventDefault();
      latest.current();
    };
    window.addEventListener("keydown", down);
    return () => window.removeEventListener("keydown", down);
  }, [on]);
}

/** One spelling for a key, from caps or a press: ⇧ ⌥ ⌘, ↵, arrows, Space, Esc, letters upper case. */
const normal = (k: string) =>
  k
    .replace(/Shift\s?/g, "⇧")
    .replace(/Alt\s?|Option\s?/g, "⌥")
    .replace(/Ctrl\s?|Cmd\s?/g, "⌘")
    .replace(/Enter|Return/g, "↵")
    .replace(/Escape/g, "Esc")
    .replace(/\s+/g, "")
    .toUpperCase();
const NAMED: Record<string, string> = { Enter: "↵", ArrowLeft: "←", ArrowRight: "→", ArrowUp: "↑", ArrowDown: "↓", Backspace: "⌫", " ": "SPACE", Escape: "ESC", Tab: "TAB" };
function chordOf(e: React.KeyboardEvent) {
  const k = NAMED[e.key] ?? (e.key.length === 1 ? e.key.toUpperCase() : e.key.toUpperCase());
  const sym = e.key.length === 1 && !/[a-z]/i.test(e.key);
  return `${e.metaKey || e.ctrlKey ? "⌘" : ""}${e.altKey ? "⌥" : ""}${e.shiftKey && !sym ? "⇧" : ""}${k}`;
}
const keyText = (s: Shortcut) => (typeof s === "string" ? s : `${s.keys} ${s.then ?? ""}`);
const said = (s: Shortcut) => (typeof s === "string" ? s : s.then ? `${s.keys} then ${s.then}` : s.keys);

function Marked({ text, q }: { text: string; q: string }) {
  const i = q ? text.toLowerCase().indexOf(q) : -1;
  if (i < 0) return <>{text}</>;
  return (
    <>
      {text.slice(0, i)}
      <mark className="rounded-[var(--ns-radius-xs)] bg-[var(--ns-selected)] text-[var(--ns-ink)]">{text.slice(i, i + q.length)}</mark>
      {text.slice(i + q.length)}
    </>
  );
}

function ShortcutSheet({ groups, open: openProp, defaultOpen, onOpenChange, description, bindKeys = true, labels }: ShortcutSheetProps) {
  const L = { ...SHORTCUT_SHEET_LABELS, ...labels };
  const [open, setOpen] = useControllableOpen({ open: openProp, defaultOpen, onOpenChange });
  const [q, setQ] = React.useState("");
  const [hit, setHit] = React.useState<{ id: string; n: number } | null>(null);
  const [live, setLive] = React.useState("");
  const list = React.useRef<HTMLDivElement>(null);
  /* the fade over the foot shows only while the list runs on under it (scrolled short of its end) */
  const [foot, setFoot] = React.useState<HTMLParagraphElement | null>(null);
  const [more, setMore] = React.useState(false);
  React.useEffect(() => {
    let box = foot?.parentElement ?? null;
    while (box && !/auto|scroll/.test(getComputedStyle(box).overflowY)) box = box.parentElement;
    if (!foot || !box) return;
    const scroller = box;
    /* the foot hangs 16px into the scroller's end (its -mb-4), so that much past the bottom is not more list */
    const read = () => setMore(scroller.scrollHeight - scroller.scrollTop - scroller.clientHeight > 16);
    scroller.addEventListener("scroll", read, { passive: true });
    const ro = typeof ResizeObserver === "undefined" ? null : new ResizeObserver(read);
    ro?.observe(scroller);
    if (scroller.firstElementChild) ro?.observe(scroller.firstElementChild);
    const first = requestAnimationFrame(read);
    return () => (scroller.removeEventListener("scroll", read), ro?.disconnect(), cancelAnimationFrame(first));
  }, [foot]);
  const pendingG = React.useRef(0);
  useShortcutSheetKeys(() => setOpen(true), bindKeys && !open);
  const query = q.trim().toLowerCase();
  const shown = groups
    .map(([label, rows]) => [label, rows.map((r, i) => ({ id: `${label}:${i}`, keys: r[0], label: r[1], key: r[2] })).filter((r) => !query || r.label.toLowerCase().includes(query) || normal(keyText(r.keys)).replace(/\s/g, "") === normal(query))] as const)
    .filter(([, rows]) => rows.length);
  const change = (o: boolean) => {
    if (!o) {
      setQ("");
      setHit(null);
      setLive("");
    }
    setOpen(o);
  };
  const tryKey = (e: React.KeyboardEvent) => {
    if (inField(e.target) || ["Escape", "Tab", "Meta", "Control", "Shift", "Alt"].includes(e.key)) return;
    const c = chordOf(e);
    const all = groups.flatMap(([label, rows]) => rows.map((r, i) => ({ id: `${label}:${i}`, keys: r[0], label: r[1] })));
    let rows = Date.now() - pendingG.current < 1500 ? all.filter((r) => typeof r.keys !== "string" && normal(r.keys.keys) === "G" && r.keys.then && normal(r.keys.then) === c) : [];
    if (!rows.length) rows = all.filter((r) => typeof r.keys === "string" && normal(r.keys) === c);
    pendingG.current = c === "G" ? Date.now() : 0;
    if (!rows.length && c === "G" && all.some((r) => typeof r.keys !== "string" && normal(r.keys.keys) === "G")) {
      e.preventDefault();
      return setLive("G … now a page’s letter");
    }
    if (!rows.length) return setLive(`${c} isn’t bound here.`);
    e.preventDefault();
    const r = rows[0]!;
    setHit((h) => ({ id: r.id, n: (h?.n ?? 0) + 1 }));
    setLive(`${said(r.keys)}: ${r.label}`);
    requestAnimationFrame(() => list.current?.querySelector(`[data-row="${CSS.escape(r.id)}"]`)?.scrollIntoView({ block: "nearest" }));
  };
  return (
    <Dialog open={open} onOpenChange={change} title={L.title} description={description ?? fillNodes(L.description, { key: <span className="font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]">?</span> })} size="lg" noCancel>
      <div data-slot="shortcut-sheet" className="flex flex-col gap-3">
        {/* one scroller, the dialog's own: the find field stays at its top and the try-it line at its foot */}
        <div className="sticky top-0 z-[1] -mt-1 bg-[var(--ns-raised)] pt-1">
          <SearchField
            value={q}
            onValueChange={setQ}
            placeholder={L.find}
            aria-label={L.find}
            className="w-full"
            onKeyDown={(e) => {
              if (e.key !== "ArrowDown") return;
              e.preventDefault();
              list.current?.focus();
            }}
          />
        </div>
        {/* the list takes the keys you try: focus it (↓ from the find field) and press one; its groups balance over two
            columns, so a search narrows both */}
        <div
          ref={list}
          tabIndex={0}
          role="region"
          aria-label={L.list}
          onKeyDown={tryKey}
          className="-m-1 columns-2 gap-x-6 rounded-[var(--ns-radius)] p-1 outline-hidden focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)] phone:columns-1"
        >
          {shown.map(([label, rows]) => (
            <section key={label} aria-label={label} className="mb-5 flex break-inside-avoid flex-col gap-1 last:mb-0">
              <h3 className="m-0 pb-1 text-[length:var(--ns-text-meta)] font-[number:var(--ns-weight-medium)] text-[var(--ns-ink-3)]">{label}</h3>
              {rows.map((r) => (
                <div
                  key={r.id + (hit?.id === r.id ? hit.n : "")}
                  data-row={r.id}
                  data-key={r.key}
                  data-hit={hit?.id === r.id || undefined}
                  className="flex min-h-8 items-center justify-between gap-3 rounded-[var(--ns-radius-sm)] px-1 py-1 shadow-[inset_0_-1px_0_var(--ns-line-soft)] data-hit:[animation:ns-mark-fade_var(--ns-time-born)_var(--ns-ease)]"
                >
                  <span className="text-[var(--ns-ink-2)]">
                    <Marked text={r.label} q={query} />
                  </span>
                  <KeyboardHint {...hintProps(r.keys)} className="shrink-0" />
                </div>
              ))}
            </section>
          ))}
          {!shown.length && <p className="m-0 [column-span:all] py-6 text-center text-[var(--ns-ink-2)]">{fill(L.nothing, { query: q.trim() })}</p>}
        </div>
        {/* the try-it line stays at the scroller's foot; a fade above it says the list runs on under it when the sheet is
            shorter than its list (a phone, a short window, a preview stage), and only then */}
        <p ref={setFoot} aria-live="polite" className={cn("sticky bottom-0 m-0 -mb-4 min-h-5 bg-[var(--ns-raised)] pt-1 pb-4 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)] pointer-coarse:hidden", "before:pointer-events-none before:absolute before:inset-x-0 before:bottom-full before:h-6 before:bg-[linear-gradient(to_top,var(--ns-raised),transparent)] before:content-[''] before:[transition:opacity_var(--ns-time-color)]", !more && "before:opacity-0")}>
          {live || L.tryIt}
        </p>
      </div>
    </Dialog>
  );
}

/* ---- The recorder: the sheet's rows, each one's keys a button that records new ones ---- */

/** A row the recorder can change: the key map's id, what it does, its keys stored as "mod+shift+l" (mod is ⌘ on Apple,
 *  Ctrl elsewhere), and the keys it came with, for Reset. */
type ShortcutRecorderRow = { id: string; label: string; keys: string; defaultKeys?: string | undefined };
type ShortcutRecorderProps = {
  /** the app's key map, one group of rows */
  rows: ShortcutRecorderRow[];
  /** a new chord for a row (and, on a swap, the old one for the row that owned it). Return a promise to save it; a
   *  refusal puts the keys back and says so. */
  onRebind?: ((id: string, chord: string) => void | Promise<unknown>) | undefined;
  /** a row ready to record at first paint, without taking focus (a stage that shows recording at rest) */
  defaultRecording?: string | undefined;
  /** the browser's own chords it refuses, with what each does; the defaults: tabs, windows, quit, address, reload */
  reserved?: Record<string, string> | undefined;
  /** its built-in words (SHORTCUT_RECORDER_LABELS) */
  labels?: Partial<ShortcutRecorderLabels> | undefined;
  className?: string | undefined;
  "data-slot"?: string | undefined;
};
/** The recorder's words, over the English defaults: `{row}` a row's words, `{keys}` and `{old}` its chords said aloud,
 *  `{owner}` the row that holds a chord, `{does}` what the browser does with it, `{key}` a key that can't be bound. */
const SHORTCUT_RECORDER_LABELS = {
  title: "Keyboard shortcuts",
  find: "Find a shortcut",
  nothing: "No shortcut matches “{query}”.",
  change: "{row}: {keys}. Change shortcut",
  recording: "Recording a shortcut for {row}. Press the keys; Esc cancels",
  press: "Press keys…",
  reset: "Reset",
  resetName: "Reset {row} to {keys}",
  taken: "Taken by",
  keepLooking: "Keep looking",
  swap: "Swap",
  clash: "{keys} is {owner}’s. Swap, and {owner} takes {old}.",
  now: "{row} is now {keys}",
  swapped: "{row} is now {keys}; {owner} is {old}",
  back: "{row} is back to {keys}",
  keeps: "{row} keeps {keys}",
  already: "{row} is already {keys}",
  refused: "{keys} {does} in your browser; pick another",
  notAKey: "{key} can’t be a shortcut; try a letter or a digit with {mod}",
  failed: "Couldn’t save; {rows}.",
  stillIs: "{row} is still {keys}",
  lit: "{keys}: {row}",
};
type ShortcutRecorderLabels = typeof SHORTCUT_RECORDER_LABELS;
const RESERVED_CHORDS: Record<string, string> = {
  "mod+w": "closes the tab",
  "mod+t": "opens a tab",
  "mod+n": "opens a window",
  "mod+q": "quits the browser",
  "mod+l": "goes to the address bar",
  "mod+r": "reloads the page",
  "mod+shift+n": "opens a private window",
  "mod+shift+t": "reopens a tab",
};
const MODS = ["mod", "alt", "shift"];
const MOD_CODES = new Set(["ShiftLeft", "ShiftRight", "ControlLeft", "ControlRight", "AltLeft", "AltRight", "MetaLeft", "MetaRight"]);
const CODE_KEYS: Record<string, string> = { Slash: "/", Period: ".", Comma: ",", BracketLeft: "[", BracketRight: "]", Semicolon: ";", Quote: "'", Backquote: "`", Minus: "-", Equal: "=", Space: "space", Enter: "enter" };
/** The physical key (e.code), whatever the layout prints on it: KeyL is "l" on any keyboard. */
function keyOfCode(code: string) {
  const m = /^Key([A-Z])$/.exec(code) ?? /^Digit(\d)$/.exec(code);
  return m ? m[1]!.toLowerCase() : (CODE_KEYS[code] ?? null);
}
/** A key press as a stored chord: "mod+shift+l"; without `key`, only the modifiers held. */
function storedChord(e: { metaKey: boolean; ctrlKey: boolean; altKey: boolean; shiftKey: boolean }, apple: boolean, key?: string | null) {
  return [(apple ? e.metaKey : e.ctrlKey) && "mod", e.altKey && "alt", e.shiftKey && "shift", key].filter(Boolean).join("+");
}
/** A stored chord as caps: "mod+shift+l" is ⌘⇧L (KeyboardHint prints Ctrl Shift L off Apple); a chord of modifiers
 *  only prints every one of them, and no key. */
function printChord(chord: string) {
  const parts = chord ? chord.split("+") : [];
  const glyph: Record<string, string> = { mod: "⌘", alt: "⌥", shift: "⇧" };
  const key = parts.find((p) => !MODS.includes(p));
  const mods = MODS.filter((m) => parts.includes(m)).map((m) => glyph[m]).join("");
  return mods + (key === undefined ? "" : key === "space" ? "Space" : key === "enter" ? "↵" : key.toUpperCase());
}
/** A stored chord said aloud: "Command Shift L" on Apple, "Ctrl Shift L" elsewhere. */
function sayChord(chord: string, apple: boolean) {
  const p = printChord(chord);
  return (apple ? p.replace(/⌘/g, "Command ").replace(/⌥/g, "Option ").replace(/⇧/g, "Shift ") : asCtrl(p).replace(/⌃/g, "Ctrl ")).replace(/\s+/g, " ").trim();
}
const noSubscribe = () => () => {};
const coarse = () => typeof matchMedia !== "undefined" && matchMedia("(pointer: coarse)").matches;
function useCoarse() {
  return React.useSyncExternalStore(
    (f) => {
      if (typeof matchMedia === "undefined") return () => {};
      const q = matchMedia("(pointer: coarse)");
      q.addEventListener?.("change", f);
      return () => q.removeEventListener?.("change", f);
    },
    coarse,
    () => false,
  );
}

function ShortcutRecorder({ rows: given, onRebind, defaultRecording, reserved = RESERVED_CHORDS, labels, className, "data-slot": slot = "shortcut-recorder" }: ShortcutRecorderProps) {
  const L = { ...SHORTCUT_RECORDER_LABELS, ...labels };
  const apple = React.useSyncExternalStore(noSubscribe, isApple, () => false);
  const touch = useCoarse();
  /* the key map as the host gave it, with the changes made here on top until it hands back new rows */
  const [seed, setSeed] = React.useState(given);
  const [keys, setKeys] = React.useState<Record<string, string>>({});
  if (seed !== given) {
    setSeed(given);
    setKeys({});
  }
  const rows = given.map((r) => ({ ...r, keys: keys[r.id] ?? r.keys, defaultKeys: r.defaultKeys ?? r.keys }));
  const row = (id: string) => rows.find((r) => r.id === id)!;
  const [rec, setRec] = React.useState<string | null>(defaultRecording ?? null);
  /* recording at rest, set by the host: it took no focus, so a press on it keeps it recording, now with focus */
  const [ready, setReady] = React.useState(defaultRecording != null);
  const [held, setHeld] = React.useState("");
  const [clash, setClash] = React.useState<{ chord: string; owner: string } | null>(null);
  const [lit, setLit] = React.useState<string | null>(null);
  const [said, setSaid] = React.useState<{ text: string; bad?: boolean } | null>(null);
  const [find, setFind] = React.useState("");
  const btns = React.useRef<Record<string, HTMLButtonElement | null>>({});
  const timer = React.useRef<ReturnType<typeof setTimeout>>(undefined);
  React.useEffect(() => () => clearTimeout(timer.current), []);
  const say = (k: string) => sayChord(k, apple);
  const flash = (id: string) => {
    clearTimeout(timer.current);
    setLit(id);
    timer.current = setTimeout(() => setLit((l) => (l === id ? null : l)), 1400);
  };
  const stop = (id: string, refocus = true) => {
    setRec(null);
    setReady(false);
    setHeld("");
    setClash(null);
    if (refocus) requestAnimationFrame(() => btns.current[id]?.focus());
  };
  const apply = (changes: Record<string, string>, ok: string) => {
    const before = Object.fromEntries(Object.keys(changes).map((id) => [id, row(id).keys]));
    setKeys((k) => ({ ...k, ...changes }));
    setSaid({ text: ok });
    const saves = Object.entries(changes).map(([id, chord]) => onRebind?.(id, chord));
    if (!saves.some((p) => p && typeof (p as Promise<unknown>).then === "function")) return;
    Promise.all(saves).catch(() => {
      setKeys((k) => ({ ...k, ...before }));
      setSaid({ text: fill(L.failed, { rows: Object.keys(before).map((id) => fill(L.stillIs, { row: row(id).label, keys: say(before[id]!) })).join(", ") }), bad: true });
    });
  };
  const record = (id: string, e: React.KeyboardEvent) => {
    /* Tab leaves the row unrecorded and moves on, as Tab does */
    if (e.key === "Tab") return stop(id, false);
    e.preventDefault();
    const r = row(id);
    if (e.key === "Escape") {
      setLit(null);
      setSaid({ text: fill(L.keeps, { row: r.label, keys: say(r.keys) }) });
      return stop(id);
    }
    if (MOD_CODES.has(e.code)) return setHeld(storedChord(e, apple));
    const key = keyOfCode(e.code);
    if (!key) return setSaid({ text: fill(L.notAKey, { key: e.key, mod: apple ? "⌘" : "Ctrl" }), bad: true });
    const chord = storedChord(e, apple, key);
    setHeld(chord);
    setClash(null);
    setLit(null);
    if (reserved[chord]) return setSaid({ text: fill(L.refused, { keys: say(chord), does: reserved[chord]! }), bad: true });
    if (chord === r.keys) return (setSaid({ text: fill(L.already, { row: r.label, keys: say(chord) }) }), stop(id));
    const owner = rows.find((x) => x.keys === chord && x.id !== id);
    if (owner) {
      setClash({ chord, owner: owner.id });
      setLit(owner.id);
      setSaid({ text: fill(L.clash, { keys: say(chord), owner: owner.label, old: say(r.keys) }) });
      return;
    }
    apply({ [id]: chord }, fill(L.now, { row: r.label, keys: say(chord) }));
    flash(id);
    stop(id);
  };
  const swap = (id: string) => {
    if (!clash) return;
    const r = row(id);
    const owner = row(clash.owner);
    apply({ [id]: clash.chord, [owner.id]: r.keys }, fill(L.swapped, { row: r.label, keys: say(clash.chord), owner: owner.label, old: say(r.keys) }));
    flash(owner.id);
    stop(id);
  };
  /* the sheet's own: with focus in the list, a bound chord lights its row */
  const tryKey = (e: React.KeyboardEvent) => {
    if (rec || inField(e.target)) return;
    const key = keyOfCode(e.code);
    const hit = key && rows.find((x) => x.keys === storedChord(e, apple, key));
    if (!hit) return;
    e.preventDefault();
    flash(hit.id);
    setSaid({ text: fill(L.lit, { keys: say(hit.keys), row: hit.label }) });
  };
  const q = find.trim().toLowerCase();
  const shown = rows.filter((r) => !q || r.label.toLowerCase().includes(q));
  return (
    <div data-slot={slot} data-ns-recorder="" className={cn("flex w-[540px] max-w-full flex-col", className)}>
      <section aria-label={L.title} onKeyDown={tryKey} className="rounded-[var(--ns-radius-lg)] [corner-shape:var(--ns-corner)] bg-[var(--ns-panel)] shadow-[inset_0_0_0_1px_var(--ns-line),0_1px_2px_rgb(0_0_0/0.04)]">
        <header className="flex flex-wrap items-center gap-3 border-b border-[var(--ns-line-soft)] px-6 py-4 phone:px-4">
          <h3 className="m-0 flex-1 text-[length:var(--ns-text-body)] font-[number:var(--ns-weight-strong)] tracking-[-0.01em] text-[var(--ns-ink)]">{L.title}</h3>
          <SearchField value={find} onValueChange={setFind} placeholder={L.find} aria-label={L.find} size="sm" className="w-[220px] phone:w-full" />
        </header>
        <div role="group" aria-label={L.title} className="px-3 py-3 phone:px-2">
          {shown.map((r) => {
            const on = rec === r.id;
            const changed = r.keys !== r.defaultKeys;
            return (
              <div key={r.id} data-row={r.id}>
                <div data-lit={lit === r.id ? "" : undefined} className="flex min-h-11 items-center gap-3 rounded-[var(--ns-radius)] px-3 text-[var(--ns-ink)] [transition:background-color_var(--ns-time-color)] data-lit:bg-[var(--ns-selected)]">
                  <span className="min-w-0 flex-1">{r.label}</span>
                  {touch ? (
                    /* a phone has no keys to press: each row's keys read as they are */
                    <span data-slot="shortcut-recorder-keys" role="img" aria-label={fill(L.lit, { keys: say(r.keys), row: r.label })} className="inline-flex gap-0.5">
                      {capsOf(apple ? printChord(r.keys) : asCtrl(printChord(r.keys))).map((c, i) => (
                        <kbd key={i} aria-hidden className={cn(keyCap, keyCapTone.surface)}>
                          {c}
                        </kbd>
                      ))}
                    </span>
                  ) : (
                    <>
                      {changed && !on && (
                        <button
                          type="button"
                          aria-label={fill(L.resetName, { row: r.label, keys: say(r.defaultKeys) })}
                          onClick={() => (apply({ [r.id]: r.defaultKeys }, fill(L.back, { row: r.label, keys: say(r.defaultKeys) })), flash(r.id))}
                          className={cn(HIT_AREA, "cursor-pointer rounded-[var(--ns-radius-sm)] px-1.5 py-0.5 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)] outline-hidden hover:bg-[var(--ns-hover)] hover:text-[var(--ns-ink)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)]")}
                        >
                          {L.reset}
                        </button>
                      )}
                      <button
                        ref={(el) => {
                          btns.current[r.id] = el;
                        }}
                        type="button"
                        data-slot="shortcut-recorder-key"
                        data-keys={r.keys}
                        aria-label={on ? fill(L.recording, { row: r.label }) : fill(L.change, { row: r.label, keys: say(r.keys) })}
                        aria-pressed={on}
                        onClick={() => {
                          if (on && ready) return setReady(false);
                          if (on) return stop(r.id);
                          setRec(r.id);
                          setReady(false);
                          setHeld("");
                          setClash(null);
                          setLit(null);
                          setSaid(null);
                        }}
                        onKeyDown={(e) => on && record(r.id, e)}
                        onKeyUp={(e) => on && !clash && MOD_CODES.has(e.code) && setHeld(storedChord(e, apple))}
                        onBlur={(e) => on && !ready && !clash && !e.currentTarget.closest("[data-ns-recorder]")?.contains(e.relatedTarget as Node | null) && stop(r.id, false)}
                        className={cn(
                          HIT_AREA,
                          "inline-flex h-8 min-w-[112px] cursor-pointer items-center justify-end gap-2 rounded-[var(--ns-radius)] px-2 outline-hidden [transition:background-color_var(--ns-time-color),box-shadow_var(--ns-time-color)] hover:bg-[var(--ns-hover)] focus-visible:shadow-[0_0_0_2px_var(--ns-signal)]",
                          on && "bg-[var(--ns-field)] shadow-[inset_0_0_0_1px_var(--ns-signal)] hover:bg-[var(--ns-field)] focus-visible:shadow-[inset_0_0_0_1px_var(--ns-signal),0_0_0_3px_color-mix(in_oklab,var(--ns-signal)_25%,transparent)]",
                        )}
                      >
                        {on ? (
                          held ? (
                            <KeyboardHint keys={printChord(held)} held />
                          ) : (
                            <span className="text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{L.press}</span>
                          )
                        ) : (
                          <span key={r.keys} className="inline-flex [animation:ns-fade_var(--ns-time-color)_var(--ns-ease)_both]">
                            <KeyboardHint keys={printChord(r.keys)} />
                          </span>
                        )}
                      </button>
                    </>
                  )}
                </div>
                {on && clash && (
                  <div data-slot="shortcut-recorder-clash" className="flex flex-wrap items-center justify-end gap-2 px-3 pt-1 pb-2 text-[length:var(--ns-text-small)] text-[var(--ns-ink-2)] [animation:ns-rise_var(--ns-time-menu)_var(--ns-ease)_both]">
                    <span className="me-auto">
                      {L.taken} <span className="font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)]">{row(clash.owner).label}</span>
                    </span>
                    <button
                      type="button"
                      onClick={() => (setClash(null), setLit(null), setHeld(""), setReady(false), btns.current[r.id]?.focus())}
                      className="h-8 cursor-pointer rounded-[var(--ns-radius)] px-3 text-[var(--ns-ink-2)] outline-hidden hover:bg-[var(--ns-hover)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)] pointer-coarse:h-11"
                    >
                      {L.keepLooking}
                    </button>
                    <button
                      type="button"
                      autoFocus={!ready}
                      onClick={() => swap(r.id)}
                      className="h-8 cursor-pointer rounded-[var(--ns-radius)] px-3 font-[number:var(--ns-weight-medium)] text-[var(--ns-ink)] shadow-[inset_0_0_0_1px_var(--ns-line)] outline-hidden hover:bg-[var(--ns-hover)] focus-visible:outline-2 focus-visible:outline-[var(--ns-signal)] pointer-coarse:h-11"
                    >
                      {L.swap}
                    </button>
                  </div>
                )}
              </div>
            );
          })}
          {!shown.length && <p className="m-0 px-3 py-3 text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{fill(L.nothing, { query: find.trim() })}</p>}
        </div>
      </section>
      <p aria-live="polite" className={cn("m-0 mt-3 min-h-5 px-1 text-[length:var(--ns-text-small)] leading-5", said?.bad ? "text-[var(--ns-bad-ink)]" : "text-[var(--ns-ink-3)]")}>
        {said?.text}
      </p>
    </div>
  );
}

export { printChord, RESERVED_CHORDS, SHORTCUT_RECORDER_LABELS, SHORTCUT_SHEET_LABELS, ShortcutRecorder, ShortcutSheet, sayChord, type ShortcutRecorderLabels, type ShortcutRecorderProps, type ShortcutRecorderRow, type ShortcutSheetLabels, type ShortcutSheetProps };
```

### lib/notchset/controllable.ts

```tsx
// Notchset shortcut-sheet 1.2.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";

/**
 * Controlled and uncontrolled, one source of truth: a piece takes `value` with `onValueChange` (controlled) or
 * `defaultValue` (uncontrolled), and reads and sets it through this hook. Controlled, it shows `value` and only asks
 * for a change; uncontrolled, it keeps its own state; it never switches between the two after its first render. On a
 * Base UI root it hands Base UI the controlled value. Controlled, two identical sets in one event can each call
 * onChange (the second is compared with what is shown, not with what was asked): harmless for open and close; a host
 * whose onChange has side effects makes it idempotent.
 * @example
 * const [value, setValue] = useControllable({ value: props.value, defaultValue: props.defaultValue ?? 0, onChange: props.onValueChange });
 * const [open, setOpen] = useControllableOpen(props);
 */
export function useControllable<T>({ value, defaultValue, onChange }: { value?: T | undefined; defaultValue: T; onChange?: ((next: T) => void) | undefined }): [T, (next: T | ((prev: T) => T)) => void] {
  const controlled = value !== undefined;
  const [own, setOwn] = React.useState(defaultValue);
  const current = controlled ? value : own;
  /* `asked` is what this event asked for so far, cleared by each render, so a refused request can be made again; written in an insertion effect so a layout effect reads this render's value. */
  const latest = React.useRef<{ current: T; controlled: boolean; onChange: typeof onChange; asked?: { v: T } | undefined }>({ current, controlled, onChange });
  React.useInsertionEffect(() => {
    latest.current = { current, controlled, onChange };
  });
  const set = React.useCallback((next: T | ((prev: T) => T)) => {
    const l = latest.current;
    const base = l.asked ? l.asked.v : l.current;
    const v = typeof next === "function" ? (next as (prev: T) => T)(base) : next;
    if (Object.is(v, base) && (!l.asked || Object.is(v, l.current))) return;
    l.asked = { v };
    if (!l.controlled) setOwn(v);
    l.onChange?.(v);
  }, []);
  return [current, set];
}

/** The same for a piece that opens: `open` with `onOpenChange`, or `defaultOpen`. */
export function useControllableOpen({ open, defaultOpen = false, onOpenChange }: { open?: boolean | undefined; defaultOpen?: boolean | undefined; onOpenChange?: ((open: boolean) => void) | undefined }) {
  return useControllable({ value: open, defaultValue: defaultOpen, onChange: onOpenChange });
}
```

### lib/notchset/hit-area.ts

```tsx
// Notchset shortcut-sheet 1.2.0 · https://notchset.dev/changelog
/** Press area round the control (a centred ::after): --ns-press-min on every pointer, --ns-hit on touch. The identity
 * transform keeps the control its containing block. */
export const HIT_AREA =
  "[transform:translate(0)] after:absolute after:inset-[min(0px,calc(50%_-_var(--ns-press-min)/2))] after:content-['']";
```

### components/ui/notchset/key-cap-parts.tsx

```tsx
// Notchset shortcut-sheet 1.2.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";

/* The key caps behind Keyboard hint and the tooltip's shortcut. Use KeyboardHint in your own screens. */
type KeyCapLabels = { then: string };
const KEY_CAP_LABELS: KeyCapLabels = { then: "then" };

/** A shortcut as data: one chord, or a chord and the key after it. */
type Shortcut = string | { keys: string; then?: string | undefined };
const hintProps = (s: Shortcut): { keys: string; then?: string | undefined } => (typeof s === "string" ? { keys: s } : s);

/** Write shortcuts with ⌘ ⇧ ⌥ and they print as Ctrl, Shift and Alt off a Mac. */
const isApple = () => typeof navigator !== "undefined" && /Mac|iPhone|iPad|iPod/.test(navigator.platform || navigator.userAgent);
const WORDS: Record<string, string> = { "⌘": "Ctrl", "⌃": "Ctrl", "⇧": "Shift", "⌥": "Alt" };
/** ⌘ ⌃ ⇧ ⌥ as Ctrl, Shift and Alt, for keyboards that are not Apple's */
const asCtrl = (k: string) => k.replace(/([⌘⌃⇧⌥])\s?/g, (_, g: string) => `${WORDS[g]} `).trimEnd();
/** The caps of one chord ("⌘⇧Z" is ⌘ ⇧ Z). */
const capsOf = (chord: string) => chord.match(/Ctrl|Shift|Alt|[⌘⇧⌥⌃]|[^⌘⇧⌥⌃\s]+/g) ?? [chord];

/** The one key cap's shape. Tone it with `keyCapTone` on a dark surface. */
const keyCap =
  "inline-flex h-5.5 min-w-5.5 shrink-0 items-center justify-center rounded-[var(--ns-radius-xs)] [corner-shape:var(--ns-corner)] px-1.5 font-[family-name:var(--ns-font-mono)] text-[length:var(--ns-text-meta)] leading-none font-[number:var(--ns-weight-medium)] whitespace-nowrap [text-box:trim-both_cap_alphabetic] [transition:background-color_var(--ns-time-quick),box-shadow_var(--ns-time-quick),translate_var(--ns-time-spring)_var(--ns-ease-spring)] data-pressed:[transition:background-color_var(--ns-time-quick),box-shadow_var(--ns-time-quick),translate_var(--ns-time-quick)_var(--ns-ease-press)]";
/** The cap's colours: on a surface (the default), or on an inverse one (a toast, the bulk bar's dark pill). */
const keyCapTone = {
  surface:
    "bg-[color-mix(in_oklab,var(--ns-ink)_7%,transparent)] text-[var(--ns-ink-2)] shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ns-ink)_5%,transparent),0_2px_0_color-mix(in_oklab,var(--ns-ink)_10%,transparent)] data-pressed:translate-y-px data-pressed:shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ns-ink)_14%,transparent),0_1px_0_color-mix(in_oklab,var(--ns-ink)_10%,transparent)] " +
    /* inside an inverse surface (data-ns-inverse) the same cap in the canvas's tints */
    "in-data-ns-inverse:bg-[color-mix(in_oklab,var(--ns-canvas)_16%,transparent)] in-data-ns-inverse:text-[color-mix(in_oklab,var(--ns-canvas)_82%,transparent)] in-data-ns-inverse:shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ns-canvas)_10%,transparent),0_2px_0_color-mix(in_oklab,var(--ns-canvas)_14%,transparent)] in-data-ns-inverse:data-pressed:shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ns-canvas)_10%,transparent),0_1px_0_color-mix(in_oklab,var(--ns-canvas)_14%,transparent)]",
  inverse: "bg-[color-mix(in_oklab,var(--ns-canvas)_16%,transparent)] text-inherit shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ns-canvas)_10%,transparent)]",
} as const;
const keyCapSurface = `${keyCap} ${keyCapTone.surface}`;

const never = () => () => {};
/* the small cap: shorter and narrower round the same glyph, its fill lighter */
const small = "h-4.5 min-w-4.5 px-1 bg-[color-mix(in_oklab,var(--ns-ink)_5%,transparent)] in-data-ns-inverse:bg-[color-mix(in_oklab,var(--ns-canvas)_12%,transparent)]";

/* the large cap (a stage, a shortcut taught on its own): 44 tall, 18px glyphs, a 3px skirt that shrinks to 1px as it sinks */
const large =
  "h-11 min-w-11 rounded-[10px] px-3 font-[family-name:var(--ns-font-body)] text-[18px] [text-box:normal] [--sk:3px] bg-[color-mix(in_oklab,var(--ns-ink)_5%,var(--ns-raised))] shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ns-ink)_9%,transparent),0_var(--sk)_0_color-mix(in_oklab,var(--ns-ink)_13%,transparent)] data-pressed:translate-y-[2px] data-pressed:bg-[color-mix(in_oklab,var(--ns-ink)_9%,var(--ns-raised))] data-pressed:shadow-[inset_0_0_0_1px_color-mix(in_oklab,var(--ns-ink)_12%,transparent),inset_0_1px_2px_rgb(0_0_0/0.14),0_1px_0_color-mix(in_oklab,var(--ns-ink)_13%,transparent)]";
/* tone ok: the chord landed; each cap lights the one green, left to right 40ms apart, with a small pop */
const lit =
  "[--sk:2px] bg-[var(--ns-btn-ok)] text-white shadow-[0_var(--sk)_0_color-mix(in_oklab,var(--ns-btn-ok)_62%,black)] data-pressed:bg-[var(--ns-btn-ok)] data-pressed:shadow-[0_1px_0_color-mix(in_oklab,var(--ns-btn-ok)_62%,black),inset_0_1px_2px_rgb(0_0_0/0.25)] [animation:ns-key-lit_340ms_var(--ns-ease-arrive)_both] motion-reduce:animate-none";

type KeyCapsProps = {
  keys: string;
  then?: string | undefined;
  /** true sinks every cap; "first" holds the first chord; a list sinks only the caps named (as printed: "⌘", "K") */
  held?: boolean | "first" | readonly string[] | undefined;
  size?: "sm" | "md" | "lg" | undefined;
  /** "ok": the shortcut ran; the caps light the one green, left to right */
  tone?: "neutral" | "ok" | undefined;
  labels?: Partial<KeyCapLabels> | undefined;
  className?: string | undefined;
  "data-slot"?: string | undefined;
};

/** The caps of a chord, or of a sequence with its "then" between; hidden on touch screens. */
function KeyCaps({ keys, then, held, size = "md", tone = "neutral", labels, className, "data-slot": slot = "keyboard-hint" }: KeyCapsProps) {
  const L = { ...KEY_CAP_LABELS, ...labels };
  /* the first render matches the server's (Ctrl) */
  const apple = React.useSyncExternalStore(never, isApple, () => false);
  const list = Array.isArray(held) ? (held as readonly string[]) : null;
  const chord = (k: string, down: boolean) => (
    <span className={size === "lg" ? "inline-flex gap-2" : "inline-flex gap-0.5"}>
      {capsOf(apple ? k : asCtrl(k)).map((c, i) => (
        <kbd key={i} data-slot="key-cap" data-pressed={(list ? list.includes(c) : down) ? "" : undefined} data-tone={tone === "ok" ? "ok" : undefined} data-ns-glide="" style={tone === "ok" ? { animationDelay: `${i * 40}ms` } : undefined} className={cn(keyCapSurface, size === "sm" && small, size === "lg" && large, tone === "ok" && lit)}>
          {c}
        </kbd>
      ))}
    </span>
  );
  return (
    <span data-slot={slot} className={cn("inline-flex shrink-0 items-center gap-1 pointer-coarse:hidden", className)}>
      {chord(keys, held === true || held === "first")}
      {then && (
        <>
          <span className="font-[family-name:var(--ns-font-body)] text-[length:var(--ns-text-meta)] text-[var(--ns-ink-2)] in-data-ns-inverse:text-[color-mix(in_oklab,var(--ns-canvas)_62%,transparent)]">{L.then}</span>
          {chord(then, held === true)}
        </>
      )}
    </span>
  );
}

export { asCtrl, capsOf, hintProps, isApple, KEY_CAP_LABELS, keyCap, keyCapTone, KeyCaps, type KeyCapLabels, type KeyCapsProps, type Shortcut };
```

### lib/notchset/layers.ts

```tsx
// Notchset shortcut-sheet 1.2.0 · https://notchset.dev/changelog
/*
 * The one layer scope: where each kind of surface stacks (the seven layer roles, foundation.css) and whose keys these
 * are. Whose keys: the one "is a layer open" and "is focus in a field" check every key handler reads (the
 * templates' keys, the shortcut sheet, the bulk bar, a toast's Undo key), so a key never fires under an open menu
 * or into a field in one place and not another.
 */

/** The layers that keep their keys while open over the page. */
const LAYER = "[data-slot=menu],[data-slot=popover],[data-slot=dialog],[data-slot=command-menu],[data-slot=bottom-sheet],[data-slot=date-picker-popup],[data-slot=reason-popover]";
/** What a key pressed inside belongs to: an open layer, or anything with a popup's role. */
const WITHIN = `${LAYER},[role=menu],[role=dialog],[role=listbox],[role=alertdialog]`;
/** Where a printable key types rather than commands. */
const FIELD = "input, textarea, select, [contenteditable=true], [contenteditable=''], [role=combobox]";

/** Whether a layer is open over the page. `also`: a template's own (Health's side panel holds its keys). */
export function layerOpen(also?: string): boolean {
  if (typeof document === "undefined") return false;
  return !!document.querySelector(also ? `${LAYER},${also}` : LAYER);
}

/** Whether a key's target sits inside an open layer (a menu, dialog or list keeps the keys pressed in it). */
export function inLayer(t: EventTarget | null): boolean {
  return !!(t as Element | null)?.closest?.(WITHIN);
}

/** Whether a key's target is a field being typed in. `also`: a template's own (Health's slider keeps its arrows). */
export function inField(t: EventTarget | null, also?: string): boolean {
  const el = t as HTMLElement | null;
  if (!el?.closest) return false;
  return el.isContentEditable || !!el.closest(also ? `${FIELD}, ${also}` : FIELD);
}

/**
 * Where each surface stacks, lowest first, as the class that places it (each reads its --ns-layer-* role, so an app
 * that moves one role moves every surface of that kind). Inside a piece, its parts stack with z-1 to z-4.
 */
export const layer = {
  sticky: "z-[var(--ns-layer-sticky)]",
  panel: "z-[var(--ns-layer-panel)]",
  bar: "z-[var(--ns-layer-bar)]",
  modal: "z-[var(--ns-layer-modal)]",
  /** a modal's own surface, just above its backdrop */
  modalSurface: "z-[calc(var(--ns-layer-modal)+1)]",
  popup: "z-[var(--ns-layer-popup)]",
  toast: "z-[var(--ns-layer-toast)]",
  tip: "z-[var(--ns-layer-tip)]",
} as const;
```

### lib/notchset/words.ts

```tsx
// Notchset shortcut-sheet 1.2.0 · https://notchset.dev/changelog
import * as React from "react";

/* Built-in words and figures, one way for every piece. */

/** The locale a piece writes in when the app passes none: English at launch, the same on the server and in the browser. */
export const DEFAULT_LOCALE = "en-US";

/** A count's words by the locale's plural rule: `other` always, any of the locale's other forms as it needs them. */
export type Plural = { other: string } & Partial<Record<Intl.LDMLPluralRule, string>>;

/** A whole number (or any figure) in the locale's digits and grouping. */
export function formatCount(n: number, locale: string = DEFAULT_LOCALE, options?: Intl.NumberFormatOptions): string {
  return new Intl.NumberFormat(locale, options).format(n);
}

/** A sentence with its `{name}` blanks filled; a blank with no value is left as written. */
export function fill(sentence: string, vars: Readonly<Record<string, string | number>>): string {
  return sentence.replace(/\{(\w+)\}/g, (blank, name: string) => (name in vars ? String(vars[name]) : blank));
}

/** The same, where a blank is a node (a name in ink): the sentence's own words stay in order around it. */
export function fillNodes(sentence: string, vars: Readonly<Record<string, React.ReactNode>>): React.ReactNode {
  return sentence.split(/(\{\w+\})/).map((part, i) => {
    const name = /^\{(\w+)\}$/.exec(part)?.[1];
    return name !== undefined && name in vars ? React.createElement(React.Fragment, { key: i }, vars[name]) : part;
  });
}

/** A count's sentence by the locale's plural rule, `{count}` written in the locale ("1 message", "4 messages"). */
export function plural(locale: string | undefined, n: number, forms: Plural, vars: Readonly<Record<string, string | number>> = {}): string {
  const loc = locale ?? DEFAULT_LOCALE;
  const rule = new Intl.PluralRules(loc).select(n);
  return fill(forms[rule] ?? forms.other, { count: formatCount(n, loc), ...vars });
}
```

The foundation (the tokens listed above, keyframes and motion levels) installs once with the first component; its CSS is public at https://notchset.dev/r/notchset-foundation.json.
