minotor 11.2.3 → 11.3.0

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