{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "cooling-type",
  "title": "Cooling Type",
  "description": "\"What if your launch video could write itself?\" cools in, ending on an italic word and a caret.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "registryDependencies": ["@remocn/gsh"],
  "files": [
    {
      "path": "registry/remocn/cooling-type/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont as loadSerif } from \"@remotion/google-fonts/InstrumentSerif\";\nimport { loadFont as loadInter } from \"@remotion/google-fonts/InterTight\";\nimport { type ReactNode, useEffect, useMemo, useRef, useState } from \"react\";\nimport {\n  AbsoluteFill,\n  continueRender,\n  delayRender,\n  Easing,\n  interpolate,\n  random,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\nimport type { GradientParams } from \"@/lib/remocn/gsh/gradient-engine\";\nimport { GshGround, gshParams } from \"@/lib/remocn/gsh/gsh-ground\";\nimport type { GshPresetId } from \"@/lib/remocn/gsh/presets\";\n\nconst inter = loadInter(\"normal\", {\n  weights: [\"300\"],\n  subsets: [\"latin\"],\n});\nconst serif = loadSerif(\"italic\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\n\nexport interface CoolingTypeProps {\n  text?: string;\n  accentWord?: string;\n  hot?: string;\n  accent?: string;\n  ink?: string;\n  theme?: \"dark\" | \"light\";\n  ground?: GshPresetId;\n  groundParams?: Partial<GradientParams>;\n  startAt?: number;\n  charFrames?: number;\n  coolFrames?: number;\n  seed?: number;\n}\n\nconst LIGHT_GROUND: Partial<GradientParams> = {\n  kind: \"aurora\",\n  background: \"#eef2f4\",\n  colors: [\"#d4e4ff\", \"#f3f5f7\", \"#cfeee6\", \"#e7e3fb\"],\n  blur: 0.85,\n  warp: 0.35,\n  seed: 4,\n  grain: 0.16,\n};\n\nconst THEMES = {\n  dark: {\n    ink: \"#eef3f1\",\n    hot: \"#7dffd9\",\n    accent: \"#7de8c8\",\n    glow: 1,\n    band: 0.3,\n    ground: \"kiruna\" as GshPresetId | undefined,\n    groundParams: undefined as Partial<GradientParams> | undefined,\n    groundOffset: 5,\n    scrim: \"2,8,8\",\n    scrimAlpha: 0.72,\n  },\n  light: {\n    ink: \"#141618\",\n    hot: \"#2f5bff\",\n    accent: \"#2f5bff\",\n    glow: 0.45,\n    band: 0.2,\n    ground: undefined as GshPresetId | undefined,\n    groundParams: LIGHT_GROUND as Partial<GradientParams> | undefined,\n    groundOffset: 3,\n    scrim: \"238,242,244\",\n    scrimAlpha: 0.4,\n  },\n};\n\nconst BEAT = {\n  start: -3,\n  breath: 8,\n  accentRate: 1.25,\n};\n\nconst FONT_PX = 200;\nconst TRACK = -0.028;\nconst COOL = Easing.bezier(0.33, 0, 0.2, 1);\nconst KEY = Easing.bezier(0.22, 1, 0.36, 1);\nconst CAMERA = Easing.bezier(0.87, 0, 0.13, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\ntype Measure = (s: string, serifFace: boolean) => number;\n\nfunction buildMeasure(_version: number): Measure {\n  const ctx = document.createElement(\"canvas\").getContext(\"2d\");\n  const cache: Record<string, number> = {};\n  return (s: string, serifFace: boolean) => {\n    const k = `${serifFace ? 1 : 0}|${s}`;\n    if (cache[k] === undefined) {\n      if (!ctx) return s.length * 0.5;\n      ctx.font = serifFace\n        ? `italic 400 ${FONT_PX}px \"${serif.fontFamily}\"`\n        : `300 ${FONT_PX}px \"${inter.fontFamily}\"`;\n      const tr = serifFace ? -0.01 : TRACK;\n      cache[k] = ctx.measureText(s).width / FONT_PX + tr * Array.from(s).length;\n    }\n    return cache[k];\n  };\n}\n\nfunction useMeasure() {\n  const [version, setVersion] = useState(0);\n  const [handle] = useState(() => delayRender(\"cooling-type: fonts\"));\n  const released = useRef(false);\n  useEffect(() => {\n    let live = true;\n    const bump = () => {\n      if (live) setVersion((v) => v + 1);\n    };\n    document.fonts.addEventListener(\"loadingdone\", bump);\n    Promise.all([\n      inter.waitUntilDone(),\n      serif.waitUntilDone(),\n      document.fonts.load(`300 100px \"${inter.fontFamily}\"`),\n      document.fonts.load(`italic 400 100px \"${serif.fontFamily}\"`),\n    ])\n      .catch(() => undefined)\n      .then(() => {\n        bump();\n        if (!released.current) {\n          released.current = true;\n          continueRender(handle);\n        }\n      });\n    return () => {\n      live = false;\n      document.fonts.removeEventListener(\"loadingdone\", bump);\n    };\n  }, [handle]);\n  return useMemo(() => buildMeasure(version), [version]);\n}\n\ninterface Ch {\n  ch: string;\n  x: number;\n  w: number;\n  line: number;\n  serif: boolean;\n  t: number;\n}\n\nexport function CoolingType({\n  text = \"What if your launch video could write itself?\",\n  accentWord = \"itself?\",\n  hot,\n  accent,\n  ink,\n  theme = \"dark\",\n  ground,\n  groundParams,\n  startAt = BEAT.start,\n  charFrames = 1.6,\n  coolFrames = 20,\n  seed = 5,\n}: CoolingTypeProps) {\n  const frame = useCurrentFrame();\n  const { width: W, height: H, durationInFrames } = useVideoConfig();\n  const c = THEMES[theme];\n  const inkC = ink ?? c.ink;\n  const hotC = hot ?? c.hot;\n  const accC = accent ?? c.accent;\n  const preset = ground ?? (groundParams ? undefined : c.ground);\n  const gParams = groundParams ?? (ground ? undefined : c.groundParams);\n  const bg = gshParams(preset, gParams).background;\n  const portrait = H > W * 1.1;\n  const m = useMeasure();\n\n  let content: ReactNode = <div />;\n  if (m) {\n    const words = text.split(\" \").filter((w) => w.length > 0);\n    const accIdx = accentWord ? words.lastIndexOf(accentWord) : -1;\n    const isSerif = (wi: number) => wi === accIdx;\n    const wordW = (wi: number) => m(words[wi], isSerif(wi));\n    const space = m(\" \", false);\n    const maxW = (portrait ? 0.84 : 0.78) * W;\n    const maxLines = portrait ? 5 : 2;\n    let size = portrait ? W * 0.16 : H * 0.125;\n    let rows: number[][] = [];\n    const rowW = (row: number[]) =>\n      row.reduce((a, wi, k) => a + wordW(wi) + (k > 0 ? space : 0), 0);\n    for (let k = 0; k < 30; k++) {\n      rows = [];\n      let cur: number[] = [];\n      words.forEach((_, wi) => {\n        const next = [...cur, wi];\n        if (cur.length > 0 && rowW(next) * size > maxW) {\n          rows.push(cur);\n          cur = [wi];\n        } else {\n          cur = next;\n        }\n      });\n      if (cur.length > 0) rows.push(cur);\n      if (\n        rows.length <= maxLines &&\n        rows.every((rw) => rowW(rw) * size <= maxW)\n      )\n        break;\n      size *= 0.94;\n    }\n    const LH = size * 1.14;\n    const blockW = Math.max(...rows.map(rowW)) * size;\n    const x0 = (W - blockW) / 2;\n    const top = H / 2 - (rows.length * LH) / 2;\n    const lineY = (li: number) => top + LH * (li + 0.5);\n\n    const chars: Ch[] = [];\n    let t = startAt;\n    let total = 0;\n    rows.forEach((rw) => {\n      total += rw.reduce((a, wi) => a + words[wi].length + 1, 0);\n    });\n    let n = 0;\n    rows.forEach((rw, li) => {\n      let x = x0;\n      rw.forEach((wi, k) => {\n        if (k > 0) {\n          x += space * size;\n        }\n        const sf = isSerif(wi);\n        if (sf) t += BEAT.breath;\n        const word = words[wi];\n        Array.from(word).forEach((ch, ci) => {\n          const pre = word.slice(0, ci);\n          const cx = x + m(pre, sf) * size;\n          const cw = m(ch, sf) * size;\n          chars.push({ ch, x: cx, w: cw, line: li, serif: sf, t });\n          const accel = 1.2 - 0.45 * (n / Math.max(1, total));\n          const jitter = (random(`ct-${seed}-${n}`) - 0.5) * 0.9;\n          let step = sf ? BEAT.accentRate : charFrames * accel + jitter;\n          if (/[,.;:!?]/.test(ch)) step += 4;\n          t += Math.max(0.6, step);\n          n++;\n        });\n        x += wordW(wi) * size;\n        t += sf ? 0 : charFrames * 0.9;\n        n++;\n      });\n    });\n    const typedEnd = chars.length > 0 ? chars[chars.length - 1].t : startAt;\n    const f = frame;\n\n    const shownAt = (fr: number) => {\n      let k = 0;\n      while (k < chars.length && chars[k].t <= fr) k++;\n      return k;\n    };\n    const caretAt = (fr: number) => {\n      const k = shownAt(fr);\n      if (k === 0) return { x: x0, li: 0 };\n      const cur = chars[k - 1];\n      const end = cur.x + cur.w;\n      const prevEnd =\n        k >= 2 && chars[k - 2].line === cur.line\n          ? chars[k - 2].x + chars[k - 2].w\n          : cur.x;\n      const e = KEY(Math.min(1, (fr - cur.t) / 2));\n      return { x: prevEnd + (end - prevEnd) * e, li: cur.line };\n    };\n\n    const heatOf = (ch: Ch) => {\n      const a = f - ch.t;\n      const len = ch.serif ? coolFrames * 1.8 : coolFrames;\n      return 1 - interpolate(a, [0, len], [0, 1], { ...CLAMP, easing: COOL });\n    };\n\n    const pct = (v: number) =>\n      `${(Math.max(0, Math.min(1, v)) * 100).toFixed(1)}%`;\n\n    const bands = rows.map((_, li) => {\n      const warm = chars.filter(\n        (ch) => ch.line === li && ch.t <= f && heatOf(ch) > 0.04,\n      );\n      if (warm.length === 0) return null;\n      const peak = Math.max(...warm.map(heatOf));\n      const left = warm[0].x - size * 0.06;\n      const last = warm[warm.length - 1];\n      const right = last.x + last.w + size * 0.08;\n      return (\n        <div\n          key={`b${li}`}\n          style={{\n            position: \"absolute\",\n            left,\n            top: lineY(li) - LH * 0.46,\n            width: Math.max(1, right - left),\n            height: LH * 0.92,\n            borderRadius: LH * 0.18,\n            background: `linear-gradient(90deg, color-mix(in oklab, ${hotC} 0%, transparent) 0%, color-mix(in oklab, ${hotC} ${pct(c.band * peak)}, transparent) 100%)`,\n            filter: `blur(${(size * 0.07).toFixed(2)}px)`,\n          }}\n        />\n      );\n    });\n\n    const glyphEls = chars.map((ch, i) => {\n      if (ch.t > f) return null;\n      const a = f - ch.t;\n      const heat = heatOf(ch);\n      const e = KEY(Math.min(1, a / 4));\n      const target = ch.serif ? accC : inkC;\n      const flare = ch.serif ? 1.4 : 1;\n      const g = heat * c.glow * flare;\n      const shadow =\n        g > 0.02\n          ? `0 0 ${(size * 0.12 * g).toFixed(2)}px color-mix(in oklab, ${hotC} ${pct(0.9 * g)}, transparent), 0 0 ${(size * 0.42 * g).toFixed(2)}px color-mix(in oklab, ${hotC} ${pct(0.4 * g)}, transparent)`\n          : undefined;\n      return (\n        <div\n          key={`c${i}`}\n          style={{\n            position: \"absolute\",\n            left: ch.x,\n            top: lineY(ch.line) - size / 2,\n            height: size,\n            display: \"flex\",\n            alignItems: \"center\",\n            fontFamily: ch.serif ? serif.fontFamily : inter.fontFamily,\n            fontStyle: ch.serif ? \"italic\" : \"normal\",\n            fontWeight: ch.serif ? 400 : 300,\n            fontSize: ch.serif ? size * 1.04 : size,\n            lineHeight: 1,\n            whiteSpace: \"pre\",\n            color: `color-mix(in oklab, ${hotC} ${pct(heat)}, ${target})`,\n            textShadow: shadow,\n            opacity: Math.min(1, 0.35 + a / 1.5),\n            transform: `translateY(${((1 - e) * size * 0.1).toFixed(2)}px)`,\n            filter:\n              e < 0.98 ? `blur(${((1 - e) * 4).toFixed(2)}px)` : undefined,\n          }}\n        >\n          {ch.ch}\n        </div>\n      );\n    });\n\n    const cur = caretAt(f);\n    const back = caretAt(f - 3);\n    const typing = f <= typedEnd + 2;\n    const vel = cur.li === back.li ? Math.max(0, (cur.x - back.x) / 3) : 0;\n    const trail = typing\n      ? Math.min(size * 2.6, Math.max(size * 0.25, vel * 7))\n      : interpolate(f, [typedEnd + 2, typedEnd + 10], [size * 0.25, 0], CLAMP);\n    const caretHeat = typing\n      ? 1\n      : 1 -\n        interpolate(f, [typedEnd, typedEnd + coolFrames], [0, 1], {\n          ...CLAMP,\n          easing: COOL,\n        });\n    const blink = typing || Math.floor((f - typedEnd) / 15) % 2 === 1;\n    const caretW = Math.max(2, size * 0.045);\n    const caretH = size * 1.02;\n    const caretC = `color-mix(in oklab, ${hotC} ${pct(caretHeat)}, ${inkC})`;\n    const cx = cur.x + size * 0.05;\n    const cy = lineY(cur.li);\n    const caret = (\n      <>\n        {trail > 1 ? (\n          <div\n            style={{\n              position: \"absolute\",\n              left: cx - trail,\n              top: cy - caretH * 0.2,\n              width: trail,\n              height: caretH * 0.4,\n              borderRadius: caretH,\n              background: `linear-gradient(90deg, color-mix(in oklab, ${hotC} 0%, transparent) 0%, color-mix(in oklab, ${hotC} ${pct(0.55 * c.glow + 0.15)}, transparent) 100%)`,\n              filter: `blur(${(size * 0.09).toFixed(2)}px)`,\n            }}\n          />\n        ) : null}\n        <div\n          style={{\n            position: \"absolute\",\n            left: cx,\n            top: cy - caretH / 2,\n            width: caretW,\n            height: caretH,\n            borderRadius: caretW,\n            background: caretC,\n            opacity: blink ? 1 : 0,\n            boxShadow: `0 0 ${(size * 0.18 * caretHeat * c.glow).toFixed(2)}px color-mix(in oklab, ${hotC} ${pct(0.8 * caretHeat)}, transparent)`,\n          }}\n        />\n      </>\n    );\n\n    const push = interpolate(frame, [0, durationInFrames], [1, 1.04], {\n      ...CLAMP,\n      easing: CAMERA,\n    });\n    content = (\n      <AbsoluteFill\n        style={{\n          transform: `scale(${push.toFixed(5)})`,\n          transformOrigin: \"50% 50%\",\n        }}\n      >\n        {bands}\n        {glyphEls}\n        {caret}\n      </AbsoluteFill>\n    );\n  }\n\n  return (\n    <AbsoluteFill style={{ background: bg, overflow: \"hidden\" }}>\n      <GshGround\n        preset={preset}\n        params={gParams}\n        timeOffset={c.groundOffset}\n        timeScale={0.5}\n      />\n      <AbsoluteFill\n        style={{\n          background: `radial-gradient(${portrait ? \"95% 50%\" : \"72% 62%\"} at 50% 50%, rgba(${c.scrim},${c.scrimAlpha}) 0%, rgba(${c.scrim},0) 100%)`,\n        }}\n      />\n      {content}\n    </AbsoluteFill>\n  );\n}\n\nexport default CoolingType;\n",
      "type": "registry:component",
      "target": "components/remocn/cooling-type.tsx"
    }
  ],
  "type": "registry:component"
}
