rapid-render 1.0.10 → 1.0.11

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,5 +1,5 @@
1
- (function(g,M){typeof exports=="object"&&typeof module<"u"?M(exports):typeof define=="function"&&define.amd?define(["exports"],M):(g=typeof globalThis<"u"?globalThis:g||self,M(g.RapidRender={}))})(this,(function(g){"use strict";var M=(n=>(n[n.Float32=0]="Float32",n[n.Uint32=1]="Uint32",n[n.Uint16=2]="Uint16",n))(M||{});class C{usedElemNum;typedArray;arrayType;maxElemNum;bytePerElem;arraybuffer;uint32;float32;uint16;constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=this.getArrayType(t).BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.updateTypedArray()}getArrayType(t){switch(t){case 0:return Float32Array;case 1:return Uint32Array;case 2:return Uint16Array;default:throw new Error("Unsupported ArrayType")}}updateTypedArray(){switch(this.uint32=new Uint32Array(this.arraybuffer),this.float32=new Float32Array(this.arraybuffer),this.uint16=new Uint16Array(this.arraybuffer),this.arrayType){case 0:this.typedArray=this.float32;break;case 1:this.typedArray=this.uint32;break;case 2:this.typedArray=this.uint16;break}}clear(){this.usedElemNum=0}static removeAtIndices(t,e){const r=Math.max(...e.map(o=>o.usedElemNum)),i=[...new Set(t)].filter(o=>o>=0&&o<r).sort((o,h)=>o-h);if(i.length===0)return 0;let s=0,a=0;for(let o=0;o<r;o++){if(a<i.length&&o===i[a]){a++;continue}if(s!==o)for(const h of e)h.typedArray[s]=h.typedArray[o];s++}for(const o of e)o.usedElemNum=s;return r-s}resize(t=0){if(t+=this.usedElemNum,t>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum*=2;return this.setMaxSize(this.maxElemNum),!0}return!1}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.updateTypedArray(),this.typedArray.set(e)}pushUint32(t){this.resize(1),this.uint32[this.usedElemNum++]=t}pushFloat32(t){this.resize(1),this.float32[this.usedElemNum++]=t}push(t){this.resize(1),this.typedArray[this.usedElemNum++]=t}pop(){return this.typedArray[--this.usedElemNum]}top(){return this.typedArray[this.usedElemNum-1]}get(t){return this.typedArray[t]}getArray(t=0,e){return e===void 0?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.usedElemNum}reset(){this.usedElemNum=0}}class J extends C{buffer;gl;dirty=!0;type;webglBufferSize=0;usage;constructor(t,e,r=t.ARRAY_BUFFER,i=t.DYNAMIC_DRAW){super(e),this.gl=t,this.buffer=t.createBuffer(),this.type=r,this.usage=i}makeDirty(){this.dirty=!0}clear(){super.clear(),this.dirty=!1}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize&&(t.bufferData(this.type,this.maxElemNum*this.bytePerElem,this.usage),this.webglBufferSize=this.maxElemNum),t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class m{_r;_g;_b;_a;uint32;premultipliedUint32;static clampByte(t){return t<=0?0:t>=255?255:Math.round(t)}constructor(t,e,r,i=255){this._r=t,this._g=e,this._b=r,this._a=i,this.updateUint()}setClearColor(t){t.clearColor(this.r/255,this.g/255,this.b/255,this.a/255)}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0;const t=m.clampByte(this._a),e=m.clampByte(this._r*t/255),r=m.clampByte(this._g*t/255),i=m.clampByte(this._b*t/255);this.premultipliedUint32=(t<<24|i<<16|r<<8|e)>>>0}reset(){this._r=0,this._g=0,this._b=0,this._a=255,this.updateUint()}setRGBA(t,e,r,i){this.r=t,this.g=e,this.b=r,this.a=i,this.updateUint()}setHSL(t,e,r){t=(t%360+360)%360,e=Math.max(0,Math.min(100,e))/100,r=Math.max(0,Math.min(100,r))/100;const i=(1-Math.abs(2*r-1))*e,s=i*(1-Math.abs(t/60%2-1)),a=r-i/2;let o=0,h=0,c=0;return t<60?[o,h,c]=[i,s,0]:t<120?[o,h,c]=[s,i,0]:t<180?[o,h,c]=[0,i,s]:t<240?[o,h,c]=[0,s,i]:t<300?[o,h,c]=[s,0,i]:[o,h,c]=[i,0,s],this.setRGBA((o+a)*255,(h+a)*255,(c+a)*255,255),this}toHex(){const t=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${t(this._r)}${t(this._g)}${t(this._b)}${t(this._a)}`}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new m(this._r,this._g,this._b,this._a)}toHexString(t=!0){const e=this.r.toString(16).padStart(2,"0"),r=this.g.toString(16).padStart(2,"0"),i=this.b.toString(16).padStart(2,"0"),s=this.a.toString(16).padStart(2,"0");return`#${e}${r}${i}${t?s:""}`}equal(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}equals(t){return this.equal(t)}static FromHSL(t,e,r){return new m(0,0,0).setHSL(t,e,r)}static FromRGB(t,e,r){return new m(t,e,r)}static fromNorm(t,e,r,i=1){return new m(Math.round(t*255),Math.round(e*255),Math.round(r*255),Math.round(i*255))}static clampColorByte(t){return t<=0?0:t>=255?255:Math.round(t)}static packColor(t,e,r,i,s){const a=m.clampColorByte(i),o=s?a/255:1,h=m.clampColorByte(t*o),c=m.clampColorByte(e*o),u=m.clampColorByte(r*o);return(a<<24|u<<16|c<<8|h)>>>0}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);let s=255;return t.length>=8&&(s=parseInt(t.slice(6,8),16)),new m(e,r,i,s)}add(t){return new m(Math.min(this.r+t.r,255),Math.min(this.g+t.g,255),Math.min(this.b+t.b,255),Math.min(this.a+t.a,255))}subtract(t){return new m(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)}divide(t){return t instanceof m?new m(this.r/t.r,this.g/t.g,this.b/t.b,this.a/t.a):new m(this.r/t,this.g/t,this.b/t,this.a/t)}multiply(t){return t instanceof m?new m(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a):new m(this.r*t,this.g*t,this.b*t,this.a*t)}clamp(){this.r=Math.max(0,Math.min(255,this.r)),this.g=Math.max(0,Math.min(255,this.g)),this.b=Math.max(0,Math.min(255,this.b)),this.a=Math.max(0,Math.min(255,this.a))}static Red=new m(255,0,0,255);static Green=new m(0,255,0,255);static Blue=new m(0,0,255,255);static Yellow=new m(255,255,0,255);static Purple=new m(128,0,128,255);static Orange=new m(255,165,0,255);static Pink=new m(255,192,203,255);static Gray=new m(128,128,128,255);static Brown=new m(139,69,19,255);static Cyan=new m(0,255,255,255);static Magenta=new m(255,0,255,255);static Lime=new m(192,255,0,255);static White=new m(255,255,255,255);static Black=new m(0,0,0,255);static Transparent=new m(0,0,0,0);static TRANSPARENT=new m(0,0,0,0)}const E=6;class ft{matrixCount=0;buffer;data;temporary=-1;constructor(t=10){this.buffer=new C(M.Float32),this.buffer.resize(t*E),this.data=this.buffer.getArray(),this.reset()}alloc(){const t=this.allocDirty();return this.identity(t),t}allocDirty(){return this.buffer.resize(E)&&(this.data=this.buffer.getArray()),this.buffer.usedElemNum+=E,this.matrixCount++}reset(){this.matrixCount=0,this.buffer.usedElemNum=0,this.temporary=this.alloc()}identity(t){const e=t*E,r=this.data;r[e]=1,r[e+1]=0,r[e+2]=0,r[e+3]=1,r[e+4]=0,r[e+5]=0}translate(t,e,r){const i=t*E,s=this.data;s[i+4]=s[i]*e+s[i+2]*r+s[i+4],s[i+5]=s[i+1]*e+s[i+3]*r+s[i+5]}scale(t,e,r){const i=t*E,s=this.data;s[i]*=e,s[i+1]*=e,s[i+2]*=r,s[i+3]*=r}rotate(t,e){const r=t*E,i=this.data,s=Math.cos(e),a=Math.sin(e),o=i[r],h=i[r+1],c=i[r+2],u=i[r+3];i[r]=o*s+c*a,i[r+1]=h*s+u*a,i[r+2]=o*-a+c*s,i[r+3]=h*-a+u*s}rotateWithOffset(t,e,r,i){this.translate(t,r,i),this.rotate(t,e),this.translate(t,-r,-i)}copy(t,e){const r=t*E,i=e*E,s=this.data;s[r]=s[i],s[r+1]=s[i+1],s[r+2]=s[i+2],s[r+3]=s[i+3],s[r+4]=s[i+4],s[r+5]=s[i+5]}multiply(t,e){this.multiplyOut(t,t,e)}multiplyOut(t,e,r){const i=t*E,s=e*E,a=r*E,o=this.data,h=o[s],c=o[s+1],u=o[s+2],l=o[s+3],d=o[s+4],f=o[s+5],x=o[a],v=o[a+1],y=o[a+2],T=o[a+3],w=o[a+4],b=o[a+5];o[i]=h*x+u*v,o[i+1]=c*x+l*v,o[i+2]=h*y+u*T,o[i+3]=c*y+l*T,o[i+4]=h*w+u*b+d,o[i+5]=c*w+l*b+f}invert(t){const e=t*E,r=this.data,i=r[e],s=r[e+1],a=r[e+2],o=r[e+3],h=r[e+4],c=r[e+5];let u=i*o-s*a;if(!u){this.identity(t);return}u=1/u,r[e]=o*u,r[e+1]=-s*u,r[e+2]=-a*u,r[e+3]=i*u,r[e+4]=(a*c-o*h)*u,r[e+5]=(s*h-i*c)*u}transformPoint(t,e,r){const i=t*E,s=this.data;return{x:e*s[i]+r*s[i+2]+s[i+4],y:e*s[i+1]+r*s[i+3]+s[i+5]}}worldToLocal(t,e,r){const i=this.allocDirty();this.copy(i,t),this.invert(i);const s=this.transformPoint(i,e,r);return this.matrixCount--,this.buffer.usedElemNum-=E,s}localToWorld(t,e,r){return this.transformPoint(t,e,r)}getPosition(t){const e=t*E,r=this.data;return{x:r[e+4],y:r[e+5]}}getScale(t){const e=t*E,r=this.data,i=Math.sqrt(r[e]*r[e]+r[e+1]*r[e+1]),s=Math.sqrt(r[e+2]*r[e+2]+r[e+3]*r[e+3]);return{x:i,y:s}}getRotation(t){const e=t*E,r=this.data;return Math.atan2(r[e+1],r[e])}toCSSMatrix(t,e=1,r=1){const i=t*E,s=this.data;return`matrix(${s[i]*e}, ${s[i+1]*r}, ${s[i+2]*e}, ${s[i+3]*r}, ${s[i+4]*e}, ${s[i+5]*r})`}getMatrix(t){const e=t*E;return this.data.slice(e,e+E)}getMatrixRef(t){const e=t*E;return this.data.subarray(e,e+E)}setMatrix(t,e){const r=t*E,i=this.data;i[r]=e[0],i[r+1]=e[1],i[r+2]=e[2],i[r+3]=e[3],i[r+4]=e[4],i[r+5]=e[5]}multiplyAffineInPlace(t,e,r,i,s,a,o){const h=t*6,c=this.data,u=c[h],l=c[h+1],d=c[h+2],f=c[h+3],x=c[h+4],v=c[h+5];c[h]=u*e+d*r,c[h+1]=l*e+f*r,c[h+2]=u*i+d*s,c[h+3]=l*i+f*s,c[h+4]=u*a+d*o+x,c[h+5]=l*a+f*o+v}multiplyAffine(t,e,r,i,s,a,o,h){const c=t*6,u=e*6,l=this.data,d=l[c],f=l[c+1],x=l[c+2],v=l[c+3],y=l[c+4],T=l[c+5];l[u]=d*r+x*i,l[u+1]=f*r+v*i,l[u+2]=d*s+x*a,l[u+3]=f*s+v*a,l[u+4]=d*o+x*h+y,l[u+5]=f*o+v*h+T}}class mt{matrix=new ft;step=0;stack=new C(M.Uint32);stepWorldM=new C(M.Uint32);stepAction=new C(M.Uint32);stepParentM=new C(M.Uint32);parentStack=new C(M.Uint32);curLocalM=-1;curWorldM=-1;rapid;constructor(t){this.reset(),this.rapid=t}save(){this.stack.push(this.curWorldM);const t=this.curWorldM;return this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.allocDirty(),this.stepWorldM.push(this.curWorldM),this.stepParentM.push(t),this.stepAction.push(1),this.matrix.copy(this.curWorldM,t),{world:this.curWorldM,local:this.curLocalM,step:this.step++}}restore(){this.stack.length!=0&&(this.curWorldM=this.stack.pop(),this.curLocalM=this.curWorldM-1,this.stepParentM.push(this.stack.get(this.stack.length-1)),this.stepWorldM.push(this.curWorldM),this.stepAction.push(0),this.step++)}updateMatrix(t){const e=typeof t=="number"?t:t.step;let r=0,i=e;for(;i<this.step;){if(this.stepAction.get(i)===1){const a=this.stepWorldM.get(i),o=a-1,h=this.stepParentM.get(i);this.matrix.multiplyOut(a,h,o),r++}else if(r--,r===0)break;i++}}translate(t,e){this.matrix.translate(this.curLocalM,t,e),this.matrix.translate(this.curWorldM,t,e)}scale(t,e=t){this.matrix.scale(this.curLocalM,t,e),this.matrix.scale(this.curWorldM,t,e)}rotate(t){this.matrix.rotate(this.curLocalM,t),this.matrix.rotate(this.curWorldM,t)}rotateWithOffset(t,e,r){this.matrix.rotateWithOffset(this.curLocalM,t,e,r),this.matrix.rotateWithOffset(this.curWorldM,t,e,r)}identity(){this.matrix.identity(this.curLocalM),this.matrix.identity(this.curWorldM)}reset(){this.matrix.reset(),this.stack.reset(),this.stepAction.reset(),this.stepWorldM.reset(),this.stepParentM.reset(),this.step=0,this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.alloc()}localToWorld(t,e){return this.matrix.localToWorld(this.curWorldM,t,e)}worldToLocal(t,e){return this.matrix.worldToLocal(this.curWorldM,t,e)}getGlobalPosition(){return this.matrix.getPosition(this.curWorldM)}getGlobalScale(){return this.matrix.getScale(this.curWorldM)}getGlobalRotation(){return this.matrix.getRotation(this.curWorldM)}toCSSMatrix(){return this.matrix.toCSSMatrix(this.curWorldM)}getTransform(){const t=this.curWorldM*E;return this.matrix.data.slice(t,t+E)}setTransform(t){const e=this.curWorldM*E,r=this.matrix.data;r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2],r[e+3]=t[3],r[e+4]=t[4],r[e+5]=t[5]}transformPoint(t,e){return this.matrix.transformPoint(this.curLocalM,t,e)}applyTransform(t,e=0,r=0,i=-1){let s=t.x??0,a=t.y??0;t.position&&(s+=t.position.x,a+=t.position.y);let o=1,h=1;const c=t.scale;c&&(typeof c=="number"?(o=c,h=c):(o=c.x,h=c.y));const u=t.rotation??0;let l=t.offsetX??0,d=t.offsetY??0;t.offset&&(l+=t.offset.x,d+=t.offset.y);const f=t.origin;f!==void 0&&(typeof f=="number"?(l-=f*e,d-=f*r):(l-=f.x*e,d-=f.y*r));const x=u?Math.cos(u):1,v=u?Math.sin(u):0,y=x*o,T=v*o,w=-v*h,b=x*h,N=s+y*l+w*d,_=a+T*l+b*d;if(i!==-1){this.matrix.multiplyAffine(this.curWorldM,i,y,T,w,b,N,_);return}this.matrix.multiplyAffineInPlace(this.curLocalM,y,T,w,b,N,_),this.matrix.multiplyAffineInPlace(this.curWorldM,y,T,w,b,N,_)}}var $=(n=>(n[n.REPEAT=0]="REPEAT",n[n.CLAMP=1]="CLAMP",n[n.MIRRORED_REPEAT=2]="MIRRORED_REPEAT",n))($||{});class xt{render;cache=new Map;constructor(t){this.render=t}async load(t,e){let r=this.cache.get(t);if(r)return new O(r);try{const i=await this._fetchImage(t);return r=G.fromSource(this.render,i,e),r.uid=t,this.cache.set(t,r),new O(r)}catch(i){throw console.error(`[TextureManager] Failed to load: ${t}`,i),i}}create(t,e){if(e?.key&&this.cache.has(e.key))return new O(this.cache.get(e.key));const r=G.fromSource(this.render,t,e);return e?.key&&(r.uid=e.key,this.cache.set(e.key,r)),new O(r)}createRenderTexture(t){return new pt(this.render,t)}createTextTexture(t){return new gt(this.render,t)}destroy(t,e=!1){let r,i;typeof t=="string"?(i=t,r=this.cache.get(i)):t instanceof O?(r=t.base,i=r?.uid,t.destroy()):(r=t,i=r.uid),r&&(r.refCount<=0||e)&&(r.destroy(this.render.gl),i&&this.cache.delete(i))}destroyAll(){for(const t of this.cache.values())t.destroy(this.render.gl);this.cache.clear()}_fetchImage(t){return new Promise((e,r)=>{const i=new Image;i.crossOrigin="anonymous",i.onload=()=>e(i),i.onerror=()=>r(new Error(`Failed to load image resource: ${t}`)),i.src=t})}}class G{glTexture=null;width;height;uid;refCount=0;constructor(t,e,r){this.glTexture=t,this.width=e,this.height=r}static fromSource(t,e,r={}){const i=tt(t,e,r);return new G(i,e.width,e.height)}updateSource(t,e,r={}){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),r.textureFilter!==void 0&&nt(t,r.textureFilter),r.wrap!==void 0&&st(t,r.wrap),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.pixelStorei(t.UNPACK_ALIGNMENT,1),r.premultipliedAlpha!==void 0&&t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r.premultipliedAlpha),this.width===e.width&&this.height===e.height?t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,e):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),this.width=e.width,this.height=e.height),r.premultipliedAlpha!==void 0&&t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1))}setFilterMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),nt(t,e),t.bindTexture(t.TEXTURE_2D,null))}setWrapMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),st(t,e),t.bindTexture(t.TEXTURE_2D,null))}destroy(t){this.glTexture&&(t.deleteTexture(this.glTexture),this.glTexture=null)}}class O{base;uvX=0;uvY=0;uvW=1;uvH=1;rawWidth=0;rawHeight=0;offsetX=0;offsetY=0;scale=1;isAtlas=!1;flipY=!1;isRotated=!1;glTexture=null;get width(){return(this.isRotated?this.rawHeight:this.rawWidth)*this.scale}get height(){return(this.isRotated?this.rawWidth:this.rawHeight)*this.scale}_px=0;_py=0;_pw=0;_ph=0;constructor(t){t&&this.setBase(t)}setBase(t){return this.base===t?this:(this.base&&this.base.refCount--,this.base=t,this.base.refCount++,this.setRegion(0,0,t.width,t.height),this.glTexture=t.glTexture,this)}setRegion(t,e,r,i){return this.base?(this._px=t,this._py=e,this._pw=r,this._ph=i,this.isAtlas=t!==0||e!==0||r!==this.base.width||i!==this.base.height,this.uvX=t/this.base.width,this.uvY=e/this.base.height,this.uvW=this.uvX+r/this.base.width,this.uvH=this.uvY+i/this.base.height,this.rawWidth=r*this.scale,this.rawHeight=i*this.scale,this):this}getSubTexture(t,e,r,i){if(!this.base)return new O;const s=this.clone(),a=this._px,o=this._py;return s.setRegion(a+t,o+e,r,i),s}clone(t){const e=t??new O(this.base);return t&&this.base&&t.setBase(this.base),e.scale=this.scale,e.uvX=this.uvX,e.uvY=this.uvY,e.uvW=this.uvW,e.uvH=this.uvH,e.rawWidth=this.rawWidth,e.rawHeight=this.rawHeight,e.offsetX=this.offsetX,e.offsetY=this.offsetY,e.flipY=this.flipY,e.isRotated=this.isRotated,e.isAtlas=this.isAtlas,e._px=this._px,e._py=this._py,e._pw=this._pw,e._ph=this._ph,e}splitGrid(t,e,r,i,s=0){if(!this.base)return[];const a=[],o=this.rawWidth,h=this.rawHeight,c=Math.max(0,s),u=t+c,l=e+c,d=r??Math.floor((o+c)/u),f=i??Math.floor((h+c)/l);for(let x=0;x<f;x++)for(let v=0;v<d;v++)a.push(this.getSubTexture(v*u,x*l,t,e));return a}static fromImageSource(t,e,r={}){const i=tt(t,e,r);return new O(new G(i,e.width,e.height))}destroy(){this.base&&(this.base.refCount--,this.base=void 0),this.glTexture=null}}class pt extends O{framebuffer;renderbuffer;gl;flipY=!0;clearColor;_allocW=0;_allocH=0;constructor(t,e){super(),this.gl=t.gl,this.clearColor=e.clearColor??m.Black;const r=Math.max(Math.round(e.width),1),i=Math.max(Math.round(e.height),1),a=tt(t,{width:r,height:i},{...e,onlySize:!0});if(this.setBase(new G(a,r,i)),this.framebuffer=this.gl.createFramebuffer(),this.renderbuffer=this.gl.createRenderbuffer(),!this.framebuffer||!this.renderbuffer)throw new Error("Failed to create Framebuffer or Renderbuffer");this.resize(r,i,!0)}resize(t,e,r=!1){t=Math.max(Math.round(t),1),e=Math.max(Math.round(e),1);const i=this.rawWidth===t&&this.rawHeight===e;if(!r&&i)return;const s=this.gl;(r||t>this._allocW||e>this._allocH)&&this.base&&(this._allocW=Math.max(this._allocW,t),this._allocH=Math.max(this._allocH,e),this.base.width=this._allocW,this.base.height=this._allocH,s.bindTexture(s.TEXTURE_2D,this.base.glTexture),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this._allocW,this._allocH,0,s.RGBA,s.UNSIGNED_BYTE,null),s.bindRenderbuffer(s.RENDERBUFFER,this.renderbuffer),s.renderbufferStorage(s.RENDERBUFFER,s.STENCIL_INDEX8,this._allocW,this._allocH),s.bindFramebuffer(s.FRAMEBUFFER,this.framebuffer),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.base.glTexture,0),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.STENCIL_ATTACHMENT,s.RENDERBUFFER,this.renderbuffer),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindRenderbuffer(s.RENDERBUFFER,null),s.bindTexture(s.TEXTURE_2D,null)),this.rawWidth=t,this.rawHeight=e,this.uvX=0,this.uvW=t/this._allocW,this.uvY=0,this.uvH=e/this._allocH}activate(t=!1){if(!this.framebuffer)return;const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),e.viewport(0,0,this.rawWidth,this.rawHeight),t&&this.clear()}clear(t){if(!this.framebuffer)return;const e=this.gl,r=t??this.clearColor;r&&(r.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT|e.STENCIL_BUFFER_BIT))}deactivate(){const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,null)}GetPixels(t=0,e=0,r=this.rawWidth,i=this.rawHeight){if(!this.framebuffer)return new Uint8Array(0);const s=Math.floor(t),a=Math.floor(e),o=Math.floor(r),h=Math.floor(i);if(o<=0||h<=0)return new Uint8Array(0);if(s<0||a<0||s>=this.rawWidth||a>=this.rawHeight)return new Uint8Array(0);const c=Math.min(o,this.rawWidth-s),u=Math.min(h,this.rawHeight-a),l=this.rawHeight-a-u,d=this.gl,f=d.getParameter(d.FRAMEBUFFER_BINDING);d.bindFramebuffer(d.FRAMEBUFFER,this.framebuffer);const x=new Uint8Array(c*u*4);return d.readPixels(s,l,c,u,d.RGBA,d.UNSIGNED_BYTE,x),d.bindFramebuffer(d.FRAMEBUFFER,f),x}GetColorAt(t,e){const r=this.GetPixels(t,e,1,1);return r.length<4?new m(0,0,0,0):new m(r[0],r[1],r[2],r[3])}destroy(){super.destroy(),this.framebuffer&&this.gl.deleteFramebuffer(this.framebuffer),this.renderbuffer&&this.gl.deleteRenderbuffer(this.renderbuffer),this.base?.destroy(this.gl)}}const Xt={fontFamily:"Arial",fontSize:24,fontWeight:"normal",fill:"#000000",strokeThickness:0,align:"left",lineHeight:1};class gt extends O{canvas;ctx;render;_text;_style;options;flipY=!0;constructor(t,e){super(),this.render=t,this._style={...Xt,...e},this._text=e?.text??"",this.options={premultipliedAlpha:t.premultipliedAlpha,...e},this.scale=1/t.dpr,this.canvas=document.createElement("canvas");const r=this.canvas.getContext("2d",{willReadFrequently:!0});if(!r)throw new Error("Failed to get 2d context for TextTexture");this.ctx=r,this.canvas.width=1,this.canvas.height=1;const i=tt(t,this.canvas,this.options);this.setBase(new G(i,1,1)),this.update()}get text(){return this._text}set text(t){this._text!==t&&(this._text=t,this.update())}get style(){return this._style}set style(t){this._style={...this._style,...t},this.update()}updateOffset(t,e){switch(this._style.align){case"center":return t/2;case"right":return t;default:return e}}update(){const t=this.ctx,e=this.style,r=e.fontSize,i=e.fontWeight,s=e.fontFamily,a=e.lineHeight,o=`${i} ${r}px ${s}`,h=this.render.dpr;t.font=o,t.textBaseline="top";const c=this._text.split(`
2
- `);let u=0,l=0;const d=t.measureText(c[0]||"M"),f=(d.fontBoundingBoxAscent||r)+(d.fontBoundingBoxDescent||r*.2);for(const k of c){const L=t.measureText(k);L.width>u&&(u=L.width),l+=f*a}l-=f*(a-1);const x=this._style.strokeThickness||0,v=Math.ceil(u+x*2)||1,y=Math.ceil(l+x*2)||1,T=Math.ceil(v*h),w=Math.ceil(y*h);(this.canvas.width!==T||this.canvas.height!==w)&&(this.canvas.width=T,this.canvas.height=w),t.setTransform(h,0,0,h,0,0),t.clearRect(0,0,v,y),t.font=o,t.textBaseline="top",t.textAlign=this._style.align;const b=this.updateOffset(v,x),N=e.strokeThickness,_=N>0;_&&(t.lineWidth=N,t.strokeStyle=e.stroke,t.lineJoin="round"),e.fill&&(t.fillStyle=e.fill);let D=x;for(const k of c)_&&t.strokeText(k,b,D),e.fill&&t.fillText(k,b,D),D+=f*a;this.base?.updateSource(this.render.gl,this.canvas,this.options),this.setRegion(0,0,T,w)}}const jt=(n,t=!1,e=!0)=>{const r=n.getContext("webgl2",{stencil:!0,antialias:t,premultipliedAlpha:e});if(!r)throw new Error("WebGL2 is not supported in this browser.");return r},vt=(n,t,e)=>{const r=n.createShader(e);if(!r)throw new Error("Unable to create webgl shader");if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS)){const s=n.getShaderInfoLog(r);throw console.error("Shader compilation failed:",s),new Error("Unable to compile shader: "+s+t)}return r},$t=(n,t,e)=>{var r=n.createProgram(),i=vt(n,t,35633),s=vt(n,e,35632);if(!r)throw new Error("Unable to create program shader");if(n.attachShader(r,i),n.attachShader(r,s),n.linkProgram(r),!n.getProgramParameter(r,n.LINK_STATUS)){const o=n.getProgramInfoLog(r);throw new Error("Unable to link shader program: "+o)}return r};function st(n,t){const e={[$.CLAMP]:n.CLAMP_TO_EDGE,[$.REPEAT]:n.REPEAT,[$.MIRRORED_REPEAT]:n.MIRRORED_REPEAT}[t]||n.CLAMP_TO_EDGE;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,e)}function nt(n,t){const e={[it.LINEAR]:n.LINEAR,[it.NEAREST]:n.NEAREST}[t]??n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,e)}function tt(n,t,e){const r=n.gl,i=r.createTexture();if(!i)throw new Error("Unable to create WebGL texture");if(r.bindTexture(r.TEXTURE_2D,i),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,0),r.pixelStorei(r.UNPACK_ALIGNMENT,1),st(r,e.wrap??$.CLAMP),nt(r,e.textureFilter??n.textureFilter),e.onlySize){const s=t;r.texImage2D(r.TEXTURE_2D,0,r.RGBA,s.width,s.height,0,r.RGBA,r.UNSIGNED_BYTE,null)}else{const s=e.premultipliedAlpha??n.premultipliedAlpha;s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)}return r.bindTexture(r.TEXTURE_2D,null),i}function H(n,t){if(n.includes("%TEXTURE_NUM%")&&(n=n.replace("%TEXTURE_NUM%",t.toString())),n.includes("%GET_COLOR%")){let e="";for(let r=0;r<t;r++)r==0?e+=`if(vTextureId == ${r})`:r==t-1?e+="else":e+=`else if(vTextureId == ${r})`,e+=`{return texture(uTextures[${r}], uv);}`;n=n.replace("%GET_COLOR%",e)}return n}const Kt=5126,at=5121;function qt(n,t,e){n.vertexAttribDivisor(t,e)}function yt(n,t,e,r,i){n.drawArraysInstanced(t,e,r,i)}let Qt=0;class ht{program;attributeLoc={};uniformLoc={};isCustom=!1;padding=0;uniformType={};uniformIsArray={};gl;shaderId=Qt++;vao;constructor(t,e,r,i){this.gl=t,this.program=$t(t,e,r),this.parseShader(e),this.parseShader(r),this.vao=t.createVertexArray(),i&&this.setAttributes(i)}use(){this.gl.useProgram(this.program)}bindVAO(){this.gl.bindVertexArray(this.vao)}unbindVAO(){this.gl.bindVertexArray(null)}setUniform(t,e){const r=this.uniformLoc[t];if(r===void 0)return;const i=this.uniformType[t],s=this.uniformIsArray[t];Zt(this.gl,r,i,e,s)}setUniforms(t){for(const e in t)this.setUniform(e,t[e])}setAttribute(t){const e=this.attributeLoc[t.name];if(e===void 0)return;const r=this.gl;r.vertexAttribPointer(e,t.size,t.type??Kt,t.normalized??!1,t.stride,t.offset??0),r.enableVertexAttribArray(e),qt(r,e,t.divisor??0)}setAttributes(t){for(const e of t)this.setAttribute(e)}destroy(){this.gl.deleteProgram(this.program)}parseShader(t){const e=this.gl,r=t.match(/(?:in|attribute)\s+\w+\s+\w+/g);if(r)for(const s of r){const o=s.split(/\s+/)[2],h=e.getAttribLocation(this.program,o);h!==-1&&(this.attributeLoc[o]=h)}const i=t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);if(i)for(const s of i){const a=s.split(/\s+/),o=a[1],h=a[2].replace(/\[\d+\]$/,""),c=e.getUniformLocation(this.program,h);c!==null&&(this.uniformLoc[h]=c,this.uniformType[h]=o,this.uniformIsArray[h]=/\[\d+\]$/.test(a[2]))}}}function Zt(n,t,e,r,i=!1){switch(e){case"float":return n.uniform1f(t,r);case"int":case"bool":case"sampler2D":case"samplerCube":return i?n.uniform1iv(t,r):n.uniform1i(t,r);case"vec2":return n.uniform2fv(t,r);case"vec3":return n.uniform3fv(t,r);case"vec4":return n.uniform4fv(t,r);case"ivec2":case"bvec2":return n.uniform2iv(t,r);case"ivec3":case"bvec3":return n.uniform3iv(t,r);case"ivec4":case"bvec4":return n.uniform4iv(t,r);case"mat2":return n.uniformMatrix2fv(t,!1,r);case"mat3":return n.uniformMatrix3fv(t,!1,r);case"mat4":return n.uniformMatrix4fv(t,!1,r);default:return Jt(n,t,r)}}function Jt(n,t,e){if(typeof e=="number")return n.uniform1f(t,e);const r=e;switch(r.length){case 2:return n.uniform2fv(t,r);case 3:return n.uniform3fv(t,r);case 4:return n.uniform4fv(t,r);case 9:return n.uniformMatrix3fv(t,!1,r);case 16:return n.uniformMatrix4fv(t,!1,r);default:return n.uniform1fv(t,r)}}class ot{vs;fs;glshader=new Map;uniforms={};uniformDirty=new Set;uniformTextures={};usedTextureUnitNum=0;padding=0;rapid;constructor(t,e,r,i=0,s){this.vs=e,this.fs=r,this.rapid=t,this.uniforms=s??{},this.usedTextureUnitNum=i}setUniforms(t){this.rapid.flush();const e={},r={};for(const[i,s]of Object.entries(t))s instanceof WebGLTexture?r[i]=s:e[i]=s;Object.assign(this.uniforms,e),Object.assign(this.uniformTextures,r);for(const i of this.glshader.keys())this.uniformDirty.add(i)}setPadding(t){this.padding=t;for(const e of this.glshader.values())e.padding=t;return this}applyUniform(t,e){const r=this.glshader.get(t);r&&(Object.keys(e).length>0&&r.setUniforms(e),this.uniformDirty.has(t)&&(r.setUniforms(this.uniforms),this.uniformDirty.delete(t)))}getGLShader(t,e,r,i){if(this.glshader.has(e))return this.glshader.get(e);if(i==null||r==null)return console.warn("CustomGlShader: missing base shader for "+e),null;r=r.replace("// CUSTOM_CODE_CALL","vertex(position, vRegion);"),i=i.replace("// CUSTOM_CODE_CALL","fragment(fragColor);"),r=r.replace("// CUSTOM_CODE",this.vs),i=i.replace("// CUSTOM_CODE",this.fs);const s=t.createShader(r,i);return s.isCustom=!0,s.padding=this.padding,this.glshader.set(e,s),this.uniformDirty.add(e),s}destroy(){this.glshader.forEach(t=>t.destroy())}}class ct{constructor(t){this.rapid=t,this.gl=t.gl,this.maxTextureUnits=t.maxTextureUnits,this.matrixStore=t.matrix}defaultShader;currentShader;customShader=null;customShaderUsedTextureNum=0;gl;maxTextureUnits;matrixStore;isDefaultShader=!0;KEY="default";vs="";fs="";usedTextures=[];usedTexturePadding=[];createBuffer(){}createDefaultShader(){}get freeTextureUnitNum(){return this.maxTextureUnits-this.usedTextures.length-this.customShaderUsedTextureNum}getTextureUnitList(){return Array.from({length:this.maxTextureUnits},(t,e)=>e)}findTextureUnit(t,e=0,r=0){for(let i=0;i<this.usedTextures.length;i++){const s=i*2;if(this.usedTextures[i]===t&&this.usedTexturePadding[s]===e&&this.usedTexturePadding[s+1]===r)return i}return-1}useTexture(t,e=0,r=0){const i=this.findTextureUnit(t,e,r);return i==-1?(this.freeTextureUnitNum===0&&this.flush(),this.usedTextures.push(t),this.usedTexturePadding.push(e),this.usedTexturePadding.push(r),this.usedTextures.length-1):i}createShader(t,e){return new ht(this.gl,t,e)}createCustomShader(t){return t.getGLShader(this,this.KEY,this.vs,this.fs)}getCustomShader(t){if(!t)return this.defaultShader;if(t instanceof ot){const e=this.createCustomShader(t);return e??this.defaultShader}return t}isSameShader(t){return this.isDefaultShader&&!t?!0:this.getCustomShader(t)==this.currentShader}enter(t){this.resetRender(),this.currentShader=this.getCustomShader(t),t instanceof ot?(this.customShader=t,this.customShaderUsedTextureNum=t.usedTextureUnitNum):(this.customShader=null,this.customShaderUsedTextureNum=0),this.isDefaultShader=this.currentShader==this.defaultShader,this.currentShader.use(),this.currentShader.setUniform("u_projection",this.rapid.projection)}exit(){this.hasPendingContent()&&this.flush(),this.gl.bindVertexArray(null)}flush(){this.render(),this.resetRender()}render(){this.prepareRender()}prepareRender(){const t=this.currentShader;if(t.use(),this.customShader){const r=this.customShader,i={};for(const s in r.uniformTextures)i[s]=this.useTexture(r.uniformTextures[s]);this.customShader.applyUniform(this.KEY,i)}const e=this.gl;for(let r=0;r<this.usedTextures.length;r++)e.activeTexture(e.TEXTURE0+r),e.bindTexture(e.TEXTURE_2D,this.usedTextures[r]);t.setUniform("uTextures",Int32Array.from({length:this.usedTextures.length},(r,i)=>i)),t.setUniform("uPadding",Float32Array.from({length:this.usedTexturePadding.length},(r,i)=>this.usedTexturePadding[i]))}resetRender(){this.usedTextures.length=0,this.usedTexturePadding.length=0}hasPendingContent(){return!1}}const et=`#version 300 es\r
1
+ (function(g,w){typeof exports=="object"&&typeof module<"u"?w(exports):typeof define=="function"&&define.amd?define(["exports"],w):(g=typeof globalThis<"u"?globalThis:g||self,w(g.RapidRender={}))})(this,(function(g){"use strict";var w=(n=>(n[n.Float32=0]="Float32",n[n.Uint32=1]="Uint32",n[n.Uint16=2]="Uint16",n))(w||{});class C{usedElemNum;typedArray;arrayType;maxElemNum;bytePerElem;arraybuffer;uint32;float32;uint16;constructor(t){this.usedElemNum=0,this.maxElemNum=512,this.bytePerElem=this.getArrayType(t).BYTES_PER_ELEMENT,this.arrayType=t,this.arraybuffer=new ArrayBuffer(this.maxElemNum*this.bytePerElem),this.updateTypedArray()}getArrayType(t){switch(t){case 0:return Float32Array;case 1:return Uint32Array;case 2:return Uint16Array;default:throw new Error("Unsupported ArrayType")}}updateTypedArray(){switch(this.uint32=new Uint32Array(this.arraybuffer),this.float32=new Float32Array(this.arraybuffer),this.uint16=new Uint16Array(this.arraybuffer),this.arrayType){case 0:this.typedArray=this.float32;break;case 1:this.typedArray=this.uint32;break;case 2:this.typedArray=this.uint16;break}}clear(){this.usedElemNum=0}static removeAtIndices(t,e){const r=Math.max(...e.map(o=>o.usedElemNum)),i=[...new Set(t)].filter(o=>o>=0&&o<r).sort((o,h)=>o-h);if(i.length===0)return 0;let s=0,a=0;for(let o=0;o<r;o++){if(a<i.length&&o===i[a]){a++;continue}if(s!==o)for(const h of e)h.typedArray[s]=h.typedArray[o];s++}for(const o of e)o.usedElemNum=s;return r-s}resize(t=0){if(t+=this.usedElemNum,t>this.maxElemNum){for(;t>this.maxElemNum;)this.maxElemNum*=2;return this.setMaxSize(this.maxElemNum),!0}return!1}setMaxSize(t=this.maxElemNum){const e=this.typedArray;this.maxElemNum=t,this.arraybuffer=new ArrayBuffer(t*this.bytePerElem),this.updateTypedArray(),this.typedArray.set(e)}pushUint32(t){this.resize(1),this.uint32[this.usedElemNum++]=t}pushFloat32(t){this.resize(1),this.float32[this.usedElemNum++]=t}push(t){this.resize(1),this.typedArray[this.usedElemNum++]=t}pop(){return this.typedArray[--this.usedElemNum]}top(){return this.typedArray[this.usedElemNum-1]}get(t){return this.typedArray[t]}getArray(t=0,e){return e===void 0?this.typedArray:this.typedArray.subarray(t,e)}get length(){return this.usedElemNum}reset(){this.usedElemNum=0}}class tt extends C{buffer;gl;dirty=!0;type;webglBufferSize=0;usage;constructor(t,e,r=t.ARRAY_BUFFER,i=t.DYNAMIC_DRAW){super(e),this.gl=t,this.buffer=t.createBuffer(),this.type=r,this.usage=i}makeDirty(){this.dirty=!0}clear(){super.clear(),this.dirty=!1}bindBuffer(){this.gl.bindBuffer(this.type,this.buffer)}bufferData(){if(this.dirty){const t=this.gl;this.maxElemNum>this.webglBufferSize&&(t.bufferData(this.type,this.maxElemNum*this.bytePerElem,this.usage),this.webglBufferSize=this.maxElemNum),t.bufferSubData(this.type,0,this.getArray(0,this.usedElemNum)),this.dirty=!1}}}class m{_r;_g;_b;_a;uint32;premultipliedUint32;static clampByte(t){return t<=0?0:t>=255?255:Math.round(t)}constructor(t,e,r,i=255){this._r=t,this._g=e,this._b=r,this._a=i,this.updateUint()}setClearColor(t){t.clearColor(this.r/255,this.g/255,this.b/255,this.a/255)}get r(){return this._r}set r(t){this._r=t,this.updateUint()}get g(){return this._g}set g(t){this._g=t,this.updateUint()}get b(){return this._b}set b(t){this._b=t,this.updateUint()}get a(){return this._a}set a(t){this._a=t,this.updateUint()}updateUint(){this.uint32=(this._a<<24|this._b<<16|this._g<<8|this._r)>>>0;const t=m.clampByte(this._a),e=m.clampByte(this._r*t/255),r=m.clampByte(this._g*t/255),i=m.clampByte(this._b*t/255);this.premultipliedUint32=(t<<24|i<<16|r<<8|e)>>>0}reset(){this._r=0,this._g=0,this._b=0,this._a=255,this.updateUint()}setRGBA(t,e,r,i){this.r=t,this.g=e,this.b=r,this.a=i,this.updateUint()}setHSL(t,e,r){t=(t%360+360)%360,e=Math.max(0,Math.min(100,e))/100,r=Math.max(0,Math.min(100,r))/100;const i=(1-Math.abs(2*r-1))*e,s=i*(1-Math.abs(t/60%2-1)),a=r-i/2;let o=0,h=0,c=0;return t<60?[o,h,c]=[i,s,0]:t<120?[o,h,c]=[s,i,0]:t<180?[o,h,c]=[0,i,s]:t<240?[o,h,c]=[0,s,i]:t<300?[o,h,c]=[s,0,i]:[o,h,c]=[i,0,s],this.setRGBA((o+a)*255,(h+a)*255,(c+a)*255,255),this}toHex(){const t=e=>Math.max(0,Math.min(255,Math.round(e))).toString(16).padStart(2,"0");return`#${t(this._r)}${t(this._g)}${t(this._b)}${t(this._a)}`}copy(t){this.setRGBA(t.r,t.g,t.b,t.a)}clone(){return new m(this._r,this._g,this._b,this._a)}toHexString(t=!0){const e=this.r.toString(16).padStart(2,"0"),r=this.g.toString(16).padStart(2,"0"),i=this.b.toString(16).padStart(2,"0"),s=this.a.toString(16).padStart(2,"0");return`#${e}${r}${i}${t?s:""}`}equal(t){return t.r===this.r&&t.g===this.g&&t.b===this.b&&t.a===this.a}equals(t){return this.equal(t)}static FromHSL(t,e,r){return new m(0,0,0).setHSL(t,e,r)}static FromRGB(t,e,r){return new m(t,e,r)}static fromNorm(t,e,r,i=1){return new m(Math.round(t*255),Math.round(e*255),Math.round(r*255),Math.round(i*255))}static clampColorByte(t){return t<=0?0:t>=255?255:Math.round(t)}static packColor(t,e,r,i,s){const a=m.clampColorByte(i),o=s?a/255:1,h=m.clampColorByte(t*o),c=m.clampColorByte(e*o),u=m.clampColorByte(r*o);return(a<<24|u<<16|c<<8|h)>>>0}static fromHex(t){t.startsWith("#")&&(t=t.slice(1));const e=parseInt(t.slice(0,2),16),r=parseInt(t.slice(2,4),16),i=parseInt(t.slice(4,6),16);let s=255;return t.length>=8&&(s=parseInt(t.slice(6,8),16)),new m(e,r,i,s)}add(t){return new m(Math.min(this.r+t.r,255),Math.min(this.g+t.g,255),Math.min(this.b+t.b,255),Math.min(this.a+t.a,255))}subtract(t){return new m(this.r-t.r,this.g-t.g,this.b-t.b,this.a-t.a)}divide(t){return t instanceof m?new m(this.r/t.r,this.g/t.g,this.b/t.b,this.a/t.a):new m(this.r/t,this.g/t,this.b/t,this.a/t)}multiply(t){return t instanceof m?new m(this.r*t.r,this.g*t.g,this.b*t.b,this.a*t.a):new m(this.r*t,this.g*t,this.b*t,this.a*t)}clamp(){this.r=Math.max(0,Math.min(255,this.r)),this.g=Math.max(0,Math.min(255,this.g)),this.b=Math.max(0,Math.min(255,this.b)),this.a=Math.max(0,Math.min(255,this.a))}static Red=new m(255,0,0,255);static Green=new m(0,255,0,255);static Blue=new m(0,0,255,255);static Yellow=new m(255,255,0,255);static Purple=new m(128,0,128,255);static Orange=new m(255,165,0,255);static Pink=new m(255,192,203,255);static Gray=new m(128,128,128,255);static Brown=new m(139,69,19,255);static Cyan=new m(0,255,255,255);static Magenta=new m(255,0,255,255);static Lime=new m(192,255,0,255);static White=new m(255,255,255,255);static Black=new m(0,0,0,255);static Transparent=new m(0,0,0,0);static TRANSPARENT=new m(0,0,0,0)}const E=6;class xt{matrixCount=0;buffer;data;temporary=-1;constructor(t=10){this.buffer=new C(w.Float32),this.buffer.resize(t*E),this.data=this.buffer.getArray(),this.reset()}alloc(){const t=this.allocDirty();return this.identity(t),t}allocDirty(){return this.buffer.resize(E)&&(this.data=this.buffer.getArray()),this.buffer.usedElemNum+=E,this.matrixCount++}reset(){this.matrixCount=0,this.buffer.usedElemNum=0,this.temporary=this.alloc()}identity(t){const e=t*E,r=this.data;r[e]=1,r[e+1]=0,r[e+2]=0,r[e+3]=1,r[e+4]=0,r[e+5]=0}translate(t,e,r){const i=t*E,s=this.data;s[i+4]=s[i]*e+s[i+2]*r+s[i+4],s[i+5]=s[i+1]*e+s[i+3]*r+s[i+5]}scale(t,e,r){const i=t*E,s=this.data;s[i]*=e,s[i+1]*=e,s[i+2]*=r,s[i+3]*=r}rotate(t,e){const r=t*E,i=this.data,s=Math.cos(e),a=Math.sin(e),o=i[r],h=i[r+1],c=i[r+2],u=i[r+3];i[r]=o*s+c*a,i[r+1]=h*s+u*a,i[r+2]=o*-a+c*s,i[r+3]=h*-a+u*s}rotateWithOffset(t,e,r,i){this.translate(t,r,i),this.rotate(t,e),this.translate(t,-r,-i)}copy(t,e){const r=t*E,i=e*E,s=this.data;s[r]=s[i],s[r+1]=s[i+1],s[r+2]=s[i+2],s[r+3]=s[i+3],s[r+4]=s[i+4],s[r+5]=s[i+5]}multiply(t,e){this.multiplyOut(t,t,e)}multiplyOut(t,e,r){const i=t*E,s=e*E,a=r*E,o=this.data,h=o[s],c=o[s+1],u=o[s+2],l=o[s+3],d=o[s+4],f=o[s+5],x=o[a],y=o[a+1],T=o[a+2],R=o[a+3],S=o[a+4],b=o[a+5];o[i]=h*x+u*y,o[i+1]=c*x+l*y,o[i+2]=h*T+u*R,o[i+3]=c*T+l*R,o[i+4]=h*S+u*b+d,o[i+5]=c*S+l*b+f}invert(t){const e=t*E,r=this.data,i=r[e],s=r[e+1],a=r[e+2],o=r[e+3],h=r[e+4],c=r[e+5];let u=i*o-s*a;if(!u){this.identity(t);return}u=1/u,r[e]=o*u,r[e+1]=-s*u,r[e+2]=-a*u,r[e+3]=i*u,r[e+4]=(a*c-o*h)*u,r[e+5]=(s*h-i*c)*u}transformPoint(t,e,r){const i=t*E,s=this.data;return{x:e*s[i]+r*s[i+2]+s[i+4],y:e*s[i+1]+r*s[i+3]+s[i+5]}}worldToLocal(t,e,r){const i=this.allocDirty();this.copy(i,t),this.invert(i);const s=this.transformPoint(i,e,r);return this.matrixCount--,this.buffer.usedElemNum-=E,s}localToWorld(t,e,r){return this.transformPoint(t,e,r)}getPosition(t){const e=t*E,r=this.data;return{x:r[e+4],y:r[e+5]}}getScale(t){const e=t*E,r=this.data,i=Math.sqrt(r[e]*r[e]+r[e+1]*r[e+1]),s=Math.sqrt(r[e+2]*r[e+2]+r[e+3]*r[e+3]);return{x:i,y:s}}getRotation(t){const e=t*E,r=this.data;return Math.atan2(r[e+1],r[e])}toCSSMatrix(t,e=1,r=1){const i=t*E,s=this.data;return`matrix(${s[i]*e}, ${s[i+1]*r}, ${s[i+2]*e}, ${s[i+3]*r}, ${s[i+4]*e}, ${s[i+5]*r})`}getMatrix(t){const e=t*E;return this.data.slice(e,e+E)}getMatrixRef(t){const e=t*E;return this.data.subarray(e,e+E)}setMatrix(t,e){const r=t*E,i=this.data;i[r]=e[0],i[r+1]=e[1],i[r+2]=e[2],i[r+3]=e[3],i[r+4]=e[4],i[r+5]=e[5]}multiplyAffineInPlace(t,e,r,i,s,a,o){const h=t*6,c=this.data,u=c[h],l=c[h+1],d=c[h+2],f=c[h+3],x=c[h+4],y=c[h+5];c[h]=u*e+d*r,c[h+1]=l*e+f*r,c[h+2]=u*i+d*s,c[h+3]=l*i+f*s,c[h+4]=u*a+d*o+x,c[h+5]=l*a+f*o+y}multiplyAffine(t,e,r,i,s,a,o,h){const c=t*6,u=e*6,l=this.data,d=l[c],f=l[c+1],x=l[c+2],y=l[c+3],T=l[c+4],R=l[c+5];l[u]=d*r+x*i,l[u+1]=f*r+y*i,l[u+2]=d*s+x*a,l[u+3]=f*s+y*a,l[u+4]=d*o+x*h+T,l[u+5]=f*o+y*h+R}}class pt{matrix=new xt;step=0;stack=new C(w.Uint32);stepWorldM=new C(w.Uint32);stepAction=new C(w.Uint32);stepParentM=new C(w.Uint32);parentStack=new C(w.Uint32);curLocalM=-1;curWorldM=-1;rapid;constructor(t){this.reset(),this.rapid=t}save(){this.stack.push(this.curWorldM);const t=this.curWorldM;return this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.allocDirty(),this.stepWorldM.push(this.curWorldM),this.stepParentM.push(t),this.stepAction.push(1),this.matrix.copy(this.curWorldM,t),{world:this.curWorldM,local:this.curLocalM,step:this.step++}}restore(){this.stack.length!=0&&(this.curWorldM=this.stack.pop(),this.curLocalM=this.curWorldM-1,this.stepParentM.push(this.stack.get(this.stack.length-1)),this.stepWorldM.push(this.curWorldM),this.stepAction.push(0),this.step++)}updateMatrixSubtree(t){const e=typeof t=="number"?t:t.step;let r=0,i=e;for(;i<this.step;){if(this.stepAction.get(i)===1){const a=this.stepWorldM.get(i),o=a-1,h=this.stepParentM.get(i);this.matrix.multiplyOut(a,h,o),r++}else if(r--,r===0)break;i++}}translate(t,e){this.matrix.translate(this.curLocalM,t,e),this.matrix.translate(this.curWorldM,t,e)}scale(t,e=t){this.matrix.scale(this.curLocalM,t,e),this.matrix.scale(this.curWorldM,t,e)}rotate(t){this.matrix.rotate(this.curLocalM,t),this.matrix.rotate(this.curWorldM,t)}rotateWithOffset(t,e,r){this.matrix.rotateWithOffset(this.curLocalM,t,e,r),this.matrix.rotateWithOffset(this.curWorldM,t,e,r)}identity(){this.matrix.identity(this.curLocalM),this.matrix.identity(this.curWorldM)}reset(){this.matrix.reset(),this.stack.reset(),this.stepAction.reset(),this.stepWorldM.reset(),this.stepParentM.reset(),this.step=0,this.curLocalM=this.matrix.alloc(),this.curWorldM=this.matrix.alloc()}localToWorld(t,e){return this.matrix.localToWorld(this.curWorldM,t,e)}worldToLocal(t,e){return this.matrix.worldToLocal(this.curWorldM,t,e)}getGlobalPosition(){return this.matrix.getPosition(this.curWorldM)}getGlobalScale(){return this.matrix.getScale(this.curWorldM)}getGlobalRotation(){return this.matrix.getRotation(this.curWorldM)}toCSSMatrix(){return this.matrix.toCSSMatrix(this.curWorldM)}getTransform(){const t=this.curWorldM*E;return this.matrix.data.slice(t,t+E)}setTransform(t){const e=this.curWorldM*E,r=this.matrix.data;r[e]=t[0],r[e+1]=t[1],r[e+2]=t[2],r[e+3]=t[3],r[e+4]=t[4],r[e+5]=t[5]}transformPoint(t,e){return this.matrix.transformPoint(this.curLocalM,t,e)}applyTransform(t,e=0,r=0,i=-1){let s=t.x??0,a=t.y??0;t.position&&(s+=t.position.x,a+=t.position.y);let o=1,h=1;const c=t.scale;c&&(typeof c=="number"?(o=c,h=c):(o=c.x,h=c.y));const u=t.rotation??0;let l=t.offsetX??0,d=t.offsetY??0;t.offset&&(l+=t.offset.x,d+=t.offset.y);const f=t.origin;f!==void 0&&(typeof f=="number"?(l-=f*e,d-=f*r):(l-=f.x*e,d-=f.y*r));const x=u?Math.cos(u):1,y=u?Math.sin(u):0,T=x*o,R=y*o,S=-y*h,b=x*h,N=s+T*l+S*d,P=a+R*l+b*d;if(i!==-1){this.matrix.multiplyAffine(this.curWorldM,i,T,R,S,b,N,P);return}this.matrix.multiplyAffineInPlace(this.curLocalM,T,R,S,b,N,P),this.matrix.multiplyAffineInPlace(this.curWorldM,T,R,S,b,N,P)}}var j=(n=>(n[n.REPEAT=0]="REPEAT",n[n.CLAMP=1]="CLAMP",n[n.MIRRORED_REPEAT=2]="MIRRORED_REPEAT",n))(j||{});class gt{render;cache=new Map;constructor(t){this.render=t}async load(t,e){let r=this.cache.get(t);if(r)return new I(r);try{const i=await this._fetchImage(t);return r=Y.fromSource(this.render,i,e),r.uid=t,this.cache.set(t,r),new I(r)}catch(i){throw console.error(`[TextureManager] Failed to load: ${t}`,i),i}}create(t,e){if(e?.key&&this.cache.has(e.key))return new I(this.cache.get(e.key));const r=Y.fromSource(this.render,t,e);return e?.key&&(r.uid=e.key,this.cache.set(e.key,r)),new I(r)}createRenderTexture(t){return new vt(this.render,t)}createTextTexture(t){return new yt(this.render,t)}destroy(t,e=!1){let r,i;typeof t=="string"?(i=t,r=this.cache.get(i)):t instanceof I?(r=t.base,i=r?.uid,t.destroy()):(r=t,i=r.uid),r&&(r.refCount<=0||e)&&(r.destroy(this.render.gl),i&&this.cache.delete(i))}destroyAll(){for(const t of this.cache.values())t.destroy(this.render.gl);this.cache.clear()}_fetchImage(t){return new Promise((e,r)=>{const i=new Image;i.crossOrigin="anonymous",i.onload=()=>e(i),i.onerror=()=>r(new Error(`Failed to load image resource: ${t}`)),i.src=t})}}class Y{glTexture=null;width;height;uid;refCount=0;constructor(t,e,r){this.glTexture=t,this.width=e,this.height=r}static fromSource(t,e,r={}){const i=et(t,e,r);return new Y(i,e.width,e.height)}updateSource(t,e,r={}){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),r.textureFilter!==void 0&&ht(t,r.textureFilter),r.wrap!==void 0&&at(t,r.wrap),t.pixelStorei(t.UNPACK_FLIP_Y_WEBGL,1),t.pixelStorei(t.UNPACK_ALIGNMENT,1),r.premultipliedAlpha!==void 0&&t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,r.premultipliedAlpha),this.width===e.width&&this.height===e.height?t.texSubImage2D(t.TEXTURE_2D,0,0,0,t.RGBA,t.UNSIGNED_BYTE,e):(t.texImage2D(t.TEXTURE_2D,0,t.RGBA,t.RGBA,t.UNSIGNED_BYTE,e),this.width=e.width,this.height=e.height),r.premultipliedAlpha!==void 0&&t.pixelStorei(t.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1))}setFilterMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),ht(t,e),t.bindTexture(t.TEXTURE_2D,null))}setWrapMode(t,e){this.glTexture&&(t.bindTexture(t.TEXTURE_2D,this.glTexture),at(t,e),t.bindTexture(t.TEXTURE_2D,null))}destroy(t){this.glTexture&&(t.deleteTexture(this.glTexture),this.glTexture=null)}}class I{base;uvX=0;uvY=0;uvW=1;uvH=1;rawWidth=0;rawHeight=0;offsetX=0;offsetY=0;scale=1;isAtlas=!1;flipY=!1;isRotated=!1;glTexture=null;get width(){return(this.isRotated?this.rawHeight:this.rawWidth)*this.scale}get height(){return(this.isRotated?this.rawWidth:this.rawHeight)*this.scale}_px=0;_py=0;_pw=0;_ph=0;constructor(t){t&&this.setBase(t)}setBase(t){return this.base===t?this:(this.base&&this.base.refCount--,this.base=t,this.base.refCount++,this.setRegion(0,0,t.width,t.height),this.glTexture=t.glTexture,this)}setRegion(t,e,r,i){return this.base?(this._px=t,this._py=e,this._pw=r,this._ph=i,this.isAtlas=t!==0||e!==0||r!==this.base.width||i!==this.base.height,this.uvX=t/this.base.width,this.uvY=e/this.base.height,this.uvW=this.uvX+r/this.base.width,this.uvH=this.uvY+i/this.base.height,this.rawWidth=r*this.scale,this.rawHeight=i*this.scale,this):this}getSubTexture(t,e,r,i){if(!this.base)return new I;const s=this.clone(),a=this._px,o=this._py;return s.setRegion(a+t,o+e,r,i),s}clone(t){const e=t??new I(this.base);return t&&this.base&&t.setBase(this.base),e.scale=this.scale,e.uvX=this.uvX,e.uvY=this.uvY,e.uvW=this.uvW,e.uvH=this.uvH,e.rawWidth=this.rawWidth,e.rawHeight=this.rawHeight,e.offsetX=this.offsetX,e.offsetY=this.offsetY,e.flipY=this.flipY,e.isRotated=this.isRotated,e.isAtlas=this.isAtlas,e._px=this._px,e._py=this._py,e._pw=this._pw,e._ph=this._ph,e}splitGrid(t,e,r,i,s=0){if(!this.base)return[];const a=[],o=this.rawWidth,h=this.rawHeight,c=Math.max(0,s),u=t+c,l=e+c,d=r??Math.floor((o+c)/u),f=i??Math.floor((h+c)/l);for(let x=0;x<f;x++)for(let y=0;y<d;y++)a.push(this.getSubTexture(y*u,x*l,t,e));return a}static fromImageSource(t,e,r={}){const i=et(t,e,r);return new I(new Y(i,e.width,e.height))}destroy(){this.base&&(this.base.refCount--,this.base=void 0),this.glTexture=null}}class vt extends I{framebuffer;renderbuffer;gl;flipY=!0;clearColor;_allocW=0;_allocH=0;constructor(t,e){super(),this.gl=t.gl,this.clearColor=e.clearColor??m.Black;const r=Math.max(Math.round(e.width),1),i=Math.max(Math.round(e.height),1),a=et(t,{width:r,height:i},{...e,onlySize:!0});if(this.setBase(new Y(a,r,i)),this.framebuffer=this.gl.createFramebuffer(),this.renderbuffer=this.gl.createRenderbuffer(),!this.framebuffer||!this.renderbuffer)throw new Error("Failed to create Framebuffer or Renderbuffer");this.resize(r,i,!0)}resize(t,e,r=!1){t=Math.max(Math.round(t),1),e=Math.max(Math.round(e),1);const i=this.rawWidth===t&&this.rawHeight===e;if(!r&&i)return;const s=this.gl;(r||t>this._allocW||e>this._allocH)&&this.base&&(this._allocW=Math.max(this._allocW,t),this._allocH=Math.max(this._allocH,e),this.base.width=this._allocW,this.base.height=this._allocH,s.bindTexture(s.TEXTURE_2D,this.base.glTexture),s.texImage2D(s.TEXTURE_2D,0,s.RGBA,this._allocW,this._allocH,0,s.RGBA,s.UNSIGNED_BYTE,null),s.bindRenderbuffer(s.RENDERBUFFER,this.renderbuffer),s.renderbufferStorage(s.RENDERBUFFER,s.STENCIL_INDEX8,this._allocW,this._allocH),s.bindFramebuffer(s.FRAMEBUFFER,this.framebuffer),s.framebufferTexture2D(s.FRAMEBUFFER,s.COLOR_ATTACHMENT0,s.TEXTURE_2D,this.base.glTexture,0),s.framebufferRenderbuffer(s.FRAMEBUFFER,s.STENCIL_ATTACHMENT,s.RENDERBUFFER,this.renderbuffer),s.bindFramebuffer(s.FRAMEBUFFER,null),s.bindRenderbuffer(s.RENDERBUFFER,null),s.bindTexture(s.TEXTURE_2D,null)),this.rawWidth=t,this.rawHeight=e,this.uvX=0,this.uvW=t/this._allocW,this.uvY=0,this.uvH=e/this._allocH}activate(t=!1){if(!this.framebuffer)return;const e=this.gl;e.bindFramebuffer(e.FRAMEBUFFER,this.framebuffer),e.viewport(0,0,this.rawWidth,this.rawHeight),t&&this.clear()}clear(t){if(!this.framebuffer)return;const e=this.gl,r=t??this.clearColor;r&&(r.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT|e.STENCIL_BUFFER_BIT))}deactivate(){const t=this.gl;t.bindFramebuffer(t.FRAMEBUFFER,null)}GetPixels(t=0,e=0,r=this.rawWidth,i=this.rawHeight){if(!this.framebuffer)return new Uint8Array(0);const s=Math.floor(t),a=Math.floor(e),o=Math.floor(r),h=Math.floor(i);if(o<=0||h<=0)return new Uint8Array(0);if(s<0||a<0||s>=this.rawWidth||a>=this.rawHeight)return new Uint8Array(0);const c=Math.min(o,this.rawWidth-s),u=Math.min(h,this.rawHeight-a),l=this.rawHeight-a-u,d=this.gl,f=d.getParameter(d.FRAMEBUFFER_BINDING);d.bindFramebuffer(d.FRAMEBUFFER,this.framebuffer);const x=new Uint8Array(c*u*4);return d.readPixels(s,l,c,u,d.RGBA,d.UNSIGNED_BYTE,x),d.bindFramebuffer(d.FRAMEBUFFER,f),x}GetColorAt(t,e){const r=this.GetPixels(t,e,1,1);return r.length<4?new m(0,0,0,0):new m(r[0],r[1],r[2],r[3])}destroy(){super.destroy(),this.framebuffer&&this.gl.deleteFramebuffer(this.framebuffer),this.renderbuffer&&this.gl.deleteRenderbuffer(this.renderbuffer),this.base?.destroy(this.gl)}}const qt={fontFamily:"Arial",fontSize:24,fontWeight:"normal",fill:"#000000",strokeThickness:0,align:"left",lineHeight:1};class yt extends I{canvas;ctx;render;_text;_style;options;flipY=!0;constructor(t,e){super(),this.render=t,this._style={...qt,...e},this._text=e?.text??"",this.options={premultipliedAlpha:t.premultipliedAlpha,...e},this.scale=1/t.dpr,this.canvas=document.createElement("canvas");const r=this.canvas.getContext("2d",{willReadFrequently:!0});if(!r)throw new Error("Failed to get 2d context for TextTexture");this.ctx=r,this.canvas.width=1,this.canvas.height=1;const i=et(t,this.canvas,this.options);this.setBase(new Y(i,1,1)),this.update()}get text(){return this._text}set text(t){this._text!==t&&(this._text=t,this.update())}get style(){return this._style}set style(t){this._style={...this._style,...t},this.update()}updateOffset(t,e){switch(this._style.align){case"center":return t/2;case"right":return t;default:return e}}update(){const t=this.ctx,e=this.style,r=e.fontSize,i=e.fontWeight,s=e.fontFamily,a=e.lineHeight,o=`${i} ${r}px ${s}`,h=this.render.dpr;t.font=o,t.textBaseline="top";const c=this._text.split(`
2
+ `);let u=0,l=0;const d=t.measureText(c[0]||"M"),f=(d.fontBoundingBoxAscent||r)+(d.fontBoundingBoxDescent||r*.2);for(const B of c){const L=t.measureText(B);L.width>u&&(u=L.width),l+=f*a}l-=f*(a-1);const x=this._style.strokeThickness||0,y=Math.ceil(u+x*2)||1,T=Math.ceil(l+x*2)||1,R=Math.ceil(y*h),S=Math.ceil(T*h);(this.canvas.width!==R||this.canvas.height!==S)&&(this.canvas.width=R,this.canvas.height=S),t.setTransform(h,0,0,h,0,0),t.clearRect(0,0,y,T),t.font=o,t.textBaseline="top",t.textAlign=this._style.align;const b=this.updateOffset(y,x),N=e.strokeThickness,P=N>0;P&&(t.lineWidth=N,t.strokeStyle=e.stroke,t.lineJoin="round"),e.fill&&(t.fillStyle=e.fill);let W=x;for(const B of c)P&&t.strokeText(B,b,W),e.fill&&t.fillText(B,b,W),W+=f*a;this.base?.updateSource(this.render.gl,this.canvas,this.options),this.setRegion(0,0,R,S)}}const Qt=(n,t=!1,e=!0)=>{const r=n.getContext("webgl2",{stencil:!0,antialias:t,premultipliedAlpha:e});if(!r)throw new Error("WebGL2 is not supported in this browser.");return r},Tt=(n,t,e)=>{const r=n.createShader(e);if(!r)throw new Error("Unable to create webgl shader");if(n.shaderSource(r,t),n.compileShader(r),!n.getShaderParameter(r,n.COMPILE_STATUS)){const s=n.getShaderInfoLog(r);throw console.error("Shader compilation failed:",s),new Error("Unable to compile shader: "+s+t)}return r},Zt=(n,t,e)=>{var r=n.createProgram(),i=Tt(n,t,35633),s=Tt(n,e,35632);if(!r)throw new Error("Unable to create program shader");if(n.attachShader(r,i),n.attachShader(r,s),n.linkProgram(r),!n.getProgramParameter(r,n.LINK_STATUS)){const o=n.getProgramInfoLog(r);throw new Error("Unable to link shader program: "+o)}return r};function at(n,t){const e={[j.CLAMP]:n.CLAMP_TO_EDGE,[j.REPEAT]:n.REPEAT,[j.MIRRORED_REPEAT]:n.MIRRORED_REPEAT}[t]||n.CLAMP_TO_EDGE;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_S,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_WRAP_T,e)}function ht(n,t){const e={[st.LINEAR]:n.LINEAR,[st.NEAREST]:n.NEAREST}[t]??n.NEAREST;n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MIN_FILTER,e),n.texParameteri(n.TEXTURE_2D,n.TEXTURE_MAG_FILTER,e)}function et(n,t,e){const r=n.gl,i=r.createTexture();if(!i)throw new Error("Unable to create WebGL texture");if(r.bindTexture(r.TEXTURE_2D,i),r.pixelStorei(r.UNPACK_FLIP_Y_WEBGL,0),r.pixelStorei(r.UNPACK_ALIGNMENT,1),at(r,e.wrap??j.CLAMP),ht(r,e.textureFilter??n.textureFilter),e.onlySize){const s=t;r.texImage2D(r.TEXTURE_2D,0,r.RGBA,s.width,s.height,0,r.RGBA,r.UNSIGNED_BYTE,null)}else{const s=e.premultipliedAlpha??n.premultipliedAlpha;s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!0),r.texImage2D(r.TEXTURE_2D,0,r.RGBA,r.RGBA,r.UNSIGNED_BYTE,t),s&&r.pixelStorei(r.UNPACK_PREMULTIPLY_ALPHA_WEBGL,!1)}return r.bindTexture(r.TEXTURE_2D,null),i}function z(n,t){if(n.includes("%TEXTURE_NUM%")&&(n=n.replace("%TEXTURE_NUM%",t.toString())),n.includes("%GET_COLOR%")){let e="";for(let r=0;r<t;r++)r==0?e+=`if(vTextureId == ${r})`:r==t-1?e+="else":e+=`else if(vTextureId == ${r})`,e+=`{return texture(uTextures[${r}], uv);}`;n=n.replace("%GET_COLOR%",e)}return n}const Jt=5126,ot=5121;function te(n,t,e){n.vertexAttribDivisor(t,e)}function Rt(n,t,e,r,i){n.drawArraysInstanced(t,e,r,i)}let ee=0;class ct{program;attributeLoc={};uniformLoc={};isCustom=!1;padding=0;uniformType={};uniformIsArray={};gl;shaderId=ee++;vao;constructor(t,e,r,i){this.gl=t,this.program=Zt(t,e,r),this.parseShader(e),this.parseShader(r),this.vao=t.createVertexArray(),i&&this.setAttributes(i)}use(){this.gl.useProgram(this.program)}bindVAO(){this.gl.bindVertexArray(this.vao)}unbindVAO(){this.gl.bindVertexArray(null)}setUniform(t,e){const r=this.uniformLoc[t];if(r===void 0)return;const i=this.uniformType[t],s=this.uniformIsArray[t];re(this.gl,r,i,e,s)}setUniforms(t){for(const e in t)this.setUniform(e,t[e])}setAttribute(t){const e=this.attributeLoc[t.name];if(e===void 0)return;const r=this.gl;r.vertexAttribPointer(e,t.size,t.type??Jt,t.normalized??!1,t.stride,t.offset??0),r.enableVertexAttribArray(e),te(r,e,t.divisor??0)}setAttributes(t){for(const e of t)this.setAttribute(e)}destroy(){this.gl.deleteProgram(this.program)}parseShader(t){const e=this.gl,r=t.match(/(?:in|attribute)\s+\w+\s+\w+/g);if(r)for(const s of r){const o=s.split(/\s+/)[2],h=e.getAttribLocation(this.program,o);h!==-1&&(this.attributeLoc[o]=h)}const i=t.match(/uniform\s+\w+\s+\w+(?:\[\d+\])?/g);if(i)for(const s of i){const a=s.split(/\s+/),o=a[1],h=a[2].replace(/\[\d+\]$/,""),c=e.getUniformLocation(this.program,h);c!==null&&(this.uniformLoc[h]=c,this.uniformType[h]=o,this.uniformIsArray[h]=/\[\d+\]$/.test(a[2]))}}}function re(n,t,e,r,i=!1){switch(e){case"float":return n.uniform1f(t,r);case"int":case"bool":case"sampler2D":case"samplerCube":return i?n.uniform1iv(t,r):n.uniform1i(t,r);case"vec2":return n.uniform2fv(t,r);case"vec3":return n.uniform3fv(t,r);case"vec4":return n.uniform4fv(t,r);case"ivec2":case"bvec2":return n.uniform2iv(t,r);case"ivec3":case"bvec3":return n.uniform3iv(t,r);case"ivec4":case"bvec4":return n.uniform4iv(t,r);case"mat2":return n.uniformMatrix2fv(t,!1,r);case"mat3":return n.uniformMatrix3fv(t,!1,r);case"mat4":return n.uniformMatrix4fv(t,!1,r);default:return ie(n,t,r)}}function ie(n,t,e){if(typeof e=="number")return n.uniform1f(t,e);const r=e;switch(r.length){case 2:return n.uniform2fv(t,r);case 3:return n.uniform3fv(t,r);case 4:return n.uniform4fv(t,r);case 9:return n.uniformMatrix3fv(t,!1,r);case 16:return n.uniformMatrix4fv(t,!1,r);default:return n.uniform1fv(t,r)}}class ut{vs;fs;glshader=new Map;uniforms={};uniformDirty=new Set;uniformTextures={};usedTextureUnitNum=0;padding=0;rapid;constructor(t,e,r,i=0,s){this.vs=e,this.fs=r,this.rapid=t,this.uniforms=s??{},this.usedTextureUnitNum=i}setUniforms(t){this.rapid.flush();const e={},r={};for(const[i,s]of Object.entries(t))s instanceof WebGLTexture?r[i]=s:e[i]=s;Object.assign(this.uniforms,e),Object.assign(this.uniformTextures,r);for(const i of this.glshader.keys())this.uniformDirty.add(i)}setPadding(t){this.padding=t;for(const e of this.glshader.values())e.padding=t;return this}applyUniform(t,e){const r=this.glshader.get(t);r&&(Object.keys(e).length>0&&r.setUniforms(e),this.uniformDirty.has(t)&&(r.setUniforms(this.uniforms),this.uniformDirty.delete(t)))}getGLShader(t,e,r,i){if(this.glshader.has(e))return this.glshader.get(e);if(i==null||r==null)return console.warn("CustomGlShader: missing base shader for "+e),null;r=r.replace("// CUSTOM_CODE_CALL","vertex(position, vRegion);"),i=i.replace("// CUSTOM_CODE_CALL","fragment(fragColor);"),r=r.replace("// CUSTOM_CODE",this.vs),i=i.replace("// CUSTOM_CODE",this.fs);const s=t.createShader(r,i);return s.isCustom=!0,s.padding=this.padding,this.glshader.set(e,s),this.uniformDirty.add(e),s}destroy(){this.glshader.forEach(t=>t.destroy())}}class lt{constructor(t){this.rapid=t,this.gl=t.gl,this.maxTextureUnits=t.maxTextureUnits,this.matrixStore=t.matrix}defaultShader;currentShader;customShader=null;customShaderUsedTextureNum=0;gl;maxTextureUnits;matrixStore;isDefaultShader=!0;KEY="default";vs="";fs="";usedTextures=[];usedTexturePadding=[];createBuffer(){}createDefaultShader(){}get freeTextureUnitNum(){return this.maxTextureUnits-this.usedTextures.length-this.customShaderUsedTextureNum}getTextureUnitList(){return Array.from({length:this.maxTextureUnits},(t,e)=>e)}findTextureUnit(t,e=0,r=0){for(let i=0;i<this.usedTextures.length;i++){const s=i*2;if(this.usedTextures[i]===t&&this.usedTexturePadding[s]===e&&this.usedTexturePadding[s+1]===r)return i}return-1}useTexture(t,e=0,r=0){const i=this.findTextureUnit(t,e,r);return i==-1?(this.freeTextureUnitNum===0&&this.flush(),this.usedTextures.push(t),this.usedTexturePadding.push(e),this.usedTexturePadding.push(r),this.usedTextures.length-1):i}createShader(t,e){return new ct(this.gl,t,e)}createCustomShader(t){return t.getGLShader(this,this.KEY,this.vs,this.fs)}getCustomShader(t){if(!t)return this.defaultShader;if(t instanceof ut){const e=this.createCustomShader(t);return e??this.defaultShader}return t}isSameShader(t){return this.isDefaultShader&&!t?!0:this.getCustomShader(t)==this.currentShader}enter(t){this.resetRender(),this.currentShader=this.getCustomShader(t),t instanceof ut?(this.customShader=t,this.customShaderUsedTextureNum=t.usedTextureUnitNum):(this.customShader=null,this.customShaderUsedTextureNum=0),this.isDefaultShader=this.currentShader==this.defaultShader,this.currentShader.use(),this.currentShader.setUniform("u_projection",this.rapid.projection)}exit(){this.hasPendingContent()&&this.flush(),this.gl.bindVertexArray(null)}flush(){this.render(),this.resetRender()}render(){this.prepareRender()}prepareRender(){const t=this.currentShader;if(t.use(),this.customShader){const r=this.customShader,i={};for(const s in r.uniformTextures)i[s]=this.useTexture(r.uniformTextures[s]);this.customShader.applyUniform(this.KEY,i)}const e=this.gl;for(let r=0;r<this.usedTextures.length;r++)e.activeTexture(e.TEXTURE0+r),e.bindTexture(e.TEXTURE_2D,this.usedTextures[r]);t.setUniform("uTextures",Int32Array.from({length:this.usedTextures.length},(r,i)=>i)),t.setUniform("uPadding",Float32Array.from({length:this.usedTexturePadding.length},(r,i)=>this.usedTexturePadding[i]))}resetRender(){this.usedTextures.length=0,this.usedTexturePadding.length=0}hasPendingContent(){return!1}}const rt=`#version 300 es\r
3
3
  precision highp float;\r
4
4
  \r
5
5
  // per-vertex\r
@@ -47,7 +47,7 @@ void main(void) {\r
47
47
  \r
48
48
  gl_Position = u_projection * position;\r
49
49
  }\r
50
- `,Tt=`#version 300 es\r
50
+ `,Et=`#version 300 es\r
51
51
  precision mediump float;\r
52
52
  \r
53
53
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -96,7 +96,7 @@ void main(void) {\r
96
96
  \r
97
97
  // CUSTOM_CODE_CALL\r
98
98
  }\r
99
- `,K=48,Rt=new Float32Array([0,0,1,0,0,1,1,1]);class rt extends ct{instanceBuffer;quadBuffer;instanceCount=0;localSpriteMatrix=new Float32Array(6);worldSpriteMatrix=new Float32Array(6);KEY="Sprite";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.quadBuffer=new J(t,M.Float32,t.ARRAY_BUFFER,t.STATIC_DRAW),this.quadBuffer.bindBuffer();for(const e of Rt)this.quadBuffer.pushFloat32(e);this.quadBuffer.makeDirty(),this.quadBuffer.bufferData(),this.instanceBuffer=new J(t,M.Uint32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW)}createDefaultShader(){const t=this.rapid,e=H(Tt,t.maxTextureUnits),r=H(et,t.maxTextureUnits);return this.vs=r,this.fs=e,this.defaultShader=this.createShader(r,e),this.defaultShader}createShader(t,e){const r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aMatrixRow0",size:3,stride:K,offset:0,divisor:1},{name:"aMatrixRow1",size:3,stride:K,offset:12,divisor:1},{name:"aUVRect",size:4,stride:K,offset:24,divisor:1},{name:"aColor",size:4,type:at,normalized:!0,stride:K,offset:40,divisor:1},{name:"aTextureId",size:1,type:at,stride:K,offset:44,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}createCustomShader(t){const e=H(Tt,this.rapid.maxTextureUnits-t.usedTextureUnitNum),r=H(et,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,r,e)}drawSprite(t,e,r=0,i=0,s=1,a=1,o=4294967295,h=0,c=0,u=!1,l=!1,d=!1){const f=e*6,x=this.matrixStore.data;this.drawSpriteAffine(t,x[f],x[f+1],x[f+2],x[f+3],x[f+4],x[f+5],r,i,s,a,o,h,c,u,l,d)}drawSpriteAffine(t,e,r,i,s,a,o,h=0,c=0,u=1,l=1,d=4294967295,f=0,x=0,v=!1,y=!1,T=!1){const w=t.base,b=t.rawWidth,N=t.rawHeight,_=t.offsetX,D=t.offsetY,k=this.useTexture(t.glTexture,f/w.width,x/w.height),L=this.instanceBuffer,S=L.usedElemNum;L.resize(12);const P=L.float32,V=L.uint32,Y=T?N:b,z=T?b:N,W=Y+2*f,B=z+2*x,U=_-f,I=D-x,R=this.localSpriteMatrix;T?(R[0]=0,R[1]=y?B:-B,R[2]=v?-W:W,R[3]=0,R[4]=U+(v?W:0),R[5]=I+(y?0:B)):(R[0]=v?-W:W,R[1]=0,R[2]=0,R[3]=y?-B:B,R[4]=U+(v?W:0),R[5]=I+(y?B:0));const A=this.worldSpriteMatrix;A[0]=e*R[0]+i*R[1],A[1]=r*R[0]+s*R[1],A[2]=e*R[2]+i*R[3],A[3]=r*R[2]+s*R[3],A[4]=a+e*R[4]+i*R[5],A[5]=o+r*R[4]+s*R[5],P[S+6]=h,P[S+7]=c,P[S+8]=u,P[S+9]=l,V[S+10]=d,V[S+11]=k,this.rapid.roundPixels&&(A[4]=Math.round(A[4]),A[5]=Math.round(A[5])),P[S]=A[0],P[S+1]=A[2],P[S+2]=A[4],P[S+3]=A[1],P[S+4]=A[3],P[S+5]=A[5],L.usedElemNum+=12,L.makeDirty(),this.instanceCount++}render(){if(this.instanceCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO(),yt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++}resetRender(){super.resetRender(),this.instanceBuffer.clear(),this.instanceCount=0}hasPendingContent(){return this.instanceCount>0}}const te=`#version 300 es\r
99
+ `,K=48,Mt=new Float32Array([0,0,1,0,0,1,1,1]);class it extends lt{instanceBuffer;quadBuffer;instanceCount=0;localSpriteMatrix=new Float32Array(6);worldSpriteMatrix=new Float32Array(6);KEY="Sprite";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.quadBuffer=new tt(t,w.Float32,t.ARRAY_BUFFER,t.STATIC_DRAW),this.quadBuffer.bindBuffer();for(const e of Mt)this.quadBuffer.pushFloat32(e);this.quadBuffer.makeDirty(),this.quadBuffer.bufferData(),this.instanceBuffer=new tt(t,w.Uint32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW)}createDefaultShader(){const t=this.rapid,e=z(Et,t.maxTextureUnits),r=z(rt,t.maxTextureUnits);return this.vs=r,this.fs=e,this.defaultShader=this.createShader(r,e),this.defaultShader}createShader(t,e){const r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aMatrixRow0",size:3,stride:K,offset:0,divisor:1},{name:"aMatrixRow1",size:3,stride:K,offset:12,divisor:1},{name:"aUVRect",size:4,stride:K,offset:24,divisor:1},{name:"aColor",size:4,type:ot,normalized:!0,stride:K,offset:40,divisor:1},{name:"aTextureId",size:1,type:ot,stride:K,offset:44,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}createCustomShader(t){const e=z(Et,this.rapid.maxTextureUnits-t.usedTextureUnitNum),r=z(rt,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,r,e)}drawSprite(t,e,r=0,i=0,s=1,a=1,o=4294967295,h=0,c=0,u=!1,l=!1,d=!1){const f=e*6,x=this.matrixStore.data;this.drawSpriteAffine(t,x[f],x[f+1],x[f+2],x[f+3],x[f+4],x[f+5],r,i,s,a,o,h,c,u,l,d)}drawSpriteAffine(t,e,r,i,s,a,o,h=0,c=0,u=1,l=1,d=4294967295,f=0,x=0,y=!1,T=!1,R=!1){const S=t.base,b=t.rawWidth,N=t.rawHeight,P=t.offsetX,W=t.offsetY,B=this.useTexture(t.glTexture,f/S.width,x/S.height),L=this.instanceBuffer,A=L.usedElemNum;L.resize(12);const _=L.float32,$=L.uint32,G=R?N:b,H=R?b:N,F=G+2*f,D=H+2*x,V=P-f,M=W-x,v=this.localSpriteMatrix;R?(v[0]=0,v[1]=T?D:-D,v[2]=y?-F:F,v[3]=0,v[4]=V+(y?F:0),v[5]=M+(T?0:D)):(v[0]=y?-F:F,v[1]=0,v[2]=0,v[3]=T?-D:D,v[4]=V+(y?F:0),v[5]=M+(T?D:0));const U=this.worldSpriteMatrix;U[0]=e*v[0]+i*v[1],U[1]=r*v[0]+s*v[1],U[2]=e*v[2]+i*v[3],U[3]=r*v[2]+s*v[3],U[4]=a+e*v[4]+i*v[5],U[5]=o+r*v[4]+s*v[5],_[A+6]=h,_[A+7]=c,_[A+8]=u,_[A+9]=l,$[A+10]=d,$[A+11]=B,this.rapid.roundPixels&&(U[4]=Math.round(U[4]),U[5]=Math.round(U[5])),_[A]=U[0],_[A+1]=U[2],_[A+2]=U[4],_[A+3]=U[1],_[A+4]=U[3],_[A+5]=U[5],L.usedElemNum+=12,L.makeDirty(),this.instanceCount++}render(){if(this.instanceCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO(),Rt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++}resetRender(){super.resetRender(),this.instanceBuffer.clear(),this.instanceCount=0}hasPendingContent(){return this.instanceCount>0}}const se=`#version 300 es\r
100
100
  precision highp float;\r
101
101
  \r
102
102
  in vec2 aPosition;\r
@@ -127,7 +127,7 @@ void main(void) {\r
127
127
  // CUSTOM_CODE_CALL\r
128
128
  gl_Position = u_projection * position;\r
129
129
  }\r
130
- `,ee=`#version 300 es\r
130
+ `,ne=`#version 300 es\r
131
131
  precision mediump float;\r
132
132
  \r
133
133
  in vec4 vColor;\r
@@ -173,7 +173,7 @@ void main(void) {\r
173
173
  fragColor = sampleTexture(vRegion) * vColor;\r
174
174
  // CUSTOM_CODE_CALL\r
175
175
  }\r
176
- `,re=`#version 300 es\r
176
+ `,ae=`#version 300 es\r
177
177
  precision highp float;\r
178
178
  \r
179
179
  in vec2 aPosition;\r
@@ -196,7 +196,7 @@ void main(void) {\r
196
196
  );\r
197
197
  gl_Position = u_projection * position;\r
198
198
  }\r
