{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"pop-up-card-where-a-typed-sentence-stands-up-as-a-layered-paper-homepage","type":"registry:block","title":"Pop-Up Card Where a Typed Sentence Stands Up as a Layered Paper Homepage","description":"Pop-up card in CSS 3D: a typed sentence lies on the table and a paper homepage stands up from the fold in die-cut layers. Free React and HTML code to copy.","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/pop-up-card-where-a-typed-sentence-stands-up-as-a-layered-paper-homepage.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport type { CSSProperties, ReactNode } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n/** Everything printed on the card. Change the business here. */\nconst site = {\n  sentence: \"A sourdough bakery in Lisbon that takes orders for Saturday pickup.\",\n  brand: \"Forno Lume\",\n  links: [\"Bread\", \"Mornings\", \"Find us\"],\n  headline: [\"Bread worth\", \"waking up\", \"for.\"],\n  sub: \"Slow dough, shaped by hand in Alfama.\",\n  cta: \"Order for Saturday\",\n  note: [\"Saturday pickup\", \"8 until 1\"],\n  hero: { src: \"https://images.pexels.com/photos/4881596/pexels-photo-4881596.jpeg?auto=compress&cs=tinysrgb&w=600\", alt: \"Round sourdough loaf on a dark surface dusted with flour\" },\n  tiles: [\n    { label: \"Country loaf\", src: \"https://images.pexels.com/photos/4881589/pexels-photo-4881589.jpeg?auto=compress&cs=tinysrgb&w=300\", alt: \"Sliced sourdough seen from above on a floured black table\", tone: \"#2a2420\" },\n    { label: \"Almond croissant\", src: \"https://images.pexels.com/photos/13439695/pexels-photo-13439695.jpeg?auto=compress&cs=tinysrgb&w=300\", alt: \"Two almond croissants on white paper\", tone: \"#d9d2c8\" },\n    { label: \"Seeded rye\", src: \"https://images.pexels.com/photos/17890200/pexels-photo-17890200.jpeg?auto=compress&cs=tinysrgb&w=300\", alt: \"Dark crusted loaf cut open on a cloth\", tone: \"#3a2c22\" },\n  ],\n};\n\nconst BLUE = \"#4F98FB\";\nconst INK = \"#0B0D12\";\nconst PAPER = \"#F8F6F1\";\n// Design pixels. The whole scene is scaled to fit its frame.\nconst W = 580; // card width\nconst H = 360; // height of the leaf that stands up\nconst D = 330; // depth of the leaf that lies on the table\nconst SCENE_W = 900;\nconst SCENE_H = 740;\nconst OPEN = 97; // degrees between the two leaves when the card is standing\nconst FLAT = 7;\n\nconst clamp = (v: number, lo: number, hi: number) => Math.min(hi, Math.max(lo, v));\nconst stand = \"rotateX(calc(var(--a) * 1deg - 90deg))\";\n\n/** A die-cut piece that stands parallel to the back leaf, `d` pixels in front of the fold, held by paper tabs. */\nfunction Flat({ x, w, h, d, radius, tabs, edge = \"#cfcabf\", children }: { x: number; w: number; h: number; d: number; radius: string; tabs: number[]; edge?: string; children: ReactNode }) {\n  return (\n    <div className=\"absolute\" style={{ left: x - W / 2, top: -h, width: w, height: h, transformOrigin: \"50% 100%\", transform: `translateZ(${d}px) ${stand}`, transformStyle: \"preserve-3d\" }}>\n      {tabs.map((tx) => (\n        <div\n          key={tx}\n          aria-hidden=\"true\"\n          className=\"absolute\"\n          style={{ left: tx, top: 10, width: 20, height: d, transformOrigin: \"50% 0\", transform: \"rotateX(calc(var(--a) * -1deg))\", background: \"linear-gradient(180deg, #e9e5dc 0%, #d2cdc2 100%)\", boxShadow: \"inset 1px 0 0 rgba(255,255,255,0.7), inset -1px 0 0 rgba(0,0,0,0.12)\" }}\n        />\n      ))}\n      <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ borderRadius: radius, background: edge, transform: \"translateZ(-2.5px)\" }} />\n      <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ borderRadius: radius, background: edge, transform: \"translateZ(-1.2px)\" }} />\n      <div className=\"absolute inset-0 overflow-hidden\" style={{ borderRadius: radius, boxShadow: \"inset 0 1px 0 rgba(255,255,255,0.75), inset 0 -1px 0 rgba(0,0,0,0.14)\" }}>\n        {children}\n        <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"linear-gradient(180deg, rgba(255,255,255,0.10) 0%, rgba(255,255,255,0) 30%, rgba(20,14,4,0.10) 100%)\" }} />\n      </div>\n    </div>\n  );\n}\n\n/** The soft shadow a standing piece throws on the leaf behind it. */\nfunction Cast({ x, w, h, d, radius }: { x: number; w: number; h: number; d: number; radius: string }) {\n  return (\n    <div\n      aria-hidden=\"true\"\n      className=\"absolute\"\n      style={{ left: x + d * 0.3, top: H - h + d * 0.2, width: w, height: h + 30, borderRadius: radius, background: \"rgba(38,28,10,0.34)\", filter: `blur(${(5 + d * 0.09).toFixed(1)}px)`, opacity: \"var(--s)\" as unknown as number }}\n    />\n  );\n}\n\n/** The shadow at the foot of a standing piece, lying on the base leaf. */\nfunction Foot({ x, w, d }: { x: number; w: number; d: number }) {\n  return (\n    <div aria-hidden=\"true\" className=\"absolute\" style={{ left: x + 6, top: d - 26, width: w + 16, height: 30, borderRadius: 12, background: \"linear-gradient(180deg, rgba(38,28,10,0), rgba(38,28,10,0.38))\", filter: \"blur(5px)\", opacity: \"var(--s)\" as unknown as number }} />\n  );\n}\n\nexport default function PopUpHomepageCard() {\n  const reduce = useReducedMotion();\n  const wrapRef = useRef<HTMLDivElement>(null);\n  const sceneRef = useRef<HTMLDivElement>(null);\n  const cardRef = useRef<HTMLDivElement>(null);\n  const typedRef = useRef<HTMLSpanElement>(null);\n  const [standing, setStanding] = useState(true);\n  const sim = useRef({ a: 58, va: 0, target: OPEN, yaw: -10, tyaw: 0, dragging: false, y0: 0, a0: 0, moved: 0, scale: 1, nextDip: 0, held: false, user: false });\n\n  useEffect(() => {\n    const wrap = wrapRef.current;\n    const scene = sceneRef.current;\n    const card = cardRef.current;\n    if (!wrap || !scene || !card) return;\n    const s = sim.current;\n    let raf = 0;\n    let visible = true;\n    let last = performance.now();\n    const t0 = last;\n    s.nextDip = last + 5200;\n    if (reduce) s.a = s.target;\n\n    const measure = () => {\n      const sc = clamp(wrap.clientWidth / 770, 0.4, 1);\n      s.scale = sc;\n      wrap.style.height = `${Math.round(SCENE_H * sc)}px`;\n      scene.style.transform = `translateX(-50%) scale(${sc.toFixed(4)})`;\n    };\n    measure();\n    const ro = new ResizeObserver(measure);\n    ro.observe(wrap);\n\n    const paint = (now: number) => {\n      const idle = reduce ? 0 : Math.sin((now - t0) / 2600) * 5;\n      s.yaw += (-10 + idle + s.tyaw - s.yaw) * 0.08;\n      card.style.setProperty(\"--a\", s.a.toFixed(2));\n      card.style.setProperty(\"--s\", clamp((s.a - 30) / 55, 0, 1).toFixed(3));\n      card.style.setProperty(\"--dim\", clamp((70 - s.a) / 90, 0, 0.55).toFixed(3));\n      card.style.transform = `rotateX(-27deg) rotateY(${(reduce ? -10 : s.yaw).toFixed(2)}deg)`;\n      const t = typedRef.current;\n      if (t) {\n        const n = Math.round(site.sentence.length * clamp((s.a - 20) / 52, 0, 1));\n        if (t.dataset.n !== String(n)) {\n          t.dataset.n = String(n);\n          t.textContent = site.sentence.slice(0, n);\n        }\n      }\n    };\n\n    const tick = (now: number) => {\n      const dt = Math.min(0.033, (now - last) / 1000);\n      last = now;\n      if (reduce) {\n        s.a = s.target;\n      } else if (!s.dragging) {\n        const acc = 58 * (s.target - s.a) - 8.2 * s.va;\n        s.va += acc * dt;\n        s.a = clamp(s.a + s.va * dt, 2, 112);\n        // the idle demo: press the card down, let the sentence clear, and let it stand again\n        if (!s.user && !s.held && now > s.nextDip) {\n          if (s.target === OPEN) {\n            s.target = 16;\n            s.nextDip = now + 1500;\n          } else {\n            s.target = OPEN;\n            s.nextDip = now + 6200;\n          }\n        }\n      }\n      paint(now);\n      if (visible) raf = requestAnimationFrame(tick);\n    };\n\n    const io = new IntersectionObserver(([e]) => {\n      const was = visible;\n      visible = e.isIntersecting;\n      if (visible && !was) {\n        last = performance.now();\n        raf = requestAnimationFrame(tick);\n      }\n    });\n    io.observe(wrap);\n    raf = requestAnimationFrame(tick);\n\n    const down = (e: PointerEvent) => {\n      if (e.button !== 0 || (e.target as HTMLElement).closest(\"button\")) return;\n      s.dragging = true;\n      s.y0 = e.clientY;\n      s.a0 = s.a;\n      s.moved = 0;\n      s.va = 0;\n      scene.setPointerCapture(e.pointerId);\n    };\n    const move = (e: PointerEvent) => {\n      const r = wrap.getBoundingClientRect();\n      s.tyaw = clamp(((e.clientX - r.left) / r.width - 0.5) * 2, -1, 1) * 12;\n      if (!s.dragging) return;\n      const dy = (s.y0 - e.clientY) / s.scale;\n      s.moved = Math.max(s.moved, Math.abs(dy));\n      const next = clamp(s.a0 + dy * 0.42, 2, 110);\n      s.va = (next - s.a) * 30;\n      s.a = next;\n    };\n    const up = () => {\n      if (!s.dragging) return;\n      s.dragging = false;\n      const open = s.moved < 5 ? s.target !== OPEN : s.a + s.va * 0.12 > 46;\n      s.target = open ? OPEN : FLAT;\n      s.user = !open;\n      s.nextDip = performance.now() + 9000;\n      setStanding(open);\n    };\n    const leave = () => {\n      s.tyaw = 0;\n    };\n    scene.addEventListener(\"pointerdown\", down);\n    scene.addEventListener(\"pointermove\", move);\n    scene.addEventListener(\"pointerup\", up);\n    scene.addEventListener(\"pointercancel\", up);\n    scene.addEventListener(\"pointerleave\", leave);\n\n    return () => {\n      cancelAnimationFrame(raf);\n      ro.disconnect();\n      io.disconnect();\n      scene.removeEventListener(\"pointerdown\", down);\n      scene.removeEventListener(\"pointermove\", move);\n      scene.removeEventListener(\"pointerup\", up);\n      scene.removeEventListener(\"pointercancel\", up);\n      scene.removeEventListener(\"pointerleave\", leave);\n    };\n  }, [reduce]);\n\n  const toggle = () => {\n    const s = sim.current;\n    const open = s.target !== OPEN;\n    s.target = open ? OPEN : FLAT;\n    s.user = !open;\n    s.nextDip = performance.now() + 9000;\n    setStanding(open);\n  };\n  const hold = (v: boolean) => () => {\n    sim.current.held = v;\n    if (!v) sim.current.nextDip = performance.now() + 4000;\n  };\n\n  const grain: CSSProperties = { backgroundImage: \"repeating-linear-gradient(92deg, rgba(120,100,60,0.018) 0px, rgba(120,100,60,0) 3px, rgba(120,100,60,0.014) 7px), repeating-linear-gradient(1deg, rgba(120,100,60,0.014) 0px, rgba(120,100,60,0) 4px)\" };\n  const arch = \"104px 104px 4px 4px\";\n  const sans = '\"Inter Tight\", \"Inter\", ui-sans-serif, system-ui, sans-serif';\n\n  return (\n    <section className=\"relative overflow-hidden bg-[#0B0D12]\" style={{ fontFamily: sans }} onMouseEnter={hold(true)} onMouseLeave={hold(false)}>\n      <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"radial-gradient(58% 60% at 50% 46%, #2b2f3a 0%, #191c25 42%, #0e1016 74%, #0B0D12 100%)\" }} />\n      <div ref={wrapRef} className=\"relative mx-auto w-full overflow-hidden\" style={{ height: SCENE_H }}>\n        <div\n          ref={sceneRef}\n          className=\"absolute left-1/2 top-0 touch-pan-x select-none\"\n          style={{ width: SCENE_W, height: SCENE_H, transformOrigin: \"50% 0\", transform: \"translateX(-50%)\", perspective: \"1500px\", perspectiveOrigin: \"50% 38%\", cursor: \"grab\" }}\n        >\n          <div ref={cardRef} className=\"absolute\" style={{ left: SCENE_W / 2, top: 404, width: 0, height: 0, transformStyle: \"preserve-3d\", transform: \"rotateX(-27deg) rotateY(-10deg)\", [\"--a\" as string]: reduce ? OPEN : 58, [\"--s\" as string]: 1, [\"--dim\" as string]: 0 }}>\n            {/* shadow of the whole card on the table */}\n            <div aria-hidden=\"true\" className=\"absolute\" style={{ left: -W / 2 - 30, top: 0, width: W + 150, height: D + 70, transformOrigin: \"50% 0\", transform: \"translate3d(0,4px,-70px) rotateX(90deg)\", background: \"rgba(0,0,0,0.75)\", filter: \"blur(34px)\" }} />\n            <div aria-hidden=\"true\" className=\"absolute\" style={{ left: -W / 2 + 2, top: 0, width: W + 8, height: D + 6, transformOrigin: \"50% 0\", transform: \"translate3d(0,2.5px,0) rotateX(90deg)\", background: \"rgba(0,0,0,0.8)\", filter: \"blur(7px)\" }} />\n\n            {/* the leaf that lies on the table: it carries the sentence */}\n            <div className=\"absolute overflow-hidden\" style={{ left: -W / 2, top: 0, width: W, height: D, transformOrigin: \"50% 0\", transform: \"rotateX(90deg)\", background: PAPER, borderRadius: \"0 0 10px 10px\", ...grain }}>\n              <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"linear-gradient(180deg, rgba(38,28,10,0.30) 0%, rgba(38,28,10,0.10) 9%, rgba(38,28,10,0) 30%, rgba(255,255,255,0.35) 100%)\" }} />\n              <Foot x={338} w={208} d={52} />\n              <Foot x={28} w={282} d={96} />\n              <Foot x={336} w={212} d={150} />\n              <p className=\"absolute left-[30px] right-[30px] font-mono text-[10px] font-semibold uppercase tracking-[0.3em]\" style={{ top: 192, color: BLUE }}>\n                One sentence\n              </p>\n              <p className=\"absolute left-[28px] right-[40px] text-[31px] font-extrabold leading-[1.12] tracking-[-0.035em]\" style={{ top: 212, color: INK }}>\n                <span className=\"sr-only\">{site.sentence}</span>\n                <span aria-hidden=\"true\">\n                  <span ref={typedRef}>{site.sentence}</span>\n                  <span className=\"pop-up-card-sentence-caret ml-[3px] inline-block h-[28px] w-[4px] translate-y-[4px] rounded-full\" style={{ background: BLUE }} />\n                </span>\n              </p>\n              <div aria-hidden=\"true\" className=\"absolute inset-0\" style={{ background: \"rgba(8,9,14,1)\", opacity: \"var(--dim)\" as unknown as number }} />\n            </div>\n\n            {/* the leaf that stands up: the page itself */}\n            <div className=\"absolute\" style={{ left: -W / 2, top: -H, width: W, height: H, transformOrigin: \"50% 100%\", transform: stand, transformStyle: \"preserve-3d\" }}>\n              <div className=\"absolute inset-0 overflow-hidden\" style={{ background: INK, borderRadius: \"10px 10px 0 0\", transform: \"rotateY(180deg) translateZ(1px)\", backfaceVisibility: \"hidden\" }} aria-hidden=\"true\">\n                <div className=\"absolute inset-0\" style={{ background: \"linear-gradient(165deg, #39404f 0%, #232834 45%, #171b24 100%)\", boxShadow: \"inset 0 0 0 1px rgba(255,255,255,0.10), inset 0 -2px 0 rgba(255,255,255,0.16)\" }} />\n                <span className=\"absolute left-1/2 top-1/2 h-3 w-3 -translate-x-1/2 -translate-y-1/2 rounded-full\" style={{ background: BLUE, boxShadow: `0 0 24px ${BLUE}` }} />\n              </div>\n              <div className=\"absolute inset-0 overflow-hidden\" style={{ background: PAPER, borderRadius: \"10px 10px 0 0\", backfaceVisibility: \"hidden\", ...grain }}>\n                <Cast x={338} w={208} h={276} d={52} radius={arch} />\n                <Cast x={28} w={282} h={104} d={96} radius=\"8px\" />\n                <div className=\"absolute left-[28px] right-[28px] top-[20px] flex items-center justify-between\">\n                  <span className=\"flex items-center gap-2 text-[13px] font-extrabold tracking-[-0.02em]\" style={{ color: INK }}>\n                    <span aria-hidden=\"true\" className=\"h-[9px] w-[9px] rounded-full\" style={{ background: BLUE }} />\n                    {site.brand}\n                  </span>\n                  <span className=\"flex items-center gap-[18px] text-[10.5px] font-semibold text-neutral-600\">\n                    {site.links.map((l) => (\n                      <span key={l}>{l}</span>\n                    ))}\n                  </span>\n                </div>\n                <div aria-hidden=\"true\" className=\"absolute left-[28px] right-[28px] top-[50px] h-px bg-neutral-900/10\" />\n                <h2 className=\"absolute left-[28px] top-[74px] text-[50px] font-black leading-[0.94] tracking-[-0.055em]\" style={{ color: INK }}>\n                  {site.headline.map((l) => (\n                    <span key={l} className=\"block\">\n                      {l}\n                    </span>\n                  ))}\n                </h2>\n                <p className=\"absolute left-[30px] top-[226px] w-[250px] text-[12.5px] font-semibold leading-snug text-neutral-600\">\n                  {site.sub} <span style={{ color: \"#0B0D12\" }}>{site.note[0]}, {site.note[1]}.</span>\n                </p>\n                <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"linear-gradient(180deg, rgba(255,255,255,0.22) 0%, rgba(255,255,255,0) 35%, rgba(38,28,10,0.16) 100%)\" }} />\n                <div aria-hidden=\"true\" className=\"pointer-events-none absolute inset-0\" style={{ background: \"rgba(8,9,14,1)\", opacity: \"var(--dim)\" as unknown as number }} />\n              </div>\n            </div>\n\n            {/* the pieces that stand in front of the page, back to front */}\n            <Flat x={338} w={208} h={276} d={52} radius={arch} tabs={[94]}>\n              <div className=\"absolute inset-0 bg-[#fbfaf7]\" />\n              <div className=\"absolute inset-[9px] overflow-hidden bg-[#15171c]\" style={{ borderRadius: \"96px 96px 2px 2px\" }}>\n                <img src={site.hero.src} alt={site.hero.alt} width={190} height={258} draggable={false} className=\"h-full w-full object-cover\" style={{ objectPosition: \"50% 62%\" }} />\n              </div>\n            </Flat>\n\n            <Flat x={28} w={282} h={104} d={96} radius=\"8px\" tabs={[38, 224]}>\n              <div className=\"absolute inset-0 bg-[#fbfaf7]\" />\n              <ul className=\"absolute inset-[7px] grid grid-cols-3 gap-[7px]\">\n                {site.tiles.map((t) => (\n                  <li key={t.label} className=\"relative overflow-hidden rounded-[4px]\" style={{ background: t.tone }}>\n                    <img src={t.src} alt={t.alt} width={85} height={98} draggable={false} className=\"h-full w-full object-cover\" />\n                    <span className=\"absolute inset-x-0 bottom-0 bg-gradient-to-t from-black/80 to-black/0 px-[6px] pb-[6px] pt-5 text-[8.5px] font-bold leading-none text-white\">{t.label}</span>\n                  </li>\n                ))}\n              </ul>\n            </Flat>\n\n            <Flat x={336} w={212} h={54} d={150} radius=\"27px\" tabs={[96]} edge=\"#2f69c0\">\n              <div className=\"absolute inset-0\" style={{ background: `linear-gradient(180deg, #6aa9fc 0%, ${BLUE} 45%, #3f86ea 100%)` }} />\n              <span className=\"absolute inset-0 flex items-center justify-center gap-2 text-[15px] font-extrabold tracking-[-0.02em]\" style={{ color: INK }}>\n                {site.cta}\n                <svg aria-hidden=\"true\" width=\"14\" height=\"14\" viewBox=\"0 0 20 20\" fill=\"none\" stroke=\"currentColor\" strokeWidth=\"2.6\" strokeLinecap=\"round\" strokeLinejoin=\"round\">\n                  <path d=\"M4 10h12M11 5l5 5-5 5\" />\n                </svg>\n              </span>\n            </Flat>\n          </div>\n        </div>\n\n        <div className=\"absolute inset-x-0 bottom-5 flex justify-center sm:bottom-8\">\n          <button\n            type=\"button\"\n            onClick={toggle}\n            aria-pressed={standing}\n            className=\"inline-flex h-11 items-center gap-2 rounded-full border border-white/15 bg-white/[0.06] px-5 text-[13px] font-bold tracking-[-0.01em] text-white transition hover:bg-white/[0.14] focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#4F98FB]\"\n          >\n            <span aria-hidden=\"true\" className=\"h-2 w-2 rounded-full\" style={{ background: standing ? BLUE : \"rgba(255,255,255,0.4)\" }} />\n            {standing ? \"Press it flat\" : \"Stand it up\"}\n          </button>\n        </div>\n      </div>\n      <style>{`\n        @keyframes pop-up-card-sentence-caret-blink { 0%, 55% { opacity: 1 } 56%, 100% { opacity: 0 } }\n        .pop-up-card-sentence-caret { animation: pop-up-card-sentence-caret-blink 1.1s steps(1) infinite; }\n        @media (prefers-reduced-motion: reduce) { .pop-up-card-sentence-caret { animation: none; } }\n      `}</style>\n    </section>\n  );\n}\n"}]}
