PageSourceSearch

https://ridemtu.com/assets/GeolocationPermissionContext-BNsxlLYQ.js

js ridemtu.com collected 2026-09-27 13:01:17 UTC 3,243 bytes, 1 lines download raw bytes

1import{r as s,j as E}from"./chunk-LFPYN7LY-BYCOceFh.js";const g="portal:geolocation-granted";function f(e){typeof window>"u"||window.dispatchEvent(new CustomEvent(g,{detail:e}))}const w={enableHighAccuracy:!0,timeout:1e4,maximumAge:6e4},P={...w,maximumAge:0},b={enableHighAccuracy:!1,maximumAge:3e5,timeout:2e4};function l(){var e;return typeof window<"u"&&"permissions"in navigator&&typeof((e=navigator.permissions)==null?void 0:e.query)=="function"}async function x(){if(!l())return!1;try{return(await navigator.permissions.query({name:"geolocation"})).state==="granted"}catch{return!1}}function p(e){const{latitude:o,longitude:i}=e.coords;return{lng:i,lat:o}}function C(){if(typeof window>"u"||!("geolocation"in navigator))return;l()&&navigator.permissions.query({name:"geolocation"}).then(o=>{o.state==="granted"&&f()}).catch(()=>{});const e=o=>{if(!o){navigator.geolocation.getCurrentPosition(i=>{f(p(i))},()=>e(!0),b);return}l()&&navigator.permissions.query({name:"geolocation"}).then(i=>{i.state==="granted"&&f()}).catch(()=>{})};navigator.geolocation.getCurrentPosition(o=>{f(p(o))},()=>e(!1),w)}const h=s.createContext(void 0),y=s.createContext(void 0);function G({children:e}){const[o,i]=s.useState("pending"),[L,v]=s.useState(null),m=s.useRef(!1);return s.useEffect(()=>{let n=!1,a;const d=t=>t==="denied"?(m.current=!1,"denied"):t==="granted"||m.current?"granted":"prompt",c=t=>{if(n)return;m.current=!0,i("granted");const r=t.detail;r!=null&&Number.isFinite(r.lat)&&Number.isFinite(r.lng)&&v({lat:r.lat,lng:r.lng})};if(window.addEventListener(g,c),!l())return x().then(t=>{n||i(t?"granted":"prompt")}),()=>{n=!0,window.removeEventListener(g,c)};navigator.permissions.query({name:"geolocation"}).then(t=>{if(n)return;const r=()=>{i(d(t.state))};r(),t.addEventListener("change",r),a=()=>{t.removeEventListener("change",r)}}).catch(()=>{n||i("unsupported")});const u=()=>{n||document.visibilityState!=="visible"||l()&&navigator.permissions.query({name:"geolocation"}).then(t=>{n||i(d(t.state))}).catch(()=>{})};return document.addEventListener("visibilitychange",u),window.addEventListener("focus",u),()=>{n=!0,a==null||a(),document.removeEventListener("visibilitychange",u),window.removeEventListener("focus",u),window.removeEventListener(g,c)}},[]),s.useEffect(()=>{if(typeof window>"u"||!("geolocation"in navigator))return;if(o!=="granted"){v(null);return}let n=!1,a;const d=r=>{n||v(p(r))},c=()=>{navigator.geolocation.getCurrentPosition(d,void 0,w)};c();const u=navigator.geolocation.watchPosition(d,void 0,P);a=()=>{try{navigator.geolocation.clearWatch(u)}catch{}};const t=()=>{document.visibilityState!=="visible"||n||c()};return document.addEventListener("visibilitychange",t),()=>{n=!0,document.removeEventListener("visibilitychange",t),a==null||a()}},[o]),E.jsx(h.Provider,{value:o,children:E.jsx(y.Provider,{value:L,children:e})})}function A(){const e=s.useContext(h);if(e===void 0)throw new Error("useGeolocationAccessState must be used within GeolocationProvider");return e}function O(){const e=A();return e==="pending"?null:e==="granted"}function T(){const e=s.useContext(y);if(e===void 0)throw new Error("useUserLocation must be used within GeolocationProvider");return e}export{G,O as a,T as b,f as n,C as r,A as u};

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.