199
- `,ie=`#version 300 es\r
199
+ `,he=`#version 300 es\r
200
200
  precision mediump float;\r
201
201
  \r
202
202
  in vec2 vRegion;\r
@@ -216,7 +216,7 @@ void main(void) {\r
216
216
  discard;\r
217
217
  }\r
218
218
  }\r
219
- `,q=20;class Et extends ct{vertexBuffer;vertexCount=0;matrixIndex=-1;drawMode=this.gl.TRIANGLES;texture;maskShader;KEY="Graphic";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.vertexBuffer=new J(t,M.Float32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW),this.maskShader=this.createMaskShader(re,ie)}createDefaultShader(){return this.vs=te,this.fs=ee,this.defaultShader=this.createShader(this.vs,this.fs),this.defaultShader}createMaskShader(t,e){const r=this.gl,i=new ht(r,t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:q-4,offset:0,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:q-4,offset:8,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}createShader(t,e){const r=this.gl,i=super.createShader(t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:q,offset:0,divisor:0},{name:"aColor",size:4,type:r.UNSIGNED_BYTE,normalized:!0,stride:q,offset:8,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:q,offset:12,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}startGraphic(t,e=this.gl.TRIANGLES,r){this.vertexBuffer.clear(),this.vertexCount=0,this.matrixIndex=t,this.drawMode=e,this.texture=r,this.texture?.glTexture&&this.useTexture(this.texture.glTexture,0,0)}addVertex(t,e,r=0,i=0,s=4294967295){const a=this.vertexBuffer;a.pushFloat32(t),a.pushFloat32(e),this.currentShader!=this.maskShader&&a.pushUint32(s),a.pushFloat32(r),a.pushFloat32(i),this.vertexCount++,this.vertexBuffer.makeDirty()}endGraphic(){this.flush()}render(){if(this.vertexCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader,r=this.matrixIndex*6,i=this.matrixStore.data;let s=i[r+4],a=i[r+5];this.rapid.roundPixels&&(s=Math.round(s),a=Math.round(a)),e.setUniform("uMatrixRow0",[i[r],i[r+2],s]),e.setUniform("uMatrixRow1",[i[r+1],i[r+3],a]),e.setUniform("uUVRect",this.texture?[this.texture.uvX,this.texture.uvY,this.texture.uvW,this.texture.uvH]:[0,0,1,1]),this.texture?.glTexture?(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.texture.glTexture),e.setUniform("uTexture",0),e.setUniform("uUseTexture",1)):e.setUniform("uUseTexture",0),this.vertexBuffer.bindBuffer(),this.vertexBuffer.bufferData(),e.bindVAO(),t.drawArrays(this.drawMode,0,this.vertexCount),this.rapid.drawcallCount++,this.texture=void 0}hasPendingContent(){return!1}}class p{x;y;static ZERO=new p(0,0);static ONE=new p(1,1);static UP=new p(0,1);static DOWN=new p(0,-1);static LEFT=new p(-1,0);static RIGHT=new p(1,0);constructor(t,e){this.x=t!==void 0?t:0,this.y=e!==void 0?e:0}set(t,e){return e===void 0?(this.x=t,this.y=t):(this.x=t,this.y=e),this}add(t){return new p(this.x+t.x,this.y+t.y)}subtract(t){return new p(this.x-t.x,this.y-t.y)}sub(t){return new p(this.x-t.x,this.y-t.y)}multiply(t){return t instanceof p?new p(this.x*t.x,this.y*t.y):new p(this.x*t,this.y*t)}mul(t){return this.multiply(t)}divide(t){return t instanceof p?new p(this.x/t.x,this.y/t.y):new p(this.x/t,this.y/t)}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}distanceTo(t){const e=this.x-t.x,r=this.y-t.y;return Math.sqrt(e*e+r*r)}clone(){return new p(this.x,this.y)}to(t){this.x=t.x,this.y=t.y}copy(){return new p(this.x,this.y)}equals(t){return t.x==this.x&&t.y==this.y}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}inverted(){return new p(this.x*-1,this.y*-1)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}squaredLength(){return this.x*this.x+this.y*this.y}normalize(){const t=this.length();return this.x=this.x/t||0,this.y=this.y/t||0,this}normalized(){const t=this.length();return new p(this.x/t||0,this.y/t||0)}fix(t=1e-13){this.x=Math.abs(this.x)<t?0:this.x,this.y=Math.abs(this.y)<t?0:this.y}fixed(t=1e-13){return new p(Math.abs(this.x)<t?0:this.x,Math.abs(this.y)<t?0:this.y)}angle(){return Math.atan2(this.y,this.x)}abs(){return new p(Math.abs(this.x),Math.abs(this.y))}floor(){return new p(Math.floor(this.x),Math.floor(this.y))}ceil(){return new p(Math.ceil(this.x),Math.ceil(this.y))}stringify(){return`Vec2(${this.x}, ${this.y})`}clear(){this.x=0,this.y=0}isPrettyMuchZero(){return Math.abs(this.x)<1e-4&&Math.abs(this.y)<1e-4}isZero(){return this.x==0&&this.y==0}isNotZero(){return this.x!==0||this.y!==0}setToPolar(t,e=1){return this.x=Math.cos(t)*e,this.y=Math.sin(t)*e,this}static FromArray(t){return t.map(e=>new p(e[0],e[1]))}static fromAngle(t){return new p(Math.cos(t),Math.sin(t))}}const Mt=(n,t)=>{const[e,r,i,s,a,o]=t,h=new Float32Array([e,i,0,0,r,s,0,0,0,0,1,0,a,o,0,1]);return wt(h,n)},wt=(n,t)=>{const e=new Float32Array(16);for(let r=0;r<4;r++)for(let i=0;i<4;i++){let s=0;for(let a=0;a<4;a++)s+=n[i*4+a]*t[a*4+r];e[i*4+r]=s}return e};var St=(n=>(n[n.STRETCH=0]="STRETCH",n[n.REPEAT=1]="REPEAT",n))(St||{});const ut=10,At=(n,t,e,r,i,s)=>{const a=[],o=[],h=r?Math.atan2(t.y,t.x):Math.atan2(-t.y,-t.x),c=Math.PI,u=new p(t.y,-t.x);for(let l=0;l<ut;l++){const d=l/ut,f=(l+1)/ut,x=h+d*c,v=h+f*c,y=new p(Math.cos(x)*e,Math.sin(x)*e),T=new p(Math.cos(v)*e,Math.sin(v)*e);a.push(n),o.push(new p(i,.5)),a.push(n.add(y)),o.push(new p(i+y.dot(u)*s,.5-.5*y.dot(t)/e)),a.push(n.add(T)),o.push(new p(i+T.dot(u)*s,.5-.5*T.dot(t)/e))}return{vertices:a,uv:o}},se=(n,t=!1)=>{const e=[];if(n.length<2||t&&n.length<3)return{normals:e,length:0};const r=4,i=.001,s=n.length;let a=0;if(t)for(let h=0;h<s;h++){const c=n[h],u=n[(h+1)%s];a+=c.distanceTo(u)}else for(let h=0;h<s-1;h++)a+=n[h].distanceTo(n[h+1]);const o=(h,c,u)=>{const l=c.subtract(h).normalize(),d=c.subtract(u).normalize(),f=d.dot(l);if(f<-1+i)return{normal:l.perpendicular(),miters:1};{let x=d.add(l).normalize();l.cross(d)<0&&(x=x.multiply(-1));let v=1/Math.sqrt((1-f)/2);return{normal:x,miters:Math.min(v,r)}}};if(t)for(let h=0;h<s;h++){const c=h===0?n[s-1]:n[h-1],u=n[h],l=h===s-1?n[0]:n[h+1];e.push(o(c,u,l))}else for(let h=0;h<s;h++)if(h===0){const c=n[1].subtract(n[0]).normalize();e.push({normal:c.perpendicular(),miters:1})}else if(h===s-1){const c=n[h].subtract(n[h-1]).normalize();e.push({normal:c.perpendicular(),miters:1})}else e.push(o(n[h-1],n[h],n[h+1]));return{normals:e,length:a}},ne=n=>{const t=n.points;if(t.length<2)return{vertices:[],uv:[]};const{normals:e,length:r}=se(t,n.closed),i=(n.width||1)/2,s=[],a=[],o=n.roundCap||!1,h=n.textureMode||0;let c=0;const u=n.texture?.rawWidth||1,l=n.closed?t.length:t.length-1;for(let d=0;d<l;d++){const f=t[d],x=e[d].normal,v=e[d].miters,y=(d+1)%t.length,T=t[y],w=e[y].normal,b=e[y].miters,N=f.add(x.multiply(v*i)),_=f.subtract(x.multiply(v*i)),D=T.add(w.multiply(b*i)),k=T.subtract(w.multiply(b*i)),L=f.distanceTo(T);let S=0,P=0;h===0?(S=c/r,P=(c+L)/r):(S=c/u,P=S+L/u);const V=new p(S,0),Y=new p(S,1),z=new p(P,0),W=new p(P,1);s.push(N),a.push(V),s.push(_),a.push(Y),s.push(D),a.push(z),s.push(D),a.push(z),s.push(k),a.push(W),s.push(_),a.push(Y),c+=L}if(o&&!n.closed){const d=t[0],f=e[0].normal,x=h===0?r>0?1/r:0:1/u,v=At(d,f,i,!0,0,x);s.push(...v.vertices),a.push(...v.uv);const y=t[t.length-1],T=e[t.length-1].normal,w=h===0?1:c/u,b=h===0?r>0?1/r:0:1/u,N=At(y,T,i,!1,w,b);s.push(...N.vertices),a.push(...N.uv)}return{vertices:s,uv:a}},Q=(n,t,e,r)=>{if(t.customMatrix!==void 0)return t.customMatrix;if(t.modifyStack){n.matrixStack.applyTransform(t,e,r);return}else{const i=n.matrix.temporary;return n.matrixStack.applyTransform(t,e,r,i),i}},bt=(n,t)=>t?n?t.premultipliedUint32:t.uint32:4294967295,ae=2,Ut=(n,t)=>{const e=Q(n,t,t.texture.rawWidth,t.texture.rawHeight),r=t.texture;if(!r?.base||n.inCreateMask)return;const i=r.isAtlas?n.atlasSpriteRegion:n.spriteRegion;n.enterRegion(i,t.shader);let s=r.uvX,a=r.uvY,o=r.uvW,h=r.uvH;const c=!!t.flipX,u=!!t.flipY!=!!r.flipY;let l=t.padding??i.currentShader.padding;r.isAtlas&&(l+=ae);const d=s<=o?l:-l,f=a<=h?l:-l;i.drawSprite(r,e??t.customMatrix??n.matrixStack.curWorldM,s,a,o,h,n.getColorUint32(t.color),d,f,c,u,r.isRotated)},Ct=(n,t)=>{const e=n.particleRegion;n.enterRegion(e,t.shader);const r=t.texture,i=t.count??t.x.length,s=t.color;e.drawParticles(r,t.x,t.y,t.rotation,s,i,t.scaleX,t.scaleY,r.uvX,r.uvY,r.uvW,r.uvH,t.flipX,t.flipY,r.isRotated,t.originX,t.originY,n.premultipliedAlpha,t.reverseOrder,t.customMatrix)},lt=(n,t)=>{if(t.points.length===0)return;const e=Q(n,t,0,0);n.startGraphic(t.drawMode??n.gl.TRIANGLES,t.texture,t.shader,e??t.customMatrix);for(let r=0;r<t.points.length;r++){const i=t.points[r],s=t.uv?.[r],a=Array.isArray(t.color)?t.color[r]:t.color;n.addGraphicVertex(i.x,i.y,s?.x??0,s?.y??0,n.getColorUint32(a))}n.endGraphic()},_t=(n,t)=>{if(n.inCreateMask)return;const{vertices:e,uv:r}=ne(t);lt(n,{...t,points:e,uv:r,drawMode:n.gl.TRIANGLES})},Pt=(n,t)=>{const e=Q(n,t,t.texture.rawWidth,t.texture.rawHeight);n.startMaskGraphic(n.gl.TRIANGLE_FAN,t.texture,e??t.customMatrix),n.addRectVertex(t.texture.rawWidth,t.texture.rawHeight),n.endGraphic()},Nt=(n,t)=>{const e=Q(n,t,t.width,t.height);n.startGraphic(n.gl.TRIANGLE_FAN,t.texture,t.shader,e??t.customMatrix),n.addRectVertex(t.width,t.height,t.color),n.endGraphic()},Lt=(n,t)=>{const e=t.segments??32,r=Q(n,t,0,0);n.startGraphic(n.gl.TRIANGLE_FAN,void 0,t.shader,r??t.customMatrix);const i=n.getColorUint32(t.color);n.addGraphicVertex(0,0,.5,.5,i),n.addCircleVertex(t.radius,t.color,e),n.addGraphicVertex(t.radius,0,1,.5,i),n.endGraphic()},It=`#version 300 es\r
219
+ `,q=20;class wt extends lt{vertexBuffer;vertexCount=0;matrixIndex=-1;drawMode=this.gl.TRIANGLES;texture;maskShader;KEY="Graphic";constructor(t){super(t),this.createBuffer(),this.createDefaultShader()}createBuffer(){const t=this.gl;this.vertexBuffer=new tt(t,w.Float32,t.ARRAY_BUFFER,t.DYNAMIC_DRAW),this.maskShader=this.createMaskShader(ae,he)}createDefaultShader(){return this.vs=se,this.fs=ne,this.defaultShader=this.createShader(this.vs,this.fs),this.defaultShader}createMaskShader(t,e){const r=this.gl,i=new ct(r,t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:q-4,offset:0,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:q-4,offset:8,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}createShader(t,e){const r=this.gl,i=super.createShader(t,e);return i.use(),i.bindVAO(),this.vertexBuffer.bindBuffer(),i.setAttributes([{name:"aPosition",size:2,type:r.FLOAT,stride:q,offset:0,divisor:0},{name:"aColor",size:4,type:r.UNSIGNED_BYTE,normalized:!0,stride:q,offset:8,divisor:0},{name:"aUV",size:2,type:r.FLOAT,stride:q,offset:12,divisor:0}]),i.unbindVAO(),this.currentShader&&this.currentShader.use(),i}startGraphic(t,e=this.gl.TRIANGLES,r){this.vertexBuffer.clear(),this.vertexCount=0,this.matrixIndex=t,this.drawMode=e,this.texture=r,this.texture?.glTexture&&this.useTexture(this.texture.glTexture,0,0)}addVertex(t,e,r=0,i=0,s=4294967295){const a=this.vertexBuffer;a.pushFloat32(t),a.pushFloat32(e),this.currentShader!=this.maskShader&&a.pushUint32(s),a.pushFloat32(r),a.pushFloat32(i),this.vertexCount++,this.vertexBuffer.makeDirty()}endGraphic(){this.flush()}render(){if(this.vertexCount===0)return;this.prepareRender();const t=this.gl,e=this.currentShader,r=this.matrixIndex*6,i=this.matrixStore.data;let s=i[r+4],a=i[r+5];this.rapid.roundPixels&&(s=Math.round(s),a=Math.round(a)),e.setUniform("uMatrixRow0",[i[r],i[r+2],s]),e.setUniform("uMatrixRow1",[i[r+1],i[r+3],a]),e.setUniform("uUVRect",this.texture?[this.texture.uvX,this.texture.uvY,this.texture.uvW,this.texture.uvH]:[0,0,1,1]),this.texture?.glTexture?(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.texture.glTexture),e.setUniform("uTexture",0),e.setUniform("uUseTexture",1)):e.setUniform("uUseTexture",0),this.vertexBuffer.bindBuffer(),this.vertexBuffer.bufferData(),e.bindVAO(),t.drawArrays(this.drawMode,0,this.vertexCount),this.rapid.drawcallCount++,this.texture=void 0}hasPendingContent(){return!1}}class p{x;y;static ZERO=new p(0,0);static ONE=new p(1,1);static UP=new p(0,1);static DOWN=new p(0,-1);static LEFT=new p(-1,0);static RIGHT=new p(1,0);constructor(t,e){this.x=t!==void 0?t:0,this.y=e!==void 0?e:0}set(t,e){return e===void 0?(this.x=t,this.y=t):(this.x=t,this.y=e),this}add(t){return new p(this.x+t.x,this.y+t.y)}subtract(t){return new p(this.x-t.x,this.y-t.y)}sub(t){return new p(this.x-t.x,this.y-t.y)}multiply(t){return t instanceof p?new p(this.x*t.x,this.y*t.y):new p(this.x*t,this.y*t)}mul(t){return this.multiply(t)}divide(t){return t instanceof p?new p(this.x/t.x,this.y/t.y):new p(this.x/t,this.y/t)}dot(t){return this.x*t.x+this.y*t.y}cross(t){return this.x*t.y-this.y*t.x}distanceTo(t){const e=this.x-t.x,r=this.y-t.y;return Math.sqrt(e*e+r*r)}clone(){return new p(this.x,this.y)}to(t){this.x=t.x,this.y=t.y}copy(){return new p(this.x,this.y)}equals(t){return t.x==this.x&&t.y==this.y}perpendicular(){const t=this.x;return this.x=-this.y,this.y=t,this}invert(){return this.x=-this.x,this.y=-this.y,this}inverted(){return new p(this.x*-1,this.y*-1)}length(){return Math.sqrt(this.x*this.x+this.y*this.y)}squaredLength(){return this.x*this.x+this.y*this.y}normalize(){const t=this.length();return this.x=this.x/t||0,this.y=this.y/t||0,this}normalized(){const t=this.length();return new p(this.x/t||0,this.y/t||0)}fix(t=1e-13){this.x=Math.abs(this.x)<t?0:this.x,this.y=Math.abs(this.y)<t?0:this.y}fixed(t=1e-13){return new p(Math.abs(this.x)<t?0:this.x,Math.abs(this.y)<t?0:this.y)}angle(){return Math.atan2(this.y,this.x)}abs(){return new p(Math.abs(this.x),Math.abs(this.y))}floor(){return new p(Math.floor(this.x),Math.floor(this.y))}ceil(){return new p(Math.ceil(this.x),Math.ceil(this.y))}stringify(){return`Vec2(${this.x}, ${this.y})`}clear(){this.x=0,this.y=0}isPrettyMuchZero(){return Math.abs(this.x)<1e-4&&Math.abs(this.y)<1e-4}isZero(){return this.x==0&&this.y==0}isNotZero(){return this.x!==0||this.y!==0}setToPolar(t,e=1){return this.x=Math.cos(t)*e,this.y=Math.sin(t)*e,this}static FromArray(t){return t.map(e=>new p(e[0],e[1]))}static fromAngle(t){return new p(Math.cos(t),Math.sin(t))}}const St=(n,t)=>{const[e,r,i,s,a,o]=t,h=new Float32Array([e,i,0,0,r,s,0,0,0,0,1,0,a,o,0,1]);return At(h,n)},At=(n,t)=>{const e=new Float32Array(16);for(let r=0;r<4;r++)for(let i=0;i<4;i++){let s=0;for(let a=0;a<4;a++)s+=n[i*4+a]*t[a*4+r];e[i*4+r]=s}return e};var bt=(n=>(n[n.STRETCH=0]="STRETCH",n[n.REPEAT=1]="REPEAT",n))(bt||{});const dt=10,Ut=(n,t,e,r,i,s)=>{const a=[],o=[],h=r?Math.atan2(t.y,t.x):Math.atan2(-t.y,-t.x),c=Math.PI,u=new p(t.y,-t.x);for(let l=0;l<dt;l++){const d=l/dt,f=(l+1)/dt,x=h+d*c,y=h+f*c,T=new p(Math.cos(x)*e,Math.sin(x)*e),R=new p(Math.cos(y)*e,Math.sin(y)*e);a.push(n),o.push(new p(i,.5)),a.push(n.add(T)),o.push(new p(i+T.dot(u)*s,.5-.5*T.dot(t)/e)),a.push(n.add(R)),o.push(new p(i+R.dot(u)*s,.5-.5*R.dot(t)/e))}return{vertices:a,uv:o}},oe=(n,t=!1)=>{const e=[];if(n.length<2||t&&n.length<3)return{normals:e,length:0};const r=4,i=.001,s=n.length;let a=0;if(t)for(let h=0;h<s;h++){const c=n[h],u=n[(h+1)%s];a+=c.distanceTo(u)}else for(let h=0;h<s-1;h++)a+=n[h].distanceTo(n[h+1]);const o=(h,c,u)=>{const l=c.subtract(h).normalize(),d=c.subtract(u).normalize(),f=d.dot(l);if(f<-1+i)return{normal:l.perpendicular(),miters:1};{let x=d.add(l).normalize();l.cross(d)<0&&(x=x.multiply(-1));let y=1/Math.sqrt((1-f)/2);return{normal:x,miters:Math.min(y,r)}}};if(t)for(let h=0;h<s;h++){const c=h===0?n[s-1]:n[h-1],u=n[h],l=h===s-1?n[0]:n[h+1];e.push(o(c,u,l))}else for(let h=0;h<s;h++)if(h===0){const c=n[1].subtract(n[0]).normalize();e.push({normal:c.perpendicular(),miters:1})}else if(h===s-1){const c=n[h].subtract(n[h-1]).normalize();e.push({normal:c.perpendicular(),miters:1})}else e.push(o(n[h-1],n[h],n[h+1]));return{normals:e,length:a}},ce=n=>{const t=n.points;if(t.length<2)return{vertices:[],uv:[]};const{normals:e,length:r}=oe(t,n.closed),i=(n.width||1)/2,s=[],a=[],o=n.roundCap||!1,h=n.textureMode||0;let c=0;const u=n.texture?.rawWidth||1,l=n.closed?t.length:t.length-1;for(let d=0;d<l;d++){const f=t[d],x=e[d].normal,y=e[d].miters,T=(d+1)%t.length,R=t[T],S=e[T].normal,b=e[T].miters,N=f.add(x.multiply(y*i)),P=f.subtract(x.multiply(y*i)),W=R.add(S.multiply(b*i)),B=R.subtract(S.multiply(b*i)),L=f.distanceTo(R);let A=0,_=0;h===0?(A=c/r,_=(c+L)/r):(A=c/u,_=A+L/u);const $=new p(A,0),G=new p(A,1),H=new p(_,0),F=new p(_,1);s.push(N),a.push($),s.push(P),a.push(G),s.push(W),a.push(H),s.push(W),a.push(H),s.push(B),a.push(F),s.push(P),a.push(G),c+=L}if(o&&!n.closed){const d=t[0],f=e[0].normal,x=h===0?r>0?1/r:0:1/u,y=Ut(d,f,i,!0,0,x);s.push(...y.vertices),a.push(...y.uv);const T=t[t.length-1],R=e[t.length-1].normal,S=h===0?1:c/u,b=h===0?r>0?1/r:0:1/u,N=Ut(T,R,i,!1,S,b);s.push(...N.vertices),a.push(...N.uv)}return{vertices:s,uv:a}},Q=(n,t,e,r)=>{if(t.customMatrix!==void 0)return t.customMatrix;if(t.modifyStack){n.matrixStack.applyTransform(t,e,r);return}else{const i=n.matrix.temporary;return n.matrixStack.applyTransform(t,e,r,i),i}},Ct=(n,t)=>t?n?t.premultipliedUint32:t.uint32:4294967295,ue=2,_t=(n,t)=>{const e=Q(n,t,t.texture.rawWidth,t.texture.rawHeight),r=t.texture;if(!r?.base||n.inCreateMask)return;const i=r.isAtlas?n.atlasSpriteRegion:n.spriteRegion;n.enterRegion(i,t.shader);let s=r.uvX,a=r.uvY,o=r.uvW,h=r.uvH;const c=!!t.flipX,u=!!t.flipY!=!!r.flipY;let l=t.padding??i.currentShader.padding;r.isAtlas&&(l+=ue);const d=s<=o?l:-l,f=a<=h?l:-l;i.drawSprite(r,e??t.customMatrix??n.matrixStack.curWorldM,s,a,o,h,n.getColorUint32(t.color),d,f,c,u,r.isRotated)},Pt=(n,t)=>{const e=n.particleRegion;n.enterRegion(e,t.shader);const r=t.texture,i=t.count??t.x.length,s=t.color;e.drawParticles(r,t.x,t.y,t.rotation,s,i,t.scaleX,t.scaleY,t.u0??r.uvX,t.v0??r.uvY,t.u1??r.uvW,t.v1??r.uvH,t.flipX,t.flipY,r.isRotated,t.originX,t.originY,n.premultipliedAlpha,t.reverseOrder,t.customMatrix)},ft=(n,t)=>{if(t.points.length===0)return;const e=Q(n,t,0,0);n.startGraphic(t.drawMode??n.gl.TRIANGLES,t.texture,t.shader,e??t.customMatrix);for(let r=0;r<t.points.length;r++){const i=t.points[r],s=t.uv?.[r],a=Array.isArray(t.color)?t.color[r]:t.color;n.addGraphicVertex(i.x,i.y,s?.x??0,s?.y??0,n.getColorUint32(a))}n.endGraphic()},Nt=(n,t)=>{if(n.inCreateMask)return;const{vertices:e,uv:r}=ce(t);ft(n,{...t,points:e,uv:r,drawMode:n.gl.TRIANGLES})},Lt=(n,t)=>{const e=Q(n,t,t.texture.rawWidth,t.texture.rawHeight);n.startMaskGraphic(n.gl.TRIANGLE_FAN,t.texture,e??t.customMatrix),n.addRectVertex(t.texture.rawWidth,t.texture.rawHeight),n.endGraphic()},It=(n,t)=>{const e=Q(n,t,t.width,t.height);n.startGraphic(n.gl.TRIANGLE_FAN,t.texture,t.shader,e??t.customMatrix),n.addRectVertex(t.width,t.height,t.color),n.endGraphic()},Ot=(n,t)=>{const e=t.segments??32,r=Q(n,t,0,0);n.startGraphic(n.gl.TRIANGLE_FAN,void 0,t.shader,r??t.customMatrix);const i=n.getColorUint32(t.color);n.addGraphicVertex(0,0,.5,.5,i),n.addCircleVertex(t.radius,t.color,e),n.addGraphicVertex(t.radius,0,1,.5,i),n.endGraphic()},Ft=`#version 300 es\r
220
220
  precision mediump float;\r
