{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "ticket-stub",
  "title": "Ticket Stub",
  "author": "Visant Labs <visantsupply@gmail.com>",
  "description": "Confirmar presença destacando o canhoto de um ingresso: arrastar pela picotagem rasga, e soltar antes da metade devolve.",
  "dependencies": [
    "motion"
  ],
  "registryDependencies": [],
  "files": [
    {
      "path": "registry/visant/ui/ticket-stub.tsx",
      "content": "\"use client\";\n\n/*\n * CANHOTO: confirm attendance by tearing the stub off a ticket.\n *\n * Collision: an event identity whose content lives in pieces you keep (tickets,\n * tags, keychains) + the perforated stub of a paper ticket, where the act of\n * tearing IS the commitment. It is a slide-to-confirm with a reason to exist:\n * the stub follows the finger along the perforation, tipping from its bottom\n * corner as it tears from the top; past 55% of its width it comes off and the\n * ticket reads \"confirmado\"; short of it, it springs back into the perforation.\n * One drag. A button underneath, so Enter or Space confirm too, and an undo.\n */\nimport * as React from \"react\";\nimport { animate, motion, useMotionValue, useReducedMotion, useTransform } from \"motion/react\";\n\nconst SNAP = { type: \"spring\", stiffness: 420, damping: 32 } as const;\nconst TEAR = 0.55;\nconst clamp = (v: number, a: number, b: number) => Math.max(a, Math.min(b, v));\n// Two half-circle notches where the perforation meets the edges (alpha-only mask).\nconst notch = (side: \"left\" | \"right\") =>\n  `radial-gradient(circle 8px at ${side === \"right\" ? \"100%\" : \"0\"} 0, transparent 97%, var(--foreground)) top / 100% 51% no-repeat, radial-gradient(circle 8px at ${side === \"right\" ? \"100%\" : \"0\"} 100%, transparent 97%, var(--foreground)) bottom / 100% 51% no-repeat`;\n\nexport function TicketStub() {\n  const reduce = useReducedMotion();\n  const stub = React.useRef<HTMLButtonElement>(null);\n  const [torn, setTorn] = React.useState(false);\n  const x = useMotionValue(0);\n  const w = React.useRef(96);\n  const p = useTransform(x, (v) => clamp(v / w.current, 0, 1));\n  const rotate = useTransform(p, (v) => v * 9);\n  const cue = useTransform(p, [0, 0.4], [1, 0]);\n  const drag = React.useRef<{ x: number; moved: boolean } | null>(null);\n\n  const tear = () => {\n    setTorn(true);\n    if (reduce) x.jump(w.current * 2);\n    else animate(x, w.current * 2.2, { type: \"spring\", stiffness: 260, damping: 30 });\n  };\n  const back = () => (reduce ? x.jump(0) : animate(x, 0, SNAP));\n  const refocus = React.useRef(false);\n  const undo = () => {\n    refocus.current = true;\n    setTorn(false);\n    back();\n  };\n  React.useEffect(() => {\n    if (!torn && refocus.current) stub.current?.focus(); // undo hands focus back to the stub\n    refocus.current = false;\n  }, [torn]);\n\n  const onDown = (e: React.PointerEvent<HTMLButtonElement>) => {\n    if (torn) return;\n    w.current = e.currentTarget.offsetWidth;\n    e.currentTarget.setPointerCapture(e.pointerId);\n    x.stop();\n    drag.current = { x: e.clientX - x.get(), moved: false };\n  };\n  const onMove = (e: React.PointerEvent) => {\n    const d = drag.current;\n    if (!d) return;\n    const dx = clamp(e.clientX - d.x, 0, w.current * 1.2);\n    if (dx > 4) d.moved = true;\n    x.set(dx);\n  };\n  const onUp = () => {\n    const d = drag.current;\n    drag.current = null;\n    if (!d || !d.moved) return;\n    if (p.get() > TEAR) tear();\n    else back();\n  };\n\n  return (\n    <div className=\"flex flex-col gap-4 p-4 sm:p-6\">\n      <div className=\"flex h-36 select-none\">\n        {/* The ticket: what you are confirming, and nothing else. */}\n        <div style={{ mask: notch(\"right\"), WebkitMask: notch(\"right\") }} className=\"flex flex-1 flex-col justify-between rounded-l-tile border border-r-0 border-border bg-background p-4\">\n          <div className=\"flex flex-col gap-1\">\n            <span className=\"[font-family:var(--font-display,inherit)] text-base font-medium leading-tight text-foreground\">Encontro de design</span>\n            <span className=\"font-mono text-[11px] uppercase tracking-[0.08em] text-muted-foreground\">sáb 14 nov · 19h</span>\n          </div>\n          <div className=\"flex items-end justify-between gap-2\">\n            <div className=\"flex items-baseline gap-1.5\">\n              <span className=\"[font-family:var(--font-display,inherit)] text-[2.5rem] font-medium leading-none tracking-[-0.03em] tabular-nums text-foreground\">03</span>\n              <span className=\"[font-family:var(--font-display,inherit)] text-xs text-muted-foreground\">mesa</span>\n            </div>\n            <motion.div\n              initial={false}\n              animate={{ opacity: torn ? 1 : 0, y: torn ? 0 : 4 }}\n              transition={{ duration: reduce ? 0 : 0.24, ease: [0.22, 1, 0.36, 1] }}\n              className=\"flex flex-col items-end gap-1\"\n            >\n              <span className=\"font-mono text-[11px] uppercase tracking-[0.08em] text-foreground\">confirmado</span>\n              <button\n                type=\"button\"\n                tabIndex={torn ? 0 : -1}\n                aria-hidden={!torn}\n                onClick={undo}\n                className=\"[font-family:var(--font-display,inherit)] text-xs text-muted-foreground underline underline-offset-4 outline-none focus-visible:[box-shadow:var(--focus)]\"\n              >\n                desfazer\n              </button>\n            </motion.div>\n          </div>\n        </div>\n        {/* The perforation the stub tears along. */}\n        <div aria-hidden className=\"w-px border-l border-dashed border-border\" />\n        <motion.button\n          ref={stub}\n          type=\"button\"\n          data-lab-target\n          disabled={torn}\n          aria-label=\"Confirmar presença: arraste o canhoto ou pressione Enter\"\n          onClick={(e) => {\n            if (e.detail === 0) tear(); // keyboard: Enter / Space\n          }}\n          onPointerDown={onDown}\n          onPointerMove={onMove}\n          onPointerUp={onUp}\n          onPointerCancel={onUp}\n          style={{ x, rotate, originX: 0, originY: 1, mask: notch(\"left\"), WebkitMask: notch(\"left\") }}\n          className=\"flex w-24 cursor-grab touch-none flex-col items-center justify-between rounded-r-tile border border-l-0 border-border bg-card py-4 outline-none focus-visible:[box-shadow:var(--focus)] active:cursor-grabbing disabled:cursor-default sm:w-28\"\n        >\n          <span className=\"font-mono text-[10px] uppercase tracking-[0.12em] text-muted-foreground\">entrada</span>\n          <span className=\"[font-family:var(--font-display,inherit)] text-base font-medium tabular-nums text-foreground\">0128</span>\n          <motion.span style={{ opacity: cue }} className=\"font-mono text-[10px] uppercase tracking-[0.12em] text-muted-foreground\">\n            rasgue →\n          </motion.span>\n        </motion.button>\n      </div>\n      <span className=\"sr-only\" aria-live=\"polite\">\n        {torn ? \"Presença confirmada. Encontro de design, sábado 14 de novembro às 19h, mesa 03.\" : \"\"}\n      </span>\n    </div>\n  );\n}\n",
      "type": "registry:ui"
    }
  ],
  "meta": {
    "uso": {
      "quando": "Confirmar presença, inscrição ou ingresso com um gesto deliberado",
      "evite": "Confirmação destrutiva: hold-to-confirm; deslizar sem metáfora: slide-to-confirm"
    }
  },
  "categories": [
    "controles",
    "confirmar",
    "ingresso",
    "rasgar",
    "arrastar",
    "evento"
  ],
  "type": "registry:ui"
}