{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "pass-swap",
  "title": "Pass Swap",
  "description": "An object passes across the frame and each pass swaps the headline to the next one.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/pass-swap/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadDisplay } from \"@remotion/google-fonts/HankenGrotesk\";\nimport type React from \"react\";\nimport { useId } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  Img,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: display } = loadDisplay(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\n\n/**\n * gradients.sh \"fluted\": ink blue, electric blue, ember orange, cream. The\n * objects carry it (the blue slot takes the accent) and so does the last word.\n */\nconst FLUTED = {\n  bg: \"#050507\",\n  colors: [\"#1d2a8f\", \"#2f7bff\", \"#ff7a3d\", \"#ffe2c4\"],\n} as const;\n\nexport interface PassSwapProps {\n  /** Headlines in order; each pass of the object swaps to the next one. */\n  lines?: string[];\n  /** Object when no `src` is given; \"mixed\" alternates slab and disc per pass. */\n  shape?: \"slab\" | \"disc\" | \"mixed\";\n  /** A product cutout (transparent PNG) to sweep instead of the shape. */\n  src?: string;\n  /** Fill the last word of the final line with the object gradient. */\n  accentLastWord?: boolean;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\n// Beat sheet (30fps), for three lines / two passes:\n//  0–20    first line settles in (rise + unblur)\n//  30–60   pass 1, left → right: the object crosses in front of the line;\n//          behind its center line the headline has already become line 2\n//  60–76   hold on line 2\n//  76–106  pass 2, right → left, swaps to the final line\n//  106–150 hold on the final line (poster frame)\nconst FIRST_PASS = 30;\nconst PASS_LEN = 30;\nconst PASS_GAP = 46;\nconst FINAL_HOLD = 44;\n\nexport function passSwapDuration(lineCount = 3) {\n  const passes = Math.max(1, lineCount - 1);\n  return FIRST_PASS + (passes - 1) * PASS_GAP + PASS_LEN + FINAL_HOLD;\n}\n\nconst SWEEP = Easing.bezier(0.62, 0, 0.36, 1);\nconst SETTLE = Easing.bezier(0.22, 1, 0.36, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst THEMES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F2F1EE\",\n    grain: 0.06,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#111113\",\n    grain: 0.04,\n  },\n} as const;\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `ps-grain-${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{ position: \"absolute\", inset: 0, opacity, pointerEvents: \"none\" }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.85\"\n          numOctaves={2}\n          seed={5}\n          stitchTiles=\"stitch\"\n        />\n        <feColorMatrix type=\"saturate\" values=\"0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\n/** Polygon (px) covering the half-plane on one side of a tilted line. */\nfunction halfPlane(\n  cx: number,\n  cy: number,\n  angleDeg: number,\n  side: 1 | -1,\n  L: number,\n) {\n  const th = (angleDeg * Math.PI) / 180;\n  const ax = Math.sin(th);\n  const ay = -Math.cos(th);\n  const nx = Math.cos(th) * side;\n  const ny = Math.sin(th) * side;\n  const pts = [\n    [cx + ax * L, cy + ay * L],\n    [cx + ax * L + nx * L, cy + ay * L + ny * L],\n    [cx - ax * L + nx * L, cy - ay * L + ny * L],\n    [cx - ax * L, cy - ay * L],\n  ];\n  return `polygon(${pts.map(([x, y]) => `${x.toFixed(1)}px ${y.toFixed(1)}px`).join(\", \")})`;\n}\n\nexport function PassSwap({\n  lines = [\"Copy the code.\", \"Own every frame.\", \"Ship the film.\"],\n  shape = \"mixed\",\n  src,\n  accentLastWord = true,\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: PassSwapProps) {\n  const frame = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const u = H / 720;\n  const c = THEMES[theme];\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const blurId = `ps-blur-${uid}`;\n\n  const safeLines = lines.length > 0 ? lines : [\"\"];\n  const passes = Math.max(0, safeLines.length - 1);\n  const longest = Math.max(...safeLines.map((l) => l.length), 1);\n  // Hanken Grotesk 500 at -0.035em averages ~0.47em per character.\n  const fs = Math.min(150 * u, (W * 0.86) / (longest * 0.47));\n\n  // Which pass is live (or last finished).\n  let index = 0;\n  let passP = -1;\n  for (let i = 0; i < passes; i++) {\n    const t0 = FIRST_PASS + i * PASS_GAP;\n    if (frame >= t0) {\n      index = i;\n      passP = (frame - t0) / PASS_LEN;\n    }\n  }\n  const passing = passP >= 0 && passP < 1;\n  const done = passP >= 1;\n  const dir: 1 | -1 = index % 2 === 0 ? 1 : -1;\n\n  // Object size: tall enough to hide the swap line across the whole cap height.\n  const isDisc =\n    !src && (shape === \"disc\" || (shape === \"mixed\" && index % 2 === 1));\n  const ow = src ? H * 0.62 : isDisc ? H * 0.7 : H * 0.34;\n  const oh = src ? H * 0.82 : isDisc ? H * 0.7 : H * 0.92;\n  const radius = isDisc ? oh / 2 : ow / 2;\n\n  const travel = W + ow * 1.6;\n  const sweepAt = (p: number) => {\n    const e = SWEEP(Math.min(1, Math.max(0, p)));\n    const x = -ow * 0.8 + e * travel;\n    return dir === 1 ? x : W - x;\n  };\n  const cx = sweepAt(passP);\n  const vel =\n    Math.abs(\n      sweepAt(passP + 0.5 / PASS_LEN) - sweepAt(passP - 0.5 / PASS_LEN),\n    ) * speed;\n  const tilt = dir * interpolate(passP, [0, 1], [11, 4], CLAMP);\n  const cy = H / 2 + interpolate(passP, [0, 0.5, 1], [10, 0, -10], CLAMP) * u;\n\n  const fromLine = safeLines[Math.min(index, safeLines.length - 1)];\n  const toLine = safeLines[Math.min(index + 1, safeLines.length - 1)];\n  const current = passes === 0 ? safeLines[0] : done ? toLine : fromLine;\n\n  // First line arrives.\n  const intro = interpolate(frame, [0, 22], [0, 1], {\n    ...CLAMP,\n    easing: SETTLE,\n  });\n  // New line is dragged a touch by the object and settles.\n  const tStart = FIRST_PASS + index * PASS_GAP;\n  const drag = interpolate(\n    frame,\n    [tStart + PASS_LEN * 0.3, tStart + PASS_LEN + 16],\n    [1, 0],\n    { ...CLAMP, easing: SETTLE },\n  );\n  const toOffset = -dir * 26 * u * drag;\n\n  // The last word takes the palette's warm end on dark, the deep end on light.\n  const ink =\n    theme === \"dark\"\n      ? [\n          FLUTED.colors[2],\n          `color-mix(in oklab, ${FLUTED.colors[2]} 50%, ${FLUTED.colors[3]})`,\n          FLUTED.colors[3],\n        ]\n      : [\n          FLUTED.colors[0],\n          accent,\n          `color-mix(in oklab, ${accent} 70%, ${FLUTED.colors[2]})`,\n        ];\n\n  const finalIdx = safeLines.length - 1;\n  const renderLine = (text: string, lineIdx: number) => {\n    const isFinal = lineIdx === finalIdx && accentLastWord && passes > 0;\n    const cut = isFinal ? text.trimEnd().lastIndexOf(\" \") : -1;\n    const head = cut >= 0 ? text.slice(0, cut + 1) : text;\n    const tail = cut >= 0 ? text.slice(cut + 1) : \"\";\n    return (\n      <div\n        style={{\n          fontFamily: display,\n          fontWeight: 500,\n          fontSize: fs,\n          letterSpacing: \"-0.035em\",\n          lineHeight: 1,\n          color: c.fg,\n          whiteSpace: \"pre\",\n          textAlign: \"center\",\n        }}\n      >\n        {head}\n        {tail && (\n          <span\n            style={{\n              backgroundImage: `linear-gradient(100deg, ${ink.join(\", \")})`,\n              WebkitBackgroundClip: \"text\",\n              backgroundClip: \"text\",\n              color: \"transparent\",\n              // keeps the clip box wide enough for the final glyph's overhang\n              paddingRight: \"0.04em\",\n              marginRight: \"-0.04em\",\n            }}\n          >\n            {tail}\n          </span>\n        )}\n      </div>\n    );\n  };\n\n  const lineBox = (\n    text: string,\n    lineIdx: number,\n    extra: React.CSSProperties,\n  ) => (\n    <AbsoluteFill\n      style={{\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        ...extra,\n      }}\n    >\n      {renderLine(text, lineIdx)}\n    </AbsoluteFill>\n  );\n\n  const L = W * 3;\n  const blur = Math.min(vel * 0.09, 14 * u);\n\n  // One palette, two flat readings: the slab is a blue column warming at its\n  // foot, the disc a low sun going from cream to ember to blue. The angle\n  // drifts a few degrees with the pass.\n  const [f0, , f2, f3] = FLUTED.colors;\n  const f1 = accent;\n  const drift = passP * 10;\n  const slabFill = `linear-gradient(${180 - drift}deg, ${f0} 0%, ${f1} 42%, color-mix(in oklab, ${f1} 50%, ${f2}) 74%, ${f2} 100%)`;\n  const discFill = `linear-gradient(${170 + drift}deg, ${f3} 0%, color-mix(in oklab, ${f3} 40%, ${f2}) 26%, ${f2} 52%, color-mix(in oklab, ${f2} 45%, ${f1}) 78%, ${f1} 100%)`;\n\n  const object = src ? (\n    <Img\n      src={src}\n      style={{ width: \"100%\", height: \"100%\", objectFit: \"contain\" }}\n    />\n  ) : (\n    <div\n      style={{\n        width: \"100%\",\n        height: \"100%\",\n        borderRadius: radius,\n        background: isDisc ? discFill : slabFill,\n        boxShadow: `inset 0 ${1.5 * u}px 0 rgba(255,255,255,0.28), inset 0 0 0 1px rgba(255,255,255,0.08)`,\n      }}\n    />\n  );\n\n  return (\n    <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n      <svg width={0} height={0} style={{ position: \"absolute\" }} aria-hidden>\n        <filter\n          id={blurId}\n          x=\"-40%\"\n          y=\"-10%\"\n          width=\"180%\"\n          height=\"120%\"\n          colorInterpolationFilters=\"sRGB\"\n        >\n          <feGaussianBlur stdDeviation={`${blur} 0`} />\n        </filter>\n      </svg>\n\n      {passing ? (\n        <>\n          {lineBox(fromLine, index, {\n            clipPath: halfPlane(cx, cy, tilt, dir, L),\n          })}\n          {lineBox(toLine, index + 1, {\n            clipPath: halfPlane(cx, cy, tilt, -dir as 1 | -1, L),\n            transform: `translateX(${toOffset}px)`,\n          })}\n        </>\n      ) : (\n        lineBox(current, done ? index + 1 : index, {\n          opacity: index === 0 && !done ? intro : 1,\n          transform: `translateX(${done ? toOffset : 0}px) translateY(${index === 0 && !done ? (1 - intro) * 14 * u : 0}px)`,\n          filter:\n            index === 0 && !done && intro < 1\n              ? `blur(${(1 - intro) * 10 * u}px)`\n              : undefined,\n        })\n      )}\n\n      {passing && (\n        <div\n          style={{\n            position: \"absolute\",\n            left: cx - ow / 2,\n            top: cy - oh / 2,\n            width: ow,\n            height: oh,\n            transform: `rotate(${tilt}deg)`,\n            filter: blur > 0.4 ? `url(#${blurId})` : undefined,\n          }}\n        >\n          {object}\n        </div>\n      )}\n\n      <Grain opacity={c.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/pass-swap.tsx"
    }
  ],
  "type": "registry:component"
}
