text: /**
   * @license glsl-canvas-js v0.2.9
   * (c) 2022 Luca Zampetti <lzampetti@gmail.com>
   * License: MIT
   */
  !function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).glsl={})}(this,(function(t){"use strict";function e(t,e){for(var r=0;r<e.length;r++){var i=e[r];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function r(t,e){t.prototype=Object.create(e.prototype),t.prototype.constructor=t,i(t,e)}function i(t,e){return(i=Object.setPrototypeOf||function(t,e){return t.__proto__=e,t})(t,e)}function n(t){if(void 0===t)throw new ReferenceError("this hasn't been initialised - super() hasn't been called");return t}var o="\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nattribute vec4 a_position;\nattribute vec4 a_normal;\nattribute vec2 a_texcoord;\nattribute vec4 a_color;\n\nvarying vec4 v_position;\nvarying vec4 v_normal;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\n",s="\n#ifdef GL_ES\nprecision mediump float;\n#endif\n\nvarying vec4 v_position;\nvarying vec4 v_normal;\nvarying vec2 v_texcoord;\nvarying vec4 v_color;\n",a="#version 300 es\n\nprecision mediump float;\n\nin vec4 a_position;\nin vec4 a_normal;\nin vec2 a_texcoord;\nin vec4 a_color;\n\nout vec4 v_position;\nout vec4 v_normal;\nout vec2 v_texcoord;\nout vec4 v_color;\n",u="#version 300 es\n\nprecision mediump float;\n\nin vec4 v_position;\nin vec4 v_normal;\nin vec2 v_texcoord;\nin vec4 v_color;\n\nout vec4 outColor;\n",h="\nuniform mat4 u_projectionMatrix;\nuniform mat4 u_modelViewMatrix;\nuniform mat4 u_normalMatrix;\n\nuniform vec2 u_resolution;\nuniform float u_time;\n",f="\nvoid main() {\n\tv_position = a_position;\n\tv_normal = a_normal;\n\tv_texcoord = a_texcoord;\n\tv_color = a_color;\n\tgl_Position = a_position;\n}\n",c="\nvoid main(void) {\n\tv_position = u_projectionMatrix * u_modelViewMatrix * a_position;\n\tv_normal = u_normalMatrix * a_normal;\n\tv_texcoord = a_texcoord;\n\tv_color = a_color;\n\tgl_Position = v_position;\n}\n",l=o+h+c,d=a+h+c,m=s+h+"\nvoid main() {\n\tvec2 st = gl_FragCoord.xy / u_resolution.xy;\n\tst.x *= u_resolution.x / u_resolution.y;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * st.y,\n\t\tabs(cos(u_time * 0.2)) * st.y,\n\t\tabs(sin(u_time)) * st.y\n\t);\n\tgl_FragColor = vec4(color, 1.0);\n}\n",v=u+h+"\nvoid main() {\n\tvec2 st = gl_FragCoord.xy / u_resolution.xy;\n\tst.x *= u_resolution.x / u_resolution.y;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * st.y,\n\t\tabs(cos(u_time * 0.2)) * st.y,\n\t\tabs(sin(u_time)) * st.y\n\t);\n\toutColor = vec4(color, 1.0);\n}\n",p=s+h+"\nvoid main() {\n\tvec2 uv = v_texcoord;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * uv.y,\n\t\tabs(cos(u_time * 0.2)) * uv.y,\n\t\tabs(sin(u_time)) * uv.y\n\t);\n\tfloat incidence = max(dot(v_normal.xyz, vec3(0.0, 1.0, 0.0)), 0.0);\n\tvec3 light = vec3(0.2) + (vec3(1.0) * incidence);\n\tgl_FragColor = vec4(v_color.rgb * color * light, 1.0);\n}\n",g=u+h+"\nvoid main() {\n\tvec2 uv = v_texcoord;\n\tvec3 color = vec3(\n\t\tabs(cos(u_time * 0.1)) * uv.y,\n\t\tabs(cos(u_time * 0.2)) * uv.y,\n\t\tabs(sin(u_time)) * uv.y\n\t);\n\tfloat incidence = max(dot(v_normal.xyz, vec3(0.0, 1.0, 0.0)), 0.0);\n\tvec3 light = vec3(0.2) + (vec3(1.0) * incidence);\n\toutColor = vec4(v_color.rgb * color * light, 1.0);\n}\n",_=o+h+f,y=a+h+f,x=s+h+"\nvoid main(){\n\tgl_FragColor = vec4(0.0, 0.0, 0.0, 1.0);\n}",T=u+h+"\nvoid main() {\n\toutColor = vec4(0.0, 0.0, 0.0, 1.0);\n}\n";var E=setTimeout;function U(t){return Boolean(t&&void 0!==t.length)}function M(){}function b(t){if(!(this instanceof b))throw new TypeError("Promises must be constructed via new");if("function"!=typeof t)throw new TypeError("not a function");this._state=0,this._handled=!1,this._value=void 0,this._deferreds=[],S(t,this)}function A(t,e){for(;3===t._state;)t=t._value;0!==t._state?(t._handled=!0,b._immediateFn((function(){var r=1===t._state?e.onFulfilled:e.onRejected;if(null!==r){var i;try{i=r(t._value)}catch(t){return void F(e.promise,t)}w(e.promise,i)}else(1===t._state?w:F)(e.promise,t._value)}))):t._deferreds.push(e)}function w(t,e){try{if(e===t)throw new TypeError("A promise cannot be resolved with itself.");if(e&&("object"==typeof e||"function"==typeof e)){var r=e.then;if(e instanceof b)return t._state=3,t._value=e,void L(t);if("function"==typeof r)return void S((i=r,n=e,function(){i.apply(n,arguments)}),t)}t._state=1,t._value=e,L(t)}catch(e){F(t,e)}var i,n}function F(t,e){t._state=2,t._value=e,L(t)}function L(t){2===t._state&&0===t._deferreds.length&&b._immediateFn((function(){t._handled||b._unhandledRejectionFn(t._value)}));for(var e=0,r=t._deferreds.length;e<r;e++)A(t,t._deferreds[e]);t._deferreds=null}function R(t,e,r){this.onFulfilled="function"==typeof t?t:null,this.onRejected="function"==typeof e?e:null,this.promise=r}function S(t,e){var r=!1;try{t((function(t){r||(r=!0,w(e,t))}),(function(t){r||(r=!0,F(e,t))}))}catch(t){if(r)return;r=!0,F(e,t)}}b.prototype.catch=function(t){return this.then(null,t)},b.prototype.then=function(t,e){var r=new this.constructor(M);return A(this,new R(t,e,r)),r},b.prototype.finally=function(t){var e=this.constructor;return this.then((function(r){return e.resolve(t()).then((function(){return r}))}),(function(r){return e.resolve(t()).then((function(){return e.reject(r)}))}))},b.all=function(t){return new b((function(e,r){if(!U(t))return r(new TypeError("Promise.all accepts an array"));var i=Array.prototype.slice.call(t);if(0===i.length)return e([]);var n=i.length;function o(t,s){try{if(s&&("object"==typeof s||"function"==typeof s)){var a=s.then;if("function"==typeof a)return void a.call(s,(function(e){o(t,e)}),r)}i[t]=s,0==--n&&e(i)}catch(t){r(t)}}for(var s=0;s<i.length;s++)o(s,i[s])}))},b.allSettled=function(t){return new this((function(e,r){if(!t||void 0===t.length)return r(new TypeError(typeof t+" "+t+" is not iterable(cannot read property Symbol(Symbol.iterator))"));var i=Array.prototype.slice.call(t);if(0===i.length)return e([]);var n=i.length;function o(t,r){if(r&&("object"==typeof r||"function"==typeof r)){var s=r.then;if("function"==typeof s)return void s.call(r,(function(e){o(t,e)}),(function(r){i[t]={status:"rejected",reason:r},0==--n&&e(i)}))}i[t]={status:"fulfilled",value:r},0==--n&&e(i)}for(var s=0;s<i.length;s++)o(s,i[s])}))},b.resolve=function(t){return t&&"object"==typeof t&&t.constructor===b?t:new b((function(e){e(t)}))},b.reject=function(t){return new b((function(e,r){r(t)}))},b.race=function(t){return new b((function(e,r){if(!U(t))return r(new TypeError("Promise.race accepts an array"));for(var i=0,n=t.length;i<n;i++)b.resolve(t[i]).then(e,r)}))},b._immediateFn="function"==typeof setImmediate&&function(t){setImmediate(t)}||function(t){E(t,0)},b._unhandledRejectionFn=function(t){"undefined"!=typeof console&&console&&console.warn("Possible Unhandled Promise Rejection:",t)};var P,O=function(){function t(){}return t.fetch=function(t){return new Promise((function(e,r){var i=new XMLHttpRequest;i.onload=function(){e(i.response||i.responseText)},i.onerror=function(e){console.log("Common.error",e),r(new Error("Network request failed for url "+t))},i.ontimeout=function(e){r(new Error("Network request failed for url "+t))},i.onabort=function(){r(new Error("Aborted"))},i.open("GET",t,!0),i.send(null)}))},t.getResource=function(e,r){return void 0===r&&(r=""),-1===e.indexOf(":/")?t.join(r,e):e},t.join=function(){for(var e=[],r=arguments.length,i=new Array(r),n=0;n<r;n++)i[n]=arguments[n];return i.forEach((function(r){0===r.indexOf("/")&&(e=[]),t.comps(r).forEach((function(t){switch(t){case".":break;case"..":e.pop();break;default:e.push(t)}}))})),e.join("/")},t.dirname=function(e){var r=t.comps(e);return r.pop(),r.join("/")},t.comps=function(t){return t.replace(/\/$/,"").split(/\/+/)},t}();!function(t){t[t.None=0]="None",t[t.Error=1]="Error",t[t.Warn=2]="Warn",t[t.Log=3]="Log"}(P||(P={}));var B,D,C,I=function(){function t(){}return t.log=function(){var e;t.enabled&&t.level>=P.Log&&(e=console).log.apply(e,arguments)},t.warn=function(){var e;t.enabled&&t.level>=P.Warn&&(e=console).warn.apply(e,arguments)},t.error=function(){var e;t.enabled&&t.level>=P.Error&&(e=console).error.apply(e,arguments)},t}();I.level=P.Warn,I.enabled=!0,(B=t.ContextVersion||(t.ContextVersion={})).WebGl="webgl",B.WebGl2="webgl2",function(t){t.LowP="lowp",t.MediumP="mediump",t.HighP="highp"}(D||(D={})),function(t){t.Flat="flat",t.Box="box",t.Sphere="sphere",t.Torus="torus",t.Mesh="mesh"}(C||(C={}));var G,k={webgl:{flat:{vertex:l,fragment:m},mesh:{vertex:l,fragment:p}},webgl2:{flat:{vertex:d,fragment:v},mesh:{vertex:d,fragment:g}}};(G=t.ContextError||(t.ContextError={}))[G.BrowserSupport=1]="BrowserSupport",G[G.Other=2]="Other";var W=function(){},V=function(){function e(){}return e.getContext_=function(t,e){for(var r=["webgl","experimental-webgl"],i=null,n=0;n<r.length;++n)try{i=t.getContext(r[n],e)}catch(t){if(i)break}return i},e.getContext2_=function(t,e){var r=null;try{r=t.getContext("webgl2",e)}catch(t){}return r},e.getFragmentVertex=function(r,i){var n;if(i){var o=e.inferVersion(i);o===t.ContextVersion.WebGl2&&(i=i.replace(/^\#version\s*300\s*es.*?\n/,""));null!==/(?:^\s*)((?:#if|#elif)(?:\s*)(defined\s*\(\s*VERTEX)(?:\s*\))|(?:#ifdef)(?:\s*VERTEX)(?:\s*))/gm.exec(i)&&(n=o===t.ContextVersion.WebGl2?"#version 300 es\n#define VERTEX\n"+i:"#define VERTEX\n"+i)}return n},e.getIncludes=function(t,r){if(void 0===r&&(r=""),void 0===t)return Promise.resolve(t);for(var i,n=/#include\s*['|"](.*.glsl)['|"]/gm,o=[],s=0,a=function(){o.push(Promise.resolve(t.slice(s,i.index))),s=i.index+i[0].length;var n=i[1],a=O.getResource(n,r),u=-1===n.indexOf(":/")?O.dirname(a):"";o.push(O.fetch(a).then((function(t){return e.getIncludes(t,u)})))};null!==(i=n.exec(t));)a();return o.push(Promise.resolve(t.slice(s))),Promise.all(o).then((function(t){return t.join("")}))},e.isWebGl=function(t){return t instanceof WebGLRenderingContext},e.isWebGl2=function(t){return window.WebGL2RenderingContext&&t instanceof WebGL2RenderingContext},e.inferVersion=function(e,r){var i=e||r;return i&&0===i.indexOf("#version 300 es")?t.ContextVersion.WebGl2:t.ContextVersion.WebGl},e.inferPrecision=function(t){var r=t.match(/precision\s+(.+)\s+float/);return r&&r.length>1&&(e.precision=r[1]),e.precision},e.versionDiffers=function(r,i,n){if(r){var o=this.isWebGl2(r)?t.ContextVersion.WebGl2:t.ContextVersion.WebGl;return e.inferVersion(i,n)!==o}return!1},e.getBufferVertex=function(t){return this.isWebGl2(t)?y:_},e.getVertex=function(t,e,r){if(void 0===r&&(r=C.Flat),t)return t;var i=this.inferVersion(t,e);return k[i][r===C.Flat?"flat":"mesh"].vertex},e.getFragment=function(t,e,r){if(void 0===r&&(r=C.Flat),e)return e;var i=this.inferVersion(t,e);return k[i][r===C.Flat?"flat":"mesh"].fragment},e.tryInferContext=function(r,i,n,o,s,a){function u(t,e){if("function"==typeof a)a(t);else{var r=n.parentNode;r&&(r.innerHTML='<div class="glsl-canvas--error">'+e+"</div>")}}if(void 0===s&&(s=[]),!WebGLRenderingContext)return u(t.ContextError.BrowserSupport,'This page requires a browser that supports WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org">Click here to upgrade your browser.</a>'),null;var h=e.inferContext(r,i,n,o);if(h){this.isWebGl2(h)||-1!==s.indexOf("OES_standard_derivatives")||s.push("OES_standard_derivatives");var f=h.getSupportedExtensions();s.forEach((function(t){-1!==f.indexOf(t)?h.getExtension(t):I.warn("GlslCanvas "+t+" not supported")}))}else u(t.ContextError.Other,'It does not appear your computer can support WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>');return h},e.tryGetContext=function(r,i,n){function o(t,e){if("function"==typeof n)n(t);else{var i=r.parentNode;i&&(i.innerHTML='<div class="glsl-canvas--error">'+e+"</div>")}}if(!WebGLRenderingContext)return o(t.ContextError.BrowserSupport,'This page requires a browser that supports WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org">Click here to upgrade your browser.</a>'),null;var s=e.getContext_(r,i);return s?s.getExtension("OES_standard_derivatives"):o(t.ContextError.Other,'It does not appear your computer can support WebGL.<br/>\n\t\t\t<a href="http://get.webgl.org/troubleshooting/">Click here for more information.</a>'),s},e.inferContext=function(e,r,i,n){return this.inferVersion(e,r)===t.ContextVersion.WebGl2?this.getContext2_(i,n):this.getContext_(i,n)},e.createShader=function(t,r,i,n){void 0===n&&(n=0);var o=t.createShader(i);if(r=r.replace(/precision\s+(.+)\s+float/,"precision "+e.precision+" float"),t.shaderSource(o,r),t.compileShader(o),!t.getShaderParameter(o,t.COMPILE_STATUS))throw e.lastError=t.getShaderInfoLog(o),I.error("*** Error compiling shader: "+e.lastError),t.deleteShader(o),{shader:o,source:r,type:i,error:e.lastError,offset:n};return o},e.createProgram=function(t,r,i,n){for(var o=t.createProgram(),s=0;s<r.length;++s)t.attachShader(o,r[s]);if(i&&n)for(var a=0;a<i.length;++a)t.bindAttribLocation(o,n?n[a]:a,i[a]);return t.linkProgram(o),t.validateProgram(o),t.getProgramParameter(o,t.LINK_STATUS)?(t.useProgram(o),o):(e.lastError=t.getProgramInfoLog(o),I.error("Error in program linking: "+e.lastError),t.deleteProgram(o),null)},e.createVertexBuffers=function(t,e){var r=new W,i=t.getAttribLocation(e,"a_texcoord");r.texcoord=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,r.texcoord),t.bufferData(t.ARRAY_BUFFER,new Float32Array([0,0,1,0,0,1,0,1,1,0,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(i),t.vertexAttribPointer(i,2,t.FLOAT,!1,0,0);var n=t.getAttribLocation(e,"a_position");return r.position=t.createBuffer(),t.bindBuffer(t.ARRAY_BUFFER,r.position),t.bufferData(t.ARRAY_BUFFER,new Float32Array([-1,-1,1,-1,-1,1,-1,1,1,-1,1,1]),t.STATIC_DRAW),t.enableVertexAttribArray(n),t.vertexAttribPointer(n,2,t.FLOAT,!1,0,0),r},e}();V.precision=D.MediumP,V.lastError="";var N,z=function(){},X=function(){function t(){this.values=new z}var e=t.prototype;return e.has=function(t){return t in this.values},e.set=function(t,e){this.values[t]=e},e.get=function(t){return this.values[t]},e.forEach=function(t){var e=this,r=0;Object.keys(this.values).forEach((function(i){t(e.values[i],r,e.values),r++}))},e.reduce=function(t,e){var r=this,i=e,n=0;return Object.keys(this.values).forEach((function(e){i=t(i,r.values[e],n,r.values),n++})),i},t}(),j=function(){function t(t){t&&(Object.assign(this,t),this.positions&&(this.size=this.positions.length/3))}var e=t.prototype;return e.create=function(t,e){this.createData_(),this.createAttributes_(t,e)},e.createBufferData_=function(t,e,r){var i=t.createBuffer();return t.bindBuffer(e,i),t.bufferData(e,r,t.STATIC_DRAW),i},e.createAttribLocation_=function(t,e,r,i,n){var o=t.getAttribLocation(e,r);return t.enableVertexAttribArray(o),t.vertexAttribPointer(o,i,n,!1,0,0),o},e.createAttributes_=function(t,e){this.positions&&(this.positionBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.positions)),this.positionLocation=this.createAttribLocation_(t,e,"a_position",this.positions.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.positionLocation,"a_position")),this.texcoords&&(this.texcoordBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.texcoords)),this.texcoordLocation=this.createAttribLocation_(t,e,"a_texcoord",this.texcoords.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.texcoordLocation,"a_texcoord")),this.normals&&(this.normalBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.normals)),this.normalLocation=this.createAttribLocation_(t,e,"a_normal",this.normals.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.normalLocation,"a_normal")),this.colors&&(this.colorBuffer=this.createBufferData_(t,t.ARRAY_BUFFER,new Float32Array(this.colors)),this.colorLocation=this.createAttribLocation_(t,e,"a_color",this.colors.length/this.size,t.FLOAT),t.bindAttribLocation(e,this.colorLocation,"a_color"))},e.attachAttributes_=function(t,e){var r;this.positions&&(r=t.getAttribLocation(e,"a_position"),t.enableVertexAttribArray(r),t.bindBuffer(t.ARRAY_BUFFER,this.positionBuffer),t.vertexAttribPointer(r,this.positions.length/this.size,t.FLOAT,!1,0,0)),this.texcoords&&(r=t.getAttribLocation(e,"a_texcoord"),t.enableVertexAttribArray(this.texcoordLocation),t.bindBuffer(t.ARRAY_BUFFER,this.texcoordBuffer),t.vertexAttribPointer(this.texcoordLocation,this.texcoords.length/this.size,t.FLOAT,!1,0,0)),this.normals&&(r=t.getAttribLocation(e,"a_normal"),t.enableVertexAttribArray(this.normalLocation),t.bindBuffer(t.ARRAY_BUFFER,this.normalBuffer),t.vertexAttribPointer(this.normalLocation,this.normals.length/this.size,t.FLOAT,!1,0,0)),this.colors&&(r=t.getAttribLocation(e,"a_color"),t.enableVertexAttribArray(this.colorLocation),t.bindBuffer(t.ARRAY_BUFFER,this.colorBuffer),t.vertexAttribPointer(this.colorLocation,this.colors.length/this.size,t.FLOAT,!1,0,0))},e.bindAttributes_=function(t,e){this.positions&&t.bindAttribLocation(e,this.positionLocation,"a_position"),this.texcoords&&t.bindAttribLocation(e,this.texcoordLocation,"a_texcoord"),this.normals&&t.bindAttribLocation(e,this.normalLocation,"a_normal"),this.colors&&t.bindAttribLocation(e,this.colorLocation,"a_color")},e.createData_=function(){this.positions=[],this.normals=[],this.texcoords=[],this.colors=[],this.size=0},t.fromIndices=function(t,e,r){var i=[];return t.forEach((function(t){i.push.apply(i,e.slice(t*r,t*r+r))})),i},t}(),H=function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e.prototype.createData_=function(){this.size=6,this.positions=[-1,-1,0,1,-1,0,1,1,0,-1,-1,0,1,1,0,-1,1,0],this.texcoords=[0,0,1,0,1,1,0,0,1,1,0,1],this.normals=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1],this.colors=[1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1]},e}(j);(N=t.BufferFloatType||(t.BufferFloatType={}))[N.FLOAT=0]="FLOAT",N[N.HALF_FLOAT=1]="HALF_FLOAT";var Y=function(){function e(t,r,i,n){var o=t.createFramebuffer(),s=e.getTexture(t,r,i,n);t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),this.texture=s,this.buffer=o,this.BW=r,this.BH=i,this.index=n}return e.getFloatType=function(t){return V.isWebGl2(t)&&t.getExtension("EXT_color_buffer_float")||t.getExtension("OES_texture_float")?t.FLOAT:null},e.getHalfFloatType=function(t){var e;return V.isWebGl2(t)&&(e=t.getExtension("EXT_color_buffer_half_float")||t.getExtension("EXT_color_buffer_float"))?t.HALF_FLOAT:(e=t.getExtension("OES_texture_half_float"))&&e.HALF_FLOAT_OES||null},e.getInternalFormat=function(t){return V.isWebGl2(t)?t.RGBA16F:t.RGBA},e.getType=function(r){return e.type===t.BufferFloatType.HALF_FLOAT?e.getHalfFloatType(r)||(e.type=t.BufferFloatType.FLOAT,e.getType(r)):e.getFloatType(r)||(e.type=t.BufferFloatType.HALF_FLOAT,e.getType(r))},e.getTexture=function(r,i,n,o){var s=e.getInternalFormat(r),a=r.RGBA,u=e.getType(r),h=r.createTexture();return r.activeTexture(r.TEXTURE0+o),r.bindTexture(r.TEXTURE_2D,h),r.texImage2D(r.TEXTURE_2D,0,s,i,n,0,a,u,null),r.checkFramebufferStatus(r.FRAMEBUFFER)!==r.FRAMEBUFFER_COMPLETE?(e.type===t.BufferFloatType.FLOAT?e.type=t.BufferFloatType.HALF_FLOAT:e.type=t.BufferFloatType.FLOAT,e.getTexture(r,i,n,o)):h},e.prototype.resize=function(t,r,i){if(r!==this.BW||i!==this.BH){var n=this.buffer,o=this.texture,s=this.index;t.bindFramebuffer(t.FRAMEBUFFER,n);var a,u=t.checkFramebufferStatus(t.FRAMEBUFFER),h=Math.min(r,this.BW),f=Math.min(i,this.BH),c=e.getType(t);u===t.FRAMEBUFFER_COMPLETE&&(a=new Float32Array(h*f*4),t.readPixels(0,0,h,f,t.RGBA,c,a)),t.bindFramebuffer(t.FRAMEBUFFER,null);var l=s+1,d=e.getTexture(t,r,i,l);c=e.getType(t),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.NEAREST),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_S,t.CLAMP_TO_EDGE),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_WRAP_T,t.CLAMP_TO_EDGE),a&&t.texSubImage2D(t.TEXTURE_2D,0,0,0,h,f,t.RGBA,c,a);var m=t.createFramebuffer();t.bindFramebuffer(t.FRAMEBUFFER,null),t.deleteTexture(o),t.activeTexture(t.TEXTURE0+s),t.bindTexture(t.TEXTURE_2D,d),this.index=s,this.texture=d,this.buffer=m,this.BW=r,this.BH=i}},e}();Y.type=t.BufferFloatType.HALF_FLOAT;var q=function(){function t(t,e,r,i){this.isValid=!1,this.index=t,this.key=e,this.vertexString=r,this.fragmentString=i,this.geometry=new H}var e=t.prototype;return e.create=function(t,e,r){var i=V.createShader(t,this.vertexString,t.VERTEX_SHADER),n=V.createShader(t,this.fragmentString,t.FRAGMENT_SHADER,1);n?this.isValid=!0:(n=V.createShader(t,V.isWebGl2(t)?T:x,t.FRAGMENT_SHADER),this.isValid=!1);var o=V.createProgram(t,[i,n]);if(!o)return this.isValid=!1,t.deleteShader(i),void t.deleteShader(n);this.geometry.create(t,o),t.deleteShader(i),t.deleteShader(n);var s=new Y(t,e,r,this.index+0),a=new Y(t,e,r,this.index+2);this.program=o,this.input=s,this.output=a},e.render=function(t,e,r){t.useProgram(this.program),t.bindFramebuffer(t.FRAMEBUFFER,this.output.buffer),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.output.texture,0),t.checkFramebufferStatus(t.FRAMEBUFFER)===t.FRAMEBUFFER_COMPLETE&&(t.clearColor(0,0,0,1),t.clear(t.COLOR_BUFFER_BIT|t.DEPTH_BUFFER_BIT)),t.viewport(0,0,e,r),t.drawArrays(t.TRIANGLES,0,this.geometry.size);var i=this.input;this.input=this.output,this.output=i},e.resize=function(t,e,r){t.useProgram(this.program),t.viewport(0,0,e,r),this.input.resize(t,e,r),this.output.resize(t,e,r)},e.destroy=function(t){t.deleteProgram(this.program),this.program=null,this.input=null,this.output=null},t}(),K=function(t){function i(){return t.apply(this,arguments)||this}var n,o,s;return r(i,t),i.getBuffers=function(t,e,r){var n=new i,o=0;if(e){V.isWebGl2(t)&&(e=e.replace(/^\#version\s*300\s*es\s*\n/,""));for(var s,a=/(?:^\s*)((?:#if|#elif)(?:\s*)(defined\s*\(\s*BUFFER_)(\d+)(?:\s*\))|(?:#ifdef)(?:\s*BUFFER_)(\d+)(?:\s*))/gm;null!==(s=a.exec(e));){var u=s[3]||s[4],h="u_buffer"+u,f=V.isWebGl2(t)?"#version 300 es\n#define BUFFER_"+u+"\n"+e:"#define BUFFER_"+u+"\n"+e,c=new q(o,h,r,f);if(c.create(t,t.drawingBufferWidth,t.drawingBufferHeight),!c.program)throw"buffer error "+h;n.set(h,c),o+=4}}return n},n=i,(o=[{key:"count",get:function(){return 4*Object.keys(this.values).length}}])&&e(n.prototype,o),s&&e(n,s),i}(X),$=function(){function t(t,e){void 0===t&&(t=0),void 0===e&&(e=0),this.isVector2=!0,this.x=t,this.y=e}var e=t.prototype;return e.copy=function(t){return this.x=t.x,this.y=t.y,this},e.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y)},e.normalize=function(){return this.divideScalar(this.length()||1)},e.divideScalar=function(t){return this.multiplyScalar(1/t)},e.multiplyScalar=function(t){return this.x*=t,this.y*=t,this},e.subVectors=function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this},e.addVectors=function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this},t}(),J=function(){function t(t,e,r){void 0===t&&(t=0),void 0===e&&(e=0),void 0===r&&(r=0),this.isVector3=!0,this.x=t,this.y=e,this.z=r}var e=t.prototype;return e.copy=function(t){return this.x=t.x,this.y=t.y,this.z=t.z,this},e.length=function(){return Math.sqrt(this.x*this.x+this.y*this.y+this.z*this.z)},e.normalize=function(){return this.divideScalar(this.length()||1)},e.divideScalar=function(t){return this.multiplyScalar(1/t)},e.multiplyScalar=function(t){return this.x*=t,this.y*=t,this.z*=t,this},e.subVectors=function(t,e){return this.x=t.x-e.x,this.y=t.y-e.y,this.z=t.z-e.z,this},e.addVectors=function(t,e){return this.x=t.x+e.x,this.y=t.y+e.y,this.z=t.z+e.z,this},e.crossVectors=function(t,e){var r=t.x,i=t.y,n=t.z,o=e.x,s=e.y,a=e.z;return this.x=i*a-n*s,this.y=n*o-r*a,this.z=r*s-i*o,this},t}(),Q=Math.PI/180,Z=function(t){function e(e,r,i){var n;return(n=t.call(this)||this).position=new J,n.value=new Float32Array([0,0,0]),n.mouse=null,n.dirty=!1,n.theta=(e||0)*Q,n.phi=(r||0)*Q,n.radius=i||6,n}r(e,t);var i=e.prototype;return i.down=function(t,e){this.mouse=new $(t,e)},i.move=function(t,e){var r=this.mouse;if(r&&(r.x!==t||r.y!==e)){var i=180*(t-r.x)*Q,n=180*(e-r.y)*Q;r.x=t,r.y=e,this.theta+=i,this.phi=Math.max(-60*Q,Math.min(60*Q,this.phi+n))}},i.up=function(){this.mouse=null},i.wheel=function(t){this.radius=Math.max(4,Math.min(10,this.radius+.02*t))},e.fromVector=function(t){var r=t.length();return new e(Math.acos(t.y/r),Math.atan(t.x/t.z),r)},e.toArray=function(t){var e=Math.sin(t.phi)*t.radius;return[e*Math.sin(t.theta),Math.cos(t.phi)*t.radius,e*Math.cos(t.theta)]},e}(J),tt="undefined"!=typeof Float32Array?Float32Array:Array;function et(){var t=new tt(16);return tt!=Float32Array&&(t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=0,t[12]=0,t[13]=0,t[14]=0),t[0]=1,t[5]=1,t[10]=1,t[15]=1,t}function rt(t){return t[0]=1,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=1,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=1,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}function it(t,e,r,i){var n,o,s,a,u,h,f,c,l,d,m,v,p,g,_,y,x,T,E,U,M,b,A,w,F=i[0],L=i[1],R=i[2],S=Math.hypot(F,L,R);return S<1e-6?null:(F*=S=1/S,L*=S,R*=S,n=Math.sin(r),s=1-(o=Math.cos(r)),a=e[0],u=e[1],h=e[2],f=e[3],c=e[4],l=e[5],d=e[6],m=e[7],v=e[8],p=e[9],g=e[10],_=e[11],y=F*F*s+o,x=L*F*s+R*n,T=R*F*s-L*n,E=F*L*s-R*n,U=L*L*s+o,M=R*L*s+F*n,b=F*R*s+L*n,A=L*R*s-F*n,w=R*R*s+o,t[0]=a*y+c*x+v*T,t[1]=u*y+l*x+p*T,t[2]=h*y+d*x+g*T,t[3]=f*y+m*x+_*T,t[4]=a*E+c*U+v*M,t[5]=u*E+l*U+p*M,t[6]=h*E+d*U+g*M,t[7]=f*E+m*U+_*M,t[8]=a*b+c*A+v*w,t[9]=u*b+l*A+p*w,t[10]=h*b+d*A+g*w,t[11]=f*b+m*A+_*w,e!==t&&(t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15]),t)}Math.hypot||(Math.hypot=function(){for(var t=0,e=arguments.length;e--;)t+=arguments[e]*arguments[e];return Math.sqrt(t)});var nt,ot,st=function(){function t(){this.delay=0,this.current=0,this.delta=0,this.paused=!1,this.start=this.previous=this.now()}var e=t.prototype;return e.now=function(){return performance.now()},e.play=function(){if(this.previous){var t=this.now();this.delay+=t-this.previous,this.previous=t}this.paused=!1},e.pause=function(){this.paused=!0},e.next=function(){var t=this.now();return this.delta=t-this.previous,this.current=t-this.start-this.delay,this.previous=t,this},t}(),at=function(t,e){this.event=t,this.callback=e},ut=function(){function t(){this.listeners=new Set}var e=t.prototype;return e.logListeners=function(){this.listeners.forEach((function(t){return I.log(t)}))},e.subscribe=function(t){this.listeners.add(t)},e.unsubscribe=function(t){this.listeners.delete(t)},e.unsubscribeAll=function(){this.listeners.clear()},e.on=function(t,e){return this.listeners.add(new at(t,e)),this},e.off=function(t,e){var r=this;return e?this.listeners.delete(new at(t,e)):this.listeners.forEach((function(e){e.event===t&&r.listeners.delete(e)})),this},e.trigger=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];return this.listeners.forEach((function(e){e.event===t&&"function"==typeof e.callback&&e.callback.apply(e,r)})),this},t}(),ht=function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e.prototype.createData_=function(){this.size=36,this.positions=[-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1,-1,-1,1,-1,-1,1,1,1,1,1,-1,1,-1,1,1,1,1,1,-1,-1,-1,-1,1,-1,-1,1,-1,1,-1,-1,-1,1,-1,1,-1,-1,1,1,-1,-1,1,1,-1,1,1,1,1,-1,-1,1,1,1,1,-1,1,-1,-1,-1,-1,-1,1,-1,1,1,-1,-1,-1,-1,1,1,-1,1,-1],this.texcoords=[0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1,0,0,1,0,1,1,0,0,1,1,0,1],this.normals=[0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0,-1,0,0];for(var t=[[1,1,1,1],[1,0,0,1],[0,1,0,1],[0,0,1,1],[1,1,0,1],[1,0,1,1]],e=[],r=0;r<t.length;++r){var i=t[r];e=e.concat(i,i,i,i,i,i)}this.colors=e},e}(j),ft=function(t){function e(){return t.apply(this,arguments)||this}return r(e,t),e.prototype.createData_=function(){var t,e,r=2*Math.PI,i=Math.PI,n=new J,o=new J,s=[],a=[],u=[],h=[],f=[],c=Math.min(0+i,Math.PI),l=0,d=[];for(e=0;e<=60;e++){var m=[],v=e/60,p=0;for(0==e?p=.5/80:60==e&&c==Math.PI&&(p=-.5/80),t=0;t<=80;t++){var g=t/80;n.x=-1.4*Math.cos(0+g*r)*Math.sin(0+v*i),n.y=1.4*Math.cos(0+v*i),n.z=1.4*Math.sin(0+g*r)*Math.sin(0+v*i),a.push(n.x,n.y,n.z),o.copy(n).normalize(),u.push(o.x,o.y,o.z);var _=g+p,y=1-v;h.push(_,y),f.push(1,1,1,1),m.push(l++)}d.push(m)}for(e=0;e<60;e++)for(t=0;t<80;t++){var x=d[e][t+1],T=d[e][t],E=d[e+1][t],U=d[e+1][t+1];0!==e&&s.push(x,T,U),(59!==e||c<Math.PI)&&s.push(T,E,U)}this.size=s.length,this.positions=j.fromIndices(s,a,3),this.texcoords=j.fromIndices(s,h,2),this.normals=j.fromIndices(s,u,3),this.colors=j.fromIndices(s,f,4)},e}(j),ct=function(t){function e(){return t.apply(this,arguments)||this}r(e,t);var i=e.prototype;return i.createData_=function(){for(var t=200,e=40,r=[],i=[],n=[],o=[],s=[],a=new J,u=new J,h=new J,f=new J,c=new J,l=new J,d=new J,m=0;m<=t;++m){var v=m/t*2*Math.PI*2;this.calculatePositionOnCurve(v,2,3,1,h),this.calculatePositionOnCurve(v+.01,2,3,1,f),l.subVectors(f,h),d.addVectors(f,h),c.crossVectors(l,d),d.crossVectors(c,l),c.normalize(),d.normalize();for(var p=0;p<=e;++p){var g=p/e*Math.PI*2,_=-.25*Math.cos(g),y=.25*Math.sin(g);a.x=h.x+(_*d.x+y*c.x),a.y=h.y+(_*d.y+y*c.y),a.z=h.z+(_*d.z+y*c.z),i.push(a.x,a.y,a.z),u.subVectors(a,h).normalize(),n.push(u.x,u.y,u.z),o.push(m/t*2*Math.round(3)),o.push(p/e),s.push(1,1,1,1)}}for(var x=1;x<=t;x++)for(var T=1;T<=e;T++){var E=41*(x-1)+(T-1),U=41*x+(T-1),M=41*x+T,b=41*(x-1)+T;r.push(E,U,b),r.push(U,M,b)}this.size=r.length,this.positions=j.fromIndices(r,i,3),this.texcoords=j.fromIndices(r,o,2),this.normals=j.fromIndices(r,n,3),this.colors=j.fromIndices(r,s,4)},i.calculatePositionOnCurve=function(t,e,r,i,n){var o=Math.cos(t),s=Math.sin(t),a=r/e*t,u=Math.cos(a);n.x=i*(2+u)*.5*o,n.y=i*(2+u)*s*.5,n.z=i*Math.sin(a)*.5},e}(j),lt=[[1,1,1],[1,0,0],[0,1,0],[0,0,1],[1,1,0],[0,1,1]],dt=0,mt=function(){function t(){}var e=t.prototype;return e.load=function(t){var e=this;return new Promise((function(r,i){O.fetch(t).then((function(n){var o=e.parse(n);if(o.positions.length){var s=new j(o);r(s)}else i("ObjLoader error: empty positions "+t)}),(function(e){console.log("ObjLoader error:",e,t),i(e)}))}))},e.parseIndices=function(t,e,r,i,n,o){for(var s=0;s<=t.length-3;){var a=void 0,u=void 0,h=void 0;0===s?(a=s,u=s+1,h=s+2):(a=s-1,u=s+1,h=s+2),s++;for(var f=[a,u,h],c=0;c<f.length;c++){var l=t[f[c]][e],d=void 0;l&&NaN!==l&&(d=i[l-1])&&(d=d.slice(0,r),n.push.apply(n,d))}}},e.parseFaces=function(t,e,r,i,n,o,s,a){var u=this,h=n.length;t.forEach((function(t){u.parseIndices(t,0,3,e,n,"positions"),u.parseIndices(t,2,3,r,o,"normals"),u.parseIndices(t,1,2,i,s,"texcoords")}));var f=n.length-h;f>0&&(new Array(f/3).fill(0).forEach((function(){var t=lt[dt%lt.length];a.push(t[0],t[1],t[2],1)})),dt++)},e.parse=function(t){var e=this,r=[],i=[],n=[],o=[];dt=0;var s=[],a=[],u=[],h=[];-1!==t.indexOf("\r\n")&&(t=t.replace(/\r\n/g,"\n")),(t=t.replace(/  /g," ")).split("\n").forEach((function(t,f){if(0===t.indexOf("v ")){h.length&&(e.parseFaces(h,s,a,u,r,i,n,o),h=[]);var c=t.replace("v","").trim().split(" ").map((function(t){return parseFloat(t)}));s.push(c)}else if(0===t.indexOf("vn ")){var l=t.replace("vn","").trim().split(" ").map((function(t){return parseFloat(t)})),d=new J(l[0],l[1],l[2]).normalize();a.push([d.x,d.y,d.z])}else if(0===t.indexOf("vt ")){var m=t.replace("vt","").trim().split(" ").map((function(t){return parseFloat(t)}));u.push(m)}else if(0===t.indexOf("f ")){var v=t.replace("f","").trim().split(" ").map((function(t){var e=t.split("/").map((function(t){return parseInt(t)}));return 2===e.length&&e.push(null),e}));h[h.length]=v}})),h.length&&this.parseFaces(h,s,a,u,r,i,n,o);for(var f={min:new J(Number.POSITIVE_INFINITY),max:new J(Number.NEGATIVE_INFINITY)},c=0;c<r.length;c+=3)f.min.x=Math.min(f.min.x,r[c]),f.min.y=Math.min(f.min.y,r[c+1]),f.min.z=Math.min(f.min.z,r[c+2]),f.max.x=Math.max(f.max.x,r[c]),f.max.y=Math.max(f.max.y,r[c+1]),f.max.z=Math.max(f.max.z,r[c+2]);for(var l=-(f.min.x+f.max.x)/2,d=-(f.min.y+f.max.y)/2,m=-(f.min.z+f.max.z)/2,v=0;v<r.length;v+=3)r[v]+=l,r[v+1]+=d,r[v+2]+=m;var p=r.reduce((function(t,e){return Math.max(t,e)}),0);return r.forEach((function(t,e){return r[e]=t/p*2})),i.length||(i=r.slice()),n.length||(n=this.unrapUvw(r)),{positions:r,normals:i,texcoords:n,colors:o}},e.unrapUvw=function(t){for(var e=[],r=0;r<t.length;r+=3){var i=new J(t[r],t[r+1],t[r+2]);i.normalize();var n=Math.asin(-i.y),o=Math.atan2(i.x,i.z),s=.5+n/Math.PI,a=.5+o/(2*Math.PI);e.push(s,a)}return e},t}(),vt=["jpg","jpeg","png"],pt=["ogv","webm","mp4"],gt=vt.concat(pt);function _t(t){return"data"in t&&"width"in t&&"height"in t}(nt=t.TextureSourceType||(t.TextureSourceType={}))[nt.Data=0]="Data",nt[nt.Element=1]="Element",nt[nt.Url=2]="Url",(ot=t.TextureFilteringType||(t.TextureFilteringType={})).MipMap="mipmap",ot.Linear="linear",ot.Nearest="nearest";var yt,xt,Tt=function(e){function i(r,i,n,o,s){var a;return void 0===o&&(o={filtering:t.TextureFilteringType.Linear}),(a=e.call(this)||this).valid=!1,a.dirty=!1,a.animated=!1,a.powerOf2=!1,a.key=i,a.index=n,a.options=o,a.workpath=s,a.create(r),a}r(i,e),i.isPowerOf2=function(t){return 0==(t&t-1)},i.isSafari=function(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)},i.isTextureUrl=function(t){return t&&/\.(jpg|jpeg|png|ogv|webm|mp4)$/i.test(t.split("?")[0])},i.isTexture=function(t){return void 0!==i.getTextureOptions(t)},i.getMaxTextureSize=function(t){return t.getParameter(t.MAX_TEXTURE_SIZE)},i.getTextureOptions=function(t,e){if(void 0===e&&(e={}),"string"==typeof t&&""!==t){if(i.isTextureUrl(t))return e.url=t,-1!==t.indexOf("?")&&(e=t.split("?")[1].split("&").reduce((function(t,e){var r=e.split("="),i=decodeURIComponent(r[0]),n=decodeURIComponent(r[1]);switch(i){case"filtering":t[i]=n;break;case"repeat":case"UNPACK_FLIP_Y_WEBGL":t[i]=Boolean(n);break;case"UNPACK_PREMULTIPLY_ALPHA_WEBGL":case"TEXTURE_WRAP_S":case"TEXTURE_WRAP_T":t[i]=Number(n)}return t}),e)),e;document&&(t=document.querySelector(t))}return t instanceof HTMLCanvasElement||t instanceof HTMLImageElement||t instanceof HTMLVideoElement?(e.element=t,e):_t(t)?(e.data=t.data,e.width=t.width,e.height=t.height,e):null};var n=i.prototype;return n.create=function(t){this.texture=t.createTexture(),this.texture&&(this.valid=!0),this.setData(t,1,1,new Uint8Array([0,0,0,0]),this.options)},n.load=function(t,e){return void 0===e&&(e={}),this.options=e,"string"==typeof e.url?void 0===this.url||e.url!==this.url?this.setUrl(t,e.url,e):Promise.resolve(this):e.element?this.setElement(t,e.element,e):e.data&&e.width&&e.height?this.setData(t,e.width,e.height,e.data,e):Promise.reject(this)},n.setUrl=function(e,r,n){if(void 0===n&&(n={}),!this.valid)return Promise.reject(this);this.url=r,this.source=r,this.sourceType=t.TextureSourceType.Url,this.options=Object.assign(this.options,n);var o,s,a=r.split("?")[0].split(".").pop().toLowerCase(),u=-1!==pt.indexOf(a),h=O.getResource(r,this.workpath);return u?(I.log("GlslCanvas.setUrl video",h),(o=document.createElement("video")).setAttribute("preload","auto"),o.setAttribute("loop","true"),o.setAttribute("muted","true"),o.setAttribute("playsinline","true"),o.loop=!0,o.muted=!0,s=this.setElement(e,o,n),o.src=h,o.addEventListener("canplay",(function(){o.play()}))):(I.log("GlslCanvas.setUrl image",h),o=document.createElement("img"),s=this.setElement(e,o,n),i.isSafari()&&"data:"===r.slice(0,5)||(o.crossOrigin="anonymous"),o.src=h),s},n.setElement=function(e,r,i){var n=this;return void 0===i&&(i={}),i=this.options=Object.assign(this.options,i),new Promise((function(o,s){var a=r;if("string"==typeof r&&(r=document.querySelector(r)),r instanceof HTMLCanvasElement||r instanceof HTMLImageElement||r instanceof HTMLVideoElement)if(n.source=r,n.sourceType=t.TextureSourceType.Element,r instanceof HTMLVideoElement){var u=r;u.addEventListener("loadeddata",(function(t){n.update(e,i),n.setFiltering(e,i),o(n)})),u.addEventListener("error",(function(t){s(t)})),u.load()}else r instanceof HTMLImageElement?(r.addEventListener("load",(function(){n.update(e,i),n.setFiltering(e,i),o(n)})),r.addEventListener("error",(function(t){s(t)}))):(n.update(e,i),n.setFiltering(e,i),o(n));else{var h="the 'element' parameter (`element: "+JSON.stringify(a)+"`) must be a CSS selector string, or a <canvas>, <image> or <video> object";I.log("Texture '"+n.key+"': "+h,i),s(h)}}))},n.setData=function(e,r,i,n,o){return void 0===o&&(o={}),this.width=r,this.height=i,this.options=Object.assign(this.options,o),this.source=n,this.sourceType=t.TextureSourceType.Data,this.update(e,o),this.setFiltering(e,o),Promise.resolve(this)},n.update=function(e,r){if(this.valid){if(e.activeTexture(e.TEXTURE0+this.index),e.bindTexture(e.TEXTURE_2D,this.texture),e.pixelStorei(e.UNPACK_FLIP_Y_WEBGL,!1===r.UNPACK_FLIP_Y_WEBGL?0:1),e.pixelStorei(e.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r.UNPACK_PREMULTIPLY_ALPHA_WEBGL||0),this.sourceType===t.TextureSourceType.Element)this.source instanceof HTMLImageElement&&this.source.naturalWidth&&this.source.naturalHeight?(this.width=this.source.naturalWidth,this.height=this.source.naturalHeight,e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.source)):this.source instanceof HTMLVideoElement&&this.source.videoWidth&&this.source.videoHeight?(this.width=this.source.videoWidth,this.height=this.source.videoHeight,e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.source)):this.source instanceof HTMLCanvasElement&&(this.width=this.source.width,this.height=this.source.height,e.texImage2D(e.TEXTURE_2D,0,e.RGBA,e.RGBA,e.UNSIGNED_BYTE,this.source));else if(this.sourceType===t.TextureSourceType.Data){var i=this.source;e.texImage2D(e.TEXTURE_2D,0,e.RGBA,this.width,this.height,0,e.RGBA,e.UNSIGNED_BYTE,i)}this.trigger("loaded",this)}},n.tryUpdate=function(t){var e=!1;return this.animated&&(e=!0,this.update(t,this.options)),e},n.destroy=function(t){this.valid&&(t.deleteTexture(this.texture),this.texture=null,delete this.source,this.source=null,this.valid=!1)},n.setFiltering=function(e,r){if(this.valid){var n=i.isPowerOf2(this.width)&&i.isPowerOf2(this.height),o=r.filtering||t.TextureFilteringType.MipMap,s=r.TEXTURE_WRAP_S||(r.repeat?e.REPEAT:e.CLAMP_TO_EDGE),a=r.TEXTURE_WRAP_T||(r.repeat?e.REPEAT:e.CLAMP_TO_EDGE);n||(o=o===t.TextureFilteringType.MipMap?t.TextureFilteringType.Linear:o,s=a=e.CLAMP_TO_EDGE,(r.repeat||r.TEXTURE_WRAP_S||r.TEXTURE_WRAP_T)&&I.warn("GlslCanvas: cannot repeat texture "+r.url+" cause is not power of 2.")),this.powerOf2=n,this.filtering=o,e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_S,s),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_WRAP_T,a),this.filtering===t.TextureFilteringType.MipMap?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR_MIPMAP_LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR),e.generateMipmap(e.TEXTURE_2D)):this.filtering===t.TextureFilteringType.Nearest?(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.NEAREST),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.NEAREST)):this.filtering===t.TextureFilteringType.Linear&&(e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MIN_FILTER,e.LINEAR),e.texParameteri(e.TEXTURE_2D,e.TEXTURE_MAG_FILTER,e.LINEAR))}},i}(ut),Et=function(t){function e(){var e;return(e=t.apply(this,arguments)||this).count=0,e.dirty=!1,e.animated=!1,e}r(e,t);var i=e.prototype;return i.clean=function(){var t=this;Object.keys(this.values).forEach((function(e){t.values[e].dirty=!1})),this.dirty=!1},i.createOrUpdate=function(t,e,r,i,n,o){var s,a=this;void 0===i&&(i=0),void 0===n&&(n={});var u=Tt.getTextureOptions(r,n);return(s=this.get(e))||(s=new Tt(t,e,i+this.count,u,o),this.count++,this.set(e,s)),void 0!==u?s.load(t,u).then((function(e){if(e.source instanceof HTMLVideoElement){var r=e.source;r.addEventListener("play",(function(){e.animated=!0,a.animated=!0})),r.addEventListener("pause",(function(){e.animated=!1,a.animated=a.reduce((function(t,e){return t||e.animated}),!1)})),r.addEventListener("seeked",(function(){e.update(t,e.options),a.dirty=!0}))}return e})):Promise.resolve(s)},e}(X);(yt=t.UniformMethod||(t.UniformMethod={}))[yt.Unknown=0]="Unknown",yt.Uniform1i="uniform1i",yt.Uniform2i="uniform2i",yt.Uniform3i="uniform3i",yt.Uniform4i="uniform4i",yt.Uniform1f="uniform1f",yt.Uniform2f="uniform2f",yt.Uniform3f="uniform3f",yt.Uniform4f="uniform4f",yt.Uniform1iv="uniform1iv",yt.Uniform2iv="uniform2iv",yt.Uniform3iv="uniform3iv",yt.Uniform4iv="uniform4iv",yt.Uniform1fv="uniform1fv",yt.Uniform2fv="uniform2fv",yt.Uniform3fv="uniform3fv",yt.Uniform4fv="uniform4fv",yt.UniformMatrix2fv="uniformMatrix2fv",yt.UniformMatrix3fv="uniformMatrix3fv",yt.UniformMatrix4fv="uniformMatrix4fv",(xt=t.UniformType||(t.UniformType={}))[xt.Unknown=0]="Unknown",xt[xt.Float=1]="Float",xt[xt.Int=2]="Int",xt[xt.Bool=3]="Bool",xt[xt.Sampler2D=4]="Sampler2D",xt[xt.SamplerCube=5]="SamplerCube",xt[xt.Matrix2fv=6]="Matrix2fv",xt[xt.Matrix3fv=7]="Matrix3fv",xt[xt.Matrix4fv=8]="Matrix4fv";var Ut=[t.UniformMethod.Uniform1i,t.UniformMethod.Uniform2i,t.UniformMethod.Uniform3i,t.UniformMethod.Uniform4i],Mt=[t.UniformMethod.Uniform1f,t.UniformMethod.Uniform2f,t.UniformMethod.Uniform3f,t.UniformMethod.Uniform4f],bt=[t.UniformMethod.Uniform1iv,t.UniformMethod.Uniform2iv,t.UniformMethod.Uniform3iv,t.UniformMethod.Uniform4iv],At=[t.UniformMethod.Uniform1fv,t.UniformMethod.Uniform2fv,t.UniformMethod.Uniform3fv,t.UniformMethod.Uniform4fv],wt=function(e){var r=this;switch(this.dirty=!0,e&&Object.assign(this,e),this.method){case t.UniformMethod.UniformMatrix2fv:case t.UniformMethod.UniformMatrix3fv:case t.UniformMethod.UniformMatrix4fv:this.apply=function(t,e){if(r.dirty){t.useProgram(e);var i=t.getUniformLocation(e,r.key);t[r.method].apply(t,[i,!1].concat(r.values))}};break;default:this.apply=function(t,e){if(r.dirty){t.useProgram(e);var i=t.getUniformLocation(e,r.key);t[r.method].apply(t,[i].concat(r.values))}}}},Ft=function(t){function e(e){return t.call(this,e)||this}return r(e,t),e}(wt),Lt=function(e){function i(){var t;return(t=e.apply(this,arguments)||this).dirty=!1,t}r(i,e),i.isArrayOfInteger=function(t){return t.reduce((function(t,e){return t&&Number.isInteger(e)}),!0)},i.isArrayOfNumber=function(t){return t.reduce((function(t,e){return t&&"number"==typeof e}),!0)},i.isArrayOfBoolean=function(t){return t.reduce((function(t,e){return t&&"boolean"==typeof e}),!0)},i.isArrayOfTexture=function(t){return t.reduce((function(t,e){return t&&Tt.isTexture(e)}),!0)},i.isArrayOfSampler2D=function(e){return e.reduce((function(e,r){return e&&r.type===t.UniformType.Sampler2D}),!0)},i.getType_=function(e){var r=t.UniformType.Unknown,n=1===e.length&&Array.isArray(e[0])?e[0]:e;return i.isArrayOfNumber(n)?r=t.UniformType.Float:i.isArrayOfBoolean(n)?r=t.UniformType.Bool:i.isArrayOfTexture(n)&&(r=t.UniformType.Sampler2D),r},i.getMethod_=function(e,r){var i=t.UniformMethod.Unknown,n=1===r.length&&Array.isArray(r[0]),o=(n?r[0]:r).length,s=o-1;switch(e){case t.UniformType.Float:i=n?s<At.length?At[s]:t.UniformMethod.Unknown:s<Mt.length?Mt[s]:t.UniformMethod.Uniform1fv;break;case t.UniformType.Int:case t.UniformType.Bool:i=n?s<bt.length?bt[s]:t.UniformMethod.Unknown:s<Ut.length?Ut[s]:t.UniformMethod.Uniform1iv;break;case t.UniformType.Sampler2D:i=n?t.UniformMethod.Uniform1iv:1===o?t.UniformMethod.Uniform1i:t.UniformMethod.Uniform1iv}return i},i.parseUniform=function(e,r,n){var o;void 0===n&&(n=null),n=n||i.getType_(r);var s=i.getMethod_(n,r);if(n!==t.UniformType.Unknown&&s!==t.UniformMethod.Unknown){if(n===t.UniformType.Sampler2D&&s===t.UniformMethod.Uniform1iv)return r[0].map((function(t,r){return new wt({method:s,type:n,key:e+"["+r+"]",values:[t]})}));o=new wt({method:s,type:n,key:e,values:r})}else I.error("Uniforms.parseUniform.Unknown",e,r);return o};var n=i.prototype;return n.create=function(t,e,r,i){var n=new wt({method:t,type:e,key:r,values:i});return this.set(r,n),this.dirty=!0,n},n.createTexture=function(e,r){var i;return i=-1!==e.indexOf("]")?new Ft({method:t.UniformMethod.Uniform1iv,type:t.UniformType.Sampler2D,key:e,values:[[r]]}):new Ft({method:t.UniformMethod.Uniform1i,type:t.UniformType.Sampler2D,key:e,values:[r]}),this.set(e,i),this.dirty=!0,i},n.update=function(t,e,r,i){var n=this.get(r);n&&(n.method=t,n.type=e,n.values=i,n.dirty=!0,this.dirty=!0)},n.createOrUpdate=function(t,e,r,i){this.has(r)?this.update(t,e,r,i):this.create(t,e,r,i)},n.apply=function(t,e){var r=this;t.useProgram(e),Object.keys(this.values).forEach((function(i){r.values[i].apply(t,e)}))},n.clean=function(){var t=this;Object.keys(this.values).forEach((function(e){t.values[e].dirty=!1})),this.dirty=!1},i.isDifferent=function(t,e){return t.length!==e.length||t.reduce((function(t,r,i){return t||r!==e[i]}),!1)},i}(X),Rt=function(e){function i(){var t;return(t=e.call(this)||this).uniforms=new Lt,t.buffers=new K,t.textures=new Et,t.textureList=[],t.W=0,t.H=0,t.mouse=new $,t.radians=0,t.dirty=!0,t.animated=!1,t.camera=new Z,t.cache={},t.drawFunc_=t.drawArrays_,t}r(i,e);var n=i.prototype;return n.render=function(){var t=this,e=this.gl;if(e){var r=e.drawingBufferWidth,i=e.drawingBufferHeight;this.update_(),e.viewport(0,0,r,i);var n=this.uniforms;Object.keys(this.buffers.values).forEach((function(o){var s=t.buffers.values[o];s.geometry.attachAttributes_(e,s.program),n.apply(e,s.program),s.render(e,r,i)})),this.geometry.attachAttributes_(e,this.program),n.apply(e,this.program),this.drawFunc_(this.timer.delta),n.clean(),this.textures.clean(),this.dirty=!1,this.trigger("render",this)}},n.drawArrays_=function(t){var e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,null),e.viewport(0,0,this.W,this.H),e.clearColor(0,0,0,1),e.clearDepth(1),e.enable(e.DEPTH_TEST),e.depthFunc(e.LEQUAL),e.enable(e.CULL_FACE),this.doubleSided&&this.mode!==C.Flat&&(e.cullFace(e.FRONT),e.drawArrays(e.TRIANGLES,0,this.geometry.size),e.enable(e.BLEND),e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA)),e.cullFace(e.BACK),e.drawArrays(e.TRIANGLES,0,this.geometry.size)},n.create_=function(){this.createGeometry_(),this.createUniforms_()},n.createGeometry_=function(){this.parseGeometry_(),this.setMode(this.mode)},n.parseGeometry_=function(){var t=/^attribute\s+vec4\s+a_position\s*;\s*\/\/\s*([\w|\:\/\/|\.|\-|\_|\?|\&|\=]+)/gm.exec(this.vertexString);t&&t.length>1?this.mesh=t[1]:this.mesh=this.defaultMesh},n.createUniforms_=function(){var e=this.gl,r=this.fragmentString,i=e.drawingBufferWidth,n=e.drawingBufferHeight,o=this.timer=new st,s=(r.match(/u_delta/g)||[]).length>1,a=(r.match(/u_time/g)||[]).length>1,u=(r.match(/u_date/g)||[]).length>1,h=(r.match(/u_mouse/g)||[]).length>1,f=(r.match(/u_camera/g)||[]).length>1;this.animated=!0;var c=this.uniforms;if(c.create(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_resolution",[i,n]),s?(c.create(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_delta",[o.delta/1e3]),this.updateUniformDelta_=this.updateUniformDelta__):this.updateUniformDelta_=this.updateUniformNoop_,a?(c.create(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_time",[o.current/1e3]),this.updateUniformTime_=this.updateUniformTime__):this.updateUniformTime_=this.updateUniformNoop_,u){var l=new Date;c.create(t.UniformMethod.Uniform4f,t.UniformType.Float,"u_date",[l.getFullYear(),l.getMonth(),l.getDate(),3600*l.getHours()+60*l.getMinutes()+l.getSeconds()+.001*l.getMilliseconds()]),this.updateUniformDate_=this.updateUniformDate__}else this.updateUniformDate_=this.updateUniformNoop_;h?(c.create(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_mouse",[0,0]),this.updateUniformMouse_=this.updateUniformMouse__):this.updateUniformMouse_=this.updateUniformNoop_,f?(c.create(t.UniformMethod.Uniform3f,t.UniformType.Float,"u_camera",[0,0,0]),this.updateUniformCamera_=this.updateUniformCamera__):this.updateUniformCamera_=this.updateUniformNoop_,this.projectionMatrix=et(),c.create(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_projectionMatrix",this.projectionMatrix),this.modelViewMatrix=et(),c.create(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_modelViewMatrix",this.modelViewMatrix),this.normalMatrix=et(),c.create(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_normalMatrix",this.normalMatrix)},n.update_=function(){var e=this.gl,r=e.drawingBufferWidth,i=e.drawingBufferHeight;if(this.timer){var n=this.timer.next();this.uniforms.update(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_resolution",[r,i]),this.updateUniformDelta_(n),this.updateUniformTime_(n),this.updateUniformDate_(),this.updateUniformMouse_(),this.updateUniformCamera_(),this.updateUniformMesh_()}},n.updateUniformNoop_=function(){},n.updateUniformDelta__=function(e){this.uniforms.update(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_delta",[e.delta/1e3])},n.updateUniformTime__=function(e){this.uniforms.update(t.UniformMethod.Uniform1f,t.UniformType.Float,"u_time",[e.current/1e3])},n.updateUniformDate__=function(){var e=this.uniforms,r=new Date;e.update(t.UniformMethod.Uniform4f,t.UniformType.Float,"u_date",[r.getFullYear(),r.getMonth(),r.getDate(),3600*r.getHours()+60*r.getMinutes()+r.getSeconds()+.001*r.getMilliseconds()])},n.updateUniformMouse__=function(){var e=this.uniforms,r=this.mouse;e.update(t.UniformMethod.Uniform2f,t.UniformType.Float,"u_mouse",[r.x,r.y])},n.updateUniformCamera__=function(){var e=this.uniforms,r=Z.toArray(this.camera);e.update(t.UniformMethod.Uniform3f,t.UniformType.Float,"u_camera",r)},n.updateUniformMesh__=function(){var e=this.uniforms;e.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_projectionMatrix",this.updateProjectionMatrix_()),e.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_modelViewMatrix",this.updateModelViewMatrix_(this.timer.delta)),e.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_normalMatrix",this.updateNormalMatrix_(this.modelViewMatrix))},n.updateUniformFlat__=function(){var e=this.uniforms;e.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_projectionMatrix",et()),e.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_modelViewMatrix",et()),e.update(t.UniformMethod.UniformMatrix4fv,t.UniformType.Float,"u_normalMatrix",et())},n.updateProjectionMatrix_=function(){var t=this.gl,e=45*Math.PI/180,r=t.drawingBufferWidth/t.drawingBufferHeight;return function(t,e,r,i,n){var o,s=1/Math.tan(e/2);t[0]=s/r,t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=s,t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[11]=-1,t[12]=0,t[13]=0,t[15]=0,null!=n&&n!==1/0?(o=1/(i-n),t[10]=(n+i)*o,t[14]=2*n*i*o):(t[10]=-1,t[14]=-2*i)}(this.projectionMatrix,e,r,.1,100),this.projectionMatrix},n.updateModelViewMatrix_=function(t){var e,r,i,n,o,s,a,u,h,f,c,l,d,m,v,p,g,_,y=this.camera,x=this.modelViewMatrix;return x=rt(x),e=x,r=x,i=[0,0,-y.radius],p=i[0],g=i[1],_=i[2],r===e?(e[12]=r[0]*p+r[4]*g+r[8]*_+r[12],e[13]=r[1]*p+r[5]*g+r[9]*_+r[13],e[14]=r[2]*p+r[6]*g+r[10]*_+r[14],e[15]=r[3]*p+r[7]*g+r[11]*_+r[15]):(n=r[0],o=r[1],s=r[2],a=r[3],u=r[4],h=r[5],f=r[6],c=r[7],l=r[8],d=r[9],m=r[10],v=r[11],e[0]=n,e[1]=o,e[2]=s,e[3]=a,e[4]=u,e[5]=h,e[6]=f,e[7]=c,e[8]=l,e[9]=d,e[10]=m,e[11]=v,e[12]=n*p+u*g+l*_+r[12],e[13]=o*p+h*g+d*_+r[13],e[14]=s*p+f*g+m*_+r[14],e[15]=a*p+c*g+v*_+r[15]),it(x,x,y.theta+this.radians,[0,1,0]),it(x,x,y.phi,[1,0,0]),y.mouse||(y.theta+=(0-y.theta)/20,y.phi+=(0-y.phi)/20,this.radians+=5e-4*t),x},n.updateNormalMatrix_=function(t){var e,r,i,n,o,s,a,u,h,f,c,l,d,m,v,p,g,_,y,x,T,E,U,M,b,A,w,F,L,R,S,P=this.normalMatrix;return P=rt(P),e=P,i=(r=t)[0],n=r[1],o=r[2],s=r[3],a=r[4],u=r[5],h=r[6],f=r[7],c=r[8],l=r[9],d=r[10],m=r[11],v=r[12],p=r[13],g=r[14],_=r[15],(S=(y=i*u-n*a)*(R=d*_-m*g)-(x=i*h-o*a)*(L=l*_-m*p)+(T=i*f-s*a)*(F=l*g-d*p)+(E=n*h-o*u)*(w=c*_-m*v)-(U=n*f-s*u)*(A=c*g-d*v)+(M=o*f-s*h)*(b=c*p-l*v))&&(S=1/S,e[0]=(u*R-h*L+f*F)*S,e[1]=(o*L-n*R-s*F)*S,e[2]=(p*M-g*U+_*E)*S,e[3]=(d*U-l*M-m*E)*S,e[4]=(h*w-a*R-f*A)*S,e[5]=(i*R-o*w+s*A)*S,e[6]=(g*T-v*M-_*x)*S,e[7]=(c*M-d*T+m*x)*S,e[8]=(a*L-u*w+f*b)*S,e[9]=(n*w-i*L-s*b)*S,e[10]=(v*U-p*T+_*y)*S,e[11]=(l*T-c*U-m*y)*S,e[12]=(u*A-a*F-h*b)*S,e[13]=(i*F-n*A+o*b)*S,e[14]=(p*x-v*E-g*y)*S,e[15]=(c*E-l*x+d*y)*S),function(t,e){if(t===e){var r=e[1],i=e[2],n=e[3],o=e[6],s=e[7],a=e[11];t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=r,t[6]=e[9],t[7]=e[13],t[8]=i,t[9]=o,t[11]=e[14],t[12]=n,t[13]=s,t[14]=a}else t[0]=e[0],t[1]=e[4],t[2]=e[8],t[3]=e[12],t[4]=e[1],t[5]=e[5],t[6]=e[9],t[7]=e[13],t[8]=e[2],t[9]=e[6],t[10]=e[10],t[11]=e[14],t[12]=e[3],t[13]=e[7],t[14]=e[11],t[15]=e[15]}(P,P),P},n.setMode=function(t){var e,r=this;if(t===C.Mesh&&(e=this.cache[this.mesh]))return this.geometry=e,this.mode=C.Mesh,this.updateUniformMesh_=this.updateUniformMesh__,void(this.dirty=!0);switch(t){case C.Flat:e=new H,this.updateUniformMesh_=this.updateUniformNoop_,this.updateUniformFlat__();break;case C.Box:e=new ht,this.updateUniformMesh_=this.updateUniformMesh__;break;case C.Sphere:e=new ft,this.updateUniformMesh_=this.updateUniformMesh__;break;case C.Torus:e=new ct,this.updateUniformMesh_=this.updateUniformMesh__;break;case C.Mesh:e=new H,this.mesh?(new mt).load(O.getResource(this.mesh,this.workpath)).then((function(t){t.createAttributes_(r.gl,r.program);var e={};e[r.mesh]=t,r.cache=e,r.geometry=t,r.dirty=!0}),(function(t){I.warn("GlslCanvas",t),r.mode=C.Flat})):t=C.Flat,this.updateUniformMesh_=this.updateUniformMesh__}e.create(this.gl,this.program),this.geometry=e,this.mode=t,this.dirty=!0},n.setMesh=function(t){this.mesh=t},i}(ut),St=function(e){function i(t,r){var o;return void 0===r&&(r={}),(o=e.call(this)||this).valid=!1,o.visible=!1,o.controls=!1,o.vertexPath="",o.fragmentPath="",t?(o.options=r,o.canvas=t,o.width=0,o.height=0,o.rect=t.getBoundingClientRect(),o.devicePixelRatio=window.devicePixelRatio||1,o.mode=r.mode||C.Flat,o.mesh=r.mesh||void 0,o.doubleSided=r.doubleSided||!1,o.defaultMesh=o.mesh,o.workpath=r.workpath,t.style.backgroundColor=r.backgroundColor||"rgba(0,0,0,0)",o.getShaders_().then((function(t){o.load().then((function(t){o.program&&(o.addListeners_(),o.onLoop())}))}),(function(t){I.error("GlslCanvas.getShaders_.error",t)})),i.items.push(n(o)),o):n(o)}r(i,e);var o=i.prototype;return o.getShaders_=function(){var t=this;return new Promise((function(e){t.vertexString=t.options.vertexString||t.vertexString,t.fragmentString=t.options.fragmentString||t.fragmentString;var r=t.canvas,i={};r.hasAttribute("data-vertex-url")&&(i.vertex=r.getAttribute("data-vertex-url")),r.hasAttribute("data-fragment-url")&&(i.fragment=r.getAttribute("data-fragment-url")),r.hasAttribute("data-vertex")&&(t.vertexString=r.getAttribute("data-vertex")),r.hasAttribute("data-fragment")&&(t.fragmentString=r.getAttribute("data-fragment")),Object.keys(i).length?Promise.all(Object.keys(i).map((function(e){var r=O.getResource(i[e],t.workpath);return O.fetch(r).then((function(r){var n=O.dirname(i[e]);return"vertex"===e?(t.vertexPath=n,t.vertexString=r):(t.fragmentPath=n,t.fragmentString=r)}))}))).then((function(r){e([t.vertexString,t.fragmentString])})):e([t.vertexString,t.fragmentString])}))},o.addListeners_=function(){this.onScroll=this.onScroll.bind(this),this.onWheel=this.onWheel.bind(this),this.onClick=this.onClick.bind(this),this.onMove=this.onMove.bind(this),this.onMouseDown=this.onMouseDown.bind(this),this.onMouseMove=this.onMouseMove.bind(this),this.onMouseOver=this.onMouseOver.bind(this),this.onMouseOut=this.onMouseOut.bind(this),this.onMouseUp=this.onMouseUp.bind(this),this.onTouchMove=this.onTouchMove.bind(this),this.onTouchEnd=this.onTouchEnd.bind(this),this.onTouchStart=this.onTouchStart.bind(this),this.onLoop=this.onLoop.bind(this),window.addEventListener("scroll",this.onScroll),document.addEventListener("mousemove",this.onMouseMove,!1),document.addEventListener("touchmove",this.onTouchMove),this.addCanvasListeners_()},o.addCanvasListeners_=function(){this.controls=this.canvas.hasAttribute("controls"),this.canvas.addEventListener("wheel",this.onWheel),this.canvas.addEventListener("click",this.onClick),this.canvas.addEventListener("mousedown",this.onMouseDown),this.canvas.addEventListener("touchstart",this.onTouchStart),this.controls&&(this.canvas.addEventListener("mouseover",this.onMouseOver),this.canvas.addEventListener("mouseout",this.onMouseOut),this.canvas.hasAttribute("data-autoplay")||this.pause())},o.removeCanvasListeners_=function(){this.canvas.removeEventListener("wheel",this.onWheel),this.canvas.removeEventListener("click",this.onClick),this.canvas.removeEventListener("mousedown",this.onMouseDown),this.canvas.removeEventListener("mouseup",this.onMouseUp),this.canvas.removeEventListener("touchstart",this.onTouchStart),this.canvas.removeEventListener("touchend",this.onTouchEnd),this.controls&&(this.canvas.removeEventListener("mouseover",this.onMouseOver),this.canvas.removeEventListener("mouseout",this.onMouseOut))},o.removeListeners_=function(){window.cancelAnimationFrame(this.rafId),window.removeEventListener("scroll",this.onScroll),document.removeEventListener("mousemove",this.onMouseMove),document.removeEventListener("touchmove",this.onTouchMove),this.removeCanvasListeners_()},o.onScroll=function(t){this.rect=this.canvas.getBoundingClientRect()},o.onWheel=function(t){this.camera.wheel(t.deltaY),this.dirty=this.mode!==C.Flat,this.trigger("wheel",t)},o.onClick=function(t){this.controls&&this.toggle(),this.trigger("click",t)},o.onDown=function(t,e){var r=this.rect;t-=r.left,e=r.height-(e-r.top);var i=t*this.devicePixelRatio,n=e*this.devicePixelRatio;this.mouse.x=i,this.mouse.y=n;var o=Math.min(r.width,r.height);this.camera.down(t/o,e/o),this.trigger("down",this.mouse)},o.onMove=function(t,e){var r=this.rect;t-=r.left,e=r.height-(e-r.top);var i=t*this.devicePixelRatio,n=e*this.devicePixelRatio;if(i!==this.mouse.x||n!==this.mouse.y){this.mouse.x=i,this.mouse.y=n;var o=Math.min(r.width,r.height);this.camera.move(t/o,e/o),this.dirty=this.mode!==C.Flat&&null!==this.camera.mouse,this.trigger("move",this.mouse)}},o.onUp=function(t){this.camera.up(),this.controls&&this.pause(),this.trigger("out",t)},o.onMouseDown=function(t){this.onDown(t.clientX,t.clientY),document.addEventListener("mouseup",this.onMouseUp),document.removeEventListener("touchstart",this.onTouchStart),document.removeEventListener("touchmove",this.onTouchMove)},o.onMouseMove=function(t){this.onMove(t.clientX,t.clientY)},o.onMouseUp=function(t){this.onUp(t)},o.onMouseOver=function(t){this.play(),this.trigger("over",t)},o.onMouseOut=function(t){this.pause(),this.trigger("out",t)},o.onTouchStart=function(t){var e=[].slice.call(t.touches).reduce((function(t,e){return(t=t||new $).x+=e.clientX,t.y+=e.clientY,t}),null);e&&this.onDown(e.x/t.touches.length,e.y/t.touches.length),this.controls&&this.play(),this.trigger("over",t),document.addEventListener("touchend",this.onTouchEnd),document.removeEventListener("mousedown",this.onMouseDown),document.removeEventListener("mousemove",this.onMouseMove),this.controls&&(this.canvas.removeEventListener("mouseover",this.onMouseOver),this.canvas.removeEventListener("mouseout",this.onMouseOut))},o.onTouchMove=function(t){var e=[].slice.call(t.touches).reduce((function(t,e){return(t=t||new $).x+=e.clientX,t.y+=e.clientY,t}),null);e&&this.onMove(e.x/t.touches.length,e.y/t.touches.length)},o.onTouchEnd=function(t){this.onUp(t),document.removeEventListener("touchend",this.onTouchEnd)},o.onLoop=function(t){this.checkRender(),this.rafId=window.requestAnimationFrame(this.onLoop)},o.setUniform_=function(e,r,i,n){var o=this;void 0===i&&(i={}),void 0===n&&(n=null);var s=Lt.parseUniform(e,r,n);if(Array.isArray(s))Lt.isArrayOfSampler2D(s)?s.forEach((function(t){return o.loadTexture(t.key,t.values[0],i)})):s.forEach((function(t){return o.uniforms.set(t.key,t.values[0])}));else if(s)switch(s.type){case t.UniformType.Sampler2D:this.loadTexture(e,r[0],i);break;default:this.uniforms.set(e,s)}},o.isVisible_=function(){var t=this.rect;return t.top+t.height>0&&t.top<(window.innerHeight||document.documentElement.clientHeight)},o.isAnimated_=function(){return(this.animated||this.textures.animated||this.mode!==C.Flat)&&!this.timer.paused},o.isDirty_=function(){return this.dirty||this.uniforms.dirty||this.textures.dirty},o.sizeDidChanged_=function(){var t=this,e=this.gl,r=Math.ceil(this.canvas.clientWidth),i=Math.ceil(this.canvas.clientHeight);if(this.width!==r||this.height!==i){this.width=r,this.height=i;var n=Math.ceil(r*this.devicePixelRatio),o=Math.ceil(i*this.devicePixelRatio);return this.W=n,this.H=o,this.canvas.width=n,this.canvas.height=o,Object.keys(this.buffers.values).forEach((function(r){t.buffers.values[r].resize(e,n,o)})),this.rect=this.canvas.getBoundingClientRect(),this.trigger("resize"),!0}return!1},o.parseTextures_=function(t){for(var e,r=this,i=/uniform\s*sampler2D\s*([\w]*);(\s*\/\/\s*([\w|\:\/\/|\.|\-|\_|\?|\&|\=]*)|\s*)/gm;null!==(e=i.exec(t));){var n=e[1],o=e[3];Tt.isTextureUrl(o)?this.textureList.push({key:n,url:o}):this.buffers.has(n)||this.textureList.push({key:n,url:null})}this.canvas.hasAttribute("data-textures")&&this.canvas.getAttribute("data-textures").split(",").forEach((function(t,e){var i="u_texture"+e;r.textureList.push({key:i,url:t})}));return this.textureList.length>0},o.load=function(t,e){var r=this,i=V.getFragmentVertex(this.gl,t||this.fragmentString);return Promise.all([V.getIncludes(t||this.fragmentString,""===this.fragmentPath?this.workpath:this.fragmentPath),V.getIncludes(i||e||this.vertexString,""===this.vertexPath?this.workpath:this.vertexPath)]).then((function(t){return r.fragmentString=t[0],r.vertexString=t[1],r.createContext_()}))},o.getContext_=function(){var t=this.vertexString,e=this.fragmentString;if(this.vertexString=V.getVertex(t,e,this.mode),this.fragmentString=V.getFragment(t,e,this.mode),V.versionDiffers(this.gl,t,e)&&(this.destroyContext_(),this.swapCanvas_(),this.uniforms=new Lt,this.buffers=new K,this.textures=new Et,this.textureList=[]),!this.gl){var r=V.tryInferContext(t,e,this.canvas,this.options,this.options.extensions,this.options.onError);if(!r)return null;this.gl=r}return this.gl},o.createContext_=function(){var t,e,r=this.getContext_();if(!r)return!1;try{if(V.inferPrecision(this.fragmentString),t=V.createShader(r,this.vertexString,r.VERTEX_SHADER),e=V.createShader(r,this.fragmentString,r.FRAGMENT_SHADER))this.valid=!0;else{var i=V.getFragment(null,null,this.mode);e=V.createShader(r,i,r.FRAGMENT_SHADER),this.valid=!1}}catch(t){return this.trigger("error",t),!1}var n=V.createProgram(r,[t,e]);if(!n)return this.trigger("error",V.lastError),!1;if(r.deleteShader(t),r.deleteShader(e),this.program=n,this.valid){try{this.buffers=K.getBuffers(r,this.fragmentString,V.getBufferVertex(r))}catch(t){return this.valid=!1,this.trigger("error",t),!1}this.create_(),this.animated?this.canvas.classList.add("animated"):this.canvas.classList.remove("animated")}return this.trigger("load",this),this.valid},o.create_=function(){this.parseMode_(),this.parseMesh_(),e.prototype.create_.call(this),this.createBuffers_(),this.createTextures_()},o.parseMode_=function(){if(this.canvas.hasAttribute("data-mode")){var t=this.canvas.getAttribute("data-mode");-1!==["flat","box","sphere","torus","mesh"].indexOf(t)&&(this.mode=t)}},o.parseMesh_=function(){if(this.canvas.hasAttribute("data-mesh")){var t=this.canvas.getAttribute("data-mesh");-1!==t.indexOf(".obj")&&(this.mesh=this.defaultMesh=t)}},o.createBuffers_=function(){var e=this;Object.keys(this.buffers.values).forEach((function(r){var i=e.buffers.values[r];e.uniforms.create(t.UniformMethod.Uniform1i,t.UniformType.Sampler2D,i.key,[i.input.index])}))},o.createTextures_=function(){var t=this;this.parseTextures_(this.fragmentString)&&(this.textureList.filter((function(t){return t.url})).forEach((function(e){t.setTexture(e.key,e.url,e.options)})),this.textureList=[])},o.update_=function(){e.prototype.update_.call(this),this.updateBuffers_(),this.updateTextures_()},o.updateBuffers_=function(){var e=this;Object.keys(this.buffers.values).forEach((function(r){var i=e.buffers.values[r];e.uniforms.update(t.UniformMethod.Uniform1i,t.UniformType.Sampler2D,i.key,[i.input.index])}))},o.updateTextures_=function(){var e=this,r=this.gl;Object.keys(this.textures.values).forEach((function(i){var n=e.textures.values[i];n.tryUpdate(r),e.uniforms.update(t.UniformMethod.Uniform1i,t.UniformType.Sampler2D,n.key,[n.index])}))},o.destroyContext_=function(){var t=this,e=this.gl;e.useProgram(null),this.program&&e.deleteProgram(this.program),Object.keys(this.buffers.values).forEach((function(r){t.buffers.values[r].destroy(e)})),Object.keys(this.textures.values).forEach((function(r){t.textures.values[r].destroy(e)})),this.buffers=null,this.textures=null,this.uniforms=null,this.program=null,this.gl=null},o.swapCanvas_=function(){var t=this.canvas,e=t.cloneNode();t.parentNode.replaceChild(e,t),this.canvas=e,this.addCanvasListeners_()},o.destroy=function(){this.removeListeners_(),this.destroyContext_(),this.animated=!1,this.valid=!1;var t=i.items.indexOf(this);-1!==t&&i.items.splice(t,1)},o.loadTexture=function(e,r,i){var n=this;void 0===i&&(i={}),this.valid?this.textures.createOrUpdate(this.gl,e,r,this.buffers.count,i,this.options.workpath).then((function(r){var i=r.index;n.uniforms.createTexture(e,i).texture=r;var o=-1!==e.indexOf("[")?e.replace("[","Resolution["):e+"Resolution";return n.uniforms.create(t.UniformMethod.Uniform2f,t.UniformType.Float,o,[r.width,r.height]),r}),(function(t){var i=Array.isArray(t.path)?t.path.map((function(t){return t.error?t.error.message:""})).join(", "):t.message;I.error("GlslCanvas.loadTexture.error",e,r,i),n.trigger("textureError",{key:e,urlElementOrData:r,message:i})})):this.textureList.push({key:e,url:r,options:i})},o.setTexture=function(t,e,r){return void 0===r&&(r={}),this.setUniform_(t,[e],r)},o.setUniform=function(t){for(var e=arguments.length,r=new Array(e>1?e-1:0),i=1;i<e;i++)r[i-1]=arguments[i];return this.setUniform_(t,r)},o.setUniformOfInt=function(e,r){return this.setUniform_(e,r,null,t.UniformType.Int)},o.setUniforms=function(t){var e=this;Object.keys(t).forEach((function(r){e.setUniform(r,t[r])}))},o.pause=function(){this.valid&&(this.timer.pause(),this.canvas.classList.add("paused"),this.trigger("pause"))},o.play=function(){this.valid&&(this.timer.play(),this.canvas.classList.remove("paused"),this.trigger("play"))},o.toggle=function(){this.valid&&(this.timer.paused?this.play():this.pause())},o.checkRender=function(){this.isVisible_()&&(this.sizeDidChanged_()||this.isDirty_()||this.isAnimated_())?(this.render(),this.canvas.classList.add("playing")):this.canvas.classList.remove("playing")},i}(Rt);function Pt(t,e){return St.items.find((function(e){return e.canvas===t}))||new St(t,e)}function Ot(){return[].slice.call(document.getElementsByClassName("glsl-canvas")).filter((function(t){return t instanceof HTMLCanvasElement})).map((function(t){return Pt(t)}))}St.items=[],"object"==typeof window&&document.addEventListener("DOMContentLoaded",(function(){Ot()})),t.BoxGeometry=ht,t.Buffer=Y,t.Buffers=K,t.Canvas=St,t.CanvasTimer=st,t.Common=O,t.Context=V,t.ContextVertexBuffers=W,t.DefaultWebGL2BufferFragment=T,t.DefaultWebGL2BufferVertex=y,t.DefaultWebGL2FlatFragment=v,t.DefaultWebGL2MeshFragment=g,t.DefaultWebGL2MeshVertex=d,t.DefaultWebGLBufferFragment=x,t.DefaultWebGLBufferVertex=_,t.DefaultWebGLFlatFragment=m,t.DefaultWebGLMeshFragment=p,t.DefaultWebGLMeshVertex=l,t.FlatGeometry=H,t.Geometry=j,t.IOBuffer=q,t.IterableStringMap=X,t.Listener=at,t.Logger=I,t.METHODS_FLOAT=Mt,t.METHODS_FLOATV=At,t.METHODS_INT=Ut,t.METHODS_INTV=bt,t.ObjLoader=mt,t.OrbitCamera=Z,t.Renderer=Rt,t.SphereGeometry=ft,t.Subscriber=ut,t.Texture=Tt,t.TextureExtensions=gt,t.TextureImageExtensions=vt,t.TextureVideoExtensions=pt,t.Textures=Et,t.TorusGeometry=ct,t.Uniform=wt,t.UniformTexture=Ft,t.Uniforms=Lt,t.Vector2=$,t.Vector3=J,t.isTextureData=_t,t.loadAll=Ot,t.of=Pt,Object.defineProperty(t,"__esModule",{value:!0})}));
  //# sourceMappingURL=glsl-canvas.min.js.map