(function(P,u){"use strict";class $ extends u.Texture{constructor(e){super(e);var t=e instanceof u.Texture?e.bitmap:e;t&&(t.lock=!0)}destroy(e=!1){var t=this.bitmap;t&&e&&(t.lock=!1),super.destroy(e)}getImage(){return{width:this.sourceWidth,height:this.sourceHeight}}setFilters(e,t){}setWraps(e,t){}}class ie extends spine.AssetManager{constructor(e="",t,a){super((s,n)=>a[n]=new $(s.bitmap),e,t)}}var j=spine.Color,ue=spine.SkeletonClipping,ae=spine.Vector2,se=spine.Utils,oe=spine.RegionAttachment,ve=spine.MeshAttachment,ce=spine.ClippingAttachment;class _e{constructor(e,t,a){this.vertices=e,this.numVertices=t,this.numFloats=a}}const Z=["normal","light","multiply","screen"];class K{constructor(e=!0){this.vertexEffect=null,this.tempColor=new j,this.tempColor2=new j,this.vertexSize=8,this.twoColorTint=!1,this.renderable=new _e(null,0,0),this.clipper=new ue,this.temp=new ae,this.temp2=new ae,this.temp3=new j,this.temp4=new j,this._mVerts=new Array(2048),this._mUVs=new Array(2048),this._mColors=new Array(2048),this._triCache=new WeakMap,this._quadTri=new Uint16Array([0,1,2,2,3,0]),this._uvCache=new WeakMap,this._bVerts=new Float32Array(4096),this._bUVs=new Float32Array(4096),this._bIdx=new Uint16Array(4096),this._bMi=0,this._bUi=0,this._bIi=0,this._bVertCount=0,this._bTex=null,this._bBlend=-1,this._bColorNum=0,this._bAlpha=0,this._bIns=null,this._outIndices=new Int32Array(3),this.isRecord=!1,this.recordedDraws=[],this.isRecordOnly=!1,this.twoColorTint=e,e&&(this.vertexSize+=4),this.vertices=se.newFloatArray(this.vertexSize*1024)}_getTriangles(e){if(e===K.QUAD_TRIANGLES)return this._quadTri;let t=this._triCache.get(e);return t&&t.length===e.length||(t=new Uint16Array(e),this._triCache.set(e,t)),t}_getUVs(e){if(e instanceof Float32Array)return e;let t=this._uvCache.get(e);return t&&t.length===e.length||(t=new Float32Array(e),this._uvCache.set(e,t)),t}_ensureBatch(e,t,a){let s=this._bMi+e;if(s>this._bVerts.length){let r=new Float32Array(s*2);r.set(this._bVerts.subarray(0,this._bMi)),this._bVerts=r}let n=this._bUi+t;if(n>this._bUVs.length){let r=new Float32Array(n*2);r.set(this._bUVs.subarray(0,this._bUi)),this._bUVs=r}let h=this._bIi+a;if(h>this._bIdx.length){let r=new Uint16Array(h*2);r.set(this._bIdx.subarray(0,this._bIi)),this._bIdx=r}}_submitDraw(e,t,a,s,n,h,r){this.isRecord&&(this.recordedDraws.push({texture:e,vertices:t instanceof Float32Array?new Float32Array(t):new Float32Array(t),uvs:a instanceof Float32Array?new Float32Array(a):new Float32Array(a),indices:s instanceof Uint16Array?new Uint16Array(s):new Uint16Array(s),alpha:n,blendMode:h,colorNum:r}),this.isRecordOnly)||this._bIns.graphics.drawTriangles(e,0,0,t,a,s,u.Matrix.EMPTY,n,null,h,r)}_flushBatch(){if(this._bMi<=0)return;let e=Z[this._bBlend]||"normal";this._submitDraw(this._bTex,this._bVerts.slice(0,this._bMi),this._bUVs.slice(0,this._bUi),this._bIdx.slice(0,this._bIi),this._bAlpha,e,this._bColorNum),this._bMi=0,this._bUi=0,this._bIi=0,this._bVertCount=0}draw(e,t=-1,a=-1,s,n){let h=this.clipper,r=this.premultipliedAlpha,p=!1,_=this.temp,l=this.temp2,v=this.temp3,g=this.temp4,d=this.renderable,y=null,b=null,M=e.drawOrder,I=null,T=e.color,U=8,J=!1,k=this._mVerts,R=this._mUVs,C=this._mColors;this._bMi=0,this._bUi=0,this._bIi=0,this._bVertCount=0,this._bTex=null,this._bBlend=-1,this._bIns=s,t==-1&&(J=!0);for(let te=0,Pe=M.length;te=0&&t==B.data.index&&(J=!0),!J){h.clipEndWithSlot(B);continue}a>=0&&a==B.data.index&&(J=!1);let z=B.getAttachment(),q=null,G;if(z instanceof oe){let A=z;d.vertices=this.vertices,d.numVertices=4,d.numFloats=X<<2,A.computeWorldVertices(B.bone,d.vertices,0,X),b=K.QUAD_TRIANGLES,y=A.uvs,q=A.region.renderObject.page.name,G=n[q],I=A.color}else if(z instanceof ve){let A=z;d.vertices=this.vertices,d.numVertices=A.worldVerticesLength>>1,d.numFloats=d.numVertices*X,d.numFloats>d.vertices.length&&(d.vertices=this.vertices=se.newFloatArray(d.numFloats)),A.computeWorldVertices(B,0,A.worldVerticesLength,d.vertices,0,X),b=A.triangles,q=A.region.renderObject.page.name,G=n[q],y=A.uvs,I=A.color}else if(z instanceof ce){let A=z;this._flushBatch(),h.clipStart(B,A);continue}else{h.clipEndWithSlot(B);continue}if(G!=null){let A=B.color,w=this.tempColor;w.r=T.r*A.r*I.r,w.g=T.g*A.g*I.g,w.b=T.b*A.b*I.b,w.a=T.a*A.a*I.a,r&&(w.r*=w.a,w.g*=w.a,w.b*=w.a);let Q=B.data.blendMode,le=255<<24|(w.b*255|0)<<16|(w.g*255|0)<<8|(w.r*255|0),he=w.a;if(h.isClipping()){this._flushBatch();let o,V;h.clipTriangles(d.vertices,d.numFloats,b,b.length,y,w,null,p),o=new Float32Array(h.clippedVertices),V=h.clippedTriangles;let x=0,D=0,N=0,E=0;if(this.vertexEffect!=null){let W=this.vertexEffect,f=o;for(let c=0,L=o.length;c0&&(this._nativeLog("disabled missing atlas page textures="+r.join("|")),e.nativeSpineDestroy&&e.nativeSpineDestroy(n),this._nativeSpineHandle=0,this._nativeSpineActive=!1)}catch(n){this._nativeLog("init exception="+n),this._nativeSpineActive=!1,this._nativeSpineHandle&&e.nativeSpineDestroy&&e.nativeSpineDestroy(this._nativeSpineHandle),this._nativeSpineHandle=0}}_getNativeSpineAssetKey(){let e=this._templet;if(!e)return"";let t=e._textureDic&&e._textureDic.root?e._textureDic.root:"",a=e.jsonOrSkelUrl||e._jsonOrSkelUrl||"";return a&&t&&a.indexOf(t)!=0?t+a:a||t||""}_isNativeSpineDisabledAsset(e){if(!e)return!1;let t=i.nativeDisabledAssetKeys;if(!t||t.length<=0)return!1;for(let a=0;a=0)return!0}return!1}_isNativeSpineKtxPages(e){if(!e||e.length<=0)return!1;for(let t=0;t=0)continue;let p=n>0?a[n-1].trim():"";if(n>0&&p.length!=0)continue;let _=r,l=this._resolveNativeTexture(_),v=l&&l.getImage?l.getImage():null,g=v&&v.width?v.width:l?l.sourceWidth||l.width:0,d=v&&v.height?v.height:l?l.sourceHeight||l.height:0;if(g<=0||d<=0)continue;let y=-1;for(let M=n+1;M=0?a[y].trim()!=b&&(a[y]=b,s=!0,this._nativeLog("atlas size patch page="+_+" new="+b)):(a.splice(n+1,0,b),s=!0,this._nativeLog("atlas size insert page="+_+" new="+b),n++)}return s?a.join(` `):e}_resolveNativeTexture(e){let t=this._templet?this._templet._textureDic:null;if(!t||!e)return null;let a=e.replace(/\\/g,"/"),s=a.substring(a.lastIndexOf("/")+1);return t[e]||t[a]||t[s]||null}_getNativeTextureId(e){if(!e||!e._getSource)return 0;let t=e._getSource();return t?t.id!=null?t.id:t:0}_refreshNativeTextureIds(){if(!this._nativeSpineTextures||!this._nativeTextureIds)return!1;let e=!0;for(let t=0;t>1,s=this._nativeCounts[3];i._nativeProfileSpines++,i._nativeProfileDraws+=e,i._nativeProfileVertices+=a,i._nativeProfileIndices+=s,e>i._nativeProfileMaxDraws&&(i._nativeProfileMaxDraws=e),a>i._nativeProfileMaxVertices&&(i._nativeProfileMaxVertices=a),s>i._nativeProfileMaxIndices&&(i._nativeProfileMaxIndices=s),!(t-i._nativeProfileFrame0&&this.currentPlayTime>=this._nativePlayEnd&&(this._nativeSpineActive=!1,this._pause=!0,this.timer.clear(this,this._update),this._currAniName=null,this.event(u.Event.STOPPED)),!0)}_isNativeRenderableVisible(){let e=this._ins;for(;e;){if(e.destroyed||e._visible===!1||e._style&&e._style.alpha<=.01)return!1;e=e.parent}return!0}_getNativeTextureCacheKey(){if(!this._currAniName||!this._duration||this._duration<=0)return null;let e=i.nativeTextureCacheFPS>0?i.nativeTextureCacheFPS:15,t=this._nativeLoop?this.currentPlayTime%this._duration:Math.min(this.currentPlayTime,this._duration),a=Math.floor(t*e),s=this._getNativeSpineAssetKey(),n="";return this.skeleton&&this.skeleton.skin&&(n=this.skeleton.skin.name||""),s+"|"+n+"|"+this._nativeTextureCacheVariant+"|"+this._currAniName+"|"+e+"|"+a}_tryRenderNativeTextureCache(e,t){i._nativeTextureCacheRequests++;let a=u.LayaGL.instance,s=!!(a&&a.nativeSpineRenderTrianglesToTexture);if(!i.nativeTextureCache||!s)return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipFeature++,this._logNativeTextureCacheProfile(),!1;if(!this._nativeSpineActive||!this._currAniName)return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipState++,this._logNativeTextureCacheProfile(),!1;let n=this._getNativeTextureCacheKey();if(!n)return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipState++,this._logNativeTextureCacheProfile(),!1;if(i._nativeTextureCacheGlobalCount>=i.nativeTextureCacheMaxFrames&&!i._nativeTextureCacheGlobal[n])return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipCapacity++,this._logNativeTextureCacheProfile(),!1;let h=this._ins,r=i._nativeTextureCacheGlobal[n];if(r&&r.texture)return i._nativeTextureCacheHits++,h.graphics.drawTexture(r.texture,r.x,r.y,r.width,r.height,null,1,null,null,i._nativeTextureCacheFlipUV),this._logNativeTextureCacheProfile(),!0;let p=this._calcNativeDrawBounds(t);if(!p)return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipState++,this._logNativeTextureCacheProfile(),!1;let _=2,l=Math.ceil(p.maxX-p.minX+_*2),v=Math.ceil(p.maxY-p.minY+_*2),g=l*v,d=i.nativeTextureCacheMaxSize;if(l<=0||v<=0||l>d||v>d)return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipSize++,this._logNativeTextureCacheProfile(),!1;if(g>i.nativeTextureCacheMaxPixels)return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipSize++,this._logNativeTextureCacheProfile(),!1;if(i._nativeTextureCacheGlobalPixels+g>i.nativeTextureCacheMaxPixels)return i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipCapacity++,this._logNativeTextureCacheProfile(),!1;let y=new u.RenderTexture2D(l,v,u.RenderTextureFormat.R8G8B8A8,u.RenderTextureDepthFormat.DEPTHSTENCIL_NONE),b=new u.Texture(y,null,l,v),M=y._getSource(),I=M?M.id!=null?M.id:M:0;if(!I)return b.destroy(!0),i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipNative++,this._logNativeTextureCacheProfile(),!1;let T=new Float32Array(20);T[0]=1,T[1]=0,T[2]=0,T[3]=1,T[4]=-p.minX+_,T[5]=-p.minY+_,T[6]=l,T[7]=v,T[8]=t,T[9]=0,T[14]=I,T[15]=l,T[16]=v;let U=!1;try{a.nativeSpineRenderTrianglesToTexture(this._nativeTextureIds,this._nativeMeta,this._nativeAlphas,this._nativeVertices,this._nativeUVs,this._nativeIndices,T),U=!0}catch{U=!1}return U?(r={texture:b,x:p.minX-_,y:p.minY-_,width:l,height:v,pixels:g},i._nativeTextureCacheGlobal[n]=r,i._nativeTextureCacheGlobalCount++,i._nativeTextureCacheGlobalPixels+=g,i._nativeTextureCacheGlobalOrder.push(n),i._nativeTextureCacheBuilds++,h.graphics.drawTexture(b,r.x,r.y,r.width,r.height,null,1,null,null,i._nativeTextureCacheFlipUV),this._logNativeTextureCacheProfile(),!0):(b.destroy(!0),i._nativeTextureCacheSkips++,i._nativeTextureCacheSkipNative++,this._logNativeTextureCacheProfile(),!1)}_calcNativeDrawBounds(e){let t=1e20,a=1e20,s=-1e20,n=-1e20,h=this._nativeMeta,r=this._nativeVertices;for(let p=0;ps&&(s=d),yn&&(n=y)}}return t>s||a>n?null:{minX:t,minY:a,maxX:s,maxY:n}}_clearNativeTextureCache(){let e=this._nativeTextureCache;for(let t in e){let a=e[t];a&&a.texture&&a.texture.destroy(!0)}this._nativeTextureCache={},this._nativeTextureCacheCount=0}static _trimNativeTextureCacheGlobal(e){let t=i.nativeTextureCacheMaxPixels;for(;i._nativeTextureCacheGlobalOrder.length>0&&(i._nativeTextureCacheGlobalCount>=i.nativeTextureCacheMaxFrames||i._nativeTextureCacheGlobalPixels+e>t);){let a=i._nativeTextureCacheGlobalOrder.shift(),s=i._nativeTextureCacheGlobal[a];s&&(s.texture&&s.texture.destroy(!0),i._nativeTextureCacheGlobalPixels-=s.pixels||0,i._nativeTextureCacheGlobalPixels<0&&(i._nativeTextureCacheGlobalPixels=0),delete i._nativeTextureCacheGlobal[a],i._nativeTextureCacheGlobalCount--,i._nativeTextureCacheGlobalCount<0&&(i._nativeTextureCacheGlobalCount=0))}}static clearNativeTextureCache(e=!0){let t=i._nativeTextureCacheGlobal;for(let a in t){let s=t[a];s&&s.texture&&s.texture.destroy(!0)}i._nativeTextureCacheGlobal={},i._nativeTextureCacheGlobalOrder.length=0,i._nativeTextureCacheGlobalCount=0,i._nativeTextureCacheGlobalPixels=0,e&&(i._nativeTextureCacheRequests=0,i._nativeTextureCacheHits=0,i._nativeTextureCacheBuilds=0,i._nativeTextureCacheSkips=0,i._nativeTextureCacheSkipFeature=0,i._nativeTextureCacheSkipState=0,i._nativeTextureCacheSkipCapacity=0,i._nativeTextureCacheSkipSize=0,i._nativeTextureCacheSkipNative=0)}_logNativeTextureCacheProfile(){}_drainNativeEvents(e){if(!e||!e.nativeSpineDrainEvents||!this._nativeSpineHandle)return;let t=e.nativeSpineDrainEvents(this._nativeSpineHandle);if(!t)return;let a;try{a=JSON.parse(t)}catch{return}for(let s=0;sn)throw new Error("SpineSkeleton: start must less than end.");if(typeof p=="number"&&(p=this.getAniNameByIndex(e)),a||this._pause||this._currAniName!=p){this._currAniName=p,this.state.setAnimation(this.trackIndex,p,t);let _=this.state.getCurrent(this.trackIndex);_.animationStart=s,n&&n<_.animationEnd&&(_.animationEnd=n);let l=_.animation.duration;if(this._duration=l,this._playStart=s,this._playEnd=n<=l?n:l,this._pause&&(this._pause=!1,this.timer.frameLoop(1,this,this._update,null,!0)),!i.native)this._destroyNativeSpine();else if(this._nativeSpineHandle&&s==0&&n==0){let g=window.webglPlus;this._clearNativeTextureCache(),this._nativeSpineActive=!!(g&&g.nativeSpineSetAnimation&&g.nativeSpineSetAnimation(this._nativeSpineHandle,this.trackIndex,p,t)),this._nativeLoop=t,this._nativePlayEnd=t?0:l,this._nativeStoppedByEvent=!1,this.currentPlayTime=0,this._nativeHasPose=!1}else this._nativeSpineHandle&&(this._nativeSpineActive=!1);let v=this.timeKeeper;v&&(v.lastTime=Date.now()/1e3,v.delta=0,v.frameTime=0,v.frameCount=0),this._update()}}_update(){let e=this.state,t=this.skeleton;if(!e||!t)return;this.timeKeeper.update();let a=this.timeKeeper.delta*this._playbackRate;if(this._updateNative(a)||(e.update(a),e=this.state,t=this.skeleton,!e||!t)||(t.setToSetupPose(),e.apply(t),t.updateWorldTransform(),e=this.state,t=this.skeleton,!e||!t))return;let s=e.getCurrent(this.trackIndex);s&&(this.currentPlayTime=s.animationLast>0?s.animationLast:0);let n=this._ins;n.displayedInStage&&(n.graphics.clear(),this.skeletonRenderer.draw(t,-1,-1,n,this._templet._textureDic))}getAnimNum(){return this._templet.skeletonData.animations.length}getAniNameByIndex(e){return this._templet.getAniNameByIndex(e)}getSlotByName(e){return this.skeleton.findSlot(e)}playbackRate(e){this._playbackRate=e}showSkinByName(e){this.showSkinByIndex(this._templet.getSkinIndexByName(e))}showSkinByIndex(e){let t=this.skeleton.data.skins[e];if(this.skeleton.setSkin(t),this.skeleton.setSlotsToSetupPose(),this._nativeTextureCacheVariant++,i.native&&this._nativeSpineHandle&&t){let a=window.webglPlus;a&&a.nativeSpineSetSkin&&a.nativeSpineSetSkin(this._nativeSpineHandle,t.name)}}stop(){this._pause||(this._pause=!0,this._currAniName=null,this.timer.clear(this,this._update),this.state.update(-this.currentPlayTime),this.currentPlayTime=0,this.event(u.Event.STOPPED),this._soundChannelArr.length>0&&this._onAniSoundStoped(!0))}paused(){if(!this._pause&&(this._pause=!0,this.timer.clear(this,this._update),this.event(u.Event.PAUSED),this._soundChannelArr.length>0)){let e;for(let t=this._soundChannelArr.length,a=0;a0){let t;for(let a=this._soundChannelArr.length,s=0;s0&&this._onAniSoundStoped(!0),this.state&&(this.state.clearListeners(),this.state.clearTracks(),this.state=null),this.skeleton=null,this.skeletonRenderer=null,this.timeKeeper=null,this._templet&&(this._templet._removeReference(1),this._templet=null),this._destroyNativeSpine(),super.destroy(e)}get templet(){return this._templet}addAnimation(e,t=!1,a=0){a/=1e3;let s=e;if(typeof s=="number"&&(s=this.getAniNameByIndex(s)),this._currAniName=s,this.state.addAnimation(this.trackIndex,s,t,a),i.native&&this._nativeSpineHandle&&this._nativeSpineActive){let n=window.webglPlus;n&&n.nativeSpineAddAnimation&&n.nativeSpineAddAnimation(this._nativeSpineHandle,this.trackIndex,s,t,a)}}setMix(e,t,a){a/=1e3;let s=e;typeof s=="number"&&(s=this.getAniNameByIndex(s));let n=t;if(typeof n=="number"&&(n=this.getAniNameByIndex(n)),this.stateData.setMix(s,n,a),i.native&&this._nativeSpineHandle){let h=window.webglPlus;h&&h.nativeSpineSetMix&&h.nativeSpineSetMix(this._nativeSpineHandle,s,n,a)}}getBoneByName(e){return this.skeleton.findBone(e)}getSkeleton(){return this.skeleton}setSlotAttachment(e,t){if(this.skeleton.setAttachment(e,t),this._nativeTextureCacheVariant++,i.native&&this._nativeSpineHandle){let a=window.webglPlus;a&&a.nativeSpineSetAttachment&&a.nativeSpineSetAttachment(this._nativeSpineHandle,e,t)}}set currentTime(e){if(!(!this._currAniName||!this._templet)){if(e/=1e3,ethis._playEnd||e>this._duration)throw new Error("AnimationPlayer: value must large than playStartTime,small than playEndTime.");this.state.update(e-this.currentPlayTime),this.currentPlayTime=e,this._nativeSpineActive=!1}}get playState(){return this._currAniName?this._pause?i.paused:i.playing:i.stopped}static isNativePluginReady(){let e=window.webglPlus;return!!(e&&e.nativeSpineCreate&&e.nativeSpineDestroy&&e.nativeSpineGetPages&&e.nativeSpineSetAnimation&&e.nativeSpineUpdateDraws)}}i.stopped=0,i.paused=1,i.playing=2,i.nativeDebug=!1,i.native=!0,i.nativeOnlyKtx=!1,i.nativeForceWhite=!1,i.nativeProfile=!1,i.nativeProfileEvery=120,i.nativeDisabledAssetKeys=[],i.nativeTextureCache=!1,i.nativeTextureCacheFPS=15,i.nativeTextureCacheMaxSize=4096,i.nativeTextureCacheMaxFrames=240,i.nativeTextureCacheMaxPixels=16*1024*1024,i.nativeTextureCacheProfile=!1,i._nativeProfileFrame=0,i._nativeProfileSpines=0,i._nativeProfileDraws=0,i._nativeProfileVertices=0,i._nativeProfileIndices=0,i._nativeProfileMaxDraws=0,i._nativeProfileMaxVertices=0,i._nativeProfileMaxIndices=0,i._nativeTextureCacheGlobal={},i._nativeTextureCacheGlobalCount=0,i._nativeTextureCacheGlobalPixels=0,i._nativeTextureCacheGlobalOrder=[],i._nativeTextureCacheRequests=0,i._nativeTextureCacheHits=0,i._nativeTextureCacheBuilds=0,i._nativeTextureCacheSkips=0,i._nativeTextureCacheSkipFeature=0,i._nativeTextureCacheSkipState=0,i._nativeTextureCacheSkipCapacity=0,i._nativeTextureCacheSkipSize=0,i._nativeTextureCacheSkipNative=0,i._nativeTextureCacheFlipUV=[0,1,1,1,1,0,0,0],i.enableCache=!1,u.ILaya.regClass(i),u.ClassUtils.regClass("laya.layaspine.SpineSkeleton",i),u.ClassUtils.regClass("Laya.SpineSkeleton",i);class Y extends u.Resource{constructor(){super(),this._isDestroyed=!1,this._textureDic={},this._aniCache={},this._layaPremultipliedAlpha=!0,this._spinePremultipliedAlpha=!1,this._aniCache={}}get templet(){return this._templet}set templet(e){this._templet=e}get isDestroyed(){return this._isDestroyed}set isDestroyed(e){this._isDestroyed=e}get spinePremultipliedAlpha(){return this._spinePremultipliedAlpha}set spinePremultipliedAlpha(e){this._spinePremultipliedAlpha=e}buildArmature(){return new i(this)}getAniNameByIndex(e){let t=this.skeletonData.animations[e];return t?t.name:null}getSkinIndexByName(e){let t=this.skeletonData.skins,a;for(let s=0,n=t.length;s