diff --git a/dist/GlslCanvas.es.js b/dist/GlslCanvas.es.js index 403924e..37ded4f 100644 --- a/dist/GlslCanvas.es.js +++ b/dist/GlslCanvas.es.js @@ -483,7 +483,8 @@ function parseUniforms(uniforms) { } function isCanvasVisible(canvas) { - return canvas.getBoundingClientRect().top + canvas.height > 0 && canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight); + var bound = canvas.getBoundingClientRect(); + return bound.top + bound.height > 0 && bound.top < (window.innerHeight || document.documentElement.clientHeight); } function isPowerOf2(value) { diff --git a/dist/GlslCanvas.js b/dist/GlslCanvas.js index b83ec25..63a3ec2 100644 --- a/dist/GlslCanvas.js +++ b/dist/GlslCanvas.js @@ -888,7 +888,8 @@ function parseUniforms(uniforms) { } function isCanvasVisible(canvas) { - return canvas.getBoundingClientRect().top + canvas.height > 0 && canvas.getBoundingClientRect().top < (window.innerHeight || document.documentElement.clientHeight); + var bound = canvas.getBoundingClientRect(); + return bound.top + bound.height > 0 && bound.top < (window.innerHeight || document.documentElement.clientHeight); } function isPowerOf2(value) { diff --git a/dist/GlslCanvas.min.js b/dist/GlslCanvas.min.js index ce9f958..37d7bc7 100644 --- a/dist/GlslCanvas.min.js +++ b/dist/GlslCanvas.min.js @@ -1,2 +1 @@ -!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):e.GlslCanvas=t()}(this,function(){"use strict";function e(e,t,r){for(var i=0,n=e.length;i0&&(c=setTimeout(function(){if(!f){f=!0,h.abort("timeout");var e=new Error("XMLHttpRequest timeout");e.code="ETIMEDOUT",r(e)}},e.timeout)),h.setRequestHeader)for(l in m)m.hasOwnProperty(l)&&h.setRequestHeader(l,m[l]);else if(e.headers&&!i(e.headers))throw new Error("Headers cannot be set on an XDomainRequest object");return"responseType"in e&&(h.responseType=e.responseType),"beforeSend"in e&&"function"==typeof e.beforeSend&&e.beforeSend(h),h.send(v||null),h}function o(e){try{if("document"===e.responseType)return e.responseXML;var t=e.responseXML&&"parsererror"===e.responseXML.documentElement.nodeName;if(""===e.responseType&&!t)return e.responseXML}catch(e){}return null}function u(e){return'\n\n
\n
\n
'+e+"
\n
\n
\n"}function h(e,t,r){function i(t){var r=e.parentNode;r&&(r.innerHTML=u(t))}function n(e,t){"function"==typeof r?r(e):i(t)}if(!window.WebGLRenderingContext)return n(H,O),null;var a=l(e,t);return a?a.getExtension("OES_standard_derivatives"):n(j,G),a}function l(e,t){for(var r=["webgl","experimental-webgl"],i=null,n=0;n1&&void 0!==arguments[1]?arguments[1]:null,r=[];for(var i in e){var n=e[i],a=void 0;if(t&&(i=t+"."+i),"number"==typeof n)r.push({type:"float",method:"1f",name:i,value:n});else if(Array.isArray(n)){if("number"==typeof n[0])1===n.length?r.push({type:"float",method:"1f",name:i,value:n}):n.length>=2&&n.length<=4?r.push({type:"vec"+n.length,method:n.length+"fv",name:i,value:n}):n.length>4&&r.push({type:"float[]",method:"1fv",name:i+"[0]",value:n});else if("string"==typeof n[0])r.push({type:"sampler2D",method:"1i",name:i,value:n});else if(Array.isArray(n[0])&&"number"==typeof n[0][0]){if(n[0].length>=2&&n[0].length<=4)for(a=0;a0&&e.getBoundingClientRect().top<(window.innerHeight||document.documentElement.clientHeight)}function v(e){return 0==(e&e-1)}function m(){return/^((?!chrome|android).)*safari/i.test(navigator.userAgent)}function E(e,t){return!(!e||!t)&&e.toString()!==t.toString()}function T(e){var t=new Set;return Object.assign(e,{on:function(e,r){var i={};i[e]=r,t.add(i)},off:function(e,r){if(r){var i={};i[e]=r,t.delete(i)}else{var n=!0,a=!1,s=void 0;try{for(var o,u=t[Symbol.iterator]();!(n=(o=u.next()).done);n=!0){var h=o.value,l=!0,f=!1,c=void 0;try{for(var d,g=Object.keys(h)[Symbol.iterator]();!(l=(d=g.next()).done);l=!0)if(d.value===e)return void t.delete(h)}catch(e){f=!0,c=e}finally{try{!l&&g.return&&g.return()}finally{if(f)throw c}}}}catch(e){a=!0,s=e}finally{try{!n&&u.return&&u.return()}finally{if(a)throw s}}}},listSubscriptions:function(){var e=!0,r=!1,i=void 0;try{for(var n,a=t[Symbol.iterator]();!(e=(n=a.next()).done);e=!0){var s=n.value;console.log(s)}}catch(e){r=!0,i=e}finally{try{!e&&a.return&&a.return()}finally{if(r)throw i}}},subscribe:function(e){t.add(e)},unsubscribe:function(e){t.delete(e)},unsubscribeAll:function(){t.clear()},trigger:function(e){for(var r=arguments.length,i=Array(r>1?r-1:0),n=1;n0){window.glslCanvases=[];for(var t=0;t2&&void 0!==arguments[2]?arguments[2]:{};C(this,e),T(this),this.gl=t,this.texture=t.createTexture(),this.texture&&(this.valid=!0),this.bind(),this.name=r,this.source=null,this.sourceType=null,this.loading=null,this.setData(1,1,new Uint8Array([0,0,0,255]),{filtering:"linear"}),this.setFiltering(i.filtering),this.load(i)}return k(e,[{key:"destroy",value:function(){this.valid&&(this.gl.deleteTexture(this.texture),this.texture=null,delete this.data,this.data=null,this.valid=!1)}},{key:"bind",value:function(t){this.valid&&("number"==typeof t&&e.activeUnit!==t&&(this.gl.activeTexture(this.gl.TEXTURE0+t),e.activeUnit=t),e.activeTexture!==this.texture&&(this.gl.bindTexture(this.gl.TEXTURE_2D,this.texture),e.activeTexture=this.texture))}},{key:"load",value:function(){var e=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{};this.loading=null,"string"==typeof e.url?void 0!==this.url&&e.url===this.url||this.setUrl(e.url,e):e.element?this.setElement(e.element,e):e.data&&e.width&&e.height&&this.setData(e.width,e.height,e.data,e)}},{key:"setUrl",value:function(e){var t=this,r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{};if(this.valid)return this.url=e,this.source=this.url,this.sourceType="url",this.loading=new Promise(function(i,n){var a=e.split(".").pop().toLowerCase(),s="ogv"===a||"webm"===a||"mp4"===a,o=void 0;s?((o=document.createElement("video")).autoplay=!0,r.filtering="nearest"):o=new Image,o.onload=function(){try{t.setElement(o,r)}catch(e){console.log("Texture '"+t.name+"': failed to load url: '"+t.source+"'",e,r)}i(t)},o.onerror=function(e){console.log("Texture '"+t.name+"': failed to load url: '"+t.source+"'",e,r),i(t)},m()&&"data:"===t.source.slice(0,5)||(o.crossOrigin="anonymous"),o.src=t.source,s&&t.setElement(o,r)}),this.loading}},{key:"setData",value:function(e,t,r){var i=arguments.length>3&&void 0!==arguments[3]?arguments[3]:{};return this.width=e,this.height=t,this.source=r,this.sourceType="data",this.update(i),this.setFiltering(i),this.loading=Promise.resolve(this),this.loading}},{key:"setElement",value:function(e,t){var r=this,i=e;if("string"==typeof e&&(e=document.querySelector(e)),e instanceof HTMLCanvasElement||e instanceof HTMLImageElement||e instanceof HTMLVideoElement)this.source=e,this.sourceType="element",e instanceof HTMLVideoElement?(this.width=this.source.videoWidth,this.height=this.source.videoHeight,e.addEventListener("canplaythrough",function(){r.intervalID=setInterval(function(){r.update(t)},15)},!0),e.addEventListener("ended",function(){e.currentTime=0,e.play()},!0)):this.update(t),this.setFiltering(t);else{var n="the 'element' parameter (`element: "+JSON.stringify(i)+"`) must be a CSS ";n+="selector string, or a , or