{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "hidden-word",
  "title": "Hidden Word",
  "description": "A word is found hidden inside a sentence and lifted out as a large italic title.",
  "dependencies": ["remotion", "@remotion/google-fonts"],
  "files": [
    {
      "path": "registry/remocn/hidden-word/index.tsx",
      "content": "\"use client\";\n\nimport { loadFont } from \"@remotion/google-fonts/HankenGrotesk\";\nimport { loadFont as loadSerif } from \"@remotion/google-fonts/InstrumentSerif\";\nimport { type ReactNode, useId, useMemo } from \"react\";\nimport {\n  AbsoluteFill,\n  Easing,\n  interpolate,\n  interpolateColors,\n  useCurrentFrame,\n  useVideoConfig,\n} from \"remotion\";\n\nconst { fontFamily: sans } = loadFont(\"normal\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\nconst { fontFamily: serif } = loadSerif(\"italic\", {\n  weights: [\"400\"],\n  subsets: [\"latin\"],\n});\n\nexport interface HiddenWordProps {\n  /** The sentence, set as editorial body type. */\n  text?: string;\n  /** The word hiding in it; its letters are found in order inside `text`. */\n  word?: string;\n  accent?: string;\n  theme?: \"dark\" | \"light\";\n  speed?: number;\n}\n\n// Hanken Grotesk 400 (the sentence) and Instrument Serif italic 400 (the\n// found word): advance widths (1/1000 em) for ASCII 32–126, punctuation,\n// kern pairs and vertical metrics.\nconst HANKEN_400 = [\n  260, 240, 338, 699, 560, 747, 686, 174, 222, 222, 398, 560, 240, 327, 240,\n  418, 560, 560, 560, 560, 560, 560, 560, 560, 560, 560, 240, 240, 560, 560,\n  560, 516, 874, 637, 601, 704, 682, 585, 565, 731, 678, 246, 552, 634, 495,\n  839, 676, 748, 554, 774, 598, 564, 587, 656, 656, 957, 641, 602, 582, 258,\n  448, 258, 552, 405, 292, 540, 587, 518, 587, 540, 335, 514, 547, 226, 226,\n  532, 265, 828, 547, 577, 587, 587, 407, 470, 346, 547, 521, 748, 520, 521,\n  472, 239, 258, 239, 560,\n];\nconst SERIF_ITALIC_400 = [\n  170, 275, 374, 629, 424, 591, 525, 235, 346, 346, 449, 531, 219, 426, 219,\n  258, 461, 248, 404, 373, 394, 387, 411, 365, 437, 414, 299, 301, 531, 531,\n  531, 358, 665, 457, 479, 475, 536, 454, 411, 514, 545, 250, 251, 499, 414,\n  665, 542, 540, 469, 541, 525, 424, 461, 537, 458, 653, 545, 478, 427, 326,\n  256, 326, 431, 372, 355, 474, 431, 351, 474, 348, 273, 401, 476, 288, 266,\n  447, 240, 745, 521, 414, 450, 425, 368, 302, 272, 508, 412, 609, 450, 418,\n  385, 320, 252, 320, 531,\n];\nconst PUNCT_HANKEN: Record<string, number> = {\n  \"‘\": 263,\n  \"’\": 263,\n  \"“\": 436,\n  \"”\": 438,\n  \"…\": 668,\n  \"–\": 412,\n  \"—\": 1058,\n};\nconst PUNCT_SERIF: Record<string, number> = {\n  \"‘\": 166,\n  \"’\": 166,\n  \"“\": 316,\n  \"”\": 316,\n  \"…\": 539,\n  \"–\": 505,\n  \"—\": 715,\n};\nconst KERN_HANKEN = [\n  \"AC31 AG31 AO31 AQ31 AT95 AU27 AV81 AW72 AY90 Af43 Al10 At47 Av55 Aw45\",\n  \"Ay55 A’48 A“49 A”48 BT26 BV31 BW24 BX20 BY42 Bv12 By12 B’10 B“15 B”10\",\n  \"CA10 CV12 CX20 CY23 D,27 DA31 DT48 DV36 DW22 DX51 DY53 DZ33 EJ10 ES10\",\n  \"Ef12 Et14 Ev24 Ew16 Ey24 E“15 F,63 FA83 FC10 FG10 FJ42 FO10 FQ10 FS28\",\n  \"Fa42 Fc31 Fd31 Fe31 Ff15 Fg38 Fm37 Fn37 Fo31 Fp37 Fq31 Fr37 Fs40 Ft15\",\n  \"Fu32 Fv37 Fw31 Fx49 Fy37 Fz39 GT36 GV33 GW23 GY45 Gv13 Gy13 G’11 G“19\",\n  \"G”11 J,13 JA26 KC49 KG49 KO49 KQ49 KS15 Kc25 Kd25 Ke25 Kf44 Ko25 Kq25\",\n  \"Kt49 Ku19 Kv69 Kw60 Ky69 K’26 K“36 K”26 LC46 LG46 LO46 LQ46 LT119\",\n  \"LU31 LV110 LW102 LY116 Lc10 Ld10 Le10 Lf45 Lo10 Lq10 Lt50 Lv89 Lw57\",\n  \"Ly89 L’59 L“60 L”59 O,27 OA31 OT44 OV34 OW21 OX49 OY50 OZ33 P,63 PA81\",\n  \"PJ64 PX20 PZ20 Pa16 Pc30 Pd30 Pe30 Pg24 Po30 Pq30 Ps19 QJ11 QS16 QT56\",\n  \"QV47 QW34 QY62 RC16 RG16 RJ15 RO16 RQ16 RS15 RT21 RU17 RV29 RW21 RY39\",\n  \"Rc21 Rd21 Re21 Ro21 Rq21 SV23 SW17 SX14 SY31 Sf32 St31 Sv33 Sw17 Sx14\",\n  \"Sy33 S’33 S“36 S”33 T,49 TA95 TC44 TG44 TJ36 TO44 TQ44 TS19 Ta95 Tc95\",\n  \"Td95 Te95 Tf40 Tg92 Tm92 Tn92 To95 Tp92 Tq95 Tr92 Ts95 Tt43 Tu93 Tv76\",\n  \"Tw80 Tx81 Ty76 Tz98 T“11 U,13 UA26 V,49 VA81 VC34 VG34 VJ40 VO34 VQ34\",\n  \"VS27 Va68 Vc68 Vd68 Ve68 Vf16 Vg68 Vm57 Vn57 Vo68 Vp57 Vq68 Vr57 Vs69\",\n  \"Vt17 Vu55 Vv24 Vw28 Vx29 Vy24 Vz49 V“10 W,43 WA72 WC21 WG21 WJ43 WO21\",\n  \"WQ21 WS20 Wa47 Wc50 Wd50 We50 Wg52 Wm37 Wn37 Wo50 Wp37 Wq50 Wr37 Ws48\",\n  \"Wu34 Wv11 Ww16 Wx17 Wy11 Wz32 XC48 XG48 XJ12 XO48 XQ48 XS16 Xc27 Xd27\",\n  \"Xe27 Xf37 Xo27 Xq27 Xt41 Xu20 Xv66 Xw59 Xy66 X’19 X“33 X”19 Y,50 YA90\",\n  \"YC49 YG49 YJ36 YO49 YQ49 YS36 Ya81 Yc83 Yd83 Ye83 Yf34 Yg80 Ym78 Yn78\",\n  \"Yo83 Yp78 Yq83 Yr78 Ys83 Yt35 Yu80 Yv45 Yw49 Yx50 Yy45 Yz71 Y“21 ZC35\",\n  \"ZG35 ZO35 ZQ35 Zc18 Zd18 Ze18 Zf25 Zo18 Zq18 Zt27 Zv51 Zw49 Zy51 Z“24\",\n  \"av13 ay13 bf22 bt21 bv14 bx24 by14 bz11 b’36 b“33 b”36 ev10 ex11 ey10\",\n  \"f,62 f.60 fc30 fd30 fe30 ff90 fg22 fi10 fl10 fo30 fq30 fs10 gs11 hf16\",\n  \"ht13 hv13 hy13 h’27 h“26 h”27 kc26 kd26 ke26 kl27 ko26 kq26 lf20 lt10\",\n  \"l’28 l“32 l”28 mv13 my13 nv13 ny13 of10 ot11 ov14 ox25 oy14 oz12 r,49\",\n  \"r.100 ra13 rc28 rd28 re28 rg23 rl20 ro28 rq28 rs15 tc10 td10 te10\",\n  \"to10 tq10 v,40 vc14 vd14 ve14 vg12 vo14 vq14 w,34 xc25 xd25 xe25 xo25\",\n  \"xq25 y,40 yc14 yd14 ye14 yg12 yo14 yq14 zc11 zd11 ze11 zo11 zq11\",\n].join(\" \");\nconst KERN_SERIF = [\n  \"AA24 AB16 AC46 AD16 AE16 AF16 AG46 AH16 AI16 AJ12 AK16 AL16 AN16 AO46\",\n  \"AP16 AQ46 AR16 AS12 AT50 AU36 AV68 AW68 AX90 AY73 Aa18 Ab18 Ac18 Ad18\",\n  \"Ae18 Af12 Ag12 Ah12 Ai24 Aj16 Ak12 Al12 Am18 An18 Ao18 Aq18 Ar18 At18\",\n  \"Au20 Av32 Aw32 Ay48 BT12 BU12 BV16 BW16 BX40 BY28 CC12 CG12 CO12 CQ12\",\n  \"CX22 CY12 Cg24 Cu24 Cv24 Cw24 Cy24 DA20 DB10 DD10 DE10 DF10 DH10 DI10\",\n  \"DK10 DL10 DP10 DR10 DS12 DT12 DV22 DW22 DX54 DY36 EV12 EW12 EX37 EY20\",\n  \"Ec12 Ed12 Ee12 Eg18 Em12 En12 Eo12 Eq12 Er12 Eu12 Ev24 Ew24 Ex10 Ey24\",\n  \"FA42 FX30 Fa48 Fc48 Fd48 Fe48 Fg44 Fm18 Fn18 Fo48 Fp18 Fq48 Fr18 Fs24\",\n  \"Fu18 Fv18 Fw18 Fx18 Fy18 GB14 GD14 GE14 GF14 GH14 GI14 GK14 GL14 GP14\",\n  \"GR14 GU14 GX38 GY12 Ga12 Gg12 HA10 HV10 HW10 HX30 HY30 Ha18 Hc18 Hd18\",\n  \"He18 Hg14 Ho18 Hq18 Hs18 IA10 IV10 IW10 IX30 IY30 Ia18 Ic18 Id18 Ie18\",\n  \"Ig14 Io18 Iq18 Is18 JA18 JC18 JG18 JO18 JQ18 JS12 JV12 JW12 JX38 JY38\",\n  \"Ja14 Jc16 Jd16 Je16 Jg14 Jo16 Jq16 KA30 KB12 KC52 KD12 KE12 KF12 KG52\",\n  \"KH12 KI12 KK12 KL12 KM12 KN14 KO52 KP12 KQ52 KR12 KS18 KT18 KU32 KV52\",\n  \"KW42 KX30 KY58 Ka28 Kc38 Kd38 Ke38 Kf12 Kg18 Ki32 Kj24 Km32 Kn32 Ko38\",\n  \"Kp32 Kq38 Kr32 Ks14 Kt24 Ku38 Kv38 Kw38 Kx18 Ky46 LC14 LG14 LO14 LQ14\",\n  \"LT54 LU14 LV56 LW56 LX38 LY64 MC12 MG12 MO12 MQ12 MT12 MU10 MV18 MW18\",\n  \"MX33 MY28 Mg12 Mu12 Mv12 Mw12 NA16 NC12 NG12 NO12 NQ12 NV12 NW12 NX48\",\n  \"NY22 Na12 Nc12 Nd12 Ne12 No12 Nq12 OA20 OB10 OD10 OE10 OF10 OH10 OI10\",\n  \"OK10 OL10 OP10 OR10 OS12 OT12 OV22 OW22 OX54 OY36 PA40 PT-21 PX42\",\n  \"Pa24 Pc24 Pd24 Pe24 Pg18 Po24 Pq24 QA20 QB10 QD10 QE10 QF10 QH10 QI10\",\n  \"QK10 QL10 QP10 QR10 QS12 QT12 QV22 QW22 QX54 QY36 RA61 RB12 RC24 RD12\",\n  \"RE12 RF12 RG24 RH12 RI12 RK12 RL12 RO24 RP12 RQ24 RR12 RT20 RU20 RV20\",\n  \"RW24 RX56 RY28 Ra28 Rc32 Rd32 Re32 Rg24 Ro32 Rq32 SU16 SV18 SW18 SX46\",\n  \"SY20 TA42 TM12 TX38 Ta72 Tc64 Td64 Te64 Tg60 Tm24 Tn24 To64 Tp24 Tq64\",\n  \"Tr24 Ts36 Tu36 Tv36 Tw36 Tx36 Ty36 Tz24 UA26 UC12 UG12 UO12 UQ12 US10\",\n  \"UV10 UW10 UX28 UY15 Uc10 Ud10 Ue10 Ug12 Uo10 Uq10 Ux16 Uy12 VA58 VB12\",\n  \"VC14 VD12 VE12 VF12 VG14 VH12 VI12 VJ12 VK12 VL12 VM16 VN18 VO14 VP12\",\n  \"VQ14 VR12 VS10 VU12 VV24 VW24 VX52 VY24 Va64 Vc54 Vd54 Ve54 Vg64 Vm36\",\n  \"Vn36 Vo54 Vp36 Vq54 Vr36 Vt12 Vu32 Vv40 Vw40 Vx40 Vy40 Vz32 WA52 WB10\",\n  \"WC14 WD10 WE10 WF10 WG14 WH10 WI10 WJ12 WK10 WL10 WM16 WN18 WO14 WP10\",\n  \"WQ14 WR10 WS10 WU12 WV24 WX42 WY18 Wa64 Wc54 Wd54 We54 Wg64 Wm36 Wn36\",\n  \"Wo54 Wp36 Wq54 Wr36 Wt12 Wu32 Wv40 Ww40 Wx40 Wy40 Wz32 XA70 XB38 XC64\",\n  \"XD38 XE38 XF38 XG64 XH38 XI38 XJ30 XK38 XL38 XM33 XN38 XO64 XP38 XQ64\",\n  \"XR38 XS40 XT36 XU34 XV48 XW46 XX80 XY50 XZ26 Xa48 Xc48 Xd48 Xe48 Xf34\",\n  \"Xg54 Xh24 Xi48 Xj38 Xk24 Xl24 Xm58 Xn58 Xo48 Xp58 Xq48 Xr58 Xs38 Xt50\",\n  \"Xu60 Xv60 Xw60 Xx60 Xy64 Xz54 YA62 YB34 YC24 YD34 YE34 YF34 YG24 YH34\",\n  \"YI34 YJ32 YK34 YL34 YM32 YN22 YO24 YP34 YQ24 YR34 YS14 YU20 YV24 YW18\",\n  \"YX48 Ya78 Yc64 Yd64 Ye64 Yf27 Yg64 Yi18 Yj10 Ym44 Yn44 Yo64 Yp44 Yq64\",\n  \"Yr44 Ys54 Yt18 Yu48 Yv48 Yw48 Yx68 Yy40 Yz56 ZX26 af14 ag18 at12 ay28\",\n  \"bx22 dg18 dt12 dy28 fa28 fc22 fd22 fe22 ff22 fg24 fh18 fi18 fj18 fk18\",\n  \"fl18 fm12 fn12 fo32 fp12 fq22 fr12 fs12 ft22 fu12 fx22 fy18 ga12 gc12\",\n  \"gd12 ge12 go12 gq12 hg14 ig14 ja18 jc18 jd18 je18 jf14 jg32 ji12 jo18\",\n  \"jq18 kc10 kd10 ke10 kf12 ko10 kq10 kt10 lg14 mg14 ng14 ox22 px22 qx14\",\n  \"ra18 rc18 rd18 re18 rg18 ro18 rq18 ry-20 tg18 ug14 vo12 xb12 xc18\",\n  \"xd18 xe18 xo18 xq18 yo12 zb10\",\n].join(\" \");\n\nconst kernMap = (pairs: string) =>\n  new Map(\n    pairs.split(\" \").map((p) => [p.slice(0, 2), -Number(p.slice(2)) / 1000]),\n  );\n\nconst BODY = {\n  adv: HANKEN_400,\n  punct: PUNCT_HANKEN,\n  kern: kernMap(KERN_HANKEN),\n  track: -0.008,\n  asc: 1,\n  desc: 0.303,\n};\nconst DISPLAY = {\n  adv: SERIF_ITALIC_400,\n  punct: PUNCT_SERIF,\n  kern: kernMap(KERN_SERIF),\n  track: -0.01,\n  asc: 0.99,\n  desc: 0.31,\n};\ntype Face = typeof BODY;\n\nconst LINE = 1.4;\nconst CAP = 0.697;\nconst DESC = 0.21;\nconst LEADING = 1.42;\nconst SERIF_X = 0.51;\n\n/** Distance (em) from a line box's top to its baseline, for `face` at LINE. */\nconst baseOf = (face: Face) => (LINE - face.asc - face.desc) / 2 + face.asc;\n\n// Timing, in frames at speed 1.\nconst ENTER = 22;\nconst LINE_STAGGER = 4;\nconst LIGHT_AT = 44;\nconst LIGHT_STAGGER = 7;\nconst LIGHT = 10;\nconst DIM_AT = 48;\nconst DIM = 28;\nconst LIFT_AT = 86;\nconst LIFT_STAGGER = 6;\nconst FLIGHT = 30;\nconst MOVE_AT = 82;\nconst MOVE = 40;\nconst SETTLE_GAP = 4;\nconst SETTLE = 14;\n\nconst GHOST_SCALE = 0.66;\n\nconst EASE_OUT = Easing.bezier(0.22, 1, 0.36, 1);\nconst EASE_IO = Easing.bezier(0.65, 0, 0.35, 1);\nconst CLAMP = {\n  extrapolateLeft: \"clamp\",\n  extrapolateRight: \"clamp\",\n} as const;\n\n// Ground: gradients.sh \"mist\" (dark) and \"pixel-glass\" (light), a low\n// bloom from the lower right. Dim/ghost greys are translucent so they sit\n// cleanly on the gradient instead of turning muddy.\nconst THEMES = {\n  dark: {\n    bg: \"#060609\",\n    fg: \"#F3F2EF\",\n    dim: \"rgba(243, 242, 239, 0.36)\",\n    ghost: \"rgba(243, 242, 239, 0.24)\",\n    grain: 0.07,\n    mist: [\n      \"rgba(244, 217, 255, 0.5)\",\n      \"rgba(167, 123, 255, 0.46)\",\n      \"rgba(59, 42, 158, 0.5)\",\n      \"rgba(18, 13, 51, 0.6)\",\n    ],\n  },\n  light: {\n    bg: \"#F5F4F0\",\n    fg: \"#121214\",\n    dim: \"rgba(18, 18, 20, 0.36)\",\n    ghost: \"rgba(18, 18, 20, 0.26)\",\n    grain: 0.045,\n    mist: [\n      \"rgba(255, 79, 184, 0.26)\",\n      \"rgba(122, 60, 255, 0.24)\",\n      \"rgba(61, 107, 255, 0.14)\",\n      \"rgba(61, 107, 255, 0.04)\",\n    ],\n  },\n} as const;\n\nfunction advance(face: Face, ch: string) {\n  const code = ch.charCodeAt(0);\n  if (code >= 32 && code < 127) return face.adv[code - 32] / 1000;\n  return (face.punct[ch] ?? 620) / 1000;\n}\n\n/** Left edge (em) of every glyph in a run, with kerning and tracking. */\nfunction layoutRun(face: Face, chars: string[]) {\n  const xs: number[] = [];\n  let x = 0;\n  chars.forEach((ch, i) => {\n    if (i > 0) x += face.kern.get(chars[i - 1] + ch) ?? 0;\n    xs.push(x);\n    x += advance(face, ch) + face.track;\n  });\n  return { xs, total: Math.max(0, x - face.track) };\n}\n\n/** Line breaks at a measure, then narrowed until the lines balance. */\nfunction breakLines(words: string[][], measure: number) {\n  const space = advance(BODY, \" \") + BODY.track;\n  const widths = words.map((w) => layoutRun(BODY, w).total);\n  const wrap = (max: number) => {\n    const lines: number[][] = [];\n    let line: number[] = [];\n    let width = 0;\n    widths.forEach((w, i) => {\n      const next = line.length ? width + space + w : w;\n      if (line.length && next > max) {\n        lines.push(line);\n        line = [i];\n        width = w;\n      } else {\n        line.push(i);\n        width = next;\n      }\n    });\n    if (line.length) lines.push(line);\n    return lines;\n  };\n  const count = wrap(measure).length;\n  let lo = Math.max(...widths, 0);\n  let hi = measure;\n  for (let n = 0; n < 24; n++) {\n    const mid = (lo + hi) / 2;\n    if (wrap(mid).length > count) lo = mid;\n    else hi = mid;\n  }\n  return wrap(hi);\n}\n\n/** Pick the letters of `word` in order, spread as evenly as the sentence allows. */\nfunction findLetters(text: string[], word: string[]) {\n  const n = word.length;\n  const len = text.length;\n  if (!n) return [];\n  const cost = (j: number, i: number) => {\n    const a = text[i];\n    const b = word[j];\n    if (a.toLowerCase() !== b.toLowerCase()) return Number.POSITIVE_INFINITY;\n    const target = ((j + 0.5) / n) * len;\n    return Math.abs(i - target) + (a === b ? 0 : len * 0.25);\n  };\n  // best[j][i]: cheapest placement of letters 0..j with letter j at index i.\n  const best: number[][] = [];\n  const from: number[][] = [];\n  for (let j = 0; j < n; j++) {\n    best.push(new Array<number>(len).fill(Number.POSITIVE_INFINITY));\n    from.push(new Array<number>(len).fill(-1));\n    let run = Number.POSITIVE_INFINITY;\n    let runAt = -1;\n    for (let i = 0; i < len; i++) {\n      const c = cost(j, i);\n      if (j === 0) best[j][i] = c;\n      else if (runAt >= 0 && c < Number.POSITIVE_INFINITY) {\n        best[j][i] = run + c;\n        from[j][i] = runAt;\n      }\n      if (j > 0 && best[j - 1][i] < run) {\n        run = best[j - 1][i];\n        runAt = i;\n      }\n    }\n  }\n  let end = -1;\n  best[n - 1].forEach((v, i) => {\n    if (v < Number.POSITIVE_INFINITY && (end < 0 || v < best[n - 1][end]))\n      end = i;\n  });\n  if (end < 0) {\n    // Not every letter is in the sentence: match greedily, leave gaps as -1.\n    let at = 0;\n    return word.map((ch) => {\n      for (let i = at; i < len; i++)\n        if (text[i].toLowerCase() === ch.toLowerCase()) {\n          at = i + 1;\n          return i;\n        }\n      return -1;\n    });\n  }\n  const out = new Array<number>(n).fill(-1);\n  for (let j = n - 1, i = end; j >= 0; j--) {\n    out[j] = i;\n    i = from[j][i];\n  }\n  return out;\n}\n\nfunction Grain({ opacity }: { opacity: number }) {\n  const id = `g${useId().replace(/[^a-zA-Z0-9_-]/g, \"\")}`;\n  return (\n    <svg\n      width=\"100%\"\n      height=\"100%\"\n      style={{ position: \"absolute\", inset: 0, opacity, pointerEvents: \"none\" }}\n      aria-hidden\n    >\n      <filter id={id}>\n        <feTurbulence\n          type=\"fractalNoise\"\n          baseFrequency=\"0.9\"\n          numOctaves={2}\n          seed={17}\n          stitchTiles=\"stitch\"\n        />\n        <feColorMatrix values=\"0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0 0.5  0 0 0 0.9 0\" />\n      </filter>\n      <rect width=\"100%\" height=\"100%\" filter={`url(#${id})`} />\n    </svg>\n  );\n}\n\ninterface Glyph {\n  ch: string;\n  x: number;\n  line: number;\n}\n\nexport function HiddenWord({\n  text = \"Small teams make their launch film in code and post it by Friday.\",\n  word = \"ship\",\n  accent = \"#3B5BFD\",\n  theme = \"dark\",\n  speed = 1,\n}: HiddenWordProps) {\n  const t = useCurrentFrame() * speed;\n  const { width: W, height: H } = useVideoConfig();\n  const c = THEMES[theme];\n\n  const B = Math.min(H * 0.068, W * 0.038);\n  const set = useMemo(() => {\n    const chars = Array.from(text);\n    const words: string[][] = [];\n    const starts: number[] = [];\n    chars.forEach((ch, i) => {\n      if (ch === \" \") return;\n      if (i === 0 || chars[i - 1] === \" \") {\n        words.push([]);\n        starts.push(i);\n      }\n      words[words.length - 1].push(ch);\n    });\n    const lines = breakLines(words, (W * 0.66) / B);\n    const space = advance(BODY, \" \") + BODY.track;\n    const glyphs: (Glyph | null)[] = chars.map(() => null);\n    let blockWidth = 0;\n    lines.forEach((line, l) => {\n      let x = 0;\n      line.forEach((wi, k) => {\n        if (k > 0) x += space;\n        const run = layoutRun(BODY, words[wi]);\n        run.xs.forEach((gx, g) => {\n          glyphs[starts[wi] + g] = { ch: words[wi][g], x: x + gx, line: l };\n        });\n        x += run.total;\n      });\n      blockWidth = Math.max(blockWidth, x);\n    });\n    return { chars, glyphs, lines: lines.length, blockWidth };\n  }, [text, W, B]);\n\n  const target = useMemo(() => Array.from(word), [word]);\n  const picks = useMemo(\n    () => findLetters(set.chars, target),\n    [set.chars, target],\n  );\n  const display = useMemo(() => layoutRun(DISPLAY, target), [target]);\n\n  // Opening layout: the sentence block centred in frame.\n  const lineGap = B * LEADING;\n  const blockLeft = W / 2 - (set.blockWidth * B) / 2;\n  const firstBase =\n    H / 2 - ((set.lines - 1) * lineGap) / 2 + (CAP * B) / 2 - B * 0.04;\n  const blockTop = firstBase - CAP * B;\n  const blockBottom = firstBase + (set.lines - 1) * lineGap + DESC * B;\n  const blockMid = (blockTop + blockBottom) / 2;\n\n  // Poster layout: the display word over the sentence, now a small caption.\n  const F = Math.min(H * 0.42, (W * 0.6) / Math.max(0.1, display.total));\n  const ghostH = (blockBottom - blockTop) * GHOST_SCALE;\n  const gap = H * 0.085;\n  // The found word is lowercase: centre it on its x-height, not the caps.\n  const topE = (CAP + SERIF_X) / 2;\n  const groupH = topE * F + DESC * F + gap + ghostH;\n  const displayBase = H * 0.5 - groupH / 2 + topE * F;\n  const ghostMid = displayBase + DESC * F + gap + ghostH / 2;\n  const displayLeft = W / 2 - (display.total * F) / 2;\n\n  const move = interpolate(t, [MOVE_AT, MOVE_AT + MOVE], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const scale = 1 + (GHOST_SCALE - 1) * move;\n  const midY = blockMid + (ghostMid - blockMid) * move;\n  const place = (x: number, y: number) => ({\n    x: W / 2 + (x - W / 2) * scale,\n    y: midY + (y - blockMid) * scale,\n  });\n\n  const picked = new Map<number, number>();\n  picks.forEach((i, j) => {\n    if (i >= 0) picked.set(i, j);\n  });\n  const lastLand =\n    LIFT_AT + Math.max(0, target.length - 1) * LIFT_STAGGER + FLIGHT;\n  const settle = interpolate(\n    t,\n    [lastLand + SETTLE_GAP, lastLand + SETTLE_GAP + SETTLE],\n    [0, 1],\n    { ...CLAMP, easing: EASE_IO },\n  );\n  const dim = interpolate(t, [DIM_AT, DIM_AT + DIM], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const restColor = interpolateColors(\n    move,\n    [0, 1],\n    [interpolateColors(dim, [0, 1], [c.fg, c.dim]), c.ghost],\n  );\n\n  const sentence: ReactNode[] = [];\n  const marks: ReactNode[] = [];\n  const flyers: ReactNode[] = [];\n\n  set.glyphs.forEach((g, i) => {\n    if (!g) return;\n    const enter = interpolate(\n      t,\n      [g.line * LINE_STAGGER, g.line * LINE_STAGGER + ENTER],\n      [0, 1],\n      { ...CLAMP, easing: EASE_OUT },\n    );\n    const homeX = blockLeft + g.x * B;\n    const homeY = firstBase + g.line * lineGap + (1 - enter) * B * 0.45;\n    const j = picked.get(i);\n    const size = B * scale;\n    if (j === undefined) {\n      const p = place(homeX, homeY);\n      sentence.push(\n        <span\n          key={i}\n          style={{\n            position: \"absolute\",\n            left: p.x,\n            top: p.y - baseOf(BODY) * size,\n            fontSize: size,\n            color: restColor,\n            opacity: enter,\n          }}\n        >\n          {g.ch}\n        </span>,\n      );\n      return;\n    }\n\n    const lit = interpolate(\n      t,\n      [LIGHT_AT + j * LIGHT_STAGGER, LIGHT_AT + j * LIGHT_STAGGER + LIGHT],\n      [0, 1],\n      { ...CLAMP, easing: EASE_OUT },\n    );\n    const liftAt = LIFT_AT + j * LIFT_STAGGER;\n    const p = interpolate(t, [liftAt, liftAt + FLIGHT], [0, 1], {\n      ...CLAMP,\n      easing: EASE_IO,\n    });\n\n    // The empty slot the letter leaves behind gets a short accent rule.\n    const hole = interpolate(p, [0.15, 0.55], [0, 1], CLAMP);\n    if (hole > 0) {\n      const w = advance(BODY, g.ch) * size;\n      const at = place(homeX, firstBase + g.line * lineGap);\n      marks.push(\n        <div\n          key={`m${i}`}\n          style={{\n            position: \"absolute\",\n            left: at.x + w * 0.12,\n            top: at.y + size * 0.16,\n            width: w * 0.76,\n            height: Math.max(2, size * 0.07),\n            background: accent,\n            opacity: hole,\n            transform: `scaleX(${0.4 + 0.6 * hole})`,\n          }}\n        />,\n      );\n    }\n\n    const from = place(homeX + (advance(BODY, g.ch) * B) / 2, homeY);\n    const toCh = target[j];\n    const to = {\n      x: displayLeft + (display.xs[j] + advance(DISPLAY, toCh) / 2) * F,\n      y: displayBase,\n    };\n    // Lift straight up out of the line, cross over, rise into the slot from below.\n    const c1y = from.y - (g.line + 1.6) * lineGap * scale;\n    const c2y = to.y + F * 0.55;\n    const u = 1 - p;\n    const x =\n      (u * u * u + 3 * u * u * p) * from.x + (3 * u * p * p + p * p * p) * to.x;\n    const y =\n      u * u * u * from.y +\n      3 * u * u * p * c1y +\n      3 * u * p * p * c2y +\n      p * p * p * to.y;\n    const fontSize = size * (F / size) ** p;\n    const mix = interpolate(p, [0.15, 0.55], [0, 1], CLAMP);\n    const color = interpolateColors(\n      settle,\n      [0, 1],\n      [interpolateColors(lit, [0, 1], [restColor, accent]), c.fg],\n    );\n    const layer = (key: string, ch: string, face: Face, o: number) =>\n      o > 0 ? (\n        <span\n          key={key}\n          style={{\n            position: \"absolute\",\n            left: x - (advance(face, ch) * fontSize) / 2,\n            top: y - baseOf(face) * fontSize,\n            fontSize,\n            fontFamily: face === DISPLAY ? serif : sans,\n            fontStyle: face === DISPLAY ? \"italic\" : \"normal\",\n            letterSpacing: 0,\n            color,\n            opacity: o * enter,\n          }}\n        >\n          {ch}\n        </span>\n      ) : null;\n    flyers.push(layer(`a${i}`, g.ch, BODY, 1 - mix));\n    flyers.push(layer(`b${i}`, toCh, DISPLAY, mix));\n  });\n\n  // Letters of the word that the sentence does not contain arrive on their own.\n  target.forEach((ch, j) => {\n    if (picks[j] >= 0) return;\n    const at = LIFT_AT + j * LIFT_STAGGER + FLIGHT * 0.5;\n    const v = interpolate(t, [at, at + FLIGHT * 0.5], [0, 1], {\n      ...CLAMP,\n      easing: EASE_OUT,\n    });\n    if (v <= 0) return;\n    flyers.push(\n      <span\n        key={`n${j}`}\n        style={{\n          position: \"absolute\",\n          left: displayLeft + display.xs[j] * F,\n          top: displayBase - baseOf(DISPLAY) * F + (1 - v) * F * 0.12,\n          fontSize: F,\n          fontFamily: serif,\n          fontStyle: \"italic\",\n          color: interpolateColors(settle, [0, 1], [accent, c.fg]),\n          opacity: v,\n        }}\n      >\n        {ch}\n      </span>,\n    );\n  });\n\n  // The bloom drifts a few percent left and up over the shot.\n  const drift = interpolate(t, [0, lastLand + SETTLE_GAP + SETTLE], [0, 1], {\n    ...CLAMP,\n    easing: EASE_IO,\n  });\n  const ground = `radial-gradient(118% 76% at ${(72 - 8 * drift).toFixed(2)}% ${(104 - 4 * drift).toFixed(2)}%, ${c.mist[0]} 0%, ${c.mist[1]} 22%, ${c.mist[2]} 48%, ${c.mist[3]} 72%, transparent 100%)`;\n\n  return (\n    <AbsoluteFill style={{ background: c.bg, overflow: \"hidden\" }}>\n      <div style={{ position: \"absolute\", inset: 0, background: ground }} />\n      <div\n        style={{\n          position: \"absolute\",\n          inset: 0,\n          fontFamily: sans,\n          fontWeight: 400,\n          lineHeight: LINE,\n          fontKerning: \"none\",\n          whiteSpace: \"pre\",\n        }}\n      >\n        {sentence}\n        {marks}\n        {flyers}\n      </div>\n      <Grain opacity={c.grain} />\n    </AbsoluteFill>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/remocn/hidden-word.tsx"
    }
  ],
  "type": "registry:component"
}
