Prayani

Experience Component

Component

About

A glossy 3D capsule that collects your career milestones as coins and seals them into a shareable summary card.

Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Experience Component to your project and fits it to your theme.

Code

How Experience Component is used: the demo's code. The component's own source comes with a free account.

Usage.tsx

"use client";
// Self-contained demo: the component and its demo in one file, so the preview
// does not depend on any "@/components/ui/..." import path. Needs the npm package "three".

import * as React from "react";
import * as THREE from "three";
import { OrbitControls } from "three/examples/jsm/controls/OrbitControls.js";
import { RoomEnvironment } from "three/examples/jsm/environments/RoomEnvironment.js";
import { Reflector } from "three/examples/jsm/objects/Reflector.js";

/** Tiny className joiner (no @/lib/utils needed). */
const cn = (...c: (string | false | null | undefined)[]) => c.filter(Boolean).join(" ");

/* -------------------------------------------------------------------------- */
/*                                   Types                                    */
/* -------------------------------------------------------------------------- */

export interface CapsuleItem {
  /** Main label, e.g. company name. */
  title: string;
  /** Secondary label, e.g. role. */
  subtitle?: string;
  /** Small trailing label, e.g. dates. */
  meta?: string;
  /** Optional logo image URL (needs CORS, or a data: URI). Leave out for a blank coloured coin. */
  logo?: string;
  /** How large the logo sits inside the coin face (1 = fills it). Default 1. */
  logoScale?: number;
  /** Coin face colour. Defaults to the logo's corner pixel, else #111. */
  color?: string;
  /** Optional short text on the coin when there is no logo. Leave out for a blank face. */
  initials?: string;
}

export interface CapsuleSummary {
  eyebrow?: string;
  title: string;
  subtitle?: string;
  /** Text next to the logo row. */
  stat?: string;
  highlight?: string;
  highlightSub?: string;
  footnote?: string;
}

export interface ExperienceCapsuleProps {
  /** Coins, in the order they drop. The last one lands on top. */
  items: CapsuleItem[];
  /** Ticket card shown after the capsule is sealed. */
  summary?: CapsuleSummary;
  /** Capsule band colour. */
  accent?: string;
  /** Scene background colour (also used for the floor fade). */
  background?: string;
  packingLabel?: string;
  sealingLabel?: string;
  /** Restart automatically after the card has been shown. Default true. */
  loop?: boolean;
  /** Let the viewer drag to look around. Default true. */
  interactive?: boolean;
  /** Show the replay button. Default true. */
  showReplay?: boolean;
  className?: string;
}

/* -------------------------------------------------------------------------- */
/*                                  Helpers                                   */
/* -------------------------------------------------------------------------- */

const clamp01 = (x: number) => Math.min(1, Math.max(0, x));
const smooth = (a: number, b: number, x: number) => {
  const t = clamp01((x - a) / (b - a));
  return t * t * (3 - 2 * t);
};
const easeOutBack = (x: number) => 1 + 2.5 * Math.pow(x - 1, 3) + 1.5 * Math.pow(x - 1, 2);
const easeInOutCubic = (x: number) => (x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2);

function loadImage(src: string) {
  return new Promise<HTMLImageElement>((resolve, reject) => {
    const img = new Image();
    img.crossOrigin = "anonymous";
    img.onload = () => resolve(img);
    img.onerror = reject;
    img.src = src;
  });
}

function canvasTexture(c: HTMLCanvasElement, srgb = true) {
  const t = new THREE.CanvasTexture(c);
  if (srgb) t.colorSpace = THREE.SRGBColorSpace;
  t.anisotropy = 8;
  return t;
}

function radialCanvas(stops: [number, string][], size = 512) {
  const c = document.createElement("canvas");
  c.width = c.height = size;
  const g = c.getContext("2d")!;
  const gr = g.createRadialGradient(size / 2, size / 2, 0, size / 2, size / 2, size / 2);
  stops.forEach(([o, col]) => gr.addColorStop(o, col));
  g.fillStyle = gr;
  g.fillRect(0, 0, size, size);
  return c;
}

