{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"rip-stub","type":"registry:ui","title":"Rip Stub","description":"An event ticket whose perforated stub you pull against rubber-band tension until it rips free and tumbles away, stamping a confirmation onto the ticket.","dependencies":["motion","lucide-react"],"registryDependencies":[],"files":[{"path":"registry/ui/rip-stub.tsx","type":"registry:ui","content":"\"use client\";\n\nimport { useRef, useState, type MouseEvent } from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useTransform, type PanInfo } from \"motion/react\";\nimport { Check } from \"lucide-react\";\n\nexport interface RipStubProps {\n  title?: string;\n  subtitle?: string;\n  date?: string;\n  time?: string;\n  seat?: string;\n  /** Stamped on the ticket once the stub is gone. */\n  confirmation?: string;\n  accent?: string;\n  /** Px the stub must be pulled before it tears on release. */\n  threshold?: number;\n  onTear?: () => void;\n  className?: string;\n}\n\n// Two half-height tiles, each with one round bite, give a ticket its notches.\nconst notch = (side: \"0\" | \"100%\") =>\n  `radial-gradient(circle 11px at ${side} 0, #0000 97%, #000) top / 100% 51% no-repeat, radial-gradient(circle 11px at ${side} 100%, #0000 97%, #000) bottom / 100% 51% no-repeat`;\n\nconst rubber = (d: number, limit: number) => (1 - 1 / ((d * 0.6) / limit + 1)) * limit;\n\nexport function RipStub({\n  title = \"Neon Nights\",\n  subtitle = \"Warehouse 9 · Live set\",\n  date = \"Sat 14 Jun\",\n  time = \"21:00\",\n  seat = \"GA 042\",\n  confirmation = \"You're in!\",\n  accent = \"#fbbf24\",\n  threshold = 90,\n  onTear,\n  className,\n}: RipStubProps) {\n  const reduce = useReducedMotion();\n  const [torn, setTorn] = useState(false);\n  const moved = useRef(false);\n  const x = useMotionValue(0);\n  const y = useMotionValue(0);\n  const spin = useMotionValue(0);\n  const fade = useMotionValue(1);\n  const recoil = useMotionValue(0);\n  // Hinged at the bottom corner: the harder you pull, the more the top peels away.\n  const pull = useRef(0);\n  const limit = threshold * 2;\n  const atThreshold = rubber(threshold, limit);\n  // 0..1: how close the pull is to tearing.\n  const strain = useTransform(() => Math.min(Math.hypot(x.get(), y.get()) / atThreshold, 1.2));\n  const rotate = useTransform(() => strain.get() * 9 + spin.get());\n  const lean = useTransform(() => x.get() * 0.06 + recoil.get());\n  const seam = useTransform(strain, [0, 1], [\"rgba(0,0,0,0.3)\", \"rgba(0,0,0,0.85)\"]);\n\n  const tear = () => {\n    if (torn) return;\n    setTorn(true);\n    onTear?.();\n    if (reduce) return fade.set(0);\n    const fall = { duration: 0.75, ease: [0.45, 0, 0.9, 0.6] as const };\n    animate(y, y.get() + 340, fall);\n    animate(x, x.get() + 90, { duration: 0.75, ease: \"easeOut\" });\n    animate(spin, 38, fall);\n    animate(fade, 0, { duration: 0.3, delay: 0.45 });\n    animate(recoil, [0, -9, 4, 0], { duration: 0.5, ease: \"easeOut\" });\n  };\n\n  const onPan = (_: unknown, info: PanInfo) => {\n    if (torn) return;\n    moved.current = true; // swallow the click that ends a drag\n    const { x: ox, y: oy } = info.offset;\n    const d = Math.hypot(ox, oy) || 1;\n    pull.current = d;\n    const k = rubber(d, limit) / d;\n    x.set(ox * k);\n    y.set(oy * k);\n  };\n\n  const onPanEnd = () => {\n    if (torn) return;\n    if (pull.current >= threshold) return tear();\n    const back = reduce ? { duration: 0 } : ({ type: \"spring\", stiffness: 600, damping: 14 } as const);\n    animate(x, 0, back);\n    animate(y, 0, back);\n  };\n\n  const onClick = (e: MouseEvent<HTMLButtonElement>) => {\n    if (moved.current) return;\n    if (e.detail === 0) return tear(); // keyboard: Enter / Space\n    if (!reduce) animate(x, [0, 16, -5, 0], { duration: 0.45 }); // a tug that hints \"drag me\"\n  };\n\n  return (\n    <div className={`relative flex h-36 w-[22rem] max-w-full select-none ${className ?? \"\"}`}>\n      <motion.div className=\"relative min-w-0 flex-1 drop-shadow-xl\" style={{ x: lean }}>\n        <div className=\"flex h-full flex-col justify-between bg-card p-5\" style={{ mask: notch(\"100%\") }}>\n          <motion.div animate={{ opacity: torn ? 0.25 : 1 }} transition={{ duration: 0.3 }}>\n            <p className=\"text-[10px] font-semibold tracking-[0.2em] uppercase\" style={{ color: accent }}>\n              Admit one\n            </p>\n            <p className=\"mt-1 text-xl font-bold tracking-tight text-foreground\">{title}</p>\n            <p className=\"text-xs text-muted-foreground\">{subtitle}</p>\n          </motion.div>\n          <motion.dl\n            className=\"flex gap-5 text-xs\"\n            animate={{ opacity: torn ? 0.25 : 1 }}\n            transition={{ duration: 0.3 }}\n          >\n            {[\n              [\"Date\", date],\n              [\"Doors\", time],\n              [\"Seat\", seat],\n            ].map(([k, v]) => (\n              <div key={k}>\n                <dt className=\"text-muted-foreground\">{k}</dt>\n                <dd className=\"font-medium text-foreground\">{v}</dd>\n              </div>\n            ))}\n          </motion.dl>\n        </div>\n        <div role=\"status\" className=\"pointer-events-none absolute inset-0 grid place-items-center\">\n          {torn && (\n            <motion.div\n              initial={reduce ? false : { scale: 2.4, opacity: 0, rotate: -24 }}\n              animate={{ scale: 1, opacity: 1, rotate: -8 }}\n              transition={{ type: \"spring\", stiffness: 520, damping: 14, delay: 0.15 }}\n              className=\"flex items-center gap-2 rounded-lg border-[3px] px-4 py-2 text-lg font-black tracking-wide uppercase\"\n              style={{ borderColor: accent, color: accent }}\n            >\n              <Check className=\"size-5\" strokeWidth={3.5} />\n              {confirmation}\n            </motion.div>\n          )}\n        </div>\n      </motion.div>\n\n      <motion.div\n        className=\"relative w-24 shrink-0 rounded-md drop-shadow-xl has-[:focus-visible]:outline-2 has-[:focus-visible]:outline-offset-4 has-[:focus-visible]:outline-ring\" style={{ x, y, rotate, opacity: fade, transformOrigin: \"0% 100%\" }}>\n        <motion.button\n          type=\"button\"\n          disabled={torn}\n          aria-label={`Tear off the stub to check in (${seat})`}\n          onPointerDown={() => {\n            moved.current = false;\n            pull.current = 0;\n          }}\n          onPan={onPan}\n          onPanEnd={onPanEnd}\n          onClick={onClick}\n          style={{ mask: notch(\"0\"), background: accent, touchAction: \"none\" }}\n          className=\"flex size-full cursor-grab flex-col items-center justify-between py-4 text-black/80 outline-none active:cursor-grabbing\"\n        >\n          <span className=\"text-[10px] font-bold tracking-[0.2em] uppercase\">Stub</span>\n          <span className=\"text-sm font-black [writing-mode:vertical-rl]\">{seat}</span>\n          <span aria-hidden className=\"h-5 w-14 bg-[repeating-linear-gradient(90deg,currentColor_0_2px,transparent_2px_4px,currentColor_4px_5px,transparent_5px_8px)] opacity-70\" />\n        </motion.button>\n        {/* Perforation: darkens as the tear strains. */}\n        <motion.span\n          aria-hidden\n          className=\"pointer-events-none absolute inset-y-3 left-0 border-l-2 border-dashed\"\n          style={{ borderColor: seam }}\n        />\n      </motion.div>\n    </div>\n  );\n}\n"}]}