{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"forest-curtain-preloader-that-lifts-with-a-curved-edge","type":"registry:block","title":"Forest Curved Curtain Preloader","description":"","dependencies":[],"files":[{"path":"components/we-inc/forest-curtain-preloader-that-lifts-with-a-curved-edge.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  .w2lft { --w2lft-forest: #1d3a2c; --w2lft-moss: #b9c9a3; --w2lft-cream: #f4f1e8; height: 600px; background: var(--w2lft-forest); color: var(--w2lft-cream); font-family: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', sans-serif; }\n  .w2lft-page { position: relative; height: 100%; display: flex; flex-direction: column; padding: 0 clamp(16px, 4vw, 48px) clamp(18px, 4vw, 44px); }\n  .w2lft-bg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; transform: translateY(40px) scale(1.08); transition: transform 1.5s cubic-bezier(.2,.75,.15,1) .15s; }\n  .w2lft.is-out .w2lft-bg { transform: none; }\n  .w2lft-shade { position: absolute; inset: 0; background: linear-gradient(180deg, rgba(16,30,22,.55), rgba(16,30,22,.1) 35%, rgba(16,30,22,.78)); }\n  .w2lft-nav, .w2lft-body { position: relative; }\n  .w2lft-nav { display: flex; align-items: center; justify-content: space-between; height: 76px; }\n  .w2lft-brand { color: inherit; font-weight: 700; letter-spacing: .04em; text-decoration: none; }\n  .w2lft-book { display: inline-flex; align-items: center; min-height: 42px; padding: 0 18px; border-radius: 999px; background: var(--w2lft-cream); color: var(--w2lft-forest); font-size: 14px; font-weight: 600; text-decoration: none; }\n  .w2lft-body { flex: 1; display: flex; align-items: flex-end; justify-content: space-between; gap: 24px; }\n  .w2lft-text { max-width: 34rem; transform: translateY(30px); opacity: .001; transition: transform 1s cubic-bezier(.2,.75,.15,1) .35s, opacity .7s ease .35s; }\n  .w2lft.is-out .w2lft-text { transform: none; opacity: 1; }\n  .w2lft-title { margin: 0; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(32px, 5vw, 64px); line-height: 1.03; font-weight: 400; }\n  .w2lft-copy { margin: 14px 0 20px; font-size: 16px; line-height: 1.6; color: #e1e6d8; }\n  .w2lft-replay { border: 1px solid rgba(244,241,232,.55); background: rgba(16,30,22,.35); color: var(--w2lft-cream); }\n  .w2lft-card { margin: 0; width: 240px; flex: none; background: var(--w2lft-cream); color: #1f2b22; padding: 8px 8px 12px; border-radius: 6px; box-shadow: 0 24px 50px -20px rgba(0,0,0,.55); transform: translateY(40px); opacity: .001; transition: transform 1s cubic-bezier(.2,.75,.15,1) .5s, opacity .7s ease .5s; }\n  .w2lft.is-out .w2lft-card { transform: rotate(-2deg); opacity: 1; }\n  .w2lft-card img { display: block; width: 100%; height: auto; aspect-ratio: 3 / 2; object-fit: cover; border-radius: 3px; }\n  .w2lft-card figcaption { margin: 10px 4px 0; font-size: 13px; line-height: 1.45; color: #3d4a40; }\n  .w2lft-card strong { display: block; color: #1f2b22; font-size: 14px; }\n  .w2lft-cover { position: absolute; inset: 0; z-index: 2; background: var(--w2lft-forest); display: flex; flex-direction: column; justify-content: center; align-items: center; transition: transform 1s cubic-bezier(.76,0,.24,1); }\n  .w2lft.is-out .w2lft-cover { transform: translateY(calc(-100% - 160px)); }\n  .w2lft-curve { position: absolute; top: calc(100% - 1px); left: -25%; width: 150%; height: 150px; border-radius: 0 0 50% 50%; background: var(--w2lft-forest); }\n  .w2lft-word { margin: 0; font-family: ui-serif, Georgia, 'Times New Roman', serif; font-size: clamp(40px, 8vw, 100px); color: var(--w2lft-cream); letter-spacing: -.01em; text-align: center; line-height: 1.05; padding: 0 16px; }\n  .w2lft-foot { position: absolute; left: clamp(16px, 4vw, 48px); right: clamp(16px, 4vw, 48px); bottom: 48px; display: flex; justify-content: space-between; font-size: 14px; color: var(--w2lft-moss); font-variant-numeric: tabular-nums; }\n  .w2lft-track { position: absolute; left: clamp(16px, 4vw, 48px); right: clamp(16px, 4vw, 48px); bottom: 34px; height: 2px; background: rgba(185,201,163,.2); }\n  .w2lft-track span { display: block; height: 100%; background: var(--w2lft-moss); transform: scaleX(0); transform-origin: left; }\n  @media (max-width: 767px) {\n    .w2lft-body { flex-direction: column; align-items: stretch; justify-content: flex-end; }\n    .w2lft-card { display: none; }\n    .w2lft-copy { font-size: 15px; }\n  }\n\n  .w2lft { position: relative; overflow: hidden; }\n  .w2lft-cover[hidden] { display: none; }\n  .w2lft.is-snap, .w2lft.is-snap * { transition: none !important; }\n  .w2lft[data-paused] * { animation-play-state: paused !important; }\n  .w2lft-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }\n  .w2lft-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  .w2lft-replay:focus-visible, .w2lft a:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }\n  @media (prefers-reduced-motion: reduce) {\n    .w2lft *, .w2lft *::before, .w2lft *::after { animation: none !important; transition-duration: 0s !important; transition-delay: 0s !important; }\n    .w2lft .w2lft-cover { transition: opacity .45s ease !important; }\n    .w2lft.is-out .w2lft-cover { opacity: 0; }\n    .w2lft-cover *:not([data-bar]), .w2lft-page * { transform: none !important; opacity: 1; }\n  }\n`;\n\nexport default function ForestCurvedCurtainPreloader() {\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=\"w2lft\">\n      <style>{CSS}</style>\n      <div className=\"w2lft-page\" data-page=\"\" aria-busy={true}>\n        <img className=\"w2lft-bg\" src=\"https://images.pexels.com/photos/5865768/pexels-photo-5865768.jpeg?auto=compress&cs=tinysrgb&w=1600\" alt=\"Wooden cabin on a green meadow below a pine forest with low mist on the hills\" width=\"1600\" height=\"1067\" />\n        <div className=\"w2lft-shade\"></div>\n        <header className=\"w2lft-nav\">\n          <a href=\"#\" className=\"w2lft-brand\">Pinewood Hollow</a>\n          <a href=\"#\" className=\"w2lft-book\">Check dates</a>\n        </header>\n        <div className=\"w2lft-body\">\n          <div className=\"w2lft-text\">\n            <h2 className=\"w2lft-title\">Six cabins at the end of a gravel road.</h2>\n            <p className=\"w2lft-copy\">Wood stoves, no televisions and a lake a short walk through the trees.</p>\n            <button type=\"button\" className=\"w2lft-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          <figure className=\"w2lft-card\">\n            <img src=\"https://images.pexels.com/photos/29277697/pexels-photo-29277697.jpeg?auto=compress&cs=tinysrgb&w=800\" alt=\"Small wooden cabin among tall pines with rocky mountain peaks behind\" width=\"800\" height=\"533\" />\n            <figcaption><strong>Cabin four</strong> Sleeps two, closest to the ridge path</figcaption>\n          </figure>\n        </div>\n      </div>\n      <div className=\"w2lft-cover\" data-cover=\"\" aria-hidden=\"true\">\n        <span className=\"w2lft-curve\"></span>\n        <p className=\"w2lft-word\">Pinewood Hollow</p>\n        <div className=\"w2lft-foot\">\n          <span>Fetching the view</span><span><span data-num=\"\">0</span>%</span>\n        </div>\n        <span className=\"w2lft-track\"><span data-bar=\"\"></span></span>\n      </div>\n      <p className=\"w2lft-sr\" data-live=\"\" aria-live=\"polite\"></p>\n    </section>\n  );\n}\n"}]}
