Files
ArtPlayer/dist/artplayer-plugin-gif.js
T
2019-09-15 16:16:53 +08:00

9 lines
28 KiB
JavaScript

/*!
* artplayer-plugin-gif.js v3.1.15
* Github: https://github.com/zhw2590582/ArtPlayer#readme
* (c) 2017-2019 Harvey Zack
* Released under the MIT License.
*/
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?module.exports=t():"function"==typeof define&&define.amd?define(t):(e=e||self).artplayerPluginGif=t()}(this,function(){"use strict";var S=function(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e};"undefined"!=typeof globalThis?globalThis:"undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self&&self;function e(e,t){return e(t={exports:{}},t.exports),t.exports}var x=e(function(C,e){!function(e,z,t,G){function r(){}var i,n,B={URL:e.URL||e.webkitURL||e.mozURL||e.msURL,getUserMedia:(n=t.getUserMedia||t.webkitGetUserMedia||t.mozGetUserMedia||t.msGetUserMedia,n?n.bind(t):n),requestAnimFrame:e.requestAnimationFrame||e.webkitRequestAnimationFrame||e.mozRequestAnimationFrame||e.oRequestAnimationFrame||e.msRequestAnimationFrame,requestTimeout:function(r,i){if(r=r||B.noop,i=i||0,!B.requestAnimFrame)return setTimeout(r,i);var n=(new Date).getTime(),o=new Object,a=B.requestAnimFrame;return o.value=a(function e(){var t=(new Date).getTime();i<=t-n?r.call():o.value=a(e)}),o},Blob:e.Blob||e.BlobBuilder||e.WebKitBlobBuilder||e.MozBlobBuilder||e.MSBlobBuilder,btoa:(i=e.btoa||function(e){for(var t="",r=0,i=e.length,n="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=",o=void 0,a=void 0,s=void 0,c=void 0,d=void 0,l=void 0,u=void 0;r<i;)c=(o=e.charCodeAt(r++))>>2,d=(3&o)<<4|(a=e.charCodeAt(r++))>>4,l=(15&a)<<2|(s=e.charCodeAt(r++))>>6,u=63&s,isNaN(a)?l=u=64:isNaN(s)&&(u=64),t=t+n.charAt(c)+n.charAt(d)+n.charAt(l)+n.charAt(u);return t},i?i.bind(e):B.noop),isObject:function(e){return e&&"[object Object]"===Object.prototype.toString.call(e)},isEmptyObject:function(e){return B.isObject(e)&&!Object.keys(e).length},isArray:function(e){return e&&Array.isArray(e)},isFunction:function(e){return e&&"function"==typeof e},isElement:function(e){return e&&1===e.nodeType},isString:function(e){return"string"==typeof e||"[object String]"===Object.prototype.toString.call(e)},isSupported:{canvas:function(){var e=z.createElement("canvas");return e&&e.getContext&&e.getContext("2d")},webworkers:function(){return e.Worker},blob:function(){return B.Blob},Uint8Array:function(){return e.Uint8Array},Uint32Array:function(){return e.Uint32Array},videoCodecs:function(){var e=z.createElement("video"),t={mp4:!1,h264:!1,ogv:!1,ogg:!1,webm:!1};try{e&&e.canPlayType&&(t.mp4=""!==e.canPlayType('video/mp4; codecs="mp4v.20.8"'),t.h264=""!==(e.canPlayType('video/mp4; codecs="avc1.42E01E"')||e.canPlayType('video/mp4; codecs="avc1.42E01E, mp4a.40.2"')),t.ogv=""!==e.canPlayType('video/ogg; codecs="theora"'),t.ogg=""!==e.canPlayType('video/ogg; codecs="theora"'),t.webm=-1!==e.canPlayType('video/webm; codecs="vp8, vorbis"'))}catch(e){}return t}()},noop:function(){},each:function(e,t){var r=void 0,i=void 0;if(B.isArray(e))for(r=-1,i=e.length;++r<i&&!1!==t(r,e[r]););else if(B.isObject(e))for(r in e)if(e.hasOwnProperty(r)&&!1===t(r,e[r]))break},mergeOptions:function(i,n){if(B.isObject(i)&&B.isObject(n)&&Object.keys){var o={};return B.each(i,function(e,t){o[e]=i[e]}),B.each(n,function(e,t){var r=n[e];B.isObject(r)&&i[e]?o[e]=B.mergeOptions(i[e],r):o[e]=r}),o}},setCSSAttr:function(r,e,t){B.isElement(r)&&(B.isString(e)&&B.isString(t)?r.style[e]=t:B.isObject(e)&&B.each(e,function(e,t){r.style[e]=t}))},removeElement:function(e){B.isElement(e)&&e.parentNode&&e.parentNode.removeChild(e)},createWebWorker:function(e){if(!B.isString(e))return{};try{var t=new B.Blob([e],{type:"text/javascript"}),r=B.URL.createObjectURL(t);return{objectUrl:r,worker:new Worker(r)}}catch(e){return""+e}},getExtension:function(e){return e.substr(e.lastIndexOf(".")+1,e.length)},getFontSize:function(e){var t=0<arguments.length&&e!==G?e:{};if(!z.body||!1===t.resizeFont)return t.fontSize;var r=t.text,i=t.gifWidth,n=parseInt(t.fontSize,10),o=parseInt(t.minFontSize,10),a=z.createElement("div"),s=z.createElement("span");for(a.setAttribute("width",i),a.appendChild(s),s.innerHTML=r,s.style.fontSize=n+"px",s.style.textIndent="-9999px",s.style.visibility="hidden",z.body.appendChild(s);s.offsetWidth>i&&o<=n;)s.style.fontSize=--n+"px";return z.body.removeChild(s),n+"px"},webWorkerError:!1},o=Object.freeze({default:B}),f={validate:function(i){i=B.isObject(i)?i:{};var n={};return B.each(f.validators,function(e,t){var r=t.errorCode;if(!i[r]&&!t.condition)return!((n=t).error=!0)}),delete n.condition,n},isValid:function(e){var t=!0!==f.validate(e).error;return t},validators:[{condition:B.isFunction(B.getUserMedia),errorCode:"getUserMedia",errorMsg:"The getUserMedia API is not supported in your browser"},{condition:B.isSupported.canvas(),errorCode:"canvas",errorMsg:"Canvas elements are not supported in your browser"},{condition:B.isSupported.webworkers(),errorCode:"webworkers",errorMsg:"The Web Workers API is not supported in your browser"},{condition:B.isFunction(B.URL),errorCode:"window.URL",errorMsg:"The window.URL API is not supported in your browser"},{condition:B.isSupported.blob(),errorCode:"window.Blob",errorMsg:"The window.Blob File API is not supported in your browser"},{condition:B.isSupported.Uint8Array(),errorCode:"window.Uint8Array",errorMsg:"The window.Uint8Array function constructor is not supported in your browser"},{condition:B.isSupported.Uint32Array(),errorCode:"window.Uint32Array",errorMsg:"The window.Uint32Array function constructor is not supported in your browser"}],messages:{videoCodecs:{errorCode:"videocodec",errorMsg:"The video codec you are trying to use is not supported in your browser"}}},a=Object.freeze({default:f}),c={sampleInterval:10,numWorkers:2,filter:"",gifWidth:200,gifHeight:200,interval:.1,numFrames:10,frameDuration:1,keepCameraOn:!1,images:[],video:null,webcamVideoElement:null,cameraStream:null,text:"",fontWeight:"normal",fontSize:"16px",minFontSize:"10px",resizeFont:!1,fontFamily:"sans-serif",fontColor:"#ffffff",textAlign:"center",textBaseline:"bottom",textXCoordinate:null,textYCoordinate:null,progressCallback:r,completeCallback:r,saveRenderingContexts:!1,savedRenderingContexts:[],crossOrigin:"Anonymous"},s=Object.freeze({default:c});function d(){return f.isValid()}function h(){var m,h,p,v,g,b=256,w=499,y=491,C=487,S=503,x=3*S,c=b-1,k=4,O=100,F=16,o=1<<F,W=10,E=10,A=o>>E,R=o<<W-E,T=6,U=(b>>3)*(1<<T),M=30,j=1024,I=256,f=1<<18,l=[],P=[],V=[],L=[];function H(e,t,r,i,n){var o,a,s,c,d,l,u;for((s=t-e)<-1&&(s=-1),b<(c=t+e)&&(c=b),o=t+1,a=t-1,l=1;o<c||s<a;){if(d=L[l++],o<c){u=g[o++];try{u[0]-=d*(u[0]-r)/f|0,u[1]-=d*(u[1]-i)/f|0,u[2]-=d*(u[2]-n)/f|0}catch(e){}}if(s<a){u=g[a--];try{u[0]-=d*(u[0]-r)/f|0,u[1]-=d*(u[1]-i)/f|0,u[2]-=d*(u[2]-n)/f|0}catch(e){}}}}function z(e,t,r,i,n){var o=g[t],a=e/j;o[0]-=a*(o[0]-r)|0,o[1]-=a*(o[1]-i)|0,o[2]-=a*(o[2]-n)|0}function G(e,t,r){var i,n,o,a,s,c,d,l,u,f;for(u=l=~(1<<31),d=c=-1,i=0;i<b;i++)(n=(f=g[i])[0]-e)<0&&(n=-n),(o=f[1]-t)<0&&(o=-o),n+=o,(o=f[2]-r)<0&&(o=-o),(n+=o)<l&&(l=n,c=i),(a=n-(P[i]>>F-k))<u&&(u=a,d=i),s=V[i]>>E,V[i]-=s,P[i]+=s<<W;return V[c]+=A,P[c]-=R,d}(function(e,t,r){var i,n;for(h=e,p=t,v=r,g=new Array(b),i=0;i<b;i++)g[i]=new Array(4),(n=g[i])[0]=n[1]=n[2]=(i<<k+8)/b|0,V[i]=o/b|0,P[i]=0}).apply(this,arguments);var e={map:function(e,t,r){var i,n,o,a,s,c,d;for(s=1e3,d=-1,n=(i=l[t])-1;i<b||0<=n;)i<b&&(s<=(o=(c=g[i])[1]-t)?i=b:(i++,o<0&&(o=-o),(a=c[0]-e)<0&&(a=-a),(o+=a)<s&&((a=c[2]-r)<0&&(a=-a),(o+=a)<s&&(s=o,d=c[3])))),0<=n&&(s<=(o=t-(c=g[n])[1])?n=-1:(n--,o<0&&(o=-o),(a=c[0]-e)<0&&(a=-a),(o+=a)<s&&((a=c[2]-r)<0&&(a=-a),(o+=a)<s&&(s=o,d=c[3]))));return d}};return e.process=function(){return function(){var e,t,r,i,n,o,a,s,c,d,l,u,f,g;for(p<x&&(v=1),m=30+(v-1)/3,u=h,d=(l=(g=p)/(3*v))/O|(f=0),s=j,(a=(o=U)>>T)<=1&&(a=0),e=0;e<a;e++)L[e]=s*((a*a-e*e)*I/(a*a));for(c=p<x?3:p%w!=0?3*w:p%y!=0?3*y:p%C!=0?3*C:3*S,e=0;e<l;)if(z(s,t=G(r=(255&u[f+0])<<k,i=(255&u[f+1])<<k,n=(255&u[f+2])<<k),r,i,n),0!==a&&H(a,t,r,i,n),g<=(f+=c)&&(f-=p),0===d&&(d=1),++e%d==0)for(s-=s/m,(a=(o-=o/M)>>T)<=1&&(a=0),t=0;t<a;t++)L[t]=s*((a*a-t*t)*I/(a*a))}(),function(){var e;for(e=0;e<b;e++)g[e][0]>>=k,g[e][1]>>=k,g[e][2]>>=k,g[e][3]=e}(),function(){var e,t,r,i,n,o,a,s;for(e=s=a=0;e<b;e++){for(i=(n=g[r=e])[1],t=e+1;t<b;t++)(o=g[t])[1]<i&&(r=t,i=o[1]);if(o=g[r],e!=r&&(t=o[0],o[0]=n[0],n[0]=t,t=o[1],o[1]=n[1],n[1]=t,t=o[2],o[2]=n[2],n[2]=t,t=o[3],o[3]=n[3],n[3]=t),i!=a){for(l[a]=s+e>>1,t=a+1;t<i;t++)l[t]=e;a=i,s=e}}for(l[a]=s+c>>1,t=a+1;t<256;t++)l[t]=c}(),function(){for(var e=[],t=new Array(b),r=0;r<b;r++)t[g[r][3]]=r;for(var i=0,n=0;n<b;n++){var o=t[n];e[i++]=g[o][0],e[i++]=g[o][1],e[i++]=g[o][2]}return e}()},e}function l(){try{this.onmessage=function(e){var t,r=e.data||{};r.gifshot&&(t=i.run(r),postMessage(t))}}catch(e){}var i={dataToRGB:function(e,t,r){for(var i=t*r*4,n=0,o=[];n<i;)o.push(e[n++]),o.push(e[n++]),o.push(e[n++]),n++;return o},componentizedPaletteToArray:function(e){e=e||[];for(var t=[],r=0;r<e.length;r+=3){var i=e[r],n=e[r+1],o=e[r+2];t.push(i<<16|n<<8|o)}return t},processFrameWithQuantizer:function(e,t,r,i){for(var n=this.dataToRGB(e,t,r),o=new h(n,n.length,i),a=o.process(),s=new Uint32Array(this.componentizedPaletteToArray(a)),c=t*r,d=new Uint8Array(c),l=0,u=0;u<c;u++){var f=n[l++],g=n[l++],m=n[l++];d[u]=o.map(f,g,m)}return{pixels:d,palette:s}},run:function(e){var t=e=e||{},r=t.height,i=t.sampleInterval,n=t.width,o=e.data;return this.processFrameWithQuantizer(o,n,r,i)}};return i}function m(v,e,t,r){var b=0,i=(r=r===G?{}:r).loop===G?null:r.loop,w=r.palette===G?null:r.palette;if(e<=0||t<=0||65535<e||65535<t)throw"Width/Height invalid.";v[b++]=71,v[b++]=73,v[b++]=70,v[b++]=56,v[b++]=57,v[b++]=97;if(v[b++]=255&e,v[b++]=e>>8&255,v[b++]=255&t,v[b++]=t>>8&255,v[b++]=0|(null!==w?128:0),v[b++]=0,v[b++]=0,null!==i){if(i<0||65535<i)throw"Loop count invalid.";v[b++]=33,v[b++]=255,v[b++]=11,v[b++]=78,v[b++]=69,v[b++]=84,v[b++]=83,v[b++]=67,v[b++]=65,v[b++]=80,v[b++]=69,v[b++]=50,v[b++]=46,v[b++]=48,v[b++]=3,v[b++]=1,v[b++]=255&i,v[b++]=i>>8&255,v[b++]=0}var y=!1;this.addFrame=function(e,t,r,i,n,o){if(!0===y&&(--b,y=!1),o=o===G?{}:o,e<0||t<0||65535<e||65535<t)throw"x/y invalid.";if(r<=0||i<=0||65535<r||65535<i)throw"Width/Height invalid.";if(n.length<r*i)throw"Not enough pixels for the frame size.";var a=!0,s=o.palette;if(s!==G&&null!==s||(a=!1,s=w),s===G||null===s)throw"Must supply either a local or global palette.";for(var c=function(e){var t=e.length;if(t<2||256<t||t&t-1)throw"Invalid code/color length, must be power of 2 and 2 .. 256.";return t}(s),d=0;c>>=1;)++d;c=1<<d;var l=o.delay===G?0:o.delay,u=o.disposal===G?0:o.disposal;if(u<0||3<u)throw"Disposal out of range.";var f=!1,g=0;if(o.transparent!==G&&null!==o.transparent&&(f=!0,(g=o.transparent)<0||c<=g))throw"Transparent color index.";if(0===u&&!f&&0===l||(v[b++]=33,v[b++]=249,v[b++]=4,v[b++]=u<<2|(!0===f?1:0),v[b++]=255&l,v[b++]=l>>8&255,v[b++]=g,v[b++]=0),v[b++]=44,v[b++]=255&e,v[b++]=e>>8&255,v[b++]=255&t,v[b++]=t>>8&255,v[b++]=255&r,v[b++]=r>>8&255,v[b++]=255&i,v[b++]=i>>8&255,v[b++]=!0===a?128|d-1:0,!0===a)for(var m=0,h=s.length;m<h;++m){var p=s[m];v[b++]=p>>16&255,v[b++]=p>>8&255,v[b++]=255&p}b=function(t,r,e,i){t[r++]=e;var n=r++,o=1<<e,a=o-1,s=1+o,c=1+s,d=e+1,l=0,u=0;function f(e){for(;e<=l;)t[r++]=255&u,u>>=8,l-=8,r===n+256&&(t[n]=255,n=r++)}function g(e){u|=e<<l,l+=d,f(8)}var m=i[0]&a,h={};g(o);for(var p=1,v=i.length;p<v;++p){var b=i[p]&a,w=m<<8|b,y=h[w];if(y===G){for(u|=m<<l,l+=d;8<=l;)t[r++]=255&u,u>>=8,l-=8,r===n+256&&(t[n]=255,n=r++);4096===c?(g(o),c=1+s,d=e+1,h={}):(1<<d<=c&&++d,h[w]=c++),m=b}else m=y}g(m),g(s),f(1),n+1===r?t[n]=0:(t[n]=r-n-1,t[r++]=0);return r}(v,b,d<2?2:d,n)},this.end=function(){return!1===y&&(v[b++]=59,y=!0),b}}function u(){}var D=function(e){this.canvas=null,this.ctx=null,this.repeat=0,this.frames=[],this.numRenderedFrames=0,this.onRenderCompleteCallback=u,this.onRenderProgressCallback=u,this.workers=[],this.availableWorkers=[],this.generatingGIF=!1,this.options=e,this.initializeWebWorkers(e)};D.prototype={workerMethods:l(),initializeWebWorkers:function(e){var t,r=h.toString()+"("+l.toString()+"());",i=void 0,n=void 0,o=void 0,a=-1,s="";for(t=e.numWorkers;++a<t;)i=B.createWebWorker(r),B.isObject(i)?(n=i.objectUrl,o=i.worker,this.workers.push({worker:o,objectUrl:n}),this.availableWorkers.push(o)):(s=i,B.webWorkerError=!!i);this.workerError=s,this.canvas=z.createElement("canvas"),this.canvas.width=e.gifWidth,this.canvas.height=e.gifHeight,this.ctx=this.canvas.getContext("2d"),this.frames=[]},getWorker:function(){return this.availableWorkers.pop()},freeWorker:function(e){this.availableWorkers.push(e)},byteMap:function(){for(var e=[],t=0;t<256;t++)e[t]=String.fromCharCode(t);return e}(),bufferToString:function(e){for(var t=e.length,r="",i=-1;++i<t;)r+=this.byteMap[e[i]];return r},onFrameFinished:function(e){var t=this,r=t.frames,i=!!(t.options.images||[]).length,n=r.every(function(e){return!e.beingProcessed&&e.done});t.numRenderedFrames++,i&&e(t.numRenderedFrames/r.length),t.onRenderProgressCallback(.75*t.numRenderedFrames/r.length),n?t.generatingGIF||t.generateGIF(r,t.onRenderCompleteCallback):B.requestTimeout(function(){t.processNextFrame()},1)},processFrame:function(e){function t(e){var t=(0<arguments.length&&e!==G?e:{}).data;delete s.data,s.pixels=Array.prototype.slice.call(t.pixels),s.palette=Array.prototype.slice.call(t.palette),s.done=!0,s.beingProcessed=!1,r.freeWorker(c),r.onFrameFinished(n)}var r=this,i=(this.options,this.options),n=i.progressCallback,o=i.sampleInterval,a=this.frames,s=void 0,c=void 0;(s=a[e]).beingProcessed||s.done?this.onFrameFinished():(s.sampleInterval=o,s.beingProcessed=!0,s.gifshot=!0,(c=this.getWorker())?(c.onmessage=t,c.postMessage(s)):t({data:r.workerMethods.run(s)}))},startRendering:function(e){this.onRenderCompleteCallback=e;for(var t=0;t<this.options.numWorkers&&t<this.frames.length;t++)this.processFrame(t)},processNextFrame:function(){for(var e=-1,t=0;t<this.frames.length;t++){var r=this.frames[t];if(!r.done&&!r.beingProcessed){e=t;break}}0<=e&&this.processFrame(e)},generateGIF:function(n,e){var t=[],r={loop:this.repeat},i=this.options,o=i.interval,a=i.frameDuration,s=!!i.images.length,c=i.gifHeight,d=i.gifWidth,l=new m(t,d,c,r),u=this.onRenderProgressCallback,f=s?100*o:0,g=void 0;this.generatingGIF=!0,B.each(n,function(e,t){var r=t.palette;u(.75+.25*t.position*1/n.length);for(var i=0;i<a;i++)l.addFrame(0,0,d,c,t.pixels,{palette:r,delay:f})}),l.end(),u(1),this.frames=[],this.generatingGIF=!1,B.isFunction(e)&&(g=this.bufferToString(t),e("data:image/gif;base64,"+B.btoa(g)))},setRepeat:function(e){this.repeat=e},addFrame:function(e,t){t=B.isObject(t)?t:{};var r=this.ctx,i=this.options,n=i.gifWidth,o=i.gifHeight,a=B.getFontSize(t),s=t,c=s.filter,d=s.fontColor,l=s.fontFamily,u=s.fontWeight,f=(s.gifHeight,s.gifWidth,s.text),g=s.textAlign,m=s.textBaseline,h=t.textXCoordinate?t.textXCoordinate:"left"===g?1:"right"===g?n:n/2,p=t.textYCoordinate?t.textYCoordinate:"top"===m?1:"center"===m?o/2:o,v=u+" "+a+" "+l,b=void 0;try{r.filter=c,r.drawImage(e,0,0,n,o),f&&(r.font=v,r.fillStyle=d,r.textAlign=g,r.textBaseline=m,r.fillText(f,h,p)),b=r.getImageData(0,0,n,o),this.addFrameImageData(b)}catch(e){return""+e}},addFrameImageData:function(e){var t=0<arguments.length&&e!==G?e:{},r=this.frames,i=t.data;this.frames.push({data:i,width:t.width,height:t.height,palette:null,dithering:null,done:!1,beingProcessed:!1,position:r.length})},onRenderProgress:function(e){this.onRenderProgressCallback=e},isRendering:function(){return this.generatingGIF},getBase64GIF:function(t){var r=this;r.startRendering(function(e){r.destroyWorkers(),B.requestTimeout(function(){t(e)},0)})},destroyWorkers:function(){if(!this.workerError){var e=this.workers;B.each(e,function(e,t){var r=t.worker,i=t.objectUrl;r.terminate(),B.URL.revokeObjectURL(i)})}}};function N(){}var g={getGIF:function(e,t){var r=0<arguments.length&&e!==G?e:{},i=t;i=B.isFunction(i)?i:N;var n=z.createElement("canvas"),o=void 0,a=!!r.images.length,s=r.cameraStream,c=r.crop,d=r.filter,l=r.fontColor,u=r.fontFamily,f=r.fontWeight,g=r.keepCameraOn,m=(r.numWorkers,r.progressCallback),h=r.saveRenderingContexts,p=r.savedRenderingContexts,v=r.text,b=r.textAlign,w=r.textBaseline,y=r.videoElement,C=r.videoHeight,S=r.videoWidth,x=r.webcamVideoElement,k=Number(r.gifWidth),O=Number(r.gifHeight),F=Number(r.interval),W=(Number(r.sampleInterval),a?0:1e3*F),E=[],A=p.length?p.length:r.numFrames,R=A,T=new D(r),U=B.getFontSize(r),M=r.textXCoordinate?r.textXCoordinate:"left"===b?1:"right"===b?k:k/2,j=r.textYCoordinate?r.textYCoordinate:"top"===w?1:"center"===w?O/2:O,I=f+" "+U+" "+u,P=c?Math.floor(c.scaledWidth/2):0,V=c?S-c.scaledWidth:0,L=c?Math.floor(c.scaledHeight/2):0,H=c?C-c.scaledHeight:0;A=A!==G?A:10,F=F!==G?F:.1,n.width=k,n.height=O,o=n.getContext("2d"),function e(){p.length||0!==y.currentTime?function t(){var r=R-1;function e(){var e;h&&E.push(o.getImageData(0,0,k,O)),v&&(o.font=I,o.fillStyle=l,o.textAlign=b,o.textBaseline=w,o.fillText(v,M,j)),e=o.getImageData(0,0,k,O),T.addFrameImageData(e),m((A-(R=r))/A),0<r&&B.requestTimeout(t,W),R||T.getBase64GIF(function(e){i({error:!1,errorCode:"",errorMsg:"",image:e,cameraStream:s,videoElement:y,webcamVideoElement:x,savedRenderingContexts:E,keepCameraOn:g})})}p.length?(o.putImageData(p[A-R],0,0),e()):function t(){try{S<V&&(V=S),C<H&&(H=C),P<0&&(P=0),L<0&&(L=0),o.filter=d,o.drawImage(y,P,L,V,H,0,0,k,O),e()}catch(e){if("NS_ERROR_NOT_AVAILABLE"!==e.name)throw e;B.requestTimeout(t,100)}}()}():B.requestTimeout(e,100)}()},getCropDimensions:function(e){var t=0<arguments.length&&e!==G?e:{},r=t.videoWidth,i=t.videoHeight,n=t.gifWidth,o=t.gifHeight,a={width:0,height:0,scaledWidth:0,scaledHeight:0};return i<r?(a.width=Math.round(r*(o/i))-n,a.scaledWidth=Math.round(a.width*(i/o))):(a.height=Math.round(i*(n/r))-o,a.scaledHeight=Math.round(a.height*(r/n))),a}},p={loadedData:!1,defaultVideoDimensions:{width:640,height:480},findVideoSize:function e(t){e.attempts=e.attempts||0;var r=t.cameraStream,i=t.completedCallback,n=t.videoElement;n&&(0<n.videoWidth&&0<n.videoHeight?(n.removeEventListener("loadeddata",p.findVideoSize),i({videoElement:n,cameraStream:r,videoWidth:n.videoWidth,videoHeight:n.videoHeight})):e.attempts<10?(e.attempts+=1,B.requestTimeout(function(){p.findVideoSize(t)},400)):i({videoElement:n,cameraStream:r,videoWidth:p.defaultVideoDimensions.width,videoHeight:p.defaultVideoDimensions.height}))},onStreamingTimeout:function(e){B.isFunction(e)&&e({error:!0,errorCode:"getUserMedia",errorMsg:"There was an issue with the getUserMedia API - Timed out while trying to start streaming",image:null,cameraStream:{}})},stream:function(e){var t=B.isArray(e.existingVideo)?e.existingVideo[0]:e.existingVideo,r=e.cameraStream,i=e.completedCallback,n=e.streamedCallback,o=e.videoElement;if(B.isFunction(n)&&n(),t){if(B.isString(t))o.src=t,o.innerHTML='<source src="'+t+'" type="video/'+B.getExtension(t)+'" />';else if(t instanceof Blob){try{o.src=B.URL.createObjectURL(t)}catch(e){}o.innerHTML='<source src="'+t+'" type="'+t.type+'" />'}}else if(o.mozSrcObject)o.mozSrcObject=r;else if(B.URL)try{o.srcObject=r,o.src=B.URL.createObjectURL(r)}catch(e){o.srcObject=r}o.play(),B.requestTimeout(function e(){e.count=e.count||0,!0===p.loadedData?(p.findVideoSize({videoElement:o,cameraStream:r,completedCallback:i}),p.loadedData=!1):10<(e.count+=1)?p.findVideoSize({videoElement:o,cameraStream:r,completedCallback:i}):e()},0)},startStreaming:function(e){var t=B.isFunction(e.error)?e.error:B.noop,r=B.isFunction(e.streamed)?e.streamed:B.noop,i=B.isFunction(e.completed)?e.completed:B.noop,n=e.crossOrigin,o=e.existingVideo,a=e.lastCameraStream,s=e.options,c=e.webcamVideoElement,d=B.isElement(o)?o:c||z.createElement("video");n&&(d.crossOrigin=s.crossOrigin),d.autoplay=!0,d.loop=!0,d.muted=!0,d.addEventListener("loadeddata",function(e){p.loadedData=!0,s.offset&&(d.currentTime=s.offset)}),o?p.stream({videoElement:d,existingVideo:o,completedCallback:i}):a?p.stream({videoElement:d,cameraStream:a,streamedCallback:r,completedCallback:i}):B.getUserMedia({video:!0},function(e){p.stream({videoElement:d,cameraStream:e,streamedCallback:r,completedCallback:i})},t)},startVideoStreaming:function(a,e){var t=1<arguments.length&&e!==G?e:{},r=t.timeout!==G?t.timeout:0,i=t.callback,n=t.webcamVideoElement,o=void 0;0<r&&(o=B.requestTimeout(function(){p.onStreamingTimeout(i)},1e4)),p.startStreaming({error:function(){i({error:!0,errorCode:"getUserMedia",errorMsg:"There was an issue with the getUserMedia API - the user probably denied permission",image:null,cameraStream:{}})},streamed:function(){clearTimeout(o)},completed:function(e){var t=0<arguments.length&&e!==G?e:{},r=t.cameraStream,i=t.videoElement,n=t.videoHeight,o=t.videoWidth;a({cameraStream:r,videoElement:i,videoHeight:n,videoWidth:o})},lastCameraStream:t.lastCameraStream,webcamVideoElement:n,crossOrigin:t.crossOrigin,options:t})},stopVideoStreaming:function(e){var t=e=B.isObject(e)?e:{},r=t.keepCameraOn,i=t.videoElement,n=t.webcamVideoElement,o=e.cameraStream||{},a=o.getTracks&&o.getTracks()||[],s=!!a.length,c=a[0];!r&&s&&B.isFunction(c.stop)&&c.stop(),B.isElement(i)&&!n&&(i.pause(),B.isFunction(B.URL.revokeObjectURL)&&!B.webWorkerError&&i.src&&B.URL.revokeObjectURL(i.src),B.removeElement(i))}};function v(e){e=B.isObject(e)?e:{},p.stopVideoStreaming(e)}function b(e,t){var r=e.options||{},i=r.images,n=r.video,o=Number(r.gifWidth),a=Number(r.gifHeight),s=(Number(r.numFrames),e.cameraStream),c=e.videoElement,d=e.videoWidth,l=e.videoHeight,u=g.getCropDimensions({videoWidth:d,videoHeight:l,gifHeight:a,gifWidth:o}),f=t;r.crop=u,r.videoElement=c,r.videoWidth=d,r.videoHeight=l,r.cameraStream=s,B.isElement(c)&&(c.width=o+u.width,c.height=a+u.height,r.webcamVideoElement||(B.setCSSAttr(c,{position:"fixed",opacity:"0"}),z.body.appendChild(c)),c.play(),g.getGIF(r,function(e){i&&i.length||n&&n.length||v(e),f(e)}))}function w(e,t){if(t=B.isFunction(e)?e:t,e=B.isObject(e)?e:{},B.isFunction(t)){var r=B.mergeOptions(c,e)||{},i=e.cameraStream,n=r.images,o=n?n.length:0,a=r.video,s=r.webcamVideoElement;r=B.mergeOptions(r,{gifWidth:Math.floor(r.gifWidth),gifHeight:Math.floor(r.gifHeight)}),o?function(e){var t=0<arguments.length&&e!==G?e:{},n=t.callback,r=t.images,o=t.options,a=t.imagesLength,i=f.validate({getUserMedia:!0,"window.URL":!0}),s=[],c=0,d=void 0,l=void 0;if(i.error)return n(i);function u(){B.each(s,function(e,t){t&&(t.text?l.addFrame(t.img,o,t.text):l.addFrame(t,o))}),function(e,t){e.getBase64GIF(function(e){t({error:!1,errorCode:"",errorMsg:"",image:e})})}(l,n)}l=new D(o),B.each(r,function(t,r){var i,e=r;r.src&&(e=e.src),B.isElement(e)?(o.crossOrigin&&(e.crossOrigin=o.crossOrigin),s[t]=e,(c+=1)===a&&u()):B.isString(e)&&(d=new Image,o.crossOrigin&&(d.crossOrigin=o.crossOrigin),i=d,r.text&&(i.text=r.text),i.onerror=function(e){if(0==--a)return n({error:"None of the requested images was capable of being retrieved"})},i.onload=function(e){r.text?s[t]={img:i,text:i.text}:s[t]=i,(c+=1)===a&&u(),B.removeElement(i)},i.src=e,B.setCSSAttr(d,{position:"fixed",opacity:"0"}),z.body.appendChild(d))})}({images:n,imagesLength:o,callback:t,options:r}):a?function(e){var t=0<arguments.length&&e!==G?e:{},r=t.callback,i=t.existingVideo,n=t.options,o=f.validate({getUserMedia:!0,"window.URL":!0}),a=void 0,s=void 0;if(o.error)return r(o);if(B.isElement(i)&&i.src){if(s=i.src,a=B.getExtension(s),!B.isSupported.videoCodecs[a])return r(f.messages.videoCodecs)}else B.isArray(i)&&B.each(i,function(e,t){if(a=t instanceof Blob?t.type.substr(t.type.lastIndexOf("/")+1,t.length):t.substr(t.lastIndexOf(".")+1,t.length),B.isSupported.videoCodecs[a])return i=t,!1});p.startStreaming({completed:function(e){e.options=n||{},b(e,r)},existingVideo:i,crossOrigin:n.crossOrigin,options:n})}({existingVideo:a,callback:t,options:r}):function(e){var t=0<arguments.length&&e!==G?e:{},r=t.callback,i=t.lastCameraStream,n=t.options,o=t.webcamVideoElement;if(!d())return r(f.validate());n.savedRenderingContexts.length?g.getGIF(n,function(e){r(e)}):p.startVideoStreaming(function(){var e=0<arguments.length&&arguments[0]!==G?arguments[0]:{};e.options=n||{},b(e,r)},{lastCameraStream:i,callback:r,webcamVideoElement:o,crossOrigin:n.crossOrigin})}({lastCameraStream:i,callback:t,webcamVideoElement:s,options:r})}}var y={utils:o,error:a,defaultOptions:s,createGIF:w,takeSnapShot:function(e,t){if(t=B.isFunction(e)?e:t,e=B.isObject(e)?e:{},B.isFunction(t)){var r=B.mergeOptions(c,e);w(B.mergeOptions(r,{interval:.1,numFrames:1,gifWidth:Math.floor(r.gifWidth),gifHeight:Math.floor(r.gifHeight)}),t)}},stopVideoStreaming:v,isSupported:function(){return f.isValid()},isWebCamGIFSupported:d,isExistingVideoGIFSupported:function(e){var r=!1;if(B.isArray(e)&&e.length){if(B.each(e,function(e,t){B.isSupported.videoCodecs[t]&&(r=!0)}),!r)return!1}else if(B.isString(e)&&e.length&&!B.isSupported.videoCodecs[e])return!1;return f.isValid({getUserMedia:!0})},isExistingImagesGIFSupported:function(){return f.isValid({getUserMedia:!0})},VERSION:"0.4.5"};"function"==typeof G&&G.amd?G([],function(){return y}):C.exports=y}("undefined"!=typeof window?window:{},"undefined"!=typeof document?document:{createElement:function(){}},"undefined"!=typeof window?window.navigator:{})}),k=e(function(e){var t;t=function(){return function(e,t,r){t=t||"",r=r||512;for(var i=atob(e),n=[],o=0;o<i.length;o+=r){for(var a=i.slice(o,o+r),s=new Array(a.length),c=0;c<a.length;c++)s[c]=a.charCodeAt(c);var d=new Uint8Array(s);n.push(d)}return new Blob(n,{type:t})}},e.exports?(e.exports=t(),e.exports.default=e.exports):window.b64toBlob=t()});function O(t,e){var r=Object.keys(t);if(Object.getOwnPropertySymbols){var i=Object.getOwnPropertySymbols(t);e&&(i=i.filter(function(e){return Object.getOwnPropertyDescriptor(t,e).enumerable})),r.push.apply(r,i)}return r}return function(o){var e=o.constructor.utils,a=e.errorHandle,n=e.clamp,s=e.downloadFile,c=o.i18n,d=o.notice,t=o.layers,r=o.player,l=o.loading,i=o.option,u=i.theme,f=i.title,g=o.events.proxy,m=o.template.$video;c.update({"zh-cn":{"Long press, gif length is between 1 second and 10 seconds":"长按,gif 长度为 1 ~ 10 秒","Gif time is too short":"Gif 时间太短","Start creating gif...":"开始创建 gif...","Create gif successfully":"创建 gif 成功","There is another gif in the processing":"正有另一个 gif 在创建中","Release the mouse to start":"放开鼠标即可开始"},"zh-tw":{"Long press, gif length is between 1 second and 10 seconds":"長按,gif 長度為 1 ~ 10 秒","Gif time is too short":"Gif 時間太短","Start creating gif...":"開始創建 gif...","Create gif successfully":"創建 gif 成功","There is another gif in the processing":"正有另一個 gif 在創建中","Release the mouse to start":"放開鼠標即可開始"}});var h=t.add({name:"artplayer-plugin-gif-progress",style:{position:"absolute",top:"0",left:"0",height:"3px",width:"0%","background-color":u}}).$ref,p=!1,v=0,b=null,w=!1,y=0;function C(){h.style.width="0%",clearTimeout(b),b=null}return o.on("destroy",function(){b&&clearTimeout(b)}),{name:"artplayerPluginGif",attach:function(e){g(e,"mousedown",function(){w=!0,C(),y=r.currentTime,v=new Date,d.show(c.get("Long press, gif length is between 1 second and 10 seconds")),function t(){b=setTimeout(function(){var e=parseInt(h.style.width,10);e<=100?(h.style.width="".concat(e+1,"%"),t()):d.show(c.get("Release the mouse to start"))},100)}()}),g(document,"mouseup",function(){w&&(w=!1,function(){C();var e=new Date-v;if(p)d.show(c.get("There is another gif in the processing"));else if(e<1e3)d.show(c.get("Gif time is too short"));else{var t=Math.floor(n(e,1e3,1e4)/100),r=m.videoWidth,i=m.videoHeight;o.plugins.artplayerPluginGif.create({numFrames:t,offset:Math.floor(y),gifHeight:200,gifWidth:r/i*200},function(e){s(e,"".concat(f||"unnamed",".gif"))})}}(),y=0)})},create:function(e,t){var r=0<arguments.length&&void 0!==e?e:{},n=1<arguments.length?t:void 0;p=!0,l.show=!0,o.emit("artplayerPluginGif:start"),d.show(c.get("Start creating gif..."),!1),x.createGIF(function(t){for(var e=1;e<arguments.length;e++){var r=null!=arguments[e]?arguments[e]:{};e%2?O(r,!0).forEach(function(e){S(t,e,r[e])}):Object.getOwnPropertyDescriptors?Object.defineProperties(t,Object.getOwnPropertyDescriptors(r)):O(r).forEach(function(e){Object.defineProperty(t,e,Object.getOwnPropertyDescriptor(r,e))})}return t}({},r,{video:[m.src],crossOrigin:"anonymous"}),function(e){if(e.error)d.show(e.errorMsg),a(!1,e.errorMsg);else if("function"==typeof n){var t=e.image.split(",")[1],r=k(t,"image/gif"),i=URL.createObjectURL(r);d.show(c.get("Create gif successfully")),o.emit("artplayerPluginGif",i),n(i)}p=!1,l.show=!1,o.emit("artplayerPluginGif:end")})}}}});