UNPKG

pixi.js

Version:

<p align="center"> <a href="https://pixijs.com" target="_blank" rel="noopener noreferrer"> <img height="150" src="https://files.pixijs.download/branding/pixijs-logo-transparent-dark.svg?v=1" alt="PixiJS logo"> </a> </p> <br/> <p align="center">

9 lines (8 loc) • 14.6 kB
/*! * PixiJS - v8.15.0 * Compiled Mon, 05 Jan 2026 10:10:58 UTC * * PixiJS is licensed under the MIT License. * http://www.opensource.org/licenses/mit-license */this.PIXI=this.PIXI||{};var gif_js=function(A){"use strict";var He=typeof globalThis!="undefined"?globalThis:typeof window!="undefined"?window:typeof global!="undefined"?global:typeof self!="undefined"?self:{};function ee(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function qe(r){return r&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}function Ye(r){return r&&Object.prototype.hasOwnProperty.call(r,"default")&&Object.keys(r).length===1?r.default:r}function Ke(r){if(r.__esModule)return r;var t=r.default;if(typeof t=="function"){var e=function a(){return this instanceof a?Reflect.construct(t,arguments,this.constructor):t.apply(this,arguments)};e.prototype=t.prototype}else e={};return Object.defineProperty(e,"__esModule",{value:!0}),Object.keys(r).forEach(function(a){var n=Object.getOwnPropertyDescriptor(r,a);Object.defineProperty(e,a,n.get?n:{enumerable:!0,get:function(){return r[a]}})}),e}var T={},z={},B={};Object.defineProperty(B,"__esModule",{value:!0});var te=B.loop=ie=B.conditional=ae=B.parse=void 0,re=function r(t,e){var a=arguments.length>2&&arguments[2]!==void 0?arguments[2]:{},n=arguments.length>3&&arguments[3]!==void 0?arguments[3]:a;if(Array.isArray(e))e.forEach(function(u){return r(t,u,a,n)});else if(typeof e=="function")e(t,a,n,r);else{var o=Object.keys(e)[0];Array.isArray(e[o])?(n[o]={},r(t,e[o],a,n[o])):n[o]=e[o](t,a,n,r)}return a},ae=B.parse=re,ne=function(t,e){return function(a,n,o,u){e(a,n,o)&&u(a,t,n,o)}},ie=B.conditional=ne,oe=function(t,e){return function(a,n,o,u){for(var i=[],c=a.pos;e(a,n,o);){var p={};if(u(a,t,n,p),a.pos===c)break;c=a.pos,i.push(p)}return i}};te=B.loop=oe;var g={};Object.defineProperty(g,"__esModule",{value:!0});var se=g.readBits=be=g.readArray=_e=g.readUnsigned=ye=g.readString=ge=g.peekBytes=fe=g.readBytes=pe=g.peekByte=ce=g.readByte=de=g.buildStream=void 0,ue=function(t){return{data:t,pos:0}},de=g.buildStream=ue,L=function(){return function(t){return t.data[t.pos++]}},ce=g.readByte=L,le=function(){var t=arguments.length>0&&arguments[0]!==void 0?arguments[0]:0;return function(e){return e.data[e.pos+t]}},pe=g.peekByte=le,U=function(t){return function(e){return e.data.subarray(e.pos,e.pos+=t)}},fe=g.readBytes=U,he=function(t){return function(e){return e.data.subarray(e.pos,e.pos+t)}},ge=g.peekBytes=he,ve=function(t){return function(e){return Array.from(U(t)(e)).map(function(a){return String.fromCharCode(a)}).join("")}},ye=g.readString=ve,me=function(t){return function(e){var a=U(2)(e);return t?(a[1]<<8)+a[0]:(a[0]<<8)+a[1]}},_e=g.readUnsigned=me,xe=function(t,e){return function(a,n,o){for(var u=typeof e=="function"?e(a,n,o):e,i=U(t),c=new Array(u),p=0;p<u;p++)c[p]=i(a);return c}},be=g.readArray=xe,Ie=function(t,e,a){for(var n=0,o=0;o<a;o++)n+=t[e+o]&&Math.pow(2,a-o-1);return n},we=function(t){return function(e){for(var a=L()(e),n=new Array(8),o=0;o<8;o++)n[7-o]=!!(a&1<<o);return Object.keys(t).reduce(function(u,i){var c=t[i];return c.length?u[i]=Ie(n,c.index,c.length):u[i]=n[c.index],u},{})}};se=g.readBits=we,function(r){"use strict";Object.defineProperty(r,"__esModule",{value:!0}),r.default=void 0;var t=B,e=g,a={blocks:function(s){for(var f=0,d=[],_=s.data.length,P=0,b=(0,e.readByte)()(s);b!==f&&b;b=(0,e.readByte)()(s)){if(s.pos+b>=_){var F=_-s.pos;d.push((0,e.readBytes)(F)(s)),P+=F;break}d.push((0,e.readBytes)(b)(s)),P+=b}for(var m=new Uint8Array(P),y=0,v=0;v<d.length;v++)m.set(d[v],y),y+=d[v].length;return m}},n=(0,t.conditional)({gce:[{codes:(0,e.readBytes)(2)},{byteSize:(0,e.readByte)()},{extras:(0,e.readBits)({future:{index:0,length:3},disposal:{index:3,length:3},userInput:{index:6},transparentColorGiven:{index:7}})},{delay:(0,e.readUnsigned)(!0)},{transparentColorIndex:(0,e.readByte)()},{terminator:(0,e.readByte)()}]},function(l){var s=(0,e.peekBytes)(2)(l);return s[0]===33&&s[1]===249}),o=(0,t.conditional)({image:[{code:(0,e.readByte)()},{descriptor:[{left:(0,e.readUnsigned)(!0)},{top:(0,e.readUnsigned)(!0)},{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{lct:(0,e.readBits)({exists:{index:0},interlaced:{index:1},sort:{index:2},future:{index:3,length:2},size:{index:5,length:3}})}]},(0,t.conditional)({lct:(0,e.readArray)(3,function(l,s,f){return Math.pow(2,f.descriptor.lct.size+1)})},function(l,s,f){return f.descriptor.lct.exists}),{data:[{minCodeSize:(0,e.readByte)()},a]}]},function(l){return(0,e.peekByte)()(l)===44}),u=(0,t.conditional)({text:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{preData:function(s,f,d){return(0,e.readBytes)(d.text.blockSize)(s)}},a]},function(l){var s=(0,e.peekBytes)(2)(l);return s[0]===33&&s[1]===1}),i=(0,t.conditional)({application:[{codes:(0,e.readBytes)(2)},{blockSize:(0,e.readByte)()},{id:function(s,f,d){return(0,e.readString)(d.blockSize)(s)}},a]},function(l){var s=(0,e.peekBytes)(2)(l);return s[0]===33&&s[1]===255}),c=(0,t.conditional)({comment:[{codes:(0,e.readBytes)(2)},a]},function(l){var s=(0,e.peekBytes)(2)(l);return s[0]===33&&s[1]===254}),p=[{header:[{signature:(0,e.readString)(3)},{version:(0,e.readString)(3)}]},{lsd:[{width:(0,e.readUnsigned)(!0)},{height:(0,e.readUnsigned)(!0)},{gct:(0,e.readBits)({exists:{index:0},resolution:{index:1,length:3},sort:{index:4},size:{index:5,length:3}})},{backgroundColorIndex:(0,e.readByte)()},{pixelAspectRatio:(0,e.readByte)()}]},(0,t.conditional)({gct:(0,e.readArray)(3,function(l,s){return Math.pow(2,s.lsd.gct.size+1)})},function(l,s){return s.lsd.gct.exists}),{frames:(0,t.loop)([n,i,c,o,u],function(l){var s=(0,e.peekByte)()(l);return s===33||s===44})}],h=p;r.default=h}(z);var We=ee(z),j={};Object.defineProperty(j,"__esModule",{value:!0});var Pe=j.deinterlace=void 0,Be=function(t,e){for(var a=new Array(t.length),n=t.length/e,o=function(s,f){var d=t.slice(f*e,(f+1)*e);a.splice.apply(a,[s*e,e].concat(d))},u=[0,4,2,1],i=[8,8,4,2],c=0,p=0;p<4;p++)for(var h=u[p];h<n;h+=i[p])o(h,c),c++;return a};Pe=j.deinterlace=Be;var D={};Object.defineProperty(D,"__esModule",{value:!0});var Fe=D.lzw=void 0,Te=function(t,e,a){var n=4096,o=-1,u=a,i,c,p,h,l,s,f,x,d,_,v,P,I,w,S,C,b=new Array(a),F=new Array(n),m=new Array(n),y=new Array(n+1);for(P=t,c=1<<P,l=c+1,i=c+2,f=o,h=P+1,p=(1<<h)-1,d=0;d<c;d++)F[d]=0,m[d]=d;var v,x,k,I,w,C,S;for(v=x=k=I=w=C=S=0,_=0;_<u;){if(w===0){if(x<h){v+=e[S]<<x,x+=8,S++;continue}if(d=v&p,v>>=h,x-=h,d>i||d==l)break;if(d==c){h=P+1,p=(1<<h)-1,i=c+2,f=o;continue}if(f==o){y[w++]=m[d],f=d,I=d;continue}for(s=d,d==i&&(y[w++]=I,d=f);d>c;)y[w++]=m[d],d=F[d];I=m[d]&255,y[w++]=I,i<n&&(F[i]=f,m[i]=I,i++,!(i&p)&&i<n&&(h++,p+=i)),f=s}w--,b[C++]=y[w],_++}for(_=C;_<u;_++)b[_]=0;return b};Fe=D.lzw=Te,Object.defineProperty(T,"__esModule",{value:!0});var R=T.decompressFrames=Me=T.decompressFrame=$=T.parseGIF=void 0,Se=Ue(z),Ce=B,Oe=g,ke=j,Ae=D;function Ue(r){return r&&r.__esModule?r:{default:r}}var je=function(t){var e=new Uint8Array(t);return(0,Ce.parse)((0,Oe.buildStream)(e),Se.default)},$=T.parseGIF=je,De=function(t){for(var e=t.pixels.length,a=new Uint8ClampedArray(e*4),n=0;n<e;n++){var o=n*4,u=t.pixels[n],i=t.colorTable[u]||[0,0,0];a[o]=i[0],a[o+1]=i[1],a[o+2]=i[2],a[o+3]=u!==t.transparentIndex?255:0}return a},N=function(t,e,a){if(!t.image){console.warn("gif frame does not have associated image.");return}var n=t.image,o=n.descriptor.width*n.descriptor.height,u=(0,Ae.lzw)(n.data.minCodeSize,n.data.blocks,o);n.descriptor.lct.interlaced&&(u=(0,ke.deinterlace)(u,n.descriptor.width));var i={pixels:u,dims:{top:t.image.descriptor.top,left:t.image.descriptor.left,width:t.image.descriptor.width,height:t.image.descriptor.height}};return n.descriptor.lct&&n.descriptor.lct.exists?i.colorTable=n.lct:i.colorTable=e,t.gce&&(i.delay=(t.gce.delay||10)*10,i.disposalType=t.gce.extras.disposal,t.gce.extras.transparentColorGiven&&(i.transparentIndex=t.gce.transparentColorIndex)),a&&(i.patch=De(i)),i},Me=T.decompressFrame=N,Xe=function(t,e){return t.frames.filter(function(a){return a.image}).map(function(a){return N(a,t.gct,e)})};R=T.decompressFrames=Xe;var ze=Object.defineProperty,M=Object.getOwnPropertySymbols,H=Object.prototype.hasOwnProperty,q=Object.prototype.propertyIsEnumerable,Y=(r,t,e)=>t in r?ze(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Ee=(r,t)=>{for(var e in t||(t={}))H.call(t,e)&&Y(r,e,t[e]);if(M)for(var e of M(t))q.call(t,e)&&Y(r,e,t[e]);return r},Ge=(r,t)=>{var e={};for(var a in r)H.call(r,a)&&t.indexOf(a)<0&&(e[a]=r[a]);if(r!=null&&M)for(var a of M(r))t.indexOf(a)<0&&q.call(r,a)&&(e[a]=r[a]);return e};class O{constructor(t){const[{texture:{width:e,height:a}}]=t;this.width=e,this.height=a,this.frames=t,this.textures=this.frames.map(n=>n.texture),this.totalFrames=this.frames.length,this.duration=this.frames[this.totalFrames-1].end}destroy(){for(const t of this.textures)t.destroy(!0);for(const t of this.frames)t.texture=null;this.frames.length=0,this.textures.length=0,Object.assign(this,{frames:null,textures:null,width:0,height:0,duration:0,totalFrames:0})}static from(t,e){if(!t||t.byteLength===0)throw new Error("Invalid buffer");const a=m=>{var y;let v=null;for(const x of m.frames)v=(y=x.gce)!=null?y:v,"image"in x&&!("gce"in x)&&(x.gce=v)},n=$(t);a(n);const o=R(n,!0),u=[],i=n.lsd.width,c=n.lsd.height,p=PIXI.DOMAdapter.get().createCanvas(i,c),h=p.getContext("2d",{willReadFrequently:!0}),l=PIXI.DOMAdapter.get().createCanvas(),s=l.getContext("2d");let f=0,d=null;const _=e!=null?e:{},{fps:P=30}=_,b=Ge(_,["fps"]),F=1e3/P;for(let m=0;m<o.length;m++){const{disposalType:y=2,delay:v=F,patch:x,dims:{width:k,height:I,left:w,top:C}}=o[m];l.width=k,l.height=I,s.clearRect(0,0,k,I);const S=s.createImageData(k,I);S.data.set(x),s.putImageData(S,0,0),y===3&&(d=h.getImageData(0,0,i,c)),h.drawImage(l,w,C);const E=h.getImageData(0,0,i,c);y===2?h.clearRect(0,0,i,c):y===3&&h.putImageData(d,0,0);const V=PIXI.DOMAdapter.get().createCanvas(E.width,E.height);V.getContext("2d").putImageData(E,0,0),u.push({start:f,end:f+v,texture:new PIXI.Texture({source:new PIXI.CanvasSource(Ee({resource:V},b))})}),f+=v}return p.width=p.height=0,l.width=l.height=0,new O(u)}}const K={extension:PIXI.ExtensionType.Asset,detection:{test:async()=>!0,add:async r=>[...r,"gif"],remove:async r=>r.filter(t=>t!=="gif")},loader:{name:"gifLoader",id:"gif",test:r=>PIXI.path.extname(r)===".gif"||r.startsWith("data:image/gif"),load:async(r,t)=>{const e=await(await PIXI.DOMAdapter.get().fetch(r)).arrayBuffer();return O.from(e,t==null?void 0:t.data)},unload:async r=>{r.destroy()}}};var Le=Object.defineProperty,X=Object.getOwnPropertySymbols,W=Object.prototype.hasOwnProperty,Z=Object.prototype.propertyIsEnumerable,J=(r,t,e)=>t in r?Le(r,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):r[t]=e,Re=(r,t)=>{for(var e in t||(t={}))W.call(t,e)&&J(r,e,t[e]);if(X)for(var e of X(t))Z.call(t,e)&&J(r,e,t[e]);return r},$e=(r,t)=>{var e={};for(var a in r)W.call(r,a)&&t.indexOf(a)<0&&(e[a]=r[a]);if(r!=null&&X)for(var a of X(r))t.indexOf(a)<0&&Z.call(r,a)&&(e[a]=r[a]);return e};const Q=class G extends PIXI.Sprite{constructor(...t){const e=t[0]instanceof O?{source:t[0]}:t[0],a=Object.assign({},G.defaultOptions,e),{source:n,fps:o,loop:u,animationSpeed:i,autoPlay:c,autoUpdate:p,onComplete:h,onFrameChange:l,onLoop:s}=a,f=$e(a,["source","fps","loop","animationSpeed","autoPlay","autoUpdate","onComplete","onFrameChange","onLoop"]);super(Re({texture:PIXI.Texture.EMPTY},f)),this.animationSpeed=1,this.loop=!0,this.duration=0,this.autoPlay=!0,this.dirty=!1,this._currentFrame=0,this._autoUpdate=!1,this._isConnectedToTicker=!1,this._playing=!1,this._currentTime=0,this.onRender=()=>this._updateFrame(),this.texture=n.textures[0],this.duration=n.frames[n.frames.length-1].end,this._source=n,this._playing=!1,this._currentTime=0,this._isConnectedToTicker=!1,Object.assign(this,{fps:o,loop:u,animationSpeed:i,autoPlay:c,autoUpdate:p,onComplete:h,onFrameChange:l,onLoop:s}),this.currentFrame=0,c&&this.play()}stop(){this._playing&&(this._playing=!1,this._autoUpdate&&this._isConnectedToTicker&&(PIXI.Ticker.shared.remove(this.update,this),this._isConnectedToTicker=!1))}play(){this._playing||(this._playing=!0,this._autoUpdate&&!this._isConnectedToTicker&&(PIXI.Ticker.shared.add(this.update,this,PIXI.UPDATE_PRIORITY.HIGH),this._isConnectedToTicker=!0),!this.loop&&this.currentFrame===this._source.frames.length-1&&(this._currentTime=0))}get progress(){return this._currentTime/this.duration}get playing(){return this._playing}update(t){var e,a;if(!this._playing)return;const n=this.animationSpeed*t.deltaTime/PIXI.Ticker.targetFPMS,o=this._currentTime+n,u=o%this.duration,i=this._source.frames.findIndex(c=>c.start<=u&&c.end>u);o>=this.duration?this.loop?(this._currentTime=u,this._updateFrameIndex(i),(e=this.onLoop)==null||e.call(this)):(this._currentTime=this.duration,this._updateFrameIndex(this.totalFrames-1),(a=this.onComplete)==null||a.call(this),this.stop()):(this._currentTime=u,this._updateFrameIndex(i))}_updateFrame(){this.dirty&&(this.texture=this._source.frames[this._currentFrame].texture,this.dirty=!1)}get autoUpdate(){return this._autoUpdate}set autoUpdate(t){t!==this._autoUpdate&&(this._autoUpdate=t,!this._autoUpdate&&this._isConnectedToTicker?(PIXI.Ticker.shared.remove(this.update,this),this._isConnectedToTicker=!1):this._autoUpdate&&!this._isConnectedToTicker&&this._playing&&(PIXI.Ticker.shared.add(this.update,this),this._isConnectedToTicker=!0))}get currentFrame(){return this._currentFrame}set currentFrame(t){this._updateFrameIndex(t),this._currentTime=this._source.frames[t].start}get source(){return this._source}_updateFrameIndex(t){var e;if(t<0||t>=this.totalFrames)throw new Error(`Frame index out of range, expecting 0 to ${this.totalFrames}, got ${t}`);this._currentFrame!==t&&(this._currentFrame=t,this.dirty=!0,(e=this.onFrameChange)==null||e.call(this,t))}get totalFrames(){return this._source.totalFrames}destroy(t=!1){this.stop(),super.destroy(),t&&this._source.destroy();const e=null;this._source=e,this.onComplete=e,this.onFrameChange=e,this.onLoop=e}clone(){const t=new G({source:this._source,autoUpdate:this._autoUpdate,loop:this.loop,autoPlay:this.autoPlay,animationSpeed:this.animationSpeed,onComplete:this.onComplete,onFrameChange:this.onFrameChange,onLoop:this.onLoop});return t.dirty=!0,t}};Q.defaultOptions={fps:30,loop:!0,animationSpeed:1,autoPlay:!0,autoUpdate:!0,onComplete:null,onFrameChange:null,onLoop:null};let Ne=Q;return PIXI.extensions.add(K),A.GifAsset=K,A.GifSource=O,A.GifSprite=Ne,A}({});Object.assign(this.PIXI,gif_js); //# sourceMappingURL=gif.min.js.map