{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"drop-line","type":"registry:component","title":"Drop Line","description":"Words cut past one card at a time, then the last word sinks out from under the dot of its own i","dependencies":["remotion","@remotion/google-fonts"],"docs":"Needs a Remotion project. If a frame renders black, the component is drawing on a transparent layer: put a background behind it, e.g. <AbsoluteFill style={{ background: \"#faf9f6\" }}><Component /></AbsoluteFill>. Pass mode=\"dark\" for dark frames.","registryDependencies":["https://kuchi.kalarislabs.com/r/kuchi-ui.json"],"files":[{"path":"components/kuchi/drop-line/index.tsx","type":"registry:component","target":"components/kuchi/drop-line/index.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { loadFont } from \"@remotion/google-fonts/Inter\";\r\nimport type { ReactNode } from \"react\";\r\nimport { useId } from \"react\";\r\nimport { AbsoluteFill, useCurrentFrame, useVideoConfig } from \"remotion\";\r\nimport { type KuchiTheme, useKuchiTheme } from \"@/lib/kuchi-ui\";\r\nimport { BASELINE, DOT_LINE, DROP, FONT_SIZE, HOLDS, RISE } from \"./data\";\r\n\r\nconst { fontFamily: inter } = loadFont(\"normal\", { weights: [\"700\"] });\r\n\r\nconst STAGE_W = 1920;\r\nconst STAGE_H = 1080;\r\n/** Words may fill this much of the stage width before they scale down to fit. */\r\nconst MAX_WIDTH = STAGE_W * 0.9;\r\nconst DOTTED = /[ij]/;\r\n\r\n/**\r\n * Drop Line: words cut in place, the first rising into position, and on the last\r\n * card the word sinks out from under its own dot. The dot holds its position, so\r\n * the sentence ends on one mark left hanging. A last word with no \"i\" or \"j\" just\r\n * drops whole.\r\n */\r\nexport interface DropLineProps {\r\n  /** One word per card; the last one drops. */\r\n  words?: string[];\r\n  fontFamily?: string;\r\n  fontWeight?: number;\r\n  /** Type size on a 1920x1080 stage. */\r\n  fontSize?: number;\r\n  /** Size per word on that stage, for faces that set a card differently. */\r\n  wordSize?: number[];\r\n  /** Horizontal nudge per word, in stage px, for optical centring. */\r\n  wordNudge?: number[];\r\n  /** Tracking per word in em. */\r\n  wordTracking?: number[];\r\n  /** Per-letter offsets per word, in em. */\r\n  wordKerning?: number[][];\r\n  /** The card. Defaults to the theme foreground. */\r\n  ink?: string;\r\n  /** The type. Defaults to the theme background. */\r\n  paper?: string;\r\n  speed?: number;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n}\r\n\r\n/** Sample a measured table at a fractional frame; holds both ends. */\r\nexport const sample = (table: readonly number[], at: number) => {\r\n  const x = Math.max(0, Math.min(at, table.length - 1));\r\n  const i = Math.floor(x);\r\n  const a = table[i] ?? 0;\r\n  return a + ((table[i + 1] ?? a) - a) * (x - i);\r\n};\r\n\r\n/** Frame each word cuts in, the frame the last card ends, and when its drop table starts. */\r\nexport const timeline = (count: number) => {\r\n  const starts = Array.from({ length: count }, (_, i) =>\r\n    i === 0 ? 0 : HOLDS.first + (i - 1) * HOLDS.word,\r\n  );\r\n  const end = HOLDS.first + Math.max(0, count - 2) * HOLDS.word + HOLDS.last;\r\n  return { starts, end, drop: end - DROP.length };\r\n};\r\n\r\n/** Which card is up at frame `f`. */\r\nexport const cardAt = (starts: readonly number[], f: number) =>\r\n  starts.reduce((at, s, i) => (f >= s ? i : at), 0);\r\n\r\nlet measureCtx: CanvasRenderingContext2D | null | undefined;\r\n\r\nconst fontMeasure = (font: string) => {\r\n  if (typeof document === \"undefined\") return null;\r\n  if (measureCtx === undefined) {\r\n    measureCtx = document.createElement(\"canvas\").getContext(\"2d\");\r\n  }\r\n  if (measureCtx) measureCtx.font = font;\r\n  return measureCtx ?? null;\r\n};\r\n\r\n/**\r\n * A line that can sit a fraction of a pixel. Chrome rounds a baseline to a whole\r\n * device pixel, which turns a slow drop into a staircase, so the type is painted\r\n * on the two rows around `y` and added by the fraction between them.\r\n */\r\nconst Line: React.FC<{\r\n  y: number;\r\n  base: number;\r\n  px: number;\r\n  children: ReactNode;\r\n}> = ({ y, base, px, children }) => {\r\n  const row = Math.floor(y * px);\r\n  const f = y * px - row;\r\n  return (\r\n    <g style={{ isolation: \"isolate\" }}>\r\n      {[\r\n        { r: row, w: 1 - f },\r\n        { r: row + 1, w: f },\r\n      ].map(({ r, w }) => (\r\n        <g\r\n          key={r}\r\n          transform={`translate(0 ${(r + 1e-3) / px - base})`}\r\n          style={{ opacity: w, mixBlendMode: \"plus-lighter\" }}\r\n        >\r\n          {children}\r\n        </g>\r\n      ))}\r\n    </g>\r\n  );\r\n};\r\n\r\nexport const DropLine: React.FC<DropLineProps> = ({\r\n  words = [\"then\", \"ships\", \"the\", \"film\"],\r\n  fontFamily = inter,\r\n  fontWeight = 700,\r\n  fontSize = FONT_SIZE,\r\n  wordSize,\r\n  wordNudge,\r\n  wordTracking,\r\n  wordKerning,\r\n  ink,\r\n  paper,\r\n  speed = 1,\r\n  theme,\r\n  mode,\r\n}) => {\r\n  const t = useKuchiTheme(theme, mode);\r\n  const uid = useId().replace(/:/g, \"\");\r\n  const f = useCurrentFrame() * speed;\r\n  const { width, height } = useVideoConfig();\r\n  const px = Math.max(width / STAGE_W, height / STAGE_H);\r\n  const card = ink ?? t.foreground;\r\n  const type = paper ?? t.background;\r\n\r\n  const line = timeline(words.length);\r\n  const index = cardAt(line.starts, f);\r\n  const word = words[index] ?? \"\";\r\n  const isLast = index === words.length - 1;\r\n  const chars = Array.from(word);\r\n  const tracking = wordTracking?.[index] ?? -0.015;\r\n\r\n  const wanted = wordSize?.[index] ?? fontSize;\r\n  const ctx = fontMeasure(`${fontWeight} ${wanted}px ${fontFamily}`);\r\n  const measured =\r\n    (ctx ? ctx.measureText(word).width : chars.length * wanted * 0.6) +\r\n    (chars.length - 1) * tracking * wanted;\r\n  const fit = Math.min(1, MAX_WIDTH / Math.max(1, measured));\r\n  const size = wanted * fit;\r\n\r\n  // Keep the type centred on the stage as `fontSize` moves away from the measured one.\r\n  const rest = STAGE_H / 2 + (BASELINE - STAGE_H / 2) * (fontSize / FONT_SIZE);\r\n  const fall = isLast ? sample(DROP, f - line.drop) : 0;\r\n  const y = rest + (index === 0 ? sample(RISE, f) : 0);\r\n\r\n  // The cut between a dot and its stem: just above the x-height, on any face.\r\n  const dots = isLast && DOTTED.test(word);\r\n  const xHeight = ctx?.measureText(\"x\").actualBoundingBoxAscent;\r\n  const dotTop = ctx?.measureText(\"i\").actualBoundingBoxAscent;\r\n  const dotLine =\r\n    xHeight && dotTop\r\n      ? rest - (xHeight + (dotTop - xHeight) * 0.15) * fit\r\n      : rest - DOT_LINE * size;\r\n\r\n  const letters = (show: (ch: string) => boolean) => (\r\n    <text\r\n      x={STAGE_W / 2 + (wordNudge?.[index] ?? 0)}\r\n      y={rest}\r\n      textAnchor=\"middle\"\r\n      fill={type}\r\n      style={{\r\n        fontFamily,\r\n        fontWeight,\r\n        fontSize: size,\r\n        letterSpacing: `${tracking}em`,\r\n        textRendering: \"geometricPrecision\",\r\n      }}\r\n    >\r\n      {chars.map((ch, i) => (\r\n        <tspan\r\n          // biome-ignore lint/suspicious/noArrayIndexKey: letters of a fixed string\r\n          key={i}\r\n          dx={`${wordKerning?.[index]?.[i] ?? 0}em`}\r\n          fillOpacity={show(ch) ? 1 : 0}\r\n        >\r\n          {ch}\r\n        </tspan>\r\n      ))}\r\n    </text>\r\n  );\r\n\r\n  return (\r\n    <AbsoluteFill style={{ background: card, overflow: \"hidden\" }}>\r\n      <svg\r\n        viewBox={`0 0 ${STAGE_W} ${STAGE_H}`}\r\n        width=\"100%\"\r\n        height=\"100%\"\r\n        preserveAspectRatio=\"xMidYMid slice\"\r\n        style={{ position: \"absolute\", inset: 0 }}\r\n      >\r\n        <title>{words.join(\" \")}</title>\r\n        <defs>\r\n          <clipPath id={`${uid}a`}>\r\n            <rect width={STAGE_W} height={dotLine} />\r\n          </clipPath>\r\n          <clipPath id={`${uid}b`}>\r\n            <rect y={dotLine} width={STAGE_W} height={STAGE_H * 2} />\r\n          </clipPath>\r\n        </defs>\r\n        <Line y={y + fall} base={rest} px={px}>\r\n          {dots ? (\r\n            <>\r\n              {letters((ch) => !DOTTED.test(ch))}\r\n              <g clipPath={`url(#${uid}b)`}>\r\n                {letters((ch) => DOTTED.test(ch))}\r\n              </g>\r\n            </>\r\n          ) : (\r\n            letters(() => true)\r\n          )}\r\n        </Line>\r\n        {dots && (\r\n          <Line y={y} base={rest} px={px}>\r\n            <g clipPath={`url(#${uid}a)`}>{letters((ch) => DOTTED.test(ch))}</g>\r\n          </Line>\r\n        )}\r\n      </svg>\r\n    </AbsoluteFill>\r\n  );\r\n};\r\n\r\nexport default DropLine;\r\n"},{"path":"components/kuchi/drop-line/data.ts","type":"registry:component","target":"components/kuchi/drop-line/data.ts","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n/**\r\n * Every number here was measured off a 1920x1080 reference, one sample per frame.\r\n * Sizes and offsets are px on that stage.\r\n */\r\n\r\nexport const FONT_SIZE = 130;\r\n/** Where the type sits at rest. */\r\nexport const BASELINE = 574.5;\r\n\r\n/** Frames each card holds: the first, every word between, the last. */\r\nexport const HOLDS = { first: 9, word: 7, last: 15 } as const;\r\n\r\n/** The first word lands low and rises into place: px below rest, per frame. */\r\nexport const RISE = [70, 43, 22.8, 13, 7.2, 3.7, 1.55, 0.45, 0] as const;\r\n\r\n/** The last card, frame by frame: how far the word has sunk. The dot stays put. */\r\nexport const DROP = [\r\n  0, 0, 0, 0, 0.38, 1.25, 2.54, 4.4, 6.91, 10.27, 14.57, 20.23, 27.57, 37.53,\r\n  51.55,\r\n] as const;\r\n\r\n/** Between the x-height and the dot, in em above the baseline, where no face is told. */\r\nexport const DOT_LINE = 0.585;\r\n"}]}