{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "billow-gallery",
  "title": "Billow Gallery",
  "description": "An endless wall of prints that bend like paper. A slow swell rolls under the cards, they bow and twist as you drag, flick or scroll, and flutter flat again when the wall stops. Hovered cards lift on a deeper shadow. One WebGL canvas with a link list for screen readers, keyboard panning, reduced-motion support and a plain grid fallback. No dependencies.",
  "files": [
    {
      "path": "registry/new-york/blocks/billow-gallery/billow-gallery.tsx",
      "content": "\"use client\"\n\nimport * as React from \"react\"\n\nexport type BillowGalleryItem = {\n  src: string\n  alt?: string\n  /** Width over height of the card. The image is cropped to fill it. Defaults cycle through a few portrait shapes. */\n  aspect?: number\n  /** Turns the card into a link. */\n  href?: string\n  target?: \"_self\" | \"_blank\"\n}\n\nexport interface BillowGalleryProps\n  extends Omit<React.HTMLAttributes<HTMLDivElement>, \"children\" | \"onSelect\"> {\n  items: BillowGalleryItem[]\n\n  /* Layout */\n  /** Card width in px. Scaled down on narrow containers. */\n  columnWidth?: number\n  /** Space between cards in px. */\n  gap?: number\n  /** Card corner radius in px. */\n  radius?: number\n\n  /* Paper */\n  /** How far the sheets curl while the wall is moving. 0 keeps them flat. */\n  bend?: number\n  /** Height of the swell rolling across the wall. 0 stills it. */\n  crest?: number\n  /** Camera distance in px. Lower exaggerates the depth. */\n  perspective?: number\n  shadow?: boolean\n  /** Shadow colour as `#rrggbb`. */\n  shadowColor?: string\n\n  /* Motion */\n  /** Idle drift in px per second. Eases to a stop while hovered. 0 turns it off. */\n  drift?: number\n  draggable?: boolean\n  /** Pan with the mouse wheel or trackpad while hovering. */\n  wheel?: boolean\n\n  /** Called when a card is clicked or tapped (not dragged). */\n  onSelect?: (item: BillowGalleryItem, index: number) => void\n}\n\nconst DEFAULTS = {\n  columnWidth: 260,\n  gap: 56,\n  radius: 10,\n  bend: 1,\n  crest: 1,\n  perspective: 1100,\n  shadow: true,\n  shadowColor: \"#26303d\",\n  drift: 18,\n  draggable: true,\n  wheel: true,\n}\n\ntype Settings = typeof DEFAULTS\n\n/** Portrait shapes cycled through when an item has no `aspect`. */\nconst ASPECTS = [0.78, 0.68, 0.84, 0.72, 0.9, 0.66]\nconst SEGMENTS = 22\n/** Wavelength of the swell, px. */\nconst SWELL = 920\n/** How high a hovered or focused card lifts toward the camera, px. */\nconst LIFT = 42\n/** Oblique view: how far a point shifts on screen per px it rises. */\nconst TILT_X = -0.28\nconst TILT_Y = -0.5\n\nconst clamp = (v: number, min: number, max: number) => Math.min(max, Math.max(min, v))\nconst mod = (a: number, n: number) => ((a % n) + n) % n\nconst hash = (n: number) => {\n  const x = Math.sin(n * 127.1 + 311.7) * 43758.5453\n  return x - Math.floor(x)\n}\n\nfunction hexToRgb(hex: string): [number, number, number] {\n  const m = /^#?([0-9a-f]{6})$/i.exec(hex.trim())\n  const v = m ? parseInt(m[1], 16) : 0x26303d\n  return [((v >> 16) & 255) / 255, ((v >> 8) & 255) / 255, (v & 255) / 255]\n}\n\n/** The swell at a screen point, -1 to 1. Mirrors `swell()` in the vertex shader. */\nfunction swell(x: number, y: number, t: number) {\n  const k = (Math.PI * 2) / SWELL\n  return (\n    Math.sin((x * 0.62 + y * 0.78) * k - t * 0.6) * 0.65 +\n    Math.sin((-x * 0.8 + y * 0.6) * k * 1.6 + t * 0.45 + 1.3) * 0.35\n  )\n}\n\n/* ------------------------------------------------------------------ */\n/* Layout: staggered columns that wrap on both axes.                   */\n/* ------------------------------------------------------------------ */\n\ntype Cell = { item: number; x: number; y: number; w: number; h: number; col: number; seed: number }\ntype Layout = {\n  cells: Cell[]\n  periodX: number\n  periodY: number[]\n  /** Lower bounds used when wrapping, so a card straddling the edge is still drawn. */\n  loX: number\n  loY: number\n  margin: number\n  scale: number\n  step: number\n}\n\nfunction buildLayout(items: BillowGalleryItem[], viewW: number, viewH: number, s: Settings): Layout {\n  const n = items.length\n  const scale = clamp(viewW / 720, 0.56, 1)\n  const colW = s.columnWidth * scale\n  const gap = s.gap * scale\n  const step = colW + gap\n  const maxH = colW / 0.4\n  // Headroom past the edges, so cards bending in from outside are already there.\n  const margin = colW * 0.5 + gap\n  const loX = margin + colW\n  const loY = margin + maxH\n  const cols = Math.max(2, Math.ceil((viewW + margin + loX) / step) + 1)\n  // Stride between neighbouring columns, so the same image rarely sits side by side.\n  const skip = n > 2 ? Math.max(1, Math.round(n * 0.382)) : 1\n\n  const cells: Cell[] = []\n  const periodY: number[] = []\n  for (let c = 0; c < cols; c++) {\n    const offset = ((c % 2) * 0.5 + hash(c) * 0.35) * colW\n    let y = 0\n    let r = 0\n    while (y < viewH + margin + loY || r < 2) {\n      const item = (c * skip + r) % n\n      const aspect = clamp(items[item].aspect ?? ASPECTS[item % ASPECTS.length], 0.4, 2.5)\n      const h = colW / aspect\n      cells.push({ item, x: c * step, y: y + offset, w: colW, h, col: c, seed: hash(c * 31 + r * 7 + 1) })\n      y += h + gap\n      r++\n    }\n    periodY.push(y)\n  }\n  return { cells, periodX: cols * step, periodY, loX, loY, margin, scale, step }\n}\n\n/* ------------------------------------------------------------------ */\n/* Shaders                                                             */\n/* ------------------------------------------------------------------ */\n\nconst PROJECT = /* glsl */ `\nuniform vec2 uView;\nuniform float uPersp;\nvec4 project(vec2 p, float z) {\n  vec2 c = uView * 0.5;\n  z = min(z, uPersp * 0.6);\n  // A slightly oblique view: raised paper shifts up and left, away from its shadow.\n  p += z * vec2(${TILT_X.toFixed(2)}, ${TILT_Y.toFixed(2)});\n  vec2 s = c + (p - c) * (uPersp / (uPersp - z));\n  vec2 clip = s / uView * 2.0 - 1.0;\n  return vec4(clip.x, -clip.y, 0.0, 1.0);\n}\n`\n\nconst CARD_VERT = /* glsl */ `\nattribute vec2 aUv;\nuniform vec4 uRect;\nuniform vec2 uBend;\nuniform float uAmp;\nuniform float uCrest;\nuniform float uTime;\nuniform float uSeed;\nuniform float uLift;\nvarying vec2 vUv;\nvarying float vShade;\n${PROJECT}\n\nfloat swell(vec2 p) {\n  float k = 6.2831853 / ${SWELL.toFixed(1)};\n  return sin(dot(p, vec2(0.62, 0.78)) * k - uTime * 0.6) * 0.65\n       + sin(dot(p, vec2(-0.8, 0.6)) * k * 1.6 + uTime * 0.45 + 1.3) * 0.35;\n}\n\nfloat height(vec2 uv) {\n  vec2 p = uRect.xy + uv * uRect.zw;\n  vec2 q = uv * 2.0 - 1.0;\n  float seed = uSeed * 6.2831853;\n\n  // The swell rolling under the whole wall, plus each sheet's own slow flutter.\n  float z = uCrest * swell(p);\n  z += uCrest * 0.55 * sin(q.x * 1.6 + uTime * 0.7 + seed) * cos(q.y * 1.2 - uTime * 0.5 + seed * 0.5);\n  // Each sheet has one corner that won't lie flat.\n  vec2 corner = vec2(cos(seed * 1.7), sin(seed * 2.3));\n  float curl = max(dot(q, normalize(corner)) - 0.2, 0.0);\n  z += uCrest * 1.1 * curl * curl * (0.75 + 0.25 * sin(uTime * 0.9 + seed));\n\n  // Moving: the sheet bows along its direction of travel and twists a little.\n  float m = length(uBend);\n  if (m > 0.0001) {\n    vec2 d = uBend / m;\n    float s = dot(q, d);\n    float t = dot(q, vec2(-d.y, d.x));\n    float give = 0.7 + 0.6 * fract(uSeed * 7.13);\n    z += uAmp * m * give * (0.9 * s * s - 0.35 + (0.5 * uSeed - 0.25) * 1.6 * s * t);\n  }\n\n  // Lifting a sheet smooths it out.\n  return z * (1.0 - 0.75 * uLift) + uLift * ${LIFT.toFixed(1)};\n}\n\nvoid main() {\n  float e = 1.0 / ${SEGMENTS.toFixed(1)};\n  float z = height(aUv);\n  float dzx = (height(aUv + vec2(e, 0.0)) - height(aUv - vec2(e, 0.0))) / (2.0 * e * uRect.z);\n  float dzy = (height(aUv + vec2(0.0, e)) - height(aUv - vec2(0.0, e))) / (2.0 * e * uRect.w);\n  vec3 n = normalize(vec3(-dzx, -dzy, 1.0));\n  vec3 l = normalize(vec3(-0.45, -0.65, 1.0));\n  vShade = dot(n, l) / l.z;\n  vUv = aUv;\n  gl_Position = project(uRect.xy + aUv * uRect.zw, z);\n}\n`\n\nconst CARD_FRAG = /* glsl */ `\nprecision mediump float;\nuniform sampler2D uTex;\nuniform vec4 uCrop;\nuniform vec2 uSize;\nuniform float uRadius;\nuniform float uAlpha;\nuniform float uRing;\nuniform vec3 uRingColor;\nvarying vec2 vUv;\nvarying float vShade;\n\nvoid main() {\n  vec2 size = uSize;\n  vec2 px = (vUv - 0.5) * size;\n  vec2 d = abs(px) - (size * 0.5 - uRadius);\n  float sd = length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - uRadius;\n  float a = clamp(0.5 - sd, 0.0, 1.0) * uAlpha;\n\n  vec3 col = texture2D(uTex, uCrop.xy + vUv * uCrop.zw).rgb;\n  // Darken the faces turned away from the light, add a little sheen to the ones facing it.\n  col *= mix(1.0, vShade, 0.85);\n  col += max(vShade - 1.0, 0.0) * 0.35;\n\n  // Focus ring: a light band with a dark edge, inside the card.\n  float band = smoothstep(-6.0, -5.0, sd) * (1.0 - smoothstep(-3.0, -2.0, sd));\n  float edge = smoothstep(-3.0, -2.0, sd);\n  col = mix(col, vec3(1.0), band * uRing);\n  col = mix(col, uRingColor, edge * uRing);\n\n  gl_FragColor = vec4(col * a, a);\n}\n`\n\nconst SHADOW_VERT = /* glsl */ `\nattribute vec2 aUv;\nuniform vec4 uRect;\nuniform float uPad;\nvarying vec2 vPx;\n${PROJECT}\nvoid main() {\n  vec2 size = uRect.zw + uPad * 2.0;\n  vPx = (aUv - 0.5) * size;\n  gl_Position = project(uRect.xy - uPad + aUv * size, 0.0);\n}\n`\n\nconst SHADOW_FRAG = /* glsl */ `\nprecision mediump float;\nuniform vec2 uSize;\nuniform float uRadius;\nuniform float uBlur;\nuniform float uStrength;\nuniform vec3 uColor;\nvarying vec2 vPx;\nvoid main() {\n  vec2 d = abs(vPx) - (uSize * 0.5 - uRadius);\n  float sd = length(max(d, 0.0)) + min(max(d.x, d.y), 0.0) - uRadius;\n  float a = uStrength * (1.0 - smoothstep(-uBlur * 0.7, uBlur, sd));\n  gl_FragColor = vec4(uColor * a, a);\n}\n`\n\n/* ------------------------------------------------------------------ */\n/* GL helpers                                                          */\n/* ------------------------------------------------------------------ */\n\ntype GL = WebGLRenderingContext | WebGL2RenderingContext\n\nfunction compile(gl: GL, vert: string, frag: string) {\n  const make = (type: number, src: string) => {\n    const shader = gl.createShader(type)!\n    gl.shaderSource(shader, src)\n    gl.compileShader(shader)\n    if (!gl.getShaderParameter(shader, gl.COMPILE_STATUS)) {\n      throw new Error(gl.getShaderInfoLog(shader) ?? \"Shader failed to compile\")\n    }\n    return shader\n  }\n  const program = gl.createProgram()!\n  gl.attachShader(program, make(gl.VERTEX_SHADER, vert))\n  gl.attachShader(program, make(gl.FRAGMENT_SHADER, frag))\n  gl.linkProgram(program)\n  if (!gl.getProgramParameter(program, gl.LINK_STATUS)) {\n    throw new Error(gl.getProgramInfoLog(program) ?? \"Program failed to link\")\n  }\n  const uniforms: Record<string, WebGLUniformLocation | null> = {}\n  const count = gl.getProgramParameter(program, gl.ACTIVE_UNIFORMS) as number\n  for (let i = 0; i < count; i++) {\n    const info = gl.getActiveUniform(program, i)\n    if (info) uniforms[info.name] = gl.getUniformLocation(program, info.name)\n  }\n  return { program, uniforms, aUv: gl.getAttribLocation(program, \"aUv\") }\n}\n\n/** WebGL1 can only mipmap power-of-two textures, so redraw the image onto one. */\nfunction toPowerOfTwo(img: HTMLImageElement) {\n  const pot = (v: number) => clamp(2 ** Math.round(Math.log2(v)), 64, 1024)\n  const canvas = document.createElement(\"canvas\")\n  canvas.width = pot(img.naturalWidth)\n  canvas.height = pot(img.naturalHeight)\n  canvas.getContext(\"2d\")!.drawImage(img, 0, 0, canvas.width, canvas.height)\n  return canvas\n}\n\ntype Tex = { img: HTMLImageElement; tex: WebGLTexture | null; ready: number; aspect: number }\n\n/* ------------------------------------------------------------------ */\n/* Component                                                           */\n/* ------------------------------------------------------------------ */\n\nfunction splitProps(props: Record<string, unknown>) {\n  const settings: Record<string, unknown> = { ...DEFAULTS }\n  const rest: Record<string, unknown> = {}\n  for (const [key, value] of Object.entries(props)) {\n    if (key in DEFAULTS) {\n      if (value !== undefined) settings[key] = value\n    } else rest[key] = value\n  }\n  return { settings: settings as Settings, rest: rest as React.HTMLAttributes<HTMLDivElement> }\n}\n\ntype Visible = { cell: number; item: number; x: number; y: number; w: number; h: number; z: number }\n\nexport function BillowGallery({\n  items,\n  onSelect,\n  className,\n  style,\n  \"aria-label\": ariaLabel = \"Image gallery\",\n  ...props\n}: BillowGalleryProps) {\n  const { settings: s, rest } = splitProps(props)\n  const [fallback, setFallback] = React.useState(false)\n\n  const rootRef = React.useRef<HTMLDivElement>(null)\n  const canvasRef = React.useRef<HTMLCanvasElement>(null)\n  const linkRefs = React.useRef<(HTMLElement | null)[]>([])\n  const settingsRef = React.useRef(s)\n  const itemsRef = React.useRef(items)\n  const onSelectRef = React.useRef(onSelect)\n\n  const state = React.useRef({\n    cam: { x: 0, y: 0 },\n    prevCam: { x: 0, y: 0 },\n    vel: { x: 0, y: 0 },\n    seek: null as { x: number; y: number } | null,\n    bend: { x: 0, y: 0 },\n    bendVel: { x: 0, y: 0 },\n    motion: { x: 0, y: 0 },\n    driftAmount: 1,\n    dragging: false,\n    hovering: false,\n    focused: false,\n    pointer: null as { x: number; y: number } | null,\n    hoverCell: -1,\n    focusCell: -1,\n    lift: new Map<number, number>(),\n    visible: [] as Visible[],\n    layout: null as Layout | null,\n    layoutDirty: true,\n    view: { w: 0, h: 0 },\n    onScreen: true,\n    reduced: false,\n  })\n  const drag = React.useRef<{\n    id: number\n    startX: number\n    startY: number\n    lastX: number\n    lastY: number\n    moved: boolean\n    samples: { t: number; x: number; y: number }[]\n  } | null>(null)\n\n  React.useEffect(() => {\n    const prev = settingsRef.current\n    if (prev.columnWidth !== s.columnWidth || prev.gap !== s.gap) state.current.layoutDirty = true\n    settingsRef.current = s\n    itemsRef.current = items\n    onSelectRef.current = onSelect\n  })\n\n  // Items are compared by their sources so an inline array doesn't rebuild the wall every render.\n  const itemsKey = items.map((i) => `${i.src}|${i.aspect ?? \"\"}`).join(\"\\n\")\n  React.useEffect(() => {\n    state.current.layoutDirty = true\n  }, [itemsKey])\n\n  React.useEffect(() => {\n    const root = rootRef.current\n    const canvas = canvasRef.current\n    if (!root || !canvas) return\n\n    const attrs: WebGLContextAttributes = { alpha: true, antialias: true, premultipliedAlpha: true }\n    const gl = (canvas.getContext(\"webgl2\", attrs) ?? canvas.getContext(\"webgl\", attrs)) as GL | null\n    if (!gl) {\n      setFallback(true)\n      return\n    }\n    const isGL2 = typeof WebGL2RenderingContext !== \"undefined\" && gl instanceof WebGL2RenderingContext\n    const st = state.current\n    const mq = window.matchMedia(\"(prefers-reduced-motion: reduce)\")\n    st.reduced = mq.matches\n\n    let card: ReturnType<typeof compile>\n    let shade: ReturnType<typeof compile>\n    let mesh: { vbo: WebGLBuffer; ibo: WebGLBuffer; count: number }\n    let quad: WebGLBuffer\n    let blank: WebGLTexture\n    const textures = new Map<string, Tex>()\n\n    const upload = (t: Tex) => {\n      const tex = gl.createTexture()\n      gl.bindTexture(gl.TEXTURE_2D, tex)\n      gl.pixelStorei(gl.UNPACK_PREMULTIPLY_ALPHA_WEBGL, false)\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, isGL2 ? t.img : toPowerOfTwo(t.img))\n      gl.generateMipmap(gl.TEXTURE_2D)\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MIN_FILTER, gl.LINEAR_MIPMAP_LINEAR)\n      gl.texParameteri(gl.TEXTURE_2D, gl.TEXTURE_MAG_FILTER, gl.LINEAR)\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      t.tex = tex\n    }\n\n    const textureFor = (src: string) => {\n      let t = textures.get(src)\n      if (t) return t\n      const img = new Image()\n      img.crossOrigin = \"anonymous\"\n      img.decoding = \"async\"\n      t = { img, tex: null, ready: 0, aspect: 1 }\n      const entry = t\n      img.onload = () => {\n        if (gl.isContextLost()) return\n        entry.aspect = img.naturalWidth / img.naturalHeight\n        upload(entry)\n        entry.ready = performance.now()\n      }\n      img.src = src\n      textures.set(src, t)\n      return t\n    }\n\n    const init = () => {\n      card = compile(gl, CARD_VERT, CARD_FRAG)\n      shade = compile(gl, SHADOW_VERT, SHADOW_FRAG)\n\n      const verts: number[] = []\n      for (let y = 0; y <= SEGMENTS; y++)\n        for (let x = 0; x <= SEGMENTS; x++) verts.push(x / SEGMENTS, y / SEGMENTS)\n      const idx: number[] = []\n      for (let y = 0; y < SEGMENTS; y++)\n        for (let x = 0; x < SEGMENTS; x++) {\n          const a = y * (SEGMENTS + 1) + x\n          const b = a + SEGMENTS + 1\n          idx.push(a, b, a + 1, a + 1, b, b + 1)\n        }\n      const vbo = gl.createBuffer()!\n      gl.bindBuffer(gl.ARRAY_BUFFER, vbo)\n      gl.bufferData(gl.ARRAY_BUFFER, new Float32Array(verts), gl.STATIC_DRAW)\n      const ibo = gl.createBuffer()!\n      gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, ibo)\n      gl.bufferData(gl.ELEMENT_ARRAY_BUFFER, new Uint16Array(idx), gl.STATIC_DRAW)\n      mesh = { vbo, ibo, count: idx.length }\n\n      quad = gl.createBuffer()!\n      gl.bindBuffer(gl.ARRAY_BUFFER, quad)\n      gl.bufferData(gl.ARRAY_BUFFER, new Float32Array([0, 0, 1, 0, 0, 1, 1, 1]), gl.STATIC_DRAW)\n\n      blank = gl.createTexture()!\n      gl.bindTexture(gl.TEXTURE_2D, blank)\n      gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, 1, 1, 0, gl.RGBA, gl.UNSIGNED_BYTE, new Uint8Array([0, 0, 0, 0]))\n\n      gl.disable(gl.DEPTH_TEST)\n      gl.enable(gl.BLEND)\n      gl.blendFunc(gl.ONE, gl.ONE_MINUS_SRC_ALPHA)\n\n      for (const t of textures.values()) {\n        t.tex = null\n        if (t.img.complete && t.img.naturalWidth) upload(t)\n      }\n    }\n\n    try {\n      init()\n    } catch (err) {\n      console.error(err)\n      setFallback(true)\n      return\n    }\n\n    let dpr = 1\n    const resize = () => {\n      const rect = root.getBoundingClientRect()\n      dpr = Math.min(window.devicePixelRatio || 1, 2)\n      st.view = { w: rect.width, h: rect.height }\n      canvas.width = Math.max(1, Math.round(rect.width * dpr))\n      canvas.height = Math.max(1, Math.round(rect.height * dpr))\n      st.layoutDirty = true\n    }\n    resize()\n    const ro = new ResizeObserver(resize)\n    ro.observe(root)\n\n    const io = new IntersectionObserver(([entry]) => {\n      st.onScreen = entry.isIntersecting\n    })\n    io.observe(root)\n\n    const onMotion = () => {\n      st.reduced = mq.matches\n    }\n    mq.addEventListener(\"change\", onMotion)\n\n    let lost = false\n    const onLost = (e: Event) => {\n      e.preventDefault()\n      lost = true\n    }\n    const onRestored = () => {\n      try {\n        init()\n        lost = false\n      } catch {\n        setFallback(true)\n      }\n    }\n    canvas.addEventListener(\"webglcontextlost\", onLost)\n    canvas.addEventListener(\"webglcontextrestored\", onRestored)\n\n    const start = performance.now()\n    let last = start\n    let raf = 0\n    let cursor = \"\"\n\n    const tick = (now: number) => {\n      raf = requestAnimationFrame(tick)\n      const dt = Math.min((now - last) / 1000, 0.05)\n      last = now\n      if (lost || !st.onScreen || document.hidden || dt <= 0) return\n      const c = settingsRef.current\n      const list = itemsRef.current\n      const { w: vw, h: vh } = st.view\n      if (!list.length || vw < 1 || vh < 1) return\n\n      if (st.layoutDirty || !st.layout) {\n        st.layout = buildLayout(list, vw, vh, c)\n        st.layoutDirty = false\n        st.lift.clear()\n        st.hoverCell = -1\n        st.focusCell = -1\n      }\n      const L = st.layout\n      const frames = dt * 60\n      const reduced = st.reduced\n      const t = reduced ? 0 : (now - start) / 1000\n\n      /* Camera */\n      const held = st.hovering || st.focused || st.dragging\n      const driftGoal = c.drift > 0 && !reduced && !held ? 1 : 0\n      st.driftAmount += (driftGoal - st.driftAmount) * (1 - Math.pow(0.95, frames))\n\n      if (st.seek) {\n        const k = reduced ? 1 : 1 - Math.pow(1 - 0.2, frames)\n        st.cam.x += (st.seek.x - st.cam.x) * k\n        st.cam.y += (st.seek.y - st.cam.y) * k\n        if (Math.hypot(st.seek.x - st.cam.x, st.seek.y - st.cam.y) < 0.5) {\n          st.cam = { ...st.seek }\n          st.seek = null\n        }\n      } else if (!st.dragging) {\n        st.cam.x += st.vel.x * dt\n        st.cam.y += st.vel.y * dt\n        const glide = Math.pow(reduced ? 0.8 : 0.94, frames)\n        st.vel.x *= glide\n        st.vel.y *= glide\n        if (Math.hypot(st.vel.x, st.vel.y) < 2) st.vel = { x: 0, y: 0 }\n      }\n      st.cam.y += c.drift * L.scale * st.driftAmount * dt\n\n      /* Bend: a soft spring chasing the wall's velocity, so sheets flutter back when it stops. */\n      const mx = (st.cam.x - st.prevCam.x) / dt\n      const my = (st.cam.y - st.prevCam.y) / dt\n      st.prevCam = { ...st.cam }\n      st.motion.x += (mx - st.motion.x) * 0.5\n      st.motion.y += (my - st.motion.y) * 0.5\n      let tx = -st.motion.x / 1400\n      let ty = -st.motion.y / 1400\n      const tm = Math.hypot(tx, ty)\n      if (tm > 1.2) {\n        tx *= 1.2 / tm\n        ty *= 1.2 / tm\n      }\n      for (let i = 0; i < 4; i++) {\n        const h = dt / 4\n        st.bendVel.x += (170 * (tx - st.bend.x) - 15 * st.bendVel.x) * h\n        st.bendVel.y += (170 * (ty - st.bend.y) - 15 * st.bendVel.y) * h\n        st.bend.x += st.bendVel.x * h\n        st.bend.y += st.bendVel.y * h\n      }\n\n      /* Place the cards on screen */\n      const crestPx = c.crest * 44 * L.scale\n      const visible: Visible[] = []\n      for (let i = 0; i < L.cells.length; i++) {\n        const cell = L.cells[i]\n        const x = mod(cell.x - st.cam.x + L.loX, L.periodX) - L.loX\n        const y = mod(cell.y - st.cam.y + L.loY, L.periodY[cell.col]) - L.loY\n        if (x > vw + L.margin || y > vh + L.margin || x + cell.w < -L.margin || y + cell.h < -L.margin) continue\n        const z = crestPx * swell(x + cell.w / 2, y + cell.h / 2, t)\n        visible.push({ cell: i, item: cell.item, x, y, w: cell.w, h: cell.h, z })\n      }\n      st.visible = visible\n\n      /* Hover: the card under the pointer lifts */\n      const scaleAt = (z: number) => c.perspective / (c.perspective - z)\n      let hover = -1\n      if (st.pointer && !st.dragging) {\n        const p = st.pointer\n        for (let i = visible.length - 1; i >= 0; i--) {\n          const v = visible[i]\n          const z = v.z + (st.lift.get(v.cell) ?? 0) * LIFT\n          const k = scaleAt(z)\n          const x0 = vw / 2 + (v.x + z * TILT_X - vw / 2) * k\n          const y0 = vh / 2 + (v.y + z * TILT_Y - vh / 2) * k\n          if (p.x >= x0 && p.x <= x0 + v.w * k && p.y >= y0 && p.y <= y0 + v.h * k) {\n            hover = v.cell\n            break\n          }\n        }\n      }\n      st.hoverCell = hover\n      const want = hover >= 0 && (list[L.cells[hover].item]?.href || onSelectRef.current) ? \"pointer\" : \"\"\n      const nextCursor = st.dragging ? \"grabbing\" : want || (c.draggable ? \"grab\" : \"\")\n      if (nextCursor !== cursor) {\n        cursor = nextCursor\n        root.style.cursor = cursor\n      }\n\n      const liftEase = 1 - Math.pow(reduced ? 0.5 : 0.82, frames)\n      for (const v of visible) {\n        const goal = v.cell === st.hoverCell || v.cell === st.focusCell ? 1 : 0\n        const cur = st.lift.get(v.cell) ?? 0\n        if (cur === goal) continue\n        const next = cur + (goal - cur) * liftEase\n        st.lift.set(v.cell, Math.abs(goal - next) < 0.002 ? goal : next)\n      }\n\n      /* Draw */\n      gl.viewport(0, 0, canvas.width, canvas.height)\n      gl.clearColor(0, 0, 0, 0)\n      gl.clear(gl.COLOR_BUFFER_BIT)\n\n      // Lifted cards draw last, on top of their neighbours.\n      visible.sort((a, b) => (st.lift.get(a.cell) ?? 0) - (st.lift.get(b.cell) ?? 0))\n\n      const alphaOf = (v: Visible) => {\n        const tex = textureFor(list[v.item].src)\n        if (!tex.tex || !tex.ready) return { tex, alpha: 0 }\n        const k = clamp((now - tex.ready) / 520, 0, 1)\n        return { tex, alpha: reduced ? 1 : 1 - Math.pow(1 - k, 3) }\n      }\n\n      if (c.shadow) {\n        const [r, g, b] = hexToRgb(c.shadowColor)\n        gl.useProgram(shade.program)\n        gl.bindBuffer(gl.ARRAY_BUFFER, quad)\n        gl.enableVertexAttribArray(shade.aUv)\n        gl.vertexAttribPointer(shade.aUv, 2, gl.FLOAT, false, 0, 0)\n        const u = shade.uniforms\n        gl.uniform2f(u.uView, vw, vh)\n        gl.uniform1f(u.uPersp, c.perspective)\n        gl.uniform3f(u.uColor, r, g, b)\n        for (const v of visible) {\n          const { alpha } = alphaOf(v)\n          if (alpha <= 0) continue\n          const lift = st.lift.get(v.cell) ?? 0\n          // Sheets riding high on the swell cast longer, softer shadows.\n          const height = clamp((v.z / Math.max(crestPx, 1)) * 0.5 + 0.5, 0, 1) * (crestPx > 0 ? 1 : 0)\n          const inset = v.w * 0.06\n          const blur = (22 + 12 * height + 18 * lift) * L.scale\n          const drop = (20 + 14 * height + 22 * lift) * L.scale\n          gl.uniform4f(u.uRect, v.x + inset, v.y + drop, v.w - inset * 2, v.h - inset)\n          gl.uniform2f(u.uSize, v.w - inset * 2, v.h - inset)\n          gl.uniform1f(u.uPad, blur * 1.2)\n          gl.uniform1f(u.uRadius, Math.min(c.radius * 2, v.w / 2))\n          gl.uniform1f(u.uBlur, blur)\n          gl.uniform1f(u.uStrength, (0.2 + 0.05 * lift - 0.04 * height) * alpha)\n          gl.drawArrays(gl.TRIANGLE_STRIP, 0, 4)\n        }\n      }\n\n      gl.useProgram(card.program)\n      gl.bindBuffer(gl.ARRAY_BUFFER, mesh.vbo)\n      gl.bindBuffer(gl.ELEMENT_ARRAY_BUFFER, mesh.ibo)\n      gl.enableVertexAttribArray(card.aUv)\n      gl.vertexAttribPointer(card.aUv, 2, gl.FLOAT, false, 0, 0)\n      const u = card.uniforms\n      gl.uniform2f(u.uView, vw, vh)\n      gl.uniform1f(u.uPersp, c.perspective)\n      gl.uniform1f(u.uTime, t)\n      gl.uniform1f(u.uCrest, reduced ? 0 : crestPx)\n      gl.uniform1f(u.uAmp, c.bend * 110 * L.scale * (reduced ? 0.3 : 1))\n      gl.uniform2f(u.uBend, st.bend.x, st.bend.y)\n      const [rr, rg, rb] = hexToRgb(c.shadowColor)\n      gl.uniform3f(u.uRingColor, rr, rg, rb)\n      gl.uniform1i(u.uTex, 0)\n      gl.activeTexture(gl.TEXTURE0)\n      for (const v of visible) {\n        const { tex, alpha } = alphaOf(v)\n        if (alpha <= 0) continue\n        const cardAspect = v.w / v.h\n        let sx = 1\n        let sy = 1\n        if (tex.aspect > cardAspect) sx = cardAspect / tex.aspect\n        else sy = tex.aspect / cardAspect\n        gl.bindTexture(gl.TEXTURE_2D, tex.tex ?? blank)\n        gl.uniform4f(u.uRect, v.x, v.y, v.w, v.h)\n        gl.uniform2f(u.uSize, v.w, v.h)\n        gl.uniform4f(u.uCrop, (1 - sx) / 2, (1 - sy) / 2, sx, sy)\n        gl.uniform1f(u.uSeed, L.cells[v.cell].seed)\n        gl.uniform1f(u.uLift, st.lift.get(v.cell) ?? 0)\n        gl.uniform1f(u.uRadius, Math.min(c.radius, v.w / 2))\n        gl.uniform1f(u.uAlpha, alpha)\n        gl.uniform1f(u.uRing, v.cell === st.focusCell ? 1 : 0)\n        gl.drawElements(gl.TRIANGLES, mesh.count, gl.UNSIGNED_SHORT, 0)\n      }\n    }\n    raf = requestAnimationFrame(tick)\n\n    // Wheel and trackpad pan the wall. Needs a non-passive listener to stop the page scrolling.\n    const onWheel = (e: WheelEvent) => {\n      if (!settingsRef.current.wheel) return\n      const unit = e.deltaMode === 1 ? 16 : e.deltaMode === 2 ? st.view.h : 1\n      let dx = e.deltaX * unit\n      let dy = e.deltaY * unit\n      if (e.shiftKey && !dx) [dx, dy] = [dy, 0]\n      if (!dx && !dy) return\n      e.preventDefault()\n      st.seek = null\n      st.vel = { x: 0, y: 0 }\n      st.cam.x += dx\n      st.cam.y += dy\n    }\n    root.addEventListener(\"wheel\", onWheel, { passive: false })\n\n    return () => {\n      cancelAnimationFrame(raf)\n      ro.disconnect()\n      io.disconnect()\n      mq.removeEventListener(\"change\", onMotion)\n      canvas.removeEventListener(\"webglcontextlost\", onLost)\n      canvas.removeEventListener(\"webglcontextrestored\", onRestored)\n      root.removeEventListener(\"wheel\", onWheel)\n      for (const t of textures.values()) {\n        t.img.onload = null\n        if (t.tex) gl.deleteTexture(t.tex)\n      }\n      if (!gl.isContextLost()) {\n        gl.deleteTexture(blank)\n        gl.deleteBuffer(mesh.vbo)\n        gl.deleteBuffer(mesh.ibo)\n        gl.deleteBuffer(quad)\n        gl.deleteProgram(card.program)\n        gl.deleteProgram(shade.program)\n      }\n    }\n  }, [])\n\n  /* Pointer */\n\n  const localPoint = (e: React.PointerEvent) => {\n    const rect = rootRef.current!.getBoundingClientRect()\n    return { x: e.clientX - rect.left, y: e.clientY - rect.top }\n  }\n\n  const activate = (cellIndex: number) => {\n    const L = state.current.layout\n    if (!L || cellIndex < 0) return\n    const index = L.cells[cellIndex].item\n    const item = items[index]\n    if (!item) return\n    onSelectRef.current?.(item, index)\n    if (item.href) linkRefs.current[index]?.click()\n  }\n\n  const onPointerDown = (e: React.PointerEvent<HTMLDivElement>) => {\n    if (e.button !== 0 || drag.current) return\n    const st = state.current\n    st.seek = null\n    st.vel = { x: 0, y: 0 }\n    drag.current = {\n      id: e.pointerId,\n      startX: e.clientX,\n      startY: e.clientY,\n      lastX: e.clientX,\n      lastY: e.clientY,\n      moved: false,\n      samples: [{ t: performance.now(), x: st.cam.x, y: st.cam.y }],\n    }\n  }\n\n  const onPointerMove = (e: React.PointerEvent<HTMLDivElement>) => {\n    const st = state.current\n    if (e.pointerType === \"mouse\") st.pointer = localPoint(e)\n    const d = drag.current\n    if (!d || d.id !== e.pointerId || !s.draggable) return\n    if (!d.moved) {\n      if (Math.hypot(e.clientX - d.startX, e.clientY - d.startY) < 5) return\n      // Capture only once it's clearly a drag, so a plain tap still selects a card.\n      d.moved = true\n      st.dragging = true\n      e.currentTarget.setPointerCapture(e.pointerId)\n      d.lastX = e.clientX\n      d.lastY = e.clientY\n    }\n    st.cam.x -= e.clientX - d.lastX\n    st.cam.y -= e.clientY - d.lastY\n    d.lastX = e.clientX\n    d.lastY = e.clientY\n    const now = performance.now()\n    d.samples.push({ t: now, x: st.cam.x, y: st.cam.y })\n    while (d.samples.length > 2 && now - d.samples[0].t > 100) d.samples.shift()\n  }\n\n  const endDrag = (e: React.PointerEvent<HTMLDivElement>) => {\n    const d = drag.current\n    if (!d || d.id !== e.pointerId) return\n    drag.current = null\n    const st = state.current\n    if (!d.moved) {\n      if (e.type === \"pointerup\") {\n        // A tap: find the card under it. Touch has no hover, so test the point directly.\n        st.pointer = localPoint(e)\n        requestAnimationFrame(() => {\n          activate(st.hoverCell)\n          if (e.pointerType !== \"mouse\") st.pointer = null\n        })\n      }\n      return\n    }\n    st.dragging = false\n    if (e.currentTarget.hasPointerCapture(e.pointerId)) e.currentTarget.releasePointerCapture(e.pointerId)\n    const now = performance.now()\n    const first = d.samples[0]\n    const lastSample = d.samples[d.samples.length - 1]\n    if (now - lastSample.t > 80 || now <= first.t) return\n    const k = 1000 / (now - first.t)\n    st.vel = {\n      x: clamp((lastSample.x - first.x) * k, -4000, 4000),\n      y: clamp((lastSample.y - first.y) * k, -4000, 4000),\n    }\n  }\n\n  /* Keyboard: arrows pan, links in the hidden list bring their card into view. */\n\n  const onKeyDown = (e: React.KeyboardEvent<HTMLDivElement>) => {\n    const st = state.current\n    const L = st.layout\n    if (!L) return\n    const step = L.step\n    const dir: Record<string, [number, number]> = {\n      ArrowLeft: [-step, 0],\n      ArrowRight: [step, 0],\n      ArrowUp: [0, -step],\n      ArrowDown: [0, step],\n    }\n    const move = dir[e.key]\n    if (!move) return\n    e.preventDefault()\n    const base = st.seek ?? st.cam\n    st.vel = { x: 0, y: 0 }\n    st.seek = { x: base.x + move[0], y: base.y + move[1] }\n  }\n\n  const focusItem = (index: number) => {\n    const st = state.current\n    const L = st.layout\n    if (!L) return\n    st.focused = true\n    // Bring the nearest copy of the item to the centre.\n    const cx = st.view.w / 2\n    const cy = st.view.h / 2\n    let best: { cell: number; dx: number; dy: number; dist: number } | null = null\n    for (let i = 0; i < L.cells.length; i++) {\n      const cell = L.cells[i]\n      if (cell.item !== index) continue\n      const x = mod(cell.x - st.cam.x + L.loX, L.periodX) - L.loX\n      const y = mod(cell.y - st.cam.y + L.loY, L.periodY[cell.col]) - L.loY\n      const dx = x + cell.w / 2 - cx\n      const dy = y + cell.h / 2 - cy\n      const dist = Math.hypot(dx, dy)\n      if (!best || dist < best.dist) best = { cell: i, dx, dy, dist }\n    }\n    if (!best) return\n    st.focusCell = best.cell\n    st.vel = { x: 0, y: 0 }\n    st.seek = { x: st.cam.x + best.dx, y: st.cam.y + best.dy }\n  }\n\n  const blurItem = () => {\n    state.current.focusCell = -1\n  }\n\n  if (fallback) {\n    return (\n      <div\n        {...rest}\n        role=\"region\"\n        aria-label={ariaLabel}\n        className={[\"relative overflow-auto\", className].filter(Boolean).join(\" \")}\n        style={style}\n      >\n        <ul className=\"m-0 list-none p-6\" style={{ columnWidth: s.columnWidth, columnGap: s.gap }}>\n          {items.map((item, i) => {\n            const img = (\n              // eslint-disable-next-line @next/next/no-img-element\n              <img\n                src={item.src}\n                alt={item.alt ?? \"\"}\n                loading=\"lazy\"\n                className=\"block w-full object-cover\"\n                style={{\n                  aspectRatio: item.aspect ?? ASPECTS[i % ASPECTS.length],\n                  borderRadius: s.radius,\n                }}\n              />\n            )\n            return (\n              <li key={i} className=\"break-inside-avoid\" style={{ marginBottom: s.gap }}>\n                {item.href ? (\n                  <a\n                    href={item.href}\n                    target={item.target}\n                    rel={item.target === \"_blank\" ? \"noopener noreferrer\" : undefined}\n                    onClick={() => onSelect?.(item, i)}\n                  >\n                    {img}\n                  </a>\n                ) : onSelect ? (\n                  <button type=\"button\" className=\"block w-full\" onClick={() => onSelect(item, i)}>\n                    {img}\n                  </button>\n                ) : (\n                  img\n                )}\n              </li>\n            )\n          })}\n        </ul>\n      </div>\n    )\n  }\n\n  return (\n    <div\n      {...rest}\n      ref={rootRef}\n      role=\"region\"\n      aria-roledescription=\"gallery\"\n      aria-label={ariaLabel}\n      tabIndex={0}\n      className={[\n        \"relative overflow-hidden select-none outline-none focus-visible:ring-2 focus-visible:ring-ring\",\n        className,\n      ]\n        .filter(Boolean)\n        .join(\" \")}\n      style={{ touchAction: s.draggable ? \"none\" : \"pan-y\", ...style }}\n      onPointerDown={onPointerDown}\n      onPointerMove={onPointerMove}\n      onPointerUp={endDrag}\n      onPointerCancel={endDrag}\n      onPointerEnter={(e) => {\n        if (e.pointerType === \"mouse\") state.current.hovering = true\n      }}\n      onPointerLeave={(e) => {\n        if (e.pointerType !== \"mouse\") return\n        state.current.hovering = false\n        state.current.pointer = null\n      }}\n      onFocus={(e) => {\n        if (e.target === e.currentTarget) state.current.focused = true\n      }}\n      onBlur={(e) => {\n        if (!e.currentTarget.contains(e.relatedTarget as Node | null)) {\n          state.current.focused = false\n          state.current.focusCell = -1\n        }\n      }}\n      onKeyDown={onKeyDown}\n    >\n      <canvas ref={canvasRef} aria-hidden className=\"pointer-events-none absolute inset-0 block size-full\" />\n      {/* The wall is drawn on a canvas; this list carries it for screen readers and keyboard users. */}\n      <ul className=\"sr-only\">\n        {items.map((item, i) => {\n          const ref = (el: HTMLElement | null) => {\n            linkRefs.current[i] = el\n          }\n          const handlers = { onFocus: () => focusItem(i), onBlur: blurItem }\n          return (\n            <li key={i}>\n              {item.href ? (\n                <a\n                  ref={ref}\n                  href={item.href}\n                  target={item.target}\n                  rel={item.target === \"_blank\" ? \"noopener noreferrer\" : undefined}\n                  {...handlers}\n                >\n                  {item.alt || item.href}\n                </a>\n              ) : onSelect ? (\n                <button ref={ref} type=\"button\" onClick={() => onSelect(item, i)} {...handlers}>\n                  {item.alt || `Image ${i + 1}`}\n                </button>\n              ) : (\n                <span>{item.alt}</span>\n              )}\n            </li>\n          )\n        })}\n      </ul>\n    </div>\n  )\n}\n",
      "type": "registry:component"
    }
  ],
  "meta": {
    "addedAt": "2026-11-24",
    "look": "classic"
  },
  "type": "registry:component"
}