{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"scene-mixer","type":"registry:component","title":"Scene mixer","description":"A few levels and the scenes that set them: press a scene and a soft veil of light drifts across the card while every level glides to its place.","author":"Hairline UI","dependencies":[],"registryDependencies":["https://hairlineui.com/r/number-roll.json?as=dependency","https://hairlineui.com/r/text-morph.json?as=dependency"],"files":[{"path":"registry/scene-mixer.tsx","type":"registry:component","content":"// Hairline UI · scene-mixer · MIT License\n// Copyright (c) 2026 Hairline UI · https://hairlineui.com/license#components\n\n\"use client\";\n\nimport * as React from \"react\";\nimport { LightSurface, clamp, resolvePalette, useLightReducedMotion, type LightPalette, type LightPaletteName, type LightSurfaceHandle } from \"./light-surface\";\nimport { NumberRoll } from \"./number-roll\";\nimport { TextMorph } from \"./text-morph\";\nimport { INTERACTION_FOCUS, INTERACTION_PRESS } from \"./ui-interaction-motion\";\n\n/* ─────────────────────────────────────────────────────────\n * SCENE MIXER: a few levels and the scenes that set them\n *\n *   levels   each channel is a fine track with a thumb you\n *            drag, or step with the arrow keys\n *   scene    the pill names the next scene; press it and a\n *            soft veil of light drifts across the card, the\n *            scene changes under it, and every level glides to\n *            its new place while the figures roll there\n *   lit      a scene with a palette colours the tracks and\n *            keeps the card's rim lit while it's set\n *\n * Reduced motion: no veil; levels move in place.\n * ───────────────────────────────────────────────────────── */\n\nexport interface MixerChannel {\n  id: string;\n  label: string;\n  value: number;\n}\n\nexport interface MixerScene {\n  name: string;\n  /** Levels by channel id. */\n  values: Record<string, number>;\n  /** Colours the tracks and lights the rim while this scene is set. */\n  palette?: LightPaletteName | LightPalette;\n}\n\nexport interface SceneMixerProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  title: string;\n  subtitle?: string;\n  icon?: React.ReactNode;\n  channels: MixerChannel[];\n  /** A level moved by hand. */\n  onChannelChange: (id: string, value: number) => void;\n  scenes?: MixerScene[];\n  /** The scene that's set, by name; leave it out once the levels no longer match one. */\n  scene?: string;\n  /** Called under the veil with the scene to set: set the scene and its levels here. */\n  onSceneChange?: (name: string) => void;\n  max?: number;\n  unit?: string;\n}\n\nfunction Level({\n  channel,\n  max,\n  unit,\n  fill,\n  glide,\n  onChange,\n}: {\n  channel: MixerChannel;\n  max: number;\n  unit: string;\n  fill: string;\n  glide: boolean;\n  onChange: (value: number) => void;\n}) {\n  const track = React.useRef<HTMLDivElement>(null);\n  const [dragging, setDragging] = React.useState(false);\n  const k = clamp(channel.value / max, 0, 1);\n  const move = glide && !dragging ? \"transform 640ms cubic-bezier(0.16,1,0.3,1)\" : \"none\";\n  const fromPointer = (clientX: number) => {\n    const r = track.current?.getBoundingClientRect();\n    if (r) onChange(clamp(Math.round(((clientX - r.left) / r.width) * max), 0, max));\n  };\n  return (\n    <div className=\"grid grid-cols-[minmax(0,1fr)_auto] items-center gap-x-3 @[24rem]:grid-cols-[minmax(0,6.5rem)_minmax(0,1fr)_3rem]\">\n      <span className=\"truncate text-[13px] text-muted-foreground\">{channel.label}</span>\n      <div\n        ref={track}\n        role=\"slider\"\n        tabIndex={0}\n        aria-label={channel.label}\n        aria-valuemin={0}\n        aria-valuemax={max}\n        aria-valuenow={channel.value}\n        aria-valuetext={`${channel.value}${unit}`}\n        onPointerDown={(e) => {\n          e.currentTarget.setPointerCapture(e.pointerId);\n          setDragging(true);\n          fromPointer(e.clientX);\n        }}\n        onPointerMove={(e) => dragging && fromPointer(e.clientX)}\n        onPointerUp={() => setDragging(false)}\n        onPointerCancel={() => setDragging(false)}\n        onKeyDown={(e) => {\n          const by = e.shiftKey ? 10 : 1;\n          const keys: Record<string, number> = { ArrowRight: by, ArrowUp: by, ArrowLeft: -by, ArrowDown: -by, PageUp: 10, PageDown: -10 };\n          if (e.key in keys) onChange(clamp(channel.value + keys[e.key], 0, max));\n          else if (e.key === \"Home\") onChange(0);\n          else if (e.key === \"End\") onChange(max);\n          else return;\n          e.preventDefault();\n        }}\n        className={`relative order-3 col-span-2 flex h-6 cursor-pointer touch-none select-none items-center rounded-full outline-none focus-visible:ring-2 focus-visible:ring-ring/50 @[24rem]:order-2 @[24rem]:col-span-1 ${dragging ? \"cursor-grabbing\" : \"\"}`}\n      >\n        <span className=\"relative h-[3px] w-full overflow-clip rounded-full bg-[color-mix(in_oklab,var(--foreground)_13%,transparent)]\">\n          <span className=\"absolute inset-0 origin-left rounded-full\" style={{ background: fill, transform: `scaleX(${k})`, transition: move, willChange: \"transform\" }} />\n        </span>\n        <span aria-hidden className=\"pointer-events-none absolute inset-0\" style={{ transform: `translateX(${k * 100}%)`, transition: move }}>\n          <span\n            className={`absolute top-1/2 size-3.5 -translate-x-1/2 -translate-y-1/2 rounded-full bg-foreground shadow-[0_0_0_2px_var(--card)] transition-[scale] duration-150 ${dragging ? \"scale-[1.18]\" : \"\"}`}\n          />\n        </span>\n      </div>\n      <span className=\"order-2 text-right text-[12.5px] font-medium tabular-nums text-foreground @[24rem]:order-3\">\n        {dragging ? (\n          <span>\n            {channel.value}\n            {unit}\n          </span>\n        ) : (\n          <NumberRoll value={channel.value} suffix={unit} duration={720} />\n        )}\n      </span>\n    </div>\n  );\n}\n\nexport function SceneMixer({\n  title,\n  subtitle,\n  icon,\n  channels,\n  onChannelChange,\n  scenes = [],\n  scene,\n  onSceneChange,\n  max = 100,\n  unit = \"%\",\n  className = \"\",\n  ...props\n}: SceneMixerProps) {\n  const surface = React.useRef<LightSurfaceHandle>(null);\n  const reduced = useLightReducedMotion();\n  const current = scenes.find((s) => s.name === scene);\n  const index = current ? scenes.indexOf(current) : -1;\n  const next = scenes.length ? scenes[(index + 1) % scenes.length] : undefined;\n  const pal = current?.palette ? resolvePalette(current.palette) : null;\n  const fill = pal ? `linear-gradient(90deg, ${pal.ink}, color-mix(in oklab, ${pal.ink} 45%, white))` : \"var(--foreground)\";\n  const busy = React.useRef(false);\n\n  const apply = () => {\n    if (!next || !onSceneChange || busy.current) return;\n    const s = surface.current;\n    if (!s || reduced) return onSceneChange(next.name);\n    busy.current = true;\n    s.wave({\n      direction: \"diagonal\",\n      palette: next.palette ?? \"dusk\",\n      onMidpoint: () => onSceneChange(next.name),\n      onComplete: () => {\n        busy.current = false;\n      },\n    });\n  };\n\n  return (\n    <LightSurface ref={surface} palette={current?.palette ?? \"dusk\"} direction=\"diagonal\" lit={!!pal} className={`rounded-[30px] ${className}`} {...props}>\n      <div className=\"@container px-6 pb-6 pt-5\">\n        <div className=\"flex items-center justify-between gap-3\">\n          <div className=\"flex min-w-0 items-center gap-3\">\n            {icon && <span className=\"grid size-10 shrink-0 place-items-center rounded-full bg-muted text-foreground\">{icon}</span>}\n            <div className=\"min-w-0\">\n              <div className=\"truncate text-[14px] font-medium text-foreground\">{title}</div>\n              {subtitle && <div className=\"truncate text-[12.5px] text-muted-foreground\">{subtitle}</div>}\n            </div>\n          </div>\n          {next && onSceneChange && (\n            <button\n              type=\"button\"\n              onClick={apply}\n              aria-label={`Set scene: ${next.name}`}\n              className={`h-9 shrink-0 cursor-pointer whitespace-nowrap rounded-full bg-muted px-4 text-[12.5px] font-medium text-foreground hover:bg-accent ${INTERACTION_PRESS} ${INTERACTION_FOCUS}`}\n            >\n              <TextMorph>{next.name}</TextMorph>\n            </button>\n          )}\n        </div>\n        <div className=\"mt-5 text-[20px] font-medium tracking-[-0.02em] text-foreground\">{scene ?? \"Custom\"}</div>\n        <div className=\"mt-3 space-y-2 @[24rem]:space-y-1.5\">\n          {channels.map((c) => (\n            <Level key={c.id} channel={c} max={max} unit={unit} fill={fill} glide={!reduced} onChange={(v) => onChannelChange(c.id, v)} />\n          ))}\n        </div>\n      </div>\n    </LightSurface>\n  );\n}\n"},{"path":"registry/light-surface.tsx","type":"registry:component","content":"// Hairline UI · scene-mixer · 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 · scene-mixer · 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":{},"docs":"Docs and live preview: https://hairlineui.com/ui/scene-mixer. MIT licensed: https://hairlineui.com/license#components","meta":{"license":"MIT"}}