minotor 11.5.1 → 11.5.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,2 +1,2 @@
1
- "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||i===n&&void 0!==r&&t.departureTime<r.departureTime)&&(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 new Pt([],new Set(i));const c=t.options.maxTransfers+1,d=new xt(c,this.timetable.nbStops(),s),l=[],h=new Map;for(const t of i)h.set(t,bt);const f=new Set(a.map((t=>t.toStopId)).filter((t=>i.includes(t)))),p=new Set;let T=null;if(t.rangeOptions.optimizeBeyondLatestDeparture&&(T=new wt(s+1,i,a,this.timetable.nbStops(),c,t.options.maxDuration),d.setCurrentRun(T),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:void 0}),d),!o))for(const t of i){const r=T.arrivalTime(t);r<(null!==(e=h.get(t))&&void 0!==e?e:bt)&&h.set(t,r)}for(const{depTime:e,legs:n}of u){if(!o&&p.size===i.length)break;null===T?T=new wt(e,i,n,this.timetable.nbStops(),c,t.options.maxDuration):T.resetFor(e,n),d.setCurrentRun(T),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:0}),d);let s=o;if(!o)for(const t of i){const e=T.arrivalTime(t);e>=(null!==(r=h.get(t))&&void 0!==r?r:bt)||(f.has(t)&&p.has(t)?h.set(t,e):(h.set(t,e),f.has(t)&&p.add(t),s=!0))}s&&(l.push({departureTime:e,result:new yt(new Set(i),T,this.stopsIndex,this.timetable)}),T=null)}return new Pt(l,new Set(i))}}class Mt{constructor(t){this.timetable=t}run(t,e){const r=new Set(e.origins);for(let n=1;n<=t.maxTransfers+1;n++){e.initRound(n);const s=e.graph[n],i=this.timetable.findReachableRoutes(r,t.transportModes);r.clear();for(const[s,o]of i)for(const i of this.scanRoute(s,o,n,e,t))r.add(i);let o=this.findTripContinuations(r,s);const a=new Set;for(;o.length>0;){a.clear();for(const t of o){const s=this.timetable.getRoute(t.routeId);for(const i of this.scanRouteContinuation(s,t.stopIndex,n,e,t))a.add(i),r.add(i)}o=this.findTripContinuations(a,s)}for(const s of this.considerTransfers(t,n,r,e))r.add(s);if(0===r.size)break}}findTripContinuations(t,e){const r=[];for(const n of t){const t=e[n];if(!t||!("routeId"in t))continue;const s=this.timetable.getContinuousTrips(t.hopOffStopIndex,t.routeId,t.tripIndex);for(const e of s)r.push({routeId:e.routeId,stopIndex:e.stopIndex,tripIndex:e.tripIndex,previousEdge:t})}return r}scanRouteContinuation(t,e,r,n,s){const i=new Set,o=n.graph[r],a=t.getNbStops(),u=t.id,c=s.tripIndex,d=t.tripStopOffset(c),l=s.previousEdge;for(let s=e;s<a;s++){const a=t.stops[s],h=t.arrivalAtOffset(s,d);t.dropOffTypeAtOffset(s,d)!==$&&h<=n.maxArrivalTime&&h<n.improvementBound(r,a)&&h<n.destinationBest&&(o[a]={routeId:u,stopIndex:e,tripIndex:c,arrival:h,hopOffStopIndex:s,continuationOf:l},n.updateArrival(a,h,r),i.add(a))}return i}scanRoute(t,e,r,n,s){const i=new Set,o=n.graph[r],a=n.graph[r-1],u=t.getNbStops(),c=t.id;let d,l=e,h=0;for(let f=e;f<u;f++){const e=t.stops[f];if(void 0!==d){const s=t.arrivalAtOffset(f,h);t.dropOffTypeAtOffset(f,h)!==$&&s<=n.maxArrivalTime&&s<n.improvementBound(r,e)&&s<n.destinationBest&&(o[e]={routeId:c,stopIndex:l,tripIndex:d,arrival:s,hopOffStopIndex:f},n.updateArrival(e,s,r),i.add(e))}const u=a[e],p=null==u?void 0:u.arrival;if(void 0!==p&&(void 0===d||p<=t.departureAtOffset(f,h))){const e=t.findEarliestTrip(f,p,d);if(void 0===e)continue;const i=u&&"routeId"in u?{stopIndex:u.hopOffStopIndex,routeId:u.routeId,tripIndex:u.tripIndex}:void 0,o=this.timetable.findFirstBoardableTrip(f,t,e,p,d,i,s.minTransferTime);if(void 0!==o){const e=t.departureFrom(f,o),i=1===r&&void 0!==s.maxInitialWaitingTime&&e-p>s.maxInitialWaitingTime,a=e>n.maxArrivalTime;i||a||(d=o,l=f,h=t.tripStopOffset(o))}}}return i}considerTransfers(t,e,r,n){const s=new Set,i=n.graph[e];for(const o of r){const r=i[o];if(!r||"type"in r)continue;const a=this.timetable.getTransfers(o);for(const u of a){let a;a=u.minTransferTime?u.minTransferTime:u.type===ct.IN_SEAT?0:t.minTransferTime;const c=r.arrival+a;c<=n.maxArrivalTime&&c<n.improvementBound(e,u.destination)&&c<n.destinationBest&&(i[u.destination]={arrival:c,from:o,to:u.destination,minTransferTime:a||void 0,type:u.type},n.updateArrival(u.destination,c,e),s.add(u.destination))}}return s}}class Ct{constructor(t=[],e=Yt){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:r}=this,n=e[t];for(;t>0;){const s=t-1>>1,i=e[s];if(r(n,i)>=0)break;e[t]=i,t=s}e[t]=n}_down(t){const{data:e,compare:r}=this,n=this.length>>1,s=e[t];for(;t<n;){let n=1+(t<<1),i=e[n];const o=n+1;if(o<this.length&&r(e[o],i)<0&&(n=o,i=e[o]),r(i,s)>=0)break;e[t]=i,t=n}e[t]=s}}function Yt(t,e){return t<e?-1:t>e?1:0}const Dt=Math.PI/180;function Ft(t,e,r,n){const s=n.minLng,i=n.maxLng,o=n.minLat,a=n.maxLat;if(t>=s&&t<=i)return e<o?kt((e-o)*Dt):e>a?kt((e-a)*Dt):0;const u=Math.min(kt((t-s)*Dt),kt((t-i)*Dt)),c=function(t,e){const r=1-2*e;return r<=0?t>0?90:-90:Math.atan(Math.tan(t*Dt)/r)/Dt}(e,u);return c>o&&c<a?$t(u,r,e,c):Math.min($t(u,r,e,o),$t(u,r,e,a))}function Bt(t,e){return t.dist-e.dist}function kt(t){const e=Math.sin(t/2);return e*e}function $t(t,e,r,n){return e*Math.cos(n*Dt)*t+kt((r-n)*Dt)}function jt(t,e,r,n,s){return $t(kt((t-r)*Dt),s,e,n)}const zt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class Gt{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,r]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const n=r>>4;if(1!==n)throw new Error(`Got v${n} data when expected v1.`);const s=zt[15&r];if(!s)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[o]=new Uint32Array(t,4,1);return new Gt(o,i,s,t)}constructor(t,e=64,r=Float64Array,n){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=r,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const s=zt.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,o=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-o%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${r}.`);n&&n instanceof ArrayBuffer?(this.data=n,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+o+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const r=this._pos>>1;return this.ids[r]=r,this.coords[this._pos++]=t,this.coords[this._pos++]=e,r}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return Vt(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,r,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:i,nodeSize:o}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,d=a.pop()||0,l=a.pop()||0;if(d-l<=o){for(let o=l;o<=d;o++){const a=i[2*o],c=i[2*o+1];a>=t&&a<=r&&c>=e&&c<=n&&u.push(s[o])}continue}const h=l+d>>1,f=i[2*h],p=i[2*h+1];f>=t&&f<=r&&p>=e&&p<=n&&u.push(s[h]),(0===c?t<=f:e<=p)&&(a.push(l),a.push(h-1),a.push(1-c)),(0===c?r>=f:n>=p)&&(a.push(h+1),a.push(d),a.push(1-c))}return u}within(t,e,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:s,nodeSize:i}=this,o=[0,n.length-1,0],a=[],u=r*r;for(;o.length;){const c=o.pop()||0,d=o.pop()||0,l=o.pop()||0;if(d-l<=i){for(let r=l;r<=d;r++)Qt(s[2*r],s[2*r+1],t,e)<=u&&a.push(n[r]);continue}const h=l+d>>1,f=s[2*h],p=s[2*h+1];Qt(f,p,t,e)<=u&&a.push(n[h]),(0===c?t-r<=f:e-r<=p)&&(o.push(l),o.push(h-1),o.push(1-c)),(0===c?t+r>=f:e+r>=p)&&(o.push(h+1),o.push(d),o.push(1-c))}return a}}function Vt(t,e,r,n,s,i){if(s-n<=r)return;const o=n+s>>1;Jt(t,e,o,n,s,i),Vt(t,e,r,n,o-1,1-i),Vt(t,e,r,o+1,s,1-i)}function Jt(t,e,r,n,s,i){for(;s>n;){if(s-n>600){const o=s-n+1,a=r-n+1,u=Math.log(o),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(o-c)/o)*(a-o/2<0?-1:1);Jt(t,e,r,Math.max(n,Math.floor(r-a*c/o+d)),Math.min(s,Math.floor(r+(o-a)*c/o+d)),i)}const o=e[2*r+i];let a=n,u=s;for(Wt(t,e,n,r),e[2*s+i]>o&&Wt(t,e,n,s);a<u;){for(Wt(t,e,a,u),a++,u--;e[2*a+i]<o;)a++;for(;e[2*u+i]>o;)u--}e[2*n+i]===o?Wt(t,e,n,u):(u++,Wt(t,e,u,s)),u<=r&&(n=u+1),r<=u&&(s=u-1)}}function Wt(t,e,r,n){Zt(t,r,n),Zt(e,2*r,2*n),Zt(e,2*r+1,2*n+1)}function Zt(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function Qt(t,e,r,n){const s=t-r,i=e-n;return s*s+i*i}const qt="KEYS",Xt="VALUES";class Ht{set;_type;_path;constructor(t,e){const r=t._tree,n=Array.from(r.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:r,keys:n}]:[]}next(){const t=this.dive();return this.backtrack(),t}dive(){if(0===this._path.length)return{done:!0,value:void 0};const{node:t,keys:e}=Kt(this._path);if(""===Kt(e))return{done:!1,value:this.result()};const r=t.get(Kt(e));return this._path.push({node:r,keys:Array.from(r.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Kt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Kt(t))).filter((t=>""!==t)).join("")}value(){return Kt(this._path).node.get("")}result(){switch(this._type){case Xt:return this.value();case qt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Kt=t=>t[t.length-1],te=(t,e,r,n,s,i,o,a)=>{const u=i*o;t:for(const c of t.keys())if(""===c){const e=s[u-1];e<=r&&n.set(a,[t.get(c),e])}else{let u=i;for(let t=0;t<c.length;++t,++u){const n=c[t],i=o*u,a=i-o;let d=s[i];const l=Math.max(0,u-r-1),h=Math.min(o-1,u+r);for(let t=l;t<h;++t){const r=n!==e[t],o=s[a+t]+ +r,u=s[a+t+1]+1,c=s[i+t]+1,l=s[i+t+1]=Math.min(o,u,c);l<d&&(d=l)}if(d>r)continue t}te(t.get(c),e,r,n,s,u,o,a+c)}};class ee{_tree;_prefix;_size=void 0;constructor(t=new Map,e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,r]=re(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,n]=ue(r);for(const r of e.keys())if(""!==r&&r.startsWith(n)){const s=new Map;return s.set(r.slice(n.length),e.get(r)),new ee(s,t)}}return new ee(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,ie(this._tree,t)}entries(){return new Ht(this,"ENTRIES")}forEach(t){for(const[e,r]of this)t(e,r,this)}fuzzyGet(t,e){return((t,e,r)=>{const n=new Map;if("string"!=typeof e)return n;const s=e.length+1,i=s+r,o=new Uint8Array(i*s).fill(r+1);for(let t=0;t<s;++t)o[t]=t;for(let t=1;t<i;++t)o[t*s]=t;return te(t,e,r,n,o,1,s,""),n})(this._tree,t,e)}get(t){const e=ne(this._tree,t);return void 0!==e?e.get(""):void 0}has(t){return ne(this._tree,t)?.has("")??!1}keys(){return new Ht(this,qt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,se(this._tree,t).set("",e),this}get size(){if(this._size)return this._size;this._size=0;const t=this.entries();for(;!t.next().done;)this._size+=1;return this._size}update(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const r=se(this._tree,t);return r.set("",e(r.get(""))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const r=se(this._tree,t);let n=r.get("");return void 0===n&&r.set("",n=e()),n}values(){return new Ht(this,Xt)}[Symbol.iterator](){return this.entries()}static from(t){const e=new ee;for(const[r,n]of t)e.set(r,n);return e}static fromObject(t){return ee.from(Object.entries(t))}}const re=(t,e,r=[])=>{if(0===e.length||null==t)return[t,r];for(const n of t.keys())if(""!==n&&e.startsWith(n))return r.push([t,n]),re(t.get(n),e.slice(n.length),r);return r.push([t,e]),re(void 0,"",r)},ne=(t,e)=>{if(0===e.length||!t)return t;for(const r of t.keys())if(""!==r&&e.startsWith(r))return ne(t.get(r),e.slice(r.length))},se=(t,e)=>{const r=e.length;t:for(let n=0;t&&n<r;){for(const s of t.keys())if(""!==s&&e[n]===s[0]){const i=Math.min(r-n,s.length);let o=1;for(;o<i&&e[n+o]===s[o];)++o;const a=t.get(s);if(o===s.length)t=a;else{const r=new Map;r.set(s.slice(o),a),t.set(e.slice(n,n+o),r),t.delete(s),t=r}n+=o;continue t}const s=new Map;return t.set(e.slice(n),s),s}return t},ie=(t,e)=>{const[r,n]=re(t,e);if(void 0!==r)if(r.delete(""),0===r.size)oe(n);else if(1===r.size){const[t,e]=r.entries().next().value;ae(n,t,e)}},oe=t=>{if(0===t.length)return;const[e,r]=ue(t);if(e.delete(r),0===e.size)oe(t.slice(0,-1));else if(1===e.size){const[r,n]=e.entries().next().value;""!==r&&ae(t.slice(0,-1),r,n)}},ae=(t,e,r)=>{if(0===t.length)return;const[n,s]=ue(t);n.set(s+e,r),n.delete(s)},ue=t=>t[t.length-1],ce=/[\n\r\p{Z}\p{P}]+/u,de="or",le="and",he="and_not",fe=(t,e)=>{t.includes(e)||t.push(e)},pe=(t,e)=>{for(const r of e)t.includes(r)||t.push(r)},Te=({score:t},{score:e})=>e-t,Ee=()=>new Map,me=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Ie={[de]:(t,e)=>{for(const r of e.keys()){const n=t.get(r);if(null==n)t.set(r,e.get(r));else{const{score:t,terms:s,match:i}=e.get(r);n.score=n.score+t,n.match=Object.assign(n.match,i),pe(n.terms,s)}}return t},[le]:(t,e)=>{const r=new Map;for(const n of e.keys()){const s=t.get(n);if(null==s)continue;const{score:i,terms:o,match:a}=e.get(n);pe(s.terms,o),r.set(n,{score:s.score+i,terms:s.terms,match:Object.assign(s.match,a)})}return r},[he]:(t,e)=>{for(const r of e.keys())t.delete(r);return t}},_e=(t,e,r,n,s,i)=>{const{k:o,b:a,d:u}=i;return Math.log(1+(r-e+.5)/(e+.5))*(u+t*(o+1)/(t+o*(1-a+a*n/s)))},ge=(t,e,r,n)=>{for(const s of Object.keys(t._fieldIds))if(t._fieldIds[s]===r)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${n}" was not present in field "${s}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},Re=(t,e,r,n)=>{const s=t._index.fetch(n,Ee);let i=s.get(e);if(null==i)i=new Map,i.set(r,1),s.set(e,i);else{const t=i.get(r);i.set(r,(t??0)+1)}},Ae=(t,e,r,n)=>{if(!t._index.has(n))return void ge(t,r,e,n);const s=t._index.fetch(n,Ee),i=s.get(e),o=i?.get(r);!i||typeof o>"u"?ge(t,r,e,n):o<=1?i.size<=1?s.delete(e):i.delete(r):i.set(r,o-1),0===t._index.get(n).size&&t._index.delete(n)},ve=(t,e,r,n,s)=>{let i=t._fieldLength.get(e);null==i&&t._fieldLength.set(e,i=[]),i[r]=s;const o=(t._avgFieldLength[r]||0)*n+s;t._avgFieldLength[r]=o/(n+1)},Oe=(t,e)=>{const{extractField:r,stringifyField:n,tokenize:s,processTerm:i,fields:o,idField:a}=t._options,u=r(e,a);if(null==u)throw new Error(`SlimSearch: document does not have ID field "${a}"`);if(((t,e)=>t._idToShortId.has(e))(t,u))throw new Error(`SlimSearch: duplicate ID ${u}`);const c=((t,e)=>{const r=t._nextId;return t._idToShortId.set(e,r),t._documentIds.set(r,e),t._documentCount+=1,t._nextId+=1,r})(t,u);((t,e,r)=>{const{storeFields:n,extractField:s}=t._options;if(0===n?.length)return;let i=t._storedFields.get(e);void 0===i&&t._storedFields.set(e,i={});for(const t of n){const e=s(r,t);null!=e&&(i[t]=e)}})(t,c,e);for(const a of o){const o=r(e,a);if(null==o)continue;const u=s(n(o,a),a),d=t._fieldIds[a],l=new Set(u).size;ve(t,c,d,t._documentCount-1,l);for(const e of u){const r=i(e,a);if(Array.isArray(r))for(const e of r)Re(t,d,c,e);else r&&Re(t,d,c,r)}}},Se={idField:"id",extractField:(t,e)=>t[e],stringifyField:t=>t.toString(),tokenize:t=>t.split(ce),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},ye={combineWith:de,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},Ne={combineWith:"and",prefix:(t,e,r)=>e===r.length-1},be={minDirtFactor:.1,minDirtCount:20},we={batchSize:1e3,batchWait:10,...be},Ue=Symbol("*"),Pe=(t,e=de)=>{if(0===t.length)return new Map;const r=e.toLowerCase();if(!(r in Ie))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Ie[r])},xe=(t,e,r,n,s,i,o,a,u,c=new Map)=>{if(null==i)return c;for(const d of Object.keys(o)){const l=o[d],h=t._fieldIds[d],f=i.get(h);if(null==f)continue;let p=f.size;const T=t._avgFieldLength[h];for(const i of f.keys()){if(!t._documentIds.has(i)){Ae(t,h,i,r),p-=1;continue}const o=a?a(t._documentIds.get(i),r,t._storedFields.get(i)):1;if(!o)continue;const E=f.get(i),m=t._fieldLength.get(i)[h],I=n*s*l*o*_e(E,p,t._documentCount,m,T,u),_=c.get(i);if(_){_.score+=I,fe(_.terms,e);const t=me(_.match,r);t?t.push(d):_.match[r]=[d]}else c.set(i,{score:I,terms:[e],match:{[r]:[d]}})}}return c},Le=(t,e,r={})=>{if(e===Ue)return((t,e)=>{const r=new Map,n={...t._options.searchOptions,...e};for(const[e,s]of t._documentIds){const i=n.boostDocument?n.boostDocument(s,"",t._storedFields.get(e)):1;r.set(e,{score:i,terms:[],match:{}})}return r})(t,r);if("string"!=typeof e){const n={...r,...e,queries:void 0},s=e.queries.map((e=>Le(t,e,n)));return Pe(s,n.combineWith)}const{tokenize:n,processTerm:s,searchOptions:i}=t._options,o={tokenize:n,processTerm:s,...i,...r},{tokenize:a,processTerm:u}=o,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,r,n)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,r,n):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,r,n):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,r,n):1}))(o)).map((e=>((t,e,r)=>{const n={...t._options.searchOptions,...r},s=(n.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:me(n.boost,e)||1})),{}),{boostDocument:i,weights:o,maxFuzzy:a,bm25:u}=n,{fuzzy:c,prefix:d}={...ye.weights,...o},l=t._index.get(e.term),h=xe(t,e.term,e.term,1,e.termBoost,l,s,i,u);let f,p;if(e.prefix&&(f=t._index.atPrefix(e.term)),e.fuzzy){const r=!0===e.fuzzy?.2:e.fuzzy,n=r<1?Math.min(a,Math.round(e.term.length*r)):r;n&&(p=t._index.fuzzyGet(e.term,n))}if(f)for(const[r,n]of f){const o=r.length-e.term.length;if(!o)continue;p?.delete(r);const a=d*r.length/(r.length+.3*o);xe(t,e.term,r,a,e.termBoost,n,s,i,u,h)}if(p)for(const r of p.keys()){const[n,o]=p.get(r);if(!o)continue;const a=c*r.length/(r.length+o);xe(t,e.term,r,a,e.termBoost,n,s,i,u,h)}return h})(t,e,o)));return Pe(c,o.combineWith)};class Me{_options;_index;_documentCount;_documentIds;_idToShortId;_fieldIds;_fieldLength;_avgFieldLength;_nextId;_storedFields;_dirtCount;_currentVacuum;_enqueuedVacuum;_enqueuedVacuumConditions;constructor(t){if(!t?.fields)throw new Error('SlimSearch: option "fields" must be provided');const e=null==t.autoVacuum||!0===t.autoVacuum?we:t.autoVacuum;this._options={...Se,...t,autoVacuum:e,searchOptions:{...ye,...t.searchOptions},autoSuggestOptions:{...Ne,...t.autoSuggestOptions}},this._index=new ee,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=be,this.addFields(this._options.fields)}get isVacuuming(){return null!=this._currentVacuum}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}get documentCount(){return this._documentCount}get termCount(){return this._index.size}toJSON(){const t=[];for(const[e,r]of this._index){const n={};for(const[t,e]of r)n[t]=Object.fromEntries(e);t.push([e,n])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:t,version:2}}addFields(t){for(let e=0;e<t.length;e++)this._fieldIds[t[e]]=e}}const Ce=t=>{const e=t.toLowerCase(),r=new Set([e]),n={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,s]of Object.entries(n))e.includes(t)&&s.forEach((n=>{r.add(e.replace(t,n))})),s.forEach((n=>{e.includes(n)&&r.add(e.replace(n,t))}));return Array.from(r)};var Ye;function De(t){switch(t){case 0:case"LOCATION_TYPE_UNSPECIFIED":return Ye.LOCATION_TYPE_UNSPECIFIED;case 1:case"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM":return Ye.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case 2:case"LOCATION_TYPE_STATION":return Ye.LOCATION_TYPE_STATION;case 3:case"LOCATION_TYPE_ENTRANCE_EXIT":return Ye.LOCATION_TYPE_ENTRANCE_EXIT;case 4:case"LOCATION_TYPE_GENERIC_NODE":return Ye.LOCATION_TYPE_GENERIC_NODE;case 5:case"LOCATION_TYPE_BOARDING_AREA":return Ye.LOCATION_TYPE_BOARDING_AREA;default:return Ye.UNRECOGNIZED}}!function(t){t[t.LOCATION_TYPE_UNSPECIFIED=0]="LOCATION_TYPE_UNSPECIFIED",t[t.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM=1]="LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM",t[t.LOCATION_TYPE_STATION=2]="LOCATION_TYPE_STATION",t[t.LOCATION_TYPE_ENTRANCE_EXIT=3]="LOCATION_TYPE_ENTRANCE_EXIT",t[t.LOCATION_TYPE_GENERIC_NODE=4]="LOCATION_TYPE_GENERIC_NODE",t[t.LOCATION_TYPE_BOARDING_AREA=5]="LOCATION_TYPE_BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ye||(Ye={}));const Fe={encode(t,e=new R){""!==t.name&&e.uint32(10).string(t.name),void 0!==t.sourceStopId&&e.uint32(18).string(t.sourceStopId),void 0!==t.lat&&e.uint32(29).float(t.lat),void 0!==t.lon&&e.uint32(37).float(t.lon),e.uint32(42).fork();for(const r of t.children)e.uint32(r);return e.join(),void 0!==t.parent&&e.uint32(48).uint32(t.parent),0!==t.locationType&&e.uint32(56).int32(t.locationType),void 0!==t.platform&&e.uint32(66).string(t.platform),e},decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={name:"",sourceStopId:void 0,lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.name=r.string();continue;case 2:if(18!==t)break;s.sourceStopId=r.string();continue;case 3:if(29!==t)break;s.lat=r.float();continue;case 4:if(37!==t)break;s.lon=r.float();continue;case 5:if(40===t){s.children.push(r.uint32());continue}if(42===t){const t=r.uint32()+r.pos;for(;r.pos<t;)s.children.push(r.uint32());continue}break;case 6:if(48!==t)break;s.parent=r.uint32();continue;case 7:if(56!==t)break;s.locationType=r.int32();continue;case 8:if(66!==t)break;s.platform=r.string();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({name:ke(t.name)?globalThis.String(t.name):"",sourceStopId:ke(t.sourceStopId)?globalThis.String(t.sourceStopId):void 0,lat:ke(t.lat)?globalThis.Number(t.lat):void 0,lon:ke(t.lon)?globalThis.Number(t.lon):void 0,children:globalThis.Array.isArray(null==t?void 0:t.children)?t.children.map((t=>globalThis.Number(t))):[],parent:ke(t.parent)?globalThis.Number(t.parent):void 0,locationType:ke(t.locationType)?De(t.locationType):0,platform:ke(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const r={};return""!==t.name&&(r.name=t.name),void 0!==t.sourceStopId&&(r.sourceStopId=t.sourceStopId),void 0!==t.lat&&(r.lat=t.lat),void 0!==t.lon&&(r.lon=t.lon),(null===(e=t.children)||void 0===e?void 0:e.length)&&(r.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(r.parent=Math.round(t.parent)),0!==t.locationType&&(r.locationType=function(t){switch(t){case Ye.LOCATION_TYPE_UNSPECIFIED:return"LOCATION_TYPE_UNSPECIFIED";case Ye.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM";case Ye.LOCATION_TYPE_STATION:return"LOCATION_TYPE_STATION";case Ye.LOCATION_TYPE_ENTRANCE_EXIT:return"LOCATION_TYPE_ENTRANCE_EXIT";case Ye.LOCATION_TYPE_GENERIC_NODE:return"LOCATION_TYPE_GENERIC_NODE";case Ye.LOCATION_TYPE_BOARDING_AREA:return"LOCATION_TYPE_BOARDING_AREA";case Ye.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(r.platform=t.platform),r},create:t=>Fe.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s,i,o,a,u;const c={name:"",sourceStopId:void 0,lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};return c.name=null!==(e=t.name)&&void 0!==e?e:"",c.sourceStopId=null!==(r=t.sourceStopId)&&void 0!==r?r:void 0,c.lat=null!==(n=t.lat)&&void 0!==n?n:void 0,c.lon=null!==(s=t.lon)&&void 0!==s?s:void 0,c.children=(null===(i=t.children)||void 0===i?void 0:i.map((t=>t)))||[],c.parent=null!==(o=t.parent)&&void 0!==o?o:void 0,c.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,c.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,c}};const Be={encode(t,e=new R){for(const r of t.stops)Fe.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={stops:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 2:if(18!==t)break;s.stops.push(Fe.decode(r,r.uint32()));continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>Fe.fromJSON(t))):[]}),toJSON(t){var e;const r={};return(null===(e=t.stops)||void 0===e?void 0:e.length)&&(r.stops=t.stops.map((t=>Fe.toJSON(t)))),r},create:t=>Be.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={stops:[]};return r.stops=(null===(e=t.stops)||void 0===e?void 0:e.map((t=>Fe.fromPartial(t))))||[],r}};function ke(t){return null!=t}const $e=t=>({stops:t.map((t=>{return{name:(e=t).name,sourceStopId:e.sourceStopId,lat:e.lat,lon:e.lon,children:e.children,parent:e.parent,locationType:Ge(e.locationType),platform:e.platform};var e}))}),je=t=>t.stops.map(((t,e)=>{return{id:e,sourceStopId:(r=t).sourceStopId,name:r.name,lat:r.lat,lon:r.lon,children:r.children,parent:r.parent,locationType:ze(r.locationType),platform:r.platform};var r})),ze=t=>{switch(t){case Ye.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Ye.LOCATION_TYPE_STATION:return"STATION";case Ye.LOCATION_TYPE_ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Ye.LOCATION_TYPE_GENERIC_NODE:return"GENERIC_NODE";case Ye.LOCATION_TYPE_BOARDING_AREA:return"BOARDING_AREA";case Ye.LOCATION_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf location type.");case Ye.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},Ge=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return Ye.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case"STATION":return Ye.LOCATION_TYPE_STATION;case"ENTRANCE_EXIT":return Ye.LOCATION_TYPE_ENTRANCE_EXIT;case"GENERIC_NODE":return Ye.LOCATION_TYPE_GENERIC_NODE;case"BOARDING_AREA":return Ye.LOCATION_TYPE_BOARDING_AREA}};class Ve{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const r=new Map;this.stopPoints=[];for(let n=0;n<t.length;n++){const s=t[n];void 0!==s.sourceStopId&&this.sourceStopsMap.set(s.sourceStopId,n);const i=null!==(e=s.parent)&&void 0!==e?e:n;r.has(i)||r.set(i,{id:i,name:s.parent?this.stops[s.parent].name:s.name}),s.lat&&s.lon&&this.stopPoints.push({id:n,lat:s.lat,lon:s.lon})}this.textIndex=new Me({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:Ce});const n=Array.from(r.values());((t,e)=>{for(const r of e)Oe(t,r)})(this.textIndex,n),this.geoIndex=new Gt(this.stopPoints.length);for(let t=0;t<this.stopPoints.length;t++){const{lat:e,lon:r}=this.stopPoints[t];this.geoIndex.add(r,e)}this.geoIndex.finish()}static fromData(t){const e=new A(t),r=Be.decode(e);return new Ve(je(r))}serialize(){const t=$e(this.stops),e=new R;return Be.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){return((t,e,r={})=>{const{searchOptions:n}=t._options,s={...n,...r},i=Le(t,e,r),o=[];for(const[e,{score:r,terms:n,match:a}]of i){const i=n.length||1,u={id:t._documentIds.get(e),score:r*i,terms:Object.keys(a),queryTerms:n,match:a};Object.assign(u,t._storedFields.get(e)),(null==s.filter||s.filter(u))&&o.push(u)}return e===Ue&&null==s.boostDocument||o.sort(Te),o})(this.textIndex,t).map((t=>this.stops[t.id])).slice(0,e)}findStopsByLocation(t,e,r=5,n=.5){const s=function(t,e,r,n=1/0,s=1/0){let i=1;const o=[];void 0===n&&(n=1/0),void 0!==s&&(i=kt(s/6371));const a=new Ct([],Bt);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(r*Dt);for(;u;){const s=u.right,d=u.left;if(s-d<=t.nodeSize)for(let n=d;n<=s;n++){const s=t.ids[n];{const i=jt(e,r,t.coords[2*n],t.coords[2*n+1],c);a.push({id:s,dist:i})}}else{const n=d+s>>1,i=t.coords[2*n],o=t.coords[2*n+1],l=t.ids[n];{const t=jt(e,r,i,o,c);a.push({id:l,dist:t})}const h=(u.axis+1)%2,f={left:d,right:n-1,axis:h,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?i:u.maxLng,maxLat:1===u.axis?o:u.maxLat,dist:0},p={left:n+1,right:s,axis:h,minLng:0===u.axis?i:u.minLng,minLat:1===u.axis?o:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};f.dist=Ft(e,r,c,f),p.dist=Ft(e,r,c,p),a.push(f),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>i)return o;if(o.push(t.id),o.length===n)return o}u=a.pop()}return o}(this.geoIndex,e,t,r,n).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return s}findStopById(t){return this.stops[t]}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,r;const n=this.stops[t];if(!n)return[];const s=n.parent?null!==(r=null===(e=this.stops[n.parent])||void 0===e?void 0:e.children)&&void 0!==r?r:[]:n.children;return Array.from(new Set([t,...s])).map((t=>this.stops[t]))}*[Symbol.iterator](){for(const t of this.stops)yield t}}exports.Plotter=class{constructor(t){this.result=t}stationNodeId(t){return`s_${t}`}vehicleEdgeNodeId(t,e,r,n){return`e_${t}_${e}_${r}_${n}`}transferEdgeNodeId(t,e,r){return`e_${t}_${e}_${r}`}accessEdgeNodeId(t,e){return`access_${t}_${e}`}continuationNodeId(t,e,r){return`continuation_${t}_${e}_${r}`}getRoundColor(t){var e;if(0===t)return Et.colors.defaultRound;const r=Math.min(t-1,Et.colors.rounds.length-1);return null!==(e=Et.colors.rounds[r])&&void 0!==e?e:"#ee82ee"}getStationFillColor(t,e){return t?Et.colors.originStation:e?Et.colors.destinationStation:Et.colors.defaultStation}escapeDotString(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}formatStopName(t){const e=this.result.stopsIndex.findStopById(t);if(!e)return`Unknown Stop (${t})`;const r=this.escapeDotString(e.name),n=e.platform?this.escapeDotString(e.platform):"";return n?`${r}\\nPl. ${n}`:r}getStationInfo(t){var e;return{isOrigin:void 0!==(null===(e=this.result.routingState.graph[0])||void 0===e?void 0:e[t]),isDestination:this.result.routingState.destinations.includes(t)}}getVehicleEdgeFromStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.stopIndex)}getVehicleEdgeToStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.hopOffStopIndex)}createStationNode(t){if(!this.result.stopsIndex.findStopById(t))return null;const e=this.formatStopName(t),r=this.escapeDotString(String(t)),n=this.stationNodeId(t),s=this.getStationInfo(t);return` "${n}" [label="${e}\\n${r}" shape=box style=filled fillcolor="${this.getStationFillColor(s.isOrigin,s.isDestination)}"];`}createVehicleEdge(e,r){const n=this.result.timetable.getRoute(e.routeId);if(!n)return[];const s=n.stopId(e.stopIndex),i=n.stopId(e.hopOffStopIndex),o=this.stationNodeId(s),a=this.stationNodeId(i),u=this.getRoundColor(r),c=this.vehicleEdgeNodeId(s,i,e.routeId,r),d=this.result.timetable.getServiceRouteInfo(n),l=d.name,h=pt(d.type),f=t(n.departureFrom(e.stopIndex,e.tripIndex)),p=t(e.arrival),T=this.escapeDotString(l);return[` "${c}" [label="${`${this.escapeDotString(h)} ${T}\\n${`${e.routeId}:${e.tripIndex}`}\\n${f} → ${p}`}" shape=oval style=filled fillcolor="white" color="${u}"];`,` "${o}" -> "${c}" [color="${u}"];`,` "${c}" -> "${a}" [color="${u}"];`]}createAccessEdge(t){const r=this.stationNodeId(t.from),n=this.stationNodeId(t.to),s=Et.colors.defaultRound,i=this.accessEdgeNodeId(t.from,t.to);return[` "${i}" [label="${`Walk\\n${e(t.duration)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${s}"];`,` "${r}" -> "${i}" [color="${s}" style="dashed"];`,` "${i}" -> "${n}" [color="${s}" style="dashed"];`]}createTransferEdge(t,r){const n=this.stationNodeId(t.from),s=this.stationNodeId(t.to),i=this.getRoundColor(r),o=this.transferEdgeNodeId(t.from,t.to,r),a=void 0!==t.minTransferTime?e(t.minTransferTime):"N/A";return[` "${o}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${i}"];`,` "${n}" -> "${o}" [color="${i}" style="dashed"];`,` "${o}" -> "${s}" [color="${i}" style="dashed"];`]}createContinuationEdge(e,r,n){var s,i;const o=this.getVehicleEdgeToStopId(e),a=this.getVehicleEdgeFromStopId(r);if(!o||!a)return[];const u=this.stationNodeId(o),c=this.stationNodeId(a),d=this.getRoundColor(n),l=this.continuationNodeId(o,a,n),h=this.result.timetable.getRoute(e.routeId),f=this.result.timetable.getRoute(r.routeId),p=h?this.result.timetable.getServiceRouteInfo(h):null,T=f?this.result.timetable.getServiceRouteInfo(f):null,E=null!==(s=null==p?void 0:p.name)&&void 0!==s?s:`Route ${String(e.routeId)}`,m=null!==(i=null==T?void 0:T.name)&&void 0!==i?i:`Route ${String(r.routeId)}`,I=p?pt(p.type):"UNKNOWN",_=T?pt(T.type):"UNKNOWN",g=t(e.arrival),R=f?t(f.departureFrom(r.stopIndex,r.tripIndex)):"N/A",A=this.escapeDotString(E),v=this.escapeDotString(m),O=this.escapeDotString(I),S=this.escapeDotString(_),y=`${O} ${A} (${`${e.routeId}:${e.tripIndex}`}) ${g}\\n↓\\n${S} ${v} (${`${r.routeId}:${r.tripIndex}`}) ${R}`,{continuationFill:N}=Et.colors,{continuation:b,continuationEdge:w}=Et.penWidth;return[` "${l}" [label="${y}" shape=oval style="filled,bold" fillcolor="${N}" color="${d}" penwidth="${b}"];`,` "${u}" -> "${l}" [color="${d}" style="bold" penwidth="${w}"];`,` "${l}" -> "${c}" [color="${d}" style="bold" penwidth="${w}"];`]}collectStations(){const t=new Set,e=this.result.routingState.graph;for(const r of e)for(let e=0;e<r.length;e++){const n=r[e];if(void 0!==n)if(t.add(e),mt(n)){const e=this.getVehicleEdgeFromStopId(n),r=this.getVehicleEdgeToStopId(n);e&&t.add(e),r&&t.add(r)}else _t(n)&&(t.add(n.from),t.add(n.to))}return t}collectContinuationChain(t,e){const r=[];let n=t,s=t.continuationOf;for(;s;){const t=this.createContinuationEdge(s,n,e);r.push(...t),n=s,s=s.continuationOf}return r}collectEdges(){const t=[],e=[],r=this.result.routingState.graph;for(let n=0;n<r.length;n++){const s=r[n];if(s)for(let r=0;r<s.length;r++){const i=s[r];void 0!==i&&(0!==n?mt(i)?(t.push(...this.createVehicleEdge(i,n)),i.continuationOf&&e.push(...this.collectContinuationChain(i,n))):It(i)&&t.push(...this.createTransferEdge(i,n)):_t(i)&&t.push(...this.createAccessEdge(i)))}}return[...t,...e]}plotDotGraph(){const t=this.collectStations(),e=this.collectEdges(),r=new gt;r.addHeader(),r.addComment("Stations");for(const e of t){const t=this.createStationNode(e);t&&r.addRaw([t])}return r.addComment("Edges"),r.addRaw(e),r.build()}},exports.Query=Rt,exports.RangeQuery=At,exports.RangeResult=Pt,exports.Result=yt,exports.Route=vt,exports.Router=class{constructor(t,e){const r=new Mt(t),n=new Nt(t,e);this.plainRouter=new Ut(t,e,n,r),this.rangeRouter=new Lt(t,e,n,r)}route(t){return this.plainRouter.route(t)}rangeRoute(t){return this.rangeRouter.rangeRoute(t)}},exports.StopsIndex=Ve,exports.Timetable=ft;
1
+ "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(){const t=this.buf;let e=this.pos,r=0,i=0;for(let n=0;n<28;n+=7){const o=t[e++];if(r|=(127&o)<<n,!(128&o))return this.pos=e,this.assertBounds(),this.varint64Lo=r,void(this.varint64Hi=i)}const n=t[e++];if(r|=(15&n)<<28,i=(112&n)>>4,!(128&n))return this.pos=e,this.assertBounds(),this.varint64Lo=r,void(this.varint64Hi=i);for(let n=3;n<=31;n+=7){const o=t[e++];if(i|=(127&o)<<n,!(128&o))return this.pos=e,this.assertBounds(),this.varint64Lo=r,void(this.varint64Hi=i)}throw new Error("invalid varint")}const i=4294967296;function n(t){const e="-"===t[0];e&&(t=t.slice(1));const r=1e6;let n=0,o=0;function u(e,s){const a=Number(t.slice(e,s));o*=r,n=n*r+a,n>=i&&(o+=n/i|0,n%=i)}return u(-24,-18),u(-18,-12),u(-12,-6),u(-6),e?a(n,o):s(n,o)}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(i*e+t);const r=16777215&(t>>>24|e<<8),n=e>>16&65535;let o=(16777215&t)+6777216*r+6710656*n,s=r+8147497*n,a=2*n;const d=1e7;return o>=d&&(s+=Math.floor(o/d),o%=d),s>=d&&(a+=Math.floor(s/d),s%=d),a.toString()+u(s)+u(o)}function s(t,e){return{lo:0|t,hi:0|e}}function a(t,e){return e=~e,t?t=1+~t:e+=1,s(t,e)}const u=t=>{const e=String(t);return"0000000".slice(e.length)+e};function d(){let t=this.buf[this.pos++];if(!(128&t))return this.assertBounds(),t;let e=127&t;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 c=l();function l(){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&&!globalThis.Bun&&"object"==typeof process&&"object"==typeof process.env&&"1"===process.env.BUF_BIGINT_DISABLE)){const e=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),i=BigInt("0"),n=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const i="bigint"==typeof t?t:BigInt(t);if(i>r||i<e)throw new Error(`invalid int64: ${t}`);return i},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>n||e<i)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()),h(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),h(t),n(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),p(t),n(t)),dec:(t,e)=>function(t,e){let r=s(t,e);const i=2147483648&r.hi;i&&(r=a(r.lo,r.hi));const n=o(r.lo,r.hi);return i?"-"+n:n}(t,e),uDec:(t,e)=>o(t,e)}}function h(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function p(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}let f;function T(){if(!f){const r=globalThis;if(!r.TextEncoder||!r.TextDecoder)throw new Error("encoding API missing: install TextEncoder and TextDecoder on globalThis");const i=new r.TextEncoder,n=new r.TextDecoder;let o;const s={encodeUtf8:t=>i.encode(t),decodeUtf8:(t,e)=>e?(o||(o=new r.TextDecoder("utf-8",{fatal:!0})),o.decode(t)):n.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}};i.encodeInto&&(s.encodeUtf8Into=i.encodeInto.bind(i));const a=String.prototype.isWellFormed;a&&(s.checkUtf8=t=>a.call(t)),t=s,f=Object.assign(Object.assign({},t),{encodeUtf8Into:null!==(e=t.encodeUtf8Into)&&void 0!==e?e:_(t.encodeUtf8.bind(t))})}var t,e;return f}function _(t){return(e,r)=>{const i=t(e);return r.set(i),{written:i.byteLength}}}var E;!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"}(E||(E={}));class m{constructor(t){this.stackPos=[],this.encodeUtf8Into=t?_(t):T().encodeUtf8Into,this.buffer=v,this.viewCache=R,this.pos=0}ensureCapacity(t){const e=this.pos+t;if(e>this.buffer.length){let t=this.buffer.length||I;for(;t<e;)t*=2;const r=new Uint8Array(t);this.pos>0&&r.set(this.buffer),this.buffer=r}}view(){const t=this.buffer,e=this.viewCache;if(e.byteLength===t.byteLength)return e;const r=new DataView(t.buffer);return this.viewCache=r,r}finish(){const t=this.buffer.slice(0,this.pos);return this.pos=0,this.stackPos=[],t}fork(){return this.stackPos.push(this.pos),this.ensureCapacity(g),this.buffer[this.pos++]=0,this}join(){const t=this.stackPos.pop();if(void 0===t)throw new Error("invalid state, fork stack empty");const e=this.pos-t-g,r=y(e);return r>g&&(this.ensureCapacity(r-g),this.buffer.copyWithin(t+r,t+g,this.pos)),this.pos=t,this.uint32(e),this.pos+=e,this}tag(t,e){return this.uint32((t<<3|e)>>>0)}raw(t){return this.ensureCapacity(t.length),this.buffer.set(t,this.pos),this.pos+=t.length,this}uint32(t){if(N(t),this.ensureCapacity(5),t<128)return this.buffer[this.pos++]=t,this;for(;t>127;)this.buffer[this.pos++]=127&t|128,t>>>=7;return this.buffer[this.pos++]=t,this}int32(t){if(O(t),t>=0)return this.uint32(t);this.ensureCapacity(10);for(let e=0;e<9;e++)this.buffer[this.pos++]=127&t|128,t>>=7;return this.buffer[this.pos++]=1,this}bool(t){return this.ensureCapacity(1),this.buffer[this.pos++]=t?1:0,this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){"string"!=typeof t&&(t=String(t));const e=t.length;if(e<=A){this.ensureCapacity(e+1);const r=this.buffer;let i=this.pos;r[i++]=e;let n=0;for(;n<e;n++){const e=t.charCodeAt(n);if(e>127)break;r[i++]=e}if(n==e)return this.pos=i,this}this.ensureCapacity(3*e+5);const r=y(e),i=this.buffer,n=this.pos,{written:o}=this.encodeUtf8Into(t,i.subarray(n+r)),s=y(o);return s!=r&&i.copyWithin(n+s,n+r,n+r+o),this.uint32(o),this.pos+=o,this}float(t){return 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(Math.fround(t))&&Number.isFinite(t))throw new Error("invalid float32: "+t)}(t),this.ensureCapacity(4),this.view().setFloat32(this.pos,t,!0),this.pos+=4,this}double(t){return this.ensureCapacity(8),this.view().setFloat64(this.pos,t,!0),this.pos+=8,this}fixed32(t){return N(t),this.ensureCapacity(4),this.view().setUint32(this.pos,t,!0),this.pos+=4,this}sfixed32(t){return O(t),this.ensureCapacity(4),this.view().setInt32(this.pos,t,!0),this.pos+=4,this}sint32(t){return O(t),this.uint32((t<<1^t>>31)>>>0)}sfixed64(t){const e=c.enc(t);this.ensureCapacity(8);const r=this.view();return r.setInt32(this.pos,e.lo,!0),r.setInt32(this.pos+4,e.hi,!0),this.pos+=8,this}fixed64(t){const e=c.uEnc(t);this.ensureCapacity(8);const r=this.view();return r.setInt32(this.pos,e.lo,!0),r.setInt32(this.pos+4,e.hi,!0),this.pos+=8,this}int64(t){const e=c.enc(t);return this.writeVarint64(e.lo,e.hi)}sint64(t){const e=c.enc(t),r=e.hi>>31,i=e.lo<<1^r,n=(e.hi<<1|e.lo>>>31)^r;return this.writeVarint64(i,n)}uint64(t){const e=c.uEnc(t);return this.writeVarint64(e.lo,e.hi)}writeVarint64(t,e){this.ensureCapacity(10);const r=this.buffer;let i=this.pos;for(let n=0;n<28;n+=7){const o=t>>>n,s=!(o>>>7==0&&0==e);if(r[i++]=255&(s?128|o:o),!s)return this.pos=i,this}const n=t>>>28&15|(7&e)<<4,o=!!(e>>3);if(r[i++]=255&(o?128|n:n),!o)return this.pos=i,this;for(let t=3;t<31;t+=7){const n=e>>>t,o=!(n>>>7==0);if(r[i++]=255&(o?128|n:n),!o)return this.pos=i,this}return r[i++]=e>>>31&1,this.pos=i,this}}const I=128,g=1,v=new Uint8Array(0),R=new DataView(v.buffer),A=32;function y(t){return t<128?1:t<16384?2:t<2097152?3:t<268435456?4:5}class S{constructor(t,e=T().decodeUtf8){this.decodeUtf8=e,this.varint64Lo=0,this.varint64Hi=0,this.varint64=r,this.uint32=d,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){const t=this.pos,e=this.uint32(),r=this.pos-t;if(r>5||5==r&&this.buf[this.pos-1]>15)throw new Error("illegal tag: varint overflows uint32");const i=e>>>3,n=7&e;if(i<=0||n>5)throw new Error("illegal tag: field no "+i+" wire type "+n);return[i,n]}skip(t,e,r=100){let i=this.pos;switch(t){case E.Varint:for(;128&this.buf[this.pos++];);break;case E.Bit64:this.pos+=4;case E.Bit32:this.pos+=4;break;case E.LengthDelimited:let i=this.uint32();this.pos+=i;break;case E.StartGroup:if(r<=0)throw new Error("maximum recursion depth reached");for(;;){const[t,i]=this.tag();if(i===E.EndGroup){if(void 0!==e&&t!==e)throw new Error("invalid end group tag");break}this.skip(i,t,r-1)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(i,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 this.varint64(),c.dec(this.varint64Lo,this.varint64Hi)}uint64(){return this.varint64(),c.uDec(this.varint64Lo,this.varint64Hi)}sint64(){this.varint64();let t=this.varint64Lo,e=this.varint64Hi,r=-(1&t);return t=(t>>>1|(1&e)<<31)^r,e=e>>>1^r,c.dec(t,e)}bool(){const t=this.buf[this.pos];return t<128?(this.pos++,0!==t):(this.varint64(),0!==this.varint64Lo||0!==this.varint64Hi)}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return c.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return c.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(t){const e=this.bytes(),r=e.length;if(r<=A){const i=new Array(r);for(let n=0;n<r;n++){const r=e[n];if(r>127)return this.decodeUtf8(e,t);i[n]=r}return String.fromCharCode.apply(String,i)}return this.decodeUtf8(e,t)}}function O(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 N(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 b,w;function P(t){switch(t){case 0:case"TRANSFER_TYPE_UNSPECIFIED":return b.TRANSFER_TYPE_UNSPECIFIED;case 1:case"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT":return b.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case 2:case"TRANSFER_TYPE_TIMED_TRANSFER":return b.TRANSFER_TYPE_TIMED_TRANSFER;case 3:case"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME":return b.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case 4:case"TRANSFER_TYPE_IN_SEAT_TRANSFER":return b.TRANSFER_TYPE_IN_SEAT_TRANSFER;default:return b.UNRECOGNIZED}}function U(t){switch(t){case 0:case"ROUTE_TYPE_UNSPECIFIED":return w.ROUTE_TYPE_UNSPECIFIED;case 1:case"ROUTE_TYPE_TRAM":return w.ROUTE_TYPE_TRAM;case 2:case"ROUTE_TYPE_SUBWAY":return w.ROUTE_TYPE_SUBWAY;case 3:case"ROUTE_TYPE_RAIL":return w.ROUTE_TYPE_RAIL;case 4:case"ROUTE_TYPE_BUS":return w.ROUTE_TYPE_BUS;case 5:case"ROUTE_TYPE_FERRY":return w.ROUTE_TYPE_FERRY;case 6:case"ROUTE_TYPE_CABLE_TRAM":return w.ROUTE_TYPE_CABLE_TRAM;case 7:case"ROUTE_TYPE_AERIAL_LIFT":return w.ROUTE_TYPE_AERIAL_LIFT;case 8:case"ROUTE_TYPE_FUNICULAR":return w.ROUTE_TYPE_FUNICULAR;case 9:case"ROUTE_TYPE_TROLLEYBUS":return w.ROUTE_TYPE_TROLLEYBUS;case 10:case"ROUTE_TYPE_MONORAIL":return w.ROUTE_TYPE_MONORAIL;default:return w.UNRECOGNIZED}}function x(){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"}(b||(b={})),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"}(w||(w={}));const L={encode:(t,e=new m)=>(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){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r=x();for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(10!==t)break;r.stopTimes=i.bytes();continue;case 2:if(18!==t)break;r.pickupDropOffTypes=i.bytes();continue;case 3:if(26!==t)break;r.stops=i.bytes();continue;case 4:if(32!==t)break;r.serviceRouteId=i.uint32();continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({stopTimes:j(t.stopTimes)?$(t.stopTimes):j(t.stop_times)?$(t.stop_times):new Uint8Array(0),pickupDropOffTypes:j(t.pickupDropOffTypes)?$(t.pickupDropOffTypes):j(t.pickup_drop_off_types)?$(t.pickup_drop_off_types):new Uint8Array(0),stops:j(t.stops)?$(t.stops):new Uint8Array(0),serviceRouteId:j(t.serviceRouteId)?globalThis.Number(t.serviceRouteId):j(t.service_route_id)?globalThis.Number(t.service_route_id):0}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=k(t.stopTimes)),0!==t.pickupDropOffTypes.length&&(e.pickupDropOffTypes=k(t.pickupDropOffTypes)),0!==t.stops.length&&(e.stops=k(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,i,n;const o=x();return o.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),o.pickupDropOffTypes=null!==(r=t.pickupDropOffTypes)&&void 0!==r?r:new Uint8Array(0),o.stops=null!==(i=t.stops)&&void 0!==i?i:new Uint8Array(0),o.serviceRouteId=null!==(n=t.serviceRouteId)&&void 0!==n?n:0,o}};const D={encode:(t,e=new m)=>(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){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={destination:0,type:0,minTransferTime:void 0};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(8!==t)break;r.destination=i.uint32();continue;case 2:if(16!==t)break;r.type=i.int32();continue;case 3:if(24!==t)break;r.minTransferTime=i.uint32();continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({destination:j(t.destination)?globalThis.Number(t.destination):0,type:j(t.type)?P(t.type):0,minTransferTime:j(t.minTransferTime)?globalThis.Number(t.minTransferTime):j(t.min_transfer_time)?globalThis.Number(t.min_transfer_time):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 b.TRANSFER_TYPE_UNSPECIFIED:return"TRANSFER_TYPE_UNSPECIFIED";case b.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT";case b.TRANSFER_TYPE_TIMED_TRANSFER:return"TRANSFER_TYPE_TIMED_TRANSFER";case b.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME";case b.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"TRANSFER_TYPE_IN_SEAT_TRANSFER";case b.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,i;const n={destination:0,type:0,minTransferTime:void 0};return n.destination=null!==(e=t.destination)&&void 0!==e?e:0,n.type=null!==(r=t.type)&&void 0!==r?r:0,n.minTransferTime=null!==(i=t.minTransferTime)&&void 0!==i?i:void 0,n}};const C={encode:(t,e=new m)=>(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){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={stopIndex:0,routeId:0,tripIndex:0};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(8!==t)break;r.stopIndex=i.uint32();continue;case 2:if(16!==t)break;r.routeId=i.uint32();continue;case 3:if(24!==t)break;r.tripIndex=i.uint32();continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({stopIndex:j(t.stopIndex)?globalThis.Number(t.stopIndex):j(t.stop_index)?globalThis.Number(t.stop_index):0,routeId:j(t.routeId)?globalThis.Number(t.routeId):j(t.route_id)?globalThis.Number(t.route_id):0,tripIndex:j(t.tripIndex)?globalThis.Number(t.tripIndex):j(t.trip_index)?globalThis.Number(t.trip_index):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=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,i;const n={stopIndex:0,routeId:0,tripIndex:0};return n.stopIndex=null!==(e=t.stopIndex)&&void 0!==e?e:0,n.routeId=null!==(r=t.routeId)&&void 0!==r?r:0,n.tripIndex=null!==(i=t.tripIndex)&&void 0!==i?i:0,n}};const M={encode(t,e=new m){void 0!==t.origin&&C.encode(t.origin,e.uint32(10).fork()).join();for(const r of t.destinations)C.encode(r,e.uint32(18).fork()).join();return e},decode(t,e){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={origin:void 0,destinations:[]};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(10!==t)break;r.origin=C.decode(i,i.uint32());continue;case 2:if(18!==t)break;r.destinations.push(C.decode(i,i.uint32()));continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({origin:j(t.origin)?C.fromJSON(t.origin):void 0,destinations:globalThis.Array.isArray(null==t?void 0:t.destinations)?t.destinations.map((t=>C.fromJSON(t))):[]}),toJSON(t){var e;const r={};return void 0!==t.origin&&(r.origin=C.toJSON(t.origin)),(null===(e=t.destinations)||void 0===e?void 0:e.length)&&(r.destinations=t.destinations.map((t=>C.toJSON(t)))),r},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={origin:void 0,destinations:[]};return r.origin=void 0!==t.origin&&null!==t.origin?C.fromPartial(t.origin):void 0,r.destinations=(null===(e=t.destinations)||void 0===e?void 0:e.map((t=>C.fromPartial(t))))||[],r}};const Y={encode(t,e=new m){if(0!==t.routes.length){e.uint32(10).fork();for(const r of t.routes)e.uint32(r);e.join()}for(const r of t.transfers)D.encode(r,e.uint32(18).fork()).join();return e},decode(t,e){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={routes:[],transfers:[]};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(8===t){r.routes.push(i.uint32());continue}if(10===t){const t=i.uint32()+i.pos;for(;i.pos<t;)r.routes.push(i.uint32());continue}break;case 2:if(18!==t)break;r.transfers.push(D.decode(i,i.uint32()));continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},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=>D.fromJSON(t))):[]}),toJSON(t){var e,r;const i={};return(null===(e=t.routes)||void 0===e?void 0:e.length)&&(i.routes=t.routes.map((t=>Math.round(t)))),(null===(r=t.transfers)||void 0===r?void 0:r.length)&&(i.transfers=t.transfers.map((t=>D.toJSON(t)))),i},create:t=>Y.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const i={routes:[],transfers:[]};return i.routes=(null===(e=t.routes)||void 0===e?void 0:e.map((t=>t)))||[],i.transfers=(null===(r=t.transfers)||void 0===r?void 0:r.map((t=>D.fromPartial(t))))||[],i}};const F={encode(t,e=new m){if(0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),0!==t.routes.length){e.uint32(26).fork();for(const r of t.routes)e.uint32(r);e.join()}return e},decode(t,e){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={type:0,name:"",routes:[]};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(8!==t)break;r.type=i.int32();continue;case 2:if(18!==t)break;r.name=i.string();continue;case 3:if(24===t){r.routes.push(i.uint32());continue}if(26===t){const t=i.uint32()+i.pos;for(;i.pos<t;)r.routes.push(i.uint32());continue}}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({type:j(t.type)?U(t.type):0,name:j(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 w.ROUTE_TYPE_UNSPECIFIED:return"ROUTE_TYPE_UNSPECIFIED";case w.ROUTE_TYPE_TRAM:return"ROUTE_TYPE_TRAM";case w.ROUTE_TYPE_SUBWAY:return"ROUTE_TYPE_SUBWAY";case w.ROUTE_TYPE_RAIL:return"ROUTE_TYPE_RAIL";case w.ROUTE_TYPE_BUS:return"ROUTE_TYPE_BUS";case w.ROUTE_TYPE_FERRY:return"ROUTE_TYPE_FERRY";case w.ROUTE_TYPE_CABLE_TRAM:return"ROUTE_TYPE_CABLE_TRAM";case w.ROUTE_TYPE_AERIAL_LIFT:return"ROUTE_TYPE_AERIAL_LIFT";case w.ROUTE_TYPE_FUNICULAR:return"ROUTE_TYPE_FUNICULAR";case w.ROUTE_TYPE_TROLLEYBUS:return"ROUTE_TYPE_TROLLEYBUS";case w.ROUTE_TYPE_MONORAIL:return"ROUTE_TYPE_MONORAIL";case w.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=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,i;const n={type:0,name:"",routes:[]};return n.type=null!==(e=t.type)&&void 0!==e?e:0,n.name=null!==(r=t.name)&&void 0!==r?r:"",n.routes=(null===(i=t.routes)||void 0===i?void 0:i.map((t=>t)))||[],n}};const B={encode(t,e=new m){for(const r of t.stopsAdjacency)Y.encode(r,e.uint32(10).fork()).join();for(const r of t.routesAdjacency)L.encode(r,e.uint32(18).fork()).join();for(const r of t.serviceRoutes)F.encode(r,e.uint32(26).fork()).join();for(const r of t.tripContinuations)M.encode(r,e.uint32(34).fork()).join();for(const r of t.guaranteedTripTransfers)M.encode(r,e.uint32(42).fork()).join();return e},decode(t,e){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(10!==t)break;r.stopsAdjacency.push(Y.decode(i,i.uint32()));continue;case 2:if(18!==t)break;r.routesAdjacency.push(L.decode(i,i.uint32()));continue;case 3:if(26!==t)break;r.serviceRoutes.push(F.decode(i,i.uint32()));continue;case 4:if(34!==t)break;r.tripContinuations.push(M.decode(i,i.uint32()));continue;case 5:if(42!==t)break;r.guaranteedTripTransfers.push(M.decode(i,i.uint32()));continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>Y.fromJSON(t))):globalThis.Array.isArray(null==t?void 0:t.stops_adjacency)?t.stops_adjacency.map((t=>Y.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>L.fromJSON(t))):globalThis.Array.isArray(null==t?void 0:t.routes_adjacency)?t.routes_adjacency.map((t=>L.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>F.fromJSON(t))):globalThis.Array.isArray(null==t?void 0:t.service_routes)?t.service_routes.map((t=>F.fromJSON(t))):[],tripContinuations:globalThis.Array.isArray(null==t?void 0:t.tripContinuations)?t.tripContinuations.map((t=>M.fromJSON(t))):globalThis.Array.isArray(null==t?void 0:t.trip_continuations)?t.trip_continuations.map((t=>M.fromJSON(t))):[],guaranteedTripTransfers:globalThis.Array.isArray(null==t?void 0:t.guaranteedTripTransfers)?t.guaranteedTripTransfers.map((t=>M.fromJSON(t))):globalThis.Array.isArray(null==t?void 0:t.guaranteed_trip_transfers)?t.guaranteed_trip_transfers.map((t=>M.fromJSON(t))):[]}),toJSON(t){var e,r,i,n,o;const s={};return(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(s.stopsAdjacency=t.stopsAdjacency.map((t=>Y.toJSON(t)))),(null===(r=t.routesAdjacency)||void 0===r?void 0:r.length)&&(s.routesAdjacency=t.routesAdjacency.map((t=>L.toJSON(t)))),(null===(i=t.serviceRoutes)||void 0===i?void 0:i.length)&&(s.serviceRoutes=t.serviceRoutes.map((t=>F.toJSON(t)))),(null===(n=t.tripContinuations)||void 0===n?void 0:n.length)&&(s.tripContinuations=t.tripContinuations.map((t=>M.toJSON(t)))),(null===(o=t.guaranteedTripTransfers)||void 0===o?void 0:o.length)&&(s.guaranteedTripTransfers=t.guaranteedTripTransfers.map((t=>M.toJSON(t)))),s},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,i,n,o;const s={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};return s.stopsAdjacency=(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.map((t=>Y.fromPartial(t))))||[],s.routesAdjacency=(null===(r=t.routesAdjacency)||void 0===r?void 0:r.map((t=>L.fromPartial(t))))||[],s.serviceRoutes=(null===(i=t.serviceRoutes)||void 0===i?void 0:i.map((t=>F.fromPartial(t))))||[],s.tripContinuations=(null===(n=t.tripContinuations)||void 0===n?void 0:n.map((t=>M.fromPartial(t))))||[],s.guaranteedTripTransfers=(null===(o=t.guaranteedTripTransfers)||void 0===o?void 0:o.map((t=>M.fromPartial(t))))||[],s}};function $(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 k(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 j(t){return null!=t}const z=0,G=1;let V=class t{constructor(t,e,r,i,n){this.id=t,this.stopTimes=e,this.pickupDropOffTypes=r,this.stops=i,this.serviceRouteId=n,this.nbStops=i.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<i.length;t++){const e=i[t],r=this.stopIndices.get(e);r?r.push(t):this.stopIndices.set(e,[t])}}static of(e){var r,i;const{id:n,serviceRouteId:o,trips:s}=e;if(0===s.length)throw new Error("At least one trip must be provided");const a=s[0],u=new Uint32Array(a.stops.map((t=>t.id))),d=u.length;for(let t=1;t<s.length;t++){const e=s[t];if(e.stops.length!==d)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${d}`);for(let r=0;r<d;r++)if(e.stops[r].id!==u[r])throw new Error(`Trip ${t} has different stop at index ${r}`)}const c=new Uint16Array(s.length*d*2);for(let t=0;t<s.length;t++){const e=s[t];for(let r=0;r<d;r++){const i=e.stops[r],n=2*(t*d+r);c[n]=i.arrivalTime,c[n+1]=i.departureTime}}const l=s.length*d,h=new Uint8Array(Math.ceil(l/2));for(let t=0;t<s.length;t++){const e=s[t];for(let n=0;n<d;n++){const o=e.stops[n],s=t*d+n,a=null!==(r=o.pickUpType)&&void 0!==r?r:z,u=null!==(i=o.dropOffType)&&void 0!==i?i:z,c=Math.floor(s/2),l=s%2==1;h[c]|=l?a<<6|u<<4:a<<2|u}}return new t(n,c,h,u,o)}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),i=this.stopTimes[r];if(void 0===i)throw new Error(`Arrival time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return i}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,i=this.pickupDropOffTypes[r>>1];return 1&r?i>>4&3:3&i}departureFrom(t,e){const r=2*(e*this.stops.length+t)+1,i=this.stopTimes[r];if(void 0===i)throw new Error(`Departure time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return i}pickUpTypeFrom(t,e){const r=e*this.stops.length+t,i=r>>1,n=!(1&~r),o=this.pickupDropOffTypes[i];if(void 0===o)throw new Error(`Pick up type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return n?o>>6&3:o>>2&3}dropOffTypeAt(t,e){const r=e*this.stops.length+t,i=r>>1,n=!(1&~r),o=this.pickupDropOffTypes[i];if(void 0===o)throw new Error(`Drop off type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return n?o>>4&3:3&o}findEarliestTrip(t,e=0,r){if(this.nbTrips<=0)return;let i=this.nbTrips-1;if(void 0!==r&&(i=Math.min(i,r-1)),i<0)return;let n=0,o=-1;for(;n<=i;){const r=n+i>>>1;this.departureFrom(t,r)<e?n=r+1:(o=r,i=r-1)}return-1!==o?o: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 J=(BigInt(1)<<BigInt(20))-BigInt(1),W=1048575,Z=BigInt(0),Q=BigInt(20),q=BigInt(40),H=(t,e)=>{if(t<0||t>W)throw new Error(`${e} must be between 0 and 1048575, got ${t}`)},X=(t,e,r)=>(H(t,"stopIndex"),H(e,"routeId"),H(r,"tripIndex"),BigInt(t)<<q|BigInt(e)<<Q|BigInt(r)<<Z),K=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),tt=!0,et=t=>{if(K===tt)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],tt);return e},rt=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(K===tt)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,tt);return e},it=t=>{if(K===tt)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],tt);return e},nt=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(K===tt)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,tt);return e},ot=t=>{const e=[];return t.forEach((t=>{const r=t.serialize();e.push({stopTimes:it(r.stopTimes),pickupDropOffTypes:r.pickupDropOffTypes,stops:et(r.stops),serviceRouteId:r.serviceRouteId})})),e},st=t=>{switch(t){case b.TRANSFER_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf transfer type.");case b.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return ht.RECOMMENDED;case b.TRANSFER_TYPE_TIMED_TRANSFER:return ht.GUARANTEED;case b.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return ht.REQUIRES_MINIMAL_TIME;case b.TRANSFER_TYPE_IN_SEAT_TRANSFER:return ht.IN_SEAT;case b.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},at=t=>{switch(t){case ht.RECOMMENDED:return b.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case ht.GUARANTEED:return b.TRANSFER_TYPE_TIMED_TRANSFER;case ht.REQUIRES_MINIMAL_TIME:return b.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case ht.IN_SEAT:return b.TRANSFER_TYPE_IN_SEAT_TRANSFER}},ut=t=>{switch(t){case w.ROUTE_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf route type.");case w.ROUTE_TYPE_TRAM:return pt.TRAM;case w.ROUTE_TYPE_SUBWAY:return pt.SUBWAY;case w.ROUTE_TYPE_RAIL:return pt.RAIL;case w.ROUTE_TYPE_BUS:return pt.BUS;case w.ROUTE_TYPE_FERRY:return pt.FERRY;case w.ROUTE_TYPE_CABLE_TRAM:return pt.CABLE_TRAM;case w.ROUTE_TYPE_AERIAL_LIFT:return pt.AERIAL_LIFT;case w.ROUTE_TYPE_FUNICULAR:return pt.FUNICULAR;case w.ROUTE_TYPE_TROLLEYBUS:return pt.TROLLEYBUS;case w.ROUTE_TYPE_MONORAIL:return pt.MONORAIL;case w.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},dt=t=>{switch(t){case pt.TRAM:return w.ROUTE_TYPE_TRAM;case pt.SUBWAY:return w.ROUTE_TYPE_SUBWAY;case pt.RAIL:return w.ROUTE_TYPE_RAIL;case pt.BUS:return w.ROUTE_TYPE_BUS;case pt.FERRY:return w.ROUTE_TYPE_FERRY;case pt.CABLE_TRAM:return w.ROUTE_TYPE_CABLE_TRAM;case pt.AERIAL_LIFT:return w.ROUTE_TYPE_AERIAL_LIFT;case pt.FUNICULAR:return w.ROUTE_TYPE_FUNICULAR;case pt.TROLLEYBUS:return w.ROUTE_TYPE_TROLLEYBUS;case pt.MONORAIL:return w.ROUTE_TYPE_MONORAIL}},ct=t=>{const e=[];for(const[i,n]of t.entries()){const[t,o,s]=(r=i,[Number(r>>q&J),Number(r>>Q&J),Number(r>>Z&J)]);e.push({origin:{stopIndex:t,routeId:o,tripIndex:s},destinations:n.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})))})}var r;return e},lt=t=>{const e=new Map;for(let r=0;r<t.length;r++){const i=t[r],n=i.origin,o=X(n.stopIndex,n.routeId,n.tripIndex),s=i.destinations.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(o,s)}return e},ht={RECOMMENDED:1,GUARANTEED:2,REQUIRES_MINIMAL_TIME:3,IN_SEAT:4},pt={TRAM:1,SUBWAY:2,RAIL:3,BUS:4,FERRY:5,CABLE_TRAM:6,AERIAL_LIFT:7,FUNICULAR:8,TROLLEYBUS:9,MONORAIL:10},ft=new Set(Object.values(pt)),Tt=[];class _t{constructor(t,e,r,i,n){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=r,this.tripContinuations=i,this.guaranteedTripTransfers=n,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:at(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime}))):[],routes:t.routes})))),routesAdjacency:ot(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:dt(t.type),name:t.name,routes:t.routes})))),tripContinuations:ct(this.tripContinuations||new Map),guaranteedTripTransfers:ct(this.guaranteedTripTransfers||new Map)};var e,r;const i=new m;return B.encode(t,i),i.finish()}static fromData(t){const e=new S(t),r=B.decode(e);return new _t((t=>{const e=[];for(let r=0;r<t.length;r++){const i=t[r],n=[];for(let t=0;t<i.transfers.length;t++){const e=i.transfers[t],r=Object.assign({destination:e.destination,type:st(e.type)},void 0!==e.minTransferTime&&{minTransferTime:e.minTransferTime});n.push(r)}const o={routes:i.routes};n.length>0&&(o.transfers=n),e.push(o)}return e})(r.stopsAdjacency),(t=>{const e=[];for(let r=0;r<t.length;r++){const i=t[r],n=rt(i.stops);e.push(new V(r,nt(i.stopTimes),i.pickupDropOffTypes,n,i.serviceRouteId))}return e})(r.routesAdjacency),(t=>{const e=[];for(let r=0;r<t.length;r++){const i=t[r];e.push({type:ut(i.type),name:i.name,routes:i.routes})}return e})(r.serviceRoutes),lt(r.tripContinuations),lt(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 i;const n=null===(i=this.tripContinuations)||void 0===i?void 0:i.get(X(t,e,r));return n||Tt}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 i=e.routes[t],n=this.routesAdjacency[i];n&&r.push(n)}return r}findReachableRoutes(t,e=ft){const r=new Map,i=e!==ft;for(const n of t){const t=this.stopsAdjacency[n];if(t)for(let o=0;o<t.routes.length;o++){const s=this.routesAdjacency[t.routes[o]];if(!s)continue;if(i){const t=this.serviceRoutes[s.serviceRoute()];if(!t||!e.has(t.type))continue}const a=s.stopRouteIndices(n)[0],u=r.get(s);void 0!==u?a<u&&r.set(s,a):r.set(s,a)}}return r}isTripTransferGuaranteed(t,e){var r;const i=X(t.stopIndex,t.routeId,t.tripIndex),n=null===(r=this.guaranteedTripTransfers)||void 0===r?void 0:r.get(i);if(!n)return!1;for(let t=0;t<n.length;t++){const r=n[t];if(r.stopIndex===e.stopIndex&&r.routeId===e.routeId&&r.tripIndex===e.tripIndex)return!0}return!1}findFirstBoardableTrip(t,e,r,i=0,n,o,s=0){const a=e.getNbTrips();for(let u=r;u<(null!=n?n:a);u++){if(e.pickUpTypeFrom(t,u)===G)continue;if(void 0===o)return u;if(this.isTripTransferGuaranteed(o,{stopIndex:t,routeId:e.id,tripIndex:u}))return u;if(e.departureFrom(t,u)>=i+s)return u}}getGuaranteedTripTransfers(t,e,r){var i;const n=null===(i=this.guaranteedTripTransfers)||void 0===i?void 0:i.get(X(t,e,r));return n||Tt}}const Et=t=>{switch(t){case pt.TRAM:return"TRAM";case pt.SUBWAY:return"SUBWAY";case pt.RAIL:return"RAIL";case pt.BUS:return"BUS";case pt.FERRY:return"FERRY";case pt.CABLE_TRAM:return"CABLE_TRAM";case pt.AERIAL_LIFT:return"AERIAL_LIFT";case pt.FUNICULAR:return"FUNICULAR";case pt.TROLLEYBUS:return"TROLLEYBUS";case pt.MONORAIL:return"MONORAIL"}},mt=t=>{switch(t){case ht.RECOMMENDED:return"RECOMMENDED";case ht.GUARANTEED:return"GUARANTEED";case ht.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case ht.IN_SEAT:return"IN_SEAT"}},It={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 gt(t){return"routeId"in t&&"stopIndex"in t&&"hopOffStopIndex"in t}function vt(t){return"from"in t&&"to"in t&&"type"in t}function Rt(t){return"from"in t&&"duration"in t}class At{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 i=Object.entries(r).map((([t,e])=>`${t}="${e}"`)).join(" "),n=i?` [${i}]`:"";return this.lines.push(` "${t}" -> "${e}"${n};`),this}addRaw(t){return this.lines.push(...t),this}build(){return this.lines.push("}"),this.lines.join("\n")}}class yt{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}yt.Builder=class{constructor(){var t;this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:(t=120,Math.round(t/60)),transportModes:ft}}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 yt(this)}};class St extends yt{constructor(t){super(t),this.lastDepartureTime=t.lastDepartureTimeValue,this.rangeOptions=t.rangeOptionsValue}}St.Builder=class extends yt.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 St(this)}};class Ot{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;for(let e=this.legs.length-1;e>=0;e--){const r=this.legs[e];if("arrivalTime"in r)return r.arrivalTime+t;"minTransferTime"in r&&r.minTransferTime&&(t+=r.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,i)=>{const n=`From: ${r.from.name}${r.from.platform?` (Pl. ${r.from.platform})`:""}`,o=`To: ${r.to.name}${r.to.platform?` (Pl. ${r.to.platform})`:""}`,s="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 ${i+1}:`,` ${n}`,` ${o}`,s?` ${s}`:"",a?` ${a}`:"",u?` ${u}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}}const Nt=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],bt=t=>{const e=Nt[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};class wt{constructor(t,e,r,i){this.destinations=t,this.routingState=e,this.stopsIndex=r,this.timetable=i}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 i,n,o;for(const t of r){const e=this.routingState.getArrival(t);void 0!==e&&(void 0===n||e.arrival<n)&&(i=t,n=e.arrival,o=e.legNumber)}if(void 0===i||void 0===o)return;const s=[];let a,u=i,d=o;for(;d>=0;){const t=null===(e=this.routingState.graph[d])||void 0===e?void 0:e[u];if(!t){if(0===d)break;throw new Error(`No edge arriving at stop ${u} at round ${d}`)}let r;if("routeId"in t){let e,i;if(t.continuationOf){let r=t;const n=[r];for(;r.continuationOf;)n.push(r.continuationOf),r=r.continuationOf;e=r,i=this.buildVehicleLeg(n)}else e=t,i=this.buildVehicleLeg([t]);r=i,a&&this.timetable.isTripTransferGuaranteed({stopIndex:e.hopOffStopIndex,routeId:e.routeId,tripIndex:e.tripIndex},{stopIndex:a.stopIndex,routeId:a.routeId,tripIndex:a.tripIndex})&&s.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}s.push(r),u=r.from.id,"routeId"in t&&(d-=1)}return new Ot(s.reverse())}buildServiceRouteInfo(t){const e=this.timetable.getServiceRouteInfo(t);return{type:Et(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],i=this.timetable.getRoute(e.routeId),n=this.timetable.getRoute(r.routeId);return{from:this.stopsIndex.findStopById(i.stopId(e.stopIndex)),to:this.stopsIndex.findStopById(n.stopId(r.hopOffStopIndex)),route:this.buildServiceRouteInfo(i),departureTime:i.departureFrom(e.stopIndex,e.tripIndex),arrivalTime:r.arrival,pickUpType:bt(i.pickUpTypeFrom(e.stopIndex,e.tripIndex)),dropOffType:bt(n.dropOffTypeAt(r.hopOffStopIndex,r.tripIndex))}}buildTransferLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),minTransferTime:t.minTransferTime,type:mt(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),i=this.timetable.getRoute(e.routeId),n=r.stopId(t.hopOffStopIndex),o=i.stopId(e.stopIndex);return{from:this.stopsIndex.findStopById(n),to:this.stopsIndex.findStopById(o),type:mt(ht.GUARANTEED)}}arrivalAt(t,e){var r,i;const n=this.stopsIndex.equivalentStops(t);let o;for(const t of n){let n;if(void 0===e||(null===(r=this.routingState.getArrival(t.id))||void 0===r?void 0:r.legNumber)===e+1)n=this.routingState.getArrival(t.id);else for(let r=e+1;r>=0;r--){const e=null===(i=this.routingState.graph[r])||void 0===i?void 0:i[t.id];if(void 0!==e){n={arrival:e.arrival,legNumber:r};break}}void 0!==n&&(void 0===o||n.arrival<o.arrival)&&(o=n)}return o}}class Pt{constructor(t,e){this.timetable=t,this.stopsIndex=e}collectAccessPaths(t,e){var r;const i=this.stopsIndex.equivalentStops(t).map((t=>t.id)),n=new Map;for(const t of i){const i=n.get(t);(void 0===i||i.duration>0)&&n.set(t,{fromStopId:t,toStopId:t,duration:0});for(const i of this.timetable.getTransfers(t))if(i.type===ht.REQUIRES_MINIMAL_TIME){const o=null!==(r=i.minTransferTime)&&void 0!==r?r:e,s=n.get(i.destination);(void 0===s||s.duration&&o<s.duration)&&n.set(i.destination,{fromStopId:t,toStopId:i.destination,duration:o})}}return Array.from(n.values())}collectDepartureTimes(t,e,r){const i=new Map;for(const n of t){const{toStopId:t}=n,o=e+n.duration,s=r+n.duration;for(const e of this.timetable.routesPassingThrough(t))for(const r of e.stopRouteIndices(t)){let t=e.findEarliestTrip(r,o);if(void 0===t)continue;const a=e.getNbTrips();for(;t<a;){const o=e.departureFrom(r,t);if(o>s)break;if(e.pickUpTypeFrom(r,t)!==G){const t=o-n.duration;let e=i.get(t);void 0===e&&i.set(t,e=new Set),e.add(n)}t++}}}if(0===i.size)return[];const n=Array.from(i.entries()).sort((([t],[e])=>e-t));return n.map((([t,e])=>({depTime:t,legs:Array.from(e)})))}}const Ut=65535;class xt{constructor(t,e,r,i,n=0,o){this._destinationBest=Ut,this.maxArrivalTime=Ut,this.reachedStops=[],this.destinations=e,this.maxDuration=o,this.maxArrivalTime=void 0===o?Ut:t+o,this.destinationSet=new Set(e),this.earliestArrivalTimes=new Uint16Array(i).fill(Ut),this.earliestArrivalLegs=new Uint8Array(i),this.origins=[],this.graph=[new Array(i)];for(let t=1;t<=n;t++)this.graph.push(new Array(i));this.seedAccessPaths(t,r)}seedAccessPaths(t,e){const r=new Set;for(const i of e){const e=t+i.duration;if(e>this.maxArrivalTime)continue;const n=0===i.duration?{stopId:i.fromStopId,arrival:t}:{arrival:e,from:i.fromStopId,to:i.toStopId,duration:i.duration},o=i.toStopId;e<this.earliestArrivalTimes[o]&&(this.earliestArrivalTimes[o]=e,this.graph[0][o]=n),r.add(o)}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]=Ut,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=Ut,this.maxArrivalTime=void 0===this.maxDuration?Ut:t+this.maxDuration,this.seedAccessPaths(t,e)}*arrivals(){for(let t=0;t<this.earliestArrivalTimes.length;t++){const e=this.earliestArrivalTimes[t];e<Ut&&(yield{stop:t,arrival:e,legNumber:this.earliestArrivalLegs[t]})}}earliestArrivalAtAnyDestination(){return this._destinationBest}getArrival(t){const e=this.earliestArrivalTimes[t];if(!(e>=Ut))return{arrival:e,legNumber:this.earliestArrivalLegs[t]}}isDestination(t){return this.destinationSet.has(t)}static fromTestData({nbStops:t,origins:e=[],destinations:r=[],arrivals:i=[],graph:n=[]}){const o=new xt(0,r,e.map((t=>({fromStopId:t,toStopId:t,duration:0}))),t),s=new Uint16Array(t).fill(Ut),a=new Uint8Array(t);for(const[t,e,r]of i)s[t]=e,a[t]=r;o.earliestArrivalTimes=s,o.earliestArrivalLegs=a,o._destinationBest=Ut;for(const t of r){const e=s[t];void 0!==e&&e<o._destinationBest&&(o._destinationBest=e)}const u=n.map((e=>{const r=new Array(t);for(const[t,i]of e)r[t]=i;return r}));return o.graph.splice(0,o.graph.length,...u),o}}class Lt{constructor(t,e,r,i){this.timetable=t,this.stopsIndex=e,this.accessFinder=r,this.raptor=i}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)),i=new xt(t.departureTime,r,e,this.timetable.nbStops(),t.options.maxTransfers+1,t.options.maxDuration);return this.raptor.run(t.options,i),new wt(new Set(r),i,this.stopsIndex,this.timetable)}}class Dt{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,i;for(const t of this._runs)for(const n of e){const e=t.result.arrivalAt(n);void 0!==e&&((void 0===i||e.arrival<i)&&(i=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,i=1/0;for(const t of this._runs)for(const n of e){const e=t.result.arrivalAt(n);if(void 0===e)continue;const o=e.arrival-t.departureTime;(o<i||o===i&&void 0!==r&&t.departureTime<r.departureTime)&&(i=o,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:i}of this._runs){const n=i.arrivalAt(t,e);void 0!==n&&(void 0===r||n.arrival<r.arrival)&&(r=n)}return r}shortestDurationTo(t,e){let r;for(const{departureTime:i,result:n}of this._runs){const o=n.arrivalAt(t,e);if(void 0===o)continue;const s=o.arrival-i;(void 0===r||s<r.duration)&&(r=Object.assign(Object.assign({},o),{duration:s}))}return r}allShortestDurations(){const t=new Map;for(const{departureTime:e,result:r}of this._runs)for(const{stop:i,arrival:n,legNumber:o}of r.routingState.arrivals()){const r=n-e,s=t.get(i);(void 0===s||r<s.duration)&&t.set(i,{arrival:n,legNumber:o,duration:r})}return t}allEarliestArrivals(){const t=new Map;for(const{result:e}of this._runs)for(const{stop:r,arrival:i,legNumber:n}of e.routingState.arrivals()){const e=t.get(r);(void 0===e||i<e.arrival)&&t.set(r,{arrival:i,legNumber:n})}return t}[Symbol.iterator](){return this._runs[Symbol.iterator]()}}class Ct{constructor(t,e,r){this._destinationBest=Ut,this.latestDeparture=r,this.roundLabels=Array.from({length:t+2},(()=>new Uint16Array(e).fill(Ut))),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 i=this.currentRun.getArrival(t);(void 0===i||e<i.arrival||e===i.arrival&&r<i.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],i=this.roundLabels[t];for(let t=0;t<e.length;t++){const n=e[t];r[n]<i[n]&&(i[n]=r[n])}e.length=0}}class Mt{constructor(t,e,r,i){this.timetable=t,this.stopsIndex=e,this.accessFinder=r,this.raptor=i}rangeRoute(t){var e,r;const{departureTime:i,lastDepartureTime:n}=t,o=Array.from(t.to).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),s=0===o.length,a=this.accessFinder.collectAccessPaths(t.from,t.options.minTransferTime),u=this.accessFinder.collectDepartureTimes(a,i,n);if(0===u.length)return new Dt([],new Set(o));const d=t.options.maxTransfers+1,c=new Ct(d,this.timetable.nbStops(),n),l=[],h=new Map;for(const t of o)h.set(t,Ut);const p=new Set(a.map((t=>t.toStopId)).filter((t=>o.includes(t)))),f=new Set;let T=null;if(t.rangeOptions.optimizeBeyondLatestDeparture&&(T=new xt(n+1,o,a,this.timetable.nbStops(),d,t.options.maxDuration),c.setCurrentRun(T),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:void 0}),c),!s))for(const t of o){const r=T.arrivalTime(t);r<(null!==(e=h.get(t))&&void 0!==e?e:Ut)&&h.set(t,r)}for(const{depTime:e,legs:i}of u){if(!s&&f.size===o.length)break;null===T?T=new xt(e,o,i,this.timetable.nbStops(),d,t.options.maxDuration):T.resetFor(e,i),c.setCurrentRun(T),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:0}),c);let n=s;if(!s)for(const t of o){const e=T.arrivalTime(t);e>=(null!==(r=h.get(t))&&void 0!==r?r:Ut)||(p.has(t)&&f.has(t)?h.set(t,e):(h.set(t,e),p.has(t)&&f.add(t),n=!0))}n&&(l.push({departureTime:e,result:new wt(new Set(o),T,this.stopsIndex,this.timetable)}),T=null)}return new Dt(l,new Set(o))}}class Yt{constructor(t){this.timetable=t}run(t,e){const r=new Set(e.origins);for(let i=1;i<=t.maxTransfers+1;i++){e.initRound(i);const n=e.graph[i],o=this.timetable.findReachableRoutes(r,t.transportModes);r.clear();for(const[n,s]of o)for(const o of this.scanRoute(n,s,i,e,t))r.add(o);let s=this.findTripContinuations(r,n);const a=new Set;for(;s.length>0;){a.clear();for(const t of s){const n=this.timetable.getRoute(t.routeId);for(const o of this.scanRouteContinuation(n,t.stopIndex,i,e,t))a.add(o),r.add(o)}s=this.findTripContinuations(a,n)}for(const n of this.considerTransfers(t,i,r,e))r.add(n);if(0===r.size)break}}findTripContinuations(t,e){const r=[];for(const i of t){const t=e[i];if(!t||!("routeId"in t))continue;const n=this.timetable.getContinuousTrips(t.hopOffStopIndex,t.routeId,t.tripIndex);for(const e of n)r.push({routeId:e.routeId,stopIndex:e.stopIndex,tripIndex:e.tripIndex,previousEdge:t})}return r}scanRouteContinuation(t,e,r,i,n){const o=new Set,s=i.graph[r],a=t.getNbStops(),u=t.id,d=n.tripIndex,c=t.tripStopOffset(d),l=n.previousEdge;for(let n=e;n<a;n++){const a=t.stops[n],h=t.arrivalAtOffset(n,c);t.dropOffTypeAtOffset(n,c)!==G&&h<=i.maxArrivalTime&&h<i.improvementBound(r,a)&&h<i.destinationBest&&(s[a]={routeId:u,stopIndex:e,tripIndex:d,arrival:h,hopOffStopIndex:n,continuationOf:l},i.updateArrival(a,h,r),o.add(a))}return o}scanRoute(t,e,r,i,n){const o=new Set,s=i.graph[r],a=i.graph[r-1],u=t.getNbStops(),d=t.id;let c,l=e,h=0;for(let p=e;p<u;p++){const e=t.stops[p];if(void 0!==c){const n=t.arrivalAtOffset(p,h);t.dropOffTypeAtOffset(p,h)!==G&&n<=i.maxArrivalTime&&n<i.improvementBound(r,e)&&n<i.destinationBest&&(s[e]={routeId:d,stopIndex:l,tripIndex:c,arrival:n,hopOffStopIndex:p},i.updateArrival(e,n,r),o.add(e))}const u=a[e],f=null==u?void 0:u.arrival;if(void 0!==f&&(void 0===c||f<=t.departureAtOffset(p,h))){const e=t.findEarliestTrip(p,f,c);if(void 0===e)continue;const o=u&&"routeId"in u?{stopIndex:u.hopOffStopIndex,routeId:u.routeId,tripIndex:u.tripIndex}:void 0,s=this.timetable.findFirstBoardableTrip(p,t,e,f,c,o,n.minTransferTime);if(void 0!==s){const e=t.departureFrom(p,s),o=1===r&&void 0!==n.maxInitialWaitingTime&&e-f>n.maxInitialWaitingTime,a=e>i.maxArrivalTime;o||a||(c=s,l=p,h=t.tripStopOffset(s))}}}return o}considerTransfers(t,e,r,i){const n=new Set,o=i.graph[e];for(const s of r){const r=o[s];if(!r||"type"in r)continue;const a=this.timetable.getTransfers(s);for(const u of a){let a;a=u.minTransferTime?u.minTransferTime:u.type===ht.IN_SEAT?0:t.minTransferTime;const d=r.arrival+a;d<=i.maxArrivalTime&&d<i.improvementBound(e,u.destination)&&d<i.destinationBest&&(o[u.destination]={arrival:d,from:s,to:u.destination,minTransferTime:a||void 0,type:u.type},i.updateArrival(u.destination,d,e),n.add(u.destination))}}return n}}class Ft{constructor(t=[],e=(t,e)=>t<e?-1:t>e?1:0){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this._up(this.length++)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return--this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:r}=this,i=e[t];for(;t>0;){const n=t-1>>1,o=e[n];if(r(i,o)>=0)break;e[t]=o,t=n}e[t]=i}_down(t){const{data:e,compare:r}=this,i=this.length>>1,n=e[t];for(;t<i;){let i=1+(t<<1);const o=i+1;if(o<this.length&&r(e[o],e[i])<0&&(i=o),r(e[i],n)>=0)break;e[t]=e[i],t=i}e[t]=n}}const Bt=Math.PI/180;function $t(t,e,r,i){const n=i.minLng,o=i.maxLng,s=i.minLat,a=i.maxLat;if(t>=n&&t<=o)return e<s?jt((e-s)*Bt):e>a?jt((e-a)*Bt):0;const u=Math.min(jt((t-n)*Bt),jt((t-o)*Bt)),d=function(t,e){const r=1-2*e;return r<=0?t>0?90:-90:Math.atan(Math.tan(t*Bt)/r)/Bt}(e,u);return d>s&&d<a?zt(u,r,e,d):Math.min(zt(u,r,e,s),zt(u,r,e,a))}function kt(t,e){return t.dist-e.dist}function jt(t){const e=Math.sin(t/2);return e*e}function zt(t,e,r,i){return e*Math.cos(i*Bt)*t+jt((r-i)*Bt)}function Gt(t,e,r,i,n){return zt(jt((t-r)*Bt),n,e,i)}const Vt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array],Jt=new Uint32Array(96);class Wt{static from(t){if(!t||void 0===t.byteLength||t.buffer)throw new Error("Data must be an instance of ArrayBuffer or SharedArrayBuffer.");const[e,r]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const i=r>>4;if(1!==i)throw new Error(`Got v${i} data when expected v1.`);const n=Vt[15&r];if(!n)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[s]=new Uint32Array(t,4,1);return new Wt(s,o,n,void 0,t)}constructor(t,e=64,r=Float64Array,i=ArrayBuffer,n){if(isNaN(t)||t<0)throw new Error(`Unexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=r,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const o=Vt.indexOf(this.ArrayType),s=2*t*this.ArrayType.BYTES_PER_ELEMENT,a=t*this.IndexArrayType.BYTES_PER_ELEMENT,u=(8-a%8)%8;if(o<0)throw new Error(`Unexpected typed array class: ${r}.`);if(n)this.data=n,this.ids=new this.IndexArrayType(n,8,t),this.coords=new r(n,8+a+u,2*t),this._pos=2*t,this._finished=!0;else{const n=this.data=new i(8+s+a+u);this.ids=new this.IndexArrayType(n,8,t),this.coords=new r(n,8+a+u,2*t),this._pos=0,this._finished=!1,new Uint8Array(n,0,2).set([219,16+o]),new Uint16Array(n,2,1)[0]=e,new Uint32Array(n,4,1)[0]=t}}add(t,e){const r=this._pos>>1;return this.ids[r]=r,this.coords[this._pos++]=t,this.coords[this._pos++]=e,r}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return Zt(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,r,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:o,nodeSize:s}=this;Jt[0]=0,Jt[1]=n.length-1,Jt[2]=0;let a=3;const u=[];for(;a>0;){const d=Jt[--a],c=Jt[--a],l=Jt[--a];if(c-l<=s){for(let s=l;s<=c;s++){const a=o[2*s],d=o[2*s+1];a>=t&&a<=r&&d>=e&&d<=i&&u.push(n[s])}continue}const h=l+c>>1,p=o[2*h],f=o[2*h+1];p>=t&&p<=r&&f>=e&&f<=i&&u.push(n[h]),(0===d?t<=p:e<=f)&&(Jt[a++]=l,Jt[a++]=h-1,Jt[a++]=1-d),(0===d?r>=p:i>=f)&&(Jt[a++]=h+1,Jt[a++]=c,Jt[a++]=1-d)}return u}within(t,e,r){const i=[];return this.withinInto(t,e,r,i),i}withinInto(t,e,r,i){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:o,nodeSize:s}=this;Jt[0]=0,Jt[1]=n.length-1,Jt[2]=0;let a=3,u=0;const d=r*r;for(;a>0;){const c=Jt[--a],l=Jt[--a],h=Jt[--a];if(l-h<=s){for(let r=h;r<=l;r++)Xt(o[2*r],o[2*r+1],t,e)<=d&&(i[u++]=n[r]);continue}const p=h+l>>1,f=o[2*p],T=o[2*p+1];Xt(f,T,t,e)<=d&&(i[u++]=n[p]),(0===c?t-r<=f:e-r<=T)&&(Jt[a++]=h,Jt[a++]=p-1,Jt[a++]=1-c),(0===c?t+r>=f:e+r>=T)&&(Jt[a++]=p+1,Jt[a++]=l,Jt[a++]=1-c)}return u}}function Zt(t,e,r,i,n,o){if(n-i<=r)return;const s=i+n>>1;Qt(t,e,s,i,n,o),Zt(t,e,r,i,s-1,1-o),Zt(t,e,r,s+1,n,1-o)}function Qt(t,e,r,i,n,o){for(;n>i;){if(n-i>600){const s=n-i+1,a=r-i+1,u=Math.log(s),d=.5*Math.exp(2*u/3),c=.5*Math.sqrt(u*d*(s-d)/s)*(a-s/2<0?-1:1);Qt(t,e,r,Math.max(i,Math.floor(r-a*d/s+c)),Math.min(n,Math.floor(r+(s-a)*d/s+c)),o)}const s=e[2*r+o];let a=i,u=n;for(qt(t,e,i,r),e[2*n+o]>s&&qt(t,e,i,n);a<u;){for(qt(t,e,a,u),a++,u--;e[2*a+o]<s;)a++;for(;e[2*u+o]>s;)u--}e[2*i+o]===s?qt(t,e,i,u):(u++,qt(t,e,u,n)),u<=r&&(i=u+1),r<=u&&(n=u-1)}}function qt(t,e,r,i){Ht(t,r,i),Ht(e,2*r,2*i),Ht(e,2*r+1,2*i+1)}function Ht(t,e,r){const i=t[e];t[e]=t[r],t[r]=i}function Xt(t,e,r,i){const n=t-r,o=e-i;return n*n+o*o}const Kt=t=>t[t.length-1],te="ENTRIES",ee="KEYS",re="VALUES";var ie=class{set;_type;_path;constructor(t,e){let r=t._tree,i=[...r.keys()];this.set=t,this._type=e,this._path=i.length>0?[{node:r,keys:i}]:[]}next(){let t=this.dive();return this.backtrack(),t}key(){return this.set._prefix+this._path.map((({keys:t})=>Kt(t))).filter((t=>""!==t)).join("")}value(){return Kt(this._path).node.get("")}[Symbol.iterator](){return this}result(){switch(this._type){case re:return this.value();case ee:return this.key();case te:return[this.key(),this.value()];default:throw Error(`Unknown iterator type: ${this._type}`)}}dive(){if(0===this._path.length)return{done:!0,value:void 0};let{node:t,keys:e}=Kt(this._path);if(""===Kt(e))return{done:!1,value:this.result()};let r=t.get(Kt(e));return this._path.push({node:r,keys:[...r.keys()]}),this.dive()}backtrack(){if(0===this._path.length)return;let{keys:t}=Kt(this._path);t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}};const ne=(t,e,r,i,n,o,s,a)=>{let u=o*s;t:for(let d of t.keys())if(""===d){let e=n[u-1];e<=r&&i.set(a,[t.get(d),e])}else{let u=o;for(let t=0;t<d.length;++t,++u){let i=d[t],o=s*u,a=o-s,c=n[o],l=Math.max(0,u-r-1),h=Math.min(s-1,u+r);for(let t=l;t<h;++t){let r=i!==e[t],s=n[a+t]+Number(r),u=n[a+t+1]+1,d=n[o+t]+1,l=n[o+t+1]=Math.min(s,u,d);l<c&&(c=l)}if(c>r)continue t}ne(t.get(d),e,r,i,n,u,s,a+d)}},oe=(t,e,r=[])=>{if(0===e.length||null==t)return[t,r];for(let i of t.keys())if(""!==i&&e.startsWith(i))return r.push([t,i]),oe(t.get(i),e.slice(i.length),r);return r.push([t,e]),oe(void 0,"",r)},se=(t,e)=>{if(0===e.length||!t)return t;for(let r of t.keys())if(""!==r&&e.startsWith(r))return se(t.get(r),e.slice(r.length))},ae=(t,e)=>{let r=e.length;t:for(let i=0;t&&i<r;){for(let n of t.keys())if(""!==n&&e[i]===n[0]){let o=Math.min(r-i,n.length),s=1;for(;s<o&&e[i+s]===n[s];)s+=1;let a=t.get(n);if(s===n.length)t=a;else{let r=new Map([[n.slice(s),a]]);t.set(e.slice(i,i+s),r),t.delete(n),t=r}i+=s;continue t}let n=new Map;return t.set(e.slice(i),n),n}return t},ue=(t,e,r)=>{if(0===t.length)return;let[i,n]=Kt(t);i.set(n+e,r),i.delete(n)},de=t=>{if(0===t.length)return;let[e,r]=Kt(t);if(e.delete(r),0===e.size)de(t.slice(0,-1));else if(1===e.size){let[r,i]=e.entries().next().value;""!==r&&ue(t.slice(0,-1),r,i)}};var ce=class t{_tree;_prefix;_size=void 0;constructor(t=new Map,e=""){this._tree=t,this._prefix=e}atPrefix(e){if(!e.startsWith(this._prefix))throw Error("Mismatched prefix");let[r,i]=oe(this._tree,e.slice(this._prefix.length));if(void 0===r){let[r,n]=Kt(i);for(let i of r.keys())if(""!==i&&i.startsWith(n)){let o=new Map([[i.slice(n.length),r.get(i)]]);return new t(o,e)}}return new t(r,e)}clear(){this._size=void 0,this._tree.clear()}delete(t){this._size=void 0,((t,e)=>{let[r,i]=oe(t,e);if(void 0!==r)if(r.delete(""),0===r.size)de(i);else if(1===r.size){let[t,e]=r.entries().next().value;ue(i,t,e)}})(this._tree,t)}entries(){return new ie(this,te)}forEach(t){for(let[e,r]of this)t(e,r,this)}fuzzyGet(t,e){return((t,e,r)=>{let i=new Map;if("string"!=typeof e)return i;let n=e.length+1,o=n+r,s=new Uint8Array(o*n).fill(r+1);for(let t=0;t<n;++t)s[t]=t;for(let t=1;t<o;++t)s[t*n]=t;return ne(t,e,r,i,s,1,n,""),i})(this._tree,t,e)}get(t){let e=se(this._tree,t);return void 0===e?void 0:e.get("")}has(t){return se(this._tree,t)?.has("")??!1}keys(){return new ie(this,ee)}set(t,e){if("string"!=typeof t)throw Error("key must be a string");return this._size=void 0,ae(this._tree,t).set("",e),this}get size(){if("number"==typeof this._size)return this._size;this._size=0;let t=this.entries();for(;!t.next().done;)this._size+=1;return this._size}update(t,e){if("string"!=typeof t)throw Error("key must be a string");this._size=void 0;let r=ae(this._tree,t);return r.set("",e(r.get(""))),this}fetch(t,e){if("string"!=typeof t)throw Error("key must be a string");this._size=void 0;let r=ae(this._tree,t),i=r.get("");return void 0===i&&r.set("",i=e()),i}values(){return new ie(this,re)}[Symbol.iterator](){return this.entries()}static from(e){let r=new t;for(let[t,i]of e)r.set(t,i);return r}static fromObject(e){return t.from(Object.entries(e))}};const le=/[\n\r\p{Z}\p{P}]+/u,he=(t,e)=>{t.includes(e)||t.push(e)},pe=(t,e)=>{for(let r of e)t.includes(r)||t.push(r)},fe=({score:t},{score:e})=>e-t,Te=()=>new Map,_e=(t,e)=>Object.hasOwn(t,e)?t[e]:void 0,Ee={or:(t,e)=>{for(let r of e.keys()){let i=t.get(r);if(null==i)t.set(r,e.get(r));else{let{score:t,terms:n,match:o}=e.get(r);i.score+=t,i.match=Object.assign(i.match,o),pe(i.terms,n)}}return t},and:(t,e)=>{let r=new Map;for(let i of e.keys()){let n=t.get(i);if(null==n)continue;let{score:o,terms:s,match:a}=e.get(i);pe(n.terms,s),r.set(i,{score:n.score+o,terms:n.terms,match:Object.assign(n.match,a)})}return r},and_not:(t,e)=>{for(let r of e.keys())t.delete(r);return t}},me=(t,e,r,i,n,o)=>{let{k:s,b:a,d:u}=o;return Math.log(1+(r-e+.5)/(e+.5))*(u+t*(s+1)/(t+s*(1-a+a*i/n)))},Ie=(t,e,r,i)=>{for(let n of Object.keys(t._fieldIds))if(t._fieldIds[n]===r)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${i}" was not present in field "${n}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},ge=(t,e,r,i)=>{let n=t._index.fetch(i,Te),o=n.get(e);if(null==o)o=new Map([[r,1]]),n.set(e,o);else{let t=o.get(r);o.set(r,(t??0)+1)}},ve=(t,e,r,i)=>{if(!t._index.has(i))return void Ie(t,r,e,i);let n=t._index.fetch(i,Te),o=n.get(e),s=o?.get(r);o&&null!=s?s<=1?o.size<=1?n.delete(e):o.delete(r):o.set(r,s-1):Ie(t,r,e,i),0===t._index.get(i).size&&t._index.delete(i)},Re=(t,e,r,i,n)=>{let o=t._fieldLength.get(e);o??t._fieldLength.set(e,o=[]),o[r]=n;let s=(t._avgFieldLength[r]||0)*i+n;t._avgFieldLength[r]=s/(i+1)},Ae=(t,e)=>{let{extractField:r,stringifyField:i,tokenize:n,processTerm:o,fields:s,idField:a}=t._options,u=r(e,a);if(null==u)throw Error(`SlimSearch: document does not have ID field "${a}"`);if(((t,e)=>t._idToShortId.has(e))(t,u))throw Error(`SlimSearch: duplicate ID ${u}`);let d=((t,e)=>{let r=t._nextId;return t._idToShortId.set(e,r),t._documentIds.set(r,e),t._documentCount+=1,t._nextId+=1,r})(t,u);((t,e,r)=>{let{storeFields:i,extractField:n}=t._options;if(0===i?.length)return;let o=t._storedFields.get(e);o??t._storedFields.set(e,o={});for(let t of i){let e=n(r,t);null!=e&&(o[t]=e)}})(t,d,e);for(let a of s){let s=r(e,a);if(null==s)continue;let u=n(i(s,a),a),c=t._fieldIds[a],l=new Set(u).size;Re(t,d,c,t._documentCount-1,l);for(let e of u){let r=o(e,a);if(Array.isArray(r))for(let e of r)ge(t,c,d,e);else r&&ge(t,c,d,r)}}},ye={idField:"id",extractField:(t,e)=>t[e],stringifyField:t=>t.toString(),tokenize:t=>t.split(le),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},Se={combineWith:"or",prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},Oe={combineWith:"and",prefix:(t,e,r)=>e===r.length-1},Ne={minDirtFactor:.1,minDirtCount:20},be={batchSize:1e3,batchWait:10,...Ne},we=Symbol("*"),Pe=(t,e="or")=>{if(0===t.length)return new Map;let r=e.toLowerCase();if(!(r in Ee))throw Error(`Invalid combination operator: ${e}`);return t.reduce(Ee[r])},Ue=(t,e,r,i,n,o,s,a,u,d=new Map)=>{if(null==o)return d;for(let c of Object.keys(s)){let l=s[c],h=t._fieldIds[c],p=o.get(h);if(null==p)continue;let f=p.size,T=t._avgFieldLength[h];for(let o of p.keys()){if(!t._documentIds.has(o)){ve(t,h,o,r),--f;continue}let s=a?a(t._documentIds.get(o),r,t._storedFields.get(o)):1;if(!s)continue;let _=p.get(o),E=t._fieldLength.get(o)[h],m=i*n*l*s*me(_,f,t._documentCount,E,T,u),I=d.get(o);if(I){I.score+=m,he(I.terms,e);let t=_e(I.match,r);t?t.push(c):I.match[r]=[c]}else d.set(o,{score:m,terms:[e],match:{[r]:[c]}})}}return d},xe=(t,e,r={})=>{if(e===we)return((t,e)=>{let r=new Map,i={...t._options.searchOptions,...e};for(let[e,n]of t._documentIds){let o=i.boostDocument?i.boostDocument(n,"",t._storedFields.get(e)):1;r.set(e,{score:o,terms:[],match:{}})}return r})(t,r);if("string"!=typeof e){let i={...r,...e,queries:void 0},n=e.queries.map((e=>xe(t,e,i)));return Pe(n,i.combineWith)}let{tokenize:i,processTerm:n,searchOptions:o}=t._options,s={tokenize:i,processTerm:n,...o,...r},{tokenize:a,processTerm:u}=s,d=a(e).flatMap((t=>u(t))).filter(Boolean).map((t=>(e,r,i)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,r,i):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,r,i):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,r,i):1}))(s)).map((e=>((t,e,r)=>{let i,n,o={...t._options.searchOptions,...r},s=(o.fields??t._options.fields).reduce(((t,e)=>(t[e]=_e(o.boost,e)||1,t)),{}),{boostDocument:a,weights:u,maxFuzzy:d,bm25:c}=o,{fuzzy:l,prefix:h}={...Se.weights,...u},p=t._index.get(e.term),f=Ue(t,e.term,e.term,1,e.termBoost,p,s,a,c);if(e.prefix&&(i=t._index.atPrefix(e.term)),e.fuzzy){let r=!0===e.fuzzy?.2:e.fuzzy,i=r<1?Math.min(d,Math.round(e.term.length*r)):r;i&&(n=t._index.fuzzyGet(e.term,i))}if(i)for(let[r,o]of i){let i=r.length-e.term.length;if(!i)continue;n?.delete(r);let u=h*r.length/(r.length+.3*i);Ue(t,e.term,r,u,e.termBoost,o,s,a,c,f)}if(n)for(let r of n.keys()){let[i,o]=n.get(r);if(!o)continue;let u=l*r.length/(r.length+o);Ue(t,e.term,r,u,e.termBoost,i,s,a,c,f)}return f})(t,e,s)));return Pe(d,s.combineWith)};var Le=class{_options;_index;_documentCount;_documentIds;_idToShortId;_fieldIds;_fieldLength;_avgFieldLength;_nextId;_storedFields;_dirtCount;_currentVacuum;_enqueuedVacuum;_enqueuedVacuumConditions;constructor(t){if(!t?.fields)throw Error('SlimSearch: option "fields" must be provided');let e=null==t.autoVacuum||!0===t.autoVacuum?be:t.autoVacuum;this._options={...ye,...t,autoVacuum:e,searchOptions:{...Se,...t.searchOptions},autoSuggestOptions:{...Oe,...t.autoSuggestOptions}},this._index=new ce,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=Ne,this.addFields(this._options.fields)}get isVacuuming(){return null!=this._currentVacuum}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}get documentCount(){return this._documentCount}get termCount(){return this._index.size}toJSON(){let t=[];for(let[e,r]of this._index){let i={};for(let[t,e]of r)i[t]=Object.fromEntries(e);t.push([e,i])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:t,version:2}}addFields(t){for(let e=0;e<t.length;e++)this._fieldIds[t[e]]=e}};const De=t=>{const e=t.toLowerCase(),r=new Set([e]),i={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,n]of Object.entries(i))e.includes(t)&&n.forEach((i=>{r.add(e.replace(t,i))})),n.forEach((i=>{e.includes(i)&&r.add(e.replace(i,t))}));return Array.from(r)};var Ce;function Me(t){switch(t){case 0:case"LOCATION_TYPE_UNSPECIFIED":return Ce.LOCATION_TYPE_UNSPECIFIED;case 1:case"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM":return Ce.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case 2:case"LOCATION_TYPE_STATION":return Ce.LOCATION_TYPE_STATION;case 3:case"LOCATION_TYPE_ENTRANCE_EXIT":return Ce.LOCATION_TYPE_ENTRANCE_EXIT;case 4:case"LOCATION_TYPE_GENERIC_NODE":return Ce.LOCATION_TYPE_GENERIC_NODE;case 5:case"LOCATION_TYPE_BOARDING_AREA":return Ce.LOCATION_TYPE_BOARDING_AREA;default:return Ce.UNRECOGNIZED}}!function(t){t[t.LOCATION_TYPE_UNSPECIFIED=0]="LOCATION_TYPE_UNSPECIFIED",t[t.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM=1]="LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM",t[t.LOCATION_TYPE_STATION=2]="LOCATION_TYPE_STATION",t[t.LOCATION_TYPE_ENTRANCE_EXIT=3]="LOCATION_TYPE_ENTRANCE_EXIT",t[t.LOCATION_TYPE_GENERIC_NODE=4]="LOCATION_TYPE_GENERIC_NODE",t[t.LOCATION_TYPE_BOARDING_AREA=5]="LOCATION_TYPE_BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Ce||(Ce={}));const Ye={encode(t,e=new m){if(""!==t.name&&e.uint32(10).string(t.name),void 0!==t.sourceStopId&&e.uint32(18).string(t.sourceStopId),void 0!==t.lat&&e.uint32(29).float(t.lat),void 0!==t.lon&&e.uint32(37).float(t.lon),0!==t.children.length){e.uint32(42).fork();for(const r of t.children)e.uint32(r);e.join()}return void 0!==t.parent&&e.uint32(48).uint32(t.parent),0!==t.locationType&&e.uint32(56).int32(t.locationType),void 0!==t.platform&&e.uint32(66).string(t.platform),e},decode(t,e){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={name:"",sourceStopId:void 0,lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 1:if(10!==t)break;r.name=i.string();continue;case 2:if(18!==t)break;r.sourceStopId=i.string();continue;case 3:if(29!==t)break;r.lat=i.float();continue;case 4:if(37!==t)break;r.lon=i.float();continue;case 5:if(40===t){r.children.push(i.uint32());continue}if(42===t){const t=i.uint32()+i.pos;for(;i.pos<t;)r.children.push(i.uint32());continue}break;case 6:if(48!==t)break;r.parent=i.uint32();continue;case 7:if(56!==t)break;r.locationType=i.int32();continue;case 8:if(66!==t)break;r.platform=i.string();continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({name:$e(t.name)?globalThis.String(t.name):"",sourceStopId:$e(t.sourceStopId)?globalThis.String(t.sourceStopId):$e(t.source_stop_id)?globalThis.String(t.source_stop_id):void 0,lat:$e(t.lat)?globalThis.Number(t.lat):void 0,lon:$e(t.lon)?globalThis.Number(t.lon):void 0,children:globalThis.Array.isArray(null==t?void 0:t.children)?t.children.map((t=>globalThis.Number(t))):[],parent:$e(t.parent)?globalThis.Number(t.parent):void 0,locationType:$e(t.locationType)?Me(t.locationType):$e(t.location_type)?Me(t.location_type):0,platform:$e(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const r={};return""!==t.name&&(r.name=t.name),void 0!==t.sourceStopId&&(r.sourceStopId=t.sourceStopId),void 0!==t.lat&&(r.lat=Be(t.lat)),void 0!==t.lon&&(r.lon=Be(t.lon)),(null===(e=t.children)||void 0===e?void 0:e.length)&&(r.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(r.parent=Math.round(t.parent)),0!==t.locationType&&(r.locationType=function(t){switch(t){case Ce.LOCATION_TYPE_UNSPECIFIED:return"LOCATION_TYPE_UNSPECIFIED";case Ce.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM";case Ce.LOCATION_TYPE_STATION:return"LOCATION_TYPE_STATION";case Ce.LOCATION_TYPE_ENTRANCE_EXIT:return"LOCATION_TYPE_ENTRANCE_EXIT";case Ce.LOCATION_TYPE_GENERIC_NODE:return"LOCATION_TYPE_GENERIC_NODE";case Ce.LOCATION_TYPE_BOARDING_AREA:return"LOCATION_TYPE_BOARDING_AREA";case Ce.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(r.platform=t.platform),r},create:t=>Ye.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,i,n,o,s,a,u;const d={name:"",sourceStopId:void 0,lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};return d.name=null!==(e=t.name)&&void 0!==e?e:"",d.sourceStopId=null!==(r=t.sourceStopId)&&void 0!==r?r:void 0,d.lat=null!==(i=t.lat)&&void 0!==i?i:void 0,d.lon=null!==(n=t.lon)&&void 0!==n?n:void 0,d.children=(null===(o=t.children)||void 0===o?void 0:o.map((t=>t)))||[],d.parent=null!==(s=t.parent)&&void 0!==s?s:void 0,d.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,d.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,d}};const Fe={encode(t,e=new m){for(const r of t.stops)Ye.encode(r,e.uint32(18).fork()).join();return e},decode(t,e){var r;const i=t instanceof S?t:new S(t),n=null!==(r=i.__tsProtoDecodeDepth)&&void 0!==r?r:0;if(n>=100)throw new globalThis.Error("protobuf decode recursion limit exceeded");i.__tsProtoDecodeDepth=n+1;try{const t=void 0===e?i.len:i.pos+e,r={stops:[]};for(;i.pos<t;){const t=i.uint32();switch(t>>>3){case 2:if(18!==t)break;r.stops.push(Ye.decode(i,i.uint32()));continue}if(4==(7&t)||0===t)break;i.skip(7&t)}return r}finally{i.__tsProtoDecodeDepth=n}},fromJSON:t=>({stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>Ye.fromJSON(t))):[]}),toJSON(t){var e;const r={};return(null===(e=t.stops)||void 0===e?void 0:e.length)&&(r.stops=t.stops.map((t=>Ye.toJSON(t)))),r},create:t=>Fe.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={stops:[]};return r.stops=(null===(e=t.stops)||void 0===e?void 0:e.map((t=>Ye.fromPartial(t))))||[],r}};function Be(t){return"number"!=typeof t||globalThis.Number.isFinite(t)?t:globalThis.String(t)}function $e(t){return null!=t}const ke=t=>({stops:t.map((t=>{return{name:(e=t).name,sourceStopId:e.sourceStopId,lat:e.lat,lon:e.lon,children:e.children,parent:e.parent,locationType:Ge(e.locationType),platform:e.platform};var e}))}),je=t=>t.stops.map(((t,e)=>{return{id:e,sourceStopId:(r=t).sourceStopId,name:r.name,lat:r.lat,lon:r.lon,children:r.children,parent:r.parent,locationType:ze(r.locationType),platform:r.platform};var r})),ze=t=>{switch(t){case Ce.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Ce.LOCATION_TYPE_STATION:return"STATION";case Ce.LOCATION_TYPE_ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Ce.LOCATION_TYPE_GENERIC_NODE:return"GENERIC_NODE";case Ce.LOCATION_TYPE_BOARDING_AREA:return"BOARDING_AREA";case Ce.LOCATION_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf location type.");case Ce.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},Ge=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return Ce.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case"STATION":return Ce.LOCATION_TYPE_STATION;case"ENTRANCE_EXIT":return Ce.LOCATION_TYPE_ENTRANCE_EXIT;case"GENERIC_NODE":return Ce.LOCATION_TYPE_GENERIC_NODE;case"BOARDING_AREA":return Ce.LOCATION_TYPE_BOARDING_AREA}};class Ve{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const r=new Map;this.stopPoints=[];for(let i=0;i<t.length;i++){const n=t[i];void 0!==n.sourceStopId&&this.sourceStopsMap.set(n.sourceStopId,i);const o=null!==(e=n.parent)&&void 0!==e?e:i;r.has(o)||r.set(o,{id:o,name:n.parent?this.stops[n.parent].name:n.name}),n.lat&&n.lon&&this.stopPoints.push({id:i,lat:n.lat,lon:n.lon})}this.textIndex=(t=>new Le(t))({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:De});const i=Array.from(r.values());((t,e)=>{for(let r of e)Ae(t,r)})(this.textIndex,i),this.geoIndex=new Wt(this.stopPoints.length);for(let t=0;t<this.stopPoints.length;t++){const{lat:e,lon:r}=this.stopPoints[t];this.geoIndex.add(r,e)}this.geoIndex.finish()}static fromData(t){const e=new S(t),r=Fe.decode(e);return new Ve(je(r))}serialize(){const t=ke(this.stops),e=new m;return Fe.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){const r=((t,e,r={})=>{let{searchOptions:i}=t._options,n={...i,...r},o=xe(t,e,r),s=[];for(let[e,{score:r,terms:i,match:a}]of o){let o=i.length||1,u={id:t._documentIds.get(e),score:r*o,terms:Object.keys(a),queryTerms:i,match:a,...t._storedFields.get(e)};(null==n.filter||n.filter(u))&&s.push(u)}return e===we&&null==n.boostDocument||s.sort(fe),s})(this.textIndex,t).map((t=>this.stops[t.id]));return r.slice(0,e)}findStopsByLocation(t,e,r=5,i=.5){const n=function(t,e,r,i=1/0,n=1/0){let o=1;const s=[];void 0===i&&(i=1/0),void 0!==n&&(o=jt(n/6371));const a=new Ft([],kt);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const d=Math.cos(r*Bt);for(;u;){const n=u.right,c=u.left;if(n-c<=t.nodeSize)for(let i=c;i<=n;i++){const n=t.ids[i];{const o=Gt(e,r,t.coords[2*i],t.coords[2*i+1],d);a.push({id:n,dist:o})}}else{const i=c+n>>1,o=t.coords[2*i],s=t.coords[2*i+1],l=t.ids[i];{const t=Gt(e,r,o,s,d);a.push({id:l,dist:t})}const h=(u.axis+1)%2,p={left:c,right:i-1,axis:h,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?o:u.maxLng,maxLat:1===u.axis?s:u.maxLat,dist:0},f={left:i+1,right:n,axis:h,minLng:0===u.axis?o:u.minLng,minLat:1===u.axis?s:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};p.dist=$t(e,r,d,p),f.dist=$t(e,r,d,f),a.push(p),a.push(f)}let l;for(;(l=a.pop())&&"id"in l;){if(l.dist>o)return s;if(s.push(l.id),s.length===i)return s}u=l}return s}(this.geoIndex,e,t,r,i).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return n}findStopById(t){return this.stops[t]}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,r;const i=this.stops[t];if(!i)return[];const n=i.parent?null!==(r=null===(e=this.stops[i.parent])||void 0===e?void 0:e.children)&&void 0!==r?r:[]:i.children;return Array.from(new Set([t,...n])).map((t=>this.stops[t]))}*[Symbol.iterator](){for(const t of this.stops)yield t}}exports.Plotter=class{constructor(t){this.result=t}stationNodeId(t){return`s_${t}`}vehicleEdgeNodeId(t,e,r,i){return`e_${t}_${e}_${r}_${i}`}transferEdgeNodeId(t,e,r){return`e_${t}_${e}_${r}`}accessEdgeNodeId(t,e){return`access_${t}_${e}`}continuationNodeId(t,e,r){return`continuation_${t}_${e}_${r}`}getRoundColor(t){var e;if(0===t)return It.colors.defaultRound;const r=Math.min(t-1,It.colors.rounds.length-1);return null!==(e=It.colors.rounds[r])&&void 0!==e?e:"#ee82ee"}getStationFillColor(t,e){return t?It.colors.originStation:e?It.colors.destinationStation:It.colors.defaultStation}escapeDotString(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}formatStopName(t){const e=this.result.stopsIndex.findStopById(t);if(!e)return`Unknown Stop (${t})`;const r=this.escapeDotString(e.name),i=e.platform?this.escapeDotString(e.platform):"";return i?`${r}\\nPl. ${i}`:r}getStationInfo(t){var e;return{isOrigin:void 0!==(null===(e=this.result.routingState.graph[0])||void 0===e?void 0:e[t]),isDestination:this.result.routingState.destinations.includes(t)}}getVehicleEdgeFromStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.stopIndex)}getVehicleEdgeToStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.hopOffStopIndex)}createStationNode(t){if(!this.result.stopsIndex.findStopById(t))return null;const e=this.formatStopName(t),r=this.escapeDotString(String(t)),i=this.stationNodeId(t),n=this.getStationInfo(t);return` "${i}" [label="${e}\\n${r}" shape=box style=filled fillcolor="${this.getStationFillColor(n.isOrigin,n.isDestination)}"];`}createVehicleEdge(e,r){const i=this.result.timetable.getRoute(e.routeId);if(!i)return[];const n=i.stopId(e.stopIndex),o=i.stopId(e.hopOffStopIndex),s=this.stationNodeId(n),a=this.stationNodeId(o),u=this.getRoundColor(r),d=this.vehicleEdgeNodeId(n,o,e.routeId,r),c=this.result.timetable.getServiceRouteInfo(i),l=c.name,h=Et(c.type),p=t(i.departureFrom(e.stopIndex,e.tripIndex)),f=t(e.arrival),T=this.escapeDotString(l);return[` "${d}" [label="${`${this.escapeDotString(h)} ${T}\\n${`${e.routeId}:${e.tripIndex}`}\\n${p} → ${f}`}" shape=oval style=filled fillcolor="white" color="${u}"];`,` "${s}" -> "${d}" [color="${u}"];`,` "${d}" -> "${a}" [color="${u}"];`]}createAccessEdge(t){const r=this.stationNodeId(t.from),i=this.stationNodeId(t.to),n=It.colors.defaultRound,o=this.accessEdgeNodeId(t.from,t.to);return[` "${o}" [label="${`Walk\\n${e(t.duration)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${n}"];`,` "${r}" -> "${o}" [color="${n}" style="dashed"];`,` "${o}" -> "${i}" [color="${n}" style="dashed"];`]}createTransferEdge(t,r){const i=this.stationNodeId(t.from),n=this.stationNodeId(t.to),o=this.getRoundColor(r),s=this.transferEdgeNodeId(t.from,t.to,r),a=void 0!==t.minTransferTime?e(t.minTransferTime):"N/A";return[` "${s}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${o}"];`,` "${i}" -> "${s}" [color="${o}" style="dashed"];`,` "${s}" -> "${n}" [color="${o}" style="dashed"];`]}createContinuationEdge(e,r,i){var n,o;const s=this.getVehicleEdgeToStopId(e),a=this.getVehicleEdgeFromStopId(r);if(!s||!a)return[];const u=this.stationNodeId(s),d=this.stationNodeId(a),c=this.getRoundColor(i),l=this.continuationNodeId(s,a,i),h=this.result.timetable.getRoute(e.routeId),p=this.result.timetable.getRoute(r.routeId),f=h?this.result.timetable.getServiceRouteInfo(h):null,T=p?this.result.timetable.getServiceRouteInfo(p):null,_=null!==(n=null==f?void 0:f.name)&&void 0!==n?n:`Route ${String(e.routeId)}`,E=null!==(o=null==T?void 0:T.name)&&void 0!==o?o:`Route ${String(r.routeId)}`,m=f?Et(f.type):"UNKNOWN",I=T?Et(T.type):"UNKNOWN",g=t(e.arrival),v=p?t(p.departureFrom(r.stopIndex,r.tripIndex)):"N/A",R=this.escapeDotString(_),A=this.escapeDotString(E),y=this.escapeDotString(m),S=this.escapeDotString(I),O=`${y} ${R} (${`${e.routeId}:${e.tripIndex}`}) ${g}\\n↓\\n${S} ${A} (${`${r.routeId}:${r.tripIndex}`}) ${v}`,{continuationFill:N}=It.colors,{continuation:b,continuationEdge:w}=It.penWidth;return[` "${l}" [label="${O}" shape=oval style="filled,bold" fillcolor="${N}" color="${c}" penwidth="${b}"];`,` "${u}" -> "${l}" [color="${c}" style="bold" penwidth="${w}"];`,` "${l}" -> "${d}" [color="${c}" style="bold" penwidth="${w}"];`]}collectStations(){const t=new Set,e=this.result.routingState.graph;for(const r of e)for(let e=0;e<r.length;e++){const i=r[e];if(void 0!==i)if(t.add(e),gt(i)){const e=this.getVehicleEdgeFromStopId(i),r=this.getVehicleEdgeToStopId(i);e&&t.add(e),r&&t.add(r)}else Rt(i)&&(t.add(i.from),t.add(i.to))}return t}collectContinuationChain(t,e){const r=[];let i=t,n=t.continuationOf;for(;n;){const t=this.createContinuationEdge(n,i,e);r.push(...t),i=n,n=n.continuationOf}return r}collectEdges(){const t=[],e=[],r=this.result.routingState.graph;for(let i=0;i<r.length;i++){const n=r[i];if(n)for(let r=0;r<n.length;r++){const o=n[r];void 0!==o&&(0!==i?gt(o)?(t.push(...this.createVehicleEdge(o,i)),o.continuationOf&&e.push(...this.collectContinuationChain(o,i))):vt(o)&&t.push(...this.createTransferEdge(o,i)):Rt(o)&&t.push(...this.createAccessEdge(o)))}}return[...t,...e]}plotDotGraph(){const t=this.collectStations(),e=this.collectEdges(),r=new At;r.addHeader(),r.addComment("Stations");for(const e of t){const t=this.createStationNode(e);t&&r.addRaw([t])}return r.addComment("Edges"),r.addRaw(e),r.build()}},exports.Query=yt,exports.RangeQuery=St,exports.RangeResult=Dt,exports.Result=wt,exports.Route=Ot,exports.Router=class{constructor(t,e){const r=new Yt(t),i=new Pt(t,e);this.plainRouter=new Lt(t,e,i,r),this.rangeRouter=new Mt(t,e,i,r)}route(t){return this.plainRouter.route(t)}rangeRoute(t){return this.rangeRouter.rangeRoute(t)}},exports.StopsIndex=Ve,exports.Timetable=_t;
2
2
  //# sourceMappingURL=router.cjs.js.map