{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"squish-letter-heading","type":"registry:component","title":"Squish Letter Heading","description":"A heading whose letters squash under the pointer and push their neighbours up: each letter keeps its area as it squashes, springs back with one overshoot, and the line ripples behind the pointer before settling to crisp type.","dependencies":[],"registryDependencies":[],"files":[{"path":"components/viberdy/squish-letter-heading.tsx","content":"\"use client\";\n\nimport { Fragment, useEffect, useRef, useSyncExternalStore } from \"react\";\nimport type { CSSProperties, PointerEvent as ReactPointerEvent } from \"react\";\n\n/**\n * SquishLetterHeading — a heading whose letters squash under the pointer.\n *\n * The letter under the pointer squashes onto the baseline, growing as wide\n * as it grows short, while its neighbours bulge up with what it lost; quick\n * passes add a lean. Every letter has its own spring, so the line ripples\n * behind the pointer and settles back to crisp type. DOM only.\n *\n * Part of the Tactile Maximalism kit: dough #f7f0e4, warm ink #17130f and\n * one loud accent, bubblegum #ff2d78, filled once per screen; grain fixed to\n * the material; soft shadows tinted by what casts them, never a hard offset.\n * Everything soft keeps its area as it squashes and settles inside 450ms.\n * Unbounded through var(--font-unbounded) for display over Geist. Respects\n * prefers-reduced-motion. No dependencies beyond React. Paste it as its own\n * file: it repeats the kit's small helpers, which would clash in one module.\n * Load Unbounded with next/font (variable: \"--font-unbounded\") on a\n * parent, or from Google Fonts or @fontsource.\n * Needs Tailwind v4 (on v3.4, add the @tailwindcss/container-queries plugin).\n */\n\nconst DISPLAY = 'var(--font-unbounded, \"Unbounded\", var(--font-sans, \"Geist\"), ui-sans-serif, system-ui, sans-serif)';\n\n/** Dough, warm ink, and one loud accent. */\nconst DOUGH = {\n  ground: \"#f7f0e4\",\n  surface: \"#fffaf1\",\n  well: \"#efe5d3\",\n  solid: \"#17130f\",\n  ink: \"rgba(23,19,15,0.92)\",\n  ink2: \"rgba(23,19,15,0.64)\",\n  ink3: \"rgba(23,19,15,0.42)\",\n  line: \"rgba(23,19,15,0.1)\",\n  line2: \"rgba(23,19,15,0.18)\",\n  gum: \"#ff2d78\",\n  gumDeep: \"#d8155d\",\n  lilac: \"#e8e1f6\",\n} as const;\n\nfunction clamp(v: number, lo: number, hi: number): number {\n  return v < lo ? lo : v > hi ? hi : v;\n}\n\nfunction subscribeMotion(cb: () => void) {\n  const m = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n  m.addEventListener(\"change\", cb);\n  return () => m.removeEventListener(\"change\", cb);\n}\n\n/** True when the visitor asked for reduced motion. False on the server. */\nfunction useReducedMotion(): boolean {\n  return useSyncExternalStore(\n    subscribeMotion,\n    () => window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches,\n    () => false,\n  );\n}\n\n/**\n * SquishLetterHeading — a heading whose letters squash under the pointer and\n * push their neighbours up.\n *\n * Run the pointer along the line and the letter under it squashes onto the\n * baseline, growing as wide as it grows short, while the letters on either\n * side bulge up a little with what it lost; quick passes add a sideways lean.\n * Every letter is on its own spring (one overshoot, settled inside 450ms), so\n * the line ripples behind the pointer and settles back to crisp type. One\n * word can sit in bubblegum. DOM only: the text stays real, selectable text.\n */\nexport function SquishLetterHeading({\n  text = \"Everything you drop, one page.\",\n  accent = \"drop,\",\n  as: Tag = \"h2\",\n  size = \"clamp(34px, 7.4cqw, 96px)\",\n  className = \"\",\n  style,\n}: {\n  text?: string;\n  /** A word (exactly as written) set in bubblegum. */\n  accent?: string;\n  as?: \"h1\" | \"h2\" | \"h3\" | \"p\";\n  size?: string;\n  className?: string;\n  style?: CSSProperties;\n}) {\n  const spans = useRef<(HTMLSpanElement | null)[]>([]);\n  const reduced = useReducedMotion();\n  const sim = useRef({ y: new Float32Array(0), v: new Float32Array(0), t: new Float32Array(0), sk: new Float32Array(0), skv: new Float32Array(0), raf: 0, last: 0, px: -1e4, vx: 0, lastX: 0, lastT: 0 });\n  const tickRef = useRef<(now: number) => void>(() => undefined);\n  const words = text.split(\" \").filter(Boolean);\n  const lengths = words.map((w) => [...w].length);\n  const count = lengths.reduce((a, b) => a + b, 0);\n  const starts = lengths.map((_, wi) => lengths.slice(0, wi).reduce((a, b) => a + b, 0));\n\n  useEffect(() => {\n    const st = sim.current;\n    st.y = new Float32Array(count).fill(1);\n    st.v = new Float32Array(count);\n    st.t = new Float32Array(count).fill(1);\n    st.sk = new Float32Array(count);\n    st.skv = new Float32Array(count);\n    tickRef.current = (now: number) => {\n      st.raf = 0;\n      const dt = st.last ? Math.min(1 / 30, (now - st.last) / 1000) : 1 / 60;\n      st.last = now;\n      let moving = false;\n      for (let i = 0; i < count; i++) {\n        for (let k = 0; k < 2; k++) {\n          const h = dt / 2;\n          st.v[i] += (420 * (st.t[i] - st.y[i]) - 18 * st.v[i]) * h;\n          st.y[i] += st.v[i] * h;\n          st.skv[i] += (-380 * st.sk[i] - 20 * st.skv[i]) * h;\n          st.sk[i] += st.skv[i] * h;\n        }\n        const el = spans.current[i];\n        if (el) el.style.transform = `scale(${(1 / st.y[i]).toFixed(4)}, ${st.y[i].toFixed(4)}) skewX(${st.sk[i].toFixed(2)}deg)`;\n        if (Math.abs(st.v[i]) > 0.003 || Math.abs(st.t[i] - st.y[i]) > 0.002 || Math.abs(st.sk[i]) > 0.03 || Math.abs(st.skv[i]) > 0.1) moving = true;\n      }\n      if (moving) st.raf = requestAnimationFrame((n) => tickRef.current(n));\n      else {\n        st.last = 0;\n        // Settled: clear the transforms only if every letter is at rest; a held squash stays squashed.\n        if (st.t.every((t) => t === 1)) {\n          spans.current.forEach((el) => {\n            if (el) el.style.transform = \"\";\n          });\n        }\n      }\n    };\n    return () => {\n      cancelAnimationFrame(st.raf);\n      st.raf = 0;\n      st.last = 0;\n    };\n  }, [count]);\n\n  const kick = () => {\n    const st = sim.current;\n    if (!st.raf) st.raf = requestAnimationFrame((n) => tickRef.current(n));\n  };\n  // Aim every letter from the pointer: the one under it squashes, its neighbours take up the volume.\n  const aim = (x: number, y: number, speed: number) => {\n    const st = sim.current;\n    for (let i = 0; i < count; i++) {\n      const el = spans.current[i];\n      if (!el) continue;\n      const r = el.getBoundingClientRect();\n      const inRow = y >= r.top - r.height * 0.1 && y <= r.bottom + r.height * 0.1;\n      const d = inRow ? Math.abs(x - (r.left + r.width / 2)) / Math.max(1, r.width) : 99;\n      st.t[i] = d < 0.6 ? 0.8 : d < 1.6 ? 1 + 0.07 * (1.6 - d) : 1;\n      if (d < 1) st.skv[i] += clamp(speed, -2, 2) * 40 * (1 - d);\n    }\n    kick();\n  };\n  const onMove = (e: ReactPointerEvent<HTMLElement>) => {\n    if (reduced) return;\n    const st = sim.current;\n    const now = performance.now();\n    const speed = st.lastT ? (e.clientX - st.lastX) / Math.max(8, now - st.lastT) : 0;\n    st.lastX = e.clientX;\n    st.lastT = now;\n    aim(e.clientX, e.clientY, speed);\n  };\n  const onLeave = () => {\n    const st = sim.current;\n    st.t.fill(1);\n    st.lastT = 0;\n    kick();\n  };\n\n  return (\n    <Tag\n      onPointerMove={onMove}\n      onPointerLeave={onLeave}\n      className={\"tm-scope m-0 w-full @container \" + className}\n      style={{ fontFamily: DISPLAY, fontWeight: 800, fontSize: size, lineHeight: 1, letterSpacing: \"-0.04em\", color: DOUGH.solid, ...style }}\n    >\n      <span className=\"sr-only\">{text}</span>\n      <span aria-hidden>\n      {words.map((w, wi) => (\n        <Fragment key={wi}>\n        <span className=\"inline-block whitespace-nowrap\" style={{ color: w === accent ? DOUGH.gum : undefined }}>\n          {[...w].map((ch, ci) => {\n            const i = starts[wi] + ci;\n            return (\n              <span key={ci} ref={(el) => void (spans.current[i] = el)} className=\"inline-block\" style={{ transformOrigin: \"50% 88%\", willChange: \"transform\", transition: \"none\" }}>\n                {ch}\n              </span>\n            );\n          })}\n        </span>\n        {/* The space sits between the words: inside an inline-block it would collapse. */}\n        {wi < words.length - 1 ? \" \" : null}\n        </Fragment>\n      ))}\n      </span>\n    </Tag>\n  );\n}\n","type":"registry:component","target":"components/viberdy/squish-letter-heading.tsx"}],"meta":{"tier":"free","tags":["text effect","heading","hover","squash and stretch","spring","letters"],"href":"https://viberdy.dev/library/squish-letter-heading","aiPrompt":"Build a React + Tailwind text effect, `SquishLetterHeading({ text, accent, as, size, className, style })`.\n\nTactile Maximalism grammar: loud but composed. A dough ground #f7f0e4 over most of the page (surfaces #fffaf1, a pressed well #efe5d3), warm ink #17130f at 92/64/42%, hairlines at 10% and 18%; ONE loud accent, bubblegum #ff2d78 (deep #d8155d), as a filled thing once per screen, and one quiet tint, lavender #e8e1f6, only on small chips, never a second loud colour. Grain at 4-6%, monochrome, static, fixed to the material. Depth is soft and tinted: a contact shadow 0 2px 6px rgba(23,19,15,0.1) plus a wide one 0 18px 40px -8px tinted by what casts it (a gum chip casts pink); pressed, both collapse to 0 1px 3px rgba(23,19,15,0.14). Never a hard offset shadow (that is neo-brutalism). Type: Unbounded at 800 through var(--font-unbounded, \"Unbounded\", ...) for one oversized headline per screen (up to ~15cqw, leading 0.92, tracking -0.045em), Geist for reading at 16-17px/1.5, Geist Mono uppercase at 11-12px for labels. Full pills for every control and chip, 28px cards, 20px nested media. Motion: everything soft keeps its area as it squashes (scaleX = 1 / scaleY about its foot), deforms in proportion to the input (where, how long, how fast), overshoots once and settles inside 450ms (a spring near k 420, c 18), and always returns to one legible rest shape. Reduced motion keeps the states and drops the springs.\n\nThe heading holds a screen-reader copy of the text and an aria-hidden copy split into letter spans (inline-block, grouped per word so lines break between words; the accent word in #ff2d78), set in Unbounded 800 at clamp(34px, 7.4cqw, 96px), leading 1, tracking -0.04em. Each letter has a height factor y on a spring (k 420, c 18) and a skew on its own spring (k 380, c 20), written as scale(1/y, y) skewX(skew) about 50% 88%. On pointer move, for each letter on the pointer's line: d = |x - its centre| / its width; target 0.8 if d < 0.6, else 1 + 0.07 (1.6 - d) up to d 1.6 (the neighbours bulge), else 1; letters within one width get a skew kick from the pointer's horizontal speed. Leave: all targets back to 1. One rAF loop, asleep when settled; reduced motion does nothing.","license":"https://viberdy.dev/license"}}