{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"letters-flipping-into-place-in-3d","type":"registry:component","title":"Letters Flipping into Place in 3D","description":"","dependencies":[],"files":[{"path":"components/we-inc/letters-flipping-into-place-in-3d.tsx","type":"registry:component","content":"import { Fragment, useEffect, useRef } from \"react\";\nimport type { CSSProperties } from \"react\";\n\nconst BUSINESS = \"Fernwick Ferry Company\";\nconst HEADLINE = \"Next crossing leaves at 7:40.\";\nconst COPY = \"Foot passengers and bikes to Holm Island, six sailings a day. Tickets from the hut on the quay or from the crew on board.\";\n\nconst CSS = `\n/* Edit these first: colours, and how long one full cycle takes. */\n.fl-root {\n  --fl-bg: #1b2430;\n  --fl-ink: #f3efe6;\n  --fl-muted: #aab5c3;\n  --fl-accent: #f2b84b;\n  --fl-speed: 8s;\n  position: relative;\n  overflow: hidden;\n  box-sizing: border-box;\n  min-height: 480px;\n  display: flex;\n  align-items: center;\n  justify-content: center;\n  padding: 72px 20px;\n  background: var(--fl-bg);\n  color: var(--fl-ink);\n  font-family: \"Inter Tight\", Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif;\n  -webkit-font-smoothing: antialiased;\n}\n.fl-root *, .fl-root *::before, .fl-root *::after { box-sizing: border-box; }\n.fl-inner { position: relative; z-index: 1; width: 100%; max-width: 1040px; }\n.fl-eyebrow { margin: 0 0 22px; font-family: \"Inter Tight\", Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif; font-size: 13px; font-weight: 600; letter-spacing: .14em; text-transform: uppercase; color: var(--fl-muted); }\n.fl-h { margin: 0; font-size: clamp(42px, 7.8vw, 100px); font-weight: 800; line-height: 1.02; letter-spacing: -.035em; }\n.fl-copy { margin: 28px 0 0; max-width: 34em; font-family: \"Inter Tight\", Inter, ui-sans-serif, system-ui, -apple-system, \"Segoe UI\", sans-serif; font-size: clamp(16px, 1.5vw, 19px); line-height: 1.6; color: var(--fl-muted); }\n.fl-sr { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n.fl-w { display: inline-block; white-space: nowrap; }\n.fl-l { display: inline-block; }\n/* Paused while scrolled out of view (the script sets data-paused). */\n.fl-root[data-paused=\"true\"] *, .fl-root[data-paused=\"true\"] *::before, .fl-root[data-paused=\"true\"] *::after { animation-play-state: paused !important; }\n@media (prefers-reduced-motion: reduce) {\n  .fl-root *, .fl-root *::before, .fl-root *::after { animation: none !important; }\n}\n\n.fl-root { background: linear-gradient(180deg, #222d3b 0%, var(--fl-bg) 60%, #161d27 100%); }\n.fl-h { max-width: 11em; }\n.fl-h .fl-w { perspective: 700px; }\n.fl-h .fl-w:last-child { color: var(--fl-accent); }\n.fl-l {\n  transform-origin: 50% 85%;\n  backface-visibility: hidden;\n  animation: fl-flip var(--fl-speed) infinite both;\n  animation-delay: calc(var(--i) * 34ms);\n}\n@keyframes fl-flip {\n  0% { opacity: 0; transform: rotateX(-100deg); animation-timing-function: cubic-bezier(.25, 1.45, .45, 1); }\n  13% { opacity: 1; transform: rotateX(0); }\n  86% { opacity: 1; transform: rotateX(0); animation-timing-function: cubic-bezier(.55, 0, .75, .4); }\n  96%, 100% { opacity: 0; transform: rotateX(90deg); }\n}\n`;\n\n/** Splits text into words (so lines still wrap) and letters, each letter numbered with --i. */\nfunction Letters({ text }: { text: string }) {\n  let i = 0;\n  return (\n    <span aria-hidden=\"true\">\n      {text.split(\" \").map((word, w) => (\n        <Fragment key={w}>\n          {w > 0 && \" \"}\n          <span className=\"fl-w\">\n            {[...word].map((ch, c) => (\n              <span key={c} className=\"fl-l\" style={{ \"--i\": i++ } as CSSProperties}>\n                {ch}\n              </span>\n            ))}\n          </span>\n        </Fragment>\n      ))}\n    </span>\n  );\n}\n\nexport default function LettersFlippingIntoPlace() {\n  const rootRef = useRef<HTMLElement>(null);\n\n  // Pause the CSS animation while the section is off screen.\n  useEffect(() => {\n    const el = rootRef.current;\n    if (!el || typeof IntersectionObserver === \"undefined\") return;\n    const io = new IntersectionObserver(([entry]) => {\n      el.dataset.paused = entry.isIntersecting ? \"false\" : \"true\";\n    });\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  return (\n    <section ref={rootRef} data-paused=\"false\" className=\"fl-root w-full\">\n      <style>{CSS}</style>\n      <div className=\"fl-inner\">\n        <p className=\"fl-eyebrow\">{BUSINESS}</p>\n        <h2 className=\"fl-h\">\n          <span className=\"fl-sr\">{HEADLINE}</span>\n          <Letters text={HEADLINE} />\n        </h2>\n        <p className=\"fl-copy\">{COPY}</p>\n      </div>\n    </section>\n  );\n}\n"}]}
