minotor 5.0.1 → 7.0.0
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.
- package/CHANGELOG.md +8 -3
- package/dist/cli.mjs +282 -654
- package/dist/cli.mjs.map +1 -1
- package/dist/gtfs/parser.d.ts +4 -10
- package/dist/gtfs/routes.d.ts +16 -2
- package/dist/gtfs/stops.d.ts +3 -13
- package/dist/gtfs/transfers.d.ts +2 -2
- package/dist/gtfs/trips.d.ts +12 -8
- package/dist/parser.cjs.js +257 -644
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.esm.js +257 -644
- package/dist/parser.esm.js.map +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.esm.js +1 -1
- package/dist/router.esm.js.map +1 -1
- package/dist/router.umd.js +1 -1
- package/dist/router.umd.js.map +1 -1
- package/dist/stops/io.d.ts +3 -3
- package/dist/stops/proto/stops.d.ts +1 -8
- package/dist/stops/stops.d.ts +0 -4
- package/dist/stops/stopsIndex.d.ts +3 -3
- package/dist/timetable/io.d.ts +6 -6
- package/dist/timetable/proto/timetable.d.ts +5 -27
- package/dist/timetable/route.d.ts +2 -11
- package/dist/timetable/timetable.d.ts +17 -9
- package/package.json +1 -1
- package/src/__e2e__/timetable/stops.bin +2 -2
- package/src/__e2e__/timetable/timetable.bin +2 -2
- package/src/cli/minotor.ts +3 -4
- package/src/gtfs/__tests__/parser.test.ts +5 -6
- package/src/gtfs/__tests__/routes.test.ts +0 -3
- package/src/gtfs/__tests__/stops.test.ts +1 -124
- package/src/gtfs/__tests__/transfers.test.ts +7 -7
- package/src/gtfs/__tests__/trips.test.ts +74 -45
- package/src/gtfs/parser.ts +32 -49
- package/src/gtfs/routes.ts +43 -5
- package/src/gtfs/stops.ts +2 -44
- package/src/gtfs/transfers.ts +2 -2
- package/src/gtfs/trips.ts +66 -43
- package/src/routing/__tests__/result.test.ts +48 -48
- package/src/routing/__tests__/router.test.ts +279 -363
- package/src/routing/router.ts +22 -8
- package/src/stops/__tests__/io.test.ts +25 -31
- package/src/stops/__tests__/stopFinder.test.ts +82 -103
- package/src/stops/io.ts +8 -17
- package/src/stops/proto/stops.proto +3 -3
- package/src/stops/proto/stops.ts +16 -120
- package/src/stops/stops.ts +0 -4
- package/src/stops/stopsIndex.ts +37 -41
- package/src/timetable/__tests__/io.test.ts +44 -54
- package/src/timetable/__tests__/route.test.ts +10 -29
- package/src/timetable/__tests__/timetable.test.ts +29 -37
- package/src/timetable/io.ts +66 -74
- package/src/timetable/proto/timetable.proto +7 -14
- package/src/timetable/proto/timetable.ts +49 -391
- package/src/timetable/route.ts +2 -32
- package/src/timetable/timetable.ts +51 -31
package/dist/router.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";class t{constructor(t){this.totalSeconds=t}static fromSeconds(e){return new t(e)}static fromMinutes(e){return new t(60*e)}static zero(){return new t(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),r=this.totalSeconds%60;return t>0?`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`}toSeconds(){return this.totalSeconds}add(e){const r=this.totalSeconds+e.toSeconds();return new t(r)}subtract(e){const r=Math.max(0,this.totalSeconds-e.toSeconds());return new t(r)}}function e(){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 r(t,e,r){for(let n=0;n<28;n+=7){const s=t>>>n,o=!(s>>>7==0&&0==e),i=255&(o?128|s:s);if(r.push(i),!o)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),o=255&(s?128|n:n);if(r.push(o),!s)return}r.push(e>>>31&1)}}"function"==typeof SuppressedError&&SuppressedError;const n=4294967296;function s(t){const e="-"===t[0];e&&(t=t.slice(1));const r=1e6;let s=0,o=0;function u(e,i){const a=Number(t.slice(e,i));o*=r,s=s*r+a,s>=n&&(o+=s/n|0,s%=n)}return u(-24,-18),u(-18,-12),u(-12,-6),u(-6),e?a(s,o):i(s,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(n*e+t);const r=16777215&(t>>>24|e<<8),s=e>>16&65535;let o=(16777215&t)+6777216*r+6710656*s,i=r+8147497*s,a=2*s;const c=1e7;return o>=c&&(i+=Math.floor(o/c),o%=c),i>=c&&(a+=Math.floor(i/c),i%=c),a.toString()+u(i)+u(o)}function i(t,e){return{lo:0|t,hi:0|e}}function a(t,e){return e=~e,t?t=1+~t:e+=1,i(t,e)}const u=t=>{const e=String(t);return"0000000".slice(e.length)+e};function c(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 f=d();function d(){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&&("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()),h(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),h(t),s(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),p(t),s(t)),dec:(t,e)=>function(t,e){let r=i(t,e);const n=2147483648&r.hi;n&&(r=a(r.lo,r.hi));const s=o(r.lo,r.hi);return n?"-"+s:s}(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)}const m=Symbol.for("@bufbuild/protobuf/text-encoding");function v(){if(null==globalThis[m]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[m]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[m]}var g;!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"}(g||(g={}));const T=34028234663852886e22,y=-34028234663852886e22;class E{constructor(t=v().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(w(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return A(t),c(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||t<y))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){w(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){A(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return A(t),c(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),r=new DataView(e.buffer),n=f.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=f.uEnc(t);return r.setInt32(0,n.lo,!0),r.setInt32(4,n.hi,!0),this.raw(e)}int64(t){let e=f.enc(t);return r(e.lo,e.hi,this.buf),this}sint64(t){const e=f.enc(t),n=e.hi>>31;return r(e.lo<<1^n,(e.hi<<1|e.lo>>>31)^n,this.buf),this}uint64(t){const e=f.uEnc(t);return r(e.lo,e.hi,this.buf),this}}class I{constructor(t,r=v().decodeUtf8){this.decodeUtf8=r,this.varint64=e,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 g.Varint:for(;128&this.buf[this.pos++];);break;case g.Bit64:this.pos+=4;case g.Bit32:this.pos+=4;break;case g.LengthDelimited:let r=this.uint32();this.pos+=r;break;case g.StartGroup:for(;;){const[t,r]=this.tag();if(r===g.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 f.dec(...this.varint64())}uint64(){return f.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),r=-(1&t);return t=(t>>>1|(1&e)<<31)^r,e=e>>>1^r,f.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 f.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return f.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 A(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 w(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,b;function R(t){switch(t){case 0:case"RECOMMENDED_TRANSFER_POINT":return S.RECOMMENDED_TRANSFER_POINT;case 1:case"TIMED_TRANSFER":return S.TIMED_TRANSFER;case 2:case"REQUIRES_MINIMAL_TIME":return S.REQUIRES_MINIMAL_TIME;case 3:case"IN_SEAT_TRANSFER":return S.IN_SEAT_TRANSFER;default:return S.UNRECOGNIZED}}function _(t){switch(t){case 0:case"TRAM":return b.TRAM;case 1:case"SUBWAY":return b.SUBWAY;case 2:case"RAIL":return b.RAIL;case 3:case"BUS":return b.BUS;case 4:case"FERRY":return b.FERRY;case 5:case"CABLE_TRAM":return b.CABLE_TRAM;case 6:case"AERIAL_LIFT":return b.AERIAL_LIFT;case 7:case"FUNICULAR":return b.FUNICULAR;case 8:case"TROLLEYBUS":return b.TROLLEYBUS;case 9:case"MONORAIL":return b.MONORAIL;default:return b.UNRECOGNIZED}}function N(){return{stopTimes:new Uint8Array(0),pickUpDropOffTypes:new Uint8Array(0),stops:new Uint8Array(0),serviceRouteId:""}}!function(t){t[t.RECOMMENDED_TRANSFER_POINT=0]="RECOMMENDED_TRANSFER_POINT",t[t.TIMED_TRANSFER=1]="TIMED_TRANSFER",t[t.REQUIRES_MINIMAL_TIME=2]="REQUIRES_MINIMAL_TIME",t[t.IN_SEAT_TRANSFER=3]="IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(S||(S={})),function(t){t[t.TRAM=0]="TRAM",t[t.SUBWAY=1]="SUBWAY",t[t.RAIL=2]="RAIL",t[t.BUS=3]="BUS",t[t.FERRY=4]="FERRY",t[t.CABLE_TRAM=5]="CABLE_TRAM",t[t.AERIAL_LIFT=6]="AERIAL_LIFT",t[t.FUNICULAR=7]="FUNICULAR",t[t.TROLLEYBUS=8]="TROLLEYBUS",t[t.MONORAIL=9]="MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(b||(b={}));const O={encode:(t,e=new E)=>(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),""!==t.serviceRouteId&&e.uint32(34).string(t.serviceRouteId),e),decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s=N();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(34!==t)break;s.serviceRouteId=r.string();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stopTimes:$(t.stopTimes)?P(t.stopTimes):new Uint8Array(0),pickUpDropOffTypes:$(t.pickUpDropOffTypes)?P(t.pickUpDropOffTypes):new Uint8Array(0),stops:$(t.stops)?P(t.stops):new Uint8Array(0),serviceRouteId:$(t.serviceRouteId)?globalThis.String(t.serviceRouteId):""}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=C(t.stopTimes)),0!==t.pickUpDropOffTypes.length&&(e.pickUpDropOffTypes=C(t.pickUpDropOffTypes)),0!==t.stops.length&&(e.stops=C(t.stops)),""!==t.serviceRouteId&&(e.serviceRouteId=t.serviceRouteId),e},create:t=>O.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s;const o=N();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!==(n=t.stops)&&void 0!==n?n:new Uint8Array(0),o.serviceRouteId=null!==(s=t.serviceRouteId)&&void 0!==s?s:"",o}};const M={encode:(t,e=new E)=>(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 I?t:new I(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:$(t.destination)?globalThis.Number(t.destination):0,type:$(t.type)?R(t.type):0,minTransferTime:$(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.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED_TRANSFER_POINT";case S.TIMED_TRANSFER:return"TIMED_TRANSFER";case S.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case S.IN_SEAT_TRANSFER:return"IN_SEAT_TRANSFER";case S.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>M.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 k={encode:(t,e=new E)=>(Object.entries(t.stops).forEach((([t,r])=>{U.encode({key:t,value:r},e.uint32(10).fork()).join()})),e),decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={stops:{}};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=U.decode(r,r.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stops:j(t.stops)?Object.entries(t.stops).reduce(((t,[e,r])=>(t[globalThis.Number(e)]=L.fromJSON(r),t)),{}):{}}),toJSON(t){const e={};if(t.stops){const r=Object.entries(t.stops);r.length>0&&(e.stops={},r.forEach((([t,r])=>{e.stops[t]=L.toJSON(r)})))}return e},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={stops:{}};return r.stops=Object.entries(null!==(e=t.stops)&&void 0!==e?e:{}).reduce(((t,[e,r])=>(void 0!==r&&(t[globalThis.Number(e)]=L.fromPartial(r)),t)),{}),r}};const L={encode(t,e=new E){for(const r of t.transfers)M.encode(r,e.uint32(10).fork()).join();e.uint32(18).fork();for(const r of t.routes)e.int32(r);return e.join(),e},decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={transfers:[],routes:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.transfers.push(M.decode(r,r.uint32()));continue;case 2:if(16===t){s.routes.push(r.int32());continue}if(18===t){const t=r.uint32()+r.pos;for(;r.pos<t;)s.routes.push(r.int32());continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>M.fromJSON(t))):[],routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[]}),toJSON(t){var e,r;const n={};return(null===(e=t.transfers)||void 0===e?void 0:e.length)&&(n.transfers=t.transfers.map((t=>M.toJSON(t)))),(null===(r=t.routes)||void 0===r?void 0:r.length)&&(n.routes=t.routes.map((t=>Math.round(t)))),n},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={transfers:[],routes:[]};return n.transfers=(null===(e=t.transfers)||void 0===e?void 0:e.map((t=>M.fromPartial(t))))||[],n.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],n}};const U={encode:(t,e=new E)=>(0!==t.key&&e.uint32(8).uint32(t.key),void 0!==t.value&&L.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={key:0,value:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.key=r.uint32();continue;case 2:if(18!==t)break;s.value=L.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({key:$(t.key)?globalThis.Number(t.key):0,value:$(t.value)?L.fromJSON(t.value):void 0}),toJSON(t){const e={};return 0!==t.key&&(e.key=Math.round(t.key)),void 0!==t.value&&(e.value=L.toJSON(t.value)),e},create:t=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={key:0,value:void 0};return r.key=null!==(e=t.key)&&void 0!==e?e:0,r.value=void 0!==t.value&&null!==t.value?L.fromPartial(t.value):void 0,r}};const x={encode(t,e=new E){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.int32(r);return e.join(),e},decode(t,e){const r=t instanceof I?t:new I(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.int32());continue}if(26===t){const t=r.uint32()+r.pos;for(;r.pos<t;)s.routes.push(r.int32());continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({type:$(t.type)?_(t.type):0,name:$(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 b.TRAM:return"TRAM";case b.SUBWAY:return"SUBWAY";case b.RAIL:return"RAIL";case b.BUS:return"BUS";case b.FERRY:return"FERRY";case b.CABLE_TRAM:return"CABLE_TRAM";case b.AERIAL_LIFT:return"AERIAL_LIFT";case b.FUNICULAR:return"FUNICULAR";case b.TROLLEYBUS:return"TROLLEYBUS";case b.MONORAIL:return"MONORAIL";case b.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=>x.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 D={encode:(t,e=new E)=>(Object.entries(t.routes).forEach((([t,r])=>{B.encode({key:t,value:r},e.uint32(10).fork()).join()})),e),decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={routes:{}};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=B.decode(r,r.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({routes:j(t.routes)?Object.entries(t.routes).reduce(((t,[e,r])=>(t[e]=x.fromJSON(r),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const r=Object.entries(t.routes);r.length>0&&(e.routes={},r.forEach((([t,r])=>{e.routes[t]=x.toJSON(r)})))}return e},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={routes:{}};return r.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,r])=>(void 0!==r&&(t[e]=x.fromPartial(r)),t)),{}),r}};const B={encode:(t,e=new E)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&x.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={key:"",value:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=r.string();continue;case 2:if(18!==t)break;s.value=x.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({key:$(t.key)?globalThis.String(t.key):"",value:$(t.value)?x.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=x.toJSON(t.value)),e},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={key:"",value:void 0};return r.key=null!==(e=t.key)&&void 0!==e?e:"",r.value=void 0!==t.value&&null!==t.value?x.fromPartial(t.value):void 0,r}};const F={encode(t,e=new E){""!==t.version&&e.uint32(10).string(t.version),void 0!==t.stopsAdjacency&&k.encode(t.stopsAdjacency,e.uint32(18).fork()).join();for(const r of t.routesAdjacency)O.encode(r,e.uint32(26).fork()).join();return void 0!==t.routes&&D.encode(t.routes,e.uint32(34).fork()).join(),e},decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={version:"",stopsAdjacency:void 0,routesAdjacency:[],routes:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=r.string();continue;case 2:if(18!==t)break;s.stopsAdjacency=k.decode(r,r.uint32());continue;case 3:if(26!==t)break;s.routesAdjacency.push(O.decode(r,r.uint32()));continue;case 4:if(34!==t)break;s.routes=D.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({version:$(t.version)?globalThis.String(t.version):"",stopsAdjacency:$(t.stopsAdjacency)?k.fromJSON(t.stopsAdjacency):void 0,routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>O.fromJSON(t))):[],routes:$(t.routes)?D.fromJSON(t.routes):void 0}),toJSON(t){var e;const r={};return""!==t.version&&(r.version=t.version),void 0!==t.stopsAdjacency&&(r.stopsAdjacency=k.toJSON(t.stopsAdjacency)),(null===(e=t.routesAdjacency)||void 0===e?void 0:e.length)&&(r.routesAdjacency=t.routesAdjacency.map((t=>O.toJSON(t)))),void 0!==t.routes&&(r.routes=D.toJSON(t.routes)),r},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={version:"",stopsAdjacency:void 0,routesAdjacency:[],routes:void 0};return n.version=null!==(e=t.version)&&void 0!==e?e:"",n.stopsAdjacency=void 0!==t.stopsAdjacency&&null!==t.stopsAdjacency?k.fromPartial(t.stopsAdjacency):void 0,n.routesAdjacency=(null===(r=t.routesAdjacency)||void 0===r?void 0:r.map((t=>O.fromPartial(t))))||[],n.routes=void 0!==t.routes&&null!==t.routes?D.fromPartial(t.routes):void 0,n}};function P(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 C(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"object"==typeof t&&null!==t}function $(t){return null!=t}class z{static infinity(){return new z(Number.MAX_SAFE_INTEGER)}static origin(){return new z(0)}constructor(t){this.minutesSinceMidnight=t}static fromMinutes(t){return new z(t)}static fromHMS(t,e,r){if(t<0||e<0||r<0||e>=60||r>=60)throw new Error("Invalid time. Ensure hours, minutes, and seconds are valid values.");const n=r+60*e+3600*t,s=Math.round(n/60);return new z(s)}static fromHM(t,e){if(t<0||e<0||e>=60)throw new Error("Invalid time. Ensure hours and minutes are valid values.");return new z(e+60*t)}static fromDate(t){const e=t.getHours(),r=t.getMinutes(),n=t.getSeconds();return z.fromHMS(e,r,n)}static fromString(t){const[e,r,n]=t.split(":");if(void 0===e||void 0===r||""===e.trim()||""===r.trim()||isNaN(Number(e))||isNaN(Number(r))||void 0!==n&&(""===n.trim()||isNaN(Number(n))))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const s=parseInt(e,10),o=parseInt(r,10),i=void 0!==n?parseInt(n,10):0;return z.fromHMS(s,o,i)}toString(){let t=Math.floor(this.minutesSinceMidnight/60);const e=Math.floor(this.minutesSinceMidnight%60);return t>=24&&(t%=24),`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}toMinutes(){return this.minutesSinceMidnight}plus(t){const e=60*this.minutesSinceMidnight+t.toSeconds();return new z(Math.round(e/60))}minus(t){let e=60*this.minutesSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new z(Math.round(e/60))}diff(e){const r=this.minutesSinceMidnight-e.toMinutes();return t.fromSeconds(Math.abs(60*r))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.isAfter(t)?e:t))}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.isBefore(t)?e:t))}isAfter(t){return this.minutesSinceMidnight>t.toMinutes()}isBefore(t){return this.minutesSinceMidnight<t.toMinutes()}equals(t){return this.minutesSinceMidnight===t.toMinutes()}}const G=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],J=t=>{const e=G[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};let V=class{constructor(t,e,r,n){this.stopTimes=t,this.pickUpDropOffTypes=e,this.stops=r,this.serviceRouteId=n,this.nbStops=r.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<r.length;t++)this.stopIndices.set(r[t],t)}serialize(){return{stopTimes:this.stopTimes,pickUpDropOffTypes:this.pickUpDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}isBefore(t,e){const r=this.stopIndices.get(t);if(void 0===r)throw new Error(`Stop index ${r} not found in route ${this.serviceRouteId}`);const n=this.stopIndices.get(e);if(void 0===n)throw new Error(`Stop index ${n} not found in route ${this.serviceRouteId}`);return r<n}getNbStops(){return this.nbStops}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const r=2*(e*this.stops.length+this.stopIndex(t)),n=this.stopTimes[r];if(void 0===n)throw new Error(`Arrival time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return z.fromMinutes(n)}departureFrom(t,e){const r=2*(e*this.stops.length+this.stopIndex(t))+1,n=this.stopTimes[r];if(void 0===n)throw new Error(`Departure time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return z.fromMinutes(n)}pickUpTypeFrom(t,e){const r=e*this.stops.length+this.stopIndex(t),n=Math.floor(r/2),s=r%2==1,o=this.pickUpDropOffTypes[n];if(void 0===o)throw new Error(`Pick up type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return J(s?o>>6&3:o>>2&3)}dropOffTypeAt(t,e){const r=e*this.stops.length+this.stopIndex(t),n=Math.floor(r/2),s=r%2==1,o=this.pickUpDropOffTypes[n];if(void 0===o)throw new Error(`Drop off type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return J(s?o>>4&3:3&o)}stopsIterator(t){const e=void 0!==t?this.stopIndices.get(t):0;if(void 0===e)throw new Error(`Start stop ${t} not found in route ${this.serviceRouteId}`);return function*(t,e){for(let r=e;r<t.length;r++)yield t[r]}(this.stops,e)}findEarliestTrip(t,e=z.origin(),r){const n=void 0!==r?Math.min(r-1,this.nbTrips-1):this.nbTrips-1;if(n<0)return;let s,o=0,i=n;for(;o<=i;){const r=Math.floor((o+i)/2),n=this.departureFrom(t,r),a=this.pickUpTypeFrom(t,r);(n.isAfter(e)||n.equals(e))&&"NOT_AVAILABLE"!==a?(s=r,i=r-1):o=r+1}return s}stopIndex(t){const e=this.stopIndices.get(t);if(void 0===e)throw new Error(`Stop index for ${t} not found in route ${this.serviceRouteId}`);return e}};const Y=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),W=!0,q=t=>{if(Y===W)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],W);return e},Z=t=>{if(Y===W)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],W);return e},H=t=>{const e={stops:{}};return t.forEach(((t,r)=>{e.stops[r]={transfers:t.transfers.map((t=>Object.assign({destination:t.destination,type:et(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))),routes:t.routes}})),e},Q=t=>{const e=[];return t.forEach((t=>{const r=t.serialize();e.push({stopTimes:Z(r.stopTimes),pickUpDropOffTypes:r.pickUpDropOffTypes,stops:q(r.stops),serviceRouteId:r.serviceRouteId})})),e},X=t=>{const e={routes:{}};return t.forEach(((t,r)=>{e.routes[r]={type:nt(t.type),name:t.name,routes:t.routes}})),e},K=t=>{const e=[];return t.forEach((t=>{const r=(t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(Y===W)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,W);return e})(t.stops);e.push(new V((t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(Y===W)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,W);return e})(t.stopTimes),t.pickUpDropOffTypes,r,t.serviceRouteId))})),e},tt=t=>{switch(t){case S.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case S.TIMED_TRANSFER:return"GUARANTEED";case S.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case S.IN_SEAT_TRANSFER:return"IN_SEAT";case S.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},et=t=>{switch(t){case"RECOMMENDED":return S.RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return S.TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return S.REQUIRES_MINIMAL_TIME;case"IN_SEAT":return S.IN_SEAT_TRANSFER}},rt=t=>{switch(t){case b.TRAM:return"TRAM";case b.SUBWAY:return"SUBWAY";case b.RAIL:return"RAIL";case b.BUS:return"BUS";case b.FERRY:return"FERRY";case b.CABLE_TRAM:return"CABLE_TRAM";case b.AERIAL_LIFT:return"AERIAL_LIFT";case b.FUNICULAR:return"FUNICULAR";case b.TROLLEYBUS:return"TROLLEYBUS";case b.MONORAIL:return"MONORAIL";case b.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},nt=t=>{switch(t){case"TRAM":return b.TRAM;case"SUBWAY":return b.SUBWAY;case"RAIL":return b.RAIL;case"BUS":return b.BUS;case"FERRY":return b.FERRY;case"CABLE_TRAM":return b.CABLE_TRAM;case"AERIAL_LIFT":return b.AERIAL_LIFT;case"FUNICULAR":return b.FUNICULAR;case"TROLLEYBUS":return b.TROLLEYBUS;case"MONORAIL":return b.MONORAIL}},st=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),ot="0.0.5";class it{constructor(t,e,r){this.stopsAdjacency=t,this.routesAdjacency=e,this.routes=r}serialize(){const t={version:ot,stopsAdjacency:H(this.stopsAdjacency),routesAdjacency:Q(this.routesAdjacency),routes:X(this.routes)},e=new E;return F.encode(t,e),e.finish()}static fromData(e){const r=new I(e),n=F.decode(r);if(n.version!==ot)throw new Error(`Unsupported timetable version ${n.version}`);return new it((e=>{const r=new Map;return Object.entries(e.stops).forEach((([e,n])=>{const s=parseInt(e,10);r.set(s,{transfers:n.transfers.map((e=>Object.assign({destination:e.destination,type:tt(e.type)},void 0!==e.minTransferTime&&{minTransferTime:t.fromSeconds(e.minTransferTime)}))),routes:n.routes})})),r})(n.stopsAdjacency),K(n.routesAdjacency),(t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,r])=>{e.set(t,{type:rt(r.type),name:r.name,routes:r.routes})})),e})(n.routes))}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){var e,r;return null!==(r=null===(e=this.stopsAdjacency.get(t))||void 0===e?void 0:e.transfers)&&void 0!==r?r:[]}getServiceRouteInfo(t){const e=this.routes.get(t.serviceRoute());if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);const{routes:r}=e;return function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(r[n[s]]=t[n[s]])}return r}(e,["routes"])}routesPassingThrough(t){const e=this.stopsAdjacency.get(t);if(!e)return[];const r=[];for(const t of e.routes){const e=this.routesAdjacency[t];e&&r.push(e)}return r}findReachableRoutes(t,e=st){const r=new Map;for(const n of t){const t=this.routesPassingThrough(n).filter((t=>{const r=this.getServiceRouteInfo(t);return e.has(r.type)}));for(const e of t){const t=r.get(e);t?e.isBefore(n,t)&&r.set(e,n):r.set(e,n)}}return r}}class at{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}at.Builder=class{constructor(){this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:t.fromSeconds(120),transportModes:st}}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}build(){return new at(this)}};class ut{constructor(t){this.legs=t}departureTime(){const e=t.zero();for(let t=0;t<this.legs.length;t++){const r=this.legs[t];if("departureTime"in r)return r.departureTime.minus(e);"minTransferTime"in r&&r.minTransferTime&&e.add(r.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let e=z.origin();const r=t.zero();let n=!1;for(let t=this.legs.length-1;t>=0;t--){const s=this.legs[t];"arrivalTime"in s&&!n?(e=s.arrivalTime,n=!0):"minTransferTime"in s&&s.minTransferTime&&n&&r.add(s.minTransferTime)}if(!n)throw new Error("No vehicle leg found in route");return e.plus(r)}totalDuration(){return 0===this.legs.length?t.zero():this.arrivalTime().diff(this.departureTime())}toString(){return this.legs.map(((t,e)=>{var r;const n=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,s=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,o="minTransferTime"in t?`Minimum Transfer Time: ${null===(r=t.minTransferTime)||void 0===r?void 0:r.toString()}`:"",i="route"in t&&"departureTime"in t&&"arrivalTime"in t?`Route: ${t.route.type} ${t.route.name}, Departure: ${t.departureTime.toString()}, Arrival: ${t.arrivalTime.toString()}`:"";return[`Leg ${e+1}:`,` ${n}`,` ${s}`,o?` ${o}`:"",i?` ${i}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}asJson(){return this.legs.map((t=>"route"in t?{from:t.from.sourceStopId,to:t.to.sourceStopId,departure:t.departureTime.toString(),arrival:t.arrivalTime.toString(),route:t.route}:Object.assign({from:t.from.sourceStopId,to:t.to.sourceStopId,type:t.type},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toString()})))}}class ct{constructor(t,e,r,n){this.query=t,this.earliestArrivals=e,this.earliestArrivalsPerRound=r,this.stopsIndex=n}bestRoute(t){var e,r,n;const s=(t instanceof Set?Array.from(t):t?[t]:Array.from(this.query.to)).flatMap((t=>this.stopsIndex.equivalentStops(t)));let o,i;for(const t of s){const e=this.earliestArrivals.get(t.id);void 0!==e&&(void 0===i||e.arrival.isBefore(i.arrival))&&(o=t.id,i=e)}if(!o||!i)return;const a=[];let u=o,c=i.legNumber;for(;i.origin!==u;){const t=null===(e=this.earliestArrivalsPerRound[c])||void 0===e?void 0:e.get(u);if(!(null==t?void 0:t.leg))throw new Error(`No leg found for a trip leg: start stop=${null!==(n=null===(r=null==t?void 0:t.leg)||void 0===r?void 0:r.from.id)&&void 0!==n?n:"unknown"}, end stop=${u}, round=${c}, origin=${i.origin}`);a.unshift(t.leg),u=t.leg.from.id,"route"in t.leg&&(c-=1)}return new ut(a)}arrivalAt(t,e){const r=this.stopsIndex.equivalentStops(t);let n;const s=void 0!==e?this.earliestArrivalsPerRound[e+1]:this.earliestArrivals;for(const t of r){const e=s.get(t.id);void 0!==e&&(void 0===n||e.arrival.isBefore(n.arrival))&&(n=e)}return n}}const lt=z.infinity();class ft{constructor(t=[],e=dt){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,o=e[s];if(r(n,o)>=0)break;e[t]=o,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),o=e[n];const i=n+1;if(i<this.length&&r(e[i],o)<0&&(n=i,o=e[i]),r(o,s)>=0)break;e[t]=o,t=n}e[t]=s}}function dt(t,e){return t<e?-1:t>e?1:0}const ht=Math.PI/180;function pt(t,e,r,n){const s=n.minLng,o=n.maxLng,i=n.minLat,a=n.maxLat;if(t>=s&&t<=o)return e<i?vt((e-i)*ht):e>a?vt((e-a)*ht):0;const u=Math.min(vt((t-s)*ht),vt((t-o)*ht)),c=function(t,e){const r=1-2*e;return r<=0?t>0?90:-90:Math.atan(Math.tan(t*ht)/r)/ht}(e,u);return c>i&&c<a?gt(u,r,e,c):Math.min(gt(u,r,e,i),gt(u,r,e,a))}function mt(t,e){return t.dist-e.dist}function vt(t){const e=Math.sin(t/2);return e*e}function gt(t,e,r,n){return e*Math.cos(n*ht)*t+vt((r-n)*ht)}function Tt(t,e,r,n,s){return gt(vt((t-r)*ht),s,e,n)}const yt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class Et{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=yt[15&r];if(!s)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[i]=new Uint32Array(t,4,1);return new Et(i,o,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=yt.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,i=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-i%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+i+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+i+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+i+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 It(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:o,nodeSize:i}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,l=a.pop()||0,f=a.pop()||0;if(l-f<=i){for(let i=f;i<=l;i++){const a=o[2*i],c=o[2*i+1];a>=t&&a<=r&&c>=e&&c<=n&&u.push(s[i])}continue}const d=f+l>>1,h=o[2*d],p=o[2*d+1];h>=t&&h<=r&&p>=e&&p<=n&&u.push(s[d]),(0===c?t<=h:e<=p)&&(a.push(f),a.push(d-1),a.push(1-c)),(0===c?r>=h:n>=p)&&(a.push(d+1),a.push(l),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:o}=this,i=[0,n.length-1,0],a=[],u=r*r;for(;i.length;){const c=i.pop()||0,l=i.pop()||0,f=i.pop()||0;if(l-f<=o){for(let r=f;r<=l;r++)bt(s[2*r],s[2*r+1],t,e)<=u&&a.push(n[r]);continue}const d=f+l>>1,h=s[2*d],p=s[2*d+1];bt(h,p,t,e)<=u&&a.push(n[d]),(0===c?t-r<=h:e-r<=p)&&(i.push(f),i.push(d-1),i.push(1-c)),(0===c?t+r>=h:e+r>=p)&&(i.push(d+1),i.push(l),i.push(1-c))}return a}}function It(t,e,r,n,s,o){if(s-n<=r)return;const i=n+s>>1;At(t,e,i,n,s,o),It(t,e,r,n,i-1,1-o),It(t,e,r,i+1,s,1-o)}function At(t,e,r,n,s,o){for(;s>n;){if(s-n>600){const i=s-n+1,a=r-n+1,u=Math.log(i),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(i-c)/i)*(a-i/2<0?-1:1);At(t,e,r,Math.max(n,Math.floor(r-a*c/i+l)),Math.min(s,Math.floor(r+(i-a)*c/i+l)),o)}const i=e[2*r+o];let a=n,u=s;for(wt(t,e,n,r),e[2*s+o]>i&&wt(t,e,n,s);a<u;){for(wt(t,e,a,u),a++,u--;e[2*a+o]<i;)a++;for(;e[2*u+o]>i;)u--}e[2*n+o]===i?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){St(t,r,n),St(e,2*r,2*n),St(e,2*r+1,2*n+1)}function St(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function bt(t,e,r,n){const s=t-r,o=e-n;return s*s+o*o}const Rt="KEYS",_t="VALUES",Nt="";class Ot{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}=Mt(this._path);if(Mt(e)===Nt)return{done:!1,value:this.result()};const r=t.get(Mt(e));return this._path.push({node:r,keys:Array.from(r.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Mt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Mt(t))).filter((t=>t!==Nt)).join("")}value(){return Mt(this._path).node.get(Nt)}result(){switch(this._type){case _t:return this.value();case Rt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Mt=t=>t[t.length-1],kt=(t,e,r,n,s,o,i,a)=>{const u=o*i;t:for(const c of t.keys())if(c===Nt){const e=s[u-1];e<=r&&n.set(a,[t.get(c),e])}else{let u=o;for(let t=0;t<c.length;++t,++u){const n=c[t],o=i*u,a=o-i;let l=s[o];const f=Math.max(0,u-r-1),d=Math.min(i-1,u+r);for(let t=f;t<d;++t){const r=n!==e[t],i=s[a+t]+ +r,u=s[a+t+1]+1,c=s[o+t]+1,f=s[o+t+1]=Math.min(i,u,c);f<l&&(l=f)}if(l>r)continue t}kt(t.get(c),e,r,n,s,u,i,a+c)}};class Lt{_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]=Ut(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,n]=Ct(r);for(const r of e.keys())if(r!==Nt&&r.startsWith(n)){const s=new Map;return s.set(r.slice(n.length),e.get(r)),new Lt(s,t)}}return new Lt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Bt(this._tree,t)}entries(){return new Ot(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,o=s+r,i=new Uint8Array(o*s).fill(r+1);for(let t=0;t<s;++t)i[t]=t;for(let t=1;t<o;++t)i[t*s]=t;return kt(t,e,r,n,i,1,s,""),n})(this._tree,t,e)}get(t){const e=xt(this._tree,t);return void 0!==e?e.get(Nt):void 0}has(t){return xt(this._tree,t)?.has(Nt)??!1}keys(){return new Ot(this,Rt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Dt(this._tree,t).set(Nt,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=Dt(this._tree,t);return r.set(Nt,e(r.get(Nt))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const r=Dt(this._tree,t);let n=r.get(Nt);return void 0===n&&r.set(Nt,n=e()),n}values(){return new Ot(this,_t)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Lt;for(const[r,n]of t)e.set(r,n);return e}static fromObject(t){return Lt.from(Object.entries(t))}}const Ut=(t,e,r=[])=>{if(0===e.length||null==t)return[t,r];for(const n of t.keys())if(n!==Nt&&e.startsWith(n))return r.push([t,n]),Ut(t.get(n),e.slice(n.length),r);return r.push([t,e]),Ut(void 0,"",r)},xt=(t,e)=>{if(0===e.length||!t)return t;for(const r of t.keys())if(r!==Nt&&e.startsWith(r))return xt(t.get(r),e.slice(r.length))},Dt=(t,e)=>{const r=e.length;t:for(let n=0;t&&n<r;){for(const s of t.keys())if(s!==Nt&&e[n]===s[0]){const o=Math.min(r-n,s.length);let i=1;for(;i<o&&e[n+i]===s[i];)++i;const a=t.get(s);if(i===s.length)t=a;else{const r=new Map;r.set(s.slice(i),a),t.set(e.slice(n,n+i),r),t.delete(s),t=r}n+=i;continue t}const s=new Map;return t.set(e.slice(n),s),s}return t},Bt=(t,e)=>{const[r,n]=Ut(t,e);if(void 0!==r)if(r.delete(Nt),0===r.size)Ft(n);else if(1===r.size){const[t,e]=r.entries().next().value;Pt(n,t,e)}},Ft=t=>{if(0===t.length)return;const[e,r]=Ct(t);if(e.delete(r),0===e.size)Ft(t.slice(0,-1));else if(1===e.size){const[r,n]=e.entries().next().value;r!==Nt&&Pt(t.slice(0,-1),r,n)}},Pt=(t,e,r)=>{if(0===t.length)return;const[n,s]=Ct(t);n.set(s+e,r),n.delete(s)},Ct=t=>t[t.length-1],jt=/[\n\r\p{Z}\p{P}]+/u,$t="or",zt="and",Gt="and_not",Jt=(t,e)=>{t.includes(e)||t.push(e)},Vt=(t,e)=>{for(const r of e)t.includes(r)||t.push(r)},Yt=({score:t},{score:e})=>e-t,Wt=()=>new Map,qt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Zt={[$t]:(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:o}=e.get(r);n.score=n.score+t,n.match=Object.assign(n.match,o),Vt(n.terms,s)}}return t},[zt]:(t,e)=>{const r=new Map;for(const n of e.keys()){const s=t.get(n);if(null==s)continue;const{score:o,terms:i,match:a}=e.get(n);Vt(s.terms,i),r.set(n,{score:s.score+o,terms:s.terms,match:Object.assign(s.match,a)})}return r},[Gt]:(t,e)=>{for(const r of e.keys())t.delete(r);return t}},Ht=(t,e,r,n,s,o)=>{const{k:i,b:a,d:u}=o;return Math.log(1+(r-e+.5)/(e+.5))*(u+t*(i+1)/(t+i*(1-a+a*n/s)))},Qt=(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")},Xt=(t,e,r,n)=>{const s=t._index.fetch(n,Wt);let o=s.get(e);if(null==o)o=new Map,o.set(r,1),s.set(e,o);else{const t=o.get(r);o.set(r,(t??0)+1)}},Kt=(t,e,r,n)=>{if(!t._index.has(n))return void Qt(t,r,e,n);const s=t._index.fetch(n,Wt),o=s.get(e),i=o?.get(r);!o||typeof i>"u"?Qt(t,r,e,n):i<=1?o.size<=1?s.delete(e):o.delete(r):o.set(r,i-1),0===t._index.get(n).size&&t._index.delete(n)},te=(t,e,r,n,s)=>{let o=t._fieldLength.get(e);null==o&&t._fieldLength.set(e,o=[]),o[r]=s;const i=(t._avgFieldLength[r]||0)*n+s;t._avgFieldLength[r]=i/(n+1)},ee=(t,e)=>{const{extractField:r,tokenize:n,processTerm:s,fields:o,idField:i}=t._options,a=r(e,i);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${i}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const u=((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,a);((t,e,r)=>{const{storeFields:n,extractField:s}=t._options;if(0===n?.length)return;let o=t._storedFields.get(e);void 0===o&&t._storedFields.set(e,o={});for(const t of n){const e=s(r,t);null!=e&&(o[t]=e)}})(t,u,e);for(const i of o){const o=r(e,i);if(null==o)continue;const a=n(o.toString(),i),c=t._fieldIds[i],l=new Set(a).size;te(t,u,c,t._documentCount-1,l);for(const e of a){const r=s(e,i);if(Array.isArray(r))for(const e of r)Xt(t,c,u,e);else r&&Xt(t,c,u,r)}}},re={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split(jt),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},ne={combineWith:$t,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},se={combineWith:"and",prefix:(t,e,r)=>e===r.length-1},oe={minDirtFactor:.1,minDirtCount:20},ie={batchSize:1e3,batchWait:10,...oe},ae=Symbol("*"),ue=(t,e=$t)=>{if(0===t.length)return new Map;const r=e.toLowerCase();if(!(r in Zt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Zt[r])},ce=(t,e,r,n,s,o,i,a,u,c=new Map)=>{if(null==o)return c;for(const l of Object.keys(i)){const f=i[l],d=t._fieldIds[l],h=o.get(d);if(null==h)continue;let p=h.size;const m=t._avgFieldLength[d];for(const o of h.keys()){if(!t._documentIds.has(o)){Kt(t,d,o,r),p-=1;continue}const i=a?a(t._documentIds.get(o),r,t._storedFields.get(o)):1;if(!i)continue;const v=h.get(o),g=t._fieldLength.get(o)[d],T=n*s*f*i*Ht(v,p,t._documentCount,g,m,u),y=c.get(o);if(y){y.score+=T,Jt(y.terms,e);const t=qt(y.match,r);t?t.push(l):y.match[r]=[l]}else c.set(o,{score:T,terms:[e],match:{[r]:[l]}})}}return c},le=(t,e,r={})=>{if(e===ae)return((t,e)=>{const r=new Map,n={...t._options.searchOptions,...e};for(const[e,s]of t._documentIds){const o=n.boostDocument?n.boostDocument(s,"",t._storedFields.get(e)):1;r.set(e,{score:o,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 ue(s,n.combineWith)}const{tokenize:n,processTerm:s,searchOptions:o}=t._options,i={tokenize:n,processTerm:s,...o,...r},{tokenize:a,processTerm:u}=i,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}))(i)).map((e=>((t,e,r)=>{const n={...t._options.searchOptions,...r},s=(n.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:qt(n.boost,e)||1})),{}),{boostDocument:o,weights:i,maxFuzzy:a,bm25:u}=n,{fuzzy:c,prefix:l}={...ne.weights,...i},f=t._index.get(e.term),d=ce(t,e.term,e.term,1,e.termBoost,f,s,o,u);let h,p;if(e.prefix&&(h=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(h)for(const[r,n]of h){const i=r.length-e.term.length;if(!i)continue;p?.delete(r);const a=l*r.length/(r.length+.3*i);ce(t,e.term,r,a,e.termBoost,n,s,o,u,d)}if(p)for(const r of p.keys()){const[n,i]=p.get(r);if(!i)continue;const a=c*r.length/(r.length+i);ce(t,e.term,r,a,e.termBoost,n,s,o,u,d)}return d})(t,e,i)));return ue(c,i.combineWith)};class fe{_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?ie:t.autoVacuum;this._options={...re,...t,autoVacuum:e,searchOptions:{...ne,...t.searchOptions},autoSuggestOptions:{...se,...t.autoSuggestOptions}},this._index=new Lt,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=oe,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 de=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 he;function pe(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return he.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return he.STATION;case 2:case"ENTRANCE_EXIT":return he.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return he.GENERIC_NODE;case 4:case"BOARDING_AREA":return he.BOARDING_AREA;default:return he.UNRECOGNIZED}}!function(t){t[t.SIMPLE_STOP_OR_PLATFORM=0]="SIMPLE_STOP_OR_PLATFORM",t[t.STATION=1]="STATION",t[t.ENTRANCE_EXIT=2]="ENTRANCE_EXIT",t[t.GENERIC_NODE=3]="GENERIC_NODE",t[t.BOARDING_AREA=4]="BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(he||(he={}));const me={encode(t,e=new E){""!==t.name&&e.uint32(10).string(t.name),""!==t.sourceStopId&&e.uint32(18).string(t.sourceStopId),void 0!==t.lat&&e.uint32(25).double(t.lat),void 0!==t.lon&&e.uint32(33).double(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 I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={name:"",sourceStopId:"",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(25!==t)break;s.lat=r.double();continue;case 4:if(33!==t)break;s.lon=r.double();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:Te(t.name)?globalThis.String(t.name):"",sourceStopId:Te(t.sourceStopId)?globalThis.String(t.sourceStopId):"",lat:Te(t.lat)?globalThis.Number(t.lat):void 0,lon:Te(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:Te(t.parent)?globalThis.Number(t.parent):void 0,locationType:Te(t.locationType)?pe(t.locationType):0,platform:Te(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const r={};return""!==t.name&&(r.name=t.name),""!==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 he.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case he.STATION:return"STATION";case he.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case he.GENERIC_NODE:return"GENERIC_NODE";case he.BOARDING_AREA:return"BOARDING_AREA";case he.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(r.platform=t.platform),r},create:t=>me.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s,o,i,a,u;const c={name:"",sourceStopId:"",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:"",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===(o=t.children)||void 0===o?void 0:o.map((t=>t)))||[],c.parent=null!==(i=t.parent)&&void 0!==i?i: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 ve={encode:(t,e=new E)=>(""!==t.version&&e.uint32(10).string(t.version),Object.entries(t.stops).forEach((([t,r])=>{ge.encode({key:t,value:r},e.uint32(18).fork()).join()})),e),decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={version:"",stops:{}};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=r.string();continue;case 2:{if(18!==t)break;const e=ge.decode(r,r.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON(t){return{version:Te(t.version)?globalThis.String(t.version):"",stops:(e=t.stops,"object"==typeof e&&null!==e?Object.entries(t.stops).reduce(((t,[e,r])=>(t[globalThis.Number(e)]=me.fromJSON(r),t)),{}):{})};var e},toJSON(t){const e={};if(""!==t.version&&(e.version=t.version),t.stops){const r=Object.entries(t.stops);r.length>0&&(e.stops={},r.forEach((([t,r])=>{e.stops[t]=me.toJSON(r)})))}return e},create:t=>ve.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={version:"",stops:{}};return n.version=null!==(e=t.version)&&void 0!==e?e:"",n.stops=Object.entries(null!==(r=t.stops)&&void 0!==r?r:{}).reduce(((t,[e,r])=>(void 0!==r&&(t[globalThis.Number(e)]=me.fromPartial(r)),t)),{}),n}};const ge={encode:(t,e=new E)=>(0!==t.key&&e.uint32(8).uint32(t.key),void 0!==t.value&&me.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const r=t instanceof I?t:new I(t),n=void 0===e?r.len:r.pos+e,s={key:0,value:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.key=r.uint32();continue;case 2:if(18!==t)break;s.value=me.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({key:Te(t.key)?globalThis.Number(t.key):0,value:Te(t.value)?me.fromJSON(t.value):void 0}),toJSON(t){const e={};return 0!==t.key&&(e.key=Math.round(t.key)),void 0!==t.value&&(e.value=me.toJSON(t.value)),e},create:t=>ge.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={key:0,value:void 0};return r.key=null!==(e=t.key)&&void 0!==e?e:0,r.value=void 0!==t.value&&null!==t.value?me.fromPartial(t.value):void 0,r}};function Te(t){return null!=t}const ye="0.0.2",Ee=t=>{const e={version:ye,stops:{}};return t.forEach(((t,r)=>{var n;e.stops[r]={name:(n=t).name,sourceStopId:n.sourceStopId,lat:n.lat,lon:n.lon,children:n.children,parent:n.parent,locationType:we(n.locationType),platform:n.platform}})),e},Ie=t=>{if(t.version!==ye)throw new Error(`Unsupported stopMap version ${t.version}`);const e=new Map;return Object.entries(t.stops).forEach((([t,r])=>{const n=parseInt(t,10);var s;e.set(n,{id:n,sourceStopId:(s=r).sourceStopId,name:s.name,lat:s.lat,lon:s.lon,children:s.children,parent:s.parent,locationType:Ae(s.locationType),platform:s.platform})})),e},Ae=t=>{switch(t){case he.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case he.STATION:return"STATION";case he.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case he.GENERIC_NODE:return"GENERIC_NODE";case he.BOARDING_AREA:return"BOARDING_AREA";case he.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},we=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return he.SIMPLE_STOP_OR_PLATFORM;case"STATION":return he.STATION;case"ENTRANCE_EXIT":return he.ENTRANCE_EXIT;case"GENERIC_NODE":return he.GENERIC_NODE;case"BOARDING_AREA":return he.BOARDING_AREA}};class Se{constructor(t){var e;this.stopsMap=t,this.sourceStopsMap=new Map;for(const[e,r]of t.entries())this.sourceStopsMap.set(r.sourceStopId,e);this.textIndex=new fe({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:de});const r=new Map;for(const[n,s]of t.entries()){const t=null!==(e=s.parent)&&void 0!==e?e:n;r.has(t)||r.set(t,{id:t,name:s.parent?this.stopsMap.get(s.parent).name:s.name})}const n=Array.from(r.values());((t,e)=>{for(const r of e)ee(t,r)})(this.textIndex,n),this.stopPoints=Array.from(this.stopsMap.entries()).filter((([,t])=>!(!t.lat||!t.lon))).map((([t,e])=>({id:t,lat:e.lat,lon:e.lon}))),this.geoIndex=new Et(this.stopPoints.length);for(const{lat:t,lon:e}of this.stopPoints)this.geoIndex.add(e,t);this.geoIndex.finish()}static fromData(t){const e=new I(t),r=ve.decode(e);return new Se(Ie(r))}serialize(){const t=Ee(this.stopsMap),e=new E;return ve.encode(t,e),e.finish()}size(){return this.stopsMap.size}findStopsByName(t,e=5){return((t,e,r={})=>{const{searchOptions:n}=t._options,s={...n,...r},o=le(t,e,r),i=[];for(const[e,{score:r,terms:n,match:a}]of o){const o=n.length||1,u={id:t._documentIds.get(e),score:r*o,terms:Object.keys(a),queryTerms:n,match:a};Object.assign(u,t._storedFields.get(e)),(null==s.filter||s.filter(u))&&i.push(u)}return e===ae&&null==s.boostDocument||i.sort(Yt),i})(this.textIndex,t).map((t=>this.stopsMap.get(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 o=1;const i=[];void 0===n&&(n=1/0),void 0!==s&&(o=vt(s/6371));const a=new ft([],mt);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(r*ht);for(;u;){const s=u.right,l=u.left;if(s-l<=t.nodeSize)for(let n=l;n<=s;n++){const s=t.ids[n];{const o=Tt(e,r,t.coords[2*n],t.coords[2*n+1],c);a.push({id:s,dist:o})}}else{const n=l+s>>1,o=t.coords[2*n],i=t.coords[2*n+1],f=t.ids[n];{const t=Tt(e,r,o,i,c);a.push({id:f,dist:t})}const d=(u.axis+1)%2,h={left:l,right:n-1,axis:d,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?o:u.maxLng,maxLat:1===u.axis?i:u.maxLat,dist:0},p={left:n+1,right:s,axis:d,minLng:0===u.axis?o:u.minLng,minLat:1===u.axis?i:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};h.dist=pt(e,r,c,h),p.dist=pt(e,r,c,p),a.push(h),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>o)return i;if(i.push(t.id),i.length===n)return i}u=a.pop()}return i}(this.geoIndex,e,t,r,n).map((t=>{const e=this.stopPoints[t];return this.stopsMap.get(e.id)}));return s}findStopById(t){return this.stopsMap.get(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.sourceStopsMap.get(t);if(void 0===n)return[];const s=this.stopsMap.get(n);if(!s)return[];const o=s.parent?null!==(r=null===(e=this.stopsMap.get(s.parent))||void 0===e?void 0:e.children)&&void 0!==r?r:[]:s.children;return Array.from(new Set([n,...o])).map((t=>this.stopsMap.get(t)))}}exports.Duration=t,exports.Plotter=class{constructor(t){this.result=t}plotDotGraph(){const t=this.result.earliestArrivalsPerRound,e=["digraph PathTree {"," graph [overlap=false];"," node [shape=ellipse style=filled fillcolor=lightgrey];"];return t.forEach(((t,r)=>{t.forEach((t=>{const{origin:n,leg:s}=t;if(!s)return;const o=this.result.stopsIndex.findStopById(s.from.id),i=this.result.stopsIndex.findStopById(s.to.id),a=this.result.stopsIndex.findStopById(n);if(o&&i&&a){const t=o.platform?`${o.name} (Pl. ${o.platform})`:o.name,n=i.platform?`${i.name} (Pl. ${i.platform})`:i.name,u=a.platform?`${a.name} (Pl. ${a.platform})`:a.name,c="route"in s,l=c?`${s.route.name}\n${s.departureTime.toString()} - ${s.arrivalTime.toString()}`:s.minTransferTime?s.minTransferTime.toString():"",f=`IntermediateNode${o.id}_${i.id}`,d=c?"":', color="red", fontcolor="red"',h=c?"":' fontcolor="red"';e.push(` "${t} (Origin: ${u}) [R${r}]\n(${o.id})" -> "${f}" [shape=point${d}];`),e.push(` "${f}" [label="${l}" shape=rect style=filled fillcolor=white${h} border=0];`),e.push(` "${f}" -> "${n} (Origin: ${u}) [R${r}]\n(${i.id})" [${d.replace(", ","")}];`)}}))})),e.push("}"),e.join("\n")}},exports.Query=at,exports.Result=ct,exports.Route=ut,exports.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}considerTransfers(e,r,n,s,o){var i,a;const{options:u}=e,c=new Set;for(const e of r){const r=n.get(e);if(!r)continue;const l=r.leg;if(!l||"route"in l)for(const l of this.timetable.getTransfers(e)){let f;f=l.minTransferTime?l.minTransferTime:"IN_SEAT"===l.type?t.zero():u.minTransferTime;const d=r.arrival.plus(f),h=null!==(a=null===(i=n.get(l.destination))||void 0===i?void 0:i.arrival)&&void 0!==a?a:lt;if(d.isBefore(h)){const t=r.origin;n.set(l.destination,{arrival:d,legNumber:o,origin:t,leg:{from:this.stopsIndex.findStopById(e),to:this.stopsIndex.findStopById(l.destination),minTransferTime:l.minTransferTime,type:l.type}}),s.set(l.destination,{arrival:d,legNumber:o,origin:t}),c.add(l.destination)}}}for(const t of c)r.add(t)}earliestArrivalAtAnyStop(t,e){var r,n;let s=lt;for(const o of e){const e=null!==(n=null===(r=t.get(o.id))||void 0===r?void 0:r.arrival)&&void 0!==n?n:lt;s=z.min(s,e)}return s}route(t){var e,r,n,s,o;const{from:i,to:a,departureTime:u,options:c}=t,l=this.stopsIndex.equivalentStops(i),f=Array.from(a).flatMap((t=>this.stopsIndex.equivalentStops(t))),d=new Map,h=new Map,p=[h],m=new Set;for(const t of l)m.add(t.id),d.set(t.id,{arrival:u,legNumber:0,origin:t.id}),h.set(t.id,{arrival:u,legNumber:0,origin:t.id});this.considerTransfers(t,m,h,d,0);for(let i=1;i<=c.maxTransfers+1;i++){const a=new Map;p.push(a);const u=p[i-1],l=this.timetable.findReachableRoutes(m,c.transportModes);m.clear();for(const[t,c]of l.entries()){let l;for(const h of t.stopsIterator(c)){if(void 0!==l){const n=t.arrivalAt(h,l.tripIndex),s=t.dropOffTypeAt(h,l.tripIndex),o=null!==(r=null===(e=d.get(h))||void 0===e?void 0:e.arrival)&&void 0!==r?r:lt;if("NOT_AVAILABLE"!==s&&n.isBefore(o)&&n.isBefore(this.earliestArrivalAtAnyStop(d,f))){const e=t.departureFrom(l.bestHopOnStop,l.tripIndex);a.set(h,{arrival:n,legNumber:i,origin:l.origin,leg:{from:this.stopsIndex.findStopById(l.bestHopOnStop),to:this.stopsIndex.findStopById(h),departureTime:e,arrivalTime:n,route:this.timetable.getServiceRouteInfo(t)}}),d.set(h,{arrival:n,legNumber:i,origin:l.origin}),m.add(h)}}const c=null===(n=u.get(h))||void 0===n?void 0:n.arrival;if(void 0!==c&&(void 0===l||c.isBefore(t.arrivalAt(h,l.tripIndex))||c.equals(t.arrivalAt(h,l.tripIndex)))){const e=t.findEarliestTrip(h,c,null==l?void 0:l.tripIndex);void 0!==e&&(l={tripIndex:e,bestHopOnStop:h,origin:null!==(o=null===(s=u.get(h))||void 0===s?void 0:s.origin)&&void 0!==o?o:h})}}}if(this.considerTransfers(t,m,a,d,i),0===m.size)break}return new ct(t,d,p,this.stopsIndex)}},exports.StopsIndex=Se,exports.Time=z,exports.Timetable=it;
|
|
1
|
+
"use strict";class t{constructor(t){this.totalSeconds=t}static fromSeconds(e){return new t(e)}static fromMinutes(e){return new t(60*e)}static zero(){return new t(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),r=this.totalSeconds%60;return t>0?`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`}toSeconds(){return this.totalSeconds}add(e){const r=this.totalSeconds+e.toSeconds();return new t(r)}subtract(e){const r=Math.max(0,this.totalSeconds-e.toSeconds());return new t(r)}}function e(){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 r(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)}}"function"==typeof SuppressedError&&SuppressedError;const n=4294967296;function s(t){const e="-"===t[0];e&&(t=t.slice(1));const r=1e6;let s=0,i=0;function u(e,o){const a=Number(t.slice(e,o));i*=r,s=s*r+a,s>=n&&(i+=s/n|0,s%=n)}return u(-24,-18),u(-18,-12),u(-12,-6),u(-6),e?a(s,i):o(s,i)}function i(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(n*e+t);const r=16777215&(t>>>24|e<<8),s=e>>16&65535;let i=(16777215&t)+6777216*r+6710656*s,o=r+8147497*s,a=2*s;const c=1e7;return i>=c&&(o+=Math.floor(i/c),i%=c),o>=c&&(a+=Math.floor(o/c),o%=c),a.toString()+u(o)+u(i)}function o(t,e){return{lo:0|t,hi:0|e}}function a(t,e){return e=~e,t?t=1+~t:e+=1,o(t,e)}const u=t=>{const e=String(t);return"0000000".slice(e.length)+e};function c(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&&("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()),d(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),d(t),s(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),p(t),s(t)),dec:(t,e)=>function(t,e){let r=o(t,e);const n=2147483648&r.hi;n&&(r=a(r.lo,r.hi));const s=i(r.lo,r.hi);return n?"-"+s:s}(t,e),uDec:(t,e)=>i(t,e)}}function d(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)}const m=Symbol.for("@bufbuild/protobuf/text-encoding");function g(){if(null==globalThis[m]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[m]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[m]}var T;!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"}(T||(T={}));const v=34028234663852886e22,y=-34028234663852886e22;class I{constructor(t=g().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(R(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return E(t),c(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>v||t<y))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){R(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){E(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return E(t),c(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 r(e.lo,e.hi,this.buf),this}sint64(t){const e=h.enc(t),n=e.hi>>31;return r(e.lo<<1^n,(e.hi<<1|e.lo>>>31)^n,this.buf),this}uint64(t){const e=h.uEnc(t);return r(e.lo,e.hi,this.buf),this}}class A{constructor(t,r=g().decodeUtf8){this.decodeUtf8=r,this.varint64=e,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 T.Varint:for(;128&this.buf[this.pos++];);break;case T.Bit64:this.pos+=4;case T.Bit32:this.pos+=4;break;case T.LengthDelimited:let r=this.uint32();this.pos+=r;break;case T.StartGroup:for(;;){const[t,r]=this.tag();if(r===T.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 E(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 R(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 w,S;function _(t){switch(t){case 0:case"RECOMMENDED_TRANSFER_POINT":return w.RECOMMENDED_TRANSFER_POINT;case 1:case"TIMED_TRANSFER":return w.TIMED_TRANSFER;case 2:case"REQUIRES_MINIMAL_TIME":return w.REQUIRES_MINIMAL_TIME;case 3:case"IN_SEAT_TRANSFER":return w.IN_SEAT_TRANSFER;default:return w.UNRECOGNIZED}}function b(t){switch(t){case 0:case"TRAM":return S.TRAM;case 1:case"SUBWAY":return S.SUBWAY;case 2:case"RAIL":return S.RAIL;case 3:case"BUS":return S.BUS;case 4:case"FERRY":return S.FERRY;case 5:case"CABLE_TRAM":return S.CABLE_TRAM;case 6:case"AERIAL_LIFT":return S.AERIAL_LIFT;case 7:case"FUNICULAR":return S.FUNICULAR;case 8:case"TROLLEYBUS":return S.TROLLEYBUS;case 9:case"MONORAIL":return S.MONORAIL;default:return S.UNRECOGNIZED}}function N(){return{stopTimes:new Uint8Array(0),pickUpDropOffTypes:new Uint8Array(0),stops:new Uint8Array(0),serviceRouteId:0}}!function(t){t[t.RECOMMENDED_TRANSFER_POINT=0]="RECOMMENDED_TRANSFER_POINT",t[t.TIMED_TRANSFER=1]="TIMED_TRANSFER",t[t.REQUIRES_MINIMAL_TIME=2]="REQUIRES_MINIMAL_TIME",t[t.IN_SEAT_TRANSFER=3]="IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(w||(w={})),function(t){t[t.TRAM=0]="TRAM",t[t.SUBWAY=1]="SUBWAY",t[t.RAIL=2]="RAIL",t[t.BUS=3]="BUS",t[t.FERRY=4]="FERRY",t[t.CABLE_TRAM=5]="CABLE_TRAM",t[t.AERIAL_LIFT=6]="AERIAL_LIFT",t[t.FUNICULAR=7]="FUNICULAR",t[t.TROLLEYBUS=8]="TROLLEYBUS",t[t.MONORAIL=9]="MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(S||(S={}));const O={encode:(t,e=new I)=>(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=N();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)?k(t.stopTimes):new Uint8Array(0),pickUpDropOffTypes:B(t.pickUpDropOffTypes)?k(t.pickUpDropOffTypes):new Uint8Array(0),stops:B(t.stops)?k(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=D(t.stopTimes)),0!==t.pickUpDropOffTypes.length&&(e.pickUpDropOffTypes=D(t.pickUpDropOffTypes)),0!==t.stops.length&&(e.stops=D(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>O.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s;const i=N();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 M={encode:(t,e=new I)=>(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)?_(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 w.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED_TRANSFER_POINT";case w.TIMED_TRANSFER:return"TIMED_TRANSFER";case w.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case w.IN_SEAT_TRANSFER:return"IN_SEAT_TRANSFER";case w.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>M.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 L={encode(t,e=new I){for(const r of t.transfers)M.encode(r,e.uint32(10).fork()).join();e.uint32(18).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={transfers:[],routes:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.transfers.push(M.decode(r,r.uint32()));continue;case 2:if(16===t){s.routes.push(r.uint32());continue}if(18===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=>({transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>M.fromJSON(t))):[],routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[]}),toJSON(t){var e,r;const n={};return(null===(e=t.transfers)||void 0===e?void 0:e.length)&&(n.transfers=t.transfers.map((t=>M.toJSON(t)))),(null===(r=t.routes)||void 0===r?void 0:r.length)&&(n.routes=t.routes.map((t=>Math.round(t)))),n},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={transfers:[],routes:[]};return n.transfers=(null===(e=t.transfers)||void 0===e?void 0:e.map((t=>M.fromPartial(t))))||[],n.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],n}};const U={encode(t,e=new I){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 S.TRAM:return"TRAM";case S.SUBWAY:return"SUBWAY";case S.RAIL:return"RAIL";case S.BUS:return"BUS";case S.FERRY:return"FERRY";case S.CABLE_TRAM:return"CABLE_TRAM";case S.AERIAL_LIFT:return"AERIAL_LIFT";case S.FUNICULAR:return"FUNICULAR";case S.TROLLEYBUS:return"TROLLEYBUS";case S.MONORAIL:return"MONORAIL";case S.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=>U.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 x={encode(t,e=new I){""!==t.version&&e.uint32(10).string(t.version);for(const r of t.stopsAdjacency)L.encode(r,e.uint32(18).fork()).join();for(const r of t.routesAdjacency)O.encode(r,e.uint32(26).fork()).join();for(const r of t.serviceRoutes)U.encode(r,e.uint32(34).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={version:"",stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=r.string();continue;case 2:if(18!==t)break;s.stopsAdjacency.push(L.decode(r,r.uint32()));continue;case 3:if(26!==t)break;s.routesAdjacency.push(O.decode(r,r.uint32()));continue;case 4:if(34!==t)break;s.serviceRoutes.push(U.decode(r,r.uint32()));continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({version:B(t.version)?globalThis.String(t.version):"",stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>L.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>O.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>U.fromJSON(t))):[]}),toJSON(t){var e,r,n;const s={};return""!==t.version&&(s.version=t.version),(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(s.stopsAdjacency=t.stopsAdjacency.map((t=>L.toJSON(t)))),(null===(r=t.routesAdjacency)||void 0===r?void 0:r.length)&&(s.routesAdjacency=t.routesAdjacency.map((t=>O.toJSON(t)))),(null===(n=t.serviceRoutes)||void 0===n?void 0:n.length)&&(s.serviceRoutes=t.serviceRoutes.map((t=>U.toJSON(t)))),s},create:t=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s;const i={version:"",stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[]};return i.version=null!==(e=t.version)&&void 0!==e?e:"",i.stopsAdjacency=(null===(r=t.stopsAdjacency)||void 0===r?void 0:r.map((t=>L.fromPartial(t))))||[],i.routesAdjacency=(null===(n=t.routesAdjacency)||void 0===n?void 0:n.map((t=>O.fromPartial(t))))||[],i.serviceRoutes=(null===(s=t.serviceRoutes)||void 0===s?void 0:s.map((t=>U.fromPartial(t))))||[],i}};function k(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 D(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}class F{static infinity(){return new F(Number.MAX_SAFE_INTEGER)}static origin(){return new F(0)}constructor(t){this.minutesSinceMidnight=t}static fromMinutes(t){return new F(t)}static fromHMS(t,e,r){if(t<0||e<0||r<0||e>=60||r>=60)throw new Error("Invalid time. Ensure hours, minutes, and seconds are valid values.");const n=r+60*e+3600*t,s=Math.round(n/60);return new F(s)}static fromHM(t,e){if(t<0||e<0||e>=60)throw new Error("Invalid time. Ensure hours and minutes are valid values.");return new F(e+60*t)}static fromDate(t){const e=t.getHours(),r=t.getMinutes(),n=t.getSeconds();return F.fromHMS(e,r,n)}static fromString(t){const[e,r,n]=t.split(":");if(void 0===e||void 0===r||""===e.trim()||""===r.trim()||isNaN(Number(e))||isNaN(Number(r))||void 0!==n&&(""===n.trim()||isNaN(Number(n))))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const s=parseInt(e,10),i=parseInt(r,10),o=void 0!==n?parseInt(n,10):0;return F.fromHMS(s,i,o)}toString(){let t=Math.floor(this.minutesSinceMidnight/60);const e=Math.floor(this.minutesSinceMidnight%60);return t>=24&&(t%=24),`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}toMinutes(){return this.minutesSinceMidnight}plus(t){const e=60*this.minutesSinceMidnight+t.toSeconds();return new F(Math.round(e/60))}minus(t){let e=60*this.minutesSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new F(Math.round(e/60))}diff(e){const r=this.minutesSinceMidnight-e.toMinutes();return t.fromSeconds(Math.abs(60*r))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.isAfter(t)?e:t))}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.isBefore(t)?e:t))}isAfter(t){return this.minutesSinceMidnight>t.toMinutes()}isBefore(t){return this.minutesSinceMidnight<t.toMinutes()}equals(t){return this.minutesSinceMidnight===t.toMinutes()}}const C=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],P=t=>{const e=C[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};let $=class{constructor(t,e,r,n){this.stopTimes=t,this.pickUpDropOffTypes=e,this.stops=r,this.serviceRouteId=n,this.nbStops=r.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<r.length;t++)this.stopIndices.set(r[t],t)}serialize(){return{stopTimes:this.stopTimes,pickUpDropOffTypes:this.pickUpDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}isBefore(t,e){const r=this.stopIndices.get(t);if(void 0===r)throw new Error(`Stop index ${r} not found in route ${this.serviceRouteId}`);const n=this.stopIndices.get(e);if(void 0===n)throw new Error(`Stop index ${n} not found in route ${this.serviceRouteId}`);return r<n}getNbStops(){return this.nbStops}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const r=2*(e*this.stops.length+this.stopIndex(t)),n=this.stopTimes[r];if(void 0===n)throw new Error(`Arrival time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return F.fromMinutes(n)}departureFrom(t,e){const r=2*(e*this.stops.length+this.stopIndex(t))+1,n=this.stopTimes[r];if(void 0===n)throw new Error(`Departure time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return F.fromMinutes(n)}pickUpTypeFrom(t,e){const r=e*this.stops.length+this.stopIndex(t),n=Math.floor(r/2),s=r%2==1,i=this.pickUpDropOffTypes[n];if(void 0===i)throw new Error(`Pick up type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return P(s?i>>6&3:i>>2&3)}dropOffTypeAt(t,e){const r=e*this.stops.length+this.stopIndex(t),n=Math.floor(r/2),s=r%2==1,i=this.pickUpDropOffTypes[n];if(void 0===i)throw new Error(`Drop off type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return P(s?i>>4&3:3&i)}findEarliestTrip(t,e=F.origin(),r){const n=void 0!==r?Math.min(r-1,this.nbTrips-1):this.nbTrips-1;if(n<0)return;let s,i=0,o=n;for(;i<=o;){const r=Math.floor((i+o)/2),n=this.departureFrom(t,r),a=this.pickUpTypeFrom(t,r);(n.isAfter(e)||n.equals(e))&&"NOT_AVAILABLE"!==a?(s=r,o=r-1):i=r+1}return s}stopIndex(t){const e=this.stopIndices.get(t);if(void 0===e)throw new Error(`Stop index for ${t} not found in route ${this.serviceRouteId}`);return e}};const z=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),j=!0,G=t=>{if(z===j)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],j);return e},V=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(z===j)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,j);return e},Y=t=>{if(z===j)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],j);return e},J=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(z===j)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,j);return e},W=t=>{const e=[];return t.forEach((t=>{const r=t.serialize();e.push({stopTimes:Y(r.stopTimes),pickUpDropOffTypes:r.pickUpDropOffTypes,stops:G(r.stops),serviceRouteId:r.serviceRouteId})})),e},q=t=>{switch(t){case w.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case w.TIMED_TRANSFER:return"GUARANTEED";case w.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case w.IN_SEAT_TRANSFER:return"IN_SEAT";case w.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},Z=t=>{switch(t){case"RECOMMENDED":return w.RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return w.TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return w.REQUIRES_MINIMAL_TIME;case"IN_SEAT":return w.IN_SEAT_TRANSFER}},H=t=>{switch(t){case S.TRAM:return"TRAM";case S.SUBWAY:return"SUBWAY";case S.RAIL:return"RAIL";case S.BUS:return"BUS";case S.FERRY:return"FERRY";case S.CABLE_TRAM:return"CABLE_TRAM";case S.AERIAL_LIFT:return"AERIAL_LIFT";case S.FUNICULAR:return"FUNICULAR";case S.TROLLEYBUS:return"TROLLEYBUS";case S.MONORAIL:return"MONORAIL";case S.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},Q=t=>{switch(t){case"TRAM":return S.TRAM;case"SUBWAY":return S.SUBWAY;case"RAIL":return S.RAIL;case"BUS":return S.BUS;case"FERRY":return S.FERRY;case"CABLE_TRAM":return S.CABLE_TRAM;case"AERIAL_LIFT":return S.AERIAL_LIFT;case"FUNICULAR":return S.FUNICULAR;case"TROLLEYBUS":return S.TROLLEYBUS;case"MONORAIL":return S.MONORAIL}},X=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),K="0.0.7";class tt{constructor(t,e,r){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=r,this.activeStops=new Set;for(let e=0;e<t.length;e++){const r=t[e];(r.routes.length>0||r.transfers.length>0)&&this.activeStops.add(e)}}serialize(){const t={version:K,stopsAdjacency:(r=this.stopsAdjacency,r.map((t=>({transfers:t.transfers.map((t=>Object.assign({destination:t.destination,type:Z(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))),routes:t.routes})))),routesAdjacency:W(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:Q(t.type),name:t.name,routes:t.routes}))))};var e,r;const n=new I;return x.encode(t,n),n.finish()}static fromData(e){const r=new A(e),n=x.decode(r);if(n.version!==K)throw new Error(`Unsupported timetable version ${n.version}`);return new tt((e=>{const r=[];for(let n=0;n<e.length;n++){const s=e[n],i=[];for(let e=0;e<s.transfers.length;e++){const r=s.transfers[e],n=Object.assign({destination:r.destination,type:q(r.type)},void 0!==r.minTransferTime&&{minTransferTime:t.fromSeconds(r.minTransferTime)});i.push(n)}r.push({transfers:i,routes:s.routes})}return r})(n.stopsAdjacency),(t=>{const e=[];for(let r=0;r<t.length;r++){const n=t[r],s=V(n.stops);e.push(new $(J(n.stopTimes),n.pickUpDropOffTypes,s,n.serviceRouteId))}return e})(n.routesAdjacency),(t=>{const e=[];for(let r=0;r<t.length;r++){const n=t[r];e.push({type:H(n.type),name:n.name,routes:n.routes})}return e})(n.serviceRoutes))}isActive(t){return this.activeStops.has(t)}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){var e,r;return null!==(r=null===(e=this.stopsAdjacency[t])||void 0===e?void 0:e.transfers)&&void 0!==r?r:[]}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);const{routes:r}=e;return function(t,e){var r={};for(var n in t)Object.prototype.hasOwnProperty.call(t,n)&&e.indexOf(n)<0&&(r[n]=t[n]);if(null!=t&&"function"==typeof Object.getOwnPropertySymbols){var s=0;for(n=Object.getOwnPropertySymbols(t);s<n.length;s++)e.indexOf(n[s])<0&&Object.prototype.propertyIsEnumerable.call(t,n[s])&&(r[n[s]]=t[n[s]])}return r}(e,["routes"])}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=X){const r=new Map,n=Array.from(t);for(let t=0;t<n.length;t++){const s=n[t],i=this.routesPassingThrough(s).filter((t=>{const r=this.getServiceRouteInfo(t);return e.has(r.type)}));for(let t=0;t<i.length;t++){const e=i[t],n=r.get(e);n?e.isBefore(s,n)&&r.set(e,s):r.set(e,s)}}return r}}class et{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}et.Builder=class{constructor(){this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:t.fromSeconds(120),transportModes:X}}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}build(){return new et(this)}};class rt{constructor(t){this.legs=t}departureTime(){const e=t.zero();for(let t=0;t<this.legs.length;t++){const r=this.legs[t];if("departureTime"in r)return r.departureTime.minus(e);"minTransferTime"in r&&r.minTransferTime&&e.add(r.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let e=F.origin();const r=t.zero();let n=!1;for(let t=this.legs.length-1;t>=0;t--){const s=this.legs[t];"arrivalTime"in s&&!n?(e=s.arrivalTime,n=!0):"minTransferTime"in s&&s.minTransferTime&&n&&r.add(s.minTransferTime)}if(!n)throw new Error("No vehicle leg found in route");return e.plus(r)}totalDuration(){return 0===this.legs.length?t.zero():this.arrivalTime().diff(this.departureTime())}toString(){return this.legs.map(((t,e)=>{var r;const n=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,s=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,i="minTransferTime"in t?`Minimum Transfer Time: ${null===(r=t.minTransferTime)||void 0===r?void 0:r.toString()}`:"",o="route"in t&&"departureTime"in t&&"arrivalTime"in t?`Route: ${t.route.type} ${t.route.name}, Departure: ${t.departureTime.toString()}, Arrival: ${t.arrivalTime.toString()}`:"";return[`Leg ${e+1}:`,` ${n}`,` ${s}`,i?` ${i}`:"",o?` ${o}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}asJson(){return this.legs.map((t=>"route"in t?{from:t.from.sourceStopId,to:t.to.sourceStopId,departure:t.departureTime.toString(),arrival:t.arrivalTime.toString(),route:t.route}:Object.assign({from:t.from.sourceStopId,to:t.to.sourceStopId,type:t.type},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toString()})))}}class nt{constructor(t,e,r,n){this.query=t,this.earliestArrivals=e,this.earliestArrivalsPerRound=r,this.stopsIndex=n}bestRoute(t){var e,r,n;const s=(t instanceof Set?Array.from(t):t?[t]:Array.from(this.query.to)).flatMap((t=>this.stopsIndex.equivalentStops(t)));let i,o;for(const t of s){const e=this.earliestArrivals.get(t.id);void 0!==e&&(void 0===o||e.arrival.isBefore(o.arrival))&&(i=t.id,o=e)}if(!i||!o)return;const a=[];let u=i,c=o.legNumber;for(;o.origin!==u;){const t=null===(e=this.earliestArrivalsPerRound[c])||void 0===e?void 0:e.get(u);if(!(null==t?void 0:t.leg))throw new Error(`No leg found for a trip leg: start stop=${null!==(n=null===(r=null==t?void 0:t.leg)||void 0===r?void 0:r.from.id)&&void 0!==n?n:"unknown"}, end stop=${u}, round=${c}, origin=${o.origin}`);a.unshift(t.leg),u=t.leg.from.id,"route"in t.leg&&(c-=1)}return new rt(a)}arrivalAt(t,e){const r=this.stopsIndex.equivalentStops(t);let n;const s=void 0!==e?this.earliestArrivalsPerRound[e+1]:this.earliestArrivals;for(const t of r){const e=s.get(t.id);void 0!==e&&(void 0===n||e.arrival.isBefore(n.arrival))&&(n=e)}return n}}const st=F.infinity();class it{constructor(t=[],e=ot){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 ot(t,e){return t<e?-1:t>e?1:0}const at=Math.PI/180;function ut(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?lt((e-o)*at):e>a?lt((e-a)*at):0;const u=Math.min(lt((t-s)*at),lt((t-i)*at)),c=function(t,e){const r=1-2*e;return r<=0?t>0?90:-90:Math.atan(Math.tan(t*at)/r)/at}(e,u);return c>o&&c<a?ht(u,r,e,c):Math.min(ht(u,r,e,o),ht(u,r,e,a))}function ct(t,e){return t.dist-e.dist}function lt(t){const e=Math.sin(t/2);return e*e}function ht(t,e,r,n){return e*Math.cos(n*at)*t+lt((r-n)*at)}function ft(t,e,r,n,s){return ht(lt((t-r)*at),s,e,n)}const dt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class pt{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=dt[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 pt(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=dt.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 mt(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,l=a.pop()||0,h=a.pop()||0;if(l-h<=o){for(let o=h;o<=l;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 f=h+l>>1,d=i[2*f],p=i[2*f+1];d>=t&&d<=r&&p>=e&&p<=n&&u.push(s[f]),(0===c?t<=d:e<=p)&&(a.push(h),a.push(f-1),a.push(1-c)),(0===c?r>=d:n>=p)&&(a.push(f+1),a.push(l),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,l=o.pop()||0,h=o.pop()||0;if(l-h<=i){for(let r=h;r<=l;r++)yt(s[2*r],s[2*r+1],t,e)<=u&&a.push(n[r]);continue}const f=h+l>>1,d=s[2*f],p=s[2*f+1];yt(d,p,t,e)<=u&&a.push(n[f]),(0===c?t-r<=d:e-r<=p)&&(o.push(h),o.push(f-1),o.push(1-c)),(0===c?t+r>=d:e+r>=p)&&(o.push(f+1),o.push(l),o.push(1-c))}return a}}function mt(t,e,r,n,s,i){if(s-n<=r)return;const o=n+s>>1;gt(t,e,o,n,s,i),mt(t,e,r,n,o-1,1-i),mt(t,e,r,o+1,s,1-i)}function gt(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),l=.5*Math.sqrt(u*c*(o-c)/o)*(a-o/2<0?-1:1);gt(t,e,r,Math.max(n,Math.floor(r-a*c/o+l)),Math.min(s,Math.floor(r+(o-a)*c/o+l)),i)}const o=e[2*r+i];let a=n,u=s;for(Tt(t,e,n,r),e[2*s+i]>o&&Tt(t,e,n,s);a<u;){for(Tt(t,e,a,u),a++,u--;e[2*a+i]<o;)a++;for(;e[2*u+i]>o;)u--}e[2*n+i]===o?Tt(t,e,n,u):(u++,Tt(t,e,u,s)),u<=r&&(n=u+1),r<=u&&(s=u-1)}}function Tt(t,e,r,n){vt(t,r,n),vt(e,2*r,2*n),vt(e,2*r+1,2*n+1)}function vt(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function yt(t,e,r,n){const s=t-r,i=e-n;return s*s+i*i}const It="KEYS",At="VALUES",Et="";class Rt{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}=wt(this._path);if(wt(e)===Et)return{done:!1,value:this.result()};const r=t.get(wt(e));return this._path.push({node:r,keys:Array.from(r.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=wt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>wt(t))).filter((t=>t!==Et)).join("")}value(){return wt(this._path).node.get(Et)}result(){switch(this._type){case At:return this.value();case It:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const wt=t=>t[t.length-1],St=(t,e,r,n,s,i,o,a)=>{const u=i*o;t:for(const c of t.keys())if(c===Et){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 l=s[i];const h=Math.max(0,u-r-1),f=Math.min(o-1,u+r);for(let t=h;t<f;++t){const r=n!==e[t],o=s[a+t]+ +r,u=s[a+t+1]+1,c=s[i+t]+1,h=s[i+t+1]=Math.min(o,u,c);h<l&&(l=h)}if(l>r)continue t}St(t.get(c),e,r,n,s,u,o,a+c)}};class _t{_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]=bt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,n]=xt(r);for(const r of e.keys())if(r!==Et&&r.startsWith(n)){const s=new Map;return s.set(r.slice(n.length),e.get(r)),new _t(s,t)}}return new _t(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Mt(this._tree,t)}entries(){return new Rt(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 St(t,e,r,n,o,1,s,""),n})(this._tree,t,e)}get(t){const e=Nt(this._tree,t);return void 0!==e?e.get(Et):void 0}has(t){return Nt(this._tree,t)?.has(Et)??!1}keys(){return new Rt(this,It)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Ot(this._tree,t).set(Et,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=Ot(this._tree,t);return r.set(Et,e(r.get(Et))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const r=Ot(this._tree,t);let n=r.get(Et);return void 0===n&&r.set(Et,n=e()),n}values(){return new Rt(this,At)}[Symbol.iterator](){return this.entries()}static from(t){const e=new _t;for(const[r,n]of t)e.set(r,n);return e}static fromObject(t){return _t.from(Object.entries(t))}}const bt=(t,e,r=[])=>{if(0===e.length||null==t)return[t,r];for(const n of t.keys())if(n!==Et&&e.startsWith(n))return r.push([t,n]),bt(t.get(n),e.slice(n.length),r);return r.push([t,e]),bt(void 0,"",r)},Nt=(t,e)=>{if(0===e.length||!t)return t;for(const r of t.keys())if(r!==Et&&e.startsWith(r))return Nt(t.get(r),e.slice(r.length))},Ot=(t,e)=>{const r=e.length;t:for(let n=0;t&&n<r;){for(const s of t.keys())if(s!==Et&&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},Mt=(t,e)=>{const[r,n]=bt(t,e);if(void 0!==r)if(r.delete(Et),0===r.size)Lt(n);else if(1===r.size){const[t,e]=r.entries().next().value;Ut(n,t,e)}},Lt=t=>{if(0===t.length)return;const[e,r]=xt(t);if(e.delete(r),0===e.size)Lt(t.slice(0,-1));else if(1===e.size){const[r,n]=e.entries().next().value;r!==Et&&Ut(t.slice(0,-1),r,n)}},Ut=(t,e,r)=>{if(0===t.length)return;const[n,s]=xt(t);n.set(s+e,r),n.delete(s)},xt=t=>t[t.length-1],kt=/[\n\r\p{Z}\p{P}]+/u,Dt="or",Bt="and",Ft="and_not",Ct=(t,e)=>{t.includes(e)||t.push(e)},Pt=(t,e)=>{for(const r of e)t.includes(r)||t.push(r)},$t=({score:t},{score:e})=>e-t,zt=()=>new Map,jt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Gt={[Dt]:(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),Pt(n.terms,s)}}return t},[Bt]:(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);Pt(s.terms,o),r.set(n,{score:s.score+i,terms:s.terms,match:Object.assign(s.match,a)})}return r},[Ft]:(t,e)=>{for(const r of e.keys())t.delete(r);return t}},Vt=(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)))},Yt=(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")},Jt=(t,e,r,n)=>{const s=t._index.fetch(n,zt);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)}},Wt=(t,e,r,n)=>{if(!t._index.has(n))return void Yt(t,r,e,n);const s=t._index.fetch(n,zt),i=s.get(e),o=i?.get(r);!i||typeof o>"u"?Yt(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)},qt=(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)},Zt=(t,e)=>{const{extractField:r,tokenize:n,processTerm:s,fields:i,idField:o}=t._options,a=r(e,o);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${o}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const u=((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,a);((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,u,e);for(const o of i){const i=r(e,o);if(null==i)continue;const a=n(i.toString(),o),c=t._fieldIds[o],l=new Set(a).size;qt(t,u,c,t._documentCount-1,l);for(const e of a){const r=s(e,o);if(Array.isArray(r))for(const e of r)Jt(t,c,u,e);else r&&Jt(t,c,u,r)}}},Ht={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split(kt),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},Qt={combineWith:Dt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},Xt={combineWith:"and",prefix:(t,e,r)=>e===r.length-1},Kt={minDirtFactor:.1,minDirtCount:20},te={batchSize:1e3,batchWait:10,...Kt},ee=Symbol("*"),re=(t,e=Dt)=>{if(0===t.length)return new Map;const r=e.toLowerCase();if(!(r in Gt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Gt[r])},ne=(t,e,r,n,s,i,o,a,u,c=new Map)=>{if(null==i)return c;for(const l of Object.keys(o)){const h=o[l],f=t._fieldIds[l],d=i.get(f);if(null==d)continue;let p=d.size;const m=t._avgFieldLength[f];for(const i of d.keys()){if(!t._documentIds.has(i)){Wt(t,f,i,r),p-=1;continue}const o=a?a(t._documentIds.get(i),r,t._storedFields.get(i)):1;if(!o)continue;const g=d.get(i),T=t._fieldLength.get(i)[f],v=n*s*h*o*Vt(g,p,t._documentCount,T,m,u),y=c.get(i);if(y){y.score+=v,Ct(y.terms,e);const t=jt(y.match,r);t?t.push(l):y.match[r]=[l]}else c.set(i,{score:v,terms:[e],match:{[r]:[l]}})}}return c},se=(t,e,r={})=>{if(e===ee)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=>se(t,e,n)));return re(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]:jt(n.boost,e)||1})),{}),{boostDocument:i,weights:o,maxFuzzy:a,bm25:u}=n,{fuzzy:c,prefix:l}={...Qt.weights,...o},h=t._index.get(e.term),f=ne(t,e.term,e.term,1,e.termBoost,h,s,i,u);let d,p;if(e.prefix&&(d=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(d)for(const[r,n]of d){const o=r.length-e.term.length;if(!o)continue;p?.delete(r);const a=l*r.length/(r.length+.3*o);ne(t,e.term,r,a,e.termBoost,n,s,i,u,f)}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);ne(t,e.term,r,a,e.termBoost,n,s,i,u,f)}return f})(t,e,o)));return re(c,o.combineWith)};class ie{_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?te:t.autoVacuum;this._options={...Ht,...t,autoVacuum:e,searchOptions:{...Qt,...t.searchOptions},autoSuggestOptions:{...Xt,...t.autoSuggestOptions}},this._index=new _t,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=Kt,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 oe=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 ae;function ue(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return ae.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return ae.STATION;case 2:case"ENTRANCE_EXIT":return ae.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return ae.GENERIC_NODE;case 4:case"BOARDING_AREA":return ae.BOARDING_AREA;default:return ae.UNRECOGNIZED}}!function(t){t[t.SIMPLE_STOP_OR_PLATFORM=0]="SIMPLE_STOP_OR_PLATFORM",t[t.STATION=1]="STATION",t[t.ENTRANCE_EXIT=2]="ENTRANCE_EXIT",t[t.GENERIC_NODE=3]="GENERIC_NODE",t[t.BOARDING_AREA=4]="BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(ae||(ae={}));const ce={encode(t,e=new I){""!==t.name&&e.uint32(10).string(t.name),""!==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:"",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:he(t.name)?globalThis.String(t.name):"",sourceStopId:he(t.sourceStopId)?globalThis.String(t.sourceStopId):"",lat:he(t.lat)?globalThis.Number(t.lat):void 0,lon:he(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:he(t.parent)?globalThis.Number(t.parent):void 0,locationType:he(t.locationType)?ue(t.locationType):0,platform:he(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const r={};return""!==t.name&&(r.name=t.name),""!==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 ae.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case ae.STATION:return"STATION";case ae.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case ae.GENERIC_NODE:return"GENERIC_NODE";case ae.BOARDING_AREA:return"BOARDING_AREA";case ae.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(r.platform=t.platform),r},create:t=>ce.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s,i,o,a,u;const c={name:"",sourceStopId:"",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:"",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 le={encode(t,e=new I){""!==t.version&&e.uint32(10).string(t.version);for(const r of t.stops)ce.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={version:"",stops:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=r.string();continue;case 2:if(18!==t)break;s.stops.push(ce.decode(r,r.uint32()));continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({version:he(t.version)?globalThis.String(t.version):"",stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>ce.fromJSON(t))):[]}),toJSON(t){var e;const r={};return""!==t.version&&(r.version=t.version),(null===(e=t.stops)||void 0===e?void 0:e.length)&&(r.stops=t.stops.map((t=>ce.toJSON(t)))),r},create:t=>le.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={version:"",stops:[]};return n.version=null!==(e=t.version)&&void 0!==e?e:"",n.stops=(null===(r=t.stops)||void 0===r?void 0:r.map((t=>ce.fromPartial(t))))||[],n}};function he(t){return null!=t}const fe="0.0.3",de=t=>({version:fe,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}))}),pe=t=>{if(t.version!==fe)throw new Error(`Unsupported stopMap version ${t.version}`);return 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:me(r.locationType),platform:r.platform};var r}))},me=t=>{switch(t){case ae.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case ae.STATION:return"STATION";case ae.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case ae.GENERIC_NODE:return"GENERIC_NODE";case ae.BOARDING_AREA:return"BOARDING_AREA";case ae.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},ge=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return ae.SIMPLE_STOP_OR_PLATFORM;case"STATION":return ae.STATION;case"ENTRANCE_EXIT":return ae.ENTRANCE_EXIT;case"GENERIC_NODE":return ae.GENERIC_NODE;case"BOARDING_AREA":return ae.BOARDING_AREA}};class Te{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];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 ie({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:oe});const n=Array.from(r.values());((t,e)=>{for(const r of e)Zt(t,r)})(this.textIndex,n),this.geoIndex=new pt(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=le.decode(e);return new Te(pe(r))}serialize(){const t=de(this.stops),e=new I;return le.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=se(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===ee&&null==s.boostDocument||o.sort($t),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=lt(s/6371));const a=new it([],ct);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(r*at);for(;u;){const s=u.right,l=u.left;if(s-l<=t.nodeSize)for(let n=l;n<=s;n++){const s=t.ids[n];{const i=ft(e,r,t.coords[2*n],t.coords[2*n+1],c);a.push({id:s,dist:i})}}else{const n=l+s>>1,i=t.coords[2*n],o=t.coords[2*n+1],h=t.ids[n];{const t=ft(e,r,i,o,c);a.push({id:h,dist:t})}const f=(u.axis+1)%2,d={left:l,right:n-1,axis:f,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:f,minLng:0===u.axis?i:u.minLng,minLat:1===u.axis?o:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};d.dist=ut(e,r,c,d),p.dist=ut(e,r,c,p),a.push(d),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.sourceStopsMap.get(t);if(void 0===n)return[];const s=this.stops[n];if(!s)return[];const i=s.parent?null!==(r=null===(e=this.stops[s.parent])||void 0===e?void 0:e.children)&&void 0!==r?r:[]:s.children;return Array.from(new Set([n,...i])).map((t=>this.stops[t]))}}exports.Duration=t,exports.Plotter=class{constructor(t){this.result=t}plotDotGraph(){const t=this.result.earliestArrivalsPerRound,e=["digraph PathTree {"," graph [overlap=false];"," node [shape=ellipse style=filled fillcolor=lightgrey];"];return t.forEach(((t,r)=>{t.forEach((t=>{const{origin:n,leg:s}=t;if(!s)return;const i=this.result.stopsIndex.findStopById(s.from.id),o=this.result.stopsIndex.findStopById(s.to.id),a=this.result.stopsIndex.findStopById(n);if(i&&o&&a){const t=i.platform?`${i.name} (Pl. ${i.platform})`:i.name,n=o.platform?`${o.name} (Pl. ${o.platform})`:o.name,u=a.platform?`${a.name} (Pl. ${a.platform})`:a.name,c="route"in s,l=c?`${s.route.name}\n${s.departureTime.toString()} - ${s.arrivalTime.toString()}`:s.minTransferTime?s.minTransferTime.toString():"",h=`IntermediateNode${i.id}_${o.id}`,f=c?"":', color="red", fontcolor="red"',d=c?"":' fontcolor="red"';e.push(` "${t} (Origin: ${u}) [R${r}]\n(${i.id})" -> "${h}" [shape=point${f}];`),e.push(` "${h}" [label="${l}" shape=rect style=filled fillcolor=white${d} border=0];`),e.push(` "${h}" -> "${n} (Origin: ${u}) [R${r}]\n(${o.id})" [${f.replace(", ","")}];`)}}))})),e.push("}"),e.join("\n")}},exports.Query=et,exports.Result=nt,exports.Route=rt,exports.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}considerTransfers(e,r,n,s,i){var o,a;const{options:u}=e,c=new Set,l=Array.from(r);for(let e=0;e<l.length;e++){const r=l[e],h=n.get(r);if(!h)continue;const f=h.leg;if(f&&!("route"in f))continue;const d=this.timetable.getTransfers(r);for(let e=0;e<d.length;e++){const l=d[e];let f;f=l.minTransferTime?l.minTransferTime:"IN_SEAT"===l.type?t.zero():u.minTransferTime;const p=h.arrival.plus(f),m=null!==(a=null===(o=n.get(l.destination))||void 0===o?void 0:o.arrival)&&void 0!==a?a:st;if(p.isBefore(m)){const t=h.origin;n.set(l.destination,{arrival:p,legNumber:i,origin:t,leg:{from:this.stopsIndex.findStopById(r),to:this.stopsIndex.findStopById(l.destination),minTransferTime:l.minTransferTime,type:l.type}}),s.set(l.destination,{arrival:p,legNumber:i,origin:t}),c.add(l.destination)}}}const h=Array.from(c);for(let t=0;t<h.length;t++){const e=h[t];r.add(e)}}earliestArrivalAtAnyStop(t,e){var r,n;let s=st;for(let i=0;i<e.length;i++){const o=e[i],a=null!==(n=null===(r=t.get(o.id))||void 0===r?void 0:r.arrival)&&void 0!==n?n:st;s=F.min(s,a)}return s}route(t){var e,r,n,s,i;const{from:o,to:a,departureTime:u,options:c}=t,l=this.stopsIndex.equivalentStops(o),h=Array.from(a).flatMap((t=>this.stopsIndex.equivalentStops(t))),f=new Map,d=new Map,p=[d],m=new Set;for(let t=0;t<l.length;t++){const e=l[t];m.add(e.id),f.set(e.id,{arrival:u,legNumber:0,origin:e.id}),d.set(e.id,{arrival:u,legNumber:0,origin:e.id})}this.considerTransfers(t,m,d,f,0);for(let o=1;o<=c.maxTransfers+1;o++){const a=new Map;p.push(a);const u=p[o-1],l=this.timetable.findReachableRoutes(m,c.transportModes);m.clear();const d=Array.from(l.entries());for(let t=0;t<d.length;t++){const[c,l]=d[t];let p;for(let t=c.stopIndex(l);t<c.getNbStops();t++){const l=c.stops[t];if(void 0!==p){const t=c.arrivalAt(l,p.tripIndex),n=c.dropOffTypeAt(l,p.tripIndex),s=null!==(r=null===(e=f.get(l))||void 0===e?void 0:e.arrival)&&void 0!==r?r:st;if("NOT_AVAILABLE"!==n&&t.isBefore(s)&&t.isBefore(this.earliestArrivalAtAnyStop(f,h))){const e=c.departureFrom(p.bestHopOnStop,p.tripIndex);a.set(l,{arrival:t,legNumber:o,origin:p.origin,leg:{from:this.stopsIndex.findStopById(p.bestHopOnStop),to:this.stopsIndex.findStopById(l),departureTime:e,arrivalTime:t,route:this.timetable.getServiceRouteInfo(c)}}),f.set(l,{arrival:t,legNumber:o,origin:p.origin}),m.add(l)}}const d=null===(n=u.get(l))||void 0===n?void 0:n.arrival;if(void 0!==d&&(void 0===p||d.isBefore(c.arrivalAt(l,p.tripIndex))||d.equals(c.arrivalAt(l,p.tripIndex)))){const t=c.findEarliestTrip(l,d,null==p?void 0:p.tripIndex);void 0!==t&&(p={tripIndex:t,bestHopOnStop:l,origin:null!==(i=null===(s=u.get(l))||void 0===s?void 0:s.origin)&&void 0!==i?i:l})}}}if(this.considerTransfers(t,m,a,f,o),0===m.size)break}return new nt(t,f,p,this.stopsIndex)}},exports.StopsIndex=Te,exports.Time=F,exports.Timetable=tt;
|
|
2
2
|
//# sourceMappingURL=router.cjs.js.map
|