{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "double-take",
  "title": "Double Take",
  "description": "\"Read that again.\" above an oversized pink \"One person\" on blue.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/double-take/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/Outfit\";\nimport { useEffect, useMemo, 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 outfit = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface DoubleTakeProps {\n  text?: string;\n  focus?: string;\n  cue?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#2445E5\", ink: \"#FFFFFF\", accent: \"#FF8FB1\" },\n  light: { bg: \"#FFFFFF\", ink: \"#2445E5\", accent: \"#E0457B\" },\n} as const;\n\nconst WGHT = 500;\nconst TRACK = -0.035;\nconst MEASURE_PX = 100;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_CRAWL = Easing.bezier(0.42, 0, 0.62, 1);\nconst EASE_REWIND = Easing.bezier(0.5, 0, 0.12, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst IN_LEN = 14;\nconst IN_STAGGER = 3;\nconst CRAWL_AT = 16;\nconst PER_WORD = 6.5;\nconst STOP_HOLD = 8;\nconst REWIND_LEN = 24;\nconst CLEAR_LEN = 12;\nconst MIN_HOLD = 26;\n\nlet measureCtx: CanvasRenderingContext2D | null = null;\n\nfunction ctx2d() {\n  if (!measureCtx) {\n    measureCtx = document.createElement(\"canvas\").getContext(\"2d\");\n  }\n  if (!measureCtx) throw new Error(\"double-take: no 2d context\");\n  measureCtx.font = `${WGHT} ${MEASURE_PX}px \"${outfit.fontFamily}\"`;\n  return measureCtx;\n}\n\nfunction em(s: string) {\n  return (\n    ctx2d().measureText(s).width / MEASURE_PX + TRACK * Array.from(s).length\n  );\n}\n\nfunction useFontsReady() {\n  const [ready, setReady] = useState(false);\n  const [handle] = useState(() => delayRender(\"double-take: fonts\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      outfit.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${outfit.fontFamily}\"`),\n      document.fonts.load(`400 100px \"${outfit.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (live) setReady(true);\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [handle]);\n  return ready;\n}\n\ninterface Layout {\n  words: { text: string; x: number; w: number; focus: boolean }[];\n  lineW: number;\n  focusX0: number;\n  focusX1: number;\n  baseline: number;\n  cap: number;\n}\n\nfunction buildLayout(text: string, focus: string): Layout {\n  const tokens: { text: string; start: number; end: number }[] = [];\n  const re = /\\S+/g;\n  let m = re.exec(text);\n  while (m) {\n    tokens.push({ text: m[0], start: m.index, end: m.index + m[0].length });\n    m = re.exec(text);\n  }\n  const needle = focus.trim().toLowerCase();\n  let at = needle ? text.toLowerCase().indexOf(needle) : -1;\n  let end = at + needle.length;\n  if (at < 0) {\n    const last = tokens[tokens.length - 1];\n    at = last ? last.start : 0;\n    end = last ? last.end : 0;\n  }\n  const space = em(\" \");\n  let x = 0;\n  const words = tokens.map((tk) => {\n    const w = em(tk.text);\n    const out = {\n      text: tk.text,\n      x,\n      w,\n      focus: tk.end > at && tk.start < end,\n    };\n    x += w + space;\n    return out;\n  });\n  const lineW = em(tokens.map((tk) => tk.text).join(\" \"));\n  const fw = words.filter((w) => w.focus);\n  const focusX0 = fw.length ? fw[0].x : 0;\n  const focusX1 = fw.length ? fw[fw.length - 1].x + fw[fw.length - 1].w : 0;\n\n  const c = ctx2d();\n  const fm = c.measureText(\"Hxg\");\n  const asc = fm.fontBoundingBoxAscent / MEASURE_PX;\n  const desc = fm.fontBoundingBoxDescent / MEASURE_PX;\n  const cap = c.measureText(\"H\").actualBoundingBoxAscent / MEASURE_PX;\n  const baseline = (1 - asc - desc) / 2 + asc;\n  return { words, lineW, focusX0, focusX1, baseline, cap };\n}\n\nexport function DoubleTake({\n  text = \"One person wrote this entire launch video over a single lunch break.\",\n  focus = \"One person\",\n  cue = \"Read that again.\",\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: DoubleTakeProps) {\n  const frame = useCurrentFrame();\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  const ready = useFontsReady();\n\n  const layout = useMemo(\n    () => (ready ? buildLayout(text, focus) : null),\n    [ready, text, focus],\n  );\n\n  if (!layout) {\n    return (\n      <div style={{ position: \"absolute\", inset: 0, background: stage }} />\n    );\n  }\n\n  const portrait = H > W * 1.1;\n  const F = portrait ? W * 0.3 : H * 0.34;\n  const mx = W * (portrait ? 0.08 : 0.07);\n  const my = H * (portrait ? 0.07 : 0.1);\n  const { words, lineW, focusX0, focusX1, baseline, cap } = layout;\n\n  const crawlLen = Math.max(36, Math.min(120, words.length * PER_WORD));\n  const stopAt = CRAWL_AT + crawlLen;\n  const rewindAt = stopAt + STOP_HOLD;\n  const landAt = rewindAt + REWIND_LEN;\n  const motionEnd = landAt + CLEAR_LEN;\n  const room = durationInFrames * speed - MIN_HOLD;\n  const k = Math.max(0.55, Math.min(1, room / motionEnd));\n  const t = (frame * speed) / k;\n\n  const startLeft = mx;\n  const endLeft = Math.min(mx, W - mx - lineW * F);\n  const crawl = interpolate(t, [CRAWL_AT, stopAt], [0, 1], {\n    ...CLAMP,\n    easing: EASE_CRAWL,\n  });\n  const left = startLeft + (endLeft - startLeft) * crawl;\n  const centreAtStop = (W / 2 - endLeft) / F;\n\n  const focusW = focusX1 - focusX0;\n  const sF = Math.max(0.4, Math.min(1.25, (W * 0.84) / (focusW * F)));\n  const r = interpolate(t, [rewindAt, landAt], [0, 1], {\n    ...CLAMP,\n    easing: EASE_REWIND,\n  });\n  const zoom = interpolate(t, [rewindAt + REWIND_LEN * 0.35, landAt], [0, 1], {\n    ...CLAMP,\n    easing: Easing.bezier(0.45, 0, 0.2, 1),\n  });\n  const s = Math.exp(Math.log(sF) * zoom);\n  const focusCentre = (focusX0 + focusX1) / 2;\n\n  const rewinding = t >= rewindAt;\n  const fx = rewinding\n    ? centreAtStop + (focusCentre - centreAtStop) * r\n    : (W / 2 - left) / F;\n\n  const stripY = H * (portrait ? 0.52 : 0.55);\n  const lineTop = stripY + (cap / 2 - baseline) * F;\n\n  const tint = interpolate(t, [landAt - 10, landAt + 2], [0, 1], CLAMP);\n  const clear = interpolate(t, [landAt - 6, landAt + CLEAR_LEN], [1, 0], {\n    ...CLAMP,\n    easing: Easing.bezier(0.4, 0, 0.6, 1),\n  });\n  const focusColor = interpolateColors(tint, [0, 1], [c.ink, hi]);\n\n  const cueF = Math.max(16, (portrait ? W : H) * 0.07);\n  const cueIn = interpolate(t, [stopAt + 2, stopAt + 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  const clipTop = (baseline - 1.0) * F;\n  const clipH = 1.3 * F;\n  const fade = (mx * 0.9).toFixed(1);\n  const edgeMask = `linear-gradient(90deg, transparent 0px, #000 ${fade}px, #000 calc(100% - ${fade}px), transparent 100%)`;\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {cue ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: mx,\n            top: my - (baseline - cap) * cueF,\n            height: cueF * 1.3,\n            overflow: \"hidden\",\n          }}\n        >\n          <div\n            style={{\n              fontFamily: outfit.fontFamily,\n              fontWeight: 400,\n              fontSize: cueF,\n              lineHeight: `${cueF}px`,\n              letterSpacing: \"-0.015em\",\n              whiteSpace: \"pre\",\n              color: c.ink,\n              transform: `translateY(${((1 - cueIn) * 1.2 * cueF).toFixed(2)}px)`,\n            }}\n          >\n            {cue}\n          </div>\n        </div>\n      ) : null}\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          maskImage: edgeMask,\n          WebkitMaskImage: edgeMask,\n        }}\n      >\n        <div\n          style={{\n            position: \"absolute\",\n            left: 0,\n            top: 0,\n            transformOrigin: \"0 0\",\n            transform: `translate(${(W / 2).toFixed(2)}px, ${stripY.toFixed(2)}px) scale(${s.toFixed(5)}) translate(${(-fx * F).toFixed(2)}px, ${(-stripY).toFixed(2)}px)`,\n          }}\n        >\n          <div\n            style={{\n              position: \"absolute\",\n              left: -0.2 * F,\n              top: lineTop + clipTop,\n              width: (lineW + 0.6) * F,\n              height: clipH,\n              overflow: \"hidden\",\n            }}\n          >\n            {words.map((w, i) => {\n              const q = interpolate(\n                t,\n                [i * IN_STAGGER, i * IN_STAGGER + IN_LEN],\n                [0, 1],\n                { ...CLAMP, easing: EASE_OUT },\n              );\n              return (\n                <div\n                  key={`${i}-${w.text}`}\n                  style={{\n                    position: \"absolute\",\n                    left: (w.x + 0.2) * F,\n                    top: -clipTop,\n                    height: F,\n                    fontFamily: outfit.fontFamily,\n                    fontWeight: WGHT,\n                    fontSize: F,\n                    lineHeight: `${F}px`,\n                    letterSpacing: `${TRACK}em`,\n                    whiteSpace: \"pre\",\n                    color: w.focus ? focusColor : c.ink,\n                    opacity: w.focus ? 1 : clear,\n                    transform: `translateY(${((1 - q) * 1.15 * F).toFixed(2)}px)`,\n                  }}\n                >\n                  {w.text}\n                </div>\n              );\n            })}\n          </div>\n        </div>\n      </div>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/double-take.tsx"
    }
  ],
  "type": "registry:component"
}
