{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cart",
  "title": "Cart",
  "author": "AlgorizeTech",
  "description": "A shopping cart with quantity controls, variant details and totals, rendered as drawer, modal, popover or full page. Use it for the cart step of a storefront.",
  "dependencies": [
    "lucide-react"
  ],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/CartBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport {\n  ArrowRight,\n  Minus,\n  Plus,\n  ShoppingBag,\n  ShoppingCart,\n  Trash2,\n  X,\n} from \"lucide-react\";\nimport { useEffect, useLayoutEffect, useRef, useState } from \"react\";\nimport { getThemeStyles } from \"./cart-theme\";\n\n/**\n * The animations have to apply their \"from\" values before the browser paints,\n * otherwise the panel is visible for one frame in its final position.\n * useLayoutEffect does that; React warns when it runs during SSR, so fall back\n * on the server.\n */\nconst useIsomorphicLayoutEffect =\n  typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\n// ==========================================\n// MOTION — Web Animations, no library\n// ==========================================\n// GSAP's eases as CSS easings: cubic-beziers where exact, else `linear()`\n// sampled from GSAP's own curves (max error 0.15%).\nconst POWER1_OUT = \"cubic-bezier(.3333, .6667, .6667, 1)\";\nconst POWER2_OUT = \"cubic-bezier(.3333, 1, .6667, 1)\";\nconst POWER2_IN = \"cubic-bezier(.3333, 0, .6667, 0)\";\nconst POWER1_IN_OUT =\n  \"linear(0, .002 3.125%, .0078 6.25%, .0176 9.375%, .0313 12.5%, .0488 15.625%, .0703 18.75%, .0957 21.875%, .125 25%, .1582 28.125%, .1953 31.25%, .2363 34.375%, .2813 37.5%, .3301 40.625%, .3828 43.75%, .4395 46.875%, .5 50%, .5605 53.125%, .6172 56.25%, .6699 59.375%, .7188 62.5%, .7637 65.625%, .8047 68.75%, .8418 71.875%, .875 75%, .9043 78.125%, .9297 81.25%, .9512 84.375%, .9688 87.5%, .9824 90.625%, .9922 93.75%, .998 96.875%, 1)\";\nconst POWER3_OUT =\n  \"linear(0, .1945, .3591, .4971, .6115, .7052, .7808, .8409, .8877, .9233, .9497, .9686, .9816, .9901, .9952, .998, .9994, .9999, 1, 1)\";\nconst POWER3_IN =\n  \"linear(0, .0002 12.5%, .0039 25%, .0095 31.25%, .0198 37.5%, .0366 43.75%, .0625 50%, .0797 53.125%, .1001 56.25%, .1243 59.375%, .1526 62.5%, .1855 65.625%, .2234 68.75%, .2669 71.875%, .3164 75%, .3725 78.125%, .4358 81.25%, .5068 84.375%, .5862 87.5%, .6745 90.625%, .7725 93.75%, .8807 96.875%, 1)\";\nconst BACK_OUT_1_5 =\n  \"linear(0, .2103, .3925, .5484, .68, .7891, .8775, .9472, 1, 1.0378, 1.0625, 1.0759, 1.08, 1.0766, 1.0675, 1.0547, 1.04, 1.0253, 1.0125, 1.0034, 1)\";\nconst BACK_OUT_4 = \"cubic-bezier(.3333, 2.3333, .6667, 1)\";\nconst ELASTIC_OUT_045 =\n  \"linear(0, .0583 0.781%, .1239 1.563%, .1951 2.344%, .2702 3.125%, .5832 6.25%, .7313 7.813%, .8002 8.594%, .8649 9.375%, .9248 10.156%, .9796 10.938%, 1.029 11.719%, 1.073 12.5%, 1.1115 13.281%, 1.1444 14.063%, 1.1719 14.844%, 1.1942 15.625%, 1.2115 16.406%, 1.224 17.188%, 1.2321 17.969%, 1.2361 18.75%, 1.2364 19.531%, 1.2333 20.313%, 1.2187 21.875%, 1.1953 23.438%, 1.1661 25%, 1.1007 28.125%, 1.0392 31.25%, 1.0134 32.813%, .992 34.375%, .9751 35.938%, .9628 37.5%, .9549 39.063%, .951 40.625%, .9525 43.75%, .9625 46.875%, .9761 50%, 1 56.25%, 1.0069 59.375%, 1.0101 62.5%, 1.0084 68.75%, 1.0028 75%, .9988 81.25%, .9978 87.5%, 1)\";\nconst ELASTIC_OUT_04 =\n  \"linear(0, .0598 0.781%, .1295 1.563%, .2069 2.344%, .2898 3.125%, .6398 6.25%, .7238 7.031%, .804 7.813%, .8792 8.594%, .9488 9.375%, 1.0121 10.156%, 1.0687 10.938%, 1.1184 11.719%, 1.1609 12.5%, 1.1963 13.281%, 1.2248 14.063%, 1.2464 14.844%, 1.2617 15.625%, 1.271 16.406%, 1.2746 17.188%, 1.2733 17.969%, 1.2674 18.75%, 1.2576 19.531%, 1.2443 20.313%, 1.2101 21.875%, 1.125 25%, 1.0816 26.563%, 1.0413 28.125%, 1.0063 29.688%, .9776 31.25%, .956 32.813%, .9414 34.375%, .9335 35.938%, .9313 37.5%, .934 39.063%, .9404 40.625%, .9599 43.75%, .9817 46.875%, 1 50%, 1.0119 53.125%, 1.0168 56.25%, 1.0162 59.375%, 1.0121 62.5%, 1.0017 68.75%, .9961 75%, .9991 87.5%, 1)\";\nconst BOUNCE_OUT =\n  \"linear(0, .0018 1.563%, .0074 3.125%, .0166 4.688%, .0295 6.25%, .0462 7.813%, .0665 9.375%, .0905 10.938%, .1182 12.5%, .1496 14.063%, .1846 15.625%, .2234 17.188%, .2659 18.75%, .312 20.313%, .3619 21.875%, .4154 23.438%, .4727 25%, .5279 26.42%, .5862 27.841%, .6475 29.261%, .7119 30.682%, .7794 32.102%, .8499 33.523%, .9234 34.943%, 1 36.364%, .9697 37.5%, .9313 39.063%, .8965 40.625%, .8655 42.188%, .8381 43.75%, .8145 45.313%, .7945 46.875%, .7782 48.438%, .7656 50%, .7567 51.563%, .7515 53.125%, .75 54.688%, .7522 56.25%, .7581 57.813%, .7676 59.375%, .7809 60.938%, .7979 62.5%, .8336 65.057%, .8792 67.614%, .9346 70.17%, 1 72.727%, .9727 75%, .9584 76.563%, .9478 78.125%, .9409 79.688%, .9377 81.25%, .9382 82.813%, .9424 84.375%, .9503 85.938%, .9619 87.5%, .9788 89.205%, 1 90.909%, .9883 93.182%, .9844 95.455%, .9883 97.727%, 1)\";\n\n/** Every animation still attached to an element, so a new gesture can kill them. */\nconst liveAnimations = new WeakMap<Element, Set<Animation>>();\n\nfunction play(\n  el: Element | null,\n  keyframes: Keyframe[],\n  options: KeyframeAnimationOptions,\n): Animation | null {\n  if (!el || typeof el.animate !== \"function\") return null;\n  const animation = el.animate(keyframes, options);\n  const live = liveAnimations.get(el) ?? new Set<Animation>();\n  liveAnimations.set(el, live);\n  live.add(animation);\n  const forget = () => live.delete(animation);\n  animation.addEventListener(\"finish\", forget);\n  animation.addEventListener(\"cancel\", forget);\n  return animation;\n}\n\n/** Stop every animation on these elements; they fall back to their resting CSS. */\nfunction killAnimationsOf(elements: (Element | null)[]) {\n  for (const el of elements) {\n    if (!el) continue;\n    for (const animation of [...(liveAnimations.get(el) ?? [])]) animation.cancel();\n  }\n}\n\n/** Current (animated) values of some CSS properties, as keyframe values. */\nfunction readStyle(el: Element, properties: string[]): Keyframe {\n  const computed = getComputedStyle(el);\n  const frame: Keyframe = {};\n  for (const property of properties) frame[property] = computed.getPropertyValue(property);\n  return frame;\n}\n\n/**\n * Tween to `to`, from `from` or else from wherever the element is right now,\n * replacing whatever was animating it. The end values are written inline, as\n * the resting state, so nothing depends on a fill.\n */\nfunction tweenTo(\n  el: HTMLElement,\n  to: Record<string, string>,\n  options: { from?: Keyframe; duration: number; easing: string },\n): Animation | null {\n  const from = options.from ?? readStyle(el, Object.keys(to));\n  killAnimationsOf([el]);\n  for (const [property, value] of Object.entries(to)) el.style.setProperty(property, value);\n  return play(el, [from, to], { duration: options.duration * 1000, easing: options.easing });\n}\n\nexport type CartColor = \"indigo\" | \"rose\" | \"emerald\" | \"zinc\" | (string & {});\nexport type CartType = \"drawer\" | \"modal\" | \"page\";\n\nexport interface CartItem {\n  id: string;\n  name: string;\n  price: number;\n  quantity: number;\n  size?: string;\n  color?: string;\n  gradient: string;\n}\n\nconst ItemRow = ({\n  item,\n  updateQty,\n  removeItem,\n}: {\n  item: CartItem;\n  updateQty: (id: string, delta: number) => void;\n  removeItem: (id: string) => void;\n  theme: Record<string, string>;\n}) => (\n  <div className=\"flex gap-4 py-4 border-b border-border\">\n    <div\n      className={cn(\n        \"w-20 h-24 rounded-lg bg-gradient-to-br shrink-0 shadow-inner\",\n        item.gradient,\n      )}\n    />\n    <div className=\"flex flex-col flex-1 justify-between\">\n      <div className=\"flex justify-between items-start gap-2\">\n        <div>\n          <h4 className=\"text-sm font-semibold text-foreground leading-tight\">\n            {item.name}\n          </h4>\n          <p className=\"text-xs text-muted-foreground mt-1\">\n            {item.color} | Size: {item.size}\n          </p>\n        </div>\n        <span className=\"text-sm font-semibold text-foreground shrink-0\">\n          ${(item.price * item.quantity).toFixed(2)}\n        </span>\n      </div>\n      <div className=\"flex items-center justify-between mt-3\">\n        <div className=\"flex items-center bg-muted border border-border rounded-md p-0.5\">\n          <button\n            onClick={() => updateQty(item.id, -1)}\n            className=\"w-6 h-6 flex items-center justify-center rounded text-muted-foreground hover:bg-card hover:text-foreground transition-colors active:scale-95\"\n          >\n            <Minus size={14} strokeWidth={2.5} />\n          </button>\n          <span className=\"w-6 text-center text-xs font-semibold select-none\">\n            {item.quantity}\n          </span>\n          <button\n            onClick={() => updateQty(item.id, 1)}\n            className=\"w-6 h-6 flex items-center justify-center rounded text-muted-foreground hover:bg-card hover:text-foreground transition-colors active:scale-95\"\n          >\n            <Plus size={14} strokeWidth={2.5} />\n          </button>\n        </div>\n        <button\n          onClick={() => removeItem(item.id)}\n          className=\"text-muted-foreground hover:text-red-500 transition-colors p-1\"\n        >\n          <Trash2 size={16} />\n        </button>\n      </div>\n    </div>\n  </div>\n);\n\nconst Summary = ({\n  subtotal,\n  theme,\n  isPage = false,\n}: {\n  subtotal: number;\n  theme: Record<string, string>;\n  isPage?: boolean;\n}) => (\n  <div\n    className={cn(\n      \"flex flex-col gap-3\",\n      isPage\n        ? \"p-6 sm:p-8 bg-muted rounded-2xl border border-border\"\n        : \"\",\n    )}\n  >\n    <div className=\"flex justify-between text-sm text-muted-foreground\">\n      <span>Subtotal</span>\n      <span className=\"font-medium text-foreground\">\n        ${subtotal.toFixed(2)}\n      </span>\n    </div>\n    <div className=\"flex justify-between text-sm text-muted-foreground\">\n      <span>Shipping</span>\n      <span className=\"font-medium text-foreground\">\n        Calculated at checkout\n      </span>\n    </div>\n    <div className=\"border-t border-border my-1\" />\n    <div className=\"flex justify-between items-end mb-4\">\n      <span className=\"text-base font-semibold text-foreground\">\n        Total\n      </span>\n      <span className=\"text-2xl font-bold text-foreground\">\n        ${subtotal.toFixed(2)}\n      </span>\n    </div>\n    <button\n      className={cn(\n        \"w-full py-4 rounded-xl font-semibold flex items-center justify-center gap-2 transition-all active:scale-[0.98] shadow-md hover:shadow-lg\",\n        theme.bg,\n      )}\n    >\n      Proceed to Checkout <ArrowRight size={18} />\n    </button>\n  </div>\n);\n\n/**\n * Every trigger animation below is decoration layered on a plain button: each\n * one tweens *from* an offset back to the resting state CSS already paints, so\n * a blocked, failed or reduced-motion run still leaves a usable trigger.\n */\nconst prefersReducedMotion = () =>\n  typeof window !== \"undefined\" &&\n  window.matchMedia?.(\"(prefers-reduced-motion: reduce)\").matches === true;\n\n/**\n * Defined at module scope on purpose: inside CartBlock it would be a new\n * component type on every render, remounting the button on each cart change.\n */\nfunction TriggerButton({\n  isOpen,\n  onToggle,\n  totalItems,\n  themeBg,\n  themeBorder,\n}: {\n  isOpen: boolean;\n  onToggle: () => void;\n  totalItems: number;\n  themeBg: string;\n  themeBorder: string;\n}) {\n  const buttonRef = useRef<HTMLButtonElement>(null);\n  const iconRef = useRef<HTMLSpanElement>(null);\n  const ringRef = useRef<HTMLSpanElement>(null);\n  const badgeRef = useRef<HTMLSpanElement>(null);\n  const nudgeRef = useRef<{ pause: () => void; restart: () => void } | null>(null);\n  const prevTotal = useRef(totalItems);\n\n  const shouldNudge = !isOpen && totalItems > 0;\n\n  // --- \"click me\": the bag tilts every few seconds and pushes out a ring.\n  // One 4.5s cycle (1.7s of motion + 2.8s rest), repeating after a 1.2s delay.\n  useIsomorphicLayoutEffect(() => {\n    const icon = iconRef.current;\n    const ring = ringRef.current;\n    const button = buttonRef.current;\n    if (!icon || !ring || !button || !shouldNudge || prefersReducedMotion()) return;\n\n    killAnimationsOf([button, icon, ring]);\n\n    const CYCLE = 4.5;\n    const at = (seconds: number) => seconds / CYCLE;\n    const timing: KeyframeAnimationOptions = {\n      duration: CYCLE * 1000,\n      delay: 1200,\n      iterations: Infinity,\n      // The ring sits at its starting pose through the delay, as it always has.\n      fill: \"backwards\",\n    };\n    let cycle: Animation[] = [];\n    let settle: Animation[] = [];\n\n    const start = () => {\n      cycle = [\n        play(\n          ring,\n          [\n            { scale: \"0.9\", opacity: 0.5, offset: 0, easing: POWER2_OUT },\n            { scale: \"1.8\", opacity: 0, offset: at(0.9) },\n            { scale: \"1.8\", opacity: 0, offset: 1 },\n          ],\n          timing,\n        ),\n        play(\n          icon,\n          [\n            { rotate: \"0deg\", offset: 0, easing: POWER2_OUT },\n            { rotate: \"-14deg\", offset: at(0.16) },\n            // The tilt back starts once the ring has finished (0.9s), so the\n            // bag holds its lean until then.\n            { rotate: \"-14deg\", offset: at(0.9), easing: POWER1_IN_OUT },\n            { rotate: \"10deg\", offset: at(1.06), easing: POWER1_IN_OUT },\n            { rotate: \"-6deg\", offset: at(1.2), easing: ELASTIC_OUT_045 },\n            { rotate: \"0deg\", offset: at(1.7) },\n            { rotate: \"0deg\", offset: 1 },\n          ],\n          timing,\n        ),\n      ].filter((a): a is Animation => a !== null);\n    };\n    const stop = () => {\n      for (const animation of [...cycle, ...settle]) animation.cancel();\n      cycle = [];\n      settle = [];\n    };\n\n    start();\n    nudgeRef.current = {\n      // Freeze the cycle, then settle the bag upright and fade the ring.\n      pause: () => {\n        for (const animation of cycle) animation.pause();\n        const hold = { fill: \"forwards\" } as const;\n        settle.push(\n          ...[\n            play(icon, [readStyle(icon, [\"rotate\"]), { rotate: \"0deg\" }], { ...hold, duration: 250, easing: POWER2_OUT }),\n            play(ring, [readStyle(ring, [\"opacity\"]), { opacity: 0 }], { ...hold, duration: 200, easing: POWER1_OUT }),\n          ].filter((a): a is Animation => a !== null),\n        );\n      },\n      // From the top, delay included.\n      restart: () => {\n        stop();\n        start();\n      },\n    };\n    return () => {\n      nudgeRef.current = null;\n      stop();\n    };\n  }, [shouldNudge]);\n\n  // Pointing at the button is already engagement. Stop nudging and settle the\n  // bag upright rather than freezing it mid-tilt.\n  const pauseNudge = () => {\n    nudgeRef.current?.pause();\n  };\n  const resumeNudge = () => {\n    if (shouldNudge && nudgeRef.current) {\n      nudgeRef.current.restart();\n    }\n  };\n\n  // --- the press itself: squash, spring back, and throw a ring outwards so the\n  // click reads as the thing that pushed the panel into view.\n  const playPress = () => {\n    const button = buttonRef.current;\n    const icon = iconRef.current;\n    const ring = ringRef.current;\n    if (!button || !icon || prefersReducedMotion()) return;\n\n    // A press while nudging opens the cart, which ends the nudge and puts the\n    // bag back at rest before the press starts; otherwise the press starts\n    // wherever an earlier one left off.\n    const fromRest = shouldNudge;\n    const buttonFrom = fromRest ? { scale: \"1\" } : readStyle(button, [\"scale\"]);\n    const iconFrom = fromRest\n      ? { rotate: \"0deg\", translate: \"0px 0px\", scale: \"1\" }\n      : readStyle(icon, [\"rotate\", \"translate\", \"scale\"]);\n\n    killAnimationsOf([button, icon, ring]);\n\n    play(\n      button,\n      [\n        { scale: buttonFrom.scale, easing: POWER2_IN },\n        { scale: \"0.86\", offset: 0.1 / 0.65, easing: ELASTIC_OUT_045 },\n        { scale: \"1\" },\n      ],\n      { duration: 650 },\n    );\n    play(icon, [{ rotate: iconFrom.rotate, easing: POWER2_IN }, { rotate: \"0deg\" }], {\n      duration: 100,\n    });\n    play(\n      icon,\n      [\n        { translate: iconFrom.translate, scale: iconFrom.scale, easing: POWER2_IN },\n        { translate: \"0px 3px\", scale: \"0.9\", offset: 0.1 / 0.6, easing: ELASTIC_OUT_04 },\n        { translate: \"0px 0px\", scale: \"1\" },\n      ],\n      { duration: 600 },\n    );\n    play(\n      ring,\n      [\n        { scale: \"0.85\", opacity: 0.6 },\n        { scale: \"1.9\", opacity: 0 },\n      ],\n      { duration: 600, delay: 40, easing: POWER3_OUT, fill: fromRest ? \"none\" : \"backwards\" },\n    );\n  };\n\n  // --- something landed in the bag: pop the count and bounce the icon, so a\n  // quantity change is visible even while the panel is closed.\n  useEffect(() => {\n    const grew = totalItems > prevTotal.current;\n    prevTotal.current = totalItems;\n    if (!grew || prefersReducedMotion()) return;\n\n    play(badgeRef.current, [{ scale: \"0.3\" }, { scale: \"1\" }], {\n      duration: 600,\n      easing: BACK_OUT_4,\n    });\n    play(iconRef.current, [{ translate: \"0px -4px\" }, { translate: \"0px 0px\" }], {\n      duration: 600,\n      easing: BOUNCE_OUT,\n    });\n  }, [totalItems]);\n\n  return (\n    <button\n      ref={buttonRef}\n      onClick={() => {\n        playPress();\n        onToggle();\n      }}\n      onMouseEnter={pauseNudge}\n      onMouseLeave={resumeNudge}\n      onFocus={pauseNudge}\n      onBlur={resumeNudge}\n      aria-expanded={isOpen}\n      aria-label={`${isOpen ? \"Close\" : \"Open\"} cart, ${totalItems} item${\n        totalItems === 1 ? \"\" : \"s\"\n      }`}\n      className={cn(\n        \"relative flex items-center justify-center p-3 rounded-full bg-card border border-border shadow-sm hover:shadow-md text-foreground will-change-transform\",\n        // Scale belongs to the press animation here - a CSS transition on it\n        // would fight the spring and flatten it.\n        \"transition-[background-color,box-shadow,border-color] duration-200\",\n        // The only press feedback a reduced-motion user gets, since playPress\n        // opts out for them.\n        \"active:bg-muted\",\n        isOpen && \"bg-muted\",\n      )}\n    >\n      <span\n        ref={ringRef}\n        aria-hidden=\"true\"\n        className={cn(\n          \"pointer-events-none absolute inset-0 rounded-full border-2 opacity-0\",\n          themeBorder,\n        )}\n      />\n      <span ref={iconRef} className=\"block will-change-transform\">\n        <ShoppingBag size={22} />\n      </span>\n      {totalItems > 0 && (\n        <span\n          ref={badgeRef}\n          className={cn(\n            \"absolute -top-1 -right-1 w-5 h-5 flex items-center justify-center text-[10px] font-semibold rounded-full shadow-sm\",\n            themeBg,\n          )}\n        >\n          {totalItems}\n        </span>\n      )}\n    </button>\n  );\n}\n\nexport function CartBlock({\n  initialItems = [],\n  type = \"drawer\",\n  color = \"primary\",\n}: {\n  /**\n   * Items the cart starts with. Own this list in the parent - the component\n   * ships no sample data, so a CartBlock rendered without `initialItems`\n   * shows its empty state.\n   */\n  initialItems?: readonly CartItem[];\n  type?: CartType;\n  color?: CartColor;\n}) {\n  const [isOpen, setIsOpen] = useState(false);\n  /**\n   * The animated layer stays mounted for the whole open -> close cycle. It is\n   * set from the click handler, in the same update as `isOpen`, and cleared by\n   * the exit tween's onComplete, so the two can never disagree.\n   */\n  const [isLayerMounted, setIsLayerMounted] = useState(false);\n  const [items, setItems] = useState<CartItem[]>(() => [...initialItems]);\n  const { theme, style } = getThemeStyles(color);\n\n  const openCart = () => {\n    setIsLayerMounted(true);\n    setIsOpen(true);\n  };\n  const closeCart = () => setIsOpen(false);\n\n  const containerRef = useRef<HTMLDivElement>(null);\n  const overlayRef = useRef<HTMLDivElement>(null);\n\n  const subtotal = items.reduce(\n    (acc, item) => acc + item.price * item.quantity,\n    0,\n  );\n  const totalItems = items.reduce((acc, item) => acc + item.quantity, 0);\n\n  const updateQty = (id: string, delta: number) => {\n    setItems(\n      items.map((item) => {\n        if (item.id === id) {\n          const newQty = item.quantity + delta;\n          return newQty > 0 ? { ...item, quantity: newQty } : item;\n        }\n        return item;\n      }),\n    );\n  };\n\n  const removeItem = (id: string) =>\n    setItems(items.filter((item) => item.id !== id));\n\n  // --- ANIMATION ---\n  useIsomorphicLayoutEffect(() => {\n    if (type === \"page\" || !isLayerMounted) return;\n\n    const el = containerRef.current;\n    const overlay = overlayRef.current;\n    if (!el) return;\n\n    // A fast toggle can leave a tween mid-flight. tweenTo cancels it, which\n    // also drops its completion, so a superseded close cannot unmount a cart\n    // that is opening again.\n    if (isOpen) {\n      if (overlay)\n        tweenTo(overlay, { opacity: \"1\" }, { from: { opacity: 0 }, duration: 0.3, easing: POWER2_OUT });\n\n      if (type === \"drawer\")\n        tweenTo(el, { translate: \"0%\" }, { from: { translate: \"100%\" }, duration: 0.4, easing: POWER3_OUT });\n      if (type === \"modal\")\n        tweenTo(\n          el,\n          { opacity: \"1\", scale: \"1\", translate: \"0px 0px\" },\n          {\n            from: { opacity: 0, scale: \"0.95\", translate: \"0px 10px\" },\n            duration: 0.4,\n            easing: BACK_OUT_1_5,\n          },\n        );\n      return;\n    }\n\n    // Unmount when the exit tween actually finishes, rather than on a fixed\n    // timer that can fire out of step with the open state.\n    const unmountLayer = () => setIsLayerMounted(false);\n\n    if (overlay) tweenTo(overlay, { opacity: \"0\" }, { duration: 0.3, easing: POWER2_IN });\n\n    let exit: Animation | null = null;\n    if (type === \"drawer\")\n      exit = tweenTo(el, { translate: \"100%\" }, { duration: 0.3, easing: POWER3_IN });\n    if (type === \"modal\")\n      exit = tweenTo(\n        el,\n        { opacity: \"0\", scale: \"0.95\", translate: \"0px 10px\" },\n        { duration: 0.3, easing: POWER2_IN },\n      );\n    if (exit) exit.addEventListener(\"finish\", unmountLayer);\n    else if (type === \"drawer\" || type === \"modal\") unmountLayer();\n  }, [isOpen, isLayerMounted, type]);\n\n  useEffect(() => {\n    if (!isOpen) return;\n    const handleEsc = (e: KeyboardEvent) => {\n      if (e.key === \"Escape\") closeCart();\n    };\n    document.addEventListener(\"keydown\", handleEsc);\n    return () => document.removeEventListener(\"keydown\", handleEsc);\n  }, [isOpen]);\n\n  if (type === \"page\") {\n    return (\n      <div className=\"w-full max-w-5xl mx-auto p-4 sm:p-8\" style={style}>\n        <div className=\"flex items-center gap-3 mb-8\">\n          <ShoppingCart className={cn(\"w-8 h-8\", theme.text)} />\n          <h2 className=\"text-3xl font-bold text-foreground\">\n            Your Cart\n          </h2>\n          <span className=\"ml-2 px-3 py-1 rounded-full bg-muted text-sm font-semibold text-muted-foreground\">\n            {totalItems} Items\n          </span>\n        </div>\n\n        {items.length === 0 ? (\n          <div className=\"flex flex-col items-center justify-center py-24 bg-background border border-border rounded-3xl\">\n            <ShoppingBag className=\"w-16 h-16 text-muted-foreground/40 mb-4\" />\n            <h3 className=\"text-xl font-semibold text-foreground mb-2\">\n              Your cart is empty\n            </h3>\n            <button\n              className={cn(\n                \"mt-4 px-6 py-3 rounded-xl font-semibold shadow-sm transition-opacity\",\n                theme.bg,\n              )}\n            >\n              Continue Shopping\n            </button>\n          </div>\n        ) : (\n          <div className=\"flex flex-col lg:flex-row gap-8\">\n            <div className=\"flex-1 bg-background border border-border rounded-3xl p-6 sm:p-8 shadow-sm\">\n              <h3 className=\"text-lg font-semibold text-foreground mb-4 border-b border-border pb-4\">\n                Order Items\n              </h3>\n              {items.map((item) => (\n                <ItemRow\n                  key={item.id}\n                  item={item}\n                  updateQty={updateQty}\n                  removeItem={removeItem}\n                  theme={theme}\n                />\n              ))}\n            </div>\n            <div className=\"w-full lg:w-[380px] shrink-0\">\n              <Summary subtotal={subtotal} theme={theme} isPage={true} />\n            </div>\n          </div>\n        )}\n      </div>\n    );\n  }\n\n  return (\n    <div\n      className=\"w-full flex items-center justify-center relative\"\n      style={style}\n    >\n      <div className=\"relative z-[90]\">\n        <TriggerButton\n          isOpen={isOpen}\n          onToggle={() => (isOpen ? closeCart() : openCart())}\n          totalItems={totalItems}\n          themeBg={theme.bg}\n          themeBorder={theme.border}\n        />\n      </div>\n\n      {(type === \"drawer\" || type === \"modal\") && isLayerMounted && (\n        <div\n          className={cn(\n            \"fixed inset-0 z-[100] pointer-events-none flex\",\n            type === \"drawer\" ? \"justify-end\" : \"justify-center items-center\",\n          )}\n        >\n          <div\n            ref={overlayRef}\n            onClick={closeCart}\n            className=\"absolute inset-0 bg-black/40 backdrop-blur-sm pointer-events-auto opacity-0\"\n          />\n\n          <div\n            ref={containerRef}\n            className={cn(\n              \"relative z-[101] bg-background flex flex-col shadow-2xl pointer-events-auto\",\n              type === \"drawer\"\n                ? \"w-full max-w-md h-[100dvh] border-l border-border\"\n                : \"w-full max-w-lg max-h-[85vh] rounded-3xl border border-border opacity-0\",\n            )}\n          >\n            <div className=\"px-6 py-5 border-b border-border flex items-center justify-between shrink-0\">\n              <div className=\"flex items-center gap-2\">\n                <ShoppingBag className={cn(\"w-5 h-5\", theme.text)} />\n                <h3 className=\"text-lg font-semibold text-foreground\">\n                  Shopping Cart\n                </h3>\n                <span className=\"ml-2 px-2 py-0.5 rounded-full bg-muted text-xs font-semibold text-muted-foreground\">\n                  {totalItems}\n                </span>\n              </div>\n              <button\n                onClick={closeCart}\n                className=\"w-8 h-8 flex items-center justify-center rounded-full bg-muted text-muted-foreground hover:text-foreground transition-colors\"\n              >\n                <X size={16} />\n              </button>\n            </div>\n\n            <div className=\"flex-1 overflow-y-auto p-6\">\n              {items.length === 0 ? (\n                <div className=\"h-full flex flex-col items-center justify-center text-muted-foreground space-y-4\">\n                  <ShoppingCart size={48} className=\"opacity-20\" />\n                  <p>Your cart is empty.</p>\n                </div>\n              ) : (\n                <div className=\"flex flex-col\">\n                  {items.map((item) => (\n                    <ItemRow\n                      key={item.id}\n                      item={item}\n                      updateQty={updateQty}\n                      removeItem={removeItem}\n                      theme={theme}\n                    />\n                  ))}\n                </div>\n              )}\n            </div>\n\n            {items.length > 0 && (\n              <div className=\"p-6 border-t border-border bg-muted/50 shrink-0\">\n                <Summary subtotal={subtotal} theme={theme} />\n              </div>\n            )}\n          </div>\n        </div>\n      )}\n    </div>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/custom/blocks/CartBlock.tsx"
    },
    {
      "path": "src/components/custom/blocks/cart-theme.ts",
      "content": "\"use client\";\n\nimport React from \"react\";\n\nconst colorThemes: Record<string, Record<string, string>> = {\n  primary: {\n    bg: \"bg-primary hover:bg-primary/90 text-primary-foreground\",\n    text: \"text-primary\",\n    border: \"border-primary/30\",\n    bgSoft: \"bg-primary/10\",\n    ring: \"focus:ring-primary\",\n  },\n  indigo: {\n    bg: \"bg-indigo-600 hover:bg-indigo-700 text-white\",\n    text: \"text-indigo-600 dark:text-indigo-400\",\n    border: \"border-indigo-600\",\n    bgSoft: \"bg-indigo-50 dark:bg-indigo-500/10\",\n    ring: \"focus:ring-indigo-600\",\n  },\n  rose: {\n    bg: \"bg-rose-600 hover:bg-rose-700 text-white\",\n    text: \"text-rose-600 dark:text-rose-400\",\n    border: \"border-rose-600\",\n    bgSoft: \"bg-rose-50 dark:bg-rose-500/10\",\n    ring: \"focus:ring-rose-600\",\n  },\n  emerald: {\n    bg: \"bg-emerald-600 hover:bg-emerald-700 text-white\",\n    text: \"text-emerald-600 dark:text-emerald-400\",\n    border: \"border-emerald-600\",\n    bgSoft: \"bg-emerald-50 dark:bg-emerald-500/10\",\n    ring: \"focus:ring-emerald-600\",\n  },\n  zinc: {\n    bg: \"bg-zinc-900 hover:bg-zinc-800 dark:bg-zinc-100 dark:hover:bg-zinc-200 dark:text-zinc-900 text-white\",\n    text: \"text-zinc-900 dark:text-zinc-100\",\n    border: \"border-zinc-900 dark:border-zinc-100\",\n    bgSoft: \"bg-zinc-100 dark:bg-zinc-800/50\",\n    ring: \"focus:ring-zinc-900 dark:focus:ring-zinc-100\",\n  },\n};\n\nconst hexToRgb = (hex: string) => {\n  let cleanHex = hex.replace(/^#/, \"\");\n  if (cleanHex.length === 3)\n    cleanHex = cleanHex\n      .split(\"\")\n      .map((x) => x + x)\n      .join(\"\");\n  const result = /^([a-f\\d]{2})([a-f\\d]{2})([a-f\\d]{2})$/i.exec(cleanHex);\n  return result\n    ? `${parseInt(result[1], 16)}, ${parseInt(result[2], 16)}, ${parseInt(result[3], 16)}`\n    : \"99, 102, 241\";\n};\n\nexport const getThemeStyles = (color: string) => {\n  if (color && color.startsWith(\"#\")) {\n    const rgb = hexToRgb(color);\n    return {\n      theme: {\n        bg: \"bg-[var(--theme-color)] text-white hover:opacity-90\",\n        text: \"text-[var(--theme-color)]\",\n        border: \"border-[var(--theme-color)]\",\n        bgSoft: \"bg-[rgba(var(--theme-color-rgb),0.1)]\",\n        ring: \"focus:ring-[var(--theme-color)]\",\n      },\n      style: {\n        \"--theme-color\": color,\n        \"--theme-color-rgb\": rgb,\n      } as React.CSSProperties,\n    };\n  }\n  return { theme: colorThemes[color] || colorThemes.primary, style: {} };\n};\n",
      "type": "registry:component",
      "target": "components/custom/blocks/cart-theme.ts"
    }
  ],
  "docs": "Named exports: CartBlock, getThemeStyles (from cart-theme.ts, which installs alongside), and the CartItem type. Switch presentation with `type` (drawer | modal | popover | page) without changing the item data. Pass the products in from the parent via `initialItems` — the component ships no sample data and renders its empty state without them. Items carry { id, name, price, quantity, gradient, size?, color? }; quantity and removal are handled internally. The trigger animates itself: a periodic tilt-and-ring nudge while the cart has items and has never been opened, a spring on press, and a badge pop whenever the count grows — all skipped under prefers-reduced-motion.",
  "categories": [
    "commerce"
  ],
  "type": "registry:component"
}
