alpha-video-player-js 1.4.1 → 1.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1 +1 @@
1
- var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};function e(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}function i(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function n(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var o="start",r={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:o,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},a="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",s=function(t){function i(e,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=e,r.action=n,Object.setPrototypeOf(r,i.prototype),r}return e(i,t),i}(Error),l=function(t){return t instanceof s||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},h=function(t){return new s("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},d=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},u=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},c=function(t,e){var i,n,a,s,l,h,d,c,p,v,f,y,g,m=Object.assign({},r,e||{},t);return m.playbackRate=null!==(i=m.playbackRate)&&void 0!==i?i:r.playbackRate,m.muted=null!==(n=m.muted)&&void 0!==n?n:r.muted,m.loop=null!==(a=m.loop)&&void 0!==a?a:r.loop,m.fps=null!==(s=m.fps)&&void 0!==s?s:r.fps,m.orientation=null!==(l=m.orientation)&&void 0!==l?l:r.orientation,m.side=null!==(h=m.side)&&void 0!==h?h:r.side,m.alphaScale=u(m.alphaScale),m.alphaAlign=null!==(d=m.alphaAlign)&&void 0!==d?d:o,m.autoShow=null!==(c=m.autoShow)&&void 0!==c?c:r.autoShow,m.autoClear=null!==(p=m.autoClear)&&void 0!==p?p:r.autoClear,m.autoDestroy=null!==(v=m.autoDestroy)&&void 0!==v?v:r.autoDestroy,m.autoResize=null!==(f=m.autoResize)&&void 0!==f?f:r.autoResize,m.debug=null!==(y=m.debug)&&void 0!==y?y:r.debug,m.videoFrame=null!==(g=m.videoFrame)&&void 0!==g?g:r.videoFrame,m},p=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=o);var r=u(i);if("landscape"===t){var a=1/(1+r),s=r/(1+r);return{rgb:{x:"front"===e?0:s,y:0,width:a,height:1},alpha:{x:"front"===e?a:0,y:"start"===n?0:1-r,width:s,height:r}}}var l=1/(1+r),h=r/(1+r);return{rgb:{x:0,y:"front"===e?0:h,width:1,height:l},alpha:{x:"start"===n?0:1-r,y:"front"===e?l:0,width:r,height:h}}},v=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},f=function(t,e,i){if(void 0===i&&(i=!1),i)throw h(e);if(!t)throw function(t){return new s("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},y=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},g=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=c(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw h("updateConfig");var i=this.config,n=this.playing,o=void 0!==t.src&&t.src!==i.src,r=o&&(n||this.resumeOnReady),a=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var s=this.config;if(o&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(s.muted),void 0!==t.loop&&this.setLoop(s.loop),void 0!==t.playbackRate&&this.setPlaybackRate(s.playbackRate),r){this.resumeOnReady=!0;var l=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&l===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!a||o||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,s)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||a),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,s=t.crossOrigin;this.resetReady();var l=this.video=document.createElement("video");if(l.crossOrigin=null!=s?s:"anonymous",l.poster=i||a,l.src=e,l.autoplay=!1,l.preload="auto",l.playbackRate=n,l.loop=r,l.muted=o,o&&l.setAttribute("muted",""),l.setAttribute("playsinline",""),l.setAttribute("webkit-playsinline",""),l.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var h=this.config.width||this.container.offsetWidth,d=this.config.height||this.container.offsetHeight;l.style.display="block",l.style.width=h?"".concat(h,"px"):"100%",l.style.height=d?"".concat(d,"px"):"100%",l.style.visibility=this.config.autoShow?"visible":"hidden",l.style.pointerEvents="none",this.container.appendChild(l)}else l.style.position="absolute",l.style.width="0",l.style.height="0",l.style.overflow="hidden",l.style.pointerEvents="none",document.body.appendChild(l);this.bindInstance(),this.addEvent(),l.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,o;return i(this,void 0,void 0,(function(){var i,r,a,s;return n(this,(function(n){switch(n.label){case 0:f(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,i=this.video,r=++this.playRequestId,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,i.play()];case 2:return a=n.sent(),this.destroyed||r!==this.playRequestId||i!==this.video||i.paused||i.ended?[2,a]:(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame(),[2,a]);case 3:s=n.sent();try{this.destroyed||r!==this.playRequestId||null===(o=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===o||o.call(e,s)}finally{throw s}case 4:return[2]}}))}))},t.prototype.pause=function(){f(this.video,"pause",this.destroyed),this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){f(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw h("setSrc");this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){f(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){f(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){f(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){f(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,r=t.container;if(e&&i){var a=d(),s=i.width||(null==r?void 0:r.offsetWidth)||(n?n.width/a:e.videoWidth),l=i.height||(null==r?void 0:r.offsetHeight)||(n?n.height/a:e.videoHeight),h=s,u=l;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var c=function(t,e,i,n,r){if(void 0===n&&(n=1),void 0===r&&(r=o),0===n)return t/e;var a=p(i,"front",n,r).rgb;return t*a.width/(e*a.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),v=s||e.videoWidth,f=l||e.videoHeight,y=void 0;if("width"===i.autoResize||"height"===i.autoResize)y=i.autoResize;else y=c>=v/f?"width":"height";h="width"===y?v:Math.round(f*c),u="width"===y?Math.round(v/c):f}var g=u*a;n&&h&&u&&(h*a!==this.canvasWidth||g!==this.canvasHeight)?(!function(t,e,i){var n=d();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,h,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=h?"".concat(h,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),m=function(t){function i(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return e(i,t),i.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},i.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},i.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},i.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},i.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var h=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(h,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(h);var d=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(d,0),r},i.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=o);var r=[-1,1,1,1,-1,-1,1,-1],a=p(t,e,i,n),s=a.rgb,l=a.alpha,h=v(s),d=v(l),u=[];return r.forEach((function(t,e){e%2==0&&(u=u.concat(r.slice(e,e+2)).concat(h.slice(e,e+2)).concat(d.slice(e,e+2)))})),new Float32Array(u)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},i.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},i.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},i.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&y(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},i.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},i.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,h=i.program,d=function(e){try{e()}catch(e){null!=t||(t=e)}};if(d((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(h&&r&&d((function(){return o.detachShader(h,r)})),h&&a&&d((function(){return o.detachShader(h,a)})),r&&d((function(){return o.deleteShader(r)})),a&&d((function(){return o.deleteShader(a)})),s&&d((function(){return o.deleteTexture(s)})),l&&d((function(){return o.deleteBuffer(l)})),h&&d((function(){return o.deleteProgram(h)})),d((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},i}(g),R=function(t){function i(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return e(i,t),i.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},i.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},i.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},i.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,h=t.config;if(e&&i&&n&&o&&y(n)&&r&&a&&s&&l){var d=p(h.orientation,h.side,h.alphaScale,h.alphaAlign),u=d.rgb,c=d.alpha;e.drawImage(n,u.x*r,u.y*a,u.width*r,u.height*a,0,0,s,l);var v=e.getImageData(0,0,s,l),f=v.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var g=i.getImageData(0,0,s,l).data,m=3;m<f.length;m+=4)f[m]=g[m-3];e.putImageData(v,0,0)}},i.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},i.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},i}(g),b=function(t){function i(e){return t.call(this,e,!0)||this}return e(i,t),i.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},i}(g),w=["crossOrigin"],E=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=c(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new b(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=d(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new m(t,a,s):new R(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,o){var r,a=this;(null===(r=this.config)||void 0===r?void 0:r.src)&&t.whenReady().then((function(){return i(a,void 0,void 0,(function(){var i;return n(this,(function(n){switch(n.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:o?[4,t.play()]:[3,2];case 1:n.sent(),n.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(o||(null===(i=this.config)||void 0===i?void 0:i.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){a.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playing;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw h(t);if(!this.render)throw function(t){return new s("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return i(this,void 0,void 0,(function(){var e,i;return n(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw h("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=c(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||w.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}();export{s as AlphaVideoPlayerError,E as default,l as isAlphaVideoPlayerError};
1
+ var t=function(e,i){return t=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},t(e,i)};function e(e,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=e}t(e,i),e.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}function i(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function n(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var o="start",r={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:o,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},a="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",s=function(t){function i(e,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=e,r.action=n,Object.setPrototypeOf(r,i.prototype),r}return e(i,t),i}(Error),l=function(t){return t instanceof s||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},h=function(t){return new s("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},d=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},u=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},c=function(t,e){var i,n,a,s,l,h,d,c,p,v,f,y,g,m=Object.assign({},r,e||{},t);return m.playbackRate=null!==(i=m.playbackRate)&&void 0!==i?i:r.playbackRate,m.muted=null!==(n=m.muted)&&void 0!==n?n:r.muted,m.loop=null!==(a=m.loop)&&void 0!==a?a:r.loop,m.fps=null!==(s=m.fps)&&void 0!==s?s:r.fps,m.orientation=null!==(l=m.orientation)&&void 0!==l?l:r.orientation,m.side=null!==(h=m.side)&&void 0!==h?h:r.side,m.alphaScale=u(m.alphaScale),m.alphaAlign=null!==(d=m.alphaAlign)&&void 0!==d?d:o,m.autoShow=null!==(c=m.autoShow)&&void 0!==c?c:r.autoShow,m.autoClear=null!==(p=m.autoClear)&&void 0!==p?p:r.autoClear,m.autoDestroy=null!==(v=m.autoDestroy)&&void 0!==v?v:r.autoDestroy,m.autoResize=null!==(f=m.autoResize)&&void 0!==f?f:r.autoResize,m.debug=null!==(y=m.debug)&&void 0!==y?y:r.debug,m.videoFrame=null!==(g=m.videoFrame)&&void 0!==g?g:r.videoFrame,m},p=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=o);var r=u(i);if("landscape"===t){var a=1/(1+r),s=r/(1+r);return{rgb:{x:"front"===e?0:s,y:0,width:a,height:1},alpha:{x:"front"===e?a:0,y:"start"===n?0:1-r,width:s,height:r}}}var l=1/(1+r),h=r/(1+r);return{rgb:{x:0,y:"front"===e?0:h,width:1,height:l},alpha:{x:"start"===n?0:1-r,y:"front"===e?l:0,width:r,height:h}}},v=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},f=function(t,e,i){if(void 0===i&&(i=!1),i)throw h(e);if(!t)throw function(t){return new s("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},y=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},g=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.playPending=!1,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"playRequested",{get:function(){return this.playing||this.playPending||this.resumeOnReady},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=c(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw h("updateConfig");var i=this.config,n=this.playing,o=this.playRequested,r=void 0!==t.src&&t.src!==i.src,a=r&&o,s=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var l=this.config;if(r&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(l.muted),void 0!==t.loop&&this.setLoop(l.loop),void 0!==t.playbackRate&&this.setPlaybackRate(l.playbackRate),a){this.resumeOnReady=!0;var d=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&d===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!s||r||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,l)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||a),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,s=t.crossOrigin;this.resetReady();var l=this.video=document.createElement("video");if(l.crossOrigin=null!=s?s:"anonymous",l.poster=i||a,l.src=e,l.autoplay=!1,l.preload="auto",l.playbackRate=n,l.loop=r,l.muted=o,o&&l.setAttribute("muted",""),l.setAttribute("playsinline",""),l.setAttribute("webkit-playsinline",""),l.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var h=this.config.width||this.container.offsetWidth,d=this.config.height||this.container.offsetHeight;l.style.display="block",l.style.width=h?"".concat(h,"px"):"100%",l.style.height=d?"".concat(d,"px"):"100%",l.style.visibility=this.config.autoShow?"visible":"hidden",l.style.pointerEvents="none",this.container.appendChild(l)}else l.style.position="absolute",l.style.width="0",l.style.height="0",l.style.overflow="hidden",l.style.pointerEvents="none",document.body.appendChild(l);this.bindInstance(),this.addEvent(),l.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,o;return i(this,void 0,void 0,(function(){var i,r,a,s;return n(this,(function(n){switch(n.label){case 0:f(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,i=this.video,r=++this.playRequestId,this.playPending=!0,n.label=1;case 1:return n.trys.push([1,3,,4]),[4,i.play()];case 2:return a=n.sent(),this.destroyed||r!==this.playRequestId||i!==this.video?[2,a]:(this.playPending=!1,i.paused||i.ended||(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame()),[2,a]);case 3:if(s=n.sent(),this.destroyed||r!==this.playRequestId||i!==this.video)return[2];this.playPending=!1;try{null===(o=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===o||o.call(e,s)}finally{throw s}case 4:return[2]}}))}))},t.prototype.pause=function(){f(this.video,"pause",this.destroyed),this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){f(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw h("setSrc");this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){f(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){f(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){f(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){f(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,r=t.container;if(e&&i){var a=d(),s=i.width||(null==r?void 0:r.offsetWidth)||(n?n.width/a:e.videoWidth),l=i.height||(null==r?void 0:r.offsetHeight)||(n?n.height/a:e.videoHeight),h=s,u=l;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var c=function(t,e,i,n,r){if(void 0===n&&(n=1),void 0===r&&(r=o),0===n)return t/e;var a=p(i,"front",n,r).rgb;return t*a.width/(e*a.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),v=s||e.videoWidth,f=l||e.videoHeight,y=void 0;if("width"===i.autoResize||"height"===i.autoResize)y=i.autoResize;else y=c>=v/f?"width":"height";h="width"===y?v:Math.round(f*c),u="width"===y?Math.round(v/c):f}var g=u*a;n&&h&&u&&(h*a!==this.canvasWidth||g!==this.canvasHeight)?(!function(t,e,i){var n=d();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,h,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=h?"".concat(h,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.playPending=!1,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,this.playPending=!1,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),m=function(t){function i(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return e(i,t),i.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},i.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},i.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},i.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},i.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var h=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(h,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(h);var d=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(d,0),r},i.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=o);var r=[-1,1,1,1,-1,-1,1,-1],a=p(t,e,i,n),s=a.rgb,l=a.alpha,h=v(s),d=v(l),u=[];return r.forEach((function(t,e){e%2==0&&(u=u.concat(r.slice(e,e+2)).concat(h.slice(e,e+2)).concat(d.slice(e,e+2)))})),new Float32Array(u)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},i.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},i.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},i.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&y(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},i.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},i.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,h=i.program,d=function(e){try{e()}catch(e){null!=t||(t=e)}};if(d((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(h&&r&&d((function(){return o.detachShader(h,r)})),h&&a&&d((function(){return o.detachShader(h,a)})),r&&d((function(){return o.deleteShader(r)})),a&&d((function(){return o.deleteShader(a)})),s&&d((function(){return o.deleteTexture(s)})),l&&d((function(){return o.deleteBuffer(l)})),h&&d((function(){return o.deleteProgram(h)})),d((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},i}(g),R=function(t){function i(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return e(i,t),i.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},i.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},i.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},i.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,h=t.config;if(e&&i&&n&&o&&y(n)&&r&&a&&s&&l){var d=p(h.orientation,h.side,h.alphaScale,h.alphaAlign),u=d.rgb,c=d.alpha;e.drawImage(n,u.x*r,u.y*a,u.width*r,u.height*a,0,0,s,l);var v=e.getImageData(0,0,s,l),f=v.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var g=i.getImageData(0,0,s,l).data,m=3;m<f.length;m+=4)f[m]=g[m-3];e.putImageData(v,0,0)}},i.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},i.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},i}(g),b=function(t){function i(e){return t.call(this,e,!0)||this}return e(i,t),i.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},i}(g),w=["crossOrigin"],E=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=c(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new b(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=d(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new m(t,a,s):new R(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,o){var r,a=this;(null===(r=this.config)||void 0===r?void 0:r.src)&&t.whenReady().then((function(){return i(a,void 0,void 0,(function(){var i;return n(this,(function(n){switch(n.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:o?[4,t.play()]:[3,2];case 1:n.sent(),n.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(o||(null===(i=this.config)||void 0===i?void 0:i.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){a.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playRequested;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw h(t);if(!this.render)throw function(t){return new s("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return i(this,void 0,void 0,(function(){var e,i;return n(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw h("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=c(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||w.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}();export{s as AlphaVideoPlayerError,E as default,l as isAlphaVideoPlayerError};
package/dist/react.js CHANGED
@@ -1 +1 @@
1
- import t,{forwardRef as e,useRef as i,useEffect as n,useImperativeHandle as o}from"react";var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},r(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var s=function(){return s=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)};function l(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function u(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var d="start",h={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:d,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},c="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",v=function(t){function e(i,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=i,r.action=n,Object.setPrototypeOf(r,e.prototype),r}return a(e,t),e}(Error),p=function(t){return t instanceof v||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},f=function(t){return new v("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},y=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},g=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},m=function(t,e){var i,n,o,r,a,s,l,u,c,v,p,f,y,m=Object.assign({},h,e||{},t);return m.playbackRate=null!==(i=m.playbackRate)&&void 0!==i?i:h.playbackRate,m.muted=null!==(n=m.muted)&&void 0!==n?n:h.muted,m.loop=null!==(o=m.loop)&&void 0!==o?o:h.loop,m.fps=null!==(r=m.fps)&&void 0!==r?r:h.fps,m.orientation=null!==(a=m.orientation)&&void 0!==a?a:h.orientation,m.side=null!==(s=m.side)&&void 0!==s?s:h.side,m.alphaScale=g(m.alphaScale),m.alphaAlign=null!==(l=m.alphaAlign)&&void 0!==l?l:d,m.autoShow=null!==(u=m.autoShow)&&void 0!==u?u:h.autoShow,m.autoClear=null!==(c=m.autoClear)&&void 0!==c?c:h.autoClear,m.autoDestroy=null!==(v=m.autoDestroy)&&void 0!==v?v:h.autoDestroy,m.autoResize=null!==(p=m.autoResize)&&void 0!==p?p:h.autoResize,m.debug=null!==(f=m.debug)&&void 0!==f?f:h.debug,m.videoFrame=null!==(y=m.videoFrame)&&void 0!==y?y:h.videoFrame,m},R=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=d);var o=g(i);if("landscape"===t){var r=1/(1+o),a=o/(1+o);return{rgb:{x:"front"===e?0:a,y:0,width:r,height:1},alpha:{x:"front"===e?r:0,y:"start"===n?0:1-o,width:a,height:o}}}var s=1/(1+o),l=o/(1+o);return{rgb:{x:0,y:"front"===e?0:l,width:1,height:s},alpha:{x:"start"===n?0:1-o,y:"front"===e?s:0,width:o,height:l}}},b=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},w=function(t,e,i){if(void 0===i&&(i=!1),i)throw f(e);if(!t)throw function(t){return new v("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},E=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},A=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=m(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw f("updateConfig");var i=this.config,n=this.playing,o=void 0!==t.src&&t.src!==i.src,r=o&&(n||this.resumeOnReady),a=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var s=this.config;if(o&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(s.muted),void 0!==t.loop&&this.setLoop(s.loop),void 0!==t.playbackRate&&this.setPlaybackRate(s.playbackRate),r){this.resumeOnReady=!0;var l=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&l===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!a||o||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,s)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||c),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,a=t.crossOrigin;this.resetReady();var s=this.video=document.createElement("video");if(s.crossOrigin=null!=a?a:"anonymous",s.poster=i||c,s.src=e,s.autoplay=!1,s.preload="auto",s.playbackRate=n,s.loop=r,s.muted=o,o&&s.setAttribute("muted",""),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline",""),s.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var l=this.config.width||this.container.offsetWidth,u=this.config.height||this.container.offsetHeight;s.style.display="block",s.style.width=l?"".concat(l,"px"):"100%",s.style.height=u?"".concat(u,"px"):"100%",s.style.visibility=this.config.autoShow?"visible":"hidden",s.style.pointerEvents="none",this.container.appendChild(s)}else s.style.position="absolute",s.style.width="0",s.style.height="0",s.style.overflow="hidden",s.style.pointerEvents="none",document.body.appendChild(s);this.bindInstance(),this.addEvent(),s.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,i;return l(this,void 0,void 0,(function(){var n,o,r,a;return u(this,(function(s){switch(s.label){case 0:w(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,n=this.video,o=++this.playRequestId,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.play()];case 2:return r=s.sent(),this.destroyed||o!==this.playRequestId||n!==this.video||n.paused||n.ended?[2,r]:(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame(),[2,r]);case 3:a=s.sent();try{this.destroyed||o!==this.playRequestId||null===(i=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===i||i.call(e,a)}finally{throw a}case 4:return[2]}}))}))},t.prototype.pause=function(){w(this.video,"pause",this.destroyed),this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){w(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw f("setSrc");this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){w(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){w(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){w(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){w(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,o=t.container;if(e&&i){var r=y(),a=i.width||(null==o?void 0:o.offsetWidth)||(n?n.width/r:e.videoWidth),s=i.height||(null==o?void 0:o.offsetHeight)||(n?n.height/r:e.videoHeight),l=a,u=s;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var h=function(t,e,i,n,o){if(void 0===n&&(n=1),void 0===o&&(o=d),0===n)return t/e;var r=R(i,"front",n,o).rgb;return t*r.width/(e*r.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),c=a||e.videoWidth,v=s||e.videoHeight,p=void 0;if("width"===i.autoResize||"height"===i.autoResize)p=i.autoResize;else p=h>=c/v?"width":"height";l="width"===p?c:Math.round(v*h),u="width"===p?Math.round(c/h):v}var f=u*r;n&&l&&u&&(l*r!==this.canvasWidth||f!==this.canvasHeight)?(!function(t,e,i){var n=y();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,l,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=l?"".concat(l,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),C=function(t){function e(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return a(e,t),e.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},e.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},e.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},e.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},e.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var u=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(u,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(u);var d=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(d,0),r},e.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=d);var o=[-1,1,1,1,-1,-1,1,-1],r=R(t,e,i,n),a=r.rgb,s=r.alpha,l=b(a),u=b(s),h=[];return o.forEach((function(t,e){e%2==0&&(h=h.concat(o.slice(e,e+2)).concat(l.slice(e,e+2)).concat(u.slice(e,e+2)))})),new Float32Array(h)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},e.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},e.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},e.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&E(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},e.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,u=i.program,d=function(e){try{e()}catch(e){null!=t||(t=e)}};if(d((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(u&&r&&d((function(){return o.detachShader(u,r)})),u&&a&&d((function(){return o.detachShader(u,a)})),r&&d((function(){return o.deleteShader(r)})),a&&d((function(){return o.deleteShader(a)})),s&&d((function(){return o.deleteTexture(s)})),l&&d((function(){return o.deleteBuffer(l)})),u&&d((function(){return o.deleteProgram(u)})),d((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},e}(A),P=function(t){function e(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return a(e,t),e.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},e.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},e.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},e.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,u=t.config;if(e&&i&&n&&o&&E(n)&&r&&a&&s&&l){var d=R(u.orientation,u.side,u.alphaScale,u.alphaAlign),h=d.rgb,c=d.alpha;e.drawImage(n,h.x*r,h.y*a,h.width*r,h.height*a,0,0,s,l);var v=e.getImageData(0,0,s,l),p=v.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var f=i.getImageData(0,0,s,l).data,y=3;y<p.length;y+=4)p[y]=f[y-3];e.putImageData(v,0,0)}},e.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},e}(A),_=function(t){function e(e){return t.call(this,e,!0)||this}return a(e,t),e.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},e}(A),S=["crossOrigin"],x=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=m(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new _(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=y(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new C(t,a,s):new P(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,i){var n,o=this;(null===(n=this.config)||void 0===n?void 0:n.src)&&t.whenReady().then((function(){return l(o,void 0,void 0,(function(){var n;return u(this,(function(o){switch(o.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:i?[4,t.play()]:[3,2];case 1:o.sent(),o.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(i||(null===(n=this.config)||void 0===n?void 0:n.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){o.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playing;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw f(t);if(!this.render)throw function(t){return new v("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return l(this,void 0,void 0,(function(){var e,i;return u(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw f("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=m(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||S.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}(),T=e((function(e,r){var a=i(null),l=i(null),u=i(e);return u.current=e,n((function(){var t,e,i,n,o,r,s,h,c,v,p,f,y;if(a.current){var g=u.current;return l.current=new x({container:a.current,src:g.src,poster:g.poster,width:g.width,height:g.height,crossOrigin:g.crossOrigin,muted:null===(t=g.muted)||void 0===t||t,loop:null!==(e=g.loop)&&void 0!==e&&e,playbackRate:null!==(i=g.playbackRate)&&void 0!==i?i:1,fps:g.fps,orientation:null!==(n=g.orientation)&&void 0!==n?n:"landscape",side:null!==(o=g.side)&&void 0!==o?o:"front",alphaScale:null!==(r=g.alphaScale)&&void 0!==r?r:1,alphaAlign:null!==(s=g.alphaAlign)&&void 0!==s?s:d,videoFrame:null!==(h=g.videoFrame)&&void 0!==h&&h,debug:null!==(c=g.debug)&&void 0!==c&&c,autoShow:null!==(v=g.autoShow)&&void 0!==v&&v,autoClear:null===(p=g.autoClear)||void 0===p||p,autoDestroy:null!==(f=g.autoDestroy)&&void 0!==f&&f,autoResize:null!==(y=g.autoResize)&&void 0!==y?y:"contain",onInitSuccess:function(){var t,e;return null===(e=(t=u.current).onInitSuccess)||void 0===e?void 0:e.call(t)},onInitError:function(t){var e,i;return null===(i=(e=u.current).onInitError)||void 0===i?void 0:i.call(e,t)},onLoad:function(){var t,e;return null===(e=(t=u.current).onLoad)||void 0===e?void 0:e.call(t)},onCanPlay:function(){var t,e;return null===(e=(t=u.current).onCanPlay)||void 0===e?void 0:e.call(t)},onPlay:function(){var t,e;return null===(e=(t=u.current).onPlay)||void 0===e?void 0:e.call(t)},onLoop:function(){var t,e;return null===(e=(t=u.current).onLoop)||void 0===e?void 0:e.call(t)},onPause:function(){var t,e;return null===(e=(t=u.current).onPause)||void 0===e?void 0:e.call(t)},onEnded:function(){var t,e;return null===(e=(t=u.current).onEnded)||void 0===e?void 0:e.call(t)},onError:function(t){var e,i;return null===(i=(e=u.current).onError)||void 0===i?void 0:i.call(e,t)},onDestroy:function(){var t,e;return null===(e=(t=u.current).onDestroy)||void 0===e?void 0:e.call(t)}}),function(){var t;null===(t=l.current)||void 0===t||t.destroy(),l.current=null}}}),[]),n((function(){var t,e,i,n,o,r,a,h,c,v,p,f,y,g,m=u.current,R=s(s({},null!=m.src?{src:m.src}:{}),{poster:m.poster,width:m.width,height:m.height,crossOrigin:m.crossOrigin,muted:null===(t=m.muted)||void 0===t||t,loop:null!==(e=m.loop)&&void 0!==e&&e,playbackRate:null!==(i=m.playbackRate)&&void 0!==i?i:1,fps:m.fps,orientation:null!==(n=m.orientation)&&void 0!==n?n:"landscape",side:null!==(o=m.side)&&void 0!==o?o:"front",alphaScale:null!==(r=m.alphaScale)&&void 0!==r?r:1,alphaAlign:null!==(a=m.alphaAlign)&&void 0!==a?a:d,videoFrame:null!==(h=m.videoFrame)&&void 0!==h&&h,debug:null!==(c=m.debug)&&void 0!==c&&c,autoShow:null!==(v=m.autoShow)&&void 0!==v&&v,autoClear:null===(p=m.autoClear)||void 0===p||p,autoDestroy:null!==(f=m.autoDestroy)&&void 0!==f&&f,autoResize:null!==(y=m.autoResize)&&void 0!==y?y:"contain"});null===(g=l.current)||void 0===g||g.updateConfig(R)}),[e.src,e.poster,e.width,e.height,e.crossOrigin,e.muted,e.loop,e.playbackRate,e.fps,e.orientation,e.side,e.alphaScale,e.alphaAlign,e.videoFrame,e.debug,e.autoShow,e.autoClear,e.autoDestroy,e.autoResize]),o(r,(function(){return{play:function(){var t;return null===(t=l.current)||void 0===t?void 0:t.play()},updateConfig:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.updateConfig(t)},pause:function(){var t;return null===(t=l.current)||void 0===t?void 0:t.pause()},destroy:function(){var t;null===(t=l.current)||void 0===t||t.destroy(),l.current=null},reset:function(){var t;return null===(t=l.current)||void 0===t?void 0:t.reset()},setSrc:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setSrc(t)},setCurrentTime:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setCurrentTime(t)},setMute:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setMute(t)},setLoop:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setLoop(t)},setPlaybackRate:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setPlaybackRate(t)},getPlayer:function(){return l.current}}})),t.createElement("div",{ref:a,className:e.className,style:e.style})}));T.displayName="AlphaVideoPlayer";export{v as AlphaVideoPlayerError,T as default,p as isAlphaVideoPlayerError};
1
+ import t,{forwardRef as e,useRef as i,useEffect as n,useImperativeHandle as o}from"react";var r=function(t,e){return r=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},r(t,e)};function a(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}r(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var s=function(){return s=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},s.apply(this,arguments)};function l(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function u(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var d="start",h={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:d,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},c="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",p=function(t){function e(i,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=i,r.action=n,Object.setPrototypeOf(r,e.prototype),r}return a(e,t),e}(Error),v=function(t){return t instanceof p||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},f=function(t){return new p("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},y=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},g=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},m=function(t,e){var i,n,o,r,a,s,l,u,c,p,v,f,y,m=Object.assign({},h,e||{},t);return m.playbackRate=null!==(i=m.playbackRate)&&void 0!==i?i:h.playbackRate,m.muted=null!==(n=m.muted)&&void 0!==n?n:h.muted,m.loop=null!==(o=m.loop)&&void 0!==o?o:h.loop,m.fps=null!==(r=m.fps)&&void 0!==r?r:h.fps,m.orientation=null!==(a=m.orientation)&&void 0!==a?a:h.orientation,m.side=null!==(s=m.side)&&void 0!==s?s:h.side,m.alphaScale=g(m.alphaScale),m.alphaAlign=null!==(l=m.alphaAlign)&&void 0!==l?l:d,m.autoShow=null!==(u=m.autoShow)&&void 0!==u?u:h.autoShow,m.autoClear=null!==(c=m.autoClear)&&void 0!==c?c:h.autoClear,m.autoDestroy=null!==(p=m.autoDestroy)&&void 0!==p?p:h.autoDestroy,m.autoResize=null!==(v=m.autoResize)&&void 0!==v?v:h.autoResize,m.debug=null!==(f=m.debug)&&void 0!==f?f:h.debug,m.videoFrame=null!==(y=m.videoFrame)&&void 0!==y?y:h.videoFrame,m},R=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=d);var o=g(i);if("landscape"===t){var r=1/(1+o),a=o/(1+o);return{rgb:{x:"front"===e?0:a,y:0,width:r,height:1},alpha:{x:"front"===e?r:0,y:"start"===n?0:1-o,width:a,height:o}}}var s=1/(1+o),l=o/(1+o);return{rgb:{x:0,y:"front"===e?0:l,width:1,height:s},alpha:{x:"start"===n?0:1-o,y:"front"===e?s:0,width:o,height:l}}},b=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},w=function(t,e,i){if(void 0===i&&(i=!1),i)throw f(e);if(!t)throw function(t){return new p("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},E=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},A=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.playPending=!1,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"playRequested",{get:function(){return this.playing||this.playPending||this.resumeOnReady},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=m(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw f("updateConfig");var i=this.config,n=this.playing,o=this.playRequested,r=void 0!==t.src&&t.src!==i.src,a=r&&o,s=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var l=this.config;if(r&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(l.muted),void 0!==t.loop&&this.setLoop(l.loop),void 0!==t.playbackRate&&this.setPlaybackRate(l.playbackRate),a){this.resumeOnReady=!0;var u=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&u===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!s||r||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,l)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||c),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,a=t.crossOrigin;this.resetReady();var s=this.video=document.createElement("video");if(s.crossOrigin=null!=a?a:"anonymous",s.poster=i||c,s.src=e,s.autoplay=!1,s.preload="auto",s.playbackRate=n,s.loop=r,s.muted=o,o&&s.setAttribute("muted",""),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline",""),s.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var l=this.config.width||this.container.offsetWidth,u=this.config.height||this.container.offsetHeight;s.style.display="block",s.style.width=l?"".concat(l,"px"):"100%",s.style.height=u?"".concat(u,"px"):"100%",s.style.visibility=this.config.autoShow?"visible":"hidden",s.style.pointerEvents="none",this.container.appendChild(s)}else s.style.position="absolute",s.style.width="0",s.style.height="0",s.style.overflow="hidden",s.style.pointerEvents="none",document.body.appendChild(s);this.bindInstance(),this.addEvent(),s.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,i;return l(this,void 0,void 0,(function(){var n,o,r,a;return u(this,(function(s){switch(s.label){case 0:w(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,n=this.video,o=++this.playRequestId,this.playPending=!0,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.play()];case 2:return r=s.sent(),this.destroyed||o!==this.playRequestId||n!==this.video?[2,r]:(this.playPending=!1,n.paused||n.ended||(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame()),[2,r]);case 3:if(a=s.sent(),this.destroyed||o!==this.playRequestId||n!==this.video)return[2];this.playPending=!1;try{null===(i=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===i||i.call(e,a)}finally{throw a}case 4:return[2]}}))}))},t.prototype.pause=function(){w(this.video,"pause",this.destroyed),this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){w(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw f("setSrc");this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){w(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){w(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){w(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){w(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,o=t.container;if(e&&i){var r=y(),a=i.width||(null==o?void 0:o.offsetWidth)||(n?n.width/r:e.videoWidth),s=i.height||(null==o?void 0:o.offsetHeight)||(n?n.height/r:e.videoHeight),l=a,u=s;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var h=function(t,e,i,n,o){if(void 0===n&&(n=1),void 0===o&&(o=d),0===n)return t/e;var r=R(i,"front",n,o).rgb;return t*r.width/(e*r.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),c=a||e.videoWidth,p=s||e.videoHeight,v=void 0;if("width"===i.autoResize||"height"===i.autoResize)v=i.autoResize;else v=h>=c/p?"width":"height";l="width"===v?c:Math.round(p*h),u="width"===v?Math.round(c/h):p}var f=u*r;n&&l&&u&&(l*r!==this.canvasWidth||f!==this.canvasHeight)?(!function(t,e,i){var n=y();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,l,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=l?"".concat(l,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.playPending=!1,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,this.playPending=!1,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),P=function(t){function e(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return a(e,t),e.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},e.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},e.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},e.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},e.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var u=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(u,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(u);var d=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(d,0),r},e.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=d);var o=[-1,1,1,1,-1,-1,1,-1],r=R(t,e,i,n),a=r.rgb,s=r.alpha,l=b(a),u=b(s),h=[];return o.forEach((function(t,e){e%2==0&&(h=h.concat(o.slice(e,e+2)).concat(l.slice(e,e+2)).concat(u.slice(e,e+2)))})),new Float32Array(h)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},e.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},e.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},e.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&E(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},e.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,u=i.program,d=function(e){try{e()}catch(e){null!=t||(t=e)}};if(d((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(u&&r&&d((function(){return o.detachShader(u,r)})),u&&a&&d((function(){return o.detachShader(u,a)})),r&&d((function(){return o.deleteShader(r)})),a&&d((function(){return o.deleteShader(a)})),s&&d((function(){return o.deleteTexture(s)})),l&&d((function(){return o.deleteBuffer(l)})),u&&d((function(){return o.deleteProgram(u)})),d((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},e}(A),C=function(t){function e(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return a(e,t),e.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},e.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},e.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},e.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,u=t.config;if(e&&i&&n&&o&&E(n)&&r&&a&&s&&l){var d=R(u.orientation,u.side,u.alphaScale,u.alphaAlign),h=d.rgb,c=d.alpha;e.drawImage(n,h.x*r,h.y*a,h.width*r,h.height*a,0,0,s,l);var p=e.getImageData(0,0,s,l),v=p.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var f=i.getImageData(0,0,s,l).data,y=3;y<v.length;y+=4)v[y]=f[y-3];e.putImageData(p,0,0)}},e.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},e}(A),_=function(t){function e(e){return t.call(this,e,!0)||this}return a(e,t),e.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},e}(A),S=["crossOrigin"],x=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=m(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new _(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=y(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new P(t,a,s):new C(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,i){var n,o=this;(null===(n=this.config)||void 0===n?void 0:n.src)&&t.whenReady().then((function(){return l(o,void 0,void 0,(function(){var n;return u(this,(function(o){switch(o.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:i?[4,t.play()]:[3,2];case 1:o.sent(),o.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(i||(null===(n=this.config)||void 0===n?void 0:n.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){o.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playRequested;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw f(t);if(!this.render)throw function(t){return new p("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return l(this,void 0,void 0,(function(){var e,i;return u(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw f("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=m(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||S.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}(),T=e((function(e,r){var a=i(null),l=i(null),u=i(e);return u.current=e,n((function(){var t,e,i,n,o,r,s,h,c,p,v,f,y;if(a.current){var g=u.current;return l.current=new x({container:a.current,src:g.src,poster:g.poster,width:g.width,height:g.height,crossOrigin:g.crossOrigin,muted:null===(t=g.muted)||void 0===t||t,loop:null!==(e=g.loop)&&void 0!==e&&e,playbackRate:null!==(i=g.playbackRate)&&void 0!==i?i:1,fps:g.fps,orientation:null!==(n=g.orientation)&&void 0!==n?n:"landscape",side:null!==(o=g.side)&&void 0!==o?o:"front",alphaScale:null!==(r=g.alphaScale)&&void 0!==r?r:1,alphaAlign:null!==(s=g.alphaAlign)&&void 0!==s?s:d,videoFrame:null!==(h=g.videoFrame)&&void 0!==h&&h,debug:null!==(c=g.debug)&&void 0!==c&&c,autoShow:null!==(p=g.autoShow)&&void 0!==p&&p,autoClear:null===(v=g.autoClear)||void 0===v||v,autoDestroy:null!==(f=g.autoDestroy)&&void 0!==f&&f,autoResize:null!==(y=g.autoResize)&&void 0!==y?y:"contain",onInitSuccess:function(){var t,e;return null===(e=(t=u.current).onInitSuccess)||void 0===e?void 0:e.call(t)},onInitError:function(t){var e,i;return null===(i=(e=u.current).onInitError)||void 0===i?void 0:i.call(e,t)},onLoad:function(){var t,e;return null===(e=(t=u.current).onLoad)||void 0===e?void 0:e.call(t)},onCanPlay:function(){var t,e;return null===(e=(t=u.current).onCanPlay)||void 0===e?void 0:e.call(t)},onPlay:function(){var t,e;return null===(e=(t=u.current).onPlay)||void 0===e?void 0:e.call(t)},onLoop:function(){var t,e;return null===(e=(t=u.current).onLoop)||void 0===e?void 0:e.call(t)},onPause:function(){var t,e;return null===(e=(t=u.current).onPause)||void 0===e?void 0:e.call(t)},onEnded:function(){var t,e;return null===(e=(t=u.current).onEnded)||void 0===e?void 0:e.call(t)},onError:function(t){var e,i;return null===(i=(e=u.current).onError)||void 0===i?void 0:i.call(e,t)},onDestroy:function(){var t,e;return null===(e=(t=u.current).onDestroy)||void 0===e?void 0:e.call(t)}}),function(){var t;null===(t=l.current)||void 0===t||t.destroy(),l.current=null}}}),[]),n((function(){var t,e,i,n,o,r,a,h,c,p,v,f,y,g,m=u.current,R=s(s({},null!=m.src?{src:m.src}:{}),{poster:m.poster,width:m.width,height:m.height,crossOrigin:m.crossOrigin,muted:null===(t=m.muted)||void 0===t||t,loop:null!==(e=m.loop)&&void 0!==e&&e,playbackRate:null!==(i=m.playbackRate)&&void 0!==i?i:1,fps:m.fps,orientation:null!==(n=m.orientation)&&void 0!==n?n:"landscape",side:null!==(o=m.side)&&void 0!==o?o:"front",alphaScale:null!==(r=m.alphaScale)&&void 0!==r?r:1,alphaAlign:null!==(a=m.alphaAlign)&&void 0!==a?a:d,videoFrame:null!==(h=m.videoFrame)&&void 0!==h&&h,debug:null!==(c=m.debug)&&void 0!==c&&c,autoShow:null!==(p=m.autoShow)&&void 0!==p&&p,autoClear:null===(v=m.autoClear)||void 0===v||v,autoDestroy:null!==(f=m.autoDestroy)&&void 0!==f&&f,autoResize:null!==(y=m.autoResize)&&void 0!==y?y:"contain"});null===(g=l.current)||void 0===g||g.updateConfig(R)}),[e.src,e.poster,e.width,e.height,e.crossOrigin,e.muted,e.loop,e.playbackRate,e.fps,e.orientation,e.side,e.alphaScale,e.alphaAlign,e.videoFrame,e.debug,e.autoShow,e.autoClear,e.autoDestroy,e.autoResize]),o(r,(function(){return{play:function(){var t;return null===(t=l.current)||void 0===t?void 0:t.play()},updateConfig:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.updateConfig(t)},pause:function(){var t;return null===(t=l.current)||void 0===t?void 0:t.pause()},destroy:function(){var t;null===(t=l.current)||void 0===t||t.destroy(),l.current=null},reset:function(){var t;return null===(t=l.current)||void 0===t?void 0:t.reset()},setSrc:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setSrc(t)},setCurrentTime:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setCurrentTime(t)},setMute:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setMute(t)},setLoop:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setLoop(t)},setPlaybackRate:function(t){var e;return null===(e=l.current)||void 0===e?void 0:e.setPlaybackRate(t)},getPlayer:function(){return l.current}}})),t.createElement("div",{ref:a,className:e.className,style:e.style})}));T.displayName="AlphaVideoPlayer";export{p as AlphaVideoPlayerError,T as default,v as isAlphaVideoPlayerError};
package/dist/vue2.js CHANGED
@@ -1 +1 @@
1
- import t from"vue";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},e(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function o(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var a="start",s={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:a,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",h=function(t){function e(i,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=i,r.action=n,Object.setPrototypeOf(r,e.prototype),r}return i(e,t),e}(Error),u=function(t){return t instanceof h||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},d=function(t){return new h("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},c=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},p=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},f=function(t,e){var i,n,o,r,l,h,u,d,c,f,v,y,g,m=Object.assign({},s,e||{},t);return m.playbackRate=null!==(i=m.playbackRate)&&void 0!==i?i:s.playbackRate,m.muted=null!==(n=m.muted)&&void 0!==n?n:s.muted,m.loop=null!==(o=m.loop)&&void 0!==o?o:s.loop,m.fps=null!==(r=m.fps)&&void 0!==r?r:s.fps,m.orientation=null!==(l=m.orientation)&&void 0!==l?l:s.orientation,m.side=null!==(h=m.side)&&void 0!==h?h:s.side,m.alphaScale=p(m.alphaScale),m.alphaAlign=null!==(u=m.alphaAlign)&&void 0!==u?u:a,m.autoShow=null!==(d=m.autoShow)&&void 0!==d?d:s.autoShow,m.autoClear=null!==(c=m.autoClear)&&void 0!==c?c:s.autoClear,m.autoDestroy=null!==(f=m.autoDestroy)&&void 0!==f?f:s.autoDestroy,m.autoResize=null!==(v=m.autoResize)&&void 0!==v?v:s.autoResize,m.debug=null!==(y=m.debug)&&void 0!==y?y:s.debug,m.videoFrame=null!==(g=m.videoFrame)&&void 0!==g?g:s.videoFrame,m},v=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=a);var o=p(i);if("landscape"===t){var r=1/(1+o),s=o/(1+o);return{rgb:{x:"front"===e?0:s,y:0,width:r,height:1},alpha:{x:"front"===e?r:0,y:"start"===n?0:1-o,width:s,height:o}}}var l=1/(1+o),h=o/(1+o);return{rgb:{x:0,y:"front"===e?0:h,width:1,height:l},alpha:{x:"start"===n?0:1-o,y:"front"===e?l:0,width:o,height:h}}},y=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},g=function(t,e,i){if(void 0===i&&(i=!1),i)throw d(e);if(!t)throw function(t){return new h("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},m=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},b=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=f(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw d("updateConfig");var i=this.config,n=this.playing,o=void 0!==t.src&&t.src!==i.src,r=o&&(n||this.resumeOnReady),a=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var s=this.config;if(o&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(s.muted),void 0!==t.loop&&this.setLoop(s.loop),void 0!==t.playbackRate&&this.setPlaybackRate(s.playbackRate),r){this.resumeOnReady=!0;var l=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&l===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!a||o||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,s)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||l),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,a=t.crossOrigin;this.resetReady();var s=this.video=document.createElement("video");if(s.crossOrigin=null!=a?a:"anonymous",s.poster=i||l,s.src=e,s.autoplay=!1,s.preload="auto",s.playbackRate=n,s.loop=r,s.muted=o,o&&s.setAttribute("muted",""),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline",""),s.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var h=this.config.width||this.container.offsetWidth,u=this.config.height||this.container.offsetHeight;s.style.display="block",s.style.width=h?"".concat(h,"px"):"100%",s.style.height=u?"".concat(u,"px"):"100%",s.style.visibility=this.config.autoShow?"visible":"hidden",s.style.pointerEvents="none",this.container.appendChild(s)}else s.style.position="absolute",s.style.width="0",s.style.height="0",s.style.overflow="hidden",s.style.pointerEvents="none",document.body.appendChild(s);this.bindInstance(),this.addEvent(),s.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,i;return o(this,void 0,void 0,(function(){var n,o,a,s;return r(this,(function(r){switch(r.label){case 0:g(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,n=this.video,o=++this.playRequestId,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,n.play()];case 2:return a=r.sent(),this.destroyed||o!==this.playRequestId||n!==this.video||n.paused||n.ended?[2,a]:(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame(),[2,a]);case 3:s=r.sent();try{this.destroyed||o!==this.playRequestId||null===(i=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===i||i.call(e,s)}finally{throw s}case 4:return[2]}}))}))},t.prototype.pause=function(){g(this.video,"pause",this.destroyed),this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){g(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw d("setSrc");this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){g(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){g(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){g(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){g(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,o=t.container;if(e&&i){var r=c(),s=i.width||(null==o?void 0:o.offsetWidth)||(n?n.width/r:e.videoWidth),l=i.height||(null==o?void 0:o.offsetHeight)||(n?n.height/r:e.videoHeight),h=s,u=l;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var d=function(t,e,i,n,o){if(void 0===n&&(n=1),void 0===o&&(o=a),0===n)return t/e;var r=v(i,"front",n,o).rgb;return t*r.width/(e*r.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),p=s||e.videoWidth,f=l||e.videoHeight,y=void 0;if("width"===i.autoResize||"height"===i.autoResize)y=i.autoResize;else y=d>=p/f?"width":"height";h="width"===y?p:Math.round(f*d),u="width"===y?Math.round(p/d):f}var g=u*r;n&&h&&u&&(h*r!==this.canvasWidth||g!==this.canvasHeight)?(!function(t,e,i){var n=c();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,h,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=h?"".concat(h,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),R=function(t){function e(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return i(e,t),e.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},e.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},e.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},e.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},e.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var h=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(h,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(h);var u=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(u,0),r},e.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=a);var o=[-1,1,1,1,-1,-1,1,-1],r=v(t,e,i,n),s=r.rgb,l=r.alpha,h=y(s),u=y(l),d=[];return o.forEach((function(t,e){e%2==0&&(d=d.concat(o.slice(e,e+2)).concat(h.slice(e,e+2)).concat(u.slice(e,e+2)))})),new Float32Array(d)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},e.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},e.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},e.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&m(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},e.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,h=i.program,u=function(e){try{e()}catch(e){null!=t||(t=e)}};if(u((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(h&&r&&u((function(){return o.detachShader(h,r)})),h&&a&&u((function(){return o.detachShader(h,a)})),r&&u((function(){return o.deleteShader(r)})),a&&u((function(){return o.deleteShader(a)})),s&&u((function(){return o.deleteTexture(s)})),l&&u((function(){return o.deleteBuffer(l)})),h&&u((function(){return o.deleteProgram(h)})),u((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},e}(b),w=function(t){function e(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return i(e,t),e.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},e.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},e.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},e.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,h=t.config;if(e&&i&&n&&o&&m(n)&&r&&a&&s&&l){var u=v(h.orientation,h.side,h.alphaScale,h.alphaAlign),d=u.rgb,c=u.alpha;e.drawImage(n,d.x*r,d.y*a,d.width*r,d.height*a,0,0,s,l);var p=e.getImageData(0,0,s,l),f=p.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var y=i.getImageData(0,0,s,l).data,g=3;g<f.length;g+=4)f[g]=y[g-3];e.putImageData(p,0,0)}},e.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},e}(b),_=function(t){function e(e){return t.call(this,e,!0)||this}return i(e,t),e.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},e}(b),C=["crossOrigin"],E=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=f(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new _(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=c(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new R(t,a,s):new w(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,i){var n,a=this;(null===(n=this.config)||void 0===n?void 0:n.src)&&t.whenReady().then((function(){return o(a,void 0,void 0,(function(){var n;return r(this,(function(o){switch(o.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:i?[4,t.play()]:[3,2];case 1:o.sent(),o.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(i||(null===(n=this.config)||void 0===n?void 0:n.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){a.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playing;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw d(t);if(!this.render)throw function(t){return new h("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return o(this,void 0,void 0,(function(){var e,i;return r(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw d("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=f(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||C.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}(),A=t.extend({name:"AlphaVideoPlayer",props:{src:{type:String,default:void 0},poster:{type:String,default:void 0},width:{type:Number,default:void 0},height:{type:Number,default:void 0},crossOrigin:{type:String,default:void 0},muted:{type:Boolean,default:!0},loop:{type:Boolean,default:!1},playbackRate:{type:Number,default:1},fps:{type:Number,default:0},orientation:{type:String,default:"landscape"},side:{type:String,default:"front"},alphaScale:{type:Number,default:1},alphaAlign:{type:String,default:a},videoFrame:{type:Boolean,default:!1},debug:{type:Boolean,default:!1},autoShow:{type:Boolean,default:!1},autoClear:{type:Boolean,default:!0},autoDestroy:{type:Boolean,default:!1},autoResize:{default:"contain"}},data:function(){return{_player:null}},render:function(t){return t("div",{ref:"container"})},mounted:function(){this._initPlayer()},beforeDestroy:function(){this._destroyPlayer()},watch:{src:function(){this._syncConfig()},poster:function(){this._syncConfig()},width:function(){this._syncConfig()},height:function(){this._syncConfig()},crossOrigin:function(){this._syncConfig()},muted:function(){this._syncConfig()},loop:function(){this._syncConfig()},playbackRate:function(){this._syncConfig()},fps:function(){this._syncConfig()},orientation:function(){this._syncConfig()},side:function(){this._syncConfig()},alphaScale:function(){this._syncConfig()},alphaAlign:function(){this._syncConfig()},videoFrame:function(){this._syncConfig()},debug:function(){this._syncConfig()},autoShow:function(){this._syncConfig()},autoClear:function(){this._syncConfig()},autoDestroy:function(){this._syncConfig()},autoResize:function(){this._syncConfig()}},methods:{_initPlayer:function(){var t=this,e=t.$refs.container;e&&(t._destroyPlayer(),t._player=new E({container:e,src:t.src,poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize,onInitSuccess:function(){return t.$emit("init-success")},onInitError:function(e){return t.$emit("init-error",e)},onLoad:function(){return t.$emit("load")},onCanPlay:function(){return t.$emit("can-play")},onPlay:function(){return t.$emit("play")},onLoop:function(){return t.$emit("loop")},onPause:function(){return t.$emit("pause")},onEnded:function(){return t.$emit("ended")},onError:function(e){return t.$emit("error",e)},onDestroy:function(){return t.$emit("destroy")}}))},_currentConfig:function(){var t=this;return n(n({},null!=t.src?{src:t.src}:{}),{poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize})},_syncConfig:function(){var t;null===(t=this._player)||void 0===t||t.updateConfig(this._currentConfig())},play:function(){var t;return null===(t=this._player)||void 0===t?void 0:t.play()},updateConfig:function(t){var e;null===(e=this._player)||void 0===e||e.updateConfig(t)},pause:function(){var t;null===(t=this._player)||void 0===t||t.pause()},reset:function(){var t;null===(t=this._player)||void 0===t||t.reset()},_destroyPlayer:function(){var t=this;t._player&&(t._player.destroy(),t._player=null)},destroy:function(){this._destroyPlayer()},setSrc:function(t){var e;null===(e=this._player)||void 0===e||e.setSrc(t)},setCurrentTime:function(t){var e;null===(e=this._player)||void 0===e||e.setCurrentTime(t)},setMute:function(t){var e;null===(e=this._player)||void 0===e||e.setMute(t)},setLoop:function(t){var e;null===(e=this._player)||void 0===e||e.setLoop(t)},setPlaybackRate:function(t){var e;null===(e=this._player)||void 0===e||e.setPlaybackRate(t)},getPlayer:function(){return this._player}}});export{h as AlphaVideoPlayerError,A as default,u as isAlphaVideoPlayerError};
1
+ import t from"vue";var e=function(t,i){return e=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},e(t,i)};function i(t,i){if("function"!=typeof i&&null!==i)throw new TypeError("Class extends value "+String(i)+" is not a constructor or null");function n(){this.constructor=t}e(t,i),t.prototype=null===i?Object.create(i):(n.prototype=i.prototype,new n)}var n=function(){return n=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},n.apply(this,arguments)};function o(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function r(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var a="start",s={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:a,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},l="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",h=function(t){function e(i,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=i,r.action=n,Object.setPrototypeOf(r,e.prototype),r}return i(e,t),e}(Error),u=function(t){return t instanceof h||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},d=function(t){return new h("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},c=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},p=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},f=function(t,e){var i,n,o,r,l,h,u,d,c,f,y,v,g,m=Object.assign({},s,e||{},t);return m.playbackRate=null!==(i=m.playbackRate)&&void 0!==i?i:s.playbackRate,m.muted=null!==(n=m.muted)&&void 0!==n?n:s.muted,m.loop=null!==(o=m.loop)&&void 0!==o?o:s.loop,m.fps=null!==(r=m.fps)&&void 0!==r?r:s.fps,m.orientation=null!==(l=m.orientation)&&void 0!==l?l:s.orientation,m.side=null!==(h=m.side)&&void 0!==h?h:s.side,m.alphaScale=p(m.alphaScale),m.alphaAlign=null!==(u=m.alphaAlign)&&void 0!==u?u:a,m.autoShow=null!==(d=m.autoShow)&&void 0!==d?d:s.autoShow,m.autoClear=null!==(c=m.autoClear)&&void 0!==c?c:s.autoClear,m.autoDestroy=null!==(f=m.autoDestroy)&&void 0!==f?f:s.autoDestroy,m.autoResize=null!==(y=m.autoResize)&&void 0!==y?y:s.autoResize,m.debug=null!==(v=m.debug)&&void 0!==v?v:s.debug,m.videoFrame=null!==(g=m.videoFrame)&&void 0!==g?g:s.videoFrame,m},y=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=a);var o=p(i);if("landscape"===t){var r=1/(1+o),s=o/(1+o);return{rgb:{x:"front"===e?0:s,y:0,width:r,height:1},alpha:{x:"front"===e?r:0,y:"start"===n?0:1-o,width:s,height:o}}}var l=1/(1+o),h=o/(1+o);return{rgb:{x:0,y:"front"===e?0:h,width:1,height:l},alpha:{x:"start"===n?0:1-o,y:"front"===e?l:0,width:o,height:h}}},v=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},g=function(t,e,i){if(void 0===i&&(i=!1),i)throw d(e);if(!t)throw function(t){return new h("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},m=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},b=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.playPending=!1,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"playRequested",{get:function(){return this.playing||this.playPending||this.resumeOnReady},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=f(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw d("updateConfig");var i=this.config,n=this.playing,o=this.playRequested,r=void 0!==t.src&&t.src!==i.src,a=r&&o,s=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var l=this.config;if(r&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(l.muted),void 0!==t.loop&&this.setLoop(l.loop),void 0!==t.playbackRate&&this.setPlaybackRate(l.playbackRate),a){this.resumeOnReady=!0;var h=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&h===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!s||r||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,l)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||l),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,a=t.crossOrigin;this.resetReady();var s=this.video=document.createElement("video");if(s.crossOrigin=null!=a?a:"anonymous",s.poster=i||l,s.src=e,s.autoplay=!1,s.preload="auto",s.playbackRate=n,s.loop=r,s.muted=o,o&&s.setAttribute("muted",""),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline",""),s.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var h=this.config.width||this.container.offsetWidth,u=this.config.height||this.container.offsetHeight;s.style.display="block",s.style.width=h?"".concat(h,"px"):"100%",s.style.height=u?"".concat(u,"px"):"100%",s.style.visibility=this.config.autoShow?"visible":"hidden",s.style.pointerEvents="none",this.container.appendChild(s)}else s.style.position="absolute",s.style.width="0",s.style.height="0",s.style.overflow="hidden",s.style.pointerEvents="none",document.body.appendChild(s);this.bindInstance(),this.addEvent(),s.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,i;return o(this,void 0,void 0,(function(){var n,o,a,s;return r(this,(function(r){switch(r.label){case 0:g(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,n=this.video,o=++this.playRequestId,this.playPending=!0,r.label=1;case 1:return r.trys.push([1,3,,4]),[4,n.play()];case 2:return a=r.sent(),this.destroyed||o!==this.playRequestId||n!==this.video?[2,a]:(this.playPending=!1,n.paused||n.ended||(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame()),[2,a]);case 3:if(s=r.sent(),this.destroyed||o!==this.playRequestId||n!==this.video)return[2];this.playPending=!1;try{null===(i=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===i||i.call(e,s)}finally{throw s}case 4:return[2]}}))}))},t.prototype.pause=function(){g(this.video,"pause",this.destroyed),this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){g(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw d("setSrc");this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){g(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){g(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){g(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){g(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,o=t.container;if(e&&i){var r=c(),s=i.width||(null==o?void 0:o.offsetWidth)||(n?n.width/r:e.videoWidth),l=i.height||(null==o?void 0:o.offsetHeight)||(n?n.height/r:e.videoHeight),h=s,u=l;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var d=function(t,e,i,n,o){if(void 0===n&&(n=1),void 0===o&&(o=a),0===n)return t/e;var r=y(i,"front",n,o).rgb;return t*r.width/(e*r.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),p=s||e.videoWidth,f=l||e.videoHeight,v=void 0;if("width"===i.autoResize||"height"===i.autoResize)v=i.autoResize;else v=d>=p/f?"width":"height";h="width"===v?p:Math.round(f*d),u="width"===v?Math.round(p/d):f}var g=u*r;n&&h&&u&&(h*r!==this.canvasWidth||g!==this.canvasHeight)?(!function(t,e,i){var n=c();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,h,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=h?"".concat(h,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.playPending=!1,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,this.playPending=!1,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),R=function(t){function e(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return i(e,t),e.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},e.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},e.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},e.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},e.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var h=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(h,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(h);var u=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(u,0),r},e.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=a);var o=[-1,1,1,1,-1,-1,1,-1],r=y(t,e,i,n),s=r.rgb,l=r.alpha,h=v(s),u=v(l),d=[];return o.forEach((function(t,e){e%2==0&&(d=d.concat(o.slice(e,e+2)).concat(h.slice(e,e+2)).concat(u.slice(e,e+2)))})),new Float32Array(d)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},e.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},e.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},e.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&m(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},e.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,h=i.program,u=function(e){try{e()}catch(e){null!=t||(t=e)}};if(u((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(h&&r&&u((function(){return o.detachShader(h,r)})),h&&a&&u((function(){return o.detachShader(h,a)})),r&&u((function(){return o.deleteShader(r)})),a&&u((function(){return o.deleteShader(a)})),s&&u((function(){return o.deleteTexture(s)})),l&&u((function(){return o.deleteBuffer(l)})),h&&u((function(){return o.deleteProgram(h)})),u((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},e}(b),w=function(t){function e(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return i(e,t),e.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},e.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},e.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},e.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,h=t.config;if(e&&i&&n&&o&&m(n)&&r&&a&&s&&l){var u=y(h.orientation,h.side,h.alphaScale,h.alphaAlign),d=u.rgb,c=u.alpha;e.drawImage(n,d.x*r,d.y*a,d.width*r,d.height*a,0,0,s,l);var p=e.getImageData(0,0,s,l),f=p.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var v=i.getImageData(0,0,s,l).data,g=3;g<f.length;g+=4)f[g]=v[g-3];e.putImageData(p,0,0)}},e.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},e}(b),_=function(t){function e(e){return t.call(this,e,!0)||this}return i(e,t),e.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},e}(b),C=["crossOrigin"],E=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=f(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new _(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=c(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new R(t,a,s):new w(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,i){var n,a=this;(null===(n=this.config)||void 0===n?void 0:n.src)&&t.whenReady().then((function(){return o(a,void 0,void 0,(function(){var n;return r(this,(function(o){switch(o.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:i?[4,t.play()]:[3,2];case 1:o.sent(),o.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(i||(null===(n=this.config)||void 0===n?void 0:n.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){a.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playRequested;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw d(t);if(!this.render)throw function(t){return new h("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return o(this,void 0,void 0,(function(){var e,i;return r(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw d("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=f(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||C.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}(),A=t.extend({name:"AlphaVideoPlayer",props:{src:{type:String,default:void 0},poster:{type:String,default:void 0},width:{type:Number,default:void 0},height:{type:Number,default:void 0},crossOrigin:{type:String,default:void 0},muted:{type:Boolean,default:!0},loop:{type:Boolean,default:!1},playbackRate:{type:Number,default:1},fps:{type:Number,default:0},orientation:{type:String,default:"landscape"},side:{type:String,default:"front"},alphaScale:{type:Number,default:1},alphaAlign:{type:String,default:a},videoFrame:{type:Boolean,default:!1},debug:{type:Boolean,default:!1},autoShow:{type:Boolean,default:!1},autoClear:{type:Boolean,default:!0},autoDestroy:{type:Boolean,default:!1},autoResize:{default:"contain"}},data:function(){return{_player:null}},render:function(t){return t("div",{ref:"container"})},mounted:function(){this._initPlayer()},beforeDestroy:function(){this._destroyPlayer()},watch:{src:function(){this._syncConfig()},poster:function(){this._syncConfig()},width:function(){this._syncConfig()},height:function(){this._syncConfig()},crossOrigin:function(){this._syncConfig()},muted:function(){this._syncConfig()},loop:function(){this._syncConfig()},playbackRate:function(){this._syncConfig()},fps:function(){this._syncConfig()},orientation:function(){this._syncConfig()},side:function(){this._syncConfig()},alphaScale:function(){this._syncConfig()},alphaAlign:function(){this._syncConfig()},videoFrame:function(){this._syncConfig()},debug:function(){this._syncConfig()},autoShow:function(){this._syncConfig()},autoClear:function(){this._syncConfig()},autoDestroy:function(){this._syncConfig()},autoResize:function(){this._syncConfig()}},methods:{_initPlayer:function(){var t=this,e=t.$refs.container;e&&(t._destroyPlayer(),t._player=new E({container:e,src:t.src,poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize,onInitSuccess:function(){return t.$emit("init-success")},onInitError:function(e){return t.$emit("init-error",e)},onLoad:function(){return t.$emit("load")},onCanPlay:function(){return t.$emit("can-play")},onPlay:function(){return t.$emit("play")},onLoop:function(){return t.$emit("loop")},onPause:function(){return t.$emit("pause")},onEnded:function(){return t.$emit("ended")},onError:function(e){return t.$emit("error",e)},onDestroy:function(){return t.$emit("destroy")}}))},_currentConfig:function(){var t=this;return n(n({},null!=t.src?{src:t.src}:{}),{poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize})},_syncConfig:function(){var t;null===(t=this._player)||void 0===t||t.updateConfig(this._currentConfig())},play:function(){var t;return null===(t=this._player)||void 0===t?void 0:t.play()},updateConfig:function(t){var e;null===(e=this._player)||void 0===e||e.updateConfig(t)},pause:function(){var t;null===(t=this._player)||void 0===t||t.pause()},reset:function(){var t;null===(t=this._player)||void 0===t||t.reset()},_destroyPlayer:function(){var t=this;t._player&&(t._player.destroy(),t._player=null)},destroy:function(){this._destroyPlayer()},setSrc:function(t){var e;null===(e=this._player)||void 0===e||e.setSrc(t)},setCurrentTime:function(t){var e;null===(e=this._player)||void 0===e||e.setCurrentTime(t)},setMute:function(t){var e;null===(e=this._player)||void 0===e||e.setMute(t)},setLoop:function(t){var e;null===(e=this._player)||void 0===e||e.setLoop(t)},setPlaybackRate:function(t){var e;null===(e=this._player)||void 0===e||e.setPlaybackRate(t)},getPlayer:function(){return this._player}}});export{h as AlphaVideoPlayerError,A as default,u as isAlphaVideoPlayerError};
package/dist/vue3.js CHANGED
@@ -1 +1 @@
1
- import{defineComponent as t,ref as e,watch as i,onMounted as n,onBeforeUnmount as o,h as r}from"vue";var a=function(t,e){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},a(t,e)};function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var l=function(){return l=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},l.apply(this,arguments)};function u(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function d(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var h="start",c={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:h,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},p="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",f=function(t){function e(i,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=i,r.action=n,Object.setPrototypeOf(r,e.prototype),r}return s(e,t),e}(Error),v=function(t){return t instanceof f||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},y=function(t){return new f("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},g=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},m=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},b=function(t,e){var i,n,o,r,a,s,l,u,d,p,f,v,y,g=Object.assign({},c,e||{},t);return g.playbackRate=null!==(i=g.playbackRate)&&void 0!==i?i:c.playbackRate,g.muted=null!==(n=g.muted)&&void 0!==n?n:c.muted,g.loop=null!==(o=g.loop)&&void 0!==o?o:c.loop,g.fps=null!==(r=g.fps)&&void 0!==r?r:c.fps,g.orientation=null!==(a=g.orientation)&&void 0!==a?a:c.orientation,g.side=null!==(s=g.side)&&void 0!==s?s:c.side,g.alphaScale=m(g.alphaScale),g.alphaAlign=null!==(l=g.alphaAlign)&&void 0!==l?l:h,g.autoShow=null!==(u=g.autoShow)&&void 0!==u?u:c.autoShow,g.autoClear=null!==(d=g.autoClear)&&void 0!==d?d:c.autoClear,g.autoDestroy=null!==(p=g.autoDestroy)&&void 0!==p?p:c.autoDestroy,g.autoResize=null!==(f=g.autoResize)&&void 0!==f?f:c.autoResize,g.debug=null!==(v=g.debug)&&void 0!==v?v:c.debug,g.videoFrame=null!==(y=g.videoFrame)&&void 0!==y?y:c.videoFrame,g},R=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=h);var o=m(i);if("landscape"===t){var r=1/(1+o),a=o/(1+o);return{rgb:{x:"front"===e?0:a,y:0,width:r,height:1},alpha:{x:"front"===e?r:0,y:"start"===n?0:1-o,width:a,height:o}}}var s=1/(1+o),l=o/(1+o);return{rgb:{x:0,y:"front"===e?0:l,width:1,height:s},alpha:{x:"start"===n?0:1-o,y:"front"===e?s:0,width:o,height:l}}},w=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},E=function(t,e,i){if(void 0===i&&(i=!1),i)throw y(e);if(!t)throw function(t){return new f("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},A=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},C=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=b(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw y("updateConfig");var i=this.config,n=this.playing,o=void 0!==t.src&&t.src!==i.src,r=o&&(n||this.resumeOnReady),a=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var s=this.config;if(o&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(s.muted),void 0!==t.loop&&this.setLoop(s.loop),void 0!==t.playbackRate&&this.setPlaybackRate(s.playbackRate),r){this.resumeOnReady=!0;var l=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&l===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!a||o||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,s)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||p),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,a=t.crossOrigin;this.resetReady();var s=this.video=document.createElement("video");if(s.crossOrigin=null!=a?a:"anonymous",s.poster=i||p,s.src=e,s.autoplay=!1,s.preload="auto",s.playbackRate=n,s.loop=r,s.muted=o,o&&s.setAttribute("muted",""),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline",""),s.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var l=this.config.width||this.container.offsetWidth,u=this.config.height||this.container.offsetHeight;s.style.display="block",s.style.width=l?"".concat(l,"px"):"100%",s.style.height=u?"".concat(u,"px"):"100%",s.style.visibility=this.config.autoShow?"visible":"hidden",s.style.pointerEvents="none",this.container.appendChild(s)}else s.style.position="absolute",s.style.width="0",s.style.height="0",s.style.overflow="hidden",s.style.pointerEvents="none",document.body.appendChild(s);this.bindInstance(),this.addEvent(),s.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,i;return u(this,void 0,void 0,(function(){var n,o,r,a;return d(this,(function(s){switch(s.label){case 0:E(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,n=this.video,o=++this.playRequestId,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.play()];case 2:return r=s.sent(),this.destroyed||o!==this.playRequestId||n!==this.video||n.paused||n.ended?[2,r]:(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame(),[2,r]);case 3:a=s.sent();try{this.destroyed||o!==this.playRequestId||null===(i=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===i||i.call(e,a)}finally{throw a}case 4:return[2]}}))}))},t.prototype.pause=function(){E(this.video,"pause",this.destroyed),this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){E(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw y("setSrc");this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){E(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){E(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){E(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){E(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,o=t.container;if(e&&i){var r=g(),a=i.width||(null==o?void 0:o.offsetWidth)||(n?n.width/r:e.videoWidth),s=i.height||(null==o?void 0:o.offsetHeight)||(n?n.height/r:e.videoHeight),l=a,u=s;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var d=function(t,e,i,n,o){if(void 0===n&&(n=1),void 0===o&&(o=h),0===n)return t/e;var r=R(i,"front",n,o).rgb;return t*r.width/(e*r.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),c=a||e.videoWidth,p=s||e.videoHeight,f=void 0;if("width"===i.autoResize||"height"===i.autoResize)f=i.autoResize;else f=d>=c/p?"width":"height";l="width"===f?c:Math.round(p*d),u="width"===f?Math.round(c/d):p}var v=u*r;n&&l&&u&&(l*r!==this.canvasWidth||v!==this.canvasHeight)?(!function(t,e,i){var n=g();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,l,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=l?"".concat(l,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),S=function(t){function e(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return s(e,t),e.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},e.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},e.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},e.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},e.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var u=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(u,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(u);var d=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(d,0),r},e.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=h);var o=[-1,1,1,1,-1,-1,1,-1],r=R(t,e,i,n),a=r.rgb,s=r.alpha,l=w(a),u=w(s),d=[];return o.forEach((function(t,e){e%2==0&&(d=d.concat(o.slice(e,e+2)).concat(l.slice(e,e+2)).concat(u.slice(e,e+2)))})),new Float32Array(d)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},e.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},e.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},e.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&A(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},e.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,u=i.program,d=function(e){try{e()}catch(e){null!=t||(t=e)}};if(d((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(u&&r&&d((function(){return o.detachShader(u,r)})),u&&a&&d((function(){return o.detachShader(u,a)})),r&&d((function(){return o.deleteShader(r)})),a&&d((function(){return o.deleteShader(a)})),s&&d((function(){return o.deleteTexture(s)})),l&&d((function(){return o.deleteBuffer(l)})),u&&d((function(){return o.deleteProgram(u)})),d((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},e}(C),P=function(t){function e(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return s(e,t),e.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},e.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},e.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},e.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,u=t.config;if(e&&i&&n&&o&&A(n)&&r&&a&&s&&l){var d=R(u.orientation,u.side,u.alphaScale,u.alphaAlign),h=d.rgb,c=d.alpha;e.drawImage(n,h.x*r,h.y*a,h.width*r,h.height*a,0,0,s,l);var p=e.getImageData(0,0,s,l),f=p.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var v=i.getImageData(0,0,s,l).data,y=3;y<f.length;y+=4)f[y]=v[y-3];e.putImageData(p,0,0)}},e.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},e}(C),_=function(t){function e(e){return t.call(this,e,!0)||this}return s(e,t),e.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},e}(C),x=["crossOrigin"],T=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=b(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new _(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=g(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new S(t,a,s):new P(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,i){var n,o=this;(null===(n=this.config)||void 0===n?void 0:n.src)&&t.whenReady().then((function(){return u(o,void 0,void 0,(function(){var n;return d(this,(function(o){switch(o.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:i?[4,t.play()]:[3,2];case 1:o.sent(),o.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(i||(null===(n=this.config)||void 0===n?void 0:n.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){o.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playing;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw y(t);if(!this.render)throw function(t){return new f("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return u(this,void 0,void 0,(function(){var e,i;return d(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw y("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=b(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||x.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}(),L=t({name:"AlphaVideoPlayer",props:{src:{type:String,default:void 0},poster:{type:String,default:void 0},width:{type:Number,default:void 0},height:{type:Number,default:void 0},crossOrigin:{type:String,default:void 0},muted:{type:Boolean,default:!0},loop:{type:Boolean,default:!1},playbackRate:{type:Number,default:1},fps:{type:Number,default:0},orientation:{type:String,default:"landscape"},side:{type:String,default:"front"},alphaScale:{type:Number,default:1},alphaAlign:{type:String,default:h},videoFrame:{type:Boolean,default:!1},debug:{type:Boolean,default:!1},autoShow:{type:Boolean,default:!1},autoClear:{type:Boolean,default:!0},autoDestroy:{type:Boolean,default:!1},autoResize:{type:[String,Boolean],default:"contain"}},emits:["initSuccess","initError","load","canPlay","play","loop","pause","ended","error","destroy"],setup:function(t,a){var s=a.emit,u=a.expose,d=e(),h=null,c=function(){h&&(h.destroy(),h=null)};return i((function(){return[t.src,t.poster,t.width,t.height,t.crossOrigin,t.muted,t.loop,t.playbackRate,t.fps,t.orientation,t.side,t.alphaScale,t.alphaAlign,t.videoFrame,t.debug,t.autoShow,t.autoClear,t.autoDestroy,t.autoResize]}),(function(){return null==h?void 0:h.updateConfig(l(l({},null!=t.src?{src:t.src}:{}),{poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize}))})),n((function(){d.value&&(c(),h=new T({container:d.value,src:t.src,poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize,onInitSuccess:function(){return s("initSuccess")},onInitError:function(t){return s("initError",t)},onLoad:function(){return s("load")},onCanPlay:function(){return s("canPlay")},onPlay:function(){return s("play")},onLoop:function(){return s("loop")},onPause:function(){return s("pause")},onEnded:function(){return s("ended")},onError:function(t){return s("error",t)},onDestroy:function(){return s("destroy")}}))})),o(c),u({play:function(){return null==h?void 0:h.play()},updateConfig:function(t){return null==h?void 0:h.updateConfig(t)},pause:function(){return null==h?void 0:h.pause()},destroy:c,reset:function(){return null==h?void 0:h.reset()},setSrc:function(t){return null==h?void 0:h.setSrc(t)},setCurrentTime:function(t){return null==h?void 0:h.setCurrentTime(t)},setMute:function(t){return null==h?void 0:h.setMute(t)},setLoop:function(t){return null==h?void 0:h.setLoop(t)},setPlaybackRate:function(t){return null==h?void 0:h.setPlaybackRate(t)},getPlayer:function(){return h}}),function(){return r("div",{ref:d})}}});export{f as AlphaVideoPlayerError,L as default,v as isAlphaVideoPlayerError};
1
+ import{defineComponent as t,ref as e,watch as i,onMounted as n,onBeforeUnmount as o,h as r}from"vue";var a=function(t,e){return a=Object.setPrototypeOf||{__proto__:[]}instanceof Array&&function(t,e){t.__proto__=e}||function(t,e){for(var i in e)Object.prototype.hasOwnProperty.call(e,i)&&(t[i]=e[i])},a(t,e)};function s(t,e){if("function"!=typeof e&&null!==e)throw new TypeError("Class extends value "+String(e)+" is not a constructor or null");function i(){this.constructor=t}a(t,e),t.prototype=null===e?Object.create(e):(i.prototype=e.prototype,new i)}var l=function(){return l=Object.assign||function(t){for(var e,i=1,n=arguments.length;i<n;i++)for(var o in e=arguments[i])Object.prototype.hasOwnProperty.call(e,o)&&(t[o]=e[o]);return t},l.apply(this,arguments)};function u(t,e,i,n){return new(i||(i=Promise))((function(o,r){function a(t){try{l(n.next(t))}catch(t){r(t)}}function s(t){try{l(n.throw(t))}catch(t){r(t)}}function l(t){var e;t.done?o(t.value):(e=t.value,e instanceof i?e:new i((function(t){t(e)}))).then(a,s)}l((n=n.apply(t,e||[])).next())}))}function d(t,e){var i,n,o,r,a={label:0,sent:function(){if(1&o[0])throw o[1];return o[1]},trys:[],ops:[]};return r={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(r[Symbol.iterator]=function(){return this}),r;function s(s){return function(l){return function(s){if(i)throw new TypeError("Generator is already executing.");for(;r&&(r=0,s[0]&&(a=0)),a;)try{if(i=1,n&&(o=2&s[0]?n.return:s[0]?n.throw||((o=n.return)&&o.call(n),0):n.next)&&!(o=o.call(n,s[1])).done)return o;switch(n=0,o&&(s=[2&s[0],o.value]),s[0]){case 0:case 1:o=s;break;case 4:return a.label++,{value:s[1],done:!1};case 5:a.label++,n=s[1],s=[0];continue;case 7:s=a.ops.pop(),a.trys.pop();continue;default:if(!(o=a.trys,(o=o.length>0&&o[o.length-1])||6!==s[0]&&2!==s[0])){a=0;continue}if(3===s[0]&&(!o||s[1]>o[0]&&s[1]<o[3])){a.label=s[1];break}if(6===s[0]&&a.label<o[1]){a.label=o[1],o=s;break}if(o&&a.label<o[2]){a.label=o[2],a.ops.push(s);break}o[2]&&a.ops.pop(),a.trys.pop();continue}s=e.call(t,a)}catch(t){s=[6,t],n=0}finally{i=o=0}if(5&s[0])throw s[1];return{value:s[0]?s[1]:void 0,done:!0}}([s,l])}}}"function"==typeof SuppressedError&&SuppressedError;var h="start",c={playbackRate:1,muted:!0,loop:!1,fps:0,orientation:"landscape",side:"front",alphaScale:1,alphaAlign:h,autoShow:!1,autoClear:!0,autoDestroy:!1,autoResize:"contain",debug:!1,videoFrame:!1},p="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///yH5BAEAAAAALAAAAAABAAEAAAIBRAA7",f=function(t){function e(i,n,o){var r=t.call(this,"[alpha-video-player-js]: ".concat(o))||this;return r.name="AlphaVideoPlayerError",r.code=i,r.action=n,Object.setPrototypeOf(r,e.prototype),r}return s(e,t),e}(Error),v=function(t){return t instanceof f||!!t&&"object"==typeof t&&"AlphaVideoPlayerError"===t.name&&"string"==typeof t.code},y=function(t){return new f("PLAYER_DESTROYED",t,"cannot ".concat(t," because this player has been destroyed. Create a new player instance before calling ").concat(t,"()."))},g=function(){return"undefined"!=typeof window&&window.devicePixelRatio||1},m=function(t){if(void 0===t&&(t=1),"number"!=typeof t||!isFinite(t)||t<0||t>1)throw new Error("[alpha-video-player-js]: alphaScale must be a finite number between 0 and 1.");return t},b=function(t,e){var i,n,o,r,a,s,l,u,d,p,f,v,y,g=Object.assign({},c,e||{},t);return g.playbackRate=null!==(i=g.playbackRate)&&void 0!==i?i:c.playbackRate,g.muted=null!==(n=g.muted)&&void 0!==n?n:c.muted,g.loop=null!==(o=g.loop)&&void 0!==o?o:c.loop,g.fps=null!==(r=g.fps)&&void 0!==r?r:c.fps,g.orientation=null!==(a=g.orientation)&&void 0!==a?a:c.orientation,g.side=null!==(s=g.side)&&void 0!==s?s:c.side,g.alphaScale=m(g.alphaScale),g.alphaAlign=null!==(l=g.alphaAlign)&&void 0!==l?l:h,g.autoShow=null!==(u=g.autoShow)&&void 0!==u?u:c.autoShow,g.autoClear=null!==(d=g.autoClear)&&void 0!==d?d:c.autoClear,g.autoDestroy=null!==(p=g.autoDestroy)&&void 0!==p?p:c.autoDestroy,g.autoResize=null!==(f=g.autoResize)&&void 0!==f?f:c.autoResize,g.debug=null!==(v=g.debug)&&void 0!==v?v:c.debug,g.videoFrame=null!==(y=g.videoFrame)&&void 0!==y?y:c.videoFrame,g},R=function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=h);var o=m(i);if("landscape"===t){var r=1/(1+o),a=o/(1+o);return{rgb:{x:"front"===e?0:a,y:0,width:r,height:1},alpha:{x:"front"===e?r:0,y:"start"===n?0:1-o,width:a,height:o}}}var s=1/(1+o),l=o/(1+o);return{rgb:{x:0,y:"front"===e?0:l,width:1,height:s},alpha:{x:"start"===n?0:1-o,y:"front"===e?s:0,width:o,height:l}}},w=function(t){var e=t.x,i=t.y,n=t.width,o=t.height;return[e,1-i,e+n,1-i,e,1-i-o,e+n,1-i-o]},E=function(t,e,i){if(void 0===i&&(i=!1),i)throw y(e);if(!t)throw function(t){return new f("VIDEO_SOURCE_MISSING",t,"cannot ".concat(t," because no video source has been set. Provide src, call setSrc(src), or call updateConfig({ src }) first."))}(e)},A=function(t){return t.readyState>=2&&t.videoWidth>0&&t.videoHeight>0},P=function(){function t(t,e,i){if(void 0===e&&(e=!1),void 0===i&&(i=null),this.canvasWidth=0,this.canvasHeight=0,this.videoWidth=0,this.videoHeight=0,this.animationId=null,this.animationGeneration=0,this.playRequestId=0,this.playPending=!1,this.sourceGeneration=0,this.resumeOnReady=!1,this.destroyed=!1,this.onCanPlayTimes=1,this.readyPromise=Promise.resolve(),this.resolveReady=null,this.transitionStyle=null,this.canPlay=!1,this.cancelAnimation=null,this.renderVideoDirectly=!1,this.playing=!1,!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");if(this.renderVideoDirectly=e,this.setConfig(t),this.container=t.container,this.canvas=i,i){var n=this.canvas,o=n.width,r=n.height;this.canvasWidth=o,this.canvasHeight=r}try{t.src&&this.initVideo()}catch(t){throw this.destroy(!1),t}}return Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.video)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"playRequested",{get:function(){return this.playing||this.playPending||this.resumeOnReady},enumerable:!1,configurable:!0}),t.prototype.whenReady=function(){return this.canPlay?Promise.resolve():this.readyPromise},t.prototype.setOutputVisible=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;e&&(e.style.visibility=t?"visible":"hidden")},t.prototype.setOutputTransitioning=function(t){var e=this.renderVideoDirectly?this.video:this.canvas;if(e)return t?(this.transitionStyle||(this.transitionStyle={position:e.style.position||"",left:e.style.left||"",top:e.style.top||"",zIndex:e.style.zIndex||""}),e.style.position="absolute",e.style.left="0",e.style.top="0",void(e.style.zIndex="1")):void(this.transitionStyle&&(e.style.position=this.transitionStyle.position,e.style.left=this.transitionStyle.left,e.style.top=this.transitionStyle.top,e.style.zIndex=this.transitionStyle.zIndex,this.transitionStyle=null))},t.prototype.prepareOutput=function(){!this.renderVideoDirectly&&this.canPlay&&this.drawFrameOnce()},t.prototype.setConfig=function(t){t&&(this.config=b(t,this.config))},t.prototype.updateConfig=function(t){var e=this;if(this.destroyed||!this.config)throw y("updateConfig");var i=this.config,n=this.playing,o=this.playRequested,r=void 0!==t.src&&t.src!==i.src,a=r&&o,s=void 0!==t.fps&&t.fps!==i.fps||void 0!==t.videoFrame&&t.videoFrame!==i.videoFrame;this.setConfig(t);var l=this.config;if(r&&this.setSrc(t.src),this.video){if(void 0!==t.muted&&this.setMute(l.muted),void 0!==t.loop&&this.setLoop(l.loop),void 0!==t.playbackRate&&this.setPlaybackRate(l.playbackRate),a){this.resumeOnReady=!0;var u=this.sourceGeneration;this.whenReady().then((function(){if(!e.destroyed&&u===e.sourceGeneration&&e.resumeOnReady)return e.resumeOnReady=!1,e.play()})).catch((function(){}))}!s||r||!n||this.renderVideoDirectly||this.video.paused||(this.cancelDrawFrame(),this.playing=!0,this.drawFrame()),this.onConfigUpdated(i,l)}},t.prototype.onConfigUpdated=function(t,e){this.video&&t.poster!==e.poster&&(this.video.poster=e.poster||p),t.width===e.width&&t.height===e.height&&t.autoResize===e.autoResize&&t.orientation===e.orientation&&t.alphaScale===e.alphaScale&&t.alphaAlign===e.alphaAlign||this.resizeOutput(),t.autoShow!==e.autoShow&&this.video&&(this.renderVideoDirectly?this.setNativeVideoVisible(this.playing||!!e.autoShow):e.autoShow&&this.canPlay&&this.drawFrameOnce())},t.prototype.initVideo=function(){var t=this.config,e=t.src,i=t.poster,n=t.playbackRate,o=t.muted,r=t.loop,a=t.crossOrigin;this.resetReady();var s=this.video=document.createElement("video");if(s.crossOrigin=null!=a?a:"anonymous",s.poster=i||p,s.src=e,s.autoplay=!1,s.preload="auto",s.playbackRate=n,s.loop=r,s.muted=o,o&&s.setAttribute("muted",""),s.setAttribute("playsinline",""),s.setAttribute("webkit-playsinline",""),s.setAttribute("x-webkit-airplay",""),this.renderVideoDirectly){var l=this.config.width||this.container.offsetWidth,u=this.config.height||this.container.offsetHeight;s.style.display="block",s.style.width=l?"".concat(l,"px"):"100%",s.style.height=u?"".concat(u,"px"):"100%",s.style.visibility=this.config.autoShow?"visible":"hidden",s.style.pointerEvents="none",this.container.appendChild(s)}else s.style.position="absolute",s.style.width="0",s.style.height="0",s.style.overflow="hidden",s.style.pointerEvents="none",document.body.appendChild(s);this.bindInstance(),this.addEvent(),s.load()},t.prototype.resetReady=function(){var t,e=this;null===(t=this.resolveReady)||void 0===t||t.call(this),this.readyPromise=new Promise((function(t){e.resolveReady=t}))},t.prototype.drawFrameOnce=function(){},t.prototype.drawFrame=function(){var t=this;if(!this.destroyed&&this.playing&&null===this.animationId){var e=this.animationGeneration,i=this.initAdaptAnimation(),n=i.request,o=i.cancel;this.cancelAnimation=o;var r,a=this.config.fps>0?1e3/this.config.fps:0,s=function(){return!t.destroyed&&t.playing&&e===t.animationGeneration&&t.video&&!t.video.paused&&!t.video.ended},l=function(e){if(s()){t.animationId=null;try{(void 0===e||void 0===r||e-r>=a)&&(t.drawFrameOnce(),r=void 0!==r&&void 0!==e&&a?e-(e-r)%a:e)}catch(e){return void t.onError(e)}s()&&(t.animationId=n(l))}};l()}},t.prototype.initAdaptAnimation=function(){var t=this.config,e=t.videoFrame,i=t.fps,n=function(){if("undefined"==typeof window)return null;var t=window;return t.requestAnimationFrame||t.webkitRequestAnimationFrame||t.mozRequestAnimationFrame||t.oRequestAnimationFrame||t.msRequestAnimationFrame||null}(),o=function(){if("undefined"==typeof window)return null;var t=window;return t.cancelAnimationFrame||t.mozCancelAnimationFrame||t.webkitCancelAnimationFrame||t.msCancelAnimationFrame||null}(),r=this.video;if(e&&r.requestVideoFrameCallback&&r.cancelVideoFrameCallback)return{request:function(t){return r.requestVideoFrameCallback(t)},cancel:function(t){return r.cancelVideoFrameCallback(t)}};if(n&&o)return{request:function(t){return n.call(window,t)},cancel:function(t){return o.call(window,t)}};var a=i>0?1e3/i:16;return{request:function(t){return window.setTimeout((function(){return t(Date.now())}),a)},cancel:function(t){return window.clearTimeout(t)}}},t.prototype.cancelDrawFrame=function(){var t;this.animationGeneration++;try{null!==this.animationId&&(null===(t=this.cancelAnimation)||void 0===t||t.call(this,this.animationId))}finally{this.animationId=null,this.cancelAnimation=null,this.playing=!1}},t.prototype.play=function(t){var e,i;return u(this,void 0,void 0,(function(){var n,o,r,a;return d(this,(function(s){switch(s.label){case 0:E(this.video,"play",this.destroyed),t&&this.setConfig(t),this.resumeOnReady=!1,n=this.video,o=++this.playRequestId,this.playPending=!0,s.label=1;case 1:return s.trys.push([1,3,,4]),[4,n.play()];case 2:return r=s.sent(),this.destroyed||o!==this.playRequestId||n!==this.video?[2,r]:(this.playPending=!1,n.paused||n.ended||(this.cancelDrawFrame(),this.playing=!0,this.renderVideoDirectly?this.setNativeVideoVisible(!0):this.drawFrame()),[2,r]);case 3:if(a=s.sent(),this.destroyed||o!==this.playRequestId||n!==this.video)return[2];this.playPending=!1;try{null===(i=null===(e=this.config)||void 0===e?void 0:e.onError)||void 0===i||i.call(e,a)}finally{throw a}case 4:return[2]}}))}))},t.prototype.pause=function(){E(this.video,"pause",this.destroyed),this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.video.pause()},t.prototype.reset=function(){E(this.video,"reset",this.destroyed),this.video.currentTime=0},t.prototype.setSrc=function(t){if(this.destroyed)throw y("setSrc");this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1,this.cancelDrawFrame(),this.canPlay=!1,this.onCanPlayTimes=1,this.config.src=t,this.renderVideoDirectly&&this.setNativeVideoVisible(!!this.config.autoShow),this.video?(this.resetReady(),this.video.src=t,this.video.load(),this.video.currentTime=0):this.initVideo()},t.prototype.setCurrentTime=function(t){E(this.video,"setCurrentTime",this.destroyed),this.video.currentTime=t},t.prototype.setMute=function(t){E(this.video,"setMute",this.destroyed),this.video.muted=t,t?this.video.setAttribute("muted",""):this.video.removeAttribute("muted")},t.prototype.setLoop=function(t){E(this.video,"setLoop",this.destroyed),this.video.loop=t},t.prototype.setPlaybackRate=function(t){E(this.video,"setPlaybackRate",this.destroyed),this.video.playbackRate=t},t.prototype.onLoad=function(){var t=this,e=t.video,i=t.config;t.canvas,this.videoWidth=e.videoWidth,this.videoHeight=e.videoHeight,this.resizeOutput(),i.onLoad&&i.onLoad()},t.prototype.resizeOutput=function(){var t=this,e=t.video,i=t.config,n=t.canvas,o=t.container;if(e&&i){var r=g(),a=i.width||(null==o?void 0:o.offsetWidth)||(n?n.width/r:e.videoWidth),s=i.height||(null==o?void 0:o.offsetHeight)||(n?n.height/r:e.videoHeight),l=a,u=s;if(i.autoResize&&(n||this.renderVideoDirectly)&&e.videoWidth>0&&e.videoHeight>0){var d=function(t,e,i,n,o){if(void 0===n&&(n=1),void 0===o&&(o=h),0===n)return t/e;var r=R(i,"front",n,o).rgb;return t*r.width/(e*r.height)}(e.videoWidth,e.videoHeight,i.orientation,i.alphaScale,i.alphaAlign),c=a||e.videoWidth,p=s||e.videoHeight,f=void 0;if("width"===i.autoResize||"height"===i.autoResize)f=i.autoResize;else f=d>=c/p?"width":"height";l="width"===f?c:Math.round(p*d),u="width"===f?Math.round(c/d):p}var v=u*r;n&&l&&u&&(l*r!==this.canvasWidth||v!==this.canvasHeight)?(!function(t,e,i){var n=g();t.width=e*n,t.height=i*n,t.style.width=e+"px",t.style.height=i+"px"}(n,l,u),this.canvasWidth=n.width,this.canvasHeight=n.height,this.onCanvasResized()):this.renderVideoDirectly&&(e.style.width=l?"".concat(l,"px"):"100%",e.style.height=u?"".concat(u,"px"):"100%")}},t.prototype.onCanvasResized=function(){},t.prototype.onCanplay=function(){var t,e=this.config;this.canPlay=!0,null===(t=this.resolveReady)||void 0===t||t.call(this),this.resolveReady=null;try{this.renderVideoDirectly?e.autoShow&&this.setNativeVideoVisible(!0):e.autoShow&&this.drawFrameOnce()}catch(t){return void this.onError(t)}1===this.onCanPlayTimes&&e.onCanPlay&&e.onCanPlay(),1!==this.onCanPlayTimes&&e.loop&&e.onLoop&&e.onLoop(),this.onCanPlayTimes++},t.prototype.onPlay=function(){var t=this.config;t.onPlay&&t.onPlay()},t.prototype.onPause=function(){var t,e,i=this.config;(null===(t=this.video)||void 0===t?void 0:t.paused)&&(this.playRequestId++,this.playPending=!1,this.cancelDrawFrame()),null===(e=null==i?void 0:i.onPause)||void 0===e||e.call(i)},t.prototype.onEnded=function(){var t,e=this.config,i=this.video;this.playRequestId++,this.playPending=!1,i.currentTime=0,this.cancelDrawFrame();try{null===(t=e.onEnded)||void 0===t||t.call(e)}finally{e.autoDestroy&&this.destroy()}},t.prototype.setNativeVideoVisible=function(t){this.renderVideoDirectly&&this.video&&(this.video.style.visibility=t?"visible":"hidden")},t.prototype.onError=function(t){var e,i,n=this.config,o=this.video;if(n&&!this.destroyed){n.debug&&console.error(null!==(e=null==o?void 0:o.error)&&void 0!==e?e:t);try{null===(i=n.onError)||void 0===i||i.call(n,t)}finally{this.destroy()}}},t.prototype.destroy=function(t){var e=this;if(void 0===t&&(t=!0),!this.destroyed){this.destroyed=!0,this.playRequestId++,this.playPending=!1,this.sourceGeneration++,this.resumeOnReady=!1;var i,n=this,o=n.config,r=n.video,a=n.canvas,s=function(t){try{t()}catch(t){null!=i||(i=t)}};s((function(){return e.cancelDrawFrame()})),s((function(){var t;return null===(t=e.resolveReady)||void 0===t?void 0:t.call(e)})),this.resolveReady=null,s((function(){return e.removeEvent()})),s((function(){r&&(r.pause(),r.removeAttribute("src"),r.load())})),s((function(){var t;return null===(t=null==r?void 0:r.parentNode)||void 0===t?void 0:t.removeChild(r)})),s((function(){return e.releaseRenderResources()})),s((function(){var t;return null===(t=null==a?void 0:a.parentNode)||void 0===t?void 0:t.removeChild(a)})),s((function(){a&&(a.width=a.height=0)})),this.config=null,this.container=null,this.video=null,this.canvas=null,this.transitionStyle=null,this.canPlay=!1,t&&s((function(){var t;return null===(t=null==o?void 0:o.onDestroy)||void 0===t?void 0:t.call(o)})),i&&(null==o?void 0:o.debug)&&console.error("[alpha-video-player-js] destroy error:",i)}},t.prototype.releaseRenderResources=function(){},t.prototype.bindInstance=function(){var t=this,e=t.onLoad,i=t.onCanplay,n=t.onPlay,o=t.onPause,r=t.onEnded,a=t.onError;this.onLoad=e.bind(this),this.onCanplay=i.bind(this),this.onPlay=n.bind(this),this.onPause=o.bind(this),this.onEnded=r.bind(this),this.onError=a.bind(this)},t.prototype.addEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e.addEventListener("loadedmetadata",i),e.addEventListener("canplaythrough",n),e.addEventListener("play",o),e.addEventListener("pause",r),e.addEventListener("ended",a),e.addEventListener("error",s)},t.prototype.removeEvent=function(){var t=this,e=t.video,i=t.onLoad,n=t.onCanplay,o=t.onPlay,r=t.onPause,a=t.onEnded,s=t.onError;e&&(e.removeEventListener("loadedmetadata",i),e.removeEventListener("play",o),e.removeEventListener("canplaythrough",n),e.removeEventListener("pause",r),e.removeEventListener("ended",a),e.removeEventListener("error",s))},t}(),C=function(t){function e(e,i,n){var o=t.call(this,e,!1,i)||this;o.onContextLost=function(t){return o.onError(t)},o.gl=n;try{o.initWebGLRender(),i.addEventListener("webglcontextlost",o.onContextLost)}catch(t){throw o.destroy(!1),t}return o}return s(e,t),e.prototype.initWebGLRender=function(){var t=this.canvas,e=this.gl;e.enable(e.BLEND),e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.viewport(0,0,t.width,t.height),this.vertexShader=this.initShader(e.VERTEX_SHADER,"#define GLSLIFY 1\nattribute vec4 a_Position;attribute vec2 a_Video_Texture_Position;attribute vec2 a_Alpha_Video_Texture_Position;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_Position=a_Position;v_Video_Texture_Position=a_Video_Texture_Position;v_Alpha_Video_Texture_Position=a_Alpha_Video_Texture_Position;}"),this.fragmentShader=this.initShader(e.FRAGMENT_SHADER,"precision lowp float;\n#define GLSLIFY 1\nuniform sampler2D u_Sampler;varying vec2 v_Video_Texture_Position;varying vec2 v_Alpha_Video_Texture_Position;void main(){gl_FragColor=vec4(texture2D(u_Sampler,v_Video_Texture_Position).rgb,texture2D(u_Sampler,v_Alpha_Video_Texture_Position).r);}"),this.program=this.initProgram(),this.texture=this.initTexture(),this.vertexBuffer=this.initVertexBuffer()},e.prototype.initShader=function(t,e){var i=this.gl,n=i.createShader(t);if(!n)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL shader.");if(t===i.VERTEX_SHADER?this.vertexShader=n:this.fragmentShader=n,i.shaderSource(n,e),i.compileShader(n),!i.getShaderParameter(n,i.COMPILE_STATUS))throw new Error("[alpha-video-player-js]: WebGL shader compilation failed: ".concat(i.getShaderInfoLog(n)||""));return n},e.prototype.initProgram=function(){var t=this.gl,e=t.createProgram();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL program.");if(this.program=e,t.attachShader(e,this.vertexShader),t.attachShader(e,this.fragmentShader),t.linkProgram(e),!t.getProgramParameter(e,t.LINK_STATUS))throw new Error("[alpha-video-player-js]: WebGL program linking failed: ".concat(t.getProgramInfoLog(e)||""));return t.useProgram(e),e},e.prototype.initTexture=function(){var t=this.gl,e=t.createTexture();if(!e)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL texture.");return this.texture=e,t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,e),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),e},e.prototype.initVertexBuffer=function(){var t=this,e=t.gl,i=t.program,n=t.config,o=this.computeVertexCoords(n),r=e.createBuffer();if(!r)throw new Error("[alpha-video-player-js]: Unable to allocate a WebGL buffer.");this.vertexBuffer=r,e.bindBuffer(e.ARRAY_BUFFER,r),e.bufferData(e.ARRAY_BUFFER,o,e.STATIC_DRAW);var a=o.BYTES_PER_ELEMENT,s=e.getAttribLocation(i,"a_Position");e.vertexAttribPointer(s,2,e.FLOAT,!1,6*a,0),e.enableVertexAttribArray(s);var l=e.getAttribLocation(i,"a_Video_Texture_Position");e.vertexAttribPointer(l,2,e.FLOAT,!1,6*a,2*a),e.enableVertexAttribArray(l);var u=e.getAttribLocation(i,"a_Alpha_Video_Texture_Position");e.vertexAttribPointer(u,2,e.FLOAT,!1,6*a,4*a),e.enableVertexAttribArray(u);var d=e.getUniformLocation(i,"u_Sampler");return e.uniform1i(d,0),r},e.prototype.computeVertexCoords=function(t){return function(t,e,i,n){void 0===i&&(i=1),void 0===n&&(n=h);var o=[-1,1,1,1,-1,-1,1,-1],r=R(t,e,i,n),a=r.rgb,s=r.alpha,l=w(a),u=w(s),d=[];return o.forEach((function(t,e){e%2==0&&(d=d.concat(o.slice(e,e+2)).concat(l.slice(e,e+2)).concat(u.slice(e,e+2)))})),new Float32Array(d)}(t.orientation,t.side,t.alphaScale,t.alphaAlign)},e.prototype.onConfigUpdated=function(e,i){if(t.prototype.onConfigUpdated.call(this,e,i),(e.orientation!==i.orientation||e.side!==i.side||e.alphaScale!==i.alphaScale||e.alphaAlign!==i.alphaAlign)&&this.gl&&this.vertexBuffer){var n=this.computeVertexCoords(i);this.gl.bindBuffer(this.gl.ARRAY_BUFFER,this.vertexBuffer),this.gl.bufferData(this.gl.ARRAY_BUFFER,n,this.gl.STATIC_DRAW)}},e.prototype.onCanvasResized=function(){var t=this.gl,e=this.canvas;t&&e&&t.viewport(0,0,e.width,e.height)},e.prototype.drawFrameOnce=function(){var t=this.gl,e=this.video;t&&!t.isContextLost()&&e&&this.canPlay&&A(e)&&(t.clear(t.COLOR_BUFFER_BIT),t.texImage2D(t.TEXTURE_2D,0,t.RGB,t.RGB,t.UNSIGNED_BYTE,e),t.drawArrays(t.TRIANGLE_STRIP,0,4))},e.prototype.onEnded=function(){var e=this.gl;this.config.autoClear&&e.clear(e.COLOR_BUFFER_BIT),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){var t,e=this,i=this,n=i.canvas,o=i.gl,r=i.vertexShader,a=i.fragmentShader,s=i.texture,l=i.vertexBuffer,u=i.program,d=function(e){try{e()}catch(e){null!=t||(t=e)}};if(d((function(){return null==n?void 0:n.removeEventListener("webglcontextlost",e.onContextLost)})),o&&(u&&r&&d((function(){return o.detachShader(u,r)})),u&&a&&d((function(){return o.detachShader(u,a)})),r&&d((function(){return o.deleteShader(r)})),a&&d((function(){return o.deleteShader(a)})),s&&d((function(){return o.deleteTexture(s)})),l&&d((function(){return o.deleteBuffer(l)})),u&&d((function(){return o.deleteProgram(u)})),d((function(){var t;return null===(t=o.getExtension("WEBGL_lose_context"))||void 0===t?void 0:t.loseContext()}))),this.gl=null,this.vertexShader=null,this.fragmentShader=null,this.texture=null,this.vertexBuffer=null,this.program=null,t)throw t},e}(P),S=function(t){function e(e,i){var n=t.call(this,e,!1,i)||this;try{n.initCanvasRender()}catch(t){throw n.destroy(!1),t}return n}return s(e,t),e.prototype.initCanvasRender=function(){var t=this.canvas;if(this.context2d=t.getContext("2d"),!this.context2d)throw new Error("[alpha-video-player-js]: Your browser does not support canvas rendering.");this.resizeAlphaCanvas()},e.prototype.onCanvasResized=function(){this.context2d=this.canvas.getContext("2d"),this.resizeAlphaCanvas()},e.prototype.resizeAlphaCanvas=function(){var t=this.alphaCanvas||document.createElement("canvas");if(t.width=this.canvasWidth,t.height=this.canvasHeight,this.alphaCanvas=t,this.alphaContext2d=t.getContext("2d"),!this.alphaContext2d)throw new Error("[alpha-video-player-js]: Unable to allocate the alpha canvas.")},e.prototype.drawFrameOnce=function(){var t=this,e=t.context2d,i=t.alphaContext2d,n=t.video,o=t.canPlay,r=t.videoWidth,a=t.videoHeight,s=t.canvasWidth,l=t.canvasHeight,u=t.config;if(e&&i&&n&&o&&A(n)&&r&&a&&s&&l){var d=R(u.orientation,u.side,u.alphaScale,u.alphaAlign),h=d.rgb,c=d.alpha;e.drawImage(n,h.x*r,h.y*a,h.width*r,h.height*a,0,0,s,l);var p=e.getImageData(0,0,s,l),f=p.data;i.drawImage(n,c.x*r,c.y*a,c.width*r,c.height*a,0,0,s,l);for(var v=i.getImageData(0,0,s,l).data,y=3;y<f.length;y+=4)f[y]=v[y-3];e.putImageData(p,0,0)}},e.prototype.onEnded=function(){var e=this,i=e.context2d,n=e.canvasWidth,o=e.canvasHeight;e.config.autoClear&&i.clearRect(0,0,n,o),t.prototype.onEnded.call(this)},e.prototype.releaseRenderResources=function(){try{this.alphaCanvas&&(this.alphaCanvas.width=this.alphaCanvas.height=0)}finally{this.context2d=null,this.alphaCanvas=null,this.alphaContext2d=null}},e}(P),_=function(t){function e(e){return t.call(this,e,!0)||this}return s(e,t),e.prototype.onEnded=function(){this.config.autoClear&&this.setNativeVideoVisible(!1),t.prototype.onEnded.call(this)},e}(P),x=["crossOrigin"],T=function(){function t(t){this.render=null,this.config=null,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,this.transitionGeneration=0,this.config=b(t),this.render=this.createRenderer(this.config,!0)}return t.prototype.createRenderer=function(t,e){var i,n,o;void 0===e&&(e=!1);var r=null,a=null,s=null;try{if(!t.container)throw new Error("[alpha-video-player-js]: container can not be empty!");return r=0===t.alphaScale?new _(t):(s=(a=function(t,e,i){var n=t.offsetWidth,o=t.offsetHeight,r=g(),a=e||n,s=i||o;a&&s||console.warn("[alpha-video-player-js]: container size is 0. Make sure the container is mounted and has a non-zero size before creating the player.");var l=document.createElement("canvas");return l.width=a*r,l.height=s*r,l.style.width="100%",l.style.height="100%",l.style.pointerEvents="none",t.appendChild(l),l}(t.container,t.width,t.height)).getContext("webgl")||a.getContext("experimental-webgl"))?new C(t,a,s):new S(t,a),e&&(null===(i=t.onInitSuccess)||void 0===i||i.call(t)),r}catch(e){if(null==r||r.destroy(!1),s&&!s.isContextLost()&&(null===(n=s.getExtension("WEBGL_lose_context"))||void 0===n||n.loseContext()),a&&(null===(o=a.parentNode)||void 0===o||o.removeChild(a),a.width=a.height=0),!t.onInitError)throw e;return t.onInitError(e),null}},t.prototype.rendererUpdates=function(t){var e=Object.assign({},t);return delete e.container,e},t.prototype.finishTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.config;t.prepareOutput(),t.setOutputTransitioning(!1),t.setOutputVisible(!0),t.updateConfig({onError:null==n?void 0:n.onError,onDestroy:null==n?void 0:n.onDestroy}),this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i.destroy(!1)}},t.prototype.rollbackTransition=function(t,e){if(e===this.transitionGeneration&&this.render===t&&this.outgoingRender){var i=this.outgoingRender,n=this.outgoingConfig,o=this.transitionWasPlaying;this.transitionGeneration++,this.render=i,this.config=n,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,t.destroy(!1),n&&i.updateConfig(this.rendererUpdates(n)),i.setOutputVisible(!0),o&&i.play().catch((function(){}))}},t.prototype.cancelTransition=function(){if(!this.outgoingRender)return!1;var t=this.render,e=this.outgoingRender,i=this.outgoingConfig,n=this.transitionWasPlaying;return this.transitionGeneration++,null==t||t.destroy(!1),this.render=e,this.config=i,this.outgoingRender=null,this.outgoingConfig=null,this.transitionWasPlaying=!1,i&&e.updateConfig(this.rendererUpdates(i)),e.setOutputVisible(!0),n},t.prototype.activateTransition=function(t,e,i){var n,o=this;(null===(n=this.config)||void 0===n?void 0:n.src)&&t.whenReady().then((function(){return u(o,void 0,void 0,(function(){var n;return d(this,(function(o){switch(o.label){case 0:return e!==this.transitionGeneration||this.render!==t?[2]:i?[4,t.play()]:[3,2];case 1:o.sent(),o.label=2;case 2:return e!==this.transitionGeneration||this.render!==t||(i||(null===(n=this.config)||void 0===n?void 0:n.autoShow))&&this.finishTransition(t,e),[2]}}))}))})).catch((function(){o.rollbackTransition(t,e)}))},t.prototype.startTransition=function(t,e,i){var n=this,o=this.render;if(!o)return this.config=t,void(this.render=this.createRenderer(t));var r=++this.transitionGeneration,a=null,s=Object.assign({},t,{onDestroy:void 0,onError:function(e){try{var i=n.config?n.config.onError:t.onError;null==i||i(e)}finally{a&&n.rollbackTransition(a,n.transitionGeneration)}}});if(a=this.createRenderer(s)){a.setOutputTransitioning(!0),a.setOutputVisible(!1);var l=null!=i?i:o.playRequested;l&&(o.updateConfig({onPause:void 0}),o.pause()),this.outgoingRender=o,this.outgoingConfig=e,this.transitionWasPlaying=l,this.render=a,this.config=t,this.activateTransition(a,r,l)}},t.prototype.getRenderer=function(t){if(void 0===t&&(t="use the player"),!this.config)throw y(t);if(!this.render)throw function(t){return new f("PLAYER_NOT_INITIALIZED",t,"cannot ".concat(t," because the renderer was not initialized. Check onInitError for the initialization failure."))}(t);return this.render},Object.defineProperty(t.prototype,"playing",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.playing)||!1},enumerable:!1,configurable:!0}),Object.defineProperty(t.prototype,"loop",{get:function(){var t;return(null===(t=this.render)||void 0===t?void 0:t.loop)||!1},enumerable:!1,configurable:!0}),t.prototype.play=function(t){return u(this,void 0,void 0,(function(){var e,i;return d(this,(function(n){switch(n.label){case 0:return t&&this.updateConfig(t),[4,(e=this.getRenderer("play")).play()];case 1:return i=n.sent(),this.outgoingRender&&this.render===e?[4,e.whenReady()]:[3,3];case 2:n.sent(),this.finishTransition(e,this.transitionGeneration),n.label=3;case 3:return[2,i]}}))}))},t.prototype.updateConfig=function(t){if(!this.config)throw y("updateConfig");var e=this.config,i=Object.assign({},t);void 0===i.src&&delete i.src;var n=b(Object.assign({},i,{container:e.container}),e),o=function(t){return 0===t.alphaScale!=(0===n.alphaScale)||0===t.alphaScale&&t.src!==n.src||x.some((function(e){return t[e]!==n[e]}))};if(this.outgoingRender&&o(e)){var r=this.cancelTransition();return o(e=this.config)?void this.startTransition(n,e,r):(this.config=n,this.getRenderer("updateConfig").updateConfig(this.rendererUpdates(n)),void(r&&this.getRenderer("play").play().catch((function(){}))))}if(this.render&&!o(e)){this.config=n;var a=Object.assign({},i);if(this.outgoingRender&&(delete a.onError,delete a.onDestroy),this.getRenderer("updateConfig").updateConfig(a),this.outgoingRender&&e.src!==n.src){var s=++this.transitionGeneration;this.activateTransition(this.getRenderer("updateConfig"),s,this.transitionWasPlaying)}}else this.startTransition(n,e)},t.prototype.pause=function(){var t;this.getRenderer("pause").pause(),null===(t=this.outgoingRender)||void 0===t||t.pause()},t.prototype.destroy=function(){var t,e,i,n;this.transitionGeneration++,this.outgoingRender&&this.render&&this.render.updateConfig({onError:null===(t=this.config)||void 0===t?void 0:t.onError,onDestroy:null===(e=this.config)||void 0===e?void 0:e.onDestroy}),null===(i=this.render)||void 0===i||i.destroy(),null===(n=this.outgoingRender)||void 0===n||n.destroy(!1),this.render=null,this.outgoingRender=null,this.outgoingConfig=null,this.config=null},t.prototype.reset=function(){this.getRenderer("reset").reset()},t.prototype.setSrc=function(t){if(this.getRenderer("setSrc").setSrc(t),this.config&&(this.config.src=t),this.outgoingRender){var e=++this.transitionGeneration;this.activateTransition(this.getRenderer("setSrc"),e,this.transitionWasPlaying)}},t.prototype.setCurrentTime=function(t){this.getRenderer("setCurrentTime").setCurrentTime(t)},t.prototype.setMute=function(t){this.getRenderer("setMute").setMute(t),this.config&&(this.config.muted=t)},t.prototype.setLoop=function(t){this.getRenderer("setLoop").setLoop(t),this.config&&(this.config.loop=t)},t.prototype.setPlaybackRate=function(t){this.getRenderer("setPlaybackRate").setPlaybackRate(t),this.config&&(this.config.playbackRate=t)},t}(),L=t({name:"AlphaVideoPlayer",props:{src:{type:String,default:void 0},poster:{type:String,default:void 0},width:{type:Number,default:void 0},height:{type:Number,default:void 0},crossOrigin:{type:String,default:void 0},muted:{type:Boolean,default:!0},loop:{type:Boolean,default:!1},playbackRate:{type:Number,default:1},fps:{type:Number,default:0},orientation:{type:String,default:"landscape"},side:{type:String,default:"front"},alphaScale:{type:Number,default:1},alphaAlign:{type:String,default:h},videoFrame:{type:Boolean,default:!1},debug:{type:Boolean,default:!1},autoShow:{type:Boolean,default:!1},autoClear:{type:Boolean,default:!0},autoDestroy:{type:Boolean,default:!1},autoResize:{type:[String,Boolean],default:"contain"}},emits:["initSuccess","initError","load","canPlay","play","loop","pause","ended","error","destroy"],setup:function(t,a){var s=a.emit,u=a.expose,d=e(),h=null,c=function(){h&&(h.destroy(),h=null)};return i((function(){return[t.src,t.poster,t.width,t.height,t.crossOrigin,t.muted,t.loop,t.playbackRate,t.fps,t.orientation,t.side,t.alphaScale,t.alphaAlign,t.videoFrame,t.debug,t.autoShow,t.autoClear,t.autoDestroy,t.autoResize]}),(function(){return null==h?void 0:h.updateConfig(l(l({},null!=t.src?{src:t.src}:{}),{poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize}))})),n((function(){d.value&&(c(),h=new T({container:d.value,src:t.src,poster:t.poster,width:t.width,height:t.height,crossOrigin:t.crossOrigin,muted:t.muted,loop:t.loop,playbackRate:t.playbackRate,fps:t.fps,orientation:t.orientation,side:t.side,alphaScale:t.alphaScale,alphaAlign:t.alphaAlign,videoFrame:t.videoFrame,debug:t.debug,autoShow:t.autoShow,autoClear:t.autoClear,autoDestroy:t.autoDestroy,autoResize:t.autoResize,onInitSuccess:function(){return s("initSuccess")},onInitError:function(t){return s("initError",t)},onLoad:function(){return s("load")},onCanPlay:function(){return s("canPlay")},onPlay:function(){return s("play")},onLoop:function(){return s("loop")},onPause:function(){return s("pause")},onEnded:function(){return s("ended")},onError:function(t){return s("error",t)},onDestroy:function(){return s("destroy")}}))})),o(c),u({play:function(){return null==h?void 0:h.play()},updateConfig:function(t){return null==h?void 0:h.updateConfig(t)},pause:function(){return null==h?void 0:h.pause()},destroy:c,reset:function(){return null==h?void 0:h.reset()},setSrc:function(t){return null==h?void 0:h.setSrc(t)},setCurrentTime:function(t){return null==h?void 0:h.setCurrentTime(t)},setMute:function(t){return null==h?void 0:h.setMute(t)},setLoop:function(t){return null==h?void 0:h.setLoop(t)},setPlaybackRate:function(t){return null==h?void 0:h.setPlaybackRate(t)},getPlayer:function(){return h}}),function(){return r("div",{ref:d})}}});export{f as AlphaVideoPlayerError,L as default,v as isAlphaVideoPlayerError};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "alpha-video-player-js",
3
- "version": "1.4.1",
3
+ "version": "1.4.2",
4
4
  "description": "Web 视频动画特效播放 sdk",
5
5
  "main": "dist/alpha-video-player-js.js",
6
6
  "types": "dist/alpha-video-player-js.d.ts",