{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"cookie-consent","type":"registry:component","title":"Cookie consent","description":"Bakes a bite back into the cookie for every category you allow.","author":"Yash Bavadiya <https://xevrion.dev>","dependencies":[],"registryDependencies":["utils"],"files":[{"path":"components/cookie-consent.tsx","type":"registry:component","content":"\"use client\";\n\nimport {\n  useEffect,\n  useId,\n  useLayoutEffect,\n  useRef,\n  useState,\n  useSyncExternalStore,\n} from \"react\";\nimport { useReducedMotion } from \"@/hooks/use-reduced-motion\";\nimport { cn } from \"@/lib/utils\";\n\nexport type Consent = {\n  functional: boolean;\n  analytics: boolean;\n  marketing: boolean;\n};\n\ntype Category = keyof Consent;\n\nexport const COOKIE_CATEGORIES: {\n  key: Category;\n  name: string;\n  description: string;\n}[] = [\n  {\n    key: \"functional\",\n    name: \"Functional\",\n    description: \"Remembers your language, theme and text size.\",\n  },\n  {\n    key: \"analytics\",\n    name: \"Analytics\",\n    description: \"Counts page visits so we know what to fix. No ad networks.\",\n  },\n  {\n    key: \"marketing\",\n    name: \"Marketing\",\n    description: \"Tells our ads on other sites that you have been here.\",\n  },\n];\n\nconst NONE: Consent = { functional: false, analytics: false, marketing: false };\nconst ALL: Consent = { functional: true, analytics: true, marketing: true };\n\n// Accept or reject all changes the cookie, then the banner closes. This is\n// long enough to see the bites mostly land or heal; the tail plays under\n// the content's fade out.\nconst SETTLE_MS = 240;\n\n// The cookie is drawn in a 120 unit box: a 50 unit dough disc in the middle.\nconst CENTER = 60;\nconst RADIUS = 50;\n// Each bite is a 34 unit circle whose middle sits 66 from the center, so it\n// takes an 18 unit deep mouthful. Deep enough to read as a bite at 24px in\n// the pill, shallow enough that three of them (the default, everything off)\n// still leave something that is plainly a cookie.\nconst BITE_RADIUS = 34;\nconst BITE_REACH = 66;\n// Far enough out that the bite, teeth and all, clears the dough completely.\nconst BITE_AWAY = 44;\n// Angles in degrees, clockwise from 3 o'clock, one per category above.\nconst BITES: Record<Category, number> = {\n  functional: 205,\n  analytics: -30,\n  marketing: 95,\n};\n// Three small circles along each bite's inner rim leave scalloped tooth\n// marks instead of a clean arc.\nconst TEETH = [-34, 0, 34];\n\n// Chips sit mostly where bites land, so eating a bite eats chips. The one\n// near the middle survives everything.\nconst CHIPS = [\n  { x: 57, y: 60, r: 5.5, t: 20 },\n  { x: 84, y: 36, r: 4.5, t: -30 },\n  { x: 95, y: 58, r: 3.5, t: 10 },\n  { x: 72, y: 88, r: 4.5, t: 40 },\n  { x: 48, y: 96, r: 3.5, t: -15 },\n  { x: 27, y: 58, r: 4.5, t: 60 },\n  { x: 36, y: 34, r: 3.5, t: 0 },\n  { x: 62, y: 24, r: 3.5, t: 35 },\n];\n\nconst rad = (deg: number) => (deg * Math.PI) / 180;\n\n// Baked goods are a physical material: dough and chocolate keep their own\n// colors in both themes, dimmed a touch for dark mode so they do not glow.\nconst CRUST = \"stroke-[light-dark(#c08845,#a8773f)]\";\nconst CHOC = \"fill-[light-dark(#4b2d18,#3d2413)]\";\n// Baked color: pale in the middle, browner toward the edge that saw more\n// heat.\nconst DOUGH_MID = \"light-dark(#e8bd80, #cf9d62)\";\nconst DOUGH_EDGE = \"light-dark(#cf9552, #b17c42)\";\n// Darker flecks of brown sugar in the dough.\nconst SPECKS = [\n  [44, 46],\n  [70, 50],\n  [52, 76],\n  [80, 72],\n  [38, 70],\n  [66, 38],\n  [60, 90],\n  [88, 48],\n  [30, 48],\n];\nconst CRUMB = \"bg-[light-dark(#dcab6b,#c8945a)]\";\n\nexport function Cookie({\n  consent,\n  size = 80,\n  className,\n}: {\n  consent: Consent;\n  size?: number;\n  className?: string;\n}) {\n  // useId's colons are not safe inside url(#...).\n  const maskId = `cookie-${useId().replace(/[^a-zA-Z0-9-]/g, \"\")}`;\n  return (\n    <svg\n      viewBox=\"0 0 120 120\"\n      width={size}\n      height={size}\n      aria-hidden\n      className={cn(\"block overflow-visible\", className)}\n    >\n      <defs>\n        <mask id={maskId} maskUnits=\"userSpaceOnUse\" x=\"0\" y=\"0\" width=\"120\" height=\"120\">\n          <rect width=\"120\" height=\"120\" fill=\"white\" />\n          {(Object.keys(BITES) as Category[]).map((key) => {\n            const angle = rad(BITES[key]);\n            const ux = Math.cos(angle);\n            const uy = Math.sin(angle);\n            const cx = CENTER + ux * BITE_REACH;\n            const cy = CENTER + uy * BITE_REACH;\n            const away = consent[key] ? BITE_AWAY : 0;\n            return (\n              <g\n                key={key}\n                style={{ transform: `translate(${ux * away}px, ${uy * away}px)` }}\n                // Biting is quick and decisive; healing is a softer ease so\n                // it reads as the cookie filling back in. Classes rather\n                // than a JS reduced motion check, which differs between the\n                // server and the first client render.\n                className={cn(\n                  \"motion-reduce:[transition:none]\",\n                  consent[key]\n                    ? \"[transition:transform_280ms_cubic-bezier(0.77,0,0.175,1)]\"\n                    : \"[transition:transform_220ms_cubic-bezier(0.23,1,0.32,1)]\",\n                )}\n              >\n                <circle cx={cx} cy={cy} r={BITE_RADIUS} fill=\"black\" />\n                {TEETH.map((offset) => {\n                  const a = angle + Math.PI + rad(offset);\n                  return (\n                    <circle\n                      key={offset}\n                      cx={cx + Math.cos(a) * (BITE_RADIUS - 2)}\n                      cy={cy + Math.sin(a) * (BITE_RADIUS - 2)}\n                      r={6.5}\n                      fill=\"black\"\n                    />\n                  );\n                })}\n              </g>\n            );\n          })}\n        </mask>\n        <radialGradient id={`${maskId}-bake`} cx=\"0.45\" cy=\"0.42\" r=\"0.6\">\n          <stop offset=\"0.55\" style={{ stopColor: DOUGH_MID }} />\n          <stop offset=\"1\" style={{ stopColor: DOUGH_EDGE }} />\n        </radialGradient>\n      </defs>\n      <g mask={`url(#${maskId})`}>\n        <circle\n          cx={CENTER}\n          cy={CENTER}\n          r={RADIUS - 1.5}\n          strokeWidth={3}\n          fill={`url(#${maskId}-bake)`}\n          className={CRUST}\n        />\n        {SPECKS.map(([x, y]) => (\n          <circle\n            key={`${x}-${y}`}\n            cx={x}\n            cy={y}\n            r={1.1}\n            className={CHOC}\n            opacity={0.35}\n          />\n        ))}\n        {CHIPS.map((chip) => (\n          <ellipse\n            key={`${chip.x}-${chip.y}`}\n            cx={chip.x}\n            cy={chip.y}\n            rx={chip.r}\n            ry={chip.r * 0.8}\n            transform={`rotate(${chip.t} ${chip.x} ${chip.y})`}\n            className={CHOC}\n          />\n        ))}\n        {/* A glint on each chip's upper left, where the light hits the\n            melted chocolate. */}\n        {CHIPS.map((chip) => (\n          <circle\n            key={`g-${chip.x}-${chip.y}`}\n            cx={chip.x - chip.r * 0.35}\n            cy={chip.y - chip.r * 0.3}\n            r={chip.r * 0.3}\n            fill=\"white\"\n            opacity={0.22}\n          />\n        ))}\n      </g>\n    </svg>\n  );\n}\n\n// Shared by every banner on the page, so opening settings in one place and\n// saving in another stays in sync.\nconst listeners = new Set<() => void>();\nfunction subscribe(listener: () => void) {\n  listeners.add(listener);\n  window.addEventListener(\"storage\", listener);\n  return () => {\n    listeners.delete(listener);\n    window.removeEventListener(\"storage\", listener);\n  };\n}\nfunction readStored(key: string) {\n  try {\n    return window.localStorage.getItem(key);\n  } catch {\n    return null;\n  }\n}\nfunction parse(raw: string | null): Consent | null {\n  if (!raw) return null;\n  try {\n    const value = JSON.parse(raw) as Partial<Consent>;\n    return {\n      functional: !!value.functional,\n      analytics: !!value.analytics,\n      marketing: !!value.marketing,\n    };\n  } catch {\n    return null;\n  }\n}\n\nfunction Switch({\n  id,\n  on,\n  onToggle,\n  describedBy,\n}: {\n  id: string;\n  on: boolean;\n  onToggle: () => void;\n  describedBy: string;\n}) {\n  return (\n    <button\n      id={id}\n      type=\"button\"\n      role=\"switch\"\n      aria-checked={on}\n      aria-describedby={describedBy}\n      onClick={onToggle}\n      className={cn(\n        \"relative h-6 w-10 shrink-0 rounded-full outline-hidden transition-[background-color,scale] duration-200 ease-out focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground active:scale-[0.96]\",\n        // A 48x40 hit area around the 40x24 track.\n        \"after:absolute after:-inset-x-1 after:-inset-y-2\",\n        on ? \"bg-foreground\" : \"bg-foreground/15\",\n      )}\n    >\n      <span\n        aria-hidden\n        className={cn(\n          \"absolute top-0.5 left-0.5 size-5 rounded-full bg-background shadow-[0_1px_2px_oklch(0_0_0/0.2)] transition-[translate] duration-200 ease-[cubic-bezier(0.23,1,0.32,1)]\",\n          on ? \"translate-x-4\" : \"translate-x-0\",\n        )}\n      />\n    </button>\n  );\n}\n\n// The pill is h-10, so its fully rounded ends have a 20px radius: the same\n// radius as the banner's corners, which lets one rounded clip be both.\nconst PILL_H = 40;\n\n/* How the banner and the pill are one surface: the banner is always laid\n   out, and a clip-path cuts it down to the pill's box in its bottom left\n   corner. Opening transitions the clip back to the whole banner. Only\n   clip-path, transform and opacity change, so nothing is laid out or\n   re-rasterized per frame, and a CSS transition retargets from wherever it\n   is, so reopening mid-close just turns around. A clip would cut off a\n   box-shadow, so the lift lives on a plate underneath that scales from the\n   pill's box to the banner's on the same curve, and the hairline edge is a\n   second clip one pixel bigger all round. */\nconst MORPH = \"ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:duration-0\";\n// Opening is what the eye is on; closing just gets out of the way.\nconst morphTime = (open: boolean) => (open ? \"duration-[240ms]\" : \"duration-[180ms]\");\n\nexport function CookieConsent({\n  storageKey,\n  contained = false,\n  onChange,\n  className,\n}: {\n  // Opt in to remembering the choice in localStorage under this key. Left\n  // out, the choice lasts for this page view only.\n  storageKey?: string;\n  // Positions the banner inside its nearest positioned parent instead of the\n  // viewport, for previews like the demo below.\n  contained?: boolean;\n  onChange?: (consent: Consent) => void;\n  className?: string;\n}) {\n  const reduceMotion = useReducedMotion();\n  const id = useId();\n  const stored = useSyncExternalStore(\n    subscribe,\n    () => (storageKey ? readStored(storageKey) : null),\n    // With storage, nothing renders on the server: the choice lives in the\n    // browser, and a banner flashing for people who already chose is worse\n    // than a beat of nothing. Without it, the banner is known up front.\n    () => (storageKey ? undefined : null),\n  );\n  // When storage is blocked the choice still holds for this visit.\n  const [memory, setMemory] = useState<Consent | null>(null);\n  const saved = parse(stored ?? null) ?? memory;\n  const [reopened, setReopened] = useState(false);\n  const [draft, setDraft] = useState<Consent>(NONE);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const bannerRef = useRef<HTMLElement>(null);\n  const cookieRef = useRef<HTMLDivElement>(null);\n  const headingRef = useRef<HTMLHeadingElement>(null);\n  const pillRef = useRef<HTMLButtonElement>(null);\n  const timer = useRef(0);\n  const settling = useRef(false);\n  const effects = useRef(new Set<Animation>());\n  const focusPill = useRef(false);\n\n  const ready = stored !== undefined;\n  const open = ready && (saved === null || reopened);\n\n  useEffect(() => {\n    const running = effects.current;\n    return () => {\n      window.clearTimeout(timer.current);\n      running.forEach((a) => a.cancel());\n    };\n  }, []);\n\n  // The clip and the plate need the pill's box relative to the banner's.\n  // Written straight to CSS variables, never state: it only changes when\n  // the banner reflows (a narrower screen wraps its text).\n  useLayoutEffect(() => {\n    const root = rootRef.current;\n    const banner = bannerRef.current;\n    const pill = pillRef.current;\n    if (!root || !banner || !pill) return;\n    const measure = () => {\n      const w = banner.offsetWidth;\n      const h = banner.offsetHeight;\n      const pw = pill.offsetWidth;\n      if (!w || !h) return;\n      root.style.setProperty(\"--pill-w\", `${pw}px`);\n      root.style.setProperty(\"--sx\", String(pw / w));\n      root.style.setProperty(\"--sy\", String(PILL_H / h));\n    };\n    measure();\n    const observer = new ResizeObserver(measure);\n    observer.observe(banner);\n    observer.observe(pill);\n    return () => observer.disconnect();\n  }, [ready]);\n\n  useEffect(() => {\n    if (open) {\n      if (reopened) headingRef.current?.focus();\n    } else if (focusPill.current) {\n      focusPill.current = false;\n      pillRef.current?.focus();\n    }\n  }, [open, reopened]);\n\n  // A bite shakes a few crumbs loose from where the teeth went in, and the\n  // cookie flinches. One-shots, so WAAPI rather than state.\n  const crunch = (key: Category) => {\n    const wrap = cookieRef.current;\n    if (!wrap || reduceMotion) return;\n    const scale = wrap.offsetWidth / 120;\n    const angle = rad(BITES[key]);\n    const edge = BITE_REACH - BITE_RADIUS + 6;\n    const flinch = wrap.animate(\n      { rotate: [\"0deg\", `${Math.cos(angle) > 0 ? -5 : 5}deg`, \"0deg\"] },\n      { duration: 280, easing: \"cubic-bezier(0.23, 1, 0.32, 1)\" },\n    );\n    effects.current.add(flinch);\n    flinch.onfinish = flinch.oncancel = () => effects.current.delete(flinch);\n    for (let i = 0; i < 4; i++) {\n      const crumb = document.createElement(\"span\");\n      const size = 3 + (i % 2) * 2;\n      crumb.className = cn(\n        \"pointer-events-none absolute rounded-[1px]\",\n        CRUMB,\n      );\n      crumb.style.width = `${size}px`;\n      crumb.style.height = `${size}px`;\n      const spread = rad((i - 1.5) * 16);\n      const px = (CENTER + Math.cos(angle + spread) * (edge + 22)) * scale;\n      const py = (CENTER + Math.sin(angle + spread) * (edge + 22)) * scale;\n      crumb.style.left = `${px}px`;\n      crumb.style.top = `${py}px`;\n      wrap.appendChild(crumb);\n      // Crumbs fall under gravity: a slow start, a long drop, a fade at\n      // the bottom. Physical, so longer than a UI transition.\n      const fall = crumb.animate(\n        {\n          translate: [\n            \"0 0\",\n            `${Math.cos(angle) * 8 + (i - 1.5) * 4}px ${26 + i * 7}px`,\n          ],\n          rotate: [\"0deg\", `${(i % 2 ? 1 : -1) * 140}deg`],\n          opacity: [1, 1, 0],\n        },\n        { duration: 620 + i * 60, easing: \"cubic-bezier(0.55, 0, 1, 0.45)\" },\n      );\n      effects.current.add(fall);\n      fall.onfinish = fall.oncancel = () => {\n        effects.current.delete(fall);\n        crumb.remove();\n      };\n    }\n  };\n\n  const change = (next: Consent) => {\n    for (const { key } of COOKIE_CATEGORIES) {\n      if (draft[key] && !next[key]) crunch(key);\n    }\n    setDraft(next);\n  };\n\n  const finish = (next: Consent) => {\n    settling.current = false;\n    try {\n      if (!storageKey) throw new Error(\"no storage\");\n      window.localStorage.setItem(\n        storageKey,\n        JSON.stringify({ ...next, savedAt: new Date().toISOString() }),\n      );\n    } catch {\n      setMemory(next);\n    }\n    listeners.forEach((l) => l());\n    focusPill.current = true;\n    setReopened(false);\n    onChange?.(next);\n  };\n\n  const save = (next: Consent) => {\n    if (settling.current) return;\n    const changed = COOKIE_CATEGORIES.some((c) => draft[c.key] !== next[c.key]);\n    change(next);\n    // Accept or reject all plays out on the cookie before the banner\n    // closes, just long enough to see the bites land or heal. When nothing\n    // changes (reject all on a fresh banner), there is nothing to wait for.\n    if (!changed || reduceMotion) return finish(next);\n    settling.current = true;\n    window.clearTimeout(timer.current);\n    timer.current = window.setTimeout(() => finish(next), SETTLE_MS);\n  };\n\n  // Escape backs out of a reopened banner, keeping what was saved. On a\n  // first visit there is nothing to fall back to, so it asks for a choice.\n  const dismiss = () => {\n    if (saved === null || settling.current) return;\n    focusPill.current = true;\n    setReopened(false);\n  };\n\n  const shown = open ? draft : (saved ?? NONE);\n  const turnedOff = COOKIE_CATEGORIES.filter((c) => !draft[c.key]).length;\n\n  if (!ready) return null;\n\n  return (\n    <div\n      className={cn(\n        \"pointer-events-none flex items-end\",\n        contained ? \"absolute inset-x-3 bottom-3\" : \"fixed inset-x-4 bottom-4 z-50\",\n        className,\n      )}\n    >\n      <div ref={rootRef} className=\"relative w-[min(500px,100%)]\">\n        {/* Everything that morphs. Once closed it hides for good, so the\n            pill's press can shrink it without showing the surface behind. */}\n        <div\n          className={cn(\n            \"relative transition-opacity duration-0\",\n            open ? \"opacity-100\" : \"opacity-0 delay-[180ms] motion-reduce:delay-0\",\n          )}\n        >\n          {/* The lift. Scaled rather than clipped so its shadow survives;\n              the same curve keeps its box on the clip's box every frame. */}\n          <div\n            aria-hidden\n            className={cn(\n              \"absolute inset-0 origin-bottom-left rounded-[20px] transition-[transform,opacity]\",\n              // shadow-raised minus its hairline, which the edge below draws.\n              \"shadow-[0_1px_2px_light-dark(oklch(0_0_0/0.06),oklch(0_0_0/0.4)),0_6px_16px_-6px_light-dark(oklch(0_0_0/0.12),oklch(0_0_0/0.6))]\",\n              MORPH,\n              morphTime(open),\n              open\n                ? \"[transform:scale(1,1)] opacity-100\"\n                : \"[transform:scale(var(--sx,1),var(--sy,1))] opacity-0\",\n            )}\n          />\n          {/* The hairline edge: the surface's clip plus a pixel all round. */}\n          <div\n            aria-hidden\n            className={cn(\n              \"absolute inset-0 bg-foreground/[0.07] [transition-property:clip-path] dark:bg-foreground/[0.09]\",\n              MORPH,\n              morphTime(open),\n              open\n                ? \"[clip-path:inset(-1px_-1px_-1px_-1px_round_21px)]\"\n                : \"[clip-path:inset(calc(100%-41px)_calc(100%-var(--pill-w,100%)-1px)_-1px_-1px_round_21px)]\",\n            )}\n          />\n          <section\n            ref={bannerRef}\n            aria-labelledby={`${id}-title`}\n            inert={!open}\n            onKeyDown={(e) => {\n              if (e.key === \"Escape\") dismiss();\n            }}\n            className={cn(\n              \"relative rounded-[20px] bg-background p-5 [transition-property:clip-path]\",\n              MORPH,\n              morphTime(open),\n              open\n                ? \"pointer-events-auto [clip-path:inset(0_0_0_0_round_20px)]\"\n                : \"[clip-path:inset(calc(100%-40px)_calc(100%-var(--pill-w,100%))_0_0_round_20px)]\",\n            )}\n          >\n            {/* The content fades rather than scales: text stays crisp and\n                the clip does the moving. Out fast before the clip crops it,\n                in just behind the clip so it lands on a settled surface. */}\n            <div\n              className={cn(\n                \"transition-[opacity,translate] ease-[cubic-bezier(0.23,1,0.32,1)] motion-reduce:translate-y-0\",\n                open\n                  ? \"translate-y-0 opacity-100 delay-[30ms] duration-[210ms]\"\n                  : \"translate-y-1 opacity-0 duration-[90ms]\",\n              )}\n            >\n              <div className=\"flex items-center gap-4\">\n                <div ref={cookieRef} className=\"relative shrink-0\">\n                  <Cookie consent={draft} size={80} />\n                </div>\n                <div className=\"min-w-0\">\n                  <h2\n                    ref={headingRef}\n                    id={`${id}-title`}\n                    tabIndex={-1}\n                    className=\"text-[15px] font-semibold text-balance text-foreground outline-hidden\"\n                  >\n                    We bake a few cookies\n                  </h2>\n                  <p className=\"mt-1 text-sm text-pretty text-muted-foreground\">\n                    Only the ones you allow. Switch one on and its bite bakes\n                    back in. Leave it off and the bite stays.\n                  </p>\n                </div>\n              </div>\n\n              <ul className=\"mt-4 divide-y divide-border border-y border-border\">\n                <li className=\"flex items-center gap-4 py-3\">\n                  <div className=\"min-w-0 flex-1\">\n                    <p className=\"text-sm font-medium text-foreground\">Essential</p>\n                    <p className=\"text-[13px] text-pretty text-muted-foreground\">\n                      Sign-in, your cart and security. The site breaks without\n                      these.\n                    </p>\n                  </div>\n                  <span className=\"shrink-0 text-[13px] text-muted-foreground\">Always on</span>\n                </li>\n                {COOKIE_CATEGORIES.map((category) => (\n                  <li key={category.key} className=\"flex items-center gap-4 py-3\">\n                    {/* The whole text is the switch's label, so a click on\n                        the name or the note flips it too. */}\n                    <label\n                      htmlFor={`${id}-${category.key}`}\n                      className=\"min-w-0 flex-1 cursor-pointer select-none\"\n                    >\n                      <span className=\"block text-sm font-medium text-foreground\">\n                        {category.name}\n                      </span>\n                      <span\n                        id={`${id}-${category.key}-desc`}\n                        className=\"block text-[13px] text-pretty text-muted-foreground\"\n                      >\n                        {category.description}\n                      </span>\n                    </label>\n                    <Switch\n                      id={`${id}-${category.key}`}\n                      on={draft[category.key]}\n                      describedBy={`${id}-${category.key}-desc`}\n                      onToggle={() =>\n                        change({ ...draft, [category.key]: !draft[category.key] })\n                      }\n                    />\n                  </li>\n                ))}\n              </ul>\n\n              <div className=\"mt-4 grid grid-cols-2 gap-2 sm:flex\">\n                {(\n                  [\n                    [\"Reject all\", NONE],\n                    [\"Accept all\", ALL],\n                  ] as const\n                ).map(([label, next]) => (\n                  <button\n                    key={label}\n                    type=\"button\"\n                    onClick={() => save(next)}\n                    className=\"h-10 rounded-[10px] bg-muted px-4 text-sm font-medium text-foreground outline-hidden transition-[scale,background-color] duration-150 ease-out hover:bg-foreground/[0.08] focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground active:scale-[0.96] sm:flex-1\"\n                  >\n                    {label}\n                  </button>\n                ))}\n                <button\n                  type=\"button\"\n                  onClick={() => save(draft)}\n                  className=\"col-span-2 h-10 rounded-[10px] bg-foreground px-4 text-sm font-medium text-background outline-hidden transition-[scale,opacity] duration-150 ease-out hover:opacity-90 focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground active:scale-[0.96] sm:flex-1\"\n                >\n                  Save choices\n                </button>\n              </div>\n            </div>\n            <p className=\"sr-only\" aria-live=\"polite\">\n              {turnedOff === 0\n                ? \"All cookies allowed.\"\n                : `${turnedOff} of 3 optional cookie types turned off.`}\n            </p>\n          </section>\n        </div>\n\n        <button\n          ref={pillRef}\n          type=\"button\"\n          inert={open}\n          onClick={() => {\n            setDraft(saved ?? NONE);\n            setReopened(true);\n          }}\n          className={cn(\n            \"absolute bottom-0 left-0 flex h-10 origin-bottom-left items-center gap-2 rounded-full bg-background pr-4 pl-2 text-sm font-medium whitespace-nowrap text-foreground shadow-raised outline-hidden focus-visible:outline-2 focus-visible:outline-solid focus-visible:outline-offset-2 focus-visible:outline-foreground active:scale-[0.96]\",\n            // The pill dissolves into the surface growing out of it, and\n            // comes back as the clip lands on its box. Its press stays\n            // instant either way, so the delay is on opacity only.\n            open\n              ? \"opacity-0 [transition:opacity_90ms_ease-out,scale_150ms_ease-out]\"\n              : \"pointer-events-auto opacity-100 [transition:opacity_140ms_cubic-bezier(0.23,1,0.32,1)_60ms,scale_150ms_ease-out] motion-reduce:[transition:opacity_140ms_ease-out,scale_150ms_ease-out]\",\n          )}\n        >\n          {/* The small cookie keeps the bites you chose. */}\n          <Cookie consent={shown} size={24} />\n          Cookie settings\n        </button>\n      </div>\n    </div>\n  );\n}\n\nexport default function CookieConsentDemo() {\n  return (\n    // A stand-in page, so the banner has something to sit on top of.\n    // Taller on phones, where the category notes wrap to two lines: tall\n    // enough that the banner stops below the article's headline.\n    <div className=\"relative h-[750px] w-[min(560px,100%)] overflow-hidden rounded-[20px] bg-muted sm:h-[560px]\">\n      <article className=\"px-7 pt-7\">\n        <p className=\"text-[13px] text-muted-foreground\">Field Notes · 6 min read</p>\n        <h2 className=\"mt-2 text-xl font-semibold text-foreground\">\n          Cold brew at home, without the sludge\n        </h2>\n        <p className=\"mt-3 text-sm leading-6 text-muted-foreground\">\n          Grind coarse, steep for eighteen hours in the fridge, and filter\n          twice. The second pass through a paper filter is what takes it from\n          muddy to clean, and it costs you five minutes.\n        </p>\n        <p className=\"mt-3 text-sm leading-6 text-muted-foreground\">\n          A ratio of one to eight makes a concentrate you can cut with water or\n          milk. Stronger than that and the bitterness creeps back in.\n        </p>\n      </article>\n      {/* No storageKey: the demo opens on the full banner every visit. */}\n      <CookieConsent contained />\n    </div>\n  );\n}\n"},{"path":"hooks/use-reduced-motion.ts","type":"registry:hook","target":"hooks/use-reduced-motion.ts","content":"\"use client\";\n\nimport { useSyncExternalStore } from \"react\";\n\n// Motion's useReducedMotion reads the media query on the very first client\n// render, but the server can't know it, so every component that renders\n// differently under reduced motion broke hydration for those users. This\n// reports false during hydration, matching the server HTML, then the real\n// preference straight after, and follows it if it changes.\nconst query = \"(prefers-reduced-motion: reduce)\";\n\nfunction subscribe(onChange: () => void) {\n  const media = window.matchMedia(query);\n  media.addEventListener(\"change\", onChange);\n  return () => media.removeEventListener(\"change\", onChange);\n}\n\nexport function useReducedMotion() {\n  return useSyncExternalStore(\n    subscribe,\n    () => window.matchMedia(query).matches,\n    () => false,\n  );\n}\n"}],"cssVars":{"light":{"shadow-raised":"0 0 0 1px oklch(0 0 0 / 0.06), 0 1px 2px oklch(0 0 0 / 0.06), 0 6px 16px -6px oklch(0 0 0 / 0.12)"},"dark":{"shadow-raised":"0 0 0 1px oklch(1 0 0 / 0.08), 0 1px 2px oklch(0 0 0 / 0.4), 0 6px 16px -6px oklch(0 0 0 / 0.6)"},"theme":{"shadow-raised":"var(--shadow-raised)"}},"categories":["feedback"],"docs":"From ui lab: https://lab.xevrion.dev/lab/cookie-consent"}