minotor 3.0.1 → 3.0.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/.cspell.json +12 -1
- package/.gitattributes +3 -0
- package/.github/PULL_REQUEST_TEMPLATE.md +3 -0
- package/.github/workflows/minotor.yml +17 -1
- package/CHANGELOG.md +2 -2
- package/README.md +34 -14
- package/dist/__e2e__/router.test.d.ts +1 -0
- package/dist/cli/perf.d.ts +28 -0
- package/dist/cli/utils.d.ts +6 -2
- package/dist/cli.mjs +1967 -823
- package/dist/cli.mjs.map +1 -1
- package/dist/gtfs/trips.d.ts +1 -0
- package/dist/gtfs/utils.d.ts +1 -1
- package/dist/parser.cjs.js +1030 -627
- package/dist/parser.cjs.js.map +1 -1
- package/dist/parser.d.ts +4 -2
- package/dist/parser.esm.js +1030 -627
- 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.d.ts +10 -5
- 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/__tests__/result.test.d.ts +1 -0
- package/dist/routing/query.d.ts +27 -6
- package/dist/routing/result.d.ts +1 -1
- package/dist/routing/route.d.ts +47 -2
- package/dist/routing/router.d.ts +15 -1
- package/dist/stops/stopsIndex.d.ts +3 -3
- package/dist/timetable/__tests__/route.test.d.ts +1 -0
- package/dist/timetable/__tests__/time.test.d.ts +1 -0
- package/dist/timetable/io.d.ts +7 -1
- package/dist/timetable/proto/timetable.d.ts +1 -1
- package/dist/timetable/route.d.ts +155 -0
- package/dist/timetable/time.d.ts +21 -0
- package/dist/timetable/timetable.d.ts +41 -61
- package/package.json +36 -34
- package/src/__e2e__/benchmark.json +22 -0
- package/src/__e2e__/router.test.ts +209 -0
- package/src/__e2e__/timetable/stops.bin +3 -0
- package/src/__e2e__/timetable/timetable.bin +3 -0
- package/src/cli/minotor.ts +51 -1
- package/src/cli/perf.ts +136 -0
- package/src/cli/repl.ts +26 -13
- package/src/cli/utils.ts +6 -28
- package/src/gtfs/__tests__/parser.test.ts +12 -15
- package/src/gtfs/__tests__/services.test.ts +1 -0
- package/src/gtfs/__tests__/transfers.test.ts +0 -1
- package/src/gtfs/__tests__/trips.test.ts +67 -74
- package/src/gtfs/profiles/ch.ts +1 -1
- package/src/gtfs/routes.ts +4 -4
- package/src/gtfs/services.ts +15 -2
- package/src/gtfs/stops.ts +7 -3
- package/src/gtfs/transfers.ts +6 -3
- package/src/gtfs/trips.ts +33 -16
- package/src/gtfs/utils.ts +13 -2
- package/src/parser.ts +4 -2
- package/src/router.ts +17 -11
- package/src/routing/__tests__/result.test.ts +392 -0
- package/src/routing/__tests__/router.test.ts +94 -137
- package/src/routing/query.ts +28 -7
- package/src/routing/result.ts +10 -5
- package/src/routing/route.ts +95 -9
- package/src/routing/router.ts +82 -66
- package/src/stops/__tests__/io.test.ts +1 -1
- package/src/stops/__tests__/stopFinder.test.ts +1 -1
- package/src/stops/proto/stops.ts +4 -4
- package/src/stops/stopsIndex.ts +3 -3
- package/src/timetable/__tests__/io.test.ts +16 -23
- package/src/timetable/__tests__/route.test.ts +317 -0
- package/src/timetable/__tests__/time.test.ts +494 -0
- package/src/timetable/__tests__/timetable.test.ts +64 -75
- package/src/timetable/io.ts +32 -26
- package/src/timetable/proto/timetable.proto +1 -1
- package/src/timetable/proto/timetable.ts +13 -13
- package/src/timetable/route.ts +347 -0
- package/src/timetable/time.ts +40 -8
- package/src/timetable/timetable.ts +74 -165
- package/tsconfig.build.json +1 -1
package/dist/router.d.ts
CHANGED
|
@@ -1,11 +1,16 @@
|
|
|
1
1
|
import { Plotter } from './routing/plotter.js';
|
|
2
2
|
import { Query } from './routing/query.js';
|
|
3
3
|
import { Result } from './routing/result.js';
|
|
4
|
-
import { Leg,
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
4
|
+
import type { Leg, Transfer, VehicleLeg } from './routing/route.js';
|
|
5
|
+
import { Route } from './routing/route.js';
|
|
6
|
+
import type { ReachingTime } from './routing/router.js';
|
|
7
|
+
import { Router } from './routing/router.js';
|
|
8
|
+
import type { LocationType, SourceStopId, StopId } from './stops/stops.js';
|
|
9
|
+
import type { Stop } from './stops/stops.js';
|
|
7
10
|
import { StopsIndex } from './stops/stopsIndex.js';
|
|
8
11
|
import { Duration } from './timetable/duration.js';
|
|
9
12
|
import { Time } from './timetable/time.js';
|
|
10
|
-
import { RouteType, ServiceRoute,
|
|
11
|
-
|
|
13
|
+
import type { RouteType, ServiceRoute, TransferType } from './timetable/timetable.js';
|
|
14
|
+
import { Timetable } from './timetable/timetable.js';
|
|
15
|
+
export { Duration, Plotter, Query, Result, Route, Router, StopsIndex, Time, Timetable, };
|
|
16
|
+
export type { Leg, LocationType, ReachingTime, RouteType, ServiceRoute, SourceStopId, Stop, StopId, Transfer, TransferType, VehicleLeg, };
|
package/dist/router.esm.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
class t{constructor(t){this.result=t}plotDotGraph(){const t=this.result.earliestArrivalsPerRound,e=["digraph PathTree {"," graph [overlap=false];"," node [shape=ellipse style=filled fillcolor=lightgrey];"];return t.forEach(((t,n)=>{t.forEach((t=>{const{origin:r,leg:s}=t;if(!s)return;const o=this.result.stopsIndex.findStopById(s.from.id),i=this.result.stopsIndex.findStopById(s.to.id),a=this.result.stopsIndex.findStopById(r);if(o&&i&&a){const t=o.platform?`${o.name} (Pl. ${o.platform})`:o.name,r=i.platform?`${i.name} (Pl. ${i.platform})`:i.name,u=a.platform?`${a.name} (Pl. ${a.platform})`:a.name,c="route"in s,l=c?`${s.route.name}\n${s.departureTime.toString()} - ${s.arrivalTime.toString()}`:s.minTransferTime?s.minTransferTime.toString():"",d=`IntermediateNode${o.id}_${i.id}`,f=c?"":', color="red", fontcolor="red"',h=c?"":' fontcolor="red"';e.push(` "${t} (Origin: ${u}) [R${n}]\n(${o.id})" -> "${d}" [shape=point${f}];`),e.push(` "${d}" [label="${l}" shape=rect style=filled fillcolor=white${h} border=0];`),e.push(` "${d}" -> "${r} (Origin: ${u}) [R${n}]\n(${i.id})" [${f.replace(", ","")}];`)}}))})),e.push("}"),e.join("\n")}}class e{constructor(t){this.totalSeconds=t}static fromSeconds(t){return new e(t)}static fromMinutes(t){return new e(60*t)}static zero(){return new e(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),n=this.totalSeconds%60;return t>0?`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`:`${e.toString().padStart(2,"0")}:${n.toString().padStart(2,"0")}`}toSeconds(){return this.totalSeconds}add(t){const n=this.totalSeconds+t.toSeconds();return new e(n)}subtract(t){const n=Math.max(0,this.totalSeconds-t.toSeconds());return new e(n)}}function n(){let t=0,e=0;for(let n=0;n<28;n+=7){let r=this.buf[this.pos++];if(t|=(127&r)<<n,!(128&r))return this.assertBounds(),[t,e]}let n=this.buf[this.pos++];if(t|=(15&n)<<28,e=(112&n)>>4,!(128&n))return this.assertBounds(),[t,e];for(let n=3;n<=31;n+=7){let r=this.buf[this.pos++];if(e|=(127&r)<<n,!(128&r))return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function r(t,e,n){for(let r=0;r<28;r+=7){const s=t>>>r,o=!(s>>>7==0&&0==e),i=255&(o?128|s:s);if(n.push(i),!o)return}const r=t>>>28&15|(7&e)<<4,s=!!(e>>3);if(n.push(255&(s?128|r:r)),s){for(let t=3;t<31;t+=7){const r=e>>>t,s=!(r>>>7==0),o=255&(s?128|r:r);if(n.push(o),!s)return}n.push(e>>>31&1)}}const s=4294967296;function o(t){const e="-"===t[0];e&&(t=t.slice(1));const n=1e6;let r=0,o=0;function i(e,i){const a=Number(t.slice(e,i));o*=n,r=r*n+a,r>=s&&(o+=r/s|0,r%=s)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?u(r,o):a(r,o)}function i(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(s*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,a=2*r;const u=1e7;return o>=u&&(i+=Math.floor(o/u),o%=u),i>=u&&(a+=Math.floor(i/u),i%=u),a.toString()+c(i)+c(o)}function a(t,e){return{lo:0|t,hi:0|e}}function u(t,e){return e=~e,t?t=1+~t:e+=1,a(t,e)}const c=t=>{const e=String(t);return"0000000".slice(e.length)+e};function l(t,e){if(t>=0){for(;t>127;)e.push(127&t|128),t>>>=7;e.push(t)}else{for(let n=0;n<9;n++)e.push(127&t|128),t>>=7;e.push(1)}}function d(){let t=this.buf[this.pos++],e=127&t;if(!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<7,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<14,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<21,!(128&t))return this.assertBounds(),e;t=this.buf[this.pos++],e|=(15&t)<<28;for(let e=5;128&t&&e<10;e++)t=this.buf[this.pos++];if(128&t)throw new Error("invalid varint");return this.assertBounds(),e>>>0}const f=h();function h(){const t=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof t.getBigInt64&&"function"==typeof t.getBigUint64&&"function"==typeof t.setBigInt64&&"function"==typeof t.setBigUint64&&("object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const e=BigInt("-9223372036854775808"),n=BigInt("9223372036854775807"),r=BigInt("0"),s=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const r="bigint"==typeof t?t:BigInt(t);if(r>n||r<e)throw new Error(`invalid int64: ${t}`);return r},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>s||e<r)throw new Error(`invalid uint64: ${t}`);return e},enc(e){return t.setBigInt64(0,this.parse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(e){return t.setBigInt64(0,this.uParse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigInt64(0,!0)),uDec:(e,n)=>(t.setInt32(0,e,!0),t.setInt32(4,n,!0),t.getBigUint64(0,!0))}}return{zero:"0",supported:!1,parse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),m(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),p(t),o(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),m(t),o(t)),dec:(t,e)=>function(t,e){let n=a(t,e);const r=2147483648&n.hi;r&&(n=u(n.lo,n.hi));const s=i(n.lo,n.hi);return r?"-"+s:s}(t,e),uDec:(t,e)=>i(t,e)}}function p(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function m(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const g=Symbol.for("@bufbuild/protobuf/text-encoding");function v(){if(null==globalThis[g]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[g]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[g]}var y;!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"}(y||(y={}));const T=34028234663852886e22,E=-34028234663852886e22;class I{constructor(t=v().encodeUtf8){this.encodeUtf8=t,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let t=0;for(let e=0;e<this.chunks.length;e++)t+=this.chunks[e].length;let e=new Uint8Array(t),n=0;for(let t=0;t<this.chunks.length;t++)e.set(this.chunks[t],n),n+=this.chunks[t].length;return this.chunks=[],e}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let t=this.finish(),e=this.stack.pop();if(!e)throw new Error("invalid state, fork stack empty");return this.chunks=e.chunks,this.buf=e.buf,this.uint32(t.byteLength),this.raw(t)}tag(t,e){return this.uint32((t<<3|e)>>>0)}raw(t){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(t),this}uint32(t){for(S(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return w(t),l(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.encodeUtf8(t);return this.uint32(e.byteLength),this.raw(e)}float(t){!function(t){if("string"==typeof t){const e=t;if(t=Number(t),Number.isNaN(t)&&"NaN"!==e)throw new Error("invalid float32: "+e)}else if("number"!=typeof t)throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>T||t<E))throw new Error("invalid float32: "+t)}(t);let e=new Uint8Array(4);return new DataView(e.buffer).setFloat32(0,t,!0),this.raw(e)}double(t){let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t,!0),this.raw(e)}fixed32(t){S(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){w(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return w(t),l(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),n=new DataView(e.buffer),r=f.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=f.uEnc(t);return n.setInt32(0,r.lo,!0),n.setInt32(4,r.hi,!0),this.raw(e)}int64(t){let e=f.enc(t);return r(e.lo,e.hi,this.buf),this}sint64(t){const e=f.enc(t),n=e.hi>>31;return r(e.lo<<1^n,(e.hi<<1|e.lo>>>31)^n,this.buf),this}uint64(t){const e=f.uEnc(t);return r(e.lo,e.hi,this.buf),this}}class A{constructor(t,e=v().decodeUtf8){this.decodeUtf8=e,this.varint64=n,this.uint32=d,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 y.Varint:for(;128&this.buf[this.pos++];);break;case y.Bit64:this.pos+=4;case y.Bit32:this.pos+=4;break;case y.LengthDelimited:let n=this.uint32();this.pos+=n;break;case y.StartGroup:for(;;){const[t,n]=this.tag();if(n===y.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 f.dec(...this.varint64())}uint64(){return f.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),n=-(1&t);return t=(t>>>1|(1&e)<<31)^n,e=e>>>1^n,f.dec(t,e)}bool(){let[t,e]=this.varint64();return 0!==t||0!==e}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return f.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return f.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let t=this.uint32(),e=this.pos;return this.pos+=t,this.assertBounds(),this.buf.subarray(e,e+t)}string(){return this.decodeUtf8(this.bytes())}}function w(t){if("string"==typeof t)t=Number(t);else if("number"!=typeof t)throw new Error("invalid int32: "+typeof t);if(!Number.isInteger(t)||t>2147483647||t<-2147483648)throw new Error("invalid int32: "+t)}function S(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 b,R;function _(t){switch(t){case 0:case"RECOMMENDED_TRANSFER_POINT":return b.RECOMMENDED_TRANSFER_POINT;case 1:case"TIMED_TRANSFER":return b.TIMED_TRANSFER;case 2:case"REQUIRES_MINIMAL_TIME":return b.REQUIRES_MINIMAL_TIME;case 3:case"IN_SEAT_TRANSFER":return b.IN_SEAT_TRANSFER;default:return b.UNRECOGNIZED}}function N(t){switch(t){case 0:case"TRAM":return R.TRAM;case 1:case"SUBWAY":return R.SUBWAY;case 2:case"RAIL":return R.RAIL;case 3:case"BUS":return R.BUS;case 4:case"FERRY":return R.FERRY;case 5:case"CABLE_TRAM":return R.CABLE_TRAM;case 6:case"AERIAL_LIFT":return R.AERIAL_LIFT;case 7:case"FUNICULAR":return R.FUNICULAR;case 8:case"TROLLEYBUS":return R.TROLLEYBUS;case 9:case"MONORAIL":return R.MONORAIL;default:return R.UNRECOGNIZED}}function O(){return{stopTimes:new Uint8Array(0),pickUpDropOffTypes:new Uint8Array(0),stops:new Uint8Array(0),serviceRouteId:""}}!function(t){t[t.RECOMMENDED_TRANSFER_POINT=0]="RECOMMENDED_TRANSFER_POINT",t[t.TIMED_TRANSFER=1]="TIMED_TRANSFER",t[t.REQUIRES_MINIMAL_TIME=2]="REQUIRES_MINIMAL_TIME",t[t.IN_SEAT_TRANSFER=3]="IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(b||(b={})),function(t){t[t.TRAM=0]="TRAM",t[t.SUBWAY=1]="SUBWAY",t[t.RAIL=2]="RAIL",t[t.BUS=3]="BUS",t[t.FERRY=4]="FERRY",t[t.CABLE_TRAM=5]="CABLE_TRAM",t[t.AERIAL_LIFT=6]="AERIAL_LIFT",t[t.FUNICULAR=7]="FUNICULAR",t[t.TROLLEYBUS=8]="TROLLEYBUS",t[t.MONORAIL=9]="MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(R||(R={}));const M={encode:(t,e=new I)=>(0!==t.stopTimes.length&&e.uint32(10).bytes(t.stopTimes),0!==t.pickUpDropOffTypes.length&&e.uint32(18).bytes(t.pickUpDropOffTypes),0!==t.stops.length&&e.uint32(26).bytes(t.stops),""!==t.serviceRouteId&&e.uint32(34).string(t.serviceRouteId),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s=O();for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopTimes=n.bytes();continue;case 2:if(18!==t)break;s.pickUpDropOffTypes=n.bytes();continue;case 3:if(26!==t)break;s.stops=n.bytes();continue;case 4:if(34!==t)break;s.serviceRouteId=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stopTimes:G(t.stopTimes)?z(t.stopTimes):new Uint8Array(0),pickUpDropOffTypes:G(t.pickUpDropOffTypes)?z(t.pickUpDropOffTypes):new Uint8Array(0),stops:G(t.stops)?z(t.stops):new Uint8Array(0),serviceRouteId:G(t.serviceRouteId)?globalThis.String(t.serviceRouteId):""}),toJSON(t){const e={};return 0!==t.stopTimes.length&&(e.stopTimes=$(t.stopTimes)),0!==t.pickUpDropOffTypes.length&&(e.pickUpDropOffTypes=$(t.pickUpDropOffTypes)),0!==t.stops.length&&(e.stops=$(t.stops)),""!==t.serviceRouteId&&(e.serviceRouteId=t.serviceRouteId),e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s;const o=O();return o.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),o.pickUpDropOffTypes=null!==(n=t.pickUpDropOffTypes)&&void 0!==n?n:new Uint8Array(0),o.stops=null!==(r=t.stops)&&void 0!==r?r:new Uint8Array(0),o.serviceRouteId=null!==(s=t.serviceRouteId)&&void 0!==s?s:"",o}};const k={encode:(t,e=new I)=>(Object.entries(t.routes).forEach((([t,n])=>{L.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={routes:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=L.decode(n,n.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:J(t.routes)?Object.entries(t.routes).reduce(((t,[e,n])=>(t[e]=M.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const n=Object.entries(t.routes);n.length>0&&(e.routes={},n.forEach((([t,n])=>{e.routes[t]=M.toJSON(n)})))}return e},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={routes:{}};return n.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=M.fromPartial(n)),t)),{}),n}};const L={encode:(t,e=new I)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&M.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=M.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:G(t.key)?globalThis.String(t.key):"",value:G(t.value)?M.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=M.toJSON(t.value)),e},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?M.fromPartial(t.value):void 0,n}};const U={encode:(t,e=new I)=>(0!==t.destination&&e.uint32(8).uint32(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).int32(t.minTransferTime),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={destination:0,type:0,minTransferTime:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.destination=n.uint32();continue;case 2:if(16!==t)break;s.type=n.int32();continue;case 3:if(24!==t)break;s.minTransferTime=n.int32();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({destination:G(t.destination)?globalThis.Number(t.destination):0,type:G(t.type)?_(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 b.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED_TRANSFER_POINT";case b.TIMED_TRANSFER:return"TIMED_TRANSFER";case b.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case b.IN_SEAT_TRANSFER:return"IN_SEAT_TRANSFER";case b.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r;const s={destination:0,type:0,minTransferTime:void 0};return s.destination=null!==(e=t.destination)&&void 0!==e?e:0,s.type=null!==(n=t.type)&&void 0!==n?n:0,s.minTransferTime=null!==(r=t.minTransferTime)&&void 0!==r?r:void 0,s}};const x={encode:(t,e=new I)=>(Object.entries(t.stops).forEach((([t,n])=>{B.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={stops:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=B.decode(n,n.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({stops:J(t.stops)?Object.entries(t.stops).reduce(((t,[e,n])=>(t[e]=D.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.stops){const n=Object.entries(t.stops);n.length>0&&(e.stops={},n.forEach((([t,n])=>{e.stops[t]=D.toJSON(n)})))}return e},create:t=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={stops:{}};return n.stops=Object.entries(null!==(e=t.stops)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=D.fromPartial(n)),t)),{}),n}};const D={encode(t,e=new I){for(const n of t.transfers)U.encode(n,e.uint32(10).fork()).join();for(const n of t.routes)e.uint32(18).string(n);return e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={transfers:[],routes:[]};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.transfers.push(U.decode(n,n.uint32()));continue;case 2:if(18!==t)break;s.routes.push(n.string());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>U.fromJSON(t))):[],routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.String(t))):[]}),toJSON(t){var e,n;const r={};return(null===(e=t.transfers)||void 0===e?void 0:e.length)&&(r.transfers=t.transfers.map((t=>U.toJSON(t)))),(null===(n=t.routes)||void 0===n?void 0:n.length)&&(r.routes=t.routes),r},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={transfers:[],routes:[]};return r.transfers=(null===(e=t.transfers)||void 0===e?void 0:e.map((t=>U.fromPartial(t))))||[],r.routes=(null===(n=t.routes)||void 0===n?void 0:n.map((t=>t)))||[],r}};const B={encode:(t,e=new I)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&D.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=D.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:G(t.key)?globalThis.String(t.key):"",value:G(t.value)?D.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=D.toJSON(t.value)),e},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?D.fromPartial(t.value):void 0,n}};const F={encode:(t,e=new I)=>(0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={type:0,name:""};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.type=n.int32();continue;case 2:if(18!==t)break;s.name=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({type:G(t.type)?N(t.type):0,name:G(t.name)?globalThis.String(t.name):""}),toJSON(t){const e={};return 0!==t.type&&(e.type=function(t){switch(t){case R.TRAM:return"TRAM";case R.SUBWAY:return"SUBWAY";case R.RAIL:return"RAIL";case R.BUS:return"BUS";case R.FERRY:return"FERRY";case R.CABLE_TRAM:return"CABLE_TRAM";case R.AERIAL_LIFT:return"AERIAL_LIFT";case R.FUNICULAR:return"FUNICULAR";case R.TROLLEYBUS:return"TROLLEYBUS";case R.MONORAIL:return"MONORAIL";case R.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),""!==t.name&&(e.name=t.name),e},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={type:0,name:""};return r.type=null!==(e=t.type)&&void 0!==e?e:0,r.name=null!==(n=t.name)&&void 0!==n?n:"",r}};const j={encode:(t,e=new I)=>(Object.entries(t.routes).forEach((([t,n])=>{C.encode({key:t,value:n},e.uint32(10).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={routes:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=C.decode(n,n.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({routes:J(t.routes)?Object.entries(t.routes).reduce(((t,[e,n])=>(t[e]=F.fromJSON(n),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const n=Object.entries(t.routes);n.length>0&&(e.routes={},n.forEach((([t,n])=>{e.routes[t]=F.toJSON(n)})))}return e},create:t=>j.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={routes:{}};return n.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[e]=F.fromPartial(n)),t)),{}),n}};const C={encode:(t,e=new I)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&F.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:"",value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=n.string();continue;case 2:if(18!==t)break;s.value=F.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:G(t.key)?globalThis.String(t.key):"",value:G(t.value)?F.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=F.toJSON(t.value)),e},create:t=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:"",value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:"",n.value=void 0!==t.value&&null!==t.value?F.fromPartial(t.value):void 0,n}};const P={encode:(t,e=new I)=>(""!==t.version&&e.uint32(10).string(t.version),void 0!==t.stopsAdjacency&&x.encode(t.stopsAdjacency,e.uint32(18).fork()).join(),void 0!==t.routesAdjacency&&k.encode(t.routesAdjacency,e.uint32(26).fork()).join(),void 0!==t.routes&&j.encode(t.routes,e.uint32(34).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=n.string();continue;case 2:if(18!==t)break;s.stopsAdjacency=x.decode(n,n.uint32());continue;case 3:if(26!==t)break;s.routesAdjacency=k.decode(n,n.uint32());continue;case 4:if(34!==t)break;s.routes=j.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({version:G(t.version)?globalThis.String(t.version):"",stopsAdjacency:G(t.stopsAdjacency)?x.fromJSON(t.stopsAdjacency):void 0,routesAdjacency:G(t.routesAdjacency)?k.fromJSON(t.routesAdjacency):void 0,routes:G(t.routes)?j.fromJSON(t.routes):void 0}),toJSON(t){const e={};return""!==t.version&&(e.version=t.version),void 0!==t.stopsAdjacency&&(e.stopsAdjacency=x.toJSON(t.stopsAdjacency)),void 0!==t.routesAdjacency&&(e.routesAdjacency=k.toJSON(t.routesAdjacency)),void 0!==t.routes&&(e.routes=j.toJSON(t.routes)),e},create:t=>P.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};return n.version=null!==(e=t.version)&&void 0!==e?e:"",n.stopsAdjacency=void 0!==t.stopsAdjacency&&null!==t.stopsAdjacency?x.fromPartial(t.stopsAdjacency):void 0,n.routesAdjacency=void 0!==t.routesAdjacency&&null!==t.routesAdjacency?k.fromPartial(t.routesAdjacency):void 0,n.routes=void 0!==t.routes&&null!==t.routes?j.fromPartial(t.routes):void 0,n}};function z(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),n=new Uint8Array(e.length);for(let t=0;t<e.length;++t)n[t]=e.charCodeAt(t);return n}}function $(t){if(globalThis.Buffer)return globalThis.Buffer.from(t).toString("base64");{const e=[];return t.forEach((t=>{e.push(globalThis.String.fromCharCode(t))})),globalThis.btoa(e.join(""))}}function J(t){return"object"==typeof t&&null!==t}function G(t){return null!=t}const V=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),Y=!0;function W(t){if(V===Y)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint32(4*e,t[e],Y);return e}function Z(t){if(V===Y)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),n=new DataView(e.buffer);for(let e=0;e<t.length;e++)n.setUint16(2*e,t[e],Y);return e}function q(t){if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(V===Y)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint16(2*t,Y);return e}const H=t=>{const e={stops:{}};return t.forEach(((t,n)=>{e.stops[n]={transfers:t.transfers.map((t=>Object.assign({destination:t.destination,type:et(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))),routes:t.routes}})),e},X=t=>{const e={routes:{}};return t.forEach(((t,n)=>{e.routes[n]={stopTimes:Z(t.stopTimes),pickUpDropOffTypes:t.pickUpDropOffTypes,stops:W(t.stops),serviceRouteId:t.serviceRouteId}})),e},Q=t=>{const e={routes:{}};return t.forEach(((t,n)=>{e.routes[n]={type:rt(t.type),name:t.name}})),e},K=t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,n])=>{const r=function(t){if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(V===Y)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),n=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=n.getUint32(4*t,Y);return e}(n.stops),s=new Map;for(let t=0;t<r.length;t++)s.set(r[t],t);e.set(t,{stopTimes:q(n.stopTimes),pickUpDropOffTypes:n.pickUpDropOffTypes,stops:r,stopIndices:s,serviceRouteId:n.serviceRouteId})})),e},tt=t=>{switch(t){case b.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case b.TIMED_TRANSFER:return"GUARANTEED";case b.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case b.IN_SEAT_TRANSFER:return"IN_SEAT";case b.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},et=t=>{switch(t){case"RECOMMENDED":return b.RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return b.TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return b.REQUIRES_MINIMAL_TIME;case"IN_SEAT":return b.IN_SEAT_TRANSFER}},nt=t=>{switch(t){case R.TRAM:return"TRAM";case R.SUBWAY:return"SUBWAY";case R.RAIL:return"RAIL";case R.BUS:return"BUS";case R.FERRY:return"FERRY";case R.CABLE_TRAM:return"CABLE_TRAM";case R.AERIAL_LIFT:return"AERIAL_LIFT";case R.FUNICULAR:return"FUNICULAR";case R.TROLLEYBUS:return"TROLLEYBUS";case R.MONORAIL:return"MONORAIL";case R.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},rt=t=>{switch(t){case"TRAM":return R.TRAM;case"SUBWAY":return R.SUBWAY;case"RAIL":return R.RAIL;case"BUS":return R.BUS;case"FERRY":return R.FERRY;case"CABLE_TRAM":return R.CABLE_TRAM;case"AERIAL_LIFT":return R.AERIAL_LIFT;case"FUNICULAR":return R.FUNICULAR;case"TROLLEYBUS":return R.TROLLEYBUS;case"MONORAIL":return R.MONORAIL}};class st{static infinity(){return new st(Number.MAX_SAFE_INTEGER)}static origin(){return new st(0)}constructor(t){this.minutesSinceMidnight=t}static fromMinutes(t){return new st(t)}static fromHMS(t,e,n){if(t<0||e<0||n<0||e>=60||n>=60)throw new Error("Invalid time. Ensure hours, minutes, and seconds are valid values.");const r=n+60*e+3600*t,s=Math.round(r/60);return new st(s)}static fromHM(t,e){if(t<0||e<0||e>=60)throw new Error("Invalid time. Ensure hours and minutes are valid values.");return new st(e+60*t)}static fromDate(t){const e=t.getHours(),n=t.getMinutes(),r=t.getSeconds();return st.fromHMS(e,n,r)}static fromString(t){const[e,n,r]=t.split(":");if(void 0===e||void 0===n||isNaN(Number(e))||isNaN(Number(n))||void 0!==r&&isNaN(Number(r)))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const s=parseInt(e,10),o=parseInt(n,10),i=void 0!==r?parseInt(r,10):0;return st.fromHMS(s,o,i)}toString(){const t=Math.floor(this.minutesSinceMidnight/60),e=Math.floor(this.minutesSinceMidnight%60);return`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}toMinutes(){return this.minutesSinceMidnight}plus(t){const e=60*this.minutesSinceMidnight+t.toSeconds();return new st(Math.round(e/60))}minus(t){let e=60*this.minutesSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new st(Math.round(e/60))}diff(t){const n=this.minutesSinceMidnight-t.toMinutes();return e.fromSeconds(Math.abs(60*n))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.toMinutes()>t.toMinutes()?e:t))}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.toMinutes()<t.toMinutes()?e:t))}}const ot=["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"],it="0.0.3";class at{constructor(t,e,n){this.stopsAdjacency=t,this.routesAdjacency=e,this.routes=n}serialize(){const t={version:it,stopsAdjacency:H(this.stopsAdjacency),routesAdjacency:X(this.routesAdjacency),routes:Q(this.routes)},e=new I;return P.encode(t,e),e.finish()}static fromData(t){const n=new A(t),r=P.decode(n);if(r.version!==it)throw new Error(`Unsupported timetable version ${r.version}`);return new at((t=>{const n=new Map;return Object.entries(t.stops).forEach((([t,r])=>{const s=parseInt(t,10);n.set(s,{transfers:r.transfers.map((t=>Object.assign({destination:t.destination,type:tt(t.type)},void 0!==t.minTransferTime&&{minTransferTime:e.fromSeconds(t.minTransferTime)}))),routes:r.routes})})),n})(r.stopsAdjacency),K(r.routesAdjacency),(t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,n])=>{e.set(t,{type:nt(n.type),name:n.name})})),e})(r.routes))}getRoutesThroughStop(t){const e=this.stopsAdjacency.get(t);return e?e.routes:[]}getRoute(t){return this.routesAdjacency.get(t)}getTransfers(t){var e,n;return null!==(n=null===(e=this.stopsAdjacency.get(t))||void 0===e?void 0:e.transfers)&&void 0!==n?n:[]}findReachableRoutes(t,e=ot){var n;const r=new Map;for(const s of t){const t=null===(n=this.stopsAdjacency.get(s))||void 0===n?void 0:n.routes.filter((t=>{const n=this.getServiceRouteFromRouteId(t);return!!n&&e.includes(n.type)}));for(const e of t||[]){const t=r.get(e);if(t){const n=this.routesAdjacency.get(e).stopIndices;n.get(s)<n.get(t)&&r.set(e,s)}else r.set(e,s)}}return r}getServiceRouteFromRouteId(t){const e=this.routesAdjacency.get(t);if(e)return this.routes.get(e.serviceRouteId);console.warn(`Route ${t} not found.`)}getServiceRoute(t){return this.routes.get(t)}findEarliestTrip(t,e,n,r=st.origin()){const s=t.stopIndices.get(e),o=t.stops.length;if(void 0!==n){let e,i;for(let a=n;a>=0;a--){const n=a*o+s,u=t.stopTimes[2*n+1],c=t.pickUpDropOffTypes[2*n];if(u<r.toMinutes())break;1!==c&&(void 0===i||u<i.toMinutes())&&(e=a,i=st.fromMinutes(u))}return e}for(let e=0;e<t.stopTimes.length/o;e++){const n=e*o+s,i=t.stopTimes[2*n+1],a=t.pickUpDropOffTypes[2*n];if(i>=r.toMinutes()&&1!==a)return e}}}class ut{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}ut.Builder=class{constructor(){this.toValue=[],this.optionsValue={maxTransfers:5,minTransferTime:e.fromSeconds(120),transportModes:ot}}from(t){return this.fromValue=t,this}to(t){return this.toValue=Array.isArray(t)?t:[t],this}departureTime(t){return this.departureTimeValue=t,this}maxTransfers(t){return this.optionsValue.maxTransfers=t,this}minTransferTime(t){return this.optionsValue.minTransferTime=t,this}transportModes(t){return this.optionsValue.transportModes=t,this}build(){return new ut(this)}};class ct{constructor(t){this.legs=t}departureTime(){const t=e.zero();for(let e=0;e<this.legs.length;e++){const n=this.legs[e];if("departureTime"in n)return n.departureTime.minus(t);"minTransferTime"in n&&n.minTransferTime&&t.add(n.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let t=st.origin();const n=e.zero();let r=!1;for(let e=this.legs.length-1;e>=0;e--){const s=this.legs[e];"arrivalTime"in s&&!r?(t=s.arrivalTime,r=!0):"minTransferTime"in s&&s.minTransferTime&&r&&n.add(s.minTransferTime)}if(!r)throw new Error("No vehicle leg found in route");return t.plus(n)}totalDuration(){return 0===this.legs.length?e.zero():this.arrivalTime().diff(this.departureTime())}print(){return this.legs.map(((t,e)=>{var n,r;return"route"in t?`Leg ${e+1}: ${t.from.name} to ${t.to.name}\n via route ${t.route.type} ${t.route.name},\n departs at ${t.departureTime.toString()}, arrives at ${t.arrivalTime.toString()}`:`Leg ${e+1}: Transfer from ${t.from.name} to ${t.to.name},\n minimum transfer time: ${null!==(r=null===(n=t.minTransferTime)||void 0===n?void 0:n.toString())&&void 0!==r?r:"not specified"}`})).join("\n")}}class lt{constructor(t,e,n,r){this.query=t,this.earliestArrivals=e,this.earliestArrivalsPerRound=n,this.stopsIndex=r}bestRoute(t){var e,n,r;const s=(Array.isArray(t)?t:t?[t]:this.query.to).flatMap((t=>this.stopsIndex.equivalentStops(t)));let o,i;for(const t of s){const e=this.earliestArrivals.get(t.id);void 0!==e&&(void 0===i||e.time.toMinutes()<i.time.toMinutes())&&(o=t.id,i=e)}if(!o||!i)return;const a=[];let u=o,c=i.legNumber;for(;i.origin!==u;){const t=null===(e=this.earliestArrivalsPerRound[c])||void 0===e?void 0:e.get(u);if(!(null==t?void 0:t.leg))throw new Error(`No leg found for a trip leg: start stop=${null!==(r=null===(n=null==t?void 0:t.leg)||void 0===n?void 0:n.from.id)&&void 0!==r?r:"unknown"}, end stop=${u}, round=${c}, origin=${i.origin}`);a.unshift(t.leg),u=t.leg.from.id,"route"in t.leg&&(c-=1)}return new ct(a)}arrivalAt(t,e){const n=this.stopsIndex.equivalentStops(t);let r;const s=void 0!==e?this.earliestArrivalsPerRound[e-1]:this.earliestArrivals;for(const t of n){const e=s.get(t.id);void 0!==e&&(void 0===r||e.time.toMinutes()<r.time.toMinutes())&&(r=e)}return r}}const dt=st.infinity();class ft{constructor(t,e){this.timetable=t,this.stopsIndex=e}considerTransfers(t,n,r,s,o){var i,a,u,c;const{options:l}=t,d=new Set;for(const t of n)for(const n of this.timetable.getTransfers(t)){let f;f=n.minTransferTime?n.minTransferTime:"IN_SEAT"===n.type?e.zero():l.minTransferTime;const h=r.get(t).time.plus(f),p=null!==(a=null===(i=r.get(n.destination))||void 0===i?void 0:i.time)&&void 0!==a?a:dt;if(h.toMinutes()<p.toMinutes()){const e=null!==(c=null===(u=r.get(t))||void 0===u?void 0:u.origin)&&void 0!==c?c:t;r.set(n.destination,{time:h,legNumber:o,origin:e,leg:{from:this.stopsIndex.findStopById(t),to:this.stopsIndex.findStopById(n.destination),minTransferTime:n.minTransferTime,type:n.type}}),s.set(n.destination,{time:h,legNumber:o,origin:e}),d.add(n.destination)}}for(const t of d)n.add(t)}route(t){var e,n,r,s,o,i,a;const{from:u,to:c,departureTime:l,options:d}=t,f=this.stopsIndex.equivalentStops(u),h=c.flatMap((t=>this.stopsIndex.equivalentStops(t))),p=new Map,m=new Map,g=[m],v=new Set;for(const t of f)v.add(t.id),p.set(t.id,{time:l,legNumber:0,origin:t.id}),m.set(t.id,{time:l,legNumber:0,origin:t.id});this.considerTransfers(t,v,m,p,0);for(let u=1;u<=d.maxTransfers+1;u++){const c=new Map;g.push(c);const l=g[u-1],f=this.timetable.findReachableRoutes(v,d.transportModes);v.clear();for(const[t,d]of f.entries()){const f=this.timetable.getRoute(t);let m;for(let t=f.stopIndices.get(d);t<f.stops.length;t++){const d=f.stops[t],g=f.stops.length;if(void 0!==m){const o=2*(m.trip*g+t),i=st.fromMinutes(f.stopTimes[o]),a=f.pickUpDropOffTypes[2*t+1],l=null!==(n=null===(e=p.get(d))||void 0===e?void 0:e.time)&&void 0!==n?n:dt;let y=l;if(h.length>0){const t=[];for(const e of h){const n=null!==(s=null===(r=p.get(e.id))||void 0===r?void 0:r.time)&&void 0!==s?s:dt;t.push(n)}const e=st.min(...t);y=st.min(l,e)}if(1!==a&&i.toMinutes()<y.toMinutes()){const t=f.stopIndices.get(m.bestHopOnStop),e=m.trip*g*2+2*t+1,n=st.fromMinutes(f.stopTimes[e]);c.set(d,{time:i,legNumber:u,origin:m.origin,leg:{from:this.stopsIndex.findStopById(m.bestHopOnStop),to:this.stopsIndex.findStopById(d),departureTime:n,arrivalTime:i,route:this.timetable.getServiceRoute(f.serviceRouteId)}}),p.set(d,{time:i,legNumber:u,origin:m.origin}),v.add(d)}}const y=null===(o=l.get(d))||void 0===o?void 0:o.time;if(void 0!==y&&(void 0===m||y.toMinutes()<=f.stopTimes[2*(m.trip*g+t)])){const t=this.timetable.findEarliestTrip(f,d,null==m?void 0:m.trip,y);void 0!==t&&(m={trip:t,bestHopOnStop:d,origin:null!==(a=null===(i=l.get(d))||void 0===i?void 0:i.origin)&&void 0!==a?a:d})}}}if(this.considerTransfers(t,v,c,p,u),0===v.size)break}return new lt(t,p,g,this.stopsIndex)}}class ht{constructor(t=[],e=pt){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:n}=this,r=e[t];for(;t>0;){const s=t-1>>1,o=e[s];if(n(r,o)>=0)break;e[t]=o,t=s}e[t]=r}_down(t){const{data:e,compare:n}=this,r=this.length>>1,s=e[t];for(;t<r;){let r=1+(t<<1),o=e[r];const i=r+1;if(i<this.length&&n(e[i],o)<0&&(r=i,o=e[i]),n(o,s)>=0)break;e[t]=o,t=r}e[t]=s}}function pt(t,e){return t<e?-1:t>e?1:0}const mt=Math.PI/180;function gt(t,e,n,r){const s=r.minLng,o=r.maxLng,i=r.minLat,a=r.maxLat;if(t>=s&&t<=o)return e<i?yt((e-i)*mt):e>a?yt((e-a)*mt):0;const u=Math.min(yt((t-s)*mt),yt((t-o)*mt)),c=function(t,e){const n=1-2*e;return n<=0?t>0?90:-90:Math.atan(Math.tan(t*mt)/n)/mt}(e,u);return c>i&&c<a?Tt(u,n,e,c):Math.min(Tt(u,n,e,i),Tt(u,n,e,a))}function vt(t,e){return t.dist-e.dist}function yt(t){const e=Math.sin(t/2);return e*e}function Tt(t,e,n,r){return e*Math.cos(r*mt)*t+yt((n-r)*mt)}function Et(t,e,n,r,s){return Tt(yt((t-n)*mt),s,e,r)}const It=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class At{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,n]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const r=n>>4;if(1!==r)throw new Error(`Got v${r} data when expected v1.`);const s=It[15&n];if(!s)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[i]=new Uint32Array(t,4,1);return new At(i,o,s,t)}constructor(t,e=64,n=Float64Array,r){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=n,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const s=It.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,i=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-i%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${n}.`);r&&r instanceof ArrayBuffer?(this.data=r,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+i+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+i+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+i+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const n=this._pos>>1;return this.ids[n]=n,this.coords[this._pos++]=t,this.coords[this._pos++]=e,n}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return wt(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,n,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:o,nodeSize:i}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,l=a.pop()||0,d=a.pop()||0;if(l-d<=i){for(let i=d;i<=l;i++){const a=o[2*i],c=o[2*i+1];a>=t&&a<=n&&c>=e&&c<=r&&u.push(s[i])}continue}const f=d+l>>1,h=o[2*f],p=o[2*f+1];h>=t&&h<=n&&p>=e&&p<=r&&u.push(s[f]),(0===c?t<=h:e<=p)&&(a.push(d),a.push(f-1),a.push(1-c)),(0===c?n>=h:r>=p)&&(a.push(f+1),a.push(l),a.push(1-c))}return u}within(t,e,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:r,coords:s,nodeSize:o}=this,i=[0,r.length-1,0],a=[],u=n*n;for(;i.length;){const c=i.pop()||0,l=i.pop()||0,d=i.pop()||0;if(l-d<=o){for(let n=d;n<=l;n++)_t(s[2*n],s[2*n+1],t,e)<=u&&a.push(r[n]);continue}const f=d+l>>1,h=s[2*f],p=s[2*f+1];_t(h,p,t,e)<=u&&a.push(r[f]),(0===c?t-n<=h:e-n<=p)&&(i.push(d),i.push(f-1),i.push(1-c)),(0===c?t+n>=h:e+n>=p)&&(i.push(f+1),i.push(l),i.push(1-c))}return a}}function wt(t,e,n,r,s,o){if(s-r<=n)return;const i=r+s>>1;St(t,e,i,r,s,o),wt(t,e,n,r,i-1,1-o),wt(t,e,n,i+1,s,1-o)}function St(t,e,n,r,s,o){for(;s>r;){if(s-r>600){const i=s-r+1,a=n-r+1,u=Math.log(i),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(i-c)/i)*(a-i/2<0?-1:1);St(t,e,n,Math.max(r,Math.floor(n-a*c/i+l)),Math.min(s,Math.floor(n+(i-a)*c/i+l)),o)}const i=e[2*n+o];let a=r,u=s;for(bt(t,e,r,n),e[2*s+o]>i&&bt(t,e,r,s);a<u;){for(bt(t,e,a,u),a++,u--;e[2*a+o]<i;)a++;for(;e[2*u+o]>i;)u--}e[2*r+o]===i?bt(t,e,r,u):(u++,bt(t,e,u,s)),u<=n&&(r=u+1),n<=u&&(s=u-1)}}function bt(t,e,n,r){Rt(t,n,r),Rt(e,2*n,2*r),Rt(e,2*n+1,2*r+1)}function Rt(t,e,n){const r=t[e];t[e]=t[n],t[n]=r}function _t(t,e,n,r){const s=t-n,o=e-r;return s*s+o*o}const Nt="KEYS",Ot="VALUES",Mt="";class kt{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}=Lt(this._path);if(Lt(e)===Mt)return{done:!1,value:this.result()};const n=t.get(Lt(e));return this._path.push({node:n,keys:Array.from(n.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=Lt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>Lt(t))).filter((t=>t!==Mt)).join("")}value(){return Lt(this._path).node.get(Mt)}result(){switch(this._type){case Ot:return this.value();case Nt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const Lt=t=>t[t.length-1],Ut=(t,e,n,r,s,o,i,a)=>{const u=o*i;t:for(const c of t.keys())if(c===Mt){const e=s[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=i*u,a=o-i;let l=s[o];const d=Math.max(0,u-n-1),f=Math.min(i-1,u+n);for(let t=d;t<f;++t){const n=r!==e[t],i=s[a+t]+ +n,u=s[a+t+1]+1,c=s[o+t]+1,d=s[o+t+1]=Math.min(i,u,c);d<l&&(l=d)}if(l>n)continue t}Ut(t.get(c),e,n,r,s,u,i,a+c)}};class xt{_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]=Dt(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,r]=zt(n);for(const n of e.keys())if(n!==Mt&&n.startsWith(r)){const s=new Map;return s.set(n.slice(r.length),e.get(n)),new xt(s,t)}}return new xt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,jt(this._tree,t)}entries(){return new kt(this,"ENTRIES")}forEach(t){for(const[e,n]of this)t(e,n,this)}fuzzyGet(t,e){return((t,e,n)=>{const r=new Map;if("string"!=typeof e)return r;const s=e.length+1,o=s+n,i=new Uint8Array(o*s).fill(n+1);for(let t=0;t<s;++t)i[t]=t;for(let t=1;t<o;++t)i[t*s]=t;return Ut(t,e,n,r,i,1,s,""),r})(this._tree,t,e)}get(t){const e=Bt(this._tree,t);return void 0!==e?e.get(Mt):void 0}has(t){return Bt(this._tree,t)?.has(Mt)??!1}keys(){return new kt(this,Nt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,Ft(this._tree,t).set(Mt,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=Ft(this._tree,t);return n.set(Mt,e(n.get(Mt))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const n=Ft(this._tree,t);let r=n.get(Mt);return void 0===r&&n.set(Mt,r=e()),r}values(){return new kt(this,Ot)}[Symbol.iterator](){return this.entries()}static from(t){const e=new xt;for(const[n,r]of t)e.set(n,r);return e}static fromObject(t){return xt.from(Object.entries(t))}}const Dt=(t,e,n=[])=>{if(0===e.length||null==t)return[t,n];for(const r of t.keys())if(r!==Mt&&e.startsWith(r))return n.push([t,r]),Dt(t.get(r),e.slice(r.length),n);return n.push([t,e]),Dt(void 0,"",n)},Bt=(t,e)=>{if(0===e.length||!t)return t;for(const n of t.keys())if(n!==Mt&&e.startsWith(n))return Bt(t.get(n),e.slice(n.length))},Ft=(t,e)=>{const n=e.length;t:for(let r=0;t&&r<n;){for(const s of t.keys())if(s!==Mt&&e[r]===s[0]){const o=Math.min(n-r,s.length);let i=1;for(;i<o&&e[r+i]===s[i];)++i;const a=t.get(s);if(i===s.length)t=a;else{const n=new Map;n.set(s.slice(i),a),t.set(e.slice(r,r+i),n),t.delete(s),t=n}r+=i;continue t}const s=new Map;return t.set(e.slice(r),s),s}return t},jt=(t,e)=>{const[n,r]=Dt(t,e);if(void 0!==n)if(n.delete(Mt),0===n.size)Ct(r);else if(1===n.size){const[t,e]=n.entries().next().value;Pt(r,t,e)}},Ct=t=>{if(0===t.length)return;const[e,n]=zt(t);if(e.delete(n),0===e.size)Ct(t.slice(0,-1));else if(1===e.size){const[n,r]=e.entries().next().value;n!==Mt&&Pt(t.slice(0,-1),n,r)}},Pt=(t,e,n)=>{if(0===t.length)return;const[r,s]=zt(t);r.set(s+e,n),r.delete(s)},zt=t=>t[t.length-1],$t=/[\n\r\p{Z}\p{P}]+/u,Jt="or",Gt="and",Vt="and_not",Yt=(t,e)=>{t.includes(e)||t.push(e)},Wt=(t,e)=>{for(const n of e)t.includes(n)||t.push(n)},Zt=({score:t},{score:e})=>e-t,qt=()=>new Map,Ht=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Xt={[Jt]:(t,e)=>{for(const n of e.keys()){const r=t.get(n);if(null==r)t.set(n,e.get(n));else{const{score:t,terms:s,match:o}=e.get(n);r.score=r.score+t,r.match=Object.assign(r.match,o),Wt(r.terms,s)}}return t},[Gt]:(t,e)=>{const n=new Map;for(const r of e.keys()){const s=t.get(r);if(null==s)continue;const{score:o,terms:i,match:a}=e.get(r);Wt(s.terms,i),n.set(r,{score:s.score+o,terms:s.terms,match:Object.assign(s.match,a)})}return n},[Vt]:(t,e)=>{for(const n of e.keys())t.delete(n);return t}},Qt=(t,e,n,r,s,o)=>{const{k:i,b:a,d:u}=o;return Math.log(1+(n-e+.5)/(e+.5))*(u+t*(i+1)/(t+i*(1-a+a*r/s)))},Kt=(t,e,n,r)=>{for(const s of Object.keys(t._fieldIds))if(t._fieldIds[s]===n)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${r}" was not present in field "${s}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},te=(t,e,n,r)=>{const s=t._index.fetch(r,qt);let o=s.get(e);if(null==o)o=new Map,o.set(n,1),s.set(e,o);else{const t=o.get(n);o.set(n,(t??0)+1)}},ee=(t,e,n,r)=>{if(!t._index.has(r))return void Kt(t,n,e,r);const s=t._index.fetch(r,qt),o=s.get(e),i=o?.get(n);!o||typeof i>"u"?Kt(t,n,e,r):i<=1?o.size<=1?s.delete(e):o.delete(n):o.set(n,i-1),0===t._index.get(r).size&&t._index.delete(r)},ne=(t,e,n,r,s)=>{let o=t._fieldLength.get(e);null==o&&t._fieldLength.set(e,o=[]),o[n]=s;const i=(t._avgFieldLength[n]||0)*r+s;t._avgFieldLength[n]=i/(r+1)},re=(t,e)=>{const{extractField:n,tokenize:r,processTerm:s,fields:o,idField:i}=t._options,a=n(e,i);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${i}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const u=((t,e)=>{const n=t._nextId;return t._idToShortId.set(e,n),t._documentIds.set(n,e),t._documentCount+=1,t._nextId+=1,n})(t,a);((t,e,n)=>{const{storeFields:r,extractField:s}=t._options;if(0===r?.length)return;let o=t._storedFields.get(e);void 0===o&&t._storedFields.set(e,o={});for(const t of r){const e=s(n,t);null!=e&&(o[t]=e)}})(t,u,e);for(const i of o){const o=n(e,i);if(null==o)continue;const a=r(o.toString(),i),c=t._fieldIds[i],l=new Set(a).size;ne(t,u,c,t._documentCount-1,l);for(const e of a){const n=s(e,i);if(Array.isArray(n))for(const e of n)te(t,c,u,e);else n&&te(t,c,u,n)}}},se={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split($t),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},oe={combineWith:Jt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},ie={combineWith:"and",prefix:(t,e,n)=>e===n.length-1},ae={minDirtFactor:.1,minDirtCount:20},ue={batchSize:1e3,batchWait:10,...ae},ce=Symbol("*"),le=(t,e=Jt)=>{if(0===t.length)return new Map;const n=e.toLowerCase();if(!(n in Xt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Xt[n])},de=(t,e,n,r,s,o,i,a,u,c=new Map)=>{if(null==o)return c;for(const l of Object.keys(i)){const d=i[l],f=t._fieldIds[l],h=o.get(f);if(null==h)continue;let p=h.size;const m=t._avgFieldLength[f];for(const o of h.keys()){if(!t._documentIds.has(o)){ee(t,f,o,n),p-=1;continue}const i=a?a(t._documentIds.get(o),n,t._storedFields.get(o)):1;if(!i)continue;const g=h.get(o),v=t._fieldLength.get(o)[f],y=r*s*d*i*Qt(g,p,t._documentCount,v,m,u),T=c.get(o);if(T){T.score+=y,Yt(T.terms,e);const t=Ht(T.match,n);t?t.push(l):T.match[n]=[l]}else c.set(o,{score:y,terms:[e],match:{[n]:[l]}})}}return c},fe=(t,e,n={})=>{if(e===ce)return((t,e)=>{const n=new Map,r={...t._options.searchOptions,...e};for(const[e,s]of t._documentIds){const o=r.boostDocument?r.boostDocument(s,"",t._storedFields.get(e)):1;n.set(e,{score:o,terms:[],match:{}})}return n})(t,n);if("string"!=typeof e){const r={...n,...e,queries:void 0},s=e.queries.map((e=>fe(t,e,r)));return le(s,r.combineWith)}const{tokenize:r,processTerm:s,searchOptions:o}=t._options,i={tokenize:r,processTerm:s,...o,...n},{tokenize:a,processTerm:u}=i,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}))(i)).map((e=>((t,e,n)=>{const r={...t._options.searchOptions,...n},s=(r.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:Ht(r.boost,e)||1})),{}),{boostDocument:o,weights:i,maxFuzzy:a,bm25:u}=r,{fuzzy:c,prefix:l}={...oe.weights,...i},d=t._index.get(e.term),f=de(t,e.term,e.term,1,e.termBoost,d,s,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 i=n.length-e.term.length;if(!i)continue;p?.delete(n);const a=l*n.length/(n.length+.3*i);de(t,e.term,n,a,e.termBoost,r,s,o,u,f)}if(p)for(const n of p.keys()){const[r,i]=p.get(n);if(!i)continue;const a=c*n.length/(n.length+i);de(t,e.term,n,a,e.termBoost,r,s,o,u,f)}return f})(t,e,i)));return le(c,i.combineWith)};class he{_options;_index;_documentCount;_documentIds;_idToShortId;_fieldIds;_fieldLength;_avgFieldLength;_nextId;_storedFields;_dirtCount;_currentVacuum;_enqueuedVacuum;_enqueuedVacuumConditions;constructor(t){if(!t?.fields)throw new Error('SlimSearch: option "fields" must be provided');const e=null==t.autoVacuum||!0===t.autoVacuum?ue:t.autoVacuum;this._options={...se,...t,autoVacuum:e,searchOptions:{...oe,...t.searchOptions},autoSuggestOptions:{...ie,...t.autoSuggestOptions}},this._index=new xt,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=ae,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 pe=t=>{const e=t.toLowerCase(),n=new Set([e]),r={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,s]of Object.entries(r))e.includes(t)&&s.forEach((r=>{n.add(e.replace(t,r))})),s.forEach((r=>{e.includes(r)&&n.add(e.replace(r,t))}));return Array.from(n)};var me;function ge(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return me.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return me.STATION;case 2:case"ENTRANCE_EXIT":return me.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return me.GENERIC_NODE;case 4:case"BOARDING_AREA":return me.BOARDING_AREA;default:return me.UNRECOGNIZED}}!function(t){t[t.SIMPLE_STOP_OR_PLATFORM=0]="SIMPLE_STOP_OR_PLATFORM",t[t.STATION=1]="STATION",t[t.ENTRANCE_EXIT=2]="ENTRANCE_EXIT",t[t.GENERIC_NODE=3]="GENERIC_NODE",t[t.BOARDING_AREA=4]="BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(me||(me={}));const ve={encode(t,e=new I){""!==t.name&&e.uint32(10).string(t.name),""!==t.sourceStopId&&e.uint32(18).string(t.sourceStopId),void 0!==t.lat&&e.uint32(25).double(t.lat),void 0!==t.lon&&e.uint32(33).double(t.lon),e.uint32(42).fork();for(const n of t.children)e.uint32(n);return e.join(),void 0!==t.parent&&e.uint32(48).uint32(t.parent),0!==t.locationType&&e.uint32(56).int32(t.locationType),void 0!==t.platform&&e.uint32(66).string(t.platform),e},decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={name:"",sourceStopId:"",lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.name=n.string();continue;case 2:if(18!==t)break;s.sourceStopId=n.string();continue;case 3:if(25!==t)break;s.lat=n.double();continue;case 4:if(33!==t)break;s.lon=n.double();continue;case 5:if(40===t){s.children.push(n.uint32());continue}if(42===t){const t=n.uint32()+n.pos;for(;n.pos<t;)s.children.push(n.uint32());continue}break;case 6:if(48!==t)break;s.parent=n.uint32();continue;case 7:if(56!==t)break;s.locationType=n.int32();continue;case 8:if(66!==t)break;s.platform=n.string();continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({name:Ee(t.name)?globalThis.String(t.name):"",sourceStopId:Ee(t.sourceStopId)?globalThis.String(t.sourceStopId):"",lat:Ee(t.lat)?globalThis.Number(t.lat):void 0,lon:Ee(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:Ee(t.parent)?globalThis.Number(t.parent):void 0,locationType:Ee(t.locationType)?ge(t.locationType):0,platform:Ee(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const n={};return""!==t.name&&(n.name=t.name),""!==t.sourceStopId&&(n.sourceStopId=t.sourceStopId),void 0!==t.lat&&(n.lat=t.lat),void 0!==t.lon&&(n.lon=t.lon),(null===(e=t.children)||void 0===e?void 0:e.length)&&(n.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(n.parent=Math.round(t.parent)),0!==t.locationType&&(n.locationType=function(t){switch(t){case me.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case me.STATION:return"STATION";case me.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case me.GENERIC_NODE:return"GENERIC_NODE";case me.BOARDING_AREA:return"BOARDING_AREA";case me.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(n.platform=t.platform),n},create:t=>ve.fromPartial(null!=t?t:{}),fromPartial(t){var e,n,r,s,o,i,a,u;const c={name:"",sourceStopId:"",lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};return c.name=null!==(e=t.name)&&void 0!==e?e:"",c.sourceStopId=null!==(n=t.sourceStopId)&&void 0!==n?n:"",c.lat=null!==(r=t.lat)&&void 0!==r?r:void 0,c.lon=null!==(s=t.lon)&&void 0!==s?s:void 0,c.children=(null===(o=t.children)||void 0===o?void 0:o.map((t=>t)))||[],c.parent=null!==(i=t.parent)&&void 0!==i?i:void 0,c.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,c.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,c}};const ye={encode:(t,e=new I)=>(""!==t.version&&e.uint32(10).string(t.version),Object.entries(t.stops).forEach((([t,n])=>{Te.encode({key:t,value:n},e.uint32(18).fork()).join()})),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={version:"",stops:{}};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=n.string();continue;case 2:{if(18!==t)break;const e=Te.decode(n,n.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON(t){return{version:Ee(t.version)?globalThis.String(t.version):"",stops:(e=t.stops,"object"==typeof e&&null!==e?Object.entries(t.stops).reduce(((t,[e,n])=>(t[globalThis.Number(e)]=ve.fromJSON(n),t)),{}):{})};var e},toJSON(t){const e={};if(""!==t.version&&(e.version=t.version),t.stops){const n=Object.entries(t.stops);n.length>0&&(e.stops={},n.forEach((([t,n])=>{e.stops[t]=ve.toJSON(n)})))}return e},create:t=>ye.fromPartial(null!=t?t:{}),fromPartial(t){var e,n;const r={version:"",stops:{}};return r.version=null!==(e=t.version)&&void 0!==e?e:"",r.stops=Object.entries(null!==(n=t.stops)&&void 0!==n?n:{}).reduce(((t,[e,n])=>(void 0!==n&&(t[globalThis.Number(e)]=ve.fromPartial(n)),t)),{}),r}};const Te={encode:(t,e=new I)=>(0!==t.key&&e.uint32(8).uint32(t.key),void 0!==t.value&&ve.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const n=t instanceof A?t:new A(t);let r=void 0===e?n.len:n.pos+e;const s={key:0,value:void 0};for(;n.pos<r;){const t=n.uint32();switch(t>>>3){case 1:if(8!==t)break;s.key=n.uint32();continue;case 2:if(18!==t)break;s.value=ve.decode(n,n.uint32());continue}if(4==(7&t)||0===t)break;n.skip(7&t)}return s},fromJSON:t=>({key:Ee(t.key)?globalThis.Number(t.key):0,value:Ee(t.value)?ve.fromJSON(t.value):void 0}),toJSON(t){const e={};return 0!==t.key&&(e.key=Math.round(t.key)),void 0!==t.value&&(e.value=ve.toJSON(t.value)),e},create:t=>Te.fromPartial(null!=t?t:{}),fromPartial(t){var e;const n={key:0,value:void 0};return n.key=null!==(e=t.key)&&void 0!==e?e:0,n.value=void 0!==t.value&&null!==t.value?ve.fromPartial(t.value):void 0,n}};function Ee(t){return null!=t}const Ie="0.0.2",Ae=t=>{const e={version:Ie,stops:{}};return t.forEach(((t,n)=>{var r;e.stops[n]={name:(r=t).name,sourceStopId:r.sourceStopId,lat:r.lat,lon:r.lon,children:r.children,parent:r.parent,locationType:be(r.locationType),platform:r.platform}})),e},we=t=>{if(t.version!==Ie)throw new Error(`Unsupported stopMap version ${t.version}`);const e=new Map;return Object.entries(t.stops).forEach((([t,n])=>{const r=parseInt(t,10);var s;e.set(r,{id:r,sourceStopId:(s=n).sourceStopId,name:s.name,lat:s.lat,lon:s.lon,children:s.children,parent:s.parent,locationType:Se(s.locationType),platform:s.platform})})),e},Se=t=>{switch(t){case me.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case me.STATION:return"STATION";case me.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case me.GENERIC_NODE:return"GENERIC_NODE";case me.BOARDING_AREA:return"BOARDING_AREA";case me.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},be=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return me.SIMPLE_STOP_OR_PLATFORM;case"STATION":return me.STATION;case"ENTRANCE_EXIT":return me.ENTRANCE_EXIT;case"GENERIC_NODE":return me.GENERIC_NODE;case"BOARDING_AREA":return me.BOARDING_AREA}};class Re{constructor(t){var e;this.stopsMap=t,this.sourceStopsMap=new Map;for(const[e,n]of t.entries())this.sourceStopsMap.set(n.sourceStopId,e);this.textIndex=new he({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:pe});const n=new Map;for(const[r,s]of t.entries()){const t=null!==(e=s.parent)&&void 0!==e?e:r;n.has(t)||n.set(t,{id:t,name:s.parent?this.stopsMap.get(s.parent).name:s.name})}const r=Array.from(n.values());((t,e)=>{for(const n of e)re(t,n)})(this.textIndex,r),this.stopPoints=Array.from(this.stopsMap.entries()).filter((([,t])=>!(!t.lat||!t.lon))).map((([t,e])=>({id:t,lat:e.lat,lon:e.lon}))),this.geoIndex=new At(this.stopPoints.length);for(const{lat:t,lon:e}of this.stopPoints)this.geoIndex.add(e,t);this.geoIndex.finish()}static fromData(t){const e=new A(t),n=ye.decode(e);return new Re(we(n))}serialize(){const t=Ae(this.stopsMap),e=new I;return ye.encode(t,e),e.finish()}size(){return this.stopsMap.size}findStopsByName(t,e=5){return((t,e,n={})=>{const{searchOptions:r}=t._options,s={...r,...n},o=fe(t,e,n),i=[];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==s.filter||s.filter(u))&&i.push(u)}return e===ce&&null==s.boostDocument||i.sort(Zt),i})(this.textIndex,t).map((t=>this.stopsMap.get(t.id))).slice(0,e)}findStopsByLocation(t,e,n=5,r=.5){const s=function(t,e,n,r=1/0,s=1/0){let o=1;const i=[];void 0===r&&(r=1/0),void 0!==s&&(o=yt(s/6371));const a=new ht([],vt);let u={left:0,right:t.ids.length-1,axis:0,dist:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(n*mt);for(;u;){const s=u.right,l=u.left;if(s-l<=t.nodeSize)for(let r=l;r<=s;r++){const s=t.ids[r];{const o=Et(e,n,t.coords[2*r],t.coords[2*r+1],c);a.push({id:s,dist:o})}}else{const r=l+s>>1,o=t.coords[2*r],i=t.coords[2*r+1],d=t.ids[r];{const t=Et(e,n,o,i,c);a.push({id:d,dist:t})}const f=(u.axis+1)%2,h={left:l,right:r-1,axis:f,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?o:u.maxLng,maxLat:1===u.axis?i:u.maxLat,dist:0},p={left:r+1,right:s,axis:f,minLng:0===u.axis?o:u.minLng,minLat:1===u.axis?i:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};h.dist=gt(e,n,c,h),p.dist=gt(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 i;if(i.push(t.id),i.length===r)return i}u=a.pop()}return i}(this.geoIndex,e,t,n,r).map((t=>{const e=this.stopPoints[t];return this.stopsMap.get(e.id)}));return s}findStopById(t){return this.stopsMap.get(t)}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,n;const r=this.sourceStopsMap.get(t);if(void 0===r)return[];const s=this.stopsMap.get(r);if(!s)return[];const o=s.parent?null!==(n=null===(e=this.stopsMap.get(s.parent))||void 0===e?void 0:e.children)&&void 0!==n?n:[]:s.children;return Array.from(new Set([r,...o])).map((t=>this.stopsMap.get(t)))}}export{e as Duration,t as Plotter,ut as Query,lt as Result,ct as Route,ft as Router,Re as StopsIndex,st as Time,at as Timetable};
|
|
1
|
+
class t{constructor(t){this.result=t}plotDotGraph(){const t=this.result.earliestArrivalsPerRound,e=["digraph PathTree {"," graph [overlap=false];"," node [shape=ellipse style=filled fillcolor=lightgrey];"];return t.forEach(((t,r)=>{t.forEach((t=>{const{origin:n,leg:s}=t;if(!s)return;const o=this.result.stopsIndex.findStopById(s.from.id),i=this.result.stopsIndex.findStopById(s.to.id),a=this.result.stopsIndex.findStopById(n);if(o&&i&&a){const t=o.platform?`${o.name} (Pl. ${o.platform})`:o.name,n=i.platform?`${i.name} (Pl. ${i.platform})`:i.name,u=a.platform?`${a.name} (Pl. ${a.platform})`:a.name,c="route"in s,l=c?`${s.route.name}\n${s.departureTime.toString()} - ${s.arrivalTime.toString()}`:s.minTransferTime?s.minTransferTime.toString():"",f=`IntermediateNode${o.id}_${i.id}`,d=c?"":', color="red", fontcolor="red"',h=c?"":' fontcolor="red"';e.push(` "${t} (Origin: ${u}) [R${r}]\n(${o.id})" -> "${f}" [shape=point${d}];`),e.push(` "${f}" [label="${l}" shape=rect style=filled fillcolor=white${h} border=0];`),e.push(` "${f}" -> "${n} (Origin: ${u}) [R${r}]\n(${i.id})" [${d.replace(", ","")}];`)}}))})),e.push("}"),e.join("\n")}}class e{constructor(t){this.totalSeconds=t}static fromSeconds(t){return new e(t)}static fromMinutes(t){return new e(60*t)}static zero(){return new e(0)}toString(){const t=Math.floor(this.totalSeconds/3600),e=Math.floor(this.totalSeconds%3600/60),r=this.totalSeconds%60;return t>0?`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`:`${e.toString().padStart(2,"0")}:${r.toString().padStart(2,"0")}`}toSeconds(){return this.totalSeconds}add(t){const r=this.totalSeconds+t.toSeconds();return new e(r)}subtract(t){const r=Math.max(0,this.totalSeconds-t.toSeconds());return new e(r)}}function r(){let t=0,e=0;for(let r=0;r<28;r+=7){let n=this.buf[this.pos++];if(t|=(127&n)<<r,!(128&n))return this.assertBounds(),[t,e]}let r=this.buf[this.pos++];if(t|=(15&r)<<28,e=(112&r)>>4,!(128&r))return this.assertBounds(),[t,e];for(let r=3;r<=31;r+=7){let n=this.buf[this.pos++];if(e|=(127&n)<<r,!(128&n))return this.assertBounds(),[t,e]}throw new Error("invalid varint")}function n(t,e,r){for(let n=0;n<28;n+=7){const s=t>>>n,o=!(s>>>7==0&&0==e),i=255&(o?128|s:s);if(r.push(i),!o)return}const n=t>>>28&15|(7&e)<<4,s=!!(e>>3);if(r.push(255&(s?128|n:n)),s){for(let t=3;t<31;t+=7){const n=e>>>t,s=!(n>>>7==0),o=255&(s?128|n:n);if(r.push(o),!s)return}r.push(e>>>31&1)}}const s=4294967296;function o(t){const e="-"===t[0];e&&(t=t.slice(1));const r=1e6;let n=0,o=0;function i(e,i){const a=Number(t.slice(e,i));o*=r,n=n*r+a,n>=s&&(o+=n/s|0,n%=s)}return i(-24,-18),i(-18,-12),i(-12,-6),i(-6),e?u(n,o):a(n,o)}function i(t,e){if(({lo:t,hi:e}=function(t,e){return{lo:t>>>0,hi:e>>>0}}(t,e)),e<=2097151)return String(s*e+t);const r=16777215&(t>>>24|e<<8),n=e>>16&65535;let o=(16777215&t)+6777216*r+6710656*n,i=r+8147497*n,a=2*n;const u=1e7;return o>=u&&(i+=Math.floor(o/u),o%=u),i>=u&&(a+=Math.floor(i/u),i%=u),a.toString()+c(i)+c(o)}function a(t,e){return{lo:0|t,hi:0|e}}function u(t,e){return e=~e,t?t=1+~t:e+=1,a(t,e)}const c=t=>{const e=String(t);return"0000000".slice(e.length)+e};function l(t,e){if(t>=0){for(;t>127;)e.push(127&t|128),t>>>=7;e.push(t)}else{for(let r=0;r<9;r++)e.push(127&t|128),t>>=7;e.push(1)}}function f(){let t=this.buf[this.pos++],e=127&t;if(!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<7,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<14,!(128&t))return this.assertBounds(),e;if(t=this.buf[this.pos++],e|=(127&t)<<21,!(128&t))return this.assertBounds(),e;t=this.buf[this.pos++],e|=(15&t)<<28;for(let e=5;128&t&&e<10;e++)t=this.buf[this.pos++];if(128&t)throw new Error("invalid varint");return this.assertBounds(),e>>>0}const d=h();function h(){const t=new DataView(new ArrayBuffer(8));if("function"==typeof BigInt&&"function"==typeof t.getBigInt64&&"function"==typeof t.getBigUint64&&"function"==typeof t.setBigInt64&&"function"==typeof t.setBigUint64&&("object"!=typeof process||"object"!=typeof process.env||"1"!==process.env.BUF_BIGINT_DISABLE)){const e=BigInt("-9223372036854775808"),r=BigInt("9223372036854775807"),n=BigInt("0"),s=BigInt("18446744073709551615");return{zero:BigInt(0),supported:!0,parse(t){const n="bigint"==typeof t?t:BigInt(t);if(n>r||n<e)throw new Error(`invalid int64: ${t}`);return n},uParse(t){const e="bigint"==typeof t?t:BigInt(t);if(e>s||e<n)throw new Error(`invalid uint64: ${t}`);return e},enc(e){return t.setBigInt64(0,this.parse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},uEnc(e){return t.setBigInt64(0,this.uParse(e),!0),{lo:t.getInt32(0,!0),hi:t.getInt32(4,!0)}},dec:(e,r)=>(t.setInt32(0,e,!0),t.setInt32(4,r,!0),t.getBigInt64(0,!0)),uDec:(e,r)=>(t.setInt32(0,e,!0),t.setInt32(4,r,!0),t.getBigUint64(0,!0))}}return{zero:"0",supported:!1,parse:t=>("string"!=typeof t&&(t=t.toString()),p(t),t),uParse:t=>("string"!=typeof t&&(t=t.toString()),m(t),t),enc:t=>("string"!=typeof t&&(t=t.toString()),p(t),o(t)),uEnc:t=>("string"!=typeof t&&(t=t.toString()),m(t),o(t)),dec:(t,e)=>function(t,e){let r=a(t,e);const n=2147483648&r.hi;n&&(r=u(r.lo,r.hi));const s=i(r.lo,r.hi);return n?"-"+s:s}(t,e),uDec:(t,e)=>i(t,e)}}function p(t){if(!/^-?[0-9]+$/.test(t))throw new Error("invalid int64: "+t)}function m(t){if(!/^[0-9]+$/.test(t))throw new Error("invalid uint64: "+t)}const v=Symbol.for("@bufbuild/protobuf/text-encoding");function g(){if(null==globalThis[v]){const t=new globalThis.TextEncoder,e=new globalThis.TextDecoder;globalThis[v]={encodeUtf8:e=>t.encode(e),decodeUtf8:t=>e.decode(t),checkUtf8(t){try{return encodeURIComponent(t),!0}catch(t){return!1}}}}return globalThis[v]}var y;!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"}(y||(y={}));const T=34028234663852886e22,E=-34028234663852886e22;class I{constructor(t=g().encodeUtf8){this.encodeUtf8=t,this.stack=[],this.chunks=[],this.buf=[]}finish(){this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]);let t=0;for(let e=0;e<this.chunks.length;e++)t+=this.chunks[e].length;let e=new Uint8Array(t),r=0;for(let t=0;t<this.chunks.length;t++)e.set(this.chunks[t],r),r+=this.chunks[t].length;return this.chunks=[],e}fork(){return this.stack.push({chunks:this.chunks,buf:this.buf}),this.chunks=[],this.buf=[],this}join(){let t=this.finish(),e=this.stack.pop();if(!e)throw new Error("invalid state, fork stack empty");return this.chunks=e.chunks,this.buf=e.buf,this.uint32(t.byteLength),this.raw(t)}tag(t,e){return this.uint32((t<<3|e)>>>0)}raw(t){return this.buf.length&&(this.chunks.push(new Uint8Array(this.buf)),this.buf=[]),this.chunks.push(t),this}uint32(t){for(w(t);t>127;)this.buf.push(127&t|128),t>>>=7;return this.buf.push(t),this}int32(t){return S(t),l(t,this.buf),this}bool(t){return this.buf.push(t?1:0),this}bytes(t){return this.uint32(t.byteLength),this.raw(t)}string(t){let e=this.encodeUtf8(t);return this.uint32(e.byteLength),this.raw(e)}float(t){!function(t){if("string"==typeof t){const e=t;if(t=Number(t),Number.isNaN(t)&&"NaN"!==e)throw new Error("invalid float32: "+e)}else if("number"!=typeof t)throw new Error("invalid float32: "+typeof t);if(Number.isFinite(t)&&(t>T||t<E))throw new Error("invalid float32: "+t)}(t);let e=new Uint8Array(4);return new DataView(e.buffer).setFloat32(0,t,!0),this.raw(e)}double(t){let e=new Uint8Array(8);return new DataView(e.buffer).setFloat64(0,t,!0),this.raw(e)}fixed32(t){w(t);let e=new Uint8Array(4);return new DataView(e.buffer).setUint32(0,t,!0),this.raw(e)}sfixed32(t){S(t);let e=new Uint8Array(4);return new DataView(e.buffer).setInt32(0,t,!0),this.raw(e)}sint32(t){return S(t),l(t=(t<<1^t>>31)>>>0,this.buf),this}sfixed64(t){let e=new Uint8Array(8),r=new DataView(e.buffer),n=d.enc(t);return r.setInt32(0,n.lo,!0),r.setInt32(4,n.hi,!0),this.raw(e)}fixed64(t){let e=new Uint8Array(8),r=new DataView(e.buffer),n=d.uEnc(t);return r.setInt32(0,n.lo,!0),r.setInt32(4,n.hi,!0),this.raw(e)}int64(t){let e=d.enc(t);return n(e.lo,e.hi,this.buf),this}sint64(t){const e=d.enc(t),r=e.hi>>31;return n(e.lo<<1^r,(e.hi<<1|e.lo>>>31)^r,this.buf),this}uint64(t){const e=d.uEnc(t);return n(e.lo,e.hi,this.buf),this}}class A{constructor(t,e=g().decodeUtf8){this.decodeUtf8=e,this.varint64=r,this.uint32=f,this.buf=t,this.len=t.length,this.pos=0,this.view=new DataView(t.buffer,t.byteOffset,t.byteLength)}tag(){let t=this.uint32(),e=t>>>3,r=7&t;if(e<=0||r<0||r>5)throw new Error("illegal tag: field no "+e+" wire type "+r);return[e,r]}skip(t,e){let r=this.pos;switch(t){case y.Varint:for(;128&this.buf[this.pos++];);break;case y.Bit64:this.pos+=4;case y.Bit32:this.pos+=4;break;case y.LengthDelimited:let r=this.uint32();this.pos+=r;break;case y.StartGroup:for(;;){const[t,r]=this.tag();if(r===y.EndGroup){if(void 0!==e&&t!==e)throw new Error("invalid end group tag");break}this.skip(r,t)}break;default:throw new Error("cant skip wire type "+t)}return this.assertBounds(),this.buf.subarray(r,this.pos)}assertBounds(){if(this.pos>this.len)throw new RangeError("premature EOF")}int32(){return 0|this.uint32()}sint32(){let t=this.uint32();return t>>>1^-(1&t)}int64(){return d.dec(...this.varint64())}uint64(){return d.uDec(...this.varint64())}sint64(){let[t,e]=this.varint64(),r=-(1&t);return t=(t>>>1|(1&e)<<31)^r,e=e>>>1^r,d.dec(t,e)}bool(){let[t,e]=this.varint64();return 0!==t||0!==e}fixed32(){return this.view.getUint32((this.pos+=4)-4,!0)}sfixed32(){return this.view.getInt32((this.pos+=4)-4,!0)}fixed64(){return d.uDec(this.sfixed32(),this.sfixed32())}sfixed64(){return d.dec(this.sfixed32(),this.sfixed32())}float(){return this.view.getFloat32((this.pos+=4)-4,!0)}double(){return this.view.getFloat64((this.pos+=8)-8,!0)}bytes(){let t=this.uint32(),e=this.pos;return this.pos+=t,this.assertBounds(),this.buf.subarray(e,e+t)}string(){return this.decodeUtf8(this.bytes())}}function S(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 b,R;function _(t){switch(t){case 0:case"RECOMMENDED_TRANSFER_POINT":return b.RECOMMENDED_TRANSFER_POINT;case 1:case"TIMED_TRANSFER":return b.TIMED_TRANSFER;case 2:case"REQUIRES_MINIMAL_TIME":return b.REQUIRES_MINIMAL_TIME;case 3:case"IN_SEAT_TRANSFER":return b.IN_SEAT_TRANSFER;default:return b.UNRECOGNIZED}}function N(t){switch(t){case 0:case"TRAM":return R.TRAM;case 1:case"SUBWAY":return R.SUBWAY;case 2:case"RAIL":return R.RAIL;case 3:case"BUS":return R.BUS;case 4:case"FERRY":return R.FERRY;case 5:case"CABLE_TRAM":return R.CABLE_TRAM;case 6:case"AERIAL_LIFT":return R.AERIAL_LIFT;case 7:case"FUNICULAR":return R.FUNICULAR;case 8:case"TROLLEYBUS":return R.TROLLEYBUS;case 9:case"MONORAIL":return R.MONORAIL;default:return R.UNRECOGNIZED}}function O(){return{stopTimes:new Uint8Array(0),pickUpDropOffTypes:new Uint8Array(0),stops:new Uint8Array(0),serviceRouteId:""}}!function(t){t[t.RECOMMENDED_TRANSFER_POINT=0]="RECOMMENDED_TRANSFER_POINT",t[t.TIMED_TRANSFER=1]="TIMED_TRANSFER",t[t.REQUIRES_MINIMAL_TIME=2]="REQUIRES_MINIMAL_TIME",t[t.IN_SEAT_TRANSFER=3]="IN_SEAT_TRANSFER",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(b||(b={})),function(t){t[t.TRAM=0]="TRAM",t[t.SUBWAY=1]="SUBWAY",t[t.RAIL=2]="RAIL",t[t.BUS=3]="BUS",t[t.FERRY=4]="FERRY",t[t.CABLE_TRAM=5]="CABLE_TRAM",t[t.AERIAL_LIFT=6]="AERIAL_LIFT",t[t.FUNICULAR=7]="FUNICULAR",t[t.TROLLEYBUS=8]="TROLLEYBUS",t[t.MONORAIL=9]="MONORAIL",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(R||(R={}));const k={encode:(t,e=new I)=>(0!==t.stopTimes.length&&e.uint32(10).bytes(t.stopTimes),0!==t.pickUpDropOffTypes.length&&e.uint32(18).bytes(t.pickUpDropOffTypes),0!==t.stops.length&&e.uint32(26).bytes(t.stops),""!==t.serviceRouteId&&e.uint32(34).string(t.serviceRouteId),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s=O();for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.stopTimes=r.bytes();continue;case 2:if(18!==t)break;s.pickUpDropOffTypes=r.bytes();continue;case 3:if(26!==t)break;s.stops=r.bytes();continue;case 4:if(34!==t)break;s.serviceRouteId=r.string();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stopTimes:J(t.stopTimes)?$(t.stopTimes):new Uint8Array(0),pickUpDropOffTypes:J(t.pickUpDropOffTypes)?$(t.pickUpDropOffTypes):new Uint8Array(0),stops:J(t.stops)?$(t.stops):new Uint8Array(0),serviceRouteId:J(t.serviceRouteId)?globalThis.String(t.serviceRouteId):""}),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)),""!==t.serviceRouteId&&(e.serviceRouteId=t.serviceRouteId),e},create:t=>k.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s;const o=O();return o.stopTimes=null!==(e=t.stopTimes)&&void 0!==e?e:new Uint8Array(0),o.pickUpDropOffTypes=null!==(r=t.pickUpDropOffTypes)&&void 0!==r?r:new Uint8Array(0),o.stops=null!==(n=t.stops)&&void 0!==n?n:new Uint8Array(0),o.serviceRouteId=null!==(s=t.serviceRouteId)&&void 0!==s?s:"",o}};const M={encode:(t,e=new I)=>(Object.entries(t.routes).forEach((([t,r])=>{L.encode({key:t,value:r},e.uint32(10).fork()).join()})),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={routes:{}};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=L.decode(r,r.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({routes:G(t.routes)?Object.entries(t.routes).reduce(((t,[e,r])=>(t[e]=k.fromJSON(r),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const r=Object.entries(t.routes);r.length>0&&(e.routes={},r.forEach((([t,r])=>{e.routes[t]=k.toJSON(r)})))}return e},create:t=>M.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={routes:{}};return r.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,r])=>(void 0!==r&&(t[e]=k.fromPartial(r)),t)),{}),r}};const L={encode:(t,e=new I)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&k.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={key:"",value:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=r.string();continue;case 2:if(18!==t)break;s.value=k.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({key:J(t.key)?globalThis.String(t.key):"",value:J(t.value)?k.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=k.toJSON(t.value)),e},create:t=>L.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={key:"",value:void 0};return r.key=null!==(e=t.key)&&void 0!==e?e:"",r.value=void 0!==t.value&&null!==t.value?k.fromPartial(t.value):void 0,r}};const U={encode:(t,e=new I)=>(0!==t.destination&&e.uint32(8).uint32(t.destination),0!==t.type&&e.uint32(16).int32(t.type),void 0!==t.minTransferTime&&e.uint32(24).int32(t.minTransferTime),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={destination:0,type:0,minTransferTime:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.destination=r.uint32();continue;case 2:if(16!==t)break;s.type=r.int32();continue;case 3:if(24!==t)break;s.minTransferTime=r.int32();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({destination:J(t.destination)?globalThis.Number(t.destination):0,type:J(t.type)?_(t.type):0,minTransferTime:J(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 b.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED_TRANSFER_POINT";case b.TIMED_TRANSFER:return"TIMED_TRANSFER";case b.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case b.IN_SEAT_TRANSFER:return"IN_SEAT_TRANSFER";case b.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),void 0!==t.minTransferTime&&(e.minTransferTime=Math.round(t.minTransferTime)),e},create:t=>U.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n;const s={destination:0,type:0,minTransferTime:void 0};return s.destination=null!==(e=t.destination)&&void 0!==e?e:0,s.type=null!==(r=t.type)&&void 0!==r?r:0,s.minTransferTime=null!==(n=t.minTransferTime)&&void 0!==n?n:void 0,s}};const x={encode:(t,e=new I)=>(Object.entries(t.stops).forEach((([t,r])=>{D.encode({key:t,value:r},e.uint32(10).fork()).join()})),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={stops:{}};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=D.decode(r,r.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({stops:G(t.stops)?Object.entries(t.stops).reduce(((t,[e,r])=>(t[e]=B.fromJSON(r),t)),{}):{}}),toJSON(t){const e={};if(t.stops){const r=Object.entries(t.stops);r.length>0&&(e.stops={},r.forEach((([t,r])=>{e.stops[t]=B.toJSON(r)})))}return e},create:t=>x.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={stops:{}};return r.stops=Object.entries(null!==(e=t.stops)&&void 0!==e?e:{}).reduce(((t,[e,r])=>(void 0!==r&&(t[e]=B.fromPartial(r)),t)),{}),r}};const B={encode(t,e=new I){for(const r of t.transfers)U.encode(r,e.uint32(10).fork()).join();for(const r of t.routes)e.uint32(18).string(r);return e},decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={transfers:[],routes:[]};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.transfers.push(U.decode(r,r.uint32()));continue;case 2:if(18!==t)break;s.routes.push(r.string());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({transfers:globalThis.Array.isArray(null==t?void 0:t.transfers)?t.transfers.map((t=>U.fromJSON(t))):[],routes:globalThis.Array.isArray(null==t?void 0:t.routes)?t.routes.map((t=>globalThis.String(t))):[]}),toJSON(t){var e,r;const n={};return(null===(e=t.transfers)||void 0===e?void 0:e.length)&&(n.transfers=t.transfers.map((t=>U.toJSON(t)))),(null===(r=t.routes)||void 0===r?void 0:r.length)&&(n.routes=t.routes),n},create:t=>B.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={transfers:[],routes:[]};return n.transfers=(null===(e=t.transfers)||void 0===e?void 0:e.map((t=>U.fromPartial(t))))||[],n.routes=(null===(r=t.routes)||void 0===r?void 0:r.map((t=>t)))||[],n}};const D={encode:(t,e=new I)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&B.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={key:"",value:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=r.string();continue;case 2:if(18!==t)break;s.value=B.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({key:J(t.key)?globalThis.String(t.key):"",value:J(t.value)?B.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=B.toJSON(t.value)),e},create:t=>D.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={key:"",value:void 0};return r.key=null!==(e=t.key)&&void 0!==e?e:"",r.value=void 0!==t.value&&null!==t.value?B.fromPartial(t.value):void 0,r}};const F={encode:(t,e=new I)=>(0!==t.type&&e.uint32(8).int32(t.type),""!==t.name&&e.uint32(18).string(t.name),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={type:0,name:""};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.type=r.int32();continue;case 2:if(18!==t)break;s.name=r.string();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({type:J(t.type)?N(t.type):0,name:J(t.name)?globalThis.String(t.name):""}),toJSON(t){const e={};return 0!==t.type&&(e.type=function(t){switch(t){case R.TRAM:return"TRAM";case R.SUBWAY:return"SUBWAY";case R.RAIL:return"RAIL";case R.BUS:return"BUS";case R.FERRY:return"FERRY";case R.CABLE_TRAM:return"CABLE_TRAM";case R.AERIAL_LIFT:return"AERIAL_LIFT";case R.FUNICULAR:return"FUNICULAR";case R.TROLLEYBUS:return"TROLLEYBUS";case R.MONORAIL:return"MONORAIL";case R.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.type)),""!==t.name&&(e.name=t.name),e},create:t=>F.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={type:0,name:""};return n.type=null!==(e=t.type)&&void 0!==e?e:0,n.name=null!==(r=t.name)&&void 0!==r?r:"",n}};const P={encode:(t,e=new I)=>(Object.entries(t.routes).forEach((([t,r])=>{j.encode({key:t,value:r},e.uint32(10).fork()).join()})),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={routes:{}};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:{if(10!==t)break;const e=j.decode(r,r.uint32());void 0!==e.value&&(s.routes[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({routes:G(t.routes)?Object.entries(t.routes).reduce(((t,[e,r])=>(t[e]=F.fromJSON(r),t)),{}):{}}),toJSON(t){const e={};if(t.routes){const r=Object.entries(t.routes);r.length>0&&(e.routes={},r.forEach((([t,r])=>{e.routes[t]=F.toJSON(r)})))}return e},create:t=>P.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={routes:{}};return r.routes=Object.entries(null!==(e=t.routes)&&void 0!==e?e:{}).reduce(((t,[e,r])=>(void 0!==r&&(t[e]=F.fromPartial(r)),t)),{}),r}};const j={encode:(t,e=new I)=>(""!==t.key&&e.uint32(10).string(t.key),void 0!==t.value&&F.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={key:"",value:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.key=r.string();continue;case 2:if(18!==t)break;s.value=F.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({key:J(t.key)?globalThis.String(t.key):"",value:J(t.value)?F.fromJSON(t.value):void 0}),toJSON(t){const e={};return""!==t.key&&(e.key=t.key),void 0!==t.value&&(e.value=F.toJSON(t.value)),e},create:t=>j.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={key:"",value:void 0};return r.key=null!==(e=t.key)&&void 0!==e?e:"",r.value=void 0!==t.value&&null!==t.value?F.fromPartial(t.value):void 0,r}};const C={encode:(t,e=new I)=>(""!==t.version&&e.uint32(10).string(t.version),void 0!==t.stopsAdjacency&&x.encode(t.stopsAdjacency,e.uint32(18).fork()).join(),void 0!==t.routesAdjacency&&M.encode(t.routesAdjacency,e.uint32(26).fork()).join(),void 0!==t.routes&&P.encode(t.routes,e.uint32(34).fork()).join(),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=r.string();continue;case 2:if(18!==t)break;s.stopsAdjacency=x.decode(r,r.uint32());continue;case 3:if(26!==t)break;s.routesAdjacency=M.decode(r,r.uint32());continue;case 4:if(34!==t)break;s.routes=P.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({version:J(t.version)?globalThis.String(t.version):"",stopsAdjacency:J(t.stopsAdjacency)?x.fromJSON(t.stopsAdjacency):void 0,routesAdjacency:J(t.routesAdjacency)?M.fromJSON(t.routesAdjacency):void 0,routes:J(t.routes)?P.fromJSON(t.routes):void 0}),toJSON(t){const e={};return""!==t.version&&(e.version=t.version),void 0!==t.stopsAdjacency&&(e.stopsAdjacency=x.toJSON(t.stopsAdjacency)),void 0!==t.routesAdjacency&&(e.routesAdjacency=M.toJSON(t.routesAdjacency)),void 0!==t.routes&&(e.routes=P.toJSON(t.routes)),e},create:t=>C.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={version:"",stopsAdjacency:void 0,routesAdjacency:void 0,routes:void 0};return r.version=null!==(e=t.version)&&void 0!==e?e:"",r.stopsAdjacency=void 0!==t.stopsAdjacency&&null!==t.stopsAdjacency?x.fromPartial(t.stopsAdjacency):void 0,r.routesAdjacency=void 0!==t.routesAdjacency&&null!==t.routesAdjacency?M.fromPartial(t.routesAdjacency):void 0,r.routes=void 0!==t.routes&&null!==t.routes?P.fromPartial(t.routes):void 0,r}};function $(t){if(globalThis.Buffer)return Uint8Array.from(globalThis.Buffer.from(t,"base64"));{const e=globalThis.atob(t),r=new Uint8Array(e.length);for(let t=0;t<e.length;++t)r[t]=e.charCodeAt(t);return r}}function 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"object"==typeof t&&null!==t}function J(t){return null!=t}class V{static infinity(){return new V(Number.MAX_SAFE_INTEGER)}static origin(){return new V(0)}constructor(t){this.minutesSinceMidnight=t}static fromMinutes(t){return new V(t)}static fromHMS(t,e,r){if(t<0||e<0||r<0||e>=60||r>=60)throw new Error("Invalid time. Ensure hours, minutes, and seconds are valid values.");const n=r+60*e+3600*t,s=Math.round(n/60);return new V(s)}static fromHM(t,e){if(t<0||e<0||e>=60)throw new Error("Invalid time. Ensure hours and minutes are valid values.");return new V(e+60*t)}static fromDate(t){const e=t.getHours(),r=t.getMinutes(),n=t.getSeconds();return V.fromHMS(e,r,n)}static fromString(t){const[e,r,n]=t.split(":");if(void 0===e||void 0===r||""===e.trim()||""===r.trim()||isNaN(Number(e))||isNaN(Number(r))||void 0!==n&&(""===n.trim()||isNaN(Number(n))))throw new Error('Input string must be in the format "HH:MM:SS" or "HH:MM".');const s=parseInt(e,10),o=parseInt(r,10),i=void 0!==n?parseInt(n,10):0;return V.fromHMS(s,o,i)}toString(){let t=Math.floor(this.minutesSinceMidnight/60);const e=Math.floor(this.minutesSinceMidnight%60);return t>=24&&(t%=24),`${t.toString().padStart(2,"0")}:${e.toString().padStart(2,"0")}`}toMinutes(){return this.minutesSinceMidnight}plus(t){const e=60*this.minutesSinceMidnight+t.toSeconds();return new V(Math.round(e/60))}minus(t){let e=60*this.minutesSinceMidnight-t.toSeconds();return e<0&&(e+=86400),new V(Math.round(e/60))}diff(t){const r=this.minutesSinceMidnight-t.toMinutes();return e.fromSeconds(Math.abs(60*r))}static max(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.isAfter(t)?e:t))}static min(...t){if(0===t.length)throw new Error("At least one Time instance is required.");return t.reduce(((t,e)=>e.isBefore(t)?e:t))}isAfter(t){return this.minutesSinceMidnight>t.toMinutes()}isBefore(t){return this.minutesSinceMidnight<t.toMinutes()}equals(t){return this.minutesSinceMidnight===t.toMinutes()}}const Y=["REGULAR","NOT_AVAILABLE","MUST_PHONE_AGENCY","MUST_COORDINATE_WITH_DRIVER"],W=t=>{const e=Y[t];if(!e)throw new Error(`Invalid pickup/drop-off type ${t}`);return e};let q=class{constructor(t,e,r,n){this.stopTimes=t,this.pickUpDropOffTypes=e,this.stops=r,this.serviceRouteId=n,this.nbStops=r.length,this.nbTrips=this.stopTimes.length/(2*this.stops.length),this.stopIndices=new Map;for(let t=0;t<r.length;t++)this.stopIndices.set(r[t],t)}serialize(){return{stopTimes:this.stopTimes,pickUpDropOffTypes:this.pickUpDropOffTypes,stops:this.stops,serviceRouteId:this.serviceRouteId}}isBefore(t,e){const r=this.stopIndices.get(t);if(void 0===r)throw new Error(`Stop index ${r} not found in route ${this.serviceRouteId}`);const n=this.stopIndices.get(e);if(void 0===n)throw new Error(`Stop index ${n} not found in route ${this.serviceRouteId}`);return r<n}getNbStops(){return this.nbStops}serviceRoute(){return this.serviceRouteId}arrivalAt(t,e){const r=2*(e*this.stops.length+this.stopIndex(t)),n=this.stopTimes[r];if(void 0===n)throw new Error(`Arrival time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return V.fromMinutes(n)}departureFrom(t,e){const r=2*(e*this.stops.length+this.stopIndex(t))+1,n=this.stopTimes[r];if(void 0===n)throw new Error(`Departure time not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return V.fromMinutes(n)}pickUpTypeFrom(t,e){const r=2*(e*this.stops.length+this.stopIndex(t)),n=this.pickUpDropOffTypes[r];if(void 0===n)throw new Error(`Pick up type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return W(n)}dropOffTypeAt(t,e){const r=2*(e*this.stops.length+this.stopIndex(t))+1,n=this.pickUpDropOffTypes[r];if(void 0===n)throw new Error(`Drop off type not found for stop ${t} at trip index ${e} in route ${this.serviceRouteId}`);return W(n)}stopsIterator(t){const e=void 0!==t?this.stopIndices.get(t):0;if(void 0===e)throw new Error(`Start stop ${t} not found in route ${this.serviceRouteId}`);return function*(t,e){for(let r=e;r<t.length;r++)yield t[r]}(this.stops,e)}findEarliestTrip(t,e=V.origin(),r){const n=void 0!==r?Math.min(r-1,this.nbTrips-1):this.nbTrips-1;if(n<0)return;let s,o=0,i=n;for(;o<=i;){const r=Math.floor((o+i)/2),n=this.departureFrom(t,r),a=this.pickUpTypeFrom(t,r);(n.isAfter(e)||n.equals(e))&&"NOT_AVAILABLE"!==a?(s=r,i=r-1):o=r+1}return s}stopIndex(t){const e=this.stopIndices.get(t);if(void 0===e)throw new Error(`Stop index for ${t} not found in route ${this.serviceRouteId}`);return e}};const Z=(()=>{const t=new ArrayBuffer(4);return new DataView(t).setUint32(0,305419896),120===new Uint8Array(t)[0]})(),H=!0,X=t=>{if(Z===H)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(4*t.length),r=new DataView(e.buffer);for(let e=0;e<t.length;e++)r.setUint32(4*e,t[e],H);return e},Q=t=>{if(Z===H)return new Uint8Array(t.buffer,t.byteOffset,t.byteLength);const e=new Uint8Array(2*t.length),r=new DataView(e.buffer);for(let e=0;e<t.length;e++)r.setUint16(2*e,t[e],H);return e},K=t=>{const e={stops:{}};return t.forEach(((t,r)=>{e.stops[r]={transfers:t.transfers.map((t=>Object.assign({destination:t.destination,type:st(t.type)},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toSeconds()}))),routes:t.routes}})),e},tt=t=>{const e={routes:{}};return t.forEach(((t,r)=>{const n=t.serialize();e.routes[r]={stopTimes:Q(n.stopTimes),pickUpDropOffTypes:n.pickUpDropOffTypes,stops:X(n.stops),serviceRouteId:n.serviceRouteId}})),e},et=t=>{const e={routes:{}};return t.forEach(((t,r)=>{e.routes[r]={type:it(t.type),name:t.name}})),e},rt=t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,r])=>{const n=(t=>{if(t.byteLength%4!=0)throw new Error("Byte array length must be a multiple of 4 to convert to Uint32Array");if(Z===H)return new Uint32Array(t.buffer,t.byteOffset,t.byteLength/4);const e=new Uint32Array(t.byteLength/4),r=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=r.getUint32(4*t,H);return e})(r.stops);e.set(t,new q((t=>{if(t.byteLength%2!=0)throw new Error("Byte array length must be a multiple of 2 to convert to Uint16Array");if(Z===H)return new Uint16Array(t.buffer,t.byteOffset,t.byteLength/2);const e=new Uint16Array(t.byteLength/2),r=new DataView(t.buffer,t.byteOffset,t.byteLength);for(let t=0;t<e.length;t++)e[t]=r.getUint16(2*t,H);return e})(r.stopTimes),r.pickUpDropOffTypes,n,r.serviceRouteId))})),e},nt=t=>{switch(t){case b.RECOMMENDED_TRANSFER_POINT:return"RECOMMENDED";case b.TIMED_TRANSFER:return"GUARANTEED";case b.REQUIRES_MINIMAL_TIME:return"REQUIRES_MINIMAL_TIME";case b.IN_SEAT_TRANSFER:return"IN_SEAT";case b.UNRECOGNIZED:throw new Error("Unrecognized protobuf transfer type.")}},st=t=>{switch(t){case"RECOMMENDED":return b.RECOMMENDED_TRANSFER_POINT;case"GUARANTEED":return b.TIMED_TRANSFER;case"REQUIRES_MINIMAL_TIME":return b.REQUIRES_MINIMAL_TIME;case"IN_SEAT":return b.IN_SEAT_TRANSFER}},ot=t=>{switch(t){case R.TRAM:return"TRAM";case R.SUBWAY:return"SUBWAY";case R.RAIL:return"RAIL";case R.BUS:return"BUS";case R.FERRY:return"FERRY";case R.CABLE_TRAM:return"CABLE_TRAM";case R.AERIAL_LIFT:return"AERIAL_LIFT";case R.FUNICULAR:return"FUNICULAR";case R.TROLLEYBUS:return"TROLLEYBUS";case R.MONORAIL:return"MONORAIL";case R.UNRECOGNIZED:default:throw new Error("Unrecognized protobuf route type.")}},it=t=>{switch(t){case"TRAM":return R.TRAM;case"SUBWAY":return R.SUBWAY;case"RAIL":return R.RAIL;case"BUS":return R.BUS;case"FERRY":return R.FERRY;case"CABLE_TRAM":return R.CABLE_TRAM;case"AERIAL_LIFT":return R.AERIAL_LIFT;case"FUNICULAR":return R.FUNICULAR;case"TROLLEYBUS":return R.TROLLEYBUS;case"MONORAIL":return R.MONORAIL}},at=new Set(["TRAM","SUBWAY","RAIL","BUS","FERRY","CABLE_TRAM","AERIAL_LIFT","FUNICULAR","TROLLEYBUS","MONORAIL"]),ut="0.0.3";class ct{constructor(t,e,r){this.stopsAdjacency=t,this.routesAdjacency=e,this.routes=r}serialize(){const t={version:ut,stopsAdjacency:K(this.stopsAdjacency),routesAdjacency:tt(this.routesAdjacency),routes:et(this.routes)},e=new I;return C.encode(t,e),e.finish()}static fromData(t){const r=new A(t),n=C.decode(r);if(n.version!==ut)throw new Error(`Unsupported timetable version ${n.version}`);return new ct((t=>{const r=new Map;return Object.entries(t.stops).forEach((([t,n])=>{const s=parseInt(t,10);r.set(s,{transfers:n.transfers.map((t=>Object.assign({destination:t.destination,type:nt(t.type)},void 0!==t.minTransferTime&&{minTransferTime:e.fromSeconds(t.minTransferTime)}))),routes:n.routes})})),r})(n.stopsAdjacency),rt(n.routesAdjacency),(t=>{const e=new Map;return Object.entries(t.routes).forEach((([t,r])=>{e.set(t,{type:ot(r.type),name:r.name})})),e})(n.routes))}getRoute(t){return this.routesAdjacency.get(t)}getTransfers(t){var e,r;return null!==(r=null===(e=this.stopsAdjacency.get(t))||void 0===e?void 0:e.transfers)&&void 0!==r?r:[]}getServiceRoute(t){return this.routes.get(t.serviceRoute())}routesPassingThrough(t){const e=this.stopsAdjacency.get(t);if(!e)return[];const r=[];for(const t of e.routes){const e=this.routesAdjacency.get(t);e&&r.push(e)}return r}findReachableRoutes(t,e=at){const r=new Map;for(const n of t){const t=this.routesPassingThrough(n).filter((t=>{const r=this.getServiceRoute(t);return e.has(r.type)}));for(const e of t){const t=r.get(e);t?e.isBefore(n,t)&&r.set(e,n):r.set(e,n)}}return r}}class lt{constructor(t){this.from=t.fromValue,this.to=t.toValue,this.departureTime=t.departureTimeValue,this.options=t.optionsValue}}lt.Builder=class{constructor(){this.toValue=new Set,this.optionsValue={maxTransfers:5,minTransferTime:e.fromSeconds(120),transportModes:at}}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 lt(this)}};class ft{constructor(t){this.legs=t}departureTime(){const t=e.zero();for(let e=0;e<this.legs.length;e++){const r=this.legs[e];if("departureTime"in r)return r.departureTime.minus(t);"minTransferTime"in r&&r.minTransferTime&&t.add(r.minTransferTime)}throw new Error("No vehicle leg found in route")}arrivalTime(){let t=V.origin();const r=e.zero();let n=!1;for(let e=this.legs.length-1;e>=0;e--){const s=this.legs[e];"arrivalTime"in s&&!n?(t=s.arrivalTime,n=!0):"minTransferTime"in s&&s.minTransferTime&&n&&r.add(s.minTransferTime)}if(!n)throw new Error("No vehicle leg found in route");return t.plus(r)}totalDuration(){return 0===this.legs.length?e.zero():this.arrivalTime().diff(this.departureTime())}toString(){return this.legs.map(((t,e)=>{var r;const n=`From: ${t.from.name}${t.from.platform?` (Pl. ${t.from.platform})`:""}`,s=`To: ${t.to.name}${t.to.platform?` (Pl. ${t.to.platform})`:""}`,o="minTransferTime"in t?`Minimum Transfer Time: ${null===(r=t.minTransferTime)||void 0===r?void 0:r.toString()}`:"",i="route"in t&&"departureTime"in t&&"arrivalTime"in t?`Route: ${t.route.type} ${t.route.name}, Departure: ${t.departureTime.toString()}, Arrival: ${t.arrivalTime.toString()}`:"";return[`Leg ${e+1}:`,` ${n}`,` ${s}`,o?` ${o}`:"",i?` ${i}`:""].filter((t=>""!==t.trim())).join("\n")})).join("\n")}asJson(){return this.legs.map((t=>"route"in t?{from:t.from.sourceStopId,to:t.to.sourceStopId,departure:t.departureTime.toString(),arrival:t.arrivalTime.toString(),route:t.route}:Object.assign({from:t.from.sourceStopId,to:t.to.sourceStopId,type:t.type},void 0!==t.minTransferTime&&{minTransferTime:t.minTransferTime.toString()})))}}class dt{constructor(t,e,r,n){this.query=t,this.earliestArrivals=e,this.earliestArrivalsPerRound=r,this.stopsIndex=n}bestRoute(t){var e,r,n;const s=(t instanceof Set?Array.from(t):t?[t]:Array.from(this.query.to)).flatMap((t=>this.stopsIndex.equivalentStops(t)));let o,i;for(const t of s){const e=this.earliestArrivals.get(t.id);void 0!==e&&(void 0===i||e.arrival.isBefore(i.arrival))&&(o=t.id,i=e)}if(!o||!i)return;const a=[];let u=o,c=i.legNumber;for(;i.origin!==u;){const t=null===(e=this.earliestArrivalsPerRound[c])||void 0===e?void 0:e.get(u);if(!(null==t?void 0:t.leg))throw new Error(`No leg found for a trip leg: start stop=${null!==(n=null===(r=null==t?void 0:t.leg)||void 0===r?void 0:r.from.id)&&void 0!==n?n:"unknown"}, end stop=${u}, round=${c}, origin=${i.origin}`);a.unshift(t.leg),u=t.leg.from.id,"route"in t.leg&&(c-=1)}return new ft(a)}arrivalAt(t,e){const r=this.stopsIndex.equivalentStops(t);let n;const s=void 0!==e?this.earliestArrivalsPerRound[e+1]:this.earliestArrivals;for(const t of r){const e=s.get(t.id);void 0!==e&&(void 0===n||e.arrival.isBefore(n.arrival))&&(n=e)}return n}}const ht=V.infinity();class pt{constructor(t,e){this.timetable=t,this.stopsIndex=e}considerTransfers(t,r,n,s,o){var i,a;const{options:u}=t,c=new Set;for(const t of r){const r=n.get(t);if(!r)continue;const l=r.leg;if(!l||"route"in l)for(const l of this.timetable.getTransfers(t)){let f;f=l.minTransferTime?l.minTransferTime:"IN_SEAT"===l.type?e.zero():u.minTransferTime;const d=r.arrival.plus(f),h=null!==(a=null===(i=n.get(l.destination))||void 0===i?void 0:i.arrival)&&void 0!==a?a:ht;if(d.isBefore(h)){const e=r.origin;n.set(l.destination,{arrival:d,legNumber:o,origin:e,leg:{from:this.stopsIndex.findStopById(t),to:this.stopsIndex.findStopById(l.destination),minTransferTime:l.minTransferTime,type:l.type}}),s.set(l.destination,{arrival:d,legNumber:o,origin:e}),c.add(l.destination)}}}for(const t of c)r.add(t)}earliestArrivalAtAnyStop(t,e){var r,n;let s=ht;for(const o of e){const e=null!==(n=null===(r=t.get(o.id))||void 0===r?void 0:r.arrival)&&void 0!==n?n:ht;s=V.min(s,e)}return s}route(t){var e,r,n,s,o;const{from:i,to:a,departureTime:u,options:c}=t,l=this.stopsIndex.equivalentStops(i),f=Array.from(a).flatMap((t=>this.stopsIndex.equivalentStops(t))),d=new Map,h=new Map,p=[h],m=new Set;for(const t of l)m.add(t.id),d.set(t.id,{arrival:u,legNumber:0,origin:t.id}),h.set(t.id,{arrival:u,legNumber:0,origin:t.id});this.considerTransfers(t,m,h,d,0);for(let i=1;i<=c.maxTransfers+1;i++){const a=new Map;p.push(a);const u=p[i-1],l=this.timetable.findReachableRoutes(m,c.transportModes);m.clear();for(const[t,c]of l.entries()){let l;for(const h of t.stopsIterator(c)){if(void 0!==l){const n=t.arrivalAt(h,l.tripIndex),s=t.dropOffTypeAt(h,l.tripIndex),o=null!==(r=null===(e=d.get(h))||void 0===e?void 0:e.arrival)&&void 0!==r?r:ht;if("NOT_AVAILABLE"!==s&&n.isBefore(o)&&n.isBefore(this.earliestArrivalAtAnyStop(d,f))){const e=t.departureFrom(l.bestHopOnStop,l.tripIndex);a.set(h,{arrival:n,legNumber:i,origin:l.origin,leg:{from:this.stopsIndex.findStopById(l.bestHopOnStop),to:this.stopsIndex.findStopById(h),departureTime:e,arrivalTime:n,route:this.timetable.getServiceRoute(t)}}),d.set(h,{arrival:n,legNumber:i,origin:l.origin}),m.add(h)}}const c=null===(n=u.get(h))||void 0===n?void 0:n.arrival;if(void 0!==c&&(void 0===l||c.isBefore(t.arrivalAt(h,l.tripIndex))||c.equals(t.arrivalAt(h,l.tripIndex)))){const e=t.findEarliestTrip(h,c,null==l?void 0:l.tripIndex);void 0!==e&&(l={tripIndex:e,bestHopOnStop:h,origin:null!==(o=null===(s=u.get(h))||void 0===s?void 0:s.origin)&&void 0!==o?o:h})}}}if(this.considerTransfers(t,m,a,d,i),0===m.size)break}return new dt(t,d,p,this.stopsIndex)}}class mt{constructor(t=[],e=vt){if(this.data=t,this.length=this.data.length,this.compare=e,this.length>0)for(let t=(this.length>>1)-1;t>=0;t--)this._down(t)}push(t){this.data.push(t),this.length++,this._up(this.length-1)}pop(){if(0===this.length)return;const t=this.data[0],e=this.data.pop();return this.length--,this.length>0&&(this.data[0]=e,this._down(0)),t}peek(){return this.data[0]}_up(t){const{data:e,compare:r}=this,n=e[t];for(;t>0;){const s=t-1>>1,o=e[s];if(r(n,o)>=0)break;e[t]=o,t=s}e[t]=n}_down(t){const{data:e,compare:r}=this,n=this.length>>1,s=e[t];for(;t<n;){let n=1+(t<<1),o=e[n];const i=n+1;if(i<this.length&&r(e[i],o)<0&&(n=i,o=e[i]),r(o,s)>=0)break;e[t]=o,t=n}e[t]=s}}function vt(t,e){return t<e?-1:t>e?1:0}const gt=Math.PI/180;function yt(t,e,r,n){const s=n.minLng,o=n.maxLng,i=n.minLat,a=n.maxLat;if(t>=s&&t<=o)return e<i?Et((e-i)*gt):e>a?Et((e-a)*gt):0;const u=Math.min(Et((t-s)*gt),Et((t-o)*gt)),c=function(t,e){const r=1-2*e;return r<=0?t>0?90:-90:Math.atan(Math.tan(t*gt)/r)/gt}(e,u);return c>i&&c<a?It(u,r,e,c):Math.min(It(u,r,e,i),It(u,r,e,a))}function Tt(t,e){return t.dist-e.dist}function Et(t){const e=Math.sin(t/2);return e*e}function It(t,e,r,n){return e*Math.cos(n*gt)*t+Et((r-n)*gt)}function At(t,e,r,n,s){return It(Et((t-r)*gt),s,e,n)}const St=[Int8Array,Uint8Array,Uint8ClampedArray,Int16Array,Uint16Array,Int32Array,Uint32Array,Float32Array,Float64Array];class wt{static from(t){if(!(t instanceof ArrayBuffer))throw new Error("Data must be an instance of ArrayBuffer.");const[e,r]=new Uint8Array(t,0,2);if(219!==e)throw new Error("Data does not appear to be in a KDBush format.");const n=r>>4;if(1!==n)throw new Error(`Got v${n} data when expected v1.`);const s=St[15&r];if(!s)throw new Error("Unrecognized array type.");const[o]=new Uint16Array(t,2,1),[i]=new Uint32Array(t,4,1);return new wt(i,o,s,t)}constructor(t,e=64,r=Float64Array,n){if(isNaN(t)||t<0)throw new Error(`Unpexpected numItems value: ${t}.`);this.numItems=+t,this.nodeSize=Math.min(Math.max(+e,2),65535),this.ArrayType=r,this.IndexArrayType=t<65536?Uint16Array:Uint32Array;const s=St.indexOf(this.ArrayType),o=2*t*this.ArrayType.BYTES_PER_ELEMENT,i=t*this.IndexArrayType.BYTES_PER_ELEMENT,a=(8-i%8)%8;if(s<0)throw new Error(`Unexpected typed array class: ${r}.`);n&&n instanceof ArrayBuffer?(this.data=n,this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+i+a,2*t),this._pos=2*t,this._finished=!0):(this.data=new ArrayBuffer(8+o+i+a),this.ids=new this.IndexArrayType(this.data,8,t),this.coords=new this.ArrayType(this.data,8+i+a,2*t),this._pos=0,this._finished=!1,new Uint8Array(this.data,0,2).set([219,16+s]),new Uint16Array(this.data,2,1)[0]=e,new Uint32Array(this.data,4,1)[0]=t)}add(t,e){const r=this._pos>>1;return this.ids[r]=r,this.coords[this._pos++]=t,this.coords[this._pos++]=e,r}finish(){const t=this._pos>>1;if(t!==this.numItems)throw new Error(`Added ${t} items when expected ${this.numItems}.`);return bt(this.ids,this.coords,this.nodeSize,0,this.numItems-1,0),this._finished=!0,this}range(t,e,r,n){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:s,coords:o,nodeSize:i}=this,a=[0,s.length-1,0],u=[];for(;a.length;){const c=a.pop()||0,l=a.pop()||0,f=a.pop()||0;if(l-f<=i){for(let i=f;i<=l;i++){const a=o[2*i],c=o[2*i+1];a>=t&&a<=r&&c>=e&&c<=n&&u.push(s[i])}continue}const d=f+l>>1,h=o[2*d],p=o[2*d+1];h>=t&&h<=r&&p>=e&&p<=n&&u.push(s[d]),(0===c?t<=h:e<=p)&&(a.push(f),a.push(d-1),a.push(1-c)),(0===c?r>=h:n>=p)&&(a.push(d+1),a.push(l),a.push(1-c))}return u}within(t,e,r){if(!this._finished)throw new Error("Data not yet indexed - call index.finish().");const{ids:n,coords:s,nodeSize:o}=this,i=[0,n.length-1,0],a=[],u=r*r;for(;i.length;){const c=i.pop()||0,l=i.pop()||0,f=i.pop()||0;if(l-f<=o){for(let r=f;r<=l;r++)Ot(s[2*r],s[2*r+1],t,e)<=u&&a.push(n[r]);continue}const d=f+l>>1,h=s[2*d],p=s[2*d+1];Ot(h,p,t,e)<=u&&a.push(n[d]),(0===c?t-r<=h:e-r<=p)&&(i.push(f),i.push(d-1),i.push(1-c)),(0===c?t+r>=h:e+r>=p)&&(i.push(d+1),i.push(l),i.push(1-c))}return a}}function bt(t,e,r,n,s,o){if(s-n<=r)return;const i=n+s>>1;Rt(t,e,i,n,s,o),bt(t,e,r,n,i-1,1-o),bt(t,e,r,i+1,s,1-o)}function Rt(t,e,r,n,s,o){for(;s>n;){if(s-n>600){const i=s-n+1,a=r-n+1,u=Math.log(i),c=.5*Math.exp(2*u/3),l=.5*Math.sqrt(u*c*(i-c)/i)*(a-i/2<0?-1:1);Rt(t,e,r,Math.max(n,Math.floor(r-a*c/i+l)),Math.min(s,Math.floor(r+(i-a)*c/i+l)),o)}const i=e[2*r+o];let a=n,u=s;for(_t(t,e,n,r),e[2*s+o]>i&&_t(t,e,n,s);a<u;){for(_t(t,e,a,u),a++,u--;e[2*a+o]<i;)a++;for(;e[2*u+o]>i;)u--}e[2*n+o]===i?_t(t,e,n,u):(u++,_t(t,e,u,s)),u<=r&&(n=u+1),r<=u&&(s=u-1)}}function _t(t,e,r,n){Nt(t,r,n),Nt(e,2*r,2*n),Nt(e,2*r+1,2*n+1)}function Nt(t,e,r){const n=t[e];t[e]=t[r],t[r]=n}function Ot(t,e,r,n){const s=t-r,o=e-n;return s*s+o*o}const kt="KEYS",Mt="VALUES",Lt="";class Ut{set;_type;_path;constructor(t,e){const r=t._tree,n=Array.from(r.keys());this.set=t,this._type=e,this._path=n.length>0?[{node:r,keys:n}]:[]}next(){const t=this.dive();return this.backtrack(),t}dive(){if(0===this._path.length)return{done:!0,value:void 0};const{node:t,keys:e}=xt(this._path);if(xt(e)===Lt)return{done:!1,value:this.result()};const r=t.get(xt(e));return this._path.push({node:r,keys:Array.from(r.keys())}),this.dive()}backtrack(){if(0===this._path.length)return;const t=xt(this._path).keys;t.pop(),!(t.length>0)&&(this._path.pop(),this.backtrack())}key(){return this.set._prefix+this._path.map((({keys:t})=>xt(t))).filter((t=>t!==Lt)).join("")}value(){return xt(this._path).node.get(Lt)}result(){switch(this._type){case Mt:return this.value();case kt:return this.key();default:return[this.key(),this.value()]}}[Symbol.iterator](){return this}}const xt=t=>t[t.length-1],Bt=(t,e,r,n,s,o,i,a)=>{const u=o*i;t:for(const c of t.keys())if(c===Lt){const e=s[u-1];e<=r&&n.set(a,[t.get(c),e])}else{let u=o;for(let t=0;t<c.length;++t,++u){const n=c[t],o=i*u,a=o-i;let l=s[o];const f=Math.max(0,u-r-1),d=Math.min(i-1,u+r);for(let t=f;t<d;++t){const r=n!==e[t],i=s[a+t]+ +r,u=s[a+t+1]+1,c=s[o+t]+1,f=s[o+t+1]=Math.min(i,u,c);f<l&&(l=f)}if(l>r)continue t}Bt(t.get(c),e,r,n,s,u,i,a+c)}};class Dt{_tree;_prefix;_size=void 0;constructor(t=new Map,e=""){this._tree=t,this._prefix=e}atPrefix(t){if(!t.startsWith(this._prefix))throw new Error("Mismatched prefix");const[e,r]=Ft(this._tree,t.slice(this._prefix.length));if(void 0===e){const[e,n]=Gt(r);for(const r of e.keys())if(r!==Lt&&r.startsWith(n)){const s=new Map;return s.set(r.slice(n.length),e.get(r)),new Dt(s,t)}}return new Dt(e,t)}clear(){this._size=void 0,this._tree.clear()}delete(t){return this._size=void 0,Ct(this._tree,t)}entries(){return new Ut(this,"ENTRIES")}forEach(t){for(const[e,r]of this)t(e,r,this)}fuzzyGet(t,e){return((t,e,r)=>{const n=new Map;if("string"!=typeof e)return n;const s=e.length+1,o=s+r,i=new Uint8Array(o*s).fill(r+1);for(let t=0;t<s;++t)i[t]=t;for(let t=1;t<o;++t)i[t*s]=t;return Bt(t,e,r,n,i,1,s,""),n})(this._tree,t,e)}get(t){const e=Pt(this._tree,t);return void 0!==e?e.get(Lt):void 0}has(t){return Pt(this._tree,t)?.has(Lt)??!1}keys(){return new Ut(this,kt)}set(t,e){if("string"!=typeof t)throw new Error("key must be a string");return this._size=void 0,jt(this._tree,t).set(Lt,e),this}get size(){if(this._size)return this._size;this._size=0;const t=this.entries();for(;!t.next().done;)this._size+=1;return this._size}update(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const r=jt(this._tree,t);return r.set(Lt,e(r.get(Lt))),this}fetch(t,e){if("string"!=typeof t)throw new Error("key must be a string");this._size=void 0;const r=jt(this._tree,t);let n=r.get(Lt);return void 0===n&&r.set(Lt,n=e()),n}values(){return new Ut(this,Mt)}[Symbol.iterator](){return this.entries()}static from(t){const e=new Dt;for(const[r,n]of t)e.set(r,n);return e}static fromObject(t){return Dt.from(Object.entries(t))}}const Ft=(t,e,r=[])=>{if(0===e.length||null==t)return[t,r];for(const n of t.keys())if(n!==Lt&&e.startsWith(n))return r.push([t,n]),Ft(t.get(n),e.slice(n.length),r);return r.push([t,e]),Ft(void 0,"",r)},Pt=(t,e)=>{if(0===e.length||!t)return t;for(const r of t.keys())if(r!==Lt&&e.startsWith(r))return Pt(t.get(r),e.slice(r.length))},jt=(t,e)=>{const r=e.length;t:for(let n=0;t&&n<r;){for(const s of t.keys())if(s!==Lt&&e[n]===s[0]){const o=Math.min(r-n,s.length);let i=1;for(;i<o&&e[n+i]===s[i];)++i;const a=t.get(s);if(i===s.length)t=a;else{const r=new Map;r.set(s.slice(i),a),t.set(e.slice(n,n+i),r),t.delete(s),t=r}n+=i;continue t}const s=new Map;return t.set(e.slice(n),s),s}return t},Ct=(t,e)=>{const[r,n]=Ft(t,e);if(void 0!==r)if(r.delete(Lt),0===r.size)$t(n);else if(1===r.size){const[t,e]=r.entries().next().value;zt(n,t,e)}},$t=t=>{if(0===t.length)return;const[e,r]=Gt(t);if(e.delete(r),0===e.size)$t(t.slice(0,-1));else if(1===e.size){const[r,n]=e.entries().next().value;r!==Lt&&zt(t.slice(0,-1),r,n)}},zt=(t,e,r)=>{if(0===t.length)return;const[n,s]=Gt(t);n.set(s+e,r),n.delete(s)},Gt=t=>t[t.length-1],Jt=/[\n\r\p{Z}\p{P}]+/u,Vt="or",Yt="and",Wt="and_not",qt=(t,e)=>{t.includes(e)||t.push(e)},Zt=(t,e)=>{for(const r of e)t.includes(r)||t.push(r)},Ht=({score:t},{score:e})=>e-t,Xt=()=>new Map,Qt=(t,e)=>Object.prototype.hasOwnProperty.call(t,e)?t[e]:void 0,Kt={[Vt]:(t,e)=>{for(const r of e.keys()){const n=t.get(r);if(null==n)t.set(r,e.get(r));else{const{score:t,terms:s,match:o}=e.get(r);n.score=n.score+t,n.match=Object.assign(n.match,o),Zt(n.terms,s)}}return t},[Yt]:(t,e)=>{const r=new Map;for(const n of e.keys()){const s=t.get(n);if(null==s)continue;const{score:o,terms:i,match:a}=e.get(n);Zt(s.terms,i),r.set(n,{score:s.score+o,terms:s.terms,match:Object.assign(s.match,a)})}return r},[Wt]:(t,e)=>{for(const r of e.keys())t.delete(r);return t}},te=(t,e,r,n,s,o)=>{const{k:i,b:a,d:u}=o;return Math.log(1+(r-e+.5)/(e+.5))*(u+t*(i+1)/(t+i*(1-a+a*n/s)))},ee=(t,e,r,n)=>{for(const s of Object.keys(t._fieldIds))if(t._fieldIds[s]===r)return void t._options.logger("warn",`SlimSearch: document with ID ${t._documentIds.get(e)} has changed before removal: term "${n}" was not present in field "${s}". Removing a document after it has changed can corrupt the index!`,"version_conflict")},re=(t,e,r,n)=>{const s=t._index.fetch(n,Xt);let o=s.get(e);if(null==o)o=new Map,o.set(r,1),s.set(e,o);else{const t=o.get(r);o.set(r,(t??0)+1)}},ne=(t,e,r,n)=>{if(!t._index.has(n))return void ee(t,r,e,n);const s=t._index.fetch(n,Xt),o=s.get(e),i=o?.get(r);!o||typeof i>"u"?ee(t,r,e,n):i<=1?o.size<=1?s.delete(e):o.delete(r):o.set(r,i-1),0===t._index.get(n).size&&t._index.delete(n)},se=(t,e,r,n,s)=>{let o=t._fieldLength.get(e);null==o&&t._fieldLength.set(e,o=[]),o[r]=s;const i=(t._avgFieldLength[r]||0)*n+s;t._avgFieldLength[r]=i/(n+1)},oe=(t,e)=>{const{extractField:r,tokenize:n,processTerm:s,fields:o,idField:i}=t._options,a=r(e,i);if(null==a)throw new Error(`SlimSearch: document does not have ID field "${i}"`);if(((t,e)=>t._idToShortId.has(e))(t,a))throw new Error(`SlimSearch: duplicate ID ${a}`);const u=((t,e)=>{const r=t._nextId;return t._idToShortId.set(e,r),t._documentIds.set(r,e),t._documentCount+=1,t._nextId+=1,r})(t,a);((t,e,r)=>{const{storeFields:n,extractField:s}=t._options;if(0===n?.length)return;let o=t._storedFields.get(e);void 0===o&&t._storedFields.set(e,o={});for(const t of n){const e=s(r,t);null!=e&&(o[t]=e)}})(t,u,e);for(const i of o){const o=r(e,i);if(null==o)continue;const a=n(o.toString(),i),c=t._fieldIds[i],l=new Set(a).size;se(t,u,c,t._documentCount-1,l);for(const e of a){const r=s(e,i);if(Array.isArray(r))for(const e of r)re(t,c,u,e);else r&&re(t,c,u,r)}}},ie={idField:"id",extractField:(t,e)=>t[e],tokenize:t=>t.split(Jt),processTerm:t=>t.toLowerCase(),fields:void 0,searchOptions:void 0,storeFields:[],logger:(t,e)=>{console?.[t]?.(e)},autoVacuum:!0},ae={combineWith:Vt,prefix:!1,fuzzy:!1,maxFuzzy:6,boost:{},weights:{fuzzy:.45,prefix:.375},bm25:{k:1.2,b:.7,d:.5}},ue={combineWith:"and",prefix:(t,e,r)=>e===r.length-1},ce={minDirtFactor:.1,minDirtCount:20},le={batchSize:1e3,batchWait:10,...ce},fe=Symbol("*"),de=(t,e=Vt)=>{if(0===t.length)return new Map;const r=e.toLowerCase();if(!(r in Kt))throw new Error(`Invalid combination operator: ${e}`);return t.reduce(Kt[r])},he=(t,e,r,n,s,o,i,a,u,c=new Map)=>{if(null==o)return c;for(const l of Object.keys(i)){const f=i[l],d=t._fieldIds[l],h=o.get(d);if(null==h)continue;let p=h.size;const m=t._avgFieldLength[d];for(const o of h.keys()){if(!t._documentIds.has(o)){ne(t,d,o,r),p-=1;continue}const i=a?a(t._documentIds.get(o),r,t._storedFields.get(o)):1;if(!i)continue;const v=h.get(o),g=t._fieldLength.get(o)[d],y=n*s*f*i*te(v,p,t._documentCount,g,m,u),T=c.get(o);if(T){T.score+=y,qt(T.terms,e);const t=Qt(T.match,r);t?t.push(l):T.match[r]=[l]}else c.set(o,{score:y,terms:[e],match:{[r]:[l]}})}}return c},pe=(t,e,r={})=>{if(e===fe)return((t,e)=>{const r=new Map,n={...t._options.searchOptions,...e};for(const[e,s]of t._documentIds){const o=n.boostDocument?n.boostDocument(s,"",t._storedFields.get(e)):1;r.set(e,{score:o,terms:[],match:{}})}return r})(t,r);if("string"!=typeof e){const n={...r,...e,queries:void 0},s=e.queries.map((e=>pe(t,e,n)));return de(s,n.combineWith)}const{tokenize:n,processTerm:s,searchOptions:o}=t._options,i={tokenize:n,processTerm:s,...o,...r},{tokenize:a,processTerm:u}=i,c=a(e).flatMap((t=>u(t))).filter((t=>!!t)).map((t=>(e,r,n)=>({term:e,fuzzy:"function"==typeof t.fuzzy?t.fuzzy(e,r,n):t.fuzzy??!1,prefix:"function"==typeof t.prefix?t.prefix(e,r,n):!0===t.prefix,termBoost:"function"==typeof t.boostTerm?t.boostTerm(e,r,n):1}))(i)).map((e=>((t,e,r)=>{const n={...t._options.searchOptions,...r},s=(n.fields??t._options.fields).reduce(((t,e)=>({...t,[e]:Qt(n.boost,e)||1})),{}),{boostDocument:o,weights:i,maxFuzzy:a,bm25:u}=n,{fuzzy:c,prefix:l}={...ae.weights,...i},f=t._index.get(e.term),d=he(t,e.term,e.term,1,e.termBoost,f,s,o,u);let h,p;if(e.prefix&&(h=t._index.atPrefix(e.term)),e.fuzzy){const r=!0===e.fuzzy?.2:e.fuzzy,n=r<1?Math.min(a,Math.round(e.term.length*r)):r;n&&(p=t._index.fuzzyGet(e.term,n))}if(h)for(const[r,n]of h){const i=r.length-e.term.length;if(!i)continue;p?.delete(r);const a=l*r.length/(r.length+.3*i);he(t,e.term,r,a,e.termBoost,n,s,o,u,d)}if(p)for(const r of p.keys()){const[n,i]=p.get(r);if(!i)continue;const a=c*r.length/(r.length+i);he(t,e.term,r,a,e.termBoost,n,s,o,u,d)}return d})(t,e,i)));return de(c,i.combineWith)};class me{_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?le:t.autoVacuum;this._options={...ie,...t,autoVacuum:e,searchOptions:{...ae,...t.searchOptions},autoSuggestOptions:{...ue,...t.autoSuggestOptions}},this._index=new Dt,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=ce,this.addFields(this._options.fields)}get isVacuuming(){return null!=this._currentVacuum}get dirtCount(){return this._dirtCount}get dirtFactor(){return this._dirtCount/(1+this._documentCount+this._dirtCount)}get documentCount(){return this._documentCount}get termCount(){return this._index.size}toJSON(){const t=[];for(const[e,r]of this._index){const n={};for(const[t,e]of r)n[t]=Object.fromEntries(e);t.push([e,n])}return{documentCount:this._documentCount,nextId:this._nextId,documentIds:Object.fromEntries(this._documentIds),fieldIds:this._fieldIds,fieldLength:Object.fromEntries(this._fieldLength),averageFieldLength:this._avgFieldLength,storedFields:Object.fromEntries(this._storedFields),dirtCount:this._dirtCount,index:t,version:2}}addFields(t){for(let e=0;e<t.length;e++)this._fieldIds[t[e]]=e}}const ve=t=>{const e=t.toLowerCase(),r=new Set([e]),n={a:["à","â","ä"],c:["ç"],e:["é","è","ê","ë"],i:["î","ï"],o:["ô","ö"],u:["ù","û","ü"],ae:["ä"],oe:["ö"],ue:["ü"]};for(const[t,s]of Object.entries(n))e.includes(t)&&s.forEach((n=>{r.add(e.replace(t,n))})),s.forEach((n=>{e.includes(n)&&r.add(e.replace(n,t))}));return Array.from(r)};var ge;function ye(t){switch(t){case 0:case"SIMPLE_STOP_OR_PLATFORM":return ge.SIMPLE_STOP_OR_PLATFORM;case 1:case"STATION":return ge.STATION;case 2:case"ENTRANCE_EXIT":return ge.ENTRANCE_EXIT;case 3:case"GENERIC_NODE":return ge.GENERIC_NODE;case 4:case"BOARDING_AREA":return ge.BOARDING_AREA;default:return ge.UNRECOGNIZED}}!function(t){t[t.SIMPLE_STOP_OR_PLATFORM=0]="SIMPLE_STOP_OR_PLATFORM",t[t.STATION=1]="STATION",t[t.ENTRANCE_EXIT=2]="ENTRANCE_EXIT",t[t.GENERIC_NODE=3]="GENERIC_NODE",t[t.BOARDING_AREA=4]="BOARDING_AREA",t[t.UNRECOGNIZED=-1]="UNRECOGNIZED"}(ge||(ge={}));const Te={encode(t,e=new I){""!==t.name&&e.uint32(10).string(t.name),""!==t.sourceStopId&&e.uint32(18).string(t.sourceStopId),void 0!==t.lat&&e.uint32(25).double(t.lat),void 0!==t.lon&&e.uint32(33).double(t.lon),e.uint32(42).fork();for(const r of t.children)e.uint32(r);return e.join(),void 0!==t.parent&&e.uint32(48).uint32(t.parent),0!==t.locationType&&e.uint32(56).int32(t.locationType),void 0!==t.platform&&e.uint32(66).string(t.platform),e},decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={name:"",sourceStopId:"",lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.name=r.string();continue;case 2:if(18!==t)break;s.sourceStopId=r.string();continue;case 3:if(25!==t)break;s.lat=r.double();continue;case 4:if(33!==t)break;s.lon=r.double();continue;case 5:if(40===t){s.children.push(r.uint32());continue}if(42===t){const t=r.uint32()+r.pos;for(;r.pos<t;)s.children.push(r.uint32());continue}break;case 6:if(48!==t)break;s.parent=r.uint32();continue;case 7:if(56!==t)break;s.locationType=r.int32();continue;case 8:if(66!==t)break;s.platform=r.string();continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({name:Ae(t.name)?globalThis.String(t.name):"",sourceStopId:Ae(t.sourceStopId)?globalThis.String(t.sourceStopId):"",lat:Ae(t.lat)?globalThis.Number(t.lat):void 0,lon:Ae(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:Ae(t.parent)?globalThis.Number(t.parent):void 0,locationType:Ae(t.locationType)?ye(t.locationType):0,platform:Ae(t.platform)?globalThis.String(t.platform):void 0}),toJSON(t){var e;const r={};return""!==t.name&&(r.name=t.name),""!==t.sourceStopId&&(r.sourceStopId=t.sourceStopId),void 0!==t.lat&&(r.lat=t.lat),void 0!==t.lon&&(r.lon=t.lon),(null===(e=t.children)||void 0===e?void 0:e.length)&&(r.children=t.children.map((t=>Math.round(t)))),void 0!==t.parent&&(r.parent=Math.round(t.parent)),0!==t.locationType&&(r.locationType=function(t){switch(t){case ge.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case ge.STATION:return"STATION";case ge.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case ge.GENERIC_NODE:return"GENERIC_NODE";case ge.BOARDING_AREA:return"BOARDING_AREA";case ge.UNRECOGNIZED:default:return"UNRECOGNIZED"}}(t.locationType)),void 0!==t.platform&&(r.platform=t.platform),r},create:t=>Te.fromPartial(null!=t?t:{}),fromPartial(t){var e,r,n,s,o,i,a,u;const c={name:"",sourceStopId:"",lat:void 0,lon:void 0,children:[],parent:void 0,locationType:0,platform:void 0};return c.name=null!==(e=t.name)&&void 0!==e?e:"",c.sourceStopId=null!==(r=t.sourceStopId)&&void 0!==r?r:"",c.lat=null!==(n=t.lat)&&void 0!==n?n:void 0,c.lon=null!==(s=t.lon)&&void 0!==s?s:void 0,c.children=(null===(o=t.children)||void 0===o?void 0:o.map((t=>t)))||[],c.parent=null!==(i=t.parent)&&void 0!==i?i:void 0,c.locationType=null!==(a=t.locationType)&&void 0!==a?a:0,c.platform=null!==(u=t.platform)&&void 0!==u?u:void 0,c}};const Ee={encode:(t,e=new I)=>(""!==t.version&&e.uint32(10).string(t.version),Object.entries(t.stops).forEach((([t,r])=>{Ie.encode({key:t,value:r},e.uint32(18).fork()).join()})),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={version:"",stops:{}};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(10!==t)break;s.version=r.string();continue;case 2:{if(18!==t)break;const e=Ie.decode(r,r.uint32());void 0!==e.value&&(s.stops[e.key]=e.value);continue}}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON(t){return{version:Ae(t.version)?globalThis.String(t.version):"",stops:(e=t.stops,"object"==typeof e&&null!==e?Object.entries(t.stops).reduce(((t,[e,r])=>(t[globalThis.Number(e)]=Te.fromJSON(r),t)),{}):{})};var e},toJSON(t){const e={};if(""!==t.version&&(e.version=t.version),t.stops){const r=Object.entries(t.stops);r.length>0&&(e.stops={},r.forEach((([t,r])=>{e.stops[t]=Te.toJSON(r)})))}return e},create:t=>Ee.fromPartial(null!=t?t:{}),fromPartial(t){var e,r;const n={version:"",stops:{}};return n.version=null!==(e=t.version)&&void 0!==e?e:"",n.stops=Object.entries(null!==(r=t.stops)&&void 0!==r?r:{}).reduce(((t,[e,r])=>(void 0!==r&&(t[globalThis.Number(e)]=Te.fromPartial(r)),t)),{}),n}};const Ie={encode:(t,e=new I)=>(0!==t.key&&e.uint32(8).uint32(t.key),void 0!==t.value&&Te.encode(t.value,e.uint32(18).fork()).join(),e),decode(t,e){const r=t instanceof A?t:new A(t),n=void 0===e?r.len:r.pos+e,s={key:0,value:void 0};for(;r.pos<n;){const t=r.uint32();switch(t>>>3){case 1:if(8!==t)break;s.key=r.uint32();continue;case 2:if(18!==t)break;s.value=Te.decode(r,r.uint32());continue}if(4==(7&t)||0===t)break;r.skip(7&t)}return s},fromJSON:t=>({key:Ae(t.key)?globalThis.Number(t.key):0,value:Ae(t.value)?Te.fromJSON(t.value):void 0}),toJSON(t){const e={};return 0!==t.key&&(e.key=Math.round(t.key)),void 0!==t.value&&(e.value=Te.toJSON(t.value)),e},create:t=>Ie.fromPartial(null!=t?t:{}),fromPartial(t){var e;const r={key:0,value:void 0};return r.key=null!==(e=t.key)&&void 0!==e?e:0,r.value=void 0!==t.value&&null!==t.value?Te.fromPartial(t.value):void 0,r}};function Ae(t){return null!=t}const Se="0.0.2",we=t=>{const e={version:Se,stops:{}};return t.forEach(((t,r)=>{var n;e.stops[r]={name:(n=t).name,sourceStopId:n.sourceStopId,lat:n.lat,lon:n.lon,children:n.children,parent:n.parent,locationType:_e(n.locationType),platform:n.platform}})),e},be=t=>{if(t.version!==Se)throw new Error(`Unsupported stopMap version ${t.version}`);const e=new Map;return Object.entries(t.stops).forEach((([t,r])=>{const n=parseInt(t,10);var s;e.set(n,{id:n,sourceStopId:(s=r).sourceStopId,name:s.name,lat:s.lat,lon:s.lon,children:s.children,parent:s.parent,locationType:Re(s.locationType),platform:s.platform})})),e},Re=t=>{switch(t){case ge.SIMPLE_STOP_OR_PLATFORM:return"SIMPLE_STOP_OR_PLATFORM";case ge.STATION:return"STATION";case ge.ENTRANCE_EXIT:return"ENTRANCE_EXIT";case ge.GENERIC_NODE:return"GENERIC_NODE";case ge.BOARDING_AREA:return"BOARDING_AREA";case ge.UNRECOGNIZED:throw new Error("Unrecognized protobuf location type.")}},_e=t=>{switch(t){case"SIMPLE_STOP_OR_PLATFORM":return ge.SIMPLE_STOP_OR_PLATFORM;case"STATION":return ge.STATION;case"ENTRANCE_EXIT":return ge.ENTRANCE_EXIT;case"GENERIC_NODE":return ge.GENERIC_NODE;case"BOARDING_AREA":return ge.BOARDING_AREA}};class Ne{constructor(t){var e;this.stopsMap=t,this.sourceStopsMap=new Map;for(const[e,r]of t.entries())this.sourceStopsMap.set(r.sourceStopId,e);this.textIndex=new me({fields:["name"],storeFields:["id"],searchOptions:{prefix:!0,fuzzy:.2},processTerm:ve});const r=new Map;for(const[n,s]of t.entries()){const t=null!==(e=s.parent)&&void 0!==e?e:n;r.has(t)||r.set(t,{id:t,name:s.parent?this.stopsMap.get(s.parent).name:s.name})}const n=Array.from(r.values());((t,e)=>{for(const r of e)oe(t,r)})(this.textIndex,n),this.stopPoints=Array.from(this.stopsMap.entries()).filter((([,t])=>!(!t.lat||!t.lon))).map((([t,e])=>({id:t,lat:e.lat,lon:e.lon}))),this.geoIndex=new wt(this.stopPoints.length);for(const{lat:t,lon:e}of this.stopPoints)this.geoIndex.add(e,t);this.geoIndex.finish()}static fromData(t){const e=new A(t),r=Ee.decode(e);return new Ne(be(r))}serialize(){const t=we(this.stopsMap),e=new I;return Ee.encode(t,e),e.finish()}size(){return this.stopsMap.size}findStopsByName(t,e=5){return((t,e,r={})=>{const{searchOptions:n}=t._options,s={...n,...r},o=pe(t,e,r),i=[];for(const[e,{score:r,terms:n,match:a}]of o){const o=n.length||1,u={id:t._documentIds.get(e),score:r*o,terms:Object.keys(a),queryTerms:n,match:a};Object.assign(u,t._storedFields.get(e)),(null==s.filter||s.filter(u))&&i.push(u)}return e===fe&&null==s.boostDocument||i.sort(Ht),i})(this.textIndex,t).map((t=>this.stopsMap.get(t.id))).slice(0,e)}findStopsByLocation(t,e,r=5,n=.5){const s=function(t,e,r,n=1/0,s=1/0){let o=1;const i=[];void 0===n&&(n=1/0),void 0!==s&&(o=Et(s/6371));const a=new mt([],Tt);let u={left:0,right:t.ids.length-1,axis:0,minLng:-180,minLat:-90,maxLng:180,maxLat:90};const c=Math.cos(r*gt);for(;u;){const s=u.right,l=u.left;if(s-l<=t.nodeSize)for(let n=l;n<=s;n++){const s=t.ids[n];{const o=At(e,r,t.coords[2*n],t.coords[2*n+1],c);a.push({id:s,dist:o})}}else{const n=l+s>>1,o=t.coords[2*n],i=t.coords[2*n+1],f=t.ids[n];{const t=At(e,r,o,i,c);a.push({id:f,dist:t})}const d=(u.axis+1)%2,h={left:l,right:n-1,axis:d,minLng:u.minLng,minLat:u.minLat,maxLng:0===u.axis?o:u.maxLng,maxLat:1===u.axis?i:u.maxLat,dist:0},p={left:n+1,right:s,axis:d,minLng:0===u.axis?o:u.minLng,minLat:1===u.axis?i:u.minLat,maxLng:u.maxLng,maxLat:u.maxLat,dist:0};h.dist=yt(e,r,c,h),p.dist=yt(e,r,c,p),a.push(h),a.push(p)}for(;a.length&&null!=a.peek().id;){const t=a.pop();if(t.dist>o)return i;if(i.push(t.id),i.length===n)return i}u=a.pop()}return i}(this.geoIndex,e,t,r,n).map((t=>{const e=this.stopPoints[t];return this.stopsMap.get(e.id)}));return s}findStopById(t){return this.stopsMap.get(t)}findStopBySourceStopId(t){const e=this.sourceStopsMap.get(t);if(void 0!==e)return this.findStopById(e)}equivalentStops(t){var e,r;const n=this.sourceStopsMap.get(t);if(void 0===n)return[];const s=this.stopsMap.get(n);if(!s)return[];const o=s.parent?null!==(r=null===(e=this.stopsMap.get(s.parent))||void 0===e?void 0:e.children)&&void 0!==r?r:[]:s.children;return Array.from(new Set([n,...o])).map((t=>this.stopsMap.get(t)))}}export{e as Duration,t as Plotter,lt as Query,dt as Result,ft as Route,pt as Router,Ne as StopsIndex,V as Time,ct as Timetable};
|
|
2
2
|
//# sourceMappingURL=router.esm.js.map
|