{
  "id": "ribbon-pointer-trail",
  "kind": "element",
  "title": "Ribbon pointer trail",
  "summary": "A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.",
  "url": "https://enrichr.dev/elements/ribbon-pointer-trail.html",
  "section": "background",
  "techniques": [
    "pointer-interaction"
  ],
  "stack": [
    "Vanilla JS",
    "Canvas"
  ],
  "frameworks": [
    "React",
    "Next.js",
    "Vanilla"
  ],
  "mood": [
    "fluid",
    "playful"
  ],
  "intents": [
    "mouse trail ribbon effect",
    "gradient cursor trail",
    "smooth pointer trail canvas",
    "snake trail following mouse",
    "interactive background cursor ribbon"
  ],
  "status": "tested",
  "params": [
    {
      "key": "segments",
      "label": "Links in the ribbon",
      "type": "range",
      "min": 30,
      "max": 400,
      "step": 1,
      "value": 200
    },
    {
      "key": "width",
      "label": "Max width (px)",
      "type": "range",
      "min": 10,
      "max": 200,
      "step": 1,
      "value": 100
    },
    {
      "key": "drag",
      "label": "Drag (higher is longer)",
      "type": "range",
      "min": 1.5,
      "max": 10,
      "step": 0.1,
      "value": 3.5
    },
    {
      "key": "glide",
      "label": "Glide to pointer (s)",
      "type": "range",
      "min": 0.05,
      "max": 1.5,
      "step": 0.05,
      "value": 0.3
    },
    {
      "key": "idle",
      "label": "Idle demo loop",
      "type": "select",
      "options": [
        [
          "on",
          "On"
        ],
        [
          "off",
          "Off"
        ]
      ],
      "value": "on"
    },
    {
      "key": "speed",
      "label": "Idle loop speed",
      "type": "range",
      "min": 0.2,
      "max": 3,
      "step": 0.05,
      "value": 1
    },
    {
      "key": "head",
      "label": "Head colour",
      "type": "color",
      "value": "#e6ff55"
    },
    {
      "key": "tail",
      "label": "Tail colour",
      "type": "color",
      "value": "#1a7a4c"
    },
    {
      "key": "middle",
      "label": "Middle stop",
      "type": "select",
      "options": [
        [
          "none",
          "None"
        ],
        [
          "violet",
          "Violet"
        ],
        [
          "terracotta",
          "Terracotta"
        ]
      ],
      "value": "none"
    },
    {
      "key": "background",
      "label": "Background",
      "type": "color",
      "value": "#050d0a"
    }
  ],
  "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 \"Ribbon pointer trail\" element to this project.\n\nThis is the \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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/ribbon-pointer-trail.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 \"Ribbon pointer trail\" 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 \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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 \"Ribbon pointer trail\" element to this codebase.\n\nThis is the \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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-ribbon-pointer-trail.mdc so the rule stays with the project:\n---\ndescription: How to use the Enrichr Ribbon pointer trail 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 \"Ribbon pointer trail\" element. Tailwind is available but this component needs no utility classes.\n\nThis is the \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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- ribbon-pointer-trail.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 \"./ribbon-pointer-trail\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function RibbonPointerTrail(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 \"Ribbon pointer trail\" element to this React + Vite + TypeScript + Tailwind project. Do not install any packages.\n\nThis is the \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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- ribbon-pointer-trail.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/RibbonPointerTrail.tsx):\n```tsx\n\"use client\";\nimport { useEffect, useRef } from \"react\";\nimport { markup, mount } from \"./ribbon-pointer-trail\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function RibbonPointerTrail(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 \"Ribbon pointer trail\" element.\n\nThis is the \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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), ribbon-pointer-trail.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 \"Ribbon pointer trail\" element. No packages, no server code.\n\nThis is the \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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 ribbon-pointer-trail.js and then main.js), style.css (the CSS below), ribbon-pointer-trail.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 \"Ribbon pointer trail\" 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 \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.json\n\nWhat it does: A target point glides to the pointer over 0.3 seconds on a power1.out curve, and every new pointer move restarts that glide from wherever the target is, which is what GSAP's quickTo does. Behind it hangs a chain of 200 points. Every frame each point moves a 3.5th of the way towards the point ahead of it, so the chain lags further the further back you go. Each link is drawn as one round-capped line. Its width climbs from 1 pixel at the head to the full width in the middle and back down to 1 pixel at the tail, and is multiplied by the link's own length capped at one pixel, so the ribbon is fat while you move and shrinks to nothing when you stop. Colours run from the head colour to the tail colour, through violet or terracotta if you pick a middle stop. Links are painted from the tail forward so the thin head sits on top. With the idle demo on, a virtual pointer traces a slow loop while nobody is pointing.\nAccessibility: The canvas is decorative and has a text label. With prefers-reduced-motion it draws one still ribbon and ignores the pointer and the idle loop. Nothing flashes. There is nothing to operate, so no keyboard input is needed.\n\nTunable settings:\n- Links in the ribbon: range 30 to 400, step 1, default 200\n- Max width (px): range 10 to 200, step 1, default 100\n- Drag (higher is longer): range 1.5 to 10, step 0.1, default 3.5\n- Glide to pointer (s): range 0.05 to 1.5, step 0.05, default 0.3\n- Idle demo loop: select (On / Off), default on\n- Idle loop speed: range 0.2 to 3, step 0.05, default 1\n- Head colour: color, default #e6ff55\n- Tail colour: color, default #1a7a4c\n- Middle stop: select (None / Violet / Terracotta), default none\n- Background: color, default #050d0a\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/ribbon-pointer-trail.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 \"Ribbon pointer trail\" 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 \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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 RibbonPointerTrail.\n2. Paste the JavaScript below into a separate code file named ribbon-pointer-trail.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 \"./ribbon-pointer-trail\"; // markup is the HTML string; mount is the JavaScript's mount function\n\nexport default function RibbonPointerTrail(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(RibbonPointerTrail, {\n  segments: { type: ControlType.Number, title: \"Links in the ribbon\", min: 30, max: 400, step: 1, defaultValue: 200 },\n  width: { type: ControlType.Number, title: \"Max width\", min: 10, max: 200, step: 1, defaultValue: 100 },\n  drag: { type: ControlType.Number, title: \"Drag\", min: 1.5, max: 10, step: 0.1, defaultValue: 3.5 },\n  glide: { type: ControlType.Number, title: \"Glide to pointer\", min: 0.05, max: 1.5, step: 0.05, defaultValue: 0.3 },\n  idle: { type: ControlType.Enum, title: \"Idle demo loop\", options: [\"on\",\"off\"], optionTitles: [\"On\",\"Off\"], defaultValue: \"on\" },\n  speed: { type: ControlType.Number, title: \"Idle loop speed\", min: 0.2, max: 3, step: 0.05, defaultValue: 1 },\n  head: { type: ControlType.Color, title: \"Head colour\", defaultValue: \"#e6ff55\" },\n  tail: { type: ControlType.Color, title: \"Tail colour\", defaultValue: \"#1a7a4c\" },\n  middle: { type: ControlType.Enum, title: \"Middle stop\", options: [\"none\",\"violet\",\"terracotta\"], optionTitles: [\"None\",\"Violet\",\"Terracotta\"], defaultValue: \"none\" },\n  background: { type: ControlType.Color, title: \"Background\", defaultValue: \"#050d0a\" },\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 \"Ribbon pointer trail\" 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 \"Ribbon pointer trail\" element from the Enrichr Library: A smooth lime-to-green ribbon chases the pointer, swelling while you move and melting away when you stop.\nPage: https://enrichr.dev/elements/ribbon-pointer-trail.html\nMachine-readable spec: https://enrichr.dev/elements/ribbon-pointer-trail.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-ribbon-pointer-trail\"></div>, and a <script> block with the JavaScript followed by:\n   mount(document.getElementById(\"enrichr-ribbon-pointer-trail\"), { ...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 ribbon and ignores the pointer and the idle loop. Nothing flashes. There is nothing to operate, so no keyboard input is needed.",
  "performance": "One canvas, one short line per link, no filters or shadows, so 200 links cost very little. The pixel ratio is capped at 2 and the loop pauses off screen and in hidden tabs. Touch scrolling still works because the element only claims horizontal drags.",
  "dependencies": [],
  "codepen": "https://codepen.io/Enrichr-Dev/pen/ZYeVjNO",
  "source": {
    "markup": "<div class=\"ef-rpt\"><canvas class=\"ef-rpt__c\" role=\"img\" aria-label=\"A smooth ribbon that trails the pointer, fading from lime to green, thick in the middle and tapering at both ends\"></canvas></div>",
    "css": "/* Enrichr Library · https://enrichr.dev */\n.ef-rpt { position: relative; width: 100%; height: 100%; min-height: 26rem; overflow: hidden; border-radius: 1rem; background: #050d0a; touch-action: pan-y; }\n.ef-rpt .ef-rpt__c { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }",
    "js": "// Enrichr Library · https://enrichr.dev\n// Ribbon pointer trail: a smooth gradient ribbon that chases the pointer. A chain of 200 points follows a target that glides\n// to the pointer in 0.3 s on a power1.out curve (GSAP's quickTo, re-implemented). Every frame each point moves 1/3.5 of the\n// way to the point ahead of it, and each link of the chain is drawn as a round-capped line whose width rises from 1 px at\n// the head to the full width in the middle and back down at the tail (GSAP's wrapYoyo), scaled by the link's length, so\n// the ribbon swells while you move and melts away when you stop. The head is lime, the tail green, with an optional violet\n// or terracotta stop in the middle. With idle on, a virtual pointer loops through the box while no one is pointing.\n// Reduced motion draws one still ribbon and ignores the pointer. The loop pauses off screen and in hidden tabs.\n// mount(root, { segments (links in the chain), width (max ribbon width, px), drag (chain lag, higher = longer),\n//               glide (seconds for the target to reach the pointer), idle (on | off), speed (idle loop speed),\n//               head (colour), tail (colour), middle (none | violet | terracotta), background })\nfunction mount(root, o) {\n  var reduce = window.matchMedia(\"(prefers-reduced-motion: reduce)\").matches;\n  var wrap = root.querySelector(\".ef-rpt\");\n  var canvas = root.querySelector(\".ef-rpt__c\");\n  var ctx = canvas.getContext(\"2d\");\n  var MIDS = { violet: \"#4b1a9a\", terracotta: \"#e54c1e\" };\n  var opts = {}, raf = 0, visible = true, io = null, ro = null, destroyed = false, last = 0;\n  var W = 1, H = 1, dpr = 1, pts = [], widths = [], cols = [], n = 0;\n  var m = { x: 0, y: 0 }, qx = null, qy = null, inside = false, lastReal = -1e9, phase = 0;\n\n  function num(v, d) { v = Number(v); return isFinite(v) ? v : d; }\n  function hex(h, d) { var r = /^#?([0-9a-f]{6})$/i.exec(h || \"\"); var v = parseInt(r ? r[1] : d, 16); return [v >> 16, (v >> 8) & 255, v & 255]; }\n  function mix(a, b, t) { return [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t]; }\n  // gsap.utils.wrapYoyo(min, max, value): bounces value back and forth between min and max\n  function wrapYoyo(min, max, v) { var range = max - min, total = range * 2; v = (total + (v - min) % total) % total || 0; return min + (v > range ? total - v : v); }\n\n  // gsap.quickTo(m, \"x\", { duration }) re-implemented: every call restarts a tween from the current value to the new one\n  function ease(p) { return 1 - (1 - p) * (1 - p); } // power1.out, GSAP's default ease\n  function qval(q, now) { if (!q) return 0; var p = Math.min(1, (now - q.t0) / (q.d * 1000)); return p >= 1 ? q.to : q.from + (q.to - q.from) * ease(p); }\n  function qto(q, v, now) { var cur = q ? qval(q, now) : v; return { from: cur, to: v, t0: now, d: Math.max(0.001, opts.glide) }; }\n  function aim(x, y, now) { qx = qto(qx, x, now); qy = qto(qy, y, now); }\n\n  function build(keep) {\n    var nn = Math.max(3, Math.round(opts.segments));\n    if (!keep || nn !== n) {\n      var old = pts; pts = [];\n      for (var i = 0; i < nn; i++) {\n        // the original scatters the chain across the page first, so it gathers on the first frames\n        pts.push(old[i] ? old[i] : { x: W * Math.random(), y: (1 - i / nn) * H });\n      }\n      n = nn;\n    }\n    var peak = n / 2, hc = hex(opts.head, \"e6ff55\"), tc = hex(opts.tail, \"1a7a4c\"), mc = MIDS[opts.middle] ? hex(MIDS[opts.middle]) : null;\n    widths = []; cols = [];\n    for (var j = 0; j < n; j++) {\n      widths.push(wrapYoyo(1, peak, j) / peak * opts.width); // 1 px at the ends, full width in the middle, like the original\n      var t = j / (n - 1), c;\n      if (mc) c = t < 0.5 ? mix(hc, mc, t * 2) : mix(mc, tc, (t - 0.5) * 2);\n      else c = mix(hc, tc, t);\n      cols.push(\"rgb(\" + Math.round(c[0]) + \",\" + Math.round(c[1]) + \",\" + Math.round(c[2]) + \")\");\n    }\n  }\n\n  function step() {\n    var nx = m.x, ny = m.y, k = Math.max(1, opts.drag);\n    for (var i = 0; i < n; i++) {\n      var pt = pts[i];\n      pt.x += (nx - pt.x) / k;\n      pt.y += (ny - pt.y) / k;\n      nx = pt.x; ny = pt.y;\n    }\n  }\n  function draw() {\n    ctx.setTransform(dpr, 0, 0, dpr, 0, 0);\n    ctx.clearRect(0, 0, W, H);\n    ctx.lineCap = \"round\";\n    // the original prepends every path, so the head sits on top: paint from the tail forward\n    for (var i = n - 1; i > 0; i--) {\n      var a = pts[i - 1], b = pts[i];\n      var d = Math.hypot(a.x - b.x, a.y - b.y), w = widths[i] * (d < 0 ? 0 : d > 1 ? 1 : d);\n      if (w <= 0) continue;\n      ctx.strokeStyle = cols[i]; ctx.lineWidth = w;\n      ctx.beginPath(); ctx.moveTo(a.x, a.y); ctx.lineTo(b.x, b.y); ctx.stroke();\n    }\n  }\n\n  // idle demo: a slow figure-of-eight path across the box, fed to the same quickTo as a real pointer\n  function idlePoint(ph) {\n    return { x: W * (0.5 + 0.34 * Math.sin(ph * 1.3) + 0.06 * Math.sin(ph * 3.1)), y: H * (0.5 + 0.3 * Math.sin(ph * 2.1 + 0.7)) };\n  }\n  function idle(now, dt) {\n    if (opts.idle !== \"on\" || inside || now - lastReal < 1500) return;\n    phase += dt * opts.speed;\n    var p = idlePoint(phase);\n    aim(p.x, p.y, now);\n  }\n\n  function loop(now) {\n    raf = requestAnimationFrame(loop);\n    var dt = Math.min(0.1, (now - last) / 1000 || 0); last = now;\n    if (!visible || document.hidden) return;\n    idle(now, dt);\n    m.x = qval(qx, now); m.y = qval(qy, now);\n    step(); // per frame, like gsap.ticker\n    draw();\n  }\n\n  // reduced motion: run the idle path off screen for a moment and draw the resulting ribbon once\n  function still() {\n    var ph = 2.2, t = 0;\n    for (var i = 0; i < n; i++) { var p0 = idlePoint(ph - i * 2.4 / n); pts[i].x = p0.x; pts[i].y = p0.y; }\n    qx = qy = null;\n    for (var f = 0; f < 30; f++) {\n      t += 1000 / 60; ph += 1 / 60 * 1.1;\n      var p = idlePoint(ph); aim(p.x, p.y, t);\n      m.x = qval(qx, t); m.y = qval(qy, t);\n      step();\n    }\n    draw();\n  }\n\n  function onMove(e) {\n    var r = wrap.getBoundingClientRect();\n    inside = true; lastReal = performance.now();\n    aim(e.clientX - r.left, e.clientY - r.top, lastReal);\n  }\n  function onEnter() { inside = true; lastReal = performance.now(); }\n  function onLeave() { inside = false; lastReal = performance.now(); }\n\n  function size() {\n    dpr = Math.min(window.devicePixelRatio || 1, 2);\n    var w = Math.max(1, wrap.clientWidth), h = Math.max(1, wrap.clientHeight), first = W === 1 && H === 1;\n    W = w; H = h;\n    canvas.width = Math.round(W * dpr); canvas.height = Math.round(H * dpr);\n    if (first) {\n      // the original starts its target at (half the height, the bottom edge)\n      m.x = H / 2; m.y = H; var t = performance.now(); qx = { from: m.x, to: m.x, t0: t, d: 0.3 }; qy = { from: m.y, to: m.y, t0: t, d: 0.3 };\n      build(false);\n    }\n    if (reduce) still(); else draw();\n  }\n  function update(partial) {\n    opts = Object.assign({ segments: 200, width: 100, drag: 3.5, glide: 0.3, idle: \"on\", speed: 1, head: \"#e6ff55\", tail: \"#1a7a4c\", middle: \"none\", background: \"#050d0a\" }, opts, partial || {});\n    opts.segments = Math.min(400, Math.max(3, num(opts.segments, 200))); opts.width = Math.max(1, num(opts.width, 100));\n    opts.drag = Math.max(1, num(opts.drag, 3.5)); opts.glide = Math.max(0.01, num(opts.glide, 0.3)); opts.speed = Math.max(0, num(opts.speed, 1));\n    wrap.style.background = opts.background;\n    if (W > 1 || H > 1) { build(true); if (reduce) still(); else draw(); }\n  }\n\n  update(o);\n  size();\n  if (!reduce) {\n    wrap.addEventListener(\"pointermove\", onMove, { passive: true });\n    wrap.addEventListener(\"pointerdown\", onMove, { passive: true });\n    wrap.addEventListener(\"pointerenter\", onEnter);\n    wrap.addEventListener(\"pointerleave\", onLeave);\n    if (\"IntersectionObserver\" in window) { io = new IntersectionObserver(function (e) { visible = e[0].isIntersecting; }); io.observe(wrap); }\n    last = performance.now(); lastReal = last - 900; // let the opening gather play before the idle loop starts\n    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      wrap.removeEventListener(\"pointermove\", onMove);\n      wrap.removeEventListener(\"pointerdown\", onMove);\n      wrap.removeEventListener(\"pointerenter\", onEnter);\n      wrap.removeEventListener(\"pointerleave\", onLeave);\n      if (io) io.disconnect();\n      if (ro) ro.disconnect();\n    }\n  };\n}"
  }
}