{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "dialog-session-alert",
  "type": "registry:component",
  "title": "Session Timeout Alert",
  "description": "An alert dialog with a draining countdown ring that turns red in the last ten seconds and signs the user out at zero. Clicking the backdrop nudges the dialog instead of dismissing it.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "modals",
    "alert dialog",
    "countdown",
    "session",
    "timeout",
    "security",
    "modal"
  ],
  "docs": "https://hyperblur.dev/effects/dialog-session-alert",
  "files": [
    {
      "path": "registry/hyperblur/dialog-session-alert.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/dialog-session-alert.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface DialogSessionAlertProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  open?: boolean;\n  defaultOpen?: boolean;\n  onOpenChange?: (open: boolean) => void;\n  embedded?: boolean;\n  trigger?: React.ReactNode;\n  seconds?: number;\n  app?: string;\n  note?: string;\n  onExtend?: () => void;\n  onSignOut?: () => void;\n  onTimeout?: () => void;\n  onSignIn?: () => void;\n  accent?: string;\n}\n\nconst css = `\n.hb-xe5 { --hb-xe5-accent: #f5a524; display: inline-block; box-sizing: border-box; color: #ededed; font-family: var(--font-sans, ui-sans-serif, system-ui, sans-serif); }\n.hb-xe5 *, .hb-xe5 *::before, .hb-xe5 *::after { box-sizing: border-box; }\n.hb-xe5[data-embedded] { position: relative; display: grid; place-items: center; width: 100%; height: 100%; min-height: 190px; border-radius: 16px; overflow: hidden; isolation: isolate; background: repeating-linear-gradient(0deg, #0e0e0f 0 22px, #101011 22px 23px), #0e0e0f; }\n.hb-xe5-trigger { display: inline-flex; align-items: center; gap: 8px; height: 34px; padding: 0 13px; border: 1px solid #2a2a2c; border-radius: 9px; background: #151517; color: #e4e4e7; font: inherit; font-size: 13px; font-weight: 500; cursor: pointer; transition: border-color 0.2s ease, transform 0.15s ease; }\n.hb-xe5-trigger:hover { border-color: #3c3c40; }\n.hb-xe5-trigger:active { transform: scale(0.97); }\n.hb-xe5-trigger svg { width: 14px; height: 14px; color: var(--hb-xe5-accent); }\n.hb-xe5 button:focus-visible { outline: 2px solid var(--hb-xe5-accent); outline-offset: 2px; }\n.hb-xe5-layer { position: fixed; inset: 0; z-index: 1000; height: 100dvh; display: grid; place-items: center; padding: 16px; }\n.hb-xe5[data-embedded] .hb-xe5-layer { position: absolute; height: auto; z-index: 2; padding: 10px; }\n.hb-xe5-scrim { position: absolute; inset: 0; background: radial-gradient(70% 70% at 50% 50%, rgba(0, 0, 0, 0.45), rgba(0, 0, 0, 0.78)); animation: hb-xe5-fade 0.25s ease both; }\n.hb-xe5-layer[data-state=\"closed\"] .hb-xe5-scrim { animation: hb-xe5-fade-out 0.2s ease both; }\n.hb-xe5-panel { position: relative; width: 100%; max-width: 380px; max-height: 100%; overflow: auto; padding: 18px; border: 1px solid #2b2925; border-radius: 18px; background: linear-gradient(180deg, #19181a, #121213); box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.05), 0 0 0 1px rgba(0, 0, 0, 0.5), 0 30px 70px -20px rgba(0, 0, 0, 0.9); outline: none; animation: hb-xe5-in 0.42s cubic-bezier(0.2, 0.9, 0.25, 1.15) both; }\n.hb-xe5-panel::before { content: \"\"; position: absolute; inset: 0 0 auto; height: 1px; background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--hb-xe5-tone) 70%, transparent), transparent); }\n.hb-xe5-layer[data-state=\"closed\"] .hb-xe5-panel { animation: hb-xe5-out 0.2s ease both; }\n.hb-xe5-panel[data-nudge=\"a\"] { animation: hb-xe5-nudge-a 0.4s cubic-bezier(0.3, 0.7, 0.4, 1); }\n.hb-xe5-panel[data-nudge=\"b\"] { animation: hb-xe5-nudge-b 0.4s cubic-bezier(0.3, 0.7, 0.4, 1); }\n.hb-xe5-top { display: flex; gap: 14px; align-items: center; }\n.hb-xe5-ring { position: relative; flex: none; width: 62px; height: 62px; }\n.hb-xe5-ring svg { width: 100%; height: 100%; transform: rotate(-90deg); overflow: visible; }\n.hb-xe5-track { stroke: #262528; }\n.hb-xe5-arc { stroke: var(--hb-xe5-tone); transition: stroke-dashoffset 1s linear, stroke 0.4s ease; filter: drop-shadow(0 0 6px color-mix(in srgb, var(--hb-xe5-tone) 55%, transparent)); }\n.hb-xe5-num { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--font-mono, ui-monospace, monospace); font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; letter-spacing: -0.02em; color: #f4f4f5; }\n.hb-xe5-halo { position: absolute; inset: -4px; border-radius: 50%; border: 1px solid var(--hb-xe5-tone); opacity: 0; }\n.hb-xe5-panel[data-urgent=\"true\"] .hb-xe5-halo { animation: hb-xe5-halo 1s cubic-bezier(0.2, 0.8, 0.3, 1) infinite; }\n.hb-xe5-lock { display: grid; place-items: center; width: 62px; height: 62px; flex: none; border-radius: 50%; background: radial-gradient(circle at 50% 30%, #2a2a2e, #18181a); box-shadow: inset 0 0 0 1px #2e2e33; color: #c4c4c8; animation: hb-xe5-pop 0.45s cubic-bezier(0.2, 0.9, 0.25, 1.3) both; }\n.hb-xe5-lock svg { width: 22px; height: 22px; }\n.hb-xe5-title { margin: 0; font-size: 15.5px; font-weight: 600; letter-spacing: -0.01em; line-height: 1.3; }\n.hb-xe5-desc { margin: 4px 0 0; color: #9f9fa5; font-size: 12.5px; line-height: 1.5; }\n.hb-xe5-desc b { color: #ededed; font-weight: 600; font-variant-numeric: tabular-nums; }\n.hb-xe5-note { display: flex; align-items: center; gap: 9px; margin-top: 14px; padding: 9px 11px; border-radius: 10px; background: #0f0f10; box-shadow: inset 0 0 0 1px #222224; color: #b4b4b9; font-size: 12px; }\n.hb-xe5-note svg { flex: none; width: 14px; height: 14px; color: #6fd39b; }\n.hb-xe5-foot { display: flex; gap: 8px; margin-top: 14px; }\n.hb-xe5-btn { flex: 1; display: inline-flex; align-items: center; justify-content: center; height: 36px; padding: 0 12px; border: 1px solid #2c2c30; border-radius: 10px; background: transparent; color: #d4d4d8; font: inherit; font-size: 13px; font-weight: 550; white-space: nowrap; cursor: pointer; transition: background-color 0.15s ease, transform 0.15s cubic-bezier(0.3, 0.7, 0.4, 1); }\n.hb-xe5-btn:hover { background: #1c1c1f; }\n.hb-xe5-btn:active { transform: scale(0.97); }\n.hb-xe5-btn[data-primary] { border-color: transparent; background: linear-gradient(180deg, #fafafa, #e4e4e7); color: #111; box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.12), 0 6px 16px -8px rgba(255, 255, 255, 0.3); }\n.hb-xe5-btn[data-primary]:hover { background: #fff; }\n@keyframes hb-xe5-fade { from { opacity: 0; } to { opacity: 1; } }\n@keyframes hb-xe5-fade-out { from { opacity: 1; } to { opacity: 0; } }\n@keyframes hb-xe5-in { from { opacity: 0; transform: translateY(10px) scale(0.96); } to { opacity: 1; transform: none; } }\n@keyframes hb-xe5-out { from { opacity: 1; transform: none; } to { opacity: 0; transform: scale(0.97); } }\n@keyframes hb-xe5-nudge-a { 0%, 100% { transform: none; } 40% { transform: scale(1.025); } }\n@keyframes hb-xe5-nudge-b { 0%, 100% { transform: none; } 40% { transform: scale(1.025); } }\n@keyframes hb-xe5-halo { from { opacity: 0.8; transform: scale(0.92); } to { opacity: 0; transform: scale(1.25); } }\n@keyframes hb-xe5-pop { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }\n@media (prefers-reduced-motion: reduce) {\n  .hb-xe5-scrim, .hb-xe5-panel, .hb-xe5-lock, .hb-xe5-layer[data-state=\"closed\"] .hb-xe5-panel, .hb-xe5-layer[data-state=\"closed\"] .hb-xe5-scrim, .hb-xe5-panel[data-nudge] { animation: none; }\n  .hb-xe5-panel[data-urgent=\"true\"] .hb-xe5-halo { animation: none; opacity: 0.5; }\n  .hb-xe5-layer[data-state=\"closed\"] { opacity: 0; }\n  .hb-xe5-arc, .hb-xe5-btn, .hb-xe5-trigger { transition: none; }\n}\n`;\n\nconst focusable =\n  'a[href],button:not(:disabled),input:not(:disabled),select:not(:disabled),textarea:not(:disabled),[tabindex]:not([tabindex=\"-1\"])';\n\nfunction useLayer(\n  open: boolean,\n  embedded: boolean,\n  panel: React.RefObject<HTMLElement | null>,\n  onClose: () => void,\n  userOpened: React.RefObject<boolean>,\n) {\n  const closeRef = React.useRef(onClose);\n  React.useEffect(() => {\n    closeRef.current = onClose;\n  });\n  React.useEffect(() => {\n    if (!open) return;\n    const node = panel.current;\n    const steal = !embedded || userOpened.current;\n    const previous = document.activeElement as HTMLElement | null;\n    const html = document.documentElement;\n    const overflow = html.style.overflow;\n    if (!embedded) html.style.overflow = \"hidden\";\n    if (steal && node) {\n      const target = node.querySelector<HTMLElement>(\"[data-autofocus]\") ?? node.querySelector<HTMLElement>(focusable) ?? node;\n      target.focus({ preventScroll: true });\n    }\n    const onKey = (e: KeyboardEvent) => {\n      if (!node) return;\n      if (embedded && !node.contains(document.activeElement)) return;\n      if (e.key === \"Escape\") {\n        e.preventDefault();\n        closeRef.current();\n        return;\n      }\n      if (e.key !== \"Tab\") return;\n      const items = Array.from(node.querySelectorAll<HTMLElement>(focusable)).filter((el) => el.getClientRects().length > 0);\n      if (!items.length) {\n        e.preventDefault();\n        node.focus();\n        return;\n      }\n      const first = items[0];\n      const last = items[items.length - 1];\n      const active = document.activeElement;\n      if (!node.contains(active)) {\n        e.preventDefault();\n        first.focus();\n      } else if (e.shiftKey && (active === first || active === node)) {\n        e.preventDefault();\n        last.focus();\n      } else if (!e.shiftKey && active === last) {\n        e.preventDefault();\n        first.focus();\n      }\n    };\n    document.addEventListener(\"keydown\", onKey);\n    return () => {\n      document.removeEventListener(\"keydown\", onKey);\n      if (!embedded) html.style.overflow = overflow;\n      if (steal && previous && previous.isConnected && previous !== document.body) previous.focus({ preventScroll: true });\n    };\n  }, [open, embedded, panel, userOpened]);\n}\n\nfunction clock(s: number) {\n  const v = Math.max(0, s);\n  return `${Math.floor(v / 60)}:${String(v % 60).padStart(2, \"0\")}`;\n}\n\nexport function DialogSessionAlert({\n  open,\n  defaultOpen,\n  onOpenChange,\n  embedded = false,\n  trigger = \"Preview timeout warning\",\n  seconds = 60,\n  app = \"Ledgerline\",\n  note = \"Your draft “Q3 board memo” is saved.\",\n  onExtend,\n  onSignOut,\n  onTimeout,\n  onSignIn,\n  accent = \"#f5a524\",\n  className = \"\",\n  style,\n  ...rest\n}: DialogSessionAlertProps) {\n  const [inner, setInner] = React.useState(defaultOpen ?? embedded);\n  const isOpen = open ?? inner;\n  const [present, setPresent] = React.useState(isOpen);\n  const [remaining, setRemaining] = React.useState(seconds);\n  const [nudge, setNudge] = React.useState<\"a\" | \"b\" | undefined>(undefined);\n  const userOpened = React.useRef(false);\n  const panel = React.useRef<HTMLDivElement>(null);\n  const id = React.useId();\n  const expired = remaining <= 0;\n\n  if (isOpen && !present) setPresent(true);\n\n  const setOpen = React.useCallback(\n    (next: boolean) => {\n      if (next) {\n        userOpened.current = true;\n        setRemaining(seconds);\n      }\n      if (open === undefined) setInner(next);\n      onOpenChange?.(next);\n    },\n    [open, onOpenChange, seconds],\n  );\n\n  const extend = React.useCallback(() => {\n    if (expired) return;\n    onExtend?.();\n    setOpen(false);\n  }, [expired, onExtend, setOpen]);\n\n  React.useEffect(() => {\n    if (isOpen || !present) return;\n    const t = setTimeout(() => setPresent(false), 220);\n    return () => clearTimeout(t);\n  }, [isOpen, present]);\n\n  React.useEffect(() => {\n    if (!isOpen || expired) return;\n    const t = setInterval(() => setRemaining((r) => r - 1), 1000);\n    return () => clearInterval(t);\n  }, [isOpen, expired]);\n\n  const timeoutRef = React.useRef(onTimeout);\n  React.useEffect(() => {\n    timeoutRef.current = onTimeout;\n  });\n  React.useEffect(() => {\n    if (isOpen && expired) timeoutRef.current?.();\n  }, [isOpen, expired]);\n\n  useLayer(isOpen, embedded, panel, expired ? () => setOpen(false) : extend, userOpened);\n\n  const tone = expired ? \"#71717a\" : remaining <= 10 ? \"#ff5a5f\" : accent;\n  const c = 2 * Math.PI * 27;\n  const offset = c * (1 - Math.max(remaining, 0) / Math.max(seconds, 1));\n  const vars = { \"--hb-xe5-accent\": accent, \"--hb-xe5-tone\": tone, ...style } as React.CSSProperties;\n\n  return (\n    <div className={`hb-xe5 ${className}`} data-embedded={embedded || undefined} style={vars} {...rest}>\n      <style href=\"hb-xe5-css\" precedence=\"default\">{css}</style>\n      {trigger !== null && (\n        <button type=\"button\" className=\"hb-xe5-trigger\" aria-haspopup=\"dialog\" aria-expanded={isOpen} onClick={() => setOpen(true)}>\n          <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.7\" strokeLinecap=\"round\" aria-hidden=\"true\">\n            <circle cx=\"8\" cy=\"8.5\" r=\"5.5\" />\n            <path d=\"M8 5.5v3l2 1.3M6.5 1.5h3\" />\n          </svg>\n          {trigger}\n        </button>\n      )}\n      {present && (\n        <div className=\"hb-xe5-layer\" data-state={isOpen ? \"open\" : \"closed\"}>\n          <div className=\"hb-xe5-scrim\" aria-hidden=\"true\" onClick={() => setNudge((n) => (n === \"a\" ? \"b\" : \"a\"))} />\n          <div\n            ref={panel}\n            role=\"alertdialog\"\n            aria-modal=\"true\"\n            aria-labelledby={`${id}-t`}\n            aria-describedby={`${id}-d`}\n            tabIndex={-1}\n            className=\"hb-xe5-panel\"\n            data-urgent={!expired && remaining <= 10 ? \"true\" : undefined}\n            data-nudge={nudge}\n          >\n            <div className=\"hb-xe5-top\">\n              {expired ? (\n                <span className=\"hb-xe5-lock\" aria-hidden=\"true\">\n                  <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                    <rect x=\"5\" y=\"10.5\" width=\"14\" height=\"10\" rx=\"2.5\" />\n                    <path d=\"M8 10.5V8a4 4 0 0 1 8 0v2.5\" />\n                  </svg>\n                </span>\n              ) : (\n                <span className=\"hb-xe5-ring\" aria-hidden=\"true\">\n                  <span className=\"hb-xe5-halo\" />\n                  <svg viewBox=\"0 0 62 62\" fill=\"none\">\n                    <circle className=\"hb-xe5-track\" cx=\"31\" cy=\"31\" r=\"27\" strokeWidth=\"4\" />\n                    <circle\n                      className=\"hb-xe5-arc\"\n                      cx=\"31\"\n                      cy=\"31\"\n                      r=\"27\"\n                      strokeWidth=\"4\"\n                      strokeLinecap=\"round\"\n                      strokeDasharray={c.toFixed(2)}\n                      strokeDashoffset={offset.toFixed(2)}\n                    />\n                  </svg>\n                  <span className=\"hb-xe5-num\">{clock(remaining)}</span>\n                </span>\n              )}\n              <div style={{ minWidth: 0 }}>\n                <h2 id={`${id}-t`} className=\"hb-xe5-title\">\n                  {expired ? \"You have been signed out\" : \"Your session is about to expire\"}\n                </h2>\n                <p id={`${id}-d`} className=\"hb-xe5-desc\">\n                  {expired ? (\n                    <>For your security we closed your {app} session.</>\n                  ) : (\n                    <>\n                      We will sign you out of {app} in <b>{clock(remaining)}</b> unless you stay.\n                    </>\n                  )}\n                </p>\n              </div>\n            </div>\n            {note && (\n              <div className=\"hb-xe5-note\">\n                <svg viewBox=\"0 0 16 16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\">\n                  <path d=\"m3.5 8.4 3 3 6-6.4\" />\n                </svg>\n                {note}\n              </div>\n            )}\n            <div className=\"hb-xe5-foot\">\n              {expired ? (\n                <button\n                  type=\"button\"\n                  className=\"hb-xe5-btn\"\n                  data-primary=\"\"\n                  data-autofocus=\"\"\n                  onClick={() => {\n                    onSignIn?.();\n                    setRemaining(seconds);\n                  }}\n                >\n                  Sign in again\n                </button>\n              ) : (\n                <>\n                  <button\n                    type=\"button\"\n                    className=\"hb-xe5-btn\"\n                    onClick={() => {\n                      onSignOut?.();\n                      setRemaining(0);\n                    }}\n                  >\n                    Sign out now\n                  </button>\n                  <button type=\"button\" className=\"hb-xe5-btn\" data-primary=\"\" data-autofocus=\"\" onClick={extend}>\n                    Stay signed in\n                  </button>\n                </>\n              )}\n            </div>\n            <span style={{ position: \"absolute\", width: 1, height: 1, overflow: \"hidden\", clipPath: \"inset(50%)\" }} aria-live=\"assertive\">\n              {expired ? \"Signed out\" : remaining === 30 || remaining === 10 ? `${remaining} seconds left` : \"\"}\n            </span>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}