Publish the prerendered static export (index.html, 404.html, cinema/,
c/, about/, for-cinemas/, for-film-lovers/, assets/, images/, og/,
sitemap.xml, robots.txt) as the site root and remove the React Router
+ Nitro source tree from this branch. Source remains available in
history at 0548772.
Note: public/sw.js here reports VERSION v2.0.5 while the removed source
tree (v2.1.0) was newer, and .gitignore was not carried over.
1 line
2.5 KiB
JavaScript
1 line
2.5 KiB
JavaScript
import{i as e,t}from"./react-B8IZ02wI.js";import{t as n}from"./jsx-runtime-fBfwind-.js";var r=e(t(),1),i=`https://router.project-osrm.org/table/v1/driving`,a=1.35,o=6371,s=8e3;function c(e){return e*Math.PI/180}function l(e,t){let n=c(t.latitude-e.latitude),r=c(t.longitude-e.longitude),i=Math.sin(n/2)**2+Math.cos(c(e.latitude))*Math.cos(c(t.latitude))*Math.sin(r/2)**2;return 2*o*Math.asin(Math.sqrt(i))}function u(e,t){return{distance_km:l(e,t)*a,source:`straight`}}function d(e){return!Array.isArray(e)||!Array.isArray(e[0])?[]:e[0].slice(1).map(e=>typeof e==`number`&&Number.isFinite(e)?e/1e3:null)}function f(e,t){return`${i}/${[e,...t].map(e=>`${e.longitude},${e.latitude}`).join(`;`)}?annotations=distance`}async function p(e,t){if(t.length===0)return[];let n=await fetch(f(e,t),{signal:AbortSignal.timeout(s)});if(!n.ok)throw Error(`OSRM ตอบกลับ ${n.status}`);let r=await n.json();if(r.code!==`Ok`)throw Error(`OSRM code: ${r.code??`unknown`}`);let i=d(r.distances);return t.map((e,t)=>{let n=i[t];return n==null?null:{distance_km:n,source:`road`}})}function m(e,t){return e?`${e.source===`straight`?`≈ `:``}${e.distance_km.toFixed(1)} km.`:t}function h(e,t){return[...e].sort((e,n)=>{let r=t[e.slug]?.distance_km,i=t[n.slug]?.distance_km;return r===void 0&&i===void 0?0:r===void 0?1:i===void 0?-1:r-i})}var g=n(),_=1e4,v=(0,r.createContext)(null);function y(e,t){let n={};for(let r of e)r.coordinates&&(n[r.slug]=u(t,r.coordinates));return n}function b({cinemas:e,children:t}){let[n,i]=(0,r.useState)(`idle`),[a,o]=(0,r.useState)(null),[s,c]=(0,r.useState)({}),l=(0,r.useCallback)(async t=>{let n=e.filter(e=>e.coordinates!==null);try{let e=await p(t,n.map(e=>e.coordinates)),r={};n.forEach((n,i)=>{let a=n.coordinates;r[n.slug]=e[i]??u(t,a)}),c(r)}catch{c(y(e,t))}i(`ready`)},[e]),d=(0,r.useCallback)(()=>{if(typeof navigator>`u`||!navigator.geolocation){i(`unsupported`);return}i(`locating`),navigator.geolocation.getCurrentPosition(e=>{let t={latitude:e.coords.latitude,longitude:e.coords.longitude};o(t),l(t)},e=>{i(e.code===e.PERMISSION_DENIED?`denied`:`error`)},{timeout:_,maximumAge:6e4})},[l]),f=(0,r.useMemo)(()=>({status:n,coords:a,distances:s,requestLocation:d}),[n,a,s,d]);return(0,g.jsx)(v.Provider,{value:f,children:t})}function x(){let e=(0,r.useContext)(v);if(!e)throw Error(`useNearMe ต้องถูกใช้ภายใน <NearMeProvider>`);return e}var S=(0,r.createContext)(``);function C({origin:e,children:t}){return(0,g.jsx)(S.Provider,{value:e,children:t})}function w(){return(0,r.useContext)(S)}export{m as a,x as i,w as n,h as o,b as r,C as t}; |