{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"silver-foil-balloon-letters-on-strings-that-bob-bump-and-mirror-the-studio","type":"registry:component","title":"Silver Foil Balloon Letters on Strings That Bob, Bump and Mirror the Studio","description":"WebGL text effect: a word as foil balloons on strings that bob, bump each other and mirror a studio softbox near the pointer. Free React and HTML code.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/silver-foil-balloon-letters-on-strings-that-bob-bump-and-mirror-the-studio.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport type { PointerEvent as ReactPointerEvent } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n/** The word, one balloon per letter. Four to seven capitals sit best. */\nconst WORD = \"HELLO\";\n/** The paper sweep behind the balloons. The foil picks this colour up on its underside. */\nconst WALL = \"#f2a9b8\";\n/** How far a balloon stands off the wall, in share of its own size. Larger throws a longer, softer shadow. */\nconst STANDOFF = 0.16;\n\nconst CELL = 256;\n\nconst VERT = `attribute vec2 a;\nuniform vec2 u_res;\nuniform vec2 u_at;\nuniform vec2 u_size;\nuniform float u_turn;\nvarying vec2 v_uv;\nvoid main(){\n  vec2 p = a * 0.5 * u_size;\n  float c = cos(u_turn), s = sin(u_turn);\n  p = vec2(p.x * c - p.y * s, p.x * s + p.y * c) + u_at;\n  v_uv = a * 0.5 + 0.5;\n  gl_Position = vec4(p.x / u_res.x * 2.0 - 1.0, 1.0 - p.y / u_res.y * 2.0, 0.0, 1.0);\n}`;\n\nconst FRAG = `precision highp float;\nconst float CELL = 256.0;\nvarying vec2 v_uv;\nuniform sampler2D u_tex;\nuniform sampler2D u_soft;\nuniform float u_cell;\nuniform float u_cells;\nuniform float u_turn;\nuniform vec2 u_tilt;\nuniform vec2 u_lamp;\nuniform vec3 u_wall;\nuniform float u_shadow;\n\n// The room the foil mirrors, by the direction a ray leaves the surface (y is up here).\nvec3 room(vec3 r){\n  float up = r.y;\n  vec3 floorNear = u_wall * 1.08 + 0.06;\n  vec3 floorFar = u_wall * 0.5;\n  vec3 mid = mix(vec3(0.80, 0.79, 0.84), u_wall, 0.18);\n  vec3 dark = vec3(0.17, 0.13, 0.19);\n  vec3 ceiling = vec3(0.50, 0.49, 0.54);\n  vec3 col = mix(floorFar, floorNear, smoothstep(-0.95, -0.28, up));\n  col = mix(col, mix(mid, vec3(0.93, 0.93, 0.96), smoothstep(-0.2, 0.1, up)), smoothstep(-0.3, -0.08, up));\n  col = mix(col, dark, smoothstep(0.08, 0.2, up));\n  col = mix(col, ceiling, smoothstep(0.62, 0.9, up));\n  // The big softbox overhead. It slides with the lamp.\n  float box = smoothstep(0.26, 0.34, up) * (1.0 - smoothstep(0.66, 0.78, up));\n  box *= 1.0 - smoothstep(0.62, 0.78, abs(r.x - u_lamp.x * 0.55));\n  col = mix(col, vec3(1.0, 0.99, 0.97), box);\n  // Two tall strip lights at the sides, cut by a black flag.\n  float strip = (1.0 - smoothstep(0.035, 0.07, abs(abs(r.x + u_lamp.x * 0.2) - 0.74))) * smoothstep(-0.5, -0.2, up) * (1.0 - smoothstep(0.5, 0.7, up));\n  col = mix(col, vec3(1.0), strip * 0.9);\n  float flag = (1.0 - smoothstep(0.03, 0.09, abs(abs(r.x) - 0.9))) * (1.0 - smoothstep(0.2, 0.6, abs(up)));\n  col = mix(col, dark, flag * 0.7);\n  return col;\n}\n\nvec2 facing(vec2 texel){\n  vec4 p = texture2D(u_tex, vec2((texel.x / CELL + u_cell) / u_cells, texel.y / CELL)) * 255.0;\n  return vec2(p.r * 256.0 + p.g, p.b * 256.0 + p.a) / 32767.5 - 1.0;\n}\n\nvoid main(){\n  vec2 uv = vec2((v_uv.x + u_cell) / u_cells, v_uv.y);\n  // t: r is height, g is the outline, b is the soft shadow, a is the shade in the crease.\n  vec4 t = texture2D(u_soft, uv);\n  if (u_shadow > 0.5) {\n    float s = t.b * 0.36;\n    gl_FragColor = vec4(u_wall * 0.2 * s, s);\n    return;\n  }\n  if (t.g < 0.004) discard;\n  // The facing direction is stored at 16 bits a side, so it is blended by hand between the four nearest texels.\n  vec2 px = clamp(v_uv * CELL - 0.5, 0.0, CELL - 1.001);\n  vec2 f = fract(px);\n  vec2 i = floor(px) + 0.5;\n  vec2 nxy = mix(mix(facing(i), facing(i + vec2(1.0, 0.0)), f.x), mix(facing(i + vec2(0.0, 1.0)), facing(i + vec2(1.0, 1.0)), f.x), f.y);\n  float c = cos(u_turn), s = sin(u_turn);\n  nxy = vec2(nxy.x * c - nxy.y * s, nxy.x * s + nxy.y * c);\n  // Screen y runs downward, the room's y runs upward.\n  vec3 n = normalize(vec3(nxy.x + u_tilt.x, -(nxy.y + u_tilt.y), sqrt(max(1.0 - dot(nxy, nxy), 0.02))));\n  vec3 r = reflect(vec3(0.0, 0.0, -1.0), n);\n  vec3 col = room(r);\n  // Foil is brighter at glancing angles and never quite a perfect mirror.\n  col = mix(col, vec3(1.0), pow(1.0 - n.z, 3.0) * 0.28);\n  vec3 lamp = normalize(vec3(u_lamp.x * 0.7, 0.62 + u_lamp.y * 0.3, 0.75));\n  float hot = pow(max(dot(n, normalize(lamp + vec3(0.0, 0.0, 1.0))), 0.0), 260.0);\n  col += vec3(1.0) * hot * 1.4;\n  // The crease where the pillow meets its flat welded seam sits in shade.\n  col *= t.a;\n  gl_FragColor = vec4(col * t.g, t.g);\n}`;\n\n/** Three passes of a box blur, which is close to a true soft blur and cheap. */\nfunction soften(src: Float32Array, radius: number) {\n  const n = CELL;\n  const a = Float32Array.from(src);\n  const b = new Float32Array(n * n);\n  const span = radius * 2 + 1;\n  for (let pass = 0; pass < 3; pass++) {\n    for (let y = 0; y < n; y++) {\n      let sum = 0;\n      for (let x = -radius; x <= radius; x++) sum += a[y * n + Math.min(n - 1, Math.max(0, x))];\n      for (let x = 0; x < n; x++) {\n        b[y * n + x] = sum / span;\n        sum += a[y * n + Math.min(n - 1, x + radius + 1)] - a[y * n + Math.max(0, x - radius)];\n      }\n    }\n    for (let x = 0; x < n; x++) {\n      let sum = 0;\n      for (let y = -radius; y <= radius; y++) sum += b[Math.min(n - 1, Math.max(0, y)) * n + x];\n      for (let y = 0; y < n; y++) {\n        a[y * n + x] = sum / span;\n        sum += b[Math.min(n - 1, y + radius + 1) * n + x] - b[Math.max(0, y - radius) * n + x];\n      }\n    }\n  }\n  return a;\n}\n\nfunction grain(x: number, y: number) {\n  const xi = Math.floor(x);\n  const yi = Math.floor(y);\n  const h = (i: number, j: number) => {\n    const s = Math.sin(i * 127.1 + j * 311.7) * 43758.5453;\n    return s - Math.floor(s);\n  };\n  const fx = x - xi;\n  const fy = y - yi;\n  const u = fx * fx * (3 - 2 * fx);\n  const v = fy * fy * (3 - 2 * fy);\n  return (h(xi, yi) * (1 - u) + h(xi + 1, yi) * u) * (1 - v) + (h(xi, yi + 1) * (1 - u) + h(xi + 1, yi + 1) * u) * v;\n}\n\n/** Inflate one letter: returns its surface (which way each point faces, how high it stands, its outline), its soft shadow and its width. */\nfunction inflate(letter: string, seed: number) {\n  const n = CELL;\n  const cv = document.createElement(\"canvas\");\n  cv.width = n;\n  cv.height = n;\n  const c = cv.getContext(\"2d\", { willReadFrequently: true })!;\n  let px = 196;\n  const face = (size: number) => `900 ${size}px \"Arial Black\", \"Segoe UI Black\", \"Helvetica Neue\", Impact, sans-serif`;\n  c.font = face(px);\n  const first = c.measureText(letter);\n  if (first.width > 164) px *= 164 / first.width;\n  c.font = face(px);\n  const m = c.measureText(letter);\n  const rise = m.actualBoundingBoxAscent || px * 0.72;\n  const drop = m.actualBoundingBoxDescent || 0;\n  c.textAlign = \"center\";\n  c.lineJoin = \"round\";\n  c.lineWidth = 15;\n  c.fillStyle = \"#fff\";\n  c.strokeStyle = \"#fff\";\n  c.strokeText(letter, n / 2, n / 2 + (rise - drop) / 2);\n  c.fillText(letter, n / 2, n / 2 + (rise - drop) / 2);\n  const raw = c.getImageData(0, 0, n, n).data;\n  const mask = new Float32Array(n * n);\n  for (let i = 0; i < n * n; i++) mask[i] = raw[i * 4 + 3] / 255;\n\n  const tight = soften(mask, 6);\n  const wide = soften(mask, 15);\n  const broad = soften(mask, 30);\n  const round = (v: number) => Math.sqrt(Math.max(0, 1 - (1 - v) * (1 - v)));\n  const height = new Float32Array(n * n);\n  for (let y = 1; y < n - 1; y++) {\n    for (let x = 1; x < n - 1; x++) {\n      const i = y * n + x;\n      const body = Math.min(1, Math.max(0, (tight[i] - 0.5) / 0.46));\n      const pillow = Math.min(1, Math.max(0, (wide[i] - 0.5) / 0.4));\n      let h = 0.3 * round(body) + 0.48 * round(pillow) + 0.22 * Math.min(1, broad[i] * 1.5) * body;\n      // Creases run in from the welded seam, across the way the surface slopes.\n      const gx = wide[i + 1] - wide[i - 1];\n      const gy = wide[i + n] - wide[i - n];\n      const gl = Math.hypot(gx, gy) + 1e-5;\n      const along = (x * -gy + y * gx) / gl;\n      const seam = Math.exp(-Math.pow((tight[i] - 0.5) / 0.2, 2));\n      const flank = tight[i] > 0.5 ? (1 - h) * (1 - h) : 0;\n      const ripple = Math.sin(along * 0.3 + grain(x * 0.035 + seed, y * 0.035) * 9) * (0.35 + 0.65 * grain(x * 0.07, y * 0.07 + seed));\n      h += ripple * (0.009 * seam + 0.034 * flank);\n      // Big, slow dents so no two balloons catch the light alike.\n      h += (grain(x * 0.018 + seed * 3, y * 0.018) - 0.5) * 0.12 * body;\n      height[i] = h;\n    }\n  }\n  const smooth = soften(height, 1);\n  const surface = new Uint8Array(n * n * 4).fill(128);\n  const extra = new Uint8Array(n * n * 4);\n  const DEPTH = 30;\n  for (let y = 1; y < n - 1; y++) {\n    for (let x = 1; x < n - 1; x++) {\n      const i = y * n + x;\n      const dx = (smooth[i + 1] - smooth[i - 1]) * 0.5 * DEPTH;\n      const dy = (smooth[i + n] - smooth[i - n]) * 0.5 * DEPTH;\n      const len = Math.hypot(dx, dy, 1);\n      // Sixteen bits for each of the two slopes. Eight would show as rings in a mirror finish.\n      const fx = Math.round(((-dx / len) * 0.5 + 0.5) * 65535);\n      const fy = Math.round(((-dy / len) * 0.5 + 0.5) * 65535);\n      surface[i * 4] = fx >> 8;\n      surface[i * 4 + 1] = fx & 255;\n      surface[i * 4 + 2] = fy >> 8;\n      surface[i * 4 + 3] = fy & 255;\n      extra[i * 4] = Math.round(Math.min(1, Math.max(0, smooth[i])) * 255);\n      // The outline reaches a little past the letter: that margin is the flat seam.\n      const edge = Math.min(1, Math.max(0, (tight[i] - 0.2) / 0.1));\n      extra[i * 4 + 1] = Math.round(edge * edge * (3 - 2 * edge) * 255);\n      // The crease where the pillow meets its seam sits in shade.\n      extra[i * 4 + 3] = Math.round((1 - 0.42 * Math.exp(-Math.pow((tight[i] - 0.53) / 0.06, 2))) * 255);\n    }\n  }\n  const shade = soften(mask, 11);\n  for (let i = 0; i < n * n; i++) extra[i * 4 + 2] = Math.round(Math.min(1, shade[i] * 1.15) * 255);\n  return { surface, extra, width: (m.width + 15) / n };\n}\n\nfunction rgb(hex: string) {\n  const v = parseInt(hex.slice(1), 16);\n  return [((v >> 16) & 255) / 255, ((v >> 8) & 255) / 255, (v & 255) / 255];\n}\n\ntype Body = { hx: number; hy: number; x: number; y: number; vx: number; vy: number; a: number; va: number; w: number; vw: number; size: number };\n\nexport default function SilverFoilBalloonLettersOnStringsThatBobBumpAndMirrorTheStudio() {\n  const reduce = useReducedMotion();\n  const stage = useRef<HTMLDivElement>(null);\n  const canvas = useRef<HTMLCanvasElement>(null);\n  const strings = useRef<SVGSVGElement>(null);\n  const pointer = useRef({ x: -999, y: -999, vx: 0, vy: 0, at: -1e6, poke: false });\n  const wave = useRef(0);\n  const [live, setLive] = useState(false);\n  const letters = [...WORD];\n\n  useEffect(() => {\n    const el = stage.current;\n    const cv = canvas.current;\n    const svg = strings.current;\n    if (!el || !cv || !svg) return;\n    const gl = cv.getContext(\"webgl\", { antialias: true, alpha: true, premultipliedAlpha: true });\n    if (!gl) return;\n    const compile = (type: number, source: string) => {\n      const shader = gl.createShader(type)!;\n      gl.shaderSource(shader, source);\n      gl.compileShader(shader);\n      return shader;\n    };\n    const program = gl.createProgram()!;\n    gl.attachShader(program, compile(gl.VERTEX_SHADER, VERT));\n    gl.attachShader(program, compile(gl.FRAGMENT_SHADER, FRAG));\n    gl.linkProgram(program);\n    if (!gl.getProgramParameter(program, gl.LINK_STATUS)) return;\n    gl.useProgram(program);\n    gl.bindBuffer(gl.ARRAY_BUFFER, gl.createBuffer());\n    gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([-1, -1, 1, -1, -1, 1, 1, 1]), gl.STATIC_DRAW);\n    const at = gl.getAttribLocation(program, \"a\");\n    gl.enableVertexAttribArray(at);\n    gl.vertexAttribPointer(at, 2, gl.FLOAT, false, 0, 0);\n    const u = (name: string) => gl.getUniformLocation(program, name);\n    const uni = { res: u(\"u_res\"), at: u(\"u_at\"), size: u(\"u_size\"), turn: u(\"u_turn\"), cell: u(\"u_cell\"), tilt: u(\"u_tilt\"), lamp: u(\"u_lamp\"), shadow: u(\"u_shadow\") };\n\n    // Every letter is inflated once and packed side by side into two textures.\n    const count = letters.length;\n    const baked = letters.map((ch, i) => inflate(ch, i * 7.3 + 1));\n    const atlas = new Uint8Array(CELL * count * CELL * 4);\n    const soft = new Uint8Array(CELL * count * CELL * 4);\n    baked.forEach((b, k) => {\n      for (let y = 0; y < CELL; y++) {\n        atlas.set(b.surface.subarray(y * CELL * 4, (y + 1) * CELL * 4), (y * CELL * count + k * CELL) * 4);\n        soft.set(b.extra.subarray(y * CELL * 4, (y + 1) * CELL * 4), (y * CELL * count + k * CELL) * 4);\n      }\n    });\n    const texture = (unit: number, filter: number, data: Uint8Array) => {\n      gl.activeTexture(gl.TEXTURE0 + unit);\n      gl.bindTexture(gl.TEXTURE_2D, gl.createTexture());\n      gl.pixelStorei(gl.UNPACK_ALIGNMENT, 1);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_S, gl.CLAMP_TO_EDGE);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_WRAP_T, gl.CLAMP_TO_EDGE);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, filter);\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, filter);\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, CELL * count, CELL, 0, gl.RGBA, gl.UNSIGNED_BYTE, data);\n    };\n    texture(0, gl.NEAREST, atlas);\n    texture(1, gl.LINEAR, soft);\n    gl.uniform1i(u(\"u_tex\"), 0);\n    gl.uniform1i(u(\"u_soft\"), 1);\n    gl.uniform1f(u(\"u_cells\"), count);\n    gl.uniform3fv(u(\"u_wall\"), rgb(WALL));\n    gl.enable(gl.BLEND);\n    gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA);\n\n    const bodies: Body[] = letters.map(() => ({ hx: 0, hy: 0, x: 0, y: 0, vx: 0, vy: 0, a: 0, va: 0, w: 0, vw: 0, size: 100 }));\n    const paths = Array.from(svg.querySelectorAll(\"path\"));\n    let W = 0;\n    let H = 0;\n    let ratio = 1;\n    let raf = 0;\n    let visible = true;\n    let last = 0;\n    let seenWave = wave.current;\n    let nextGust = 1.1;\n    const queue: { at: number; i: number; fx: number; fy: number }[] = [];\n    const started = performance.now();\n    const lamp = { x: 0.15, y: 0 };\n\n    const layout = () => {\n      W = el.clientWidth;\n      H = el.clientHeight;\n      if (!W || !H) return;\n      ratio = Math.min(window.devicePixelRatio || 1, 2);\n      cv.width = Math.round(W * ratio);\n      cv.height = Math.round(H * ratio);\n      gl.viewport(0, 0, cv.width, cv.height);\n      svg.setAttribute(\"viewBox\", `0 0 ${W} ${H}`);\n      const total = baked.reduce((sum, b) => sum + b.width, 0);\n      // Balloons crowd each other a little, the way a bunch does.\n      const size = Math.min((W * 0.9) / (total * 0.93), H * 0.52, 300);\n      let x = (W - total * 0.93 * size) / 2;\n      bodies.forEach((b, i) => {\n        const w = baked[i].width * 0.93 * size;\n        b.size = size;\n        b.hx = x + w / 2;\n        b.hy = H * 0.43 + (i % 2 ? 1 : -1) * size * 0.035;\n        x += w;\n      });\n    };\n\n    const kick = (i: number, fx: number, fy: number) => {\n      const b = bodies[i];\n      if (!b) return;\n      b.vx += fx;\n      b.vy += fy;\n      b.va += (fx * 0.004 + (i % 2 ? 0.4 : -0.4)) * Math.min(1, Math.hypot(fx, fy) / 300);\n      b.vw += Math.hypot(fx, fy) * 0.006;\n    };\n\n    const draw = (t: number) => {\n      gl.clearColor(0, 0, 0, 0);\n      gl.clear(gl.COLOR_BUFFER_BIT);\n      gl.uniform2f(uni.res, cv.width, cv.height);\n      gl.uniform2f(uni.lamp, lamp.x, lamp.y);\n      for (let pass = 0; pass < 2; pass++) {\n        gl.uniform1f(uni.shadow, pass === 0 ? 1 : 0);\n        bodies.forEach((b, i) => {\n          const s = b.size * ratio;\n          const lift = STANDOFF * (1 + b.y / (b.size * 0.6));\n          const dx = pass === 0 ? s * lift * 0.55 : 0;\n          const dy = pass === 0 ? s * lift * 0.95 : 0;\n          const grow = pass === 0 ? 1.1 : 1;\n          gl.uniform2f(uni.at, (b.hx + b.x) * ratio + dx, (b.hy + b.y) * ratio + dy);\n          gl.uniform2f(uni.size, s * (1 + b.w) * grow, s * (1 - b.w) * grow);\n          gl.uniform1f(uni.turn, b.a);\n          gl.uniform1f(uni.cell, i);\n          gl.uniform2f(uni.tilt, b.vx * 0.0007 + Math.sin(t * 0.7 + i * 1.9) * 0.05, b.vy * 0.0007 + Math.cos(t * 0.55 + i * 1.3) * 0.04);\n          gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4);\n        });\n      }\n      // Each string hangs from the foot of its balloon to a point off the bottom of the stage.\n      bodies.forEach((b, i) => {\n        const fx = b.hx + b.x - Math.sin(b.a) * b.size * 0.3;\n        const fy = b.hy + b.y + Math.cos(b.a) * b.size * 0.3;\n        const ex = W / 2 + (b.hx - W / 2) * 0.22;\n        paths[i]?.setAttribute(\"d\", `M${fx.toFixed(1)} ${fy.toFixed(1)} C${(fx + b.vx * 0.05).toFixed(1)} ${(fy + (H - fy) * 0.5).toFixed(1)} ${ex.toFixed(1)} ${(H - (H - fy) * 0.35).toFixed(1)} ${ex.toFixed(1)} ${H + 20}`);\n      });\n    };\n\n    const step = (dt: number, t: number, stamp: number) => {\n      const p = pointer.current;\n      const idle = stamp - p.at > 1800;\n      // With nobody about, a draught bumps one balloon every few seconds.\n      if (idle && t > nextGust) {\n        const i = Math.floor(grain(t * 3.1, 7) * count) % count;\n        const dir = grain(t, 3) > 0.5 ? 1 : -1;\n        queue.push({ at: t, i, fx: dir * (260 + grain(t, 9) * 160), fy: -120 });\n        nextGust = t + 2.4 + grain(t, 5) * 1.6;\n      }\n      if (seenWave !== wave.current) {\n        seenWave = wave.current;\n        bodies.forEach((_, i) => queue.push({ at: t + i * 0.085, i, fx: (i % 2 ? -1 : 1) * 90, fy: -420 }));\n      }\n      for (let k = queue.length - 1; k >= 0; k--) {\n        if (queue[k].at <= t) {\n          kick(queue[k].i, queue[k].fx, queue[k].fy);\n          queue.splice(k, 1);\n        }\n      }\n      const tx = idle ? Math.sin(t * 0.35) * 0.5 : (p.x / W) * 2 - 1;\n      const ty = idle ? Math.sin(t * 0.27) * 0.3 : 1 - (p.y / H) * 2;\n      lamp.x += (tx - lamp.x) * Math.min(1, dt * 4);\n      lamp.y += (ty - lamp.y) * Math.min(1, dt * 4);\n\n      bodies.forEach((b, i) => {\n        const cx = b.hx + b.x;\n        const cy = b.hy + b.y;\n        if (!idle) {\n          const dx = cx - p.x;\n          const dy = cy - p.y;\n          const reach = b.size * 0.5;\n          const d = Math.hypot(dx, dy) + 0.001;\n          if (d < reach) {\n            const push = 1 - d / reach;\n            const speed = Math.hypot(p.vx, p.vy);\n            b.vx += ((dx / d) * 1500 * push + p.vx * push * 5) * dt;\n            b.vy += ((dy / d) * 1500 * push + p.vy * push * 5) * dt;\n            b.va += ((dx * p.vy - dy * p.vx) / (reach * reach)) * push * 0.01 * dt * 60;\n            b.vw += speed * push * 0.0009 * dt * 60;\n            if (p.poke) kick(i, (dx / d) * 520, (dy / d) * 520 - 120);\n          }\n        }\n        // A light, floaty tether: it overshoots and takes a while to settle.\n        const bob = Math.sin(t * 0.9 + i * 1.7) * b.size * 0.022;\n        b.vx += (-b.x * 34 - b.vx * 2.6) * dt;\n        b.vy += ((bob - b.y) * 34 - b.vy * 2.6) * dt;\n        const lean = Math.sin(t * 0.6 + i * 2.3) * 0.035 + (b.x / b.size) * 0.5;\n        b.va += ((lean - b.a) * 30 - b.va * 2.4) * dt;\n        b.vw += (-b.w * 260 - b.vw * 9) * dt;\n      });\n      p.poke = false;\n      p.vx *= Math.pow(0.02, dt);\n      p.vy *= Math.pow(0.02, dt);\n      // Neighbours that swing into each other bounce apart.\n      for (let i = 0; i < count - 1; i++) {\n        const l = bodies[i];\n        const r = bodies[i + 1];\n        const rest = r.hx - l.hx;\n        const gap = r.hx + r.x - (l.hx + l.x);\n        const least = rest * 0.8;\n        if (gap < least) {\n          const fix = (least - gap) / 2;\n          l.x -= fix;\n          r.x += fix;\n          const swap = (l.vx - r.vx) * 0.75;\n          if (swap > 0) {\n            l.vx -= swap;\n            r.vx += swap;\n            l.vw += swap * 0.0016;\n            r.vw += swap * 0.0016;\n            r.va += swap * 0.0012;\n            l.va -= swap * 0.0012;\n          }\n        }\n      }\n      bodies.forEach((b) => {\n        b.x += b.vx * dt;\n        b.y += b.vy * dt;\n        b.a += b.va * dt;\n        b.w = Math.max(-0.16, Math.min(0.16, b.w + b.vw * dt));\n      });\n    };\n\n    const loop = (stamp: number) => {\n      const t = (stamp - started) / 1000;\n      const dt = Math.min(last ? (stamp - last) / 1000 : 0.016, 0.033);\n      last = stamp;\n      step(dt, t, stamp);\n      draw(t);\n      raf = visible && !document.hidden ? requestAnimationFrame(loop) : 0;\n    };\n    const wake = () => {\n      if (reduce) {\n        draw(0);\n        return;\n      }\n      if (!raf && visible && !document.hidden) {\n        last = 0;\n        raf = requestAnimationFrame(loop);\n      }\n    };\n    const ro = new ResizeObserver(() => {\n      layout();\n      if (reduce) draw(0);\n    });\n    ro.observe(el);\n    const io = new IntersectionObserver(([entry]) => {\n      visible = entry.isIntersecting;\n      wake();\n    });\n    io.observe(el);\n    document.addEventListener(\"visibilitychange\", wake);\n    layout();\n    setLive(true);\n    wake();\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      document.removeEventListener(\"visibilitychange\", wake);\n    };\n    // The word is a constant, so the letters never change between renders.\n    // eslint-disable-next-line react-hooks/exhaustive-deps\n  }, [reduce]);\n\n  function track(e: ReactPointerEvent<HTMLDivElement>) {\n    const r = e.currentTarget.getBoundingClientRect();\n    const p = pointer.current;\n    const x = e.clientX - r.left;\n    const y = e.clientY - r.top;\n    const now = performance.now();\n    const dt = Math.max(8, now - p.at) / 1000;\n    if (now - p.at < 200) {\n      p.vx = p.vx * 0.5 + ((x - p.x) / dt) * 0.5;\n      p.vy = p.vy * 0.5 + ((y - p.y) / dt) * 0.5;\n    }\n    p.x = x;\n    p.y = y;\n    p.at = now;\n    if (e.type === \"pointerdown\") p.poke = true;\n  }\n\n  return (\n    <section className=\"relative isolate flex min-h-[740px] w-full flex-col items-center overflow-hidden px-4\" style={{ backgroundColor: WALL }}>\n      <div aria-hidden=\"true\" className=\"absolute inset-0 -z-10\" style={{ background: \"radial-gradient(75% 60% at 50% 38%, rgba(255,255,255,0.34) 0%, rgba(255,255,255,0) 55%), linear-gradient(180deg, rgba(120,30,60,0) 55%, rgba(120,30,60,0.2) 100%)\" }} />\n\n      <style>{`\n        @keyframes silver-foil-balloon-letters-sheen { from { background-position: 50% 0%; } to { background-position: 50% 100%; } }\n        .sfb-still { animation: silver-foil-balloon-letters-sheen 3.4s ease-in-out infinite alternate; filter: drop-shadow(14px 22px 14px rgba(120, 30, 60, 0.3)); }\n        @media (prefers-reduced-motion: reduce) { .sfb-still { animation: none; } }\n      `}</style>\n      <div ref={stage} onPointerMove={track} onPointerDown={track} className=\"absolute inset-0 touch-pan-y\">\n        <svg ref={strings} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full transition-opacity duration-500 ${live ? \"opacity-100\" : \"opacity-0\"}`} fill=\"none\">\n          {letters.map((_, i) => (\n            <path key={i} stroke=\"rgba(255,255,255,0.75)\" strokeWidth=\"1.1\" strokeLinecap=\"round\" />\n          ))}\n        </svg>\n        <canvas ref={canvas} aria-hidden=\"true\" className={`absolute inset-0 h-full w-full transition-opacity duration-500 ${live ? \"opacity-100\" : \"opacity-0\"}`} />\n      </div>\n\n      {/* The real word. It is what assistive technology and search read, and what shows if the balloons cannot be drawn. */}\n      <h2\n        className={`pointer-events-none relative mt-[250px] select-none text-center text-[19vw] font-black leading-none tracking-tight sm:text-[150px] ${live ? \"text-transparent\" : \"sfb-still bg-clip-text text-transparent\"}`}\n        style={live ? undefined : { backgroundImage: \"linear-gradient(180deg, #ffffff 0%, #f4f4f8 38%, #3b2a3a 50%, #d98ea0 62%, #ffe3ea 100%)\", backgroundSize: \"100% 140%\" }}\n      >\n        {WORD}\n      </h2>\n\n      <div className=\"pointer-events-none relative mt-auto flex w-full max-w-[880px] items-center justify-between gap-4 pb-9 text-[13px]\">\n        <p className=\"text-[#5a1f33]\">\n          <span className=\"font-semibold text-[#3a0f20]\">Foil letters</span>\n          <span className=\"mx-2 opacity-50\">/</span>\n          sweep through them or tap one\n        </p>\n        {!reduce && (\n          <button\n            type=\"button\"\n            onClick={() => (wave.current += 1)}\n            className=\"pointer-events-auto min-h-[40px] shrink-0 rounded-full bg-[#3a0f20] px-5 font-medium text-white shadow-[0_10px_20px_-10px_rgba(58,15,32,0.7)] transition-transform hover:-translate-y-0.5 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#3a0f20] focus-visible:ring-offset-2 focus-visible:ring-offset-[#f2a9b8]\"\n          >\n            Bounce them\n          </button>\n        )}\n      </div>\n    </section>\n  );\n}\n"}]}
