{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"clip-path-typewriter-for-proportional-serif-headlines","type":"registry:component","title":"Clip-Path Typewriter for Serif Headlines","description":"","dependencies":["framer-motion"],"files":[{"path":"components/we-inc/clip-path-typewriter-for-proportional-serif-headlines.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\n\n// The headline. Every letter is revealed by its own clip-path, so any font works.\nconst HEADLINE = \"Flowers that last the whole week.\";\nconst STEP_MS = 45; // time between letters\n\nexport default function ClipPathTypewriterHeadline() {\n  const rootRef = useRef<HTMLElement>(null);\n  const [paused, setPaused] = useState(false);\n  const [run, setRun] = useState(0);\n  const reduce = useReducedMotion();\n\n  useEffect(() => {\n    const el = rootRef.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(([entry]) => setPaused(!entry.isIntersecting));\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  let i = 0;\n  const words = HEADLINE.split(\" \");\n  const total = HEADLINE.length;\n\n  return (\n    <section\n      ref={rootRef}\n      data-paused={paused ? \"true\" : \"false\"}\n      data-still={reduce ? \"true\" : \"false\"}\n      className=\"cpt-root px-4 py-20 sm:py-28\"\n      style={{ [\"--cpt-step\" as string]: `${STEP_MS}ms` }}\n    >\n      <style>{`\n        .cpt-root { background: linear-gradient(160deg, #fcebdc 0%, #f6e4e4 45%, #ece3f1 100%); }\n        .cpt-h { font-family: \"Iowan Old Style\", \"Palatino Linotype\", Palatino, Georgia, serif; font-weight: 500; color: #3b1d3a; font-size: clamp(2.25rem, 6.5vw, 4.5rem); line-height: 1.08; letter-spacing: -0.01em; }\n        .cpt-w { display: inline-block; white-space: nowrap; }\n        .cpt-c { position: relative; display: inline-block; }\n        .cpt-g { display: inline-block; clip-path: inset(0 100% 0 0); animation: cpt-in 90ms ease-out both; animation-delay: calc(var(--i) * var(--cpt-step)); }\n        .cpt-c::after { content: \"\"; position: absolute; right: -0.07em; top: 0.12em; bottom: 0.08em; width: 0.06em; min-width: 2px; background: #b4535a; opacity: 0; animation: cpt-caret var(--cpt-step) steps(1); animation-delay: calc(var(--i) * var(--cpt-step)); }\n        .cpt-c.cpt-last::after { animation: cpt-blink 1.05s steps(1) infinite; animation-delay: calc(var(--i) * var(--cpt-step)); }\n        @keyframes cpt-in { to { clip-path: inset(0 -0.2em 0 -0.2em); } }\n        @keyframes cpt-caret { 0%, 100% { opacity: 1; } }\n        @keyframes cpt-blink { 0%, 55% { opacity: 1; } 56%, 100% { opacity: 0; } }\n        .cpt-root[data-paused=\"true\"] .cpt-g, .cpt-root[data-paused=\"true\"] .cpt-c::after { animation-play-state: paused; }\n        .cpt-root[data-still=\"true\"] .cpt-g { animation: none; clip-path: none; }\n        .cpt-root[data-still=\"true\"] .cpt-c::after { animation: none; }\n        @media (prefers-reduced-motion: reduce) { .cpt-g { animation: none; clip-path: none; } .cpt-c::after { animation: none; } }\n      `}</style>\n      <div className=\"mx-auto max-w-3xl text-center\">\n        <p className=\"text-sm font-medium text-[#6b3a52]\">Petal &amp; Fern, Canal Street</p>\n        <h1 className=\"cpt-h mt-5\">\n          <span className=\"sr-only\">{HEADLINE}</span>\n          <span aria-hidden=\"true\" key={run}>\n            {words.map((w, wi) => {\n              const letters = [...w].map((ch) => {\n                const idx = i++;\n                return (\n                  <span key={idx} className={`cpt-c${idx === total - 1 ? \" cpt-last\" : \"\"}`} style={{ [\"--i\" as string]: idx }}>\n                    <span className=\"cpt-g\">{ch}</span>\n                  </span>\n                );\n              });\n              i++; // the space counts as a beat\n              return (\n                <span key={wi}>\n                  <span className=\"cpt-w\">{letters}</span>\n                  {wi < words.length - 1 ? \" \" : null}\n                </span>\n              );\n            })}\n          </span>\n        </h1>\n        <p className=\"mx-auto mt-6 max-w-md text-base leading-relaxed text-[#5b3a4f]\">Stems cut at dawn from two farms up the valley, wrapped in paper and delivered before lunch.</p>\n        <div className=\"mt-8 flex flex-wrap items-center justify-center gap-3\">\n          <a href=\"#\" className=\"inline-flex h-11 items-center rounded-full bg-[#3b1d3a] px-6 text-sm font-semibold text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#b4535a] focus-visible:ring-offset-2\">Order a bunch</a>\n          <button type=\"button\" onClick={() => setRun((r) => r + 1)} className=\"inline-flex h-11 items-center rounded-full border border-[#3b1d3a]/30 px-5 text-sm font-medium text-[#3b1d3a] hover:bg-white/50 focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#b4535a]\">Replay typing</button>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
