{"version":3,"file":"TrailingCursor.yeMy3ZLb.mjs","names":["useState","useRef","useMemo"],"sources":["https:/framerusercontent.com/modules/VbR6ciSVPVGUvKjRWVGP/ngUyTKt9V0lMqYGJnEWa/TrailingCursor.js"],"sourcesContent":["// Custom Cursor with movement-based trail - Optimized Version\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useEffect,useRef,useState,useMemo}from\"react\";import{addPropertyControls,ControlType,RenderTarget,useIsStaticRenderer}from\"framer\";// Constants at module scope (fix #11)\nconst IDLE_THRESHOLD=90// ms before considering cursor idle\n;const MIN_MOVE_DISTANCE=1.8// px minimum move to register\n;const CLOSE_DURATION=300// ms to fully close trail\n;const HEAD_LINGER=70// ms the head stays after trail disappears\n;const MIN_FRAME_TIME=16// ms (60fps)\n;/**\n * Custom Cursor with Trailing Squares\n *\n * Shows a square cursor that follows the pointer and renders a fading trail of squares.\n * Trail length and opacity are based on recent pointer movement intensity.\n *\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function TrailingCursor(props){const{color,size,trailMaxLength=200,minTrailLength=2,style}=props;const isStatic=useIsStaticRenderer();// State — all hooks BEFORE any conditional return (fix #1)\nconst[trail,setTrail]=useState([]);const[visible,setVisible]=useState(false);// Refs for tracking state without causing re-renders\nconst trailRef=useRef([]);const lastPosRef=useRef(null);const lastMoveTimeRef=useRef(0);const isIdleRef=useRef(true);const lastDecayTimeRef=useRef(0);const idleDecayStartRef=useRef(null);const headLingerStartRef=useRef(null);const visibleRef=useRef(false)// fix #8: stable ref for visible\n;// Ref-based RAF loop control (fix #6)\nconst rafRunningRef=useRef(false);const rafIdRef=useRef(null);// Keep visibleRef in sync (fix #8)\nuseEffect(()=>{visibleRef.current=visible;},[visible]);// Optimized decay calculation\nconst calculateDecayRate=useRef((trailLength,frameTime)=>{if(trailLength<=1)return 1;const frames=Math.max(1,CLOSE_DURATION/Math.max(MIN_FRAME_TIME,frameTime));return Math.max(1,Math.min(3,trailLength/frames));}).current;// Main decay logic — uses refs only, no state deps (fix #8)\nconst fadeTrailRef=useRef();fadeTrailRef.current=timestamp=>{const dt=timestamp-lastDecayTimeRef.current;if(dt<MIN_FRAME_TIME)return;const timeSinceMove=timestamp-lastMoveTimeRef.current;const isIdle=timeSinceMove>IDLE_THRESHOLD;const currentTrail=trailRef.current;if(isIdle){isIdleRef.current=true;}// Handle empty trail\nif(currentTrail.length===0){if(visibleRef.current){setVisible(false);}lastDecayTimeRef.current=timestamp;if(idleDecayStartRef.current)idleDecayStartRef.current=null;if(headLingerStartRef.current)headLingerStartRef.current=null;return;}const len=currentTrail.length;let newTrail=currentTrail;// PHASE 1: Active movement - remove one point from tail\nif(!isIdle&&len>minTrailLength){newTrail=currentTrail.slice(1);idleDecayStartRef.current=null;headLingerStartRef.current=null;}else if(isIdle){if(!idleDecayStartRef.current){idleDecayStartRef.current={len,time:timestamp};}if(len===1){if(!headLingerStartRef.current){headLingerStartRef.current=timestamp;}if(timestamp-headLingerStartRef.current>=HEAD_LINGER){newTrail=[];headLingerStartRef.current=null;idleDecayStartRef.current=null;}}else{const startLen=idleDecayStartRef.current.len;const decayRate=calculateDecayRate(startLen,dt);const removeCount=Math.min(Math.ceil(decayRate),len-1);if(removeCount>0){newTrail=currentTrail.slice(removeCount);}}}// Only update if changed\nif(newTrail!==currentTrail){trailRef.current=newTrail;setTrail(newTrail)// fix #9: no redundant spread\n;}lastDecayTimeRef.current=timestamp;};// Stable RAF loop helper (fix #6)\nconst startLoop=useRef(()=>{if(rafRunningRef.current)return;rafRunningRef.current=true;function loop(timestamp){fadeTrailRef.current?.(timestamp);if(trailRef.current.length>0||!isIdleRef.current){rafIdRef.current=requestAnimationFrame(loop);}else{rafRunningRef.current=false;rafIdRef.current=null;}}rafIdRef.current=requestAnimationFrame(loop);}).current;// Cleanup RAF on unmount\nuseEffect(()=>{return()=>{if(rafIdRef.current!==null){cancelAnimationFrame(rafIdRef.current);}};},[]);// Mouse movement handler — no visible/now deps (fix #7, #8)\nuseEffect(()=>{const handleMove=e=>{const x=e.clientX;const y=e.clientY;const timestamp=performance.now()// fix #7: direct call\n;if(x<0||x>window.innerWidth||y<0||y>window.innerHeight){return;}const lastPos=lastPosRef.current;if(lastPos){const dx=x-lastPos.x;const dy=y-lastPos.y;const dist=Math.sqrt(dx*dx+dy*dy);if(dist<MIN_MOVE_DISTANCE){return;}const newPoint={x,y};let newTrail=[...trailRef.current,newPoint];if(newTrail.length>trailMaxLength){newTrail=newTrail.slice(newTrail.length-trailMaxLength);}trailRef.current=newTrail;lastPosRef.current=newPoint;lastMoveTimeRef.current=timestamp;isIdleRef.current=false;setTrail(newTrail);if(!visibleRef.current)setVisible(true)// fix #8: use ref\n;}else{const newPoint={x,y};trailRef.current=[newPoint];lastPosRef.current=newPoint;lastMoveTimeRef.current=timestamp;isIdleRef.current=false;setTrail([newPoint]);setVisible(true);}startLoop()// fix #6: kick RAF loop if not running\n;};window.addEventListener(\"mousemove\",handleMove,{passive:true});return()=>{window.removeEventListener(\"mousemove\",handleMove);};},[trailMaxLength,startLoop]);// Smooth path generation - memoized\nconst pathData=useMemo(()=>{if(trail.length===0)return\"\";if(trail.length===1){const{x,y}=trail[0];return`M${x},${y}`;}const points=trail;let d=`M${points[0].x},${points[0].y}`;for(let i=0;i<points.length-1;i++){const p0=points[i];const p1=points[i+1];const mx=(p0.x+p1.x)/2;const my=(p0.y+p1.y)/2;d+=` Q${p0.x},${p0.y} ${mx},${my}`;}const last=points[points.length-1];d+=` T${last.x},${last.y}`;return d;},[trail]);// Hide native cursor\nuseEffect(()=>{if(visible){document.body.style.cursor=\"none\";}return()=>{document.body.style.cursor=\"\";};},[visible]);// Guard rendering instead of early return (fix #1)\nif(isStatic||RenderTarget.current()!==RenderTarget.preview){return null;}if(!visible)return null;const halfSize=size/2;const head=trail.length>0?trail[trail.length-1]:null;return /*#__PURE__*/_jsxs(\"div\",{style:{pointerEvents:\"none\",position:\"fixed\",inset:0,zIndex:999999,...style},children:[trail.length>1&&/*#__PURE__*/_jsx(\"svg\",{width:\"100%\",height:\"100%\",style:{position:\"fixed\",left:0,top:0,width:\"100%\",height:\"100%\",pointerEvents:\"none\",overflow:\"visible\"},children:/*#__PURE__*/_jsx(\"path\",{d:pathData,fill:\"none\",stroke:color,strokeWidth:size,strokeLinecap:\"round\",strokeLinejoin:\"round\",vectorEffect:\"non-scaling-stroke\"})}),head&&/*#__PURE__*/_jsx(\"div\",{style:{position:\"fixed\",left:0,top:0,transform:`translate(${head.x-halfSize}px, ${head.y-halfSize}px)`,width:size,height:size,backgroundColor:color,boxShadow:\"0 1px 10px 0 rgba(0,0,0,0.10)\",pointerEvents:\"none\",willChange:\"transform\"}})]});}addPropertyControls(TrailingCursor,{color:{type:ControlType.Color,title:\"Color\",defaultValue:\"#0099FF\"},size:{type:ControlType.Number,title:\"Size\",defaultValue:4,min:2,max:60,unit:\"px\"},trailBaseLength:{type:ControlType.Number,title:\"Trail Min\",defaultValue:4,min:1,max:14,step:1},minTrailLength:{type:ControlType.Number,title:\"Min Trail Length\",defaultValue:2,min:1,max:14,step:1},trailMaxLength:{type:ControlType.Number,title:\"Trail Max\",defaultValue:14,min:4,max:200,step:1},fade:{type:ControlType.Number,title:\"Trail Fade\",defaultValue:.17,min:.05,max:.6,step:.01,hidden:true},delay:{type:ControlType.Number,title:\"Trail Delay\",defaultValue:10,min:5,max:1e3,step:5},speed:{type:ControlType.Number,title:\"Trail Speed\",defaultValue:1,min:.3,max:4,step:.05,unit:\"x\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"TrailingCursor\",\"slots\":[],\"annotations\":{\"framerSupportedLayoutHeight\":\"fixed\",\"framerContractVersion\":\"1\",\"framerSupportedLayoutWidth\":\"fixed\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./TrailingCursor.map"],"mappings":"yNAeG,SAAwB,EAAe,EAAM,CAAC,GAAK,CAAC,QAAM,OAAK,iBAA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