{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"assemble-reveal","type":"registry:component","title":"Assemble Reveal","description":"A reveal where parts assemble in 3D: each item starts at its own offset and turn deep in perspective and flies home on a spring with a slight overshoot, one after another, as it comes into view.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/assemble-reveal.tsx","content":"\"use client\";\n\nimport { useEffect, useRef, useState, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\n\n/**\n * AssembleReveal — parts that assemble as they come into view.\n *\n * Each item starts at its own fixed offset and turn in 3D perspective and\n * flies home on a spring with a slight overshoot, one after another; it\n * renders in place first and only scatters once it can animate, so nothing is\n * hidden without script. On view, once or every time, or on a prop. CSS 3D.\n *\n * Part of the Spatial 3D kit: a dark studio (#0a0a0d, panels #101114 and\n * #16171b, ink #f2f1ee) with anodised copper #ff7a3d only as light, and\n * one object in three finishes (titanium, ceramic, soft-touch polymer) under\n * one rig: key, fill and rim, soft shadows, occlusion and a softbox\n * reflection. Hanken Grotesk through var(--font-hanken) for display over\n * Geist. Respects prefers-reduced-motion. No dependencies beyond React.\n * Paste it as its own file: it repeats the kit's small helpers, which would\n * clash in one module. Load Hanken Grotesk with next/font (variable:\n * \"--font-hanken\") on a parent, or from Google Fonts or @fontsource.\n */\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/** A part's starting pose: a fixed offset and turn in 3D, from its index. */\nfunction scatterOf(i: number, distance: number): string {\n  const h = (k: number) => {\n    const x = Math.sin(i * 91.3458 + k * 47.123) * 24634.6345;\n    return (x - Math.floor(x)) * 2 - 1;\n  };\n  return `translate3d(${(h(1) * 140 * distance).toFixed(1)}px, ${(h(2) * 90 * distance + 40).toFixed(1)}px, ${(-220 + h(3) * 180 * distance).toFixed(1)}px) rotateX(${(h(4) * 50).toFixed(1)}deg) rotateY(${(h(5) * 60).toFixed(1)}deg) rotateZ(${(h(6) * 14).toFixed(1)}deg)`;\n}\n\nexport type AssembleRevealProps = {\n  /** The parts, in the order they arrive. */\n  items: ReactNode[];\n  /** Delay between parts, ms. */\n  stagger?: number;\n  /** How far out the parts start (1 = about 140px across and 220px deep). */\n  distance?: number;\n  /** Assemble once, or come apart again each time it leaves the view. */\n  once?: boolean;\n  /** Assemble now, instead of on view. */\n  play?: boolean;\n  className?: string;\n  itemClassName?: string;\n  style?: CSSProperties;\n};\n\n/**\n * Parts that assemble as they come into view. Each item starts at its own\n * fixed offset and turn in real 3D perspective (deep behind the page and\n * off to one side) and flies home on a spring with a slight overshoot\n * (900ms), one after another; opacity follows in 500ms. Everything renders in\n * place first and only scatters once it can animate, so nothing is ever\n * hidden without script. Reduced motion shows the parts assembled.\n */\nexport function AssembleReveal({ items, stagger = 70, distance = 1, once = true, play, className, itemClassName, style }: AssembleRevealProps) {\n  const hostRef = useRef<HTMLDivElement>(null);\n  const [phase, setPhase] = useState<\"static\" | \"armed\" | \"in\">(\"static\");\n  const reduced = useReducedMotion();\n  const controlled = play !== undefined;\n\n  useEffect(() => {\n    if (reduced) return;\n    const el = hostRef.current;\n    if (!el) return;\n    let a = 0;\n    let b = 0;\n    // Scatter, let that paint, then send the parts home.\n    const assemble = () => {\n      a = requestAnimationFrame(() => {\n        setPhase(\"armed\");\n        b = requestAnimationFrame(() => {\n          b = requestAnimationFrame(() => setPhase(\"in\"));\n        });\n      });\n    };\n    if (controlled) {\n      if (play) assemble();\n      else a = requestAnimationFrame(() => setPhase(\"armed\"));\n      return () => {\n        cancelAnimationFrame(a);\n        cancelAnimationFrame(b);\n      };\n    }\n    let done = false;\n    const io = new IntersectionObserver(\n      (entries) => {\n        const v = entries[entries.length - 1].isIntersecting;\n        if (v && !done) {\n          done = once;\n          assemble();\n        } else if (!v && (!once || !done)) setPhase(\"armed\");\n      },\n      { threshold: 0.25 },\n    );\n    io.observe(el);\n    return () => {\n      io.disconnect();\n      cancelAnimationFrame(a);\n      cancelAnimationFrame(b);\n    };\n  }, [reduced, controlled, play, once]);\n\n  return (\n    <div ref={hostRef} className={className} style={{ perspective: 1100, ...style }}>\n      {items.map((item, i) => {\n        const out = phase === \"armed\";\n        return (\n          <div\n            key={i}\n            className={itemClassName}\n            style={{\n              transform: out ? scatterOf(i, distance) : \"none\",\n              opacity: out ? 0 : 1,\n              transition: phase === \"in\" ? `transform 900ms cubic-bezier(.2,1.25,.3,1) ${i * stagger}ms, opacity 500ms ease ${i * stagger}ms` : \"none\",\n            }}\n          >\n            {item}\n          </div>\n        );\n      })}\n    </div>\n  );\n}\n","type":"registry:component","target":"components/viberdy/assemble-reveal.tsx"}],"meta":{"tier":"free","tags":["animation","reveal","3d","css 3d","stagger","spring","scroll"],"href":"https://viberdy.dev/library/assemble-reveal","aiPrompt":"Build a React + Tailwind primitive, `AssembleReveal({ items, stagger, distance, once, play, className, itemClassName, style })`.\n\nA container with perspective 1100px; each item in a wrapper. Three phases: static (rendered in place, the server's and the no-script state), armed (every item at its scatter pose, opacity 0, no transition) and in (identity, transition transform 900ms cubic-bezier(.2,1.25,.3,1) and opacity 500ms, each delayed i x stagger). The scatter pose is fixed per index from a hash: translate3d(+-140 x distance px, +-90 x distance + 40px, -220 +- 180 x distance px) rotateX(+-50deg) rotateY(+-60deg) rotateZ(+-14deg). An IntersectionObserver (threshold 0.25) arms it when out of view and assembles it on entry (arm, let a frame paint, then go in); once keeps it assembled; play drives it by hand. Every state change happens in callbacks or animation frames, never synchronously in an effect.\n\nSpatial 3D grammar: a dark studio, ground #0a0a0d (panels #101114, raised #16171b, ink #f2f1ee at 92/60/38%, hairlines at 8% and 16%), and one accent, anodised copper #ff7a3d, used only as light (a status arc, a detent marker, an active underglow), never as a fill. One object in three finishes, as material parameters: titanium (base #b9bcc2, gloss 0.62, specular 0.8, fully metallic), ceramic (#ece7dd, gloss 0.4, specular 0.25, a little subsurface wrap) and soft-touch polymer (#1b1c20, gloss 0.3, specular 0.12, the rim kept up so it holds against the ground). One rig for everything: a warm key from (0.55, 0.65, 0.42) at 1.15, a cool fill from (-0.4, -0.15, 0.55) at 0.3, a rim from behind at 0.65, soft shadows (k 16), five-tap occlusion and a studio reflection (a big softbox overhead left, a strip behind right), in linear light with a filmic curve and a 1/255 dither. Parts are blended with small smooth-min radii (8-15% of the smaller part) so the object reads as machined, not melted. Hanken Grotesk through var(--font-hanken, \"Hanken Grotesk\", ...) at 600-800 for display, Geist for reading, Geist Mono uppercase for readouts. Radii 24px panels, 20px cards, 14px controls, the dial full round. Motion: detent springs (stiffness 340, damping 26, ~380ms), orbit inertia that decays in ~270ms, an idle drift of 6 degrees a second on the page clock after 2.5s of stillness, hovers and presses in 90-420ms. Respect prefers-reduced-motion (a still three-quarter view you can still turn by hand; no drift, no scatter). No dependencies beyond React.","license":"https://viberdy.dev/license"}}