{"version":3,"file":"SVGPathAnimator.Cc0uMsVC.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/8Y9Jwm6N4QjQWNtVEvCi/uT06dKmXBfGrgYyTOOeO/SVGPathAnimator.js"],"sourcesContent":["// SVG Path Animator - Upload SVG path, animate with slider, adjust width and color\nimport{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useRef,useEffect,startTransition}from\"react\";import{addPropertyControls,ControlType}from\"framer\";/**\n * @framerSupportedLayoutWidth fixed\n * @framerSupportedLayoutHeight fixed\n */export default function SVGPathAnimator(props){const{svgFile=\"data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 100 100'%3E%3Cpath d='M10,50 Q50,10 90,50 Q50,90 10,50' fill='none' stroke='%23000' stroke-width='2'/%3E%3C/svg%3E\",progress=0,strokeWidth=2,strokeColor=\"#000000\",backgroundColor=\"#FFFFFF\",autoplay=true,duration=2,delay=0,loop=true}=props;const[svgContent,setSvgContent]=useState(\"\");const[pathLength,setPathLength]=useState(0);const[animatedProgress,setAnimatedProgress]=useState(0);const[isPlaying,setIsPlaying]=useState(autoplay);const pathRef=useRef(null);const svgRef=useRef(null);const animationRef=useRef();const startTimeRef=useRef();// Load and parse SVG file\nuseEffect(()=>{if(!svgFile)return;const loadSVG=async()=>{try{const response=await fetch(svgFile);const svgText=await response.text();startTransition(()=>setSvgContent(svgText));}catch(error){console.error(\"Failed to load SVG:\",error);}};loadSVG();},[svgFile]);// Calculate path length when SVG content changes\nuseEffect(()=>{if(pathRef.current){const length=pathRef.current.getTotalLength();setPathLength(length);}},[svgContent]);// Animation logic\nuseEffect(()=>{if(!autoplay){setAnimatedProgress(progress);return;}const animate=timestamp=>{if(!startTimeRef.current){startTimeRef.current=timestamp+delay*1e3;}const elapsed=timestamp-startTimeRef.current;const progressTime=Math.max(0,elapsed)/(duration*1e3);if(progressTime>=1){setAnimatedProgress(100);if(loop){startTimeRef.current=timestamp;setAnimatedProgress(0);if(isPlaying){animationRef.current=requestAnimationFrame(animate);}}}else{setAnimatedProgress(progressTime*100);if(isPlaying){animationRef.current=requestAnimationFrame(animate);}}};if(isPlaying){startTimeRef.current=undefined;animationRef.current=requestAnimationFrame(animate);}return()=>{if(animationRef.current){cancelAnimationFrame(animationRef.current);}};},[autoplay,duration,delay,loop,isPlaying]);// Handle play/pause toggle\nconst togglePlayPause=()=>{startTransition(()=>setIsPlaying(!isPlaying));};// Reset animation\nconst resetAnimation=()=>{startTransition(()=>{setAnimatedProgress(0);startTimeRef.current=undefined;});};// Extract path data from SVG content\nconst extractPathData=svgString=>{const parser=new DOMParser;const doc=parser.parseFromString(svgString,\"image/svg+xml\");const pathElement=doc.querySelector(\"path\");return pathElement?.getAttribute(\"d\")||\"\";};// Extract viewBox from SVG content\nconst extractViewBox=svgString=>{const parser=new DOMParser;const doc=parser.parseFromString(svgString,\"image/svg+xml\");const svgElement=doc.querySelector(\"svg\");return svgElement?.getAttribute(\"viewBox\")||\"0 0 100 100\";};const pathData=svgContent?extractPathData(svgContent):\"M10,50 Q50,10 90,50 Q50,90 10,50\";const viewBox=svgContent?extractViewBox(svgContent):\"0 0 100 100\";const currentProgress=autoplay?animatedProgress:progress;const dashArray=pathLength;const dashOffset=pathLength-pathLength*currentProgress/100;return /*#__PURE__*/_jsxs(\"div\",{style:{width:\"100%\",height:\"100%\",backgroundColor,display:\"flex\",flexDirection:\"column\",alignItems:\"center\",justifyContent:\"center\",padding:20,position:\"relative\"},children:[/*#__PURE__*/_jsx(\"div\",{style:{flex:1,width:\"100%\",display:\"flex\",alignItems:\"center\",justifyContent:\"center\"},children:/*#__PURE__*/_jsx(\"svg\",{ref:svgRef,viewBox:viewBox,style:{width:\"100%\",height:\"100%\",maxWidth:\"100%\",maxHeight:\"100%\"},children:/*#__PURE__*/_jsx(\"path\",{ref:pathRef,d:pathData,fill:\"none\",stroke:strokeColor,strokeWidth:strokeWidth,strokeDasharray:dashArray,strokeDashoffset:dashOffset,strokeLinecap:\"round\",strokeLinejoin:\"round\"})})}),autoplay&&/*#__PURE__*/_jsxs(\"div\",{style:{position:\"absolute\",bottom:10,left:10,display:\"flex\",gap:8,zIndex:10},children:[/*#__PURE__*/_jsx(\"button\",{onClick:togglePlayPause,style:{padding:\"8px 12px\",backgroundColor:\"rgba(0, 0, 0, 0.7)\",color:\"white\",border:\"none\",borderRadius:4,cursor:\"pointer\",fontSize:12},children:isPlaying?\"Pause\":\"Play\"}),/*#__PURE__*/_jsx(\"button\",{onClick:resetAnimation,style:{padding:\"8px 12px\",backgroundColor:\"rgba(0, 0, 0, 0.7)\",color:\"white\",border:\"none\",borderRadius:4,cursor:\"pointer\",fontSize:12},children:\"Reset\"})]})]});}addPropertyControls(SVGPathAnimator,{svgFile:{type:ControlType.File,title:\"SVG File\",allowedFileTypes:[\"svg\"]},autoplay:{type:ControlType.Boolean,title:\"Animation\",defaultValue:true,enabledTitle:\"Auto\",disabledTitle:\"Manual\"},progress:{type:ControlType.Number,title:\"Progress\",defaultValue:0,min:0,max:100,step:1,unit:\"%\",hidden:({autoplay})=>autoplay},duration:{type:ControlType.Number,title:\"Duration\",defaultValue:2,min:.1,max:10,step:.1,unit:\"s\",hidden:({autoplay})=>!autoplay},delay:{type:ControlType.Number,title:\"Delay\",defaultValue:0,min:0,max:5,step:.1,unit:\"s\",hidden:({autoplay})=>!autoplay},loop:{type:ControlType.Boolean,title:\"Loop\",defaultValue:true,hidden:({autoplay})=>!autoplay},strokeWidth:{type:ControlType.Number,title:\"Stroke Width\",defaultValue:2,min:1,max:200,step:1,unit:\"px\"},strokeColor:{type:ControlType.Color,title:\"Stroke Color\",defaultValue:\"#000000\"},backgroundColor:{type:ControlType.Color,title:\"Background\",defaultValue:\"#FFFFFF\"}});\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SVGPathAnimator\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\",\"framerSupportedLayoutHeight\":\"fixed\",\"fram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