{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "card-sticker-peel",
  "type": "registry:component",
  "title": "Sticker Peel",
  "description": "A die-cut sticker on its backing sheet. Drag to peel a corner and reveal the backing, click or press Enter to peel or reset.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "components",
    "sticker",
    "peel",
    "drag",
    "card",
    "fold",
    "clip-path"
  ],
  "docs": "https://hyperblur.dev/effects/card-sticker-peel",
  "files": [
    {
      "path": "registry/hyperblur/card-sticker-peel.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/card-sticker-peel.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type StickerCorner = \"br\" | \"bl\" | \"tr\" | \"tl\";\n\nexport interface CardStickerPeelProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  title?: string;\n  subtitle?: string;\n  backing?: string;\n  accent?: string;\n  corner?: StickerCorner;\n  ratio?: number;\n  idle?: boolean;\n  children?: React.ReactNode;\n}\n\nconst css = `\n.hb-qk5 {\n  position: relative;\n  display: block;\n  width: 100%;\n  aspect-ratio: var(--hb-qk5-r);\n  border-radius: 18px;\n  border: 1px solid #2a2a2a;\n  background:\n    radial-gradient(circle, rgba(0, 0, 0, 0.1) 1px, transparent 1.5px) 0 0 / 12px 12px,\n    linear-gradient(160deg, #f1ede2, #dcd6c6);\n  color: #121622;\n  font-family: inherit;\n  box-sizing: border-box;\n  cursor: grab;\n  user-select: none;\n  touch-action: none;\n  -webkit-tap-highlight-color: transparent;\n}\n.hb-qk5 *, .hb-qk5 *::before, .hb-qk5 *::after { box-sizing: border-box; }\n.hb-qk5[data-drag=\"true\"] { cursor: grabbing; }\n.hb-qk5:focus-visible { outline: 2px solid var(--hb-qk5-c); outline-offset: 3px; }\n.hb-qk5-back {\n  position: absolute;\n  inset: 6%;\n  display: flex;\n  padding: 2.4% 3%;\n  align-items: flex-end;\n  justify-content: flex-end;\n  border-radius: 20px;\n  border: 1.5px dashed rgba(18, 22, 34, 0.28);\n  font-size: 10px;\n  font-weight: 600;\n  letter-spacing: 0.16em;\n  text-transform: uppercase;\n  color: rgba(18, 22, 34, 0.5);\n}\n.hb-qk5[data-corner=\"bl\"] .hb-qk5-back { justify-content: flex-start; }\n.hb-qk5[data-corner=\"tr\"] .hb-qk5-back { align-items: flex-start; }\n.hb-qk5[data-corner=\"tl\"] .hb-qk5-back { align-items: flex-start; justify-content: flex-start; }\n.hb-qk5-stage {\n  position: absolute;\n  inset: 6%;\n  filter: drop-shadow(0 7px 7px rgba(18, 22, 34, 0.32));\n}\n.hb-qk5-face, .hb-qk5-flap { position: absolute; inset: 0; }\n.hb-qk5-face {\n  display: flex;\n  flex-direction: column;\n  align-items: center;\n  justify-content: center;\n  gap: 5%;\n  padding: 6%;\n  border-radius: 20px;\n  border: 5px solid #fbfaf6;\n  background:\n    repeating-conic-gradient(from 0deg at 50% 46%, var(--hb-qk5-c) 0 9deg, color-mix(in srgb, var(--hb-qk5-c) 78%, #ffffff) 9deg 18deg);\n  color: #ffffff;\n  overflow: hidden;\n}\n.hb-qk5-badge {\n  display: grid;\n  place-items: center;\n  width: 46%;\n  max-height: 58%;\n  aspect-ratio: 1;\n  border-radius: 50%;\n  background: #fbfaf6;\n  box-shadow: 0 3px 0 rgba(18, 22, 34, 0.25);\n}\n.hb-qk5-badge svg {\n  width: 56%;\n  height: 56%;\n  fill: var(--hb-qk5-c);\n  stroke: #121622;\n  stroke-width: 1.4;\n  stroke-linejoin: round;\n}\n.hb-qk5-tx { text-align: center; min-width: 0; max-width: 100%; }\n.hb-qk5-title {\n  margin: 0;\n  font-size: 19px;\n  font-weight: 800;\n  line-height: 1;\n  letter-spacing: 0.02em;\n  text-transform: uppercase;\n  color: #ffffff;\n  text-shadow: 0 2px 0 rgba(18, 22, 34, 0.4);\n}\n.hb-qk5-sub {\n  margin: 4px 0 0;\n  font-size: 10.5px;\n  font-weight: 600;\n  letter-spacing: 0.12em;\n  text-transform: uppercase;\n  color: rgba(255, 255, 255, 0.86);\n}\n.hb-qk5-flap { pointer-events: none; }\n`;\n\ntype Pt = [number, number];\n\nfunction clipHalf(poly: Pt[], side: (p: Pt) => number): Pt[] {\n  const out: Pt[] = [];\n  for (let i = 0; i < poly.length; i += 1) {\n    const a = poly[i];\n    const b = poly[(i + 1) % poly.length];\n    const fa = side(a);\n    const fb = side(b);\n    if (fa >= 0) out.push(a);\n    if ((fa >= 0) !== (fb >= 0)) {\n      const t = fa / (fa - fb);\n      out.push([a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]);\n    }\n  }\n  return out;\n}\n\nfunction cornerOf(corner: StickerCorner, w: number): Pt {\n  return [corner.endsWith(\"r\") ? w : 0, corner.startsWith(\"b\") ? 1 : 0];\n}\n\nfunction shape(poly: Pt[], w: number) {\n  return `polygon(${poly.map(([x, y]) => `${((x / w) * 100).toFixed(2)}% ${(y * 100).toFixed(2)}%`).join(\", \")})`;\n}\n\nfunction geometry(p: Pt, corner: StickerCorner, w: number) {\n  const c = cornerOf(corner, w);\n  const dx = p[0] - c[0];\n  const dy = p[1] - c[1];\n  const len = Math.hypot(dx, dy);\n  if (len < 0.004) return { face: \"none\", flap: \"polygon(0 0, 0 0, 0 0)\", paper: \"none\" };\n  const nx = dx / len;\n  const ny = dy / len;\n  const mx = (c[0] + p[0]) / 2;\n  const my = (c[1] + p[1]) / 2;\n  const f = (q: Pt) => (q[0] - mx) * nx + (q[1] - my) * ny;\n  const box: Pt[] = [\n    [0, 0],\n    [w, 0],\n    [w, 1],\n    [0, 1],\n  ];\n  const face = clipHalf(box, f);\n  const folded = clipHalf(box, (q) => -f(q)).map((q): Pt => {\n    const d = f(q);\n    return [q[0] - 2 * d * nx, q[1] - 2 * d * ny];\n  });\n  const angle = (Math.atan2(nx, -ny) * 180) / Math.PI;\n  const span = Math.abs(w * nx) + Math.abs(ny);\n  const at = ((mx - w / 2) * nx + (my - 0.5) * ny) / span + 0.5;\n  const ext = len / 2 / span;\n  const paper = `linear-gradient(${angle.toFixed(1)}deg, #a9a392 ${(at * 100).toFixed(2)}%, #f0ece3 ${((at + ext * 0.4) * 100).toFixed(2)}%, #fbfaf6 ${((at + ext) * 100).toFixed(2)}%)`;\n  return { face: shape(face, w), flap: shape(folded, w), paper };\n}\n\nfunction restPoint(corner: StickerCorner, w: number, k: number): Pt {\n  const c = cornerOf(corner, w);\n  const sx = c[0] > 0 ? -1 : 1;\n  const sy = c[1] > 0 ? -1 : 1;\n  return [c[0] + sx * k * w, c[1] + sy * k];\n}\n\nfunction clampPoint(p: Pt, corner: StickerCorner, w: number): Pt {\n  let x = Math.min(w, Math.max(0, p[0]));\n  let y = Math.min(1, Math.max(0, p[1]));\n  const c = cornerOf(corner, w);\n  const max = Math.hypot(w, 1) * 0.8;\n  const d = Math.hypot(x - c[0], y - c[1]);\n  if (d > max) {\n    x = c[0] + ((x - c[0]) / d) * max;\n    y = c[1] + ((y - c[1]) / d) * max;\n  }\n  return [x, y];\n}\n\nexport function CardStickerPeel({\n  title = \"Ship it\",\n  subtitle = \"Friday release\",\n  backing = \"Peel slowly\",\n  accent = \"#2f7bff\",\n  corner = \"br\",\n  ratio = 1,\n  idle = true,\n  className = \"\",\n  style,\n  children,\n  ...rest\n}: CardStickerPeelProps) {\n  const [p, setP] = React.useState<Pt>(() => restPoint(corner, ratio, 0.13));\n  const [peeled, setPeeled] = React.useState(false);\n  const pRef = React.useRef<Pt>(p);\n  const mode = React.useRef<\"idle\" | \"drag\" | \"held\">(\"idle\");\n  const hold = React.useRef<Pt>(p);\n  const drag = React.useRef({ x: 0, y: 0, p0: p, moved: false, from: \"idle\" as \"idle\" | \"held\" });\n  const reduced = React.useRef(false);\n  const root = React.useRef<HTMLDivElement>(null);\n  const [dragging, setDragging] = React.useState(false);\n\n  const put = React.useCallback((next: Pt) => {\n    pRef.current = next;\n    setP(next);\n  }, []);\n\n  React.useEffect(() => {\n    reduced.current = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const el = root.current;\n    if (!el || reduced.current || !idle) return;\n    let raf = 0;\n    const frame = (ms: number) => {\n      if (mode.current !== \"drag\") {\n        const goal =\n          mode.current === \"idle\"\n            ? restPoint(corner, ratio, 0.14 + 0.05 * Math.sin((ms / 1000) * 1.1))\n            : hold.current;\n        const cur = pRef.current;\n        const nx = cur[0] + (goal[0] - cur[0]) * 0.14;\n        const ny = cur[1] + (goal[1] - cur[1]) * 0.14;\n        if (Math.abs(nx - cur[0]) > 0.0002 || Math.abs(ny - cur[1]) > 0.0002) put([nx, ny]);\n      }\n      raf = requestAnimationFrame(frame);\n    };\n    const io = new IntersectionObserver(([entry]) => {\n      cancelAnimationFrame(raf);\n      if (entry.isIntersecting) raf = requestAnimationFrame(frame);\n    });\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(raf);\n    };\n  }, [corner, ratio, idle, put]);\n\n  const settle = React.useCallback(\n    (goal: Pt) => {\n      if (reduced.current || !idle) put(goal);\n    },\n    [idle, put],\n  );\n\n  const reset = React.useCallback(() => {\n    mode.current = \"idle\";\n    setPeeled(false);\n    settle(restPoint(corner, ratio, 0.13));\n  }, [corner, ratio, settle]);\n\n  const open = React.useCallback(() => {\n    const goal = clampPoint(restPoint(corner, ratio, 0.52), corner, ratio);\n    hold.current = goal;\n    mode.current = \"held\";\n    setPeeled(true);\n    settle(goal);\n  }, [corner, ratio, settle]);\n\n  const toggle = () => {\n    if (mode.current === \"held\") reset();\n    else open();\n  };\n\n  const down = (e: React.PointerEvent<HTMLDivElement>) => {\n    rest.onPointerDown?.(e);\n    if (e.button !== 0) return;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    drag.current = {\n      x: e.clientX,\n      y: e.clientY,\n      p0: pRef.current,\n      moved: false,\n      from: mode.current === \"held\" ? \"held\" : \"idle\",\n    };\n    mode.current = \"drag\";\n    setDragging(true);\n  };\n\n  const move = (e: React.PointerEvent<HTMLDivElement>) => {\n    rest.onPointerMove?.(e);\n    if (mode.current !== \"drag\") return;\n    const r = e.currentTarget.getBoundingClientRect();\n    if (!r.width || !r.height) return;\n    const d = drag.current;\n    const dx = e.clientX - d.x;\n    const dy = e.clientY - d.y;\n    if (Math.hypot(dx, dy) > 4) d.moved = true;\n    if (!d.moved) return;\n    const next = clampPoint([d.p0[0] + (dx / r.width) * ratio, d.p0[1] + dy / r.height], corner, ratio);\n    put(next);\n  };\n\n  const up = (e: React.PointerEvent<HTMLDivElement>) => {\n    rest.onPointerUp?.(e);\n    if (mode.current !== \"drag\") return;\n    if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId);\n    setDragging(false);\n    const d = drag.current;\n    if (!d.moved) {\n      mode.current = d.from;\n      toggle();\n      return;\n    }\n    const c = cornerOf(corner, ratio);\n    const dist = Math.hypot(pRef.current[0] - c[0], pRef.current[1] - c[1]);\n    if (dist < 0.1) {\n      reset();\n    } else {\n      hold.current = pRef.current;\n      mode.current = \"held\";\n      setPeeled(true);\n    }\n  };\n\n  const cancel = (e: React.PointerEvent<HTMLDivElement>) => {\n    rest.onPointerCancel?.(e);\n    if (mode.current !== \"drag\") return;\n    setDragging(false);\n    hold.current = pRef.current;\n    mode.current = \"held\";\n    setPeeled(true);\n  };\n\n  const key = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    rest.onKeyDown?.(e);\n    if (e.defaultPrevented) return;\n    if (e.key === \"Enter\" || e.key === \" \") {\n      e.preventDefault();\n      toggle();\n    } else if (e.key === \"Escape\" && mode.current === \"held\") {\n      e.preventDefault();\n      reset();\n    }\n  };\n\n  const geo = geometry(p, corner, ratio);\n\n  return (\n    <div\n      ref={root}\n      role=\"button\"\n      tabIndex={0}\n      aria-pressed={peeled}\n      aria-label={`${title} sticker. Drag a corner or press Enter to peel it, press again to put it back.`}\n      className={`hb-qk5 ${className}`}\n      data-corner={corner}\n      data-drag={dragging ? \"true\" : \"false\"}\n      style={{ \"--hb-qk5-r\": ratio, \"--hb-qk5-c\": accent, ...style } as React.CSSProperties}\n      {...rest}\n      onPointerDown={down}\n      onPointerMove={move}\n      onPointerUp={up}\n      onPointerCancel={cancel}\n      onKeyDown={key}\n    >\n      <style href=\"hb-card-sticker-peel\" precedence=\"default\">{css}</style>\n      <div className=\"hb-qk5-back\" aria-hidden=\"true\">\n        {backing}\n      </div>\n      <div className=\"hb-qk5-stage\">\n        <div className=\"hb-qk5-face\" style={{ clipPath: geo.face }}>\n          {children ?? (\n            <>\n              <span className=\"hb-qk5-badge\" aria-hidden=\"true\">\n                <svg viewBox=\"0 0 24 24\">\n                  <path d=\"M13.2 2 5 13.4h5.4L9.6 22 19 9.8h-5.6L13.2 2z\" />\n                </svg>\n              </span>\n              <span className=\"hb-qk5-tx\">\n                <h3 className=\"hb-qk5-title\">{title}</h3>\n                {subtitle ? <p className=\"hb-qk5-sub\">{subtitle}</p> : null}\n              </span>\n            </>\n          )}\n        </div>\n        <div className=\"hb-qk5-flap\" style={{ clipPath: geo.flap, background: geo.paper }} aria-hidden=\"true\" />\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}