{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "point-hop",
  "title": "Point Hop",
  "description": "A decimal figure 34.2 with a pink point that hops between digits, then a unit like microseconds.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/point-hop/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadGeist } from \"@remotion/google-fonts/Geist\";\nimport { loadFont as loadGeistMono } from \"@remotion/google-fonts/GeistMono\";\nimport { useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst geist = loadGeist(\"normal\", {\n  weights: [\"500\"],\n  subsets: [\"latin\"],\n});\nconst geistMono = loadGeistMono(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\n\nexport interface PointHopProps {\n  value?: number;\n  unit?: string;\n  prefixes?: string[];\n  label?: string;\n  accent?: string;\n  background?: string;\n  speed?: number;\n  theme?: \"dark\" | \"light\";\n}\n\nconst THEMES = {\n  dark: {\n    pink: \"#F472B6\",\n    bg: \"#14151A\",\n    ink: \"#FBF0DF\",\n    soft: \"rgba(251,240,223,0.62)\",\n  },\n  light: {\n    pink: \"#C2185B\",\n    bg: \"#FBF0DF\",\n    ink: \"#14151A\",\n    soft: \"rgba(20,21,26,0.62)\",\n  },\n} as const;\n\nconst TRACK = -0.02;\nconst UNIT_SCALE = 0.46;\n\nconst RISE_GAP = 1.6;\nconst RISE_LEN = 16;\nconst LABEL_AT = 6;\nconst FIRST_STEP = 34;\nconst HOP_LEN = 7;\nconst HOP_GAP = 1;\nconst SWAP_LEN = 12;\nconst FOLD_LEN = 14;\nconst STEP_REST = 12;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ninterface Plan {\n  digits: string[];\n  start: number;\n  steps: number;\n  foldAfter: number[];\n  pointLeaves: boolean;\n}\n\nfunction plan(value: number, maxSteps: number): Plan {\n  const v = Math.max(0, Math.abs(value));\n  let s = v.toFixed(12).replace(/0+$/, \"\");\n  if (s.endsWith(\".\")) s = s.slice(0, -1);\n  const [intPart, frac = \"\"] = s.split(\".\");\n  let steps = 0;\n  let scaled = v;\n  while (scaled > 0 && scaled < 1 && steps < maxSteps) {\n    scaled *= 1000;\n    steps++;\n  }\n  const end = intPart.length + steps * 3;\n  const digits = Array.from(intPart + frac);\n  while (digits.length < end) digits.push(\"0\");\n  const foldAfter = digits.map(() => -1);\n  for (let k = 1; k <= steps; k++) {\n    const slot = intPart.length + k * 3;\n    let i = 0;\n    while (i < slot - 1 && digits[i] === \"0\") {\n      if (foldAfter[i] < 0) foldAfter[i] = k;\n      i++;\n    }\n  }\n  return {\n    digits,\n    start: intPart.length,\n    steps,\n    foldAfter,\n    pointLeaves: end >= digits.length && steps > 0,\n  };\n}\n\ninterface Metrics {\n  digit: number;\n  point: number;\n  cap: number;\n  base: number;\n  units: number[];\n  label: number;\n}\n\nfunction measure(units: string[], label: string): Metrics {\n  const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n  if (!ctx) throw new Error(\"point-hop: no 2d context\");\n  ctx.font = `500 100px \"${geist.fontFamily}\"`;\n  const w = (s: string) => ctx.measureText(s).width / 100;\n  const digit = w(\"0000000000\") / 10;\n  const point = w(\".\");\n  const unitW = units.map((u) => w(u) + TRACK * Math.max(0, u.length - 1));\n  const m0 = ctx.measureText(\"0\");\n  const asc = m0.fontBoundingBoxAscent / 100;\n  const desc = m0.fontBoundingBoxDescent / 100;\n  ctx.font = `400 100px \"${geistMono.fontFamily}\"`;\n  return {\n    digit,\n    point,\n    cap: m0.actualBoundingBoxAscent / 100,\n    base: (1 - (asc + desc)) / 2 + asc,\n    units: unitW,\n    label: label ? w(label) : 0,\n  };\n}\n\nfunction useMetrics(units: string[], label: string) {\n  const key = [...units, label].join(\"\\u0001\");\n  const [state, setState] = useState<{ key: string; m: Metrics } | null>(null);\n  const [handle] = useState(() => delayRender(\"point-hop: measuring\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    Promise.all([\n      geist.waitUntilDone(),\n      geistMono.waitUntilDone(),\n      document.fonts.load(`500 100px \"${geist.fontFamily}\"`),\n      document.fonts.load(`400 100px \"${geistMono.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        if (!live) return;\n        const parts = key.split(\"\\u0001\");\n        setState({ key, m: measure(parts.slice(0, -1), parts.at(-1) ?? \"\") });\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\nfunction stepTimes(k: number) {\n  const stepLen = 3 * (HOP_LEN + HOP_GAP) + FOLD_LEN + STEP_REST;\n  const at = FIRST_STEP + (k - 1) * stepLen;\n  const hopsEnd = at + 3 * (HOP_LEN + HOP_GAP) - HOP_GAP;\n  return {\n    at,\n    hop: (h: number) => at + h * (HOP_LEN + HOP_GAP),\n    swapAt: hopsEnd - 6,\n    foldAt: hopsEnd - 2,\n  };\n}\n\nfunction stateAt(t: number, p: Plan, m: Metrics) {\n  let q = p.start;\n  let arc = 0;\n  let land = 0;\n  for (let k = 1; k <= p.steps; k++) {\n    const st = stepTimes(k);\n    for (let h = 0; h < 3; h++) {\n      const a = st.hop(h);\n      const raw = interpolate(t, [a, a + HOP_LEN], [0, 1], CLAMP);\n      const e = EASE_IO(raw);\n      q += e;\n      if (raw > 0 && raw < 1) arc = Math.sin(Math.PI * e);\n      const after = t - (a + HOP_LEN);\n      if (after >= 0 && after < 5) land = Math.sin((after / 5) * Math.PI);\n    }\n  }\n  const fold = p.digits.map((_, i) => {\n    const k = p.foldAfter[i];\n    if (k < 0) return 1;\n    const st = stepTimes(k);\n    return (\n      1 -\n      interpolate(t, [st.foldAt, st.foldAt + FOLD_LEN], [0, 1], {\n        ...CLAMP,\n        easing: EASE_IO,\n      })\n    );\n  });\n  const last = stepTimes(Math.max(1, p.steps));\n  const pointAlive = p.pointLeaves\n    ? 1 -\n      interpolate(t, [last.foldAt, last.foldAt + FOLD_LEN], [0, 1], {\n        ...CLAMP,\n        easing: EASE_IO,\n      })\n    : 1;\n  let unitIdx = 0;\n  let swap = 1;\n  for (let k = 1; k <= p.steps; k++) {\n    const st = stepTimes(k);\n    const s = interpolate(t, [st.swapAt, st.swapAt + SWAP_LEN], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    if (s > 0) {\n      unitIdx = k;\n      swap = s;\n    }\n  }\n  const Pw = (m.point + TRACK * 2) * pointAlive;\n  const D = m.digit + TRACK;\n  const prev = m.units[Math.max(0, unitIdx - 1)];\n  const unitW = prev + (m.units[unitIdx] - prev) * swap;\n  const xs: number[] = [];\n  let run = 0;\n  for (let i = 0; i < p.digits.length; i++) {\n    const gap = Pw * interpolate(i - q + 1, [0, 1], [0, 1], CLAMP);\n    xs.push(run + gap);\n    run += D * fold[i];\n  }\n  const digitsW = run + Pw;\n  const unitGap = 0.06;\n  const totalEm = digitsW + unitGap + unitW * UNIT_SCALE;\n  const qi = Math.min(Math.floor(q), p.digits.length);\n  let pointX = 0;\n  for (let i = 0; i < qi; i++) pointX += D * fold[i];\n  if (qi < p.digits.length) pointX += D * fold[qi] * (q - qi);\n  return {\n    arc,\n    land,\n    fold,\n    pointAlive,\n    unitIdx,\n    swap,\n    xs,\n    digitsW,\n    unitGap,\n    totalEm,\n    pointX,\n  };\n}\n\nexport function PointHop({\n  value = 0.0000342,\n  unit = \"s\",\n  prefixes = [\"\", \"m\", \"µ\", \"n\"],\n  label = \"scene refresh after a prop change\",\n  accent,\n  background,\n  speed = 1,\n  theme = \"dark\",\n}: PointHopProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n  const spot = accent ?? c.pink;\n  const pre = prefixes.length > 0 ? prefixes : [\"\"];\n  const p = useMemo(() => plan(value, pre.length - 1), [value, pre.length]);\n  const units = useMemo(\n    () => pre.slice(0, p.steps + 1).map((x) => x + unit),\n    [pre, p.steps, unit],\n  );\n  const m = useMetrics(units, label);\n\n  const transparent = background === \"transparent\";\n  const stage = transparent ? \"transparent\" : (background ?? c.bg);\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 margin = Math.min(W, H) * (portrait ? 0.08 : 0.085);\n  const measureW = W - 2 * margin;\n  const s = stateAt(t, p, m);\n  const fin = stateAt(1e6, p, m);\n\n  const maxF = H * (portrait ? 0.2 : 0.42);\n  const fitF = (em: number) => Math.min(maxF, measureW / em);\n  const F = fitF(s.totalEm);\n  const Fend = fitF(fin.totalEm);\n\n  const labelSize = label\n    ? Math.min(H * (portrait ? 0.022 : 0.036), measureW / m.label)\n    : 0;\n  const capTop = margin + (label ? labelSize * 1.2 + Fend * 0.5 : Fend * 0.3);\n  const baseY = capTop + m.cap * F;\n  const left = margin;\n\n  const arcH = (m.cap + 0.3) * F;\n  const maskTop = baseY - m.cap * F - arcH - F * 0.2;\n  const maskBottom = baseY + F * 0.24;\n  const glyphTop = (lift: number) => baseY - maskTop - m.base * F + lift;\n\n  const rise = (i: number) =>\n    interpolate(t, [i * RISE_GAP, i * RISE_GAP + RISE_LEN], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n  const drop = (r: number) => (1 - r) * (maskBottom - maskTop);\n\n  const text = {\n    position: \"absolute\" as const,\n    whiteSpace: \"pre\" as const,\n    fontFamily: geist.fontFamily,\n    fontWeight: 500,\n    fontFeatureSettings: '\"tnum\" 1, \"lnum\" 1',\n  };\n\n  const digitEls = p.digits.map((d, i) => {\n    const f = s.fold[i];\n    if (f <= 0.001) return null;\n    return (\n      <div\n        key={`d${i}`}\n        style={{\n          ...text,\n          left: left + s.xs[i] * F,\n          top: glyphTop(drop(rise(i))),\n          fontSize: F,\n          lineHeight: `${F}px`,\n          color: c.ink,\n          opacity: interpolate(f, [0, 0.7], [0, 1], CLAMP),\n          transform: f < 1 ? `scaleX(${f.toFixed(4)})` : undefined,\n          transformOrigin: \"0% 50%\",\n        }}\n      >\n        {d}\n      </div>\n    );\n  });\n\n  const squash = 1 - 0.18 * s.land;\n  const pointEl =\n    s.pointAlive > 0.001 ? (\n      <div\n        style={{\n          ...text,\n          left: left + (s.pointX + TRACK * 0.5) * F,\n          top: glyphTop(drop(rise(p.start)) - s.arc * arcH),\n          fontSize: F,\n          lineHeight: `${F}px`,\n          color: spot,\n          opacity: s.pointAlive,\n          transform: `scale(${(1 / squash).toFixed(3)}, ${squash.toFixed(3)}) scale(${(0.5 + 0.5 * s.pointAlive).toFixed(3)})`,\n          transformOrigin: `${(m.point * 50).toFixed(0)}% ${(m.base * 100).toFixed(0)}%`,\n        }}\n      >\n        .\n      </div>\n    ) : null;\n\n  const U = F * UNIT_SCALE;\n  const unitLeft = left + (s.digitsW + s.unitGap) * F;\n  const unitRise = rise(p.digits.length + 1);\n  const unitLine = (str: string, k: number, y: number, o: number) => (\n    <div\n      key={`u${k}`}\n      style={{\n        ...text,\n        left: unitLeft,\n        top: baseY - maskTop - m.base * U + y,\n        fontSize: U,\n        lineHeight: `${U}px`,\n        letterSpacing: `${TRACK}em`,\n        color: spot,\n        opacity: o,\n      }}\n    >\n      {str}\n    </div>\n  );\n  const unitDrop = (maskBottom - maskTop) * 0.5;\n  const unitEls =\n    s.unitIdx === 0 || s.swap >= 1\n      ? [unitLine(units[s.unitIdx], s.unitIdx, drop(unitRise), 1)]\n      : [\n          unitLine(\n            units[s.unitIdx - 1],\n            s.unitIdx - 1,\n            s.swap * unitDrop,\n            1 - s.swap,\n          ),\n          unitLine(\n            units[s.unitIdx],\n            s.unitIdx,\n            (s.swap - 1) * unitDrop,\n            s.swap,\n          ),\n        ];\n\n  const labelP = interpolate(t, [LABEL_AT, LABEL_AT + 16], [0, 1], {\n    ...CLAMP,\n    easing: EASE_OUT,\n  });\n\n  return (\n    <AbsoluteFill style={{ background: stage, overflow: \"hidden\" }}>\n      {label ? (\n        <div\n          style={{\n            position: \"absolute\",\n            left: margin,\n            top: margin,\n            height: labelSize * 1.3,\n            overflow: \"hidden\",\n            fontFamily: geistMono.fontFamily,\n            fontWeight: 400,\n            fontSize: labelSize,\n            lineHeight: `${labelSize * 1.3}px`,\n            color: c.soft,\n            whiteSpace: \"pre\",\n          }}\n        >\n          <div\n            style={{\n              transform: `translateY(${((1 - labelP) * labelSize * 1.4).toFixed(2)}px)`,\n            }}\n          >\n            {label}\n          </div>\n        </div>\n      ) : null}\n      <div\n        style={{\n          position: \"absolute\",\n          left: 0,\n          width: W,\n          top: maskTop,\n          height: maskBottom - maskTop,\n          overflow: \"hidden\",\n        }}\n      >\n        {digitEls}\n        {pointEl}\n        {unitEls}\n      </div>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/point-hop.tsx"
    }
  ],
  "type": "registry:component"
}
