{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "gallery-liquid-seams-01",
  "title": "Liquid Seams",
  "description": "A centered column of pictures whose joins run together like wet paint while the page scrolls fast, then part into crisp, separate pictures with a clear gap as it slows",
  "dependencies": [
    "motion@13"
  ],
  "registryDependencies": [
    "https://ui.cortexcn.dev/r/utils.json"
  ],
  "files": [
    {
      "path": "registry/blocks/gallery-liquid-seams-01/components/liquid-seams-gallery.tsx",
      "content": "\"use client\";\n\nimport { type CSSProperties, useId, useRef } from \"react\";\nimport { cn } from \"@/lib/utils\";\nimport { GalleryHeader } from \"./liquid-seams/gallery-header\";\nimport { PictureTile } from \"./liquid-seams/picture-tile\";\nimport { DEFAULT_PICTURES, type Picture } from \"./liquid-seams/pictures\";\nimport { SeamBand } from \"./liquid-seams/seam-band\";\nimport { useSeamFlow } from \"./liquid-seams/use-seam-flow\";\n\n// Cortexcn item \"gallery-liquid-seams-01\", revision 95e8a7e696e2, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-liquid-seams-01/95e8a7e696e2.json\n\nexport type { Picture } from \"./liquid-seams/pictures\";\n\nexport interface LiquidSeamsGalleryProps {\n  /** The pictures, top to bottom. Each tile takes its picture's shape. */\n  pictures?: Picture[];\n  /** Leave it empty to show the column on its own. */\n  heading?: string;\n  description?: string;\n  /** Pixels between pictures while the page is still. */\n  gap?: number;\n  /** The furthest, in pixels, the paint is pushed at full speed. */\n  maxSmear?: number;\n  /**\n   * How far, in pixels, each seam reaches into the pictures on either side.\n   * Narrow screens use less, so a seam never covers most of a picture.\n   */\n  seamDepth?: number;\n  /** The scroll speed, in pixels per second, that melts the seams fully. */\n  fullSpeed?: number;\n  /** Names the gallery for screen readers when there is no heading. */\n  label?: string;\n  className?: string;\n}\n\n/**\n * A centered column of pictures whose joins run together like wet paint\n * while the page scrolls fast. Each join is a band over the gap that blends\n * the two pictures' edges and swirls them with an SVG filter, as strongly as\n * the scroll is fast. When the scroll slows the bands fade away, leaving\n * crisp, separate pictures with a clear gap. With reduced motion the\n * pictures always stay crisp.\n */\nexport function LiquidSeamsGallery({\n  pictures = DEFAULT_PICTURES,\n  heading = \"Paintings from the meadow\",\n  description = \"Scroll quickly and the edges between the pictures run together like wet paint. Slow down and each one settles back into its own frame.\",\n  gap = 24,\n  maxSmear = 40,\n  seamDepth = 88,\n  fullSpeed = 2400,\n  label = \"Paintings\",\n  className,\n}: LiquidSeamsGalleryProps) {\n  const headingId = useId();\n  const listRef = useRef<HTMLUListElement>(null);\n  const { flow, strength } = useSeamFlow(listRef, fullSpeed);\n\n  const seams = {\n    \"--seam-gap\": `${gap}px`,\n    \"--seam-depth\": `min(${seamDepth}px, 12cqw)`,\n    gap: \"var(--seam-gap)\",\n  } as CSSProperties;\n\n  return (\n    <section\n      aria-label={heading ? undefined : label}\n      aria-labelledby={heading ? headingId : undefined}\n      className={cn(\"w-full\", className)}\n    >\n      <div className=\"mx-auto flex w-full max-w-3xl flex-col gap-10\">\n        {heading ? (\n          <GalleryHeader\n            description={description}\n            heading={heading}\n            id={headingId}\n          />\n        ) : null}\n        <ul className=\"@container flex flex-col\" ref={listRef} style={seams}>\n          {pictures.map((picture, index) => {\n            const next = pictures[index + 1];\n            return (\n              <li className=\"relative\" key={picture.src}>\n                <PictureTile\n                  eager={index === 0}\n                  number={index + 1}\n                  picture={picture}\n                />\n                {next ? (\n                  <SeamBand\n                    flow={flow}\n                    lower={next}\n                    maxSmear={maxSmear}\n                    seed={index * 3 + 1}\n                    strength={strength}\n                    upper={picture}\n                  />\n                ) : null}\n              </li>\n            );\n          })}\n        </ul>\n      </div>\n    </section>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/liquid-seams-gallery.tsx"
    },
    {
      "path": "registry/blocks/gallery-liquid-seams-01/components/liquid-seams/gallery-header.tsx",
      "content": "/** The gallery's heading and a line that tells visitors what to try. */\nexport function GalleryHeader({\n  id,\n  heading,\n  description,\n}: {\n  id: string;\n  heading: string;\n  description?: string;\n}) {\n  return (\n    <header className=\"flex flex-col items-center gap-3 text-center\">\n      <h2\n        className=\"text-balance font-semibold text-3xl tracking-tight sm:text-4xl\"\n        id={id}\n      >\n        {heading}\n      </h2>\n      {description ? (\n        <p className=\"max-w-md text-pretty text-muted-foreground leading-relaxed\">\n          {description}\n        </p>\n      ) : null}\n    </header>\n  );\n}\n// Cortexcn item \"gallery-liquid-seams-01\", revision 95e8a7e696e2, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-liquid-seams-01/95e8a7e696e2.json\n\n",
      "type": "registry:component",
      "target": "components/liquid-seams/gallery-header.tsx"
    },
    {
      "path": "registry/blocks/gallery-liquid-seams-01/components/liquid-seams/picture-tile.tsx",
      "content": "import type { Picture } from \"./pictures\";\n\n// Cortexcn item \"gallery-liquid-seams-01\", revision 95e8a7e696e2, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-liquid-seams-01/95e8a7e696e2.json\n\nfunction pad(value: number) {\n  return String(value).padStart(2, \"0\");\n}\n\n/**\n * One picture in the column, the full width of it and the shape of the\n * picture, with rounded corners. Its number and title sit above the seams,\n * so they stay sharp while the edges around them melt.\n */\nexport function PictureTile({\n  picture,\n  number,\n  eager = false,\n}: {\n  picture: Picture;\n  number: number;\n  /** Loads at once instead of when it nears the screen. */\n  eager?: boolean;\n}) {\n  return (\n    <figure\n      className=\"relative overflow-hidden rounded-2xl bg-muted\"\n      style={{ aspectRatio: `${picture.width} / ${picture.height}` }}\n    >\n      {/* biome-ignore lint/performance/noImgElement: framework-agnostic registry block */}\n      <img\n        alt={picture.alt}\n        className=\"absolute inset-0 size-full object-cover\"\n        decoding=\"async\"\n        draggable={false}\n        height={picture.height}\n        loading={eager ? \"eager\" : \"lazy\"}\n        src={picture.src}\n        width={picture.width}\n      />\n      {/* A hairline that keeps pale pictures apart from a light page. */}\n      <span\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-0 rounded-2xl ring-1 ring-foreground/10 ring-inset\"\n      />\n      {picture.title ? (\n        <figcaption className=\"absolute bottom-3 left-3 z-20 flex max-w-[calc(100%-1.5rem)] items-center gap-2 rounded-full border border-border/60 bg-background/90 px-3 py-1 text-xs shadow-sm backdrop-blur-sm sm:bottom-4 sm:left-4\">\n          <span className=\"font-mono text-muted-foreground tabular-nums\">\n            {pad(number)}\n          </span>\n          <span className=\"truncate font-medium text-foreground\">\n            {picture.title}\n          </span>\n        </figcaption>\n      ) : null}\n    </figure>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/liquid-seams/picture-tile.tsx"
    },
    {
      "path": "registry/blocks/gallery-liquid-seams-01/components/liquid-seams/pictures.ts",
      "content": "export interface Picture {\n  src: string;\n  /** Describes the picture for screen readers. */\n  alt: string;\n  /**\n   * The picture's size in pixels. Its tile takes the same shape, so the\n   * edges in each seam line up with the pictures around them.\n   */\n  width: number;\n  height: number;\n  /** A short label shown on the picture. */\n  title?: string;\n}\n\n// Cortexcn item \"gallery-liquid-seams-01\", revision 95e8a7e696e2, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-liquid-seams-01/95e8a7e696e2.json\n\n/** The oil paintings from the Cortexcn site. Swap in your own pictures. */\nconst ART_BASE = \"https://www.cortexcn.dev/images/ui-home\";\n\nexport const DEFAULT_PICTURES: Picture[] = [\n  {\n    src: `${ART_BASE}/soft-meadow-grass.webp`,\n    alt: \"An oil painting of pale seed heads on long green stems bending to the right across a soft blue sky, with blurred patches of peach behind them\",\n    title: \"Seed heads in the wind\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/white-blooms.webp`,\n    alt: \"An oil painting of fluffy white flower heads with amber centers, tossed by the wind above a base of teal and green under a pale blue sky\",\n    title: \"White blooms\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/pastel-wildflowers.webp`,\n    alt: \"An oil painting of small yellow and coral wildflowers on thin stems rising from dark green grass on the right, against a misty blue background\",\n    title: \"Yellow wildflowers\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/neutral-florals.webp`,\n    alt: \"An oil painting of three white flowers with peach centers on long, thin stems against a hazy blue and green background\",\n    title: \"Three white flowers\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/pastel-daisies.webp`,\n    alt: \"An oil painting of white daisies with gold centers scattered through tall green grass under a pale sky\",\n    title: \"Daisies in the grass\",\n    width: 1344,\n    height: 896,\n  },\n  {\n    src: `${ART_BASE}/blue-cream-florals.webp`,\n    alt: \"An oil painting of two white flowers with yellow centers on the left, above grass brushed in green, teal, and gold under a misty blue sky\",\n    title: \"Edge of the field\",\n    width: 1344,\n    height: 896,\n  },\n];\n",
      "type": "registry:lib",
      "target": "components/liquid-seams/pictures.ts"
    },
    {
      "path": "registry/blocks/gallery-liquid-seams-01/components/liquid-seams/seam-band.tsx",
      "content": "\"use client\";\n\nimport { type MotionValue, motion, useTransform } from \"motion/react\";\nimport { type CSSProperties, useId } from \"react\";\nimport type { Picture } from \"./pictures\";\nimport { SeamFilter } from \"./seam-filter\";\n\n// Cortexcn item \"gallery-liquid-seams-01\", revision 95e8a7e696e2, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-liquid-seams-01/95e8a7e696e2.json\n\ninterface SeamBandProps {\n  /** The picture above the seam. */\n  upper: Picture;\n  /** The picture below the seam. */\n  lower: Picture;\n  flow: MotionValue<number>;\n  strength: MotionValue<number>;\n  /** The furthest, in pixels, the paint is pushed at full speed. */\n  maxSmear: number;\n  seed: number;\n}\n\n/** Below this strength the band is hidden and runs no filter at all. */\nconst AT_REST = 0.005;\n/** How far the paint lags behind the scroll, as a share of the smear. */\nconst TRAIL_SHARE = 0.5;\n\n/** Fades the band out at its top and bottom, into the crisp pictures. */\nconst EDGE_FADE =\n  \"linear-gradient(to bottom, transparent, black 24%, black 76%, transparent)\";\n/** Brings the lower picture in across the middle of the band. */\nconst CROSSFADE = \"linear-gradient(to bottom, transparent 30%, black 70%)\";\n\nconst UNSAFE_ID = /[^\\w-]/g;\n\n/**\n * One picture's edge as paint for the seam: the picture lined up with its\n * tile, and a mirrored copy past the edge, so the paint runs on into the gap\n * without a hard line. Both lag a little behind the scroll.\n */\nfunction PaintedEdge({\n  picture,\n  edge,\n  trail,\n}: {\n  picture: Picture;\n  edge: \"top\" | \"bottom\";\n  trail: MotionValue<number>;\n}) {\n  const shape = { aspectRatio: `${picture.width} / ${picture.height}` };\n  // Where the picture's edge sits in the band, from the band's own edge.\n  const lined: CSSProperties =\n    edge === \"bottom\"\n      ? { bottom: \"calc(var(--seam-depth) + var(--seam-gap))\" }\n      : { top: \"calc(var(--seam-depth) + var(--seam-gap))\" };\n  const mirrored: CSSProperties =\n    edge === \"bottom\"\n      ? { top: \"var(--seam-depth)\" }\n      : { bottom: \"var(--seam-depth)\" };\n\n  return (\n    <motion.div className=\"absolute inset-0\" style={{ y: trail }}>\n      {/* biome-ignore lint/performance/noImgElement: framework-agnostic registry block */}\n      <img\n        alt=\"\"\n        className=\"absolute inset-x-0 h-auto w-full\"\n        decoding=\"async\"\n        draggable={false}\n        height={picture.height}\n        loading=\"lazy\"\n        src={picture.src}\n        style={{ ...shape, ...lined }}\n        width={picture.width}\n      />\n      {/* biome-ignore lint/performance/noImgElement: framework-agnostic registry block */}\n      <img\n        alt=\"\"\n        className=\"absolute inset-x-0 h-auto w-full -scale-y-100\"\n        decoding=\"async\"\n        draggable={false}\n        height={picture.height}\n        loading=\"lazy\"\n        src={picture.src}\n        style={{ ...shape, ...mirrored }}\n        width={picture.width}\n      />\n    </motion.div>\n  );\n}\n\n/**\n * The join between two pictures. It reaches into both and spans the gap, and\n * only shows while the page scrolls fast: the lower picture fades in over the\n * upper one across the middle, and the seam filter swirls the two together.\n * As the scroll slows it fades out, and the crisp pictures and the gap\n * between them show through again. At rest it is hidden with no filter.\n */\nexport function SeamBand({\n  upper,\n  lower,\n  flow,\n  strength,\n  maxSmear,\n  seed,\n}: SeamBandProps) {\n  const filterId = `liquid-seam-${useId().replace(UNSAFE_ID, \"\")}`;\n  const opacity = useTransform(strength, [0, 0.5], [0, 1]);\n  const visibility = useTransform(strength, (value) =>\n    value > AT_REST ? \"visible\" : \"hidden\",\n  );\n  const filter = useTransform(strength, (value) =>\n    value > AT_REST ? `url(#${filterId})` : \"none\",\n  );\n  // feDisplacementMap moves a pixel by up to half its scale either way.\n  const scale = useTransform(strength, (value) => value * maxSmear * 2);\n  const trail = useTransform(flow, (value) => value * maxSmear * TRAIL_SHARE);\n\n  return (\n    <>\n      <SeamFilter id={filterId} scale={scale} seed={seed} />\n      <motion.div\n        aria-hidden=\"true\"\n        className=\"pointer-events-none absolute inset-x-0 z-10 overflow-hidden\"\n        style={{\n          top: \"calc(100% - var(--seam-depth))\",\n          height: \"calc(var(--seam-depth) * 2 + var(--seam-gap))\",\n          opacity,\n          visibility,\n          filter,\n          maskImage: EDGE_FADE,\n          WebkitMaskImage: EDGE_FADE,\n        }}\n      >\n        <PaintedEdge edge=\"bottom\" picture={upper} trail={trail} />\n        {/* The mask stays put while the paint inside it trails. */}\n        <div\n          className=\"absolute inset-0\"\n          style={{ maskImage: CROSSFADE, WebkitMaskImage: CROSSFADE }}\n        >\n          <PaintedEdge edge=\"top\" picture={lower} trail={trail} />\n        </div>\n      </motion.div>\n    </>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/liquid-seams/seam-band.tsx"
    },
    {
      "path": "registry/blocks/gallery-liquid-seams-01/components/liquid-seams/seam-filter.tsx",
      "content": "\"use client\";\n\nimport { type MotionValue, useMotionValueEvent } from \"motion/react\";\nimport { useRef } from \"react\";\n\n// Cortexcn item \"gallery-liquid-seams-01\", revision 95e8a7e696e2, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-liquid-seams-01/95e8a7e696e2.json\n\ninterface SeamFilterProps {\n  id: string;\n  /** Seeds the noise, so no two seams swirl the same way. */\n  seed: number;\n  /** How hard the noise pushes the paint, in pixels. Follows the scroll. */\n  scale: MotionValue<number>;\n}\n\n/**\n * Soft noise, wide from side to side and tight from top to bottom. The green\n * channel is pushed toward its extremes and the red one is flattened, so the\n * paint runs up and down in wavy streaks and barely drifts sideways.\n */\nconst NOISE_TO_FLOW = [\n  \"0.4 0 0 0 0.3\",\n  \"0 1.8 0 0 -0.4\",\n  \"0 0 1 0 0\",\n  \"0 0 0 0 1\",\n].join(\" \");\n\n/**\n * The SVG filter that marbles one seam. It moves every pixel of the seam band\n * up or down by an amount read from the noise, so the two pictures run into\n * each other in streaks. The push is set straight on the element as the\n * scroll speed changes, so it never re-renders React.\n */\nexport function SeamFilter({ id, seed, scale }: SeamFilterProps) {\n  const mapRef = useRef<SVGFEDisplacementMapElement>(null);\n\n  useMotionValueEvent(scale, \"change\", (value) => {\n    mapRef.current?.setAttribute(\"scale\", value.toFixed(2));\n  });\n\n  return (\n    <svg\n      aria-hidden=\"true\"\n      className=\"pointer-events-none absolute size-0 overflow-hidden\"\n      focusable=\"false\"\n    >\n      <filter\n        colorInterpolationFilters=\"sRGB\"\n        height=\"140%\"\n        id={id}\n        width=\"120%\"\n        x=\"-10%\"\n        y=\"-20%\"\n      >\n        <feTurbulence\n          baseFrequency=\"0.008 0.03\"\n          numOctaves={2}\n          result=\"noise\"\n          seed={seed}\n          type=\"fractalNoise\"\n        />\n        <feColorMatrix\n          in=\"noise\"\n          result=\"flow\"\n          type=\"matrix\"\n          values={NOISE_TO_FLOW}\n        />\n        <feDisplacementMap\n          in=\"SourceGraphic\"\n          in2=\"flow\"\n          ref={mapRef}\n          scale={0}\n          xChannelSelector=\"R\"\n          yChannelSelector=\"G\"\n        />\n      </filter>\n    </svg>\n  );\n}\n",
      "type": "registry:component",
      "target": "components/liquid-seams/seam-filter.tsx"
    },
    {
      "path": "registry/blocks/gallery-liquid-seams-01/components/liquid-seams/use-seam-flow.ts",
      "content": "\"use client\";\n\nimport {\n  type MotionValue,\n  useMotionValue,\n  useReducedMotion,\n  useSpring,\n  useTransform,\n  useVelocity,\n} from \"motion/react\";\nimport { type RefObject, useEffect } from \"react\";\n\n// Cortexcn item \"gallery-liquid-seams-01\", revision 95e8a7e696e2, MIT license.\n// https://ui.cortexcn.dev/r/v/gallery-liquid-seams-01/95e8a7e696e2.json\n\nexport interface SeamFlow {\n  /**\n   * From -1 to 1: positive while the page scrolls down, negative while it\n   * scrolls up, and 0 when it is still.\n   */\n  flow: MotionValue<number>;\n  /** How far the seams have melted, from 0 when still to 1 at full speed. */\n  strength: MotionValue<number>;\n}\n\n/** Scrolling slower than this share of the full speed leaves the seams alone. */\nconst CALM_SHARE = 0.25;\n/** A pause longer than this, in milliseconds, means the next scroll is new. */\nconst IDLE_MS = 120;\n/** Picks up quickly and settles in about half a second, without a bounce. */\nconst SETTLE = { stiffness: 170, damping: 28, mass: 0.7 };\n\n/**\n * Turns the gallery's speed on screen into how far its seams melt. It reads\n * the gallery's own position on every scroll, so it works whether the window\n * scrolls or a box around the gallery does. With reduced motion it never\n * listens, and the seams stay crisp.\n */\nexport function useSeamFlow(\n  target: RefObject<HTMLElement | null>,\n  fullSpeed: number,\n): SeamFlow {\n  const reduceMotion = useReducedMotion();\n  /** How far the gallery has moved up the screen, in pixels. */\n  const travel = useMotionValue(0);\n  const speed = useVelocity(travel);\n  const calm = fullSpeed * CALM_SHARE;\n  const push = useTransform(\n    speed,\n    [-fullSpeed, -calm, calm, fullSpeed],\n    [-1, 0, 0, 1],\n  );\n  const flow = useSpring(push, SETTLE);\n  const strength = useTransform(flow, (value) => Math.min(Math.abs(value), 1));\n\n  useEffect(() => {\n    const node = target.current;\n    if (!node || reduceMotion) {\n      return;\n    }\n    let lastAt = Number.NEGATIVE_INFINITY;\n    const measure = () => {\n      const now = performance.now();\n      const moved = -node.getBoundingClientRect().top;\n      // The first reading of a new scroll only marks where it starts, so a\n      // layout change made while the page was still never counts as speed.\n      if (now - lastAt > IDLE_MS) {\n        travel.jump(moved);\n      } else {\n        travel.set(moved);\n      }\n      lastAt = now;\n    };\n    // Scroll events do not bubble, so listening while they travel down to\n    // the target catches the window and every scrolling box alike.\n    const options = { capture: true, passive: true };\n    document.addEventListener(\"scroll\", measure, options);\n    return () => document.removeEventListener(\"scroll\", measure, options);\n  }, [target, reduceMotion, travel]);\n\n  return { flow, strength };\n}\n",
      "type": "registry:lib",
      "target": "components/liquid-seams/use-seam-flow.ts"
    }
  ],
  "type": "registry:block",
  "author": "Cortexcn (https://ui.cortexcn.dev)",
  "meta": {
    "license": "MIT",
    "revision": "95e8a7e696e2"
  }
}