{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"terracotta-double-wipe-preloader-for-a-ceramics-shop","type":"registry:block","title":"Terracotta Double Wipe Preloader","description":"","dependencies":[],"files":[{"path":"components/we-inc/terracotta-double-wipe-preloader-for-a-ceramics-shop.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 = 1100; // 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  .w2wip { --w2wip-front: #3a231a; --w2wip-back: #b4552f; --w2wip-page: #f5ece2; height: 600px; background: var(--w2wip-page); color: #2b1a13; font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; }\n  .w2wip-page { height: 100%; display: flex; flex-direction: column; padding: 0 clamp(16px, 4vw, 48px); }\n  .w2wip-nav { display: flex; align-items: center; justify-content: space-between; height: 72px; }\n  .w2wip-brand { color: var(--w2wip-back); font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: 22px; font-weight: 700; text-decoration: none; }\n  .w2wip-nav ul { display: flex; gap: 26px; margin: 0; padding: 0; list-style: none; }\n  .w2wip-nav ul a { color: #5a4135; font-size: 14px; text-decoration: none; }\n  .w2wip-hero { flex: 1; display: grid; grid-template-columns: 1fr 1.3fr; gap: clamp(20px, 4vw, 56px); align-items: center; min-height: 0; padding-bottom: 24px; }\n  .w2wip-title { margin: 0; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(30px, 4.2vw, 52px); line-height: 1.08; font-weight: 400; }\n  .w2wip-copy { margin: 18px 0 0; font-size: 16px; line-height: 1.6; color: #5a4135; max-width: 28rem; }\n  .w2wip-row { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 26px; }\n  .w2wip-cta { display: inline-flex; align-items: center; min-height: 44px; padding: 0 22px; border-radius: 999px; background: #9e4423; color: #fff8f2; font-size: 14px; font-weight: 600; text-decoration: none; }\n  .w2wip-replay { border: 1px solid #d9c3b2; background: #fffaf5; color: #3a231a; }\n  .w2wip-pics { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }\n  .w2wip-pics figure { margin: 0; }\n  \n  .w2wip-pics img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 4; object-fit: cover; border-radius: 3px; transform: translateY(18px); opacity: .001; transition: transform .9s cubic-bezier(.2,.75,.15,1) .35s, opacity .6s ease .35s; }\n  .w2wip-pics figure + figure img { transition-delay: .48s; margin-top: 36px; }\n  .w2wip.is-out .w2wip-pics img { transform: none; opacity: 1; }\n  .w2wip-pics figcaption { margin-top: 8px; font-size: 13px; color: #6b4e40; }\n  .w2wip-cover { position: absolute; inset: 0; z-index: 2; }\n  .w2wip-back, .w2wip-front { position: absolute; inset: 0; transition: transform .75s cubic-bezier(.75,0,.2,1); }\n  .w2wip-back { background: var(--w2wip-back); transition-delay: .16s; }\n  .w2wip-front { background: var(--w2wip-front); color: #f3e3d6; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 14px; }\n  .w2wip.is-out .w2wip-back, .w2wip.is-out .w2wip-front { transform: translateX(101%); }\n  .w2wip-word { margin: 0; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(48px, 9vw, 104px); font-weight: 700; letter-spacing: -.02em; }\n  .w2wip-pct { margin: 0; font-size: 13px; letter-spacing: .18em; text-transform: uppercase; color: #d9b9a4; font-variant-numeric: tabular-nums; }\n  @media (max-width: 767px) {\n    .w2wip-nav ul li:not(:first-child) { display: none; }\n    .w2wip-hero { grid-template-columns: 1fr; align-content: start; gap: 20px; }\n    .w2wip-pics img { aspect-ratio: 4 / 3; }\n    .w2wip-pics figure + figure img { margin-top: 0; }\n    .w2wip-copy { font-size: 15px; margin-top: 12px; }\n    .w2wip-row { margin-top: 18px; }\n  }\n\n  .w2wip { position: relative; overflow: hidden; }\n  .w2wip-cover[hidden] { display: none; }\n  .w2wip.is-snap, .w2wip.is-snap * { transition: none !important; }\n  .w2wip[data-paused] * { animation-play-state: paused !important; }\n  .w2wip-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n  .w2wip-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  .w2wip-replay:focus-visible, .w2wip a:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }\n  @media (prefers-reduced-motion: reduce) {\n    .w2wip *, .w2wip *::before, .w2wip *::after { animation: none !important; transition-duration: 0s !important; transition-delay: 0s !important; }\n    .w2wip .w2wip-cover { transition: opacity .45s ease !important; }\n    .w2wip.is-out .w2wip-cover { opacity: 0; }\n    .w2wip-cover *:not([data-bar]), .w2wip-page * { transform: none !important; opacity: 1; }\n  }\n`;\n\nexport default function TerracottaDoubleWipePreloader() {\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=\"w2wip\">\n      <style>{CSS}</style>\n      <div className=\"w2wip-page\" data-page=\"\" aria-busy={true}>\n        <header className=\"w2wip-nav\">\n          <a href=\"#\" className=\"w2wip-brand\">Clayhouse</a>\n          <nav aria-label=\"Shop\"><ul><li><a href=\"#\">Vases</a></li><li><a href=\"#\">Tableware</a></li><li><a href=\"#\">Classes</a></li></ul></nav>\n        </header>\n        <div className=\"w2wip-hero\">\n          <div>\n            <h2 className=\"w2wip-title\">Stoneware thrown and glazed by hand on Hollis Street.</h2>\n            <p className=\"w2wip-copy\">New vases come out of the kiln every second Friday. Each one is signed on the foot.</p>\n            <div className=\"w2wip-row\"><a href=\"#\" className=\"w2wip-cta\">Shop this firing</a><button type=\"button\" className=\"w2wip-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=\"w2wip-pics\">\n            <figure><img src=\"https://images.pexels.com/photos/15122643/pexels-photo-15122643.jpeg?auto=compress&cs=tinysrgb&w=1200\" alt=\"Rows of matte white ceramic vases in different shapes on a wooden shelf\" width=\"1200\" height=\"800\" /><figcaption>White matte, tall forms</figcaption></figure>\n            <figure><img src=\"https://images.pexels.com/photos/8063872/pexels-photo-8063872.jpeg?auto=compress&cs=tinysrgb&w=1200\" alt=\"Glazed white vases and jugs lined up on a pottery studio shelf\" width=\"1200\" height=\"800\" /><figcaption>Gloss glaze, small jugs</figcaption></figure>\n          </div>\n        </div>\n      </div>\n      <div className=\"w2wip-cover\" data-cover=\"\" aria-hidden=\"true\">\n        <span className=\"w2wip-back\"></span>\n        <div className=\"w2wip-front\">\n          <p className=\"w2wip-word\">Clayhouse</p>\n          <p className=\"w2wip-pct\">Unloading the kiln <span data-num=\"\">0</span>%</p>\n        </div>\n      </div>\n      <p className=\"w2wip-sr\" data-live=\"\" aria-live=\"polite\"></p>\n    </section>\n  );\n}\n"}]}
