{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"check-cycle","type":"registry:component","title":"Check Cycle","description":"Rotating words beside a checkbox: a sentence that finishes itself several ways. \"Create your own\" sits left of a ticked shadcn-style checkbox and the word to its right rolls up out of a slot — Intros, Demos, Launches, Changelogs, Tutorials, And more — then the line steps back a little and rests.","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/check-cycle.tsx","type":"registry:component","target":"components/kuchi/check-cycle.tsx","content":"/*! Portions Copyright (c) 2026 Sri Nath (snap-cn). MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\r\n\r\nimport { loadFont as loadSans } from \"@remotion/google-fonts/Inter\";\r\nimport { type CSSProperties, useEffect, useId, useState } from \"react\";\r\nimport {\r\n  AbsoluteFill,\r\n  continueRender,\r\n  delayRender,\r\n  Easing,\r\n  useCurrentFrame,\r\n  useVideoConfig,\r\n} from \"remotion\";\r\nimport {\r\n  resolveFont,\r\n  type KuchiTheme,\r\n  useKuchiTheme,\r\n} from \"@/lib/kuchi-ui\";\r\n\r\n/**\r\n * A sentence that finishes itself over and over: \"Create your own ☑ Intros\",\r\n * then Demos, Launches, Changelogs, Tutorials, \"And more\" — each word rolling\r\n * up out of a slot beside a ticked checkbox — then the line steps back a little\r\n * and rests.\r\n *\r\n * ## Everything here was measured off a recording, frame by frame\r\n *\r\n * The numbers below are not taste. They were recovered from a 2.17 second,\r\n * 718 × 394 screen capture (65 frames) by fitting renders of this scene to it\r\n * in BT.709 Y′CbCr, through a model of the capture's own resampling kernel:\r\n *\r\n *   - the recording is a 30fps video captured at a jittery ~30Hz: its\r\n *     timestamps wander ±8ms, but snapped to a 30fps grid every capture frame\r\n *     is exactly one source frame — none doubled, none dropped. Fitted on that\r\n *     clock instead of the stamps, every curve below came out clean.\r\n *   - the two words in the slot move as ONE strip — the gap between the word\r\n *     leaving and the word arriving is constant to 0.2px on every frame of a\r\n *     roll — so it is one curve, not an ease-in exit and an ease-out entrance.\r\n *     It is `cubic-bezier(0.65, 0, 0.35, 1)` over exactly 0.5s, a roll every\r\n *     20 frames: 0.076px RMS across both rolls. The runner-up, quart in-out,\r\n *     is 0.10; the CSS `ease-in-out` is 0.69.\r\n *   - the strip does not travel the same distance every time: 44.19px, then\r\n *     42.27px. Both are shipped, in `TRAVEL`, and cycle.\r\n *\r\n * ## The type is Inter 3, and that was measured too\r\n *\r\n * Fingerprinted on the five words the recording shows, at matched width:\r\n * Inter 500 is 0.45px RMS from the reference, the next face (Be Vietnam Pro)\r\n * 0.48, Helvetica 0.50, Geist 0.61. SF Pro, fitted outline against outline,\r\n * is 37% worse than Inter. And it is Inter *3*: the same fit against Inter\r\n * 3.19 is 12% closer across all four lines than against the Inter 4 Google\r\n * serves today, and a third closer on the lead-in alone. So 3.19 is loaded\r\n * (OFL, from fontsource), with Google's Inter behind it as the fallback.\r\n *\r\n * ## The checkbox sits still, and everything is laid out from it\r\n *\r\n * The lead-in is right-aligned to the box and the word left-aligned from it, so\r\n * the sentence survives new copy: the box never moves, only the words around it\r\n * change width — which is also what the reference does when \"Docs\" becomes\r\n * \"And more\".\r\n */\r\n\r\nconst { fontFamily: SANS } = loadSans(\"normal\", {\r\n  weights: [\"500\"],\r\n  subsets: [\"latin\"],\r\n});\r\n\r\nconst FACE = \"Check Cycle Inter\";\r\nconst FACE_URL =\r\n  \"https://cdn.jsdelivr.net/npm/@fontsource/inter@4.5.15/files/inter-latin-500-normal.woff2\";\r\nlet faceLoad: Promise<unknown> | null = null;\r\nfunction loadFace(): Promise<unknown> {\r\n  if (faceLoad) return faceLoad;\r\n  if (typeof FontFace === \"undefined\") {\r\n    faceLoad = Promise.resolve();\r\n    return faceLoad;\r\n  }\r\n  const face = new FontFace(FACE, `url(${FACE_URL}) format(\"woff2\")`, {\r\n    weight: \"500\",\r\n  });\r\n  document.fonts.add(face);\r\n  // A face that fails to load leaves Google's Inter to paint — close, not exact.\r\n  faceLoad = face.load().catch(() => undefined);\r\n  return faceLoad;\r\n}\r\n\r\n/* ─────────────────────────────────────────────────────────────────────────\r\n   The scene, in the reference's own 718 × 394 pixels\r\n   ───────────────────────────────────────────────────────────────────────── */\r\n\r\nexport const REF_W = 718;\r\nexport const REF_H = 394;\r\n\r\n/** Type size of both halves of the sentence. Fitted per line: 21.62–21.97. */\r\nexport const SIZE = 21.78;\r\n/** Where the lead-in's advance ends — it is right-aligned to this x. */\r\nexport const LEAD_END = 340.04;\r\n/** The lead-in's baseline. */\r\nexport const LEAD_BASE = 203.01;\r\n/** Where the word's advance starts. */\r\nexport const WORD_X = 379.1;\r\n/** The word's baseline: 1.5px below the lead-in's, on every word shown. */\r\nexport const WORD_BASE = 204.97;\r\n\r\n/** The checkbox, as x, y, width, height, corner radius. */\r\nexport const BOX = { x: 345.11, y: 183.71, w: 27.03, h: 27.59, r: 6.53 };\r\n/** The tick, as three points in the box's own coordinates, and its stroke. */\r\nexport const TICK: readonly (readonly [number, number])[] = [\r\n  [5.468, 13.785],\r\n  [11.827, 18.695],\r\n  [20.72, 8.888],\r\n];\r\nexport const TICK_W = 2.72;\r\n\r\n/**\r\n * The slot the words roll through: a hard clip, top and bottom. Fitted as a\r\n * feathered mask across eight frames with both words visible — the feathers\r\n * came back at 2.1px and 1.0px, which is the capture's blur, not a fade.\r\n */\r\nexport const SLOT = [171.37, 223.62] as const;\r\n\r\n/** How far the strip travels on each roll, in turn. */\r\nexport const TRAVEL = [44.19, 42.27] as const;\r\n/** When the first roll starts, how often a roll comes, and how long it takes. */\r\nexport const ROLL_AT = 0.0324;\r\nexport const ROLL_EVERY = 0.667;\r\nexport const ROLL_FOR = 0.5;\r\n/** The roll's curve: the in-out cubic. */\r\nexport const ROLL_EASE = Easing.bezier(0.65, 0, 0.35, 1);\r\n\r\n/** How long the last word holds after its roll starts, before the step back. */\r\nexport const HOLD = 1.004;\r\n\r\n/**\r\n * The step back: the line shrinks about the frame's centre to `ZOOM_TO` and\r\n * rests there. The recording falls all the way to nothing; this keeps only the\r\n * start of that — a settle, not an exit.\r\n */\r\nexport const PIVOT = [359.14, 197.52] as const;\r\nexport const ZOOM_TO = 0.8;\r\nexport const ZOOM_FOR = 0.6;\r\nexport const ZOOM_EASE = Easing.bezier(0.65, 0, 0.35, 1);\r\n/** Frames' worth of rest at the smaller size before the scene ends. */\r\nexport const ZOOM_REST = 0.2;\r\n\r\nconst unit = (v: number) => Math.min(1, Math.max(0, v));\r\n\r\n/** Strip travel at `now` seconds, for a list of `n` words. */\r\nexport function stripAt(now: number, n: number): number {\r\n  let s = 0;\r\n  for (let k = 0; k < n - 1; k++) {\r\n    const p = unit((now - (ROLL_AT + k * ROLL_EVERY)) / ROLL_FOR);\r\n    s += (TRAVEL[k % TRAVEL.length] ?? 0) * ROLL_EASE(p);\r\n  }\r\n  return s;\r\n}\r\n\r\n/** Where word `k` rests on the strip. */\r\nexport function restOf(k: number): number {\r\n  let c = 0;\r\n  for (let j = 0; j < k; j++) c += TRAVEL[j % TRAVEL.length] ?? 0;\r\n  return c;\r\n}\r\n\r\n/** When the step back starts, for `n` words. */\r\nexport function zoomStart(n: number): number {\r\n  return ROLL_AT + Math.max(0, n - 2) * ROLL_EVERY + HOLD;\r\n}\r\n\r\n/** Camera scale at `now`: 1, easing down to `ZOOM_TO`. */\r\nexport function zoomAt(now: number, n: number): number {\r\n  return 1 - (1 - ZOOM_TO) * ZOOM_EASE(unit((now - zoomStart(n)) / ZOOM_FOR));\r\n}\r\n\r\n/** Seconds from the first frame to the end: rolls, hold, step back, rest. */\r\nexport function sceneLength(n: number): number {\r\n  return zoomStart(n) + ZOOM_FOR + ZOOM_REST;\r\n}\r\n\r\n/**\r\n * A line of type that can sit — and move — a fraction of a pixel.\r\n *\r\n * Chrome rounds a glyph run's baseline to a whole device pixel, in HTML and\r\n * SVG alike, with or without `will-change`. On the roll's slow lift-off that\r\n * is measured, not theoretical: the word held still for four frames and then\r\n * jumped a pixel, three times, before it started to move at all.\r\n *\r\n * So the line is painted twice, one device pixel apart, both copies placed ON\r\n * a whole pixel so there is nothing left to round, and cross-faded by the\r\n * fraction in between. `plus-lighter` adds the two copies' coverage instead of\r\n * stacking one over the other, so the blend is exactly linear: a baseline at\r\n * 0.25 of a pixel reads as 0.25, and the ink's centroid moves in steps of\r\n * 1/8 px when it is asked to (measured). That is the resample a video of this\r\n * line would have — which is what the reference is.\r\n */\r\nfunction Line({\r\n  x,\r\n  y,\r\n  dev,\r\n  anchor,\r\n  style,\r\n  children,\r\n}: {\r\n  x: number;\r\n  y: number;\r\n  dev: { a: number; b: number };\r\n  anchor?: \"end\";\r\n  style: CSSProperties;\r\n  children: string;\r\n}) {\r\n  const d = dev.a * y + dev.b;\r\n  const lo = Math.floor(d);\r\n  const f = d - lo;\r\n  // A thousandth of a pixel inside the row, so the rounding has nowhere to go.\r\n  const at = (row: number) => (row + 1e-3 - dev.b) / dev.a;\r\n  return (\r\n    <g style={{ isolation: \"isolate\" }}>\r\n      {[\r\n        [lo, 1 - f],\r\n        [lo + 1, f],\r\n      ].map(([row, w]) => (\r\n        <text\r\n          key={row}\r\n          x={x}\r\n          y={at(row ?? 0)}\r\n          textAnchor={anchor}\r\n          style={{ ...style, opacity: w, mixBlendMode: \"plus-lighter\" }}\r\n        >\r\n          {children}\r\n        </text>\r\n      ))}\r\n    </g>\r\n  );\r\n}\r\n\r\nexport interface CheckCycleProps {\r\n  /** The part of the sentence that never changes. */\r\n  headline?: string;\r\n  /** The words that finish it, in order, comma separated. */\r\n  words?: string;\r\n  theme?: Partial<KuchiTheme>;\r\n  mode?: \"light\" | \"dark\";\r\n  fontFamily?: string;\r\n}\r\n\r\nexport function CheckCycle({\r\n  headline = \"Create your own\",\r\n  words = \"Intros, Demos, Launches, Changelogs, Tutorials, And more\",\r\n  theme,\r\n  mode = \"light\",\r\n  fontFamily = \"Default\",\r\n}: CheckCycleProps) {\r\n  const frame = useCurrentFrame();\r\n  const { fps, width, height } = useVideoConfig();\r\n  const t = useKuchiTheme(theme, mode);\r\n  const face = resolveFont(fontFamily) ?? `\"${FACE}\", ${SANS}`;\r\n  const [handle] = useState(() => delayRender(\"check-cycle: loading Inter 3\"));\r\n  useEffect(() => {\r\n    loadFace().then(() => continueRender(handle));\r\n  }, [handle]);\r\n  const id = useId().replace(/:/g, \"\");\r\n\r\n  const list = words\r\n    .split(\",\")\r\n    .map((w) => w.trim())\r\n    .filter(Boolean);\r\n  const n = Math.max(1, list.length);\r\n  const now = frame / fps;\r\n\r\n  /**\r\n   * One reference pixel, and the offset that centres the layout. Scaled to\r\n   * whichever side is tighter, so a render at the reference's dimensions *is*\r\n   * the reference's dimensions and nothing resamples mid-comparison.\r\n   */\r\n  const u = Math.min(width / REF_W, height / REF_H);\r\n  const s = stripAt(now, n);\r\n  const z = zoomAt(now, n);\r\n\r\n  const type = {\r\n    fontFamily: face,\r\n    fontWeight: 500,\r\n    fontSize: SIZE,\r\n    fill: t.foreground,\r\n    // Unhinted outlines, so the sub-pixel `Line` blend moves the shape it\r\n    // drew rather than a re-hinted one.\r\n    textRendering: \"geometricPrecision\",\r\n  } as const;\r\n\r\n  const top = (height - REF_H * u) / 2;\r\n  // A Remotion render's `scale` is the page's devicePixelRatio.\r\n  const dpr = typeof window === \"undefined\" ? 1 : window.devicePixelRatio || 1;\r\n  // A baseline, y in scene units, lands on device row a·y + b.\r\n  const [x0, y0] = PIVOT;\r\n  const dev = { a: dpr * u * z, b: dpr * (top + u * y0 * (1 - z)) };\r\n\r\n  return (\r\n    <AbsoluteFill style={{ backgroundColor: t.background }}>\r\n      <svg\r\n        width={REF_W * u}\r\n        height={REF_H * u}\r\n        viewBox={`0 0 ${REF_W} ${REF_H}`}\r\n        style={{\r\n          position: \"absolute\",\r\n          left: (width - REF_W * u) / 2,\r\n          top: (height - REF_H * u) / 2,\r\n          overflow: \"visible\",\r\n        }}\r\n      >\r\n        <defs>\r\n          <clipPath id={`${id}-slot`}>\r\n            <rect x={0} y={SLOT[0]} width={REF_W} height={SLOT[1] - SLOT[0]} />\r\n          </clipPath>\r\n        </defs>\r\n\r\n        <g\r\n          transform={`translate(${x0} ${y0}) scale(${z}) translate(${-x0} ${-y0})`}\r\n        >\r\n          <Line x={LEAD_END} y={LEAD_BASE} dev={dev} anchor=\"end\" style={type}>\r\n            {headline}\r\n          </Line>\r\n\r\n          <rect\r\n            x={BOX.x}\r\n            y={BOX.y}\r\n            width={BOX.w}\r\n            height={BOX.h}\r\n            rx={BOX.r}\r\n            fill={t.primary}\r\n          />\r\n          <polyline\r\n            points={TICK.map(([a, b]) => `${BOX.x + a},${BOX.y + b}`).join(\" \")}\r\n            fill=\"none\"\r\n            stroke={t.primaryForeground}\r\n            strokeWidth={TICK_W}\r\n            strokeLinecap=\"round\"\r\n            strokeLinejoin=\"round\"\r\n          />\r\n\r\n          <g clipPath={`url(#${id}-slot)`}>\r\n            {list.map((word, k) => {\r\n              const y = WORD_BASE + restOf(k) - s;\r\n              // Off the slot entirely: nothing to paint.\r\n              if (Math.abs(y - WORD_BASE) > SLOT[1] - SLOT[0] + SIZE)\r\n                return null;\r\n              return (\r\n                <Line\r\n                  key={`${k}-${word}`}\r\n                  x={WORD_X}\r\n                  y={y}\r\n                  dev={dev}\r\n                  style={type}\r\n                >\r\n                  {word}\r\n                </Line>\r\n              );\r\n            })}\r\n          </g>\r\n        </g>\r\n      </svg>\r\n    </AbsoluteFill>\r\n  );\r\n}\r\n"}]}