{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "popup-cookie-preferences",
  "type": "registry:component",
  "title": "Cookie Preferences",
  "description": "A cookie consent card or bottom bar with a segmented dial that counts the enabled categories, a Customize panel that expands in place with switches and vendor lists, and a small launcher with a receipt id after saving.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "modals",
    "cookies",
    "consent",
    "gdpr",
    "preferences",
    "banner",
    "switch"
  ],
  "docs": "https://hyperblur.dev/effects/popup-cookie-preferences",
  "files": [
    {
      "path": "registry/hyperblur/popup-cookie-preferences.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/popup-cookie-preferences.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface PopupCookieVendor {\n  name: string;\n  duration: string;\n}\n\nexport interface PopupCookieCategory {\n  id: string;\n  label: string;\n  description: string;\n  required?: boolean;\n  defaultEnabled?: boolean;\n  vendors?: PopupCookieVendor[];\n}\n\nexport interface PopupCookiePreferencesProps extends Omit<React.HTMLAttributes<HTMLDivElement>, \"title\"> {\n  categories?: PopupCookieCategory[];\n  layout?: \"card\" | \"bar\";\n  title?: string;\n  description?: string;\n  policyHref?: string;\n  defaultOpen?: boolean;\n  onConsent?: (choices: Record<string, boolean>) => void;\n  embedded?: boolean;\n  accent?: string;\n}\n\nconst defaultCategories: PopupCookieCategory[] = [\n  {\n    id: \"necessary\",\n    label: \"Strictly necessary\",\n    description: \"Sign-in, checkout and security. The site does not work without these.\",\n    required: true,\n    vendors: [\n      { name: \"Session\", duration: \"Session\" },\n      { name: \"CSRF token\", duration: \"Session\" },\n    ],\n  },\n  {\n    id: \"functional\",\n    label: \"Preferences\",\n    description: \"Remember your language, currency and recently viewed items.\",\n    defaultEnabled: true,\n    vendors: [{ name: \"Locale\", duration: \"1 year\" }],\n  },\n  {\n    id: \"analytics\",\n    label: \"Analytics\",\n    description: \"Anonymous page views that tell us which features people actually use.\",\n    vendors: [\n      { name: \"Plausible\", duration: \"None\" },\n      { name: \"Hotjar\", duration: \"1 year\" },\n    ],\n  },\n  {\n    id: \"marketing\",\n    label: \"Marketing\",\n    description: \"Measure ad campaigns and show you relevant offers on other sites.\",\n    vendors: [\n      { name: \"Meta Pixel\", duration: \"3 months\" },\n      { name: \"Google Ads\", duration: \"13 months\" },\n    ],\n  },\n];\n\nfunction refId(text: string) {\n  let x = 2166136261;\n  for (let i = 0; i < text.length; i++) x = Math.imul(x ^ text.charCodeAt(i), 16777619);\n  const a = (x >>> 0).toString(16).toUpperCase().padStart(8, \"0\");\n  return `${a.slice(0, 4)}-${a.slice(4)}`;\n}\n\nconst css = `\n.hb-xf4 { --hb-xf4-accent: #c08a4a; box-sizing: border-box; font-family: inherit; color: #ededed; }\n.hb-xf4 *, .hb-xf4 *::before, .hb-xf4 *::after { box-sizing: border-box; }\n.hb-xf4-dock { position: fixed; z-index: 900; left: 16px; bottom: 16px; width: min(392px, calc(100vw - 32px)); }\n.hb-xf4[data-layout=\"bar\"] .hb-xf4-dock { left: 16px; right: 16px; width: auto; max-width: 980px; margin: 0 auto; }\n.hb-xf4-embedded .hb-xf4-dock { position: relative; left: auto; right: auto; bottom: auto; width: 100%; max-width: none; }\n.hb-xf4-card { position: relative; border-radius: 20px; background: linear-gradient(180deg, #171717, #111 45%); border: 1px solid #2a2a2a; box-shadow: inset 0 1px 0 rgba(255,255,255,.06), 0 30px 60px -24px rgba(0,0,0,.85); overflow: hidden; animation: hb-xf4-rise .5s cubic-bezier(.16,1,.3,1) both; }\n.hb-xf4-main { display: grid; grid-template-columns: auto 1fr; gap: 14px; padding: 16px 16px 14px; align-items: start; }\n.hb-xf4[data-layout=\"bar\"] .hb-xf4-main { grid-template-columns: auto 1fr auto; align-items: center; }\n.hb-xf4-dial { position: relative; width: 44px; height: 44px; flex: none; }\n.hb-xf4-dial svg { width: 100%; height: 100%; transform: rotate(-90deg); }\n.hb-xf4-arc { fill: none; stroke-width: 4; stroke-linecap: round; transition: stroke .35s cubic-bezier(.3,.7,.4,1), opacity .35s; }\n.hb-xf4-dial b { position: absolute; inset: 0; display: grid; place-items: center; font-size: 11px; font-weight: 600; font-variant-numeric: tabular-nums; color: #ededed; }\n.hb-xf4-title { margin: 0; font-size: 14px; font-weight: 600; letter-spacing: -.01em; }\n.hb-xf4-desc { margin: 4px 0 0; font-size: 12.5px; line-height: 1.5; color: #a1a1a1; }\n.hb-xf4-desc a { color: #ededed; text-decoration: underline; text-decoration-color: #555; text-underline-offset: 2px; }\n.hb-xf4-desc a:focus-visible { outline: 2px solid var(--hb-xf4-accent); outline-offset: 2px; border-radius: 2px; }\n.hb-xf4-actions { display: flex; gap: 6px; padding: 0 16px 16px; flex-wrap: wrap; }\n.hb-xf4[data-layout=\"bar\"] .hb-xf4-actions { padding: 0; flex-wrap: nowrap; }\n.hb-xf4-btn { all: unset; box-sizing: border-box; flex: 1 1 auto; display: inline-flex; align-items: center; justify-content: center; gap: 6px; height: 34px; padding: 0 14px; border-radius: 10px; font-size: 12.5px; font-weight: 600; white-space: nowrap; cursor: pointer; transition: background .2s, border-color .2s, transform .15s cubic-bezier(.3,.7,.4,1), color .2s; }\n.hb-xf4-btn:active { transform: scale(.97); }\n.hb-xf4-btn:focus-visible { outline: 2px solid var(--hb-xf4-accent); outline-offset: 2px; }\n.hb-xf4-primary { color: #0a0a0a; background: linear-gradient(#f4f4f4, #dcdcdc); box-shadow: inset 0 -1px 0 rgba(0,0,0,.18); }\n.hb-xf4-primary:hover { background: #fff; }\n.hb-xf4-quiet { color: #ededed; background: #1a1a1a; border: 1px solid #2c2c2c; }\n.hb-xf4-quiet:hover { border-color: #3c3c3c; background: #1e1e1e; }\n.hb-xf4-link { flex: 0 0 auto; color: #a1a1a1; padding: 0 8px; }\n.hb-xf4-link:hover { color: #ededed; }\n.hb-xf4-link svg { width: 12px; height: 12px; transition: transform .3s cubic-bezier(.3,.7,.4,1); }\n.hb-xf4-link[aria-expanded=\"true\"] svg { transform: rotate(180deg); }\n.hb-xf4-prefs { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .45s cubic-bezier(.16,1,.3,1); }\n.hb-xf4-prefs[data-open=\"true\"] { grid-template-rows: 1fr; }\n.hb-xf4-prefs > div { overflow: hidden; min-height: 0; }\n.hb-xf4-list { list-style: none; margin: 0; padding: 0 10px 6px; display: grid; gap: 4px; max-height: min(48dvh, 320px); overflow: auto; }\n.hb-xf4-row { border-radius: 12px; background: #141414; border: 1px solid #222; transition: border-color .25s; }\n.hb-xf4-row[data-on=\"true\"] { border-color: color-mix(in srgb, var(--hb-xf4-accent) 30%, #222); }\n.hb-xf4-rowhead { display: flex; align-items: center; gap: 10px; padding: 10px 10px 10px 12px; }\n.hb-xf4-rowtext { flex: 1; min-width: 0; }\n.hb-xf4-rowlabel { display: flex; align-items: center; gap: 6px; margin: 0; font-size: 12.5px; font-weight: 600; }\n.hb-xf4-count { font-size: 10.5px; font-weight: 500; color: #8f8f8f; padding: 1px 6px; border-radius: 999px; background: #1d1d1d; border: 1px solid #2a2a2a; }\n.hb-xf4-rowdesc { margin: 3px 0 0; font-size: 11.5px; line-height: 1.45; color: #8f8f8f; }\n.hb-xf4-more { all: unset; box-sizing: border-box; margin-top: 4px; font-size: 11px; color: color-mix(in srgb, var(--hb-xf4-accent) 75%, #fff); cursor: pointer; }\n.hb-xf4-more:focus-visible { outline: 2px solid var(--hb-xf4-accent); outline-offset: 2px; border-radius: 3px; }\n.hb-xf4-vendors { display: grid; gap: 2px; margin: 6px 0 0; padding: 0; list-style: none; animation: hb-xf4-fade .3s ease both; }\n.hb-xf4-vendors li { display: flex; justify-content: space-between; font-size: 11px; color: #a1a1a1; padding: 4px 8px; border-radius: 6px; background: #101010; }\n.hb-xf4-vendors span:last-child { font-family: var(--font-mono), ui-monospace, monospace; font-size: 10.5px; color: #7a7a7a; }\n.hb-xf4-switch { all: unset; box-sizing: border-box; position: relative; width: 38px; height: 22px; border-radius: 999px; flex: none; background: #262626; box-shadow: inset 0 1px 2px rgba(0,0,0,.6); cursor: pointer; transition: background .3s cubic-bezier(.3,.7,.4,1); }\n.hb-xf4-switch::after { content: \"\"; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: linear-gradient(#fff, #d8d8d8); box-shadow: 0 2px 4px rgba(0,0,0,.4); transition: transform .35s cubic-bezier(.3,1.4,.5,1), width .2s; }\n.hb-xf4-switch:active::after { width: 20px; }\n.hb-xf4-switch[aria-checked=\"true\"] { background: var(--hb-xf4-accent); }\n.hb-xf4-switch[aria-checked=\"true\"]::after { transform: translateX(16px); }\n.hb-xf4-switch[aria-checked=\"true\"]:active::after { transform: translateX(12px); }\n.hb-xf4-switch:focus-visible { outline: 2px solid var(--hb-xf4-accent); outline-offset: 2px; }\n.hb-xf4-switch[aria-disabled=\"true\"] { cursor: not-allowed; opacity: .55; }\n.hb-xf4-lock { display: grid; place-items: center; width: 22px; height: 22px; color: #6f6f6f; }\n.hb-xf4-lock svg { width: 13px; height: 13px; }\n.hb-xf4-save { display: flex; gap: 6px; padding: 8px 10px 12px; }\n.hb-xf4-launch { all: unset; box-sizing: border-box; position: fixed; z-index: 900; left: 16px; bottom: 16px; display: inline-flex; align-items: center; gap: 8px; height: 40px; padding: 0 14px 0 6px; border-radius: 999px; background: #151515; border: 1px solid #2a2a2a; color: #ededed; font-size: 12px; box-shadow: 0 14px 30px -14px rgba(0,0,0,.8); cursor: pointer; animation: hb-xf4-rise .45s cubic-bezier(.16,1,.3,1) both; transition: border-color .2s; }\n.hb-xf4-embedded .hb-xf4-launch { position: relative; left: auto; bottom: auto; }\n.hb-xf4-launch:hover { border-color: #3a3a3a; }\n.hb-xf4-launch:focus-visible { outline: 2px solid var(--hb-xf4-accent); outline-offset: 2px; }\n.hb-xf4-launch .hb-xf4-dial { width: 28px; height: 28px; }\n.hb-xf4-launch .hb-xf4-dial b { font-size: 9px; }\n.hb-xf4-launch small { font-family: var(--font-mono), ui-monospace, monospace; font-size: 10.5px; color: #7a7a7a; }\n.hb-xf4-embedded { display: grid; place-items: center; width: 100%; }\n@keyframes hb-xf4-rise { from { opacity: 0; transform: translateY(16px) scale(.98); } }\n@keyframes hb-xf4-fade { from { opacity: 0; transform: translateY(-3px); } }\n@media (max-width: 560px) {\n  .hb-xf4[data-layout=\"bar\"] .hb-xf4-main { grid-template-columns: auto 1fr; }\n  .hb-xf4[data-layout=\"bar\"] .hb-xf4-actions { grid-column: 1 / -1; flex-wrap: wrap; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-xf4 *, .hb-xf4 *::after { animation: none !important; transition: none !important; }\n}\n`;\n\nfunction Dial({ categories, choices }: { categories: PopupCookieCategory[]; choices: Record<string, boolean> }) {\n  const n = categories.length || 1;\n  const r = 18;\n  const c = 2 * Math.PI * r;\n  const gap = 5;\n  const seg = c / n - gap;\n  const on = categories.filter((x) => choices[x.id]).length;\n  return (\n    <span className=\"hb-xf4-dial\" aria-hidden=\"true\">\n      <svg viewBox=\"0 0 44 44\">\n        {categories.map((cat, i) => (\n          <circle\n            key={cat.id}\n            className=\"hb-xf4-arc\"\n            cx=\"22\"\n            cy=\"22\"\n            r={r}\n            strokeDasharray={`${seg.toFixed(2)} ${(c - seg).toFixed(2)}`}\n            strokeDashoffset={(-(c / n) * i - gap / 2).toFixed(2)}\n            style={{ stroke: choices[cat.id] ? \"var(--hb-xf4-accent)\" : \"#2c2c2c\" }}\n          />\n        ))}\n      </svg>\n      <b>{on}/{n}</b>\n    </span>\n  );\n}\n\nexport function PopupCookiePreferences({\n  categories = defaultCategories,\n  layout = \"card\",\n  title = \"We use cookies, sparingly\",\n  description = \"Only what keeps the store running is on by default. Choose what else you are comfortable with.\",\n  policyHref = \"#cookies\",\n  defaultOpen = true,\n  onConsent,\n  embedded = false,\n  accent = \"#c08a4a\",\n  className = \"\",\n  style,\n  ...rest\n}: PopupCookiePreferencesProps) {\n  const uid = React.useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const initial = React.useMemo(() => {\n    const out: Record<string, boolean> = {};\n    for (const c of categories) out[c.id] = Boolean(c.required || c.defaultEnabled);\n    return out;\n  }, [categories]);\n  const [view, setView] = React.useState<\"banner\" | \"saved\">(defaultOpen ? \"banner\" : \"saved\");\n  const [prefs, setPrefs] = React.useState(false);\n  const [choices, setChoices] = React.useState(initial);\n  const [vendorsOpen, setVendorsOpen] = React.useState<string | null>(null);\n  const [savedRef, setSavedRef] = React.useState(\"\");\n  const listRef = React.useRef<HTMLUListElement>(null);\n  const launchRef = React.useRef<HTMLButtonElement>(null);\n  const cardRef = React.useRef<HTMLDivElement>(null);\n  const focusNext = React.useRef<\"card\" | \"launch\" | \"list\" | null>(null);\n\n  React.useEffect(() => {\n    const target = focusNext.current;\n    if (!target) return;\n    focusNext.current = null;\n    const frame = requestAnimationFrame(() => {\n      if (target === \"launch\") launchRef.current?.focus({ preventScroll: true });\n      if (target === \"card\") cardRef.current?.querySelector<HTMLElement>(\".hb-xf4-btn\")?.focus({ preventScroll: true });\n      if (target === \"list\") listRef.current?.querySelector<HTMLElement>(\".hb-xf4-switch:not([aria-disabled='true'])\")?.focus({ preventScroll: true });\n    });\n    return () => cancelAnimationFrame(frame);\n  }, [view, prefs]);\n\n  const commit = (next: Record<string, boolean>) => {\n    setChoices(next);\n    setSavedRef(refId(JSON.stringify(next)));\n    onConsent?.(next);\n    setPrefs(false);\n    setVendorsOpen(null);\n    focusNext.current = \"launch\";\n    setView(\"saved\");\n  };\n\n  const all = (value: boolean) => {\n    const next: Record<string, boolean> = {};\n    for (const c of categories) next[c.id] = c.required ? true : value;\n    commit(next);\n  };\n\n  const togglePrefs = () => {\n    const next = !prefs;\n    if (next) focusNext.current = \"list\";\n    setPrefs(next);\n  };\n\n  const vars = { \"--hb-xf4-accent\": accent } as React.CSSProperties;\n\n  return (\n    <div className={`hb-xf4 ${embedded ? \"hb-xf4-embedded\" : \"\"} ${className}`} data-layout={layout} style={{ ...vars, ...style }} {...rest}>\n      <style href=\"hb-popup-cookie-preferences\" precedence=\"default\">{css}</style>\n      {view === \"saved\" ? (\n        <button\n          ref={launchRef}\n          type=\"button\"\n          className=\"hb-xf4-launch\"\n          aria-label=\"Cookie settings\"\n          onClick={() => {\n            focusNext.current = \"card\";\n            setView(\"banner\");\n          }}\n        >\n          <Dial categories={categories} choices={choices} />\n          <span>Cookie settings</span>\n          {savedRef && <small aria-live=\"polite\">Saved · {savedRef}</small>}\n        </button>\n      ) : (\n        <div className=\"hb-xf4-dock\">\n          <div\n            ref={cardRef}\n            className=\"hb-xf4-card\"\n            role=\"dialog\"\n            aria-modal=\"false\"\n            aria-labelledby={`${uid}-t`}\n            aria-describedby={`${uid}-d`}\n            onKeyDown={(e) => {\n              if (e.key === \"Escape\" && prefs) {\n                e.stopPropagation();\n                focusNext.current = \"card\";\n                setPrefs(false);\n              }\n            }}\n          >\n            <div className=\"hb-xf4-main\">\n              <Dial categories={categories} choices={choices} />\n              <div style={{ minWidth: 0 }}>\n                <p className=\"hb-xf4-title\" id={`${uid}-t`}>{title}</p>\n                <p className=\"hb-xf4-desc\" id={`${uid}-d`}>\n                  {description} <a href={policyHref}>Cookie policy</a>\n                </p>\n              </div>\n              {layout === \"bar\" && !prefs && (\n                <div className=\"hb-xf4-actions\">\n                  <button type=\"button\" className=\"hb-xf4-btn hb-xf4-link\" aria-expanded={prefs} aria-controls={`${uid}-p`} onClick={togglePrefs}>\n                    Customize\n                  </button>\n                  <button type=\"button\" className=\"hb-xf4-btn hb-xf4-quiet\" onClick={() => all(false)}>Reject all</button>\n                  <button type=\"button\" className=\"hb-xf4-btn hb-xf4-primary\" onClick={() => all(true)}>Accept all</button>\n                </div>\n              )}\n            </div>\n            {layout === \"card\" && !prefs && (\n              <div className=\"hb-xf4-actions\">\n                <button type=\"button\" className=\"hb-xf4-btn hb-xf4-quiet\" onClick={() => all(false)}>Reject all</button>\n                <button type=\"button\" className=\"hb-xf4-btn hb-xf4-primary\" onClick={() => all(true)}>Accept all</button>\n                <button type=\"button\" className=\"hb-xf4-btn hb-xf4-link\" aria-expanded={prefs} aria-controls={`${uid}-p`} onClick={togglePrefs}>\n                  Customize\n                  <svg viewBox=\"0 0 12 12\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"m3 4.5 3 3 3-3\" /></svg>\n                </button>\n              </div>\n            )}\n            <div className=\"hb-xf4-prefs\" data-open={prefs} id={`${uid}-p`} inert={!prefs}>\n              <div>\n                <ul className=\"hb-xf4-list\" ref={listRef}>\n                  {categories.map((cat) => {\n                    const on = Boolean(choices[cat.id]);\n                    const vendors = cat.vendors ?? [];\n                    return (\n                      <li key={cat.id} className=\"hb-xf4-row\" data-on={on}>\n                        <div className=\"hb-xf4-rowhead\">\n                          <div className=\"hb-xf4-rowtext\">\n                            <p className=\"hb-xf4-rowlabel\" id={`${uid}-${cat.id}`}>\n                              {cat.label}\n                              {vendors.length > 0 && <span className=\"hb-xf4-count\">{vendors.length}</span>}\n                            </p>\n                            <p className=\"hb-xf4-rowdesc\">{cat.description}</p>\n                            {vendors.length > 0 && (\n                              <button\n                                type=\"button\"\n                                className=\"hb-xf4-more\"\n                                aria-expanded={vendorsOpen === cat.id}\n                                onClick={() => setVendorsOpen((v) => (v === cat.id ? null : cat.id))}\n                              >\n                                {vendorsOpen === cat.id ? \"Hide vendors\" : \"Show vendors\"}\n                              </button>\n                            )}\n                            {vendorsOpen === cat.id && (\n                              <ul className=\"hb-xf4-vendors\">\n                                {vendors.map((v) => (\n                                  <li key={v.name}><span>{v.name}</span><span>{v.duration}</span></li>\n                                ))}\n                              </ul>\n                            )}\n                          </div>\n                          {cat.required && (\n                            <span className=\"hb-xf4-lock\" title=\"Always on\">\n                              <svg viewBox=\"0 0 24 24\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" aria-hidden=\"true\"><rect x=\"5\" y=\"11\" width=\"14\" height=\"10\" rx=\"2.5\" /><path d=\"M8 11V8a4 4 0 0 1 8 0v3\" /></svg>\n                            </span>\n                          )}\n                          <button\n                            type=\"button\"\n                            role=\"switch\"\n                            className=\"hb-xf4-switch\"\n                            aria-checked={on}\n                            aria-labelledby={`${uid}-${cat.id}`}\n                            aria-disabled={cat.required ? true : undefined}\n                            onClick={() => {\n                              if (cat.required) return;\n                              setChoices((c) => ({ ...c, [cat.id]: !c[cat.id] }));\n                            }}\n                          />\n                        </div>\n                      </li>\n                    );\n                  })}\n                </ul>\n                <div className=\"hb-xf4-save\">\n                  <button type=\"button\" className=\"hb-xf4-btn hb-xf4-link\" onClick={() => { focusNext.current = \"card\"; setPrefs(false); }}>Back</button>\n                  <button type=\"button\" className=\"hb-xf4-btn hb-xf4-quiet\" onClick={() => all(false)}>Reject all</button>\n                  <button type=\"button\" className=\"hb-xf4-btn hb-xf4-primary\" onClick={() => commit(choices)}>Save choices</button>\n                </div>\n              </div>\n            </div>\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n"
    }
  ]
}