UNPKG

@curiousmedia/preloadjs-animate-composition-loader

Version:

A PreloadJS Loader that handles the loading of Adobe Animate CreateJS Exports

3 lines (2 loc) 3.05 kB
!function(e,t){"object"==typeof exports&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((e="undefined"!=typeof globalThis?globalThis:e||self)["preloadjs-animate-composition-loader"]={})}(this,(function(e){"use strict";const t="animate_composition";class s extends createjs.AbstractLoader{constructor(e,s){super(e,s,t),this._manifestQueue=null,this.compositionsIDMap={}}static addPlaySoundOnWindow(){window.playSound=(e,t,s)=>createjs.Sound.play(e,{interrupt:createjs.Sound.INTERRUPT_EARLY,loop:t,offset:s})}static get MANIFEST_PROGRESS(){return.25}static canLoadItem(e){return e.type===t}destroy(){super.destroy(),this._manifestQueue.close()}_createRequest(){this._request=new createjs.JavaScriptLoader(this._item)}handleEvent(e){const t=window.AdobeAn;switch(e.type){case"complete":{if(this._rawResult=e.target.getResult(!0),!t.compositions)throw new Error("Using out of date flash export! "+this._item.src);let i;if(this.compositionsIDMap[this._item.src])i=this.compositionsIDMap[this._item.src];else{let e=Object.keys(t.compositions);for(let t=0,s=e.length;t<s;t++)if(!this.compositionsIDMap[e[t]]){i=e[t];break}this.compositionsIDMap[this._item.src]=i}this._item.assetsPath=this._item.src.slice(0,this._item.src.lastIndexOf("/")+1);let o=this._item.comp=t.compositions[i],r=this._result=this._item.lib=o.getLibrary();if(delete t.compositions[i],!r)throw new Error("Something went wrong. Lib not found");return this._sendProgress(s.MANIFEST_PROGRESS),void this._loadManifest(r)}case"progress":return e.loaded*=s.MANIFEST_PROGRESS,this.progress=e.loaded/e.total,(isNaN(this.progress)||this.progress===1/0)&&(this.progress=0),void this._sendProgress(e)}super._handleEvent(e)}_loadManifest(e){if(e.properties.manifest&&e.properties.manifest.length){let t=new createjs.LoadQueue(this._preferXHR,this._item.assetsPath,this._item.crossOrigin);t.installPlugin(createjs.Sound),t.on("complete",this._handleManifestComplete,this,!0),t.on("fileload",this._handleManifestFileLoad,this),t.on("progress",this._handleManifestProgress,this),t.on("error",this._handleManifestError,this,!0),this._manifestQueue=t;let s=[];for(let t=0,i=e.properties.manifest.length;t<i;t++)s.push(e.properties.manifest[t]);t.loadManifest(s)}else this._sendComplete()}_handleManifestFileLoad(e){if(e&&"image"===e.item.type){this._item.comp.getImages()[e.item.id]=e.result}}_handleManifestComplete(e){let t=this._item.comp,s=t.getLibrary(),i=t.getSpriteSheet(),o=e.target,r=s.ssMetadata;for(let e=0;e<r.length;e++)i[r[e].name]=new createjs.SpriteSheet({images:[o.getResult(r[e].name)],frames:r[e].frames});this._sendComplete()}_handleManifestProgress(e){this.progress=e.progress*(1-s.MANIFEST_PROGRESS)+s.MANIFEST_PROGRESS,this._sendProgress(this.progress)}_handleManifestError(e){let t=new createjs.Event("fileerror");t.item=e.data,this.dispatchEvent(t)}}e.ANIMATE_COMPOSITION=t,e.AnimateCompositionLoader=s,Object.defineProperty(e,"__esModule",{value:!0})})); //# sourceMappingURL=preloadjs-animate-composition-loader.js.map