minotor 1.0.4 → 1.0.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2 -2
- package/dist/router.cjs.js +1 -1
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.d.ts +3 -2
- package/dist/router.esm.js +1 -1
- package/dist/router.umd.js +1 -1
- package/dist/router.umd.js.map +1 -1
- package/package.json +1 -1
- package/src/router.ts +5 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
## [1.0.
|
|
1
|
+
## [1.0.5](https://github.com/aubryio/minotor/compare/v1.0.4...v1.0.5) (2025-02-11)
|
|
2
2
|
|
|
3
3
|
|
|
4
4
|
### Bug Fixes
|
|
5
5
|
|
|
6
|
-
* expose
|
|
6
|
+
* expose route and duration types ([#10](https://github.com/aubryio/minotor/issues/10)) ([51ff6a5](https://github.com/aubryio/minotor/commit/51ff6a5f0e0abbd850cf0a05a5ab35734c4fdaf0))
|
package/dist/router.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";class t{constructor(t){this.totalSeconds=t}static fromSeconds(e){return new t(e)}static fromMinutes(e){return new t(60*e)}static zero(){return new t(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),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(e){const n=this.totalSeconds+e.toSeconds();return new t(n)}subtract(e){const n=Math.max(0,this.totalSeconds-e.toSeconds());return new t(n)}}function e(){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 n(t,e,n){for(let r=0;r<28;r+=7){const s=t>>>r,o=!(s>>>7==0&&0==e),i=255&(o?128|s:s);if(n.push(i),!o)return}const r=t>>>28&15|(7&e)<<4,s=!!(e>>3);if(n.push(255&(s?128|r:r)),s){for(let t=3;t<31;t+=7){const r=e>>>t,s=!(r>>>7==0),o=255&(s?128|r:r);if(n.push(o),!s)return}n.push(e>>>31&1)}}const r=4294967296;function s(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let s=0,o=0;function c(e,i){const a=Number(t.slice(e,i));o*=n,s=s*n+a,s>=r&&(o+=s/r|0,s%=r)}return c(-24,-18),c(-18,-12),c(-12,-6),c(-6),e?a(s,o):i(s,o)}function o(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(r*e+t);const n=16777215&(t>>>24|e<<8),s=e>>16&65535;let o=(16777215&t)+6777216*n+6710656*s,i=n+8147497*s,a=2*s;const u=1e7;return o>=u&&(i+=Math.floor(o/u),o%=u),i>=u&&(a+=Math.floor(i/u),i%=u),a.toString()+c(i)+c(o)}function i(t,e){return{lo:0|t,hi:0|e}}function a(t,e){return e=~e,t?t=1+~t:e+=1,i(t,e)}const c=t=>{const e=String(t);return"0000000".slice(e.length)+e};function u(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 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"),s=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>s||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()),h(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),h(t),s(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),p(t),s(t)),dec:(t,e)=>function(t,e){let n=i(t,e);const r=2147483648&n.hi;r&&(n=a(n.lo,n.hi));const s=o(n.lo,n.hi);return r?"-"+s:s}(t,e),uDec:(t,e)=>o(t,e)}}function h(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function p(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const m=Symbol.for("@bufbuild/protobuf/text-encoding");function v(){if(null==globalThis[m]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[m]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[m]}var 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 g=34028234663852886e22,E=-34028234663852886e22;class y{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(_(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return I(t),u(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),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>g||t<E))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){_(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){I(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return I(t),u(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 n(e.lo,e.hi,this.buf),this}sint64(t){let e=d.enc(t),r=e.hi>>31;return n(e.lo<<1^r,(e.hi<<1|e.lo>>>31)^r,this.buf),this}uint64(t){let e=d.uEnc(t);return n(e.lo,e.hi,this.buf),this}}class A{constructor(t,n=v().decodeUtf8){this.decodeUtf8=n,this.varint64=e,this.uint32=l,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.uint32(),e=t>>>3,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 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 I(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 _(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 R,S,N;function O(t){switch(t){case 0:case"NOT_AVAILABLE":return R.NOT_AVAILABLE;case 1:case"MUST_PHONE_AGENCY":return R.MUST_PHONE_AGENCY;case 2:case"MUST_COORDINATE_WITH_DRIVER":return R.MUST_COORDINATE_WITH_DRIVER;default:return R.UNRECOGNIZED}}function w(t){switch(t){case R.NOT_AVAILABLE:return"NOT_AVAILABLE";case R.MUST_PHONE_AGENCY:return"MUST_PHONE_AGENCY";case R.MUST_COORDINATE_WITH_DRIVER:return"MUST_COORDINATE_WITH_DRIVER";case R.UNRECOGNIZED:default:return"UNRECOGNIZED"}}function b(t){switch(t){case 0:case"RECOMMENDED_TRANSFER_POINT":return S.RECOMMENDED_TRANSFER_POINT;case 1:case"TIMED_TRANSFER":return S.TIMED_TRANSFER;case 2:case"REQUIRES_MINIMAL_TIME":return S.REQUIRES_MINIMAL_TIME;case 3:case"IN_SEAT_TRANSFER":return S.IN_SEAT_TRANSFER;default:return S.UNRECOGNIZED}}function k(t){switch(t){case 0:case"TRAM":return N.TRAM;case 1:case"SUBWAY":return N.SUBWAY;case 2:case"RAIL":return N.RAIL;case 3:case"BUS":return N.BUS;case 4:case"FERRY":return N.FERRY;case 5:case"CABLE_TRAM":return N.CABLE_TRAM;case 6:case"AERIAL_LIFT":return N.AERIAL_LIFT;case 7:case"FUNICULAR":return N.FUNICULAR;case 8:case"TROLLEYBUS":return N.TROLLEYBUS;case 9:case"MONORAIL":return N.MONORAIL;default:return N.UNRECOGNIZED}}!function(t){t[t.NOT_AVAILABLE=0]="NOT_AVAILABLE",t[t.MUST_PHONE_AGENCY=1]="MUST_PHONE_AGENCY",t[t.MUST_COORDINATE_WITH_DRIVER=2]="MUST_COORDINATE_WITH_DRIVER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(R||(R={})),function(t){t[t.RECOMMENDED_TRANSFER_POINT=0]="RECOMMENDED_TRANSFER_POINT",t[t.TIMED_TRANSFER=1]="TIMED_TRANSFER",t[t.REQUIRES_MINIMAL_TIME=2]="REQUIRES_MINIMAL_TIME",t[t.IN_SEAT_TRANSFER=3]="IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(S||(S={})),function(t){t[t.TRAM=0]="TRAM",t[t.SUBWAY=1]="SUBWAY",t[t.RAIL=2]="RAIL",t[t.BUS=3]="BUS",t[t.FERRY=4]="FERRY",t[t.CABLE_TRAM=5]="CABLE_TRAM",t[t.AERIAL_LIFT=6]="AERIAL_LIFT",t[t.FUNICULAR=7]="FUNICULAR",t[t.TROLLEYBUS=8]="TROLLEYBUS",t[t.MONORAIL=9]="MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(N||(N={}));const M={encode:(t,e=new y)=>(0!==t.arrival&&e.uint32(8).int32(t.arrival),0!==t.departure&&e.uint32(16).int32(t.departure),void 0!==t.pickUpType&&e.uint32(24).int32(t.pickUpType),void 0!==t.dropOffType&&e.uint32(32).int32(t.dropOffType),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={arrival:0,departure:0,pickUpType:void 0,dropOffType:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.arrival=n.int32();continue;case 2:if(16!==t)break;s.departure=n.int32();continue;case 3:if(24!==t)break;s.pickUpType=n.int32();continue;case 4:if(32!==t)break;s.dropOffType=n.int32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({arrival:V(t.arrival)?globalThis.Number(t.arrival):0,departure:V(t.departure)?globalThis.Number(t.departure):0,pickUpType:V(t.pickUpType)?O(t.pickUpType):void 0,dropOffType:V(t.dropOffType)?O(t.dropOffType):void 0}),toJSON(t){const e={};return 0!==t.arrival&&(e.arrival=Math.round(t.arrival)),0!==t.departure&&(e.departure=Math.round(t.departure)),void 0!==t.pickUpType&&(e.pickUpType=w(t.pickUpType)),void 0!==t.dropOffType&&(e.dropOffType=w(t.dropOffType)),e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s;const o={arrival:0,departure:0,pickUpType:void 0,dropOffType:void 0};return o.arrival=null!==(e=t.arrival)&&void 0!==e?e:0,o.departure=null!==(n=t.departure)&&void 0!==n?n:0,o.pickUpType=null!==(r=t.pickUpType)&&void 0!==r?r:void 0,o.dropOffType=null!==(s=t.dropOffType)&&void 0!==s?s:void 0,o}};const L={encode(t,e=new y){for(const n of t.stopTimes)M.encode(n,e.uint32(10).fork()).join();for(const n of t.stops)e.uint32(18).string(n);return""!==t.serviceRouteId&&e.uint32(26).string(t.serviceRouteId),e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={stopTimes:[],stops:[],serviceRouteId:""};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopTimes.push(M.decode(n,n.uint32()));continue;case 2:if(18!==t)break;s.stops.push(n.string());continue;case 3:if(26!==t)break;s.serviceRouteId=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopTimes:globalThis.Array.isArray(null==t?void 0:t.stopTimes)?t.stopTimes.map((t=>M.fromJSON(t))):[],stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>globalThis.String(t))):[],serviceRouteId:V(t.serviceRouteId)?globalThis.String(t.serviceRouteId):""}),toJSON(t){var e,n;const r={};return(null===(e=t.stopTimes)||void 0===e?void 0:e.length)&&(r.stopTimes=t.stopTimes.map((t=>M.toJSON(t)))),(null===(n=t.stops)||void 0===n?void 0:n.length)&&(r.stops=t.stops),""!==t.serviceRouteId&&(r.serviceRouteId=t.serviceRouteId),r},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={stopTimes:[],stops:[],serviceRouteId:""};return s.stopTimes=(null===(e=t.stopTimes)||void 0===e?void 0:e.map((t=>M.fromPartial(t))))||[],s.stops=(null===(n=t.stops)||void 0===n?void 0:n.map((t=>t)))||[],s.serviceRouteId=null!==(r=t.serviceRouteId)&&void 0!==r?r:"",s}};const U={encode:(t,e=new y)=>(Object.entries(t.routes).forEach((([t,n])=>{x.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={routes:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=x.decode(n,n.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:$(t.routes)?Object.entries(t.routes).reduce(((t,[e,n])=>(t[e]=L.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const n=Object.entries(t.routes);n.length>0&&(e.routes={},n.forEach((([t,n])=>{e.routes[t]=L.toJSON(n)})))}return e},create:t=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={routes:{}};return n.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=L.fromPartial(n)),t)),{}),n}};const x={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&L.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=L.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:V(t.key)?globalThis.String(t.key):"",value:V(t.value)?L.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=L.toJSON(t.value)),e},create:t=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?L.fromPartial(t.value):void 0,n}};const D={encode:(t,e=new y)=>(""!==t.destination&&e.uint32(10).string(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).int32(t.minTransferTime),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={destination:"",type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.destination=n.string();continue;case 2:if(16!==t)break;s.type=n.int32();continue;case 3:if(24!==t)break;s.minTransferTime=n.int32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({destination:V(t.destination)?globalThis.String(t.destination):"",type:V(t.type)?b(t.type):0,minTransferTime:V(t.minTransferTime)?globalThis.Number(t.minTransferTime):void 0}),toJSON(t){const e={};return""!==t.destination&&(e.destination=t.destination),0!==t.type&&(e.type=function(t){switch(t){case S.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED_TRANSFER_POINT";case S.TIMED_TRANSFER:return"TIMED_TRANSFER";case S.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case S.IN_SEAT_TRANSFER:return"IN_SEAT_TRANSFER";case S.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={destination:"",type:0,minTransferTime:void 0};return s.destination=null!==(e=t.destination)&&void 0!==e?e:"",s.type=null!==(n=t.type)&&void 0!==n?n:0,s.minTransferTime=null!==(r=t.minTransferTime)&&void 0!==r?r:void 0,s}};const B={encode:(t,e=new y)=>(Object.entries(t.stops).forEach((([t,n])=>{P.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={stops:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=P.decode(n,n.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stops:$(t.stops)?Object.entries(t.stops).reduce(((t,[e,n])=>(t[e]=C.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.stops){const n=Object.entries(t.stops);n.length>0&&(e.stops={},n.forEach((([t,n])=>{e.stops[t]=C.toJSON(n)})))}return e},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={stops:{}};return n.stops=Object.entries(null!==(e=t.stops)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=C.fromPartial(n)),t)),{}),n}};const C={encode(t,e=new y){for(const n of t.transfers)D.encode(n,e.uint32(10).fork()).join();for(const n of t.routes)e.uint32(18).string(n);return e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={transfers:[],routes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.transfers.push(D.decode(n,n.uint32()));continue;case 2:if(18!==t)break;s.routes.push(n.string());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>D.fromJSON(t))):[],routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.String(t))):[]}),toJSON(t){var e,n;const r={};return(null===(e=t.transfers)||void 0===e?void 0:e.length)&&(r.transfers=t.transfers.map((t=>D.toJSON(t)))),(null===(n=t.routes)||void 0===n?void 0:n.length)&&(r.routes=t.routes),r},create:t=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={transfers:[],routes:[]};return r.transfers=(null===(e=t.transfers)||void 0===e?void 0:e.map((t=>D.fromPartial(t))))||[],r.routes=(null===(n=t.routes)||void 0===n?void 0:n.map((t=>t)))||[],r}};const P={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&C.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=C.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:V(t.key)?globalThis.String(t.key):"",value:V(t.value)?C.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=C.toJSON(t.value)),e},create:t=>P.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?C.fromPartial(t.value):void 0,n}};const F={encode:(t,e=new y)=>(0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={type:0,name:""};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.type=n.int32();continue;case 2:if(18!==t)break;s.name=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({type:V(t.type)?k(t.type):0,name:V(t.name)?globalThis.String(t.name):""}),toJSON(t){const e={};return 0!==t.type&&(e.type=function(t){switch(t){case N.TRAM:return"TRAM";case N.SUBWAY:return"SUBWAY";case N.RAIL:return"RAIL";case N.BUS:return"BUS";case N.FERRY:return"FERRY";case N.CABLE_TRAM:return"CABLE_TRAM";case N.AERIAL_LIFT:return"AERIAL_LIFT";case N.FUNICULAR:return"FUNICULAR";case N.TROLLEYBUS:return"TROLLEYBUS";case N.MONORAIL:return"MONORAIL";case N.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),""!==t.name&&(e.name=t.name),e},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={type:0,name:""};return r.type=null!==(e=t.type)&&void 0!==e?e:0,r.name=null!==(n=t.name)&&void 0!==n?n:"",r}};const j={encode:(t,e=new y)=>(Object.entries(t.routes).forEach((([t,n])=>{z.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={routes:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=z.decode(n,n.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:$(t.routes)?Object.entries(t.routes).reduce(((t,[e,n])=>(t[e]=F.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const n=Object.entries(t.routes);n.length>0&&(e.routes={},n.forEach((([t,n])=>{e.routes[t]=F.toJSON(n)})))}return e},create:t=>j.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={routes:{}};return n.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=F.fromPartial(n)),t)),{}),n}};const z={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&F.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=F.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:V(t.key)?globalThis.String(t.key):"",value:V(t.value)?F.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=F.toJSON(t.value)),e},create:t=>z.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?F.fromPartial(t.value):void 0,n}};const G={encode:(t,e=new y)=>(""!==t.version&&e.uint32(10).string(t.version),void 0!==t.stopsAdjacency&&B.encode(t.stopsAdjacency,e.uint32(18).fork()).join(),void 0!==t.routesAdjacency&&U.encode(t.routesAdjacency,e.uint32(26).fork()).join(),void 0!==t.routes&&j.encode(t.routes,e.uint32(34).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=n.string();continue;case 2:if(18!==t)break;s.stopsAdjacency=B.decode(n,n.uint32());continue;case 3:if(26!==t)break;s.routesAdjacency=U.decode(n,n.uint32());continue;case 4:if(34!==t)break;s.routes=j.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({version:V(t.version)?globalThis.String(t.version):"",stopsAdjacency:V(t.stopsAdjacency)?B.fromJSON(t.stopsAdjacency):void 0,routesAdjacency:V(t.routesAdjacency)?U.fromJSON(t.routesAdjacency):void 0,routes:V(t.routes)?j.fromJSON(t.routes):void 0}),toJSON(t){const e={};return""!==t.version&&(e.version=t.version),void 0!==t.stopsAdjacency&&(e.stopsAdjacency=B.toJSON(t.stopsAdjacency)),void 0!==t.routesAdjacency&&(e.routesAdjacency=U.toJSON(t.routesAdjacency)),void 0!==t.routes&&(e.routes=j.toJSON(t.routes)),e},create:t=>G.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};return n.version=null!==(e=t.version)&&void 0!==e?e:"",n.stopsAdjacency=void 0!==t.stopsAdjacency&&null!==t.stopsAdjacency?B.fromPartial(t.stopsAdjacency):void 0,n.routesAdjacency=void 0!==t.routesAdjacency&&null!==t.routesAdjacency?U.fromPartial(t.routesAdjacency):void 0,n.routes=void 0!==t.routes&&null!==t.routes?j.fromPartial(t.routes):void 0,n}};function $(t){return"object"==typeof t&&null!==t}function V(t){return null!=t}class J{static infinity(){return new J(Number.MAX_SAFE_INTEGER)}static origin(){return new J(0)}constructor(t){this.secondsSinceMidnight=t}static fromSeconds(t){return new J(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.");return new J(n+60*e+3600*t)}static fromDate(t){const e=t.getHours(),n=t.getMinutes(),r=t.getSeconds();return new J(r+60*n+3600*e)}static fromString(t){const[e,n,r]=t.split(":");if(void 0===e||void 0===n||isNaN(Number(e))||isNaN(Number(n))||void 0!==r&&isNaN(Number(r)))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const s=parseInt(e,10),o=parseInt(n,10),i=void 0!==r?parseInt(r,10):0;return new J(i+60*o+3600*s)}toString(){const t=Math.floor(this.secondsSinceMidnight/3600),e=Math.floor(this.secondsSinceMidnight%3600/60),n=this.secondsSinceMidnight%60;return`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}toSeconds(){return this.secondsSinceMidnight}plus(t){const e=this.secondsSinceMidnight+t.toSeconds();return new J(e)}minus(t){let e=this.secondsSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new J(e)}diff(e){const n=this.secondsSinceMidnight-e.toSeconds();return t.fromSeconds(Math.abs(n))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.toSeconds()>t.toSeconds()?e:t))}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.toSeconds()<t.toSeconds()?e:t))}}const Y=t=>{const e={stops:{}};return t.forEach(((t,n)=>{e.stops[n]={transfers:t.transfers.map((t=>Object.assign({destination:t.destination,type:q(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))),routes:t.routes}})),e},W=t=>{const e={routes:{}};return t.forEach(((t,n)=>{e.routes[n]={stopTimes:t.stopTimes.map((t=>({arrival:t.arrival.toSeconds(),departure:t.departure.toSeconds(),pickUpType:tt(t.pickUpType),dropOffType:tt(t.dropOffType)}))),stops:t.stops,serviceRouteId:t.serviceRouteId}})),e},H=t=>{const e={routes:{}};return t.forEach(((t,n)=>{e.routes[n]={type:X(t.type),name:t.name}})),e},Z=t=>{switch(t){case S.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case S.TIMED_TRANSFER:return"GUARANTEED";case S.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case S.IN_SEAT_TRANSFER:return"IN_SEAT";case S.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},q=t=>{switch(t){case"RECOMMENDED":return S.RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return S.TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return S.REQUIRES_MINIMAL_TIME;case"IN_SEAT":return S.IN_SEAT_TRANSFER}},Q=t=>{switch(t){case N.TRAM:return"TRAM";case N.SUBWAY:return"SUBWAY";case N.RAIL:return"RAIL";case N.BUS:return"BUS";case N.FERRY:return"FERRY";case N.CABLE_TRAM:return"CABLE_TRAM";case N.AERIAL_LIFT:return"AERIAL_LIFT";case N.FUNICULAR:return"FUNICULAR";case N.TROLLEYBUS:return"TROLLEYBUS";case N.MONORAIL:return"MONORAIL";case N.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},X=t=>{switch(t){case"TRAM":return N.TRAM;case"SUBWAY":return N.SUBWAY;case"RAIL":return N.RAIL;case"BUS":return N.BUS;case"FERRY":return N.FERRY;case"CABLE_TRAM":return N.CABLE_TRAM;case"AERIAL_LIFT":return N.AERIAL_LIFT;case"FUNICULAR":return N.FUNICULAR;case"TROLLEYBUS":return N.TROLLEYBUS;case"MONORAIL":return N.MONORAIL}},K=t=>{switch(t){case R.MUST_PHONE_AGENCY:return"MUST_PHONE_AGENCY";case R.MUST_COORDINATE_WITH_DRIVER:return"MUST_COORDINATE_WITH_DRIVER";case R.NOT_AVAILABLE:return"NOT_AVAILABLE";default:return"REGULAR"}},tt=t=>{switch(t){case"REGULAR":return;case"NOT_AVAILABLE":return R.NOT_AVAILABLE;case"MUST_COORDINATE_WITH_DRIVER":return R.MUST_COORDINATE_WITH_DRIVER;case"MUST_PHONE_AGENCY":return R.MUST_PHONE_AGENCY}},et=["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"],nt="0.0.1";class rt{constructor(t,e,n){this.stopsAdjacency=t,this.routesAdjacency=e,this.routes=n}serialize(){const t={version:nt,stopsAdjacency:Y(this.stopsAdjacency),routesAdjacency:W(this.routesAdjacency),routes:H(this.routes)},e=new y;return G.encode(t,e),e.finish()}static fromData(e){const n=new A(e),r=G.decode(n);if(r.version!==nt)throw new Error(`Unsupported timetable version ${r.version}`);return new rt((e=>{const n=new Map;return Object.entries(e.stops).forEach((([e,r])=>{n.set(e,{transfers:r.transfers.map((e=>Object.assign({destination:e.destination,type:Z(e.type)},void 0!==e.minTransferTime&&{minTransferTime:t.fromSeconds(e.minTransferTime)}))),routes:r.routes})})),n})(r.stopsAdjacency),(t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,n])=>{e.set(t,{stopTimes:n.stopTimes.map((t=>({arrival:J.fromSeconds(t.arrival),departure:J.fromSeconds(t.departure),pickUpType:void 0!==t.pickUpType?K(t.pickUpType):"REGULAR",dropOffType:void 0!==t.dropOffType?K(t.dropOffType):"REGULAR"}))),stops:n.stops,stopIndices:new Map(n.stops.map(((t,e)=>[t,e]))),serviceRouteId:n.serviceRouteId})})),e})(r.routesAdjacency),(t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,n])=>{e.set(t,{type:Q(n.type),name:n.name})})),e})(r.routes))}getRoute(t){return this.routesAdjacency.get(t)}getTransfers(t){var e,n;return null!==(n=null===(e=this.stopsAdjacency.get(t))||void 0===e?void 0:e.transfers)&&void 0!==n?n:[]}findReachableRoutes(t,e=et){var n;const r=new Map;for(const s of t){const t=null===(n=this.stopsAdjacency.get(s))||void 0===n?void 0:n.routes.filter((t=>{const n=this.getServiceRouteFromRouteId(t);return!!n&&e.includes(n.type)}));for(const e of t||[]){const t=r.get(e);if(t){const n=this.routesAdjacency.get(e).stopIndices;n.get(s)<n.get(t)&&r.set(e,s)}else r.set(e,s)}}return r}getServiceRouteFromRouteId(t){const e=this.routesAdjacency.get(t);if(e)return this.routes.get(e.serviceRouteId);console.warn(`Route ${t} not found.`)}getServiceRoute(t){return this.routes.get(t)}findEarliestTrip(t,e,n,r=J.origin()){const s=t.stopIndices.get(e),o=t.stops.length;if(void 0!==n){let e,i;for(let a=n;a>=0;a--){const n=a*o+s,c=t.stopTimes[n];if(c.departure<=r)break;"NOT_AVAILABLE"!==c.pickUpType&&(void 0===i||c.departure<i)&&(e=a,i=c.departure)}return e}for(let e=0;e<t.stopTimes.length/o;e++){const n=e*o+s,i=t.stopTimes[n];if(i.departure>r&&"NOT_AVAILABLE"!==i.pickUpType)return e}}}class st{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}st.Builder=class{constructor(){this.optionsValue={maxTransfers:5,minTransferTime:t.fromSeconds(120),transportModes:et}}from(t){return this.fromValue=t,this}to(t){return this.toValue=Array.isArray(t)?t:[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 st(this)}};class ot{constructor(t){this.legs=t}departureTime(){const e=t.zero();for(let t=0;t<this.legs.length;t++){const n=this.legs[t];if("departureTime"in n)return n.departureTime.minus(e);"minTransferTime"in n&&n.minTransferTime&&e.add(n.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let e=J.origin();const n=t.zero();let r=!1;for(let t=this.legs.length-1;t>=0;t--){const s=this.legs[t];"arrivalTime"in s&&!r?(e=s.arrivalTime,r=!0):"minTransferTime"in s&&s.minTransferTime&&r&&n.add(s.minTransferTime)}if(!r)throw new Error("No vehicle leg found in route");return e.plus(n)}totalDuration(){return 0===this.legs.length?t.zero():this.arrivalTime().diff(this.departureTime())}print(){return this.legs.map(((t,e)=>{var n,r;return"route"in t?`Leg ${e+1}: ${t.from.name} to ${t.to.name}\n via route ${t.route.type} ${t.route.name},\n departs at ${t.departureTime.toString()}, arrives at ${t.arrivalTime.toString()}`:`Leg ${e+1}: Transfer from ${t.from.name} to ${t.to.name},\n minimum transfer time: ${null!==(r=null===(n=t.minTransferTime)||void 0===n?void 0:n.toString())&&void 0!==r?r:"not specified"}`})).join("\n")}}class it{constructor(t,e,n,r){this.query=t,this.earliestArrivals=e,this.earliestArrivalsPerRound=n,this.stopsIndex=r}bestRoute(t){var e,n,r;const s=(Array.isArray(t)?t:t?[t]:this.query.to).flatMap((t=>this.stopsIndex.equivalentStops(t)));let o,i;for(const t of s){const e=this.earliestArrivals.get(t);void 0!==e&&(void 0===i||e.time.toSeconds()<i.time.toSeconds())&&(o=t,i=e)}if(!o||!i)return;const a=[];let c=o,u=i.legNumber;for(;i.origin!==c;){const t=null===(e=this.earliestArrivalsPerRound[u])||void 0===e?void 0:e.get(c);if(!(null==t?void 0:t.leg))throw new Error(`No leg found for a trip leg: start stop=${null!==(r=null===(n=null==t?void 0:t.leg)||void 0===n?void 0:n.from.id)&&void 0!==r?r:"unknown"}, end stop=${c}, round=${u}, origin=${i.origin}`);a.unshift(t.leg),c=t.leg.from.id,"route"in t.leg&&(u-=1)}return new ot(a)}arrivalAt(t,e){const n=this.stopsIndex.equivalentStops(t);let r;const s=void 0!==e?this.earliestArrivalsPerRound[e-1]:this.earliestArrivals;for(const t of n){const e=s.get(t);void 0!==e&&(void 0===r||e.time.toSeconds()<r.time.toSeconds())&&(r=e)}return r}}const at=J.infinity();class ct{constructor(t=[],e=ut){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 s=t-1>>1,o=e[s];if(n(r,o)>=0)break;e[t]=o,t=s}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,s=e[t];for(;t<r;){let r=1+(t<<1),o=e[r];const i=r+1;if(i<this.length&&n(e[i],o)<0&&(r=i,o=e[i]),n(o,s)>=0)break;e[t]=o,t=r}e[t]=s}}function ut(t,e){return t<e?-1:t>e?1:0}const lt=Math.PI/180;function dt(t,e,n,r){const s=r.minLng,o=r.maxLng,i=r.minLat,a=r.maxLat;if(t>=s&&t<=o)return e<i?ht((e-i)*lt):e>a?ht((e-a)*lt):0;const c=Math.min(ht((t-s)*lt),ht((t-o)*lt)),u=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*lt)/n)/lt}(e,c);return u>i&&u<a?pt(c,n,e,u):Math.min(pt(c,n,e,i),pt(c,n,e,a))}function ft(t,e){return t.dist-e.dist}function ht(t){const e=Math.sin(t/2);return e*e}function pt(t,e,n,r){return e*Math.cos(r*lt)*t+ht((n-r)*lt)}function mt(t,e,n,r,s){return pt(ht((t-n)*lt),s,e,r)}const vt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class Tt{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 s=vt[15&n];if(!s)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[i]=new Uint32Array(t,4,1);return new Tt(i,o,s,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 s=vt.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,i=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-i%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${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+i+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+i+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+i+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const 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 gt(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:s,coords:o,nodeSize:i}=this,a=[0,s.length-1,0],c=[];for(;a.length;){const u=a.pop()||0,l=a.pop()||0,d=a.pop()||0;if(l-d<=i){for(let i=d;i<=l;i++){const a=o[2*i],u=o[2*i+1];a>=t&&a<=n&&u>=e&&u<=r&&c.push(s[i])}continue}const f=d+l>>1,h=o[2*f],p=o[2*f+1];h>=t&&h<=n&&p>=e&&p<=r&&c.push(s[f]),(0===u?t<=h:e<=p)&&(a.push(d),a.push(f-1),a.push(1-u)),(0===u?n>=h:r>=p)&&(a.push(f+1),a.push(l),a.push(1-u))}return c}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:s,nodeSize:o}=this,i=[0,r.length-1,0],a=[],c=n*n;for(;i.length;){const u=i.pop()||0,l=i.pop()||0,d=i.pop()||0;if(l-d<=o){for(let n=d;n<=l;n++)It(s[2*n],s[2*n+1],t,e)<=c&&a.push(r[n]);continue}const f=d+l>>1,h=s[2*f],p=s[2*f+1];It(h,p,t,e)<=c&&a.push(r[f]),(0===u?t-n<=h:e-n<=p)&&(i.push(d),i.push(f-1),i.push(1-u)),(0===u?t+n>=h:e+n>=p)&&(i.push(f+1),i.push(l),i.push(1-u))}return a}}function gt(t,e,n,r,s,o){if(s-r<=n)return;const i=r+s>>1;Et(t,e,i,r,s,o),gt(t,e,n,r,i-1,1-o),gt(t,e,n,i+1,s,1-o)}function Et(t,e,n,r,s,o){for(;s>r;){if(s-r>600){const i=s-r+1,a=n-r+1,c=Math.log(i),u=.5*Math.exp(2*c/3),l=.5*Math.sqrt(c*u*(i-u)/i)*(a-i/2<0?-1:1);Et(t,e,n,Math.max(r,Math.floor(n-a*u/i+l)),Math.min(s,Math.floor(n+(i-a)*u/i+l)),o)}const i=e[2*n+o];let a=r,c=s;for(yt(t,e,r,n),e[2*s+o]>i&&yt(t,e,r,s);a<c;){for(yt(t,e,a,c),a++,c--;e[2*a+o]<i;)a++;for(;e[2*c+o]>i;)c--}e[2*r+o]===i?yt(t,e,r,c):(c++,yt(t,e,c,s)),c<=n&&(r=c+1),n<=c&&(s=c-1)}}function yt(t,e,n,r){At(t,n,r),At(e,2*n,2*r),At(e,2*n+1,2*r+1)}function At(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function It(t,e,n,r){const s=t-n,o=e-r;return s*s+o*o}const _t="KEYS",Rt="VALUES",St="";class Nt{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}=Ot(this._path);if(Ot(e)===St)return{done:!1,value:this.result()};const n=t.get(Ot(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Ot(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Ot(t))).filter((t=>t!==St)).join("")}value(){return Ot(this._path).node.get(St)}result(){switch(this._type){case Rt:return this.value();case _t:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Ot=t=>t[t.length-1],wt=(t,e,n,r,s,o,i,a)=>{const c=o*i;t:for(const u of t.keys())if(u===St){const e=s[c-1];e<=n&&r.set(a,[t.get(u),e])}else{let c=o;for(let t=0;t<u.length;++t,++c){const r=u[t],o=i*c,a=o-i;let l=s[o];const d=Math.max(0,c-n-1),f=Math.min(i-1,c+n);for(let t=d;t<f;++t){const n=r!==e[t],i=s[a+t]+ +n,c=s[a+t+1]+1,u=s[o+t]+1,d=s[o+t+1]=Math.min(i,c,u);d<l&&(l=d)}if(l>n)continue t}wt(t.get(u),e,n,r,s,c,i,a+u)}};class bt{_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]=kt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=Bt(n);for(const n of e.keys())if(n!==St&&n.startsWith(r)){const s=new Map;return s.set(n.slice(r.length),e.get(n)),new bt(s,t)}}return new bt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Ut(this._tree,t)}entries(){return new Nt(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 s=e.length+1,o=s+n,i=new Uint8Array(o*s).fill(n+1);for(let t=0;t<s;++t)i[t]=t;for(let t=1;t<o;++t)i[t*s]=t;return wt(t,e,n,r,i,1,s,""),r})(this._tree,t,e)}get(t){const e=Mt(this._tree,t);return void 0!==e?e.get(St):void 0}has(t){return Mt(this._tree,t)?.has(St)??!1}keys(){return new Nt(this,_t)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Lt(this._tree,t).set(St,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=Lt(this._tree,t);return n.set(St,e(n.get(St))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Lt(this._tree,t);let r=n.get(St);return void 0===r&&n.set(St,r=e()),r}values(){return new Nt(this,Rt)}[Symbol.iterator](){return this.entries()}static from(t){const e=new bt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return bt.from(Object.entries(t))}}const kt=(t,e,n=[])=>{if(0===e.length||null==t)return[t,n];for(const r of t.keys())if(r!==St&&e.startsWith(r))return n.push([t,r]),kt(t.get(r),e.slice(r.length),n);return n.push([t,e]),kt(void 0,"",n)},Mt=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(n!==St&&e.startsWith(n))return Mt(t.get(n),e.slice(n.length))},Lt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const s of t.keys())if(s!==St&&e[r]===s[0]){const o=Math.min(n-r,s.length);let i=1;for(;i<o&&e[r+i]===s[i];)++i;const a=t.get(s);if(i===s.length)t=a;else{const n=new Map;n.set(s.slice(i),a),t.set(e.slice(r,r+i),n),t.delete(s),t=n}r+=i;continue t}const s=new Map;return t.set(e.slice(r),s),s}return t},Ut=(t,e)=>{const[n,r]=kt(t,e);if(void 0!==n)if(n.delete(St),0===n.size)xt(r);else if(1===n.size){const[t,e]=n.entries().next().value;Dt(r,t,e)}},xt=t=>{if(0===t.length)return;const[e,n]=Bt(t);if(e.delete(n),0===e.size)xt(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;n!==St&&Dt(t.slice(0,-1),n,r)}},Dt=(t,e,n)=>{if(0===t.length)return;const[r,s]=Bt(t);r.set(s+e,n),r.delete(s)},Bt=t=>t[t.length-1],Ct=/[\n\r\p{Z}\p{P}]+/u,Pt="or",Ft="and",jt="and_not",zt=(t,e)=>{t.includes(e)||t.push(e)},Gt=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},$t=({score:t},{score:e})=>e-t,Vt=()=>new Map,Jt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Yt={[Pt]:(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:s,match:o}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,o),Gt(r.terms,s)}}return t},[Ft]:(t,e)=>{const n=new Map;for(const r of e.keys()){const s=t.get(r);if(null==s)continue;const{score:o,terms:i,match:a}=e.get(r);Gt(s.terms,i),n.set(r,{score:s.score+o,terms:s.terms,match:Object.assign(s.match,a)})}return n},[jt]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},Wt=(t,e,n,r,s,o)=>{const{k:i,b:a,d:c}=o;return Math.log(1+(n-e+.5)/(e+.5))*(c+t*(i+1)/(t+i*(1-a+a*r/s)))},Ht=(t,e,n,r)=>{for(const s of Object.keys(t._fieldIds))if(t._fieldIds[s]===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 "${s}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},Zt=(t,e,n,r)=>{const s=t._index.fetch(r,Vt);let o=s.get(e);if(null==o)o=new Map,o.set(n,1),s.set(e,o);else{const t=o.get(n);o.set(n,(t??0)+1)}},qt=(t,e,n,r)=>{if(!t._index.has(r))return void Ht(t,n,e,r);const s=t._index.fetch(r,Vt),o=s.get(e),i=o?.get(n);!o||typeof i>"u"?Ht(t,n,e,r):i<=1?o.size<=1?s.delete(e):o.delete(n):o.set(n,i-1),0===t._index.get(r).size&&t._index.delete(r)},Qt=(t,e,n,r,s)=>{let o=t._fieldLength.get(e);null==o&&t._fieldLength.set(e,o=[]),o[n]=s;const i=(t._avgFieldLength[n]||0)*r+s;t._avgFieldLength[n]=i/(r+1)},Xt=(t,e)=>{const{extractField:n,tokenize:r,processTerm:s,fields:o,idField:i}=t._options,a=n(e,i);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${i}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const c=((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:s}=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=s(n,t);null!=e&&(o[t]=e)}})(t,c,e);for(const i of o){const o=n(e,i);if(null==o)continue;const a=r(o.toString(),i),u=t._fieldIds[i],l=new Set(a).size;Qt(t,c,u,t._documentCount-1,l);for(const e of a){const n=s(e,i);if(Array.isArray(n))for(const e of n)Zt(t,u,c,e);else n&&Zt(t,u,c,n)}}},Kt={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split(Ct),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},te={combineWith:Pt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},ee={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},ne={minDirtFactor:.1,minDirtCount:20},re={batchSize:1e3,batchWait:10,...ne},se=Symbol("*"),oe=(t,e=Pt)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in Yt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Yt[n])},ie=(t,e,n,r,s,o,i,a,c,u=new Map)=>{if(null==o)return u;for(const l of Object.keys(i)){const d=i[l],f=t._fieldIds[l],h=o.get(f);if(null==h)continue;let p=h.size;const m=t._avgFieldLength[f];for(const o of h.keys()){if(!t._documentIds.has(o)){qt(t,f,o,n),p-=1;continue}const i=a?a(t._documentIds.get(o),n,t._storedFields.get(o)):1;if(!i)continue;const v=h.get(o),T=t._fieldLength.get(o)[f],g=r*s*d*i*Wt(v,p,t._documentCount,T,m,c),E=u.get(o);if(E){E.score+=g,zt(E.terms,e);const t=Jt(E.match,n);t?t.push(l):E.match[n]=[l]}else u.set(o,{score:g,terms:[e],match:{[n]:[l]}})}}return u},ae=(t,e,n={})=>{if(e===se)return((t,e)=>{const n=new Map,r={...t._options.searchOptions,...e};for(const[e,s]of t._documentIds){const o=r.boostDocument?r.boostDocument(s,"",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},s=e.queries.map((e=>ae(t,e,r)));return oe(s,r.combineWith)}const{tokenize:r,processTerm:s,searchOptions:o}=t._options,i={tokenize:r,processTerm:s,...o,...n},{tokenize:a,processTerm:c}=i,u=a(e).flatMap((t=>c(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}))(i)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},s=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:Jt(r.boost,e)||1})),{}),{boostDocument:o,weights:i,maxFuzzy:a,bm25:c}=r,{fuzzy:u,prefix:l}={...te.weights,...i},d=t._index.get(e.term),f=ie(t,e.term,e.term,1,e.termBoost,d,s,o,c);let h,p;if(e.prefix&&(h=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(h)for(const[n,r]of h){const i=n.length-e.term.length;if(!i)continue;p?.delete(n);const a=l*n.length/(n.length+.3*i);ie(t,e.term,n,a,e.termBoost,r,s,o,c,f)}if(p)for(const n of p.keys()){const[r,i]=p.get(n);if(!i)continue;const a=u*n.length/(n.length+i);ie(t,e.term,n,a,e.termBoost,r,s,o,c,f)}return f})(t,e,i)));return oe(u,i.combineWith)};class ce{_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?re:t.autoVacuum;this._options={...Kt,...t,autoVacuum:e,searchOptions:{...te,...t.searchOptions},autoSuggestOptions:{...ee,...t.autoSuggestOptions}},this._index=new bt,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=ne,this.addFields(this._options.fields)}get isVacuuming(){return null!=this._currentVacuum}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}get documentCount(){return this._documentCount}get termCount(){return this._index.size}toJSON(){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 ue=t=>{const e=t.toLowerCase(),n=new Set([e]),r={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,s]of Object.entries(r))e.includes(t)&&s.forEach((r=>{n.add(e.replace(t,r))})),s.forEach((r=>{e.includes(r)&&n.add(e.replace(r,t))}));return Array.from(n)};var le;function de(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return le.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return le.STATION;case 2:case"ENTRANCE_EXIT":return le.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return le.GENERIC_NODE;case 4:case"BOARDING_AREA":return le.BOARDING_AREA;default:return le.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"}(le||(le={}));const fe={encode(t,e=new y){""!==t.name&&e.uint32(10).string(t.name),void 0!==t.lat&&e.uint32(17).double(t.lat),void 0!==t.lon&&e.uint32(25).double(t.lon);for(const n of t.children)e.uint32(34).string(n);return void 0!==t.parent&&e.uint32(42).string(t.parent),0!==t.locationType&&e.uint32(48).int32(t.locationType),void 0!==t.platform&&e.uint32(58).string(t.platform),e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={name:"",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;s.name=n.string();continue;case 2:if(17!==t)break;s.lat=n.double();continue;case 3:if(25!==t)break;s.lon=n.double();continue;case 4:if(34!==t)break;s.children.push(n.string());continue;case 5:if(42!==t)break;s.parent=n.string();continue;case 6:if(48!==t)break;s.locationType=n.int32();continue;case 7:if(58!==t)break;s.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({name:me(t.name)?globalThis.String(t.name):"",lat:me(t.lat)?globalThis.Number(t.lat):void 0,lon:me(t.lon)?globalThis.Number(t.lon):void 0,children:globalThis.Array.isArray(null==t?void 0:t.children)?t.children.map((t=>globalThis.String(t))):[],parent:me(t.parent)?globalThis.String(t.parent):void 0,locationType:me(t.locationType)?de(t.locationType):0,platform:me(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const n={};return""!==t.name&&(n.name=t.name),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),void 0!==t.parent&&(n.parent=t.parent),0!==t.locationType&&(n.locationType=function(t){switch(t){case le.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case le.STATION:return"STATION";case le.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case le.GENERIC_NODE:return"GENERIC_NODE";case le.BOARDING_AREA:return"BOARDING_AREA";case le.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>fe.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s,o,i,a;const c={name:"",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.lat=null!==(n=t.lat)&&void 0!==n?n:void 0,c.lon=null!==(r=t.lon)&&void 0!==r?r:void 0,c.children=(null===(s=t.children)||void 0===s?void 0:s.map((t=>t)))||[],c.parent=null!==(o=t.parent)&&void 0!==o?o:void 0,c.locationType=null!==(i=t.locationType)&&void 0!==i?i:0,c.platform=null!==(a=t.platform)&&void 0!==a?a:void 0,c}};const he={encode:(t,e=new y)=>(""!==t.version&&e.uint32(10).string(t.version),Object.entries(t.stops).forEach((([t,n])=>{pe.encode({key:t,value:n},e.uint32(18).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={version:"",stops:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=n.string();continue;case 2:{if(18!==t)break;const e=pe.decode(n,n.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON(t){return{version:me(t.version)?globalThis.String(t.version):"",stops:(e=t.stops,"object"==typeof e&&null!==e?Object.entries(t.stops).reduce(((t,[e,n])=>(t[e]=fe.fromJSON(n),t)),{}):{})};var e},toJSON(t){const e={};if(""!==t.version&&(e.version=t.version),t.stops){const n=Object.entries(t.stops);n.length>0&&(e.stops={},n.forEach((([t,n])=>{e.stops[t]=fe.toJSON(n)})))}return e},create:t=>he.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=Object.entries(null!==(n=t.stops)&&void 0!==n?n:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=fe.fromPartial(n)),t)),{}),r}};const pe={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&fe.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=fe.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:me(t.key)?globalThis.String(t.key):"",value:me(t.value)?fe.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=fe.toJSON(t.value)),e},create:t=>pe.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?fe.fromPartial(t.value):void 0,n}};function me(t){return null!=t}const ve="0.0.1",Te=t=>{const e={version:ve,stops:{}};return t.forEach(((t,n)=>{var r;e.stops[n]={name:(r=t).name,lat:r.lat,lon:r.lon,children:r.children,parent:r.parent,locationType:ye(r.locationType),platform:r.platform}})),e},ge=t=>{if(t.version!==ve)throw new Error(`Unsupported stopMap version ${t.version}`);const e=new Map;return Object.entries(t.stops).forEach((([t,n])=>{var r;e.set(t,{id:t,name:(r=n).name,lat:r.lat,lon:r.lon,children:r.children,parent:r.parent,locationType:Ee(r.locationType),platform:r.platform})})),e},Ee=t=>{switch(t){case le.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case le.STATION:return"STATION";case le.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case le.GENERIC_NODE:return"GENERIC_NODE";case le.BOARDING_AREA:return"BOARDING_AREA";case le.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},ye=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return le.SIMPLE_STOP_OR_PLATFORM;case"STATION":return le.STATION;case"ENTRANCE_EXIT":return le.ENTRANCE_EXIT;case"GENERIC_NODE":return le.GENERIC_NODE;case"BOARDING_AREA":return le.BOARDING_AREA}};class Ae{constructor(t){var e;this.stopsMap=t,this.textIndex=new ce({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:ue});const n=new Map;for(const[r,s]of t.entries()){const t=null!==(e=s.parent)&&void 0!==e?e:r;n.has(t)||n.set(t,{id:t,name:s.parent?this.stopsMap.get(s.parent).name:s.name})}const r=Array.from(n.values());((t,e)=>{for(const n of e)Xt(t,n)})(this.textIndex,r),this.stopPoints=Array.from(this.stopsMap.entries()).filter((([,t])=>!(!t.lat||!t.lon))).map((([t,e])=>({id:t,lat:e.lat,lon:e.lon}))),this.geoIndex=new Tt(this.stopPoints.length);for(const{lat:t,lon:e}of this.stopPoints)this.geoIndex.add(e,t);this.geoIndex.finish()}static fromData(t){const e=new A(t),n=he.decode(e);return new Ae(ge(n))}serialize(){const t=Te(this.stopsMap),e=new y;return he.encode(t,e),e.finish()}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,s={...r,...n},o=ae(t,e,n),i=[];for(const[e,{score:n,terms:r,match:a}]of o){const o=r.length||1,c={id:t._documentIds.get(e),score:n*o,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(c,t._storedFields.get(e)),(null==s.filter||s.filter(c))&&i.push(c)}return e===se&&null==s.boostDocument||i.sort($t),i})(this.textIndex,t).map((t=>this.stopsMap.get(t.id))).slice(0,e)}findStopsByLocation(t,e,n=5,r=.5){const s=function(t,e,n,r=1/0,s=1/0){let o=1;const i=[];void 0===r&&(r=1/0),void 0!==s&&(o=ht(s/6371));const a=new ct([],ft);let c={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const u=Math.cos(n*lt);for(;c;){const s=c.right,l=c.left;if(s-l<=t.nodeSize)for(let r=l;r<=s;r++){const s=t.ids[r];{const o=mt(e,n,t.coords[2*r],t.coords[2*r+1],u);a.push({id:s,dist:o})}}else{const r=l+s>>1,o=t.coords[2*r],i=t.coords[2*r+1],d=t.ids[r];{const t=mt(e,n,o,i,u);a.push({id:d,dist:t})}const f=(c.axis+1)%2,h={left:l,right:r-1,axis:f,minLng:c.minLng,minLat:c.minLat,maxLng:0===c.axis?o:c.maxLng,maxLat:1===c.axis?i:c.maxLat,dist:0},p={left:r+1,right:s,axis:f,minLng:0===c.axis?o:c.minLng,minLat:1===c.axis?i:c.minLat,maxLng:c.maxLng,maxLat:c.maxLat,dist:0};h.dist=dt(e,n,u,h),p.dist=dt(e,n,u,p),a.push(h),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>o)return i;if(i.push(t.id),i.length===r)return i}c=a.pop()}return i}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stopsMap.get(e.id)}));return s}findStopById(t){return this.stopsMap.get(t)}equivalentStops(t){var e,n;const r=this.stopsMap.get(t);if(!r)return[];const s=r.parent?null!==(n=null===(e=this.stopsMap.get(r.parent))||void 0===e?void 0:e.children)&&void 0!==n?n:[]:r.children;return Array.from(new Set([t,...s]))}}exports.Plotter=class{constructor(t){this.result=t}plotDotGraph(){const t=this.result.earliestArrivalsPerRound,e=["digraph PathTree {"," graph [overlap=false];"," node [shape=ellipse style=filled fillcolor=lightgrey];"];return t.forEach(((t,n)=>{t.forEach((t=>{const{origin:r,leg:s}=t;if(!s)return;const o=this.result.stopsIndex.findStopById(s.from.id),i=this.result.stopsIndex.findStopById(s.to.id),a=this.result.stopsIndex.findStopById(r);if(o&&i&&a){const t=o.platform?`${o.name} (Pl. ${o.platform})`:o.name,r=i.platform?`${i.name} (Pl. ${i.platform})`:i.name,c=a.platform?`${a.name} (Pl. ${a.platform})`:a.name,u="route"in s,l=u?`${s.route.name}\n${s.departureTime.toString()} - ${s.arrivalTime.toString()}`:s.minTransferTime?s.minTransferTime.toString():"",d=`IntermediateNode${o.id}_${i.id}`,f=u?"":', color="red", fontcolor="red"',h=u?"":' fontcolor="red"';e.push(` "${t} (Origin: ${c}) [R${n}]\n(${o.id})" -> "${d}" [shape=point${f}];`),e.push(` "${d}" [label="${l}" shape=rect style=filled fillcolor=white${h} border=0];`),e.push(` "${d}" -> "${r} (Origin: ${c}) [R${n}]\n(${i.id})" [${f.replace(", ","")}];`)}}))})),e.push("}"),e.join("\n")}},exports.Query=st,exports.Result=it,exports.Route=ot,exports.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}considerTransfers(e,n,r,s,o){var i,a,c,u;const{options:l}=e,d=new Set;for(const e of n)for(const n of this.timetable.getTransfers(e)){let f;f=n.minTransferTime?n.minTransferTime:"IN_SEAT"===n.type?t.zero():l.minTransferTime;const h=r.get(e).time.plus(f),p=null!==(a=null===(i=r.get(n.destination))||void 0===i?void 0:i.time)&&void 0!==a?a:at;if(h.toSeconds()<p.toSeconds()){const t=null!==(u=null===(c=r.get(e))||void 0===c?void 0:c.origin)&&void 0!==u?u:e;r.set(n.destination,{time:h,legNumber:o,origin:t,leg:{from:this.stopsIndex.findStopById(e),to:this.stopsIndex.findStopById(n.destination),minTransferTime:n.minTransferTime,type:n.type}}),s.set(n.destination,{time:h,legNumber:o,origin:t}),d.add(n.destination)}}for(const t of d)n.add(t)}route(t){var e,n,r,s,o,i,a;const{from:c,to:u,departureTime:l,options:d}=t,f=this.stopsIndex.equivalentStops(c),h=u.flatMap((t=>this.stopsIndex.equivalentStops(t))),p=new Map,m=new Map,v=[m],T=new Set;for(const t of f)T.add(t),p.set(t,{time:l,legNumber:0,origin:t}),m.set(t,{time:l,legNumber:0,origin:t});this.considerTransfers(t,T,m,p,0);for(let c=1;c<=d.maxTransfers+1;c++){const u=new Map;v.push(u);const l=v[c-1],f=this.timetable.findReachableRoutes(T,d.transportModes);T.clear();for(const[t,d]of f.entries()){const f=this.timetable.getRoute(t);let m;for(let t=f.stopIndices.get(d);t<f.stops.length;t++){const d=f.stops[t],v=f.stops.length;if(void 0!==m){const o=f.stopTimes[m.trip*v+t],i=null!==(n=null===(e=p.get(d))||void 0===e?void 0:e.time)&&void 0!==n?n:at;let a=i;if(h.length>0){const t=[];for(const e of h){const n=null!==(s=null===(r=p.get(e))||void 0===r?void 0:r.time)&&void 0!==s?s:at;t.push(n)}const e=J.min(...t);a=J.min(i,e)}if("NOT_AVAILABLE"!==o.dropOffType&&o.arrival.toSeconds()<a.toSeconds()){const t=f.stopIndices.get(m.bestHopOnStop),e=f.stopTimes[m.trip*v+t];u.set(d,{time:o.arrival,legNumber:c,origin:m.origin,leg:{from:this.stopsIndex.findStopById(m.bestHopOnStop),to:this.stopsIndex.findStopById(d),departureTime:e.departure,arrivalTime:o.arrival,route:this.timetable.getServiceRoute(f.serviceRouteId)}}),p.set(d,{time:o.arrival,legNumber:c,origin:m.origin}),T.add(d)}}const g=null===(o=l.get(d))||void 0===o?void 0:o.time;if(void 0!==g&&(void 0===m||g.toSeconds()<=f.stopTimes[m.trip*v+t].departure.toSeconds())){const t=this.timetable.findEarliestTrip(f,d,null==m?void 0:m.trip,g);void 0!==t&&(m={trip:t,bestHopOnStop:d,origin:null!==(a=null===(i=l.get(d))||void 0===i?void 0:i.origin)&&void 0!==a?a:d})}}}if(this.considerTransfers(t,T,u,p,c),0===T.size)break}return new it(t,p,v,this.stopsIndex)}},exports.StopsIndex=Ae,exports.Time=J,exports.Timetable=rt;
|
|
1
|
+
"use strict";class t{constructor(t){this.totalSeconds=t}static fromSeconds(e){return new t(e)}static fromMinutes(e){return new t(60*e)}static zero(){return new t(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),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(e){const n=this.totalSeconds+e.toSeconds();return new t(n)}subtract(e){const n=Math.max(0,this.totalSeconds-e.toSeconds());return new t(n)}}function e(){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 n(t,e,n){for(let r=0;r<28;r+=7){const s=t>>>r,o=!(s>>>7==0&&0==e),i=255&(o?128|s:s);if(n.push(i),!o)return}const r=t>>>28&15|(7&e)<<4,s=!!(e>>3);if(n.push(255&(s?128|r:r)),s){for(let t=3;t<31;t+=7){const r=e>>>t,s=!(r>>>7==0),o=255&(s?128|r:r);if(n.push(o),!s)return}n.push(e>>>31&1)}}const r=4294967296;function s(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let s=0,o=0;function c(e,i){const a=Number(t.slice(e,i));o*=n,s=s*n+a,s>=r&&(o+=s/r|0,s%=r)}return c(-24,-18),c(-18,-12),c(-12,-6),c(-6),e?a(s,o):i(s,o)}function o(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(r*e+t);const n=16777215&(t>>>24|e<<8),s=e>>16&65535;let o=(16777215&t)+6777216*n+6710656*s,i=n+8147497*s,a=2*s;const u=1e7;return o>=u&&(i+=Math.floor(o/u),o%=u),i>=u&&(a+=Math.floor(i/u),i%=u),a.toString()+c(i)+c(o)}function i(t,e){return{lo:0|t,hi:0|e}}function a(t,e){return e=~e,t?t=1+~t:e+=1,i(t,e)}const c=t=>{const e=String(t);return"0000000".slice(e.length)+e};function u(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 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"),s=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>s||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()),h(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),h(t),s(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),p(t),s(t)),dec:(t,e)=>function(t,e){let n=i(t,e);const r=2147483648&n.hi;r&&(n=a(n.lo,n.hi));const s=o(n.lo,n.hi);return r?"-"+s:s}(t,e),uDec:(t,e)=>o(t,e)}}function h(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function p(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const m=Symbol.for("@bufbuild/protobuf/text-encoding");function v(){if(null==globalThis[m]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[m]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[m]}var 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 g=34028234663852886e22,E=-34028234663852886e22;class y{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(_(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return I(t),u(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),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>g||t<E))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){_(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){I(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return I(t),u(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 n(e.lo,e.hi,this.buf),this}sint64(t){let e=d.enc(t),r=e.hi>>31;return n(e.lo<<1^r,(e.hi<<1|e.lo>>>31)^r,this.buf),this}uint64(t){let e=d.uEnc(t);return n(e.lo,e.hi,this.buf),this}}class A{constructor(t,n=v().decodeUtf8){this.decodeUtf8=n,this.varint64=e,this.uint32=l,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.uint32(),e=t>>>3,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 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 I(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 _(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 R,S,N;function O(t){switch(t){case 0:case"NOT_AVAILABLE":return R.NOT_AVAILABLE;case 1:case"MUST_PHONE_AGENCY":return R.MUST_PHONE_AGENCY;case 2:case"MUST_COORDINATE_WITH_DRIVER":return R.MUST_COORDINATE_WITH_DRIVER;default:return R.UNRECOGNIZED}}function w(t){switch(t){case R.NOT_AVAILABLE:return"NOT_AVAILABLE";case R.MUST_PHONE_AGENCY:return"MUST_PHONE_AGENCY";case R.MUST_COORDINATE_WITH_DRIVER:return"MUST_COORDINATE_WITH_DRIVER";case R.UNRECOGNIZED:default:return"UNRECOGNIZED"}}function b(t){switch(t){case 0:case"RECOMMENDED_TRANSFER_POINT":return S.RECOMMENDED_TRANSFER_POINT;case 1:case"TIMED_TRANSFER":return S.TIMED_TRANSFER;case 2:case"REQUIRES_MINIMAL_TIME":return S.REQUIRES_MINIMAL_TIME;case 3:case"IN_SEAT_TRANSFER":return S.IN_SEAT_TRANSFER;default:return S.UNRECOGNIZED}}function k(t){switch(t){case 0:case"TRAM":return N.TRAM;case 1:case"SUBWAY":return N.SUBWAY;case 2:case"RAIL":return N.RAIL;case 3:case"BUS":return N.BUS;case 4:case"FERRY":return N.FERRY;case 5:case"CABLE_TRAM":return N.CABLE_TRAM;case 6:case"AERIAL_LIFT":return N.AERIAL_LIFT;case 7:case"FUNICULAR":return N.FUNICULAR;case 8:case"TROLLEYBUS":return N.TROLLEYBUS;case 9:case"MONORAIL":return N.MONORAIL;default:return N.UNRECOGNIZED}}!function(t){t[t.NOT_AVAILABLE=0]="NOT_AVAILABLE",t[t.MUST_PHONE_AGENCY=1]="MUST_PHONE_AGENCY",t[t.MUST_COORDINATE_WITH_DRIVER=2]="MUST_COORDINATE_WITH_DRIVER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(R||(R={})),function(t){t[t.RECOMMENDED_TRANSFER_POINT=0]="RECOMMENDED_TRANSFER_POINT",t[t.TIMED_TRANSFER=1]="TIMED_TRANSFER",t[t.REQUIRES_MINIMAL_TIME=2]="REQUIRES_MINIMAL_TIME",t[t.IN_SEAT_TRANSFER=3]="IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(S||(S={})),function(t){t[t.TRAM=0]="TRAM",t[t.SUBWAY=1]="SUBWAY",t[t.RAIL=2]="RAIL",t[t.BUS=3]="BUS",t[t.FERRY=4]="FERRY",t[t.CABLE_TRAM=5]="CABLE_TRAM",t[t.AERIAL_LIFT=6]="AERIAL_LIFT",t[t.FUNICULAR=7]="FUNICULAR",t[t.TROLLEYBUS=8]="TROLLEYBUS",t[t.MONORAIL=9]="MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(N||(N={}));const M={encode:(t,e=new y)=>(0!==t.arrival&&e.uint32(8).int32(t.arrival),0!==t.departure&&e.uint32(16).int32(t.departure),void 0!==t.pickUpType&&e.uint32(24).int32(t.pickUpType),void 0!==t.dropOffType&&e.uint32(32).int32(t.dropOffType),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={arrival:0,departure:0,pickUpType:void 0,dropOffType:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.arrival=n.int32();continue;case 2:if(16!==t)break;s.departure=n.int32();continue;case 3:if(24!==t)break;s.pickUpType=n.int32();continue;case 4:if(32!==t)break;s.dropOffType=n.int32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({arrival:V(t.arrival)?globalThis.Number(t.arrival):0,departure:V(t.departure)?globalThis.Number(t.departure):0,pickUpType:V(t.pickUpType)?O(t.pickUpType):void 0,dropOffType:V(t.dropOffType)?O(t.dropOffType):void 0}),toJSON(t){const e={};return 0!==t.arrival&&(e.arrival=Math.round(t.arrival)),0!==t.departure&&(e.departure=Math.round(t.departure)),void 0!==t.pickUpType&&(e.pickUpType=w(t.pickUpType)),void 0!==t.dropOffType&&(e.dropOffType=w(t.dropOffType)),e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s;const o={arrival:0,departure:0,pickUpType:void 0,dropOffType:void 0};return o.arrival=null!==(e=t.arrival)&&void 0!==e?e:0,o.departure=null!==(n=t.departure)&&void 0!==n?n:0,o.pickUpType=null!==(r=t.pickUpType)&&void 0!==r?r:void 0,o.dropOffType=null!==(s=t.dropOffType)&&void 0!==s?s:void 0,o}};const L={encode(t,e=new y){for(const n of t.stopTimes)M.encode(n,e.uint32(10).fork()).join();for(const n of t.stops)e.uint32(18).string(n);return""!==t.serviceRouteId&&e.uint32(26).string(t.serviceRouteId),e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={stopTimes:[],stops:[],serviceRouteId:""};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopTimes.push(M.decode(n,n.uint32()));continue;case 2:if(18!==t)break;s.stops.push(n.string());continue;case 3:if(26!==t)break;s.serviceRouteId=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopTimes:globalThis.Array.isArray(null==t?void 0:t.stopTimes)?t.stopTimes.map((t=>M.fromJSON(t))):[],stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>globalThis.String(t))):[],serviceRouteId:V(t.serviceRouteId)?globalThis.String(t.serviceRouteId):""}),toJSON(t){var e,n;const r={};return(null===(e=t.stopTimes)||void 0===e?void 0:e.length)&&(r.stopTimes=t.stopTimes.map((t=>M.toJSON(t)))),(null===(n=t.stops)||void 0===n?void 0:n.length)&&(r.stops=t.stops),""!==t.serviceRouteId&&(r.serviceRouteId=t.serviceRouteId),r},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={stopTimes:[],stops:[],serviceRouteId:""};return s.stopTimes=(null===(e=t.stopTimes)||void 0===e?void 0:e.map((t=>M.fromPartial(t))))||[],s.stops=(null===(n=t.stops)||void 0===n?void 0:n.map((t=>t)))||[],s.serviceRouteId=null!==(r=t.serviceRouteId)&&void 0!==r?r:"",s}};const U={encode:(t,e=new y)=>(Object.entries(t.routes).forEach((([t,n])=>{x.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={routes:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=x.decode(n,n.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:$(t.routes)?Object.entries(t.routes).reduce(((t,[e,n])=>(t[e]=L.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const n=Object.entries(t.routes);n.length>0&&(e.routes={},n.forEach((([t,n])=>{e.routes[t]=L.toJSON(n)})))}return e},create:t=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={routes:{}};return n.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=L.fromPartial(n)),t)),{}),n}};const x={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&L.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=L.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:V(t.key)?globalThis.String(t.key):"",value:V(t.value)?L.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=L.toJSON(t.value)),e},create:t=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?L.fromPartial(t.value):void 0,n}};const D={encode:(t,e=new y)=>(""!==t.destination&&e.uint32(10).string(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).int32(t.minTransferTime),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={destination:"",type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.destination=n.string();continue;case 2:if(16!==t)break;s.type=n.int32();continue;case 3:if(24!==t)break;s.minTransferTime=n.int32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({destination:V(t.destination)?globalThis.String(t.destination):"",type:V(t.type)?b(t.type):0,minTransferTime:V(t.minTransferTime)?globalThis.Number(t.minTransferTime):void 0}),toJSON(t){const e={};return""!==t.destination&&(e.destination=t.destination),0!==t.type&&(e.type=function(t){switch(t){case S.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED_TRANSFER_POINT";case S.TIMED_TRANSFER:return"TIMED_TRANSFER";case S.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case S.IN_SEAT_TRANSFER:return"IN_SEAT_TRANSFER";case S.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={destination:"",type:0,minTransferTime:void 0};return s.destination=null!==(e=t.destination)&&void 0!==e?e:"",s.type=null!==(n=t.type)&&void 0!==n?n:0,s.minTransferTime=null!==(r=t.minTransferTime)&&void 0!==r?r:void 0,s}};const B={encode:(t,e=new y)=>(Object.entries(t.stops).forEach((([t,n])=>{P.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={stops:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=P.decode(n,n.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stops:$(t.stops)?Object.entries(t.stops).reduce(((t,[e,n])=>(t[e]=C.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.stops){const n=Object.entries(t.stops);n.length>0&&(e.stops={},n.forEach((([t,n])=>{e.stops[t]=C.toJSON(n)})))}return e},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={stops:{}};return n.stops=Object.entries(null!==(e=t.stops)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=C.fromPartial(n)),t)),{}),n}};const C={encode(t,e=new y){for(const n of t.transfers)D.encode(n,e.uint32(10).fork()).join();for(const n of t.routes)e.uint32(18).string(n);return e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={transfers:[],routes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.transfers.push(D.decode(n,n.uint32()));continue;case 2:if(18!==t)break;s.routes.push(n.string());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>D.fromJSON(t))):[],routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.String(t))):[]}),toJSON(t){var e,n;const r={};return(null===(e=t.transfers)||void 0===e?void 0:e.length)&&(r.transfers=t.transfers.map((t=>D.toJSON(t)))),(null===(n=t.routes)||void 0===n?void 0:n.length)&&(r.routes=t.routes),r},create:t=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={transfers:[],routes:[]};return r.transfers=(null===(e=t.transfers)||void 0===e?void 0:e.map((t=>D.fromPartial(t))))||[],r.routes=(null===(n=t.routes)||void 0===n?void 0:n.map((t=>t)))||[],r}};const P={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&C.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=C.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:V(t.key)?globalThis.String(t.key):"",value:V(t.value)?C.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=C.toJSON(t.value)),e},create:t=>P.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?C.fromPartial(t.value):void 0,n}};const F={encode:(t,e=new y)=>(0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={type:0,name:""};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.type=n.int32();continue;case 2:if(18!==t)break;s.name=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({type:V(t.type)?k(t.type):0,name:V(t.name)?globalThis.String(t.name):""}),toJSON(t){const e={};return 0!==t.type&&(e.type=function(t){switch(t){case N.TRAM:return"TRAM";case N.SUBWAY:return"SUBWAY";case N.RAIL:return"RAIL";case N.BUS:return"BUS";case N.FERRY:return"FERRY";case N.CABLE_TRAM:return"CABLE_TRAM";case N.AERIAL_LIFT:return"AERIAL_LIFT";case N.FUNICULAR:return"FUNICULAR";case N.TROLLEYBUS:return"TROLLEYBUS";case N.MONORAIL:return"MONORAIL";case N.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),""!==t.name&&(e.name=t.name),e},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={type:0,name:""};return r.type=null!==(e=t.type)&&void 0!==e?e:0,r.name=null!==(n=t.name)&&void 0!==n?n:"",r}};const j={encode:(t,e=new y)=>(Object.entries(t.routes).forEach((([t,n])=>{z.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={routes:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=z.decode(n,n.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:$(t.routes)?Object.entries(t.routes).reduce(((t,[e,n])=>(t[e]=F.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const n=Object.entries(t.routes);n.length>0&&(e.routes={},n.forEach((([t,n])=>{e.routes[t]=F.toJSON(n)})))}return e},create:t=>j.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={routes:{}};return n.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=F.fromPartial(n)),t)),{}),n}};const z={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&F.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=F.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:V(t.key)?globalThis.String(t.key):"",value:V(t.value)?F.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=F.toJSON(t.value)),e},create:t=>z.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?F.fromPartial(t.value):void 0,n}};const G={encode:(t,e=new y)=>(""!==t.version&&e.uint32(10).string(t.version),void 0!==t.stopsAdjacency&&B.encode(t.stopsAdjacency,e.uint32(18).fork()).join(),void 0!==t.routesAdjacency&&U.encode(t.routesAdjacency,e.uint32(26).fork()).join(),void 0!==t.routes&&j.encode(t.routes,e.uint32(34).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=n.string();continue;case 2:if(18!==t)break;s.stopsAdjacency=B.decode(n,n.uint32());continue;case 3:if(26!==t)break;s.routesAdjacency=U.decode(n,n.uint32());continue;case 4:if(34!==t)break;s.routes=j.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({version:V(t.version)?globalThis.String(t.version):"",stopsAdjacency:V(t.stopsAdjacency)?B.fromJSON(t.stopsAdjacency):void 0,routesAdjacency:V(t.routesAdjacency)?U.fromJSON(t.routesAdjacency):void 0,routes:V(t.routes)?j.fromJSON(t.routes):void 0}),toJSON(t){const e={};return""!==t.version&&(e.version=t.version),void 0!==t.stopsAdjacency&&(e.stopsAdjacency=B.toJSON(t.stopsAdjacency)),void 0!==t.routesAdjacency&&(e.routesAdjacency=U.toJSON(t.routesAdjacency)),void 0!==t.routes&&(e.routes=j.toJSON(t.routes)),e},create:t=>G.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};return n.version=null!==(e=t.version)&&void 0!==e?e:"",n.stopsAdjacency=void 0!==t.stopsAdjacency&&null!==t.stopsAdjacency?B.fromPartial(t.stopsAdjacency):void 0,n.routesAdjacency=void 0!==t.routesAdjacency&&null!==t.routesAdjacency?U.fromPartial(t.routesAdjacency):void 0,n.routes=void 0!==t.routes&&null!==t.routes?j.fromPartial(t.routes):void 0,n}};function $(t){return"object"==typeof t&&null!==t}function V(t){return null!=t}class J{static infinity(){return new J(Number.MAX_SAFE_INTEGER)}static origin(){return new J(0)}constructor(t){this.secondsSinceMidnight=t}static fromSeconds(t){return new J(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.");return new J(n+60*e+3600*t)}static fromDate(t){const e=t.getHours(),n=t.getMinutes(),r=t.getSeconds();return new J(r+60*n+3600*e)}static fromString(t){const[e,n,r]=t.split(":");if(void 0===e||void 0===n||isNaN(Number(e))||isNaN(Number(n))||void 0!==r&&isNaN(Number(r)))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const s=parseInt(e,10),o=parseInt(n,10),i=void 0!==r?parseInt(r,10):0;return new J(i+60*o+3600*s)}toString(){const t=Math.floor(this.secondsSinceMidnight/3600),e=Math.floor(this.secondsSinceMidnight%3600/60),n=this.secondsSinceMidnight%60;return`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}toSeconds(){return this.secondsSinceMidnight}plus(t){const e=this.secondsSinceMidnight+t.toSeconds();return new J(e)}minus(t){let e=this.secondsSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new J(e)}diff(e){const n=this.secondsSinceMidnight-e.toSeconds();return t.fromSeconds(Math.abs(n))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.toSeconds()>t.toSeconds()?e:t))}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.toSeconds()<t.toSeconds()?e:t))}}const Y=t=>{const e={stops:{}};return t.forEach(((t,n)=>{e.stops[n]={transfers:t.transfers.map((t=>Object.assign({destination:t.destination,type:q(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))),routes:t.routes}})),e},W=t=>{const e={routes:{}};return t.forEach(((t,n)=>{e.routes[n]={stopTimes:t.stopTimes.map((t=>({arrival:t.arrival.toSeconds(),departure:t.departure.toSeconds(),pickUpType:tt(t.pickUpType),dropOffType:tt(t.dropOffType)}))),stops:t.stops,serviceRouteId:t.serviceRouteId}})),e},H=t=>{const e={routes:{}};return t.forEach(((t,n)=>{e.routes[n]={type:X(t.type),name:t.name}})),e},Z=t=>{switch(t){case S.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case S.TIMED_TRANSFER:return"GUARANTEED";case S.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case S.IN_SEAT_TRANSFER:return"IN_SEAT";case S.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},q=t=>{switch(t){case"RECOMMENDED":return S.RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return S.TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return S.REQUIRES_MINIMAL_TIME;case"IN_SEAT":return S.IN_SEAT_TRANSFER}},Q=t=>{switch(t){case N.TRAM:return"TRAM";case N.SUBWAY:return"SUBWAY";case N.RAIL:return"RAIL";case N.BUS:return"BUS";case N.FERRY:return"FERRY";case N.CABLE_TRAM:return"CABLE_TRAM";case N.AERIAL_LIFT:return"AERIAL_LIFT";case N.FUNICULAR:return"FUNICULAR";case N.TROLLEYBUS:return"TROLLEYBUS";case N.MONORAIL:return"MONORAIL";case N.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},X=t=>{switch(t){case"TRAM":return N.TRAM;case"SUBWAY":return N.SUBWAY;case"RAIL":return N.RAIL;case"BUS":return N.BUS;case"FERRY":return N.FERRY;case"CABLE_TRAM":return N.CABLE_TRAM;case"AERIAL_LIFT":return N.AERIAL_LIFT;case"FUNICULAR":return N.FUNICULAR;case"TROLLEYBUS":return N.TROLLEYBUS;case"MONORAIL":return N.MONORAIL}},K=t=>{switch(t){case R.MUST_PHONE_AGENCY:return"MUST_PHONE_AGENCY";case R.MUST_COORDINATE_WITH_DRIVER:return"MUST_COORDINATE_WITH_DRIVER";case R.NOT_AVAILABLE:return"NOT_AVAILABLE";default:return"REGULAR"}},tt=t=>{switch(t){case"REGULAR":return;case"NOT_AVAILABLE":return R.NOT_AVAILABLE;case"MUST_COORDINATE_WITH_DRIVER":return R.MUST_COORDINATE_WITH_DRIVER;case"MUST_PHONE_AGENCY":return R.MUST_PHONE_AGENCY}},et=["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"],nt="0.0.1";class rt{constructor(t,e,n){this.stopsAdjacency=t,this.routesAdjacency=e,this.routes=n}serialize(){const t={version:nt,stopsAdjacency:Y(this.stopsAdjacency),routesAdjacency:W(this.routesAdjacency),routes:H(this.routes)},e=new y;return G.encode(t,e),e.finish()}static fromData(e){const n=new A(e),r=G.decode(n);if(r.version!==nt)throw new Error(`Unsupported timetable version ${r.version}`);return new rt((e=>{const n=new Map;return Object.entries(e.stops).forEach((([e,r])=>{n.set(e,{transfers:r.transfers.map((e=>Object.assign({destination:e.destination,type:Z(e.type)},void 0!==e.minTransferTime&&{minTransferTime:t.fromSeconds(e.minTransferTime)}))),routes:r.routes})})),n})(r.stopsAdjacency),(t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,n])=>{e.set(t,{stopTimes:n.stopTimes.map((t=>({arrival:J.fromSeconds(t.arrival),departure:J.fromSeconds(t.departure),pickUpType:void 0!==t.pickUpType?K(t.pickUpType):"REGULAR",dropOffType:void 0!==t.dropOffType?K(t.dropOffType):"REGULAR"}))),stops:n.stops,stopIndices:new Map(n.stops.map(((t,e)=>[t,e]))),serviceRouteId:n.serviceRouteId})})),e})(r.routesAdjacency),(t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,n])=>{e.set(t,{type:Q(n.type),name:n.name})})),e})(r.routes))}getRoute(t){return this.routesAdjacency.get(t)}getTransfers(t){var e,n;return null!==(n=null===(e=this.stopsAdjacency.get(t))||void 0===e?void 0:e.transfers)&&void 0!==n?n:[]}findReachableRoutes(t,e=et){var n;const r=new Map;for(const s of t){const t=null===(n=this.stopsAdjacency.get(s))||void 0===n?void 0:n.routes.filter((t=>{const n=this.getServiceRouteFromRouteId(t);return!!n&&e.includes(n.type)}));for(const e of t||[]){const t=r.get(e);if(t){const n=this.routesAdjacency.get(e).stopIndices;n.get(s)<n.get(t)&&r.set(e,s)}else r.set(e,s)}}return r}getServiceRouteFromRouteId(t){const e=this.routesAdjacency.get(t);if(e)return this.routes.get(e.serviceRouteId);console.warn(`Route ${t} not found.`)}getServiceRoute(t){return this.routes.get(t)}findEarliestTrip(t,e,n,r=J.origin()){const s=t.stopIndices.get(e),o=t.stops.length;if(void 0!==n){let e,i;for(let a=n;a>=0;a--){const n=a*o+s,c=t.stopTimes[n];if(c.departure<=r)break;"NOT_AVAILABLE"!==c.pickUpType&&(void 0===i||c.departure<i)&&(e=a,i=c.departure)}return e}for(let e=0;e<t.stopTimes.length/o;e++){const n=e*o+s,i=t.stopTimes[n];if(i.departure>r&&"NOT_AVAILABLE"!==i.pickUpType)return e}}}class st{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}st.Builder=class{constructor(){this.optionsValue={maxTransfers:5,minTransferTime:t.fromSeconds(120),transportModes:et}}from(t){return this.fromValue=t,this}to(t){return this.toValue=Array.isArray(t)?t:[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 st(this)}};class ot{constructor(t){this.legs=t}departureTime(){const e=t.zero();for(let t=0;t<this.legs.length;t++){const n=this.legs[t];if("departureTime"in n)return n.departureTime.minus(e);"minTransferTime"in n&&n.minTransferTime&&e.add(n.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let e=J.origin();const n=t.zero();let r=!1;for(let t=this.legs.length-1;t>=0;t--){const s=this.legs[t];"arrivalTime"in s&&!r?(e=s.arrivalTime,r=!0):"minTransferTime"in s&&s.minTransferTime&&r&&n.add(s.minTransferTime)}if(!r)throw new Error("No vehicle leg found in route");return e.plus(n)}totalDuration(){return 0===this.legs.length?t.zero():this.arrivalTime().diff(this.departureTime())}print(){return this.legs.map(((t,e)=>{var n,r;return"route"in t?`Leg ${e+1}: ${t.from.name} to ${t.to.name}\n via route ${t.route.type} ${t.route.name},\n departs at ${t.departureTime.toString()}, arrives at ${t.arrivalTime.toString()}`:`Leg ${e+1}: Transfer from ${t.from.name} to ${t.to.name},\n minimum transfer time: ${null!==(r=null===(n=t.minTransferTime)||void 0===n?void 0:n.toString())&&void 0!==r?r:"not specified"}`})).join("\n")}}class it{constructor(t,e,n,r){this.query=t,this.earliestArrivals=e,this.earliestArrivalsPerRound=n,this.stopsIndex=r}bestRoute(t){var e,n,r;const s=(Array.isArray(t)?t:t?[t]:this.query.to).flatMap((t=>this.stopsIndex.equivalentStops(t)));let o,i;for(const t of s){const e=this.earliestArrivals.get(t);void 0!==e&&(void 0===i||e.time.toSeconds()<i.time.toSeconds())&&(o=t,i=e)}if(!o||!i)return;const a=[];let c=o,u=i.legNumber;for(;i.origin!==c;){const t=null===(e=this.earliestArrivalsPerRound[u])||void 0===e?void 0:e.get(c);if(!(null==t?void 0:t.leg))throw new Error(`No leg found for a trip leg: start stop=${null!==(r=null===(n=null==t?void 0:t.leg)||void 0===n?void 0:n.from.id)&&void 0!==r?r:"unknown"}, end stop=${c}, round=${u}, origin=${i.origin}`);a.unshift(t.leg),c=t.leg.from.id,"route"in t.leg&&(u-=1)}return new ot(a)}arrivalAt(t,e){const n=this.stopsIndex.equivalentStops(t);let r;const s=void 0!==e?this.earliestArrivalsPerRound[e-1]:this.earliestArrivals;for(const t of n){const e=s.get(t);void 0!==e&&(void 0===r||e.time.toSeconds()<r.time.toSeconds())&&(r=e)}return r}}const at=J.infinity();class ct{constructor(t=[],e=ut){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 s=t-1>>1,o=e[s];if(n(r,o)>=0)break;e[t]=o,t=s}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,s=e[t];for(;t<r;){let r=1+(t<<1),o=e[r];const i=r+1;if(i<this.length&&n(e[i],o)<0&&(r=i,o=e[i]),n(o,s)>=0)break;e[t]=o,t=r}e[t]=s}}function ut(t,e){return t<e?-1:t>e?1:0}const lt=Math.PI/180;function dt(t,e,n,r){const s=r.minLng,o=r.maxLng,i=r.minLat,a=r.maxLat;if(t>=s&&t<=o)return e<i?ht((e-i)*lt):e>a?ht((e-a)*lt):0;const c=Math.min(ht((t-s)*lt),ht((t-o)*lt)),u=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*lt)/n)/lt}(e,c);return u>i&&u<a?pt(c,n,e,u):Math.min(pt(c,n,e,i),pt(c,n,e,a))}function ft(t,e){return t.dist-e.dist}function ht(t){const e=Math.sin(t/2);return e*e}function pt(t,e,n,r){return e*Math.cos(r*lt)*t+ht((n-r)*lt)}function mt(t,e,n,r,s){return pt(ht((t-n)*lt),s,e,r)}const vt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class Tt{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 s=vt[15&n];if(!s)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[i]=new Uint32Array(t,4,1);return new Tt(i,o,s,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 s=vt.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,i=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-i%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${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+i+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+i+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+i+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const 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 gt(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:s,coords:o,nodeSize:i}=this,a=[0,s.length-1,0],c=[];for(;a.length;){const u=a.pop()||0,l=a.pop()||0,d=a.pop()||0;if(l-d<=i){for(let i=d;i<=l;i++){const a=o[2*i],u=o[2*i+1];a>=t&&a<=n&&u>=e&&u<=r&&c.push(s[i])}continue}const f=d+l>>1,h=o[2*f],p=o[2*f+1];h>=t&&h<=n&&p>=e&&p<=r&&c.push(s[f]),(0===u?t<=h:e<=p)&&(a.push(d),a.push(f-1),a.push(1-u)),(0===u?n>=h:r>=p)&&(a.push(f+1),a.push(l),a.push(1-u))}return c}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:s,nodeSize:o}=this,i=[0,r.length-1,0],a=[],c=n*n;for(;i.length;){const u=i.pop()||0,l=i.pop()||0,d=i.pop()||0;if(l-d<=o){for(let n=d;n<=l;n++)It(s[2*n],s[2*n+1],t,e)<=c&&a.push(r[n]);continue}const f=d+l>>1,h=s[2*f],p=s[2*f+1];It(h,p,t,e)<=c&&a.push(r[f]),(0===u?t-n<=h:e-n<=p)&&(i.push(d),i.push(f-1),i.push(1-u)),(0===u?t+n>=h:e+n>=p)&&(i.push(f+1),i.push(l),i.push(1-u))}return a}}function gt(t,e,n,r,s,o){if(s-r<=n)return;const i=r+s>>1;Et(t,e,i,r,s,o),gt(t,e,n,r,i-1,1-o),gt(t,e,n,i+1,s,1-o)}function Et(t,e,n,r,s,o){for(;s>r;){if(s-r>600){const i=s-r+1,a=n-r+1,c=Math.log(i),u=.5*Math.exp(2*c/3),l=.5*Math.sqrt(c*u*(i-u)/i)*(a-i/2<0?-1:1);Et(t,e,n,Math.max(r,Math.floor(n-a*u/i+l)),Math.min(s,Math.floor(n+(i-a)*u/i+l)),o)}const i=e[2*n+o];let a=r,c=s;for(yt(t,e,r,n),e[2*s+o]>i&&yt(t,e,r,s);a<c;){for(yt(t,e,a,c),a++,c--;e[2*a+o]<i;)a++;for(;e[2*c+o]>i;)c--}e[2*r+o]===i?yt(t,e,r,c):(c++,yt(t,e,c,s)),c<=n&&(r=c+1),n<=c&&(s=c-1)}}function yt(t,e,n,r){At(t,n,r),At(e,2*n,2*r),At(e,2*n+1,2*r+1)}function At(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function It(t,e,n,r){const s=t-n,o=e-r;return s*s+o*o}const _t="KEYS",Rt="VALUES",St="";class Nt{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}=Ot(this._path);if(Ot(e)===St)return{done:!1,value:this.result()};const n=t.get(Ot(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Ot(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Ot(t))).filter((t=>t!==St)).join("")}value(){return Ot(this._path).node.get(St)}result(){switch(this._type){case Rt:return this.value();case _t:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Ot=t=>t[t.length-1],wt=(t,e,n,r,s,o,i,a)=>{const c=o*i;t:for(const u of t.keys())if(u===St){const e=s[c-1];e<=n&&r.set(a,[t.get(u),e])}else{let c=o;for(let t=0;t<u.length;++t,++c){const r=u[t],o=i*c,a=o-i;let l=s[o];const d=Math.max(0,c-n-1),f=Math.min(i-1,c+n);for(let t=d;t<f;++t){const n=r!==e[t],i=s[a+t]+ +n,c=s[a+t+1]+1,u=s[o+t]+1,d=s[o+t+1]=Math.min(i,c,u);d<l&&(l=d)}if(l>n)continue t}wt(t.get(u),e,n,r,s,c,i,a+u)}};class bt{_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]=kt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=Bt(n);for(const n of e.keys())if(n!==St&&n.startsWith(r)){const s=new Map;return s.set(n.slice(r.length),e.get(n)),new bt(s,t)}}return new bt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Ut(this._tree,t)}entries(){return new Nt(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 s=e.length+1,o=s+n,i=new Uint8Array(o*s).fill(n+1);for(let t=0;t<s;++t)i[t]=t;for(let t=1;t<o;++t)i[t*s]=t;return wt(t,e,n,r,i,1,s,""),r})(this._tree,t,e)}get(t){const e=Mt(this._tree,t);return void 0!==e?e.get(St):void 0}has(t){return Mt(this._tree,t)?.has(St)??!1}keys(){return new Nt(this,_t)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Lt(this._tree,t).set(St,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=Lt(this._tree,t);return n.set(St,e(n.get(St))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Lt(this._tree,t);let r=n.get(St);return void 0===r&&n.set(St,r=e()),r}values(){return new Nt(this,Rt)}[Symbol.iterator](){return this.entries()}static from(t){const e=new bt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return bt.from(Object.entries(t))}}const kt=(t,e,n=[])=>{if(0===e.length||null==t)return[t,n];for(const r of t.keys())if(r!==St&&e.startsWith(r))return n.push([t,r]),kt(t.get(r),e.slice(r.length),n);return n.push([t,e]),kt(void 0,"",n)},Mt=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(n!==St&&e.startsWith(n))return Mt(t.get(n),e.slice(n.length))},Lt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const s of t.keys())if(s!==St&&e[r]===s[0]){const o=Math.min(n-r,s.length);let i=1;for(;i<o&&e[r+i]===s[i];)++i;const a=t.get(s);if(i===s.length)t=a;else{const n=new Map;n.set(s.slice(i),a),t.set(e.slice(r,r+i),n),t.delete(s),t=n}r+=i;continue t}const s=new Map;return t.set(e.slice(r),s),s}return t},Ut=(t,e)=>{const[n,r]=kt(t,e);if(void 0!==n)if(n.delete(St),0===n.size)xt(r);else if(1===n.size){const[t,e]=n.entries().next().value;Dt(r,t,e)}},xt=t=>{if(0===t.length)return;const[e,n]=Bt(t);if(e.delete(n),0===e.size)xt(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;n!==St&&Dt(t.slice(0,-1),n,r)}},Dt=(t,e,n)=>{if(0===t.length)return;const[r,s]=Bt(t);r.set(s+e,n),r.delete(s)},Bt=t=>t[t.length-1],Ct=/[\n\r\p{Z}\p{P}]+/u,Pt="or",Ft="and",jt="and_not",zt=(t,e)=>{t.includes(e)||t.push(e)},Gt=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},$t=({score:t},{score:e})=>e-t,Vt=()=>new Map,Jt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Yt={[Pt]:(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:s,match:o}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,o),Gt(r.terms,s)}}return t},[Ft]:(t,e)=>{const n=new Map;for(const r of e.keys()){const s=t.get(r);if(null==s)continue;const{score:o,terms:i,match:a}=e.get(r);Gt(s.terms,i),n.set(r,{score:s.score+o,terms:s.terms,match:Object.assign(s.match,a)})}return n},[jt]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},Wt=(t,e,n,r,s,o)=>{const{k:i,b:a,d:c}=o;return Math.log(1+(n-e+.5)/(e+.5))*(c+t*(i+1)/(t+i*(1-a+a*r/s)))},Ht=(t,e,n,r)=>{for(const s of Object.keys(t._fieldIds))if(t._fieldIds[s]===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 "${s}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},Zt=(t,e,n,r)=>{const s=t._index.fetch(r,Vt);let o=s.get(e);if(null==o)o=new Map,o.set(n,1),s.set(e,o);else{const t=o.get(n);o.set(n,(t??0)+1)}},qt=(t,e,n,r)=>{if(!t._index.has(r))return void Ht(t,n,e,r);const s=t._index.fetch(r,Vt),o=s.get(e),i=o?.get(n);!o||typeof i>"u"?Ht(t,n,e,r):i<=1?o.size<=1?s.delete(e):o.delete(n):o.set(n,i-1),0===t._index.get(r).size&&t._index.delete(r)},Qt=(t,e,n,r,s)=>{let o=t._fieldLength.get(e);null==o&&t._fieldLength.set(e,o=[]),o[n]=s;const i=(t._avgFieldLength[n]||0)*r+s;t._avgFieldLength[n]=i/(r+1)},Xt=(t,e)=>{const{extractField:n,tokenize:r,processTerm:s,fields:o,idField:i}=t._options,a=n(e,i);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${i}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const c=((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:s}=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=s(n,t);null!=e&&(o[t]=e)}})(t,c,e);for(const i of o){const o=n(e,i);if(null==o)continue;const a=r(o.toString(),i),u=t._fieldIds[i],l=new Set(a).size;Qt(t,c,u,t._documentCount-1,l);for(const e of a){const n=s(e,i);if(Array.isArray(n))for(const e of n)Zt(t,u,c,e);else n&&Zt(t,u,c,n)}}},Kt={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split(Ct),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},te={combineWith:Pt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},ee={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},ne={minDirtFactor:.1,minDirtCount:20},re={batchSize:1e3,batchWait:10,...ne},se=Symbol("*"),oe=(t,e=Pt)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in Yt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Yt[n])},ie=(t,e,n,r,s,o,i,a,c,u=new Map)=>{if(null==o)return u;for(const l of Object.keys(i)){const d=i[l],f=t._fieldIds[l],h=o.get(f);if(null==h)continue;let p=h.size;const m=t._avgFieldLength[f];for(const o of h.keys()){if(!t._documentIds.has(o)){qt(t,f,o,n),p-=1;continue}const i=a?a(t._documentIds.get(o),n,t._storedFields.get(o)):1;if(!i)continue;const v=h.get(o),T=t._fieldLength.get(o)[f],g=r*s*d*i*Wt(v,p,t._documentCount,T,m,c),E=u.get(o);if(E){E.score+=g,zt(E.terms,e);const t=Jt(E.match,n);t?t.push(l):E.match[n]=[l]}else u.set(o,{score:g,terms:[e],match:{[n]:[l]}})}}return u},ae=(t,e,n={})=>{if(e===se)return((t,e)=>{const n=new Map,r={...t._options.searchOptions,...e};for(const[e,s]of t._documentIds){const o=r.boostDocument?r.boostDocument(s,"",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},s=e.queries.map((e=>ae(t,e,r)));return oe(s,r.combineWith)}const{tokenize:r,processTerm:s,searchOptions:o}=t._options,i={tokenize:r,processTerm:s,...o,...n},{tokenize:a,processTerm:c}=i,u=a(e).flatMap((t=>c(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}))(i)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},s=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:Jt(r.boost,e)||1})),{}),{boostDocument:o,weights:i,maxFuzzy:a,bm25:c}=r,{fuzzy:u,prefix:l}={...te.weights,...i},d=t._index.get(e.term),f=ie(t,e.term,e.term,1,e.termBoost,d,s,o,c);let h,p;if(e.prefix&&(h=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(h)for(const[n,r]of h){const i=n.length-e.term.length;if(!i)continue;p?.delete(n);const a=l*n.length/(n.length+.3*i);ie(t,e.term,n,a,e.termBoost,r,s,o,c,f)}if(p)for(const n of p.keys()){const[r,i]=p.get(n);if(!i)continue;const a=u*n.length/(n.length+i);ie(t,e.term,n,a,e.termBoost,r,s,o,c,f)}return f})(t,e,i)));return oe(u,i.combineWith)};class ce{_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?re:t.autoVacuum;this._options={...Kt,...t,autoVacuum:e,searchOptions:{...te,...t.searchOptions},autoSuggestOptions:{...ee,...t.autoSuggestOptions}},this._index=new bt,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=ne,this.addFields(this._options.fields)}get isVacuuming(){return null!=this._currentVacuum}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}get documentCount(){return this._documentCount}get termCount(){return this._index.size}toJSON(){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 ue=t=>{const e=t.toLowerCase(),n=new Set([e]),r={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,s]of Object.entries(r))e.includes(t)&&s.forEach((r=>{n.add(e.replace(t,r))})),s.forEach((r=>{e.includes(r)&&n.add(e.replace(r,t))}));return Array.from(n)};var le;function de(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return le.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return le.STATION;case 2:case"ENTRANCE_EXIT":return le.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return le.GENERIC_NODE;case 4:case"BOARDING_AREA":return le.BOARDING_AREA;default:return le.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"}(le||(le={}));const fe={encode(t,e=new y){""!==t.name&&e.uint32(10).string(t.name),void 0!==t.lat&&e.uint32(17).double(t.lat),void 0!==t.lon&&e.uint32(25).double(t.lon);for(const n of t.children)e.uint32(34).string(n);return void 0!==t.parent&&e.uint32(42).string(t.parent),0!==t.locationType&&e.uint32(48).int32(t.locationType),void 0!==t.platform&&e.uint32(58).string(t.platform),e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={name:"",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;s.name=n.string();continue;case 2:if(17!==t)break;s.lat=n.double();continue;case 3:if(25!==t)break;s.lon=n.double();continue;case 4:if(34!==t)break;s.children.push(n.string());continue;case 5:if(42!==t)break;s.parent=n.string();continue;case 6:if(48!==t)break;s.locationType=n.int32();continue;case 7:if(58!==t)break;s.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({name:me(t.name)?globalThis.String(t.name):"",lat:me(t.lat)?globalThis.Number(t.lat):void 0,lon:me(t.lon)?globalThis.Number(t.lon):void 0,children:globalThis.Array.isArray(null==t?void 0:t.children)?t.children.map((t=>globalThis.String(t))):[],parent:me(t.parent)?globalThis.String(t.parent):void 0,locationType:me(t.locationType)?de(t.locationType):0,platform:me(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const n={};return""!==t.name&&(n.name=t.name),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),void 0!==t.parent&&(n.parent=t.parent),0!==t.locationType&&(n.locationType=function(t){switch(t){case le.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case le.STATION:return"STATION";case le.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case le.GENERIC_NODE:return"GENERIC_NODE";case le.BOARDING_AREA:return"BOARDING_AREA";case le.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>fe.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s,o,i,a;const c={name:"",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.lat=null!==(n=t.lat)&&void 0!==n?n:void 0,c.lon=null!==(r=t.lon)&&void 0!==r?r:void 0,c.children=(null===(s=t.children)||void 0===s?void 0:s.map((t=>t)))||[],c.parent=null!==(o=t.parent)&&void 0!==o?o:void 0,c.locationType=null!==(i=t.locationType)&&void 0!==i?i:0,c.platform=null!==(a=t.platform)&&void 0!==a?a:void 0,c}};const he={encode:(t,e=new y)=>(""!==t.version&&e.uint32(10).string(t.version),Object.entries(t.stops).forEach((([t,n])=>{pe.encode({key:t,value:n},e.uint32(18).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={version:"",stops:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=n.string();continue;case 2:{if(18!==t)break;const e=pe.decode(n,n.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON(t){return{version:me(t.version)?globalThis.String(t.version):"",stops:(e=t.stops,"object"==typeof e&&null!==e?Object.entries(t.stops).reduce(((t,[e,n])=>(t[e]=fe.fromJSON(n),t)),{}):{})};var e},toJSON(t){const e={};if(""!==t.version&&(e.version=t.version),t.stops){const n=Object.entries(t.stops);n.length>0&&(e.stops={},n.forEach((([t,n])=>{e.stops[t]=fe.toJSON(n)})))}return e},create:t=>he.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=Object.entries(null!==(n=t.stops)&&void 0!==n?n:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=fe.fromPartial(n)),t)),{}),r}};const pe={encode:(t,e=new y)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&fe.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=fe.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:me(t.key)?globalThis.String(t.key):"",value:me(t.value)?fe.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=fe.toJSON(t.value)),e},create:t=>pe.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?fe.fromPartial(t.value):void 0,n}};function me(t){return null!=t}const ve="0.0.1",Te=t=>{const e={version:ve,stops:{}};return t.forEach(((t,n)=>{var r;e.stops[n]={name:(r=t).name,lat:r.lat,lon:r.lon,children:r.children,parent:r.parent,locationType:ye(r.locationType),platform:r.platform}})),e},ge=t=>{if(t.version!==ve)throw new Error(`Unsupported stopMap version ${t.version}`);const e=new Map;return Object.entries(t.stops).forEach((([t,n])=>{var r;e.set(t,{id:t,name:(r=n).name,lat:r.lat,lon:r.lon,children:r.children,parent:r.parent,locationType:Ee(r.locationType),platform:r.platform})})),e},Ee=t=>{switch(t){case le.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case le.STATION:return"STATION";case le.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case le.GENERIC_NODE:return"GENERIC_NODE";case le.BOARDING_AREA:return"BOARDING_AREA";case le.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},ye=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return le.SIMPLE_STOP_OR_PLATFORM;case"STATION":return le.STATION;case"ENTRANCE_EXIT":return le.ENTRANCE_EXIT;case"GENERIC_NODE":return le.GENERIC_NODE;case"BOARDING_AREA":return le.BOARDING_AREA}};class Ae{constructor(t){var e;this.stopsMap=t,this.textIndex=new ce({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:ue});const n=new Map;for(const[r,s]of t.entries()){const t=null!==(e=s.parent)&&void 0!==e?e:r;n.has(t)||n.set(t,{id:t,name:s.parent?this.stopsMap.get(s.parent).name:s.name})}const r=Array.from(n.values());((t,e)=>{for(const n of e)Xt(t,n)})(this.textIndex,r),this.stopPoints=Array.from(this.stopsMap.entries()).filter((([,t])=>!(!t.lat||!t.lon))).map((([t,e])=>({id:t,lat:e.lat,lon:e.lon}))),this.geoIndex=new Tt(this.stopPoints.length);for(const{lat:t,lon:e}of this.stopPoints)this.geoIndex.add(e,t);this.geoIndex.finish()}static fromData(t){const e=new A(t),n=he.decode(e);return new Ae(ge(n))}serialize(){const t=Te(this.stopsMap),e=new y;return he.encode(t,e),e.finish()}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,s={...r,...n},o=ae(t,e,n),i=[];for(const[e,{score:n,terms:r,match:a}]of o){const o=r.length||1,c={id:t._documentIds.get(e),score:n*o,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(c,t._storedFields.get(e)),(null==s.filter||s.filter(c))&&i.push(c)}return e===se&&null==s.boostDocument||i.sort($t),i})(this.textIndex,t).map((t=>this.stopsMap.get(t.id))).slice(0,e)}findStopsByLocation(t,e,n=5,r=.5){const s=function(t,e,n,r=1/0,s=1/0){let o=1;const i=[];void 0===r&&(r=1/0),void 0!==s&&(o=ht(s/6371));const a=new ct([],ft);let c={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const u=Math.cos(n*lt);for(;c;){const s=c.right,l=c.left;if(s-l<=t.nodeSize)for(let r=l;r<=s;r++){const s=t.ids[r];{const o=mt(e,n,t.coords[2*r],t.coords[2*r+1],u);a.push({id:s,dist:o})}}else{const r=l+s>>1,o=t.coords[2*r],i=t.coords[2*r+1],d=t.ids[r];{const t=mt(e,n,o,i,u);a.push({id:d,dist:t})}const f=(c.axis+1)%2,h={left:l,right:r-1,axis:f,minLng:c.minLng,minLat:c.minLat,maxLng:0===c.axis?o:c.maxLng,maxLat:1===c.axis?i:c.maxLat,dist:0},p={left:r+1,right:s,axis:f,minLng:0===c.axis?o:c.minLng,minLat:1===c.axis?i:c.minLat,maxLng:c.maxLng,maxLat:c.maxLat,dist:0};h.dist=dt(e,n,u,h),p.dist=dt(e,n,u,p),a.push(h),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>o)return i;if(i.push(t.id),i.length===r)return i}c=a.pop()}return i}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stopsMap.get(e.id)}));return s}findStopById(t){return this.stopsMap.get(t)}equivalentStops(t){var e,n;const r=this.stopsMap.get(t);if(!r)return[];const s=r.parent?null!==(n=null===(e=this.stopsMap.get(r.parent))||void 0===e?void 0:e.children)&&void 0!==n?n:[]:r.children;return Array.from(new Set([t,...s]))}}exports.Duration=t,exports.Plotter=class{constructor(t){this.result=t}plotDotGraph(){const t=this.result.earliestArrivalsPerRound,e=["digraph PathTree {"," graph [overlap=false];"," node [shape=ellipse style=filled fillcolor=lightgrey];"];return t.forEach(((t,n)=>{t.forEach((t=>{const{origin:r,leg:s}=t;if(!s)return;const o=this.result.stopsIndex.findStopById(s.from.id),i=this.result.stopsIndex.findStopById(s.to.id),a=this.result.stopsIndex.findStopById(r);if(o&&i&&a){const t=o.platform?`${o.name} (Pl. ${o.platform})`:o.name,r=i.platform?`${i.name} (Pl. ${i.platform})`:i.name,c=a.platform?`${a.name} (Pl. ${a.platform})`:a.name,u="route"in s,l=u?`${s.route.name}\n${s.departureTime.toString()} - ${s.arrivalTime.toString()}`:s.minTransferTime?s.minTransferTime.toString():"",d=`IntermediateNode${o.id}_${i.id}`,f=u?"":', color="red", fontcolor="red"',h=u?"":' fontcolor="red"';e.push(` "${t} (Origin: ${c}) [R${n}]\n(${o.id})" -> "${d}" [shape=point${f}];`),e.push(` "${d}" [label="${l}" shape=rect style=filled fillcolor=white${h} border=0];`),e.push(` "${d}" -> "${r} (Origin: ${c}) [R${n}]\n(${i.id})" [${f.replace(", ","")}];`)}}))})),e.push("}"),e.join("\n")}},exports.Query=st,exports.Result=it,exports.Route=ot,exports.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}considerTransfers(e,n,r,s,o){var i,a,c,u;const{options:l}=e,d=new Set;for(const e of n)for(const n of this.timetable.getTransfers(e)){let f;f=n.minTransferTime?n.minTransferTime:"IN_SEAT"===n.type?t.zero():l.minTransferTime;const h=r.get(e).time.plus(f),p=null!==(a=null===(i=r.get(n.destination))||void 0===i?void 0:i.time)&&void 0!==a?a:at;if(h.toSeconds()<p.toSeconds()){const t=null!==(u=null===(c=r.get(e))||void 0===c?void 0:c.origin)&&void 0!==u?u:e;r.set(n.destination,{time:h,legNumber:o,origin:t,leg:{from:this.stopsIndex.findStopById(e),to:this.stopsIndex.findStopById(n.destination),minTransferTime:n.minTransferTime,type:n.type}}),s.set(n.destination,{time:h,legNumber:o,origin:t}),d.add(n.destination)}}for(const t of d)n.add(t)}route(t){var e,n,r,s,o,i,a;const{from:c,to:u,departureTime:l,options:d}=t,f=this.stopsIndex.equivalentStops(c),h=u.flatMap((t=>this.stopsIndex.equivalentStops(t))),p=new Map,m=new Map,v=[m],T=new Set;for(const t of f)T.add(t),p.set(t,{time:l,legNumber:0,origin:t}),m.set(t,{time:l,legNumber:0,origin:t});this.considerTransfers(t,T,m,p,0);for(let c=1;c<=d.maxTransfers+1;c++){const u=new Map;v.push(u);const l=v[c-1],f=this.timetable.findReachableRoutes(T,d.transportModes);T.clear();for(const[t,d]of f.entries()){const f=this.timetable.getRoute(t);let m;for(let t=f.stopIndices.get(d);t<f.stops.length;t++){const d=f.stops[t],v=f.stops.length;if(void 0!==m){const o=f.stopTimes[m.trip*v+t],i=null!==(n=null===(e=p.get(d))||void 0===e?void 0:e.time)&&void 0!==n?n:at;let a=i;if(h.length>0){const t=[];for(const e of h){const n=null!==(s=null===(r=p.get(e))||void 0===r?void 0:r.time)&&void 0!==s?s:at;t.push(n)}const e=J.min(...t);a=J.min(i,e)}if("NOT_AVAILABLE"!==o.dropOffType&&o.arrival.toSeconds()<a.toSeconds()){const t=f.stopIndices.get(m.bestHopOnStop),e=f.stopTimes[m.trip*v+t];u.set(d,{time:o.arrival,legNumber:c,origin:m.origin,leg:{from:this.stopsIndex.findStopById(m.bestHopOnStop),to:this.stopsIndex.findStopById(d),departureTime:e.departure,arrivalTime:o.arrival,route:this.timetable.getServiceRoute(f.serviceRouteId)}}),p.set(d,{time:o.arrival,legNumber:c,origin:m.origin}),T.add(d)}}const g=null===(o=l.get(d))||void 0===o?void 0:o.time;if(void 0!==g&&(void 0===m||g.toSeconds()<=f.stopTimes[m.trip*v+t].departure.toSeconds())){const t=this.timetable.findEarliestTrip(f,d,null==m?void 0:m.trip,g);void 0!==t&&(m={trip:t,bestHopOnStop:d,origin:null!==(a=null===(i=l.get(d))||void 0===i?void 0:i.origin)&&void 0!==a?a:d})}}}if(this.considerTransfers(t,T,u,p,c),0===T.size)break}return new it(t,p,v,this.stopsIndex)}},exports.StopsIndex=Ae,exports.Time=J,exports.Timetable=rt;
|
|
2
2
|
//# sourceMappingURL=router.cjs.js.map
|