{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "motion-flip-sequence",
  "type": "registry:component",
  "title": "Motion Flip Sequence",
  "description": "A pinned card that flips in 3D from one step to the next as you scroll, swapping faces while its back is turned. A sheen crosses the card mid-flip, the floor shadow squeezes, and a deck behind shows the steps left.",
  "author": "Hyperblur <hello@hyperblur.dev>",
  "dependencies": [],
  "registryDependencies": [],
  "categories": [
    "motion",
    "scroll",
    "3d",
    "flip",
    "steps",
    "cards",
    "pinned"
  ],
  "docs": "https://hyperblur.dev/effects/motion-flip-sequence",
  "files": [
    {
      "path": "registry/hyperblur/motion-flip-sequence.tsx",
      "type": "registry:component",
      "target": "components/hyperblur/motion-flip-sequence.tsx",
      "content": "\"use client\";\n\nimport * as React from \"react\";\n\nexport interface MotionFlipSequenceFace {\n  step: string;\n  title: string;\n  text: string;\n  metric: string;\n  metricLabel: string;\n  from: string;\n  to: string;\n}\n\nexport interface MotionFlipSequenceProps extends Omit<React.HTMLAttributes<HTMLElement>, \"title\"> {\n  faces?: MotionFlipSequenceFace[];\n  accent?: string;\n  progress?: number;\n  autoPlay?: boolean;\n  duration?: number;\n  length?: number;\n  height?: string;\n}\n\nconst defaultFaces: MotionFlipSequenceFace[] = [\n  { step: \"Plan\", title: \"Scope the sprint in one board\", text: \"Drag issues in, set the goal, and the estimate updates live.\", metric: \"14\", metricLabel: \"issues\", from: \"#1b2f6b\", to: \"#4d7dff\" },\n  { step: \"Build\", title: \"Preview every branch\", text: \"Each push gets its own link with comments pinned to the page.\", metric: \"3m\", metricLabel: \"to preview\", from: \"#2c1659\", to: \"#9a6bff\" },\n  { step: \"Ship\", title: \"Release behind a flag\", text: \"Roll out to 5% first, watch errors, then open the gate.\", metric: \"5%\", metricLabel: \"canary\", from: \"#0d3f3a\", to: \"#2fd1ad\" },\n  { step: \"Learn\", title: \"See what people actually used\", text: \"Adoption, drop-off and feedback land on the same card.\", metric: \"+22%\", metricLabel: \"activation\", from: \"#4b2210\", to: \"#ff8c4a\" },\n];\n\nconst css = `\n.hb-wh5 {\n  --hb-wh5-a: #2f7bff;\n  position: relative;\n  width: 100%;\n  height: var(--hb-wh5-h);\n  color: #ededed;\n  font-family: inherit;\n  background: #0a0a0a;\n}\n.hb-wh5[data-pinned=\"true\"] { height: calc(var(--hb-wh5-h) * var(--hb-wh5-len)); }\n.hb-wh5 *, .hb-wh5 *::before, .hb-wh5 *::after { box-sizing: border-box; }\n.hb-wh5-stage {\n  position: sticky;\n  top: 0;\n  height: var(--hb-wh5-h);\n  overflow: hidden;\n  container-type: size;\n  display: grid;\n  grid-template-columns: auto 1fr;\n  align-items: center;\n  gap: 5cqw;\n  padding: 6cqh max(14px, 6cqw);\n  background:\n    radial-gradient(50% 70% at 70% 50%, color-mix(in srgb, var(--hb-wh5-a) 10%, transparent), transparent 70%),\n    #0a0a0a;\n}\n.hb-wh5-steps {\n  margin: 0;\n  padding: 0;\n  list-style: none;\n  display: grid;\n  gap: clamp(4px, 2.6cqh, 22px);\n}\n.hb-wh5-step {\n  display: flex;\n  align-items: center;\n  gap: 0.7em;\n  font-size: clamp(9px, 2.6cqh, 16px);\n  font-weight: 500;\n  color: #5e5e5e;\n  transition: color 0.4s ease;\n}\n.hb-wh5-step b {\n  display: grid;\n  place-items: center;\n  width: 1.9em;\n  height: 1.9em;\n  border-radius: 50%;\n  border: 1px solid #2a2a2a;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: 0.78em;\n  font-weight: 500;\n  transition: border-color 0.4s ease, background 0.4s ease, color 0.4s ease;\n}\n.hb-wh5-step[data-on=\"true\"] { color: #ededed; }\n.hb-wh5-step[data-on=\"true\"] b { border-color: var(--hb-wh5-a); background: var(--hb-wh5-a); color: #fff; }\n.hb-wh5-step[data-done=\"true\"] b { border-color: color-mix(in srgb, var(--hb-wh5-a) 55%, #333); color: color-mix(in srgb, var(--hb-wh5-a) 60%, #fff); }\n.hb-wh5-name { display: none; }\n.hb-wh5-scene {\n  position: relative;\n  display: grid;\n  place-items: center;\n  height: 100%;\n  perspective: 1100px;\n}\n.hb-wh5-deck {\n  position: absolute;\n  width: min(86%, 100cqh, 560px);\n  aspect-ratio: 16 / 10;\n  border-radius: clamp(10px, 3cqh, 22px);\n  border: 1px solid #222;\n  background: linear-gradient(180deg, #151515, #0f0f0f);\n  transform: translate(calc(var(--k) * 10px), calc(var(--k) * 8px)) scale(calc(1 - var(--k) * 0.04));\n  opacity: calc(0.8 - var(--k) * 0.25);\n}\n.hb-wh5-card {\n  position: relative;\n  width: min(86%, 100cqh, 560px);\n  aspect-ratio: 16 / 10;\n  transform-style: preserve-3d;\n  will-change: transform;\n}\n.hb-wh5-side {\n  position: absolute;\n  inset: 0;\n  display: flex;\n  flex-direction: column;\n  justify-content: space-between;\n  padding: clamp(10px, 5%, 30px);\n  border-radius: clamp(10px, 3cqh, 22px);\n  overflow: hidden;\n  backface-visibility: hidden;\n  -webkit-backface-visibility: hidden;\n  background: linear-gradient(140deg, var(--to), var(--from) 62%, #0b0b0b);\n  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.18), inset 0 0 0 1px rgba(255, 255, 255, 0.06);\n  container-type: inline-size;\n}\n.hb-wh5-back { transform: rotateY(180deg); }\n.hb-wh5-side::before {\n  content: \"\";\n  position: absolute;\n  inset: 0;\n  background: linear-gradient(105deg, transparent 30%, rgba(255, 255, 255, 0.28) 48%, transparent 62%);\n  transform: translateX(calc(var(--hb-wh5-sheen, 0) * 140% - 70%));\n  pointer-events: none;\n}\n.hb-wh5-side::after {\n  content: \"\";\n  position: absolute;\n  right: -12%;\n  top: -30%;\n  width: 60%;\n  aspect-ratio: 1;\n  border-radius: 50%;\n  border: 1px solid rgba(255, 255, 255, 0.16);\n  box-shadow: 0 0 0 18px rgba(255, 255, 255, 0.03), 0 0 0 40px rgba(255, 255, 255, 0.025);\n  pointer-events: none;\n}\n.hb-wh5-top {\n  position: relative;\n  display: flex;\n  justify-content: space-between;\n  align-items: center;\n  font-family: var(--font-mono, ui-monospace, monospace);\n  font-size: clamp(7px, 3.4cqw, 13px);\n  letter-spacing: 0.14em;\n  text-transform: uppercase;\n  color: rgba(255, 255, 255, 0.72);\n}\n.hb-wh5-title {\n  position: relative;\n  margin: 0;\n  max-width: 15ch;\n  font-family: var(--font-grotesk, var(--font-sans, system-ui));\n  font-size: clamp(12px, 8.4cqw, 38px);\n  font-weight: 600;\n  line-height: 1.04;\n  letter-spacing: -0.03em;\n  color: #fff;\n}\n.hb-wh5-low {\n  position: relative;\n  display: flex;\n  align-items: flex-end;\n  justify-content: space-between;\n  gap: 1em;\n}\n.hb-wh5-text {\n  margin: 0;\n  max-width: 30ch;\n  font-size: clamp(7px, 3.6cqw, 15px);\n  line-height: 1.4;\n  color: rgba(255, 255, 255, 0.74);\n}\n.hb-wh5-metric { text-align: right; flex: none; }\n.hb-wh5-metric b {\n  display: block;\n  font-family: var(--font-grotesk, var(--font-sans, system-ui));\n  font-size: clamp(12px, 9cqw, 40px);\n  font-weight: 600;\n  line-height: 1;\n  letter-spacing: -0.03em;\n  color: #fff;\n}\n.hb-wh5-metric span { font-size: clamp(6px, 2.8cqw, 12px); color: rgba(255, 255, 255, 0.6); }\n.hb-wh5-shadow {\n  position: absolute;\n  left: 50%;\n  bottom: 6%;\n  width: min(70%, 80cqh, 460px);\n  height: 18px;\n  border-radius: 50%;\n  background: radial-gradient(closest-side, rgba(0, 0, 0, 0.8), transparent);\n  transform: translateX(-50%) scaleX(var(--hb-wh5-sq, 1));\n  filter: blur(6px);\n  pointer-events: none;\n}\n@container (max-width: 460px) {\n  .hb-wh5-stage { grid-template-columns: 1fr; grid-template-rows: 1fr auto; gap: 3cqh; padding: 5cqh 14px; }\n  .hb-wh5-steps { order: 2; display: flex; justify-content: center; gap: 0.9em; }\n  .hb-wh5-step span { display: none; }\n  .hb-wh5-text { display: none; }\n}\n@container (min-width: 700px) {\n  .hb-wh5-name { display: inline; }\n}\n@media (prefers-reduced-motion: reduce) {\n  .hb-wh5-step, .hb-wh5-step b { transition: none; }\n}\n`;\n\nfunction clamp01(x: number) {\n  return Math.min(1, Math.max(0, x));\n}\n\nfunction inOut(x: number) {\n  return x < 0.5 ? 4 * x * x * x : 1 - Math.pow(-2 * x + 2, 3) / 2;\n}\n\nfunction findScroller(el: HTMLElement): HTMLElement | null {\n  let node = el.parentElement;\n  while (node && node !== document.body && node !== document.documentElement) {\n    const oy = getComputedStyle(node).overflowY;\n    if ((oy === \"auto\" || oy === \"scroll\" || oy === \"overlay\") && node.scrollHeight > node.clientHeight + 1) return node;\n    node = node.parentElement;\n  }\n  return null;\n}\n\nfunction loopAt(ms: number, duration: number) {\n  const d = Math.max(1, duration) * 1000;\n  const back = d * 0.4;\n  const hold = 1400;\n  const t = ms % (d + hold + back + 900);\n  if (t < d) return t / d;\n  if (t < d + hold) return 1;\n  if (t < d + hold + back) return 1 - inOut((t - d - hold) / back);\n  return 0;\n}\n\nfunction useProgress(\n  ref: React.RefObject<HTMLElement | null>,\n  apply: (p: number) => void,\n  progress: number | undefined,\n  autoPlay: boolean,\n  duration: number,\n) {\n  const applyRef = React.useRef(apply);\n  React.useLayoutEffect(() => {\n    applyRef.current = apply;\n  });\n  React.useEffect(() => {\n    const el = ref.current;\n    if (!el) return;\n    const run = (p: number) => applyRef.current(clamp01(p));\n    if (typeof progress === \"number\") {\n      run(progress);\n      return;\n    }\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) {\n      run(1);\n      return;\n    }\n    let raf = 0;\n    if (autoPlay) {\n      let visible = true;\n      let last = 0;\n      let t = 0;\n      const io = new IntersectionObserver((entries) => {\n        visible = entries[0]?.isIntersecting ?? true;\n      });\n      io.observe(el);\n      const loop = (now: number) => {\n        const dt = last ? Math.min(64, now - last) : 0;\n        last = now;\n        if (visible) {\n          t += dt;\n          run(loopAt(t, duration));\n        }\n        raf = requestAnimationFrame(loop);\n      };\n      raf = requestAnimationFrame(loop);\n      return () => {\n        cancelAnimationFrame(raf);\n        io.disconnect();\n      };\n    }\n    const sc = findScroller(el);\n    const measure = () => {\n      raf = 0;\n      const r = el.getBoundingClientRect();\n      const top = sc ? r.top - sc.getBoundingClientRect().top : r.top;\n      const vh = sc ? sc.clientHeight : window.innerHeight;\n      const span = r.height - vh;\n      run(span > 1 ? -top / span : (vh - top) / (vh + r.height));\n    };\n    const onScroll = () => {\n      if (!raf) raf = requestAnimationFrame(measure);\n    };\n    measure();\n    const target: HTMLElement | Window = sc ?? window;\n    target.addEventListener(\"scroll\", onScroll, { passive: true });\n    window.addEventListener(\"resize\", onScroll);\n    return () => {\n      cancelAnimationFrame(raf);\n      target.removeEventListener(\"scroll\", onScroll);\n      window.removeEventListener(\"resize\", onScroll);\n    };\n  }, [ref, progress, autoPlay, duration]);\n}\n\nfunction angleAt(p: number, n: number) {\n  if (n < 2) return 0;\n  const s = clamp01(p) * (n - 1);\n  const k = Math.min(n - 2, Math.floor(s));\n  const local = s - k;\n  const flip = inOut(clamp01((local - 0.25) / 0.5));\n  return (k + flip) * 180;\n}\n\nfunction Side({ face, index, total, back, hidden }: { face: MotionFlipSequenceFace; index: number; total: number; back?: boolean; hidden: boolean }) {\n  return (\n    <div\n      aria-hidden={hidden ? \"true\" : undefined}\n      className={back ? \"hb-wh5-side hb-wh5-back\" : \"hb-wh5-side\"}\n      style={{ \"--from\": face.from, \"--to\": face.to } as React.CSSProperties}\n    >\n      <div className=\"hb-wh5-top\">\n        <span>{face.step}</span>\n        <span>\n          {String(index + 1).padStart(2, \"0\")} / {String(total).padStart(2, \"0\")}\n        </span>\n      </div>\n      <h3 className=\"hb-wh5-title\">{face.title}</h3>\n      <div className=\"hb-wh5-low\">\n        <p className=\"hb-wh5-text\">{face.text}</p>\n        <div className=\"hb-wh5-metric\">\n          <b>{face.metric}</b>\n          <span>{face.metricLabel}</span>\n        </div>\n      </div>\n    </div>\n  );\n}\n\nexport function MotionFlipSequence({\n  faces = defaultFaces,\n  accent = \"#2f7bff\",\n  progress,\n  autoPlay = false,\n  duration = 6,\n  length = 4,\n  height = \"100vh\",\n  className,\n  style,\n  ...rest\n}: MotionFlipSequenceProps) {\n  const ref = React.useRef<HTMLElement>(null);\n  const n = Math.max(1, faces.length);\n  const [angle, setAngle] = React.useState(() => angleAt(typeof progress === \"number\" ? progress : 0, n));\n  const pinned = progress === undefined && !autoPlay;\n\n  useProgress(\n    ref,\n    (p) => {\n      const a = Math.round(angleAt(p, n) * 10) / 10;\n      setAngle((old) => (old === a ? old : a));\n    },\n    progress,\n    autoPlay,\n    duration,\n  );\n\n  const frontIndex = Math.min(n - 1, 2 * Math.floor((angle + 270) / 360));\n  const backIndex = Math.min(n - 1, 2 * Math.floor((angle + 90) / 360) + 1);\n  const turn = ((angle % 360) + 360) % 360;\n  const frontUp = turn < 90 || turn >= 270;\n  const active = Math.min(n - 1, Math.round(angle / 180));\n  const local = (angle % 180) / 180;\n  const sheen = Math.sin(local * Math.PI);\n  const rem = n - 1 - active;\n\n  return (\n    <section\n      ref={ref}\n      className={[\"hb-wh5\", className].filter(Boolean).join(\" \")}\n      data-pinned={pinned ? \"true\" : \"false\"}\n      style={\n        {\n          \"--hb-wh5-a\": accent,\n          \"--hb-wh5-h\": height,\n          \"--hb-wh5-len\": length,\n          ...style,\n        } as React.CSSProperties\n      }\n      {...rest}\n    >\n      <style href=\"hb-motion-flip-sequence\" precedence=\"default\">{css}</style>\n      <div className=\"hb-wh5-stage\">\n        <ol className=\"hb-wh5-steps\">\n          {faces.map((f, i) => (\n            <li\n              key={f.step}\n              className=\"hb-wh5-step\"\n              data-on={i === active ? \"true\" : \"false\"}\n              data-done={i < active ? \"true\" : \"false\"}\n              aria-current={i === active ? \"step\" : undefined}\n            >\n              <b>{i + 1}</b>\n              <span>\n                {f.step}\n                <span className=\"hb-wh5-name\"> · {f.metric} {f.metricLabel}</span>\n              </span>\n            </li>\n          ))}\n        </ol>\n        <div className=\"hb-wh5-scene\">\n          {Array.from({ length: Math.min(2, rem) }, (_, k) => (\n            <span key={k} className=\"hb-wh5-deck\" aria-hidden=\"true\" style={{ \"--k\": 2 - k } as React.CSSProperties} />\n          ))}\n          <span\n            className=\"hb-wh5-shadow\"\n            aria-hidden=\"true\"\n            style={{ \"--hb-wh5-sq\": Math.abs(Math.cos((angle * Math.PI) / 180)).toFixed(3) } as React.CSSProperties}\n          />\n          <div\n            className=\"hb-wh5-card\"\n            style={\n              {\n                transform: `translateY(${(-sheen * 6).toFixed(2)}%) rotateY(${angle.toFixed(1)}deg) rotateX(${(sheen * 6).toFixed(2)}deg)`,\n                \"--hb-wh5-sheen\": local.toFixed(3),\n              } as React.CSSProperties\n            }\n          >\n            <Side face={faces[frontIndex]} index={frontIndex} total={n} hidden={!frontUp} />\n            <Side face={faces[backIndex]} index={backIndex} total={n} back hidden={frontUp} />\n          </div>\n        </div>\n      </div>\n    </section>\n  );\n}\n"
    }
  ]
}