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