{"$schema":"https://ui.shadcn.com/schema/registry-item.json","name":"calm-letter-decode-scramble-text-reveal","type":"registry:block","title":"Calm Letter Decode Scramble","description":"Free text scramble effect in React and plain JavaScript: soft placeholder marks settle into a headline left to right, with no layout jump and a screen reader copy.","dependencies":["framer-motion","lucide-react"],"files":[{"path":"components/we-inc/calm-letter-decode-scramble-text-reveal.tsx","type":"registry:component","content":"import { useEffect, useRef, useState } from \"react\";\nimport { useReducedMotion } from \"framer-motion\";\nimport { RotateCcw } from \"lucide-react\";\n\n// The sentence that decodes, and the quiet characters it passes through.\nconst HEADLINE = \"Every coastline, decoded by hand.\";\nconst CALM = \"·:-=~+/.\";\nconst STEP_MS = 34; // delay between one letter settling and the next\nconst FLICKER_MS = 70; // how often an unsettled slot changes character\nconst HOLD_MS = 5200; // how long the finished line rests before decoding again\n\n// Word boundaries, so a scrambled \"-\" or \"/\" can never open a new line break.\nconst WORDS = HEADLINE.split(\" \").reduce<{ start: number; len: number }[]>((acc, word) => {\n  const prev = acc[acc.length - 1];\n  return [...acc, { start: prev ? prev.start + prev.len + 1 : 0, len: word.length }];\n}, []);\n\ntype Slot = { ch: string; done: boolean };\n\nconst settled = (): Slot[] => [...HEADLINE].map((ch) => ({ ch, done: true }));\nconst pick = () => CALM[Math.floor(Math.random() * CALM.length)];\n\nexport default function CalmLetterDecodeScrambleTextReveal() {\n  const reduce = useReducedMotion();\n  const rootRef = useRef<HTMLElement>(null);\n  const [slots, setSlots] = useState<Slot[]>(() =>\n    [...HEADLINE].map((ch) => ({ ch: ch === \" \" ? \" \" : pick(), done: ch === \" \" })),\n  );\n  const [run, setRun] = useState(0);\n  const [visible, setVisible] = useState(true);\n\n  useEffect(() => {\n    const el = rootRef.current;\n    if (!el) return;\n    const io = new IntersectionObserver(([e]) => setVisible(e.isIntersecting));\n    io.observe(el);\n    return () => io.disconnect();\n  }, []);\n\n  useEffect(() => {\n    if (reduce) {\n      setSlots(settled());\n      return;\n    }\n    if (!visible) return;\n    let start = performance.now();\n    const timer = window.setInterval(() => {\n      const t = performance.now() - start;\n      const end = 160 + HEADLINE.length * STEP_MS;\n      if (t > end + HOLD_MS) start = performance.now();\n      setSlots(\n        [...HEADLINE].map((ch, i) => {\n          const done = ch === \" \" || t > 160 + i * STEP_MS;\n          return { ch: done ? ch : pick(), done };\n        }),\n      );\n    }, FLICKER_MS);\n    return () => window.clearInterval(timer);\n  }, [reduce, visible, run]);\n\n  return (\n    <section ref={rootRef} className=\"lds-root relative overflow-hidden px-5 py-20 sm:px-10 sm:py-28\">\n      <style>{`\n        .lds-root { background: radial-gradient(120% 90% at 20% 0%, #16302f 0%, #0d1a1c 55%, #0a1315 100%); color: #efe6d2; }\n        .lds-grain { position: absolute; inset: 0; opacity: .5; pointer-events: none;\n          background-image: radial-gradient(rgba(239,230,210,.05) 1px, transparent 1px); background-size: 3px 3px; }\n        .lds-stack { display: grid; }\n        .lds-stack > * { grid-area: 1 / 1; }\n        .lds-line { font-family: ui-monospace, \"SF Mono\", Menlo, Consolas, monospace; font-weight: 600;\n          font-size: clamp(1.7rem, 5.4vw, 3.6rem); line-height: 1.15; letter-spacing: -.01em; }\n        .lds-ghost { visibility: hidden; }\n        .lds-ch { transition: color .35s ease, opacity .35s ease; }\n        .lds-ch[data-done=\"false\"] { color: #7fa39c; opacity: .55; }\n        .lds-ch[data-done=\"true\"] { color: #efe6d2; }\n        @keyframes lds-caret { 50% { opacity: 0 } }\n        .lds-caret { display: inline-block; width: .5ch; height: .9em; margin-left: .15ch; vertical-align: -.08em;\n          background: #d9a45b; animation: lds-caret 1.1s steps(1) infinite; }\n        @media (prefers-reduced-motion: reduce) { .lds-caret { animation: none; } .lds-ch { transition: none; } }\n      `}</style>\n      <div className=\"lds-grain\" aria-hidden=\"true\" />\n      <div className=\"relative mx-auto max-w-4xl\">\n        <p className=\"text-sm font-medium uppercase tracking-[0.2em] text-[#d9a45b]\">Tidewater Map Archive</p>\n        <h1 className=\"lds-line mt-5\">\n          <span className=\"sr-only\">{HEADLINE}</span>\n          <span className=\"lds-stack\" aria-hidden=\"true\">\n            <span className=\"lds-ghost\">{HEADLINE}<span className=\"lds-caret\" /></span>\n            <span>\n              {WORDS.map(({ start, len }, w) => (\n                <span key={w}>\n                  {w > 0 && \" \"}\n                  <span className=\"whitespace-nowrap\">\n                    {slots.slice(start, start + len).map((s, i) => (\n                      <span key={i} className=\"lds-ch\" data-done={s.done}>{s.ch}</span>\n                    ))}\n                  </span>\n                </span>\n              ))}\n              <span className=\"lds-caret\" />\n            </span>\n          </span>\n        </h1>\n        <p className=\"mt-6 max-w-xl text-base leading-relaxed text-[#c9c2b0] sm:text-lg\">\n          Four hundred hand-drawn charts of the northern shore, scanned at full size and transcribed line by line.\n        </p>\n        <div className=\"mt-9 flex flex-wrap items-center gap-3\">\n          <a href=\"#\" className=\"inline-flex min-h-[44px] items-center rounded-full bg-[#efe6d2] px-6 text-sm font-semibold text-[#0d1a1c] transition hover:bg-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#d9a45b] focus-visible:ring-offset-2 focus-visible:ring-offset-[#0d1a1c]\">\n            Browse the charts\n          </a>\n          <button\n            type=\"button\"\n            onClick={() => setRun((n) => n + 1)}\n            className=\"inline-flex min-h-[44px] items-center gap-2 rounded-full px-4 text-sm font-medium text-[#c9c2b0] transition hover:text-white focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-[#d9a45b]\"\n          >\n            <RotateCcw aria-hidden=\"true\" className=\"h-4 w-4\" /> Replay\n          </button>\n        </div>\n      </div>\n    </section>\n  );\n}\n"}]}
