-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathuv.min.js
48 lines (48 loc) · 21.9 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
{let g=null,v,Z=0,y=0,U=0,P,Q,j=g,O=0,L=0,G=g,C,D,E,H,l,W=-1,S=0,T=0,z=(a,b)=>W!=(W&=~a)?console.warn(b):void 0;const N=globalThis[(P=document.currentScript.src)&&new URL(P).hash.slice(1)||'globalThis']??={},B=Array(32).fill(g),R={imageOrientation:'flipY',premultiplyAlpha:'none'},Y=class{fromSrc(s,a,b,o){this.from(typeof s=='string'?fetch(s,o).then(a=>a.blob()):s,a,b);return this}from(t,F=N.Formats.RGBA,o=Z){if(typeof t!='object')return
this.format=F;this.o=o;if(t instanceof Blob)t=createImageBitmap(t,R);if(t.then)return t.then(t=>this.from(t,F,o));if(this.layers&&this.u>=0)U!=(U=this.u)&&g.activeTexture(33984+U),g.bindTexture(this.layers?35866:3553,B[U]=null),this.u=-1;this.layers=0;$(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}get options(){return this.o}set options(o){this.o=o||=Z;const b=$(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;$(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){if((!this.layers^!l)&&this.u>=0)U!=(U=this.u)&&g.activeTexture(33984+U),g.bindTexture(this.layers?35866:3553,B[U]=null),this.u=-1;this.layers=l;const b=$(this);this.o=o;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(d,x=0,y=0,w=this.width,h=this.height,F=this.format){if($(this)>4e3)return;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){if($(this)<4e3)return;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);if(P=this.u){U!=(U=P|0)&&g.activeTexture(33984+U);this.u=-1;g.bindTexture(P<99?3553:35866,B[U]=null)}}}.prototype,X=(t,b)=>{t.u=U+(t.layers&&4294967296);B[U]&&(B[U].u!=t.u&&g.bindTexture(39419-b,null),B[U].u=-1);g.bindTexture(b,B[U]=t);t.m==3&&g.generateMipmap(b);return b},$=t=>{const b=t.layers?35866:3553;if(t.u>=0)return g.activeTexture(33984+(U=t.u|0)),b;if(U!=y)g.activeTexture(33984+(U=y));X(t,b);return b},F=Float32Array,V=[],J=function(s=0,l=this.l-s,t=this.t){return{t,b:this.b,s:this.s+s,l,sub:J}}
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,P=36244,5121],RG8:[33336,33320,5121],RGB8:[36221,36248,5121],RGBA8:[36220,36249,5121],R16:[33332,P,5123],RG16:[33338,33320,5123],RGB16:[36215,36248,5123],RGBA16:[36214,36249,5123],R32:[33334,P,5125],RG32:[33340,33320,5125],RGB32:[36209,36248,5125],RGBA32:[36208,36249,5125],R16F:[33325,6403,5131],RG16F:[33327,33319,5131],RGB16F:[34843,6407,5131],RGBA16F:[34842,6408,5131],R16F_32F:[33325,6403,5126],RG16F_32F:[33327,33319,5126],RGB16F_32F:[34843,6407,5126],RGBA16F_32F:[34842,6408,5126],R32F:[33326,6403,5126],RG32F:[33328,33319,5126],RGB32F:[34837,6407,5126],RGBA32F:[34836,6408,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.setDefaultOptions=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();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,B=this.#b;this.#a=A*x-this.#c*y;this.#b=B*x-this.#d*y;this.#c=A*y+this.#c*x
this.#d=B*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)}resetTo(m){this.#a=m.#a;this.#b=m.#b;this.#c=m.#c;this.#d=m.#d;this.#e=m.#e;this.#f=m.#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);g.bindBuffer(34962,v.s=l);g.vertexAttribPointer(5,2,5126,0,0,0);for(let i=0;i<6;)g.enableVertexAttribArray(i),g.vertexAttribDivisor(i,i++<5);v.size=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 size(){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 z(16,'.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)}
N.Geometry=(t=5,p)=>{p instanceof F||(p=new F((P=p).length),p.set(P,0));g.bindBuffer(34962,P=g.createBuffer());g.bufferData(34962,p,35044);return{t,b:P,s:P=0,l:p.length>>1,sub:J}};const I=new F(6);class K{j;p;m;k;#a;#b;#c;#d;#e;#f;get width(){return(this.j||g.canvas).width}get height(){return(this.j||g.canvas).height}get texture(){return this.j?.t}getData(x=0,y=0,w=this.width,h=this.height,a=null){if(j!=(j=this.j))g.bindFramebuffer(36160,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);$(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(F!=N.Formats.RGBA)z(1,'Browser does not support specifying format for main target');D=F}}setTexture(T,L=0){const{j}=this;if(!j)return z(2,'Cannot attach a texture to the main target (its output must always be the <canvas>, use .resize() to change size/format)');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=Q,m=581575183,k=H,a=1,b=0,c=0,d=1,e=0,f=0){this.j=j;this.p=p;this.m=m;this.k=k;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,B=this.#b;this.#a=A*x-this.#c*y;this.#b=B*x-this.#d*y;this.#c=A*y+this.#c*x;this.#d=B*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,581575183,H,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;this.p=Q;this.m=581575183;this.k=H}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.p=t.p;this.m=t.m;this.k=t.k}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.m,this.k,this.#a,this.#b,this.#c,this.#d,this.#e,this.#f)}set shader(p){this.p=p||Q}get shader(){return this.p}set geometry(k){this.k=k||H}get geometry(){return this.k}get blend(){return this.m>>>9}set blend(a){this.m=this.m&511|a<<9}get mask(){return this.m&511}set mask(a){this.m=this.m&-512|a&511}clear(r=0,g=0,b=0,a=0){g.clearColor(r,g,b,a);const M=this.m&15;if(L!=(L=L&-16|M))g.colorMask(M&1,M&2,M&4,M&8)
if(j!=(j=this.j))g.bindFramebuffer(36160,j);const W=(j||g.canvas).width,H=(j||g.canvas).height;if(W|H){if(S!=W||T!=H)g.viewport(0,0,S=W,T=H);g.clear((j?j.S=j.S+1&7:O=O+1&7)?16384:(g.stencilMask(255),g.disable(2960),L&=-241,17408))}}clearColor(r=0,g=0,b=0,a=0){g.clearColor(r,g,b,a);const M=this.m&15;if(L!=(L=L&-16|M))g.colorMask(M&1,M&2,M&4,M&8);if(j!=(j=this.j))g.bindFramebuffer(36160,j);const W=(j||g.canvas).width,H=(j||g.canvas).height;if(W|H){if(S!=W||T!=H)g.viewport(0,0,S=W,T=H);g.clear(16384)}}clearStencil(){const x=this.j;if(!(x?x.S=x.S+1&7:O=O+1&7)){if(j!=x)g.bindFramebuffer(36160,j=x);const W=(j||g.canvas).width,H=(j||g.canvas).height
if(W|H){if(S!=W||T!=H)g.viewport(0,0,S=W,T=H);g.stencilMask(255);g.clear(1024);g.disable(2960);L&=-241}}}draw(K,e,J=0,H=0,a=0,c=0,d=0,f=0,D=1e999){if(j!=(j=this.j))g.bindFramebuffer(36160,j);{const W=(j||g.canvas).width,A=(j||g.canvas).height;if(!W|!A)return;if(S!=W||T!=A)g.viewport(0,0,S=W,T=A)}if(E!=(E=this.p))g.useProgram(E);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.g,0,I);if(E.a!=a||E.b!=c||E.c!=d||E.d!=f)g.uniform4f(E.u,E.a=a,E.b=c,E.c=d,E.d=f);if(E.e!=J)g.uniform1f(E.s,E.e=J);if(E.f!=H)g.uniform1f(E.t,E.f=H);const {k,m}=this,Q=L^m,b=this.j?.t
if(Q&15)g.colorMask(m&1,m&2,m&4,m&8);if(Q&240){if(m&240){if(!(L&240))g.enable(2960);g.stencilMask(L=1<<(j?j.S:O));g.stencilFunc(m&32?m&16?512:517:m&16?514:519,255,L);g.stencilOp(L=m&128?m&64?5386:7681:m&64?0:7680,L,L)}else g.disable(2960)}if(Q&0xEE000000)g.blendEquationSeparate((m>>25&7)+32773,(m>>29&7)+32773);if(Q&33553920)g.blendFuncSeparate((m>>9&15)+(m&7168&&766),(m>>17&15)+(m&1835008&&766),(m>>13&15)+(m&114688&&766),(m>>21&15)+(m&29360128&&766));if(Q&256)m&256?g.enable(3024):g.disable(3024);L=m;if(Array.isArray(e)){if(e.length<E.T.length||e.length>16)return z(4,'.draw(): Shader expects '+E.T.length+' texture(s)');let v=-1,i=v;while(++i<e.length){const t=e[i]
if(t==b)return z(8,'.draw(): Cannot use a texture that is also being drawn to');if(t.u>-1){v&=~(1<<(31-t.u));g.uniform1i(E.T[i],t.u);if(t.m==3){if(U!=(U=t.u|0))g.activeTexture(33984+U);g.generateMipmap(t.layers?35866:3553)}}}for(i=-1;++i<e.length;){const t=e[i];if(t.u>-1)continue;U=Math.clz32(v);v&=~(1<<(31-U));g.activeTexture(33984+U);X(t,t.layers?35866:3553);g.uniform1i(E.T[i],U)}y=Math.clz32(v)}else if(e){if(E.T.length>1)return z(4,'.draw(): Shader expects '+E.T.length+' texture(s)');if(e==b)return z(8,'.draw(): Cannot use a texture that is also being drawn to');if(e.u>-1){g.uniform1i(E.T[0],e.u);if(e.m==3){if(U!=(U=e.u|0))g.activeTexture(33984+U);g.generateMipmap(e.layers?35866:3553)}}else{X(e,e.layers?35866:3553)
g.uniform1i(E.T[0],U)}y=+!e.u}if(b)b.m|=1;if(K instanceof WebGLVertexArrayObject){if(G!=K)g.bindVertexArray(G=K);let o=K.s;if(o!=(o=this.k.b)){g.bindBuffer(34962,K.s=o);g.vertexAttribPointer(5,2,5126,0,0,0)}g.drawArraysInstanced(k.t,k.s,k.l,Math.min(D,K.size));return}if(G)g.bindVertexArray(G=null);if(l!=(l=this.k.b)){g.bindBuffer(34962,l);g.vertexAttribPointer(5,2,5126,0,0,0)}g.bindBuffer(34962,C);if(K.byteLength){g.bufferData(34962,K,35040)
g.drawArraysInstanced(k.t,k.s,k.l,Math.min(D,K.byteLength/64))}else{if(!K.R.l)return z(64,'.draw(): Mesh has already been consumed. Use .upload() if you want to draw the mesh more than once');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(k.t,k.s,k.l,Math.min(D,K.size))
K.delete()}}delete(){const{j}=this;if(j){g.deleteFramebuffer(j);if(j.X)g.deleteRenderbuffer(j.X);if(j.Y)g.deleteRenderbuffer(j.Y)}}}N.setTargetCanvas=z=>{g=N.gl=z.getContext('webgl2',{preserveDrawingBuffer:0,antialias:0,depth:0,premultipliedAlpha:1,stencil:1});g.pixelStorei(37440,1);g.bindBuffer(34962,C=g.createBuffer())
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);g.bindBuffer(34962,l=(H=N.Geometry(5,[0,0,0,1,1,0,1,1])).b);g.vertexAttribPointer(5,2,5126,0,0,0);P=6;while(P-->0)g.enableVertexAttribArray(P),g.vertexAttribDivisor(P,P<5);v=g.createShader(35633);g.shaderSource(v,`#version 300 es
uniform mat2x3 g;in mat2x3 m;in vec4 u;in vec4 t;in vec2 V,P;out vec3 uv;out vec2 pos,xy;flat out float effect;flat out vec4 tint;void main(){gl_PointSize=1.;gl_Position=vec4(vec3(xy=vec3(pos=P,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=570434063;O=S=T=0;return new K(null)}
Object.assign(N,{R:1,G:2,B:4,A:8,RGB:7,RGBA:15,IF_SET:16,IF_UNSET:32,NO_DRAW:48,UNSET:64,SET:128,FLIP:192,DITHERING:256,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,NORM:0,FLOAT:1,UINT:2,LAYERED:4,TRIANGLE_STRIP:5,TRIANGLES:4,TRIANGLE_FAN:6,LINE_LOOP:2,LINE_STRIP:3,LINES:1,POINTS:0,_:void 0,colorSpace:t=>{g.drawingBufferColorSpace=t},gl:null})
P.REPLACE=1114129;P.DEFAULT=1135889;N.PI2??=(N.PI??=Math.PI)*2;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)};N.Shader=(s,t=[],w=0)=>{let U='',R=-1;for(P=0;P<16;P++)U+=R==(R=t[P]||0)?',tex'+P:';uniform '+(R&3?R&2?'highp u':'highp ':'lowp ')+'sampler2D'+(R&4?'Array tex':' tex')+P;const p=g.createProgram(),f=g.createShader(35632);g.shaderSource(f,`#version 300 es
precision mediump float;precision highp int;in vec3 uv;in vec2 pos,xy;flat in float effect;flat in vec4 tint;out ${w?w>1?'u':'highp ':'lowp '}vec4 color${U};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
out lowp 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.g=P('g');p.u=P('u');p.s=P('s');p.t=P('t');p.a=p.b=p.c=p.d=p.e=p.f=0;p.T=Array.from({length:16},(_,i)=>P('tex'+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),r=requestAnimationFrame;let l=performance.now()*-.001,d,f;r(f=()=>{r(f);x.resize(Math.round(innerWidth*(d=devicePixelRatio)),Math.round(innerHeight*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}}