!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).GPUIO={})}(this,(function(t){"use strict";var e=function(t,n){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var n in e)Object.prototype.hasOwnProperty.call(e,n)&&(t[n]=e[n])},e(t,n)};var n=function(){return n=Object.assign||function(t){for(var e,n=1,r=arguments.length;n0&&o[o.length-1])||6!==c[0]&&2!==c[0])){a=0;continue}if(3===c[0]&&(!o||c[1]>o[0]&&c[1]0}function i(t){return r(t)&&t>0}function a(t){return e(t)&&t<0}function c(t){return r(t)&&t<0}function s(t){return e(t)&&t>=0}function u(t){return r(t)&&t>=0}function l(t){return e(t)&&t<=0}function f(t){return r(t)&&t<=0}function p(t,n,r){return e(t)&&t>=n&&t<=r}function _(t,e,n){return r(t)&&t>=e&&t<=n}function h(t){return"string"==typeof t}function m(t){return ArrayBuffer.isView(t)&&!(t instanceof DataView)}function d(t){return Array.isArray(t)||m(t)}function v(t){return!("object"!=typeof t||d(t)||null===t||t instanceof ArrayBuffer||t instanceof DataView)}function g(t){return"boolean"==typeof t}t.isArray=d,t.isBoolean=g,t.isFiniteNumber=n,t.isInteger=r,t.isIntegerInRange=_,t.isNegativeInteger=c,t.isNegativeNumber=a,t.isNonNegativeInteger=u,t.isNonNegativeNumber=s,t.isNonPositiveInteger=f,t.isNonPositiveNumber=l,t.isNumber=e,t.isNumberInRange=p,t.isObject=v,t.isPositiveInteger=i,t.isPositiveNumber=o,t.isString=h,t.isTypedArray=m,Object.defineProperty(t,"__esModule",{value:!0})}(e)}(0,c.exports);var s=c.exports,u="HALF_FLOAT",l="FLOAT",f="UNSIGNED_BYTE",p="BYTE",_="UNSIGNED_SHORT",h="SHORT",m="UNSIGNED_INT",d="INT",v="BOOL",g="UINT",y="NEAREST",b="LINEAR",w="CLAMP_TO_EDGE",E="REPEAT",P=[Float32Array,Uint8Array,Int8Array,Uint16Array,Int16Array,Uint32Array,Int32Array,Array],x=[u,l,f,p,_,h,m,d],A=[y,b],U=[w,E],T="RGBA",I=["RGB",T],R=[f,l,u],O="300 es",S="100",L="webgl2",F="webgl",N="experimental-webgl",G="experimental-webgl2",C="lowp",B="mediump",V="highp",D="FLOAT_1D_UNIFORM",M="FLOAT_2D_UNIFORM",k="FLOAT_3D_UNIFORM",W="FLOAT_4D_UNIFORM",j="INT_1D_UNIFORM",X="INT_2D_UNIFORM",H="INT_3D_UNIFORM",Y="INT_4D_UNIFORM",z="UINT_1D_UNIFORM",J="UINT_2D_UNIFORM",q="UINT_3D_UNIFORM",K="UINT_4D_UNIFORM",Q="BOOL_1D_UNIFORM",$="BOOL_2D_UNIFORM",Z="BOOL_3D_UNIFORM",tt="BOOL_4D_UNIFORM",et="DEFAULT",nt="SEGMENT",rt="LAYER_POINTS",ot="LAYER_LINES",it="LAYER_VECTOR_FIELD",at="LAYER_MESH",ct="GPUIO_VS_WRAP_X",st="GPUIO_VS_WRAP_Y",ut="GPUIO_VS_INDEXED_POSITIONS",lt="GPUIO_VS_UV_ATTRIBUTE",ft="GPUIO_VS_NORMAL_ATTRIBUTE",pt="GPUIO_VS_POSITION_W_ACCUM",_t=function(t){throw new Error(t)},ht=0,mt=Math.pow(2,8)-1,dt=-Math.pow(2,7),vt=Math.pow(2,7)-1,gt=0,yt=Math.pow(2,16)-1,bt=-Math.pow(2,15),wt=Math.pow(2,15)-1,Et=0,Pt=Math.pow(2,32)-1,xt=-Math.pow(2,31),At=Math.pow(2,31)-1,Ut=16777216,Tt="GPUIO_INT_PRECISION",It="GPUIO_FLOAT_PRECISION",Rt="BOUNDARY_TOP",Ot="BOUNDARY_BOTTOM",St="BOUNDARY_LEFT",Lt="BOUNDARY_RIGHT";function Ft(t){if(t===V)return 2;if(t===B)return 1;if(t===C)return 0;throw new Error("Unknown shader precision value: ".concat(JSON.stringify(t),"."))}function Nt(t,e){switch(t){case u:case l:return l;case f:case _:case m:return e===S?d:g;case p:case h:case d:return d;default:throw new Error("Invalid type: ".concat(t," passed to glslKeyForType."))}}function Gt(t,e){switch(void 0===e&&(e=!1),t){case u:return e?Float32Array:Uint16Array;case l:return Float32Array;case f:return Uint8Array;case p:return Int8Array;case _:return Uint16Array;case h:return Int16Array;case m:return Uint32Array;case d:return Int32Array;default:throw new Error('Unsupported type: "'.concat(t,'".'))}}function Ct(t,e){switch(t){case u:case l:return 1===e?"float":"vec".concat(e);case f:case _:case m:return 1===e?"uint":"uvec".concat(e);case p:case h:case d:return 1===e?"int":"ivec".concat(e)}throw new Error("Invalid type: ".concat(t," passed to glslTypeForType."))}function Bt(t){switch(t){case u:case l:return"";case f:case _:case m:return"u";case p:case h:case d:return"i"}throw new Error("Invalid type: ".concat(t," passed to glslPrefixForType."))}function Vt(t){switch(t){case 1:return".x";case 2:return".xy";case 3:return".xyz";case 4:return""}throw new Error("Invalid numComponents: ".concat(t," passed to glslComponentSelectionForNumComponents."))}var Dt=Object.freeze({__proto__:null,arrayConstructorForType:Gt,glslComponentSelectionForNumComponents:Vt,glslPrefixForType:Bt,glslTypeForType:Ct,intForPrecision:Ft,uniformTypeForType:Nt}),Mt="\n#if (".concat(Tt," == ").concat(Ft(C),")\n\tprecision lowp int;\n\t#if (__VERSION__ == 300)\n\t\tprecision lowp isampler2D;\n\t\tprecision lowp usampler2D;\n\t#endif\n#elif (").concat(Tt," == ").concat(Ft(B),")\n\tprecision mediump int;\n\t#if (__VERSION__ == 300)\n\t\tprecision mediump isampler2D;\n\t\tprecision mediump usampler2D;\n\t#endif\n#else \n\t#ifdef GL_FRAGMENT_PRECISION_HIGH\n\t\tprecision highp int;\n\t\t#if (__VERSION__ == 300)\n\t\t\tprecision highp isampler2D;\n\t\t\tprecision highp usampler2D;\n\t\t#endif\n\t#else\n\t\tprecision mediump int;\n\t\t#if (__VERSION__ == 300)\n\t\t\tprecision mediump isampler2D;\n\t\t\tprecision mediump usampler2D;\n\t\t#endif\n\t#endif\n#endif\n#if (").concat(It," == ").concat(Ft(C),")\n\tprecision lowp float;\n\tprecision lowp sampler2D;\n#elif (").concat(It," == ").concat(Ft(B),")\n\tprecision mediump float;\n\tprecision mediump sampler2D;\n#else\n\t#ifdef GL_FRAGMENT_PRECISION_HIGH\n\t\tprecision highp float;\n\t\tprecision highp sampler2D;\n\t#else\n\t\tprecision mediump float;\n\t\tprecision mediump sampler2D;\n\t#endif\n#endif\n");function kt(t){return t.replace(/\bin\b/g,"attribute")}function Wt(t){return t.replace(/[.*+?^${}()|[\]\\]/g,"\\$&")}function jt(t,e,n){var r=new RegExp("\\b".concat(Wt(e),"\\s*=\\s*\\S[^;]*;"),"sg"),o=t.match(r);if(o)for(var i=0;ir&&(r=h),n[_]={location:h,type:m};t=t.replace(o[0],"")}}function qt(t,e){var n=Jt(t,e);if(0===n.length)return[t];t=t.replace(/\blayout\s*\(\s*location\s*=\s*([0-9]+)\s*\)\s*/g,"");for(var r=[],o=0,i=n.length;o> b;\n\t#else\n\t\treturn ").concat(t,"(round(").concat(_e(t),"(a) / pow(").concat(_e(e),"(2.0), ").concat(_e(e),"(b))));\n\t#endif\n}")}function Se(t){return"int bitwiseOr".concat(32===t?"":t,"(int a, int b) {\n\t#if (__VERSION__ == 300)\n\t\treturn a | b;\n\t#else\n\t\tint result = 0;\n\t\tint n = 1;\n\t\t\n\t\tfor (int i = 0; i < ").concat(t,"; i++) {\n\t\t\tif ((modi(a, 2) == 1) || (modi(b, 2) == 1)) {\n\t\t\t\tresult += n;\n\t\t\t}\n\t\t\ta = a / 2;\n\t\t\tb = b / 2;\n\t\t\tn = n * 2;\n\t\t\tif(!(a > 0 || b > 0)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t#endif\n}")}function Le(t){return"int bitwiseXOR".concat(32===t?"":t,"(int a, int b) {\n\t#if (__VERSION__ == 300)\n\t\treturn a ^ b;\n\t#else\n\t\tint result = 0;\n\t\tint n = 1;\n\t\t\n\t\tfor (int i = 0; i < ").concat(t,"; i++) {\n\t\t\tif ((modi(a, 2) == 1) != (modi(b, 2) == 1)) {\n\t\t\t\tresult += n;\n\t\t\t}\n\t\t\ta = a / 2;\n\t\t\tb = b / 2;\n\t\t\tn = n * 2;\n\t\t\tif(!(a > 0 || b > 0)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t#endif\n}")}function Fe(t){return"int bitwiseAnd".concat(32===t?"":t,"(int a, int b) {\n\t#if (__VERSION__ == 300)\n\t\treturn a & b;\n\t#else\n\t\tint result = 0;\n\t\tint n = 1;\n\t\tfor (int i = 0; i < ").concat(t,"; i++) {\n\t\t\tif ((modi(a, 2) == 1) && (modi(b, 2) == 1)) {\n\t\t\t\tresult += n;\n\t\t\t}\n\t\t\ta = a / 2;\n\t\t\tb = b / 2;\n\t\t\tn = n * 2;\n\t\t\tif(!(a > 0 && b > 0)) {\n\t\t\t\tbreak;\n\t\t\t}\n\t\t}\n\t\treturn result;\n\t#endif\n}")}function Ne(t){return"int bitwiseNot".concat(32===t?"":t,"(int a) {\n\t#if (__VERSION__ == 300)\n\t\treturn ~a;\n\t#else\n\t\tint result = 0;\n\t\tint n = 1;\n\n\t\tfor (int i = 0; i < ").concat(t,"; i++) {\n\t\t\tif (modi(a, 2) == 0) {\n\t\t\t\tresult += n;\n\t\t\t}\n\t\t\ta = a / 2;\n\t\t\tn = n * 2;\n\t\t}\n\t\treturn result;\n\t#endif\n}")}function Ge(t,e){var n="";return t.includes("index1DToUV")&&(n+="\n\n".concat(Ue("int","ivec2"),"\n").concat(Ue("int","vec2"),"\n#if (__VERSION__ == 300)\n").concat(Ue("int","uvec2"),"\n").concat(Ue("uint","uvec2"),"\n").concat(Ue("uint","ivec2"),"\n").concat(Ue("uint","vec2"),"\n#endif\n")),(t.includes("modi")||e===S&&t.includes("bitwise"))&&(n+="\n\n".concat(Te("int","int"),"\n").concat(Te("ivec2","ivec2"),"\n").concat(Te("ivec3","ivec3"),"\n").concat(Te("ivec4","ivec4"),"\n").concat(Te("ivec2","int"),"\n").concat(Te("ivec3","int"),"\n").concat(Te("ivec4","int"),"\n#if (__VERSION__ == 300)\n").concat(Te("uint","uint"),"\n").concat(Te("uvec2","uvec2"),"\n").concat(Te("uvec3","uvec3"),"\n").concat(Te("uvec4","uvec4"),"\n").concat(Te("uvec2","uint"),"\n").concat(Te("uvec3","uint"),"\n").concat(Te("uvec4","uint"),"\n#endif\n")),t.includes("stepi")&&(n+="\n\n".concat(Ie("int","int"),"\n").concat(Ie("ivec2","ivec2"),"\n").concat(Ie("ivec3","ivec3"),"\n").concat(Ie("ivec4","ivec4"),"\n").concat(Ie("int","ivec2"),"\n").concat(Ie("int","ivec3"),"\n").concat(Ie("int","ivec4"),"\n#if (__VERSION__ == 300)\n").concat(Ie("uint","uint"),"\n").concat(Ie("uvec2","uvec2"),"\n").concat(Ie("uvec3","uvec3"),"\n").concat(Ie("uvec4","uvec4"),"\n").concat(Ie("uint","uvec2"),"\n").concat(Ie("uint","uvec3"),"\n").concat(Ie("uint","uvec4"),"\n#endif\n")),t.includes("bitshiftLeft")&&(n+="\n\n".concat(Re("int","int"),"\n").concat(Re("ivec2","ivec2"),"\n").concat(Re("ivec3","ivec3"),"\n").concat(Re("ivec4","ivec4"),"\n").concat(Re("ivec2","int"),"\n").concat(Re("ivec3","int"),"\n").concat(Re("ivec4","int"),"\n#if (__VERSION__ == 300)\n").concat(Re("uint","uint"),"\n").concat(Re("uvec2","uvec2"),"\n").concat(Re("uvec3","uvec3"),"\n").concat(Re("uvec4","uvec4"),"\n").concat(Re("uvec2","uint"),"\n").concat(Re("uvec3","uint"),"\n").concat(Re("uvec4","uint"),"\n#endif\n")),t.includes("bitshiftRight")&&(n+="\n\n".concat(Oe("int","int"),"\n").concat(Oe("ivec2","ivec2"),"\n").concat(Oe("ivec3","ivec3"),"\n").concat(Oe("ivec4","ivec4"),"\n").concat(Oe("ivec2","int"),"\n").concat(Oe("ivec3","int"),"\n").concat(Oe("ivec4","int"),"\n#if (__VERSION__ == 300)\n").concat(Oe("uint","uint"),"\n").concat(Oe("uvec2","uvec2"),"\n").concat(Oe("uvec3","uvec3"),"\n").concat(Oe("uvec4","uvec4"),"\n").concat(Oe("uvec2","uint"),"\n").concat(Oe("uvec3","uint"),"\n").concat(Oe("uvec4","uint"),"\n#endif\n")),t.includes("bitwiseOr")&&(n+="\n\n".concat(Se(8),"\n").concat(Se(16),"\n").concat(Se(32),"\n#if (__VERSION__ == 300)\n").concat([8,16,""].map((function(t){return"\nuint bitwiseOr".concat(t,"(uint a, uint b) {\n\treturn uint(bitwiseOr").concat(t,"(int(a), int(b)));\n}")})).join("\n"),"\n#endif\n")),t.includes("bitwiseXOR")&&(n+="\n\n".concat(Le(8),"\n").concat(Le(16),"\n").concat(Le(32),"\n#if (__VERSION__ == 300)\n").concat([8,16,""].map((function(t){return"\nuint bitwiseXOR".concat(t,"(uint a, uint b) {\n\treturn uint(bitwiseXOR").concat(t,"(int(a), int(b)));\n}")})).join("\n"),"\n#endif\n")),t.includes("bitwiseAnd")&&(n+="\n\n".concat(Fe(8),"\n").concat(Fe(16),"\n").concat(Fe(32),"\n#if (__VERSION__ == 300)\n").concat([8,16,""].map((function(t){return"\nuint bitwiseAnd".concat(t,"(uint a, uint b) {\n\treturn uint(bitwiseAnd").concat(t,"(int(a), int(b)));\n}")})).join("\n"),"\n#endif\n")),t.includes("bitwiseNot")&&(n+="\n\n".concat(Ne(8),"\n").concat(Ne(16),"\n").concat(Ne(32),"\n#if (__VERSION__ == 300)\n").concat([8,16,""].map((function(t){return"\nuint bitwiseNot".concat(t,"(uint a) {\n\treturn uint(bitwiseNot").concat(t,"(int(a)));\n}")})).join("\n"),"\n#endif\n")),n}var Ce=Object.freeze({__proto__:null,GLSL1Polyfills:Ae,SAMPLER2D_CAST_INT:se,SAMPLER2D_DIMENSIONS_UNIFORM:fe,SAMPLER2D_FILTER:ue,SAMPLER2D_HALF_PX_UNIFORM:le,SAMPLER2D_WRAP_X:ae,SAMPLER2D_WRAP_Y:ce,fragmentShaderPolyfills:Ge,texturePolyfill:pe}),Be={supportsWebGL2:void 0,supportsHighpVertex:void 0,supportsHighpFragment:void 0,mediumpVertexPrecision:void 0,mediumpFragmentPrecision:void 0};function Ve(t){return t===f||t===_||t===m}function De(t){return t===p||t===h||t===d}function Me(t){return Ve(t)||De(t)}function ke(t){for(var e="",n=Object.keys(t),r=0;r>>1:n>>>1;t[e]=n}return t}());for(var n=0;n>>8;return-1^e}un.changeDpiDataUrl=function(t,e){var n=t.split(","),r=n[0],o=n[1],i=void 0,a=void 0,c=!1;if(-1!==r.indexOf(_n)){i=_n;var s=function(t){var e=t.indexOf(mn);-1===e&&(e=t.indexOf(dn));-1===e&&(e=t.indexOf(vn));return e}(o);s>=0?(a=4*Math.ceil((s+28)/3),c=!0):a=44}-1!==r.indexOf(hn)&&(i=hn,a=24);for(var u=o.substring(0,a),l=o.substring(a),f=atob(u),p=new Uint8Array(f.length),_=0;_>8,t[15]=255&e,t[16]=e>>8,t[17]=255&e,t;if(n===_n){var o=new Uint8Array(13);e*=39.3701,o[0]=gn,o[1]=yn,o[2]=bn,o[3]=wn,o[4]=e>>>24,o[5]=e>>>16,o[6]=e>>>8,o[7]=255&e,o[8]=o[4],o[9]=o[5],o[10]=o[6],o[11]=o[7],o[12]=1;var i=fn(o),a=new Uint8Array(4);if(a[0]=i>>>24,a[1]=i>>>16,a[2]=i>>>8,a[3]=255&i,r){var c=function(t){for(var e=t.length-1;e>=4;e--)if(9===t[e-4]&&t[e-3]===gn&&t[e-2]===yn&&t[e-1]===bn&&t[e]===wn)return e-3}(t);return t.set(o,c),t.set(a,c+13),t}var s=new Uint8Array(4);s[0]=0,s[1]=0,s[2]=0,s[3]=9;var u=new Uint8Array(54);return u.set(t,0),u.set(s,33),u.set(o,37),u.set(a,50),u}}const Pn="This constructor is not a subclass of Float16Array",xn="The constructor property value is not an object",An="Attempting to access detached ArrayBuffer",Un="Cannot convert undefined or null to object",Tn="Cannot mix BigInt and other types, use explicit conversions",In="@@iterator property is not callable",Rn="Reduce of empty array with no initial value",On="Offset is out of bounds";function Sn(t){return(e,...n)=>Fn(t,e,n)}function Ln(t,e){return Sn(Bn(t,e).get)}const{apply:Fn,construct:Nn,defineProperty:Gn,get:Cn,getOwnPropertyDescriptor:Bn,getPrototypeOf:Vn,has:Dn,ownKeys:Mn,set:kn,setPrototypeOf:Wn}=Reflect,jn=Proxy,{MAX_SAFE_INTEGER:Xn,isFinite:Hn,isNaN:Yn}=Number,{iterator:zn,species:Jn,toStringTag:qn,for:Kn}=Symbol,Qn=Object,{create:$n,defineProperty:Zn,freeze:tr,is:er}=Qn,nr=Qn.prototype,rr=nr.__lookupGetter__?Sn(nr.__lookupGetter__):(t,e)=>{if(null==t)throw Kr(Un);let n=Qn(t);do{const t=Bn(n,e);if(void 0!==t)return or(t,"get")?t.get:void 0}while(null!==(n=Vn(n)))},or=Qn.hasOwn||Sn(nr.hasOwnProperty),ir=Array,ar=ir.isArray,cr=ir.prototype,sr=Sn(cr.join),ur=Sn(cr.push),lr=Sn(cr.toLocaleString),fr=cr[zn],pr=Sn(fr),_r=Math.trunc,hr=ArrayBuffer,mr=hr.isView,dr=hr.prototype,vr=Sn(dr.slice),gr=Ln(dr,"byteLength"),yr="undefined"!=typeof SharedArrayBuffer?SharedArrayBuffer:null,br=yr&&Ln(yr.prototype,"byteLength"),wr=Vn(Uint8Array),Er=wr.from,Pr=wr.prototype,xr=Pr[zn],Ar=Sn(Pr.keys),Ur=Sn(Pr.values),Tr=Sn(Pr.entries),Ir=Sn(Pr.set),Rr=Sn(Pr.reverse),Or=Sn(Pr.fill),Sr=Sn(Pr.copyWithin),Lr=Sn(Pr.sort),Fr=Sn(Pr.slice),Nr=Sn(Pr.subarray),Gr=Ln(Pr,"buffer"),Cr=Ln(Pr,"byteOffset"),Br=Ln(Pr,"length"),Vr=Ln(Pr,qn),Dr=Uint16Array,Mr=(...t)=>Fn(Er,Dr,t),kr=Uint32Array,Wr=Float32Array,jr=Vn([][zn]()),Xr=Sn(jr.next),Hr=Sn(function*(){}().next),Yr=Vn(jr),zr=DataView.prototype,Jr=Sn(zr.getUint16),qr=Sn(zr.setUint16),Kr=TypeError,Qr=RangeError,$r=WeakSet,Zr=$r.prototype,to=Sn(Zr.add),eo=Sn(Zr.has),no=WeakMap,ro=no.prototype,oo=Sn(ro.get),io=Sn(ro.has),ao=Sn(ro.set),co=new no,so=$n(null,{next:{value:function(){const t=oo(co,this);return Xr(t)}},[zn]:{value:function(){return this}}});function uo(t){if(t[zn]===fr)return t;const e=$n(so);return ao(co,e,pr(t)),e}const lo=new no,fo=$n(Yr,{next:{value:function(){const t=oo(lo,this);return Hr(t)},writable:!0,configurable:!0}});for(const t of Mn(jr))"next"!==t&&Zn(fo,t,Bn(jr,t));function po(t){const e=$n(fo);return ao(lo,e,t),e}function _o(t){return null!==t&&"object"==typeof t||"function"==typeof t}function ho(t){return null!==t&&"object"==typeof t}function mo(t){return void 0!==Vr(t)}function vo(t){const e=Vr(t);return"BigInt64Array"===e||"BigUint64Array"===e}function go(t){if(null===yr)return!1;try{return br(t),!0}catch(t){return!1}}function yo(t){if(!ar(t))return!1;if(t[zn]===fr)return!0;return"Array Iterator"===t[zn]()[qn]}function bo(t){if("string"!=typeof t)return!1;const e=+t;return t===e+""&&(!!Hn(e)&&e===_r(e))}const wo=Kn("__Float16Array__");const Eo=new hr(4),Po=new Wr(Eo),xo=new kr(Eo),Ao=new kr(512),Uo=new kr(512);for(let t=0;t<256;++t){const e=t-127;e<-27?(Ao[t]=0,Ao[256|t]=32768,Uo[t]=24,Uo[256|t]=24):e<-14?(Ao[t]=1024>>-e-14,Ao[256|t]=1024>>-e-14|32768,Uo[t]=-e-1,Uo[256|t]=-e-1):e<=15?(Ao[t]=e+15<<10,Ao[256|t]=e+15<<10|32768,Uo[t]=13,Uo[256|t]=13):e<128?(Ao[t]=31744,Ao[256|t]=64512,Uo[t]=24,Uo[256|t]=24):(Ao[t]=31744,Ao[256|t]=64512,Uo[t]=13,Uo[256|t]=13)}function To(t){Po[0]=t;const e=xo[0],n=e>>23&511;return Ao[n]+((8388607&e)>>Uo[n])}const Io=new kr(2048),Ro=new kr(64),Oo=new kr(64);for(let t=1;t<1024;++t){let e=t<<13,n=0;for(;0==(8388608&e);)e<<=1,n-=8388608;e&=-8388609,n+=947912704,Io[t]=e|n}for(let t=1024;t<2048;++t)Io[t]=939524096+(t-1024<<13);for(let t=1;t<31;++t)Ro[t]=t<<23;Ro[31]=1199570944,Ro[32]=2147483648;for(let t=33;t<63;++t)Ro[t]=2147483648+(t-32<<23);Ro[63]=3347054592;for(let t=1;t<64;++t)32!==t&&(Oo[t]=1024);function So(t){const e=t>>10;return xo[0]=Io[Oo[e]+(1023&t)]+Ro[e],Po[0]}function Lo(t){const e=+t;return Yn(e)||0===e?0:_r(e)}function Fo(t){const e=Lo(t);return e<0?0:ee)return 1;if(0===t&&0===e){const n=er(t,0),r=er(e,0);if(!n&&r)return-1;if(n&&!r)return 1}return 0}const Bo=new no;function Vo(t){return io(Bo,t)||!mr(t)&&function(t){if(!ho(t))return!1;const e=Vn(t);if(!ho(e))return!1;const n=e.constructor;if(void 0===n)return!1;if(!_o(n))throw Kr(xn);return Dn(n,wo)}(t)}function Do(t){if(!Vo(t))throw Kr("This is not a Float16Array object")}function Mo(t,e){const n=Vo(t),r=mo(t);if(!n&&!r)throw Kr("Species constructor didn't return TypedArray object");if("number"==typeof e){let r;if(n){const e=ko(t);r=Br(e)}else r=Br(t);if(rbo(e)&&or(t,e)?So(Cn(t,e)):eo(jo,rr(t,e))?Cn(t,e):Cn(t,e,n),set:(t,e,n,r)=>bo(e)&&or(t,e)?kn(t,e,To(n)):kn(t,e,n,r),getOwnPropertyDescriptor(t,e){if(bo(e)&&or(t,e)){const n=Bn(t,e);return n.value=So(n.value),n}return Bn(t,e)},defineProperty:(t,e,n)=>bo(e)&&or(t,e)&&or(n,"value")?(n.value=To(n.value),Gn(t,e,n)):Gn(t,e,n)});class Ho{constructor(t,e,n){let r;if(Vo(t))r=Nn(Dr,[ko(t)],new.target);else if(_o(t)&&!function(t){try{return gr(t),!0}catch(t){return!1}}(t)){let e,n;if(mo(t)){e=t,n=Br(t);const o=Gr(t),i=go(o)?hr:No(o,hr);if(Go(o))throw Kr(An);if(vo(t))throw Kr(Tn);const a=new i(2*n);r=Nn(Dr,[a],new.target)}else{const o=t[zn];if(null!=o&&"function"!=typeof o)throw Kr(In);null!=o?yo(t)?(e=t,n=t.length):(e=[...t],n=e.length):(e=t,n=Fo(e.length)),r=Nn(Dr,[n],new.target)}for(let t=0;t=0?r:n+r;if(!(o<0||o>=n))return So(e[o])}map(t,...e){Do(this);const n=ko(this),r=Br(n),o=e[0],i=No(n,Ho);if(i===Ho){const e=new Ho(r),i=ko(e);for(let e=0;e=0;--e)o=t(o,So(n[e]),e,this);return o}forEach(t,...e){Do(this);const n=ko(this),r=Br(n),o=e[0];for(let e=0;e=0;--e){const r=So(n[e]);if(Fn(t,o,[r,e,this]))return r}}findLastIndex(t,...e){Do(this);const n=ko(this),r=Br(n),o=e[0];for(let e=r-1;e>=0;--e){const r=So(n[e]);if(Fn(t,o,[r,e,this]))return e}return-1}every(t,...e){Do(this);const n=ko(this),r=Br(n),o=e[0];for(let e=0;eo)throw Qr(On);for(let t=0;tn(So(t),So(e)))),this}slice(t,e){Do(this);const n=ko(this),r=No(n,Ho);if(r===Ho){const r=new Dr(Gr(n),Cr(n),Br(n));return new Ho(Gr(Fr(r,t,e)))}const o=Br(n),i=Lo(t),a=void 0===e?o:Lo(e);let c,s;c=i===-1/0?0:i<0?o+i>0?o+i:0:o0?o+a:0:o0?s-c:0,l=new r(u);if(Mo(l,u),0===u)return l;if(Go(Gr(n)))throw Kr(An);let f=0;for(;c=1?Lo(e[0]):r-1;if(o===-1/0)return-1;o>=0?o=o=0;--e)if(or(n,e)&&So(n[e])===t)return e;return-1}includes(t,...e){Do(this);const n=ko(this),r=Br(n);let o=Lo(e[0]);if(o===1/0)return!1;o<0&&(o+=r,o<0&&(o=0));const i=Yn(t);for(let e=o;e=e.status}function o(t){try{t.dispatchEvent(new MouseEvent("click"))}catch(n){var e=document.createEvent("MouseEvents");e.initMouseEvent("click",!0,!0,window,0,0,0,80,20,!1,!1,!1,!1,0,null),t.dispatchEvent(e)}}var i="object"==typeof window&&window.window===window?window:"object"==typeof self&&self.self===self?self:"object"==typeof a&&a.global===a?a:void 0,c=i.navigator&&/Macintosh/.test(navigator.userAgent)&&/AppleWebKit/.test(navigator.userAgent)&&!/Safari/.test(navigator.userAgent),s=i.saveAs||("object"!=typeof window||window!==i?function(){}:"download"in HTMLAnchorElement.prototype&&!c?function(t,e,a){var c=i.URL||i.webkitURL,s=document.createElement("a");e=e||t.name||"download",s.download=e,s.rel="noopener","string"==typeof t?(s.href=t,s.origin===location.origin?o(s):r(s.href)?n(t,e,a):o(s,s.target="_blank")):(s.href=c.createObjectURL(t),setTimeout((function(){c.revokeObjectURL(s.href)}),4e4),setTimeout((function(){o(s)}),0))}:"msSaveOrOpenBlob"in navigator?function(t,i,a){if(i=i||t.name||"download","string"!=typeof t)navigator.msSaveOrOpenBlob(e(t,a),i);else if(r(t))n(t,i,a);else{var c=document.createElement("a");c.href=t,c.target="_blank",setTimeout((function(){o(c)}))}}:function(t,e,r,o){if((o=o||open("","_blank"))&&(o.document.title=o.document.body.innerText="downloading..."),"string"==typeof t)return n(t,e,r);var a="application/octet-stream"===t.type,s=/constructor/i.test(i.HTMLElement)||i.safari,u=/CriOS\/[\d]+/.test(navigator.userAgent);if((u||a&&s||c)&&"undefined"!=typeof FileReader){var l=new FileReader;l.onloadend=function(){var t=l.result;t=u?t:t.replace(/^data:[^;]*;/,"data:attachment/file;"),o?o.location.href=t:location=t,o=null},l.readAsDataURL(t)}else{var f=i.URL||i.webkitURL,p=f.createObjectURL(t);o?o.location=p:location.href=p,o=null,setTimeout((function(){f.revokeObjectURL(p)}),4e4)}});i.saveAs=s.saveAs=s,t.exports=s}()}(qo);var Ko=qo.exports;function Qo(t){return x.indexOf(t)>-1}function $o(t){return A.indexOf(t)>-1}function Zo(t){return U.indexOf(t)>-1}function ti(t){return I.indexOf(t)>-1}function ei(t){return R.indexOf(t)>-1}function ni(t,e,n){if(s.isArray(t)){if(t.length!==e)return!1;for(var r=0;r127)&&s.isInteger(t));case h:return!(t<-32768)&&(!(t>32767)&&s.isInteger(t));case d:return!(t<-2147483648)&&(!(t>2147483647)&&s.isInteger(t));case f:return!(t>255)&&s.isNonNegativeInteger(t);case _:return!(t>65535)&&s.isNonNegativeInteger(t);case m:return!(t>4294967295)&&s.isNonNegativeInteger(t);default:throw new Error("Unknown type ".concat(e))}}function oi(t,e,n,r){t.forEach((function(t){e.indexOf(t)<0&&console.warn('Invalid params key "'.concat(t,'" passed to ').concat(n).concat(r?' with name "'.concat(r,'"'):"",". Valid keys are ").concat(JSON.stringify(e),"."))}))}function ii(t,e,n,r){e.forEach((function(e){if(t.indexOf(e)<0)throw new Error('Required params key "'.concat(e,'" was not passed to ').concat(n).concat(r?' with name "'.concat(r,'"'):"","."))}))}var ai=Object.freeze({__proto__:null,checkRequiredKeys:ii,checkValidKeys:oi,isNumberOfType:ri,isValidClearValue:ni,isValidDataType:Qo,isValidFilter:$o,isValidImageFormat:ti,isValidImageType:ei,isValidWrap:Zo}),ci=new WeakMap,si=new WeakMap;function ui(t,e,n,r){var o=t.gl,a=r?i([n],r,!0):n,c=ci.get(a);if(!c){if(c=function(t,e,n,r){var o=t.gl,i=t._errorCallback,a=t.isWebGL2,c=o.createFramebuffer();if(c){if(o.bindFramebuffer(o.FRAMEBUFFER,c),o.framebufferTexture2D(o.FRAMEBUFFER,o.COLOR_ATTACHMENT0,o.TEXTURE_2D,n,0),r){if(!a)throw new Error("WebGL1 does not support drawing to multiple outputs.");if(r.length>15)throw new Error("Can't draw to more than 16 outputs.");for(var s=0,u=r.length;s4)throw new Error("Invalid numComponents: ".concat(JSON.stringify(c),' for GPULayer "').concat(r,'", must be number in range [1-4].'));this.numComponents=c;var p=t.calcGPULayerSize(i,r,e.verboseLogging),_=p.length,h=p.width,m=p.height;this._length=_,this._width=h,this._height=m;var d=void 0!==_||a!==l&&a!=u?y:b,v=void 0!==n.filter?n.filter:d;if(!$o(v))throw new Error("Invalid filter: ".concat(JSON.stringify(v),' for GPULayer "').concat(r,'", must be one of ').concat(JSON.stringify(A),"."));if(v===b&&a!==l&&a!=u)throw new Error('LINEAR filtering is not supported on integer types, please use NEAREST filtering for GPULayer "'.concat(r,'" with type: ').concat(a,"."));this.filter=v;var g=void 0!==n.wrapX?n.wrapX:w;if(!Zo(g))throw new Error("Invalid wrapX: ".concat(JSON.stringify(g),' for GPULayer "').concat(r,'", must be one of ').concat(JSON.stringify(U),"."));this.wrapX=g;var E=void 0!==n.wrapY?n.wrapY:w;if(!Zo(E))throw new Error("Invalid wrapY: ".concat(JSON.stringify(E),' for GPULayer "').concat(r,'", must be one of ').concat(JSON.stringify(U),"."));if(this.wrapY=E,!Qo(a))throw new Error("Invalid type: ".concat(JSON.stringify(a),' for GPULayer "').concat(r,'", must be one of ').concat(JSON.stringify(x),"."));this.type=a;var P=t.getGPULayerInternalType({composer:e,type:a,name:r});this._internalType=P;var T=t.getGLTextureParameters({composer:e,name:r,numComponents:c,internalType:P}),I=T.glFormat,R=T.glInternalFormat,O=T.glType,S=T.glNumChannels;this._glInternalFormat=R,this._glFormat=I,this._glType=O,this._glNumChannels=S;var L=t.getGPULayerInternalFilter({composer:e,filter:v,wrapX:g,wrapY:E,internalType:P,name:r});this._internalFilter=L,this._glFilter=f[L],this._internalWrapX=t.getGPULayerInternalWrap({composer:e,wrap:g,internalFilter:L,internalType:P,name:r}),this._glWrapS=f[this._internalWrapX],this._internalWrapY=t.getGPULayerInternalWrap({composer:e,wrap:E,internalFilter:L,internalType:P,name:r}),this._glWrapT=f[this._internalWrapY];var F=void 0!==n.numBuffers?n.numBuffers:1;if(!s.isPositiveInteger(F))throw new Error("Invalid numBuffers: ".concat(JSON.stringify(F),' for GPULayer "').concat(r,'", must be positive integer.'));this.numBuffers=F,void 0!==n.clearValue&&(this.clearValue=n.clearValue),this._initBuffers(n.array)}return t.initFromImageURL=function(e,n){return r(this,void 0,void 0,(function(){return o(this,(function(r){return[2,new Promise((function(r,o){if(!n)throw new Error("Error initing GPULayer: must pass params to GPULayer.initFromImageURL(composer, params).");if(!s.isObject(n))throw new Error("Error initing GPULayer: must pass valid params object to GPULayer.initFromImageURL(composer, params), got ".concat(JSON.stringify(n),"."));var i=Object.keys(n);oi(i,["name","url","filter","wrapX","wrapY","format","type","clearValue"],"GPULayer.initFromImageURL(composer, params)",n.name),ii(i,["name","url"],"GPULayer.initFromImageURL(composer, params)",n.name);var a=n.url,c=n.name,u=n.filter,f=n.wrapX,p=n.wrapY,_=n.type,h=n.format;if(!s.isString(a))throw new Error("Expected GPULayer.initFromImageURL params to have url of type string, got ".concat(a," of type ").concat(typeof a,"."));if(_&&!ei(_))throw new Error('Invalid type: "'.concat(_,'" for GPULayer.initFromImageURL "').concat(c,'", must be one of ').concat(JSON.stringify(R),"."));if(h&&!ti(h))throw new Error('Invalid format: "'.concat(h,'" for GPULayer.initFromImageURL "').concat(c,'", must be one of ').concat(JSON.stringify(I),"."));var m=new t(e,{name:c,type:_||l,numComponents:h?h.length:4,dimensions:[1,1],filter:u,wrapX:f,wrapY:p,numBuffers:1,clearValue:n.clearValue}),d=new Image;d.onload=function(){m.resize([d.width,d.height],d),r(m)},d.onerror=function(t){o(new Error('Error loading image "'.concat(c,'": ').concat(t)))},d.src=a}))]}))}))},Object.defineProperty(t.prototype,"width",{get:function(){return this._width},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this._height},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"length",{get:function(){if(!this._length)throw new Error('Cannot access length on 2D GPULayer "'.concat(this.name,'".'));return this._length},enumerable:!1,configurable:!0}),t.prototype.is1D=function(){return void 0!==this._length},t.prototype.is2D=function(){return!this.is1D()},t.prototype._usingTextureOverrideForCurrentBuffer=function(){return!(!this._textureOverrides||!this._textureOverrides[this.bufferIndex])},t.prototype.copyCurrentStateToGPULayer=function(t){var e=this._composer;if(this===t)throw new Error("Can't call GPULayer.copyCurrentStateToGPULayer() on self.");var n=e._copyProgramForType(this._internalType);e.step({program:n,input:this,output:t})},t.prototype._initBuffers=function(e){var n=this,r=n.name,o=n.numBuffers,i=n._composer,a=n._glInternalFormat,c=n._glFormat,u=n._glType,l=n._glFilter,f=n._glWrapS,p=n._glWrapT,_=n.width,h=n.height,m=i.gl,d=i._errorCallback,v=null;s.isArray(e)?v=t.validateGPULayerArray(e,this):(null==e?void 0:e.constructor)===HTMLImageElement&&(v=e);for(var g=0;g-n&&(t+=n),(t<0||t>=n)&&(console.warn("Out of range buffer index: ".concat(t,' for GPULayer "').concat(this.name,'" with $.numBuffers} buffer').concat(n>1?"s":"",". Was this intentional?")),t<0?t+=n*Math.ceil(Math.abs(t)/n):t%=n);var i=o[t];return r&&r[t]&&(i=r[t]),{texture:i,layer:this}},t.prototype._prepareForWrite=function(t){t&&this.incrementBufferIndex(),this._textureOverrides&&(this._textureOverrides[this.bufferIndex]=void 0)},t.prototype.setFromArray=function(e){var n=this,r=n._composer,o=n._glInternalFormat,i=n._glFormat,a=n._glType,c=n.width,s=n.height,u=n._currentTexture,l=r.gl,f=t.validateGPULayerArray(e,this);l.bindTexture(l.TEXTURE_2D,u),l.texImage2D(l.TEXTURE_2D,0,o,c,s,0,i,a,f),l.bindTexture(l.TEXTURE_2D,null)},t.prototype.resize=function(e,n){var r=this.name,o=this._composer.verboseLogging;o&&console.log('Resizing GPULayer "'.concat(r,'" to ').concat(JSON.stringify(e),"."));var i=t.calcGPULayerSize(e,r,o),a=i.length,c=i.width,s=i.height;this._length=a,this._width=c,this._height=s,this._destroyBuffers(),this._initBuffers(n)},Object.defineProperty(t.prototype,"clearValue",{get:function(){return this._clearValue},set:function(t){var e=this.numComponents,n=this.type;if(!ni(t,e,n))throw new Error("Invalid clearValue: ".concat(JSON.stringify(t),' for GPULayer "').concat(this.name,'", expected ').concat(n," or array of ").concat(n," of length ").concat(e,"."));this._clearValue=s.isArray(t)?t.slice():t,this._clearValueVec4=void 0},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"clearValueVec4",{get:function(){var t=this._clearValueVec4;if(!t){var e=this.clearValue;if(t=[],s.isFiniteNumber(e))t.push(e,e,e,e);else{t.push.apply(t,e);for(var n=t.length;n<4;n++)t.push(0)}this._clearValueVec4=t}return t},enumerable:!1,configurable:!0}),t.prototype.clear=function(t){void 0===t&&(t=!1);var e=this,n=e.name,r=e._composer,o=e.clearValueVec4,i=e.numBuffers,a=e.type;r.verboseLogging&&console.log('Clearing GPULayer "'.concat(n,'".'));var c=r._setValueProgramForType(a);c.setUniform("u_value",o),this.decrementBufferIndex();for(var s=t?i:1,u=0;u=l)break;for(var g=0;g1)throw new Error('GPULayer "'.concat(i,'" contains multiple WebGL textures (one for each buffer) that are flip-flopped during compute cycles, please choose a GPULayer with one buffer. You can copy the current state of this GPULayer to a single buffer GPULayer during your render loop.'));var s=a.properties.get(t);c.deleteTexture(s.__webglTexture),s.__webglTexture=o.texture,s.__webglInit=!0},t.prototype._destroyBuffers=function(){var t=this._composer,e=this._buffers,n=t.gl;e.forEach((function(t){n.deleteTexture(t),function(t,e){t.bindFramebuffer(t.FRAMEBUFFER,null);var n=si.get(e);if(n)for(var r=0,o=n.length;rM){D=!1;break}}Ei.filterWrapSupport[p]=D,i.deleteProgram(B)}else Ei.filterWrapSupport[p]=!1;i.deleteShader(N)}else Ei.filterWrapSupport[p]=!1;return R.dispose(),i.deleteTexture(_),Ei.filterWrapSupport[p]}function Ui(t){var e=-1/0,n=1/0;switch(t){case f:e=ht,n=mt;break;case p:e=dt,n=vt;break;case _:e=gt,n=yt;break;case h:e=bt,n=wt;break;case m:e=Et,n=Pt;break;case d:e=xt,n=At}return{min:e,max:n}}li.initArrayForType=function(t,e,n){return void 0===n&&(n=!1),new(Gt(t,n))(e)},li.calcGPULayerSize=function(t,e,n){if(s.isNumber(t)){if(!s.isPositiveInteger(t))throw new Error("Invalid length: ".concat(JSON.stringify(t),' for GPULayer "').concat(e,'", must be positive integer.'));var r=t,o=Math.ceil(Math.sqrt(r)),i=Math.ceil(r/o);return n&&console.log("Using [".concat(o,", ").concat(i,"] for 1D array of length ").concat(t,' in GPULayer "').concat(e,'".')),{width:o,height:i,length:r}}var a=t[0];if(!s.isPositiveInteger(a))throw new Error("Invalid width: ".concat(JSON.stringify(a),' for GPULayer "').concat(e,'", must be positive integer.'));var c=t[1];if(!s.isPositiveInteger(c))throw new Error("Invalid height: ".concat(JSON.stringify(c),' for GPULayer "').concat(e,'", must be positive integer.'));return{width:a,height:c}},li.getGPULayerInternalWrap=function(t){var e=t.composer,n=t.wrap,r=t.internalFilter,o=t.internalType;return n===w||Ai(e,o,r,n)?n:w},li.getGPULayerInternalFilter=function(t){var e=t.filter;if(e===y)return e;var n=t.composer,r=t.internalType,o=t.wrapX,i=t.wrapY,a=t.name;r===u&&((bi(n,hi,!0)||bi(n,_i,!0))&&Ai(n,r,e,o)&&Ai(n,r,e,i)||(console.warn("This browser does not support ".concat(e," filtering for type ").concat(r," and wrap [").concat(o,", ").concat(i,']. Falling back to NEAREST filter for GPULayer "').concat(a,'" with ').concat(e," polyfill in fragment shader.")),e=y));r===l&&(bi(n,_i,!0)&&Ai(n,r,e,o)&&Ai(n,r,e,i)||(console.warn("This browser does not support ".concat(e," filtering for type ").concat(r," and wrap [").concat(o,", ").concat(i,']. Falling back to NEAREST filter for GPULayer "').concat(a,'" with ').concat(e," polyfill in fragment shader.")),e=y));return e},li.getGLTextureParameters=function(t){var e,n,r,o,i=t.composer,a=t.name,c=t.numComponents,s=t.internalType,v=i.gl,g=i.glslVersion;if(i.isWebGL2){if(o=c,3===c&&(o=4),s===l||s===u)switch(o){case 1:n=v.RED;break;case 2:n=v.RG;break;case 4:n=v.RGBA;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}else switch(o){case 1:n=v.RED_INTEGER;break;case 2:n=v.RG_INTEGER;break;case 4:n=v.RGBA_INTEGER;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}switch(s){case u:switch(e=v.HALF_FLOAT,o){case 1:r=v.R16F;break;case 2:r=v.RG16F;break;case 4:r=v.RGBA16F;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;case l:switch(e=v.FLOAT,o){case 1:r=v.R32F;break;case 2:r=v.RG32F;break;case 4:r=v.RGBA32F;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;case f:if(e=v.UNSIGNED_BYTE,g===S&&s===f)r=n;else switch(o){case 1:r=v.R8UI;break;case 2:r=v.RG8UI;break;case 4:r=v.RGBA8UI;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;case p:switch(e=v.BYTE,o){case 1:r=v.R8I;break;case 2:r=v.RG8I;break;case 4:r=v.RGBA8I;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;case h:switch(e=v.SHORT,o){case 1:r=v.R16I;break;case 2:r=v.RG16I;break;case 4:r=v.RGBA16I;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;case _:switch(e=v.UNSIGNED_SHORT,o){case 1:r=v.R16UI;break;case 2:r=v.RG16UI;break;case 4:r=v.RGBA16UI;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;case d:switch(e=v.INT,o){case 1:r=v.R32I;break;case 2:r=v.RG32I;break;case 4:r=v.RGBA32I;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;case m:switch(e=v.UNSIGNED_INT,o){case 1:r=v.R32UI;break;case 2:r=v.RG32UI;break;case 4:r=v.RGBA32UI;break;default:throw new Error("Unsupported glNumChannels: ".concat(o,' for GPULayer "').concat(a,'".'))}break;default:throw new Error('Unsupported type: "'.concat(s,'" for GPULayer "').concat(a,'".'))}}else{if(c<1||c>4)throw new Error("Unsupported numComponents: ".concat(c,' for GPULayer "').concat(a,'".'));switch(o=4,n=v.RGBA,r=v.RGBA,s){case l:e=v.FLOAT;break;case u:e=v.HALF_FLOAT||bi(i,pi).HALF_FLOAT_OES;break;default:throw new Error('Unsupported type: "'.concat(s,'" in WebGL 1.0 for GPULayer "').concat(a,'".'))}}if(void 0===e||void 0===n||void 0===r){var y=[];throw void 0===e&&y.push("glType"),void 0===n&&y.push("glFormat"),void 0===r&&y.push("glInternalFormat"),new Error("Invalid type: ".concat(s," for numComponents: ").concat(c,", unable to init parameter").concat(y.length>1?"s":""," ").concat(y.join(", "),' for GPULayer "').concat(a,'".'))}if(void 0===o||c<1||c>4||o 16,777,216 are not supported, on mobile UNSIGNED_INT, INT, UNSIGNED_SHORT, and SHORT with absolute value > 2,048 may not be supported.')),a=l)),o){if(a===l)if(bi(e,mi,!0))xi(e,a)||(console.warn('FLOAT not supported for writing operations in this browser, falling back to HALF_FLOAT type for GPULayer "'.concat(n,'".')),a=u);else console.warn('FLOAT not supported in this browser, falling back to HALF_FLOAT type for GPULayer "'.concat(n,'".')),a=u;if(a===u)bi(e,di,!0)||bi(e,mi,!0),xi(e,a)||(console.warn("This browser does not support writing to HALF_FLOAT textures."),r("This browser does not support writing to HALF_FLOAT textures."))}else{if(a===l)if(bi(e,fi,!0))xi(e,a)||(console.warn('FLOAT not supported for writing operations in this browser, falling back to HALF_FLOAT type for GPULayer "'.concat(n,'".')),a=u);else console.warn('FLOAT not supported in this browser, falling back to HALF_FLOAT type for GPULayer "'.concat(n,'".')),a=u;if(a===u)bi(e,pi,!0),xi(e,a)||console.warn("This browser does not support writing to HALF_FLOAT textures.")}return a},li.validateGPULayerArray=function(t,e){var n=e.numComponents,r=e.width,o=e.height,i=e.name,a=e._glNumChannels,c=e._internalType,s=e.is1D()?e.length:null;if(t.length!==r*o*n&&(!s||s&&t.length!==s*n))throw new Error("Invalid data length: ".concat(t.length,' for GPULayer "').concat(i,'" of ').concat(s?"length ".concat(s," and "):"","dimensions: [").concat(r,", ").concat(o,"] and numComponents: ").concat(n,"."));var v=!1;switch(t.constructor){case Array:v=!0;break;case Float32Array:v=c!==l;break;case Uint8Array:v=c!==f;break;case Int8Array:v=c!==p;break;case Uint16Array:v=c!==_;break;case Int16Array:v=c!==h;break;case Uint32Array:v=c!==m;break;case Int32Array:v=c!==d;break;default:throw new Error("Invalid array type: ".concat(t.constructor.name,' for GPULayer "').concat(i,'", please use one of [').concat(P.map((function(t){return t.name})).join(", "),"]."))}var g=Ui(c),y=g.min,b=g.max,w=r*o*a,E=t.length!==w,x=t;if(v||E){x=li.initArrayForType(c,w);for(var A=c===u&&v?new DataView(x.buffer):null,U=0,T=t.length/n;Ub&&(O=b,S=!0),S&&console.warn("Clipping out of range value ".concat(R," to ").concat(O,' for GPULayer "').concat(i,'" with internal type ').concat(c,"."));var L=U*a+I;A?Jo(A,2*L,O,!0):x[L]=O}}return x};var Ti=Object.freeze({__proto__:null,minMaxValuesForType:Ui,shouldCastIntTypeAsFloat:Pi,testFilterWrap:Ai,testWriteSupport:xi}),Ii=function(){function t(t,e,n,r){void 0===t&&(t=0),void 0===e&&(e=0),void 0===n&&(n=0),void 0===r&&(r=1),this.x=t,this.y=e,this.z=n,this.w=r}return Object.defineProperty(t.prototype,"width",{get:function(){return this.z},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"height",{get:function(){return this.w},enumerable:!1,configurable:!0}),t.prototype.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this.w=t.w,this},t}(),Ri="\nin vec2 a_gpuio_position;\n#ifdef ".concat(lt,"\n\tin vec2 a_gpuio_uv;\n#endif\n#ifdef ").concat(ft,"\n\tin vec2 a_gpuio_normal;\n#endif\n\nuniform vec2 u_gpuio_scale;\nuniform vec2 u_gpuio_translation;\n\nout vec2 v_uv;\nout vec2 v_uv_local;\n#ifdef ").concat(ft,"\n\tout vec2 v_normal;\n#endif\n\nvoid main() {\n\t// Optional varyings.\n\t#ifdef ").concat(lt,"\n\t\tv_uv_local = a_gpuio_uv;\n\t#else\n\t\tv_uv_local = 0.5 * (a_gpuio_position + 1.0);\n\t#endif\n\t#ifdef ").concat(ft,"\n\t\tv_normal = a_gpuio_normal;\n\t#endif\n\n\t// Apply transformations.\n\tvec2 position = u_gpuio_scale * a_gpuio_position + u_gpuio_translation;\n\n\t// Calculate a global uv for the viewport.\n\tv_uv = 0.5 * (position + 1.0);\n\n\t// Calculate vertex position.\n\tgl_Position = vec4(position, 0, 1);\n}"),Oi='\n/**\n * Create UV coordinates from a 1D index for data stored in a texture of size "dimensions".\n */\nvec2 uvFromIndex(const float index, const vec2 dimensions) {\n\tfloat y = floor((index + 0.5) / dimensions.x);\n\tfloat x = floor(index - y * dimensions.x + 0.5);\n\treturn vec2(x + 0.5, y + 0.5) / dimensions;\n}\nvec2 uvFromIndex(const int index, const vec2 dimensions) {\n\tint width = int(dimensions.x);\n\tint y = index / width;\n\tint x = index - y * width;\n\treturn vec2(float(x) + 0.5, float(y) + 0.5) / dimensions;\n}\nvec2 uvFromIndex(const float index, const ivec2 dimensions) {\n\tfloat width = float(dimensions.x);\n\tfloat y = floor((index + 0.5) / width);\n\tfloat x = floor(index - y * width + 0.5);\n\treturn vec2(x + 0.5, y + 0.5) / vec2(dimensions);\n}\nvec2 uvFromIndex(const int index, const ivec2 dimensions) {\n\tint y = index / dimensions.x;\n\tint x = index - y * dimensions.x;\n\treturn vec2(float(x) + 0.5, float(y) + 0.5) / vec2(dimensions);\n}',Si="\n".concat(Oi,"\n\n#if (__VERSION__ != 300 || ").concat(ut," == 1)\n\t// Cannot use int vertex attributes.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer\n\tin float a_gpuio_index;\n#endif\n\nuniform sampler2D u_gpuio_positions; // Texture lookup with position data.\nuniform vec2 u_gpuio_positionsDimensions;\nuniform vec2 u_gpuio_scale;\n\nout vec2 v_uv;\nout vec2 v_lineWrapping; // Use this to test if line is only half wrapped and should not be rendered.\nflat out int v_index;\n\nvoid main() {\n\t// Calculate a uv based on the point's index attribute.\n\t#if (__VERSION__ != 300 || ").concat(ut," == 1)\n\t\tvec2 positionUV = uvFromIndex(a_gpuio_index, u_gpuio_positionsDimensions);\n\t\tv_index = int(a_gpuio_index);\n\t#else\n\t\tvec2 positionUV = uvFromIndex(gl_VertexID, u_gpuio_positionsDimensions);\n\t\tv_index = gl_VertexID;\n\t#endif\n\n\t// Calculate a global uv for the viewport.\n\t// Lookup vertex position and scale to [0, 1] range.\n\t#ifdef ").concat(pt,"\n\t\t// We have packed a 2D displacement with the position.\n\t\tvec4 positionData = texture(u_gpuio_positions, positionUV);\n\t\t// position = first two components plus last two components (optional accumulation buffer).\n\t\tv_uv = (positionData.rg + positionData.ba) * u_gpuio_scale;\n\t#else\n\t\tv_uv = texture(u_gpuio_positions, positionUV).rg * u_gpuio_scale;\n\t#endif\n\n\t// Wrap if needed.\n\tv_lineWrapping = vec2(0.0);\n\t#ifdef ").concat(ct,"\n\t\tv_lineWrapping.x = max(step(1.0, v_uv.x), step(v_uv.x, 0.0));\n\t\tv_ux.x = fract(v_uv.x + 1.0);\n\t#endif\n\t#ifdef ").concat(st,"\n\t\tv_lineWrapping.y = max(step(1.0, v_uv.y), step(v_uv.y, 0.0));\n\t\tv_ux.y = fract(v_uv.y + 1.0);\n\t#endif\n\n\t// Calculate position in [-1, 1] range.\n\tvec2 position = v_uv * 2.0 - 1.0;\n\n\tgl_Position = vec4(position, 0, 1);\n}"),Li="\n".concat(Oi,"\n\n#if (__VERSION__ != 300)\n\t// Cannot use int vertex attributes.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer\n\tin float a_gpuio_index;\n#endif\n\nuniform sampler2D u_gpuio_positions; // Texture lookup with position data.\nuniform vec2 u_gpuio_positionsDimensions;\nuniform vec2 u_gpuio_scale;\nuniform float u_gpuio_pointSize;\n\nout vec2 v_uv;\nout vec2 v_uv_position;\nout vec2 v_position;\nflat out int v_index;\n\nvoid main() {\n\t// Calculate a uv based on the point's index attribute.\n\t#if (__VERSION__ == 300)\n\t\tv_uv_position = uvFromIndex(gl_VertexID, u_gpuio_positionsDimensions);\n\t\tv_index = gl_VertexID;\n\t#else\n\t\tv_uv_position = uvFromIndex(a_gpuio_index, u_gpuio_positionsDimensions);\n\t\tv_index = int(a_gpuio_index);\n\t#endif\n\n\t// Calculate a global uv for the viewport.\n\t// Lookup vertex position and scale to [0, 1] range.\n\t#ifdef ").concat(pt,"\n\t\t// We have packed a 2D displacement with the position.\n\t\tvec4 positionData = texture(u_gpuio_positions, v_uv_position);\n\t\t// position = first two components plus last two components (optional accumulation buffer).\n\t\tv_position = positionData.rg + positionData.ba;\n\t\tv_uv = v_position * u_gpuio_scale;\n\t#else\n\t\tv_position = texture(u_gpuio_positions, v_uv_position).rg;\n\t\tv_uv = v_position * u_gpuio_scale;\n\t#endif\n\n\t// Wrap if needed.\n\t#ifdef ").concat(ct,"\n\t\tv_uv.x = fract(v_uv.x + ceil(abs(v_uv.x)));\n\t#endif\n\t#ifdef ").concat(st,"\n\t\tv_uv.y = fract(v_uv.y + ceil(abs(v_uv.y)));\n\t#endif\n\n\t// Calculate position in [-1, 1] range.\n\tvec2 position = v_uv * 2.0 - 1.0;\n\n\tgl_PointSize = u_gpuio_pointSize;\n\tgl_Position = vec4(position, 0, 1);\n}"),Fi="\n".concat(Oi,"\n\n#if (__VERSION__ != 300)\n\t// Cannot use int vertex attributes.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer\n\tin float a_gpuio_index;\n#endif\n\nuniform sampler2D u_gpuio_vectors; // Texture lookup with vector data.\nuniform vec2 u_gpuio_dimensions;\nuniform vec2 u_gpuio_scale;\n\nout vec2 v_uv;\nflat out int v_index;\n\nvoid main() {\n\t#if (__VERSION__ == 300)\n\t\t// Divide index by 2.\n\t\tint index = gl_VertexID / 2;\n\t\tv_index = index;\n\t#else\n\t\t// Divide index by 2.\n\t\tfloat index = floor((a_gpuio_index + 0.5) / 2.0);\n\t\tv_index = int(index);\n\t#endif\n\n\t// Calculate a uv based on the vertex index attribute.\n\tv_uv = uvFromIndex(index, u_gpuio_dimensions);\n\t#if (__VERSION__ == 300)\n\t\t// Add vector displacement if needed.\n\t\tv_uv += float(gl_VertexID - 2 * index) * texture(u_gpuio_vectors, v_uv).xy * u_gpuio_scale;\n\t#else\n\t\t// Add vector displacement if needed.\n\t\tv_uv += (a_gpuio_index - 2.0 * index) * texture(u_gpuio_vectors, v_uv).xy * u_gpuio_scale;\n\t#endif\n\n\n\t// Calculate position in [-1, 1] range.\n\tvec2 position = v_uv * 2.0 - 1.0;\n\n\tgl_Position = vec4(position, 0, 1);\n}"),Ni="\n".concat(Oi,"\n\n#if (__VERSION__ != 300)\n\t// Cannot use int vertex attributes.\n\t// https://developer.mozilla.org/en-US/docs/Web/API/WebGLRenderingContext/vertexAttribPointer\n\tin float a_gpuio_index;\n#endif\n\nuniform sampler2D u_gpuio_positions; // Texture lookup with position data.\nuniform vec2 u_gpuio_positionsDimensions;\nuniform vec2 u_gpuio_scale;\n\nout vec2 v_uv;\nout vec2 v_uv_position;\nout vec2 v_position;\nflat out int v_index;\n\nvoid main() {\n\t// Calculate a uv based on the point's index attribute.\n\t#if (__VERSION__ == 300)\n\t\tv_uv_position = uvFromIndex(gl_VertexID, u_gpuio_positionsDimensions);\n\t\tv_index = gl_VertexID;\n\t#else\n\t\tv_uv_position = uvFromIndex(a_gpuio_index, u_gpuio_positionsDimensions);\n\t\tv_index = int(a_gpuio_index);\n\t#endif\n\n\t// Calculate a global uv for the viewport.\n\t// Lookup vertex position and scale to [0, 1] range.\n\t#ifdef ").concat(pt,"\n\t\t// We have packed a 2D displacement with the position.\n\t\tvec4 positionData = texture(u_gpuio_positions, v_uv_position);\n\t\t// position = first two components plus last two components (optional accumulation buffer).\n\t\tv_position = positionData.rg + positionData.ba;\n\t\tv_uv = v_position * u_gpuio_scale;\n\t#else\n\t\tv_position = texture(u_gpuio_positions, v_uv_position).rg;\n\t\tv_uv = v_position * u_gpuio_scale;\n\t#endif\n\n\t// Calculate position in [-1, 1] range.\n\tvec2 position = v_uv * 2.0 - 1.0;\n\n\tgl_Position = vec4(position, 0, 1);\n}"),Gi=function(){function t(e,r){var o=this;this._fragmentShaders={},this._compileTimeConstants={},this._uniforms={},this._programs={},this._programsKeyLookup=new WeakMap,this._samplerUniformsIndices=[];var i=(r||{}).name;if(!e)throw new Error('Error initing GPUProgram "'.concat(i,'": must pass GPUComposer instance to GPUProgram(composer, params).'));if(!r)throw new Error("Error initing GPUProgram: must pass params to GPUProgram(composer, params).");if(!s.isObject(r))throw new Error("Error initing GPUProgram: must pass valid params object to GPUProgram(composer, params), got ".concat(JSON.stringify(r),"."));var a=Object.keys(r);oi(a,["name","fragmentShader","uniforms","compileTimeConstants"],"GPUProgram(composer, params)",r.name),ii(a,["name","fragmentShader"],"GPUProgram(composer, params)",r.name);var c=r.fragmentShader,u=r.uniforms,l=r.compileTimeConstants;this._composer=e,this.name=i;var f=nn(s.isString(c)?c:c.join("\n"),e.glslVersion,i),p=f.shaderSource,_=f.samplerUniforms,h=f.additionalSources;if(this._fragmentShaderSource=p,_.forEach((function(t,e){o._samplerUniformsIndices.push({name:t,inputIndex:0,shaderIndex:e})})),this.constructor===t&&h){this._childPrograms=[];for(var m=0,d=h.length;m4)throw new Error("Invalid uniform value: [".concat(e.join(", "),'] passed to GPUProgram "').concat(this.name,', uniforms must be of type number[] with length <= 4, number, or boolean."'));var p=null===(r=a[t])||void 0===r?void 0:r.type;if(n){var _=rn(e,n,t,this.name);if(void 0===p)p=_;else if(p!==_)throw new Error('Uniform "'.concat(t,'" for GPUProgram "').concat(this.name,'" cannot change from type ').concat(p," to type ").concat(_,"."))}if(void 0===p)throw new Error('Unknown type for uniform "'.concat(t,'", please pass in type to GPUProgram.setUniform(name, value, type) when initing a new uniform.'));if(this._cacheUniformValue(t,e,p)){var h=u.find((function(e){return e.name===t}));h&&s.isInteger(e)&&(h.inputIndex=e),l&&console.log('Setting uniform "'.concat(t,'" for program "').concat(this.name,'" to value ').concat(JSON.stringify(e),"."));for(var m=Object.keys(i),d=0,v=m.length;d=0?console.warn("Found > 1 sampler2D uniforms at texture index ".concat(s,' for GPUProgram "').concat(this.name,'".')):o[s]=u}i=0;for(var l=e.length;i=0?e:i(i([],e,!0),[t],!1):e===t||e.layer===t?[e]:[e,t]},t.prototype._passThroughLayerDataFromInputToOutput=function(t){var e=this._copyProgramForType(t._internalType);this.step({program:e,input:t,output:t})},t.prototype._setOutputLayer=function(t,e,n,r){var o=this.gl,i=this.isWebGL2;if(r){for(var a=s.isArray(r)?r:[r],c=0,u=a.length;c=0)){if(1===l.numBuffers)throw new Error('Cannot use same buffer "'.concat(l.name,'" for input and output of a program. Try increasing the number of buffers in your output layer to at least 2 so you can render to nextState using currentState as an input.'));e?l._prepareForWrite(!0):(this._passThroughLayerDataFromInputToOutput(l),l._prepareForWrite(!1))}else e?l._prepareForWrite(!0):(l._usingTextureOverrideForCurrentBuffer()&&this._passThroughLayerDataFromInputToOutput(l),l._prepareForWrite(!1))}var f=a[0],p=void 0,_=[o.COLOR_ATTACHMENT0];if(a.length>1){p=[];for(c=1,u=a.length;cp)throw new Error("Invalid count ".concat(_," for layer parameter of length ").concat(p,"."));c===S&&_>Ut&&console.warn("Points positions array length: ".concat(_," is longer than what is supported by GLSL1 : ").concat(Ut,"."));var h=t.program;if(void 0===h){h=this._setValueProgramForType(l);var m=t.color||[1,0,0];if(3!==m.length)throw new Error("Color parameter must have length 3, got ".concat(JSON.stringify(m),"."));h.setUniform("u_value",i(i([],m,!0),[1],!1),l)}var v=this._addLayerToInputs(u,t.input),g={};4===u.numComponents&&(g[pt]="1"),t.wrapX&&(g[ct]="1"),t.wrapY&&(g[st]="1");var y=this._drawSetup(h,rt,g,!1,v,f);h._setVertexUniform(y,"u_gpuio_positions",on(u,v),d);var b=this._width,w=this._height;t.useOutputScale&&(b=(e=this._widthHeightForOutput(h.name,f)).width,w=e.height),h._setVertexUniform(y,"u_gpuio_scale",[1/b,1/w],l);var E=t.pointSize||1;h._setVertexUniform(y,"u_gpuio_pointSize",E,l);var P=[u.width,u.height];if(h._setVertexUniform(y,"u_gpuio_positionsDimensions",P,l),c===S){if(void 0===this._pointIndexBuffer||a&&a.length<_){var x=Qe(p);this._pointIndexArray=x,this._pointIndexBuffer=this._initVertexBuffer(x)}o.bindBuffer(o.ARRAY_BUFFER,this._pointIndexBuffer),this._setIndexAttribute(y,h.name)}this._setBlendMode(t.blendAlpha),o.drawArrays(o.POINTS,0,_),this._drawFinish(t)}}},t.prototype.drawLayerAsVectorField=function(t){var e=Object.keys(t);if(oi(e,["layer","program","input","output","vectorSpacing","vectorScale","color","blendAlpha"],"GPUComposer.drawLayerAsVectorField(params)"),ii(e,["layer"],"GPUComposer.drawLayerAsVectorField(params)"),!this._iterateOverOutputsIfNeeded(t,"drawLayerAsVectorField")){var n=this,r=n.gl,o=n._vectorFieldIndexArray,a=n._width,c=n._height,s=n.glslVersion,u=n._errorState,f=t.layer,p=t.output;if(!u){if(2!==f.numComponents)throw new Error('GPUComposer.drawLayerAsVectorField() must be passed a fieldLayer with 2 components, got fieldLayer "'.concat(f.name,'" with ').concat(f.numComponents," components."));var _=t.program;if(void 0===_){_=this._setValueProgramForType(l);var h=t.color||[1,0,0];if(3!==h.length)throw new Error("color parameter must have length 3, got ".concat(JSON.stringify(h),"."));_.setUniform("u_value",i(i([],h,!0),[1],!1),l)}var m=this._addLayerToInputs(f,t.input),v=this._drawSetup(_,it,{},!1,m,p);_._setVertexUniform(v,"u_gpuio_vectors",on(f,m),d);var g=t.vectorScale||1;_._setVertexUniform(v,"u_gpuio_scale",[g/a,g/c],l);var y=t.vectorSpacing||10,b=[Math.floor(a/y),Math.floor(c/y)];_._setVertexUniform(v,"u_gpuio_dimensions",b,l);var w=2*b[0]*b[1];if(s===S){if(void 0===this._vectorFieldIndexBuffer||o&&o.lengthUt&&console.warn("Mesh positions array length: ".concat(m," is longer than what is supported by GLSL1 : ").concat(Ut,"."));var v=t.program;if(void 0===v){v=this._setValueProgramForType(l);var g=t.color||[1,0,0];if(3!==g.length)throw new Error("Color parameter must have length 3, got ".concat(JSON.stringify(g),"."));v.setUniform("u_value",i(i([],g,!0),[1],!1),l)}var y=this._addLayerToInputs(_,t.input),b={};4===_.numComponents&&(b[pt]="1");var w=this._drawSetup(v,at,b,!1,y,h);v._setVertexUniform(w,"u_gpuio_positions",on(_,y),d);var E=a,P=c;t.useOutputScale&&(E=(e=this._widthHeightForOutput(v.name,h)).width,P=e.height),v._setVertexUniform(w,"u_gpuio_scale",[1/E,1/P],l);var x=[_.width,_.height];if(v._setVertexUniform(w,"u_gpuio_positionsDimensions",x,l),s===S){if(void 0===f||p&&p.length0&&0==(t&t-1)},initSequentialFloatArray:Qe,uniformInternalTypeForValue:rn,indexOfLayerInArray:on,readPixelsAsync:sn},wi),ie),ai),Ti),Ce),Dt),Wi=He,ji=function(){if(void 0===Be.supportsWebGL2){var t=document.createElement("canvas").getContext(L);Be.supportsWebGL2=He(t)}return Be.supportsWebGL2},Xi=Je,Hi=qe,Yi=function(){if(void 0===Be.mediumpVertexPrecision){var t=document.createElement("canvas").getContext("webgl");if(!t)throw new Error("Unable to init webgl context.");var e=je(t,S,B,B,"\n\tattribute vec4 position; // needed because of another bug in Safari\n\tuniform mediump vec3 v;\n\tvarying mediump vec4 v_result;\n\tvoid main() {\n\t\tgl_Position = position;\n\t\tgl_PointSize = 1.0;\n\t\tv_result = vec4(normalize(v) * 0.5 + 0.5, 1);\n\t}\n\t\t",t.VERTEX_SHADER,"mediumpPrecisionVertexTest",_t);if(!e)throw new Error("Unable to init vertex shader.");var n=je(t,S,B,B,"\n\tvarying mediump vec4 v_result;\n\tvoid main() {\n\t\tgl_FragColor = v_result;\n\t}\n\t\t",t.FRAGMENT_SHADER,"mediumpPrecisionVertexTest",_t);if(!n)throw new Error("Unable to init fragment shader.");var r=Math.pow(2,31)-1,o=Math.sqrt(r),i=255*(o/Math.sqrt(o*o*3)*.5+.5)|0,a=Ke("mediumpPrecisionVertexTest",t,n,e,(function(e){var n=t.getUniformLocation(e,"v");t.uniform3f(n,o,o,o)})),c=Math.abs(a[0]-i)>16;Be.mediumpVertexPrecision=c?B:V}return Be.mediumpVertexPrecision},zi=function(){if(void 0===Be.mediumpFragmentPrecision){var t=document.createElement("canvas").getContext("webgl");if(!t)throw new Error("Unable to init webgl context.");var e=je(t,S,B,B,"\n\tattribute vec4 position; // needed because of another bug in Safari\n\tvoid main() {\n\t\tgl_Position = position;\n\t\tgl_PointSize = 1.0;\n\t}\n\t\t",t.VERTEX_SHADER,"mediumpPrecisionFragmentTest",_t);if(!e)throw new Error("Unable to init vertex shader.");var n=je(t,S,B,B,"\n\tuniform mediump vec3 v;\n\tvoid main() {\n\t\tgl_FragColor = vec4(normalize(v) * 0.5 + 0.5, 1);\n\t}\n\t\t",t.FRAGMENT_SHADER,"mediumpPrecisionFragmentTest",_t);if(!n)throw new Error("Unable to init fragment shader.");var r=Math.pow(2,31)-1,o=Math.sqrt(r),i=255*(o/Math.sqrt(o*o*3)*.5+.5)|0,a=Ke("mediumpPrecisionFragmentTest",t,n,e,(function(e){var n=t.getUniformLocation(e,"v");t.uniform3f(n,o,o,o)})),c=Math.abs(a[0]-i)>16;Be.mediumpFragmentPrecision=c?B:V}return Be.mediumpFragmentPrecision},Ji=Bi,qi=function(t,e){var n=e.type,r=e.numInputs||2,o=e.precision||"",i=e.components||"xyzw",a=Ct(n,i.length),c=new Array(r),s=e.name||"".concat(r,"-way_add_").concat(Nt(n,t.glslVersion),"_").concat(i);return new Gi(t,{name:s,fragmentShader:"\nin vec2 v_uv;\n".concat(c.map((function(t,e){return"uniform ".concat(o," ").concat(Bt(n),"sampler2D u_state").concat(e,";")})).join("\n"),"\nout ").concat(o," ").concat(a," out_result;\nvoid main() {\n\tout_result = ").concat(c.map((function(t,e){return"texture(u_state".concat(e,", v_uv).").concat(i)})).join(" + "),";\n}"),uniforms:c.map((function(t,e){return{name:"u_state".concat(e),value:e,type:d}}))})},Ki=function(t,e){var n=e.type,r=e.value,o=e.precision||"",i=s.isArray(r)?r.length:1,a=Ct(n,i),c=1===i?4:i,u=Ct(n,c),l=Vt(c),f=e.name||"addValue_".concat(a,"_w_length_").concat(i);return new Gi(t,{name:f,fragmentShader:"\nin vec2 v_uv;\nuniform ".concat(o," ").concat(a," u_value;\nuniform ").concat(o," ").concat(Bt(n),"sampler2D u_state;\nout ").concat(o," ").concat(u," out_result;\nvoid main() {\n\tout_result = ").concat(a!==u?u:"","(u_value) + texture(u_state, v_uv)").concat(l,";\n}"),uniforms:[{name:"u_state",value:0,type:d},{name:"u_value",value:r,type:Nt(n,t.glslVersion)}]})},Qi=function(t,e){var n=e.type,r=e.value,o=e.precision||"",i=s.isArray(r)?r.length:1,a=Ct(n,i),c=1===i?4:i,u=Ct(n,c),l=Vt(c),f=e.name||"addValue_".concat(a,"_w_length_").concat(i);return new Gi(t,{name:f,fragmentShader:"\nin vec2 v_uv;\nuniform ".concat(o," ").concat(a," u_value;\nuniform ").concat(o," ").concat(Bt(n),"sampler2D u_state;\nout ").concat(o," ").concat(u," out_result;\nvoid main() {\n\tout_result = ").concat(a!==u?u:"","(u_value) * texture(u_state, v_uv)").concat(l,";\n}"),uniforms:[{name:"u_state",value:0,type:d},{name:"u_value",value:r,type:Nt(n,t.glslVersion)}]})},$i=Vi,Zi=function(t,e){var n=e.type,r=e.precision||"",o=void 0===e.opacity?1:e.opacity,i=e.color||[0,0,0],a=e.name||"setColor",c=Ct(n,4);return new Gi(t,{name:a,fragmentShader:"\nuniform ".concat(r," vec3 u_color;\nuniform ").concat(r," float u_opacity;\nout ").concat(r," ").concat(c," out_result;\nvoid main() {\n\tout_result = ").concat(c,"(u_color, u_opacity);\n}"),uniforms:[{name:"u_color",value:i,type:l},{name:"u_opacity",value:o,type:l}]})},ta=function(t,e){return Vi(t,{type:l,value:0,name:e.name})},ea=function(t,e){var n=e.type,r=e.precision||"",o=Ct(n,3),i=Ct(l,3),a=Bt(n),c=i===o,s=e.name||"renderRGB_".concat(o);return new Gi(t,{name:s,fragmentShader:"\nin vec2 v_uv;\nuniform float u_opacity;\nuniform float u_scale;\nuniform ".concat(r," ").concat(a,"sampler2D u_state;\nout vec4 out_result;\nvoid main() {\n\tvec3 color = u_scale * (").concat(c?"":i,"(texture(u_state, v_uv).rgb));\n\tout_result = vec4(color, u_opacity);\n}"),uniforms:[{name:"u_state",value:0,type:d},{name:"u_scale",value:void 0!==e.scale?e.scale:1,type:l},{name:"u_opacity",value:void 0!==e.opacity?e.opacity:1,type:l}]})},na=function(t,e){var n=e.type,r=e.precision||"",o=e.components||"xyzw",i=o.length,a=Ct(n,i),c=Ct(l,i),s=Bt(n),u=c===a,f=e.name||"renderAmplitude_".concat(a,"_w_").concat(i,"_components");return new Gi(t,{name:f,fragmentShader:"\nin vec2 v_uv;\nuniform float u_opacity;\nuniform float u_scale;\nuniform vec3 u_colorMax;\nuniform vec3 u_colorMin;\nuniform ".concat(r," ").concat(s,"sampler2D u_state;\nout vec4 out_result;\nvoid main() {\n\tfloat amplitude = u_scale * ").concat(1===i?"abs":"length","(").concat(u?"":c,"(texture(u_state, v_uv)").concat("xyzw"===o||"rgba"===o||"stpq"===o?"":".".concat(o),"));\n\tvec3 color = mix(u_colorMin, u_colorMax, amplitude);\n\tout_result = vec4(color, u_opacity);\n}"),uniforms:[{name:"u_state",value:0,type:d},{name:"u_scale",value:void 0!==e.scale?e.scale:1,type:l},{name:"u_opacity",value:void 0!==e.opacity?e.opacity:1,type:l},{name:"u_colorMax",value:e.colorMax||[1,1,1],type:l},{name:"u_colorMin",value:e.colorMin||[0,0,0],type:l}]})},ra=function(t,e){var n=e.type,r=e.precision||"",o=Ct(n,1),i=Bt(n),a="float"===o,c=e.component||"x",s=e.name||"renderAmplitude_".concat(o,"_").concat(c);return new Gi(t,{name:s,fragmentShader:"\nin vec2 v_uv;\nuniform float u_opacity;\nuniform float u_scale;\nuniform float u_bias;\nuniform vec3 u_colorMin;\nuniform vec3 u_colorMax;\nuniform vec3 u_colorCenter;\nuniform ".concat(r," ").concat(i,"sampler2D u_state;\nout vec4 out_result;\nvoid main() {\n\tfloat signedAmplitude = u_scale * (").concat(a?"":"float","(texture(u_state, v_uv).").concat(c,") - u_bias);\n\tfloat amplitudeSign = sign(signedAmplitude);\n\tvec3 interpColor = mix(u_colorMin, u_colorMax, amplitudeSign / 2.0 + 0.5);\n\tvec3 color = mix(u_colorCenter, interpColor, signedAmplitude * amplitudeSign);\n\tout_result = vec4(color, u_opacity);\n}"),uniforms:[{name:"u_state",value:0,type:d},{name:"u_scale",value:void 0!==e.scale?e.scale:1,type:l},{name:"u_bias",value:e.bias||0,type:l},{name:"u_opacity",value:void 0!==e.opacity?e.opacity:1,type:l},{name:"u_colorMin",value:e.colorMin||[0,0,1],type:l},{name:"u_colorMax",value:e.colorMax||[1,0,0],type:l},{name:"u_colorCenter",value:e.colorCenter||[1,1,1],type:l}]})};t.BOOL=v,t.BOOL_1D_UNIFORM=Q,t.BOOL_2D_UNIFORM=$,t.BOOL_3D_UNIFORM=Z,t.BOOL_4D_UNIFORM=tt,t.BOUNDARY_BOTTOM=Ot,t.BOUNDARY_LEFT=St,t.BOUNDARY_RIGHT=Lt,t.BOUNDARY_TOP=Rt,t.BYTE=p,t.CLAMP_TO_EDGE=w,t.DEFAULT_CIRCLE_NUM_SEGMENTS=18,t.DEFAULT_ERROR_CALLBACK=_t,t.DEFAULT_PROGRAM_NAME=et,t.EXPERIMENTAL_WEBGL=N,t.EXPERIMENTAL_WEBGL2=G,t.FLOAT=l,t.FLOAT_1D_UNIFORM=D,t.FLOAT_2D_UNIFORM=M,t.FLOAT_3D_UNIFORM=k,t.FLOAT_4D_UNIFORM=W,t.GLSL1=S,t.GLSL3=O,t.GPUComposer=Di,t.GPUIO_FLOAT_PRECISION=It,t.GPUIO_INT_PRECISION=Tt,t.GPUIO_VS_INDEXED_POSITIONS=ut,t.GPUIO_VS_NORMAL_ATTRIBUTE=ft,t.GPUIO_VS_POSITION_W_ACCUM=pt,t.GPUIO_VS_UV_ATTRIBUTE=lt,t.GPUIO_VS_WRAP_X=ct,t.GPUIO_VS_WRAP_Y=st,t.GPUIndexBuffer=Mi,t.GPULayer=li,t.GPUProgram=Gi,t.HALF_FLOAT=u,t.INT=d,t.INT_1D_UNIFORM=j,t.INT_2D_UNIFORM=X,t.INT_3D_UNIFORM=H,t.INT_4D_UNIFORM=Y,t.LAYER_LINES_PROGRAM_NAME=ot,t.LAYER_MESH_PROGRAM_NAME=at,t.LAYER_POINTS_PROGRAM_NAME=rt,t.LAYER_VECTOR_FIELD_PROGRAM_NAME=it,t.LINEAR=b,t.MAX_BYTE=vt,t.MAX_FLOAT_INT=Ut,t.MAX_HALF_FLOAT_INT=2048,t.MAX_INT=At,t.MAX_SHORT=wt,t.MAX_UNSIGNED_BYTE=mt,t.MAX_UNSIGNED_INT=Pt,t.MAX_UNSIGNED_SHORT=yt,t.MIN_BYTE=dt,t.MIN_FLOAT_INT=-16777216,t.MIN_HALF_FLOAT_INT=-2048,t.MIN_INT=xt,t.MIN_SHORT=bt,t.MIN_UNSIGNED_BYTE=ht,t.MIN_UNSIGNED_INT=Et,t.MIN_UNSIGNED_SHORT=gt,t.NEAREST=y,t.PRECISION_HIGH_P=V,t.PRECISION_LOW_P=C,t.PRECISION_MEDIUM_P=B,t.REPEAT=E,t.RGB="RGB",t.RGBA=T,t.SEGMENT_PROGRAM_NAME=nt,t.SHORT=h,t.UINT=g,t.UINT_1D_UNIFORM=z,t.UINT_2D_UNIFORM=J,t.UINT_3D_UNIFORM=q,t.UINT_4D_UNIFORM=K,t.UNSIGNED_BYTE=f,t.UNSIGNED_INT=m,t.UNSIGNED_SHORT=_,t.WEBGL1=F,t.WEBGL2=L,t._testing=ki,t.addLayersProgram=qi,t.addValueProgram=Ki,t.copyProgram=Ji,t.getFragmentShaderMediumpPrecision=zi,t.getVertexShaderMediumpPrecision=Yi,t.isHighpSupportedInFragmentShader=Hi,t.isHighpSupportedInVertexShader=Xi,t.isWebGL2=Wi,t.isWebGL2Supported=ji,t.multiplyValueProgram=Qi,t.renderAmplitudeProgram=na,t.renderRGBProgram=ea,t.renderSignedAmplitudeProgram=ra,t.setColorProgram=Zi,t.setValueProgram=$i,t.validArrayTypes=P,t.validDataTypes=x,t.validFilters=A,t.validImageFormats=I,t.validImageTypes=R,t.validWraps=U,t.zeroProgram=ta})); //# sourceMappingURL=gpu-io.min.js.map