{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "animated-list",
  "title": "Animated List",
  "author": "AlgorizeTech",
  "description": "A container component for rendering lists with animated item insertions, reorders, or removals. Ideal for dynamic notifications or feeds.",
  "dependencies": [],
  "registryDependencies": [
    "utils"
  ],
  "files": [
    {
      "path": "src/components/custom/blocks/AnimatedListBlock.tsx",
      "content": "\"use client\";\n\nimport { cn } from \"@/lib/utils\";\nimport React, { forwardRef, useEffect, useRef } from \"react\";\n\nexport type AnimationVariant =\n  | \"flip\"\n  | \"slide-right\"\n  | \"slide-left\"\n  | \"slide-up\"\n  | \"pop\";\n\nexport interface AnimatedListProps\n  extends React.HTMLAttributes<HTMLDivElement> {\n  staggerDelay?: number;\n  animationDelay?: number;\n  ease?: string;\n  duration?: number;\n  variant?: AnimationVariant;\n}\n\n// ==========================================\n// EASING (GSAP ease names, built from GSAP's own formulas)\n// ==========================================\ntype EaseFn = (progress: number) => number;\n\nconst invert =\n  (ease: EaseFn): EaseFn =>\n  (p) =>\n    1 - ease(1 - p);\nconst inOutFromIn =\n  (easeIn: EaseFn): EaseFn =>\n  (p) =>\n    p < 0.5 ? easeIn(p * 2) / 2 : 1 - easeIn((1 - p) * 2) / 2;\nconst inOutFromOut =\n  (easeOut: EaseFn): EaseFn =>\n  (p) =>\n    p < 0.5 ? (1 - easeOut(1 - p * 2)) / 2 : 0.5 + easeOut((p - 0.5) * 2) / 2;\n\n/** A CSS cubic-bezier as a function of progress (Newton, then bisection). */\nconst cubicBezier = (x1: number, y1: number, x2: number, y2: number): EaseFn => {\n  const at = (t: number, a: number, b: number) =>\n    3 * (1 - t) * (1 - t) * t * a + 3 * (1 - t) * t * t * b + t * t * t;\n  const slope = (t: number, a: number, b: number) =>\n    3 * (1 - t) * (1 - t) * a + 6 * (1 - t) * t * (b - a) + 3 * t * t * (1 - b);\n  return (x) => {\n    if (x <= 0 || x >= 1) return x <= 0 ? 0 : 1;\n    let t = x;\n    for (let i = 0; i < 8; i++) {\n      const s = slope(t, x1, x2);\n      if (Math.abs(s) < 1e-6) break;\n      const err = at(t, x1, x2) - x;\n      if (Math.abs(err) < 1e-7) return at(t, y1, y2);\n      t -= err / s;\n    }\n    let lo = 0;\n    let hi = 1;\n    t = x;\n    for (let i = 0; i < 30 && hi - lo > 1e-7; i++) {\n      if (at(t, x1, x2) < x) lo = t;\n      else hi = t;\n      t = (lo + hi) / 2;\n    }\n    return at(t, y1, y2);\n  };\n};\n\nconst CSS_EASES: Record<string, [number, number, number, number]> = {\n  ease: [0.25, 0.1, 0.25, 1],\n  \"ease-in\": [0.42, 0, 1, 1],\n  \"ease-out\": [0, 0, 0.58, 1],\n  \"ease-in-out\": [0.42, 0, 0.58, 1],\n};\n\nconst POWER_EXPONENTS: Record<string, number> = {\n  power1: 2,\n  quad: 2,\n  power2: 3,\n  cubic: 3,\n  power3: 4,\n  quart: 4,\n  power4: 5,\n  quint: 5,\n  strong: 5,\n};\n\nconst bounceOut: EaseFn = (p) => {\n  const n = 7.5625;\n  const c = 2.75;\n  if (p < 1 / c) return n * p * p;\n  if (p < 2 / c) return n * (p - 1.5 / c) ** 2 + 0.75;\n  if (p < 2.5 / c) return n * (p - 2.25 / c) ** 2 + 0.9375;\n  return n * (p - 2.625 / c) ** 2 + 0.984375;\n};\n\n/**\n * The ease a GSAP ease string names — \"power2.out\", \"back.out(1.7)\",\n * \"elastic.out(1, 0.3)\", \"Power3.easeInOut\", \"steps(5)\", \"none\" — from the\n * same formulas GSAP uses. CSS keywords and `cubic-bezier(…)` work too;\n * anything else falls back to power1.out, as it does in GSAP.\n */\nfunction parseEase(name: string): EaseFn {\n  const trimmed = name.trim();\n  const open = trimmed.indexOf(\"(\");\n  const head = (open < 0 ? trimmed : trimmed.slice(0, open)).toLowerCase();\n  const args =\n    open < 0\n      ? []\n      : trimmed\n          .slice(open + 1, trimmed.lastIndexOf(\")\"))\n          .split(\",\")\n          .map((value) => (value.trim() === \"\" ? undefined : Number(value)));\n\n  if (\n    head === \"cubic-bezier\" &&\n    args.length === 4 &&\n    args.every((value) => value !== undefined && !isNaN(value))\n  ) {\n    const [x1, y1, x2, y2] = args as number[];\n    return cubicBezier(x1, y1, x2, y2);\n  }\n  if (CSS_EASES[head]) return cubicBezier(...CSS_EASES[head]);\n\n  const [family, rawType = \"out\"] = head.split(\".\");\n  const type = rawType.replace(/^ease/, \"\");\n  const pick = (easeIn: EaseFn, easeOut: EaseFn, easeInOut: EaseFn) =>\n    type === \"in\" ? easeIn : type === \"inout\" ? easeInOut : easeOut;\n\n  if (family === \"none\" || family === \"linear\" || family === \"power0\") {\n    return (p) => p;\n  }\n  if (POWER_EXPONENTS[family]) {\n    const power = POWER_EXPONENTS[family];\n    const easeIn: EaseFn = (p) => p ** power;\n    return pick(easeIn, (p) => 1 - (1 - p) ** power, inOutFromIn(easeIn));\n  }\n  if (family === \"sine\") {\n    const easeIn: EaseFn = (p) => (p === 1 ? 1 : 1 - Math.cos((p * Math.PI) / 2));\n    return pick(easeIn, invert(easeIn), inOutFromIn(easeIn));\n  }\n  if (family === \"expo\") {\n    const easeIn: EaseFn = (p) => 2 ** (10 * (p - 1)) * p + p ** 6 * (1 - p);\n    return pick(easeIn, invert(easeIn), inOutFromIn(easeIn));\n  }\n  if (family === \"circ\") {\n    const easeIn: EaseFn = (p) => -(Math.sqrt(1 - p * p) - 1);\n    return pick(easeIn, invert(easeIn), inOutFromIn(easeIn));\n  }\n  if (family === \"bounce\") {\n    const easeIn = invert(bounceOut);\n    return pick(easeIn, bounceOut, inOutFromIn(easeIn));\n  }\n  if (family === \"back\") {\n    const overshoot = args[0] ?? 1.70158;\n    const easeOut: EaseFn = (p) =>\n      p ? (p - 1) * (p - 1) * ((overshoot + 1) * (p - 1) + overshoot) + 1 : 0;\n    return pick(invert(easeOut), easeOut, inOutFromOut(easeOut));\n  }\n  if (family === \"elastic\") {\n    const amplitude = args[0] ?? 1;\n    const p1 = amplitude >= 1 ? amplitude : 1;\n    const period =\n      (args[1] || (type === \"inout\" ? 0.45 : 0.3)) / (amplitude < 1 ? amplitude : 1);\n    const p3 = (period / (2 * Math.PI)) * (Math.asin(1 / p1) || 0);\n    const easeOut: EaseFn = (p) =>\n      p === 1\n        ? 1\n        : p1 * 2 ** (-10 * p) * Math.sin(((p - p3) * 2 * Math.PI) / period) + 1;\n    return pick(invert(easeOut), easeOut, inOutFromOut(easeOut));\n  }\n  if (family === \"steps\") {\n    const steps = args[0] ?? 1;\n    const immediateStart = Boolean(args[1]);\n    const count = steps + (immediateStart ? 0 : 1);\n    const offset = immediateStart ? 1 : 0;\n    return (p) =>\n      (Math.trunc(count * Math.min(Math.max(p, 0), 1 - 1e-8)) + offset) / steps;\n  }\n\n  // power1.out — GSAP's default ease\n  return (p) => 1 - (1 - p) * (1 - p);\n}\n\n// ==========================================\n// ENTRANCE\n// ==========================================\n/** Where each variant starts; every item tweens from here to rest. */\ntype StartState = {\n  x: number;\n  y: number;\n  scale: number;\n  rotationX: number;\n  transformOrigin?: string;\n};\n\nconst START_STATES: Record<AnimationVariant, StartState> = {\n  \"slide-right\": { x: 60, y: 0, scale: 1, rotationX: 0 },\n  \"slide-left\": { x: -60, y: 0, scale: 1, rotationX: 0 },\n  \"slide-up\": { x: 0, y: 40, scale: 1, rotationX: 0 },\n  pop: { x: 0, y: 0, scale: 0.6, rotationX: 0 },\n  flip: {\n    x: 0,\n    y: 40,\n    scale: 0.9,\n    rotationX: -45,\n    transformOrigin: \"top center\",\n  },\n};\n\n/**\n * Write one frame of an item's entrance: `progress` is the eased position\n * between the start state (0) and rest (1). Written to the inline style every\n * frame, the way GSAP renders (a GPU-forced translate3d first), so a CSS\n * transition on the item reacts to the motion exactly as it did with GSAP.\n */\nconst renderEntrance = (el: HTMLElement, from: StartState, progress: number) => {\n  const rest = 1 - progress;\n  const rotationX = from.rotationX * rest;\n  const scale = from.scale + (1 - from.scale) * progress;\n  el.style.opacity = String(progress);\n  el.style.filter = `blur(${8 * rest}px)`;\n  el.style.transform =\n    `translate3d(${from.x * rest}px, ${from.y * rest}px, 0px)` +\n    (rotationX ? ` rotateX(${rotationX}deg)` : \"\") +\n    (scale !== 1 ? ` scale(${scale}, ${scale})` : \"\");\n};\n\nexport const AnimatedList = forwardRef<HTMLDivElement, AnimatedListProps>(\n  (\n    {\n      children,\n      staggerDelay = 0.12,\n      animationDelay = 0,\n      ease = \"back.out(1.5)\",\n      duration = 0.6,\n      variant = \"slide-right\",\n      className,\n      ...props\n    },\n    ref,\n  ) => {\n    const containerRef = useRef<HTMLDivElement>(null);\n\n    React.useImperativeHandle(\n      ref,\n      () => containerRef.current as HTMLDivElement,\n    );\n\n    useEffect(() => {\n      if (!containerRef.current) return;\n\n      const items = Array.from(containerRef.current.children) as HTMLElement[];\n\n      // Define dynamic starting states based on the selected variant\n      const from = START_STATES[variant] ?? START_STATES.flip;\n      const easing = parseEase(ease);\n\n      // Reset items to start state. The item's own translate/scale/rotate\n      // are folded out, so only this entrance moves it.\n      items.forEach((item) => {\n        item.style.translate = item.style.scale = item.style.rotate = \"none\";\n        if (from.transformOrigin) item.style.transformOrigin = from.transformOrigin;\n        renderEntrance(item, from, 0);\n      });\n\n      // Orchestrate the animated entrance, one frame at a time\n      const start = performance.now();\n      const done = new Set<HTMLElement>();\n      let frame = requestAnimationFrame(function tick(now) {\n        const elapsed = (now - start) / 1000;\n        items.forEach((item, index) => {\n          if (done.has(item)) return;\n          const local = elapsed - animationDelay - index * staggerDelay;\n          if (local <= 0) return;\n          const progress = duration > 0 ? Math.min(local / duration, 1) : 1;\n          renderEntrance(item, from, progress < 1 ? easing(progress) : 1);\n          if (progress >= 1) done.add(item);\n        });\n        if (done.size < items.length) frame = requestAnimationFrame(tick);\n      });\n\n      return () => {\n        cancelAnimationFrame(frame);\n      };\n    }, [staggerDelay, animationDelay, ease, duration, variant]);\n\n    return (\n      <div\n        ref={containerRef}\n        // perspective enables the 3D rotationX effect on children if 'flip' is chosen\n        className={cn(\n          \"flex flex-col gap-3 lg:gap-4 perspective-[1000px]\",\n          className,\n        )}\n        {...props}\n      >\n        {children}\n      </div>\n    );\n  },\n);\nAnimatedList.displayName = \"AnimatedList\";\n\nexport type AnimatedListItemProps = React.HTMLAttributes<HTMLDivElement>;\n\n/** GSAP's default ease, power1.out — exact. */\nconst EASE_POWER1_OUT = \"cubic-bezier(0.3333, 0.6667, 0.6667, 1)\";\n\nexport const AnimatedListItem = forwardRef<\n  HTMLDivElement,\n  AnimatedListItemProps\n>(({ children, className, ...props }, ref) => {\n  const cardRef = useRef<HTMLDivElement>(null);\n  const glowRef = useRef<HTMLDivElement>(null);\n\n  React.useImperativeHandle(ref, () => cardRef.current as HTMLDivElement);\n\n  // Mouse-tracking Spotlight Effect — the gradient's centre and alpha are\n  // registered custom properties, so they transition like any other value.\n  const moveSpotlight = (\n    x: string,\n    y: string,\n    alpha: number,\n    seconds: number,\n  ) => {\n    const glow = glowRef.current;\n    if (!glow) return;\n    glow.style.transitionDuration = [\n      // the glow's own `transition-opacity duration-300`\n      \"var(--tw-duration, var(--default-transition-duration))\",\n      `${seconds}s`,\n      `${seconds}s`,\n      `${seconds}s`,\n    ].join(\", \");\n    glow.style.setProperty(\"--animated-list-spot-x\", x);\n    glow.style.setProperty(\"--animated-list-spot-y\", y);\n    glow.style.setProperty(\"--animated-list-spot-alpha\", String(alpha));\n  };\n\n  const handleMouseMove = (e: React.MouseEvent<HTMLDivElement>) => {\n    if (!cardRef.current) return;\n    const rect = cardRef.current.getBoundingClientRect();\n    const x = e.clientX - rect.left;\n    const y = e.clientY - rect.top;\n    moveSpotlight(`${x}px`, `${y}px`, 0.06, 0.1);\n  };\n\n  const handleMouseLeave = () => {\n    moveSpotlight(\"50%\", \"50%\", 0, 0.5);\n  };\n\n  return (\n    <div\n      ref={cardRef}\n      onMouseMove={handleMouseMove}\n      onMouseLeave={handleMouseLeave}\n      className={cn(\n        \"relative w-full rounded-2xl bg-card border border-border/80 p-4 shadow-[0_2px_12px_rgba(0,0,0,0.03)] dark:shadow-[0_2px_20px_rgba(0,0,0,0.2)] opacity-0 group cursor-pointer transition-transform duration-300 hover:-translate-y-1 overflow-hidden\",\n        className,\n      )}\n      {...props}\n    >\n      <style>{`\n        @property --animated-list-spot-x {\n          syntax: \"<length-percentage>\";\n          inherits: false;\n          initial-value: 50%;\n        }\n        @property --animated-list-spot-y {\n          syntax: \"<length-percentage>\";\n          inherits: false;\n          initial-value: 50%;\n        }\n        @property --animated-list-spot-alpha {\n          syntax: \"<number>\";\n          inherits: false;\n          initial-value: 0;\n        }\n      `}</style>\n\n      {/* Spotlight Overlay Layer */}\n      <div\n        ref={glowRef}\n        className=\"absolute inset-0 z-0 pointer-events-none transition-opacity duration-300 opacity-0 group-hover:opacity-100\"\n        style={{\n          background:\n            \"radial-gradient(600px circle at var(--animated-list-spot-x) var(--animated-list-spot-y), rgba(255,255,255,var(--animated-list-spot-alpha)), transparent 40%)\",\n          transitionProperty:\n            \"opacity, --animated-list-spot-x, --animated-list-spot-y, --animated-list-spot-alpha\",\n          transitionTimingFunction: `var(--tw-ease, var(--default-transition-timing-function)), ${EASE_POWER1_OUT}, ${EASE_POWER1_OUT}, ${EASE_POWER1_OUT}`,\n        }}\n      />\n\n      {/* Inner Border Shine */}\n      <div className=\"absolute inset-0 rounded-2xl border border-white/40 dark:border-white/5 pointer-events-none z-10\" />\n\n      {/* Content Layer */}\n      <div className=\"relative z-20\">{children}</div>\n    </div>\n  );\n});\nAnimatedListItem.displayName = \"AnimatedListItem\";\n",
      "type": "registry:component",
      "target": "components/custom/blocks/AnimatedListBlock.tsx"
    }
  ],
  "docs": "Renders animated lists with smooth insertion and deletion transitions.",
  "categories": [
    "media",
    "scroll"
  ],
  "type": "registry:component"
}
