{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"layer-stack","type":"registry:block","title":"Layer Stack","description":"Isometric stack of five layers with a list beside it – the chosen entry lifts its layer out in color","dependencies":[],"files":[{"path":"illustrations/layer-stack/layer-stack.tsx","type":"registry:block","content":"\"use client\";\n\nimport { useEffect, useId, useRef, useState, type ReactNode } from \"react\";\n\n/*\n * Layer Stack – an interactive card illustration, in a single self-contained file.\n * An isometric stack of five layers next to a list of five entries. The chosen entry lifts its layer\n * out of the stack in blue, with a soft glow underneath; the others settle back to glassy gray.\n * It steps through the entries on its own and pauses while you hover; click or focus an entry to pick it.\n * The artwork is laid out on a 600 × 400 grid inside a 3 : 2 frame and scales with its container.\n */\n\nexport type LayerStackItem = {\n  /** Main line of the entry */\n  title: string;\n  /** Short muted hint on the right */\n  hint?: string;\n  /** Icon drawn onto the layer: one of the built-in names */\n  icon?: LayerIcon;\n};\n\nexport type LayerIcon = \"bolt\" | \"database\" | \"plug\" | \"spark\" | \"pulse\";\n\nexport type LayerStackProps = {\n  /** Up to five entries, top layer first */\n  items?: LayerStackItem[];\n  /** Entry to start on */\n  defaultIndex?: number;\n  /** Time per entry while it plays on its own, in ms */\n  interval?: number;\n  /** Called when an entry is picked by the user */\n  onChange?: (index: number) => void;\n  className?: string;\n};\n\nconst defaultItems: LayerStackItem[] = [\n  { title: \"Triggered by events\", hint: \"Webhooks\", icon: \"bolt\" },\n  { title: \"Grounded in your data\", hint: \"Context\", icon: \"database\" },\n  { title: \"Connected to your apps\", hint: \"APIs\", icon: \"plug\" },\n  { title: \"Works with any model\", hint: \"Routing\", icon: \"spark\" },\n  { title: \"Traced at every step\", hint: \"Logs\", icon: \"pulse\" },\n];\n\n/* Layer geometry on the 600 × 400 grid */\nconst SIZE = 104; // side of a layer before the isometric projection (rhombus 208 × 104)\nconst STEP = 26; // vertical distance between resting layers\nconst GAP = 34; // the chosen layer lifts off the ones below it\nconst ABOVE = 24; // and the layers above it lift a little further, so it shows\nconst THICK = 9; // layer thickness\nconst CX = 168; // stack centre\nconst TOP = 109; // y of the top layer's back corner when nothing is lifted\n\nexport function LayerStack({ items = defaultItems, defaultIndex = 0, interval = 2600, onChange, className }: LayerStackProps) {\n  const id = \"ui-lyr\" + useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  // No items: the defaults rather than an empty highlighted row\n  const list = (items.length ? items : defaultItems).slice(0, 5);\n  const [active, setActive] = useState(Math.min(defaultIndex, list.length - 1));\n  const [paused, setPaused] = useState(false);\n  const touched = useRef(false);\n\n  // Step through the entries on its own until someone interacts; never with reduced motion\n  useEffect(() => {\n    if (paused || touched.current || list.length < 2) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    const timer = window.setInterval(() => setActive((i) => (i + 1) % list.length), interval);\n    return () => window.clearInterval(timer);\n  }, [paused, interval, list.length]);\n\n  const pick = (i: number) => {\n    touched.current = true;\n    setActive(i);\n    onChange?.(i);\n  };\n\n  // Resting y of each layer: gaps open below and above the chosen one. The bottom layer has nothing\n  // below it, so when it's chosen it stays put and only the layers above it rise\n  const last = list.length - 1;\n  const yOf = (i: number) => TOP + i * STEP - (i < active ? GAP + ABOVE : i === active && active < last ? GAP : 0);\n\n  return (\n    <div\n      className={[\"ui-lyr\", className].filter(Boolean).join(\" \")}\n      onMouseEnter={() => setPaused(true)}\n      onMouseLeave={() => setPaused(false)}\n      onFocus={() => setPaused(true)}\n      onBlur={() => setPaused(false)}\n    >\n      {/* React 19 hoists this into <head> once, no matter how many instances render */}\n      <style href=\"ui-layer-stack\" precedence=\"default\">\n        {css}\n      </style>\n\n      <svg className=\"ui-lyr-stack\" viewBox=\"0 0 600 400\" aria-hidden=\"true\">\n        <defs>\n          <filter id={`${id}-glow`} x=\"-60%\" y=\"-120%\" width=\"220%\" height=\"340%\">\n            <feGaussianBlur stdDeviation=\"14\" />\n          </filter>\n        </defs>\n\n        {/* Bottom layer first, so the upper ones overlap it */}\n        {list\n          .map((item, i) => (\n            <g\n              key={i}\n              className=\"ui-lyr-layer\"\n              data-active={i === active ? \"\" : undefined}\n              data-above={i < active ? \"\" : undefined}\n              style={{ transform: `translate(${CX}px, ${yOf(i)}px)` }}\n            >\n              {/* Glow just beneath this layer – fades in while it's the chosen one, same strength on every layer */}\n              <ellipse className=\"ui-lyr-glow\" cx={0} cy={SIZE / 2 + THICK + 18} rx={70} ry={24} filter={`url(#${id}-glow)`} />\n              {/* Thickness: the same rhombus, shifted down, peeks out below the top face */}\n              <g transform={`translate(0 ${THICK}) matrix(1 0.5 -1 0.5 0 0)`}>\n                <rect className=\"ui-lyr-side\" width={SIZE} height={SIZE} rx={9} />\n                <rect className=\"ui-lyr-side-on\" width={SIZE} height={SIZE} rx={9} />\n              </g>\n              <g transform=\"matrix(1 0.5 -1 0.5 0 0)\">\n                <rect className=\"ui-lyr-face\" width={SIZE} height={SIZE} rx={9} />\n                <rect className=\"ui-lyr-face-on\" width={SIZE} height={SIZE} rx={9} />\n                <g className=\"ui-lyr-icon\" transform={`translate(${SIZE / 2 - 18} ${SIZE / 2 - 18}) scale(1.5)`}>\n                  {icons[item.icon ?? \"bolt\"]}\n                </g>\n              </g>\n            </g>\n          ))\n          .reverse()}\n      </svg>\n\n      <div className=\"ui-lyr-menu\" role=\"tablist\" aria-label=\"Layers\" aria-orientation=\"vertical\">\n        <span className=\"ui-lyr-pill\" aria-hidden=\"true\" style={{ transform: `translateY(calc(${active} * var(--ui-lyr-row)))` }} />\n        {list.map((item, i) => (\n          <button\n            key={i}\n            type=\"button\"\n            role=\"tab\"\n            aria-selected={i === active}\n            tabIndex={i === active ? 0 : -1}\n            className=\"ui-lyr-row\"\n            onClick={() => pick(i)}\n            onKeyDown={(e) => {\n              const next = e.key === \"ArrowDown\" ? i + 1 : e.key === \"ArrowUp\" ? i - 1 : null;\n              if (next === null) return;\n              e.preventDefault();\n              const n = (next + list.length) % list.length;\n              pick(n);\n              (e.currentTarget.parentElement?.children[n + 1] as HTMLElement | undefined)?.focus();\n            }}\n          >\n            <span className=\"ui-lyr-title\">{item.title}</span>\n            {item.hint && <span className=\"ui-lyr-hint\">{item.hint}</span>}\n          </button>\n        ))}\n      </div>\n    </div>\n  );\n}\n\n/* ---------- Icons, drawn on a 24 grid and laid onto the layer ---------- */\n\nconst icons: Record<LayerIcon, ReactNode> = {\n  bolt: <path d=\"M13 3 5 13.5h6L10 21l8-10.5h-6L13 3Z\" />,\n  database: (\n    <>\n      <ellipse cx=\"12\" cy=\"6\" rx=\"7\" ry=\"3\" />\n      <path d=\"M5 6v12c0 1.7 3.1 3 7 3s7-1.3 7-3V6M5 12c0 1.7 3.1 3 7 3s7-1.3 7-3\" />\n    </>\n  ),\n  plug: <path d=\"M9 3v5M15 3v5M6.5 8h11v3a5.5 5.5 0 0 1-11 0V8ZM12 16.5V21\" />,\n  spark: <path d=\"M12 3c.6 4.6 2.4 6.4 7 7-4.6.6-6.4 2.4-7 7-.6-4.6-2.4-6.4-7-7 4.6-.6 6.4-2.4 7-7ZM18.5 15.5c.2 1.5.8 2.1 2.3 2.3-1.5.2-2.1.8-2.3 2.3-.2-1.5-.8-2.1-2.3-2.3 1.5-.2 2.1-.8 2.3-2.3Z\" />,\n  pulse: <path d=\"M3 12h4l2.5-6 5 12 2.5-6h4\" />,\n};\n\n/* ---------- Styles ---------- */\n\nconst css = /* css */ `\n.ui-lyr {\n  /* 1 unit of the 600 × 400 layout grid */\n  --u: calc(100cqw / 600);\n  --ui-lyr-row: calc(52 * var(--u));\n  /* The accent blue used across the library */\n  --ui-lyr-accent: #2f6bff;\n  --ui-lyr-accent-deep: #2557d9;\n  --ui-lyr-tint: #e9f0ff;\n  --ui-lyr-glow: rgba(47, 107, 255, 0.28);\n  --ui-lyr-face: rgba(255, 255, 255, 0.6);\n  --ui-lyr-edge: rgba(10, 10, 10, 0.11);\n  --ui-lyr-side: #ececef;\n  --ui-lyr-face-above: rgba(255, 255, 255, 0.3);\n  --ui-lyr-side-above: rgba(236, 236, 239, 0.55);\n  --ui-lyr-panel: #f5f5f5;\n  --ui-lyr-pill: #ffffff;\n  --ui-lyr-pill-ring: #e5e5e5;\n  --ui-lyr-text: #171717;\n  --ui-lyr-muted: #8f8f8f;\n  --ui-lyr-ease: cubic-bezier(0.65, 0, 0.25, 1);\n  position: relative;\n  width: 100%;\n  aspect-ratio: 3 / 2;\n  container-type: inline-size;\n  font-family: \"Inter\", ui-sans-serif, system-ui, -apple-system, sans-serif;\n  -webkit-font-smoothing: antialiased;\n}\n.ui-lyr *, .ui-lyr *::before, .ui-lyr *::after { box-sizing: border-box; }\n\n/* ---------- Stack ---------- */\n\n.ui-lyr-stack { position: absolute; inset: 0; width: 100%; height: 100%; overflow: visible; }\n.ui-lyr-layer { transition: transform 560ms var(--ui-lyr-ease); }\n.ui-lyr-glow {\n  fill: var(--ui-lyr-glow);\n  opacity: 0;\n  transition: opacity 420ms ease;\n}\n.ui-lyr-layer[data-active] .ui-lyr-glow { opacity: 1; }\n.ui-lyr-side-on {\n  fill: var(--ui-lyr-accent-deep);\n  opacity: 0;\n  transition: opacity 360ms ease;\n}\n.ui-lyr-side {\n  fill: var(--ui-lyr-side);\n  stroke: var(--ui-lyr-edge);\n  stroke-width: 1;\n  vector-effect: non-scaling-stroke;\n  transition: fill 360ms ease, stroke 360ms ease;\n}\n.ui-lyr-face {\n  fill: var(--ui-lyr-face);\n  stroke: var(--ui-lyr-edge);\n  stroke-width: 1;\n  vector-effect: non-scaling-stroke;\n  transition: fill 360ms ease, stroke 360ms ease;\n}\n.ui-lyr-face-on {\n  fill: var(--ui-lyr-tint);\n  stroke: var(--ui-lyr-accent);\n  opacity: 0;\n  stroke-width: 1.6;\n  vector-effect: non-scaling-stroke;\n  transition: opacity 360ms ease;\n}\n.ui-lyr-icon {\n  fill: none;\n  stroke: var(--ui-lyr-accent);\n  stroke-width: 1.5;\n  stroke-linecap: round;\n  stroke-linejoin: round;\n  opacity: 0;\n  transition: opacity 300ms ease;\n}\n/* Layers above the chosen one turn more glassy, so its color shows through */\n.ui-lyr-layer[data-above] .ui-lyr-face { fill: var(--ui-lyr-face-above); }\n.ui-lyr-layer[data-above] .ui-lyr-side { fill: var(--ui-lyr-side-above); }\n.ui-lyr-layer[data-active] .ui-lyr-side-on { opacity: 1; }\n.ui-lyr-layer[data-active] .ui-lyr-face-on { opacity: 1; }\n.ui-lyr-layer[data-active] .ui-lyr-icon { opacity: 1; transition-delay: 120ms; }\n\n/* ---------- Menu ---------- */\n\n.ui-lyr-menu {\n  position: absolute;\n  left: calc(326 * var(--u));\n  top: 50%;\n  width: calc(248 * var(--u));\n  padding: calc(8 * var(--u));\n  transform: translateY(-50%);\n  border-radius: calc(18 * var(--u));\n  background: var(--ui-lyr-panel);\n}\n/* White card that glides behind the chosen row */\n.ui-lyr-pill {\n  position: absolute;\n  left: calc(8 * var(--u));\n  right: calc(8 * var(--u));\n  top: calc(8 * var(--u));\n  height: var(--ui-lyr-row);\n  border-radius: calc(12 * var(--u));\n  background: var(--ui-lyr-pill);\n  box-shadow: 0 0 0 1px var(--ui-lyr-pill-ring), 0 1px 2px rgba(0, 0, 0, 0.05);\n  transition: transform 460ms var(--ui-lyr-ease);\n}\n.ui-lyr-row {\n  position: relative;\n  display: flex;\n  align-items: center;\n  justify-content: space-between;\n  gap: calc(10 * var(--u));\n  width: 100%;\n  height: var(--ui-lyr-row);\n  margin: 0;\n  padding: 0 calc(14 * var(--u));\n  border: 0;\n  border-radius: calc(12 * var(--u));\n  background: transparent;\n  font: inherit;\n  text-align: left;\n  cursor: pointer;\n  -webkit-tap-highlight-color: transparent;\n}\n.ui-lyr-row:focus-visible { outline: 2px solid var(--ui-lyr-accent); outline-offset: -2px; }\n.ui-lyr-title {\n  flex: 0 1 auto;\n  min-width: 0;\n  overflow: hidden;\n  font-size: calc(14 * var(--u));\n  font-weight: 500;\n  line-height: 1.3;\n  letter-spacing: -0.01em;\n  white-space: nowrap;\n  text-overflow: ellipsis;\n  color: var(--ui-lyr-text);\n  transition: color 300ms ease;\n}\n.ui-lyr-hint {\n  /* The title comes first – the hint gives way and ends in … */\n  flex: 0 10000 auto;\n  min-width: 0;\n  max-width: 45%;\n  overflow: hidden;\n  white-space: nowrap;\n  text-overflow: ellipsis;\n  font-size: calc(12 * var(--u));\n  line-height: 1.3;\n  color: var(--ui-lyr-muted);\n}\n.ui-lyr-row[aria-selected=\"true\"] .ui-lyr-title { color: var(--ui-lyr-accent); }\n\n@media (prefers-reduced-motion: reduce) {\n  .ui-lyr-layer, .ui-lyr-glow, .ui-lyr-pill { transition: none; }\n}\n\n/* Dark mode: follows a .dark class or data-theme=\"dark\" on any ancestor, e.g. <html> */\n:where(.dark, [data-theme=\"dark\"]) .ui-lyr {\n  --ui-lyr-accent: #6b95ff;\n  --ui-lyr-accent-deep: #2f6bff;\n  --ui-lyr-tint: #1f2c4d;\n  --ui-lyr-glow: rgba(47, 107, 255, 0.3);\n  --ui-lyr-face: rgba(255, 255, 255, 0.04);\n  --ui-lyr-edge: rgba(255, 255, 255, 0.13);\n  --ui-lyr-side: #26262a;\n  --ui-lyr-face-above: rgba(255, 255, 255, 0.025);\n  --ui-lyr-side-above: rgba(38, 38, 42, 0.5);\n  --ui-lyr-panel: #161618;\n  --ui-lyr-pill: #232326;\n  --ui-lyr-pill-ring: rgba(255, 255, 255, 0.08);\n  --ui-lyr-text: #ededed;\n  --ui-lyr-muted: #8f8f8f;\n}\n`;\n"}]}