PageSourceSearch

https://ridemtu.com/assets/MapControlContext-CaZ7lMlQ.js

js ridemtu.com collected 2026-09-27 13:01:30 UTC 6,674 bytes, 1 lines download raw bytes

1import{r as E,j as x}from"./chunk-LFPYN7LY-BYCOceFh.js";class y extends Error{constructor(t,e,o){super(t),this.statusCode=e,this.originalError=o,this.name="RTPIServiceError"}}function b(){var r;return typeof window<"u"&&((r=window.location)!=null&&r.origin)?window.location.origin:""}async function l(r){const t=r.startsWith("/")?r.slice(1):r,e=b();if(!e)throw new y("RTPI proxy requires browser origin (window.location.origin).",void 0);const o=`${e}/api/rtpi?path=${encodeURIComponent(t)}`,a=await fetch(o,{method:"GET",headers:{Accept:"application/json"}});if(!a.ok){let i=`RTPI proxy error: ${a.status} ${a.statusText}`;try{const n=await a.json();n!=null&&n.error&&typeof n.error=="string"&&(i=n.error)}catch{}throw new y(i,a.status)}return a.json()}const j=1440*60*1e3,v=new Map,S=new Map,D=new Map;function d(r){return`rtpi:${r}`}function w(r,t,e=j){const o=r.get(t);return o?Date.now()-o.ts>e?(r.delete(t),null):o.value:null}function $(r,t,e){r.set(t,{value:e,ts:Date.now()})}async function B(r){const t=[`routes/${r}/paths`,`routes/${r}/patterns`,`routes/${r}/shapes`,`routes/${r}/geometry`],e=[];for(const o of t)try{const a=await l(o);if(a)return a}catch(a){e.push({uri:o,err:a})}throw console.error(`[Endpoints] Failed to fetch route geometry for ${r}. Tried:`,t,e),new y(`Unable to load route geometry for ${r}`,void 0)}async function F(r){try{return await l(`routes/${r}/stops`)}catch(t){throw console.error(`[Endpoints] Failed to fetch stops for route ${r}:`,t),t}}async function G(r){try{const t=await l(`routes/${r}/vehicles`);return(Array.isArray(t==null?void 0:t.data)?t.data:Array.isArray(t)?t:[]).map(o=>({...o,routeId:r}))}catch(t){throw console.error(`[Endpoints] Failed to fetch vehicles for route ${r}:`,t),t}}async function V(r){return l(`stops/${r}/routes`)}async function K(r,t){try{let e=`stops/${r}/arrivals`;t!=null&&String(t).length>0&&(e+=`?routeId=${encodeURIComponent(String(t))}`);const o=await l(e);return Array.isArray(o==null?void 0:o.data)?o.data:Array.isArray(o)?o:[]}catch(e){throw console.error(`[Endpoints] Failed to fetch arrivals for stop ${r}:`,e),e}}async function Y(r){try{const t=await l(`stops/rtpi/${r}/arrivals`);return Array.isArray(t)?t:[]}catch(t){throw console.error(`[Endpoints] Failed to fetch arrivals for RTPI stop number ${r}:`,t),t}}async function _(r){try{const t=await l(`v1/vehicles/${r}/arrivals`);return Array.isArray(t==null?void 0:t.data)?t.data:Array.isArray(t)?t:[]}catch(t){throw console.error(`[Endpoints] Failed to fetch arrivals for vehicle ${r}:`,t),t}}async function k(r){const t=d(`routes/${r}/patterns`),e=w(v,t);if(e)return e;try{const o=await l(`routes/${r}/patterns`),i=(Array.isArray(o==null?void 0:o.data)?o.data:Array.isArray(o)?o:[]).map(n=>{var s,c,u,h,p;return{id:n.id??n.patternId??String(Math.random()),name:n.name!=null&&String(n.name).trim()!==""?String(n.name):"Pattern",direction:n.direction!=null&&String(n.direction).trim()!==""?String(n.direction):void 0,directionType:n.directionType!=null?String(n.directionType).trim():"",shape:n.shape??n.encodedShape??n.polyline??"",route:n.route??{id:((s=n.route)==null?void 0:s.id)??r,name:((c=n.route)==null?void 0:c.name)??n.routeName??"",shortName:((u=n.route)==null?void 0:u.shortName)??n.routeShortName??"",color:((h=n.route)==null?void 0:h.color)??n.color??"#1976D2",textColor:((p=n.route)==null?void 0:p.textColor)??n.textColor??"#FFFFFF"}}});return $(v,t,i),i}catch(o){throw console.error(`[Endpoints] Failed to fetch patterns for route ${r}:`,o),o}}async function R(r,t){const e=d(`routes/${r}/patterns/${t}/stops`),o=w(S,e);if(o)return o;try{const a=await l(`routes/${r}/patterns/${t}/stops`),n=(Array.isArray(a==null?void 0:a.data)?a.data:Array.isArray(a)?a:[]).map(s=>{const c=s.stop??s;return{stop:{...c,id:c.id??s.stopId??s.id,name:c.name??s.stopName??s.name??"Unknown Stop",lat:c.lat??s.lat??0,lon:c.lon??c.lng??s.lon??0},sequence:s.sequence??s.stopSequence}});return $(S,e,n),n}catch(a){throw console.error(`[Endpoints] Failed to fetch pattern stops for route ${r}, pattern ${t}:`,a),a}}async function H(r){const t=d(`stops/${r}/patterns`),e=w(D,t);
1if(e)return e;try{const o=await l(`stops/${r}/patterns`),a=Array.isArray(o==null?void 0:o.data)?o.data:Array.isArray(o)?o:[];return $(D,t,a),a}catch(o){throw console.error(`[Endpoints] Failed to fetch patterns for stop ${r}:`,o),o}}function q(r,t){const e=r;return{...r,hasWarning:(t==null?void 0:t.hasWarning)??!!(e.hasWarning??e.alert),...(t==null?void 0:t.patternDirection)!=null?{patternDirection:t.patternDirection}:{}}}function m(r){return String(r||"direction").trim().toLowerCase().replace(/\s+/g,"-").replace(/[^a-z0-9-]/g,"")}function A(r){var e;if(r==null)return"";const t=(e=r.direction)==null?void 0:e.trim();return t||(r.directionType??"").trim()}function J(r,t){return!t||t==="all"?!0:m(A(r))===t}function L(r,t,e){if(!e)return`/route/${r}/direction/all/stop/${t}/arrivals`;const o=A(e);return o?`/route/${r}/direction/${m(o)}/stop/${t}/arrivals`:`/route/${r}/direction/all/stop/${t}/arrivals`}async function U(r){const t=await k(r),e=[],o=new Map;for(const a of t){const i=A(a);if(!i)continue;const n=m(i),s=o.get(n);s!==void 0?e[s].patternIds.push(a.id):(o.set(n,e.length),e.push({id:n,name:i,patternIds:[a.id]}))}return e}async function Q(r,t,e){const o=e??(await U(r)).find(s=>s.id===t);if(!o)return console.warn("📍 [DirectionsService] Direction not found:",t),[];const a=[];for(const s of o.patternIds)try{const c=await R(r,s);for(const u of c)a.push(q(u.stop,{patternDirection:o.name,hasWarning:!1}))}catch(c){console.error(`📍 [DirectionsService] Failed to fetch stops for pattern ${s}:`,c)}const i=new Set,n=[];for(const s of a){const c=String(s.id);i.has(c)||(i.add(c),n.push(s))}return n}const P=E.createContext(void 0);function X({children:r,focusedRoute:t,focusedStopId:e,centerToServiceRegionTrigger:o,centerOnLocationTrigger:a,onFocusedRouteChange:i,onFocusedStopChange:n,onCenterToServiceRegion:s,onCenterOnLocation:c}){const g={focusedRoute:t,focusedStopId:e,centerToServiceRegionTrigger:o,centerOnLocationTrigger:a,onFocusedRouteChange:i,onFocusedStopChange:n,onCenterToServiceRegion:s,onCenterOnLocation:c,setFocusedRoute:f=>{i==null||i(f)},setFocusedStop:f=>{n==null||n(f)},centerToServiceRegion:()=>{s==null||s()},centerOnLocation:(f,M,T=17)=>{c==null||c(f,M,T)},clearFocusedStates:()=>{i==null||i(null),n==null||n(null)}};return x.jsx(P.Provider,{value:g,children:r})}function Z(){const r=E.useContext(P);if(!r)throw new Error("useMapControl must be used within a MapControlProvider");return r}export{X as M,y as R,F as a,Q as b,V as c,K as d,J as e,U as f,l as g,_ as h,H as i,Y as j,k,B as l,G as m,A as p,L as s,q as t,Z 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.