{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "install-app-banner",
  "type": "registry:component",
  "title": "Install App Banner",
  "description": "An install invite for web apps: an Install button wired to the browser prompt, manual Share then Add to Home Screen steps on iPhone, and a remembered snooze.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "ordering",
    "pwa",
    "install",
    "banner",
    "mobile",
    "ios",
    "app"
  ],
  "docs": "https://hyperblur.dev/effects/install-app-banner",
  "files": [
    {
      "path": "registry/hyperblur/install-app-banner.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/install-app-banner.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport type InstallOutcome = \"accepted\" | \"dismissed\" | \"unavailable\";\n\nexport interface InstallAppLabels {\n  region: string;\n  install: string;\n  notNow: string;\n  close: string;\n  iosIntro: string;\n  iosTap: string;\n  iosShare: string;\n  iosToolbar: string;\n  iosChoose: string;\n  iosAdd: string;\n  gotIt: string;\n  installed: string;\n}\n\nexport interface InstallAppBannerProps extends React.HTMLAttributes<HTMLDivElement> {\n  appName?: string;\n  meta?: string;\n  description?: string;\n  benefits?: string[];\n  icon?: React.ReactNode;\n  snoozeDays?: number;\n  storageKey?: string;\n  delay?: number;\n  forceVisible?: boolean;\n  mode?: \"auto\" | \"prompt\" | \"ios\";\n  placement?: \"fixed\" | \"inline\";\n  appearance?: \"dark\" | \"light\";\n  labels?: Partial<InstallAppLabels>;\n  onInstall?: (outcome: InstallOutcome) => void;\n  onDismiss?: () => void;\n  accent?: string;\n}\n\ninterface InstallPromptEvent extends Event {\n  prompt: () => Promise<void>;\n  userChoice: Promise<{ outcome: \"accepted\" | \"dismissed\" }>;\n}\n\nconst defaultLabels: InstallAppLabels = {\n  region: \"Install the app\",\n  install: \"Install\",\n  notNow: \"Not now\",\n  close: \"Dismiss\",\n  iosIntro: \"Add it to your iPhone in two steps:\",\n  iosTap: \"Tap\",\n  iosShare: \"Share\",\n  iosToolbar: \"in the browser bar\",\n  iosChoose: \"Choose\",\n  iosAdd: \"Add to Home Screen\",\n  gotIt: \"Got it\",\n  installed: \"Added to your home screen\",\n};\n\nconst css = `\n.hb-oc3 {\n  --hb-oc3-accent: #2f7bff;\n  --hb-oc3-bg: #121212;\n  --hb-oc3-line: #262626;\n  --hb-oc3-text: #ededed;\n  --hb-oc3-muted: #a1a1a1;\n  --hb-oc3-soft: #1b1b1b;\n  box-sizing: border-box;\n  color: var(--hb-oc3-text);\n  font-family: inherit;\n}\n.hb-oc3 *, .hb-oc3 *::before, .hb-oc3 *::after { box-sizing: border-box; }\n.hb-oc3[data-appearance=\"light\"] {\n  --hb-oc3-bg: #ffffff;\n  --hb-oc3-line: #e7e4dd;\n  --hb-oc3-text: #121622;\n  --hb-oc3-muted: #5f6470;\n  --hb-oc3-soft: #f4f2ed;\n}\n.hb-oc3[data-placement=\"inline\"] { position: relative; width: 100%; max-width: 400px; }\n.hb-oc3[data-placement=\"fixed\"] {\n  position: fixed;\n  right: 0;\n  bottom: 0;\n  left: 0;\n  z-index: 60;\n}\n@media (min-width: 640px) {\n  .hb-oc3[data-placement=\"fixed\"] { right: 20px; bottom: 20px; left: auto; width: 384px; }\n}\n.hb-oc3-card {\n  container-type: inline-size;\n  position: relative;\n  padding: 14px;\n  border: 1px solid var(--hb-oc3-line);\n  border-radius: 18px;\n  background: var(--hb-oc3-bg);\n  box-shadow: 0 24px 48px -20px rgba(0, 0, 0, 0.55), 0 0 0 1px rgba(255, 255, 255, 0.02) inset;\n  animation: hb-oc3-up 0.5s cubic-bezier(0.2, 0.9, 0.25, 1) both;\n}\n.hb-oc3[data-placement=\"fixed\"] .hb-oc3-card {\n  padding-bottom: calc(14px + env(safe-area-inset-bottom, 0px));\n  border-bottom-width: 0;\n  border-radius: 20px 20px 0 0;\n}\n@media (min-width: 640px) {\n  .hb-oc3[data-placement=\"fixed\"] .hb-oc3-card { padding-bottom: 14px; border-bottom-width: 1px; border-radius: 18px; }\n}\n.hb-oc3[data-leaving=\"true\"] .hb-oc3-card { animation: hb-oc3-down 0.26s ease-in both; }\n@keyframes hb-oc3-up {\n  from { opacity: 0; transform: translateY(26px); }\n  to { opacity: 1; transform: none; }\n}\n@keyframes hb-oc3-down {\n  to { opacity: 0; transform: translateY(26px); }\n}\n.hb-oc3-x {\n  position: absolute;\n  top: 10px;\n  right: 10px;\n  display: grid;\n  place-items: center;\n  width: 28px;\n  height: 28px;\n  margin: 0;\n  padding: 0;\n  border: 0;\n  border-radius: 50%;\n  background: transparent;\n  color: var(--hb-oc3-muted);\n  cursor: pointer;\n  transition: background-color 0.16s ease, color 0.16s ease;\n}\n.hb-oc3-x:hover { background: var(--hb-oc3-soft); color: var(--hb-oc3-text); }\n.hb-oc3-x svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; }\n.hb-oc3-top { display: flex; align-items: center; gap: 12px; padding-right: 30px; }\n.hb-oc3-icon {\n  display: grid;\n  flex: none;\n  place-items: center;\n  width: 44px;\n  height: 44px;\n  overflow: hidden;\n  border-radius: 12px;\n  box-shadow: 0 6px 16px -6px color-mix(in srgb, var(--hb-oc3-accent) 70%, transparent);\n  animation: hb-oc3-pop 0.7s 0.18s cubic-bezier(0.3, 1.6, 0.5, 1) both;\n}\n.hb-oc3-icon > svg { width: 100%; height: 100%; display: block; }\n@keyframes hb-oc3-pop {\n  from { transform: scale(0.6) rotate(-8deg); opacity: 0; }\n  to { transform: none; opacity: 1; }\n}\n.hb-oc3-name { display: flex; flex-direction: column; min-width: 0; }\n.hb-oc3-name strong { overflow: hidden; font-size: 15px; font-weight: 600; letter-spacing: -0.01em; white-space: nowrap; text-overflow: ellipsis; }\n.hb-oc3-name span { overflow: hidden; color: var(--hb-oc3-muted); font-size: 12px; white-space: nowrap; text-overflow: ellipsis; }\n.hb-oc3-desc { margin: 10px 0 0; color: var(--hb-oc3-muted); font-size: 13px; line-height: 1.45; }\n.hb-oc3-list { display: flex; flex-wrap: wrap; gap: 4px 14px; margin: 9px 0 0; padding: 0; list-style: none; }\n.hb-oc3-list li { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; white-space: nowrap; }\n.hb-oc3-list svg { width: 14px; height: 14px; flex: none; fill: none; stroke: var(--hb-oc3-accent); stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc3-actions { display: flex; gap: 8px; margin-top: 12px; }\n.hb-oc3-btn {\n  display: inline-flex;\n  flex: 1 1 0;\n  align-items: center;\n  justify-content: center;\n  gap: 7px;\n  height: 36px;\n  margin: 0;\n  padding: 0 14px;\n  border: 1px solid var(--hb-oc3-line);\n  border-radius: 999px;\n  background: transparent;\n  color: var(--hb-oc3-text);\n  font: inherit;\n  font-size: 13px;\n  font-weight: 500;\n  white-space: nowrap;\n  cursor: pointer;\n  transition: background-color 0.16s ease, filter 0.16s ease, transform 0.12s ease;\n}\n.hb-oc3-btn:hover { background: var(--hb-oc3-soft); }\n.hb-oc3-btn[data-primary=\"true\"] {\n  position: relative;\n  overflow: hidden;\n  border-color: transparent;\n  background: var(--hb-oc3-accent);\n  color: #ffffff;\n}\n.hb-oc3-btn[data-primary=\"true\"]::after {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.35) 50%, transparent 65%);\n  transform: translateX(-120%);\n  animation: hb-oc3-shine 3.4s 1s ease-in-out infinite;\n}\n@keyframes hb-oc3-shine {\n  0%, 60% { transform: translateX(-120%); }\n  85%, 100% { transform: translateX(120%); }\n}\n.hb-oc3-btn[data-primary=\"true\"]:hover { filter: brightness(1.1); }\n.hb-oc3-btn:active { transform: scale(0.97); }\n.hb-oc3-btn svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc3-x:focus-visible, .hb-oc3-btn:focus-visible { outline: 2px solid var(--hb-oc3-accent); outline-offset: 2px; }\n.hb-oc3-steps { display: flex; flex-direction: column; gap: 7px; margin: 10px 0 0; padding: 0; list-style: none; font-size: 13px; }\n.hb-oc3-steps li { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }\n.hb-oc3-n {\n  display: grid;\n  place-items: center;\n  width: 20px;\n  height: 20px;\n  border-radius: 50%;\n  background: var(--hb-oc3-soft);\n  color: var(--hb-oc3-muted);\n  font-size: 11px;\n  font-weight: 600;\n}\n.hb-oc3-key {\n  display: inline-flex;\n  align-items: center;\n  gap: 5px;\n  height: 24px;\n  padding: 0 8px;\n  border: 1px solid var(--hb-oc3-line);\n  border-radius: 7px;\n  background: var(--hb-oc3-soft);\n  font-weight: 500;\n}\n.hb-oc3-key svg { width: 14px; height: 14px; fill: none; stroke: var(--hb-oc3-accent); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }\n.hb-oc3-steps em { color: var(--hb-oc3-muted); font-style: normal; }\n.hb-oc3-done {\n  display: flex;\n  align-items: center;\n  gap: 8px;\n  margin-top: 12px;\n  height: 36px;\n  padding: 0 12px;\n  border-radius: 999px;\n  background: color-mix(in srgb, #3ccf91 14%, transparent);\n  color: #3ccf91;\n  font-size: 13px;\n  font-weight: 500;\n  animation: hb-oc3-up 0.35s ease both;\n}\n.hb-oc3-done svg { width: 16px; height: 16px; fill: none; stroke: currentColor; stroke-width: 2.4; stroke-linecap: round; stroke-linejoin: round; }\n@container (max-width: 290px) {\n  .hb-oc3-actions { flex-direction: column; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-oc3 *, .hb-oc3 *::before, .hb-oc3 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction writeSnooze(key: string, until: number) {\n  try {\n    window.localStorage.setItem(key, String(until));\n    return true;\n  } catch {\n    return false;\n  }\n}\n\nfunction DefaultIcon({ accent }: { accent: string }) {\n  const id = React.useId().replace(/:/g, \"\");\n  return (\n    <svg viewBox=\"0 0 48 48\" aria-hidden=\"true\">\n      <defs>\n        <linearGradient id={`${id}g`} x1=\"0\" y1=\"0\" x2=\"1\" y2=\"1\">\n          <stop offset=\"0\" stopColor={accent} />\n          <stop offset=\"1\" stopColor=\"#0b1f4d\" />\n        </linearGradient>\n      </defs>\n      <rect width=\"48\" height=\"48\" fill={`url(#${id}g)`} />\n      <path d=\"M17 13c0 2 2 2 2 4M24 11c0 2 2 2 2 4M31 13c0 2 2 2 2 4\" fill=\"none\" stroke=\"#ffffff\" strokeOpacity=\"0.75\" strokeWidth=\"1.8\" strokeLinecap=\"round\" />\n      <path d=\"M10 23h28a14 14 0 0 1-28 0z\" fill=\"#ffffff\" />\n      <path d=\"M13 23h22\" stroke={accent} strokeWidth=\"2\" strokeLinecap=\"round\" />\n      <rect x=\"18\" y=\"36\" width=\"12\" height=\"3\" rx=\"1.5\" fill=\"#ffffff\" fillOpacity=\"0.85\" />\n    </svg>\n  );\n}\n\nexport function InstallAppBanner({\n  appName = \"Corner Kitchen\",\n  meta = \"Free · Installs in seconds\",\n  description = \"Reorder in two taps and track every delivery.\",\n  benefits = [\"Live order tracking\", \"Works offline\"],\n  icon,\n  snoozeDays = 7,\n  storageKey = \"install-banner-snooze\",\n  delay = 1200,\n  forceVisible = false,\n  mode = \"auto\",\n  placement = \"fixed\",\n  appearance = \"dark\",\n  labels,\n  onInstall,\n  onDismiss,\n  accent = \"#2f7bff\",\n  className,\n  style,\n  onKeyDown,\n  ...rest\n}: InstallAppBannerProps) {\n  const t = { ...defaultLabels, ...labels };\n  const [visible, setVisible] = React.useState(false);\n  const [kind, setKind] = React.useState<\"prompt\" | \"ios\">(\"prompt\");\n  const [phase, setPhase] = React.useState<\"idle\" | \"done\">(\"idle\");\n  const [leaving, setLeaving] = React.useState(false);\n  const [paused, setPaused] = React.useState(false);\n  const deferred = React.useRef<InstallPromptEvent | null>(null);\n  const timers = React.useRef<number[]>([]);\n\n  const later = React.useCallback((fn: () => void, ms: number) => {\n    timers.current.push(window.setTimeout(fn, ms));\n  }, []);\n\n  React.useEffect(() => {\n    const list = timers.current;\n    return () => list.forEach((id) => window.clearTimeout(id));\n  }, []);\n\n  React.useEffect(() => {\n    if (forceVisible || typeof window === \"undefined\") return;\n    const nav = navigator as Navigator & { standalone?: boolean };\n    const standalone = window.matchMedia?.(\"(display-mode: standalone)\").matches || nav.standalone === true;\n    if (standalone) return;\n    let snoozed = false;\n    try {\n      const until = Number(window.localStorage.getItem(storageKey));\n      snoozed = Number.isFinite(until) && until > Date.now();\n    } catch {\n      snoozed = false;\n    }\n    if (snoozed) return;\n    let timer = 0;\n    const onPrompt = (event: Event) => {\n      event.preventDefault();\n      deferred.current = event as InstallPromptEvent;\n      window.clearTimeout(timer);\n      timer = window.setTimeout(() => {\n        setKind(\"prompt\");\n        setVisible(true);\n      }, delay);\n    };\n    const onInstalled = () => {\n      deferred.current = null;\n      setVisible(false);\n    };\n    window.addEventListener(\"beforeinstallprompt\", onPrompt);\n    window.addEventListener(\"appinstalled\", onInstalled);\n    const ua = nav.userAgent;\n    const ios = /iphone|ipad|ipod/i.test(ua) || (nav.platform === \"MacIntel\" && nav.maxTouchPoints > 1);\n    const safari = /safari/i.test(ua) && !/crios|fxios|edgios|android/i.test(ua);\n    if (ios && safari && mode !== \"prompt\") {\n      timer = window.setTimeout(() => {\n        setKind(\"ios\");\n        setVisible(true);\n      }, delay);\n    }\n    return () => {\n      window.clearTimeout(timer);\n      window.removeEventListener(\"beforeinstallprompt\", onPrompt);\n      window.removeEventListener(\"appinstalled\", onInstalled);\n    };\n  }, [forceVisible, storageKey, delay, mode]);\n\n  const shownKind = mode === \"auto\" ? kind : mode;\n  const shown = forceVisible ? !paused : visible;\n\n  const close = (snooze: boolean) => {\n    if (snooze && !forceVisible) writeSnooze(storageKey, Date.now() + snoozeDays * 86400000);\n    setLeaving(true);\n    later(() => {\n      setLeaving(false);\n      setPhase(\"idle\");\n      if (forceVisible) {\n        setPaused(true);\n        later(() => setPaused(false), 1600);\n      } else setVisible(false);\n    }, 260);\n  };\n\n  const dismiss = () => {\n    onDismiss?.();\n    close(true);\n  };\n\n  const install = async () => {\n    const event = deferred.current;\n    if (!event) {\n      onInstall?.(\"unavailable\");\n      if (forceVisible) {\n        setPhase(\"done\");\n        later(() => close(false), 2200);\n      }\n      return;\n    }\n    try {\n      await event.prompt();\n      const choice = await event.userChoice;\n      deferred.current = null;\n      onInstall?.(choice.outcome);\n      if (choice.outcome === \"accepted\") {\n        setPhase(\"done\");\n        later(() => close(false), 2200);\n      } else close(true);\n    } catch {\n      onInstall?.(\"unavailable\");\n    }\n  };\n\n  if (!shown) return null;\n\n  return (\n    <div\n      className={[\"hb-oc3\", className].filter(Boolean).join(\" \")}\n      role=\"region\"\n      aria-label={t.region}\n      data-placement={placement}\n      data-appearance={appearance}\n      data-leaving={leaving ? \"true\" : undefined}\n      style={{ \"--hb-oc3-accent\": accent, ...style } as React.CSSProperties}\n      onKeyDown={(e) => {\n        onKeyDown?.(e);\n        if (e.key === \"Escape\") dismiss();\n      }}\n      {...rest}\n    >\n      <style href=\"hb-install-app-banner\" precedence=\"default\">{css}</style>\n      <div className=\"hb-oc3-card\">\n        <button type=\"button\" className=\"hb-oc3-x\" aria-label={t.close} onClick={dismiss}>\n          <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n            <path d=\"M6 6l12 12M18 6 6 18\" />\n          </svg>\n        </button>\n        <div className=\"hb-oc3-top\">\n          <span className=\"hb-oc3-icon\">{icon ?? <DefaultIcon accent={accent} />}</span>\n          <span className=\"hb-oc3-name\">\n            <strong>{appName}</strong>\n            {meta && <span>{meta}</span>}\n          </span>\n        </div>\n        {shownKind === \"ios\" ? (\n          <>\n            <p className=\"hb-oc3-desc\">{t.iosIntro}</p>\n            <ol className=\"hb-oc3-steps\">\n              <li>\n                <span className=\"hb-oc3-n\">1</span>\n                {t.iosTap}\n                <span className=\"hb-oc3-key\">\n                  <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                    <path d=\"M12 3v12M8 7l4-4 4 4M7 11H5v10h14V11h-2\" />\n                  </svg>\n                  {t.iosShare}\n                </span>\n                <em>{t.iosToolbar}</em>\n              </li>\n              <li>\n                <span className=\"hb-oc3-n\">2</span>\n                {t.iosChoose}\n                <span className=\"hb-oc3-key\">\n                  <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                    <rect x=\"4\" y=\"4\" width=\"16\" height=\"16\" rx=\"4\" />\n                    <path d=\"M12 8.5v7M8.5 12h7\" />\n                  </svg>\n                  {t.iosAdd}\n                </span>\n              </li>\n            </ol>\n            <div className=\"hb-oc3-actions\">\n              <button type=\"button\" className=\"hb-oc3-btn\" onClick={dismiss}>\n                {t.gotIt}\n              </button>\n            </div>\n          </>\n        ) : (\n          <>\n            {description && <p className=\"hb-oc3-desc\">{description}</p>}\n            {benefits.length > 0 && (\n              <ul className=\"hb-oc3-list\">\n                {benefits.map((b) => (\n                  <li key={b}>\n                    <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                      <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n                    </svg>\n                    {b}\n                  </li>\n                ))}\n              </ul>\n            )}\n            {phase === \"done\" ? (\n              <div className=\"hb-oc3-done\" role=\"status\">\n                <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                  <path d=\"M5 12.5l4.5 4.5L19 7.5\" />\n                </svg>\n                {t.installed}\n              </div>\n            ) : (\n              <div className=\"hb-oc3-actions\">\n                <button type=\"button\" className=\"hb-oc3-btn\" onClick={dismiss}>\n                  {t.notNow}\n                </button>\n                <button type=\"button\" className=\"hb-oc3-btn\" data-primary=\"true\" onClick={() => void install()}>\n                  <svg viewBox=\"0 0 24 24\" aria-hidden=\"true\">\n                    <path d=\"M12 4v11M7.5 10.5 12 15l4.5-4.5M5 19h14\" />\n                  </svg>\n                  {t.install}\n                </button>\n              </div>\n            )}\n          </>\n        )}\n      </div>\n    </div>\n  );\n}\n"
    }
  ]
}