{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"iso-card-stack","type":"registry:component","title":"Iso Card Stack","description":"An isometric document pipeline on a round base: the front card works with its task icon, shows a check when it's done and lifts away, the others step forward and a new card drops in with its lines writing themselves in.","dependencies":["framer-motion"],"files":[{"path":"registry/dot/iso-card-stack.tsx","type":"registry:component","target":"components/dot/iso-card-stack.tsx","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type CSSProperties } from \"react\";\nimport { AnimatePresence, motion, useReducedMotion } from \"framer-motion\";\n\nexport type IsoIcon = \"gear\" | \"code\" | \"chart\" | \"lock\" | \"bolt\" | \"doc\";\n\nexport interface IsoCardStackProps {\n  /** Icons for incoming cards, used in turn */\n  icons?: IsoIcon[];\n  /** Cards standing in the stack (2–4) */\n  stackSize?: number;\n  /** Edges, lines and icons */\n  accentColor?: string;\n  /** Card faces and the base */\n  surfaceColor?: string;\n  /** Milliseconds per card: it works, shows a check, then leaves. 0 holds still */\n  interval?: number;\n  /** Activity lights on the base and a glow when a card is done */\n  activity?: boolean;\n  /** Soft shadow under the base */\n  shadow?: boolean;\n  /** Pause while the pointer is over it */\n  pauseOnHover?: boolean;\n  /** Called each time a card finishes, with how many have finished so far */\n  onCycle?: (completed: number) => void;\n  /** Accessible description */\n  label?: string;\n  className?: string;\n  style?: CSSProperties;\n}\n\n// ─── Isometric geometry (artboard 600 × 850, starting at y = -30) ────────────\n\nconst COS = Math.cos(Math.PI / 6); // 0.866\nconst W = 255; // card width along its face\nconst H = 360; // card height\nconst T = 16; // card thickness\nconst DEPTH = 184; // distance from the back slot to the front slot\nconst FRONT: [number, number] = [262, 576]; // bottom-left corner of the front card's face\n\ntype P = [number, number];\nconst face = (u: number, v: number): P => [u * COS, -u * 0.5 - v]; // u along the width, v up\nconst thick: P = [-T * COS, -T * 0.5]; // thickness points back and to the left\nconst add = (a: P, b: P): P => [a[0] + b[0], a[1] + b[1]];\nconst pts = (list: P[]) => list.map(([x, y]) => `${x.toFixed(1)},${y.toFixed(1)}`).join(\" \");\n// Card content is drawn flat (x right, y up) and projected onto the face with this matrix\nconst FACE_MATRIX = `matrix(${COS.toFixed(4)} -0.5 0 -1 0 0)`;\n\nfunction gearPath(cx: number, cy: number, r: number, teeth = 8) {\n  const steps = teeth * 4;\n  let d = \"\";\n  for (let i = 0; i < steps; i++) {\n    const a = (i / steps) * Math.PI * 2;\n    const rr = i % 4 < 2 ? r : r * 0.78;\n    d += `${i ? \"L\" : \"M\"}${(cx + Math.cos(a) * rr).toFixed(2)},${(cy + Math.sin(a) * rr).toFixed(2)}`;\n  }\n  return d + \"Z\";\n}\n\n/** Icon outlines in the card's flat space (y up), centred on cx, cy */\nfunction Icon({ name, cx, cy, color }: { name: IsoIcon | \"check\"; cx: number; cy: number; color: string }) {\n  const s = { fill: \"none\", stroke: color, strokeWidth: 3, strokeLinecap: \"round\" as const, strokeLinejoin: \"round\" as const };\n  switch (name) {\n    case \"gear\":\n      return (\n        <>\n          <path d={gearPath(cx, cy, 42)} {...s} />\n          <circle cx={cx} cy={cy} r={18} {...s} />\n        </>\n      );\n    case \"check\":\n      return (\n        <>\n          <circle cx={cx} cy={cy} r={40} {...s} />\n          <path d={`M${cx - 18},${cy + 1} L${cx - 5},${cy - 13} L${cx + 20},${cy + 14}`} {...s} strokeWidth={4} />\n        </>\n      );\n    case \"code\":\n      return <path d={`M${cx - 16},${cy + 20} L${cx - 36},${cy} L${cx - 16},${cy - 20} M${cx + 16},${cy + 20} L${cx + 36},${cy} L${cx + 16},${cy - 20} M${cx + 7},${cy + 28} L${cx - 7},${cy - 28}`} {...s} />;\n    case \"chart\":\n      return <path d={`M${cx - 36},${cy - 32} L${cx + 36},${cy - 32} M${cx - 24},${cy - 32} L${cx - 24},${cy - 4} M${cx},${cy - 32} L${cx},${cy + 18} M${cx + 24},${cy - 32} L${cx + 24},${cy + 4}`} {...s} strokeWidth={6} />;\n    case \"lock\":\n      return (\n        <>\n          <rect x={cx - 28} y={cy - 32} width={56} height={44} rx={6} {...s} />\n          <path d={`M${cx - 17},${cy + 12} L${cx - 17},${cy + 24} A17,17 0 0 0 ${cx + 17},${cy + 24} L${cx + 17},${cy + 12}`} {...s} />\n          <path d={`M${cx},${cy - 16} L${cx},${cy - 4}`} {...s} />\n        </>\n      );\n    case \"bolt\":\n      return <path d={`M${cx + 6},${cy + 40} L${cx - 22},${cy - 4} L${cx - 2},${cy - 4} L${cx - 8},${cy - 40} L${cx + 22},${cy + 6} L${cx + 2},${cy + 6} Z`} {...s} />;\n    case \"doc\":\n      return (\n        <>\n          <path d={`M${cx - 26},${cy - 36} L${cx - 26},${cy + 36} L${cx + 12},${cy + 36} L${cx + 26},${cy + 22} L${cx + 26},${cy - 36} Z`} {...s} />\n          <path d={`M${cx - 14},${cy + 8} L${cx + 14},${cy + 8} M${cx - 14},${cy - 8} L${cx + 14},${cy - 8}`} {...s} />\n        </>\n      );\n  }\n}\n\ninterface CardItem {\n  id: number;\n  icon: IsoIcon;\n}\n\nfunction Card({ item, accent, surface, front, done, animate }: { item: CardItem; accent: string; surface: string; front: boolean; done: boolean; animate: boolean }) {\n  const lines = [0.86, 0.79, 0.72, 0.65, 0.58];\n  const iconX = W * 0.62;\n  const iconY = H * 0.3;\n  return (\n    <g>\n      <polygon points={pts([face(0, 0), face(0, H), add(face(0, H), thick), add(face(0, 0), thick)])} fill={accent} />\n      <polygon points={pts([face(0, H), face(W, H), add(face(W, H), thick), add(face(0, H), thick)])} fill={accent} />\n      <polygon points={pts([face(0, 0), face(W, 0), face(W, H), face(0, H)])} fill={surface} stroke={accent} strokeWidth={3} strokeLinejoin=\"round\" />\n      <g transform={FACE_MATRIX}>\n        {/* Text lines write themselves in as the card arrives */}\n        {lines.map((v, i) => (\n          <motion.path\n            key={i}\n            d={`M${W * 0.16},${H * v} L${W * (i === 4 ? 0.62 : 0.84)},${H * v}`}\n            stroke={accent}\n            strokeWidth={3}\n            strokeLinecap=\"round\"\n            fill=\"none\"\n            initial={animate ? { pathLength: 0 } : false}\n            animate={{ pathLength: 1 }}\n            transition={{ duration: 0.5, delay: 0.35 + i * 0.08, ease: \"easeOut\" }}\n          />\n        ))}\n        {/* The front card shows its task icon while working, then a check */}\n        <motion.g initial={false} animate={{ opacity: front && !done ? 1 : 0 }} transition={{ duration: 0.3 }}>\n          <motion.g\n            animate={item.icon === \"gear\" && front && !done && animate ? { rotate: 360 } : { rotate: 0 }}\n            transition={item.icon === \"gear\" && front && !done && animate ? { duration: 5, ease: \"linear\", repeat: Infinity } : { duration: 0.3 }}\n            style={{ transformBox: \"fill-box\", transformOrigin: \"center\" }}\n          >\n            <Icon name={item.icon} cx={iconX} cy={iconY} color={accent} />\n          </motion.g>\n        </motion.g>\n        <motion.g\n          initial={false}\n          animate={{ opacity: front && done ? 1 : 0, scale: front && done ? 1 : 0.6 }}\n          transition={{ type: \"spring\", stiffness: 420, damping: 22 }}\n          style={{ transformBox: \"fill-box\", transformOrigin: \"center\" }}\n        >\n          <Icon name=\"check\" cx={iconX} cy={iconY} color={accent} />\n        </motion.g>\n      </g>\n    </g>\n  );\n}\n\n/**\n * An isometric document pipeline: cards stand on a round base, the front card works (its icon\n * active, the base lights blinking), shows a check when it's done, then lifts out while the others\n * step forward and a new card drops in at the back with its lines writing themselves in. SVG,\n * scales to its container; pauses offscreen and holds still with reduced motion.\n */\nexport function IsoCardStack({\n  icons = [\"gear\", \"code\", \"chart\", \"lock\", \"bolt\"],\n  stackSize = 3,\n  accentColor = \"#FF5A1F\",\n  surfaceColor = \"#0D0D0D\",\n  interval = 2600,\n  activity = true,\n  shadow = true,\n  pauseOnHover = false,\n  onCycle,\n  label = \"An isometric stack of documents being processed one by one\",\n  className,\n  style,\n}: IsoCardStackProps) {\n  const uid = useId().replace(/:/g, \"\");\n  const reduceMotion = useReducedMotion() ?? false;\n  const accent = accentColor;\n  const size = Math.max(2, Math.min(4, Math.round(stackSize)));\n  const iconList: IsoIcon[] = icons.length ? icons : [\"gear\"];\n  const iconFor = (id: number) => iconList[id % iconList.length];\n\n  const [cards, setCards] = useState<CardItem[]>(() => Array.from({ length: size }, (_, i) => ({ id: i, icon: iconFor(i) })));\n  const [done, setDone] = useState(false);\n  const [inView, setInView] = useState(true);\n  const [hovered, setHovered] = useState(false);\n  const completed = useRef(0);\n  const rootRef = useRef<SVGSVGElement | null>(null);\n  const onCycleRef = useRef(onCycle);\n  useEffect(() => {\n    onCycleRef.current = onCycle;\n  });\n\n  // Keep the stack at `stackSize` when it changes: add cards at the back or drop them from the back\n  if (cards.length !== size) {\n    const next = cards.length < size ? [...Array.from({ length: size - cards.length }, (_, i) => ({ id: Math.max(...cards.map((c) => c.id)) + 1 + i, icon: iconFor(Math.max(...cards.map((c) => c.id)) + 1 + i) })), ...cards] : cards.slice(cards.length - size);\n    setCards(next);\n  }\n\n  const running = interval > 0 && !reduceMotion && inView && !(pauseOnHover && hovered);\n\n  useEffect(() => {\n    const node = rootRef.current;\n    if (!node || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(([entry]) => setInView(entry.isIntersecting));\n    io.observe(node);\n    return () => io.disconnect();\n  }, []);\n\n  // One cycle: the front card works, shows a check, then leaves and a new card joins at the back\n  useEffect(() => {\n    if (!running) return;\n    const step = Math.max(1200, interval);\n    const finish = setTimeout(() => setDone(true), step * 0.62);\n    const advance = setTimeout(() => {\n      completed.current += 1;\n      onCycleRef.current?.(completed.current);\n      setDone(false);\n      setCards((c) => {\n        const id = Math.max(...c.map((x) => x.id)) + 1;\n        return [{ id, icon: iconList[id % iconList.length] }, ...c.slice(0, -1)];\n      });\n    }, step);\n    return () => {\n      clearTimeout(finish);\n      clearTimeout(advance);\n    };\n    // A new cycle starts whenever the cards change\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [running, interval, cards]);\n\n  const gap = DEPTH / (size - 1);\n  const slot = (s: number): P => [FRONT[0] - (size - 1 - s) * gap * COS, FRONT[1] - (size - 1 - s) * gap * 0.5];\n  const move = { duration: Math.min(0.9, Math.max(0.5, interval / 3200)), ease: [0.65, 0, 0.35, 1] as const };\n  const lift = H * 0.55;\n  const working = running && !done;\n\n  // Base\n  const cx = 300;\n  const top = 560;\n  const rx = 212;\n  const ry = rx * 0.5774;\n  const height = 122;\n\n  return (\n    <svg\n      ref={rootRef}\n      viewBox=\"0 -30 600 850\"\n      role=\"img\"\n      aria-label={label}\n      className={className}\n      onPointerEnter={() => setHovered(true)}\n      onPointerLeave={() => setHovered(false)}\n      style={{ display: \"block\", width: \"100%\", height: \"auto\", overflow: \"visible\", ...style }}\n    >\n      <defs>\n        <filter id={`${uid}-blur`} x=\"-50%\" y=\"-50%\" width=\"200%\" height=\"200%\">\n          <feGaussianBlur stdDeviation=\"18\" />\n        </filter>\n        <style>{`\n@keyframes ${uid}-led { 0%,100% { opacity: .35 } 50% { opacity: 1 } }\n@media (prefers-reduced-motion: reduce) { .${uid}-led { animation: none !important } }\n`}</style>\n      </defs>\n\n      {/* Soft shadow under the base */}\n      {shadow && <ellipse cx={cx} cy={top + height + 26} rx={rx * 1.02} ry={ry * 0.7} fill=\"#000\" opacity={0.55} filter={`url(#${uid}-blur)`} />}\n\n      {/* Base: side, top and rings */}\n      <path\n        d={`M${cx - rx},${top} L${cx - rx},${top + height} A${rx},${ry} 0 0 0 ${cx + rx},${top + height} L${cx + rx},${top} Z`}\n        fill={surfaceColor}\n        stroke={accent}\n        strokeWidth={3}\n        strokeLinejoin=\"round\"\n      />\n      <ellipse cx={cx} cy={top} rx={rx} ry={ry} fill={surfaceColor} stroke={accent} strokeWidth={3} />\n      {/* A glow on the base each time a card is done */}\n      {activity && (\n        <motion.ellipse\n          cx={cx}\n          cy={top}\n          rx={rx * 0.8}\n          ry={ry * 0.8}\n          fill={accent}\n          filter={`url(#${uid}-blur)`}\n          initial={false}\n          animate={{ opacity: done ? 0.28 : 0 }}\n          transition={{ duration: done ? 0.25 : 0.6 }}\n        />\n      )}\n      <ellipse cx={cx} cy={top} rx={rx * 0.8} ry={ry * 0.8} fill=\"none\" stroke={accent} strokeWidth={3} />\n      <ellipse cx={cx} cy={top} rx={rx * 0.48} ry={ry * 0.48} fill=\"none\" stroke={accent} strokeWidth={3} />\n\n      {/* Vents double as activity lights: they blink in turn while a card is working */}\n      {[0, 1, 2].map((i) => {\n        const x = cx + rx * (0.62 + i * 0.12);\n        const yTop = top + ry * Math.sqrt(Math.max(0, 1 - ((x - cx) / rx) ** 2)) + 22;\n        return (\n          <rect\n            key={i}\n            className={`${uid}-led`}\n            x={x - 6}\n            y={yTop}\n            width={12}\n            height={height - 40}\n            rx={6}\n            fill={accent}\n            style={{\n              opacity: activity && working ? undefined : 1,\n              animation: activity && working ? `${uid}-led .9s ease-in-out ${i * 0.15}s infinite` : undefined,\n            }}\n          />\n        );\n      })}\n\n      {/* Cards, back to front */}\n      <AnimatePresence initial={false}>\n        {cards.map((item, s) => {\n          const [x, y] = slot(s);\n          const front = s === cards.length - 1;\n          return (\n            <motion.g\n              key={item.id}\n              initial={{ x: slot(0)[0], y: slot(0)[1] - lift, opacity: 0 }}\n              animate={{ x, y, opacity: 1 }}\n              exit={{ x: x + gap * COS, y: y + gap * 0.5 - lift, opacity: 0, transition: move }}\n              transition={move}\n            >\n              <Card item={item} accent={accent} surface={surfaceColor} front={front} done={front && done} animate={!reduceMotion} />\n            </motion.g>\n          );\n        })}\n      </AnimatePresence>\n    </svg>\n  );\n}\n"}],"docs":"Iso Card Stack is ready. Props and a live canvas: https://bydot.co/component/iso-card-stack","meta":{"tier":"free","category":"UI Elements","version":"1.0.0"}}