{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"bakery-layered-lift-preloader-with-three-stacked-colours","type":"registry:block","title":"Bakery Layered Lift Preloader","description":"","dependencies":[],"files":[{"path":"components/we-inc/bakery-layered-lift-preloader-with-three-stacked-colours.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  .w2stk { --w2stk-rye: #3b2517; --w2stk-crust: #c7843f; --w2stk-flour: #f3e9d6; height: 600px; background: var(--w2stk-flour); color: #2c1c11; font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; }\n  .w2stk-page { height: 100%; display: flex; flex-direction: column; padding: 0 clamp(16px, 4vw, 48px); }\n  .w2stk-nav { display: flex; align-items: center; justify-content: space-between; gap: 12px; height: 72px; }\n  .w2stk-brand { color: inherit; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: 20px; font-weight: 700; text-decoration: none; }\n  .w2stk-link { display: inline-flex; align-items: center; min-height: 40px; color: #8a4b17; font-size: 14px; font-weight: 600; text-underline-offset: 4px; }\n  .w2stk-hero { flex: 1; display: grid; grid-template-columns: 1fr 1.1fr; gap: clamp(20px, 4vw, 56px); align-items: center; min-height: 0; padding-bottom: 24px; }\n  .w2stk-title { margin: 0; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(32px, 4.6vw, 58px); line-height: 1.02; font-weight: 700; letter-spacing: -.015em; }\n  .w2stk-copy { margin: 16px 0 0; font-size: 16px; line-height: 1.6; color: #5a4331; max-width: 28rem; }\n  .w2stk-hours { display: flex; gap: 28px; margin: 20px 0 22px; }\n  .w2stk-hours dt { font-size: 12px; letter-spacing: .14em; text-transform: uppercase; color: #7a5a3f; }\n  .w2stk-hours dd { margin: 4px 0 0; font-size: 15px; font-weight: 600; }\n  .w2stk-replay { border: 1px solid #d8c19e; background: #fbf5ea; color: #2c1c11; }\n  .w2stk-pics { position: relative; height: 100%; max-height: 440px; }\n  .w2stk-pics img { position: absolute; object-fit: cover; display: block; border-radius: 4px; }\n  .w2stk-a { top: 0; right: 0; width: 86%; height: 78%; transform: translateY(30px); transition: transform 1.1s cubic-bezier(.2,.75,.15,1) .5s; }\n  .w2stk-b { left: 0; bottom: 0; width: 46%; height: 40%; border: 6px solid var(--w2stk-flour); box-shadow: 0 20px 40px -18px rgba(60,35,15,.5); transform: translateY(60px); transition: transform 1.1s cubic-bezier(.2,.75,.15,1) .6s; }\n  .w2stk.is-out .w2stk-a, .w2stk.is-out .w2stk-b { transform: none; }\n  .w2stk-cover { position: absolute; inset: 0; z-index: 2; }\n  .w2stk-l1, .w2stk-l2, .w2stk-l3 { position: absolute; inset: 0; transition: transform .8s cubic-bezier(.76,0,.24,1); }\n  .w2stk-l3 { background: var(--w2stk-flour); transition-delay: .26s; box-shadow: 0 10px 0 #e2d3b8; }\n  .w2stk-l2 { background: var(--w2stk-crust); transition-delay: .13s; }\n  .w2stk-l1 { background: var(--w2stk-rye); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--w2stk-flour); }\n  .w2stk.is-out .w2stk-l1, .w2stk.is-out .w2stk-l2, .w2stk.is-out .w2stk-l3 { transform: translateY(-104%); }\n  .w2stk-word { margin: 0; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(44px, 9vw, 110px); font-weight: 700; letter-spacing: -.02em; text-align: center; line-height: 1; padding: 0 16px; }\n  .w2stk-pct { margin: 0; font-size: 13px; letter-spacing: .2em; text-transform: uppercase; color: #e0c39b; font-variant-numeric: tabular-nums; }\n  @media (max-width: 767px) {\n    .w2stk-nav { height: 64px; }\n    .w2stk-brand { font-size: 17px; }\n    .w2stk-hero { grid-template-columns: 1fr; align-content: start; gap: 18px; }\n    .w2stk-pics { height: 160px; order: -1; }\n    .w2stk-b { display: none; }\n    .w2stk-a { width: 100%; height: 100%; }\n    .w2stk-copy { font-size: 15px; margin-top: 12px; }\n    .w2stk-hours { margin: 14px 0 16px; }\n  }\n\n  .w2stk { position: relative; overflow: hidden; }\n  .w2stk-cover[hidden] { display: none; }\n  .w2stk.is-snap, .w2stk.is-snap * { transition: none !important; }\n  .w2stk[data-paused] * { animation-play-state: paused !important; }\n  .w2stk-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n  .w2stk-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  .w2stk-replay:focus-visible, .w2stk a:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }\n  @media (prefers-reduced-motion: reduce) {\n    .w2stk *, .w2stk *::before, .w2stk *::after { animation: none !important; transition-duration: 0s !important; transition-delay: 0s !important; }\n    .w2stk .w2stk-cover { transition: opacity .45s ease !important; }\n    .w2stk.is-out .w2stk-cover { opacity: 0; }\n    .w2stk-cover *:not([data-bar]), .w2stk-page * { transform: none !important; opacity: 1; }\n  }\n`;\n\nexport default function BakeryLayeredLiftPreloader() {\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=\"w2stk\">\n      <style>{CSS}</style>\n      <div className=\"w2stk-page\" data-page=\"\" aria-busy={true}>\n        <header className=\"w2stk-nav\">\n          <a href=\"#\" className=\"w2stk-brand\">Bramble Street Bakery</a>\n          <a href=\"#\" className=\"w2stk-link\">Order for Saturday</a>\n        </header>\n        <div className=\"w2stk-hero\">\n          <div className=\"w2stk-text\">\n            <h2 className=\"w2stk-title\">Sourdough out of the oven by seven.</h2>\n            <p className=\"w2stk-copy\">Country loaves, rye and a short list of pastries, baked through the night in a stone deck oven.</p>\n            <dl className=\"w2stk-hours\"><div><dt>Tue to Fri</dt><dd>7 am to 3 pm</dd></div><div><dt>Sat and Sun</dt><dd>8 am to 1 pm</dd></div></dl>\n            <button type=\"button\" className=\"w2stk-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 className=\"w2stk-pics\">\n            <img className=\"w2stk-a\" src=\"https://images.pexels.com/photos/1383908/pexels-photo-1383908.jpeg?auto=compress&cs=tinysrgb&w=1200\" alt=\"Rows of crusty rustic bread loaves stacked on a wooden board\" width=\"1200\" height=\"800\" />\n            <img className=\"w2stk-b\" src=\"https://images.pexels.com/photos/10481790/pexels-photo-10481790.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"Round loaves baking on the shelves of a lit commercial oven\" width=\"800\" height=\"530\" />\n          </div>\n        </div>\n      </div>\n      <div className=\"w2stk-cover\" data-cover=\"\" aria-hidden=\"true\">\n        <span className=\"w2stk-l3\"></span>\n        <span className=\"w2stk-l2\"></span>\n        <div className=\"w2stk-l1\">\n          <p className=\"w2stk-word\">Bramble Street</p>\n          <p className=\"w2stk-pct\">Warming the oven <span data-num=\"\">0</span>%</p>\n        </div>\n      </div>\n      <p className=\"w2stk-sr\" data-live=\"\" aria-live=\"polite\"></p>\n    </section>\n  );\n}\n"}]}
