{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"navy-split-halves-preloader-with-a-wordmark-across-the-seam","type":"registry:block","title":"Navy Split Halves Preloader","description":"","dependencies":[],"files":[{"path":"components/we-inc/navy-split-halves-preloader-with-a-wordmark-across-the-seam.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst MIN = 800; // shortest time the cover shows, in ms\nconst CAP = 1400; // longest the cover waits for images, in ms\nconst EXIT = 850; // length of the exit, in ms\n// On a real page: give the cover position: fixed; inset: 0 and put data-page on your <main>.\n\nconst CSS = `\n  .w2spl { --w2spl-navy: #13203a; --w2spl-gold: #c8a96a; --w2spl-ivory: #f7f3ec; height: 600px; background: var(--w2spl-navy); color: var(--w2spl-ivory); font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; }\n  .w2spl-page { position: relative; height: 100%; display: flex; flex-direction: column; justify-content: space-between; padding: 0 clamp(16px, 4vw, 48px) clamp(16px, 4vw, 44px); }\n  .w2spl-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: scale(1.1); transition: transform 1.8s cubic-bezier(.2,.7,.2,1) .2s; }\n  .w2spl.is-out .w2spl-bg { transform: none; }\n  .w2spl-shade { position: absolute; inset: 0; background: linear-gradient(90deg, rgba(14,24,44,.78), rgba(14,24,44,.15) 70%); }\n  .w2spl-nav, .w2spl-card { position: relative; }\n  .w2spl-nav { display: flex; align-items: center; justify-content: space-between; height: 76px; }\n  .w2spl-brand { color: inherit; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: 20px; letter-spacing: .04em; text-decoration: none; }\n  .w2spl-book { display: inline-flex; align-items: center; min-height: 42px; padding: 0 18px; border-radius: 999px; background: var(--w2spl-ivory); color: var(--w2spl-navy); font-size: 14px; font-weight: 600; text-decoration: none; }\n  .w2spl-card { max-width: 30rem; background: var(--w2spl-ivory); color: var(--w2spl-navy); padding: clamp(20px, 3vw, 32px); border-radius: 4px; box-shadow: 0 30px 60px -30px rgba(0,0,0,.6); transform: translateY(24px); opacity: .001; transition: transform .9s cubic-bezier(.2,.75,.15,1) .45s, opacity .6s ease .45s; }\n  .w2spl.is-out .w2spl-card { transform: none; opacity: 1; }\n  .w2spl-kicker { margin: 0; font-size: 12px; letter-spacing: .2em; text-transform: uppercase; color: #6d5a33; }\n  .w2spl-title { margin: 10px 0 0; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(26px, 3.4vw, 40px); line-height: 1.1; font-weight: 400; }\n  .w2spl-row { display: flex; gap: 14px; align-items: center; margin: 16px 0 18px; }\n  .w2spl-thumb { width: 96px; height: 64px; object-fit: cover; border-radius: 2px; flex: none; }\n  .w2spl-copy { margin: 0; font-size: 15px; line-height: 1.55; color: #3c4658; }\n  .w2spl-replay { border: 1px solid #c9c2b4; background: transparent; color: var(--w2spl-navy); }\n  .w2spl-cover { position: absolute; inset: 0; z-index: 2; }\n  .w2spl-half { position: absolute; left: 0; right: 0; height: 50%; overflow: hidden; background: var(--w2spl-navy); transition: transform .7s cubic-bezier(.55,0,.85,.4) .1s; }\n  .w2spl-top { top: 0; } .w2spl-bot { bottom: 0; }\n  .w2spl.is-out .w2spl-top { transform: translateY(-101%); }\n  .w2spl.is-out .w2spl-bot { transform: translateY(101%); }\n  .w2spl-mark { position: absolute; left: 0; right: 0; margin: 0; height: 1em; line-height: 1; text-align: center; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(80px, 17vw, 220px); letter-spacing: .02em; color: var(--w2spl-ivory); transition: opacity .3s ease .15s; }\n  .w2spl.is-out .w2spl-mark { opacity: 0; }\n  .w2spl-top .w2spl-mark { bottom: -.5em; } .w2spl-bot .w2spl-mark { top: -.5em; }\n  .w2spl-seam { position: absolute; left: 0; right: 0; top: 50%; height: 1px; transition: opacity .2s ease; }\n  .w2spl-seam span { display: block; height: 100%; background: var(--w2spl-gold); transform: scaleX(0); }\n  .w2spl.is-out .w2spl-seam, .w2spl.is-out .w2spl-pct { opacity: 0; }\n  .w2spl-pct { position: absolute; left: 0; right: 0; bottom: 36px; margin: 0; text-align: center; font-size: 13px; letter-spacing: .3em; color: var(--w2spl-gold); font-variant-numeric: tabular-nums; transition: opacity .2s ease; }\n  @media (max-width: 767px) {\n    .w2spl-thumb { width: 76px; height: 54px; }\n    .w2spl-shade { background: linear-gradient(0deg, rgba(14,24,44,.7), rgba(14,24,44,.2)); }\n  }\n\n  .w2spl { position: relative; overflow: hidden; }\n  .w2spl-cover[hidden] { display: none; }\n  .w2spl.is-snap, .w2spl.is-snap * { transition: none !important; }\n  .w2spl[data-paused] * { animation-play-state: paused !important; }\n  .w2spl-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n  .w2spl-replay { display: inline-flex; align-items: center; gap: 8px; min-height: 40px; padding: 0 16px; border-radius: 999px; font: 600 13px/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }\n  .w2spl-replay:focus-visible, .w2spl a:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }\n  @media (prefers-reduced-motion: reduce) {\n    .w2spl *, .w2spl *::before, .w2spl *::after { animation: none !important; transition-duration: 0s !important; transition-delay: 0s !important; }\n    .w2spl .w2spl-cover { transition: opacity .45s ease !important; }\n    .w2spl.is-out .w2spl-cover { opacity: 0; }\n    .w2spl-cover *:not([data-bar]), .w2spl-page * { transform: none !important; opacity: 1; }\n  }\n`;\n\nexport default function NavySplitHalvesPreloader() {\n  const ref = useRef<HTMLElement>(null);\n\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    const page = root.querySelector<HTMLElement>(\"[data-page]\")!;\n    const cover = root.querySelector<HTMLElement>(\"[data-cover]\")!;\n    const live = root.querySelector<HTMLElement>(\"[data-live]\")!;\n    const again = root.querySelector<HTMLButtonElement>(\"[data-replay]\")!;\n    const nums = root.querySelectorAll<HTMLElement>(\"[data-num]\");\n    const bars = root.querySelectorAll<HTMLElement>(\"[data-bar]\");\n    const ticks = root.querySelectorAll<HTMLElement>(\"[data-tick]\");\n    const rm = window.matchMedia(\"(prefers-reduced-motion: reduce)\");\n    let run = 0, frame = 0, seen = true, timer = 0;\n    let step: ((now: number) => void) | null = null;\n    const draw = (v: number) => {\n      const t = String(Math.round(v * 100));\n      nums.forEach((n) => { n.textContent = t; });\n      bars.forEach((b) => { b.style.transform = `scaleX(${v})`; });\n    };\n    const start = (refocus: boolean) => {\n      const id = ++run, t0 = performance.now(), imgs = page.querySelectorAll(\"img\"), total = imgs.length;\n      let done = 0, shown = 0;\n      cancelAnimationFrame(frame);\n      window.clearTimeout(timer);\n      root.classList.add(\"is-snap\");\n      root.classList.remove(\"is-out\");\n      cover.hidden = false;\n      void root.offsetWidth;\n      root.classList.remove(\"is-snap\");\n      page.inert = true;\n      page.setAttribute(\"aria-busy\", \"true\");\n      live.textContent = \"Loading\";\n      ticks.forEach((k) => k.classList.remove(\"is-on\"));\n      // Real progress: one step per image that fires load or error.\n      imgs.forEach((img, i) => {\n        const hit = () => { if (id !== run) return; done++; ticks[i]?.classList.add(\"is-on\"); };\n        if (img.complete) hit();\n        else { img.addEventListener(\"load\", hit, { once: true }); img.addEventListener(\"error\", hit, { once: true }); }\n      });\n      step = (now: number) => {\n        let real = total ? done / total : 1;\n        const t = now - t0;\n        if (t > CAP) real = 1;\n        shown += (real - shown) * (rm.matches ? 1 : 0.2);\n        if (real - shown < 0.004) shown = real;\n        draw(shown);\n        if (shown === 1 && t >= MIN) {\n          step = null;\n          frame = 0;\n          root.classList.add(\"is-out\");\n          live.textContent = \"Page ready\";\n          page.inert = false;\n          page.removeAttribute(\"aria-busy\");\n          timer = window.setTimeout(() => { cover.hidden = true; if (refocus) again.focus(); }, rm.matches ? 500 : EXIT);\n          return;\n        }\n        frame = seen ? requestAnimationFrame(step) : 0;\n      };\n      frame = requestAnimationFrame(step);\n    };\n    // Off screen: stop the frame loop and pause CSS loops.\n    const io = new IntersectionObserver(([e]) => {\n      seen = e.isIntersecting;\n      root.toggleAttribute(\"data-paused\", !seen);\n      if (seen && step && !frame) frame = requestAnimationFrame(step);\n    });\n    io.observe(root);\n    const onReplay = () => start(true);\n    again.addEventListener(\"click\", onReplay);\n    start(false);\n    return () => {\n      run++;\n      cancelAnimationFrame(frame);\n      window.clearTimeout(timer);\n      io.disconnect();\n      again.removeEventListener(\"click\", onReplay);\n    };\n  }, []);\n\n  return (\n    <section ref={ref} className=\"w2spl\">\n      <style>{CSS}</style>\n      <div className=\"w2spl-page\" data-page=\"\" aria-busy={true}>\n        <img className=\"w2spl-bg\" src=\"https://images.pexels.com/photos/7507131/pexels-photo-7507131.jpeg?auto=compress&cs=tinysrgb&w=1600\" alt=\"Hotel room with sheer white curtains drawn across a tall window in soft daylight\" width=\"1600\" height=\"1067\" />\n        <div className=\"w2spl-shade\"></div>\n        <header className=\"w2spl-nav\">\n          <a href=\"#\" className=\"w2spl-brand\">The Calder Rooms</a>\n          <a href=\"#\" className=\"w2spl-book\">Book a room</a>\n        </header>\n        <div className=\"w2spl-card\">\n          <p className=\"w2spl-kicker\">Harbour Road, open all year</p>\n          <h2 className=\"w2spl-title\">Twenty-two quiet rooms above the harbour.</h2>\n          <div className=\"w2spl-row\">\n            <img className=\"w2spl-thumb\" src=\"https://images.pexels.com/photos/11063185/pexels-photo-11063185.jpeg?auto=compress&cs=tinysrgb&w=600\" alt=\"Black and white photo of a made bed beside a window with a framed print of trees\" width=\"600\" height=\"400\" />\n            <p className=\"w2spl-copy\">Linen sheets, a deep bath and breakfast served until eleven.</p>\n          </div>\n          <button type=\"button\" className=\"w2spl-replay\" data-replay=\"\">\n              <svg viewBox=\"0 0 20 20\" width=\"16\" height=\"16\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"1.8\" strokeLinecap=\"round\" strokeLinejoin=\"round\" aria-hidden=\"true\"><path d=\"M4 10a6 6 0 1 0 1.8-4.3\" /><path d=\"M4 3.5v3.2h3.2\" /></svg>\n              Replay intro\n            </button>\n        </div>\n      </div>\n      <div className=\"w2spl-cover\" data-cover=\"\" aria-hidden=\"true\">\n        <div className=\"w2spl-half w2spl-top\"><p className=\"w2spl-mark\">Calder</p></div>\n        <div className=\"w2spl-half w2spl-bot\"><p className=\"w2spl-mark\">Calder</p></div>\n        <span className=\"w2spl-seam\"><span data-bar=\"\"></span></span>\n        <p className=\"w2spl-pct\"><span data-num=\"\">0</span>%</p>\n      </div>\n      <p className=\"w2spl-sr\" data-live=\"\" aria-live=\"polite\"></p>\n    </section>\n  );\n}\n"}]}
