{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "what-sticks",
  "title": "What Sticks",
  "description": "A column of claims dims one by one until \"You own every file.\" is highlighted.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/what-sticks/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Rubik\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  interpolateColors,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst rubik = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface WhatSticksProps {\n  lines?: string[];\n  keep?: number;\n  moments?: string[];\n  forget?: number[];\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#2A1033\", ink: \"#FFFFFF\", accent: \"#7CC4FF\", ghost: 0.17 },\n  light: { bg: \"#F3EEF5\", ink: \"#2A1033\", accent: \"#2B7BD6\", ghost: 0.2 },\n} as const;\n\nconst DEFAULT_LINES = [\n  \"Scenes install with one command.\",\n  \"Every word on screen is a prop.\",\n  \"Transitions land on the beat.\",\n  \"Captions come from the transcript.\",\n  \"You own every file.\",\n  \"It renders on your laptop.\",\n];\n\nconst DEFAULT_MOMENTS = [\n  \"Tonight, you’ll remember all of it.\",\n  \"Tomorrow, about half.\",\n  \"Next week, just this.\",\n];\n\nconst WGHT = 500;\nconst TRACK = -0.025;\nconst LH = 1.2;\nconst SLUG = 0.5;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN_OUT = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ntype Metrics = Record<string, number>;\n\nfunction measureAll(texts: string[]): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"what-sticks: no 2d context\");\n  ctx.font = `${WGHT} 100px \"${rubik.fontFamily}\"`;\n  const w: Metrics = {};\n  for (const s of texts) {\n    w[s] = ctx.measureText(s).width / 100 + TRACK * Array.from(s).length;\n  }\n  return w;\n}\n\nfunction useMetrics(texts: string[]) {\n  const key = texts.join(\"\\u0001\");\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"what-sticks: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      rubik.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${rubik.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        setState({ key, m: measureAll(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.m : null;\n}\n\nconst lineW = (words: string[], m: Metrics) =>\n  m[words.join(\" \")] ?? words.reduce((a, w) => a + m[w], 0);\n\nfunction splitTwo(text: string, m: Metrics): string[] {\n  const words = text.split(\" \").filter(Boolean);\n  if (words.length < 2) return [text];\n  let best: string[] = [text];\n  let bestW = Number.POSITIVE_INFINITY;\n  for (let cut = 1; cut < words.length; cut++) {\n    const a = words.slice(0, cut).join(\" \");\n    const b = words.slice(cut).join(\" \");\n    const w = Math.max(m[a], m[b]);\n    if (w < bestW) {\n      bestW = w;\n      best = [a, b];\n    }\n  }\n  return best;\n}\n\nfunction prefixes(text: string): string[] {\n  const words = text.split(\" \").filter(Boolean);\n  const out: string[] = [];\n  for (let i = 1; i <= words.length; i++) {\n    out.push(words.slice(0, i).join(\" \"));\n    out.push(words.slice(i).join(\" \"));\n  }\n  return out;\n}\n\nconst hash = (i: number, salt: number) => {\n  const x = Math.sin(i * 127.1 + salt * 311.7) * 43758.5453;\n  return x - Math.floor(x);\n};\n\nexport function WhatSticks({\n  lines = DEFAULT_LINES,\n  keep,\n  moments = DEFAULT_MOMENTS,\n  forget,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: WhatSticksProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const c = THEMES[theme];\n  const hi = accent ?? c.accent;\n  const stage =\n    background === \"transparent\" ? \"transparent\" : (background ?? c.bg);\n\n  const list = lines.length > 0 ? lines : DEFAULT_LINES;\n  const steps = moments.length > 0 ? moments : DEFAULT_MOMENTS;\n  const n = list.length;\n  const kept = Math.min(\n    n - 1,\n    Math.max(0, keep ?? Math.min(n - 1, Math.floor(n * 0.7))),\n  );\n\n  const m = useMetrics([...list.flatMap(prefixes), ...steps]);\n\n  if (!m) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const portrait = H > W * 1.1;\n  const availW = W * (portrait ? 0.84 : 0.8);\n  let F = 0;\n  let blocks: string[][] = [];\n  for (const L of [1, 2]) {\n    const target = Math.max(\n      ...list.map((s) => Math.max(...splitTwo(s, m).map((r) => m[r]))),\n    );\n    const b = list.map((s) =>\n      L === 1 || m[s] <= target ? [s] : splitTwo(s, m),\n    );\n    const widest = Math.max(\n      0.1,\n      ...b.flat().map((r) => lineW([r], m)),\n      ...steps.map((s) => m[s] * SLUG),\n    );\n    const rows = b.reduce((a, x) => a + x.length, 0);\n    const size = Math.min(\n      H * (portrait ? 0.062 : 0.092),\n      availW / widest,\n      (H * (portrait ? 0.7 : 0.8)) / (rows * LH + SLUG * 1.6 + 0.9),\n    );\n    if (size > F * 1.12) {\n      F = size;\n      blocks = b;\n    }\n  }\n\n  const S = F * SLUG;\n  const slugH = S * 1.5;\n  const gapAfterSlug = F * 0.75;\n  const rowH = F * LH;\n  const totalRows = blocks.reduce((a, x) => a + x.length, 0);\n  const blockH = slugH + gapAfterSlug + totalRows * rowH;\n  const top = (H - blockH) / 2;\n\n  const others = list.map((_, i) => i).filter((i) => i !== kept);\n  const order =\n    forget && forget.length > 0\n      ? [\n          ...forget.filter((i) => i !== kept && i >= 0 && i < n),\n          ...others.filter((i) => !forget.includes(i)),\n        ]\n      : [...others].sort((a, b) => hash(a, n) - hash(b, n));\n\n  const stepCount = Math.max(1, steps.length);\n  const span = durationInFrames * speed;\n  const enterOf = (i: number) => 10 + i * 5;\n  const first = enterOf(n - 1) + 18 + 30;\n  const gap =\n    stepCount > 2\n      ? Math.min(90, Math.max(42, (span - first - 100) / (stepCount - 2)))\n      : 0;\n  const stepAt = (s: number) => first + (s - 1) * gap;\n\n  const forgottenAt = new Map<number, { step: number; rank: number }>();\n  if (stepCount > 1) {\n    let done = 0;\n    for (let s = 1; s < stepCount; s++) {\n      const target = Math.round(((n - 1) * s) / (stepCount - 1));\n      for (let r = 0; done < target; r++, done++) {\n        forgottenAt.set(order[done], { step: s, rank: r });\n      }\n    }\n  }\n\n  const slugIndex = (() => {\n    let k = 0;\n    for (let s = 1; s < stepCount; s++) if (t >= stepAt(s)) k = s;\n    return k;\n  })();\n\n  const nodes: React.ReactNode[] = [];\n\n  for (let s = 0; s < stepCount; s++) {\n    const tin = s === 0 ? 0 : stepAt(s);\n    const tout = s + 1 < stepCount ? stepAt(s + 1) : Number.POSITIVE_INFINITY;\n    if (t < tin - 1 || t > tout + 14) continue;\n    if (Math.abs(s - slugIndex) > 1) continue;\n    const enter = s === 0 ? tin : tin + 6;\n    const pin = interpolate(t, [enter, enter + 14], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    const pout = Number.isFinite(tout)\n      ? interpolate(t, [tout, tout + 5], [0, 1], {\n          ...CLAMP,\n          easing: EASE_IN_OUT,\n        })\n      : 0;\n    const last = s === stepCount - 1;\n    nodes.push(\n      <div\n        key={`slug-${s}`}\n        style={{\n          position: \"absolute\",\n          left: 0,\n          width: W,\n          top,\n          height: slugH,\n          overflow: \"hidden\",\n        }}\n      >\n        <div\n          style={{\n            width: \"100%\",\n            textAlign: \"center\",\n            fontFamily: rubik.fontFamily,\n            fontWeight: 400,\n            fontSize: S,\n            lineHeight: `${slugH}px`,\n            letterSpacing: \"-0.005em\",\n            whiteSpace: \"pre\",\n            color: last\n              ? interpolateColors(\n                  Math.min(Math.max(t, tin + 6), tin + 20),\n                  [tin + 6, tin + 20],\n                  [c.ink, hi],\n                )\n              : c.ink,\n            opacity: (0.72 + (last ? 0.28 : 0)) * (1 - pout) * pin,\n            transform: `translateY(${((1 - pin) * slugH * 0.6).toFixed(2)}px)`,\n          }}\n        >\n          {steps[s]}\n        </div>\n      </div>,\n    );\n  }\n\n  let row = 0;\n  const finalStep = stepCount - 1;\n  const glowAt = stepAt(Math.max(1, finalStep)) + 22;\n  for (let i = 0; i < n; i++) {\n    const rows = blocks[i];\n    const y0 = top + slugH + gapAfterSlug + row * rowH;\n    row += rows.length;\n    const d = enterOf(i);\n    if (t < d - 1) continue;\n    const pin = interpolate(t, [d, d + 18], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    const f = forgottenAt.get(i);\n    let alpha = 1;\n    if (f) {\n      const fs = stepAt(f.step) + 10 + f.rank * 5;\n      alpha = interpolate(t, [fs, fs + 20], [1, c.ghost], {\n        ...CLAMP,\n        easing: EASE_IN_OUT,\n      });\n    }\n    const isKept = i === kept && stepCount > 1;\n    const glow = isKept\n      ? interpolate(t, [glowAt, glowAt + 18], [0, 1], {\n          ...CLAMP,\n          easing: EASE_IN_OUT,\n        })\n      : 0;\n    const color = isKept ? interpolateColors(glow, [0, 1], [c.ink, hi]) : c.ink;\n    nodes.push(\n      <div\n        key={`line-${i}`}\n        style={{\n          position: \"absolute\",\n          left: 0,\n          width: W,\n          top: y0 - F * 0.12,\n          height: rows.length * rowH + F * 0.24,\n          overflow: \"hidden\",\n          opacity: alpha,\n          transform: `scale(${1 + glow * 0.05})`,\n          transformOrigin: \"50% 50%\",\n        }}\n      >\n        <div\n          style={{\n            paddingTop: F * 0.12,\n            transform: `translateY(${((1 - pin) * rowH * 0.9).toFixed(2)}px)`,\n          }}\n        >\n          {rows.map((r) => (\n            <div\n              key={r}\n              style={{\n                width: \"100%\",\n                height: rowH,\n                textAlign: \"center\",\n                fontFamily: rubik.fontFamily,\n                fontWeight: WGHT,\n                fontSize: F,\n                lineHeight: `${rowH}px`,\n                letterSpacing: `${TRACK}em`,\n                whiteSpace: \"pre\",\n                color,\n              }}\n            >\n              {r}\n            </div>\n          ))}\n        </div>\n      </div>,\n    );\n  }\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {nodes}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/what-sticks.tsx"
    }
  ],
  "type": "registry:component"
}
