{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "flick-swap",
  "title": "Flick Swap",
  "description": "A headline flicks into place with a gradient second line, 'Grounds that never sit still.'.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/flick-swap/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadBricolage } from \"@remotion/google-fonts/BricolageGrotesque\";\nimport { loadFont as loadMono } from \"@remotion/google-fonts/JetBrainsMono\";\nimport type React from \"react\";\nimport { Fragment, useId } from \"react\";\nimport {\n  AbsoluteFill,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst bricolage = loadBricolage(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\nconst mono = loadMono(\"normal\", { weights: [\"500\"], subsets: [\"latin\"] });\n\nexport interface FlickSwapItem {\n  label?: string;\n  headline: string;\n  highlight?: string;\n}\n\nexport interface FlickSwapProps {\n  items?: FlickSwapItem[];\n  dwell?: number;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst DEFAULT_ITEMS: FlickSwapItem[] = [\n  {\n    label: \"Captions\",\n    headline: \"Every word lands on the beat.\",\n    highlight: \"on the beat\",\n  },\n  {\n    label: \"Transitions\",\n    headline: \"Cuts that feel expensive.\",\n    highlight: \"expensive\",\n  },\n  {\n    label: \"Backgrounds\",\n    headline: \"Grounds that never sit still.\",\n    highlight: \"never sit still\",\n  },\n];\n\nconst HALO = [\"#fff4ec\", \"#ffb36b\", \"#e2457a\", \"#3d4dff\"] as const;\n\nconst PALETTES = {\n  dark: {\n    bg: \"#0A0A0B\",\n    fg: \"#F4F3F0\",\n    muted: \"#8E8D94\",\n    rail: \"rgba(255,255,255,0.16)\",\n    wash: 0.2,\n    highlight: (accent: string) =>\n      `linear-gradient(90deg, ${HALO[1]} 0%, ${HALO[2]} 48%, color-mix(in oklab, ${accent} 70%, ${HALO[3]}) 100%)`,\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#111113\",\n    muted: \"#6E6C67\",\n    rail: \"rgba(17,17,19,0.16)\",\n    wash: 0.16,\n    highlight: (accent: string) =>\n      `linear-gradient(90deg, #e8762a 0%, ${HALO[2]} 45%, ${accent} 100%)`,\n  },\n} as const;\n\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nfunction springOffset(t: number, x0: number, v0: number) {\n  const w = 0.3;\n  const z = 0.72;\n  const wd = w * Math.sqrt(1 - z * z);\n  const e = Math.exp(-z * w * t);\n  return (\n    e * (x0 * Math.cos(wd * t) + ((v0 + z * w * x0) / wd) * Math.sin(wd * t))\n  );\n}\n\nconst DRAG = 7;\nconst DRAG_AMT = 0.07;\nconst SETTLE = 22;\n\nfunction scrollAt(f: number, n: number, period: number) {\n  if (f < 0) return -0.48;\n  let k = Math.min(n - 1, Math.floor(f / period));\n  const nextRelease = (k + 1) * period;\n  if (k < n - 1 && f >= nextRelease - DRAG) {\n    const t = (f - (nextRelease - DRAG)) / DRAG;\n    return k + DRAG_AMT * t * t;\n  }\n  k = Math.max(0, k);\n  const t = f - k * period;\n  if (k === 0) return springOffset(t, -0.48, 0.06);\n  return k + springOffset(t, DRAG_AMT - 1, 0.085);\n}\n\ninterface Word {\n  text: string;\n  index: number;\n  hl: [number, number] | null;\n}\n\nfunction splitWords(text: string, highlight?: string) {\n  const lower = text.toLowerCase();\n  const h0 = highlight ? lower.indexOf(highlight.toLowerCase()) : -1;\n  const h1 = h0 >= 0 && highlight ? h0 + highlight.length : -1;\n  const hLen = Math.max(1, h1 - h0);\n  const words: Word[] = [];\n  const re = /\\S+/g;\n  let index = 0;\n  for (let m = re.exec(text); m; m = re.exec(text)) {\n    const a = m.index;\n    const b = a + m[0].length;\n    const inside = h0 >= 0 && a < h1 && b > h0;\n    words.push({\n      text: m[0],\n      index: index++,\n      hl: inside\n        ? [(Math.max(a, h0) - h0) / hLen, (Math.min(b, h1) - h0) / hLen]\n        : null,\n    });\n  }\n  return words;\n}\n\nfunction phraseFill(\n  [a, b]: [number, number],\n  image: string,\n): React.CSSProperties {\n  const f = Math.max(0.02, b - a);\n  const K = 1 / f;\n  const P = K > 1 ? a / f / (K - 1) : 0;\n  return {\n    backgroundImage: image,\n    backgroundSize: `${K * 100}% 100%`,\n    backgroundPosition: `${P * 100}% 0%`,\n    WebkitBackgroundClip: \"text\",\n    backgroundClip: \"text\",\n    color: \"transparent\",\n  };\n}\n\nfunction estimateEm(text: string) {\n  let w = 0;\n  for (const ch of text) {\n    if (ch === \" \") w += 0.24;\n    else if (/[iljtf.,'’]/.test(ch)) w += 0.28;\n    else if (/[mwMW]/.test(ch)) w += 0.82;\n    else if (/[A-Z]/.test(ch)) w += 0.66;\n    else w += 0.53;\n  }\n  return w;\n}\n\nexport function FlickSwap({\n  items = DEFAULT_ITEMS,\n  dwell = 28,\n  accent = \"#3B5BFD\",\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: FlickSwapProps) {\n  const frame = useCurrentFrame() * speed;\n  const { width, height } = useVideoConfig();\n  const p = PALETTES[theme];\n  const uid = useId().replace(/[^a-zA-Z0-9_-]/g, \"\");\n  const transparent = background === \"transparent\";\n  const list = items.length > 0 ? items : DEFAULT_ITEMS;\n  const n = list.length;\n\n  const portrait = height > width * 1.1;\n  const s = portrait\n    ? (width / 1280) * 1.55\n    : Math.min(width / 1280, height / 720);\n  const padX = width * (portrait ? 0.08 : 0.09);\n  const maxW = portrait ? width - padX * 2 : width * 0.76;\n\n  const period = SETTLE + dwell;\n  const y = scrollAt(frame, n, period);\n  const v =\n    (scrollAt(frame + 0.5, n, period) - scrollAt(frame - 0.5, n, period)) *\n    height;\n  const speedPx = Math.abs(v);\n  const blur = Math.min(16 * s, speedPx * 0.13);\n  const lean = Math.max(-1.2, Math.min(1.2, (v / height) * 9));\n  const sway = (v / height) * 26 * s;\n\n  const baseFs = (portrait ? 150 : 118) * s;\n  const fsFor = (text: string) => {\n    const em = Math.max(1, estimateEm(text) * 1.04);\n    const three = Math.min(baseFs * (portrait ? 0.9 : 0.7), (maxW * 3) / em);\n    return Math.min(baseFs, Math.max((maxW * 2) / em, three));\n  };\n  const labelFs = (portrait ? 24 : 19) * s;\n\n  const gy = -y * 9;\n  const ground = [\n    `radial-gradient(48% 62% at 92% ${(64 + gy).toFixed(2)}%, color-mix(in oklab, ${HALO[2]} ${Math.round(p.wash * 100)}%, transparent) 0%, transparent 70%)`,\n    `radial-gradient(38% 50% at 70% ${(96 + gy).toFixed(2)}%, color-mix(in oklab, ${HALO[1]} ${Math.round(p.wash * 70)}%, transparent) 0%, transparent 70%)`,\n    `radial-gradient(55% 70% at 104% ${(30 + gy).toFixed(2)}%, color-mix(in oklab, ${HALO[3]} ${Math.round(p.wash * 120)}%, transparent) 0%, transparent 70%)`,\n  ].join(\", \");\n\n  const railGap = 26 * s;\n  const railH = railGap * (n - 1);\n  const railX = width - padX * (portrait ? 0.55 : 0.42);\n  const railTop = height / 2 - railH / 2;\n  const railY = railTop + Math.max(-0.3, Math.min(n - 0.7, y)) * railGap;\n  const railIn = interpolate(frame, [4, 16], [0, 1], CLAMP);\n\n  return (\n    <AbsoluteFill\n      style={{\n        background: transparent ? \"transparent\" : (background ?? p.bg),\n        overflow: \"hidden\",\n      }}\n    >\n      {!transparent && background === undefined ? (\n        <div style={{ position: \"absolute\", inset: 0, background: ground }} />\n      ) : null}\n\n      <svg width={0} height={0} style={{ position: \"absolute\" }} aria-hidden>\n        <defs>\n          <filter id={`fs-${uid}`} x=\"-5%\" y=\"-60%\" width=\"110%\" height=\"220%\">\n            <feGaussianBlur stdDeviation={`0 ${blur.toFixed(2)}`} />\n          </filter>\n        </defs>\n      </svg>\n\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          filter: blur > 0.4 ? `url(#fs-${uid})` : undefined,\n          transform: `translateX(${sway.toFixed(2)}px) rotate(${lean.toFixed(3)}deg)`,\n          transformOrigin: \"100% 100%\",\n        }}\n      >\n        {list.map((item, i) => {\n          const off = (i - y) * height;\n          if (Math.abs(off) > height * 1.05) return null;\n          const fs = fsFor(item.headline);\n          const words = splitWords(item.headline, item.highlight);\n          return (\n            <div\n              key={i}\n              style={{\n                position: \"absolute\",\n                left: padX,\n                top: 0,\n                height,\n                width: maxW,\n                display: \"flex\",\n                flexDirection: \"column\",\n                justifyContent: \"center\",\n                transform: `translateY(${off.toFixed(2)}px)`,\n              }}\n            >\n              {item.label ? (\n                <div\n                  style={{\n                    display: \"flex\",\n                    alignItems: \"center\",\n                    gap: labelFs * 0.8,\n                    marginBottom: fs * 0.32,\n                    fontFamily: mono.fontFamily,\n                    fontWeight: 500,\n                    fontSize: labelFs,\n                    letterSpacing: \"0.12em\",\n                    textTransform: \"uppercase\",\n                    color: p.muted,\n                  }}\n                >\n                  <span style={{ color: p.fg }}>\n                    {String(i + 1).padStart(2, \"0\")}\n                  </span>\n                  <span\n                    style={{\n                      width: labelFs * 1.6,\n                      height: Math.max(1, 1.5 * s),\n                      background: p.rail,\n                    }}\n                  />\n                  <span>{item.label}</span>\n                </div>\n              ) : null}\n              <div\n                style={{\n                  fontFamily: bricolage.fontFamily,\n                  fontWeight: 500,\n                  fontSize: fs,\n                  lineHeight: 1.02,\n                  letterSpacing: \"-0.035em\",\n                  color: p.fg,\n                  textWrap: \"balance\",\n                }}\n              >\n                {words.map((w, k) => {\n                  const lag =\n                    (0.5 + Math.min(1.1, k * 0.13)) / Math.max(0.25, speed);\n                  const rel =\n                    (y - scrollAt(frame - lag * speed, n, period)) * height;\n                  return (\n                    <Fragment key={w.index}>\n                      {k > 0 ? \" \" : null}\n                      <span\n                        style={{\n                          display: \"inline-block\",\n                          paddingRight: \"0.03em\",\n                          marginRight: \"-0.03em\",\n                          transform: `translateY(${rel.toFixed(2)}px)`,\n                          ...(w.hl\n                            ? phraseFill(w.hl, p.highlight(accent))\n                            : {}),\n                        }}\n                      >\n                        {w.text}\n                      </span>\n                    </Fragment>\n                  );\n                })}\n              </div>\n            </div>\n          );\n        })}\n      </div>\n\n      {n > 1 ? (\n        <div style={{ position: \"absolute\", inset: 0, opacity: railIn }}>\n          {list.map((_, i) => (\n            <div\n              key={i}\n              style={{\n                position: \"absolute\",\n                left: railX - 3 * s,\n                top: railTop + i * railGap - 3 * s,\n                width: 6 * s,\n                height: 6 * s,\n                borderRadius: 9,\n                background: p.rail,\n              }}\n            />\n          ))}\n          <div\n            style={{\n              position: \"absolute\",\n              left: railX - 3 * s,\n              top: railY - 11 * s,\n              width: 6 * s,\n              height: 22 * s,\n              borderRadius: 9,\n              background: p.fg,\n            }}\n          />\n        </div>\n      ) : null}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/flick-swap.tsx"
    }
  ],
  "type": "registry:component"
}
