{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "fugitive-ink",
  "title": "Fugitive Ink",
  "description": "A one-time secret panel that prints a new API key or recovery code fully legible, then lets it fade like security ink, armed by the user's own copy or by clicking away, never by a modal you close and lose.",
  "dependencies": [],
  "files": [
    {
      "path": "registry/core/fugitive-ink/component.tsx",
      "content": "\"use client\";\n\nimport { useCallback, useEffect, useMemo, useRef, useState, type CSSProperties } from \"react\";\n\n// ---------------------------------------------------------------------------\n// FugitiveInk — a one-time secret panel (new API key, recovery code) that\n// prints the value fully legible, then lets it decay like security ink\n// instead of hiding it behind a modal you can close and lose. The\n// never-again clause is enacted, not footnoted.\n//\n// MECHANISM: a single governing scalar `t` (0 -> 1 across `decayMs`, default\n// 60s) is written once per tick as the CSS custom property `--fi-t` on the\n// panel root and inherits to every character span — there is no per-char\n// timer or choreography. Each middle character carries only a static\n// `--fi-o` offset derived from a hash of its index (0..0.4 of the window),\n// and a shared CSS formula turns (t, o) into that character's own local\n// phase: `--fi-local = clamp01((t - o) * 1.667)`, scaled so the\n// latest-offset character still reaches 1 exactly when t reaches 1. That\n// local phase crosses three thresholds, same formula for every character,\n// just at different absolute moments: font-weight 600 -> 300 (phase\n// 0 -> 0.35), color --foreground -> --ns-muted via color-mix (phase\n// 0.3 -> 0.65), then a clip-path eating the glyph from its waterline\n// (bottom) up, leaving a top hairline (phase 0.55 -> 1, up to 88% eaten).\n// The prefix and last four characters never enter this system at all — they\n// render as plain, permanently full-weight text — so the string decays into\n// a stub that is exactly what a returning user needs to recognize the key\n// by, not gibberish.\n//\n// Arming: the clock is idle (t pinned at 0, secret fully legible) until the\n// user's own Copy click *or* focus leaving the panel entirely (a real\n// `blur`/`focusout` past the panel boundary), whichever happens first — a\n// one-way latch, not a toggle. A thin rule under the secret drains on the\n// same `--fi-t` scalar (`scaleX(1 - t)`) and is labelled with the real\n// integer seconds remaining, recomputed from wall-clock elapsed time so it\n// can't drift from what's announced. Clipboard and pixels expire together:\n// the Copy button copies the full value for as long as t < 1, and once t\n// reaches 1 it copies only the identifying stub (`prefix…suffix`) forever\n// after — never the full value again, but never a dead button either. A\n// permanent record line under the field (`sk-live-…4f2q, copied 14:32, will\n// not be shown again`) survives decay unchanged; nothing here is a modal\n// that closes and takes the record with it.\n//\n// A11Y: the secret sits in a real `role=\"textbox\" aria-readonly` element,\n// keyboard-focusable and text-selectable, never conveying the live value\n// through color or clip alone — the character text itself never changes.\n// The Copy button's accessible name is explicit (\"Copy secret key, shown\n// only once\", swapping to name the stub once expired). Arming announces\n// assertively (a visually-hidden `role=\"alert\"`); crossing half and zero\n// announce politely (`aria-live=\"polite\"`) and never claim a state the\n// pixels haven't reached yet, since both read off the same `t`.\n// `prefers-reduced-motion` doesn't disable the decay, it quantizes the same\n// `--fi-t` scalar to the same three moments (0, half, expired) instead of a\n// continuous ramp, so the CSS thresholds above collapse to three discrete\n// text states rather than a smooth animation.\n// ---------------------------------------------------------------------------\n\nconst DEFAULT_DECAY_MS = 60_000;\nconst TICK_MS = 100;\nconst OFFSET_MAX = 0.4; // fraction of the window a character's local clock can lag by\nconst LOCAL_SCALE = 1 / (1 - OFFSET_MAX); // reciprocal: max-offset char still reaches local=1 at t=1\nconst WEIGHT_RECIP = 1 / 0.35; // local phase 0 -> 0.35 covers the font-weight step\nconst COLOR_START = 0.3;\nconst COLOR_RECIP = 1 / 0.35; // local phase 0.3 -> 0.65 covers the color step\nconst CLIP_START = 0.55;\nconst CLIP_RECIP = 1 / 0.45; // local phase 0.55 -> 1 covers the clip-path step\nconst CLIP_MAX_PCT = 88; // never fully to 100 — a hairline survives, it doesn't vanish\n\nfunction hashOffset(index: number): number {\n  const h = Math.imul(index + 1, 2654435761) >>> 0;\n  return ((h % 1000) / 1000) * OFFSET_MAX;\n}\n\nfunction formatClock(d: Date): string {\n  const h = d.getHours().toString().padStart(2, \"0\");\n  const m = d.getMinutes().toString().padStart(2, \"0\");\n  return `${h}:${m}`;\n}\n\nfunction secondsLeft(msLeft: number): number {\n  return Math.max(0, Math.ceil(msLeft / 1000));\n}\n\nasync function copyToClipboard(text: string): Promise<boolean> {\n  try {\n    if (navigator.clipboard && window.isSecureContext) {\n      await navigator.clipboard.writeText(text);\n      return true;\n    }\n  } catch {\n    // fall through to the execCommand fallback\n  }\n  try {\n    const ta = document.createElement(\"textarea\");\n    ta.value = text;\n    ta.setAttribute(\"readonly\", \"\");\n    ta.style.position = \"fixed\";\n    ta.style.top = \"0\";\n    ta.style.left = \"0\";\n    ta.style.opacity = \"0\";\n    ta.style.pointerEvents = \"none\";\n    document.body.appendChild(ta);\n    ta.focus();\n    ta.select();\n    const ok = document.execCommand(\"copy\");\n    document.body.removeChild(ta);\n    return ok;\n  } catch {\n    return false;\n  }\n}\n\ntype Phase = \"idle\" | \"armed\" | \"expired\";\n\nexport interface FugitiveInkProps {\n  /** The real secret — full API key, recovery code, etc. Shown once, in full. */\n  value: string;\n  /** Caption above the field, e.g. \"New API key\". Also seeds accessible names. */\n  label?: string;\n  /** Characters at the start that never decay (the identifying prefix, e.g. \"sk-live-\"). */\n  prefixLen?: number;\n  /** Characters at the end that never decay. */\n  suffixLen?: number;\n  /** Full decay window in ms, idle -> fully faded. Default 60000 (60s). */\n  decayMs?: number;\n  /** Overrides the record line's timestamp text instead of the real clock at arm time. */\n  copiedAtOverride?: string;\n  /** Called on every successful copy with what was actually copied and which kind. */\n  onCopy?: (copied: string, kind: \"full\" | \"stub\") => void;\n  /** extra classes merged onto the rendered root element */\n  className?: string;\n}\n\nexport function FugitiveInk({\n  value,\n  label = \"New API key\",\n  prefixLen = 8,\n  suffixLen = 4,\n  decayMs = DEFAULT_DECAY_MS,\n  copiedAtOverride,\n  onCopy,\n  className = \"\",\n}: FugitiveInkProps) {\n  const panelRef = useRef<HTMLDivElement>(null);\n  const armedAtRef = useRef<number | null>(null);\n  const timerRef = useRef<number | undefined>(undefined);\n  const reducedRef = useRef(false);\n  const halfFiredRef = useRef(false);\n\n  const [phase, setPhase] = useState<Phase>(\"idle\");\n  const [remainingSec, setRemainingSec] = useState(() => Math.round(decayMs / 1000));\n  const [recordVerb, setRecordVerb] = useState<\"copied\" | \"shown\">(\"copied\");\n  const [recordAt, setRecordAt] = useState<string | null>(null);\n  const [politeMsg, setPoliteMsg] = useState(\"\");\n  const [assertiveMsg, setAssertiveMsg] = useState(\"\");\n\n  const totalSec = Math.round(decayMs / 1000);\n\n  const safePrefixLen = Math.min(prefixLen, Math.max(0, value.length - suffixLen));\n  const safeSuffixLen = Math.min(suffixLen, Math.max(0, value.length - safePrefixLen));\n  const prefix = value.slice(0, safePrefixLen);\n  const suffix = safeSuffixLen > 0 ? value.slice(value.length - safeSuffixLen) : \"\";\n  const middle = value.slice(safePrefixLen, value.length - safeSuffixLen);\n  const stub = `${prefix}…${suffix}`;\n\n  const offsets = useMemo(() => middle.split(\"\").map((_, i) => hashOffset(i)), [middle]);\n\n  const announcePolite = useCallback((text: string) => {\n    setPoliteMsg(\"\");\n    window.requestAnimationFrame(() => setPoliteMsg(text));\n  }, []);\n  const announceAssertive = useCallback((text: string) => {\n    setAssertiveMsg(\"\");\n    window.requestAnimationFrame(() => setAssertiveMsg(text));\n  }, []);\n\n  const stopClock = useCallback(() => {\n    if (timerRef.current !== undefined) {\n      window.clearTimeout(timerRef.current);\n      timerRef.current = undefined;\n    }\n  }, []);\n\n  const writeT = useCallback((t: number) => {\n    const clamped = t < 0 ? 0 : t > 1 ? 1 : t;\n    const snapped = reducedRef.current ? (clamped >= 1 ? 1 : clamped >= 0.5 ? 0.5 : 0) : clamped;\n    panelRef.current?.style.setProperty(\"--fi-t\", snapped.toFixed(4));\n  }, []);\n\n  const tick = useCallback(() => {\n    const armedAt = armedAtRef.current;\n    if (armedAt == null) return;\n    const elapsed = performance.now() - armedAt;\n    const t = Math.min(1, elapsed / decayMs);\n    writeT(t);\n\n    setRemainingSec((prev) => {\n      const next = secondsLeft(decayMs - elapsed);\n      return prev === next ? prev : next;\n    });\n\n    if (!halfFiredRef.current && t >= 0.5) {\n      halfFiredRef.current = true;\n      announcePolite(`Half faded — ${Math.round(totalSec / 2)} seconds left.`);\n    }\n\n    if (t >= 1) {\n      setPhase(\"expired\");\n      announcePolite(\"Key no longer readable.\");\n      stopClock();\n      return;\n    }\n\n    timerRef.current = window.setTimeout(tick, TICK_MS);\n  }, [decayMs, writeT, announcePolite, stopClock, totalSec]);\n\n  const arm = useCallback(\n    (copied: boolean) => {\n      if (armedAtRef.current != null) return; // one-way latch: copy-then-blur can't re-arm\n      armedAtRef.current = performance.now();\n      halfFiredRef.current = false;\n      setPhase(\"armed\");\n      setRemainingSec(totalSec);\n      setRecordVerb(copied ? \"copied\" : \"shown\");\n      setRecordAt(copiedAtOverride ?? formatClock(new Date()));\n      announceAssertive(\n        copied\n          ? `Copied. Key becomes unreadable in ${totalSec} seconds.`\n          : `Key becomes unreadable in ${totalSec} seconds.`\n      );\n      writeT(0);\n      stopClock();\n      timerRef.current = window.setTimeout(tick, TICK_MS);\n    },\n    [announceAssertive, copiedAtOverride, stopClock, tick, totalSec, writeT]\n  );\n\n  useEffect(() => {\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    reducedRef.current = mq.matches;\n    const onChange = () => {\n      reducedRef.current = mq.matches;\n    };\n    mq.addEventListener?.(\"change\", onChange);\n    return () => mq.removeEventListener?.(\"change\", onChange);\n  }, []);\n\n  useEffect(() => stopClock, [stopClock]);\n\n  const handleCopyClick = useCallback(() => {\n    void (async () => {\n      if (phase === \"expired\") {\n        const ok = await copyToClipboard(stub);\n        if (ok) {\n          onCopy?.(stub, \"stub\");\n          announcePolite(\"Copied identifier.\");\n        } else {\n          announcePolite(\"Copy failed.\");\n        }\n        return;\n      }\n\n      const wasArmed = armedAtRef.current != null;\n      const ok = await copyToClipboard(value);\n      if (!ok) {\n        announcePolite(\"Copy failed.\");\n        return;\n      }\n      onCopy?.(value, \"full\");\n      if (wasArmed) {\n        announcePolite(\"Copied.\");\n      } else {\n        arm(true);\n      }\n    })();\n  }, [announcePolite, arm, onCopy, phase, stub, value]);\n\n  const handlePanelBlur = useCallback(\n    (e: React.FocusEvent<HTMLDivElement>) => {\n      const next = e.relatedTarget as Node | null;\n      if (next && panelRef.current?.contains(next)) return;\n      arm(false);\n    },\n    [arm]\n  );\n\n  const copyLabel =\n    phase === \"expired\" ? `Copy key identifier ${stub}, secret no longer available` : \"Copy secret key, shown only once\";\n\n  const clockLabel =\n    phase === \"idle\"\n      ? `Copy, or click away, to start the ${totalSec}s clock`\n      : phase === \"expired\"\n        ? \"Faded — no longer shown\"\n        : `${remainingSec}s remaining`;\n\n  const recordLine =\n    phase === \"idle\" ? `${stub} — not yet ${recordVerb === \"copied\" ? \"copied\" : \"shown\"}` : `${stub}, ${recordVerb} ${recordAt}, will not be shown again`;\n\n  return (\n    <div\n      ref={panelRef}\n      className={`ns-fi ${className}`}\n      data-phase={phase}\n      onBlur={handlePanelBlur}\n      style={{ \"--fi-t\": 0 } as CSSProperties}\n    >\n      <p className=\"ns-fi-label\">{label}</p>\n\n      <div className=\"ns-fi-secret\" role=\"textbox\" aria-readonly=\"true\" aria-label={`${label} value`} tabIndex={0}>\n        <span className=\"ns-fi-exempt\">{prefix}</span>\n        <span className=\"ns-fi-chars\">\n          {middle.split(\"\").map((ch, i) => (\n            <span\n              key={i}\n              className=\"ns-fi-char\"\n              style={{ \"--fi-o\": offsets[i]?.toFixed(4) ?? \"0\" } as CSSProperties}\n            >\n              {ch === \" \" ? \" \" : ch}\n            </span>\n          ))}\n        </span>\n        <span className=\"ns-fi-exempt\">{suffix}</span>\n      </div>\n\n      <div className=\"ns-fi-rulewrap\">\n        <div className=\"ns-fi-rule\" aria-hidden=\"true\" />\n        <span className=\"ns-fi-countdown\" data-ns-fi-countdown={phase !== \"idle\" ? \"\" : undefined}>\n          {clockLabel}\n        </span>\n      </div>\n\n      <button type=\"button\" className=\"ns-fi-copy-btn\" aria-label={copyLabel} onClick={handleCopyClick}>\n        <svg width=\"14\" height=\"14\" viewBox=\"0 0 14 14\" fill=\"none\" aria-hidden=\"true\">\n          <rect x=\"4.5\" y=\"4.5\" width=\"8\" height=\"8\" rx=\"1.5\" stroke=\"currentColor\" strokeWidth=\"1.3\" />\n          <path d=\"M2.5 9.5V2.5a1 1 0 0 1 1-1H9.5\" stroke=\"currentColor\" strokeWidth=\"1.3\" strokeLinecap=\"round\" />\n        </svg>\n        {phase === \"expired\" ? \"Copy identifier\" : \"Copy secret key\"}\n      </button>\n\n      <p className=\"ns-fi-record\">{recordLine}</p>\n\n      <span className=\"ns-fi-sr\" role=\"status\" aria-live=\"polite\">\n        {politeMsg}\n      </span>\n      <span className=\"ns-fi-sr\" role=\"alert\" aria-live=\"assertive\">\n        {assertiveMsg}\n      </span>\n\n      <style>{`\n        .ns-fi {\n          display: flex;\n          flex-direction: column;\n          gap: 12px;\n          max-width: 26rem;\n          padding: 16px;\n          border: 1px solid var(--border);\n          border-radius: 12px;\n          background: var(--background);\n        }\n        .ns-fi-label {\n          margin: 0;\n          font-size: 11px;\n          font-weight: 500;\n          letter-spacing: 0.04em;\n          text-transform: uppercase;\n          color: var(--ns-muted);\n        }\n        .ns-fi-sr {\n          position: absolute;\n          width: 1px;\n          height: 1px;\n          padding: 0;\n          margin: -1px;\n          overflow: hidden;\n          clip: rect(0, 0, 0, 0);\n          white-space: nowrap;\n          border: 0;\n        }\n\n        .ns-fi-secret {\n          display: block;\n          padding: 10px 12px;\n          border: 1px solid var(--border);\n          border-radius: 6px;\n          font-family: var(--font-mono, ui-monospace, monospace);\n          font-size: 13px;\n          line-height: 1.5;\n          color: var(--foreground);\n          word-break: break-all;\n          user-select: text;\n          cursor: text;\n        }\n        .ns-fi-secret:focus-visible {\n          outline: 2px solid var(--ns-accent);\n          outline-offset: 2px;\n        }\n        .ns-fi-exempt {\n          font-weight: 600;\n          color: var(--foreground);\n          white-space: pre;\n        }\n        .ns-fi-chars {\n          white-space: pre-wrap;\n        }\n        .ns-fi-char {\n          display: inline-block;\n          white-space: pre;\n          --fi-local: max(0, min(1, calc((var(--fi-t, 0) - var(--fi-o, 0)) * ${LOCAL_SCALE.toFixed(4)})));\n          --fi-w01: min(1, calc(var(--fi-local, 0) * ${WEIGHT_RECIP.toFixed(4)}));\n          --fi-mix: calc(100 * max(0, min(1, calc((var(--fi-local, 0) - ${COLOR_START}) * ${COLOR_RECIP.toFixed(4)}))));\n          --fi-eat: calc(${CLIP_MAX_PCT} * max(0, min(1, calc((var(--fi-local, 0) - ${CLIP_START}) * ${CLIP_RECIP.toFixed(4)}))));\n          font-weight: calc(600 - 300 * var(--fi-w01, 0));\n          color: color-mix(in oklab, var(--foreground), var(--ns-muted) calc(var(--fi-mix, 0) * 1%));\n          clip-path: inset(0 0 calc(var(--fi-eat, 0) * 1%) 0);\n        }\n        @media (prefers-reduced-motion: no-preference) {\n          .ns-fi-char {\n            transition: color 160ms linear, clip-path 160ms linear;\n          }\n        }\n        @media (prefers-reduced-motion: reduce) {\n          .ns-fi-char {\n            transition: none;\n          }\n        }\n\n        .ns-fi-rulewrap {\n          display: flex;\n          align-items: center;\n          gap: 10px;\n        }\n        .ns-fi-rule {\n          position: relative;\n          flex: 1;\n          height: 2px;\n          border-radius: 999px;\n          background: var(--border);\n          overflow: hidden;\n        }\n        .ns-fi-rule::after {\n          content: \"\";\n          position: absolute;\n          inset: 0;\n          transform-origin: left center;\n          transform: scaleX(calc(1 - var(--fi-t, 0)));\n          background: var(--foreground);\n        }\n        @media (prefers-reduced-motion: no-preference) {\n          .ns-fi-rule::after {\n            transition: transform 160ms linear;\n          }\n        }\n        .ns-fi-countdown {\n          flex-shrink: 0;\n          font-family: var(--font-mono, ui-monospace, monospace);\n          font-size: 11px;\n          color: var(--ns-muted);\n          white-space: nowrap;\n        }\n\n        .ns-fi-copy-btn {\n          display: inline-flex;\n          align-items: center;\n          align-self: flex-start;\n          gap: 8px;\n          padding: 8px 14px;\n          border: 1px solid var(--border);\n          border-radius: 6px;\n          background: var(--background);\n          color: var(--foreground);\n          font-size: 13px;\n          cursor: pointer;\n          transition: border-color 140ms ease-out, background-color 140ms ease-out;\n        }\n        .ns-fi-copy-btn:hover {\n          border-color: color-mix(in oklab, var(--foreground) 24%, var(--border));\n          background: color-mix(in oklab, var(--foreground) 3%, var(--background));\n        }\n        .ns-fi-copy-btn:active {\n          background: color-mix(in oklab, var(--foreground) 6%, var(--background));\n        }\n        .ns-fi-copy-btn:focus-visible {\n          outline: 2px solid var(--ns-accent);\n          outline-offset: 2px;\n        }\n\n        .ns-fi-record {\n          margin: 0;\n          font-family: var(--font-mono, ui-monospace, monospace);\n          font-size: 11px;\n          color: var(--ns-muted);\n          word-break: break-all;\n        }\n      `}</style>\n    </div>\n  );\n}\n",
      "type": "registry:ui",
      "target": "components/ui/fugitive-ink.tsx"
    }
  ],
  "cssVars": {
    "theme": {
      "color-ns-muted": "var(--ns-muted)",
      "color-ns-accent": "var(--ns-accent)"
    },
    "light": {
      "ns-muted": "#4d4d4d",
      "ns-accent": "#006bff"
    },
    "dark": {
      "ns-muted": "#8f8f8f"
    }
  },
  "meta": {
    "collection": "core",
    "tags": [
      "secret",
      "api-key",
      "clipboard",
      "recovery-code",
      "reveal",
      "decay",
      "aria-live",
      "accessibility"
    ],
    "instruction": "A one-time secret panel for key issuance and recovery-code flows: the value renders fully legible in a real role=textbox, aria-readonly, keyboard-focusable, text-selectable element, with a Copy button labelled \"Copy secret key, shown only once\" and a permanent record line underneath (initially \"<prefix>…<suffix> — not yet copied\"). Nothing decays until the user arms the panel by clicking Copy or by letting focus leave the panel entirely (blur past its boundary) — a one-way latch, whichever happens first, never both and never re-triggered by a second copy. Once armed, a single governing scalar t runs from 0 to 1 across `decayMs` (default 60000). It is written once per ~100ms tick as the CSS custom property --fi-t on the panel root and inherited by every character span — there is no per-character JS timer. Each middle character (the prefix and last four characters are permanently exempt and never decay) carries only a static --fi-o offset derived from a hash of its index (0 to 0.4 of the window), and a shared CSS formula turns (t, o) into that character's own local phase, scaled so the latest-offset character still finishes exactly when t reaches 1. That local phase crosses three thresholds — the same formula for every character, just at staggered absolute moments — font-weight 600 to 300, then color --foreground to --ns-muted via color-mix, then a clip-path eating the glyph from its waterline (bottom) upward, capped at 88% so a top hairline always survives; the effect reads as granular, paper-like decay rather than a uniform wipe. A thin rule under the secret drains on the same t (scaleX(1-t)) and is labelled with the real integer seconds remaining, recomputed from wall-clock elapsed time so the label can never say something the pixels haven't caught up to. Clipboard and pixels expire together: the Copy button copies the full value for as long as t < 1; once t reaches 1 the button relabels itself and copies only the identifying stub (prefix…suffix) from then on — full value copy never returns, but the button never dies either. The record line survives decay unchanged and switches to \"<prefix>…<suffix>, copied <HH:MM>, will not be shown again\" (or \"shown\" if arming came from blur, not an explicit copy) — this is the permanent artifact a user comes back hunting for later, deliberately not a modal that closes and takes the record with it. Arming announces assertively via a visually-hidden role=alert (\"Copied. Key becomes unreadable in 60 seconds.\"); crossing the halfway point and full expiry each announce once, politely, via a separate aria-live=polite region. prefers-reduced-motion does not disable the decay — it quantizes the same --fi-t scalar to exactly three values (0, 0.5, 1) at the same three moments the announcements already fire, so the continuous CSS thresholds collapse into three discrete text states instead of a smooth ramp, and per-character transitions are removed. Every color is --background, --foreground, --ns-muted, --border and --ns-accent (focus ring only) — no hex, no gradients, no canvas."
  },
  "type": "registry:ui"
}