/* JBB Binary Bundle Loader - https://github.com/wavesoft/jbb */ var JBB=JBB||{};JBB.BinaryLoader=function(t){function r(i){if(e[i])return e[i].exports;var s=e[i]={exports:{},id:i,loaded:!1};return t[i].call(s.exports,s,s.exports,r),s.loaded=!0,s.exports}var e={};return r.m=t,r.c=e,r.p="",r(0)}([function(t,r,e){"use strict";function i(t,r){var e=t.readStringLT(),i=new Blob([t.readTypedArray(A.UINT8,r)],{type:e});return URL.createObjectURL(i)}function s(t,r,e){var s=0,n="";switch(r){case 0:s=t.u8[t.i8++];break;case 1:s=t.u16[t.i16++];break;case 2:s=t.u32[t.i32++];break;case 3:s=t.f64[t.i64++]}if(0===e)return n=String.fromCharCode.apply(null,t.readTypedArray(A.UINT8,s));if(1===e)return n=String.fromCharCode.apply(null,t.readTypedArray(A.UINT16,s));if(2===e){var a=document.createElement("img");return a.src=i(t,s),a}if(4===e){var a=document.createElement("script");return a.src=i(t,s),a}if(7===e)return i(t,s);throw new w.AssertError("Unknown buffer type #"+e+"!")}function n(t,r,e){if(!(32&e&&32!==(48&e))){var i=e;32&e&&(i=t.u8[t.i8++]|(15&e)<<8);var s=t.profile.decode(i);if(void 0===s)throw new w.AssertError("Could not found known object entity #"+i+"!");var n=s.create();t.iref_table.push(n);var a=l(t,r);return s.init(n,a,1,0),n}if(56!==(60&e)){if(48===(56&e)){var i=(7&e)<<8|t.u8[t.i8++],o=l(t,r),h=t.factory_plain[i];if(void 0===h)throw new w.AssertError("Could not found simple object signature with id #"+i+"!");return h(o)}throw new w.AssertError("Unexpected object opcode 0x"+e.toString(16)+"!")}var u=3&e;switch(u){case 0:var f=t.f64[t.i64++];10*t.s8[t.i8++];return new Date(f);default:throw new w.AssertError("Unknown primitive object with POID #"+u+"!")}}function a(t,r,e,i){for(var s=new m[_.FROM[i]](e),n=t.readFloat64(),a=t.readTypedArray(_.TO[i],e),o=0;e>o;++o)s[o]=pivot+a[o]*n;return s}function o(t,r,e,i){var s=I.FROM[i],n=new m[s](e),a=0;switch(s){case 0:a=t.u8[t.i8++];break;case 1:a=t.s8[t.i8++];break;case 2:a=t.u16[t.i16++];break;case 3:a=t.s16[t.i16++];break;case 4:a=t.u32[t.i32++];break;case 5:a=t.s32[t.i32++];break;case 6:a=t.f32[t.i32++];break;case 7:a=t.f64[t.i64++]}var o=t.readTypedArray(I.TO[i],e-1);n[0]=a;for(var h=0,u=o.length;u>h;++h)a+=o[h],n[h+1]=a;return n}function h(t,r){var e=t.u16[t.i16++],i=t.signature_table[e],s=t.factory_plain_bulk[e];if(void 0===s)throw new w.AssertError("Could not found simple object signature with id #"+e+"!");for(var n=l(t,r),a=n.length/i.length,o=new Array(a),h=0;a>h;++h)o[h]=s(n,h);return o}function u(t,r,e){var i=t.u16[t.i16++],s=t.profile.decode(i),n=s.props,a=0,o=[],h=0,u=0,f=0,c=null,p=0,d=0,v=[],b=[];for(f=65536>e?t.u16[t.i16++]:t.u32[t.i32++],o=Array(f),h=0;f>h;++h)t.iref_table.push(o[h]=s.create());if(f){if(v=l(t,r),void 0===v.length)throw new w.AssertError("Decoded known bulk primitive is not array!");a=v.length/n}var y=new Array(e),g=0,T=void 0;for(h=0;e>h;)if(d=t.u8[t.i8++],(128&d)===k.LREF_7)u=127&d,y[h++]=T=b[u];else if((192&d)===k.DEFINE){for(u=(63&d)+1,p=0;u>p;p++)c=o[g],s.init(c,v,a,g),y[h++]=c,g++;T=c}else if((224&d)===k.REPEAT)for(u=(31&d)+1,p=0;u>p;p++)y[h++]=T;else if((240&d)===k.IREF){if(u=(15&d)<<16|t.u16[t.i16++],u>=t.iref_table.length)throw new w.IRefError("Invalid IREF #"+u+"!");y[h++]=T=t.iref_table[u],b.push(t.iref_table[u])}else if((248&d)===k.LREF_11)u=(7&d)<<8|t.u8[t.i8++],y[h++]=T=b[u];else if(d===k.LREF_16)u=t.u16[t.i16++],y[h++]=T=b[u];else if(d===k.XREF){if(u=t.readStringLT(),void 0===r[u])throw new w.XRefError("Cannot import undefined external reference "+u+"!");y[h++]=T=r[u]}return y}function f(t,r,e,i){for(var s,n,a=t.u8[t.i8++],o=[],h=0,u=!0,f=0,l=0,p=0,d=0,v=0,b=0;e>h;){if(i)if(64===(240&a)){switch(p=1&a,d=a>>1&7,v=p?t.u32[t.i32++]:t.u16[t.i16++],u&&(n=new m[d](e),u=!1),d){case 0:b=t.u8[t.i8++];break;case 1:b=t.s8[t.i8++];break;case 2:b=t.u16[t.i16++];break;case 3:b=t.s16[t.i16++];break;case 4:b=t.u32[t.i32++];break;case 5:b=t.s32[t.i32++];break;case 6:b=t.f32[t.i32++];break;case 7:b=t.f64[t.i64++]}n.fill(b,h,h+v),h+=v}else{if(s=c(t,r,a),void 0===s.length)throw new w.AssertError("Encountered non-array chunk as part of chunked array!");if(u&&(n=new s.constructor(e),u=!1),!(s instanceof n.constructor))throw new w.AssertError("Got is_numeric flag, but chunks are not of the same type (op was "+a+"!");n.set(s,h),h+=s.length}else{if(s=c(t,r,a),void 0===s.length)throw new w.AssertError("Encountered non-array chunk as part of chunked array!");for(u&&(o=new Array(e),u=!1),f=0,l=s.length;l>f;f++,h++)o[h]=s[f]}if(!(e>h))break;a=t.u8[t.i8++]}return i?n:o}function c(t,r,e){var i,s=0,n=0,c=0,p=0,d=[];if(e=255&e,110===e)return h(t,r);if(111===e){for(p=t.u8[t.i8++],d[p-1]=null,s=0;p>s;++s)d[s]=l(t,r);return d}if(126===e)return[];if(127===e)throw new w.AssertError("Encountered PRIM_CHUNK_END outside of chunked array!");if(0===(224&e)){c=1&e,n=e>>1&15,p=c?t.u32[t.i32++]:t.u16[t.i16++],i=t.readTypedArray(E.TO[n],p);var v=new m[E.FROM[n]](i);return v}if(32===(240&e))return c=1&e,n=e>>1&7,p=c?t.u32[t.i32++]:t.u16[t.i16++],o(t,r,p,n);if(48===(240&e))return c=1&e,n=e>>1&7,p=c?t.u32[t.i32++]:t.u16[t.i16++],a(t,r,p,n);if(64===(240&e)){switch(c=1&e,n=e>>1&7,p=c?t.u32[t.i32++]:t.u16[t.i16++],n){case 0:i=t.u8[t.i8++];break;case 1:i=t.s8[t.i8++];break;case 2:i=t.u16[t.i16++];break;case 3:i=t.s16[t.i16++];break;case 4:i=t.u32[t.i32++];break;case 5:i=t.s32[t.i32++];break;case 6:i=t.f32[t.i32++];break;case 7:i=t.f64[t.i64++]}var v=new m[n](p);for(s=0;p>s;++s)v[s]=i;return v}if(80===(240&e))return c=1&e,n=e>>1&7,p=c?t.u32[t.i32++]:t.u16[t.i16++],d=t.readTypedArray(n,p);if(96===(248&e))return n=7&e,p=t.u8[t.i8++],d=t.readTypedArray(n,p);if(104===(254&e)){for(c=1&e,p=c?t.u32[t.i32++]:t.u16[t.i16++],i=l(t,r),d[p-1]=null,s=0;p>s;s++)d[s]=i;return d}if(106===(254&e)){for(c=1&e,p=c?t.u32[t.i32++]:t.u16[t.i16++],d[p-1]=null,s=0;p>s;++s)d[s]=l(t,r);return d}if(120===(252&e))return c=1&e,n=e>>1&1,p=c?t.u32[t.i32++]:t.u16[t.i16++],f(t,r,p,n);if(124===(254&e))return c=1&e,p=c?t.u32[t.i32++]:t.u16[t.i16++],u(t,r,p);throw new w.AssertError("Unknown array op-code 0x"+e.toString(16)+" at offset @"+(t.i8-t.ofs8)+"!")}function l(t,r){var e=t.u8[t.i8++];if(0===(128&e))return c(t,r,127&e);if(128===(192&e))return n(t,r,63&e);if(192===(224&e))return s(t,(24&e)>>3,7&e);if(224===(240&e)){var i=t.u16[t.i16++];if(i=(15&e)<<16|i,i>=t.iref_table.length)throw new w.IRefError("Invalid IREF #"+i+"!");return t.iref_table[i]}if(240===(248&e))switch(7&e){case 0:return t.u8[t.i8++];case 1:return t.s8[t.i8++];case 2:return t.u16[t.i16++];case 3:return t.s16[t.i16++];case 4:return t.u32[t.i32++];case 5:return t.s32[t.i32++];case 6:return t.f32[t.i32++];case 7:return t.f64[t.i64++]}else{if(248===(252&e))return U[3&e];if(252===(254&e))return N[2&e];if(254===(255&e)){var a=t.readStringLT();if(void 0===r[a])throw new w.XRefError("Cannot import undefined external reference "+a+"!");return r[a]}if(255===(255&e))throw new w.AssertError("Encountered RESERVED primitive operator!")}}function p(t,r){for(;!t.eof();){var e=t.u8[t.i8++];switch(e){case 248:var i=t.prefix+t.readStringLT();r[i]=l(t,r);break;default:throw new w.AssertError("Unknown control operator 0x"+e.toString(16)+" at @"+t.i8+"!")}}}function d(t,r,e){var i=t.length,s=Array(i),n=!1;return t.forEach(function(a,o){var h=new XMLHttpRequest;h.open("GET",t[o]),h.responseType="arraybuffer",h.send(),h.addEventListener("progress",function(t){t.lengthComputable&&r.update(h,t.loaded,t.total)}),h.addEventListener("readystatechange",function(){if(4===h.readyState)if(200===h.status)s[o]=h.response,0===--i&&(r.complete(),e(null));else{if(n)return;n=!0,r.complete(),e("Error loading "+t[o]+": "+h.statusText)}})}),s}var v=e(1),b=e(2),y=e(3),w=e(4);const g=0,T=1,A={UINT8:0,INT8:1,UINT16:2,INT16:3,UINT32:4,INT32:5,FLOAT32:6,FLOAT64:7},E={FROM:[A.UINT16,A.INT16,A.UINT32,A.INT32,A.UINT32,A.INT32,A.FLOAT32,A.FLOAT32,A.FLOAT32,A.FLOAT32,A.FLOAT64,A.FLOAT64,A.FLOAT64,A.FLOAT64,A.FLOAT64],TO:[A.UINT8,A.INT8,A.UINT8,A.INT8,A.UINT16,A.INT16,A.UINT8,A.INT8,A.UINT16,A.INT16,A.UINT8,A.INT8,A.UINT16,A.INT16,A.FLOAT32]},I={FROM:[A.UINT16,A.INT16,A.UINT32,A.INT32,A.UINT32,A.INT32],TO:[A.INT8,A.INT8,A.INT8,A.INT8,A.INT16,A.INT16]},_={FROM:[A.FLOAT32,A.FLOAT32,A.FLOAT64,A.FLOAT64],TO:[A.INT8,A.INT16,A.INT8,A.INT16]},m=[Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Float32Array,Float64Array],k=([A.UINT16,A.UINT32],[A.UINT8,A.UINT16,A.UINT32,A.FLOAT64],{LREF_7:0,LREF_11:240,LREF_16:254,IREF:224,XREF:255,DEFINE:128,REPEAT:192}),U=[void 0,null,!1,!0],N=[NaN];var F=function(t,r){"object"==typeof t&&(r=t,t=""),this.database=r||{},this.baseDir=t||"",this.queuedRequests=[],this.profile=new b,this.progressManager=new y};F.prototype={constructor:F,addProfile:function(t){this.profile.add(t)},add:function(t,r){var e,i="";this.baseDir&&(i=this.baseDir+"/");var s=t.split("?"),n="",a=[];if(s.length>1&&(n="?"+s[1]),".jbbp"===s[0].substr(s[0].length-5).toLowerCase()){var e=i+s[0].substr(0,s[0].length-5);a=[e+".jbbp"+n,e+"_b16.jbbp"+n,e+"_b32.jbbp"+n,e+"_b64.jbbp"+n]}else{var t=s[0];".jbb"!=t.substr(t.length-4)&&(t+=".jbb"),a=[i+t+n]}var o={callback:r,status:g,buffer:void 0,url:a};this.queuedRequests.push(o)},addByBuffer:function(t,r){var e={callback:r,status:T,buffer:t,url:void 0};this.queuedRequests.push(e)},addProgressHandler:function(t){this.progressManager.addHandler(t)},removeProgressHandler:function(t){this.progressManager.removeHandler(t)},load:function(t){this.__process(t)},__process:function(t){var r=this;if(t||(t=function(){}),0===this.queuedRequests.length)return void t(null,this.database);for(var e=!1,i=0;ie;++e)0!==e&&(r+=","),r+="p[i+c*"+e+"]";return new Function("p","i","var c=p.length/"+t+";return ["+r+"]")}var i=function(t,r){this.profile=r,this.prefix="",this.sparse=t instanceof Array;var i,s,n,a=32;if(this.sparse?(this.u8=new Uint8Array(t[0]),this.s8=new Int8Array(t[0]),this.u16=new Uint16Array(t[1]),this.s16=new Int16Array(t[1]),this.u32=new Uint32Array(t[2]),this.s32=new Int32Array(t[2]),this.f32=new Float32Array(t[2]),this.f64=new Float64Array(t[3]),i=new Uint16Array(t[0],0,a/2),s=new Uint32Array(t[0],0,a/4),n=t[0].byteLength):(this.u8=new Uint8Array(t),this.s8=new Int8Array(t),this.u16=new Uint16Array(t),this.s16=new Int16Array(t),this.u32=new Uint32Array(t),this.s32=new Int32Array(t),this.f32=new Float32Array(t),this.f64=new Float64Array(t),i=new Uint16Array(t),s=new Uint32Array(t),n=t.byteLength),this.magic=i[0],this.table_id=i[1],this.version=i[2],this.table_count=i[3],this.ver_major=255&this.version,this.ver_minor=(65280&this.version)>>8,this.max64=s[2],this.max32=s[3],this.max16=s[4],this.max8=s[5],this.lenST=s[6],this.lenOT=s[7],12610==this.magic)throw{name:"EndianessError",message:"Unfortunately the JBB format is currently only compatible with Little-Endian CPUs",toString:function(){return this.name+": "+this.message}};if(16945!=this.magic)throw{name:"DecodingError",message:"This does not look like a JBB archive! (Magic is 0x"+this.magic.toString(16)+")",toString:function(){return this.name+": "+this.message}};if(258!=this.version)throw{name:"DecodingError",message:"Unsupported bundle version v"+this.ver_minor+"."+this.ver_minor,toString:function(){return this.name+": "+this.message}};this.sparse?(this.i64=0,this.i32=0,this.i16=0,this.i8=a,this.iEnd=this.i8+this.max8-this.lenST,this.ofs8=this.i8,this.ofs16=this.i16,this.ofs32=this.i32,this.ofs64=this.i64):(this.i64=a,this.i32=this.i64+this.max64,this.i16=this.i32+this.max32,this.i8=this.i16+this.max16,this.iEnd=this.i8+this.max8-this.lenST,this.ofs8=this.i8,this.ofs16=this.i16,this.ofs32=this.i32,this.ofs64=this.i64,this.i16/=2,this.i32/=4,this.i64/=8);var o=[];if(this.table_count<=1)0!==this.table_id&&o.push(this.table_id);else{if(0!==this.table_id)throw{name:"DecodingError",message:"Invalid header data",toString:function(){return this.name+": "+this.message}};for(var h=0;h0){for(var c=this.i8+this.max8,h=c-this.lenST;c>h;++h){var l=this.u8[h];0===l?(this.string_table.push(u),u="",f=!1):(u+=String.fromCharCode(l),f=!0)}f&&this.string_table.push(u)}var p=[],d=0,v=!1;if(this.signature_table=[],this.lenOT>0){for(var c=2*this.i16+this.max16,h=c-this.lenOT;c>h;h+=2){var l=this.u16[h/2];d--?p.push(this.string_table[l]):(v&&this.signature_table.push(p),p=[],d=l,v=!0)}v&&this.signature_table.push(p)}this.sparse?this.readTypedArray=function(r,e){var i=this.i8,s=2*this.i16,n=4*this.i32,a=8*this.i64;switch(r){case 0:return this.i8+=e,new Uint8Array(t[0],i,e);case 1:return this.i8+=e,new Int8Array(t[0],i,e);case 2:return this.i16+=e,new Uint16Array(t[1],s,e);case 3:return this.i16+=e,new Int16Array(t[1],s,e);case 4:return this.i32+=e,new Uint32Array(t[2],n,e);case 5:return this.i32+=e,new Int32Array(t[2],n,e);case 6:return this.i32+=e,new Float32Array(t[2],n,e);case 7:return this.i64+=e,new Float64Array(t[3],a,e)}}:this.readTypedArray=function(r,e){var i=this.i8,s=2*this.i16,n=4*this.i32,a=8*this.i64;switch(r){case 0:return this.i8+=e,new Uint8Array(t,i,e);case 1:return this.i8+=e,new Int8Array(t,i,e);case 2:return this.i16+=e,new Uint16Array(t,s,e);case 3:return this.i16+=e,new Int16Array(t,s,e);case 4:return this.i32+=e,new Uint32Array(t,n,e);case 5:return this.i32+=e,new Int32Array(t,n,e);case 6:return this.i32+=e,new Float32Array(t,n,e);case 7:return this.i64+=e,new Float64Array(t,a,e)}},this.factory_plain=[],this.factory_plain_bulk=[];for(var h=0;hT;++T)w+="'"+b[T]+"': values["+T+"],",g+="'"+b[T]+"': values[i+c*"+T+"],";w+="}",g+="}",this.factory_plain.push(new Function("values",w)),this.factory_plain_bulk.push(new Function("values","i",g))}this.factory_weave=[function(t,r){return[]}];for(var h=1;16>h;++h)this.factory_weave.push(e(h))};i.prototype.readStringLT=function(){var t=this.u16[this.i16++];if(t>=this.string_table.length)throw{name:"RangeError",message:"String ID is outside than the range of the string lookup table!",toString:function(){return this.name+": "+this.message}};return this.string_table[t]},i.prototype.eof=function(){return this.i8>=this.iEnd},i.prototype.where=function(){console.log("i8=",this.i8-this.ofs8," [U:",this.u8[this.i8],"0x"+this.u8[this.i8].toString(16),"/ S:",this.s8[this.i8],"]"),console.log("i16=",this.i16-this.ofs16/2," [U:",this.u16[this.i16],"/ S:",this.s16[this.i16],"]"),console.log("i32=",this.i32-this.ofs32/4," [U:",this.u32[this.i32],"/ S:",this.s32[this.i32],"/ F:",this.f32[this.i32],"]"),console.log("i64=",this.i64-this.ofs64/8," [F:",this.f64[this.i64],"]")},t.exports=i},function(t,r){"use strict";var e=function(){this.size=0,this._lib=[],this._profiles=[],this._offset=0,this._foffset=0};e.prototype.add=function(t){this._lib.push(t)},e.prototype.use=function(t){if(0!=t.length)for(var r=0,e=t.length;e>r;r++){for(var i=null,s=t[r],n=0,a=this._lib.length;a>n;n++){var o=this._lib[n];if(o.id===s){i=o;break}}if(null===i){var h=(65520&s)>>4,u=15&s;throw{name:"DecodingError",message:"The bundle uses profile 0x"+h.toString(16)+", rev "+u+" but it was not loaded!",toString:function(){return this.name+": "+this.message}}}this.size+=i.size,this._profiles.push([i,this._foffset,this._foffset+i.frequent,this._offset,this._offset+i.size-i.frequent]),this._offset+=i.size-i.frequent,this._foffset+=i.frequent}},e.prototype.decode=function(t){if(32>t)for(var r=0,e=this._profiles.length;e>r;++r){var i=this._profiles[r],s=i[0],n=i[1],a=i[2];if(t>=n&&a>t)return s.decode(t-n)}else{t-=32;for(var r=0,e=this._profiles.length;e>r;++r){var i=this._profiles[r],s=i[0],n=i[3],a=i[4];if(t>=n&&a>t)return s.decode(t-n+32)}}},t.exports=e},function(t,r){"use strict";var e=function(t){this.parent=t,this.objectLookup=[],this.objects=[],this.value=0};e.prototype.update=function(t,r,e){var i=this.objectLookup.indexOf(t);-1===i?(i=this.objectLookup.length,this.objectLookup.push(t),this.objects.push([r,e])):(this.objects[i][0]=r,this.objects[i][1]=e);for(var s=0,n=0,a=0;a