{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"ghost-complete","type":"registry:component","title":"Ghost Complete","description":"Grey ghost suggestions autocomplete a sentence, each accepted with a Tab keypress.","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>.","registryDependencies":["https://kuchi.kalarislabs.com/r/gradient-ground.json"],"files":[{"path":"components/kuchi/ghost-complete.tsx","type":"registry:component","target":"components/kuchi/ghost-complete.tsx","content":"/*! Portions Copyright (c) 2026 Remocn. MIT License. See THIRD_PARTY_LICENSES. */\n\"use client\";\n\nimport { loadFont as loadGeist } from \"@remotion/google-fonts/Geist\";\nimport { loadFont as loadGeistMono } from \"@remotion/google-fonts/GeistMono\";\nimport { loadFont as loadManrope } from \"@remotion/google-fonts/Manrope\";\nimport type React from \"react\";\nimport { useMemo } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  interpolateColors,\n  spring,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/kuchi/gsh/gradient-engine\";\nimport { GshGround } from \"@/lib/kuchi/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/kuchi/gsh/presets\";\n\nconst { fontFamily: geist } = loadGeist(\"normal\", {\n  weights: [\"300\", \"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: mono } = loadGeistMono(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\nconst manrope = loadManrope(\"normal\", {\n  weights: [\"600\"],\n  subsets: [\"latin\"],\n});\n\nexport interface GhostCompleteProps {\n  title?: string;\n  typed?: string;\n  suggestions?: string[];\n  keepLastFill?: boolean;\n  showLogo?: boolean;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  ground?: GshPresetId;\n  groundParams?: Partial<GradientParams>;\n  /** Label of the key pressed to accept a suggestion. */\n  keyLabel?: string;\n  /** Text next to the key. */\n  hintLabel?: string;\n  /** Frames a ghost suggestion waits before it is accepted. */\n  hold?: number;\n  /** Replaces the acme mark. */\n  logo?: React.ReactNode;\n  /** Text color; overrides the theme ink. */\n  ink?: string;\n  /** Solid fill in place of the gradient ground; \"transparent\" drops it. */\n  background?: string;\n  /** Typeface for the copy. Load it yourself; Geist by default. */\n  fontFamily?: string;\n  /** Size of the card and key, around the frame's center. */\n  scale?: number;\n  /** Frames to hold the first frame before anything moves. */\n  delay?: number;\n  speed?: number;\n}\n\n\nfunction KuchiLogo({ fontSize, color }: { fontSize: number; color: string }) {\n  return (\n    <div\n      style={{\n        display: \"flex\",\n        alignItems: \"baseline\",\n        color,\n        fontFamily: manrope.fontFamily,\n        fontWeight: 600,\n        fontSize,\n        letterSpacing: \"-0.025em\",\n        lineHeight: 1,\n      }}\n    >\n      <span>Acme</span>\n    </div>\n  );\n}\n\nconst ADV = [\n  243, 228, 361, 515, 643, 810, 649, 186, 290, 290, 427, 562, 213, 418, 213,\n  494, 673, 406, 630, 625, 629, 641, 604, 531, 624, 606, 302, 302, 546, 544,\n  546, 570, 925, 689, 688, 713, 701, 609, 595, 713, 716, 280, 607, 656, 583,\n  890, 745, 751, 657, 745, 680, 654, 568, 694, 688, 968, 633, 594, 561, 361,\n  470, 361, 438, 558, 258, 565, 608, 563, 608, 576, 412, 607, 591, 256, 284,\n  609, 282, 885, 591, 588, 608, 608, 394, 537, 410, 586, 560, 829, 607, 553,\n  552, 395, 274, 395, 523,\n];\nconst TRACK = -0.035;\nconst LEADING = 1.08;\n\nconst LIGHT_GROUND: Partial<GradientParams> = {\n  kind: \"mist\",\n  colors: [\"#F2955A\", \"#F7CBA8\", \"#F3E6D8\", \"#6B2A12\"],\n  background: \"#F2EEE8\",\n  speed: 0.8,\n  loopSeconds: 14,\n  scale: 0.8,\n  warp: 0.4,\n  blur: 0.65,\n  grain: 0.3,\n  seed: 9,\n};\n\nconst THEMES = {\n  dark: {\n    base: \"#050303\",\n    scrim:\n      \"linear-gradient(180deg, rgba(5,3,3,0.55) 0%, rgba(5,3,3,0.2) 70%, rgba(5,3,3,0) 100%)\",\n    card: \"rgba(17,14,13,0.9)\",\n    depth:\n      \"inset 0 1px 0 rgba(255,255,255,0.06), 0 0 0 1px rgba(255,255,255,0.08), 0 30px 60px -20px rgba(0,0,0,0.75)\",\n    divider: \"rgba(255,255,255,0.07)\",\n    fg: \"#F4F1EC\",\n    ghost: \"#5C5650\",\n    fill: \"#FFB27A\",\n    dim: \"#8F8780\",\n    key: \"rgba(255,255,255,0.14)\",\n    keyBg: \"rgba(255,255,255,0.04)\",\n    logo: \"#F4F1EC\",\n  },\n  light: {\n    base: \"#F2EEE8\",\n    scrim:\n      \"linear-gradient(180deg, rgba(246,243,238,0.5) 0%, rgba(246,243,238,0.1) 100%)\",\n    card: \"rgba(255,255,255,0.94)\",\n    depth:\n      \"0 0 0 1px rgba(40,24,12,0.06), 0 1px 3px rgba(40,24,12,0.05), 0 30px 60px -24px rgba(90,40,10,0.25)\",\n    divider: \"rgba(40,24,12,0.07)\",\n    fg: \"#17120F\",\n    ghost: \"#C2BAB1\",\n    fill: \"#C2410C\",\n    dim: \"#857B73\",\n    key: \"rgba(40,24,12,0.16)\",\n    keyBg: \"#F7F4F0\",\n    logo: \"#17120F\",\n  },\n} as const;\n\nconst ENTER = Easing.bezier(0.32, 0.72, 0, 1);\nconst MOVE = Easing.bezier(0.65, 0, 0.35, 1);\nconst EXIT = Easing.bezier(0.55, 0, 1, 0.45);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\nconst TYPE_START = 6;\nconst PER_CHAR = 2;\nconst GHOST_LEAD = 4;\nconst HOLD_GHOST = 16;\nconst AFTER_FILL = 8;\nconst SETTLE = 12;\n\nfunction advance(ch: string) {\n  const code = ch.charCodeAt(0);\n  return (code >= 32 && code < 127 ? ADV[code - 32] : 600) / 1000;\n}\n\ninterface Glyph {\n  ch: string;\n  seg: number;\n  i: number;\n}\n\ninterface Segment {\n  start: number;\n  length: number;\n  breaks: number;\n  ghostIn: number;\n  accept: number;\n  fillDur: number;\n}\n\n/** The foreground at `scale`, around the frame's center; nothing extra at 1. */\nfunction ScaleLayer({\n  scale,\n  children,\n}: {\n  scale: number;\n  children: React.ReactNode;\n}) {\n  if (scale === 1) return children;\n  return (\n    <AbsoluteFill style={{ transform: `scale(${scale})` }}>\n      {children}\n    </AbsoluteFill>\n  );\n}\n\nexport function GhostComplete({\n  title = \"Launch notes\",\n  typed = \"Ship the\",\n  suggestions = [\"launch video\", \"\\nbefore lunch.\"],\n  keepLastFill = true,\n  showLogo = true,\n  theme = \"dark\",\n  ground,\n  groundParams,\n  keyLabel = \"Tab\",\n  hintLabel = \"to accept\",\n  hold = HOLD_GHOST,\n  logo,\n  ink,\n  background,\n  fontFamily = geist,\n  scale = 1,\n  delay = 0,\n  speed = 1,\n}: GhostCompleteProps) {\n  const t = Math.max(0, useCurrentFrame() - delay) * speed;\n  const { width: W, height: H, fps } = useVideoConfig();\n  const tall = H > W;\n  const u = tall ? W / 1000 : H / 720;\n  const c = THEMES[theme];\n  const dark = theme === \"dark\";\n  const fg = ink ?? c.fg;\n  const resolvedGround: GshPresetId | undefined =\n    ground ?? (groundParams ? undefined : dark ? \"hearth\" : undefined);\n  const resolvedParams = groundParams ?? (dark ? undefined : LIGHT_GROUND);\n\n  const plan = useMemo(() => {\n    const glyphs: Glyph[] = Array.from(typed).map((ch, i) => ({\n      ch,\n      seg: -1,\n      i,\n    }));\n    const segs: Segment[] = [];\n    let clock = TYPE_START + typed.length * PER_CHAR + GHOST_LEAD;\n    suggestions.forEach((raw, k) => {\n      const text =\n        raw.startsWith(\"\\n\") || raw.startsWith(\" \") ? raw : ` ${raw}`;\n      const chars = Array.from(text);\n      const start = glyphs.length;\n      chars.forEach((ch, i) => {\n        glyphs.push({ ch, seg: k, i });\n      });\n      const fillDur = Math.max(7, Math.min(12, chars.length * 0.6));\n      const ghostIn = clock;\n      const accept = ghostIn + hold + (k === 0 ? 6 : 0);\n      segs.push({\n        start,\n        length: chars.length,\n        breaks: chars.filter((ch) => ch === \"\\n\").length,\n        ghostIn,\n        accept,\n        fillDur,\n      });\n      clock = accept + fillDur + AFTER_FILL;\n    });\n    const lines: number[] = [0];\n    for (const g of glyphs) {\n      if (g.ch === \"\\n\") lines.push(0);\n      else lines[lines.length - 1] += advance(g.ch) + TRACK;\n    }\n    return {\n      glyphs,\n      segs,\n      widest: Math.max(...lines) - TRACK,\n      lineCount: lines.length,\n      end: clock,\n    };\n  }, [typed, suggestions, hold]);\n  const { glyphs, segs } = plan;\n  const last = segs[segs.length - 1];\n\n  const F = Math.min(\n    (tall ? 104 : 112) * u,\n    (W * (tall ? 0.72 : 0.62)) / plan.widest,\n    (H * 0.4) / (plan.lineCount * LEADING),\n  );\n  const lineH = F * LEADING;\n  const blockW = plan.widest * F;\n\n  const padX = 44 * u;\n  const headH = 66 * u;\n  const padTop = headH + 14 * u;\n  const footH = tall ? 16 * u : 72 * u;\n  const cardW = blockW + padX * 2 + F * 0.2;\n\n  const visLines =\n    1 +\n    segs.reduce(\n      (n, s) =>\n        n +\n        s.breaks *\n          spring({\n            frame: t - s.ghostIn + 2,\n            fps,\n            config: { damping: 200 },\n            durationInFrames: 14,\n          }),\n      0,\n    );\n  const cardH = padTop + visLines * lineH + 28 * u + footH;\n  const finalH = padTop + plan.lineCount * lineH + 28 * u + footH;\n  const cardLeft = (W - cardW) / 2;\n  const cardTop = (tall ? 0.38 : 0.47) * H - finalH / 2;\n  const bigKeyY = cardTop + finalH + 0.13 * H;\n\n  const cardIn = spring({\n    frame: t,\n    fps,\n    config: { mass: 0.8, damping: 18, stiffness: 160 },\n  });\n\n  const typedCount = Math.max(\n    0,\n    Math.min(typed.length, Math.floor((t - TYPE_START) / PER_CHAR) + 1),\n  );\n  let caret = typedCount;\n  let busy = t < TYPE_START + typed.length * PER_CHAR + 2;\n  const fronts = segs.map((s) => {\n    const k = interpolate(t, [s.accept, s.accept + s.fillDur], [0, 1], {\n      ...CLAMP,\n      easing: MOVE,\n    });\n    const front = k * s.length;\n    if (t >= s.accept) caret = s.start + Math.min(s.length, Math.ceil(front));\n    if (t >= s.accept - 2 && t <= s.accept + s.fillDur + 3) busy = true;\n    return front;\n  });\n  const phase = (t % 30) / 30;\n  const blink = busy\n    ? 1\n    : interpolate(phase, [0, 0.45, 0.55, 0.95, 1], [1, 1, 0, 0, 1], CLAMP);\n\n  const styleOf = (g: Glyph): React.CSSProperties => {\n    if (g.seg < 0) return { color: fg };\n    const s = segs[g.seg];\n    const appear = interpolate(\n      t,\n      [s.ghostIn + g.i * 0.35, s.ghostIn + g.i * 0.35 + 6],\n      [0, 1],\n      { ...CLAMP, easing: ENTER },\n    );\n    const filled = Math.min(1, Math.max(0, fronts[g.seg] - g.i));\n    const settleAt = s.accept + s.fillDur + AFTER_FILL;\n    const settle =\n      keepLastFill && g.seg === segs.length - 1\n        ? 0\n        : interpolate(t, [settleAt, settleAt + SETTLE], [0, 1], {\n            ...CLAMP,\n            easing: MOVE,\n          });\n    if (filled <= 0) return { color: c.ghost, opacity: appear };\n    if (settle > 0) {\n      return { color: interpolateColors(settle, [0, 1], [c.fill, fg]) };\n    }\n    return { color: interpolateColors(filled, [0, 1], [c.ghost, c.fill]) };\n  };\n\n  const hintOut = interpolate(\n    t,\n    [last.accept + last.fillDur + 4, last.accept + last.fillDur + 12],\n    [0, 1],\n    { ...CLAMP, easing: EXIT },\n  );\n  const hintArmed = interpolate(\n    t,\n    [segs[0].ghostIn + 2, segs[0].ghostIn + 12],\n    [0, 1],\n    { ...CLAMP, easing: ENTER },\n  );\n  const press = segs.reduce((p, s) => {\n    const down = spring({\n      frame: t - s.accept + 3,\n      fps,\n      config: { mass: 0.5, damping: 12, stiffness: 200 },\n    });\n    const up = spring({\n      frame: t - s.accept - 2,\n      fps,\n      config: { mass: 0.5, damping: 12, stiffness: 200 },\n    });\n    return Math.max(p, Math.max(0, down - up));\n  }, 0);\n  const logoIn = interpolate(t, [plan.end - 2, plan.end + 12], [0, 1], {\n    ...CLAMP,\n    easing: ENTER,\n  });\n  const push = interpolate(t, [0, plan.end + 40], [1, 1.03], {\n    ...CLAMP,\n    easing: MOVE,\n  });\n\n  const caretEl = (\n    <span\n      key=\"caret\"\n      style={{\n        display: \"inline-block\",\n        position: \"relative\",\n        width: 0,\n        height: \"0.86em\",\n        verticalAlign: \"-0.1em\",\n      }}\n    >\n      <span\n        style={{\n          position: \"absolute\",\n          left: \"0.035em\",\n          top: 0,\n          bottom: 0,\n          width: Math.max(2, 0.04 * F),\n          borderRadius: 2,\n          background: c.fill,\n          opacity: blink,\n        }}\n      />\n    </span>\n  );\n\n  const nodes: React.ReactNode[] = [];\n  glyphs.forEach((g, idx) => {\n    if (idx === caret) nodes.push(caretEl);\n    const visible =\n      g.seg < 0 ? idx < typedCount : t >= segs[g.seg].ghostIn - 0.5;\n    if (!visible) return;\n    if (g.ch === \"\\n\") {\n      nodes.push(<br key={idx} />);\n      return;\n    }\n    nodes.push(\n      <span key={idx} style={styleOf(g)}>\n        {g.ch}\n      </span>,\n    );\n  });\n  if (caret >= glyphs.length) nodes.push(caretEl);\n\n  const label = (size: number): React.CSSProperties => ({\n    fontFamily,\n    fontWeight: 400,\n    fontSize: size,\n    letterSpacing: \"-0.01em\",\n    color: c.dim,\n  });\n\n  const keyCap = (k: number, raised: boolean) => (\n    <div\n      style={{\n        height: 34 * k,\n        padding: `0 ${12 * k}px`,\n        display: \"flex\",\n        alignItems: \"center\",\n        borderRadius: 8 * k,\n        background: interpolateColors(\n          press,\n          [0, 1],\n          [raised ? c.card : c.keyBg, c.fill],\n        ),\n        boxShadow: `inset 0 0 0 1px ${c.key}, 0 ${(1 - press) * 2 * k}px 0 ${c.key}${raised ? `, ${c.depth}` : \"\"}`,\n        transform: `translateY(${press * 2 * k}px) scale(${1 - press * 0.04})`,\n        color: interpolateColors(\n          press,\n          [0, 1],\n          [fg, dark ? \"#1A0E06\" : \"#FFFFFF\"],\n        ),\n        fontFamily: mono,\n        fontWeight: 400,\n        fontSize: 17 * k,\n        letterSpacing: \"0.02em\",\n      }}\n    >\n      {keyLabel}\n    </div>\n  );\n\n  const keyIn = spring({\n    frame: t - segs[0].ghostIn + 4,\n    fps,\n    config: { mass: 0.8, damping: 18, stiffness: 160 },\n  });\n\n  return (\n    <AbsoluteFill\n      style={{\n        background:\n          background === undefined\n            ? c.base\n            : background === \"transparent\"\n              ? undefined\n              : background,\n        overflow: \"hidden\",\n      }}\n    >\n      {background === undefined ? (\n        <>\n          <GshGround\n            preset={resolvedGround}\n            params={resolvedParams}\n            timeOffset={dark ? 6 : 2}\n            timeScale={0.45}\n          />\n          <AbsoluteFill style={{ background: c.scrim }} />\n        </>\n      ) : null}\n      <ScaleLayer scale={scale}>\n        <AbsoluteFill style={{ transform: `scale(${push})` }}>\n          <div\n            style={{\n              position: \"absolute\",\n              left: cardLeft,\n              top: cardTop,\n              width: cardW,\n              height: cardH,\n              borderRadius: 28 * u,\n              background: c.card,\n              boxShadow: c.depth,\n              overflow: \"hidden\",\n              opacity: interpolate(cardIn, [0, 0.4], [0, 1], CLAMP),\n              transform: `translateY(${(1 - cardIn) * 40 * u}px) scale(${0.96 + 0.04 * cardIn})`,\n            }}\n          >\n            <div\n              style={{\n                position: \"absolute\",\n                left: padX,\n                top: 0,\n                height: headH,\n                display: \"flex\",\n                alignItems: \"flex-end\",\n                gap: 10 * u,\n              }}\n            >\n              <svg\n                viewBox=\"0 0 24 24\"\n                width={(tall ? 28 : 22) * u}\n                height={(tall ? 28 : 22) * u}\n                style={{ marginBottom: 1 * u }}\n                aria-hidden\n              >\n                <g\n                  fill=\"none\"\n                  stroke={c.dim}\n                  strokeWidth={1.5}\n                  strokeLinecap=\"round\"\n                  strokeLinejoin=\"round\"\n                >\n                  <path d=\"M6.5 3.5h7l4 4v13h-11z\" />\n                  <path d=\"M13.5 3.5v4h4M9.5 12.5h5M9.5 16h5\" />\n                </g>\n              </svg>\n              <div style={label((tall ? 26 : 19) * u)}>{title}</div>\n            </div>\n            <div\n              style={{\n                position: \"absolute\",\n                left: padX,\n                top: padTop,\n                width: blockW + F,\n                fontFamily,\n                fontWeight: 400,\n                fontSize: F,\n                lineHeight: LEADING,\n                letterSpacing: `${TRACK}em`,\n                whiteSpace: \"pre\",\n                fontKerning: \"normal\",\n              }}\n            >\n              {nodes}\n            </div>\n            {tall ? null : (\n              <div\n                style={{\n                  position: \"absolute\",\n                  left: 0,\n                  right: 0,\n                  bottom: 0,\n                  height: footH,\n                  borderTop: `1px solid ${c.divider}`,\n                  display: \"flex\",\n                  alignItems: \"center\",\n                  justifyContent: \"space-between\",\n                  padding: `0 ${padX - 10 * u}px 0 ${padX}px`,\n                }}\n              >\n                <div\n                  style={{\n                    display: \"flex\",\n                    alignItems: \"center\",\n                    gap: 12 * u,\n                    opacity: (0.35 + 0.65 * hintArmed) * (1 - hintOut),\n                  }}\n                >\n                  {keyCap(u, false)}\n                  <div style={label(19 * u)}>{hintLabel}</div>\n                </div>\n                {showLogo ? (\n                  <div\n                    style={{\n                      opacity: logoIn,\n                      transform: `translateY(${(1 - logoIn) * 8 * u}px)`,\n                    }}\n                  >\n                    {logo ?? <KuchiLogo fontSize={24 * u} color={c.logo} />}\n                  </div>\n                ) : null}\n              </div>\n            )}\n          </div>\n          {tall ? (\n            <div\n              style={{\n                position: \"absolute\",\n                left: 0,\n                right: 0,\n                top: bigKeyY,\n                display: \"flex\",\n                flexDirection: \"column\",\n                alignItems: \"center\",\n                gap: 30 * u,\n                opacity:\n                  Math.min(1, keyIn * 1.4) *\n                  (0.35 + 0.65 * hintArmed) *\n                  (1 - 0.5 * hintOut),\n                transform: `translateY(${(1 - keyIn) * 40 * u}px)`,\n              }}\n            >\n              {keyCap(3.4 * u, true)}\n              <div style={label(34 * u)}>{hintLabel}</div>\n            </div>\n          ) : null}\n          {tall && showLogo ? (\n            <div\n              style={{\n                position: \"absolute\",\n                left: 0,\n                right: 0,\n                top: bigKeyY + 290 * u,\n                display: \"flex\",\n                justifyContent: \"center\",\n                opacity: logoIn,\n                transform: `translateY(${(1 - logoIn) * 12 * u}px)`,\n              }}\n            >\n              {logo ?? <KuchiLogo fontSize={40 * u} color={c.logo} />}\n            </div>\n          ) : null}\n        </AbsoluteFill>\n      </ScaleLayer>\n    </AbsoluteFill>\n  );\n}\n"}]}