{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ticket-tear",
  "type": "registry:component",
  "title": "Ticket Tear",
  "description": "A paper ticket with a perforation: drag the stub and it tears from top to bottom, with a fibrous edge and a shadow that grows as it peels away.",
  "author": "Marcelo Treviño Velázquez <https://furin.dev>",
  "dependencies": [],
  "categories": [
    "Cards"
  ],
  "docs": "Installed in components/furin/ticket-tear/. Docs, live controls and props table: https://furin.dev/components/ticket-tear/",
  "files": [
    {
      "path": "registry/ticket-tear/TicketTear.tsx",
      "content": "\"use client\";\nimport { useEffect, useMemo, useRef } from \"react\";\nimport type { CSSProperties } from \"react\";\nimport \"./TicketTear.css\";\n\nexport interface TicketTearProps {\n  /** Título grande del boleto. */\n  title?: string;\n  /** Fecha y hora, bajo el título. */\n  subtitle?: string;\n  /** Lugar del evento. */\n  place?: string;\n  /** Sección, fila y asiento (datos ficticios). */\n  seat?: { section: string; row: string; seat: string };\n  /** Rótulo del campo de sección. */\n  sectionLabel?: string;\n  /** Rótulo del campo de fila. */\n  rowLabel?: string;\n  /** Rótulo del campo de asiento. */\n  seatLabel?: string;\n  /** Texto vertical impreso en el talón. */\n  stubLabel?: string;\n  /** Color de acento del boleto y del talón. */\n  accent?: string;\n  /** Color del papel. */\n  paperColor?: string;\n  /** Escala de todo el boleto. */\n  scale?: number;\n  /** Cuando el talón se arranca, el boleto se rehace solo tras unos segundos. */\n  autoReset?: boolean;\n  /** Clase extra para el contenedor. */\n  className?: string;\n  /** Estilos extra para el contenedor. */\n  style?: CSSProperties;\n}\n\nconst W = 390, H = 160, WS = 96, XB = W - WS, RN = 9, RC = 12, RH = 2.5, PITCH = 9.5;\n\n// Borde rasgado fijo (semilla), para que el rasgado sea igual en cada render.\nconst JAG = (() => {\n  let s = 11;\n  const r = () => ((s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff);\n  const out: number[] = [];\n  let drift = 0;\n  for (let i = 0; i < Math.ceil(H / 1.6) + 2; i++) {\n    drift += (r() - 0.5) * 1.8; drift *= 0.9;\n    out.push(drift + (r() - 0.5) * 2.2 + (r() < 0.06 ? (r() - 0.5) * 6 : 0));\n  }\n  return out;\n})();\nconst jag = (y: number) => JAG[Math.min(JAG.length - 1, Math.max(0, Math.round(y / 1.6)))];\nconst f = (n: number) => n.toFixed(2);\nconst torn = (y0: number, y1: number): [number, number][] => {\n  const pts: [number, number][] = [];\n  for (let y = y0; y <= y1; y += 1.6) pts.push([XB + jag(y) * Math.min(1, (y - y0 + 6) / 6, (y1 - y + 6) / 6 + 0.35), y]);\n  return pts;\n};\nconst holes = (yF: number) => {\n  const hs: number[] = [];\n  for (let y = RN + 7; y < H - RN - 2; y += PITCH) if (y - RH >= yF) hs.push(y);\n  return hs;\n};\n\nfunction paths(yF: number) {\n  const tp = torn(RN, yF);\n  const hs = holes(yF);\n  const tornD = tp.map((p) => `L${f(p[0])} ${f(p[1])}`).join(\"\");\n  // Perforación: mordidas semicirculares a cada lado de la línea.\n  const down = hs.map((y) => `L${XB} ${f(y - RH)}A${RH} ${RH} 0 0 0 ${XB} ${f(y + RH)}`).join(\"\");\n  const up = [...hs].reverse().map((y) => `L${XB} ${f(y + RH)}A${RH} ${RH} 0 0 0 ${XB} ${f(y - RH)}`).join(\"\");\n  const main = `M0 ${RC}A${RC} ${RC} 0 0 1 ${RC} 0L${XB - RN} 0A${RN} ${RN} 0 0 0 ${XB} ${RN}${tornD}L${XB} ${f(Math.max(yF, RN))}${down}L${XB} ${H - RN}A${RN} ${RN} 0 0 0 ${XB - RN} ${H}L${RC} ${H}A${RC} ${RC} 0 0 1 0 ${H - RC}Z`;\n  const upper = `M${XB} ${RN}A${RN} ${RN} 0 0 0 ${XB + RN} 0L${W - RC} 0A${RC} ${RC} 0 0 1 ${W} ${RC}L${W} ${f(yF)}L${XB} ${f(yF)}${[...tp].reverse().map((p) => `L${f(p[0])} ${f(p[1])}`).join(\"\")}Z`;\n  const lower = `M${XB} ${f(yF)}L${W} ${f(yF)}L${W} ${H - RC}A${RC} ${RC} 0 0 1 ${W - RC} ${H}L${XB + RN} ${H}A${RN} ${RN} 0 0 0 ${XB} ${H - RN}${up}Z`;\n  const fiber = tp.map((p, i) => `${i ? \"L\" : \"M\"}${f(p[0])} ${f(p[1])}`).join(\"\");\n  return { main, upper, lower, fiber, tp };\n}\n\nconst BARS = (() => {\n  let s = 5;\n  const r = () => ((s = (s * 1103515245 + 12345) & 0x7fffffff) / 0x7fffffff);\n  const out: { y: number; h: number }[] = [];\n  for (let y = 0; y < 62; ) { const h = 1 + Math.floor(r() * 3); out.push({ y, h }); y += h + 1 + Math.floor(r() * 2); }\n  return out;\n})();\n\n/** Boleto de papel con perforación: arrastra el talón y se rasga de arriba abajo, con borde de fibras y sombra real. */\nexport function TicketTear({\n  title = \"Furin Live\",\n  subtitle = \"Saturday, October 3 · 8:00 PM\",\n  place = \"North Forum · Mexico City\",\n  seat = { section: \"A\", row: \"12\", seat: \"08\" },\n  sectionLabel = \"Section\",\n  rowLabel = \"Row\",\n  seatLabel = \"Seat\",\n  stubLabel = \"STUB · 0482\",\n  accent = \"#ff5a36\",\n  paperColor = \"#f5f0e5\",\n  scale = 1,\n  autoReset = true,\n  className = \"\",\n  style,\n}: TicketTearProps) {\n  const root = useRef<HTMLDivElement>(null);\n  const opts = useRef({ autoReset });\n  opts.current = { autoReset };\n  const kick = useRef<() => void>(() => {});\n  const init = useMemo(() => paths(RN), []);\n\n  useEffect(() => {\n    const el = root.current;\n    if (!el) return;\n    const stage = el.querySelector<HTMLElement>(\".furin-ticket__stage\")!;\n    const main = el.querySelector<HTMLElement>(\".furin-ticket__main\")!;\n    const upper = el.querySelector<HTMLElement>(\".furin-ticket__upper\")!;\n    const lower = el.querySelector<HTMLElement>(\".furin-ticket__lower\")!;\n    const upperWrap = el.querySelector<HTMLElement>(\".furin-ticket__upper-wrap\")!;\n    const lowerWrap = el.querySelector<HTMLElement>(\".furin-ticket__lower-wrap\")!;\n    const hit = el.querySelector<HTMLElement>(\".furin-ticket__hit\")!;\n    const fibers = Array.from(el.querySelectorAll<SVGPathElement>(\".furin-ticket__fiber\"));\n    const reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n    type Mode = \"idle\" | \"drag\" | \"hold\" | \"finish\" | \"fall\" | \"gone\" | \"mend\" | \"nudge\";\n    let mode: Mode = \"idle\";\n    let t = 0, modeAt = 0, raf = 0, visible = true, last = 0;\n    let grabX = 0, grabT = 0, vel = 0, lastX = 0, lastTime = 0, sc = 1;\n    const fall = { x: 0, y: 0, vx: 0, vy: 0, r: 0, vr: 0, o: 1 };\n    let touched = false, hintTimer = 0;\n\n    const ease = (x: number) => x * x * (3 - 2 * x);\n    const apply = () => {\n      const yF = RN + (H - RN) * t;\n      const p = paths(yF);\n      main.style.clipPath = `path('${p.main}')`;\n      upper.style.clipPath = `path('${p.upper}')`;\n      lower.style.clipPath = `path('${p.lower}')`;\n      for (const fb of fibers) fb.setAttribute(\"d\", p.fiber);\n      const phi = 64 * Math.pow(Math.min(1, t * 1.15), 0.7);\n      upperWrap.style.transformOrigin = `${XB}px ${yF}px`;\n      upperWrap.style.transform = `translate(${fall.x}px, ${fall.y}px) rotate(${phi + fall.r}deg)`;\n      upperWrap.style.opacity = String(fall.o);\n      const lift = Math.min(1, t * 2);\n      upperWrap.style.filter = `drop-shadow(${(2 + lift * 7).toFixed(1)}px ${(3 + lift * 9).toFixed(1)}px ${(5 + lift * 10).toFixed(1)}px rgba(0,0,0,${(0.3 + lift * 0.22).toFixed(2)}))`;\n      lowerWrap.style.opacity = t >= 0.995 ? \"0\" : String(fall.o);\n      hit.style.pointerEvents = mode === \"gone\" || mode === \"fall\" ? \"none\" : \"auto\";\n      hit.style.cursor = mode === \"drag\" ? \"grabbing\" : \"grab\";\n    };\n\n    const setMode = (m: Mode, now: number) => { mode = m; modeAt = now; };\n    const reset = () => { t = 0; fall.x = fall.y = fall.r = fall.vx = fall.vy = fall.vr = 0; fall.o = 0; apply(); };\n    const scheduleHint = () => {\n      window.clearTimeout(hintTimer);\n      if (reduce) return;\n      hintTimer = window.setTimeout(() => { if (mode === \"idle\" && visible && !touched) { setMode(\"nudge\", performance.now()); wake(); } scheduleHint(); }, 3600);\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      const el_ = now - modeAt;\n      let busy = true;\n      if (mode === \"nudge\") {\n        const k = el_ / 900;\n        t = k >= 1 ? 0 : 0.2 * Math.sin(k * Math.PI) ** 2 * (1 - 0.2 * k);\n        if (k >= 1) { t = 0; mode = \"idle\"; busy = false; }\n      } else if (mode === \"finish\") {\n        t += (1 - t) * Math.min(1, dt * 14) + dt * 0.5;\n        if (t >= 1) {\n          t = 1;\n          fall.vx = 120 + Math.max(0, vel) * 260; fall.vy = -60; fall.vr = 90 + vel * 120;\n          setMode(\"fall\", now);\n        }\n      } else if (mode === \"fall\") {\n        fall.vy += 1500 * dt; fall.x += fall.vx * dt; fall.y += fall.vy * dt; fall.r += fall.vr * dt;\n        fall.o = Math.max(0, 1 - Math.max(0, el_ - 450) / 450);\n        if (el_ > 900) { fall.o = 0; setMode(\"gone\", now); }\n      } else if (mode === \"gone\") {\n        if (opts.current.autoReset && el_ > 2200) { reset(); setMode(\"mend\", now); }\n        else busy = el_ < 2400 || opts.current.autoReset;\n      } else if (mode === \"hold\") {\n        if (opts.current.autoReset && el_ > 3200) setMode(\"mend\", now);\n        else busy = opts.current.autoReset;\n      } else if (mode === \"mend\") {\n        if (fall.o < 1 && t === 0) fall.o = Math.min(1, fall.o + dt * 3);\n        t = Math.max(0, t - dt * 1.4 * (0.4 + t));\n        if (t <= 0.001 && fall.o >= 1) { t = 0; fall.o = 1; setMode(\"idle\", now); busy = false; }\n      } else busy = false;\n      apply();\n      if (busy && visible) raf = requestAnimationFrame(tick); else last = 0;\n    };\n    const wake = () => { if (!raf && visible) raf = requestAnimationFrame(tick); };\n    fall.o = 1;\n    apply();\n    scheduleHint();\n\n    const onDown = (e: PointerEvent) => {\n      if (mode === \"gone\" || mode === \"fall\" || mode === \"finish\") return;\n      touched = true;\n      sc = stage.getBoundingClientRect().width / W || 1;\n      grabX = e.clientX; grabT = t; lastX = e.clientX; lastTime = performance.now(); vel = 0;\n      hit.setPointerCapture(e.pointerId);\n      setMode(\"drag\", performance.now());\n      wake();\n    };\n    const onMove = (e: PointerEvent) => {\n      if (mode !== \"drag\") return;\n      const now = performance.now();\n      vel = (e.clientX - lastX) / Math.max(1, now - lastTime);\n      lastX = e.clientX; lastTime = now;\n      // El rasgado avanza con el arrastre hacia afuera; contra el papel, no cede.\n      t = Math.max(0, Math.min(1, grabT + (e.clientX - grabX) / sc / 112));\n      wake();\n    };\n    const onUp = () => {\n      if (mode !== \"drag\") return;\n      const now = performance.now();\n      if (t > 0.72 || (t > 0.45 && vel > 0.6)) setMode(\"finish\", now);\n      else { t *= 0.94; setMode(t < 0.03 ? \"idle\" : \"hold\", now); }\n      wake();\n    };\n    hit.addEventListener(\"pointerdown\", onDown);\n    hit.addEventListener(\"pointermove\", onMove);\n    hit.addEventListener(\"pointerup\", onUp);\n    hit.addEventListener(\"pointercancel\", onUp);\n    kick.current = () => { if (mode === \"idle\" || mode === \"hold\") { touched = true; setMode(\"finish\", performance.now()); wake(); } };\n    const io = new IntersectionObserver(([en]) => { visible = en.isIntersecting; if (visible) wake(); }, { threshold: 0.05 });\n    io.observe(el);\n    if (reduce) { t = 0.34; apply(); }\n    return () => {\n      cancelAnimationFrame(raf);\n      window.clearTimeout(hintTimer);\n      io.disconnect();\n      hit.removeEventListener(\"pointerdown\", onDown);\n      hit.removeEventListener(\"pointermove\", onMove);\n      hit.removeEventListener(\"pointerup\", onUp);\n      hit.removeEventListener(\"pointercancel\", onUp);\n    };\n  }, []);\n\n  const vars = { \"--tt-accent\": accent, \"--tt-paper\": paperColor, \"--tt-w\": `${W}px`, \"--tt-h\": `${H}px`, \"--tt-s\": scale } as CSSProperties;\n  const art = (\n    <div className=\"furin-ticket__art\">\n      <div className=\"furin-ticket__main-art\">\n        <div className=\"furin-ticket__bar\" />\n        <div className=\"furin-ticket__top\"><span>ADMIT ONE</span><span>No. 004218</span></div>\n        <h3 className=\"furin-ticket__title\">{title}</h3>\n        <p className=\"furin-ticket__sub\">{subtitle}</p>\n        <p className=\"furin-ticket__place\">{place}</p>\n        <div className=\"furin-ticket__fields\">\n          <div><i>{sectionLabel}</i><b>{seat.section}</b></div>\n          <div><i>{rowLabel}</i><b>{seat.row}</b></div>\n          <div><i>{seatLabel}</i><b>{seat.seat}</b></div>\n        </div>\n      </div>\n      <div className=\"furin-ticket__stub-art\">\n        <span className=\"furin-ticket__vert\">{stubLabel}</span>\n        <svg viewBox=\"0 0 38 62\" className=\"furin-ticket__code\" aria-hidden>\n          {BARS.map((b, i) => <rect key={i} x=\"0\" y={b.y} width=\"38\" height={b.h} />)}\n        </svg>\n      </div>\n      <div className=\"furin-ticket__light\" />\n      <div className=\"furin-ticket__grain\" />\n    </div>\n  );\n  const fiberSvg = (cls: string, dx: number) => (\n    <svg className={`furin-ticket__fibers ${cls}`} viewBox={`0 0 ${W} ${H}`} aria-hidden>\n      <path className=\"furin-ticket__fiber\" d={init.fiber} transform={`translate(${dx} 0)`} />\n    </svg>\n  );\n  return (\n    <div\n      ref={root}\n      className={`furin-ticket ${className}`}\n      style={{ ...vars, ...style }}\n      role=\"img\"\n      aria-label={`Ticket for ${title}. Drag the stub to tear it.`}\n      tabIndex={0}\n      onKeyDown={(e) => { if (e.key === \"Enter\" || e.key === \" \") { e.preventDefault(); kick.current(); } }}\n    >\n      <div className=\"furin-ticket__stage\">\n        <div className=\"furin-ticket__lower-wrap\"><div className=\"furin-ticket__piece furin-ticket__lower\" style={{ clipPath: `path('${init.lower}')` }}>{art}</div></div>\n        <div className=\"furin-ticket__main-wrap\">\n          <div className=\"furin-ticket__piece furin-ticket__main\" style={{ clipPath: `path('${init.main}')` }}>{art}</div>\n          {fiberSvg(\"furin-ticket__fibers--main\", -1.6)}\n        </div>\n        <div className=\"furin-ticket__upper-wrap\">\n          <div className=\"furin-ticket__piece furin-ticket__upper\" style={{ clipPath: `path('${init.upper}')` }}>{art}{fiberSvg(\"furin-ticket__fibers--up\", 1.6)}</div>\n        </div>\n        <div className=\"furin-ticket__hit\" />\n      </div>\n    </div>\n  );\n}\n\nexport default TicketTear;\n",
      "type": "registry:component",
      "target": "components/furin/ticket-tear/TicketTear.tsx"
    },
    {
      "path": "registry/ticket-tear/TicketTear.css",
      "content": ".furin-ticket {\n  --tt-accent: #ff5a36; --tt-paper: #f5f0e5; --tt-s: 1;\n  --tt-grain: url(\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='200' height='200'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .35 0 0 0 0 .3 0 0 0 0 .22 0 0 0 .65 0'/%3E%3C/filter%3E%3Crect width='200' height='200' filter='url(%23n)'/%3E%3C/svg%3E\");\n  position: relative;\n  width: 100%;\n  height: 100%;\n  min-height: 260px;\n  display: grid;\n  place-items: center;\n  outline: none;\n  user-select: none;\n  -webkit-user-select: none;\n}\n.furin-ticket__stage { position: relative; width: var(--tt-w); height: var(--tt-h); transform: scale(var(--tt-s)) rotate(-2.5deg); }\n.furin-ticket__stage > div { position: absolute; inset: 0; }\n.furin-ticket__lower-wrap, .furin-ticket__main-wrap { filter: drop-shadow(0 1px 1px rgba(0, 0, 0, 0.45)) drop-shadow(0 12px 16px rgba(0, 0, 0, 0.4)); }\n.furin-ticket__piece { position: absolute; inset: 0; }\n.furin-ticket__fibers { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; overflow: visible; }\n.furin-ticket__fiber { fill: none; stroke: #fffdf6; stroke-width: 2.2; stroke-linejoin: round; stroke-linecap: round; opacity: 0.95; }\n/* Zona del talón que se agarra. */\n.furin-ticket__hit { left: calc(var(--tt-w) - 96px) !important; width: 96px; z-index: 5; touch-action: none; }\n\n/* Arte del boleto (se pinta tres veces, recortado por cada pedazo). */\n.furin-ticket__art { position: absolute; inset: 0; color: #1a130d; font-family: Geist, \"Inter\", system-ui, sans-serif; background: var(--tt-paper); overflow: hidden; }\n.furin-ticket__main-art { position: absolute; left: 0; top: 0; bottom: 0; width: 294px; padding: 15px 18px 14px 28px; box-sizing: border-box; display: flex; flex-direction: column; }\n.furin-ticket__bar { position: absolute; left: 0; top: 0; bottom: 0; width: 12px; background: var(--tt-accent); }\n.furin-ticket__bar::after { content: \"\"; position: absolute; inset: 0; background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.12) 0 2px, transparent 2px 8px); }\n.furin-ticket__top { display: flex; justify-content: space-between; font: 600 9px/1 \"JetBrains Mono\", ui-monospace, monospace; letter-spacing: 0.2em; color: rgba(26, 19, 13, 0.55); }\n.furin-ticket__title { margin: 12px 0 0; font-weight: 800; font-size: 34px; line-height: 0.95; letter-spacing: -0.035em; }\n.furin-ticket__sub { margin: 8px 0 0; font-size: 12.5px; font-weight: 600; }\n.furin-ticket__place { margin: 2px 0 0; font-size: 11px; color: rgba(26, 19, 13, 0.6); }\n.furin-ticket__fields { margin-top: auto; display: flex; gap: 0; border-top: 1.5px solid rgba(26, 19, 13, 0.85); padding-top: 7px; }\n.furin-ticket__fields div { flex: 1; display: grid; gap: 2px; }\n.furin-ticket__fields div + div { padding-left: 12px; border-left: 1px solid rgba(26, 19, 13, 0.18); }\n.furin-ticket__fields i { font: 600 8px/1 \"JetBrains Mono\", ui-monospace, monospace; letter-spacing: 0.18em; text-transform: uppercase; font-style: normal; color: rgba(26, 19, 13, 0.5); }\n.furin-ticket__fields b { font-size: 19px; font-weight: 750; letter-spacing: -0.02em; line-height: 1; }\n.furin-ticket__stub-art { position: absolute; right: 0; top: 0; bottom: 0; width: 96px; background: var(--tt-accent); color: #fff; display: grid; place-items: center; }\n.furin-ticket__stub-art::before { content: \"\"; position: absolute; inset: 0; background: linear-gradient(180deg, rgba(255, 255, 255, 0.16), rgba(0, 0, 0, 0.14)); }\n.furin-ticket__vert { position: absolute; left: 12px; top: 50%; transform: translate(-50%, -50%) rotate(-90deg); white-space: nowrap; font: 700 9px/1 \"JetBrains Mono\", ui-monospace, monospace; letter-spacing: 0.24em; opacity: 0.92; }\n.furin-ticket__code { position: relative; width: 38px; height: 62px; margin-left: 12px; fill: #fff; opacity: 0.95; }\n.furin-ticket__light { position: absolute; inset: 0; background: linear-gradient(115deg, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 38%, rgba(0, 0, 0, 0.07) 100%); mix-blend-mode: soft-light; pointer-events: none; }\n.furin-ticket__grain { position: absolute; inset: 0; background: var(--tt-grain) 0 0 / 200px 200px; mix-blend-mode: multiply; opacity: 0.55; pointer-events: none; }\n.furin-ticket:focus-visible .furin-ticket__stage { outline: 2px solid rgba(255, 255, 255, 0.45); outline-offset: 10px; border-radius: 8px; }\n",
      "type": "registry:file",
      "target": "components/furin/ticket-tear/TicketTear.css"
    }
  ]
}
