{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "tittle-drop",
  "title": "Tittle Drop",
  "description": "Dots of the i and j drop in last onto 'Ship it in minutes.' on a light ground.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/tittle-drop/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/DMSans\";\nimport { useLayoutEffect, 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 face = loadFont(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\", \"latin-ext\"],\n});\n\nexport interface TittleDropProps {\n  /** The line. Every \"i\" and \"j\" is set dotless, a trailing \".\" is left open: the dots land there. */\n  title?: string;\n  /** Small grey line under the headline. */\n  subline?: string;\n  /** Which landing dot takes the accent (0-based, negative counts from the end). */\n  accentDot?: number;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\nconst THEMES = {\n  light: { bg: \"#FAFAF9\", fg: \"#0E0E0D\", muted: \"#8C8C88\", bubble: \"#EDEDEA\" },\n  dark: { bg: \"#0A0A0A\", fg: \"#F2F2F0\", muted: \"#7C7C79\", bubble: \"#1B1B1A\" },\n} as const;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IN_OUT = Easing.bezier(0.65, 0, 0.35, 1);\n\n// Beats, in frames at 30fps (before `speed`).\nconst BUBBLE_IN = 0;\nconst RISE = 30;\nconst RISE_LEN = 30;\nconst SET = 34;\nconst WORD_STAGGER = 5;\nconst SET_LEN = 24;\nconst HOP0 = 72;\nconst HOP_GAP = 12;\nconst HOP_LEN = 17;\nconst SHIFT_LEN = 9;\n/** The bubble is this much larger while it is alone on the stage. */\nconst SOLO_SCALE = 2.3;\n/** Bubble scale once it waits above the line. */\nconst REST_SCALE = 1.3;\nconst DOTLESS: Record<string, string> = { i: \"ı\", j: \"ȷ\" };\n\ninterface Ink {\n  left: number;\n  right: number;\n  top: number;\n  bottom: number;\n}\n\ninterface Target {\n  x: number;\n  y: number;\n  w: number;\n  h: number;\n  /** Index of the glyph span the dot crowns (-1 for the full stop). */\n  glyph: number;\n}\n\ninterface Layout {\n  rowW: number;\n  rowH: number;\n  targets: Target[];\n  /** Dot diameter in the bubble: the font's own tittle. */\n  dot: number;\n}\n\nconst clamp = { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\" } as const;\n\n/**\n * Ink box of a glyph relative to its origin and baseline, read off a canvas.\n * With `topPart`, only the topmost island of ink (the tittle) is measured.\n */\nfunction measureInk(\n  char: string,\n  family: string,\n  fontSize: number,\n  topPart: boolean,\n): Ink | null {\n  const k = 4;\n  const size = fontSize * k;\n  const canvas = document.createElement(\"canvas\");\n  canvas.width = Math.ceil(size * 2);\n  canvas.height = Math.ceil(size * 2);\n  const ctx = canvas.getContext(\"2d\", { willReadFrequently: true });\n  if (!ctx) return null;\n  const ox = Math.round(size * 0.5);\n  const by = Math.round(size * 1.3);\n  ctx.font = `400 ${size}px ${family}`;\n  ctx.textBaseline = \"alphabetic\";\n  ctx.fillStyle = \"#000\";\n  ctx.fillText(char, ox, by);\n  const { data, width, height } = ctx.getImageData(\n    0,\n    0,\n    canvas.width,\n    canvas.height,\n  );\n  const rowHasInk = (y: number) => {\n    for (let x = 0; x < width; x++)\n      if (data[(y * width + x) * 4 + 3] > 127) return true;\n    return false;\n  };\n  let top = -1;\n  for (let y = 0; y < height; y++) {\n    if (rowHasInk(y)) {\n      top = y;\n      break;\n    }\n  }\n  if (top < 0) return null;\n  let bottom = top;\n  if (topPart) {\n    while (bottom < height && rowHasInk(bottom)) bottom++;\n  } else {\n    for (let y = height - 1; y >= top; y--) {\n      if (rowHasInk(y)) {\n        bottom = y + 1;\n        break;\n      }\n    }\n  }\n  let left = width;\n  let right = 0;\n  for (let y = top; y < bottom; y++) {\n    for (let x = 0; x < width; x++) {\n      if (data[(y * width + x) * 4 + 3] > 127) {\n        if (x < left) left = x;\n        if (x + 1 > right) right = x + 1;\n      }\n    }\n  }\n  return {\n    left: (left - ox) / k,\n    right: (right - ox) / k,\n    top: (top - by) / k,\n    bottom: (bottom - by) / k,\n  };\n}\n\nfunction sameLayout(a: Layout | null, b: Layout) {\n  return (\n    a !== null &&\n    a.rowW === b.rowW &&\n    a.rowH === b.rowH &&\n    a.dot === b.dot &&\n    a.targets.map((t) => `${t.x},${t.y}`).join() ===\n      b.targets.map((t) => `${t.x},${t.y}`).join()\n  );\n}\n\nexport function TittleDrop({\n  title = \"Ship it in minutes.\",\n  subline = \"Launch videos from ready-made Remotion components.\",\n  accentDot = -1,\n  accent = \"#3B5BFD\",\n  theme = \"light\",\n  speed = 1,\n}: TittleDropProps) {\n  const frame = useCurrentFrame() * speed;\n  const { width, height } = useVideoConfig();\n  const t = THEMES[theme];\n\n  const fontSize = Math.round(width * 0.076);\n  const subSize = Math.round(width * 0.0165);\n  const chars = Array.from(title);\n  const hasStop = chars.at(-1) === \".\";\n  const wordOf: number[] = [];\n  chars.forEach((ch, i) => {\n    wordOf.push((wordOf[i - 1] ?? 0) + (ch === \" \" ? 1 : 0));\n  });\n\n  const rowRef = useRef<HTMLDivElement>(null);\n  const glyphRefs = useRef<(HTMLSpanElement | null)[]>([]);\n  const baseRef = useRef<HTMLSpanElement>(null);\n  const [layout, setLayout] = useState<Layout | null>(null);\n  const [handle] = useState(() => delayRender(\"tittle-drop: measuring\"));\n  const released = useRef(false);\n\n  // biome-ignore lint/correctness/useExhaustiveDependencies: re-measure when the copy or size changes\n  useLayoutEffect(() => {\n    let live = true;\n    face\n      .waitUntilDone()\n      .catch(() => undefined)\n      .then(() => document.fonts.ready)\n      .then(() => {\n        if (!live) return;\n        const row = rowRef.current;\n        const base = baseRef.current;\n        if (row && base) {\n          const family = face.fontFamily.includes('\"')\n            ? face.fontFamily\n            : `\"${face.fontFamily}\"`;\n          const rowRect = row.getBoundingClientRect();\n          // Studio scales the stage; work in unscaled composition pixels.\n          const scale = rowRect.width / row.offsetWidth || 1;\n          const baseline = base.offsetTop;\n          const inks: Record<string, Ink | null> = {};\n          const targets: Target[] = [];\n          chars.forEach((ch, i) => {\n            const isStop = hasStop && i === chars.length - 1;\n            if (!DOTLESS[ch] && !isStop) return;\n            const el = glyphRefs.current[i];\n            if (!el) return;\n            if (!(ch in inks))\n              inks[ch] = measureInk(ch, family, fontSize, !isStop);\n            const ink = inks[ch];\n            if (!ink) return;\n            const x0 = (el.getBoundingClientRect().left - rowRect.left) / scale;\n            targets.push({\n              x: x0 + (ink.left + ink.right) / 2,\n              y: baseline + (ink.top + ink.bottom) / 2,\n              w: ink.right - ink.left,\n              h: ink.bottom - ink.top,\n              glyph: isStop ? -1 : i,\n            });\n          });\n          const tittle = targets.find((x) => x.glyph >= 0);\n          const next: Layout = {\n            rowW: row.offsetWidth,\n            rowH: row.offsetHeight,\n            targets,\n            dot: tittle ? (tittle.w + tittle.h) / 2 : fontSize * 0.12,\n          };\n          setLayout((prev) => (sameLayout(prev, next) ? prev : next));\n        }\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n    };\n  }, [title, fontSize, handle]);\n\n  const targets = layout?.targets ?? [];\n  const n = targets.length;\n  const d = layout?.dot ?? fontSize * 0.12;\n  const accentIndex = n === 0 ? -1 : ((accentDot % n) + n) % n;\n\n  // The bubble: in, alone and large, then up to its place above the line.\n  const bubbleIn = interpolate(frame, [BUBBLE_IN, BUBBLE_IN + 16], [0, 1], {\n    ...clamp,\n    easing: EASE_OUT,\n  });\n  const rise = interpolate(frame, [RISE, RISE + RISE_LEN], [0, 1], {\n    ...clamp,\n    easing: EASE_IN_OUT,\n  });\n  const rowW = layout?.rowW ?? 0;\n  const rowH = layout?.rowH ?? 0;\n  const bubbleX = rowW / 2;\n  const bubbleY = interpolate(rise, [0, 1], [rowH / 2, -fontSize * 0.42]);\n  const bubbleScale =\n    interpolate(rise, [0, 1], [SOLO_SCALE, REST_SCALE]) *\n    interpolate(bubbleIn, [0, 1], [0.86, 1]);\n\n  // Queue: three dots wait in the bubble, the front one hops, the rest shuffle\n  // forward and a new one surfaces at the back until the line is dotted.\n  const hopStart = (k: number) => HOP0 + k * HOP_GAP;\n  let departed = 0;\n  for (let k = 0; k < n; k++) {\n    departed += interpolate(\n      frame,\n      [hopStart(k) + 2, hopStart(k) + 2 + SHIFT_LEN],\n      [0, 1],\n      { ...clamp, easing: EASE_IN_OUT },\n    );\n  }\n  const waiting = n === 0 ? 3 : Math.min(3, n - departed);\n  const gap = d * 2.05;\n  const padX = d * 1.35;\n  const bubbleW = 2 * padX + Math.max(0, waiting - 1) * gap + d;\n  const bubbleH = d * 3.3;\n  // Once the last dot leaves, the empty bubble folds away.\n  const empty = Math.min(1, waiting);\n  const bubbleOpacity = bubbleIn * empty ** 3;\n  const bubbleK = bubbleScale * (0.4 + 0.6 * empty);\n\n  const slotX = (slot: number) =>\n    bubbleX + (slot - (waiting - 1) / 2) * gap * bubbleScale;\n  const bounce = (slot: number) => {\n    const u = (((frame - slot * 5) % 26) + 26) % 26;\n    return u < 13 ? Math.sin((u / 13) * Math.PI) : 0;\n  };\n\n  let lastLand = HOP0;\n  if (n > 0) lastLand = hopStart(n - 1) + HOP_LEN;\n\n  const dots = targets.map((target, k) => {\n    const start = hopStart(k);\n    const land = start + HOP_LEN;\n    const isAccent = k === accentIndex;\n    const ink = isAccent ? accent : t.fg;\n    if (frame < start) {\n      const slot = k - departed;\n      if (slot > 3) return null;\n      const show = interpolate(slot, [2, 3], [1, 0], clamp);\n      const b = bounce(Math.round(slot));\n      const pre = interpolate(frame, [start - 3, start], [0, 1], clamp);\n      return {\n        key: k,\n        x: slotX(slot),\n        y: bubbleY - b * d * 0.42 * bubbleScale,\n        w: d * bubbleScale,\n        h: d * bubbleScale * (1 - pre * 0.22),\n        sx: 1 + pre * 0.12,\n        color: t.muted,\n        opacity: bubbleIn * show * (0.55 + 0.45 * b),\n      };\n    }\n    const p = interpolate(frame, [start, land], [0, 1], clamp);\n    const sx0 = slotX(0);\n    const x = interpolate(p, [0, 1], [sx0, target.x]);\n    const lift = fontSize * 0.42 + Math.max(0, bubbleY - target.y) * 0.5;\n    const y =\n      interpolate(p, [0, 1], [bubbleY, target.y]) - lift * 4 * p * (1 - p);\n    const dt = frame - land;\n    const squash = dt >= 0 ? Math.exp(-dt / 4.5) * Math.cos(dt * 0.5) * 0.3 : 0;\n    const stretch = dt < 0 ? Math.sin(p * Math.PI) * 0.12 : 0;\n    const colorP = interpolate(p, [0, 0.6], [0, 1], clamp);\n    return {\n      key: k,\n      x,\n      y,\n      w: interpolate(p, [0, 1], [d * bubbleScale, target.w]),\n      h: interpolate(p, [0, 1], [d * bubbleScale, target.h]),\n      sx: (1 + squash * 0.8) * (1 - stretch * 0.5),\n      sy: (1 - squash) * (1 + stretch),\n      color: interpolateColors(colorP, [0, 1], [t.muted, ink]),\n      opacity: 1,\n    };\n  });\n\n  // A tiny give in the stem the moment its dot lands.\n  const dip = (glyph: number) => {\n    const k = targets.findIndex((x) => x.glyph === glyph);\n    if (k < 0) return 0;\n    const dt = frame - (hopStart(k) + HOP_LEN);\n    if (dt < 0 || dt > 9) return 0;\n    return Math.sin((dt / 9) * Math.PI) * fontSize * 0.028;\n  };\n\n  const subStart = lastLand + 8;\n  const subP = interpolate(frame, [subStart, subStart + 30], [0, 1], {\n    ...clamp,\n    easing: EASE_OUT,\n  });\n\n  return (\n    <AbsoluteFill\n      style={{\n        background: t.bg,\n        alignItems: \"center\",\n        justifyContent: \"center\",\n        fontFamily: face.fontFamily,\n      }}\n    >\n      <div\n        ref={rowRef}\n        style={{\n          position: \"relative\",\n          whiteSpace: \"pre\",\n          fontSize,\n          fontWeight: 400,\n          letterSpacing: \"-0.03em\",\n          lineHeight: 1.2,\n          color: t.fg,\n          marginTop: height * 0.02,\n        }}\n      >\n        {chars.map((ch, i) => {\n          const isStop = hasStop && i === chars.length - 1;\n          const p = interpolate(\n            frame,\n            [\n              SET + wordOf[i] * WORD_STAGGER,\n              SET + wordOf[i] * WORD_STAGGER + SET_LEN,\n            ],\n            [0, 1],\n            { ...clamp, easing: EASE_OUT },\n          );\n          return (\n            <span\n              key={i}\n              ref={(el) => {\n                glyphRefs.current[i] = el;\n              }}\n              style={{\n                position: \"relative\",\n                top: (1 - p) * fontSize * 0.2 + dip(i),\n                opacity: isStop ? 0 : p,\n                filter: p < 1 ? `blur(${(1 - p) * 9}px)` : undefined,\n              }}\n            >\n              {DOTLESS[ch] ?? ch}\n            </span>\n          );\n        })}\n        <span\n          ref={baseRef}\n          style={{ display: \"inline-block\", width: 0, height: 0 }}\n        />\n        <div\n          style={{\n            position: \"absolute\",\n            left: bubbleX - (bubbleW * bubbleK) / 2,\n            top: bubbleY - (bubbleH * bubbleK) / 2,\n            width: bubbleW * bubbleK,\n            height: bubbleH * bubbleK,\n            borderRadius: (bubbleH * bubbleK) / 2,\n            background: t.bubble,\n            opacity: layout ? bubbleOpacity : 0,\n            filter: bubbleIn < 1 ? `blur(${(1 - bubbleIn) * 8}px)` : undefined,\n          }}\n        />\n        {layout\n          ? dots.map((dot) =>\n              dot ? (\n                <div\n                  key={dot.key}\n                  style={{\n                    position: \"absolute\",\n                    left: dot.x - dot.w / 2,\n                    top: dot.y - dot.h / 2,\n                    width: dot.w,\n                    height: dot.h,\n                    borderRadius: \"50%\",\n                    background: dot.color,\n                    opacity: dot.opacity,\n                    transformOrigin: \"50% 100%\",\n                    transform: `scale(${dot.sx}, ${dot.sy ?? 1})`,\n                  }}\n                />\n              ) : null,\n            )\n          : null}\n        <div\n          style={{\n            position: \"absolute\",\n            left: \"50%\",\n            top: \"100%\",\n            marginTop: fontSize * 0.36,\n            transform: `translate(-50%, ${(1 - subP) * 12}px)`,\n            whiteSpace: \"nowrap\",\n            fontSize: subSize,\n            letterSpacing: \"-0.005em\",\n            lineHeight: 1.4,\n            color: t.muted,\n            opacity: subP,\n            filter: `blur(${(1 - subP) * 8}px)`,\n          }}\n        >\n          {subline}\n        </div>\n      </div>\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/tittle-drop.tsx"
    }
  ],
  "type": "registry:component"
}