/** Paints a coin face: metal bezel, coloured inset, logo (as-is), gloss. */
async function paintCoinFace(item: CapsuleItem) {
  const S = 512, C = S / 2, R = S / 2, IN = R * 0.8;
  const c = document.createElement("canvas");
  c.width = c.height = S;
  const g = c.getContext("2d")!;
  const mr = document.createElement("canvas");
  mr.width = mr.height = S;
  const m = mr.getContext("2d")!;
  const circle = (ctx: CanvasRenderingContext2D, rad: number) => {
    ctx.beginPath();
    ctx.arc(C, C, rad, 0, Math.PI * 2);
    ctx.fill();
  };

  // silver bezel
  const lg = g.createLinearGradient(0, 0, S, S);
  ([[0, "#f6f8fb"], [0.3, "#a4abb5"], [0.48, "#eef1f5"], [0.68, "#848b96"], [1, "#e3e7ec"]] as const).forEach(([o, col]) =>
    lg.addColorStop(o, col)
  );
  g.fillStyle = lg;
  circle(g, R);
  g.fillStyle = "#2a2e35";
  circle(g, R * 0.835);

  let bg = item.color ?? "#111214";
  let img: HTMLImageElement | null = null;
  if (item.logo) {
    try {
      img = await loadImage(item.logo);
      if (!item.color) {
        const probe = document.createElement("canvas");
        probe.width = probe.height = 4;
        const p = probe.getContext("2d")!;
        p.drawImage(img, 0, 0, img.width, img.height, 0, 0, 64, 64);
        const d = p.getImageData(1, 1, 1, 1).data;
        bg = `rgb(${d[0]},${d[1]},${d[2]})`;
      }
    } catch {
      img = null; // missing or tainted image: fall back to a blank coloured face
    }
  }

  g.fillStyle = bg;
  circle(g, IN);
  g.save();
  g.beginPath();
  g.arc(C, C, IN, 0, Math.PI * 2);
  g.clip();
  if (img) {
    const k = (item.logoScale ?? 1) * IN * 2;
    const ar = img.width / img.height;
    const w = ar >= 1 ? k : k * ar, h = ar >= 1 ? k / ar : k;
    g.drawImage(img, C - w / 2, C - h / 2, w, h);
  } else if (item.initials) {
    const text = item.initials;
    g.fillStyle = "#fff";
    g.textAlign = "center";
    g.textBaseline = "middle";
    g.font = `700 ${text.length > 2 ? 120 : 150}px Inter, ui-sans-serif, system-ui, sans-serif`;
    g.fillText(text, C, C + 6);
  }
  // inner shadow + gloss
  const sh = g.createRadialGradient(C, C, IN * 0.72, C, C, IN);
  sh.addColorStop(0, "rgba(0,0,0,0)");
  sh.addColorStop(1, "rgba(0,0,0,.35)");
  g.fillStyle = sh;
  circle(g, IN);
  const gl = g.createLinearGradient(C - IN, C - IN, C + IN * 0.2, C + IN * 0.4);
  gl.addColorStop(0, "rgba(255,255,255,.22)");
  gl.addColorStop(1, "rgba(255,255,255,0)");
  g.fillStyle = gl;
  circle(g, IN);
  g.restore();

  // metalness (B) / roughness (G): bezel is metal, face is glossy enamel
  m.fillStyle = "rgb(0,70,255)";
  circle(m, R);
  m.fillStyle = "rgb(0,60,0)";
  circle(m, IN);
  return { color: c, mr };
}

/* -------------------------------------------------------------------------- */
/*                                 Component                                  */
/* -------------------------------------------------------------------------- */

type Hud =
  | { mode: "pack" }
  | { mode: "item"; index: number }
  | { mode: "seal" };

const SLOT_JITTER: [number, number, number, number][] = [
  [0.05, 0.03, 0.1, 0.4],
  [-0.07, -0.02, -0.12, 1.7],
  [0.06, 0.05, 0.09, 2.9],
  [-0.04, 0.06, -0.1, 4.2],
  [0.02, -0.03, 0.06, 5.6],
];

