planet/docs/main.js

2 lines
116 KiB
JavaScript

!function(e){var t={};function r(n){if(t[n])return t[n].exports;var a=t[n]={i:n,l:!1,exports:{}};return e[n].call(a.exports,a,a.exports,r),a.l=!0,a.exports}r.m=e,r.c=t,r.d=function(e,t,n){r.o(e,t)||Object.defineProperty(e,t,{enumerable:!0,get:n})},r.r=function(e){"undefined"!=typeof Symbol&&Symbol.toStringTag&&Object.defineProperty(e,Symbol.toStringTag,{value:"Module"}),Object.defineProperty(e,"__esModule",{value:!0})},r.t=function(e,t){if(1&t&&(e=r(e)),8&t)return e;if(4&t&&"object"==typeof e&&e&&e.__esModule)return e;var n=Object.create(null);if(r.r(n),Object.defineProperty(n,"default",{enumerable:!0,value:e}),2&t&&"string"!=typeof e)for(var a in e)r.d(n,a,function(t){return e[t]}.bind(null,a));return n},r.n=function(e){var t=e&&e.__esModule?function(){return e.default}:function(){return e};return r.d(t,"a",t),t},r.o=function(e,t){return Object.prototype.hasOwnProperty.call(e,t)},r.p="",r(r.s=16)}([function(e,t,r){e.exports=r.p+"dcbe4e47e8a4cb4c76f00dc2ca584ea3.bin"},function(e,t){e.exports=function(e){return e[0]=1,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=1,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=1,e[11]=0,e[12]=0,e[13]=0,e[14]=0,e[15]=1,e}},function(e,t,r){e.exports=r.p+"8c72ff38eff4b3d878b6e59563fb2558.bin"},function(e,t,r){e.exports=r.p+"c40f782b6d48c16bbdfa867a67914314.bin"},function(e,t,r){e.exports=r.p+"670398984b2a839f0da3039cd8ae215a.bin"},function(e,t,r){e.exports=r.p+"4cc86edf6517c35dd8aecdbf6a4b1a2e.bin"},function(e,t,r){e.exports=r.p+"aad316ae2f3185e637764ab20f4536ee.bin"},function(e,t,r){e.exports=r.p+"c5d1e42d1b2c2960ef12ca75b5e71fc1.bin"},function(e,t,r){e.exports=r.p+"80e3348d39fbc859dfe0bb2cda08c5b1.bin"},function(e,t,r){e.exports=r.p+"8ab0cc172cd882ef6b69422eaa5a502d.bin"},function(e,t,r){e.exports=r.p+"88a1fb4d8c42c36a027c7ab503de7511.bin"},function(e,t,r){e.exports=r.p+"a7a417e76651f9fa75e63e45e22095e6.bin"},function(e,t,r){e.exports=r.p+"b8f9c879c9c795656294aa401ac3854c.bin"},function(e,t,r){e.exports=r.p+"5293ee29e3db7bbd05f03823aa9bd53a.bin"},function(e,t,r){e.exports=r.p+"6f2d59ca82e22144ee26889cc862912f.bin"},function(e,t,r){e.exports=r.p+"f988ae2257d2f750090c9bda21c58f10.bin"},function(e,t,r){"use strict";r.r(t);var n=r(2),a=r.n(n),i=r(3),o=r.n(i),f=r(4),u=r.n(f),s=r(5),c=r.n(s),l=r(0),d=r.n(l),m=r(6),p=r.n(m),h=r(7),b=r.n(h),v=r(8),g=r.n(v),y=r(9),x=r.n(y),w=r(10),k=r.n(w),_=r(11),A=r.n(_),S=r(12),E=r.n(S),T=r(13),j=r.n(T),D=r(14),O=r.n(D),C=r(15),F=r.n(C);const z={hexsphere_0:a.a,hexsphere_1:o.a,hexsphere_2:u.a,hexsphere_3:c.a,hexsphere_4:d.a,hexsphere_5:p.a,hexsphere_6:b.a,icosahedron_0:g.a,icosahedron_1:x.a,icosahedron_2:k.a,icosahedron_3:A.a,icosahedron_4:E.a,icosahedron_5:j.a,icosahedron_6:O.a,icosahedron_7:F.a},L=r(17)({extensions:["OES_element_index_uint"]}),M=r(18)(L,{center:[0,0,0],distance:3});let P=null;const B=e=>{fetch(e).then(e=>e.arrayBuffer()).then(e=>{let t=new DataView(e),r=t.getUint32(0,!0),n=t.getUint32(4,!0);const a={positions:new Float32Array(e,8,3*r),normals:new Float32Array(e,12*r+8,3*r),colors:new Float32Array(e,24*r+8,3*r),cells:new Uint32Array(e,36*r+8,3*n)};P=(e=>L({vert:"\n precision mediump float;\n uniform mat4 projection, view;\n attribute vec3 position, normal, color;\n varying vec3 fragNormal, fragPosition, fragColor;\n void main() {\n fragNormal = normal;\n fragPosition = position;\n fragColor = color;\n gl_Position = projection * view * vec4(position, 1.0);\n }",frag:"\n precision mediump float;\n struct Light {\n vec3 color;\n vec3 position;\n };\n uniform Light lights[1];\n varying vec3 fragNormal, fragPosition, fragColor;\n void main() {\n vec3 normal = normalize(fragNormal);\n vec3 light = vec3(0.1, 0.1, 0.1);\n for (int i = 0; i < 1; i++) {\n vec3 lightDir = normalize(lights[i].position - fragPosition);\n float diffuse = max(0.0, dot(lightDir, normal));\n light += diffuse * lights[i].color;\n }\n gl_FragColor = vec4(fragColor * light, 1.0);\n }",attributes:{position:e.positions,normal:e.normals,color:e.colors},elements:e.cells,uniforms:{"lights[0].color":[1,1,1],"lights[0].position":({tick:e})=>{const t=.008*e;return[1e3*Math.cos(t),1e3*Math.sin(t),1e3*Math.sin(t)]}}}))(a),L.frame(()=>{L.clear({depth:1,color:[0,0,0,1]}),M(()=>{P()})}),R.style.display="none"})},I=document.querySelector("select#shape-select"),R=document.querySelector("#shape-loading");I.value="hexsphere_4",B(d.a),I.addEventListener("change",e=>{R.style.display="inline",B(z[e.target.value])})},function(e,t,r){e.exports=function(){"use strict";var e=function(e){return e instanceof Uint8Array||e instanceof Uint16Array||e instanceof Uint32Array||e instanceof Int8Array||e instanceof Int16Array||e instanceof Int32Array||e instanceof Float32Array||e instanceof Float64Array||e instanceof Uint8ClampedArray},t=function(e,t){for(var r=Object.keys(t),n=0;n<r.length;++n)e[r[n]]=t[r[n]];return e},r="\n";function n(e){var t=new Error("(regl) "+e);throw console.error(t),t}function a(e,t){e||n(t)}function i(e){return e?": "+e:""}function o(e,t,r){t.indexOf(e)<0&&n("invalid value"+i(r)+". must be one of: "+t)}var f=["gl","canvas","container","attributes","pixelRatio","extensions","optionalExtensions","profile","onDone"];function u(e,t){for(e+="";e.length<t;)e=" "+e;return e}function s(){this.name="unknown",this.lines=[],this.index={},this.hasErrors=!1}function c(e,t){this.number=e,this.line=t,this.errors=[]}function l(e,t,r){this.file=e,this.line=t,this.message=r}function d(){var e=new Error,t=(e.stack||e).toString(),r=/compileProcedure.*\n\s*at.*\((.*)\)/.exec(t);if(r)return r[1];var n=/compileProcedure.*\n\s*at\s+(.*)(\n|$)/.exec(t);return n?n[1]:"unknown"}function m(){var e=new Error,t=(e.stack||e).toString(),r=/at REGLCommand.*\n\s+at.*\((.*)\)/.exec(t);if(r)return r[1];var n=/at REGLCommand.*\n\s+at\s+(.*)\n/.exec(t);return n?n[1]:"unknown"}function p(e,t){var r,n=e.split("\n"),a=1,i=0,o={unknown:new s,0:new s};o.unknown.name=o[0].name=t||d(),o.unknown.lines.push(new c(0,""));for(var f=0;f<n.length;++f){var u=n[f],l=/^\s*\#\s*(\w+)\s+(.+)\s*$/.exec(u);if(l)switch(l[1]){case"line":var m=/(\d+)(\s+\d+)?/.exec(l[2]);m&&(a=0|m[1],m[2]&&((i=0|m[2])in o||(o[i]=new s)));break;case"define":var p=/SHADER_NAME(_B64)?\s+(.*)$/.exec(l[2]);p&&(o[i].name=p[1]?(r=p[2],"undefined"!=typeof atob?atob(r):"base64:"+r):p[2])}o[i].lines.push(new c(a++,u))}return Object.keys(o).forEach(function(e){var t=o[e];t.lines.forEach(function(e){t.index[e.number]=e})}),o}function h(e){e._commandRef=d()}function b(e,t){var r=m();n(e+" in command "+(t||d())+("unknown"===r?"":" called from "+r))}function v(e,t,r,n){typeof e!==t&&b("invalid parameter type"+i(r)+". expected "+t+", got "+typeof e,n||d())}var g=33071,y=9728,x=9984,w=9985,k=9986,_=9987,A=5126,S=32819,E=32820,T=33635,j=34042,D={};function O(e,t){return e===E||e===S||e===T?2:e===j?4:D[e]*t}function C(e){return!(e&e-1||!e)}D[5120]=D[5121]=1,D[5122]=D[5123]=D[36193]=D[T]=D[S]=D[E]=2,D[5124]=D[5125]=D[A]=D[j]=4;var F=t(a,{optional:function(e){e()},raise:n,commandRaise:b,command:function(e,t,r){e||b(t,r||d())},parameter:function(e,t,r){e in t||n("unknown parameter ("+e+")"+i(r)+". possible values: "+Object.keys(t).join())},commandParameter:function(e,t,r,n){e in t||b("unknown parameter ("+e+")"+i(r)+". possible values: "+Object.keys(t).join(),n||d())},constructor:function(e){Object.keys(e).forEach(function(e){f.indexOf(e)<0&&n('invalid regl constructor argument "'+e+'". must be one of '+f)})},type:function(e,t,r){typeof e!==t&&n("invalid parameter type"+i(r)+". expected "+t+", got "+typeof e)},commandType:v,isTypedArray:function(t,r){e(t)||n("invalid parameter type"+i(r)+". must be a typed array")},nni:function(e,t){e>=0&&(0|e)===e||n("invalid parameter type, ("+e+")"+i(t)+". must be a nonnegative integer")},oneOf:o,shaderError:function(e,t,n,i,o){if(!e.getShaderParameter(t,e.COMPILE_STATUS)){var f=e.getShaderInfoLog(t),s=i===e.FRAGMENT_SHADER?"fragment":"vertex";v(n,"string",s+" shader source must be a string",o);var c=p(n,o),d=function(e){var t=[];return e.split("\n").forEach(function(e){if(!(e.length<5)){var r=/^ERROR\:\s+(\d+)\:(\d+)\:\s*(.*)$/.exec(e);r?t.push(new l(0|r[1],0|r[2],r[3].trim())):e.length>0&&t.push(new l("unknown",0,e))}}),t}(f);!function(e,t){t.forEach(function(t){var r=e[t.file];if(r){var n=r.index[t.line];if(n)return n.errors.push(t),void(r.hasErrors=!0)}e.unknown.hasErrors=!0,e.unknown.lines[0].errors.push(t)})}(c,d),Object.keys(c).forEach(function(e){var t=c[e];if(t.hasErrors){var n=[""],a=[""];i("file number "+e+": "+t.name+"\n","color:red;text-decoration:underline;font-weight:bold"),t.lines.forEach(function(e){if(e.errors.length>0){i(u(e.number,4)+"| ","background-color:yellow; font-weight:bold"),i(e.line+r,"color:red; background-color:yellow; font-weight:bold");var t=0;e.errors.forEach(function(n){var a=n.message,o=/^\s*\'(.*)\'\s*\:\s*(.*)$/.exec(a);if(o){var f=o[1];switch(a=o[2],f){case"assign":f="="}t=Math.max(e.line.indexOf(f,t),0)}else t=0;i(u("| ",6)),i(u("^^^",t+3)+r,"font-weight:bold"),i(u("| ",6)),i(a+r,"font-weight:bold")}),i(u("| ",6)+r)}else i(u(e.number,4)+"| "),i(e.line+r,"color:red")}),"undefined"==typeof document||window.chrome?console.log(n.join("")):(a[0]=n.join("%c"),console.log.apply(console,a))}function i(e,t){n.push(e),a.push(t||"")}}),a.raise("Error compiling "+s+" shader, "+c[0].name)}},linkError:function(e,t,n,i,o){if(!e.getProgramParameter(t,e.LINK_STATUS)){var f=e.getProgramInfoLog(t),u=p(n,o),s=p(i,o),c='Error linking program with vertex shader, "'+s[0].name+'", and fragment shader "'+u[0].name+'"';"undefined"!=typeof document?console.log("%c"+c+r+"%c"+f,"color:red;text-decoration:underline;font-weight:bold","color:red"):console.log(c+r+f),a.raise(c)}},callSite:m,saveCommandRef:h,saveDrawInfo:function(e,t,r,n){function a(e){return e?n.id(e):0}function i(e,t){Object.keys(t).forEach(function(t){e[n.id(t)]=!0})}h(e),e._fragId=a(e.static.frag),e._vertId=a(e.static.vert);var o=e._uniformSet={};i(o,t.static),i(o,t.dynamic);var f=e._attributeSet={};i(f,r.static),i(f,r.dynamic),e._hasCount="count"in e.static||"count"in e.dynamic||"elements"in e.static||"elements"in e.dynamic},framebufferFormat:function(e,t,r){e.texture?o(e.texture._texture.internalformat,t,"unsupported texture format for attachment"):o(e.renderbuffer._renderbuffer.format,r,"unsupported renderbuffer format for attachment")},guessCommand:d,texture2D:function(e,t,r){var n,i=t.width,o=t.height,f=t.channels;a(i>0&&i<=r.maxTextureSize&&o>0&&o<=r.maxTextureSize,"invalid texture shape"),(e.wrapS!==g||e.wrapT!==g)&&a(C(i)&&C(o),"incompatible wrap mode for texture, both width and height must be power of 2"),1===t.mipmask?1!==i&&1!==o&&a(e.minFilter!==x&&e.minFilter!==k&&e.minFilter!==w&&e.minFilter!==_,"min filter requires mipmap"):(a(C(i)&&C(o),"texture must be a square power of 2 to support mipmapping"),a(t.mipmask===(i<<1)-1,"missing or incomplete mipmap data")),t.type===A&&(r.extensions.indexOf("oes_texture_float_linear")<0&&a(e.minFilter===y&&e.magFilter===y,"filter not supported, must enable oes_texture_float_linear"),a(!e.genMipmaps,"mipmap generation not supported with float textures"));var u=t.images;for(n=0;n<16;++n)if(u[n]){var s=i>>n,c=o>>n;a(t.mipmask&1<<n,"missing mipmap data");var l=u[n];if(a(l.width===s&&l.height===c,"invalid shape for mip images"),a(l.format===t.format&&l.internalformat===t.internalformat&&l.type===t.type,"incompatible type for mip image"),l.compressed);else if(l.data){var d=Math.ceil(O(l.type,f)*s/l.unpackAlignment)*l.unpackAlignment;a(l.data.byteLength===d*c,"invalid data for image, buffer size is inconsistent with image format")}else l.element||l.copy}else e.genMipmaps||a(0==(t.mipmask&1<<n),"extra mipmap data");t.compressed&&a(!e.genMipmaps,"mipmap generation for compressed images not supported")},textureCube:function(e,t,r,n){var i=e.width,o=e.height,f=e.channels;a(i>0&&i<=n.maxTextureSize&&o>0&&o<=n.maxTextureSize,"invalid texture shape"),a(i===o,"cube map must be square"),a(t.wrapS===g&&t.wrapT===g,"wrap mode not supported by cube map");for(var u=0;u<r.length;++u){var s=r[u];a(s.width===i&&s.height===o,"inconsistent cube map face shape"),t.genMipmaps&&(a(!s.compressed,"can not generate mipmap for compressed textures"),a(1===s.mipmask,"can not specify mipmaps and generate mipmaps"));for(var c=s.images,l=0;l<16;++l){var d=c[l];if(d){var m=i>>l,p=o>>l;a(s.mipmask&1<<l,"missing mipmap data"),a(d.width===m&&d.height===p,"invalid shape for mip images"),a(d.format===e.format&&d.internalformat===e.internalformat&&d.type===e.type,"incompatible type for mip image"),d.compressed||(d.data?a(d.data.byteLength===m*p*Math.max(O(d.type,f),d.unpackAlignment),"invalid data for image, buffer size is inconsistent with image format"):d.element||d.copy)}}}}}),z=0,L=0;function M(e,t){this.id=z++,this.type=e,this.data=t}function P(e){return e.replace(/\\/g,"\\\\").replace(/"/g,'\\"')}function B(e){return"["+function e(t){if(0===t.length)return[];var r=t.charAt(0),n=t.charAt(t.length-1);if(t.length>1&&r===n&&('"'===r||"'"===r))return['"'+P(t.substr(1,t.length-2))+'"'];var a=/\[(false|true|null|\d+|'[^']*'|"[^"]*")\]/.exec(t);if(a)return e(t.substr(0,a.index)).concat(e(a[1])).concat(e(t.substr(a.index+a[0].length)));var i=t.split(".");if(1===i.length)return['"'+P(t)+'"'];for(var o=[],f=0;f<i.length;++f)o=o.concat(e(i[f]));return o}(e).join("][")+"]"}var I={DynamicVariable:M,define:function(e,t){return new M(e,B(t+""))},isDynamic:function(e){return"function"==typeof e&&!e._reglType||e instanceof M},unbox:function(e,t){return"function"==typeof e?new M(L,e):e},accessor:B},R={next:"function"==typeof requestAnimationFrame?function(e){return requestAnimationFrame(e)}:function(e){return setTimeout(e,16)},cancel:"function"==typeof cancelAnimationFrame?function(e){return cancelAnimationFrame(e)}:clearTimeout},W="undefined"!=typeof performance&&performance.now?function(){return performance.now()}:function(){return+new Date};function H(e){return"string"==typeof e?e.split():(F(Array.isArray(e),"invalid extension array"),e)}function U(e){return"string"==typeof e?(F("undefined"!=typeof document,"not supported outside of DOM"),document.querySelector(e)):e}function N(e){var r,n,a,i,o,f=e||{},u={},s=[],c=[],l="undefined"==typeof window?1:window.devicePixelRatio,d=!1,m=function(e){e&&F.raise(e)},p=function(){};if("string"==typeof f?(F("undefined"!=typeof document,"selector queries only supported in DOM enviroments"),r=document.querySelector(f),F(r,"invalid query string for element")):"object"==typeof f?"string"==typeof(o=f).nodeName&&"function"==typeof o.appendChild&&"function"==typeof o.getBoundingClientRect?r=f:function(e){return"function"==typeof e.drawArrays||"function"==typeof e.drawElements}(f)?a=(i=f).canvas:(F.constructor(f),"gl"in f?i=f.gl:"canvas"in f?a=U(f.canvas):"container"in f&&(n=U(f.container)),"attributes"in f&&(u=f.attributes,F.type(u,"object","invalid context attributes")),"extensions"in f&&(s=H(f.extensions)),"optionalExtensions"in f&&(c=H(f.optionalExtensions)),"onDone"in f&&(F.type(f.onDone,"function","invalid or missing onDone callback"),m=f.onDone),"profile"in f&&(d=!!f.profile),"pixelRatio"in f&&(l=+f.pixelRatio,F(l>0,"invalid pixel ratio"))):F.raise("invalid arguments to regl"),r&&("canvas"===r.nodeName.toLowerCase()?a=r:n=r),!i){if(!a){F("undefined"!=typeof document,"must manually specify webgl context outside of DOM environments");var h=function(e,r,n){var a=document.createElement("canvas");function i(){var r=window.innerWidth,i=window.innerHeight;if(e!==document.body){var o=e.getBoundingClientRect();r=o.right-o.left,i=o.bottom-o.top}a.width=n*r,a.height=n*i,t(a.style,{width:r+"px",height:i+"px"})}return t(a.style,{border:0,margin:0,padding:0,top:0,left:0}),e.appendChild(a),e===document.body&&(a.style.position="absolute",t(e.style,{margin:0,padding:0})),window.addEventListener("resize",i,!1),i(),{canvas:a,onDestroy:function(){window.removeEventListener("resize",i),e.removeChild(a)}}}(n||document.body,0,l);if(!h)return null;a=h.canvas,p=h.onDestroy}i=function(e,t){function r(r){try{return e.getContext(r,t)}catch(e){return null}}return r("webgl")||r("experimental-webgl")||r("webgl-experimental")}(a,u)}return i?{gl:i,canvas:a,container:n,extensions:s,optionalExtensions:c,pixelRatio:l,profile:d,onDone:m,onDestroy:p}:(p(),m("webgl not supported, try upgrading your browser or graphics drivers http://get.webgl.org"),null)}function q(e,t){for(var r=Array(e),n=0;n<e;++n)r[n]=t(n);return r}var G=5120,Q=5121,V=5122,Y=5123,K=5124,X=5125,$=5126;function J(e){var t,r;return t=(e>65535)<<4,t|=r=((e>>>=t)>255)<<3,t|=r=((e>>>=r)>15)<<2,(t|=r=((e>>>=r)>3)<<1)|(e>>>=r)>>1}function Z(){var e=q(8,function(){return[]});function t(t){var r=function(e){for(var t=16;t<=1<<28;t*=16)if(e<=t)return t;return 0}(t),n=e[J(r)>>2];return n.length>0?n.pop():new ArrayBuffer(r)}function r(t){e[J(t.byteLength)>>2].push(t)}return{alloc:t,free:r,allocType:function(e,r){var n=null;switch(e){case G:n=new Int8Array(t(r),0,r);break;case Q:n=new Uint8Array(t(r),0,r);break;case V:n=new Int16Array(t(2*r),0,r);break;case Y:n=new Uint16Array(t(2*r),0,r);break;case K:n=new Int32Array(t(4*r),0,r);break;case X:n=new Uint32Array(t(4*r),0,r);break;case $:n=new Float32Array(t(4*r),0,r);break;default:return null}return n.length!==r?n.subarray(0,r):n},freeType:function(e){r(e.buffer)}}}var ee=Z();ee.zero=Z();var te=function(e,t){var r=1;t.ext_texture_filter_anisotropic&&(r=e.getParameter(34047));var n=1,a=1;t.webgl_draw_buffers&&(n=e.getParameter(34852),a=e.getParameter(36063));var i=!!t.oes_texture_float;if(i){var o=e.createTexture();e.bindTexture(3553,o),e.texImage2D(3553,0,6408,1,1,0,6408,5126,null);var f=e.createFramebuffer();if(e.bindFramebuffer(36160,f),e.framebufferTexture2D(36160,36064,3553,o,0),e.bindTexture(3553,null),36053!==e.checkFramebufferStatus(36160))i=!1;else{e.viewport(0,0,1,1),e.clearColor(1,0,0,1),e.clear(16384);var u=ee.allocType(5126,4);e.readPixels(0,0,1,1,6408,5126,u),e.getError()?i=!1:(e.deleteFramebuffer(f),e.deleteTexture(o),i=1===u[0]),ee.freeType(u)}}var s="undefined"!=typeof navigator&&(/MSIE/.test(navigator.userAgent)||/Trident\//.test(navigator.appVersion)||/Edge/.test(navigator.userAgent)),c=!0;if(!s){var l=e.createTexture(),d=ee.allocType(5121,36);e.activeTexture(33984),e.bindTexture(34067,l),e.texImage2D(34069,0,6408,3,3,0,6408,5121,d),ee.freeType(d),e.bindTexture(34067,null),e.deleteTexture(l),c=!e.getError()}return{colorBits:[e.getParameter(3410),e.getParameter(3411),e.getParameter(3412),e.getParameter(3413)],depthBits:e.getParameter(3414),stencilBits:e.getParameter(3415),subpixelBits:e.getParameter(3408),extensions:Object.keys(t).filter(function(e){return!!t[e]}),maxAnisotropic:r,maxDrawbuffers:n,maxColorAttachments:a,pointSizeDims:e.getParameter(33901),lineWidthDims:e.getParameter(33902),maxViewportDims:e.getParameter(3386),maxCombinedTextureUnits:e.getParameter(35661),maxCubeMapSize:e.getParameter(34076),maxRenderbufferSize:e.getParameter(34024),maxTextureUnits:e.getParameter(34930),maxTextureSize:e.getParameter(3379),maxAttributes:e.getParameter(34921),maxVertexUniforms:e.getParameter(36347),maxVertexTextureUnits:e.getParameter(35660),maxVaryingVectors:e.getParameter(36348),maxFragmentUniforms:e.getParameter(36349),glsl:e.getParameter(35724),renderer:e.getParameter(7937),vendor:e.getParameter(7936),version:e.getParameter(7938),readFloat:i,npotTextureCube:c}};function re(t){return!!t&&"object"==typeof t&&Array.isArray(t.shape)&&Array.isArray(t.stride)&&"number"==typeof t.offset&&t.shape.length===t.stride.length&&(Array.isArray(t.data)||e(t.data))}var ne=function(e){return Object.keys(e).map(function(t){return e[t]})},ae={shape:function(e){for(var t=[],r=e;r.length;r=r[0])t.push(r.length);return t},flatten:function(e,t,r,n){var a=1;if(t.length)for(var i=0;i<t.length;++i)a*=t[i];else a=0;var o=n||ee.allocType(r,a);switch(t.length){case 0:break;case 1:!function(e,t,r){for(var n=0;n<t;++n)r[n]=e[n]}(e,t[0],o);break;case 2:!function(e,t,r,n){for(var a=0,i=0;i<t;++i)for(var o=e[i],f=0;f<r;++f)n[a++]=o[f]}(e,t[0],t[1],o);break;case 3:ie(e,t[0],t[1],t[2],o,0);break;default:!function e(t,r,n,a,i){for(var o=1,f=n+1;f<r.length;++f)o*=r[f];var u=r[n];if(r.length-n==4){var s=r[n+1],c=r[n+2],l=r[n+3];for(f=0;f<u;++f)ie(t[f],s,c,l,a,i),i+=o}else for(f=0;f<u;++f)e(t[f],r,n+1,a,i),i+=o}(e,t,0,o,0)}return o}};function ie(e,t,r,n,a,i){for(var o=i,f=0;f<t;++f)for(var u=e[f],s=0;s<r;++s)for(var c=u[s],l=0;l<n;++l)a[o++]=c[l]}var oe={"[object Int8Array]":5120,"[object Int16Array]":5122,"[object Int32Array]":5124,"[object Uint8Array]":5121,"[object Uint8ClampedArray]":5121,"[object Uint16Array]":5123,"[object Uint32Array]":5125,"[object Float32Array]":5126,"[object Float64Array]":5121,"[object ArrayBuffer]":5121},fe={int8:5120,int16:5122,int32:5124,uint8:5121,uint16:5123,uint32:5125,float:5126,float32:5126},ue={dynamic:35048,stream:35040,static:35044},se=ae.flatten,ce=ae.shape,le=35044,de=35040,me=5121,pe=5126,he=[];function be(e){return 0|oe[Object.prototype.toString.call(e)]}function ve(e,t){for(var r=0;r<t.length;++r)e[r]=t[r]}function ge(e,t,r,n,a,i,o){for(var f=0,u=0;u<r;++u)for(var s=0;s<n;++s)e[f++]=t[a*u+i*s+o]}he[5120]=1,he[5122]=2,he[5124]=4,he[5121]=1,he[5123]=2,he[5125]=4,he[5126]=4;var ye={points:0,point:0,lines:1,line:1,triangles:4,triangle:4,"line loop":2,"line strip":3,"triangle strip":5,"triangle fan":6},xe=0,we=1,ke=4,_e=5120,Ae=5121,Se=5122,Ee=5123,Te=5124,je=5125,De=34963,Oe=35040,Ce=35044,Fe=new Float32Array(1),ze=new Uint32Array(Fe.buffer),Le=5123;function Me(e){for(var t=ee.allocType(Le,e.length),r=0;r<e.length;++r)if(isNaN(e[r]))t[r]=65535;else if(e[r]===1/0)t[r]=31744;else if(e[r]===-1/0)t[r]=64512;else{Fe[0]=e[r];var n=ze[0],a=n>>>31<<15,i=(n<<1>>>24)-127,o=n>>13&1023;if(i<-24)t[r]=a;else if(i<-14){var f=-14-i;t[r]=a+(o+1024>>f)}else t[r]=i>15?a+31744:a+(i+15<<10)+o}return t}function Pe(t){return Array.isArray(t)||e(t)}var Be=function(e){return!(e&e-1||!e)},Ie=34467,Re=3553,We=34067,He=34069,Ue=6408,Ne=6406,qe=6407,Ge=6409,Qe=6410,Ve=32854,Ye=32855,Ke=36194,Xe=32819,$e=32820,Je=33635,Ze=34042,et=6402,tt=34041,rt=35904,nt=35906,at=36193,it=33776,ot=33777,ft=33778,ut=33779,st=35986,ct=35987,lt=34798,dt=35840,mt=35841,pt=35842,ht=35843,bt=36196,vt=5121,gt=5123,yt=5125,xt=5126,wt=10242,kt=10243,_t=10497,At=33071,St=33648,Et=10240,Tt=10241,jt=9728,Dt=9729,Ot=9984,Ct=9985,Ft=9986,zt=9987,Lt=33170,Mt=4352,Pt=4353,Bt=4354,It=34046,Rt=3317,Wt=37440,Ht=37441,Ut=37443,Nt=37444,qt=33984,Gt=[Ot,Ft,Ct,zt],Qt=[0,Ge,Qe,qe,Ue],Vt={};function Yt(e){return"[object "+e+"]"}Vt[Ge]=Vt[Ne]=Vt[et]=1,Vt[tt]=Vt[Qe]=2,Vt[qe]=Vt[rt]=3,Vt[Ue]=Vt[nt]=4;var Kt=Yt("HTMLCanvasElement"),Xt=Yt("CanvasRenderingContext2D"),$t=Yt("ImageBitmap"),Jt=Yt("HTMLImageElement"),Zt=Yt("HTMLVideoElement"),er=Object.keys(oe).concat([Kt,Xt,$t,Jt,Zt]),tr=[];tr[vt]=1,tr[xt]=4,tr[at]=2,tr[gt]=2,tr[yt]=4;var rr=[];function nr(e){return Array.isArray(e)&&(0===e.length||"number"==typeof e[0])}function ar(e){if(!Array.isArray(e))return!1;var t=e.length;return!(0===t||!Pe(e[0]))}function ir(e){return Object.prototype.toString.call(e)}function or(e){return ir(e)===Kt}function fr(e){if(!e)return!1;var t=ir(e);return er.indexOf(t)>=0||nr(e)||ar(e)||re(e)}function ur(e){return 0|oe[Object.prototype.toString.call(e)]}function sr(e,t){return ee.allocType(e.type===at?xt:e.type,t)}function cr(e,t){e.type===at?(e.data=Me(t),ee.freeType(t)):e.data=t}function lr(e,t,r,n,a,i){var o;if(o=void 0!==rr[e]?rr[e]:Vt[e]*tr[t],i&&(o*=6),a){for(var f=0,u=r;u>=1;)f+=o*u*u,u/=2;return f}return o*r*n}function dr(r,n,a,i,o,f,u){var s={"don't care":Mt,"dont care":Mt,nice:Bt,fast:Pt},c={repeat:_t,clamp:At,mirror:St},l={nearest:jt,linear:Dt},d=t({mipmap:zt,"nearest mipmap nearest":Ot,"linear mipmap nearest":Ct,"nearest mipmap linear":Ft,"linear mipmap linear":zt},l),m={none:0,browser:Nt},p={uint8:vt,rgba4:Xe,rgb565:Je,"rgb5 a1":$e},h={alpha:Ne,luminance:Ge,"luminance alpha":Qe,rgb:qe,rgba:Ue,rgba4:Ve,"rgb5 a1":Ye,rgb565:Ke},b={};n.ext_srgb&&(h.srgb=rt,h.srgba=nt),n.oes_texture_float&&(p.float32=p.float=xt),n.oes_texture_half_float&&(p.float16=p["half float"]=at),n.webgl_depth_texture&&(t(h,{depth:et,"depth stencil":tt}),t(p,{uint16:gt,uint32:yt,"depth stencil":Ze})),n.webgl_compressed_texture_s3tc&&t(b,{"rgb s3tc dxt1":it,"rgba s3tc dxt1":ot,"rgba s3tc dxt3":ft,"rgba s3tc dxt5":ut}),n.webgl_compressed_texture_atc&&t(b,{"rgb atc":st,"rgba atc explicit alpha":ct,"rgba atc interpolated alpha":lt}),n.webgl_compressed_texture_pvrtc&&t(b,{"rgb pvrtc 4bppv1":dt,"rgb pvrtc 2bppv1":mt,"rgba pvrtc 4bppv1":pt,"rgba pvrtc 2bppv1":ht}),n.webgl_compressed_texture_etc1&&(b["rgb etc1"]=bt);var v=Array.prototype.slice.call(r.getParameter(Ie));Object.keys(b).forEach(function(e){var t=b[e];v.indexOf(t)>=0&&(h[e]=t)});var g=Object.keys(h);a.textureFormats=g;var y=[];Object.keys(h).forEach(function(e){var t=h[e];y[t]=e});var x=[];Object.keys(p).forEach(function(e){var t=p[e];x[t]=e});var w=[];Object.keys(l).forEach(function(e){var t=l[e];w[t]=e});var k=[];Object.keys(d).forEach(function(e){var t=d[e];k[t]=e});var _=[];Object.keys(c).forEach(function(e){var t=c[e];_[t]=e});var A=g.reduce(function(e,t){var r=h[t];return r===Ge||r===Ne||r===Ge||r===Qe||r===et||r===tt?e[r]=r:r===Ye||t.indexOf("rgba")>=0?e[r]=Ue:e[r]=qe,e},{});function S(){this.internalformat=Ue,this.format=Ue,this.type=vt,this.compressed=!1,this.premultiplyAlpha=!1,this.flipY=!1,this.unpackAlignment=1,this.colorSpace=Nt,this.width=0,this.height=0,this.channels=0}function E(e,t){e.internalformat=t.internalformat,e.format=t.format,e.type=t.type,e.compressed=t.compressed,e.premultiplyAlpha=t.premultiplyAlpha,e.flipY=t.flipY,e.unpackAlignment=t.unpackAlignment,e.colorSpace=t.colorSpace,e.width=t.width,e.height=t.height,e.channels=t.channels}function T(e,t){if("object"==typeof t&&t){if("premultiplyAlpha"in t&&(F.type(t.premultiplyAlpha,"boolean","invalid premultiplyAlpha"),e.premultiplyAlpha=t.premultiplyAlpha),"flipY"in t&&(F.type(t.flipY,"boolean","invalid texture flip"),e.flipY=t.flipY),"alignment"in t&&(F.oneOf(t.alignment,[1,2,4,8],"invalid texture unpack alignment"),e.unpackAlignment=t.alignment),"colorSpace"in t&&(F.parameter(t.colorSpace,m,"invalid colorSpace"),e.colorSpace=m[t.colorSpace]),"type"in t){var r=t.type;F(n.oes_texture_float||!("float"===r||"float32"===r),"you must enable the OES_texture_float extension in order to use floating point textures."),F(n.oes_texture_half_float||!("half float"===r||"float16"===r),"you must enable the OES_texture_half_float extension in order to use 16-bit floating point textures."),F(n.webgl_depth_texture||!("uint16"===r||"uint32"===r||"depth stencil"===r),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),F.parameter(r,p,"invalid texture type"),e.type=p[r]}var i=e.width,o=e.height,f=e.channels,u=!1;"shape"in t?(F(Array.isArray(t.shape)&&t.shape.length>=2,"shape must be an array"),i=t.shape[0],o=t.shape[1],3===t.shape.length&&(f=t.shape[2],F(f>0&&f<=4,"invalid number of channels"),u=!0),F(i>=0&&i<=a.maxTextureSize,"invalid width"),F(o>=0&&o<=a.maxTextureSize,"invalid height")):("radius"in t&&(i=o=t.radius,F(i>=0&&i<=a.maxTextureSize,"invalid radius")),"width"in t&&(i=t.width,F(i>=0&&i<=a.maxTextureSize,"invalid width")),"height"in t&&(o=t.height,F(o>=0&&o<=a.maxTextureSize,"invalid height")),"channels"in t&&(f=t.channels,F(f>0&&f<=4,"invalid number of channels"),u=!0)),e.width=0|i,e.height=0|o,e.channels=0|f;var s=!1;if("format"in t){var c=t.format;F(n.webgl_depth_texture||!("depth"===c||"depth stencil"===c),"you must enable the WEBGL_depth_texture extension in order to use depth/stencil textures."),F.parameter(c,h,"invalid texture format");var l=e.internalformat=h[c];e.format=A[l],c in p&&("type"in t||(e.type=p[c])),c in b&&(e.compressed=!0),s=!0}!u&&s?e.channels=Vt[e.format]:u&&!s?e.channels!==Qt[e.format]&&(e.format=e.internalformat=Qt[e.channels]):s&&u&&F(e.channels===Vt[e.format],"number of channels inconsistent with specified format")}}function j(e){r.pixelStorei(Wt,e.flipY),r.pixelStorei(Ht,e.premultiplyAlpha),r.pixelStorei(Ut,e.colorSpace),r.pixelStorei(Rt,e.unpackAlignment)}function D(){S.call(this),this.xOffset=0,this.yOffset=0,this.data=null,this.needsFree=!1,this.element=null,this.needsCopy=!1}function O(t,r){var n=null;if(fr(r)?n=r:r&&(F.type(r,"object","invalid pixel data type"),T(t,r),"x"in r&&(t.xOffset=0|r.x),"y"in r&&(t.yOffset=0|r.y),fr(r.data)&&(n=r.data)),F(!t.compressed||n instanceof Uint8Array,"compressed texture data must be stored in a uint8array"),r.copy){F(!n,"can not specify copy and data field for the same texture");var i=o.viewportWidth,f=o.viewportHeight;t.width=t.width||i-t.xOffset,t.height=t.height||f-t.yOffset,t.needsCopy=!0,F(t.xOffset>=0&&t.xOffset<i&&t.yOffset>=0&&t.yOffset<f&&t.width>0&&t.width<=i&&t.height>0&&t.height<=f,"copy texture read out of bounds")}else if(n){if(e(n))t.channels=t.channels||4,t.data=n,"type"in r||t.type!==vt||(t.type=ur(n));else if(nr(n))t.channels=t.channels||4,function(e,t){var r=t.length;switch(e.type){case vt:case gt:case yt:case xt:var n=ee.allocType(e.type,r);n.set(t),e.data=n;break;case at:e.data=Me(t);break;default:F.raise("unsupported texture type, must specify a typed array")}}(t,n),t.alignment=1,t.needsFree=!0;else if(re(n)){var u=n.data;Array.isArray(u)||t.type!==vt||(t.type=ur(u));var s,c,l,d,m,p,h=n.shape,b=n.stride;3===h.length?(l=h[2],p=b[2]):(F(2===h.length,"invalid ndarray pixel data, must be 2 or 3D"),l=1,p=1),s=h[0],c=h[1],d=b[0],m=b[1],t.alignment=1,t.width=s,t.height=c,t.channels=l,t.format=t.internalformat=Qt[l],t.needsFree=!0,function(e,t,r,n,a,i){for(var o=e.width,f=e.height,u=e.channels,s=sr(e,o*f*u),c=0,l=0;l<f;++l)for(var d=0;d<o;++d)for(var m=0;m<u;++m)s[c++]=t[r*d+n*l+a*m+i];cr(e,s)}(t,u,d,m,p,n.offset)}else if(or(n)||ir(n)===Xt)or(n)?t.element=n:t.element=n.canvas,t.width=t.element.width,t.height=t.element.height,t.channels=4;else if(function(e){return ir(e)===$t}(n))t.element=n,t.width=n.width,t.height=n.height,t.channels=4;else if(function(e){return ir(e)===Jt}(n))t.element=n,t.width=n.naturalWidth,t.height=n.naturalHeight,t.channels=4;else if(function(e){return ir(e)===Zt}(n))t.element=n,t.width=n.videoWidth,t.height=n.videoHeight,t.channels=4;else if(ar(n)){var v=t.width||n[0].length,g=t.height||n.length,y=t.channels;y=Pe(n[0][0])?y||n[0][0].length:y||1;for(var x=ae.shape(n),w=1,k=0;k<x.length;++k)w*=x[k];var _=sr(t,w);ae.flatten(n,x,"",_),cr(t,_),t.alignment=1,t.width=v,t.height=g,t.channels=y,t.format=t.internalformat=Qt[y],t.needsFree=!0}}else t.width=t.width||1,t.height=t.height||1,t.channels=t.channels||4;t.type===xt?F(a.extensions.indexOf("oes_texture_float")>=0,"oes_texture_float extension not enabled"):t.type===at&&F(a.extensions.indexOf("oes_texture_half_float")>=0,"oes_texture_half_float extension not enabled")}function C(e,t,n){var a=e.element,o=e.data,f=e.internalformat,u=e.format,s=e.type,c=e.width,l=e.height,d=e.channels;if(j(e),a)r.texImage2D(t,n,u,u,s,a);else if(e.compressed)r.compressedTexImage2D(t,n,f,c,l,0,o);else if(e.needsCopy)i(),r.copyTexImage2D(t,n,u,e.xOffset,e.yOffset,c,l,0);else{var m=!o;m&&(o=ee.zero.allocType(s,c*l*d)),r.texImage2D(t,n,u,c,l,0,u,s,o),m&&o&&ee.zero.freeType(o)}}function z(e,t,n,a,o){var f=e.element,u=e.data,s=e.internalformat,c=e.format,l=e.type,d=e.width,m=e.height;j(e),f?r.texSubImage2D(t,o,n,a,c,l,f):e.compressed?r.compressedTexSubImage2D(t,o,n,a,s,d,m,u):e.needsCopy?(i(),r.copyTexSubImage2D(t,o,n,a,e.xOffset,e.yOffset,d,m)):r.texSubImage2D(t,o,n,a,d,m,c,l,u)}var L=[];function M(){return L.pop()||new D}function P(e){e.needsFree&&ee.freeType(e.data),D.call(e),L.push(e)}function B(){S.call(this),this.genMipmaps=!1,this.mipmapHint=Mt,this.mipmask=0,this.images=Array(16)}function I(e,t,r){var n=e.images[0]=M();e.mipmask=1,n.width=e.width=t,n.height=e.height=r,n.channels=e.channels=4}function R(e,t){var r=null;if(fr(t))E(r=e.images[0]=M(),e),O(r,t),e.mipmask=1;else if(T(e,t),Array.isArray(t.mipmap))for(var n=t.mipmap,a=0;a<n.length;++a)E(r=e.images[a]=M(),e),r.width>>=a,r.height>>=a,O(r,n[a]),e.mipmask|=1<<a;else E(r=e.images[0]=M(),e),O(r,t),e.mipmask=1;E(e,e.images[0]),(e.compressed&&e.internalformat===it||e.internalformat===ot||e.internalformat===ft||e.internalformat===ut)&&F(e.width%4==0&&e.height%4==0,"for compressed texture formats, mipmap level 0 must have width and height that are a multiple of 4")}function W(e,t){for(var r=e.images,n=0;n<r.length;++n){if(!r[n])return;C(r[n],t,n)}}var H=[];function U(){var e=H.pop()||new B;S.call(e),e.mipmask=0;for(var t=0;t<16;++t)e.images[t]=null;return e}function N(e){for(var t=e.images,r=0;r<t.length;++r)t[r]&&P(t[r]),t[r]=null;H.push(e)}function q(){this.minFilter=jt,this.magFilter=jt,this.wrapS=At,this.wrapT=At,this.anisotropic=1,this.genMipmaps=!1,this.mipmapHint=Mt}function G(e,t){if("min"in t){var r=t.min;F.parameter(r,d),e.minFilter=d[r],Gt.indexOf(e.minFilter)>=0&&!("faces"in t)&&(e.genMipmaps=!0)}if("mag"in t){var n=t.mag;F.parameter(n,l),e.magFilter=l[n]}var i=e.wrapS,o=e.wrapT;if("wrap"in t){var f=t.wrap;"string"==typeof f?(F.parameter(f,c),i=o=c[f]):Array.isArray(f)&&(F.parameter(f[0],c),F.parameter(f[1],c),i=c[f[0]],o=c[f[1]])}else{if("wrapS"in t){var u=t.wrapS;F.parameter(u,c),i=c[u]}if("wrapT"in t){var m=t.wrapT;F.parameter(m,c),o=c[m]}}if(e.wrapS=i,e.wrapT=o,"anisotropic"in t){var p=t.anisotropic;F("number"==typeof p&&p>=1&&p<=a.maxAnisotropic,"aniso samples must be between 1 and "),e.anisotropic=t.anisotropic}if("mipmap"in t){var h=!1;switch(typeof t.mipmap){case"string":F.parameter(t.mipmap,s,"invalid mipmap hint"),e.mipmapHint=s[t.mipmap],e.genMipmaps=!0,h=!0;break;case"boolean":h=e.genMipmaps=t.mipmap;break;case"object":F(Array.isArray(t.mipmap),"invalid mipmap type"),e.genMipmaps=!1,h=!0;break;default:F.raise("invalid mipmap type")}!h||"min"in t||(e.minFilter=Ot)}}function Q(e,t){r.texParameteri(t,Tt,e.minFilter),r.texParameteri(t,Et,e.magFilter),r.texParameteri(t,wt,e.wrapS),r.texParameteri(t,kt,e.wrapT),n.ext_texture_filter_anisotropic&&r.texParameteri(t,It,e.anisotropic),e.genMipmaps&&(r.hint(Lt,e.mipmapHint),r.generateMipmap(t))}var V=0,Y={},K=a.maxTextureUnits,X=Array(K).map(function(){return null});function $(e){S.call(this),this.mipmask=0,this.internalformat=Ue,this.id=V++,this.refCount=1,this.target=e,this.texture=r.createTexture(),this.unit=-1,this.bindCount=0,this.texInfo=new q,u.profile&&(this.stats={size:0})}function J(e){r.activeTexture(qt),r.bindTexture(e.target,e.texture)}function Z(){var e=X[0];e?r.bindTexture(e.target,e.texture):r.bindTexture(Re,null)}function te(e){var t=e.texture;F(t,"must not double destroy texture");var n=e.unit,a=e.target;n>=0&&(r.activeTexture(qt+n),r.bindTexture(a,null),X[n]=null),r.deleteTexture(t),e.texture=null,e.params=null,e.pixels=null,e.refCount=0,delete Y[e.id],f.textureCount--}return t($.prototype,{bind:function(){this.bindCount+=1;var e=this.unit;if(e<0){for(var t=0;t<K;++t){var n=X[t];if(n){if(n.bindCount>0)continue;n.unit=-1}X[t]=this,e=t;break}e>=K&&F.raise("insufficient number of texture units"),u.profile&&f.maxTextureUnits<e+1&&(f.maxTextureUnits=e+1),this.unit=e,r.activeTexture(qt+e),r.bindTexture(this.target,this.texture)}return e},unbind:function(){this.bindCount-=1},decRef:function(){--this.refCount<=0&&te(this)}}),u.profile&&(f.getTotalTextureSize=function(){var e=0;return Object.keys(Y).forEach(function(t){e+=Y[t].stats.size}),e}),{create2D:function(e,t){var n=new $(Re);function i(e,t){var r=n.texInfo;q.call(r);var o=U();return"number"==typeof e?I(o,0|e,"number"==typeof t?0|t:0|e):e?(F.type(e,"object","invalid arguments to regl.texture"),G(r,e),R(o,e)):I(o,1,1),r.genMipmaps&&(o.mipmask=(o.width<<1)-1),n.mipmask=o.mipmask,E(n,o),F.texture2D(r,o,a),n.internalformat=o.internalformat,i.width=o.width,i.height=o.height,J(n),W(o,Re),Q(r,Re),Z(),N(o),u.profile&&(n.stats.size=lr(n.internalformat,n.type,o.width,o.height,r.genMipmaps,!1)),i.format=y[n.internalformat],i.type=x[n.type],i.mag=w[r.magFilter],i.min=k[r.minFilter],i.wrapS=_[r.wrapS],i.wrapT=_[r.wrapT],i}return Y[n.id]=n,f.textureCount++,i(e,t),i.subimage=function(e,t,r,a){F(!!e,"must specify image data");var o=0|t,f=0|r,u=0|a,s=M();return E(s,n),s.width=0,s.height=0,O(s,e),s.width=s.width||(n.width>>u)-o,s.height=s.height||(n.height>>u)-f,F(n.type===s.type&&n.format===s.format&&n.internalformat===s.internalformat,"incompatible format for texture.subimage"),F(o>=0&&f>=0&&o+s.width<=n.width&&f+s.height<=n.height,"texture.subimage write out of bounds"),F(n.mipmask&1<<u,"missing mipmap data"),F(s.data||s.element||s.needsCopy,"missing image data"),J(n),z(s,Re,o,f,u),Z(),P(s),i},i.resize=function(e,t){var a,o=0|e,f=0|t||o;if(o===n.width&&f===n.height)return i;i.width=n.width=o,i.height=n.height=f,J(n);for(var s=n.channels,c=n.type,l=0;n.mipmask>>l;++l){var d=o>>l,m=f>>l;if(!d||!m)break;a=ee.zero.allocType(c,d*m*s),r.texImage2D(Re,l,n.format,d,m,0,n.format,n.type,a),a&&ee.zero.freeType(a)}return Z(),u.profile&&(n.stats.size=lr(n.internalformat,n.type,o,f,!1,!1)),i},i._reglType="texture2d",i._texture=n,u.profile&&(i.stats=n.stats),i.destroy=function(){n.decRef()},i},createCube:function(e,t,n,i,o,s){var c=new $(We);Y[c.id]=c,f.cubeCount++;var l=new Array(6);function d(e,t,r,n,i,o){var f,s=c.texInfo;for(q.call(s),f=0;f<6;++f)l[f]=U();if("number"!=typeof e&&e)if("object"==typeof e)if(t)R(l[0],e),R(l[1],t),R(l[2],r),R(l[3],n),R(l[4],i),R(l[5],o);else if(G(s,e),T(c,e),"faces"in e){var m=e.faces;for(F(Array.isArray(m)&&6===m.length,"cube faces must be a length 6 array"),f=0;f<6;++f)F("object"==typeof m[f]&&!!m[f],"invalid input for cube map face"),E(l[f],c),R(l[f],m[f])}else for(f=0;f<6;++f)R(l[f],e);else F.raise("invalid arguments to cube map");else{var p=0|e||1;for(f=0;f<6;++f)I(l[f],p,p)}for(E(c,l[0]),a.npotTextureCube||F(Be(c.width)&&Be(c.height),"your browser does not support non power or two texture dimensions"),s.genMipmaps?c.mipmask=(l[0].width<<1)-1:c.mipmask=l[0].mipmask,F.textureCube(c,s,l,a),c.internalformat=l[0].internalformat,d.width=l[0].width,d.height=l[0].height,J(c),f=0;f<6;++f)W(l[f],He+f);for(Q(s,We),Z(),u.profile&&(c.stats.size=lr(c.internalformat,c.type,d.width,d.height,s.genMipmaps,!0)),d.format=y[c.internalformat],d.type=x[c.type],d.mag=w[s.magFilter],d.min=k[s.minFilter],d.wrapS=_[s.wrapS],d.wrapT=_[s.wrapT],f=0;f<6;++f)N(l[f]);return d}return d(e,t,n,i,o,s),d.subimage=function(e,t,r,n,a){F(!!t,"must specify image data"),F("number"==typeof e&&e===(0|e)&&e>=0&&e<6,"invalid face");var i=0|r,o=0|n,f=0|a,u=M();return E(u,c),u.width=0,u.height=0,O(u,t),u.width=u.width||(c.width>>f)-i,u.height=u.height||(c.height>>f)-o,F(c.type===u.type&&c.format===u.format&&c.internalformat===u.internalformat,"incompatible format for texture.subimage"),F(i>=0&&o>=0&&i+u.width<=c.width&&o+u.height<=c.height,"texture.subimage write out of bounds"),F(c.mipmask&1<<f,"missing mipmap data"),F(u.data||u.element||u.needsCopy,"missing image data"),J(c),z(u,He+e,i,o,f),Z(),P(u),d},d.resize=function(e){var t=0|e;if(t!==c.width){d.width=c.width=t,d.height=c.height=t,J(c);for(var n=0;n<6;++n)for(var a=0;c.mipmask>>a;++a)r.texImage2D(He+n,a,c.format,t>>a,t>>a,0,c.format,c.type,null);return Z(),u.profile&&(c.stats.size=lr(c.internalformat,c.type,d.width,d.height,!1,!0)),d}},d._reglType="textureCube",d._texture=c,u.profile&&(d.stats=c.stats),d.destroy=function(){c.decRef()},d},clear:function(){for(var e=0;e<K;++e)r.activeTexture(qt+e),r.bindTexture(Re,null),X[e]=null;ne(Y).forEach(te),f.cubeCount=0,f.textureCount=0},getTexture:function(e){return null},restore:function(){for(var e=0;e<K;++e){var t=X[e];t&&(t.bindCount=0,t.unit=-1,X[e]=null)}ne(Y).forEach(function(e){e.texture=r.createTexture(),r.bindTexture(e.target,e.texture);for(var t=0;t<32;++t)if(0!=(e.mipmask&1<<t))if(e.target===Re)r.texImage2D(Re,t,e.internalformat,e.width>>t,e.height>>t,0,e.internalformat,e.type,null);else for(var n=0;n<6;++n)r.texImage2D(He+n,t,e.internalformat,e.width>>t,e.height>>t,0,e.internalformat,e.type,null);Q(e.texInfo,e.target)})}}}rr[Ve]=2,rr[Ye]=2,rr[Ke]=2,rr[tt]=4,rr[it]=.5,rr[ot]=.5,rr[ft]=1,rr[ut]=1,rr[st]=.5,rr[ct]=1,rr[lt]=1,rr[dt]=.5,rr[mt]=.25,rr[pt]=.5,rr[ht]=.25,rr[bt]=.5;var mr=36161,pr=32854,hr=[];function br(e,t,r){return hr[e]*t*r}hr[pr]=2,hr[32855]=2,hr[36194]=2,hr[33189]=2,hr[36168]=1,hr[34041]=4,hr[35907]=4,hr[34836]=16,hr[34842]=8,hr[34843]=6;var vr=function(e,t,r,n,a){var i={rgba4:pr,rgb565:36194,"rgb5 a1":32855,depth:33189,stencil:36168,"depth stencil":34041};t.ext_srgb&&(i.srgba=35907),t.ext_color_buffer_half_float&&(i.rgba16f=34842,i.rgb16f=34843),t.webgl_color_buffer_float&&(i.rgba32f=34836);var o=[];Object.keys(i).forEach(function(e){var t=i[e];o[t]=e});var f=0,u={};function s(e){this.id=f++,this.refCount=1,this.renderbuffer=e,this.format=pr,this.width=0,this.height=0,a.profile&&(this.stats={size:0})}function c(t){var r=t.renderbuffer;F(r,"must not double destroy renderbuffer"),e.bindRenderbuffer(mr,null),e.deleteRenderbuffer(r),t.renderbuffer=null,t.refCount=0,delete u[t.id],n.renderbufferCount--}return s.prototype.decRef=function(){--this.refCount<=0&&c(this)},a.profile&&(n.getTotalRenderbufferSize=function(){var e=0;return Object.keys(u).forEach(function(t){e+=u[t].stats.size}),e}),{create:function(t,f){var c=new s(e.createRenderbuffer());function l(t,n){var f=0,u=0,s=pr;if("object"==typeof t&&t){var d=t;if("shape"in d){var m=d.shape;F(Array.isArray(m)&&m.length>=2,"invalid renderbuffer shape"),f=0|m[0],u=0|m[1]}else"radius"in d&&(f=u=0|d.radius),"width"in d&&(f=0|d.width),"height"in d&&(u=0|d.height);"format"in d&&(F.parameter(d.format,i,"invalid renderbuffer format"),s=i[d.format])}else"number"==typeof t?(f=0|t,u="number"==typeof n?0|n:f):t?F.raise("invalid arguments to renderbuffer constructor"):f=u=1;if(F(f>0&&u>0&&f<=r.maxRenderbufferSize&&u<=r.maxRenderbufferSize,"invalid renderbuffer size"),f!==c.width||u!==c.height||s!==c.format)return l.width=c.width=f,l.height=c.height=u,c.format=s,e.bindRenderbuffer(mr,c.renderbuffer),e.renderbufferStorage(mr,s,f,u),F(0===e.getError(),"invalid render buffer format"),a.profile&&(c.stats.size=br(c.format,c.width,c.height)),l.format=o[c.format],l}return u[c.id]=c,n.renderbufferCount++,l(t,f),l.resize=function(t,n){var i=0|t,o=0|n||i;return i===c.width&&o===c.height?l:(F(i>0&&o>0&&i<=r.maxRenderbufferSize&&o<=r.maxRenderbufferSize,"invalid renderbuffer size"),l.width=c.width=i,l.height=c.height=o,e.bindRenderbuffer(mr,c.renderbuffer),e.renderbufferStorage(mr,c.format,i,o),F(0===e.getError(),"invalid render buffer format"),a.profile&&(c.stats.size=br(c.format,c.width,c.height)),l)},l._reglType="renderbuffer",l._renderbuffer=c,a.profile&&(l.stats=c.stats),l.destroy=function(){c.decRef()},l},clear:function(){ne(u).forEach(c)},restore:function(){ne(u).forEach(function(t){t.renderbuffer=e.createRenderbuffer(),e.bindRenderbuffer(mr,t.renderbuffer),e.renderbufferStorage(mr,t.format,t.width,t.height)}),e.bindRenderbuffer(mr,null)}}},gr=36160,yr=36161,xr=3553,wr=34069,kr=36064,_r=36096,Ar=36128,Sr=33306,Er=36053,Tr=6402,jr=[6407,6408],Dr=[];Dr[6408]=4,Dr[6407]=3;var Or=[];Or[5121]=1,Or[5126]=4,Or[36193]=2;var Cr=33189,Fr=36168,zr=34041,Lr=[32854,32855,36194,35907,34842,34843,34836],Mr={};Mr[Er]="complete",Mr[36054]="incomplete attachment",Mr[36057]="incomplete dimensions",Mr[36055]="incomplete, missing attachment",Mr[36061]="unsupported";var Pr=5126;function Br(){this.state=0,this.x=0,this.y=0,this.z=0,this.w=0,this.buffer=null,this.size=0,this.normalized=!1,this.type=Pr,this.offset=0,this.stride=0,this.divisor=0}var Ir=35632,Rr=35633,Wr=35718,Hr=35721,Ur=6408,Nr=5121,qr=3333,Gr=5126;function Qr(t,r,n,a,i,o,f){function u(u){var s;null===r.next?(F(i.preserveDrawingBuffer,'you must create a webgl context with "preserveDrawingBuffer":true in order to read pixels from the drawing buffer'),s=Nr):(F(null!==r.next.colorAttachments[0].texture,"You cannot read from a renderbuffer"),s=r.next.colorAttachments[0].texture._texture.type,o.oes_texture_float?(F(s===Nr||s===Gr,"Reading from a framebuffer is only allowed for the types 'uint8' and 'float'"),s===Gr&&F(f.readFloat,"Reading 'float' values is not permitted in your browser. For a fallback, please see: https://www.npmjs.com/package/glsl-read-float")):F(s===Nr,"Reading from a framebuffer is only allowed for the type 'uint8'"));var c=0,l=0,d=a.framebufferWidth,m=a.framebufferHeight,p=null;e(u)?p=u:u&&(F.type(u,"object","invalid arguments to regl.read()"),c=0|u.x,l=0|u.y,F(c>=0&&c<a.framebufferWidth,"invalid x offset for regl.read"),F(l>=0&&l<a.framebufferHeight,"invalid y offset for regl.read"),d=0|(u.width||a.framebufferWidth-c),m=0|(u.height||a.framebufferHeight-l),p=u.data||null),p&&(s===Nr?F(p instanceof Uint8Array,"buffer must be 'Uint8Array' when reading from a framebuffer of type 'uint8'"):s===Gr&&F(p instanceof Float32Array,"buffer must be 'Float32Array' when reading from a framebuffer of type 'float'")),F(d>0&&d+c<=a.framebufferWidth,"invalid width for read pixels"),F(m>0&&m+l<=a.framebufferHeight,"invalid height for read pixels"),n();var h=d*m*4;return p||(s===Nr?p=new Uint8Array(h):s===Gr&&(p=p||new Float32Array(h))),F.isTypedArray(p,"data buffer for regl.read() must be a typedarray"),F(p.byteLength>=h,"data buffer for regl.read() too small"),t.pixelStorei(qr,4),t.readPixels(c,l,d,m,Ur,s,p),p}return function(e){return e&&"framebuffer"in e?function(e){var t;return r.setFBO({framebuffer:e.framebuffer},function(){t=u(e)}),t}(e):u(e)}}function Vr(e){return Array.prototype.slice.call(e)}function Yr(e){return Vr(e).join("")}var Kr="xyzw".split(""),Xr=5121,$r=1,Jr=2,Zr=0,en=1,tn=2,rn=3,nn=4,an="dither",on="blend.enable",fn="blend.color",un="blend.equation",sn="blend.func",cn="depth.enable",ln="depth.func",dn="depth.range",mn="depth.mask",pn="colorMask",hn="cull.enable",bn="cull.face",vn="frontFace",gn="lineWidth",yn="polygonOffset.enable",xn="polygonOffset.offset",wn="sample.alpha",kn="sample.enable",_n="sample.coverage",An="stencil.enable",Sn="stencil.mask",En="stencil.func",Tn="stencil.opFront",jn="stencil.opBack",Dn="scissor.enable",On="scissor.box",Cn="viewport",Fn="profile",zn="framebuffer",Ln="vert",Mn="frag",Pn="elements",Bn="primitive",In="count",Rn="offset",Wn="instances",Hn=zn+"Width",Un=zn+"Height",Nn=Cn+"Width",qn=Cn+"Height",Gn="drawingBufferWidth",Qn="drawingBufferHeight",Vn=[sn,un,En,Tn,jn,_n,Cn,On,xn],Yn=34962,Kn=34963,Xn=3553,$n=34067,Jn=2884,Zn=3042,ea=3024,ta=2960,ra=2929,na=3089,aa=32823,ia=32926,oa=32928,fa=5126,ua=35664,sa=35665,ca=35666,la=5124,da=35667,ma=35668,pa=35669,ha=35670,ba=35671,va=35672,ga=35673,ya=35674,xa=35675,wa=35676,ka=35678,_a=35680,Aa=4,Sa=1028,Ea=1029,Ta=2304,ja=2305,Da=32775,Oa=32776,Ca=519,Fa=7680,za=0,La=1,Ma=32774,Pa=513,Ba=36160,Ia=36064,Ra={0:0,1:1,zero:0,one:1,"src color":768,"one minus src color":769,"src alpha":770,"one minus src alpha":771,"dst color":774,"one minus dst color":775,"dst alpha":772,"one minus dst alpha":773,"constant color":32769,"one minus constant color":32770,"constant alpha":32771,"one minus constant alpha":32772,"src alpha saturate":776},Wa=["constant color, constant alpha","one minus constant color, constant alpha","constant color, one minus constant alpha","one minus constant color, one minus constant alpha","constant alpha, constant color","constant alpha, one minus constant color","one minus constant alpha, constant color","one minus constant alpha, one minus constant color"],Ha={never:512,less:513,"<":513,equal:514,"=":514,"==":514,"===":514,lequal:515,"<=":515,greater:516,">":516,notequal:517,"!=":517,"!==":517,gequal:518,">=":518,always:519},Ua={0:0,zero:0,keep:7680,replace:7681,increment:7682,decrement:7683,"increment wrap":34055,"decrement wrap":34056,invert:5386},Na={frag:35632,vert:35633},qa={cw:Ta,ccw:ja};function Ga(t){return Array.isArray(t)||e(t)||re(t)}function Qa(e){return e.sort(function(e,t){return e===Cn?-1:t===Cn?1:e<t?-1:1})}function Va(e,t,r,n){this.thisDep=e,this.contextDep=t,this.propDep=r,this.append=n}function Ya(e){return e&&!(e.thisDep||e.contextDep||e.propDep)}function Ka(e){return new Va(!1,!1,!1,e)}function Xa(e,t){var r=e.type;if(r===Zr){var n=e.data.length;return new Va(!0,n>=1,n>=2,t)}if(r===nn){var a=e.data;return new Va(a.thisDep,a.contextDep,a.propDep,t)}return new Va(r===rn,r===tn,r===en,t)}var $a=new Va(!1,!1,!1,function(){});function Ja(e,r,n,a,i,o,f,u,s,c,l,d,m,p,h){var b=c.Record,v={add:32774,subtract:32778,"reverse subtract":32779};n.ext_blend_minmax&&(v.min=Da,v.max=Oa);var g=n.angle_instanced_arrays,y=n.webgl_draw_buffers,x={dirty:!0,profile:h.profile},w={},k=[],_={},A={};function S(e){return e.replace(".","_")}function E(e,t,r){var n=S(e);k.push(e),w[n]=x[n]=!!r,_[n]=t}function T(e,t,r){var n=S(e);k.push(e),Array.isArray(r)?(x[n]=r.slice(),w[n]=r.slice()):x[n]=w[n]=r,A[n]=t}E(an,ea),E(on,Zn),T(fn,"blendColor",[0,0,0,0]),T(un,"blendEquationSeparate",[Ma,Ma]),T(sn,"blendFuncSeparate",[La,za,La,za]),E(cn,ra,!0),T(ln,"depthFunc",Pa),T(dn,"depthRange",[0,1]),T(mn,"depthMask",!0),T(pn,pn,[!0,!0,!0,!0]),E(hn,Jn),T(bn,"cullFace",Ea),T(vn,vn,ja),T(gn,gn,1),E(yn,aa),T(xn,"polygonOffset",[0,0]),E(wn,ia),E(kn,oa),T(_n,"sampleCoverage",[1,!1]),E(An,ta),T(Sn,"stencilMask",-1),T(En,"stencilFunc",[Ca,0,-1]),T(Tn,"stencilOpSeparate",[Sa,Fa,Fa,Fa]),T(jn,"stencilOpSeparate",[Ea,Fa,Fa,Fa]),E(Dn,na),T(On,"scissor",[0,0,e.drawingBufferWidth,e.drawingBufferHeight]),T(Cn,Cn,[0,0,e.drawingBufferWidth,e.drawingBufferHeight]);var j={gl:e,context:m,strings:r,next:w,current:x,draw:d,elements:o,buffer:i,shader:l,attributes:c.state,uniforms:s,framebuffer:u,extensions:n,timer:p,isBufferArgs:Ga},D={primTypes:ye,compareFuncs:Ha,blendFuncs:Ra,blendEquations:v,stencilOps:Ua,glTypes:fe,orientationType:qa};F.optional(function(){j.isArrayLike=Pe}),y&&(D.backBuffer=[Ea],D.drawBuffer=q(a.maxDrawbuffers,function(e){return 0===e?[0]:q(e,function(e){return Ia+e})}));var O=0;function C(){var e=function(){var e=0,r=[],n=[];function a(){var r=[],n=[];return t(function(){r.push.apply(r,Vr(arguments))},{def:function(){var t="v"+e++;return n.push(t),arguments.length>0&&(r.push(t,"="),r.push.apply(r,Vr(arguments)),r.push(";")),t},toString:function(){return Yr([n.length>0?"var "+n+";":"",Yr(r)])}})}function i(){var e=a(),r=a(),n=e.toString,i=r.toString;function o(t,n){r(t,n,"=",e.def(t,n),";")}return t(function(){e.apply(e,Vr(arguments))},{def:e.def,entry:e,exit:r,save:o,set:function(t,r,n){o(t,r),e(t,r,"=",n,";")},toString:function(){return n()+i()}})}var o=a(),f={};return{global:o,link:function(t){for(var a=0;a<n.length;++a)if(n[a]===t)return r[a];var i="g"+e++;return r.push(i),n.push(t),i},block:a,proc:function(e,r){var n=[];function a(){var e="a"+n.length;return n.push(e),e}r=r||0;for(var o=0;o<r;++o)a();var u=i(),s=u.toString;return f[e]=t(u,{arg:a,toString:function(){return Yr(["function(",n.join(),"){",s(),"}"])}})},scope:i,cond:function(){var e=Yr(arguments),r=i(),n=i(),a=r.toString,o=n.toString;return t(r,{then:function(){return r.apply(r,Vr(arguments)),this},else:function(){return n.apply(n,Vr(arguments)),this},toString:function(){var t=o();return t&&(t="else{"+t+"}"),Yr(["if(",e,"){",a(),"}",t])}})},compile:function(){var e=['"use strict";',o,"return {"];Object.keys(f).forEach(function(t){e.push('"',t,'":',f[t].toString(),",")}),e.push("}");var t=Yr(e).replace(/;/g,";\n").replace(/}/g,"}\n").replace(/{/g,"{\n");return Function.apply(null,r.concat(t)).apply(null,n)}}}(),n=e.link,a=e.global;e.id=O++,e.batchId="0";var i=n(j),o=e.shared={props:"a0"};Object.keys(j).forEach(function(e){o[e]=a.def(i,".",e)}),F.optional(function(){e.CHECK=n(F),e.commandStr=F.guessCommand(),e.command=n(e.commandStr),e.assert=function(e,t,r){e("if(!(",t,"))",this.CHECK,".commandRaise(",n(r),",",this.command,");")},D.invalidBlendCombinations=Wa});var f=e.next={},u=e.current={};Object.keys(A).forEach(function(e){Array.isArray(x[e])&&(f[e]=a.def(o.next,".",e),u[e]=a.def(o.current,".",e))});var s=e.constants={};Object.keys(D).forEach(function(e){s[e]=a.def(JSON.stringify(D[e]))}),e.invoke=function(t,r){switch(r.type){case Zr:var a=["this",o.context,o.props,e.batchId];return t.def(n(r.data),".call(",a.slice(0,Math.max(r.data.length+1,4)),")");case en:return t.def(o.props,r.data);case tn:return t.def(o.context,r.data);case rn:return t.def("this",r.data);case nn:return r.data.append(e,t),r.data.ref}},e.attribCache={};var l={};return e.scopeAttrib=function(e){var t=r.id(e);if(t in l)return l[t];var a=c.scope[t];a||(a=c.scope[t]=new b);var i=l[t]=n(a);return i},e}function z(e,t,n,f,s){var c=e.static,d=e.dynamic;F.optional(function(){var e=[zn,Ln,Mn,Pn,Bn,Rn,In,Wn,Fn].concat(k);function t(t){Object.keys(t).forEach(function(t){F.command(e.indexOf(t)>=0,'unknown parameter "'+t+'"',s.commandStr)})}t(c),t(d)});var m=function(e,t){var r=e.static,n=e.dynamic;if(zn in r){var a=r[zn];return a?(a=u.getFramebuffer(a),F.command(a,"invalid framebuffer object"),Ka(function(e,t){var r=e.link(a),n=e.shared;t.set(n.framebuffer,".next",r);var i=n.context;return t.set(i,"."+Hn,r+".width"),t.set(i,"."+Un,r+".height"),r})):Ka(function(e,t){var r=e.shared;t.set(r.framebuffer,".next","null");var n=r.context;return t.set(n,"."+Hn,n+"."+Gn),t.set(n,"."+Un,n+"."+Qn),"null"})}if(zn in n){var i=n[zn];return Xa(i,function(e,t){var r=e.invoke(t,i),n=e.shared,a=n.framebuffer,o=t.def(a,".getFramebuffer(",r,")");F.optional(function(){e.assert(t,"!"+r+"||"+o,"invalid framebuffer object")}),t.set(a,".next",o);var f=n.context;return t.set(f,"."+Hn,o+"?"+o+".width:"+f+"."+Gn),t.set(f,"."+Un,o+"?"+o+".height:"+f+"."+Qn),o})}return null}(e),p=function(e,t,r){var n=e.static,a=e.dynamic;function i(e){if(e in n){var i=n[e];F.commandType(i,"object","invalid "+e,r.commandStr);var o,f,u=!0,s=0|i.x,c=0|i.y;return"width"in i?(o=0|i.width,F.command(o>=0,"invalid "+e,r.commandStr)):u=!1,"height"in i?(f=0|i.height,F.command(f>=0,"invalid "+e,r.commandStr)):u=!1,new Va(!u&&t&&t.thisDep,!u&&t&&t.contextDep,!u&&t&&t.propDep,function(e,t){var r=e.shared.context,n=o;"width"in i||(n=t.def(r,".",Hn,"-",s));var a=f;return"height"in i||(a=t.def(r,".",Un,"-",c)),[s,c,n,a]})}if(e in a){var l=a[e],d=Xa(l,function(t,r){var n=t.invoke(r,l);F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid "+e)});var a=t.shared.context,i=r.def(n,".x|0"),o=r.def(n,".y|0"),f=r.def('"width" in ',n,"?",n,".width|0:","(",a,".",Hn,"-",i,")"),u=r.def('"height" in ',n,"?",n,".height|0:","(",a,".",Un,"-",o,")");return F.optional(function(){t.assert(r,f+">=0&&"+u+">=0","invalid "+e)}),[i,o,f,u]});return t&&(d.thisDep=d.thisDep||t.thisDep,d.contextDep=d.contextDep||t.contextDep,d.propDep=d.propDep||t.propDep),d}return t?new Va(t.thisDep,t.contextDep,t.propDep,function(e,t){var r=e.shared.context;return[0,0,t.def(r,".",Hn),t.def(r,".",Un)]}):null}var o=i(Cn);if(o){var f=o;o=new Va(o.thisDep,o.contextDep,o.propDep,function(e,t){var r=f.append(e,t),n=e.shared.context;return t.set(n,"."+Nn,r[2]),t.set(n,"."+qn,r[3]),r})}return{viewport:o,scissor_box:i(On)}}(e,m,s),h=function(e,t){var r=e.static,n=e.dynamic,a=function(){if(Pn in r){var e=r[Pn];Ga(e)?e=o.getElements(o.create(e,!0)):e&&(e=o.getElements(e),F.command(e,"invalid elements",t.commandStr));var a=Ka(function(t,r){if(e){var n=t.link(e);return t.ELEMENTS=n,n}return t.ELEMENTS=null,null});return a.value=e,a}if(Pn in n){var i=n[Pn];return Xa(i,function(e,t){var r=e.shared,n=r.isBufferArgs,a=r.elements,o=e.invoke(t,i),f=t.def("null"),u=t.def(n,"(",o,")"),s=e.cond(u).then(f,"=",a,".createStream(",o,");").else(f,"=",a,".getElements(",o,");");return F.optional(function(){e.assert(s.else,"!"+o+"||"+f,"invalid elements")}),t.entry(s),t.exit(e.cond(u).then(a,".destroyStream(",f,");")),e.ELEMENTS=f,f})}return null}();function i(e,i){if(e in r){var o=0|r[e];return F.command(!i||o>=0,"invalid "+e,t.commandStr),Ka(function(e,t){return i&&(e.OFFSET=o),o})}if(e in n){var f=n[e];return Xa(f,function(t,r){var n=t.invoke(r,f);return i&&(t.OFFSET=n,F.optional(function(){t.assert(r,n+">=0","invalid "+e)})),n})}return i&&a?Ka(function(e,t){return e.OFFSET="0",0}):null}var f=i(Rn,!0);return{elements:a,primitive:function(){if(Bn in r){var e=r[Bn];return F.commandParameter(e,ye,"invalid primitve",t.commandStr),Ka(function(t,r){return ye[e]})}if(Bn in n){var i=n[Bn];return Xa(i,function(e,t){var r=e.constants.primTypes,n=e.invoke(t,i);return F.optional(function(){e.assert(t,n+" in "+r,"invalid primitive, must be one of "+Object.keys(ye))}),t.def(r,"[",n,"]")})}return a?Ya(a)?a.value?Ka(function(e,t){return t.def(e.ELEMENTS,".primType")}):Ka(function(){return Aa}):new Va(a.thisDep,a.contextDep,a.propDep,function(e,t){var r=e.ELEMENTS;return t.def(r,"?",r,".primType:",Aa)}):null}(),count:function(){if(In in r){var e=0|r[In];return F.command("number"==typeof e&&e>=0,"invalid vertex count",t.commandStr),Ka(function(){return e})}if(In in n){var i=n[In];return Xa(i,function(e,t){var r=e.invoke(t,i);return F.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">=0&&"+r+"===("+r+"|0)","invalid vertex count")}),r})}if(a){if(Ya(a)){if(a)return f?new Va(f.thisDep,f.contextDep,f.propDep,function(e,t){var r=t.def(e.ELEMENTS,".vertCount-",e.OFFSET);return F.optional(function(){e.assert(t,r+">=0","invalid vertex offset/element buffer too small")}),r}):Ka(function(e,t){return t.def(e.ELEMENTS,".vertCount")});var o=Ka(function(){return-1});return F.optional(function(){o.MISSING=!0}),o}var u=new Va(a.thisDep||f.thisDep,a.contextDep||f.contextDep,a.propDep||f.propDep,function(e,t){var r=e.ELEMENTS;return e.OFFSET?t.def(r,"?",r,".vertCount-",e.OFFSET,":-1"):t.def(r,"?",r,".vertCount:-1")});return F.optional(function(){u.DYNAMIC=!0}),u}return null}(),instances:i(Wn,!1),offset:f}}(e,s),y=function(e,t){var r=e.static,n=e.dynamic,i={};return k.forEach(function(e){var o=S(e);function f(t,a){if(e in r){var f=t(r[e]);i[o]=Ka(function(){return f})}else if(e in n){var u=n[e];i[o]=Xa(u,function(e,t){return a(e,t,e.invoke(t,u))})}}switch(e){case hn:case on:case an:case An:case cn:case Dn:case yn:case wn:case kn:case mn:return f(function(r){return F.commandType(r,"boolean",e,t.commandStr),r},function(t,r,n){return F.optional(function(){t.assert(r,"typeof "+n+'==="boolean"',"invalid flag "+e,t.commandStr)}),n});case ln:return f(function(r){return F.commandParameter(r,Ha,"invalid "+e,t.commandStr),Ha[r]},function(t,r,n){var a=t.constants.compareFuncs;return F.optional(function(){t.assert(r,n+" in "+a,"invalid "+e+", must be one of "+Object.keys(Ha))}),r.def(a,"[",n,"]")});case dn:return f(function(e){return F.command(Pe(e)&&2===e.length&&"number"==typeof e[0]&&"number"==typeof e[1]&&e[0]<=e[1],"depth range is 2d array",t.commandStr),e},function(e,t,r){return F.optional(function(){e.assert(t,e.shared.isArrayLike+"("+r+")&&"+r+".length===2&&typeof "+r+'[0]==="number"&&typeof '+r+'[1]==="number"&&'+r+"[0]<="+r+"[1]","depth range must be a 2d array")}),[t.def("+",r,"[0]"),t.def("+",r,"[1]")]});case sn:return f(function(e){F.commandType(e,"object","blend.func",t.commandStr);var r="srcRGB"in e?e.srcRGB:e.src,n="srcAlpha"in e?e.srcAlpha:e.src,a="dstRGB"in e?e.dstRGB:e.dst,i="dstAlpha"in e?e.dstAlpha:e.dst;return F.commandParameter(r,Ra,o+".srcRGB",t.commandStr),F.commandParameter(n,Ra,o+".srcAlpha",t.commandStr),F.commandParameter(a,Ra,o+".dstRGB",t.commandStr),F.commandParameter(i,Ra,o+".dstAlpha",t.commandStr),F.command(-1===Wa.indexOf(r+", "+a),"unallowed blending combination (srcRGB, dstRGB) = ("+r+", "+a+")",t.commandStr),[Ra[r],Ra[a],Ra[n],Ra[i]]},function(t,r,n){var a=t.constants.blendFuncs;function i(i,o){var f=r.def('"',i,o,'" in ',n,"?",n,".",i,o,":",n,".",i);return F.optional(function(){t.assert(r,f+" in "+a,"invalid "+e+"."+i+o+", must be one of "+Object.keys(Ra))}),f}F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid blend func, must be an object")});var o=i("src","RGB"),f=i("dst","RGB");F.optional(function(){var e=t.constants.invalidBlendCombinations;t.assert(r,e+".indexOf("+o+'+", "+'+f+") === -1 ","unallowed blending combination for (srcRGB, dstRGB)")});var u=r.def(a,"[",o,"]"),s=r.def(a,"[",i("src","Alpha"),"]");return[u,r.def(a,"[",f,"]"),s,r.def(a,"[",i("dst","Alpha"),"]")]});case un:return f(function(r){return"string"==typeof r?(F.commandParameter(r,v,"invalid "+e,t.commandStr),[v[r],v[r]]):"object"==typeof r?(F.commandParameter(r.rgb,v,e+".rgb",t.commandStr),F.commandParameter(r.alpha,v,e+".alpha",t.commandStr),[v[r.rgb],v[r.alpha]]):void F.commandRaise("invalid blend.equation",t.commandStr)},function(t,r,n){var a=t.constants.blendEquations,i=r.def(),o=r.def(),f=t.cond("typeof ",n,'==="string"');return F.optional(function(){function r(e,r,n){t.assert(e,n+" in "+a,"invalid "+r+", must be one of "+Object.keys(v))}r(f.then,e,n),t.assert(f.else,n+"&&typeof "+n+'==="object"',"invalid "+e),r(f.else,e+".rgb",n+".rgb"),r(f.else,e+".alpha",n+".alpha")}),f.then(i,"=",o,"=",a,"[",n,"];"),f.else(i,"=",a,"[",n,".rgb];",o,"=",a,"[",n,".alpha];"),r(f),[i,o]});case fn:return f(function(e){return F.command(Pe(e)&&4===e.length,"blend.color must be a 4d array",t.commandStr),q(4,function(t){return+e[t]})},function(e,t,r){return F.optional(function(){e.assert(t,e.shared.isArrayLike+"("+r+")&&"+r+".length===4","blend.color must be a 4d array")}),q(4,function(e){return t.def("+",r,"[",e,"]")})});case Sn:return f(function(e){return F.commandType(e,"number",o,t.commandStr),0|e},function(e,t,r){return F.optional(function(){e.assert(t,"typeof "+r+'==="number"',"invalid stencil.mask")}),t.def(r,"|0")});case En:return f(function(r){F.commandType(r,"object",o,t.commandStr);var n=r.cmp||"keep",a=r.ref||0,i="mask"in r?r.mask:-1;return F.commandParameter(n,Ha,e+".cmp",t.commandStr),F.commandType(a,"number",e+".ref",t.commandStr),F.commandType(i,"number",e+".mask",t.commandStr),[Ha[n],a,i]},function(e,t,r){var n=e.constants.compareFuncs;return F.optional(function(){function a(){e.assert(t,Array.prototype.join.call(arguments,""),"invalid stencil.func")}a(r+"&&typeof ",r,'==="object"'),a('!("cmp" in ',r,")||(",r,".cmp in ",n,")")}),[t.def('"cmp" in ',r,"?",n,"[",r,".cmp]",":",Fa),t.def(r,".ref|0"),t.def('"mask" in ',r,"?",r,".mask|0:-1")]});case Tn:case jn:return f(function(r){F.commandType(r,"object",o,t.commandStr);var n=r.fail||"keep",a=r.zfail||"keep",i=r.zpass||"keep";return F.commandParameter(n,Ua,e+".fail",t.commandStr),F.commandParameter(a,Ua,e+".zfail",t.commandStr),F.commandParameter(i,Ua,e+".zpass",t.commandStr),[e===jn?Ea:Sa,Ua[n],Ua[a],Ua[i]]},function(t,r,n){var a=t.constants.stencilOps;function i(i){return F.optional(function(){t.assert(r,'!("'+i+'" in '+n+")||("+n+"."+i+" in "+a+")","invalid "+e+"."+i+", must be one of "+Object.keys(Ua))}),r.def('"',i,'" in ',n,"?",a,"[",n,".",i,"]:",Fa)}return F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid "+e)}),[e===jn?Ea:Sa,i("fail"),i("zfail"),i("zpass")]});case xn:return f(function(e){F.commandType(e,"object",o,t.commandStr);var r=0|e.factor,n=0|e.units;return F.commandType(r,"number",o+".factor",t.commandStr),F.commandType(n,"number",o+".units",t.commandStr),[r,n]},function(t,r,n){return F.optional(function(){t.assert(r,n+"&&typeof "+n+'==="object"',"invalid "+e)}),[r.def(n,".factor|0"),r.def(n,".units|0")]});case bn:return f(function(e){var r=0;return"front"===e?r=Sa:"back"===e&&(r=Ea),F.command(!!r,o,t.commandStr),r},function(e,t,r){return F.optional(function(){e.assert(t,r+'==="front"||'+r+'==="back"',"invalid cull.face")}),t.def(r,'==="front"?',Sa,":",Ea)});case gn:return f(function(e){return F.command("number"==typeof e&&e>=a.lineWidthDims[0]&&e<=a.lineWidthDims[1],"invalid line width, must be a positive number between "+a.lineWidthDims[0]+" and "+a.lineWidthDims[1],t.commandStr),e},function(e,t,r){return F.optional(function(){e.assert(t,"typeof "+r+'==="number"&&'+r+">="+a.lineWidthDims[0]+"&&"+r+"<="+a.lineWidthDims[1],"invalid line width")}),r});case vn:return f(function(e){return F.commandParameter(e,qa,o,t.commandStr),qa[e]},function(e,t,r){return F.optional(function(){e.assert(t,r+'==="cw"||'+r+'==="ccw"',"invalid frontFace, must be one of cw,ccw")}),t.def(r+'==="cw"?'+Ta+":"+ja)});case pn:return f(function(e){return F.command(Pe(e)&&4===e.length,"color.mask must be length 4 array",t.commandStr),e.map(function(e){return!!e})},function(e,t,r){return F.optional(function(){e.assert(t,e.shared.isArrayLike+"("+r+")&&"+r+".length===4","invalid color.mask")}),q(4,function(e){return"!!"+r+"["+e+"]"})});case _n:return f(function(e){F.command("object"==typeof e&&e,o,t.commandStr);var r="value"in e?e.value:1,n=!!e.invert;return F.command("number"==typeof r&&r>=0&&r<=1,"sample.coverage.value must be a number between 0 and 1",t.commandStr),[r,n]},function(e,t,r){return F.optional(function(){e.assert(t,r+"&&typeof "+r+'==="object"',"invalid sample.coverage")}),[t.def('"value" in ',r,"?+",r,".value:1"),t.def("!!",r,".invert")]})}}),i}(e,s),x=function(e){var t=e.static,n=e.dynamic;function a(e){if(e in t){var a=r.id(t[e]);F.optional(function(){l.shader(Na[e],a,F.guessCommand())});var i=Ka(function(){return a});return i.id=a,i}if(e in n){var o=n[e];return Xa(o,function(t,r){var n=t.invoke(r,o),a=r.def(t.shared.strings,".id(",n,")");return F.optional(function(){r(t.shared.shader,".shader(",Na[e],",",a,",",t.command,");")}),a})}return null}var i,o=a(Mn),f=a(Ln),u=null;return Ya(o)&&Ya(f)?(u=l.program(f.id,o.id),i=Ka(function(e,t){return e.link(u)})):i=new Va(o&&o.thisDep||f&&f.thisDep,o&&o.contextDep||f&&f.contextDep,o&&o.propDep||f&&f.propDep,function(e,t){var r,n,a=e.shared.shader;r=o?o.append(e,t):t.def(a,".",Mn),n=f?f.append(e,t):t.def(a,".",Ln);var i=a+".program("+n+","+r;return F.optional(function(){i+=","+e.command}),t.def(i+")")}),{frag:o,vert:f,progVar:i,program:u}}(e);function w(e){var t=p[e];t&&(y[e]=t)}w(Cn),w(S(On));var _=Object.keys(y).length>0,A={framebuffer:m,draw:h,shader:x,state:y,dirty:_};return A.profile=function(e){var t,r=e.static,n=e.dynamic;if(Fn in r){var a=!!r[Fn];(t=Ka(function(e,t){return a})).enable=a}else if(Fn in n){var i=n[Fn];t=Xa(i,function(e,t){return e.invoke(t,i)})}return t}(e),A.uniforms=function(e,t){var r=e.static,n=e.dynamic,a={};return Object.keys(r).forEach(function(e){var n,i=r[e];if("number"==typeof i||"boolean"==typeof i)n=Ka(function(){return i});else if("function"==typeof i){var o=i._reglType;"texture2d"===o||"textureCube"===o?n=Ka(function(e){return e.link(i)}):"framebuffer"===o||"framebufferCube"===o?(F.command(i.color.length>0,'missing color attachment for framebuffer sent to uniform "'+e+'"',t.commandStr),n=Ka(function(e){return e.link(i.color[0])})):F.commandRaise('invalid data for uniform "'+e+'"',t.commandStr)}else Pe(i)?n=Ka(function(t){return t.global.def("[",q(i.length,function(r){return F.command("number"==typeof i[r]||"boolean"==typeof i[r],"invalid uniform "+e,t.commandStr),i[r]}),"]")}):F.commandRaise('invalid or missing data for uniform "'+e+'"',t.commandStr);n.value=i,a[e]=n}),Object.keys(n).forEach(function(e){var t=n[e];a[e]=Xa(t,function(e,r){return e.invoke(r,t)})}),a}(n,s),A.attributes=function(e,t){var n=e.static,a=e.dynamic,o={};return Object.keys(n).forEach(function(e){var a=n[e],f=r.id(e),u=new b;if(Ga(a))u.state=$r,u.buffer=i.getBuffer(i.create(a,Yn,!1,!0)),u.type=0;else{var s=i.getBuffer(a);if(s)u.state=$r,u.buffer=s,u.type=0;else if(F.command("object"==typeof a&&a,"invalid data for attribute "+e,t.commandStr),"constant"in a){var c=a.constant;u.buffer="null",u.state=Jr,"number"==typeof c?u.x=c:(F.command(Pe(c)&&c.length>0&&c.length<=4,"invalid constant for attribute "+e,t.commandStr),Kr.forEach(function(e,t){t<c.length&&(u[e]=c[t])}))}else{s=Ga(a.buffer)?i.getBuffer(i.create(a.buffer,Yn,!1,!0)):i.getBuffer(a.buffer),F.command(!!s,'missing buffer for attribute "'+e+'"',t.commandStr);var l=0|a.offset;F.command(l>=0,'invalid offset for attribute "'+e+'"',t.commandStr);var d=0|a.stride;F.command(d>=0&&d<256,'invalid stride for attribute "'+e+'", must be integer betweeen [0, 255]',t.commandStr);var m=0|a.size;F.command(!("size"in a)||m>0&&m<=4,'invalid size for attribute "'+e+'", must be 1,2,3,4',t.commandStr);var p=!!a.normalized,h=0;"type"in a&&(F.commandParameter(a.type,fe,"invalid type for attribute "+e,t.commandStr),h=fe[a.type]);var v=0|a.divisor;"divisor"in a&&(F.command(0===v||g,'cannot specify divisor for attribute "'+e+'", instancing not supported',t.commandStr),F.command(v>=0,'invalid divisor for attribute "'+e+'"',t.commandStr)),F.optional(function(){var r=t.commandStr,n=["buffer","offset","divisor","normalized","type","size","stride"];Object.keys(a).forEach(function(t){F.command(n.indexOf(t)>=0,'unknown parameter "'+t+'" for attribute pointer "'+e+'" (valid parameters are '+n+")",r)})}),u.buffer=s,u.state=$r,u.size=m,u.normalized=p,u.type=h||s.dtype,u.offset=l,u.stride=d,u.divisor=v}}o[e]=Ka(function(e,t){var r=e.attribCache;if(f in r)return r[f];var n={isStream:!1};return Object.keys(u).forEach(function(e){n[e]=u[e]}),u.buffer&&(n.buffer=e.link(u.buffer),n.type=n.type||n.buffer+".dtype"),r[f]=n,n})}),Object.keys(a).forEach(function(e){var t=a[e];o[e]=Xa(t,function(r,n){var a=r.invoke(n,t),i=r.shared,o=i.isBufferArgs,f=i.buffer;F.optional(function(){r.assert(n,a+"&&(typeof "+a+'==="object"||typeof '+a+'==="function")&&('+o+"("+a+")||"+f+".getBuffer("+a+")||"+f+".getBuffer("+a+".buffer)||"+o+"("+a+'.buffer)||("constant" in '+a+"&&(typeof "+a+'.constant==="number"||'+i.isArrayLike+"("+a+".constant))))",'invalid dynamic attribute "'+e+'"')});var u={isStream:n.def(!1)},s=new b;s.state=$r,Object.keys(s).forEach(function(e){u[e]=n.def(""+s[e])});var c=u.buffer,l=u.type;function d(e){n(u[e],"=",a,".",e,"|0;")}return n("if(",o,"(",a,")){",u.isStream,"=true;",c,"=",f,".createStream(",Yn,",",a,");",l,"=",c,".dtype;","}else{",c,"=",f,".getBuffer(",a,");","if(",c,"){",l,"=",c,".dtype;",'}else if("constant" in ',a,"){",u.state,"=",Jr,";","if(typeof "+a+'.constant === "number"){',u[Kr[0]],"=",a,".constant;",Kr.slice(1).map(function(e){return u[e]}).join("="),"=0;","}else{",Kr.map(function(e,t){return u[e]+"="+a+".constant.length>"+t+"?"+a+".constant["+t+"]:0;"}).join(""),"}}else{","if(",o,"(",a,".buffer)){",c,"=",f,".createStream(",Yn,",",a,".buffer);","}else{",c,"=",f,".getBuffer(",a,".buffer);","}",l,'="type" in ',a,"?",i.glTypes,"[",a,".type]:",c,".dtype;",u.normalized,"=!!",a,".normalized;"),d("size"),d("offset"),d("stride"),d("divisor"),n("}}"),n.exit("if(",u.isStream,"){",f,".destroyStream(",c,");","}"),u})}),o}(t,s),A.context=function(e){var t=e.static,r=e.dynamic,n={};return Object.keys(t).forEach(function(e){var r=t[e];n[e]=Ka(function(e,t){return"number"==typeof r||"boolean"==typeof r?""+r:e.link(r)})}),Object.keys(r).forEach(function(e){var t=r[e];n[e]=Xa(t,function(e,r){return e.invoke(r,t)})}),n}(f),A}function L(e,t,r){var n=e.shared,a=n.context,i=e.scope();Object.keys(r).forEach(function(n){t.save(a,"."+n);var o=r[n];i(a,".",n,"=",o.append(e,t),";")}),t(i)}function M(e,t,r,n){var a,i=e.shared,o=i.gl,f=i.framebuffer;y&&(a=t.def(i.extensions,".webgl_draw_buffers"));var u,s=e.constants,c=s.drawBuffer,l=s.backBuffer;u=r?r.append(e,t):t.def(f,".next"),n||t("if(",u,"!==",f,".cur){"),t("if(",u,"){",o,".bindFramebuffer(",Ba,",",u,".framebuffer);"),y&&t(a,".drawBuffersWEBGL(",c,"[",u,".colorAttachments.length]);"),t("}else{",o,".bindFramebuffer(",Ba,",null);"),y&&t(a,".drawBuffersWEBGL(",l,");"),t("}",f,".cur=",u,";"),n||t("}")}function P(e,t,r){var n=e.shared,a=n.gl,i=e.current,o=e.next,f=n.current,u=n.next,s=e.cond(f,".dirty");k.forEach(function(t){var n,c,l=S(t);if(!(l in r.state))if(l in o){n=o[l],c=i[l];var d=q(x[l].length,function(e){return s.def(n,"[",e,"]")});s(e.cond(d.map(function(e,t){return e+"!=="+c+"["+t+"]"}).join("||")).then(a,".",A[l],"(",d,");",d.map(function(e,t){return c+"["+t+"]="+e}).join(";"),";"))}else{n=s.def(u,".",l);var m=e.cond(n,"!==",f,".",l);s(m),l in _?m(e.cond(n).then(a,".enable(",_[l],");").else(a,".disable(",_[l],");"),f,".",l,"=",n,";"):m(a,".",A[l],"(",n,");",f,".",l,"=",n,";")}}),0===Object.keys(r.state).length&&s(f,".dirty=false;"),t(s)}function B(e,t,r,n){var a=e.shared,i=e.current,o=a.current,f=a.gl;Qa(Object.keys(r)).forEach(function(a){var u=r[a];if(!n||n(u)){var s=u.append(e,t);if(_[a]){var c=_[a];Ya(u)?t(f,s?".enable(":".disable(",c,");"):t(e.cond(s).then(f,".enable(",c,");").else(f,".disable(",c,");")),t(o,".",a,"=",s,";")}else if(Pe(s)){var l=i[a];t(f,".",A[a],"(",s,");",s.map(function(e,t){return l+"["+t+"]="+e}).join(";"),";")}else t(f,".",A[a],"(",s,");",o,".",a,"=",s,";")}})}function R(e,t){g&&(e.instancing=t.def(e.shared.extensions,".angle_instanced_arrays"))}function W(e,t,r,n,a){var i,o,f,u=e.shared,s=e.stats,c=u.current,l=u.timer,d=r.profile;function m(){return"undefined"==typeof performance?"Date.now()":"performance.now()"}function h(e){i=t.def(),e(i,"=",m(),";"),"string"==typeof a?e(s,".count+=",a,";"):e(s,".count++;"),p&&(n?(o=t.def(),e(o,"=",l,".getNumPendingQueries();")):e(l,".beginQuery(",s,");"))}function b(e){e(s,".cpuTime+=",m(),"-",i,";"),p&&(n?e(l,".pushScopeStats(",o,",",l,".getNumPendingQueries(),",s,");"):e(l,".endQuery();"))}function v(e){var r=t.def(c,".profile");t(c,".profile=",e,";"),t.exit(c,".profile=",r,";")}if(d){if(Ya(d))return void(d.enable?(h(t),b(t.exit),v("true")):v("false"));v(f=d.append(e,t))}else f=t.def(c,".profile");var g=e.block();h(g),t("if(",f,"){",g,"}");var y=e.block();b(y),t.exit("if(",f,"){",y,"}")}function H(e,t,r,n,a){var i=e.shared;n.forEach(function(n){var o,f=n.name,u=r.attributes[f];if(u){if(!a(u))return;o=u.append(e,t)}else{if(!a($a))return;var s=e.scopeAttrib(f);F.optional(function(){e.assert(t,s+".state","missing attribute "+f)}),o={},Object.keys(new b).forEach(function(e){o[e]=t.def(s,".",e)})}!function(r,n,a){var o=i.gl,f=t.def(r,".location"),u=t.def(i.attributes,"[",f,"]"),s=a.state,c=a.buffer,l=[a.x,a.y,a.z,a.w],d=["buffer","normalized","offset","stride"];function m(){t("if(!",u,".buffer){",o,".enableVertexAttribArray(",f,");}");var r,i=a.type;if(r=a.size?t.def(a.size,"||",n):n,t("if(",u,".type!==",i,"||",u,".size!==",r,"||",d.map(function(e){return u+"."+e+"!=="+a[e]}).join("||"),"){",o,".bindBuffer(",Yn,",",c,".buffer);",o,".vertexAttribPointer(",[f,r,i,a.normalized,a.stride,a.offset],");",u,".type=",i,";",u,".size=",r,";",d.map(function(e){return u+"."+e+"="+a[e]+";"}).join(""),"}"),g){var s=a.divisor;t("if(",u,".divisor!==",s,"){",e.instancing,".vertexAttribDivisorANGLE(",[f,s],");",u,".divisor=",s,";}")}}function p(){t("if(",u,".buffer){",o,".disableVertexAttribArray(",f,");","}if(",Kr.map(function(e,t){return u+"."+e+"!=="+l[t]}).join("||"),"){",o,".vertexAttrib4f(",f,",",l,");",Kr.map(function(e,t){return u+"."+e+"="+l[t]+";"}).join(""),"}")}s===$r?m():s===Jr?p():(t("if(",s,"===",$r,"){"),m(),t("}else{"),p(),t("}"))}(e.link(n),function(e){switch(e){case ua:case da:case ba:return 2;case sa:case ma:case va:return 3;case ca:case pa:case ga:return 4;default:return 1}}(n.info.type),o)})}function U(e,t,n,a,i){for(var o,f=e.shared,u=f.gl,s=0;s<a.length;++s){var c,l=a[s],d=l.name,m=l.info.type,p=n.uniforms[d],h=e.link(l),b=h+".location";if(p){if(!i(p))continue;if(Ya(p)){var v=p.value;if(F.command(null!=v,'missing uniform "'+d+'"',e.commandStr),m===ka||m===_a){F.command("function"==typeof v&&(m===ka&&("texture2d"===v._reglType||"framebuffer"===v._reglType)||m===_a&&("textureCube"===v._reglType||"framebufferCube"===v._reglType)),"invalid texture for uniform "+d,e.commandStr);var g=e.link(v._texture||v.color[0]._texture);t(u,".uniform1i(",b,",",g+".bind());"),t.exit(g,".unbind();")}else if(m===ya||m===xa||m===wa){F.optional(function(){F.command(Pe(v),"invalid matrix for uniform "+d,e.commandStr),F.command(m===ya&&4===v.length||m===xa&&9===v.length||m===wa&&16===v.length,"invalid length for matrix uniform "+d,e.commandStr)});var y=e.global.def("new Float32Array(["+Array.prototype.slice.call(v)+"])"),x=2;m===xa?x=3:m===wa&&(x=4),t(u,".uniformMatrix",x,"fv(",b,",false,",y,");")}else{switch(m){case fa:F.commandType(v,"number","uniform "+d,e.commandStr),o="1f";break;case ua:F.command(Pe(v)&&2===v.length,"uniform "+d,e.commandStr),o="2f";break;case sa:F.command(Pe(v)&&3===v.length,"uniform "+d,e.commandStr),o="3f";break;case ca:F.command(Pe(v)&&4===v.length,"uniform "+d,e.commandStr),o="4f";break;case ha:F.commandType(v,"boolean","uniform "+d,e.commandStr),o="1i";break;case la:F.commandType(v,"number","uniform "+d,e.commandStr),o="1i";break;case ba:case da:F.command(Pe(v)&&2===v.length,"uniform "+d,e.commandStr),o="2i";break;case va:case ma:F.command(Pe(v)&&3===v.length,"uniform "+d,e.commandStr),o="3i";break;case ga:case pa:F.command(Pe(v)&&4===v.length,"uniform "+d,e.commandStr),o="4i"}t(u,".uniform",o,"(",b,",",Pe(v)?Array.prototype.slice.call(v):v,");")}continue}c=p.append(e,t)}else{if(!i($a))continue;c=t.def(f.uniforms,"[",r.id(d),"]")}m===ka?t("if(",c,"&&",c,'._reglType==="framebuffer"){',c,"=",c,".color[0];","}"):m===_a&&t("if(",c,"&&",c,'._reglType==="framebufferCube"){',c,"=",c,".color[0];","}"),F.optional(function(){function r(r,n){e.assert(t,r,'bad data or missing for uniform "'+d+'". '+n)}function n(e){r("typeof "+c+'==="'+e+'"',"invalid type, expected "+e)}function a(t,n){r(f.isArrayLike+"("+c+")&&"+c+".length==="+t,"invalid vector, should have length "+t,e.commandStr)}function i(t){r("typeof "+c+'==="function"&&'+c+'._reglType==="texture'+(t===Xn?"2d":"Cube")+'"',"invalid texture type",e.commandStr)}switch(m){case la:n("number");break;case da:a(2);break;case ma:a(3);break;case pa:a(4);break;case fa:n("number");break;case ua:a(2);break;case sa:a(3);break;case ca:a(4);break;case ha:n("boolean");break;case ba:a(2);break;case va:a(3);break;case ga:case ya:a(4);break;case xa:a(9);break;case wa:a(16);break;case ka:i(Xn);break;case _a:i($n)}});var w=1;switch(m){case ka:case _a:var k=t.def(c,"._texture");t(u,".uniform1i(",b,",",k,".bind());"),t.exit(k,".unbind();");continue;case la:case ha:o="1i";break;case da:case ba:o="2i",w=2;break;case ma:case va:o="3i",w=3;break;case pa:case ga:o="4i",w=4;break;case fa:o="1f";break;case ua:o="2f",w=2;break;case sa:o="3f",w=3;break;case ca:o="4f",w=4;break;case ya:o="Matrix2fv";break;case xa:o="Matrix3fv";break;case wa:o="Matrix4fv"}if(t(u,".uniform",o,"(",b,","),"M"===o.charAt(0)){var _=Math.pow(m-ya+2,2),A=e.global.def("new Float32Array(",_,")");t("false,(Array.isArray(",c,")||",c," instanceof Float32Array)?",c,":(",q(_,function(e){return A+"["+e+"]="+c+"["+e+"]"}),",",A,")")}else t(w>1?q(w,function(e){return c+"["+e+"]"}):c);t(");")}}function N(e,t,r,n){var a=e.shared,i=a.gl,o=a.draw,f=n.draw,u=function(){var a,u=f.elements,s=t;return u?((u.contextDep&&n.contextDynamic||u.propDep)&&(s=r),a=u.append(e,s)):a=s.def(o,".",Pn),a&&s("if("+a+")"+i+".bindBuffer("+Kn+","+a+".buffer.buffer);"),a}();function s(a){var i=f[a];return i?i.contextDep&&n.contextDynamic||i.propDep?i.append(e,r):i.append(e,t):t.def(o,".",a)}var c,l,d=s(Bn),m=s(Rn),p=function(){var a,i=f.count,u=t;return i?((i.contextDep&&n.contextDynamic||i.propDep)&&(u=r),a=i.append(e,u),F.optional(function(){i.MISSING&&e.assert(t,"false","missing vertex count"),i.DYNAMIC&&e.assert(u,a+">=0","missing vertex count")})):(a=u.def(o,".",In),F.optional(function(){e.assert(u,a+">=0","missing vertex count")})),a}();if("number"==typeof p){if(0===p)return}else r("if(",p,"){"),r.exit("}");g&&(c=s(Wn),l=e.instancing);var h=u+".type",b=f.elements&&Ya(f.elements);function v(){function e(){r(l,".drawElementsInstancedANGLE(",[d,p,h,m+"<<(("+h+"-"+Xr+")>>1)",c],");")}function t(){r(l,".drawArraysInstancedANGLE(",[d,m,p,c],");")}u?b?e():(r("if(",u,"){"),e(),r("}else{"),t(),r("}")):t()}function y(){function e(){r(i+".drawElements("+[d,p,h,m+"<<(("+h+"-"+Xr+")>>1)"]+");")}function t(){r(i+".drawArrays("+[d,m,p]+");")}u?b?e():(r("if(",u,"){"),e(),r("}else{"),t(),r("}")):t()}g&&("number"!=typeof c||c>=0)?"string"==typeof c?(r("if(",c,">0){"),v(),r("}else if(",c,"<0){"),y(),r("}")):v():y()}function G(e,t,r,n,a){var i=C(),o=i.proc("body",a);return F.optional(function(){i.commandStr=t.commandStr,i.command=i.link(t.commandStr)}),g&&(i.instancing=o.def(i.shared.extensions,".angle_instanced_arrays")),e(i,o,r,n),i.compile().body}function Q(e,t,r,n){R(e,t),H(e,t,r,n.attributes,function(){return!0}),U(e,t,r,n.uniforms,function(){return!0}),N(e,t,t,r)}function V(e,t,r,n){function a(){return!0}e.batchId="a1",R(e,t),H(e,t,r,n.attributes,a),U(e,t,r,n.uniforms,a),N(e,t,t,r)}function Y(e,t,r,n){R(e,t);var a=r.contextDep,i=t.def(),o=t.def();e.shared.props=o,e.batchId=i;var f=e.scope(),u=e.scope();function s(e){return e.contextDep&&a||e.propDep}function c(e){return!s(e)}if(t(f.entry,"for(",i,"=0;",i,"<","a1",";++",i,"){",o,"=","a0","[",i,"];",u,"}",f.exit),r.needsContext&&L(e,u,r.context),r.needsFramebuffer&&M(e,u,r.framebuffer),B(e,u,r.state,s),r.profile&&s(r.profile)&&W(e,u,r,!1,!0),n)H(e,f,r,n.attributes,c),H(e,u,r,n.attributes,s),U(e,f,r,n.uniforms,c),U(e,u,r,n.uniforms,s),N(e,f,u,r);else{var l=e.global.def("{}"),d=r.shader.progVar.append(e,u),m=u.def(d,".id"),p=u.def(l,"[",m,"]");u(e.shared.gl,".useProgram(",d,".program);","if(!",p,"){",p,"=",l,"[",m,"]=",e.link(function(t){return G(V,e,r,t,2)}),"(",d,");}",p,".call(this,a0[",i,"],",i,");")}}function K(e,t,r){var n=t.static[r];if(n&&function(e){if("object"==typeof e&&!Pe(e)){for(var t=Object.keys(e),r=0;r<t.length;++r)if(I.isDynamic(e[t[r]]))return!0;return!1}}(n)){var a=e.global,i=Object.keys(n),o=!1,f=!1,u=!1,s=e.global.def("{}");i.forEach(function(t){var r=n[t];if(I.isDynamic(r)){"function"==typeof r&&(r=n[t]=I.unbox(r));var i=Xa(r,null);o=o||i.thisDep,u=u||i.propDep,f=f||i.contextDep}else{switch(a(s,".",t,"="),typeof r){case"number":a(r);break;case"string":a('"',r,'"');break;case"object":Array.isArray(r)&&a("[",r.join(),"]");break;default:a(e.link(r))}a(";")}}),t.dynamic[r]=new I.DynamicVariable(nn,{thisDep:o,contextDep:f,propDep:u,ref:s,append:function(e,t){i.forEach(function(r){var a=n[r];if(I.isDynamic(a)){var i=e.invoke(t,a);t(s,".",r,"=",i,";")}})}}),delete t.static[r]}}return{next:w,current:x,procs:function(){var e=C(),t=e.proc("poll"),r=e.proc("refresh"),n=e.block();t(n),r(n);var i,o=e.shared,f=o.gl,u=o.next,s=o.current;n(s,".dirty=false;"),M(e,t),M(e,r,null,!0),g&&(i=e.link(g));for(var c=0;c<a.maxAttributes;++c){var l=r.def(o.attributes,"[",c,"]"),d=e.cond(l,".buffer");d.then(f,".enableVertexAttribArray(",c,");",f,".bindBuffer(",Yn,",",l,".buffer.buffer);",f,".vertexAttribPointer(",c,",",l,".size,",l,".type,",l,".normalized,",l,".stride,",l,".offset);").else(f,".disableVertexAttribArray(",c,");",f,".vertexAttrib4f(",c,",",l,".x,",l,".y,",l,".z,",l,".w);",l,".buffer=null;"),r(d),g&&r(i,".vertexAttribDivisorANGLE(",c,",",l,".divisor);")}return Object.keys(_).forEach(function(a){var i=_[a],o=n.def(u,".",a),c=e.block();c("if(",o,"){",f,".enable(",i,")}else{",f,".disable(",i,")}",s,".",a,"=",o,";"),r(c),t("if(",o,"!==",s,".",a,"){",c,"}")}),Object.keys(A).forEach(function(a){var i,o,c=A[a],l=x[a],d=e.block();if(d(f,".",c,"("),Pe(l)){var m=l.length;i=e.global.def(u,".",a),o=e.global.def(s,".",a),d(q(m,function(e){return i+"["+e+"]"}),");",q(m,function(e){return o+"["+e+"]="+i+"["+e+"];"}).join("")),t("if(",q(m,function(e){return i+"["+e+"]!=="+o+"["+e+"]"}).join("||"),"){",d,"}")}else i=n.def(u,".",a),o=n.def(s,".",a),d(i,");",s,".",a,"=",i,";"),t("if(",i,"!==",o,"){",d,"}");r(d)}),e.compile()}(),compile:function(e,t,n,a,i){var o=C();o.stats=o.link(i),Object.keys(t.static).forEach(function(e){K(o,t,e)}),Vn.forEach(function(t){K(o,e,t)});var f=z(e,t,n,a,o);return function(e,t){var r=e.proc("draw",1);R(e,r),L(e,r,t.context),M(e,r,t.framebuffer),P(e,r,t),B(e,r,t.state),W(e,r,t,!1,!0);var n=t.shader.progVar.append(e,r);if(r(e.shared.gl,".useProgram(",n,".program);"),t.shader.program)Q(e,r,t,t.shader.program);else{var a=e.global.def("{}"),i=r.def(n,".id"),o=r.def(a,"[",i,"]");r(e.cond(o).then(o,".call(this,a0);").else(o,"=",a,"[",i,"]=",e.link(function(r){return G(Q,e,t,r,1)}),"(",n,");",o,".call(this,a0);"))}Object.keys(t.state).length>0&&r(e.shared.current,".dirty=true;")}(o,f),function(e,t){var n=e.proc("scope",3);e.batchId="a2";var a=e.shared,i=a.current;function o(r){var i=t.shader[r];i&&n.set(a.shader,"."+r,i.append(e,n))}L(e,n,t.context),t.framebuffer&&t.framebuffer.append(e,n),Qa(Object.keys(t.state)).forEach(function(r){var i=t.state[r].append(e,n);Pe(i)?i.forEach(function(t,a){n.set(e.next[r],"["+a+"]",t)}):n.set(a.next,"."+r,i)}),W(e,n,t,!0,!0),[Pn,Rn,In,Wn,Bn].forEach(function(r){var i=t.draw[r];i&&n.set(a.draw,"."+r,""+i.append(e,n))}),Object.keys(t.uniforms).forEach(function(i){n.set(a.uniforms,"["+r.id(i)+"]",t.uniforms[i].append(e,n))}),Object.keys(t.attributes).forEach(function(r){var a=t.attributes[r].append(e,n),i=e.scopeAttrib(r);Object.keys(new b).forEach(function(e){n.set(i,"."+e,a[e])})}),o(Ln),o(Mn),Object.keys(t.state).length>0&&(n(i,".dirty=true;"),n.exit(i,".dirty=true;")),n("a1(",e.shared.context,",a0,",e.batchId,");")}(o,f),function(e,t){var r=e.proc("batch",2);e.batchId="0",R(e,r);var n=!1,a=!0;Object.keys(t.context).forEach(function(e){n=n||t.context[e].propDep}),n||(L(e,r,t.context),a=!1);var i=t.framebuffer,o=!1;function f(e){return e.contextDep&&n||e.propDep}i?(i.propDep?n=o=!0:i.contextDep&&n&&(o=!0),o||M(e,r,i)):M(e,r,null),t.state.viewport&&t.state.viewport.propDep&&(n=!0),P(e,r,t),B(e,r,t.state,function(e){return!f(e)}),t.profile&&f(t.profile)||W(e,r,t,!1,"a1"),t.contextDep=n,t.needsContext=a,t.needsFramebuffer=o;var u=t.shader.progVar;if(u.contextDep&&n||u.propDep)Y(e,r,t,null);else{var s=u.append(e,r);if(r(e.shared.gl,".useProgram(",s,".program);"),t.shader.program)Y(e,r,t,t.shader.program);else{var c=e.global.def("{}"),l=r.def(s,".id"),d=r.def(c,"[",l,"]");r(e.cond(d).then(d,".call(this,a0,a1);").else(d,"=",c,"[",l,"]=",e.link(function(r){return G(Y,e,t,r,2)}),"(",s,");",d,".call(this,a0,a1);"))}}Object.keys(t.state).length>0&&r(e.shared.current,".dirty=true;")}(o,f),o.compile()}}}var Za=34918,ei=34919,ti=35007,ri=function(e,t){if(!t.ext_disjoint_timer_query)return null;var r=[];function n(e){r.push(e)}var a=[];function i(){this.startQueryIndex=-1,this.endQueryIndex=-1,this.sum=0,this.stats=null}var o=[];function f(e){o.push(e)}var u=[];function s(e,t,r){var n=o.pop()||new i;n.startQueryIndex=e,n.endQueryIndex=t,n.sum=0,n.stats=r,u.push(n)}var c=[],l=[];return{beginQuery:function(e){var n=r.pop()||t.ext_disjoint_timer_query.createQueryEXT();t.ext_disjoint_timer_query.beginQueryEXT(ti,n),a.push(n),s(a.length-1,a.length,e)},endQuery:function(){t.ext_disjoint_timer_query.endQueryEXT(ti)},pushScopeStats:s,update:function(){var e,r,i=a.length;if(0!==i){l.length=Math.max(l.length,i+1),c.length=Math.max(c.length,i+1),c[0]=0,l[0]=0;var o=0;for(e=0,r=0;r<a.length;++r){var s=a[r];t.ext_disjoint_timer_query.getQueryObjectEXT(s,ei)?(o+=t.ext_disjoint_timer_query.getQueryObjectEXT(s,Za),n(s)):a[e++]=s,c[r+1]=o,l[r+1]=e}for(a.length=e,e=0,r=0;r<u.length;++r){var d=u[r],m=d.startQueryIndex,p=d.endQueryIndex;d.sum+=c[p]-c[m];var h=l[m],b=l[p];b===h?(d.stats.gpuTime+=d.sum/1e6,f(d)):(d.startQueryIndex=h,d.endQueryIndex=b,u[e++]=d)}u.length=e}},getNumPendingQueries:function(){return a.length},clear:function(){r.push.apply(r,a);for(var e=0;e<r.length;e++)t.ext_disjoint_timer_query.deleteQueryEXT(r[e]);a.length=0,r.length=0},restore:function(){a.length=0,r.length=0}}},ni=16384,ai=256,ii=1024,oi=34962,fi="webglcontextlost",ui="webglcontextrestored",si=1,ci=2,li=3;function di(e,t){for(var r=0;r<e.length;++r)if(e[r]===t)return r;return-1}return function(r){var n=N(r);if(!n)return null;var a=n.gl,i=a.getContextAttributes(),o=a.isContextLost(),f=function(e,t){var r={};function n(t){F.type(t,"string","extension name must be string");var n,a=t.toLowerCase();try{n=r[a]=e.getExtension(a)}catch(e){}return!!n}for(var a=0;a<t.extensions.length;++a){var i=t.extensions[a];if(!n(i))return t.onDestroy(),t.onDone('"'+i+'" extension is not supported by the current WebGL context, try upgrading your system or a different browser'),null}return t.optionalExtensions.forEach(n),{extensions:r,restore:function(){Object.keys(r).forEach(function(e){if(r[e]&&!n(e))throw new Error("(regl): error restoring extension "+e)})}}}(a,n);if(!f)return null;var u,s,c=(u={"":0},s=[""],{id:function(e){var t=u[e];return t||(t=u[e]=s.length,s.push(e),t)},str:function(e){return s[e]}}),l={bufferCount:0,elementsCount:0,framebufferCount:0,shaderCount:0,textureCount:0,cubeCount:0,renderbufferCount:0,maxTextureUnits:0},d=f.extensions,m=ri(a,d),p=W(),h=a.drawingBufferWidth,b=a.drawingBufferHeight,v={tick:0,time:0,viewportWidth:h,viewportHeight:b,framebufferWidth:h,framebufferHeight:b,drawingBufferWidth:h,drawingBufferHeight:b,pixelRatio:n.pixelRatio},g=te(a,d),y=function(e,t,r,n){for(var a=r.maxAttributes,i=new Array(a),o=0;o<a;++o)i[o]=new Br;return{Record:Br,scope:{},state:i}}(0,0,g),x=function(t,r,n,a){var i=0,o={};function f(e){this.id=i++,this.buffer=t.createBuffer(),this.type=e,this.usage=le,this.byteLength=0,this.dimension=1,this.dtype=me,this.persistentData=null,n.profile&&(this.stats={size:0})}f.prototype.bind=function(){t.bindBuffer(this.type,this.buffer)},f.prototype.destroy=function(){l(this)};var u=[];function s(e,r,n){e.byteLength=r.byteLength,t.bufferData(e.type,r,n)}function c(t,r,n,a,i,o){var f,u;if(t.usage=n,Array.isArray(r)){if(t.dtype=a||pe,r.length>0)if(Array.isArray(r[0])){f=ce(r);for(var c=1,l=1;l<f.length;++l)c*=f[l];t.dimension=c,u=se(r,f,t.dtype),s(t,u,n),o?t.persistentData=u:ee.freeType(u)}else if("number"==typeof r[0]){t.dimension=i;var d=ee.allocType(t.dtype,r.length);ve(d,r),s(t,d,n),o?t.persistentData=d:ee.freeType(d)}else e(r[0])?(t.dimension=r[0].length,t.dtype=a||be(r[0])||pe,u=se(r,[r.length,r[0].length],t.dtype),s(t,u,n),o?t.persistentData=u:ee.freeType(u)):F.raise("invalid buffer data")}else if(e(r))t.dtype=a||be(r),t.dimension=i,s(t,r,n),o&&(t.persistentData=new Uint8Array(new Uint8Array(r.buffer)));else if(re(r)){f=r.shape;var m=r.stride,p=r.offset,h=0,b=0,v=0,g=0;1===f.length?(h=f[0],b=1,v=m[0],g=0):2===f.length?(h=f[0],b=f[1],v=m[0],g=m[1]):F.raise("invalid shape"),t.dtype=a||be(r.data)||pe,t.dimension=b;var y=ee.allocType(t.dtype,h*b);ge(y,r.data,h,b,v,g,p),s(t,y,n),o?t.persistentData=y:ee.freeType(y)}else F.raise("invalid buffer data")}function l(e){r.bufferCount--;for(var n=0;n<a.state.length;++n){var i=a.state[n];i.buffer===e&&(t.disableVertexAttribArray(n),i.buffer=null)}var f=e.buffer;F(f,"buffer must not be deleted already"),t.deleteBuffer(f),e.buffer=null,delete o[e.id]}return n.profile&&(r.getTotalBufferSize=function(){var e=0;return Object.keys(o).forEach(function(t){e+=o[t].stats.size}),e}),{create:function(a,i,u,s){r.bufferCount++;var d=new f(i);function m(r){var a=le,i=null,o=0,f=0,u=1;return Array.isArray(r)||e(r)||re(r)?i=r:"number"==typeof r?o=0|r:r&&(F.type(r,"object","buffer arguments must be an object, a number or an array"),"data"in r&&(F(null===i||Array.isArray(i)||e(i)||re(i),"invalid data for buffer"),i=r.data),"usage"in r&&(F.parameter(r.usage,ue,"invalid buffer usage"),a=ue[r.usage]),"type"in r&&(F.parameter(r.type,fe,"invalid buffer type"),f=fe[r.type]),"dimension"in r&&(F.type(r.dimension,"number","invalid dimension"),u=0|r.dimension),"length"in r&&(F.nni(o,"buffer length must be a nonnegative integer"),o=0|r.length)),d.bind(),i?c(d,i,a,f,u,s):(o&&t.bufferData(d.type,o,a),d.dtype=f||me,d.usage=a,d.dimension=u,d.byteLength=o),n.profile&&(d.stats.size=d.byteLength*he[d.dtype]),m}function p(e,r){F(r+e.byteLength<=d.byteLength,"invalid buffer subdata call, buffer is too small. Can't write data of size "+e.byteLength+" starting from offset "+r+" to a buffer of size "+d.byteLength),t.bufferSubData(d.type,r,e)}return o[d.id]=d,u||m(a),m._reglType="buffer",m._buffer=d,m.subdata=function(t,r){var n,a=0|(r||0);if(d.bind(),e(t))p(t,a);else if(Array.isArray(t)){if(t.length>0)if("number"==typeof t[0]){var i=ee.allocType(d.dtype,t.length);ve(i,t),p(i,a),ee.freeType(i)}else if(Array.isArray(t[0])||e(t[0])){n=ce(t);var o=se(t,n,d.dtype);p(o,a),ee.freeType(o)}else F.raise("invalid buffer data")}else if(re(t)){n=t.shape;var f=t.stride,u=0,s=0,c=0,l=0;1===n.length?(u=n[0],s=1,c=f[0],l=0):2===n.length?(u=n[0],s=n[1],c=f[0],l=f[1]):F.raise("invalid shape");var h=Array.isArray(t.data)?d.dtype:be(t.data),b=ee.allocType(h,u*s);ge(b,t.data,u,s,c,l,t.offset),p(b,a),ee.freeType(b)}else F.raise("invalid data for buffer subdata");return m},n.profile&&(m.stats=d.stats),m.destroy=function(){l(d)},m},createStream:function(e,t){var r=u.pop();return r||(r=new f(e)),r.bind(),c(r,t,de,0,1,!1),r},destroyStream:function(e){u.push(e)},clear:function(){ne(o).forEach(l),u.forEach(l)},getBuffer:function(e){return e&&e._buffer instanceof f?e._buffer:null},restore:function(){ne(o).forEach(function(e){e.buffer=t.createBuffer(),t.bindBuffer(e.type,e.buffer),t.bufferData(e.type,e.persistentData||e.byteLength,e.usage)})},_initBuffer:c}}(a,l,n,y),w=function(t,r,n,a){var i={},o=0,f={uint8:Ae,uint16:Ee};function u(e){this.id=o++,i[this.id]=this,this.buffer=e,this.primType=ke,this.vertCount=0,this.type=0}r.oes_element_index_uint&&(f.uint32=je),u.prototype.bind=function(){this.buffer.bind()};var s=[];function c(a,i,o,f,u,s,c){if(a.buffer.bind(),i){var l=c;c||e(i)&&(!re(i)||e(i.data))||(l=r.oes_element_index_uint?je:Ee),n._initBuffer(a.buffer,i,o,l,3)}else t.bufferData(De,s,o),a.buffer.dtype=d||Ae,a.buffer.usage=o,a.buffer.dimension=3,a.buffer.byteLength=s;var d=c;if(!c){switch(a.buffer.dtype){case Ae:case _e:d=Ae;break;case Ee:case Se:d=Ee;break;case je:case Te:d=je;break;default:F.raise("unsupported type for element array")}a.buffer.dtype=d}a.type=d,F(d!==je||!!r.oes_element_index_uint,"32 bit element buffers not supported, enable oes_element_index_uint first");var m=u;m<0&&(m=a.buffer.byteLength,d===Ee?m>>=1:d===je&&(m>>=2)),a.vertCount=m;var p=f;if(f<0){p=ke;var h=a.buffer.dimension;1===h&&(p=xe),2===h&&(p=we),3===h&&(p=ke)}a.primType=p}function l(e){a.elementsCount--,F(null!==e.buffer,"must not double destroy elements"),delete i[e.id],e.buffer.destroy(),e.buffer=null}return{create:function(t,r){var i=n.create(null,De,!0),o=new u(i._buffer);function s(t){if(t)if("number"==typeof t)i(t),o.primType=ke,o.vertCount=0|t,o.type=Ae;else{var r=null,n=Ce,a=-1,u=-1,l=0,d=0;Array.isArray(t)||e(t)||re(t)?r=t:(F.type(t,"object","invalid arguments for elements"),"data"in t&&(r=t.data,F(Array.isArray(r)||e(r)||re(r),"invalid data for element buffer")),"usage"in t&&(F.parameter(t.usage,ue,"invalid element buffer usage"),n=ue[t.usage]),"primitive"in t&&(F.parameter(t.primitive,ye,"invalid element buffer primitive"),a=ye[t.primitive]),"count"in t&&(F("number"==typeof t.count&&t.count>=0,"invalid vertex count for elements"),u=0|t.count),"type"in t&&(F.parameter(t.type,f,"invalid buffer type"),d=f[t.type]),"length"in t?l=0|t.length:(l=u,d===Ee||d===Se?l*=2:d!==je&&d!==Te||(l*=4))),c(o,r,n,a,u,l,d)}else i(),o.primType=ke,o.vertCount=0,o.type=Ae;return s}return a.elementsCount++,s(t),s._reglType="elements",s._elements=o,s.subdata=function(e,t){return i.subdata(e,t),s},s.destroy=function(){l(o)},s},createStream:function(e){var t=s.pop();return t||(t=new u(n.create(null,De,!0,!1)._buffer)),c(t,e,Oe,-1,-1,0,0),t},destroyStream:function(e){s.push(e)},getElements:function(e){return"function"==typeof e&&e._elements instanceof u?e._elements:null},clear:function(){ne(i).forEach(l)}}}(a,d,x,l),k=function(e,t,r,n){var a={},i={};function o(e,t,r,n){this.name=e,this.id=t,this.location=r,this.info=n}function f(e,t){for(var r=0;r<e.length;++r)if(e[r].id===t.id)return void(e[r].location=t.location);e.push(t)}function u(r,n,o){var f=r===Ir?a:i,u=f[n];if(!u){var s=t.str(n);u=e.createShader(r),e.shaderSource(u,s),e.compileShader(u),F.shaderError(e,u,s,r,o),f[n]=u}return u}var s={},c=[],l=0;function d(e,t){this.id=l++,this.fragId=e,this.vertId=t,this.program=null,this.uniforms=[],this.attributes=[],n.profile&&(this.stats={uniformsCount:0,attributesCount:0})}function m(r,a){var i,s,c=u(Ir,r.fragId),l=u(Rr,r.vertId),d=r.program=e.createProgram();e.attachShader(d,c),e.attachShader(d,l),e.linkProgram(d),F.linkError(e,d,t.str(r.fragId),t.str(r.vertId),a);var m=e.getProgramParameter(d,Wr);n.profile&&(r.stats.uniformsCount=m);var p=r.uniforms;for(i=0;i<m;++i)if(s=e.getActiveUniform(d,i))if(s.size>1)for(var h=0;h<s.size;++h){var b=s.name.replace("[0]","["+h+"]");f(p,new o(b,t.id(b),e.getUniformLocation(d,b),s))}else f(p,new o(s.name,t.id(s.name),e.getUniformLocation(d,s.name),s));var v=e.getProgramParameter(d,Hr);n.profile&&(r.stats.attributesCount=v);var g=r.attributes;for(i=0;i<v;++i)(s=e.getActiveAttrib(d,i))&&f(g,new o(s.name,t.id(s.name),e.getAttribLocation(d,s.name),s))}return n.profile&&(r.getMaxUniformsCount=function(){var e=0;return c.forEach(function(t){t.stats.uniformsCount>e&&(e=t.stats.uniformsCount)}),e},r.getMaxAttributesCount=function(){var e=0;return c.forEach(function(t){t.stats.attributesCount>e&&(e=t.stats.attributesCount)}),e}),{clear:function(){var t=e.deleteShader.bind(e);ne(a).forEach(t),a={},ne(i).forEach(t),i={},c.forEach(function(t){e.deleteProgram(t.program)}),c.length=0,s={},r.shaderCount=0},program:function(e,t,n){F.command(e>=0,"missing vertex shader",n),F.command(t>=0,"missing fragment shader",n);var a=s[t];a||(a=s[t]={});var i=a[e];return i||(i=new d(t,e),r.shaderCount++,m(i,n),a[e]=i,c.push(i)),i},restore:function(){a={},i={};for(var e=0;e<c.length;++e)m(c[e])},shader:u,frag:-1,vert:-1}}(a,c,l,n),_=dr(a,d,g,function(){E.procs.poll()},v,l,n),A=vr(a,d,g,l,n),S=function(e,r,n,a,i,o){var f={cur:null,next:null,dirty:!1,setFBO:null},u=["rgba"],s=["rgba4","rgb565","rgb5 a1"];r.ext_srgb&&s.push("srgba"),r.ext_color_buffer_half_float&&s.push("rgba16f","rgb16f"),r.webgl_color_buffer_float&&s.push("rgba32f");var c=["uint8"];function l(e,t,r){this.target=e,this.texture=t,this.renderbuffer=r;var n=0,a=0;t?(n=t.width,a=t.height):r&&(n=r.width,a=r.height),this.width=n,this.height=a}function d(e){e&&(e.texture&&e.texture._texture.decRef(),e.renderbuffer&&e.renderbuffer._renderbuffer.decRef())}function m(e,t,r){if(e)if(e.texture){var n=e.texture._texture,a=Math.max(1,n.width),i=Math.max(1,n.height);F(a===t&&i===r,"inconsistent width/height for supplied texture"),n.refCount+=1}else{var o=e.renderbuffer._renderbuffer;F(o.width===t&&o.height===r,"inconsistent width/height for renderbuffer"),o.refCount+=1}}function p(t,r){r&&(r.texture?e.framebufferTexture2D(gr,t,r.target,r.texture._texture.texture,0):e.framebufferRenderbuffer(gr,t,yr,r.renderbuffer._renderbuffer.renderbuffer))}function h(e){var t=xr,r=null,n=null,a=e;"object"==typeof e&&(a=e.data,"target"in e&&(t=0|e.target)),F.type(a,"function","invalid attachment data");var i=a._reglType;return"texture2d"===i?(r=a,F(t===xr)):"textureCube"===i?(r=a,F(t>=wr&&t<wr+6,"invalid cube map target")):"renderbuffer"===i?(n=a,t=yr):F.raise("invalid regl object for attachment"),new l(t,r,n)}function b(e,t,r,n,o){if(r){var f=a.create2D({width:e,height:t,format:n,type:o});return f._texture.refCount=0,new l(xr,f,null)}var u=i.create({width:e,height:t,format:n});return u._renderbuffer.refCount=0,new l(yr,null,u)}function v(e){return e&&(e.texture||e.renderbuffer)}function g(e,t,r){e&&(e.texture?e.texture.resize(t,r):e.renderbuffer&&e.renderbuffer.resize(t,r),e.width=t,e.height=r)}r.oes_texture_half_float&&c.push("half float","float16"),r.oes_texture_float&&c.push("float","float32");var y=0,x={};function w(){this.id=y++,x[this.id]=this,this.framebuffer=e.createFramebuffer(),this.width=0,this.height=0,this.colorAttachments=[],this.depthAttachment=null,this.stencilAttachment=null,this.depthStencilAttachment=null}function k(e){e.colorAttachments.forEach(d),d(e.depthAttachment),d(e.stencilAttachment),d(e.depthStencilAttachment)}function _(t){var r=t.framebuffer;F(r,"must not double destroy framebuffer"),e.deleteFramebuffer(r),t.framebuffer=null,o.framebufferCount--,delete x[t.id]}function A(t){var r;e.bindFramebuffer(gr,t.framebuffer);var a=t.colorAttachments;for(r=0;r<a.length;++r)p(kr+r,a[r]);for(r=a.length;r<n.maxColorAttachments;++r)e.framebufferTexture2D(gr,kr+r,xr,null,0);e.framebufferTexture2D(gr,Sr,xr,null,0),e.framebufferTexture2D(gr,_r,xr,null,0),e.framebufferTexture2D(gr,Ar,xr,null,0),p(_r,t.depthAttachment),p(Ar,t.stencilAttachment),p(Sr,t.depthStencilAttachment);var i=e.checkFramebufferStatus(gr);e.isContextLost()||i===Er||F.raise("framebuffer configuration not supported, status = "+Mr[i]),e.bindFramebuffer(gr,f.next?f.next.framebuffer:null),f.cur=f.next,e.getError()}function S(e,a){var i=new w;function l(e,t){var a;F(f.next!==i,"can not update framebuffer which is currently in use");var o=0,d=0,p=!0,g=!0,y=null,x=!0,w="rgba",_="uint8",S=1,E=null,T=null,j=null,D=!1;if("number"==typeof e)o=0|e,d=0|t||o;else if(e){F.type(e,"object","invalid arguments for framebuffer");var O=e;if("shape"in O){var C=O.shape;F(Array.isArray(C)&&C.length>=2,"invalid shape for framebuffer"),o=C[0],d=C[1]}else"radius"in O&&(o=d=O.radius),"width"in O&&(o=O.width),"height"in O&&(d=O.height);("color"in O||"colors"in O)&&(y=O.color||O.colors,Array.isArray(y)&&F(1===y.length||r.webgl_draw_buffers,"multiple render targets not supported")),y||("colorCount"in O&&(S=0|O.colorCount,F(S>0,"invalid color buffer count")),"colorTexture"in O&&(x=!!O.colorTexture,w="rgba4"),"colorType"in O&&(_=O.colorType,x?(F(r.oes_texture_float||!("float"===_||"float32"===_),"you must enable OES_texture_float in order to use floating point framebuffer objects"),F(r.oes_texture_half_float||!("half float"===_||"float16"===_),"you must enable OES_texture_half_float in order to use 16-bit floating point framebuffer objects")):"half float"===_||"float16"===_?(F(r.ext_color_buffer_half_float,"you must enable EXT_color_buffer_half_float to use 16-bit render buffers"),w="rgba16f"):"float"!==_&&"float32"!==_||(F(r.webgl_color_buffer_float,"you must enable WEBGL_color_buffer_float in order to use 32-bit floating point renderbuffers"),w="rgba32f"),F.oneOf(_,c,"invalid color type")),"colorFormat"in O&&(w=O.colorFormat,u.indexOf(w)>=0?x=!0:s.indexOf(w)>=0?x=!1:x?F.oneOf(O.colorFormat,u,"invalid color format for texture"):F.oneOf(O.colorFormat,s,"invalid color format for renderbuffer"))),("depthTexture"in O||"depthStencilTexture"in O)&&(D=!(!O.depthTexture&&!O.depthStencilTexture),F(!D||r.webgl_depth_texture,"webgl_depth_texture extension not supported")),"depth"in O&&("boolean"==typeof O.depth?p=O.depth:(E=O.depth,g=!1)),"stencil"in O&&("boolean"==typeof O.stencil?g=O.stencil:(T=O.stencil,p=!1)),"depthStencil"in O&&("boolean"==typeof O.depthStencil?p=g=O.depthStencil:(j=O.depthStencil,p=!1,g=!1))}else o=d=1;var z=null,L=null,M=null,P=null;if(Array.isArray(y))z=y.map(h);else if(y)z=[h(y)];else for(z=new Array(S),a=0;a<S;++a)z[a]=b(o,d,x,w,_);F(r.webgl_draw_buffers||z.length<=1,"you must enable the WEBGL_draw_buffers extension in order to use multiple color buffers."),F(z.length<=n.maxColorAttachments,"too many color attachments, not supported"),o=o||z[0].width,d=d||z[0].height,E?L=h(E):p&&!g&&(L=b(o,d,D,"depth","uint32")),T?M=h(T):g&&!p&&(M=b(o,d,!1,"stencil","uint8")),j?P=h(j):!E&&!T&&g&&p&&(P=b(o,d,D,"depth stencil","depth stencil")),F(!!E+!!T+!!j<=1,"invalid framebuffer configuration, can specify exactly one depth/stencil attachment");var B=null;for(a=0;a<z.length;++a)if(m(z[a],o,d),F(!z[a]||z[a].texture&&jr.indexOf(z[a].texture._texture.format)>=0||z[a].renderbuffer&&Lr.indexOf(z[a].renderbuffer._renderbuffer.format)>=0,"framebuffer color attachment "+a+" is invalid"),z[a]&&z[a].texture){var I=Dr[z[a].texture._texture.format]*Or[z[a].texture._texture.type];null===B?B=I:F(B===I,"all color attachments much have the same number of bits per pixel.")}return m(L,o,d),F(!L||L.texture&&L.texture._texture.format===Tr||L.renderbuffer&&L.renderbuffer._renderbuffer.format===Cr,"invalid depth attachment for framebuffer object"),m(M,o,d),F(!M||M.renderbuffer&&M.renderbuffer._renderbuffer.format===Fr,"invalid stencil attachment for framebuffer object"),m(P,o,d),F(!P||P.texture&&P.texture._texture.format===zr||P.renderbuffer&&P.renderbuffer._renderbuffer.format===zr,"invalid depth-stencil attachment for framebuffer object"),k(i),i.width=o,i.height=d,i.colorAttachments=z,i.depthAttachment=L,i.stencilAttachment=M,i.depthStencilAttachment=P,l.color=z.map(v),l.depth=v(L),l.stencil=v(M),l.depthStencil=v(P),l.width=i.width,l.height=i.height,A(i),l}return o.framebufferCount++,l(e,a),t(l,{resize:function(e,t){F(f.next!==i,"can not resize a framebuffer which is currently in use");var r=Math.max(0|e,1),n=Math.max(0|t||r,1);if(r===i.width&&n===i.height)return l;for(var a=i.colorAttachments,o=0;o<a.length;++o)g(a[o],r,n);return g(i.depthAttachment,r,n),g(i.stencilAttachment,r,n),g(i.depthStencilAttachment,r,n),i.width=l.width=r,i.height=l.height=n,A(i),l},_reglType:"framebuffer",_framebuffer:i,destroy:function(){_(i),k(i)},use:function(e){f.setFBO({framebuffer:l},e)}})}return t(f,{getFramebuffer:function(e){if("function"==typeof e&&"framebuffer"===e._reglType){var t=e._framebuffer;if(t instanceof w)return t}return null},create:S,createCube:function(e){var i=Array(6);function o(e){var n;F(i.indexOf(f.next)<0,"can not update framebuffer which is currently in use");var s,l={color:null},d=0,m=null,p="rgba",h="uint8",b=1;if("number"==typeof e)d=0|e;else if(e){F.type(e,"object","invalid arguments for framebuffer");var v=e;if("shape"in v){var g=v.shape;F(Array.isArray(g)&&g.length>=2,"invalid shape for framebuffer"),F(g[0]===g[1],"cube framebuffer must be square"),d=g[0]}else"radius"in v&&(d=0|v.radius),"width"in v?(d=0|v.width,"height"in v&&F(v.height===d,"must be square")):"height"in v&&(d=0|v.height);("color"in v||"colors"in v)&&(m=v.color||v.colors,Array.isArray(m)&&F(1===m.length||r.webgl_draw_buffers,"multiple render targets not supported")),m||("colorCount"in v&&(b=0|v.colorCount,F(b>0,"invalid color buffer count")),"colorType"in v&&(F.oneOf(v.colorType,c,"invalid color type"),h=v.colorType),"colorFormat"in v&&(p=v.colorFormat,F.oneOf(v.colorFormat,u,"invalid color format for texture"))),"depth"in v&&(l.depth=v.depth),"stencil"in v&&(l.stencil=v.stencil),"depthStencil"in v&&(l.depthStencil=v.depthStencil)}else d=1;if(m)if(Array.isArray(m))for(s=[],n=0;n<m.length;++n)s[n]=m[n];else s=[m];else{s=Array(b);var y={radius:d,format:p,type:h};for(n=0;n<b;++n)s[n]=a.createCube(y)}for(l.color=Array(s.length),n=0;n<s.length;++n){var x=s[n];F("function"==typeof x&&"textureCube"===x._reglType,"invalid cube map"),d=d||x.width,F(x.width===d&&x.height===d,"invalid cube map shape"),l.color[n]={target:wr,data:s[n]}}for(n=0;n<6;++n){for(var w=0;w<s.length;++w)l.color[w].target=wr+n;n>0&&(l.depth=i[0].depth,l.stencil=i[0].stencil,l.depthStencil=i[0].depthStencil),i[n]?i[n](l):i[n]=S(l)}return t(o,{width:d,height:d,color:s})}return o(e),t(o,{faces:i,resize:function(e){var t,r=0|e;if(F(r>0&&r<=n.maxCubeMapSize,"invalid radius for cube fbo"),r===o.width)return o;var a=o.color;for(t=0;t<a.length;++t)a[t].resize(r);for(t=0;t<6;++t)i[t].resize(r);return o.width=o.height=r,o},_reglType:"framebufferCube",destroy:function(){i.forEach(function(e){e.destroy()})}})},clear:function(){ne(x).forEach(_)},restore:function(){f.cur=null,f.next=null,f.dirty=!0,ne(x).forEach(function(t){t.framebuffer=e.createFramebuffer(),A(t)})}})}(a,d,g,_,A,l),E=Ja(a,c,d,g,x,w,0,S,{},y,k,{elements:null,primitive:4,count:-1,offset:0,instances:-1},v,m,n),T=Qr(a,S,E.procs.poll,v,i,d,g),j=E.next,D=a.canvas,O=[],C=[],z=[],L=[n.onDestroy],M=null;function P(){if(0===O.length)return m&&m.update(),void(M=null);M=R.next(P),X();for(var e=O.length-1;e>=0;--e){var t=O[e];t&&t(v,null,0)}a.flush(),m&&m.update()}function B(){!M&&O.length>0&&(M=R.next(P))}function H(){M&&(R.cancel(P),M=null)}function U(e){e.preventDefault(),o=!0,H(),C.forEach(function(e){e()})}function q(e){a.getError(),o=!1,f.restore(),k.restore(),x.restore(),_.restore(),A.restore(),S.restore(),m&&m.restore(),E.procs.refresh(),B(),z.forEach(function(e){e()})}function G(e){function r(e){var t={},r={};return Object.keys(e).forEach(function(n){var a=e[n];I.isDynamic(a)?r[n]=I.unbox(a,n):t[n]=a}),{dynamic:r,static:t}}F(!!e,"invalid args to regl({...})"),F.type(e,"object","invalid args to regl({...})");var n=r(e.context||{}),a=r(e.uniforms||{}),i=r(e.attributes||{}),f=r(function(e){var r=t({},e);function n(e){if(e in r){var t=r[e];delete r[e],Object.keys(t).forEach(function(n){r[e+"."+n]=t[n]})}}return delete r.uniforms,delete r.attributes,delete r.context,"stencil"in r&&r.stencil.op&&(r.stencil.opBack=r.stencil.opFront=r.stencil.op,delete r.stencil.op),n("blend"),n("depth"),n("cull"),n("stencil"),n("polygonOffset"),n("scissor"),n("sample"),r}(e)),u={gpuTime:0,cpuTime:0,count:0},s=E.compile(f,i,a,n,u),c=s.draw,l=s.batch,d=s.scope,m=[];return t(function(e,t){var r;if(o&&F.raise("context lost"),"function"==typeof e)return d.call(this,null,e,0);if("function"==typeof t){if("number"==typeof e){for(r=0;r<e;++r)d.call(this,null,t,r);return}if(Array.isArray(e)){for(r=0;r<e.length;++r)d.call(this,e[r],t,r);return}return d.call(this,e,t,0)}if("number"==typeof e){if(e>0)return l.call(this,function(e){for(;m.length<e;)m.push(null);return m}(0|e),0|e)}else{if(!Array.isArray(e))return c.call(this,e);if(e.length)return l.call(this,e,e.length)}},{stats:u})}D&&(D.addEventListener(fi,U,!1),D.addEventListener(ui,q,!1));var Q=S.setFBO=G({framebuffer:I.define.call(null,si,"framebuffer")});function V(e,t){var r=0;E.procs.poll();var n=t.color;n&&(a.clearColor(+n[0]||0,+n[1]||0,+n[2]||0,+n[3]||0),r|=ni),"depth"in t&&(a.clearDepth(+t.depth),r|=ai),"stencil"in t&&(a.clearStencil(0|t.stencil),r|=ii),F(!!r,"called regl.clear with no buffer specified"),a.clear(r)}function Y(e){return F.type(e,"function","regl.frame() callback must be a function"),O.push(e),B(),{cancel:function(){var t=di(O,e);F(t>=0,"cannot cancel a frame twice"),O[t]=function e(){var t=di(O,e);O[t]=O[O.length-1],O.length-=1,O.length<=0&&H()}}}}function K(){var e=j.viewport,t=j.scissor_box;e[0]=e[1]=t[0]=t[1]=0,v.viewportWidth=v.framebufferWidth=v.drawingBufferWidth=e[2]=t[2]=a.drawingBufferWidth,v.viewportHeight=v.framebufferHeight=v.drawingBufferHeight=e[3]=t[3]=a.drawingBufferHeight}function X(){v.tick+=1,v.time=J(),K(),E.procs.poll()}function $(){K(),E.procs.refresh(),m&&m.update()}function J(){return(W()-p)/1e3}$();var Z=t(G,{clear:function(e){if(F("object"==typeof e&&e,"regl.clear() takes an object as input"),"framebuffer"in e)if(e.framebuffer&&"framebufferCube"===e.framebuffer_reglType)for(var r=0;r<6;++r)Q(t({framebuffer:e.framebuffer.faces[r]},e),V);else Q(e,V);else V(null,e)},prop:I.define.bind(null,si),context:I.define.bind(null,ci),this:I.define.bind(null,li),draw:G({}),buffer:function(e){return x.create(e,oi,!1,!1)},elements:function(e){return w.create(e,!1)},texture:_.create2D,cube:_.createCube,renderbuffer:A.create,framebuffer:S.create,framebufferCube:S.createCube,attributes:i,frame:Y,on:function(e,t){var r;switch(F.type(t,"function","listener callback must be a function"),e){case"frame":return Y(t);case"lost":r=C;break;case"restore":r=z;break;case"destroy":r=L;break;default:F.raise("invalid event, must be one of frame,lost,restore,destroy")}return r.push(t),{cancel:function(){for(var e=0;e<r.length;++e)if(r[e]===t)return r[e]=r[r.length-1],void r.pop()}}},limits:g,hasExtension:function(e){return g.extensions.indexOf(e.toLowerCase())>=0},read:T,destroy:function(){O.length=0,H(),D&&(D.removeEventListener(fi,U),D.removeEventListener(ui,q)),k.clear(),S.clear(),A.clear(),_.clear(),w.clear(),x.clear(),m&&m.clear(),L.forEach(function(e){e()})},_gl:a,_refresh:$,poll:function(){X(),m&&m.update()},now:J,stats:l});return n.onDone(null,Z),Z}}()},function(e,t,r){var n=r(19),a=r(21),i=r(1),o=r(24),f=r(25);e.exports=function(e,t){var r=t||{};void 0===r.noScroll&&(r.noScroll=r.preventDefault);var s={view:i(new Float32Array(16)),projection:i(new Float32Array(16)),center:new Float32Array(r.center||3),theta:r.theta||0,phi:r.phi||0,distance:Math.log(r.distance||10),eye:new Float32Array(3),up:new Float32Array(r.up||[0,1,0]),fovy:r.fovy||Math.PI/4,near:void 0!==r.near?r.near:.01,far:void 0!==r.far?r.far:1e3,noScroll:void 0!==r.noScroll&&r.noScroll,flipY:!!r.flipY,dtheta:0,dphi:0,rotationSpeed:void 0!==r.rotationSpeed?r.rotationSpeed:1,zoomSpeed:void 0!==r.zoomSpeed?r.zoomSpeed:1,renderOnDirty:void 0!==typeof r.renderOnDirty&&!!r.renderOnDirty},c=r.element,l=void 0!==r.damping?r.damping:.9,d=new Float32Array([1,0,0]),m=new Float32Array([0,0,1]),p=Math.log("minDistance"in r?r.minDistance:.1),h=Math.log("maxDistance"in r?r.maxDistance:1e3),b=0,v=0,g=0;if(u&&!1!==r.mouse){var y=c||e._gl.canvas;function x(){return c?c.offsetHeight:window.innerHeight}n(y,function(e,t,r){if(1&e){var n=(t-v)/(c?c.offsetWidth:window.innerWidth),a=(r-g)/x();s.dtheta+=4*s.rotationSpeed*n,s.dphi+=4*s.rotationSpeed*a,s.dirty=!0}v=t,g=r}),a(y,function(e,t){b+=t/x()*s.zoomSpeed,s.dirty=!0},r.noScroll)}function w(e){var t=e*l;return Math.abs(t)<.1?0:(s.dirty=!0,t)}function k(e,t,r){return Math.min(Math.max(e,t),r)}s.dirty=!0;var _=e({context:Object.assign({},s,{dirty:function(){return s.dirty},projection:function(e){return o(s.projection,s.fovy,e.viewportWidth/e.viewportHeight,s.near,s.far),s.flipY&&(s.projection[5]*=-1),s.projection}}),uniforms:Object.keys(s).reduce(function(t,r){return t[r]=e.context(r),t},{})});function A(e,t){void 0!==A.dirty&&(s.dirty=A.dirty||s.dirty,A.dirty=void 0),e&&t&&(s.dirty=!0),s.renderOnDirty&&!s.dirty||(t||(t=e,e={}),function(e){Object.keys(e).forEach(function(t){s[t]=e[t]});var t=s.center,r=s.eye,n=s.up,a=s.dtheta,i=s.dphi;s.theta+=a,s.phi=k(s.phi+i,-Math.PI/2,Math.PI/2),s.distance=k(s.distance+b,p,h),s.dtheta=w(a),s.dphi=w(i),b=w(b);for(var o=s.theta,u=s.phi,c=Math.exp(s.distance),l=c*Math.sin(o)*Math.cos(u),v=c*Math.cos(o)*Math.cos(u),g=c*Math.sin(u),y=0;y<3;++y)r[y]=t[y]+l*m[y]+v*d[y]+g*n[y];f(s.view,r,t,n)}(e),_(t),s.dirty=!1)}return Object.keys(s).forEach(function(e){A[e]=s[e]}),A};var u="undefined"!=typeof window},function(e,t,r){"use strict";e.exports=function(e,t){t||(t=e,e=window);var r=0,a=0,i=0,o={shift:!1,alt:!1,control:!1,meta:!1},f=!1;function u(e){var t=!1;return"altKey"in e&&(t=t||e.altKey!==o.alt,o.alt=!!e.altKey),"shiftKey"in e&&(t=t||e.shiftKey!==o.shift,o.shift=!!e.shiftKey),"ctrlKey"in e&&(t=t||e.ctrlKey!==o.control,o.control=!!e.ctrlKey),"metaKey"in e&&(t=t||e.metaKey!==o.meta,o.meta=!!e.metaKey),t}function s(e,f){var s=n.x(f),c=n.y(f);"buttons"in f&&(e=0|f.buttons),(e!==r||s!==a||c!==i||u(f))&&(r=0|e,a=s||0,i=c||0,t&&t(r,a,i,o))}function c(e){s(0,e)}function l(){(r||a||i||o.shift||o.alt||o.meta||o.control)&&(a=i=0,r=0,o.shift=o.alt=o.control=o.meta=!1,t&&t(0,0,0,o))}function d(e){u(e)&&t&&t(r,a,i,o)}function m(e){0===n.buttons(e)?s(0,e):s(r,e)}function p(e){s(r|n.buttons(e),e)}function h(e){s(r&~n.buttons(e),e)}function b(){f||(f=!0,e.addEventListener("mousemove",m),e.addEventListener("mousedown",p),e.addEventListener("mouseup",h),e.addEventListener("mouseleave",c),e.addEventListener("mouseenter",c),e.addEventListener("mouseout",c),e.addEventListener("mouseover",c),e.addEventListener("blur",l),e.addEventListener("keyup",d),e.addEventListener("keydown",d),e.addEventListener("keypress",d),e!==window&&(window.addEventListener("blur",l),window.addEventListener("keyup",d),window.addEventListener("keydown",d),window.addEventListener("keypress",d)))}b();var v={element:e};return Object.defineProperties(v,{enabled:{get:function(){return f},set:function(t){t?b():f&&(f=!1,e.removeEventListener("mousemove",m),e.removeEventListener("mousedown",p),e.removeEventListener("mouseup",h),e.removeEventListener("mouseleave",c),e.removeEventListener("mouseenter",c),e.removeEventListener("mouseout",c),e.removeEventListener("mouseover",c),e.removeEventListener("blur",l),e.removeEventListener("keyup",d),e.removeEventListener("keydown",d),e.removeEventListener("keypress",d),e!==window&&(window.removeEventListener("blur",l),window.removeEventListener("keyup",d),window.removeEventListener("keydown",d),window.removeEventListener("keypress",d)))},enumerable:!0},buttons:{get:function(){return r},enumerable:!0},x:{get:function(){return a},enumerable:!0},y:{get:function(){return i},enumerable:!0},mods:{get:function(){return o},enumerable:!0}}),v};var n=r(20)},function(e,t,r){"use strict";function n(e){return e.target||e.srcElement||window}t.buttons=function(e){if("object"==typeof e){if("buttons"in e)return e.buttons;if("which"in e){if(2===(t=e.which))return 4;if(3===t)return 2;if(t>0)return 1<<t-1}else if("button"in e){var t;if(1===(t=e.button))return 4;if(2===t)return 2;if(t>=0)return 1<<t}}return 0},t.element=n,t.x=function(e){if("object"==typeof e){if("offsetX"in e)return e.offsetX;var t=n(e).getBoundingClientRect();return e.clientX-t.left}return 0},t.y=function(e){if("object"==typeof e){if("offsetY"in e)return e.offsetY;var t=n(e).getBoundingClientRect();return e.clientY-t.top}return 0}},function(e,t,r){"use strict";var n=r(22);e.exports=function(e,t,r){"function"==typeof e&&(r=!!t,t=e,e=window);var a=n("ex",e),i=function(e){r&&e.preventDefault();var n=e.deltaX||0,i=e.deltaY||0,o=e.deltaZ||0,f=e.deltaMode,u=1;switch(f){case 1:u=a;break;case 2:u=window.innerHeight}if(i*=u,o*=u,(n*=u)||i||o)return t(n,i,o,e)};return e.addEventListener("wheel",i),i}},function(e,t,r){"use strict";var n=r(23);e.exports=f;var a=o("in",document.body);function i(e,t){var r=n(getComputedStyle(e).getPropertyValue(t));return r[0]*f(r[1],e)}function o(e,t){var r=document.createElement("div");r.style.height="128"+e,t.appendChild(r);var n=i(r,"height")/128;return t.removeChild(r),n}function f(e,t){if(!e)return null;switch(t=t||document.body,e=(e+""||"px").trim().toLowerCase(),t!==window&&t!==document||(t=document.body),e){case"%":return t.clientHeight/100;case"ch":case"ex":return o(e,t);case"em":return i(t,"font-size");case"rem":return i(document.body,"font-size");case"vw":return window.innerWidth/100;case"vh":return window.innerHeight/100;case"vmin":return Math.min(window.innerWidth,window.innerHeight)/100;case"vmax":return Math.max(window.innerWidth,window.innerHeight)/100;case"in":return a;case"cm":return a/2.54;case"mm":return a/25.4;case"pt":return a/72;case"pc":return a/6;case"px":return 1}var r=n(e);if(!isNaN(r[0])&&r[1]){var u=f(r[1],t);return"number"==typeof u?r[0]*u:null}return null}},function(e,t){e.exports=function(e,t){t||(t=[0,""]),e=String(e);var r=parseFloat(e,10);return t[0]=r,t[1]=e.match(/[\d.\-\+]*\s*(.*)/)[1]||"",t}},function(e,t){e.exports=function(e,t,r,n,a){var i=1/Math.tan(t/2),o=1/(n-a);return e[0]=i/r,e[1]=0,e[2]=0,e[3]=0,e[4]=0,e[5]=i,e[6]=0,e[7]=0,e[8]=0,e[9]=0,e[10]=(a+n)*o,e[11]=-1,e[12]=0,e[13]=0,e[14]=2*a*n*o,e[15]=0,e}},function(e,t,r){var n=r(1);e.exports=function(e,t,r,a){var i,o,f,u,s,c,l,d,m,p,h=t[0],b=t[1],v=t[2],g=a[0],y=a[1],x=a[2],w=r[0],k=r[1],_=r[2];if(Math.abs(h-w)<1e-6&&Math.abs(b-k)<1e-6&&Math.abs(v-_)<1e-6)return n(e);l=h-w,d=b-k,m=v-_,p=1/Math.sqrt(l*l+d*d+m*m),i=y*(m*=p)-x*(d*=p),o=x*(l*=p)-g*m,f=g*d-y*l,(p=Math.sqrt(i*i+o*o+f*f))?(i*=p=1/p,o*=p,f*=p):(i=0,o=0,f=0);u=d*f-m*o,s=m*i-l*f,c=l*o-d*i,(p=Math.sqrt(u*u+s*s+c*c))?(u*=p=1/p,s*=p,c*=p):(u=0,s=0,c=0);return e[0]=i,e[1]=u,e[2]=l,e[3]=0,e[4]=o,e[5]=s,e[6]=d,e[7]=0,e[8]=f,e[9]=c,e[10]=m,e[11]=0,e[12]=-(i*h+o*b+f*v),e[13]=-(u*h+s*b+c*v),e[14]=-(l*h+d*b+m*v),e[15]=1,e}}]);
//# sourceMappingURL=main.js.map