minotor 8.0.0 → 9.0.1
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/.github/workflows/minotor.yml +1 -1
- package/CHANGELOG.md +3 -8
- package/README.md +1 -1
- package/dist/cli.mjs +352 -256
- package/dist/cli.mjs.map +1 -1
- package/dist/gtfs/transfers.d.ts +21 -6
- package/dist/gtfs/trips.d.ts +2 -2
- package/dist/parser.cjs.js +296 -188
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.esm.js +296 -188
- 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/routing/router.d.ts +4 -4
- package/dist/timetable/io.d.ts +3 -3
- package/dist/timetable/proto/timetable.d.ts +6 -4
- package/dist/timetable/route.d.ts +13 -21
- package/dist/timetable/timetable.d.ts +13 -11
- package/dist/timetable/tripBoardingId.d.ts +34 -0
- package/package.json +1 -1
- package/src/__e2e__/timetable/timetable.bin +2 -2
- package/src/cli/repl.ts +53 -67
- package/src/gtfs/__tests__/parser.test.ts +19 -4
- package/src/gtfs/__tests__/transfers.test.ts +598 -318
- package/src/gtfs/__tests__/trips.test.ts +3 -44
- package/src/gtfs/parser.ts +26 -8
- package/src/gtfs/transfers.ts +151 -20
- package/src/gtfs/trips.ts +1 -39
- package/src/routing/__tests__/result.test.ts +10 -10
- package/src/routing/__tests__/router.test.ts +11 -9
- package/src/routing/result.ts +2 -2
- package/src/routing/router.ts +34 -22
- package/src/timetable/__tests__/io.test.ts +8 -7
- package/src/timetable/__tests__/route.test.ts +66 -80
- package/src/timetable/__tests__/timetable.test.ts +32 -29
- package/src/timetable/__tests__/tripBoardingId.test.ts +57 -0
- package/src/timetable/io.ts +21 -20
- package/src/timetable/proto/timetable.proto +6 -4
- package/src/timetable/proto/timetable.ts +84 -48
- package/src/timetable/route.ts +39 -56
- package/src/timetable/timetable.ts +37 -26
- package/src/timetable/tripBoardingId.ts +94 -0
- package/dist/timetable/tripId.d.ts +0 -15
- package/src/timetable/__tests__/tripId.test.ts +0 -27
- package/src/timetable/tripId.ts +0 -29
- /package/dist/timetable/__tests__/{tripId.test.d.ts → tripBoardingId.test.d.ts} +0 -0
package/dist/router.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).minotor={})}(this,(function(t){"use strict";class e{constructor(t){this.totalSeconds=t}static fromSeconds(t){return new e(t)}static fromMinutes(t){return new e(60*t)}static zero(){return new e(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),n=this.totalSeconds%60;return t>0?`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`:`${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}toSeconds(){return this.totalSeconds}add(t){const n=this.totalSeconds+t.toSeconds();return new e(n)}subtract(t){const n=Math.max(0,this.totalSeconds-t.toSeconds());return new e(n)}}function n(){let t=0,e=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(t|=(127&r)<<n,!(128&r))return this.assertBounds(),[t,e]}let n=this.buf[this.pos++];if(t|=(15&n)<<28,e=(112&n)>>4,!(128&n))return this.assertBounds(),[t,e];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(e|=(127&r)<<n,!(128&r))return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function r(t,e,n){for(let r=0;r<28;r+=7){const o=t>>>r,i=!(o>>>7==0&&0==e),s=255&(i?128|o:o);if(n.push(s),!i)return}const r=t>>>28&15|(7&e)<<4,o=!!(e>>3);if(n.push(255&(o?128|r:r)),o){for(let t=3;t<31;t+=7){const r=e>>>t,o=!(r>>>7==0),i=255&(o?128|r:r);if(n.push(i),!o)return}n.push(e>>>31&1)}}const o=4294967296;function i(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let r=0,i=0;function s(e,s){const a=Number(t.slice(e,s));i*=n,r=r*n+a,r>=o&&(i+=r/o|0,r%=o)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),e?u(r,i):a(r,i)}function s(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(o*e+t);const n=16777215&(t>>>24|e<<8),r=e>>16&65535;let i=(16777215&t)+6777216*n+6710656*r,s=n+8147497*r,a=2*r;const u=1e7;return i>=u&&(s+=Math.floor(i/u),i%=u),s>=u&&(a+=Math.floor(s/u),s%=u),a.toString()+c(s)+c(i)}function a(t,e){return{lo:0|t,hi:0|e}}function u(t,e){return e=~e,t?t=1+~t:e+=1,a(t,e)}const c=t=>{const e=String(t);return"0000000".slice(e.length)+e};function l(t,e){if(t>=0){for(;t>127;)e.push(127&t|128),t>>>=7;e.push(t)}else{for(let n=0;n<9;n++)e.push(127&t|128),t>>=7;e.push(1)}}function h(){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 d=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"),n=BigInt("9223372036854775807"),r=BigInt("0"),o=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const r="bigint"==typeof t?t:BigInt(t);if(r>n||r<e)throw new Error(`invalid int64: ${t}`);return r},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>o||e<r)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,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigInt64(0,!0)),uDec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigUint64(0,!0))}}return{zero:"0",supported:!1,parse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),m(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),p(t),i(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),m(t),i(t)),dec:(t,e)=>function(t,e){let n=a(t,e);const r=2147483648&n.hi;r&&(n=u(n.lo,n.hi));const o=s(n.lo,n.hi);return r?"-"+o:o}(t,e),uDec:(t,e)=>s(t,e)}}function p(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function m(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const g=Symbol.for("@bufbuild/protobuf/text-encoding");function v(){if(null==globalThis[g]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[g]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[g]}var I;!function(t){t[t.Varint=0]="Varint",t[t.Bit64=1]="Bit64",t[t.LengthDelimited=2]="LengthDelimited",t[t.StartGroup=3]="StartGroup",t[t.EndGroup=4]="EndGroup",t[t.Bit32=5]="Bit32"}(I||(I={}));const T=34028234663852886e22,y=-34028234663852886e22;class S{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),n=0;for(let t=0;t<this.chunks.length;t++)e.set(this.chunks[t],n),n+=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 A(t),l(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){R(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),l(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=d.enc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(e)}fixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=d.uEnc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(e)}int64(t){let e=d.enc(t);return r(e.lo,e.hi,this.buf),this}sint64(t){const e=d.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=d.uEnc(t);return r(e.lo,e.hi,this.buf),this}}class E{constructor(t,e=v().decodeUtf8){this.decodeUtf8=e,this.varint64=n,this.uint32=h,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,n=7&t;if(e<=0||n<0||n>5)throw new Error("illegal tag: field no "+e+" wire type "+n);return[e,n]}skip(t,e){let n=this.pos;switch(t){case I.Varint:for(;128&this.buf[this.pos++];);break;case I.Bit64:this.pos+=4;case I.Bit32:this.pos+=4;break;case I.LengthDelimited:let n=this.uint32();this.pos+=n;break;case I.StartGroup:for(;;){const[t,n]=this.tag();if(n===I.EndGroup){if(void 0!==e&&t!==e)throw new Error("invalid end group tag");break}this.skip(n,t)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(n,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 d.dec(...this.varint64())}uint64(){return d.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),n=-(1&t);return t=(t>>>1|(1&e)<<31)^n,e=e>>>1^n,d.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 d.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return d.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 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,b;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 N(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 O(){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"}(b||(b={}));const M={encode:(t,e=new S)=>(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 n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o=O();for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;o.stopTimes=n.bytes();continue;case 2:if(18!==t)break;o.pickUpDropOffTypes=n.bytes();continue;case 3:if(26!==t)break;o.stops=n.bytes();continue;case 4:if(32!==t)break;o.serviceRouteId=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({stopTimes:F(t.stopTimes)?C(t.stopTimes):new Uint8Array(0),pickUpDropOffTypes:F(t.pickUpDropOffTypes)?C(t.pickUpDropOffTypes):new Uint8Array(0),stops:F(t.stops)?C(t.stops):new Uint8Array(0),serviceRouteId:F(t.serviceRouteId)?globalThis.Number(t.serviceRouteId):0}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=B(t.stopTimes)),0!==t.pickUpDropOffTypes.length&&(e.pickUpDropOffTypes=B(t.pickUpDropOffTypes)),0!==t.stops.length&&(e.stops=B(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,o;const i=O();return i.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),i.pickUpDropOffTypes=null!==(n=t.pickUpDropOffTypes)&&void 0!==n?n:new Uint8Array(0),i.stops=null!==(r=t.stops)&&void 0!==r?r:new Uint8Array(0),i.serviceRouteId=null!==(o=t.serviceRouteId)&&void 0!==o?o:0,i}};const U={encode:(t,e=new S)=>(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 n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={destination:0,type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;o.destination=n.uint32();continue;case 2:if(16!==t)break;o.type=n.int32();continue;case 3:if(24!==t)break;o.minTransferTime=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({destination:F(t.destination)?globalThis.Number(t.destination):0,type:F(t.type)?_(t.type):0,minTransferTime:F(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=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const o={destination:0,type:0,minTransferTime:void 0};return o.destination=null!==(e=t.destination)&&void 0!==e?e:0,o.type=null!==(n=t.type)&&void 0!==n?n:0,o.minTransferTime=null!==(r=t.minTransferTime)&&void 0!==r?r:void 0,o}};const L={encode:(t,e=new S)=>(0!==t.hopOnStop&&e.uint32(8).uint32(t.hopOnStop),0!==t.routeId&&e.uint32(16).uint32(t.routeId),0!==t.tripIndex&&e.uint32(24).uint32(t.tripIndex),e),decode(t,e){const n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={hopOnStop:0,routeId:0,tripIndex:0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;o.hopOnStop=n.uint32();continue;case 2:if(16!==t)break;o.routeId=n.uint32();continue;case 3:if(24!==t)break;o.tripIndex=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({hopOnStop:F(t.hopOnStop)?globalThis.Number(t.hopOnStop):0,routeId:F(t.routeId)?globalThis.Number(t.routeId):0,tripIndex:F(t.tripIndex)?globalThis.Number(t.tripIndex):0}),toJSON(t){const e={};return 0!==t.hopOnStop&&(e.hopOnStop=Math.round(t.hopOnStop)),0!==t.routeId&&(e.routeId=Math.round(t.routeId)),0!==t.tripIndex&&(e.tripIndex=Math.round(t.tripIndex)),e},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const o={hopOnStop:0,routeId:0,tripIndex:0};return o.hopOnStop=null!==(e=t.hopOnStop)&&void 0!==e?e:0,o.routeId=null!==(n=t.routeId)&&void 0!==n?n:0,o.tripIndex=null!==(r=t.tripIndex)&&void 0!==r?r:0,o}};const x={encode(t,e=new S){0!==t.key&&e.uint32(8).uint32(t.key);for(const n of t.value)L.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={key:0,value:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;o.key=n.uint32();continue;case 2:if(18!==t)break;o.value.push(L.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({key:F(t.key)?globalThis.Number(t.key):0,value:globalThis.Array.isArray(null==t?void 0:t.value)?t.value.map((t=>L.fromJSON(t))):[]}),toJSON(t){var e;const n={};return 0!==t.key&&(n.key=Math.round(t.key)),(null===(e=t.value)||void 0===e?void 0:e.length)&&(n.value=t.value.map((t=>L.toJSON(t)))),n},create:t=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={key:0,value:[]};return r.key=null!==(e=t.key)&&void 0!==e?e:0,r.value=(null===(n=t.value)||void 0===n?void 0:n.map((t=>L.fromPartial(t))))||[],r}};const k={encode(t,e=new S){e.uint32(10).fork();for(const n of t.routes)e.uint32(n);e.join();for(const n of t.transfers)U.encode(n,e.uint32(18).fork()).join();for(const n of t.tripContinuations)x.encode(n,e.uint32(26).fork()).join();return e},decode(t,e){const n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={routes:[],transfers:[],tripContinuations:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8===t){o.routes.push(n.uint32());continue}if(10===t){const t=n.uint32()+n.pos;for(;n.pos<t;)o.routes.push(n.uint32());continue}break;case 2:if(18!==t)break;o.transfers.push(U.decode(n,n.uint32()));continue;case 3:if(26!==t)break;o.tripContinuations.push(x.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[],transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>U.fromJSON(t))):[],tripContinuations:globalThis.Array.isArray(null==t?void 0:t.tripContinuations)?t.tripContinuations.map((t=>x.fromJSON(t))):[]}),toJSON(t){var e,n,r;const o={};return(null===(e=t.routes)||void 0===e?void 0:e.length)&&(o.routes=t.routes.map((t=>Math.round(t)))),(null===(n=t.transfers)||void 0===n?void 0:n.length)&&(o.transfers=t.transfers.map((t=>U.toJSON(t)))),(null===(r=t.tripContinuations)||void 0===r?void 0:r.length)&&(o.tripContinuations=t.tripContinuations.map((t=>x.toJSON(t)))),o},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const o={routes:[],transfers:[],tripContinuations:[]};return o.routes=(null===(e=t.routes)||void 0===e?void 0:e.map((t=>t)))||[],o.transfers=(null===(n=t.transfers)||void 0===n?void 0:n.map((t=>U.fromPartial(t))))||[],o.tripContinuations=(null===(r=t.tripContinuations)||void 0===r?void 0:r.map((t=>x.fromPartial(t))))||[],o}};const D={encode(t,e=new S){0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e.uint32(26).fork();for(const n of t.routes)e.uint32(n);return e.join(),e},decode(t,e){const n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={type:0,name:"",routes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;o.type=n.int32();continue;case 2:if(18!==t)break;o.name=n.string();continue;case 3:if(24===t){o.routes.push(n.uint32());continue}if(26===t){const t=n.uint32()+n.pos;for(;n.pos<t;)o.routes.push(n.uint32());continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({type:F(t.type)?N(t.type):0,name:F(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 n={};return 0!==t.type&&(n.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&&(n.name=t.name),(null===(e=t.routes)||void 0===e?void 0:e.length)&&(n.routes=t.routes.map((t=>Math.round(t)))),n},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const o={type:0,name:"",routes:[]};return o.type=null!==(e=t.type)&&void 0!==e?e:0,o.name=null!==(n=t.name)&&void 0!==n?n:"",o.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],o}};const $={encode(t,e=new S){""!==t.version&&e.uint32(10).string(t.version);for(const n of t.stopsAdjacency)k.encode(n,e.uint32(18).fork()).join();for(const n of t.routesAdjacency)M.encode(n,e.uint32(26).fork()).join();for(const n of t.serviceRoutes)D.encode(n,e.uint32(34).fork()).join();return e},decode(t,e){const n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={version:"",stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;o.version=n.string();continue;case 2:if(18!==t)break;o.stopsAdjacency.push(k.decode(n,n.uint32()));continue;case 3:if(26!==t)break;o.routesAdjacency.push(M.decode(n,n.uint32()));continue;case 4:if(34!==t)break;o.serviceRoutes.push(D.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({version:F(t.version)?globalThis.String(t.version):"",stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>k.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>M.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>D.fromJSON(t))):[]}),toJSON(t){var e,n,r;const o={};return""!==t.version&&(o.version=t.version),(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(o.stopsAdjacency=t.stopsAdjacency.map((t=>k.toJSON(t)))),(null===(n=t.routesAdjacency)||void 0===n?void 0:n.length)&&(o.routesAdjacency=t.routesAdjacency.map((t=>M.toJSON(t)))),(null===(r=t.serviceRoutes)||void 0===r?void 0:r.length)&&(o.serviceRoutes=t.serviceRoutes.map((t=>D.toJSON(t)))),o},create:t=>$.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,o;const i={version:"",stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[]};return i.version=null!==(e=t.version)&&void 0!==e?e:"",i.stopsAdjacency=(null===(n=t.stopsAdjacency)||void 0===n?void 0:n.map((t=>k.fromPartial(t))))||[],i.routesAdjacency=(null===(r=t.routesAdjacency)||void 0===r?void 0:r.map((t=>M.fromPartial(t))))||[],i.serviceRoutes=(null===(o=t.serviceRoutes)||void 0===o?void 0:o.map((t=>D.fromPartial(t))))||[],i}};function C(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n}}function B(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 F(t){return null!=t}class P{static infinity(){return new P(Number.MAX_SAFE_INTEGER)}static origin(){return new P(0)}constructor(t){this.minutesSinceMidnight=t}static fromMinutes(t){return new P(t)}static fromHMS(t,e,n){if(t<0||e<0||n<0||e>=60||n>=60)throw new Error("Invalid time. Ensure hours, minutes, and seconds are valid values.");const r=n+60*e+3600*t,o=Math.round(r/60);return new P(o)}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 P(e+60*t)}static fromDate(t){const e=t.getHours(),n=t.getMinutes(),r=t.getSeconds();return P.fromHMS(e,n,r)}static fromString(t){const[e,n,r]=t.split(":");if(void 0===e||void 0===n||""===e.trim()||""===n.trim()||isNaN(Number(e))||isNaN(Number(n))||void 0!==r&&(""===r.trim()||isNaN(Number(r))))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const o=parseInt(e,10),i=parseInt(n,10),s=void 0!==r?parseInt(r,10):0;return P.fromHMS(o,i,s)}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 P(Math.round(e/60))}minus(t){let e=60*this.minutesSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new P(Math.round(e/60))}diff(t){const n=this.minutesSinceMidnight-t.toMinutes();return e.fromSeconds(Math.abs(60*n))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");let e=t[0];for(let n=1;n<t.length;n++)t[n].minutesSinceMidnight>e.minutesSinceMidnight&&(e=t[n]);return e}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");let e=t[0];for(let n=1;n<t.length;n++)t[n].minutesSinceMidnight<e.minutesSinceMidnight&&(e=t[n]);return e}isAfter(t){return this.minutesSinceMidnight>t.minutesSinceMidnight}isBefore(t){return this.minutesSinceMidnight<t.minutesSinceMidnight}equals(t){return this.minutesSinceMidnight===t.minutesSinceMidnight}}const z=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],j=t=>{const e=z[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};let G=class t{constructor(t,e,n,r,o){this.id=t,this.stopTimes=e,this.pickUpDropOffTypes=n,this.stops=r,this.serviceRouteId=o,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)}static of(e){var n,r;const{id:o,serviceRouteId:i,trips:s}=e;if(0===s.length)throw new Error("At least one trip must be provided");const a=s[0],u=new Uint32Array(a.stops.map((t=>t.id))),c=u.length;for(let t=1;t<s.length;t++){const e=s[t];if(e.stops.length!==c)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${c}`);for(let n=0;n<c;n++)if(e.stops[n].id!==u[n])throw new Error(`Trip ${t} has different stop at index ${n}`)}const l=new Uint16Array(s.length*c*2);for(let t=0;t<s.length;t++){const e=s[t];for(let n=0;n<c;n++){const r=e.stops[n],o=2*(t*c+n);l[o]=r.arrivalTime.toMinutes(),l[o+1]=r.departureTime.toMinutes()}}const h=s.length*c,d=new Uint8Array(Math.ceil(h/2));for(let t=0;t<s.length;t++){const e=s[t];for(let o=0;o<c;o++){const i=e.stops[o],s=t*c+o,a=null!==(n=i.pickUpType)&&void 0!==n?n:0,u=null!==(r=i.dropOffType)&&void 0!==r?r:0,l=Math.floor(s/2),h=s%2==1;d[l]|=h?a<<6|u<<4:a<<2|u}}return new t(o,l,d,u,i)}serialize(){return{stopTimes:this.stopTimes,pickUpDropOffTypes:this.pickUpDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}isBefore(t,e){const n=this.stopIndices.get(t);if(void 0===n)throw new Error(`Stop index not found for ${t} in route ${this.serviceRouteId}`);const r=this.stopIndices.get(e);if(void 0===r)throw new Error(`Stop index not found for ${e} in route ${this.serviceRouteId}`);return n<r}getNbStops(){return this.nbStops}getNbTrips(){return this.nbTrips}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const n=2*(e*this.stops.length+this.stopRouteIndex(t)),r=this.stopTimes[n];if(void 0===r)throw new Error(`Arrival time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return P.fromMinutes(r)}departureFrom(t,e){const n=2*(e*this.stops.length+this.stopRouteIndex(t))+1,r=this.stopTimes[n];if(void 0===r)throw new Error(`Departure time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return P.fromMinutes(r)}pickUpTypeFrom(t,e){const n=e*this.stops.length+this.stopRouteIndex(t),r=Math.floor(n/2),o=n%2==1,i=this.pickUpDropOffTypes[r];if(void 0===i)throw new Error(`Pick up type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return j(o?i>>6&3:i>>2&3)}dropOffTypeAt(t,e){const n=e*this.stops.length+this.stopRouteIndex(t),r=Math.floor(n/2),o=n%2==1,i=this.pickUpDropOffTypes[r];if(void 0===i)throw new Error(`Drop off type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return j(o?i>>4&3:3&i)}findEarliestTrip(t,e=P.origin(),n){if(this.nbTrips<=0)return;let r=this.nbTrips-1;if(void 0!==n&&(r=Math.min(r,n-1)),r<0)return;let o=0,i=-1;for(;o<=r;){const n=o+r>>>1;this.departureFrom(t,n).isBefore(e)?o=n+1:(i=n,r=n-1)}if(-1!==i)for(let e=i;e<(null!=n?n:this.nbTrips);e++){if("NOT_AVAILABLE"!==this.pickUpTypeFrom(t,e))return e}}stopRouteIndex(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}stopId(t){const e=this.stops[t];if(void 0===e)throw new Error(`StopId for stop at index ${t} not found in route ${this.serviceRouteId}`);return e}};const V=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),Y=!0,J=t=>{if(V===Y)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint32(4*e,t[e],Y);return e},W=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(V===Y)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint32(4*t,Y);return e},q=t=>{if(V===Y)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint16(2*e,t[e],Y);return e},Z=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(V===Y)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint16(2*t,Y);return e},H=t=>{const e=[];return t.forEach((t=>{const n=t.serialize();e.push({stopTimes:q(n.stopTimes),pickUpDropOffTypes:n.pickUpDropOffTypes,stops:J(n.stops),serviceRouteId:n.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.")}},X=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}},K=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.")}},tt=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}},et=t=>{const e=[];for(const[n,r]of t.entries())e.push({key:n,value:r.map((t=>({hopOnStop:t.hopOnStop,routeId:t.routeId,tripIndex:t.tripIndex})))});return e},nt=t=>{const e=new Map;for(let n=0;n<t.length;n++){const r=t[n],o=r.value.map((t=>({hopOnStop:t.hopOnStop,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(r.key,o)}return e},rt=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),ot=[],it="0.0.8";class st{constructor(t,e,n){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=n,this.activeStops=new Set;for(let e=0;e<t.length;e++){const n=t[e];(n.routes.length>0||n.transfers&&n.transfers.length>0||n.tripContinuations&&n.tripContinuations.size>0)&&this.activeStops.add(e)}}serialize(){const t={version:it,stopsAdjacency:(n=this.stopsAdjacency,n.map((t=>({transfers:t.transfers?t.transfers.map((t=>Object.assign({destination:t.destination,type:X(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))):[],routes:t.routes,tripContinuations:t.tripContinuations?et(t.tripContinuations):[]})))),routesAdjacency:H(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:tt(t.type),name:t.name,routes:t.routes}))))};var e,n;const r=new S;return $.encode(t,r),r.finish()}static fromData(t){const n=new E(t),r=$.decode(n);if(r.version!==it)throw new Error(`Unsupported timetable version ${r.version}`);return new st((t=>{const n=[];for(let r=0;r<t.length;r++){const o=t[r],i=[];for(let t=0;t<o.transfers.length;t++){const n=o.transfers[t],r=Object.assign({destination:n.destination,type:Q(n.type)},void 0!==n.minTransferTime&&{minTransferTime:e.fromSeconds(n.minTransferTime)});i.push(r)}const s={routes:o.routes};i.length>0&&(s.transfers=i);const a=nt(o.tripContinuations);a.size>0&&(s.tripContinuations=a),n.push(s)}return n})(r.stopsAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],o=W(r.stops);e.push(new G(n,Z(r.stopTimes),r.pickUpDropOffTypes,o,r.serviceRouteId))}return e})(r.routesAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n];e.push({type:K(r.type),name:r.name,routes:r.routes})}return e})(r.serviceRoutes))}isActive(t){return this.activeStops.has(t)}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){const e=this.stopsAdjacency[t];if(!e)throw new Error(`Stop ID ${t} not found`);return e.transfers||[]}getContinuousTrips(t,e,n){var r;const o=this.stopsAdjacency[t];if(!o)throw new Error(`Stop ID ${t} not found`);return(null===(r=o.tripContinuations)||void 0===r?void 0:r.get(((t,e)=>t<<15|e)(e,n)))||ot}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);return{type:e.type,name:e.name}}routesPassingThrough(t){const e=this.stopsAdjacency[t];if(!e)return[];const n=[];for(let t=0;t<e.routes.length;t++){const r=e.routes[t],o=this.routesAdjacency[r];o&&n.push(o)}return n}findReachableRoutes(t,e=rt){const n=new Map,r=Array.from(t);for(let t=0;t<r.length;t++){const o=r[t],i=this.routesPassingThrough(o).filter((t=>{const n=this.getServiceRouteInfo(t);return e.has(n.type)}));for(let t=0;t<i.length;t++){const e=i[t],r=n.get(e);r?e.isBefore(o,r)&&n.set(e,o):n.set(e,o)}}return n}}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:e.fromSeconds(120),transportModes:rt}}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 t=e.zero();for(let e=0;e<this.legs.length;e++){const n=this.legs[e];if("departureTime"in n)return n.departureTime.minus(t);"minTransferTime"in n&&n.minTransferTime&&t.add(n.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let t=P.origin();const n=e.zero();let r=!1;for(let e=this.legs.length-1;e>=0;e--){const o=this.legs[e];"arrivalTime"in o&&!r?(t=o.arrivalTime,r=!0):"minTransferTime"in o&&o.minTransferTime&&r&&n.add(o.minTransferTime)}if(!r)throw new Error("No vehicle leg found in route");return t.plus(n)}totalDuration(){return 0===this.legs.length?e.zero():this.arrivalTime().diff(this.departureTime())}toString(){return this.legs.map(((t,e)=>{var n;const r=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,o=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,i="minTransferTime"in t?`Minimum Transfer Time: ${null===(n=t.minTransferTime)||void 0===n?void 0:n.toString()}`:"",s="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}:`,` ${r}`,` ${o}`,i?` ${i}`:"",s?` ${s}`:""].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,n,r){this.query=t,this.routingState=e,this.stopsIndex=n,this.timetable=r}bestRoute(t){var e;const n=(t instanceof Set?Array.from(t):t?[t]:Array.from(this.query.to)).flatMap((t=>this.stopsIndex.equivalentStops(t)));let r,o;for(const t of n){const e=this.routingState.earliestArrivals.get(t.id);void 0!==e&&(void 0===o||e.arrival.isBefore(o.arrival))&&(r=t.id,o=e)}if(!r||!o)return;const i=[];let s=r,a=o.legNumber;for(;a>0;){const t=null===(e=this.routingState.graph[a])||void 0===e?void 0:e.get(s);if(!t)throw new Error(`No edge arriving at stop ${s} at round ${a}`);let n;if("routeId"in t){let e=t;const r=[e];for(;"routeId"in e&&e.continuationOf;)r.push(e.continuationOf),e=e.continuationOf;n=this.buildVehicleLeg(r)}else{if(!("type"in t))break;n=this.buildTransferLeg(t)}i.unshift(n),s=n.from.id,"routeId"in t&&(a-=1)}return new ut(i)}buildVehicleLeg(t){if(0===t.length)throw new Error("Cannot build vehicle leg from empty edges");const e=t[t.length-1],n=t[0],r=this.timetable.getRoute(e.routeId),o=this.timetable.getRoute(n.routeId);return{from:this.stopsIndex.findStopById(e.from),to:this.stopsIndex.findStopById(n.to),route:this.timetable.getServiceRouteInfo(r),departureTime:r.departureFrom(e.from,e.tripIndex),arrivalTime:n.arrival,pickUpType:r.pickUpTypeFrom(e.from,e.tripIndex),dropOffType:o.dropOffTypeAt(n.to,n.tripIndex)}}buildTransferLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),minTransferTime:t.minTransferTime,type:t.type}}arrivalAt(t,e){var n;const r=this.stopsIndex.equivalentStops(t);let o;for(const t of r){let r;if(void 0===e)r=this.routingState.earliestArrivals.get(t.id);else for(let o=e+1;o>=0;o--){const e=null===(n=this.routingState.graph[o])||void 0===n?void 0:n.get(t.id);if(void 0!==e){r={arrival:e.arrival,legNumber:o};break}}void 0!==r&&(void 0===o||r.arrival.isBefore(o.arrival))&&(o=r)}return o}}const lt=P.infinity();class ht{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:n}=this,r=e[t];for(;t>0;){const o=t-1>>1,i=e[o];if(n(r,i)>=0)break;e[t]=i,t=o}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,o=e[t];for(;t<r;){let r=1+(t<<1),i=e[r];const s=r+1;if(s<this.length&&n(e[s],i)<0&&(r=s,i=e[s]),n(i,o)>=0)break;e[t]=i,t=r}e[t]=o}}function dt(t,e){return t<e?-1:t>e?1:0}const ft=Math.PI/180;function pt(t,e,n,r){const o=r.minLng,i=r.maxLng,s=r.minLat,a=r.maxLat;if(t>=o&&t<=i)return e<s?gt((e-s)*ft):e>a?gt((e-a)*ft):0;const u=Math.min(gt((t-o)*ft),gt((t-i)*ft)),c=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*ft)/n)/ft}(e,u);return c>s&&c<a?vt(u,n,e,c):Math.min(vt(u,n,e,s),vt(u,n,e,a))}function mt(t,e){return t.dist-e.dist}function gt(t){const e=Math.sin(t/2);return e*e}function vt(t,e,n,r){return e*Math.cos(r*ft)*t+gt((n-r)*ft)}function It(t,e,n,r,o){return vt(gt((t-n)*ft),o,e,r)}const Tt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class yt{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const r=n>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const o=Tt[15&n];if(!o)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[s]=new Uint32Array(t,4,1);return new yt(s,i,o,t)}constructor(t,e=64,n=Float64Array,r){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=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const o=Tt.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,s=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-s%8)%8;if(o<0)throw new Error(`Unexpected typed array class: ${n}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+s+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+o]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return St(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:o,coords:i,nodeSize:s}=this,a=[0,o.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,l=a.pop()||0,h=a.pop()||0;if(l-h<=s){for(let s=h;s<=l;s++){const a=i[2*s],c=i[2*s+1];a>=t&&a<=n&&c>=e&&c<=r&&u.push(o[s])}continue}const d=h+l>>1,f=i[2*d],p=i[2*d+1];f>=t&&f<=n&&p>=e&&p<=r&&u.push(o[d]),(0===c?t<=f:e<=p)&&(a.push(h),a.push(d-1),a.push(1-c)),(0===c?n>=f:r>=p)&&(a.push(d+1),a.push(l),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:o,nodeSize:i}=this,s=[0,r.length-1,0],a=[],u=n*n;for(;s.length;){const c=s.pop()||0,l=s.pop()||0,h=s.pop()||0;if(l-h<=i){for(let n=h;n<=l;n++)wt(o[2*n],o[2*n+1],t,e)<=u&&a.push(r[n]);continue}const d=h+l>>1,f=o[2*d],p=o[2*d+1];wt(f,p,t,e)<=u&&a.push(r[d]),(0===c?t-n<=f:e-n<=p)&&(s.push(h),s.push(d-1),s.push(1-c)),(0===c?t+n>=f:e+n>=p)&&(s.push(d+1),s.push(l),s.push(1-c))}return a}}function St(t,e,n,r,o,i){if(o-r<=n)return;const s=r+o>>1;Et(t,e,s,r,o,i),St(t,e,n,r,s-1,1-i),St(t,e,n,s+1,o,1-i)}function Et(t,e,n,r,o,i){for(;o>r;){if(o-r>600){const s=o-r+1,a=n-r+1,u=Math.log(s),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(s-c)/s)*(a-s/2<0?-1:1);Et(t,e,n,Math.max(r,Math.floor(n-a*c/s+l)),Math.min(o,Math.floor(n+(s-a)*c/s+l)),i)}const s=e[2*n+i];let a=r,u=o;for(At(t,e,r,n),e[2*o+i]>s&&At(t,e,r,o);a<u;){for(At(t,e,a,u),a++,u--;e[2*a+i]<s;)a++;for(;e[2*u+i]>s;)u--}e[2*r+i]===s?At(t,e,r,u):(u++,At(t,e,u,o)),u<=n&&(r=u+1),n<=u&&(o=u-1)}}function At(t,e,n,r){Rt(t,n,r),Rt(e,2*n,2*r),Rt(e,2*n+1,2*r+1)}function Rt(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function wt(t,e,n,r){const o=t-n,i=e-r;return o*o+i*i}const bt="KEYS",_t="VALUES",Nt="";class Ot{set;_type;_path;constructor(t,e){const n=t._tree,r=Array.from(n.keys());this.set=t,this._type=e,this._path=r.length>0?[{node:n,keys:r}]:[]}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 n=t.get(Mt(e));return this._path.push({node:n,keys:Array.from(n.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 bt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Mt=t=>t[t.length-1],Ut=(t,e,n,r,o,i,s,a)=>{const u=i*s;t:for(const c of t.keys())if(c===Nt){const e=o[u-1];e<=n&&r.set(a,[t.get(c),e])}else{let u=i;for(let t=0;t<c.length;++t,++u){const r=c[t],i=s*u,a=i-s;let l=o[i];const h=Math.max(0,u-n-1),d=Math.min(s-1,u+n);for(let t=h;t<d;++t){const n=r!==e[t],s=o[a+t]+ +n,u=o[a+t+1]+1,c=o[i+t]+1,h=o[i+t+1]=Math.min(s,u,c);h<l&&(l=h)}if(l>n)continue t}Ut(t.get(c),e,n,r,o,u,s,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,n]=xt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=Ft(n);for(const n of e.keys())if(n!==Nt&&n.startsWith(r)){const o=new Map;return o.set(n.slice(r.length),e.get(n)),new Lt(o,t)}}return new Lt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,$t(this._tree,t)}entries(){return new Ot(this,"ENTRIES")}forEach(t){for(const[e,n]of this)t(e,n,this)}fuzzyGet(t,e){return((t,e,n)=>{const r=new Map;if("string"!=typeof e)return r;const o=e.length+1,i=o+n,s=new Uint8Array(i*o).fill(n+1);for(let t=0;t<o;++t)s[t]=t;for(let t=1;t<i;++t)s[t*o]=t;return Ut(t,e,n,r,s,1,o,""),r})(this._tree,t,e)}get(t){const e=kt(this._tree,t);return void 0!==e?e.get(Nt):void 0}has(t){return kt(this._tree,t)?.has(Nt)??!1}keys(){return new Ot(this,bt)}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 n=Dt(this._tree,t);return n.set(Nt,e(n.get(Nt))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Dt(this._tree,t);let r=n.get(Nt);return void 0===r&&n.set(Nt,r=e()),r}values(){return new Ot(this,_t)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Lt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return Lt.from(Object.entries(t))}}const xt=(t,e,n=[])=>{if(0===e.length||null==t)return[t,n];for(const r of t.keys())if(r!==Nt&&e.startsWith(r))return n.push([t,r]),xt(t.get(r),e.slice(r.length),n);return n.push([t,e]),xt(void 0,"",n)},kt=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(n!==Nt&&e.startsWith(n))return kt(t.get(n),e.slice(n.length))},Dt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const o of t.keys())if(o!==Nt&&e[r]===o[0]){const i=Math.min(n-r,o.length);let s=1;for(;s<i&&e[r+s]===o[s];)++s;const a=t.get(o);if(s===o.length)t=a;else{const n=new Map;n.set(o.slice(s),a),t.set(e.slice(r,r+s),n),t.delete(o),t=n}r+=s;continue t}const o=new Map;return t.set(e.slice(r),o),o}return t},$t=(t,e)=>{const[n,r]=xt(t,e);if(void 0!==n)if(n.delete(Nt),0===n.size)Ct(r);else if(1===n.size){const[t,e]=n.entries().next().value;Bt(r,t,e)}},Ct=t=>{if(0===t.length)return;const[e,n]=Ft(t);if(e.delete(n),0===e.size)Ct(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;n!==Nt&&Bt(t.slice(0,-1),n,r)}},Bt=(t,e,n)=>{if(0===t.length)return;const[r,o]=Ft(t);r.set(o+e,n),r.delete(o)},Ft=t=>t[t.length-1],Pt=/[\n\r\p{Z}\p{P}]+/u,zt="or",jt="and",Gt="and_not",Vt=(t,e)=>{t.includes(e)||t.push(e)},Yt=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},Jt=({score:t},{score:e})=>e-t,Wt=()=>new Map,qt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Zt={[zt]:(t,e)=>{for(const n of e.keys()){const r=t.get(n);if(null==r)t.set(n,e.get(n));else{const{score:t,terms:o,match:i}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,i),Yt(r.terms,o)}}return t},[jt]:(t,e)=>{const n=new Map;for(const r of e.keys()){const o=t.get(r);if(null==o)continue;const{score:i,terms:s,match:a}=e.get(r);Yt(o.terms,s),n.set(r,{score:o.score+i,terms:o.terms,match:Object.assign(o.match,a)})}return n},[Gt]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},Ht=(t,e,n,r,o,i)=>{const{k:s,b:a,d:u}=i;return Math.log(1+(n-e+.5)/(e+.5))*(u+t*(s+1)/(t+s*(1-a+a*r/o)))},Qt=(t,e,n,r)=>{for(const o of Object.keys(t._fieldIds))if(t._fieldIds[o]===n)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${r}" was not present in field "${o}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},Xt=(t,e,n,r)=>{const o=t._index.fetch(r,Wt);let i=o.get(e);if(null==i)i=new Map,i.set(n,1),o.set(e,i);else{const t=i.get(n);i.set(n,(t??0)+1)}},Kt=(t,e,n,r)=>{if(!t._index.has(r))return void Qt(t,n,e,r);const o=t._index.fetch(r,Wt),i=o.get(e),s=i?.get(n);!i||typeof s>"u"?Qt(t,n,e,r):s<=1?i.size<=1?o.delete(e):i.delete(n):i.set(n,s-1),0===t._index.get(r).size&&t._index.delete(r)},te=(t,e,n,r,o)=>{let i=t._fieldLength.get(e);null==i&&t._fieldLength.set(e,i=[]),i[n]=o;const s=(t._avgFieldLength[n]||0)*r+o;t._avgFieldLength[n]=s/(r+1)},ee=(t,e)=>{const{extractField:n,tokenize:r,processTerm:o,fields:i,idField:s}=t._options,a=n(e,s);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${s}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const u=((t,e)=>{const n=t._nextId;return t._idToShortId.set(e,n),t._documentIds.set(n,e),t._documentCount+=1,t._nextId+=1,n})(t,a);((t,e,n)=>{const{storeFields:r,extractField:o}=t._options;if(0===r?.length)return;let i=t._storedFields.get(e);void 0===i&&t._storedFields.set(e,i={});for(const t of r){const e=o(n,t);null!=e&&(i[t]=e)}})(t,u,e);for(const s of i){const i=n(e,s);if(null==i)continue;const a=r(i.toString(),s),c=t._fieldIds[s],l=new Set(a).size;te(t,u,c,t._documentCount-1,l);for(const e of a){const n=o(e,s);if(Array.isArray(n))for(const e of n)Xt(t,c,u,e);else n&&Xt(t,c,u,n)}}},ne={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split(Pt),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},re={combineWith:zt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},oe={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},ie={minDirtFactor:.1,minDirtCount:20},se={batchSize:1e3,batchWait:10,...ie},ae=Symbol("*"),ue=(t,e=zt)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in Zt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Zt[n])},ce=(t,e,n,r,o,i,s,a,u,c=new Map)=>{if(null==i)return c;for(const l of Object.keys(s)){const h=s[l],d=t._fieldIds[l],f=i.get(d);if(null==f)continue;let p=f.size;const m=t._avgFieldLength[d];for(const i of f.keys()){if(!t._documentIds.has(i)){Kt(t,d,i,n),p-=1;continue}const s=a?a(t._documentIds.get(i),n,t._storedFields.get(i)):1;if(!s)continue;const g=f.get(i),v=t._fieldLength.get(i)[d],I=r*o*h*s*Ht(g,p,t._documentCount,v,m,u),T=c.get(i);if(T){T.score+=I,Vt(T.terms,e);const t=qt(T.match,n);t?t.push(l):T.match[n]=[l]}else c.set(i,{score:I,terms:[e],match:{[n]:[l]}})}}return c},le=(t,e,n={})=>{if(e===ae)return((t,e)=>{const n=new Map,r={...t._options.searchOptions,...e};for(const[e,o]of t._documentIds){const i=r.boostDocument?r.boostDocument(o,"",t._storedFields.get(e)):1;n.set(e,{score:i,terms:[],match:{}})}return n})(t,n);if("string"!=typeof e){const r={...n,...e,queries:void 0},o=e.queries.map((e=>le(t,e,r)));return ue(o,r.combineWith)}const{tokenize:r,processTerm:o,searchOptions:i}=t._options,s={tokenize:r,processTerm:o,...i,...n},{tokenize:a,processTerm:u}=s,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,n,r)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,n,r):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,n,r):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,n,r):1}))(s)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},o=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:qt(r.boost,e)||1})),{}),{boostDocument:i,weights:s,maxFuzzy:a,bm25:u}=r,{fuzzy:c,prefix:l}={...re.weights,...s},h=t._index.get(e.term),d=ce(t,e.term,e.term,1,e.termBoost,h,o,i,u);let f,p;if(e.prefix&&(f=t._index.atPrefix(e.term)),e.fuzzy){const n=!0===e.fuzzy?.2:e.fuzzy,r=n<1?Math.min(a,Math.round(e.term.length*n)):n;r&&(p=t._index.fuzzyGet(e.term,r))}if(f)for(const[n,r]of f){const s=n.length-e.term.length;if(!s)continue;p?.delete(n);const a=l*n.length/(n.length+.3*s);ce(t,e.term,n,a,e.termBoost,r,o,i,u,d)}if(p)for(const n of p.keys()){const[r,s]=p.get(n);if(!s)continue;const a=c*n.length/(n.length+s);ce(t,e.term,n,a,e.termBoost,r,o,i,u,d)}return d})(t,e,s)));return ue(c,s.combineWith)};class he{_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?se:t.autoVacuum;this._options={...ne,...t,autoVacuum:e,searchOptions:{...re,...t.searchOptions},autoSuggestOptions:{...oe,...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=ie,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,n]of this._index){const r={};for(const[t,e]of n)r[t]=Object.fromEntries(e);t.push([e,r])}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(),n=new Set([e]),r={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,o]of Object.entries(r))e.includes(t)&&o.forEach((r=>{n.add(e.replace(t,r))})),o.forEach((r=>{e.includes(r)&&n.add(e.replace(r,t))}));return Array.from(n)};var fe;function pe(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return fe.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return fe.STATION;case 2:case"ENTRANCE_EXIT":return fe.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return fe.GENERIC_NODE;case 4:case"BOARDING_AREA":return fe.BOARDING_AREA;default:return fe.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"}(fe||(fe={}));const me={encode(t,e=new S){""!==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 n of t.children)e.uint32(n);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 n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={name:"",sourceStopId:"",lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;o.name=n.string();continue;case 2:if(18!==t)break;o.sourceStopId=n.string();continue;case 3:if(29!==t)break;o.lat=n.float();continue;case 4:if(37!==t)break;o.lon=n.float();continue;case 5:if(40===t){o.children.push(n.uint32());continue}if(42===t){const t=n.uint32()+n.pos;for(;n.pos<t;)o.children.push(n.uint32());continue}break;case 6:if(48!==t)break;o.parent=n.uint32();continue;case 7:if(56!==t)break;o.locationType=n.int32();continue;case 8:if(66!==t)break;o.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({name:ve(t.name)?globalThis.String(t.name):"",sourceStopId:ve(t.sourceStopId)?globalThis.String(t.sourceStopId):"",lat:ve(t.lat)?globalThis.Number(t.lat):void 0,lon:ve(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:ve(t.parent)?globalThis.Number(t.parent):void 0,locationType:ve(t.locationType)?pe(t.locationType):0,platform:ve(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const n={};return""!==t.name&&(n.name=t.name),""!==t.sourceStopId&&(n.sourceStopId=t.sourceStopId),void 0!==t.lat&&(n.lat=t.lat),void 0!==t.lon&&(n.lon=t.lon),(null===(e=t.children)||void 0===e?void 0:e.length)&&(n.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(n.parent=Math.round(t.parent)),0!==t.locationType&&(n.locationType=function(t){switch(t){case fe.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case fe.STATION:return"STATION";case fe.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case fe.GENERIC_NODE:return"GENERIC_NODE";case fe.BOARDING_AREA:return"BOARDING_AREA";case fe.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>me.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,o,i,s,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!==(n=t.sourceStopId)&&void 0!==n?n:"",c.lat=null!==(r=t.lat)&&void 0!==r?r:void 0,c.lon=null!==(o=t.lon)&&void 0!==o?o:void 0,c.children=(null===(i=t.children)||void 0===i?void 0:i.map((t=>t)))||[],c.parent=null!==(s=t.parent)&&void 0!==s?s: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 ge={encode(t,e=new S){""!==t.version&&e.uint32(10).string(t.version);for(const n of t.stops)me.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof E?t:new E(t),r=void 0===e?n.len:n.pos+e,o={version:"",stops:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;o.version=n.string();continue;case 2:if(18!==t)break;o.stops.push(me.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({version:ve(t.version)?globalThis.String(t.version):"",stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>me.fromJSON(t))):[]}),toJSON(t){var e;const n={};return""!==t.version&&(n.version=t.version),(null===(e=t.stops)||void 0===e?void 0:e.length)&&(n.stops=t.stops.map((t=>me.toJSON(t)))),n},create:t=>ge.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={version:"",stops:[]};return r.version=null!==(e=t.version)&&void 0!==e?e:"",r.stops=(null===(n=t.stops)||void 0===n?void 0:n.map((t=>me.fromPartial(t))))||[],r}};function ve(t){return null!=t}const Ie="0.0.3",Te=t=>({version:Ie,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:Ee(e.locationType),platform:e.platform};var e}))}),ye=t=>{if(t.version!==Ie)throw new Error(`Unsupported stopMap version ${t.version}`);return t.stops.map(((t,e)=>{return{id:e,sourceStopId:(n=t).sourceStopId,name:n.name,lat:n.lat,lon:n.lon,children:n.children,parent:n.parent,locationType:Se(n.locationType),platform:n.platform};var n}))},Se=t=>{switch(t){case fe.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case fe.STATION:return"STATION";case fe.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case fe.GENERIC_NODE:return"GENERIC_NODE";case fe.BOARDING_AREA:return"BOARDING_AREA";case fe.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},Ee=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return fe.SIMPLE_STOP_OR_PLATFORM;case"STATION":return fe.STATION;case"ENTRANCE_EXIT":return fe.ENTRANCE_EXIT;case"GENERIC_NODE":return fe.GENERIC_NODE;case"BOARDING_AREA":return fe.BOARDING_AREA}};class Ae{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const n=new Map;this.stopPoints=[];for(let r=0;r<t.length;r++){const o=t[r];this.sourceStopsMap.set(o.sourceStopId,r);const i=null!==(e=o.parent)&&void 0!==e?e:r;n.has(i)||n.set(i,{id:i,name:o.parent?this.stops[o.parent].name:o.name}),o.lat&&o.lon&&this.stopPoints.push({id:r,lat:o.lat,lon:o.lon})}this.textIndex=new he({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:de});const r=Array.from(n.values());((t,e)=>{for(const n of e)ee(t,n)})(this.textIndex,r),this.geoIndex=new yt(this.stopPoints.length);for(let t=0;t<this.stopPoints.length;t++){const{lat:e,lon:n}=this.stopPoints[t];this.geoIndex.add(n,e)}this.geoIndex.finish()}static fromData(t){const e=new E(t),n=ge.decode(e);return new Ae(ye(n))}serialize(){const t=Te(this.stops),e=new S;return ge.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,o={...r,...n},i=le(t,e,n),s=[];for(const[e,{score:n,terms:r,match:a}]of i){const i=r.length||1,u={id:t._documentIds.get(e),score:n*i,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(u,t._storedFields.get(e)),(null==o.filter||o.filter(u))&&s.push(u)}return e===ae&&null==o.boostDocument||s.sort(Jt),s})(this.textIndex,t).map((t=>this.stops[t.id])).slice(0,e)}findStopsByLocation(t,e,n=5,r=.5){const o=function(t,e,n,r=1/0,o=1/0){let i=1;const s=[];void 0===r&&(r=1/0),void 0!==o&&(i=gt(o/6371));const a=new ht([],mt);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(n*ft);for(;u;){const o=u.right,l=u.left;if(o-l<=t.nodeSize)for(let r=l;r<=o;r++){const o=t.ids[r];{const i=It(e,n,t.coords[2*r],t.coords[2*r+1],c);a.push({id:o,dist:i})}}else{const r=l+o>>1,i=t.coords[2*r],s=t.coords[2*r+1],h=t.ids[r];{const t=It(e,n,i,s,c);a.push({id:h,dist:t})}const d=(u.axis+1)%2,f={left:l,right:r-1,axis:d,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?i:u.maxLng,maxLat:1===u.axis?s:u.maxLat,dist:0},p={left:r+1,right:o,axis:d,minLng:0===u.axis?i:u.minLng,minLat:1===u.axis?s:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};f.dist=pt(e,n,c,f),p.dist=pt(e,n,c,p),a.push(f),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>i)return s;if(s.push(t.id),s.length===r)return s}u=a.pop()}return s}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return o}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,n;const r=this.sourceStopsMap.get(t);if(void 0===r)return[];const o=this.stops[r];if(!o)return[];const i=o.parent?null!==(n=null===(e=this.stops[o.parent])||void 0===e?void 0:e.children)&&void 0!==n?n:[]:o.children;return Array.from(new Set([r,...i])).map((t=>this.stops[t]))}}t.Duration=e,t.Plotter=class{constructor(t){this.ROUND_COLORS=["#60a5fa","#ff9800","#14b8a6","#fb7185","#ffdf00","#b600ff","#ee82ee"],this.result=t}getRoundColor(t){var e;if(0===t)return"#888888";const n=Math.min(t-1,this.ROUND_COLORS.length-1);return null!==(e=this.ROUND_COLORS[n])&&void 0!==e?e:"#ee82ee"}escapeDotString(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}getStationInfo(t){var e,n;return{isOrigin:null!==(n=null===(e=this.result.routingState.graph[0])||void 0===e?void 0:e.has(t))&&void 0!==n&&n,isDestination:this.result.routingState.destinations.includes(t)}}formatStopName(t){const e=this.result.stopsIndex.findStopById(t);if(!e)return`Unknown Stop (${t})`;const n=this.escapeDotString(e.name),r=e.platform?this.escapeDotString(e.platform):"";return r?`${n}\\nPl. ${r}`:n}getStationFillColor(t,e){return t?"#60a5fa":e?"#ee82ee":"white"}createStationNode(t){if(!this.result.stopsIndex.findStopById(t))return"";const e=this.formatStopName(t),n=this.escapeDotString(String(t)),r=`s_${t}`,o=this.getStationInfo(t);return` "${r}" [label="${e}\\n${n}" shape=box style=filled fillcolor="${this.getStationFillColor(o.isOrigin,o.isDestination)}"];`}createVehicleEdge(t,e){var n;const r=`s_${t.from}`,o=`s_${t.to}`,i=this.getRoundColor(e),s=`e_${t.from}_${t.to}_${t.routeId}_${e}`,a=this.result.timetable.getRoute(t.routeId),u=a?this.result.timetable.getServiceRouteInfo(a):null,c=null!==(n=null==u?void 0:u.name)&&void 0!==n?n:`Route ${String(t.routeId)}`,l=(null==u?void 0:u.type)||"UNKNOWN",h=a?a.departureFrom(t.from,t.tripIndex).toString():"N/A",d=t.arrival.toString(),f=this.escapeDotString(c);return[` "${s}" [label="${`${this.escapeDotString(l)} ${f}\\n${`${t.routeId}:${t.tripIndex}`}\\n${h} → ${d}`}" shape=oval style=filled fillcolor="white" color="${i}"];`,` "${r}" -> "${s}" [color="${i}"];`,` "${s}" -> "${o}" [color="${i}"];`]}createTransferEdge(t,e){var n;const r=`s_${t.from}`,o=`s_${t.to}`,i=this.getRoundColor(e),s=`e_${t.from}_${t.to}_${e}`,a=(null===(n=t.minTransferTime)||void 0===n?void 0:n.toString())||"N/A";return[` "${s}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${i}"];`,` "${r}" -> "${s}" [color="${i}" style="dashed"];`,` "${s}" -> "${o}" [color="${i}" style="dashed"];`]}createContinuationEdge(t,e,n){var r,o;const i=`s_${t.to}`,s=`s_${e.from}`,a=this.getRoundColor(n),u=`continuation_${t.to}_${e.from}_${n}`,c=this.result.timetable.getRoute(t.routeId),l=this.result.timetable.getRoute(e.routeId),h=c?this.result.timetable.getServiceRouteInfo(c):null,d=l?this.result.timetable.getServiceRouteInfo(l):null,f=null!==(r=null==h?void 0:h.name)&&void 0!==r?r:`Route ${String(t.routeId)}`,p=null!==(o=null==d?void 0:d.name)&&void 0!==o?o:`Route ${String(e.routeId)}`,m=(null==h?void 0:h.type)||"UNKNOWN",g=(null==d?void 0:d.type)||"UNKNOWN",v=t.arrival.toString(),I=l?l.departureFrom(e.from,e.tripIndex).toString():"N/A",T=this.escapeDotString(f),y=this.escapeDotString(p),S=this.escapeDotString(m),E=this.escapeDotString(g);return[` "${u}" [label="${`${S} ${T} (${`${t.routeId}:${t.tripIndex}`}) ${v}\\n↓\\n${E} ${y} (${`${e.routeId}:${e.tripIndex}`}) ${I}`}" shape=oval style="filled,bold" fillcolor="#ffffcc" color="${a}" penwidth="2"];`,` "${i}" -> "${u}" [color="${a}" style="bold" penwidth="3"];`,` "${u}" -> "${s}" [color="${a}" style="bold" penwidth="3"];`]}collectGraphData(){const t=new Set,e=[],n=[],r=this.result.routingState.graph;return r.forEach((e=>{e.forEach(((e,n)=>{t.add(n),"from"in e&&"to"in e&&(t.add(e.from),t.add(e.to))}))})),r.forEach(((t,r)=>{0!==r&&t.forEach((t=>{if("from"in t&&"to"in t)if("routeId"in t){const o=this.createVehicleEdge(t,r);if(e.push(...o),t.continuationOf){let e=t,o=t.continuationOf;for(;o;){const t=this.createContinuationEdge(o,e,r);n.push(...t),e=o,o=o.continuationOf}}}else{const n=this.createTransferEdge(t,r);e.push(...n)}}))})),e.push(...n),{stations:t,edges:e}}plotDotGraph(){const{stations:t,edges:e}=this.collectGraphData(),n=["digraph RoutingGraph {"," graph [overlap=false, splines=true, rankdir=TB, bgcolor=white, nodesep=0.8, ranksep=1.2, concentrate=true];",' node [fontname="Arial" margin=0.1];',' edge [fontname="Arial" fontsize=10];',""," // Stations"];return t.forEach((t=>{const e=this.createStationNode(t);e&&n.push(e)})),n.push(""," // Edges"),n.push(...e),n.push("}"),n.join("\n")}},t.Query=at,t.Result=ct,t.Route=ut,t.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}route(t){const e=this.initRoutingState(t),n=new Set;for(const t of e.graph[0].keys())n.add(t);const r=this.considerTransfers(t,0,n,e);for(const t of r)n.add(t);for(let r=1;r<=t.options.maxTransfers+1;r++){const o=new Map;e.graph.push(o);const i=this.timetable.findReachableRoutes(n,t.options.transportModes);n.clear();for(const[t,o]of i){const i=this.scanRoute(t,o,r,e);for(const t of i)n.add(t)}let s=this.findTripContinuations(n,o);for(;s.length>0;){const t=new Set;for(const n of s){const o=this.timetable.getRoute(n.routeId),i=this.scanRoute(o,n.hopOnStop,r,e,n);for(const e of i)t.add(e)}for(const e of t)n.add(e);s=this.findTripContinuations(t,o)}const a=this.considerTransfers(t,r,n,e);for(const t of a)n.add(t);if(0===n.size)break}return new ct(t,e,this.stopsIndex,this.timetable)}findTripContinuations(t,e){const n=[];for(const r of t){const t=e.get(r);if(!t||!("routeId"in t))continue;const o=this.timetable.getContinuousTrips(r,t.routeId,t.tripIndex);for(let e=0;e<o.length;e++){const r=o[e];n.push({routeId:r.routeId,hopOnStop:r.hopOnStop,tripIndex:r.tripIndex,previousEdge:t})}}return n}initRoutingState(t){const{from:e,to:n,departureTime:r}=t,o=this.stopsIndex.equivalentStops(e).map((t=>t.id)),i=Array.from(n).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),s=new Map,a=new Map,u=[a],c={arrival:r,legNumber:0};for(const t of o)s.set(t,c),a.set(t,c);return{destinations:i,earliestArrivals:s,graph:u}}scanRoute(t,e,n,r,o){var i,s,a;const u=new Set;let c=o?{routeId:t.id,hopOnStop:e,tripIndex:o.tripIndex}:void 0;const l=r.graph[n],h=r.graph[n-1],d=t.stopRouteIndex(e),f=this.earliestArrivalAtAnyStop(r.earliestArrivals,r.destinations);for(let e=d;e<t.getNbStops();e++){const d=t.stops[e];if(void 0!==c){const e=t.arrivalAt(d,c.tripIndex),a=t.dropOffTypeAt(d,c.tripIndex),h=null!==(s=null===(i=r.earliestArrivals.get(d))||void 0===i?void 0:i.arrival)&&void 0!==s?s:lt;if("NOT_AVAILABLE"!==a&&e.isBefore(h)&&e.isBefore(f)){const i={arrival:e,routeId:t.id,tripIndex:c.tripIndex,from:c.hopOnStop,to:d};o&&(i.continuationOf=o.previousEdge),l.set(d,i),r.earliestArrivals.set(d,{arrival:e,legNumber:n}),u.add(d)}}if(o)continue;const p=null===(a=h.get(d))||void 0===a?void 0:a.arrival;if(void 0!==p&&(void 0===c||p.isBefore(t.departureFrom(d,c.tripIndex))||p.equals(t.departureFrom(d,c.tripIndex)))){const e=t.findEarliestTrip(d,p,null==c?void 0:c.tripIndex);void 0!==e&&(c={routeId:t.id,tripIndex:e,hopOnStop:d})}}return u}considerTransfers(t,n,r,o){var i,s;const{options:a}=t,u=o.graph[n],c=new Set;for(const t of r){const r=u.get(t);if(!r||"type"in r)continue;const l=this.timetable.getTransfers(t);for(let h=0;h<l.length;h++){const d=l[h];let f;f=d.minTransferTime?d.minTransferTime:"IN_SEAT"===d.type?e.zero():a.minTransferTime;const p=r.arrival.plus(f),m=null!==(s=null===(i=u.get(d.destination))||void 0===i?void 0:i.arrival)&&void 0!==s?s:lt;p.isBefore(m)&&(u.set(d.destination,{arrival:p,from:t,to:d.destination,minTransferTime:d.minTransferTime,type:d.type}),o.earliestArrivals.set(d.destination,{arrival:p,legNumber:n}),c.add(d.destination))}}return c}earliestArrivalAtAnyStop(t,e){var n,r;let o=lt;for(let i=0;i<e.length;i++){const s=e[i],a=null!==(r=null===(n=t.get(s))||void 0===n?void 0:n.arrival)&&void 0!==r?r:lt;o=P.min(o,a)}return o}},t.StopsIndex=Ae,t.Time=P,t.Timetable=st}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).minotor={})}(this,(function(t){"use strict";class e{constructor(t){this.totalSeconds=t}static fromSeconds(t){return new e(t)}static fromMinutes(t){return new e(60*t)}static zero(){return new e(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),n=this.totalSeconds%60;return t>0?`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`:`${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}toSeconds(){return this.totalSeconds}add(t){const n=this.totalSeconds+t.toSeconds();return new e(n)}subtract(t){const n=Math.max(0,this.totalSeconds-t.toSeconds());return new e(n)}}function n(){let t=0,e=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(t|=(127&r)<<n,!(128&r))return this.assertBounds(),[t,e]}let n=this.buf[this.pos++];if(t|=(15&n)<<28,e=(112&n)>>4,!(128&n))return this.assertBounds(),[t,e];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(e|=(127&r)<<n,!(128&r))return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function r(t,e,n){for(let r=0;r<28;r+=7){const i=t>>>r,o=!(i>>>7==0&&0==e),s=255&(o?128|i:i);if(n.push(s),!o)return}const r=t>>>28&15|(7&e)<<4,i=!!(e>>3);if(n.push(255&(i?128|r:r)),i){for(let t=3;t<31;t+=7){const r=e>>>t,i=!(r>>>7==0),o=255&(i?128|r:r);if(n.push(o),!i)return}n.push(e>>>31&1)}}const i=4294967296;function o(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let r=0,o=0;function s(e,s){const a=Number(t.slice(e,s));o*=n,r=r*n+a,r>=i&&(o+=r/i|0,r%=i)}return s(-24,-18),s(-18,-12),s(-12,-6),s(-6),e?u(r,o):a(r,o)}function s(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(i*e+t);const n=16777215&(t>>>24|e<<8),r=e>>16&65535;let o=(16777215&t)+6777216*n+6710656*r,s=n+8147497*r,a=2*r;const u=1e7;return o>=u&&(s+=Math.floor(o/u),o%=u),s>=u&&(a+=Math.floor(s/u),s%=u),a.toString()+c(s)+c(o)}function a(t,e){return{lo:0|t,hi:0|e}}function u(t,e){return e=~e,t?t=1+~t:e+=1,a(t,e)}const c=t=>{const e=String(t);return"0000000".slice(e.length)+e};function d(t,e){if(t>=0){for(;t>127;)e.push(127&t|128),t>>>=7;e.push(t)}else{for(let n=0;n<9;n++)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"),n=BigInt("9223372036854775807"),r=BigInt("0"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const r="bigint"==typeof t?t:BigInt(t);if(r>n||r<e)throw new Error(`invalid int64: ${t}`);return r},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>i||e<r)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,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigInt64(0,!0)),uDec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigUint64(0,!0))}}return{zero:"0",supported:!1,parse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),m(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),p(t),o(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),m(t),o(t)),dec:(t,e)=>function(t,e){let n=a(t,e);const r=2147483648&n.hi;r&&(n=u(n.lo,n.hi));const i=s(n.lo,n.hi);return r?"-"+i:i}(t,e),uDec:(t,e)=>s(t,e)}}function p(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function m(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const g=Symbol.for("@bufbuild/protobuf/text-encoding");function I(){if(null==globalThis[g]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[g]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[g]}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,S=-34028234663852886e22;class y{constructor(t=I().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),n=0;for(let t=0;t<this.chunks.length;t++)e.set(this.chunks[t],n),n+=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),d(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.encodeUtf8(t);return this.uint32(e.byteLength),this.raw(e)}float(t){!function(t){if("string"==typeof t){const e=t;if(t=Number(t),Number.isNaN(t)&&"NaN"!==e)throw new Error("invalid float32: "+e)}else if("number"!=typeof t)throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>v||t<S))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),d(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=h.enc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(e)}fixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=h.uEnc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.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,e=I().decodeUtf8){this.decodeUtf8=e,this.varint64=n,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,n=7&t;if(e<=0||n<0||n>5)throw new Error("illegal tag: field no "+e+" wire type "+n);return[e,n]}skip(t,e){let n=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 n=this.uint32();this.pos+=n;break;case T.StartGroup:for(;;){const[t,n]=this.tag();if(n===T.EndGroup){if(void 0!==e&&t!==e)throw new Error("invalid end group tag");break}this.skip(n,t)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(n,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(),n=-(1&t);return t=(t>>>1|(1&e)<<31)^n,e=e>>>1^n,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,b;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 N(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 O(){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"}(b||(b={}));const M={encode:(t,e=new y)=>(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 n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i=O();for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;i.stopTimes=n.bytes();continue;case 2:if(18!==t)break;i.pickUpDropOffTypes=n.bytes();continue;case 3:if(26!==t)break;i.stops=n.bytes();continue;case 4:if(32!==t)break;i.serviceRouteId=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({stopTimes:F(t.stopTimes)?B(t.stopTimes):new Uint8Array(0),pickUpDropOffTypes:F(t.pickUpDropOffTypes)?B(t.pickUpDropOffTypes):new Uint8Array(0),stops:F(t.stops)?B(t.stops):new Uint8Array(0),serviceRouteId:F(t.serviceRouteId)?globalThis.Number(t.serviceRouteId):0}),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)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,i;const o=O();return o.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),o.pickUpDropOffTypes=null!==(n=t.pickUpDropOffTypes)&&void 0!==n?n:new Uint8Array(0),o.stops=null!==(r=t.stops)&&void 0!==r?r:new Uint8Array(0),o.serviceRouteId=null!==(i=t.serviceRouteId)&&void 0!==i?i:0,o}};const x={encode:(t,e=new y)=>(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 n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={destination:0,type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;i.destination=n.uint32();continue;case 2:if(16!==t)break;i.type=n.int32();continue;case 3:if(24!==t)break;i.minTransferTime=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({destination:F(t.destination)?globalThis.Number(t.destination):0,type:F(t.type)?_(t.type):0,minTransferTime:F(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=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const i={destination:0,type:0,minTransferTime:void 0};return i.destination=null!==(e=t.destination)&&void 0!==e?e:0,i.type=null!==(n=t.type)&&void 0!==n?n:0,i.minTransferTime=null!==(r=t.minTransferTime)&&void 0!==r?r:void 0,i}};const U={encode:(t,e=new y)=>(0!==t.hopOnStopIndex&&e.uint32(8).uint32(t.hopOnStopIndex),0!==t.routeId&&e.uint32(16).uint32(t.routeId),0!==t.tripIndex&&e.uint32(24).uint32(t.tripIndex),e),decode(t,e){const n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={hopOnStopIndex:0,routeId:0,tripIndex:0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;i.hopOnStopIndex=n.uint32();continue;case 2:if(16!==t)break;i.routeId=n.uint32();continue;case 3:if(24!==t)break;i.tripIndex=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({hopOnStopIndex:F(t.hopOnStopIndex)?globalThis.Number(t.hopOnStopIndex):0,routeId:F(t.routeId)?globalThis.Number(t.routeId):0,tripIndex:F(t.tripIndex)?globalThis.Number(t.tripIndex):0}),toJSON(t){const e={};return 0!==t.hopOnStopIndex&&(e.hopOnStopIndex=Math.round(t.hopOnStopIndex)),0!==t.routeId&&(e.routeId=Math.round(t.routeId)),0!==t.tripIndex&&(e.tripIndex=Math.round(t.tripIndex)),e},create:t=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const i={hopOnStopIndex:0,routeId:0,tripIndex:0};return i.hopOnStopIndex=null!==(e=t.hopOnStopIndex)&&void 0!==e?e:0,i.routeId=null!==(n=t.routeId)&&void 0!==n?n:0,i.tripIndex=null!==(r=t.tripIndex)&&void 0!==r?r:0,i}};const L={encode(t,e=new y){0!==t.originStopIndex&&e.uint32(8).uint32(t.originStopIndex),0!==t.originRouteId&&e.uint32(16).uint32(t.originRouteId),0!==t.originTripIndex&&e.uint32(24).uint32(t.originTripIndex);for(const n of t.continuations)U.encode(n,e.uint32(34).fork()).join();return e},decode(t,e){const n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={originStopIndex:0,originRouteId:0,originTripIndex:0,continuations:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;i.originStopIndex=n.uint32();continue;case 2:if(16!==t)break;i.originRouteId=n.uint32();continue;case 3:if(24!==t)break;i.originTripIndex=n.uint32();continue;case 4:if(34!==t)break;i.continuations.push(U.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({originStopIndex:F(t.originStopIndex)?globalThis.Number(t.originStopIndex):0,originRouteId:F(t.originRouteId)?globalThis.Number(t.originRouteId):0,originTripIndex:F(t.originTripIndex)?globalThis.Number(t.originTripIndex):0,continuations:globalThis.Array.isArray(null==t?void 0:t.continuations)?t.continuations.map((t=>U.fromJSON(t))):[]}),toJSON(t){var e;const n={};return 0!==t.originStopIndex&&(n.originStopIndex=Math.round(t.originStopIndex)),0!==t.originRouteId&&(n.originRouteId=Math.round(t.originRouteId)),0!==t.originTripIndex&&(n.originTripIndex=Math.round(t.originTripIndex)),(null===(e=t.continuations)||void 0===e?void 0:e.length)&&(n.continuations=t.continuations.map((t=>U.toJSON(t)))),n},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,i;const o={originStopIndex:0,originRouteId:0,originTripIndex:0,continuations:[]};return o.originStopIndex=null!==(e=t.originStopIndex)&&void 0!==e?e:0,o.originRouteId=null!==(n=t.originRouteId)&&void 0!==n?n:0,o.originTripIndex=null!==(r=t.originTripIndex)&&void 0!==r?r:0,o.continuations=(null===(i=t.continuations)||void 0===i?void 0:i.map((t=>U.fromPartial(t))))||[],o}};const k={encode(t,e=new y){e.uint32(10).fork();for(const n of t.routes)e.uint32(n);e.join();for(const n of t.transfers)x.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={routes:[],transfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8===t){i.routes.push(n.uint32());continue}if(10===t){const t=n.uint32()+n.pos;for(;n.pos<t;)i.routes.push(n.uint32());continue}break;case 2:if(18!==t)break;i.transfers.push(x.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[],transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>x.fromJSON(t))):[]}),toJSON(t){var e,n;const r={};return(null===(e=t.routes)||void 0===e?void 0:e.length)&&(r.routes=t.routes.map((t=>Math.round(t)))),(null===(n=t.transfers)||void 0===n?void 0:n.length)&&(r.transfers=t.transfers.map((t=>x.toJSON(t)))),r},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={routes:[],transfers:[]};return r.routes=(null===(e=t.routes)||void 0===e?void 0:e.map((t=>t)))||[],r.transfers=(null===(n=t.transfers)||void 0===n?void 0:n.map((t=>x.fromPartial(t))))||[],r}};const D={encode(t,e=new y){0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e.uint32(26).fork();for(const n of t.routes)e.uint32(n);return e.join(),e},decode(t,e){const n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={type:0,name:"",routes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;i.type=n.int32();continue;case 2:if(18!==t)break;i.name=n.string();continue;case 3:if(24===t){i.routes.push(n.uint32());continue}if(26===t){const t=n.uint32()+n.pos;for(;n.pos<t;)i.routes.push(n.uint32());continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({type:F(t.type)?N(t.type):0,name:F(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 n={};return 0!==t.type&&(n.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&&(n.name=t.name),(null===(e=t.routes)||void 0===e?void 0:e.length)&&(n.routes=t.routes.map((t=>Math.round(t)))),n},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const i={type:0,name:"",routes:[]};return i.type=null!==(e=t.type)&&void 0!==e?e:0,i.name=null!==(n=t.name)&&void 0!==n?n:"",i.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],i}};const $={encode(t,e=new y){""!==t.version&&e.uint32(10).string(t.version);for(const n of t.stopsAdjacency)k.encode(n,e.uint32(18).fork()).join();for(const n of t.routesAdjacency)M.encode(n,e.uint32(26).fork()).join();for(const n of t.serviceRoutes)D.encode(n,e.uint32(34).fork()).join();for(const n of t.tripContinuations)L.encode(n,e.uint32(42).fork()).join();return e},decode(t,e){const n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={version:"",stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;i.version=n.string();continue;case 2:if(18!==t)break;i.stopsAdjacency.push(k.decode(n,n.uint32()));continue;case 3:if(26!==t)break;i.routesAdjacency.push(M.decode(n,n.uint32()));continue;case 4:if(34!==t)break;i.serviceRoutes.push(D.decode(n,n.uint32()));continue;case 5:if(42!==t)break;i.tripContinuations.push(L.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({version:F(t.version)?globalThis.String(t.version):"",stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>k.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>M.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>D.fromJSON(t))):[],tripContinuations:globalThis.Array.isArray(null==t?void 0:t.tripContinuations)?t.tripContinuations.map((t=>L.fromJSON(t))):[]}),toJSON(t){var e,n,r,i;const o={};return""!==t.version&&(o.version=t.version),(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(o.stopsAdjacency=t.stopsAdjacency.map((t=>k.toJSON(t)))),(null===(n=t.routesAdjacency)||void 0===n?void 0:n.length)&&(o.routesAdjacency=t.routesAdjacency.map((t=>M.toJSON(t)))),(null===(r=t.serviceRoutes)||void 0===r?void 0:r.length)&&(o.serviceRoutes=t.serviceRoutes.map((t=>D.toJSON(t)))),(null===(i=t.tripContinuations)||void 0===i?void 0:i.length)&&(o.tripContinuations=t.tripContinuations.map((t=>L.toJSON(t)))),o},create:t=>$.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,i,o;const s={version:"",stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[]};return s.version=null!==(e=t.version)&&void 0!==e?e:"",s.stopsAdjacency=(null===(n=t.stopsAdjacency)||void 0===n?void 0:n.map((t=>k.fromPartial(t))))||[],s.routesAdjacency=(null===(r=t.routesAdjacency)||void 0===r?void 0:r.map((t=>M.fromPartial(t))))||[],s.serviceRoutes=(null===(i=t.serviceRoutes)||void 0===i?void 0:i.map((t=>D.fromPartial(t))))||[],s.tripContinuations=(null===(o=t.tripContinuations)||void 0===o?void 0:o.map((t=>L.fromPartial(t))))||[],s}};function B(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n}}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 F(t){return null!=t}class P{static infinity(){return new P(Number.MAX_SAFE_INTEGER)}static origin(){return new P(0)}constructor(t){this.minutesSinceMidnight=t}static fromMinutes(t){return new P(t)}static fromHMS(t,e,n){if(t<0||e<0||n<0||e>=60||n>=60)throw new Error("Invalid time. Ensure hours, minutes, and seconds are valid values.");const r=n+60*e+3600*t,i=Math.round(r/60);return new P(i)}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 P(e+60*t)}static fromDate(t){const e=t.getHours(),n=t.getMinutes(),r=t.getSeconds();return P.fromHMS(e,n,r)}static fromString(t){const[e,n,r]=t.split(":");if(void 0===e||void 0===n||""===e.trim()||""===n.trim()||isNaN(Number(e))||isNaN(Number(n))||void 0!==r&&(""===r.trim()||isNaN(Number(r))))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const i=parseInt(e,10),o=parseInt(n,10),s=void 0!==r?parseInt(r,10):0;return P.fromHMS(i,o,s)}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 P(Math.round(e/60))}minus(t){let e=60*this.minutesSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new P(Math.round(e/60))}diff(t){const n=this.minutesSinceMidnight-t.toMinutes();return e.fromSeconds(Math.abs(60*n))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");let e=t[0];for(let n=1;n<t.length;n++)t[n].minutesSinceMidnight>e.minutesSinceMidnight&&(e=t[n]);return e}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");let e=t[0];for(let n=1;n<t.length;n++)t[n].minutesSinceMidnight<e.minutesSinceMidnight&&(e=t[n]);return e}isAfter(t){return this.minutesSinceMidnight>t.minutesSinceMidnight}isBefore(t){return this.minutesSinceMidnight<t.minutesSinceMidnight}equals(t){return this.minutesSinceMidnight===t.minutesSinceMidnight}}const z=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],j=t=>{const e=z[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};let G=class t{constructor(t,e,n,r,i){this.id=t,this.stopTimes=e,this.pickUpDropOffTypes=n,this.stops=r,this.serviceRouteId=i,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++){const e=r[t],n=this.stopIndices.get(e);n?n.push(t):this.stopIndices.set(e,[t])}}static of(e){var n,r;const{id:i,serviceRouteId:o,trips:s}=e;if(0===s.length)throw new Error("At least one trip must be provided");const a=s[0],u=new Uint32Array(a.stops.map((t=>t.id))),c=u.length;for(let t=1;t<s.length;t++){const e=s[t];if(e.stops.length!==c)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${c}`);for(let n=0;n<c;n++)if(e.stops[n].id!==u[n])throw new Error(`Trip ${t} has different stop at index ${n}`)}const d=new Uint16Array(s.length*c*2);for(let t=0;t<s.length;t++){const e=s[t];for(let n=0;n<c;n++){const r=e.stops[n],i=2*(t*c+n);d[i]=r.arrivalTime.toMinutes(),d[i+1]=r.departureTime.toMinutes()}}const l=s.length*c,h=new Uint8Array(Math.ceil(l/2));for(let t=0;t<s.length;t++){const e=s[t];for(let i=0;i<c;i++){const o=e.stops[i],s=t*c+i,a=null!==(n=o.pickUpType)&&void 0!==n?n:0,u=null!==(r=o.dropOffType)&&void 0!==r?r:0,d=Math.floor(s/2),l=s%2==1;h[d]|=l?a<<6|u<<4:a<<2|u}}return new t(i,d,h,u,o)}serialize(){return{stopTimes:this.stopTimes,pickUpDropOffTypes:this.pickUpDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}getNbStops(){return this.nbStops}getNbTrips(){return this.nbTrips}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const n=2*(e*this.stops.length+t),r=this.stopTimes[n];if(void 0===r)throw new Error(`Arrival time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return P.fromMinutes(r)}departureFrom(t,e){const n=2*(e*this.stops.length+t)+1,r=this.stopTimes[n];if(void 0===r)throw new Error(`Departure time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return P.fromMinutes(r)}pickUpTypeFrom(t,e){const n=e*this.stops.length+t,r=Math.floor(n/2),i=n%2==1,o=this.pickUpDropOffTypes[r];if(void 0===o)throw new Error(`Pick up type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return j(i?o>>6&3:o>>2&3)}dropOffTypeAt(t,e){const n=e*this.stops.length+t,r=Math.floor(n/2),i=n%2==1,o=this.pickUpDropOffTypes[r];if(void 0===o)throw new Error(`Drop off type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return j(i?o>>4&3:3&o)}findEarliestTrip(t,e=P.origin(),n){if(this.nbTrips<=0)return;let r=this.nbTrips-1;if(void 0!==n&&(r=Math.min(r,n-1)),r<0)return;let i=0,o=-1;for(;i<=r;){const n=i+r>>>1;this.departureFrom(t,n).isBefore(e)?i=n+1:(o=n,r=n-1)}if(-1!==o)for(let e=o;e<(null!=n?n:this.nbTrips);e++){if("NOT_AVAILABLE"!==this.pickUpTypeFrom(t,e))return e}}stopRouteIndices(t){const e=this.stopIndices.get(t);return void 0===e?[]:e}stopId(t){const e=this.stops[t];if(void 0===e)throw new Error(`StopId for stop at index ${t} not found in route ${this.serviceRouteId}`);return e}};const V=(BigInt(1)<<BigInt(20))-BigInt(1),Y=1048575,J=BigInt(0),W=BigInt(20),q=BigInt(40),Z=(t,e)=>{if(t<0||t>Y)throw new Error(`${e} must be between 0 and 1048575, got ${t}`)},H=(t,e,n)=>(Z(t,"stopIndex"),Z(e,"routeId"),Z(n,"tripIndex"),BigInt(t)<<q|BigInt(e)<<W|BigInt(n)<<J),Q=t=>[Number(t>>q&V),Number(t>>W&V),Number(t>>J&V)],X=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),K=!0,tt=t=>{if(X===K)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint32(4*e,t[e],K);return e},et=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(X===K)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint32(4*t,K);return e},nt=t=>{if(X===K)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint16(2*e,t[e],K);return e},rt=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(X===K)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint16(2*t,K);return e},it=t=>{const e=[];return t.forEach((t=>{const n=t.serialize();e.push({stopTimes:nt(n.stopTimes),pickUpDropOffTypes:n.pickUpDropOffTypes,stops:tt(n.stops),serviceRouteId:n.serviceRouteId})})),e},ot=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.")}},st=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}},at=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.")}},ut=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}},ct=t=>{const e=[];for(const[n,r]of t.entries()){const[t,i,o]=Q(n);e.push({originStopIndex:t,originRouteId:i,originTripIndex:o,continuations:r.map((t=>({hopOnStopIndex:t.hopOnStopIndex,routeId:t.routeId,tripIndex:t.tripIndex})))})}return e},dt=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),lt=[],ht="0.0.9";class ft{constructor(t,e,n,r){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=n,this.tripContinuations=r,this.activeStops=new Set;for(let e=0;e<t.length;e++){const n=t[e];(n.routes.length>0||n.transfers&&n.transfers.length>0)&&this.activeStops.add(e)}}serialize(){const t={version:ht,stopsAdjacency:(n=this.stopsAdjacency,n.map((t=>({transfers:t.transfers?t.transfers.map((t=>Object.assign({destination:t.destination,type:st(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))):[],routes:t.routes})))),routesAdjacency:it(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:ut(t.type),name:t.name,routes:t.routes})))),tripContinuations:ct(this.tripContinuations||new Map)};var e,n;const r=new y;return $.encode(t,r),r.finish()}static fromData(t){const n=new A(t),r=$.decode(n);if(r.version!==ht)throw new Error(`Unsupported timetable version ${r.version}`);return new ft((t=>{const n=[];for(let r=0;r<t.length;r++){const i=t[r],o=[];for(let t=0;t<i.transfers.length;t++){const n=i.transfers[t],r=Object.assign({destination:n.destination,type:ot(n.type)},void 0!==n.minTransferTime&&{minTransferTime:e.fromSeconds(n.minTransferTime)});o.push(r)}const s={routes:i.routes};o.length>0&&(s.transfers=o),n.push(s)}return n})(r.stopsAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],i=et(r.stops);e.push(new G(n,rt(r.stopTimes),r.pickUpDropOffTypes,i,r.serviceRouteId))}return e})(r.routesAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n];e.push({type:at(r.type),name:r.name,routes:r.routes})}return e})(r.serviceRoutes),(t=>{const e=new Map;for(let n=0;n<t.length;n++){const r=t[n],i=H(r.originStopIndex,r.originRouteId,r.originTripIndex),o=r.continuations.map((t=>({hopOnStopIndex:t.hopOnStopIndex,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(i,o)}return e})(r.tripContinuations))}isActive(t){return this.activeStops.has(t)}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){const e=this.stopsAdjacency[t];if(!e)throw new Error(`Stop ID ${t} not found`);return e.transfers||[]}getContinuousTrips(t,e,n){var r;const i=null===(r=this.tripContinuations)||void 0===r?void 0:r.get(H(t,e,n));return i||lt}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);return{type:e.type,name:e.name}}routesPassingThrough(t){const e=this.stopsAdjacency[t];if(!e)return[];const n=[];for(let t=0;t<e.routes.length;t++){const r=e.routes[t],i=this.routesAdjacency[r];i&&n.push(i)}return n}findReachableRoutes(t,e=dt){const n=new Map,r=Array.from(t);for(let t=0;t<r.length;t++){const i=r[t],o=this.routesPassingThrough(i).filter((t=>{const n=this.getServiceRouteInfo(t);return e.has(n.type)}));for(let t=0;t<o.length;t++){const e=o[t],r=e.stopRouteIndices(i)[0],s=n.get(e);void 0!==s?r<s&&n.set(e,r):n.set(e,r)}}return n}}class pt{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}pt.Builder=class{constructor(){this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:e.fromSeconds(120),transportModes:dt}}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 pt(this)}};class mt{constructor(t){this.legs=t}departureTime(){const t=e.zero();for(let e=0;e<this.legs.length;e++){const n=this.legs[e];if("departureTime"in n)return n.departureTime.minus(t);"minTransferTime"in n&&n.minTransferTime&&t.add(n.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let t=P.origin();const n=e.zero();let r=!1;for(let e=this.legs.length-1;e>=0;e--){const i=this.legs[e];"arrivalTime"in i&&!r?(t=i.arrivalTime,r=!0):"minTransferTime"in i&&i.minTransferTime&&r&&n.add(i.minTransferTime)}if(!r)throw new Error("No vehicle leg found in route");return t.plus(n)}totalDuration(){return 0===this.legs.length?e.zero():this.arrivalTime().diff(this.departureTime())}toString(){return this.legs.map(((t,e)=>{var n;const r=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,i=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,o="minTransferTime"in t?`Minimum Transfer Time: ${null===(n=t.minTransferTime)||void 0===n?void 0:n.toString()}`:"",s="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}:`,` ${r}`,` ${i}`,o?` ${o}`:"",s?` ${s}`:""].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 gt{constructor(t,e,n,r){this.query=t,this.routingState=e,this.stopsIndex=n,this.timetable=r}bestRoute(t){var e;const n=(t instanceof Set?Array.from(t):t?[t]:Array.from(this.query.to)).flatMap((t=>this.stopsIndex.equivalentStops(t)));let r,i;for(const t of n){const e=this.routingState.earliestArrivals.get(t.id);void 0!==e&&(void 0===i||e.arrival.isBefore(i.arrival))&&(r=t.id,i=e)}if(!r||!i)return;const o=[];let s=r,a=i.legNumber;for(;a>0;){const t=null===(e=this.routingState.graph[a])||void 0===e?void 0:e.get(s);if(!t)throw new Error(`No edge arriving at stop ${s} at round ${a}`);let n;if("routeId"in t){let e=t;const r=[e];for(;"routeId"in e&&e.continuationOf;)r.push(e.continuationOf),e=e.continuationOf;n=this.buildVehicleLeg(r)}else{if(!("type"in t))break;n=this.buildTransferLeg(t)}o.unshift(n),s=n.from.id,"routeId"in t&&(a-=1)}return new mt(o)}buildVehicleLeg(t){if(0===t.length)throw new Error("Cannot build vehicle leg from empty edges");const e=t[t.length-1],n=t[0],r=this.timetable.getRoute(e.routeId),i=this.timetable.getRoute(n.routeId);return{from:this.stopsIndex.findStopById(r.stopId(e.from)),to:this.stopsIndex.findStopById(i.stopId(n.to)),route:this.timetable.getServiceRouteInfo(r),departureTime:r.departureFrom(e.from,e.tripIndex),arrivalTime:n.arrival,pickUpType:r.pickUpTypeFrom(e.from,e.tripIndex),dropOffType:i.dropOffTypeAt(n.to,n.tripIndex)}}buildTransferLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),minTransferTime:t.minTransferTime,type:t.type}}arrivalAt(t,e){var n;const r=this.stopsIndex.equivalentStops(t);let i;for(const t of r){let r;if(void 0===e)r=this.routingState.earliestArrivals.get(t.id);else for(let i=e+1;i>=0;i--){const e=null===(n=this.routingState.graph[i])||void 0===n?void 0:n.get(t.id);if(void 0!==e){r={arrival:e.arrival,legNumber:i};break}}void 0!==r&&(void 0===i||r.arrival.isBefore(i.arrival))&&(i=r)}return i}}const It=P.infinity();class Tt{constructor(t=[],e=vt){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:n}=this,r=e[t];for(;t>0;){const i=t-1>>1,o=e[i];if(n(r,o)>=0)break;e[t]=o,t=i}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,i=e[t];for(;t<r;){let r=1+(t<<1),o=e[r];const s=r+1;if(s<this.length&&n(e[s],o)<0&&(r=s,o=e[s]),n(o,i)>=0)break;e[t]=o,t=r}e[t]=i}}function vt(t,e){return t<e?-1:t>e?1:0}const St=Math.PI/180;function yt(t,e,n,r){const i=r.minLng,o=r.maxLng,s=r.minLat,a=r.maxLat;if(t>=i&&t<=o)return e<s?Et((e-s)*St):e>a?Et((e-a)*St):0;const u=Math.min(Et((t-i)*St),Et((t-o)*St)),c=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*St)/n)/St}(e,u);return c>s&&c<a?Rt(u,n,e,c):Math.min(Rt(u,n,e,s),Rt(u,n,e,a))}function At(t,e){return t.dist-e.dist}function Et(t){const e=Math.sin(t/2);return e*e}function Rt(t,e,n,r){return e*Math.cos(r*St)*t+Et((n-r)*St)}function wt(t,e,n,r,i){return Rt(Et((t-n)*St),i,e,r)}const bt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class _t{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const r=n>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const i=bt[15&n];if(!i)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[s]=new Uint32Array(t,4,1);return new _t(s,o,i,t)}constructor(t,e=64,n=Float64Array,r){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=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const i=bt.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,s=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-s%8)%8;if(i<0)throw new Error(`Unexpected typed array class: ${n}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+s+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+i]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return Nt(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:i,coords:o,nodeSize:s}=this,a=[0,i.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,d=a.pop()||0,l=a.pop()||0;if(d-l<=s){for(let s=l;s<=d;s++){const a=o[2*s],c=o[2*s+1];a>=t&&a<=n&&c>=e&&c<=r&&u.push(i[s])}continue}const h=l+d>>1,f=o[2*h],p=o[2*h+1];f>=t&&f<=n&&p>=e&&p<=r&&u.push(i[h]),(0===c?t<=f:e<=p)&&(a.push(l),a.push(h-1),a.push(1-c)),(0===c?n>=f:r>=p)&&(a.push(h+1),a.push(d),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:i,nodeSize:o}=this,s=[0,r.length-1,0],a=[],u=n*n;for(;s.length;){const c=s.pop()||0,d=s.pop()||0,l=s.pop()||0;if(d-l<=o){for(let n=l;n<=d;n++)Ut(i[2*n],i[2*n+1],t,e)<=u&&a.push(r[n]);continue}const h=l+d>>1,f=i[2*h],p=i[2*h+1];Ut(f,p,t,e)<=u&&a.push(r[h]),(0===c?t-n<=f:e-n<=p)&&(s.push(l),s.push(h-1),s.push(1-c)),(0===c?t+n>=f:e+n>=p)&&(s.push(h+1),s.push(d),s.push(1-c))}return a}}function Nt(t,e,n,r,i,o){if(i-r<=n)return;const s=r+i>>1;Ot(t,e,s,r,i,o),Nt(t,e,n,r,s-1,1-o),Nt(t,e,n,s+1,i,1-o)}function Ot(t,e,n,r,i,o){for(;i>r;){if(i-r>600){const s=i-r+1,a=n-r+1,u=Math.log(s),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(s-c)/s)*(a-s/2<0?-1:1);Ot(t,e,n,Math.max(r,Math.floor(n-a*c/s+d)),Math.min(i,Math.floor(n+(s-a)*c/s+d)),o)}const s=e[2*n+o];let a=r,u=i;for(Mt(t,e,r,n),e[2*i+o]>s&&Mt(t,e,r,i);a<u;){for(Mt(t,e,a,u),a++,u--;e[2*a+o]<s;)a++;for(;e[2*u+o]>s;)u--}e[2*r+o]===s?Mt(t,e,r,u):(u++,Mt(t,e,u,i)),u<=n&&(r=u+1),n<=u&&(i=u-1)}}function Mt(t,e,n,r){xt(t,n,r),xt(e,2*n,2*r),xt(e,2*n+1,2*r+1)}function xt(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function Ut(t,e,n,r){const i=t-n,o=e-r;return i*i+o*o}const Lt="KEYS",kt="VALUES",Dt="";class $t{set;_type;_path;constructor(t,e){const n=t._tree,r=Array.from(n.keys());this.set=t,this._type=e,this._path=r.length>0?[{node:n,keys:r}]:[]}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}=Bt(this._path);if(Bt(e)===Dt)return{done:!1,value:this.result()};const n=t.get(Bt(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Bt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Bt(t))).filter((t=>t!==Dt)).join("")}value(){return Bt(this._path).node.get(Dt)}result(){switch(this._type){case kt:return this.value();case Lt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Bt=t=>t[t.length-1],Ct=(t,e,n,r,i,o,s,a)=>{const u=o*s;t:for(const c of t.keys())if(c===Dt){const e=i[u-1];e<=n&&r.set(a,[t.get(c),e])}else{let u=o;for(let t=0;t<c.length;++t,++u){const r=c[t],o=s*u,a=o-s;let d=i[o];const l=Math.max(0,u-n-1),h=Math.min(s-1,u+n);for(let t=l;t<h;++t){const n=r!==e[t],s=i[a+t]+ +n,u=i[a+t+1]+1,c=i[o+t]+1,l=i[o+t+1]=Math.min(s,u,c);l<d&&(d=l)}if(d>n)continue t}Ct(t.get(c),e,n,r,i,u,s,a+c)}};class Ft{_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,n]=Pt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=Jt(n);for(const n of e.keys())if(n!==Dt&&n.startsWith(r)){const i=new Map;return i.set(n.slice(r.length),e.get(n)),new Ft(i,t)}}return new Ft(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Gt(this._tree,t)}entries(){return new $t(this,"ENTRIES")}forEach(t){for(const[e,n]of this)t(e,n,this)}fuzzyGet(t,e){return((t,e,n)=>{const r=new Map;if("string"!=typeof e)return r;const i=e.length+1,o=i+n,s=new Uint8Array(o*i).fill(n+1);for(let t=0;t<i;++t)s[t]=t;for(let t=1;t<o;++t)s[t*i]=t;return Ct(t,e,n,r,s,1,i,""),r})(this._tree,t,e)}get(t){const e=zt(this._tree,t);return void 0!==e?e.get(Dt):void 0}has(t){return zt(this._tree,t)?.has(Dt)??!1}keys(){return new $t(this,Lt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,jt(this._tree,t).set(Dt,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 n=jt(this._tree,t);return n.set(Dt,e(n.get(Dt))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=jt(this._tree,t);let r=n.get(Dt);return void 0===r&&n.set(Dt,r=e()),r}values(){return new $t(this,kt)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Ft;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return Ft.from(Object.entries(t))}}const Pt=(t,e,n=[])=>{if(0===e.length||null==t)return[t,n];for(const r of t.keys())if(r!==Dt&&e.startsWith(r))return n.push([t,r]),Pt(t.get(r),e.slice(r.length),n);return n.push([t,e]),Pt(void 0,"",n)},zt=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(n!==Dt&&e.startsWith(n))return zt(t.get(n),e.slice(n.length))},jt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const i of t.keys())if(i!==Dt&&e[r]===i[0]){const o=Math.min(n-r,i.length);let s=1;for(;s<o&&e[r+s]===i[s];)++s;const a=t.get(i);if(s===i.length)t=a;else{const n=new Map;n.set(i.slice(s),a),t.set(e.slice(r,r+s),n),t.delete(i),t=n}r+=s;continue t}const i=new Map;return t.set(e.slice(r),i),i}return t},Gt=(t,e)=>{const[n,r]=Pt(t,e);if(void 0!==n)if(n.delete(Dt),0===n.size)Vt(r);else if(1===n.size){const[t,e]=n.entries().next().value;Yt(r,t,e)}},Vt=t=>{if(0===t.length)return;const[e,n]=Jt(t);if(e.delete(n),0===e.size)Vt(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;n!==Dt&&Yt(t.slice(0,-1),n,r)}},Yt=(t,e,n)=>{if(0===t.length)return;const[r,i]=Jt(t);r.set(i+e,n),r.delete(i)},Jt=t=>t[t.length-1],Wt=/[\n\r\p{Z}\p{P}]+/u,qt="or",Zt="and",Ht="and_not",Qt=(t,e)=>{t.includes(e)||t.push(e)},Xt=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},Kt=({score:t},{score:e})=>e-t,te=()=>new Map,ee=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,ne={[qt]:(t,e)=>{for(const n of e.keys()){const r=t.get(n);if(null==r)t.set(n,e.get(n));else{const{score:t,terms:i,match:o}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,o),Xt(r.terms,i)}}return t},[Zt]:(t,e)=>{const n=new Map;for(const r of e.keys()){const i=t.get(r);if(null==i)continue;const{score:o,terms:s,match:a}=e.get(r);Xt(i.terms,s),n.set(r,{score:i.score+o,terms:i.terms,match:Object.assign(i.match,a)})}return n},[Ht]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},re=(t,e,n,r,i,o)=>{const{k:s,b:a,d:u}=o;return Math.log(1+(n-e+.5)/(e+.5))*(u+t*(s+1)/(t+s*(1-a+a*r/i)))},ie=(t,e,n,r)=>{for(const i of Object.keys(t._fieldIds))if(t._fieldIds[i]===n)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${r}" was not present in field "${i}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},oe=(t,e,n,r)=>{const i=t._index.fetch(r,te);let o=i.get(e);if(null==o)o=new Map,o.set(n,1),i.set(e,o);else{const t=o.get(n);o.set(n,(t??0)+1)}},se=(t,e,n,r)=>{if(!t._index.has(r))return void ie(t,n,e,r);const i=t._index.fetch(r,te),o=i.get(e),s=o?.get(n);!o||typeof s>"u"?ie(t,n,e,r):s<=1?o.size<=1?i.delete(e):o.delete(n):o.set(n,s-1),0===t._index.get(r).size&&t._index.delete(r)},ae=(t,e,n,r,i)=>{let o=t._fieldLength.get(e);null==o&&t._fieldLength.set(e,o=[]),o[n]=i;const s=(t._avgFieldLength[n]||0)*r+i;t._avgFieldLength[n]=s/(r+1)},ue=(t,e)=>{const{extractField:n,tokenize:r,processTerm:i,fields:o,idField:s}=t._options,a=n(e,s);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${s}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const u=((t,e)=>{const n=t._nextId;return t._idToShortId.set(e,n),t._documentIds.set(n,e),t._documentCount+=1,t._nextId+=1,n})(t,a);((t,e,n)=>{const{storeFields:r,extractField:i}=t._options;if(0===r?.length)return;let o=t._storedFields.get(e);void 0===o&&t._storedFields.set(e,o={});for(const t of r){const e=i(n,t);null!=e&&(o[t]=e)}})(t,u,e);for(const s of o){const o=n(e,s);if(null==o)continue;const a=r(o.toString(),s),c=t._fieldIds[s],d=new Set(a).size;ae(t,u,c,t._documentCount-1,d);for(const e of a){const n=i(e,s);if(Array.isArray(n))for(const e of n)oe(t,c,u,e);else n&&oe(t,c,u,n)}}},ce={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split(Wt),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},de={combineWith:qt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},le={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},he={minDirtFactor:.1,minDirtCount:20},fe={batchSize:1e3,batchWait:10,...he},pe=Symbol("*"),me=(t,e=qt)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in ne))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(ne[n])},ge=(t,e,n,r,i,o,s,a,u,c=new Map)=>{if(null==o)return c;for(const d of Object.keys(s)){const l=s[d],h=t._fieldIds[d],f=o.get(h);if(null==f)continue;let p=f.size;const m=t._avgFieldLength[h];for(const o of f.keys()){if(!t._documentIds.has(o)){se(t,h,o,n),p-=1;continue}const s=a?a(t._documentIds.get(o),n,t._storedFields.get(o)):1;if(!s)continue;const g=f.get(o),I=t._fieldLength.get(o)[h],T=r*i*l*s*re(g,p,t._documentCount,I,m,u),v=c.get(o);if(v){v.score+=T,Qt(v.terms,e);const t=ee(v.match,n);t?t.push(d):v.match[n]=[d]}else c.set(o,{score:T,terms:[e],match:{[n]:[d]}})}}return c},Ie=(t,e,n={})=>{if(e===pe)return((t,e)=>{const n=new Map,r={...t._options.searchOptions,...e};for(const[e,i]of t._documentIds){const o=r.boostDocument?r.boostDocument(i,"",t._storedFields.get(e)):1;n.set(e,{score:o,terms:[],match:{}})}return n})(t,n);if("string"!=typeof e){const r={...n,...e,queries:void 0},i=e.queries.map((e=>Ie(t,e,r)));return me(i,r.combineWith)}const{tokenize:r,processTerm:i,searchOptions:o}=t._options,s={tokenize:r,processTerm:i,...o,...n},{tokenize:a,processTerm:u}=s,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,n,r)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,n,r):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,n,r):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,n,r):1}))(s)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},i=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:ee(r.boost,e)||1})),{}),{boostDocument:o,weights:s,maxFuzzy:a,bm25:u}=r,{fuzzy:c,prefix:d}={...de.weights,...s},l=t._index.get(e.term),h=ge(t,e.term,e.term,1,e.termBoost,l,i,o,u);let f,p;if(e.prefix&&(f=t._index.atPrefix(e.term)),e.fuzzy){const n=!0===e.fuzzy?.2:e.fuzzy,r=n<1?Math.min(a,Math.round(e.term.length*n)):n;r&&(p=t._index.fuzzyGet(e.term,r))}if(f)for(const[n,r]of f){const s=n.length-e.term.length;if(!s)continue;p?.delete(n);const a=d*n.length/(n.length+.3*s);ge(t,e.term,n,a,e.termBoost,r,i,o,u,h)}if(p)for(const n of p.keys()){const[r,s]=p.get(n);if(!s)continue;const a=c*n.length/(n.length+s);ge(t,e.term,n,a,e.termBoost,r,i,o,u,h)}return h})(t,e,s)));return me(c,s.combineWith)};class Te{_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?fe:t.autoVacuum;this._options={...ce,...t,autoVacuum:e,searchOptions:{...de,...t.searchOptions},autoSuggestOptions:{...le,...t.autoSuggestOptions}},this._index=new Ft,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=he,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,n]of this._index){const r={};for(const[t,e]of n)r[t]=Object.fromEntries(e);t.push([e,r])}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 ve=t=>{const e=t.toLowerCase(),n=new Set([e]),r={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,i]of Object.entries(r))e.includes(t)&&i.forEach((r=>{n.add(e.replace(t,r))})),i.forEach((r=>{e.includes(r)&&n.add(e.replace(r,t))}));return Array.from(n)};var Se;function ye(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return Se.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return Se.STATION;case 2:case"ENTRANCE_EXIT":return Se.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return Se.GENERIC_NODE;case 4:case"BOARDING_AREA":return Se.BOARDING_AREA;default:return Se.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"}(Se||(Se={}));const Ae={encode(t,e=new y){""!==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 n of t.children)e.uint32(n);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 n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={name:"",sourceStopId:"",lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;i.name=n.string();continue;case 2:if(18!==t)break;i.sourceStopId=n.string();continue;case 3:if(29!==t)break;i.lat=n.float();continue;case 4:if(37!==t)break;i.lon=n.float();continue;case 5:if(40===t){i.children.push(n.uint32());continue}if(42===t){const t=n.uint32()+n.pos;for(;n.pos<t;)i.children.push(n.uint32());continue}break;case 6:if(48!==t)break;i.parent=n.uint32();continue;case 7:if(56!==t)break;i.locationType=n.int32();continue;case 8:if(66!==t)break;i.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({name:Re(t.name)?globalThis.String(t.name):"",sourceStopId:Re(t.sourceStopId)?globalThis.String(t.sourceStopId):"",lat:Re(t.lat)?globalThis.Number(t.lat):void 0,lon:Re(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:Re(t.parent)?globalThis.Number(t.parent):void 0,locationType:Re(t.locationType)?ye(t.locationType):0,platform:Re(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const n={};return""!==t.name&&(n.name=t.name),""!==t.sourceStopId&&(n.sourceStopId=t.sourceStopId),void 0!==t.lat&&(n.lat=t.lat),void 0!==t.lon&&(n.lon=t.lon),(null===(e=t.children)||void 0===e?void 0:e.length)&&(n.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(n.parent=Math.round(t.parent)),0!==t.locationType&&(n.locationType=function(t){switch(t){case Se.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Se.STATION:return"STATION";case Se.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Se.GENERIC_NODE:return"GENERIC_NODE";case Se.BOARDING_AREA:return"BOARDING_AREA";case Se.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>Ae.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,i,o,s,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!==(n=t.sourceStopId)&&void 0!==n?n:"",c.lat=null!==(r=t.lat)&&void 0!==r?r:void 0,c.lon=null!==(i=t.lon)&&void 0!==i?i:void 0,c.children=(null===(o=t.children)||void 0===o?void 0:o.map((t=>t)))||[],c.parent=null!==(s=t.parent)&&void 0!==s?s: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 Ee={encode(t,e=new y){""!==t.version&&e.uint32(10).string(t.version);for(const n of t.stops)Ae.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof A?t:new A(t),r=void 0===e?n.len:n.pos+e,i={version:"",stops:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;i.version=n.string();continue;case 2:if(18!==t)break;i.stops.push(Ae.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({version:Re(t.version)?globalThis.String(t.version):"",stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>Ae.fromJSON(t))):[]}),toJSON(t){var e;const n={};return""!==t.version&&(n.version=t.version),(null===(e=t.stops)||void 0===e?void 0:e.length)&&(n.stops=t.stops.map((t=>Ae.toJSON(t)))),n},create:t=>Ee.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={version:"",stops:[]};return r.version=null!==(e=t.version)&&void 0!==e?e:"",r.stops=(null===(n=t.stops)||void 0===n?void 0:n.map((t=>Ae.fromPartial(t))))||[],r}};function Re(t){return null!=t}const we="0.0.3",be=t=>({version:we,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:Oe(e.locationType),platform:e.platform};var e}))}),_e=t=>{if(t.version!==we)throw new Error(`Unsupported stopMap version ${t.version}`);return t.stops.map(((t,e)=>{return{id:e,sourceStopId:(n=t).sourceStopId,name:n.name,lat:n.lat,lon:n.lon,children:n.children,parent:n.parent,locationType:Ne(n.locationType),platform:n.platform};var n}))},Ne=t=>{switch(t){case Se.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Se.STATION:return"STATION";case Se.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Se.GENERIC_NODE:return"GENERIC_NODE";case Se.BOARDING_AREA:return"BOARDING_AREA";case Se.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},Oe=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return Se.SIMPLE_STOP_OR_PLATFORM;case"STATION":return Se.STATION;case"ENTRANCE_EXIT":return Se.ENTRANCE_EXIT;case"GENERIC_NODE":return Se.GENERIC_NODE;case"BOARDING_AREA":return Se.BOARDING_AREA}};class Me{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const n=new Map;this.stopPoints=[];for(let r=0;r<t.length;r++){const i=t[r];this.sourceStopsMap.set(i.sourceStopId,r);const o=null!==(e=i.parent)&&void 0!==e?e:r;n.has(o)||n.set(o,{id:o,name:i.parent?this.stops[i.parent].name:i.name}),i.lat&&i.lon&&this.stopPoints.push({id:r,lat:i.lat,lon:i.lon})}this.textIndex=new Te({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:ve});const r=Array.from(n.values());((t,e)=>{for(const n of e)ue(t,n)})(this.textIndex,r),this.geoIndex=new _t(this.stopPoints.length);for(let t=0;t<this.stopPoints.length;t++){const{lat:e,lon:n}=this.stopPoints[t];this.geoIndex.add(n,e)}this.geoIndex.finish()}static fromData(t){const e=new A(t),n=Ee.decode(e);return new Me(_e(n))}serialize(){const t=be(this.stops),e=new y;return Ee.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,i={...r,...n},o=Ie(t,e,n),s=[];for(const[e,{score:n,terms:r,match:a}]of o){const o=r.length||1,u={id:t._documentIds.get(e),score:n*o,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(u,t._storedFields.get(e)),(null==i.filter||i.filter(u))&&s.push(u)}return e===pe&&null==i.boostDocument||s.sort(Kt),s})(this.textIndex,t).map((t=>this.stops[t.id])).slice(0,e)}findStopsByLocation(t,e,n=5,r=.5){const i=function(t,e,n,r=1/0,i=1/0){let o=1;const s=[];void 0===r&&(r=1/0),void 0!==i&&(o=Et(i/6371));const a=new Tt([],At);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(n*St);for(;u;){const i=u.right,d=u.left;if(i-d<=t.nodeSize)for(let r=d;r<=i;r++){const i=t.ids[r];{const o=wt(e,n,t.coords[2*r],t.coords[2*r+1],c);a.push({id:i,dist:o})}}else{const r=d+i>>1,o=t.coords[2*r],s=t.coords[2*r+1],l=t.ids[r];{const t=wt(e,n,o,s,c);a.push({id:l,dist:t})}const h=(u.axis+1)%2,f={left:d,right:r-1,axis:h,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?o:u.maxLng,maxLat:1===u.axis?s:u.maxLat,dist:0},p={left:r+1,right:i,axis:h,minLng:0===u.axis?o:u.minLng,minLat:1===u.axis?s:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};f.dist=yt(e,n,c,f),p.dist=yt(e,n,c,p),a.push(f),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>o)return s;if(s.push(t.id),s.length===r)return s}u=a.pop()}return s}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return i}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,n;const r=this.sourceStopsMap.get(t);if(void 0===r)return[];const i=this.stops[r];if(!i)return[];const o=i.parent?null!==(n=null===(e=this.stops[i.parent])||void 0===e?void 0:e.children)&&void 0!==n?n:[]:i.children;return Array.from(new Set([r,...o])).map((t=>this.stops[t]))}}t.Duration=e,t.Plotter=class{constructor(t){this.ROUND_COLORS=["#60a5fa","#ff9800","#14b8a6","#fb7185","#ffdf00","#b600ff","#ee82ee"],this.result=t}getRoundColor(t){var e;if(0===t)return"#888888";const n=Math.min(t-1,this.ROUND_COLORS.length-1);return null!==(e=this.ROUND_COLORS[n])&&void 0!==e?e:"#ee82ee"}escapeDotString(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}getStationInfo(t){var e,n;return{isOrigin:null!==(n=null===(e=this.result.routingState.graph[0])||void 0===e?void 0:e.has(t))&&void 0!==n&&n,isDestination:this.result.routingState.destinations.includes(t)}}formatStopName(t){const e=this.result.stopsIndex.findStopById(t);if(!e)return`Unknown Stop (${t})`;const n=this.escapeDotString(e.name),r=e.platform?this.escapeDotString(e.platform):"";return r?`${n}\\nPl. ${r}`:n}getStationFillColor(t,e){return t?"#60a5fa":e?"#ee82ee":"white"}createStationNode(t){if(!this.result.stopsIndex.findStopById(t))return"";const e=this.formatStopName(t),n=this.escapeDotString(String(t)),r=`s_${t}`,i=this.getStationInfo(t);return` "${r}" [label="${e}\\n${n}" shape=box style=filled fillcolor="${this.getStationFillColor(i.isOrigin,i.isDestination)}"];`}createVehicleEdge(t,e){var n;const r=`s_${t.from}`,i=`s_${t.to}`,o=this.getRoundColor(e),s=`e_${t.from}_${t.to}_${t.routeId}_${e}`,a=this.result.timetable.getRoute(t.routeId),u=a?this.result.timetable.getServiceRouteInfo(a):null,c=null!==(n=null==u?void 0:u.name)&&void 0!==n?n:`Route ${String(t.routeId)}`,d=(null==u?void 0:u.type)||"UNKNOWN",l=a?a.departureFrom(t.from,t.tripIndex).toString():"N/A",h=t.arrival.toString(),f=this.escapeDotString(c);return[` "${s}" [label="${`${this.escapeDotString(d)} ${f}\\n${`${t.routeId}:${t.tripIndex}`}\\n${l} → ${h}`}" shape=oval style=filled fillcolor="white" color="${o}"];`,` "${r}" -> "${s}" [color="${o}"];`,` "${s}" -> "${i}" [color="${o}"];`]}createTransferEdge(t,e){var n;const r=`s_${t.from}`,i=`s_${t.to}`,o=this.getRoundColor(e),s=`e_${t.from}_${t.to}_${e}`,a=(null===(n=t.minTransferTime)||void 0===n?void 0:n.toString())||"N/A";return[` "${s}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${o}"];`,` "${r}" -> "${s}" [color="${o}" style="dashed"];`,` "${s}" -> "${i}" [color="${o}" style="dashed"];`]}createContinuationEdge(t,e,n){var r,i;const o=`s_${t.to}`,s=`s_${e.from}`,a=this.getRoundColor(n),u=`continuation_${t.to}_${e.from}_${n}`,c=this.result.timetable.getRoute(t.routeId),d=this.result.timetable.getRoute(e.routeId),l=c?this.result.timetable.getServiceRouteInfo(c):null,h=d?this.result.timetable.getServiceRouteInfo(d):null,f=null!==(r=null==l?void 0:l.name)&&void 0!==r?r:`Route ${String(t.routeId)}`,p=null!==(i=null==h?void 0:h.name)&&void 0!==i?i:`Route ${String(e.routeId)}`,m=(null==l?void 0:l.type)||"UNKNOWN",g=(null==h?void 0:h.type)||"UNKNOWN",I=t.arrival.toString(),T=d?d.departureFrom(e.from,e.tripIndex).toString():"N/A",v=this.escapeDotString(f),S=this.escapeDotString(p),y=this.escapeDotString(m),A=this.escapeDotString(g);return[` "${u}" [label="${`${y} ${v} (${`${t.routeId}:${t.tripIndex}`}) ${I}\\n↓\\n${A} ${S} (${`${e.routeId}:${e.tripIndex}`}) ${T}`}" shape=oval style="filled,bold" fillcolor="#ffffcc" color="${a}" penwidth="2"];`,` "${o}" -> "${u}" [color="${a}" style="bold" penwidth="3"];`,` "${u}" -> "${s}" [color="${a}" style="bold" penwidth="3"];`]}collectGraphData(){const t=new Set,e=[],n=[],r=this.result.routingState.graph;return r.forEach((e=>{e.forEach(((e,n)=>{t.add(n),"from"in e&&"to"in e&&(t.add(e.from),t.add(e.to))}))})),r.forEach(((t,r)=>{0!==r&&t.forEach((t=>{if("from"in t&&"to"in t)if("routeId"in t){const i=this.createVehicleEdge(t,r);if(e.push(...i),t.continuationOf){let e=t,i=t.continuationOf;for(;i;){const t=this.createContinuationEdge(i,e,r);n.push(...t),e=i,i=i.continuationOf}}}else{const n=this.createTransferEdge(t,r);e.push(...n)}}))})),e.push(...n),{stations:t,edges:e}}plotDotGraph(){const{stations:t,edges:e}=this.collectGraphData(),n=["digraph RoutingGraph {"," graph [overlap=false, splines=true, rankdir=TB, bgcolor=white, nodesep=0.8, ranksep=1.2, concentrate=true];",' node [fontname="Arial" margin=0.1];',' edge [fontname="Arial" fontsize=10];',""," // Stations"];return t.forEach((t=>{const e=this.createStationNode(t);e&&n.push(e)})),n.push(""," // Edges"),n.push(...e),n.push("}"),n.join("\n")}},t.Query=pt,t.Result=gt,t.Route=mt,t.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}route(t){const e=this.initRoutingState(t),n=new Set;for(const t of e.graph[0].keys())n.add(t);const r=this.considerTransfers(t,0,n,e);for(const t of r)n.add(t);for(let r=1;r<=t.options.maxTransfers+1;r++){const i=new Map;e.graph.push(i);const o=this.timetable.findReachableRoutes(n,t.options.transportModes);n.clear();for(const[t,i]of o){const o=this.scanRoute(t,i,r,e);for(const t of o)n.add(t)}let s=this.findTripContinuations(n,i);for(;s.length>0;){const t=new Set;for(const n of s){const i=this.timetable.getRoute(n.routeId),o=this.scanRoute(i,n.hopOnStopIndex,r,e,n);for(const e of o)t.add(e)}for(const e of t)n.add(e);s=this.findTripContinuations(t,i)}const a=this.considerTransfers(t,r,n,e);for(const t of a)n.add(t);if(0===n.size)break}return new gt(t,e,this.stopsIndex,this.timetable)}findTripContinuations(t,e){const n=[];for(const r of t){const t=e.get(r);if(!t||!("routeId"in t))continue;const i=this.timetable.getContinuousTrips(t.to,t.routeId,t.tripIndex);for(let e=0;e<i.length;e++){const r=i[e];n.push({routeId:r.routeId,hopOnStopIndex:r.hopOnStopIndex,tripIndex:r.tripIndex,previousEdge:t})}}return n}initRoutingState(t){const{from:e,to:n,departureTime:r}=t,i=this.stopsIndex.equivalentStops(e).map((t=>t.id)),o=Array.from(n).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),s=new Map,a=new Map,u=[a],c={arrival:r,legNumber:0};for(const t of i)s.set(t,c),a.set(t,c);return{destinations:o,earliestArrivals:s,graph:u}}scanRoute(t,e,n,r,i){var o,s,a;const u=new Set;let c=i?{routeId:t.id,hopOnStopIndex:e,tripIndex:i.tripIndex}:void 0;const d=r.graph[n],l=r.graph[n-1],h=this.earliestArrivalAtAnyStop(r.earliestArrivals,r.destinations);for(let f=e;f<t.getNbStops();f++){const e=t.stops[f];if(void 0!==c){const a=t.arrivalAt(f,c.tripIndex),l=t.dropOffTypeAt(f,c.tripIndex),p=null!==(s=null===(o=r.earliestArrivals.get(e))||void 0===o?void 0:o.arrival)&&void 0!==s?s:It;if("NOT_AVAILABLE"!==l&&a.isBefore(p)&&a.isBefore(h)){const o={arrival:a,routeId:t.id,tripIndex:c.tripIndex,from:c.hopOnStopIndex,to:f};i&&(o.continuationOf=i.previousEdge),d.set(e,o),r.earliestArrivals.set(e,{arrival:a,legNumber:n}),u.add(e)}}if(i)continue;const p=null===(a=l.get(e))||void 0===a?void 0:a.arrival;if(void 0!==p&&(void 0===c||p.isBefore(t.departureFrom(f,c.tripIndex))||p.equals(t.departureFrom(f,c.tripIndex)))){const e=t.findEarliestTrip(f,p,null==c?void 0:c.tripIndex);void 0!==e&&(c={routeId:t.id,tripIndex:e,hopOnStopIndex:f})}}return u}considerTransfers(t,n,r,i){var o,s;const{options:a}=t,u=i.graph[n],c=new Set;for(const t of r){const r=u.get(t);if(!r||"type"in r)continue;const d=this.timetable.getTransfers(t);for(let l=0;l<d.length;l++){const h=d[l];let f;f=h.minTransferTime?h.minTransferTime:"IN_SEAT"===h.type?e.zero():a.minTransferTime;const p=r.arrival.plus(f),m=null!==(s=null===(o=u.get(h.destination))||void 0===o?void 0:o.arrival)&&void 0!==s?s:It;p.isBefore(m)&&(u.set(h.destination,{arrival:p,from:t,to:h.destination,minTransferTime:h.minTransferTime,type:h.type}),i.earliestArrivals.set(h.destination,{arrival:p,legNumber:n}),c.add(h.destination))}}return c}earliestArrivalAtAnyStop(t,e){var n,r;let i=It;for(let o=0;o<e.length;o++){const s=e[o],a=null!==(r=null===(n=t.get(s))||void 0===n?void 0:n.arrival)&&void 0!==r?r:It;i=P.min(i,a)}return i}},t.StopsIndex=Me,t.Time=P,t.Timetable=ft}));
|
|
2
2
|
//# sourceMappingURL=router.umd.js.map
|