minotor 11.1.0 → 11.1.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +3 -3
- package/dist/cli.mjs +316 -139
- package/dist/cli.mjs.map +1 -1
- package/dist/parser.cjs.js +71 -15
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.esm.js +71 -15
- package/dist/parser.esm.js.map +1 -1
- package/dist/router.cjs.js +1 -1
- package/dist/router.cjs.js.map +1 -1
- package/dist/router.esm.js +1 -1
- package/dist/router.esm.js.map +1 -1
- package/dist/router.umd.js +1 -1
- package/dist/router.umd.js.map +1 -1
- package/dist/routing/router.d.ts +28 -42
- package/dist/routing/state.d.ts +119 -0
- package/dist/timetable/route.d.ts +27 -0
- package/dist/timetable/timetable.d.ts +4 -0
- package/package.json +1 -1
- package/src/routing/__tests__/plotter.test.ts +47 -59
- package/src/routing/__tests__/result.test.ts +203 -267
- package/src/routing/plotter.ts +10 -7
- package/src/routing/result.ts +22 -20
- package/src/routing/router.ts +158 -143
- package/src/routing/state.ts +199 -0
- package/src/timetable/route.ts +47 -0
- package/src/timetable/timetable.ts +33 -18
package/dist/router.cjs.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
"use strict";const t=Number.MAX_SAFE_INTEGER,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 o(t){return"routeId"in t&&"stopIndex"in t&&"hopOffStopIndex"in t}function i(t){return"from"in t&&"to"in t&&"type"in t}class s{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(" "),o=r?` [${r}]`:"";return this.lines.push(` "${t}" -> "${e}"${o};`),this}addRaw(t){return this.lines.push(...t),this}build(){return this.lines.push("}"),this.lines.join("\n")}}function a(){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 u(t,e,n){for(let r=0;r<28;r+=7){const o=t>>>r,i=!(o>>>7==0&&0==e),s=255&(i?128|o:o);if(n.push(s),!i)return}const r=t>>>28&15|(7&e)<<4,o=!!(e>>3);if(n.push(255&(o?128|r:r)),o){for(let t=3;t<31;t+=7){const r=e>>>t,o=!(r>>>7==0),i=255&(o?128|r:r);if(n.push(i),!o)return}n.push(e>>>31&1)}}const c=4294967296;function d(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let r=0,o=0;function i(e,i){const s=Number(t.slice(e,i));o*=n,r=r*n+s,r>=c&&(o+=r/c|0,r%=c)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?h(r,o):f(r,o)}function l(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(c*e+t);const n=16777215&(t>>>24|e<<8),r=e>>16&65535;let o=(16777215&t)+6777216*n+6710656*r,i=n+8147497*r,s=2*r;const a=1e7;return o>=a&&(i+=Math.floor(o/a),o%=a),i>=a&&(s+=Math.floor(i/a),i%=a),s.toString()+p(i)+p(o)}function f(t,e){return{lo:0|t,hi:0|e}}function h(t,e){return e=~e,t?t=1+~t:e+=1,f(t,e)}const p=t=>{const e=String(t);return"0000000".slice(e.length)+e};function T(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 E(){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"),o=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const r="bigint"==typeof t?t:BigInt(t);if(r>n||r<e)throw new Error(`invalid int64: ${t}`);return r},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>o||e<r)throw new Error(`invalid uint64: ${t}`);return e},enc(e){return t.setBigInt64(0,this.parse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(e){return t.setBigInt64(0,this.uParse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigInt64(0,!0)),uDec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigUint64(0,!0))}}return{zero:"0",supported:!1,parse:t=>("string"!=typeof t&&(t=t.toString()),m(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),g(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),m(t),d(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),g(t),d(t)),dec:(t,e)=>function(t,e){let n=f(t,e);const r=2147483648&n.hi;r&&(n=h(n.lo,n.hi));const o=l(n.lo,n.hi);return r?"-"+o:o}(t,e),uDec:(t,e)=>l(t,e)}}function m(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function g(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const R=Symbol.for("@bufbuild/protobuf/text-encoding");function A(){if(null==globalThis[R]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[R]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[R]}var v;!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"}(v||(v={}));const O=34028234663852886e22,y=-34028234663852886e22;class S{constructor(t=A().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(w(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return b(t),T(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>O||t<y))throw new Error("invalid float32: "+t)}(t);let e=new Uint8Array(4);return new DataView(e.buffer).setFloat32(0,t,!0),this.raw(e)}double(t){let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t,!0),this.raw(e)}fixed32(t){w(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){b(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return b(t),T(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 u(e.lo,e.hi,this.buf),this}sint64(t){const e=I.enc(t),n=e.hi>>31;return u(e.lo<<1^n,(e.hi<<1|e.lo>>>31)^n,this.buf),this}uint64(t){const e=I.uEnc(t);return u(e.lo,e.hi,this.buf),this}}class N{constructor(t,e=A().decodeUtf8){this.decodeUtf8=e,this.varint64=a,this.uint32=E,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 v.Varint:for(;128&this.buf[this.pos++];);break;case v.Bit64:this.pos+=4;case v.Bit32:this.pos+=4;break;case v.LengthDelimited:let n=this.uint32();this.pos+=n;break;case v.StartGroup:for(;;){const[t,n]=this.tag();if(n===v.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 b(t){if("string"==typeof t)t=Number(t);else if("number"!=typeof t)throw new Error("invalid int32: "+typeof t);if(!Number.isInteger(t)||t>2147483647||t<-2147483648)throw new Error("invalid int32: "+t)}function w(t){if("string"==typeof t)t=Number(t);else if("number"!=typeof t)throw new Error("invalid uint32: "+typeof t);if(!Number.isInteger(t)||t>4294967295||t<0)throw new Error("invalid uint32: "+t)}var P,U;function x(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 L(t){switch(t){case 0:case"ROUTE_TYPE_UNSPECIFIED":return U.ROUTE_TYPE_UNSPECIFIED;case 1:case"ROUTE_TYPE_TRAM":return U.ROUTE_TYPE_TRAM;case 2:case"ROUTE_TYPE_SUBWAY":return U.ROUTE_TYPE_SUBWAY;case 3:case"ROUTE_TYPE_RAIL":return U.ROUTE_TYPE_RAIL;case 4:case"ROUTE_TYPE_BUS":return U.ROUTE_TYPE_BUS;case 5:case"ROUTE_TYPE_FERRY":return U.ROUTE_TYPE_FERRY;case 6:case"ROUTE_TYPE_CABLE_TRAM":return U.ROUTE_TYPE_CABLE_TRAM;case 7:case"ROUTE_TYPE_AERIAL_LIFT":return U.ROUTE_TYPE_AERIAL_LIFT;case 8:case"ROUTE_TYPE_FUNICULAR":return U.ROUTE_TYPE_FUNICULAR;case 9:case"ROUTE_TYPE_TROLLEYBUS":return U.ROUTE_TYPE_TROLLEYBUS;case 10:case"ROUTE_TYPE_MONORAIL":return U.ROUTE_TYPE_MONORAIL;default:return U.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"}(U||(U={}));const C={encode:(t,e=new S)=>(0!==t.stopTimes.length&&e.uint32(10).bytes(t.stopTimes),0!==t.pickupDropOffTypes.length&&e.uint32(18).bytes(t.pickupDropOffTypes),0!==t.stops.length&&e.uint32(26).bytes(t.stops),0!==t.serviceRouteId&&e.uint32(32).uint32(t.serviceRouteId),e),decode(t,e){const n=t instanceof N?t:new N(t),r=void 0===e?n.len:n.pos+e,o=Y();for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;o.stopTimes=n.bytes();continue;case 2:if(18!==t)break;o.pickupDropOffTypes=n.bytes();continue;case 3:if(26!==t)break;o.stops=n.bytes();continue;case 4:if(32!==t)break;o.serviceRouteId=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({stopTimes:G(t.stopTimes)?j(t.stopTimes):new Uint8Array(0),pickupDropOffTypes:G(t.pickupDropOffTypes)?j(t.pickupDropOffTypes):new Uint8Array(0),stops:G(t.stops)?j(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=z(t.stopTimes)),0!==t.pickupDropOffTypes.length&&(e.pickupDropOffTypes=z(t.pickupDropOffTypes)),0!==t.stops.length&&(e.stops=z(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,o;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!==(o=t.serviceRouteId)&&void 0!==o?o:0,i}};const M={encode:(t,e=new S)=>(0!==t.destination&&e.uint32(8).uint32(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).uint32(t.minTransferTime),e),decode(t,e){const n=t instanceof N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={destination:0,type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;o.destination=n.uint32();continue;case 2:if(16!==t)break;o.type=n.int32();continue;case 3:if(24!==t)break;o.minTransferTime=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({destination:G(t.destination)?globalThis.Number(t.destination):0,type:G(t.type)?x(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=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const o={destination:0,type:0,minTransferTime:void 0};return o.destination=null!==(e=t.destination)&&void 0!==e?e:0,o.type=null!==(n=t.type)&&void 0!==n?n:0,o.minTransferTime=null!==(r=t.minTransferTime)&&void 0!==r?r:void 0,o}};const F={encode:(t,e=new S)=>(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 N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={stopIndex:0,routeId:0,tripIndex:0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;o.stopIndex=n.uint32();continue;case 2:if(16!==t)break;o.routeId=n.uint32();continue;case 3:if(24!==t)break;o.tripIndex=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({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=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const o={stopIndex:0,routeId:0,tripIndex:0};return o.stopIndex=null!==(e=t.stopIndex)&&void 0!==e?e:0,o.routeId=null!==(n=t.routeId)&&void 0!==n?n:0,o.tripIndex=null!==(r=t.tripIndex)&&void 0!==r?r:0,o}};const D={encode(t,e=new S){void 0!==t.origin&&F.encode(t.origin,e.uint32(10).fork()).join();for(const n of t.destinations)F.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={origin:void 0,destinations:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;o.origin=F.decode(n,n.uint32());continue;case 2:if(18!==t)break;o.destinations.push(F.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({origin:G(t.origin)?F.fromJSON(t.origin):void 0,destinations:globalThis.Array.isArray(null==t?void 0:t.destinations)?t.destinations.map((t=>F.fromJSON(t))):[]}),toJSON(t){var e;const n={};return void 0!==t.origin&&(n.origin=F.toJSON(t.origin)),(null===(e=t.destinations)||void 0===e?void 0:e.length)&&(n.destinations=t.destinations.map((t=>F.toJSON(t)))),n},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={origin:void 0,destinations:[]};return n.origin=void 0!==t.origin&&null!==t.origin?F.fromPartial(t.origin):void 0,n.destinations=(null===(e=t.destinations)||void 0===e?void 0:e.map((t=>F.fromPartial(t))))||[],n}};const k={encode(t,e=new S){e.uint32(10).fork();for(const n of t.routes)e.uint32(n);e.join();for(const n of t.transfers)M.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={routes:[],transfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8===t){o.routes.push(n.uint32());continue}if(10===t){const t=n.uint32()+n.pos;for(;n.pos<t;)o.routes.push(n.uint32());continue}break;case 2:if(18!==t)break;o.transfers.push(M.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[],transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>M.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=>M.toJSON(t)))),r},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={routes:[],transfers:[]};return r.routes=(null===(e=t.routes)||void 0===e?void 0:e.map((t=>t)))||[],r.transfers=(null===(n=t.transfers)||void 0===n?void 0:n.map((t=>M.fromPartial(t))))||[],r}};const $={encode(t,e=new S){0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e.uint32(26).fork();for(const n of t.routes)e.uint32(n);return e.join(),e},decode(t,e){const n=t instanceof N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={type:0,name:"",routes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;o.type=n.int32();continue;case 2:if(18!==t)break;o.name=n.string();continue;case 3:if(24===t){o.routes.push(n.uint32());continue}if(26===t){const t=n.uint32()+n.pos;for(;n.pos<t;)o.routes.push(n.uint32());continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({type:G(t.type)?L(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 U.ROUTE_TYPE_UNSPECIFIED:return"ROUTE_TYPE_UNSPECIFIED";case U.ROUTE_TYPE_TRAM:return"ROUTE_TYPE_TRAM";case U.ROUTE_TYPE_SUBWAY:return"ROUTE_TYPE_SUBWAY";case U.ROUTE_TYPE_RAIL:return"ROUTE_TYPE_RAIL";case U.ROUTE_TYPE_BUS:return"ROUTE_TYPE_BUS";case U.ROUTE_TYPE_FERRY:return"ROUTE_TYPE_FERRY";case U.ROUTE_TYPE_CABLE_TRAM:return"ROUTE_TYPE_CABLE_TRAM";case U.ROUTE_TYPE_AERIAL_LIFT:return"ROUTE_TYPE_AERIAL_LIFT";case U.ROUTE_TYPE_FUNICULAR:return"ROUTE_TYPE_FUNICULAR";case U.ROUTE_TYPE_TROLLEYBUS:return"ROUTE_TYPE_TROLLEYBUS";case U.ROUTE_TYPE_MONORAIL:return"ROUTE_TYPE_MONORAIL";case U.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 o={type:0,name:"",routes:[]};return o.type=null!==(e=t.type)&&void 0!==e?e:0,o.name=null!==(n=t.name)&&void 0!==n?n:"",o.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],o}};const B={encode(t,e=new S){for(const n of t.stopsAdjacency)k.encode(n,e.uint32(10).fork()).join();for(const n of t.routesAdjacency)C.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)D.encode(n,e.uint32(34).fork()).join();for(const n of t.guaranteedTripTransfers)D.encode(n,e.uint32(42).fork()).join();return e},decode(t,e){const n=t instanceof N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;o.stopsAdjacency.push(k.decode(n,n.uint32()));continue;case 2:if(18!==t)break;o.routesAdjacency.push(C.decode(n,n.uint32()));continue;case 3:if(26!==t)break;o.serviceRoutes.push($.decode(n,n.uint32()));continue;case 4:if(34!==t)break;o.tripContinuations.push(D.decode(n,n.uint32()));continue;case 5:if(42!==t)break;o.guaranteedTripTransfers.push(D.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>k.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>C.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=>D.fromJSON(t))):[],guaranteedTripTransfers:globalThis.Array.isArray(null==t?void 0:t.guaranteedTripTransfers)?t.guaranteedTripTransfers.map((t=>D.fromJSON(t))):[]}),toJSON(t){var e,n,r,o,i;const s={};return(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(s.stopsAdjacency=t.stopsAdjacency.map((t=>k.toJSON(t)))),(null===(n=t.routesAdjacency)||void 0===n?void 0:n.length)&&(s.routesAdjacency=t.routesAdjacency.map((t=>C.toJSON(t)))),(null===(r=t.serviceRoutes)||void 0===r?void 0:r.length)&&(s.serviceRoutes=t.serviceRoutes.map((t=>$.toJSON(t)))),(null===(o=t.tripContinuations)||void 0===o?void 0:o.length)&&(s.tripContinuations=t.tripContinuations.map((t=>D.toJSON(t)))),(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.length)&&(s.guaranteedTripTransfers=t.guaranteedTripTransfers.map((t=>D.toJSON(t)))),s},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,o,i;const s={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};return s.stopsAdjacency=(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.map((t=>k.fromPartial(t))))||[],s.routesAdjacency=(null===(n=t.routesAdjacency)||void 0===n?void 0:n.map((t=>C.fromPartial(t))))||[],s.serviceRoutes=(null===(r=t.serviceRoutes)||void 0===r?void 0:r.map((t=>$.fromPartial(t))))||[],s.tripContinuations=(null===(o=t.tripContinuations)||void 0===o?void 0:o.map((t=>D.fromPartial(t))))||[],s.guaranteedTripTransfers=(null===(i=t.guaranteedTripTransfers)||void 0===i?void 0:i.map((t=>D.fromPartial(t))))||[],s}};function j(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 z(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 V=class t{constructor(t,e,n,r,o){this.id=t,this.stopTimes=e,this.pickupDropOffTypes=n,this.stops=r,this.serviceRouteId=o,this.nbStops=r.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<r.length;t++){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:o,serviceRouteId:i,trips:s}=e;if(0===s.length)throw new Error("At least one trip must be provided");const a=s[0],u=new Uint32Array(a.stops.map((t=>t.id))),c=u.length;for(let t=1;t<s.length;t++){const e=s[t];if(e.stops.length!==c)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${c}`);for(let n=0;n<c;n++)if(e.stops[n].id!==u[n])throw new Error(`Trip ${t} has different stop at index ${n}`)}const d=new Uint16Array(s.length*c*2);for(let t=0;t<s.length;t++){const e=s[t];for(let n=0;n<c;n++){const r=e.stops[n],o=2*(t*c+n);d[o]=r.arrivalTime,d[o+1]=r.departureTime}}const l=s.length*c,f=new Uint8Array(Math.ceil(l/2));for(let t=0;t<s.length;t++){const e=s[t];for(let o=0;o<c;o++){const i=e.stops[o],s=t*c+o,a=null!==(n=i.pickUpType)&&void 0!==n?n:0,u=null!==(r=i.dropOffType)&&void 0!==r?r:0,d=Math.floor(s/2),l=s%2==1;f[d]|=l?a<<6|u<<4:a<<2|u}}return new t(o,d,f,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}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=Math.floor(n/2),o=n%2==1,i=this.pickupDropOffTypes[r];if(void 0===i)throw new Error(`Pick up type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return o?i>>6&3:i>>2&3}dropOffTypeAt(t,e){const n=e*this.stops.length+t,r=Math.floor(n/2),o=n%2==1,i=this.pickupDropOffTypes[r];if(void 0===i)throw new Error(`Drop off type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return o?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 o=0,i=-1;for(;o<=r;){const n=o+r>>>1;this.departureFrom(t,n)<e?o=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 J=(BigInt(1)<<BigInt(20))-BigInt(1),W=1048575,Z=BigInt(0),q=BigInt(20),Q=BigInt(40),X=(t,e)=>{if(t<0||t>W)throw new Error(`${e} must be between 0 and 1048575, got ${t}`)},H=(t,e,n)=>(X(t,"stopIndex"),X(e,"routeId"),X(n,"tripIndex"),BigInt(t)<<Q|BigInt(e)<<q|BigInt(n)<<Z),K=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),tt=!0,et=t=>{if(K===tt)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint32(4*e,t[e],tt);return e},nt=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(K===tt)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint32(4*t,tt);return e},rt=t=>{if(K===tt)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],tt);return e},ot=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(K===tt)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint16(2*t,tt);return e},it=t=>{const e=[];return t.forEach((t=>{const n=t.serialize();e.push({stopTimes:rt(n.stopTimes),pickupDropOffTypes:n.pickupDropOffTypes,stops:et(n.stops),serviceRouteId:n.serviceRouteId})})),e},st=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.")}},at=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}},ut=t=>{switch(t){case U.ROUTE_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf route type.");case U.ROUTE_TYPE_TRAM:return"TRAM";case U.ROUTE_TYPE_SUBWAY:return"SUBWAY";case U.ROUTE_TYPE_RAIL:return"RAIL";case U.ROUTE_TYPE_BUS:return"BUS";case U.ROUTE_TYPE_FERRY:return"FERRY";case U.ROUTE_TYPE_CABLE_TRAM:return"CABLE_TRAM";case U.ROUTE_TYPE_AERIAL_LIFT:return"AERIAL_LIFT";case U.ROUTE_TYPE_FUNICULAR:return"FUNICULAR";case U.ROUTE_TYPE_TROLLEYBUS:return"TROLLEYBUS";case U.ROUTE_TYPE_MONORAIL:return"MONORAIL";case U.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},ct=t=>{switch(t){case"TRAM":return U.ROUTE_TYPE_TRAM;case"SUBWAY":return U.ROUTE_TYPE_SUBWAY;case"RAIL":return U.ROUTE_TYPE_RAIL;case"BUS":return U.ROUTE_TYPE_BUS;case"FERRY":return U.ROUTE_TYPE_FERRY;case"CABLE_TRAM":return U.ROUTE_TYPE_CABLE_TRAM;case"AERIAL_LIFT":return U.ROUTE_TYPE_AERIAL_LIFT;case"FUNICULAR":return U.ROUTE_TYPE_FUNICULAR;case"TROLLEYBUS":return U.ROUTE_TYPE_TROLLEYBUS;case"MONORAIL":return U.ROUTE_TYPE_MONORAIL}},dt=t=>{const e=[];for(const[r,o]of t.entries()){const[t,i,s]=(n=r,[Number(n>>Q&J),Number(n>>q&J),Number(n>>Z&J)]);e.push({origin:{stopIndex:t,routeId:i,tripIndex:s},destinations:o.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})))})}var n;return e},lt=t=>{const e=new Map;for(let n=0;n<t.length;n++){const r=t[n],o=r.origin,i=H(o.stopIndex,o.routeId,o.tripIndex),s=r.destinations.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(i,s)}return e},ft=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),ht=[];class pt{constructor(t,e,n,r,o){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=n,this.tripContinuations=r,this.guaranteedTripTransfers=o,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:at(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime}))):[],routes:t.routes})))),routesAdjacency:it(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:ct(t.type),name:t.name,routes:t.routes})))),tripContinuations:dt(this.tripContinuations||new Map),guaranteedTripTransfers:dt(this.guaranteedTripTransfers||new Map)};var e,n;const r=new S;return B.encode(t,r),r.finish()}static fromData(t){const e=new N(t),n=B.decode(e);return new pt((t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],o=[];for(let t=0;t<r.transfers.length;t++){const e=r.transfers[t],n=Object.assign({destination:e.destination,type:st(e.type)},void 0!==e.minTransferTime&&{minTransferTime:e.minTransferTime});o.push(n)}const i={routes:r.routes};o.length>0&&(i.transfers=o),e.push(i)}return e})(n.stopsAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],o=nt(r.stops);e.push(new V(n,ot(r.stopTimes),r.pickupDropOffTypes,o,r.serviceRouteId))}return e})(n.routesAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n];e.push({type:ut(r.type),name:r.name,routes:r.routes})}return e})(n.serviceRoutes),lt(n.tripContinuations),lt(n.guaranteedTripTransfers))}isActive(t){return this.activeStops.has(t)}getRoute(t){return this.routesAdjacency[t]}getTransfers(t){const e=this.stopsAdjacency[t];if(!e)throw new Error(`Stop ID ${t} not found`);return e.transfers||[]}getContinuousTrips(t,e,n){var r;const o=null===(r=this.tripContinuations)||void 0===r?void 0:r.get(H(t,e,n));return o||ht}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);return{type:e.type,name:e.name}}routesPassingThrough(t){const e=this.stopsAdjacency[t];if(!e)return[];const n=[];for(let t=0;t<e.routes.length;t++){const r=e.routes[t],o=this.routesAdjacency[r];o&&n.push(o)}return n}findReachableRoutes(t,e=ft){const n=new Map,r=Array.from(t);for(let t=0;t<r.length;t++){const o=r[t],i=this.routesPassingThrough(o).filter((t=>{const n=this.getServiceRouteInfo(t);return e.has(n.type)}));for(let t=0;t<i.length;t++){const e=i[t],r=e.stopRouteIndices(o)[0],s=n.get(e);void 0!==s?r<s&&n.set(e,r):n.set(e,r)}}return n}isTripTransferGuaranteed(t,e){var n;const r=H(t.stopIndex,t.routeId,t.tripIndex),o=null===(n=this.guaranteedTripTransfers)||void 0===n?void 0:n.get(r);return!!o&&o.some((t=>t.stopIndex===e.stopIndex&&t.routeId===e.routeId&&t.tripIndex===e.tripIndex))}getGuaranteedTripTransfers(t,e,n){var r;const o=null===(r=this.guaranteedTripTransfers)||void 0===r?void 0:r.get(H(t,e,n));return o||ht}}class Tt{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}Tt.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}build(){return new Tt(this)}};class Et{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;"minTransferTime"in n&&n.minTransferTime&&(t+=n.minTransferTime)}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 o=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,i=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,s="type"in t&&!("route"in t)?`Transfer: ${t.type}${t.minTransferTime?`, Minimum Transfer Time: ${n(t.minTransferTime)}`:""}`:"",a="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}:`,` ${o}`,` ${i}`,s?` ${s}`:"",a?` ${a}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}asJson(){return this.legs.map((t=>"route"in t?{from:t.from.id,to:t.to.id,departure:e(t.departureTime),arrival:e(t.arrivalTime),route:t.route}:Object.assign({from:t.from.id,to:t.to.id,type:t.type},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime})))}}const It=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],_t=t=>{const e=It[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};class mt{constructor(t,e,n,r){this.query=t,this.routingState=e,this.stopsIndex=n,this.timetable=r}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=t instanceof Set?t:t?[t]:this.query.to;let r,o;for(const t of n){const e=this.stopsIndex.equivalentStops(t);for(const t of e){const e=this.routingState.earliestArrivals.get(t.id);void 0!==e&&(void 0===o||e.arrival<o.arrival)&&(r=t.id,o=e)}}if(!r||!o)return;const i=[];let s,a=r,u=o.legNumber;for(;u>0;){const t=null===(e=this.routingState.graph[u])||void 0===e?void 0:e.get(a);if(!t)throw new Error(`No edge arriving at stop ${a} at round ${u}`);let n;if("routeId"in t){let e,r;if(t.continuationOf){let n=t;const o=[n];for(;n.continuationOf;)o.push(n.continuationOf),n=n.continuationOf;e=n,r=this.buildVehicleLeg(o)}else e=t,r=this.buildVehicleLeg([t]);n=r,s&&this.timetable.isTripTransferGuaranteed({stopIndex:e.hopOffStopIndex,routeId:e.routeId,tripIndex:e.tripIndex},{stopIndex:s.stopIndex,routeId:s.routeId,tripIndex:s.tripIndex})&&i.push(this.buildGuaranteedTransferLeg(e,s)),s=e}else{if(!("type"in t))break;n=this.buildTransferLeg(t),s=void 0}i.push(n),a=n.from.id,"routeId"in t&&(u-=1)}return new Et(i.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),o=this.timetable.getRoute(n.routeId);return{from:this.stopsIndex.findStopById(r.stopId(e.stopIndex)),to:this.stopsIndex.findStopById(o.stopId(n.hopOffStopIndex)),route:this.timetable.getServiceRouteInfo(r),departureTime:r.departureFrom(e.stopIndex,e.tripIndex),arrivalTime:n.arrival,pickUpType:_t(r.pickUpTypeFrom(e.stopIndex,e.tripIndex)),dropOffType:_t(o.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}}buildGuaranteedTransferLeg(t,e){const n=this.timetable.getRoute(t.routeId),r=this.timetable.getRoute(e.routeId),o=n.stopId(t.hopOffStopIndex),i=r.stopId(e.stopIndex);return{from:this.stopsIndex.findStopById(o),to:this.stopsIndex.findStopById(i),type:"GUARANTEED"}}arrivalAt(t,e){var n;const r=this.stopsIndex.equivalentStops(t);let o;for(const t of r){let r;if(void 0===e)r=this.routingState.earliestArrivals.get(t.id);else for(let o=e+1;o>=0;o--){const e=null===(n=this.routingState.graph[o])||void 0===n?void 0:n.get(t.id);if(void 0!==e){r={arrival:e.arrival,legNumber:o};break}}void 0!==r&&(void 0===o||r.arrival<o.arrival)&&(o=r)}return o}}const gt=t;class Rt{constructor(t=[],e=At){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,r=e[t];for(;t>0;){const o=t-1>>1,i=e[o];if(n(r,i)>=0)break;e[t]=i,t=o}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,o=e[t];for(;t<r;){let r=1+(t<<1),i=e[r];const s=r+1;if(s<this.length&&n(e[s],i)<0&&(r=s,i=e[s]),n(i,o)>=0)break;e[t]=i,t=r}e[t]=o}}function At(t,e){return t<e?-1:t>e?1:0}const vt=Math.PI/180;function Ot(t,e,n,r){const o=r.minLng,i=r.maxLng,s=r.minLat,a=r.maxLat;if(t>=o&&t<=i)return e<s?St((e-s)*vt):e>a?St((e-a)*vt):0;const u=Math.min(St((t-o)*vt),St((t-i)*vt)),c=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*vt)/n)/vt}(e,u);return c>s&&c<a?Nt(u,n,e,c):Math.min(Nt(u,n,e,s),Nt(u,n,e,a))}function yt(t,e){return t.dist-e.dist}function St(t){const e=Math.sin(t/2);return e*e}function Nt(t,e,n,r){return e*Math.cos(r*vt)*t+St((n-r)*vt)}function bt(t,e,n,r,o){return Nt(St((t-n)*vt),o,e,r)}const wt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class Pt{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const r=n>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const o=wt[15&n];if(!o)throw new Error("Unrecognized array type.");const[i]=new Uint16Array(t,2,1),[s]=new Uint32Array(t,4,1);return new Pt(s,i,o,t)}constructor(t,e=64,n=Float64Array,r){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const o=wt.indexOf(this.ArrayType),i=2*t*this.ArrayType.BYTES_PER_ELEMENT,s=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-s%8)%8;if(o<0)throw new Error(`Unexpected typed array class: ${n}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+i+s+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+o]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return Ut(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:o,coords:i,nodeSize:s}=this,a=[0,o.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,d=a.pop()||0,l=a.pop()||0;if(d-l<=s){for(let s=l;s<=d;s++){const a=i[2*s],c=i[2*s+1];a>=t&&a<=n&&c>=e&&c<=r&&u.push(o[s])}continue}const f=l+d>>1,h=i[2*f],p=i[2*f+1];h>=t&&h<=n&&p>=e&&p<=r&&u.push(o[f]),(0===c?t<=h:e<=p)&&(a.push(l),a.push(f-1),a.push(1-c)),(0===c?n>=h:r>=p)&&(a.push(f+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:o,nodeSize:i}=this,s=[0,r.length-1,0],a=[],u=n*n;for(;s.length;){const c=s.pop()||0,d=s.pop()||0,l=s.pop()||0;if(d-l<=i){for(let n=l;n<=d;n++)Ct(o[2*n],o[2*n+1],t,e)<=u&&a.push(r[n]);continue}const f=l+d>>1,h=o[2*f],p=o[2*f+1];Ct(h,p,t,e)<=u&&a.push(r[f]),(0===c?t-n<=h:e-n<=p)&&(s.push(l),s.push(f-1),s.push(1-c)),(0===c?t+n>=h:e+n>=p)&&(s.push(f+1),s.push(d),s.push(1-c))}return a}}function Ut(t,e,n,r,o,i){if(o-r<=n)return;const s=r+o>>1;xt(t,e,s,r,o,i),Ut(t,e,n,r,s-1,1-i),Ut(t,e,n,s+1,o,1-i)}function xt(t,e,n,r,o,i){for(;o>r;){if(o-r>600){const s=o-r+1,a=n-r+1,u=Math.log(s),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(s-c)/s)*(a-s/2<0?-1:1);xt(t,e,n,Math.max(r,Math.floor(n-a*c/s+d)),Math.min(o,Math.floor(n+(s-a)*c/s+d)),i)}const s=e[2*n+i];let a=r,u=o;for(Lt(t,e,r,n),e[2*o+i]>s&&Lt(t,e,r,o);a<u;){for(Lt(t,e,a,u),a++,u--;e[2*a+i]<s;)a++;for(;e[2*u+i]>s;)u--}e[2*r+i]===s?Lt(t,e,r,u):(u++,Lt(t,e,u,o)),u<=n&&(r=u+1),n<=u&&(o=u-1)}}function Lt(t,e,n,r){Yt(t,n,r),Yt(e,2*n,2*r),Yt(e,2*n+1,2*r+1)}function Yt(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function Ct(t,e,n,r){const o=t-n,i=e-r;return o*o+i*i}const Mt="KEYS",Ft="VALUES";class Dt{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}=kt(this._path);if(""===kt(e))return{done:!1,value:this.result()};const n=t.get(kt(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=kt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>kt(t))).filter((t=>""!==t)).join("")}value(){return kt(this._path).node.get("")}result(){switch(this._type){case Ft:return this.value();case Mt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const kt=t=>t[t.length-1],$t=(t,e,n,r,o,i,s,a)=>{const u=i*s;t:for(const c of t.keys())if(""===c){const e=o[u-1];e<=n&&r.set(a,[t.get(c),e])}else{let u=i;for(let t=0;t<c.length;++t,++u){const r=c[t],i=s*u,a=i-s;let d=o[i];const l=Math.max(0,u-n-1),f=Math.min(s-1,u+n);for(let t=l;t<f;++t){const n=r!==e[t],s=o[a+t]+ +n,u=o[a+t+1]+1,c=o[i+t]+1,l=o[i+t+1]=Math.min(s,u,c);l<d&&(d=l)}if(d>n)continue t}$t(t.get(c),e,n,r,o,u,s,a+c)}};class Bt{_tree;_prefix;_size=void 0;constructor(t=new Map,e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,n]=jt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=Zt(n);for(const n of e.keys())if(""!==n&&n.startsWith(r)){const o=new Map;return o.set(n.slice(r.length),e.get(n)),new Bt(o,t)}}return new Bt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Vt(this._tree,t)}entries(){return new Dt(this,"ENTRIES")}forEach(t){for(const[e,n]of this)t(e,n,this)}fuzzyGet(t,e){return((t,e,n)=>{const r=new Map;if("string"!=typeof e)return r;const o=e.length+1,i=o+n,s=new Uint8Array(i*o).fill(n+1);for(let t=0;t<o;++t)s[t]=t;for(let t=1;t<i;++t)s[t*o]=t;return $t(t,e,n,r,s,1,o,""),r})(this._tree,t,e)}get(t){const e=zt(this._tree,t);return void 0!==e?e.get(""):void 0}has(t){return zt(this._tree,t)?.has("")??!1}keys(){return new Dt(this,Mt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Gt(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=Gt(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=Gt(this._tree,t);let r=n.get("");return void 0===r&&n.set("",r=e()),r}values(){return new Dt(this,Ft)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Bt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return Bt.from(Object.entries(t))}}const jt=(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]),jt(t.get(r),e.slice(r.length),n);return n.push([t,e]),jt(void 0,"",n)},zt=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(""!==n&&e.startsWith(n))return zt(t.get(n),e.slice(n.length))},Gt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const o of t.keys())if(""!==o&&e[r]===o[0]){const i=Math.min(n-r,o.length);let s=1;for(;s<i&&e[r+s]===o[s];)++s;const a=t.get(o);if(s===o.length)t=a;else{const n=new Map;n.set(o.slice(s),a),t.set(e.slice(r,r+s),n),t.delete(o),t=n}r+=s;continue t}const o=new Map;return t.set(e.slice(r),o),o}return t},Vt=(t,e)=>{const[n,r]=jt(t,e);if(void 0!==n)if(n.delete(""),0===n.size)Jt(r);else if(1===n.size){const[t,e]=n.entries().next().value;Wt(r,t,e)}},Jt=t=>{if(0===t.length)return;const[e,n]=Zt(t);if(e.delete(n),0===e.size)Jt(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;""!==n&&Wt(t.slice(0,-1),n,r)}},Wt=(t,e,n)=>{if(0===t.length)return;const[r,o]=Zt(t);r.set(o+e,n),r.delete(o)},Zt=t=>t[t.length-1],qt=/[\n\r\p{Z}\p{P}]+/u,Qt="or",Xt="and",Ht="and_not",Kt=(t,e)=>{t.includes(e)||t.push(e)},te=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},ee=({score:t},{score:e})=>e-t,ne=()=>new Map,re=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,oe={[Qt]:(t,e)=>{for(const n of e.keys()){const r=t.get(n);if(null==r)t.set(n,e.get(n));else{const{score:t,terms:o,match:i}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,i),te(r.terms,o)}}return t},[Xt]:(t,e)=>{const n=new Map;for(const r of e.keys()){const o=t.get(r);if(null==o)continue;const{score:i,terms:s,match:a}=e.get(r);te(o.terms,s),n.set(r,{score:o.score+i,terms:o.terms,match:Object.assign(o.match,a)})}return n},[Ht]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},ie=(t,e,n,r,o,i)=>{const{k:s,b:a,d:u}=i;return Math.log(1+(n-e+.5)/(e+.5))*(u+t*(s+1)/(t+s*(1-a+a*r/o)))},se=(t,e,n,r)=>{for(const o of Object.keys(t._fieldIds))if(t._fieldIds[o]===n)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${r}" was not present in field "${o}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},ae=(t,e,n,r)=>{const o=t._index.fetch(r,ne);let i=o.get(e);if(null==i)i=new Map,i.set(n,1),o.set(e,i);else{const t=i.get(n);i.set(n,(t??0)+1)}},ue=(t,e,n,r)=>{if(!t._index.has(r))return void se(t,n,e,r);const o=t._index.fetch(r,ne),i=o.get(e),s=i?.get(n);!i||typeof s>"u"?se(t,n,e,r):s<=1?i.size<=1?o.delete(e):i.delete(n):i.set(n,s-1),0===t._index.get(r).size&&t._index.delete(r)},ce=(t,e,n,r,o)=>{let i=t._fieldLength.get(e);null==i&&t._fieldLength.set(e,i=[]),i[n]=o;const s=(t._avgFieldLength[n]||0)*r+o;t._avgFieldLength[n]=s/(r+1)},de=(t,e)=>{const{extractField:n,stringifyField:r,tokenize:o,processTerm:i,fields:s,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:o}=t._options;if(0===r?.length)return;let i=t._storedFields.get(e);void 0===i&&t._storedFields.set(e,i={});for(const t of r){const e=o(n,t);null!=e&&(i[t]=e)}})(t,c,e);for(const a of s){const s=n(e,a);if(null==s)continue;const u=o(r(s,a),a),d=t._fieldIds[a],l=new Set(u).size;ce(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)ae(t,d,c,e);else n&&ae(t,d,c,n)}}},le={idField:"id",extractField:(t,e)=>t[e],stringifyField:t=>t.toString(),tokenize:t=>t.split(qt),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},fe={combineWith:Qt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},he={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},pe={minDirtFactor:.1,minDirtCount:20},Te={batchSize:1e3,batchWait:10,...pe},Ee=Symbol("*"),Ie=(t,e=Qt)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in oe))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(oe[n])},_e=(t,e,n,r,o,i,s,a,u,c=new Map)=>{if(null==i)return c;for(const d of Object.keys(s)){const l=s[d],f=t._fieldIds[d],h=i.get(f);if(null==h)continue;let p=h.size;const T=t._avgFieldLength[f];for(const i of h.keys()){if(!t._documentIds.has(i)){ue(t,f,i,n),p-=1;continue}const s=a?a(t._documentIds.get(i),n,t._storedFields.get(i)):1;if(!s)continue;const E=h.get(i),I=t._fieldLength.get(i)[f],_=r*o*l*s*ie(E,p,t._documentCount,I,T,u),m=c.get(i);if(m){m.score+=_,Kt(m.terms,e);const t=re(m.match,n);t?t.push(d):m.match[n]=[d]}else c.set(i,{score:_,terms:[e],match:{[n]:[d]}})}}return c},me=(t,e,n={})=>{if(e===Ee)return((t,e)=>{const n=new Map,r={...t._options.searchOptions,...e};for(const[e,o]of t._documentIds){const i=r.boostDocument?r.boostDocument(o,"",t._storedFields.get(e)):1;n.set(e,{score:i,terms:[],match:{}})}return n})(t,n);if("string"!=typeof e){const r={...n,...e,queries:void 0},o=e.queries.map((e=>me(t,e,r)));return Ie(o,r.combineWith)}const{tokenize:r,processTerm:o,searchOptions:i}=t._options,s={tokenize:r,processTerm:o,...i,...n},{tokenize:a,processTerm:u}=s,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,n,r)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,n,r):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,n,r):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,n,r):1}))(s)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},o=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:re(r.boost,e)||1})),{}),{boostDocument:i,weights:s,maxFuzzy:a,bm25:u}=r,{fuzzy:c,prefix:d}={...fe.weights,...s},l=t._index.get(e.term),f=_e(t,e.term,e.term,1,e.termBoost,l,o,i,u);let h,p;if(e.prefix&&(h=t._index.atPrefix(e.term)),e.fuzzy){const n=!0===e.fuzzy?.2:e.fuzzy,r=n<1?Math.min(a,Math.round(e.term.length*n)):n;r&&(p=t._index.fuzzyGet(e.term,r))}if(h)for(const[n,r]of h){const s=n.length-e.term.length;if(!s)continue;p?.delete(n);const a=d*n.length/(n.length+.3*s);_e(t,e.term,n,a,e.termBoost,r,o,i,u,f)}if(p)for(const n of p.keys()){const[r,s]=p.get(n);if(!s)continue;const a=c*n.length/(n.length+s);_e(t,e.term,n,a,e.termBoost,r,o,i,u,f)}return f})(t,e,s)));return Ie(c,s.combineWith)};class ge{_options;_index;_documentCount;_documentIds;_idToShortId;_fieldIds;_fieldLength;_avgFieldLength;_nextId;_storedFields;_dirtCount;_currentVacuum;_enqueuedVacuum;_enqueuedVacuumConditions;constructor(t){if(!t?.fields)throw new Error('SlimSearch: option "fields" must be provided');const e=null==t.autoVacuum||!0===t.autoVacuum?Te:t.autoVacuum;this._options={...le,...t,autoVacuum:e,searchOptions:{...fe,...t.searchOptions},autoSuggestOptions:{...he,...t.autoSuggestOptions}},this._index=new Bt,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=pe,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 Re=t=>{const e=t.toLowerCase(),n=new Set([e]),r={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,o]of Object.entries(r))e.includes(t)&&o.forEach((r=>{n.add(e.replace(t,r))})),o.forEach((r=>{e.includes(r)&&n.add(e.replace(r,t))}));return Array.from(n)};var Ae;function ve(t){switch(t){case 0:case"LOCATION_TYPE_UNSPECIFIED":return Ae.LOCATION_TYPE_UNSPECIFIED;case 1:case"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM":return Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case 2:case"LOCATION_TYPE_STATION":return Ae.LOCATION_TYPE_STATION;case 3:case"LOCATION_TYPE_ENTRANCE_EXIT":return Ae.LOCATION_TYPE_ENTRANCE_EXIT;case 4:case"LOCATION_TYPE_GENERIC_NODE":return Ae.LOCATION_TYPE_GENERIC_NODE;case 5:case"LOCATION_TYPE_BOARDING_AREA":return Ae.LOCATION_TYPE_BOARDING_AREA;default:return Ae.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"}(Ae||(Ae={}));const Oe={encode(t,e=new S){""!==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 N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={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;o.name=n.string();continue;case 2:if(18!==t)break;o.sourceStopId=n.string();continue;case 3:if(29!==t)break;o.lat=n.float();continue;case 4:if(37!==t)break;o.lon=n.float();continue;case 5:if(40===t){o.children.push(n.uint32());continue}if(42===t){const t=n.uint32()+n.pos;for(;n.pos<t;)o.children.push(n.uint32());continue}break;case 6:if(48!==t)break;o.parent=n.uint32();continue;case 7:if(56!==t)break;o.locationType=n.int32();continue;case 8:if(66!==t)break;o.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({name:Se(t.name)?globalThis.String(t.name):"",sourceStopId:Se(t.sourceStopId)?globalThis.String(t.sourceStopId):void 0,lat:Se(t.lat)?globalThis.Number(t.lat):void 0,lon:Se(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:Se(t.parent)?globalThis.Number(t.parent):void 0,locationType:Se(t.locationType)?ve(t.locationType):0,platform:Se(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 Ae.LOCATION_TYPE_UNSPECIFIED:return"LOCATION_TYPE_UNSPECIFIED";case Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM";case Ae.LOCATION_TYPE_STATION:return"LOCATION_TYPE_STATION";case Ae.LOCATION_TYPE_ENTRANCE_EXIT:return"LOCATION_TYPE_ENTRANCE_EXIT";case Ae.LOCATION_TYPE_GENERIC_NODE:return"LOCATION_TYPE_GENERIC_NODE";case Ae.LOCATION_TYPE_BOARDING_AREA:return"LOCATION_TYPE_BOARDING_AREA";case Ae.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>Oe.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,o,i,s,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!==(o=t.lon)&&void 0!==o?o:void 0,c.children=(null===(i=t.children)||void 0===i?void 0:i.map((t=>t)))||[],c.parent=null!==(s=t.parent)&&void 0!==s?s:void 0,c.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,c.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,c}};const ye={encode(t,e=new S){for(const n of t.stops)Oe.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof N?t:new N(t),r=void 0===e?n.len:n.pos+e,o={stops:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 2:if(18!==t)break;o.stops.push(Oe.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return o},fromJSON:t=>({stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>Oe.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=>Oe.toJSON(t)))),n},create:t=>ye.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=>Oe.fromPartial(t))))||[],n}};function Se(t){return null!=t}const Ne=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:Pe(e.locationType),platform:e.platform};var e}))}),be=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:we(n.locationType),platform:n.platform};var n})),we=t=>{switch(t){case Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Ae.LOCATION_TYPE_STATION:return"STATION";case Ae.LOCATION_TYPE_ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Ae.LOCATION_TYPE_GENERIC_NODE:return"GENERIC_NODE";case Ae.LOCATION_TYPE_BOARDING_AREA:return"BOARDING_AREA";case Ae.LOCATION_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf location type.");case Ae.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},Pe=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case"STATION":return Ae.LOCATION_TYPE_STATION;case"ENTRANCE_EXIT":return Ae.LOCATION_TYPE_ENTRANCE_EXIT;case"GENERIC_NODE":return Ae.LOCATION_TYPE_GENERIC_NODE;case"BOARDING_AREA":return Ae.LOCATION_TYPE_BOARDING_AREA}};class Ue{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const n=new Map;this.stopPoints=[];for(let r=0;r<t.length;r++){const o=t[r];void 0!==o.sourceStopId&&this.sourceStopsMap.set(o.sourceStopId,r);const i=null!==(e=o.parent)&&void 0!==e?e:r;n.has(i)||n.set(i,{id:i,name:o.parent?this.stops[o.parent].name:o.name}),o.lat&&o.lon&&this.stopPoints.push({id:r,lat:o.lat,lon:o.lon})}this.textIndex=new ge({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:Re});const r=Array.from(n.values());((t,e)=>{for(const n of e)de(t,n)})(this.textIndex,r),this.geoIndex=new Pt(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 N(t),n=ye.decode(e);return new Ue(be(n))}serialize(){const t=Ne(this.stops),e=new S;return ye.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,o={...r,...n},i=me(t,e,n),s=[];for(const[e,{score:n,terms:r,match:a}]of i){const i=r.length||1,u={id:t._documentIds.get(e),score:n*i,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(u,t._storedFields.get(e)),(null==o.filter||o.filter(u))&&s.push(u)}return e===Ee&&null==o.boostDocument||s.sort(ee),s})(this.textIndex,t).map((t=>this.stops[t.id])).slice(0,e)}findStopsByLocation(t,e,n=5,r=.5){const o=function(t,e,n,r=1/0,o=1/0){let i=1;const s=[];void 0===r&&(r=1/0),void 0!==o&&(i=St(o/6371));const a=new Rt([],yt);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(n*vt);for(;u;){const o=u.right,d=u.left;if(o-d<=t.nodeSize)for(let r=d;r<=o;r++){const o=t.ids[r];{const i=bt(e,n,t.coords[2*r],t.coords[2*r+1],c);a.push({id:o,dist:i})}}else{const r=d+o>>1,i=t.coords[2*r],s=t.coords[2*r+1],l=t.ids[r];{const t=bt(e,n,i,s,c);a.push({id:l,dist:t})}const f=(u.axis+1)%2,h={left:d,right:r-1,axis:f,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?i:u.maxLng,maxLat:1===u.axis?s:u.maxLat,dist:0},p={left:r+1,right:o,axis:f,minLng:0===u.axis?i:u.minLng,minLat:1===u.axis?s:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};h.dist=Ot(e,n,c,h),p.dist=Ot(e,n,c,p),a.push(h),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>i)return s;if(s.push(t.id),s.length===r)return s}u=a.pop()}return s}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return o}findStopById(t){return this.stops[t]}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,n;const r=this.stops[t];if(!r)return[];const o=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,...o])).map((t=>this.stops[t]))}*[Symbol.iterator](){for(const t of this.stops)yield t}}exports.Plotter=class{constructor(t){this.result=t}stationNodeId(t){return`s_${t}`}vehicleEdgeNodeId(t,e,n,r){return`e_${t}_${e}_${n}_${r}`}transferEdgeNodeId(t,e,n){return`e_${t}_${e}_${n}`}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,n;return{isOrigin:null!==(n=null===(e=this.result.routingState.graph[0])||void 0===e?void 0:e.has(t))&&void 0!==n&&n,isDestination:this.result.routingState.destinations.includes(t)}}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),o=this.getStationInfo(t);return` "${r}" [label="${e}\\n${n}" shape=box style=filled fillcolor="${this.getStationFillColor(o.isOrigin,o.isDestination)}"];`}createVehicleEdge(t,n){const r=this.result.timetable.getRoute(t.routeId);if(!r)return[];const o=r.stopId(t.stopIndex),i=r.stopId(t.hopOffStopIndex),s=this.stationNodeId(o),a=this.stationNodeId(i),u=this.getRoundColor(n),c=this.vehicleEdgeNodeId(o,i,t.routeId,n),d=this.result.timetable.getServiceRouteInfo(r),l=d.name,f=d.type,h=e(r.departureFrom(t.stopIndex,t.tripIndex)),p=e(t.arrival),T=this.escapeDotString(l);return[` "${c}" [label="${`${this.escapeDotString(f)} ${T}\\n${`${t.routeId}:${t.tripIndex}`}\\n${h} → ${p}`}" shape=oval style=filled fillcolor="white" color="${u}"];`,` "${s}" -> "${c}" [color="${u}"];`,` "${c}" -> "${a}" [color="${u}"];`]}createTransferEdge(t,e){const r=this.stationNodeId(t.from),o=this.stationNodeId(t.to),i=this.getRoundColor(e),s=this.transferEdgeNodeId(t.from,t.to,e),a=void 0!==t.minTransferTime?n(t.minTransferTime):"N/A";return[` "${s}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${i}"];`,` "${r}" -> "${s}" [color="${i}" style="dashed"];`,` "${s}" -> "${o}" [color="${i}" style="dashed"];`]}createContinuationEdge(t,n,o){var i,s;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(o),f=this.continuationNodeId(a,u,o),h=this.result.timetable.getRoute(t.routeId),p=this.result.timetable.getRoute(n.routeId),T=h?this.result.timetable.getServiceRouteInfo(h):null,E=p?this.result.timetable.getServiceRouteInfo(p):null,I=null!==(i=null==T?void 0:T.name)&&void 0!==i?i:`Route ${String(t.routeId)}`,_=null!==(s=null==E?void 0:E.name)&&void 0!==s?s:`Route ${String(n.routeId)}`,m=(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(I),O=this.escapeDotString(_),y=this.escapeDotString(m),S=this.escapeDotString(g),N=`${y} ${v} (${`${t.routeId}:${t.tripIndex}`}) ${R}\\n↓\\n${S} ${O} (${`${n.routeId}:${n.tripIndex}`}) ${A}`,{continuationFill:b}=r.colors,{continuation:w,continuationEdge:P}=r.penWidth;return[` "${f}" [label="${N}" shape=oval style="filled,bold" fillcolor="${b}" color="${l}" penwidth="${w}"];`,` "${c}" -> "${f}" [color="${l}" style="bold" penwidth="${P}"];`,` "${f}" -> "${d}" [color="${l}" style="bold" penwidth="${P}"];`]}collectStations(){const t=new Set,e=this.result.routingState.graph;for(const n of e)for(const[e,r]of n)if(t.add(e),o(r)){const e=this.getVehicleEdgeFromStopId(r),n=this.getVehicleEdgeToStopId(r);e&&t.add(e),n&&t.add(n)}return t}collectContinuationChain(t,e){const n=[];let r=t,o=t.continuationOf;for(;o;){const t=this.createContinuationEdge(o,r,e);n.push(...t),r=o,o=o.continuationOf}return n}collectEdges(){const t=[],e=[],n=this.result.routingState.graph;for(let r=0;r<n.length;r++){const s=n[r];if(s&&0!==r)for(const n of s.values())o(n)?(t.push(...this.createVehicleEdge(n,r)),n.continuationOf&&e.push(...this.collectContinuationChain(n,r))):i(n)&&t.push(...this.createTransferEdge(n,r))}return[...t,...e]}plotDotGraph(){const t=this.collectStations(),e=this.collectEdges(),n=new s;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()}},exports.Query=Tt,exports.Result=mt,exports.Route=Et,exports.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}route(t){const e=this.initRoutingState(t),n=new Set;for(const t of e.graph[0].keys())n.add(t);const r=this.considerTransfers(t,0,n,e);for(const t of r)n.add(t);for(let r=1;r<=t.options.maxTransfers+1;r++){const o=new Map;e.graph.push(o);const i=this.timetable.findReachableRoutes(n,t.options.transportModes);n.clear();for(const[o,s]of i){const i=this.scanRoute(o,s,r,e,t.options);for(const t of i)n.add(t)}let s=this.findTripContinuations(n,o);for(;s.length>0;){const i=new Set;for(const n of s){const o=this.timetable.getRoute(n.routeId),s=this.scanRoute(o,n.stopIndex,r,e,t.options,n);for(const t of s)i.add(t)}for(const t of i)n.add(t);s=this.findTripContinuations(i,o)}const a=this.considerTransfers(t,r,n,e);for(const t of a)n.add(t);if(0===n.size)break}return new mt(t,e,this.stopsIndex,this.timetable)}findTripContinuations(t,e){const n=[];for(const r of t){const t=e.get(r);if(!t||!("routeId"in t))continue;const o=this.timetable.getContinuousTrips(t.hopOffStopIndex,t.routeId,t.tripIndex);for(let e=0;e<o.length;e++){const r=o[e];n.push({routeId:r.routeId,stopIndex:r.stopIndex,tripIndex:r.tripIndex,previousEdge:t})}}return n}initRoutingState(t){const{from:e,to:n,departureTime:r}=t,o=this.stopsIndex.equivalentStops(e).map((t=>t.id)),i=Array.from(n).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id)),s=new Map,a=new Map,u=[a],c={arrival:r,legNumber:0};for(const t of o)s.set(t,c),a.set(t,c);return{destinations:i,earliestArrivals:s,graph:u}}scanRoute(t,e,n,r,o,i){var s,a;const u=new Set;let c=i?{routeId:t.id,stopIndex:e,tripIndex:i.tripIndex}:void 0;const d=r.graph[n],l=r.graph[n-1],f=this.earliestArrivalAtAnyStop(r.earliestArrivals,r.destinations);for(let h=e;h<t.getNbStops();h++){const e=t.stops[h];if(void 0!==c){const o=t.arrivalAt(h,c.tripIndex),l=t.dropOffTypeAt(h,c.tripIndex),p=null!==(a=null===(s=r.earliestArrivals.get(e))||void 0===s?void 0:s.arrival)&&void 0!==a?a:gt;if(1!==l&&o<p&&o<f){const t={routeId:c.routeId,stopIndex:c.stopIndex,tripIndex:c.tripIndex,arrival:o,hopOffStopIndex:h};i&&(t.continuationOf=i.previousEdge),d.set(e,t),r.earliestArrivals.set(e,{arrival:o,legNumber:n}),u.add(e)}}if(i)continue;const p=l.get(e),T=null==p?void 0:p.arrival;if(void 0!==T&&(void 0===c||T<=t.departureFrom(h,c.tripIndex))){const e=t.findEarliestTrip(h,T,null==c?void 0:c.tripIndex);if(void 0===e)continue;const n=this.findFirstBoardableTrip(h,t,e,T,null==c?void 0:c.tripIndex,p&&"routeId"in p?p:void 0,o.minTransferTime);void 0!==n&&(c={routeId:t.id,tripIndex:n,stopIndex:h})}}return u}findFirstBoardableTrip(t,e,n,r=0,o,i,s=0){const a=e.getNbTrips();for(let u=n;u<(null!=o?o:a);u++){if(1===e.pickUpTypeFrom(t,u))continue;if(void 0===i)return u;if(this.timetable.isTripTransferGuaranteed({stopIndex:i.hopOffStopIndex,routeId:i.routeId,tripIndex:i.tripIndex},{stopIndex:t,routeId:e.id,tripIndex:u}))return u;if(e.departureFrom(t,u)>=r+s)return u}}considerTransfers(t,e,n,r){var o,i;const{options:s}=t,a=r.graph[e],u=new Set;for(const t of n){const n=a.get(t);if(!n||"type"in n)continue;const c=this.timetable.getTransfers(t);for(let d=0;d<c.length;d++){const l=c[d];let f;f=l.minTransferTime?l.minTransferTime:"IN_SEAT"===l.type?0:s.minTransferTime;const h=n.arrival+f;h<(null!==(i=null===(o=r.earliestArrivals.get(l.destination))||void 0===o?void 0:o.arrival)&&void 0!==i?i:gt)&&(a.set(l.destination,{arrival:h,from:t,to:l.destination,minTransferTime:l.minTransferTime,type:l.type}),r.earliestArrivals.set(l.destination,{arrival:h,legNumber:e}),u.add(l.destination))}}return u}earliestArrivalAtAnyStop(t,e){var n,r;let o=gt;for(let i=0;i<e.length;i++){const s=e[i],a=null!==(r=null===(n=t.get(s))||void 0===n?void 0:n.arrival)&&void 0!==r?r:gt;o=Math.min(o,a)}return o}},exports.StopsIndex=Ue,exports.Timetable=pt;
|
|
1
|
+
"use strict";const t=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")}`},e=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`},n={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 r(t){return"routeId"in t&&"stopIndex"in t&&"hopOffStopIndex"in t}function i(t){return"from"in t&&"to"in t&&"type"in t}class o{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(" "),i=r?` [${r}]`:"";return this.lines.push(` "${t}" -> "${e}"${i};`),this}addRaw(t){return this.lines.push(...t),this}build(){return this.lines.push("}"),this.lines.join("\n")}}function s(){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 a(t,e,n){for(let r=0;r<28;r+=7){const i=t>>>r,o=!(i>>>7==0&&0==e),s=255&(o?128|i:i);if(n.push(s),!o)return}const r=t>>>28&15|(7&e)<<4,i=!!(e>>3);if(n.push(255&(i?128|r:r)),i){for(let t=3;t<31;t+=7){const r=e>>>t,i=!(r>>>7==0),o=255&(i?128|r:r);if(n.push(o),!i)return}n.push(e>>>31&1)}}const u=4294967296;function c(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let r=0,i=0;function o(e,o){const s=Number(t.slice(e,o));i*=n,r=r*n+s,r>=u&&(i+=r/u|0,r%=u)}return o(-24,-18),o(-18,-12),o(-12,-6),o(-6),e?f(r,i):l(r,i)}function d(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(u*e+t);const n=16777215&(t>>>24|e<<8),r=e>>16&65535;let i=(16777215&t)+6777216*n+6710656*r,o=n+8147497*r,s=2*r;const a=1e7;return i>=a&&(o+=Math.floor(i/a),i%=a),o>=a&&(s+=Math.floor(o/a),o%=a),s.toString()+h(o)+h(i)}function l(t,e){return{lo:0|t,hi:0|e}}function f(t,e){return e=~e,t?t=1+~t:e+=1,l(t,e)}const h=t=>{const e=String(t);return"0000000".slice(e.length)+e};function p(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 T(){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 E=_();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"),i=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const r="bigint"==typeof t?t:BigInt(t);if(r>n||r<e)throw new Error(`invalid int64: ${t}`);return r},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>i||e<r)throw new Error(`invalid uint64: ${t}`);return e},enc(e){return t.setBigInt64(0,this.parse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(e){return t.setBigInt64(0,this.uParse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigInt64(0,!0)),uDec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigUint64(0,!0))}}return{zero:"0",supported:!1,parse:t=>("string"!=typeof t&&(t=t.toString()),I(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),m(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),I(t),c(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),m(t),c(t)),dec:(t,e)=>function(t,e){let n=l(t,e);const r=2147483648&n.hi;r&&(n=f(n.lo,n.hi));const i=d(n.lo,n.hi);return r?"-"+i:i}(t,e),uDec:(t,e)=>d(t,e)}}function I(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function m(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const g=Symbol.for("@bufbuild/protobuf/text-encoding");function R(){if(null==globalThis[g]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[g]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[g]}var A;!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"}(A||(A={}));const v=34028234663852886e22,O=-34028234663852886e22;class y{constructor(t=R().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(b(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return N(t),p(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.encodeUtf8(t);return this.uint32(e.byteLength),this.raw(e)}float(t){!function(t){if("string"==typeof t){const e=t;if(t=Number(t),Number.isNaN(t)&&"NaN"!==e)throw new Error("invalid float32: "+e)}else if("number"!=typeof t)throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>v||t<O))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){b(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){N(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return N(t),p(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=E.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=E.uEnc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(e)}int64(t){let e=E.enc(t);return a(e.lo,e.hi,this.buf),this}sint64(t){const e=E.enc(t),n=e.hi>>31;return a(e.lo<<1^n,(e.hi<<1|e.lo>>>31)^n,this.buf),this}uint64(t){const e=E.uEnc(t);return a(e.lo,e.hi,this.buf),this}}class S{constructor(t,e=R().decodeUtf8){this.decodeUtf8=e,this.varint64=s,this.uint32=T,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 A.Varint:for(;128&this.buf[this.pos++];);break;case A.Bit64:this.pos+=4;case A.Bit32:this.pos+=4;break;case A.LengthDelimited:let n=this.uint32();this.pos+=n;break;case A.StartGroup:for(;;){const[t,n]=this.tag();if(n===A.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 E.dec(...this.varint64())}uint64(){return E.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),n=-(1&t);return t=(t>>>1|(1&e)<<31)^n,e=e>>>1^n,E.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 E.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return E.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 N(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 b(t){if("string"==typeof t)t=Number(t);else if("number"!=typeof t)throw new Error("invalid uint32: "+typeof t);if(!Number.isInteger(t)||t>4294967295||t<0)throw new Error("invalid uint32: "+t)}var w,U;function P(t){switch(t){case 0:case"TRANSFER_TYPE_UNSPECIFIED":return w.TRANSFER_TYPE_UNSPECIFIED;case 1:case"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT":return w.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case 2:case"TRANSFER_TYPE_TIMED_TRANSFER":return w.TRANSFER_TYPE_TIMED_TRANSFER;case 3:case"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME":return w.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case 4:case"TRANSFER_TYPE_IN_SEAT_TRANSFER":return w.TRANSFER_TYPE_IN_SEAT_TRANSFER;default:return w.UNRECOGNIZED}}function x(t){switch(t){case 0:case"ROUTE_TYPE_UNSPECIFIED":return U.ROUTE_TYPE_UNSPECIFIED;case 1:case"ROUTE_TYPE_TRAM":return U.ROUTE_TYPE_TRAM;case 2:case"ROUTE_TYPE_SUBWAY":return U.ROUTE_TYPE_SUBWAY;case 3:case"ROUTE_TYPE_RAIL":return U.ROUTE_TYPE_RAIL;case 4:case"ROUTE_TYPE_BUS":return U.ROUTE_TYPE_BUS;case 5:case"ROUTE_TYPE_FERRY":return U.ROUTE_TYPE_FERRY;case 6:case"ROUTE_TYPE_CABLE_TRAM":return U.ROUTE_TYPE_CABLE_TRAM;case 7:case"ROUTE_TYPE_AERIAL_LIFT":return U.ROUTE_TYPE_AERIAL_LIFT;case 8:case"ROUTE_TYPE_FUNICULAR":return U.ROUTE_TYPE_FUNICULAR;case 9:case"ROUTE_TYPE_TROLLEYBUS":return U.ROUTE_TYPE_TROLLEYBUS;case 10:case"ROUTE_TYPE_MONORAIL":return U.ROUTE_TYPE_MONORAIL;default:return U.UNRECOGNIZED}}function L(){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"}(w||(w={})),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"}(U||(U={}));const C={encode:(t,e=new y)=>(0!==t.stopTimes.length&&e.uint32(10).bytes(t.stopTimes),0!==t.pickupDropOffTypes.length&&e.uint32(18).bytes(t.pickupDropOffTypes),0!==t.stops.length&&e.uint32(26).bytes(t.stops),0!==t.serviceRouteId&&e.uint32(32).uint32(t.serviceRouteId),e),decode(t,e){const n=t instanceof S?t:new S(t),r=void 0===e?n.len:n.pos+e,i=L();for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;i.stopTimes=n.bytes();continue;case 2:if(18!==t)break;i.pickupDropOffTypes=n.bytes();continue;case 3:if(26!==t)break;i.stops=n.bytes();continue;case 4:if(32!==t)break;i.serviceRouteId=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({stopTimes:z(t.stopTimes)?B(t.stopTimes):new Uint8Array(0),pickupDropOffTypes:z(t.pickupDropOffTypes)?B(t.pickupDropOffTypes):new Uint8Array(0),stops:z(t.stops)?B(t.stops):new Uint8Array(0),serviceRouteId:z(t.serviceRouteId)?globalThis.Number(t.serviceRouteId):0}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=j(t.stopTimes)),0!==t.pickupDropOffTypes.length&&(e.pickupDropOffTypes=j(t.pickupDropOffTypes)),0!==t.stops.length&&(e.stops=j(t.stops)),0!==t.serviceRouteId&&(e.serviceRouteId=Math.round(t.serviceRouteId)),e},create:t=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,i;const o=L();return o.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),o.pickupDropOffTypes=null!==(n=t.pickupDropOffTypes)&&void 0!==n?n:new Uint8Array(0),o.stops=null!==(r=t.stops)&&void 0!==r?r:new Uint8Array(0),o.serviceRouteId=null!==(i=t.serviceRouteId)&&void 0!==i?i:0,o}};const Y={encode:(t,e=new y)=>(0!==t.destination&&e.uint32(8).uint32(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).uint32(t.minTransferTime),e),decode(t,e){const n=t instanceof S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={destination:0,type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;i.destination=n.uint32();continue;case 2:if(16!==t)break;i.type=n.int32();continue;case 3:if(24!==t)break;i.minTransferTime=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({destination:z(t.destination)?globalThis.Number(t.destination):0,type:z(t.type)?P(t.type):0,minTransferTime:z(t.minTransferTime)?globalThis.Number(t.minTransferTime):void 0}),toJSON(t){const e={};return 0!==t.destination&&(e.destination=Math.round(t.destination)),0!==t.type&&(e.type=function(t){switch(t){case w.TRANSFER_TYPE_UNSPECIFIED:return"TRANSFER_TYPE_UNSPECIFIED";case w.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT";case w.TRANSFER_TYPE_TIMED_TRANSFER:return"TRANSFER_TYPE_TIMED_TRANSFER";case w.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"TRANSFER_TYPE_REQUIRES_MINIMAL_TIME";case w.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"TRANSFER_TYPE_IN_SEAT_TRANSFER";case w.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>Y.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const i={destination:0,type:0,minTransferTime:void 0};return i.destination=null!==(e=t.destination)&&void 0!==e?e:0,i.type=null!==(n=t.type)&&void 0!==n?n:0,i.minTransferTime=null!==(r=t.minTransferTime)&&void 0!==r?r:void 0,i}};const M={encode:(t,e=new y)=>(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 S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={stopIndex:0,routeId:0,tripIndex:0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;i.stopIndex=n.uint32();continue;case 2:if(16!==t)break;i.routeId=n.uint32();continue;case 3:if(24!==t)break;i.tripIndex=n.uint32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({stopIndex:z(t.stopIndex)?globalThis.Number(t.stopIndex):0,routeId:z(t.routeId)?globalThis.Number(t.routeId):0,tripIndex:z(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=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const i={stopIndex:0,routeId:0,tripIndex:0};return i.stopIndex=null!==(e=t.stopIndex)&&void 0!==e?e:0,i.routeId=null!==(n=t.routeId)&&void 0!==n?n:0,i.tripIndex=null!==(r=t.tripIndex)&&void 0!==r?r:0,i}};const F={encode(t,e=new y){void 0!==t.origin&&M.encode(t.origin,e.uint32(10).fork()).join();for(const n of t.destinations)M.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={origin:void 0,destinations:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;i.origin=M.decode(n,n.uint32());continue;case 2:if(18!==t)break;i.destinations.push(M.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({origin:z(t.origin)?M.fromJSON(t.origin):void 0,destinations:globalThis.Array.isArray(null==t?void 0:t.destinations)?t.destinations.map((t=>M.fromJSON(t))):[]}),toJSON(t){var e;const n={};return void 0!==t.origin&&(n.origin=M.toJSON(t.origin)),(null===(e=t.destinations)||void 0===e?void 0:e.length)&&(n.destinations=t.destinations.map((t=>M.toJSON(t)))),n},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={origin:void 0,destinations:[]};return n.origin=void 0!==t.origin&&null!==t.origin?M.fromPartial(t.origin):void 0,n.destinations=(null===(e=t.destinations)||void 0===e?void 0:e.map((t=>M.fromPartial(t))))||[],n}};const D={encode(t,e=new y){e.uint32(10).fork();for(const n of t.routes)e.uint32(n);e.join();for(const n of t.transfers)Y.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={routes:[],transfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8===t){i.routes.push(n.uint32());continue}if(10===t){const t=n.uint32()+n.pos;for(;n.pos<t;)i.routes.push(n.uint32());continue}break;case 2:if(18!==t)break;i.transfers.push(Y.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.Number(t))):[],transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>Y.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=>Y.toJSON(t)))),r},create:t=>D.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=>Y.fromPartial(t))))||[],r}};const k={encode(t,e=new y){0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e.uint32(26).fork();for(const n of t.routes)e.uint32(n);return e.join(),e},decode(t,e){const n=t instanceof S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={type:0,name:"",routes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;i.type=n.int32();continue;case 2:if(18!==t)break;i.name=n.string();continue;case 3:if(24===t){i.routes.push(n.uint32());continue}if(26===t){const t=n.uint32()+n.pos;for(;n.pos<t;)i.routes.push(n.uint32());continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({type:z(t.type)?x(t.type):0,name:z(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 U.ROUTE_TYPE_UNSPECIFIED:return"ROUTE_TYPE_UNSPECIFIED";case U.ROUTE_TYPE_TRAM:return"ROUTE_TYPE_TRAM";case U.ROUTE_TYPE_SUBWAY:return"ROUTE_TYPE_SUBWAY";case U.ROUTE_TYPE_RAIL:return"ROUTE_TYPE_RAIL";case U.ROUTE_TYPE_BUS:return"ROUTE_TYPE_BUS";case U.ROUTE_TYPE_FERRY:return"ROUTE_TYPE_FERRY";case U.ROUTE_TYPE_CABLE_TRAM:return"ROUTE_TYPE_CABLE_TRAM";case U.ROUTE_TYPE_AERIAL_LIFT:return"ROUTE_TYPE_AERIAL_LIFT";case U.ROUTE_TYPE_FUNICULAR:return"ROUTE_TYPE_FUNICULAR";case U.ROUTE_TYPE_TROLLEYBUS:return"ROUTE_TYPE_TROLLEYBUS";case U.ROUTE_TYPE_MONORAIL:return"ROUTE_TYPE_MONORAIL";case U.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=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const i={type:0,name:"",routes:[]};return i.type=null!==(e=t.type)&&void 0!==e?e:0,i.name=null!==(n=t.name)&&void 0!==n?n:"",i.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],i}};const $={encode(t,e=new y){for(const n of t.stopsAdjacency)D.encode(n,e.uint32(10).fork()).join();for(const n of t.routesAdjacency)C.encode(n,e.uint32(18).fork()).join();for(const n of t.serviceRoutes)k.encode(n,e.uint32(26).fork()).join();for(const n of t.tripContinuations)F.encode(n,e.uint32(34).fork()).join();for(const n of t.guaranteedTripTransfers)F.encode(n,e.uint32(42).fork()).join();return e},decode(t,e){const n=t instanceof S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;i.stopsAdjacency.push(D.decode(n,n.uint32()));continue;case 2:if(18!==t)break;i.routesAdjacency.push(C.decode(n,n.uint32()));continue;case 3:if(26!==t)break;i.serviceRoutes.push(k.decode(n,n.uint32()));continue;case 4:if(34!==t)break;i.tripContinuations.push(F.decode(n,n.uint32()));continue;case 5:if(42!==t)break;i.guaranteedTripTransfers.push(F.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({stopsAdjacency:globalThis.Array.isArray(null==t?void 0:t.stopsAdjacency)?t.stopsAdjacency.map((t=>D.fromJSON(t))):[],routesAdjacency:globalThis.Array.isArray(null==t?void 0:t.routesAdjacency)?t.routesAdjacency.map((t=>C.fromJSON(t))):[],serviceRoutes:globalThis.Array.isArray(null==t?void 0:t.serviceRoutes)?t.serviceRoutes.map((t=>k.fromJSON(t))):[],tripContinuations:globalThis.Array.isArray(null==t?void 0:t.tripContinuations)?t.tripContinuations.map((t=>F.fromJSON(t))):[],guaranteedTripTransfers:globalThis.Array.isArray(null==t?void 0:t.guaranteedTripTransfers)?t.guaranteedTripTransfers.map((t=>F.fromJSON(t))):[]}),toJSON(t){var e,n,r,i,o;const s={};return(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.length)&&(s.stopsAdjacency=t.stopsAdjacency.map((t=>D.toJSON(t)))),(null===(n=t.routesAdjacency)||void 0===n?void 0:n.length)&&(s.routesAdjacency=t.routesAdjacency.map((t=>C.toJSON(t)))),(null===(r=t.serviceRoutes)||void 0===r?void 0:r.length)&&(s.serviceRoutes=t.serviceRoutes.map((t=>k.toJSON(t)))),(null===(i=t.tripContinuations)||void 0===i?void 0:i.length)&&(s.tripContinuations=t.tripContinuations.map((t=>F.toJSON(t)))),(null===(o=t.guaranteedTripTransfers)||void 0===o?void 0:o.length)&&(s.guaranteedTripTransfers=t.guaranteedTripTransfers.map((t=>F.toJSON(t)))),s},create:t=>$.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,i,o;const s={stopsAdjacency:[],routesAdjacency:[],serviceRoutes:[],tripContinuations:[],guaranteedTripTransfers:[]};return s.stopsAdjacency=(null===(e=t.stopsAdjacency)||void 0===e?void 0:e.map((t=>D.fromPartial(t))))||[],s.routesAdjacency=(null===(n=t.routesAdjacency)||void 0===n?void 0:n.map((t=>C.fromPartial(t))))||[],s.serviceRoutes=(null===(r=t.serviceRoutes)||void 0===r?void 0:r.map((t=>k.fromPartial(t))))||[],s.tripContinuations=(null===(i=t.tripContinuations)||void 0===i?void 0:i.map((t=>F.fromPartial(t))))||[],s.guaranteedTripTransfers=(null===(o=t.guaranteedTripTransfers)||void 0===o?void 0:o.map((t=>F.fromPartial(t))))||[],s}};function B(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n}}function j(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 z(t){return null!=t}let G=class t{constructor(t,e,n,r,i){this.id=t,this.stopTimes=e,this.pickupDropOffTypes=n,this.stops=r,this.serviceRouteId=i,this.nbStops=r.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<r.length;t++){const e=r[t],n=this.stopIndices.get(e);n?n.push(t):this.stopIndices.set(e,[t])}}static of(e){var n,r;const{id:i,serviceRouteId:o,trips:s}=e;if(0===s.length)throw new Error("At least one trip must be provided");const a=s[0],u=new Uint32Array(a.stops.map((t=>t.id))),c=u.length;for(let t=1;t<s.length;t++){const e=s[t];if(e.stops.length!==c)throw new Error(`Trip ${t} has ${e.stops.length} stops, expected ${c}`);for(let n=0;n<c;n++)if(e.stops[n].id!==u[n])throw new Error(`Trip ${t} has different stop at index ${n}`)}const d=new Uint16Array(s.length*c*2);for(let t=0;t<s.length;t++){const e=s[t];for(let n=0;n<c;n++){const r=e.stops[n],i=2*(t*c+n);d[i]=r.arrivalTime,d[i+1]=r.departureTime}}const l=s.length*c,f=new Uint8Array(Math.ceil(l/2));for(let t=0;t<s.length;t++){const e=s[t];for(let i=0;i<c;i++){const o=e.stops[i],s=t*c+i,a=null!==(n=o.pickUpType)&&void 0!==n?n:0,u=null!==(r=o.dropOffType)&&void 0!==r?r:0,d=Math.floor(s/2),l=s%2==1;f[d]|=l?a<<6|u<<4:a<<2|u}}return new t(i,d,f,u,o)}serialize(){return{stopTimes:this.stopTimes,pickupDropOffTypes:this.pickupDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}getNbStops(){return this.nbStops}getNbTrips(){return this.nbTrips}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const n=2*(e*this.stops.length+t),r=this.stopTimes[n];if(void 0===r)throw new Error(`Arrival time not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return r}tripStopOffset(t){return t*this.nbStops}arrivalAtOffset(t,e){return this.stopTimes[2*(e+t)]}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=Math.floor(n/2),i=n%2==1,o=this.pickupDropOffTypes[r];if(void 0===o)throw new Error(`Pick up type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return i?o>>6&3:o>>2&3}dropOffTypeAt(t,e){const n=e*this.stops.length+t,r=Math.floor(n/2),i=n%2==1,o=this.pickupDropOffTypes[r];if(void 0===o)throw new Error(`Drop off type not found for stop ${this.stopId(t)} (${t}) at trip index ${e} in route ${this.serviceRouteId}`);return i?o>>4&3:3&o}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 i=0,o=-1;for(;i<=r;){const n=i+r>>>1;this.departureFrom(t,n)<e?i=n+1:(o=n,r=n-1)}return-1!==o?o:void 0}stopRouteIndices(t){const e=this.stopIndices.get(t);return void 0===e?[]:e}stopId(t){const e=this.stops[t];if(void 0===e)throw new Error(`StopId for stop at index ${t} not found in route ${this.serviceRouteId}`);return e}};const V=(BigInt(1)<<BigInt(20))-BigInt(1),J=1048575,W=BigInt(0),Z=BigInt(20),q=BigInt(40),Q=(t,e)=>{if(t<0||t>J)throw new Error(`${e} must be between 0 and 1048575, got ${t}`)},X=(t,e,n)=>(Q(t,"stopIndex"),Q(e,"routeId"),Q(n,"tripIndex"),BigInt(t)<<q|BigInt(e)<<Z|BigInt(n)<<W),H=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),K=!0,tt=t=>{if(H===K)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint32(4*e,t[e],K);return e},et=t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(H===K)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint32(4*t,K);return e},nt=t=>{if(H===K)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint16(2*e,t[e],K);return e},rt=t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(H===K)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint16(2*t,K);return e},it=t=>{const e=[];return t.forEach((t=>{const n=t.serialize();e.push({stopTimes:nt(n.stopTimes),pickupDropOffTypes:n.pickupDropOffTypes,stops:tt(n.stops),serviceRouteId:n.serviceRouteId})})),e},ot=t=>{switch(t){case w.TRANSFER_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf transfer type.");case w.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case w.TRANSFER_TYPE_TIMED_TRANSFER:return"GUARANTEED";case w.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case w.TRANSFER_TYPE_IN_SEAT_TRANSFER:return"IN_SEAT";case w.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},st=t=>{switch(t){case"RECOMMENDED":return w.TRANSFER_TYPE_RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return w.TRANSFER_TYPE_TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return w.TRANSFER_TYPE_REQUIRES_MINIMAL_TIME;case"IN_SEAT":return w.TRANSFER_TYPE_IN_SEAT_TRANSFER}},at=t=>{switch(t){case U.ROUTE_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf route type.");case U.ROUTE_TYPE_TRAM:return"TRAM";case U.ROUTE_TYPE_SUBWAY:return"SUBWAY";case U.ROUTE_TYPE_RAIL:return"RAIL";case U.ROUTE_TYPE_BUS:return"BUS";case U.ROUTE_TYPE_FERRY:return"FERRY";case U.ROUTE_TYPE_CABLE_TRAM:return"CABLE_TRAM";case U.ROUTE_TYPE_AERIAL_LIFT:return"AERIAL_LIFT";case U.ROUTE_TYPE_FUNICULAR:return"FUNICULAR";case U.ROUTE_TYPE_TROLLEYBUS:return"TROLLEYBUS";case U.ROUTE_TYPE_MONORAIL:return"MONORAIL";case U.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},ut=t=>{switch(t){case"TRAM":return U.ROUTE_TYPE_TRAM;case"SUBWAY":return U.ROUTE_TYPE_SUBWAY;case"RAIL":return U.ROUTE_TYPE_RAIL;case"BUS":return U.ROUTE_TYPE_BUS;case"FERRY":return U.ROUTE_TYPE_FERRY;case"CABLE_TRAM":return U.ROUTE_TYPE_CABLE_TRAM;case"AERIAL_LIFT":return U.ROUTE_TYPE_AERIAL_LIFT;case"FUNICULAR":return U.ROUTE_TYPE_FUNICULAR;case"TROLLEYBUS":return U.ROUTE_TYPE_TROLLEYBUS;case"MONORAIL":return U.ROUTE_TYPE_MONORAIL}},ct=t=>{const e=[];for(const[r,i]of t.entries()){const[t,o,s]=(n=r,[Number(n>>q&V),Number(n>>Z&V),Number(n>>W&V)]);e.push({origin:{stopIndex:t,routeId:o,tripIndex:s},destinations:i.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})))})}var n;return e},dt=t=>{const e=new Map;for(let n=0;n<t.length;n++){const r=t[n],i=r.origin,o=X(i.stopIndex,i.routeId,i.tripIndex),s=r.destinations.map((t=>({stopIndex:t.stopIndex,routeId:t.routeId,tripIndex:t.tripIndex})));e.set(o,s)}return e},lt=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),ft=[];class ht{constructor(t,e,n,r,i){this.stopsAdjacency=t,this.routesAdjacency=e,this.serviceRoutes=n,this.tripContinuations=r,this.guaranteedTripTransfers=i,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:st(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime}))):[],routes:t.routes})))),routesAdjacency:it(this.routesAdjacency),serviceRoutes:(e=this.serviceRoutes,e.map((t=>({type:ut(t.type),name:t.name,routes:t.routes})))),tripContinuations:ct(this.tripContinuations||new Map),guaranteedTripTransfers:ct(this.guaranteedTripTransfers||new Map)};var e,n;const r=new y;return $.encode(t,r),r.finish()}static fromData(t){const e=new S(t),n=$.decode(e);return new ht((t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],i=[];for(let t=0;t<r.transfers.length;t++){const e=r.transfers[t],n=Object.assign({destination:e.destination,type:ot(e.type)},void 0!==e.minTransferTime&&{minTransferTime:e.minTransferTime});i.push(n)}const o={routes:r.routes};i.length>0&&(o.transfers=i),e.push(o)}return e})(n.stopsAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n],i=et(r.stops);e.push(new G(n,rt(r.stopTimes),r.pickupDropOffTypes,i,r.serviceRouteId))}return e})(n.routesAdjacency),(t=>{const e=[];for(let n=0;n<t.length;n++){const r=t[n];e.push({type:at(r.type),name:r.name,routes:r.routes})}return e})(n.serviceRoutes),dt(n.tripContinuations),dt(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 i=null===(r=this.tripContinuations)||void 0===r?void 0:r.get(X(t,e,n));return i||ft}getServiceRouteInfo(t){const e=this.serviceRoutes[t.serviceRoute()];if(!e)throw new Error(`Service route not found for route ID: ${t.serviceRoute()}`);return{type:e.type,name:e.name}}routesPassingThrough(t){const e=this.stopsAdjacency[t];if(!e)return[];const n=[];for(let t=0;t<e.routes.length;t++){const r=e.routes[t],i=this.routesAdjacency[r];i&&n.push(i)}return n}findReachableRoutes(t,e=lt){const n=new Map,r=e!==lt;for(const i of t){const t=this.stopsAdjacency[i];if(t)for(let o=0;o<t.routes.length;o++){const s=this.routesAdjacency[t.routes[o]];if(!s)continue;if(r){const t=this.serviceRoutes[s.serviceRoute()];if(!t||!e.has(t.type))continue}const a=s.stopRouteIndices(i)[0],u=n.get(s);void 0!==u?a<u&&n.set(s,a):n.set(s,a)}}return n}isTripTransferGuaranteed(t,e){var n;const r=X(t.stopIndex,t.routeId,t.tripIndex),i=null===(n=this.guaranteedTripTransfers)||void 0===n?void 0:n.get(r);if(!i)return!1;for(let t=0;t<i.length;t++){const n=i[t];if(n.stopIndex===e.stopIndex&&n.routeId===e.routeId&&n.tripIndex===e.tripIndex)return!0}return!1}getGuaranteedTripTransfers(t,e,n){var r;const i=null===(r=this.guaranteedTripTransfers)||void 0===r?void 0:r.get(X(t,e,n));return i||ft}}class pt{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}pt.Builder=class{constructor(){var t;this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:(t=120,Math.round(t/60)),transportModes:lt}}from(t){return this.fromValue=t,this}to(t){return this.toValue=t instanceof Set?t:new Set([t]),this}departureTime(t){return this.departureTimeValue=t,this}maxTransfers(t){return this.optionsValue.maxTransfers=t,this}minTransferTime(t){return this.optionsValue.minTransferTime=t,this}transportModes(t){return this.optionsValue.transportModes=t,this}build(){return new pt(this)}};class Tt{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;"minTransferTime"in n&&n.minTransferTime&&(t+=n.minTransferTime)}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(((n,r)=>{const i=`From: ${n.from.name}${n.from.platform?` (Pl. ${n.from.platform})`:""}`,o=`To: ${n.to.name}${n.to.platform?` (Pl. ${n.to.platform})`:""}`,s="type"in n&&!("route"in n)?`Transfer: ${n.type}${n.minTransferTime?`, Minimum Transfer Time: ${e(n.minTransferTime)}`:""}`:"",a="route"in n&&"departureTime"in n&&"arrivalTime"in n?`Route: ${n.route.type} ${n.route.name}, Departure: ${t(n.departureTime)}, Arrival: ${t(n.arrivalTime)}`:"";return[`Leg ${r+1}:`,` ${i}`,` ${o}`,s?` ${s}`:"",a?` ${a}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}asJson(){return this.legs.map((e=>"route"in e?{from:e.from.id,to:e.to.id,departure:t(e.departureTime),arrival:t(e.arrivalTime),route:e.route}:Object.assign({from:e.from.id,to:e.to.id,type:e.type},void 0!==e.minTransferTime&&{minTransferTime:e.minTransferTime})))}}const Et=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],_t=t=>{const e=Et[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};class It{constructor(t,e,n,r){this.query=t,this.routingState=e,this.stopsIndex=n,this.timetable=r}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=t instanceof Set?t:t?[t]:this.query.to;let r,i,o;for(const t of n){const e=this.stopsIndex.equivalentStops(t);for(const t of e){const e=this.routingState.getArrival(t.id);void 0!==e&&(void 0===i||e.arrival<i)&&(r=t.id,i=e.arrival,o=e.legNumber)}}if(void 0===r||void 0===o)return;const s=[];let a,u=r,c=o;for(;c>0;){const t=null===(e=this.routingState.graph[c])||void 0===e?void 0:e[u];if(!t)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 i=[n];for(;n.continuationOf;)i.push(n.continuationOf),n=n.continuationOf;e=n,r=this.buildVehicleLeg(i)}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})&&s.push(this.buildGuaranteedTransferLeg(e,a)),a=e}else{if(!("type"in t))break;n=this.buildTransferLeg(t),a=void 0}s.push(n),u=n.from.id,"routeId"in t&&(c-=1)}return new Tt(s.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),i=this.timetable.getRoute(n.routeId);return{from:this.stopsIndex.findStopById(r.stopId(e.stopIndex)),to:this.stopsIndex.findStopById(i.stopId(n.hopOffStopIndex)),route:this.timetable.getServiceRouteInfo(r),departureTime:r.departureFrom(e.stopIndex,e.tripIndex),arrivalTime:n.arrival,pickUpType:_t(r.pickUpTypeFrom(e.stopIndex,e.tripIndex)),dropOffType:_t(i.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}}buildGuaranteedTransferLeg(t,e){const n=this.timetable.getRoute(t.routeId),r=this.timetable.getRoute(e.routeId),i=n.stopId(t.hopOffStopIndex),o=r.stopId(e.stopIndex);return{from:this.stopsIndex.findStopById(i),to:this.stopsIndex.findStopById(o),type:"GUARANTEED"}}arrivalAt(t,e){var n,r;const i=this.stopsIndex.equivalentStops(t);let o;for(const t of i){let i;if(void 0===e||(null===(n=this.routingState.getArrival(t.id))||void 0===n?void 0:n.legNumber)===e+1)i=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){i={arrival:e.arrival,legNumber:n};break}}void 0!==i&&(void 0===o||i.arrival<o.arrival)&&(o=i)}return o}}const mt=65535;class gt{constructor(t,e,n,r){this.origins=t,this.destinations=e;const i=new Uint16Array(r).fill(mt),o=new Uint8Array(r),s=new Array(r);for(const e of t)i[e]=n,s[e]={arrival:n};this.earliestArrivalTimes=i,this.earliestArrivalLegs=o,this.graph=[s]}get nbStops(){return this.earliestArrivalTimes.length}arrivalTime(t){return this.earliestArrivalTimes[t]}updateArrival(t,e,n){this.earliestArrivalTimes[t]=e,this.earliestArrivalLegs[t]=n}getArrival(t){const e=this.earliestArrivalTimes[t];if(!(e>=mt))return{arrival:e,legNumber:this.earliestArrivalLegs[t]}}static fromTestData({nbStops:t,origins:e=[],destinations:n=[],arrivals:r=[],graph:i=[]}){const o=new gt(e,n,0,t),s=new Uint16Array(t).fill(mt),a=new Uint8Array(t);for(const[t,e,n]of r)s[t]=e,a[t]=n;o.earliestArrivalTimes=s,o.earliestArrivalLegs=a;const u=i.map((e=>{const n=new Array(t);for(const[t,r]of e)n[t]=r;return n}));return o.graph.splice(0,o.graph.length,...u),o}}class Rt{constructor(t=[],e=At){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,r=e[t];for(;t>0;){const i=t-1>>1,o=e[i];if(n(r,o)>=0)break;e[t]=o,t=i}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,i=e[t];for(;t<r;){let r=1+(t<<1),o=e[r];const s=r+1;if(s<this.length&&n(e[s],o)<0&&(r=s,o=e[s]),n(o,i)>=0)break;e[t]=o,t=r}e[t]=i}}function At(t,e){return t<e?-1:t>e?1:0}const vt=Math.PI/180;function Ot(t,e,n,r){const i=r.minLng,o=r.maxLng,s=r.minLat,a=r.maxLat;if(t>=i&&t<=o)return e<s?St((e-s)*vt):e>a?St((e-a)*vt):0;const u=Math.min(St((t-i)*vt),St((t-o)*vt)),c=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*vt)/n)/vt}(e,u);return c>s&&c<a?Nt(u,n,e,c):Math.min(Nt(u,n,e,s),Nt(u,n,e,a))}function yt(t,e){return t.dist-e.dist}function St(t){const e=Math.sin(t/2);return e*e}function Nt(t,e,n,r){return e*Math.cos(r*vt)*t+St((n-r)*vt)}function bt(t,e,n,r,i){return Nt(St((t-n)*vt),i,e,r)}const wt=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class Ut{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const r=n>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const i=wt[15&n];if(!i)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[s]=new Uint32Array(t,4,1);return new Ut(s,o,i,t)}constructor(t,e=64,n=Float64Array,r){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const i=wt.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,s=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-s%8)%8;if(i<0)throw new Error(`Unexpected typed array class: ${n}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+s+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+s+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+i]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return Pt(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:i,coords:o,nodeSize:s}=this,a=[0,i.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,d=a.pop()||0,l=a.pop()||0;if(d-l<=s){for(let s=l;s<=d;s++){const a=o[2*s],c=o[2*s+1];a>=t&&a<=n&&c>=e&&c<=r&&u.push(i[s])}continue}const f=l+d>>1,h=o[2*f],p=o[2*f+1];h>=t&&h<=n&&p>=e&&p<=r&&u.push(i[f]),(0===c?t<=h:e<=p)&&(a.push(l),a.push(f-1),a.push(1-c)),(0===c?n>=h:r>=p)&&(a.push(f+1),a.push(d),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:i,nodeSize:o}=this,s=[0,r.length-1,0],a=[],u=n*n;for(;s.length;){const c=s.pop()||0,d=s.pop()||0,l=s.pop()||0;if(d-l<=o){for(let n=l;n<=d;n++)Yt(i[2*n],i[2*n+1],t,e)<=u&&a.push(r[n]);continue}const f=l+d>>1,h=i[2*f],p=i[2*f+1];Yt(h,p,t,e)<=u&&a.push(r[f]),(0===c?t-n<=h:e-n<=p)&&(s.push(l),s.push(f-1),s.push(1-c)),(0===c?t+n>=h:e+n>=p)&&(s.push(f+1),s.push(d),s.push(1-c))}return a}}function Pt(t,e,n,r,i,o){if(i-r<=n)return;const s=r+i>>1;xt(t,e,s,r,i,o),Pt(t,e,n,r,s-1,1-o),Pt(t,e,n,s+1,i,1-o)}function xt(t,e,n,r,i,o){for(;i>r;){if(i-r>600){const s=i-r+1,a=n-r+1,u=Math.log(s),c=.5*Math.exp(2*u/3),d=.5*Math.sqrt(u*c*(s-c)/s)*(a-s/2<0?-1:1);xt(t,e,n,Math.max(r,Math.floor(n-a*c/s+d)),Math.min(i,Math.floor(n+(s-a)*c/s+d)),o)}const s=e[2*n+o];let a=r,u=i;for(Lt(t,e,r,n),e[2*i+o]>s&&Lt(t,e,r,i);a<u;){for(Lt(t,e,a,u),a++,u--;e[2*a+o]<s;)a++;for(;e[2*u+o]>s;)u--}e[2*r+o]===s?Lt(t,e,r,u):(u++,Lt(t,e,u,i)),u<=n&&(r=u+1),n<=u&&(i=u-1)}}function Lt(t,e,n,r){Ct(t,n,r),Ct(e,2*n,2*r),Ct(e,2*n+1,2*r+1)}function Ct(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function Yt(t,e,n,r){const i=t-n,o=e-r;return i*i+o*o}const Mt="KEYS",Ft="VALUES";class Dt{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}=kt(this._path);if(""===kt(e))return{done:!1,value:this.result()};const n=t.get(kt(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=kt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>kt(t))).filter((t=>""!==t)).join("")}value(){return kt(this._path).node.get("")}result(){switch(this._type){case Ft:return this.value();case Mt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const kt=t=>t[t.length-1],$t=(t,e,n,r,i,o,s,a)=>{const u=o*s;t:for(const c of t.keys())if(""===c){const e=i[u-1];e<=n&&r.set(a,[t.get(c),e])}else{let u=o;for(let t=0;t<c.length;++t,++u){const r=c[t],o=s*u,a=o-s;let d=i[o];const l=Math.max(0,u-n-1),f=Math.min(s-1,u+n);for(let t=l;t<f;++t){const n=r!==e[t],s=i[a+t]+ +n,u=i[a+t+1]+1,c=i[o+t]+1,l=i[o+t+1]=Math.min(s,u,c);l<d&&(d=l)}if(d>n)continue t}$t(t.get(c),e,n,r,i,u,s,a+c)}};class Bt{_tree;_prefix;_size=void 0;constructor(t=new Map,e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,n]=jt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=Zt(n);for(const n of e.keys())if(""!==n&&n.startsWith(r)){const i=new Map;return i.set(n.slice(r.length),e.get(n)),new Bt(i,t)}}return new Bt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Vt(this._tree,t)}entries(){return new Dt(this,"ENTRIES")}forEach(t){for(const[e,n]of this)t(e,n,this)}fuzzyGet(t,e){return((t,e,n)=>{const r=new Map;if("string"!=typeof e)return r;const i=e.length+1,o=i+n,s=new Uint8Array(o*i).fill(n+1);for(let t=0;t<i;++t)s[t]=t;for(let t=1;t<o;++t)s[t*i]=t;return $t(t,e,n,r,s,1,i,""),r})(this._tree,t,e)}get(t){const e=zt(this._tree,t);return void 0!==e?e.get(""):void 0}has(t){return zt(this._tree,t)?.has("")??!1}keys(){return new Dt(this,Mt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Gt(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=Gt(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=Gt(this._tree,t);let r=n.get("");return void 0===r&&n.set("",r=e()),r}values(){return new Dt(this,Ft)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Bt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return Bt.from(Object.entries(t))}}const jt=(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]),jt(t.get(r),e.slice(r.length),n);return n.push([t,e]),jt(void 0,"",n)},zt=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(""!==n&&e.startsWith(n))return zt(t.get(n),e.slice(n.length))},Gt=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const i of t.keys())if(""!==i&&e[r]===i[0]){const o=Math.min(n-r,i.length);let s=1;for(;s<o&&e[r+s]===i[s];)++s;const a=t.get(i);if(s===i.length)t=a;else{const n=new Map;n.set(i.slice(s),a),t.set(e.slice(r,r+s),n),t.delete(i),t=n}r+=s;continue t}const i=new Map;return t.set(e.slice(r),i),i}return t},Vt=(t,e)=>{const[n,r]=jt(t,e);if(void 0!==n)if(n.delete(""),0===n.size)Jt(r);else if(1===n.size){const[t,e]=n.entries().next().value;Wt(r,t,e)}},Jt=t=>{if(0===t.length)return;const[e,n]=Zt(t);if(e.delete(n),0===e.size)Jt(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;""!==n&&Wt(t.slice(0,-1),n,r)}},Wt=(t,e,n)=>{if(0===t.length)return;const[r,i]=Zt(t);r.set(i+e,n),r.delete(i)},Zt=t=>t[t.length-1],qt=/[\n\r\p{Z}\p{P}]+/u,Qt="or",Xt="and",Ht="and_not",Kt=(t,e)=>{t.includes(e)||t.push(e)},te=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},ee=({score:t},{score:e})=>e-t,ne=()=>new Map,re=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,ie={[Qt]:(t,e)=>{for(const n of e.keys()){const r=t.get(n);if(null==r)t.set(n,e.get(n));else{const{score:t,terms:i,match:o}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,o),te(r.terms,i)}}return t},[Xt]:(t,e)=>{const n=new Map;for(const r of e.keys()){const i=t.get(r);if(null==i)continue;const{score:o,terms:s,match:a}=e.get(r);te(i.terms,s),n.set(r,{score:i.score+o,terms:i.terms,match:Object.assign(i.match,a)})}return n},[Ht]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},oe=(t,e,n,r,i,o)=>{const{k:s,b:a,d:u}=o;return Math.log(1+(n-e+.5)/(e+.5))*(u+t*(s+1)/(t+s*(1-a+a*r/i)))},se=(t,e,n,r)=>{for(const i of Object.keys(t._fieldIds))if(t._fieldIds[i]===n)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${r}" was not present in field "${i}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},ae=(t,e,n,r)=>{const i=t._index.fetch(r,ne);let o=i.get(e);if(null==o)o=new Map,o.set(n,1),i.set(e,o);else{const t=o.get(n);o.set(n,(t??0)+1)}},ue=(t,e,n,r)=>{if(!t._index.has(r))return void se(t,n,e,r);const i=t._index.fetch(r,ne),o=i.get(e),s=o?.get(n);!o||typeof s>"u"?se(t,n,e,r):s<=1?o.size<=1?i.delete(e):o.delete(n):o.set(n,s-1),0===t._index.get(r).size&&t._index.delete(r)},ce=(t,e,n,r,i)=>{let o=t._fieldLength.get(e);null==o&&t._fieldLength.set(e,o=[]),o[n]=i;const s=(t._avgFieldLength[n]||0)*r+i;t._avgFieldLength[n]=s/(r+1)},de=(t,e)=>{const{extractField:n,stringifyField:r,tokenize:i,processTerm:o,fields:s,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:i}=t._options;if(0===r?.length)return;let o=t._storedFields.get(e);void 0===o&&t._storedFields.set(e,o={});for(const t of r){const e=i(n,t);null!=e&&(o[t]=e)}})(t,c,e);for(const a of s){const s=n(e,a);if(null==s)continue;const u=i(r(s,a),a),d=t._fieldIds[a],l=new Set(u).size;ce(t,c,d,t._documentCount-1,l);for(const e of u){const n=o(e,a);if(Array.isArray(n))for(const e of n)ae(t,d,c,e);else n&&ae(t,d,c,n)}}},le={idField:"id",extractField:(t,e)=>t[e],stringifyField:t=>t.toString(),tokenize:t=>t.split(qt),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},fe={combineWith:Qt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},he={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},pe={minDirtFactor:.1,minDirtCount:20},Te={batchSize:1e3,batchWait:10,...pe},Ee=Symbol("*"),_e=(t,e=Qt)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in ie))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(ie[n])},Ie=(t,e,n,r,i,o,s,a,u,c=new Map)=>{if(null==o)return c;for(const d of Object.keys(s)){const l=s[d],f=t._fieldIds[d],h=o.get(f);if(null==h)continue;let p=h.size;const T=t._avgFieldLength[f];for(const o of h.keys()){if(!t._documentIds.has(o)){ue(t,f,o,n),p-=1;continue}const s=a?a(t._documentIds.get(o),n,t._storedFields.get(o)):1;if(!s)continue;const E=h.get(o),_=t._fieldLength.get(o)[f],I=r*i*l*s*oe(E,p,t._documentCount,_,T,u),m=c.get(o);if(m){m.score+=I,Kt(m.terms,e);const t=re(m.match,n);t?t.push(d):m.match[n]=[d]}else c.set(o,{score:I,terms:[e],match:{[n]:[d]}})}}return c},me=(t,e,n={})=>{if(e===Ee)return((t,e)=>{const n=new Map,r={...t._options.searchOptions,...e};for(const[e,i]of t._documentIds){const o=r.boostDocument?r.boostDocument(i,"",t._storedFields.get(e)):1;n.set(e,{score:o,terms:[],match:{}})}return n})(t,n);if("string"!=typeof e){const r={...n,...e,queries:void 0},i=e.queries.map((e=>me(t,e,r)));return _e(i,r.combineWith)}const{tokenize:r,processTerm:i,searchOptions:o}=t._options,s={tokenize:r,processTerm:i,...o,...n},{tokenize:a,processTerm:u}=s,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,n,r)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,n,r):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,n,r):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,n,r):1}))(s)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},i=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:re(r.boost,e)||1})),{}),{boostDocument:o,weights:s,maxFuzzy:a,bm25:u}=r,{fuzzy:c,prefix:d}={...fe.weights,...s},l=t._index.get(e.term),f=Ie(t,e.term,e.term,1,e.termBoost,l,i,o,u);let h,p;if(e.prefix&&(h=t._index.atPrefix(e.term)),e.fuzzy){const n=!0===e.fuzzy?.2:e.fuzzy,r=n<1?Math.min(a,Math.round(e.term.length*n)):n;r&&(p=t._index.fuzzyGet(e.term,r))}if(h)for(const[n,r]of h){const s=n.length-e.term.length;if(!s)continue;p?.delete(n);const a=d*n.length/(n.length+.3*s);Ie(t,e.term,n,a,e.termBoost,r,i,o,u,f)}if(p)for(const n of p.keys()){const[r,s]=p.get(n);if(!s)continue;const a=c*n.length/(n.length+s);Ie(t,e.term,n,a,e.termBoost,r,i,o,u,f)}return f})(t,e,s)));return _e(c,s.combineWith)};class ge{_options;_index;_documentCount;_documentIds;_idToShortId;_fieldIds;_fieldLength;_avgFieldLength;_nextId;_storedFields;_dirtCount;_currentVacuum;_enqueuedVacuum;_enqueuedVacuumConditions;constructor(t){if(!t?.fields)throw new Error('SlimSearch: option "fields" must be provided');const e=null==t.autoVacuum||!0===t.autoVacuum?Te:t.autoVacuum;this._options={...le,...t,autoVacuum:e,searchOptions:{...fe,...t.searchOptions},autoSuggestOptions:{...he,...t.autoSuggestOptions}},this._index=new Bt,this._documentCount=0,this._documentIds=new Map,this._idToShortId=new Map,this._fieldIds={},this._fieldLength=new Map,this._avgFieldLength=[],this._nextId=0,this._storedFields=new Map,this._dirtCount=0,this._currentVacuum=null,this._enqueuedVacuum=null,this._enqueuedVacuumConditions=pe,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 Re=t=>{const e=t.toLowerCase(),n=new Set([e]),r={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,i]of Object.entries(r))e.includes(t)&&i.forEach((r=>{n.add(e.replace(t,r))})),i.forEach((r=>{e.includes(r)&&n.add(e.replace(r,t))}));return Array.from(n)};var Ae;function ve(t){switch(t){case 0:case"LOCATION_TYPE_UNSPECIFIED":return Ae.LOCATION_TYPE_UNSPECIFIED;case 1:case"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM":return Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case 2:case"LOCATION_TYPE_STATION":return Ae.LOCATION_TYPE_STATION;case 3:case"LOCATION_TYPE_ENTRANCE_EXIT":return Ae.LOCATION_TYPE_ENTRANCE_EXIT;case 4:case"LOCATION_TYPE_GENERIC_NODE":return Ae.LOCATION_TYPE_GENERIC_NODE;case 5:case"LOCATION_TYPE_BOARDING_AREA":return Ae.LOCATION_TYPE_BOARDING_AREA;default:return Ae.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"}(Ae||(Ae={}));const Oe={encode(t,e=new y){""!==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 S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={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;i.name=n.string();continue;case 2:if(18!==t)break;i.sourceStopId=n.string();continue;case 3:if(29!==t)break;i.lat=n.float();continue;case 4:if(37!==t)break;i.lon=n.float();continue;case 5:if(40===t){i.children.push(n.uint32());continue}if(42===t){const t=n.uint32()+n.pos;for(;n.pos<t;)i.children.push(n.uint32());continue}break;case 6:if(48!==t)break;i.parent=n.uint32();continue;case 7:if(56!==t)break;i.locationType=n.int32();continue;case 8:if(66!==t)break;i.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({name:Se(t.name)?globalThis.String(t.name):"",sourceStopId:Se(t.sourceStopId)?globalThis.String(t.sourceStopId):void 0,lat:Se(t.lat)?globalThis.Number(t.lat):void 0,lon:Se(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:Se(t.parent)?globalThis.Number(t.parent):void 0,locationType:Se(t.locationType)?ve(t.locationType):0,platform:Se(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 Ae.LOCATION_TYPE_UNSPECIFIED:return"LOCATION_TYPE_UNSPECIFIED";case Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM";case Ae.LOCATION_TYPE_STATION:return"LOCATION_TYPE_STATION";case Ae.LOCATION_TYPE_ENTRANCE_EXIT:return"LOCATION_TYPE_ENTRANCE_EXIT";case Ae.LOCATION_TYPE_GENERIC_NODE:return"LOCATION_TYPE_GENERIC_NODE";case Ae.LOCATION_TYPE_BOARDING_AREA:return"LOCATION_TYPE_BOARDING_AREA";case Ae.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>Oe.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,i,o,s,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!==(i=t.lon)&&void 0!==i?i:void 0,c.children=(null===(o=t.children)||void 0===o?void 0:o.map((t=>t)))||[],c.parent=null!==(s=t.parent)&&void 0!==s?s:void 0,c.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,c.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,c}};const ye={encode(t,e=new y){for(const n of t.stops)Oe.encode(n,e.uint32(18).fork()).join();return e},decode(t,e){const n=t instanceof S?t:new S(t),r=void 0===e?n.len:n.pos+e,i={stops:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 2:if(18!==t)break;i.stops.push(Oe.decode(n,n.uint32()));continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return i},fromJSON:t=>({stops:globalThis.Array.isArray(null==t?void 0:t.stops)?t.stops.map((t=>Oe.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=>Oe.toJSON(t)))),n},create:t=>ye.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=>Oe.fromPartial(t))))||[],n}};function Se(t){return null!=t}const Ne=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:Ue(e.locationType),platform:e.platform};var e}))}),be=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:we(n.locationType),platform:n.platform};var n})),we=t=>{switch(t){case Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case Ae.LOCATION_TYPE_STATION:return"STATION";case Ae.LOCATION_TYPE_ENTRANCE_EXIT:return"ENTRANCE_EXIT";case Ae.LOCATION_TYPE_GENERIC_NODE:return"GENERIC_NODE";case Ae.LOCATION_TYPE_BOARDING_AREA:return"BOARDING_AREA";case Ae.LOCATION_TYPE_UNSPECIFIED:throw new Error("Unspecified protobuf location type.");case Ae.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},Ue=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return Ae.LOCATION_TYPE_SIMPLE_STOP_OR_PLATFORM;case"STATION":return Ae.LOCATION_TYPE_STATION;case"ENTRANCE_EXIT":return Ae.LOCATION_TYPE_ENTRANCE_EXIT;case"GENERIC_NODE":return Ae.LOCATION_TYPE_GENERIC_NODE;case"BOARDING_AREA":return Ae.LOCATION_TYPE_BOARDING_AREA}};class Pe{constructor(t){var e;this.stops=t,this.sourceStopsMap=new Map;const n=new Map;this.stopPoints=[];for(let r=0;r<t.length;r++){const i=t[r];void 0!==i.sourceStopId&&this.sourceStopsMap.set(i.sourceStopId,r);const o=null!==(e=i.parent)&&void 0!==e?e:r;n.has(o)||n.set(o,{id:o,name:i.parent?this.stops[i.parent].name:i.name}),i.lat&&i.lon&&this.stopPoints.push({id:r,lat:i.lat,lon:i.lon})}this.textIndex=new ge({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:Re});const r=Array.from(n.values());((t,e)=>{for(const n of e)de(t,n)})(this.textIndex,r),this.geoIndex=new Ut(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 S(t),n=ye.decode(e);return new Pe(be(n))}serialize(){const t=Ne(this.stops),e=new y;return ye.encode(t,e),e.finish()}size(){return this.stops.length}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,i={...r,...n},o=me(t,e,n),s=[];for(const[e,{score:n,terms:r,match:a}]of o){const o=r.length||1,u={id:t._documentIds.get(e),score:n*o,terms:Object.keys(a),queryTerms:r,match:a};Object.assign(u,t._storedFields.get(e)),(null==i.filter||i.filter(u))&&s.push(u)}return e===Ee&&null==i.boostDocument||s.sort(ee),s})(this.textIndex,t).map((t=>this.stops[t.id])).slice(0,e)}findStopsByLocation(t,e,n=5,r=.5){const i=function(t,e,n,r=1/0,i=1/0){let o=1;const s=[];void 0===r&&(r=1/0),void 0!==i&&(o=St(i/6371));const a=new Rt([],yt);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(n*vt);for(;u;){const i=u.right,d=u.left;if(i-d<=t.nodeSize)for(let r=d;r<=i;r++){const i=t.ids[r];{const o=bt(e,n,t.coords[2*r],t.coords[2*r+1],c);a.push({id:i,dist:o})}}else{const r=d+i>>1,o=t.coords[2*r],s=t.coords[2*r+1],l=t.ids[r];{const t=bt(e,n,o,s,c);a.push({id:l,dist:t})}const f=(u.axis+1)%2,h={left:d,right:r-1,axis:f,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?o:u.maxLng,maxLat:1===u.axis?s:u.maxLat,dist:0},p={left:r+1,right:i,axis:f,minLng:0===u.axis?o:u.minLng,minLat:1===u.axis?s:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};h.dist=Ot(e,n,c,h),p.dist=Ot(e,n,c,p),a.push(h),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>o)return s;if(s.push(t.id),s.length===r)return s}u=a.pop()}return s}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stops[e.id]}));return i}findStopById(t){return this.stops[t]}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,n;const r=this.stops[t];if(!r)return[];const i=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,...i])).map((t=>this.stops[t]))}*[Symbol.iterator](){for(const t of this.stops)yield t}}exports.Plotter=class{constructor(t){this.result=t}stationNodeId(t){return`s_${t}`}vehicleEdgeNodeId(t,e,n,r){return`e_${t}_${e}_${n}_${r}`}transferEdgeNodeId(t,e,n){return`e_${t}_${e}_${n}`}continuationNodeId(t,e,n){return`continuation_${t}_${e}_${n}`}getRoundColor(t){var e;if(0===t)return n.colors.defaultRound;const r=Math.min(t-1,n.colors.rounds.length-1);return null!==(e=n.colors.rounds[r])&&void 0!==e?e:"#ee82ee"}getStationFillColor(t,e){return t?n.colors.originStation:e?n.colors.destinationStation:n.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),i=this.getStationInfo(t);return` "${r}" [label="${e}\\n${n}" shape=box style=filled fillcolor="${this.getStationFillColor(i.isOrigin,i.isDestination)}"];`}createVehicleEdge(e,n){const r=this.result.timetable.getRoute(e.routeId);if(!r)return[];const i=r.stopId(e.stopIndex),o=r.stopId(e.hopOffStopIndex),s=this.stationNodeId(i),a=this.stationNodeId(o),u=this.getRoundColor(n),c=this.vehicleEdgeNodeId(i,o,e.routeId,n),d=this.result.timetable.getServiceRouteInfo(r),l=d.name,f=d.type,h=t(r.departureFrom(e.stopIndex,e.tripIndex)),p=t(e.arrival),T=this.escapeDotString(l);return[` "${c}" [label="${`${this.escapeDotString(f)} ${T}\\n${`${e.routeId}:${e.tripIndex}`}\\n${h} → ${p}`}" shape=oval style=filled fillcolor="white" color="${u}"];`,` "${s}" -> "${c}" [color="${u}"];`,` "${c}" -> "${a}" [color="${u}"];`]}createTransferEdge(t,n){const r=this.stationNodeId(t.from),i=this.stationNodeId(t.to),o=this.getRoundColor(n),s=this.transferEdgeNodeId(t.from,t.to,n),a=void 0!==t.minTransferTime?e(t.minTransferTime):"N/A";return[` "${s}" [label="${`Transfer\\n${this.escapeDotString(a)}`}" shape=oval style="dashed,filled" fillcolor="white" color="${o}"];`,` "${r}" -> "${s}" [color="${o}" style="dashed"];`,` "${s}" -> "${i}" [color="${o}" style="dashed"];`]}createContinuationEdge(e,r,i){var o,s;const a=this.getVehicleEdgeToStopId(e),u=this.getVehicleEdgeFromStopId(r);if(!a||!u)return[];const c=this.stationNodeId(a),d=this.stationNodeId(u),l=this.getRoundColor(i),f=this.continuationNodeId(a,u,i),h=this.result.timetable.getRoute(e.routeId),p=this.result.timetable.getRoute(r.routeId),T=h?this.result.timetable.getServiceRouteInfo(h):null,E=p?this.result.timetable.getServiceRouteInfo(p):null,_=null!==(o=null==T?void 0:T.name)&&void 0!==o?o:`Route ${String(e.routeId)}`,I=null!==(s=null==E?void 0:E.name)&&void 0!==s?s:`Route ${String(r.routeId)}`,m=(null==T?void 0:T.type)||"UNKNOWN",g=(null==E?void 0:E.type)||"UNKNOWN",R=t(e.arrival),A=p?t(p.departureFrom(r.stopIndex,r.tripIndex)):"N/A",v=this.escapeDotString(_),O=this.escapeDotString(I),y=this.escapeDotString(m),S=this.escapeDotString(g),N=`${y} ${v} (${`${e.routeId}:${e.tripIndex}`}) ${R}\\n↓\\n${S} ${O} (${`${r.routeId}:${r.tripIndex}`}) ${A}`,{continuationFill:b}=n.colors,{continuation:w,continuationEdge:U}=n.penWidth;return[` "${f}" [label="${N}" shape=oval style="filled,bold" fillcolor="${b}" color="${l}" penwidth="${w}"];`,` "${c}" -> "${f}" [color="${l}" style="bold" penwidth="${U}"];`,` "${f}" -> "${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 i=n[e];if(void 0!==i&&(t.add(e),r(i))){const e=this.getVehicleEdgeFromStopId(i),n=this.getVehicleEdgeToStopId(i);e&&t.add(e),n&&t.add(n)}}return t}collectContinuationChain(t,e){const n=[];let r=t,i=t.continuationOf;for(;i;){const t=this.createContinuationEdge(i,r,e);n.push(...t),r=i,i=i.continuationOf}return n}collectEdges(){const t=[],e=[],n=this.result.routingState.graph;for(let o=0;o<n.length;o++){const s=n[o];if(s&&0!==o)for(let n=0;n<s.length;n++){const a=s[n];void 0!==a&&(r(a)?(t.push(...this.createVehicleEdge(a,o)),a.continuationOf&&e.push(...this.collectContinuationChain(a,o))):i(a)&&t.push(...this.createTransferEdge(a,o)))}}return[...t,...e]}plotDotGraph(){const t=this.collectStations(),e=this.collectEdges(),n=new o;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()}},exports.Query=pt,exports.Result=It,exports.Route=Tt,exports.Router=class{constructor(t,e){this.timetable=t,this.stopsIndex=e}route(t){const e=this.initRoutingState(t),n=new Set(e.origins),r=this.considerTransfers(t,0,n,e);for(const t of r)n.add(t);for(let r=1;r<=t.options.maxTransfers+1;r++){const i=new Array(e.nbStops);e.graph.push(i);const o=this.timetable.findReachableRoutes(n,t.options.transportModes);n.clear();for(const[i,s]of o){const o=this.scanRoute(i,s,r,e,t.options);for(const t of o)n.add(t)}let s=this.findTripContinuations(n,i);const a=new Set;for(;s.length>0;){a.clear();for(const t of s){const n=this.timetable.getRoute(t.routeId),i=this.scanRouteContinuation(n,t.stopIndex,r,e,t);for(const t of i)a.add(t)}for(const t of a)n.add(t);s=this.findTripContinuations(a,i)}const u=this.considerTransfers(t,r,n,e);for(const t of u)n.add(t);if(0===n.size)break}return new It(t,e,this.stopsIndex,this.timetable)}findTripContinuations(t,e){const n=[];for(const r of t){const t=e[r];if(!t||!("routeId"in t))continue;const i=this.timetable.getContinuousTrips(t.hopOffStopIndex,t.routeId,t.tripIndex);for(let e=0;e<i.length;e++){const r=i[e];n.push({routeId:r.routeId,stopIndex:r.stopIndex,tripIndex:r.tripIndex,previousEdge:t})}}return n}initRoutingState(t){const{from:e,to:n,departureTime:r}=t,i=this.stopsIndex.equivalentStops(e).map((t=>t.id)),o=Array.from(n).flatMap((t=>this.stopsIndex.equivalentStops(t))).map((t=>t.id));return new gt(i,o,r,this.timetable.nbStops())}scanRouteContinuation(t,e,n,r,i){const o=new Set,s=r.graph[n],a=this.earliestArrivalAtAnyStop(r),u=t.getNbStops(),c=t.id,d=i.tripIndex,l=t.tripStopOffset(d),f=i.previousEdge;for(let i=e;i<u;i++){const u=t.stops[i],h=t.arrivalAtOffset(i,l),p=t.dropOffTypeAtOffset(i,l),T=r.arrivalTime(u);1!==p&&h<T&&h<a&&(s[u]={routeId:c,stopIndex:e,tripIndex:d,arrival:h,hopOffStopIndex:i,continuationOf:f},r.updateArrival(u,h,n),o.add(u))}return o}scanRoute(t,e,n,r,i){const o=new Set,s=r.graph[n],a=r.graph[n-1],u=this.earliestArrivalAtAnyStop(r),c=t.getNbStops(),d=t.id;let l,f=e,h=0;for(let p=e;p<c;p++){const e=t.stops[p];if(void 0!==l){const i=t.arrivalAtOffset(p,h),a=t.dropOffTypeAtOffset(p,h),c=r.arrivalTime(e);1!==a&&i<c&&i<u&&(s[e]={routeId:d,stopIndex:f,tripIndex:l,arrival:i,hopOffStopIndex:p},r.updateArrival(e,i,n),o.add(e))}const c=a[e],T=null==c?void 0:c.arrival;if(void 0!==T&&(void 0===l||T<=t.departureFrom(p,l))){const e=t.findEarliestTrip(p,T,l);if(void 0===e)continue;const n=this.findFirstBoardableTrip(p,t,e,T,l,c&&"routeId"in c?c:void 0,i.minTransferTime);void 0!==n&&(l=n,f=p,h=t.tripStopOffset(n))}}return o}findFirstBoardableTrip(t,e,n,r=0,i,o,s=0){const a=e.getNbTrips();for(let u=n;u<(null!=i?i:a);u++){if(1===e.pickUpTypeFrom(t,u))continue;if(void 0===o)return u;if(this.timetable.isTripTransferGuaranteed({stopIndex:o.hopOffStopIndex,routeId:o.routeId,tripIndex:o.tripIndex},{stopIndex:t,routeId:e.id,tripIndex:u}))return u;if(e.departureFrom(t,u)>=r+s)return u}}considerTransfers(t,e,n,r){const{options:i}=t,o=r.graph[e],s=new Set;for(const t of n){const n=o[t];if(!n||"type"in n)continue;const a=this.timetable.getTransfers(t);for(let u=0;u<a.length;u++){const c=a[u];let d;d=c.minTransferTime?c.minTransferTime:"IN_SEAT"===c.type?0:i.minTransferTime;const l=n.arrival+d;l<r.arrivalTime(c.destination)&&(o[c.destination]={arrival:l,from:t,to:c.destination,minTransferTime:c.minTransferTime,type:c.type},r.updateArrival(c.destination,l,e),s.add(c.destination))}}return s}earliestArrivalAtAnyStop(t){let e=mt;for(let n=0;n<t.destinations.length;n++){const r=t.arrivalTime(t.destinations[n]);r<e&&(e=r)}return e}},exports.StopsIndex=Pe,exports.Timetable=ht;
|
|
2
2
|
//# sourceMappingURL=router.cjs.js.map
|