221
221
  \r
222
222
  uniform sampler2D uTextures[%TEXTURE_NUM%];\r
@@ -265,7 +265,7 @@ void main(void) {\r
265
265
  \r
266
266
  // CUSTOM_CODE_CALL\r
267
267
  }\r
268
- `;class he extends rt{KEY="AtlasSprite";constructor(t){super(t)}createCustomShader(t){const e=H(It,this.rapid.maxTextureUnits-t.usedTextureUnitNum),r=H(et,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,r,e)}createDefaultShader(){const t=this.rapid,e=H(It,t.maxTextureUnits),r=H(et,t.maxTextureUnits);return this.vs=r,this.fs=e,this.defaultShader=this.createShader(r,e),this.defaultShader}}const Ot=`#version 300 es\r
268
+ `;class le extends it{KEY="AtlasSprite";constructor(t){super(t)}createCustomShader(t){const e=z(Ft,this.rapid.maxTextureUnits-t.usedTextureUnitNum),r=z(rt,this.rapid.maxTextureUnits-t.usedTextureUnitNum);return t.getGLShader(this,this.KEY,r,e)}createDefaultShader(){const t=this.rapid,e=z(Ft,t.maxTextureUnits),r=z(rt,t.maxTextureUnits);return this.vs=r,this.fs=e,this.defaultShader=this.createShader(r,e),this.defaultShader}}const Wt=`#version 300 es\r
269
269
  precision highp float;\r
