{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "on-approach",
  "title": "on Approach",
  "description": "'Wheels up' stays fixed while the time phrase swaps from 'in June' down to 'today.'.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/on-approach/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/RedHatDisplay\";\nimport type React from \"react\";\nimport { useEffect, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst redHat = loadFont(\"normal\", {\n  weights: [\"400\", \"500\"],\n  subsets: [\"latin\"],\n});\n\nexport interface OnApproachProps {\n  lead?: string;\n  steps?: string[];\n  interval?: number;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: { bg: \"#B84A26\", ink: \"#FFF1E0\", accent: \"#8FD3FF\" },\n  light: { bg: \"#FFF1E0\", ink: \"#B84A26\", accent: \"#1B4F72\" },\n} as const;\n\nconst WGHT = 500;\nconst TRACK = -0.035;\nconst FONT_PX = 200;\nconst LEADING = 0.9;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_GROW = Easing.bezier(0.7, 0, 0.2, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst IN = 2;\nconst FIRST = 36;\nconst GROW = 18;\n\ninterface Metrics {\n  w: Record<string, number>;\n  asc: number;\n  desc: number;\n  cap: number;\n}\n\nfunction measureAll(texts: string[]): Metrics {\n  const canvas = document.createElement(\"canvas\");\n  const ctx = canvas.getContext(\"2d\");\n  if (!ctx) throw new Error(\"on-approach: no 2d context\");\n  ctx.font = `${WGHT} ${FONT_PX}px \"${redHat.fontFamily}\"`;\n  const w: Record<string, number> = {};\n  for (const s of texts) {\n    w[s] = ctx.measureText(s).width / FONT_PX + TRACK * Array.from(s).length;\n  }\n  const fm = ctx.measureText(\"Hxg\");\n  const h = ctx.measureText(\"H\");\n  return {\n    w,\n    asc: fm.fontBoundingBoxAscent / FONT_PX,\n    desc: fm.fontBoundingBoxDescent / FONT_PX,\n    cap: h.actualBoundingBoxAscent / FONT_PX,\n  };\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(\"on-approach: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      redHat.waitUntilDone(),\n      document.fonts.load(`${WGHT} 100px \"${redHat.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\nexport function OnApproach({\n  lead = \"Wheels up\",\n  steps = [\"in June.\", \"next week.\", \"tomorrow.\", \"today.\"],\n  interval = 30,\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: OnApproachProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = 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 = steps.length > 0 ? steps : [\"today.\"];\n  const leadSp = `${lead} `;\n  const m = useMetrics([leadSp, lead, ...list, ...list.map((s) => leadSp + s)]);\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 marginX = W * (portrait ? 0.08 : 0.06);\n  const marginY = H * (portrait ? 0.07 : 0.09);\n  const measureW = W - marginX * 2;\n  const measureH = H - marginY * 2;\n  const last = list.length - 1;\n\n  const finalSize = Math.min(\n    measureW / Math.max(m.w[lead], m.w[list[last]], 0.1),\n    measureH / (m.cap + LEADING + m.desc * 0.6),\n  );\n  const startSize = Math.min(\n    H * (portrait ? 0.035 : 0.075),\n    measureW / Math.max(0.1, m.w[leadSp + list[0]]),\n  );\n  const sizes = list.map((s, k) => {\n    if (k === last && last > 0) return finalSize;\n    const geo =\n      last > 0 ? startSize * (finalSize / startSize) ** (k / last) : finalSize;\n    return Math.min(geo, measureW / Math.max(0.1, m.w[leadSp + s]));\n  });\n\n  const stepAt = (k: number) => FIRST + (k - 1) * Math.max(16, interval);\n\n  let k = 0;\n  for (let i = 1; i <= last; i++) if (t >= stepAt(i)) k = i;\n  const g =\n    k > 0\n      ? interpolate(t, [stepAt(k), stepAt(k) + GROW], [0, 1], {\n          ...CLAMP,\n          easing: EASE_GROW,\n        })\n      : 1;\n  const moving = k > 0 && g < 1;\n  const from = Math.max(0, k - 1);\n  const to = k;\n  const size = moving ? sizes[from] + (sizes[to] - sizes[from]) * g : sizes[k];\n\n  const capTop = marginY;\n  const baseOf = (s: number) => capTop + m.cap * s;\n  const boxTop = (base: number, s: number) =>\n    base - ((1 - m.asc - m.desc) / 2 + m.asc) * s;\n\n  const textStyle = (s: number, color: string): React.CSSProperties => ({\n    position: \"absolute\",\n    height: s,\n    lineHeight: `${s}px`,\n    whiteSpace: \"pre\",\n    fontFamily: redHat.fontFamily,\n    fontWeight: WGHT,\n    fontSize: s,\n    letterSpacing: `${TRACK}em`,\n    color,\n  });\n\n  const intro = interpolate(t, [IN, IN + 18], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  const base = baseOf(size);\n  const nodes: React.ReactNode[] = [];\n  nodes.push(\n    <div\n      key=\"lead\"\n      style={{\n        ...textStyle(size, c.ink),\n        left: marginX,\n        top: boxTop(base, size),\n        opacity: intro,\n        transform: `translateY(${((1 - intro) * size * 0.6).toFixed(2)}px)`,\n      }}\n    >\n      {lead}\n    </div>,\n  );\n\n  const tailPos = (idx: number, s: number) => {\n    const b = baseOf(s);\n    if (idx === last && last > 0) {\n      return { x: marginX, base: b + LEADING * s };\n    }\n    return { x: marginX + m.w[leadSp] * s, base: b };\n  };\n\n  const tail = (idx: number, s: number, p: number, dir: 1 | -1) => {\n    const pos = tailPos(idx, s);\n    const clipTop = pos.base - (m.cap + 0.12) * s;\n    const clipH = (m.cap + 0.12 + m.desc * 0.9) * s;\n    const dy = dir * (1 - p) * (m.cap + 0.3) * s;\n    return (\n      <div\n        key={`tail-${idx}-${dir}`}\n        style={{\n          position: \"absolute\",\n          left: 0,\n          right: 0,\n          top: clipTop,\n          height: clipH,\n          overflow: \"hidden\",\n        }}\n      >\n        <div\n          style={{\n            ...textStyle(s, hi),\n            left: pos.x,\n            top: boxTop(pos.base, s) - clipTop,\n            transform: `translateY(${dy.toFixed(2)}px)`,\n          }}\n        >\n          {list[idx]}\n        </div>\n      </div>\n    );\n  };\n\n  if (moving) {\n    const out = interpolate(g, [0, 0.4], [0, 1], {\n      ...CLAMP,\n      easing: Easing.bezier(0.55, 0, 1, 0.45),\n    });\n    const inn = interpolate(g, [0.35, 1], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    if (out < 1) nodes.push(tail(from, size, 1 - out, -1));\n    if (inn > 0) nodes.push(tail(to, size, inn, 1));\n  } else {\n    const p = k === 0 ? intro : 1;\n    nodes.push(tail(k, size, p, 1));\n  }\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {nodes}\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/on-approach.tsx"
    }
  ],
  "type": "registry:component"
}
