{"version":3,"file":"shared-lib.DK6VuExO.mjs","names":["useState","useRef"],"sources":["https:/framerusercontent.com/modules/oTUcInn54EdNwSVxiOnm/WNO6dmFtoVTMlurk1P9u/Train_code.js"],"sourcesContent":["import{jsx as _jsx,jsxs as _jsxs}from\"react/jsx-runtime\";import{useState,useRef,useEffect}from\"react\";export default function SpeedTracker(){// STATES\nconst[speedKmh,setSpeedKmh]=useState(0);const[displaySpeed,setDisplaySpeed]=useState(0);const[tracking,setTracking]=useState(false);const[glow,setGlow]=useState(false);const[darkMode,setDarkMode]=useState(true);const[unit,setUnit]=useState(\"kmh\");// REFS\nconst lastPosition=useRef(null);const lastTime=useRef(null);const watchId=useRef(null);const animationRef=useRef(null);const readingCount=useRef(0);const lastSpeed=useRef(0);// AUTO DETECT SYSTEM THEME\nuseEffect(()=>{const prefersDark=window.matchMedia(\"(prefers-color-scheme: dark)\").matches;setDarkMode(prefersDark);},[]);// TESLA STYLE ANIMATION\nfunction animateSpeed(target){cancelAnimationFrame(animationRef.current);const start=displaySpeed;const duration=400;let startTime=null;function step(timestamp){if(!startTime)startTime=timestamp;const progress=timestamp-startTime;const percent=Math.min(progress/duration,1);const eased=percent<.5?2*percent*percent:1-Math.pow(-2*percent+2,2)/2;const value=Math.round(start+(target-start)*eased);setDisplaySpeed(value);if(percent<1)animationRef.current=requestAnimationFrame(step);}animationRef.current=requestAnimationFrame(step);}// DISTANCE CALCULATION\nfunction calculateDistance(lat1,lon1,lat2,lon2){const R=6371;const dLat=(lat2-lat1)*Math.PI/180;const dLon=(lon2-lon1)*Math.PI/180;const a=Math.sin(dLat/2)*Math.sin(dLat/2)+Math.cos(lat1*Math.PI/180)*Math.cos(lat2*Math.PI/180)*Math.sin(dLon/2)*Math.sin(dLon/2);const c=2*Math.atan2(Math.sqrt(a),Math.sqrt(1-a));return R*c;}// START TRACKING\nfunction startTracking(){if(!navigator.geolocation){alert(\"Geolocation not supported\");return;}setTracking(true);watchId.current=navigator.geolocation.watchPosition(position=>{const{latitude,longitude,accuracy,speed}=position.coords;const currentTime=Date.now();readingCount.current+=1;// FILTER 1: Ignore first readings\nif(readingCount.current<=3){lastPosition.current={latitude,longitude};lastTime.current=currentTime;return;}// FILTER 2: Ignore poor accuracy\nif(accuracy>50)return;let calculatedSpeed;// FILTER 3: Use native GPS speed\nif(speed!==null&&speed!==undefined){calculatedSpeed=Math.round(speed*3.6);}else{if(!lastPosition.current||!lastTime.current)return;const distance=calculateDistance(lastPosition.current.latitude,lastPosition.current.longitude,latitude,longitude);const timeDiff=(currentTime-lastTime.current)/36e5;calculatedSpeed=Math.round(distance/timeDiff);}if(!isNaN(calculatedSpeed)&&calculatedSpeed>=0){const speedDiff=Math.abs(calculatedSpeed-lastSpeed.current);// FILTER 4: Ignore unrealistic jumps\nif(speedDiff>150&&readingCount.current>5)return;lastSpeed.current=calculatedSpeed;setSpeedKmh(calculatedSpeed);const converted=unit===\"kmh\"?calculatedSpeed:Math.round(calculatedSpeed*.621371);animateSpeed(converted);setGlow(true);setTimeout(()=>setGlow(false),250);}lastPosition.current={latitude,longitude};lastTime.current=currentTime;},error=>console.error(error),{enableHighAccuracy:true,maximumAge:0,timeout:5e3});}function stopTracking(){setTracking(false);navigator.geolocation.clearWatch(watchId.current);readingCount.current=0;lastSpeed.current=0;}function toggleTheme(){setDarkMode(!darkMode);}function changeUnit(newUnit){setUnit(newUnit);const converted=newUnit===\"kmh\"?speedKmh:Math.round(speedKmh*.621371);animateSpeed(converted);}// STYLES\nconst outerContainer={height:\"100dvh\",width:\"100vw\",background:darkMode?\"#000\":\"#fff\",color:darkMode?\"#fff\":\"#000\",fontFamily:\"Inter, sans-serif\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",position:\"relative\",transition:\"0.3s\"};return /*#__PURE__*/_jsxs(\"div\",{style:outerContainer,children:[/*#__PURE__*/_jsx(\"div\",{onClick:toggleTheme,style:{position:\"absolute\",top:\"20px\",right:\"20px\",width:\"58px\",height:\"32px\",background:darkMode?\"#222\":\"#ddd\",borderRadius:\"20px\",padding:\"4px\",cursor:\"pointer\"},children:/*#__PURE__*/_jsx(\"div\",{style:{width:\"24px\",height:\"24px\",background:darkMode?\"#000\":\"#fff\",borderRadius:\"50%\",transform:darkMode?\"translateX(26px)\":\"translateX(0px)\",transition:\"0.3s\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",fontSize:\"14px\"},children:darkMode?\"🌙\":\"☀️\"})}),/*#__PURE__*/_jsxs(\"div\",{style:{position:\"absolute\",top:\"20px\",left:\"20px\",background:darkMode?\"#111\":\"#eee\",borderRadius:\"14px\",padding:\"4px\",display:\"flex\"},children:[/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",top:\"4px\",left:unit===\"kmh\"?\"4px\":\"52px\",width:\"48px\",height:\"32px\",background:darkMode?\"#fff\":\"#000\",borderRadius:\"10px\",transition:\"0.25s\"}}),/*#__PURE__*/_jsx(\"div\",{onClick:()=>changeUnit(\"kmh\"),style:{width:\"48px\",height:\"32px\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",cursor:\"pointer\",zIndex:1,color:unit===\"kmh\"?darkMode?\"#000\":\"#fff\":darkMode?\"#aaa\":\"#666\"},children:\"km/h\"}),/*#__PURE__*/_jsx(\"div\",{onClick:()=>changeUnit(\"mph\"),style:{width:\"48px\",height:\"32px\",display:\"flex\",justifyContent:\"center\",alignItems:\"center\",cursor:\"pointer\",zIndex:1,color:unit===\"mph\"?darkMode?\"#000\":\"#fff\":darkMode?\"#aaa\":\"#666\"},children:\"mph\"})]}),/*#__PURE__*/_jsxs(\"div\",{style:{textAlign:\"center\"},children:[/*#__PURE__*/_jsx(\"div\",{style:{fontSize:\"12px\",letterSpacing:\"0.2em\",color:darkMode?\"#666\":\"#888\"},children:\"LIVE SPEED\"}),/*#__PURE__*/_jsx(\"div\",{style:{fontSize:\"clamp(90px,20vw,160px)\",fontWeight:600,transform:glow?\"scale(1.06)\":\"scale(1)\",transition:\"0.25s\"},children:readingCount.current<=2?\"0\":displaySpeed}),/*#__PURE__*/_jsx(\"div\",{style:{color:darkMode?\"#666\":\"#888\"},children:unit===\"kmh\"?\"km/h\":\"mph\"}),/*#__PURE__*/_jsx(\"button\",{onClick:tracking?stopTracking:startTracking,style:{marginTop:\"14px\",padding:\"16px 32px\",borderRadius:\"16px\",border:\"none\",background:darkMode?\"#fff\":\"#000\",color:darkMode?\"#000\":\"#fff\",cursor:\"pointer\"},children:tracking?\"Stop Tracking\":\"Start Tracking\"})]}),/*#__PURE__*/_jsx(\"div\",{style:{position:\"absolute\",bottom:\"20px\",fontSize:\"12px\",color:darkMode?\"#666\":\"#888\"},children:\"Made with ♥ by Pixel Retouch Labs\"})]});}\nexport const __FramerMetadata__ = {\"exports\":{\"default\":{\"type\":\"reactComponent\",\"name\":\"SpeedTracker\",\"slots\":[],\"annotations\":{\"framerContractVersion\":\"1\"}},\"__FramerMetadata__\":{\"type\":\"variable\"}}}\n//# sourceMappingURL=./Train_code.map"],"mappings":"kJAAsG,SAAwB,GAAc,CAC5I,GAAK,CAAC,EAAS,GAAaA,EAAS,EAAE,CAAM,CAAC,EAAa,GAAiBA,EAAS,EAAE,CAAM,CAAC,EAAS,GAAaA,EAAS,GAAM,CAAM,CAAC,EAAK,GAASA,EAAS,GAAM,CAAM,CAAC,EAAS,GAAaA,EAAS,GAAK,CAAM,CAAC,EAAK,GAASA,EAAS,MAAM,CAChP,EAAaC,EAAO,KAAK,CAAO,EAASA,EAAO,KAAK,CAAO,EAAQA,EAAO,KAAK,CAAO,EAAaA,EAAO,KAAK,CAAO,EAAaA,EAAO,EAAE,CAAO,EAAUA,EAAO,EAAE,CAC7K,MAAc,CAAC,IAAM,EAAY,EAAO,WAAW,+BAA+B,CAAC,QAAQ,EAAY,EAAY,EAAG,EAAE,CAAC,CACzH,SAAS,EAAa,EAAO,CAAC,qBAAqB,EAAa,QAAQ,CAAC,IAAM,EAAM,EAAoC,EAAU,KAAK,SAAS,EAAK,EAAU,CAAC,AAAc,IAAU,EAAU,IAA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