import{x as vt,y as ne,z as _,A as Dt,D as re,F as z,H as ae,V as oe,J as ot,d as E,v as W,K as T,p as At,L as Ft,M as ct,N as L,w as ie,O as Ut,P as Ht,Q as le,e as Et,T as Wt,U as ce,W as he,X as de,Y as ue,Z as Lt,_ as pe,$ as fe}from"./index-DvAPfvr6.js";import{c as me,R as xe,S as ge,B as Ce,a as _e,b as ye,d as ve,A as be,C as Te}from"./RenderTargetSystem-Cp6tD-lP.js";import{S as qt}from"./Filter-BiIvpnZm.js";class Se{constructor(){this.isBatchable=!1}reset(){this.isBatchable=!1,this.context=null,this.graphicsData&&(this.graphicsData.destroy(),this.graphicsData=null)}destroy(){this.reset()}}class Pe{constructor(){this.instructions=new ne}init(){this.instructions.reset()}destroy(){this.instructions.destroy(),this.instructions=null}}const bt=class yt{constructor(t){this._renderer=t,this._managedContexts=new vt({renderer:t,type:"resource",name:"graphicsContext"})}init(t){yt.defaultOptions.bezierSmoothness=(t==null?void 0:t.bezierSmoothness)??yt.defaultOptions.bezierSmoothness}getContextRenderData(t){return this.getGpuContext(t).graphicsData||this._initContextRenderData(t)}updateGpuContext(t){const e=t._gpuData,s=!!e[this._renderer.uid],n=e[this._renderer.uid]||this._initContext(t);return(t.dirty||!s)&&(s&&n.reset(),n.isBatchable=!1,t.dirty=!1),n}getGpuContext(t){return t._gpuData[this._renderer.uid]||this._initContext(t)}_initContextRenderData(t){const e=new Pe,s=this.getGpuContext(t);return s.graphicsData=e,e.init(),e}_initContext(t){const e=new Se;return e.context=t,t._gpuData[this._renderer.uid]=e,this._managedContexts.add(t),e}destroy(){this._managedContexts.destroy(),this._renderer=null}};bt.extension={type:[_.CanvasSystem],name:"graphicsContext"};bt.defaultOptions={bezierSmoothness:.5};let Me=bt;class Ot{constructor(t,e){this.state=qt.for2d(),this.renderer=t,this._adaptor=e,this.renderer.runners.contextChange.add(this),this._managedGraphics=new vt({renderer:t,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(t){return!1}addRenderable(t,e){this._managedGraphics.add(t),this.renderer.renderPipes.batch.break(e),e.add(t)}updateRenderable(t){}execute(t){t.isRenderable&&this._adaptor.execute(this,t)}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null}}Ot.extension={type:[_.CanvasPipes],name:"graphics"};class ke{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(t=>{Dt.return(t)}),this.batches.length=0}}class Vt{constructor(t,e){this.state=qt.for2d(),this.renderer=t,this._adaptor=e,this.renderer.runners.contextChange.add(this),this._managedGraphics=new vt({renderer:t,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(t){const e=t.context,s=!!t._gpuData,r=this.renderer.graphicsContext.updateGpuContext(e);return!!(r.isBatchable||s!==r.isBatchable)}addRenderable(t,e){const n=this.renderer.graphicsContext.updateGpuContext(t.context);t.didViewUpdate&&this._rebuild(t),n.isBatchable?this._addToBatcher(t,e):(this.renderer.renderPipes.batch.break(e),e.add(t))}updateRenderable(t){const s=this._getGpuDataForRenderable(t).batches;for(let n=0;n{const i=Dt.get(re);return l.copyTo(i),i.renderable=t,i.roundPixels=o,i})}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null}}Vt.extension={type:[_.WebGLPipes,_.WebGPUPipes],name:"graphics"};z.add(Ot);z.add(Vt);z.add(Me);z.add(ae);class dt extends oe{constructor(t){t instanceof ot&&(t={context:t});const{context:e,roundPixels:s,...n}=t||{};super({label:"Graphics",...n}),this.renderPipeId="graphics",e?this.context=e:(this.context=this._ownedContext=new ot,this.context.autoGarbageCollect=this.autoGarbageCollect),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=s??!1}set context(t){t!==this._context&&(this._context&&(this._context.off("update",this.onViewUpdate,this),this._context.off("unload",this.unload,this)),this._context=t,this._context.on("update",this.onViewUpdate,this),this._context.on("unload",this.unload,this),this.onViewUpdate())}get context(){return this._context}get bounds(){return this._context.bounds}updateBounds(){}containsPoint(t){return this._context.containsPoint(t)}destroy(t){this._ownedContext&&!t?this._ownedContext.destroy(t):(t===!0||(t==null?void 0:t.context)===!0)&&this._context.destroy(t),this._ownedContext=null,this._context=null,super.destroy(t)}_onTouch(t){this._gcLastUsed=t,this._context._gcLastUsed=t}_callContextMethod(t,e){return this.context[t](...e),this}setFillStyle(...t){return this._callContextMethod("setFillStyle",t)}setStrokeStyle(...t){return this._callContextMethod("setStrokeStyle",t)}fill(...t){return this._callContextMethod("fill",t)}stroke(...t){return this._callContextMethod("stroke",t)}texture(...t){return this._callContextMethod("texture",t)}beginPath(){return this._callContextMethod("beginPath",[])}cut(){return this._callContextMethod("cut",[])}arc(...t){return this._callContextMethod("arc",t)}arcTo(...t){return this._callContextMethod("arcTo",t)}arcToSvg(...t){return this._callContextMethod("arcToSvg",t)}bezierCurveTo(...t){return this._callContextMethod("bezierCurveTo",t)}closePath(){return this._callContextMethod("closePath",[])}ellipse(...t){return this._callContextMethod("ellipse",t)}circle(...t){return this._callContextMethod("circle",t)}path(...t){return this._callContextMethod("path",t)}lineTo(...t){return this._callContextMethod("lineTo",t)}moveTo(...t){return this._callContextMethod("moveTo",t)}quadraticCurveTo(...t){return this._callContextMethod("quadraticCurveTo",t)}rect(...t){return this._callContextMethod("rect",t)}roundRect(...t){return this._callContextMethod("roundRect",t)}poly(...t){return this._callContextMethod("poly",t)}regularPoly(...t){return this._callContextMethod("regularPoly",t)}roundPoly(...t){return this._callContextMethod("roundPoly",t)}roundShape(...t){return this._callContextMethod("roundShape",t)}filletRect(...t){return this._callContextMethod("filletRect",t)}chamferRect(...t){return this._callContextMethod("chamferRect",t)}star(...t){return this._callContextMethod("star",t)}svg(...t){return this._callContextMethod("svg",t)}restore(...t){return this._callContextMethod("restore",t)}save(){return this._callContextMethod("save",[])}getTransform(){return this.context.getTransform()}resetTransform(){return this._callContextMethod("resetTransform",[])}rotateTransform(...t){return this._callContextMethod("rotate",t)}scaleTransform(...t){return this._callContextMethod("scale",t)}setTransform(...t){return this._callContextMethod("setTransform",t)}transform(...t){return this._callContextMethod("transform",t)}translateTransform(...t){return this._callContextMethod("translate",t)}clear(){return this._callContextMethod("clear",[])}get fillStyle(){return this._context.fillStyle}set fillStyle(t){this._context.fillStyle=t}get strokeStyle(){return this._context.strokeStyle}set strokeStyle(t){this._context.strokeStyle=t}clone(t=!1){return t?new dt(this._context.clone()):(this._ownedContext=null,new dt(this._context))}lineStyle(t,e,s){E(W,"Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.");const n={};return t&&(n.width=t),e&&(n.color=e),s&&(n.alpha=s),this.context.strokeStyle=n,this}beginFill(t,e){E(W,"Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.");const s={};return t!==void 0&&(s.color=t),e!==void 0&&(s.alpha=e),this.context.fillStyle=s,this}endFill(){E(W,"Graphics#endFill is no longer needed. Use Graphics#fill to fill the shape with the desired style."),this.context.fill();const t=this.context.strokeStyle;return(t.width!==ot.defaultStrokeStyle.width||t.color!==ot.defaultStrokeStyle.color||t.alpha!==ot.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...t){return E(W,"Graphics#drawCircle has been renamed to Graphics#circle"),this._callContextMethod("circle",t)}drawEllipse(...t){return E(W,"Graphics#drawEllipse has been renamed to Graphics#ellipse"),this._callContextMethod("ellipse",t)}drawPolygon(...t){return E(W,"Graphics#drawPolygon has been renamed to Graphics#poly"),this._callContextMethod("poly",t)}drawRect(...t){return E(W,"Graphics#drawRect has been renamed to Graphics#rect"),this._callContextMethod("rect",t)}drawRoundedRect(...t){return E(W,"Graphics#drawRoundedRect has been renamed to Graphics#roundRect"),this._callContextMethod("roundRect",t)}drawStar(...t){return E(W,"Graphics#drawStar has been renamed to Graphics#star"),this._callContextMethod("star",t)}}const Tt=class K{static _getPatternRepeat(t,e){const s=t&&t!=="clamp-to-edge",n=e&&e!=="clamp-to-edge";return s&&n?"repeat":s?"repeat-x":n?"repeat-y":"no-repeat"}start(t,e,s){}execute(t,e){var l,i,p,f;const s=e.elements;if(!s||!s.length)return;const n=t.renderer,r=n.canvasContext,o=r.activeContext;for(let y=0;y>>24&255)/255,v=(F>>>24&255)/255,X=((i=n.filter)==null?void 0:i.alphaMultiplier)??1,et=S*v*X;if(et<=0)continue;o.globalAlpha=et;const st=q&16777215,Q=F&16777215,P=Ft(ct(Q,st)),w=m.frame,R=C.addressModeU??C.addressMode,ut=C.addressModeV??C.addressMode,nt=K._getPatternRepeat(R,ut),O=m.source._resolution??m.source.resolution??1,J=(f=(p=g.renderable)==null?void 0:p.renderGroup)==null?void 0:f.isCachedAsTexture,d=w.x*O,u=w.y*O,x=w.width*O,V=w.height*O,G=g.bounds,M=n.renderTarget.renderTarget.isRoot,U=G.minX,H=G.minY,I=G.maxX-G.minX,D=G.maxY-G.minY,N=m.rotate,c=m.uvs,Y=Math.min(c.x0,c.x1,c.x2,c.x3,c.y0,c.y1,c.y2,c.y3),j=Math.max(c.x0,c.x1,c.x2,c.x3,c.y0,c.y1,c.y2,c.y3),b=nt!=="no-repeat"&&(Y<0||j>1),it=N&&!(!b&&(P!==16777215||N));it?(K._tempPatternMatrix.copyFrom(g.transform),At.matrixAppendRotationInv(K._tempPatternMatrix,N,U,H,I,D),r.setContextTransform(K._tempPatternMatrix,g.roundPixels===1,void 0,J&&M)):r.setContextTransform(g.transform,g.roundPixels===1,void 0,J&&M);const pt=I,ft=D;let rt=it?0:U,at=it?0:H;if(!it&&g.roundPixels===1&&(rt|=0,at|=0),b){let mt=k;const Z=P!==16777215&&!N,tt=w.width<=m.source.width&&w.height<=m.source.height;Z&&tt&&(mt=T.getTintedCanvas({texture:m},P));const xt=o.createPattern(mt,nt);if(!xt)continue;const Pt=pt,Mt=ft;if(Pt===0||Mt===0)continue;const kt=1/Pt,wt=1/Mt,Rt=(c.x1-c.x0)*kt,Gt=(c.y1-c.y0)*kt,Bt=(c.x3-c.x0)*wt,It=(c.y3-c.y0)*wt,ee=c.x0-Rt*rt-Bt*at,se=c.y0-Gt*rt-It*at,gt=m.source.pixelWidth,Ct=m.source.pixelHeight;K._tempPatternMatrix.set(Rt*gt,Gt*Ct,Bt*gt,It*Ct,ee*gt,se*Ct),T.applyPatternTransform(xt,K._tempPatternMatrix),o.fillStyle=xt,o.fillRect(rt,at,pt,ft)}else{const Z=P!==16777215||N?T.getTintedCanvas({texture:m},P):k,tt=Z!==k;o.drawImage(Z,tt?0:d,tt?0:u,tt?Z.width:x,tt?Z.height:V,rt,at,pt,ft)}}}};Tt._tempPatternMatrix=new L;Tt.extension={type:[_.CanvasPipesAdaptor],name:"batch"};let we=Tt;class Nt{constructor(t){this._colorStack=[],this._colorStackIndex=0,this._currentColor=0,this._renderer=t}buildStart(){this._colorStack[0]=15,this._colorStackIndex=1,this._currentColor=15}push(t,e,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;n[this._colorStackIndex]=n[this._colorStackIndex-1]&t.mask;const r=this._colorStack[this._colorStackIndex];r!==this._currentColor&&(this._currentColor=r,s.add({renderPipeId:"colorMask",colorMask:r,canBundle:!1})),this._colorStackIndex++}pop(t,e,s){this._renderer.renderPipes.batch.break(s);const n=this._colorStack;this._colorStackIndex--;const r=n[this._colorStackIndex-1];r!==this._currentColor&&(this._currentColor=r,s.add({renderPipeId:"colorMask",colorMask:r,canBundle:!1}))}execute(t){}destroy(){this._renderer=null,this._colorStack=null}}Nt.extension={type:[_.CanvasPipes],name:"colorMask"};function Re(a,t,e,s,n,r){r=Math.max(0,Math.min(r,Math.min(s,n)/2)),a.moveTo(t+r,e),a.lineTo(t+s-r,e),a.quadraticCurveTo(t+s,e,t+s,e+r),a.lineTo(t+s,e+n-r),a.quadraticCurveTo(t+s,e+n,t+s-r,e+n),a.lineTo(t+r,e+n),a.quadraticCurveTo(t,e+n,t,e+n-r),a.lineTo(t,e+r),a.quadraticCurveTo(t,e,t+r,e)}function Yt(a,t){switch(t.type){case"rectangle":{const e=t;a.rect(e.x,e.y,e.width,e.height);break}case"roundedRectangle":{const e=t;Re(a,e.x,e.y,e.width,e.height,e.radius);break}case"circle":{const e=t;a.moveTo(e.x+e.radius,e.y),a.arc(e.x,e.y,e.radius,0,Math.PI*2);break}case"ellipse":{const e=t;a.ellipse?(a.moveTo(e.x+e.halfWidth,e.y),a.ellipse(e.x,e.y,e.halfWidth,e.halfHeight,0,0,Math.PI*2)):(a.save(),a.translate(e.x,e.y),a.scale(e.halfWidth,e.halfHeight),a.moveTo(1,0),a.arc(0,0,1,0,Math.PI*2),a.restore());break}case"triangle":{const e=t;a.moveTo(e.x,e.y),a.lineTo(e.x2,e.y2),a.lineTo(e.x3,e.y3),a.closePath();break}case"polygon":default:{const e=t,s=e.points;if(!(s!=null&&s.length))break;a.moveTo(s[0],s[1]);for(let n=2;n>>24&255)/255,f=(i>>>24&255)/255,y=((q=s.filter)==null?void 0:q.alphaMultiplier)??1,A=p*f*y;if(A<=0)return;const g=l&16777215,m=i&16777215,k=Ft(ct(m,g)),C=s._roundPixels|e._roundPixels;r.save(),n.setContextTransform(o,C===1),n.setBlendMode(e.groupBlendMode);const B=e.context.instructions;for(let st=0;st0&&(o.globalAlpha=i.alpha,o.fillStyle=i.toHex(),o.fillRect(l.x,l.y,l.width,l.height),o.globalAlpha=1)}}finishRenderPass(){}copyToTexture(t,e,s,n,r){const l=this._renderTargetSystem.getGpuRenderTarget(t).canvas,i=e.source,{context:p}=this._ensureCanvas(i),f=(r==null?void 0:r.x)??0,y=(r==null?void 0:r.y)??0;return p.drawImage(l,s.x,s.y,n.width,n.height,f,y,n.width,n.height),i.update(),e}destroyGpuRenderTarget(t){}_ensureCanvas(t){let e=t.resource;(!e||!ue.test(e))&&(e=Lt.get().createCanvas(t.pixelWidth,t.pixelHeight),t.resource=e),(e.width!==t.pixelWidth||e.height!==t.pixelHeight)&&(e.width=t.pixelWidth,e.height=t.pixelHeight);const s=e.getContext("2d");return{canvas:e,context:s}}}class Jt extends xe{constructor(t){super(t),this.adaptor=new Oe,this.adaptor.init(t,this)}}Jt.extension={type:[_.CanvasSystem],name:"renderTarget"};class Kt{constructor(t){}init(){}initSource(t){}generateCanvas(t){const e=Lt.get().createCanvas(),s=e.getContext("2d"),n=T.getCanvasSource(t);if(!n)return e;const r=t.frame,o=t.source._resolution??t.source.resolution??1,l=r.x*o,i=r.y*o,p=r.width*o,f=r.height*o;return e.width=Math.ceil(p),e.height=Math.ceil(f),s.drawImage(n,l,i,p,f,0,0,p,f),e}getPixels(t){const e=this.generateCanvas(t);return{pixels:e.getContext("2d",{willReadFrequently:!0}).getImageData(0,0,e.width,e.height).data,width:e.width,height:e.height}}destroy(){}}Kt.extension={type:[_.CanvasSystem],name:"texture"};const Ve=[...ge,zt,$t,Kt,Jt],Ne=[Ce,_e,ye,ve,be,jt,Nt,Te],Ye=[we,Xt],Qt=[],Zt=[],te=[];z.handleByNamedList(_.CanvasSystem,Qt);z.handleByNamedList(_.CanvasPipes,Zt);z.handleByNamedList(_.CanvasPipesAdaptor,te);z.add(...Ve,...Ne,...Ye);class Xe extends pe{constructor(){const t={name:"canvas",type:fe.CANVAS,systems:Qt,renderPipes:Zt,renderPipeAdaptors:te};super(t)}}export{Xe as CanvasRenderer};