@omnimedia/omnitool
Version:
open source video processing tools
3 lines (2 loc) • 26.8 kB
JavaScript
import{a as Zt,b as g}from"./chunk-3G2KQFOA.js";import{c as ee,d as re,f as oe,g as se,h as ne,i as ae,j as ie,l as le,n as ce,p as he}from"./chunk-VZ3PJFW4.js";import{h as ut,r as Kt,u as Qt,v as xt}from"./chunk-VPDWKHO7.js";import{a as gt,b as de,c as pe,d as ue,e as me,f as Ct,g as fe,j as K}from"./chunk-GJVDGVMF.js";import{o as J}from"./chunk-B3RTSQDT.js";import{A as mt,D as Dt,E as ft,L as te,d as p,e as B,g as pt,k as T,m as D,o as I,p as $t,r as Bt,u as $,v as Jt}from"./chunk-OSED66WT.js";var ke="#808080",yt=new T,we=new T,Re=new T,It=new T;function Ge(s,t,e){s.beginPath();for(let r=0;r<e.length;r+=3){let o=e[r]*2,n=e[r+1]*2,a=e[r+2]*2;s.moveTo(t[o],t[o+1]),s.lineTo(t[n],t[n+1]),s.lineTo(t[a],t[a+1]),s.closePath()}s.fill()}function Be(s){return`#${(s&16777215).toString(16).padStart(6,"0")}`}function De(s,t,e,r,o,n){n=Math.max(0,Math.min(n,Math.min(r,o)/2)),s.moveTo(t+n,e),s.lineTo(t+r-n,e),s.quadraticCurveTo(t+r,e,t+r,e+n),s.lineTo(t+r,e+o-n),s.quadraticCurveTo(t+r,e+o,t+r-n,e+o),s.lineTo(t+n,e+o),s.quadraticCurveTo(t,e+o,t,e+o-n),s.lineTo(t,e+n),s.quadraticCurveTo(t,e,t+n,e)}function _t(s,t){switch(t.type){case"rectangle":{let e=t;s.rect(e.x,e.y,e.width,e.height);break}case"roundedRectangle":{let e=t;De(s,e.x,e.y,e.width,e.height,e.radius);break}case"circle":{let e=t;s.arc(e.x,e.y,e.radius,0,Math.PI*2);break}case"ellipse":{let e=t;s.ellipse?s.ellipse(e.x,e.y,e.halfWidth,e.halfHeight,0,0,Math.PI*2):(s.save(),s.translate(e.x,e.y),s.scale(e.halfWidth,e.halfHeight),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{let e=t;s.moveTo(e.x,e.y),s.lineTo(e.x2,e.y2),s.lineTo(e.x3,e.y3),s.closePath();break}default:{let e=t,r=e.points;if(!r?.length)break;s.moveTo(r[0],r[1]);for(let o=2;o<r.length;o+=2)s.lineTo(r[o],r[o+1]);e.closePath&&s.closePath();break}}}function Ie(s,t){if(!t?.length)return!1;for(let e=0;e<t.length;e++){let r=t[e];if(!r?.shape)continue;let o=r.transform,n=o&&!o.isIdentity();n&&(s.save(),s.transform(o.a,o.b,o.c,o.d,o.tx,o.ty)),_t(s,r.shape),n&&s.restore()}return!0}function Ae(s,t,e,r){let o=s.fill;if(o instanceof de){o.buildGradient();let a=o.texture;if(a){let l=g.getTintedPattern(a,t),i=e?It.copyFrom(e).scale(a.source.pixelWidth,a.source.pixelHeight):It.copyFrom(o.transform);return r&&!s.textureSpace&&i.append(r),g.applyPatternTransform(l,i),l}}if(o instanceof pe){let a=g.getTintedPattern(o.texture,t);return g.applyPatternTransform(a,o.transform),a}let n=s.texture;if(n&&n!==Dt.WHITE){if(!n.source.resource)return ke;let a=g.getTintedPattern(n,t),l=e?It.copyFrom(e).scale(n.source.pixelWidth,n.source.pixelHeight):s.matrix;return g.applyPatternTransform(a,l),a}return Be(t)}var tt=class{constructor(){this.shader=null}contextChange(t){}execute(t,e){let r=t.renderer,o=r.canvasContext,n=o.activeContext,a=e.groupTransform,l=r.globalUniforms.globalUniformData?.worldColor??4294967295,i=e.groupColorAlpha,d=(l>>>24&255)/255,h=(i>>>24&255)/255,y=r.filter?.alphaMultiplier??1,_=d*h*y;if(_<=0)return;let H=l&16777215,q=i&16777215,L=ut($(q,H)),k=r._roundPixels|e._roundPixels;n.save(),o.setContextTransform(a,k===1),o.setBlendMode(e.groupBlendMode);let U=e.context.instructions;for(let S=0;S<U.length;S++){let C=U[S];if(C.action==="texture"){let m=C.data,f=m.image,x=f?g.getCanvasSource(f):null;if(!x)continue;let F=m.alpha*_;if(F<=0)continue;let Y=$(m.style,L);n.globalAlpha=F;let M=x;Y!==16777215&&(M=g.getTintedCanvas({texture:f},Y));let W=f.frame,v=f.source._resolution??f.source.resolution??1,R=W.x*v,G=W.y*v,Z=W.width*v,V=W.height*v;M!==x&&(R=0,G=0);let E=m.transform,b=E&&!E.isIdentity(),c=f.rotate;b||c?(yt.copyFrom(a),b&&yt.append(E),c&&mt.matrixAppendRotationInv(yt,c,m.dx,m.dy,m.dw,m.dh),o.setContextTransform(yt,k===1)):o.setContextTransform(a,k===1),n.drawImage(M,R,G,M===x?Z:M.width,M===x?V:M.height,c?0:m.dx,c?0:m.dy,m.dw,m.dh),(b||c)&&o.setContextTransform(a,k===1);continue}let w=C.data,ct=w?.path?.shapePath;if(!ct?.shapePrimitives?.length)continue;let P=w.style,O=$(P.color,L),A=P.alpha*_;if(A<=0)continue;let Q=C.action==="stroke";if(n.globalAlpha=A,Q){let m=P;n.lineWidth=m.width,n.lineCap=m.cap,n.lineJoin=m.join,n.miterLimit=m.miterLimit}let j=ct.shapePrimitives;if(!Q&&w.hole?.shapePath?.shapePrimitives?.length){let m=j[j.length-1];m.holes=w.hole.shapePath.shapePrimitives}for(let m=0;m<j.length;m++){let f=j[m];if(!f?.shape)continue;let x=f.transform,F=x&&!x.isIdentity(),Y=P.texture&&P.texture!==Dt.WHITE,M=P.textureSpace==="global"?x:null,W=Y?me(we,P,f.shape,M):null,v=F?Re.copyFrom(a).append(x):a,R=Ae(P,O,W,v);if(F&&(n.save(),n.transform(x.a,x.b,x.c,x.d,x.tx,x.ty)),Q){let G=P;if(G.alignment!==.5&&!G.pixelLine){let V=[],E=[],b=[];if(Ct[f.shape.type]?.build(f.shape,V)){let Tt=f.shape.closePath??!0;gt(V,G,!1,Tt,E,b),n.fillStyle=R,Ge(n,E,b)}else n.strokeStyle=R,n.beginPath(),_t(n,f.shape),n.stroke()}else n.strokeStyle=R,n.beginPath(),_t(n,f.shape),n.stroke()}else n.fillStyle=R,n.beginPath(),_t(n,f.shape),Ie(n,f.holes)?n.fill("evenodd"):n.fill();F&&n.restore()}}n.restore()}destroy(){this.shader=null}};tt.extension={type:[p.CanvasPipesAdaptor],name:"graphics"};var At=class N{static _getPatternRepeat(t,e){let r=t&&t!=="clamp-to-edge",o=e&&e!=="clamp-to-edge";return r&&o?"repeat":r?"repeat-x":o?"repeat-y":"no-repeat"}start(t,e,r){}execute(t,e){let r=e.elements;if(!r||!r.length)return;let o=t.renderer,n=o.canvasContext,a=n.activeContext;for(let l=0;l<r.length;l++){let i=r[l];if(!i.packAsQuad)continue;let d=i,h=d.texture,y=h?g.getCanvasSource(h):null;if(!y)continue;let _=h.source.style,H=n.smoothProperty,q=_.scaleMode!=="nearest";a[H]!==q&&(a[H]=q),n.setBlendMode(e.blendMode);let L=o.globalUniforms.globalUniformData?.worldColor??4294967295,k=d.color,U=(L>>>24&255)/255,S=(k>>>24&255)/255,C=o.filter?.alphaMultiplier??1,w=U*S*C;if(w<=0)continue;a.globalAlpha=w;let ct=L&16777215,P=k&16777215,O=ut($(P,ct)),A=h.frame,Q=_.addressModeU??_.addressMode,j=_.addressModeV??_.addressMode,m=N._getPatternRepeat(Q,j),f=h.source._resolution??h.source.resolution??1,x=d.renderable?.renderGroup?.isCachedAsTexture,F=A.x*f,Y=A.y*f,M=A.width*f,W=A.height*f,v=d.bounds,R=o.renderTarget.renderTarget.isRoot,G=v.minX,Z=v.minY,V=v.maxX-v.minX,E=v.maxY-v.minY,b=h.rotate,c=h.uvs,Tt=Math.min(c.x0,c.x1,c.x2,c.x3,c.y0,c.y1,c.y2,c.y3),Se=Math.max(c.x0,c.x1,c.x2,c.x3,c.y0,c.y1,c.y2,c.y3),qt=m!=="no-repeat"&&(Tt<0||Se>1),St=b&&!(!qt&&(O!==16777215||b));St?(N._tempPatternMatrix.copyFrom(d.transform),mt.matrixAppendRotationInv(N._tempPatternMatrix,b,G,Z,V,E),n.setContextTransform(N._tempPatternMatrix,d.roundPixels===1,void 0,x&&R)):n.setContextTransform(d.transform,d.roundPixels===1,void 0,x&&R);let ht=St?0:G,dt=St?0:Z,Pt=V,Mt=E;if(qt){let kt=y,z=O!==16777215&&!b,X=A.width<=h.source.width&&A.height<=h.source.height;z&&X&&(kt=g.getTintedCanvas({texture:h},O));let wt=a.createPattern(kt,m);if(!wt)continue;let Lt=Pt,Ot=Mt;if(Lt===0||Ot===0)continue;let Vt=1/Lt,Nt=1/Ot,jt=(c.x1-c.x0)*Vt,Yt=(c.y1-c.y0)*Vt,zt=(c.x3-c.x0)*Nt,Xt=(c.y3-c.y0)*Nt,Pe=c.x0-jt*ht-zt*dt,Me=c.y0-Yt*ht-Xt*dt,Rt=h.source.pixelWidth,Gt=h.source.pixelHeight;N._tempPatternMatrix.set(jt*Rt,Yt*Gt,zt*Rt,Xt*Gt,Pe*Rt,Me*Gt),g.applyPatternTransform(wt,N._tempPatternMatrix),a.fillStyle=wt,a.fillRect(ht,dt,Pt,Mt)}else{let z=O!==16777215||b?g.getTintedCanvas({texture:h},O):y,X=z!==y;a.drawImage(z,X?0:F,X?0:Y,X?z.width:M,X?z.height:W,ht,dt,Pt,Mt)}}}};At._tempPatternMatrix=new T;At.extension={type:[p.CanvasPipesAdaptor],name:"batch"};var xe=At;var et=class{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,r){this._renderer.renderPipes.batch.break(r);let o=this._colorStack;o[this._colorStackIndex]=o[this._colorStackIndex-1]&t.mask;let n=this._colorStack[this._colorStackIndex];n!==this._currentColor&&(this._currentColor=n,r.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1})),this._colorStackIndex++}pop(t,e,r){this._renderer.renderPipes.batch.break(r);let o=this._colorStack;this._colorStackIndex--;let n=o[this._colorStackIndex-1];n!==this._currentColor&&(this._currentColor=n,r.add({renderPipeId:"colorMask",colorMask:n,canBundle:!1}))}execute(t){}destroy(){this._renderer=null,this._colorStack=null}};et.extension={type:[p.CanvasPipes],name:"colorMask"};var Et=class{constructor(){this.isBatchable=!1}reset(){this.isBatchable=!1,this.context=null,this.graphicsData&&(this.graphicsData.destroy(),this.graphicsData=null)}destroy(){this.reset()}},Ht=class{constructor(){this.instructions=new Jt}init(){this.instructions.reset()}destroy(){this.instructions.destroy(),this.instructions=null}},Ft=class Ut{constructor(t){this._renderer=t,this._managedContexts=new J({renderer:t,type:"resource",name:"graphicsContext"})}init(t){Ut.defaultOptions.bezierSmoothness=t?.bezierSmoothness??Ut.defaultOptions.bezierSmoothness}getContextRenderData(t){return this.getGpuContext(t).graphicsData||this._initContextRenderData(t)}updateGpuContext(t){let e=t._gpuData,r=!!e[this._renderer.uid],o=e[this._renderer.uid]||this._initContext(t);return(t.dirty||!r)&&(r&&o.reset(),o.isBatchable=!1,t.dirty=!1),o}getGpuContext(t){return t._gpuData[this._renderer.uid]||this._initContext(t)}_initContextRenderData(t){let e=new Ht,r=this.getGpuContext(t);return r.graphicsData=e,e.init(),e}_initContext(t){let e=new Et;return e.context=t,t._gpuData[this._renderer.uid]=e,this._managedContexts.add(t),e}destroy(){this._managedContexts.destroy(),this._renderer=null}};Ft.extension={type:[p.CanvasSystem],name:"graphicsContext"};Ft.defaultOptions={bezierSmoothness:.5};var ge=Ft;var rt=class{constructor(t,e){this.state=xt.for2d(),this.renderer=t,this._adaptor=e,this.renderer.runners.contextChange.add(this),this._managedGraphics=new J({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}};rt.extension={type:[p.CanvasPipes],name:"graphics"};var Wt=class{constructor(){this.batches=[],this.batched=!1}destroy(){this.batches.forEach(t=>{Bt.return(t)}),this.batches.length=0}},ot=class{constructor(t,e){this.state=xt.for2d(),this.renderer=t,this._adaptor=e,this.renderer.runners.contextChange.add(this),this._managedGraphics=new J({renderer:t,type:"renderable",priority:-1,name:"graphics"})}contextChange(){this._adaptor.contextChange(this.renderer)}validateRenderable(t){let e=t.context,r=!!t._gpuData,n=this.renderer.graphicsContext.updateGpuContext(e);return!!(n.isBatchable||r!==n.isBatchable)}addRenderable(t,e){let o=this.renderer.graphicsContext.updateGpuContext(t.context);t.didViewUpdate&&this._rebuild(t),o.isBatchable?this._addToBatcher(t,e):(this.renderer.renderPipes.batch.break(e),e.add(t))}updateRenderable(t){let r=this._getGpuDataForRenderable(t).batches;for(let o=0;o<r.length;o++){let n=r[o];n._batcher.updateElement(n)}}execute(t){if(!t.isRenderable)return;let e=this.renderer,r=t.context;if(!e.graphicsContext.getGpuContext(r).batches.length)return;let n=r.customShader||this._adaptor.shader;this.state.blendMode=t.groupBlendMode;let a=n.resources.localUniforms.uniforms;a.uTransformMatrix=t.groupTransform,a.uRound=e._roundPixels|t._roundPixels,le(t.groupColorAlpha,a.uColor,0),this._adaptor.execute(this,t)}_rebuild(t){let e=this._getGpuDataForRenderable(t),o=this.renderer.graphicsContext.updateGpuContext(t.context);e.destroy(),o.isBatchable&&this._updateBatchesForRenderable(t,e)}_addToBatcher(t,e){let r=this.renderer.renderPipes.batch,o=this._getGpuDataForRenderable(t).batches;for(let n=0;n<o.length;n++){let a=o[n];r.addToBatch(a,e)}}_getGpuDataForRenderable(t){return t._gpuData[this.renderer.uid]||this._initGpuDataForRenderable(t)}_initGpuDataForRenderable(t){let e=new Wt;return t._gpuData[this.renderer.uid]=e,this._managedGraphics.add(t),e}_updateBatchesForRenderable(t,e){let r=t.context,n=this.renderer.graphicsContext.getGpuContext(r),a=this.renderer._roundPixels|t._roundPixels;e.batches=n.batches.map(l=>{let i=Bt.get(ue);return l.copyTo(i),i.renderable=t,i.roundPixels=a,i})}destroy(){this._managedGraphics.destroy(),this.renderer=null,this._adaptor.destroy(),this._adaptor=null,this.state=null}};ot.extension={type:[p.WebGLPipes,p.WebGPUPipes],name:"graphics"};B.add(rt);B.add(ot);B.add(ge);B.add(fe);var vt=class s extends Kt{constructor(t){t instanceof K&&(t={context:t});let{context:e,roundPixels:r,...o}=t||{};super({label:"Graphics",...o}),this.renderPipeId="graphics",e?this.context=e:(this.context=this._ownedContext=new K,this.context.autoGarbageCollect=this.autoGarbageCollect),this.didViewUpdate=!0,this.allowChildren=!1,this.roundPixels=r??!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?.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 s(this._context.clone()):(this._ownedContext=null,new s(this._context))}lineStyle(t,e,r){I(D,"Graphics#lineStyle is no longer needed. Use Graphics#setStrokeStyle to set the stroke style.");let o={};return t&&(o.width=t),e&&(o.color=e),r&&(o.alpha=r),this.context.strokeStyle=o,this}beginFill(t,e){I(D,"Graphics#beginFill is no longer needed. Use Graphics#fill to fill the shape with the desired style.");let r={};return t!==void 0&&(r.color=t),e!==void 0&&(r.alpha=e),this.context.fillStyle=r,this}endFill(){I(D,"Graphics#endFill is no longer needed. Use Graphics#fill to fill the shape with the desired style."),this.context.fill();let t=this.context.strokeStyle;return(t.width!==K.defaultStrokeStyle.width||t.color!==K.defaultStrokeStyle.color||t.alpha!==K.defaultStrokeStyle.alpha)&&this.context.stroke(),this}drawCircle(...t){return I(D,"Graphics#drawCircle has been renamed to Graphics#circle"),this._callContextMethod("circle",t)}drawEllipse(...t){return I(D,"Graphics#drawEllipse has been renamed to Graphics#ellipse"),this._callContextMethod("ellipse",t)}drawPolygon(...t){return I(D,"Graphics#drawPolygon has been renamed to Graphics#poly"),this._callContextMethod("poly",t)}drawRect(...t){return I(D,"Graphics#drawRect has been renamed to Graphics#rect"),this._callContextMethod("rect",t)}drawRoundedRect(...t){return I(D,"Graphics#drawRoundedRect has been renamed to Graphics#roundRect"),this._callContextMethod("roundRect",t)}drawStar(...t){return I(D,"Graphics#drawStar has been renamed to Graphics#star"),this._callContextMethod("star",t)}};function Ee(s,t,e,r,o,n){n=Math.max(0,Math.min(n,Math.min(r,o)/2)),s.moveTo(t+n,e),s.lineTo(t+r-n,e),s.quadraticCurveTo(t+r,e,t+r,e+n),s.lineTo(t+r,e+o-n),s.quadraticCurveTo(t+r,e+o,t+r-n,e+o),s.lineTo(t+n,e+o),s.quadraticCurveTo(t,e+o,t,e+o-n),s.lineTo(t,e+n),s.quadraticCurveTo(t,e,t+n,e)}function Ce(s,t){switch(t.type){case"rectangle":{let e=t;s.rect(e.x,e.y,e.width,e.height);break}case"roundedRectangle":{let e=t;Ee(s,e.x,e.y,e.width,e.height,e.radius);break}case"circle":{let e=t;s.moveTo(e.x+e.radius,e.y),s.arc(e.x,e.y,e.radius,0,Math.PI*2);break}case"ellipse":{let e=t;s.ellipse?(s.moveTo(e.x+e.halfWidth,e.y),s.ellipse(e.x,e.y,e.halfWidth,e.halfHeight,0,0,Math.PI*2)):(s.save(),s.translate(e.x,e.y),s.scale(e.halfWidth,e.halfHeight),s.moveTo(1,0),s.arc(0,0,1,0,Math.PI*2),s.restore());break}case"triangle":{let e=t;s.moveTo(e.x,e.y),s.lineTo(e.x2,e.y2),s.lineTo(e.x3,e.y3),s.closePath();break}default:{let e=t,r=e.points;if(!r?.length)break;s.moveTo(r[0],r[1]);for(let o=2;o<r.length;o+=2)s.lineTo(r[o],r[o+1]);e.closePath&&s.closePath();break}}}function He(s,t,e){let r=[],o=[],n=[];if(!Ct[t.type]?.build(t,r))return!1;let l=t.closePath??!0;gt(r,e,!1,l,o,n);for(let i=0;i<n.length;i+=3){let d=n[i]*2,h=n[i+1]*2,y=n[i+2]*2;s.moveTo(o[d],o[d+1]),s.lineTo(o[h],o[h+1]),s.lineTo(o[y],o[y+1]),s.closePath()}return!0}function Ue(s,t){if(!t?.length)return!1;for(let e=0;e<t.length;e++){let r=t[e];if(!r?.shape)continue;let o=r.transform,n=o&&!o.isIdentity();n&&(s.save(),s.transform(o.a,o.b,o.c,o.d,o.tx,o.ty)),Ce(s,r.shape),n&&s.restore()}return!0}var st=class{constructor(t){this._warnedMaskTypes=new Set,this._canvasMaskStack=[],this._renderer=t}push(t,e,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"stencilMask",action:"pushMaskBegin",mask:t,inverse:e._maskOptions.inverse,canBundle:!1})}pop(t,e,r){this._renderer.renderPipes.batch.break(r),r.add({renderPipeId:"stencilMask",action:"popMaskEnd",mask:t,inverse:e._maskOptions.inverse,canBundle:!1})}execute(t){if(t.action!=="pushMaskBegin"&&t.action!=="popMaskEnd")return;let e=this._renderer,r=e.canvasContext,o=r?.activeContext;if(!o)return;if(t.action==="popMaskEnd"){this._canvasMaskStack.pop()&&o.restore();return}t.inverse&&this._warnOnce("inverse","CanvasRenderer: inverse masks are not supported on Canvas2D; ignoring inverse flag.");let n=t.mask.mask;if(!(n instanceof vt)){this._warnOnce("nonGraphics","CanvasRenderer: only Graphics masks are supported in Canvas2D; skipping mask."),this._canvasMaskStack.push(!1);return}let a=n,l=a.context?.instructions;if(!l?.length){this._canvasMaskStack.push(!1);return}o.save(),r.setContextTransform(a.groupTransform,(e._roundPixels|a._roundPixels)===1),o.beginPath();let i=!1,d=!1;for(let h=0;h<l.length;h++){let y=l[h],_=y.action;if(_!=="fill"&&_!=="stroke")continue;let H=y.data,q=H?.path?.shapePath;if(!q?.shapePrimitives?.length)continue;let L=_==="stroke",k=q.shapePrimitives;for(let U=0;U<k.length;U++){let S=k[U];if(!S?.shape)continue;let C=S.transform,w=C&&!C.isIdentity();w&&(o.save(),o.transform(C.a,C.b,C.c,C.d,C.tx,C.ty)),L&&H.style?i=He(o,S.shape,H.style)||i:(Ce(o,S.shape),d=Ue(o,S.holes)||d,i=!0),w&&o.restore()}}if(!i){o.restore(),this._canvasMaskStack.push(!1);return}d?o.clip("evenodd"):o.clip(),this._canvasMaskStack.push(!0)}destroy(){this._renderer=null,this._warnedMaskTypes=null,this._canvasMaskStack=null}_warnOnce(t,e){this._warnedMaskTypes.has(t)||(this._warnedMaskTypes.add(t),$t(e))}};st.extension={type:[p.CanvasPipes],name:"stencilMask"};var u="source-over";function ye(){let s=Zt(),t=Object.create(null);return t.inherit=u,t.none=u,t.normal="source-over",t.add="lighter",t.multiply=s?"multiply":u,t.screen=s?"screen":u,t.overlay=s?"overlay":u,t.darken=s?"darken":u,t.lighten=s?"lighten":u,t["color-dodge"]=s?"color-dodge":u,t["color-burn"]=s?"color-burn":u,t["hard-light"]=s?"hard-light":u,t["soft-light"]=s?"soft-light":u,t.difference=s?"difference":u,t.exclusion=s?"exclusion":u,t.saturation=s?"saturation":u,t.color=s?"color":u,t.luminosity=s?"luminosity":u,t["linear-burn"]=s?"color-burn":u,t["linear-dodge"]=s?"color-dodge":u,t["linear-light"]=s?"hard-light":u,t["pin-light"]=s?"hard-light":u,t["vivid-light"]=s?"hard-light":u,t["hard-mix"]=u,t.negation=s?"difference":u,t["normal-npm"]=t.normal,t["add-npm"]=t.add,t["screen-npm"]=t.screen,t.erase="destination-out",t.subtract=u,t.divide=u,t.min=u,t.max=u,t}var Fe=new T,nt=class{constructor(t){this.activeResolution=1,this.smoothProperty="imageSmoothingEnabled",this.blendModes=ye(),this._activeBlendMode="normal",this._projTransform=null,this._outerBlend=!1,this._warnedBlendModes=new Set,this._renderer=t}resolutionChange(t){this.activeResolution=t}init(){let t=this._renderer.background.alpha<1;if(this.rootContext=this._renderer.canvas.getContext("2d",{alpha:t}),this.activeContext=this.rootContext,this.activeResolution=this._renderer.resolution,!this.rootContext.imageSmoothingEnabled){let e=this.rootContext;e.webkitImageSmoothingEnabled?this.smoothProperty="webkitImageSmoothingEnabled":e.mozImageSmoothingEnabled?this.smoothProperty="mozImageSmoothingEnabled":e.oImageSmoothingEnabled?this.smoothProperty="oImageSmoothingEnabled":e.msImageSmoothingEnabled&&(this.smoothProperty="msImageSmoothingEnabled")}}setContextTransform(t,e,r,o){let n=o?T.IDENTITY:this._renderer.globalUniforms.globalUniformData?.worldTransformMatrix||T.IDENTITY,a=Fe;a.copyFrom(n),a.append(t);let l=this._projTransform,i=this.activeResolution;if(r=r||i,l){let d=T.shared;d.copyFrom(a),d.prepend(l),a=d}e?this.activeContext.setTransform(a.a*r,a.b*r,a.c*r,a.d*r,a.tx*i|0,a.ty*i|0):this.activeContext.setTransform(a.a*r,a.b*r,a.c*r,a.d*r,a.tx*i,a.ty*i)}clear(t,e){let r=this.activeContext,o=this._renderer;if(r.clearRect(0,0,o.width,o.height),t){let n=pt.shared.setValue(t);r.globalAlpha=e??n.alpha,r.fillStyle=n.toHex(),r.fillRect(0,0,o.width,o.height),r.globalAlpha=1}}setBlendMode(t){if(this._activeBlendMode===t)return;this._activeBlendMode=t,this._outerBlend=!1;let e=this.blendModes[t];if(!e){this._warnedBlendModes.has(t)||(console.warn(`CanvasRenderer: blend mode "${t}" is not supported in Canvas2D; falling back to "source-over".`),this._warnedBlendModes.add(t)),this.activeContext.globalCompositeOperation="source-over";return}this.activeContext.globalCompositeOperation=e}destroy(){this.rootContext=null,this.activeContext=null,this._warnedBlendModes.clear()}};nt.extension={type:[p.CanvasSystem],name:"canvasContext"};var at=class{constructor(){this.maxTextures=16,this.maxBatchableTextures=16,this.maxUniformBindings=0}init(){}};at.extension={type:[p.CanvasSystem],name:"limits"};var bt=class{init(t,e){this._renderer=t,this._renderTargetSystem=e}initGpuRenderTarget(t){let e=t.colorTexture,{canvas:r,context:o}=this._ensureCanvas(e);return{canvas:r,context:o,width:r.width,height:r.height}}resizeGpuRenderTarget(t){let e=t.colorTexture,{canvas:r}=this._ensureCanvas(e);r.width=t.pixelWidth,r.height=t.pixelHeight}startRenderPass(t,e,r,o){let n=this._renderTargetSystem.getGpuRenderTarget(t);this._renderer.canvasContext.activeContext=n.context,this._renderer.canvasContext.activeResolution=t.resolution,e&&this.clear(t,e,r,o)}clear(t,e,r,o){let a=this._renderTargetSystem.getGpuRenderTarget(t).context,l=o||{x:0,y:0,width:t.pixelWidth,height:t.pixelHeight};if(a.setTransform(1,0,0,1,0,0),a.clearRect(l.x,l.y,l.width,l.height),r){let i=pt.shared.setValue(r);i.alpha>0&&(a.globalAlpha=i.alpha,a.fillStyle=i.toHex(),a.fillRect(l.x,l.y,l.width,l.height),a.globalAlpha=1)}}finishRenderPass(){}copyToTexture(t,e,r,o,n){let l=this._renderTargetSystem.getGpuRenderTarget(t).canvas,i=e.source,{context:d}=this._ensureCanvas(i),h=n?.x??0,y=n?.y??0;return d.drawImage(l,r.x,r.y,o.width,o.height,h,y,o.width,o.height),i.update(),e}destroyGpuRenderTarget(t){}_ensureCanvas(t){let e=t.resource;(!e||!Qt.test(e))&&(e=ft.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);let r=e.getContext("2d");return{canvas:e,context:r}}};var it=class extends he{constructor(t){super(t),this.adaptor=new bt,this.adaptor.init(t,this)}};it.extension={type:[p.CanvasSystem],name:"renderTarget"};var lt=class{constructor(t){}init(){}initSource(t){}generateCanvas(t){let e=ft.get().createCanvas(),r=e.getContext("2d"),o=g.getCanvasSource(t);if(!o)return e;let n=t.frame,a=t.source._resolution??t.source.resolution??1,l=n.x*a,i=n.y*a,d=n.width*a,h=n.height*a;return e.width=Math.ceil(d),e.height=Math.ceil(h),r.drawImage(o,l,i,d,h,0,0,d,h),e}getPixels(t){let 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(){}};lt.extension={type:[p.CanvasSystem],name:"texture"};var We=[...ce,nt,at,lt,it],qe=[ie,ne,se,oe,ae,st,et,re],Le=[xe,tt],ve=[],be=[],Te=[];B.handleByNamedList(p.CanvasSystem,ve);B.handleByNamedList(p.CanvasPipes,be);B.handleByNamedList(p.CanvasPipesAdaptor,Te);B.add(...We,...qe,...Le);var _e=class extends ee{constructor(){let t={name:"canvas",type:te.CANVAS,systems:ve,renderPipes:be,renderPipeAdaptors:Te};super(t)}};export{vt as a,_e as b};
//# sourceMappingURL=chunk-GWNLC4DH.js.map