minotor
Version:
A lightweight client-side transit routing library.
1 lines • 85.3 kB
JavaScript
"use strict";const t=t=>{let e=Math.floor(t/60);const r=Math.floor(t%60);return e>=24&&(e%=24),`${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`},e=t=>{const e=Math.floor(t/60),r=t%60;return e>0?`${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${r}min`};function r(){let t=0,e=0;for(let r=0;r<28;r+=7){let n=this.buf[this.pos++];if(t|=(127&n)<<r,!(128&n))return this.assertBounds(),[t,e]}let r=this.buf[this.pos++];if(t|=(15&r)<<28,e=(112&r)>>4,!(128&r))return this.assertBounds(),[t,e];for(let r=3;r<=31;r+=7){let n=this.buf[this.pos++];if(e|=(127&n)<<r,!(128&n))return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function n(t,e,r){for(let n=0;n<28;n+=7){const s=t>>>n,i=!(s>>>7==0&&0==e),o=255&(i?128|s:s);if(r.push(o),!i)return}const n=t>>>28&15|(7&e)<<4,s=!!(e>>3);if(r.push(255&(s?128|n:n)),s){for(let t=3;t<31;t+=7){const n=e>>>t,s=!(n>>>7==0),i=255&(s?128|n:n);if(r.push(i),!s)return}r.push(e>>>31&1)}}const s=4294967296;function i(t){const e="-"===t[0];e&&(t=t.slice(1));const r=1e6;let n=0,i=0;function o(e,o){const a=Number(t.slice(e,o));i*=r,n=n*r+a,n>=s&&(i+=n/s|0,n%=s)}return o(-24,-18),o(-18,-12),o(-12,-6),o(-6),e?u(n,i):a(n,i)}function o(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(s*e+t);const r=16777215&(t>>>24|e<<8),n=e>>16&65535;let i=(16777215&t)+6777216*r+6710656*n,o=r+8147497*n,a=2*n;const u=1e7;return i>=u&&(o+=Math.floor(i/u),i%=u),o>=u&&(a+=Math.floor(o/u),o%=u),a.toString()+c(o)+c(i)}function a(t,e){return{lo:0|t,hi:0|e}}function u(t,e){return e=~e,t?t=1+~t:e+=1,a(t,e)}const c=t=>{const e=String(t);return"0000000".slice(e.length)+e};function d(t,e){if(t>=0){for(;t>127;)e.push(127&t|128),t>>>=7;e.push(t)}else{for(let r=0;r<9;r++)e.push(127&t|128),t>>=7;e.push(1)}}function l(){let t=this.buf[this.pos++],e=127&t;if(!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<7,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<14,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<21,!(128&t))return this.assertBounds(),e;t=this.buf[this.pos++],e|=(15&t)<<28;for(let e=5;128&t&&e<10;e++)t=this.buf[this.pos++];if(128&t)throw new Error("invalid varint");return this.assertBounds(),e>>>0}const h=f();function f(){const t=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof t.getBigInt64&&"function"==typeof t.getBigUint64&&"function"==typeof t.setBigInt64&&"function"==typeof t.setBigUint64&&(!!globalThis.Deno||"object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const e=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),n=BigInt("0"),s=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const n="bigint"==typeof t?t:BigInt(t);if(n>r||n<e)throw new Error(`invalid int64: ${t}`);return n},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>s||e<n)throw new Error(`invalid uint64: ${t}`);return e},enc(e){return t.setBigInt64(0,this.parse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(e){return t.setBigInt64(0,this.uParse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec:(e,r)=>(t.setInt32(0,e,!0),t.setInt32(4,r,!0),t.getBigInt64(0,!0)),uDec:(e,r)=>(t.setInt32(0,e,!0),t.setInt32(4,r,!0),t.getBigUint64(0,!0))}}return{zero:"0",supported:!1,parse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),T(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),p(t),i(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),T(t),i(t)),dec:(t,e)=>function(t,e){let r=a(t,e);const n=2147483648&r.hi;n&&(r=u(r.lo,r.hi));const s=o(r.lo,r.hi);return n?"-"+s:s}(t,e),uDec:(t,e)=>o(t,e)}}function p(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function T(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const E=Symbol.for("@bufbuild/protobuf/text-encoding");function m(){if(null==globalThis[E]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[E]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[E]}var I;!function(t){t[t.Varint=0]="Varint",t[t.Bit64=1]="Bit64",t[t.LengthDelimited=2]="LengthDelimited",t[t.StartGroup=3]="StartGroup",t[t.EndGroup=4]="EndGroup",t[t.Bit32=5]="Bit32"}(I||(I={}));const _=34028234663852886e22,g=-34028234663852886e22;class R{constructor(t=m().encodeUtf8){this.encodeUtf8=t,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let t=0;for(let e=0;e<this.chunks.length;e++)t+=this.chunks[e].length;let e=new Uint8Array(t),r=0;for(let t=0;t<this.chunks.length;t++)e.set(this.chunks[t],r),r+=this.chunks[t].length;return this.chunks=[],e}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let t=this.finish(),e=this.stack.pop();if(!e)throw new Error("invalid state, fork stack empty");return this.chunks=e.chunks,this.buf=e.buf,this.uint32(t.byteLength),this.raw(t)}tag(t,e){return this.uint32((t<<3|e)>>>0)}raw(t){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(t),this}uint32(t){for(O(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return v(t),d(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.encodeUtf8(t);return this.uint32(e.byteLength),this.raw(e)}float(t){!function(t){if("string"==typeof t){const e=t;if(t=Number(t),Number.isNaN(t)&&"NaN"!==e)throw new Error("invalid float32: "+e)}else if("number"!=typeof t)throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>_||t<g))throw new Error("invalid float32: "+t)}(t);let e=new Uint8Array(4);return new DataView(e.buffer).setFloat32(0,t,!0),this.raw(e)}double(t){let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t,!0),this.raw(e)}fixed32(t){O(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){v(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return v(t),d(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),r=new DataView(e.buffer),n=h.enc(t);return r.setInt32(0,n.lo,!0),r.setInt32(4,n.hi,!0),this.raw(e)}fixed64(t){let e=new Uint8Array(8),r=new DataView(e.buffer),n=h.uEnc(t);return r.setInt32(0,n.lo,!0),r.setInt32(4,n.hi,!0),this.raw(e)}int64(t){let e=h.enc(t);return n(e.lo,e.hi,this.buf),this}sint64(t){const e=h.enc(t),r=e.hi>>31;return n(e.lo<<1^r,(e.hi<<1|e.lo>>>31)^r,this.buf),this}uint64(t){const e=h.uEnc(t);return n(e.lo,e.hi,this.buf),this}}class A{constructor(t,e=m().decodeUtf8){this.decodeUtf8=e,this.varint64=r,this.uint32=l,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.uint32(),e=t>>>3,r=7&t;if(e<=0||r<0||r>5)throw new Error("illegal tag: field no "+e+" wire type "+r);return[e,r]}skip(t,e){let r=this.pos;switch(t){case I.Varint:for(;128&this.buf[this.pos++];);break;case I.Bit64:this.pos+=4;case I.Bit32:this.pos+=4;break;case I.LengthDelimited:let r=this.uint32();this.pos+=r;break;case I.StartGroup:for(;;){const[t,r]=this.tag();if(r===I.EndGroup){if(void 0!==e&&t!==e)throw new Error("invalid end group tag");break}this.skip(r,t)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(r,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return 0|this.uint32()}sint32(){let t=this.uint32();return t>>>1^-(1&t)}int64(){return h.dec(...this.varint64())}uint64(){return h.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),r=-(1&t);return t=(t>>>1|(1&e)<<31)^r,e=e>>>1^r,h.dec(t,e)}bool(){let[t,e]=this.varint64();return 0!==t||0!==e}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return h.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return h.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let t=this.uint32(),e=this.pos;return this.pos+=t,this.assertBounds(),this.buf.subarray(e,e+t)}string(){return this.decodeUtf8(this.bytes())}}function v(t){if("string"==typeof t)t=Number(t);else if("number"!=typeof t)throw new Error("invalid int32: "+typeof t);if(!Number.isInteger(t)||t>2147483647||t<-2147483648)throw new Error("invalid int32: "+t)}function O(t){if("string"==typeof t)t=Number(t);else if("number"!=typeof t)throw new Error("invalid uint32: "+typeof t);if(!Number.isInteger(t)||t>4294967295||t<0)throw new Error("invalid uint32: "+t)}var S,y;function N(t){switch(t){case 0:case"TRANSFER_TYPE_UNSPECIFIED":return S.TRANSFER_TYPE_UNSPECIFIED;case 1:case"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT":return S.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case 2:case"TRANSFER_TYPE_TIMED_TRANSFER":return S.TRANSFER_TYPE_TIMED_TRANSFER;case 3:case"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME":return S.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case 4:case"TRANSFER_TYPE_IN_SEAT_TRANSFER":return S.TRANSFER_TYPE_IN_SEAT_TRANSFER;default:return S.UNRECOGNIZED}}function b(t){switch(t){case 0:case"ROUTE_TYPE_UNSPECIFIED":return y.ROUTE_TYPE_UNSPECIFIED;case 1:case"ROUTE_TYPE_TRAM":return y.ROUTE_TYPE_TRAM;case 2:case"ROUTE_TYPE_SUBWAY":return y.ROUTE_TYPE_SUBWAY;case 3:case"ROUTE_TYPE_RAIL":return y.ROUTE_TYPE_RAIL;case 4:case"ROUTE_TYPE_BUS":return y.ROUTE_TYPE_BUS;case 5:case"ROUTE_TYPE_FERRY":return y.ROUTE_TYPE_FERRY;case 6:case"ROUTE_TYPE_CABLE_TRAM":return y.ROUTE_TYPE_CABLE_TRAM;case 7:case"ROUTE_TYPE_AERIAL_LIFT":return y.ROUTE_TYPE_AERIAL_LIFT;case 8:case"ROUTE_TYPE_FUNICULAR":return y.ROUTE_TYPE_FUNICULAR;case 9:case"ROUTE_TYPE_TROLLEYBUS":return y.ROUTE_TYPE_TROLLEYBUS;case 10:case"ROUTE_TYPE_MONORAIL":return y.ROUTE_TYPE_MONORAIL;default:return y.UNRECOGNIZED}}function w(){return{stopTimes:new Uint8Array(0),pickupDropOffTypes:new Uint8Array(0),stops:new Uint8Array(0),serviceRouteId:0}}!function(t){t[t.TRANSFER_TYPE_UNSPECIFIED=0]="TRANSFER_TYPE_UNSPECIFIED",t[t.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT=1]="TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT",t[t.TRANSFER_TYPE_TIMED_TRANSFER=2]="TRANSFER_TYPE_TIMED_TRANSFER",t[t.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME=3]="TRANSFER_TYPE_REQUIRES_MINIMAL_TIME",t[t.TRANSFER_TYPE_IN_SEAT_TRANSFER=4]="TRANSFER_TYPE_IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(S||(S={})),function(t){t[t.ROUTE_TYPE_UNSPECIFIED=0]="ROUTE_TYPE_UNSPECIFIED",t[t.ROUTE_TYPE_TRAM=1]="ROUTE_TYPE_TRAM",t[t.ROUTE_TYPE_SUBWAY=2]="ROUTE_TYPE_SUBWAY",t[t.ROUTE_TYPE_RAIL=3]="ROUTE_TYPE_RAIL",t[t.ROUTE_TYPE_BUS=4]="ROUTE_TYPE_BUS",t[t.ROUTE_TYPE_FERRY=5]="ROUTE_TYPE_FERRY",t[t.ROUTE_TYPE_CABLE_TRAM=6]="ROUTE_TYPE_CABLE_TRAM",t[t.ROUTE_TYPE_AERIAL_LIFT=7]="ROUTE_TYPE_AERIAL_LIFT",t[t.ROUTE_TYPE_FUNICULAR=8]="ROUTE_TYPE_FUNICULAR",t[t.ROUTE_TYPE_TROLLEYBUS=9]="ROUTE_TYPE_TROLLEYBUS",t[t.ROUTE_TYPE_MONORAIL=10]="ROUTE_TYPE_MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(y||(y={}));const U={encode:(t,e=new R)=>(0!==t.stopTimes.length&&e.uint32(10).bytes(t.stopTimes),0!==t.pickupDropOffTypes.length&&e.uint32(18).bytes(t.pickupDropOffTypes),0!==t.stops.length&&e.uint32(26).bytes(t.stops),0!==t.serviceRouteId&&e.uint32(32).uint32(t.serviceRouteId),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s=w();for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopTimes=r.bytes();continue;case 2:if(18!==t)break;s.pickupDropOffTypes=r.bytes();continue;case 3:if(26!==t)break;s.stops=r.bytes();continue;case 4:if(32!==t)break;s.serviceRouteId=r.uint32();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stopTimes:B(t.stopTimes)?D(t.stopTimes):new Uint8Array(0),pickupDropOffTypes:B(t.pickupDropOffTypes)?D(t.pickupDropOffTypes):new Uint8Array(0),stops:B(t.stops)?D(t.stops):new Uint8Array(0),serviceRouteId:B(t.serviceRouteId)?globalThis.Number(t.serviceRouteId):0}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=F(t.stopTimes)),0!==t.pickupDropOffTypes.length&&(e.pickupDropOffTypes=F(t.pickupDropOffTypes)),0!==t.stops.length&&(e.stops=F(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s;const i=w();return i.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),i.pickupDropOffTypes=null!==(r=t.pickupDropOffTypes)&&void 0!==r?r:new Uint8Array(0),i.stops=null!==(n=t.stops)&&void 0!==n?n:new Uint8Array(0),i.serviceRouteId=null!==(s=t.serviceRouteId)&&void 0!==s?s:0,i}};const P={encode:(t,e=new R)=>(0!==t.destination&&e.uint32(8).uint32(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).uint32(t.minTransferTime),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={destination:0,type:0,minTransferTime:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.destination=r.uint32();continue;case 2:if(16!==t)break;s.type=r.int32();continue;case 3:if(24!==t)break;s.minTransferTime=r.uint32();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({destination:B(t.destination)?globalThis.Number(t.destination):0,type:B(t.type)?N(t.type):0,minTransferTime:B(t.minTransferTime)?globalThis.Number(t.minTransferTime):void 0}),toJSON(t){const e={};return 0!==t.destination&&(e.destination=Math.round(t.destination)),0!==t.type&&(e.type=function(t){switch(t){case S.TRANSFER_TYPE_UNSPECIFIED:return"TRANSFER_TYPE_UNSPECIFIED";case S.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT";case S.TRANSFER_TYPE_TIMED_TRANSFER:return"TRANSFER_TYPE_TIMED_TRANSFER";case S.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME";case S.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"TRANSFER_TYPE_IN_SEAT_TRANSFER";case S.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>P.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n;const s={destination:0,type:0,minTransferTime:void 0};return s.destination=null!==(e=t.destination)&&void 0!==e?e:0,s.type=null!==(r=t.type)&&void 0!==r?r:0,s.minTransferTime=null!==(n=t.minTransferTime)&&void 0!==n?n:void 0,s}};const x={encode:(t,e=new R)=>(0!==t.stopIndex&&e.uint32(8).uint32(t.stopIndex),0!==t.routeId&&e.uint32(16).uint32(t.routeId),0!==t.tripIndex&&e.uint32(24).uint32(t.tripIndex),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={stopIndex:0,routeId:0,tripIndex:0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.stopIndex=r.uint32();continue;case 2:if(16!==t)break;s.routeId=r.uint32();continue;case 3:if(24!==t)break;s.tripIndex=r.uint32();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stopIndex:B(t.stopIndex)?globalThis.Number(t.stopIndex):0,routeId:B(t.routeId)?globalThis.Number(t.routeId):0,tripIndex:B(t.tripIndex)?globalThis.Number(t.tripIndex):0}),toJSON(t){const e={};return 0!==t.stopIndex&&(e.stopIndex=Math.round(t.stopIndex)),0!==t.routeId&&(e.routeId=Math.round(t.routeId)),0!==t.tripIndex&&(e.tripIndex=Math.round(t.tripIndex)),e},create:t=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n;const s={stopIndex:0,routeId:0,tripIndex:0};return s.stopIndex=null!==(e=t.stopIndex)&&void 0!==e?e:0,s.routeId=null!==(r=t.routeId)&&void 0!==r?r:0,s.tripIndex=null!==(n=t.tripIndex)&&void 0!==n?n:0,s}};const L={encode(t,e=new R){void 0!==t.origin&&x.encode(t.origin,e.uint32(10).fork()).join();for(const r of t.destinations)x.encode(r,e.uint32(18).fork()).join();return e},decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={origin:void 0,destinations:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.origin=x.decode(r,r.uint32());continue;case 2:if(18!==t)break;s.destinations.push(x.decode(r,r.uint32()));continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({origin:B(t.origin)?x.fromJSON(t.origin):void 0,destinations:globalThis.Array.isArray(null==t?void 0:t.destinations)?t.destinations.map((t=>x.fromJSON(t))):[]}),toJSON(t){var e;const r={};return void 0!==t.origin&&(r.origin=x.toJSON(t.origin)),(null===(e=t.destinations)||void 0===e?void 0:e.length)&&(r.destinations=t.destinations.map((t=>x.toJSON(t)))),r},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={origin:void 0,destinations:[]};return r.origin=void 0!==t.origin&&null!==t.origin?x.fromPartial(t.origin):void 0,r.destinations=(null===(e=t.destinations)||void 0===e?void 0:e.map((t=>x.fromPartial(t))))||[],r}};const M={encode(t,e=new R){e.uint32(10).fork();for(const r of t.routes)e.uint32(r);e.join();for(const r of t.transfers)P.encode(r,e.uint32(18).fork()).join();return e},decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={routes:[],transfers:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8===t){s.routes.push(r.uint32());continue}if(10===t){const t=r.uint32()+r.pos;for(;r.pos<t;)s.routes.push(r.uint32());continue}break;case 2:if(18!==t)break;s.transfers.push(P.decode(r,r.uint32()));continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[],transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>P.fromJSON(t))):[]}),toJSON(t){var e,r;const n={};return(null===(e=t.routes)||void 0===e?void 0:e.length)&&(n.routes=t.routes.map((t=>Math.round(t)))),(null===(r=t.transfers)||void 0===r?void 0:r.length)&&(n.transfers=t.transfers.map((t=>P.toJSON(t)))),n},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={routes:[],transfers:[]};return n.routes=(null===(e=t.routes)||void 0===e?void 0:e.map((t=>t)))||[],n.transfers=(null===(r=t.transfers)||void 0===r?void 0:r.map((t=>P.fromPartial(t))))||[],n}};const C={encode(t,e=new R){0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e.uint32(26).fork();for(const r of t.routes)e.uint32(r);return e.join(),e},decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={type:0,name:"",routes:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.type=r.int32();continue;case 2:if(18!==t)break;s.name=r.string();continue;case 3:if(24===t){s.routes.push(r.uint32());continue}if(26===t){const t=r.uint32()+r.pos;for(;r.pos<t;)s.routes.push(r.uint32());continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({type:B(t.type)?b(t.type):0,name:B(t.name)?globalThis.String(t.name):"",routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[]}),toJSON(t){var e;const r={};return 0!==t.type&&(r.type=function(t){switch(t){case y.ROUTE_TYPE_UNSPECIFIED:return"ROUTE_TYPE_UNSPECIFIED";case y.ROUTE_TYPE_TRAM:return"ROUTE_TYPE_TRAM";case y.ROUTE_TYPE_SUBWAY:return"ROUTE_TYPE_SUBWAY";case y.ROUTE_TYPE_RAIL:return"ROUTE_TYPE_RAIL";case y.ROUTE_TYPE_BUS:return"ROUTE_TYPE_BUS";case y.ROUTE_TYPE_FERRY:return"ROUTE_TYPE_FERRY";case y.ROUTE_TYPE_CABLE_TRAM:return"ROUTE_TYPE_CABLE_TRAM";case y.ROUTE_TYPE_AERIAL_LIFT:return"ROUTE_TYPE_AERIAL_LIFT";case y.ROUTE_TYPE_FUNICULAR:return"ROUTE_TYPE_FUNICULAR";case y.ROUTE_TYPE_TROLLEYBUS:return"ROUTE_TYPE_TROLLEYBUS";case y.ROUTE_TYPE_MONORAIL:return"ROUTE_TYPE_MONORAIL";case y.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),""!==t.name&&(r.name=t.name),(null===(e=t.routes)||void 0===e?void 0:e.length)&&(r.routes=t.routes.map((t=>Math.round(t)))),r},create:t=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n;const s={type:0,name:"",routes:[]};return s.type=null!==(e=t.type)&&void 0!==e?e:0,s.name=null!==(r=t.name)&&void 0!==r?r:"",s.routes=(null===(n=t.routes)||void 0===n?void 0:n.map((t=>t)))||[],s}};const Y={encode(t,e=new R){for(const r of t.stopsAdjacency)M.encode(r,e.uint32(10).fork()).join();for(const r of t.routesAdjacency)U.encode(r,e.uint32(18).fork()).join();for(const r of t.serviceRoutes)C.encode(r,e.uint32(26).fork()).join();for(const r of t.tripContinuations)L.encode(r,e.uint32(34).fork()).join();for(const r of t.guaranteedTripTransfers)L.encode(r,e.uint32(42).fork()).join();return e},decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopsAdjacency.push(M.decode(r,r.uint32()));continue;case 2:if(18!==t)break;s.routesAdjacency.push(U.decode(r,r.uint32()));continue;case 3:if(26!==t)break;s.serviceRoutes.push(C.decode(r,r.uint32()));continue;case 4:if(34!==t)break;s.tripContinuations.push(L.decode(r,r.uint32()));continue;case 5:if(42!==t)break;s.guaranteedTripTransfers.push(L.decode(r,r.uint32()));continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>M.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>U.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>C.fromJSON(t))):[],tripContinuations:globalThis.Array.isArray(null==t?void 0:t.tripContinuations)?t.tripContinuations.map((t=>L.fromJSON(t))):[],guaranteedTripTransfers:globalThis.Array.isArray(null==t?void 0:t.guaranteedTripTransfers)?t.guaranteedTripTransfers.map((t=>L.fromJSON(t))):[]}),toJSON(t){var e,r,n,s,i;const o={};return(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(o.stopsAdjacency=t.stopsAdjacency.map((t=>M.toJSON(t)))),(null===(r=t.routesAdjacency)||void 0===r?void 0:r.length)&&(o.routesAdjacency=t.routesAdjacency.map((t=>U.toJSON(t)))),(null===(n=t.serviceRoutes)||void 0===n?void 0:n.length)&&(o.serviceRoutes=t.serviceRoutes.map((t=>C.toJSON(t)))),(null===(s=t.tripContinuations)||void 0===s?void 0:s.length)&&(o.tripContinuations=t.tripContinuations.map((t=>L.toJSON(t)))),(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.length)&&(o.guaranteedTripTransfers=t.guaranteedTripTransfers.map((t=>L.toJSON(t)))),o},create:t=>Y.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s,i;const o={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};return o.stopsAdjacency=(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.map((t=>M.fromPartial(t))))||[],o.routesAdjacency=(null===(r=t.routesAdjacency)||void 0===r?void 0:r.map((t=>U.fromPartial(t))))||[],o.serviceRoutes=(null===(n=t.serviceRoutes)||void 0===n?void 0:n.map((t=>C.fromPartial(t))))||[],o.tripContinuations=(null===(s=t.tripContinuations)||void 0===s?void 0:s.map((t=>L.fromPartial(t))))||[],o.guaranteedTripTransfers=(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.map((t=>L.fromPartial(t))))||[],o}};function D(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;++t)r[t]=e.charCodeAt(t);return r}}function F(t){if(globalThis.Buffer)return globalThis.Buffer.from(t).toString("base64");{const e=[];return t.forEach((t=>{e.push(globalThis.String.fromCharCode(t))})),globalThis.btoa(e.join(""))}}function B(t){return null!=t}const k=0,$=1;let j=class t{constructor(t,e,r,n,s){this.id=t,this.stopTimes=e,this.pickupDropOffTypes=r,this.stops=n,this.serviceRouteId=s,this.nbStops=n.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<n.length;t++){const e=n[t],r=this.stopIndices.get(e);r?r.push(t):this.stopIndices.set(e,[t])}}static of(e){var r,n;const{id:s,serviceRouteId:i,trips:o}=e;if(0===o.length)throw new Error("At least one trip must be provided");const a=o[0],u=new Uint32Array(a.stops.map((t=>t.id))),c=u.length;for(let t=1;t<o.length;t++){const e=o[t];if(e.stops.length!==c)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${c}`);for(let r=0;r<c;r++)if(e.stops[r].id!==u[r])throw new Error(`Trip ${t} has different stop at index ${r}`)}const d=new Uint16Array(o.length*c*2);for(let t=0;t<o.length;t++){const e=o[t];for(let r=0;r<c;r++){const n=e.stops[r],s=2*(t*c+r);d[s]=n.arrivalTime,d[s+1]=n.departureTime}}const l=o.length*c,h=new Uint8Array(Math.ceil(l/2));for(let t=0;t<o.length;t++){const e=o[t];for(let s=0;s<c;s++){const i=e.stops[s],o=t*c+s,a=null!==(r=i.pickUpType)&&void 0!==r?r:k,u=null!==(n=i.dropOffType)&&void 0!==n?n:k,d=Math.floor(o/2),l=o%2==1;h[d]|=l?a<<6|u<<4:a<<2|u}}return new t(s,d,h,u,i)}serialize(){return{stopTimes:this.stopTimes,pickupDropOffTypes:this.pickupDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}getNbStops(){return this.nbStops}getNbTrips(){return this.nbTrips}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const r=2*(e*this.stops.length+t),n=this.stopTimes[r];if(void 0===n)throw new Error(`Arrival time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return n}tripStopOffset(t){return t*this.nbStops}arrivalAtOffset(t,e){return this.stopTimes[2*(e+t)]}departureAtOffset(t,e){return this.stopTimes[2*(e+t)+1]}dropOffTypeAtOffset(t,e){const r=e+t,n=this.pickupDropOffTypes[r>>1];return 1&r?n>>4&3:3&n}departureFrom(t,e){const r=2*(e*this.stops.length+t)+1,n=this.stopTimes[r];if(void 0===n)throw new Error(`Departure time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return n}pickUpTypeFrom(t,e){const r=e*this.stops.length+t,n=r>>1,s=!(1&~r),i=this.pickupDropOffTypes[n];if(void 0===i)throw new Error(`Pick up type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return s?i>>6&3:i>>2&3}dropOffTypeAt(t,e){const r=e*this.stops.length+t,n=r>>1,s=!(1&~r),i=this.pickupDropOffTypes[n];if(void 0===i)throw new Error(`Drop off type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return s?i>>4&3:3&i}findEarliestTrip(t,e=0,r){if(this.nbTrips<=0)return;let n=this.nbTrips-1;if(void 0!==r&&(n=Math.min(n,r-1)),n<0)return;let s=0,i=-1;for(;s<=n;){const r=s+n>>>1;this.departureFrom(t,r)<e?s=r+1:(i=r,n=r-1)}return-1!==i?i:void 0}stopRouteIndices(t){const e=this.stopIndices.get(t);return void 0===e?[]:e}stopId(t){const e=this.stops[t];if(void 0===e)throw new Error(`StopId for stop at index ${t} not found in route ${this.serviceRouteId}`);return e}};const z=(BigInt(1)<<BigInt(20))-BigInt(1),G=1048575,V=BigInt(0),J=BigInt(20),W=BigInt(40),Z=(t,e)=>{if(t<0||t>G)throw new Error(`${e} must be between 0 and 1048575, got ${t}`)},Q=(t,e,r)=>(Z(t,"stopIndex"),Z(e,"routeId"),Z(r,"tripIndex"),BigInt(t)<<W|BigInt(e)<<J|BigInt(r)<<V),q=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),X=!0,H=t=>{if(q===X)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),r=new DataView(e.buffer);for(let e=0;e<t.length;e++)r.setUint32(4*e,t[e],X);return e},K=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(q===X)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),r=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=r.getUint32(4*t,X);return e},tt=t=>{if(q===X)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),r=new DataView(e.buffer);for(let e=0;e<t.length;e++)r.setUint16(2*e,t[e],X);return e},et=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(q===X)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),r=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=r.getUint16(2*t,X);return e},rt=t=>{const e=[];return t.forEach((t=>{const r=t.serialize();e.push({stopTimes:tt(r.stopTimes),pickupDropOffTypes:r.pickupDropOffTypes,stops:H(r.stops),serviceRouteId:r.serviceRouteId})})),e},nt=t=>{switch(t){case S.TRANSFER_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf transfer type.");case S.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return ct.RECOMMENDED;case S.TRANSFER_TYPE_TIMED_TRANSFER:return ct.GUARANTEED;case S.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return ct.REQUIRES_MINIMAL_TIME;case S.TRANSFER_TYPE_IN_SEAT_TRANSFER:return ct.IN_SEAT;case S.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},st=t=>{switch(t){case ct.RECOMMENDED:return S.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case ct.GUARANTEED:return S.TRANSFER_TYPE_TIMED_TRANSFER;case ct.REQUIRES_MINIMAL_TIME:return S.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case ct.IN_SEAT:return S.TRANSFER_TYPE_IN_SEAT_TRANSFER}},it=t=>{switch(t){case y.ROUTE_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf route type.");case y.ROUTE_TYPE_TRAM:return dt.TRAM;case y.ROUTE_TYPE_SUBWAY:return dt.SUBWAY;case y.ROUTE_TYPE_RAIL:return dt.RAIL;case y.ROUTE_TYPE_BUS:return dt.BUS;case y.ROUTE_TYPE_FERRY:return dt.FERRY;case y.ROUTE_TYPE_CABLE_TRAM:return dt.CABLE_TRAM;case y.ROUTE_TYPE_AERIAL_LIFT:return dt.AERIAL_LIFT;case y.ROUTE_TYPE_FUNICULAR:return dt.FUNICULAR;case y.ROUTE_TYPE_TROLLEYBUS:return dt.TROLLEYBUS;case y.ROUTE_TYPE_MONORAIL:return dt.MONORAIL;case y.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},ot=t=>{switch(t){case dt.TRAM:return y.ROUTE_TYPE_TRAM;case dt.SUBWAY:return y.ROUTE_TYPE_SUBWAY;case dt.RAIL:return y.ROUTE_TYPE_RAIL;case dt.BUS:return y.ROUTE_TYPE_BUS;case dt.FERRY:return y.ROUTE_TYPE_FERRY;case dt.CABLE_TRAM:return y.ROUTE_TYPE_CABLE_TRAM;case dt.AERIAL_LIFT:return y.ROUTE_TYPE_AERIAL_LIFT;case dt.FUNICULAR:return y.ROUTE_TYPE_FUNICULAR;case dt.TROLLEYBUS:return y.ROUTE_TYPE_TROLLEYBUS;case dt.MONORAIL:return y.ROUTE_TYPE_MONORAIL}},at=t=>{const e=[];for(const[n,s]of t.entries()){const[t,i,o]=(r=n,[Number(r>>W&z),Number(r>>J&z),Number(r>>V&z)]);e.push({origin:{stopIndex:t,routeId:i,tripIndex:o},destinations:s.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})))})}var r;return e},ut=t=>{const e=new Map;for(let r=0;r<t.length;r++){const n=t[r],s=n.origin,i=Q(s.stopIndex,s.routeId,s.tripIndex),o=n.destinations.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(i,o)}return e},ct={RECOMMENDED:1,GUARANTEED:2,REQUIRES_MINIMAL_TIME:3,IN_SEAT:4},dt={TRAM:1,SUBWAY:2,RAIL:3,BUS:4,FERRY:5,CABLE_TRAM:6,AERIAL_LIFT:7,FUNICULAR:8,TROLLEYBUS:9,MONORAIL:10},lt=new Set(Object.values(dt)),ht=[];class ft{constructor(t,e,r,n,s){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=r,this.tripContinuations=n,this.guaranteedTripTransfers=s,this.activeStops=new Set;for(let e=0;e<t.length;e++){const r=t[e];(r.routes.length>0||r.transfers&&r.transfers.length>0)&&this.activeStops.add(e)}}serialize(){const t={stopsAdjacency:(r=this.stopsAdjacency,r.map((t=>({transfers:t.transfers?t.transfers.map((t=>Object.assign({destination:t.destination,type:st(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime}))):[],routes:t.routes})))),routesAdjacency:rt(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:ot(t.type),name:t.name,routes:t.routes})))),tripContinuations:at(this.tripContinuations||new Map),guaranteedTripTransfers:at(this.guaranteedTripTransfers||new Map)};var e,r;const n=new R;return Y.encode(t,n),n.finish()}static fromData(t){const e=new A(t),r=Y.decode(e);return new ft((t=>{const e=[];for(let r=0;r<t.length;r++){const n=t[r],s=[];for(let t=0;t<n.transfers.length;t++){const e=n.transfers[t],r=Object.assign({destination:e.destination,type:nt(e.type)},void 0!==e.minTransferTime&&{minTransferTime:e.minTransferTime});s.push(r)}const i={routes:n.routes};s.length>0&&(i.transfers=s),e.push(i)}return e})(r.stopsAdjacency),(t=>{const e=[];for(let r=0;r<t.length;r++){const n=t[r],s=K(n.stops);e.push(new j(r,et(n.stopTimes),n.pickupDropOffTypes,s,n.serviceRouteId))}return e})(r.routesAdjacency),(t=>{const e=[];for(let r=0;r<t.length;r++){const n=t[r];e.push({type:it(n.type),name:n.name,routes:n.routes})}return e})(r.serviceRoutes),ut(r.tripContinuations),ut(r.guaranteedTripTransfers))}isActive(t){return this.activeStops.has(t)}nbStops(){return this.stopsAdjacency.length}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){const e=this.stopsAdjacency[t];if(!e)throw new Error(`Stop ID ${t} not found`);return e.transfers||[]}getContinuousTrips(t,e,r){var n;const s=null===(n=this.tripContinuations)||void 0===n?void 0:n.get(Q(t,e,r));return s||ht}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);return{type:e.type,name:e.name}}routesPassingThrough(t){const e=this.stopsAdjacency[t];if(!e)return[];const r=[];for(let t=0;t<e.routes.length;t++){const n=e.routes[t],s=this.routesAdjacency[n];s&&r.push(s)}return r}findReachableRoutes(t,e=lt){const r=new Map,n=e!==lt;for(const s of t){const t=this.stopsAdjacency[s];if(t)for(let i=0;i<t.routes.length;i++){const o=this.routesAdjacency[t.routes[i]];if(!o)continue;if(n){const t=this.serviceRoutes[o.serviceRoute()];if(!t||!e.has(t.type))continue}const a=o.stopRouteIndices(s)[0],u=r.get(o);void 0!==u?a<u&&r.set(o,a):r.set(o,a)}}return r}isTripTransferGuaranteed(t,e){var r;const n=Q(t.stopIndex,t.routeId,t.tripIndex),s=null===(r=this.guaranteedTripTransfers)||void 0===r?void 0:r.get(n);if(!s)return!1;for(let t=0;t<s.length;t++){const r=s[t];if(r.stopIndex===e.stopIndex&&r.routeId===e.routeId&&r.tripIndex===e.tripIndex)return!0}return!1}findFirstBoardableTrip(t,e,r,n=0,s,i,o=0){const a=e.getNbTrips();for(let u=r;u<(null!=s?s:a);u++){if(e.pickUpTypeFrom(t,u)===$)continue;if(void 0===i)return u;if(this.isTripTransferGuaranteed(i,{stopIndex:t,routeId:e.id,tripIndex:u}))return u;if(e.departureFrom(t,u)>=n+o)return u}}getGuaranteedTripTransfers(t,e,r){var n;const s=null===(n=this.guaranteedTripTransfers)||void 0===n?void 0:n.get(Q(t,e,r));return s||ht}}const pt=t=>{switch(t){case dt.TRAM:return"TRAM";case dt.SUBWAY:return"SUBWAY";case dt.RAIL:return"RAIL";case dt.BUS:return"BUS";case dt.FERRY:return"FERRY";case dt.CABLE_TRAM:return"CABLE_TRAM";case dt.AERIAL_LIFT:return"AERIAL_LIFT";case dt.FUNICULAR:return"FUNICULAR";case dt.TROLLEYBUS:return"TROLLEYBUS";case dt.MONORAIL:return"MONORAIL"}},Tt=t=>{switch(t){case ct.RECOMMENDED:return"RECOMMENDED";case ct.GUARANTEED:return"GUARANTEED";case ct.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case ct.IN_SEAT:return"IN_SEAT"}},Et={colors:{rounds:["#60a5fa","#ff9800","#14b8a6","#fb7185","#ffdf00","#b600ff","#ee82ee"],defaultRound:"#888888",originStation:"#60a5fa",destinationStation:"#ee82ee",defaultStation:"white",continuationFill:"#ffffcc"},penWidth:{continuation:2,continuationEdge:3}};function mt(t){return"routeId"in t&&"stopIndex"in t&&"hopOffStopIndex"in t}function It(t){return"from"in t&&"to"in t&&"type"in t}function _t(t){return"from"in t&&"duration"in t}class gt{constructor(){this.lines=[]}addHeader(){return this.lines.push("digraph RoutingGraph {"," graph [overlap=false, splines=true, rankdir=TB, bgcolor=white, nodesep=0.8, ranksep=1.2, concentrate=true];",' node [fontname="Arial" margin=0.1];',' edge [fontname="Arial" fontsize=10];'),this}addComment(t){return this.lines.push("",` // ${t}`),this}addNode(t,e){const r=Object.entries(e).map((([t,e])=>`${t}="${e}"`)).join(" ");return this.lines.push(` "${t}" [${r}];`),this}addEdge(t,e,r={}){const n=Object.entries(r).map((([t,e])=>`${t}="${e}"`)).join(" "),s=n?` [${n}]`:"";return this.lines.push(` "${t}" -> "${e}"${s};`),this}addRaw(t){return this.lines.push(...t),this}build(){return this.lines.push("}"),this.lines.join("\n")}}class Rt{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}Rt.Builder=class{constructor(){var t;this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:(t=120,Math.round(t/60)),transportModes:lt}}from(t){return this.fromValue=t,this}to(t){return this.toValue=t instanceof Set?t:new Set([t]),this}departureTime(t){return this.departureTimeValue=t,this}maxTransfers(t){return this.optionsValue.maxTransfers=t,this}minTransferTime(t){return this.optionsValue.minTransferTime=t,this}transportModes(t){return this.optionsValue.transportModes=t,this}maxDuration(t){return this.optionsValue.maxDuration=t,this}maxInitialWaitingTime(t){return this.optionsValue.maxInitialWaitingTime=t,this}build(){return new Rt(this)}};class At extends Rt{constructor(t){super(t),this.lastDepartureTime=t.lastDepartureTimeValue,this.rangeOptions=t.rangeOptionsValue}}At.Builder=class extends Rt.Builder{constructor(){super(...arguments),this.rangeOptionsValue={optimizeBeyondLatestDeparture:!0}}lastDepartureTime(t){return this.lastDepartureTimeValue=t,this}rangeOptions(t){return this.rangeOptionsValue=Object.assign(Object.assign({},this.rangeOptionsValue),t),this}build(){return new At(this)}};class vt{constructor(t){this.legs=t}departureTime(){let t=0;for(let e=0;e<this.legs.length;e++){const r=this.legs[e];if("departureTime"in r)return r.departureTime-t;"duration"in r&&r.duration&&(t+=r.duration)}throw new Error("No vehicle leg found in route")}arrivalTime(){let t=0,e=0;for(let r=this.legs.length-1;r>=0;r--){const n=this.legs[r];if("arrivalTime"in n)return t=n.arrivalTime,t+e;"minTransferTime"in n&&n.minTransferTime&&(e+=n.minTransferTime)}throw new Error("No vehicle leg found in route")}totalDuration(){return 0===this.legs.length?0:Math.abs(this.arrivalTime()-this.departureTime())}toString(){return this.legs.map(((r,n)=>{const s=`From: ${r.from.name}${r.from.platform?` (Pl. ${r.from.platform})`:""}`,i=`To: ${r.to.name}${r.to.platform?` (Pl. ${r.to.platform})`:""}`,o="type"in r&&!("route"in r)?`Transfer: ${r.type}${r.minTransferTime?`, Minimum Transfer Time: ${e(r.minTransferTime)}`:""}`:"",a="duration"in r?`Access duration: ${e(r.duration)}`:"",u="route"in r&&"departureTime"in r&&"arrivalTime"in r?`Route: ${r.route.type} ${r.route.name}, Departure: ${t(r.departureTime)}, Arrival: ${t(r.arrivalTime)}`:"";return[`Leg ${n+1}:`,` ${s}`,` ${i}`,o?` ${o}`:"",a?` ${a}`:"",u?` ${u}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}}const Ot=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],St=t=>{const e=Ot[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};class yt{constructor(t,e,r,n){this.destinations=t,this.routingState=e,this.stopsIndex=r,this.timetable=n}expandDestinations(t){const e=t instanceof Set?t:void 0!==t?[t]:this.destinations,r=new Set;for(const t of e)for(const e of this.stopsIndex.equivalentStops(t))r.add(e.id);return r}bestRouteToSourceStopId(t){var e;if(t instanceof Set){const e=new Set;for(const r of t){const t=this.stopsIndex.findStopBySourceStopId(r);void 0!==t&&e.add(t.id)}return 0===e.size?void 0:this.bestRoute(e)}const r=null===(e=this.stopsIndex.findStopBySourceStopId(t))||void 0===e?void 0:e.id;return void 0===r?void 0:this.bestRoute(r)}bestRoute(t){var e;const r=this.expandDestinations(t);let n,s,i;for(const t of r){const e=this.routingState.getArrival(t);void 0!==e&&(void 0===s||e.arrival<s)&&(n=t,s=e.arrival,i=e.legNumber)}if(void 0===n||void 0===i)return;const o=[];let a,u=n,c=i;for(;c>=0;){const t=null===(e=this.routingState.graph[c])||void 0===e?void 0:e[u];if(!t){if(0===c)break;throw new Error(`No edge arriving at stop ${u} at round ${c}`)}let r;if("routeId"in t){let e,n;if(t.continuationOf){let r=t;const s=[r];for(;r.continuationOf;)s.push(r.continuationOf),r=r.continuationOf;e=r,n=this.buildVehicleLeg(s)}else e=t,n=this.buildVehicleLeg([t]);r=n,a&&this.timetable.isTripTransferGuaranteed({stopIndex:e.hopOffStopIndex,routeId:e.routeId,tripIndex:e.tripIndex},{stopIndex:a.stopIndex,routeId:a.routeId,tripIndex:a.tripIndex})&&o.push(this.buildGuaranteedTransferLeg(e,a)),a=e}else if("type"in t)r=this.buildTransferLeg(t),a=void 0;else{if(!("duration"in t))break;r=this.buildAccessLeg(t),a=void 0}o.push(r),u=r.from.id,"routeId"in t&&(c-=1)}return new vt(o.reverse())}buildServiceRouteInfo(t){const e=this.timetable.getServiceRouteInfo(t);return{type:pt(e.type),name:e.name}}buildVehicleLeg(t){if(0===t.length)throw new Error("Cannot build vehicle leg from empty edges");const e=t[t.length-1],r=t[0],n=this.timetable.getRoute(e.routeId),s=this.timetable.getRoute(r.routeId);return{from:this.stopsIndex.findStopById(n.stopId(e.stopIndex)),to:this.stopsIndex.findStopById(s.stopId(r.hopOffStopIndex)),route:this.buildServiceRouteInfo(n),departureTime:n.departureFrom(e.stopIndex,e.tripIndex),arrivalTime:r.arrival,pickUpType:St(n.pickUpTypeFrom(e.stopIndex,e.tripIndex)),dropOffType:St(s.dropOffTypeAt(r.hopOffStopIndex,r.tripIndex))}}buildTransferLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),minTransferTime:t.minTransferTime,type:Tt(t.type)}}buildAccessLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),duration:t.duration}}buildGuaranteedTransferLeg(t,e){const r=this.timetable.getRoute(t.routeId),n=this.timetable.getRoute(e.routeId),s=r.stopId(t.hopOffStopIndex),i=n.stopId(e.stopIndex);return{from:this.stopsIndex.findStopById(s),to:this.stopsIndex.findStopById(i),type:Tt(ct.GUARANTEED)}}arrivalAt(t,e){var r,n;const s=this.stopsIndex.equivalentStops(t);let i;for(const t of s){let s;if(void 0===e||(null===(r=this.routingState.getArrival(t.id))||void 0===r?void 0:r.legNumber)===e+1)s=this.routingState.getArrival(t.id);else for(let r=e+1;r>=0;r--){const e=null===(n=this.routingState.graph[r])||void 0===n?void 0:n[t.id];if(void 0!==e){s={arrival:e.arrival,legNumber:r};break}}void 0!==s&&(void 0===i||s.arrival<i.arrival)&&(i=s)}return i}}class Nt{constructor(t,e){this.timetable=t,this.stopsIndex=e}collectAccessPaths(t,e){var r;const n=this.stopsIndex.equivalentStops(t).map((t=>t.id)),s=new Map;for(const t of n){const n=s.get(t);(void 0===n||n.duration>0)&&s.set(t,{fromStopId:t,toStopId:t,duration:0});for(const n of this.timetable.getTransfers(t))if(n.type===ct.REQUIRES_MINIMAL_TIME){const i=null!==(r=n.minTransferTime)&&void 0!==r?r:e,o=s.get(n.destination);(void 0===o||o.duration&&i<o.duration)&&s.set(n.destination,{fromStopId:t,toStopId:n.destination,duration:i})}}return Array.from(s.values())}collectDepartureTimes(t,e,r){const n=new Map;for(const s of t){const{toStopId:t}=s,i=e+s.duration,o=r+s.duration;for(const e of this.timetable.routesPassingThrough(t))for(const r of e.stopRouteIndices(t)){let t=e.findEarliestTrip(r,i);if(void 0===t)continue;const a=e.getNbTrips();for(;t<a;){const i=e.departureFrom(r,t);if(i>o)break;if(e.pickUpTypeFrom(r,t)!==$){const t=i-s.duration;let e=n.get(t);void 0===e&&n.set(t,e=new Set),e.add(s)}t++}}}if(0===n.size)return[];return Array.from(n.entries()).sort((([t],[e])=>e-t)).map((([t,e])=>({depTime:t,legs:Array.from(e)})))}}const bt=65535;class wt{constructor(t,e,r,n,s=0,i){this._destinationBest=bt,this.maxArrivalTime=bt,this.reachedStops=[],this.destinations=e,this.maxDuration=i,this.maxArrivalTime=void 0===i?bt:t+i,this.destinationSet=new Set(e),this.earliestArrivalTimes=new Uint16Array(n).fill(bt),this.earliestArrivalLegs=new Uint8Array(n),this.origins=[],this.graph=[new Array(n)];for(let t=1;t<=s;t++)this.graph.push(new Array(n));this.seedAccessPaths(t,r)}seedAccessPaths(t,e){const r=new Set;for(const n of e){const e=t+n.duration;if(e>this.maxArrivalTime)continue;const s=0===n.duration?{stopId:n.fromStopId,arrival:t}:{arrival:e,from:n.fromStopId,to:n.toStopId,duration:n.duration},i=n.toStopId;e<this.earliestArrivalTimes[i]&&(this.earliestArrivalTimes[i]=e,this.graph[0][i]=s),r.add(i)}for(const t of r)this.reachedStops.push(t);this.origins=Array.from(r);for(let t=0;t<this.destinations.length;t++){const e=this.earliestArrivalTimes[this.destinations[t]];e<this._destinationBest&&(this._destinationBest=e)}}get nbStops(){return this.earliestArrivalTimes.length}arrivalTime(t){return this.earliestArrivalTimes[t]}get destinationBest(){return this._destinationBest}improvementBound(t,e){return this.arrivalTime(e)}initRound(t){}updateArrival(t,e,r){this.reachedStops.push(t),this.earliestArrivalTimes[t]=e,this.earliestArrivalLegs[t]=r,this.destinationSet.has(t)&&e<this._destinationBest&&(this._destinationBest=e)}resetFor(t,e){for(const t of this.reachedStops){this.earliestArrivalTimes[t]=bt,this.earliestArrivalLegs[t]=0;for(let e=0;e<this.graph.length;e++)this.graph[e][t]=void 0}this.reachedStops.length=0,this._destinationBest=bt,this.maxArrivalTime=void 0===this.maxDuration?bt:t+this.maxDuration,this.seedAccessPaths(t,e)}*arrivals(){for(let t=0;t<this.earliestArrivalTimes.length;t++){const e=this.earliestArrivalTimes[t];e<bt&&(yield{stop:t,arrival:e,legNumber:this.earliestArrivalLegs[t]})}}earliestArrivalAtAnyDestination(){return this._destinationBest}getArrival(t){const e=this.earliestArrivalTimes[t];if(!(e>=bt))return{arrival:e,legNumber:this.earliestArrivalLegs[t]}}isDestination(t){return this.destinationSet.has(t)}static fromTestData({nbStops:t,origins:e=[],destinations:r=[],arrivals:n=[],graph:s=[]}){const i=new wt(0,r,e.map((t=>({fromStopId:t,toStopId:t,duration:0}))),t),o=new Uint16Array(t).fill(bt),a=new Uint8Array(t);for(const[t,e,r]of n)o[t]=e,a[t]=r;i.earliestArrivalTimes=o,i.earliestArrivalLegs=a,i._destinationBest=bt;for(const t of r){const e=o[t];void 0!==e&&e<i._destinationBest&&(i._destinationBest=e)}const u=s.map((e=>{const r=new Array(t);for(const[t,n]of e)r[t]=n;return r}));return i.graph.splice(0,i.graph.length,...u),i}}class Ut{constructor(t,e,r,n){this.timetable=t,this.stopsIndex=e,this.accessFinder=r,this.raptor=n}route(t){const e=this.accessFinder.collectAccessPaths(t.from,t.options.minTransferTime),r=Array.from(t.to).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),n=new wt(t.departureTime,r,e,this.timetable.nbStops(),t.options.maxTransfers+1,t.options.maxDuration);return this.raptor.run(t.options,n),new yt(new Set(r),n,this.stopsIndex,this.timetable)}}class Pt{constructor(t,e){this._runs=t,this._destinations=e}get destinations(){return this._destinations}normalizeTargets(t){return t instanceof Set?new Set(t):void 0!==t?new Set([t]):new Set(this._destinations)}getRoutes(){const t=[];for(const{result:e}of this._runs){const r=e.bestRoute();void 0!==r&&t.push(r)}return t.reverse()}bestRoute(t){const e=this.normalizeTargets(t);let r,n;for(const t of this._runs)for(const s of e){const e=t.result.arrivalAt(s);void 0!==e&&((void 0===n||e.arrival<n)&&(n=e.arrival,r=t))}return null==r?void 0:r.result.bestRoute(e)}latestDepartureRoute(t){const e=this.normalizeTargets(t);for(const{result:t}of this._runs){const r=t.bestRoute(e);if(void 0!==r)return r}}fastestRoute(t){const e=this.normalizeTargets(t);let r,n=1/0;for(const t of this._runs)for(const s of e){const e=t.result.arrivalAt(s);if(void 0===e)continue;const i=e.arrival-t.departureTime;i<n&&(n=i,r=t)}return null==r?void 0:r.result.bestRoute(e)}get size(){return this._runs.length}earliestArrivalAt(t,e){let r;for(const{result:n}of this._runs){const s=n.arrivalAt(t,e);void 0!==s&&(void 0===r||s.arrival<r.arrival)&&(r=s)}return r}shortestDurationTo(t,e){let r;for(const{departureTime:n,result:s}of this._runs){const i=s.arrivalAt(t,e);if(void 0===i)continue;const o=i.arrival-n;(void 0===r||o<r.duration)&&(r=Object.assign(Object.assign({},i),{duration:o}))}return r}allShortestDurations(){const t=new Map;for(const{departureTime:e,result:r}of this._runs)for(const{stop:n,arrival:s,legNumber:i}of r.routingState.arrivals()){const r=s-e,o=t.get(n);(void 0===o||r<o.duration)&&t.set(n,{arrival:s,legNumber:i,duration:r})}return t}allEarliestArrivals(){const t=new Map;for(const{result:e}of this._runs)for(const{stop:r,arrival:n,legNumber:s}of e.routingState.arrivals()){const e=t.get(r);(void 0===e||n<e.arrival)&&t.set(r,{arrival:n,legNumber:s})}return t}[Symbol.iterator](){return this._runs[Symbol.iterator]()}}class xt{constructor(t,e,r){this._destinationBest=bt,this.latestDeparture=r,this.roundLabels=Array.from({length:t+2},(()=>new Uint16Array(e).fill(bt))),this.changedInRound=Array.from({length:t+2},(()=>[]))}setCurrentRun(t){this.currentRun=t;const e=t.graph[0];for(const r of t.origins){const t=e[r];t&&this.updateArrival(r,t.arrival,0)}}get origins(){return this.currentRun.origins}get graph(){return this.currentRun.graph}arrivalTime(t){return this.currentRun.arrivalTime(t)}improvementBound(t,e){return this.roundLabels[t][e]}get destinationBest(){return this._destinationBest}get maxArrivalTime(){return this.currentRun.maxArrivalTime}isDestination(t){return this.currentRun.isDestination(t)}updateArrival(t,e,r){const n=this.currentRun.getArrival(t);(void 0===n||e<n.arrival||e===n.arrival&&r<n.legNumber)&&this.currentRun.updateArrival(t,e,r),e<this.roundLabels[r][t]&&(this.roundLabels[r][t]=e,this.changedInRound[r].push(t),this.currentRun.isDestination(t)&&e<this._destinationBest&&(this._destinationBest=e))}initRound(t){const e=this.changedInRound[t-1];if(0===e.length)return;const r=this.roundLabels[t-1],n=this.roundLabels[t];for(let t=0;t<e.length;t++){const s=e[t];r[s]<n[s]&&(n[s]=r[s])}e.length=0}}class Lt{constructor(t,e,r,n){this.timetable=t,this.stopsIndex=e,this.accessFinder=r,this.raptor=n}rangeRoute(t){var e,r;const{departureTime:n,lastDepartureTime:s}=t,i=Array.from(t.to).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),o=0===i.length,a=this.accessFinder.collectAccessPaths(t.from,t.options.minTransferTime),u=this.accessFinder.collectDepartureTimes(a,n,s);if(0===u.length)return