{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "spine-turn",
  "title": "Spine Turn",
  "description": "Vertical titles turn like book spines, handing off to a large accent 'Wrap-up'.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/spine-turn/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadPlexSans } from \"@remotion/google-fonts/IBMPlexSans\";\nimport type React from \"react\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst plex = loadPlexSans(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface SpineTurnProps {\n  titles?: string[];\n  hold?: number;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: {\n    bg: \"#0F1B2D\",\n    spine: \"#7D8CA3\",\n    rule: \"rgba(243, 245, 248, 0.22)\",\n    accent: \"#FF9900\",\n  },\n  light: {\n    bg: \"#FFFFFF\",\n    spine: \"#8A96A8\",\n    rule: \"rgba(15, 27, 45, 0.2)\",\n    accent: \"#C76A00\",\n  },\n} as const;\n\nconst TRACK = -0.035;\nconst SPINE_TRACK = -0.01;\nconst BOX = 1.0;\nconst BASE = 0.8;\n\nconst ENTER = 16;\nconst TURN = 26;\nconst NEXT_LAG = 14;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_TURN = Easing.bezier(0.7, 0, 0.2, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nfunction measure(titles: string[]) {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"spine-turn: no 2d context\");\n  ctx.font = `500 100px \"${plex.fontFamily}\"`;\n  return titles.map((s) => {\n    const n = Array.from(s).length;\n    return {\n      hero: ctx.measureText(s).width / 100 + TRACK * Math.max(0, n - 1),\n      spine: ctx.measureText(s).width / 100 + SPINE_TRACK * Math.max(0, n - 1),\n    };\n  });\n}\n\nfunction useWidths(titles: string[]) {\n  const key = titles.join(\"\\u0001\");\n  const [state, setState] = useState<{\n    key: string;\n    w: { hero: number; spine: number }[];\n  } | null>(null);\n  const [handle] = useState(() => delayRender(\"spine-turn: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      plex.waitUntilDone(),\n      document.fonts.load(`500 100px \"${plex.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, w: measure(key.split(\"\\u0001\")) });\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [key, handle]);\n  return state && state.key === key ? state.w : null;\n}\n\nexport function SpineTurn({\n  titles = [\"Kickoff\", \"Deep dive\", \"Wrap-up\"],\n  hold = 26,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: SpineTurnProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n  const list = useMemo(() => {\n    const l = titles.filter((s) => s.trim().length > 0);\n    return l.length > 0 ? l : [\"remocn\"];\n  }, [titles]);\n  const widths = useWidths(list);\n\n  const transparent = background === \"transparent\";\n  const stage = transparent ? \"transparent\" : (background ?? c.bg);\n\n  if (!widths) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const n = list.length;\n  const portrait = H > W * 1.1;\n  const margin = Math.min(W, H) * 0.08;\n  const ruleY = H - margin;\n\n  const spineLen = H - margin * 2.4;\n  const longest = Math.max(...widths.slice(0, -1).map((w) => w.spine), 0.01);\n  const S = Math.min(\n    spineLen / longest,\n    Math.min(W, H) * (portrait ? 0.13 : 0.16),\n  );\n  const spineCol = S * BOX * 0.86;\n  const spineGap = S * 0.3;\n\n  const turnAt = (k: number) => ENTER + hold + k * (TURN + NEXT_LAG + hold);\n\n  const heroOf = (k: number) => {\n    const areaL = margin + k * (spineCol + spineGap) + (k > 0 ? S * 0.5 : 0);\n    const areaW = W - margin - areaL;\n    const F = Math.min(\n      (areaW * 0.94) / widths[k].hero,\n      H * (portrait ? 0.18 : 0.46),\n    );\n    const x = areaL;\n    const baseline = ruleY - F * 0.26;\n    return { F, x, baseline };\n  };\n\n  const spineOf = (k: number) => {\n    const x = margin + k * (spineCol + spineGap) + S * 0.78;\n    const y = ruleY - S * 0.3;\n    return { x, y };\n  };\n\n  const els: React.ReactNode[] = [];\n  list.forEach((title, k) => {\n    const isLast = k === n - 1;\n    const hero = heroOf(k);\n    const enterAt = k === 0 ? 0 : turnAt(k - 1) + NEXT_LAG;\n    const enter = interpolate(t, [enterAt, enterAt + ENTER], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    if (enter <= 0) return;\n    const turn = isLast\n      ? 0\n      : interpolate(t, [turnAt(k), turnAt(k) + TURN], [0, 1], {\n          ...CLAMP,\n          easing: EASE_TURN,\n        });\n    const spine = spineOf(k);\n    const ox = hero.x + (spine.x - hero.x) * turn;\n    const oy = hero.baseline + (spine.y - hero.baseline) * turn;\n    const size = hero.F + (S - hero.F) * turn;\n    const track = TRACK + (SPINE_TRACK - TRACK) * turn;\n    const rot = -90 * turn;\n\n    const glyphs = (\n      <div\n        key=\"glyphs\"\n        style={{\n          position: \"absolute\",\n          left: 0,\n          top: -BASE * size,\n          height: BOX * size,\n          lineHeight: `${BOX * size}px`,\n          whiteSpace: \"pre\",\n          fontFamily: plex.fontFamily,\n          fontWeight: 500,\n          fontSize: size,\n          letterSpacing: `${track}em`,\n          color:\n            turn > 0\n              ? `color-mix(in oklab, ${c.spine} ${(Math.min(1, turn * 1.4) * 100).toFixed(1)}%, ${accent ?? c.accent})`\n              : (accent ?? c.accent),\n        }}\n      >\n        {title}\n      </div>\n    );\n\n    const masked = enter < 1;\n    els.push(\n      <div\n        key={`t${k}`}\n        style={{\n          position: \"absolute\",\n          left: ox,\n          top: oy,\n          width: 0,\n          height: 0,\n          transform: `rotate(${rot.toFixed(3)}deg)`,\n          transformOrigin: \"0 0\",\n        }}\n      >\n        {masked ? (\n          <div\n            style={{\n              position: \"absolute\",\n              left: -size * 0.2,\n              top: -BASE * size - size * 0.1,\n              width: widths[k].hero * size + size * 0.4,\n              height: BOX * size + size * 0.12,\n              overflow: \"hidden\",\n            }}\n          >\n            <div\n              style={{\n                position: \"absolute\",\n                left: size * 0.2,\n                top: BASE * size + size * 0.1 + (1 - enter) * BOX * size * 1.05,\n              }}\n            >\n              {glyphs}\n            </div>\n          </div>\n        ) : (\n          glyphs\n        )}\n      </div>,\n    );\n  });\n\n  const ruleP = interpolate(t, [0, ENTER + 6], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      <div\n        style={{\n          position: \"absolute\",\n          left: margin,\n          top: ruleY,\n          width: (W - margin * 2) * ruleP,\n          height: Math.max(1, H * 0.0016),\n          background: c.rule,\n        }}\n      />\n      {els}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/spine-turn.tsx"
    }
  ],
  "type": "registry:component"
}