export function ExperienceCapsule({
  items,
  summary,
  accent = "#3340e6",
  background = "#eef0f3",
  packingLabel = "Packing the capsule…",
  sealingLabel = "Sealing the capsule…",
  loop = true,
  interactive = true,
  showReplay = true,
  className,
}: ExperienceCapsuleProps) {
  const mountRef = React.useRef<HTMLDivElement>(null);
  const fadeRef = React.useRef<HTMLDivElement>(null);
  const timeRef = React.useRef(0);
  const [hud, setHud] = React.useState<Hud>({ mode: "pack" });
  const [pillVisible, setPillVisible] = React.useState(false);
  const [cardVisible, setCardVisible] = React.useState(false);
  const [chips, setChips] = React.useState<string[]>([]);

  const N = items.length;
  // Rebuild the scene only when the content really changes.
  const itemsKey = JSON.stringify(items);

  React.useEffect(() => {
    const mount = mountRef.current;
    if (!mount || N === 0) return;
    let disposed = false;

    /* timeline */
    const T_INTRO = 2.0, GAP = 1.25, DROP = 1.05;
    const T_SEAL = T_INTRO + (N - 1) * GAP + DROP + 0.55;
    const SEAL_DUR = 0.9;
    const T_REVEAL = T_SEAL + SEAL_DUR + 0.5;
    const T_FADE = T_REVEAL + 6.0;
    const T_LOOP = T_FADE + 0.6;

    /* renderer / scene */
    const renderer = new THREE.WebGLRenderer({ antialias: true });
    renderer.setPixelRatio(Math.min(window.devicePixelRatio, 2));
    renderer.toneMapping = THREE.NeutralToneMapping;
    renderer.domElement.style.display = "block";
    mount.appendChild(renderer.domElement);

    const scene = new THREE.Scene();
    scene.background = new THREE.Color(background);
    const pmrem = new THREE.PMREMGenerator(renderer);
    const envRT = pmrem.fromScene(new RoomEnvironment(), 0.035);
    scene.environment = envRT.texture;

    const camera = new THREE.PerspectiveCamera(28, 1, 0.1, 100);
    camera.position.set(0, 3.4, 12.8);
    const controls = new OrbitControls(camera, renderer.domElement);
    controls.enabled = interactive;
    controls.enableZoom = false;
    controls.enablePan = false;
    controls.enableDamping = true;
    controls.minPolarAngle = Math.PI * 0.28;
    controls.maxPolarAngle = Math.PI * 0.5;
    controls.minAzimuthAngle = -0.9;
    controls.maxAzimuthAngle = 0.9;
    controls.target.set(0, 0.3, 0);
    renderer.domElement.style.touchAction = "pan-y"; // keep page scroll working on touch

    const key = new THREE.DirectionalLight(0xffffff, 1.6);
    key.position.set(3, 6, 5);
    const rimLight = new THREE.DirectionalLight(0xdfe6ff, 0.8);
    rimLight.position.set(-5, 2, -3);
    scene.add(key, rimLight, new THREE.HemisphereLight(0xffffff, 0xcfd3da, 0.6));

    /* floor: mirror + fade + contact shadow */
    const FLOOR_Y = -1.62;
    const mirror = new Reflector(new THREE.PlaneGeometry(12, 12), {
      color: 0xb9bdc4, textureWidth: 1024, textureHeight: 1024, clipBias: 0.003,
    });
    mirror.rotation.x = -Math.PI / 2;
    mirror.position.y = FLOOR_Y - 0.002;
    mirror.renderOrder = 1;
    const bgRGB = new THREE.Color(background).getStyle(THREE.SRGBColorSpace).replace(/rgb\(|\)/g, "");
    const fadeMat = new THREE.MeshBasicMaterial({
      map: canvasTexture(radialCanvas([[0, `rgba(${bgRGB},.72)`], [0.16, `rgba(${bgRGB},.82)`], [0.34, `rgba(${bgRGB},1)`], [1, `rgba(${bgRGB},1)`]])),
      transparent: true, depthWrite: false, toneMapped: false,
    });
    const fade = new THREE.Mesh(new THREE.PlaneGeometry(12.2, 12.2), fadeMat);
    fade.rotation.x = -Math.PI / 2;
    fade.position.y = FLOOR_Y;
    fade.renderOrder = 2;
    const floorFar = new THREE.Mesh(new THREE.PlaneGeometry(200, 200), new THREE.MeshBasicMaterial({ color: background, toneMapped: false }));
    floorFar.rotation.x = -Math.PI / 2;
    floorFar.position.y = FLOOR_Y - 0.004;
    const shadowMat = new THREE.MeshBasicMaterial({
      map: canvasTexture(radialCanvas([[0, "rgba(18,22,32,.42)"], [0.35, "rgba(18,22,32,.18)"], [1, "rgba(18,22,32,0)"]], 256)),
      transparent: true, depthWrite: false, toneMapped: false,
    });
    const shadow = new THREE.Mesh(new THREE.PlaneGeometry(3.4, 1.5), shadowMat);
    shadow.rotation.x = -Math.PI / 2;
    shadow.position.y = FLOOR_Y + 0.003;
    shadow.renderOrder = 3;
    scene.add(mirror, fade, floorFar, shadow);

    /* capsule */
    const rig = new THREE.Group();
    scene.add(rig);
    const CAP_R = 1.0, CAP_H = 0.5;
    const halfProfile = (isTop: boolean) => {
      const pts: THREE.Vector2[] = [];
      for (let k = 0; k <= 40; k++) {
        const th = (k / 40) * (Math.PI / 2);
        pts.push(new THREE.Vector2(Math.max(1e-4, Math.sin(th) * CAP_R), -CAP_H - Math.cos(th) * CAP_R));
      }
      pts.push(new THREE.Vector2(CAP_R, 0));
      if (isTop) {
        pts.forEach((p) => (p.y = -p.y));
        pts.reverse();
      }
      return pts;
    };
    const glassMat = new THREE.MeshPhysicalMaterial({
      color: 0xffffff, metalness: 0, roughness: 0.03, transmission: 1, thickness: 0.12, ior: 1.42,
      clearcoat: 1, clearcoatRoughness: 0.04, specularIntensity: 1, envMapIntensity: 1.35,
      attenuationColor: new THREE.Color("#dde4ee"), attenuationDistance: 3, side: THREE.DoubleSide,
    });
    const cup = new THREE.Mesh(new THREE.LatheGeometry(halfProfile(false), 128), glassMat);
    const lid = new THREE.Group();
    lid.add(new THREE.Mesh(new THREE.LatheGeometry(halfProfile(true), 128), glassMat));
    const lip = new THREE.Mesh(
      new THREE.TorusGeometry(CAP_R, 0.012, 12, 128),
      new THREE.MeshPhysicalMaterial({ color: 0xffffff, roughness: 0.1, transmission: 0.6, clearcoat: 1 })
    );
    lip.rotation.x = Math.PI / 2;
    lid.add(lip);
    const bandMat = new THREE.MeshPhysicalMaterial({
      color: new THREE.Color(accent), metalness: 0.35, roughness: 0.22, clearcoat: 1, clearcoatRoughness: 0.08,
      emissive: new THREE.Color(accent), emissiveIntensity: 0,
    });
    const band = new THREE.Mesh(new THREE.TorusGeometry(CAP_R + 0.012, 0.042, 24, 160), bandMat);
    band.rotation.x = Math.PI / 2;
    band.position.y = -0.01;
    rig.add(cup, band, lid);

    /* coins */
    const COIN_R = 0.5, COIN_T = 0.1;
    const ridge = document.createElement("canvas");
    ridge.width = 1024;
    ridge.height = 8;
    const rg = ridge.getContext("2d")!;
    for (let i = 0; i < 1024; i += 8) {
      rg.fillStyle = "#fff"; rg.fillRect(i, 0, 4, 8);
      rg.fillStyle = "#000"; rg.fillRect(i + 4, 0, 4, 8);
    }
    const ridgeTex = canvasTexture(ridge, false);
    ridgeTex.wrapS = THREE.RepeatWrapping;
    const edgeMat = new THREE.MeshStandardMaterial({ color: 0xd6dae0, metalness: 1, roughness: 0.26, bumpMap: ridgeTex, bumpScale: 1.2 });
    const rimMat = new THREE.MeshStandardMaterial({ color: 0xe6e9ee, metalness: 1, roughness: 0.18 });
    const sideGeo = new THREE.CylinderGeometry(COIN_R, COIN_R, COIN_T, 128, 1, true).rotateX(Math.PI / 2);
    const faceGeo = new THREE.CircleGeometry(COIN_R * 0.99, 128);
    const rimGeo = new THREE.TorusGeometry(COIN_R - 0.018, 0.022, 14, 128);
    const coins: THREE.Group[] = [];
    const faceTextures: THREE.Texture[] = [];
    const faceMats: THREE.Material[] = [];

    (async () => {
      const urls: string[] = [];
      for (const item of items) {
        const { color, mr } = await paintCoinFace(item);
        if (disposed) return;
        const tex = canvasTexture(color), mrTex = canvasTexture(mr, false);
        faceTextures.push(tex, mrTex);
        const faceMat = new THREE.MeshPhysicalMaterial({
          map: tex, metalnessMap: mrTex, roughnessMap: mrTex, metalness: 1, roughness: 1, clearcoat: 0.8, clearcoatRoughness: 0.1,
        });
        faceMats.push(faceMat);
        const g = new THREE.Group();
        const front = new THREE.Mesh(faceGeo, faceMat);
        front.position.z = COIN_T / 2;
        const back = new THREE.Mesh(faceGeo, faceMat);
        back.position.z = -COIN_T / 2;
        back.rotation.y = Math.PI;
        const rf = new THREE.Mesh(rimGeo, rimMat);
        rf.position.z = COIN_T / 2 - 0.004;
        const rb = new THREE.Mesh(rimGeo, rimMat);
        rb.position.z = -COIN_T / 2 + 0.004;
        g.add(front, back, new THREE.Mesh(sideGeo, edgeMat), rf, rb);
        rig.add(g);
        coins.push(g);
        try {
          urls.push(color.toDataURL("image/png"));
        } catch {
          urls.push("");
        }
      }
      setChips(urls);
    })();

    /* choreography: everything is a pure function of time */
    const _e = new THREE.Euler();
    const qa = new THREE.Quaternion(), qb = new THREE.Quaternion(), flipQ = new THREE.Quaternion();
    const pa = new THREE.Vector3(), pb = new THREE.Vector3(), pc = new THREE.Vector3();
    const X = new THREE.Vector3(1, 0, 0);

    const orbitPose = (i: number, t: number, pos: THREE.Vector3, quat: THREE.Quaternion) => {
      const spill = easeOutBack(clamp01(t / 1.1));
      const a = (i / N) * Math.PI * 2 + t * 0.7 + 0.6;
      const r = 0.2 + 1.65 * spill;
      const y = -0.12 - 0.85 * (1 - spill) + Math.sin(t * 1.6 + i * 1.3) * 0.2 + Math.sin(a) * 0.12;
      pos.set(Math.cos(a) * r, y, Math.sin(a) * r * 0.8);
      _e.set(Math.sin(t * 1.1 + i) * 0.35, Math.sin(t * 1.3 + i * 1.7) * 1.05, Math.sin(t * 0.9 + i * 2.1) * 0.25);
      quat.setFromEuler(_e);
    };
    const slotPose = (i: number, pos: THREE.Vector3, quat: THREE.Quaternion) => {
      const [jx, jz, tilt, spin] = SLOT_JITTER[i % SLOT_JITTER.length];
      pos.set(jx, -1.2 + i * 0.118, jz);
      _e.set(-Math.PI / 2 + tilt, 0, spin, "XZY");
      quat.setFromEuler(_e);
    };
    const poseCoin = (i: number, t: number, obj: THREE.Object3D) => {
      const ts = T_INTRO + i * GAP, u = (t - ts) / DROP;
      if (u <= 0) {
        orbitPose(i, t, obj.position, obj.quaternion);
        obj.scale.setScalar(smooth(0, 0.5, t) * 0.9 + 0.1);
        return;
      }
      obj.scale.setScalar(1);
      slotPose(i, pb, qb);
      if (u >= 1) {
        const d = t - ts - DROP; // small settle bounce
        obj.position.copy(pb);
        obj.position.y += Math.max(0, Math.sin(d * 22)) * 0.07 * Math.exp(-d * 9);
        obj.quaternion.copy(qb);
        return;
      }
      orbitPose(i, ts, pa, qa);
      pc.set(pa.x * 0.25, 1.85, pa.z * 0.25); // arc apex above the cup
      const s = u < 0.5 ? 0.5 * Math.sin(u * Math.PI) : 1 - 0.5 * (1 + Math.cos(u * Math.PI));
      const k = 1 - s;
      obj.position.set(
        k * k * pa.x + 2 * k * s * pc.x + s * s * pb.x,
        k * k * pa.y + 2 * k * s * pc.y + s * s * pb.y,
        k * k * pa.z + 2 * k * s * pc.z + s * s * pb.z
      );
      obj.quaternion.slerpQuaternions(qa, qb, smooth(0.05, 0.85, u));
      flipQ.setFromAxisAngle(X, Math.PI * 2 * smooth(0.1, 0.8, u));
      obj.quaternion.premultiply(flipQ);
    };

    let hudKey = "", lastPill = false, lastCard = false;
    const pose = (t: number) => {
      rig.rotation.y = Math.sin(t * 0.45) * 0.12;
      const sc = clamp01((t - T_SEAL) / SEAL_DUR), close = sc > 0 ? easeOutBack(sc) : 0;
      lid.position.set(0, 1.55 * (1 - close) + Math.sin(t * 1.4) * 0.05 * (1 - close), 0);
      lid.rotation.set(0, 0, 0.07 * (1 - close));
      const flash = Math.max(0, 1 - Math.abs(t - (T_SEAL + SEAL_DUR * 0.55)) / 0.35);
      bandMat.emissiveIntensity = flash * 0.9;
      const squash = flash * 0.03;
      const rv = easeInOutCubic(clamp01((t - T_REVEAL) / 1.1));
      const s = 1 - rv * 0.22;
      rig.scale.set((1 + squash) * s, (1 - squash) * s, (1 + squash) * s);
      rig.position.y = rv * 1.25 + Math.sin(t * 1.2) * 0.04 * rv;
      shadow.scale.setScalar(1 + rv * 0.5);
      shadowMat.opacity = 1 - rv * 0.55;
      coins.forEach((c, i) => poseCoin(i, t, c));

      // HUD (only touches React state when something changes)
      let landed = 0;
      for (let i = 0; i < N; i++) if (t >= T_INTRO + i * GAP + DROP * 0.8) landed = i + 1;
      const next: Hud = landed === 0 ? { mode: "pack" } : t < T_SEAL ? { mode: "item", index: landed - 1 } : { mode: "seal" };
      const nk = next.mode + ("index" in next ? next.index : "");
      if (nk !== hudKey) { hudKey = nk; setHud(next); }
      const pill = t > 0.25 && t < T_REVEAL - 0.1;
      if (pill !== lastPill) { lastPill = pill; setPillVisible(pill); }
      const card = t > T_REVEAL + 0.25 && t < T_FADE + 0.2;
      if (card !== lastCard) { lastCard = card; setCardVisible(card); }
      if (fadeRef.current) {
        fadeRef.current.style.opacity = String(t > T_FADE ? smooth(T_FADE, T_LOOP, t) : t < 0.35 ? 1 - smooth(0, 0.35, t) : 0);
      }
    };

    /* layout */
    const resize = () => {
      const w = mount.clientWidth, h = mount.clientHeight;
      if (!w || !h) return;
      renderer.setSize(w, h);
      camera.aspect = w / h;
      const dist = 13.2 / Math.min(1, camera.aspect / 0.9);
      const dir = camera.position.clone().sub(controls.target).normalize();
      camera.position.copy(controls.target).add(dir.multiplyScalar(dist));
      camera.updateProjectionMatrix();
    };
    const ro = new ResizeObserver(resize);
    ro.observe(mount);
    resize();

    /* clock: pauses when scrolled out of view */
    let visible = true;
    const io = new IntersectionObserver(([e]) => (visible = e.isIntersecting));
    io.observe(mount);
    const reduce = window.matchMedia("(prefers-reduced-motion: reduce)").matches;
    timeRef.current = 0;
    let last = performance.now();
    renderer.setAnimationLoop((now) => {
      const dt = Math.min(0.05, (now - last) / 1000);
      last = now;
      if (!visible) return;
      timeRef.current += dt;
      if (timeRef.current > T_LOOP) timeRef.current = loop ? 0 : T_FADE - 0.01;
      const t = reduce ? T_REVEAL + 1.5 : timeRef.current;
      pose(t);
      controls.update();
      renderer.render(scene, camera);
    });

    return () => {
      disposed = true;
      renderer.setAnimationLoop(null);
      ro.disconnect();
      io.disconnect();
      controls.dispose();
      scene.traverse((o) => {
        const mesh = o as THREE.Mesh;
        if (mesh.geometry) mesh.geometry.dispose();
        const mat = mesh.material as THREE.Material | THREE.Material[] | undefined;
        (Array.isArray(mat) ? mat : mat ? [mat] : []).forEach((mm) => {
          const withMap = mm as THREE.MeshBasicMaterial;
          withMap.map?.dispose();
          mm.dispose();
        });
      });
      [ridgeTex, ...faceTextures].forEach((t) => t.dispose());
      faceMats.forEach((m) => m.dispose());
      (mirror as unknown as { dispose?: () => void }).dispose?.();
      envRT.dispose();
      pmrem.dispose();
      renderer.dispose();
      renderer.domElement.remove();
    };
    // eslint-disable-next-line react-hooks/exhaustive-deps
  }, [itemsKey, accent, background, loop, interactive, N]);

  const current = hud.mode === "item" ? items[hud.index] : null;
  const chip = hud.mode === "item" ? chips[hud.index] : undefined;

  return (
    <div
      className={cn("relative h-[620px] w-full overflow-hidden rounded-3xl", className)}
      style={{ background }}
    >
      <style>{`@keyframes ec-swap{from{opacity:0;transform:translateY(6px);filter:blur(3px)}to{opacity:1;transform:none;filter:none}}`}</style>
      <div ref={mountRef} className="absolute inset-0 cursor-grab active:cursor-grabbing" />
      <div
        className="pointer-events-none absolute inset-0"
        style={{ background: "radial-gradient(120% 90% at 50% 38%, rgba(255,255,255,0) 55%, rgba(196,201,210,.38) 100%)" }}
      />

      {showReplay && (
        <button
          type="button"
          onClick={() => (timeRef.current = 0)}
          className="absolute right-4 top-4 rounded-full bg-white/75 px-3.5 py-1.5 text-[13px] text-neutral-900 shadow-sm backdrop-blur transition hover:bg-white"
        >
          ↻ Replay
        </button>
      )}

      {/* status pill */}
      <div
        className={cn(
          "absolute bottom-[8%] left-1/2 flex max-w-[92%] -translate-x-1/2 items-center gap-2.5 whitespace-nowrap rounded-full bg-[#0d0e10] py-2 pl-2 pr-3.5 text-sm leading-none text-white shadow-[0_10px_30px_rgba(10,12,20,.18)] transition-all duration-500",
          pillVisible ? "opacity-100" : "pointer-events-none translate-y-3 opacity-0"
        )}
      >
        <span className="grid size-6 flex-none place-items-center overflow-hidden rounded-full">
          {hud.mode === "pack" && <span className="size-3.5 animate-spin rounded-full border-2 border-[#4a4e57] border-t-white" />}
          {hud.mode === "seal" && (
            <svg width="13" height="13" viewBox="0 0 24 24" fill="#fff" aria-hidden>
              <path d="M7 10V7a5 5 0 0 1 10 0v3h1a1 1 0 0 1 1 1v10a1 1 0 0 1-1 1H6a1 1 0 0 1-1-1V11a1 1 0 0 1 1-1h1zm2 0h6V7a3 3 0 0 0-6 0v3z" />
            </svg>
          )}
          {hud.mode === "item" && chip && <img src={chip} alt="" className="size-full" />}
        </span>
        <span key={hud.mode + (current?.title ?? "")} className="flex min-w-0 items-baseline gap-2 animate-[ec-swap_.38s_cubic-bezier(.2,.8,.2,1)]">
          <b className="font-semibold">{hud.mode === "pack" ? packingLabel : hud.mode === "seal" ? sealingLabel : current?.title}</b>
          {current && (
            <span className="truncate text-[13px] text-[#9aa0aa]">
              {[current.subtitle, current.meta].filter(Boolean).join(" · ")}
            </span>
          )}
        </span>
        <span className="h-3.5 w-px bg-[#3a3d44]" />
        <span className="text-[13px] tabular-nums text-[#9aa0aa]">
          {hud.mode === "pack" ? 0 : hud.mode === "seal" ? N : hud.index + 1}/{N}
        </span>
      </div>

      {/* ticket card */}
      {summary && (
        <div
          className={cn(
            "absolute bottom-[5%] left-1/2 w-[min(380px,90%)] -translate-x-1/2 rounded-3xl bg-white px-5 pb-4 pt-5 text-center text-neutral-900 shadow-[0_1px_0_rgba(0,0,0,.04),0_24px_60px_rgba(20,24,40,.14)] transition-all duration-700",
            cardVisible ? "translate-y-0 opacity-100" : "pointer-events-none translate-y-10 opacity-0"
          )}
        >
          {summary.eyebrow && <div className="text-[11px] uppercase tracking-[.12em] text-neutral-400">{summary.eyebrow}</div>}
          <div className="mt-1.5 text-3xl font-bold tracking-tight">{summary.title}</div>
          {summary.subtitle && <div className="mt-0.5 text-sm text-neutral-600">{summary.subtitle}</div>}
          <div className="mt-3 flex items-center justify-center gap-2.5 text-[13px] text-neutral-400">
            <div className="flex">
              {chips.filter(Boolean).map((src, i) => (
                <img key={i} src={src} alt={items[i]?.title ?? ""} className={cn("size-[22px] rounded-full ring-2 ring-white", i > 0 && "-ml-1.5")} />
              ))}
            </div>
            {summary.stat && <span>{summary.stat}</span>}
          </div>
          {(summary.highlight || summary.highlightSub || summary.footnote) && (
            <>
              <div className="relative -mx-5 my-4 border-t-[1.5px] border-dashed border-neutral-200">
                <span className="absolute -left-2.5 -top-2.5 size-5 rounded-full" style={{ background }} />
                <span className="absolute -right-2.5 -top-2.5 size-5 rounded-full" style={{ background }} />
              </div>
              {summary.highlight && <div className="text-[15px] font-semibold">{summary.highlight}</div>}
              {summary.highlightSub && <div className="mt-1 text-[12.5px] text-neutral-400">{summary.highlightSub}</div>}
              {summary.footnote && <div className="mt-2.5 text-[11.5px] text-neutral-300">{summary.footnote}</div>}
            </>
          )}
        </div>
      )}

      <div ref={fadeRef} className="pointer-events-none absolute inset-0 opacity-0" style={{ background }} />
    </div>
  );
}

