{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"property-listing-card-tilt-with-floating-layers","type":"registry:block","title":"Property Listing Card Tilt With Floating Layers","description":"","dependencies":[],"files":[{"path":"components/we-inc/property-listing-card-tilt-with-floating-layers.tsx","type":"registry:component","content":"import { useEffect, useRef } from \"react\";\n\nconst MAX_TILT = 9; // degrees at the card's edge\nconst EASE = 0.09; // how quickly the card follows the pointer\nconst PHOTO = \"https://images.pexels.com/photos/32029072/pexels-photo-32029072.jpeg?auto=compress&cs=tinysrgb&w=1000\";\n\nconst specs = [\n  { label: \"2 bedrooms\", d: \"M3 17V9h14v8M3 13h14M6 9V6h8v3\" },\n  { label: \"1 bathroom\", d: \"M3 11h14v2a4 4 0 0 1-4 4H7a4 4 0 0 1-4-4v-2ZM5 11V5a2 2 0 0 1 3-1\" },\n  { label: \"Tiled patio\", d: \"M3 3h14v14H3zM3 10h14M10 3v14\" },\n];\n\nconst css = `\n  .w4prl { --w4prl-bg: #eef1f4; --w4prl-ink: #1c2530; --w4prl-muted: #4f5b69; --w4prl-accent: #2f6b4f;\n    background: var(--w4prl-bg); color: var(--w4prl-ink); padding: 72px 20px; font-family: ui-sans-serif, system-ui, sans-serif; overflow: hidden; }\n  .w4prl-wrap { max-width: 62rem; margin: 0 auto; display: grid; gap: 48px; align-items: center; }\n  @media (min-width: 820px) { .w4prl-wrap { grid-template-columns: 1fr 1.05fr; } }\n  .w4prl-kicker { margin: 0; font-size: 12px; font-weight: 600; letter-spacing: .22em; text-transform: uppercase; color: var(--w4prl-accent); }\n  .w4prl-title { margin: 14px 0 0; font-size: clamp(28px, 3.8vw, 40px); font-weight: 650; line-height: 1.12; letter-spacing: -.02em; }\n  .w4prl-copy { margin: 16px 0 0; max-width: 26rem; font-size: 16px; line-height: 1.65; color: var(--w4prl-muted); }\n  .w4prl-stage { display: flex; justify-content: center; perspective: 1000px; touch-action: pan-y; padding: 8px 0 16px; }\n  .w4prl-card { position: relative; display: block; width: 100%; max-width: 380px; padding: 14px 14px 20px; box-sizing: border-box; color: inherit; text-decoration: none;\n    transform-style: preserve-3d; will-change: transform; outline: none; }\n  .w4prl-base { position: absolute; inset: 0; border-radius: 22px; background: #fff; box-shadow: 0 1px 2px rgba(20, 30, 40, .08), 0 24px 50px -24px rgba(20, 30, 40, .35); }\n  .w4prl-card:focus-visible .w4prl-base { outline: 3px solid var(--w4prl-accent); outline-offset: 5px; }\n  .w4prl-photo { position: relative; display: block; aspect-ratio: 4 / 3; border-radius: 14px; overflow: hidden; background: #c9b98e; transform: translateZ(26px);\n    box-shadow: 0 14px 26px -16px rgba(20, 30, 40, .55); }\n  .w4prl-photo img { display: block; width: 100%; height: 100%; object-fit: cover; }\n  .w4prl-hl { position: absolute; inset: -60%; opacity: .15; pointer-events: none; background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, .55), rgba(255, 255, 255, 0) 36%); }\n  .w4prl-price { position: absolute; left: 26px; top: 26px; padding: 8px 14px; border-radius: 999px; background: var(--w4prl-ink); color: #fff; font-size: 15px; font-weight: 650;\n    transform: translateZ(60px); box-shadow: 0 10px 20px -8px rgba(10, 20, 30, .6); }\n  .w4prl-price small { font-weight: 500; opacity: .8; }\n  .w4prl-tag { position: absolute; right: 26px; top: 28px; padding: 6px 11px; border-radius: 999px; background: #fff; color: var(--w4prl-accent); font-size: 12px; font-weight: 650;\n    transform: translateZ(44px); box-shadow: 0 8px 16px -8px rgba(10, 20, 30, .45); }\n  .w4prl-info { position: relative; display: block; padding: 18px 6px 0; transform: translateZ(34px); }\n  .w4prl-addr { display: block; font-size: 19px; font-weight: 650; letter-spacing: -.01em; }\n  .w4prl-area { display: block; margin-top: 3px; font-size: 14px; color: var(--w4prl-muted); }\n  .w4prl-specs { display: flex; flex-wrap: wrap; gap: 8px 16px; margin-top: 14px; padding-top: 14px; border-top: 1px solid #e3e7ec; font-size: 13.5px; color: #34404d; }\n  .w4prl-specs span { display: inline-flex; align-items: center; gap: 6px; }\n  .w4prl-specs svg { width: 18px; height: 18px; fill: none; stroke: var(--w4prl-accent); stroke-width: 1.6; stroke-linejoin: round; }\n  .w4prl-cta { display: inline-flex; align-items: center; min-height: 46px; margin-top: 26px; padding: 0 22px; border-radius: 12px; background: var(--w4prl-accent); color: #fff;\n    font-size: 15px; font-weight: 600; text-decoration: none; }\n  .w4prl-cta:hover { background: #245540; }\n  .w4prl-cta:focus-visible { outline: 3px solid var(--w4prl-ink); outline-offset: 3px; }\n  @media (prefers-reduced-motion: reduce) { .w4prl-card { transform: rotateX(5deg) rotateY(-7deg) !important; will-change: auto; } .w4prl-hl { transform: translate(-14%, -18%) !important; opacity: .35 !important; } }\n`;\n\nexport default function PropertyListingCardTiltWithFloatingLayers() {\n  const root = useRef<HTMLElement>(null);\n  const cardRef = useRef<HTMLAnchorElement>(null);\n  const hl = useRef<HTMLSpanElement>(null);\n\n  useEffect(() => {\n    const el = root.current, card = cardRef.current, light = hl.current;\n    if (!el || !card || !light) return;\n    if (window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches) return;\n    let tx = 0, ty = 0, x = 0, y = 0, idle = true, frame = 0, visible = true, timer = 0;\n    const clamp = (v: number) => Math.max(-1, Math.min(1, v));\n    const go = () => { if (!frame && visible) frame = requestAnimationFrame(tick); };\n    const aim = (e: PointerEvent) => {\n      const r = card.getBoundingClientRect();\n      tx = clamp(((e.clientX - r.left) / r.width) * 2 - 1);\n      ty = clamp(((e.clientY - r.top) / r.height) * 2 - 1);\n      idle = false; go();\n    };\n    const flat = () => { tx = 0; ty = 0; go(); };\n    const tick = (now: number) => {\n      frame = 0;\n      // idle demo: a slow drift around the corners until real input arrives\n      if (idle) { tx = Math.cos(now / 2600) * 0.75; ty = Math.sin(now / 1900) * 0.6; }\n      x += (tx - x) * EASE; y += (ty - y) * EASE;\n      card.style.transform = `rotateX(${(-y * MAX_TILT).toFixed(2)}deg) rotateY(${(x * MAX_TILT).toFixed(2)}deg)`;\n      light.style.transform = `translate(${(x * 24).toFixed(1)}%, ${(y * 24).toFixed(1)}%)`;\n      light.style.opacity = (0.12 + 0.55 * Math.min(1, Math.hypot(x, y))).toFixed(3);\n      if (idle || Math.abs(tx - x) + Math.abs(ty - y) > 0.002) go();\n    };\n    const onMove = (e: PointerEvent) => { if (e.pointerType === \"mouse\" || e.buttons) aim(e); };\n    const onDown = (e: PointerEvent) => { clearTimeout(timer); aim(e); };\n    const onUp = (e: PointerEvent) => { if (e.pointerType !== \"mouse\") timer = window.setTimeout(flat, 700); };\n    const onLeave = (e: PointerEvent) => { if (e.pointerType === \"mouse\") flat(); };\n    const onFocus = () => { idle = false; tx = -0.55; ty = -0.45; go(); };\n    const pairs: [EventTarget, string, EventListener][] = [\n      [el, \"pointermove\", onMove as EventListener], [el, \"pointerdown\", onDown as EventListener], [el, \"pointerup\", onUp as EventListener],\n      [el, \"pointerleave\", onLeave as EventListener], [el, \"pointercancel\", flat], [card, \"focus\", onFocus], [card, \"blur\", flat],\n    ];\n    pairs.forEach(([t, n, f]) => t.addEventListener(n, f));\n    const io = new IntersectionObserver(([en]) => {\n      visible = en.isIntersecting;\n      if (visible) go(); else { cancelAnimationFrame(frame); frame = 0; }\n    });\n    io.observe(el);\n    go();\n    return () => {\n      cancelAnimationFrame(frame); clearTimeout(timer); io.disconnect();\n      pairs.forEach(([t, n, f]) => t.removeEventListener(n, f));\n    };\n  }, []);\n\n  return (\n    <section ref={root} className=\"w4prl\">\n      <style>{css}</style>\n      <div className=\"w4prl-wrap\">\n        <div>\n          <p className=\"w4prl-kicker\">Larkfield Lettings</p>\n          <h2 className=\"w4prl-title\">A yellow brick bungalow with green shutters, two streets from the beach.</h2>\n          <p className=\"w4prl-copy\">Single storey, south facing, with a tiled patio out front and a quiet lane behind. Unfurnished, pets considered.</p>\n          <a href=\"#\" className=\"w4prl-cta\">Book a viewing</a>\n        </div>\n        <div className=\"w4prl-stage\">\n          <a ref={cardRef} href=\"#\" className=\"w4prl-card\" aria-label=\"7 Quayside Lane, Seacombe, two bedroom bungalow to let at 1,450 pounds a month, view listing\">\n            <span className=\"w4prl-base\" aria-hidden=\"true\" />\n            <span className=\"w4prl-photo\" aria-hidden=\"true\">\n              <img src={PHOTO} alt=\"Yellow brick bungalow with green shutters and a tiled patio\" width={1000} height={667} loading=\"lazy\" />\n              <span ref={hl} className=\"w4prl-hl\" />\n            </span>\n            <span className=\"w4prl-price\" aria-hidden=\"true\">£1,450 <small>pcm</small></span>\n            <span className=\"w4prl-tag\" aria-hidden=\"true\">From 1 Dec</span>\n            <span className=\"w4prl-info\" aria-hidden=\"true\">\n              <span className=\"w4prl-addr\">7 Quayside Lane</span>\n              <span className=\"w4prl-area\">Seacombe, bungalow</span>\n              <span className=\"w4prl-specs\">\n                {specs.map((s) => (\n                  <span key={s.label}><svg viewBox=\"0 0 20 20\"><path d={s.d} /></svg>{s.label}</span>\n                ))}\n              </span>\n            </span>\n          </a>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
