UNPKG

gtfs-to-html

Version:

Build human readable transit timetables as HTML, PDF or CSV from GTFS

2 lines (1 loc) 9.77 kB
!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).Pbf={})}(this,function(t){"use strict";const e=4294967296,i=1/e,s="undefined"==typeof TextDecoder?null:new TextDecoder("utf-8");function r(t,e,i){return i?4294967296*e+(t>>>0):4294967296*(e>>>0)+(t>>>0)}function h(t,e,i){const s=e<=16383?1:e<=2097151?2:e<=268435455?3:Math.floor(Math.log(e)/(7*Math.LN2));i.realloc(s),i.buf.copyWithin(t+s,t,i.pos)}function o(t,e){const i=t.length;let s=e.buf,r=e.pos,h=e.length;for(let o=0;o<i;o++){let i=t[o];if(i<0||r+10>h)e.pos=r,e.writeVarint(i),s=e.buf,r=e.pos,h=e.length;else{for(;i>127;)s[r++]=i%128|128,i=Math.floor(i/128);s[r++]=i}}e.pos=r}function n(t,e){for(let i=0;i<t.length;i++)e.writeSVarint(t[i])}function a(t,e){for(let i=0;i<t.length;i++)e.writeFloat(t[i])}function d(t,e){for(let i=0;i<t.length;i++)e.writeDouble(t[i])}function l(t,e){for(let i=0;i<t.length;i++)e.writeBoolean(t[i])}function u(t,e){for(let i=0;i<t.length;i++)e.writeFixed32(t[i])}function f(t,e){for(let i=0;i<t.length;i++)e.writeSFixed32(t[i])}function p(t,e){for(let i=0;i<t.length;i++)e.writeFixed64(t[i])}function w(t,e){for(let i=0;i<t.length;i++)e.writeSFixed64(t[i])}t.PbfReader=class{constructor(t){this.buf=ArrayBuffer.isView(t)?t:new Uint8Array(t),this.dataView=new DataView(this.buf.buffer,this.buf.byteOffset,this.buf.byteLength),this.pos=0,this.type=0,this._valueStart=-1,this.length=this.buf.length}readFields(t,e,i=this.length){let s;for(;s=this.nextField(i);)t(s,e,this);return e}readMessage(t,e){return this.readFields(t,e,this.readVarint()+this.pos)}readFixed32(){const t=this.dataView.getUint32(this.pos,!0);return this.pos+=4,t}readSFixed32(){const t=this.dataView.getInt32(this.pos,!0);return this.pos+=4,t}readFixed64(){const t=this.dataView.getUint32(this.pos,!0)+this.dataView.getUint32(this.pos+4,!0)*e;return this.pos+=8,t}readSFixed64(){const t=this.dataView.getUint32(this.pos,!0)+this.dataView.getInt32(this.pos+4,!0)*e;return this.pos+=8,t}readFloat(){const t=this.dataView.getFloat32(this.pos,!0);return this.pos+=4,t}readDouble(){const t=this.dataView.getFloat64(this.pos,!0);return this.pos+=8,t}readVarint(t){const e=this.buf,i=e[this.pos++];if(i<128)return i;let s,h=127&i;return s=e[this.pos++],h|=(127&s)<<7,s<128?h:(s=e[this.pos++],h|=(127&s)<<14,s<128?h:(s=e[this.pos++],h|=(127&s)<<21,s<128?h:(s=e[this.pos],h|=(15&s)<<28,function(t,e,i){const s=i.buf;let h,o;if(o=s[i.pos++],h=(112&o)>>4,o<128)return r(t,h,e);if(o=s[i.pos++],h|=(127&o)<<3,o<128)return r(t,h,e);if(o=s[i.pos++],h|=(127&o)<<10,o<128)return r(t,h,e);if(o=s[i.pos++],h|=(127&o)<<17,o<128)return r(t,h,e);if(o=s[i.pos++],h|=(127&o)<<24,o<128)return r(t,h,e);if(o=s[i.pos++],h|=(1&o)<<31,o<128)return r(t,h,e);throw new Error("Expected varint not more than 10 bytes")}(h,t,this))))}readSVarint(){const t=this.readVarint();return t%2==1?(t+1)/-2:t/2}readBoolean(){return Boolean(this.readVarint())}readString(){const t=this.readVarint()+this.pos,e=this.pos;return this.pos=t,t-e>=12&&s?s.decode(this.buf.subarray(e,t)):function(t,e,i){let s="",r=e;for(;r<i;){const e=t[r];let h,o,n,a=null,d=e>239?4:e>223?3:e>191?2:1;if(r+d>i)break;1===d?e<128&&(a=e):2===d?(h=t[r+1],128==(192&h)&&(a=(31&e)<<6|63&h,a<=127&&(a=null))):3===d?(h=t[r+1],o=t[r+2],128==(192&h)&&128==(192&o)&&(a=(15&e)<<12|(63&h)<<6|63&o,(a<=2047||a>=55296&&a<=57343)&&(a=null))):4===d&&(h=t[r+1],o=t[r+2],n=t[r+3],128==(192&h)&&128==(192&o)&&128==(192&n)&&(a=(15&e)<<18|(63&h)<<12|(63&o)<<6|63&n,(a<=65535||a>=1114112)&&(a=null))),null===a?(a=65533,d=1):a>65535&&(a-=65536,s+=String.fromCharCode(a>>>10&1023|55296),a=56320|1023&a),s+=String.fromCharCode(a),r+=d}return s}(this.buf,e,t)}readBytes(){const t=this.readVarint()+this.pos,e=this.buf.subarray(this.pos,t);return this.pos=t,e}readPackedVarint(t=[],e){const i=this.readPackedEnd();for(;this.pos<i;)t.push(this.readVarint(e));return t}readPackedSVarint(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readSVarint());return t}readPackedBoolean(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readBoolean());return t}readPackedFloat(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readFloat());return t}readPackedDouble(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readDouble());return t}readPackedFixed32(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readFixed32());return t}readPackedSFixed32(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readSFixed32());return t}readPackedFixed64(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readFixed64());return t}readPackedSFixed64(t=[]){const e=this.readPackedEnd();for(;this.pos<e;)t.push(this.readSFixed64());return t}readPackedEnd(){return 2===this.type?this.readVarint()+this.pos:this.pos+1}nextField(t=this.length){if(this.pos===this._valueStart&&this.skip(this.type),this.pos>=t)return 0;const e=this.readVarint();return this.type=7&e,this._valueStart=this.pos,e>>>3}skip(t){const e=7&t;if(0===e)for(;this.buf[this.pos++]>127;);else if(2===e)this.pos=this.readVarint()+this.pos;else if(5===e)this.pos+=4;else{if(1!==e)throw new Error(`Unimplemented type: ${e}`);this.pos+=8}}},t.PbfWriter=class{constructor(t=new Uint8Array(16)){this.buf=ArrayBuffer.isView(t)?t:new Uint8Array(t),this.dataView=new DataView(this.buf.buffer,this.buf.byteOffset,this.buf.byteLength),this.pos=0,this.length=this.buf.length}writeTag(t,e){this.writeVarint(t<<3|e)}realloc(t){let e=this.length||16;for(;e<this.pos+t;)e*=2;if(e!==this.length){const t=new Uint8Array(e);t.set(this.buf),this.buf=t,this.dataView=new DataView(t.buffer),this.length=e}}finish(){return this.length=this.pos,this.pos=0,this.buf.subarray(0,this.length)}writeFixed32(t){this.realloc(4),this.dataView.setInt32(this.pos,t,!0),this.pos+=4}writeSFixed32(t){this.realloc(4),this.dataView.setInt32(this.pos,t,!0),this.pos+=4}writeFixed64(t){this.realloc(8),this.dataView.setInt32(this.pos,-1&t,!0),this.dataView.setInt32(this.pos+4,Math.floor(t*i),!0),this.pos+=8}writeSFixed64(t){this.realloc(8),this.dataView.setInt32(this.pos,-1&t,!0),this.dataView.setInt32(this.pos+4,Math.floor(t*i),!0),this.pos+=8}writeVarint(t){if((t=+t||0)>=0&&t<128)return this.pos>=this.length&&this.realloc(1),void(this.buf[this.pos++]=t);t>268435455||t<0?function(t,e){let i,s;t>=0?(i=t%4294967296|0,s=t/4294967296|0):(i=~(-t%4294967296),s=~(-t/4294967296),4294967295^i?i=i+1|0:(i=0,s=s+1|0));if(t>=0x10000000000000000||t<-0x10000000000000000)throw new Error("Given varint doesn't fit into 10 bytes");e.realloc(10),function(t,e,i){i.buf[i.pos++]=127&t|128,t>>>=7,i.buf[i.pos++]=127&t|128,t>>>=7,i.buf[i.pos++]=127&t|128,t>>>=7,i.buf[i.pos++]=127&t|128,t>>>=7,i.buf[i.pos]=127&t}(i,0,e),function(t,e){const i=(7&t)<<4;if(e.buf[e.pos++]|=i|((t>>>=3)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;if(e.buf[e.pos++]=127&t|((t>>>=7)?128:0),!t)return;e.buf[e.pos++]=127&t}(s,e)}(t,this):(this.realloc(4),this.buf[this.pos++]=127&t|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=127&(t>>>=7)|(t>127?128:0),t<=127||(this.buf[this.pos++]=t>>>7&127))))}writeSVarint(t){this.writeVarint(t<0?2*-t-1:2*t)}writeBoolean(t){this.writeVarint(+t)}writeString(t){t=String(t),this.realloc(4*t.length),this.pos++;const e=this.pos;this.pos=function(t,e,i){for(let s,r,h=0;h<e.length;h++){if(s=e.charCodeAt(h),s>55295&&s<57344){if(!r){s>56319||h+1===e.length?(t[i++]=239,t[i++]=191,t[i++]=189):r=s;continue}if(s<56320){t[i++]=239,t[i++]=191,t[i++]=189,r=s;continue}s=r-55296<<10|s-56320|65536,r=null}else r&&(t[i++]=239,t[i++]=191,t[i++]=189,r=null);s<128?t[i++]=s:(s<2048?t[i++]=s>>6|192:(s<65536?t[i++]=s>>12|224:(t[i++]=s>>18|240,t[i++]=s>>12&63|128),t[i++]=s>>6&63|128),t[i++]=63&s|128)}return i}(this.buf,t,this.pos);const i=this.pos-e;i>=128&&h(e,i,this),this.pos=e-1,this.writeVarint(i),this.pos+=i}writeFloat(t){this.realloc(4),this.dataView.setFloat32(this.pos,t,!0),this.pos+=4}writeDouble(t){this.realloc(8),this.dataView.setFloat64(this.pos,t,!0),this.pos+=8}writeBytes(t){const e=t.length;this.writeVarint(e),this.realloc(e),this.buf.set(t,this.pos),this.pos+=e}writeRawMessage(t,e){this.pos++;const i=this.pos;t(e,this);const s=this.pos-i;s>=128&&h(i,s,this),this.pos=i-1,this.writeVarint(s),this.pos+=s}writeMessage(t,e,i){this.writeTag(t,2),this.writeRawMessage(e,i)}writePackedVarint(t,e){e.length&&this.writeMessage(t,o,e)}writePackedSVarint(t,e){e.length&&this.writeMessage(t,n,e)}writePackedBoolean(t,e){e.length&&this.writeMessage(t,l,e)}writePackedFloat(t,e){e.length&&this.writeMessage(t,a,e)}writePackedDouble(t,e){e.length&&this.writeMessage(t,d,e)}writePackedFixed32(t,e){e.length&&this.writeMessage(t,u,e)}writePackedSFixed32(t,e){e.length&&this.writeMessage(t,f,e)}writePackedFixed64(t,e){e.length&&this.writeMessage(t,p,e)}writePackedSFixed64(t,e){e.length&&this.writeMessage(t,w,e)}writeBytesField(t,e){this.writeTag(t,2),this.writeBytes(e)}writeFixed32Field(t,e){this.writeTag(t,5),this.writeFixed32(e)}writeSFixed32Field(t,e){this.writeTag(t,5),this.writeSFixed32(e)}writeFixed64Field(t,e){this.writeTag(t,1),this.writeFixed64(e)}writeSFixed64Field(t,e){this.writeTag(t,1),this.writeSFixed64(e)}writeVarintField(t,e){this.writeTag(t,0),this.writeVarint(e)}writeSVarintField(t,e){this.writeTag(t,0),this.writeSVarint(e)}writeStringField(t,e){this.writeTag(t,2),this.writeString(e)}writeFloatField(t,e){this.writeTag(t,5),this.writeFloat(e)}writeDoubleField(t,e){this.writeTag(t,1),this.writeDouble(e)}writeBooleanField(t,e){this.writeVarintField(t,+e)}}});