{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"wave-reveal","type":"registry:component","title":"Wave Reveal","description":"Carries one screen into the next with a colourful wave: the card pulls toward the pressed button, a wave leaves from it and bends the screen as it passes, and its colour lingers on the edges. Vertical, horizontal or center.","author":"Saurabh <saurabh10102@gmail.com>","dependencies":["clsx","motion","tailwind-merge"],"registryDependencies":[],"docs":"Wave Reveal: usage, props and types at https://beui.dev/components/motion/wave-reveal.md","files":[{"path":"components/motion/wave-reveal.tsx","type":"registry:component","target":"@components/motion/wave-reveal.tsx","content":"\"use client\";\n// beui.dev/components/motion/wave-reveal\n\nimport {\n  animate,\n  cubicBezier,\n  type HTMLMotionProps,\n  type MotionValue,\n  motion,\n  useMotionValue,\n  useMotionValueEvent,\n  useReducedMotion,\n  useTransform,\n} from \"motion/react\";\nimport {\n  type ReactNode,\n  type RefObject,\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n} from \"react\";\nimport { EASE_OUT, SPRING_PRESS } from \"@/lib/ease\";\nimport { focusFirstIn } from \"@/lib/focusable\";\nimport { cn } from \"@/lib/utils\";\n\nexport type WaveRevealType = \"vertical\" | \"horizontal\" | \"center\";\n\nexport interface WaveRevealProps\n  extends Omit<\n    HTMLMotionProps<\"div\">,\n    \"children\" | \"style\" | \"onAnimationStart\" | \"onDrag\" | \"onDragStart\" | \"onDragEnd\"\n  > {\n  /** The first screen, shown while `revealed` is false. */\n  children: ReactNode;\n  /** The screen the wave carries in when `revealed` turns true. */\n  revealedContent: ReactNode;\n  /** Which screen shows. Flip it to play the wave; flipping it back plays the wave again toward the first screen. */\n  revealed: boolean;\n  /** Shape of the wave front: a wide arc that travels up or down, a tall arc that travels sideways, or a ring from the centre. Default: \"vertical\" */\n  type?: WaveRevealType;\n  /** Element the wave leaves from, such as the confirm button. Without it the wave leaves from the last press inside, else from the bottom edge, the left edge or the centre. */\n  sourceRef?: RefObject<HTMLElement | null>;\n  /** Time the wave takes to cross the screen, in seconds. A short gather before it and the fading edge glow after it add about 1.3s. Default: 1.6 */\n  duration?: number;\n  /** Colours of the wave and the glow it leaves on the edges, any CSS colour. Default: amber, sky, pink, peach and cyan */\n  colors?: string[];\n  /** How far the wave swells the screen under it, in px. 0 turns the swell off. Default: 26 */\n  distortion?: number;\n  /** Called when a wave finishes, with the `revealed` value it carried in. */\n  onRevealComplete?: (revealed: boolean) => void;\n}\n\nconst DEFAULT_COLORS = [\"#ffc915\", \"#7ec4ff\", \"#eb64a0\", \"#ffb07a\", \"#7fd9ee\"];\n/** Tints laid over the palette just ahead of the front and deep in its tail. */\nconst AHEAD = \"rgb(255 122 182 / 0.55)\";\nconst BEHIND = \"rgb(90 190 255 / 0.5)\";\n\n/** Anticipation: the screen pulls toward the source and gathers light there. */\nconst GATHER_S = 0.42;\n/** How long the edge glow stays after the front has left, fading out. */\nconst LINGER_S = 0.9;\nconst REDUCED_S = 0.2;\n/** How far the screen pulls in toward the source while it gathers. */\nconst PULL = 0.962;\n\n/** Width of the soft seam between the two screens, in px. */\nconst SEAM = 24;\n/** Colour reaching ahead of the front, in px. */\nconst LEAD = 110;\n/** Colour trailing behind the front, in px. */\nconst TAIL = 280;\n/** Extra travel past the farthest corner so the colour fully leaves. */\nconst OVERSHOOT = 140;\n/** Width of the glow the wave leaves on the edges, in px. */\nconst RIM = 18;\n/** How much wider (vertical) or taller (horizontal) the arc is than it is deep. */\nconst ARC = 1.45;\n/** Backdrop blur under the front, in px. */\nconst BLUR = 8;\n/** Where the front sits in the lens map, as a share of its radius. */\nconst LENS_FRONT = 0.8;\nconst DOTS = 26;\n/** Sparks thrown off the front as it travels. */\nconst SPARKS = 44;\nconst SPARK_LIFE_S = 0.9;\n/** How far the front ripples either way, in px. */\nconst RIPPLE = 18;\n/** The colour layers reach this far past the card, so the ripple never pulls in a bare edge. */\nconst PAD = 24;\nconst NOISE_PERIOD = 1024;\nconst NOISE_SPAN = 2048;\n\n// The front leaves briskly and eases as it reaches the far edge, like a wave\n// spreading from a touch. EASE_OUT reaches the edge too soon for a sweep this\n// long; EASE_IN_OUT stalls at the start.\nconst WAVE_EASE = cubicBezier(0.3, 0.1, 0.3, 1);\n\ntype Run = { id: number; target: boolean };\ntype Dot = { angle: number; reach: number; delay: number; size: number; color: string };\ntype Spark = { at: number; angle: number; drift: number; size: number; color: string };\n\nconst clamp01 = (value: number) => Math.min(1, Math.max(0, value));\nconst smooth = (edge0: number, edge1: number, value: number) => {\n  const x = clamp01((value - edge0) / (edge1 - edge0));\n  return x * x * (3 - 2 * x);\n};\n\n/**\n * The swell as a displacement map: red and green carry the inward direction,\n * scaled by a bump centred on the front (at LENS_FRONT of the radius),\n * narrow ahead of it and wider behind. The filter stretches it over the\n * wave's ellipse every frame.\n */\nlet lensMap: string | null = null;\nfunction getLensMap() {\n  if (lensMap || typeof document === \"undefined\") return lensMap;\n  const size = 256;\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = size;\n  canvas.height = size;\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return null;\n  const image = ctx.createImageData(size, size);\n  for (let y = 0; y < size; y++) {\n    for (let x = 0; x < size; x++) {\n      const nx = ((x + 0.5) / size) * 2 - 1;\n      const ny = ((y + 0.5) / size) * 2 - 1;\n      const d = Math.hypot(nx, ny);\n      const u = (d - LENS_FRONT) / (d > LENS_FRONT ? 0.07 : 0.17);\n      const lift = d < 1 ? Math.exp(-u * u) : 0;\n      const ux = d > 0 ? nx / d : 0;\n      const uy = d > 0 ? ny / d : 0;\n      const i = (y * size + x) * 4;\n      image.data[i] = 128 - 127 * ux * lift;\n      image.data[i + 1] = 128 - 127 * uy * lift;\n      image.data[i + 2] = 128;\n      image.data[i + 3] = 255;\n    }\n  }\n  ctx.putImageData(image, 0, 0);\n  lensMap = canvas.toDataURL();\n  return lensMap;\n}\n\n/**\n * Slow, smooth noise that tiles every NOISE_PERIOD px, as a displacement map.\n * Sliding it under the colour makes the front ripple the way a real wave's\n * crest does instead of staying a perfect ellipse.\n */\nlet noiseMap: string | null = null;\nfunction getNoiseMap() {\n  if (noiseMap || typeof document === \"undefined\") return noiseMap;\n  const size = NOISE_SPAN / 8;\n  const period = NOISE_PERIOD / 8;\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = size;\n  canvas.height = size;\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) return null;\n  const image = ctx.createImageData(size, size);\n  const turn = (Math.PI * 2) / period;\n  for (let y = 0; y < size; y++) {\n    for (let x = 0; x < size; x++) {\n      const r = 0.6 * Math.sin(turn * (x + y) + 1.3) + 0.4 * Math.sin(turn * (2 * x - y) + 4.1);\n      const g = 0.6 * Math.sin(turn * (x - y) + 2.2) + 0.4 * Math.sin(turn * (x + 2 * y) + 0.7);\n      const i = (y * size + x) * 4;\n      image.data[i] = 128 + 127 * r;\n      image.data[i + 1] = 128 + 127 * g;\n      image.data[i + 2] = 128;\n      image.data[i + 3] = 255;\n    }\n  }\n  ctx.putImageData(image, 0, 0);\n  noiseMap = canvas.toDataURL();\n  return noiseMap;\n}\n\n/** The palette as gradient stops that wrap seamlessly, repeated `times` over. */\nfunction loop(colors: string[], times = 1) {\n  const list = colors.length > 0 ? colors : DEFAULT_COLORS;\n  return [...Array.from({ length: times }, () => list).flat(), list[0]].join(\", \");\n}\n\n/** A radial gradient on the wave's ellipse; stops are px from the front, + ahead. */\nfunction ellipseGradient(\n  rx: number,\n  ry: number,\n  ox: number,\n  oy: number,\n  ax: number,\n  stops: [number, string][],\n) {\n  const list = stops\n    .map(([offset, color]) => `${color} ${(rx + offset * ax).toFixed(1)}px`)\n    .join(\", \");\n  return `radial-gradient(${rx.toFixed(1)}px ${ry.toFixed(1)}px at ${ox.toFixed(1)}px ${oy.toFixed(1)}px, ${list})`;\n}\n\nconst a = (alpha: number) => `rgb(0 0 0 / ${alpha})`;\n\nexport function WaveReveal({\n  children,\n  revealedContent,\n  revealed,\n  type = \"vertical\",\n  sourceRef,\n  duration = 1.6,\n  colors = DEFAULT_COLORS,\n  distortion = 26,\n  onRevealComplete,\n  className,\n  onPointerDownCapture,\n  ...props\n}: WaveRevealProps) {\n  const reduce = useReducedMotion() ?? false;\n  const filterId = `wave-${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n\n  // `shown` is the settled screen; a run carries the other one in on top.\n  const [shown, setShown] = useState(revealed);\n  const [run, setRun] = useState<Run | null>(null);\n  const [lastRevealed, setLastRevealed] = useState(revealed);\n  if (revealed !== lastRevealed) {\n    setLastRevealed(revealed);\n    setRun((current) => ({ id: (current?.id ?? 0) + 1, target: revealed }));\n  }\n  const target = run ? run.target : shown;\n\n  const stageRef = useRef<HTMLDivElement>(null);\n  const canvasRef = useRef<HTMLCanvasElement>(null);\n  const layerRefs = useRef<(HTMLDivElement | null)[]>([null, null]);\n  const imageRef = useRef<SVGFEImageElement>(null);\n  const displaceRefs = useRef<(SVGFEDisplacementMapElement | null)[]>([null, null, null]);\n  const pressRef = useRef<{ x: number; y: number; at: number } | null>(null);\n  const dotsRef = useRef<Dot[]>([]);\n  const sparksRef = useRef<Spark[]>([]);\n  const noiseRef = useRef<SVGFEImageElement>(null);\n  const completeRef = useRef(onRevealComplete);\n  const colorsRef = useRef(colors);\n  useLayoutEffect(() => {\n    completeRef.current = onRevealComplete;\n    colorsRef.current = colors;\n  });\n  const [map, setMap] = useState<string | null>(null);\n  const [noise, setNoise] = useState<string | null>(null);\n  useEffect(() => {\n    setMap(getLensMap());\n    setNoise(getNoiseMap());\n  }, []);\n\n  // Geometry of the current run, in px from the stage's top-left corner.\n  const ox = useMotionValue(0);\n  const oy = useMotionValue(0);\n  const ax = useMotionValue(ARC);\n  const ay = useMotionValue(1);\n  const reach = useMotionValue(1);\n  const travel = useMotionValue(duration);\n  // Seconds since the run began: gather, then travel, then linger.\n  const t = useMotionValue(0);\n  const fade = useMotionValue(1);\n  const scale = useMotionValue(1);\n\n  const progress = useTransform(() => clamp01((t.get() - GATHER_S) / travel.get()));\n  const front = useTransform(() => WAVE_EASE(progress.get()));\n  const radius = useTransform(() => Math.max(0.5, front.get() * reach.get()));\n  const rx = useTransform(() => radius.get() * ax.get());\n  const ry = useTransform(() => radius.get() * ay.get());\n  const released = useTransform(() => smooth(GATHER_S, GATHER_S + 0.14, t.get()));\n  const bandOpacity = useTransform(() => released.get() * (1 - smooth(0.62, 1, progress.get())));\n  // The core only lights once the front has room, so the first frames are not a white disc.\n  const coreOpacity = useTransform(() => bandOpacity.get() * smooth(24, 110, radius.get()));\n  const energy = useTransform(() => released.get() * (1 - smooth(0.45, 1, progress.get())));\n  const rimOpacity = useTransform(\n    () => released.get() * (1 - smooth(0, LINGER_S, t.get() - GATHER_S - travel.get())),\n  );\n  const gatherOpacity = useTransform(\n    () => 0.55 * smooth(0, GATHER_S, t.get()) * (1 - smooth(GATHER_S, GATHER_S + 0.3, t.get())),\n  );\n  const gatherScale = useTransform(() => 0.55 + 0.45 * smooth(0, GATHER_S, t.get()));\n\n  const shape = (stops: [number, string][], pad = 0) =>\n    ellipseGradient(rx.get(), ry.get(), ox.get() + pad, oy.get() + pad, ax.get(), stops);\n\n  const insideMask = useTransform(() => shape([[-SEAM, \"#000\"], [0, \"transparent\"]]));\n  const outsideMask = useTransform(() => shape([[-SEAM, \"transparent\"], [0, \"#000\"]]));\n  // The colour is strongest toward the card's edges and lighter over its middle,\n  // so the content stays readable through the wave.\n  const bandMask = useTransform(\n    () =>\n      `${shape(\n        [\n          [-TAIL, a(0)],\n          [-TAIL * 0.72, a(0.14)],\n          [-TAIL * 0.42, a(0.45)],\n          [-TAIL * 0.14, a(0.84)],\n          [0, a(0.97)],\n          [LEAD * 0.22, a(0.6)],\n          [LEAD * 0.58, a(0.2)],\n          [LEAD, a(0)],\n        ],\n        PAD,\n      )}, radial-gradient(closest-side at 50% 50%, ${a(0.62)} 35%, #000 100%)`,\n  );\n  const coreMask = useTransform(() =>\n    shape(\n      [\n        [-36, a(0)],\n        [-10, a(0.55)],\n        [2, a(0.8)],\n        [14, a(0)],\n      ],\n      PAD,\n    ),\n  );\n  const blurMask = useTransform(() =>\n    shape([\n      [-320, a(0)],\n      [-230, a(0.2)],\n      [-110, a(0.7)],\n      [0, a(1)],\n      [40, a(0.55)],\n      [95, a(0)],\n    ]),\n  );\n  const reached = useTransform(() =>\n    shape([\n      [LEAD * 0.25, \"#000\"],\n      [LEAD * 0.7, \"transparent\"],\n    ]),\n  );\n  const tints = useTransform(() =>\n    shape(\n      [\n        [-160, \"transparent\"],\n        [-84, BEHIND],\n        [-24, \"transparent\"],\n        [8, \"transparent\"],\n        [32, AHEAD],\n        [84, \"transparent\"],\n      ],\n      PAD,\n    ),\n  );\n  const palette = loop(colors);\n  const doubled = loop(colors, 2);\n  // The colour flows along the front as it travels.\n  const bandFill = useTransform(() => {\n    const flow = ((t.get() * 9) % 100).toFixed(2);\n    if (type === \"center\") {\n      return `${tints.get()}, conic-gradient(from ${(t.get() * 40).toFixed(1)}deg at ${(ox.get() + PAD).toFixed(1)}px ${(oy.get() + PAD).toFixed(1)}px, ${palette})`;\n    }\n    const along = type === \"vertical\" ? `90deg` : `180deg`;\n    const place = type === \"vertical\" ? `${flow}% 0 / 200% 100%` : `0 ${flow}% / 100% 200%`;\n    return `${tints.get()}, linear-gradient(${along}, ${doubled}) ${place}`;\n  });\n  const rimFill = useTransform(\n    () => `conic-gradient(from ${(t.get() * 55).toFixed(1)}deg at 50% 50%, ${palette})`,\n  );\n  const hairFill = useTransform(\n    () => `linear-gradient(rgb(255 255 255 / 0.6), rgb(255 255 255 / 0.6)), ${rimFill.get()}`,\n  );\n  // Uneven rim: lumps of thickness that drift around the edge.\n  const lumps = useTransform(\n    () =>\n      `conic-gradient(from ${(-t.get() * 25).toFixed(1)}deg at 50% 50%, ${a(0.35)}, #000 10%, ${a(0.5)} 24%, #000 41%, ${a(0.3)} 57%, #000 73%, ${a(0.55)} 86%, ${a(0.35)})`,\n  );\n  const rimMask = useTransform(\n    () =>\n      `${reached.get()}, ${lumps.get()}, linear-gradient(to right, #000, ${a(0.45)} ${RIM * 0.45}px, transparent ${RIM}px, transparent calc(100% - ${RIM}px), ${a(0.45)} calc(100% - ${RIM * 0.45}px), #000), linear-gradient(to bottom, #000, ${a(0.45)} ${RIM * 0.45}px, transparent ${RIM}px, transparent calc(100% - ${RIM}px), ${a(0.45)} calc(100% - ${RIM * 0.45}px), #000)`,\n  );\n  const hairMask = useTransform(\n    () => `${reached.get()}, linear-gradient(#000, #000), linear-gradient(#000, #000)`,\n  );\n  const gatherFill = `radial-gradient(circle, rgb(255 255 255 / 0.9) 0%, ${colors[0] ?? DEFAULT_COLORS[0]} 22%, ${colors[2] ?? DEFAULT_COLORS[2]} 42%, transparent 70%)`;\n  const transformOrigin = useTransform(() => `${ox.get()}px ${oy.get()}px`);\n  const fadeIn = useTransform(fade, (value) => 1 - value);\n\n  const distort = !reduce && distortion > 0 && map !== null && run !== null;\n\n  // Drive the lens filter and the gathering dots from the same clock as the masks.\n  useMotionValueEvent(t, \"change\", (time) => {\n    if (distort) {\n      const image = imageRef.current;\n      const width = Math.max(1, (rx.get() * 2) / LENS_FRONT);\n      const height = Math.max(1, (ry.get() * 2) / LENS_FRONT);\n      if (image) {\n        image.setAttribute(\"x\", String(ox.get() - width / 2));\n        image.setAttribute(\"y\", String(oy.get() - height / 2));\n        image.setAttribute(\"width\", String(width));\n        image.setAttribute(\"height\", String(height));\n      }\n      const strength = energy.get() * distortion * 2;\n      displaceRefs.current.forEach((node, index) => {\n        node?.setAttribute(\"scale\", String(strength * (0.72 + index * 0.28)));\n      });\n    }\n\n    // Slide the ripple noise slowly, so the crest moves like water.\n    const ripple = noiseRef.current;\n    if (ripple) {\n      ripple.setAttribute(\"x\", String(-((time * 70) % NOISE_PERIOD)));\n      ripple.setAttribute(\"y\", String(-((time * 40) % NOISE_PERIOD)));\n    }\n\n    const canvas = canvasRef.current;\n    const ctx = canvas?.getContext(\"2d\");\n    if (!canvas || !ctx) return;\n    ctx.clearRect(0, 0, canvas.width, canvas.height);\n    const dpr = canvas.width / Math.max(1, canvas.offsetWidth);\n\n    // Sparks thrown off the front: each leaves the crest where it is at its\n    // birth, drifts a little further out and fades.\n    for (const spark of sparksRef.current) {\n      const age = time - spark.at;\n      if (age <= 0 || age >= SPARK_LIFE_S) continue;\n      const born = WAVE_EASE(clamp01((spark.at - GATHER_S) / travel.get())) * reach.get();\n      const out = born + spark.drift * (1 - Math.exp(-age * 3));\n      const x = ox.get() + Math.cos(spark.angle) * out * ax.get();\n      const y = oy.get() + Math.sin(spark.angle) * out * ay.get();\n      ctx.globalAlpha = Math.sin(Math.PI * (age / SPARK_LIFE_S)) * 0.9;\n      ctx.fillStyle = spark.color;\n      ctx.beginPath();\n      ctx.arc(x * dpr, y * dpr, spark.size * dpr * (1 - (age / SPARK_LIFE_S) * 0.5), 0, Math.PI * 2);\n      ctx.fill();\n    }\n\n    if (time > GATHER_S + 0.1) return;\n    for (const dot of dotsRef.current) {\n      const span = GATHER_S - dot.delay;\n      const k = clamp01((time - dot.delay) / span);\n      if (k <= 0) continue;\n      const eased = 1 - (1 - k) ** 3;\n      const distance = dot.reach * (1 - eased);\n      const x = ox.get() + Math.cos(dot.angle) * distance * ax.get();\n      const y = oy.get() + Math.sin(dot.angle) * distance * ay.get();\n      ctx.globalAlpha = Math.sin(Math.PI * k) * (1 - smooth(GATHER_S, GATHER_S + 0.1, time));\n      ctx.fillStyle = dot.color;\n      ctx.beginPath();\n      ctx.arc(x * dpr, y * dpr, dot.size * dpr, 0, Math.PI * 2);\n      ctx.fill();\n    }\n  });\n\n  useLayoutEffect(() => {\n    if (!run) return;\n    const stage = stageRef.current;\n    if (!stage) return;\n    const rect = stage.getBoundingClientRect();\n    const width = stage.offsetWidth;\n    const height = stage.offsetHeight;\n    const zoom = rect.width > 0 ? width / rect.width : 1;\n\n    let x = type === \"horizontal\" ? 0 : width / 2;\n    let y = type === \"vertical\" ? height : height / 2;\n    const source = sourceRef?.current;\n    const press = pressRef.current;\n    if (type !== \"center\" && source) {\n      const box = source.getBoundingClientRect();\n      x = (box.left + box.width / 2 - rect.left) * zoom;\n      y = (box.top + box.height / 2 - rect.top) * zoom;\n    } else if (type !== \"center\" && press && performance.now() - press.at < 1500) {\n      x = (press.x - rect.left) * zoom;\n      y = (press.y - rect.top) * zoom;\n    }\n    pressRef.current = null;\n\n    const arcX = type === \"vertical\" ? ARC : 1;\n    const arcY = type === \"horizontal\" ? ARC : 1;\n    let far = 0;\n    for (const [cx, cy] of [\n      [0, 0],\n      [width, 0],\n      [0, height],\n      [width, height],\n    ]) {\n      far = Math.max(far, Math.hypot((cx - x) / arcX, (cy - y) / arcY));\n    }\n    ox.set(x);\n    oy.set(y);\n    ax.set(arcX);\n    ay.set(arcY);\n    reach.set(far + OVERSHOOT);\n    travel.set(duration);\n\n    const palette = colorsRef.current.length > 0 ? colorsRef.current : DEFAULT_COLORS;\n    dotsRef.current = Array.from({ length: DOTS }, (_, index) => ({\n      angle: (index / DOTS) * Math.PI * 2 + Math.random() * 0.4,\n      reach: 46 + Math.random() * 90,\n      delay: Math.random() * GATHER_S * 0.45,\n      size: 1 + Math.random() * 1,\n      color: palette[index % palette.length],\n    }));\n    sparksRef.current = Array.from({ length: SPARKS }, (_, index) => ({\n      at: GATHER_S + Math.random() * duration * 0.7,\n      angle: Math.random() * Math.PI * 2,\n      drift: 14 + Math.random() * 30,\n      size: 0.7 + Math.random() * 1.1,\n      color: index % 3 === 0 ? \"#ffffff\" : palette[index % palette.length],\n    }));\n    const canvas = canvasRef.current;\n    if (canvas) {\n      const dpr = Math.min(2, window.devicePixelRatio || 1);\n      canvas.width = Math.round(width * dpr);\n      canvas.height = Math.round(height * dpr);\n    }\n\n    // Hand focus to the incoming screen when it was in the outgoing one.\n    const incoming = layerRefs.current[run.target ? 1 : 0];\n    const outgoing = layerRefs.current[run.target ? 0 : 1];\n    if (outgoing?.contains(document.activeElement)) focusFirstIn(incoming);\n\n    const finish = () => {\n      setShown(run.target);\n      setRun((current) => (current?.id === run.id ? null : current));\n      completeRef.current?.(run.target);\n    };\n\n    if (reduce) {\n      fade.set(1);\n      const crossfade = animate(fade, 0, { duration: REDUCED_S, ease: \"linear\", onComplete: finish });\n      return () => crossfade.stop();\n    }\n\n    t.set(0);\n    const pull = animate(scale, PULL, {\n      duration: GATHER_S,\n      ease: EASE_OUT,\n      onComplete: () => {\n        animate(scale, 1, SPRING_PRESS);\n      },\n    });\n    const clock = animate(t, GATHER_S + duration + LINGER_S, {\n      duration: GATHER_S + duration + LINGER_S,\n      ease: \"linear\",\n      onComplete: finish,\n    });\n    return () => {\n      pull.stop();\n      clock.stop();\n      scale.set(1);\n    };\n  }, [run, type, sourceRef, duration, reduce, ox, oy, ax, ay, reach, travel, t, fade, scale]);\n\n  const layer = (index: 0 | 1, content: ReactNode) => {\n    const isTarget = (index === 1) === target;\n    const visible = isTarget || run !== null;\n    const mask = run && !reduce ? (isTarget ? insideMask : outsideMask) : undefined;\n    let opacity: MotionValue<number> | number = 1;\n    if (run && reduce) opacity = isTarget ? fadeIn : fade;\n    return (\n      <motion.div\n        ref={(node) => {\n          layerRefs.current[index] = node;\n        }}\n        aria-hidden={isTarget ? undefined : true}\n        inert={!isTarget}\n        className={cn(\"[grid-area:1/1]\", !visible && \"invisible\")}\n        style={{ maskImage: mask, WebkitMaskImage: mask, opacity }}\n      >\n        {content}\n      </motion.div>\n    );\n  };\n\n  const wave = run !== null && !reduce;\n\n  return (\n    <motion.div\n      className={cn(\"relative isolate overflow-hidden\", className)}\n      style={{ scale, transformOrigin }}\n      onPointerDownCapture={(event) => {\n        pressRef.current = { x: event.clientX, y: event.clientY, at: performance.now() };\n        onPointerDownCapture?.(event);\n      }}\n      {...props}\n    >\n      <div\n        ref={stageRef}\n        className=\"grid\"\n        style={{ filter: distort ? `url(#${filterId})` : undefined }}\n      >\n        {layer(0, children)}\n        {layer(1, revealedContent)}\n      </div>\n\n      {wave ? (\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0 rounded-[inherit]\">\n          {/* Blur under the front, strongest at it and trailing far behind. */}\n          <motion.div\n            className=\"absolute inset-0\"\n            style={{\n              backdropFilter: `blur(${BLUR}px)`,\n              WebkitBackdropFilter: `blur(${BLUR}px)`,\n              maskImage: blurMask,\n              WebkitMaskImage: blurMask,\n              opacity: bandOpacity,\n            }}\n          />\n          {/* The colour, rippled by slow noise. Its own layer, so the ripple\n              filter never becomes the backdrop root of the blur above. */}\n          <div\n            className=\"absolute\"\n            style={{\n              inset: -PAD,\n              filter: noise ? `url(#${filterId}-ripple)` : undefined,\n            }}\n          >\n            {/* A soft lead ahead, a long tail behind. */}\n            <motion.div\n              className=\"absolute inset-0\"\n              style={{\n                background: bandFill,\n                maskImage: bandMask,\n                WebkitMaskImage: bandMask,\n                maskComposite: \"intersect\",\n                opacity: bandOpacity,\n              }}\n            />\n            {/* A bright core right at the front. */}\n            <motion.div\n              className=\"absolute inset-0 bg-white\"\n              style={{ maskImage: coreMask, WebkitMaskImage: coreMask, opacity: coreOpacity }}\n            />\n          </div>\n          {/* The glow left on the edges, uneven and drifting, with a hairline. */}\n          <motion.div\n            className=\"absolute inset-0 rounded-[inherit]\"\n            style={{\n              background: rimFill,\n              maskImage: rimMask,\n              maskComposite: \"intersect, intersect, add\",\n              opacity: rimOpacity,\n            }}\n          />\n          <motion.div\n            className=\"absolute inset-0 rounded-[inherit] p-[1.5px]\"\n            style={{\n              background: hairFill,\n              maskImage: hairMask,\n              maskClip: \"border-box, content-box, border-box\",\n              maskComposite: \"intersect, exclude\",\n              opacity: rimOpacity,\n            }}\n          />\n          {/* Light gathering at the source before the wave leaves. */}\n          <motion.div\n            className=\"absolute size-28 -translate-x-1/2 -translate-y-1/2 rounded-full blur-[10px]\"\n            style={{ left: ox, top: oy, background: gatherFill, opacity: gatherOpacity, scale: gatherScale }}\n          />\n          <canvas ref={canvasRef} className=\"absolute inset-0 size-full\" />\n        </div>\n      ) : null}\n\n      {map ? (\n        <svg aria-hidden=\"true\" className=\"pointer-events-none absolute size-0\" focusable=\"false\">\n          {noise ? (\n            <filter\n              id={`${filterId}-ripple`}\n              x=\"0\"\n              y=\"0\"\n              width=\"100%\"\n              height=\"100%\"\n              colorInterpolationFilters=\"sRGB\"\n            >\n              <feImage\n                ref={noiseRef}\n                href={noise}\n                width={NOISE_SPAN}\n                height={NOISE_SPAN}\n                preserveAspectRatio=\"none\"\n                result=\"noise\"\n              />\n              {/* Past the noise image, a still surface rather than a shift. */}\n              <feFlood floodColor=\"rgb(128, 128, 128)\" result=\"still\" />\n              <feComposite in=\"noise\" in2=\"still\" operator=\"over\" result=\"ripple\" />\n              <feDisplacementMap\n                in=\"SourceGraphic\"\n                in2=\"ripple\"\n                scale={RIPPLE * 2}\n                xChannelSelector=\"R\"\n                yChannelSelector=\"G\"\n              />\n            </filter>\n          ) : null}\n          <filter\n            id={filterId}\n            x=\"-10%\"\n            y=\"-10%\"\n            width=\"120%\"\n            height=\"120%\"\n            colorInterpolationFilters=\"sRGB\"\n          >\n            <feFlood floodColor=\"rgb(128, 128, 128)\" result=\"flat\" />\n            <feImage ref={imageRef} href={map} preserveAspectRatio=\"none\" result=\"lens\" />\n            <feComposite in=\"lens\" in2=\"flat\" operator=\"over\" result=\"map\" />\n            {([\"r\", \"g\", \"b\"] as const).map((channel, index) => (\n              <feDisplacementMap\n                key={channel}\n                ref={(node) => {\n                  displaceRefs.current[index] = node;\n                }}\n                in=\"SourceGraphic\"\n                in2=\"map\"\n                scale={0}\n                xChannelSelector=\"R\"\n                yChannelSelector=\"G\"\n                result={`shift-${channel}`}\n              />\n            ))}\n            <feColorMatrix\n              in=\"shift-r\"\n              values=\"1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0\"\n              result=\"only-r\"\n            />\n            <feColorMatrix\n              in=\"shift-g\"\n              values=\"0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 1 0\"\n              result=\"only-g\"\n            />\n            <feColorMatrix\n              in=\"shift-b\"\n              values=\"0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 1 0\"\n              result=\"only-b\"\n            />\n            <feBlend in=\"only-r\" in2=\"only-g\" mode=\"screen\" result=\"rg\" />\n            <feBlend in=\"rg\" in2=\"only-b\" mode=\"screen\" />\n          </filter>\n        </svg>\n      ) : null}\n    </motion.div>\n  );\n}\n"},{"path":"lib/ease.ts","type":"registry:lib","target":"@lib/ease.ts","content":"// Shared motion tokens. Easing curves mirror the CSS custom properties in\n// globals.css; springs are the canonical physics used across components.\n// Strong custom variants — defaults like `ease-in`/`ease-out` feel weak.\n\nexport const EASE_OUT = [0.16, 1, 0.3, 1] as const;\n/** Accelerating curve for things that fall (a dropped ball, a toppled block). Not for UI entrances. */\nexport const EASE_IN = [0.55, 0, 1, 0.45] as const;\nexport const EASE_IN_OUT = [0.77, 0, 0.175, 1] as const;\nexport const EASE_DRAWER = [0.32, 0.72, 0, 1] as const;\n\n/** CSS string form of EASE_OUT for inline style transitions. */\nexport const EASE_OUT_CSS = \"cubic-bezier(0.16, 1, 0.3, 1)\";\n\n/** Press feedback on buttons and other tappable surfaces. */\nexport const SPRING_PRESS = {\n  type: \"spring\",\n  stiffness: 500,\n  damping: 30,\n  mass: 0.6,\n} as const;\n\n/** Content swaps — label/icon slots trading places inside a control. */\nexport const SPRING_SWAP = {\n  type: \"spring\",\n  stiffness: 460,\n  damping: 30,\n  mass: 0.55,\n} as const;\n\n/** Overlay panel entrances — modals and sheets summoned by pointer. */\nexport const SPRING_PANEL = {\n  type: \"spring\",\n  stiffness: 420,\n  damping: 40,\n  mass: 0.5,\n} as const;\n\n/** Shared-layout glides — pills, indicators and panels morphing between positions. */\nexport const SPRING_LAYOUT = {\n  type: \"spring\",\n  stiffness: 360,\n  damping: 32,\n  mass: 0.6,\n} as const;\n\n/** Cursor-follow physics for decorative mouse tracking (magnetic, tilt, dock). */\nexport const SPRING_MOUSE = {\n  stiffness: 200,\n  damping: 15,\n  mass: 0.3,\n} as const;\n\n/** Dragged handles and fills (sliders) — critically damped `useSpring` config,\n * so the value follows the pointer butterily and never rebounds off an end. */\nexport const SPRING_GLIDE = {\n  stiffness: 700,\n  damping: 50,\n  mass: 0.5,\n} as const;\n\n/** Shared-surface morphs: a trigger growing into its panel and back on one\n * weighted spring, so opening and closing travel the same path. */\nexport const SPRING_MORPH = {\n  type: \"spring\",\n  duration: 0.5,\n  bounce: 0.22,\n} as const;\n"},{"path":"lib/focusable.ts","type":"registry:lib","target":"@lib/focusable.ts","content":"/**\n * Elements that can usually take keyboard focus. The selector cannot see\n * everything focus() checks (an element under `display: none`, say), so a\n * caller that needs certainty tries focus() and checks where it landed.\n */\nexport const FOCUSABLE_SELECTOR = [\n  \"a[href]\",\n  \"button:not(:disabled)\",\n  \"input:not(:disabled):not([type='hidden'])\",\n  \"select:not(:disabled)\",\n  \"textarea:not(:disabled)\",\n  \"[tabindex]:not([tabindex='-1'])\",\n].join(\",\");\n\n/** Elements inside `container` that Tab can reach, in DOM order. */\nexport function focusablesIn(container: Element | null | undefined) {\n  return Array.from(\n    container?.querySelectorAll<HTMLElement>(FOCUSABLE_SELECTOR) ?? [],\n  ).filter((element) => element.tabIndex >= 0 && !element.closest(\"[inert]\"));\n}\n\n/** Focuses the first tabbable element in `panel`, or the panel itself. */\nexport function focusFirstIn(panel: HTMLElement | null | undefined) {\n  (focusablesIn(panel)[0] ?? panel)?.focus({ preventScroll: true });\n}\n\n/**\n * Keeps a Tab keypress inside `panel`, wrapping from the last tabbable element\n * to the first and back. Give the panel `tabIndex={-1}` so it can hold focus\n * when it has nothing tabbable.\n */\nexport function cycleTab(event: KeyboardEvent, panel: HTMLElement | null) {\n  if (event.key !== \"Tab\" || !panel) return;\n  const elements = focusablesIn(panel);\n  const first = elements[0];\n  const last = elements[elements.length - 1];\n  const active = document.activeElement;\n  if (!first || !last) {\n    event.preventDefault();\n    panel.focus({ preventScroll: true });\n  } else if (event.shiftKey && (active === first || active === panel)) {\n    event.preventDefault();\n    last.focus();\n  } else if (!event.shiftKey && active === last) {\n    event.preventDefault();\n    first.focus();\n  }\n}\n"},{"path":"lib/utils.ts","type":"registry:lib","target":"@lib/utils.ts","content":"import { clsx, type ClassValue } from \"clsx\"\nimport { twMerge } from \"tailwind-merge\"\n\nexport function cn(...inputs: ClassValue[]) {\n  return twMerge(clsx(inputs))\n}\n"}]}