@bddh/starling-cutout
Version:
cutout
1 lines • 75.9 kB
JavaScript
"use strict";var t,e,i,r=require("../_virtual/_rollupPluginBabelHelpers.js"),n=require("../_virtual/seriously.js");t=n.__module,e=window,i=function(t){var e,i,n,s,o,a,u,h,f=t.document,c=t.console,l={},d={},p={},m={},y=[],g={},v={},x={canvas:[],image:[],video:[]},E={},b=t.WeakMap&&new WeakMap,T=0,w=function(){},R={transparent:[0,0,0,0],black:[0,0,0,1],red:[1,0,0,1],green:[0,128/255,0,1],blue:[0,0,1,1],white:[1,1,1,1],silver:[192/255,192/255,192/255,1],gray:[128/255,128/255,128/255,1],maroon:[128/255,0,0,1],purple:[128/255,0,128/255,1],fuchsia:[1,0,1,1],lime:[0,1,0,1],olive:[128/255,128/255,0,1],yellow:[1,1,0,1],navy:[0,0,128/255,1],teal:[0,128/255,128/255,1],aqua:[0,1,1,1],orange:[1,165/255,0,1]},D=/^(rgb|hsl)a?\(\s*(\d+)\s*,\s*(\d+)\s*,\s*(\d+)\s*(,\s*(\d+(\.\d*)?)\s*)?\)/i,A=/^#(([0-9a-fA-F]{3,8}))/,_=["x","y","z","w"],N=["r","g","b","a"],P={srcRGB:770,dstRGB:771,srcAlpha:1,dstAlpha:771},F=["MAX_COMBINED_TEXTURE_IMAGE_UNITS","MAX_FRAGMENT_UNIFORM_VECTORS","MAX_TEXTURE_IMAGE_UNITS","MAX_VARYING_VECTORS","MAX_VERTEX_ATTRIBS","MAX_VERTEX_TEXTURE_IMAGE_UNITS","MAX_VERTEX_UNIFORM_VECTORS"],O=/^[\t ]*#define[\t ]+SHADER_NAME\s+([^$\n\r]+)/i,U={frustum:function(t,e,i,r,n,s,o){o||(o=U.create());var a=e-t,u=r-i,h=s-n;return o[0]=2*n/a,o[1]=0,o[2]=0,o[3]=0,o[4]=0,o[5]=2*n/u,o[6]=0,o[7]=0,o[8]=(e+t)/a,o[9]=(r+i)/u,o[10]=-(s+n)/h,o[11]=-1,o[12]=0,o[13]=0,o[14]=-s*n*2/h,o[15]=0,o},perspective:function(t,e,i,r,n){var s=i*Math.tan(t*Math.PI/360),o=s*e;return U.frustum(-o,o,-s,s,i,r,n)},multiply:function(t,e,i){var r=e[0],n=e[1],s=e[2],o=e[3],a=e[4],u=e[5],h=e[6],f=e[7],c=e[8],l=e[9],d=e[10],p=e[11],m=e[12],y=e[13],g=e[14],v=e[15],x=i[0],E=i[1],b=i[2],T=i[3];return t[0]=x*r+E*a+b*c+T*m,t[1]=x*n+E*u+b*l+T*y,t[2]=x*s+E*h+b*d+T*g,t[3]=x*o+E*f+b*p+T*v,x=i[4],E=i[5],b=i[6],T=i[7],t[4]=x*r+E*a+b*c+T*m,t[5]=x*n+E*u+b*l+T*y,t[6]=x*s+E*h+b*d+T*g,t[7]=x*o+E*f+b*p+T*v,x=i[8],E=i[9],b=i[10],T=i[11],t[8]=x*r+E*a+b*c+T*m,t[9]=x*n+E*u+b*l+T*y,t[10]=x*s+E*h+b*d+T*g,t[11]=x*o+E*f+b*p+T*v,x=i[12],E=i[13],b=i[14],T=i[15],t[12]=x*r+E*a+b*c+T*m,t[13]=x*n+E*u+b*l+T*y,t[14]=x*s+E*h+b*d+T*g,t[15]=x*o+E*f+b*p+T*v,t},identity:function(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},copy:function(t,e){return t[0]=e[0],t[1]=e[1],t[2]=e[2],t[3]=e[3],t[4]=e[4],t[5]=e[5],t[6]=e[6],t[7]=e[7],t[8]=e[8],t[9]=e[9],t[10]=e[10],t[11]=e[11],t[12]=e[12],t[13]=e[13],t[14]=e[14],t[15]=e[15],t}},B=(h=0,t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||function(e){var i,r,n;function s(){e(i+r)}return i=(new Date).getTime(),r=Math.max(0,16-(i-h)),n=t.setTimeout(s,r),h=i+r,n}),L=t.cancelAnimationFrame||t.webkitCancelAnimationFrame||t.mozCancelAnimationFrame||t.oCancelAnimationFrame||t.msCancelAnimationFrame||function(e){t.cancelTimeout(e)},S=["alias","destroy","effect","id","initialize","inputs","isDestroyed","isReady","matte","off","on","readPixels","render","title","update"],I=["alias","destroy","id","inputs","isDestroyed","isReady","off","on","source","title","update"],C=["aliases","defaults","destroy","effect","go","id","incompatible","isDestroyed","isEffect","isNode","isSource","isTarget","isTransform","removeAlias","render","source","stop","target","transform"];function M(t,e){var i,r;if("string"==typeof t)i=f.querySelector(t);else if(!t)return!1;return t.tagName&&(i=t),i?(r=i.tagName.toLowerCase(),e&&e.indexOf(r)<0?t:i):t}function z(t,e){var i,r;for(i in t.prototype&&e.prototype&&t.prototype!==e.prototype&&z(t.prototype,e.prototype),e)e.hasOwnProperty(i)&&((r=Object.getOwnPropertyDescriptor(e,i)).get||r.set?Object.defineProperty(t,i,{configurable:!0,enumerable:!0,get:r.get,set:r.set}):t[i]=e[i]);return t}function G(t){var e;if(!c)return w;if("function"==typeof c[t])e=c[t];else{if("function"!=typeof c.log)return w;e=c.log}return e.bind?e.bind(c):function(){e.apply(c,arguments)}}function k(e,i){if(i||(i="HTMLElement"),!t[i])return c.error("window[proto] is undefined, proto:",i),!1;if(e instanceof t[i])return!0;if(!e||"object"!==r.typeof(e))return!1;for(;e;)if((e=Object.getPrototypeOf(e))&&e.constructor.name===i)return!0;return!1}function X(t,e,i,r,n){function s(t,e,i){return(i%=1)<0&&(i+=1),i<1/6?t+(e-t)*i*6:i<.5?e:i<2/3?t+(e-t)*(2/3-i)*6:t}var o,a;return o=2*i-(a=i<.5?i*(e+1):i+e-i*e),n||(n=[]),n[0]=s(o,a,t+1/3),n[1]=s(o,a,t),n[2]=s(o,a,t-1/3),n[3]=r,n}function j(t){var e,i,r,n="#",s=t[3]<1?4:3;for(e=0;e<s;e++)r=(i=Math.min(255,Math.round(255*t[e]||0))).toString(16),i<16&&(r="0"+r),n+=r;return n}function W(t){return Array.isArray(t)||t&&t.BYTES_PER_ELEMENT&&"length"in t}function V(e){function i(){y.length&&y.shift()()}if("function"!=typeof e)throw new Error("setTimeoutZero argument is not a function");y.push(e),"file:"!==t.location.protocol?t.postMessage("seriously-timeout-message",t.location):setTimeout(i,0)}function H(e,i){var r;try{r=t.WebGLDebugUtils&&i&&i.debugContext?t.WebGLDebugUtils.makeDebugContext(e.getContext("webgl",i)):e.getContext("webgl",i)}catch(t){}if(!r)try{r=e.getContext("experimental-webgl",i)}catch(t){}return r}function Y(){var i;return e&&e.getError()===e.CONTEXT_LOST_WEBGL&&(e=void 0),e||!t.WebGLRenderingContext||n||(i=f.createElement("canvas"),(e=H(i))?i.addEventListener("webglcontextlost",(function t(r){r.preventDefault(),e&&e.canvas===this&&(e=void 0,i.removeEventListener("webglcontextlost",t,!1))}),!1):J.logger.warn("Unable to access WebGL.")),e}function q(e){var i,r,n,s;if(!(i=M(e,["img","canvas","video"])))return!1;if(!(r=f.createElement("canvas")))return J.logger.warn("Browser does not support canvas or Seriously.js"),!1;if(0===i.naturalWidth&&"IMG"===i.tagName)return J.logger.warn("Image not loaded"),!1;if(0===i.readyState&&0===i.videoWidth&&"VIDEO"===i.tagName)return J.logger.warn("Video not loaded"),!1;if(n=Y()){(s=n.createTexture())||J.logger.error("Test WebGL context has been lost"),n.bindTexture(n.TEXTURE_2D,s);try{n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,i)}catch(e){return e.code===t.DOMException.SECURITY_ERR?J.logger.log("Unable to access cross-domain image"):J.logger.error("Error storing image to texture: "+e.message),n.deleteTexture(s),!1}n.deleteTexture(s)}else{n=r.getContext("2d");try{n.drawImage(i,0,0),n.getImageData(0,0,1,1)}catch(e){return e.code===t.DOMException.SECURITY_ERR?J.logger.log("Unable to access cross-domain image"):J.logger.error("Error drawing image to canvas: "+e.message),!1}}return!0}function Z(t){var e,i,r;function n(t,r){var n,s;W(t)?(n=t[0],s=t[1]||n):n=t,"string"==typeof n?n=n.toLowerCase():"number"==typeof n?n=String(n):n||(n=""),i[n]=s,r||(e.firstValue=n)}function s(t){return t}for(r in t.inputs)if(t.inputs.hasOwnProperty(r)){if(t.reserved.indexOf(r)>=0||Object.prototype[r])throw new Error("Reserved input name: "+r);(e=t.inputs[r]).name=r,isNaN(e.min)&&(e.min=-1/0),isNaN(e.max)&&(e.max=1/0),isNaN(e.minCount)&&(e.minCount=-1/0),isNaN(e.maxCount)&&(e.maxCount=1/0),isNaN(e.step)&&(e.step=0),isNaN(e.mod)&&(e.mod=0),"enum"===e.type&&e.options&&W(e.options)&&e.options.length&&(i={},e.options.forEach(n),e.options=i),"vector"===e.type?e.dimensions<2?e.dimensions=2:e.dimensions>4||!e.dimensions||isNaN(e.dimensions)?e.dimensions=4:e.dimensions=Math.round(e.dimensions):e.dimensions=1,e.shaderDirty=!!e.shaderDirty,"function"!=typeof e.validate&&(e.validate=J.inputValidators[e.type]||s),t.defaultImageInput||"image"!==e.type||(t.defaultImageInput=r)}}function K(t,e,i,r){var n,s,o,a,u=!0===r?r:r&&r.useFloat;u=!1,this.type=u?t.FLOAT:t.UNSIGNED_BYTE,n=t.createFramebuffer(),t.bindFramebuffer(t.FRAMEBUFFER,n),r&&r.texture?(this.texture=r.texture,t.bindTexture(t.TEXTURE_2D,this.texture),this.ownTexture=!1):(this.texture=t.createTexture(),t.bindTexture(t.TEXTURE_2D,this.texture),t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MAG_FILTER,t.LINEAR),t.texParameteri(t.TEXTURE_2D,t.TEXTURE_MIN_FILTER,t.LINEAR),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.ownTexture=!0);try{this.type===t.FLOAT?(o=new Float32Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.FLOAT,o)):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,null),this.type=t.UNSIGNED_BYTE)}catch(r){this.type=t.UNSIGNED_BYTE,o=new Uint8Array(e*i*4),t.texImage2D(t.TEXTURE_2D,0,t.RGBA,e,i,0,t.RGBA,t.UNSIGNED_BYTE,o)}if(s=t.createRenderbuffer(),t.bindRenderbuffer(t.RENDERBUFFER,s),t.renderbufferStorage(t.RENDERBUFFER,t.DEPTH_COMPONENT16,e,i),t.framebufferRenderbuffer(t.FRAMEBUFFER,t.DEPTH_ATTACHMENT,t.RENDERBUFFER,s),t.framebufferTexture2D(t.FRAMEBUFFER,t.COLOR_ATTACHMENT0,t.TEXTURE_2D,this.texture,0),(a=t.checkFramebufferStatus(t.FRAMEBUFFER))===t.FRAMEBUFFER_INCOMPLETE_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_MISSING_ATTACHMENT");if(a===t.FRAMEBUFFER_INCOMPLETE_DIMENSIONS)throw new Error("Incomplete framebuffer: FRAMEBUFFER_INCOMPLETE_DIMENSIONS");if(a===t.FRAMEBUFFER_UNSUPPORTED)throw new Error("Incomplete framebuffer: FRAMEBUFFER_UNSUPPORTED");if(a!==t.FRAMEBUFFER_COMPLETE)throw new Error("Incomplete framebuffer: "+a);t.bindTexture(t.TEXTURE_2D,null),t.bindRenderbuffer(t.RENDERBUFFER,null),t.bindFramebuffer(t.FRAMEBUFFER,null),this.gl=t,this.frameBuffer=n,this.renderBuffer=s,this.width=e,this.height=i}function $(t,e,i){var r,n,s,o,a,u,h,f,c="";function l(e,i){var r,n;if(r=i?t.createShader(t.FRAGMENT_SHADER):t.createShader(t.VERTEX_SHADER),t.shaderSource(r,e),t.compileShader(r),!t.getShaderParameter(r,t.COMPILE_STATUS)){for(e=e.split(/[\n\r]/),n=0;n<e.length;n++)e[n]=n+1+":\t"+e[n];throw e.unshift("Error compiling "+(i?"fragment":"vertex")+" shader:"),J.logger.error(e.join("\n")),new Error("Shader error: "+t.getShaderInfoLog(r))}return r}function d(e,i){if(e.type===t.SAMPLER_2D)return function(r){e.glTexture=t["TEXTURE"+r],t.uniform1i(i,r)};if(e.type===t.BOOL||e.type===t.INT)return e.size>1?function(e){t.uniform1iv(i,e)}:function(e){t.uniform1i(i,e)};if(e.type===t.FLOAT)return e.size>1?function(e){t.uniform1fv(i,e)}:function(e){t.uniform1f(i,e)};if(e.type===t.FLOAT_VEC2)return function(e){t.uniform2f(i,e[0],e[1])};if(e.type===t.FLOAT_VEC3)return function(e){t.uniform3f(i,e[0],e[1],e[2])};if(e.type===t.FLOAT_VEC4)return function(e){t.uniform4f(i,e[0],e[1],e[2],e[3])};if(e.type===t.FLOAT_MAT3)return function(e){t.uniformMatrix3fv(i,!1,e)};if(e.type===t.FLOAT_MAT4)return function(e){t.uniformMatrix4fv(i,!1,e)};throw new Error("Unknown shader uniform type: "+e.type)}function p(e){return function(){return t.getUniform(r,e)}}if(n=l(e),s=l(i,!0),r=t.createProgram(),t.attachShader(r,n),(o=t.getShaderInfoLog(n))&&(c+="Vertex shader error: "+o+"\n"),t.attachShader(r,s),(o=t.getShaderInfoLog(s))&&(c+="Fragment shader error: "+o+"\n"),t.linkProgram(r),!t.getProgramParameter(r,t.LINK_STATUS))throw c+=t.getProgramInfoLog(r),t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s),(h=O.exec(e)||O.exec(i))&&(c="Shader = "+h[1]+"\n"+c),F.forEach((function(e){c+="\n"+e+": "+t.getParameter(t[e])})),new Error("Could not initialize shader:\n"+c);for(t.useProgram(r),this.uniforms={},u=t.getProgramParameter(r,t.ACTIVE_UNIFORMS),a=0;a<u;++a)(f={info:t.getActiveUniform(r,a)}).name=f.info.name.replace(/\[0\]$/,""),f.loc=t.getUniformLocation(r,f.name),f.set=d(f.info,f.loc),f.get=p(f.loc),this.uniforms[f.name]=f,this[f.name]||(this[f.name]=f);for(this.attributes={},this.location={},u=t.getProgramParameter(r,t.ACTIVE_ATTRIBUTES),a=0;a<u;++a)(f={info:t.getActiveAttrib(r,a)}).name=f.info.name,f.location=t.getAttribLocation(r,f.name),this.attributes[f.name]=f,this.location[f.name]=f.location;this.gl=t,this.program=r,this.destroy=function(){var e;for(e in t&&(t.deleteProgram(r),t.deleteShader(n),t.deleteShader(s)),this)this.hasOwnProperty(e)&&delete this[e];r=null,n=null,s=null}}function J(e){if(t===this||!(this instanceof J)||void 0!==this.id)return new J(e);var i,n,o,h,c,y,E,R,D,A,_,N,F,S,I,G=++T,X=this,W=[],Y={},q=0,Q=[],tt=[],et=[],it=[],rt={},nt=[],st=[],ot={},at={},ut=!1,ht=!1,ft=null;function ct(t,e){var i,r,n;return!!e&&(i=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,i),e.bufferData(e.ARRAY_BUFFER,t.vertices,e.STATIC_DRAW),i.size=3,r=e.createBuffer(),e.bindBuffer(e.ELEMENT_ARRAY_BUFFER,r),e.bufferData(e.ELEMENT_ARRAY_BUFFER,t.indices,e.STATIC_DRAW),n=e.createBuffer(),e.bindBuffer(e.ARRAY_BUFFER,n),e.bufferData(e.ARRAY_BUFFER,t.coords,e.STATIC_DRAW),n.size=2,{vertex:i,index:r,texCoord:n,length:t.indices.length,mode:t.mode||e.TRIANGLES})}function lt(t){var e={};return e.vertices=new Float32Array([-1,-1,0,1,-1,0,1,1,0,-1,1,0]),e.indices=new Uint16Array([0,1,2,0,2,3]),e.coords=new Float32Array([0,0,1,0,1,1,0,1]),ct(e,t)}function dt(){J.logger.warn("WebGL context lost. 5 seconds to restore context."),ft&&clearTimeout(ft),ft=setTimeout(mt,5e3)}function pt(t){var e,r;if(!n)if(t.canvas.addEventListener("webglcontextlost",yt,!1),t.canvas.addEventListener("webglcontextrestored",mt,!1),t.isContextLost())J.logger.warn("Unable to attach lost WebGL context. Will try again when context is restored.");else{for(n=t,i=t.canvas,h=lt(n),c=new $(n,"#define SHADER_NAME seriously.base\n"+a,"#define SHADER_NAME seriously.base\n"+u),e=0;e<it.length;e++)(r=it[e]).gl=n,r.initialize(),r.buildShader();for(e=0;e<Q.length;e++)(r=Q[e]).initialize();for(e=0;e<tt.length;e++)(r=tt[e]).model||(r.model=h,r.shader=c)}}function mt(){var t,e,i,r;if(ft&&clearTimeout(ft),ft=null,o&&!n){if(k(e=o.target,"WebGLFramebuffer"))return void J.logger.error("Unable to restore target built on WebGLFramebuffer");if(t=H(e,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:o.debugContext})){if(t.isContextLost())return ft?void J.logger.error("restore WebGL Context ing, wait...."):(dt(),void J.logger.error("Unable to restore WebGL Context"));for(pt(t),o.renderToTexture?o.frameBuffer=new K(n,o.width,o.height,!1):o.frameBuffer={frameBuffer:null},i=0;i<W.length;i++)(r=W[i]).setDirty(),r.emit("webglcontextrestored");J.logger.log("WebGL context restored")}}}function yt(t){var e,r;for(t?(t.preventDefault(),dt()):ft&&clearTimeout(ft),I&&(L(I),I=0),i&&i.removeEventListener("webglcontextlost",yt,!1),e=0;e<it.length;e++)(r=it[e]).gl=null,r.initialized=!1,r.baseShader=null,r.model=null,r.frameBuffer=null,r.texture=null,r.shader&&r.shader.destroy&&(r.shader.destroy(),r.effect.commonShader&&delete at[r.hook]),r.shaderDirty=!0,r.shader=null,r.effect.lostContext&&r.effect.lostContext.call(r),t&&r.emit("webglcontextlost");for(e=0;e<Q.length;e++)(r=Q[e]).texture=null,r.initialized=!1,r.allowRefresh=!1,t&&r.emit("webglcontextlost");for(e=0;e<et.length;e++)(r=et[e]).frameBuffer=null,r.texture=null,t&&r.emit("webglcontextlost");for(e=0;e<tt.length;e++)(r=tt[e]).model=!1,r.frameBuffer=null,t&&r.emit("webglcontextlost");c&&c.destroy&&c.destroy(),n&&(n.deleteBuffer(h.vertex),n.deleteBuffer(h.texCoord),n.deleteBuffer(h.index)),h&&(delete h.vertex,delete h.texCoord,delete h.index),h=null,c=null,n=null,i=null}function gt(t){var e,i,r=!1;if(I=0,nt.length)for(r=!0,e=0;e<nt.length;e++)nt[e].call(X,t);if(Q&&Q.length)for(r=!0,e=0;e<Q.length;e++){var n=(i=Q[e]).source&&i.source.dataset&&i.source.dataset.playing;if("string"==typeof n&&"true"!==n)return void(I=B(gt));(i.dirty||i.checkDirty&&i.checkDirty())&&(i.dirty=!1,i.setDirty())}for(e=0;e<tt.length;e++)(i=tt[e]).auto&&i.dirty&&i.render();if(st.length)for(r=!0,e=0;e<st.length;e++)st[e].call(X);r&&!I&&(I=B(gt))}function vt(t,e,i,r,s,o){var a,u,h,f,c,l,d,p,m,y=0,g=s&&s.gl||n;if(g){for(a in s?(f=o&&o.width||s.width||g.canvas.width,c=o&&o.height||s.height||g.canvas.height):(f=o&&o.width||g.canvas.width,c=o&&o.height||g.canvas.height),t.use(),g.viewport(0,0,f,c),g.bindFramebuffer(g.FRAMEBUFFER,r),g.enableVertexAttribArray(t.location.position),g.enableVertexAttribArray(t.location.texCoord),e.texCoord&&(g.bindBuffer(g.ARRAY_BUFFER,e.texCoord),g.vertexAttribPointer(t.location.texCoord,e.texCoord.size,g.FLOAT,!1,0,0)),g.bindBuffer(g.ARRAY_BUFFER,e.vertex),g.vertexAttribPointer(t.location.position,e.vertex.size,g.FLOAT,!1,0,0),g.bindBuffer(g.ELEMENT_ARRAY_BUFFER,e.index),o&&o.depth?n.enable(n.DEPTH_TEST):n.disable(n.DEPTH_TEST),o?void 0===o.blend||o.blend?(n.enable(n.BLEND),l=void 0===o.srcRGB?n.ONE:o.srcRGB,p=o.dstRGB||n.ZERO,d=void 0===o.srcAlpha?l:o.srcAlpha,m=void 0===o.dstAlpha?p:o.dstAlpha,n.blendFuncSeparate(l,p,d,m),n.blendEquation(o.blendEquation||n.FUNC_ADD)):n.disable(n.BLEND):(n.enable(n.BLEND),n.blendFunc(n.ONE,n.ZERO),n.blendEquation(n.FUNC_ADD)),i)i.hasOwnProperty(a)&&(u=i[a],(h=t.uniforms[a])&&(k(u,"WebGLTexture")?(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,u),h.set(y),y++):u instanceof E||u instanceof R||u instanceof D?u.texture&&(g.activeTexture(g.TEXTURE0+y),g.bindTexture(g.TEXTURE_2D,u.texture),h.set(y),y++):null!=u&&h.set(u)));o&&void 0!==o.clear&&!o.clear||(g.clearColor(0,0,0,0),g.clear(g.COLOR_BUFFER_BIT|g.DEPTH_BUFFER_BIT)),g.drawElements(e.mode,e.length,g.UNSIGNED_SHORT,0),n.enable(n.DEPTH_TEST)}}function xt(t,e,i){var n,s;if(("string"!=typeof t||!e&&0!==e)&&(i&&"object"===r.typeof(i)||(i=e),e=t),"string"==typeof t&&p[t]||(t=null),e instanceof E||e instanceof R||e instanceof D)n=e;else if(e instanceof _||e instanceof N||e instanceof F){if(!(n=Y[e.id]))throw new Error("Cannot connect a foreign node")}else{for("string"==typeof e&&isNaN(e)&&(e=M(e,["canvas","img","video"])),s=0;s<Q.length;s++)if(n=Q[s],(!t||t===n.hook)&&n.compare&&n.compare(e,i))return n;n=new E(t,e,i)}return n}function Et(t,e){var i,r,n;if(!(t instanceof R||t instanceof D))return!1;if(t===e)return!0;for(i in n=t.sources)if(n.hasOwnProperty(i)&&((r=n[i])===e||Et(r,e)))return!0;return!1}(y=function(){this.ready=!1,this.width=1,this.height=1,this.gl=n,this.uniforms={resolution:[this.width,this.height],transform:null},this.dirty=!0,this.isDestroyed=!1,this.seriously=X,this.listeners={},this.id=q,q++}).prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},y.prototype.setUnready=function(){var t;if(this.ready&&(this.ready=!1,this.emit("unready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setUnready()},y.prototype.setDirty=function(){var t;if(!this.dirty&&(this.emit("dirty"),this.dirty=!0,this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setDirty()},y.prototype.initFrameBuffer=function(t){n&&(this.frameBuffer=new K(n,this.width,this.height,t))},y.prototype.readPixels=function(t,e,i,r,s){var o=this.gl||n;if(!n)throw new Error("Cannot read pixels until a canvas is connected");if(this.frameBuffer||(this.initFrameBuffer(),this.setDirty()),this.render(),void 0===s)s=new Uint8Array(i*r*4);else if(!k(s,"Uint8Array"))throw new Error("Incompatible array type");return o.bindFramebuffer(n.FRAMEBUFFER,this.frameBuffer.frameBuffer),o.readPixels(t,e,i,r,n.RGBA,n.UNSIGNED_BYTE,s),s},y.prototype.resize=function(){var t,e;this.source?(t=this.source.width,e=this.source.height):this.sources&&this.sources.source?(t=this.sources.source.width,e=this.sources.source.height):this.inputs&&this.inputs.width?(t=this.inputs.width,e=this.inputs.height||t):this.inputs&&this.inputs.height?t=e=this.inputs.height:(t=1,e=1),t=Math.floor(t),e=Math.floor(e),this.width===t&&this.height===e||(this.width=t,this.height=e,this.emit("resize"),this.setDirty()),this.uniforms&&this.uniforms.resolution&&(this.uniforms.resolution[0]=t,this.uniforms.resolution[1]=e),this.frameBuffer&&this.frameBuffer.resize&&this.frameBuffer.resize(t,e)},y.prototype.on=function(t,e){var i,r=-1;t&&"function"==typeof e&&((i=this.listeners[t])?r=i.indexOf(e):i=this.listeners[t]=[],r<0&&i.push(e))},y.prototype.off=function(t,e){var i,r=-1;t&&"function"==typeof e&&(i=this.listeners[t])&&(r=i.indexOf(e))>=0&&i.splice(r,1)},y.prototype.emit=function(t){var e,i=this.listeners[t];if(i&&i.length)for(e=0;e<i.length;e++)V(i[e])},y.prototype.destroy=function(){var t,e;for(e in delete this.gl,delete this.seriously,this.listeners)this.listeners.hasOwnProperty(e)&&delete this.listeners[e];for(t in this.uniforms)this.uniforms.hasOwnProperty(t)&&delete this.uniforms[t];this.targets&&delete this.targets,this.frameBuffer&&this.frameBuffer.destroy&&(this.frameBuffer.destroy(),delete this.frameBuffer),(t=W.indexOf(this))>=0&&W.splice(t,1),delete Y[this.id],this.isDestroyed=!0},_=function(t){var e,i=t;function r(t,e){var r,n,s;return s=i.effect.inputs[t],r=i.inputElements[t],"string"==typeof e&&isNaN(e)&&("enum"===s.type?s.options.hasOwnProperty(e)||(e=M(e,["select"])):"number"===s.type||"boolean"===s.type?e=M(e,["input","select"]):"image"===s.type&&(e=M(e,["canvas","img","video"]))),k(e,"HTMLInputElement")||k(e,"HTMLSelectElement")?(n=e.value,r&&r.element!==e&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t],r=null),r||(r={element:e,listener:function(t,r){return function(){var n,o;n="checkbox"===e.type?e.checked:r.value,o=i.setInput(t,n),"color"===s.type&&(o=j(o).substr(0,7)),o!==n&&(r.value=o)}}(t,e)},i.inputElements[t]=r,"range"===e.type?(e.addEventListener("input",r.listener,!0),e.addEventListener("change",r.listener,!0)):e.addEventListener("change",r.listener,!0)),r&&"checkbox"===e.type&&(n=e.checked)):(r&&(r.element.removeEventListener("change",r.listener,!0),r.element.removeEventListener("input",r.listener,!0),delete i.inputElements[t]),n=e),i.setInput(t,n),i.inputs[t]}function n(t){return function(e){var i=r(t,e);return i&&i.pub}}function s(t){return function(){var e=i.inputs[t];return e&&e.pub}}function o(t){return function(e){return r(t,e)}}function a(t){return function(){return i.inputs[t]}}for(e in i.effect.inputs)if(i.effect.inputs.hasOwnProperty(e)){if(void 0!==this[e])throw new Error("Cannot overwrite Seriously."+e);"image"===i.effect.inputs[e].type?Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:s(e),set:n(e)}):Object.defineProperty(this,e,{configurable:!0,enumerable:!0,get:a(e),set:o(e)})}Object.defineProperties(this,{effect:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.effect.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}}}),this.render=function(){return i.render(),this},this.readPixels=function(t,e,r,n,s){return i.readPixels(t,e,r,n,s)},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.inputs=function(t){var e,r,n,s;if(n=i.effect.inputs,t)return(r=n[t])?(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=z({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e):null;for(s in e={},n)n.hasOwnProperty(s)&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.matte=function(t){i.matte(t)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},R=function(t,e){var i,r,o,a,u={};for(i in y.call(this,e),this.gl=n,this.effectRef=l[t],this.sources={},this.targets=[],this.inputElements={},this.dirty=!0,this.shaderDirty=!0,this.hook=t,this.options=e,this.transform=null,this.effect=z({},this.effectRef),this.effectRef.definition&&z(this.effect,this.effectRef.definition.call(this,e)),Z(this.effect),this.uniforms.transform=s,this.inputs={},a=ot[t],this.effect.inputs)this.effect.inputs.hasOwnProperty(i)&&(void 0!==(r=this.effect.inputs[i]).defaultValue&&null!==r.defaultValue||("number"===r.type?r.defaultValue=Math.min(Math.max(0,r.min),r.max):"color"===r.type?r.defaultValue=[0,0,0,0]:"boolean"===r.type?r.defaultValue=!1:"string"===r.type?r.defaultValue="":"enum"===r.type&&(r.defaultValue=r.firstValue)),o=r.validate.call(this,r.defaultValue,r),a&&void 0!==a[i]&&(o=r.validate.call(this,a[i],r,r.defaultValue,o),a[i]=o,"image"===r.type&&(u[i]=o)),this.inputs[i]=o,r.uniform&&(this.uniforms[r.uniform]=r.defaultValue));for(i in n&&(this.initialize(),this.effect.commonShader&&this.buildShader()),this.updateReady(),this.inPlace=this.effect.inPlace,this.pub=new _(this),W.push(this),Y[this.id]=this,it.push(this),g[t].push(this),u)u.hasOwnProperty(i)&&this.setInput(i,u[i])},R.prototype=Object.create(y.prototype),R.prototype.constructor=R,R.prototype.initialize=function(){if(!this.initialized){var t=this;this.baseShader=c,this.shape?this.model=ct(this.shape,this.gl):this.model=h,"function"==typeof this.effect.initialize?this.effect.initialize.call(this,(function(){t.initFrameBuffer(!0)}),n):this.initFrameBuffer(!0),this.frameBuffer&&(this.texture=this.frameBuffer.texture),this.initialized=!0}},R.prototype.resize=function(){var t;for(y.prototype.resize.call(this),this.effect.resize&&this.effect.resize.call(this),t=0;t<this.targets.length;t++)this.targets[t].resize()},R.prototype.updateReady=function(){var t,e,i,r,n=!0;for(e in(i=this.effect).inputs)if(i.inputs.hasOwnProperty(e)&&"image"===this.effect.inputs[e].type&&(!this.sources[e]||!this.sources[e].ready)&&(!i.requires||i.requires.call(this,e,this.inputs))){n=!1;break}if(this.ready!==n&&(this.ready=n,this.emit(n?"ready":"unready"),r=n?"setReady":"setUnready",this.targets))for(t=0;t<this.targets.length;t++)this.targets[t][r]()},R.prototype.setReady=R.prototype.updateReady,R.prototype.setUnready=R.prototype.updateReady,R.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},R.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},R.prototype.removeSource=function(t){var e,i=t&&t.pub;for(e in this.inputs)!this.inputs.hasOwnProperty(e)||this.inputs[e]!==t&&this.inputs[e]!==i||(this.inputs[e]=null);for(e in this.sources)!this.sources.hasOwnProperty(e)||this.sources[e]!==t&&this.sources[e]!==i||(this.sources[e]=null)},R.prototype.buildShader=function(){var t,e=this.effect,i=this;function r(t){return O.test(t)?t:"#define SHADER_NAME seriously."+i.hook+"\n"+t}this.shaderDirty&&(e.commonShader&&at[this.hook]?(this.shader||at[this.hook].count++,this.shader=at[this.hook].shader):e.shader?(this.shader&&!e.commonShader&&this.shader.destroy(),(t=e.shader.call(this,this.inputs,{vertex:a,fragment:u},J.util))instanceof $?this.shader=t:t&&t.vertex&&t.fragment?this.shader=new $(n,r(t.vertex),r(t.fragment)):this.shader=c,e.commonShader&&(at[this.hook]={count:1,shader:this.shader})):this.shader=c,this.shaderDirty=!1)},R.prototype.render=function(){var t,e,i,r=this.effect,s=this;function o(t,e,i,r,n,o){vt(t,e,i,r,n||s,o)}if(n){if(this.initialized||this.initialize(),this.shaderDirty&&this.buildShader(),this.dirty&&this.ready){for(t in this.sources)!this.sources.hasOwnProperty(t)||r.requires&&!r.requires.call(this,t,this.inputs)||(i="function"==typeof this.inPlace?this.inPlace(t):this.inPlace,this.sources[t].render(!i));this.frameBuffer&&(e=this.frameBuffer.frameBuffer),"function"==typeof r.draw?(r.draw.call(this,this.shader,this.model,this.uniforms,e,o),this.emit("render")):e&&(vt(this.shader,this.model,this.uniforms,e,this),this.emit("render")),this.dirty=!1}return this.texture}},R.prototype.setInput=function(t,e){var i,r,n,o,a,u=this;function h(){var e,i=u.sources[t];if(i){for(e in u.sources)if(e!==t&&u.sources.hasOwnProperty(e)&&u.sources[e]===i)return;i.removeTarget(u)}}if(this.effect.inputs.hasOwnProperty(t)){if("image"===(i=this.effect.inputs[t]).type){if(e){if((e=xt(e))!==this.sources[t]){if(h(),Et(e,this))throw new Error("Attempt to make cyclical connection.");this.sources[t]=e,e.addTarget(this)}}else delete this.sources[t],e=!1;r=this.sources[t],n=Object.keys(this.sources),!0===this.inPlace&&1===n.length?(o=this.sources[n[0]],this.uniforms.transform=o&&o.cumulativeMatrix||s):this.uniforms.transform=s}else a=ot[this.hook]&&void 0!==ot[this.hook][t]?ot[this.hook][t]:i.defaultValue,r=e=i.validate.call(this,e,i,a,this.inputs[t]);return this.inputs[t]===e&&"color"!==i.type&&"vector"!==i.type||(this.inputs[t]=e,i.uniform&&(this.uniforms[i.uniform]=r),"image"===i.type?(this.resize(),this.updateReady()):i.updateSources&&this.updateReady(),i.shaderDirty&&(this.shaderDirty=!0),this.setDirty(),i.update&&i.update.call(this,e)),e}},R.prototype.alias=function(t,e){var i=this;if(C.indexOf(e)>=0)throw new Error("'"+e+"' is a reserved name and cannot be used as an alias.");return this.effect.inputs.hasOwnProperty(t)&&(e||(e=t),X.removeAlias(e),rt[e]={node:this,input:t},Object.defineProperty(X,e,{configurable:!0,enumerable:!0,get:function(){return i.inputs[t]},set:function(e){return i.setInput(t,e)}})),this},R.prototype.matte=function(t){var e,i,n,s,o,a,u,h=[],f=[],c={};function l(t){return t&&t.length&&Array.isArray(t)?Array.isArray(t[0])?Array.isArray(t[0])&&!isNaN(t[0][0])?[t]:t:[t]:[]}function d(t,e,i,r){var n,s,o,a,u;return n=(r.x-i.x)*(t.y-i.y)-(r.y-i.y)*(t.x-i.x),s=(e.x-t.x)*(t.y-i.y)-(e.y-t.y)*(t.x-i.x),!!((o=(r.y-i.y)*(e.x-t.x)-(r.x-i.x)*(e.y-t.y))&&(u=s/o,(a=n/o)>0&&a<=1&&u>0&&u<=1))&&{x:t.x+a*(e.x-t.x),y:t.y+a*(e.y-t.y)}}function p(t){var e,i,r,n,s,o,a,u,c,l,p,m=[];if(!t.simple){for(e=0;e<t.edges.length;e++)for(r=t.edges[e],i=e+1;i<t.edges.length;i++)n=t.edges[i],(s=d(r[0],r[1],n[0],n[1]))&&(s.edge1=r,s.edge2=n,m.push(s));if(m.length){for(c=[],e=0;e<m.length;e++)r=(s=m[e]).edge1,n=s.edge2,l={x:s.x,y:s.y,prev:r[0],next:n[1],id:f.length},t.vertices.push(l),f.push(l),p={x:s.x,y:s.y,prev:n[0],next:r[1],id:f.length},t.vertices.push(p),f.push(l),l.prev.next=l,l.next.prev=l,p.prev.next=p,p.next.prev=p;do{o={edges:[],vertices:[],simple:!0},c.push(o),a=u=t.vertices[0];do{e=t.vertices.indexOf(u),t.vertices.splice(e,1),o.edges.push([u,u.next]),o.vertices.push(u),u=u.next}while(u!==a)}while(t.vertices.length);for(e=h.indexOf(t),h.splice(e,1),e=0;e<c.length;e++)h.push(c[e])}else t.simple=!0}}function m(t){var e,i,r,n,s=t.vertices.length,o=0;for(e=s-1,i=0;i<s;e=i,i++)r=t.vertices[e],n=t.vertices[i],o+=r.x*n.y-n.x*r.y;return o>0}function y(t){var e,r,n,s,o,a,u,h,f,c,l,d=t.vertices,p=[],m=[];function y(t,e,i,r){var n,s,o,a,u,h,f,c,l,d,p,m;return n=i.x-e.x,s=i.y-e.y,o=t.x-i.x,a=t.y-i.y,u=e.x-t.x,h=e.y-t.y,f=r.x-t.x,c=r.y-t.y,l=r.x-e.x,d=r.y-e.y,p=r.x-i.x,m=r.y-i.y,n*d-s*l>=0&&o*m-a*p>=0&&u*c-h*f>=0}function g(t,e,i,r,n){var s,o,a,u;if(o=d[n[t]],a=d[n[e]],u=d[n[i]],0>(a.x-o.x)*(u.y-o.y)-(a.y-o.y)*(u.x-o.x))return!1;for(s=0;s<r;s++)if(s!==t&&s!==e&&s!==i&&y(o,a,u,d[n[s]]))return!1;return!0}if(r=d.length,t.clockWise)for(e=0;e<r;e++)p[e]=e;else for(e=0;e<r;e++)p[e]=r-1-e;for(s=2*(n=r),e=n-1;n>2;){if(s--<=0)return m;if(n<=(o=e)&&(o=0),n<=(e=o+1)&&(e=0),n<(a=e+1)&&(a=0),g(o,e,a,n,p)){for(u=p[o],h=p[e],f=p[a],t.clockWise?(m.push(d[u]),m.push(d[h]),m.push(d[f])):(m.push(d[f]),m.push(d[h]),m.push(d[u])),c=e,l=e+1;l<n;c++,l++)p[c]=p[l];s=2*--n}}i.indices=m}for(e=l(t),n=0;n<e.length;n++){for(t=e[n],u=null,i={vertices:[],edges:[]},s=0;s<t.length;s++)o=t[s],"object"!==r.typeof(o)||isNaN(o.x)||isNaN(o.y)?o.length>=2&&!isNaN(o[0])&&!isNaN(o[1])&&(a={x:o[0],y:o[1],id:f.length}):a={x:o.x,y:o.y,id:f.length},a&&(u?(u.next=a,a.prev=u,a.next=i.vertices[0],i.vertices[0].prev=a):(i.head=a,a.next=a,a.prev=a),f.push(a),i.vertices.push(a),u=a);if(i.vertices.length>2)for(3===i.vertices.length&&(i.simple=!0),h.push(i),s=0;s<i.vertices.length;s++)a=i.vertices[s],i.edges.push([a,a.next])}for(n=h.length-1;n>=0;n--)p(i=h[n]);for(n=0;n<h.length;n++)(i=h[n]).clockWise=m(i),y(i);for(c.vertices=[],c.coords=[],n=0;n<f.length;n++)o=f[n],c.vertices.push(2*o.x-1),c.vertices.push(-2*o.y+1),c.vertices.push(-1),c.coords.push(o.x),c.coords.push(-1*o.y+1);for(c.vertices=new Float32Array(c.vertices),c.coords=new Float32Array(c.coords),c.indices=[],n=0;n<h.length;n++)for(i=h[n],s=0;s<i.indices.length;s++)o=i.indices[s],c.indices.push(o.id);c.indices=new Uint16Array(c.indices),this.shape=c,this.gl&&ct(c,this.gl)},R.prototype.destroy=function(){var t,e,i,r=this.hook;for(e in this.effect.destroy&&"function"==typeof this.effect.destroy&&this.effect.destroy.call(this),delete this.effect,at[r]&&(at[r].count--,at[r].count||delete at[r]),this.shader&&this.shader.destroy&&this.shader!==c&&!at[r]&&this.shader.destroy(),delete this.shader,this.inputElements)this.inputElements.hasOwnProperty(e)&&((i=this.inputElements[e]).element.removeEventListener("change",i.listener,!0),i.element.removeEventListener("input",i.listener,!0));for(e in this.sources)this.sources.hasOwnProperty(e)&&((i=this.sources[e])&&i.removeTarget&&i.removeTarget(this),delete this.sources[e]);for(;this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];for(e in rt)rt.hasOwnProperty(e)&&(i=rt[e]).node===this&&X.removeAlias(e);(t=it.indexOf(this))>=0&&it.splice(t,1),(t=g[r].indexOf(this))>=0&&g[r].splice(t,1),y.prototype.destroy.call(this)},N=function(t){var e=t;Object.defineProperties(this,{original:{enumerable:!0,configurable:!0,get:function(){return e.source}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}},width:{enumerable:!0,configurable:!0,get:function(){return e.width}},height:{enumerable:!0,configurable:!0,get:function(){return e.height}}}),this.render=function(){e.render()},this.update=function(){e.setDirty()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},E=function(t,e,i){var s,o,a=i||{},u=void 0===a.flip||a.flip,h=a.width,f=a.height,c=!1,l=this,d=!1;function m(t,e,i,r){var n=p[t];if(n.definition){if(!(n=n.definition.call(l,e,i,r)))return null;n=z(z({},p[t]),n)}return n}function g(t){return l.source===t}if(y.call(this),(t&&"string"!=typeof t||!e&&0!==e)&&(i&&"object"===r.typeof(i)||(i=e),e=t),"string"==typeof e&&isNaN(e)&&(e=M(e,["canvas","img","video"])),"string"==typeof t&&p[t]&&(o=m(t,e,i,!0))&&(this.hook=t,d=!0,c=o.deferTexture,this.plugin=o,this.compare=o.compare,this.checkDirty=o.checkDirty,o.source&&(e=o.source)),!o&&k(e))"CANVAS"===e.tagName?(this.width=e.width,this.height=e.height,this.render=this.renderImageCanvas,d=!0,this.hook="canvas",this.compare=g):"IMG"===e.tagName&&(this.width=e.naturalWidth||1,this.height=e.naturalHeight||1,e.complete&&e.naturalWidth||(c=!0),e.addEventListener("load",(function(){l.isDestroyed||(l.width===e.naturalWidth&&l.height===e.naturalHeight||(l.width=e.naturalWidth,l.height=e.naturalHeight,l.resize()),l.setDirty(),l.setReady())}),!0),this.render=this.renderImageCanvas,d=!0,this.hook="image",this.compare=g);else if(!o&&k(e,"WebGLTexture")){if(n&&!n.isTexture(e))throw new Error("Not a valid WebGL texture.");isNaN(h)?isNaN(f)||(h=f):isNaN(f)&&(f=h),this.width=h,this.height=f,void 0===a.flip&&(u=!1),d=!0,this.texture=e,this.initialized=!0,this.hook="texture",this.compare=g,this.render=function(){}}if(!d&&!o)for(s in p)if(p.hasOwnProperty(s)&&p[s]&&(o=m(s,e,i,!1))){this.hook=s,d=!0,c=o.deferTexture,this.plugin=o,this.compare=o.compare,this.checkDirty=o.checkDirty,o.source&&(e=o.source);break}if(!d)throw new Error("Unknown source type");this.source=e,void 0===this.flip&&(this.flip=u),this.targets=[],c||l.setReady(),this.pub=new N(this),W.push(this),Y[this.id]=this,Q.push(this),x[this.hook].push(this),Q.length&&!I&>()},E.prototype=Object.create(y.prototype),E.prototype.constructor=E,E.prototype.initialize=function(){var t;n&&!this.texture&&this.ready&&(t=n.createTexture(),n.bindTexture(n.TEXTURE_2D,t),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),n.bindTexture(n.TEXTURE_2D,null),this.texture=t,this.initialized=!0,this.allowRefresh=!0,this.setDirty())},E.prototype.initFrameBuffer=function(t){n&&(this.frameBuffer=new K(n,this.width,this.height,{texture:this.texture,useFloat:t}))},E.prototype.addTarget=function(t){var e;for(e=0;e<this.targets.length;e++)if(this.targets[e]===t)return;this.targets.push(t)},E.prototype.removeTarget=function(t){var e=this.targets&&this.targets.indexOf(t);e>=0&&this.targets.splice(e,1)},E.prototype.resize=function(){var t,e;if(this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.framebuffer&&this.framebuffer.resize(this.width,this.height),this.emit("resize"),this.setDirty(),this.targets)for(t=0;t<this.targets.length;t++)(e=this.targets[t]).resize(),e.setTransformDirty&&e.setTransformDirty()},E.prototype.setReady=function(){var t;if(!this.ready&&(this.ready=!0,this.resize(),this.initialize(),this.emit("ready"),this.targets))for(t=0;t<this.targets.length;t++)this.targets[t].setReady()},E.prototype.render=function(){var t=this.source;n&&(t||0===t)&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.plugin&&this.plugin.render&&(this.dirty||this.checkDirty&&this.checkDirty())&&this.plugin.render.call(this,n,vt,h,c)&&(this.dirty=!1,this.emit("render")))},E.prototype.renderImageCanvas=function(){var e=this.source;if(n&&e&&this.ready&&(this.initialized||this.initialize(),this.allowRefresh&&this.dirty)){n.bindTexture(n.TEXTURE_2D,this.texture),n.pixelStorei(n.UNPACK_FLIP_Y_WEBGL,this.flip),n.pixelStorei(n.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1);try{return n.texImage2D(n.TEXTURE_2D,0,n.RGBA,n.RGBA,n.UNSIGNED_BYTE,e),this.dirty=!1,this.emit("render"),!0}catch(e){e.code===t.DOMException.SECURITY_ERR&&(this.allowRefresh=!1,J.logger.error("Unable to access cross-domain image"))}return!1}},E.prototype.destroy=function(){var t,e,i;for(this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),n&&this.texture&&n.deleteTexture(this.texture);this.targets.length;)(i=this.targets.pop())&&i.removeSource&&i.removeSource(this);for(e in(t=Q.indexOf(this))>=0&&Q.splice(t,1),(t=x[this.hook].indexOf(this))>=0&&x[this.hook].splice(t,1),this)this.hasOwnProperty(e)&&"id"!==e&&delete this[e];y.prototype.destroy.call(this)},S=function(t){var e=t;Object.defineProperties(this,{source:{enumerable:!0,configurable:!0,get:function(){if(e.source)return e.source.pub},set:function(t){e.setSource(t)}},original:{enumerable:!0,configurable:!0,get:function(){return e.target}},width:{enumerable:!0,configurable:!0,get:function(){return e.width},set:function(t){!isNaN(t)&&t>0&&e.width!==t&&(e.width=t,e.resize(),e.setTransformDirty())}},height:{enumerable:!0,configurable:!0,get:function(){return e.height},set:function(t){!isNaN(t)&&t>0&&e.height!==t&&(e.height=t,e.resize(),e.setTransformDirty())}},id:{enumerable:!0,configurable:!0,get:function(){return e.id}}}),this.render=function(){e.render()},this.readPixels=function(t,i,r,n,s){return e.readPixels(t,i,r,n,s)},this.on=function(t,i){e.on(t,i)},this.off=function(t,i){e.off(t,i)},this.go=function(t){e.go(t)},this.stop=function(){e.stop()},this.getTexture=function(){return e.frameBuffer.texture},this.destroy=function(){var t,i;for(t in e.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((i=Object.getOwnPropertyDescriptor(this,t)).get||i.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.inputs=function(t){return{source:{type:"image"}}},this.isDestroyed=function(){return e.isDestroyed},this.isReady=function(){return e.ready}},A=function(t,e,i){var s,f,l,d,p,g,v,x,E,T=this,R=!1;function D(t,e,i,r){var s=m[t];if(s.definition){if(!(s=s.definition.call(T,e,i,r)))return null;s=z(z({},m[t]),s),T.hook=E,R=!0,T.plugin=s,T.compare=s.compare,s.target&&(e=s.target),s.gl&&!T.gl&&(T.gl=s.gl,n||pt(s.gl)),T.gl===n&&(T.model=h,T.shader=c)}return s}if(y.call(this),(t&&"string"!=typeof t||!e&&0!==e)&&(i&&"object"===r.typeof(i)||(i=e),e=t),f=void 0===(s=i||{}).flip||s.flip,l=parseInt(s.width,10),d=parseInt(s.height,10),g=s.debugContext,"string"==typeof t&&m[t]&&D(t,e,s,!0),this.renderToTexture=s.renderToTexture,k(e,"WebGLFramebuffer"))if(v=e,k(s,"HTMLCanvasElement"))e=s;else if(k(s,"WebGLRenderingContext"))e=s.canvas;else if(k(s.canvas,"HTMLCanvasElement"))e=s.canvas;else{if(!k(s.context,"WebGLRenderingContext"))throw new Error("Must provide a canvas with WebGLFramebuffer target");e=s.context.canvas}if(k(e,"HTMLCanvasElement")){if(l=e.width,d=e.height,(!n||n.canvas!==e&&s.allowSecondaryWebGL)&&(p=H(e,{alpha:!0,premultipliedAlpha:!0,preserveDrawingBuffer:!0,stencil:!0,debugContext:g})),p)n&&n!==p?(this.gl=p,this.frameBuffer={frameBuffer:v||null},this.shader=new $(this.gl,a,u),this.model=lt.call(this,this.gl),this.pixels=null,this.texture=this.gl.createTexture(),this.gl.bindTexture(n.TEXTURE_2D,this.texture),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,n.LINEAR),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,n.LINEAR),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,n.CLAMP_TO_EDGE),this.gl.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,n.CLAMP_TO_EDGE),this.render=this.renderSecondaryWebGL):(o||(o=this),n||pt(p),this.render=this.renderWebGL,s.renderToTexture?n&&(this.frameBuffer=new K(n,l,d,!1)):this.frameBuffer={frameBuffer:v||null});else{if(!s.allowSecondaryWebGL&&n&&n.canvas!==e)throw new Error("Only one WebGL target canvas allowed. Set allowSecondaryWebGL option to create secondary context.");this.render=w,J.logger.log("Unable to create WebGL context.")}R=!0}if(!R)for(E in m)if(m.hasOwnProperty(E)&&m[E]&&D(E,e,s,!1))break;if(!R)throw new Error("Unknown target type");b&&((x=b.get(e))?J.logger.warn("Target already in use by another instance",e,Object.keys(x).map((function(t){return x[t]}))):(x={},b.set(e,x)),x[X.id]=X),this.target=e,this.transform=null,this.transformDirty=!0,this.flip=f,l&&(this.width=l),d&&(this.height=d),this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,void 0!==s.auto?this.auto=s.auto:this.auto=ut,this.frames=0,this.pub=new S(this),W.push(this),Y[this.id]=this,tt.push(this)},A.prototype=Object.create(y.prototype),A.prototype.constructor=A,A.prototype.setSource=function(t){var e;(e=xt(t))!==this.source&&(this.source&&this.source.removeTarget(this),this.source=e,e.addTarget(this),e&&(this.resize(),e.ready?this.setReady():this.setUnready()),this.setDirty())},A.prototype.setDirty=function(){this.dirty=!0,this.auto&&!I&&(I=B(gt))},A.prototype.resize=function(){k(this.target,"HTMLCanvasElement")?this.width===this.target.width&&this.height===this.target.height||(this.target.width=this.width,this.target.height=this.height,this.uniforms.resolution[0]=this.width,this.uniforms.resolution[1]=this.height,this.emit("resize"),this.setTransformDirty()):this.plugin&&this.plugin.resize&&this.plugin.resize.call(this),!this.source||this.source.width===this.width&&this.source.height===this.height||this.transform||(this.transform=new Float32Array(16))},A.prototype.setTransformDirty=function(){this.transformDirty=!0,this.setDirty()},A.prototype.go=function(){this.auto=!0,this.setDirty()},A.prototype.stop=function(){this.auto=!1},A.prototype.render=function(){n&&this.plugin&&this.plugin.render&&this.plugin.render.call(this,vt,c,h)},A.prototype.renderWebGL=function(){var t,e,i;if(this.resize(),n&&this.dirty&&this.ready){if(!this.source)return;this.source.render(),this.uniforms.source=this.source.texture,this.source.width===this.width&&this.source.height===this.height?this.uniforms.transform=this.source.cumulativeMatrix||s:this.transformDirty&&(t=this.transform,U.copy(t,this.source.cumulativeMatrix||s),e=this.source.width/this.width,i=this.source.height/this.height,t[0]*=e,t[1]*=e,t[2]*=e,t[3]*=e,t[4]*=i,t[5]*=i,t[6]*=i,t[7]*=i,this.uniforms.transform=t,this.transformDirty=!1),vt(c,h,this.uniforms,this.frameBuffer.frameBuffer,this,P),this.emit("render"),this.dirty=!1}},A.prototype.renderSecondaryWebGL=function(){var t,e,i,r,n;this.dirty&&this.ready&&this.source&&(this.emit("render"),this.source.render(!0),t=this.source.width,e=this.source.height,this.pixels&&this.pixels.length===t*e*4||(this.pixels=new Uint8Array(t*e*4)),this.source.readPixels(0,0,t,e,this.pixels),this.gl.texImage2D(this.gl.TEXTURE_2D,0,this.gl.RGBA,t,e,0,this.gl.RGBA,this.gl.UNSIGNED_BYTE,this.pixels),t===this.width&&e===this.height?this.uniforms.transform=s:this.transformDirty&&(i=this.transform,U.copy(i,s),r=this.source.width/this.width,n=this.source.height/this.height,i[0]*=r,i[1]*=r,i[2]*=r,i[3]*=r,i[4]*=n,i[5]*=n,i[6]*=n,i[7]*=n,this.uniforms.transform=i,this.transformDirty=!1),this.uniforms.source=this.texture,vt(this.shader,this.model,this.uniforms,null,this,P),this.dirty=!1)},A.prototype.removeSource=function(t){this.source!==t&&this.source!==t.pub||(this.source=null)},A.prototype.destroy=function(){var t,e;this.source&&this.source.removeTarget&&this.source.removeTarget(this),b&&(delete(e=b.get(this.target))[X.id],Object.keys(e).length||b.delete(this.target)),this.plugin&&this.plugin.destroy&&this.plugin.destroy.call(this),delete this.source,delete this.target,delete this.pub,delete this.uniforms,delete this.pixels,delete this.auto,(t=tt.indexOf(this))>=0&&tt.splice(t,1),y.prototype.destroy.call(this),this===o&&(i.removeEventListener("webglcontextrestored",mt,!1),yt(),o=null)},F=function(t){var e,i=t,r=this;function n(t,e,r){var n,s,o;n=i.inputElements[t],"string"==typeof r&&isNaN(r)&&("enum"===e.type?e.options.hasOwnProperty(r)||(r=M(r,["select"])):"number"===e.type||"boolean"===e.type?r=M(r,["input","select"]):"image"===e.type&&(r=M(r,["canvas","img","video"]))),k(r,"HTMLInputElement")||k(r,"HTMLSelectElement")?(s=r.value,n&&n.element!==r&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t],n=null),n||(n={element:r,listener:(o=r,function(){var e,n;e="checkbox"===r.type?r.checked:o.value,n=i.setInput(t,e),"color"===r.type&&(n=j(n)),n!==e&&(o.value=n)})},i.inputElements[t]=n,"range"===r.type?(r.addEventListener("input",n.listener,!0),r.addEventListener("change",n.listener,!0)):r.addEventListener("change",n.listener,!0)),n&&"checkbox"===r.type&&(s=r.checked)):(n&&(n.element.removeEventListener("change",n.listener,!0),n.element.removeEventListener("input",n.listener,!0),delete i.inputElements[t]),s=r),i.setInput(t,s)}function s(t,e){Object.defineProperty(r,t,{configurable:!0,enumerable:!0,get:function(){return e.get.call(i)},set:function(i){n(t,e,i)}})}function o(t){return function(){t.apply(i,arguments)&&i.setTransformDirty()}}for(e in Object.defineProperties(this,{transform:{enumerable:!0,configurable:!0,get:function(){return i.hook}},title:{enumerable:!0,configurable:!0,get:function(){return i.plugin.title||i.hook}},width:{enumerable:!0,configurable:!0,get:function(){return i.width}},height:{enumerable:!0,configurable:!0,get:function(){return i.height}},id:{enumerable:!0,configurable:!0,get:function(){return i.id}},source:{enumerable:!0,configurable:!0,get:function(){return i.source&&i.source.pub},set:function(t){i.setSource(t)}}}),i.methods)i.methods.hasOwnProperty(e)&&(this[e]=o(i.methods[e]));for(e in i.inputs)i.inputs.hasOwnProperty(e)&&s(e,i.inputs[e]);this.update=function(){i.setDirty()},this.inputs=function(t){var e,r,n,s;if(n=i.plugin.inputs,t)return!(r=n[t])||r.method?null:(e={type:r.type,defaultValue:r.defaultValue,title:r.title||t},"number"===r.type?(e.min=r.min,e.max=r.max,e.step=r.step,e.mod=r.mod):"enum"===r.type?e.options=z({},r.options):"vector"===r.type&&(e.dimensions=r.dimensions),r.description&&(e.description=r.description),e);for(s in e={},n)n.hasOwnProperty(s)&&!n[s].method&&(e[s]=this.inputs(s));return e},this.alias=function(t,e){return i.alias(t,e),this},this.on=function(t,e){i.on(t,e)},this.off=function(t,e){i.off(t,e)},this.destroy=function(){var t,e;for(t in i.destroy(),this)this.hasOwnProperty(t)&&"isDestroyed"!==t&&"id"!==t&&((e=Object.getOwnPropertyDescriptor(this,t)).get||e.set||"function"!=typeof this[t]?delete this[t]:this[t]=w)},this.isDestroyed=function(){return i.isDestroyed},this.isReady=function(){return i.ready}},D=function(t,e){var i,r,n,s,o;for(i in this.matrix=new Float32Array(16),this.cumulativeMatrix=new Float32Array(16),this.ready=!1,this.width=1,this.height=1,this.seriously=X,this.transformRef=d[t],this.hook=t,this.id=q,q++,this.options=e,this.sources=null,this.targets=[],this.inputElements={},this.inputs={},this.methods={},this.listeners={},this.texture=null,this.frameBuffer=null,this.uniforms=null,this.dirty=!0,this.transformDirty=!0,this.renderDirty=!1,this.isDestroyed=!1,this.transformed=!1,this.plugin=z({},this.transformRef),this.transformRef.definition&&z(this.plugin,this.transformRef.definition.call(this,e)),this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&((r=this.plugin.inputs[i]).method&&"function"==typeof r.method?this.methods[i]=r.method:"function"==typeof r.set&&"function"==typeof r.get&&(this.inputs[i]=r));for(i in Z(this.plugin),o=ot[t],this.plugin.inputs)this.plugin.inputs.hasOwnProperty(i)&&"function"==typeof(r=this.plugin.inputs[i]).set&&"function"==typeof r.get&&"function"!=typeof r.method&&(n=r.get.call(this),s=void 0===r.defaultValue?n:r.defaultValue,s=r.validate.call(this,s,r,n),o&&void 0!==o[i]&&(s=r.validate.call(this,o[i],r,r.defaultValue,s),o[i]=s),s!==n&&r.set.call(this,s));W.push(this),Y[this.id]=this,this.pub=new F(this),et.push(this),v[t].push(this)},D.prototype=Object.create(y.pro