{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"spec-sweep","type":"registry:component","title":"Spec Sweep","description":"A one-line spec slides in word by word while a highlight runs along it and an icon charges up","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/spec-sweep/index.tsx","type":"registry:component","target":"components/kuchi/spec-sweep/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 { useEffect, useId, useMemo, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  Easing,\r\n  getRemotionEnvironment,\r\n  interpolate,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  mixOklch,\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\nimport { BOLT, ENTRY, ICON_BOX, SWEEP } from \"./data\";\r\n\r\n/**\r\n * Spec Sweep — one centred line that arrives word by word and then gets read\r\n * out by a highlight. Every word slides in on its own clock, a soft band of\r\n * brightness travels along the line, and an icon charges up from the bottom.\r\n *\r\n * The defaults are measured off a 1920x1080 reference: it is a single curve\r\n * through time (`SWEEP`), reached at each point of the line by its distance from\r\n * the start plus that word's entry delay, so copy of any length rides the same\r\n * band.\r\n */\r\n\r\nconst { fontFamily: INTER } = loadFont(\"normal\", {\r\n  weights: [\"500\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\nexport type SpecSegmentRole = \"lead\" | \"icon\" | \"accent\" | \"muted\";\r\n\r\nexport interface SpecSegment {\r\n  /** The words. Split on spaces; each word enters on its own. Unused by `icon`. */\r\n  text?: string;\r\n  /**\r\n   * `lead` rides the highlight and falls back to grey behind it. `accent` stays\r\n   * lit once the highlight has reached it. `muted` never rises past `mutedLevel`.\r\n   * `icon` draws the `icon` path, charged with `accentColor`.\r\n   */\r\n  role?: SpecSegmentRole;\r\n}\r\n\r\nexport interface SpecSweepProps {\r\n  segments?: SpecSegment[];\r\n  /** SVG path data of the icon, drawn in an `iconBox` viewBox. */\r\n  icon?: string;\r\n  /** viewBox width and height of `icon`. */\r\n  iconBox?: [number, number];\r\n  /** Icon height, in em. */\r\n  iconSize?: number;\r\n  /** Icon colour once charged. Defaults to `theme.primary`. */\r\n  accentColor?: string;\r\n  /** Opacity of the icon before the charge reaches it. */\r\n  iconDim?: number;\r\n  /** Lighter inner edge of the icon, px on a 1920 stage. 0 turns it off. */\r\n  iconRim?: number;\r\n  /** Colour of that edge. Defaults to `accentColor` towards white. */\r\n  iconRimColor?: string;\r\n  /** Frames from the icon's entry to the start of its charge, and the charge's length. */\r\n  chargeDelay?: number;\r\n  chargeFrames?: number;\r\n  /** A family from `fonts.ts`, or a CSS family you have loaded yourself. */\r\n  fontFamily?: string;\r\n  /** Type size, px on a 1920 stage. Long copy shrinks from here to fit. */\r\n  fontSize?: number;\r\n  fontWeight?: number;\r\n  /** How far a word slides in, em. */\r\n  travel?: number;\r\n  /** Frames between one word's entry and the next. Compressed on long copy. */\r\n  stagger?: number;\r\n  /** Frames the highlight takes to cross the line. */\r\n  sweepFrames?: number;\r\n  /** Level `muted` words are capped at. */\r\n  mutedLevel?: number;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  speed?: number;\r\n}\r\n\r\n/** Widest the line may get, as a fraction of the stage: a word still sliding in stays on it. */\r\nconst MAX_LINE = 0.85;\r\n/** The last word has landed by this frame, however long the copy. */\r\nconst LAST_ENTRY = 14;\r\n/** Frame the highlight's centre leaves the start of the line. */\r\nconst SWEEP_START = 1.476;\r\n/** Frames a word is ahead of the highlight at the very start of its slide. */\r\nconst SWEEP_LEAD = 6.093;\r\n/** The text baseline sits this far below the stage centre, em. */\r\nconst BASELINE = 0.258;\r\n/** Spacing of the sampled gradient stops, px on a 1920 stage. */\r\nconst STOP_EVERY = 8;\r\n\r\nconst chargeEase = Easing.bezier(0.166, 0.092, 0.279, 1);\r\n\r\nconst held = { extrapolateLeft: \"clamp\", extrapolateRight: \"clamp\" } as const;\r\nconst ENTRY_AT = ENTRY.map((_, i) => i);\r\nconst SWEEP_AT = SWEEP.map(([at]) => at);\r\nconst SWEEP_LEVEL = SWEEP.map(([, level]) => level);\r\n\r\n/** The fraction of `travel` a word has left, `age` frames after it entered. */\r\nexport const entryOffset = (age: number) =>\r\n  interpolate(age, ENTRY_AT, [...ENTRY], held);\r\n\r\n/** Level of a word at `t` frames past the highlight's centre. */\r\nexport const sweepLevel = (\r\n  role: SpecSegmentRole,\r\n  t: number,\r\n  mutedLevel = 0.6,\r\n) => {\r\n  if (role === \"accent\" && t > 0) return 1;\r\n  const level = interpolate(t, SWEEP_AT, SWEEP_LEVEL, held);\r\n  return role === \"muted\" ? Math.min(level, mutedLevel) : level;\r\n};\r\n\r\nexport interface LineItem {\r\n  role: SpecSegmentRole;\r\n  text: string;\r\n  /** Left edge from the start of the line, and advance. px. */\r\n  x: number;\r\n  w: number;\r\n}\r\n\r\n/** Splits segments into words and lays them on one line. */\r\nexport const layoutLine = (\r\n  segments: SpecSegment[],\r\n  measure: (text: string) => number,\r\n  iconWidth: number,\r\n) => {\r\n  const space = measure(\" \");\r\n  const items: LineItem[] = [];\r\n  let x = 0;\r\n  const push = (role: SpecSegmentRole, text: string, w: number) => {\r\n    items.push({ role, text, x, w });\r\n    x += w + space;\r\n  };\r\n  for (const s of segments) {\r\n    if (s.role === \"icon\") push(\"icon\", \"\", iconWidth);\r\n    else\r\n      for (const word of (s.text ?? \"\").split(/\\s+/).filter(Boolean))\r\n        push(s.role ?? \"lead\", word, measure(word));\r\n  }\r\n  return { items, width: Math.max(0, x - space) };\r\n};\r\n\r\nconst makeMeasure = (font: string, size: number) => {\r\n  const ctx =\r\n    typeof document === \"undefined\"\r\n      ? null\r\n      : document.createElement(\"canvas\").getContext(\"2d\");\r\n  if (!ctx) return (text: string) => text.length * 0.55 * size;\r\n  ctx.font = font;\r\n  return (text: string) => ctx.measureText(text).width;\r\n};\r\n\r\nconst DEFAULT_SEGMENTS: SpecSegment[] = [\r\n  { text: \"Ship\", role: \"lead\" },\r\n  { role: \"icon\" },\r\n  { text: \"a launch film\", role: \"accent\" },\r\n  { text: \"in\", role: \"muted\" },\r\n  { text: \"20 minutes\", role: \"accent\" },\r\n];\r\n\r\nexport const SpecSweep = ({\r\n  segments = DEFAULT_SEGMENTS,\r\n  icon = BOLT,\r\n  iconBox = ICON_BOX,\r\n  iconSize = 1.452,\r\n  accentColor,\r\n  iconDim = 0.39,\r\n  iconRim = 1.47,\r\n  iconRimColor,\r\n  chargeDelay = 11.47,\r\n  chargeFrames = 30,\r\n  fontFamily,\r\n  fontSize = 85.15,\r\n  fontWeight = 500,\r\n  travel = 1.466,\r\n  stagger = 2,\r\n  sweepFrames = 54,\r\n  mutedLevel = 0.6,\r\n  theme,\r\n  mode = \"dark\",\r\n  speed = 1,\r\n}: SpecSweepProps) => {\r\n  const f = useCurrentFrame() * speed;\r\n  const { width, height } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const id = useId().replace(/:/g, \"\");\r\n  const family = resolveFont(fontFamily ?? t.fontFamily) ?? INTER;\r\n  const stage = Math.min(width / 1920, height / 1080);\r\n\r\n  // A width measured before the face lands is a width for the fallback, so the\r\n  // layout waits on it; a render holds its first frame until that has re-rendered.\r\n  const [fontTick, setFontTick] = useState(0);\r\n  const [handle] = useState(() =>\r\n    getRemotionEnvironment().isRendering\r\n      ? delayRender(\"spec-sweep: loading the face\")\r\n      : null,\r\n  );\r\n  const fontSpec = `${fontWeight} 100px ${family}`;\r\n  useEffect(() => {\r\n    let alive = true;\r\n    document.fonts\r\n      .load(fontSpec)\r\n      .catch(() => [])\r\n      .then(() => {\r\n        if (alive) setFontTick((n) => n + 1);\r\n      });\r\n    return () => {\r\n      alive = false;\r\n    };\r\n  }, [fontSpec]);\r\n  useEffect(() => {\r\n    if (fontTick > 0 && handle != null) continueRender(handle);\r\n  }, [fontTick, handle]);\r\n\r\n  const line = useMemo(() => {\r\n    void fontTick;\r\n    const place = (size: number) =>\r\n      layoutLine(\r\n        segments,\r\n        makeMeasure(`${fontWeight} ${size}px ${family}`, size),\r\n        (size * iconSize * iconBox[0]) / iconBox[1],\r\n      );\r\n    const size = fontSize * stage;\r\n    const first = place(size);\r\n    const fit = Math.min(1, (MAX_LINE * width) / Math.max(1, first.width));\r\n    const fitted = fit < 1 ? place(size * fit) : first;\r\n    return { ...fitted, size: size * fit, left: (width - fitted.width) / 2 };\r\n  }, [\r\n    fontTick,\r\n    segments,\r\n    fontWeight,\r\n    family,\r\n    iconSize,\r\n    iconBox,\r\n    fontSize,\r\n    stage,\r\n    width,\r\n  ]);\r\n\r\n  const { items, size, left } = line;\r\n  const step = Math.min(stagger, LAST_ENTRY / Math.max(1, items.length - 1));\r\n  const rate = line.width / sweepFrames; // px per frame\r\n  const baseline = height / 2 + BASELINE * size;\r\n  const accent = accentColor ?? t.primary;\r\n  const rimColor = iconRimColor ?? mixOklch(accent, \"#ffffff\", 0.3);\r\n  const ink = t.foreground;\r\n\r\n  const iconH = size * iconSize;\r\n  const iconScale = iconH / iconBox[1];\r\n\r\n  return (\r\n    <AbsoluteFill style={{ background: t.background }}>\r\n      <svg\r\n        width={width}\r\n        height={height}\r\n        style={{ position: \"absolute\", inset: 0, overflow: \"hidden\" }}\r\n      >\r\n        {items.map((item, i) => {\r\n          const age = f - step * i;\r\n          if (age < 0) return null;\r\n          const off = entryOffset(age);\r\n          const x = left + item.x + off * travel * size;\r\n\r\n          if (item.role === \"icon\") {\r\n            const charge = chargeEase(\r\n              Math.min(1, Math.max(0, (age - chargeDelay) / chargeFrames)),\r\n            );\r\n            const level = iconBox[1] * (1.006 - 1.018 * charge);\r\n            const clip = `${id}c${i}`;\r\n            const shape = (fill: string, rim: string) => (\r\n              <>\r\n                <path d={icon} fill={fill} />\r\n                {iconRim > 0 && (\r\n                  <path\r\n                    d={icon}\r\n                    fill=\"none\"\r\n                    stroke={rim}\r\n                    strokeWidth={(2 * iconRim * stage) / iconScale}\r\n                    clipPath={`url(#${clip})`}\r\n                  />\r\n                )}\r\n              </>\r\n            );\r\n            return (\r\n              <g\r\n                key={`${item.x}`}\r\n                transform={`translate(${x} ${height / 2 - iconH / 2}) scale(${iconScale})`}\r\n              >\r\n                <clipPath id={clip}>\r\n                  <path d={icon} />\r\n                </clipPath>\r\n                <clipPath id={`${clip}a`}>\r\n                  <rect x={-9e3} y={-9e3} width={18e3} height={9e3 + level} />\r\n                </clipPath>\r\n                <clipPath id={`${clip}b`}>\r\n                  <rect x={-9e3} y={level} width={18e3} height={9e3} />\r\n                </clipPath>\r\n                <g clipPath={`url(#${clip}a)`} opacity={iconDim}>\r\n                  {shape(accent, rimColor)}\r\n                </g>\r\n                <g clipPath={`url(#${clip}b)`}>{shape(accent, rimColor)}</g>\r\n              </g>\r\n            );\r\n          }\r\n\r\n          // The highlight reaches each point of the word at its own moment, so the\r\n          // word is painted with a gradient sampled from that one curve.\r\n          const grad = `${id}g${i}`;\r\n          const from = age + SWEEP_LEAD * off - SWEEP_START - item.x / rate;\r\n          const n = Math.max(2, Math.ceil(item.w / (STOP_EVERY * stage)));\r\n          const stops = Array.from({ length: n + 1 }, (_, k) => {\r\n            const u = k / n;\r\n            return (\r\n              <stop\r\n                key={u}\r\n                offset={u}\r\n                stopColor={ink}\r\n                stopOpacity={sweepLevel(\r\n                  item.role,\r\n                  from - (u * item.w) / rate,\r\n                  mutedLevel,\r\n                )}\r\n              />\r\n            );\r\n          });\r\n          return (\r\n            <g key={`${item.x}`}>\r\n              <linearGradient\r\n                id={grad}\r\n                gradientUnits=\"userSpaceOnUse\"\r\n                x1={x}\r\n                x2={x + item.w}\r\n                y1={0}\r\n                y2={0}\r\n              >\r\n                {stops}\r\n              </linearGradient>\r\n              <text\r\n                x={x}\r\n                y={baseline}\r\n                fill={`url(#${grad})`}\r\n                style={{\r\n                  fontFamily: family,\r\n                  fontWeight,\r\n                  fontSize: size,\r\n                  textRendering: \"geometricPrecision\",\r\n                }}\r\n              >\r\n                {item.text}\r\n              </text>\r\n            </g>\r\n          );\r\n        })}\r\n      </svg>\r\n    </AbsoluteFill>\r\n  );\r\n};\r\n\r\nexport default SpecSweep;\r\n"},{"path":"components/kuchi/spec-sweep/data.ts","type":"registry:component","target":"components/kuchi/spec-sweep/data.ts","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n/**\r\n * Everything below is measured frame by frame off a 1920x1080, 30fps reference.\r\n * Times are frames, lengths are em unless a comment says otherwise.\r\n */\r\n\r\n/** A word's slide in, as a fraction of `travel`, one entry per frame of its own clock. */\r\nexport const ENTRY = [\r\n  1, 0.64, 0.484, 0.374, 0.29, 0.224, 0.172, 0.128, 0.094, 0.066, 0.044, 0.028,\r\n  0.016, 0.008, 0.002, 0,\r\n] as const;\r\n\r\n/**\r\n * Brightness against time, relative to the moment the highlight's centre reaches\r\n * a point of the line: [frames, level], where 1 is full ink. One curve explains\r\n * every word of the reference to 0.8% of full scale.\r\n */\r\nexport const SWEEP: readonly (readonly [number, number])[] = [\r\n  [-50, 0.255],\r\n  [-49, 0.271],\r\n  [-45, 0.377],\r\n  [-42, 0.437],\r\n  [-39, 0.467],\r\n  [-31, 0.525],\r\n  [-25, 0.587],\r\n  [-12, 0.806],\r\n  [-5, 0.966],\r\n  [-3, 0.99],\r\n  [0, 1],\r\n  [4, 0.995],\r\n  [6, 0.974],\r\n  [13, 0.81],\r\n  [26, 0.588],\r\n  [33, 0.517],\r\n  [43, 0.462],\r\n  [51, 0.365],\r\n];\r\n\r\n/** Default mark: a rounded bolt in a `ICON_BOX` viewBox. */\r\nexport const BOLT =\r\n  \"M54.13 2.15A5.78 5.78 0 0 1 64.00 7.96L47.41 48.65A1.03 1.03 0 0 0 48.36 50.07L78.20 50.31A4.41 4.41 0 0 1 81.63 57.46L30.83 121.75A5.39 5.39 0 0 1 21.55 116.54L37.50 73.40L6.96 72.69A4.58 4.58 0 0 1 3.50 65.25Z\";\r\nexport const ICON_BOX: [number, number] = [83.07, 123.79];\r\n"}]}