{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "liquid-button",
  "title": "Liquid Button",
  "description": "Liquid glass buttons that swell when pressed.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "components/ui/liquid-button.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  animate,\n  motion,\n  useMotionTemplate,\n  useMotionValue,\n  useReducedMotion,\n  type HTMLMotionProps,\n} from \"motion/react\"\n\nimport { LiquidGlass } from \"@/components/ui/liquid-glass\"\nimport { afterglow } from \"@/lib/afterglow\"\nimport { cn } from \"@/lib/utils\"\n\nconst sizes = {\n  sm: \"h-8 gap-1.5 px-3.5 text-[13px] [&_svg]:size-3.5\",\n  md: \"h-10 gap-2 px-4.5 text-sm [&_svg]:size-4\",\n  lg: \"h-12 gap-2 px-6 text-[15px] [&_svg]:size-[18px]\",\n  icon: \"size-10 [&_svg]:size-[18px]\",\n}\n\n// liquid glass swells when pressed and settles back with a little overshoot\nconst swell = { type: \"spring\", stiffness: 420, damping: 27, mass: 0.7 } as const\n\ntype LiquidButtonProps = Omit<HTMLMotionProps<\"button\">, \"children\"> & {\n  size?: keyof typeof sizes\n  /** tints the glass with the glow color, for the primary action */\n  tinted?: boolean\n  children?: React.ReactNode\n}\n\nfunction LiquidButton({\n  size = \"md\",\n  tinted = false,\n  className,\n  children,\n  type = \"button\",\n  onPointerEnter,\n  onPointerMove,\n  onPointerLeave,\n  ...props\n}: LiquidButtonProps) {\n  const reduceMotion = useReducedMotion()\n  const x = useMotionValue(0)\n  const y = useMotionValue(0)\n  const light = useMotionValue(0)\n  const glow = useMotionTemplate`radial-gradient(64px circle at ${x}px ${y}px, oklch(1 0 0 / 30%), transparent 70%)`\n\n  function track(event: React.PointerEvent<HTMLButtonElement>) {\n    const rect = event.currentTarget.getBoundingClientRect()\n    // undo the press scale, so the light stays under the pointer\n    const scale = rect.width / event.currentTarget.offsetWidth || 1\n    x.set((event.clientX - rect.left) / scale)\n    y.set((event.clientY - rect.top) / scale)\n  }\n\n  return (\n    <motion.button\n      data-slot=\"liquid-button\"\n      type={type}\n      className={cn(\n        \"relative inline-flex shrink-0 cursor-pointer items-center justify-center rounded-full font-medium whitespace-nowrap outline-none select-none focus-visible:outline-2 focus-visible:outline-offset-2 focus-visible:outline-ring disabled:pointer-events-none disabled:text-muted-foreground\",\n        tinted ? \"text-glow-foreground\" : \"text-foreground\",\n        sizes[size],\n        className\n      )}\n      whileTap={{ scale: reduceMotion ? 1 : 1.04 }}\n      transition={swell}\n      onPointerEnter={(event) => {\n        onPointerEnter?.(event)\n        track(event)\n        animate(light, 1, { duration: 0.2 })\n      }}\n      onPointerMove={(event) => {\n        onPointerMove?.(event)\n        track(event)\n      }}\n      onPointerLeave={(event) => {\n        onPointerLeave?.(event)\n        animate(light, 0, { duration: afterglow.linger, ease: afterglow.ease })\n      }}\n      {...props}\n    >\n      <LiquidGlass\n        aria-hidden\n        className=\"absolute inset-0 rounded-[inherit]\"\n        tint={\n          tinted ? \"color-mix(in oklch, var(--glow) 72%, transparent)\" : undefined\n        }\n      />\n      {/* a soft light under the pointer, lingering after it leaves */}\n      <motion.span\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] mix-blend-plus-lighter\"\n        style={{ background: glow, opacity: light }}\n      />\n      <span className=\"relative inline-flex items-center gap-[inherit]\">\n        {children}\n      </span>\n    </motion.button>\n  )\n}\n\nexport { LiquidButton, type LiquidButtonProps }\n",
      "type": "registry:ui"
    },
    {
      "path": "components/ui/liquid-glass.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\nimport {\n  isMotionValue,\n  motion,\n  useMotionValue,\n  useTransform,\n  type MotionValue,\n} from \"motion/react\"\n\nimport { ringMask } from \"@/lib/afterglow\"\nimport { cn } from \"@/lib/utils\"\n\n/*\n * Liquid glass: a pane that bends whatever sits behind it, like Apple's\n * Liquid Glass. The rim is a curved lens, so content near the edges is\n * pulled inward, while the flat middle stays clear.\n *\n * Refraction is an SVG displacement map used as a backdrop-filter, which only\n * Chromium supports. Other browsers get a frosted fallback with the same rim.\n */\n\nconst SAMPLES = 128\nconst INDEX_OF_REFRACTION = 1.5\n\n// convex squircle: flat in the middle, rounding off toward the rim\nconst surface = (x: number) => Math.pow(1 - Math.pow(1 - x, 4), 0.25)\n\n// how far a straight-down ray is bent sideways at each point across the rim\nfunction rimProfile(bezel: number) {\n  const profile = new Float32Array(SAMPLES)\n  for (let i = 0; i < SAMPLES; i++) {\n    const x = i / (SAMPLES - 1)\n    const a = Math.max(x - 0.001, 0)\n    const b = Math.min(x + 0.001, 1)\n    const slope = (surface(b) - surface(a)) / (b - a)\n    const incident = Math.atan(slope)\n    const refracted = Math.asin(Math.sin(incident) / INDEX_OF_REFRACTION)\n    const thickness = bezel * (0.25 + surface(x))\n    profile[i] = thickness * Math.tan(incident - refracted)\n  }\n  return profile\n}\n\ntype DisplacementMap = { url: string; scale: number }\nconst maps = new Map<string, DisplacementMap>()\n\nfunction displacementMap(\n  width: number,\n  height: number,\n  radius: number,\n  bezel: number,\n  magnify: number\n): DisplacementMap {\n  const key = [width, height, radius, bezel, magnify].join(\":\")\n  const cached = maps.get(key)\n  if (cached) return cached\n\n  const profile = rimProfile(bezel)\n  const dx = new Float32Array(width * height)\n  const dy = new Float32Array(width * height)\n  let max = 0\n\n  for (let j = 0; j < height; j++) {\n    for (let i = 0; i < width; i++) {\n      // signed distance to a rounded rectangle, and the outward normal\n      const px = i + 0.5 - width / 2\n      const py = j + 0.5 - height / 2\n      const qx = Math.abs(px) - width / 2 + radius\n      const qy = Math.abs(py) - height / 2 + radius\n      const inside =\n        -(Math.hypot(Math.max(qx, 0), Math.max(qy, 0)) +\n          Math.min(Math.max(qx, qy), 0) -\n          radius)\n      let nx = 0\n      let ny = 0\n      if (qx > 0 && qy > 0) {\n        const length = Math.hypot(qx, qy) || 1\n        nx = (qx / length) * Math.sign(px)\n        ny = (qy / length) * Math.sign(py)\n      } else if (qx > qy) nx = Math.sign(px)\n      else ny = Math.sign(py)\n\n      let x = -px * magnify\n      let y = -py * magnify\n      if (inside >= 0 && inside < bezel) {\n        // sample inward, so the rim shows what's just inside the edge\n        const shift = profile[Math.round((inside / bezel) * (SAMPLES - 1))]\n        x -= nx * shift\n        y -= ny * shift\n      }\n      const k = j * width + i\n      dx[k] = x\n      dy[k] = y\n      max = Math.max(max, Math.abs(x), Math.abs(y))\n    }\n  }\n\n  const canvas = document.createElement(\"canvas\")\n  canvas.width = width\n  canvas.height = height\n  const context = canvas.getContext(\"2d\")\n  if (!context) return { url: \"\", scale: 0 }\n  const image = context.createImageData(width, height)\n  for (let k = 0; k < width * height; k++) {\n    // 128 is \"no shift\"; red moves along x, green along y\n    image.data[k * 4] = 128 + (dx[k] / (max || 1)) * 127\n    image.data[k * 4 + 1] = 128 + (dy[k] / (max || 1)) * 127\n    image.data[k * 4 + 2] = 128\n    image.data[k * 4 + 3] = 255\n  }\n  context.putImageData(image, 0, 0)\n\n  const map = { url: canvas.toDataURL(), scale: max * 2 }\n  if (maps.size > 48) maps.delete(maps.keys().next().value!)\n  maps.set(key, map)\n  return map\n}\n\n// only Chromium can use an SVG filter as a backdrop-filter\nfunction canRefract() {\n  const nav = navigator as Navigator & {\n    userAgentData?: { brands: { brand: string }[] }\n  }\n  if (nav.userAgentData) {\n    return nav.userAgentData.brands.some((b) => b.brand === \"Chromium\")\n  }\n  return /Chrome\\/\\d+/.test(nav.userAgent) && !/Firefox|FxiOS/.test(nav.userAgent)\n}\n\nconst noopSubscribe = () => () => {}\n\nfunction useCanRefract() {\n  return React.useSyncExternalStore(noopSubscribe, canRefract, () => false)\n}\n\ntype LiquidGlassProps = React.ComponentProps<\"div\"> & {\n  /** width of the curved rim in px, defaults to the corner radius (max 24) */\n  bezel?: number\n  /** 0 is flat glass, 1 is the full lens; pass a motion value to animate it */\n  refraction?: number | MotionValue<number>\n  /** zooms the middle like a magnifier, 0 to 0.3 */\n  magnify?: number\n  /** blur behind the glass in px */\n  frost?: number\n  /** a color mixed over the glass, e.g. for a tinted primary button */\n  tint?: string\n  /**\n   * fades the whole pane in and out. Never fade a parent of liquid glass\n   * instead: an ancestor with opacity cuts the glass off from what's behind it.\n   */\n  presence?: number | MotionValue<number>\n}\n\nfunction LiquidGlass({\n  bezel,\n  refraction = 1,\n  magnify = 0,\n  frost = 1,\n  tint,\n  presence = 1,\n  className,\n  children,\n  ...props\n}: LiquidGlassProps) {\n  const ref = React.useRef<HTMLDivElement>(null)\n  const displaceRef = React.useRef<SVGFEDisplacementMapElement>(null)\n  const id = `liquid-${React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`\n  const canRefractHere = useCanRefract()\n  // A fixed zero opts out of SVG backdrop sampling entirely. Native frosting avoids\n  // clipped-backdrop seams when flat panes overlap and change stacking order.\n  // Motion values still keep the map ready so they can animate away from zero.\n  const refract = canRefractHere && (typeof refraction !== \"number\" || refraction > 0)\n  const [shape, setShape] = React.useState<{ w: number; h: number; r: number }>()\n  // the scale last written to the filter, so a no-op resize can put it back\n  const applied = React.useRef(0)\n\n  React.useEffect(() => {\n    const node = ref.current\n    if (!node || !refract) return\n    const measure = () => {\n      const w = Math.round(node.offsetWidth)\n      const h = Math.round(node.offsetHeight)\n      const raw = getComputedStyle(node).borderTopLeftRadius\n      const value = parseFloat(raw) || 0\n      const r = Math.round(\n        Math.min(raw.endsWith(\"%\") ? (value / 100) * Math.min(w, h) : value, w / 2, h / 2)\n      )\n      setShape((prev) => {\n        if (prev?.w === w && prev.h === h && prev.r === r) {\n          displaceRef.current?.setAttribute(\"scale\", String(applied.current))\n          return prev\n        }\n        return { w, h, r }\n      })\n    }\n    // measure right away, then wait for resizing to settle before rebuilding the map\n    let first = true\n    let frame = 0\n    let timer = 0\n    const observer = new ResizeObserver(() => {\n      if (first) {\n        first = false\n        measure()\n        return\n      }\n      // until the new map is ready, the old one would bend the wrong pixels\n      displaceRef.current?.setAttribute(\"scale\", \"0\")\n      window.clearTimeout(timer)\n      timer = window.setTimeout(() => {\n        frame = requestAnimationFrame(measure)\n      }, 100)\n    })\n    observer.observe(node)\n    return () => {\n      observer.disconnect()\n      window.clearTimeout(timer)\n      cancelAnimationFrame(frame)\n    }\n  }, [refract])\n\n  const map = React.useMemo(() => {\n    if (!refract || !shape || shape.w < 2 || shape.h < 2) return undefined\n    const rim = Math.max(1, Math.min(bezel ?? Math.min(shape.r, 24), shape.w / 2, shape.h / 2))\n    return displacementMap(shape.w, shape.h, shape.r, Math.round(rim), magnify)\n  }, [bezel, magnify, refract, shape])\n\n  // animate refraction by scaling the filter, without rebuilding the map\n  React.useEffect(() => {\n    if (!map) return\n    const apply = (v: number) => {\n      applied.current = map.scale * v\n      displaceRef.current?.setAttribute(\"scale\", String(applied.current))\n    }\n    if (typeof refraction === \"number\") {\n      apply(refraction)\n      return\n    }\n    apply(refraction.get())\n    return refraction.on(\"change\", apply)\n  }, [map, refraction])\n\n  const ownPresence = useMotionValue(isMotionValue(presence) ? 1 : presence)\n  const visible = isMotionValue(presence) ? presence : ownPresence\n  React.useEffect(() => {\n    if (!isMotionValue(presence)) ownPresence.set(presence)\n  }, [ownPresence, presence])\n  const rimOpacity = useTransform(visible, (v) => v * 0.95)\n\n  const strength = isMotionValue(refraction) ? refraction.get() : refraction\n  const backdrop = map\n    ? `url(#${id})`\n    : `blur(${Math.max(frost, 10)}px) saturate(1.6)`\n\n  return (\n    <div\n      ref={ref}\n      data-slot=\"liquid-glass\"\n      // no isolation here: an isolated parent cuts the glass off from the scene\n      // behind it in Chrome. Layers stack in source order, and direct children\n      // are made relative so they sit on top (wrap an absolute child to keep it).\n      className={cn(\"relative [&>:where(:not([data-glass-layer]))]:relative\", className)}\n      {...props}\n    >\n      {map && (\n        <svg data-glass-layer aria-hidden width=\"0\" height=\"0\" className=\"pointer-events-none absolute\">\n          <filter id={id} colorInterpolationFilters=\"sRGB\">\n            <feGaussianBlur in=\"SourceGraphic\" stdDeviation={frost} result=\"frost\" />\n            <feImage\n              href={map.url}\n              x=\"0\"\n              y=\"0\"\n              width={shape?.w}\n              height={shape?.h}\n              preserveAspectRatio=\"none\"\n              result=\"map\"\n            />\n            <feDisplacementMap\n              ref={displaceRef}\n              in=\"frost\"\n              in2=\"map\"\n              scale={map.scale * strength}\n              xChannelSelector=\"R\"\n              yChannelSelector=\"G\"\n              result=\"bent\"\n            />\n            {/* glass makes what's behind it a little brighter and more vivid */}\n            <feColorMatrix in=\"bent\" type=\"saturate\" values=\"1.45\" result=\"vivid\" />\n            <feComponentTransfer in=\"vivid\">\n              <feFuncR type=\"linear\" slope=\"1.05\" />\n              <feFuncG type=\"linear\" slope=\"1.05\" />\n              <feFuncB type=\"linear\" slope=\"1.05\" />\n            </feComponentTransfer>\n          </filter>\n        </svg>\n      )}\n      <motion.div\n        data-glass-layer\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] shadow-[0_10px_30px_-10px_var(--liquid-shadow),0_2px_8px_-2px_var(--liquid-shadow)]\"\n        style={{ opacity: visible }}\n      />\n      <motion.div\n        data-glass-layer\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit]\"\n        style={{\n          backdropFilter: backdrop,\n          WebkitBackdropFilter: backdrop,\n          opacity: visible,\n        }}\n      />\n      {/* tint, heavier when there's no refraction so text stays legible */}\n      <motion.div\n        data-glass-layer\n        aria-hidden\n        className={cn(\n          \"pointer-events-none absolute inset-0 rounded-[inherit] bg-(--liquid-tint)\",\n          !map && \"bg-(--liquid-fallback)\"\n        )}\n        style={tint ? { background: tint, opacity: visible } : { opacity: visible }}\n      />\n      {/* volume: light gathers inside the top edge, shade settles along the bottom */}\n      <motion.div\n        data-glass-layer\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] shadow-[inset_0_1px_16px_-4px_var(--liquid-glow),inset_0_-12px_20px_-14px_var(--liquid-shade)]\"\n        style={{ opacity: visible }}\n      />\n      {/* rim light: bright where the light comes from (top left), softer opposite */}\n      <motion.div\n        data-glass-layer\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] shadow-[inset_0_0_0_0.5px_var(--liquid-edge),inset_1px_1.5px_1px_-1px_var(--liquid-rim),inset_-1px_-1.5px_1px_-1px_color-mix(in_oklch,var(--liquid-rim)_45%,transparent)]\"\n        style={{ opacity: visible }}\n      />\n      <motion.div\n        data-glass-layer\n        aria-hidden\n        className=\"pointer-events-none absolute inset-0 rounded-[inherit] p-px\"\n        style={{\n          ...ringMask,\n          background:\n            \"conic-gradient(from 300deg, var(--liquid-rim), transparent 70deg, transparent 110deg, color-mix(in oklch, var(--liquid-rim) 55%, transparent) 180deg, transparent 250deg, transparent 290deg, var(--liquid-rim))\",\n          opacity: rimOpacity,\n        }}\n      />\n      {children}\n    </div>\n  )\n}\n\nexport { LiquidGlass, useCanRefract, type LiquidGlassProps }\n",
      "type": "registry:ui"
    },
    {
      "path": "lib/afterglow.ts",
      "content": "import type { CSSProperties } from \"react\"\nimport type { TargetAndTransition, Transition } from \"motion/react\"\n\n// shared spring presets, every component picks from these\nexport const springs = {\n  snappy: { stiffness: 520, damping: 34, mass: 0.6 },\n  soft: { stiffness: 260, damping: 26, mass: 0.8 },\n  glide: { stiffness: 120, damping: 20, mass: 1 },\n} as const\n\nexport type SpringName = keyof typeof springs\n\nexport function spring(name: SpringName): Transition {\n  return { type: \"spring\", ...springs[name] }\n}\n\n// how a glow fades once its source moves away: slow, with a long tail\nexport const afterglow = {\n  linger: 0.9,\n  ease: [0.22, 1, 0.36, 1],\n} as const satisfies { linger: number; ease: Transition[\"ease\"] }\n\n// paints only the padding ring of an element, used for glowing borders\nexport const ringMask: CSSProperties = {\n  WebkitMask:\n    \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  WebkitMaskComposite: \"xor\",\n  mask: \"linear-gradient(#000 0 0) content-box, linear-gradient(#000 0 0)\",\n  maskComposite: \"exclude\",\n}\n\n// small icon gestures, played when a control is pressed or selected\nexport const iconGestures = {\n  pop: { scale: [1, 1.2, 1] },\n  ring: { rotate: [0, -18, 14, -9, 4, 0], scale: [1, 1.12, 1] },\n  // a gear looks the same after half a turn, so it can rest there and snap back unseen\n  turn: { rotate: [0, 180], scale: [1, 1.12, 1] },\n  hop: { y: [0, -3, 0], scale: [1, 1.1, 1] },\n  nudge: { x: [0, 2.5, 0], scale: [1, 1.1, 1] },\n} satisfies Record<string, TargetAndTransition>\n\nexport type IconGesture = keyof typeof iconGestures\n\n// leaving a gesture is instant: every gesture already ends at, or looks like, its resting pose\nexport const iconRest: TargetAndTransition = { scale: 1, rotate: 0, x: 0, y: 0, transition: { duration: 0 } }\n",
      "type": "registry:lib"
    }
  ],
  "cssVars": {
    "theme": {
      "color-glow": "var(--glow)",
      "color-glow-foreground": "var(--glow-foreground)",
      "color-glow-2": "var(--glow-2)",
      "color-glow-3": "var(--glow-3)",
      "color-glass": "var(--glass)",
      "color-gloss-highlight": "var(--gloss-highlight)",
      "shadow-gloss": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -1px 0 0 var(--gloss-shade), 0 0 0 1px var(--gloss-edge), 0 1px 2px 0 var(--gloss-depth), 0 4px 12px -4px var(--gloss-depth)",
      "shadow-glass": "inset 0 1px 0 0 var(--gloss-highlight), inset 0 -10px 24px -18px var(--gloss-shade), inset 0 0 0 1px var(--gloss-edge), 0 2px 6px -1px var(--gloss-depth), 0 18px 40px -12px var(--gloss-depth)",
      "shadow-well": "inset 0 1px 3px 0 var(--gloss-depth), inset 0 0 0 1px var(--gloss-edge), 0 1px 0 0 var(--gloss-highlight)"
    },
    "light": {
      "glow": "oklch(0.7 0.19 45)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.64 0.22 12)",
      "glow-3": "oklch(0.56 0.21 300)",
      "glass": "oklch(1 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 95%)",
      "gloss-shade": "oklch(0.3 0.03 285 / 10%)",
      "gloss-depth": "oklch(0.32 0.03 285 / 20%)",
      "gloss-edge": "oklch(0.22 0.02 285 / 10%)",
      "liquid-tint": "oklch(1 0 0 / 18%)",
      "liquid-fallback": "oklch(1 0 0 / 55%)",
      "liquid-rim": "oklch(1 0 0 / 95%)",
      "liquid-edge": "oklch(0.2 0.02 285 / 10%)",
      "liquid-shadow": "oklch(0.22 0.02 285 / 26%)",
      "liquid-glow": "oklch(1 0 0 / 55%)",
      "liquid-shade": "oklch(0.25 0.03 285 / 14%)"
    },
    "dark": {
      "glow": "oklch(0.8 0.16 55)",
      "glow-foreground": "oklch(0.22 0.05 40)",
      "glow-2": "oklch(0.7 0.2 15)",
      "glow-3": "oklch(0.65 0.2 300)",
      "glass": "oklch(0.19 0 0 / 55%)",
      "gloss-highlight": "oklch(1 0 0 / 16%)",
      "gloss-shade": "oklch(0 0 0 / 30%)",
      "gloss-depth": "oklch(0.04 0 0 / 60%)",
      "gloss-edge": "oklch(1 0 0 / 9%)",
      "liquid-tint": "oklch(0.2 0 0 / 22%)",
      "liquid-fallback": "oklch(0.2 0 0 / 45%)",
      "liquid-rim": "oklch(1 0 0 / 60%)",
      "liquid-edge": "oklch(1 0 0 / 10%)",
      "liquid-shadow": "oklch(0 0 0 / 50%)",
      "liquid-glow": "oklch(1 0 0 / 24%)",
      "liquid-shade": "oklch(0 0 0 / 28%)"
    }
  },
  "type": "registry:ui"
}