{
  "id": "distributed-letters-hover",
  "kind": "element",
  "title": "Distributed letters hover",
  "summary": "A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.",
  "url": "https://enrichr.dev/elements/distributed-letters-hover.html",
  "section": "text",
  "techniques": [
    "text-animation",
    "pointer-interaction",
    "stagger"
  ],
  "stack": [
    "Vanilla JS",
    "CSS"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "playful",
    "bold",
    "modern"
  ],
  "intents": [
    "scatter letters on hover",
    "text explode and reassemble animation",
    "spring back headline letters",
    "distributed text layout hover",
    "playful hero headline interaction"
  ],
  "status": "tested",
  "params": [
    {
      "key": "accent",
      "label": "Accent colour",
      "type": "color",
      "value": "#e6ff55"
    },
    {
      "key": "size",
      "label": "Headline size (rem)",
      "type": "range",
      "min": 3,
      "max": 12,
      "step": 0.5,
      "value": 7
    },
    {
      "key": "spread",
      "label": "Spread",
      "type": "range",
      "min": 0.2,
      "max": 1,
      "step": 0.05,
      "value": 1
    },
    {
      "key": "stiffness",
      "label": "Spring stiffness",
      "type": "range",
      "min": 20,
      "max": 300,
      "step": 10,
      "value": 120
    },
    {
      "key": "rotation",
      "label": "Max rotation (deg)",
      "type": "range",
      "min": 0,
      "max": 180,
      "step": 5,
      "value": 40
    }
  ],
  "license": "Free to use in personal and client projects during the preview. Final licence terms will be published here before any paid tier starts; ask before reselling the code as a collection.",
  "contract": "function mount(root, opts) -> { update(partialOpts), destroy() }; root must contain the element markup",
  "exports": {
    "claude": "Add the \"Distributed letters hover\" element to this project.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSteps:\n1. Look at the project first to see its framework and where components, styles and static files live. Follow its conventions.\n2. Fetch https://enrichr.dev/elements/distributed-letters-hover.json if you can read URLs (fields: source.markup, source.css, source.js, params); otherwise use the source at the end of this message.\n3. Add the files, mount it where I tell you (default: the top of the home page), and pass the settings below as the opts.\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n5. Run the dev server and check it. with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "chatgpt": "I want the \"Distributed letters hover\" element on my website. Below is its complete source. Please:\n1. Build one self-contained index.html that I can open locally to see it working (put the CSS in a <style> tag and the JavaScript in a <script> tag, with the markup in the body).\n2. Then explain, step by step, which parts go where in my own site, and how to mount it. My stack is: [tell me yours, or say \"plain HTML\"].\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "cursor": "Add the \"Distributed letters hover\" element to this codebase.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nUse Composer / agent mode. First search the repo for how components, styles and scripts are organised, then add the files in the matching places, mount it on the page I name, and run the app to confirm it works. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.\n\nOptional: save this as .cursor/rules/enrichr-distributed-letters-hover.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Distributed letters hover element\nalwaysApply: false\n---\nmount(root, opts) expects the element markup inside root and returns { update, destroy }. Always call destroy() on unmount and never edit the ef- class names.",
    "v0": "Create a Next.js (App Router) client component for the \"Distributed letters hover\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- distributed-letters-hover.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nUse this component as the wrapper (adjust the import paths):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./distributed-letters-hover\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DistributedLettersHover(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRender it on the home page so I can see it. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "lovable": "Add the \"Distributed letters hover\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles to create:\n- distributed-letters-hover.js : the JavaScript below, with one line appended at the end: export { mount };  (and the markup exported as: export const markup = \"<the markup string>\";). If the project uses TypeScript and does not allow JS imports, put // @ts-nocheck on the first line.\n- the CSS below goes in your global stylesheet (or a plain .css file imported once at the app root). The class names are global and start with ef-.\n\nWrapper component (src/components/DistributedLettersHover.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./distributed-letters-hover\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DistributedLettersHover(props: Record<string, unknown>) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n```\n\nRemove the \"use client\" line if it is not needed. Show it on the home page. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "bolt": "Create a small Vite project (vanilla JavaScript, no framework unless I already have one) that shows the \"Distributed letters hover\" element.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, then a script tag), style.css (the CSS below), distributed-letters-hover.js (the JavaScript below) and main.js that sets the container's innerHTML to the markup and calls mount(container, opts) with the settings below. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}\n\nVerify: with reduced motion on, nothing moves; it works at 375px wide and with touch only; there are no console errors; scrolling stays smooth; destroy() is called when it unmounts.",
    "replit": "Create a new HTML, CSS and JavaScript Repl that shows the \"Distributed letters hover\" element. No packages, no server code.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nFiles: index.html (a container element, link style.css, load distributed-letters-hover.js and then main.js), style.css (the CSS below), distributed-letters-hover.js (the JavaScript below), main.js (sets the container's innerHTML to the markup, then calls mount(container, opts) with the settings below). Press Run to preview. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "figma": "Designer handoff notes for the \"Distributed letters hover\" element (Enrichr Library). Figma cannot run this JavaScript inside a design file, so use it as a motion reference and hand the code to a developer.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nWhat it does: The word is split into one inline-block span per letter. On hover the script measures each letter's home centre, shuffles the cells of a grid sized to the stage, and gives every letter its own cell with a little jitter, so the letters spread evenly instead of piling up. Each letter then runs a small spring toward its target offset and rotation, started with a short stagger. Leaving the stage sets every target back to zero and the springs pull the letters home. The loop stops once every letter is at rest.\nAccessibility: The headline has an accessible name and the individual letters are hidden from assistive tech, so it reads as one word however scattered it is. The button toggles the scatter with aria-pressed, which gives keyboard and touch users the same effect as hover, and Escape gathers the letters. Under reduced motion the letters never move; the state shows by colour only.\n\nTunable settings:\n- Accent colour: color, default #e6ff55\n- Headline size (rem): range 3 to 12, step 0.5, default 7\n- Spread: range 0.2 to 1, step 0.05, default 1\n- Spring stiffness: range 20 to 300, step 10, default 120\n- Max rotation (deg): range 0 to 180, step 5, default 40\n\nCurrent settings:\n{{SETTINGS}}\n\nFor the developer: Element contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\nIn Figma:\n- Draw the resting state as a frame and the end state as a second frame; link them with Smart Animate to show the motion in a prototype.\n- Put the settings above in the frame's notes or Dev Mode annotations so the developer matches them.\n- Link https://enrichr.dev/elements/distributed-letters-hover.html in the handoff: the live demo and the copy-ready code are there. Developers can paste the prompts for Claude, Cursor or v0 from the Export menu.\nNothing is copied from another designer's file; this is original code from Enrichr.",
    "framer": "Add the \"Distributed letters hover\" element to Framer as a code component. Framer code components are React, so wrap the vanilla code like this. Check it in the Framer editor, as Framer's component API can change.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. In Framer: Assets > Code > New component. Name it DistributedLettersHover.\n2. Paste the JavaScript below into a separate code file named distributed-letters-hover.js in the same project, with  export { mount };  and  export const markup = \"<the markup string>\";  added. Put the CSS into the component as a <style> tag.\n3. Component:\n```tsx\nimport { addPropertyControls, ControlType } from \"framer\"\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./distributed-letters-hover\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DistributedLettersHover(props: any) {\n  const ref = useRef<HTMLDivElement>(null);\n  const fx = useRef<{ update: (o: object) => void; destroy: () => void } | null>(null);\n  useEffect(() => {\n    const root = ref.current;\n    if (!root) return;\n    root.innerHTML = markup;\n    fx.current = mount(root, props);\n    return () => { fx.current?.destroy(); fx.current = null; root.innerHTML = \"\"; };\n  }, []);\n  useEffect(() => { fx.current?.update(props); }, [JSON.stringify(props)]);\n  return <div ref={ref} />;\n}\n\naddPropertyControls(DistributedLettersHover, {\n  accent: { type: ControlType.Color, title: \"Accent colour\", defaultValue: \"#e6ff55\" },\n  size: { type: ControlType.Number, title: \"Headline size\", min: 3, max: 12, step: 0.5, defaultValue: 7 },\n  spread: { type: ControlType.Number, title: \"Spread\", min: 0.2, max: 1, step: 0.05, defaultValue: 1 },\n  stiffness: { type: ControlType.Number, title: \"Spring stiffness\", min: 20, max: 300, step: 10, defaultValue: 120 },\n  rotation: { type: ControlType.Number, title: \"Max rotation\", min: 0, max: 180, step: 5, defaultValue: 40 },\n})\n```\n4. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}",
    "webflow": "Add the \"Distributed letters hover\" element to a Webflow site with an Embed element. Test it on the published or preview site: scripts in embeds may not run inside the Designer canvas.\n\nThis is the \"Distributed letters hover\" element from the Enrichr Library: A big headline whose letters scatter evenly across the stage on hover or button press, then spring back into the word.\nPage: https://enrichr.dev/elements/distributed-letters-hover.html\nMachine-readable spec: https://enrichr.dev/elements/distributed-letters-hover.json\n\nElement contract (vanilla JavaScript, no dependencies):\n- The JavaScript defines a function mount(root, opts).\n- root is an empty container element. Set root.innerHTML to the markup first, then call mount(root, opts).\n- It returns an object with update(partialOpts) and destroy(). Call destroy() when the element is removed. Some elements also return replay().\n- The CSS classes all start with \"ef-\" so they will not collide with your styles.\n\n1. Add an Embed element where it should appear. Paste a <style> block with the CSS, one container <div id=\"enrichr-distributed-letters-hover\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-distributed-letters-hover\"), { ...your settings... });\n   (set the container's innerHTML to the markup first, as in the contract).\n2. Embed elements have a size limit (check Webflow's current number). If the code is longer, host the JS and CSS as files and link them from Custom code in the page settings, then keep only the container and the mount call in the Embed.\n3. Keep the behaviour of the source unchanged. Do not add dependencies. Respect prefers-reduced-motion. Keep text as real HTML.\n\nSettings:\n{{SETTINGS}}\n\nSource:\n{{CODE}}"
  },
  "exportTools": [
    "claude",
    "chatgpt",
    "cursor",
    "v0",
    "lovable",
    "bolt",
    "replit",
    "figma",
    "framer",
    "webflow"
  ],
  "accessibility": "The headline has an accessible name and the individual letters are hidden from assistive tech, so it reads as one word however scattered it is. The button toggles the scatter with aria-pressed, which gives keyboard and touch users the same effect as hover, and Escape gathers the letters. Under reduced motion the letters never move; the state shows by colour only.",
  "performance": "Per frame it writes one transform per letter, and only while something is moving. Letter positions are measured on mount and on resize, not per frame. Keep the word short; the cost grows with the number of letters.",
  "dependencies": [],
  "source": {
    "markup": "<div class=\"ef-dl\">\n  <div class=\"ef-dl__wrap\">\n    <div class=\"ef-dl__stage\">\n      <div class=\"ef-dl__word\" role=\"img\" aria-label=\"Disperse\"></div>\n    </div>\n    <div class=\"ef-dl__bar\">\n      <button type=\"button\" class=\"ef-dl__btn\" aria-pressed=\"false\">Scatter letters</button>\n      <span class=\"ef-dl__hint\">Hover the stage, or press the button</span>\n    </div>\n  </div>\n</div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-dl { width: 100%; }\n.ef-dl__wrap { --sz: 7; box-sizing: border-box; width: 100%; min-height: 19rem; padding: 1rem; border-radius: 1rem; display: flex; flex-direction: column; gap: 0.7rem; overflow: hidden; font-family: system-ui, -apple-system, \"Segoe UI\", Roboto, sans-serif; color: #fbf8f1; }\n.ef-dl__stage { position: relative; flex: 1; min-height: 14rem; display: flex; align-items: center; justify-content: center; overflow: hidden; border-radius: 0.8rem; }\n.ef-dl__word { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; font-size: clamp(2.2rem, calc(var(--sz) * 1rem), 22vw); font-weight: 900; line-height: 1; letter-spacing: -0.02em; text-transform: uppercase; }\n.ef-dl__ch { display: inline-block; will-change: transform; color: #fbf8f1; transition: color 300ms; }\n.ef-dl__wrap.is-on .ef-dl__ch:nth-child(odd) { color: var(--ef-acc, #e6ff55); }\n.ef-dl__bar { display: flex; align-items: center; gap: 0.8rem; flex-wrap: wrap; }\n.ef-dl__btn { font: inherit; font-size: 0.8rem; font-weight: 700; letter-spacing: 0.04em; padding: 0.55rem 1rem; border-radius: 999px; border: 1px solid rgba(251, 248, 241, 0.35); background: transparent; color: inherit; cursor: pointer; transition: background 200ms, color 200ms; }\n.ef-dl__btn:hover, .ef-dl__btn[aria-pressed=\"true\"] { background: var(--ef-acc, #e6ff55); color: #0c1e18; border-color: transparent; }\n.ef-dl__btn:focus-visible { outline: 2px solid var(--ef-acc, #e6ff55); outline-offset: 3px; }\n.ef-dl__hint { font-size: 0.72rem; opacity: 0.65; letter-spacing: 0.03em; }\n@media (prefers-reduced-motion: reduce) { .ef-dl__ch, .ef-dl__btn { transition: none; } }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Distributed letters hover: a big headline whose letters scatter across the stage on hover (or when the button is pressed), each landing in\n// its own cell of a shuffled grid so they spread evenly, then spring back into the word. A small per-letter spring runs in rAF only while\n// something moves. Reduced motion: letters stay put and the state is shown with colour only. The button is the keyboard and touch route.\n// mount(root, { background, accent, size (rem), spread (0-1), stiffness (20-300), rotation (deg) })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var wrap = root.querySelector(\".ef-dl__wrap\");\n  var stage = root.querySelector(\".ef-dl__stage\");\n  var word = root.querySelector(\".ef-dl__word\");\n  var btn = root.querySelector(\".ef-dl__btn\");\n  var WORD = \"Disperse\";\n  var opts = {}, L = [], offs = [], raf = 0, last = 0, ro = null;\n  var hover = false, pinned = false, scattered = false;\n\n  function on(el, ev, fn) { el.addEventListener(ev, fn); offs.push(function () { el.removeEventListener(ev, fn); }); }\n  function stop() { if (raf) cancelAnimationFrame(raf); raf = 0; }\n  function rnd(a, b) { return a + Math.random() * (b - a); }\n\n  function homes() {\n    L.forEach(function (l) { l.hx = l.el.offsetLeft + l.el.offsetWidth / 2; l.hy = l.el.offsetTop + l.el.offsetHeight / 2; l.hw = l.el.offsetWidth; l.hh = l.el.offsetHeight; });\n  }\n  // Give each letter its own cell of a shuffled grid; the offset is cell centre minus home, scaled by spread.\n  function targets(stagger) {\n    var sw = stage.clientWidth, sh = stage.clientHeight, n = L.length, i, j, t;\n    var cols = Math.max(1, Math.round(Math.sqrt(n * sw / Math.max(1, sh)))), rows = Math.ceil(n / cols);\n    var cw = sw / cols, ch = sh / rows, cells = [];\n    for (i = 0; i < cols * rows; i++) cells.push(i);\n    for (i = cells.length - 1; i > 0; i--) { j = Math.floor(Math.random() * (i + 1)); t = cells[i]; cells[i] = cells[j]; cells[j] = t; }\n    var now = performance.now();\n    L.forEach(function (l, k) {\n      var c = cells[k], cx = (c % cols + 0.5) * cw + rnd(-0.25, 0.25) * cw, cy = (Math.floor(c / cols) + 0.5) * ch + rnd(-0.25, 0.25) * ch;\n      cx = Math.max(l.hw / 2, Math.min(sw - l.hw / 2, cx)); cy = Math.max(l.hh / 2, Math.min(sh - l.hh / 2, cy));\n      l.px = (cx - l.hx) * opts.spread;\n      l.py = (cy - l.hy) * opts.spread;\n      l.pr = rnd(-1, 1) * opts.rotation;\n      l.at = stagger ? now + k * 28 : now;\n      l.pend = true;\n    });\n  }\n  function release() {\n    var now = performance.now();\n    L.forEach(function (l, k) { l.px = 0; l.py = 0; l.pr = 0; l.at = now + k * 22; l.pend = true; });\n  }\n  function paint(l) { l.el.style.transform = \"translate3d(\" + l.x.toFixed(1) + \"px,\" + l.y.toFixed(1) + \"px,0) rotate(\" + l.r.toFixed(1) + \"deg)\"; }\n  function tick(t) {\n    var dt = Math.min(0.04, (t - last) / 1000); last = t;\n    var k = opts.stiffness, c = 2 * Math.sqrt(k) * 0.42, moving = false;\n    L.forEach(function (l) {\n      if (l.pend && t >= l.at) { l.tx = l.px; l.ty = l.py; l.tr = l.pr; l.pend = false; }\n      if (l.pend) { moving = true; return; }\n      l.vx += ((l.tx - l.x) * k - l.vx * c) * dt; l.x += l.vx * dt;\n      l.vy += ((l.ty - l.y) * k - l.vy * c) * dt; l.y += l.vy * dt;\n      l.vr += ((l.tr - l.r) * k - l.vr * c) * dt; l.r += l.vr * dt;\n      if (Math.abs(l.tx - l.x) + Math.abs(l.ty - l.y) + Math.abs(l.tr - l.r) > 0.25 || Math.abs(l.vx) + Math.abs(l.vy) + Math.abs(l.vr) > 0.5) moving = true;\n      else { l.x = l.tx; l.y = l.ty; l.r = l.tr; l.vx = l.vy = l.vr = 0; }\n      paint(l);\n    });\n    raf = moving ? requestAnimationFrame(tick) : 0;\n  }\n  function kick() { if (!raf) { last = performance.now(); raf = requestAnimationFrame(tick); } }\n  function sync() {\n    var want = hover || pinned;\n    btn.setAttribute(\"aria-pressed\", pinned ? \"true\" : \"false\");\n    btn.textContent = pinned ? \"Gather letters\" : \"Scatter letters\";\n    if (want === scattered) return;\n    scattered = want;\n    wrap.classList.toggle(\"is-on\", scattered);\n    if (reduce) return;\n    if (scattered) targets(true); else release();\n    kick();\n  }\n  function build() {\n    word.textContent = \"\"; L = [];\n    WORD.split(\"\").forEach(function (ch) {\n      var s = document.createElement(\"span\");\n      s.className = \"ef-dl__ch\"; s.setAttribute(\"aria-hidden\", \"true\"); s.textContent = ch;\n      word.appendChild(s);\n      L.push({ el: s, x: 0, y: 0, r: 0, vx: 0, vy: 0, vr: 0, tx: 0, ty: 0, tr: 0, px: 0, py: 0, pr: 0, at: 0, pend: false, hx: 0, hy: 0, hw: 0, hh: 0 });\n    });\n    homes();\n  }\n  function relayout() {\n    if (!L.length) return;\n    L.forEach(function (l) { l.el.style.transform = \"\"; l.x = l.y = l.r = l.vx = l.vy = l.vr = 0; });\n    homes();\n    if (scattered && !reduce) { targets(false); kick(); }\n  }\n  function update(next) {\n    opts = Object.assign({ background: \"#0c1e18\", accent: \"#e6ff55\", size: 7, spread: 1, stiffness: 120, rotation: 40 }, opts, next || {});\n    wrap.style.background = opts.background;\n    wrap.style.setProperty(\"--ef-acc\", opts.accent);\n    wrap.style.setProperty(\"--sz\", String(opts.size));\n    if (L.length) { homes(); if (scattered && !reduce) { targets(false); kick(); } }\n  }\n  update(o);\n  build();\n  on(stage, \"pointerenter\", function (e) { if (e.pointerType === \"touch\") return; hover = true; sync(); });\n  on(stage, \"pointerleave\", function () { hover = false; sync(); });\n  on(btn, \"click\", function () { pinned = !pinned; sync(); });\n  on(root, \"keydown\", function (e) { if (e.key === \"Escape\" && (pinned || hover)) { pinned = false; hover = false; sync(); } });\n  if (typeof ResizeObserver !== \"undefined\") { ro = new ResizeObserver(relayout); ro.observe(stage); }\n  else { window.addEventListener(\"resize\", relayout); offs.push(function () { window.removeEventListener(\"resize\", relayout); }); }\n  function destroy() { stop(); offs.forEach(function (f) { f(); }); offs = []; if (ro) ro.disconnect(); ro = null; }\n  return { update: update, destroy: destroy };\n}"
  }
}