{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "button-hold-shred",
  "type": "registry:component",
  "title": "Button Hold Shred",
  "description": "Press and hold to feed the label into a shredder slot while paper strips grow out of the bottom edge. Letting go early pulls the label back; finishing drops the strips and confirms.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "buttons",
    "button",
    "hold",
    "delete",
    "shredder",
    "destructive",
    "confirm"
  ],
  "docs": "https://hyperblur.dev/effects/button-hold-shred",
  "files": [
    {
      "path": "registry/hyperblur/button-hold-shred.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/button-hold-shred.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface ButtonHoldShredProps\n  extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, \"children\" | \"onClick\" | \"color\"> {\n  children?: React.ReactNode;\n  doneLabel?: React.ReactNode;\n  duration?: number;\n  accent?: string;\n  size?: \"sm\" | \"md\" | \"lg\";\n  strips?: number;\n  resetAfter?: number;\n  onConfirm?: () => void;\n}\n\nconst css = `\n.hb-xd1 {\n  --hb-xd1-h: 2.75rem;\n  --hb-xd1-fs: 0.875rem;\n  --hb-xd1-p: 0;\n  position: relative;\n  display: inline-flex;\n  flex-direction: column;\n  align-items: stretch;\n  box-sizing: border-box;\n  font-family: inherit;\n  font-size: var(--hb-xd1-fs);\n  isolation: isolate;\n}\n.hb-xd1 *, .hb-xd1 *::before, .hb-xd1 *::after { box-sizing: border-box; }\n.hb-xd1[data-size=\"sm\"] { --hb-xd1-h: 2.25rem; --hb-xd1-fs: 0.8125rem; }\n.hb-xd1[data-size=\"lg\"] { --hb-xd1-h: 3.25rem; --hb-xd1-fs: 1rem; }\n.hb-xd1-btn {\n  position: relative;\n  z-index: 2;\n  display: grid;\n  place-items: center;\n  height: var(--hb-xd1-h);\n  margin: 0;\n  padding: 0 1.25em;\n  overflow: hidden;\n  font: inherit;\n  font-weight: 600;\n  letter-spacing: -0.005em;\n  color: #ffd9db;\n  white-space: nowrap;\n  background:\n    linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0) 55%),\n    linear-gradient(180deg, color-mix(in srgb, var(--hb-xd1-c) 22%, #160a0b), color-mix(in srgb, var(--hb-xd1-c) 10%, #0d0607));\n  border: 1px solid color-mix(in srgb, var(--hb-xd1-c) 38%, #2a1516);\n  border-radius: 12px;\n  box-shadow: inset 0 1px 0 rgba(255,255,255,0.07), 0 1px 2px rgba(0,0,0,0.5), 0 8px 24px -12px color-mix(in srgb, var(--hb-xd1-c) 60%, transparent);\n  cursor: pointer;\n  user-select: none;\n  -webkit-user-select: none;\n  -webkit-touch-callout: none;\n  -webkit-tap-highlight-color: transparent;\n  touch-action: none;\n  transition: transform 0.25s cubic-bezier(0.3, 1.5, 0.5, 1), border-color 0.25s ease, box-shadow 0.25s ease;\n}\n.hb-xd1-btn:hover:not(:disabled) { border-color: color-mix(in srgb, var(--hb-xd1-c) 60%, #2a1516); }\n.hb-xd1-btn:focus-visible { outline: 2px solid var(--hb-xd1-c); outline-offset: 3px; }\n.hb-xd1-btn:disabled { opacity: 0.45; cursor: not-allowed; }\n.hb-xd1[data-phase=\"holding\"] .hb-xd1-btn { animation: hb-xd1-buzz 0.09s steps(2, end) infinite; }\n.hb-xd1-heat {\n  position: absolute;\n  inset: 0;\n  z-index: -1;\n  background: linear-gradient(0deg, color-mix(in srgb, var(--hb-xd1-c) 75%, transparent), color-mix(in srgb, var(--hb-xd1-c) 18%, transparent));\n  transform: scaleY(var(--hb-xd1-p));\n  transform-origin: bottom;\n}\n.hb-xd1-face {\n  grid-area: 1 / 1;\n  display: inline-flex;\n  align-items: center;\n  gap: 0.55em;\n  transform: translateY(calc(var(--hb-xd1-p) * 115%));\n}\n.hb-xd1[data-phase=\"done\"] .hb-xd1-face { opacity: 0; }\n.hb-xd1-done {\n  grid-area: 1 / 1;\n  display: inline-flex;\n  align-items: center;\n  gap: 0.5em;\n  color: #fff;\n  opacity: 0;\n  transform: translateY(-110%);\n  transition: opacity 0.2s ease, transform 0.45s cubic-bezier(0.2, 1.2, 0.4, 1);\n}\n.hb-xd1[data-phase=\"done\"] .hb-xd1-done { opacity: 1; transform: none; }\n.hb-xd1[data-phase=\"done\"] .hb-xd1-btn { border-color: var(--hb-xd1-c); background: linear-gradient(180deg, color-mix(in srgb, var(--hb-xd1-c) 92%, #fff), var(--hb-xd1-c)); }\n.hb-xd1-slot {\n  position: absolute;\n  left: 10px;\n  right: 10px;\n  bottom: 0;\n  height: 2px;\n  border-radius: 2px;\n  background: linear-gradient(90deg, transparent, rgba(0,0,0,0.85) 12%, rgba(0,0,0,0.85) 88%, transparent);\n  box-shadow: 0 -1px 0 color-mix(in srgb, var(--hb-xd1-c) 50%, transparent);\n}\n.hb-xd1-strips {\n  position: absolute;\n  z-index: 1;\n  top: calc(100% - 2px);\n  left: 14px;\n  right: 14px;\n  display: flex;\n  justify-content: space-between;\n  pointer-events: none;\n}\n.hb-xd1-strip {\n  width: 4px;\n  height: calc(var(--hb-xd1-p) * var(--hb-xd1-len));\n  border-radius: 0 0 1px 1px;\n  background:\n    repeating-linear-gradient(180deg, rgba(0,0,0,0.25) 0 1px, transparent 1px 4px),\n    linear-gradient(180deg, #f3e9e9, #cdbfc0);\n  box-shadow: 0 1px 2px rgba(0,0,0,0.4);\n  transform-origin: top center;\n}\n.hb-xd1-strip:nth-child(odd) { background: repeating-linear-gradient(180deg, rgba(0,0,0,0.28) 0 1px, transparent 1px 3px), linear-gradient(180deg, #ebe1e1, #c3b5b6); }\n.hb-xd1[data-phase=\"done\"] .hb-xd1-strip {\n  height: var(--hb-xd1-len);\n  animation: hb-xd1-fall 0.85s cubic-bezier(0.55, 0, 0.8, 0.4) var(--hb-xd1-d) forwards;\n}\n.hb-xd1-sr {\n  position: absolute;\n  width: 1px;\n  height: 1px;\n  overflow: hidden;\n  clip-path: inset(50%);\n  white-space: nowrap;\n}\n@keyframes hb-xd1-buzz {\n  0% { transform: translate(0.4px, 0); }\n  100% { transform: translate(-0.4px, 0.3px); }\n}\n@keyframes hb-xd1-fall {\n  0% { transform: translateY(0) rotate(0); opacity: 1; }\n  100% { transform: translateY(26px) rotate(var(--hb-xd1-r)); opacity: 0; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-xd1-btn, .hb-xd1-done { transition: none; }\n  .hb-xd1[data-phase=\"holding\"] .hb-xd1-btn { animation: none; }\n  .hb-xd1[data-phase=\"done\"] .hb-xd1-strip { animation: none; opacity: 0; }\n}\n`;\n\nfunction hash(n: number) {\n  let h = (n + 1) * 2654435761;\n  h = Math.imul(h ^ (h >>> 15), 2246822519);\n  h = Math.imul(h ^ (h >>> 13), 3266489917);\n  return (h ^ (h >>> 16)) >>> 0;\n}\n\nexport function ButtonHoldShred({\n  children = \"Hold to shred\",\n  doneLabel = \"Shredded\",\n  duration = 1300,\n  accent = \"#ef4444\",\n  size = \"md\",\n  strips = 14,\n  resetAfter = 2600,\n  onConfirm,\n  disabled = false,\n  type = \"button\",\n  className = \"\",\n  style,\n  onPointerDown,\n  onPointerUp,\n  onPointerLeave,\n  onPointerCancel,\n  onKeyDown,\n  onKeyUp,\n  onBlur,\n  ...rest\n}: ButtonHoldShredProps) {\n  const rootRef = React.useRef<HTMLSpanElement>(null);\n  const progress = React.useRef(0);\n  const dir = React.useRef(0);\n  const raf = React.useRef(0);\n  const last = React.useRef(0);\n  const latest = React.useRef(onConfirm);\n  const [phase, setPhase] = React.useState<\"idle\" | \"holding\" | \"done\">(\"idle\");\n\n  React.useEffect(() => {\n    latest.current = onConfirm;\n  }, [onConfirm]);\n\n  React.useEffect(() => () => cancelAnimationFrame(raf.current), []);\n\n  React.useEffect(() => {\n    if (phase !== \"done\" || resetAfter <= 0) return;\n    const t = window.setTimeout(() => {\n      progress.current = 0;\n      rootRef.current?.style.setProperty(\"--hb-xd1-p\", \"0\");\n      setPhase(\"idle\");\n    }, resetAfter);\n    return () => window.clearTimeout(t);\n  }, [phase, resetAfter]);\n\n  const run = () => {\n    cancelAnimationFrame(raf.current);\n    last.current = 0;\n    const step = (t: number) => {\n      const dt = last.current ? Math.min(48, t - last.current) : 16;\n      last.current = t;\n      if (dir.current > 0) progress.current = Math.min(1, progress.current + dt / duration);\n      else progress.current = Math.max(0, progress.current - dt / (duration * 0.32));\n      rootRef.current?.style.setProperty(\"--hb-xd1-p\", progress.current.toFixed(3));\n      if (dir.current > 0 && progress.current >= 1) {\n        dir.current = 0;\n        setPhase(\"done\");\n        latest.current?.();\n        return;\n      }\n      if (dir.current <= 0 && progress.current <= 0) {\n        setPhase(\"idle\");\n        return;\n      }\n      raf.current = requestAnimationFrame(step);\n    };\n    raf.current = requestAnimationFrame(step);\n  };\n\n  const start = () => {\n    if (disabled || phase === \"done\" || dir.current > 0) return;\n    dir.current = 1;\n    setPhase(\"holding\");\n    run();\n  };\n\n  const stop = () => {\n    if (dir.current <= 0) return;\n    dir.current = -1;\n    run();\n  };\n\n  const count = Math.max(4, Math.min(24, Math.round(strips)));\n  const list = Array.from({ length: count }, (_, i) => {\n    const h = hash(i);\n    return {\n      len: `${(14 + (h % 13)).toFixed(0)}px`,\n      d: `${((h >>> 4) % 160).toFixed(0)}ms`,\n      r: `${(((h >>> 9) % 50) - 25).toFixed(0)}deg`,\n    };\n  });\n\n  return (\n    <span\n      ref={rootRef}\n      className={`hb-xd1 ${className}`.trim()}\n      data-size={size}\n      data-phase={phase}\n      style={{ \"--hb-xd1-c\": accent, ...style } as React.CSSProperties}\n    >\n      <style href=\"hb-button-hold-shred\" precedence=\"default\">{css}</style>\n      <button\n        type={type}\n        className=\"hb-xd1-btn\"\n        disabled={disabled}\n        aria-disabled={phase === \"done\" || undefined}\n        onPointerDown={(e) => {\n          onPointerDown?.(e);\n          if (e.button !== 0) return;\n          e.currentTarget.setPointerCapture?.(e.pointerId);\n          start();\n        }}\n        onPointerUp={(e) => {\n          onPointerUp?.(e);\n          stop();\n        }}\n        onPointerLeave={(e) => {\n          onPointerLeave?.(e);\n          stop();\n        }}\n        onPointerCancel={(e) => {\n          onPointerCancel?.(e);\n          stop();\n        }}\n        onKeyDown={(e) => {\n          onKeyDown?.(e);\n          if ((e.key === \" \" || e.key === \"Enter\") && !e.repeat) {\n            e.preventDefault();\n            start();\n          }\n        }}\n        onKeyUp={(e) => {\n          onKeyUp?.(e);\n          if (e.key === \" \" || e.key === \"Enter\") stop();\n        }}\n        onBlur={(e) => {\n          onBlur?.(e);\n          stop();\n        }}\n        onContextMenu={(e) => e.preventDefault()}\n        {...rest}\n      >\n        <span className=\"hb-xd1-heat\" aria-hidden=\"true\" />\n        <span className=\"hb-xd1-face\">\n          <svg viewBox=\"0 0 24 24\" width=\"1.05em\" height=\"1.05em\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M6 9V4h9l3 3v2\" />\n            <rect x=\"3\" y=\"9\" width=\"18\" height=\"6\" rx=\"1.5\" />\n            <path d=\"M7 15v5M10 15v4M14 15v5M17 15v3\" />\n          </svg>\n          {children}\n        </span>\n        <span className=\"hb-xd1-done\" aria-hidden={phase !== \"done\"}>\n          <svg viewBox=\"0 0 24 24\" width=\"1.05em\" height=\"1.05em\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.4\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n            <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n          </svg>\n          {doneLabel}\n        </span>\n        <span className=\"hb-xd1-slot\" aria-hidden=\"true\" />\n        <span className=\"hb-xd1-sr\">Press and hold to confirm</span>\n      </button>\n      <span className=\"hb-xd1-strips\" aria-hidden=\"true\">\n        {list.map((s, i) => (\n          <span\n            key={i}\n            className=\"hb-xd1-strip\"\n            style={{ \"--hb-xd1-len\": s.len, \"--hb-xd1-d\": s.d, \"--hb-xd1-r\": s.r } as React.CSSProperties}\n          />\n        ))}\n      </span>\n      <span className=\"hb-xd1-sr\" role=\"status\" aria-live=\"polite\">\n        {phase === \"done\" ? doneLabel : \"\"}\n      </span>\n    </span>\n  );\n}\n"
    }
  ]
}