-
Notifications
You must be signed in to change notification settings - Fork 27
/
uv.min.js
52 lines (52 loc) · 21 KB
/
uv.min.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
{let g=null,v,Z=0,U=0,P,Q,j=g,O=0,L=285217039,G=g,C,D,E,W=-1,S=0,T=0,ux=0,uy=0,uz=0,uw=0,vx=0,vy=0;const N=globalThis[(P=document.currentScript.src)&&new URL(P).hash.slice(1)||'globalThis']??={},B=[g,g,g,g,g,g,g,g],R={imageOrientation:'flipY',premultiplyAlpha:'none'},Y=class{fromSrc(s,a,b,o){this.from(fetch(s,o).then(a=>a.blob()),a,b);return this}from(t,F=N.Formats.RGBA,o=Z){if(typeof t!='object')return
this.format=F;if(t instanceof Blob)t=createImageBitmap(t,R);if(t.then)return t.then(t=>this.from(t,F,o));X(this);const{0:A,1:B,2:C}=F,f=(~o>>1)&3;if(~W&32)g.pixelStorei(37440,1),g.pixelStorei(37441,1),W|=32;g.texImage2D(3553,0,A,this.width=t.width,this.height=t.height,0,B,C,t);g.texParameteri(3553,10240,(~o&1)+9728)
if(o&8)g.texParameteri(3553,10241,9984+f),this.m=3;else g.texParameteri(3553,10241,(f&1)+9728),this.m=1;g.texParameteri(3553,10242,o&32?33648:o&16?10497:33071);g.texParameteri(3553,10243,o&128?33648:o&64?10497:33071);return this}options(o=Z){const b=X(this),f=(~o>>1)&3
g.texParameteri(b,10240,(~o&1)+9728);if(o&8)g.texParameteri(b,10241,9984+f),this.m&=-3;else g.texParameteri(b,10241,(f&1)+9728),this.m|=2;g.texParameteri(b,10242,o&32?33648:o&16?10497:33071);g.texParameteri(b,10243,o&128?33648:o&64?10497:33071);return this}put(t,x=0,y=0,l=0){if(typeof t!='object')return
if(t instanceof Blob)t=createImageBitmap(t,R);if(t.then)return t.then(t=>this.put(t,x,y,l));if(~W&32)g.pixelStorei(37440,1),g.pixelStorei(37441,1),W|=32;X(this)<4e3?g.texSubImage2D(3553,0,x,y,t.width,t.height,this.format[1],this.format[2],t):g.texSubImage3D(35866,0,x,y,l,t.width,t.height,1,this.format[1],this.format[2],t)
this.m|=1}of(w=0,h=0,l=0,F=N.Formats.RGBA,o=Z){this.layers=l;const b=X(this);const f=(~o>>1)&3;this.format=F;const{0:A,1:B,2:C}=F;if(l)g.texImage3D(b,0,A,this.width=w,this.height=h,l,0,B,C,null);else g.texImage2D(3553,0,F[0],this.width=w,this.height=h,0,F[1],F[2],null);g.texParameteri(b,10240,(~o&1)+9728);if(o&8)g.texParameteri(b,10241,9984+f),this.m=3;else g.texParameteri(b,10241,(f&1)+9728),this.m=1;g.texParameteri(b,10242,o&32?33648:o&16?10497:33071)
g.texParameteri(b,10243,o&128?33648:o&64?10497:33071);return this}putData(x=0,y=0,w,h,d,F=this.format){X(this);if(W&32)g.pixelStorei(37440,0),g.pixelStorei(37441,0),W&=-33;g.texSubImage2D(3553,0,x,y,w,h,F[1],F[2],d);this.m|=1}putDataLayers(x=0,y=0,z=0,w,h,l,d,F=this.format){X(this);if(W&32)g.pixelStorei(37440,0),g.pixelStorei(37441,0),W&=-33;g.texSubImage3D(35866,0,x,y,z,w,h,l,F[1],F[2],d)
this.m|=1}uv(x=0,y=0,w=0,h=0,l=0){return{x:x/this.width,y:1-(y+h)/this.height,w:w/this.width,h:h/this.height,l,sub}}delete(){g.deleteTexture(this)}}.prototype,X=t=>{const o=B[U],b=t.layers?35866:3553;if(o)o.u=-1;B[U]=t;t.u=U;g.bindTexture(b,t);return b},F=Float32Array,V=[]
N.Formats={R:[33321,6403,5121],RG:[33323,33319,5121],RGB:[32849,6407,5121],RGBA:D=[32856,P=6408,5121],RGB565:[36194,6407,33635],R11F_G11F_B10F:[35898,6407,35899],RGB5_A1:[32855,P,32820],RGB10_A2:[32857,P,33640],RGBA4:[32854,P,32819],RGB9_E5:[35901,6407,35902],R8:[33330,36244,5121],RG8:[33336,33320,5121],RGB8:[36221,36248,5121],RGBA8:[36220,36249,5121],R16:[33332,36244,5123],RG16:[33338,33320,5123],RGB16:[36215,36248,5123],RGBA16:[36214,36249,5123],R32:[33334,36244,5125],RG32:[33340,33320,5125],RGB32:[36209,36248,5125],RGBA32:[36208,36249,5125],R16F:[33325,36244,5131],RG16F:[33327,33320,5131],RGB16F:[34843,36248,5131],RGBA16F:[34842,36249,5131],R16F_32F:[33325,36244,5126],RG16F_32F:[33327,33320,5126],RGB16F_32F:[34843,36248,5126],RGBA16F_32F:[34842,36249,5126],R32F:[33326,36244,5126],RG32F:[33328,33320,5126],RGB32F:[34837,36248,5126],RGBA32F:[34836,36249,5126]}
P=N.Texture=(w=0,h=0,l=0,F=N.Formats.RGBA,o=Z)=>{const t=Object.setPrototypeOf(g.createTexture(),Y);t.u=-1;t.layers=t.height=t.width=0;t.format=F;t.m=~o>>2&2;if(w|h)t.of(w,h,l,F,o);return t};P.defaultOptions=o=>Z=o;P=N.Mesh=()=>{const a=[];a.l=V.pop()??new F(8192);a.i=0;return new M(a)};P.single=(a=k,f=0,b=0,c=0,d=0,e=0)=>N.Mesh.singleMat(1,0,0,1,0,0,a,f,b,c,d,e);P.singleRect=(b=0,c=0,d=1,e=1,a=k,j=0,f=0,g=0,h=0,i=0)=>N.Mesh.singleMat(d,0,0,e,b,c,a,j,f,g,h,i)
P.singleMat=(a=0,b=0,c=0,d=0,e=0,f=0,{x:X,y:Y,w:W,h:H,l}=k,G=0,t1=0,t2=0,t3=0,t4=0)=>{const x=new F(16);x[0]=a;x[1]=c;x[2]=e;x[3]=b;x[4]=d;x[5]=f;x[6]=X;x[7]=Y;x[8]=W;x[9]=H;x[10]=t1;x[11]=t2;x[12]=t3;x[13]=t4;x[14]=l;x[15]=G;return x};function sub(a,b,c,d){return{x:this.x+a*this.w,y:this.y+b*this.h,w:this.w*c,h:this.h*d,l:this.l,sub}}N.uv=(x=0,y=0,w=1,h=1,l=0)=>({x,y,w,h,l,sub});const k=N.uv();N._=void 0;class M{R;#a;#b;#c;#d;#e;#f;constructor(z,a=1,b=0,c=0,d=1,e=0,f=0){this.R=z
this.#a=a;this.#b=b;this.#c=c;this.#d=d;this.#e=e;this.#f=f}translate(x=0,y=0){this.#e+=x*this.#a+y*this.#c;this.#f+=x*this.#b+y*this.#d}scale(x=1,y=x){this.#a*=x;this.#b*=x;this.#c*=y;this.#d*=y}rotate(r=0){const C=Math.cos(r),S=Math.sin(r),a=this.#a,b=this.#b,c=this.#c,d=this.#d;this.#a=a*C-c*S;this.#b=b*C-d*S;this.#c=a*S+c*C;this.#d=b*S+d*C}transform(a,b,c,d,e,f){const A=this.#a,B=this.#b,C=this.#c,D=this.#d,E=this.#e,F=this.#f;this.#a=a*A+c*B
this.#b=b*A+d*B;this.#c=a*C+c*D;this.#d=b*C+d*D;this.#e=a*E+c*F+e;this.#f=b*E+d*F+f}skew(x=0,y=0){const A=this.#a,B=this.#b;this.#a+=this.#c*y;this.#b+=this.#d*y;this.#c+=A*x;this.#d+=B*x}multiply(x=1,y=0){const A=this.#a,C=this.#c;this.#a=A*x-this.#b*y;this.#b=A*y+this.#b*x;this.#c=C*x-this.#d*y
this.#d=C*y+this.#d*x}getTransform(){return{a:this.#a,b:this.#b,c:this.#c,d:this.#d,e:this.#e,f:this.#f}}new(a=1,b=0,c=0,d=1,e=0,f=0){return new M(this.R,a,b,c,d,e,f)}reset(a=1,b=0,c=0,d=1,e=0,f=0){this.#a=a;this.#b=b;this.#c=c;this.#d=d;this.#e=e;this.#f=f}box(x=0,y=0,w=1,h=w){this.#e+=x*this.#a+y*this.#c;this.#f+=x*this.#b+y*this.#d;this.#a*=w;this.#b*=w;this.#c*=h
this.#d*=h}to(x,y){if(typeof x=='object')({x,y}=x);return{x:this.#a*x+this.#c*y+this.#e,y:this.#b*x+this.#d*y+this.#f}}from(x,y){if(typeof x=='object')({x,y}=x);const a=this.#a,b=this.#b,c=this.#c,d=this.#d,det=a*d-b*c;return{x:(x*d-x*c+c*this.#f-d*this.#e)/det,y:(y*a-y*b+b*this.#e-a*this.#f)/det}}sub(){return new M(this.R,this.#a,this.#b,this.#c,this.#d,this.#e,this.#f)}add({x:X,y:Y,w:W,h:H,l:L}=k,G=0,t1=0,t2=0,t3=0,t4=0){const j=(this.R.i+=16)-16,l=this.R.l
l[j]=this.#a;l[j+1]=this.#c;l[j+2]=this.#e;l[j+3]=this.#b;l[j+4]=this.#d;l[j+5]=this.#f;l[j+6]=X;l[j+7]=Y;l[j+8]=W;l[j+9]=H;l[j+10]=t1;l[j+11]=t2;l[j+12]=t3;l[j+13]=t4;l[j+14]=L;l[j+15]=G;if(j==8176)this.R.push(l),this.R.l=V.pop()??new F(8192),this.R.i=0}addRect(x=0,y=0,w=1,h=1,{x:X,y:Y,w:W,h:H,l:L}=k,G=0,t1=0,t2=0,t3=0,t4=0){const j=(this.R.i+=16)-16,l=this.R.l;l[j]=this.#a*w
l[j+1]=this.#c*h;l[j+2]=this.#e+x*this.#a+y*this.#c;l[j+3]=this.#b*w;l[j+4]=this.#d*h;l[j+5]=this.#f+x*this.#b+y*this.#d;l[j+6]=X;l[j+7]=Y;l[j+8]=W;l[j+9]=H;l[j+10]=t1;l[j+11]=t2;l[j+12]=t3;l[j+13]=t4;l[j+14]=L;l[j+15]=G;if(j==8176)this.R.push(l),this.R.l=V.pop()??new F(8192),this.R.i=0}addMat(a=1,b=0,c=0,d=1,e=0,f=0,{x:X,y:Y,w:W,h:H,l:L}=k,G=0,t1=0,t2=0,t3=0,t4=0){const j=(this.R.i+=16)-16,l=this.R.l,ta=this.#a,tb=this.#b,tc=this.#c,td=this.#d,te=this.#e,tf=this.#f
l[j]=a*ta+c*tb;l[j+1]=a*tc+c*td;l[j+2]=a*te+c*tf+e;l[j+3]=b*ta+d*tb;l[j+4]=b*tc+d*td;l[j+5]=b*te+d*tf+f;l[j+6]=X;l[j+7]=Y;l[j+8]=W;l[j+9]=H;l[j+10]=t1;l[j+11]=t2;l[j+12]=t3;l[j+13]=t4;l[j+14]=L;l[j+15]=G;if(j==8176)this.R.push(l),this.R.l=V.pop()??new F(8192),this.R.i=0}upload(){const b=g.createBuffer(),L=this.R.length*32768+(this.R.i<<2);g.bindBuffer(34962,b);g.bufferData(34962,L,35044);let i=0;for(;i<this.R.length;i++)g.bufferSubData(34962,i*32768,this.R[i])
g.bufferSubData(34962,i*32768,this.R.l,0,this.R.i);const v=g.createVertexArray();g.bindVertexArray(G=v);g.vertexAttribPointer(0,3,5126,0,64,0);g.vertexAttribPointer(1,3,5126,0,64,12);g.vertexAttribPointer(2,4,5126,0,64,24);g.vertexAttribPointer(3,4,5126,0,64,40);g.vertexAttribPointer(4,2,5126,0,64,56);for(let i=0;i<5;i++){g.enableVertexAttribArray(i);g.vertexAttribDivisor(i,1)}v.count=L/64;v.B=b;this.delete()
return v}delete(){if(V.length<128)V.push(this.R.l);for(let i=Math.min(this.R.length,128-V.length);i>=0;i--)V.push(this.R[i]);this.R.length=0;this.R.l=null}get count(){return this.R.length*512+this.R.i/16}export(){const f=new F(this.R.length*8192+this.R.i);for(let i=0;i<this.R.length;i++)f.set(this.R[i],i*8192);if(this.R.i)f.set(this.R.l.subarray(0,this.R.i),this.R.length*8192);return f}import(f){if(f instanceof ArrayBuffer)f=new F(f)
if(f.length%16)return void((W&16)&&(W&=-17,console.warn('.import(): Length must be a multiple of 16')));let j=Math.min(f.length,8192-this.R.i),a;if(j)this.R.l.set(f.subarray(0,j),this.R.i);if((this.R.i+=j)>=8192)this.R.push(this.R.l),this.R.l=V.pop()??new F(8192),this.R.i=0;else return;while(j<=f.length-8192)this.R.push(f.slice(j,j+=8192));this.R.l.set(a=f.subarray(j));this.R.i=a.length}}WebGLVertexArrayObject.prototype.delete=function(){g.deleteVertexArray(this)
if(this.B)g.deleteBuffer(this.B)};const I=new F(6);class K{j;#a;#b;#c;#d;#e;#f;#x;#y;#z;#w;#s;#t;get width(){return(this.j||g.canvas).width}get height(){return(this.j||g.canvas).height}get texture(){return this.j?.t}get gl(){return g}getData(x=0,y=0,w=this.width,h=this.height,a=null){if(j!=this.j)g.bindFramebuffer(36160,j=this.j);const f=j?j.f:D
if(!a){const A=f[0],S=(A==32856||A==36214||A==36208||A==34842||A==34836||A==36220?4:A==32849||A==36215||A==36209||A==34843||A==34837||A==32849||A==36221?3:A==33323||A==33338||A==33340||A==33327||A==33328||A==33336?2:1)*w*h;a=f[2]==5121?new Uint8Array(S):f[2]==5126?new F(S):f[2]==5125||f[2]==35899||f[2]==33640||f[2]==35902?new Uint32Array(S):new Uint16Array(S)}g.readPixels(x,y,w,h,f[1],f[2],a)
return a}copyTo(t,A=0,B=0,C=0,Z=0,Y=0,W=this.width,H=this.height){if(j!=this.j)g.bindFramebuffer(36160,j=this.j);X(t)<4e3?g.copyTexSubImage2D(3553,0,A,B,Z,Y,W,H):g.copyTexSubImage3D(35866,0,A,B,C,Z,Y,W,H);t.m|=1}resize(w=this.width,h=this.height,F=N.Formats.RGBA){const{j}=this;if(j){j.t=null;j.f=F;g.bindFramebuffer(36008,j);if(j.X)g.deleteRenderbuffer(j.X);const s=j.X=g.createRenderbuffer();g.bindRenderbuffer(36161,s)
g.renderbufferStorage(36161,F[0],w,h);g.framebufferRenderbuffer(36008,36064,36161,s);if(j.S>=0){if(j.Y)g.deleteRenderbuffer(j.Y);const s=j.Y=g.createRenderbuffer();g.bindRenderbuffer(36161,s);g.renderbufferStorage(36161,36168,w,h);g.framebufferRenderbuffer(36008,36128,36161,s)}}else{g.canvas.width=w;g.canvas.height=h;if(g.drawingBufferStorage)g.drawingBufferStorage(F[0],w,h)
else if(W&(F!=N.Formats.RGBA))W&=-2,console.warn('Browser does not support specifying format for main target');D=F}}setTexture(T,L=0){const{j}=this;if(!j)return W!=(W&=-3)?console.warn('Cannot attach a texture to the main target (its output must always be the <canvas>, use .resize() to change size/format)'):void 0;g.bindFramebuffer(36008,j);j.width=T.width;j.height=T.height;if(j.S>=0){if(j.Y)g.deleteRenderbuffer(j.Y);const s=j.Y=g.createRenderbuffer();g.bindRenderbuffer(36161,s);g.renderbufferStorage(36161,36168,T.width,T.height)
g.framebufferRenderbuffer(36008,36128,36161,s)}if(j.t===T&&j.l==L)return;j.t=T;j.f=T.format;j.L=L;if(j.X)g.deleteRenderbuffer(j.X),j.X=null;T.layers?g.framebufferTextureLayer(36008,36064,T,0,L):g.framebufferTexture2D(36008,36064,3553,T,0)}constructor(j,p,a=1,b=0,c=0,d=1,e=0,f=0,X=0,Y=0,Z=0,W=0,U=0,V=0){this.j=j;this.p=p;this.#a=a;this.#b=b;this.#c=c;this.#d=d;this.#e=e;this.#f=f;this.#x=X;this.#y=Y;this.#z=Z;this.#w=W;this.#s=U
this.#t=V}translate(x=0,y=0){this.#e+=x*this.#a+y*this.#c;this.#f+=x*this.#b+y*this.#d}scale(x=1,y=x){this.#a*=x;this.#b*=x;this.#c*=y;this.#d*=y}rotate(r=0){const C=Math.cos(r),S=Math.sin(r),a=this.#a,b=this.#b,c=this.#c,d=this.#d;this.#a=a*C-c*S;this.#b=b*C-d*S;this.#c=a*S+c*C;this.#d=b*S+d*C}transform(a,b,c,d,e,f){const A=this.#a,B=this.#b,C=this.#c,D=this.#d,E=this.#e,F=this.#f;this.#a=a*A+c*B;this.#b=b*A+d*B;this.#c=a*C+c*D;this.#d=b*C+d*D;this.#e=a*E+c*F+e
this.#f=b*E+d*F+f}skew(x=0,y=0){const A=this.#a,B=this.#b;this.#a+=this.#c*y; this.#b+=this.#d*y;this.#c+=A*x;this.#d+=B*x}multiply(x=1,y=0){const A=this.#a,C=this.#c;this.#a=A*x-this.#b*y;this.#b=A*y+this.#b*x;this.#c=C*x-this.#d*y;this.#d=C*y+this.#d*x}getTransform(){return{a:this.#a,b:this.#b,c:this.#c,d:this.#d,e:this.#e,f:this.#f}}new(a=1,b=0,c=0,d=1,e=0,f=0){return new K(this.j,Q,a,b,c,d,e,f)}reset(a=1,b=0,c=0,d=1,e=0,f=0,ux=0,uy=0,uz=0,uw=0,s=0,t=0){this.#a=a
this.#b=b;this.#c=c;this.#d=d;this.#e=e;this.#f=f;this.#x=ux;this.#y=uy;this.#z=uz;this.#w=uw;this.#s=s;this.#t=t;this.p=Q}resetTo(t){this.#a=t.#a;this.#b=t.#b;this.#c=t.#c;this.#d=t.#d;this.#e=t.#e;this.#f=t.#f;this.#x=t.#x;this.#y=t.#y;this.#z=t.#z;this.#w=t.#w;this.#s=t.#s;this.#t=t.#t;this.p=t.p}box(x=0,y=0,w=1,h=w){this.#e+=x*this.#a+y*this.#c;this.#f+=x*this.#b+y*this.#d;this.#a*=w;this.#b*=w;this.#c*=h;this.#d*=h}to(x,y){if(typeof x=='object')({x,y}=x)
return{x:this.#a*x+this.#c*y+this.#e,y:this.#b*x+this.#d*y+this.#f}}from(x,y){if(typeof x=='object')({x,y}=x);const a=this.#a,b=this.#b,c=this.#c,d=this.#d,det=a*d-b*c;return{x:(x*d-x*c+c*this.#f-d*this.#e)/det,y:(y*a-y*b+b*this.#e-a*this.#f)/det}}sub(){return new K(this.j,this.p,this.#a,this.#b,this.#c,this.#d,this.#e,this.#f,this.#x,this.#y,this.#z,this.#w,this.#s,this.#t)}useShader(p=Q){this.p=p}setU(a=0,b=0,c=0,d=0){this.#x=a
this.#y=b;this.#z=c;this.#w=d}setST(s=0,t=0){this.#s=s;this.#t=t}clear(r=0,g=0,b=0,a=0){g.clearColor(r,g,b,a);L=(L&240)|(r==r)|(g==g)<<1|(b==b)<<2|(a==a)<<3;g.colorMask(L&1,L&2,L&4,L&8);let m=16384;const x=this.j;if(x)if(++x.S>=8)x.S=0,m|=1024;else if(++O>=8)O=0,m|=1024;g.stencilMask(1<<(x?x.S:O));if(j!=x)g.bindFramebuffer(36160,j=x);g.clear(m)}clearColor(r=0,g=0,b=0,a=0){g.clearColor(r,g,b,a);L=(L&240)|(r==r)|(g==g)<<1|(b==b)<<2|(a==a)<<3
g.colorMask(L&1,L&2,L&4,L&8);if(j!=this.j)g.bindFramebuffer(36160,j=this.j);g.clear(16384)}clearStencil(){const x=this.j;if(x)if(++x.S>=8){x.S=0;if(j!=x)g.bindFramebuffer(36160,j=x);g.clear(1024)}else if(++O>=8){O=0;if(j!=x)g.bindFramebuffer(36160,j=x);g.clear(1024)}g.stencilMask(1<<(x?x.S:O))}draw(K,e,m=15,k=1135889,D=1e999){if(j!=this.j)g.bindFramebuffer(36160,j=this.j);{const W=(j||g.canvas).width,H=(j||g.canvas).height
if(!W|!H)return;if(S!=W||T!=H)g.viewport(0,0,S=W,T=H)}if(E!=this.p)g.useProgram(E=this.p),ux=vx=NaN;I[0]=this.#a*2;I[3]=this.#b*2;I[1]=this.#c*2;I[4]=this.#d*2;I[2]=this.#e*2-1;I[5]=this.#f*2-1;g.uniformMatrix2x3fv(E.m,0,I);if(ux!=this.#x||uy!=this.#y||uz!=this.#z||uw!=this.#w)g.uniform4f(E.a,ux=this.#x,uy=this.#y,uz=this.#z,uw=this.#w);if(vx!=this.#s)g.uniform1f(E.b,vx=this.#s);if(vy!=this.#t)g.uniform1f(E.c,vy=this.#t);m=m&2281701631|k<<8
if((L^m)&15)g.colorMask(m&1,m&2,m&4,m&8);if((L^m)&496){if(m&240){const s=j?j.S:O;if(!(L&240))g.enable(2960);if((m^L)&240){g.stencilFunc(m&32?m&16?512:517:m&16?514:519,255,1<<s);const o=m&128?m&64?5386:7681:m&64?0:7680;g.stencilOp(o,o,o)}}else if(L&240)g.disable(2960)}if((L^m)&1996488704)g.blendEquationSeparate((m>>24&7)+32773,(m>>28&7)+32773)
if((L^m)&16776960)g.blendFuncSeparate((m>>8&15)+766*!!(m&3584),(m>>16&15)+766*!!(m&917504),(m>>12&15)+766*!!(m&57344),(m>>20&15)+766*!!(m&14680064));if((m^L)&134217728)if(m&134217728)g.enable(3024);else g.disable(3024);L=m;const b=this.j?.t;if(Array.isArray(e)){if(e.length<E.t.length||e.length>8)return W!=(W&=-5)?console.warn('.draw(): Shader expects '+E.t.length+' texture(s)'):void 0;let v=255,i=0;for(;i<e.length;i++){const t=e[i]
if(t==b)return W!=(W&=-9)?console.warn('.draw(): Cannot use a texture that is also being drawn to'):void 0;if(t.u>-1){v&=-129>>t.u;g.uniform1i(E.t[i],t.u);if(t.m==3){if(U!=t.u)g.activeTexture(33984+(U=t.u));g.generateMipmap(t.layers?35866:3553)}}}for(i=0;i<e.length;i++){const t=e[i];if(t.u>-1)continue;U=Math.clz32(v)-24;v&=-129>>U;g.activeTexture(33984+U);X(t);g.uniform1i(E.t[i],U)
if(t.m==3)g.generateMipmap(t.layers?35866:3553)}}else if(e){if(E.t.length>1)return W!=(W&=-5)?console.warn('.draw(): Shader expects '+E.t.length+' texture(s)'):void 0;if(e==b)return W!=(W&=-9)?console.warn('.draw(): Cannot use a texture that is also being drawn to'):void 0;if(e.u>-1){g.uniform1i(E.t[0],e.u);if(e.m==3){if(U!=e.u)g.activeTexture(33984+(U=e.u));g.generateMipmap(e.layers?35866:3553)}}else{X(e)
g.uniform1i(E.t[0],U);if(e.m==3)g.generateMipmap(e.layers?35866:3553)}}if(b)b.m|=1;if(K instanceof WebGLVertexArrayObject){if(G!=K)g.bindVertexArray(G=K);g.drawArraysInstanced(5,0,4,Math.min(D,K.count));return}g.bindBuffer(34962,C);if(G)g.bindVertexArray(G=null);if(K.byteLength){g.bufferData(34962,K,35040)
g.drawArraysInstanced(5,0,4,Math.min(D,K.byteLength/64))}else{if(!K.R.l)return W!=(W&=-65)?console.warn('.draw(): Mesh has already been consumed. Use .upload() if you want to draw the mesh more than once'):void 0;g.bufferData(34962,K.R.length*32768+K.R.i*4,35040);for(let i=0;i<K.R.length;i++)g.bufferSubData(34962,i*32768,K.R[i]);g.bufferSubData(34962,K.R.length*32768,K.R.l,0,K.R.i);g.drawArraysInstanced(5,0,4,Math.min(D,K.count))
K.delete()}}delete(){const{j}=this;if(!j)return;g.deleteFramebuffer(j);if(j.X)g.deleteRenderbuffer(j.X);if(j.Y)g.deleteRenderbuffer(j.Y)}}N.setTargetCanvas=c=>{g=c.getContext('webgl2',{preserveDrawingBuffer:0,antialias:0,depth:0,premultipliedAlpha:1,S:1});g.pixelStorei(37440,1);C=g.createBuffer();g.bindBuffer(34962,C)
g.vertexAttribPointer(0,3,5126,0,64,0);g.vertexAttribPointer(1,3,5126,0,64,12);g.vertexAttribPointer(2,4,5126,0,64,24);g.vertexAttribPointer(3,4,5126,0,64,40);g.vertexAttribPointer(4,2,5126,0,64,56);P=5;while(P-->0)g.enableVertexAttribArray(P),g.vertexAttribDivisor(P,1);v=g.createShader(35633);g.shaderSource(v,`#version 300 es
#define L(d) layout(location=d)in
uniform mat2x3 g;L(0)mat2x3 m;L(2)vec4 u;L(3)vec4 t;L(4)vec2 V;out vec3 uv;out vec2 pos,xy;flat out float effect;flat out vec4 tint;void main(){pos=vec2(gl_VertexID&1,gl_VertexID>>1);gl_Position=vec4(vec3(xy=vec3(pos,1)*m,1)*g,0,1);uv=vec3(u.xy+pos*u.zw,V.x);tint=t;effect=V.y;}`);g.compileShader(v);Q=N.Shader(`void main(){color=texture(tex0,uv.xy)*(1.-tint);}`);g.useProgram(E=Q);g.clearStencil(0);g.stencilMask(1);g.disable(2929);g.enable(3042);g.disable(3024);for(P of[(P='EXT_color_buffer_')+'half_float',P+'float'])g.getExtension(P);j=G=null;L=285217039;O=ux=uy=uz=uw=vx=vy=0;return new K(null,Q)}
Object.assign(N,{R:1,G:2,B:4,A:8,RGB:7,RGBA:15,IF_ONE:16,IF_ZERO:32,DONT_DRAW:48,SET_ZERO:64,SET_ONE:128,FLIP:192,DITHERING:134217728,ONE:17,ZERO:0,RGB_ONE:1,A_ONE:16,SRC:34,RGB_SRC:2,ONE_MINUS_SRC:51,RGB_ONE_MINUS_SRC:3,SRC_ALPHA:68,RGB_SRC_ALPHA:4,A_SRC:64,ONE_MINUS_SRC_ALPHA:85,RGB_ONE_MINUS_SRC_ALPHA:5,A_ONE_MINUS_SRC:80,DST:136,RGB_DST:8,ONE_MINUS_DST:153,RGB_ONE_MINUS_DST:9,DST_ALPHA:102,RGB_DST_ALPHA:6,A_DST:96,ONE_MINUS_DST_ALPHA:119,RGB_ONE_MINUS_DST_ALPHA:7,A_ONE_MINUS_DST:112,SRC_ALPHA_SATURATE:170,RGB_SRC_ALPHA_SATURATE:10,ADD:17,RGB_ADD:1,A_ADD:16,SUBTRACT:85,RGB_SUBTRACT:5,A_SUBTRACT:80,REVERSE_SUBTRACT:102,RGB_REVERSE_SUBTRACT:6,A_REVERSE_SUBTRACT:96,MIN:34,RGB_MIN:2,A_MIN:32,MAX:51,RGB_MAX:3,A_MAX:48,UPSCALE_PIXELATED:1,DOWNSCALE_PIXELATED:2,DOWNSCALE_MIPMAP_NEAREST:4,PIXELATED:7,MIPMAPS:8,REPEAT:80,REPEAT_MIRRORED:160,REPEAT_X:16,REPEAT_MIRRORED_X:32,REPEAT_Y:64,REPEAT_MIRRORED_Y:128,Blend:P=(s=17,c=17,d=0)=>s|d<<8|c<<16})
P.REPLACE=1114129;P.DEFAULT=1135889;N.PI2??=(N.PI??=Math.PI)*2;N.colorSpace=t=>{g.drawingBufferColorSpace=t};N.Target=(w=0,h=0,F=N.Formats.RGBA,k=!0)=>{const t=g.createFramebuffer();g.bindFramebuffer(36008,t);t.S=NaN;t.t=null;t.l=0;if(typeof w=='boolean')k=w,w=0;if(typeof w=='object')t.t=w,t.l=h,k=!!F,F=t.t.format,t.width=w=t.t.width,t.height=h=t.t.height,t.S=0,t.t.layers?g.framebufferTextureLayer(36008,36064,t.t,0,t.l):g.framebufferTexture2D(36008,36064,3553,t.t,0);else{t.width=w
t.height=h;const s=t.X=g.createRenderbuffer();g.bindRenderbuffer(36161,s);g.renderbufferStorage(36161,F[0],w,h);g.framebufferRenderbuffer(36008,36064,36161,s)}t.f=F;if(k){const s=t.Y=g.createRenderbuffer();g.bindRenderbuffer(36161,s);g.renderbufferStorage(36161,36168,w,h);g.framebufferRenderbuffer(36008,36128,36161,s);t.S=0}return new K(t,Q)};N.Shader=s=>{const p=g.createProgram(),f=g.createShader(35632);g.shaderSource(f,`#version 300 es
precision mediump float;precision highp int;precision highp usampler2D;precision mediump sampler2DArray;precision highp usampler2DArray;in vec3 uv;in vec2 pos,xy;flat in float effect;flat in vec4 tint;out vec4 color;uniform sampler2D tex0,tex1,tex2,tex3,tex4,tex5,tex6,tex7;uniform usampler2D utex0,utex1,utex2,utex3,utex4,utex5,utex6,utex7;uniform sampler2DArray atex0,atex1,atex2,atex3,atex4,atex5,atex6,atex7;uniform usampler2DArray uatex0,uatex1,uatex2,uatex3,uatex4,uatex5,uatex6,uatex7;uniform highp vec4 u;uniform highp float s,t;
`+s);g.compileShader(f);const e=g.getShaderInfoLog(f);if(e)console.warn(`GLSL error:
`,e),g.shaderSource(f,`#version 300 es
precision mediump float;out vec4 c;void main(){c=vec4(0,0,0,1);}`),g.compileShader(f);P=a=>g.attachShader(p,a);P(v);P(f);g.linkProgram(p);P=a=>g.getUniformLocation(p,a);p.m=P('g');p.a=P('u');p.b=P('s');p.c=P('t');p.t=[0,1,2,3,4,5,6,7].map(i=>P('tex'+i)||P('utex'+i)||P('atex'+i)||P('uatex'+i));while((P=p.t.length)&&!p.t[P-1])p.t.pop();return p};N.autoCanvas=k=>{(P=document).documentElement.append(P=P.createElement('canvas'))
P.style='position:fixed;top:0;left:0;border:0;padding:0;margin:0;transform-origin:0 0';const c=P,x=N.setTargetCanvas(c),v=visualViewport,r=requestAnimationFrame;let l=9,d,f;r(f=()=>{r(f);x.resize(Math.round(v.width*v.scale*(d=devicePixelRatio)),Math.round(v.height*v.scale*d));c.style.transform=`scale(${1/d})`;x.reset(d/x.width,0,0,d/x.height,0,0);k(x.width/d,x.height/d,Math.min(1,l-(l=performance.now()*-.001)))});return x}}