/* -------------------------------------------------------------------------- */
/*                                    Demo                                    */
/* -------------------------------------------------------------------------- */

// Oldest first: the last coin lands on top of the stack.
// Each coin is a blank, coloured placeholder. Add `logo: "<image url>"` to any item
// to put a logo on its face.
const experience: CapsuleItem[] = [
  { title: "Company One", subtitle: "Intern", meta: "2019 – 2020", color: "#16181d" },
  { title: "Company Two", subtitle: "Junior Designer", meta: "2020 – 2021", color: "#f2c200" },
  { title: "Company Three", subtitle: "Designer", meta: "2021 – 2023", color: "#ef3340" },
  { title: "Company Four", subtitle: "Senior Designer", meta: "2023 – 2025", color: "#1b2a4a" },
  { title: "Company Five", subtitle: "Lead Designer", meta: "2025 – Present", color: "#1fa38a" },
];

export default function ExperienceCapsuleDemo() {
  return (
    <div className="flex min-h-screen w-full items-center justify-center bg-[#eef0f3] p-4">
      <ExperienceCapsule
        className="max-w-3xl"
        items={experience}
        packingLabel="Packing your experience…"
        summary={{
          eyebrow: "Experience capsule · sealed",
          title: "Your Name",
          subtitle: "Your Role",
          stat: "5 chapters · 2019 → today",
          highlight: "Now at Company Five",
          highlightSub: "Lead Designer · 2025 – Present",
          footnote: "Your degree · Year",
        }}
      />
    </div>
  );
}

Dependencies

More by Prayani

View all
  • Loading Animation

    Loading Animation

    200
  • Mesh Gradient

    Mesh Gradient

    20
  • ASCII Liquid Login

    ASCII Liquid Login

    11
  • Code Rain Reveal

    Code Rain Reveal

    4
  • ASCII winters

    ASCII winters