270
270
  \r
271
271
  // per-vertex\r
@@ -306,7 +306,7 @@ void main(void) {\r
306
306
  \r
307
307
  gl_Position = u_projection * vec4(v, 0.0, 1.0);\r
308
308
  }\r
309
- `,Ft=`#version 300 es\r
309
+ `,Bt=`#version 300 es\r
310
310
  precision mediump float;\r
311
311
  \r
312
312
  uniform sampler2D uTexture;\r
@@ -322,4 +322,4 @@ void main(void) {\r
322
322
  \r
323
323
  // CUSTOM_CODE_CALL\r
324
324
  }\r
325
- `,X=48,Wt=X/4;class oe extends rt{KEY="ParticleSprite";texture;customMatrix;constructor(t){super(t)}createCustomShader(t){return t.getGLShader(this,this.KEY,Ot,Ft)}createDefaultShader(){const t=Ft,e=Ot;return this.vs=e,this.fs=t,this.defaultShader=this.createShader(e,t),this.defaultShader}enter(t){super.enter(t),this.currentShader.setUniform("u_projection",this.rapid.projection)}createShader(t,e){const r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,stride:X,offset:0,divisor:1},{name:"aScale",size:2,stride:X,offset:8,divisor:1},{name:"aRotation",size:1,stride:X,offset:16,divisor:1},{name:"aUVRect",size:4,stride:X,offset:20,divisor:1},{name:"aColor",size:4,type:at,normalized:!0,stride:X,offset:36,divisor:1},{name:"aOrigin",size:2,stride:X,offset:40,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}drawParticles(t,e,r,i=0,s=4294967295,a,o=1,h=1,c=0,u=0,l=1,d=1,f=!1,x=!1,v=!1,y=.5,T=.5,w,b=!1,N){if(!t.glTexture||a<=0)return;let _=0;const D=typeof o=="number",k=typeof h=="number",L=typeof i=="number",S=typeof s=="number",P=!S&&typeof s[0]=="number";let V=t.rawWidth*(f?-1:1);D&&(V*=o);let Y=t.rawHeight*(x?-1:1);k&&(Y*=h);let z=v?Math.PI/2:0;for(L&&(z+=i);_<a;){this.texture&&t!==this.texture&&this.flush(),this.texture||(this.texture=t,this.useTexture(t.glTexture,0,0));const W=a-_,B=this.instanceBuffer;let U=B.usedElemNum;B.resize(W*Wt);const I=B.float32,R=B.uint32;for(let A=0;A<W;A++){const j=b?a-1-_-A:_+A;if(I[U]=e[j],I[U+1]=r[j],I[U+2]=D?V:V*o[j],I[U+3]=k?Y:Y*h[j],I[U+4]=L?z:i[j]+z,I[U+5]=c,I[U+6]=u,I[U+7]=l,I[U+8]=d,S)R[U+9]=4294967295;else if(P)R[U+9]=s[j];else{const zt=s[j];R[U+9]=w?zt.premultipliedUint32:zt.uint32}I[U+10]=y,I[U+11]=T,U+=Wt}B.usedElemNum=U,B.makeDirty(),this.instanceCount+=W,_+=W}this.customMatrix=N,this.flush()}render(){if(this.instanceCount===0)return;this.prepareRender();const t=this.gl;this.texture&&(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.texture.glTexture));const e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO();const r=this.rapid.matrixStack,s=this.rapid.matrix.getMatrix(this.customMatrix??r.curWorldM),a=Mt(this.rapid.projection,s);this.currentShader.setUniform("u_projection",a),yt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++,this.texture=void 0,this.customMatrix=void 0}}var Bt=(n=>(n[n.EQUAL=0]="EQUAL",n[n.NOT_EQUAL=1]="NOT_EQUAL",n))(Bt||{}),Dt=(n=>(n[n.NORMAL=0]="NORMAL",n[n.ADD=1]="ADD",n[n.MULTIPLY=2]="MULTIPLY",n[n.SCREEN=3]="SCREEN",n[n.ERASE=4]="ERASE",n))(Dt||{}),it=(n=>(n[n.LINEAR=0]="LINEAR",n[n.NEAREST=1]="NEAREST",n))(it||{}),kt=(n=>(n[n.CanvasItem=0]="CanvasItem",n[n.Viewport=1]="Viewport",n))(kt||{});class ce{gl;canvas;projection=new Float32Array(16);projectionDirty=!0;dpr;backgroundColor=m.Black;logicWidth=0;logicHeight=0;physicsWidth=0;physicsHeight=0;currentRegion=null;maxTextureUnits=0;matrixStack=new mt(this);matrix;spriteRegion;graphicRegion;atlasSpriteRegion;particleRegion;drawcallCount=0;inCreateMask=!1;texture;premultipliedAlpha;antialias;roundPixels;textureFilter;scaleMode;_filterRT=[null,null];_filterInput=new O;get height(){return this.logicHeight}get width(){return this.logicWidth}constructor(t){this.canvas=t.canvas,this.dpr=window.devicePixelRatio||1,this.antialias=t.antialias??!1,this.textureFilter=t.textureFilter??1,this.premultipliedAlpha=t.premultipliedAlpha??!0,this.roundPixels=t.roundPixels??!1,this.scaleMode=t.scaleMode??0;const e=jt(this.canvas,this.antialias,this.premultipliedAlpha);this.gl=e,this.maxTextureUnits=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.matrix=this.matrixStack.matrix,this.spriteRegion=new rt(this),this.graphicRegion=new Et(this),this.atlasSpriteRegion=new he(this),this.particleRegion=new oe(this);const r=this.canvas.clientWidth||this.canvas.width,i=this.canvas.clientHeight||this.canvas.height;this.physicsWidth=t.physicsWidth||Math.round(r*this.dpr),this.physicsHeight=t.physicsHeight||Math.round(i*this.dpr),this.logicWidth=t.logicWidth||t.width||this.physicsWidth/this.dpr,this.logicHeight=t.logicHeight||t.height||this.physicsHeight/this.dpr,this.resize(this.logicWidth,this.logicHeight,this.physicsWidth,this.physicsHeight),this.texture=new xt(this),t.backgroundColor&&(this.backgroundColor=t.backgroundColor),e.enable(e.BLEND),this.premultipliedAlpha?e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.enable(e.STENCIL_TEST),e.stencilFunc(e.ALWAYS,1,255),e.stencilOp(e.KEEP,e.KEEP,e.KEEP)}setTextureFilter(t){this.textureFilter=t}setAntialias(t){this.antialias=t}getColorUint32(t){return bt(this.premultipliedAlpha,t)}enterRegion(t,e){this.currentRegion===t&&this.currentRegion.isSameShader(e)||(this.flush(),this.currentRegion=t,t.enter(e))}drawParticles(t){Ct(this,t)}drawSprite(t){Ut(this,t)}drawLine(t){_t(this,t)}drawGraphic(t){lt(this,t)}drawRect(t){Nt(this,t)}drawCircle(t){Lt(this,t)}startGraphic(t=this.gl.TRIANGLES,e,r,i){this.enterRegion(this.graphicRegion,r),this.graphicRegion.startGraphic(i??this.matrixStack.curWorldM,t,e)}startMaskGraphic(t=this.gl.TRIANGLES,e,r){this.startGraphic(t,e,this.graphicRegion.maskShader,r)}drawMaskImage(t){Pt(this,t)}addRectVertex(t,e,r){const i=this.getColorUint32(r);this.addGraphicVertex(0,0,0,0,i),this.addGraphicVertex(t,0,1,0,i),this.addGraphicVertex(t,e,1,1,i),this.addGraphicVertex(0,e,0,1,i)}addCircleVertex(t,e,r=32){const i=Math.PI*2/r,s=this.getColorUint32(e);for(let a=0;a<r;a++){const o=i*a,h=Math.cos(o)*t,c=Math.sin(o)*t,u=.5+Math.cos(o)*.5,l=.5+Math.sin(o)*.5;this.addGraphicVertex(h,c,u,l,s)}}addGraphicVertex(t,e,r=0,i=0,s){this.graphicRegion.addVertex(t,e,r,i,typeof s=="number"?s:this.getColorUint32(s))}endGraphic(){this.graphicRegion.endGraphic()}resize(t,e,r,i){this.flush();const s=r??this.canvas.clientWidth??this.canvas.width,a=i??this.canvas.clientHeight??this.canvas.height;switch(r!==void 0&&(this.canvas.style.width=s+"px"),i!==void 0&&(this.canvas.style.height=a+"px"),this.physicsWidth=s*this.dpr,this.physicsHeight=a*this.dpr,this.logicWidth=t,this.logicHeight=e,this.scaleMode){case 1:this.canvas.width=t,this.canvas.height=e,this.canvas.style.imageRendering="pixelated",this.gl.viewport(0,0,t,e);break;case 0:this.canvas.width=this.physicsWidth,this.canvas.height=this.physicsHeight,this.canvas.style.imageRendering="auto",this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight);break;default:throw new Error("scaleMode can only be CanvasScaleMode.Viewport or CanvasScaleMode.CanvasItem")}this.updateProjection(0,this.logicWidth,this.logicHeight,0)}updateProjection(t,e,r,i){this.updateOrthMatrix(this.projection,t,e,r,i),this.projectionDirty=!0}clear(){const t=this.gl;this.backgroundColor.setClearColor(t),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT),this.drawcallCount=0,this.matrixStack.reset()}updateOrthMatrix(t,e,r,i,s){t[0]=2/(r-e),t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2/(s-i),t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=-(r+e)/(r-e),t[13]=-(s+i)/(s-i),t[14]=0,t[15]=1}flush(){this.currentRegion&&(this.currentRegion.exit(),this.currentRegion=null)}applyFilters(t,e){if(e.length===0)throw new Error("applyFilters: shaders array must not be empty.");const r=Math.max(...e.map(c=>c.padding)),i=r,s=t.rawWidth+r*2,a=t.rawHeight+r*2;for(let c=0;c<2;c++)this._filterRT[c]?this._filterRT[c].resize(s,a):this._filterRT[c]=this.texture.createRenderTexture({width:s,height:a});let o=t.clone(this._filterInput),h=0;this.matrixStack.save(),this.matrixStack.identity();for(let c=0;c<e.length;c++){const u=this._filterRT[h%2];u.offsetX=0,u.offsetY=0,this.enterRenderTexture(u),this.clearRenderTexture(),this.drawSprite({texture:o,shader:e[c],offsetX:c==0?i:0,offsetY:c==0?i:0,padding:r}),this.leaveRenderTexture(),o=u,h++}return this.matrixStack.restore(),o.offsetX=-i,o.offsetY=-i,o}enterRenderTexture(t){this.flush(),t.activate(),this.gl.viewport(0,0,t.rawWidth,t.rawHeight),this.updateProjection(0,t.rawWidth,t.rawHeight,0)}clearRenderTexture(t=new m(0,0,0,0)){this.flush();const e=this.gl;t.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT)}leaveRenderTexture(){this.flush(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight),this.updateProjection(0,this.logicWidth,this.logicHeight,0)}drawToRenderTexture(t,e,r=new m(0,0,0,0)){this.enterRenderTexture(t);try{r!==null&&this.clearRenderTexture(r),e()}finally{this.leaveRenderTexture()}}withMask(t,e,r=0,i=1){this.clearMask(),this.startDrawMask(i);try{t()}finally{this.endDrawMask()}this.enterMask(r,i);try{e()}finally{this.exitMask()}}withTransform(t,e,r=0,i=0){this.matrixStack.save();try{e&&this.matrixStack.applyTransform(e,r,i),t()}finally{this.matrixStack.restore()}}withScissor(t,e,r,i,s){this.startScissor(t,e,r,i);try{s()}finally{this.endScissor()}}withBlendMode(t,e){this.setBlendMode(t);try{e()}finally{this.setBlendMode(0)}}startDrawMask(t=1,e=255){this.flush();const r=this.gl;r.stencilMask(e),r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.ALWAYS,t,e),r.stencilOp(r.KEEP,r.KEEP,r.REPLACE),this.enterRegion(this.graphicRegion,this.graphicRegion.maskShader),this.inCreateMask=!0}endDrawMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(0),this.inCreateMask=!1}clearMask(t=255){this.flush();const e=this.gl;e.stencilMask(t),e.clear(e.STENCIL_BUFFER_BIT),this.inCreateMask=!1}enterMask(t,e=1,r=255){this.flush();const i=this.gl;i.colorMask(!0,!0,!0,!0),i.stencilMask(0),i.stencilFunc(t===0?i.EQUAL:i.NOTEQUAL,e,r),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),this.inCreateMask=!1}exitMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(255),t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),this.inCreateMask=!1}setBlendMode(t){this.flush();const e=this.gl;switch(t){case 0:this.premultipliedAlpha?e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 1:e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,e.ONE);break;case 2:e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 3:e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_COLOR,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 4:e.blendFuncSeparate(e.ZERO,e.ONE_MINUS_SRC_ALPHA,e.ZERO,e.ONE_MINUS_SRC_ALPHA);break}}startScissor(t,e,r,i){this.flush();const s=this.gl,a=this.physicsWidth/this.logicWidth,o=this.physicsHeight/this.logicHeight,h=Math.round(t*a),c=Math.round(this.physicsHeight-(e+i)*o),u=Math.round(r*a),l=Math.round(i*o);s.enable(s.SCISSOR_TEST),s.scissor(h,c,u,l)}endScissor(){this.flush(),this.gl.disable(this.gl.SCISSOR_TEST)}renderCamera(t){this.matrixStack.applyTransform(t);const e=this.matrixStack.curWorldM;this.matrix.invert(e)}logicToPhysics(t){return t.multiply(new p(this.physicsWidth/this.logicWidth,this.physicsHeight/this.logicHeight))}physicsToLogic(t){return t.multiply(new p(this.logicWidth/this.physicsWidth,this.logicHeight/this.physicsHeight))}cssToDevicePixel(t){return t.mul(this.dpr)}cssToLogic(t){const e=this.cssToDevicePixel(t);return this.physicsToLogic(e)}devicePixelToCss(t){return t.divide(this.dpr)}toCSSMatrix(t){const e=this.physicsWidth/this.dpr/this.logicWidth,r=this.physicsHeight/this.dpr/this.logicHeight;return this.matrix.toCSSMatrix(t??this.matrixStack.curWorldM,e,r)}}function ue(n){return!(n===null||typeof n!="object"||Array.isArray(n)||n instanceof p||n instanceof m)}class F{static float(t,e){return Math.random()*(e-t)+t}static int(t,e){return Math.floor(Math.random()*(e-t+1))+t}static angle(){return Math.random()*Math.PI*2}static vector(t,e,r,i){return new p(F.float(t,e),F.float(r,i))}static randomColor(t,e){return new m(F.float(t.r,e.r),F.float(t.g,e.g),F.float(t.b,e.b),F.float(t.a,e.a))}static pick(t){return t[F.int(0,t.length-1)]}static pickWeight(t){if(!t||t.length===0)return null;let e=0;for(const[,i]of t)e+=i;let r=Math.random()*e;for(const[i,s]of t)if(r-=s,r<=0)return i;return t[t.length-1][0]}static scalarOrRange(t,e){if(t==null)return e;if(Array.isArray(t)){const[r,i]=t;if(typeof r=="number")return F.float(r,i);if(r instanceof p)return F.vector(r.x,i.x,r.y,i.y);if(r instanceof m)return F.randomColor(r,i)}return typeof t=="number"?t:t.clone()}}var Gt=(n=>(n.POINT="point",n.CIRCLE="circle",n.RECT="rect",n))(Gt||{});const Ht=10,Vt=0,Yt=!0;class Z{components;constructor(t=1){if(!Number.isInteger(t)||t<=0)throw new RangeError("ParticleAttributeStore size must be a positive integer");this.components=Array.from({length:t},()=>({value:new C(M.Float32),delta:new C(M.Float32),damping:new C(M.Float32)}))}getArrayBuffer(){return this.components.flatMap(({value:t,delta:e,damping:r})=>[t,e,r])}update(t){for(const{value:e,delta:r,damping:i}of this.components)for(let s=0;s<e.usedElemNum;s++)e.typedArray[s]*=Math.pow(i.get(s),t),e.typedArray[s]+=r.get(s)*t}get(t,e=0){return this.components[e].value.get(t)}getComponent(t,e){if(typeof t=="number")return t;if(t instanceof p)return e===0?t.x:t.y;switch(e){case 0:return t.r;case 1:return t.g;case 2:return t.b;case 3:return t.a;default:return 0}}resolveComponent(t,e,r){return t===void 0?r:Array.isArray(t)?F.float(this.getComponent(t[0],e),this.getComponent(t[1],e)):this.getComponent(t,e)}create(t,e,r=1){const i=ue(t)?t:void 0,s=i===void 0?t:void 0,a=r>0?r:1;let o=0;for(let h=0;h<this.components.length;h++){const{value:c,delta:u,damping:l}=this.components[h],d=this.getComponent(e,h),f=s===void 0?this.resolveComponent(i?.start,h,d):this.getComponent(s,h),x=i?.end===void 0?f:this.resolveComponent(i.end,h,d);c.push(f),u.push(i?.delta===void 0?(x-f)/a:this.getComponent(i.delta,h)),l.push(i?.damping??1),h===0&&(o=f)}return o}}class dt{options;emitting=!1;emitTimer=0;emitRate=Ht;emitTime=Vt;emitTimeCounter=0;localSpace=Yt;rapid;x=new C(M.Float32);y=new C(M.Float32);scaleX=new C(M.Float32);scaleY=new C(M.Float32);rotation=new C(M.Float32);color=new C(M.Uint32);animations={speed:new Z,rotation:new Z,scale:new Z,color:new Z(4),velocity:new Z(2)};count=0;constructor(t,e){this.rapid=t,this.options=e,this.emitRate=e.emitRate??Ht,this.emitTime=e.emitTime??Vt,this.localSpace=e.localSpace??Yt}getAllArrayBuffer(){return[this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.color,...Object.values(this.animations).flatMap(t=>t.getArrayBuffer())]}setTexture(t){this.options.texture=t}clone(){return new dt(this.rapid,{...this.options})}setEmitRate(t){this.emitRate=t}setEmitTime(t){this.emitTime=t}start(){this.emitting=!0,this.emitTimeCounter=0}stop(){this.emitting=!1}clear(){for(const t of this.getAllArrayBuffer())t.clear();this.count=0,this.emitTimeCounter=0}emit(t){const e=this.options.maxParticles??1/0,r=Math.min(t,e-this.count);for(let i=0;i<r;i++)this.createParticle()}createParticle(){const t=F.scalarOrRange(this.options.life,1);let e=0,r=0;switch(this.options.emitShape){case"circle":{const c=Math.random()*Math.PI*2,u=(this.options.emitRadius??0)*Math.sqrt(Math.random());e=Math.cos(c)*u,r=Math.sin(c)*u;break}case"rect":{e=(Math.random()-.5)*(this.options.emitRect?.width??0),r=(Math.random()-.5)*(this.options.emitRect?.height??0);break}}const i=this.rapid.matrixStack;if(this.localSpace)this.x.push(e),this.y.push(r);else{const{x:c,y:u}=i.localToWorld(e,r);this.x.push(c),this.y.push(u)}const s=this.options.animation,a=this.animations,o=a.scale.create(s.scale,1,t),h=a.rotation.create(s.rotation,0,t);a.speed.create(s.speed,0,t),a.velocity.create(s.velocity,p.ZERO,t),a.color.create(s.color,m.White,t),this.rotation.push(h),this.scaleX.push(o),this.scaleY.push(o),this.color.pushUint32(m.packColor(a.color.get(this.count,0),a.color.get(this.count,1),a.color.get(this.count,2),a.color.get(this.count,3),this.rapid.premultipliedAlpha)),this.count+=1}update(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0){if(this.emitTimeCounter+=t,this.emitTimeCounter>=this.emitTime){const r=Math.floor(this.emitTimeCounter/this.emitTime);this.emit(this.emitRate*r),this.emitTimeCounter-=r*this.emitTime}}else{this.emitTimer+=t;const r=Math.floor(this.emitTimer*this.emitRate);r>0&&(this.emit(r),this.emitTimer-=r/this.emitRate)}const e=this.updateParticle(t);this.count-=e.length,C.removeAtIndices(e,this.getAllArrayBuffer())}updateParticle(t){const e=[],r=this.animations;Object.values(r).forEach(i=>i.update(t));for(let i=0;i<this.count;i++){const s=r.rotation.get(i),a=r.scale.get(i),o=r.speed.get(i);this.rotation.typedArray[i]=s,this.scaleX.typedArray[i]=a,this.scaleY.typedArray[i]=a,this.color.uint32[i]=m.packColor(r.color.get(i,0),r.color.get(i,1),r.color.get(i,2),r.color.get(i,3),this.rapid.premultipliedAlpha),this.x.typedArray[i]+=(o*Math.cos(s)+r.velocity.get(i,0))*t,this.y.typedArray[i]+=(o*Math.sin(s)+r.velocity.get(i,1))*t}return e}render(){const t=this.options,e=this.localSpace?void 0:this.rapid.matrix.alloc();this.rapid.drawParticles({texture:t.texture,shader:t.shader,x:this.x.typedArray,y:this.y.typedArray,scaleX:this.scaleX.typedArray,scaleY:this.scaleY.typedArray,rotation:this.rotation.typedArray,color:this.color.typedArray,count:this.count,reverseOrder:!0,originX:t.origin?.x??.5,originY:t.origin?.y??.5,customMatrix:e})}isActive(){return this.emitting||this.count>0}oneShot(){this.emit(this.emitRate)}}g.ArrayType=M,g.BaseTexture=G,g.BlendMode=Dt,g.CanvasScaleMode=kt,g.Color=m,g.CustomGlShader=ot,g.DynamicArrayBuffer=C,g.GLShader=ht,g.GraphicRegion=Et,g.LineTextureMode=St,g.MaskType=Bt,g.MatrixStack=mt,g.MatrixStore=ft,g.ParticleEmitter=dt,g.ParticleShape=Gt,g.QUAD_VERTICES=Rt,g.Rapid=ce,g.Region=ct,g.RenderTexture=pt,g.SpriteRegion=rt,g.TextTexture=gt,g.Texture=O,g.TextureFilterMode=it,g.TextureManager=xt,g.TextureWrapMode=$,g.Vec2=p,g.WebglBufferArray=J,g.composeProjectionWithAffine=Mt,g.drawCircle=Lt,g.drawGraphic=lt,g.drawLine=_t,g.drawMaskImage=Pt,g.drawParticles=Ct,g.drawRect=Nt,g.drawSprite=Ut,g.getColorUint32=bt,g.multiplyMat4=wt,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
325
+ `,X=48,Dt=X/4;class de extends it{KEY="ParticleSprite";texture;customMatrix;constructor(t){super(t)}createCustomShader(t){return t.getGLShader(this,this.KEY,Wt,Bt)}createDefaultShader(){const t=Bt,e=Wt;return this.vs=e,this.fs=t,this.defaultShader=this.createShader(e,t),this.defaultShader}enter(t){super.enter(t),this.currentShader.setUniform("u_projection",this.rapid.projection)}createShader(t,e){const r=super.createShader(t,e);return r.use(),r.bindVAO(),this.instanceBuffer.bindBuffer(),r.setAttributes([{name:"aPosition",size:2,stride:X,offset:0,divisor:1},{name:"aScale",size:2,stride:X,offset:8,divisor:1},{name:"aRotation",size:1,stride:X,offset:16,divisor:1},{name:"aUVRect",size:4,stride:X,offset:20,divisor:1},{name:"aColor",size:4,type:ot,normalized:!0,stride:X,offset:36,divisor:1},{name:"aOrigin",size:2,stride:X,offset:40,divisor:1}]),this.quadBuffer.bindBuffer(),r.setAttributes([{name:"aVertex",size:2,stride:8,offset:0,divisor:0}]),r.unbindVAO(),this.currentShader&&this.currentShader.use(),r}drawParticles(t,e,r,i=0,s=4294967295,a,o=1,h=1,c=0,u=0,l=1,d=1,f=!1,x=!1,y=!1,T=.5,R=.5,S,b=!1,N){if(!t.glTexture||a<=0)return;let P=0;const W=typeof o=="number",B=typeof h=="number",L=typeof i=="number",A=typeof s=="number",_=typeof c=="number",$=!A&&typeof s[0]=="number";let G=t.rawWidth*(f?-1:1);W&&(G*=o);let H=t.rawHeight*(x?-1:1);B&&(H*=h),_&&(H*=d-u,G*=l-c);let F=y?Math.PI/2:0;for(L&&(F+=i);P<a;){this.texture&&t!==this.texture&&this.flush(),this.texture||(this.texture=t,this.useTexture(t.glTexture,0,0));const D=a-P,V=this.instanceBuffer;let M=V.usedElemNum;V.resize(D*Dt);const v=V.float32,U=V.uint32;for(let nt=0;nt<D;nt++){const k=b?a-1-P-nt:P+nt;if(v[M]=e[k],v[M+1]=r[k],v[M+2]=W?G:G*o[k],v[M+3]=B?H:H*h[k],v[M+4]=L?F:i[k]+F,_)v[M+5]=c,v[M+6]=u,v[M+7]=l,v[M+8]=d;else{const J=c[k],jt=u[k],$t=l[k],Kt=d[k];v[M+5]=J,v[M+6]=jt,v[M+7]=$t,v[M+8]=Kt,v[M+2]*=Kt-jt,v[M+3]*=$t-J}if(A)U[M+9]=4294967295;else if($)U[M+9]=s[k];else{const J=s[k];U[M+9]=S?J.premultipliedUint32:J.uint32}v[M+10]=T,v[M+11]=R,M+=Dt}V.usedElemNum=M,V.makeDirty(),this.instanceCount+=D,P+=D}this.customMatrix=N,this.flush()}render(){if(this.instanceCount===0)return;this.prepareRender();const t=this.gl;this.texture&&(t.activeTexture(t.TEXTURE0),t.bindTexture(t.TEXTURE_2D,this.texture.glTexture));const e=this.currentShader;this.instanceBuffer.bindBuffer(),this.instanceBuffer.bufferData(),e.bindVAO();const r=this.rapid.matrixStack,s=this.rapid.matrix.getMatrix(this.customMatrix??r.curWorldM),a=St(this.rapid.projection,s);this.currentShader.setUniform("u_projection",a),Rt(t,t.TRIANGLE_STRIP,0,4,this.instanceCount),this.rapid.drawcallCount++,this.texture=void 0,this.customMatrix=void 0}}var kt=(n=>(n[n.EQUAL=0]="EQUAL",n[n.NOT_EQUAL=1]="NOT_EQUAL",n))(kt||{}),Gt=(n=>(n[n.NORMAL=0]="NORMAL",n[n.ADD=1]="ADD",n[n.MULTIPLY=2]="MULTIPLY",n[n.SCREEN=3]="SCREEN",n[n.ERASE=4]="ERASE",n))(Gt||{}),st=(n=>(n[n.LINEAR=0]="LINEAR",n[n.NEAREST=1]="NEAREST",n))(st||{}),Ht=(n=>(n[n.CanvasItem=0]="CanvasItem",n[n.Viewport=1]="Viewport",n))(Ht||{});class fe{gl;canvas;projection=new Float32Array(16);projectionDirty=!0;dpr;backgroundColor=m.Black;logicWidth=0;logicHeight=0;physicsWidth=0;physicsHeight=0;currentRegion=null;maxTextureUnits=0;matrixStack=new pt(this);matrix;spriteRegion;graphicRegion;atlasSpriteRegion;particleRegion;drawcallCount=0;inCreateMask=!1;texture;premultipliedAlpha;antialias;roundPixels;textureFilter;scaleMode;_filterRT=[null,null];_filterInput=new I;get height(){return this.logicHeight}get width(){return this.logicWidth}constructor(t){this.canvas=t.canvas,this.dpr=window.devicePixelRatio||1,this.antialias=t.antialias??!1,this.textureFilter=t.textureFilter??1,this.premultipliedAlpha=t.premultipliedAlpha??!0,this.roundPixels=t.roundPixels??!1,this.scaleMode=t.scaleMode??0;const e=Qt(this.canvas,this.antialias,this.premultipliedAlpha);this.gl=e,this.maxTextureUnits=e.getParameter(e.MAX_TEXTURE_IMAGE_UNITS),this.matrix=this.matrixStack.matrix,this.spriteRegion=new it(this),this.graphicRegion=new wt(this),this.atlasSpriteRegion=new le(this),this.particleRegion=new de(this);const r=this.canvas.clientWidth||this.canvas.width,i=this.canvas.clientHeight||this.canvas.height;this.physicsWidth=t.physicsWidth||Math.round(r*this.dpr),this.physicsHeight=t.physicsHeight||Math.round(i*this.dpr),this.logicWidth=t.logicWidth||t.width||this.physicsWidth/this.dpr,this.logicHeight=t.logicHeight||t.height||this.physicsHeight/this.dpr,this.resize(this.logicWidth,this.logicHeight,this.physicsWidth,this.physicsHeight),this.texture=new gt(this),t.backgroundColor&&(this.backgroundColor=t.backgroundColor),e.enable(e.BLEND),this.premultipliedAlpha?e.blendFunc(e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFunc(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA),e.enable(e.STENCIL_TEST),e.stencilFunc(e.ALWAYS,1,255),e.stencilOp(e.KEEP,e.KEEP,e.KEEP)}setTextureFilter(t){this.textureFilter=t}setAntialias(t){this.antialias=t}getColorUint32(t){return Ct(this.premultipliedAlpha,t)}enterRegion(t,e){this.currentRegion===t&&this.currentRegion.isSameShader(e)||(this.flush(),this.currentRegion=t,t.enter(e))}drawParticles(t){Pt(this,t)}drawSprite(t){_t(this,t)}drawLine(t){Nt(this,t)}drawGraphic(t){ft(this,t)}drawRect(t){It(this,t)}drawCircle(t){Ot(this,t)}startGraphic(t=this.gl.TRIANGLES,e,r,i){this.enterRegion(this.graphicRegion,r),this.graphicRegion.startGraphic(i??this.matrixStack.curWorldM,t,e)}startMaskGraphic(t=this.gl.TRIANGLES,e,r){this.startGraphic(t,e,this.graphicRegion.maskShader,r)}drawMaskImage(t){Lt(this,t)}addRectVertex(t,e,r){const i=this.getColorUint32(r);this.addGraphicVertex(0,0,0,0,i),this.addGraphicVertex(t,0,1,0,i),this.addGraphicVertex(t,e,1,1,i),this.addGraphicVertex(0,e,0,1,i)}addCircleVertex(t,e,r=32){const i=Math.PI*2/r,s=this.getColorUint32(e);for(let a=0;a<r;a++){const o=i*a,h=Math.cos(o)*t,c=Math.sin(o)*t,u=.5+Math.cos(o)*.5,l=.5+Math.sin(o)*.5;this.addGraphicVertex(h,c,u,l,s)}}addGraphicVertex(t,e,r=0,i=0,s){this.graphicRegion.addVertex(t,e,r,i,typeof s=="number"?s:this.getColorUint32(s))}endGraphic(){this.graphicRegion.endGraphic()}resize(t,e,r,i){this.flush();const s=r??this.canvas.clientWidth??this.canvas.width,a=i??this.canvas.clientHeight??this.canvas.height;switch(r!==void 0&&(this.canvas.style.width=s+"px"),i!==void 0&&(this.canvas.style.height=a+"px"),this.physicsWidth=s*this.dpr,this.physicsHeight=a*this.dpr,this.logicWidth=t,this.logicHeight=e,this.scaleMode){case 1:this.canvas.width=t,this.canvas.height=e,this.canvas.style.imageRendering="pixelated",this.gl.viewport(0,0,t,e);break;case 0:this.canvas.width=this.physicsWidth,this.canvas.height=this.physicsHeight,this.canvas.style.imageRendering="auto",this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight);break;default:throw new Error("scaleMode can only be CanvasScaleMode.Viewport or CanvasScaleMode.CanvasItem")}this.updateProjection(0,this.logicWidth,this.logicHeight,0)}updateProjection(t,e,r,i){this.updateOrthMatrix(this.projection,t,e,r,i),this.projectionDirty=!0}clear(){const t=this.gl;this.backgroundColor.setClearColor(t),t.clear(t.COLOR_BUFFER_BIT|t.STENCIL_BUFFER_BIT),this.drawcallCount=0,this.matrixStack.reset()}updateOrthMatrix(t,e,r,i,s){t[0]=2/(r-e),t[1]=0,t[2]=0,t[3]=0,t[4]=0,t[5]=2/(s-i),t[6]=0,t[7]=0,t[8]=0,t[9]=0,t[10]=-1,t[11]=0,t[12]=-(r+e)/(r-e),t[13]=-(s+i)/(s-i),t[14]=0,t[15]=1}flush(){this.currentRegion&&(this.currentRegion.exit(),this.currentRegion=null)}applyFilters(t,e){if(e.length===0)throw new Error("applyFilters: shaders array must not be empty.");const r=Math.max(...e.map(c=>c.padding)),i=r,s=t.rawWidth+r*2,a=t.rawHeight+r*2;for(let c=0;c<2;c++)this._filterRT[c]?this._filterRT[c].resize(s,a):this._filterRT[c]=this.texture.createRenderTexture({width:s,height:a});let o=t.clone(this._filterInput),h=0;this.matrixStack.save(),this.matrixStack.identity();for(let c=0;c<e.length;c++){const u=this._filterRT[h%2];u.offsetX=0,u.offsetY=0,this.enterRenderTexture(u),this.clearRenderTexture(),this.drawSprite({texture:o,shader:e[c],offsetX:c==0?i:0,offsetY:c==0?i:0,padding:r}),this.leaveRenderTexture(),o=u,h++}return this.matrixStack.restore(),o.offsetX=-i,o.offsetY=-i,o}enterRenderTexture(t){this.flush(),t.activate(),this.gl.viewport(0,0,t.rawWidth,t.rawHeight),this.updateProjection(0,t.rawWidth,t.rawHeight,0)}clearRenderTexture(t=new m(0,0,0,0)){this.flush();const e=this.gl;t.setClearColor(e),e.clear(e.COLOR_BUFFER_BIT)}leaveRenderTexture(){this.flush(),this.gl.bindFramebuffer(this.gl.FRAMEBUFFER,null),this.gl.viewport(0,0,this.physicsWidth,this.physicsHeight),this.updateProjection(0,this.logicWidth,this.logicHeight,0)}drawToRenderTexture(t,e,r=new m(0,0,0,0)){this.enterRenderTexture(t);try{r!==null&&this.clearRenderTexture(r),e()}finally{this.leaveRenderTexture()}}withMask(t,e,r=0,i=1){this.clearMask(),this.startDrawMask(i);try{t()}finally{this.endDrawMask()}this.enterMask(r,i);try{e()}finally{this.exitMask()}}withTransform(t,e,r=0,i=0){this.matrixStack.save();try{e&&this.matrixStack.applyTransform(e,r,i),t()}finally{this.matrixStack.restore()}}withScissor(t,e,r,i,s){this.startScissor(t,e,r,i);try{s()}finally{this.endScissor()}}withBlendMode(t,e){this.setBlendMode(t);try{e()}finally{this.setBlendMode(0)}}startDrawMask(t=1,e=255){this.flush();const r=this.gl;r.stencilMask(e),r.colorMask(!1,!1,!1,!1),r.stencilFunc(r.ALWAYS,t,e),r.stencilOp(r.KEEP,r.KEEP,r.REPLACE),this.enterRegion(this.graphicRegion,this.graphicRegion.maskShader),this.inCreateMask=!0}endDrawMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(0),this.inCreateMask=!1}clearMask(t=255){this.flush();const e=this.gl;e.stencilMask(t),e.clear(e.STENCIL_BUFFER_BIT),this.inCreateMask=!1}enterMask(t,e=1,r=255){this.flush();const i=this.gl;i.colorMask(!0,!0,!0,!0),i.stencilMask(0),i.stencilFunc(t===0?i.EQUAL:i.NOTEQUAL,e,r),i.stencilOp(i.KEEP,i.KEEP,i.KEEP),this.inCreateMask=!1}exitMask(){this.flush();const t=this.gl;t.colorMask(!0,!0,!0,!0),t.stencilMask(255),t.stencilFunc(t.ALWAYS,1,255),t.stencilOp(t.KEEP,t.KEEP,t.KEEP),this.inCreateMask=!1}setBlendMode(t){this.flush();const e=this.gl;switch(t){case 0:this.premultipliedAlpha?e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA):e.blendFuncSeparate(e.SRC_ALPHA,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 1:e.blendFuncSeparate(e.ONE,e.ONE,e.ONE,e.ONE);break;case 2:e.blendFuncSeparate(e.DST_COLOR,e.ONE_MINUS_SRC_ALPHA,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 3:e.blendFuncSeparate(e.ONE,e.ONE_MINUS_SRC_COLOR,e.ONE,e.ONE_MINUS_SRC_ALPHA);break;case 4:e.blendFuncSeparate(e.ZERO,e.ONE_MINUS_SRC_ALPHA,e.ZERO,e.ONE_MINUS_SRC_ALPHA);break}}startScissor(t,e,r,i){this.flush();const s=this.gl,a=this.physicsWidth/this.logicWidth,o=this.physicsHeight/this.logicHeight,h=Math.round(t*a),c=Math.round(this.physicsHeight-(e+i)*o),u=Math.round(r*a),l=Math.round(i*o);s.enable(s.SCISSOR_TEST),s.scissor(h,c,u,l)}endScissor(){this.flush(),this.gl.disable(this.gl.SCISSOR_TEST)}applyCamera(t){this.matrixStack.applyTransform(t);const e=this.matrixStack.curWorldM;this.matrix.invert(e)}logicToPhysics(t){return t.multiply(new p(this.physicsWidth/this.logicWidth,this.physicsHeight/this.logicHeight))}physicsToLogic(t){return t.multiply(new p(this.logicWidth/this.physicsWidth,this.logicHeight/this.physicsHeight))}cssToDevicePixel(t){return t.mul(this.dpr)}cssToLogic(t){const e=this.cssToDevicePixel(t);return this.physicsToLogic(e)}devicePixelToCss(t){return t.divide(this.dpr)}toCSSMatrix(t){const e=this.physicsWidth/this.dpr/this.logicWidth,r=this.physicsHeight/this.dpr/this.logicHeight;return this.matrix.toCSSMatrix(t??this.matrixStack.curWorldM,e,r)}}function me(n){return!(n===null||typeof n!="object"||Array.isArray(n)||n instanceof p||n instanceof m)}class O{static float(t,e){return Math.random()*(e-t)+t}static int(t,e){return Math.floor(Math.random()*(e-t+1))+t}static angle(){return Math.random()*Math.PI*2}static vector(t,e,r,i){return new p(O.float(t,e),O.float(r,i))}static randomColor(t,e){return new m(O.float(t.r,e.r),O.float(t.g,e.g),O.float(t.b,e.b),O.float(t.a,e.a))}static pick(t){return t[O.int(0,t.length-1)]}static pickWeight(t){if(!t||t.length===0)return null;let e=0;for(const[,i]of t)e+=i;let r=Math.random()*e;for(const[i,s]of t)if(r-=s,r<=0)return i;return t[t.length-1][0]}static scalarOrRange(t,e){if(t==null)return e;if(Array.isArray(t)){const[r,i]=t;if(typeof r=="number")return O.float(r,i);if(r instanceof p)return O.vector(r.x,i.x,r.y,i.y);if(r instanceof m)return O.randomColor(r,i)}return typeof t=="number"?t:t.clone()}}var Vt=(n=>(n.POINT="point",n.CIRCLE="circle",n.RECT="rect",n))(Vt||{});const Yt=10,zt=0,Xt=!0;class Z{components;constructor(t=1){if(!Number.isInteger(t)||t<=0)throw new RangeError("ParticleAttributeStore size must be a positive integer");this.components=Array.from({length:t},()=>({value:new C(w.Float32),delta:new C(w.Float32),damping:new C(w.Float32)}))}getArrayBuffer(){return this.components.flatMap(({value:t,delta:e,damping:r})=>[t,e,r])}update(t){for(const{value:e,delta:r,damping:i}of this.components)for(let s=0;s<e.usedElemNum;s++)e.typedArray[s]*=Math.pow(i.get(s),t),e.typedArray[s]+=r.get(s)*t}get(t,e=0){return this.components[e].value.get(t)}getComponent(t,e){if(typeof t=="number")return t;if(t instanceof p)return e===0?t.x:t.y;switch(e){case 0:return t.r;case 1:return t.g;case 2:return t.b;case 3:return t.a;default:return 0}}resolveComponent(t,e,r){return t===void 0?r:Array.isArray(t)?O.float(this.getComponent(t[0],e),this.getComponent(t[1],e)):this.getComponent(t,e)}create(t,e,r=1){const i=me(t)?t:void 0,s=i===void 0?t:void 0,a=r>0?r:1;let o=0;for(let h=0;h<this.components.length;h++){const{value:c,delta:u,damping:l}=this.components[h],d=this.getComponent(e,h),f=s===void 0?this.resolveComponent(i?.start,h,d):this.getComponent(s,h),x=i?.end===void 0?f:this.resolveComponent(i.end,h,d);c.push(f),u.push(i?.delta===void 0?(x-f)/a:this.getComponent(i.delta,h)),l.push(i?.damping??1),h===0&&(o=f)}return o}}class mt{options;emitting=!1;emitTimer=0;emitRate=Yt;emitTime=zt;emitTimeCounter=0;localSpace=Xt;rapid;x=new C(w.Float32);y=new C(w.Float32);scaleX=new C(w.Float32);scaleY=new C(w.Float32);rotation=new C(w.Float32);color=new C(w.Uint32);animations={speed:new Z,rotation:new Z,scale:new Z,color:new Z(4),velocity:new Z(2)};count=0;constructor(t,e){this.rapid=t,this.options=e,this.emitRate=e.emitRate??Yt,this.emitTime=e.emitTime??zt,this.localSpace=e.localSpace??Xt}getAllArrayBuffer(){return[this.x,this.y,this.scaleX,this.scaleY,this.rotation,this.color,...Object.values(this.animations).flatMap(t=>t.getArrayBuffer())]}setTexture(t){this.options.texture=t}clone(){return new mt(this.rapid,{...this.options})}setEmitRate(t){this.emitRate=t}setEmitTime(t){this.emitTime=t}start(){this.emitting=!0,this.emitTimeCounter=0}stop(){this.emitting=!1}clear(){for(const t of this.getAllArrayBuffer())t.clear();this.count=0,this.emitTimeCounter=0}emit(t){const e=this.options.maxParticles??1/0,r=Math.min(t,e-this.count);for(let i=0;i<r;i++)this.createParticle()}createParticle(){const t=O.scalarOrRange(this.options.life,1);let e=0,r=0;switch(this.options.emitShape){case"circle":{const c=Math.random()*Math.PI*2,u=(this.options.emitRadius??0)*Math.sqrt(Math.random());e=Math.cos(c)*u,r=Math.sin(c)*u;break}case"rect":{e=(Math.random()-.5)*(this.options.emitRect?.width??0),r=(Math.random()-.5)*(this.options.emitRect?.height??0);break}}const i=this.rapid.matrixStack;if(this.localSpace)this.x.push(e),this.y.push(r);else{const{x:c,y:u}=i.localToWorld(e,r);this.x.push(c),this.y.push(u)}const s=this.options.animation,a=this.animations,o=a.scale.create(s.scale,1,t),h=a.rotation.create(s.rotation,0,t);a.speed.create(s.speed,0,t),a.velocity.create(s.velocity,p.ZERO,t),a.color.create(s.color,m.White,t),this.rotation.push(h),this.scaleX.push(o),this.scaleY.push(o),this.color.pushUint32(m.packColor(a.color.get(this.count,0),a.color.get(this.count,1),a.color.get(this.count,2),a.color.get(this.count,3),this.rapid.premultipliedAlpha)),this.count+=1}update(t){if(this.emitting&&this.emitRate>0)if(this.emitTime>0){if(this.emitTimeCounter+=t,this.emitTimeCounter>=this.emitTime){const r=Math.floor(this.emitTimeCounter/this.emitTime);this.emit(this.emitRate*r),this.emitTimeCounter-=r*this.emitTime}}else{this.emitTimer+=t;const r=Math.floor(this.emitTimer*this.emitRate);r>0&&(this.emit(r),this.emitTimer-=r/this.emitRate)}const e=this.updateParticle(t);this.count-=e.length,C.removeAtIndices(e,this.getAllArrayBuffer())}updateParticle(t){const e=[],r=this.animations;Object.values(r).forEach(i=>i.update(t));for(let i=0;i<this.count;i++){const s=r.rotation.get(i),a=r.scale.get(i),o=r.speed.get(i);this.rotation.typedArray[i]=s,this.scaleX.typedArray[i]=a,this.scaleY.typedArray[i]=a,this.color.uint32[i]=m.packColor(r.color.get(i,0),r.color.get(i,1),r.color.get(i,2),r.color.get(i,3),this.rapid.premultipliedAlpha),this.x.typedArray[i]+=(o*Math.cos(s)+r.velocity.get(i,0))*t,this.y.typedArray[i]+=(o*Math.sin(s)+r.velocity.get(i,1))*t}return e}render(){const t=this.options,e=this.localSpace?void 0:this.rapid.matrix.alloc();this.rapid.drawParticles({texture:t.texture,shader:t.shader,x:this.x.typedArray,y:this.y.typedArray,scaleX:this.scaleX.typedArray,scaleY:this.scaleY.typedArray,rotation:this.rotation.typedArray,color:this.color.typedArray,count:this.count,reverseOrder:!0,originX:t.origin?.x??.5,originY:t.origin?.y??.5,customMatrix:e})}isActive(){return this.emitting||this.count>0}oneShot(){this.emit(this.emitRate)}}g.ArrayType=w,g.BaseTexture=Y,g.BlendMode=Gt,g.CanvasScaleMode=Ht,g.Color=m,g.CustomGlShader=ut,g.DynamicArrayBuffer=C,g.GLShader=ct,g.GraphicRegion=wt,g.LineTextureMode=bt,g.MaskType=kt,g.MatrixStack=pt,g.MatrixStore=xt,g.ParticleEmitter=mt,g.ParticleShape=Vt,g.QUAD_VERTICES=Mt,g.Rapid=fe,g.Region=lt,g.RenderTexture=vt,g.SpriteRegion=it,g.TextTexture=yt,g.Texture=I,g.TextureFilterMode=st,g.TextureManager=gt,g.TextureWrapMode=j,g.Vec2=p,g.WebglBufferArray=tt,g.composeProjectionWithAffine=St,g.drawCircle=Ot,g.drawGraphic=ft,g.drawLine=Nt,g.drawMaskImage=Lt,g.drawParticles=Pt,g.drawRect=It,g.drawSprite=_t,g.getColorUint32=Ct,g.multiplyMat4=At,Object.defineProperty(g,Symbol.toStringTag,{value:"Module"})}));
@@ -12,6 +12,6 @@ export declare class ParticleRegion extends SpriteRegion {
12
12
  createDefaultShader(): GLShader;
13
13
  enter(customShader?: GLShader | CustomGlShader): void;
14
14
  createShader(vs: string, fs: string): GLShader;
15
- drawParticles(texture: Texture, x: ArrayLike<number>, y: ArrayLike<number>, rotation: (ArrayLike<number> | number) | undefined, color: (ArrayLike<Color> | ArrayLike<number> | number) | undefined, count: number, scaleX: (ArrayLike<number> | number) | undefined, scaleY: (ArrayLike<number> | number) | undefined, u0: number | undefined, v0: number | undefined, u1: number | undefined, v1: number | undefined, flipX: boolean | undefined, flipY: boolean | undefined, isRotated: boolean | undefined, originX: number | undefined, originY: number | undefined, premultipliedAlpha: boolean, reverseOrder?: boolean, customMatrix?: number): void;
15
+ drawParticles(texture: Texture, x: ArrayLike<number>, y: ArrayLike<number>, rotation: (ArrayLike<number> | number) | undefined, color: (ArrayLike<Color> | ArrayLike<number> | number) | undefined, count: number, scaleX: (ArrayLike<number> | number) | undefined, scaleY: (ArrayLike<number> | number) | undefined, u0: (ArrayLike<number> | number) | undefined, v0: (ArrayLike<number> | number) | undefined, u1: (ArrayLike<number> | number) | undefined, v1: (ArrayLike<number> | number) | undefined, flipX: boolean | undefined, flipY: boolean | undefined, isRotated: boolean | undefined, originX: number | undefined, originY: number | undefined, premultipliedAlpha: boolean, reverseOrder?: boolean, customMatrix?: number): void;
16
16
  render(): void;
17
17
  }
package/dist/render.d.ts CHANGED
@@ -381,7 +381,7 @@ export declare class Rapid {
381
381
  * Disables scissor clipping, restoring full-canvas rendering.
382
382
  */
383
383
  endScissor(): void;
384
- renderCamera(transform: ITransformOptions): void;
384
+ applyCamera(transform: ITransformOptions): void;
385
385
  logicToPhysics(p: Vec2): Vec2;
386
386
  physicsToLogic(p: Vec2): Vec2;
387
387
  cssToDevicePixel(p: Vec2): Vec2;
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "rapid-render",
3
3
  "private": false,
4
- "version": "1.0.10",
4
+ "version": "1.0.11",
5
5
  "type": "module",
6
6
  "files": [
7
7
  "dist",