# Rolling clock (Notchset): prompt.md (v1.1.0)

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

Rolling number's clock form for every clock that ticks: m:ss or h:mm:ss in tabular Geist, the colon fixed. A changed digit turns one step the short way, up counting up and down counting down; h:mm:ss reserves its hour so it never widens. variant "time" shows a time of day, 24 or 12 hours..

## 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/rolling-clock.tsx`; shared code: `lib/notchset/motion.ts`.
- Registry dependencies, installed with it automatically: shadcn `utils` (cn), `notchset-foundation`.
- Builds: one set of files, the same for every shadcn style.
- Exports to keep: `ROLLING_CLOCK_LABELS`, `RollingClock`, `clockText`, 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.
- 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 { RollingClock } from "@/components/ui/notchset/rolling-clock";
```

## Parts
- A single export that takes props.

## Match the original
- Read `components/ui/notchset/rolling-clock.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
- A clock that ticks on its own (a session, a countdown, a run's elapsed time, a time of day).

### Not when
- A figure that changes because of what you did is Rolling number; a date is plain text.

## Built from
- Motion (shared helper, ships with it)

## Mistakes
- Ticking it inside the component: the host owns the time, and pauses it
- m:ss for a run that may pass an hour: pass format h:mm:ss so it never widens
- Using it for a figure you changed: that is Rolling number

## Usage

```tsx
"use client";
import * as React from "react";
import { RollingClock } from "@/components/ui/notchset/rolling-clock";
import { Spinner } from "@/components/ui/notchset/spinner";

/*
 * Three clocks ticking for real, as an app ticks them: a live session counting up in m:ss, a run's elapsed time in
 * h:mm:ss (its hour reserved, so the pill never widens), and an undo countdown that runs down to 0:00 and starts
 * again. Only the digits that change turn, the short way; the colon never moves. The knobs show the clock as a time
 * of day instead, in 24 or 12 hours, with or without its seconds.
 */
/* a second ticks on the second, so the clocks turn together */
function useTick() {
  const [n, setN] = React.useState(0);
  React.useEffect(() => {
    const id = window.setInterval(() => setN((x) => x + 1), 1000);
    return () => window.clearInterval(id);
  }, []);
  return n;
}

/* the time of day where the page is read, in seconds since midnight, ticking */
function useNow(tick: number) {
  const [start] = React.useState(() => {
    const d = new Date();
    return d.getHours() * 3600 + d.getMinutes() * 60 + d.getSeconds();
  });
  return start + tick;
}

export default function RollingClockDemo() {
  const shows = "duration" as "duration" | "time";
  const hourCycle = ("24" as string) === "12" ? 12 : 24;
  const seconds = true;
  const tick = useTick();
  const now = useNow(tick);
  const undo = 5 - (tick % 6);
  const [undone, setUndone] = React.useState(false);
  return (
    <div className="flex flex-col items-center gap-8 pb-12">
      <div className="flex flex-col items-center gap-2">
        <RollingClock
          variant={shows}
          seconds={shows === "time" ? now : 12 * 60 + 48 + tick}
          hourCycle={hourCycle}
          showSeconds={seconds}
          label={shows === "time" ? "Time now" : "Live session"}
          /* its digit windows reach 0.2em past the line: the room is laid out, so a turning digit never meets the caption */
          className="pb-[0.2em] font-[family-name:var(--ns-font-display)] text-[length:var(--ns-text-giant)] leading-none tracking-[var(--ns-tracking-display)] text-[var(--ns-ink)]"
        />
        <span className="text-[length:var(--ns-text-small)] text-[var(--ns-ink-3)]">{shows === "time" ? "Time now" : "Live session"}</span>
      </div>
      <span className="inline-flex items-center gap-2 rounded-[var(--ns-radius-full)] bg-[var(--ns-raised)] px-3 py-1.5 text-[length:var(--ns-text-small)] text-[var(--ns-ink)] shadow-[var(--ns-bezel)]">
        <Spinner size="sm" />
        Researching
        <RollingClock seconds={3757 + tick} format="h:mm:ss" label="Elapsed" className="text-[var(--ns-ink-2)]" />
      </span>
      <span className="inline-flex items-center gap-4 rounded-[var(--ns-radius-lg)] bg-[var(--ns-ink)] py-1.5 ps-4 pe-1.5 text-[length:var(--ns-text-small)] text-[var(--ns-canvas)] shadow-[var(--ns-shadow-float)]">
        {undone ? "Deal back in Negotiation" : "Deal marked lost"}
        {!undone && <RollingClock seconds={undo} label="Time left to undo" className="opacity-70" />}
        <button type="button" data-ns-press="" onClick={() => setUndone((u) => !u)} className="rounded-[var(--ns-radius-sm)] bg-[color-mix(in_oklab,var(--ns-canvas)_14%,transparent)] px-2.5 py-1 font-[number:var(--ns-weight-medium)] text-[var(--ns-canvas)] [transition:background-color_var(--ns-time-color)] hover:bg-[color-mix(in_oklab,var(--ns-canvas)_24%,transparent)]">
          {undone ? "Mark lost" : "Undo"}
        </button>
      </span>
    </div>
  );
}
```

This example also uses `spinner` (https://notchset.dev/components/spinner). Installing this item doesn't bring them; to paste the example as it is: `npx shadcn@latest add https://notchset.dev/r/rolling-clock.json https://notchset.dev/r/spinner.json`.

## Props

| Prop | Type | Default | What it does |
|---|---|---|---|
| `seconds` | `number` |  | the reading in whole seconds: a duration (elapsed or left), or with variant "time" the seconds since midnight |
| `variant` | `"duration" \| "time"` | `"duration"` | duration (the default): m:ss or h:mm:ss; time: a time of day |
| `format` | `"m:ss" \| "h:mm:ss"` | `"m:ss"` | a duration's form: m:ss (the default; past an hour it reads h:mm:ss) or h:mm:ss, its hour reserved from the start |
| `hourCycle` | `12 \| 24` | `24` | a time of day's hours: 24 (the default) or 12, with AM or PM after it |
| `showSeconds` | `boolean` | `false` | a time of day with its seconds (a duration always has them) |
| `label` | `string` |  | what the clock measures, for assistive tech ("Elapsed", "Time left to undo") |
| `labels` | `Partial<RollingClockLabels>` |  | the words for 12-hour time, English by default |

Full docs: https://notchset.dev/components/rolling-clock

## 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.

## Keyboard

| Keys | Action |
|---|---|
| Tab | passes over it: a reading, not a control |

## Performance

- Only a digit that changed animates, one transform each; a clock ticking every second animates one or two windows a second.
- No dependencies.

## Responsive

- phone and desktop
- dark (tokens)
- reduced motion: digits swap at once

## Motion inventory

| Interaction | What moves |
|---|---|
| a changed digit turns one step in its window, the short way | transform (Web Animation), --ns-time-roll, --ns-ease-panel. Reduced motion: swaps at once. |

## Accessibility contract (preserve when editing)
- role=timer named by label: read on request, never announced each second; one plain copy of the reading for assistive tech, the digit windows hidden.

## Install

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

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

### Manual

1. Install the packages: none beyond `react` and `react-dom`.
2. Copy `components/ui/notchset/rolling-clock.tsx`, `lib/notchset/motion.ts` from https://notchset.dev/r/rolling-clock.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`.

## Continue the workflow

- [Rolling number](https://notchset.dev/components/rolling-number)

## Source

### components/ui/notchset/rolling-clock.tsx

```tsx
// Notchset rolling-clock 1.1.0 · https://notchset.dev/changelog
"use client";
import * as React from "react";
import { cn } from "@/lib/utils";
import { lessMotion, roleTiming } from "@/lib/notchset/motion";

/* layout effects run as plain effects on the server, so React 18 server rendering stays silent */
const useIsomorphicLayoutEffect = typeof window === "undefined" ? React.useEffect : React.useLayoutEffect;

/*
 * Rolling clock: Rolling number's clock form, for every clock that ticks (a live session, a run's elapsed time without
 * its paused time, an undo countdown, a recording, a time of day). Tabular Geist, the colon fixed, each digit in its
 * own window. A digit that changes turns one step the short way: counting up the next digit comes in from below,
 * counting down it comes in from above, and 0:59 to 1:00 turns only the three digits that change while the colon
 * stays. Unchanged digits never move. h:mm:ss reserves its hour from the start, so a clock never grows a column
 * mid-count; m:ss carries on as h:mm:ss past an hour.
 *
 * It shows what it is given: the host ticks `seconds` (and stops ticking while a run is paused, so the clock holds
 * still). `variant="time"` reads `seconds` as the time since midnight and shows a time of day, 24-hour or 12-hour
 * (`hourCycle`), with or without its seconds. It is a timer to assistive tech (role="timer", never announced each
 * second), named by `label`. With less motion the digits swap at once.
 *
 *   <RollingClock seconds={elapsed} format="h:mm:ss" label="Elapsed" />
 *   <RollingClock seconds={left} label="Time left to undo" />
 *   <RollingClock variant="time" seconds={nowSeconds} hourCycle={12} />
 */
type RollingClockProps = {
  /** the reading in whole seconds: a duration (elapsed or left), or with variant "time" the seconds since midnight */
  seconds: number;
  /** duration (the default): m:ss or h:mm:ss; time: a time of day */
  variant?: "duration" | "time" | undefined;
  /** a duration's form: m:ss (the default; past an hour it reads h:mm:ss) or h:mm:ss, its hour reserved from the start */
  format?: "m:ss" | "h:mm:ss" | undefined;
  /** a time of day's hours: 24 (the default) or 12, with AM or PM after it */
  hourCycle?: 12 | 24 | undefined;
  /** a time of day with its seconds (a duration always has them) */
  showSeconds?: boolean | undefined;
  /** what the clock measures, for assistive tech ("Elapsed", "Time left to undo") */
  label?: string | undefined;
  /** the words for 12-hour time, English by default */
  labels?: Partial<RollingClockLabels> | undefined;
  className?: string | undefined;
};
type RollingClockLabels = { am: string; pm: string };
const ROLLING_CLOCK_LABELS: RollingClockLabels = { am: "AM", pm: "PM" };

const pad = (n: number) => String(n).padStart(2, "0");

/** The clock's reading as text: "0:04", "12:48", "1:02:37", "09:41", "9:41:07 PM". */
function clockText(seconds: number, { variant = "duration", format = "m:ss", hourCycle = 24, showSeconds = false, labels }: Omit<RollingClockProps, "seconds" | "label" | "className"> = {}): string {
  const L = { ...ROLLING_CLOCK_LABELS, ...labels };
  const s = Math.max(0, Math.floor(seconds));
  if (variant === "time") {
    const day = s % 86400;
    const h24 = Math.floor(day / 3600), m = Math.floor((day % 3600) / 60), sec = day % 60;
    const tail = showSeconds ? `:${pad(sec)}` : "";
    if (hourCycle === 12) return `${h24 % 12 || 12}:${pad(m)}${tail} ${h24 < 12 ? L.am : L.pm}`;
    return `${pad(h24)}:${pad(m)}${tail}`;
  }
  const h = Math.floor(s / 3600), m = Math.floor((s % 3600) / 60), sec = s % 60;
  if (format === "h:mm:ss" || h > 0) return `${h}:${pad(m)}:${pad(sec)}`;
  return `${m}:${pad(sec)}`;
}

type Dir = 1 | -1;

/* one digit in its window: a change turns one step, the new digit entering from below (counting up) or above (down) */
function Wheel({ d, dir }: { d: string; dir: Dir }) {
  const strip = React.useRef<HTMLSpanElement>(null);
  const [cells, setCells] = React.useState<{ from: string; to: string; dir: Dir; n: number }>({ from: d, to: d, dir, n: 0 });
  if (cells.to !== d) setCells({ from: cells.to, to: d, dir, n: cells.n + 1 });
  useIsomorphicLayoutEffect(() => {
    const el = strip.current;
    if (!el || cells.n === 0 || lessMotion(el)) return;
    /* up: the old digit sits on top and the strip rises to the new one; down: the new one waits above and drops in */
    const keys = cells.dir === 1 ? [{ transform: "translateY(0)" }, { transform: "translateY(-50%)" }] : [{ transform: "translateY(-50%)" }, { transform: "translateY(0)" }];
    el.animate?.(keys, roleTiming(el, "--ns-time-roll", "--ns-ease-panel"));
  }, [cells.n]);
  const pair = cells.dir === 1 ? [cells.from, cells.to] : [cells.to, cells.from];
  /* at rest the strip shows the digit: the second cell when it rose, the first when it dropped */
  const rest = cells.dir === 1 ? "translateY(-50%)" : "translateY(0)";
  return (
    /* the window is a line tall plus 0.2em above and below, given back by negative margins, as Rolling number's */
    <span aria-hidden data-ns-mask="" data-slot="rolling-clock-digit" data-digit={d} className="relative -my-[0.2em] inline-block h-[calc(1lh+0.4em)] overflow-hidden align-bottom select-none">
      <span ref={strip} className="absolute inset-x-0 top-0 flex flex-col will-change-transform" style={{ transform: rest }}>
        {pair.map((c, i) => (
          <span key={i} className="block h-[calc(1lh+0.4em)] py-[0.2em] text-center">
            {c}
          </span>
        ))}
      </span>
      <span className="invisible block py-[0.2em]">{d}</span>
    </span>
  );
}

function RollingClock({ seconds, variant = "duration", format = "m:ss", hourCycle = 24, showSeconds = false, label, labels, className }: RollingClockProps) {
  const text = clockText(seconds, { variant, format, hourCycle, showSeconds, labels });
  /* which way the reading moved: a time of day passing midnight still moves on */
  const [last, setLast] = React.useState({ s: seconds, dir: 1 as Dir });
  if (last.s !== seconds) {
    const delta = seconds - last.s;
    setLast({ s: seconds, dir: delta >= 0 || (variant === "time" && delta < -43200) ? 1 : -1 });
  }
  /* places are keyed from the right, so the seconds keep their wheel when an hour arrives at the left */
  const chars = [...text];
  return (
    <span data-slot="rolling-clock" role="timer" aria-label={label} className={cn("relative inline-flex tabular-nums", className)}>
      <span className="sr-only">{text}</span>
      <span aria-hidden className="inline-flex whitespace-nowrap">
        {chars.map((c, i) => {
          const key = chars.length - i;
          return /\d/.test(c) ? <Wheel key={key} d={c} dir={last.dir} /> : <span key={key} className="select-none">{c === " " ? " " : c}</span>;
        })}
      </span>
    </span>
  );
}

export { ROLLING_CLOCK_LABELS, RollingClock, clockText, type RollingClockLabels, type RollingClockProps };
```

### lib/notchset/motion.ts

```tsx
// Notchset rolling-clock 1.1.0 · https://notchset.dev/changelog
"use client";
/*
 * Less motion, the one switch every piece reads, and a motion role's timing for a Web Animation. Split from
 * physics.ts so a piece that needs only these does not carry the springs.
 */
import * as React from "react";

/**
 * Less motion where `el` sits: the device's setting, then a data-motion="reduced" on `el` or any ancestor, falling
 * back to <html>'s when there is no element. The one copy: every piece reads this.
 */
const REDUCED = '[data-motion="reduced"],[data-motion="off"]';
export function lessMotion(el?: Element | null): boolean {
  if (typeof document === "undefined") return true;
  if (typeof matchMedia !== "undefined" && matchMedia("(prefers-reduced-motion: reduce)").matches) return true;
  return !!(el?.closest?.(REDUCED) ?? document.documentElement.matches(REDUCED));
}

/** Less motion, kept current as the setting changes; true on a server, so a piece starts in its still. */
export function useLessMotion(): boolean {
  return React.useSyncExternalStore(
    (f) => {
      if (typeof matchMedia === "undefined") return () => {};
      const q = matchMedia("(prefers-reduced-motion: reduce)");
      q.addEventListener("change", f);
      const mo = typeof MutationObserver === "undefined" ? null : new MutationObserver(f);
      mo?.observe(document.documentElement, { attributes: true, attributeFilter: ["data-motion"] });
      return () => {
        q.removeEventListener("change", f);
        mo?.disconnect();
      };
    },
    () => lessMotion(),
    () => true,
  );
}

/** A motion role's duration and curve (0 under less motion: the result at once), read from the foundation where `el` sits, for a Web Animation that glides
    something CSS can't transition (a width to `auto`, a node on its way out): `roleTiming(el, "--ns-time-menu")`. */
export function roleTiming(el: Element, time: string, ease = "--ns-ease"): KeyframeAnimationOptions {
  if (lessMotion(el)) return { duration: 0, easing: "linear" };
  const cs = getComputedStyle(el);
  const t = cs.getPropertyValue(time).trim();
  const ms = t.endsWith("ms") ? parseFloat(t) : parseFloat(t) * 1000;
  return { duration: Number.isFinite(ms) ? ms : 0, easing: cs.getPropertyValue(ease).trim() || "linear" };
}

/** The foundation's curves as literal strings, for a Web Animation (`element.animate`, `KeyframeEffect`,
    `updateTiming`): those take a literal easing and throw on a CSS var. Copied from foundation.css's `--ns-ease-*`;
    CSS transitions and keyframes keep the vars. */
export const EASE = {
  enter: "cubic-bezier(0.22, 1, 0.36, 1)",
  move: "cubic-bezier(.5, 0, .2, 1)",
  exit: "cubic-bezier(.6, 0, .9, .5)",
  panel: "cubic-bezier(0.32, 0.72, 0, 1)",
  press: "cubic-bezier(0.2, 0, 0, 1)",
  spring: "cubic-bezier(0.16, 1, 0.3, 1)",
  arrive: "cubic-bezier(.3, 1.22, .5, 1)",
  breathe: "cubic-bezier(.45, 0, .55, 1)",
} as const;
```

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.
