{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"hold-to-ignite-button","type":"registry:component","title":"Hold to Ignite Button","description":"A press-and-hold confirm: a flame-edged fill rises through the button while you hold, drains if you let go early, and lands with a burst of sparks.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/hold-to-ignite-button.tsx","content":"\"use client\";\n\nimport { useCallback, useEffect, useId, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties } from \"react\";\n\n\n/** Safety orange as a field colour. Black on it reads at 6.3:1. */\nconst HV_ORANGE = \"#FF5B14\";\n\n/** The hot highlight, for orange marks on black. */\nconst HV_HOT = \"#FF7A1A\";\n\nconst HV_BLACK = \"#0B0A09\";\n\n/**\n * The display face: Archivo's width axis does the shouting (wdth 62..125).\n * Load it as a variable font with the width axis and expose it as --font-hv,\n * e.g. in Next: Archivo({ subsets: [\"latin\"], axes: [\"wdth\"], variable: \"--font-hv\" }).\n */\nconst HV_DISPLAY = 'var(--font-hv, \"Archivo\"), \"Archivo\", \"Arial Narrow\", ui-sans-serif, system-ui, sans-serif';\n\nfunction hvReducedSub(fn: () => void) {\n  if (typeof window === \"undefined\" || typeof window.matchMedia !== \"function\") return () => {};\n  const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  mq.addEventListener(\"change\", fn);\n  return () => mq.removeEventListener(\"change\", fn);\n}\n\nconst hvReducedSnap = () => typeof window !== \"undefined\" && typeof window.matchMedia === \"function\" && window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n\n/** True when the reader asked for reduced motion. Live: follows the system setting as it changes. */\nfunction useHvReduced(): boolean {\n  return useSyncExternalStore(hvReducedSub, hvReducedSnap, () => false);\n}\n\n/**\n * The kit's scoped CSS: one focus ring (2px, offset 3px, in the ink of the\n * ground it sits on), tabular figures, the press, and transitions off for\n * anything a frame loop writes.\n */\nconst HV_CSS =\n  \".hv-scope{--hv-ring:\" + HV_HOT + \"}\" +\n  \".hv-scope[data-hv-ground=orange],.hv-scope [data-hv-ground=orange]{--hv-ring:\" + HV_BLACK + \"}\" +\n  \".hv-scope[data-hv-ground=bone],.hv-scope [data-hv-ground=bone]{--hv-ring:\" + HV_BLACK + \"}\" +\n  \".hv-scope :focus-visible{outline:2px solid var(--hv-ring)!important;outline-offset:3px!important}\" +\n  \".hv-scope .hv-num{font-variant-numeric:tabular-nums}\" +\n  \".hv-scope [data-hv-live]{transition:none!important}\" +\n  \".hv-scope .hv-press{transition:transform 160ms cubic-bezier(.2,.8,.2,1),background-color 160ms,color 160ms}\" +\n  \".hv-scope .hv-press:active{transform:scale(.97)}\" +\n  \".hv-scope .hv-arr{transition:transform 220ms cubic-bezier(.2,.8,.2,1)}.hv-scope a:hover .hv-arr,.hv-scope button:hover .hv-arr{transform:translateX(3px)}\" +\n  \"@media (prefers-reduced-motion:reduce){.hv-scope .hv-press,.hv-scope .hv-arr{transition:none}}\";\n\n/** Ardent's mark: a shock diamond, the bright knot in a rocket plume. Takes the current colour. */\nfunction HvMark({ size = 22 }: { size?: number }) {\n  return (\n    <svg width={size} height={size} viewBox=\"0 0 24 24\" aria-hidden>\n      <path d=\"M12 1.5 L19 12 L12 22.5 L5 12 Z\" fill=\"currentColor\" />\n      <path d=\"M12 7.2 L15.2 12 L12 16.8 L8.8 12 Z\" fill=\"var(--hv-mark-cut, #0B0A09)\" />\n    </svg>\n  );\n}\n\n/** The flame-edged fill as a path in a w x h box: a wavy top edge at progress p. */\nfunction hbFlame(w: number, h: number, p: number, t: number): string {\n  const s = Math.sin(Math.PI * Math.min(1, p));\n  const top = h * (1 - p) + 3;\n  let d = \"M0 \" + (h + 1) + \" L0 \" + top.toFixed(2);\n  for (let i = 1; i <= 16; i++) {\n    const x = (i / 16) * w;\n    const y = top - s * (3.2 * Math.sin(x * 0.11 + t * 9) + 2 * Math.sin(x * 0.27 - t * 13) + 1.1 * Math.sin(x * 0.53 + t * 21)) - 3 * p;\n    d += \" L\" + x.toFixed(2) + \" \" + y.toFixed(2);\n  }\n  return d + \" L\" + w + \" \" + (h + 1) + \" Z\";\n}\n\ninterface HbSpark {\n  x: number;\n  y: number;\n  vx: number;\n  vy: number;\n  life: number;\n  hot: boolean;\n}\n\nconst HB_CSS =\n  \"@keyframes hv-hb-nudge{0%,100%{transform:translateX(0)}25%{transform:translateX(-4px)}75%{transform:translateX(4px)}}\" +\n  \".hv-hb[data-nudge]{animation:hv-hb-nudge 260ms cubic-bezier(.3,.7,.4,1)}\" +\n  \".hv-hb{transition:transform 180ms cubic-bezier(.2,.8,.2,1),box-shadow 220ms}\" +\n  \".hv-hb[data-phase=holding]{transform:scale(.975)}\" +\n  \".hv-hb:hover{box-shadow:0 0 0 2px var(--hv-hb-ring)}\" +\n  \"@media (prefers-reduced-motion:reduce){.hv-hb,.hv-hb[data-nudge]{animation:none;transition:none}}\";\n\nexport interface HoldToIgniteButtonProps {\n  label?: string;\n  /** What the button says while it is being held. */\n  holdingLabel?: string;\n  /** What it says once the hold completed. */\n  doneLabel?: string;\n  /** How long a full hold takes, in ms. */\n  holdMs?: number;\n  /** Called once when a hold completes. */\n  onComplete?: () => void;\n  /** Return to the idle state this long after completing (ms). 0 keeps it done. */\n  resetAfter?: number;\n  /** \"md\" 56px tall, \"lg\" 72px for a page's one big call. */\n  size?: \"md\" | \"lg\";\n  /** The ground the button sits on: \"orange\" draws it black with an orange fill, \"black\" draws it orange with a black fill. */\n  ground?: \"orange\" | \"black\";\n  className?: string;\n  style?: CSSProperties;\n}\n\n/**\n * HoldToIgniteButton — a press-and-hold confirm for the one action that\n * should not happen by accident.\n */\nexport function HoldToIgniteButton({\n  label = \"Hold to reserve\",\n  holdingLabel = \"Keep holding\",\n  doneLabel = \"Reserved\",\n  holdMs = 1100,\n  onComplete,\n  resetAfter = 0,\n  ground = \"orange\",\n  size = \"md\",\n  className = \"\",\n  style,\n}: HoldToIgniteButtonProps) {\n  const btnRef = useRef<HTMLButtonElement>(null);\n  const fillRef = useRef<SVGPathElement>(null);\n  const inkRef = useRef<HTMLSpanElement>(null);\n  const sparkRef = useRef<HTMLCanvasElement>(null);\n  const [phase, setPhase] = useState<\"idle\" | \"holding\" | \"done\">(\"idle\");\n  const [nudge, setNudge] = useState(0);\n  const hintId = useId();\n  const reduced = useHvReduced();\n  const st = useRef({ p: 0, down: false, raf: 0, last: 0, done: false, downAt: 0, loop: ((now: number) => void now) as (now: number) => void });\n  const cbRef = useRef(onComplete);\n  const holdRef = useRef(holdMs);\n  useEffect(() => {\n    cbRef.current = onComplete;\n    holdRef.current = holdMs;\n  });\n  const base = ground === \"orange\" ? HV_BLACK : HV_ORANGE;\n  const ink = ground === \"orange\" ? HV_ORANGE : HV_BLACK;\n  const fill = ground === \"orange\" ? HV_ORANGE : HV_BLACK;\n  const fillInk = ground === \"orange\" ? HV_BLACK : HV_ORANGE;\n\n  const paint = useCallback((now: number) => {\n    const b = btnRef.current;\n    const path = fillRef.current;\n    const top = inkRef.current;\n    if (!b || !path || !top) return;\n    const w = b.offsetWidth;\n    const h = b.offsetHeight;\n    const p = st.current.p;\n    const d = p <= 0 ? \"\" : hbFlame(w, h, p, hvReducedSnap() ? 0 : now / 1000);\n    path.setAttribute(\"d\", d);\n    top.style.clipPath = p <= 0 ? \"inset(100% 0 0 0)\" : \"path('\" + d + \"')\";\n  }, []);\n\n  const burst = useCallback(() => {\n    const cv = sparkRef.current;\n    const b = btnRef.current;\n    if (!cv || !b || hvReducedSnap()) return;\n    const ctx = cv.getContext(\"2d\");\n    if (!ctx) return;\n    const dpr = Math.min(2, window.devicePixelRatio || 1);\n    const W = cv.offsetWidth;\n    const H = cv.offsetHeight;\n    cv.width = Math.round(W * dpr);\n    cv.height = Math.round(H * dpr);\n    const bw = b.offsetWidth;\n    const ox = (W - bw) / 2;\n    const oy = (H - b.offsetHeight) / 2;\n    const sparks: HbSpark[] = [];\n    for (let i = 0; i < 34; i++) {\n      const a = -Math.PI / 2 + (Math.random() - 0.5) * 2.4;\n      const v = 140 + Math.random() * 320;\n      sparks.push({ x: ox + Math.random() * bw, y: oy + 2, vx: Math.cos(a) * v, vy: Math.sin(a) * v, life: 0.45 + Math.random() * 0.5, hot: Math.random() < 0.35 });\n    }\n    let last = performance.now();\n    const tick = (now: number) => {\n      const dt = Math.min(0.05, (now - last) / 1000);\n      last = now;\n      ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n      ctx.clearRect(0, 0, W, H);\n      let alive = 0;\n      for (const s of sparks) {\n        if (s.life <= 0) continue;\n        alive++;\n        s.life -= dt;\n        s.vy += 620 * dt;\n        s.vx *= 1 - 1.6 * dt;\n        const x0 = s.x;\n        const y0 = s.y;\n        s.x += s.vx * dt;\n        s.y += s.vy * dt;\n        ctx.strokeStyle = s.hot ? \"rgba(255,238,200,\" + Math.min(1, s.life * 2.2).toFixed(3) + \")\" : \"rgba(255,122,26,\" + Math.min(1, s.life * 2.2).toFixed(3) + \")\";\n        ctx.lineWidth = s.hot ? 1.6 : 2.2;\n        ctx.lineCap = \"round\";\n        ctx.beginPath();\n        ctx.moveTo(x0, y0);\n        ctx.lineTo(s.x, s.y);\n        ctx.stroke();\n      }\n      if (alive) requestAnimationFrame(tick);\n      else ctx.clearRect(0, 0, W, H);\n    };\n    requestAnimationFrame(tick);\n  }, []);\n\n  // The hold's frame loop: fills while held, drains when let go, lands at 1.\n  useEffect(() => {\n    const s = st.current;\n    const loop = (now: number) => {\n      s.raf = 0;\n      const dt = s.last ? Math.min(0.05, (now - s.last) / 1000) : 0;\n      s.last = now;\n      if (s.done) return;\n      const ms = Math.max(200, holdRef.current);\n      if (s.down) s.p = Math.min(1, s.p + (dt * 1000) / ms);\n      else s.p = Math.max(0, s.p - (dt * 1000 * 2.6) / ms);\n      paint(now);\n      if (s.p >= 1) {\n        s.done = true;\n        s.down = false;\n        setPhase(\"done\");\n        burst();\n        if (typeof navigator !== \"undefined\" && \"vibrate\" in navigator) navigator.vibrate?.(18);\n        cbRef.current?.();\n        return;\n      }\n      if (s.down || s.p > 0) s.raf = requestAnimationFrame(loop);\n      else {\n        s.last = 0;\n        setPhase(\"idle\");\n      }\n    };\n    s.loop = loop;\n    return () => {\n      if (s.raf) cancelAnimationFrame(s.raf);\n      s.raf = 0;\n    };\n  }, [paint, burst]);\n\n  const press = () => {\n    const s = st.current;\n    if (s.done || s.down) return;\n    s.down = true;\n    s.downAt = performance.now();\n    setPhase(\"holding\");\n    if (!s.raf) s.raf = requestAnimationFrame(s.loop);\n  };\n  const release = () => {\n    const s = st.current;\n    if (!s.down) return;\n    s.down = false;\n    if (!s.done) setPhase(\"idle\");\n    // A tap is not a hold: say so with a small shake.\n    if (performance.now() - s.downAt < 220) setNudge((n) => n + 1);\n    if (!s.raf) s.raf = requestAnimationFrame(s.loop);\n  };\n\n  useEffect(() => {\n    if (phase !== \"done\" || !resetAfter) return;\n    const id = window.setTimeout(() => {\n      const s = st.current;\n      s.done = false;\n      s.p = 0;\n      s.last = 0;\n      paint(performance.now());\n      setPhase(\"idle\");\n    }, resetAfter);\n    return () => window.clearTimeout(id);\n  }, [phase, resetAfter, paint]);\n\n  useEffect(() => {\n    if (!nudge) return;\n    const b = btnRef.current;\n    if (!b) return;\n    b.removeAttribute(\"data-nudge\");\n    void b.offsetWidth;\n    b.setAttribute(\"data-nudge\", \"\");\n    const id = window.setTimeout(() => b.removeAttribute(\"data-nudge\"), 300);\n    return () => window.clearTimeout(id);\n  }, [nudge]);\n\n  // All three labels share one grid cell, so the button is as wide as the longest and never reflows mid-hold.\n  const labels: [typeof phase, string][] = [\n    [\"idle\", label],\n    [\"holding\", holdingLabel],\n    [\"done\", doneLabel],\n  ];\n  const content = (\n    <>\n      {phase === \"done\" ? (\n        <svg width=\"16\" height=\"16\" viewBox=\"0 0 16 16\" aria-hidden>\n          <path d=\"M3 8.5l3.2 3L13 4.5\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.2\" strokeLinecap=\"square\" />\n        </svg>\n      ) : (\n        <HvMark size={16} />\n      )}\n      <span className=\"grid\">\n        {labels.map(([k, t]) => (\n          <span key={k} aria-hidden={k !== phase ? true : undefined} style={{ gridArea: \"1 / 1\", visibility: k === phase ? \"visible\" : \"hidden\" }}>\n            {t}\n          </span>\n        ))}\n      </span>\n    </>\n  );\n  return (\n    <span className={\"hv-scope relative inline-flex \" + className} style={style}>\n      <style>{HV_CSS + HB_CSS}</style>\n      <canvas ref={sparkRef} aria-hidden className=\"pointer-events-none absolute left-1/2 top-1/2 z-20 h-[300%] w-[160%] -translate-x-1/2 -translate-y-1/2\" />\n      <button\n        ref={btnRef}\n        type=\"button\"\n        data-phase={phase}\n        aria-describedby={hintId}\n        onPointerDown={(e) => {\n          if (e.button !== 0) return;\n          e.currentTarget.setPointerCapture(e.pointerId);\n          press();\n        }}\n        onPointerUp={release}\n        onPointerCancel={release}\n        onLostPointerCapture={release}\n        onKeyDown={(e) => {\n          if ((e.key === \" \" || e.key === \"Enter\") && !e.repeat) {\n            e.preventDefault();\n            press();\n          } else if (e.key === \" \" || e.key === \"Enter\") e.preventDefault();\n        }}\n        onKeyUp={(e) => {\n          if (e.key === \" \" || e.key === \"Enter\") {\n            e.preventDefault();\n            release();\n          }\n        }}\n        onBlur={release}\n        onContextMenu={(e) => e.preventDefault()}\n        onClick={(e) => {\n          // A click with no pointer or key behind it (a screen reader, voice control) cannot hold: it confirms at once.\n          const s = st.current;\n          if (e.detail !== 0 || s.done || s.down) return;\n          s.p = 1;\n          s.last = 0;\n          if (!s.raf) s.raf = requestAnimationFrame(s.loop);\n        }}\n        className={\"hv-hb relative inline-flex select-none items-center overflow-hidden border-0 font-bold uppercase tracking-[0.06em] \" + (size === \"lg\" ? \"h-[72px] px-9 text-[19px]\" : \"h-14 px-7 text-[15px]\")}\n        style={{ background: base, color: ink, fontFamily: HV_DISPLAY, touchAction: \"none\", WebkitTouchCallout: \"none\", \"--hv-hb-ring\": fill, cursor: phase === \"done\" ? \"default\" : \"pointer\" } as CSSProperties}\n      >\n        <svg aria-hidden className=\"pointer-events-none absolute inset-0 h-full w-full overflow-visible\">\n          <path ref={fillRef} fill={fill} />\n        </svg>\n        <span className=\"relative inline-flex items-center gap-2.5\" style={{ \"--hv-mark-cut\": base } as CSSProperties}>\n          {content}\n        </span>\n        <span ref={inkRef} aria-hidden data-hv-live=\"\" className={\"pointer-events-none absolute inset-0 flex items-center \" + (size === \"lg\" ? \"px-9\" : \"px-7\")} style={{ color: fillInk, clipPath: \"inset(100% 0 0 0)\" }}>\n          <span className=\"inline-flex items-center gap-2.5\" style={{ \"--hv-mark-cut\": fill } as CSSProperties}>\n            {content}\n          </span>\n        </span>\n      </button>\n      <span id={hintId} className=\"sr-only\">\n        {reduced ? \"Press and hold to confirm.\" : \"Press and hold for about a second to confirm.\"}\n      </span>\n      <span aria-live=\"polite\" className=\"sr-only\">\n        {phase === \"done\" ? doneLabel : \"\"}\n      </span>\n    </span>\n  );\n}\n","type":"registry:component","target":"components/viberdy/hold-to-ignite-button.tsx"}],"meta":{"tier":"free","tags":["button","hold to confirm","long press","micro-interaction","sparks","canvas","orange","confirmation"],"href":"https://viberdy.dev/library/hold-to-ignite-button","aiPrompt":"Build HoldToIgniteButton, a press-and-hold confirm. Style: Hi-Vis. Fixed palette, no theming: safety orange #FF5B14 as a flat field (black on it is 6.3:1; dim text on orange stays at 75%+ black), hot orange #FF7A1A for marks on black, warm black #0B0A09, bone #EFEBE4. Type: Archivo variable (wght 100-900, wdth 62-125) loaded with its wdth axis (next/font: Archivo({ subsets: [\"latin\"], axes: [\"wdth\"], variable: \"--font-hv\" })) and read as var(--font-hv, \"Archivo\"), display at weight 850-900, wdth 62-80, uppercase, line-height 0.84-0.9; Geist Mono (var(--font-hv-mono)) for labels at 11-12.5px, uppercase, tracking 0.12-0.16em. Square corners everywhere. Every section root carries data-hv-ground=\"black\" | \"orange\" | \"bone\". One focus ring: 2px solid, offset 3px, hot orange on black and black on orange or bone. Scroll-told parts are driven by one number p (0..1) that chases the measured scroll with v += (target - v) * 0.16 per frame, written straight to the DOM (no React state per frame); a capture-phase scroll listener on document hears any scroller, so it works on a page and inside a scrolling box. Reduced motion shows the settled end state. Links go through a safe-href helper (https, http, mailto, same-site paths and anchors only; backslashes refused). React 19, Tailwind v4 with container queries (@container on the root, @3xl = 768px for the desktop layout). No three.js, no images.\n\nA 56px square-cornered button (padding 28px, 15px bold uppercase, tracking 0.06em). On orange ground it is black with orange text and fills orange; on black ground it is orange and fills black. Holding (pointer with setPointerCapture, or Space/Enter without key repeat) raises a fill over holdMs (default 1100) in a requestAnimationFrame loop; letting go drains it 2.6x faster. The fill is an SVG path redrawn per frame: top edge at h(1 - p) + 3 - 3p with a flame wave of amplitude sin(pi p) x (3.2 sin(0.11x + 9t) + 2 sin(0.27x - 13t) + 1.1 sin(0.53x + 21t)) across 16 segments. The label is drawn twice; the second, in the fill's ink, is clipped by the same path through clip-path: path(), so the type inverts exactly under the flame. Labels: idle \"Hold to reserve\", held \"Keep holding\", done \"Reserved\" with a tick (the idle icon is a shock-diamond mark). The button scales to 0.975 while held. On completion: 34 spark streaks from the top edge on a 2D canvas 160% x 300% around the button (speed 140-460 px/s, gravity 620, drag, life 0.45-0.95 s, a third white-hot), navigator.vibrate(18), onComplete(). A tap under 220ms shakes the button (260ms, 4px). resetAfter (ms, 0 keeps it done). A hidden hint is linked by aria-describedby and completion is announced in a polite live region. Reduced motion: no sparks, no shake, no flicker. Props: label, holdingLabel, doneLabel, holdMs, onComplete, resetAfter, ground.","license":"https://viberdy.dev/license"}}