{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"track-player","type":"registry:component","title":"Track player","description":"A small lacquered player: the disc turns, the waveform ripples and fills as it plays, and changing track drifts a veil of light across it.","author":"Hairline UI","dependencies":["lucide-react"],"registryDependencies":["https://hairlineui.com/r/text-morph.json?as=dependency"],"files":[{"path":"registry/track-player.tsx","type":"registry:component","content":"// Hairline UI · track-player · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { Pause, Play, SkipBack, SkipForward } from \"lucide-react\";\nimport { LACQUER, lacquer, mixTone, type LacquerTone } from \"./lacquer\";\nimport { LightSurface, type LightPaletteName, type LightSurfaceHandle } from \"./light-surface\";\nimport { TextMorph } from \"./text-morph\";\nimport { interactionIcon, useInteractionReducedMotion } from \"./ui-interaction-motion\";\n\n/* ─────────────────────────────────────────────────────────\n * TRACK PLAYER: a small lacquered player for music or a show\n *\n *   play     the disc turns, the waveform ripples gently along\n *            its length and fills white as the track plays\n *   scrub    drag along the waveform (or use the arrow keys);\n *            the fill and the times follow, and it carries on\n *            from there\n *   change   previous and next drift a soft veil of light across\n *            the player; under it the track, its lacquer colour\n *            and its disc change over\n *\n * Plays your audio when a track has a src; without one it keeps\n * its own clock, for previews. An object with its own dark finish:\n * the same on a light page or a dark one.\n *\n * Reduced motion: no ripple, no spin and no veil.\n * ───────────────────────────────────────────────────────── */\n\nexport interface PlayerTrack {\n  id: string;\n  title: string;\n  artist: string;\n  /** Seconds; the audio's own length replaces it once known. */\n  duration: number;\n  src?: string;\n  /** Loudness, 0 to 1 (or 0 to 100), any length; drawn as 48 bars. */\n  peaks?: number[];\n  /** This track's lacquer: a named tone or any CSS colour. */\n  tone?: LacquerTone | (string & {});\n  /** Top right: where it's playing. */\n  output?: string;\n  /** Cover art for the disc; a disc in the track's colour without one. */\n  art?: string;\n}\n\nexport interface TrackPlayerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"onChange\"> {\n  tracks: PlayerTrack[];\n  index?: number;\n  defaultIndex?: number;\n  onIndexChange?: (index: number) => void;\n  playing?: boolean;\n  defaultPlaying?: boolean;\n  onPlayingChange?: (playing: boolean) => void;\n  playingLabel?: string;\n  pausedLabel?: string;\n  /** Names the player for screen readers. */\n  label?: string;\n}\n\nconst BARS = 48;\nconst VEIL: Record<LacquerTone, LightPaletteName> = { ember: \"solar\", cobalt: \"azure\", rose: \"prism\", emerald: \"azure\", midnight: \"azure\", violet: \"dusk\" };\n\nconst time = (s: number) => {\n  const t = Math.max(0, Math.round(s));\n  return `${Math.floor(t / 60)}:${String(t % 60).padStart(2, \"0\")}`;\n};\n\n/** Peaks as 48 bar heights; without peaks, a steady made-up shape from the track's id so each track looks its own. */\nfunction barsFor(track: PlayerTrack) {\n  let src = track.peaks;\n  if (!src?.length) {\n    let h = 2166136261;\n    for (const ch of track.id) h = Math.imul(h ^ ch.charCodeAt(0), 16777619);\n    const rnd = () => ((h = Math.imul(h ^ (h >>> 15), 2246822507)) >>> 0) / 4294967296;\n    src = Array.from({ length: BARS }, (_, i) => 0.3 + 0.55 * Math.abs(Math.sin(i * 0.42 + rnd() * 2)) * (0.6 + 0.4 * rnd()));\n  }\n  const max = Math.max(...src, 1e-6);\n  return Array.from({ length: BARS }, (_, i) => {\n    const a = Math.floor((i * src.length) / BARS);\n    const b = Math.max(a + 1, Math.floor(((i + 1) * src.length) / BARS));\n    let sum = 0;\n    for (let j = a; j < b; j++) sum += src[j] ?? 0;\n    return Math.max(0.16, Math.min(1, sum / (b - a) / max));\n  });\n}\n\nfunction Wave({ heights, played, rippling, reduced }: { heights: number[]; played: boolean; rippling: boolean; reduced: boolean }) {\n  return (\n    <span className=\"flex h-full w-full items-center justify-between gap-[2px]\">\n      {heights.map((h, i) => (\n        <span\n          key={i}\n          className=\"block flex-1 rounded-full\"\n          style={{\n            height: `${h * 100}%`,\n            background: played ? \"#fff\" : \"rgb(255 255 255 / 0.28)\",\n            animation: reduced ? undefined : `ui-track-pulse 900ms ease-in-out ${-(i * 55)}ms infinite alternate`,\n            animationPlayState: rippling ? \"running\" : \"paused\",\n          }}\n        />\n      ))}\n    </span>\n  );\n}\n\nexport function TrackPlayer({\n  tracks,\n  index,\n  defaultIndex = 0,\n  onIndexChange,\n  playing,\n  defaultPlaying = false,\n  onPlayingChange,\n  playingLabel = \"Now playing\",\n  pausedLabel = \"Paused\",\n  label = \"Player\",\n  className = \"\",\n  style,\n  ...props\n}: TrackPlayerProps) {\n  const reduced = useInteractionReducedMotion();\n  const surface = React.useRef<LightSurfaceHandle>(null);\n  const audio = React.useRef<HTMLAudioElement>(null);\n  const wave = React.useRef<HTMLDivElement>(null);\n  const playedLayer = React.useRef<HTMLSpanElement>(null);\n  const [ownIndex, setOwnIndex] = React.useState(defaultIndex);\n  const [ownPlaying, setOwnPlaying] = React.useState(defaultPlaying);\n  const at = Math.max(0, Math.min(tracks.length - 1, index ?? ownIndex));\n  const isPlaying = playing ?? ownPlaying;\n  const track = tracks[at];\n  const [known, setKnown] = React.useState<Record<string, number>>({});\n  const duration = known[track.id] ?? track.duration;\n  const heights = React.useMemo(() => barsFor(track), [track]);\n  const [second, setSecond] = React.useState(0);\n  const [scrubbing, setScrubbing] = React.useState(false);\n  const clock = React.useRef({ t: 0, second: 0 });\n  const tone = track.tone ?? \"ember\";\n\n  const setPlaying = (p: boolean) => {\n    if (playing === undefined) setOwnPlaying(p);\n    onPlayingChange?.(p);\n  };\n  const setIndex = (i: number) => {\n    if (index === undefined) setOwnIndex(i);\n    onIndexChange?.(i);\n  };\n\n  /** Writes the fill straight to the clipped layer; the times re-render only when the whole second changes. */\n  const paint = React.useCallback(\n    (t: number) => {\n      clock.current.t = t;\n      const pct = duration > 0 ? Math.max(0, Math.min(1, t / duration)) : 0;\n      if (playedLayer.current) playedLayer.current.style.clipPath = `inset(0 ${(100 - pct * 100).toFixed(3)}% 0 0)`;\n      const s = Math.floor(t);\n      if (s !== clock.current.second) {\n        clock.current.second = s;\n        setSecond(s);\n      }\n    },\n    [duration],\n  );\n\n  React.useLayoutEffect(() => {\n    paint(clock.current.t);\n  }, [paint]);\n\n  // Playing: the audio's own clock when there is a src, otherwise one of our own.\n  React.useEffect(() => {\n    const el = audio.current;\n    if (track.src && el) {\n      if (isPlaying) void el.play().catch(() => setPlaying(false));\n      else el.pause();\n    }\n    if (!isPlaying || scrubbing) return;\n    let raf = 0;\n    let last = 0;\n    const tick = (now: number) => {\n      const dt = last ? (now - last) / 1000 : 0;\n      last = now;\n      let t = track.src && el ? el.currentTime : clock.current.t + dt;\n      if (t >= duration) {\n        t = 0;\n        if (el && track.src) el.currentTime = 0;\n        paint(0);\n        setPlaying(false);\n        return;\n      }\n      paint(t);\n      raf = requestAnimationFrame(tick);\n    };\n    raf = requestAnimationFrame(tick);\n    return () => cancelAnimationFrame(raf);\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [isPlaying, scrubbing, track.id, track.src, duration, paint]);\n\n  const go = (delta: number) => {\n    const next = (at + delta + tracks.length) % tracks.length;\n    const land = () => {\n      setIndex(next);\n      clock.current.second = -1;\n      paint(0);\n      if (audio.current) audio.current.currentTime = 0;\n    };\n    const s = surface.current;\n    if (!s || reduced) return land();\n    const t = tracks[next].tone ?? \"ember\";\n    s.wave({ direction: \"diagonal\", palette: t in LACQUER ? VEIL[t as LacquerTone] : \"prism\", duration: 1020, onMidpoint: land });\n  };\n\n  const seekFrom = (clientX: number) => {\n    const r = wave.current?.getBoundingClientRect();\n    if (!r) return;\n    paint(Math.max(0, Math.min(1, (clientX - r.left) / r.width)) * duration);\n  };\n  const commitSeek = () => {\n    if (audio.current && track.src) audio.current.currentTime = clock.current.t;\n  };\n\n  const disc = track.art\n    ? undefined\n    : `conic-gradient(from 40deg, ${mixTone(tone, 1, \"#000000\")}, ${mixTone(tone, 0.55, \"#ffffff\")}, ${mixTone(tone, 0.7, \"#000000\")}, ${mixTone(tone, 0.75, \"#ffd36b\")}, ${mixTone(tone, 0.6, \"#6be4ff\")}, ${mixTone(tone, 1, \"#000000\")})`;\n\n  return (\n    <LightSurface\n      ref={surface}\n      direction=\"diagonal\"\n      veil=\"#05050a\"\n      role=\"group\"\n      aria-label={`${label}: ${track.title} by ${track.artist}`}\n      className={`w-full rounded-[22px] select-none ${className}`}\n      style={{ ...lacquer(tone), ...style }}\n      {...props}\n    >\n      {track.src && (\n        <audio\n          ref={audio}\n          src={track.src}\n          preload=\"metadata\"\n          onLoadedMetadata={(e) => {\n            const d = e.currentTarget.duration;\n            if (Number.isFinite(d) && d > 0) setKnown((k) => (k[track.id] === d ? k : { ...k, [track.id]: d }));\n          }}\n        />\n      )}\n      <div className=\"@container flex flex-col gap-4 px-5 py-4\">\n        <div className=\"flex items-center justify-between gap-2 text-[11px] font-medium text-white/75\">\n          <TextMorph>{isPlaying ? playingLabel : pausedLabel}</TextMorph>\n          {track.output && <span className=\"truncate font-mono text-[10.5px] text-white/65\">{track.output}</span>}\n        </div>\n\n        <div className=\"flex flex-col items-stretch gap-3 @[18rem]:flex-row @[18rem]:items-center @[18rem]:justify-between @[18rem]:gap-2.5\">\n          <div className=\"flex min-w-0 items-center gap-3\">\n            <span\n              aria-hidden\n              className=\"relative grid size-11 shrink-0 animate-spin place-items-center overflow-clip rounded-full\"\n              style={{\n                background: disc,\n                boxShadow: \"inset 0 0 0 1px rgb(255 255 255 / 0.25)\",\n                animationDuration: \"6s\",\n                animationPlayState: isPlaying && !reduced ? \"running\" : \"paused\",\n              }}\n            >\n              {track.art && <img src={track.art} alt=\"\" className=\"absolute inset-0 size-full object-cover\" />}\n              <span className=\"absolute inset-0 rounded-full\" style={{ background: \"linear-gradient(135deg, rgb(255 255 255 / 0.42) 0%, transparent 45%, rgb(0 0 0 / 0.24) 100%)\" }} />\n              <span className=\"relative size-3 rounded-full bg-[#0d0707]\" style={{ boxShadow: \"inset 0 0 0 1px rgb(255 255 255 / 0.35)\" }} />\n            </span>\n            <div className=\"min-w-0\">\n              <div className=\"truncate text-[14.5px] font-semibold leading-snug tracking-[-0.015em] text-white\">{track.title}</div>\n              <div className=\"truncate text-[12px] text-white/65\">{track.artist}</div>\n            </div>\n          </div>\n          <div className=\"flex shrink-0 items-center justify-center gap-1.5 @[18rem]:justify-end\">\n            <button\n              type=\"button\"\n              onClick={() => go(-1)}\n              aria-label=\"Previous track\"\n              className=\"grid size-7 cursor-pointer place-items-center rounded-full bg-white/12 text-white/90 outline-none transition-[background-color,scale] duration-150 hover:bg-white/22 focus-visible:ring-2 focus-visible:ring-white/70 active:scale-[0.92]\"\n            >\n              <SkipBack className=\"size-3 fill-current\" aria-hidden />\n            </button>\n            <button\n              type=\"button\"\n              onClick={() => setPlaying(!isPlaying)}\n              aria-label={isPlaying ? \"Pause\" : \"Play\"}\n              className=\"grid size-8 cursor-pointer place-items-center rounded-full bg-white text-[#12090a] outline-none transition-[scale] duration-150 focus-visible:ring-2 focus-visible:ring-white/85 active:scale-[0.93]\"\n            >\n              <span className=\"grid place-items-center [grid-area:1/1]\" style={interactionIcon(isPlaying, reduced)}>\n                <Pause className=\"size-3.5 fill-current\" aria-hidden />\n              </span>\n              <span className=\"grid place-items-center [grid-area:1/1]\" style={interactionIcon(!isPlaying, reduced)}>\n                <Play className=\"size-3.5 translate-x-px fill-current\" aria-hidden />\n              </span>\n            </button>\n            <button\n              type=\"button\"\n              onClick={() => go(1)}\n              aria-label=\"Next track\"\n              className=\"grid size-7 cursor-pointer place-items-center rounded-full bg-white/12 text-white/90 outline-none transition-[background-color,scale] duration-150 hover:bg-white/22 focus-visible:ring-2 focus-visible:ring-white/70 active:scale-[0.92]\"\n            >\n              <SkipForward className=\"size-3 fill-current\" aria-hidden />\n            </button>\n          </div>\n        </div>\n\n        <div>\n          <div\n            ref={wave}\n            role=\"slider\"\n            tabIndex={0}\n            aria-label=\"Position\"\n            aria-valuemin={0}\n            aria-valuemax={Math.round(duration)}\n            aria-valuenow={second}\n            aria-valuetext={`${time(second)} of ${time(duration)}`}\n            onPointerDown={(e) => {\n              e.currentTarget.setPointerCapture(e.pointerId);\n              setScrubbing(true);\n              seekFrom(e.clientX);\n            }}\n            onPointerMove={(e) => scrubbing && seekFrom(e.clientX)}\n            onPointerUp={() => {\n              commitSeek();\n              setScrubbing(false);\n            }}\n            onPointerCancel={() => setScrubbing(false)}\n            onKeyDown={(e) => {\n              const by = { ArrowRight: 5, ArrowUp: 5, ArrowLeft: -5, ArrowDown: -5, PageUp: 15, PageDown: -15 }[e.key];\n              const to = by !== undefined ? clock.current.t + by : e.key === \"Home\" ? 0 : e.key === \"End\" ? duration - 0.5 : null;\n              if (to === null) return;\n              e.preventDefault();\n              paint(Math.max(0, Math.min(duration, to)));\n              commitSeek();\n            }}\n            className=\"relative h-9 w-full cursor-pointer touch-none rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-white/60\"\n          >\n            <Wave heights={heights} played={false} rippling={isPlaying && !scrubbing} reduced={reduced} />\n            <span ref={playedLayer} aria-hidden className=\"pointer-events-none absolute inset-0\" style={{ clipPath: \"inset(0 100% 0 0)\" }}>\n              <Wave heights={heights} played rippling={isPlaying && !scrubbing} reduced={reduced} />\n            </span>\n          </div>\n          <div className=\"mt-1 flex items-center justify-between font-mono text-[10.5px] tabular-nums text-white/65\">\n            <span>{time(second)}</span>\n            <span>-{time(Math.max(0, duration - second))}</span>\n          </div>\n        </div>\n      </div>\n      <span className=\"sr-only\" aria-live=\"polite\">\n        {`${track.title} by ${track.artist}`}\n      </span>\n    </LightSurface>\n  );\n}\n"},{"path":"registry/lacquer.ts","type":"registry:component","content":"// Hairline UI · track-player · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n/* ─────────────────────────────────────────────────────────\n * LACQUER: the dark surface of Pillar chart, Stage timeline and\n * Track player\n *\n * These cards are objects with their own finish, like a device\n * screen or a lacquered box: always dark, the same on a light page\n * or a dark one. The colour pools in from two corners over a near\n * black, with a fine light along the top edge and a dark one along\n * the bottom; no drop shadow.\n *\n * Named tones are mixed here into plain rgba() so every browser\n * paints them (Safari dropped color-mix() inside these gradients);\n * a solid near-black sits under the gradients either way, so the\n * card can never come out light.\n * ───────────────────────────────────────────────────────── */\n\nimport type * as React from \"react\";\n\nexport type LacquerTone = \"cobalt\" | \"ember\" | \"rose\" | \"emerald\" | \"midnight\" | \"violet\";\n\nexport const LACQUER: Record<LacquerTone, string> = {\n  cobalt: \"#3462eb\",\n  ember: \"#ce3e1a\",\n  rose: \"#d0306c\",\n  emerald: \"#0f9f74\",\n  midnight: \"#3a4fd6\",\n  violet: \"#7e22f5\",\n};\n\n/** Any named tone or CSS colour, as the colour the lacquer is mixed from. */\nexport const toneColor = (tone: LacquerTone | (string & {})) => (tone in LACQUER ? LACQUER[tone as LacquerTone] : tone);\n\nconst BASE = \"#060609\";\n\ntype Rgb = [number, number, number];\nconst hex = (h: string): Rgb | null => {\n  const m = /^#([0-9a-f]{6})$/i.exec(h.trim());\n  return m ? [parseInt(m[1].slice(0, 2), 16), parseInt(m[1].slice(2, 4), 16), parseInt(m[1].slice(4, 6), 16)] : null;\n};\nconst rgba = ([r, g, b]: Rgb, a = 1) => `rgba(${Math.round(r)}, ${Math.round(g)}, ${Math.round(b)}, ${a})`;\nconst blend = (a: Rgb, b: Rgb, t: number): Rgb => [a[0] * t + b[0] * (1 - t), a[1] * t + b[1] * (1 - t), a[2] * t + b[2] * (1 - t)];\n\n/**\n * A tone mixed with another colour: `share` of the tone (0 to 1). Plain rgba() for hex colours (named tones included);\n * anything else (oklch(), a theme variable) falls back to color-mix(), which needs a browser that paints it.\n */\nexport function mixTone(tone: LacquerTone | (string & {}), share: number, other: \"transparent\" | (string & {}) = \"transparent\") {\n  const t = hex(toneColor(tone));\n  const o = other === \"transparent\" ? null : hex(other);\n  if (t && other === \"transparent\") return rgba(t, share);\n  if (t && o) return rgba(blend(t, o, share));\n  return `color-mix(in oklab, ${toneColor(tone)} ${Math.round(share * 100)}%, ${other})`;\n}\n\n/** The lacquer as inline styles: background, the lit top edge and a hairline border. Text on it is white. */\nexport function lacquer(tone: LacquerTone | (string & {})): React.CSSProperties {\n  const m = (share: number, over: \"transparent\" | (string & {}) = \"transparent\") => mixTone(tone, share, over);\n  return {\n    background: [\n      `radial-gradient(88% 78% at 10% 8%, ${m(0.74)} 0%, ${m(0.32)} 46%, transparent 76%)`,\n      `radial-gradient(82% 76% at 92% 96%, ${m(0.6)} 0%, ${m(0.26)} 52%, transparent 80%)`,\n      `linear-gradient(150deg, ${m(0.34, BASE)} 0%, ${m(0.09, BASE)} 52%, ${m(0.28, BASE)} 100%)`,\n    ].join(\", \"),\n    // Set after the shorthand, so a gradient a browser can't paint still leaves the card dark.\n    backgroundColor: BASE,\n    boxShadow: \"inset 0 1px 0 rgb(255 255 255 / 0.26), inset 0 -1px 0 rgb(0 0 0 / 0.35)\",\n    border: \"1px solid rgb(255 255 255 / 0.14)\",\n    color: \"#fff\",\n    colorScheme: \"dark\",\n  };\n}\n"},{"path":"registry/light-surface.tsx","type":"registry:component","content":"// Hairline UI · track-player · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\n\n/* ─────────────────────────────────────────────────────────\n * LIGHT SURFACE: the card the light runs through\n *\n *   wave     a band of light crosses the surface: a thin crest\n *            ring from a point (radial), a ribbon scanning left\n *            to right (horizontal), or a wide soft veil drifting\n *            across (diagonal); the content defocuses under it,\n *            your change lands at the peak, and starlight dust\n *            trails behind and fades\n *   charge   while something is held, light gathers toward the\n *            finger and the dust is pulled in; let go and it\n *            relaxes\n *   lit      a surface that's \"on\" keeps its light in the rim:\n *            colour bleeding in from the corners and a fine\n *            prismatic bezel, brighter just after a wave\n *\n * Shared by Status capsule, Hold to start, Level dial and Scene\n * mixer. Dark surfaces add the light; light surfaces get it as\n * colour.\n *\n * Reduced motion: no waves, no charge; changes land at once.\n * ───────────────────────────────────────────────────────── */\n\nexport type LightPaletteName = \"azure\" | \"solar\" | \"prism\" | \"dusk\";\n\nexport interface LightPalette {\n  /** Leading fringe of the wavefront. */\n  outerFringe: string;\n  /** The bright core of the wavefront. */\n  core: string;\n  /** Trailing band of colour. */\n  innerFringe: string;\n  /** The wash behind the wavefront. */\n  ambient: string;\n  /** Dust colours. */\n  sparkle: readonly [string, string, string];\n  /** Rim light, from the corners. */\n  rimPrimary: string;\n  rimSecondary: string;\n  rimAccent: string;\n  /** A solid colour for text and marks that follow the palette. */\n  ink: string;\n  /** How strong the wave is, 0 to 1. */\n  strength: number;\n}\n\nexport const LIGHT_PALETTES: Record<LightPaletteName, LightPalette> = {\n  // A crisp azure scan.\n  azure: {\n    outerFringe: \"rgba(56, 189, 248, 0.94)\",\n    core: \"rgba(240, 249, 255, 0.98)\",\n    innerFringe: \"rgba(37, 99, 235, 0.88)\",\n    ambient: \"rgba(14, 165, 233, 0.38)\",\n    sparkle: [\"#FFFFFF\", \"#BAE6FD\", \"#93C5FD\"],\n    rimPrimary: \"rgba(96, 185, 255, 0.64)\",\n    rimSecondary: \"rgba(59, 130, 246, 0.58)\",\n    rimAccent: \"rgba(186, 230, 253, 0.46)\",\n    ink: \"#3b82f6\",\n    strength: 0.95,\n  },\n  // Warm apricot and rose.\n  solar: {\n    outerFringe: \"rgba(244, 114, 146, 0.68)\",\n    core: \"rgba(255, 250, 234, 0.92)\",\n    innerFringe: \"rgba(251, 166, 92, 0.76)\",\n    ambient: \"rgba(251, 191, 96, 0.36)\",\n    sparkle: [\"#FFFFFF\", \"#FCD9A4\", \"#FBB6C8\"],\n    rimPrimary: \"rgba(251, 178, 102, 0.7)\",\n    rimSecondary: \"rgba(238, 126, 162, 0.62)\",\n    rimAccent: \"rgba(251, 204, 116, 0.54)\",\n    ink: \"#f59e0b\",\n    strength: 0.86,\n  },\n  // Pearl: champagne, rose and sky.\n  prism: {\n    outerFringe: \"rgba(246, 146, 196, 0.72)\",\n    core: \"rgba(255, 250, 236, 0.92)\",\n    innerFringe: \"rgba(96, 195, 248, 0.64)\",\n    ambient: \"rgba(251, 200, 114, 0.36)\",\n    sparkle: [\"#FFFFFF\", \"#FDE6B0\", \"#FFD6E8\"],\n    rimPrimary: \"rgba(250, 204, 116, 0.68)\",\n    rimSecondary: \"rgba(240, 140, 190, 0.66)\",\n    rimAccent: \"rgba(104, 188, 248, 0.5)\",\n    ink: \"#ec4899\",\n    strength: 0.88,\n  },\n  // A soft evening veil: rose and cornflower.\n  dusk: {\n    outerFringe: \"rgba(240, 150, 200, 0.5)\",\n    core: \"rgba(255, 246, 250, 0.7)\",\n    innerFringe: \"rgba(120, 160, 248, 0.48)\",\n    ambient: \"rgba(230, 150, 200, 0.22)\",\n    sparkle: [\"#FFFFFF\", \"#FFE4F0\", \"#D8E4FF\"],\n    rimPrimary: \"rgba(240, 150, 200, 0.6)\",\n    rimSecondary: \"rgba(120, 160, 248, 0.56)\",\n    rimAccent: \"rgba(250, 210, 228, 0.42)\",\n    ink: \"#6b8af6\",\n    strength: 0.64,\n  },\n};\n\nexport type LightDirection = \"radial\" | \"horizontal\" | \"diagonal\";\n/** A point inside the surface, 0 to 1 on each axis. */\nexport type LightPoint = { x: number; y: number };\n\nexport interface LightWaveOptions {\n  origin?: LightPoint;\n  direction?: LightDirection;\n  palette?: LightPaletteName | LightPalette;\n  /** ms; the default suits the direction. */\n  duration?: number;\n  /** Called once, when the content is most out of focus: change your state here. */\n  onMidpoint?: () => void;\n  onComplete?: () => void;\n}\n\nexport interface LightSurfaceHandle {\n  wave: (options?: LightWaveOptions) => void;\n  /** 0 to 1 while something is held; 0 lets the light relax. */\n  charge: (level: number, origin?: LightPoint) => void;\n  /** Whether a wave is crossing right now. */\n  busy: () => boolean;\n  element: () => HTMLDivElement | null;\n}\n\nexport const resolvePalette = (p: LightPaletteName | LightPalette | undefined, fallback: LightPaletteName = \"azure\") =>\n  typeof p === \"object\" ? p : LIGHT_PALETTES[p ?? fallback] ?? LIGHT_PALETTES[fallback];\n\nexport const clamp = (v: number, a: number, b: number) => (v < a ? a : v > b ? b : v);\nexport const easeOutCubic = (t: number) => 1 - (1 - clamp(t, 0, 1)) ** 3;\nexport const easeOutQuart = (t: number) => 1 - (1 - clamp(t, 0, 1)) ** 4;\n\nconst reducedQuery = \"(prefers-reduced-motion: reduce)\";\nexport const prefersReducedMotion = () => typeof window !== \"undefined\" && window.matchMedia(reducedQuery).matches;\nconst subscribeReduced = (onChange: () => void) => {\n  const query = window.matchMedia(reducedQuery);\n  query.addEventListener(\"change\", onChange);\n  return () => query.removeEventListener(\"change\", onChange);\n};\nexport const useLightReducedMotion = () => React.useSyncExternalStore(subscribeReduced, () => window.matchMedia(reducedQuery).matches, () => false);\n\n/** Focus, light and dust over a wave's progress (0 to 1): the change lands at 36%, at the deepest defocus. */\nexport function opticsAt(progress: number) {\n  const p = clamp(progress, 0, 1);\n  const swap = 0.36;\n  const focus = p < swap ? Math.sin((p / swap) * (Math.PI / 2)) : p < 0.86 ? Math.cos(((p - swap) / (0.86 - swap)) * (Math.PI / 2)) ** 1.35 : 0;\n  const wave = p < 0.16 ? Math.sin((p / 0.16) * (Math.PI / 2)) : (1 - (p - 0.16) / 0.84) ** 1.9;\n  const dust = p < 0.18 ? p / 0.18 : p < 0.5 ? 1 : (1 - (p - 0.5) / 0.5) ** 1.75;\n  return { blur: focus * 7.8, scale: 1 - focus * 0.01, swapped: p >= swap, wave: clamp(wave, 0, 1), dust: clamp(dust, 0, 1), veil: focus * 0.24 };\n}\n\nlet probe: CanvasRenderingContext2D | null = null;\n/** A light surface has dark text on it, judged from its own text colour (read back from a 1px canvas, so any colour syntax works). */\nexport function isLightSurface(el: Element) {\n  probe ??= document.createElement(\"canvas\").getContext(\"2d\", { willReadFrequently: true });\n  if (!probe) return false;\n  probe.clearRect(0, 0, 1, 1);\n  probe.fillStyle = \"#fff\";\n  probe.fillStyle = getComputedStyle(el).color;\n  probe.fillRect(0, 0, 1, 1);\n  const [r, g, b] = probe.getImageData(0, 0, 1, 1).data;\n  return 0.2126 * r + 0.7152 * g + 0.0722 * b < 140;\n}\n\nconst DURATION: Record<LightDirection, number> = { radial: 1400, horizontal: 1180, diagonal: 1360 };\nconst DUST = 195;\n\ntype Dust = { x: number; y: number; size: number; phase: number; twinkle: number; tone: 0 | 1 | 2; star: boolean };\nconst makeDust = (): Dust[] =>\n  Array.from({ length: DUST }, (_, i) => ({\n    x: Math.random(),\n    y: Math.random(),\n    size: 0.5 + Math.random() * 1.15,\n    phase: Math.random() * Math.PI * 2,\n    twinkle: 5 + Math.random() * 8,\n    tone: (i % 3) as 0 | 1 | 2,\n    star: i % 10 === 0,\n  }));\n\n/** On a light surface white light disappears, so the core takes the fringe colour and the dust its coloured tones. */\nconst inkFor = (p: LightPalette, light: boolean): LightPalette =>\n  light ? { ...p, core: p.outerFringe, sparkle: [p.sparkle[2], p.sparkle[1], p.sparkle[2]], strength: p.strength * 0.9 } : p;\n\nfunction starGlint(ctx: CanvasRenderingContext2D, x: number, y: number, arm: number, color: string, alpha: number) {\n  ctx.save();\n  ctx.globalAlpha = alpha;\n  ctx.strokeStyle = color;\n  ctx.lineWidth = 0.7;\n  ctx.beginPath();\n  ctx.moveTo(x - arm, y);\n  ctx.lineTo(x + arm, y);\n  ctx.moveTo(x, y - arm);\n  ctx.lineTo(x, y + arm);\n  ctx.stroke();\n  ctx.restore();\n}\n\ntype Wave = Required<Pick<LightWaveOptions, \"origin\" | \"direction\" | \"duration\">> & {\n  palette: LightPalette;\n  start: number;\n  swapped: boolean;\n  onMidpoint?: () => void;\n  onComplete?: () => void;\n};\n\ntype Settings = { palette: LightPalette; direction: LightDirection; duration: number };\n\nfunction createEngine(get: { root: () => HTMLDivElement | null; content: () => HTMLDivElement | null; veil: () => HTMLDivElement | null; canvas: () => HTMLCanvasElement | null; settings: () => Settings; settle: (on: boolean) => void }) {\n  let raf = 0;\n  let wave: Wave | null = null;\n  let level = 0;\n  let target = 0;\n  let chargeOrigin: LightPoint = { x: 0.5, y: 0.88 };\n  let last = 0;\n  let dust = makeDust();\n  let light = false;\n  let settleTimer = 0;\n  let w = 0;\n  let h = 0;\n  let dpr = 1;\n\n  const measure = () => {\n    const root = get.root();\n    const canvas = get.canvas();\n    if (!root || !canvas) return false;\n    w = root.offsetWidth;\n    h = root.offsetHeight;\n    dpr = Math.min(2, window.devicePixelRatio || 1);\n    const pw = Math.max(1, Math.round(w * dpr));\n    const ph = Math.max(1, Math.round(h * dpr));\n    if (canvas.width !== pw) canvas.width = pw;\n    if (canvas.height !== ph) canvas.height = ph;\n    light = isLightSurface(root);\n    return w > 0 && h > 0;\n  };\n\n  const idle = () => {\n    cancelAnimationFrame(raf);\n    raf = 0;\n    const canvas = get.canvas();\n    canvas?.getContext(\"2d\")?.clearRect(0, 0, canvas.width, canvas.height);\n    const content = get.content();\n    if (content) {\n      content.style.filter = \"\";\n      content.style.transform = \"\";\n      content.style.willChange = \"\";\n    }\n    const veil = get.veil();\n    if (veil) veil.style.opacity = \"0\";\n  };\n\n  const frame = (now: number) => {\n    const canvas = get.canvas();\n    const ctx = canvas?.getContext(\"2d\");\n    const content = get.content();\n    if (!canvas || !ctx) return idle();\n    const dt = last ? Math.min(64, now - last) : 16;\n    last = now;\n    // The charge follows the hand up at once and relaxes back down over about 220ms.\n    level = target >= level ? target : Math.max(target, level - dt / 220);\n\n    ctx.save();\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    ctx.clearRect(0, 0, w, h);\n    ctx.globalCompositeOperation = light ? \"source-over\" : \"lighter\";\n\n    if (level > 0.01 && !wave) drawCharge(ctx, now, content);\n    if (wave) drawWave(ctx, now, wave, content);\n\n    ctx.restore();\n    if (wave || level > 0.005) raf = requestAnimationFrame(frame);\n    else idle();\n  };\n\n  const drawCharge = (ctx: CanvasRenderingContext2D, now: number, content: HTMLDivElement | null) => {\n    const p = inkFor(get.settings().palette, light);\n    const cx = chargeOrigin.x * w;\n    const cy = chargeOrigin.y * h;\n    const lv = clamp(level, 0, 1);\n    // A halo that contracts toward the finger as the charge builds.\n    const ring = Math.hypot(w, h) * 0.54 * (1 - lv * 0.72) + 26;\n    const band = 44 * (0.7 + lv * 0.35);\n    const g = ctx.createRadialGradient(cx, cy, Math.max(0, ring - band), cx, cy, ring + band);\n    g.addColorStop(0, \"rgba(0,0,0,0)\");\n    g.addColorStop(0.32, p.innerFringe);\n    g.addColorStop(0.54, p.core);\n    g.addColorStop(0.76, p.outerFringe);\n    g.addColorStop(1, \"rgba(0,0,0,0)\");\n    ctx.globalAlpha = (0.16 + lv * 0.38) * p.strength;\n    ctx.fillStyle = g;\n    ctx.fillRect(0, 0, w, h);\n    // A soft core under the finger.\n    const coreR = 20 + lv * 72;\n    const cg = ctx.createRadialGradient(cx, cy, 0, cx, cy, coreR);\n    cg.addColorStop(0, p.core);\n    cg.addColorStop(0.5, p.outerFringe);\n    cg.addColorStop(1, \"rgba(0,0,0,0)\");\n    ctx.globalAlpha = 0.16 + lv * 0.42;\n    ctx.fillStyle = cg;\n    ctx.beginPath();\n    ctx.arc(cx, cy, coreR, 0, Math.PI * 2);\n    ctx.fill();\n    // Dust pulled in toward the finger, stars streaking once it's past half.\n    for (const d of dust) {\n      const px = d.x * w;\n      const py = d.y * h;\n      const dx = cx - px;\n      const dy = cy - py;\n      const dist = Math.hypot(dx, dy) || 1;\n      const pull = lv * lv * 0.34;\n      const x = px + dx * pull;\n      const y = py + dy * pull;\n      ctx.globalAlpha = lv * (0.4 + 0.6 * Math.sin(now * 0.011 + d.phase)) * 0.68;\n      ctx.fillStyle = p.sparkle[d.tone];\n      ctx.beginPath();\n      ctx.arc(x, y, d.size * (0.7 + lv * 0.4), 0, Math.PI * 2);\n      ctx.fill();\n      if (lv > 0.5 && d.star) {\n        ctx.strokeStyle = p.sparkle[0];\n        ctx.lineWidth = 0.7;\n        ctx.globalAlpha = (lv - 0.5) * 0.55;\n        ctx.beginPath();\n        ctx.moveTo(x, y);\n        ctx.lineTo(x - (dx / dist) * 7 * lv, y - (dy / dist) * 7 * lv);\n        ctx.stroke();\n      }\n    }\n    if (content) {\n      content.style.willChange = \"transform, filter\";\n      content.style.transform = `scale(${(1 - lv * 0.012).toFixed(4)})`;\n      content.style.filter = `blur(${(lv * 1.1).toFixed(2)}px)`;\n    }\n  };\n\n  const drawWave = (ctx: CanvasRenderingContext2D, now: number, wv: Wave, content: HTMLDivElement | null) => {\n    const raw = clamp((now - wv.start) / wv.duration, 0, 1);\n    const o = opticsAt(raw);\n    if (o.swapped && !wv.swapped) {\n      wv.swapped = true;\n      wv.onMidpoint?.();\n    }\n    if (content) {\n      content.style.willChange = \"transform, filter\";\n      content.style.filter = o.blur > 0.05 ? `blur(${o.blur.toFixed(2)}px)` : \"\";\n      content.style.transform = Math.abs(o.scale - 1) > 0.0005 ? `scale(${o.scale.toFixed(4)})` : \"\";\n    }\n    const veil = get.veil();\n    if (veil) veil.style.opacity = o.veil.toFixed(3);\n    const p = inkFor(wv.palette, light);\n\n    if (wv.direction === \"horizontal\") {\n      // A ribbon of light scanning left to right, catching the top and bottom edges as it passes.\n      const x = -w * 0.14 + easeOutCubic(raw) * w * 1.28;\n      const half = Math.max(46, w * 0.14);\n      const g = ctx.createLinearGradient(x - half * 1.7, 0, x + half * 1.1, 0);\n      g.addColorStop(0, \"rgba(0,0,0,0)\");\n      g.addColorStop(0.28, p.innerFringe);\n      g.addColorStop(0.56, p.core);\n      g.addColorStop(0.76, p.outerFringe);\n      g.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx.globalAlpha = o.wave * p.strength;\n      ctx.fillStyle = g;\n      ctx.fillRect(0, 0, w, h);\n      for (const [edgeY, top] of [[0, true], [h, false]] as const) {\n        const e = ctx.createRadialGradient(x, edgeY, 2, x, edgeY, half * 1.35);\n        e.addColorStop(0, p.core);\n        e.addColorStop(0.5, p.outerFringe);\n        e.addColorStop(1, \"rgba(0,0,0,0)\");\n        ctx.globalAlpha = o.wave * 0.85;\n        ctx.fillStyle = e;\n        ctx.fillRect(0, top ? 0 : h * 0.5, w, h * 0.5);\n      }\n      for (const d of dust) {\n        const px = d.x * w;\n        const py = d.y * h;\n        const behind = x - px;\n        if (behind <= -22 || behind >= w * 0.95) continue;\n        const fresh = clamp(1 - Math.abs(behind) / (w * 0.65), 0.15, 1);\n        const a = o.dust * fresh * (0.35 + 0.65 * Math.sin(now * 0.01 * d.twinkle * 0.2 + d.phase)) * 0.88;\n        if (a <= 0.02) continue;\n        const sx = px + clamp(behind * 0.04, 0, 12);\n        ctx.globalAlpha = a;\n        ctx.fillStyle = p.sparkle[d.tone];\n        ctx.beginPath();\n        ctx.arc(sx, py, d.size * (0.75 + fresh * 0.45), 0, Math.PI * 2);\n        ctx.fill();\n        if (d.star && a > 0.4) starGlint(ctx, sx, py, d.size * 3, p.sparkle[0], a * 0.78);\n      }\n    } else if (wv.direction === \"diagonal\") {\n      // A wide, soft veil drifting across: no hard band.\n      const e = easeOutQuart(raw);\n      const x = -w * 0.35 + e * w * 1.7;\n      const r = Math.max(w * 0.46, 260);\n      const cy = h * 0.45 + (e - 0.5) * h * 0.18;\n      ctx.save();\n      ctx.translate(x, cy);\n      ctx.scale(1.45, 0.85);\n      const g = ctx.createRadialGradient(0, 0, 0, 0, 0, r);\n      g.addColorStop(0, p.core);\n      g.addColorStop(0.28, p.outerFringe);\n      g.addColorStop(0.58, p.innerFringe);\n      g.addColorStop(0.82, p.ambient);\n      g.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx.globalAlpha = o.wave * p.strength * 0.78;\n      ctx.fillStyle = g;\n      ctx.beginPath();\n      ctx.arc(0, 0, r, 0, Math.PI * 2);\n      ctx.fill();\n      ctx.restore();\n      for (const d of dust) {\n        const px = d.x * w;\n        const py = d.y * h;\n        const behind = x - px;\n        if (behind <= -r * 0.45) continue;\n        const fresh = clamp(1 - Math.abs(behind) / (w * 0.85), 0.14, 1);\n        const a = o.dust * fresh * (0.3 + 0.7 * Math.sin(now * 0.008 + d.phase)) * 0.58;\n        if (a <= 0.02) continue;\n        ctx.globalAlpha = a;\n        ctx.fillStyle = p.sparkle[d.tone];\n        ctx.beginPath();\n        ctx.arc(px + clamp(behind * 0.02, 0, 10), py, d.size * 0.9, 0, Math.PI * 2);\n        ctx.fill();\n      }\n    } else {\n      // A thin crest of light spreading from a point, a warm wash behind it.\n      const ox = wv.origin.x * w;\n      const oy = wv.origin.y * h;\n      const far = Math.max(Math.hypot(ox, oy), Math.hypot(w - ox, oy), Math.hypot(ox, h - oy), Math.hypot(w - ox, h - oy));\n      const radius = easeOutQuart(raw) * (far * 1.16 + 44);\n      const ring = Math.max(64, far * 0.22);\n      const g = ctx.createRadialGradient(ox, oy, Math.max(0, radius - ring * 0.92), ox, oy, radius + ring * 0.8);\n      g.addColorStop(0, \"rgba(0,0,0,0)\");\n      g.addColorStop(0.22, p.innerFringe);\n      g.addColorStop(0.42, p.ambient);\n      g.addColorStop(0.54, p.core);\n      g.addColorStop(0.7, p.outerFringe);\n      g.addColorStop(0.88, p.ambient);\n      g.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx.globalAlpha = o.wave * p.strength;\n      ctx.fillStyle = g;\n      ctx.fillRect(0, 0, w, h);\n      const wash = ctx.createRadialGradient(ox, oy, 0, ox, oy, Math.max(10, radius * 0.9));\n      wash.addColorStop(0, \"rgba(0,0,0,0)\");\n      wash.addColorStop(0.66, p.ambient);\n      wash.addColorStop(1, \"rgba(0,0,0,0)\");\n      ctx.globalAlpha = o.wave * 0.44;\n      ctx.fillStyle = wash;\n      ctx.fillRect(0, 0, w, h);\n      for (const d of dust) {\n        const px = d.x * w;\n        const py = d.y * h;\n        const dx = px - ox;\n        const dy = py - oy;\n        const dist = Math.hypot(dx, dy) || 1;\n        const behind = radius - dist;\n        if (behind <= -22) continue;\n        const fresh = clamp(1 - behind / (far * 1.05), 0.14, 1);\n        const a = o.dust * fresh * (0.35 + 0.65 * Math.sin(now * 0.01 + d.phase)) * 0.78;\n        if (a <= 0.02) continue;\n        const drift = clamp(behind * 0.03, 0, 12);\n        const sx = px + (dx / dist) * drift;\n        const sy = py + (dy / dist) * drift;\n        ctx.globalAlpha = a;\n        ctx.fillStyle = p.sparkle[d.tone];\n        ctx.beginPath();\n        ctx.arc(sx, sy, d.size * (0.72 + fresh * 0.45), 0, Math.PI * 2);\n        ctx.fill();\n        if (d.star && a > 0.36) starGlint(ctx, sx, sy, d.size * 3.1, p.sparkle[0], a * 0.75);\n      }\n    }\n\n    if (raw >= 1) {\n      wave = null;\n      wv.onComplete?.();\n    }\n  };\n\n  const run = () => {\n    if (!raf) {\n      last = 0;\n      raf = requestAnimationFrame(frame);\n    }\n  };\n\n  return {\n    wave(options: LightWaveOptions = {}) {\n      const s = get.settings();\n      // A wave still on its way in hands its change over first, so nothing is lost.\n      if (wave && !wave.swapped) {\n        wave.swapped = true;\n        wave.onMidpoint?.();\n      }\n      const previous = wave;\n      wave = null;\n      previous?.onComplete?.();\n      if (prefersReducedMotion() || !measure()) {\n        options.onMidpoint?.();\n        options.onComplete?.();\n        return;\n      }\n      const direction = options.direction ?? s.direction;\n      const duration = options.duration ?? (options.direction ? DURATION[direction] : s.duration);\n      dust = makeDust();\n      target = 0;\n      level = 0;\n      wave = {\n        start: performance.now(),\n        duration,\n        origin: options.origin ?? { x: 0.5, y: 0.88 },\n        direction,\n        palette: resolvePalette(options.palette ?? s.palette),\n        swapped: false,\n        onMidpoint: options.onMidpoint,\n        onComplete: options.onComplete,\n      };\n      // The rim blooms as the wave settles, then breathes out to its resting glow.\n      window.clearTimeout(settleTimer);\n      get.settle(true);\n      settleTimer = window.setTimeout(() => get.settle(false), duration * 0.85);\n      run();\n    },\n    charge(next: number, origin?: LightPoint) {\n      if (prefersReducedMotion()) return;\n      if (origin) chargeOrigin = origin;\n      if (next > 0.005 && !raf && !measure()) return;\n      target = clamp(next, 0, 1);\n      if (target > 0.005 || level > 0.005) run();\n    },\n    busy: () => wave !== null,\n    dispose() {\n      window.clearTimeout(settleTimer);\n      cancelAnimationFrame(raf);\n      raf = 0;\n      wave = null;\n    },\n  };\n}\n\ntype Engine = ReturnType<typeof createEngine>;\n\nconst MASK_EDGE: React.CSSProperties = {\n  WebkitMask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  WebkitMaskComposite: \"xor\",\n  mask: \"linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)\",\n};\n\nexport interface LightSurfaceProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\"> {\n  children: React.ReactNode;\n  ref?: React.Ref<LightSurfaceHandle>;\n  /** The light's colours, by name or your own. */\n  palette?: LightPaletteName | LightPalette;\n  /** How waves cross it by default. */\n  direction?: LightDirection;\n  /** Default wave length in ms. */\n  duration?: number;\n  /** Keep the light in the rim: the surface is on. */\n  lit?: boolean;\n  /** A pill keeps its rim light along its long edges. */\n  shape?: \"card\" | \"capsule\";\n  /** What the content dims toward under a wave; a surface with its own dark finish passes its own dark. */\n  veil?: string;\n  /** @deprecated Ignored. Kept so components installed with an earlier copy of this file still compile. */\n  cascadeKey?: string;\n}\n\n/** A card the light runs through. Give it a radius with className; it takes the theme's card colour and border. */\nexport function LightSurface({\n  children,\n  ref,\n  palette = \"azure\",\n  direction = \"radial\",\n  duration,\n  lit = false,\n  shape = \"card\",\n  veil = \"var(--background)\",\n  cascadeKey,\n  className = \"\",\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: LightSurfaceProps) {\n  const rootRef = React.useRef<HTMLDivElement>(null);\n  const contentRef = React.useRef<HTMLDivElement>(null);\n  const veilRef = React.useRef<HTMLDivElement>(null);\n  const canvasRef = React.useRef<HTMLCanvasElement>(null);\n  const sheenRef = React.useRef<HTMLDivElement>(null);\n  const engineRef = React.useRef<Engine | null>(null);\n  const [settling, setSettling] = React.useState(false);\n  const pal = resolvePalette(palette);\n  const live = React.useRef<Settings>({ palette: pal, direction, duration: duration ?? DURATION[direction] });\n  React.useLayoutEffect(() => {\n    live.current = { palette: pal, direction, duration: duration ?? DURATION[direction] };\n  });\n\n  const engine = React.useCallback(\n    () =>\n      (engineRef.current ??= createEngine({\n        root: () => rootRef.current,\n        content: () => contentRef.current,\n        veil: () => veilRef.current,\n        canvas: () => canvasRef.current,\n        settings: () => live.current,\n        settle: (on: boolean) => setSettling(on),\n      })),\n    [],\n  );\n\n  React.useEffect(\n    () => () => {\n      engineRef.current?.dispose();\n      engineRef.current = null;\n    },\n    [],\n  );\n\n  React.useImperativeHandle(\n    ref,\n    () => ({\n      wave: (o) => engine().wave(o),\n      charge: (l, o) => engine().charge(l, o),\n      busy: () => engineRef.current?.busy() ?? false,\n      element: () => rootRef.current,\n    }),\n    [engine],\n  );\n\n  void cascadeKey;\n  const capsule = shape === \"capsule\";\n  const rim = !lit ? 0 : capsule || settling ? 0.92 : 0.72;\n  const bezel = !lit ? 0 : capsule ? 0.95 : settling ? 0.96 : 0.84;\n  const card = (a: number) => `color-mix(in oklab, var(--card) ${a}%, transparent)`;\n\n  return (\n    <div\n      ref={rootRef}\n      className={`relative isolate overflow-clip border border-border bg-card text-card-foreground ${className}`}\n      onPointerMove={(e) => {\n        onPointerMove?.(e);\n        const sheen = sheenRef.current;\n        const root = rootRef.current;\n        if (e.pointerType !== \"mouse\" || !sheen || !root) return;\n        const r = root.getBoundingClientRect();\n        sheen.style.background = `radial-gradient(240px circle at ${Math.round(e.clientX - r.left)}px ${Math.round(e.clientY - r.top)}px, color-mix(in oklab, var(--foreground) 24%, transparent), transparent 68%)`;\n        sheen.style.opacity = \"1\";\n      }}\n      onPointerLeave={(e) => {\n        onPointerLeave?.(e);\n        if (sheenRef.current) sheenRef.current.style.opacity = \"0\";\n      }}\n      {...props}\n    >\n      <div aria-hidden className=\"pointer-events-none absolute inset-0 rounded-[inherit]\" style={{ background: \"linear-gradient(180deg, color-mix(in oklab, var(--foreground) 3.5%, transparent) 0%, transparent 26%)\" }} />\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-[1400ms] ease-out\"\n        style={{\n          opacity: rim,\n          background: capsule\n            ? `radial-gradient(62% 38% at 10% 6%, ${pal.rimPrimary}, transparent 68%), radial-gradient(68% 42% at 90% 96%, ${pal.rimSecondary}, transparent 68%), radial-gradient(50% 34% at 92% 8%, ${pal.rimAccent}, transparent 72%)`\n            : `radial-gradient(52% 29% at 8% 4%, ${pal.rimPrimary}, transparent 66%), radial-gradient(54% 31% at 92% 96%, ${pal.rimSecondary}, transparent 67%), radial-gradient(44% 25% at 92% 5%, ${pal.rimAccent}, transparent 69%), radial-gradient(46% 23% at 16% 97%, ${pal.rimSecondary}, transparent 67%)`,\n        }}\n      />\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-[1400ms] ease-out\"\n        style={{\n          opacity: lit ? 1 : 0,\n          background: capsule\n            ? `radial-gradient(76% 68% at 50% 50%, ${card(88)} 0%, ${card(52)} 66%, transparent 100%)`\n            : `radial-gradient(82% 77% at 50% 50%, ${card(96)} 0%, ${card(82)} 70%, ${card(20)} 90%, transparent 100%)`,\n        }}\n      />\n      <div\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] transition-opacity duration-[1200ms] ease-out\"\n        style={{\n          ...MASK_EDGE,\n          padding: capsule ? 1.5 : 1.25,\n          opacity: bezel,\n          background: `linear-gradient(135deg, ${pal.rimPrimary} 0%, color-mix(in oklab, var(--foreground) 26%, transparent) 28%, color-mix(in oklab, var(--foreground) 6%, transparent) 54%, ${pal.rimSecondary} 100%)`,\n        }}\n      />\n      <div ref={sheenRef} aria-hidden className=\"pointer-events-none absolute inset-0 rounded-[inherit] opacity-0 transition-opacity duration-300\" style={{ ...MASK_EDGE, padding: 1 }} />\n      <div ref={contentRef} className=\"relative z-10 h-full w-full\">\n        {children}\n      </div>\n      <div ref={veilRef} aria-hidden className=\"pointer-events-none absolute inset-0 z-20 rounded-[inherit] opacity-0\" style={{ background: veil }} />\n      <canvas ref={canvasRef} aria-hidden className=\"pointer-events-none absolute inset-0 z-30 size-full rounded-[inherit]\" />\n    </div>\n  );\n}\n\n/**\n * Holds what a component shows until the light covering a change reaches its peak.\n * `next` is what the props say now; `key` changes only for changes worth a wave.\n * Returns what to show.\n */\nexport function useLightHeld<T>(next: T, key: string | number | boolean, surface: React.RefObject<LightSurfaceHandle | null>, wave: () => LightWaveOptions | null) {\n  const [held, setHeld] = React.useState<{ key: typeof key; value: T }>({ key, value: next });\n  const latest = React.useRef({ next, key });\n  React.useLayoutEffect(() => {\n    latest.current = { next, key };\n  });\n  const pending = held.key !== key;\n  React.useEffect(() => {\n    if (!pending) return;\n    const s = surface.current;\n    const options = wave();\n    const land = () => setHeld({ key: latest.current.key, value: latest.current.next });\n    // A light already crossing carries the change; otherwise one is sent for it.\n    if (!s || !options || s.busy()) {\n      const id = requestAnimationFrame(land);\n      return () => cancelAnimationFrame(id);\n    }\n    s.wave({ ...options, onMidpoint: land });\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [pending, key]);\n  return pending ? held.value : next;\n}\n"},{"path":"registry/ui-interaction-motion.ts","type":"registry:component","content":"// Hairline UI · track-player · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n'use client';\n\nimport * as React from 'react';\n\nexport const EASE_OUT = 'cubic-bezier(0.16, 1, 0.3, 1)';\nexport const EASE_SETTLE = 'cubic-bezier(0.22, 1.18, 0.36, 1)';\n/** Thrown things (indicators, thumbs): a slight overshoot on transform only. */\nexport const EASE_THROW = 'cubic-bezier(0.34, 1.36, 0.64, 1)';\n/**\n * The press every button primitive shares: a 3% give that eases in and settles back.\n * Tailwind v4's scale-* writes the `scale` property, so `scale` has to be in the list\n * or the press snaps.\n */\nexport const INTERACTION_PRESS =\n  'transition-[background-color,color,box-shadow,opacity,scale] duration-200 ease-[cubic-bezier(0.16,1,0.3,1)] active:scale-[0.97] motion-reduce:transition-none motion-reduce:active:scale-100';\nexport const INTERACTION_FOCUS ='focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring/50 focus-visible:ring-offset-2 focus-visible:ring-offset-background';\n\nconst query = '(prefers-reduced-motion: reduce)';\nconst subscribe = (notify: () => void) => {\n  const media = window.matchMedia(query);\n  media.addEventListener('change', notify);\n  return () => media.removeEventListener('change', notify);\n};\nexport const useInteractionReducedMotion = () => React.useSyncExternalStore(subscribe, () => window.matchMedia(query).matches, () => false);\n\nexport function useInteractionActivity<T extends Element>() {\n  const ref = React.useRef<T>(null);\n  const [visible, setVisible] = React.useState(false);\n  const [hidden, setHidden] = React.useState(false);\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const observer = new IntersectionObserver(([entry]) => setVisible(entry.isIntersecting));\n    observer.observe(el);\n    const visibility = () => setHidden(document.hidden);\n    visibility(); document.addEventListener('visibilitychange', visibility);\n    return () => { observer.disconnect(); document.removeEventListener('visibilitychange', visibility); };\n  }, []);\n  return { ref, active: visible && !hidden };\n}\n\nexport function interactionIcon(on: boolean, reduced: boolean): React.CSSProperties {\n  return { opacity: on ? 1 : 0, transform: on ? 'none' : 'scale(0.6)', filter: on ? 'blur(0px)' : 'blur(3px)', transition: reduced ? 'none' : `opacity 220ms ${EASE_OUT}, transform 380ms ${EASE_OUT}, filter 220ms ${EASE_OUT}` };\n}\n\n/** A raised object: one tight contact shadow, one short ambient, a hairline of light on its top edge. */\nexport const MATERIAL_LIFT =\n  'shadow-[0_1px_1.5px_rgb(0_0_0/0.07),0_3px_8px_-2px_rgb(0_0_0/0.1),inset_0_0.5px_0_rgb(255_255_255/0.8)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.5),0_4px_10px_-2px_rgb(0_0_0/0.35),inset_0_0.5px_0_rgb(255_255_255/0.1)]';\n/** A trough something sits in, shaded from above, lit along its bottom edge. */\nexport const MATERIAL_RECESS =\n  'shadow-[inset_0_1px_2.5px_rgb(0_0_0/0.09),inset_0_-0.5px_0_rgb(255_255_255/0.7)] dark:shadow-[inset_0_1px_3px_rgb(0_0_0/0.45),inset_0_-0.5px_0_rgb(255_255_255/0.07)]';\n\nexport type SpringConfig = { stiffness: number; damping: number; mass?: number };\nexport interface Spring {\n  get(): number;\n  getVelocity(): number;\n  getTarget(): number;\n  /** Aim somewhere new from wherever it is now, keeping its speed. */\n  set(target: number): void;\n  /** Add speed (units per second), on top of what it already has. */\n  push(velocity: number): void;\n  /** Be there now, at rest. */\n  jump(value: number): void;\n  configure(config: SpringConfig): void;\n  stop(): void;\n}\n\n// Every moving spring on the page shares one frame loop, which sleeps when the last one rests. Each spring's onFrame runs\n// once per frame after all of them have stepped, so several springs that draw one shape paint it once.\nconst SPRING_STEP = 1 / 240;\ntype Running = { step: () => void };\nconst runningSprings = new Set<Running>();\nconst springPainters = new Set<() => void>();\nlet springFrame = 0;\nlet springLast = 0;\nlet springSpare = 0;\n\nfunction springTick(now: number) {\n  // A hidden tab stops the frames, so the first one back must not count the whole gap as time passed.\n  springSpare += Math.min((now - springLast) / 1000, 0.05);\n  springLast = now;\n  while (springSpare >= SPRING_STEP) {\n    runningSprings.forEach((spring) => spring.step());\n    springSpare -= SPRING_STEP;\n  }\n  const painters = [...springPainters];\n  springPainters.clear();\n  painters.forEach((paint) => paint());\n  springFrame = runningSprings.size ? requestAnimationFrame(springTick) : 0;\n}\n\nfunction wakeSprings(spring: Running) {\n  runningSprings.add(spring);\n  if (springFrame) return;\n  springSpare = 0;\n  springFrame = requestAnimationFrame((now) => {\n    springLast = now - 1000 / 60;\n    springTick(now);\n  });\n}\n\n/**\n * A spring that carries its speed: re-aim it mid-flight and it curves on from where it is, push it while it swings and the\n * push adds to the swing. Use it for anything that can be interrupted; a curve restarts from a standstill every time.\n * `onFrame` should write straight to the DOM. `precision` is how close counts as there, in the value's own units.\n */\nexport function createSpring(initial: number, config: SpringConfig, onFrame: () => void, precision = 0.01): Spring {\n  let value = initial;\n  let velocity = 0;\n  let target = initial;\n  let { stiffness, damping, mass = 1 } = config;\n  const running: Running = {\n    step() {\n      velocity += ((-stiffness * (value - target) - damping * velocity) / mass) * SPRING_STEP;\n      value += velocity * SPRING_STEP;\n      if (Math.abs(value - target) < precision && Math.abs(velocity) < precision * 10) {\n        value = target;\n        velocity = 0;\n        runningSprings.delete(running);\n      }\n      springPainters.add(onFrame);\n    },\n  };\n  return {\n    get: () => value,\n    getVelocity: () => velocity,\n    getTarget: () => target,\n    set(next) {\n      if (next === target && !runningSprings.has(running)) return;\n      target = next;\n      wakeSprings(running);\n    },\n    push(speed) {\n      velocity += speed;\n      wakeSprings(running);\n    },\n    jump(next) {\n      value = next;\n      target = next;\n      velocity = 0;\n      runningSprings.delete(running);\n      onFrame();\n    },\n    configure(next) {\n      ({ stiffness, damping, mass = 1 } = next);\n    },\n    stop() {\n      runningSprings.delete(running);\n    },\n  };\n}\n\n/** Sample recent movement rather than averaging a long drag and losing its release velocity. */\nexport type PointerSample = { x: number; time: number };\nexport function samplePointer(samples: PointerSample[], x: number, time: number) {\n  samples.push({ x, time });\n  while (samples.length > 2 && time - samples[0].time > 100) samples.shift();\n}\nexport function releaseVelocity(samples: PointerSample[], now: number) {\n  if (samples.length < 2 || now - samples[samples.length - 1].time > 100) return 0;\n  const first = samples[0], last = samples[samples.length - 1];\n  return (last.x - first.x) / Math.max(1, last.time - first.time);\n}\n\n/** Smooth Apple/rational rubber-band curve: continuous exponential-like resistance without linear kinks. */\nexport function rubberBand(overshoot: number, dimension = 320, constant = 0.55): number {\n  const d = dimension || 320;\n  const abs = Math.abs(overshoot);\n  return Math.sign(overshoot) * (1 - 1 / ((abs * constant) / d + 1)) * d;\n}\n\n/** Projects resting travel from release velocity (velocity in px/ms; time in seconds). */\nexport function projectInertia(distance: number, velocity: number, time = 0.12): number {\n  return distance + velocity * 1000 * time;\n}\n\n/** Smooths incoming release velocity toward a boundary so springs don't slam or clip into walls. */\nexport function softenVelocity(velocity: number, distanceToTarget: number, factor = 10): number {\n  const maxAllowed = Math.abs(distanceToTarget) * factor;\n  return Math.sign(velocity) * Math.min(Math.abs(velocity), maxAllowed);\n}\n\n/** A damped spring sampled by WAAPI: tuned for organic lightness with a hint of life (3% breath). */\nexport function springFrames(\n  from: number,\n  to: number,\n  velocity = 0,\n  duration = 480,\n  config: { omega?: number; damping?: number; steps?: number } = {},\n) {\n  const { omega = 16, damping = 0.74, steps = 36 } = config;\n  const damped = omega * Math.sqrt(Math.max(0.001, 1 - damping * damping));\n  const displacement = from - to;\n  const coefficient = (velocity * 1000 + damping * omega * displacement) / damped;\n  return Array.from({ length: steps + 1 }, (_, i) => {\n    const t = (i / steps) * (duration / 1000);\n    const value = to + Math.exp(-damping * omega * t) * (displacement * Math.cos(damped * t) + coefficient * Math.sin(damped * t));\n    return { value: i === steps ? to : value, offset: i / steps };\n  });\n}\n\n"}],"css":{"@keyframes ui-track-pulse":{"from":{"transform":"scaleY(1)"},"to":{"transform":"scaleY(0.72)"}}},"docs":"Docs and live preview: https://hairlineui.com/ui/track-player. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}