{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "sticker-peel",
  "type": "registry:component",
  "title": "Sticker Peel",
  "description": "A glossy die-cut sticker that peels from the corner following the cursor, with curvature, a paper back and a shadow.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Cards"
  ],
  "docs": "Installed in components/furin/sticker-peel/. Docs, live controls and props table: https://furin.dev/components/sticker-peel/",
  "files": [
    {
      "path": "registry/sticker-peel/StickerPeel.tsx",
      "content": "\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport type { CSSProperties } from \"react\";\nimport \"./StickerPeel.css\";\n\nexport interface StickerPeelProps {\n  /** Texto grande de la calcomanía. */\n  children?: string;\n  /** Texto pequeño bajo el principal. */\n  subtitle?: string;\n  /** Primer color del degradado de la calcomanía. */\n  colorA?: string;\n  /** Segundo color del degradado de la calcomanía. */\n  colorB?: string;\n  /** Esquina desde la que se despega. */\n  corner?: \"bottom-right\" | \"bottom-left\" | \"top-right\" | \"top-left\";\n  /** Brillo holográfico del vinilo (0 a 1.5). */\n  gloss?: number;\n  /** Cuánto se puede despegar (0.2 a 0.8 del diámetro). */\n  maxPeel?: number;\n  /** Si no hay cursor, se levanta sola la esquina de vez en cuando. */\n  autoplay?: boolean;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst CORNERS = { \"bottom-right\": [1, 1], \"bottom-left\": [-1, 1], \"top-right\": [1, -1], \"top-left\": [-1, -1] } as const;\n\n/** Calcomanía de vinilo troquelada que se despega desde la esquina siguiendo al cursor, con curvatura, reverso de papel y sombra. */\nexport function StickerPeel({\n  children = \"hello\",\n  subtitle = \"SUPER PRO · 2026\",\n  colorA = \"#ff5d8f\",\n  colorB = \"#5b3dff\",\n  corner = \"bottom-right\",\n  gloss = 1,\n  maxPeel = 0.62,\n  autoplay = true,\n  className = \"\",\n  style,\n}: StickerPeelProps) {\n  const ref = useRef<HTMLCanvasElement>(null);\n  const opts = useRef({ children, subtitle, colorA, colorB, corner, gloss, maxPeel, autoplay });\n  opts.current = { children, subtitle, colorA, colorB, corner, gloss, maxPeel, autoplay };\n\n  useEffect(() => {\n    const cv = ref.current;\n    const ctx = cv?.getContext(\"2d\");\n    if (!cv || !ctx) return;\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    const mk = () => { const c = document.createElement(\"canvas\"); return [c, c.getContext(\"2d\")!] as const; };\n    const [art, ax] = mk(), [front, fx] = mk(), [back, bx] = mk(), [blk, kx] = mk(), [wht, wx] = mk(), [sh, shx] = mk(), [smallC, sx] = mk();\n    const nativeBlur = typeof (ctx as CanvasRenderingContext2D & { filter?: string }).filter === \"string\";\n    let W = 0, H = 0, dpr = 1, R = 100, A = 240, theta = Math.PI / 4;\n    let raf = 0, visible = true, last = 0, time = 0, built = \"\";\n    const st = { c: 100, v: 0, tc: 100 };\n    const ptr = { x: 0, y: 0, inside: false };\n\n    // Dibuja la calcomanía derecha (upright) y la gira al marco (u,v) del despegue.\n    const build = () => {\n      const o = opts.current;\n      const key = [o.children, o.subtitle, o.colorA, o.colorB, o.corner, R, dpr].join(\"|\");\n      if (key === built) return;\n      built = key;\n      A = Math.ceil(R * 2 + 10);\n      const px = Math.round(A * dpr);\n      for (const c of [art, front, back, blk, wht, sh]) { c.width = px; c.height = px; }\n      smallC.width = Math.max(2, Math.round(A / 4)); smallC.height = smallC.width;\n      const [dx, dy] = CORNERS[o.corner];\n      theta = Math.atan2(dy, dx);\n      const up = document.createElement(\"canvas\"); up.width = px; up.height = px;\n      const g = up.getContext(\"2d\")!;\n      g.scale(dpr, dpr);\n      g.translate(A / 2, A / 2);\n      // Contorno troquelado: sello con 16 ondas suaves.\n      const seal = (r: number) => { g.beginPath(); for (let i = 0; i <= 360; i++) { const a = (i / 360) * Math.PI * 2; const rr = r * (1 + 0.022 * Math.cos(a * 16)); g.lineTo(rr * Math.cos(a), rr * Math.sin(a)); } g.closePath(); };\n      seal(R);\n      g.fillStyle = \"#fbfaf6\"; g.fill();                   // borde blanco del troquel\n      g.save(); seal(R - 11); g.clip();\n      const bg = g.createLinearGradient(-R, -R, R, R);\n      bg.addColorStop(0, o.colorA); bg.addColorStop(1, o.colorB);\n      g.fillStyle = bg; g.fillRect(-R, -R, R * 2, R * 2);\n      // Rayos de sol procedimentales.\n      g.globalAlpha = 0.13; g.fillStyle = \"#fff\";\n      for (let i = 0; i < 22; i++) { const a = (i / 22) * Math.PI * 2; g.beginPath(); g.moveTo(0, 0); g.arc(0, 0, R * 1.3, a, a + Math.PI / 22); g.closePath(); g.fill(); }\n      g.globalAlpha = 1;\n      const rg = g.createRadialGradient(0, 0, 0, 0, 0, R * 0.9);\n      rg.addColorStop(0, \"rgba(255,255,255,0.28)\"); rg.addColorStop(0.55, \"rgba(255,255,255,0)\"); rg.addColorStop(1, \"rgba(0,0,0,0.28)\");\n      g.fillStyle = rg; g.fillRect(-R, -R, R * 2, R * 2);\n      // Anillo fino.\n      g.strokeStyle = \"rgba(255,255,255,0.55)\"; g.lineWidth = 1.5; g.beginPath(); g.arc(0, 0, R * 0.78, 0, Math.PI * 2); g.stroke();\n      g.restore();\n      // Texto.\n      g.textAlign = \"center\"; g.textBaseline = \"middle\";\n      const fs = Math.min(R * 0.62, (R * 1.35) / Math.max(2.2, o.children.length * 0.62));\n      g.font = `800 ${fs}px Geist, \"Inter\", system-ui, sans-serif`;\n      g.shadowColor = \"rgba(30,10,80,0.45)\"; g.shadowBlur = 10; g.shadowOffsetY = 4;\n      g.fillStyle = \"#fff\"; g.fillText(o.children, 0, -R * 0.04);\n      g.shadowColor = \"transparent\";\n      g.font = `600 ${Math.max(8, R * 0.085)}px \"JetBrains Mono\", ui-monospace, monospace`;\n      g.fillStyle = \"rgba(255,255,255,0.85)\";\n      g.fillText(o.subtitle, 0, R * 0.36);\n      // Al marco del despegue: eje u a lo largo de la esquina.\n      ax.setTransform(1, 0, 0, 1, 0, 0);\n      ax.clearRect(0, 0, px, px);\n      ax.translate(px / 2, px / 2); ax.rotate(-theta); ax.drawImage(up, -px / 2, -px / 2);\n      ax.setTransform(1, 0, 0, 1, 0, 0);\n      // Reverso (papel siliconado), y siluetas negra/blanca para sombrear por franjas.\n      const tint = (c: HTMLCanvasElement, cx: CanvasRenderingContext2D, fill: string | CanvasGradient) => {\n        cx.setTransform(1, 0, 0, 1, 0, 0); cx.globalCompositeOperation = \"source-over\"; cx.clearRect(0, 0, px, px);\n        cx.drawImage(art, 0, 0); cx.globalCompositeOperation = \"source-in\"; cx.fillStyle = fill; cx.fillRect(0, 0, px, px); cx.globalCompositeOperation = \"source-over\";\n        void c;\n      };\n      const bgd = bx.createLinearGradient(0, 0, px, px);\n      bgd.addColorStop(0, \"#f3f2ed\"); bgd.addColorStop(1, \"#dedcd4\");\n      tint(back, bx, bgd);\n      bx.globalCompositeOperation = \"source-atop\"; bx.fillStyle = \"rgba(120,116,104,0.10)\";\n      for (let k = -px; k < px * 2; k += 7 * dpr) { bx.fillRect(k, 0, 1 * dpr, px); }\n      bx.globalCompositeOperation = \"source-over\";\n      tint(blk, kx, \"#000\");\n      tint(wht, wx, \"#fff\");\n    };\n\n    const resize = () => {\n      dpr = Math.min(window.devicePixelRatio || 1, 2);\n      W = cv.clientWidth; H = cv.clientHeight;\n      cv.width = Math.max(2, Math.round(W * dpr)); cv.height = Math.max(2, Math.round(H * dpr));\n      R = Math.max(60, Math.min(W, H) * 0.3);\n      st.c = st.tc = R;\n      build();\n    };\n\n    const draw = () => {\n      build();\n      const o = opts.current;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, W, H);\n      const cx = W / 2, cy = H / 2;\n      const c = Math.min(R, st.c);\n      const peel = Math.max(0, (R - c) / (R * 2));\n      const Rc = 9 + peel * 40;\n      const px = Math.round(A * dpr);\n      // Relleno holográfico que se desplaza con el cursor y con el despegue.\n      fx.setTransform(1, 0, 0, 1, 0, 0);\n      fx.globalCompositeOperation = \"source-over\"; fx.clearRect(0, 0, px, px);\n      fx.drawImage(art, 0, 0);\n      fx.globalCompositeOperation = \"source-atop\";\n      const u0 = (-0.1 + 0.7 * Math.max(-1, Math.min(1, st.c / R))) * R + (A / 2);\n      const sg = fx.createLinearGradient((u0 - R * 0.7) * dpr, 0, (u0 + R * 0.7) * dpr, px * 0.35);\n      const ga = 0.5 * o.gloss;\n      sg.addColorStop(0, \"rgba(255,255,255,0)\"); sg.addColorStop(0.36, `rgba(160,255,230,${0.16 * ga})`); sg.addColorStop(0.5, `rgba(255,255,255,${0.42 * ga})`); sg.addColorStop(0.64, `rgba(255,170,230,${0.16 * ga})`); sg.addColorStop(1, \"rgba(255,255,255,0)\");\n      fx.fillStyle = sg; fx.fillRect(0, 0, px, px);\n      fx.globalCompositeOperation = \"source-over\";\n\n      ctx.save();\n      ctx.translate(cx, cy);\n      ctx.rotate(theta);\n      const half = A / 2;\n      // Parte pegada: sombra de contacto muy corta.\n      ctx.save();\n      ctx.shadowColor = \"rgba(0,0,0,0.55)\"; ctx.shadowBlur = 8; ctx.shadowOffsetY = 2;\n      const flatW = Math.max(0, c + half);\n      if (flatW > 0.5) ctx.drawImage(front, 0, 0, flatW * dpr, px, -half, -half, flatW, A);\n      ctx.restore();\n\n      if (c < R - 0.6) {\n        const du = 1;\n        const L = [-0.3, 1];\n        const ln = Math.hypot(L[0], L[1]);\n        const Lu = L[0] / ln, Lz = L[1] / ln;\n        type Strip = { x: number; w: number; srcX: number; sw: number; back: boolean; shade: number; spec: number; z: number };\n        const strips: Strip[] = [];\n        for (let u = c; u < R + du; u += du) {\n          const s = u - c;\n          const th = s / Rc;\n          let x: number, z: number, w: number, nu: number, nz: number;\n          if (th <= Math.PI) { x = c + Rc * Math.sin(th); z = Rc * (1 - Math.cos(th)); w = Math.max(0.35, Math.abs(Math.cos(th)) * du); nu = -Math.sin(th); nz = Math.cos(th); }\n          else { x = c - (s - Math.PI * Rc); z = 2 * Rc; w = du; nu = 0; nz = -1; }\n          const isBack = th > Math.PI / 2;\n          if (isBack) { nu = -nu; nz = -nz; }\n          const D = Math.max(0, nu * Lu + nz * Lz);\n          const rr = [-Lu + 2 * (nu * Lu + nz * Lz) * nu, -Lz + 2 * (nu * Lu + nz * Lz) * nz];\n          const spec = Math.pow(Math.max(0, rr[1]), isBack ? 14 : 34);\n          strips.push({ x: isBack && th > Math.PI ? x - du : x, w: isBack && th <= Math.PI ? w : isBack ? du : w, srcX: Math.round((u + half) * dpr), sw: Math.max(1, Math.round(du * dpr)), back: isBack, shade: 1 - (0.5 + 0.5 * D), spec, z });\n        }\n        // Sombra proyectada de la solapa sobre la parte pegada, desenfocada.\n        shx.setTransform(1, 0, 0, 1, 0, 0); shx.clearRect(0, 0, px, px);\n        shx.setTransform(dpr, 0, 0, dpr, 0, 0);\n        shx.fillStyle = \"rgba(0,0,0,0.5)\";\n        for (const t of strips) shx.fillRect(t.x + half - t.z * 0.5 - 1, 0, t.w + 1.5, A);\n        shx.setTransform(1, 0, 0, 1, 0, 0);\n        // Recorta la sombra a una banda de la solapa usando la silueta de la calcomanía.\n        shx.globalCompositeOperation = \"destination-in\"; shx.drawImage(blk, 0, 0); shx.globalCompositeOperation = \"source-over\";\n        ctx.save();\n        ctx.globalCompositeOperation = \"source-over\";\n        if (nativeBlur) {\n          (ctx as CanvasRenderingContext2D & { filter: string }).filter = \"blur(5px)\";\n          ctx.globalAlpha = 0.6;\n          ctx.drawImage(sh, -half + 5, -half + 4, A, A);\n          (ctx as CanvasRenderingContext2D & { filter: string }).filter = \"none\";\n        } else {\n          sx.clearRect(0, 0, smallC.width, smallC.height); sx.drawImage(sh, 0, 0, smallC.width, smallC.height);\n          ctx.globalAlpha = 0.6; ctx.drawImage(smallC, -half + 5, -half + 4, A, A);\n        }\n        ctx.restore();\n        // Mancha de adhesivo limpio donde estaba pegada.\n        ctx.save(); ctx.globalAlpha = 0.018;\n        const cleanW = Math.max(0, half - c);\n        if (cleanW > 0) ctx.drawImage(wht, (c + half) * dpr, 0, cleanW * dpr, px, c, -half, cleanW, A);\n        ctx.restore();\n        // Franjas de la solapa, de abajo hacia arriba.\n        for (const t of strips) {\n          const srcImg = t.back ? back : front;\n          const sw = t.sw, w = t.w + 0.7; // un poco de traslape evita rendijas entre franjas\n          ctx.drawImage(srcImg, t.srcX, 0, sw, px, t.x, -half, w, A);\n          if (t.shade > 0.02) { ctx.globalAlpha = t.shade * (t.back ? 0.55 : 0.75); ctx.drawImage(blk, t.srcX, 0, sw, px, t.x, -half, w, A); }\n          if (t.spec > 0.02) { ctx.globalAlpha = Math.min(1, t.spec * (t.back ? 0.5 : 0.8) * (0.6 + 0.4 * o.gloss)); ctx.drawImage(wht, t.srcX, 0, sw, px, t.x, -half, w, A); }\n          ctx.globalAlpha = 1;\n        }\n      }\n      ctx.restore();\n    };\n\n    const tick = (now: number) => {\n      raf = 0;\n      const dt = Math.min(0.04, (now - (last || now)) / 1000);\n      last = now;\n      time += dt;\n      const o = opts.current;\n      const [dx, dy] = CORNERS[o.corner];\n      const dl = Math.SQRT2;\n      let target = R;\n      if (ptr.inside) {\n        const u = ((ptr.x - W / 2) * dx + (ptr.y - H / 2) * dy) / dl;\n        target = Math.min(R, Math.max(R * (1 - o.maxPeel * 2 * 0.62 - 0.0), u));\n        target = Math.max(target, R - 2 * R * o.maxPeel);\n      } else if (o.autoplay) {\n        const p = (time % 4.6) / 4.6;\n        const k = Math.sin(Math.min(1, p * 1.7) * Math.PI);\n        target = R - R * 0.62 * k * k;\n      }\n      const k = 230, dmp = 17;\n      st.v += ((target - st.c) * k - st.v * dmp) * dt;\n      st.c += st.v * dt;\n      draw();\n      const busy = Math.abs(target - st.c) > 0.05 || Math.abs(st.v) > 0.05 || o.autoplay || ptr.inside;\n      if (visible && busy) raf = requestAnimationFrame(tick); else last = 0;\n    };\n    const wake = () => { if (!raf && visible && !reduce) raf = requestAnimationFrame(tick); };\n    const onMove = (e: PointerEvent) => {\n      const r = cv.getBoundingClientRect();\n      ptr.x = e.clientX - r.left; ptr.y = e.clientY - r.top;\n      ptr.inside = Math.hypot(ptr.x - W / 2, ptr.y - H / 2) < R * 1.08;\n      wake();\n    };\n    const onLeave = () => { ptr.inside = false; wake(); };\n    cv.addEventListener(\"pointermove\", onMove);\n    cv.addEventListener(\"pointerdown\", onMove);\n    cv.addEventListener(\"pointerleave\", onLeave);\n    const ro = new ResizeObserver(() => { built = \"\"; resize(); st.c = st.tc = R * (reduce ? 0.55 : 1); draw(); });\n    ro.observe(cv);\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) wake(); }, { threshold: 0.01 });\n    io.observe(cv);\n    resize();\n    if (reduce) st.c = R * 0.55;\n    draw();\n    wake();\n    // Si la tipografía web llega tarde, se vuelve a dibujar el arte.\n    document.fonts?.ready.then(() => { built = \"\"; draw(); });\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      cv.removeEventListener(\"pointermove\", onMove);\n      cv.removeEventListener(\"pointerdown\", onMove);\n      cv.removeEventListener(\"pointerleave\", onLeave);\n    };\n  }, []);\n\n  return <canvas ref={ref} className={`furin-sticker-peel ${className}`} style={style} role=\"img\" aria-label={`Sticker: ${children}`} />;\n}\n\nexport default StickerPeel;\n",
      "type": "registry:component",
      "target": "components/furin/sticker-peel/StickerPeel.tsx"
    },
    {
      "path": "registry/sticker-peel/StickerPeel.css",
      "content": ".furin-sticker-peel {\n  display: block;\n  width: 100%;\n  height: 100%;\n  min-height: 240px;\n  cursor: pointer;\n  touch-action: pan-y;\n  -webkit-tap-highlight-color: transparent;\n}\n",
      "type": "registry:file",
      "target": "components/furin/sticker-peel/StickerPeel.css"
    }
  ]
}
