minotor 11.2.0 → 11.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/dist/cli.mjs +45 -19
- package/dist/cli.mjs.map +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.esm.js +1 -1
- package/dist/router.esm.js.map +1 -1
- package/dist/router.umd.js +1 -1
- package/dist/router.umd.js.map +1 -1
- package/dist/routing/rangeResult.d.ts +21 -1
- package/package.json +1 -1
- package/src/routing/__tests__/rangeResult.test.ts +86 -1
- package/src/routing/__tests__/rangeRouter.test.ts +129 -0
- package/src/routing/rangeResult.ts +21 -1
- package/src/routing/rangeRouter.ts +27 -19
package/dist/router.umd.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).minotor={})}(this,(function(t){"use strict";const e=t=>{let e=Math.floor(t/60);const n=Math.floor(t%60);return e>=24&&(e%=24),`${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},n=t=>{const e=Math.floor(t/60),n=t%60;return e>0?`${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`:`${n}min`},r={colors:{rounds:["#60a5fa","#ff9800","#14b8a6","#fb7185","#ffdf00","#b600ff","#ee82ee"],defaultRound:"#888888",originStation:"#60a5fa",destinationStation:"#ee82ee",defaultStation:"white",continuationFill:"#ffffcc"},penWidth:{continuation:2,continuationEdge:3}};function s(t){return"routeId"in t&&"stopIndex"in t&&"hopOffStopIndex"in t}function i(t){return"from"in t&&"to"in t&&"type"in t}function o(t){return"from"in t&&"duration"in t}class a{constructor(){this.lines=[]}addHeader(){return this.lines.push("digraph RoutingGraph {"," graph [overlap=false, splines=true, rankdir=TB, bgcolor=white, nodesep=0.8, ranksep=1.2, concentrate=true];",' node [fontname="Arial" margin=0.1];',' edge [fontname="Arial" fontsize=10];'),this}addComment(t){return this.lines.push("",` // ${t}`),this}addNode(t,e){const n=Object.entries(e).map((([t,e])=>`${t}="${e}"`)).join(" ");return this.lines.push(` "${t}" [${n}];`),this}addEdge(t,e,n={}){const r=Object.entries(n).map((([t,e])=>`${t}="${e}"`)).join(" "),s=r?` [${r}]`:"";return this.lines.push(` "${t}" -> "${e}"${s};`),this}addRaw(t){return this.lines.push(...t),this}build(){return this.lines.push("}"),this.lines.join("\n")}}function u(){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 c(t,e,n){for(let r=0;r<28;r+=7){const s=t>>>r,i=!(s>>>7==0&&0==e),o=255&(i?128|s:s);if(n.push(o),!i)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),i=255&(s?128|r:r);if(n.push(i),!s)return}n.push(e>>>31&1)}}const d=4294967296;function l(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let r=0,s=0;function i(e,i){const o=Number(t.slice(e,i));s*=n,r=r*n+o,r>=d&&(s+=r/d|0,r%=d)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?p(r,s):f(r,s)}function h(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(d*e+t);const n=16777215&(t>>>24|e<<8),r=e>>16&65535;let s=(16777215&t)+6777216*n+6710656*r,i=n+8147497*r,o=2*r;const a=1e7;return s>=a&&(i+=Math.floor(s/a),s%=a),i>=a&&(o+=Math.floor(i/a),i%=a),o.toString()+T(i)+T(s)}function f(t,e){return{lo:0|t,hi:0|e}}function p(t,e){return e=~e,t?t=1+~t:e+=1,f(t,e)}const T=t=>{const e=String(t);return"0000000".slice(e.length)+e};function E(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 m(){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 I=_();function _(){const t=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof t.getBigInt64&&"function"==typeof t.getBigUint64&&"function"==typeof t.setBigInt64&&"function"==typeof t.setBigUint64&&(!!globalThis.Deno||"object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const e=BigInt("-9223372036854775808"),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()),g(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),R(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),g(t),l(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),R(t),l(t)),dec:(t,e)=>function(t,e){let n=f(t,e);const r=2147483648&n.hi;r&&(n=p(n.lo,n.hi));const s=h(n.lo,n.hi);return r?"-"+s:s}(t,e),uDec:(t,e)=>h(t,e)}}function g(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function R(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const A=Symbol.for("@bufbuild/protobuf/text-encoding");function v(){if(null==globalThis[A]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[A]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[A]}var O;!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"}(O||(O={}));const S=34028234663852886e22,y=-34028234663852886e22;class N{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(U(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return w(t),E(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.encodeUtf8(t);return this.uint32(e.byteLength),this.raw(e)}float(t){!function(t){if("string"==typeof t){const e=t;if(t=Number(t),Number.isNaN(t)&&"NaN"!==e)throw new Error("invalid float32: "+e)}else if("number"!=typeof t)throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>S||t<y))throw new Error("invalid float32: "+t)}(t);let e=new Uint8Array(4);return new DataView(e.buffer).setFloat32(0,t,!0),this.raw(e)}double(t){let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t,!0),this.raw(e)}fixed32(t){U(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){w(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return w(t),E(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=I.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=I.uEnc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(e)}int64(t){let e=I.enc(t);return c(e.lo,e.hi,this.buf),this}sint64(t){const e=I.enc(t),n=e.hi>>31;return c(e.lo<<1^n,(e.hi<<1|e.lo>>>31)^n,this.buf),this}uint64(t){const e=I.uEnc(t);return c(e.lo,e.hi,this.buf),this}}class b{constructor(t,e=v().decodeUtf8){this.decodeUtf8=e,this.varint64=u,this.uint32=m,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 O.Varint:for(;128&this.buf[this.pos++];);break;case O.Bit64:this.pos+=4;case O.Bit32:this.pos+=4;break;case O.LengthDelimited:let n=this.uint32();this.pos+=n;break;case O.StartGroup:for(;;){const[t,n]=this.tag();if(n===O.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 I.dec(...this.varint64())}uint64(){return I.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),n=-(1&t);return t=(t>>>1|(1&e)<<31)^n,e=e>>>1^n,I.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 I.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return I.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 w(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 U(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 P,x;function L(t){switch(t){case 0:case"TRANSFER_TYPE_UNSPECIFIED":return P.TRANSFER_TYPE_UNSPECIFIED;case 1:case"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT":return P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case 2:case"TRANSFER_TYPE_TIMED_TRANSFER":return P.TRANSFER_TYPE_TIMED_TRANSFER;case 3:case"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME":return P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case 4:case"TRANSFER_TYPE_IN_SEAT_TRANSFER":return P.TRANSFER_TYPE_IN_SEAT_TRANSFER;default:return P.UNRECOGNIZED}}function C(t){switch(t){case 0:case"ROUTE_TYPE_UNSPECIFIED":return x.ROUTE_TYPE_UNSPECIFIED;case 1:case"ROUTE_TYPE_TRAM":return x.ROUTE_TYPE_TRAM;case 2:case"ROUTE_TYPE_SUBWAY":return x.ROUTE_TYPE_SUBWAY;case 3:case"ROUTE_TYPE_RAIL":return x.ROUTE_TYPE_RAIL;case 4:case"ROUTE_TYPE_BUS":return x.ROUTE_TYPE_BUS;case 5:case"ROUTE_TYPE_FERRY":return x.ROUTE_TYPE_FERRY;case 6:case"ROUTE_TYPE_CABLE_TRAM":return x.ROUTE_TYPE_CABLE_TRAM;case 7:case"ROUTE_TYPE_AERIAL_LIFT":return x.ROUTE_TYPE_AERIAL_LIFT;case 8:case"ROUTE_TYPE_FUNICULAR":return x.ROUTE_TYPE_FUNICULAR;case 9:case"ROUTE_TYPE_TROLLEYBUS":return x.ROUTE_TYPE_TROLLEYBUS;case 10:case"ROUTE_TYPE_MONORAIL":return x.ROUTE_TYPE_MONORAIL;default:return x.UNRECOGNIZED}}function Y(){return{stopTimes:new Uint8Array(0),pickupDropOffTypes:new Uint8Array(0),stops:new Uint8Array(0),serviceRouteId:0}}!function(t){t[t.TRANSFER_TYPE_UNSPECIFIED=0]="TRANSFER_TYPE_UNSPECIFIED",t[t.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT=1]="TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT",t[t.TRANSFER_TYPE_TIMED_TRANSFER=2]="TRANSFER_TYPE_TIMED_TRANSFER",t[t.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME=3]="TRANSFER_TYPE_REQUIRES_MINIMAL_TIME",t[t.TRANSFER_TYPE_IN_SEAT_TRANSFER=4]="TRANSFER_TYPE_IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(P||(P={})),function(t){t[t.ROUTE_TYPE_UNSPECIFIED=0]="ROUTE_TYPE_UNSPECIFIED",t[t.ROUTE_TYPE_TRAM=1]="ROUTE_TYPE_TRAM",t[t.ROUTE_TYPE_SUBWAY=2]="ROUTE_TYPE_SUBWAY",t[t.ROUTE_TYPE_RAIL=3]="ROUTE_TYPE_RAIL",t[t.ROUTE_TYPE_BUS=4]="ROUTE_TYPE_BUS",t[t.ROUTE_TYPE_FERRY=5]="ROUTE_TYPE_FERRY",t[t.ROUTE_TYPE_CABLE_TRAM=6]="ROUTE_TYPE_CABLE_TRAM",t[t.ROUTE_TYPE_AERIAL_LIFT=7]="ROUTE_TYPE_AERIAL_LIFT",t[t.ROUTE_TYPE_FUNICULAR=8]="ROUTE_TYPE_FUNICULAR",t[t.ROUTE_TYPE_TROLLEYBUS=9]="ROUTE_TYPE_TROLLEYBUS",t[t.ROUTE_TYPE_MONORAIL=10]="ROUTE_TYPE_MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(x||(x={}));const M={encode:(t,e=new N)=>(0!==t.stopTimes.length&&e.uint32(10).bytes(t.stopTimes),0!==t.pickupDropOffTypes.length&&e.uint32(18).bytes(t.pickupDropOffTypes),0!==t.stops.length&&e.uint32(26).bytes(t.stops),0!==t.serviceRouteId&&e.uint32(32).uint32(t.serviceRouteId),e),decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s=Y();for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopTimes=n.bytes();continue;case 2:if(18!==t)break;s.pickupDropOffTypes=n.bytes();continue;case 3:if(26!==t)break;s.stops=n.bytes();continue;case 4:if(32!==t)break;s.serviceRouteId=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopTimes:G(t.stopTimes)?z(t.stopTimes):new Uint8Array(0),pickupDropOffTypes:G(t.pickupDropOffTypes)?z(t.pickupDropOffTypes):new Uint8Array(0),stops:G(t.stops)?z(t.stops):new Uint8Array(0),serviceRouteId:G(t.serviceRouteId)?globalThis.Number(t.serviceRouteId):0}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=V(t.stopTimes)),0!==t.pickupDropOffTypes.length&&(e.pickupDropOffTypes=V(t.pickupDropOffTypes)),0!==t.stops.length&&(e.stops=V(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s;const i=Y();return i.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),i.pickupDropOffTypes=null!==(n=t.pickupDropOffTypes)&&void 0!==n?n:new Uint8Array(0),i.stops=null!==(r=t.stops)&&void 0!==r?r:new Uint8Array(0),i.serviceRouteId=null!==(s=t.serviceRouteId)&&void 0!==s?s:0,i}};const F={encode:(t,e=new N)=>(0!==t.destination&&e.uint32(8).uint32(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).uint32(t.minTransferTime),e),decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={destination:0,type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.destination=n.uint32();continue;case 2:if(16!==t)break;s.type=n.int32();continue;case 3:if(24!==t)break;s.minTransferTime=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({destination:G(t.destination)?globalThis.Number(t.destination):0,type:G(t.type)?L(t.type):0,minTransferTime:G(t.minTransferTime)?globalThis.Number(t.minTransferTime):void 0}),toJSON(t){const e={};return 0!==t.destination&&(e.destination=Math.round(t.destination)),0!==t.type&&(e.type=function(t){switch(t){case P.TRANSFER_TYPE_UNSPECIFIED:return"TRANSFER_TYPE_UNSPECIFIED";case P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT";case P.TRANSFER_TYPE_TIMED_TRANSFER:return"TRANSFER_TYPE_TIMED_TRANSFER";case P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME";case P.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"TRANSFER_TYPE_IN_SEAT_TRANSFER";case P.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={destination:0,type:0,minTransferTime:void 0};return s.destination=null!==(e=t.destination)&&void 0!==e?e:0,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 D={encode:(t,e=new N)=>(0!==t.stopIndex&&e.uint32(8).uint32(t.stopIndex),0!==t.routeId&&e.uint32(16).uint32(t.routeId),0!==t.tripIndex&&e.uint32(24).uint32(t.tripIndex),e),decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={stopIndex:0,routeId:0,tripIndex:0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.stopIndex=n.uint32();continue;case 2:if(16!==t)break;s.routeId=n.uint32();continue;case 3:if(24!==t)break;s.tripIndex=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopIndex:G(t.stopIndex)?globalThis.Number(t.stopIndex):0,routeId:G(t.routeId)?globalThis.Number(t.routeId):0,tripIndex:G(t.tripIndex)?globalThis.Number(t.tripIndex):0}),toJSON(t){const e={};return 0!==t.stopIndex&&(e.stopIndex=Math.round(t.stopIndex)),0!==t.routeId&&(e.routeId=Math.round(t.routeId)),0!==t.tripIndex&&(e.tripIndex=Math.round(t.tripIndex)),e},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={stopIndex:0,routeId:0,tripIndex:0};return s.stopIndex=null!==(e=t.stopIndex)&&void 0!==e?e:0,s.routeId=null!==(n=t.routeId)&&void 0!==n?n:0,s.tripIndex=null!==(r=t.tripIndex)&&void 0!==r?r:0,s}};const k={encode(t,e=new N){void 0!==t.origin&&D.encode(t.origin,e.uint32(10).fork()).join();for(const n of t.destinations)D.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={origin:void 0,destinations:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.origin=D.decode(n,n.uint32());continue;case 2:if(18!==t)break;s.destinations.push(D.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({origin:G(t.origin)?D.fromJSON(t.origin):void 0,destinations:globalThis.Array.isArray(null==t?void 0:t.destinations)?t.destinations.map((t=>D.fromJSON(t))):[]}),toJSON(t){var e;const n={};return void 0!==t.origin&&(n.origin=D.toJSON(t.origin)),(null===(e=t.destinations)||void 0===e?void 0:e.length)&&(n.destinations=t.destinations.map((t=>D.toJSON(t)))),n},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={origin:void 0,destinations:[]};return n.origin=void 0!==t.origin&&null!==t.origin?D.fromPartial(t.origin):void 0,n.destinations=(null===(e=t.destinations)||void 0===e?void 0:e.map((t=>D.fromPartial(t))))||[],n}};const B={encode(t,e=new N){e.uint32(10).fork();for(const n of t.routes)e.uint32(n);e.join();for(const n of t.transfers)F.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={routes:[],transfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8===t){s.routes.push(n.uint32());continue}if(10===t){const t=n.uint32()+n.pos;for(;n.pos<t;)s.routes.push(n.uint32());continue}break;case 2:if(18!==t)break;s.transfers.push(F.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[],transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>F.fromJSON(t))):[]}),toJSON(t){var e,n;const r={};return(null===(e=t.routes)||void 0===e?void 0:e.length)&&(r.routes=t.routes.map((t=>Math.round(t)))),(null===(n=t.transfers)||void 0===n?void 0:n.length)&&(r.transfers=t.transfers.map((t=>F.toJSON(t)))),r},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={routes:[],transfers:[]};return r.routes=(null===(e=t.routes)||void 0===e?void 0:e.map((t=>t)))||[],r.transfers=(null===(n=t.transfers)||void 0===n?void 0:n.map((t=>F.fromPartial(t))))||[],r}};const $={encode(t,e=new N){0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e.uint32(26).fork();for(const n of t.routes)e.uint32(n);return e.join(),e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={type:0,name:"",routes:[]};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;case 3:if(24===t){s.routes.push(n.uint32());continue}if(26===t){const t=n.uint32()+n.pos;for(;n.pos<t;)s.routes.push(n.uint32());continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({type:G(t.type)?C(t.type):0,name:G(t.name)?globalThis.String(t.name):"",routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[]}),toJSON(t){var e;const n={};return 0!==t.type&&(n.type=function(t){switch(t){case x.ROUTE_TYPE_UNSPECIFIED:return"ROUTE_TYPE_UNSPECIFIED";case x.ROUTE_TYPE_TRAM:return"ROUTE_TYPE_TRAM";case x.ROUTE_TYPE_SUBWAY:return"ROUTE_TYPE_SUBWAY";case x.ROUTE_TYPE_RAIL:return"ROUTE_TYPE_RAIL";case x.ROUTE_TYPE_BUS:return"ROUTE_TYPE_BUS";case x.ROUTE_TYPE_FERRY:return"ROUTE_TYPE_FERRY";case x.ROUTE_TYPE_CABLE_TRAM:return"ROUTE_TYPE_CABLE_TRAM";case x.ROUTE_TYPE_AERIAL_LIFT:return"ROUTE_TYPE_AERIAL_LIFT";case x.ROUTE_TYPE_FUNICULAR:return"ROUTE_TYPE_FUNICULAR";case x.ROUTE_TYPE_TROLLEYBUS:return"ROUTE_TYPE_TROLLEYBUS";case x.ROUTE_TYPE_MONORAIL:return"ROUTE_TYPE_MONORAIL";case x.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),""!==t.name&&(n.name=t.name),(null===(e=t.routes)||void 0===e?void 0:e.length)&&(n.routes=t.routes.map((t=>Math.round(t)))),n},create:t=>$.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={type:0,name:"",routes:[]};return s.type=null!==(e=t.type)&&void 0!==e?e:0,s.name=null!==(n=t.name)&&void 0!==n?n:"",s.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],s}};const j={encode(t,e=new N){for(const n of t.stopsAdjacency)B.encode(n,e.uint32(10).fork()).join();for(const n of t.routesAdjacency)M.encode(n,e.uint32(18).fork()).join();for(const n of t.serviceRoutes)$.encode(n,e.uint32(26).fork()).join();for(const n of t.tripContinuations)k.encode(n,e.uint32(34).fork()).join();for(const n of t.guaranteedTripTransfers)k.encode(n,e.uint32(42).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopsAdjacency.push(B.decode(n,n.uint32()));continue;case 2:if(18!==t)break;s.routesAdjacency.push(M.decode(n,n.uint32()));continue;case 3:if(26!==t)break;s.serviceRoutes.push($.decode(n,n.uint32()));continue;case 4:if(34!==t)break;s.tripContinuations.push(k.decode(n,n.uint32()));continue;case 5:if(42!==t)break;s.guaranteedTripTransfers.push(k.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>B.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>M.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>$.fromJSON(t))):[],tripContinuations:globalThis.Array.isArray(null==t?void 0:t.tripContinuations)?t.tripContinuations.map((t=>k.fromJSON(t))):[],guaranteedTripTransfers:globalThis.Array.isArray(null==t?void 0:t.guaranteedTripTransfers)?t.guaranteedTripTransfers.map((t=>k.fromJSON(t))):[]}),toJSON(t){var e,n,r,s,i;const o={};return(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(o.stopsAdjacency=t.stopsAdjacency.map((t=>B.toJSON(t)))),(null===(n=t.routesAdjacency)||void 0===n?void 0:n.length)&&(o.routesAdjacency=t.routesAdjacency.map((t=>M.toJSON(t)))),(null===(r=t.serviceRoutes)||void 0===r?void 0:r.length)&&(o.serviceRoutes=t.serviceRoutes.map((t=>$.toJSON(t)))),(null===(s=t.tripContinuations)||void 0===s?void 0:s.length)&&(o.tripContinuations=t.tripContinuations.map((t=>k.toJSON(t)))),(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.length)&&(o.guaranteedTripTransfers=t.guaranteedTripTransfers.map((t=>k.toJSON(t)))),o},create:t=>j.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s,i;const o={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};return o.stopsAdjacency=(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.map((t=>B.fromPartial(t))))||[],o.routesAdjacency=(null===(n=t.routesAdjacency)||void 0===n?void 0:n.map((t=>M.fromPartial(t))))||[],o.serviceRoutes=(null===(r=t.serviceRoutes)||void 0===r?void 0:r.map((t=>$.fromPartial(t))))||[],o.tripContinuations=(null===(s=t.tripContinuations)||void 0===s?void 0:s.map((t=>k.fromPartial(t))))||[],o.guaranteedTripTransfers=(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.map((t=>k.fromPartial(t))))||[],o}};function z(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n}}function V(t){if(globalThis.Buffer)return globalThis.Buffer.from(t).toString("base64");{const e=[];return t.forEach((t=>{e.push(globalThis.String.fromCharCode(t))})),globalThis.btoa(e.join(""))}}function G(t){return null!=t}let J=class t{constructor(t,e,n,r,s){this.id=t,this.stopTimes=e,this.pickupDropOffTypes=n,this.stops=r,this.serviceRouteId=s,this.nbStops=r.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<r.length;t++){const e=r[t],n=this.stopIndices.get(e);n?n.push(t):this.stopIndices.set(e,[t])}}static of(e){var n,r;const{id:s,serviceRouteId:i,trips:o}=e;if(0===o.length)throw new Error("At least one trip must be provided");const a=o[0],u=new Uint32Array(a.stops.map((t=>t.id))),c=u.length;for(let t=1;t<o.length;t++){const e=o[t];if(e.stops.length!==c)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${c}`);for(let n=0;n<c;n++)if(e.stops[n].id!==u[n])throw new Error(`Trip ${t} has different stop at index ${n}`)}const d=new Uint16Array(o.length*c*2);for(let t=0;t<o.length;t++){const e=o[t];for(let n=0;n<c;n++){const r=e.stops[n],s=2*(t*c+n);d[s]=r.arrivalTime,d[s+1]=r.departureTime}}const l=o.length*c,h=new Uint8Array(Math.ceil(l/2));for(let t=0;t<o.length;t++){const e=o[t];for(let s=0;s<c;s++){const i=e.stops[s],o=t*c+s,a=null!==(n=i.pickUpType)&&void 0!==n?n:0,u=null!==(r=i.dropOffType)&&void 0!==r?r:0,d=Math.floor(o/2),l=o%2==1;h[d]|=l?a<<6|u<<4:a<<2|u}}return new t(s,d,h,u,i)}serialize(){return{stopTimes:this.stopTimes,pickupDropOffTypes:this.pickupDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}getNbStops(){return this.nbStops}getNbTrips(){return this.nbTrips}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const n=2*(e*this.stops.length+t),r=this.stopTimes[n];if(void 0===r)throw new Error(`Arrival time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return r}tripStopOffset(t){return t*this.nbStops}arrivalAtOffset(t,e){return this.stopTimes[2*(e+t)]}departureAtOffset(t,e){return this.stopTimes[2*(e+t)+1]}dropOffTypeAtOffset(t,e){const n=e+t,r=this.pickupDropOffTypes[n>>1];return 1&n?r>>4&3:3&r}departureFrom(t,e){const n=2*(e*this.stops.length+t)+1,r=this.stopTimes[n];if(void 0===r)throw new Error(`Departure time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return r}pickUpTypeFrom(t,e){const n=e*this.stops.length+t,r=n>>1,s=!(1&~n),i=this.pickupDropOffTypes[r];if(void 0===i)throw new Error(`Pick up type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return s?i>>6&3:i>>2&3}dropOffTypeAt(t,e){const n=e*this.stops.length+t,r=n>>1,s=!(1&~n),i=this.pickupDropOffTypes[r];if(void 0===i)throw new Error(`Drop off type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return s?i>>4&3:3&i}findEarliestTrip(t,e=0,n){if(this.nbTrips<=0)return;let r=this.nbTrips-1;if(void 0!==n&&(r=Math.min(r,n-1)),r<0)return;let s=0,i=-1;for(;s<=r;){const n=s+r>>>1;this.departureFrom(t,n)<e?s=n+1:(i=n,r=n-1)}return-1!==i?i:void 0}stopRouteIndices(t){const e=this.stopIndices.get(t);return void 0===e?[]:e}stopId(t){const e=this.stops[t];if(void 0===e)throw new Error(`StopId for stop at index ${t} not found in route ${this.serviceRouteId}`);return e}};const W=(BigInt(1)<<BigInt(20))-BigInt(1),Z=1048575,q=BigInt(0),Q=BigInt(20),X=BigInt(40),H=(t,e)=>{if(t<0||t>Z)throw new Error(`${e} must be between 0 and 1048575, got ${t}`)},K=(t,e,n)=>(H(t,"stopIndex"),H(e,"routeId"),H(n,"tripIndex"),BigInt(t)<<X|BigInt(e)<<Q|BigInt(n)<<q),tt=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),et=!0,nt=t=>{if(tt===et)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint32(4*e,t[e],et);return e},rt=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(tt===et)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint32(4*t,et);return e},st=t=>{if(tt===et)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint16(2*e,t[e],et);return e},it=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(tt===et)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint16(2*t,et);return e},ot=t=>{const e=[];return t.forEach((t=>{const n=t.serialize();e.push({stopTimes:st(n.stopTimes),pickupDropOffTypes:n.pickupDropOffTypes,stops:nt(n.stops),serviceRouteId:n.serviceRouteId})})),e},at=t=>{switch(t){case P.TRANSFER_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf transfer type.");case P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case P.TRANSFER_TYPE_TIMED_TRANSFER:return"GUARANTEED";case P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case P.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"IN_SEAT";case P.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},ut=t=>{switch(t){case"RECOMMENDED":return P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return P.TRANSFER_TYPE_TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case"IN_SEAT":return P.TRANSFER_TYPE_IN_SEAT_TRANSFER}},ct=t=>{switch(t){case x.ROUTE_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf route type.");case x.ROUTE_TYPE_TRAM:return"TRAM";case x.ROUTE_TYPE_SUBWAY:return"SUBWAY";case x.ROUTE_TYPE_RAIL:return"RAIL";case x.ROUTE_TYPE_BUS:return"BUS";case x.ROUTE_TYPE_FERRY:return"FERRY";case x.ROUTE_TYPE_CABLE_TRAM:return"CABLE_TRAM";case x.ROUTE_TYPE_AERIAL_LIFT:return"AERIAL_LIFT";case x.ROUTE_TYPE_FUNICULAR:return"FUNICULAR";case x.ROUTE_TYPE_TROLLEYBUS:return"TROLLEYBUS";case x.ROUTE_TYPE_MONORAIL:return"MONORAIL";case x.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},dt=t=>{switch(t){case"TRAM":return x.ROUTE_TYPE_TRAM;case"SUBWAY":return x.ROUTE_TYPE_SUBWAY;case"RAIL":return x.ROUTE_TYPE_RAIL;case"BUS":return x.ROUTE_TYPE_BUS;case"FERRY":return x.ROUTE_TYPE_FERRY;case"CABLE_TRAM":return x.ROUTE_TYPE_CABLE_TRAM;case"AERIAL_LIFT":return x.ROUTE_TYPE_AERIAL_LIFT;case"FUNICULAR":return x.ROUTE_TYPE_FUNICULAR;case"TROLLEYBUS":return x.ROUTE_TYPE_TROLLEYBUS;case"MONORAIL":return x.ROUTE_TYPE_MONORAIL}},lt=t=>{const e=[];for(const[r,s]of t.entries()){const[t,i,o]=(n=r,[Number(n>>X&W),Number(n>>Q&W),Number(n>>q&W)]);e.push({origin:{stopIndex:t,routeId:i,tripIndex:o},destinations:s.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})))})}var n;return e},ht=t=>{const e=new Map;for(let n=0;n<t.length;n++){const r=t[n],s=r.origin,i=K(s.stopIndex,s.routeId,s.tripIndex),o=r.destinations.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(i,o)}return e},ft=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),pt=[];class Tt{constructor(t,e,n,r,s){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=n,this.tripContinuations=r,this.guaranteedTripTransfers=s,this.activeStops=new Set;for(let e=0;e<t.length;e++){const n=t[e];(n.routes.length>0||n.transfers&&n.transfers.length>0)&&this.activeStops.add(e)}}serialize(){const t={stopsAdjacency:(n=this.stopsAdjacency,n.map((t=>({transfers:t.transfers?t.transfers.map((t=>Object.assign({destination:t.destination,type:ut(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime}))):[],routes:t.routes})))),routesAdjacency:ot(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:dt(t.type),name:t.name,routes:t.routes})))),tripContinuations:lt(this.tripContinuations||new Map),guaranteedTripTransfers:lt(this.guaranteedTripTransfers||new Map)};var e,n;const r=new N;return j.encode(t,r),r.finish()}static fromData(t){const e=new b(t),n=j.decode(e);return new Tt((t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],s=[];for(let t=0;t<r.transfers.length;t++){const e=r.transfers[t],n=Object.assign({destination:e.destination,type:at(e.type)},void 0!==e.minTransferTime&&{minTransferTime:e.minTransferTime});s.push(n)}const i={routes:r.routes};s.length>0&&(i.transfers=s),e.push(i)}return e})(n.stopsAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],s=rt(r.stops);e.push(new J(n,it(r.stopTimes),r.pickupDropOffTypes,s,r.serviceRouteId))}return e})(n.routesAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n];e.push({type:ct(r.type),name:r.name,routes:r.routes})}return e})(n.serviceRoutes),ht(n.tripContinuations),ht(n.guaranteedTripTransfers))}isActive(t){return this.activeStops.has(t)}nbStops(){return this.stopsAdjacency.length}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){const e=this.stopsAdjacency[t];if(!e)throw new Error(`Stop ID ${t} not found`);return e.transfers||[]}getContinuousTrips(t,e,n){var r;const s=null===(r=this.tripContinuations)||void 0===r?void 0:r.get(K(t,e,n));return s||pt}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);return{type:e.type,name:e.name}}routesPassingThrough(t){const e=this.stopsAdjacency[t];if(!e)return[];const n=[];for(let t=0;t<e.routes.length;t++){const r=e.routes[t],s=this.routesAdjacency[r];s&&n.push(s)}return n}findReachableRoutes(t,e=ft){const n=new Map,r=e!==ft;for(const s of t){const t=this.stopsAdjacency[s];if(t)for(let i=0;i<t.routes.length;i++){const o=this.routesAdjacency[t.routes[i]];if(!o)continue;if(r){const t=this.serviceRoutes[o.serviceRoute()];if(!t||!e.has(t.type))continue}const a=o.stopRouteIndices(s)[0],u=n.get(o);void 0!==u?a<u&&n.set(o,a):n.set(o,a)}}return n}isTripTransferGuaranteed(t,e){var n;const r=K(t.stopIndex,t.routeId,t.tripIndex),s=null===(n=this.guaranteedTripTransfers)||void 0===n?void 0:n.get(r);if(!s)return!1;for(let t=0;t<s.length;t++){const n=s[t];if(n.stopIndex===e.stopIndex&&n.routeId===e.routeId&&n.tripIndex===e.tripIndex)return!0}return!1}findFirstBoardableTrip(t,e,n,r=0,s,i,o=0){const a=e.getNbTrips();for(let u=n;u<(null!=s?s:a);u++){if(1===e.pickUpTypeFrom(t,u))continue;if(void 0===i)return u;if(this.isTripTransferGuaranteed(i,{stopIndex:t,routeId:e.id,tripIndex:u}))return u;if(e.departureFrom(t,u)>=r+o)return u}}getGuaranteedTripTransfers(t,e,n){var r;const s=null===(r=this.guaranteedTripTransfers)||void 0===r?void 0:r.get(K(t,e,n));return s||pt}}class Et{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}Et.Builder=class{constructor(){var t;this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:(t=120,Math.round(t/60)),transportModes:ft}}from(t){return this.fromValue=t,this}to(t){return this.toValue=t instanceof Set?t:new Set([t]),this}departureTime(t){return this.departureTimeValue=t,this}maxTransfers(t){return this.optionsValue.maxTransfers=t,this}minTransferTime(t){return this.optionsValue.minTransferTime=t,this}transportModes(t){return this.optionsValue.transportModes=t,this}maxInitialWaitingTime(t){return this.optionsValue.maxInitialWaitingTime=t,this}build(){return new Et(this)}};class mt extends Et{constructor(t){super(t),this.lastDepartureTime=t.lastDepartureTimeValue,this.rangeOptions=t.rangeOptionsValue}}mt.Builder=class extends Et.Builder{constructor(){super(...arguments),this.rangeOptionsValue={optimizeBeyondLatestDeparture:!0}}lastDepartureTime(t){return this.lastDepartureTimeValue=t,this}rangeOptions(t){return this.rangeOptionsValue=Object.assign(Object.assign({},this.rangeOptionsValue),t),this}build(){return new mt(this)}};class It{constructor(t){this.legs=t}departureTime(){let t=0;for(let e=0;e<this.legs.length;e++){const n=this.legs[e];if("departureTime"in n)return n.departureTime-t;"duration"in n&&n.duration&&(t+=n.duration)}throw new Error("No vehicle leg found in route")}arrivalTime(){let t=0,e=0;for(let n=this.legs.length-1;n>=0;n--){const r=this.legs[n];if("arrivalTime"in r)return t=r.arrivalTime,t+e;"minTransferTime"in r&&r.minTransferTime&&(e+=r.minTransferTime)}throw new Error("No vehicle leg found in route")}totalDuration(){return 0===this.legs.length?0:Math.abs(this.arrivalTime()-this.departureTime())}toString(){return this.legs.map(((t,r)=>{const s=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,i=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,o="type"in t&&!("route"in t)?`Transfer: ${t.type}${t.minTransferTime?`, Minimum Transfer Time: ${n(t.minTransferTime)}`:""}`:"",a="duration"in t?`Access duration: ${n(t.duration)}`:"",u="route"in t&&"departureTime"in t&&"arrivalTime"in t?`Route: ${t.route.type} ${t.route.name}, Departure: ${e(t.departureTime)}, Arrival: ${e(t.arrivalTime)}`:"";return[`Leg ${r+1}:`,` ${s}`,` ${i}`,o?` ${o}`:"",a?` ${a}`:"",u?` ${u}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}}const _t=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],gt=t=>{const e=_t[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};class Rt{constructor(t,e,n,r){this.destinations=t,this.routingState=e,this.stopsIndex=n,this.timetable=r}expandDestinations(t){const e=t instanceof Set?t:void 0!==t?[t]:this.destinations,n=new Set;for(const t of e)for(const e of this.stopsIndex.equivalentStops(t))n.add(e.id);return n}bestRouteToSourceStopId(t){var e;if(t instanceof Set){const e=new Set;for(const n of t){const t=this.stopsIndex.findStopBySourceStopId(n);void 0!==t&&e.add(t.id)}return 0===e.size?void 0:this.bestRoute(e)}const n=null===(e=this.stopsIndex.findStopBySourceStopId(t))||void 0===e?void 0:e.id;return void 0===n?void 0:this.bestRoute(n)}bestRoute(t){var e;const n=this.expandDestinations(t);let r,s,i;for(const t of n){const e=this.routingState.getArrival(t);void 0!==e&&(void 0===s||e.arrival<s)&&(r=t,s=e.arrival,i=e.legNumber)}if(void 0===r||void 0===i)return;const o=[];let a,u=r,c=i;for(;c>=0;){const t=null===(e=this.routingState.graph[c])||void 0===e?void 0:e[u];if(!t){if(0===c)break;throw new Error(`No edge arriving at stop ${u} at round ${c}`)}let n;if("routeId"in t){let e,r;if(t.continuationOf){let n=t;const s=[n];for(;n.continuationOf;)s.push(n.continuationOf),n=n.continuationOf;e=n,r=this.buildVehicleLeg(s)}else e=t,r=this.buildVehicleLeg([t]);n=r,a&&this.timetable.isTripTransferGuaranteed({stopIndex:e.hopOffStopIndex,routeId:e.routeId,tripIndex:e.tripIndex},{stopIndex:a.stopIndex,routeId:a.routeId,tripIndex:a.tripIndex})&&o.push(this.buildGuaranteedTransferLeg(e,a)),a=e}else if("type"in t)n=this.buildTransferLeg(t),a=void 0;else{if(!("duration"in t))break;n=this.buildAccessLeg(t),a=void 0}o.push(n),u=n.from.id,"routeId"in t&&(c-=1)}return new It(o.reverse())}buildVehicleLeg(t){if(0===t.length)throw new Error("Cannot build vehicle leg from empty edges");const e=t[t.length-1],n=t[0],r=this.timetable.getRoute(e.routeId),s=this.timetable.getRoute(n.routeId);return{from:this.stopsIndex.findStopById(r.stopId(e.stopIndex)),to:this.stopsIndex.findStopById(s.stopId(n.hopOffStopIndex)),route:this.timetable.getServiceRouteInfo(r),departureTime:r.departureFrom(e.stopIndex,e.tripIndex),arrivalTime:n.arrival,pickUpType:gt(r.pickUpTypeFrom(e.stopIndex,e.tripIndex)),dropOffType:gt(s.dropOffTypeAt(n.hopOffStopIndex,n.tripIndex))}}buildTransferLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),minTransferTime:t.minTransferTime,type:t.type}}buildAccessLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),duration:t.duration}}buildGuaranteedTransferLeg(t,e){const n=this.timetable.getRoute(t.routeId),r=this.timetable.getRoute(e.routeId),s=n.stopId(t.hopOffStopIndex),i=r.stopId(e.stopIndex);return{from:this.stopsIndex.findStopById(s),to:this.stopsIndex.findStopById(i),type:"GUARANTEED"}}arrivalAt(t,e){var n,r;const s=this.stopsIndex.equivalentStops(t);let i;for(const t of s){let s;if(void 0===e||(null===(n=this.routingState.getArrival(t.id))||void 0===n?void 0:n.legNumber)===e+1)s=this.routingState.getArrival(t.id);else for(let n=e+1;n>=0;n--){const e=null===(r=this.routingState.graph[n])||void 0===r?void 0:r[t.id];if(void 0!==e){s={arrival:e.arrival,legNumber:n};break}}void 0!==s&&(void 0===i||s.arrival<i.arrival)&&(i=s)}return i}}class At{constructor(t,e){this.timetable=t,this.stopsIndex=e}collectAccessPaths(t,e){var n;const r=this.stopsIndex.equivalentStops(t).map((t=>t.id)),s=new Map;for(const t of r){const r=s.get(t);(void 0===r||r.duration>0)&&s.set(t,{fromStopId:t,toStopId:t,duration:0});for(const r of this.timetable.getTransfers(t))if("REQUIRES_MINIMAL_TIME"===r.type){const i=null!==(n=r.minTransferTime)&&void 0!==n?n:e,o=s.get(r.destination);(void 0===o||o.duration&&i<o.duration)&&s.set(r.destination,{fromStopId:t,toStopId:r.destination,duration:i})}}return Array.from(s.values())}collectDepartureTimes(t,e,n){const r=new Map;for(const s of t){const{toStopId:t}=s,i=e+s.duration,o=n+s.duration;for(const e of this.timetable.routesPassingThrough(t))for(const n of e.stopRouteIndices(t)){let t=e.findEarliestTrip(n,i);if(void 0===t)continue;const a=e.getNbTrips();for(;t<a;){const i=e.departureFrom(n,t);if(i>o)break;if(1!==e.pickUpTypeFrom(n,t)){const t=i-s.duration;let e=r.get(t);void 0===e&&r.set(t,e=new Set),e.add(s)}t++}}}if(0===r.size)return[];return Array.from(r.entries()).sort((([t],[e])=>e-t)).map((([t,e])=>({depTime:t,legs:Array.from(e)})))}}const vt=65535;class Ot{constructor(t,e,n,r,s=0){this._destinationBest=vt,this.reachedStops=[],this.destinations=e,this.destinationSet=new Set(e),this.earliestArrivalTimes=new Uint16Array(r).fill(vt),this.earliestArrivalLegs=new Uint8Array(r),this.origins=[],this.graph=[new Array(r)];for(let t=1;t<=s;t++)this.graph.push(new Array(r));this.seedAccessPaths(t,n)}seedAccessPaths(t,e){const n=new Set;for(const r of e){const e=t+r.duration,s=0===r.duration?{stopId:r.fromStopId,arrival:t}:{arrival:e,from:r.fromStopId,to:r.toStopId,duration:r.duration},i=r.toStopId;e<this.earliestArrivalTimes[i]&&(this.earliestArrivalTimes[i]=e,this.graph[0][i]=s),n.add(i)}for(const t of n)this.reachedStops.push(t);this.origins=Array.from(n);for(let t=0;t<this.destinations.length;t++){const e=this.earliestArrivalTimes[this.destinations[t]];e<this._destinationBest&&(this._destinationBest=e)}}get nbStops(){return this.earliestArrivalTimes.length}arrivalTime(t){return this.earliestArrivalTimes[t]}get destinationBest(){return this._destinationBest}improvementBound(t,e){return this.arrivalTime(e)}initRound(t){}updateArrival(t,e,n){this.reachedStops.push(t),this.earliestArrivalTimes[t]=e,this.earliestArrivalLegs[t]=n,this.destinationSet.has(t)&&e<this._destinationBest&&(this._destinationBest=e)}resetFor(t,e){for(const t of this.reachedStops){this.earliestArrivalTimes[t]=vt,this.earliestArrivalLegs[t]=0;for(let e=0;e<this.graph.length;e++)this.graph[e][t]=void 0}this.reachedStops.length=0,this._destinationBest=vt,this.seedAccessPaths(t,e)}*arrivals(){for(let t=0;t<this.earliestArrivalTimes.length;t++){const e=this.earliestArrivalTimes[t];e<vt&&(yield{stop:t,arrival:e,legNumber:this.earliestArrivalLegs[t]})}}earliestArrivalAtAnyDestination(){return this._destinationBest}getArrival(t){const e=this.earliestArrivalTimes[t];if(!(e>=vt))return{arrival:e,legNumber:this.earliestArrivalLegs[t]}}isDestination(t){return this.destinationSet.has(t)}static fromTestData({nbStops:t,origins:e=[],destinations:n=[],arrivals:r=[],graph:s=[]}){const i=new Ot(0,n,e.map((t=>({fromStopId:t,toStopId:t,duration:0}))),t),o=new Uint16Array(t).fill(vt),a=new Uint8Array(t);for(const[t,e,n]of r)o[t]=e,a[t]=n;i.earliestArrivalTimes=o,i.earliestArrivalLegs=a,i._destinationBest=vt;for(const t of n){const e=o[t];void 0!==e&&e<i._destinationBest&&(i._destinationBest=e)}const u=s.map((e=>{const n=new Array(t);for(const[t,r]of e)n[t]=r;return n}));return i.graph.splice(0,i.graph.length,...u),i}}class St{constructor(t,e,n,r){this.timetable=t,this.stopsIndex=e,this.accessFinder=n,this.raptor=r}route(t){const e=this.accessFinder.collectAccessPaths(t.from,t.options.minTransferTime),n=Array.from(t.to).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),r=new Ot(t.departureTime,n,e,this.timetable.nbStops(),t.options.maxTransfers+1);return this.raptor.run(t.options,r),new Rt(new Set(n),r,this.stopsIndex,this.timetable)}}class yt{constructor(t,e){this._runs=t,this._destinations=e}get destinations(){return this._destinations}normalizeTargets(t){return t instanceof Set?new Set(t):void 0!==t?new Set([t]):new Set(this._destinations)}getRoutes(){const t=[];for(const{result:e}of this._runs){const n=e.bestRoute();void 0!==n&&t.push(n)}return t.reverse()}bestRoute(t){const e=this.normalizeTargets(t);let n,r;for(const t of this._runs)for(const s of e){const e=t.result.arrivalAt(s);void 0!==e&&((void 0===r||e.arrival<r)&&(r=e.arrival,n=t))}return null==n?void 0:n.result.bestRoute(e)}latestDepartureRoute(t){const e=this.normalizeTargets(t);for(const{result:t}of this._runs){const n=t.bestRoute(e);if(void 0!==n)return n}}fastestRoute(t){const e=this.normalizeTargets(t);let n,r=1/0;for(const t of this._runs)for(const s of e){const e=t.result.arrivalAt(s);if(void 0===e)continue;const i=e.arrival-t.departureTime;i<r&&(r=i,n=t)}return null==n?void 0:n.result.bestRoute(e)}get size(){return this._runs.length}earliestArrivalAt(t,e){let n;for(const{result:r}of this._runs){const s=r.arrivalAt(t,e);void 0!==s&&(void 0===n||s.arrival<n.arrival)&&(n=s)}return n}shortestDurationTo(t,e){let n;for(const{departureTime:r,result:s}of this._runs){const i=s.arrivalAt(t,e);if(void 0===i)continue;const o=i.arrival-r;(void 0===n||o<n.duration)&&(n=Object.assign(Object.assign({},i),{duration:o}))}return n}allShortestDurations(){const t=new Map;for(const{departureTime:e,result:n}of this._runs)for(const{stop:r,arrival:s,legNumber:i}of n.routingState.arrivals()){const n=s-e,o=t.get(r);(void 0===o||n<o.duration)&&t.set(r,{arrival:s,legNumber:i,duration:n})}return t}allEarliestArrivals(){const t=new Map;for(const{result:e}of this._runs)for(const{stop:n,arrival:r,legNumber:s}of e.routingState.arrivals()){const e=t.get(n);(void 0===e||r<e.arrival)&&t.set(n,{arrival:r,legNumber:s})}return t}[Symbol.iterator](){return this._runs[Symbol.iterator]()}}class Nt{constructor(t,e,n){this._destinationBest=vt,this.latestDeparture=n,this.roundLabels=Array.from({length:t+2},(()=>new Uint16Array(e).fill(vt))),this.changedInRound=Array.from({length:t+2},(()=>[]))}setCurrentRun(t){this.currentRun=t;const e=t.graph[0];for(const n of t.origins){const t=e[n];t&&this.updateArrival(n,t.arrival,0)}}get origins(){return this.currentRun.origins}get graph(){return this.currentRun.graph}arrivalTime(t){return this.currentRun.arrivalTime(t)}improvementBound(t,e){return this.roundLabels[t][e]}get destinationBest(){return this._destinationBest}isDestination(t){return this.currentRun.isDestination(t)}updateArrival(t,e,n){this.currentRun.updateArrival(t,e,n),e<this.roundLabels[n][t]&&(this.roundLabels[n][t]=e,this.changedInRound[n].push(t),this.currentRun.isDestination(t)&&e<this._destinationBest&&(this._destinationBest=e))}initRound(t){const e=this.changedInRound[t-1];if(0===e.length)return;const n=this.roundLabels[t-1],r=this.roundLabels[t];for(let t=0;t<e.length;t++){const s=e[t];n[s]<r[s]&&(r[s]=n[s])}e.length=0}}class bt{constructor(t,e,n,r){this.timetable=t,this.stopsIndex=e,this.accessFinder=n,this.raptor=r}rangeRoute(t){var e,n;const{departureTime:r,lastDepartureTime:s}=t,i=Array.from(t.to).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),o=this.accessFinder.collectAccessPaths(t.from,t.options.minTransferTime),a=this.accessFinder.collectDepartureTimes(o,r,s);if(0===a.length)return new yt([],new Set(i));const u=t.options.maxTransfers+1,c=new Nt(u,this.timetable.nbStops(),s),d=[],l=new Map;for(const t of i)l.set(t,vt);const h=new Set(o.map((t=>t.toStopId)).filter((t=>i.includes(t)))),f=new Set;let p=null;if(t.rangeOptions.optimizeBeyondLatestDeparture){p=new Ot(s+1,i,o,this.timetable.nbStops(),u),c.setCurrentRun(p),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:void 0}),c);for(const t of i){const n=p.arrivalTime(t);n<(null!==(e=l.get(t))&&void 0!==e?e:vt)&&l.set(t,n)}}for(const{depTime:e,legs:r}of a){if(f.size===i.length)break;null===p?p=new Ot(e,i,r,this.timetable.nbStops(),u):p.resetFor(e,r),c.setCurrentRun(p),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:0}),c);let s=!1;for(const t of i){const e=p.arrivalTime(t);e>=(null!==(n=l.get(t))&&void 0!==n?n:vt)||(h.has(t)&&f.has(t)?l.set(t,e):(l.set(t,e),h.has(t)&&f.add(t),s=!0))}s&&(d.push({departureTime:e,result:new Rt(new Set(i),p,this.stopsIndex,this.timetable)}),p=null)}return new yt(d,new Set(i))}}class wt{constructor(t){this.timetable=t}run(t,e){const n=new Set(e.origins);for(let r=1;r<=t.maxTransfers+1;r++){e.initRound(r);const s=e.graph[r],i=this.timetable.findReachableRoutes(n,t.transportModes);n.clear();for(const[s,o]of i)for(const i of this.scanRoute(s,o,r,e,t))n.add(i);let o=this.findTripContinuations(n,s);const a=new Set;for(;o.length>0;){a.clear();for(const t of o){const s=this.timetable.getRoute(t.routeId);for(const i of this.scanRouteContinuation(s,t.stopIndex,r,e,t))a.add(i),n.add(i)}o=this.findTripContinuations(a,s)}for(const s of this.considerTransfers(t,r,n,e))n.add(s);if(0===n.size)break}}findTripContinuations(t,e){const n=[];for(const r of t){const t=e[r];if(!t||!("routeId"in t))continue;const s=this.timetable.getContinuousTrips(t.hopOffStopIndex,t.routeId,t.tripIndex);for(const e of s)n.push({routeId:e.routeId,stopIndex:e.stopIndex,tripIndex:e.tripIndex,previousEdge:t})}return n}scanRouteContinuation(t,e,n,r,s){const i=new Set,o=r.graph[n],a=t.getNbStops(),u=t.id,c=s.tripIndex,d=t.tripStopOffset(c),l=s.previousEdge;for(let s=e;s<a;s++){const a=t.stops[s],h=t.arrivalAtOffset(s,d);1!==t.dropOffTypeAtOffset(s,d)&&h<r.improvementBound(n,a)&&h<r.destinationBest&&(o[a]={routeId:u,stopIndex:e,tripIndex:c,arrival:h,hopOffStopIndex:s,continuationOf:l},r.updateArrival(a,h,n),i.add(a))}return i}scanRoute(t,e,n,r,s){const i=new Set,o=r.graph[n],a=r.graph[n-1],u=t.getNbStops(),c=t.id;let d,l=e,h=0;for(let f=e;f<u;f++){const e=t.stops[f];if(void 0!==d){const s=t.arrivalAtOffset(f,h);1!==t.dropOffTypeAtOffset(f,h)&&s<r.improvementBound(n,e)&&s<r.destinationBest&&(o[e]={routeId:c,stopIndex:l,tripIndex:d,arrival:s,hopOffStopIndex:f},r.updateArrival(e,s,n),i.add(e))}const u=a[e],p=null==u?void 0:u.arrival;if(void 0!==p&&(void 0===d||p<=t.departureAtOffset(f,h))){const e=t.findEarliestTrip(f,p,d);if(void 0===e)continue;const r=u&&"routeId"in u?{stopIndex:u.hopOffStopIndex,routeId:u.routeId,tripIndex:u.tripIndex}:void 0,i=this.timetable.findFirstBoardableTrip(f,t,e,p,d,r,s.minTransferTime);if(void 0!==i){1===n&&void 0!==s.maxInitialWaitingTime&&t.departureFrom(f,i)-p>s.maxInitialWaitingTime||(d=i,l=f,h=t.tripStopOffset(i))}}}return i}considerTransfers(t,e,n,r){const s=new Set,i=r.graph[e];for(const o of n){const n=i[o];if(!n||"type"in n)continue;const a=this.timetable.getTransfers(o);for(const u of a){let a;a=u.minTransferTime?u.minTransferTime:"IN_SEAT"===u.type?0:t.minTransferTime;const c=n.arrival+a;c<r.improvementBound(e,u.destination)&&c<r.destinationBest&&(i[u.destination]={arrival:c,from:o,to:u.destination,minTransferTime:a||void 0,type:u.type},r.updateArrival(u.destination,c,e),s.add(u.destination))}}return s}}class Ut{constructor(t=[],e=Pt){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,i=e[s];if(n(r,i)>=0)break;e[t]=i,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),i=e[r];const o=r+1;if(o<this.length&&n(e[o],i)<0&&(r=o,i=e[o]),n(i,s)>=0)break;e[t]=i,t=r}e[t]=s}}function Pt(t,e){return t<e?-1:t>e?1:0}const xt=Math.PI/180;function Lt(t,e,n,r){const s=r.minLng,i=r.maxLng,o=r.minLat,a=r.maxLat;if(t>=s&&t<=i)return e<o?Yt((e-o)*xt):e>a?Yt((e-a)*xt):0;const u=Math.min(Yt((t-s)*xt),Yt((t-i)*xt)),c=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*xt)/n)/xt}(e,u);return c>o&&c<a?Mt(u,n,e,c):Math.min(Mt(u,n,e,o),Mt(u,n,e,a))}function Ct(t,e){return t.dist-e.dist}function Yt(t){const e=Math.sin(t/2);return e*e}function Mt(t,e,n,r){return e*Math.cos(r*xt)*t+Yt((n-r)*xt)}function Ft(t,e,n,r,s){return Mt(Yt((t-n)*xt),s,e,r)}const Dt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class kt{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=Dt[15&n];if(!s)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[o]=new Uint32Array(t,4,1);return new kt(o,i,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=Dt.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,o=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-o%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${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+o+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+o+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const 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 Bt(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:i,nodeSize:o}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,d=a.pop()||0,l=a.pop()||0;if(d-l<=o){for(let o=l;o<=d;o++){const a=i[2*o],c=i[2*o+1];a>=t&&a<=n&&c>=e&&c<=r&&u.push(s[o])}continue}const h=l+d>>1,f=i[2*h],p=i[2*h+1];f>=t&&f<=n&&p>=e&&p<=r&&u.push(s[h]),(0===c?t<=f:e<=p)&&(a.push(l),a.push(h-1),a.push(1-c)),(0===c?n>=f:r>=p)&&(a.push(h+1),a.push(d),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:s,nodeSize:i}=this,o=[0,r.length-1,0],a=[],u=n*n;for(;o.length;){const c=o.pop()||0,d=o.pop()||0,l=o.pop()||0;if(d-l<=i){for(let n=l;n<=d;n++)Vt(s[2*n],s[2*n+1],t,e)<=u&&a.push(r[n]);continue}const h=l+d>>1,f=s[2*h],p=s[2*h+1];Vt(f,p,t,e)<=u&&a.push(r[h]),(0===c?t-n<=f:e-n<=p)&&(o.push(l),o.push(h-1),o.push(1-c)),(0===c?t+n>=f:e+n>=p)&&(o.push(h+1),o.push(d),o.push(1-c))}return a}}function Bt(t,e,n,r,s,i){if(s-r<=n)return;const o=r+s>>1;$t(t,e,o,r,s,i),Bt(t,e,n,r,o-1,1-i),Bt(t,e,n,o+1,s,1-i)}function $t(t,e,n,r,s,i){for(;s>r;){if(s-r>600){const o=s-r+1,a=n-r+1,u=Math.log(o),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(o-c)/o)*(a-o/2<0?-1:1);$t(t,e,n,Math.max(r,Math.floor(n-a*c/o+d)),Math.min(s,Math.floor(n+(o-a)*c/o+d)),i)}const o=e[2*n+i];let a=r,u=s;for(jt(t,e,r,n),e[2*s+i]>o&&jt(t,e,r,s);a<u;){for(jt(t,e,a,u),a++,u--;e[2*a+i]<o;)a++;for(;e[2*u+i]>o;)u--}e[2*r+i]===o?jt(t,e,r,u):(u++,jt(t,e,u,s)),u<=n&&(r=u+1),n<=u&&(s=u-1)}}function jt(t,e,n,r){zt(t,n,r),zt(e,2*n,2*r),zt(e,2*n+1,2*r+1)}function zt(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function Vt(t,e,n,r){const s=t-n,i=e-r;return s*s+i*i}const Gt="KEYS",Jt="VALUES";class Wt{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}=Zt(this._path);if(""===Zt(e))return{done:!1,value:this.result()};const n=t.get(Zt(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Zt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Zt(t))).filter((t=>""!==t)).join("")}value(){return Zt(this._path).node.get("")}result(){switch(this._type){case Jt:return this.value();case Gt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Zt=t=>t[t.length-1],qt=(t,e,n,r,s,i,o,a)=>{const u=i*o;t:for(const c of t.keys())if(""===c){const e=s[u-1];e<=n&&r.set(a,[t.get(c),e])}else{let u=i;for(let t=0;t<c.length;++t,++u){const r=c[t],i=o*u,a=i-o;let d=s[i];const l=Math.max(0,u-n-1),h=Math.min(o-1,u+n);for(let t=l;t<h;++t){const n=r!==e[t],o=s[a+t]+ +n,u=s[a+t+1]+1,c=s[i+t]+1,l=s[i+t+1]=Math.min(o,u,c);l<d&&(d=l)}if(d>n)continue t}qt(t.get(c),e,n,r,s,u,o,a+c)}};class Qt{_tree;_prefix;_size=void 0;constructor(t=new Map,e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,n]=Xt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=re(n);for(const n of e.keys())if(""!==n&&n.startsWith(r)){const s=new Map;return s.set(n.slice(r.length),e.get(n)),new Qt(s,t)}}return new Qt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,te(this._tree,t)}entries(){return new Wt(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,i=s+n,o=new Uint8Array(i*s).fill(n+1);for(let t=0;t<s;++t)o[t]=t;for(let t=1;t<i;++t)o[t*s]=t;return qt(t,e,n,r,o,1,s,""),r})(this._tree,t,e)}get(t){const e=Ht(this._tree,t);return void 0!==e?e.get(""):void 0}has(t){return Ht(this._tree,t)?.has("")??!1}keys(){return new Wt(this,Gt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Kt(this._tree,t).set("",e),this}get size(){if(this._size)return this._size;this._size=0;const t=this.entries();for(;!t.next().done;)this._size+=1;return this._size}update(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Kt(this._tree,t);return n.set("",e(n.get(""))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Kt(this._tree,t);let r=n.get("");return void 0===r&&n.set("",r=e()),r}values(){return new Wt(this,Jt)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Qt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return Qt.from(Object.entries(t))}}const Xt=(t,e,n=[])=>{if(0===e.length||null==t)return[t,n];for(const r of t.keys())if(""!==r&&e.startsWith(r))return n.push([t,r]),Xt(t.get(r),e.slice(r.length),n);return n.push([t,e]),Xt(void 0,"",n)},Ht=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(""!==n&&e.startsWith(n))return Ht(t.get(n),e.slice(n.length))},Kt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const s of t.keys())if(""!==s&&e[r]===s[0]){const i=Math.min(n-r,s.length);let o=1;for(;o<i&&e[r+o]===s[o];)++o;const a=t.get(s);if(o===s.length)t=a;else{const n=new Map;n.set(s.slice(o),a),t.set(e.slice(r,r+o),n),t.delete(s),t=n}r+=o;continue t}const s=new Map;return t.set(e.slice(r),s),s}return t},te=(t,e)=>{const[n,r]=Xt(t,e);if(void 0!==n)if(n.delete(""),0===n.size)ee(r);else if(1===n.size){const[t,e]=n.entries().next().value;ne(r,t,e)}},ee=t=>{if(0===t.length)return;const[e,n]=re(t);if(e.delete(n),0===e.size)ee(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;""!==n&&ne(t.slice(0,-1),n,r)}},ne=(t,e,n)=>{if(0===t.length)return;const[r,s]=re(t);r.set(s+e,n),r.delete(s)},re=t=>t[t.length-1],se=/[\n\r\p{Z}\p{P}]+/u,ie="or",oe="and",ae="and_not",ue=(t,e)=>{t.includes(e)||t.push(e)},ce=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},de=({score:t},{score:e})=>e-t,le=()=>new Map,he=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,fe={[ie]:(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:i}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,i),ce(r.terms,s)}}return t},[oe]:(t,e)=>{const n=new Map;for(const r of e.keys()){const s=t.get(r);if(null==s)continue;const{score:i,terms:o,match:a}=e.get(r);ce(s.terms,o),n.set(r,{score:s.score+i,terms:s.terms,match:Object.assign(s.match,a)})}return n},[ae]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},pe=(t,e,n,r,s,i)=>{const{k:o,b:a,d:u}=i;return Math.log(1+(n-e+.5)/(e+.5))*(u+t*(o+1)/(t+o*(1-a+a*r/s)))},Te=(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")},Ee=(t,e,n,r)=>{const s=t._index.fetch(r,le);let i=s.get(e);if(null==i)i=new Map,i.set(n,1),s.set(e,i);else{const t=i.get(n);i.set(n,(t??0)+1)}},me=(t,e,n,r)=>{if(!t._index.has(r))return void Te(t,n,e,r);const s=t._index.fetch(r,le),i=s.get(e),o=i?.get(n);!i||typeof o>"u"?Te(t,n,e,r):o<=1?i.size<=1?s.delete(e):i.delete(n):i.set(n,o-1),0===t._index.get(r).size&&t._index.delete(r)},Ie=(t,e,n,r,s)=>{let i=t._fieldLength.get(e);null==i&&t._fieldLength.set(e,i=[]),i[n]=s;const o=(t._avgFieldLength[n]||0)*r+s;t._avgFieldLength[n]=o/(r+1)},_e=(t,e)=>{const{extractField:n,stringifyField:r,tokenize:s,processTerm:i,fields:o,idField:a}=t._options,u=n(e,a);if(null==u)throw new Error(`SlimSearch: document does not have ID field "${a}"`);if(((t,e)=>t._idToShortId.has(e))(t,u))throw new Error(`SlimSearch: duplicate ID ${u}`);const c=((t,e)=>{const n=t._nextId;return t._idToShortId.set(e,n),t._documentIds.set(n,e),t._documentCount+=1,t._nextId+=1,n})(t,u);((t,e,n)=>{const{storeFields:r,extractField:s}=t._options;if(0===r?.length)return;let i=t._storedFields.get(e);void 0===i&&t._storedFields.set(e,i={});for(const t of r){const e=s(n,t);null!=e&&(i[t]=e)}})(t,c,e);for(const a of o){const o=n(e,a);if(null==o)continue;const u=s(r(o,a),a),d=t._fieldIds[a],l=new Set(u).size;Ie(t,c,d,t._documentCount-1,l);for(const e of u){const n=i(e,a);if(Array.isArray(n))for(const e of n)Ee(t,d,c,e);else n&&Ee(t,d,c,n)}}},ge={idField:"id",extractField:(t,e)=>t[e],stringifyField:t=>t.toString(),tokenize:t=>t.split(se),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},Re={combineWith:ie,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},Ae={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},ve={minDirtFactor:.1,minDirtCount:20},Oe={batchSize:1e3,batchWait:10,...ve},Se=Symbol("*"),ye=(t,e=ie)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in fe))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(fe[n])},Ne=(t,e,n,r,s,i,o,a,u,c=new Map)=>{if(null==i)return c;for(const d of Object.keys(o)){const l=o[d],h=t._fieldIds[d],f=i.get(h);if(null==f)continue;let p=f.size;const T=t._avgFieldLength[h];for(const i of f.keys()){if(!t._documentIds.has(i)){me(t,h,i,n),p-=1;continue}const o=a?a(t._documentIds.get(i),n,t._storedFields.get(i)):1;if(!o)continue;const E=f.get(i),m=t._fieldLength.get(i)[h],I=r*s*l*o*pe(E,p,t._documentCount,m,T,u),_=c.get(i);if(_){_.score+=I,ue(_.terms,e);const t=he(_.match,n);t?t.push(d):_.match[n]=[d]}else c.set(i,{score:I,terms:[e],match:{[n]:[d]}})}}return c},be=(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 i=r.boostDocument?r.boostDocument(s,"",t._storedFields.get(e)):1;n.set(e,{score:i,terms:[],match:{}})}return n})(t,n);if("string"!=typeof e){const r={...n,...e,queries:void 0},s=e.queries.map((e=>be(t,e,r)));return ye(s,r.combineWith)}const{tokenize:r,processTerm:s,searchOptions:i}=t._options,o={tokenize:r,processTerm:s,...i,...n},{tokenize:a,processTerm:u}=o,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,n,r)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,n,r):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,n,r):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,n,r):1}))(o)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},s=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:he(r.boost,e)||1})),{}),{boostDocument:i,weights:o,maxFuzzy:a,bm25:u}=r,{fuzzy:c,prefix:d}={...Re.weights,...o},l=t._index.get(e.term),h=Ne(t,e.term,e.term,1,e.termBoost,l,s,i,u);let f,p;if(e.prefix&&(f=t._index.atPrefix(e.term)),e.fuzzy){const n=!0===e.fuzzy?.2:e.fuzzy,r=n<1?Math.min(a,Math.round(e.term.length*n)):n;r&&(p=t._index.fuzzyGet(e.term,r))}if(f)for(const[n,r]of f){const o=n.length-e.term.length;if(!o)continue;p?.delete(n);const a=d*n.length/(n.length+.3*o);Ne(t,e.term,n,a,e.termBoost,r,s,i,u,h)}if(p)for(const n of p.keys()){const[r,o]=p.get(n);if(!o)continue;const a=c*n.length/(n.length+o);Ne(t,e.term,n,a,e.termBoost,r,s,i,u,h)}return h})(t,e,o)));return ye(c,o.combineWith)};class we{_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?Oe:t.autoVacuum;this._options={...ge,...t,autoVacuum:e,searchOptions:{...Re,...t.searchOptions},autoSuggestOptions:{...Ae,...t.autoSuggestOptions}},this._index=new Qt,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=ve,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 Pe;function xe(t){switch(t){case 0:case"LOCATION_TYPE_UNSPECIFIED":return Pe.LOCATION_TYPE_UNSPECIFIED;case 1:case"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM":return Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case 2:case"LOCATION_TYPE_STATION":return Pe.LOCATION_TYPE_STATION;case 3:case"LOCATION_TYPE_ENTRANCE_EXIT":return Pe.LOCATION_TYPE_ENTRANCE_EXIT;case 4:case"LOCATION_TYPE_GENERIC_NODE":return Pe.LOCATION_TYPE_GENERIC_NODE;case 5:case"LOCATION_TYPE_BOARDING_AREA":return Pe.LOCATION_TYPE_BOARDING_AREA;default:return Pe.UNRECOGNIZED}}!function(t){t[t.LOCATION_TYPE_UNSPECIFIED=0]="LOCATION_TYPE_UNSPECIFIED",t[t.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM=1]="LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM",t[t.LOCATION_TYPE_STATION=2]="LOCATION_TYPE_STATION",t[t.LOCATION_TYPE_ENTRANCE_EXIT=3]="LOCATION_TYPE_ENTRANCE_EXIT",t[t.LOCATION_TYPE_GENERIC_NODE=4]="LOCATION_TYPE_GENERIC_NODE",t[t.LOCATION_TYPE_BOARDING_AREA=5]="LOCATION_TYPE_BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Pe||(Pe={}));const Le={encode(t,e=new N){""!==t.name&&e.uint32(10).string(t.name),void 0!==t.sourceStopId&&e.uint32(18).string(t.sourceStopId),void 0!==t.lat&&e.uint32(29).float(t.lat),void 0!==t.lon&&e.uint32(37).float(t.lon),e.uint32(42).fork();for(const n of t.children)e.uint32(n);return e.join(),void 0!==t.parent&&e.uint32(48).uint32(t.parent),0!==t.locationType&&e.uint32(56).int32(t.locationType),void 0!==t.platform&&e.uint32(66).string(t.platform),e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={name:"",sourceStopId:void 0,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(18!==t)break;s.sourceStopId=n.string();continue;case 3:if(29!==t)break;s.lat=n.float();continue;case 4:if(37!==t)break;s.lon=n.float();continue;case 5:if(40===t){s.children.push(n.uint32());continue}if(42===t){const t=n.uint32()+n.pos;for(;n.pos<t;)s.children.push(n.uint32());continue}break;case 6:if(48!==t)break;s.parent=n.uint32();continue;case 7:if(56!==t)break;s.locationType=n.int32();continue;case 8:if(66!==t)break;s.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({name:Ye(t.name)?globalThis.String(t.name):"",sourceStopId:Ye(t.sourceStopId)?globalThis.String(t.sourceStopId):void 0,lat:Ye(t.lat)?globalThis.Number(t.lat):void 0,lon:Ye(t.lon)?globalThis.Number(t.lon):void 0,children:globalThis.Array.isArray(null==t?void 0:t.children)?t.children.map((t=>globalThis.Number(t))):[],parent:Ye(t.parent)?globalThis.Number(t.parent):void 0,locationType:Ye(t.locationType)?xe(t.locationType):0,platform:Ye(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const n={};return""!==t.name&&(n.name=t.name),void 0!==t.sourceStopId&&(n.sourceStopId=t.sourceStopId),void 0!==t.lat&&(n.lat=t.lat),void 0!==t.lon&&(n.lon=t.lon),(null===(e=t.children)||void 0===e?void 0:e.length)&&(n.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(n.parent=Math.round(t.parent)),0!==t.locationType&&(n.locationType=function(t){switch(t){case Pe.LOCATION_TYPE_UNSPECIFIED:return"LOCATION_TYPE_UNSPECIFIED";case Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM";case Pe.LOCATION_TYPE_STATION:return"LOCATION_TYPE_STATION";case Pe.LOCATION_TYPE_ENTRANCE_EXIT:return"LOCATION_TYPE_ENTRANCE_EXIT";case Pe.LOCATION_TYPE_GENERIC_NODE:return"LOCATION_TYPE_GENERIC_NODE";case Pe.LOCATION_TYPE_BOARDING_AREA:return"LOCATION_TYPE_BOARDING_AREA";case Pe.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>Le.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s,i,o,a,u;const c={name:"",sourceStopId:void 0,lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};return c.name=null!==(e=t.name)&&void 0!==e?e:"",c.sourceStopId=null!==(n=t.sourceStopId)&&void 0!==n?n:void 0,c.lat=null!==(r=t.lat)&&void 0!==r?r:void 0,c.lon=null!==(s=t.lon)&&void 0!==s?s:void 0,c.children=(null===(i=t.children)||void 0===i?void 0:i.map((t=>t)))||[],c.parent=null!==(o=t.parent)&&void 0!==o?o:void 0,c.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,c.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,c}};const Ce={encode(t,e=new N){for(const n of t.stops)Le.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={stops:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 2:if(18!==t)break;s.stops.push(Le.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>Le.fromJSON(t))):[]}),toJSON(t){var e;const n={};return(null===(e=t.stops)||void 0===e?void 0:e.length)&&(n.stops=t.stops.map((t=>Le.toJSON(t)))),n},create:t=>Ce.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={stops:[]};return n.stops=(null===(e=t.stops)||void 0===e?void 0:e.map((t=>Le.fromPartial(t))))||[],n}};function Ye(t){return null!=t}const Me=t=>({stops:t.map((t=>{return{name:(e=t).name,sourceStopId:e.sourceStopId,lat:e.lat,lon:e.lon,children:e.children,parent:e.parent,locationType:ke(e.locationType),platform:e.platform};var e}))}),Fe=t=>t.stops.map(((t,e)=>{return{id:e,sourceStopId:(n=t).sourceStopId,name:n.name,lat:n.lat,lon:n.lon,children:n.children,parent:n.parent,locationType:De(n.locationType),platform:n.platform};var n})),De=t=>{switch(t){case Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Pe.LOCATION_TYPE_STATION:return"STATION";case Pe.LOCATION_TYPE_ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Pe.LOCATION_TYPE_GENERIC_NODE:return"GENERIC_NODE";case Pe.LOCATION_TYPE_BOARDING_AREA:return"BOARDING_AREA";case Pe.LOCATION_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf location type.");case Pe.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},ke=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case"STATION":return Pe.LOCATION_TYPE_STATION;case"ENTRANCE_EXIT":return Pe.LOCATION_TYPE_ENTRANCE_EXIT;case"GENERIC_NODE":return Pe.LOCATION_TYPE_GENERIC_NODE;case"BOARDING_AREA":return Pe.LOCATION_TYPE_BOARDING_AREA}};class Be{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const n=new Map;this.stopPoints=[];for(let r=0;r<t.length;r++){const s=t[r];void 0!==s.sourceStopId&&this.sourceStopsMap.set(s.sourceStopId,r);const i=null!==(e=s.parent)&&void 0!==e?e:r;n.has(i)||n.set(i,{id:i,name:s.parent?this.stops[s.parent].name:s.name}),s.lat&&s.lon&&this.stopPoints.push({id:r,lat:s.lat,lon:s.lon})}this.textIndex=new we({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:Ue});const r=Array.from(n.values());((t,e)=>{for(const n of e)_e(t,n)})(this.textIndex,r),this.geoIndex=new kt(this.stopPoints.length);for(let t=0;t<this.stopPoints.length;t++){const{lat:e,lon:n}=this.stopPoints[t];this.geoIndex.add(n,e)}this.geoIndex.finish()}static fromData(t){const e=new b(t),n=Ce.decode(e);return new Be(Fe(n))}serialize(){const t=Me(this.stops),e=new N;return Ce.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,s={...r,...n},i=be(t,e,n),o=[];for(const[e,{score:n,terms:r,match:a}]of i){const i=r.length||1,u={id:t._documentIds.get(e),score:n*i,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(u,t._storedFields.get(e)),(null==s.filter||s.filter(u))&&o.push(u)}return e===Se&&null==s.boostDocument||o.sort(de),o})(this.textIndex,t).map((t=>this.stops[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 i=1;const o=[];void 0===r&&(r=1/0),void 0!==s&&(i=Yt(s/6371));const a=new Ut([],Ct);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(n*xt);for(;u;){const s=u.right,d=u.left;if(s-d<=t.nodeSize)for(let r=d;r<=s;r++){const s=t.ids[r];{const i=Ft(e,n,t.coords[2*r],t.coords[2*r+1],c);a.push({id:s,dist:i})}}else{const r=d+s>>1,i=t.coords[2*r],o=t.coords[2*r+1],l=t.ids[r];{const t=Ft(e,n,i,o,c);a.push({id:l,dist:t})}const h=(u.axis+1)%2,f={left:d,right:r-1,axis:h,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?i:u.maxLng,maxLat:1===u.axis?o:u.maxLat,dist:0},p={left:r+1,right:s,axis:h,minLng:0===u.axis?i:u.minLng,minLat:1===u.axis?o:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};f.dist=Lt(e,n,c,f),p.dist=Lt(e,n,c,p),a.push(f),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>i)return o;if(o.push(t.id),o.length===r)return o}u=a.pop()}return o}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return s}findStopById(t){return this.stops[t]}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,n;const r=this.stops[t];if(!r)return[];const s=r.parent?null!==(n=null===(e=this.stops[r.parent])||void 0===e?void 0:e.children)&&void 0!==n?n:[]:r.children;return Array.from(new Set([t,...s])).map((t=>this.stops[t]))}*[Symbol.iterator](){for(const t of this.stops)yield t}}t.Plotter=class{constructor(t){this.result=t}stationNodeId(t){return`s_${t}`}vehicleEdgeNodeId(t,e,n,r){return`e_${t}_${e}_${n}_${r}`}transferEdgeNodeId(t,e,n){return`e_${t}_${e}_${n}`}accessEdgeNodeId(t,e){return`access_${t}_${e}`}continuationNodeId(t,e,n){return`continuation_${t}_${e}_${n}`}getRoundColor(t){var e;if(0===t)return r.colors.defaultRound;const n=Math.min(t-1,r.colors.rounds.length-1);return null!==(e=r.colors.rounds[n])&&void 0!==e?e:"#ee82ee"}getStationFillColor(t,e){return t?r.colors.originStation:e?r.colors.destinationStation:r.colors.defaultStation}escapeDotString(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}formatStopName(t){const e=this.result.stopsIndex.findStopById(t);if(!e)return`Unknown Stop (${t})`;const n=this.escapeDotString(e.name),r=e.platform?this.escapeDotString(e.platform):"";return r?`${n}\\nPl. ${r}`:n}getStationInfo(t){var e;return{isOrigin:void 0!==(null===(e=this.result.routingState.graph[0])||void 0===e?void 0:e[t]),isDestination:this.result.routingState.destinations.includes(t)}}getVehicleEdgeFromStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.stopIndex)}getVehicleEdgeToStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.hopOffStopIndex)}createStationNode(t){if(!this.result.stopsIndex.findStopById(t))return null;const e=this.formatStopName(t),n=this.escapeDotString(String(t)),r=this.stationNodeId(t),s=this.getStationInfo(t);return` "${r}" [label="${e}\\n${n}" shape=box style=filled fillcolor="${this.getStationFillColor(s.isOrigin,s.isDestination)}"];`}createVehicleEdge(t,n){const r=this.result.timetable.getRoute(t.routeId);if(!r)return[];const s=r.stopId(t.stopIndex),i=r.stopId(t.hopOffStopIndex),o=this.stationNodeId(s),a=this.stationNodeId(i),u=this.getRoundColor(n),c=this.vehicleEdgeNodeId(s,i,t.routeId,n),d=this.result.timetable.getServiceRouteInfo(r),l=d.name,h=d.type,f=e(r.departureFrom(t.stopIndex,t.tripIndex)),p=e(t.arrival),T=this.escapeDotString(l);return[` "${c}" [label="${`${this.escapeDotString(h)} ${T}\\n${`${t.routeId}:${t.tripIndex}`}\\n${f} → ${p}`}" shape=oval style=filled fillcolor="white" color="${u}"];`,` "${o}" -> "${c}" [color="${u}"];`,` "${c}" -> "${a}" [color="${u}"];`]}createAccessEdge(t){const e=this.stationNodeId(t.from),s=this.stationNodeId(t.to),i=r.colors.defaultRound,o=this.accessEdgeNodeId(t.from,t.to);return[` "${o}" [label="${`Walk\\n${n(t.duration)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${i}"];`,` "${e}" -> "${o}" [color="${i}" style="dashed"];`,` "${o}" -> "${s}" [color="${i}" style="dashed"];`]}createTransferEdge(t,e){const r=this.stationNodeId(t.from),s=this.stationNodeId(t.to),i=this.getRoundColor(e),o=this.transferEdgeNodeId(t.from,t.to,e),a=void 0!==t.minTransferTime?n(t.minTransferTime):"N/A";return[` "${o}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${i}"];`,` "${r}" -> "${o}" [color="${i}" style="dashed"];`,` "${o}" -> "${s}" [color="${i}" style="dashed"];`]}createContinuationEdge(t,n,s){var i,o;const a=this.getVehicleEdgeToStopId(t),u=this.getVehicleEdgeFromStopId(n);if(!a||!u)return[];const c=this.stationNodeId(a),d=this.stationNodeId(u),l=this.getRoundColor(s),h=this.continuationNodeId(a,u,s),f=this.result.timetable.getRoute(t.routeId),p=this.result.timetable.getRoute(n.routeId),T=f?this.result.timetable.getServiceRouteInfo(f):null,E=p?this.result.timetable.getServiceRouteInfo(p):null,m=null!==(i=null==T?void 0:T.name)&&void 0!==i?i:`Route ${String(t.routeId)}`,I=null!==(o=null==E?void 0:E.name)&&void 0!==o?o:`Route ${String(n.routeId)}`,_=(null==T?void 0:T.type)||"UNKNOWN",g=(null==E?void 0:E.type)||"UNKNOWN",R=e(t.arrival),A=p?e(p.departureFrom(n.stopIndex,n.tripIndex)):"N/A",v=this.escapeDotString(m),O=this.escapeDotString(I),S=this.escapeDotString(_),y=this.escapeDotString(g),N=`${S} ${v} (${`${t.routeId}:${t.tripIndex}`}) ${R}\\n↓\\n${y} ${O} (${`${n.routeId}:${n.tripIndex}`}) ${A}`,{continuationFill:b}=r.colors,{continuation:w,continuationEdge:U}=r.penWidth;return[` "${h}" [label="${N}" shape=oval style="filled,bold" fillcolor="${b}" color="${l}" penwidth="${w}"];`,` "${c}" -> "${h}" [color="${l}" style="bold" penwidth="${U}"];`,` "${h}" -> "${d}" [color="${l}" style="bold" penwidth="${U}"];`]}collectStations(){const t=new Set,e=this.result.routingState.graph;for(const n of e)for(let e=0;e<n.length;e++){const r=n[e];if(void 0!==r)if(t.add(e),s(r)){const e=this.getVehicleEdgeFromStopId(r),n=this.getVehicleEdgeToStopId(r);e&&t.add(e),n&&t.add(n)}else o(r)&&(t.add(r.from),t.add(r.to))}return t}collectContinuationChain(t,e){const n=[];let r=t,s=t.continuationOf;for(;s;){const t=this.createContinuationEdge(s,r,e);n.push(...t),r=s,s=s.continuationOf}return n}collectEdges(){const t=[],e=[],n=this.result.routingState.graph;for(let r=0;r<n.length;r++){const a=n[r];if(a)for(let n=0;n<a.length;n++){const u=a[n];void 0!==u&&(0!==r?s(u)?(t.push(...this.createVehicleEdge(u,r)),u.continuationOf&&e.push(...this.collectContinuationChain(u,r))):i(u)&&t.push(...this.createTransferEdge(u,r)):o(u)&&t.push(...this.createAccessEdge(u)))}}return[...t,...e]}plotDotGraph(){const t=this.collectStations(),e=this.collectEdges(),n=new a;n.addHeader(),n.addComment("Stations");for(const e of t){const t=this.createStationNode(e);t&&n.addRaw([t])}return n.addComment("Edges"),n.addRaw(e),n.build()}},t.Query=Et,t.RangeQuery=mt,t.RangeResult=yt,t.Result=Rt,t.Route=It,t.Router=class{constructor(t,e){const n=new wt(t),r=new At(t,e);this.plainRouter=new St(t,e,r,n),this.rangeRouter=new bt(t,e,r,n)}route(t){return this.plainRouter.route(t)}rangeRoute(t){return this.rangeRouter.rangeRoute(t)}},t.StopsIndex=Be,t.Timetable=Tt}));
|
|
1
|
+
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).minotor={})}(this,(function(t){"use strict";const e=t=>{let e=Math.floor(t/60);const n=Math.floor(t%60);return e>=24&&(e%=24),`${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`},n=t=>{const e=Math.floor(t/60),n=t%60;return e>0?`${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`:`${n}min`},r={colors:{rounds:["#60a5fa","#ff9800","#14b8a6","#fb7185","#ffdf00","#b600ff","#ee82ee"],defaultRound:"#888888",originStation:"#60a5fa",destinationStation:"#ee82ee",defaultStation:"white",continuationFill:"#ffffcc"},penWidth:{continuation:2,continuationEdge:3}};function s(t){return"routeId"in t&&"stopIndex"in t&&"hopOffStopIndex"in t}function i(t){return"from"in t&&"to"in t&&"type"in t}function o(t){return"from"in t&&"duration"in t}class a{constructor(){this.lines=[]}addHeader(){return this.lines.push("digraph RoutingGraph {"," graph [overlap=false, splines=true, rankdir=TB, bgcolor=white, nodesep=0.8, ranksep=1.2, concentrate=true];",' node [fontname="Arial" margin=0.1];',' edge [fontname="Arial" fontsize=10];'),this}addComment(t){return this.lines.push("",` // ${t}`),this}addNode(t,e){const n=Object.entries(e).map((([t,e])=>`${t}="${e}"`)).join(" ");return this.lines.push(` "${t}" [${n}];`),this}addEdge(t,e,n={}){const r=Object.entries(n).map((([t,e])=>`${t}="${e}"`)).join(" "),s=r?` [${r}]`:"";return this.lines.push(` "${t}" -> "${e}"${s};`),this}addRaw(t){return this.lines.push(...t),this}build(){return this.lines.push("}"),this.lines.join("\n")}}function u(){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 c(t,e,n){for(let r=0;r<28;r+=7){const s=t>>>r,i=!(s>>>7==0&&0==e),o=255&(i?128|s:s);if(n.push(o),!i)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),i=255&(s?128|r:r);if(n.push(i),!s)return}n.push(e>>>31&1)}}const d=4294967296;function l(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let r=0,s=0;function i(e,i){const o=Number(t.slice(e,i));s*=n,r=r*n+o,r>=d&&(s+=r/d|0,r%=d)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?p(r,s):f(r,s)}function h(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(d*e+t);const n=16777215&(t>>>24|e<<8),r=e>>16&65535;let s=(16777215&t)+6777216*n+6710656*r,i=n+8147497*r,o=2*r;const a=1e7;return s>=a&&(i+=Math.floor(s/a),s%=a),i>=a&&(o+=Math.floor(i/a),i%=a),o.toString()+T(i)+T(s)}function f(t,e){return{lo:0|t,hi:0|e}}function p(t,e){return e=~e,t?t=1+~t:e+=1,f(t,e)}const T=t=>{const e=String(t);return"0000000".slice(e.length)+e};function E(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 m(){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 I=_();function _(){const t=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof t.getBigInt64&&"function"==typeof t.getBigUint64&&"function"==typeof t.setBigInt64&&"function"==typeof t.setBigUint64&&(!!globalThis.Deno||"object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const e=BigInt("-9223372036854775808"),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()),g(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),R(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),g(t),l(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),R(t),l(t)),dec:(t,e)=>function(t,e){let n=f(t,e);const r=2147483648&n.hi;r&&(n=p(n.lo,n.hi));const s=h(n.lo,n.hi);return r?"-"+s:s}(t,e),uDec:(t,e)=>h(t,e)}}function g(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function R(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const A=Symbol.for("@bufbuild/protobuf/text-encoding");function v(){if(null==globalThis[A]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[A]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[A]}var O;!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"}(O||(O={}));const S=34028234663852886e22,y=-34028234663852886e22;class N{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(U(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return w(t),E(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.encodeUtf8(t);return this.uint32(e.byteLength),this.raw(e)}float(t){!function(t){if("string"==typeof t){const e=t;if(t=Number(t),Number.isNaN(t)&&"NaN"!==e)throw new Error("invalid float32: "+e)}else if("number"!=typeof t)throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>S||t<y))throw new Error("invalid float32: "+t)}(t);let e=new Uint8Array(4);return new DataView(e.buffer).setFloat32(0,t,!0),this.raw(e)}double(t){let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t,!0),this.raw(e)}fixed32(t){U(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){w(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return w(t),E(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=I.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=I.uEnc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(e)}int64(t){let e=I.enc(t);return c(e.lo,e.hi,this.buf),this}sint64(t){const e=I.enc(t),n=e.hi>>31;return c(e.lo<<1^n,(e.hi<<1|e.lo>>>31)^n,this.buf),this}uint64(t){const e=I.uEnc(t);return c(e.lo,e.hi,this.buf),this}}class b{constructor(t,e=v().decodeUtf8){this.decodeUtf8=e,this.varint64=u,this.uint32=m,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 O.Varint:for(;128&this.buf[this.pos++];);break;case O.Bit64:this.pos+=4;case O.Bit32:this.pos+=4;break;case O.LengthDelimited:let n=this.uint32();this.pos+=n;break;case O.StartGroup:for(;;){const[t,n]=this.tag();if(n===O.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 I.dec(...this.varint64())}uint64(){return I.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),n=-(1&t);return t=(t>>>1|(1&e)<<31)^n,e=e>>>1^n,I.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 I.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return I.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 w(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 U(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 P,x;function L(t){switch(t){case 0:case"TRANSFER_TYPE_UNSPECIFIED":return P.TRANSFER_TYPE_UNSPECIFIED;case 1:case"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT":return P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case 2:case"TRANSFER_TYPE_TIMED_TRANSFER":return P.TRANSFER_TYPE_TIMED_TRANSFER;case 3:case"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME":return P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case 4:case"TRANSFER_TYPE_IN_SEAT_TRANSFER":return P.TRANSFER_TYPE_IN_SEAT_TRANSFER;default:return P.UNRECOGNIZED}}function C(t){switch(t){case 0:case"ROUTE_TYPE_UNSPECIFIED":return x.ROUTE_TYPE_UNSPECIFIED;case 1:case"ROUTE_TYPE_TRAM":return x.ROUTE_TYPE_TRAM;case 2:case"ROUTE_TYPE_SUBWAY":return x.ROUTE_TYPE_SUBWAY;case 3:case"ROUTE_TYPE_RAIL":return x.ROUTE_TYPE_RAIL;case 4:case"ROUTE_TYPE_BUS":return x.ROUTE_TYPE_BUS;case 5:case"ROUTE_TYPE_FERRY":return x.ROUTE_TYPE_FERRY;case 6:case"ROUTE_TYPE_CABLE_TRAM":return x.ROUTE_TYPE_CABLE_TRAM;case 7:case"ROUTE_TYPE_AERIAL_LIFT":return x.ROUTE_TYPE_AERIAL_LIFT;case 8:case"ROUTE_TYPE_FUNICULAR":return x.ROUTE_TYPE_FUNICULAR;case 9:case"ROUTE_TYPE_TROLLEYBUS":return x.ROUTE_TYPE_TROLLEYBUS;case 10:case"ROUTE_TYPE_MONORAIL":return x.ROUTE_TYPE_MONORAIL;default:return x.UNRECOGNIZED}}function Y(){return{stopTimes:new Uint8Array(0),pickupDropOffTypes:new Uint8Array(0),stops:new Uint8Array(0),serviceRouteId:0}}!function(t){t[t.TRANSFER_TYPE_UNSPECIFIED=0]="TRANSFER_TYPE_UNSPECIFIED",t[t.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT=1]="TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT",t[t.TRANSFER_TYPE_TIMED_TRANSFER=2]="TRANSFER_TYPE_TIMED_TRANSFER",t[t.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME=3]="TRANSFER_TYPE_REQUIRES_MINIMAL_TIME",t[t.TRANSFER_TYPE_IN_SEAT_TRANSFER=4]="TRANSFER_TYPE_IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(P||(P={})),function(t){t[t.ROUTE_TYPE_UNSPECIFIED=0]="ROUTE_TYPE_UNSPECIFIED",t[t.ROUTE_TYPE_TRAM=1]="ROUTE_TYPE_TRAM",t[t.ROUTE_TYPE_SUBWAY=2]="ROUTE_TYPE_SUBWAY",t[t.ROUTE_TYPE_RAIL=3]="ROUTE_TYPE_RAIL",t[t.ROUTE_TYPE_BUS=4]="ROUTE_TYPE_BUS",t[t.ROUTE_TYPE_FERRY=5]="ROUTE_TYPE_FERRY",t[t.ROUTE_TYPE_CABLE_TRAM=6]="ROUTE_TYPE_CABLE_TRAM",t[t.ROUTE_TYPE_AERIAL_LIFT=7]="ROUTE_TYPE_AERIAL_LIFT",t[t.ROUTE_TYPE_FUNICULAR=8]="ROUTE_TYPE_FUNICULAR",t[t.ROUTE_TYPE_TROLLEYBUS=9]="ROUTE_TYPE_TROLLEYBUS",t[t.ROUTE_TYPE_MONORAIL=10]="ROUTE_TYPE_MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(x||(x={}));const M={encode:(t,e=new N)=>(0!==t.stopTimes.length&&e.uint32(10).bytes(t.stopTimes),0!==t.pickupDropOffTypes.length&&e.uint32(18).bytes(t.pickupDropOffTypes),0!==t.stops.length&&e.uint32(26).bytes(t.stops),0!==t.serviceRouteId&&e.uint32(32).uint32(t.serviceRouteId),e),decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s=Y();for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopTimes=n.bytes();continue;case 2:if(18!==t)break;s.pickupDropOffTypes=n.bytes();continue;case 3:if(26!==t)break;s.stops=n.bytes();continue;case 4:if(32!==t)break;s.serviceRouteId=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopTimes:G(t.stopTimes)?z(t.stopTimes):new Uint8Array(0),pickupDropOffTypes:G(t.pickupDropOffTypes)?z(t.pickupDropOffTypes):new Uint8Array(0),stops:G(t.stops)?z(t.stops):new Uint8Array(0),serviceRouteId:G(t.serviceRouteId)?globalThis.Number(t.serviceRouteId):0}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=V(t.stopTimes)),0!==t.pickupDropOffTypes.length&&(e.pickupDropOffTypes=V(t.pickupDropOffTypes)),0!==t.stops.length&&(e.stops=V(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s;const i=Y();return i.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),i.pickupDropOffTypes=null!==(n=t.pickupDropOffTypes)&&void 0!==n?n:new Uint8Array(0),i.stops=null!==(r=t.stops)&&void 0!==r?r:new Uint8Array(0),i.serviceRouteId=null!==(s=t.serviceRouteId)&&void 0!==s?s:0,i}};const F={encode:(t,e=new N)=>(0!==t.destination&&e.uint32(8).uint32(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).uint32(t.minTransferTime),e),decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={destination:0,type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.destination=n.uint32();continue;case 2:if(16!==t)break;s.type=n.int32();continue;case 3:if(24!==t)break;s.minTransferTime=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({destination:G(t.destination)?globalThis.Number(t.destination):0,type:G(t.type)?L(t.type):0,minTransferTime:G(t.minTransferTime)?globalThis.Number(t.minTransferTime):void 0}),toJSON(t){const e={};return 0!==t.destination&&(e.destination=Math.round(t.destination)),0!==t.type&&(e.type=function(t){switch(t){case P.TRANSFER_TYPE_UNSPECIFIED:return"TRANSFER_TYPE_UNSPECIFIED";case P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT";case P.TRANSFER_TYPE_TIMED_TRANSFER:return"TRANSFER_TYPE_TIMED_TRANSFER";case P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME";case P.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"TRANSFER_TYPE_IN_SEAT_TRANSFER";case P.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={destination:0,type:0,minTransferTime:void 0};return s.destination=null!==(e=t.destination)&&void 0!==e?e:0,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 D={encode:(t,e=new N)=>(0!==t.stopIndex&&e.uint32(8).uint32(t.stopIndex),0!==t.routeId&&e.uint32(16).uint32(t.routeId),0!==t.tripIndex&&e.uint32(24).uint32(t.tripIndex),e),decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={stopIndex:0,routeId:0,tripIndex:0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.stopIndex=n.uint32();continue;case 2:if(16!==t)break;s.routeId=n.uint32();continue;case 3:if(24!==t)break;s.tripIndex=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopIndex:G(t.stopIndex)?globalThis.Number(t.stopIndex):0,routeId:G(t.routeId)?globalThis.Number(t.routeId):0,tripIndex:G(t.tripIndex)?globalThis.Number(t.tripIndex):0}),toJSON(t){const e={};return 0!==t.stopIndex&&(e.stopIndex=Math.round(t.stopIndex)),0!==t.routeId&&(e.routeId=Math.round(t.routeId)),0!==t.tripIndex&&(e.tripIndex=Math.round(t.tripIndex)),e},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={stopIndex:0,routeId:0,tripIndex:0};return s.stopIndex=null!==(e=t.stopIndex)&&void 0!==e?e:0,s.routeId=null!==(n=t.routeId)&&void 0!==n?n:0,s.tripIndex=null!==(r=t.tripIndex)&&void 0!==r?r:0,s}};const k={encode(t,e=new N){void 0!==t.origin&&D.encode(t.origin,e.uint32(10).fork()).join();for(const n of t.destinations)D.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={origin:void 0,destinations:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.origin=D.decode(n,n.uint32());continue;case 2:if(18!==t)break;s.destinations.push(D.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({origin:G(t.origin)?D.fromJSON(t.origin):void 0,destinations:globalThis.Array.isArray(null==t?void 0:t.destinations)?t.destinations.map((t=>D.fromJSON(t))):[]}),toJSON(t){var e;const n={};return void 0!==t.origin&&(n.origin=D.toJSON(t.origin)),(null===(e=t.destinations)||void 0===e?void 0:e.length)&&(n.destinations=t.destinations.map((t=>D.toJSON(t)))),n},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={origin:void 0,destinations:[]};return n.origin=void 0!==t.origin&&null!==t.origin?D.fromPartial(t.origin):void 0,n.destinations=(null===(e=t.destinations)||void 0===e?void 0:e.map((t=>D.fromPartial(t))))||[],n}};const B={encode(t,e=new N){e.uint32(10).fork();for(const n of t.routes)e.uint32(n);e.join();for(const n of t.transfers)F.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={routes:[],transfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8===t){s.routes.push(n.uint32());continue}if(10===t){const t=n.uint32()+n.pos;for(;n.pos<t;)s.routes.push(n.uint32());continue}break;case 2:if(18!==t)break;s.transfers.push(F.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[],transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>F.fromJSON(t))):[]}),toJSON(t){var e,n;const r={};return(null===(e=t.routes)||void 0===e?void 0:e.length)&&(r.routes=t.routes.map((t=>Math.round(t)))),(null===(n=t.transfers)||void 0===n?void 0:n.length)&&(r.transfers=t.transfers.map((t=>F.toJSON(t)))),r},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={routes:[],transfers:[]};return r.routes=(null===(e=t.routes)||void 0===e?void 0:e.map((t=>t)))||[],r.transfers=(null===(n=t.transfers)||void 0===n?void 0:n.map((t=>F.fromPartial(t))))||[],r}};const $={encode(t,e=new N){0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e.uint32(26).fork();for(const n of t.routes)e.uint32(n);return e.join(),e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={type:0,name:"",routes:[]};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;case 3:if(24===t){s.routes.push(n.uint32());continue}if(26===t){const t=n.uint32()+n.pos;for(;n.pos<t;)s.routes.push(n.uint32());continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({type:G(t.type)?C(t.type):0,name:G(t.name)?globalThis.String(t.name):"",routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[]}),toJSON(t){var e;const n={};return 0!==t.type&&(n.type=function(t){switch(t){case x.ROUTE_TYPE_UNSPECIFIED:return"ROUTE_TYPE_UNSPECIFIED";case x.ROUTE_TYPE_TRAM:return"ROUTE_TYPE_TRAM";case x.ROUTE_TYPE_SUBWAY:return"ROUTE_TYPE_SUBWAY";case x.ROUTE_TYPE_RAIL:return"ROUTE_TYPE_RAIL";case x.ROUTE_TYPE_BUS:return"ROUTE_TYPE_BUS";case x.ROUTE_TYPE_FERRY:return"ROUTE_TYPE_FERRY";case x.ROUTE_TYPE_CABLE_TRAM:return"ROUTE_TYPE_CABLE_TRAM";case x.ROUTE_TYPE_AERIAL_LIFT:return"ROUTE_TYPE_AERIAL_LIFT";case x.ROUTE_TYPE_FUNICULAR:return"ROUTE_TYPE_FUNICULAR";case x.ROUTE_TYPE_TROLLEYBUS:return"ROUTE_TYPE_TROLLEYBUS";case x.ROUTE_TYPE_MONORAIL:return"ROUTE_TYPE_MONORAIL";case x.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),""!==t.name&&(n.name=t.name),(null===(e=t.routes)||void 0===e?void 0:e.length)&&(n.routes=t.routes.map((t=>Math.round(t)))),n},create:t=>$.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={type:0,name:"",routes:[]};return s.type=null!==(e=t.type)&&void 0!==e?e:0,s.name=null!==(n=t.name)&&void 0!==n?n:"",s.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],s}};const j={encode(t,e=new N){for(const n of t.stopsAdjacency)B.encode(n,e.uint32(10).fork()).join();for(const n of t.routesAdjacency)M.encode(n,e.uint32(18).fork()).join();for(const n of t.serviceRoutes)$.encode(n,e.uint32(26).fork()).join();for(const n of t.tripContinuations)k.encode(n,e.uint32(34).fork()).join();for(const n of t.guaranteedTripTransfers)k.encode(n,e.uint32(42).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopsAdjacency.push(B.decode(n,n.uint32()));continue;case 2:if(18!==t)break;s.routesAdjacency.push(M.decode(n,n.uint32()));continue;case 3:if(26!==t)break;s.serviceRoutes.push($.decode(n,n.uint32()));continue;case 4:if(34!==t)break;s.tripContinuations.push(k.decode(n,n.uint32()));continue;case 5:if(42!==t)break;s.guaranteedTripTransfers.push(k.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>B.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>M.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>$.fromJSON(t))):[],tripContinuations:globalThis.Array.isArray(null==t?void 0:t.tripContinuations)?t.tripContinuations.map((t=>k.fromJSON(t))):[],guaranteedTripTransfers:globalThis.Array.isArray(null==t?void 0:t.guaranteedTripTransfers)?t.guaranteedTripTransfers.map((t=>k.fromJSON(t))):[]}),toJSON(t){var e,n,r,s,i;const o={};return(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(o.stopsAdjacency=t.stopsAdjacency.map((t=>B.toJSON(t)))),(null===(n=t.routesAdjacency)||void 0===n?void 0:n.length)&&(o.routesAdjacency=t.routesAdjacency.map((t=>M.toJSON(t)))),(null===(r=t.serviceRoutes)||void 0===r?void 0:r.length)&&(o.serviceRoutes=t.serviceRoutes.map((t=>$.toJSON(t)))),(null===(s=t.tripContinuations)||void 0===s?void 0:s.length)&&(o.tripContinuations=t.tripContinuations.map((t=>k.toJSON(t)))),(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.length)&&(o.guaranteedTripTransfers=t.guaranteedTripTransfers.map((t=>k.toJSON(t)))),o},create:t=>j.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s,i;const o={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};return o.stopsAdjacency=(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.map((t=>B.fromPartial(t))))||[],o.routesAdjacency=(null===(n=t.routesAdjacency)||void 0===n?void 0:n.map((t=>M.fromPartial(t))))||[],o.serviceRoutes=(null===(r=t.serviceRoutes)||void 0===r?void 0:r.map((t=>$.fromPartial(t))))||[],o.tripContinuations=(null===(s=t.tripContinuations)||void 0===s?void 0:s.map((t=>k.fromPartial(t))))||[],o.guaranteedTripTransfers=(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.map((t=>k.fromPartial(t))))||[],o}};function z(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n}}function V(t){if(globalThis.Buffer)return globalThis.Buffer.from(t).toString("base64");{const e=[];return t.forEach((t=>{e.push(globalThis.String.fromCharCode(t))})),globalThis.btoa(e.join(""))}}function G(t){return null!=t}let J=class t{constructor(t,e,n,r,s){this.id=t,this.stopTimes=e,this.pickupDropOffTypes=n,this.stops=r,this.serviceRouteId=s,this.nbStops=r.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<r.length;t++){const e=r[t],n=this.stopIndices.get(e);n?n.push(t):this.stopIndices.set(e,[t])}}static of(e){var n,r;const{id:s,serviceRouteId:i,trips:o}=e;if(0===o.length)throw new Error("At least one trip must be provided");const a=o[0],u=new Uint32Array(a.stops.map((t=>t.id))),c=u.length;for(let t=1;t<o.length;t++){const e=o[t];if(e.stops.length!==c)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${c}`);for(let n=0;n<c;n++)if(e.stops[n].id!==u[n])throw new Error(`Trip ${t} has different stop at index ${n}`)}const d=new Uint16Array(o.length*c*2);for(let t=0;t<o.length;t++){const e=o[t];for(let n=0;n<c;n++){const r=e.stops[n],s=2*(t*c+n);d[s]=r.arrivalTime,d[s+1]=r.departureTime}}const l=o.length*c,h=new Uint8Array(Math.ceil(l/2));for(let t=0;t<o.length;t++){const e=o[t];for(let s=0;s<c;s++){const i=e.stops[s],o=t*c+s,a=null!==(n=i.pickUpType)&&void 0!==n?n:0,u=null!==(r=i.dropOffType)&&void 0!==r?r:0,d=Math.floor(o/2),l=o%2==1;h[d]|=l?a<<6|u<<4:a<<2|u}}return new t(s,d,h,u,i)}serialize(){return{stopTimes:this.stopTimes,pickupDropOffTypes:this.pickupDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}getNbStops(){return this.nbStops}getNbTrips(){return this.nbTrips}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const n=2*(e*this.stops.length+t),r=this.stopTimes[n];if(void 0===r)throw new Error(`Arrival time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return r}tripStopOffset(t){return t*this.nbStops}arrivalAtOffset(t,e){return this.stopTimes[2*(e+t)]}departureAtOffset(t,e){return this.stopTimes[2*(e+t)+1]}dropOffTypeAtOffset(t,e){const n=e+t,r=this.pickupDropOffTypes[n>>1];return 1&n?r>>4&3:3&r}departureFrom(t,e){const n=2*(e*this.stops.length+t)+1,r=this.stopTimes[n];if(void 0===r)throw new Error(`Departure time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return r}pickUpTypeFrom(t,e){const n=e*this.stops.length+t,r=n>>1,s=!(1&~n),i=this.pickupDropOffTypes[r];if(void 0===i)throw new Error(`Pick up type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return s?i>>6&3:i>>2&3}dropOffTypeAt(t,e){const n=e*this.stops.length+t,r=n>>1,s=!(1&~n),i=this.pickupDropOffTypes[r];if(void 0===i)throw new Error(`Drop off type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return s?i>>4&3:3&i}findEarliestTrip(t,e=0,n){if(this.nbTrips<=0)return;let r=this.nbTrips-1;if(void 0!==n&&(r=Math.min(r,n-1)),r<0)return;let s=0,i=-1;for(;s<=r;){const n=s+r>>>1;this.departureFrom(t,n)<e?s=n+1:(i=n,r=n-1)}return-1!==i?i:void 0}stopRouteIndices(t){const e=this.stopIndices.get(t);return void 0===e?[]:e}stopId(t){const e=this.stops[t];if(void 0===e)throw new Error(`StopId for stop at index ${t} not found in route ${this.serviceRouteId}`);return e}};const W=(BigInt(1)<<BigInt(20))-BigInt(1),Z=1048575,q=BigInt(0),Q=BigInt(20),X=BigInt(40),H=(t,e)=>{if(t<0||t>Z)throw new Error(`${e} must be between 0 and 1048575, got ${t}`)},K=(t,e,n)=>(H(t,"stopIndex"),H(e,"routeId"),H(n,"tripIndex"),BigInt(t)<<X|BigInt(e)<<Q|BigInt(n)<<q),tt=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),et=!0,nt=t=>{if(tt===et)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint32(4*e,t[e],et);return e},rt=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(tt===et)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint32(4*t,et);return e},st=t=>{if(tt===et)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint16(2*e,t[e],et);return e},it=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(tt===et)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint16(2*t,et);return e},ot=t=>{const e=[];return t.forEach((t=>{const n=t.serialize();e.push({stopTimes:st(n.stopTimes),pickupDropOffTypes:n.pickupDropOffTypes,stops:nt(n.stops),serviceRouteId:n.serviceRouteId})})),e},at=t=>{switch(t){case P.TRANSFER_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf transfer type.");case P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case P.TRANSFER_TYPE_TIMED_TRANSFER:return"GUARANTEED";case P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case P.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"IN_SEAT";case P.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},ut=t=>{switch(t){case"RECOMMENDED":return P.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return P.TRANSFER_TYPE_TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return P.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case"IN_SEAT":return P.TRANSFER_TYPE_IN_SEAT_TRANSFER}},ct=t=>{switch(t){case x.ROUTE_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf route type.");case x.ROUTE_TYPE_TRAM:return"TRAM";case x.ROUTE_TYPE_SUBWAY:return"SUBWAY";case x.ROUTE_TYPE_RAIL:return"RAIL";case x.ROUTE_TYPE_BUS:return"BUS";case x.ROUTE_TYPE_FERRY:return"FERRY";case x.ROUTE_TYPE_CABLE_TRAM:return"CABLE_TRAM";case x.ROUTE_TYPE_AERIAL_LIFT:return"AERIAL_LIFT";case x.ROUTE_TYPE_FUNICULAR:return"FUNICULAR";case x.ROUTE_TYPE_TROLLEYBUS:return"TROLLEYBUS";case x.ROUTE_TYPE_MONORAIL:return"MONORAIL";case x.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},dt=t=>{switch(t){case"TRAM":return x.ROUTE_TYPE_TRAM;case"SUBWAY":return x.ROUTE_TYPE_SUBWAY;case"RAIL":return x.ROUTE_TYPE_RAIL;case"BUS":return x.ROUTE_TYPE_BUS;case"FERRY":return x.ROUTE_TYPE_FERRY;case"CABLE_TRAM":return x.ROUTE_TYPE_CABLE_TRAM;case"AERIAL_LIFT":return x.ROUTE_TYPE_AERIAL_LIFT;case"FUNICULAR":return x.ROUTE_TYPE_FUNICULAR;case"TROLLEYBUS":return x.ROUTE_TYPE_TROLLEYBUS;case"MONORAIL":return x.ROUTE_TYPE_MONORAIL}},lt=t=>{const e=[];for(const[r,s]of t.entries()){const[t,i,o]=(n=r,[Number(n>>X&W),Number(n>>Q&W),Number(n>>q&W)]);e.push({origin:{stopIndex:t,routeId:i,tripIndex:o},destinations:s.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})))})}var n;return e},ht=t=>{const e=new Map;for(let n=0;n<t.length;n++){const r=t[n],s=r.origin,i=K(s.stopIndex,s.routeId,s.tripIndex),o=r.destinations.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(i,o)}return e},ft=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),pt=[];class Tt{constructor(t,e,n,r,s){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=n,this.tripContinuations=r,this.guaranteedTripTransfers=s,this.activeStops=new Set;for(let e=0;e<t.length;e++){const n=t[e];(n.routes.length>0||n.transfers&&n.transfers.length>0)&&this.activeStops.add(e)}}serialize(){const t={stopsAdjacency:(n=this.stopsAdjacency,n.map((t=>({transfers:t.transfers?t.transfers.map((t=>Object.assign({destination:t.destination,type:ut(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime}))):[],routes:t.routes})))),routesAdjacency:ot(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:dt(t.type),name:t.name,routes:t.routes})))),tripContinuations:lt(this.tripContinuations||new Map),guaranteedTripTransfers:lt(this.guaranteedTripTransfers||new Map)};var e,n;const r=new N;return j.encode(t,r),r.finish()}static fromData(t){const e=new b(t),n=j.decode(e);return new Tt((t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],s=[];for(let t=0;t<r.transfers.length;t++){const e=r.transfers[t],n=Object.assign({destination:e.destination,type:at(e.type)},void 0!==e.minTransferTime&&{minTransferTime:e.minTransferTime});s.push(n)}const i={routes:r.routes};s.length>0&&(i.transfers=s),e.push(i)}return e})(n.stopsAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],s=rt(r.stops);e.push(new J(n,it(r.stopTimes),r.pickupDropOffTypes,s,r.serviceRouteId))}return e})(n.routesAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n];e.push({type:ct(r.type),name:r.name,routes:r.routes})}return e})(n.serviceRoutes),ht(n.tripContinuations),ht(n.guaranteedTripTransfers))}isActive(t){return this.activeStops.has(t)}nbStops(){return this.stopsAdjacency.length}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){const e=this.stopsAdjacency[t];if(!e)throw new Error(`Stop ID ${t} not found`);return e.transfers||[]}getContinuousTrips(t,e,n){var r;const s=null===(r=this.tripContinuations)||void 0===r?void 0:r.get(K(t,e,n));return s||pt}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);return{type:e.type,name:e.name}}routesPassingThrough(t){const e=this.stopsAdjacency[t];if(!e)return[];const n=[];for(let t=0;t<e.routes.length;t++){const r=e.routes[t],s=this.routesAdjacency[r];s&&n.push(s)}return n}findReachableRoutes(t,e=ft){const n=new Map,r=e!==ft;for(const s of t){const t=this.stopsAdjacency[s];if(t)for(let i=0;i<t.routes.length;i++){const o=this.routesAdjacency[t.routes[i]];if(!o)continue;if(r){const t=this.serviceRoutes[o.serviceRoute()];if(!t||!e.has(t.type))continue}const a=o.stopRouteIndices(s)[0],u=n.get(o);void 0!==u?a<u&&n.set(o,a):n.set(o,a)}}return n}isTripTransferGuaranteed(t,e){var n;const r=K(t.stopIndex,t.routeId,t.tripIndex),s=null===(n=this.guaranteedTripTransfers)||void 0===n?void 0:n.get(r);if(!s)return!1;for(let t=0;t<s.length;t++){const n=s[t];if(n.stopIndex===e.stopIndex&&n.routeId===e.routeId&&n.tripIndex===e.tripIndex)return!0}return!1}findFirstBoardableTrip(t,e,n,r=0,s,i,o=0){const a=e.getNbTrips();for(let u=n;u<(null!=s?s:a);u++){if(1===e.pickUpTypeFrom(t,u))continue;if(void 0===i)return u;if(this.isTripTransferGuaranteed(i,{stopIndex:t,routeId:e.id,tripIndex:u}))return u;if(e.departureFrom(t,u)>=r+o)return u}}getGuaranteedTripTransfers(t,e,n){var r;const s=null===(r=this.guaranteedTripTransfers)||void 0===r?void 0:r.get(K(t,e,n));return s||pt}}class Et{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}Et.Builder=class{constructor(){var t;this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:(t=120,Math.round(t/60)),transportModes:ft}}from(t){return this.fromValue=t,this}to(t){return this.toValue=t instanceof Set?t:new Set([t]),this}departureTime(t){return this.departureTimeValue=t,this}maxTransfers(t){return this.optionsValue.maxTransfers=t,this}minTransferTime(t){return this.optionsValue.minTransferTime=t,this}transportModes(t){return this.optionsValue.transportModes=t,this}maxInitialWaitingTime(t){return this.optionsValue.maxInitialWaitingTime=t,this}build(){return new Et(this)}};class mt extends Et{constructor(t){super(t),this.lastDepartureTime=t.lastDepartureTimeValue,this.rangeOptions=t.rangeOptionsValue}}mt.Builder=class extends Et.Builder{constructor(){super(...arguments),this.rangeOptionsValue={optimizeBeyondLatestDeparture:!0}}lastDepartureTime(t){return this.lastDepartureTimeValue=t,this}rangeOptions(t){return this.rangeOptionsValue=Object.assign(Object.assign({},this.rangeOptionsValue),t),this}build(){return new mt(this)}};class It{constructor(t){this.legs=t}departureTime(){let t=0;for(let e=0;e<this.legs.length;e++){const n=this.legs[e];if("departureTime"in n)return n.departureTime-t;"duration"in n&&n.duration&&(t+=n.duration)}throw new Error("No vehicle leg found in route")}arrivalTime(){let t=0,e=0;for(let n=this.legs.length-1;n>=0;n--){const r=this.legs[n];if("arrivalTime"in r)return t=r.arrivalTime,t+e;"minTransferTime"in r&&r.minTransferTime&&(e+=r.minTransferTime)}throw new Error("No vehicle leg found in route")}totalDuration(){return 0===this.legs.length?0:Math.abs(this.arrivalTime()-this.departureTime())}toString(){return this.legs.map(((t,r)=>{const s=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,i=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,o="type"in t&&!("route"in t)?`Transfer: ${t.type}${t.minTransferTime?`, Minimum Transfer Time: ${n(t.minTransferTime)}`:""}`:"",a="duration"in t?`Access duration: ${n(t.duration)}`:"",u="route"in t&&"departureTime"in t&&"arrivalTime"in t?`Route: ${t.route.type} ${t.route.name}, Departure: ${e(t.departureTime)}, Arrival: ${e(t.arrivalTime)}`:"";return[`Leg ${r+1}:`,` ${s}`,` ${i}`,o?` ${o}`:"",a?` ${a}`:"",u?` ${u}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}}const _t=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],gt=t=>{const e=_t[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};class Rt{constructor(t,e,n,r){this.destinations=t,this.routingState=e,this.stopsIndex=n,this.timetable=r}expandDestinations(t){const e=t instanceof Set?t:void 0!==t?[t]:this.destinations,n=new Set;for(const t of e)for(const e of this.stopsIndex.equivalentStops(t))n.add(e.id);return n}bestRouteToSourceStopId(t){var e;if(t instanceof Set){const e=new Set;for(const n of t){const t=this.stopsIndex.findStopBySourceStopId(n);void 0!==t&&e.add(t.id)}return 0===e.size?void 0:this.bestRoute(e)}const n=null===(e=this.stopsIndex.findStopBySourceStopId(t))||void 0===e?void 0:e.id;return void 0===n?void 0:this.bestRoute(n)}bestRoute(t){var e;const n=this.expandDestinations(t);let r,s,i;for(const t of n){const e=this.routingState.getArrival(t);void 0!==e&&(void 0===s||e.arrival<s)&&(r=t,s=e.arrival,i=e.legNumber)}if(void 0===r||void 0===i)return;const o=[];let a,u=r,c=i;for(;c>=0;){const t=null===(e=this.routingState.graph[c])||void 0===e?void 0:e[u];if(!t){if(0===c)break;throw new Error(`No edge arriving at stop ${u} at round ${c}`)}let n;if("routeId"in t){let e,r;if(t.continuationOf){let n=t;const s=[n];for(;n.continuationOf;)s.push(n.continuationOf),n=n.continuationOf;e=n,r=this.buildVehicleLeg(s)}else e=t,r=this.buildVehicleLeg([t]);n=r,a&&this.timetable.isTripTransferGuaranteed({stopIndex:e.hopOffStopIndex,routeId:e.routeId,tripIndex:e.tripIndex},{stopIndex:a.stopIndex,routeId:a.routeId,tripIndex:a.tripIndex})&&o.push(this.buildGuaranteedTransferLeg(e,a)),a=e}else if("type"in t)n=this.buildTransferLeg(t),a=void 0;else{if(!("duration"in t))break;n=this.buildAccessLeg(t),a=void 0}o.push(n),u=n.from.id,"routeId"in t&&(c-=1)}return new It(o.reverse())}buildVehicleLeg(t){if(0===t.length)throw new Error("Cannot build vehicle leg from empty edges");const e=t[t.length-1],n=t[0],r=this.timetable.getRoute(e.routeId),s=this.timetable.getRoute(n.routeId);return{from:this.stopsIndex.findStopById(r.stopId(e.stopIndex)),to:this.stopsIndex.findStopById(s.stopId(n.hopOffStopIndex)),route:this.timetable.getServiceRouteInfo(r),departureTime:r.departureFrom(e.stopIndex,e.tripIndex),arrivalTime:n.arrival,pickUpType:gt(r.pickUpTypeFrom(e.stopIndex,e.tripIndex)),dropOffType:gt(s.dropOffTypeAt(n.hopOffStopIndex,n.tripIndex))}}buildTransferLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),minTransferTime:t.minTransferTime,type:t.type}}buildAccessLeg(t){return{from:this.stopsIndex.findStopById(t.from),to:this.stopsIndex.findStopById(t.to),duration:t.duration}}buildGuaranteedTransferLeg(t,e){const n=this.timetable.getRoute(t.routeId),r=this.timetable.getRoute(e.routeId),s=n.stopId(t.hopOffStopIndex),i=r.stopId(e.stopIndex);return{from:this.stopsIndex.findStopById(s),to:this.stopsIndex.findStopById(i),type:"GUARANTEED"}}arrivalAt(t,e){var n,r;const s=this.stopsIndex.equivalentStops(t);let i;for(const t of s){let s;if(void 0===e||(null===(n=this.routingState.getArrival(t.id))||void 0===n?void 0:n.legNumber)===e+1)s=this.routingState.getArrival(t.id);else for(let n=e+1;n>=0;n--){const e=null===(r=this.routingState.graph[n])||void 0===r?void 0:r[t.id];if(void 0!==e){s={arrival:e.arrival,legNumber:n};break}}void 0!==s&&(void 0===i||s.arrival<i.arrival)&&(i=s)}return i}}class At{constructor(t,e){this.timetable=t,this.stopsIndex=e}collectAccessPaths(t,e){var n;const r=this.stopsIndex.equivalentStops(t).map((t=>t.id)),s=new Map;for(const t of r){const r=s.get(t);(void 0===r||r.duration>0)&&s.set(t,{fromStopId:t,toStopId:t,duration:0});for(const r of this.timetable.getTransfers(t))if("REQUIRES_MINIMAL_TIME"===r.type){const i=null!==(n=r.minTransferTime)&&void 0!==n?n:e,o=s.get(r.destination);(void 0===o||o.duration&&i<o.duration)&&s.set(r.destination,{fromStopId:t,toStopId:r.destination,duration:i})}}return Array.from(s.values())}collectDepartureTimes(t,e,n){const r=new Map;for(const s of t){const{toStopId:t}=s,i=e+s.duration,o=n+s.duration;for(const e of this.timetable.routesPassingThrough(t))for(const n of e.stopRouteIndices(t)){let t=e.findEarliestTrip(n,i);if(void 0===t)continue;const a=e.getNbTrips();for(;t<a;){const i=e.departureFrom(n,t);if(i>o)break;if(1!==e.pickUpTypeFrom(n,t)){const t=i-s.duration;let e=r.get(t);void 0===e&&r.set(t,e=new Set),e.add(s)}t++}}}if(0===r.size)return[];return Array.from(r.entries()).sort((([t],[e])=>e-t)).map((([t,e])=>({depTime:t,legs:Array.from(e)})))}}const vt=65535;class Ot{constructor(t,e,n,r,s=0){this._destinationBest=vt,this.reachedStops=[],this.destinations=e,this.destinationSet=new Set(e),this.earliestArrivalTimes=new Uint16Array(r).fill(vt),this.earliestArrivalLegs=new Uint8Array(r),this.origins=[],this.graph=[new Array(r)];for(let t=1;t<=s;t++)this.graph.push(new Array(r));this.seedAccessPaths(t,n)}seedAccessPaths(t,e){const n=new Set;for(const r of e){const e=t+r.duration,s=0===r.duration?{stopId:r.fromStopId,arrival:t}:{arrival:e,from:r.fromStopId,to:r.toStopId,duration:r.duration},i=r.toStopId;e<this.earliestArrivalTimes[i]&&(this.earliestArrivalTimes[i]=e,this.graph[0][i]=s),n.add(i)}for(const t of n)this.reachedStops.push(t);this.origins=Array.from(n);for(let t=0;t<this.destinations.length;t++){const e=this.earliestArrivalTimes[this.destinations[t]];e<this._destinationBest&&(this._destinationBest=e)}}get nbStops(){return this.earliestArrivalTimes.length}arrivalTime(t){return this.earliestArrivalTimes[t]}get destinationBest(){return this._destinationBest}improvementBound(t,e){return this.arrivalTime(e)}initRound(t){}updateArrival(t,e,n){this.reachedStops.push(t),this.earliestArrivalTimes[t]=e,this.earliestArrivalLegs[t]=n,this.destinationSet.has(t)&&e<this._destinationBest&&(this._destinationBest=e)}resetFor(t,e){for(const t of this.reachedStops){this.earliestArrivalTimes[t]=vt,this.earliestArrivalLegs[t]=0;for(let e=0;e<this.graph.length;e++)this.graph[e][t]=void 0}this.reachedStops.length=0,this._destinationBest=vt,this.seedAccessPaths(t,e)}*arrivals(){for(let t=0;t<this.earliestArrivalTimes.length;t++){const e=this.earliestArrivalTimes[t];e<vt&&(yield{stop:t,arrival:e,legNumber:this.earliestArrivalLegs[t]})}}earliestArrivalAtAnyDestination(){return this._destinationBest}getArrival(t){const e=this.earliestArrivalTimes[t];if(!(e>=vt))return{arrival:e,legNumber:this.earliestArrivalLegs[t]}}isDestination(t){return this.destinationSet.has(t)}static fromTestData({nbStops:t,origins:e=[],destinations:n=[],arrivals:r=[],graph:s=[]}){const i=new Ot(0,n,e.map((t=>({fromStopId:t,toStopId:t,duration:0}))),t),o=new Uint16Array(t).fill(vt),a=new Uint8Array(t);for(const[t,e,n]of r)o[t]=e,a[t]=n;i.earliestArrivalTimes=o,i.earliestArrivalLegs=a,i._destinationBest=vt;for(const t of n){const e=o[t];void 0!==e&&e<i._destinationBest&&(i._destinationBest=e)}const u=s.map((e=>{const n=new Array(t);for(const[t,r]of e)n[t]=r;return n}));return i.graph.splice(0,i.graph.length,...u),i}}class St{constructor(t,e,n,r){this.timetable=t,this.stopsIndex=e,this.accessFinder=n,this.raptor=r}route(t){const e=this.accessFinder.collectAccessPaths(t.from,t.options.minTransferTime),n=Array.from(t.to).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),r=new Ot(t.departureTime,n,e,this.timetable.nbStops(),t.options.maxTransfers+1);return this.raptor.run(t.options,r),new Rt(new Set(n),r,this.stopsIndex,this.timetable)}}class yt{constructor(t,e){this._runs=t,this._destinations=e}get destinations(){return this._destinations}normalizeTargets(t){return t instanceof Set?new Set(t):void 0!==t?new Set([t]):new Set(this._destinations)}getRoutes(){const t=[];for(const{result:e}of this._runs){const n=e.bestRoute();void 0!==n&&t.push(n)}return t.reverse()}bestRoute(t){const e=this.normalizeTargets(t);let n,r;for(const t of this._runs)for(const s of e){const e=t.result.arrivalAt(s);void 0!==e&&((void 0===r||e.arrival<r)&&(r=e.arrival,n=t))}return null==n?void 0:n.result.bestRoute(e)}latestDepartureRoute(t){const e=this.normalizeTargets(t);for(const{result:t}of this._runs){const n=t.bestRoute(e);if(void 0!==n)return n}}fastestRoute(t){const e=this.normalizeTargets(t);let n,r=1/0;for(const t of this._runs)for(const s of e){const e=t.result.arrivalAt(s);if(void 0===e)continue;const i=e.arrival-t.departureTime;i<r&&(r=i,n=t)}return null==n?void 0:n.result.bestRoute(e)}get size(){return this._runs.length}earliestArrivalAt(t,e){let n;for(const{result:r}of this._runs){const s=r.arrivalAt(t,e);void 0!==s&&(void 0===n||s.arrival<n.arrival)&&(n=s)}return n}shortestDurationTo(t,e){let n;for(const{departureTime:r,result:s}of this._runs){const i=s.arrivalAt(t,e);if(void 0===i)continue;const o=i.arrival-r;(void 0===n||o<n.duration)&&(n=Object.assign(Object.assign({},i),{duration:o}))}return n}allShortestDurations(){const t=new Map;for(const{departureTime:e,result:n}of this._runs)for(const{stop:r,arrival:s,legNumber:i}of n.routingState.arrivals()){const n=s-e,o=t.get(r);(void 0===o||n<o.duration)&&t.set(r,{arrival:s,legNumber:i,duration:n})}return t}allEarliestArrivals(){const t=new Map;for(const{result:e}of this._runs)for(const{stop:n,arrival:r,legNumber:s}of e.routingState.arrivals()){const e=t.get(n);(void 0===e||r<e.arrival)&&t.set(n,{arrival:r,legNumber:s})}return t}[Symbol.iterator](){return this._runs[Symbol.iterator]()}}class Nt{constructor(t,e,n){this._destinationBest=vt,this.latestDeparture=n,this.roundLabels=Array.from({length:t+2},(()=>new Uint16Array(e).fill(vt))),this.changedInRound=Array.from({length:t+2},(()=>[]))}setCurrentRun(t){this.currentRun=t;const e=t.graph[0];for(const n of t.origins){const t=e[n];t&&this.updateArrival(n,t.arrival,0)}}get origins(){return this.currentRun.origins}get graph(){return this.currentRun.graph}arrivalTime(t){return this.currentRun.arrivalTime(t)}improvementBound(t,e){return this.roundLabels[t][e]}get destinationBest(){return this._destinationBest}isDestination(t){return this.currentRun.isDestination(t)}updateArrival(t,e,n){this.currentRun.updateArrival(t,e,n),e<this.roundLabels[n][t]&&(this.roundLabels[n][t]=e,this.changedInRound[n].push(t),this.currentRun.isDestination(t)&&e<this._destinationBest&&(this._destinationBest=e))}initRound(t){const e=this.changedInRound[t-1];if(0===e.length)return;const n=this.roundLabels[t-1],r=this.roundLabels[t];for(let t=0;t<e.length;t++){const s=e[t];n[s]<r[s]&&(r[s]=n[s])}e.length=0}}class bt{constructor(t,e,n,r){this.timetable=t,this.stopsIndex=e,this.accessFinder=n,this.raptor=r}rangeRoute(t){var e,n;const{departureTime:r,lastDepartureTime:s}=t,i=Array.from(t.to).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),o=0===i.length,a=this.accessFinder.collectAccessPaths(t.from,t.options.minTransferTime),u=this.accessFinder.collectDepartureTimes(a,r,s);if(0===u.length)return new yt([],new Set(i));const c=t.options.maxTransfers+1,d=new Nt(c,this.timetable.nbStops(),s),l=[],h=new Map;for(const t of i)h.set(t,vt);const f=new Set(a.map((t=>t.toStopId)).filter((t=>i.includes(t)))),p=new Set;let T=null;if(t.rangeOptions.optimizeBeyondLatestDeparture&&(T=new Ot(s+1,i,a,this.timetable.nbStops(),c),d.setCurrentRun(T),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:void 0}),d),!o))for(const t of i){const n=T.arrivalTime(t);n<(null!==(e=h.get(t))&&void 0!==e?e:vt)&&h.set(t,n)}for(const{depTime:e,legs:r}of u){if(!o&&p.size===i.length)break;null===T?T=new Ot(e,i,r,this.timetable.nbStops(),c):T.resetFor(e,r),d.setCurrentRun(T),this.raptor.run(Object.assign(Object.assign({},t.options),{maxInitialWaitingTime:0}),d);let s=o;if(!o)for(const t of i){const e=T.arrivalTime(t);e>=(null!==(n=h.get(t))&&void 0!==n?n:vt)||(f.has(t)&&p.has(t)?h.set(t,e):(h.set(t,e),f.has(t)&&p.add(t),s=!0))}s&&(l.push({departureTime:e,result:new Rt(new Set(i),T,this.stopsIndex,this.timetable)}),T=null)}return new yt(l,new Set(i))}}class wt{constructor(t){this.timetable=t}run(t,e){const n=new Set(e.origins);for(let r=1;r<=t.maxTransfers+1;r++){e.initRound(r);const s=e.graph[r],i=this.timetable.findReachableRoutes(n,t.transportModes);n.clear();for(const[s,o]of i)for(const i of this.scanRoute(s,o,r,e,t))n.add(i);let o=this.findTripContinuations(n,s);const a=new Set;for(;o.length>0;){a.clear();for(const t of o){const s=this.timetable.getRoute(t.routeId);for(const i of this.scanRouteContinuation(s,t.stopIndex,r,e,t))a.add(i),n.add(i)}o=this.findTripContinuations(a,s)}for(const s of this.considerTransfers(t,r,n,e))n.add(s);if(0===n.size)break}}findTripContinuations(t,e){const n=[];for(const r of t){const t=e[r];if(!t||!("routeId"in t))continue;const s=this.timetable.getContinuousTrips(t.hopOffStopIndex,t.routeId,t.tripIndex);for(const e of s)n.push({routeId:e.routeId,stopIndex:e.stopIndex,tripIndex:e.tripIndex,previousEdge:t})}return n}scanRouteContinuation(t,e,n,r,s){const i=new Set,o=r.graph[n],a=t.getNbStops(),u=t.id,c=s.tripIndex,d=t.tripStopOffset(c),l=s.previousEdge;for(let s=e;s<a;s++){const a=t.stops[s],h=t.arrivalAtOffset(s,d);1!==t.dropOffTypeAtOffset(s,d)&&h<r.improvementBound(n,a)&&h<r.destinationBest&&(o[a]={routeId:u,stopIndex:e,tripIndex:c,arrival:h,hopOffStopIndex:s,continuationOf:l},r.updateArrival(a,h,n),i.add(a))}return i}scanRoute(t,e,n,r,s){const i=new Set,o=r.graph[n],a=r.graph[n-1],u=t.getNbStops(),c=t.id;let d,l=e,h=0;for(let f=e;f<u;f++){const e=t.stops[f];if(void 0!==d){const s=t.arrivalAtOffset(f,h);1!==t.dropOffTypeAtOffset(f,h)&&s<r.improvementBound(n,e)&&s<r.destinationBest&&(o[e]={routeId:c,stopIndex:l,tripIndex:d,arrival:s,hopOffStopIndex:f},r.updateArrival(e,s,n),i.add(e))}const u=a[e],p=null==u?void 0:u.arrival;if(void 0!==p&&(void 0===d||p<=t.departureAtOffset(f,h))){const e=t.findEarliestTrip(f,p,d);if(void 0===e)continue;const r=u&&"routeId"in u?{stopIndex:u.hopOffStopIndex,routeId:u.routeId,tripIndex:u.tripIndex}:void 0,i=this.timetable.findFirstBoardableTrip(f,t,e,p,d,r,s.minTransferTime);if(void 0!==i){1===n&&void 0!==s.maxInitialWaitingTime&&t.departureFrom(f,i)-p>s.maxInitialWaitingTime||(d=i,l=f,h=t.tripStopOffset(i))}}}return i}considerTransfers(t,e,n,r){const s=new Set,i=r.graph[e];for(const o of n){const n=i[o];if(!n||"type"in n)continue;const a=this.timetable.getTransfers(o);for(const u of a){let a;a=u.minTransferTime?u.minTransferTime:"IN_SEAT"===u.type?0:t.minTransferTime;const c=n.arrival+a;c<r.improvementBound(e,u.destination)&&c<r.destinationBest&&(i[u.destination]={arrival:c,from:o,to:u.destination,minTransferTime:a||void 0,type:u.type},r.updateArrival(u.destination,c,e),s.add(u.destination))}}return s}}class Ut{constructor(t=[],e=Pt){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,i=e[s];if(n(r,i)>=0)break;e[t]=i,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),i=e[r];const o=r+1;if(o<this.length&&n(e[o],i)<0&&(r=o,i=e[o]),n(i,s)>=0)break;e[t]=i,t=r}e[t]=s}}function Pt(t,e){return t<e?-1:t>e?1:0}const xt=Math.PI/180;function Lt(t,e,n,r){const s=r.minLng,i=r.maxLng,o=r.minLat,a=r.maxLat;if(t>=s&&t<=i)return e<o?Yt((e-o)*xt):e>a?Yt((e-a)*xt):0;const u=Math.min(Yt((t-s)*xt),Yt((t-i)*xt)),c=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*xt)/n)/xt}(e,u);return c>o&&c<a?Mt(u,n,e,c):Math.min(Mt(u,n,e,o),Mt(u,n,e,a))}function Ct(t,e){return t.dist-e.dist}function Yt(t){const e=Math.sin(t/2);return e*e}function Mt(t,e,n,r){return e*Math.cos(r*xt)*t+Yt((n-r)*xt)}function Ft(t,e,n,r,s){return Mt(Yt((t-n)*xt),s,e,r)}const Dt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class kt{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=Dt[15&n];if(!s)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[o]=new Uint32Array(t,4,1);return new kt(o,i,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=Dt.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,o=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-o%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${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+o+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+o+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+o+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const 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 Bt(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:i,nodeSize:o}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,d=a.pop()||0,l=a.pop()||0;if(d-l<=o){for(let o=l;o<=d;o++){const a=i[2*o],c=i[2*o+1];a>=t&&a<=n&&c>=e&&c<=r&&u.push(s[o])}continue}const h=l+d>>1,f=i[2*h],p=i[2*h+1];f>=t&&f<=n&&p>=e&&p<=r&&u.push(s[h]),(0===c?t<=f:e<=p)&&(a.push(l),a.push(h-1),a.push(1-c)),(0===c?n>=f:r>=p)&&(a.push(h+1),a.push(d),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:s,nodeSize:i}=this,o=[0,r.length-1,0],a=[],u=n*n;for(;o.length;){const c=o.pop()||0,d=o.pop()||0,l=o.pop()||0;if(d-l<=i){for(let n=l;n<=d;n++)Vt(s[2*n],s[2*n+1],t,e)<=u&&a.push(r[n]);continue}const h=l+d>>1,f=s[2*h],p=s[2*h+1];Vt(f,p,t,e)<=u&&a.push(r[h]),(0===c?t-n<=f:e-n<=p)&&(o.push(l),o.push(h-1),o.push(1-c)),(0===c?t+n>=f:e+n>=p)&&(o.push(h+1),o.push(d),o.push(1-c))}return a}}function Bt(t,e,n,r,s,i){if(s-r<=n)return;const o=r+s>>1;$t(t,e,o,r,s,i),Bt(t,e,n,r,o-1,1-i),Bt(t,e,n,o+1,s,1-i)}function $t(t,e,n,r,s,i){for(;s>r;){if(s-r>600){const o=s-r+1,a=n-r+1,u=Math.log(o),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(o-c)/o)*(a-o/2<0?-1:1);$t(t,e,n,Math.max(r,Math.floor(n-a*c/o+d)),Math.min(s,Math.floor(n+(o-a)*c/o+d)),i)}const o=e[2*n+i];let a=r,u=s;for(jt(t,e,r,n),e[2*s+i]>o&&jt(t,e,r,s);a<u;){for(jt(t,e,a,u),a++,u--;e[2*a+i]<o;)a++;for(;e[2*u+i]>o;)u--}e[2*r+i]===o?jt(t,e,r,u):(u++,jt(t,e,u,s)),u<=n&&(r=u+1),n<=u&&(s=u-1)}}function jt(t,e,n,r){zt(t,n,r),zt(e,2*n,2*r),zt(e,2*n+1,2*r+1)}function zt(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function Vt(t,e,n,r){const s=t-n,i=e-r;return s*s+i*i}const Gt="KEYS",Jt="VALUES";class Wt{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}=Zt(this._path);if(""===Zt(e))return{done:!1,value:this.result()};const n=t.get(Zt(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Zt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Zt(t))).filter((t=>""!==t)).join("")}value(){return Zt(this._path).node.get("")}result(){switch(this._type){case Jt:return this.value();case Gt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Zt=t=>t[t.length-1],qt=(t,e,n,r,s,i,o,a)=>{const u=i*o;t:for(const c of t.keys())if(""===c){const e=s[u-1];e<=n&&r.set(a,[t.get(c),e])}else{let u=i;for(let t=0;t<c.length;++t,++u){const r=c[t],i=o*u,a=i-o;let d=s[i];const l=Math.max(0,u-n-1),h=Math.min(o-1,u+n);for(let t=l;t<h;++t){const n=r!==e[t],o=s[a+t]+ +n,u=s[a+t+1]+1,c=s[i+t]+1,l=s[i+t+1]=Math.min(o,u,c);l<d&&(d=l)}if(d>n)continue t}qt(t.get(c),e,n,r,s,u,o,a+c)}};class Qt{_tree;_prefix;_size=void 0;constructor(t=new Map,e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,n]=Xt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=re(n);for(const n of e.keys())if(""!==n&&n.startsWith(r)){const s=new Map;return s.set(n.slice(r.length),e.get(n)),new Qt(s,t)}}return new Qt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,te(this._tree,t)}entries(){return new Wt(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,i=s+n,o=new Uint8Array(i*s).fill(n+1);for(let t=0;t<s;++t)o[t]=t;for(let t=1;t<i;++t)o[t*s]=t;return qt(t,e,n,r,o,1,s,""),r})(this._tree,t,e)}get(t){const e=Ht(this._tree,t);return void 0!==e?e.get(""):void 0}has(t){return Ht(this._tree,t)?.has("")??!1}keys(){return new Wt(this,Gt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Kt(this._tree,t).set("",e),this}get size(){if(this._size)return this._size;this._size=0;const t=this.entries();for(;!t.next().done;)this._size+=1;return this._size}update(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Kt(this._tree,t);return n.set("",e(n.get(""))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Kt(this._tree,t);let r=n.get("");return void 0===r&&n.set("",r=e()),r}values(){return new Wt(this,Jt)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Qt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return Qt.from(Object.entries(t))}}const Xt=(t,e,n=[])=>{if(0===e.length||null==t)return[t,n];for(const r of t.keys())if(""!==r&&e.startsWith(r))return n.push([t,r]),Xt(t.get(r),e.slice(r.length),n);return n.push([t,e]),Xt(void 0,"",n)},Ht=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(""!==n&&e.startsWith(n))return Ht(t.get(n),e.slice(n.length))},Kt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const s of t.keys())if(""!==s&&e[r]===s[0]){const i=Math.min(n-r,s.length);let o=1;for(;o<i&&e[r+o]===s[o];)++o;const a=t.get(s);if(o===s.length)t=a;else{const n=new Map;n.set(s.slice(o),a),t.set(e.slice(r,r+o),n),t.delete(s),t=n}r+=o;continue t}const s=new Map;return t.set(e.slice(r),s),s}return t},te=(t,e)=>{const[n,r]=Xt(t,e);if(void 0!==n)if(n.delete(""),0===n.size)ee(r);else if(1===n.size){const[t,e]=n.entries().next().value;ne(r,t,e)}},ee=t=>{if(0===t.length)return;const[e,n]=re(t);if(e.delete(n),0===e.size)ee(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;""!==n&&ne(t.slice(0,-1),n,r)}},ne=(t,e,n)=>{if(0===t.length)return;const[r,s]=re(t);r.set(s+e,n),r.delete(s)},re=t=>t[t.length-1],se=/[\n\r\p{Z}\p{P}]+/u,ie="or",oe="and",ae="and_not",ue=(t,e)=>{t.includes(e)||t.push(e)},ce=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},de=({score:t},{score:e})=>e-t,le=()=>new Map,he=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,fe={[ie]:(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:i}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,i),ce(r.terms,s)}}return t},[oe]:(t,e)=>{const n=new Map;for(const r of e.keys()){const s=t.get(r);if(null==s)continue;const{score:i,terms:o,match:a}=e.get(r);ce(s.terms,o),n.set(r,{score:s.score+i,terms:s.terms,match:Object.assign(s.match,a)})}return n},[ae]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},pe=(t,e,n,r,s,i)=>{const{k:o,b:a,d:u}=i;return Math.log(1+(n-e+.5)/(e+.5))*(u+t*(o+1)/(t+o*(1-a+a*r/s)))},Te=(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")},Ee=(t,e,n,r)=>{const s=t._index.fetch(r,le);let i=s.get(e);if(null==i)i=new Map,i.set(n,1),s.set(e,i);else{const t=i.get(n);i.set(n,(t??0)+1)}},me=(t,e,n,r)=>{if(!t._index.has(r))return void Te(t,n,e,r);const s=t._index.fetch(r,le),i=s.get(e),o=i?.get(n);!i||typeof o>"u"?Te(t,n,e,r):o<=1?i.size<=1?s.delete(e):i.delete(n):i.set(n,o-1),0===t._index.get(r).size&&t._index.delete(r)},Ie=(t,e,n,r,s)=>{let i=t._fieldLength.get(e);null==i&&t._fieldLength.set(e,i=[]),i[n]=s;const o=(t._avgFieldLength[n]||0)*r+s;t._avgFieldLength[n]=o/(r+1)},_e=(t,e)=>{const{extractField:n,stringifyField:r,tokenize:s,processTerm:i,fields:o,idField:a}=t._options,u=n(e,a);if(null==u)throw new Error(`SlimSearch: document does not have ID field "${a}"`);if(((t,e)=>t._idToShortId.has(e))(t,u))throw new Error(`SlimSearch: duplicate ID ${u}`);const c=((t,e)=>{const n=t._nextId;return t._idToShortId.set(e,n),t._documentIds.set(n,e),t._documentCount+=1,t._nextId+=1,n})(t,u);((t,e,n)=>{const{storeFields:r,extractField:s}=t._options;if(0===r?.length)return;let i=t._storedFields.get(e);void 0===i&&t._storedFields.set(e,i={});for(const t of r){const e=s(n,t);null!=e&&(i[t]=e)}})(t,c,e);for(const a of o){const o=n(e,a);if(null==o)continue;const u=s(r(o,a),a),d=t._fieldIds[a],l=new Set(u).size;Ie(t,c,d,t._documentCount-1,l);for(const e of u){const n=i(e,a);if(Array.isArray(n))for(const e of n)Ee(t,d,c,e);else n&&Ee(t,d,c,n)}}},ge={idField:"id",extractField:(t,e)=>t[e],stringifyField:t=>t.toString(),tokenize:t=>t.split(se),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},Re={combineWith:ie,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},Ae={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},ve={minDirtFactor:.1,minDirtCount:20},Oe={batchSize:1e3,batchWait:10,...ve},Se=Symbol("*"),ye=(t,e=ie)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in fe))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(fe[n])},Ne=(t,e,n,r,s,i,o,a,u,c=new Map)=>{if(null==i)return c;for(const d of Object.keys(o)){const l=o[d],h=t._fieldIds[d],f=i.get(h);if(null==f)continue;let p=f.size;const T=t._avgFieldLength[h];for(const i of f.keys()){if(!t._documentIds.has(i)){me(t,h,i,n),p-=1;continue}const o=a?a(t._documentIds.get(i),n,t._storedFields.get(i)):1;if(!o)continue;const E=f.get(i),m=t._fieldLength.get(i)[h],I=r*s*l*o*pe(E,p,t._documentCount,m,T,u),_=c.get(i);if(_){_.score+=I,ue(_.terms,e);const t=he(_.match,n);t?t.push(d):_.match[n]=[d]}else c.set(i,{score:I,terms:[e],match:{[n]:[d]}})}}return c},be=(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 i=r.boostDocument?r.boostDocument(s,"",t._storedFields.get(e)):1;n.set(e,{score:i,terms:[],match:{}})}return n})(t,n);if("string"!=typeof e){const r={...n,...e,queries:void 0},s=e.queries.map((e=>be(t,e,r)));return ye(s,r.combineWith)}const{tokenize:r,processTerm:s,searchOptions:i}=t._options,o={tokenize:r,processTerm:s,...i,...n},{tokenize:a,processTerm:u}=o,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,n,r)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,n,r):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,n,r):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,n,r):1}))(o)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},s=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:he(r.boost,e)||1})),{}),{boostDocument:i,weights:o,maxFuzzy:a,bm25:u}=r,{fuzzy:c,prefix:d}={...Re.weights,...o},l=t._index.get(e.term),h=Ne(t,e.term,e.term,1,e.termBoost,l,s,i,u);let f,p;if(e.prefix&&(f=t._index.atPrefix(e.term)),e.fuzzy){const n=!0===e.fuzzy?.2:e.fuzzy,r=n<1?Math.min(a,Math.round(e.term.length*n)):n;r&&(p=t._index.fuzzyGet(e.term,r))}if(f)for(const[n,r]of f){const o=n.length-e.term.length;if(!o)continue;p?.delete(n);const a=d*n.length/(n.length+.3*o);Ne(t,e.term,n,a,e.termBoost,r,s,i,u,h)}if(p)for(const n of p.keys()){const[r,o]=p.get(n);if(!o)continue;const a=c*n.length/(n.length+o);Ne(t,e.term,n,a,e.termBoost,r,s,i,u,h)}return h})(t,e,o)));return ye(c,o.combineWith)};class we{_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?Oe:t.autoVacuum;this._options={...ge,...t,autoVacuum:e,searchOptions:{...Re,...t.searchOptions},autoSuggestOptions:{...Ae,...t.autoSuggestOptions}},this._index=new Qt,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=ve,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 Pe;function xe(t){switch(t){case 0:case"LOCATION_TYPE_UNSPECIFIED":return Pe.LOCATION_TYPE_UNSPECIFIED;case 1:case"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM":return Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case 2:case"LOCATION_TYPE_STATION":return Pe.LOCATION_TYPE_STATION;case 3:case"LOCATION_TYPE_ENTRANCE_EXIT":return Pe.LOCATION_TYPE_ENTRANCE_EXIT;case 4:case"LOCATION_TYPE_GENERIC_NODE":return Pe.LOCATION_TYPE_GENERIC_NODE;case 5:case"LOCATION_TYPE_BOARDING_AREA":return Pe.LOCATION_TYPE_BOARDING_AREA;default:return Pe.UNRECOGNIZED}}!function(t){t[t.LOCATION_TYPE_UNSPECIFIED=0]="LOCATION_TYPE_UNSPECIFIED",t[t.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM=1]="LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM",t[t.LOCATION_TYPE_STATION=2]="LOCATION_TYPE_STATION",t[t.LOCATION_TYPE_ENTRANCE_EXIT=3]="LOCATION_TYPE_ENTRANCE_EXIT",t[t.LOCATION_TYPE_GENERIC_NODE=4]="LOCATION_TYPE_GENERIC_NODE",t[t.LOCATION_TYPE_BOARDING_AREA=5]="LOCATION_TYPE_BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(Pe||(Pe={}));const Le={encode(t,e=new N){""!==t.name&&e.uint32(10).string(t.name),void 0!==t.sourceStopId&&e.uint32(18).string(t.sourceStopId),void 0!==t.lat&&e.uint32(29).float(t.lat),void 0!==t.lon&&e.uint32(37).float(t.lon),e.uint32(42).fork();for(const n of t.children)e.uint32(n);return e.join(),void 0!==t.parent&&e.uint32(48).uint32(t.parent),0!==t.locationType&&e.uint32(56).int32(t.locationType),void 0!==t.platform&&e.uint32(66).string(t.platform),e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={name:"",sourceStopId:void 0,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(18!==t)break;s.sourceStopId=n.string();continue;case 3:if(29!==t)break;s.lat=n.float();continue;case 4:if(37!==t)break;s.lon=n.float();continue;case 5:if(40===t){s.children.push(n.uint32());continue}if(42===t){const t=n.uint32()+n.pos;for(;n.pos<t;)s.children.push(n.uint32());continue}break;case 6:if(48!==t)break;s.parent=n.uint32();continue;case 7:if(56!==t)break;s.locationType=n.int32();continue;case 8:if(66!==t)break;s.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({name:Ye(t.name)?globalThis.String(t.name):"",sourceStopId:Ye(t.sourceStopId)?globalThis.String(t.sourceStopId):void 0,lat:Ye(t.lat)?globalThis.Number(t.lat):void 0,lon:Ye(t.lon)?globalThis.Number(t.lon):void 0,children:globalThis.Array.isArray(null==t?void 0:t.children)?t.children.map((t=>globalThis.Number(t))):[],parent:Ye(t.parent)?globalThis.Number(t.parent):void 0,locationType:Ye(t.locationType)?xe(t.locationType):0,platform:Ye(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const n={};return""!==t.name&&(n.name=t.name),void 0!==t.sourceStopId&&(n.sourceStopId=t.sourceStopId),void 0!==t.lat&&(n.lat=t.lat),void 0!==t.lon&&(n.lon=t.lon),(null===(e=t.children)||void 0===e?void 0:e.length)&&(n.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(n.parent=Math.round(t.parent)),0!==t.locationType&&(n.locationType=function(t){switch(t){case Pe.LOCATION_TYPE_UNSPECIFIED:return"LOCATION_TYPE_UNSPECIFIED";case Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM";case Pe.LOCATION_TYPE_STATION:return"LOCATION_TYPE_STATION";case Pe.LOCATION_TYPE_ENTRANCE_EXIT:return"LOCATION_TYPE_ENTRANCE_EXIT";case Pe.LOCATION_TYPE_GENERIC_NODE:return"LOCATION_TYPE_GENERIC_NODE";case Pe.LOCATION_TYPE_BOARDING_AREA:return"LOCATION_TYPE_BOARDING_AREA";case Pe.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>Le.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s,i,o,a,u;const c={name:"",sourceStopId:void 0,lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};return c.name=null!==(e=t.name)&&void 0!==e?e:"",c.sourceStopId=null!==(n=t.sourceStopId)&&void 0!==n?n:void 0,c.lat=null!==(r=t.lat)&&void 0!==r?r:void 0,c.lon=null!==(s=t.lon)&&void 0!==s?s:void 0,c.children=(null===(i=t.children)||void 0===i?void 0:i.map((t=>t)))||[],c.parent=null!==(o=t.parent)&&void 0!==o?o:void 0,c.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,c.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,c}};const Ce={encode(t,e=new N){for(const n of t.stops)Le.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof b?t:new b(t),r=void 0===e?n.len:n.pos+e,s={stops:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 2:if(18!==t)break;s.stops.push(Le.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>Le.fromJSON(t))):[]}),toJSON(t){var e;const n={};return(null===(e=t.stops)||void 0===e?void 0:e.length)&&(n.stops=t.stops.map((t=>Le.toJSON(t)))),n},create:t=>Ce.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={stops:[]};return n.stops=(null===(e=t.stops)||void 0===e?void 0:e.map((t=>Le.fromPartial(t))))||[],n}};function Ye(t){return null!=t}const Me=t=>({stops:t.map((t=>{return{name:(e=t).name,sourceStopId:e.sourceStopId,lat:e.lat,lon:e.lon,children:e.children,parent:e.parent,locationType:ke(e.locationType),platform:e.platform};var e}))}),Fe=t=>t.stops.map(((t,e)=>{return{id:e,sourceStopId:(n=t).sourceStopId,name:n.name,lat:n.lat,lon:n.lon,children:n.children,parent:n.parent,locationType:De(n.locationType),platform:n.platform};var n})),De=t=>{switch(t){case Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Pe.LOCATION_TYPE_STATION:return"STATION";case Pe.LOCATION_TYPE_ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Pe.LOCATION_TYPE_GENERIC_NODE:return"GENERIC_NODE";case Pe.LOCATION_TYPE_BOARDING_AREA:return"BOARDING_AREA";case Pe.LOCATION_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf location type.");case Pe.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},ke=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return Pe.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case"STATION":return Pe.LOCATION_TYPE_STATION;case"ENTRANCE_EXIT":return Pe.LOCATION_TYPE_ENTRANCE_EXIT;case"GENERIC_NODE":return Pe.LOCATION_TYPE_GENERIC_NODE;case"BOARDING_AREA":return Pe.LOCATION_TYPE_BOARDING_AREA}};class Be{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const n=new Map;this.stopPoints=[];for(let r=0;r<t.length;r++){const s=t[r];void 0!==s.sourceStopId&&this.sourceStopsMap.set(s.sourceStopId,r);const i=null!==(e=s.parent)&&void 0!==e?e:r;n.has(i)||n.set(i,{id:i,name:s.parent?this.stops[s.parent].name:s.name}),s.lat&&s.lon&&this.stopPoints.push({id:r,lat:s.lat,lon:s.lon})}this.textIndex=new we({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:Ue});const r=Array.from(n.values());((t,e)=>{for(const n of e)_e(t,n)})(this.textIndex,r),this.geoIndex=new kt(this.stopPoints.length);for(let t=0;t<this.stopPoints.length;t++){const{lat:e,lon:n}=this.stopPoints[t];this.geoIndex.add(n,e)}this.geoIndex.finish()}static fromData(t){const e=new b(t),n=Ce.decode(e);return new Be(Fe(n))}serialize(){const t=Me(this.stops),e=new N;return Ce.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,s={...r,...n},i=be(t,e,n),o=[];for(const[e,{score:n,terms:r,match:a}]of i){const i=r.length||1,u={id:t._documentIds.get(e),score:n*i,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(u,t._storedFields.get(e)),(null==s.filter||s.filter(u))&&o.push(u)}return e===Se&&null==s.boostDocument||o.sort(de),o})(this.textIndex,t).map((t=>this.stops[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 i=1;const o=[];void 0===r&&(r=1/0),void 0!==s&&(i=Yt(s/6371));const a=new Ut([],Ct);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(n*xt);for(;u;){const s=u.right,d=u.left;if(s-d<=t.nodeSize)for(let r=d;r<=s;r++){const s=t.ids[r];{const i=Ft(e,n,t.coords[2*r],t.coords[2*r+1],c);a.push({id:s,dist:i})}}else{const r=d+s>>1,i=t.coords[2*r],o=t.coords[2*r+1],l=t.ids[r];{const t=Ft(e,n,i,o,c);a.push({id:l,dist:t})}const h=(u.axis+1)%2,f={left:d,right:r-1,axis:h,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?i:u.maxLng,maxLat:1===u.axis?o:u.maxLat,dist:0},p={left:r+1,right:s,axis:h,minLng:0===u.axis?i:u.minLng,minLat:1===u.axis?o:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};f.dist=Lt(e,n,c,f),p.dist=Lt(e,n,c,p),a.push(f),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>i)return o;if(o.push(t.id),o.length===r)return o}u=a.pop()}return o}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return s}findStopById(t){return this.stops[t]}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,n;const r=this.stops[t];if(!r)return[];const s=r.parent?null!==(n=null===(e=this.stops[r.parent])||void 0===e?void 0:e.children)&&void 0!==n?n:[]:r.children;return Array.from(new Set([t,...s])).map((t=>this.stops[t]))}*[Symbol.iterator](){for(const t of this.stops)yield t}}t.Plotter=class{constructor(t){this.result=t}stationNodeId(t){return`s_${t}`}vehicleEdgeNodeId(t,e,n,r){return`e_${t}_${e}_${n}_${r}`}transferEdgeNodeId(t,e,n){return`e_${t}_${e}_${n}`}accessEdgeNodeId(t,e){return`access_${t}_${e}`}continuationNodeId(t,e,n){return`continuation_${t}_${e}_${n}`}getRoundColor(t){var e;if(0===t)return r.colors.defaultRound;const n=Math.min(t-1,r.colors.rounds.length-1);return null!==(e=r.colors.rounds[n])&&void 0!==e?e:"#ee82ee"}getStationFillColor(t,e){return t?r.colors.originStation:e?r.colors.destinationStation:r.colors.defaultStation}escapeDotString(t){return t.replace(/\\/g,"\\\\").replace(/"/g,'\\"').replace(/\n/g,"\\n").replace(/\r/g,"\\r").replace(/\t/g,"\\t")}formatStopName(t){const e=this.result.stopsIndex.findStopById(t);if(!e)return`Unknown Stop (${t})`;const n=this.escapeDotString(e.name),r=e.platform?this.escapeDotString(e.platform):"";return r?`${n}\\nPl. ${r}`:n}getStationInfo(t){var e;return{isOrigin:void 0!==(null===(e=this.result.routingState.graph[0])||void 0===e?void 0:e[t]),isDestination:this.result.routingState.destinations.includes(t)}}getVehicleEdgeFromStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.stopIndex)}getVehicleEdgeToStopId(t){const e=this.result.timetable.getRoute(t.routeId);return null==e?void 0:e.stopId(t.hopOffStopIndex)}createStationNode(t){if(!this.result.stopsIndex.findStopById(t))return null;const e=this.formatStopName(t),n=this.escapeDotString(String(t)),r=this.stationNodeId(t),s=this.getStationInfo(t);return` "${r}" [label="${e}\\n${n}" shape=box style=filled fillcolor="${this.getStationFillColor(s.isOrigin,s.isDestination)}"];`}createVehicleEdge(t,n){const r=this.result.timetable.getRoute(t.routeId);if(!r)return[];const s=r.stopId(t.stopIndex),i=r.stopId(t.hopOffStopIndex),o=this.stationNodeId(s),a=this.stationNodeId(i),u=this.getRoundColor(n),c=this.vehicleEdgeNodeId(s,i,t.routeId,n),d=this.result.timetable.getServiceRouteInfo(r),l=d.name,h=d.type,f=e(r.departureFrom(t.stopIndex,t.tripIndex)),p=e(t.arrival),T=this.escapeDotString(l);return[` "${c}" [label="${`${this.escapeDotString(h)} ${T}\\n${`${t.routeId}:${t.tripIndex}`}\\n${f} → ${p}`}" shape=oval style=filled fillcolor="white" color="${u}"];`,` "${o}" -> "${c}" [color="${u}"];`,` "${c}" -> "${a}" [color="${u}"];`]}createAccessEdge(t){const e=this.stationNodeId(t.from),s=this.stationNodeId(t.to),i=r.colors.defaultRound,o=this.accessEdgeNodeId(t.from,t.to);return[` "${o}" [label="${`Walk\\n${n(t.duration)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${i}"];`,` "${e}" -> "${o}" [color="${i}" style="dashed"];`,` "${o}" -> "${s}" [color="${i}" style="dashed"];`]}createTransferEdge(t,e){const r=this.stationNodeId(t.from),s=this.stationNodeId(t.to),i=this.getRoundColor(e),o=this.transferEdgeNodeId(t.from,t.to,e),a=void 0!==t.minTransferTime?n(t.minTransferTime):"N/A";return[` "${o}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${i}"];`,` "${r}" -> "${o}" [color="${i}" style="dashed"];`,` "${o}" -> "${s}" [color="${i}" style="dashed"];`]}createContinuationEdge(t,n,s){var i,o;const a=this.getVehicleEdgeToStopId(t),u=this.getVehicleEdgeFromStopId(n);if(!a||!u)return[];const c=this.stationNodeId(a),d=this.stationNodeId(u),l=this.getRoundColor(s),h=this.continuationNodeId(a,u,s),f=this.result.timetable.getRoute(t.routeId),p=this.result.timetable.getRoute(n.routeId),T=f?this.result.timetable.getServiceRouteInfo(f):null,E=p?this.result.timetable.getServiceRouteInfo(p):null,m=null!==(i=null==T?void 0:T.name)&&void 0!==i?i:`Route ${String(t.routeId)}`,I=null!==(o=null==E?void 0:E.name)&&void 0!==o?o:`Route ${String(n.routeId)}`,_=(null==T?void 0:T.type)||"UNKNOWN",g=(null==E?void 0:E.type)||"UNKNOWN",R=e(t.arrival),A=p?e(p.departureFrom(n.stopIndex,n.tripIndex)):"N/A",v=this.escapeDotString(m),O=this.escapeDotString(I),S=this.escapeDotString(_),y=this.escapeDotString(g),N=`${S} ${v} (${`${t.routeId}:${t.tripIndex}`}) ${R}\\n↓\\n${y} ${O} (${`${n.routeId}:${n.tripIndex}`}) ${A}`,{continuationFill:b}=r.colors,{continuation:w,continuationEdge:U}=r.penWidth;return[` "${h}" [label="${N}" shape=oval style="filled,bold" fillcolor="${b}" color="${l}" penwidth="${w}"];`,` "${c}" -> "${h}" [color="${l}" style="bold" penwidth="${U}"];`,` "${h}" -> "${d}" [color="${l}" style="bold" penwidth="${U}"];`]}collectStations(){const t=new Set,e=this.result.routingState.graph;for(const n of e)for(let e=0;e<n.length;e++){const r=n[e];if(void 0!==r)if(t.add(e),s(r)){const e=this.getVehicleEdgeFromStopId(r),n=this.getVehicleEdgeToStopId(r);e&&t.add(e),n&&t.add(n)}else o(r)&&(t.add(r.from),t.add(r.to))}return t}collectContinuationChain(t,e){const n=[];let r=t,s=t.continuationOf;for(;s;){const t=this.createContinuationEdge(s,r,e);n.push(...t),r=s,s=s.continuationOf}return n}collectEdges(){const t=[],e=[],n=this.result.routingState.graph;for(let r=0;r<n.length;r++){const a=n[r];if(a)for(let n=0;n<a.length;n++){const u=a[n];void 0!==u&&(0!==r?s(u)?(t.push(...this.createVehicleEdge(u,r)),u.continuationOf&&e.push(...this.collectContinuationChain(u,r))):i(u)&&t.push(...this.createTransferEdge(u,r)):o(u)&&t.push(...this.createAccessEdge(u)))}}return[...t,...e]}plotDotGraph(){const t=this.collectStations(),e=this.collectEdges(),n=new a;n.addHeader(),n.addComment("Stations");for(const e of t){const t=this.createStationNode(e);t&&n.addRaw([t])}return n.addComment("Edges"),n.addRaw(e),n.build()}},t.Query=Et,t.RangeQuery=mt,t.RangeResult=yt,t.Result=Rt,t.Route=It,t.Router=class{constructor(t,e){const n=new wt(t),r=new At(t,e);this.plainRouter=new St(t,e,r,n),this.rangeRouter=new bt(t,e,r,n)}route(t){return this.plainRouter.route(t)}rangeRoute(t){return this.rangeRouter.rangeRoute(t)}},t.StopsIndex=Be,t.Timetable=Tt}));
|
|
2
2
|
//# sourceMappingURL=router.umd.js.map
|