{
  "id": "dot-matrix-pulse",
  "kind": "element",
  "title": "Dot matrix pulse",
  "summary": "A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.",
  "url": "https://enrichr.dev/elements/dot-matrix-pulse.html",
  "section": "background",
  "techniques": [
    "stagger"
  ],
  "stack": [
    "Vanilla JS",
    "Canvas"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "technical",
    "calm"
  ],
  "intents": [
    "dot matrix background",
    "pulsing dot grid",
    "animated dot grid hero",
    "glowing dots background loop",
    "ripple dot pattern background"
  ],
  "status": "tested",
  "params": [
    {
      "key": "spacing",
      "label": "Spacing (px)",
      "type": "range",
      "min": 20,
      "max": 90,
      "step": 1,
      "value": 42
    },
    {
      "key": "size",
      "label": "Dot size at rest (px)",
      "type": "range",
      "min": 1,
      "max": 8,
      "step": 0.5,
      "value": 3.5
    },
    {
      "key": "swell",
      "label": "Swell (how much dots grow)",
      "type": "range",
      "min": 0,
      "max": 6,
      "step": 0.1,
      "value": 4.2
    },
    {
      "key": "speed",
      "label": "Speed",
      "type": "range",
      "min": 0.1,
      "max": 2.5,
      "step": 0.05,
      "value": 0.9
    },
    {
      "key": "highlights",
      "label": "Highlight dots (%)",
      "type": "range",
      "min": 0,
      "max": 100,
      "step": 1,
      "value": 25
    },
    {
      "key": "dot",
      "label": "Dot and glow colour",
      "type": "color",
      "value": "#e6ff55"
    },
    {
      "key": "hot",
      "label": "Highlight core",
      "type": "color",
      "value": "#fbf8f1"
    },
    {
      "key": "rim",
      "label": "Dot edges",
      "type": "color",
      "value": "#1a7a4c"
    },
    {
      "key": "background",
      "label": "Background",
      "type": "color",
      "value": "#0c1e18"
    }
  ],
  "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 \"Dot matrix pulse\" element to this project.\n\nThis is the \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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/dot-matrix-pulse.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 \"Dot matrix pulse\" 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 \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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 \"Dot matrix pulse\" element to this codebase.\n\nThis is the \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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-dot-matrix-pulse.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Dot matrix pulse 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 \"Dot matrix pulse\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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- dot-matrix-pulse.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 \"./dot-matrix-pulse\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DotMatrixPulse(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 \"Dot matrix pulse\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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- dot-matrix-pulse.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/DotMatrixPulse.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./dot-matrix-pulse\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DotMatrixPulse(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 \"Dot matrix pulse\" element.\n\nThis is the \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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), dot-matrix-pulse.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 \"Dot matrix pulse\" element. No packages, no server code.\n\nThis is the \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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 dot-matrix-pulse.js and then main.js), style.css (the CSS below), dot-matrix-pulse.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 \"Dot matrix pulse\" 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 \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.json\n\nWhat it does: The dots sit on an even grid, centred in the box, with one extra row and column so the edges are always covered. Each dot gets a start time from its distance to the centre (up to 1.8 seconds) plus a random offset, its own duration of 2.2 to 4.7 seconds, a size to grow to and an opacity to fade to. One clock drives everything: at any moment each dot's progress is clamped between its start and end and eased with a sine in-out curve, and the whole timeline plays forward and then backward, like a GSAP timeline set to repeat and yoyo, so the loop never jumps. The gradient and glow of each dot are drawn once per half-pixel size into a small sprite and reused, so a frame is just one image copy per dot. The random numbers come from each dot's place in the grid, so resizing keeps the same pattern.\nAccessibility: The canvas is decorative and has a text label. With prefers-reduced-motion it draws one still frame from the middle of the ripple and never animates. Nothing flashes: each dot takes two to five seconds to swell. Nothing here needs keyboard input.\n\nTunable settings:\n- Spacing (px): range 20 to 90, step 1, default 42\n- Dot size at rest (px): range 1 to 8, step 0.5, default 3.5\n- Swell (how much dots grow): range 0 to 6, step 0.1, default 4.2\n- Speed: range 0.1 to 2.5, step 0.05, default 0.9\n- Highlight dots (%): range 0 to 100, step 1, default 25\n- Dot and glow colour: color, default #e6ff55\n- Highlight core: color, default #fbf8f1\n- Dot edges: color, default #1a7a4c\n- Background: color, default #0c1e18\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/dot-matrix-pulse.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 \"Dot matrix pulse\" 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 \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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 DotMatrixPulse.\n2. Paste the JavaScript below into a separate code file named dot-matrix-pulse.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 \"./dot-matrix-pulse\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function DotMatrixPulse(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(DotMatrixPulse, {\n  spacing: { type: ControlType.Number, title: \"Spacing\", min: 20, max: 90, step: 1, defaultValue: 42 },\n  size: { type: ControlType.Number, title: \"Dot size at rest\", min: 1, max: 8, step: 0.5, defaultValue: 3.5 },\n  swell: { type: ControlType.Number, title: \"Swell\", min: 0, max: 6, step: 0.1, defaultValue: 4.2 },\n  speed: { type: ControlType.Number, title: \"Speed\", min: 0.1, max: 2.5, step: 0.05, defaultValue: 0.9 },\n  highlights: { type: ControlType.Number, title: \"Highlight dots\", min: 0, max: 100, step: 1, defaultValue: 25 },\n  dot: { type: ControlType.Color, title: \"Dot and glow colour\", defaultValue: \"#e6ff55\" },\n  hot: { type: ControlType.Color, title: \"Highlight core\", defaultValue: \"#fbf8f1\" },\n  rim: { type: ControlType.Color, title: \"Dot edges\", defaultValue: \"#1a7a4c\" },\n  background: { type: ControlType.Color, title: \"Background\", defaultValue: \"#0c1e18\" },\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 \"Dot matrix pulse\" 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 \"Dot matrix pulse\" element from the Enrichr Library: A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back, on a seamless loop.\nPage: https://enrichr.dev/elements/dot-matrix-pulse.html\nMachine-readable spec: https://enrichr.dev/elements/dot-matrix-pulse.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-dot-matrix-pulse\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-dot-matrix-pulse\"), { ...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 canvas is decorative and has a text label. With prefers-reduced-motion it draws one still frame from the middle of the ripple and never animates. Nothing flashes: each dot takes two to five seconds to swell. Nothing here needs keyboard input.",
  "performance": "No filters run per frame: each dot is one drawImage from a cached sprite, so a full-screen grid of about a thousand dots stays light. The grid is capped at about 5,000 dots, the pixel ratio at 2, and the loop pauses off screen or in a hidden tab.",
  "dependencies": [],
  "codepen": "https://codepen.io/Enrichr-Dev/pen/JoWwBmJ",
  "source": {
    "markup": "<div class=\"ef-dm\"><canvas class=\"ef-dm__c\" role=\"img\" aria-label=\"A grid of glowing dots that swell and fade in a slow ripple out from the centre, then settle back\"></canvas></div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-dm { position: relative; width: 100%; min-height: 20rem; overflow: hidden; border-radius: 1rem; background: #0c1e18; }\n.ef-dm__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Dot matrix pulse: a grid of glowing dots that swell and fade in a slow ripple out from the centre, then ease back, on a\n// seamless loop. Each dot starts by its distance from the centre plus a random offset, and has its own duration, size and\n// fade. The whole timeline plays forward, then in reverse, on a sine in-out curve (a yoyo timeline), so the loop has no\n// seam. About one dot in four is a hotter highlight dot. Dots are drawn from cached sprites that hold the gradient and glow.\n// Reduced motion draws one still frame from the middle of the ripple. The loop pauses off screen and in hidden tabs.\n// mount(root, { spacing (px), size (rest radius, px), swell (extra growth), speed, highlights (% of dots),\n//               dot (dot and glow colour), hot (highlight core), rim (dot edges), background })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var wrap = root.querySelector(\".ef-dm\");\n  var canvas = root.querySelector(\".ef-dm__c\");\n  var ctx = canvas.getContext(\"2d\");\n  var opts = {}, raf = 0, visible = true, io = null, ro = null, destroyed = false, last = 0, clock = 0;\n  var W = 1, H = 1, dpr = 1, dots = [], total = 1, sprites = {};\n  var cDot = [230, 255, 85], cHot = [251, 248, 241], cRim = [26, 122, 76];\n  var PAD = 12; // room around each sprite for the glow (8px blur)\n\n  function hex(h, d) { var m = /^#?([0-9a-f]{6})$/i.exec(h || \"\"); var v = parseInt(m ? m[1] : d, 16); return [v >> 16, (v >> 8) & 255, v & 255]; }\n  function rgba(c, a) { return \"rgba(\" + c[0] + \",\" + c[1] + \",\" + c[2] + \",\" + a + \")\"; }\n  function shade(c, k) { return [Math.round(c[0] * k), Math.round(c[1] * k), Math.round(c[2] * k)]; }\n  function num(v, d) { v = Number(v); return isFinite(v) ? v : d; }\n  // stable random number in [0, 1) for a grid position counted from the centre, so a resize keeps the pattern\n  function rand(i, j, salt) {\n    var h = Math.imul(i + 7919 * salt, 374761393) ^ Math.imul(j - 104729 * salt, 668265263);\n    h = Math.imul(h ^ (h >>> 13), 1274126177);\n    return ((h ^ (h >>> 16)) >>> 0) / 4294967296;\n  }\n\n  // one sprite per dot kind and half-pixel radius: the radial gradient with its glow, drawn once and reused every frame\n  function sprite(hot, r) {\n    var q = Math.max(0.5, Math.round(r * 2) / 2), key = (hot ? \"h\" : \"d\") + q;\n    if (sprites[key]) return sprites[key];\n    var half = q + PAD, px = Math.max(2, Math.ceil(half * 2 * dpr)), k = px / (half * 2);\n    var c = document.createElement(\"canvas\"); c.width = c.height = px;\n    var g = c.getContext(\"2d\");\n    g.setTransform(k, 0, 0, k, 0, 0);\n    var grad = g.createRadialGradient(half, half, 0, half, half, q);\n    if (hot) { grad.addColorStop(0, rgba(cHot, 1)); grad.addColorStop(0.6, rgba(cDot, 0.9)); grad.addColorStop(1, rgba(shade(cRim, 0.35), 0.3)); }\n    else { grad.addColorStop(0, rgba(cDot, 1)); grad.addColorStop(0.7, rgba(cRim, 0.8)); grad.addColorStop(1, rgba(shade(cRim, 0.5), 0.2)); }\n    g.shadowColor = rgba(cDot, 0.4); g.shadowBlur = 8 * k; // shadowBlur ignores the transform, so scale it by hand\n    g.fillStyle = grad;\n    g.beginPath(); g.arc(half, half, q, 0, 6.2832); g.fill();\n    return (sprites[key] = { c: c, q: q, half: half });\n  }\n\n  function build() {\n    var s = Math.max(opts.spacing, Math.sqrt(W * H / 5000)); // never more than about 5,000 dots\n    var cols = Math.floor(W / s) + 2, rows = Math.floor(H / s) + 2;\n    var ox = (W - (cols - 1) * s) / 2, oy = (H - (rows - 1) * s) / 2;\n    var cx = W / 2, cy = H / 2, maxD = Math.hypot(cx, cy) || 1, mc = cols >> 1, mr = rows >> 1;\n    dots = []; total = 0.01;\n    for (var r = 0; r < rows; r++) {\n      for (var c = 0; c < cols; c++) {\n        var x = ox + c * s, y = oy + r * s, seed = rand(c - mc, r - mr, 1) * 100;\n        var t0 = Math.hypot(x - cx, y - cy) / maxD * 1.8 + seed % 1.5, d = 2.2 + seed % 2.5;\n        dots.push({ x: x, y: y, t0: t0, d: d, k: 1.1 + (seed % 4.2) / 4.2 * opts.swell, a: 0.25 + seed % 0.75, hot: rand(c - mc, r - mr, 2) * 100 < opts.highlights });\n        if (t0 + d > total) total = t0 + d;\n      }\n    }\n  }\n\n  function frame(t) {\n    var tt = t % (2 * total);\n    if (tt > total) tt = 2 * total - tt; // yoyo: forward, then the same path in reverse\n    ctx.clearRect(0, 0, W, H);\n    for (var i = 0; i < dots.length; i++) {\n      var d = dots[i], p = (tt - d.t0) / d.d;\n      p = p <= 0 ? 0 : p >= 1 ? 1 : p;\n      var e = (1 - Math.cos(Math.PI * p)) / 2; // sine in-out\n      var r = opts.size * (1 + (d.k - 1) * e), sp = sprite(d.hot, r), f = r / sp.q, h = sp.half * f;\n      ctx.globalAlpha = 1 + (d.a - 1) * e;\n      ctx.drawImage(sp.c, d.x - h, d.y - h, h * 2, h * 2);\n    }\n    ctx.globalAlpha = 1;\n  }\n  function still() { frame(total * 0.5); }\n\n  function loop(now) {\n    raf = requestAnimationFrame(loop);\n    var dt = Math.min(0.05, (now - last) / 1000 || 0); last = now;\n    if (!visible || document.hidden) return;\n    clock += dt * opts.speed;\n    frame(clock);\n  }\n  function size() {\n    var nd = Math.min(window.devicePixelRatio || 1, 2);\n    if (nd !== dpr) { dpr = nd; sprites = {}; }\n    W = Math.max(1, wrap.clientWidth); H = Math.max(1, wrap.clientHeight);\n    canvas.width = Math.round(W * dpr); canvas.height = Math.round(H * dpr);\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    build();\n    if (reduce) still(); else frame(clock);\n  }\n  function update(partial) {\n    opts = Object.assign({ spacing: 42, size: 3.5, swell: 4.2, speed: 0.9, highlights: 25, dot: \"#e6ff55\", hot: \"#fbf8f1\", rim: \"#1a7a4c\", background: \"#0c1e18\" }, opts, partial || {});\n    opts.spacing = Math.max(12, num(opts.spacing, 42)); opts.size = Math.max(0.5, num(opts.size, 3.5));\n    opts.swell = Math.max(0, num(opts.swell, 4.2)); opts.speed = Math.max(0, num(opts.speed, 0.9)); opts.highlights = num(opts.highlights, 25);\n    cDot = hex(opts.dot, \"e6ff55\"); cHot = hex(opts.hot, \"fbf8f1\"); cRim = hex(opts.rim, \"1a7a4c\");\n    wrap.style.background = opts.background;\n    sprites = {};\n    if (destroyed) return;\n    build();\n    if (reduce) still(); else frame(clock);\n  }\n\n  update(o);\n  size();\n  if (!reduce) {\n    if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(wrap); }\n    last = performance.now(); raf = requestAnimationFrame(loop);\n  }\n  if (\"ResizeObserver\" in window) { ro = new ResizeObserver(function () { if (!destroyed) size(); }); ro.observe(wrap); }\n  return {\n    update: update,\n    destroy: function () {\n      destroyed = true; cancelAnimationFrame(raf);\n      if (io) io.disconnect();\n      if (ro) ro.disconnect();\n      sprites = {};\n    }\n  };\n}"
  }
}