{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"graphite-shutter-preloader-for-an-architecture-practice","type":"registry:block","title":"Graphite Shutter Preloader","description":"","dependencies":[],"files":[{"path":"components/we-inc/graphite-shutter-preloader-for-an-architecture-practice.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst MIN = 900; // shortest time the cover shows, in ms\nconst CAP = 1500; // longest the cover waits for images, in ms\nconst EXIT = 1000; // 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  .w2shu { --w2shu-cover: #26282b; --w2shu-page: #eceae6; --w2shu-ink: #1d1f22; height: 600px; background: var(--w2shu-page); color: var(--w2shu-ink); font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; }\n  .w2shu-page { height: 100%; display: flex; flex-direction: column; padding: 0 clamp(16px, 4vw, 48px); }\n  .w2shu-nav { display: flex; align-items: center; justify-content: space-between; height: 72px; border-bottom: 1px solid #d3d0ca; }\n  .w2shu-brand { color: inherit; font-weight: 700; letter-spacing: .02em; text-decoration: none; }\n  .w2shu-nav ul { display: flex; gap: 28px; margin: 0; padding: 0; list-style: none; }\n  .w2shu-nav ul a { color: #4a4d52; font-size: 14px; text-decoration: none; }\n  .w2shu-hero { flex: 1; display: grid; grid-template-columns: 1fr 1.15fr; gap: clamp(20px, 4vw, 56px); align-items: center; padding: 28px 0; min-height: 0; }\n  .w2shu-kicker { margin: 0; font-size: 12px; letter-spacing: .22em; text-transform: uppercase; color: #5d6066; }\n  .w2shu-title { margin: 16px 0 0; font-size: clamp(30px, 4.4vw, 54px); line-height: 1.04; letter-spacing: -.03em; font-weight: 600; }\n  .w2shu-copy { margin: 18px 0 0; max-width: 30rem; font-size: 16px; line-height: 1.6; color: #4a4d52; }\n  .w2shu-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 28px; }\n  .w2shu-cta { display: inline-flex; align-items: center; min-height: 44px; padding: 0 22px; background: var(--w2shu-ink); color: #f4f2ee; border-radius: 2px; font-size: 14px; font-weight: 600; text-decoration: none; }\n  .w2shu-replay { border: 1px solid #b9b5ae; background: transparent; color: var(--w2shu-ink); }\n  .w2shu-pics { position: relative; height: 100%; max-height: 430px; }\n  .w2shu-pics img { position: absolute; object-fit: cover; display: block; box-shadow: 0 24px 50px -24px rgba(20,20,22,.45); }\n  .w2shu-a { inset: 0 18% 14% 0; width: 82%; height: 86%; }\n  .w2shu-b { right: 0; bottom: 0; width: 44%; height: 42%; border: 6px solid var(--w2shu-page); }\n  .w2shu-pics img { transform: scale(1.06); transition: transform 1.4s cubic-bezier(.2,.7,.2,1) .3s; }\n  .w2shu.is-out .w2shu-pics img { transform: none; }\n  .w2shu-cover { position: absolute; inset: 0; display: flex; z-index: 2; }\n  .w2shu-slat { flex: 1; height: 100%; background: var(--w2shu-cover); transition: transform .7s cubic-bezier(.7,0,.25,1); }\n  .w2shu-slat + .w2shu-slat { box-shadow: inset 1px 0 rgba(255,255,255,.04); }\n  .w2shu-slat:nth-child(2) { transition-delay: .05s; } .w2shu-slat:nth-child(3) { transition-delay: .1s; }\n  .w2shu-slat:nth-child(4) { transition-delay: .15s; } .w2shu-slat:nth-child(5) { transition-delay: .2s; } .w2shu-slat:nth-child(6) { transition-delay: .25s; }\n  .w2shu.is-out .w2shu-slat:nth-child(odd) { transform: translateY(-101%); }\n  .w2shu.is-out .w2shu-slat:nth-child(even) { transform: translateY(101%); }\n  .w2shu-mark { position: absolute; left: clamp(16px, 4vw, 48px); right: clamp(16px, 4vw, 48px); bottom: 40px; color: #e9e6e0; transition: opacity .25s ease, transform .4s ease; }\n  .w2shu.is-out .w2shu-mark { opacity: 0; transform: translateY(-12px); }\n  .w2shu-name { margin: 0; font-size: 13px; letter-spacing: .3em; text-transform: uppercase; color: #a9a6a0; }\n  .w2shu-count { margin: 6px 0 14px; font-size: clamp(56px, 9vw, 112px); font-weight: 300; line-height: 1; letter-spacing: -.04em; font-variant-numeric: tabular-nums; }\n  .w2shu-line { display: block; height: 1px; background: rgba(233,230,224,.18); }\n  .w2shu-line span { display: block; height: 100%; background: #e9e6e0; transform: scaleX(0); transform-origin: left; }\n  @media (max-width: 767px) {\n    .w2shu-nav ul li:not(:last-child) { display: none; }\n    .w2shu-hero { grid-template-columns: 1fr; align-content: start; gap: 22px; padding-top: 22px; }\n    .w2shu-pics { height: 170px; }\n    .w2shu-b { display: none; }\n    .w2shu-a { inset: 0; width: 100%; height: 100%; }\n    .w2shu-copy { font-size: 15px; }\n  }\n\n  .w2shu { position: relative; overflow: hidden; }\n  .w2shu-cover[hidden] { display: none; }\n  .w2shu.is-snap, .w2shu.is-snap * { transition: none !important; }\n  .w2shu[data-paused] * { animation-play-state: paused !important; }\n  .w2shu-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n  .w2shu-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  .w2shu-replay:focus-visible, .w2shu a:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }\n  @media (prefers-reduced-motion: reduce) {\n    .w2shu *, .w2shu *::before, .w2shu *::after { animation: none !important; transition-duration: 0s !important; transition-delay: 0s !important; }\n    .w2shu .w2shu-cover { transition: opacity .45s ease !important; }\n    .w2shu.is-out .w2shu-cover { opacity: 0; }\n    .w2shu-cover *:not([data-bar]), .w2shu-page * { transform: none !important; opacity: 1; }\n  }\n`;\n\nexport default function GraphiteShutterPreloader() {\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=\"w2shu\">\n      <style>{CSS}</style>\n      <div className=\"w2shu-page\" data-page=\"\" aria-busy={true}>\n        <header className=\"w2shu-nav\">\n          <a href=\"#\" className=\"w2shu-brand\">Ostrander Hale</a>\n          <nav aria-label=\"Main\"><ul><li><a href=\"#\">Houses</a></li><li><a href=\"#\">Practice</a></li><li><a href=\"#\">Contact</a></li></ul></nav>\n        </header>\n        <div className=\"w2shu-hero\">\n          <div className=\"w2shu-text\">\n            <p className=\"w2shu-kicker\">Architects, Wellington Road</p>\n            <h2 className=\"w2shu-title\">Houses drawn around the light they get.</h2>\n            <p className=\"w2shu-copy\">We design new homes and quiet extensions, from the first site visit to the last coat of limewash.</p>\n            <div className=\"w2shu-row\"><a href=\"#\" className=\"w2shu-cta\">See recent houses</a><button type=\"button\" className=\"w2shu-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></div>\n          </div>\n          <div className=\"w2shu-pics\">\n            <img className=\"w2shu-a\" src=\"https://images.pexels.com/photos/18273285/pexels-photo-18273285.jpeg?auto=compress&cs=tinysrgb&w=1200\" alt=\"Two-storey modern house with dark cladding and white render behind young trees\" width=\"1200\" height=\"800\" />\n            <img className=\"w2shu-b\" src=\"https://images.pexels.com/photos/7031622/pexels-photo-7031622.jpeg?auto=compress&cs=tinysrgb&w=1200\" alt=\"Open plan room with a concrete floor and wide windows facing a lake\" width=\"1200\" height=\"800\" />\n          </div>\n        </div>\n      </div>\n      <div className=\"w2shu-cover\" data-cover=\"\" aria-hidden=\"true\">\n        <span className=\"w2shu-slat\"></span><span className=\"w2shu-slat\"></span><span className=\"w2shu-slat\"></span><span className=\"w2shu-slat\"></span><span className=\"w2shu-slat\"></span><span className=\"w2shu-slat\"></span>\n        <div className=\"w2shu-mark\">\n          <p className=\"w2shu-name\">Ostrander Hale</p>\n          <p className=\"w2shu-count\"><span data-num=\"\">0</span>%</p>\n          <span className=\"w2shu-line\"><span data-bar=\"\"></span></span>\n        </div>\n      </div>\n      <p className=\"w2shu-sr\" data-live=\"\" aria-live=\"polite\"></p>\n    </section>\n  );\n}\n"}]}
