{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"split-columns-slide-in-opposite-directions","type":"registry:block","title":"Split Columns Slide in Opposite Directions","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/split-columns-slide-in-opposite-directions.tsx","type":"registry:component","content":"import { useEffect, useLayoutEffect, useRef, useState, type MouseEvent } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// Same styles as the plain HTML version; the comment at the top of STYLES names the values to change.\nconst STYLES = `\n  /* Change these: --w6col-paper, --w6col-ink, --w6col-blue (accent), the 48px and 30% travel in the\n     w6col keyframes, and the .55s durations. */\n  .w6col { --w6col-paper: #fafaf9; --w6col-ink: #1e293b; --w6col-blue: #35577a;\n    height: 620px; display: flex; flex-direction: column; background: var(--w6col-paper); color: var(--w6col-ink);\n    font-family: ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; overflow: hidden; }\n  .w6col *, .w6col *::before { box-sizing: border-box; }\n  .w6col-top { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 6px 24px; padding: 16px clamp(16px, 4.5vw, 52px); border-bottom: 1px solid #e2e8f0; }\n  .w6col-brand { margin: 0; font-size: 1rem; font-weight: 700; letter-spacing: -.01em; }\n  .w6col-brand span { font-weight: 400; color: #475569; }\n  .w6col-nav { display: flex; gap: 2px; margin: 0 -12px; padding: 0; list-style: none; }\n  .w6col-nav a { display: inline-flex; align-items: center; min-height: 40px; padding: 0 12px; border-radius: 999px; color: #475569; font-size: .9375rem; text-decoration: none; }\n  .w6col-nav a:hover { color: var(--w6col-ink); }\n  .w6col-nav a[aria-current=\"page\"] { background: #e8eef5; color: var(--w6col-blue); font-weight: 600; }\n  .w6col a:focus-visible, .w6col h2:focus-visible { outline: 2px solid var(--w6col-blue); outline-offset: 3px; }\n  .w6col h2:focus { outline: none; }\n  .w6col-stage { flex: 1; min-height: 0; overflow-y: auto; overflow-x: hidden; }\n  .w6col-view { display: flex; flex-direction: column-reverse; }\n  .w6col-view[hidden] { display: none; }\n  .w6col-pic { height: 210px; overflow: hidden; background: #e2e8f0; }\n  .w6col-pic img { display: block; width: 100%; height: 100%; object-fit: cover; }\n  .w6col-txt { padding: 22px clamp(16px, 4.5vw, 52px) 28px; background: var(--w6col-paper); }\n  .w6col-num { margin: 0; font-size: .8125rem; font-weight: 700; letter-spacing: .12em; color: var(--w6col-blue); font-variant-numeric: tabular-nums; }\n  .w6col h2 { margin: 8px 0 0; font-size: clamp(1.6rem, 3.4vw, 2.5rem); font-weight: 650; line-height: 1.08; letter-spacing: -.025em; max-width: 15ch; }\n  .w6col-txt > p:not(.w6col-num) { margin: 14px 0 0; max-width: 30rem; font-size: 1rem; line-height: 1.6; color: #475569; }\n  .w6col-list { margin: 18px 0 0; padding: 0; list-style: none; display: grid; gap: 8px; }\n  .w6col-list li { display: flex; gap: 10px; font-size: .9375rem; }\n  .w6col-list li::before { content: \"\"; flex: none; width: 6px; height: 6px; margin-top: .55em; border-radius: 50%; background: var(--w6col-blue); }\n  .w6col-more { display: inline-flex; align-items: center; min-height: 44px; margin-top: 20px; padding: 0 20px; border-radius: 999px; background: var(--w6col-ink); color: #fff; font-size: .875rem; font-weight: 600; text-decoration: none; }\n  .w6col-more:hover { background: var(--w6col-blue); }\n  @media (min-width: 820px) {\n    .w6col-stage { overflow: hidden; }\n    .w6col-view { height: 100%; flex-direction: row; }\n    .w6col-txt { flex: 1.1; align-self: center; padding: 32px 52px; }\n    .w6col-pic { flex: 1; height: 100%; }\n  }\n\n  /* Two named columns, named only while the page changes. Going forward the text rises and the photo falls,\n     going back they swap directions; each group clips its own snapshot so nothing spills over the header.\n     Separate pages: add  @view-transition { navigation: auto; }  and give both columns these names on every page. */\n  ::view-transition-group(w6col-text), ::view-transition-group(w6col-pic) { animation: none; overflow: clip; }\n  ::view-transition-old(w6col-text), ::view-transition-new(w6col-text), ::view-transition-old(w6col-pic), ::view-transition-new(w6col-pic) { mix-blend-mode: normal; }\n  ::view-transition-old(w6col-text) { animation: w6col-up-out .3s cubic-bezier(.4, 0, .6, 1) both; }\n  ::view-transition-new(w6col-text) { animation: w6col-up-in .55s .1s cubic-bezier(.2, .8, .2, 1) both; }\n  ::view-transition-old(w6col-pic) { animation: w6col-down-out .55s cubic-bezier(.6, 0, .3, 1) both; }\n  ::view-transition-new(w6col-pic) { animation: w6col-down-in .55s cubic-bezier(.6, 0, .3, 1) both; }\n  :root[data-w6col-dir=\"b\"]::view-transition-old(w6col-text) { animation-name: w6col-down-fade; }\n  :root[data-w6col-dir=\"b\"]::view-transition-new(w6col-text) { animation-name: w6col-down-text; }\n  :root[data-w6col-dir=\"b\"]::view-transition-old(w6col-pic) { animation-name: w6col-up-pic; }\n  :root[data-w6col-dir=\"b\"]::view-transition-new(w6col-pic) { animation-name: w6col-up-from; }\n  @keyframes w6col-up-out { to { opacity: 0; transform: translateY(-48px); } }\n  @keyframes w6col-up-in { from { opacity: 0; transform: translateY(48px); } }\n  @keyframes w6col-down-fade { to { opacity: 0; transform: translateY(48px); } }\n  @keyframes w6col-down-text { from { opacity: 0; transform: translateY(-48px); } }\n  @keyframes w6col-down-out { to { transform: translateY(100%); } }\n  @keyframes w6col-down-in { from { transform: translateY(-100%); } }\n  @keyframes w6col-up-pic { to { transform: translateY(-100%); } }\n  @keyframes w6col-up-from { from { transform: translateY(100%); } }\n  /* Fallback without view transitions: the new columns arrive from opposite sides. */\n  .w6col[data-fb] .w6col-view:not([hidden]) .w6col-txt { animation: w6col-up-in .5s cubic-bezier(.2, .8, .2, 1) both; }\n  .w6col[data-fb] .w6col-view:not([hidden]) .w6col-pic img { animation: w6col-settle .6s cubic-bezier(.2, .8, .2, 1) both; }\n  @keyframes w6col-settle { from { opacity: 0; transform: scale(1.08); } }\n  @media (prefers-reduced-motion: reduce) {\n    ::view-transition-group(w6col-text), ::view-transition-group(w6col-pic), ::view-transition-old(w6col-text), ::view-transition-new(w6col-text),\n    ::view-transition-old(w6col-pic), ::view-transition-new(w6col-pic) { animation: none; }\n    .w6col .w6col-txt, .w6col .w6col-pic img { animation: none !important; }\n  }\n`;\n\nconst PAGES = [\n  { nav: \"Kitchens\", title: \"Kitchens made to the inch\", more: \"Next: Wardrobes\",\n    text: \"Painted shaker doors on oak carcasses, worktops cut from a single board where the room allows, and drawers that run on hardwood.\",\n    list: [\"Survey and drawings in two weeks\", \"Fitted by the people who made it\", \"From £14,000\"],\n    src: \"https://images.pexels.com/photos/7746657/pexels-photo-7746657.jpeg?auto=compress&cs=tinysrgb&w=900\",\n    alt: \"A kitchen with grey panelled cabinets, a wooden worktop and a steel sink\" },\n  { nav: \"Wardrobes\", title: \"Wardrobes that use the whole wall\", more: \"Next: Staircases\",\n    text: \"Built into alcoves, under eaves and around chimney breasts, with the inside planned around what you actually hang and fold.\",\n    list: [\"Doors to the ceiling, no gaps to dust\", \"Lights that come on as a door opens\", \"From £3,800\"],\n    src: \"https://images.pexels.com/photos/31759521/pexels-photo-31759521.jpeg?auto=compress&cs=tinysrgb&w=900\",\n    alt: \"A wall of fitted grey wardrobes with drawers and an open shelf, beside a tall window\" },\n  { nav: \"Staircases\", title: \"Stairs you notice on the way up\", more: \"Back to Kitchens\",\n    text: \"New oak treads over an old frame, or a whole new flight with a handrail turned in the workshop and fitted in one day.\",\n    list: [\"Oak, ash or painted pine\", \"Drawings made in the workshop\", \"From £6,500\"],\n    src: \"https://images.pexels.com/photos/13005094/pexels-photo-13005094.jpeg?auto=compress&cs=tinysrgb&w=900\",\n    alt: \"A light oak staircase with a curving black iron railing against a white wall\" },\n];\nconst DEMO = [700, 1700, 3000]; // idle demo: ms before each automatic page change; [] turns it off\nconst useIso = typeof window !== \"undefined\" ? useLayoutEffect : useEffect;\n\n// Gives (or takes away) each column of a view its view-transition-name from data-vt.\nconst tag = (v: Element | null, on: boolean) => v?.querySelectorAll<HTMLElement>(\"[data-vt]\").forEach((n) => {\n  if (on) n.style.setProperty(\"view-transition-name\", n.dataset.vt!); else n.style.removeProperty(\"view-transition-name\");\n});\n\nexport default function SplitColumnsSlideInOppositeDirections() {\n  const reduce = useReducedMotion();\n  const [cur, setCur] = useState(0);\n  const [fb, setFb] = useState(false);\n  const rootRef = useRef<HTMLDivElement>(null);\n  const stageRef = useRef<HTMLDivElement>(null);\n  const views = useRef<(HTMLElement | null)[]>([]);\n  const heads = useRef<(HTMLHeadingElement | null)[]>([]);\n  const st = useRef({ cur: 0, busy: false, auto: DEMO.length > 0 });\n  const afterCommit = useRef<null | (() => void)>(null);\n\n  useIso(() => { const f = afterCommit.current; afterCommit.current = null; f?.(); }, [cur]);\n\n  const go = (i: number, person: boolean) => {\n    const s = st.current;\n    if (i === s.cur || s.busy) return;\n    const dir = i > s.cur ? \"f\" : \"b\", was = views.current[s.cur];\n    s.cur = i;\n    const landed = () => {\n      if (stageRef.current) stageRef.current.scrollTop = 0;\n      if (person) heads.current[i]?.focus({ preventScroll: true });\n    };\n    const doc = document as any;\n    if (reduce || matchMedia(\"(prefers-reduced-motion: reduce)\").matches) { afterCommit.current = landed; setCur(i); return; }\n    if (doc.startViewTransition) {\n      s.busy = true;\n      tag(was, true);\n      const html = document.documentElement;\n      html.setAttribute(\"data-w6col-dir\", dir);\n      doc.startViewTransition(() => new Promise<void>((done) => {\n        afterCommit.current = () => { tag(was, false); tag(views.current[i], true); landed(); done(); };\n        setCur(i);\n      })).finished.finally(() => { tag(views.current[i], false); html.removeAttribute(\"data-w6col-dir\"); s.busy = false; });\n    } else { afterCommit.current = landed; setFb(true); setCur(i); }\n  };\n  const goRef = useRef(go);\n  goRef.current = go;\n\n  // Idle demo: changes page now and then while the piece is on screen and nobody has used it.\n  useEffect(() => {\n    const root = rootRef.current;\n    if (!root || reduce || !DEMO.length) return;\n    let timer = 0, turns = 0, seen = false;\n    const tick = () => {\n      timer = 0;\n      if (!st.current.auto || !seen) return;\n      goRef.current((st.current.cur + 1) % PAGES.length, false);\n      turns++;\n      timer = window.setTimeout(tick, DEMO[Math.min(turns, DEMO.length - 1)]);\n    };\n    // The demo waits for the page to finish loading, so the first thing anyone sees is the resting view.\n    const kick = () => { if (seen && st.current.auto && !timer && document.readyState === \"complete\") timer = window.setTimeout(tick, DEMO[Math.min(turns, DEMO.length - 1)]); };\n    window.addEventListener(\"load\", kick);\n    const io = new IntersectionObserver((e) => {\n      seen = e[0].isIntersecting;\n      if (seen) kick(); else { clearTimeout(timer); timer = 0; }\n    });\n    io.observe(root);\n    const stop = () => { st.current.auto = false; };\n    root.addEventListener(\"pointerdown\", stop);\n    root.addEventListener(\"keydown\", stop);\n    return () => { io.disconnect(); clearTimeout(timer); window.removeEventListener(\"load\", kick); root.removeEventListener(\"pointerdown\", stop); root.removeEventListener(\"keydown\", stop); };\n  }, [reduce]);\n\n  const link = (i: number) => (e: MouseEvent) => { e.preventDefault(); st.current.auto = false; go(i, true); };\n\n  return (\n    <div className=\"w6col\" ref={rootRef} data-fb={fb ? \"\" : undefined}>\n      <style>{STYLES}</style>\n      <header className=\"w6col-top\">\n        <p className=\"w6col-brand\">Cobble &amp; Finch <span>Joinery</span></p>\n        <nav aria-label=\"Joinery pages\">\n          <ul className=\"w6col-nav\">\n            {PAGES.map((p, i) => (\n              <li key={p.nav}><a href=\"#\" onClick={link(i)} aria-current={i === cur ? \"page\" : undefined}>{p.nav}</a></li>\n            ))}\n          </ul>\n        </nav>\n      </header>\n      <div className=\"w6col-stage\" ref={stageRef}>\n        {PAGES.map((p, i) => (\n          <section key={p.nav} className=\"w6col-view\" aria-labelledby={`w6col-h${i}`} hidden={i !== cur} ref={(el) => { views.current[i] = el; }}>\n            <div className=\"w6col-txt\" data-vt=\"w6col-text\">\n              <p className=\"w6col-num\" aria-hidden=\"true\">{String(i + 1).padStart(2, \"0\")}</p>\n              <h2 id={`w6col-h${i}`} tabIndex={-1} ref={(el) => { heads.current[i] = el; }}>{p.title}</h2>\n              <p>{p.text}</p>\n              <ul className=\"w6col-list\">{p.list.map((l) => <li key={l}>{l}</li>)}</ul>\n              <a className=\"w6col-more\" href=\"#\" onClick={link((i + 1) % PAGES.length)}>{p.more}</a>\n            </div>\n            <div className=\"w6col-pic\" data-vt=\"w6col-pic\"><img src={p.src} alt={p.alt} width={600} height={900} /></div>\n          </section>\n        ))}\n      </div>\n    </div>\n  );\n}\n"}]}
