{
  "$schema": "https://ui.shadcn.com/schema/registry-item.json",
  "name": "horizontal-case-strip",
  "type": "registry:block",
  "title": "Horizontal Case Strip",
  "description": "A row of case studies that scrolls sideways while the page scrolls down: a pixel of scroll moves it a pixel, with a count, a progress rail and keyboard focus that brings each card into view.",
  "dependencies": [
    "svg-scroll-draw"
  ],
  "files": [
    {
      "path": "registry/blocks/horizontal-case-strip.tsx",
      "content": "'use client';\n\n/**\n * horizontal-case-strip — a row of case-study cards that slides sideways as the\n * reader scrolls down. The stage holds still while the row crosses it, and a\n * count and a progress rail show how far along the reader is.\n *\n * Built on svg-scroll-draw (MIT): https://svg-scroll-draw.vercel.app/blocks\n * Needs: react, svg-scroll-draw 2.18.1 or later (`scrollHorizontal` from\n * `svg-scroll-draw/horizontal`, measured against the sticky stage).\n * Styling: Tailwind CSS.\n *\n * Uses scrollHorizontal (svg-scroll-draw/horizontal) with no distance and no\n * trigger: it finds the sticky stage, moves the row by its width minus the\n * stage's, and measures again when the window, the page, the row or the section\n * changes size. Its onProgress drives the count and the rail. Before 2.18.1 the\n * row moved by its width minus the window's, so the stage's side padding left\n * the end of the last case off screen.\n *\n * The section is the row's travel plus one screen tall, so a pixel of scroll\n * moves the row a pixel at any width. The stage sticks with CSS\n * `position: sticky`: keep the block out of any ancestor with\n * `overflow: hidden`, and if a reset stops sideways scrolling on html or body,\n * use `overflow-x: clip` there instead. Cards are sized against the stage, not\n * the window, so the block works in a page container as well as full width.\n *\n * Tab reaches every case, including the ones still off to the right: the page\n * scrolls to the point where the focused case is in view.\n *\n * Reduced motion: scrollHorizontal keeps scrubbing on purpose, because holding\n * the row at its end would hide every case but the last. This block has a\n * layout that needs no movement, so visitors who ask for reduced motion get the\n * cases as a plain grid, with no sticky stage, and the block switches over if\n * the setting changes while the page is open.\n *\n * Props: heading, cases (client, title, text, meta, href, and cover: line-art\n * paths in a 200 × 150 box), linkLabel, className (on the outer section).\n */\n\nimport { useEffect, useId, useRef } from 'react';\nimport { scrollHorizontal } from 'svg-scroll-draw/horizontal';\n\nexport interface CaseStudy {\n  /** Who the work was for. Shown before the title, and read after the link text. */\n  client: string;\n  title: string;\n  /** One or two sentences. */\n  text: string;\n  /** Discipline and year, e.g. 'Packaging · 2025'. */\n  meta: string;\n  href: string;\n  /** The cover's line drawing: SVG path `d` strings in a 200 × 150 box, stroked, not filled. */\n  cover: string[];\n}\n\nexport interface HorizontalCaseStripProps {\n  heading?: string;\n  cases?: CaseStudy[];\n  /** Visible text of each case's link. Screen readers also hear the client's name. */\n  linkLabel?: string;\n  /** Classes for the outer section, e.g. a background colour. Not overflow-hidden: it unsticks the stage. */\n  className?: string;\n}\n\nexport const DEFAULT_CASES: CaseStudy[] = [\n  {\n    client: 'Tidewater Ferries',\n    title: 'A timetable you can read from the pier',\n    text: 'Signs and a printed timetable for six crossings, set large enough to read with a bag in each hand.',\n    meta: 'Wayfinding · 2025',\n    href: '/work/tidewater-ferries',\n    cover: [\n      'M 40 92 L 160 92 L 148 108 L 52 108 Z',\n      'M 70 92 V 76 H 128 V 92',\n      'M 112 76 V 62 H 122 V 76',\n      'M 20 122 q 10 -8 20 0 t 20 0 t 20 0 t 20 0 t 20 0 t 20 0 t 20 0 t 20 0',\n    ],\n  },\n  {\n    client: 'Hollow Oak Bakery',\n    title: 'Boxes that survive the bike courier',\n    text: 'A fold-flat box for loaves and tarts, tested on cobbles, that the bakery folds in eleven seconds.',\n    meta: 'Packaging · 2025',\n    href: '/work/hollow-oak-bakery',\n    cover: [\n      'M 60 62 L 100 46 L 140 62 L 140 108 L 100 124 L 60 108 Z',\n      'M 60 62 L 100 78 L 140 62 M 100 78 V 124',\n      'M 82 54 Q 100 34 118 54',\n    ],\n  },\n  {\n    client: 'Northfield Library',\n    title: 'Late returns, without the guilt',\n    text: 'Reminder letters and a returns page rewritten so that people come back instead of staying away.',\n    meta: 'Service design · 2024',\n    href: '/work/northfield-library',\n    cover: [\n      'M 58 50 V 112 H 74 V 50 Z',\n      'M 78 42 V 112 H 92 V 42 Z',\n      'M 100 56 L 113 52 L 130 110 L 117 114 Z',\n      'M 44 112 H 156',\n    ],\n  },\n  {\n    client: 'Meridian Cycling Club',\n    title: 'Route maps that fold into a jersey pocket',\n    text: 'Twelve club routes on one sheet, with the climbs drawn to scale and the cafés where they matter.',\n    meta: 'Print · 2024',\n    href: '/work/meridian-cycling-club',\n    cover: [\n      'M 40 52 L 80 42 L 120 52 L 160 42 V 108 L 120 118 L 80 108 L 40 118 Z',\n      'M 80 42 V 108 M 120 52 V 118',\n      'M 52 100 C 70 80 90 96 104 76 S 138 72 148 58',\n    ],\n  },\n];\n\n/** Custom property on the section that holds the row's travel, in px. */\nconst TRAVEL = '--case-strip-travel';\n\n/** How far the row travels: its width minus the stage's content box. */\nfunction travelOf(stage: HTMLElement, track: HTMLElement): number {\n  const cs = getComputedStyle(stage);\n  const seen = stage.clientWidth - parseFloat(cs.paddingLeft) - parseFloat(cs.paddingRight);\n  return Math.max(0, track.scrollWidth - seen);\n}\n\n/** Focus from the keyboard or a screen reader, not from a pointer. */\nfunction isKeyboardFocus(el: Element): boolean {\n  try {\n    return el.matches(':focus-visible');\n  } catch {\n    // A browser without :focus-visible: keep the keyboard path working.\n    return true;\n  }\n}\n\n/** Starts the strip: runway height, scrub, count, rail and keyboard. Returns its cleanup. */\nfunction startStrip(\n  runway: HTMLElement,\n  stage: HTMLElement,\n  track: HTMLElement,\n  count: HTMLElement | null,\n  fill: HTMLElement | null,\n): () => void {\n  const last = Math.max(0, track.children.length - 1);\n\n  // A pixel of scroll moves the row a pixel: the runway is the row's travel\n  // plus the one screen the stage stays stuck for. Set before scrollHorizontal,\n  // so its first measurement already sees the right runway; after that the\n  // observer keeps the height current, and the strip follows it on its own.\n  const fit = () => runway.style.setProperty(TRAVEL, `${travelOf(stage, track)}px`);\n  fit();\n  const resize = typeof ResizeObserver === 'undefined' ? null : new ResizeObserver(fit);\n  resize?.observe(track);\n  resize?.observe(stage);\n\n  // -1, not 0, so the first call always writes the count, even when a re-run\n  // finds another number left on screen.\n  let shown = -1;\n  const strip = scrollHorizontal(track, {\n    onProgress: (p) => {\n      if (fill) fill.style.transform = `scaleX(${p})`;\n      // The nearest case: with four, it ticks over at 1/6, 1/2 and 5/6.\n      const i = Math.round(p * last);\n      if (i !== shown && count) {\n        count.textContent = String(i + 1).padStart(2, '0');\n        shown = i;\n      }\n    },\n  });\n\n  // The stage cannot scroll (overflow: clip), so a case reached with Tab is\n  // brought into view by scrolling the page to it, on the next frame: the\n  // browser runs its own scroll to the focused link after focusin, and undoes\n  // one made inside the handler.\n  let frame = 0;\n  const onFocus = (e: FocusEvent) => {\n    const target = e.target as Element;\n    // Keyboard focus only. Chrome focuses a link on mousedown, and a row that\n    // moves before mouseup puts the click on the row instead of the link, so\n    // clicking the second case's link did nothing.\n    if (!isKeyboardFocus(target)) return;\n    const item = target.closest('li');\n    if (!item || item.parentElement !== track) return;\n    const travel = travelOf(stage, track);\n    // How far into the row the case starts. Both boxes carry the same\n    // translateX, so it cancels out.\n    const at = item.getBoundingClientRect().left - track.getBoundingClientRect().left;\n    const p = travel > 0 ? Math.min(1, at / travel) : 0;\n    const top = runway.getBoundingClientRect().top + window.scrollY + p * (runway.offsetHeight - window.innerHeight);\n    cancelAnimationFrame(frame);\n    frame = requestAnimationFrame(() => window.scrollTo({ top }));\n  };\n  track.addEventListener('focusin', onFocus);\n\n  return () => {\n    cancelAnimationFrame(frame);\n    track.removeEventListener('focusin', onFocus);\n    resize?.disconnect();\n    // Puts the row's own inline transform back.\n    strip.destroy();\n    runway.style.removeProperty(TRAVEL);\n  };\n}\n\nexport function HorizontalCaseStrip({\n  heading = 'Selected work',\n  cases = DEFAULT_CASES,\n  linkLabel = 'Read the case study',\n  className = '',\n}: HorizontalCaseStripProps) {\n  const headingId = useId();\n  const runwayRef = useRef<HTMLElement>(null);\n  const stageRef = useRef<HTMLDivElement>(null);\n  const trackRef = useRef<HTMLOListElement>(null);\n  const countRef = useRef<HTMLElement>(null);\n  const fillRef = useRef<HTMLSpanElement>(null);\n\n  useEffect(() => {\n    const runway = runwayRef.current;\n    const stage = stageRef.current;\n    const track = trackRef.current;\n    if (!runway || !stage || !track) return;\n\n    // No strip when reduced motion is asked for: the motion-safe: classes\n    // below already leave the cases as a grid. Follows the setting live.\n    const reduce = typeof window.matchMedia === 'function'\n      ? window.matchMedia('(prefers-reduced-motion: reduce)')\n      : null;\n    let stop: (() => void) | undefined;\n    const sync = () => {\n      stop?.();\n      stop = reduce?.matches\n        ? undefined\n        : startStrip(runway, stage, track, countRef.current, fillRef.current);\n    };\n    sync();\n    reduce?.addEventListener('change', sync);\n\n    // StrictMode mounts effects twice in development: the cleanup restores the\n    // row's transform and the section's height, so the second run starts clean.\n    return () => {\n      reduce?.removeEventListener('change', sync);\n      stop?.();\n    };\n    // Re-run only when the number of cases changes: a new array with the same\n    // cases changes nothing the strip measured, and a resize is followed anyway.\n  }, [cases.length]);\n\n  const total = String(cases.length).padStart(2, '0');\n\n  return (\n    // The runway: the scroll room the stage sticks inside. Its height is the\n    // row's travel (set from the effect) plus one screen; svh where supported,\n    // so a phone's collapsing toolbar does not change it.\n    <section\n      ref={runwayRef}\n      aria-labelledby={headingId}\n      className={`text-neutral-950 dark:text-neutral-50 motion-safe:h-[calc(var(--case-strip-travel,200vh)_+_100vh)] motion-safe:supports-[height:100svh]:h-[calc(var(--case-strip-travel,200vh)_+_100svh)] ${className}`}\n    >\n      {/* The stage. overflow-clip, not overflow-hidden: a hidden box can still\n          be scrolled by focus, which shifts the whole row and leaves it\n          shifted. minmax(0,1fr) columns: an auto column would grow to the\n          row's full width and take the header with it. container-type lets the\n          cards size against the stage rather than the window. */}\n      <div\n        ref={stageRef}\n        className=\"box-border grid grid-cols-[minmax(0,1fr)] gap-[clamp(20px,4vh,40px)] px-[6vw] py-[clamp(24px,7vh,72px)] [container-type:inline-size] motion-safe:sticky motion-safe:top-0 motion-safe:h-screen motion-safe:supports-[height:100svh]:h-[100svh] motion-safe:grid-rows-[auto_minmax(0,1fr)] motion-safe:overflow-clip\"\n      >\n        <header className=\"flex items-center gap-4\">\n          <h2 id={headingId} className=\"text-[clamp(24px,3vw,36px)] font-semibold leading-[1.1] tracking-[-0.01em]\">\n            {heading}\n          </h2>\n          {/* Both aria-hidden: the list already tells a screen reader how many\n              cases there are. */}\n          <p\n            aria-hidden=\"true\"\n            className=\"ml-auto flex-none whitespace-nowrap font-mono text-[13px] font-medium leading-none tabular-nums motion-reduce:hidden\"\n          >\n            <b ref={countRef}>01</b> / {total}\n          </p>\n          <span\n            aria-hidden=\"true\"\n            className=\"relative h-0.5 flex-[0_0_min(24vw,200px)] bg-neutral-200 motion-reduce:hidden dark:bg-neutral-800\"\n          >\n            <span ref={fillRef} className=\"absolute inset-0 origin-left bg-current [transform:scaleX(0)]\" />\n          </span>\n        </header>\n\n        {/* The row: as wide as its cases (w-max), so it can be measured and\n            moved, and never narrower than the stage (min-w-full), so a row that\n            already fits is not pushed the wrong way. role=\"list\": Safari drops\n            the list role from a list styled list-style: none, and the count\n            above is hidden on the promise that the list gives it. */}\n        <ol\n          ref={trackRef}\n          role=\"list\"\n          className=\"m-0 grid list-none gap-6 p-0 sm:grid-cols-2 motion-safe:flex motion-safe:w-max motion-safe:min-w-full\"\n        >\n          {cases.map((c, i) => (\n            // Narrower than the stage (cqw: the stage's width, wherever it is\n            // placed), so the next case shows at the edge and the reader can\n            // tell the row goes on.\n            <li\n              key={`${c.client}-${c.title}`}\n              className=\"flex min-h-0 flex-col motion-safe:w-[min(78cqw,520px)]\"\n            >\n              {/* Fills the height the text leaves, down to nothing on a short screen. */}\n              <svg\n                viewBox=\"0 0 200 150\"\n                fill=\"none\"\n                stroke=\"currentColor\"\n                strokeWidth={2}\n                strokeLinecap=\"round\"\n                strokeLinejoin=\"round\"\n                aria-hidden=\"true\"\n                className=\"box-border aspect-[4/3] w-full rounded-2xl border border-neutral-200 bg-white dark:border-neutral-800 dark:bg-neutral-950 motion-safe:aspect-auto motion-safe:min-h-0 motion-safe:flex-[1_1_auto]\"\n              >\n                {c.cover.map((d, j) => (\n                  <path key={j} d={d} />\n                ))}\n              </svg>\n              <p className=\"mt-4 font-mono text-xs font-semibold leading-none text-[#3056d3] dark:text-[#8aa4ff]\">\n                {String(i + 1).padStart(2, '0')} · {c.client}\n              </p>\n              <h3 className=\"mb-1.5 mt-2 text-[clamp(19px,2vw,24px)] font-semibold leading-[1.2]\">{c.title}</h3>\n              <p className=\"max-w-[44ch] text-[15px] leading-[1.55] text-neutral-700 dark:text-neutral-300\">{c.text}</p>\n              <p className=\"mt-2 text-[13px] leading-[1.4] text-neutral-600 dark:text-neutral-400\">{c.meta}</p>\n              <a\n                href={c.href}\n                className=\"mt-2.5 self-start text-[15px] font-medium leading-[1.4] underline underline-offset-[3px] focus-visible:outline-offset-[3px] focus-visible:[outline:2px_solid_#3056d3] dark:focus-visible:[outline-color:#8aa4ff]\"\n              >\n                {linkLabel}\n                <span className=\"sr-only\">: {c.client}</span>\n              </a>\n            </li>\n          ))}\n        </ol>\n      </div>\n    </section>\n  );\n}\n\nexport default HorizontalCaseStrip;\n",
      "type": "registry:component",
      "target": "components/scroll/horizontal-case-strip.tsx"
    }
  ],
  "categories": [
    "scroll",
    "horizontal"
  ]
}
