@footgun/cobalt 0.7.2 → 0.7.4
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.
- package/CHANGELOG.md +9 -0
- package/bundle.js +2 -2
- package/package.json +1 -1
- package/src/fb-texture/fb-texture.js +1 -1
- package/src/spritesheet/spritesheet.js +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
|
+
# 0.7.4
|
|
2
|
+
* bugfix: make destroy method work for spritesheet nodes
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
# 0.7.3
|
|
6
|
+
* bugfix: make destroy method work for fb texture
|
|
7
|
+
|
|
8
|
+
|
|
1
9
|
# 0.7.2
|
|
2
10
|
* bugfix: make destroy method work for HDR tile nodes
|
|
3
11
|
|
|
12
|
+
|
|
4
13
|
# 0.7.1
|
|
5
14
|
* bugfix: make destroy method work on tileAtlas node
|
|
6
15
|
|
package/bundle.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
var Os=Object.create;var ln=Object.defineProperty;var ms=Object.getOwnPropertyDescriptor;var Vs=Object.getOwnPropertyNames;var qs=Object.getPrototypeOf,Ns=Object.prototype.hasOwnProperty;var xt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),hn=(e,t)=>{for(var n in t)ln(e,n,{get:t[n],enumerable:!0})},Cs=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Vs(t))!Ns.call(e,i)&&i!==n&&ln(e,i,{get:()=>t[i],enumerable:!(r=ms(t,i))||r.enumerable});return e};var pi=(e,t,n)=>(n=e!=null?Os(qs(e)):{},Cs(t||!e||!e.__esModule?ln(n,"default",{value:e,enumerable:!0}):n,e));var je=xt((_1,Ii)=>{"use strict";function bu(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h>=0?(o=s,i=s-1):r=s+1}return o}function Tu(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h>0?(o=s,i=s-1):r=s+1}return o}function Pu(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h<0?(o=s,r=s+1):i=s-1}return o}function Su(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h<=0?(o=s,r=s+1):i=s-1}return o}function _u(e,t,n,r,i){for(;r<=i;){var o=r+i>>>1,s=e[o],f=n!==void 0?n(s,t):s-t;if(f===0)return o;f<=0?r=o+1:i=o-1}return-1}function Je(e,t,n,r,i,o){return typeof n=="function"?o(e,t,n,r===void 0?0:r|0,i===void 0?e.length-1:i|0):o(e,t,void 0,n===void 0?0:n|0,r===void 0?e.length-1:r|0)}Ii.exports={ge:function(e,t,n,r,i){return Je(e,t,n,r,i,bu)},gt:function(e,t,n,r,i){return Je(e,t,n,r,i,Tu)},lt:function(e,t,n,r,i){return Je(e,t,n,r,i,Pu)},le:function(e,t,n,r,i){return Je(e,t,n,r,i,Su)},eq:function(e,t,n,r,i){return Je(e,t,n,r,i,_u)}}});var Tr=xt((B1,mi)=>{"use strict";mi.exports=Bu;var Oi=+(Math.pow(2,27)+1);function Bu(e,t,n){var r=e*t,i=Oi*e,o=i-e,s=i-o,f=e-s,h=Oi*t,p=h-t,g=h-p,D=t-g,X=r-s*g,N=X-f*g,I=N-s*D,V=f*D-I;return n?(n[0]=V,n[1]=r,n):[V,r]}});var gn=xt((D1,Vi)=>{"use strict";Vi.exports=Uu;function Du(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,f=s+o;return f?[f,n]:[n]}function Uu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return Du(e[0],t[0]);var i=n+r,o=new Array(i),s=0,f=0,h=0,p=Math.abs,g=e[f],D=p(g),X=t[h],N=p(X),I,V;D<N?(V=g,f+=1,f<n&&(g=e[f],D=p(g))):(V=X,h+=1,h<r&&(X=t[h],N=p(X))),f<n&&D<N||h>=r?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=t[h],N=p(X)));for(var q=I+V,Y=q-I,K=V-Y,Q=K,tt=q,H,W,st,et,rt;f<n&&h<r;)D<N?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=t[h],N=p(X))),V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H;for(;f<n;)I=g,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,f+=1,f<n&&(g=e[f]);for(;h<r;)I=X,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,h+=1,h<r&&(X=t[h]);return Q&&(o[s++]=Q),tt&&(o[s++]=tt),s||(o[s++]=0),o.length=s,o}});var Ni=xt((U1,qi)=>{"use strict";qi.exports=Fu;function Fu(e,t,n){var r=e+t,i=r-e,o=r-i,s=t-i,f=e-o;return n?(n[0]=f+s,n[1]=r,n):[f+s,r]}});var xn=xt((F1,Ci)=>{"use strict";var wn=Tr(),Gu=Ni();Ci.exports=Au;function Au(e,t){var n=e.length;if(n===1){var r=wn(e[0],t);return r[0]?r:[r[1]]}var i=new Array(2*n),o=[.1,.1],s=[.1,.1],f=0;wn(e[0],t,o),o[0]&&(i[f++]=o[0]);for(var h=1;h<n;++h){wn(e[h],t,s);var p=o[1];Gu(p,s[0],o),o[0]&&(i[f++]=o[0]);var g=s[1],D=o[1],X=g+D,N=X-g,I=D-N;o[1]=X,I&&(i[f++]=I)}return o[1]&&(i[f++]=o[1]),f===0&&(i[f++]=0),i.length=f,i}});var yn=xt((G1,Xi)=>{"use strict";Xi.exports=Lu;function zu(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,f=s+o;return f?[f,n]:[n]}function Lu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return zu(e[0],-t[0]);var i=n+r,o=new Array(i),s=0,f=0,h=0,p=Math.abs,g=e[f],D=p(g),X=-t[h],N=p(X),I,V;D<N?(V=g,f+=1,f<n&&(g=e[f],D=p(g))):(V=X,h+=1,h<r&&(X=-t[h],N=p(X))),f<n&&D<N||h>=r?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=-t[h],N=p(X)));for(var q=I+V,Y=q-I,K=V-Y,Q=K,tt=q,H,W,st,et,rt;f<n&&h<r;)D<N?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=-t[h],N=p(X))),V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H;for(;f<n;)I=g,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,f+=1,f<n&&(g=e[f]);for(;h<r;)I=X,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,h+=1,h<r&&(X=-t[h]);return Q&&(o[s++]=Q),tt&&(o[s++]=tt),s||(o[s++]=0),o.length=s,o}});var bn=xt((A1,Mn)=>{"use strict";var Eu=Tr(),Ru=gn(),Iu=xn(),Ou=yn(),ki=5,Pr=11102230246251565e-32,mu=(3+16*Pr)*Pr,Vu=(7+56*Pr)*Pr;function qu(e,t,n,r){return function(o,s,f){var h=e(e(t(s[1],f[0]),t(-f[1],s[0])),e(t(o[1],s[0]),t(-s[1],o[0]))),p=e(t(o[1],f[0]),t(-f[1],o[0])),g=r(h,p);return g[g.length-1]}}function Nu(e,t,n,r){return function(o,s,f,h){var p=e(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),h[2]))),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),h[2])))),g=e(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),h[2]))),e(n(e(t(s[1],f[0]),t(-f[1],s[0])),o[2]),e(n(e(t(o[1],f[0]),t(-f[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),f[2])))),D=r(p,g);return D[D.length-1]}}function Cu(e,t,n,r){return function(o,s,f,h,p){var g=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),f[2]),e(n(e(t(f[1],p[0]),t(-p[1],f[0])),-h[2]),n(e(t(f[1],h[0]),t(-h[1],f[0])),p[2]))),s[3]),e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-h[2]),n(e(t(s[1],h[0]),t(-h[1],s[0])),p[2]))),-f[3]),n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),p[2]))),h[3]))),e(n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),h[2]))),-p[3]),e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-h[2]),n(e(t(s[1],h[0]),t(-h[1],s[0])),p[2]))),o[3]),n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-h[2]),n(e(t(o[1],h[0]),t(-h[1],o[0])),p[2]))),-s[3])))),e(e(n(e(n(e(t(s[1],p[0]),t(-p[1],s[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),p[2]))),h[3]),e(n(e(n(e(t(s[1],h[0]),t(-h[1],s[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),h[2]))),-p[3]),n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),h[2]))),o[3]))),e(n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),h[2]))),-s[3]),e(n(e(n(e(t(s[1],h[0]),t(-h[1],s[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),h[2]))),f[3]),n(e(n(e(t(s[1],f[0]),t(-f[1],s[0])),o[2]),e(n(e(t(o[1],f[0]),t(-f[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),f[2]))),-h[3]))))),D=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),f[2]),e(n(e(t(f[1],p[0]),t(-p[1],f[0])),-h[2]),n(e(t(f[1],h[0]),t(-h[1],f[0])),p[2]))),o[3]),n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-h[2]),n(e(t(o[1],h[0]),t(-h[1],o[0])),p[2]))),-f[3])),e(n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),p[2]))),h[3]),n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),h[2]))),-p[3]))),e(e(n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),p[2]))),o[3]),n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),p[2]))),-s[3])),e(n(e(n(e(t(s[1],p[0]),t(-p[1],s[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),p[2]))),f[3]),n(e(n(e(t(s[1],f[0]),t(-f[1],s[0])),o[2]),e(n(e(t(o[1],f[0]),t(-f[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),f[2]))),-p[3])))),X=r(g,D);return X[X.length-1]}}function Sr(e){var t=e===3?qu:e===4?Nu:Cu;return t(Ru,Eu,Iu,Ou)}var Xu=Sr(3),ku=Sr(4),De=[function(){return 0},function(){return 0},function(t,n){return n[0]-t[0]},function(t,n,r){var i=(t[1]-r[1])*(n[0]-r[0]),o=(t[0]-r[0])*(n[1]-r[1]),s=i-o,f;if(i>0){if(o<=0)return s;f=i+o}else if(i<0){if(o>=0)return s;f=-(i+o)}else return s;var h=mu*f;return s>=h||s<=-h?s:Xu(t,n,r)},function(t,n,r,i){var o=t[0]-i[0],s=n[0]-i[0],f=r[0]-i[0],h=t[1]-i[1],p=n[1]-i[1],g=r[1]-i[1],D=t[2]-i[2],X=n[2]-i[2],N=r[2]-i[2],I=s*g,V=f*p,q=f*h,Y=o*g,K=o*p,Q=s*h,tt=D*(I-V)+X*(q-Y)+N*(K-Q),H=(Math.abs(I)+Math.abs(V))*Math.abs(D)+(Math.abs(q)+Math.abs(Y))*Math.abs(X)+(Math.abs(K)+Math.abs(Q))*Math.abs(N),W=Vu*H;return tt>W||-tt>W?tt:ku(t,n,r,i)}];function Yu(e){var t=De[e.length];return t||(t=De[e.length]=Sr(e.length)),t.apply(void 0,e)}function Hu(e,t,n,r,i,o,s){return function(h,p,g,D,X){switch(arguments.length){case 0:case 1:return 0;case 2:return r(h,p);case 3:return i(h,p,g);case 4:return o(h,p,g,D);case 5:return s(h,p,g,D,X)}for(var N=new Array(arguments.length),I=0;I<arguments.length;++I)N[I]=arguments[I];return e(N)}}function Zu(){for(;De.length<=ki;)De.push(Sr(De.length));Mn.exports=Hu.apply(void 0,[Yu].concat(De));for(var e=0;e<=ki;++e)Mn.exports[e]=De[e]}Zu()});var Ki=xt((z1,Wi)=>{"use strict";var _r=je(),be=bn()[3],Pn=0,Yi=1,Tn=2;Wi.exports=Ju;function Zi(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function tr(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function $u(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==Pn&&(n=be(e.a,e.b,t.b),n)?n:e.idx-t.idx}function Hi(e,t){return be(e.a,e.b,t)}function Wu(e,t,n,r,i){for(var o=_r.lt(t,r,Hi),s=_r.gt(t,r,Hi),f=o;f<s;++f){for(var h=t[f],p=h.lowerIds,D=p.length;D>1&&be(n[p[D-2]],n[p[D-1]],r)>0;)e.push([p[D-1],p[D-2],i]),D-=1;p.length=D,p.push(i);for(var g=h.upperIds,D=g.length;D>1&&be(n[g[D-2]],n[g[D-1]],r)<0;)e.push([g[D-2],g[D-1],i]),D-=1;g.length=D,g.push(i)}}function $i(e,t){var n;return e.a[0]<t.a[0]?n=be(e.a,e.b,t.a):n=be(t.b,t.a,e.a),n||(t.b[0]<e.b[0]?n=be(e.a,e.b,t.b):n=be(t.b,t.a,e.b),n||e.idx-t.idx)}function Ku(e,t,n){var r=_r.le(e,n,$i),i=e[r],o=i.upperIds,s=o[o.length-1];i.upperIds=[s],e.splice(r+1,0,new Zi(n.a,n.b,n.idx,[s],o))}function Qu(e,t,n){var r=n.a;n.a=n.b,n.b=r;var i=_r.eq(e,n,$i),o=e[i],s=e[i-1];s.upperIds=o.upperIds,e.splice(i,1)}function Ju(e,t){for(var n=e.length,r=t.length,i=[],o=0;o<n;++o)i.push(new tr(e[o],null,Pn,o));for(var o=0;o<r;++o){var s=t[o],f=e[s[0]],h=e[s[1]];f[0]<h[0]?i.push(new tr(f,h,Tn,o),new tr(h,f,Yi,o)):f[0]>h[0]&&i.push(new tr(h,f,Tn,o),new tr(f,h,Yi,o))}i.sort($u);for(var p=i[0].a[0]-(1+Math.abs(i[0].a[0]))*Math.pow(2,-52),g=[new Zi([p,1],[p,0],-1,[],[],[],[])],D=[],o=0,X=i.length;o<X;++o){var N=i[o],I=N.type;I===Pn?Wu(D,g,e,N.a,N.idx):I===Tn?Ku(g,e,N):Qu(g,e,N)}return D}});var ji=xt((L1,Ji)=>{"use strict";var ju=je();Ji.exports=t0;function Qi(e,t){this.stars=e,this.edges=t}var Ue=Qi.prototype;function Sn(e,t,n){for(var r=1,i=e.length;r<i;r+=2)if(e[r-1]===t&&e[r]===n){e[r-1]=e[i-2],e[r]=e[i-1],e.length=i-2;return}}Ue.isConstraint=(function(){var e=[0,0];function t(n,r){return n[0]-r[0]||n[1]-r[1]}return function(n,r){return e[0]=Math.min(n,r),e[1]=Math.max(n,r),ju.eq(this.edges,e,t)>=0}})();Ue.removeTriangle=function(e,t,n){var r=this.stars;Sn(r[e],t,n),Sn(r[t],n,e),Sn(r[n],e,t)};Ue.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)};Ue.opposite=function(e,t){for(var n=this.stars[t],r=1,i=n.length;r<i;r+=2)if(n[r]===e)return n[r-1];return-1};Ue.flip=function(e,t){var n=this.opposite(e,t),r=this.opposite(t,e);this.removeTriangle(e,t,n),this.removeTriangle(t,e,r),this.addTriangle(e,r,n),this.addTriangle(t,n,r)};Ue.edges=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],o=0,s=i.length;o<s;o+=2)t.push([i[o],i[o+1]]);return t};Ue.cells=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],o=0,s=i.length;o<s;o+=2){var f=i[o],h=i[o+1];n<Math.min(f,h)&&t.push([n,f,h])}return t};function t0(e,t){for(var n=new Array(e),r=0;r<e;++r)n[r]=[];return new Qi(n,t)}});var ro=xt((E1,_n)=>{"use strict";var e0=Tr(),r0=gn(),n0=yn(),i0=xn(),to=6;function eo(e){var t=e===3?u0:e===4?f0:e===5?c0:l0;return t(r0,n0,e0,i0)}function o0(){return 0}function a0(){return 0}function s0(){return 0}function u0(e,t,n,r){function i(o,s,f){var h=n(o[0],o[0]),p=r(h,s[0]),g=r(h,f[0]),D=n(s[0],s[0]),X=r(D,o[0]),N=r(D,f[0]),I=n(f[0],f[0]),V=r(I,o[0]),q=r(I,s[0]),Y=e(t(q,N),t(X,p)),K=t(V,g),Q=t(Y,K);return Q[Q.length-1]}return i}function f0(e,t,n,r){function i(o,s,f,h){var p=e(n(o[0],o[0]),n(o[1],o[1])),g=r(p,s[0]),D=r(p,f[0]),X=r(p,h[0]),N=e(n(s[0],s[0]),n(s[1],s[1])),I=r(N,o[0]),V=r(N,f[0]),q=r(N,h[0]),Y=e(n(f[0],f[0]),n(f[1],f[1])),K=r(Y,o[0]),Q=r(Y,s[0]),tt=r(Y,h[0]),H=e(n(h[0],h[0]),n(h[1],h[1])),W=r(H,o[0]),st=r(H,s[0]),et=r(H,f[0]),rt=e(e(r(t(et,tt),s[1]),e(r(t(st,q),-f[1]),r(t(Q,V),h[1]))),e(r(t(st,q),o[1]),e(r(t(W,X),-s[1]),r(t(I,g),h[1])))),U=e(e(r(t(et,tt),o[1]),e(r(t(W,X),-f[1]),r(t(K,D),h[1]))),e(r(t(Q,V),o[1]),e(r(t(K,D),-s[1]),r(t(I,g),f[1])))),a=t(rt,U);return a[a.length-1]}return i}function c0(e,t,n,r){function i(o,s,f,h,p){var g=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),D=r(g,s[0]),X=r(g,f[0]),N=r(g,h[0]),I=r(g,p[0]),V=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),q=r(V,o[0]),Y=r(V,f[0]),K=r(V,h[0]),Q=r(V,p[0]),tt=e(n(f[0],f[0]),e(n(f[1],f[1]),n(f[2],f[2]))),H=r(tt,o[0]),W=r(tt,s[0]),st=r(tt,h[0]),et=r(tt,p[0]),rt=e(n(h[0],h[0]),e(n(h[1],h[1]),n(h[2],h[2]))),U=r(rt,o[0]),a=r(rt,s[0]),v=r(rt,f[0]),T=r(rt,p[0]),M=e(n(p[0],p[0]),e(n(p[1],p[1]),n(p[2],p[2]))),S=r(M,o[0]),L=r(M,s[0]),O=r(M,f[0]),B=r(M,h[0]),l=e(e(e(r(e(r(t(B,T),f[1]),e(r(t(O,et),-h[1]),r(t(v,st),p[1]))),s[2]),e(r(e(r(t(B,T),s[1]),e(r(t(L,Q),-h[1]),r(t(a,K),p[1]))),-f[2]),r(e(r(t(O,et),s[1]),e(r(t(L,Q),-f[1]),r(t(W,Y),p[1]))),h[2]))),e(r(e(r(t(v,st),s[1]),e(r(t(a,K),-f[1]),r(t(W,Y),h[1]))),-p[2]),e(r(e(r(t(B,T),s[1]),e(r(t(L,Q),-h[1]),r(t(a,K),p[1]))),o[2]),r(e(r(t(B,T),o[1]),e(r(t(S,I),-h[1]),r(t(U,N),p[1]))),-s[2])))),e(e(r(e(r(t(L,Q),o[1]),e(r(t(S,I),-s[1]),r(t(q,D),p[1]))),h[2]),e(r(e(r(t(a,K),o[1]),e(r(t(U,N),-s[1]),r(t(q,D),h[1]))),-p[2]),r(e(r(t(v,st),s[1]),e(r(t(a,K),-f[1]),r(t(W,Y),h[1]))),o[2]))),e(r(e(r(t(v,st),o[1]),e(r(t(U,N),-f[1]),r(t(H,X),h[1]))),-s[2]),e(r(e(r(t(a,K),o[1]),e(r(t(U,N),-s[1]),r(t(q,D),h[1]))),f[2]),r(e(r(t(W,Y),o[1]),e(r(t(H,X),-s[1]),r(t(q,D),f[1]))),-h[2]))))),G=e(e(e(r(e(r(t(B,T),f[1]),e(r(t(O,et),-h[1]),r(t(v,st),p[1]))),o[2]),r(e(r(t(B,T),o[1]),e(r(t(S,I),-h[1]),r(t(U,N),p[1]))),-f[2])),e(r(e(r(t(O,et),o[1]),e(r(t(S,I),-f[1]),r(t(H,X),p[1]))),h[2]),r(e(r(t(v,st),o[1]),e(r(t(U,N),-f[1]),r(t(H,X),h[1]))),-p[2]))),e(e(r(e(r(t(O,et),s[1]),e(r(t(L,Q),-f[1]),r(t(W,Y),p[1]))),o[2]),r(e(r(t(O,et),o[1]),e(r(t(S,I),-f[1]),r(t(H,X),p[1]))),-s[2])),e(r(e(r(t(L,Q),o[1]),e(r(t(S,I),-s[1]),r(t(q,D),p[1]))),f[2]),r(e(r(t(W,Y),o[1]),e(r(t(H,X),-s[1]),r(t(q,D),f[1]))),-p[2])))),ot=t(l,G);return ot[ot.length-1]}return i}function l0(e,t,n,r){function i(o,s,f,h,p,g){var D=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),X=r(D,s[0]),N=r(D,f[0]),I=r(D,h[0]),V=r(D,p[0]),q=r(D,g[0]),Y=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),K=r(Y,o[0]),Q=r(Y,f[0]),tt=r(Y,h[0]),H=r(Y,p[0]),W=r(Y,g[0]),st=e(e(n(f[0],f[0]),n(f[1],f[1])),e(n(f[2],f[2]),n(f[3],f[3]))),et=r(st,o[0]),rt=r(st,s[0]),U=r(st,h[0]),a=r(st,p[0]),v=r(st,g[0]),T=e(e(n(h[0],h[0]),n(h[1],h[1])),e(n(h[2],h[2]),n(h[3],h[3]))),M=r(T,o[0]),S=r(T,s[0]),L=r(T,f[0]),O=r(T,p[0]),B=r(T,g[0]),l=e(e(n(p[0],p[0]),n(p[1],p[1])),e(n(p[2],p[2]),n(p[3],p[3]))),G=r(l,o[0]),ot=r(l,s[0]),at=r(l,f[0]),ut=r(l,h[0]),ft=r(l,g[0]),yt=e(e(n(g[0],g[0]),n(g[1],g[1])),e(n(g[2],g[2]),n(g[3],g[3]))),pt=r(yt,o[0]),k=r(yt,s[0]),$=r(yt,f[0]),F=r(yt,h[0]),c=r(yt,p[0]),b=e(e(e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),f[2]),r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),p[2]),r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),-g[2]))),s[3]),e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-h[2])),e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),p[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-g[2]))),-f[3]),r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),s[2]),r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),s[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-f[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-h[2])),e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),p[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-h[2])),e(r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),p[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),p[2]),r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),-g[2]))),h[3]),r(e(e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),s[2]),r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-g[2]))),o[3]))),e(e(r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-g[2]))),-s[3]),r(e(e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-g[2]))),f[3])),e(r(e(e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-g[2]))),-h[3]),r(e(e(r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-s[2])),e(r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-h[2]))),g[3]))))),w=e(e(e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),f[2]),r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),p[2]),r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),-g[2]))),o[3]),e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-h[2])),e(r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),p[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-g[2]))),-f[3]),r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-f[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),p[2]),r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),-g[2]))),f[3]),r(e(e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),s[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-f[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-p[2]))),o[3]))),e(e(r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-f[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-p[2]))),-s[3]),r(e(e(r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-p[2]))),f[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-p[2]))),-h[3]),r(e(e(r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-s[2])),e(r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-h[2]))),p[3]))))),z=t(b,w);return z[z.length-1]}return i}var Fe=[o0,a0,s0];function h0(e){var t=Fe[e.length];return t||(t=Fe[e.length]=eo(e.length)),t.apply(void 0,e)}function p0(e,t,n,r,i,o,s,f){function h(p,g,D,X,N,I){switch(arguments.length){case 0:case 1:return 0;case 2:return r(p,g);case 3:return i(p,g,D);case 4:return o(p,g,D,X);case 5:return s(p,g,D,X,N);case 6:return f(p,g,D,X,N,I)}for(var V=new Array(arguments.length),q=0;q<arguments.length;++q)V[q]=arguments[q];return e(V)}return h}function v0(){for(;Fe.length<=to;)Fe.push(eo(Fe.length));_n.exports=p0.apply(void 0,[h0].concat(Fe));for(var e=0;e<=to;++e)_n.exports[e]=Fe[e]}v0()});var io=xt((I1,no)=>{"use strict";var Bn=ro()[4],R1=je();no.exports=d0;function Br(e,t,n,r,i,o){var s=t.opposite(r,i);if(!(s<0)){if(i<r){var f=r;r=i,i=f,f=o,o=s,s=f}t.isConstraint(r,i)||Bn(e[r],e[i],e[o],e[s])<0&&n.push(r,i)}}function d0(e,t){for(var n=[],r=e.length,i=t.stars,o=0;o<r;++o)for(var s=i[o],f=1;f<s.length;f+=2){var h=s[f];if(!(h<o)&&!t.isConstraint(o,h)){for(var p=s[f-1],g=-1,D=1;D<s.length;D+=2)if(s[D-1]===h){g=s[D];break}g<0||Bn(e[o],e[h],e[p],e[g])<0&&n.push(o,h)}}for(;n.length>0;){for(var h=n.pop(),o=n.pop(),p=-1,g=-1,s=i[o],X=1;X<s.length;X+=2){var N=s[X-1],I=s[X];N===h?g=I:I===h&&(p=N)}p<0||g<0||Bn(e[o],e[h],e[p],e[g])>=0||(t.flip(o,h),Br(e,t,n,p,o,g),Br(e,t,n,o,g,p),Br(e,t,n,g,h,p),Br(e,t,n,h,p,g))}}});var uo=xt((O1,so)=>{"use strict";var g0=je();so.exports=M0;function oo(e,t,n,r,i,o,s){this.cells=e,this.neighbor=t,this.flags=r,this.constraint=n,this.active=i,this.next=o,this.boundary=s}var w0=oo.prototype;function ao(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}w0.locate=(function(){var e=[0,0,0];return function(t,n,r){var i=t,o=n,s=r;return n<r?n<t&&(i=n,o=r,s=t):r<t&&(i=r,o=t,s=n),i<0?-1:(e[0]=i,e[1]=o,e[2]=s,g0.eq(this.cells,e,ao))}})();function x0(e,t){for(var n=e.cells(),r=n.length,i=0;i<r;++i){var o=n[i],s=o[0],f=o[1],h=o[2];f<h?f<s&&(o[0]=f,o[1]=h,o[2]=s):h<s&&(o[0]=h,o[1]=s,o[2]=f)}n.sort(ao);for(var p=new Array(r),i=0;i<p.length;++i)p[i]=0;var g=[],D=[],X=new Array(3*r),N=new Array(3*r),I=null;t&&(I=[]);for(var V=new oo(n,X,N,p,g,D,I),i=0;i<r;++i)for(var o=n[i],q=0;q<3;++q){var s=o[q],f=o[(q+1)%3],Y=X[3*i+q]=V.locate(f,s,e.opposite(f,s)),K=N[3*i+q]=e.isConstraint(s,f);Y<0&&(K?D.push(i):(g.push(i),p[i]=1),t&&I.push([f,s,-1]))}return V}function y0(e,t,n){for(var r=0,i=0;i<e.length;++i)t[i]===n&&(e[r++]=e[i]);return e.length=r,e}function M0(e,t,n){var r=x0(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,o=r.active,s=r.next,f=r.flags,h=r.cells,p=r.constraint,g=r.neighbor;o.length>0||s.length>0;){for(;o.length>0;){var D=o.pop();if(f[D]!==-i){f[D]=i;for(var X=h[D],N=0;N<3;++N){var I=g[3*D+N];I>=0&&f[I]===0&&(p[3*D+N]?s.push(I):(o.push(I),f[I]=i))}}}var V=s;s=o,o=V,s.length=0,i=-i}var q=y0(h,f,t);return n?q.concat(r.boundary):q}});var co=xt((m1,fo)=>{"use strict";var b0=Ki(),T0=ji(),P0=io(),Dn=uo();fo.exports=D0;function S0(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function _0(e,t){return e[0]-t[0]||e[1]-t[1]}function B0(e){return e.map(S0).sort(_0)}function Dr(e,t,n){return t in e?e[t]:n}function D0(e,t,n){Array.isArray(t)?(n=n||{},t=t||[]):(n=t||{},t=[]);var r=!!Dr(n,"delaunay",!0),i=!!Dr(n,"interior",!0),o=!!Dr(n,"exterior",!0),s=!!Dr(n,"infinity",!1);if(!i&&!o||e.length===0)return[];var f=b0(e,t);if(r||i!==o||s){for(var h=T0(e.length,B0(t)),p=0;p<f.length;++p){var g=f[p];h.addTriangle(g[0],g[1],g[2])}return r&&P0(e,h),o?i?s?Dn(h,0,s):h.cells():Dn(h,1,s):Dn(h,-1)}else return f}});var po=xt((V1,ho)=>{"use strict";"use restrict";ho.exports=lo;function lo(e){this.roots=new Array(e),this.ranks=new Array(e);for(var t=0;t<e;++t)this.roots[t]=t,this.ranks[t]=0}var Ur=lo.prototype;Object.defineProperty(Ur,"length",{get:function(){return this.roots.length}});Ur.makeSet=function(){var e=this.roots.length;return this.roots.push(e),this.ranks.push(0),e};Ur.find=function(e){for(var t=e,n=this.roots;n[e]!==e;)e=n[e];for(;n[t]!==e;){var r=n[t];n[t]=e,t=r}return e};Ur.link=function(e,t){var n=this.find(e),r=this.find(t);if(n!==r){var i=this.ranks,o=this.roots,s=i[n],f=i[r];s<f?o[n]=r:f<s?o[r]=n:(o[r]=n,++i[n])}}});var rr=xt(Xt=>{"use strict";"use restrict";var Un=32;Xt.INT_BITS=Un;Xt.INT_MAX=2147483647;Xt.INT_MIN=-1<<Un-1;Xt.sign=function(e){return(e>0)-(e<0)};Xt.abs=function(e){var t=e>>Un-1;return(e^t)-t};Xt.min=function(e,t){return t^(e^t)&-(e<t)};Xt.max=function(e,t){return e^(e^t)&-(e<t)};Xt.isPow2=function(e){return!(e&e-1)&&!!e};Xt.log2=function(e){var t,n;return t=(e>65535)<<4,e>>>=t,n=(e>255)<<3,e>>>=n,t|=n,n=(e>15)<<2,e>>>=n,t|=n,n=(e>3)<<1,e>>>=n,t|=n,t|e>>1};Xt.log10=function(e){return e>=1e9?9:e>=1e8?8:e>=1e7?7:e>=1e6?6:e>=1e5?5:e>=1e4?4:e>=1e3?3:e>=100?2:e>=10?1:0};Xt.popCount=function(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),(e+(e>>>4)&252645135)*16843009>>>24};function vo(e){var t=32;return e&=-e,e&&t--,e&65535&&(t-=16),e&16711935&&(t-=8),e&252645135&&(t-=4),e&858993459&&(t-=2),e&1431655765&&(t-=1),t}Xt.countTrailingZeros=vo;Xt.nextPow2=function(e){return e+=e===0,--e,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+1};Xt.prevPow2=function(e){return e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e-(e>>>1)};Xt.parity=function(e){return e^=e>>>16,e^=e>>>8,e^=e>>>4,e&=15,27030>>>e&1};var er=new Array(256);(function(e){for(var t=0;t<256;++t){var n=t,r=t,i=7;for(n>>>=1;n;n>>>=1)r<<=1,r|=n&1,--i;e[t]=r<<i&255}})(er);Xt.reverse=function(e){return er[e&255]<<24|er[e>>>8&255]<<16|er[e>>>16&255]<<8|er[e>>>24&255]};Xt.interleave2=function(e,t){return e&=65535,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t&=65535,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1};Xt.deinterleave2=function(e,t){return e=e>>>t&1431655765,e=(e|e>>>1)&858993459,e=(e|e>>>2)&252645135,e=(e|e>>>4)&16711935,e=(e|e>>>16)&65535,e<<16>>16};Xt.interleave3=function(e,t,n){return e&=1023,e=(e|e<<16)&4278190335,e=(e|e<<8)&251719695,e=(e|e<<4)&3272356035,e=(e|e<<2)&1227133513,t&=1023,t=(t|t<<16)&4278190335,t=(t|t<<8)&251719695,t=(t|t<<4)&3272356035,t=(t|t<<2)&1227133513,e|=t<<1,n&=1023,n=(n|n<<16)&4278190335,n=(n|n<<8)&251719695,n=(n|n<<4)&3272356035,n=(n|n<<2)&1227133513,e|n<<2};Xt.deinterleave3=function(e,t){return e=e>>>t&1227133513,e=(e|e>>>2)&3272356035,e=(e|e>>>4)&251719695,e=(e|e>>>8)&4278190335,e=(e|e>>>16)&1023,e<<22>>22};Xt.nextCombination=function(e){var t=e|e-1;return t+1|(~t&-~t)-1>>>vo(e)+1}});var xo=xt((N1,wo)=>{"use strict";function go(e,t,n){var r=e[n]|0;if(r<=0)return[];var i=new Array(r),o;if(n===e.length-1)for(o=0;o<r;++o)i[o]=t;else for(o=0;o<r;++o)i[o]=go(e,t,n+1);return i}function U0(e,t){var n,r;for(n=new Array(e),r=0;r<e;++r)n[r]=t;return n}function F0(e,t){switch(typeof t>"u"&&(t=0),typeof e){case"number":if(e>0)return U0(e|0,t);break;case"object":if(typeof e.length=="number")return go(e,t,0);break}return[]}wo.exports=F0});var Ar=xt(zt=>{"use strict";var Fr=rr(),te=xo();globalThis.__TYPEDARRAY_POOL||(globalThis.__TYPEDARRAY_POOL={UINT8:te([32,0]),UINT16:te([32,0]),UINT32:te([32,0]),BIGUINT64:te([32,0]),INT8:te([32,0]),INT16:te([32,0]),INT32:te([32,0]),BIGINT64:te([32,0]),FLOAT:te([32,0]),DOUBLE:te([32,0]),DATA:te([32,0]),UINT8C:te([32,0])});var G0=typeof Uint8ClampedArray<"u",A0=typeof BigUint64Array<"u",z0=typeof BigInt64Array<"u",Qt=globalThis.__TYPEDARRAY_POOL;Qt.UINT8C||(Qt.UINT8C=te([32,0]));Qt.BIGUINT64||(Qt.BIGUINT64=te([32,0]));Qt.BIGINT64||(Qt.BIGINT64=te([32,0]));var Gr=Qt.DATA;zt.free=function(t){if(Object.prototype.toString.call(t)!=="[object ArrayBuffer]"&&(t=t.buffer),!!t){var n=t.length||t.byteLength,r=Fr.log2(n)|0;Gr[r].push(t)}};function yo(e){if(e){var t=e.length||e.byteLength,n=Fr.log2(t);Gr[n].push(e)}}function L0(e){yo(e.buffer)}zt.freeUint8=zt.freeUint16=zt.freeUint32=zt.freeBigUint64=zt.freeInt8=zt.freeInt16=zt.freeInt32=zt.freeBigInt64=zt.freeFloat32=zt.freeFloat=zt.freeFloat64=zt.freeDouble=zt.freeUint8Clamped=zt.freeDataView=L0;zt.freeArrayBuffer=yo;zt.malloc=function(t,n){if(n===void 0||n==="arraybuffer")return ie(t);switch(n){case"uint8":return Fn(t);case"uint16":return Mo(t);case"uint32":return bo(t);case"int8":return To(t);case"int16":return Po(t);case"int32":return So(t);case"float":case"float32":return _o(t);case"double":case"float64":return Bo(t);case"uint8_clamped":return Do(t);case"bigint64":return Fo(t);case"biguint64":return Uo(t);case"data":case"dataview":return Go(t);default:return null}return null};function ie(t){var t=Fr.nextPow2(t),n=Fr.log2(t),r=Gr[n];return r.length>0?r.pop():new ArrayBuffer(t)}zt.mallocArrayBuffer=ie;function Fn(e){return new Uint8Array(ie(e),0,e)}zt.mallocUint8=Fn;function Mo(e){return new Uint16Array(ie(2*e),0,e)}zt.mallocUint16=Mo;function bo(e){return new Uint32Array(ie(4*e),0,e)}zt.mallocUint32=bo;function To(e){return new Int8Array(ie(e),0,e)}zt.mallocInt8=To;function Po(e){return new Int16Array(ie(2*e),0,e)}zt.mallocInt16=Po;function So(e){return new Int32Array(ie(4*e),0,e)}zt.mallocInt32=So;function _o(e){return new Float32Array(ie(4*e),0,e)}zt.mallocFloat32=zt.mallocFloat=_o;function Bo(e){return new Float64Array(ie(8*e),0,e)}zt.mallocFloat64=zt.mallocDouble=Bo;function Do(e){return G0?new Uint8ClampedArray(ie(e),0,e):Fn(e)}zt.mallocUint8Clamped=Do;function Uo(e){return A0?new BigUint64Array(ie(8*e),0,e):null}zt.mallocBigUint64=Uo;function Fo(e){return z0?new BigInt64Array(ie(8*e),0,e):null}zt.mallocBigInt64=Fo;function Go(e){return new DataView(ie(e),0,e)}zt.mallocDataView=Go;zt.clearCache=function(){for(var t=0;t<32;++t)Qt.UINT8[t].length=0,Qt.UINT16[t].length=0,Qt.UINT32[t].length=0,Qt.INT8[t].length=0,Qt.INT16[t].length=0,Qt.INT32[t].length=0,Qt.FLOAT[t].length=0,Qt.DOUBLE[t].length=0,Qt.BIGUINT64[t].length=0,Qt.BIGINT64[t].length=0,Qt.UINT8C[t].length=0,Gr[t].length=0}});var Ro=xt((X1,Eo)=>{"use strict";Eo.exports=E0;var Lr=32;function E0(e,t){t<=4*Lr?Er(0,t-1,e):Rr(0,t-1,e)}function Er(e,t,n){for(var r=2*(e+1),i=e+1;i<=t;++i){for(var o=n[r++],s=n[r++],f=i,h=r-2;f-- >e;){var p=n[h-2],g=n[h-1];if(p<o)break;if(p===o&&g<s)break;n[h]=p,n[h+1]=g,h-=2}n[h]=o,n[h+1]=s}}function Ao(e,t,n){e*=2,t*=2;var r=n[e],i=n[e+1];n[e]=n[t],n[e+1]=n[t+1],n[t]=r,n[t+1]=i}function zo(e,t,n){e*=2,t*=2,n[e]=n[t],n[e+1]=n[t+1]}function R0(e,t,n,r){e*=2,t*=2,n*=2;var i=r[e],o=r[e+1];r[e]=r[t],r[e+1]=r[t+1],r[t]=r[n],r[t+1]=r[n+1],r[n]=i,r[n+1]=o}function Lo(e,t,n,r,i){e*=2,t*=2,i[e]=i[t],i[t]=n,i[e+1]=i[t+1],i[t+1]=r}function ge(e,t,n){e*=2,t*=2;var r=n[e],i=n[t];return r<i?!1:r===i?n[e+1]>n[t+1]:!0}function zr(e,t,n,r){e*=2;var i=r[e];return i<t?!0:i===t?r[e+1]<n:!1}function Rr(e,t,n){var r=(t-e+1)/6|0,i=e+r,o=t-r,s=e+t>>1,f=s-r,h=s+r,p=i,g=f,D=s,X=h,N=o,I=e+1,V=t-1,q=0;ge(p,g,n)&&(q=p,p=g,g=q),ge(X,N,n)&&(q=X,X=N,N=q),ge(p,D,n)&&(q=p,p=D,D=q),ge(g,D,n)&&(q=g,g=D,D=q),ge(p,X,n)&&(q=p,p=X,X=q),ge(D,X,n)&&(q=D,D=X,X=q),ge(g,N,n)&&(q=g,g=N,N=q),ge(g,D,n)&&(q=g,g=D,D=q),ge(X,N,n)&&(q=X,X=N,N=q);for(var Y=n[2*g],K=n[2*g+1],Q=n[2*X],tt=n[2*X+1],H=2*p,W=2*D,st=2*N,et=2*i,rt=2*s,U=2*o,a=0;a<2;++a){var v=n[H+a],T=n[W+a],M=n[st+a];n[et+a]=v,n[rt+a]=T,n[U+a]=M}zo(f,e,n),zo(h,t,n);for(var S=I;S<=V;++S)if(zr(S,Y,K,n))S!==I&&Ao(S,I,n),++I;else if(!zr(S,Q,tt,n))for(;;)if(zr(V,Q,tt,n)){zr(V,Y,K,n)?(R0(S,I,V,n),++I,--V):(Ao(S,V,n),--V);break}else{if(--V<S)break;continue}Lo(e,I-1,Y,K,n),Lo(t,V+1,Q,tt,n),I-2-e<=Lr?Er(e,I-2,n):Rr(e,I-2,n),t-(V+2)<=Lr?Er(V+2,t,n):Rr(V+2,t,n),V-I<=Lr?Er(I,V,n):Rr(I,V,n)}});var Gn=xt((k1,Io)=>{"use strict";Io.exports={init:O0,sweepBipartite:m0,sweepComplete:V0,scanBipartite:q0,scanComplete:N0};var Yt=Ar(),I0=rr(),Ir=Ro(),se=1<<28,Ae=1024,Jt=Yt.mallocInt32(Ae),we=Yt.mallocInt32(Ae),xe=Yt.mallocInt32(Ae),Ge=Yt.mallocInt32(Ae),Xe=Yt.mallocInt32(Ae),nr=Yt.mallocInt32(Ae),Pt=Yt.mallocDouble(Ae*8);function O0(e){var t=I0.nextPow2(e);Jt.length<t&&(Yt.free(Jt),Jt=Yt.mallocInt32(t)),we.length<t&&(Yt.free(we),we=Yt.mallocInt32(t)),xe.length<t&&(Yt.free(xe),xe=Yt.mallocInt32(t)),Ge.length<t&&(Yt.free(Ge),Ge=Yt.mallocInt32(t)),Xe.length<t&&(Yt.free(Xe),Xe=Yt.mallocInt32(t)),nr.length<t&&(Yt.free(nr),nr=Yt.mallocInt32(t));var n=8*t;Pt.length<n&&(Yt.free(Pt),Pt=Yt.mallocDouble(n))}function ke(e,t,n,r){var i=t[r],o=e[n-1];e[i]=o,t[o]=i}function Ye(e,t,n,r){e[n]=r,t[r]=n}function m0(e,t,n,r,i,o,s,f,h,p){for(var g=0,D=2*e,X=e-1,N=D-1,I=n;I<r;++I){var V=o[I],q=D*I;Pt[g++]=i[q+X],Pt[g++]=-(V+1),Pt[g++]=i[q+N],Pt[g++]=V}for(var I=s;I<f;++I){var V=p[I]+se,Y=D*I;Pt[g++]=h[Y+X],Pt[g++]=-V,Pt[g++]=h[Y+N],Pt[g++]=V}var K=g>>>1;Ir(Pt,K);for(var Q=0,tt=0,I=0;I<K;++I){var H=Pt[2*I+1]|0;if(H>=se)H=H-se|0,ke(xe,Ge,tt--,H);else if(H>=0)ke(Jt,we,Q--,H);else if(H<=-se){H=-H-se|0;for(var W=0;W<Q;++W){var st=t(Jt[W],H);if(st!==void 0)return st}Ye(xe,Ge,tt++,H)}else{H=-H-1|0;for(var W=0;W<tt;++W){var st=t(H,xe[W]);if(st!==void 0)return st}Ye(Jt,we,Q++,H)}}}function V0(e,t,n,r,i,o,s,f,h,p){for(var g=0,D=2*e,X=e-1,N=D-1,I=n;I<r;++I){var V=o[I]+1<<1,q=D*I;Pt[g++]=i[q+X],Pt[g++]=-V,Pt[g++]=i[q+N],Pt[g++]=V}for(var I=s;I<f;++I){var V=p[I]+1<<1,Y=D*I;Pt[g++]=h[Y+X],Pt[g++]=-V|1,Pt[g++]=h[Y+N],Pt[g++]=V|1}var K=g>>>1;Ir(Pt,K);for(var Q=0,tt=0,H=0,I=0;I<K;++I){var W=Pt[2*I+1]|0,st=W&1;if(I<K-1&&W>>1===Pt[2*I+3]>>1&&(st=2,I+=1),W<0){for(var et=-(W>>1)-1,rt=0;rt<H;++rt){var U=t(Xe[rt],et);if(U!==void 0)return U}if(st!==0)for(var rt=0;rt<Q;++rt){var U=t(Jt[rt],et);if(U!==void 0)return U}if(st!==1)for(var rt=0;rt<tt;++rt){var U=t(xe[rt],et);if(U!==void 0)return U}st===0?Ye(Jt,we,Q++,et):st===1?Ye(xe,Ge,tt++,et):st===2&&Ye(Xe,nr,H++,et)}else{var et=(W>>1)-1;st===0?ke(Jt,we,Q--,et):st===1?ke(xe,Ge,tt--,et):st===2&&ke(Xe,nr,H--,et)}}}function q0(e,t,n,r,i,o,s,f,h,p,g,D){var X=0,N=2*e,I=t,V=t+e,q=1,Y=1;r?Y=se:q=se;for(var K=i;K<o;++K){var Q=K+q,tt=N*K;Pt[X++]=s[tt+I],Pt[X++]=-Q,Pt[X++]=s[tt+V],Pt[X++]=Q}for(var K=h;K<p;++K){var Q=K+Y,H=N*K;Pt[X++]=g[H+I],Pt[X++]=-Q}var W=X>>>1;Ir(Pt,W);for(var st=0,K=0;K<W;++K){var et=Pt[2*K+1]|0;if(et<0){var Q=-et,rt=!1;if(Q>=se?(rt=!r,Q-=se):(rt=!!r,Q-=1),rt)Ye(Jt,we,st++,Q);else{var U=D[Q],a=N*Q,v=g[a+t+1],T=g[a+t+1+e];t:for(var M=0;M<st;++M){var S=Jt[M],L=N*S;if(!(T<s[L+t+1]||s[L+t+1+e]<v)){for(var O=t+2;O<e;++O)if(g[a+O+e]<s[L+O]||s[L+O+e]<g[a+O])continue t;var B=f[S],l;if(r?l=n(U,B):l=n(B,U),l!==void 0)return l}}}}else ke(Jt,we,st--,et-q)}}function N0(e,t,n,r,i,o,s,f,h,p,g){for(var D=0,X=2*e,N=t,I=t+e,V=r;V<i;++V){var q=V+se,Y=X*V;Pt[D++]=o[Y+N],Pt[D++]=-q,Pt[D++]=o[Y+I],Pt[D++]=q}for(var V=f;V<h;++V){var q=V+1,K=X*V;Pt[D++]=p[K+N],Pt[D++]=-q}var Q=D>>>1;Ir(Pt,Q);for(var tt=0,V=0;V<Q;++V){var H=Pt[2*V+1]|0;if(H<0){var q=-H;if(q>=se)Jt[tt++]=q-se;else{q-=1;var W=g[q],st=X*q,et=p[st+t+1],rt=p[st+t+1+e];t:for(var U=0;U<tt;++U){var a=Jt[U],v=s[a];if(v===W)break;var T=X*a;if(!(rt<o[T+t+1]||o[T+t+1+e]<et)){for(var M=t+2;M<e;++M)if(p[st+M+e]<o[T+M]||o[T+M+e]<p[st+M])continue t;var S=n(v,W);if(S!==void 0)return S}}}}else{for(var q=H-se,U=tt-1;U>=0;--U)if(Jt[U]===q){for(var M=U+1;M<tt;++M)Jt[M-1]=Jt[M];break}--tt}}}});var No=xt(On=>{"use strict";var ze="d",$e="ax",Oo="vv",An="fp",ir="es",Or="rs",Rn="re",or="rb",mo="ri",He="rp",mr="bs",In="be",ar="bb",Vo="bi",Ze="bp",zn="rv",Ln="Q",En=[ze,$e,Oo,Or,Rn,or,mo,mr,In,ar,Vo];function C0(e,t,n){var r="bruteForce"+(e?"Red":"Blue")+(t?"Flip":"")+(n?"Full":""),i=["function ",r,"(",En.join(),"){","var ",ir,"=2*",ze,";"],o="for(var i="+Or+","+He+"="+ir+"*"+Or+";i<"+Rn+";++i,"+He+"+="+ir+"){var x0="+or+"["+$e+"+"+He+"],x1="+or+"["+$e+"+"+He+"+"+ze+"],xi="+mo+"[i];",s="for(var j="+mr+","+Ze+"="+ir+"*"+mr+";j<"+In+";++j,"+Ze+"+="+ir+"){var y0="+ar+"["+$e+"+"+Ze+"],"+(n?"y1="+ar+"["+$e+"+"+Ze+"+"+ze+"],":"")+"yi="+Vo+"[j];";return e?i.push(o,Ln,":",s):i.push(s,Ln,":",o),n?i.push("if(y1<x0||x1<y0)continue;"):t?i.push("if(y0<=x0||x1<y0)continue;"):i.push("if(y0<x0||x1<y0)continue;"),i.push("for(var k="+$e+"+1;k<"+ze+";++k){var r0="+or+"[k+"+He+"],r1="+or+"[k+"+ze+"+"+He+"],b0="+ar+"[k+"+Ze+"],b1="+ar+"[k+"+ze+"+"+Ze+"];if(r1<b0||b1<r0)continue "+Ln+";}var "+zn+"="+Oo+"("),t?i.push("yi,xi"):i.push("xi,yi"),i.push(");if("+zn+"!==void 0)return "+zn+";}}}"),{name:r,code:i.join("")}}function qo(e){var t="bruteForce"+(e?"Full":"Partial"),n=[],r=En.slice();e||r.splice(3,0,An);var i=["function "+t+"("+r.join()+"){"];function o(h,p){var g=C0(h,p,e);n.push(g.code),i.push("return "+g.name+"("+En.join()+");")}i.push("if("+Rn+"-"+Or+">"+In+"-"+mr+"){"),e?(o(!0,!1),i.push("}else{"),o(!1,!1)):(i.push("if("+An+"){"),o(!0,!0),i.push("}else{"),o(!0,!1),i.push("}}else{if("+An+"){"),o(!1,!0),i.push("}else{"),o(!1,!1),i.push("}")),i.push("}}return "+t);var s=n.join("")+i.join(""),f=new Function(s);return f()}On.partial=qo(!1);On.full=qo(!0)});var mn=xt((H1,Co)=>{"use strict";Co.exports=k0;var X0="for(var j=2*a,k=j*c,l=k,m=c,n=b,o=a+b,p=c;d>p;++p,k+=j){var _;if($)if(m===p)m+=1,l+=j;else{for(var s=0;j>s;++s){var t=e[k+s];e[k+s]=e[l],e[l++]=t}var u=f[p];f[p]=f[m],f[m++]=u}}return m";function k0(e,t){var n="abcdef".split("").concat(t),r=[];return e.indexOf("lo")>=0&&r.push("lo=e[k+n]"),e.indexOf("hi")>=0&&r.push("hi=e[k+o]"),n.push(X0.replace("_",r.join()).replace("$",e)),Function.apply(void 0,n)}});var Yo=xt((Z1,ko)=>{"use strict";ko.exports=$0;var Y0=mn(),Xo=Y0("lo<p0",["p0"]),H0=8;function Z0(e,t,n,r,i,o){for(var s=2*e,f=s*(n+1)+t,h=n+1;h<r;++h,f+=s)for(var p=i[f],g=h,D=s*(h-1);g>n&&i[D+t]>p;--g,D-=s){for(var X=D,N=D+s,I=0;I<s;++I,++X,++N){var V=i[X];i[X]=i[N],i[N]=V}var q=o[g];o[g]=o[g-1],o[g-1]=q}}function $0(e,t,n,r,i,o){if(r<=n+1)return n;for(var s=n,f=r,h=r+n>>>1,p=2*e,g=h,D=i[p*h+t];s<f;){if(f-s<H0){Z0(e,t,s,f,i,o),D=i[p*h+t];break}var X=f-s,N=Math.random()*X+s|0,I=i[p*N+t],V=Math.random()*X+s|0,q=i[p*V+t],Y=Math.random()*X+s|0,K=i[p*Y+t];I<=q?K>=q?(g=V,D=q):I>=K?(g=N,D=I):(g=Y,D=K):q>=K?(g=V,D=q):K>=I?(g=N,D=I):(g=Y,D=K);for(var H=p*(f-1),W=p*g,Q=0;Q<p;++Q,++H,++W){var tt=i[H];i[H]=i[W],i[W]=tt}var st=o[f-1];o[f-1]=o[g],o[g]=st,g=Xo(e,t,s,f-1,i,o,D);for(var H=p*(f-1),W=p*g,Q=0;Q<p;++Q,++H,++W){var tt=i[H];i[H]=i[W],i[W]=tt}var st=o[f-1];if(o[f-1]=o[g],o[g]=st,h<g){for(f=g-1;s<f&&i[p*(f-1)+t]===D;)f-=1;f+=1}else if(g<h)for(s=g+1;s<f&&i[p*s+t]===D;)s+=1;else break}return Xo(e,t,n,h,i,o,i[p*h+t])}});var Jo=xt(($1,Qo)=>{"use strict";Qo.exports=uf;var We=Ar(),Vn=rr(),Wo=No(),W0=Wo.partial,K0=Wo.full,Te=Gn(),Q0=Yo(),Ke=mn(),Ho=128,J0=1<<22,j0=1<<22,tf=Ke("!(lo>=p0)&&!(p1>=hi)",["p0","p1"]),Zo=Ke("lo===p0",["p0"]),ef=Ke("lo<p0",["p0"]),rf=Ke("hi<=p0",["p0"]),$o=Ke("lo<=p0&&p0<=hi",["p0"]),nf=Ke("lo<p0&&p0<=hi",["p0"]),qn=6,Nn=2,Ko=1024,ee=We.mallocInt32(Ko),Le=We.mallocDouble(Ko);function of(e,t){var n=8*Vn.log2(t+1)*(e+1)|0,r=Vn.nextPow2(qn*n);ee.length<r&&(We.free(ee),ee=We.mallocInt32(r));var i=Vn.nextPow2(Nn*n);Le.length<i&&(We.free(Le),Le=We.mallocDouble(i))}function ce(e,t,n,r,i,o,s,f,h){var p=qn*e;ee[p]=t,ee[p+1]=n,ee[p+2]=r,ee[p+3]=i,ee[p+4]=o,ee[p+5]=s;var g=Nn*e;Le[g]=f,Le[g+1]=h}function af(e,t,n,r,i,o,s,f,h,p,g){var D=2*e,X=h*D,N=p[X+t];t:for(var I=i,V=i*D;I<o;++I,V+=D){var q=s[V+t],Y=s[V+t+e];if(!(N<q||Y<N)&&!(r&&N===q)){for(var K=f[I],Q=t+1;Q<e;++Q){var q=s[V+Q],Y=s[V+Q+e],tt=p[X+Q],H=p[X+Q+e];if(Y<tt||H<q)continue t}var W;if(r?W=n(g,K):W=n(K,g),W!==void 0)return W}}}function sf(e,t,n,r,i,o,s,f,h,p){var g=2*e,D=f*g,X=h[D+t];t:for(var N=r,I=r*g;N<i;++N,I+=g){var V=s[N];if(V!==p){var q=o[I+t],Y=o[I+t+e];if(!(X<q||Y<X)){for(var K=t+1;K<e;++K){var q=o[I+K],Y=o[I+K+e],Q=h[D+K],tt=h[D+K+e];if(Y<Q||tt<q)continue t}var H=n(V,p);if(H!==void 0)return H}}}}function uf(e,t,n,r,i,o,s,f,h){of(e,r+s);var p=0,g=2*e,D;for(ce(p++,0,0,r,0,s,n?16:0,-1/0,1/0),n||ce(p++,0,0,s,0,r,1,-1/0,1/0);p>0;){p-=1;var X=p*qn,N=ee[X],I=ee[X+1],V=ee[X+2],q=ee[X+3],Y=ee[X+4],K=ee[X+5],Q=p*Nn,tt=Le[Q],H=Le[Q+1],W=K&1,st=!!(K&16),et=i,rt=o,U=f,a=h;if(W&&(et=f,rt=h,U=i,a=o),!(K&2&&(V=ef(e,N,I,V,et,rt,H),I>=V))&&!(K&4&&(I=rf(e,N,I,V,et,rt,tt),I>=V))){var v=V-I,T=Y-q;if(st){if(e*v*(v+T)<j0){if(D=Te.scanComplete(e,N,t,I,V,et,rt,q,Y,U,a),D!==void 0)return D;continue}}else if(e*Math.min(v,T)<Ho){if(D=W0(e,N,t,W,I,V,et,rt,q,Y,U,a),D!==void 0)return D;continue}else if(e*v*T<J0){if(D=Te.scanBipartite(e,N,t,W,I,V,et,rt,q,Y,U,a),D!==void 0)return D;continue}var M=tf(e,N,I,V,et,rt,tt,H);if(I<M)if(e*(M-I)<Ho){if(D=K0(e,N+1,t,I,M,et,rt,q,Y,U,a),D!==void 0)return D}else if(N===e-2){if(W?D=Te.sweepBipartite(e,t,q,Y,U,a,I,M,et,rt):D=Te.sweepBipartite(e,t,I,M,et,rt,q,Y,U,a),D!==void 0)return D}else ce(p++,N+1,I,M,q,Y,W,-1/0,1/0),ce(p++,N+1,q,Y,I,M,W^1,-1/0,1/0);if(M<V){var S=Q0(e,N,q,Y,U,a),L=U[g*S+N],O=Zo(e,N,S,Y,U,a,L);if(O<Y&&ce(p++,N,M,V,O,Y,(W|4)+(st?16:0),L,H),q<S&&ce(p++,N,M,V,q,S,(W|2)+(st?16:0),tt,L),S+1===O){if(st?D=sf(e,N,t,M,V,et,rt,S,U,a[S]):D=af(e,N,t,W,M,V,et,rt,S,U,a[S]),D!==void 0)return D}else if(S<O){var B;if(st){if(B=$o(e,N,M,V,et,rt,L),M<B){var l=Zo(e,N,M,B,et,rt,L);if(N===e-2){if(M<l&&(D=Te.sweepComplete(e,t,M,l,et,rt,S,O,U,a),D!==void 0)||l<B&&(D=Te.sweepBipartite(e,t,l,B,et,rt,S,O,U,a),D!==void 0))return D}else M<l&&ce(p++,N+1,M,l,S,O,16,-1/0,1/0),l<B&&(ce(p++,N+1,l,B,S,O,0,-1/0,1/0),ce(p++,N+1,S,O,l,B,1,-1/0,1/0))}}else W?B=nf(e,N,M,V,et,rt,L):B=$o(e,N,M,V,et,rt,L),M<B&&(N===e-2?W?D=Te.sweepBipartite(e,t,S,O,U,a,M,B,et,rt):D=Te.sweepBipartite(e,t,M,B,et,rt,S,O,U,a):(ce(p++,N+1,M,B,S,O,W,-1/0,1/0),ce(p++,N+1,S,O,M,B,W^1,-1/0,1/0)))}}}}}});var ra=xt((W1,ea)=>{"use strict";ea.exports=pf;var Pe=Ar(),Vr=Gn(),ff=Jo();function cf(e,t){for(var n=0;n<e;++n)if(!(t[n]<=t[n+e]))return!0;return!1}function jo(e,t,n,r){for(var i=0,o=0,s=0,f=e.length;s<f;++s){var h=e[s];if(!cf(t,h)){for(var p=0;p<2*t;++p)n[i++]=h[p];r[o++]=s}}return o}function qr(e,t,n,r){var i=e.length,o=t.length;if(!(i<=0||o<=0)){var s=e[0].length>>>1;if(!(s<=0)){var f,h=Pe.mallocDouble(2*s*i),p=Pe.mallocInt32(i);if(i=jo(e,s,h,p),i>0){if(s===1&&r)Vr.init(i),f=Vr.sweepComplete(s,n,0,i,h,p,0,i,h,p);else{var g=Pe.mallocDouble(2*s*o),D=Pe.mallocInt32(o);o=jo(t,s,g,D),o>0&&(Vr.init(i+o),s===1?f=Vr.sweepBipartite(s,n,0,i,h,p,0,o,g,D):f=ff(s,n,r,i,h,p,o,g,D),Pe.free(g),Pe.free(D))}Pe.free(h),Pe.free(p)}return f}}}var sr;function ta(e,t){sr.push([e,t])}function lf(e){return sr=[],qr(e,e,ta,!0),sr}function hf(e,t){return sr=[],qr(e,t,ta,!1),sr}function pf(e,t,n){var r;switch(arguments.length){case 1:return lf(e);case 2:return typeof t=="function"?qr(e,e,t,!0):hf(e,t);case 3:return qr(e,t,n,!1);default:throw new Error("box-intersect: Invalid arguments")}}});var ia=xt((K1,na)=>{"use strict";na.exports=df;var Nr=bn()[3];function vf(e,t,n,r){for(var i=0;i<2;++i){var o=e[i],s=t[i],f=Math.min(o,s),h=Math.max(o,s),p=n[i],g=r[i],D=Math.min(p,g),X=Math.max(p,g);if(X<f||h<D)return!1}return!0}function df(e,t,n,r){var i=Nr(e,n,r),o=Nr(t,n,r);if(i>0&&o>0||i<0&&o<0)return!1;var s=Nr(n,e,t),f=Nr(r,e,t);return s>0&&f>0||s<0&&f<0?!1:i===0&&o===0&&s===0&&f===0?vf(e,t,n,r):!0}});var oa=xt(()=>{});var ur=xt((aa,Cn)=>{(function(e,t){"use strict";function n(U,a){if(!U)throw new Error(a||"Assertion failed")}function r(U,a){U.super_=a;var v=function(){};v.prototype=a.prototype,U.prototype=new v,U.prototype.constructor=U}function i(U,a,v){if(i.isBN(U))return U;this.negative=0,this.words=null,this.length=0,this.red=null,U!==null&&((a==="le"||a==="be")&&(v=a,a=10),this._init(U||0,a||10,v||"be"))}typeof e=="object"?e.exports=i:t.BN=i,i.BN=i,i.wordSize=26;var o;try{typeof window<"u"&&typeof window.Buffer<"u"?o=window.Buffer:o=oa().Buffer}catch{}i.isBN=function(a){return a instanceof i?!0:a!==null&&typeof a=="object"&&a.constructor.wordSize===i.wordSize&&Array.isArray(a.words)},i.max=function(a,v){return a.cmp(v)>0?a:v},i.min=function(a,v){return a.cmp(v)<0?a:v},i.prototype._init=function(a,v,T){if(typeof a=="number")return this._initNumber(a,v,T);if(typeof a=="object")return this._initArray(a,v,T);v==="hex"&&(v=16),n(v===(v|0)&&v>=2&&v<=36),a=a.toString().replace(/\s+/g,"");var M=0;a[0]==="-"&&(M++,this.negative=1),M<a.length&&(v===16?this._parseHex(a,M,T):(this._parseBase(a,v,M),T==="le"&&this._initArray(this.toArray(),v,T)))},i.prototype._initNumber=function(a,v,T){a<0&&(this.negative=1,a=-a),a<67108864?(this.words=[a&67108863],this.length=1):a<4503599627370496?(this.words=[a&67108863,a/67108864&67108863],this.length=2):(n(a<9007199254740992),this.words=[a&67108863,a/67108864&67108863,1],this.length=3),T==="le"&&this._initArray(this.toArray(),v,T)},i.prototype._initArray=function(a,v,T){if(n(typeof a.length=="number"),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var S,L,O=0;if(T==="be")for(M=a.length-1,S=0;M>=0;M-=3)L=a[M]|a[M-1]<<8|a[M-2]<<16,this.words[S]|=L<<O&67108863,this.words[S+1]=L>>>26-O&67108863,O+=24,O>=26&&(O-=26,S++);else if(T==="le")for(M=0,S=0;M<a.length;M+=3)L=a[M]|a[M+1]<<8|a[M+2]<<16,this.words[S]|=L<<O&67108863,this.words[S+1]=L>>>26-O&67108863,O+=24,O>=26&&(O-=26,S++);return this.strip()};function s(U,a){var v=U.charCodeAt(a);return v>=65&&v<=70?v-55:v>=97&&v<=102?v-87:v-48&15}function f(U,a,v){var T=s(U,v);return v-1>=a&&(T|=s(U,v-1)<<4),T}i.prototype._parseHex=function(a,v,T){this.length=Math.ceil((a.length-v)/6),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var S=0,L=0,O;if(T==="be")for(M=a.length-1;M>=v;M-=2)O=f(a,v,M)<<S,this.words[L]|=O&67108863,S>=18?(S-=18,L+=1,this.words[L]|=O>>>26):S+=8;else{var B=a.length-v;for(M=B%2===0?v+1:v;M<a.length;M+=2)O=f(a,v,M)<<S,this.words[L]|=O&67108863,S>=18?(S-=18,L+=1,this.words[L]|=O>>>26):S+=8}this.strip()};function h(U,a,v,T){for(var M=0,S=Math.min(U.length,v),L=a;L<S;L++){var O=U.charCodeAt(L)-48;M*=T,O>=49?M+=O-49+10:O>=17?M+=O-17+10:M+=O}return M}i.prototype._parseBase=function(a,v,T){this.words=[0],this.length=1;for(var M=0,S=1;S<=67108863;S*=v)M++;M--,S=S/v|0;for(var L=a.length-T,O=L%M,B=Math.min(L,L-O)+T,l=0,G=T;G<B;G+=M)l=h(a,G,G+M,v),this.imuln(S),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(O!==0){var ot=1;for(l=h(a,G,a.length,v),G=0;G<O;G++)ot*=v;this.imuln(ot),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}this.strip()},i.prototype.copy=function(a){a.words=new Array(this.length);for(var v=0;v<this.length;v++)a.words[v]=this.words[v];a.length=this.length,a.negative=this.negative,a.red=this.red},i.prototype.clone=function(){var a=new i(null);return this.copy(a),a},i.prototype._expand=function(a){for(;this.length<a;)this.words[this.length++]=0;return this},i.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},i.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var p=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],g=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],D=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(a,v){a=a||10,v=v|0||1;var T;if(a===16||a==="hex"){T="";for(var M=0,S=0,L=0;L<this.length;L++){var O=this.words[L],B=((O<<M|S)&16777215).toString(16);S=O>>>24-M&16777215,M+=2,M>=26&&(M-=26,L--),S!==0||L!==this.length-1?T=p[6-B.length]+B+T:T=B+T}for(S!==0&&(T=S.toString(16)+T);T.length%v!==0;)T="0"+T;return this.negative!==0&&(T="-"+T),T}if(a===(a|0)&&a>=2&&a<=36){var l=g[a],G=D[a];T="";var ot=this.clone();for(ot.negative=0;!ot.isZero();){var at=ot.modn(G).toString(a);ot=ot.idivn(G),ot.isZero()?T=at+T:T=p[l-at.length]+at+T}for(this.isZero()&&(T="0"+T);T.length%v!==0;)T="0"+T;return this.negative!==0&&(T="-"+T),T}n(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var a=this.words[0];return this.length===2?a+=this.words[1]*67108864:this.length===3&&this.words[2]===1?a+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-a:a},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(a,v){return n(typeof o<"u"),this.toArrayLike(o,a,v)},i.prototype.toArray=function(a,v){return this.toArrayLike(Array,a,v)},i.prototype.toArrayLike=function(a,v,T){var M=this.byteLength(),S=T||Math.max(1,M);n(M<=S,"byte array longer than desired length"),n(S>0,"Requested array length <= 0"),this.strip();var L=v==="le",O=new a(S),B,l,G=this.clone();if(L){for(l=0;!G.isZero();l++)B=G.andln(255),G.iushrn(8),O[l]=B;for(;l<S;l++)O[l]=0}else{for(l=0;l<S-M;l++)O[l]=0;for(l=0;!G.isZero();l++)B=G.andln(255),G.iushrn(8),O[S-l-1]=B}return O},Math.clz32?i.prototype._countBits=function(a){return 32-Math.clz32(a)}:i.prototype._countBits=function(a){var v=a,T=0;return v>=4096&&(T+=13,v>>>=13),v>=64&&(T+=7,v>>>=7),v>=8&&(T+=4,v>>>=4),v>=2&&(T+=2,v>>>=2),T+v},i.prototype._zeroBits=function(a){if(a===0)return 26;var v=a,T=0;return(v&8191)===0&&(T+=13,v>>>=13),(v&127)===0&&(T+=7,v>>>=7),(v&15)===0&&(T+=4,v>>>=4),(v&3)===0&&(T+=2,v>>>=2),(v&1)===0&&T++,T},i.prototype.bitLength=function(){var a=this.words[this.length-1],v=this._countBits(a);return(this.length-1)*26+v};function X(U){for(var a=new Array(U.bitLength()),v=0;v<a.length;v++){var T=v/26|0,M=v%26;a[v]=(U.words[T]&1<<M)>>>M}return a}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var a=0,v=0;v<this.length;v++){var T=this._zeroBits(this.words[v]);if(a+=T,T!==26)break}return a},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(a){return this.negative!==0?this.abs().inotn(a).iaddn(1):this.clone()},i.prototype.fromTwos=function(a){return this.testn(a-1)?this.notn(a).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(a){for(;this.length<a.length;)this.words[this.length++]=0;for(var v=0;v<a.length;v++)this.words[v]=this.words[v]|a.words[v];return this.strip()},i.prototype.ior=function(a){return n((this.negative|a.negative)===0),this.iuor(a)},i.prototype.or=function(a){return this.length>a.length?this.clone().ior(a):a.clone().ior(this)},i.prototype.uor=function(a){return this.length>a.length?this.clone().iuor(a):a.clone().iuor(this)},i.prototype.iuand=function(a){var v;this.length>a.length?v=a:v=this;for(var T=0;T<v.length;T++)this.words[T]=this.words[T]&a.words[T];return this.length=v.length,this.strip()},i.prototype.iand=function(a){return n((this.negative|a.negative)===0),this.iuand(a)},i.prototype.and=function(a){return this.length>a.length?this.clone().iand(a):a.clone().iand(this)},i.prototype.uand=function(a){return this.length>a.length?this.clone().iuand(a):a.clone().iuand(this)},i.prototype.iuxor=function(a){var v,T;this.length>a.length?(v=this,T=a):(v=a,T=this);for(var M=0;M<T.length;M++)this.words[M]=v.words[M]^T.words[M];if(this!==v)for(;M<v.length;M++)this.words[M]=v.words[M];return this.length=v.length,this.strip()},i.prototype.ixor=function(a){return n((this.negative|a.negative)===0),this.iuxor(a)},i.prototype.xor=function(a){return this.length>a.length?this.clone().ixor(a):a.clone().ixor(this)},i.prototype.uxor=function(a){return this.length>a.length?this.clone().iuxor(a):a.clone().iuxor(this)},i.prototype.inotn=function(a){n(typeof a=="number"&&a>=0);var v=Math.ceil(a/26)|0,T=a%26;this._expand(v),T>0&&v--;for(var M=0;M<v;M++)this.words[M]=~this.words[M]&67108863;return T>0&&(this.words[M]=~this.words[M]&67108863>>26-T),this.strip()},i.prototype.notn=function(a){return this.clone().inotn(a)},i.prototype.setn=function(a,v){n(typeof a=="number"&&a>=0);var T=a/26|0,M=a%26;return this._expand(T+1),v?this.words[T]=this.words[T]|1<<M:this.words[T]=this.words[T]&~(1<<M),this.strip()},i.prototype.iadd=function(a){var v;if(this.negative!==0&&a.negative===0)return this.negative=0,v=this.isub(a),this.negative^=1,this._normSign();if(this.negative===0&&a.negative!==0)return a.negative=0,v=this.isub(a),a.negative=1,v._normSign();var T,M;this.length>a.length?(T=this,M=a):(T=a,M=this);for(var S=0,L=0;L<M.length;L++)v=(T.words[L]|0)+(M.words[L]|0)+S,this.words[L]=v&67108863,S=v>>>26;for(;S!==0&&L<T.length;L++)v=(T.words[L]|0)+S,this.words[L]=v&67108863,S=v>>>26;if(this.length=T.length,S!==0)this.words[this.length]=S,this.length++;else if(T!==this)for(;L<T.length;L++)this.words[L]=T.words[L];return this},i.prototype.add=function(a){var v;return a.negative!==0&&this.negative===0?(a.negative=0,v=this.sub(a),a.negative^=1,v):a.negative===0&&this.negative!==0?(this.negative=0,v=a.sub(this),this.negative=1,v):this.length>a.length?this.clone().iadd(a):a.clone().iadd(this)},i.prototype.isub=function(a){if(a.negative!==0){a.negative=0;var v=this.iadd(a);return a.negative=1,v._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(a),this.negative=1,this._normSign();var T=this.cmp(a);if(T===0)return this.negative=0,this.length=1,this.words[0]=0,this;var M,S;T>0?(M=this,S=a):(M=a,S=this);for(var L=0,O=0;O<S.length;O++)v=(M.words[O]|0)-(S.words[O]|0)+L,L=v>>26,this.words[O]=v&67108863;for(;L!==0&&O<M.length;O++)v=(M.words[O]|0)+L,L=v>>26,this.words[O]=v&67108863;if(L===0&&O<M.length&&M!==this)for(;O<M.length;O++)this.words[O]=M.words[O];return this.length=Math.max(this.length,O),M!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(a){return this.clone().isub(a)};function N(U,a,v){v.negative=a.negative^U.negative;var T=U.length+a.length|0;v.length=T,T=T-1|0;var M=U.words[0]|0,S=a.words[0]|0,L=M*S,O=L&67108863,B=L/67108864|0;v.words[0]=O;for(var l=1;l<T;l++){for(var G=B>>>26,ot=B&67108863,at=Math.min(l,a.length-1),ut=Math.max(0,l-U.length+1);ut<=at;ut++){var ft=l-ut|0;M=U.words[ft]|0,S=a.words[ut]|0,L=M*S+ot,G+=L/67108864|0,ot=L&67108863}v.words[l]=ot|0,B=G|0}return B!==0?v.words[l]=B|0:v.length--,v.strip()}var I=function(a,v,T){var M=a.words,S=v.words,L=T.words,O=0,B,l,G,ot=M[0]|0,at=ot&8191,ut=ot>>>13,ft=M[1]|0,yt=ft&8191,pt=ft>>>13,k=M[2]|0,$=k&8191,F=k>>>13,c=M[3]|0,b=c&8191,w=c>>>13,z=M[4]|0,R=z&8191,m=z>>>13,C=M[5]|0,u=C&8191,_=C>>>13,x=M[6]|0,y=x&8191,d=x>>>13,P=M[7]|0,E=P&8191,A=P>>>13,Z=M[8]|0,J=Z&8191,j=Z>>>13,ct=M[9]|0,nt=ct&8191,it=ct>>>13,vt=S[0]|0,ht=vt&8191,lt=vt>>>13,dt=S[1]|0,wt=dt&8191,gt=dt>>>13,Ct=S[2]|0,Mt=Ct&8191,bt=Ct>>>13,Ht=S[3]|0,St=Ht&8191,_t=Ht>>>13,$t=S[4]|0,Bt=$t&8191,Dt=$t>>>13,Wt=S[5]|0,Ut=Wt&8191,Ft=Wt>>>13,Kt=S[6]|0,Gt=Kt&8191,At=Kt>>>13,jt=S[7]|0,Rt=jt&8191,It=jt>>>13,Se=S[8]|0,Ot=Se&8191,mt=Se>>>13,_e=S[9]|0,Vt=_e&8191,Nt=_e>>>13;T.negative=a.negative^v.negative,T.length=19,B=Math.imul(at,ht),l=Math.imul(at,lt),l=l+Math.imul(ut,ht)|0,G=Math.imul(ut,lt);var me=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(me>>>26)|0,me&=67108863,B=Math.imul(yt,ht),l=Math.imul(yt,lt),l=l+Math.imul(pt,ht)|0,G=Math.imul(pt,lt),B=B+Math.imul(at,wt)|0,l=l+Math.imul(at,gt)|0,l=l+Math.imul(ut,wt)|0,G=G+Math.imul(ut,gt)|0;var Ve=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Ve>>>26)|0,Ve&=67108863,B=Math.imul($,ht),l=Math.imul($,lt),l=l+Math.imul(F,ht)|0,G=Math.imul(F,lt),B=B+Math.imul(yt,wt)|0,l=l+Math.imul(yt,gt)|0,l=l+Math.imul(pt,wt)|0,G=G+Math.imul(pt,gt)|0,B=B+Math.imul(at,Mt)|0,l=l+Math.imul(at,bt)|0,l=l+Math.imul(ut,Mt)|0,G=G+Math.imul(ut,bt)|0;var qe=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(qe>>>26)|0,qe&=67108863,B=Math.imul(b,ht),l=Math.imul(b,lt),l=l+Math.imul(w,ht)|0,G=Math.imul(w,lt),B=B+Math.imul($,wt)|0,l=l+Math.imul($,gt)|0,l=l+Math.imul(F,wt)|0,G=G+Math.imul(F,gt)|0,B=B+Math.imul(yt,Mt)|0,l=l+Math.imul(yt,bt)|0,l=l+Math.imul(pt,Mt)|0,G=G+Math.imul(pt,bt)|0,B=B+Math.imul(at,St)|0,l=l+Math.imul(at,_t)|0,l=l+Math.imul(ut,St)|0,G=G+Math.imul(ut,_t)|0;var Zt=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,B=Math.imul(R,ht),l=Math.imul(R,lt),l=l+Math.imul(m,ht)|0,G=Math.imul(m,lt),B=B+Math.imul(b,wt)|0,l=l+Math.imul(b,gt)|0,l=l+Math.imul(w,wt)|0,G=G+Math.imul(w,gt)|0,B=B+Math.imul($,Mt)|0,l=l+Math.imul($,bt)|0,l=l+Math.imul(F,Mt)|0,G=G+Math.imul(F,bt)|0,B=B+Math.imul(yt,St)|0,l=l+Math.imul(yt,_t)|0,l=l+Math.imul(pt,St)|0,G=G+Math.imul(pt,_t)|0,B=B+Math.imul(at,Bt)|0,l=l+Math.imul(at,Dt)|0,l=l+Math.imul(ut,Bt)|0,G=G+Math.imul(ut,Dt)|0;var Wr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,B=Math.imul(u,ht),l=Math.imul(u,lt),l=l+Math.imul(_,ht)|0,G=Math.imul(_,lt),B=B+Math.imul(R,wt)|0,l=l+Math.imul(R,gt)|0,l=l+Math.imul(m,wt)|0,G=G+Math.imul(m,gt)|0,B=B+Math.imul(b,Mt)|0,l=l+Math.imul(b,bt)|0,l=l+Math.imul(w,Mt)|0,G=G+Math.imul(w,bt)|0,B=B+Math.imul($,St)|0,l=l+Math.imul($,_t)|0,l=l+Math.imul(F,St)|0,G=G+Math.imul(F,_t)|0,B=B+Math.imul(yt,Bt)|0,l=l+Math.imul(yt,Dt)|0,l=l+Math.imul(pt,Bt)|0,G=G+Math.imul(pt,Dt)|0,B=B+Math.imul(at,Ut)|0,l=l+Math.imul(at,Ft)|0,l=l+Math.imul(ut,Ut)|0,G=G+Math.imul(ut,Ft)|0;var Kr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,B=Math.imul(y,ht),l=Math.imul(y,lt),l=l+Math.imul(d,ht)|0,G=Math.imul(d,lt),B=B+Math.imul(u,wt)|0,l=l+Math.imul(u,gt)|0,l=l+Math.imul(_,wt)|0,G=G+Math.imul(_,gt)|0,B=B+Math.imul(R,Mt)|0,l=l+Math.imul(R,bt)|0,l=l+Math.imul(m,Mt)|0,G=G+Math.imul(m,bt)|0,B=B+Math.imul(b,St)|0,l=l+Math.imul(b,_t)|0,l=l+Math.imul(w,St)|0,G=G+Math.imul(w,_t)|0,B=B+Math.imul($,Bt)|0,l=l+Math.imul($,Dt)|0,l=l+Math.imul(F,Bt)|0,G=G+Math.imul(F,Dt)|0,B=B+Math.imul(yt,Ut)|0,l=l+Math.imul(yt,Ft)|0,l=l+Math.imul(pt,Ut)|0,G=G+Math.imul(pt,Ft)|0,B=B+Math.imul(at,Gt)|0,l=l+Math.imul(at,At)|0,l=l+Math.imul(ut,Gt)|0,G=G+Math.imul(ut,At)|0;var Qr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,B=Math.imul(E,ht),l=Math.imul(E,lt),l=l+Math.imul(A,ht)|0,G=Math.imul(A,lt),B=B+Math.imul(y,wt)|0,l=l+Math.imul(y,gt)|0,l=l+Math.imul(d,wt)|0,G=G+Math.imul(d,gt)|0,B=B+Math.imul(u,Mt)|0,l=l+Math.imul(u,bt)|0,l=l+Math.imul(_,Mt)|0,G=G+Math.imul(_,bt)|0,B=B+Math.imul(R,St)|0,l=l+Math.imul(R,_t)|0,l=l+Math.imul(m,St)|0,G=G+Math.imul(m,_t)|0,B=B+Math.imul(b,Bt)|0,l=l+Math.imul(b,Dt)|0,l=l+Math.imul(w,Bt)|0,G=G+Math.imul(w,Dt)|0,B=B+Math.imul($,Ut)|0,l=l+Math.imul($,Ft)|0,l=l+Math.imul(F,Ut)|0,G=G+Math.imul(F,Ft)|0,B=B+Math.imul(yt,Gt)|0,l=l+Math.imul(yt,At)|0,l=l+Math.imul(pt,Gt)|0,G=G+Math.imul(pt,At)|0,B=B+Math.imul(at,Rt)|0,l=l+Math.imul(at,It)|0,l=l+Math.imul(ut,Rt)|0,G=G+Math.imul(ut,It)|0;var Jr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,B=Math.imul(J,ht),l=Math.imul(J,lt),l=l+Math.imul(j,ht)|0,G=Math.imul(j,lt),B=B+Math.imul(E,wt)|0,l=l+Math.imul(E,gt)|0,l=l+Math.imul(A,wt)|0,G=G+Math.imul(A,gt)|0,B=B+Math.imul(y,Mt)|0,l=l+Math.imul(y,bt)|0,l=l+Math.imul(d,Mt)|0,G=G+Math.imul(d,bt)|0,B=B+Math.imul(u,St)|0,l=l+Math.imul(u,_t)|0,l=l+Math.imul(_,St)|0,G=G+Math.imul(_,_t)|0,B=B+Math.imul(R,Bt)|0,l=l+Math.imul(R,Dt)|0,l=l+Math.imul(m,Bt)|0,G=G+Math.imul(m,Dt)|0,B=B+Math.imul(b,Ut)|0,l=l+Math.imul(b,Ft)|0,l=l+Math.imul(w,Ut)|0,G=G+Math.imul(w,Ft)|0,B=B+Math.imul($,Gt)|0,l=l+Math.imul($,At)|0,l=l+Math.imul(F,Gt)|0,G=G+Math.imul(F,At)|0,B=B+Math.imul(yt,Rt)|0,l=l+Math.imul(yt,It)|0,l=l+Math.imul(pt,Rt)|0,G=G+Math.imul(pt,It)|0,B=B+Math.imul(at,Ot)|0,l=l+Math.imul(at,mt)|0,l=l+Math.imul(ut,Ot)|0,G=G+Math.imul(ut,mt)|0;var jr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(jr>>>26)|0,jr&=67108863,B=Math.imul(nt,ht),l=Math.imul(nt,lt),l=l+Math.imul(it,ht)|0,G=Math.imul(it,lt),B=B+Math.imul(J,wt)|0,l=l+Math.imul(J,gt)|0,l=l+Math.imul(j,wt)|0,G=G+Math.imul(j,gt)|0,B=B+Math.imul(E,Mt)|0,l=l+Math.imul(E,bt)|0,l=l+Math.imul(A,Mt)|0,G=G+Math.imul(A,bt)|0,B=B+Math.imul(y,St)|0,l=l+Math.imul(y,_t)|0,l=l+Math.imul(d,St)|0,G=G+Math.imul(d,_t)|0,B=B+Math.imul(u,Bt)|0,l=l+Math.imul(u,Dt)|0,l=l+Math.imul(_,Bt)|0,G=G+Math.imul(_,Dt)|0,B=B+Math.imul(R,Ut)|0,l=l+Math.imul(R,Ft)|0,l=l+Math.imul(m,Ut)|0,G=G+Math.imul(m,Ft)|0,B=B+Math.imul(b,Gt)|0,l=l+Math.imul(b,At)|0,l=l+Math.imul(w,Gt)|0,G=G+Math.imul(w,At)|0,B=B+Math.imul($,Rt)|0,l=l+Math.imul($,It)|0,l=l+Math.imul(F,Rt)|0,G=G+Math.imul(F,It)|0,B=B+Math.imul(yt,Ot)|0,l=l+Math.imul(yt,mt)|0,l=l+Math.imul(pt,Ot)|0,G=G+Math.imul(pt,mt)|0,B=B+Math.imul(at,Vt)|0,l=l+Math.imul(at,Nt)|0,l=l+Math.imul(ut,Vt)|0,G=G+Math.imul(ut,Nt)|0;var tn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(tn>>>26)|0,tn&=67108863,B=Math.imul(nt,wt),l=Math.imul(nt,gt),l=l+Math.imul(it,wt)|0,G=Math.imul(it,gt),B=B+Math.imul(J,Mt)|0,l=l+Math.imul(J,bt)|0,l=l+Math.imul(j,Mt)|0,G=G+Math.imul(j,bt)|0,B=B+Math.imul(E,St)|0,l=l+Math.imul(E,_t)|0,l=l+Math.imul(A,St)|0,G=G+Math.imul(A,_t)|0,B=B+Math.imul(y,Bt)|0,l=l+Math.imul(y,Dt)|0,l=l+Math.imul(d,Bt)|0,G=G+Math.imul(d,Dt)|0,B=B+Math.imul(u,Ut)|0,l=l+Math.imul(u,Ft)|0,l=l+Math.imul(_,Ut)|0,G=G+Math.imul(_,Ft)|0,B=B+Math.imul(R,Gt)|0,l=l+Math.imul(R,At)|0,l=l+Math.imul(m,Gt)|0,G=G+Math.imul(m,At)|0,B=B+Math.imul(b,Rt)|0,l=l+Math.imul(b,It)|0,l=l+Math.imul(w,Rt)|0,G=G+Math.imul(w,It)|0,B=B+Math.imul($,Ot)|0,l=l+Math.imul($,mt)|0,l=l+Math.imul(F,Ot)|0,G=G+Math.imul(F,mt)|0,B=B+Math.imul(yt,Vt)|0,l=l+Math.imul(yt,Nt)|0,l=l+Math.imul(pt,Vt)|0,G=G+Math.imul(pt,Nt)|0;var en=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(en>>>26)|0,en&=67108863,B=Math.imul(nt,Mt),l=Math.imul(nt,bt),l=l+Math.imul(it,Mt)|0,G=Math.imul(it,bt),B=B+Math.imul(J,St)|0,l=l+Math.imul(J,_t)|0,l=l+Math.imul(j,St)|0,G=G+Math.imul(j,_t)|0,B=B+Math.imul(E,Bt)|0,l=l+Math.imul(E,Dt)|0,l=l+Math.imul(A,Bt)|0,G=G+Math.imul(A,Dt)|0,B=B+Math.imul(y,Ut)|0,l=l+Math.imul(y,Ft)|0,l=l+Math.imul(d,Ut)|0,G=G+Math.imul(d,Ft)|0,B=B+Math.imul(u,Gt)|0,l=l+Math.imul(u,At)|0,l=l+Math.imul(_,Gt)|0,G=G+Math.imul(_,At)|0,B=B+Math.imul(R,Rt)|0,l=l+Math.imul(R,It)|0,l=l+Math.imul(m,Rt)|0,G=G+Math.imul(m,It)|0,B=B+Math.imul(b,Ot)|0,l=l+Math.imul(b,mt)|0,l=l+Math.imul(w,Ot)|0,G=G+Math.imul(w,mt)|0,B=B+Math.imul($,Vt)|0,l=l+Math.imul($,Nt)|0,l=l+Math.imul(F,Vt)|0,G=G+Math.imul(F,Nt)|0;var rn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(rn>>>26)|0,rn&=67108863,B=Math.imul(nt,St),l=Math.imul(nt,_t),l=l+Math.imul(it,St)|0,G=Math.imul(it,_t),B=B+Math.imul(J,Bt)|0,l=l+Math.imul(J,Dt)|0,l=l+Math.imul(j,Bt)|0,G=G+Math.imul(j,Dt)|0,B=B+Math.imul(E,Ut)|0,l=l+Math.imul(E,Ft)|0,l=l+Math.imul(A,Ut)|0,G=G+Math.imul(A,Ft)|0,B=B+Math.imul(y,Gt)|0,l=l+Math.imul(y,At)|0,l=l+Math.imul(d,Gt)|0,G=G+Math.imul(d,At)|0,B=B+Math.imul(u,Rt)|0,l=l+Math.imul(u,It)|0,l=l+Math.imul(_,Rt)|0,G=G+Math.imul(_,It)|0,B=B+Math.imul(R,Ot)|0,l=l+Math.imul(R,mt)|0,l=l+Math.imul(m,Ot)|0,G=G+Math.imul(m,mt)|0,B=B+Math.imul(b,Vt)|0,l=l+Math.imul(b,Nt)|0,l=l+Math.imul(w,Vt)|0,G=G+Math.imul(w,Nt)|0;var nn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(nn>>>26)|0,nn&=67108863,B=Math.imul(nt,Bt),l=Math.imul(nt,Dt),l=l+Math.imul(it,Bt)|0,G=Math.imul(it,Dt),B=B+Math.imul(J,Ut)|0,l=l+Math.imul(J,Ft)|0,l=l+Math.imul(j,Ut)|0,G=G+Math.imul(j,Ft)|0,B=B+Math.imul(E,Gt)|0,l=l+Math.imul(E,At)|0,l=l+Math.imul(A,Gt)|0,G=G+Math.imul(A,At)|0,B=B+Math.imul(y,Rt)|0,l=l+Math.imul(y,It)|0,l=l+Math.imul(d,Rt)|0,G=G+Math.imul(d,It)|0,B=B+Math.imul(u,Ot)|0,l=l+Math.imul(u,mt)|0,l=l+Math.imul(_,Ot)|0,G=G+Math.imul(_,mt)|0,B=B+Math.imul(R,Vt)|0,l=l+Math.imul(R,Nt)|0,l=l+Math.imul(m,Vt)|0,G=G+Math.imul(m,Nt)|0;var on=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(on>>>26)|0,on&=67108863,B=Math.imul(nt,Ut),l=Math.imul(nt,Ft),l=l+Math.imul(it,Ut)|0,G=Math.imul(it,Ft),B=B+Math.imul(J,Gt)|0,l=l+Math.imul(J,At)|0,l=l+Math.imul(j,Gt)|0,G=G+Math.imul(j,At)|0,B=B+Math.imul(E,Rt)|0,l=l+Math.imul(E,It)|0,l=l+Math.imul(A,Rt)|0,G=G+Math.imul(A,It)|0,B=B+Math.imul(y,Ot)|0,l=l+Math.imul(y,mt)|0,l=l+Math.imul(d,Ot)|0,G=G+Math.imul(d,mt)|0,B=B+Math.imul(u,Vt)|0,l=l+Math.imul(u,Nt)|0,l=l+Math.imul(_,Vt)|0,G=G+Math.imul(_,Nt)|0;var an=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(an>>>26)|0,an&=67108863,B=Math.imul(nt,Gt),l=Math.imul(nt,At),l=l+Math.imul(it,Gt)|0,G=Math.imul(it,At),B=B+Math.imul(J,Rt)|0,l=l+Math.imul(J,It)|0,l=l+Math.imul(j,Rt)|0,G=G+Math.imul(j,It)|0,B=B+Math.imul(E,Ot)|0,l=l+Math.imul(E,mt)|0,l=l+Math.imul(A,Ot)|0,G=G+Math.imul(A,mt)|0,B=B+Math.imul(y,Vt)|0,l=l+Math.imul(y,Nt)|0,l=l+Math.imul(d,Vt)|0,G=G+Math.imul(d,Nt)|0;var sn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(sn>>>26)|0,sn&=67108863,B=Math.imul(nt,Rt),l=Math.imul(nt,It),l=l+Math.imul(it,Rt)|0,G=Math.imul(it,It),B=B+Math.imul(J,Ot)|0,l=l+Math.imul(J,mt)|0,l=l+Math.imul(j,Ot)|0,G=G+Math.imul(j,mt)|0,B=B+Math.imul(E,Vt)|0,l=l+Math.imul(E,Nt)|0,l=l+Math.imul(A,Vt)|0,G=G+Math.imul(A,Nt)|0;var un=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(un>>>26)|0,un&=67108863,B=Math.imul(nt,Ot),l=Math.imul(nt,mt),l=l+Math.imul(it,Ot)|0,G=Math.imul(it,mt),B=B+Math.imul(J,Vt)|0,l=l+Math.imul(J,Nt)|0,l=l+Math.imul(j,Vt)|0,G=G+Math.imul(j,Nt)|0;var fn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(fn>>>26)|0,fn&=67108863,B=Math.imul(nt,Vt),l=Math.imul(nt,Nt),l=l+Math.imul(it,Vt)|0,G=Math.imul(it,Nt);var cn=(O+B|0)+((l&8191)<<13)|0;return O=(G+(l>>>13)|0)+(cn>>>26)|0,cn&=67108863,L[0]=me,L[1]=Ve,L[2]=qe,L[3]=Zt,L[4]=Wr,L[5]=Kr,L[6]=Qr,L[7]=Jr,L[8]=jr,L[9]=tn,L[10]=en,L[11]=rn,L[12]=nn,L[13]=on,L[14]=an,L[15]=sn,L[16]=un,L[17]=fn,L[18]=cn,O!==0&&(L[19]=O,T.length++),T};Math.imul||(I=N);function V(U,a,v){v.negative=a.negative^U.negative,v.length=U.length+a.length;for(var T=0,M=0,S=0;S<v.length-1;S++){var L=M;M=0;for(var O=T&67108863,B=Math.min(S,a.length-1),l=Math.max(0,S-U.length+1);l<=B;l++){var G=S-l,ot=U.words[G]|0,at=a.words[l]|0,ut=ot*at,ft=ut&67108863;L=L+(ut/67108864|0)|0,ft=ft+O|0,O=ft&67108863,L=L+(ft>>>26)|0,M+=L>>>26,L&=67108863}v.words[S]=O,T=L,L=M}return T!==0?v.words[S]=T:v.length--,v.strip()}function q(U,a,v){var T=new Y;return T.mulp(U,a,v)}i.prototype.mulTo=function(a,v){var T,M=this.length+a.length;return this.length===10&&a.length===10?T=I(this,a,v):M<63?T=N(this,a,v):M<1024?T=V(this,a,v):T=q(this,a,v),T};function Y(U,a){this.x=U,this.y=a}Y.prototype.makeRBT=function(a){for(var v=new Array(a),T=i.prototype._countBits(a)-1,M=0;M<a;M++)v[M]=this.revBin(M,T,a);return v},Y.prototype.revBin=function(a,v,T){if(a===0||a===T-1)return a;for(var M=0,S=0;S<v;S++)M|=(a&1)<<v-S-1,a>>=1;return M},Y.prototype.permute=function(a,v,T,M,S,L){for(var O=0;O<L;O++)M[O]=v[a[O]],S[O]=T[a[O]]},Y.prototype.transform=function(a,v,T,M,S,L){this.permute(L,a,v,T,M,S);for(var O=1;O<S;O<<=1)for(var B=O<<1,l=Math.cos(2*Math.PI/B),G=Math.sin(2*Math.PI/B),ot=0;ot<S;ot+=B)for(var at=l,ut=G,ft=0;ft<O;ft++){var yt=T[ot+ft],pt=M[ot+ft],k=T[ot+ft+O],$=M[ot+ft+O],F=at*k-ut*$;$=at*$+ut*k,k=F,T[ot+ft]=yt+k,M[ot+ft]=pt+$,T[ot+ft+O]=yt-k,M[ot+ft+O]=pt-$,ft!==B&&(F=l*at-G*ut,ut=l*ut+G*at,at=F)}},Y.prototype.guessLen13b=function(a,v){var T=Math.max(v,a)|1,M=T&1,S=0;for(T=T/2|0;T;T=T>>>1)S++;return 1<<S+1+M},Y.prototype.conjugate=function(a,v,T){if(!(T<=1))for(var M=0;M<T/2;M++){var S=a[M];a[M]=a[T-M-1],a[T-M-1]=S,S=v[M],v[M]=-v[T-M-1],v[T-M-1]=-S}},Y.prototype.normalize13b=function(a,v){for(var T=0,M=0;M<v/2;M++){var S=Math.round(a[2*M+1]/v)*8192+Math.round(a[2*M]/v)+T;a[M]=S&67108863,S<67108864?T=0:T=S/67108864|0}return a},Y.prototype.convert13b=function(a,v,T,M){for(var S=0,L=0;L<v;L++)S=S+(a[L]|0),T[2*L]=S&8191,S=S>>>13,T[2*L+1]=S&8191,S=S>>>13;for(L=2*v;L<M;++L)T[L]=0;n(S===0),n((S&-8192)===0)},Y.prototype.stub=function(a){for(var v=new Array(a),T=0;T<a;T++)v[T]=0;return v},Y.prototype.mulp=function(a,v,T){var M=2*this.guessLen13b(a.length,v.length),S=this.makeRBT(M),L=this.stub(M),O=new Array(M),B=new Array(M),l=new Array(M),G=new Array(M),ot=new Array(M),at=new Array(M),ut=T.words;ut.length=M,this.convert13b(a.words,a.length,O,M),this.convert13b(v.words,v.length,G,M),this.transform(O,L,B,l,M,S),this.transform(G,L,ot,at,M,S);for(var ft=0;ft<M;ft++){var yt=B[ft]*ot[ft]-l[ft]*at[ft];l[ft]=B[ft]*at[ft]+l[ft]*ot[ft],B[ft]=yt}return this.conjugate(B,l,M),this.transform(B,l,ut,L,M,S),this.conjugate(ut,L,M),this.normalize13b(ut,M),T.negative=a.negative^v.negative,T.length=a.length+v.length,T.strip()},i.prototype.mul=function(a){var v=new i(null);return v.words=new Array(this.length+a.length),this.mulTo(a,v)},i.prototype.mulf=function(a){var v=new i(null);return v.words=new Array(this.length+a.length),q(this,a,v)},i.prototype.imul=function(a){return this.clone().mulTo(a,this)},i.prototype.imuln=function(a){n(typeof a=="number"),n(a<67108864);for(var v=0,T=0;T<this.length;T++){var M=(this.words[T]|0)*a,S=(M&67108863)+(v&67108863);v>>=26,v+=M/67108864|0,v+=S>>>26,this.words[T]=S&67108863}return v!==0&&(this.words[T]=v,this.length++),this.length=a===0?1:this.length,this},i.prototype.muln=function(a){return this.clone().imuln(a)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(a){var v=X(a);if(v.length===0)return new i(1);for(var T=this,M=0;M<v.length&&v[M]===0;M++,T=T.sqr());if(++M<v.length)for(var S=T.sqr();M<v.length;M++,S=S.sqr())v[M]!==0&&(T=T.mul(S));return T},i.prototype.iushln=function(a){n(typeof a=="number"&&a>=0);var v=a%26,T=(a-v)/26,M=67108863>>>26-v<<26-v,S;if(v!==0){var L=0;for(S=0;S<this.length;S++){var O=this.words[S]&M,B=(this.words[S]|0)-O<<v;this.words[S]=B|L,L=O>>>26-v}L&&(this.words[S]=L,this.length++)}if(T!==0){for(S=this.length-1;S>=0;S--)this.words[S+T]=this.words[S];for(S=0;S<T;S++)this.words[S]=0;this.length+=T}return this.strip()},i.prototype.ishln=function(a){return n(this.negative===0),this.iushln(a)},i.prototype.iushrn=function(a,v,T){n(typeof a=="number"&&a>=0);var M;v?M=(v-v%26)/26:M=0;var S=a%26,L=Math.min((a-S)/26,this.length),O=67108863^67108863>>>S<<S,B=T;if(M-=L,M=Math.max(0,M),B){for(var l=0;l<L;l++)B.words[l]=this.words[l];B.length=L}if(L!==0)if(this.length>L)for(this.length-=L,l=0;l<this.length;l++)this.words[l]=this.words[l+L];else this.words[0]=0,this.length=1;var G=0;for(l=this.length-1;l>=0&&(G!==0||l>=M);l--){var ot=this.words[l]|0;this.words[l]=G<<26-S|ot>>>S,G=ot&O}return B&&G!==0&&(B.words[B.length++]=G),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(a,v,T){return n(this.negative===0),this.iushrn(a,v,T)},i.prototype.shln=function(a){return this.clone().ishln(a)},i.prototype.ushln=function(a){return this.clone().iushln(a)},i.prototype.shrn=function(a){return this.clone().ishrn(a)},i.prototype.ushrn=function(a){return this.clone().iushrn(a)},i.prototype.testn=function(a){n(typeof a=="number"&&a>=0);var v=a%26,T=(a-v)/26,M=1<<v;if(this.length<=T)return!1;var S=this.words[T];return!!(S&M)},i.prototype.imaskn=function(a){n(typeof a=="number"&&a>=0);var v=a%26,T=(a-v)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=T)return this;if(v!==0&&T++,this.length=Math.min(T,this.length),v!==0){var M=67108863^67108863>>>v<<v;this.words[this.length-1]&=M}return this.strip()},i.prototype.maskn=function(a){return this.clone().imaskn(a)},i.prototype.iaddn=function(a){return n(typeof a=="number"),n(a<67108864),a<0?this.isubn(-a):this.negative!==0?this.length===1&&(this.words[0]|0)<a?(this.words[0]=a-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(a),this.negative=1,this):this._iaddn(a)},i.prototype._iaddn=function(a){this.words[0]+=a;for(var v=0;v<this.length&&this.words[v]>=67108864;v++)this.words[v]-=67108864,v===this.length-1?this.words[v+1]=1:this.words[v+1]++;return this.length=Math.max(this.length,v+1),this},i.prototype.isubn=function(a){if(n(typeof a=="number"),n(a<67108864),a<0)return this.iaddn(-a);if(this.negative!==0)return this.negative=0,this.iaddn(a),this.negative=1,this;if(this.words[0]-=a,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var v=0;v<this.length&&this.words[v]<0;v++)this.words[v]+=67108864,this.words[v+1]-=1;return this.strip()},i.prototype.addn=function(a){return this.clone().iaddn(a)},i.prototype.subn=function(a){return this.clone().isubn(a)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(a,v,T){var M=a.length+T,S;this._expand(M);var L,O=0;for(S=0;S<a.length;S++){L=(this.words[S+T]|0)+O;var B=(a.words[S]|0)*v;L-=B&67108863,O=(L>>26)-(B/67108864|0),this.words[S+T]=L&67108863}for(;S<this.length-T;S++)L=(this.words[S+T]|0)+O,O=L>>26,this.words[S+T]=L&67108863;if(O===0)return this.strip();for(n(O===-1),O=0,S=0;S<this.length;S++)L=-(this.words[S]|0)+O,O=L>>26,this.words[S]=L&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(a,v){var T=this.length-a.length,M=this.clone(),S=a,L=S.words[S.length-1]|0,O=this._countBits(L);T=26-O,T!==0&&(S=S.ushln(T),M.iushln(T),L=S.words[S.length-1]|0);var B=M.length-S.length,l;if(v!=="mod"){l=new i(null),l.length=B+1,l.words=new Array(l.length);for(var G=0;G<l.length;G++)l.words[G]=0}var ot=M.clone()._ishlnsubmul(S,1,B);ot.negative===0&&(M=ot,l&&(l.words[B]=1));for(var at=B-1;at>=0;at--){var ut=(M.words[S.length+at]|0)*67108864+(M.words[S.length+at-1]|0);for(ut=Math.min(ut/L|0,67108863),M._ishlnsubmul(S,ut,at);M.negative!==0;)ut--,M.negative=0,M._ishlnsubmul(S,1,at),M.isZero()||(M.negative^=1);l&&(l.words[at]=ut)}return l&&l.strip(),M.strip(),v!=="div"&&T!==0&&M.iushrn(T),{div:l||null,mod:M}},i.prototype.divmod=function(a,v,T){if(n(!a.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var M,S,L;return this.negative!==0&&a.negative===0?(L=this.neg().divmod(a,v),v!=="mod"&&(M=L.div.neg()),v!=="div"&&(S=L.mod.neg(),T&&S.negative!==0&&S.iadd(a)),{div:M,mod:S}):this.negative===0&&a.negative!==0?(L=this.divmod(a.neg(),v),v!=="mod"&&(M=L.div.neg()),{div:M,mod:L.mod}):(this.negative&a.negative)!==0?(L=this.neg().divmod(a.neg(),v),v!=="div"&&(S=L.mod.neg(),T&&S.negative!==0&&S.isub(a)),{div:L.div,mod:S}):a.length>this.length||this.cmp(a)<0?{div:new i(0),mod:this}:a.length===1?v==="div"?{div:this.divn(a.words[0]),mod:null}:v==="mod"?{div:null,mod:new i(this.modn(a.words[0]))}:{div:this.divn(a.words[0]),mod:new i(this.modn(a.words[0]))}:this._wordDiv(a,v)},i.prototype.div=function(a){return this.divmod(a,"div",!1).div},i.prototype.mod=function(a){return this.divmod(a,"mod",!1).mod},i.prototype.umod=function(a){return this.divmod(a,"mod",!0).mod},i.prototype.divRound=function(a){var v=this.divmod(a);if(v.mod.isZero())return v.div;var T=v.div.negative!==0?v.mod.isub(a):v.mod,M=a.ushrn(1),S=a.andln(1),L=T.cmp(M);return L<0||S===1&&L===0?v.div:v.div.negative!==0?v.div.isubn(1):v.div.iaddn(1)},i.prototype.modn=function(a){n(a<=67108863);for(var v=(1<<26)%a,T=0,M=this.length-1;M>=0;M--)T=(v*T+(this.words[M]|0))%a;return T},i.prototype.idivn=function(a){n(a<=67108863);for(var v=0,T=this.length-1;T>=0;T--){var M=(this.words[T]|0)+v*67108864;this.words[T]=M/a|0,v=M%a}return this.strip()},i.prototype.divn=function(a){return this.clone().idivn(a)},i.prototype.egcd=function(a){n(a.negative===0),n(!a.isZero());var v=this,T=a.clone();v.negative!==0?v=v.umod(a):v=v.clone();for(var M=new i(1),S=new i(0),L=new i(0),O=new i(1),B=0;v.isEven()&&T.isEven();)v.iushrn(1),T.iushrn(1),++B;for(var l=T.clone(),G=v.clone();!v.isZero();){for(var ot=0,at=1;(v.words[0]&at)===0&&ot<26;++ot,at<<=1);if(ot>0)for(v.iushrn(ot);ot-- >0;)(M.isOdd()||S.isOdd())&&(M.iadd(l),S.isub(G)),M.iushrn(1),S.iushrn(1);for(var ut=0,ft=1;(T.words[0]&ft)===0&&ut<26;++ut,ft<<=1);if(ut>0)for(T.iushrn(ut);ut-- >0;)(L.isOdd()||O.isOdd())&&(L.iadd(l),O.isub(G)),L.iushrn(1),O.iushrn(1);v.cmp(T)>=0?(v.isub(T),M.isub(L),S.isub(O)):(T.isub(v),L.isub(M),O.isub(S))}return{a:L,b:O,gcd:T.iushln(B)}},i.prototype._invmp=function(a){n(a.negative===0),n(!a.isZero());var v=this,T=a.clone();v.negative!==0?v=v.umod(a):v=v.clone();for(var M=new i(1),S=new i(0),L=T.clone();v.cmpn(1)>0&&T.cmpn(1)>0;){for(var O=0,B=1;(v.words[0]&B)===0&&O<26;++O,B<<=1);if(O>0)for(v.iushrn(O);O-- >0;)M.isOdd()&&M.iadd(L),M.iushrn(1);for(var l=0,G=1;(T.words[0]&G)===0&&l<26;++l,G<<=1);if(l>0)for(T.iushrn(l);l-- >0;)S.isOdd()&&S.iadd(L),S.iushrn(1);v.cmp(T)>=0?(v.isub(T),M.isub(S)):(T.isub(v),S.isub(M))}var ot;return v.cmpn(1)===0?ot=M:ot=S,ot.cmpn(0)<0&&ot.iadd(a),ot},i.prototype.gcd=function(a){if(this.isZero())return a.abs();if(a.isZero())return this.abs();var v=this.clone(),T=a.clone();v.negative=0,T.negative=0;for(var M=0;v.isEven()&&T.isEven();M++)v.iushrn(1),T.iushrn(1);do{for(;v.isEven();)v.iushrn(1);for(;T.isEven();)T.iushrn(1);var S=v.cmp(T);if(S<0){var L=v;v=T,T=L}else if(S===0||T.cmpn(1)===0)break;v.isub(T)}while(!0);return T.iushln(M)},i.prototype.invm=function(a){return this.egcd(a).a.umod(a)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(a){return this.words[0]&a},i.prototype.bincn=function(a){n(typeof a=="number");var v=a%26,T=(a-v)/26,M=1<<v;if(this.length<=T)return this._expand(T+1),this.words[T]|=M,this;for(var S=M,L=T;S!==0&&L<this.length;L++){var O=this.words[L]|0;O+=S,S=O>>>26,O&=67108863,this.words[L]=O}return S!==0&&(this.words[L]=S,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(a){var v=a<0;if(this.negative!==0&&!v)return-1;if(this.negative===0&&v)return 1;this.strip();var T;if(this.length>1)T=1;else{v&&(a=-a),n(a<=67108863,"Number is too big");var M=this.words[0]|0;T=M===a?0:M<a?-1:1}return this.negative!==0?-T|0:T},i.prototype.cmp=function(a){if(this.negative!==0&&a.negative===0)return-1;if(this.negative===0&&a.negative!==0)return 1;var v=this.ucmp(a);return this.negative!==0?-v|0:v},i.prototype.ucmp=function(a){if(this.length>a.length)return 1;if(this.length<a.length)return-1;for(var v=0,T=this.length-1;T>=0;T--){var M=this.words[T]|0,S=a.words[T]|0;if(M!==S){M<S?v=-1:M>S&&(v=1);break}}return v},i.prototype.gtn=function(a){return this.cmpn(a)===1},i.prototype.gt=function(a){return this.cmp(a)===1},i.prototype.gten=function(a){return this.cmpn(a)>=0},i.prototype.gte=function(a){return this.cmp(a)>=0},i.prototype.ltn=function(a){return this.cmpn(a)===-1},i.prototype.lt=function(a){return this.cmp(a)===-1},i.prototype.lten=function(a){return this.cmpn(a)<=0},i.prototype.lte=function(a){return this.cmp(a)<=0},i.prototype.eqn=function(a){return this.cmpn(a)===0},i.prototype.eq=function(a){return this.cmp(a)===0},i.red=function(a){return new et(a)},i.prototype.toRed=function(a){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),a.convertTo(this)._forceRed(a)},i.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(a){return this.red=a,this},i.prototype.forceRed=function(a){return n(!this.red,"Already a number in reduction context"),this._forceRed(a)},i.prototype.redAdd=function(a){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,a)},i.prototype.redIAdd=function(a){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,a)},i.prototype.redSub=function(a){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,a)},i.prototype.redISub=function(a){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,a)},i.prototype.redShl=function(a){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,a)},i.prototype.redMul=function(a){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.mul(this,a)},i.prototype.redIMul=function(a){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.imul(this,a)},i.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(a){return n(this.red&&!a.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,a)};var K={k256:null,p224:null,p192:null,p25519:null};function Q(U,a){this.name=U,this.p=new i(a,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Q.prototype._tmp=function(){var a=new i(null);return a.words=new Array(Math.ceil(this.n/13)),a},Q.prototype.ireduce=function(a){var v=a,T;do this.split(v,this.tmp),v=this.imulK(v),v=v.iadd(this.tmp),T=v.bitLength();while(T>this.n);var M=T<this.n?-1:v.ucmp(this.p);return M===0?(v.words[0]=0,v.length=1):M>0?v.isub(this.p):v.strip!==void 0?v.strip():v._strip(),v},Q.prototype.split=function(a,v){a.iushrn(this.n,0,v)},Q.prototype.imulK=function(a){return a.imul(this.k)};function tt(){Q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(tt,Q),tt.prototype.split=function(a,v){for(var T=4194303,M=Math.min(a.length,9),S=0;S<M;S++)v.words[S]=a.words[S];if(v.length=M,a.length<=9){a.words[0]=0,a.length=1;return}var L=a.words[9];for(v.words[v.length++]=L&T,S=10;S<a.length;S++){var O=a.words[S]|0;a.words[S-10]=(O&T)<<4|L>>>22,L=O}L>>>=22,a.words[S-10]=L,L===0&&a.length>10?a.length-=10:a.length-=9},tt.prototype.imulK=function(a){a.words[a.length]=0,a.words[a.length+1]=0,a.length+=2;for(var v=0,T=0;T<a.length;T++){var M=a.words[T]|0;v+=M*977,a.words[T]=v&67108863,v=M*64+(v/67108864|0)}return a.words[a.length-1]===0&&(a.length--,a.words[a.length-1]===0&&a.length--),a};function H(){Q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(H,Q);function W(){Q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(W,Q);function st(){Q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(st,Q),st.prototype.imulK=function(a){for(var v=0,T=0;T<a.length;T++){var M=(a.words[T]|0)*19+v,S=M&67108863;M>>>=26,a.words[T]=S,v=M}return v!==0&&(a.words[a.length++]=v),a},i._prime=function(a){if(K[a])return K[a];var v;if(a==="k256")v=new tt;else if(a==="p224")v=new H;else if(a==="p192")v=new W;else if(a==="p25519")v=new st;else throw new Error("Unknown prime "+a);return K[a]=v,v};function et(U){if(typeof U=="string"){var a=i._prime(U);this.m=a.p,this.prime=a}else n(U.gtn(1),"modulus must be greater than 1"),this.m=U,this.prime=null}et.prototype._verify1=function(a){n(a.negative===0,"red works only with positives"),n(a.red,"red works only with red numbers")},et.prototype._verify2=function(a,v){n((a.negative|v.negative)===0,"red works only with positives"),n(a.red&&a.red===v.red,"red works only with red numbers")},et.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):a.umod(this.m)._forceRed(this)},et.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},et.prototype.add=function(a,v){this._verify2(a,v);var T=a.add(v);return T.cmp(this.m)>=0&&T.isub(this.m),T._forceRed(this)},et.prototype.iadd=function(a,v){this._verify2(a,v);var T=a.iadd(v);return T.cmp(this.m)>=0&&T.isub(this.m),T},et.prototype.sub=function(a,v){this._verify2(a,v);var T=a.sub(v);return T.cmpn(0)<0&&T.iadd(this.m),T._forceRed(this)},et.prototype.isub=function(a,v){this._verify2(a,v);var T=a.isub(v);return T.cmpn(0)<0&&T.iadd(this.m),T},et.prototype.shl=function(a,v){return this._verify1(a),this.imod(a.ushln(v))},et.prototype.imul=function(a,v){return this._verify2(a,v),this.imod(a.imul(v))},et.prototype.mul=function(a,v){return this._verify2(a,v),this.imod(a.mul(v))},et.prototype.isqr=function(a){return this.imul(a,a.clone())},et.prototype.sqr=function(a){return this.mul(a,a)},et.prototype.sqrt=function(a){if(a.isZero())return a.clone();var v=this.m.andln(3);if(n(v%2===1),v===3){var T=this.m.add(new i(1)).iushrn(2);return this.pow(a,T)}for(var M=this.m.subn(1),S=0;!M.isZero()&&M.andln(1)===0;)S++,M.iushrn(1);n(!M.isZero());var L=new i(1).toRed(this),O=L.redNeg(),B=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new i(2*l*l).toRed(this);this.pow(l,B).cmp(O)!==0;)l.redIAdd(O);for(var G=this.pow(l,M),ot=this.pow(a,M.addn(1).iushrn(1)),at=this.pow(a,M),ut=S;at.cmp(L)!==0;){for(var ft=at,yt=0;ft.cmp(L)!==0;yt++)ft=ft.redSqr();n(yt<ut);var pt=this.pow(G,new i(1).iushln(ut-yt-1));ot=ot.redMul(pt),G=pt.redSqr(),at=at.redMul(G),ut=yt}return ot},et.prototype.invm=function(a){var v=a._invmp(this.m);return v.negative!==0?(v.negative=0,this.imod(v).redNeg()):this.imod(v)},et.prototype.pow=function(a,v){if(v.isZero())return new i(1).toRed(this);if(v.cmpn(1)===0)return a.clone();var T=4,M=new Array(1<<T);M[0]=new i(1).toRed(this),M[1]=a;for(var S=2;S<M.length;S++)M[S]=this.mul(M[S-1],a);var L=M[0],O=0,B=0,l=v.bitLength()%26;for(l===0&&(l=26),S=v.length-1;S>=0;S--){for(var G=v.words[S],ot=l-1;ot>=0;ot--){var at=G>>ot&1;if(L!==M[0]&&(L=this.sqr(L)),at===0&&O===0){B=0;continue}O<<=1,O|=at,B++,!(B!==T&&(S!==0||ot!==0))&&(L=this.mul(L,M[O]),B=0,O=0)}l=26}return L},et.prototype.convertTo=function(a){var v=a.umod(this.m);return v===a?v.clone():v},et.prototype.convertFrom=function(a){var v=a.clone();return v.red=null,v},i.mont=function(a){return new rt(a)};function rt(U){et.call(this,U),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(rt,et),rt.prototype.convertTo=function(a){return this.imod(a.ushln(this.shift))},rt.prototype.convertFrom=function(a){var v=this.imod(a.mul(this.rinv));return v.red=null,v},rt.prototype.imul=function(a,v){if(a.isZero()||v.isZero())return a.words[0]=0,a.length=1,a;var T=a.imul(v),M=T.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=T.isub(M).iushrn(this.shift),L=S;return S.cmp(this.m)>=0?L=S.isub(this.m):S.cmpn(0)<0&&(L=S.iadd(this.m)),L._forceRed(this)},rt.prototype.mul=function(a,v){if(a.isZero()||v.isZero())return new i(0)._forceRed(this);var T=a.mul(v),M=T.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=T.isub(M).iushrn(this.shift),L=S;return S.cmp(this.m)>=0?L=S.isub(this.m):S.cmpn(0)<0&&(L=S.iadd(this.m)),L._forceRed(this)},rt.prototype.invm=function(a){var v=this.imod(a._invmp(this.m).mul(this.r2));return v._forceRed(this)}})(typeof Cn>"u"||Cn,aa)});var Xn=xt((th,sa)=>{"use strict";var j1=ur();sa.exports=gf;function gf(e){return e&&typeof e=="object"&&!!e.words}});var ca=xt((eh,fa)=>{"use strict";var ua=Xn();fa.exports=wf;function wf(e){return Array.isArray(e)&&e.length===2&&ua(e[0])&&ua(e[1])}});var Cr=xt((rh,kt)=>{var kn=!1;if(typeof Float64Array<"u")if(le=new Float64Array(1),re=new Uint32Array(le.buffer),le[0]=1,kn=!0,re[1]===1072693248){let e=function(r,i){return re[0]=r,re[1]=i,le[0]},t=function(r){return le[0]=r,re[0]},n=function(r){return le[0]=r,re[1]};xf=e,yf=t,Mf=n,kt.exports=function(i){return le[0]=i,[re[0],re[1]]},kt.exports.pack=e,kt.exports.lo=t,kt.exports.hi=n}else if(re[0]===1072693248){let e=function(r,i){return re[1]=r,re[0]=i,le[0]},t=function(r){return le[0]=r,re[1]},n=function(r){return le[0]=r,re[0]};bf=e,Tf=t,Pf=n,kt.exports=function(i){return le[0]=i,[re[1],re[0]]},kt.exports.pack=e,kt.exports.lo=t,kt.exports.hi=n}else kn=!1;var le,re,xf,yf,Mf,bf,Tf,Pf;if(!kn){let e=function(r,i){return he.writeUInt32LE(r,0,!0),he.writeUInt32LE(i,4,!0),he.readDoubleLE(0,!0)},t=function(r){return he.writeDoubleLE(r,0,!0),he.readUInt32LE(0,!0)},n=function(r){return he.writeDoubleLE(r,0,!0),he.readUInt32LE(4,!0)};Sf=e,_f=t,Bf=n,he=new Buffer(8),kt.exports=function(i){return he.writeDoubleLE(i,0,!0),[he.readUInt32LE(0,!0),he.readUInt32LE(4,!0)]},kt.exports.pack=e,kt.exports.lo=t,kt.exports.hi=n}var he,Sf,_f,Bf;kt.exports.sign=function(e){return kt.exports.hi(e)>>>31};kt.exports.exponent=function(e){var t=kt.exports.hi(e);return(t<<1>>>21)-1023};kt.exports.fraction=function(e){var t=kt.exports.lo(e),n=kt.exports.hi(e),r=n&(1<<20)-1;return n&2146435072&&(r+=1<<20),[t,r]};kt.exports.denormalized=function(e){var t=kt.exports.hi(e);return!(t&2146435072)}});var Yn=xt((nh,ha)=>{"use strict";var la=ur(),Df=Cr();ha.exports=Uf;function Uf(e){var t=Df.exponent(e);return t<52?new la(e):new la(e*Math.pow(2,52-t)).ushln(t-52)}});var va=xt((ih,pa)=>{"use strict";var Ff=ur();pa.exports=Gf;function Gf(e){return new Ff(e)}});var Xr=xt((oh,da)=>{"use strict";var Af=ur();da.exports=zf;function zf(e){return e.cmp(new Af(0))}});var Qe=xt((ah,wa)=>{"use strict";var kr=Yn(),ga=Xr();wa.exports=Lf;function Lf(e,t){var n=ga(e),r=ga(t);if(n===0)return[kr(0),kr(1)];if(r===0)return[kr(0),kr(0)];r<0&&(e=e.neg(),t=t.neg());var i=e.gcd(t);return i.cmpn(1)?[e.div(i),t.div(i)]:[e,t]}});var Hn=xt((sh,xa)=>{"use strict";var Ef=Qe();xa.exports=Rf;function Rf(e,t){return Ef(e[0].mul(t[1]),e[1].mul(t[0]))}});var Yr=xt((uh,Pa)=>{"use strict";var ya=ca(),Ma=Xn(),Ee=Yn(),ba=va(),If=Qe(),Of=Hn();Pa.exports=Ta;function Ta(e,t){if(ya(e))return t?Of(e,Ta(t)):[e[0].clone(),e[1].clone()];var n=0,r,i;if(Ma(e))r=e.clone();else if(typeof e=="string")r=ba(e);else{if(e===0)return[Ee(0),Ee(1)];if(e===Math.floor(e))r=Ee(e);else{for(;e!==Math.floor(e);)e=e*Math.pow(2,256),n-=256;r=Ee(e)}}if(ya(t))r.mul(t[1]),i=t[0].clone();else if(Ma(t))i=t.clone();else if(typeof t=="string")i=ba(t);else if(!t)i=Ee(1);else if(t===Math.floor(t))i=Ee(t);else{for(;t!==Math.floor(t);)t=t*Math.pow(2,256),n+=256;i=Ee(t)}return n>0?r=r.ushln(n):n<0&&(i=i.ushln(-n)),If(r,i)}});var _a=xt((fh,Sa)=>{"use strict";Sa.exports=mf;function mf(e,t){return e[0].mul(t[1]).cmp(t[0].mul(e[1]))}});var Da=xt((ch,Ba)=>{"use strict";var Vf=Xr();Ba.exports=qf;function qf(e){var t=e.length,n=e.words,r=0;if(t===1)r=n[0];else if(t===2)r=n[0]+n[1]*67108864;else for(var i=0;i<t;i++){var o=n[i];r+=o*Math.pow(67108864,i)}return Vf(e)*r}});var Aa=xt((lh,Ga)=>{"use strict";var Ua=Cr(),Fa=rr().countTrailingZeros;Ga.exports=Nf;function Nf(e){var t=Fa(Ua.lo(e));if(t<32)return t;var n=Fa(Ua.hi(e));return n>20?52:n+32}});var La=xt((hh,za)=>{"use strict";var Zn=Da(),Cf=Aa();za.exports=Xf;function Xf(e){var t=e[0],n=e[1];if(t.cmpn(0)===0)return 0;var r=t.abs().divmod(n.abs()),i=r.div,o=Zn(i),s=r.mod,f=t.negative!==n.negative?-1:1;if(s.cmpn(0)===0)return f*o;if(o){var h=Cf(o)+4,p=Zn(s.ushln(h).divRound(n));return f*(o+p*Math.pow(2,-h))}else{var g=n.bitLength()-s.bitLength()+53,p=Zn(s.ushln(g).divRound(n));return g<1023?f*p*Math.pow(2,-g):(p*=Math.pow(2,-1023),f*p*Math.pow(2,1023-g))}}});var Ra=xt((ph,Ea)=>{"use strict";Ea.exports=Yf;var kf=Yr();function Yf(e){for(var t=new Array(e.length),n=0;n<e.length;++n)t[n]=kf(e[n]);return t}});var Va=xt((vh,ma)=>{"use strict";var $n=Cr(),Ia=Math.pow(2,-1074),Oa=-1>>>0;ma.exports=Hf;function Hf(e,t){if(isNaN(e)||isNaN(t))return NaN;if(e===t)return e;if(e===0)return t<0?-Ia:Ia;var n=$n.hi(e),r=$n.lo(e);return t>e==e>0?r===Oa?(n+=1,r=0):r+=1:r===0?(r=Oa,n-=1):r-=1,$n.pack(r,n)}});var Wn=xt((dh,qa)=>{"use strict";var Zf=Qe();qa.exports=$f;function $f(e,t){return Zf(e[0].mul(t[0]),e[1].mul(t[1]))}});var Kn=xt((gh,Na)=>{"use strict";var Wf=Qe();Na.exports=Kf;function Kf(e,t){return Wf(e[0].mul(t[1]).sub(e[1].mul(t[0])),e[1].mul(t[1]))}});var ka=xt((wh,Xa)=>{"use strict";var Ca=Xr();Xa.exports=Qf;function Qf(e){return Ca(e[0])*Ca(e[1])}});var Ha=xt((xh,Ya)=>{"use strict";var Jf=Kn();Ya.exports=jf;function jf(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=Jf(e[i],t[i]);return r}});var $a=xt((yh,Za)=>{"use strict";var tc=Qe();Za.exports=ec;function ec(e,t){return tc(e[0].mul(t[1]).add(t[0].mul(e[1])),e[1].mul(t[1]))}});var Ka=xt((Mh,Wa)=>{"use strict";var rc=$a();Wa.exports=nc;function nc(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=rc(e[i],t[i]);return r}});var Ja=xt((bh,Qa)=>{"use strict";var ic=Yr(),oc=Wn();Qa.exports=ac;function ac(e,t){for(var n=ic(t),r=e.length,i=new Array(r),o=0;o<r;++o)i[o]=oc(e[o],n);return i}});var rs=xt((Th,es)=>{"use strict";es.exports=hc;var ja=Wn(),sc=Hn(),uc=Kn(),fc=ka(),Qn=Ha(),cc=Ka(),lc=Ja();function ts(e,t){return uc(ja(e[0],t[1]),ja(e[1],t[0]))}function hc(e,t,n,r){var i=Qn(t,e),o=Qn(r,n),s=ts(i,o);if(fc(s)===0)return null;var f=Qn(e,n),h=ts(o,f),p=sc(h,s),g=lc(i,p),D=cc(e,g);return D}});var ls=xt((Ph,cs)=>{"use strict";cs.exports=Pc;var pc=po(),jn=ra(),as=ia(),ns=Yr(),is=_a(),Jn=La(),Hr=Ra(),oe=Va(),vc=rs();function os(e){var t=Jn(e);return[oe(t,-1/0),oe(t,1/0)]}function dc(e,t){for(var n=new Array(t.length),r=0;r<t.length;++r){var i=t[r],o=e[i[0]],s=e[i[1]];n[r]=[oe(Math.min(o[0],s[0]),-1/0),oe(Math.min(o[1],s[1]),-1/0),oe(Math.max(o[0],s[0]),1/0),oe(Math.max(o[1],s[1]),1/0)]}return n}function ss(e){for(var t=new Array(e.length),n=0;n<e.length;++n){var r=e[n];t[n]=[oe(r[0],-1/0),oe(r[1],-1/0),oe(r[0],1/0),oe(r[1],1/0)]}return t}function gc(e,t,n){var r=[];return jn(n,function(i,o){var s=t[i],f=t[o];if(!(s[0]===f[0]||s[0]===f[1]||s[1]===f[0]||s[1]===f[1])){var h=e[s[0]],p=e[s[1]],g=e[f[0]],D=e[f[1]];as(h,p,g,D)&&r.push([i,o])}}),r}function wc(e,t,n,r){var i=[];return jn(n,r,function(o,s){var f=t[o];if(!(f[0]===s||f[1]===s)){var h=e[s],p=e[f[0]],g=e[f[1]];as(p,g,h,h)&&i.push([o,s])}}),i}function xc(e,t,n,r,i){var o,s,f=e.map(function(et){return[ns(et[0]),ns(et[1])]});for(o=0;o<n.length;++o){var h=n[o];s=h[0];var p=h[1],g=t[s],D=t[p],X=vc(Hr(e[g[0]]),Hr(e[g[1]]),Hr(e[D[0]]),Hr(e[D[1]]));if(X){var N=e.length;e.push([Jn(X[0]),Jn(X[1])]),f.push(X),r.push([s,N],[p,N])}}for(r.sort(function(et,rt){if(et[0]!==rt[0])return et[0]-rt[0];var U=f[et[1]],a=f[rt[1]];return is(U[0],a[0])||is(U[1],a[1])}),o=r.length-1;o>=0;--o){var I=r[o];s=I[0];var V=t[s],q=V[0],Y=V[1],K=e[q],Q=e[Y];if((K[0]-Q[0]||K[1]-Q[1])<0){var tt=q;q=Y,Y=tt}V[0]=q;var H=V[1]=I[1],W;for(i&&(W=V[2]);o>0&&r[o-1][0]===s;){var I=r[--o],st=I[1];i?t.push([H,st,W]):t.push([H,st]),H=st}i?t.push([H,Y,W]):t.push([H,Y])}return f}function us(e,t,n){for(var r=t.length,i=new pc(r),o=[],s=0;s<t.length;++s){var f=t[s],h=os(f[0]),p=os(f[1]);o.push([oe(h[0],-1/0),oe(p[0],-1/0),oe(h[1],1/0),oe(p[1],1/0)])}jn(o,function(I,V){i.link(I,V)});for(var g=!0,D=new Array(r),s=0;s<r;++s){var X=i.find(s);X!==s&&(g=!1,e[X]=[Math.min(e[s][0],e[X][0]),Math.min(e[s][1],e[X][1])])}if(g)return null;for(var N=0,s=0;s<r;++s){var X=i.find(s);X===s?(D[s]=N,e[N++]=e[s]):D[s]=-1}e.length=N;for(var s=0;s<r;++s)D[s]<0&&(D[s]=D[i.find(s)]);return D}function yc(e,t){return e[0]-t[0]||e[1]-t[1]}function Mc(e,t){var n=e[0]-t[0]||e[1]-t[1];return n||(e[2]<t[2]?-1:e[2]>t[2]?1:0)}function fs(e,t,n){if(e.length!==0){if(t)for(var r=0;r<e.length;++r){var i=e[r],o=t[i[0]],s=t[i[1]];i[0]=Math.min(o,s),i[1]=Math.max(o,s)}else for(var r=0;r<e.length;++r){var i=e[r],o=i[0],s=i[1];i[0]=Math.min(o,s),i[1]=Math.max(o,s)}n?e.sort(Mc):e.sort(yc);for(var f=1,r=1;r<e.length;++r){var h=e[r-1],p=e[r];p[0]===h[0]&&p[1]===h[1]&&(!n||p[2]===h[2])||(e[f++]=p)}e.length=f}}function bc(e,t,n){var r=us(e,[],ss(e));return fs(t,r,n),!!r}function Tc(e,t,n){var r=dc(e,t),i=gc(e,t,r),o=ss(e),s=wc(e,t,r,o),f=xc(e,t,i,s,n),h=us(e,f,o);return fs(t,h,n),h?!0:i.length>0||s.length>0}function Pc(e,t,n){var r;if(n){r=t;for(var i=new Array(t.length),o=0;o<t.length;++o){var s=t[o];i[o]=[s[0],s[1],n[o]]}t=i}for(var f=bc(e,t,!!n);Tc(e,t,!!n);)f=!0;if(n&&f){r.length=0,n.length=0;for(var o=0;o<t.length;++o){var s=t[o];r.push([s[0],s[1]]),n.push(s[2])}}return f}});function ne(e,t,n,r,i,o,s){let f=e.createTexture({label:t,size:{width:n,height:r},format:o,usage:s,mipLevelCount:i,sampleCount:1,dimension:"2d"}),h=f.createView(),p=[];for(let D=0;D<i;D++)p.push(f.createView({label:t,format:o,dimension:"2d",aspect:"all",baseMipLevel:D,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1}));let g=e.createSampler({label:`${t} sampler`,addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"});return{size:{width:n,height:r},texture:f,view:h,mip_view:p,sampler:g}}function qt(e){return e.canvas?navigator.gpu?.getPreferredCanvasFormat():e.context.getPreferredFormat()}function pe(e,t,n,r){r=r||qt(e);let i=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,s=ne(e.device,t,n.width,n.height,1,r,i);e.device.queue.writeTexture({texture:s.texture},n.data,{bytesPerRow:4*n.width},{width:n.width,height:n.height});let f={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return s.sampler=e.device.createSampler(f),s}async function ve(e,t,n,r){let o=await(await fetch(n)).blob();r=r||qt(e);let s=await createImageBitmap(o),f=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,p=ne(e.device,t,s.width,s.height,1,r,f);e.device.queue.copyExternalImageToTexture({source:s},{texture:p.texture},{width:s.width,height:s.height});let g={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return p.sampler=e.device.createSampler(g),p}var vi="const BLOOM_MIP_COUNT:i32=7;const MODE_PREFILTER:u32=0u;const MODE_DOWNSAMPLE:u32=1u;const MODE_UPSAMPLE_FIRST:u32=2u;const MODE_UPSAMPLE:u32=3u;const EPSILON:f32=1.0e-4;struct bloom_param{parameters:vec4<f32>,combine_constant:f32,doop:u32,ferp:u32,}struct mode_lod_param{mode_lod:u32,}@group(0)@binding(0)var output_texture:texture_storage_2d<rgba16float,write>;@group(0)@binding(1)var input_texture:texture_2d<f32>;@group(0)@binding(2)var bloom_texture:texture_2d<f32>;@group(0)@binding(3)var samp:sampler;@group(0)@binding(4)var<uniform> param:bloom_param;@group(0)@binding(5)var<uniform> pc:mode_lod_param;fn QuadraticThreshold(color:vec4<f32>,threshold:f32,curve:vec3<f32>)->vec4<f32>{let brightness=max(max(color.r,color.g),color.b);var rq:f32=clamp(brightness-curve.x,0.0,curve.y);rq=curve.z*(rq*rq);let ret_color=color*max(rq,brightness-threshold)/max(brightness,EPSILON);return ret_color;}fn Prefilter(color:vec4<f32>,uv:vec2<f32>)->vec4<f32>{let clamp_value=20.0;var c=min(vec4<f32>(clamp_value),color);c=QuadraticThreshold(color,param.parameters.x,param.parameters.yzw);return c;}fn DownsampleBox13(tex:texture_2d<f32>,lod:f32,uv:vec2<f32>,tex_size:vec2<f32>)->vec3<f32>{let A=textureSampleLevel(tex,samp,uv,lod).rgb;let texel_size=tex_size*0.5;let B=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-1.0,-1.0),lod).rgb;let C=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-1.0,1.0),lod).rgb;let D=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(1.0,1.0),lod).rgb;let E=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(1.0,-1.0),lod).rgb;let F=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-2.0,-2.0),lod).rgb;let G=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-2.0,0.0),lod).rgb;let H=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(0.0,2.0),lod).rgb;let I=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(2.0,2.0),lod).rgb;let J=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(2.0,2.0),lod).rgb;let K=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(2.0,0.0),lod).rgb;let L=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-2.0,-2.0),lod).rgb;let M=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(0.0,-2.0),lod).rgb;var result:vec3<f32>=vec3<f32>(0.0);result=result+(B+C+D+E)*0.5;result=result+(F+G+A+M)*0.125;result=result+(G+H+I+A)*0.125;result=result+(A+I+J+K)*0.125;result=result+(M+A+K+L)*0.125;result=result*0.25;return result;}fn UpsampleTent9(tex:texture_2d<f32>,lod:f32,uv:vec2<f32>,texel_size:vec2<f32>,radius:f32)->vec3<f32>{let offset=texel_size.xyxy*vec4<f32>(1.0,1.0,-1.0,0.0)*radius;var result:vec3<f32>=textureSampleLevel(tex,samp,uv,lod).rgb*4.0;result=result+textureSampleLevel(tex,samp,uv-offset.xy,lod).rgb;result=result+textureSampleLevel(tex,samp,uv-offset.wy,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv-offset.zy,lod).rgb;result=result+textureSampleLevel(tex,samp,uv+offset.zw,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv+offset.xw,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv+offset.zy,lod).rgb;result=result+textureSampleLevel(tex,samp,uv+offset.wy,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv+offset.xy,lod).rgb;return result*(1.0/16.0);}fn combine(ex_color:vec3<f32>,color_to_add:vec3<f32>,combine_constant:f32)->vec3<f32>{let existing_color=ex_color+(-color_to_add);let blended_color=(combine_constant*existing_color)+color_to_add;return blended_color;}@compute @workgroup_size(8,4,1)fn cs_main(@builtin(global_invocation_id)global_invocation_id:vec3<u32>){let mode=pc.mode_lod>>16u;let lod=pc.mode_lod&65535u;let imgSize=textureDimensions(output_texture);if(global_invocation_id.x<u32(imgSize.x)&&global_invocation_id.y<u32(imgSize.y)){var texCoords:vec2<f32>=vec2<f32>(f32(global_invocation_id.x)/f32(imgSize.x),f32(global_invocation_id.y)/f32(imgSize.y));texCoords=texCoords+(1.0/vec2<f32>(imgSize))*0.5;let texSize=vec2<f32>(textureDimensions(input_texture,i32(lod)));var color:vec4<f32>=vec4<f32>(1.0);if(mode==MODE_PREFILTER){color=vec4<f32>(DownsampleBox13(input_texture,f32(lod),texCoords,1.0/texSize),1.0);color=Prefilter(color,texCoords);}else if(mode==MODE_DOWNSAMPLE){color=vec4<f32>(DownsampleBox13(input_texture,f32(lod),texCoords,1.0/texSize),1.0);}else if(mode==MODE_UPSAMPLE_FIRST){let bloomTexSize=textureDimensions(input_texture,i32(lod)+1);let sampleScale=1.0;let upsampledTexture=UpsampleTent9(input_texture,f32(lod)+1.0,texCoords,1.0/vec2<f32>(bloomTexSize),sampleScale);let existing=textureSampleLevel(input_texture,samp,texCoords,f32(lod)).rgb;color=vec4<f32>(combine(existing,upsampledTexture,param.combine_constant),1.0);}else if(mode==MODE_UPSAMPLE){let bloomTexSize=textureDimensions(bloom_texture,i32(lod)+1);let sampleScale=1.0;let upsampledTexture=UpsampleTent9(bloom_texture,f32(lod)+1.0,texCoords,1.0/vec2<f32>(bloomTexSize),sampleScale);let existing=textureSampleLevel(input_texture,samp,texCoords,f32(lod)).rgb;color=vec4<f32>(combine(existing,upsampledTexture,param.combine_constant),1.0);}textureStore(output_texture,vec2<i32>(global_invocation_id.xy),color);}}";var ue=7,Xs=0,di=1,ks=2,gi=3,wi={type:"cobalt:bloom",refs:[{name:"emissive",type:"textureView",format:"rgba16",access:"read"},{name:"hdr",type:"textureView",format:"rgba16",access:"read"},{name:"bloom",type:"textureView",format:"rgba16",access:"readwrite"}],onInit:async function(e,t={}){return Ys(e,t)},onRun:function(e,t,n){Hs(e,t.data,n)},onDestroy:function(e,t){yi(t)},onResize:function(e,t){Zs(e,t)},onViewportPosition:function(e,t){}};function Ys(e,t){let{device:n}=e,r=e.viewport.width,i=e.viewport.height,o={compute_pipeline:null,bind_group:[],bind_group_layout:[],bind_groups_textures:[],buffers:[]},s=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.COMPUTE,storageTexture:{access:"write-only",format:"rgba16float",viewDimension:"2d"}},{binding:1,visibility:GPUShaderStage.COMPUTE,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}},{binding:2,visibility:GPUShaderStage.COMPUTE,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}},{binding:3,visibility:GPUShaderStage.COMPUTE,sampler:{}},{binding:4,visibility:GPUShaderStage.COMPUTE,buffer:{type:"uniform"}},{binding:5,visibility:GPUShaderStage.COMPUTE,buffer:{type:"uniform"}}]});o.bind_group_layout.push(s),o.bind_groups_textures.push(ne(n,"bloom downsampler image 0",r/2,i/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),o.bind_groups_textures.push(ne(n,"bloom downsampler image 1",r/2,i/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),o.bind_groups_textures.push(t.refs.bloom.data);let f=n.createPipelineLayout({bindGroupLayouts:o.bind_group_layout}),h=n.createComputePipeline({layout:f,compute:{module:n.createShaderModule({code:vi}),entryPoint:"cs_main"}});return xi(e,o,t),o.compute_pipeline=h,o}function xi(e,t,n){let{refs:r}=n,{device:i}=e,o=n.options.bloom_threshold??.1,s=n.options.bloom_knee??.2,f=n.options.bloom_combine_constant??.68,h=new Float32Array([o,o-s,s*2,.25/s,f,0,0,0]),p=i.createBuffer({label:"bloom static parameters buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});t.buffers.push(p),new Float32Array(p.getMappedRange()).set(h),p.unmap(),t.bind_group.length=0,t.params_buf=p,t.bind_group.push(Ne(i,t,t.bind_groups_textures[0].mip_view[0],r.emissive.data.view,r.hdr.data.view,r.hdr.data.sampler,p,Xs<<16|0));for(let D=1;D<ue;D++)t.bind_group.push(Ne(i,t,t.bind_groups_textures[1].mip_view[D],t.bind_groups_textures[0].view,r.hdr.data.view,r.hdr.data.sampler,p,di<<16|D-1)),t.bind_group.push(Ne(i,t,t.bind_groups_textures[0].mip_view[D],t.bind_groups_textures[1].view,r.hdr.data.view,r.hdr.data.sampler,p,di<<16|D));t.bind_group.push(Ne(i,t,t.bind_groups_textures[2].mip_view[ue-1],t.bind_groups_textures[0].view,r.hdr.data.view,r.hdr.data.sampler,p,ks<<16|ue-2));let g=!0;for(let D=ue-2;D>=0;D--)g?(t.bind_group.push(Ne(i,t,t.bind_groups_textures[1].mip_view[D],t.bind_groups_textures[0].view,t.bind_groups_textures[2].view,r.hdr.data.sampler,p,gi<<16|D)),g=!1):(t.bind_group.push(Ne(i,t,t.bind_groups_textures[2].mip_view[D],t.bind_groups_textures[0].view,t.bind_groups_textures[1].view,r.hdr.data.sampler,p,gi<<16|D)),g=!0)}function Ne(e,t,n,r,i,o,s,f){let h=new Uint32Array([f]),p=e.createBuffer({label:"bloom static mode_lod buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});return t.buffers.push(p),new Uint32Array(p.getMappedRange()).set(h),p.unmap(),e.createBindGroup({label:"bloom bind group layout",layout:t.bind_group_layout[0],entries:[{binding:0,resource:n},{binding:1,resource:r},{binding:2,resource:i},{binding:3,resource:o},{binding:4,resource:{buffer:s}},{binding:5,resource:{buffer:p}}]})}function Hs(e,t,n){let f=0,h=n.beginComputePass({label:"bloom Compute Pass"});h.setPipeline(t.compute_pipeline),h.setBindGroup(0,t.bind_group[f]),f+=1;let p=lr(0,t.bind_groups_textures[0]);h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);for(let g=1;g<ue;g++)p=lr(g,t.bind_groups_textures[0]),h.setBindGroup(0,t.bind_group[f]),f+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1),h.setBindGroup(0,t.bind_group[f]),f+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.setBindGroup(0,t.bind_group[f]),f+=1,p=lr(ue-1,t.bind_groups_textures[2]),h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);for(let g=ue-2;g>=0;g--)p=lr(g,t.bind_groups_textures[2]),h.setBindGroup(0,t.bind_group[f]),f+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.end()}function lr(e,t){let n=t.size.width,r=t.size.height;for(let i=0;i<e;i++)n/=2,r/=2;return{width:n,height:r,depthOrArrayLayers:1}}function Zs(e,t){let{device:n}=e,r=t.data;yi(r),r.bind_groups_textures.push(ne(n,"bloom downsampler image 0",e.viewport.width/2,e.viewport.height/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),r.bind_groups_textures.push(ne(n,"bloom downsampler image 1",e.viewport.width/2,e.viewport.height/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),r.bind_groups_textures.push(t.refs.bloom.data),xi(e,r,t)}function yi(e){for(let t of e.bind_groups_textures)t.texture.destroy();for(let t of e.buffers)t.destroy();e.buffers.length=0,e.bind_groups_textures.length=0}var Mi="struct DisplacementParameters{offset:vec2<f32>,scale:f32,};@group(0)@binding(0)var<uniform> uniforms:DisplacementParameters;@group(0)@binding(1)var colorTexture:texture_2d<f32>;@group(0)@binding(2)var colorSampler:sampler;@group(0)@binding(3)var noiseTexture:texture_2d<f32>;@group(0)@binding(4)var noiseSampler:sampler;@group(0)@binding(5)var displacementTexture:texture_2d<f32>;struct VertexIn{@builtin(vertex_index)vertexIndex:u32,};struct VertexOut{@builtin(position)position:vec4<f32>,@location(0)uv:vec2<f32>,};@vertex fn main_vertex(in:VertexIn)->VertexOut{const corners=array<vec2<f32>,4>(vec2<f32>(-1,-1),vec2<f32>(1,-1),vec2<f32>(-1,1),vec2<f32>(1,1),);let screenPosition=corners[in.vertexIndex];var out:VertexOut;out.position=vec4<f32>(screenPosition,0,1);out.uv=(0.5+0.5*screenPosition*vec2<f32>(1,-1));return out;}struct FragmentOut{@location(0)color:vec4<f32>,};@fragment fn main_fragment(in:VertexOut)->FragmentOut{let noiseTextureDimensions=vec2<f32>(textureDimensions(noiseTexture,0));let noiseUv=in.uv+uniforms.offset/noiseTextureDimensions;var noise=textureSample(noiseTexture,noiseSampler,noiseUv).rg;noise-=0.5;noise*=uniforms.scale/noiseTextureDimensions;let displacement=textureSample(displacementTexture,colorSampler,in.uv).r;noise*=displacement;let colorUv=in.uv+noise;var out:FragmentOut;out.color=textureSample(colorTexture,colorSampler,colorUv);return out;}";var hr=class{device;targetFormat;renderPipeline;colorSampler;noiseSampler;displacementParametersBuffer;renderBundle=null;colorTextureView;noiseMapTextureView;displacementTextureView;constructor(t){this.device=t.device,this.targetFormat=t.targetFormat,this.colorTextureView=t.colorTextureView,this.noiseMapTextureView=t.noiseMapTextureView,this.displacementTextureView=t.displacementTextureView,this.displacementParametersBuffer=t.displacementParametersBuffer;let n=this.device.createShaderModule({label:"DisplacementComposition shader module",code:Mi});this.renderPipeline=this.device.createRenderPipeline({label:"DisplacementComposition renderpipeline",layout:"auto",vertex:{module:n,entryPoint:"main_vertex"},fragment:{module:n,entryPoint:"main_fragment",targets:[{format:t.targetFormat}]},primitive:{cullMode:"none",topology:"triangle-strip"}}),this.noiseSampler=this.device.createSampler({label:"DisplacementComposition noisesampler",addressModeU:"repeat",addressModeV:"repeat",addressModeW:"repeat",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"}),this.colorSampler=this.device.createSampler({label:"DisplacementComposition colorSampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"})}getRenderBundle(){return this.renderBundle||(this.renderBundle=this.buildRenderBundle()),this.renderBundle}destroy(){}setColorTextureView(t){this.colorTextureView=t,this.renderBundle=null}setNoiseMapTextureView(t){this.noiseMapTextureView=t,this.renderBundle=null}setDisplacementTextureView(t){this.displacementTextureView=t,this.renderBundle=null}buildRenderBundle(){let t=this.device.createBindGroup({label:"DisplacementComposition bindgroup 0",layout:this.renderPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.displacementParametersBuffer.bufferGpu}},{binding:1,resource:this.colorTextureView},{binding:2,resource:this.colorSampler},{binding:3,resource:this.noiseMapTextureView},{binding:4,resource:this.noiseSampler},{binding:5,resource:this.displacementTextureView}]}),n=this.device.createRenderBundleEncoder({label:"DisplacementComposition renderbundle encoder",colorFormats:[this.targetFormat]});return n.setPipeline(this.renderPipeline),n.setBindGroup(0,t),n.draw(4),n.finish({label:"DisplacementComposition renderbundle"})}};var pr=class{device;bufferGpu;needsUpdate=!0;constructor(t){this.device=t.device,this.bufferGpu=this.device.createBuffer({label:"DisplacementParametersBuffer buffer",size:16,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.setParameters(t.initialParameters)}setParameters(t){this.device.queue.writeBuffer(this.bufferGpu,0,new Float32Array([t.offsetX,t.offsetY,t.scale]))}destroy(){this.bufferGpu.destroy()}};var bi="struct TransformData{mvpMatrix:mat4x4<f32>,};@group(0)@binding(0)var<uniform> transformUBO:TransformData;struct VertexIn{@location(0)position:vec2<f32>,};struct VertexOut{@builtin(position)position:vec4<f32>,};@vertex fn main_vertex(in:VertexIn)->VertexOut{var output:VertexOut;output.position=transformUBO.mvpMatrix*vec4<f32>(in.position,0.0,1.0);return output;}struct FragmentOut{@location(0)color:vec4<f32>,};@fragment fn main_fragment()->FragmentOut{var out:FragmentOut;out.color=vec4<f32>(1.0,1.0,1.0,1.0);return out;}";function $s(e,t){return class extends e{constructor(...n){super(...n),t(this)}}}var Ws=$s(Array,e=>e.fill(0)),Tt=1e-6;function Ks(e){function t(R=0,m=0){let C=new e(2);return R!==void 0&&(C[0]=R,m!==void 0&&(C[1]=m)),C}let n=t;function r(R,m,C){let u=C??new e(2);return u[0]=R,u[1]=m,u}function i(R,m){let C=m??new e(2);return C[0]=Math.ceil(R[0]),C[1]=Math.ceil(R[1]),C}function o(R,m){let C=m??new e(2);return C[0]=Math.floor(R[0]),C[1]=Math.floor(R[1]),C}function s(R,m){let C=m??new e(2);return C[0]=Math.round(R[0]),C[1]=Math.round(R[1]),C}function f(R,m=0,C=1,u){let _=u??new e(2);return _[0]=Math.min(C,Math.max(m,R[0])),_[1]=Math.min(C,Math.max(m,R[1])),_}function h(R,m,C){let u=C??new e(2);return u[0]=R[0]+m[0],u[1]=R[1]+m[1],u}function p(R,m,C,u){let _=u??new e(2);return _[0]=R[0]+m[0]*C,_[1]=R[1]+m[1]*C,_}function g(R,m){let C=R[0],u=R[1],_=m[0],x=m[1],y=Math.sqrt(C*C+u*u),d=Math.sqrt(_*_+x*x),P=y*d,E=P&&rt(R,m)/P;return Math.acos(E)}function D(R,m,C){let u=C??new e(2);return u[0]=R[0]-m[0],u[1]=R[1]-m[1],u}let X=D;function N(R,m){return Math.abs(R[0]-m[0])<Tt&&Math.abs(R[1]-m[1])<Tt}function I(R,m){return R[0]===m[0]&&R[1]===m[1]}function V(R,m,C,u){let _=u??new e(2);return _[0]=R[0]+C*(m[0]-R[0]),_[1]=R[1]+C*(m[1]-R[1]),_}function q(R,m,C,u){let _=u??new e(2);return _[0]=R[0]+C[0]*(m[0]-R[0]),_[1]=R[1]+C[1]*(m[1]-R[1]),_}function Y(R,m,C){let u=C??new e(2);return u[0]=Math.max(R[0],m[0]),u[1]=Math.max(R[1],m[1]),u}function K(R,m,C){let u=C??new e(2);return u[0]=Math.min(R[0],m[0]),u[1]=Math.min(R[1],m[1]),u}function Q(R,m,C){let u=C??new e(2);return u[0]=R[0]*m,u[1]=R[1]*m,u}let tt=Q;function H(R,m,C){let u=C??new e(2);return u[0]=R[0]/m,u[1]=R[1]/m,u}function W(R,m){let C=m??new e(2);return C[0]=1/R[0],C[1]=1/R[1],C}let st=W;function et(R,m,C){let u=C??new e(3),_=R[0]*m[1]-R[1]*m[0];return u[0]=0,u[1]=0,u[2]=_,u}function rt(R,m){return R[0]*m[0]+R[1]*m[1]}function U(R){let m=R[0],C=R[1];return Math.sqrt(m*m+C*C)}let a=U;function v(R){let m=R[0],C=R[1];return m*m+C*C}let T=v;function M(R,m){let C=R[0]-m[0],u=R[1]-m[1];return Math.sqrt(C*C+u*u)}let S=M;function L(R,m){let C=R[0]-m[0],u=R[1]-m[1];return C*C+u*u}let O=L;function B(R,m){let C=m??new e(2),u=R[0],_=R[1],x=Math.sqrt(u*u+_*_);return x>1e-5?(C[0]=u/x,C[1]=_/x):(C[0]=0,C[1]=0),C}function l(R,m){let C=m??new e(2);return C[0]=-R[0],C[1]=-R[1],C}function G(R,m){let C=m??new e(2);return C[0]=R[0],C[1]=R[1],C}let ot=G;function at(R,m,C){let u=C??new e(2);return u[0]=R[0]*m[0],u[1]=R[1]*m[1],u}let ut=at;function ft(R,m,C){let u=C??new e(2);return u[0]=R[0]/m[0],u[1]=R[1]/m[1],u}let yt=ft;function pt(R=1,m){let C=m??new e(2),u=Math.random()*2*Math.PI;return C[0]=Math.cos(u)*R,C[1]=Math.sin(u)*R,C}function k(R){let m=R??new e(2);return m[0]=0,m[1]=0,m}function $(R,m,C){let u=C??new e(2),_=R[0],x=R[1];return u[0]=_*m[0]+x*m[4]+m[12],u[1]=_*m[1]+x*m[5]+m[13],u}function F(R,m,C){let u=C??new e(2),_=R[0],x=R[1];return u[0]=m[0]*_+m[4]*x+m[8],u[1]=m[1]*_+m[5]*x+m[9],u}function c(R,m,C,u){let _=u??new e(2),x=R[0]-m[0],y=R[1]-m[1],d=Math.sin(C),P=Math.cos(C);return _[0]=x*P-y*d+m[0],_[1]=x*d+y*P+m[1],_}function b(R,m,C){let u=C??new e(2);return B(R,u),Q(u,m,u)}function w(R,m,C){let u=C??new e(2);return U(R)>m?b(R,m,u):G(R,u)}function z(R,m,C){let u=C??new e(2);return V(R,m,.5,u)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:f,add:h,addScaled:p,angle:g,subtract:D,sub:X,equalsApproximately:N,equals:I,lerp:V,lerpV:q,max:Y,min:K,mulScalar:Q,scale:tt,divScalar:H,inverse:W,invert:st,cross:et,dot:rt,length:U,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:L,distSq:O,normalize:B,negate:l,copy:G,clone:ot,multiply:at,mul:ut,divide:ft,div:yt,random:pt,zero:k,transformMat4:$,transformMat3:F,rotate:c,setLength:b,truncate:w,midpoint:z}}var Ti=new Map;function Ui(e){let t=Ti.get(e);return t||(t=Ks(e),Ti.set(e,t)),t}function Qs(e){function t(d,P,E){let A=new e(3);return d!==void 0&&(A[0]=d,P!==void 0&&(A[1]=P,E!==void 0&&(A[2]=E))),A}let n=t;function r(d,P,E,A){let Z=A??new e(3);return Z[0]=d,Z[1]=P,Z[2]=E,Z}function i(d,P){let E=P??new e(3);return E[0]=Math.ceil(d[0]),E[1]=Math.ceil(d[1]),E[2]=Math.ceil(d[2]),E}function o(d,P){let E=P??new e(3);return E[0]=Math.floor(d[0]),E[1]=Math.floor(d[1]),E[2]=Math.floor(d[2]),E}function s(d,P){let E=P??new e(3);return E[0]=Math.round(d[0]),E[1]=Math.round(d[1]),E[2]=Math.round(d[2]),E}function f(d,P=0,E=1,A){let Z=A??new e(3);return Z[0]=Math.min(E,Math.max(P,d[0])),Z[1]=Math.min(E,Math.max(P,d[1])),Z[2]=Math.min(E,Math.max(P,d[2])),Z}function h(d,P,E){let A=E??new e(3);return A[0]=d[0]+P[0],A[1]=d[1]+P[1],A[2]=d[2]+P[2],A}function p(d,P,E,A){let Z=A??new e(3);return Z[0]=d[0]+P[0]*E,Z[1]=d[1]+P[1]*E,Z[2]=d[2]+P[2]*E,Z}function g(d,P){let E=d[0],A=d[1],Z=d[2],J=P[0],j=P[1],ct=P[2],nt=Math.sqrt(E*E+A*A+Z*Z),it=Math.sqrt(J*J+j*j+ct*ct),vt=nt*it,ht=vt&&rt(d,P)/vt;return Math.acos(ht)}function D(d,P,E){let A=E??new e(3);return A[0]=d[0]-P[0],A[1]=d[1]-P[1],A[2]=d[2]-P[2],A}let X=D;function N(d,P){return Math.abs(d[0]-P[0])<Tt&&Math.abs(d[1]-P[1])<Tt&&Math.abs(d[2]-P[2])<Tt}function I(d,P){return d[0]===P[0]&&d[1]===P[1]&&d[2]===P[2]}function V(d,P,E,A){let Z=A??new e(3);return Z[0]=d[0]+E*(P[0]-d[0]),Z[1]=d[1]+E*(P[1]-d[1]),Z[2]=d[2]+E*(P[2]-d[2]),Z}function q(d,P,E,A){let Z=A??new e(3);return Z[0]=d[0]+E[0]*(P[0]-d[0]),Z[1]=d[1]+E[1]*(P[1]-d[1]),Z[2]=d[2]+E[2]*(P[2]-d[2]),Z}function Y(d,P,E){let A=E??new e(3);return A[0]=Math.max(d[0],P[0]),A[1]=Math.max(d[1],P[1]),A[2]=Math.max(d[2],P[2]),A}function K(d,P,E){let A=E??new e(3);return A[0]=Math.min(d[0],P[0]),A[1]=Math.min(d[1],P[1]),A[2]=Math.min(d[2],P[2]),A}function Q(d,P,E){let A=E??new e(3);return A[0]=d[0]*P,A[1]=d[1]*P,A[2]=d[2]*P,A}let tt=Q;function H(d,P,E){let A=E??new e(3);return A[0]=d[0]/P,A[1]=d[1]/P,A[2]=d[2]/P,A}function W(d,P){let E=P??new e(3);return E[0]=1/d[0],E[1]=1/d[1],E[2]=1/d[2],E}let st=W;function et(d,P,E){let A=E??new e(3),Z=d[2]*P[0]-d[0]*P[2],J=d[0]*P[1]-d[1]*P[0];return A[0]=d[1]*P[2]-d[2]*P[1],A[1]=Z,A[2]=J,A}function rt(d,P){return d[0]*P[0]+d[1]*P[1]+d[2]*P[2]}function U(d){let P=d[0],E=d[1],A=d[2];return Math.sqrt(P*P+E*E+A*A)}let a=U;function v(d){let P=d[0],E=d[1],A=d[2];return P*P+E*E+A*A}let T=v;function M(d,P){let E=d[0]-P[0],A=d[1]-P[1],Z=d[2]-P[2];return Math.sqrt(E*E+A*A+Z*Z)}let S=M;function L(d,P){let E=d[0]-P[0],A=d[1]-P[1],Z=d[2]-P[2];return E*E+A*A+Z*Z}let O=L;function B(d,P){let E=P??new e(3),A=d[0],Z=d[1],J=d[2],j=Math.sqrt(A*A+Z*Z+J*J);return j>1e-5?(E[0]=A/j,E[1]=Z/j,E[2]=J/j):(E[0]=0,E[1]=0,E[2]=0),E}function l(d,P){let E=P??new e(3);return E[0]=-d[0],E[1]=-d[1],E[2]=-d[2],E}function G(d,P){let E=P??new e(3);return E[0]=d[0],E[1]=d[1],E[2]=d[2],E}let ot=G;function at(d,P,E){let A=E??new e(3);return A[0]=d[0]*P[0],A[1]=d[1]*P[1],A[2]=d[2]*P[2],A}let ut=at;function ft(d,P,E){let A=E??new e(3);return A[0]=d[0]/P[0],A[1]=d[1]/P[1],A[2]=d[2]/P[2],A}let yt=ft;function pt(d=1,P){let E=P??new e(3),A=Math.random()*2*Math.PI,Z=Math.random()*2-1,J=Math.sqrt(1-Z*Z)*d;return E[0]=Math.cos(A)*J,E[1]=Math.sin(A)*J,E[2]=Z*d,E}function k(d){let P=d??new e(3);return P[0]=0,P[1]=0,P[2]=0,P}function $(d,P,E){let A=E??new e(3),Z=d[0],J=d[1],j=d[2],ct=P[3]*Z+P[7]*J+P[11]*j+P[15]||1;return A[0]=(P[0]*Z+P[4]*J+P[8]*j+P[12])/ct,A[1]=(P[1]*Z+P[5]*J+P[9]*j+P[13])/ct,A[2]=(P[2]*Z+P[6]*J+P[10]*j+P[14])/ct,A}function F(d,P,E){let A=E??new e(3),Z=d[0],J=d[1],j=d[2];return A[0]=Z*P[0]+J*P[4]+j*P[8],A[1]=Z*P[1]+J*P[5]+j*P[9],A[2]=Z*P[2]+J*P[6]+j*P[10],A}function c(d,P,E){let A=E??new e(3),Z=d[0],J=d[1],j=d[2];return A[0]=Z*P[0]+J*P[4]+j*P[8],A[1]=Z*P[1]+J*P[5]+j*P[9],A[2]=Z*P[2]+J*P[6]+j*P[10],A}function b(d,P,E){let A=E??new e(3),Z=P[0],J=P[1],j=P[2],ct=P[3]*2,nt=d[0],it=d[1],vt=d[2],ht=J*vt-j*it,lt=j*nt-Z*vt,dt=Z*it-J*nt;return A[0]=nt+ht*ct+(J*dt-j*lt)*2,A[1]=it+lt*ct+(j*ht-Z*dt)*2,A[2]=vt+dt*ct+(Z*lt-J*ht)*2,A}function w(d,P){let E=P??new e(3);return E[0]=d[12],E[1]=d[13],E[2]=d[14],E}function z(d,P,E){let A=E??new e(3),Z=P*4;return A[0]=d[Z+0],A[1]=d[Z+1],A[2]=d[Z+2],A}function R(d,P){let E=P??new e(3),A=d[0],Z=d[1],J=d[2],j=d[4],ct=d[5],nt=d[6],it=d[8],vt=d[9],ht=d[10];return E[0]=Math.sqrt(A*A+Z*Z+J*J),E[1]=Math.sqrt(j*j+ct*ct+nt*nt),E[2]=Math.sqrt(it*it+vt*vt+ht*ht),E}function m(d,P,E,A){let Z=A??new e(3),J=[],j=[];return J[0]=d[0]-P[0],J[1]=d[1]-P[1],J[2]=d[2]-P[2],j[0]=J[0],j[1]=J[1]*Math.cos(E)-J[2]*Math.sin(E),j[2]=J[1]*Math.sin(E)+J[2]*Math.cos(E),Z[0]=j[0]+P[0],Z[1]=j[1]+P[1],Z[2]=j[2]+P[2],Z}function C(d,P,E,A){let Z=A??new e(3),J=[],j=[];return J[0]=d[0]-P[0],J[1]=d[1]-P[1],J[2]=d[2]-P[2],j[0]=J[2]*Math.sin(E)+J[0]*Math.cos(E),j[1]=J[1],j[2]=J[2]*Math.cos(E)-J[0]*Math.sin(E),Z[0]=j[0]+P[0],Z[1]=j[1]+P[1],Z[2]=j[2]+P[2],Z}function u(d,P,E,A){let Z=A??new e(3),J=[],j=[];return J[0]=d[0]-P[0],J[1]=d[1]-P[1],J[2]=d[2]-P[2],j[0]=J[0]*Math.cos(E)-J[1]*Math.sin(E),j[1]=J[0]*Math.sin(E)+J[1]*Math.cos(E),j[2]=J[2],Z[0]=j[0]+P[0],Z[1]=j[1]+P[1],Z[2]=j[2]+P[2],Z}function _(d,P,E){let A=E??new e(3);return B(d,A),Q(A,P,A)}function x(d,P,E){let A=E??new e(3);return U(d)>P?_(d,P,A):G(d,A)}function y(d,P,E){let A=E??new e(3);return V(d,P,.5,A)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:f,add:h,addScaled:p,angle:g,subtract:D,sub:X,equalsApproximately:N,equals:I,lerp:V,lerpV:q,max:Y,min:K,mulScalar:Q,scale:tt,divScalar:H,inverse:W,invert:st,cross:et,dot:rt,length:U,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:L,distSq:O,normalize:B,negate:l,copy:G,clone:ot,multiply:at,mul:ut,divide:ft,div:yt,random:pt,zero:k,transformMat4:$,transformMat4Upper3x3:F,transformMat3:c,transformQuat:b,getTranslation:w,getAxis:z,getScaling:R,rotateX:m,rotateY:C,rotateZ:u,setLength:_,truncate:x,midpoint:y}}var Pi=new Map;function vr(e){let t=Pi.get(e);return t||(t=Qs(e),Pi.set(e,t)),t}function Js(e){let t=Ui(e),n=vr(e);function r(c,b,w,z,R,m,C,u,_){let x=new e(12);return x[3]=0,x[7]=0,x[11]=0,c!==void 0&&(x[0]=c,b!==void 0&&(x[1]=b,w!==void 0&&(x[2]=w,z!==void 0&&(x[4]=z,R!==void 0&&(x[5]=R,m!==void 0&&(x[6]=m,C!==void 0&&(x[8]=C,u!==void 0&&(x[9]=u,_!==void 0&&(x[10]=_))))))))),x}function i(c,b,w,z,R,m,C,u,_,x){let y=x??new e(12);return y[0]=c,y[1]=b,y[2]=w,y[3]=0,y[4]=z,y[5]=R,y[6]=m,y[7]=0,y[8]=C,y[9]=u,y[10]=_,y[11]=0,y}function o(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=c[1],w[2]=c[2],w[3]=0,w[4]=c[4],w[5]=c[5],w[6]=c[6],w[7]=0,w[8]=c[8],w[9]=c[9],w[10]=c[10],w[11]=0,w}function s(c,b){let w=b??new e(12),z=c[0],R=c[1],m=c[2],C=c[3],u=z+z,_=R+R,x=m+m,y=z*u,d=R*u,P=R*_,E=m*u,A=m*_,Z=m*x,J=C*u,j=C*_,ct=C*x;return w[0]=1-P-Z,w[1]=d+ct,w[2]=E-j,w[3]=0,w[4]=d-ct,w[5]=1-y-Z,w[6]=A+J,w[7]=0,w[8]=E+j,w[9]=A-J,w[10]=1-y-P,w[11]=0,w}function f(c,b){let w=b??new e(12);return w[0]=-c[0],w[1]=-c[1],w[2]=-c[2],w[4]=-c[4],w[5]=-c[5],w[6]=-c[6],w[8]=-c[8],w[9]=-c[9],w[10]=-c[10],w}function h(c,b,w){let z=w??new e(12);return z[0]=c[0]*b,z[1]=c[1]*b,z[2]=c[2]*b,z[4]=c[4]*b,z[5]=c[5]*b,z[6]=c[6]*b,z[8]=c[8]*b,z[9]=c[9]*b,z[10]=c[10]*b,z}let p=h;function g(c,b,w){let z=w??new e(12);return z[0]=c[0]+b[0],z[1]=c[1]+b[1],z[2]=c[2]+b[2],z[4]=c[4]+b[4],z[5]=c[5]+b[5],z[6]=c[6]+b[6],z[8]=c[8]+b[8],z[9]=c[9]+b[9],z[10]=c[10]+b[10],z}function D(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=c[1],w[2]=c[2],w[4]=c[4],w[5]=c[5],w[6]=c[6],w[8]=c[8],w[9]=c[9],w[10]=c[10],w}let X=D;function N(c,b){return Math.abs(c[0]-b[0])<Tt&&Math.abs(c[1]-b[1])<Tt&&Math.abs(c[2]-b[2])<Tt&&Math.abs(c[4]-b[4])<Tt&&Math.abs(c[5]-b[5])<Tt&&Math.abs(c[6]-b[6])<Tt&&Math.abs(c[8]-b[8])<Tt&&Math.abs(c[9]-b[9])<Tt&&Math.abs(c[10]-b[10])<Tt}function I(c,b){return c[0]===b[0]&&c[1]===b[1]&&c[2]===b[2]&&c[4]===b[4]&&c[5]===b[5]&&c[6]===b[6]&&c[8]===b[8]&&c[9]===b[9]&&c[10]===b[10]}function V(c){let b=c??new e(12);return b[0]=1,b[1]=0,b[2]=0,b[4]=0,b[5]=1,b[6]=0,b[8]=0,b[9]=0,b[10]=1,b}function q(c,b){let w=b??new e(12);if(w===c){let P;return P=c[1],c[1]=c[4],c[4]=P,P=c[2],c[2]=c[8],c[8]=P,P=c[6],c[6]=c[9],c[9]=P,w}let z=c[0],R=c[1],m=c[2],C=c[4],u=c[5],_=c[6],x=c[8],y=c[9],d=c[10];return w[0]=z,w[1]=C,w[2]=x,w[4]=R,w[5]=u,w[6]=y,w[8]=m,w[9]=_,w[10]=d,w}function Y(c,b){let w=b??new e(12),z=c[0],R=c[1],m=c[2],C=c[4],u=c[5],_=c[6],x=c[8],y=c[9],d=c[10],P=d*u-_*y,E=-d*C+_*x,A=y*C-u*x,Z=1/(z*P+R*E+m*A);return w[0]=P*Z,w[1]=(-d*R+m*y)*Z,w[2]=(_*R-m*u)*Z,w[4]=E*Z,w[5]=(d*z-m*x)*Z,w[6]=(-_*z+m*C)*Z,w[8]=A*Z,w[9]=(-y*z+R*x)*Z,w[10]=(u*z-R*C)*Z,w}function K(c){let b=c[0],w=c[1],z=c[2],R=c[4],m=c[5],C=c[6],u=c[8],_=c[9],x=c[10];return b*(m*x-_*C)-R*(w*x-_*z)+u*(w*C-m*z)}let Q=Y;function tt(c,b,w){let z=w??new e(12),R=c[0],m=c[1],C=c[2],u=c[4],_=c[5],x=c[6],y=c[8],d=c[9],P=c[10],E=b[0],A=b[1],Z=b[2],J=b[4],j=b[5],ct=b[6],nt=b[8],it=b[9],vt=b[10];return z[0]=R*E+u*A+y*Z,z[1]=m*E+_*A+d*Z,z[2]=C*E+x*A+P*Z,z[4]=R*J+u*j+y*ct,z[5]=m*J+_*j+d*ct,z[6]=C*J+x*j+P*ct,z[8]=R*nt+u*it+y*vt,z[9]=m*nt+_*it+d*vt,z[10]=C*nt+x*it+P*vt,z}let H=tt;function W(c,b,w){let z=w??V();return c!==z&&(z[0]=c[0],z[1]=c[1],z[2]=c[2],z[4]=c[4],z[5]=c[5],z[6]=c[6]),z[8]=b[0],z[9]=b[1],z[10]=1,z}function st(c,b){let w=b??t.create();return w[0]=c[8],w[1]=c[9],w}function et(c,b,w){let z=w??t.create(),R=b*4;return z[0]=c[R+0],z[1]=c[R+1],z}function rt(c,b,w,z){let R=z===c?c:D(c,z),m=w*4;return R[m+0]=b[0],R[m+1]=b[1],R}function U(c,b){let w=b??t.create(),z=c[0],R=c[1],m=c[4],C=c[5];return w[0]=Math.sqrt(z*z+R*R),w[1]=Math.sqrt(m*m+C*C),w}function a(c,b){let w=b??n.create(),z=c[0],R=c[1],m=c[2],C=c[4],u=c[5],_=c[6],x=c[8],y=c[9],d=c[10];return w[0]=Math.sqrt(z*z+R*R+m*m),w[1]=Math.sqrt(C*C+u*u+_*_),w[2]=Math.sqrt(x*x+y*y+d*d),w}function v(c,b){let w=b??new e(12);return w[0]=1,w[1]=0,w[2]=0,w[4]=0,w[5]=1,w[6]=0,w[8]=c[0],w[9]=c[1],w[10]=1,w}function T(c,b,w){let z=w??new e(12),R=b[0],m=b[1],C=c[0],u=c[1],_=c[2],x=c[4],y=c[5],d=c[6],P=c[8],E=c[9],A=c[10];return c!==z&&(z[0]=C,z[1]=u,z[2]=_,z[4]=x,z[5]=y,z[6]=d),z[8]=C*R+x*m+P,z[9]=u*R+y*m+E,z[10]=_*R+d*m+A,z}function M(c,b){let w=b??new e(12),z=Math.cos(c),R=Math.sin(c);return w[0]=z,w[1]=R,w[2]=0,w[4]=-R,w[5]=z,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function S(c,b,w){let z=w??new e(12),R=c[0],m=c[1],C=c[2],u=c[4],_=c[5],x=c[6],y=Math.cos(b),d=Math.sin(b);return z[0]=y*R+d*u,z[1]=y*m+d*_,z[2]=y*C+d*x,z[4]=y*u-d*R,z[5]=y*_-d*m,z[6]=y*x-d*C,c!==z&&(z[8]=c[8],z[9]=c[9],z[10]=c[10]),z}function L(c,b){let w=b??new e(12),z=Math.cos(c),R=Math.sin(c);return w[0]=1,w[1]=0,w[2]=0,w[4]=0,w[5]=z,w[6]=R,w[8]=0,w[9]=-R,w[10]=z,w}function O(c,b,w){let z=w??new e(12),R=c[4],m=c[5],C=c[6],u=c[8],_=c[9],x=c[10],y=Math.cos(b),d=Math.sin(b);return z[4]=y*R+d*u,z[5]=y*m+d*_,z[6]=y*C+d*x,z[8]=y*u-d*R,z[9]=y*_-d*m,z[10]=y*x-d*C,c!==z&&(z[0]=c[0],z[1]=c[1],z[2]=c[2]),z}function B(c,b){let w=b??new e(12),z=Math.cos(c),R=Math.sin(c);return w[0]=z,w[1]=0,w[2]=-R,w[4]=0,w[5]=1,w[6]=0,w[8]=R,w[9]=0,w[10]=z,w}function l(c,b,w){let z=w??new e(12),R=c[0],m=c[1],C=c[2],u=c[8],_=c[9],x=c[10],y=Math.cos(b),d=Math.sin(b);return z[0]=y*R-d*u,z[1]=y*m-d*_,z[2]=y*C-d*x,z[8]=y*u+d*R,z[9]=y*_+d*m,z[10]=y*x+d*C,c!==z&&(z[4]=c[4],z[5]=c[5],z[6]=c[6]),z}let G=M,ot=S;function at(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=0,w[2]=0,w[4]=0,w[5]=c[1],w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function ut(c,b,w){let z=w??new e(12),R=b[0],m=b[1];return z[0]=R*c[0],z[1]=R*c[1],z[2]=R*c[2],z[4]=m*c[4],z[5]=m*c[5],z[6]=m*c[6],c!==z&&(z[8]=c[8],z[9]=c[9],z[10]=c[10]),z}function ft(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=0,w[2]=0,w[4]=0,w[5]=c[1],w[6]=0,w[8]=0,w[9]=0,w[10]=c[2],w}function yt(c,b,w){let z=w??new e(12),R=b[0],m=b[1],C=b[2];return z[0]=R*c[0],z[1]=R*c[1],z[2]=R*c[2],z[4]=m*c[4],z[5]=m*c[5],z[6]=m*c[6],z[8]=C*c[8],z[9]=C*c[9],z[10]=C*c[10],z}function pt(c,b){let w=b??new e(12);return w[0]=c,w[1]=0,w[2]=0,w[4]=0,w[5]=c,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function k(c,b,w){let z=w??new e(12);return z[0]=b*c[0],z[1]=b*c[1],z[2]=b*c[2],z[4]=b*c[4],z[5]=b*c[5],z[6]=b*c[6],c!==z&&(z[8]=c[8],z[9]=c[9],z[10]=c[10]),z}function $(c,b){let w=b??new e(12);return w[0]=c,w[1]=0,w[2]=0,w[4]=0,w[5]=c,w[6]=0,w[8]=0,w[9]=0,w[10]=c,w}function F(c,b,w){let z=w??new e(12);return z[0]=b*c[0],z[1]=b*c[1],z[2]=b*c[2],z[4]=b*c[4],z[5]=b*c[5],z[6]=b*c[6],z[8]=b*c[8],z[9]=b*c[9],z[10]=b*c[10],z}return{add:g,clone:X,copy:D,create:r,determinant:K,equals:I,equalsApproximately:N,fromMat4:o,fromQuat:s,get3DScaling:a,getAxis:et,getScaling:U,getTranslation:st,identity:V,inverse:Y,invert:Q,mul:H,mulScalar:p,multiply:tt,multiplyScalar:h,negate:f,rotate:S,rotateX:O,rotateY:l,rotateZ:ot,rotation:M,rotationX:L,rotationY:B,rotationZ:G,scale:ut,scale3D:yt,scaling:at,scaling3D:ft,set:i,setAxis:rt,setTranslation:W,translate:T,translation:v,transpose:q,uniformScale:k,uniformScale3D:F,uniformScaling:pt,uniformScaling3D:$}}var Si=new Map;function js(e){let t=Si.get(e);return t||(t=Js(e),Si.set(e,t)),t}function tu(e){let t=vr(e);function n(u,_,x,y,d,P,E,A,Z,J,j,ct,nt,it,vt,ht){let lt=new e(16);return u!==void 0&&(lt[0]=u,_!==void 0&&(lt[1]=_,x!==void 0&&(lt[2]=x,y!==void 0&&(lt[3]=y,d!==void 0&&(lt[4]=d,P!==void 0&&(lt[5]=P,E!==void 0&&(lt[6]=E,A!==void 0&&(lt[7]=A,Z!==void 0&&(lt[8]=Z,J!==void 0&&(lt[9]=J,j!==void 0&&(lt[10]=j,ct!==void 0&&(lt[11]=ct,nt!==void 0&&(lt[12]=nt,it!==void 0&&(lt[13]=it,vt!==void 0&&(lt[14]=vt,ht!==void 0&&(lt[15]=ht)))))))))))))))),lt}function r(u,_,x,y,d,P,E,A,Z,J,j,ct,nt,it,vt,ht,lt){let dt=lt??new e(16);return dt[0]=u,dt[1]=_,dt[2]=x,dt[3]=y,dt[4]=d,dt[5]=P,dt[6]=E,dt[7]=A,dt[8]=Z,dt[9]=J,dt[10]=j,dt[11]=ct,dt[12]=nt,dt[13]=it,dt[14]=vt,dt[15]=ht,dt}function i(u,_){let x=_??new e(16);return x[0]=u[0],x[1]=u[1],x[2]=u[2],x[3]=0,x[4]=u[4],x[5]=u[5],x[6]=u[6],x[7]=0,x[8]=u[8],x[9]=u[9],x[10]=u[10],x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function o(u,_){let x=_??new e(16),y=u[0],d=u[1],P=u[2],E=u[3],A=y+y,Z=d+d,J=P+P,j=y*A,ct=d*A,nt=d*Z,it=P*A,vt=P*Z,ht=P*J,lt=E*A,dt=E*Z,wt=E*J;return x[0]=1-nt-ht,x[1]=ct+wt,x[2]=it-dt,x[3]=0,x[4]=ct-wt,x[5]=1-j-ht,x[6]=vt+lt,x[7]=0,x[8]=it+dt,x[9]=vt-lt,x[10]=1-j-nt,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function s(u,_){let x=_??new e(16);return x[0]=-u[0],x[1]=-u[1],x[2]=-u[2],x[3]=-u[3],x[4]=-u[4],x[5]=-u[5],x[6]=-u[6],x[7]=-u[7],x[8]=-u[8],x[9]=-u[9],x[10]=-u[10],x[11]=-u[11],x[12]=-u[12],x[13]=-u[13],x[14]=-u[14],x[15]=-u[15],x}function f(u,_,x){let y=x??new e(16);return y[0]=u[0]+_[0],y[1]=u[1]+_[1],y[2]=u[2]+_[2],y[3]=u[3]+_[3],y[4]=u[4]+_[4],y[5]=u[5]+_[5],y[6]=u[6]+_[6],y[7]=u[7]+_[7],y[8]=u[8]+_[8],y[9]=u[9]+_[9],y[10]=u[10]+_[10],y[11]=u[11]+_[11],y[12]=u[12]+_[12],y[13]=u[13]+_[13],y[14]=u[14]+_[14],y[15]=u[15]+_[15],y}function h(u,_,x){let y=x??new e(16);return y[0]=u[0]*_,y[1]=u[1]*_,y[2]=u[2]*_,y[3]=u[3]*_,y[4]=u[4]*_,y[5]=u[5]*_,y[6]=u[6]*_,y[7]=u[7]*_,y[8]=u[8]*_,y[9]=u[9]*_,y[10]=u[10]*_,y[11]=u[11]*_,y[12]=u[12]*_,y[13]=u[13]*_,y[14]=u[14]*_,y[15]=u[15]*_,y}let p=h;function g(u,_){let x=_??new e(16);return x[0]=u[0],x[1]=u[1],x[2]=u[2],x[3]=u[3],x[4]=u[4],x[5]=u[5],x[6]=u[6],x[7]=u[7],x[8]=u[8],x[9]=u[9],x[10]=u[10],x[11]=u[11],x[12]=u[12],x[13]=u[13],x[14]=u[14],x[15]=u[15],x}let D=g;function X(u,_){return Math.abs(u[0]-_[0])<Tt&&Math.abs(u[1]-_[1])<Tt&&Math.abs(u[2]-_[2])<Tt&&Math.abs(u[3]-_[3])<Tt&&Math.abs(u[4]-_[4])<Tt&&Math.abs(u[5]-_[5])<Tt&&Math.abs(u[6]-_[6])<Tt&&Math.abs(u[7]-_[7])<Tt&&Math.abs(u[8]-_[8])<Tt&&Math.abs(u[9]-_[9])<Tt&&Math.abs(u[10]-_[10])<Tt&&Math.abs(u[11]-_[11])<Tt&&Math.abs(u[12]-_[12])<Tt&&Math.abs(u[13]-_[13])<Tt&&Math.abs(u[14]-_[14])<Tt&&Math.abs(u[15]-_[15])<Tt}function N(u,_){return u[0]===_[0]&&u[1]===_[1]&&u[2]===_[2]&&u[3]===_[3]&&u[4]===_[4]&&u[5]===_[5]&&u[6]===_[6]&&u[7]===_[7]&&u[8]===_[8]&&u[9]===_[9]&&u[10]===_[10]&&u[11]===_[11]&&u[12]===_[12]&&u[13]===_[13]&&u[14]===_[14]&&u[15]===_[15]}function I(u){let _=u??new e(16);return _[0]=1,_[1]=0,_[2]=0,_[3]=0,_[4]=0,_[5]=1,_[6]=0,_[7]=0,_[8]=0,_[9]=0,_[10]=1,_[11]=0,_[12]=0,_[13]=0,_[14]=0,_[15]=1,_}function V(u,_){let x=_??new e(16);if(x===u){let gt;return gt=u[1],u[1]=u[4],u[4]=gt,gt=u[2],u[2]=u[8],u[8]=gt,gt=u[3],u[3]=u[12],u[12]=gt,gt=u[6],u[6]=u[9],u[9]=gt,gt=u[7],u[7]=u[13],u[13]=gt,gt=u[11],u[11]=u[14],u[14]=gt,x}let y=u[0],d=u[1],P=u[2],E=u[3],A=u[4],Z=u[5],J=u[6],j=u[7],ct=u[8],nt=u[9],it=u[10],vt=u[11],ht=u[12],lt=u[13],dt=u[14],wt=u[15];return x[0]=y,x[1]=A,x[2]=ct,x[3]=ht,x[4]=d,x[5]=Z,x[6]=nt,x[7]=lt,x[8]=P,x[9]=J,x[10]=it,x[11]=dt,x[12]=E,x[13]=j,x[14]=vt,x[15]=wt,x}function q(u,_){let x=_??new e(16),y=u[0],d=u[1],P=u[2],E=u[3],A=u[4],Z=u[5],J=u[6],j=u[7],ct=u[8],nt=u[9],it=u[10],vt=u[11],ht=u[12],lt=u[13],dt=u[14],wt=u[15],gt=it*wt,Ct=dt*vt,Mt=J*wt,bt=dt*j,Ht=J*vt,St=it*j,_t=P*wt,$t=dt*E,Bt=P*vt,Dt=it*E,Wt=P*j,Ut=J*E,Ft=ct*lt,Kt=ht*nt,Gt=A*lt,At=ht*Z,jt=A*nt,Rt=ct*Z,It=y*lt,Se=ht*d,Ot=y*nt,mt=ct*d,_e=y*Z,Vt=A*d,Nt=gt*Z+bt*nt+Ht*lt-(Ct*Z+Mt*nt+St*lt),me=Ct*d+_t*nt+Dt*lt-(gt*d+$t*nt+Bt*lt),Ve=Mt*d+$t*Z+Wt*lt-(bt*d+_t*Z+Ut*lt),qe=St*d+Bt*Z+Ut*nt-(Ht*d+Dt*Z+Wt*nt),Zt=1/(y*Nt+A*me+ct*Ve+ht*qe);return x[0]=Zt*Nt,x[1]=Zt*me,x[2]=Zt*Ve,x[3]=Zt*qe,x[4]=Zt*(Ct*A+Mt*ct+St*ht-(gt*A+bt*ct+Ht*ht)),x[5]=Zt*(gt*y+$t*ct+Bt*ht-(Ct*y+_t*ct+Dt*ht)),x[6]=Zt*(bt*y+_t*A+Ut*ht-(Mt*y+$t*A+Wt*ht)),x[7]=Zt*(Ht*y+Dt*A+Wt*ct-(St*y+Bt*A+Ut*ct)),x[8]=Zt*(Ft*j+At*vt+jt*wt-(Kt*j+Gt*vt+Rt*wt)),x[9]=Zt*(Kt*E+It*vt+mt*wt-(Ft*E+Se*vt+Ot*wt)),x[10]=Zt*(Gt*E+Se*j+_e*wt-(At*E+It*j+Vt*wt)),x[11]=Zt*(Rt*E+Ot*j+Vt*vt-(jt*E+mt*j+_e*vt)),x[12]=Zt*(Gt*it+Rt*dt+Kt*J-(jt*dt+Ft*J+At*it)),x[13]=Zt*(Ot*dt+Ft*P+Se*it-(It*it+mt*dt+Kt*P)),x[14]=Zt*(It*J+Vt*dt+At*P-(_e*dt+Gt*P+Se*J)),x[15]=Zt*(_e*it+jt*P+mt*J-(Ot*J+Vt*it+Rt*P)),x}function Y(u){let _=u[0],x=u[1],y=u[2],d=u[3],P=u[4],E=u[5],A=u[6],Z=u[7],J=u[8],j=u[9],ct=u[10],nt=u[11],it=u[12],vt=u[13],ht=u[14],lt=u[15],dt=ct*lt,wt=ht*nt,gt=A*lt,Ct=ht*Z,Mt=A*nt,bt=ct*Z,Ht=y*lt,St=ht*d,_t=y*nt,$t=ct*d,Bt=y*Z,Dt=A*d,Wt=dt*E+Ct*j+Mt*vt-(wt*E+gt*j+bt*vt),Ut=wt*x+Ht*j+$t*vt-(dt*x+St*j+_t*vt),Ft=gt*x+St*E+Bt*vt-(Ct*x+Ht*E+Dt*vt),Kt=bt*x+_t*E+Dt*j-(Mt*x+$t*E+Bt*j);return _*Wt+P*Ut+J*Ft+it*Kt}let K=q;function Q(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=u[3],Z=u[4],J=u[5],j=u[6],ct=u[7],nt=u[8],it=u[9],vt=u[10],ht=u[11],lt=u[12],dt=u[13],wt=u[14],gt=u[15],Ct=_[0],Mt=_[1],bt=_[2],Ht=_[3],St=_[4],_t=_[5],$t=_[6],Bt=_[7],Dt=_[8],Wt=_[9],Ut=_[10],Ft=_[11],Kt=_[12],Gt=_[13],At=_[14],jt=_[15];return y[0]=d*Ct+Z*Mt+nt*bt+lt*Ht,y[1]=P*Ct+J*Mt+it*bt+dt*Ht,y[2]=E*Ct+j*Mt+vt*bt+wt*Ht,y[3]=A*Ct+ct*Mt+ht*bt+gt*Ht,y[4]=d*St+Z*_t+nt*$t+lt*Bt,y[5]=P*St+J*_t+it*$t+dt*Bt,y[6]=E*St+j*_t+vt*$t+wt*Bt,y[7]=A*St+ct*_t+ht*$t+gt*Bt,y[8]=d*Dt+Z*Wt+nt*Ut+lt*Ft,y[9]=P*Dt+J*Wt+it*Ut+dt*Ft,y[10]=E*Dt+j*Wt+vt*Ut+wt*Ft,y[11]=A*Dt+ct*Wt+ht*Ut+gt*Ft,y[12]=d*Kt+Z*Gt+nt*At+lt*jt,y[13]=P*Kt+J*Gt+it*At+dt*jt,y[14]=E*Kt+j*Gt+vt*At+wt*jt,y[15]=A*Kt+ct*Gt+ht*At+gt*jt,y}let tt=Q;function H(u,_,x){let y=x??I();return u!==y&&(y[0]=u[0],y[1]=u[1],y[2]=u[2],y[3]=u[3],y[4]=u[4],y[5]=u[5],y[6]=u[6],y[7]=u[7],y[8]=u[8],y[9]=u[9],y[10]=u[10],y[11]=u[11]),y[12]=_[0],y[13]=_[1],y[14]=_[2],y[15]=1,y}function W(u,_){let x=_??t.create();return x[0]=u[12],x[1]=u[13],x[2]=u[14],x}function st(u,_,x){let y=x??t.create(),d=_*4;return y[0]=u[d+0],y[1]=u[d+1],y[2]=u[d+2],y}function et(u,_,x,y){let d=y===u?y:g(u,y),P=x*4;return d[P+0]=_[0],d[P+1]=_[1],d[P+2]=_[2],d}function rt(u,_){let x=_??t.create(),y=u[0],d=u[1],P=u[2],E=u[4],A=u[5],Z=u[6],J=u[8],j=u[9],ct=u[10];return x[0]=Math.sqrt(y*y+d*d+P*P),x[1]=Math.sqrt(E*E+A*A+Z*Z),x[2]=Math.sqrt(J*J+j*j+ct*ct),x}function U(u,_,x,y,d){let P=d??new e(16),E=Math.tan(Math.PI*.5-.5*u);if(P[0]=E/_,P[1]=0,P[2]=0,P[3]=0,P[4]=0,P[5]=E,P[6]=0,P[7]=0,P[8]=0,P[9]=0,P[11]=-1,P[12]=0,P[13]=0,P[15]=0,Number.isFinite(y)){let A=1/(x-y);P[10]=y*A,P[14]=y*x*A}else P[10]=-1,P[14]=-x;return P}function a(u,_,x,y=1/0,d){let P=d??new e(16),E=1/Math.tan(u*.5);if(P[0]=E/_,P[1]=0,P[2]=0,P[3]=0,P[4]=0,P[5]=E,P[6]=0,P[7]=0,P[8]=0,P[9]=0,P[11]=-1,P[12]=0,P[13]=0,P[15]=0,y===1/0)P[10]=0,P[14]=x;else{let A=1/(y-x);P[10]=x*A,P[14]=y*x*A}return P}function v(u,_,x,y,d,P,E){let A=E??new e(16);return A[0]=2/(_-u),A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2/(y-x),A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1/(d-P),A[11]=0,A[12]=(_+u)/(u-_),A[13]=(y+x)/(x-y),A[14]=d/(d-P),A[15]=1,A}function T(u,_,x,y,d,P,E){let A=E??new e(16),Z=_-u,J=y-x,j=d-P;return A[0]=2*d/Z,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/J,A[6]=0,A[7]=0,A[8]=(u+_)/Z,A[9]=(y+x)/J,A[10]=P/j,A[11]=-1,A[12]=0,A[13]=0,A[14]=d*P/j,A[15]=0,A}function M(u,_,x,y,d,P=1/0,E){let A=E??new e(16),Z=_-u,J=y-x;if(A[0]=2*d/Z,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/J,A[6]=0,A[7]=0,A[8]=(u+_)/Z,A[9]=(y+x)/J,A[11]=-1,A[12]=0,A[13]=0,A[15]=0,P===1/0)A[10]=0,A[14]=d;else{let j=1/(P-d);A[10]=d*j,A[14]=P*d*j}return A}let S=t.create(),L=t.create(),O=t.create();function B(u,_,x,y){let d=y??new e(16);return t.normalize(t.subtract(_,u,O),O),t.normalize(t.cross(x,O,S),S),t.normalize(t.cross(O,S,L),L),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=L[0],d[5]=L[1],d[6]=L[2],d[7]=0,d[8]=O[0],d[9]=O[1],d[10]=O[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function l(u,_,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,_,O),O),t.normalize(t.cross(x,O,S),S),t.normalize(t.cross(O,S,L),L),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=L[0],d[5]=L[1],d[6]=L[2],d[7]=0,d[8]=O[0],d[9]=O[1],d[10]=O[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function G(u,_,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,_,O),O),t.normalize(t.cross(x,O,S),S),t.normalize(t.cross(O,S,L),L),d[0]=S[0],d[1]=L[0],d[2]=O[0],d[3]=0,d[4]=S[1],d[5]=L[1],d[6]=O[1],d[7]=0,d[8]=S[2],d[9]=L[2],d[10]=O[2],d[11]=0,d[12]=-(S[0]*u[0]+S[1]*u[1]+S[2]*u[2]),d[13]=-(L[0]*u[0]+L[1]*u[1]+L[2]*u[2]),d[14]=-(O[0]*u[0]+O[1]*u[1]+O[2]*u[2]),d[15]=1,d}function ot(u,_){let x=_??new e(16);return x[0]=1,x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=1,x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=1,x[11]=0,x[12]=u[0],x[13]=u[1],x[14]=u[2],x[15]=1,x}function at(u,_,x){let y=x??new e(16),d=_[0],P=_[1],E=_[2],A=u[0],Z=u[1],J=u[2],j=u[3],ct=u[4],nt=u[5],it=u[6],vt=u[7],ht=u[8],lt=u[9],dt=u[10],wt=u[11],gt=u[12],Ct=u[13],Mt=u[14],bt=u[15];return u!==y&&(y[0]=A,y[1]=Z,y[2]=J,y[3]=j,y[4]=ct,y[5]=nt,y[6]=it,y[7]=vt,y[8]=ht,y[9]=lt,y[10]=dt,y[11]=wt),y[12]=A*d+ct*P+ht*E+gt,y[13]=Z*d+nt*P+lt*E+Ct,y[14]=J*d+it*P+dt*E+Mt,y[15]=j*d+vt*P+wt*E+bt,y}function ut(u,_){let x=_??new e(16),y=Math.cos(u),d=Math.sin(u);return x[0]=1,x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=y,x[6]=d,x[7]=0,x[8]=0,x[9]=-d,x[10]=y,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function ft(u,_,x){let y=x??new e(16),d=u[4],P=u[5],E=u[6],A=u[7],Z=u[8],J=u[9],j=u[10],ct=u[11],nt=Math.cos(_),it=Math.sin(_);return y[4]=nt*d+it*Z,y[5]=nt*P+it*J,y[6]=nt*E+it*j,y[7]=nt*A+it*ct,y[8]=nt*Z-it*d,y[9]=nt*J-it*P,y[10]=nt*j-it*E,y[11]=nt*ct-it*A,u!==y&&(y[0]=u[0],y[1]=u[1],y[2]=u[2],y[3]=u[3],y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function yt(u,_){let x=_??new e(16),y=Math.cos(u),d=Math.sin(u);return x[0]=y,x[1]=0,x[2]=-d,x[3]=0,x[4]=0,x[5]=1,x[6]=0,x[7]=0,x[8]=d,x[9]=0,x[10]=y,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function pt(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=u[3],Z=u[8],J=u[9],j=u[10],ct=u[11],nt=Math.cos(_),it=Math.sin(_);return y[0]=nt*d-it*Z,y[1]=nt*P-it*J,y[2]=nt*E-it*j,y[3]=nt*A-it*ct,y[8]=nt*Z+it*d,y[9]=nt*J+it*P,y[10]=nt*j+it*E,y[11]=nt*ct+it*A,u!==y&&(y[4]=u[4],y[5]=u[5],y[6]=u[6],y[7]=u[7],y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function k(u,_){let x=_??new e(16),y=Math.cos(u),d=Math.sin(u);return x[0]=y,x[1]=d,x[2]=0,x[3]=0,x[4]=-d,x[5]=y,x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=1,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function $(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=u[3],Z=u[4],J=u[5],j=u[6],ct=u[7],nt=Math.cos(_),it=Math.sin(_);return y[0]=nt*d+it*Z,y[1]=nt*P+it*J,y[2]=nt*E+it*j,y[3]=nt*A+it*ct,y[4]=nt*Z-it*d,y[5]=nt*J-it*P,y[6]=nt*j-it*E,y[7]=nt*ct-it*A,u!==y&&(y[8]=u[8],y[9]=u[9],y[10]=u[10],y[11]=u[11],y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function F(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=Math.sqrt(d*d+P*P+E*E);d/=A,P/=A,E/=A;let Z=d*d,J=P*P,j=E*E,ct=Math.cos(_),nt=Math.sin(_),it=1-ct;return y[0]=Z+(1-Z)*ct,y[1]=d*P*it+E*nt,y[2]=d*E*it-P*nt,y[3]=0,y[4]=d*P*it-E*nt,y[5]=J+(1-J)*ct,y[6]=P*E*it+d*nt,y[7]=0,y[8]=d*E*it+P*nt,y[9]=P*E*it-d*nt,y[10]=j+(1-j)*ct,y[11]=0,y[12]=0,y[13]=0,y[14]=0,y[15]=1,y}let c=F;function b(u,_,x,y){let d=y??new e(16),P=_[0],E=_[1],A=_[2],Z=Math.sqrt(P*P+E*E+A*A);P/=Z,E/=Z,A/=Z;let J=P*P,j=E*E,ct=A*A,nt=Math.cos(x),it=Math.sin(x),vt=1-nt,ht=J+(1-J)*nt,lt=P*E*vt+A*it,dt=P*A*vt-E*it,wt=P*E*vt-A*it,gt=j+(1-j)*nt,Ct=E*A*vt+P*it,Mt=P*A*vt+E*it,bt=E*A*vt-P*it,Ht=ct+(1-ct)*nt,St=u[0],_t=u[1],$t=u[2],Bt=u[3],Dt=u[4],Wt=u[5],Ut=u[6],Ft=u[7],Kt=u[8],Gt=u[9],At=u[10],jt=u[11];return d[0]=ht*St+lt*Dt+dt*Kt,d[1]=ht*_t+lt*Wt+dt*Gt,d[2]=ht*$t+lt*Ut+dt*At,d[3]=ht*Bt+lt*Ft+dt*jt,d[4]=wt*St+gt*Dt+Ct*Kt,d[5]=wt*_t+gt*Wt+Ct*Gt,d[6]=wt*$t+gt*Ut+Ct*At,d[7]=wt*Bt+gt*Ft+Ct*jt,d[8]=Mt*St+bt*Dt+Ht*Kt,d[9]=Mt*_t+bt*Wt+Ht*Gt,d[10]=Mt*$t+bt*Ut+Ht*At,d[11]=Mt*Bt+bt*Ft+Ht*jt,u!==d&&(d[12]=u[12],d[13]=u[13],d[14]=u[14],d[15]=u[15]),d}let w=b;function z(u,_){let x=_??new e(16);return x[0]=u[0],x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=u[1],x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=u[2],x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function R(u,_,x){let y=x??new e(16),d=_[0],P=_[1],E=_[2];return y[0]=d*u[0],y[1]=d*u[1],y[2]=d*u[2],y[3]=d*u[3],y[4]=P*u[4],y[5]=P*u[5],y[6]=P*u[6],y[7]=P*u[7],y[8]=E*u[8],y[9]=E*u[9],y[10]=E*u[10],y[11]=E*u[11],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function m(u,_){let x=_??new e(16);return x[0]=u,x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=u,x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=u,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function C(u,_,x){let y=x??new e(16);return y[0]=_*u[0],y[1]=_*u[1],y[2]=_*u[2],y[3]=_*u[3],y[4]=_*u[4],y[5]=_*u[5],y[6]=_*u[6],y[7]=_*u[7],y[8]=_*u[8],y[9]=_*u[9],y[10]=_*u[10],y[11]=_*u[11],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}return{add:f,aim:B,axisRotate:b,axisRotation:F,cameraAim:l,clone:D,copy:g,create:n,determinant:Y,equals:N,equalsApproximately:X,fromMat3:i,fromQuat:o,frustum:T,frustumReverseZ:M,getAxis:st,getScaling:rt,getTranslation:W,identity:I,inverse:q,invert:K,lookAt:G,mul:tt,mulScalar:p,multiply:Q,multiplyScalar:h,negate:s,ortho:v,perspective:U,perspectiveReverseZ:a,rotate:w,rotateX:ft,rotateY:pt,rotateZ:$,rotation:c,rotationX:ut,rotationY:yt,rotationZ:k,scale:R,scaling:z,set:r,setAxis:et,setTranslation:H,translate:at,translation:ot,transpose:V,uniformScale:C,uniformScaling:m}}var _i=new Map;function eu(e){let t=_i.get(e);return t||(t=tu(e),_i.set(e,t)),t}function ru(e){let t=vr(e);function n(k,$,F,c){let b=new e(4);return k!==void 0&&(b[0]=k,$!==void 0&&(b[1]=$,F!==void 0&&(b[2]=F,c!==void 0&&(b[3]=c)))),b}let r=n;function i(k,$,F,c,b){let w=b??new e(4);return w[0]=k,w[1]=$,w[2]=F,w[3]=c,w}function o(k,$,F){let c=F??new e(4),b=$*.5,w=Math.sin(b);return c[0]=w*k[0],c[1]=w*k[1],c[2]=w*k[2],c[3]=Math.cos(b),c}function s(k,$){let F=$??t.create(3),c=Math.acos(k[3])*2,b=Math.sin(c*.5);return b>Tt?(F[0]=k[0]/b,F[1]=k[1]/b,F[2]=k[2]/b):(F[0]=1,F[1]=0,F[2]=0),{angle:c,axis:F}}function f(k,$){let F=U(k,$);return Math.acos(2*F*F-1)}function h(k,$,F){let c=F??new e(4),b=k[0],w=k[1],z=k[2],R=k[3],m=$[0],C=$[1],u=$[2],_=$[3];return c[0]=b*_+R*m+w*u-z*C,c[1]=w*_+R*C+z*m-b*u,c[2]=z*_+R*u+b*C-w*m,c[3]=R*_-b*m-w*C-z*u,c}let p=h;function g(k,$,F){let c=F??new e(4),b=$*.5,w=k[0],z=k[1],R=k[2],m=k[3],C=Math.sin(b),u=Math.cos(b);return c[0]=w*u+m*C,c[1]=z*u+R*C,c[2]=R*u-z*C,c[3]=m*u-w*C,c}function D(k,$,F){let c=F??new e(4),b=$*.5,w=k[0],z=k[1],R=k[2],m=k[3],C=Math.sin(b),u=Math.cos(b);return c[0]=w*u-R*C,c[1]=z*u+m*C,c[2]=R*u+w*C,c[3]=m*u-z*C,c}function X(k,$,F){let c=F??new e(4),b=$*.5,w=k[0],z=k[1],R=k[2],m=k[3],C=Math.sin(b),u=Math.cos(b);return c[0]=w*u+z*C,c[1]=z*u-w*C,c[2]=R*u+m*C,c[3]=m*u-R*C,c}function N(k,$,F,c){let b=c??new e(4),w=k[0],z=k[1],R=k[2],m=k[3],C=$[0],u=$[1],_=$[2],x=$[3],y=w*C+z*u+R*_+m*x;y<0&&(y=-y,C=-C,u=-u,_=-_,x=-x);let d,P;if(1-y>Tt){let E=Math.acos(y),A=Math.sin(E);d=Math.sin((1-F)*E)/A,P=Math.sin(F*E)/A}else d=1-F,P=F;return b[0]=d*w+P*C,b[1]=d*z+P*u,b[2]=d*R+P*_,b[3]=d*m+P*x,b}function I(k,$){let F=$??new e(4),c=k[0],b=k[1],w=k[2],z=k[3],R=c*c+b*b+w*w+z*z,m=R?1/R:0;return F[0]=-c*m,F[1]=-b*m,F[2]=-w*m,F[3]=z*m,F}function V(k,$){let F=$??new e(4);return F[0]=-k[0],F[1]=-k[1],F[2]=-k[2],F[3]=k[3],F}function q(k,$){let F=$??new e(4),c=k[0]+k[5]+k[10];if(c>0){let b=Math.sqrt(c+1);F[3]=.5*b;let w=.5/b;F[0]=(k[6]-k[9])*w,F[1]=(k[8]-k[2])*w,F[2]=(k[1]-k[4])*w}else{let b=0;k[5]>k[0]&&(b=1),k[10]>k[b*4+b]&&(b=2);let w=(b+1)%3,z=(b+2)%3,R=Math.sqrt(k[b*4+b]-k[w*4+w]-k[z*4+z]+1);F[b]=.5*R;let m=.5/R;F[3]=(k[w*4+z]-k[z*4+w])*m,F[w]=(k[w*4+b]+k[b*4+w])*m,F[z]=(k[z*4+b]+k[b*4+z])*m}return F}function Y(k,$,F,c,b){let w=b??new e(4),z=k*.5,R=$*.5,m=F*.5,C=Math.sin(z),u=Math.cos(z),_=Math.sin(R),x=Math.cos(R),y=Math.sin(m),d=Math.cos(m);switch(c){case"xyz":w[0]=C*x*d+u*_*y,w[1]=u*_*d-C*x*y,w[2]=u*x*y+C*_*d,w[3]=u*x*d-C*_*y;break;case"xzy":w[0]=C*x*d-u*_*y,w[1]=u*_*d-C*x*y,w[2]=u*x*y+C*_*d,w[3]=u*x*d+C*_*y;break;case"yxz":w[0]=C*x*d+u*_*y,w[1]=u*_*d-C*x*y,w[2]=u*x*y-C*_*d,w[3]=u*x*d+C*_*y;break;case"yzx":w[0]=C*x*d+u*_*y,w[1]=u*_*d+C*x*y,w[2]=u*x*y-C*_*d,w[3]=u*x*d-C*_*y;break;case"zxy":w[0]=C*x*d-u*_*y,w[1]=u*_*d+C*x*y,w[2]=u*x*y+C*_*d,w[3]=u*x*d-C*_*y;break;case"zyx":w[0]=C*x*d-u*_*y,w[1]=u*_*d+C*x*y,w[2]=u*x*y-C*_*d,w[3]=u*x*d+C*_*y;break;default:throw new Error(`Unknown rotation order: ${c}`)}return w}function K(k,$){let F=$??new e(4);return F[0]=k[0],F[1]=k[1],F[2]=k[2],F[3]=k[3],F}let Q=K;function tt(k,$,F){let c=F??new e(4);return c[0]=k[0]+$[0],c[1]=k[1]+$[1],c[2]=k[2]+$[2],c[3]=k[3]+$[3],c}function H(k,$,F){let c=F??new e(4);return c[0]=k[0]-$[0],c[1]=k[1]-$[1],c[2]=k[2]-$[2],c[3]=k[3]-$[3],c}let W=H;function st(k,$,F){let c=F??new e(4);return c[0]=k[0]*$,c[1]=k[1]*$,c[2]=k[2]*$,c[3]=k[3]*$,c}let et=st;function rt(k,$,F){let c=F??new e(4);return c[0]=k[0]/$,c[1]=k[1]/$,c[2]=k[2]/$,c[3]=k[3]/$,c}function U(k,$){return k[0]*$[0]+k[1]*$[1]+k[2]*$[2]+k[3]*$[3]}function a(k,$,F,c){let b=c??new e(4);return b[0]=k[0]+F*($[0]-k[0]),b[1]=k[1]+F*($[1]-k[1]),b[2]=k[2]+F*($[2]-k[2]),b[3]=k[3]+F*($[3]-k[3]),b}function v(k){let $=k[0],F=k[1],c=k[2],b=k[3];return Math.sqrt($*$+F*F+c*c+b*b)}let T=v;function M(k){let $=k[0],F=k[1],c=k[2],b=k[3];return $*$+F*F+c*c+b*b}let S=M;function L(k,$){let F=$??new e(4),c=k[0],b=k[1],w=k[2],z=k[3],R=Math.sqrt(c*c+b*b+w*w+z*z);return R>1e-5?(F[0]=c/R,F[1]=b/R,F[2]=w/R,F[3]=z/R):(F[0]=0,F[1]=0,F[2]=0,F[3]=1),F}function O(k,$){return Math.abs(k[0]-$[0])<Tt&&Math.abs(k[1]-$[1])<Tt&&Math.abs(k[2]-$[2])<Tt&&Math.abs(k[3]-$[3])<Tt}function B(k,$){return k[0]===$[0]&&k[1]===$[1]&&k[2]===$[2]&&k[3]===$[3]}function l(k){let $=k??new e(4);return $[0]=0,$[1]=0,$[2]=0,$[3]=1,$}let G=t.create(),ot=t.create(),at=t.create();function ut(k,$,F){let c=F??new e(4),b=t.dot(k,$);return b<-.999999?(t.cross(ot,k,G),t.len(G)<1e-6&&t.cross(at,k,G),t.normalize(G,G),o(G,Math.PI,c),c):b>.999999?(c[0]=0,c[1]=0,c[2]=0,c[3]=1,c):(t.cross(k,$,G),c[0]=G[0],c[1]=G[1],c[2]=G[2],c[3]=1+b,L(c,c))}let ft=new e(4),yt=new e(4);function pt(k,$,F,c,b,w){let z=w??new e(4);return N(k,c,b,ft),N($,F,b,yt),N(ft,yt,2*b*(1-b),z),z}return{create:n,fromValues:r,set:i,fromAxisAngle:o,toAxisAngle:s,angle:f,multiply:h,mul:p,rotateX:g,rotateY:D,rotateZ:X,slerp:N,inverse:I,conjugate:V,fromMat:q,fromEuler:Y,copy:K,clone:Q,add:tt,subtract:H,sub:W,mulScalar:st,scale:et,divScalar:rt,dot:U,lerp:a,length:v,len:T,lengthSq:M,lenSq:S,normalize:L,equalsApproximately:O,equals:B,identity:l,rotationTo:ut,sqlerp:pt}}var Bi=new Map;function nu(e){let t=Bi.get(e);return t||(t=ru(e),Bi.set(e,t)),t}function iu(e){function t(F,c,b,w){let z=new e(4);return F!==void 0&&(z[0]=F,c!==void 0&&(z[1]=c,b!==void 0&&(z[2]=b,w!==void 0&&(z[3]=w)))),z}let n=t;function r(F,c,b,w,z){let R=z??new e(4);return R[0]=F,R[1]=c,R[2]=b,R[3]=w,R}function i(F,c){let b=c??new e(4);return b[0]=Math.ceil(F[0]),b[1]=Math.ceil(F[1]),b[2]=Math.ceil(F[2]),b[3]=Math.ceil(F[3]),b}function o(F,c){let b=c??new e(4);return b[0]=Math.floor(F[0]),b[1]=Math.floor(F[1]),b[2]=Math.floor(F[2]),b[3]=Math.floor(F[3]),b}function s(F,c){let b=c??new e(4);return b[0]=Math.round(F[0]),b[1]=Math.round(F[1]),b[2]=Math.round(F[2]),b[3]=Math.round(F[3]),b}function f(F,c=0,b=1,w){let z=w??new e(4);return z[0]=Math.min(b,Math.max(c,F[0])),z[1]=Math.min(b,Math.max(c,F[1])),z[2]=Math.min(b,Math.max(c,F[2])),z[3]=Math.min(b,Math.max(c,F[3])),z}function h(F,c,b){let w=b??new e(4);return w[0]=F[0]+c[0],w[1]=F[1]+c[1],w[2]=F[2]+c[2],w[3]=F[3]+c[3],w}function p(F,c,b,w){let z=w??new e(4);return z[0]=F[0]+c[0]*b,z[1]=F[1]+c[1]*b,z[2]=F[2]+c[2]*b,z[3]=F[3]+c[3]*b,z}function g(F,c,b){let w=b??new e(4);return w[0]=F[0]-c[0],w[1]=F[1]-c[1],w[2]=F[2]-c[2],w[3]=F[3]-c[3],w}let D=g;function X(F,c){return Math.abs(F[0]-c[0])<Tt&&Math.abs(F[1]-c[1])<Tt&&Math.abs(F[2]-c[2])<Tt&&Math.abs(F[3]-c[3])<Tt}function N(F,c){return F[0]===c[0]&&F[1]===c[1]&&F[2]===c[2]&&F[3]===c[3]}function I(F,c,b,w){let z=w??new e(4);return z[0]=F[0]+b*(c[0]-F[0]),z[1]=F[1]+b*(c[1]-F[1]),z[2]=F[2]+b*(c[2]-F[2]),z[3]=F[3]+b*(c[3]-F[3]),z}function V(F,c,b,w){let z=w??new e(4);return z[0]=F[0]+b[0]*(c[0]-F[0]),z[1]=F[1]+b[1]*(c[1]-F[1]),z[2]=F[2]+b[2]*(c[2]-F[2]),z[3]=F[3]+b[3]*(c[3]-F[3]),z}function q(F,c,b){let w=b??new e(4);return w[0]=Math.max(F[0],c[0]),w[1]=Math.max(F[1],c[1]),w[2]=Math.max(F[2],c[2]),w[3]=Math.max(F[3],c[3]),w}function Y(F,c,b){let w=b??new e(4);return w[0]=Math.min(F[0],c[0]),w[1]=Math.min(F[1],c[1]),w[2]=Math.min(F[2],c[2]),w[3]=Math.min(F[3],c[3]),w}function K(F,c,b){let w=b??new e(4);return w[0]=F[0]*c,w[1]=F[1]*c,w[2]=F[2]*c,w[3]=F[3]*c,w}let Q=K;function tt(F,c,b){let w=b??new e(4);return w[0]=F[0]/c,w[1]=F[1]/c,w[2]=F[2]/c,w[3]=F[3]/c,w}function H(F,c){let b=c??new e(4);return b[0]=1/F[0],b[1]=1/F[1],b[2]=1/F[2],b[3]=1/F[3],b}let W=H;function st(F,c){return F[0]*c[0]+F[1]*c[1]+F[2]*c[2]+F[3]*c[3]}function et(F){let c=F[0],b=F[1],w=F[2],z=F[3];return Math.sqrt(c*c+b*b+w*w+z*z)}let rt=et;function U(F){let c=F[0],b=F[1],w=F[2],z=F[3];return c*c+b*b+w*w+z*z}let a=U;function v(F,c){let b=F[0]-c[0],w=F[1]-c[1],z=F[2]-c[2],R=F[3]-c[3];return Math.sqrt(b*b+w*w+z*z+R*R)}let T=v;function M(F,c){let b=F[0]-c[0],w=F[1]-c[1],z=F[2]-c[2],R=F[3]-c[3];return b*b+w*w+z*z+R*R}let S=M;function L(F,c){let b=c??new e(4),w=F[0],z=F[1],R=F[2],m=F[3],C=Math.sqrt(w*w+z*z+R*R+m*m);return C>1e-5?(b[0]=w/C,b[1]=z/C,b[2]=R/C,b[3]=m/C):(b[0]=0,b[1]=0,b[2]=0,b[3]=0),b}function O(F,c){let b=c??new e(4);return b[0]=-F[0],b[1]=-F[1],b[2]=-F[2],b[3]=-F[3],b}function B(F,c){let b=c??new e(4);return b[0]=F[0],b[1]=F[1],b[2]=F[2],b[3]=F[3],b}let l=B;function G(F,c,b){let w=b??new e(4);return w[0]=F[0]*c[0],w[1]=F[1]*c[1],w[2]=F[2]*c[2],w[3]=F[3]*c[3],w}let ot=G;function at(F,c,b){let w=b??new e(4);return w[0]=F[0]/c[0],w[1]=F[1]/c[1],w[2]=F[2]/c[2],w[3]=F[3]/c[3],w}let ut=at;function ft(F){let c=F??new e(4);return c[0]=0,c[1]=0,c[2]=0,c[3]=0,c}function yt(F,c,b){let w=b??new e(4),z=F[0],R=F[1],m=F[2],C=F[3];return w[0]=c[0]*z+c[4]*R+c[8]*m+c[12]*C,w[1]=c[1]*z+c[5]*R+c[9]*m+c[13]*C,w[2]=c[2]*z+c[6]*R+c[10]*m+c[14]*C,w[3]=c[3]*z+c[7]*R+c[11]*m+c[15]*C,w}function pt(F,c,b){let w=b??new e(4);return L(F,w),K(w,c,w)}function k(F,c,b){let w=b??new e(4);return et(F)>c?pt(F,c,w):B(F,w)}function $(F,c,b){let w=b??new e(4);return I(F,c,.5,w)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:f,add:h,addScaled:p,subtract:g,sub:D,equalsApproximately:X,equals:N,lerp:I,lerpV:V,max:q,min:Y,mulScalar:K,scale:Q,divScalar:tt,inverse:H,invert:W,dot:st,length:et,len:rt,lengthSq:U,lenSq:a,distance:v,dist:T,distanceSq:M,distSq:S,normalize:L,negate:O,copy:B,clone:l,multiply:G,mul:ot,divide:at,div:ut,zero:ft,transformMat4:yt,setLength:pt,truncate:k,midpoint:$}}var Di=new Map;function ou(e){let t=Di.get(e);return t||(t=iu(e),Di.set(e,t)),t}function pn(e,t,n,r,i,o){return{mat3:js(e),mat4:eu(t),quat:nu(n),vec2:Ui(r),vec3:vr(i),vec4:ou(o)}}var{mat3:Me,mat4:Lt,quat:_l,vec2:Et,vec3:fe,vec4:Ce}=pn(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array),{mat3:Bl,mat4:Dl,quat:Ul,vec2:Fl,vec3:Gl,vec4:Al}=pn(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array),{mat3:zl,mat4:Ll,quat:El,vec2:Rl,vec3:Il,vec4:Ol}=pn(Ws,Array,Array,Array,Array,Array);var dr=class{device;format="r8unorm";downsizeFactor;multisample;textureSimple;textureMultisampled=null;renderPipeline;bindgroup;uniformsBuffer;trianglesBuffer;constructor(t){this.device=t.device,this.downsizeFactor=t.blurFactor,this.multisample=this.downsizeFactor>1?4:1,[this.textureSimple,this.textureMultisampled]=this.createTextures(t.width,t.height),this.trianglesBuffer=t.trianglesBuffer;let n=this.device.createShaderModule({label:"DisplacementTexture shader module",code:bi});this.renderPipeline=this.device.createRenderPipeline({label:"DisplacementTexture renderpipeline",layout:"auto",vertex:{module:n,entryPoint:"main_vertex",buffers:[{attributes:[{shaderLocation:0,offset:0,format:"float32x2"}],arrayStride:2*Float32Array.BYTES_PER_ELEMENT,stepMode:"vertex"}]},fragment:{module:n,entryPoint:"main_fragment",targets:[{format:this.format}]},primitive:{cullMode:"none",topology:"triangle-list"},multisample:{count:this.multisample}}),this.uniformsBuffer=this.device.createBuffer({label:"DisplacementTexture uniforms buffer",size:64,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.bindgroup=this.device.createBindGroup({label:"DisplacementTexture bindgroup",layout:this.renderPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.uniformsBuffer}}]})}update(t){let n=this.textureMultisampled??this.textureSimple,r={view:n.view,clearValue:[0,0,0,1],loadOp:"clear",storeOp:"store"};this.textureMultisampled&&(r.resolveTarget=this.textureSimple.view);let i=t.beginRenderPass({label:"DisplacementTexture render to texture renderpass",colorAttachments:[r]}),[o,s]=[n.texture.width,n.texture.height];i.setViewport(0,0,o,s,0,1),i.setScissorRect(0,0,o,s),i.setPipeline(this.renderPipeline),i.setBindGroup(0,this.bindgroup),i.setVertexBuffer(0,this.trianglesBuffer.bufferGpu),i.draw(3*this.trianglesBuffer.spriteCount),i.end()}resize(t,n){this.textureSimple.texture.destroy(),this.textureMultisampled?.texture.destroy(),[this.textureSimple,this.textureMultisampled]=this.createTextures(t,n)}setViewport(t){let n=[1,1,1],r=0,i=[1,1,0],o=Lt.identity();Lt.multiply(Lt.scaling(n),o,o),Lt.multiply(Lt.rotationZ(r),o,o),Lt.multiply(Lt.translation(i),o,o);let s=Lt.translation([-t.position[0],-t.position[1],0]),f=t.width/t.zoom,h=t.height/t.zoom,p=Lt.ortho(0,f,h,0,-10,10),g=Lt.identity();Lt.multiply(s,o,g),Lt.multiply(p,g,g),this.device.queue.writeBuffer(this.uniformsBuffer,0,g)}getView(){return this.textureSimple.view}destroy(){this.textureSimple.texture.destroy(),this.textureMultisampled?.texture.destroy(),this.uniformsBuffer.destroy()}createTextures(t,n){let r=this.device.createTexture({label:"DisplacementTexture texture",size:[Math.ceil(t/this.downsizeFactor),Math.ceil(n/this.downsizeFactor)],format:this.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT}),i={texture:r,view:r.createView({label:"DisplacementTexture texture view"})},o=null;if(this.multisample>1){let s=this.device.createTexture({label:"DisplacementTexture texture multisampled",size:[r.width,r.height],format:r.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT,sampleCount:this.multisample});o={texture:s,view:s.createView({label:"DisplacementTexture texture multisampled view"})}}return[i,o]}};function Be(){return Math.ceil(Math.random()*(Number.MAX_SAFE_INTEGER-10))}var gr=class{device;floatsPerSprite=6;bufferGpu;bufferNeedsUpdate=!1;sprites=new Map;get spriteCount(){return this.sprites.size}constructor(t){this.device=t.device,this.bufferGpu=this.device.createBuffer({size:t.maxSpriteCount*this.floatsPerSprite*Float32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST})}destroy(){this.bufferGpu.destroy}update(){if(this.bufferNeedsUpdate){let t=[];for(let r of this.sprites.values())t.push(...r);let n=new Float32Array(t);this.device.queue.writeBuffer(this.bufferGpu,0,n)}}addTriangle(t){let n=Be();if(this.sprites.has(n))throw new Error(`Duplicate triangle "${n}".`);let r=this.buildTriangleData(t);return this.sprites.set(n,r),this.bufferNeedsUpdate=!0,n}removeTriangle(t){if(!this.sprites.has(t))throw new Error(`Unknown triangle "${t}".`);this.sprites.delete(t),this.bufferNeedsUpdate=!0}setTriangle(t,n){if(!this.sprites.has(t))throw new Error(`Unknown triangle "${t}".`);let r=this.buildTriangleData(n);this.sprites.set(t,r),this.bufferNeedsUpdate=!0}buildTriangleData(t){return[t[0][0],t[0][1],t[1][0],t[1][1],t[2][0],t[2][1]]}};var Gi={type:"cobalt:displacement",refs:[{name:"color",type:"textureView",format:"bgra8unorm",access:"read"},{name:"map",type:"cobaltTexture",format:"bgra8unorm",access:"read"},{name:"out",type:"textureView",format:"bgra8unorm",access:"write"}],onInit:async function(e,t={}){return au(e,t)},onRun:function(e,t,n){su(e,t,n)},onDestroy:function(e,t){uu(t)},onResize:function(e,t){t.data.displacementTexture.resize(e.viewport.width,e.viewport.height),t.data.displacementComposition.setColorTextureView(t.refs.color.data.view),t.data.displacementComposition.setNoiseMapTextureView(t.refs.map.view),t.data.displacementComposition.setDisplacementTextureView(t.data.displacementTexture.getView())},onViewportPosition:function(e,t){t.data.displacementTexture.setViewport(e.viewport)},customFunctions:{addTriangle:function(e,t,n){return t.data.trianglesBuffer.addTriangle(n)},removeTriangle:function(e,t,n){t.data.trianglesBuffer.removeTriangle(n)},setPosition:function(e,t,n,r){t.data.trianglesBuffer.setTriangle(n,r)}}};async function au(e,t){let{device:n}=e,r=new pr({device:n,initialParameters:{offsetX:t.options.offseyX??0,offsetY:t.options.offseyY??0,scale:t.options.scale??20}}),i=256,o=new gr({device:n,maxSpriteCount:i}),s=new dr({device:n,width:e.viewport.width,height:e.viewport.height,blurFactor:8,trianglesBuffer:o}),f=new hr({device:n,targetFormat:qt(e),colorTextureView:t.refs.color.data.view,noiseMapTextureView:t.refs.map.view,displacementTextureView:s.getView(),displacementParametersBuffer:r});return{displacementParameters:r,displacementTexture:s,displacementComposition:f,trianglesBuffer:o}}function su(e,t,n){if(t.data.trianglesBuffer.spriteCount===0)return;t.data.trianglesBuffer.update(),t.data.displacementTexture.update(n);let i=n.beginRenderPass({label:"displacement",colorAttachments:[{view:t.refs.out,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});i.executeBundles([t.data.displacementComposition.getRenderBundle()]),i.end()}function uu(e){e.data.trianglesBuffer.destroy(),e.data.trianglesBuffer=null,e.data.displacementParameters.destroy(),e.data.displacementParameters=null,e.data.displacementTexture.destroy(),e.data.displacementTexture=null,e.data.displacementComposition.destroy(),e.data.displacementComposition=null}var vn="@binding(0)@group(0)var tileTexture:texture_2d<f32>;@binding(1)@group(0)var tileSampler:sampler;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>};const positions=array<vec2<f32>,3>(vec2<f32>(-1.0,-3.0),vec2<f32>(3.0,1.0),vec2<f32>(-1.0,1.0));const uvs=array<vec2<f32>,3>(vec2<f32>(0.0,2.0),vec2<f32>(2.0,0.0),vec2<f32>(0.0,0.0));@vertex fn vs_main(@builtin(vertex_index)VertexIndex:u32)->Fragment{var output:Fragment;output.Position=vec4<f32>(positions[VertexIndex],0.0,1.0);output.TexCoord=vec2<f32>(uvs[VertexIndex]);return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>)->@location(0)vec4<f32>{var col=textureSample(tileTexture,tileSampler,TexCoord);return vec4<f32>(col.rgb,1.0);}";var Ai={type:"cobalt:fbBlit",refs:[{name:"in",type:"cobaltTexture",format:"PREFERRED_TEXTURE_FORMAT",access:"read"},{name:"out",type:"cobaltTexture",format:"PREFERRED_TEXTURE_FORMAT",access:"write"}],onInit:async function(e,t={}){return fu(e,t)},onRun:function(e,t,n){cu(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){lu(e,t)},onViewportPosition:function(e,t){}};async function fu(e,t){let{device:n}=e,r=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),i=n.createBindGroup({layout:r,entries:[{binding:0,resource:t.refs.in.data.view},{binding:1,resource:t.refs.in.data.sampler}]}),o=n.createPipelineLayout({bindGroupLayouts:[r]}),s=n.createRenderPipeline({label:"fb-blit",vertex:{module:n.createShaderModule({code:vn}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:vn}),entryPoint:"fs_main",targets:[{format:qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:o});return{bindGroupLayout:r,bindGroup:i,pipeline:s}}function cu(e,t,n){let{device:r}=e,i=n.beginRenderPass({label:"fb-blit",colorAttachments:[{view:t.refs.out,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});i.setPipeline(t.data.pipeline),i.setBindGroup(0,t.data.bindGroup),i.draw(3),i.end()}function lu(e,t){let{device:n}=e;t.data.bindGroup=n.createBindGroup({layout:t.data.bindGroupLayout,entries:[{binding:0,resource:t.refs.in.data.view},{binding:1,resource:t.refs.in.data.sampler}]})}var zi={type:"fbTexture",refs:[],onInit:async function(e,t={}){return hu(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){Li(data)},onResize:function(e,t){pu(e,t)},onViewportPosition:function(e,t){}};async function hu(e,t){let{device:n}=e;t.options.format=t.options.format==="PREFERRED_TEXTURE_FORMAT"?qt(e):t.options.format;let{format:r,label:i,mip_count:o,usage:s,viewportScale:f}=t.options;return ne(n,i,e.viewport.width*f,e.viewport.height*f,o,r,s)}function Li(e){e.data.texture.destroy()}function pu(e,t){let{device:n}=e;Li(t);let{width:r,height:i}=e.viewport,{options:o}=t,s=t.options.viewportScale;t.data=ne(n,o.label,r*s,i*s,o.mip_count,o.format,o.usage)}var ae=class e{static structs={definition:`
|
|
1
|
+
var Os=Object.create;var ln=Object.defineProperty;var ms=Object.getOwnPropertyDescriptor;var Vs=Object.getOwnPropertyNames;var qs=Object.getPrototypeOf,Ns=Object.prototype.hasOwnProperty;var xt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),hn=(e,t)=>{for(var n in t)ln(e,n,{get:t[n],enumerable:!0})},Cs=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Vs(t))!Ns.call(e,i)&&i!==n&&ln(e,i,{get:()=>t[i],enumerable:!(r=ms(t,i))||r.enumerable});return e};var pi=(e,t,n)=>(n=e!=null?Os(qs(e)):{},Cs(t||!e||!e.__esModule?ln(n,"default",{value:e,enumerable:!0}):n,e));var je=xt((_1,Ii)=>{"use strict";function bu(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h>=0?(o=s,i=s-1):r=s+1}return o}function Tu(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h>0?(o=s,i=s-1):r=s+1}return o}function Pu(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h<0?(o=s,r=s+1):i=s-1}return o}function Su(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,f=e[s],h=n!==void 0?n(f,t):f-t;h<=0?(o=s,r=s+1):i=s-1}return o}function _u(e,t,n,r,i){for(;r<=i;){var o=r+i>>>1,s=e[o],f=n!==void 0?n(s,t):s-t;if(f===0)return o;f<=0?r=o+1:i=o-1}return-1}function Je(e,t,n,r,i,o){return typeof n=="function"?o(e,t,n,r===void 0?0:r|0,i===void 0?e.length-1:i|0):o(e,t,void 0,n===void 0?0:n|0,r===void 0?e.length-1:r|0)}Ii.exports={ge:function(e,t,n,r,i){return Je(e,t,n,r,i,bu)},gt:function(e,t,n,r,i){return Je(e,t,n,r,i,Tu)},lt:function(e,t,n,r,i){return Je(e,t,n,r,i,Pu)},le:function(e,t,n,r,i){return Je(e,t,n,r,i,Su)},eq:function(e,t,n,r,i){return Je(e,t,n,r,i,_u)}}});var Tr=xt((B1,mi)=>{"use strict";mi.exports=Bu;var Oi=+(Math.pow(2,27)+1);function Bu(e,t,n){var r=e*t,i=Oi*e,o=i-e,s=i-o,f=e-s,h=Oi*t,p=h-t,g=h-p,D=t-g,X=r-s*g,N=X-f*g,I=N-s*D,V=f*D-I;return n?(n[0]=V,n[1]=r,n):[V,r]}});var gn=xt((D1,Vi)=>{"use strict";Vi.exports=Uu;function Du(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,f=s+o;return f?[f,n]:[n]}function Uu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return Du(e[0],t[0]);var i=n+r,o=new Array(i),s=0,f=0,h=0,p=Math.abs,g=e[f],D=p(g),X=t[h],N=p(X),I,V;D<N?(V=g,f+=1,f<n&&(g=e[f],D=p(g))):(V=X,h+=1,h<r&&(X=t[h],N=p(X))),f<n&&D<N||h>=r?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=t[h],N=p(X)));for(var q=I+V,Y=q-I,K=V-Y,Q=K,tt=q,H,W,st,et,rt;f<n&&h<r;)D<N?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=t[h],N=p(X))),V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H;for(;f<n;)I=g,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,f+=1,f<n&&(g=e[f]);for(;h<r;)I=X,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,h+=1,h<r&&(X=t[h]);return Q&&(o[s++]=Q),tt&&(o[s++]=tt),s||(o[s++]=0),o.length=s,o}});var Ni=xt((U1,qi)=>{"use strict";qi.exports=Fu;function Fu(e,t,n){var r=e+t,i=r-e,o=r-i,s=t-i,f=e-o;return n?(n[0]=f+s,n[1]=r,n):[f+s,r]}});var xn=xt((F1,Ci)=>{"use strict";var wn=Tr(),Gu=Ni();Ci.exports=Au;function Au(e,t){var n=e.length;if(n===1){var r=wn(e[0],t);return r[0]?r:[r[1]]}var i=new Array(2*n),o=[.1,.1],s=[.1,.1],f=0;wn(e[0],t,o),o[0]&&(i[f++]=o[0]);for(var h=1;h<n;++h){wn(e[h],t,s);var p=o[1];Gu(p,s[0],o),o[0]&&(i[f++]=o[0]);var g=s[1],D=o[1],X=g+D,N=X-g,I=D-N;o[1]=X,I&&(i[f++]=I)}return o[1]&&(i[f++]=o[1]),f===0&&(i[f++]=0),i.length=f,i}});var yn=xt((G1,Xi)=>{"use strict";Xi.exports=Lu;function zu(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,f=s+o;return f?[f,n]:[n]}function Lu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return zu(e[0],-t[0]);var i=n+r,o=new Array(i),s=0,f=0,h=0,p=Math.abs,g=e[f],D=p(g),X=-t[h],N=p(X),I,V;D<N?(V=g,f+=1,f<n&&(g=e[f],D=p(g))):(V=X,h+=1,h<r&&(X=-t[h],N=p(X))),f<n&&D<N||h>=r?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=-t[h],N=p(X)));for(var q=I+V,Y=q-I,K=V-Y,Q=K,tt=q,H,W,st,et,rt;f<n&&h<r;)D<N?(I=g,f+=1,f<n&&(g=e[f],D=p(g))):(I=X,h+=1,h<r&&(X=-t[h],N=p(X))),V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H;for(;f<n;)I=g,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,f+=1,f<n&&(g=e[f]);for(;h<r;)I=X,V=Q,q=I+V,Y=q-I,K=V-Y,K&&(o[s++]=K),H=tt+q,W=H-tt,st=H-W,et=q-W,rt=tt-st,Q=rt+et,tt=H,h+=1,h<r&&(X=-t[h]);return Q&&(o[s++]=Q),tt&&(o[s++]=tt),s||(o[s++]=0),o.length=s,o}});var bn=xt((A1,Mn)=>{"use strict";var Eu=Tr(),Ru=gn(),Iu=xn(),Ou=yn(),ki=5,Pr=11102230246251565e-32,mu=(3+16*Pr)*Pr,Vu=(7+56*Pr)*Pr;function qu(e,t,n,r){return function(o,s,f){var h=e(e(t(s[1],f[0]),t(-f[1],s[0])),e(t(o[1],s[0]),t(-s[1],o[0]))),p=e(t(o[1],f[0]),t(-f[1],o[0])),g=r(h,p);return g[g.length-1]}}function Nu(e,t,n,r){return function(o,s,f,h){var p=e(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),h[2]))),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),h[2])))),g=e(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),h[2]))),e(n(e(t(s[1],f[0]),t(-f[1],s[0])),o[2]),e(n(e(t(o[1],f[0]),t(-f[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),f[2])))),D=r(p,g);return D[D.length-1]}}function Cu(e,t,n,r){return function(o,s,f,h,p){var g=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),f[2]),e(n(e(t(f[1],p[0]),t(-p[1],f[0])),-h[2]),n(e(t(f[1],h[0]),t(-h[1],f[0])),p[2]))),s[3]),e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-h[2]),n(e(t(s[1],h[0]),t(-h[1],s[0])),p[2]))),-f[3]),n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),p[2]))),h[3]))),e(n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),h[2]))),-p[3]),e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-h[2]),n(e(t(s[1],h[0]),t(-h[1],s[0])),p[2]))),o[3]),n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-h[2]),n(e(t(o[1],h[0]),t(-h[1],o[0])),p[2]))),-s[3])))),e(e(n(e(n(e(t(s[1],p[0]),t(-p[1],s[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),p[2]))),h[3]),e(n(e(n(e(t(s[1],h[0]),t(-h[1],s[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),h[2]))),-p[3]),n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),h[2]))),o[3]))),e(n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),h[2]))),-s[3]),e(n(e(n(e(t(s[1],h[0]),t(-h[1],s[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),h[2]))),f[3]),n(e(n(e(t(s[1],f[0]),t(-f[1],s[0])),o[2]),e(n(e(t(o[1],f[0]),t(-f[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),f[2]))),-h[3]))))),D=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),f[2]),e(n(e(t(f[1],p[0]),t(-p[1],f[0])),-h[2]),n(e(t(f[1],h[0]),t(-h[1],f[0])),p[2]))),o[3]),n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-h[2]),n(e(t(o[1],h[0]),t(-h[1],o[0])),p[2]))),-f[3])),e(n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),p[2]))),h[3]),n(e(n(e(t(f[1],h[0]),t(-h[1],f[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),h[2]))),-p[3]))),e(e(n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-f[2]),n(e(t(s[1],f[0]),t(-f[1],s[0])),p[2]))),o[3]),n(e(n(e(t(f[1],p[0]),t(-p[1],f[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-f[2]),n(e(t(o[1],f[0]),t(-f[1],o[0])),p[2]))),-s[3])),e(n(e(n(e(t(s[1],p[0]),t(-p[1],s[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),p[2]))),f[3]),n(e(n(e(t(s[1],f[0]),t(-f[1],s[0])),o[2]),e(n(e(t(o[1],f[0]),t(-f[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),f[2]))),-p[3])))),X=r(g,D);return X[X.length-1]}}function Sr(e){var t=e===3?qu:e===4?Nu:Cu;return t(Ru,Eu,Iu,Ou)}var Xu=Sr(3),ku=Sr(4),De=[function(){return 0},function(){return 0},function(t,n){return n[0]-t[0]},function(t,n,r){var i=(t[1]-r[1])*(n[0]-r[0]),o=(t[0]-r[0])*(n[1]-r[1]),s=i-o,f;if(i>0){if(o<=0)return s;f=i+o}else if(i<0){if(o>=0)return s;f=-(i+o)}else return s;var h=mu*f;return s>=h||s<=-h?s:Xu(t,n,r)},function(t,n,r,i){var o=t[0]-i[0],s=n[0]-i[0],f=r[0]-i[0],h=t[1]-i[1],p=n[1]-i[1],g=r[1]-i[1],D=t[2]-i[2],X=n[2]-i[2],N=r[2]-i[2],I=s*g,V=f*p,q=f*h,Y=o*g,K=o*p,Q=s*h,tt=D*(I-V)+X*(q-Y)+N*(K-Q),H=(Math.abs(I)+Math.abs(V))*Math.abs(D)+(Math.abs(q)+Math.abs(Y))*Math.abs(X)+(Math.abs(K)+Math.abs(Q))*Math.abs(N),W=Vu*H;return tt>W||-tt>W?tt:ku(t,n,r,i)}];function Yu(e){var t=De[e.length];return t||(t=De[e.length]=Sr(e.length)),t.apply(void 0,e)}function Hu(e,t,n,r,i,o,s){return function(h,p,g,D,X){switch(arguments.length){case 0:case 1:return 0;case 2:return r(h,p);case 3:return i(h,p,g);case 4:return o(h,p,g,D);case 5:return s(h,p,g,D,X)}for(var N=new Array(arguments.length),I=0;I<arguments.length;++I)N[I]=arguments[I];return e(N)}}function Zu(){for(;De.length<=ki;)De.push(Sr(De.length));Mn.exports=Hu.apply(void 0,[Yu].concat(De));for(var e=0;e<=ki;++e)Mn.exports[e]=De[e]}Zu()});var Ki=xt((z1,Wi)=>{"use strict";var _r=je(),be=bn()[3],Pn=0,Yi=1,Tn=2;Wi.exports=Ju;function Zi(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function tr(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function $u(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==Pn&&(n=be(e.a,e.b,t.b),n)?n:e.idx-t.idx}function Hi(e,t){return be(e.a,e.b,t)}function Wu(e,t,n,r,i){for(var o=_r.lt(t,r,Hi),s=_r.gt(t,r,Hi),f=o;f<s;++f){for(var h=t[f],p=h.lowerIds,D=p.length;D>1&&be(n[p[D-2]],n[p[D-1]],r)>0;)e.push([p[D-1],p[D-2],i]),D-=1;p.length=D,p.push(i);for(var g=h.upperIds,D=g.length;D>1&&be(n[g[D-2]],n[g[D-1]],r)<0;)e.push([g[D-2],g[D-1],i]),D-=1;g.length=D,g.push(i)}}function $i(e,t){var n;return e.a[0]<t.a[0]?n=be(e.a,e.b,t.a):n=be(t.b,t.a,e.a),n||(t.b[0]<e.b[0]?n=be(e.a,e.b,t.b):n=be(t.b,t.a,e.b),n||e.idx-t.idx)}function Ku(e,t,n){var r=_r.le(e,n,$i),i=e[r],o=i.upperIds,s=o[o.length-1];i.upperIds=[s],e.splice(r+1,0,new Zi(n.a,n.b,n.idx,[s],o))}function Qu(e,t,n){var r=n.a;n.a=n.b,n.b=r;var i=_r.eq(e,n,$i),o=e[i],s=e[i-1];s.upperIds=o.upperIds,e.splice(i,1)}function Ju(e,t){for(var n=e.length,r=t.length,i=[],o=0;o<n;++o)i.push(new tr(e[o],null,Pn,o));for(var o=0;o<r;++o){var s=t[o],f=e[s[0]],h=e[s[1]];f[0]<h[0]?i.push(new tr(f,h,Tn,o),new tr(h,f,Yi,o)):f[0]>h[0]&&i.push(new tr(h,f,Tn,o),new tr(f,h,Yi,o))}i.sort($u);for(var p=i[0].a[0]-(1+Math.abs(i[0].a[0]))*Math.pow(2,-52),g=[new Zi([p,1],[p,0],-1,[],[],[],[])],D=[],o=0,X=i.length;o<X;++o){var N=i[o],I=N.type;I===Pn?Wu(D,g,e,N.a,N.idx):I===Tn?Ku(g,e,N):Qu(g,e,N)}return D}});var ji=xt((L1,Ji)=>{"use strict";var ju=je();Ji.exports=t0;function Qi(e,t){this.stars=e,this.edges=t}var Ue=Qi.prototype;function Sn(e,t,n){for(var r=1,i=e.length;r<i;r+=2)if(e[r-1]===t&&e[r]===n){e[r-1]=e[i-2],e[r]=e[i-1],e.length=i-2;return}}Ue.isConstraint=(function(){var e=[0,0];function t(n,r){return n[0]-r[0]||n[1]-r[1]}return function(n,r){return e[0]=Math.min(n,r),e[1]=Math.max(n,r),ju.eq(this.edges,e,t)>=0}})();Ue.removeTriangle=function(e,t,n){var r=this.stars;Sn(r[e],t,n),Sn(r[t],n,e),Sn(r[n],e,t)};Ue.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)};Ue.opposite=function(e,t){for(var n=this.stars[t],r=1,i=n.length;r<i;r+=2)if(n[r]===e)return n[r-1];return-1};Ue.flip=function(e,t){var n=this.opposite(e,t),r=this.opposite(t,e);this.removeTriangle(e,t,n),this.removeTriangle(t,e,r),this.addTriangle(e,r,n),this.addTriangle(t,n,r)};Ue.edges=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],o=0,s=i.length;o<s;o+=2)t.push([i[o],i[o+1]]);return t};Ue.cells=function(){for(var e=this.stars,t=[],n=0,r=e.length;n<r;++n)for(var i=e[n],o=0,s=i.length;o<s;o+=2){var f=i[o],h=i[o+1];n<Math.min(f,h)&&t.push([n,f,h])}return t};function t0(e,t){for(var n=new Array(e),r=0;r<e;++r)n[r]=[];return new Qi(n,t)}});var ro=xt((E1,_n)=>{"use strict";var e0=Tr(),r0=gn(),n0=yn(),i0=xn(),to=6;function eo(e){var t=e===3?u0:e===4?f0:e===5?c0:l0;return t(r0,n0,e0,i0)}function o0(){return 0}function a0(){return 0}function s0(){return 0}function u0(e,t,n,r){function i(o,s,f){var h=n(o[0],o[0]),p=r(h,s[0]),g=r(h,f[0]),D=n(s[0],s[0]),X=r(D,o[0]),N=r(D,f[0]),I=n(f[0],f[0]),V=r(I,o[0]),q=r(I,s[0]),Y=e(t(q,N),t(X,p)),K=t(V,g),Q=t(Y,K);return Q[Q.length-1]}return i}function f0(e,t,n,r){function i(o,s,f,h){var p=e(n(o[0],o[0]),n(o[1],o[1])),g=r(p,s[0]),D=r(p,f[0]),X=r(p,h[0]),N=e(n(s[0],s[0]),n(s[1],s[1])),I=r(N,o[0]),V=r(N,f[0]),q=r(N,h[0]),Y=e(n(f[0],f[0]),n(f[1],f[1])),K=r(Y,o[0]),Q=r(Y,s[0]),tt=r(Y,h[0]),H=e(n(h[0],h[0]),n(h[1],h[1])),W=r(H,o[0]),st=r(H,s[0]),et=r(H,f[0]),rt=e(e(r(t(et,tt),s[1]),e(r(t(st,q),-f[1]),r(t(Q,V),h[1]))),e(r(t(st,q),o[1]),e(r(t(W,X),-s[1]),r(t(I,g),h[1])))),U=e(e(r(t(et,tt),o[1]),e(r(t(W,X),-f[1]),r(t(K,D),h[1]))),e(r(t(Q,V),o[1]),e(r(t(K,D),-s[1]),r(t(I,g),f[1])))),a=t(rt,U);return a[a.length-1]}return i}function c0(e,t,n,r){function i(o,s,f,h,p){var g=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),D=r(g,s[0]),X=r(g,f[0]),N=r(g,h[0]),I=r(g,p[0]),V=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),q=r(V,o[0]),Y=r(V,f[0]),K=r(V,h[0]),Q=r(V,p[0]),tt=e(n(f[0],f[0]),e(n(f[1],f[1]),n(f[2],f[2]))),H=r(tt,o[0]),W=r(tt,s[0]),st=r(tt,h[0]),et=r(tt,p[0]),rt=e(n(h[0],h[0]),e(n(h[1],h[1]),n(h[2],h[2]))),U=r(rt,o[0]),a=r(rt,s[0]),v=r(rt,f[0]),T=r(rt,p[0]),M=e(n(p[0],p[0]),e(n(p[1],p[1]),n(p[2],p[2]))),S=r(M,o[0]),L=r(M,s[0]),O=r(M,f[0]),B=r(M,h[0]),l=e(e(e(r(e(r(t(B,T),f[1]),e(r(t(O,et),-h[1]),r(t(v,st),p[1]))),s[2]),e(r(e(r(t(B,T),s[1]),e(r(t(L,Q),-h[1]),r(t(a,K),p[1]))),-f[2]),r(e(r(t(O,et),s[1]),e(r(t(L,Q),-f[1]),r(t(W,Y),p[1]))),h[2]))),e(r(e(r(t(v,st),s[1]),e(r(t(a,K),-f[1]),r(t(W,Y),h[1]))),-p[2]),e(r(e(r(t(B,T),s[1]),e(r(t(L,Q),-h[1]),r(t(a,K),p[1]))),o[2]),r(e(r(t(B,T),o[1]),e(r(t(S,I),-h[1]),r(t(U,N),p[1]))),-s[2])))),e(e(r(e(r(t(L,Q),o[1]),e(r(t(S,I),-s[1]),r(t(q,D),p[1]))),h[2]),e(r(e(r(t(a,K),o[1]),e(r(t(U,N),-s[1]),r(t(q,D),h[1]))),-p[2]),r(e(r(t(v,st),s[1]),e(r(t(a,K),-f[1]),r(t(W,Y),h[1]))),o[2]))),e(r(e(r(t(v,st),o[1]),e(r(t(U,N),-f[1]),r(t(H,X),h[1]))),-s[2]),e(r(e(r(t(a,K),o[1]),e(r(t(U,N),-s[1]),r(t(q,D),h[1]))),f[2]),r(e(r(t(W,Y),o[1]),e(r(t(H,X),-s[1]),r(t(q,D),f[1]))),-h[2]))))),G=e(e(e(r(e(r(t(B,T),f[1]),e(r(t(O,et),-h[1]),r(t(v,st),p[1]))),o[2]),r(e(r(t(B,T),o[1]),e(r(t(S,I),-h[1]),r(t(U,N),p[1]))),-f[2])),e(r(e(r(t(O,et),o[1]),e(r(t(S,I),-f[1]),r(t(H,X),p[1]))),h[2]),r(e(r(t(v,st),o[1]),e(r(t(U,N),-f[1]),r(t(H,X),h[1]))),-p[2]))),e(e(r(e(r(t(O,et),s[1]),e(r(t(L,Q),-f[1]),r(t(W,Y),p[1]))),o[2]),r(e(r(t(O,et),o[1]),e(r(t(S,I),-f[1]),r(t(H,X),p[1]))),-s[2])),e(r(e(r(t(L,Q),o[1]),e(r(t(S,I),-s[1]),r(t(q,D),p[1]))),f[2]),r(e(r(t(W,Y),o[1]),e(r(t(H,X),-s[1]),r(t(q,D),f[1]))),-p[2])))),ot=t(l,G);return ot[ot.length-1]}return i}function l0(e,t,n,r){function i(o,s,f,h,p,g){var D=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),X=r(D,s[0]),N=r(D,f[0]),I=r(D,h[0]),V=r(D,p[0]),q=r(D,g[0]),Y=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),K=r(Y,o[0]),Q=r(Y,f[0]),tt=r(Y,h[0]),H=r(Y,p[0]),W=r(Y,g[0]),st=e(e(n(f[0],f[0]),n(f[1],f[1])),e(n(f[2],f[2]),n(f[3],f[3]))),et=r(st,o[0]),rt=r(st,s[0]),U=r(st,h[0]),a=r(st,p[0]),v=r(st,g[0]),T=e(e(n(h[0],h[0]),n(h[1],h[1])),e(n(h[2],h[2]),n(h[3],h[3]))),M=r(T,o[0]),S=r(T,s[0]),L=r(T,f[0]),O=r(T,p[0]),B=r(T,g[0]),l=e(e(n(p[0],p[0]),n(p[1],p[1])),e(n(p[2],p[2]),n(p[3],p[3]))),G=r(l,o[0]),ot=r(l,s[0]),at=r(l,f[0]),ut=r(l,h[0]),ft=r(l,g[0]),yt=e(e(n(g[0],g[0]),n(g[1],g[1])),e(n(g[2],g[2]),n(g[3],g[3]))),pt=r(yt,o[0]),k=r(yt,s[0]),$=r(yt,f[0]),F=r(yt,h[0]),c=r(yt,p[0]),b=e(e(e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),f[2]),r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),p[2]),r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),-g[2]))),s[3]),e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-h[2])),e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),p[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-g[2]))),-f[3]),r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),s[2]),r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),s[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-f[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-h[2])),e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),p[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-h[2])),e(r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),p[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),p[2]),r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),-g[2]))),h[3]),r(e(e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),s[2]),r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-g[2]))),o[3]))),e(e(r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-g[2]))),-s[3]),r(e(e(r(e(r(t(F,B),s[1]),e(r(t(k,W),-h[1]),r(t(S,tt),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-g[2]))),f[3])),e(r(e(e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-g[2]))),-h[3]),r(e(e(r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-s[2])),e(r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-h[2]))),g[3]))))),w=e(e(e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),f[2]),r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),p[2]),r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),-g[2]))),o[3]),e(r(e(e(r(e(r(t(c,ft),h[1]),e(r(t(F,B),-p[1]),r(t(ut,O),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-h[2])),e(r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),p[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-g[2]))),-f[3]),r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(F,B),f[1]),e(r(t($,v),-h[1]),r(t(L,U),g[1]))),o[2]),r(e(r(t(F,B),o[1]),e(r(t(pt,q),-h[1]),r(t(M,I),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-f[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),-f[2])),e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(c,ft),f[1]),e(r(t($,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-f[2])),e(r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(c,ft),s[1]),e(r(t(k,W),-p[1]),r(t(ot,H),g[1]))),o[2]),r(e(r(t(c,ft),o[1]),e(r(t(pt,q),-p[1]),r(t(G,V),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),p[2]),r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),-g[2]))),f[3]),r(e(e(r(e(r(t($,v),s[1]),e(r(t(k,W),-f[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t($,v),o[1]),e(r(t(pt,q),-f[1]),r(t(et,N),g[1]))),-s[2])),e(r(e(r(t(k,W),o[1]),e(r(t(pt,q),-s[1]),r(t(K,X),g[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),s[2]),r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),-f[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),-p[2]))),o[3]))),e(e(r(e(e(r(e(r(t(ut,O),f[1]),e(r(t(at,a),-h[1]),r(t(L,U),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-f[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),h[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-p[2]))),-s[3]),r(e(e(r(e(r(t(ut,O),s[1]),e(r(t(ot,H),-h[1]),r(t(S,tt),p[1]))),o[2]),r(e(r(t(ut,O),o[1]),e(r(t(G,V),-h[1]),r(t(M,I),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),h[2]),r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),-p[2]))),f[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,H),-f[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,V),-f[1]),r(t(et,N),p[1]))),-s[2])),e(r(e(r(t(ot,H),o[1]),e(r(t(G,V),-s[1]),r(t(K,X),p[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-p[2]))),-h[3]),r(e(e(r(e(r(t(L,U),s[1]),e(r(t(S,tt),-f[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(L,U),o[1]),e(r(t(M,I),-f[1]),r(t(et,N),h[1]))),-s[2])),e(r(e(r(t(S,tt),o[1]),e(r(t(M,I),-s[1]),r(t(K,X),h[1]))),f[2]),r(e(r(t(rt,Q),o[1]),e(r(t(et,N),-s[1]),r(t(K,X),f[1]))),-h[2]))),p[3]))))),z=t(b,w);return z[z.length-1]}return i}var Fe=[o0,a0,s0];function h0(e){var t=Fe[e.length];return t||(t=Fe[e.length]=eo(e.length)),t.apply(void 0,e)}function p0(e,t,n,r,i,o,s,f){function h(p,g,D,X,N,I){switch(arguments.length){case 0:case 1:return 0;case 2:return r(p,g);case 3:return i(p,g,D);case 4:return o(p,g,D,X);case 5:return s(p,g,D,X,N);case 6:return f(p,g,D,X,N,I)}for(var V=new Array(arguments.length),q=0;q<arguments.length;++q)V[q]=arguments[q];return e(V)}return h}function v0(){for(;Fe.length<=to;)Fe.push(eo(Fe.length));_n.exports=p0.apply(void 0,[h0].concat(Fe));for(var e=0;e<=to;++e)_n.exports[e]=Fe[e]}v0()});var io=xt((I1,no)=>{"use strict";var Bn=ro()[4],R1=je();no.exports=d0;function Br(e,t,n,r,i,o){var s=t.opposite(r,i);if(!(s<0)){if(i<r){var f=r;r=i,i=f,f=o,o=s,s=f}t.isConstraint(r,i)||Bn(e[r],e[i],e[o],e[s])<0&&n.push(r,i)}}function d0(e,t){for(var n=[],r=e.length,i=t.stars,o=0;o<r;++o)for(var s=i[o],f=1;f<s.length;f+=2){var h=s[f];if(!(h<o)&&!t.isConstraint(o,h)){for(var p=s[f-1],g=-1,D=1;D<s.length;D+=2)if(s[D-1]===h){g=s[D];break}g<0||Bn(e[o],e[h],e[p],e[g])<0&&n.push(o,h)}}for(;n.length>0;){for(var h=n.pop(),o=n.pop(),p=-1,g=-1,s=i[o],X=1;X<s.length;X+=2){var N=s[X-1],I=s[X];N===h?g=I:I===h&&(p=N)}p<0||g<0||Bn(e[o],e[h],e[p],e[g])>=0||(t.flip(o,h),Br(e,t,n,p,o,g),Br(e,t,n,o,g,p),Br(e,t,n,g,h,p),Br(e,t,n,h,p,g))}}});var uo=xt((O1,so)=>{"use strict";var g0=je();so.exports=M0;function oo(e,t,n,r,i,o,s){this.cells=e,this.neighbor=t,this.flags=r,this.constraint=n,this.active=i,this.next=o,this.boundary=s}var w0=oo.prototype;function ao(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}w0.locate=(function(){var e=[0,0,0];return function(t,n,r){var i=t,o=n,s=r;return n<r?n<t&&(i=n,o=r,s=t):r<t&&(i=r,o=t,s=n),i<0?-1:(e[0]=i,e[1]=o,e[2]=s,g0.eq(this.cells,e,ao))}})();function x0(e,t){for(var n=e.cells(),r=n.length,i=0;i<r;++i){var o=n[i],s=o[0],f=o[1],h=o[2];f<h?f<s&&(o[0]=f,o[1]=h,o[2]=s):h<s&&(o[0]=h,o[1]=s,o[2]=f)}n.sort(ao);for(var p=new Array(r),i=0;i<p.length;++i)p[i]=0;var g=[],D=[],X=new Array(3*r),N=new Array(3*r),I=null;t&&(I=[]);for(var V=new oo(n,X,N,p,g,D,I),i=0;i<r;++i)for(var o=n[i],q=0;q<3;++q){var s=o[q],f=o[(q+1)%3],Y=X[3*i+q]=V.locate(f,s,e.opposite(f,s)),K=N[3*i+q]=e.isConstraint(s,f);Y<0&&(K?D.push(i):(g.push(i),p[i]=1),t&&I.push([f,s,-1]))}return V}function y0(e,t,n){for(var r=0,i=0;i<e.length;++i)t[i]===n&&(e[r++]=e[i]);return e.length=r,e}function M0(e,t,n){var r=x0(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,o=r.active,s=r.next,f=r.flags,h=r.cells,p=r.constraint,g=r.neighbor;o.length>0||s.length>0;){for(;o.length>0;){var D=o.pop();if(f[D]!==-i){f[D]=i;for(var X=h[D],N=0;N<3;++N){var I=g[3*D+N];I>=0&&f[I]===0&&(p[3*D+N]?s.push(I):(o.push(I),f[I]=i))}}}var V=s;s=o,o=V,s.length=0,i=-i}var q=y0(h,f,t);return n?q.concat(r.boundary):q}});var co=xt((m1,fo)=>{"use strict";var b0=Ki(),T0=ji(),P0=io(),Dn=uo();fo.exports=D0;function S0(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function _0(e,t){return e[0]-t[0]||e[1]-t[1]}function B0(e){return e.map(S0).sort(_0)}function Dr(e,t,n){return t in e?e[t]:n}function D0(e,t,n){Array.isArray(t)?(n=n||{},t=t||[]):(n=t||{},t=[]);var r=!!Dr(n,"delaunay",!0),i=!!Dr(n,"interior",!0),o=!!Dr(n,"exterior",!0),s=!!Dr(n,"infinity",!1);if(!i&&!o||e.length===0)return[];var f=b0(e,t);if(r||i!==o||s){for(var h=T0(e.length,B0(t)),p=0;p<f.length;++p){var g=f[p];h.addTriangle(g[0],g[1],g[2])}return r&&P0(e,h),o?i?s?Dn(h,0,s):h.cells():Dn(h,1,s):Dn(h,-1)}else return f}});var po=xt((V1,ho)=>{"use strict";"use restrict";ho.exports=lo;function lo(e){this.roots=new Array(e),this.ranks=new Array(e);for(var t=0;t<e;++t)this.roots[t]=t,this.ranks[t]=0}var Ur=lo.prototype;Object.defineProperty(Ur,"length",{get:function(){return this.roots.length}});Ur.makeSet=function(){var e=this.roots.length;return this.roots.push(e),this.ranks.push(0),e};Ur.find=function(e){for(var t=e,n=this.roots;n[e]!==e;)e=n[e];for(;n[t]!==e;){var r=n[t];n[t]=e,t=r}return e};Ur.link=function(e,t){var n=this.find(e),r=this.find(t);if(n!==r){var i=this.ranks,o=this.roots,s=i[n],f=i[r];s<f?o[n]=r:f<s?o[r]=n:(o[r]=n,++i[n])}}});var rr=xt(Xt=>{"use strict";"use restrict";var Un=32;Xt.INT_BITS=Un;Xt.INT_MAX=2147483647;Xt.INT_MIN=-1<<Un-1;Xt.sign=function(e){return(e>0)-(e<0)};Xt.abs=function(e){var t=e>>Un-1;return(e^t)-t};Xt.min=function(e,t){return t^(e^t)&-(e<t)};Xt.max=function(e,t){return e^(e^t)&-(e<t)};Xt.isPow2=function(e){return!(e&e-1)&&!!e};Xt.log2=function(e){var t,n;return t=(e>65535)<<4,e>>>=t,n=(e>255)<<3,e>>>=n,t|=n,n=(e>15)<<2,e>>>=n,t|=n,n=(e>3)<<1,e>>>=n,t|=n,t|e>>1};Xt.log10=function(e){return e>=1e9?9:e>=1e8?8:e>=1e7?7:e>=1e6?6:e>=1e5?5:e>=1e4?4:e>=1e3?3:e>=100?2:e>=10?1:0};Xt.popCount=function(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),(e+(e>>>4)&252645135)*16843009>>>24};function vo(e){var t=32;return e&=-e,e&&t--,e&65535&&(t-=16),e&16711935&&(t-=8),e&252645135&&(t-=4),e&858993459&&(t-=2),e&1431655765&&(t-=1),t}Xt.countTrailingZeros=vo;Xt.nextPow2=function(e){return e+=e===0,--e,e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e+1};Xt.prevPow2=function(e){return e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e-(e>>>1)};Xt.parity=function(e){return e^=e>>>16,e^=e>>>8,e^=e>>>4,e&=15,27030>>>e&1};var er=new Array(256);(function(e){for(var t=0;t<256;++t){var n=t,r=t,i=7;for(n>>>=1;n;n>>>=1)r<<=1,r|=n&1,--i;e[t]=r<<i&255}})(er);Xt.reverse=function(e){return er[e&255]<<24|er[e>>>8&255]<<16|er[e>>>16&255]<<8|er[e>>>24&255]};Xt.interleave2=function(e,t){return e&=65535,e=(e|e<<8)&16711935,e=(e|e<<4)&252645135,e=(e|e<<2)&858993459,e=(e|e<<1)&1431655765,t&=65535,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,e|t<<1};Xt.deinterleave2=function(e,t){return e=e>>>t&1431655765,e=(e|e>>>1)&858993459,e=(e|e>>>2)&252645135,e=(e|e>>>4)&16711935,e=(e|e>>>16)&65535,e<<16>>16};Xt.interleave3=function(e,t,n){return e&=1023,e=(e|e<<16)&4278190335,e=(e|e<<8)&251719695,e=(e|e<<4)&3272356035,e=(e|e<<2)&1227133513,t&=1023,t=(t|t<<16)&4278190335,t=(t|t<<8)&251719695,t=(t|t<<4)&3272356035,t=(t|t<<2)&1227133513,e|=t<<1,n&=1023,n=(n|n<<16)&4278190335,n=(n|n<<8)&251719695,n=(n|n<<4)&3272356035,n=(n|n<<2)&1227133513,e|n<<2};Xt.deinterleave3=function(e,t){return e=e>>>t&1227133513,e=(e|e>>>2)&3272356035,e=(e|e>>>4)&251719695,e=(e|e>>>8)&4278190335,e=(e|e>>>16)&1023,e<<22>>22};Xt.nextCombination=function(e){var t=e|e-1;return t+1|(~t&-~t)-1>>>vo(e)+1}});var xo=xt((N1,wo)=>{"use strict";function go(e,t,n){var r=e[n]|0;if(r<=0)return[];var i=new Array(r),o;if(n===e.length-1)for(o=0;o<r;++o)i[o]=t;else for(o=0;o<r;++o)i[o]=go(e,t,n+1);return i}function U0(e,t){var n,r;for(n=new Array(e),r=0;r<e;++r)n[r]=t;return n}function F0(e,t){switch(typeof t>"u"&&(t=0),typeof e){case"number":if(e>0)return U0(e|0,t);break;case"object":if(typeof e.length=="number")return go(e,t,0);break}return[]}wo.exports=F0});var Ar=xt(zt=>{"use strict";var Fr=rr(),te=xo();globalThis.__TYPEDARRAY_POOL||(globalThis.__TYPEDARRAY_POOL={UINT8:te([32,0]),UINT16:te([32,0]),UINT32:te([32,0]),BIGUINT64:te([32,0]),INT8:te([32,0]),INT16:te([32,0]),INT32:te([32,0]),BIGINT64:te([32,0]),FLOAT:te([32,0]),DOUBLE:te([32,0]),DATA:te([32,0]),UINT8C:te([32,0])});var G0=typeof Uint8ClampedArray<"u",A0=typeof BigUint64Array<"u",z0=typeof BigInt64Array<"u",Qt=globalThis.__TYPEDARRAY_POOL;Qt.UINT8C||(Qt.UINT8C=te([32,0]));Qt.BIGUINT64||(Qt.BIGUINT64=te([32,0]));Qt.BIGINT64||(Qt.BIGINT64=te([32,0]));var Gr=Qt.DATA;zt.free=function(t){if(Object.prototype.toString.call(t)!=="[object ArrayBuffer]"&&(t=t.buffer),!!t){var n=t.length||t.byteLength,r=Fr.log2(n)|0;Gr[r].push(t)}};function yo(e){if(e){var t=e.length||e.byteLength,n=Fr.log2(t);Gr[n].push(e)}}function L0(e){yo(e.buffer)}zt.freeUint8=zt.freeUint16=zt.freeUint32=zt.freeBigUint64=zt.freeInt8=zt.freeInt16=zt.freeInt32=zt.freeBigInt64=zt.freeFloat32=zt.freeFloat=zt.freeFloat64=zt.freeDouble=zt.freeUint8Clamped=zt.freeDataView=L0;zt.freeArrayBuffer=yo;zt.malloc=function(t,n){if(n===void 0||n==="arraybuffer")return ie(t);switch(n){case"uint8":return Fn(t);case"uint16":return Mo(t);case"uint32":return bo(t);case"int8":return To(t);case"int16":return Po(t);case"int32":return So(t);case"float":case"float32":return _o(t);case"double":case"float64":return Bo(t);case"uint8_clamped":return Do(t);case"bigint64":return Fo(t);case"biguint64":return Uo(t);case"data":case"dataview":return Go(t);default:return null}return null};function ie(t){var t=Fr.nextPow2(t),n=Fr.log2(t),r=Gr[n];return r.length>0?r.pop():new ArrayBuffer(t)}zt.mallocArrayBuffer=ie;function Fn(e){return new Uint8Array(ie(e),0,e)}zt.mallocUint8=Fn;function Mo(e){return new Uint16Array(ie(2*e),0,e)}zt.mallocUint16=Mo;function bo(e){return new Uint32Array(ie(4*e),0,e)}zt.mallocUint32=bo;function To(e){return new Int8Array(ie(e),0,e)}zt.mallocInt8=To;function Po(e){return new Int16Array(ie(2*e),0,e)}zt.mallocInt16=Po;function So(e){return new Int32Array(ie(4*e),0,e)}zt.mallocInt32=So;function _o(e){return new Float32Array(ie(4*e),0,e)}zt.mallocFloat32=zt.mallocFloat=_o;function Bo(e){return new Float64Array(ie(8*e),0,e)}zt.mallocFloat64=zt.mallocDouble=Bo;function Do(e){return G0?new Uint8ClampedArray(ie(e),0,e):Fn(e)}zt.mallocUint8Clamped=Do;function Uo(e){return A0?new BigUint64Array(ie(8*e),0,e):null}zt.mallocBigUint64=Uo;function Fo(e){return z0?new BigInt64Array(ie(8*e),0,e):null}zt.mallocBigInt64=Fo;function Go(e){return new DataView(ie(e),0,e)}zt.mallocDataView=Go;zt.clearCache=function(){for(var t=0;t<32;++t)Qt.UINT8[t].length=0,Qt.UINT16[t].length=0,Qt.UINT32[t].length=0,Qt.INT8[t].length=0,Qt.INT16[t].length=0,Qt.INT32[t].length=0,Qt.FLOAT[t].length=0,Qt.DOUBLE[t].length=0,Qt.BIGUINT64[t].length=0,Qt.BIGINT64[t].length=0,Qt.UINT8C[t].length=0,Gr[t].length=0}});var Ro=xt((X1,Eo)=>{"use strict";Eo.exports=E0;var Lr=32;function E0(e,t){t<=4*Lr?Er(0,t-1,e):Rr(0,t-1,e)}function Er(e,t,n){for(var r=2*(e+1),i=e+1;i<=t;++i){for(var o=n[r++],s=n[r++],f=i,h=r-2;f-- >e;){var p=n[h-2],g=n[h-1];if(p<o)break;if(p===o&&g<s)break;n[h]=p,n[h+1]=g,h-=2}n[h]=o,n[h+1]=s}}function Ao(e,t,n){e*=2,t*=2;var r=n[e],i=n[e+1];n[e]=n[t],n[e+1]=n[t+1],n[t]=r,n[t+1]=i}function zo(e,t,n){e*=2,t*=2,n[e]=n[t],n[e+1]=n[t+1]}function R0(e,t,n,r){e*=2,t*=2,n*=2;var i=r[e],o=r[e+1];r[e]=r[t],r[e+1]=r[t+1],r[t]=r[n],r[t+1]=r[n+1],r[n]=i,r[n+1]=o}function Lo(e,t,n,r,i){e*=2,t*=2,i[e]=i[t],i[t]=n,i[e+1]=i[t+1],i[t+1]=r}function ge(e,t,n){e*=2,t*=2;var r=n[e],i=n[t];return r<i?!1:r===i?n[e+1]>n[t+1]:!0}function zr(e,t,n,r){e*=2;var i=r[e];return i<t?!0:i===t?r[e+1]<n:!1}function Rr(e,t,n){var r=(t-e+1)/6|0,i=e+r,o=t-r,s=e+t>>1,f=s-r,h=s+r,p=i,g=f,D=s,X=h,N=o,I=e+1,V=t-1,q=0;ge(p,g,n)&&(q=p,p=g,g=q),ge(X,N,n)&&(q=X,X=N,N=q),ge(p,D,n)&&(q=p,p=D,D=q),ge(g,D,n)&&(q=g,g=D,D=q),ge(p,X,n)&&(q=p,p=X,X=q),ge(D,X,n)&&(q=D,D=X,X=q),ge(g,N,n)&&(q=g,g=N,N=q),ge(g,D,n)&&(q=g,g=D,D=q),ge(X,N,n)&&(q=X,X=N,N=q);for(var Y=n[2*g],K=n[2*g+1],Q=n[2*X],tt=n[2*X+1],H=2*p,W=2*D,st=2*N,et=2*i,rt=2*s,U=2*o,a=0;a<2;++a){var v=n[H+a],T=n[W+a],M=n[st+a];n[et+a]=v,n[rt+a]=T,n[U+a]=M}zo(f,e,n),zo(h,t,n);for(var S=I;S<=V;++S)if(zr(S,Y,K,n))S!==I&&Ao(S,I,n),++I;else if(!zr(S,Q,tt,n))for(;;)if(zr(V,Q,tt,n)){zr(V,Y,K,n)?(R0(S,I,V,n),++I,--V):(Ao(S,V,n),--V);break}else{if(--V<S)break;continue}Lo(e,I-1,Y,K,n),Lo(t,V+1,Q,tt,n),I-2-e<=Lr?Er(e,I-2,n):Rr(e,I-2,n),t-(V+2)<=Lr?Er(V+2,t,n):Rr(V+2,t,n),V-I<=Lr?Er(I,V,n):Rr(I,V,n)}});var Gn=xt((k1,Io)=>{"use strict";Io.exports={init:O0,sweepBipartite:m0,sweepComplete:V0,scanBipartite:q0,scanComplete:N0};var Yt=Ar(),I0=rr(),Ir=Ro(),se=1<<28,Ae=1024,Jt=Yt.mallocInt32(Ae),we=Yt.mallocInt32(Ae),xe=Yt.mallocInt32(Ae),Ge=Yt.mallocInt32(Ae),Xe=Yt.mallocInt32(Ae),nr=Yt.mallocInt32(Ae),Pt=Yt.mallocDouble(Ae*8);function O0(e){var t=I0.nextPow2(e);Jt.length<t&&(Yt.free(Jt),Jt=Yt.mallocInt32(t)),we.length<t&&(Yt.free(we),we=Yt.mallocInt32(t)),xe.length<t&&(Yt.free(xe),xe=Yt.mallocInt32(t)),Ge.length<t&&(Yt.free(Ge),Ge=Yt.mallocInt32(t)),Xe.length<t&&(Yt.free(Xe),Xe=Yt.mallocInt32(t)),nr.length<t&&(Yt.free(nr),nr=Yt.mallocInt32(t));var n=8*t;Pt.length<n&&(Yt.free(Pt),Pt=Yt.mallocDouble(n))}function ke(e,t,n,r){var i=t[r],o=e[n-1];e[i]=o,t[o]=i}function Ye(e,t,n,r){e[n]=r,t[r]=n}function m0(e,t,n,r,i,o,s,f,h,p){for(var g=0,D=2*e,X=e-1,N=D-1,I=n;I<r;++I){var V=o[I],q=D*I;Pt[g++]=i[q+X],Pt[g++]=-(V+1),Pt[g++]=i[q+N],Pt[g++]=V}for(var I=s;I<f;++I){var V=p[I]+se,Y=D*I;Pt[g++]=h[Y+X],Pt[g++]=-V,Pt[g++]=h[Y+N],Pt[g++]=V}var K=g>>>1;Ir(Pt,K);for(var Q=0,tt=0,I=0;I<K;++I){var H=Pt[2*I+1]|0;if(H>=se)H=H-se|0,ke(xe,Ge,tt--,H);else if(H>=0)ke(Jt,we,Q--,H);else if(H<=-se){H=-H-se|0;for(var W=0;W<Q;++W){var st=t(Jt[W],H);if(st!==void 0)return st}Ye(xe,Ge,tt++,H)}else{H=-H-1|0;for(var W=0;W<tt;++W){var st=t(H,xe[W]);if(st!==void 0)return st}Ye(Jt,we,Q++,H)}}}function V0(e,t,n,r,i,o,s,f,h,p){for(var g=0,D=2*e,X=e-1,N=D-1,I=n;I<r;++I){var V=o[I]+1<<1,q=D*I;Pt[g++]=i[q+X],Pt[g++]=-V,Pt[g++]=i[q+N],Pt[g++]=V}for(var I=s;I<f;++I){var V=p[I]+1<<1,Y=D*I;Pt[g++]=h[Y+X],Pt[g++]=-V|1,Pt[g++]=h[Y+N],Pt[g++]=V|1}var K=g>>>1;Ir(Pt,K);for(var Q=0,tt=0,H=0,I=0;I<K;++I){var W=Pt[2*I+1]|0,st=W&1;if(I<K-1&&W>>1===Pt[2*I+3]>>1&&(st=2,I+=1),W<0){for(var et=-(W>>1)-1,rt=0;rt<H;++rt){var U=t(Xe[rt],et);if(U!==void 0)return U}if(st!==0)for(var rt=0;rt<Q;++rt){var U=t(Jt[rt],et);if(U!==void 0)return U}if(st!==1)for(var rt=0;rt<tt;++rt){var U=t(xe[rt],et);if(U!==void 0)return U}st===0?Ye(Jt,we,Q++,et):st===1?Ye(xe,Ge,tt++,et):st===2&&Ye(Xe,nr,H++,et)}else{var et=(W>>1)-1;st===0?ke(Jt,we,Q--,et):st===1?ke(xe,Ge,tt--,et):st===2&&ke(Xe,nr,H--,et)}}}function q0(e,t,n,r,i,o,s,f,h,p,g,D){var X=0,N=2*e,I=t,V=t+e,q=1,Y=1;r?Y=se:q=se;for(var K=i;K<o;++K){var Q=K+q,tt=N*K;Pt[X++]=s[tt+I],Pt[X++]=-Q,Pt[X++]=s[tt+V],Pt[X++]=Q}for(var K=h;K<p;++K){var Q=K+Y,H=N*K;Pt[X++]=g[H+I],Pt[X++]=-Q}var W=X>>>1;Ir(Pt,W);for(var st=0,K=0;K<W;++K){var et=Pt[2*K+1]|0;if(et<0){var Q=-et,rt=!1;if(Q>=se?(rt=!r,Q-=se):(rt=!!r,Q-=1),rt)Ye(Jt,we,st++,Q);else{var U=D[Q],a=N*Q,v=g[a+t+1],T=g[a+t+1+e];t:for(var M=0;M<st;++M){var S=Jt[M],L=N*S;if(!(T<s[L+t+1]||s[L+t+1+e]<v)){for(var O=t+2;O<e;++O)if(g[a+O+e]<s[L+O]||s[L+O+e]<g[a+O])continue t;var B=f[S],l;if(r?l=n(U,B):l=n(B,U),l!==void 0)return l}}}}else ke(Jt,we,st--,et-q)}}function N0(e,t,n,r,i,o,s,f,h,p,g){for(var D=0,X=2*e,N=t,I=t+e,V=r;V<i;++V){var q=V+se,Y=X*V;Pt[D++]=o[Y+N],Pt[D++]=-q,Pt[D++]=o[Y+I],Pt[D++]=q}for(var V=f;V<h;++V){var q=V+1,K=X*V;Pt[D++]=p[K+N],Pt[D++]=-q}var Q=D>>>1;Ir(Pt,Q);for(var tt=0,V=0;V<Q;++V){var H=Pt[2*V+1]|0;if(H<0){var q=-H;if(q>=se)Jt[tt++]=q-se;else{q-=1;var W=g[q],st=X*q,et=p[st+t+1],rt=p[st+t+1+e];t:for(var U=0;U<tt;++U){var a=Jt[U],v=s[a];if(v===W)break;var T=X*a;if(!(rt<o[T+t+1]||o[T+t+1+e]<et)){for(var M=t+2;M<e;++M)if(p[st+M+e]<o[T+M]||o[T+M+e]<p[st+M])continue t;var S=n(v,W);if(S!==void 0)return S}}}}else{for(var q=H-se,U=tt-1;U>=0;--U)if(Jt[U]===q){for(var M=U+1;M<tt;++M)Jt[M-1]=Jt[M];break}--tt}}}});var No=xt(On=>{"use strict";var ze="d",$e="ax",Oo="vv",An="fp",ir="es",Or="rs",Rn="re",or="rb",mo="ri",He="rp",mr="bs",In="be",ar="bb",Vo="bi",Ze="bp",zn="rv",Ln="Q",En=[ze,$e,Oo,Or,Rn,or,mo,mr,In,ar,Vo];function C0(e,t,n){var r="bruteForce"+(e?"Red":"Blue")+(t?"Flip":"")+(n?"Full":""),i=["function ",r,"(",En.join(),"){","var ",ir,"=2*",ze,";"],o="for(var i="+Or+","+He+"="+ir+"*"+Or+";i<"+Rn+";++i,"+He+"+="+ir+"){var x0="+or+"["+$e+"+"+He+"],x1="+or+"["+$e+"+"+He+"+"+ze+"],xi="+mo+"[i];",s="for(var j="+mr+","+Ze+"="+ir+"*"+mr+";j<"+In+";++j,"+Ze+"+="+ir+"){var y0="+ar+"["+$e+"+"+Ze+"],"+(n?"y1="+ar+"["+$e+"+"+Ze+"+"+ze+"],":"")+"yi="+Vo+"[j];";return e?i.push(o,Ln,":",s):i.push(s,Ln,":",o),n?i.push("if(y1<x0||x1<y0)continue;"):t?i.push("if(y0<=x0||x1<y0)continue;"):i.push("if(y0<x0||x1<y0)continue;"),i.push("for(var k="+$e+"+1;k<"+ze+";++k){var r0="+or+"[k+"+He+"],r1="+or+"[k+"+ze+"+"+He+"],b0="+ar+"[k+"+Ze+"],b1="+ar+"[k+"+ze+"+"+Ze+"];if(r1<b0||b1<r0)continue "+Ln+";}var "+zn+"="+Oo+"("),t?i.push("yi,xi"):i.push("xi,yi"),i.push(");if("+zn+"!==void 0)return "+zn+";}}}"),{name:r,code:i.join("")}}function qo(e){var t="bruteForce"+(e?"Full":"Partial"),n=[],r=En.slice();e||r.splice(3,0,An);var i=["function "+t+"("+r.join()+"){"];function o(h,p){var g=C0(h,p,e);n.push(g.code),i.push("return "+g.name+"("+En.join()+");")}i.push("if("+Rn+"-"+Or+">"+In+"-"+mr+"){"),e?(o(!0,!1),i.push("}else{"),o(!1,!1)):(i.push("if("+An+"){"),o(!0,!0),i.push("}else{"),o(!0,!1),i.push("}}else{if("+An+"){"),o(!1,!0),i.push("}else{"),o(!1,!1),i.push("}")),i.push("}}return "+t);var s=n.join("")+i.join(""),f=new Function(s);return f()}On.partial=qo(!1);On.full=qo(!0)});var mn=xt((H1,Co)=>{"use strict";Co.exports=k0;var X0="for(var j=2*a,k=j*c,l=k,m=c,n=b,o=a+b,p=c;d>p;++p,k+=j){var _;if($)if(m===p)m+=1,l+=j;else{for(var s=0;j>s;++s){var t=e[k+s];e[k+s]=e[l],e[l++]=t}var u=f[p];f[p]=f[m],f[m++]=u}}return m";function k0(e,t){var n="abcdef".split("").concat(t),r=[];return e.indexOf("lo")>=0&&r.push("lo=e[k+n]"),e.indexOf("hi")>=0&&r.push("hi=e[k+o]"),n.push(X0.replace("_",r.join()).replace("$",e)),Function.apply(void 0,n)}});var Yo=xt((Z1,ko)=>{"use strict";ko.exports=$0;var Y0=mn(),Xo=Y0("lo<p0",["p0"]),H0=8;function Z0(e,t,n,r,i,o){for(var s=2*e,f=s*(n+1)+t,h=n+1;h<r;++h,f+=s)for(var p=i[f],g=h,D=s*(h-1);g>n&&i[D+t]>p;--g,D-=s){for(var X=D,N=D+s,I=0;I<s;++I,++X,++N){var V=i[X];i[X]=i[N],i[N]=V}var q=o[g];o[g]=o[g-1],o[g-1]=q}}function $0(e,t,n,r,i,o){if(r<=n+1)return n;for(var s=n,f=r,h=r+n>>>1,p=2*e,g=h,D=i[p*h+t];s<f;){if(f-s<H0){Z0(e,t,s,f,i,o),D=i[p*h+t];break}var X=f-s,N=Math.random()*X+s|0,I=i[p*N+t],V=Math.random()*X+s|0,q=i[p*V+t],Y=Math.random()*X+s|0,K=i[p*Y+t];I<=q?K>=q?(g=V,D=q):I>=K?(g=N,D=I):(g=Y,D=K):q>=K?(g=V,D=q):K>=I?(g=N,D=I):(g=Y,D=K);for(var H=p*(f-1),W=p*g,Q=0;Q<p;++Q,++H,++W){var tt=i[H];i[H]=i[W],i[W]=tt}var st=o[f-1];o[f-1]=o[g],o[g]=st,g=Xo(e,t,s,f-1,i,o,D);for(var H=p*(f-1),W=p*g,Q=0;Q<p;++Q,++H,++W){var tt=i[H];i[H]=i[W],i[W]=tt}var st=o[f-1];if(o[f-1]=o[g],o[g]=st,h<g){for(f=g-1;s<f&&i[p*(f-1)+t]===D;)f-=1;f+=1}else if(g<h)for(s=g+1;s<f&&i[p*s+t]===D;)s+=1;else break}return Xo(e,t,n,h,i,o,i[p*h+t])}});var Jo=xt(($1,Qo)=>{"use strict";Qo.exports=uf;var We=Ar(),Vn=rr(),Wo=No(),W0=Wo.partial,K0=Wo.full,Te=Gn(),Q0=Yo(),Ke=mn(),Ho=128,J0=1<<22,j0=1<<22,tf=Ke("!(lo>=p0)&&!(p1>=hi)",["p0","p1"]),Zo=Ke("lo===p0",["p0"]),ef=Ke("lo<p0",["p0"]),rf=Ke("hi<=p0",["p0"]),$o=Ke("lo<=p0&&p0<=hi",["p0"]),nf=Ke("lo<p0&&p0<=hi",["p0"]),qn=6,Nn=2,Ko=1024,ee=We.mallocInt32(Ko),Le=We.mallocDouble(Ko);function of(e,t){var n=8*Vn.log2(t+1)*(e+1)|0,r=Vn.nextPow2(qn*n);ee.length<r&&(We.free(ee),ee=We.mallocInt32(r));var i=Vn.nextPow2(Nn*n);Le.length<i&&(We.free(Le),Le=We.mallocDouble(i))}function ce(e,t,n,r,i,o,s,f,h){var p=qn*e;ee[p]=t,ee[p+1]=n,ee[p+2]=r,ee[p+3]=i,ee[p+4]=o,ee[p+5]=s;var g=Nn*e;Le[g]=f,Le[g+1]=h}function af(e,t,n,r,i,o,s,f,h,p,g){var D=2*e,X=h*D,N=p[X+t];t:for(var I=i,V=i*D;I<o;++I,V+=D){var q=s[V+t],Y=s[V+t+e];if(!(N<q||Y<N)&&!(r&&N===q)){for(var K=f[I],Q=t+1;Q<e;++Q){var q=s[V+Q],Y=s[V+Q+e],tt=p[X+Q],H=p[X+Q+e];if(Y<tt||H<q)continue t}var W;if(r?W=n(g,K):W=n(K,g),W!==void 0)return W}}}function sf(e,t,n,r,i,o,s,f,h,p){var g=2*e,D=f*g,X=h[D+t];t:for(var N=r,I=r*g;N<i;++N,I+=g){var V=s[N];if(V!==p){var q=o[I+t],Y=o[I+t+e];if(!(X<q||Y<X)){for(var K=t+1;K<e;++K){var q=o[I+K],Y=o[I+K+e],Q=h[D+K],tt=h[D+K+e];if(Y<Q||tt<q)continue t}var H=n(V,p);if(H!==void 0)return H}}}}function uf(e,t,n,r,i,o,s,f,h){of(e,r+s);var p=0,g=2*e,D;for(ce(p++,0,0,r,0,s,n?16:0,-1/0,1/0),n||ce(p++,0,0,s,0,r,1,-1/0,1/0);p>0;){p-=1;var X=p*qn,N=ee[X],I=ee[X+1],V=ee[X+2],q=ee[X+3],Y=ee[X+4],K=ee[X+5],Q=p*Nn,tt=Le[Q],H=Le[Q+1],W=K&1,st=!!(K&16),et=i,rt=o,U=f,a=h;if(W&&(et=f,rt=h,U=i,a=o),!(K&2&&(V=ef(e,N,I,V,et,rt,H),I>=V))&&!(K&4&&(I=rf(e,N,I,V,et,rt,tt),I>=V))){var v=V-I,T=Y-q;if(st){if(e*v*(v+T)<j0){if(D=Te.scanComplete(e,N,t,I,V,et,rt,q,Y,U,a),D!==void 0)return D;continue}}else if(e*Math.min(v,T)<Ho){if(D=W0(e,N,t,W,I,V,et,rt,q,Y,U,a),D!==void 0)return D;continue}else if(e*v*T<J0){if(D=Te.scanBipartite(e,N,t,W,I,V,et,rt,q,Y,U,a),D!==void 0)return D;continue}var M=tf(e,N,I,V,et,rt,tt,H);if(I<M)if(e*(M-I)<Ho){if(D=K0(e,N+1,t,I,M,et,rt,q,Y,U,a),D!==void 0)return D}else if(N===e-2){if(W?D=Te.sweepBipartite(e,t,q,Y,U,a,I,M,et,rt):D=Te.sweepBipartite(e,t,I,M,et,rt,q,Y,U,a),D!==void 0)return D}else ce(p++,N+1,I,M,q,Y,W,-1/0,1/0),ce(p++,N+1,q,Y,I,M,W^1,-1/0,1/0);if(M<V){var S=Q0(e,N,q,Y,U,a),L=U[g*S+N],O=Zo(e,N,S,Y,U,a,L);if(O<Y&&ce(p++,N,M,V,O,Y,(W|4)+(st?16:0),L,H),q<S&&ce(p++,N,M,V,q,S,(W|2)+(st?16:0),tt,L),S+1===O){if(st?D=sf(e,N,t,M,V,et,rt,S,U,a[S]):D=af(e,N,t,W,M,V,et,rt,S,U,a[S]),D!==void 0)return D}else if(S<O){var B;if(st){if(B=$o(e,N,M,V,et,rt,L),M<B){var l=Zo(e,N,M,B,et,rt,L);if(N===e-2){if(M<l&&(D=Te.sweepComplete(e,t,M,l,et,rt,S,O,U,a),D!==void 0)||l<B&&(D=Te.sweepBipartite(e,t,l,B,et,rt,S,O,U,a),D!==void 0))return D}else M<l&&ce(p++,N+1,M,l,S,O,16,-1/0,1/0),l<B&&(ce(p++,N+1,l,B,S,O,0,-1/0,1/0),ce(p++,N+1,S,O,l,B,1,-1/0,1/0))}}else W?B=nf(e,N,M,V,et,rt,L):B=$o(e,N,M,V,et,rt,L),M<B&&(N===e-2?W?D=Te.sweepBipartite(e,t,S,O,U,a,M,B,et,rt):D=Te.sweepBipartite(e,t,M,B,et,rt,S,O,U,a):(ce(p++,N+1,M,B,S,O,W,-1/0,1/0),ce(p++,N+1,S,O,M,B,W^1,-1/0,1/0)))}}}}}});var ra=xt((W1,ea)=>{"use strict";ea.exports=pf;var Pe=Ar(),Vr=Gn(),ff=Jo();function cf(e,t){for(var n=0;n<e;++n)if(!(t[n]<=t[n+e]))return!0;return!1}function jo(e,t,n,r){for(var i=0,o=0,s=0,f=e.length;s<f;++s){var h=e[s];if(!cf(t,h)){for(var p=0;p<2*t;++p)n[i++]=h[p];r[o++]=s}}return o}function qr(e,t,n,r){var i=e.length,o=t.length;if(!(i<=0||o<=0)){var s=e[0].length>>>1;if(!(s<=0)){var f,h=Pe.mallocDouble(2*s*i),p=Pe.mallocInt32(i);if(i=jo(e,s,h,p),i>0){if(s===1&&r)Vr.init(i),f=Vr.sweepComplete(s,n,0,i,h,p,0,i,h,p);else{var g=Pe.mallocDouble(2*s*o),D=Pe.mallocInt32(o);o=jo(t,s,g,D),o>0&&(Vr.init(i+o),s===1?f=Vr.sweepBipartite(s,n,0,i,h,p,0,o,g,D):f=ff(s,n,r,i,h,p,o,g,D),Pe.free(g),Pe.free(D))}Pe.free(h),Pe.free(p)}return f}}}var sr;function ta(e,t){sr.push([e,t])}function lf(e){return sr=[],qr(e,e,ta,!0),sr}function hf(e,t){return sr=[],qr(e,t,ta,!1),sr}function pf(e,t,n){var r;switch(arguments.length){case 1:return lf(e);case 2:return typeof t=="function"?qr(e,e,t,!0):hf(e,t);case 3:return qr(e,t,n,!1);default:throw new Error("box-intersect: Invalid arguments")}}});var ia=xt((K1,na)=>{"use strict";na.exports=df;var Nr=bn()[3];function vf(e,t,n,r){for(var i=0;i<2;++i){var o=e[i],s=t[i],f=Math.min(o,s),h=Math.max(o,s),p=n[i],g=r[i],D=Math.min(p,g),X=Math.max(p,g);if(X<f||h<D)return!1}return!0}function df(e,t,n,r){var i=Nr(e,n,r),o=Nr(t,n,r);if(i>0&&o>0||i<0&&o<0)return!1;var s=Nr(n,e,t),f=Nr(r,e,t);return s>0&&f>0||s<0&&f<0?!1:i===0&&o===0&&s===0&&f===0?vf(e,t,n,r):!0}});var oa=xt(()=>{});var ur=xt((aa,Cn)=>{(function(e,t){"use strict";function n(U,a){if(!U)throw new Error(a||"Assertion failed")}function r(U,a){U.super_=a;var v=function(){};v.prototype=a.prototype,U.prototype=new v,U.prototype.constructor=U}function i(U,a,v){if(i.isBN(U))return U;this.negative=0,this.words=null,this.length=0,this.red=null,U!==null&&((a==="le"||a==="be")&&(v=a,a=10),this._init(U||0,a||10,v||"be"))}typeof e=="object"?e.exports=i:t.BN=i,i.BN=i,i.wordSize=26;var o;try{typeof window<"u"&&typeof window.Buffer<"u"?o=window.Buffer:o=oa().Buffer}catch{}i.isBN=function(a){return a instanceof i?!0:a!==null&&typeof a=="object"&&a.constructor.wordSize===i.wordSize&&Array.isArray(a.words)},i.max=function(a,v){return a.cmp(v)>0?a:v},i.min=function(a,v){return a.cmp(v)<0?a:v},i.prototype._init=function(a,v,T){if(typeof a=="number")return this._initNumber(a,v,T);if(typeof a=="object")return this._initArray(a,v,T);v==="hex"&&(v=16),n(v===(v|0)&&v>=2&&v<=36),a=a.toString().replace(/\s+/g,"");var M=0;a[0]==="-"&&(M++,this.negative=1),M<a.length&&(v===16?this._parseHex(a,M,T):(this._parseBase(a,v,M),T==="le"&&this._initArray(this.toArray(),v,T)))},i.prototype._initNumber=function(a,v,T){a<0&&(this.negative=1,a=-a),a<67108864?(this.words=[a&67108863],this.length=1):a<4503599627370496?(this.words=[a&67108863,a/67108864&67108863],this.length=2):(n(a<9007199254740992),this.words=[a&67108863,a/67108864&67108863,1],this.length=3),T==="le"&&this._initArray(this.toArray(),v,T)},i.prototype._initArray=function(a,v,T){if(n(typeof a.length=="number"),a.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(a.length/3),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var S,L,O=0;if(T==="be")for(M=a.length-1,S=0;M>=0;M-=3)L=a[M]|a[M-1]<<8|a[M-2]<<16,this.words[S]|=L<<O&67108863,this.words[S+1]=L>>>26-O&67108863,O+=24,O>=26&&(O-=26,S++);else if(T==="le")for(M=0,S=0;M<a.length;M+=3)L=a[M]|a[M+1]<<8|a[M+2]<<16,this.words[S]|=L<<O&67108863,this.words[S+1]=L>>>26-O&67108863,O+=24,O>=26&&(O-=26,S++);return this.strip()};function s(U,a){var v=U.charCodeAt(a);return v>=65&&v<=70?v-55:v>=97&&v<=102?v-87:v-48&15}function f(U,a,v){var T=s(U,v);return v-1>=a&&(T|=s(U,v-1)<<4),T}i.prototype._parseHex=function(a,v,T){this.length=Math.ceil((a.length-v)/6),this.words=new Array(this.length);for(var M=0;M<this.length;M++)this.words[M]=0;var S=0,L=0,O;if(T==="be")for(M=a.length-1;M>=v;M-=2)O=f(a,v,M)<<S,this.words[L]|=O&67108863,S>=18?(S-=18,L+=1,this.words[L]|=O>>>26):S+=8;else{var B=a.length-v;for(M=B%2===0?v+1:v;M<a.length;M+=2)O=f(a,v,M)<<S,this.words[L]|=O&67108863,S>=18?(S-=18,L+=1,this.words[L]|=O>>>26):S+=8}this.strip()};function h(U,a,v,T){for(var M=0,S=Math.min(U.length,v),L=a;L<S;L++){var O=U.charCodeAt(L)-48;M*=T,O>=49?M+=O-49+10:O>=17?M+=O-17+10:M+=O}return M}i.prototype._parseBase=function(a,v,T){this.words=[0],this.length=1;for(var M=0,S=1;S<=67108863;S*=v)M++;M--,S=S/v|0;for(var L=a.length-T,O=L%M,B=Math.min(L,L-O)+T,l=0,G=T;G<B;G+=M)l=h(a,G,G+M,v),this.imuln(S),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l);if(O!==0){var ot=1;for(l=h(a,G,a.length,v),G=0;G<O;G++)ot*=v;this.imuln(ot),this.words[0]+l<67108864?this.words[0]+=l:this._iaddn(l)}this.strip()},i.prototype.copy=function(a){a.words=new Array(this.length);for(var v=0;v<this.length;v++)a.words[v]=this.words[v];a.length=this.length,a.negative=this.negative,a.red=this.red},i.prototype.clone=function(){var a=new i(null);return this.copy(a),a},i.prototype._expand=function(a){for(;this.length<a;)this.words[this.length++]=0;return this},i.prototype.strip=function(){for(;this.length>1&&this.words[this.length-1]===0;)this.length--;return this._normSign()},i.prototype._normSign=function(){return this.length===1&&this.words[0]===0&&(this.negative=0),this},i.prototype.inspect=function(){return(this.red?"<BN-R: ":"<BN: ")+this.toString(16)+">"};var p=["","0","00","000","0000","00000","000000","0000000","00000000","000000000","0000000000","00000000000","000000000000","0000000000000","00000000000000","000000000000000","0000000000000000","00000000000000000","000000000000000000","0000000000000000000","00000000000000000000","000000000000000000000","0000000000000000000000","00000000000000000000000","000000000000000000000000","0000000000000000000000000"],g=[0,0,25,16,12,11,10,9,8,8,7,7,7,7,6,6,6,6,6,6,6,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5,5],D=[0,0,33554432,43046721,16777216,48828125,60466176,40353607,16777216,43046721,1e7,19487171,35831808,62748517,7529536,11390625,16777216,24137569,34012224,47045881,64e6,4084101,5153632,6436343,7962624,9765625,11881376,14348907,17210368,20511149,243e5,28629151,33554432,39135393,45435424,52521875,60466176];i.prototype.toString=function(a,v){a=a||10,v=v|0||1;var T;if(a===16||a==="hex"){T="";for(var M=0,S=0,L=0;L<this.length;L++){var O=this.words[L],B=((O<<M|S)&16777215).toString(16);S=O>>>24-M&16777215,M+=2,M>=26&&(M-=26,L--),S!==0||L!==this.length-1?T=p[6-B.length]+B+T:T=B+T}for(S!==0&&(T=S.toString(16)+T);T.length%v!==0;)T="0"+T;return this.negative!==0&&(T="-"+T),T}if(a===(a|0)&&a>=2&&a<=36){var l=g[a],G=D[a];T="";var ot=this.clone();for(ot.negative=0;!ot.isZero();){var at=ot.modn(G).toString(a);ot=ot.idivn(G),ot.isZero()?T=at+T:T=p[l-at.length]+at+T}for(this.isZero()&&(T="0"+T);T.length%v!==0;)T="0"+T;return this.negative!==0&&(T="-"+T),T}n(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var a=this.words[0];return this.length===2?a+=this.words[1]*67108864:this.length===3&&this.words[2]===1?a+=4503599627370496+this.words[1]*67108864:this.length>2&&n(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-a:a},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(a,v){return n(typeof o<"u"),this.toArrayLike(o,a,v)},i.prototype.toArray=function(a,v){return this.toArrayLike(Array,a,v)},i.prototype.toArrayLike=function(a,v,T){var M=this.byteLength(),S=T||Math.max(1,M);n(M<=S,"byte array longer than desired length"),n(S>0,"Requested array length <= 0"),this.strip();var L=v==="le",O=new a(S),B,l,G=this.clone();if(L){for(l=0;!G.isZero();l++)B=G.andln(255),G.iushrn(8),O[l]=B;for(;l<S;l++)O[l]=0}else{for(l=0;l<S-M;l++)O[l]=0;for(l=0;!G.isZero();l++)B=G.andln(255),G.iushrn(8),O[S-l-1]=B}return O},Math.clz32?i.prototype._countBits=function(a){return 32-Math.clz32(a)}:i.prototype._countBits=function(a){var v=a,T=0;return v>=4096&&(T+=13,v>>>=13),v>=64&&(T+=7,v>>>=7),v>=8&&(T+=4,v>>>=4),v>=2&&(T+=2,v>>>=2),T+v},i.prototype._zeroBits=function(a){if(a===0)return 26;var v=a,T=0;return(v&8191)===0&&(T+=13,v>>>=13),(v&127)===0&&(T+=7,v>>>=7),(v&15)===0&&(T+=4,v>>>=4),(v&3)===0&&(T+=2,v>>>=2),(v&1)===0&&T++,T},i.prototype.bitLength=function(){var a=this.words[this.length-1],v=this._countBits(a);return(this.length-1)*26+v};function X(U){for(var a=new Array(U.bitLength()),v=0;v<a.length;v++){var T=v/26|0,M=v%26;a[v]=(U.words[T]&1<<M)>>>M}return a}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var a=0,v=0;v<this.length;v++){var T=this._zeroBits(this.words[v]);if(a+=T,T!==26)break}return a},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(a){return this.negative!==0?this.abs().inotn(a).iaddn(1):this.clone()},i.prototype.fromTwos=function(a){return this.testn(a-1)?this.notn(a).iaddn(1).ineg():this.clone()},i.prototype.isNeg=function(){return this.negative!==0},i.prototype.neg=function(){return this.clone().ineg()},i.prototype.ineg=function(){return this.isZero()||(this.negative^=1),this},i.prototype.iuor=function(a){for(;this.length<a.length;)this.words[this.length++]=0;for(var v=0;v<a.length;v++)this.words[v]=this.words[v]|a.words[v];return this.strip()},i.prototype.ior=function(a){return n((this.negative|a.negative)===0),this.iuor(a)},i.prototype.or=function(a){return this.length>a.length?this.clone().ior(a):a.clone().ior(this)},i.prototype.uor=function(a){return this.length>a.length?this.clone().iuor(a):a.clone().iuor(this)},i.prototype.iuand=function(a){var v;this.length>a.length?v=a:v=this;for(var T=0;T<v.length;T++)this.words[T]=this.words[T]&a.words[T];return this.length=v.length,this.strip()},i.prototype.iand=function(a){return n((this.negative|a.negative)===0),this.iuand(a)},i.prototype.and=function(a){return this.length>a.length?this.clone().iand(a):a.clone().iand(this)},i.prototype.uand=function(a){return this.length>a.length?this.clone().iuand(a):a.clone().iuand(this)},i.prototype.iuxor=function(a){var v,T;this.length>a.length?(v=this,T=a):(v=a,T=this);for(var M=0;M<T.length;M++)this.words[M]=v.words[M]^T.words[M];if(this!==v)for(;M<v.length;M++)this.words[M]=v.words[M];return this.length=v.length,this.strip()},i.prototype.ixor=function(a){return n((this.negative|a.negative)===0),this.iuxor(a)},i.prototype.xor=function(a){return this.length>a.length?this.clone().ixor(a):a.clone().ixor(this)},i.prototype.uxor=function(a){return this.length>a.length?this.clone().iuxor(a):a.clone().iuxor(this)},i.prototype.inotn=function(a){n(typeof a=="number"&&a>=0);var v=Math.ceil(a/26)|0,T=a%26;this._expand(v),T>0&&v--;for(var M=0;M<v;M++)this.words[M]=~this.words[M]&67108863;return T>0&&(this.words[M]=~this.words[M]&67108863>>26-T),this.strip()},i.prototype.notn=function(a){return this.clone().inotn(a)},i.prototype.setn=function(a,v){n(typeof a=="number"&&a>=0);var T=a/26|0,M=a%26;return this._expand(T+1),v?this.words[T]=this.words[T]|1<<M:this.words[T]=this.words[T]&~(1<<M),this.strip()},i.prototype.iadd=function(a){var v;if(this.negative!==0&&a.negative===0)return this.negative=0,v=this.isub(a),this.negative^=1,this._normSign();if(this.negative===0&&a.negative!==0)return a.negative=0,v=this.isub(a),a.negative=1,v._normSign();var T,M;this.length>a.length?(T=this,M=a):(T=a,M=this);for(var S=0,L=0;L<M.length;L++)v=(T.words[L]|0)+(M.words[L]|0)+S,this.words[L]=v&67108863,S=v>>>26;for(;S!==0&&L<T.length;L++)v=(T.words[L]|0)+S,this.words[L]=v&67108863,S=v>>>26;if(this.length=T.length,S!==0)this.words[this.length]=S,this.length++;else if(T!==this)for(;L<T.length;L++)this.words[L]=T.words[L];return this},i.prototype.add=function(a){var v;return a.negative!==0&&this.negative===0?(a.negative=0,v=this.sub(a),a.negative^=1,v):a.negative===0&&this.negative!==0?(this.negative=0,v=a.sub(this),this.negative=1,v):this.length>a.length?this.clone().iadd(a):a.clone().iadd(this)},i.prototype.isub=function(a){if(a.negative!==0){a.negative=0;var v=this.iadd(a);return a.negative=1,v._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(a),this.negative=1,this._normSign();var T=this.cmp(a);if(T===0)return this.negative=0,this.length=1,this.words[0]=0,this;var M,S;T>0?(M=this,S=a):(M=a,S=this);for(var L=0,O=0;O<S.length;O++)v=(M.words[O]|0)-(S.words[O]|0)+L,L=v>>26,this.words[O]=v&67108863;for(;L!==0&&O<M.length;O++)v=(M.words[O]|0)+L,L=v>>26,this.words[O]=v&67108863;if(L===0&&O<M.length&&M!==this)for(;O<M.length;O++)this.words[O]=M.words[O];return this.length=Math.max(this.length,O),M!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(a){return this.clone().isub(a)};function N(U,a,v){v.negative=a.negative^U.negative;var T=U.length+a.length|0;v.length=T,T=T-1|0;var M=U.words[0]|0,S=a.words[0]|0,L=M*S,O=L&67108863,B=L/67108864|0;v.words[0]=O;for(var l=1;l<T;l++){for(var G=B>>>26,ot=B&67108863,at=Math.min(l,a.length-1),ut=Math.max(0,l-U.length+1);ut<=at;ut++){var ft=l-ut|0;M=U.words[ft]|0,S=a.words[ut]|0,L=M*S+ot,G+=L/67108864|0,ot=L&67108863}v.words[l]=ot|0,B=G|0}return B!==0?v.words[l]=B|0:v.length--,v.strip()}var I=function(a,v,T){var M=a.words,S=v.words,L=T.words,O=0,B,l,G,ot=M[0]|0,at=ot&8191,ut=ot>>>13,ft=M[1]|0,yt=ft&8191,pt=ft>>>13,k=M[2]|0,$=k&8191,F=k>>>13,c=M[3]|0,b=c&8191,w=c>>>13,z=M[4]|0,R=z&8191,m=z>>>13,C=M[5]|0,u=C&8191,_=C>>>13,x=M[6]|0,y=x&8191,d=x>>>13,P=M[7]|0,E=P&8191,A=P>>>13,Z=M[8]|0,J=Z&8191,j=Z>>>13,ct=M[9]|0,nt=ct&8191,it=ct>>>13,vt=S[0]|0,ht=vt&8191,lt=vt>>>13,dt=S[1]|0,wt=dt&8191,gt=dt>>>13,Ct=S[2]|0,Mt=Ct&8191,bt=Ct>>>13,Ht=S[3]|0,St=Ht&8191,_t=Ht>>>13,$t=S[4]|0,Bt=$t&8191,Dt=$t>>>13,Wt=S[5]|0,Ut=Wt&8191,Ft=Wt>>>13,Kt=S[6]|0,Gt=Kt&8191,At=Kt>>>13,jt=S[7]|0,Rt=jt&8191,It=jt>>>13,Se=S[8]|0,Ot=Se&8191,mt=Se>>>13,_e=S[9]|0,Vt=_e&8191,Nt=_e>>>13;T.negative=a.negative^v.negative,T.length=19,B=Math.imul(at,ht),l=Math.imul(at,lt),l=l+Math.imul(ut,ht)|0,G=Math.imul(ut,lt);var me=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(me>>>26)|0,me&=67108863,B=Math.imul(yt,ht),l=Math.imul(yt,lt),l=l+Math.imul(pt,ht)|0,G=Math.imul(pt,lt),B=B+Math.imul(at,wt)|0,l=l+Math.imul(at,gt)|0,l=l+Math.imul(ut,wt)|0,G=G+Math.imul(ut,gt)|0;var Ve=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Ve>>>26)|0,Ve&=67108863,B=Math.imul($,ht),l=Math.imul($,lt),l=l+Math.imul(F,ht)|0,G=Math.imul(F,lt),B=B+Math.imul(yt,wt)|0,l=l+Math.imul(yt,gt)|0,l=l+Math.imul(pt,wt)|0,G=G+Math.imul(pt,gt)|0,B=B+Math.imul(at,Mt)|0,l=l+Math.imul(at,bt)|0,l=l+Math.imul(ut,Mt)|0,G=G+Math.imul(ut,bt)|0;var qe=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(qe>>>26)|0,qe&=67108863,B=Math.imul(b,ht),l=Math.imul(b,lt),l=l+Math.imul(w,ht)|0,G=Math.imul(w,lt),B=B+Math.imul($,wt)|0,l=l+Math.imul($,gt)|0,l=l+Math.imul(F,wt)|0,G=G+Math.imul(F,gt)|0,B=B+Math.imul(yt,Mt)|0,l=l+Math.imul(yt,bt)|0,l=l+Math.imul(pt,Mt)|0,G=G+Math.imul(pt,bt)|0,B=B+Math.imul(at,St)|0,l=l+Math.imul(at,_t)|0,l=l+Math.imul(ut,St)|0,G=G+Math.imul(ut,_t)|0;var Zt=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Zt>>>26)|0,Zt&=67108863,B=Math.imul(R,ht),l=Math.imul(R,lt),l=l+Math.imul(m,ht)|0,G=Math.imul(m,lt),B=B+Math.imul(b,wt)|0,l=l+Math.imul(b,gt)|0,l=l+Math.imul(w,wt)|0,G=G+Math.imul(w,gt)|0,B=B+Math.imul($,Mt)|0,l=l+Math.imul($,bt)|0,l=l+Math.imul(F,Mt)|0,G=G+Math.imul(F,bt)|0,B=B+Math.imul(yt,St)|0,l=l+Math.imul(yt,_t)|0,l=l+Math.imul(pt,St)|0,G=G+Math.imul(pt,_t)|0,B=B+Math.imul(at,Bt)|0,l=l+Math.imul(at,Dt)|0,l=l+Math.imul(ut,Bt)|0,G=G+Math.imul(ut,Dt)|0;var Wr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,B=Math.imul(u,ht),l=Math.imul(u,lt),l=l+Math.imul(_,ht)|0,G=Math.imul(_,lt),B=B+Math.imul(R,wt)|0,l=l+Math.imul(R,gt)|0,l=l+Math.imul(m,wt)|0,G=G+Math.imul(m,gt)|0,B=B+Math.imul(b,Mt)|0,l=l+Math.imul(b,bt)|0,l=l+Math.imul(w,Mt)|0,G=G+Math.imul(w,bt)|0,B=B+Math.imul($,St)|0,l=l+Math.imul($,_t)|0,l=l+Math.imul(F,St)|0,G=G+Math.imul(F,_t)|0,B=B+Math.imul(yt,Bt)|0,l=l+Math.imul(yt,Dt)|0,l=l+Math.imul(pt,Bt)|0,G=G+Math.imul(pt,Dt)|0,B=B+Math.imul(at,Ut)|0,l=l+Math.imul(at,Ft)|0,l=l+Math.imul(ut,Ut)|0,G=G+Math.imul(ut,Ft)|0;var Kr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,B=Math.imul(y,ht),l=Math.imul(y,lt),l=l+Math.imul(d,ht)|0,G=Math.imul(d,lt),B=B+Math.imul(u,wt)|0,l=l+Math.imul(u,gt)|0,l=l+Math.imul(_,wt)|0,G=G+Math.imul(_,gt)|0,B=B+Math.imul(R,Mt)|0,l=l+Math.imul(R,bt)|0,l=l+Math.imul(m,Mt)|0,G=G+Math.imul(m,bt)|0,B=B+Math.imul(b,St)|0,l=l+Math.imul(b,_t)|0,l=l+Math.imul(w,St)|0,G=G+Math.imul(w,_t)|0,B=B+Math.imul($,Bt)|0,l=l+Math.imul($,Dt)|0,l=l+Math.imul(F,Bt)|0,G=G+Math.imul(F,Dt)|0,B=B+Math.imul(yt,Ut)|0,l=l+Math.imul(yt,Ft)|0,l=l+Math.imul(pt,Ut)|0,G=G+Math.imul(pt,Ft)|0,B=B+Math.imul(at,Gt)|0,l=l+Math.imul(at,At)|0,l=l+Math.imul(ut,Gt)|0,G=G+Math.imul(ut,At)|0;var Qr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,B=Math.imul(E,ht),l=Math.imul(E,lt),l=l+Math.imul(A,ht)|0,G=Math.imul(A,lt),B=B+Math.imul(y,wt)|0,l=l+Math.imul(y,gt)|0,l=l+Math.imul(d,wt)|0,G=G+Math.imul(d,gt)|0,B=B+Math.imul(u,Mt)|0,l=l+Math.imul(u,bt)|0,l=l+Math.imul(_,Mt)|0,G=G+Math.imul(_,bt)|0,B=B+Math.imul(R,St)|0,l=l+Math.imul(R,_t)|0,l=l+Math.imul(m,St)|0,G=G+Math.imul(m,_t)|0,B=B+Math.imul(b,Bt)|0,l=l+Math.imul(b,Dt)|0,l=l+Math.imul(w,Bt)|0,G=G+Math.imul(w,Dt)|0,B=B+Math.imul($,Ut)|0,l=l+Math.imul($,Ft)|0,l=l+Math.imul(F,Ut)|0,G=G+Math.imul(F,Ft)|0,B=B+Math.imul(yt,Gt)|0,l=l+Math.imul(yt,At)|0,l=l+Math.imul(pt,Gt)|0,G=G+Math.imul(pt,At)|0,B=B+Math.imul(at,Rt)|0,l=l+Math.imul(at,It)|0,l=l+Math.imul(ut,Rt)|0,G=G+Math.imul(ut,It)|0;var Jr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,B=Math.imul(J,ht),l=Math.imul(J,lt),l=l+Math.imul(j,ht)|0,G=Math.imul(j,lt),B=B+Math.imul(E,wt)|0,l=l+Math.imul(E,gt)|0,l=l+Math.imul(A,wt)|0,G=G+Math.imul(A,gt)|0,B=B+Math.imul(y,Mt)|0,l=l+Math.imul(y,bt)|0,l=l+Math.imul(d,Mt)|0,G=G+Math.imul(d,bt)|0,B=B+Math.imul(u,St)|0,l=l+Math.imul(u,_t)|0,l=l+Math.imul(_,St)|0,G=G+Math.imul(_,_t)|0,B=B+Math.imul(R,Bt)|0,l=l+Math.imul(R,Dt)|0,l=l+Math.imul(m,Bt)|0,G=G+Math.imul(m,Dt)|0,B=B+Math.imul(b,Ut)|0,l=l+Math.imul(b,Ft)|0,l=l+Math.imul(w,Ut)|0,G=G+Math.imul(w,Ft)|0,B=B+Math.imul($,Gt)|0,l=l+Math.imul($,At)|0,l=l+Math.imul(F,Gt)|0,G=G+Math.imul(F,At)|0,B=B+Math.imul(yt,Rt)|0,l=l+Math.imul(yt,It)|0,l=l+Math.imul(pt,Rt)|0,G=G+Math.imul(pt,It)|0,B=B+Math.imul(at,Ot)|0,l=l+Math.imul(at,mt)|0,l=l+Math.imul(ut,Ot)|0,G=G+Math.imul(ut,mt)|0;var jr=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(jr>>>26)|0,jr&=67108863,B=Math.imul(nt,ht),l=Math.imul(nt,lt),l=l+Math.imul(it,ht)|0,G=Math.imul(it,lt),B=B+Math.imul(J,wt)|0,l=l+Math.imul(J,gt)|0,l=l+Math.imul(j,wt)|0,G=G+Math.imul(j,gt)|0,B=B+Math.imul(E,Mt)|0,l=l+Math.imul(E,bt)|0,l=l+Math.imul(A,Mt)|0,G=G+Math.imul(A,bt)|0,B=B+Math.imul(y,St)|0,l=l+Math.imul(y,_t)|0,l=l+Math.imul(d,St)|0,G=G+Math.imul(d,_t)|0,B=B+Math.imul(u,Bt)|0,l=l+Math.imul(u,Dt)|0,l=l+Math.imul(_,Bt)|0,G=G+Math.imul(_,Dt)|0,B=B+Math.imul(R,Ut)|0,l=l+Math.imul(R,Ft)|0,l=l+Math.imul(m,Ut)|0,G=G+Math.imul(m,Ft)|0,B=B+Math.imul(b,Gt)|0,l=l+Math.imul(b,At)|0,l=l+Math.imul(w,Gt)|0,G=G+Math.imul(w,At)|0,B=B+Math.imul($,Rt)|0,l=l+Math.imul($,It)|0,l=l+Math.imul(F,Rt)|0,G=G+Math.imul(F,It)|0,B=B+Math.imul(yt,Ot)|0,l=l+Math.imul(yt,mt)|0,l=l+Math.imul(pt,Ot)|0,G=G+Math.imul(pt,mt)|0,B=B+Math.imul(at,Vt)|0,l=l+Math.imul(at,Nt)|0,l=l+Math.imul(ut,Vt)|0,G=G+Math.imul(ut,Nt)|0;var tn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(tn>>>26)|0,tn&=67108863,B=Math.imul(nt,wt),l=Math.imul(nt,gt),l=l+Math.imul(it,wt)|0,G=Math.imul(it,gt),B=B+Math.imul(J,Mt)|0,l=l+Math.imul(J,bt)|0,l=l+Math.imul(j,Mt)|0,G=G+Math.imul(j,bt)|0,B=B+Math.imul(E,St)|0,l=l+Math.imul(E,_t)|0,l=l+Math.imul(A,St)|0,G=G+Math.imul(A,_t)|0,B=B+Math.imul(y,Bt)|0,l=l+Math.imul(y,Dt)|0,l=l+Math.imul(d,Bt)|0,G=G+Math.imul(d,Dt)|0,B=B+Math.imul(u,Ut)|0,l=l+Math.imul(u,Ft)|0,l=l+Math.imul(_,Ut)|0,G=G+Math.imul(_,Ft)|0,B=B+Math.imul(R,Gt)|0,l=l+Math.imul(R,At)|0,l=l+Math.imul(m,Gt)|0,G=G+Math.imul(m,At)|0,B=B+Math.imul(b,Rt)|0,l=l+Math.imul(b,It)|0,l=l+Math.imul(w,Rt)|0,G=G+Math.imul(w,It)|0,B=B+Math.imul($,Ot)|0,l=l+Math.imul($,mt)|0,l=l+Math.imul(F,Ot)|0,G=G+Math.imul(F,mt)|0,B=B+Math.imul(yt,Vt)|0,l=l+Math.imul(yt,Nt)|0,l=l+Math.imul(pt,Vt)|0,G=G+Math.imul(pt,Nt)|0;var en=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(en>>>26)|0,en&=67108863,B=Math.imul(nt,Mt),l=Math.imul(nt,bt),l=l+Math.imul(it,Mt)|0,G=Math.imul(it,bt),B=B+Math.imul(J,St)|0,l=l+Math.imul(J,_t)|0,l=l+Math.imul(j,St)|0,G=G+Math.imul(j,_t)|0,B=B+Math.imul(E,Bt)|0,l=l+Math.imul(E,Dt)|0,l=l+Math.imul(A,Bt)|0,G=G+Math.imul(A,Dt)|0,B=B+Math.imul(y,Ut)|0,l=l+Math.imul(y,Ft)|0,l=l+Math.imul(d,Ut)|0,G=G+Math.imul(d,Ft)|0,B=B+Math.imul(u,Gt)|0,l=l+Math.imul(u,At)|0,l=l+Math.imul(_,Gt)|0,G=G+Math.imul(_,At)|0,B=B+Math.imul(R,Rt)|0,l=l+Math.imul(R,It)|0,l=l+Math.imul(m,Rt)|0,G=G+Math.imul(m,It)|0,B=B+Math.imul(b,Ot)|0,l=l+Math.imul(b,mt)|0,l=l+Math.imul(w,Ot)|0,G=G+Math.imul(w,mt)|0,B=B+Math.imul($,Vt)|0,l=l+Math.imul($,Nt)|0,l=l+Math.imul(F,Vt)|0,G=G+Math.imul(F,Nt)|0;var rn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(rn>>>26)|0,rn&=67108863,B=Math.imul(nt,St),l=Math.imul(nt,_t),l=l+Math.imul(it,St)|0,G=Math.imul(it,_t),B=B+Math.imul(J,Bt)|0,l=l+Math.imul(J,Dt)|0,l=l+Math.imul(j,Bt)|0,G=G+Math.imul(j,Dt)|0,B=B+Math.imul(E,Ut)|0,l=l+Math.imul(E,Ft)|0,l=l+Math.imul(A,Ut)|0,G=G+Math.imul(A,Ft)|0,B=B+Math.imul(y,Gt)|0,l=l+Math.imul(y,At)|0,l=l+Math.imul(d,Gt)|0,G=G+Math.imul(d,At)|0,B=B+Math.imul(u,Rt)|0,l=l+Math.imul(u,It)|0,l=l+Math.imul(_,Rt)|0,G=G+Math.imul(_,It)|0,B=B+Math.imul(R,Ot)|0,l=l+Math.imul(R,mt)|0,l=l+Math.imul(m,Ot)|0,G=G+Math.imul(m,mt)|0,B=B+Math.imul(b,Vt)|0,l=l+Math.imul(b,Nt)|0,l=l+Math.imul(w,Vt)|0,G=G+Math.imul(w,Nt)|0;var nn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(nn>>>26)|0,nn&=67108863,B=Math.imul(nt,Bt),l=Math.imul(nt,Dt),l=l+Math.imul(it,Bt)|0,G=Math.imul(it,Dt),B=B+Math.imul(J,Ut)|0,l=l+Math.imul(J,Ft)|0,l=l+Math.imul(j,Ut)|0,G=G+Math.imul(j,Ft)|0,B=B+Math.imul(E,Gt)|0,l=l+Math.imul(E,At)|0,l=l+Math.imul(A,Gt)|0,G=G+Math.imul(A,At)|0,B=B+Math.imul(y,Rt)|0,l=l+Math.imul(y,It)|0,l=l+Math.imul(d,Rt)|0,G=G+Math.imul(d,It)|0,B=B+Math.imul(u,Ot)|0,l=l+Math.imul(u,mt)|0,l=l+Math.imul(_,Ot)|0,G=G+Math.imul(_,mt)|0,B=B+Math.imul(R,Vt)|0,l=l+Math.imul(R,Nt)|0,l=l+Math.imul(m,Vt)|0,G=G+Math.imul(m,Nt)|0;var on=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(on>>>26)|0,on&=67108863,B=Math.imul(nt,Ut),l=Math.imul(nt,Ft),l=l+Math.imul(it,Ut)|0,G=Math.imul(it,Ft),B=B+Math.imul(J,Gt)|0,l=l+Math.imul(J,At)|0,l=l+Math.imul(j,Gt)|0,G=G+Math.imul(j,At)|0,B=B+Math.imul(E,Rt)|0,l=l+Math.imul(E,It)|0,l=l+Math.imul(A,Rt)|0,G=G+Math.imul(A,It)|0,B=B+Math.imul(y,Ot)|0,l=l+Math.imul(y,mt)|0,l=l+Math.imul(d,Ot)|0,G=G+Math.imul(d,mt)|0,B=B+Math.imul(u,Vt)|0,l=l+Math.imul(u,Nt)|0,l=l+Math.imul(_,Vt)|0,G=G+Math.imul(_,Nt)|0;var an=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(an>>>26)|0,an&=67108863,B=Math.imul(nt,Gt),l=Math.imul(nt,At),l=l+Math.imul(it,Gt)|0,G=Math.imul(it,At),B=B+Math.imul(J,Rt)|0,l=l+Math.imul(J,It)|0,l=l+Math.imul(j,Rt)|0,G=G+Math.imul(j,It)|0,B=B+Math.imul(E,Ot)|0,l=l+Math.imul(E,mt)|0,l=l+Math.imul(A,Ot)|0,G=G+Math.imul(A,mt)|0,B=B+Math.imul(y,Vt)|0,l=l+Math.imul(y,Nt)|0,l=l+Math.imul(d,Vt)|0,G=G+Math.imul(d,Nt)|0;var sn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(sn>>>26)|0,sn&=67108863,B=Math.imul(nt,Rt),l=Math.imul(nt,It),l=l+Math.imul(it,Rt)|0,G=Math.imul(it,It),B=B+Math.imul(J,Ot)|0,l=l+Math.imul(J,mt)|0,l=l+Math.imul(j,Ot)|0,G=G+Math.imul(j,mt)|0,B=B+Math.imul(E,Vt)|0,l=l+Math.imul(E,Nt)|0,l=l+Math.imul(A,Vt)|0,G=G+Math.imul(A,Nt)|0;var un=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(un>>>26)|0,un&=67108863,B=Math.imul(nt,Ot),l=Math.imul(nt,mt),l=l+Math.imul(it,Ot)|0,G=Math.imul(it,mt),B=B+Math.imul(J,Vt)|0,l=l+Math.imul(J,Nt)|0,l=l+Math.imul(j,Vt)|0,G=G+Math.imul(j,Nt)|0;var fn=(O+B|0)+((l&8191)<<13)|0;O=(G+(l>>>13)|0)+(fn>>>26)|0,fn&=67108863,B=Math.imul(nt,Vt),l=Math.imul(nt,Nt),l=l+Math.imul(it,Vt)|0,G=Math.imul(it,Nt);var cn=(O+B|0)+((l&8191)<<13)|0;return O=(G+(l>>>13)|0)+(cn>>>26)|0,cn&=67108863,L[0]=me,L[1]=Ve,L[2]=qe,L[3]=Zt,L[4]=Wr,L[5]=Kr,L[6]=Qr,L[7]=Jr,L[8]=jr,L[9]=tn,L[10]=en,L[11]=rn,L[12]=nn,L[13]=on,L[14]=an,L[15]=sn,L[16]=un,L[17]=fn,L[18]=cn,O!==0&&(L[19]=O,T.length++),T};Math.imul||(I=N);function V(U,a,v){v.negative=a.negative^U.negative,v.length=U.length+a.length;for(var T=0,M=0,S=0;S<v.length-1;S++){var L=M;M=0;for(var O=T&67108863,B=Math.min(S,a.length-1),l=Math.max(0,S-U.length+1);l<=B;l++){var G=S-l,ot=U.words[G]|0,at=a.words[l]|0,ut=ot*at,ft=ut&67108863;L=L+(ut/67108864|0)|0,ft=ft+O|0,O=ft&67108863,L=L+(ft>>>26)|0,M+=L>>>26,L&=67108863}v.words[S]=O,T=L,L=M}return T!==0?v.words[S]=T:v.length--,v.strip()}function q(U,a,v){var T=new Y;return T.mulp(U,a,v)}i.prototype.mulTo=function(a,v){var T,M=this.length+a.length;return this.length===10&&a.length===10?T=I(this,a,v):M<63?T=N(this,a,v):M<1024?T=V(this,a,v):T=q(this,a,v),T};function Y(U,a){this.x=U,this.y=a}Y.prototype.makeRBT=function(a){for(var v=new Array(a),T=i.prototype._countBits(a)-1,M=0;M<a;M++)v[M]=this.revBin(M,T,a);return v},Y.prototype.revBin=function(a,v,T){if(a===0||a===T-1)return a;for(var M=0,S=0;S<v;S++)M|=(a&1)<<v-S-1,a>>=1;return M},Y.prototype.permute=function(a,v,T,M,S,L){for(var O=0;O<L;O++)M[O]=v[a[O]],S[O]=T[a[O]]},Y.prototype.transform=function(a,v,T,M,S,L){this.permute(L,a,v,T,M,S);for(var O=1;O<S;O<<=1)for(var B=O<<1,l=Math.cos(2*Math.PI/B),G=Math.sin(2*Math.PI/B),ot=0;ot<S;ot+=B)for(var at=l,ut=G,ft=0;ft<O;ft++){var yt=T[ot+ft],pt=M[ot+ft],k=T[ot+ft+O],$=M[ot+ft+O],F=at*k-ut*$;$=at*$+ut*k,k=F,T[ot+ft]=yt+k,M[ot+ft]=pt+$,T[ot+ft+O]=yt-k,M[ot+ft+O]=pt-$,ft!==B&&(F=l*at-G*ut,ut=l*ut+G*at,at=F)}},Y.prototype.guessLen13b=function(a,v){var T=Math.max(v,a)|1,M=T&1,S=0;for(T=T/2|0;T;T=T>>>1)S++;return 1<<S+1+M},Y.prototype.conjugate=function(a,v,T){if(!(T<=1))for(var M=0;M<T/2;M++){var S=a[M];a[M]=a[T-M-1],a[T-M-1]=S,S=v[M],v[M]=-v[T-M-1],v[T-M-1]=-S}},Y.prototype.normalize13b=function(a,v){for(var T=0,M=0;M<v/2;M++){var S=Math.round(a[2*M+1]/v)*8192+Math.round(a[2*M]/v)+T;a[M]=S&67108863,S<67108864?T=0:T=S/67108864|0}return a},Y.prototype.convert13b=function(a,v,T,M){for(var S=0,L=0;L<v;L++)S=S+(a[L]|0),T[2*L]=S&8191,S=S>>>13,T[2*L+1]=S&8191,S=S>>>13;for(L=2*v;L<M;++L)T[L]=0;n(S===0),n((S&-8192)===0)},Y.prototype.stub=function(a){for(var v=new Array(a),T=0;T<a;T++)v[T]=0;return v},Y.prototype.mulp=function(a,v,T){var M=2*this.guessLen13b(a.length,v.length),S=this.makeRBT(M),L=this.stub(M),O=new Array(M),B=new Array(M),l=new Array(M),G=new Array(M),ot=new Array(M),at=new Array(M),ut=T.words;ut.length=M,this.convert13b(a.words,a.length,O,M),this.convert13b(v.words,v.length,G,M),this.transform(O,L,B,l,M,S),this.transform(G,L,ot,at,M,S);for(var ft=0;ft<M;ft++){var yt=B[ft]*ot[ft]-l[ft]*at[ft];l[ft]=B[ft]*at[ft]+l[ft]*ot[ft],B[ft]=yt}return this.conjugate(B,l,M),this.transform(B,l,ut,L,M,S),this.conjugate(ut,L,M),this.normalize13b(ut,M),T.negative=a.negative^v.negative,T.length=a.length+v.length,T.strip()},i.prototype.mul=function(a){var v=new i(null);return v.words=new Array(this.length+a.length),this.mulTo(a,v)},i.prototype.mulf=function(a){var v=new i(null);return v.words=new Array(this.length+a.length),q(this,a,v)},i.prototype.imul=function(a){return this.clone().mulTo(a,this)},i.prototype.imuln=function(a){n(typeof a=="number"),n(a<67108864);for(var v=0,T=0;T<this.length;T++){var M=(this.words[T]|0)*a,S=(M&67108863)+(v&67108863);v>>=26,v+=M/67108864|0,v+=S>>>26,this.words[T]=S&67108863}return v!==0&&(this.words[T]=v,this.length++),this.length=a===0?1:this.length,this},i.prototype.muln=function(a){return this.clone().imuln(a)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(a){var v=X(a);if(v.length===0)return new i(1);for(var T=this,M=0;M<v.length&&v[M]===0;M++,T=T.sqr());if(++M<v.length)for(var S=T.sqr();M<v.length;M++,S=S.sqr())v[M]!==0&&(T=T.mul(S));return T},i.prototype.iushln=function(a){n(typeof a=="number"&&a>=0);var v=a%26,T=(a-v)/26,M=67108863>>>26-v<<26-v,S;if(v!==0){var L=0;for(S=0;S<this.length;S++){var O=this.words[S]&M,B=(this.words[S]|0)-O<<v;this.words[S]=B|L,L=O>>>26-v}L&&(this.words[S]=L,this.length++)}if(T!==0){for(S=this.length-1;S>=0;S--)this.words[S+T]=this.words[S];for(S=0;S<T;S++)this.words[S]=0;this.length+=T}return this.strip()},i.prototype.ishln=function(a){return n(this.negative===0),this.iushln(a)},i.prototype.iushrn=function(a,v,T){n(typeof a=="number"&&a>=0);var M;v?M=(v-v%26)/26:M=0;var S=a%26,L=Math.min((a-S)/26,this.length),O=67108863^67108863>>>S<<S,B=T;if(M-=L,M=Math.max(0,M),B){for(var l=0;l<L;l++)B.words[l]=this.words[l];B.length=L}if(L!==0)if(this.length>L)for(this.length-=L,l=0;l<this.length;l++)this.words[l]=this.words[l+L];else this.words[0]=0,this.length=1;var G=0;for(l=this.length-1;l>=0&&(G!==0||l>=M);l--){var ot=this.words[l]|0;this.words[l]=G<<26-S|ot>>>S,G=ot&O}return B&&G!==0&&(B.words[B.length++]=G),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(a,v,T){return n(this.negative===0),this.iushrn(a,v,T)},i.prototype.shln=function(a){return this.clone().ishln(a)},i.prototype.ushln=function(a){return this.clone().iushln(a)},i.prototype.shrn=function(a){return this.clone().ishrn(a)},i.prototype.ushrn=function(a){return this.clone().iushrn(a)},i.prototype.testn=function(a){n(typeof a=="number"&&a>=0);var v=a%26,T=(a-v)/26,M=1<<v;if(this.length<=T)return!1;var S=this.words[T];return!!(S&M)},i.prototype.imaskn=function(a){n(typeof a=="number"&&a>=0);var v=a%26,T=(a-v)/26;if(n(this.negative===0,"imaskn works only with positive numbers"),this.length<=T)return this;if(v!==0&&T++,this.length=Math.min(T,this.length),v!==0){var M=67108863^67108863>>>v<<v;this.words[this.length-1]&=M}return this.strip()},i.prototype.maskn=function(a){return this.clone().imaskn(a)},i.prototype.iaddn=function(a){return n(typeof a=="number"),n(a<67108864),a<0?this.isubn(-a):this.negative!==0?this.length===1&&(this.words[0]|0)<a?(this.words[0]=a-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(a),this.negative=1,this):this._iaddn(a)},i.prototype._iaddn=function(a){this.words[0]+=a;for(var v=0;v<this.length&&this.words[v]>=67108864;v++)this.words[v]-=67108864,v===this.length-1?this.words[v+1]=1:this.words[v+1]++;return this.length=Math.max(this.length,v+1),this},i.prototype.isubn=function(a){if(n(typeof a=="number"),n(a<67108864),a<0)return this.iaddn(-a);if(this.negative!==0)return this.negative=0,this.iaddn(a),this.negative=1,this;if(this.words[0]-=a,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var v=0;v<this.length&&this.words[v]<0;v++)this.words[v]+=67108864,this.words[v+1]-=1;return this.strip()},i.prototype.addn=function(a){return this.clone().iaddn(a)},i.prototype.subn=function(a){return this.clone().isubn(a)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(a,v,T){var M=a.length+T,S;this._expand(M);var L,O=0;for(S=0;S<a.length;S++){L=(this.words[S+T]|0)+O;var B=(a.words[S]|0)*v;L-=B&67108863,O=(L>>26)-(B/67108864|0),this.words[S+T]=L&67108863}for(;S<this.length-T;S++)L=(this.words[S+T]|0)+O,O=L>>26,this.words[S+T]=L&67108863;if(O===0)return this.strip();for(n(O===-1),O=0,S=0;S<this.length;S++)L=-(this.words[S]|0)+O,O=L>>26,this.words[S]=L&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(a,v){var T=this.length-a.length,M=this.clone(),S=a,L=S.words[S.length-1]|0,O=this._countBits(L);T=26-O,T!==0&&(S=S.ushln(T),M.iushln(T),L=S.words[S.length-1]|0);var B=M.length-S.length,l;if(v!=="mod"){l=new i(null),l.length=B+1,l.words=new Array(l.length);for(var G=0;G<l.length;G++)l.words[G]=0}var ot=M.clone()._ishlnsubmul(S,1,B);ot.negative===0&&(M=ot,l&&(l.words[B]=1));for(var at=B-1;at>=0;at--){var ut=(M.words[S.length+at]|0)*67108864+(M.words[S.length+at-1]|0);for(ut=Math.min(ut/L|0,67108863),M._ishlnsubmul(S,ut,at);M.negative!==0;)ut--,M.negative=0,M._ishlnsubmul(S,1,at),M.isZero()||(M.negative^=1);l&&(l.words[at]=ut)}return l&&l.strip(),M.strip(),v!=="div"&&T!==0&&M.iushrn(T),{div:l||null,mod:M}},i.prototype.divmod=function(a,v,T){if(n(!a.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var M,S,L;return this.negative!==0&&a.negative===0?(L=this.neg().divmod(a,v),v!=="mod"&&(M=L.div.neg()),v!=="div"&&(S=L.mod.neg(),T&&S.negative!==0&&S.iadd(a)),{div:M,mod:S}):this.negative===0&&a.negative!==0?(L=this.divmod(a.neg(),v),v!=="mod"&&(M=L.div.neg()),{div:M,mod:L.mod}):(this.negative&a.negative)!==0?(L=this.neg().divmod(a.neg(),v),v!=="div"&&(S=L.mod.neg(),T&&S.negative!==0&&S.isub(a)),{div:L.div,mod:S}):a.length>this.length||this.cmp(a)<0?{div:new i(0),mod:this}:a.length===1?v==="div"?{div:this.divn(a.words[0]),mod:null}:v==="mod"?{div:null,mod:new i(this.modn(a.words[0]))}:{div:this.divn(a.words[0]),mod:new i(this.modn(a.words[0]))}:this._wordDiv(a,v)},i.prototype.div=function(a){return this.divmod(a,"div",!1).div},i.prototype.mod=function(a){return this.divmod(a,"mod",!1).mod},i.prototype.umod=function(a){return this.divmod(a,"mod",!0).mod},i.prototype.divRound=function(a){var v=this.divmod(a);if(v.mod.isZero())return v.div;var T=v.div.negative!==0?v.mod.isub(a):v.mod,M=a.ushrn(1),S=a.andln(1),L=T.cmp(M);return L<0||S===1&&L===0?v.div:v.div.negative!==0?v.div.isubn(1):v.div.iaddn(1)},i.prototype.modn=function(a){n(a<=67108863);for(var v=(1<<26)%a,T=0,M=this.length-1;M>=0;M--)T=(v*T+(this.words[M]|0))%a;return T},i.prototype.idivn=function(a){n(a<=67108863);for(var v=0,T=this.length-1;T>=0;T--){var M=(this.words[T]|0)+v*67108864;this.words[T]=M/a|0,v=M%a}return this.strip()},i.prototype.divn=function(a){return this.clone().idivn(a)},i.prototype.egcd=function(a){n(a.negative===0),n(!a.isZero());var v=this,T=a.clone();v.negative!==0?v=v.umod(a):v=v.clone();for(var M=new i(1),S=new i(0),L=new i(0),O=new i(1),B=0;v.isEven()&&T.isEven();)v.iushrn(1),T.iushrn(1),++B;for(var l=T.clone(),G=v.clone();!v.isZero();){for(var ot=0,at=1;(v.words[0]&at)===0&&ot<26;++ot,at<<=1);if(ot>0)for(v.iushrn(ot);ot-- >0;)(M.isOdd()||S.isOdd())&&(M.iadd(l),S.isub(G)),M.iushrn(1),S.iushrn(1);for(var ut=0,ft=1;(T.words[0]&ft)===0&&ut<26;++ut,ft<<=1);if(ut>0)for(T.iushrn(ut);ut-- >0;)(L.isOdd()||O.isOdd())&&(L.iadd(l),O.isub(G)),L.iushrn(1),O.iushrn(1);v.cmp(T)>=0?(v.isub(T),M.isub(L),S.isub(O)):(T.isub(v),L.isub(M),O.isub(S))}return{a:L,b:O,gcd:T.iushln(B)}},i.prototype._invmp=function(a){n(a.negative===0),n(!a.isZero());var v=this,T=a.clone();v.negative!==0?v=v.umod(a):v=v.clone();for(var M=new i(1),S=new i(0),L=T.clone();v.cmpn(1)>0&&T.cmpn(1)>0;){for(var O=0,B=1;(v.words[0]&B)===0&&O<26;++O,B<<=1);if(O>0)for(v.iushrn(O);O-- >0;)M.isOdd()&&M.iadd(L),M.iushrn(1);for(var l=0,G=1;(T.words[0]&G)===0&&l<26;++l,G<<=1);if(l>0)for(T.iushrn(l);l-- >0;)S.isOdd()&&S.iadd(L),S.iushrn(1);v.cmp(T)>=0?(v.isub(T),M.isub(S)):(T.isub(v),S.isub(M))}var ot;return v.cmpn(1)===0?ot=M:ot=S,ot.cmpn(0)<0&&ot.iadd(a),ot},i.prototype.gcd=function(a){if(this.isZero())return a.abs();if(a.isZero())return this.abs();var v=this.clone(),T=a.clone();v.negative=0,T.negative=0;for(var M=0;v.isEven()&&T.isEven();M++)v.iushrn(1),T.iushrn(1);do{for(;v.isEven();)v.iushrn(1);for(;T.isEven();)T.iushrn(1);var S=v.cmp(T);if(S<0){var L=v;v=T,T=L}else if(S===0||T.cmpn(1)===0)break;v.isub(T)}while(!0);return T.iushln(M)},i.prototype.invm=function(a){return this.egcd(a).a.umod(a)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(a){return this.words[0]&a},i.prototype.bincn=function(a){n(typeof a=="number");var v=a%26,T=(a-v)/26,M=1<<v;if(this.length<=T)return this._expand(T+1),this.words[T]|=M,this;for(var S=M,L=T;S!==0&&L<this.length;L++){var O=this.words[L]|0;O+=S,S=O>>>26,O&=67108863,this.words[L]=O}return S!==0&&(this.words[L]=S,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(a){var v=a<0;if(this.negative!==0&&!v)return-1;if(this.negative===0&&v)return 1;this.strip();var T;if(this.length>1)T=1;else{v&&(a=-a),n(a<=67108863,"Number is too big");var M=this.words[0]|0;T=M===a?0:M<a?-1:1}return this.negative!==0?-T|0:T},i.prototype.cmp=function(a){if(this.negative!==0&&a.negative===0)return-1;if(this.negative===0&&a.negative!==0)return 1;var v=this.ucmp(a);return this.negative!==0?-v|0:v},i.prototype.ucmp=function(a){if(this.length>a.length)return 1;if(this.length<a.length)return-1;for(var v=0,T=this.length-1;T>=0;T--){var M=this.words[T]|0,S=a.words[T]|0;if(M!==S){M<S?v=-1:M>S&&(v=1);break}}return v},i.prototype.gtn=function(a){return this.cmpn(a)===1},i.prototype.gt=function(a){return this.cmp(a)===1},i.prototype.gten=function(a){return this.cmpn(a)>=0},i.prototype.gte=function(a){return this.cmp(a)>=0},i.prototype.ltn=function(a){return this.cmpn(a)===-1},i.prototype.lt=function(a){return this.cmp(a)===-1},i.prototype.lten=function(a){return this.cmpn(a)<=0},i.prototype.lte=function(a){return this.cmp(a)<=0},i.prototype.eqn=function(a){return this.cmpn(a)===0},i.prototype.eq=function(a){return this.cmp(a)===0},i.red=function(a){return new et(a)},i.prototype.toRed=function(a){return n(!this.red,"Already a number in reduction context"),n(this.negative===0,"red works only with positives"),a.convertTo(this)._forceRed(a)},i.prototype.fromRed=function(){return n(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(a){return this.red=a,this},i.prototype.forceRed=function(a){return n(!this.red,"Already a number in reduction context"),this._forceRed(a)},i.prototype.redAdd=function(a){return n(this.red,"redAdd works only with red numbers"),this.red.add(this,a)},i.prototype.redIAdd=function(a){return n(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,a)},i.prototype.redSub=function(a){return n(this.red,"redSub works only with red numbers"),this.red.sub(this,a)},i.prototype.redISub=function(a){return n(this.red,"redISub works only with red numbers"),this.red.isub(this,a)},i.prototype.redShl=function(a){return n(this.red,"redShl works only with red numbers"),this.red.shl(this,a)},i.prototype.redMul=function(a){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.mul(this,a)},i.prototype.redIMul=function(a){return n(this.red,"redMul works only with red numbers"),this.red._verify2(this,a),this.red.imul(this,a)},i.prototype.redSqr=function(){return n(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return n(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return n(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return n(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return n(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(a){return n(this.red&&!a.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,a)};var K={k256:null,p224:null,p192:null,p25519:null};function Q(U,a){this.name=U,this.p=new i(a,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}Q.prototype._tmp=function(){var a=new i(null);return a.words=new Array(Math.ceil(this.n/13)),a},Q.prototype.ireduce=function(a){var v=a,T;do this.split(v,this.tmp),v=this.imulK(v),v=v.iadd(this.tmp),T=v.bitLength();while(T>this.n);var M=T<this.n?-1:v.ucmp(this.p);return M===0?(v.words[0]=0,v.length=1):M>0?v.isub(this.p):v.strip!==void 0?v.strip():v._strip(),v},Q.prototype.split=function(a,v){a.iushrn(this.n,0,v)},Q.prototype.imulK=function(a){return a.imul(this.k)};function tt(){Q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(tt,Q),tt.prototype.split=function(a,v){for(var T=4194303,M=Math.min(a.length,9),S=0;S<M;S++)v.words[S]=a.words[S];if(v.length=M,a.length<=9){a.words[0]=0,a.length=1;return}var L=a.words[9];for(v.words[v.length++]=L&T,S=10;S<a.length;S++){var O=a.words[S]|0;a.words[S-10]=(O&T)<<4|L>>>22,L=O}L>>>=22,a.words[S-10]=L,L===0&&a.length>10?a.length-=10:a.length-=9},tt.prototype.imulK=function(a){a.words[a.length]=0,a.words[a.length+1]=0,a.length+=2;for(var v=0,T=0;T<a.length;T++){var M=a.words[T]|0;v+=M*977,a.words[T]=v&67108863,v=M*64+(v/67108864|0)}return a.words[a.length-1]===0&&(a.length--,a.words[a.length-1]===0&&a.length--),a};function H(){Q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r(H,Q);function W(){Q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(W,Q);function st(){Q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(st,Q),st.prototype.imulK=function(a){for(var v=0,T=0;T<a.length;T++){var M=(a.words[T]|0)*19+v,S=M&67108863;M>>>=26,a.words[T]=S,v=M}return v!==0&&(a.words[a.length++]=v),a},i._prime=function(a){if(K[a])return K[a];var v;if(a==="k256")v=new tt;else if(a==="p224")v=new H;else if(a==="p192")v=new W;else if(a==="p25519")v=new st;else throw new Error("Unknown prime "+a);return K[a]=v,v};function et(U){if(typeof U=="string"){var a=i._prime(U);this.m=a.p,this.prime=a}else n(U.gtn(1),"modulus must be greater than 1"),this.m=U,this.prime=null}et.prototype._verify1=function(a){n(a.negative===0,"red works only with positives"),n(a.red,"red works only with red numbers")},et.prototype._verify2=function(a,v){n((a.negative|v.negative)===0,"red works only with positives"),n(a.red&&a.red===v.red,"red works only with red numbers")},et.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):a.umod(this.m)._forceRed(this)},et.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},et.prototype.add=function(a,v){this._verify2(a,v);var T=a.add(v);return T.cmp(this.m)>=0&&T.isub(this.m),T._forceRed(this)},et.prototype.iadd=function(a,v){this._verify2(a,v);var T=a.iadd(v);return T.cmp(this.m)>=0&&T.isub(this.m),T},et.prototype.sub=function(a,v){this._verify2(a,v);var T=a.sub(v);return T.cmpn(0)<0&&T.iadd(this.m),T._forceRed(this)},et.prototype.isub=function(a,v){this._verify2(a,v);var T=a.isub(v);return T.cmpn(0)<0&&T.iadd(this.m),T},et.prototype.shl=function(a,v){return this._verify1(a),this.imod(a.ushln(v))},et.prototype.imul=function(a,v){return this._verify2(a,v),this.imod(a.imul(v))},et.prototype.mul=function(a,v){return this._verify2(a,v),this.imod(a.mul(v))},et.prototype.isqr=function(a){return this.imul(a,a.clone())},et.prototype.sqr=function(a){return this.mul(a,a)},et.prototype.sqrt=function(a){if(a.isZero())return a.clone();var v=this.m.andln(3);if(n(v%2===1),v===3){var T=this.m.add(new i(1)).iushrn(2);return this.pow(a,T)}for(var M=this.m.subn(1),S=0;!M.isZero()&&M.andln(1)===0;)S++,M.iushrn(1);n(!M.isZero());var L=new i(1).toRed(this),O=L.redNeg(),B=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new i(2*l*l).toRed(this);this.pow(l,B).cmp(O)!==0;)l.redIAdd(O);for(var G=this.pow(l,M),ot=this.pow(a,M.addn(1).iushrn(1)),at=this.pow(a,M),ut=S;at.cmp(L)!==0;){for(var ft=at,yt=0;ft.cmp(L)!==0;yt++)ft=ft.redSqr();n(yt<ut);var pt=this.pow(G,new i(1).iushln(ut-yt-1));ot=ot.redMul(pt),G=pt.redSqr(),at=at.redMul(G),ut=yt}return ot},et.prototype.invm=function(a){var v=a._invmp(this.m);return v.negative!==0?(v.negative=0,this.imod(v).redNeg()):this.imod(v)},et.prototype.pow=function(a,v){if(v.isZero())return new i(1).toRed(this);if(v.cmpn(1)===0)return a.clone();var T=4,M=new Array(1<<T);M[0]=new i(1).toRed(this),M[1]=a;for(var S=2;S<M.length;S++)M[S]=this.mul(M[S-1],a);var L=M[0],O=0,B=0,l=v.bitLength()%26;for(l===0&&(l=26),S=v.length-1;S>=0;S--){for(var G=v.words[S],ot=l-1;ot>=0;ot--){var at=G>>ot&1;if(L!==M[0]&&(L=this.sqr(L)),at===0&&O===0){B=0;continue}O<<=1,O|=at,B++,!(B!==T&&(S!==0||ot!==0))&&(L=this.mul(L,M[O]),B=0,O=0)}l=26}return L},et.prototype.convertTo=function(a){var v=a.umod(this.m);return v===a?v.clone():v},et.prototype.convertFrom=function(a){var v=a.clone();return v.red=null,v},i.mont=function(a){return new rt(a)};function rt(U){et.call(this,U),this.shift=this.m.bitLength(),this.shift%26!==0&&(this.shift+=26-this.shift%26),this.r=new i(1).iushln(this.shift),this.r2=this.imod(this.r.sqr()),this.rinv=this.r._invmp(this.m),this.minv=this.rinv.mul(this.r).isubn(1).div(this.m),this.minv=this.minv.umod(this.r),this.minv=this.r.sub(this.minv)}r(rt,et),rt.prototype.convertTo=function(a){return this.imod(a.ushln(this.shift))},rt.prototype.convertFrom=function(a){var v=this.imod(a.mul(this.rinv));return v.red=null,v},rt.prototype.imul=function(a,v){if(a.isZero()||v.isZero())return a.words[0]=0,a.length=1,a;var T=a.imul(v),M=T.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=T.isub(M).iushrn(this.shift),L=S;return S.cmp(this.m)>=0?L=S.isub(this.m):S.cmpn(0)<0&&(L=S.iadd(this.m)),L._forceRed(this)},rt.prototype.mul=function(a,v){if(a.isZero()||v.isZero())return new i(0)._forceRed(this);var T=a.mul(v),M=T.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=T.isub(M).iushrn(this.shift),L=S;return S.cmp(this.m)>=0?L=S.isub(this.m):S.cmpn(0)<0&&(L=S.iadd(this.m)),L._forceRed(this)},rt.prototype.invm=function(a){var v=this.imod(a._invmp(this.m).mul(this.r2));return v._forceRed(this)}})(typeof Cn>"u"||Cn,aa)});var Xn=xt((th,sa)=>{"use strict";var j1=ur();sa.exports=gf;function gf(e){return e&&typeof e=="object"&&!!e.words}});var ca=xt((eh,fa)=>{"use strict";var ua=Xn();fa.exports=wf;function wf(e){return Array.isArray(e)&&e.length===2&&ua(e[0])&&ua(e[1])}});var Cr=xt((rh,kt)=>{var kn=!1;if(typeof Float64Array<"u")if(le=new Float64Array(1),re=new Uint32Array(le.buffer),le[0]=1,kn=!0,re[1]===1072693248){let e=function(r,i){return re[0]=r,re[1]=i,le[0]},t=function(r){return le[0]=r,re[0]},n=function(r){return le[0]=r,re[1]};xf=e,yf=t,Mf=n,kt.exports=function(i){return le[0]=i,[re[0],re[1]]},kt.exports.pack=e,kt.exports.lo=t,kt.exports.hi=n}else if(re[0]===1072693248){let e=function(r,i){return re[1]=r,re[0]=i,le[0]},t=function(r){return le[0]=r,re[1]},n=function(r){return le[0]=r,re[0]};bf=e,Tf=t,Pf=n,kt.exports=function(i){return le[0]=i,[re[1],re[0]]},kt.exports.pack=e,kt.exports.lo=t,kt.exports.hi=n}else kn=!1;var le,re,xf,yf,Mf,bf,Tf,Pf;if(!kn){let e=function(r,i){return he.writeUInt32LE(r,0,!0),he.writeUInt32LE(i,4,!0),he.readDoubleLE(0,!0)},t=function(r){return he.writeDoubleLE(r,0,!0),he.readUInt32LE(0,!0)},n=function(r){return he.writeDoubleLE(r,0,!0),he.readUInt32LE(4,!0)};Sf=e,_f=t,Bf=n,he=new Buffer(8),kt.exports=function(i){return he.writeDoubleLE(i,0,!0),[he.readUInt32LE(0,!0),he.readUInt32LE(4,!0)]},kt.exports.pack=e,kt.exports.lo=t,kt.exports.hi=n}var he,Sf,_f,Bf;kt.exports.sign=function(e){return kt.exports.hi(e)>>>31};kt.exports.exponent=function(e){var t=kt.exports.hi(e);return(t<<1>>>21)-1023};kt.exports.fraction=function(e){var t=kt.exports.lo(e),n=kt.exports.hi(e),r=n&(1<<20)-1;return n&2146435072&&(r+=1<<20),[t,r]};kt.exports.denormalized=function(e){var t=kt.exports.hi(e);return!(t&2146435072)}});var Yn=xt((nh,ha)=>{"use strict";var la=ur(),Df=Cr();ha.exports=Uf;function Uf(e){var t=Df.exponent(e);return t<52?new la(e):new la(e*Math.pow(2,52-t)).ushln(t-52)}});var va=xt((ih,pa)=>{"use strict";var Ff=ur();pa.exports=Gf;function Gf(e){return new Ff(e)}});var Xr=xt((oh,da)=>{"use strict";var Af=ur();da.exports=zf;function zf(e){return e.cmp(new Af(0))}});var Qe=xt((ah,wa)=>{"use strict";var kr=Yn(),ga=Xr();wa.exports=Lf;function Lf(e,t){var n=ga(e),r=ga(t);if(n===0)return[kr(0),kr(1)];if(r===0)return[kr(0),kr(0)];r<0&&(e=e.neg(),t=t.neg());var i=e.gcd(t);return i.cmpn(1)?[e.div(i),t.div(i)]:[e,t]}});var Hn=xt((sh,xa)=>{"use strict";var Ef=Qe();xa.exports=Rf;function Rf(e,t){return Ef(e[0].mul(t[1]),e[1].mul(t[0]))}});var Yr=xt((uh,Pa)=>{"use strict";var ya=ca(),Ma=Xn(),Ee=Yn(),ba=va(),If=Qe(),Of=Hn();Pa.exports=Ta;function Ta(e,t){if(ya(e))return t?Of(e,Ta(t)):[e[0].clone(),e[1].clone()];var n=0,r,i;if(Ma(e))r=e.clone();else if(typeof e=="string")r=ba(e);else{if(e===0)return[Ee(0),Ee(1)];if(e===Math.floor(e))r=Ee(e);else{for(;e!==Math.floor(e);)e=e*Math.pow(2,256),n-=256;r=Ee(e)}}if(ya(t))r.mul(t[1]),i=t[0].clone();else if(Ma(t))i=t.clone();else if(typeof t=="string")i=ba(t);else if(!t)i=Ee(1);else if(t===Math.floor(t))i=Ee(t);else{for(;t!==Math.floor(t);)t=t*Math.pow(2,256),n+=256;i=Ee(t)}return n>0?r=r.ushln(n):n<0&&(i=i.ushln(-n)),If(r,i)}});var _a=xt((fh,Sa)=>{"use strict";Sa.exports=mf;function mf(e,t){return e[0].mul(t[1]).cmp(t[0].mul(e[1]))}});var Da=xt((ch,Ba)=>{"use strict";var Vf=Xr();Ba.exports=qf;function qf(e){var t=e.length,n=e.words,r=0;if(t===1)r=n[0];else if(t===2)r=n[0]+n[1]*67108864;else for(var i=0;i<t;i++){var o=n[i];r+=o*Math.pow(67108864,i)}return Vf(e)*r}});var Aa=xt((lh,Ga)=>{"use strict";var Ua=Cr(),Fa=rr().countTrailingZeros;Ga.exports=Nf;function Nf(e){var t=Fa(Ua.lo(e));if(t<32)return t;var n=Fa(Ua.hi(e));return n>20?52:n+32}});var La=xt((hh,za)=>{"use strict";var Zn=Da(),Cf=Aa();za.exports=Xf;function Xf(e){var t=e[0],n=e[1];if(t.cmpn(0)===0)return 0;var r=t.abs().divmod(n.abs()),i=r.div,o=Zn(i),s=r.mod,f=t.negative!==n.negative?-1:1;if(s.cmpn(0)===0)return f*o;if(o){var h=Cf(o)+4,p=Zn(s.ushln(h).divRound(n));return f*(o+p*Math.pow(2,-h))}else{var g=n.bitLength()-s.bitLength()+53,p=Zn(s.ushln(g).divRound(n));return g<1023?f*p*Math.pow(2,-g):(p*=Math.pow(2,-1023),f*p*Math.pow(2,1023-g))}}});var Ra=xt((ph,Ea)=>{"use strict";Ea.exports=Yf;var kf=Yr();function Yf(e){for(var t=new Array(e.length),n=0;n<e.length;++n)t[n]=kf(e[n]);return t}});var Va=xt((vh,ma)=>{"use strict";var $n=Cr(),Ia=Math.pow(2,-1074),Oa=-1>>>0;ma.exports=Hf;function Hf(e,t){if(isNaN(e)||isNaN(t))return NaN;if(e===t)return e;if(e===0)return t<0?-Ia:Ia;var n=$n.hi(e),r=$n.lo(e);return t>e==e>0?r===Oa?(n+=1,r=0):r+=1:r===0?(r=Oa,n-=1):r-=1,$n.pack(r,n)}});var Wn=xt((dh,qa)=>{"use strict";var Zf=Qe();qa.exports=$f;function $f(e,t){return Zf(e[0].mul(t[0]),e[1].mul(t[1]))}});var Kn=xt((gh,Na)=>{"use strict";var Wf=Qe();Na.exports=Kf;function Kf(e,t){return Wf(e[0].mul(t[1]).sub(e[1].mul(t[0])),e[1].mul(t[1]))}});var ka=xt((wh,Xa)=>{"use strict";var Ca=Xr();Xa.exports=Qf;function Qf(e){return Ca(e[0])*Ca(e[1])}});var Ha=xt((xh,Ya)=>{"use strict";var Jf=Kn();Ya.exports=jf;function jf(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=Jf(e[i],t[i]);return r}});var $a=xt((yh,Za)=>{"use strict";var tc=Qe();Za.exports=ec;function ec(e,t){return tc(e[0].mul(t[1]).add(t[0].mul(e[1])),e[1].mul(t[1]))}});var Ka=xt((Mh,Wa)=>{"use strict";var rc=$a();Wa.exports=nc;function nc(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=rc(e[i],t[i]);return r}});var Ja=xt((bh,Qa)=>{"use strict";var ic=Yr(),oc=Wn();Qa.exports=ac;function ac(e,t){for(var n=ic(t),r=e.length,i=new Array(r),o=0;o<r;++o)i[o]=oc(e[o],n);return i}});var rs=xt((Th,es)=>{"use strict";es.exports=hc;var ja=Wn(),sc=Hn(),uc=Kn(),fc=ka(),Qn=Ha(),cc=Ka(),lc=Ja();function ts(e,t){return uc(ja(e[0],t[1]),ja(e[1],t[0]))}function hc(e,t,n,r){var i=Qn(t,e),o=Qn(r,n),s=ts(i,o);if(fc(s)===0)return null;var f=Qn(e,n),h=ts(o,f),p=sc(h,s),g=lc(i,p),D=cc(e,g);return D}});var ls=xt((Ph,cs)=>{"use strict";cs.exports=Pc;var pc=po(),jn=ra(),as=ia(),ns=Yr(),is=_a(),Jn=La(),Hr=Ra(),oe=Va(),vc=rs();function os(e){var t=Jn(e);return[oe(t,-1/0),oe(t,1/0)]}function dc(e,t){for(var n=new Array(t.length),r=0;r<t.length;++r){var i=t[r],o=e[i[0]],s=e[i[1]];n[r]=[oe(Math.min(o[0],s[0]),-1/0),oe(Math.min(o[1],s[1]),-1/0),oe(Math.max(o[0],s[0]),1/0),oe(Math.max(o[1],s[1]),1/0)]}return n}function ss(e){for(var t=new Array(e.length),n=0;n<e.length;++n){var r=e[n];t[n]=[oe(r[0],-1/0),oe(r[1],-1/0),oe(r[0],1/0),oe(r[1],1/0)]}return t}function gc(e,t,n){var r=[];return jn(n,function(i,o){var s=t[i],f=t[o];if(!(s[0]===f[0]||s[0]===f[1]||s[1]===f[0]||s[1]===f[1])){var h=e[s[0]],p=e[s[1]],g=e[f[0]],D=e[f[1]];as(h,p,g,D)&&r.push([i,o])}}),r}function wc(e,t,n,r){var i=[];return jn(n,r,function(o,s){var f=t[o];if(!(f[0]===s||f[1]===s)){var h=e[s],p=e[f[0]],g=e[f[1]];as(p,g,h,h)&&i.push([o,s])}}),i}function xc(e,t,n,r,i){var o,s,f=e.map(function(et){return[ns(et[0]),ns(et[1])]});for(o=0;o<n.length;++o){var h=n[o];s=h[0];var p=h[1],g=t[s],D=t[p],X=vc(Hr(e[g[0]]),Hr(e[g[1]]),Hr(e[D[0]]),Hr(e[D[1]]));if(X){var N=e.length;e.push([Jn(X[0]),Jn(X[1])]),f.push(X),r.push([s,N],[p,N])}}for(r.sort(function(et,rt){if(et[0]!==rt[0])return et[0]-rt[0];var U=f[et[1]],a=f[rt[1]];return is(U[0],a[0])||is(U[1],a[1])}),o=r.length-1;o>=0;--o){var I=r[o];s=I[0];var V=t[s],q=V[0],Y=V[1],K=e[q],Q=e[Y];if((K[0]-Q[0]||K[1]-Q[1])<0){var tt=q;q=Y,Y=tt}V[0]=q;var H=V[1]=I[1],W;for(i&&(W=V[2]);o>0&&r[o-1][0]===s;){var I=r[--o],st=I[1];i?t.push([H,st,W]):t.push([H,st]),H=st}i?t.push([H,Y,W]):t.push([H,Y])}return f}function us(e,t,n){for(var r=t.length,i=new pc(r),o=[],s=0;s<t.length;++s){var f=t[s],h=os(f[0]),p=os(f[1]);o.push([oe(h[0],-1/0),oe(p[0],-1/0),oe(h[1],1/0),oe(p[1],1/0)])}jn(o,function(I,V){i.link(I,V)});for(var g=!0,D=new Array(r),s=0;s<r;++s){var X=i.find(s);X!==s&&(g=!1,e[X]=[Math.min(e[s][0],e[X][0]),Math.min(e[s][1],e[X][1])])}if(g)return null;for(var N=0,s=0;s<r;++s){var X=i.find(s);X===s?(D[s]=N,e[N++]=e[s]):D[s]=-1}e.length=N;for(var s=0;s<r;++s)D[s]<0&&(D[s]=D[i.find(s)]);return D}function yc(e,t){return e[0]-t[0]||e[1]-t[1]}function Mc(e,t){var n=e[0]-t[0]||e[1]-t[1];return n||(e[2]<t[2]?-1:e[2]>t[2]?1:0)}function fs(e,t,n){if(e.length!==0){if(t)for(var r=0;r<e.length;++r){var i=e[r],o=t[i[0]],s=t[i[1]];i[0]=Math.min(o,s),i[1]=Math.max(o,s)}else for(var r=0;r<e.length;++r){var i=e[r],o=i[0],s=i[1];i[0]=Math.min(o,s),i[1]=Math.max(o,s)}n?e.sort(Mc):e.sort(yc);for(var f=1,r=1;r<e.length;++r){var h=e[r-1],p=e[r];p[0]===h[0]&&p[1]===h[1]&&(!n||p[2]===h[2])||(e[f++]=p)}e.length=f}}function bc(e,t,n){var r=us(e,[],ss(e));return fs(t,r,n),!!r}function Tc(e,t,n){var r=dc(e,t),i=gc(e,t,r),o=ss(e),s=wc(e,t,r,o),f=xc(e,t,i,s,n),h=us(e,f,o);return fs(t,h,n),h?!0:i.length>0||s.length>0}function Pc(e,t,n){var r;if(n){r=t;for(var i=new Array(t.length),o=0;o<t.length;++o){var s=t[o];i[o]=[s[0],s[1],n[o]]}t=i}for(var f=bc(e,t,!!n);Tc(e,t,!!n);)f=!0;if(n&&f){r.length=0,n.length=0;for(var o=0;o<t.length;++o){var s=t[o];r.push([s[0],s[1]]),n.push(s[2])}}return f}});function ne(e,t,n,r,i,o,s){let f=e.createTexture({label:t,size:{width:n,height:r},format:o,usage:s,mipLevelCount:i,sampleCount:1,dimension:"2d"}),h=f.createView(),p=[];for(let D=0;D<i;D++)p.push(f.createView({label:t,format:o,dimension:"2d",aspect:"all",baseMipLevel:D,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1}));let g=e.createSampler({label:`${t} sampler`,addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"});return{size:{width:n,height:r},texture:f,view:h,mip_view:p,sampler:g}}function qt(e){return e.canvas?navigator.gpu?.getPreferredCanvasFormat():e.context.getPreferredFormat()}function pe(e,t,n,r){r=r||qt(e);let i=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,s=ne(e.device,t,n.width,n.height,1,r,i);e.device.queue.writeTexture({texture:s.texture},n.data,{bytesPerRow:4*n.width},{width:n.width,height:n.height});let f={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return s.sampler=e.device.createSampler(f),s}async function ve(e,t,n,r){let o=await(await fetch(n)).blob();r=r||qt(e);let s=await createImageBitmap(o),f=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,p=ne(e.device,t,s.width,s.height,1,r,f);e.device.queue.copyExternalImageToTexture({source:s},{texture:p.texture},{width:s.width,height:s.height});let g={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return p.sampler=e.device.createSampler(g),p}var vi="const BLOOM_MIP_COUNT:i32=7;const MODE_PREFILTER:u32=0u;const MODE_DOWNSAMPLE:u32=1u;const MODE_UPSAMPLE_FIRST:u32=2u;const MODE_UPSAMPLE:u32=3u;const EPSILON:f32=1.0e-4;struct bloom_param{parameters:vec4<f32>,combine_constant:f32,doop:u32,ferp:u32,}struct mode_lod_param{mode_lod:u32,}@group(0)@binding(0)var output_texture:texture_storage_2d<rgba16float,write>;@group(0)@binding(1)var input_texture:texture_2d<f32>;@group(0)@binding(2)var bloom_texture:texture_2d<f32>;@group(0)@binding(3)var samp:sampler;@group(0)@binding(4)var<uniform> param:bloom_param;@group(0)@binding(5)var<uniform> pc:mode_lod_param;fn QuadraticThreshold(color:vec4<f32>,threshold:f32,curve:vec3<f32>)->vec4<f32>{let brightness=max(max(color.r,color.g),color.b);var rq:f32=clamp(brightness-curve.x,0.0,curve.y);rq=curve.z*(rq*rq);let ret_color=color*max(rq,brightness-threshold)/max(brightness,EPSILON);return ret_color;}fn Prefilter(color:vec4<f32>,uv:vec2<f32>)->vec4<f32>{let clamp_value=20.0;var c=min(vec4<f32>(clamp_value),color);c=QuadraticThreshold(color,param.parameters.x,param.parameters.yzw);return c;}fn DownsampleBox13(tex:texture_2d<f32>,lod:f32,uv:vec2<f32>,tex_size:vec2<f32>)->vec3<f32>{let A=textureSampleLevel(tex,samp,uv,lod).rgb;let texel_size=tex_size*0.5;let B=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-1.0,-1.0),lod).rgb;let C=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-1.0,1.0),lod).rgb;let D=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(1.0,1.0),lod).rgb;let E=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(1.0,-1.0),lod).rgb;let F=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-2.0,-2.0),lod).rgb;let G=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-2.0,0.0),lod).rgb;let H=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(0.0,2.0),lod).rgb;let I=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(2.0,2.0),lod).rgb;let J=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(2.0,2.0),lod).rgb;let K=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(2.0,0.0),lod).rgb;let L=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(-2.0,-2.0),lod).rgb;let M=textureSampleLevel(tex,samp,uv+texel_size*vec2<f32>(0.0,-2.0),lod).rgb;var result:vec3<f32>=vec3<f32>(0.0);result=result+(B+C+D+E)*0.5;result=result+(F+G+A+M)*0.125;result=result+(G+H+I+A)*0.125;result=result+(A+I+J+K)*0.125;result=result+(M+A+K+L)*0.125;result=result*0.25;return result;}fn UpsampleTent9(tex:texture_2d<f32>,lod:f32,uv:vec2<f32>,texel_size:vec2<f32>,radius:f32)->vec3<f32>{let offset=texel_size.xyxy*vec4<f32>(1.0,1.0,-1.0,0.0)*radius;var result:vec3<f32>=textureSampleLevel(tex,samp,uv,lod).rgb*4.0;result=result+textureSampleLevel(tex,samp,uv-offset.xy,lod).rgb;result=result+textureSampleLevel(tex,samp,uv-offset.wy,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv-offset.zy,lod).rgb;result=result+textureSampleLevel(tex,samp,uv+offset.zw,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv+offset.xw,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv+offset.zy,lod).rgb;result=result+textureSampleLevel(tex,samp,uv+offset.wy,lod).rgb*2.0;result=result+textureSampleLevel(tex,samp,uv+offset.xy,lod).rgb;return result*(1.0/16.0);}fn combine(ex_color:vec3<f32>,color_to_add:vec3<f32>,combine_constant:f32)->vec3<f32>{let existing_color=ex_color+(-color_to_add);let blended_color=(combine_constant*existing_color)+color_to_add;return blended_color;}@compute @workgroup_size(8,4,1)fn cs_main(@builtin(global_invocation_id)global_invocation_id:vec3<u32>){let mode=pc.mode_lod>>16u;let lod=pc.mode_lod&65535u;let imgSize=textureDimensions(output_texture);if(global_invocation_id.x<u32(imgSize.x)&&global_invocation_id.y<u32(imgSize.y)){var texCoords:vec2<f32>=vec2<f32>(f32(global_invocation_id.x)/f32(imgSize.x),f32(global_invocation_id.y)/f32(imgSize.y));texCoords=texCoords+(1.0/vec2<f32>(imgSize))*0.5;let texSize=vec2<f32>(textureDimensions(input_texture,i32(lod)));var color:vec4<f32>=vec4<f32>(1.0);if(mode==MODE_PREFILTER){color=vec4<f32>(DownsampleBox13(input_texture,f32(lod),texCoords,1.0/texSize),1.0);color=Prefilter(color,texCoords);}else if(mode==MODE_DOWNSAMPLE){color=vec4<f32>(DownsampleBox13(input_texture,f32(lod),texCoords,1.0/texSize),1.0);}else if(mode==MODE_UPSAMPLE_FIRST){let bloomTexSize=textureDimensions(input_texture,i32(lod)+1);let sampleScale=1.0;let upsampledTexture=UpsampleTent9(input_texture,f32(lod)+1.0,texCoords,1.0/vec2<f32>(bloomTexSize),sampleScale);let existing=textureSampleLevel(input_texture,samp,texCoords,f32(lod)).rgb;color=vec4<f32>(combine(existing,upsampledTexture,param.combine_constant),1.0);}else if(mode==MODE_UPSAMPLE){let bloomTexSize=textureDimensions(bloom_texture,i32(lod)+1);let sampleScale=1.0;let upsampledTexture=UpsampleTent9(bloom_texture,f32(lod)+1.0,texCoords,1.0/vec2<f32>(bloomTexSize),sampleScale);let existing=textureSampleLevel(input_texture,samp,texCoords,f32(lod)).rgb;color=vec4<f32>(combine(existing,upsampledTexture,param.combine_constant),1.0);}textureStore(output_texture,vec2<i32>(global_invocation_id.xy),color);}}";var ue=7,Xs=0,di=1,ks=2,gi=3,wi={type:"cobalt:bloom",refs:[{name:"emissive",type:"textureView",format:"rgba16",access:"read"},{name:"hdr",type:"textureView",format:"rgba16",access:"read"},{name:"bloom",type:"textureView",format:"rgba16",access:"readwrite"}],onInit:async function(e,t={}){return Ys(e,t)},onRun:function(e,t,n){Hs(e,t.data,n)},onDestroy:function(e,t){yi(t)},onResize:function(e,t){Zs(e,t)},onViewportPosition:function(e,t){}};function Ys(e,t){let{device:n}=e,r=e.viewport.width,i=e.viewport.height,o={compute_pipeline:null,bind_group:[],bind_group_layout:[],bind_groups_textures:[],buffers:[]},s=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.COMPUTE,storageTexture:{access:"write-only",format:"rgba16float",viewDimension:"2d"}},{binding:1,visibility:GPUShaderStage.COMPUTE,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}},{binding:2,visibility:GPUShaderStage.COMPUTE,texture:{sampleType:"float",viewDimension:"2d",multisampled:!1}},{binding:3,visibility:GPUShaderStage.COMPUTE,sampler:{}},{binding:4,visibility:GPUShaderStage.COMPUTE,buffer:{type:"uniform"}},{binding:5,visibility:GPUShaderStage.COMPUTE,buffer:{type:"uniform"}}]});o.bind_group_layout.push(s),o.bind_groups_textures.push(ne(n,"bloom downsampler image 0",r/2,i/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),o.bind_groups_textures.push(ne(n,"bloom downsampler image 1",r/2,i/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),o.bind_groups_textures.push(t.refs.bloom.data);let f=n.createPipelineLayout({bindGroupLayouts:o.bind_group_layout}),h=n.createComputePipeline({layout:f,compute:{module:n.createShaderModule({code:vi}),entryPoint:"cs_main"}});return xi(e,o,t),o.compute_pipeline=h,o}function xi(e,t,n){let{refs:r}=n,{device:i}=e,o=n.options.bloom_threshold??.1,s=n.options.bloom_knee??.2,f=n.options.bloom_combine_constant??.68,h=new Float32Array([o,o-s,s*2,.25/s,f,0,0,0]),p=i.createBuffer({label:"bloom static parameters buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});t.buffers.push(p),new Float32Array(p.getMappedRange()).set(h),p.unmap(),t.bind_group.length=0,t.params_buf=p,t.bind_group.push(Ne(i,t,t.bind_groups_textures[0].mip_view[0],r.emissive.data.view,r.hdr.data.view,r.hdr.data.sampler,p,Xs<<16|0));for(let D=1;D<ue;D++)t.bind_group.push(Ne(i,t,t.bind_groups_textures[1].mip_view[D],t.bind_groups_textures[0].view,r.hdr.data.view,r.hdr.data.sampler,p,di<<16|D-1)),t.bind_group.push(Ne(i,t,t.bind_groups_textures[0].mip_view[D],t.bind_groups_textures[1].view,r.hdr.data.view,r.hdr.data.sampler,p,di<<16|D));t.bind_group.push(Ne(i,t,t.bind_groups_textures[2].mip_view[ue-1],t.bind_groups_textures[0].view,r.hdr.data.view,r.hdr.data.sampler,p,ks<<16|ue-2));let g=!0;for(let D=ue-2;D>=0;D--)g?(t.bind_group.push(Ne(i,t,t.bind_groups_textures[1].mip_view[D],t.bind_groups_textures[0].view,t.bind_groups_textures[2].view,r.hdr.data.sampler,p,gi<<16|D)),g=!1):(t.bind_group.push(Ne(i,t,t.bind_groups_textures[2].mip_view[D],t.bind_groups_textures[0].view,t.bind_groups_textures[1].view,r.hdr.data.sampler,p,gi<<16|D)),g=!0)}function Ne(e,t,n,r,i,o,s,f){let h=new Uint32Array([f]),p=e.createBuffer({label:"bloom static mode_lod buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});return t.buffers.push(p),new Uint32Array(p.getMappedRange()).set(h),p.unmap(),e.createBindGroup({label:"bloom bind group layout",layout:t.bind_group_layout[0],entries:[{binding:0,resource:n},{binding:1,resource:r},{binding:2,resource:i},{binding:3,resource:o},{binding:4,resource:{buffer:s}},{binding:5,resource:{buffer:p}}]})}function Hs(e,t,n){let f=0,h=n.beginComputePass({label:"bloom Compute Pass"});h.setPipeline(t.compute_pipeline),h.setBindGroup(0,t.bind_group[f]),f+=1;let p=lr(0,t.bind_groups_textures[0]);h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);for(let g=1;g<ue;g++)p=lr(g,t.bind_groups_textures[0]),h.setBindGroup(0,t.bind_group[f]),f+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1),h.setBindGroup(0,t.bind_group[f]),f+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.setBindGroup(0,t.bind_group[f]),f+=1,p=lr(ue-1,t.bind_groups_textures[2]),h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);for(let g=ue-2;g>=0;g--)p=lr(g,t.bind_groups_textures[2]),h.setBindGroup(0,t.bind_group[f]),f+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.end()}function lr(e,t){let n=t.size.width,r=t.size.height;for(let i=0;i<e;i++)n/=2,r/=2;return{width:n,height:r,depthOrArrayLayers:1}}function Zs(e,t){let{device:n}=e,r=t.data;yi(r),r.bind_groups_textures.push(ne(n,"bloom downsampler image 0",e.viewport.width/2,e.viewport.height/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),r.bind_groups_textures.push(ne(n,"bloom downsampler image 1",e.viewport.width/2,e.viewport.height/2,ue,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),r.bind_groups_textures.push(t.refs.bloom.data),xi(e,r,t)}function yi(e){for(let t of e.bind_groups_textures)t.texture.destroy();for(let t of e.buffers)t.destroy();e.buffers.length=0,e.bind_groups_textures.length=0}var Mi="struct DisplacementParameters{offset:vec2<f32>,scale:f32,};@group(0)@binding(0)var<uniform> uniforms:DisplacementParameters;@group(0)@binding(1)var colorTexture:texture_2d<f32>;@group(0)@binding(2)var colorSampler:sampler;@group(0)@binding(3)var noiseTexture:texture_2d<f32>;@group(0)@binding(4)var noiseSampler:sampler;@group(0)@binding(5)var displacementTexture:texture_2d<f32>;struct VertexIn{@builtin(vertex_index)vertexIndex:u32,};struct VertexOut{@builtin(position)position:vec4<f32>,@location(0)uv:vec2<f32>,};@vertex fn main_vertex(in:VertexIn)->VertexOut{const corners=array<vec2<f32>,4>(vec2<f32>(-1,-1),vec2<f32>(1,-1),vec2<f32>(-1,1),vec2<f32>(1,1),);let screenPosition=corners[in.vertexIndex];var out:VertexOut;out.position=vec4<f32>(screenPosition,0,1);out.uv=(0.5+0.5*screenPosition*vec2<f32>(1,-1));return out;}struct FragmentOut{@location(0)color:vec4<f32>,};@fragment fn main_fragment(in:VertexOut)->FragmentOut{let noiseTextureDimensions=vec2<f32>(textureDimensions(noiseTexture,0));let noiseUv=in.uv+uniforms.offset/noiseTextureDimensions;var noise=textureSample(noiseTexture,noiseSampler,noiseUv).rg;noise-=0.5;noise*=uniforms.scale/noiseTextureDimensions;let displacement=textureSample(displacementTexture,colorSampler,in.uv).r;noise*=displacement;let colorUv=in.uv+noise;var out:FragmentOut;out.color=textureSample(colorTexture,colorSampler,colorUv);return out;}";var hr=class{device;targetFormat;renderPipeline;colorSampler;noiseSampler;displacementParametersBuffer;renderBundle=null;colorTextureView;noiseMapTextureView;displacementTextureView;constructor(t){this.device=t.device,this.targetFormat=t.targetFormat,this.colorTextureView=t.colorTextureView,this.noiseMapTextureView=t.noiseMapTextureView,this.displacementTextureView=t.displacementTextureView,this.displacementParametersBuffer=t.displacementParametersBuffer;let n=this.device.createShaderModule({label:"DisplacementComposition shader module",code:Mi});this.renderPipeline=this.device.createRenderPipeline({label:"DisplacementComposition renderpipeline",layout:"auto",vertex:{module:n,entryPoint:"main_vertex"},fragment:{module:n,entryPoint:"main_fragment",targets:[{format:t.targetFormat}]},primitive:{cullMode:"none",topology:"triangle-strip"}}),this.noiseSampler=this.device.createSampler({label:"DisplacementComposition noisesampler",addressModeU:"repeat",addressModeV:"repeat",addressModeW:"repeat",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"}),this.colorSampler=this.device.createSampler({label:"DisplacementComposition colorSampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"})}getRenderBundle(){return this.renderBundle||(this.renderBundle=this.buildRenderBundle()),this.renderBundle}destroy(){}setColorTextureView(t){this.colorTextureView=t,this.renderBundle=null}setNoiseMapTextureView(t){this.noiseMapTextureView=t,this.renderBundle=null}setDisplacementTextureView(t){this.displacementTextureView=t,this.renderBundle=null}buildRenderBundle(){let t=this.device.createBindGroup({label:"DisplacementComposition bindgroup 0",layout:this.renderPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.displacementParametersBuffer.bufferGpu}},{binding:1,resource:this.colorTextureView},{binding:2,resource:this.colorSampler},{binding:3,resource:this.noiseMapTextureView},{binding:4,resource:this.noiseSampler},{binding:5,resource:this.displacementTextureView}]}),n=this.device.createRenderBundleEncoder({label:"DisplacementComposition renderbundle encoder",colorFormats:[this.targetFormat]});return n.setPipeline(this.renderPipeline),n.setBindGroup(0,t),n.draw(4),n.finish({label:"DisplacementComposition renderbundle"})}};var pr=class{device;bufferGpu;needsUpdate=!0;constructor(t){this.device=t.device,this.bufferGpu=this.device.createBuffer({label:"DisplacementParametersBuffer buffer",size:16,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.setParameters(t.initialParameters)}setParameters(t){this.device.queue.writeBuffer(this.bufferGpu,0,new Float32Array([t.offsetX,t.offsetY,t.scale]))}destroy(){this.bufferGpu.destroy()}};var bi="struct TransformData{mvpMatrix:mat4x4<f32>,};@group(0)@binding(0)var<uniform> transformUBO:TransformData;struct VertexIn{@location(0)position:vec2<f32>,};struct VertexOut{@builtin(position)position:vec4<f32>,};@vertex fn main_vertex(in:VertexIn)->VertexOut{var output:VertexOut;output.position=transformUBO.mvpMatrix*vec4<f32>(in.position,0.0,1.0);return output;}struct FragmentOut{@location(0)color:vec4<f32>,};@fragment fn main_fragment()->FragmentOut{var out:FragmentOut;out.color=vec4<f32>(1.0,1.0,1.0,1.0);return out;}";function $s(e,t){return class extends e{constructor(...n){super(...n),t(this)}}}var Ws=$s(Array,e=>e.fill(0)),Tt=1e-6;function Ks(e){function t(R=0,m=0){let C=new e(2);return R!==void 0&&(C[0]=R,m!==void 0&&(C[1]=m)),C}let n=t;function r(R,m,C){let u=C??new e(2);return u[0]=R,u[1]=m,u}function i(R,m){let C=m??new e(2);return C[0]=Math.ceil(R[0]),C[1]=Math.ceil(R[1]),C}function o(R,m){let C=m??new e(2);return C[0]=Math.floor(R[0]),C[1]=Math.floor(R[1]),C}function s(R,m){let C=m??new e(2);return C[0]=Math.round(R[0]),C[1]=Math.round(R[1]),C}function f(R,m=0,C=1,u){let _=u??new e(2);return _[0]=Math.min(C,Math.max(m,R[0])),_[1]=Math.min(C,Math.max(m,R[1])),_}function h(R,m,C){let u=C??new e(2);return u[0]=R[0]+m[0],u[1]=R[1]+m[1],u}function p(R,m,C,u){let _=u??new e(2);return _[0]=R[0]+m[0]*C,_[1]=R[1]+m[1]*C,_}function g(R,m){let C=R[0],u=R[1],_=m[0],x=m[1],y=Math.sqrt(C*C+u*u),d=Math.sqrt(_*_+x*x),P=y*d,E=P&&rt(R,m)/P;return Math.acos(E)}function D(R,m,C){let u=C??new e(2);return u[0]=R[0]-m[0],u[1]=R[1]-m[1],u}let X=D;function N(R,m){return Math.abs(R[0]-m[0])<Tt&&Math.abs(R[1]-m[1])<Tt}function I(R,m){return R[0]===m[0]&&R[1]===m[1]}function V(R,m,C,u){let _=u??new e(2);return _[0]=R[0]+C*(m[0]-R[0]),_[1]=R[1]+C*(m[1]-R[1]),_}function q(R,m,C,u){let _=u??new e(2);return _[0]=R[0]+C[0]*(m[0]-R[0]),_[1]=R[1]+C[1]*(m[1]-R[1]),_}function Y(R,m,C){let u=C??new e(2);return u[0]=Math.max(R[0],m[0]),u[1]=Math.max(R[1],m[1]),u}function K(R,m,C){let u=C??new e(2);return u[0]=Math.min(R[0],m[0]),u[1]=Math.min(R[1],m[1]),u}function Q(R,m,C){let u=C??new e(2);return u[0]=R[0]*m,u[1]=R[1]*m,u}let tt=Q;function H(R,m,C){let u=C??new e(2);return u[0]=R[0]/m,u[1]=R[1]/m,u}function W(R,m){let C=m??new e(2);return C[0]=1/R[0],C[1]=1/R[1],C}let st=W;function et(R,m,C){let u=C??new e(3),_=R[0]*m[1]-R[1]*m[0];return u[0]=0,u[1]=0,u[2]=_,u}function rt(R,m){return R[0]*m[0]+R[1]*m[1]}function U(R){let m=R[0],C=R[1];return Math.sqrt(m*m+C*C)}let a=U;function v(R){let m=R[0],C=R[1];return m*m+C*C}let T=v;function M(R,m){let C=R[0]-m[0],u=R[1]-m[1];return Math.sqrt(C*C+u*u)}let S=M;function L(R,m){let C=R[0]-m[0],u=R[1]-m[1];return C*C+u*u}let O=L;function B(R,m){let C=m??new e(2),u=R[0],_=R[1],x=Math.sqrt(u*u+_*_);return x>1e-5?(C[0]=u/x,C[1]=_/x):(C[0]=0,C[1]=0),C}function l(R,m){let C=m??new e(2);return C[0]=-R[0],C[1]=-R[1],C}function G(R,m){let C=m??new e(2);return C[0]=R[0],C[1]=R[1],C}let ot=G;function at(R,m,C){let u=C??new e(2);return u[0]=R[0]*m[0],u[1]=R[1]*m[1],u}let ut=at;function ft(R,m,C){let u=C??new e(2);return u[0]=R[0]/m[0],u[1]=R[1]/m[1],u}let yt=ft;function pt(R=1,m){let C=m??new e(2),u=Math.random()*2*Math.PI;return C[0]=Math.cos(u)*R,C[1]=Math.sin(u)*R,C}function k(R){let m=R??new e(2);return m[0]=0,m[1]=0,m}function $(R,m,C){let u=C??new e(2),_=R[0],x=R[1];return u[0]=_*m[0]+x*m[4]+m[12],u[1]=_*m[1]+x*m[5]+m[13],u}function F(R,m,C){let u=C??new e(2),_=R[0],x=R[1];return u[0]=m[0]*_+m[4]*x+m[8],u[1]=m[1]*_+m[5]*x+m[9],u}function c(R,m,C,u){let _=u??new e(2),x=R[0]-m[0],y=R[1]-m[1],d=Math.sin(C),P=Math.cos(C);return _[0]=x*P-y*d+m[0],_[1]=x*d+y*P+m[1],_}function b(R,m,C){let u=C??new e(2);return B(R,u),Q(u,m,u)}function w(R,m,C){let u=C??new e(2);return U(R)>m?b(R,m,u):G(R,u)}function z(R,m,C){let u=C??new e(2);return V(R,m,.5,u)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:f,add:h,addScaled:p,angle:g,subtract:D,sub:X,equalsApproximately:N,equals:I,lerp:V,lerpV:q,max:Y,min:K,mulScalar:Q,scale:tt,divScalar:H,inverse:W,invert:st,cross:et,dot:rt,length:U,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:L,distSq:O,normalize:B,negate:l,copy:G,clone:ot,multiply:at,mul:ut,divide:ft,div:yt,random:pt,zero:k,transformMat4:$,transformMat3:F,rotate:c,setLength:b,truncate:w,midpoint:z}}var Ti=new Map;function Ui(e){let t=Ti.get(e);return t||(t=Ks(e),Ti.set(e,t)),t}function Qs(e){function t(d,P,E){let A=new e(3);return d!==void 0&&(A[0]=d,P!==void 0&&(A[1]=P,E!==void 0&&(A[2]=E))),A}let n=t;function r(d,P,E,A){let Z=A??new e(3);return Z[0]=d,Z[1]=P,Z[2]=E,Z}function i(d,P){let E=P??new e(3);return E[0]=Math.ceil(d[0]),E[1]=Math.ceil(d[1]),E[2]=Math.ceil(d[2]),E}function o(d,P){let E=P??new e(3);return E[0]=Math.floor(d[0]),E[1]=Math.floor(d[1]),E[2]=Math.floor(d[2]),E}function s(d,P){let E=P??new e(3);return E[0]=Math.round(d[0]),E[1]=Math.round(d[1]),E[2]=Math.round(d[2]),E}function f(d,P=0,E=1,A){let Z=A??new e(3);return Z[0]=Math.min(E,Math.max(P,d[0])),Z[1]=Math.min(E,Math.max(P,d[1])),Z[2]=Math.min(E,Math.max(P,d[2])),Z}function h(d,P,E){let A=E??new e(3);return A[0]=d[0]+P[0],A[1]=d[1]+P[1],A[2]=d[2]+P[2],A}function p(d,P,E,A){let Z=A??new e(3);return Z[0]=d[0]+P[0]*E,Z[1]=d[1]+P[1]*E,Z[2]=d[2]+P[2]*E,Z}function g(d,P){let E=d[0],A=d[1],Z=d[2],J=P[0],j=P[1],ct=P[2],nt=Math.sqrt(E*E+A*A+Z*Z),it=Math.sqrt(J*J+j*j+ct*ct),vt=nt*it,ht=vt&&rt(d,P)/vt;return Math.acos(ht)}function D(d,P,E){let A=E??new e(3);return A[0]=d[0]-P[0],A[1]=d[1]-P[1],A[2]=d[2]-P[2],A}let X=D;function N(d,P){return Math.abs(d[0]-P[0])<Tt&&Math.abs(d[1]-P[1])<Tt&&Math.abs(d[2]-P[2])<Tt}function I(d,P){return d[0]===P[0]&&d[1]===P[1]&&d[2]===P[2]}function V(d,P,E,A){let Z=A??new e(3);return Z[0]=d[0]+E*(P[0]-d[0]),Z[1]=d[1]+E*(P[1]-d[1]),Z[2]=d[2]+E*(P[2]-d[2]),Z}function q(d,P,E,A){let Z=A??new e(3);return Z[0]=d[0]+E[0]*(P[0]-d[0]),Z[1]=d[1]+E[1]*(P[1]-d[1]),Z[2]=d[2]+E[2]*(P[2]-d[2]),Z}function Y(d,P,E){let A=E??new e(3);return A[0]=Math.max(d[0],P[0]),A[1]=Math.max(d[1],P[1]),A[2]=Math.max(d[2],P[2]),A}function K(d,P,E){let A=E??new e(3);return A[0]=Math.min(d[0],P[0]),A[1]=Math.min(d[1],P[1]),A[2]=Math.min(d[2],P[2]),A}function Q(d,P,E){let A=E??new e(3);return A[0]=d[0]*P,A[1]=d[1]*P,A[2]=d[2]*P,A}let tt=Q;function H(d,P,E){let A=E??new e(3);return A[0]=d[0]/P,A[1]=d[1]/P,A[2]=d[2]/P,A}function W(d,P){let E=P??new e(3);return E[0]=1/d[0],E[1]=1/d[1],E[2]=1/d[2],E}let st=W;function et(d,P,E){let A=E??new e(3),Z=d[2]*P[0]-d[0]*P[2],J=d[0]*P[1]-d[1]*P[0];return A[0]=d[1]*P[2]-d[2]*P[1],A[1]=Z,A[2]=J,A}function rt(d,P){return d[0]*P[0]+d[1]*P[1]+d[2]*P[2]}function U(d){let P=d[0],E=d[1],A=d[2];return Math.sqrt(P*P+E*E+A*A)}let a=U;function v(d){let P=d[0],E=d[1],A=d[2];return P*P+E*E+A*A}let T=v;function M(d,P){let E=d[0]-P[0],A=d[1]-P[1],Z=d[2]-P[2];return Math.sqrt(E*E+A*A+Z*Z)}let S=M;function L(d,P){let E=d[0]-P[0],A=d[1]-P[1],Z=d[2]-P[2];return E*E+A*A+Z*Z}let O=L;function B(d,P){let E=P??new e(3),A=d[0],Z=d[1],J=d[2],j=Math.sqrt(A*A+Z*Z+J*J);return j>1e-5?(E[0]=A/j,E[1]=Z/j,E[2]=J/j):(E[0]=0,E[1]=0,E[2]=0),E}function l(d,P){let E=P??new e(3);return E[0]=-d[0],E[1]=-d[1],E[2]=-d[2],E}function G(d,P){let E=P??new e(3);return E[0]=d[0],E[1]=d[1],E[2]=d[2],E}let ot=G;function at(d,P,E){let A=E??new e(3);return A[0]=d[0]*P[0],A[1]=d[1]*P[1],A[2]=d[2]*P[2],A}let ut=at;function ft(d,P,E){let A=E??new e(3);return A[0]=d[0]/P[0],A[1]=d[1]/P[1],A[2]=d[2]/P[2],A}let yt=ft;function pt(d=1,P){let E=P??new e(3),A=Math.random()*2*Math.PI,Z=Math.random()*2-1,J=Math.sqrt(1-Z*Z)*d;return E[0]=Math.cos(A)*J,E[1]=Math.sin(A)*J,E[2]=Z*d,E}function k(d){let P=d??new e(3);return P[0]=0,P[1]=0,P[2]=0,P}function $(d,P,E){let A=E??new e(3),Z=d[0],J=d[1],j=d[2],ct=P[3]*Z+P[7]*J+P[11]*j+P[15]||1;return A[0]=(P[0]*Z+P[4]*J+P[8]*j+P[12])/ct,A[1]=(P[1]*Z+P[5]*J+P[9]*j+P[13])/ct,A[2]=(P[2]*Z+P[6]*J+P[10]*j+P[14])/ct,A}function F(d,P,E){let A=E??new e(3),Z=d[0],J=d[1],j=d[2];return A[0]=Z*P[0]+J*P[4]+j*P[8],A[1]=Z*P[1]+J*P[5]+j*P[9],A[2]=Z*P[2]+J*P[6]+j*P[10],A}function c(d,P,E){let A=E??new e(3),Z=d[0],J=d[1],j=d[2];return A[0]=Z*P[0]+J*P[4]+j*P[8],A[1]=Z*P[1]+J*P[5]+j*P[9],A[2]=Z*P[2]+J*P[6]+j*P[10],A}function b(d,P,E){let A=E??new e(3),Z=P[0],J=P[1],j=P[2],ct=P[3]*2,nt=d[0],it=d[1],vt=d[2],ht=J*vt-j*it,lt=j*nt-Z*vt,dt=Z*it-J*nt;return A[0]=nt+ht*ct+(J*dt-j*lt)*2,A[1]=it+lt*ct+(j*ht-Z*dt)*2,A[2]=vt+dt*ct+(Z*lt-J*ht)*2,A}function w(d,P){let E=P??new e(3);return E[0]=d[12],E[1]=d[13],E[2]=d[14],E}function z(d,P,E){let A=E??new e(3),Z=P*4;return A[0]=d[Z+0],A[1]=d[Z+1],A[2]=d[Z+2],A}function R(d,P){let E=P??new e(3),A=d[0],Z=d[1],J=d[2],j=d[4],ct=d[5],nt=d[6],it=d[8],vt=d[9],ht=d[10];return E[0]=Math.sqrt(A*A+Z*Z+J*J),E[1]=Math.sqrt(j*j+ct*ct+nt*nt),E[2]=Math.sqrt(it*it+vt*vt+ht*ht),E}function m(d,P,E,A){let Z=A??new e(3),J=[],j=[];return J[0]=d[0]-P[0],J[1]=d[1]-P[1],J[2]=d[2]-P[2],j[0]=J[0],j[1]=J[1]*Math.cos(E)-J[2]*Math.sin(E),j[2]=J[1]*Math.sin(E)+J[2]*Math.cos(E),Z[0]=j[0]+P[0],Z[1]=j[1]+P[1],Z[2]=j[2]+P[2],Z}function C(d,P,E,A){let Z=A??new e(3),J=[],j=[];return J[0]=d[0]-P[0],J[1]=d[1]-P[1],J[2]=d[2]-P[2],j[0]=J[2]*Math.sin(E)+J[0]*Math.cos(E),j[1]=J[1],j[2]=J[2]*Math.cos(E)-J[0]*Math.sin(E),Z[0]=j[0]+P[0],Z[1]=j[1]+P[1],Z[2]=j[2]+P[2],Z}function u(d,P,E,A){let Z=A??new e(3),J=[],j=[];return J[0]=d[0]-P[0],J[1]=d[1]-P[1],J[2]=d[2]-P[2],j[0]=J[0]*Math.cos(E)-J[1]*Math.sin(E),j[1]=J[0]*Math.sin(E)+J[1]*Math.cos(E),j[2]=J[2],Z[0]=j[0]+P[0],Z[1]=j[1]+P[1],Z[2]=j[2]+P[2],Z}function _(d,P,E){let A=E??new e(3);return B(d,A),Q(A,P,A)}function x(d,P,E){let A=E??new e(3);return U(d)>P?_(d,P,A):G(d,A)}function y(d,P,E){let A=E??new e(3);return V(d,P,.5,A)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:f,add:h,addScaled:p,angle:g,subtract:D,sub:X,equalsApproximately:N,equals:I,lerp:V,lerpV:q,max:Y,min:K,mulScalar:Q,scale:tt,divScalar:H,inverse:W,invert:st,cross:et,dot:rt,length:U,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:L,distSq:O,normalize:B,negate:l,copy:G,clone:ot,multiply:at,mul:ut,divide:ft,div:yt,random:pt,zero:k,transformMat4:$,transformMat4Upper3x3:F,transformMat3:c,transformQuat:b,getTranslation:w,getAxis:z,getScaling:R,rotateX:m,rotateY:C,rotateZ:u,setLength:_,truncate:x,midpoint:y}}var Pi=new Map;function vr(e){let t=Pi.get(e);return t||(t=Qs(e),Pi.set(e,t)),t}function Js(e){let t=Ui(e),n=vr(e);function r(c,b,w,z,R,m,C,u,_){let x=new e(12);return x[3]=0,x[7]=0,x[11]=0,c!==void 0&&(x[0]=c,b!==void 0&&(x[1]=b,w!==void 0&&(x[2]=w,z!==void 0&&(x[4]=z,R!==void 0&&(x[5]=R,m!==void 0&&(x[6]=m,C!==void 0&&(x[8]=C,u!==void 0&&(x[9]=u,_!==void 0&&(x[10]=_))))))))),x}function i(c,b,w,z,R,m,C,u,_,x){let y=x??new e(12);return y[0]=c,y[1]=b,y[2]=w,y[3]=0,y[4]=z,y[5]=R,y[6]=m,y[7]=0,y[8]=C,y[9]=u,y[10]=_,y[11]=0,y}function o(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=c[1],w[2]=c[2],w[3]=0,w[4]=c[4],w[5]=c[5],w[6]=c[6],w[7]=0,w[8]=c[8],w[9]=c[9],w[10]=c[10],w[11]=0,w}function s(c,b){let w=b??new e(12),z=c[0],R=c[1],m=c[2],C=c[3],u=z+z,_=R+R,x=m+m,y=z*u,d=R*u,P=R*_,E=m*u,A=m*_,Z=m*x,J=C*u,j=C*_,ct=C*x;return w[0]=1-P-Z,w[1]=d+ct,w[2]=E-j,w[3]=0,w[4]=d-ct,w[5]=1-y-Z,w[6]=A+J,w[7]=0,w[8]=E+j,w[9]=A-J,w[10]=1-y-P,w[11]=0,w}function f(c,b){let w=b??new e(12);return w[0]=-c[0],w[1]=-c[1],w[2]=-c[2],w[4]=-c[4],w[5]=-c[5],w[6]=-c[6],w[8]=-c[8],w[9]=-c[9],w[10]=-c[10],w}function h(c,b,w){let z=w??new e(12);return z[0]=c[0]*b,z[1]=c[1]*b,z[2]=c[2]*b,z[4]=c[4]*b,z[5]=c[5]*b,z[6]=c[6]*b,z[8]=c[8]*b,z[9]=c[9]*b,z[10]=c[10]*b,z}let p=h;function g(c,b,w){let z=w??new e(12);return z[0]=c[0]+b[0],z[1]=c[1]+b[1],z[2]=c[2]+b[2],z[4]=c[4]+b[4],z[5]=c[5]+b[5],z[6]=c[6]+b[6],z[8]=c[8]+b[8],z[9]=c[9]+b[9],z[10]=c[10]+b[10],z}function D(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=c[1],w[2]=c[2],w[4]=c[4],w[5]=c[5],w[6]=c[6],w[8]=c[8],w[9]=c[9],w[10]=c[10],w}let X=D;function N(c,b){return Math.abs(c[0]-b[0])<Tt&&Math.abs(c[1]-b[1])<Tt&&Math.abs(c[2]-b[2])<Tt&&Math.abs(c[4]-b[4])<Tt&&Math.abs(c[5]-b[5])<Tt&&Math.abs(c[6]-b[6])<Tt&&Math.abs(c[8]-b[8])<Tt&&Math.abs(c[9]-b[9])<Tt&&Math.abs(c[10]-b[10])<Tt}function I(c,b){return c[0]===b[0]&&c[1]===b[1]&&c[2]===b[2]&&c[4]===b[4]&&c[5]===b[5]&&c[6]===b[6]&&c[8]===b[8]&&c[9]===b[9]&&c[10]===b[10]}function V(c){let b=c??new e(12);return b[0]=1,b[1]=0,b[2]=0,b[4]=0,b[5]=1,b[6]=0,b[8]=0,b[9]=0,b[10]=1,b}function q(c,b){let w=b??new e(12);if(w===c){let P;return P=c[1],c[1]=c[4],c[4]=P,P=c[2],c[2]=c[8],c[8]=P,P=c[6],c[6]=c[9],c[9]=P,w}let z=c[0],R=c[1],m=c[2],C=c[4],u=c[5],_=c[6],x=c[8],y=c[9],d=c[10];return w[0]=z,w[1]=C,w[2]=x,w[4]=R,w[5]=u,w[6]=y,w[8]=m,w[9]=_,w[10]=d,w}function Y(c,b){let w=b??new e(12),z=c[0],R=c[1],m=c[2],C=c[4],u=c[5],_=c[6],x=c[8],y=c[9],d=c[10],P=d*u-_*y,E=-d*C+_*x,A=y*C-u*x,Z=1/(z*P+R*E+m*A);return w[0]=P*Z,w[1]=(-d*R+m*y)*Z,w[2]=(_*R-m*u)*Z,w[4]=E*Z,w[5]=(d*z-m*x)*Z,w[6]=(-_*z+m*C)*Z,w[8]=A*Z,w[9]=(-y*z+R*x)*Z,w[10]=(u*z-R*C)*Z,w}function K(c){let b=c[0],w=c[1],z=c[2],R=c[4],m=c[5],C=c[6],u=c[8],_=c[9],x=c[10];return b*(m*x-_*C)-R*(w*x-_*z)+u*(w*C-m*z)}let Q=Y;function tt(c,b,w){let z=w??new e(12),R=c[0],m=c[1],C=c[2],u=c[4],_=c[5],x=c[6],y=c[8],d=c[9],P=c[10],E=b[0],A=b[1],Z=b[2],J=b[4],j=b[5],ct=b[6],nt=b[8],it=b[9],vt=b[10];return z[0]=R*E+u*A+y*Z,z[1]=m*E+_*A+d*Z,z[2]=C*E+x*A+P*Z,z[4]=R*J+u*j+y*ct,z[5]=m*J+_*j+d*ct,z[6]=C*J+x*j+P*ct,z[8]=R*nt+u*it+y*vt,z[9]=m*nt+_*it+d*vt,z[10]=C*nt+x*it+P*vt,z}let H=tt;function W(c,b,w){let z=w??V();return c!==z&&(z[0]=c[0],z[1]=c[1],z[2]=c[2],z[4]=c[4],z[5]=c[5],z[6]=c[6]),z[8]=b[0],z[9]=b[1],z[10]=1,z}function st(c,b){let w=b??t.create();return w[0]=c[8],w[1]=c[9],w}function et(c,b,w){let z=w??t.create(),R=b*4;return z[0]=c[R+0],z[1]=c[R+1],z}function rt(c,b,w,z){let R=z===c?c:D(c,z),m=w*4;return R[m+0]=b[0],R[m+1]=b[1],R}function U(c,b){let w=b??t.create(),z=c[0],R=c[1],m=c[4],C=c[5];return w[0]=Math.sqrt(z*z+R*R),w[1]=Math.sqrt(m*m+C*C),w}function a(c,b){let w=b??n.create(),z=c[0],R=c[1],m=c[2],C=c[4],u=c[5],_=c[6],x=c[8],y=c[9],d=c[10];return w[0]=Math.sqrt(z*z+R*R+m*m),w[1]=Math.sqrt(C*C+u*u+_*_),w[2]=Math.sqrt(x*x+y*y+d*d),w}function v(c,b){let w=b??new e(12);return w[0]=1,w[1]=0,w[2]=0,w[4]=0,w[5]=1,w[6]=0,w[8]=c[0],w[9]=c[1],w[10]=1,w}function T(c,b,w){let z=w??new e(12),R=b[0],m=b[1],C=c[0],u=c[1],_=c[2],x=c[4],y=c[5],d=c[6],P=c[8],E=c[9],A=c[10];return c!==z&&(z[0]=C,z[1]=u,z[2]=_,z[4]=x,z[5]=y,z[6]=d),z[8]=C*R+x*m+P,z[9]=u*R+y*m+E,z[10]=_*R+d*m+A,z}function M(c,b){let w=b??new e(12),z=Math.cos(c),R=Math.sin(c);return w[0]=z,w[1]=R,w[2]=0,w[4]=-R,w[5]=z,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function S(c,b,w){let z=w??new e(12),R=c[0],m=c[1],C=c[2],u=c[4],_=c[5],x=c[6],y=Math.cos(b),d=Math.sin(b);return z[0]=y*R+d*u,z[1]=y*m+d*_,z[2]=y*C+d*x,z[4]=y*u-d*R,z[5]=y*_-d*m,z[6]=y*x-d*C,c!==z&&(z[8]=c[8],z[9]=c[9],z[10]=c[10]),z}function L(c,b){let w=b??new e(12),z=Math.cos(c),R=Math.sin(c);return w[0]=1,w[1]=0,w[2]=0,w[4]=0,w[5]=z,w[6]=R,w[8]=0,w[9]=-R,w[10]=z,w}function O(c,b,w){let z=w??new e(12),R=c[4],m=c[5],C=c[6],u=c[8],_=c[9],x=c[10],y=Math.cos(b),d=Math.sin(b);return z[4]=y*R+d*u,z[5]=y*m+d*_,z[6]=y*C+d*x,z[8]=y*u-d*R,z[9]=y*_-d*m,z[10]=y*x-d*C,c!==z&&(z[0]=c[0],z[1]=c[1],z[2]=c[2]),z}function B(c,b){let w=b??new e(12),z=Math.cos(c),R=Math.sin(c);return w[0]=z,w[1]=0,w[2]=-R,w[4]=0,w[5]=1,w[6]=0,w[8]=R,w[9]=0,w[10]=z,w}function l(c,b,w){let z=w??new e(12),R=c[0],m=c[1],C=c[2],u=c[8],_=c[9],x=c[10],y=Math.cos(b),d=Math.sin(b);return z[0]=y*R-d*u,z[1]=y*m-d*_,z[2]=y*C-d*x,z[8]=y*u+d*R,z[9]=y*_+d*m,z[10]=y*x+d*C,c!==z&&(z[4]=c[4],z[5]=c[5],z[6]=c[6]),z}let G=M,ot=S;function at(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=0,w[2]=0,w[4]=0,w[5]=c[1],w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function ut(c,b,w){let z=w??new e(12),R=b[0],m=b[1];return z[0]=R*c[0],z[1]=R*c[1],z[2]=R*c[2],z[4]=m*c[4],z[5]=m*c[5],z[6]=m*c[6],c!==z&&(z[8]=c[8],z[9]=c[9],z[10]=c[10]),z}function ft(c,b){let w=b??new e(12);return w[0]=c[0],w[1]=0,w[2]=0,w[4]=0,w[5]=c[1],w[6]=0,w[8]=0,w[9]=0,w[10]=c[2],w}function yt(c,b,w){let z=w??new e(12),R=b[0],m=b[1],C=b[2];return z[0]=R*c[0],z[1]=R*c[1],z[2]=R*c[2],z[4]=m*c[4],z[5]=m*c[5],z[6]=m*c[6],z[8]=C*c[8],z[9]=C*c[9],z[10]=C*c[10],z}function pt(c,b){let w=b??new e(12);return w[0]=c,w[1]=0,w[2]=0,w[4]=0,w[5]=c,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function k(c,b,w){let z=w??new e(12);return z[0]=b*c[0],z[1]=b*c[1],z[2]=b*c[2],z[4]=b*c[4],z[5]=b*c[5],z[6]=b*c[6],c!==z&&(z[8]=c[8],z[9]=c[9],z[10]=c[10]),z}function $(c,b){let w=b??new e(12);return w[0]=c,w[1]=0,w[2]=0,w[4]=0,w[5]=c,w[6]=0,w[8]=0,w[9]=0,w[10]=c,w}function F(c,b,w){let z=w??new e(12);return z[0]=b*c[0],z[1]=b*c[1],z[2]=b*c[2],z[4]=b*c[4],z[5]=b*c[5],z[6]=b*c[6],z[8]=b*c[8],z[9]=b*c[9],z[10]=b*c[10],z}return{add:g,clone:X,copy:D,create:r,determinant:K,equals:I,equalsApproximately:N,fromMat4:o,fromQuat:s,get3DScaling:a,getAxis:et,getScaling:U,getTranslation:st,identity:V,inverse:Y,invert:Q,mul:H,mulScalar:p,multiply:tt,multiplyScalar:h,negate:f,rotate:S,rotateX:O,rotateY:l,rotateZ:ot,rotation:M,rotationX:L,rotationY:B,rotationZ:G,scale:ut,scale3D:yt,scaling:at,scaling3D:ft,set:i,setAxis:rt,setTranslation:W,translate:T,translation:v,transpose:q,uniformScale:k,uniformScale3D:F,uniformScaling:pt,uniformScaling3D:$}}var Si=new Map;function js(e){let t=Si.get(e);return t||(t=Js(e),Si.set(e,t)),t}function tu(e){let t=vr(e);function n(u,_,x,y,d,P,E,A,Z,J,j,ct,nt,it,vt,ht){let lt=new e(16);return u!==void 0&&(lt[0]=u,_!==void 0&&(lt[1]=_,x!==void 0&&(lt[2]=x,y!==void 0&&(lt[3]=y,d!==void 0&&(lt[4]=d,P!==void 0&&(lt[5]=P,E!==void 0&&(lt[6]=E,A!==void 0&&(lt[7]=A,Z!==void 0&&(lt[8]=Z,J!==void 0&&(lt[9]=J,j!==void 0&&(lt[10]=j,ct!==void 0&&(lt[11]=ct,nt!==void 0&&(lt[12]=nt,it!==void 0&&(lt[13]=it,vt!==void 0&&(lt[14]=vt,ht!==void 0&&(lt[15]=ht)))))))))))))))),lt}function r(u,_,x,y,d,P,E,A,Z,J,j,ct,nt,it,vt,ht,lt){let dt=lt??new e(16);return dt[0]=u,dt[1]=_,dt[2]=x,dt[3]=y,dt[4]=d,dt[5]=P,dt[6]=E,dt[7]=A,dt[8]=Z,dt[9]=J,dt[10]=j,dt[11]=ct,dt[12]=nt,dt[13]=it,dt[14]=vt,dt[15]=ht,dt}function i(u,_){let x=_??new e(16);return x[0]=u[0],x[1]=u[1],x[2]=u[2],x[3]=0,x[4]=u[4],x[5]=u[5],x[6]=u[6],x[7]=0,x[8]=u[8],x[9]=u[9],x[10]=u[10],x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function o(u,_){let x=_??new e(16),y=u[0],d=u[1],P=u[2],E=u[3],A=y+y,Z=d+d,J=P+P,j=y*A,ct=d*A,nt=d*Z,it=P*A,vt=P*Z,ht=P*J,lt=E*A,dt=E*Z,wt=E*J;return x[0]=1-nt-ht,x[1]=ct+wt,x[2]=it-dt,x[3]=0,x[4]=ct-wt,x[5]=1-j-ht,x[6]=vt+lt,x[7]=0,x[8]=it+dt,x[9]=vt-lt,x[10]=1-j-nt,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function s(u,_){let x=_??new e(16);return x[0]=-u[0],x[1]=-u[1],x[2]=-u[2],x[3]=-u[3],x[4]=-u[4],x[5]=-u[5],x[6]=-u[6],x[7]=-u[7],x[8]=-u[8],x[9]=-u[9],x[10]=-u[10],x[11]=-u[11],x[12]=-u[12],x[13]=-u[13],x[14]=-u[14],x[15]=-u[15],x}function f(u,_,x){let y=x??new e(16);return y[0]=u[0]+_[0],y[1]=u[1]+_[1],y[2]=u[2]+_[2],y[3]=u[3]+_[3],y[4]=u[4]+_[4],y[5]=u[5]+_[5],y[6]=u[6]+_[6],y[7]=u[7]+_[7],y[8]=u[8]+_[8],y[9]=u[9]+_[9],y[10]=u[10]+_[10],y[11]=u[11]+_[11],y[12]=u[12]+_[12],y[13]=u[13]+_[13],y[14]=u[14]+_[14],y[15]=u[15]+_[15],y}function h(u,_,x){let y=x??new e(16);return y[0]=u[0]*_,y[1]=u[1]*_,y[2]=u[2]*_,y[3]=u[3]*_,y[4]=u[4]*_,y[5]=u[5]*_,y[6]=u[6]*_,y[7]=u[7]*_,y[8]=u[8]*_,y[9]=u[9]*_,y[10]=u[10]*_,y[11]=u[11]*_,y[12]=u[12]*_,y[13]=u[13]*_,y[14]=u[14]*_,y[15]=u[15]*_,y}let p=h;function g(u,_){let x=_??new e(16);return x[0]=u[0],x[1]=u[1],x[2]=u[2],x[3]=u[3],x[4]=u[4],x[5]=u[5],x[6]=u[6],x[7]=u[7],x[8]=u[8],x[9]=u[9],x[10]=u[10],x[11]=u[11],x[12]=u[12],x[13]=u[13],x[14]=u[14],x[15]=u[15],x}let D=g;function X(u,_){return Math.abs(u[0]-_[0])<Tt&&Math.abs(u[1]-_[1])<Tt&&Math.abs(u[2]-_[2])<Tt&&Math.abs(u[3]-_[3])<Tt&&Math.abs(u[4]-_[4])<Tt&&Math.abs(u[5]-_[5])<Tt&&Math.abs(u[6]-_[6])<Tt&&Math.abs(u[7]-_[7])<Tt&&Math.abs(u[8]-_[8])<Tt&&Math.abs(u[9]-_[9])<Tt&&Math.abs(u[10]-_[10])<Tt&&Math.abs(u[11]-_[11])<Tt&&Math.abs(u[12]-_[12])<Tt&&Math.abs(u[13]-_[13])<Tt&&Math.abs(u[14]-_[14])<Tt&&Math.abs(u[15]-_[15])<Tt}function N(u,_){return u[0]===_[0]&&u[1]===_[1]&&u[2]===_[2]&&u[3]===_[3]&&u[4]===_[4]&&u[5]===_[5]&&u[6]===_[6]&&u[7]===_[7]&&u[8]===_[8]&&u[9]===_[9]&&u[10]===_[10]&&u[11]===_[11]&&u[12]===_[12]&&u[13]===_[13]&&u[14]===_[14]&&u[15]===_[15]}function I(u){let _=u??new e(16);return _[0]=1,_[1]=0,_[2]=0,_[3]=0,_[4]=0,_[5]=1,_[6]=0,_[7]=0,_[8]=0,_[9]=0,_[10]=1,_[11]=0,_[12]=0,_[13]=0,_[14]=0,_[15]=1,_}function V(u,_){let x=_??new e(16);if(x===u){let gt;return gt=u[1],u[1]=u[4],u[4]=gt,gt=u[2],u[2]=u[8],u[8]=gt,gt=u[3],u[3]=u[12],u[12]=gt,gt=u[6],u[6]=u[9],u[9]=gt,gt=u[7],u[7]=u[13],u[13]=gt,gt=u[11],u[11]=u[14],u[14]=gt,x}let y=u[0],d=u[1],P=u[2],E=u[3],A=u[4],Z=u[5],J=u[6],j=u[7],ct=u[8],nt=u[9],it=u[10],vt=u[11],ht=u[12],lt=u[13],dt=u[14],wt=u[15];return x[0]=y,x[1]=A,x[2]=ct,x[3]=ht,x[4]=d,x[5]=Z,x[6]=nt,x[7]=lt,x[8]=P,x[9]=J,x[10]=it,x[11]=dt,x[12]=E,x[13]=j,x[14]=vt,x[15]=wt,x}function q(u,_){let x=_??new e(16),y=u[0],d=u[1],P=u[2],E=u[3],A=u[4],Z=u[5],J=u[6],j=u[7],ct=u[8],nt=u[9],it=u[10],vt=u[11],ht=u[12],lt=u[13],dt=u[14],wt=u[15],gt=it*wt,Ct=dt*vt,Mt=J*wt,bt=dt*j,Ht=J*vt,St=it*j,_t=P*wt,$t=dt*E,Bt=P*vt,Dt=it*E,Wt=P*j,Ut=J*E,Ft=ct*lt,Kt=ht*nt,Gt=A*lt,At=ht*Z,jt=A*nt,Rt=ct*Z,It=y*lt,Se=ht*d,Ot=y*nt,mt=ct*d,_e=y*Z,Vt=A*d,Nt=gt*Z+bt*nt+Ht*lt-(Ct*Z+Mt*nt+St*lt),me=Ct*d+_t*nt+Dt*lt-(gt*d+$t*nt+Bt*lt),Ve=Mt*d+$t*Z+Wt*lt-(bt*d+_t*Z+Ut*lt),qe=St*d+Bt*Z+Ut*nt-(Ht*d+Dt*Z+Wt*nt),Zt=1/(y*Nt+A*me+ct*Ve+ht*qe);return x[0]=Zt*Nt,x[1]=Zt*me,x[2]=Zt*Ve,x[3]=Zt*qe,x[4]=Zt*(Ct*A+Mt*ct+St*ht-(gt*A+bt*ct+Ht*ht)),x[5]=Zt*(gt*y+$t*ct+Bt*ht-(Ct*y+_t*ct+Dt*ht)),x[6]=Zt*(bt*y+_t*A+Ut*ht-(Mt*y+$t*A+Wt*ht)),x[7]=Zt*(Ht*y+Dt*A+Wt*ct-(St*y+Bt*A+Ut*ct)),x[8]=Zt*(Ft*j+At*vt+jt*wt-(Kt*j+Gt*vt+Rt*wt)),x[9]=Zt*(Kt*E+It*vt+mt*wt-(Ft*E+Se*vt+Ot*wt)),x[10]=Zt*(Gt*E+Se*j+_e*wt-(At*E+It*j+Vt*wt)),x[11]=Zt*(Rt*E+Ot*j+Vt*vt-(jt*E+mt*j+_e*vt)),x[12]=Zt*(Gt*it+Rt*dt+Kt*J-(jt*dt+Ft*J+At*it)),x[13]=Zt*(Ot*dt+Ft*P+Se*it-(It*it+mt*dt+Kt*P)),x[14]=Zt*(It*J+Vt*dt+At*P-(_e*dt+Gt*P+Se*J)),x[15]=Zt*(_e*it+jt*P+mt*J-(Ot*J+Vt*it+Rt*P)),x}function Y(u){let _=u[0],x=u[1],y=u[2],d=u[3],P=u[4],E=u[5],A=u[6],Z=u[7],J=u[8],j=u[9],ct=u[10],nt=u[11],it=u[12],vt=u[13],ht=u[14],lt=u[15],dt=ct*lt,wt=ht*nt,gt=A*lt,Ct=ht*Z,Mt=A*nt,bt=ct*Z,Ht=y*lt,St=ht*d,_t=y*nt,$t=ct*d,Bt=y*Z,Dt=A*d,Wt=dt*E+Ct*j+Mt*vt-(wt*E+gt*j+bt*vt),Ut=wt*x+Ht*j+$t*vt-(dt*x+St*j+_t*vt),Ft=gt*x+St*E+Bt*vt-(Ct*x+Ht*E+Dt*vt),Kt=bt*x+_t*E+Dt*j-(Mt*x+$t*E+Bt*j);return _*Wt+P*Ut+J*Ft+it*Kt}let K=q;function Q(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=u[3],Z=u[4],J=u[5],j=u[6],ct=u[7],nt=u[8],it=u[9],vt=u[10],ht=u[11],lt=u[12],dt=u[13],wt=u[14],gt=u[15],Ct=_[0],Mt=_[1],bt=_[2],Ht=_[3],St=_[4],_t=_[5],$t=_[6],Bt=_[7],Dt=_[8],Wt=_[9],Ut=_[10],Ft=_[11],Kt=_[12],Gt=_[13],At=_[14],jt=_[15];return y[0]=d*Ct+Z*Mt+nt*bt+lt*Ht,y[1]=P*Ct+J*Mt+it*bt+dt*Ht,y[2]=E*Ct+j*Mt+vt*bt+wt*Ht,y[3]=A*Ct+ct*Mt+ht*bt+gt*Ht,y[4]=d*St+Z*_t+nt*$t+lt*Bt,y[5]=P*St+J*_t+it*$t+dt*Bt,y[6]=E*St+j*_t+vt*$t+wt*Bt,y[7]=A*St+ct*_t+ht*$t+gt*Bt,y[8]=d*Dt+Z*Wt+nt*Ut+lt*Ft,y[9]=P*Dt+J*Wt+it*Ut+dt*Ft,y[10]=E*Dt+j*Wt+vt*Ut+wt*Ft,y[11]=A*Dt+ct*Wt+ht*Ut+gt*Ft,y[12]=d*Kt+Z*Gt+nt*At+lt*jt,y[13]=P*Kt+J*Gt+it*At+dt*jt,y[14]=E*Kt+j*Gt+vt*At+wt*jt,y[15]=A*Kt+ct*Gt+ht*At+gt*jt,y}let tt=Q;function H(u,_,x){let y=x??I();return u!==y&&(y[0]=u[0],y[1]=u[1],y[2]=u[2],y[3]=u[3],y[4]=u[4],y[5]=u[5],y[6]=u[6],y[7]=u[7],y[8]=u[8],y[9]=u[9],y[10]=u[10],y[11]=u[11]),y[12]=_[0],y[13]=_[1],y[14]=_[2],y[15]=1,y}function W(u,_){let x=_??t.create();return x[0]=u[12],x[1]=u[13],x[2]=u[14],x}function st(u,_,x){let y=x??t.create(),d=_*4;return y[0]=u[d+0],y[1]=u[d+1],y[2]=u[d+2],y}function et(u,_,x,y){let d=y===u?y:g(u,y),P=x*4;return d[P+0]=_[0],d[P+1]=_[1],d[P+2]=_[2],d}function rt(u,_){let x=_??t.create(),y=u[0],d=u[1],P=u[2],E=u[4],A=u[5],Z=u[6],J=u[8],j=u[9],ct=u[10];return x[0]=Math.sqrt(y*y+d*d+P*P),x[1]=Math.sqrt(E*E+A*A+Z*Z),x[2]=Math.sqrt(J*J+j*j+ct*ct),x}function U(u,_,x,y,d){let P=d??new e(16),E=Math.tan(Math.PI*.5-.5*u);if(P[0]=E/_,P[1]=0,P[2]=0,P[3]=0,P[4]=0,P[5]=E,P[6]=0,P[7]=0,P[8]=0,P[9]=0,P[11]=-1,P[12]=0,P[13]=0,P[15]=0,Number.isFinite(y)){let A=1/(x-y);P[10]=y*A,P[14]=y*x*A}else P[10]=-1,P[14]=-x;return P}function a(u,_,x,y=1/0,d){let P=d??new e(16),E=1/Math.tan(u*.5);if(P[0]=E/_,P[1]=0,P[2]=0,P[3]=0,P[4]=0,P[5]=E,P[6]=0,P[7]=0,P[8]=0,P[9]=0,P[11]=-1,P[12]=0,P[13]=0,P[15]=0,y===1/0)P[10]=0,P[14]=x;else{let A=1/(y-x);P[10]=x*A,P[14]=y*x*A}return P}function v(u,_,x,y,d,P,E){let A=E??new e(16);return A[0]=2/(_-u),A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2/(y-x),A[6]=0,A[7]=0,A[8]=0,A[9]=0,A[10]=1/(d-P),A[11]=0,A[12]=(_+u)/(u-_),A[13]=(y+x)/(x-y),A[14]=d/(d-P),A[15]=1,A}function T(u,_,x,y,d,P,E){let A=E??new e(16),Z=_-u,J=y-x,j=d-P;return A[0]=2*d/Z,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/J,A[6]=0,A[7]=0,A[8]=(u+_)/Z,A[9]=(y+x)/J,A[10]=P/j,A[11]=-1,A[12]=0,A[13]=0,A[14]=d*P/j,A[15]=0,A}function M(u,_,x,y,d,P=1/0,E){let A=E??new e(16),Z=_-u,J=y-x;if(A[0]=2*d/Z,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/J,A[6]=0,A[7]=0,A[8]=(u+_)/Z,A[9]=(y+x)/J,A[11]=-1,A[12]=0,A[13]=0,A[15]=0,P===1/0)A[10]=0,A[14]=d;else{let j=1/(P-d);A[10]=d*j,A[14]=P*d*j}return A}let S=t.create(),L=t.create(),O=t.create();function B(u,_,x,y){let d=y??new e(16);return t.normalize(t.subtract(_,u,O),O),t.normalize(t.cross(x,O,S),S),t.normalize(t.cross(O,S,L),L),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=L[0],d[5]=L[1],d[6]=L[2],d[7]=0,d[8]=O[0],d[9]=O[1],d[10]=O[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function l(u,_,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,_,O),O),t.normalize(t.cross(x,O,S),S),t.normalize(t.cross(O,S,L),L),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=L[0],d[5]=L[1],d[6]=L[2],d[7]=0,d[8]=O[0],d[9]=O[1],d[10]=O[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function G(u,_,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,_,O),O),t.normalize(t.cross(x,O,S),S),t.normalize(t.cross(O,S,L),L),d[0]=S[0],d[1]=L[0],d[2]=O[0],d[3]=0,d[4]=S[1],d[5]=L[1],d[6]=O[1],d[7]=0,d[8]=S[2],d[9]=L[2],d[10]=O[2],d[11]=0,d[12]=-(S[0]*u[0]+S[1]*u[1]+S[2]*u[2]),d[13]=-(L[0]*u[0]+L[1]*u[1]+L[2]*u[2]),d[14]=-(O[0]*u[0]+O[1]*u[1]+O[2]*u[2]),d[15]=1,d}function ot(u,_){let x=_??new e(16);return x[0]=1,x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=1,x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=1,x[11]=0,x[12]=u[0],x[13]=u[1],x[14]=u[2],x[15]=1,x}function at(u,_,x){let y=x??new e(16),d=_[0],P=_[1],E=_[2],A=u[0],Z=u[1],J=u[2],j=u[3],ct=u[4],nt=u[5],it=u[6],vt=u[7],ht=u[8],lt=u[9],dt=u[10],wt=u[11],gt=u[12],Ct=u[13],Mt=u[14],bt=u[15];return u!==y&&(y[0]=A,y[1]=Z,y[2]=J,y[3]=j,y[4]=ct,y[5]=nt,y[6]=it,y[7]=vt,y[8]=ht,y[9]=lt,y[10]=dt,y[11]=wt),y[12]=A*d+ct*P+ht*E+gt,y[13]=Z*d+nt*P+lt*E+Ct,y[14]=J*d+it*P+dt*E+Mt,y[15]=j*d+vt*P+wt*E+bt,y}function ut(u,_){let x=_??new e(16),y=Math.cos(u),d=Math.sin(u);return x[0]=1,x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=y,x[6]=d,x[7]=0,x[8]=0,x[9]=-d,x[10]=y,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function ft(u,_,x){let y=x??new e(16),d=u[4],P=u[5],E=u[6],A=u[7],Z=u[8],J=u[9],j=u[10],ct=u[11],nt=Math.cos(_),it=Math.sin(_);return y[4]=nt*d+it*Z,y[5]=nt*P+it*J,y[6]=nt*E+it*j,y[7]=nt*A+it*ct,y[8]=nt*Z-it*d,y[9]=nt*J-it*P,y[10]=nt*j-it*E,y[11]=nt*ct-it*A,u!==y&&(y[0]=u[0],y[1]=u[1],y[2]=u[2],y[3]=u[3],y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function yt(u,_){let x=_??new e(16),y=Math.cos(u),d=Math.sin(u);return x[0]=y,x[1]=0,x[2]=-d,x[3]=0,x[4]=0,x[5]=1,x[6]=0,x[7]=0,x[8]=d,x[9]=0,x[10]=y,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function pt(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=u[3],Z=u[8],J=u[9],j=u[10],ct=u[11],nt=Math.cos(_),it=Math.sin(_);return y[0]=nt*d-it*Z,y[1]=nt*P-it*J,y[2]=nt*E-it*j,y[3]=nt*A-it*ct,y[8]=nt*Z+it*d,y[9]=nt*J+it*P,y[10]=nt*j+it*E,y[11]=nt*ct+it*A,u!==y&&(y[4]=u[4],y[5]=u[5],y[6]=u[6],y[7]=u[7],y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function k(u,_){let x=_??new e(16),y=Math.cos(u),d=Math.sin(u);return x[0]=y,x[1]=d,x[2]=0,x[3]=0,x[4]=-d,x[5]=y,x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=1,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function $(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=u[3],Z=u[4],J=u[5],j=u[6],ct=u[7],nt=Math.cos(_),it=Math.sin(_);return y[0]=nt*d+it*Z,y[1]=nt*P+it*J,y[2]=nt*E+it*j,y[3]=nt*A+it*ct,y[4]=nt*Z-it*d,y[5]=nt*J-it*P,y[6]=nt*j-it*E,y[7]=nt*ct-it*A,u!==y&&(y[8]=u[8],y[9]=u[9],y[10]=u[10],y[11]=u[11],y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function F(u,_,x){let y=x??new e(16),d=u[0],P=u[1],E=u[2],A=Math.sqrt(d*d+P*P+E*E);d/=A,P/=A,E/=A;let Z=d*d,J=P*P,j=E*E,ct=Math.cos(_),nt=Math.sin(_),it=1-ct;return y[0]=Z+(1-Z)*ct,y[1]=d*P*it+E*nt,y[2]=d*E*it-P*nt,y[3]=0,y[4]=d*P*it-E*nt,y[5]=J+(1-J)*ct,y[6]=P*E*it+d*nt,y[7]=0,y[8]=d*E*it+P*nt,y[9]=P*E*it-d*nt,y[10]=j+(1-j)*ct,y[11]=0,y[12]=0,y[13]=0,y[14]=0,y[15]=1,y}let c=F;function b(u,_,x,y){let d=y??new e(16),P=_[0],E=_[1],A=_[2],Z=Math.sqrt(P*P+E*E+A*A);P/=Z,E/=Z,A/=Z;let J=P*P,j=E*E,ct=A*A,nt=Math.cos(x),it=Math.sin(x),vt=1-nt,ht=J+(1-J)*nt,lt=P*E*vt+A*it,dt=P*A*vt-E*it,wt=P*E*vt-A*it,gt=j+(1-j)*nt,Ct=E*A*vt+P*it,Mt=P*A*vt+E*it,bt=E*A*vt-P*it,Ht=ct+(1-ct)*nt,St=u[0],_t=u[1],$t=u[2],Bt=u[3],Dt=u[4],Wt=u[5],Ut=u[6],Ft=u[7],Kt=u[8],Gt=u[9],At=u[10],jt=u[11];return d[0]=ht*St+lt*Dt+dt*Kt,d[1]=ht*_t+lt*Wt+dt*Gt,d[2]=ht*$t+lt*Ut+dt*At,d[3]=ht*Bt+lt*Ft+dt*jt,d[4]=wt*St+gt*Dt+Ct*Kt,d[5]=wt*_t+gt*Wt+Ct*Gt,d[6]=wt*$t+gt*Ut+Ct*At,d[7]=wt*Bt+gt*Ft+Ct*jt,d[8]=Mt*St+bt*Dt+Ht*Kt,d[9]=Mt*_t+bt*Wt+Ht*Gt,d[10]=Mt*$t+bt*Ut+Ht*At,d[11]=Mt*Bt+bt*Ft+Ht*jt,u!==d&&(d[12]=u[12],d[13]=u[13],d[14]=u[14],d[15]=u[15]),d}let w=b;function z(u,_){let x=_??new e(16);return x[0]=u[0],x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=u[1],x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=u[2],x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function R(u,_,x){let y=x??new e(16),d=_[0],P=_[1],E=_[2];return y[0]=d*u[0],y[1]=d*u[1],y[2]=d*u[2],y[3]=d*u[3],y[4]=P*u[4],y[5]=P*u[5],y[6]=P*u[6],y[7]=P*u[7],y[8]=E*u[8],y[9]=E*u[9],y[10]=E*u[10],y[11]=E*u[11],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function m(u,_){let x=_??new e(16);return x[0]=u,x[1]=0,x[2]=0,x[3]=0,x[4]=0,x[5]=u,x[6]=0,x[7]=0,x[8]=0,x[9]=0,x[10]=u,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}function C(u,_,x){let y=x??new e(16);return y[0]=_*u[0],y[1]=_*u[1],y[2]=_*u[2],y[3]=_*u[3],y[4]=_*u[4],y[5]=_*u[5],y[6]=_*u[6],y[7]=_*u[7],y[8]=_*u[8],y[9]=_*u[9],y[10]=_*u[10],y[11]=_*u[11],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}return{add:f,aim:B,axisRotate:b,axisRotation:F,cameraAim:l,clone:D,copy:g,create:n,determinant:Y,equals:N,equalsApproximately:X,fromMat3:i,fromQuat:o,frustum:T,frustumReverseZ:M,getAxis:st,getScaling:rt,getTranslation:W,identity:I,inverse:q,invert:K,lookAt:G,mul:tt,mulScalar:p,multiply:Q,multiplyScalar:h,negate:s,ortho:v,perspective:U,perspectiveReverseZ:a,rotate:w,rotateX:ft,rotateY:pt,rotateZ:$,rotation:c,rotationX:ut,rotationY:yt,rotationZ:k,scale:R,scaling:z,set:r,setAxis:et,setTranslation:H,translate:at,translation:ot,transpose:V,uniformScale:C,uniformScaling:m}}var _i=new Map;function eu(e){let t=_i.get(e);return t||(t=tu(e),_i.set(e,t)),t}function ru(e){let t=vr(e);function n(k,$,F,c){let b=new e(4);return k!==void 0&&(b[0]=k,$!==void 0&&(b[1]=$,F!==void 0&&(b[2]=F,c!==void 0&&(b[3]=c)))),b}let r=n;function i(k,$,F,c,b){let w=b??new e(4);return w[0]=k,w[1]=$,w[2]=F,w[3]=c,w}function o(k,$,F){let c=F??new e(4),b=$*.5,w=Math.sin(b);return c[0]=w*k[0],c[1]=w*k[1],c[2]=w*k[2],c[3]=Math.cos(b),c}function s(k,$){let F=$??t.create(3),c=Math.acos(k[3])*2,b=Math.sin(c*.5);return b>Tt?(F[0]=k[0]/b,F[1]=k[1]/b,F[2]=k[2]/b):(F[0]=1,F[1]=0,F[2]=0),{angle:c,axis:F}}function f(k,$){let F=U(k,$);return Math.acos(2*F*F-1)}function h(k,$,F){let c=F??new e(4),b=k[0],w=k[1],z=k[2],R=k[3],m=$[0],C=$[1],u=$[2],_=$[3];return c[0]=b*_+R*m+w*u-z*C,c[1]=w*_+R*C+z*m-b*u,c[2]=z*_+R*u+b*C-w*m,c[3]=R*_-b*m-w*C-z*u,c}let p=h;function g(k,$,F){let c=F??new e(4),b=$*.5,w=k[0],z=k[1],R=k[2],m=k[3],C=Math.sin(b),u=Math.cos(b);return c[0]=w*u+m*C,c[1]=z*u+R*C,c[2]=R*u-z*C,c[3]=m*u-w*C,c}function D(k,$,F){let c=F??new e(4),b=$*.5,w=k[0],z=k[1],R=k[2],m=k[3],C=Math.sin(b),u=Math.cos(b);return c[0]=w*u-R*C,c[1]=z*u+m*C,c[2]=R*u+w*C,c[3]=m*u-z*C,c}function X(k,$,F){let c=F??new e(4),b=$*.5,w=k[0],z=k[1],R=k[2],m=k[3],C=Math.sin(b),u=Math.cos(b);return c[0]=w*u+z*C,c[1]=z*u-w*C,c[2]=R*u+m*C,c[3]=m*u-R*C,c}function N(k,$,F,c){let b=c??new e(4),w=k[0],z=k[1],R=k[2],m=k[3],C=$[0],u=$[1],_=$[2],x=$[3],y=w*C+z*u+R*_+m*x;y<0&&(y=-y,C=-C,u=-u,_=-_,x=-x);let d,P;if(1-y>Tt){let E=Math.acos(y),A=Math.sin(E);d=Math.sin((1-F)*E)/A,P=Math.sin(F*E)/A}else d=1-F,P=F;return b[0]=d*w+P*C,b[1]=d*z+P*u,b[2]=d*R+P*_,b[3]=d*m+P*x,b}function I(k,$){let F=$??new e(4),c=k[0],b=k[1],w=k[2],z=k[3],R=c*c+b*b+w*w+z*z,m=R?1/R:0;return F[0]=-c*m,F[1]=-b*m,F[2]=-w*m,F[3]=z*m,F}function V(k,$){let F=$??new e(4);return F[0]=-k[0],F[1]=-k[1],F[2]=-k[2],F[3]=k[3],F}function q(k,$){let F=$??new e(4),c=k[0]+k[5]+k[10];if(c>0){let b=Math.sqrt(c+1);F[3]=.5*b;let w=.5/b;F[0]=(k[6]-k[9])*w,F[1]=(k[8]-k[2])*w,F[2]=(k[1]-k[4])*w}else{let b=0;k[5]>k[0]&&(b=1),k[10]>k[b*4+b]&&(b=2);let w=(b+1)%3,z=(b+2)%3,R=Math.sqrt(k[b*4+b]-k[w*4+w]-k[z*4+z]+1);F[b]=.5*R;let m=.5/R;F[3]=(k[w*4+z]-k[z*4+w])*m,F[w]=(k[w*4+b]+k[b*4+w])*m,F[z]=(k[z*4+b]+k[b*4+z])*m}return F}function Y(k,$,F,c,b){let w=b??new e(4),z=k*.5,R=$*.5,m=F*.5,C=Math.sin(z),u=Math.cos(z),_=Math.sin(R),x=Math.cos(R),y=Math.sin(m),d=Math.cos(m);switch(c){case"xyz":w[0]=C*x*d+u*_*y,w[1]=u*_*d-C*x*y,w[2]=u*x*y+C*_*d,w[3]=u*x*d-C*_*y;break;case"xzy":w[0]=C*x*d-u*_*y,w[1]=u*_*d-C*x*y,w[2]=u*x*y+C*_*d,w[3]=u*x*d+C*_*y;break;case"yxz":w[0]=C*x*d+u*_*y,w[1]=u*_*d-C*x*y,w[2]=u*x*y-C*_*d,w[3]=u*x*d+C*_*y;break;case"yzx":w[0]=C*x*d+u*_*y,w[1]=u*_*d+C*x*y,w[2]=u*x*y-C*_*d,w[3]=u*x*d-C*_*y;break;case"zxy":w[0]=C*x*d-u*_*y,w[1]=u*_*d+C*x*y,w[2]=u*x*y+C*_*d,w[3]=u*x*d-C*_*y;break;case"zyx":w[0]=C*x*d-u*_*y,w[1]=u*_*d+C*x*y,w[2]=u*x*y-C*_*d,w[3]=u*x*d+C*_*y;break;default:throw new Error(`Unknown rotation order: ${c}`)}return w}function K(k,$){let F=$??new e(4);return F[0]=k[0],F[1]=k[1],F[2]=k[2],F[3]=k[3],F}let Q=K;function tt(k,$,F){let c=F??new e(4);return c[0]=k[0]+$[0],c[1]=k[1]+$[1],c[2]=k[2]+$[2],c[3]=k[3]+$[3],c}function H(k,$,F){let c=F??new e(4);return c[0]=k[0]-$[0],c[1]=k[1]-$[1],c[2]=k[2]-$[2],c[3]=k[3]-$[3],c}let W=H;function st(k,$,F){let c=F??new e(4);return c[0]=k[0]*$,c[1]=k[1]*$,c[2]=k[2]*$,c[3]=k[3]*$,c}let et=st;function rt(k,$,F){let c=F??new e(4);return c[0]=k[0]/$,c[1]=k[1]/$,c[2]=k[2]/$,c[3]=k[3]/$,c}function U(k,$){return k[0]*$[0]+k[1]*$[1]+k[2]*$[2]+k[3]*$[3]}function a(k,$,F,c){let b=c??new e(4);return b[0]=k[0]+F*($[0]-k[0]),b[1]=k[1]+F*($[1]-k[1]),b[2]=k[2]+F*($[2]-k[2]),b[3]=k[3]+F*($[3]-k[3]),b}function v(k){let $=k[0],F=k[1],c=k[2],b=k[3];return Math.sqrt($*$+F*F+c*c+b*b)}let T=v;function M(k){let $=k[0],F=k[1],c=k[2],b=k[3];return $*$+F*F+c*c+b*b}let S=M;function L(k,$){let F=$??new e(4),c=k[0],b=k[1],w=k[2],z=k[3],R=Math.sqrt(c*c+b*b+w*w+z*z);return R>1e-5?(F[0]=c/R,F[1]=b/R,F[2]=w/R,F[3]=z/R):(F[0]=0,F[1]=0,F[2]=0,F[3]=1),F}function O(k,$){return Math.abs(k[0]-$[0])<Tt&&Math.abs(k[1]-$[1])<Tt&&Math.abs(k[2]-$[2])<Tt&&Math.abs(k[3]-$[3])<Tt}function B(k,$){return k[0]===$[0]&&k[1]===$[1]&&k[2]===$[2]&&k[3]===$[3]}function l(k){let $=k??new e(4);return $[0]=0,$[1]=0,$[2]=0,$[3]=1,$}let G=t.create(),ot=t.create(),at=t.create();function ut(k,$,F){let c=F??new e(4),b=t.dot(k,$);return b<-.999999?(t.cross(ot,k,G),t.len(G)<1e-6&&t.cross(at,k,G),t.normalize(G,G),o(G,Math.PI,c),c):b>.999999?(c[0]=0,c[1]=0,c[2]=0,c[3]=1,c):(t.cross(k,$,G),c[0]=G[0],c[1]=G[1],c[2]=G[2],c[3]=1+b,L(c,c))}let ft=new e(4),yt=new e(4);function pt(k,$,F,c,b,w){let z=w??new e(4);return N(k,c,b,ft),N($,F,b,yt),N(ft,yt,2*b*(1-b),z),z}return{create:n,fromValues:r,set:i,fromAxisAngle:o,toAxisAngle:s,angle:f,multiply:h,mul:p,rotateX:g,rotateY:D,rotateZ:X,slerp:N,inverse:I,conjugate:V,fromMat:q,fromEuler:Y,copy:K,clone:Q,add:tt,subtract:H,sub:W,mulScalar:st,scale:et,divScalar:rt,dot:U,lerp:a,length:v,len:T,lengthSq:M,lenSq:S,normalize:L,equalsApproximately:O,equals:B,identity:l,rotationTo:ut,sqlerp:pt}}var Bi=new Map;function nu(e){let t=Bi.get(e);return t||(t=ru(e),Bi.set(e,t)),t}function iu(e){function t(F,c,b,w){let z=new e(4);return F!==void 0&&(z[0]=F,c!==void 0&&(z[1]=c,b!==void 0&&(z[2]=b,w!==void 0&&(z[3]=w)))),z}let n=t;function r(F,c,b,w,z){let R=z??new e(4);return R[0]=F,R[1]=c,R[2]=b,R[3]=w,R}function i(F,c){let b=c??new e(4);return b[0]=Math.ceil(F[0]),b[1]=Math.ceil(F[1]),b[2]=Math.ceil(F[2]),b[3]=Math.ceil(F[3]),b}function o(F,c){let b=c??new e(4);return b[0]=Math.floor(F[0]),b[1]=Math.floor(F[1]),b[2]=Math.floor(F[2]),b[3]=Math.floor(F[3]),b}function s(F,c){let b=c??new e(4);return b[0]=Math.round(F[0]),b[1]=Math.round(F[1]),b[2]=Math.round(F[2]),b[3]=Math.round(F[3]),b}function f(F,c=0,b=1,w){let z=w??new e(4);return z[0]=Math.min(b,Math.max(c,F[0])),z[1]=Math.min(b,Math.max(c,F[1])),z[2]=Math.min(b,Math.max(c,F[2])),z[3]=Math.min(b,Math.max(c,F[3])),z}function h(F,c,b){let w=b??new e(4);return w[0]=F[0]+c[0],w[1]=F[1]+c[1],w[2]=F[2]+c[2],w[3]=F[3]+c[3],w}function p(F,c,b,w){let z=w??new e(4);return z[0]=F[0]+c[0]*b,z[1]=F[1]+c[1]*b,z[2]=F[2]+c[2]*b,z[3]=F[3]+c[3]*b,z}function g(F,c,b){let w=b??new e(4);return w[0]=F[0]-c[0],w[1]=F[1]-c[1],w[2]=F[2]-c[2],w[3]=F[3]-c[3],w}let D=g;function X(F,c){return Math.abs(F[0]-c[0])<Tt&&Math.abs(F[1]-c[1])<Tt&&Math.abs(F[2]-c[2])<Tt&&Math.abs(F[3]-c[3])<Tt}function N(F,c){return F[0]===c[0]&&F[1]===c[1]&&F[2]===c[2]&&F[3]===c[3]}function I(F,c,b,w){let z=w??new e(4);return z[0]=F[0]+b*(c[0]-F[0]),z[1]=F[1]+b*(c[1]-F[1]),z[2]=F[2]+b*(c[2]-F[2]),z[3]=F[3]+b*(c[3]-F[3]),z}function V(F,c,b,w){let z=w??new e(4);return z[0]=F[0]+b[0]*(c[0]-F[0]),z[1]=F[1]+b[1]*(c[1]-F[1]),z[2]=F[2]+b[2]*(c[2]-F[2]),z[3]=F[3]+b[3]*(c[3]-F[3]),z}function q(F,c,b){let w=b??new e(4);return w[0]=Math.max(F[0],c[0]),w[1]=Math.max(F[1],c[1]),w[2]=Math.max(F[2],c[2]),w[3]=Math.max(F[3],c[3]),w}function Y(F,c,b){let w=b??new e(4);return w[0]=Math.min(F[0],c[0]),w[1]=Math.min(F[1],c[1]),w[2]=Math.min(F[2],c[2]),w[3]=Math.min(F[3],c[3]),w}function K(F,c,b){let w=b??new e(4);return w[0]=F[0]*c,w[1]=F[1]*c,w[2]=F[2]*c,w[3]=F[3]*c,w}let Q=K;function tt(F,c,b){let w=b??new e(4);return w[0]=F[0]/c,w[1]=F[1]/c,w[2]=F[2]/c,w[3]=F[3]/c,w}function H(F,c){let b=c??new e(4);return b[0]=1/F[0],b[1]=1/F[1],b[2]=1/F[2],b[3]=1/F[3],b}let W=H;function st(F,c){return F[0]*c[0]+F[1]*c[1]+F[2]*c[2]+F[3]*c[3]}function et(F){let c=F[0],b=F[1],w=F[2],z=F[3];return Math.sqrt(c*c+b*b+w*w+z*z)}let rt=et;function U(F){let c=F[0],b=F[1],w=F[2],z=F[3];return c*c+b*b+w*w+z*z}let a=U;function v(F,c){let b=F[0]-c[0],w=F[1]-c[1],z=F[2]-c[2],R=F[3]-c[3];return Math.sqrt(b*b+w*w+z*z+R*R)}let T=v;function M(F,c){let b=F[0]-c[0],w=F[1]-c[1],z=F[2]-c[2],R=F[3]-c[3];return b*b+w*w+z*z+R*R}let S=M;function L(F,c){let b=c??new e(4),w=F[0],z=F[1],R=F[2],m=F[3],C=Math.sqrt(w*w+z*z+R*R+m*m);return C>1e-5?(b[0]=w/C,b[1]=z/C,b[2]=R/C,b[3]=m/C):(b[0]=0,b[1]=0,b[2]=0,b[3]=0),b}function O(F,c){let b=c??new e(4);return b[0]=-F[0],b[1]=-F[1],b[2]=-F[2],b[3]=-F[3],b}function B(F,c){let b=c??new e(4);return b[0]=F[0],b[1]=F[1],b[2]=F[2],b[3]=F[3],b}let l=B;function G(F,c,b){let w=b??new e(4);return w[0]=F[0]*c[0],w[1]=F[1]*c[1],w[2]=F[2]*c[2],w[3]=F[3]*c[3],w}let ot=G;function at(F,c,b){let w=b??new e(4);return w[0]=F[0]/c[0],w[1]=F[1]/c[1],w[2]=F[2]/c[2],w[3]=F[3]/c[3],w}let ut=at;function ft(F){let c=F??new e(4);return c[0]=0,c[1]=0,c[2]=0,c[3]=0,c}function yt(F,c,b){let w=b??new e(4),z=F[0],R=F[1],m=F[2],C=F[3];return w[0]=c[0]*z+c[4]*R+c[8]*m+c[12]*C,w[1]=c[1]*z+c[5]*R+c[9]*m+c[13]*C,w[2]=c[2]*z+c[6]*R+c[10]*m+c[14]*C,w[3]=c[3]*z+c[7]*R+c[11]*m+c[15]*C,w}function pt(F,c,b){let w=b??new e(4);return L(F,w),K(w,c,w)}function k(F,c,b){let w=b??new e(4);return et(F)>c?pt(F,c,w):B(F,w)}function $(F,c,b){let w=b??new e(4);return I(F,c,.5,w)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:f,add:h,addScaled:p,subtract:g,sub:D,equalsApproximately:X,equals:N,lerp:I,lerpV:V,max:q,min:Y,mulScalar:K,scale:Q,divScalar:tt,inverse:H,invert:W,dot:st,length:et,len:rt,lengthSq:U,lenSq:a,distance:v,dist:T,distanceSq:M,distSq:S,normalize:L,negate:O,copy:B,clone:l,multiply:G,mul:ot,divide:at,div:ut,zero:ft,transformMat4:yt,setLength:pt,truncate:k,midpoint:$}}var Di=new Map;function ou(e){let t=Di.get(e);return t||(t=iu(e),Di.set(e,t)),t}function pn(e,t,n,r,i,o){return{mat3:js(e),mat4:eu(t),quat:nu(n),vec2:Ui(r),vec3:vr(i),vec4:ou(o)}}var{mat3:Me,mat4:Lt,quat:_l,vec2:Et,vec3:fe,vec4:Ce}=pn(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array),{mat3:Bl,mat4:Dl,quat:Ul,vec2:Fl,vec3:Gl,vec4:Al}=pn(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array),{mat3:zl,mat4:Ll,quat:El,vec2:Rl,vec3:Il,vec4:Ol}=pn(Ws,Array,Array,Array,Array,Array);var dr=class{device;format="r8unorm";downsizeFactor;multisample;textureSimple;textureMultisampled=null;renderPipeline;bindgroup;uniformsBuffer;trianglesBuffer;constructor(t){this.device=t.device,this.downsizeFactor=t.blurFactor,this.multisample=this.downsizeFactor>1?4:1,[this.textureSimple,this.textureMultisampled]=this.createTextures(t.width,t.height),this.trianglesBuffer=t.trianglesBuffer;let n=this.device.createShaderModule({label:"DisplacementTexture shader module",code:bi});this.renderPipeline=this.device.createRenderPipeline({label:"DisplacementTexture renderpipeline",layout:"auto",vertex:{module:n,entryPoint:"main_vertex",buffers:[{attributes:[{shaderLocation:0,offset:0,format:"float32x2"}],arrayStride:2*Float32Array.BYTES_PER_ELEMENT,stepMode:"vertex"}]},fragment:{module:n,entryPoint:"main_fragment",targets:[{format:this.format}]},primitive:{cullMode:"none",topology:"triangle-list"},multisample:{count:this.multisample}}),this.uniformsBuffer=this.device.createBuffer({label:"DisplacementTexture uniforms buffer",size:64,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),this.bindgroup=this.device.createBindGroup({label:"DisplacementTexture bindgroup",layout:this.renderPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.uniformsBuffer}}]})}update(t){let n=this.textureMultisampled??this.textureSimple,r={view:n.view,clearValue:[0,0,0,1],loadOp:"clear",storeOp:"store"};this.textureMultisampled&&(r.resolveTarget=this.textureSimple.view);let i=t.beginRenderPass({label:"DisplacementTexture render to texture renderpass",colorAttachments:[r]}),[o,s]=[n.texture.width,n.texture.height];i.setViewport(0,0,o,s,0,1),i.setScissorRect(0,0,o,s),i.setPipeline(this.renderPipeline),i.setBindGroup(0,this.bindgroup),i.setVertexBuffer(0,this.trianglesBuffer.bufferGpu),i.draw(3*this.trianglesBuffer.spriteCount),i.end()}resize(t,n){this.textureSimple.texture.destroy(),this.textureMultisampled?.texture.destroy(),[this.textureSimple,this.textureMultisampled]=this.createTextures(t,n)}setViewport(t){let n=[1,1,1],r=0,i=[1,1,0],o=Lt.identity();Lt.multiply(Lt.scaling(n),o,o),Lt.multiply(Lt.rotationZ(r),o,o),Lt.multiply(Lt.translation(i),o,o);let s=Lt.translation([-t.position[0],-t.position[1],0]),f=t.width/t.zoom,h=t.height/t.zoom,p=Lt.ortho(0,f,h,0,-10,10),g=Lt.identity();Lt.multiply(s,o,g),Lt.multiply(p,g,g),this.device.queue.writeBuffer(this.uniformsBuffer,0,g)}getView(){return this.textureSimple.view}destroy(){this.textureSimple.texture.destroy(),this.textureMultisampled?.texture.destroy(),this.uniformsBuffer.destroy()}createTextures(t,n){let r=this.device.createTexture({label:"DisplacementTexture texture",size:[Math.ceil(t/this.downsizeFactor),Math.ceil(n/this.downsizeFactor)],format:this.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT}),i={texture:r,view:r.createView({label:"DisplacementTexture texture view"})},o=null;if(this.multisample>1){let s=this.device.createTexture({label:"DisplacementTexture texture multisampled",size:[r.width,r.height],format:r.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT,sampleCount:this.multisample});o={texture:s,view:s.createView({label:"DisplacementTexture texture multisampled view"})}}return[i,o]}};function Be(){return Math.ceil(Math.random()*(Number.MAX_SAFE_INTEGER-10))}var gr=class{device;floatsPerSprite=6;bufferGpu;bufferNeedsUpdate=!1;sprites=new Map;get spriteCount(){return this.sprites.size}constructor(t){this.device=t.device,this.bufferGpu=this.device.createBuffer({size:t.maxSpriteCount*this.floatsPerSprite*Float32Array.BYTES_PER_ELEMENT,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST})}destroy(){this.bufferGpu.destroy}update(){if(this.bufferNeedsUpdate){let t=[];for(let r of this.sprites.values())t.push(...r);let n=new Float32Array(t);this.device.queue.writeBuffer(this.bufferGpu,0,n)}}addTriangle(t){let n=Be();if(this.sprites.has(n))throw new Error(`Duplicate triangle "${n}".`);let r=this.buildTriangleData(t);return this.sprites.set(n,r),this.bufferNeedsUpdate=!0,n}removeTriangle(t){if(!this.sprites.has(t))throw new Error(`Unknown triangle "${t}".`);this.sprites.delete(t),this.bufferNeedsUpdate=!0}setTriangle(t,n){if(!this.sprites.has(t))throw new Error(`Unknown triangle "${t}".`);let r=this.buildTriangleData(n);this.sprites.set(t,r),this.bufferNeedsUpdate=!0}buildTriangleData(t){return[t[0][0],t[0][1],t[1][0],t[1][1],t[2][0],t[2][1]]}};var Gi={type:"cobalt:displacement",refs:[{name:"color",type:"textureView",format:"bgra8unorm",access:"read"},{name:"map",type:"cobaltTexture",format:"bgra8unorm",access:"read"},{name:"out",type:"textureView",format:"bgra8unorm",access:"write"}],onInit:async function(e,t={}){return au(e,t)},onRun:function(e,t,n){su(e,t,n)},onDestroy:function(e,t){uu(t)},onResize:function(e,t){t.data.displacementTexture.resize(e.viewport.width,e.viewport.height),t.data.displacementComposition.setColorTextureView(t.refs.color.data.view),t.data.displacementComposition.setNoiseMapTextureView(t.refs.map.view),t.data.displacementComposition.setDisplacementTextureView(t.data.displacementTexture.getView())},onViewportPosition:function(e,t){t.data.displacementTexture.setViewport(e.viewport)},customFunctions:{addTriangle:function(e,t,n){return t.data.trianglesBuffer.addTriangle(n)},removeTriangle:function(e,t,n){t.data.trianglesBuffer.removeTriangle(n)},setPosition:function(e,t,n,r){t.data.trianglesBuffer.setTriangle(n,r)}}};async function au(e,t){let{device:n}=e,r=new pr({device:n,initialParameters:{offsetX:t.options.offseyX??0,offsetY:t.options.offseyY??0,scale:t.options.scale??20}}),i=256,o=new gr({device:n,maxSpriteCount:i}),s=new dr({device:n,width:e.viewport.width,height:e.viewport.height,blurFactor:8,trianglesBuffer:o}),f=new hr({device:n,targetFormat:qt(e),colorTextureView:t.refs.color.data.view,noiseMapTextureView:t.refs.map.view,displacementTextureView:s.getView(),displacementParametersBuffer:r});return{displacementParameters:r,displacementTexture:s,displacementComposition:f,trianglesBuffer:o}}function su(e,t,n){if(t.data.trianglesBuffer.spriteCount===0)return;t.data.trianglesBuffer.update(),t.data.displacementTexture.update(n);let i=n.beginRenderPass({label:"displacement",colorAttachments:[{view:t.refs.out,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});i.executeBundles([t.data.displacementComposition.getRenderBundle()]),i.end()}function uu(e){e.data.trianglesBuffer.destroy(),e.data.trianglesBuffer=null,e.data.displacementParameters.destroy(),e.data.displacementParameters=null,e.data.displacementTexture.destroy(),e.data.displacementTexture=null,e.data.displacementComposition.destroy(),e.data.displacementComposition=null}var vn="@binding(0)@group(0)var tileTexture:texture_2d<f32>;@binding(1)@group(0)var tileSampler:sampler;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>};const positions=array<vec2<f32>,3>(vec2<f32>(-1.0,-3.0),vec2<f32>(3.0,1.0),vec2<f32>(-1.0,1.0));const uvs=array<vec2<f32>,3>(vec2<f32>(0.0,2.0),vec2<f32>(2.0,0.0),vec2<f32>(0.0,0.0));@vertex fn vs_main(@builtin(vertex_index)VertexIndex:u32)->Fragment{var output:Fragment;output.Position=vec4<f32>(positions[VertexIndex],0.0,1.0);output.TexCoord=vec2<f32>(uvs[VertexIndex]);return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>)->@location(0)vec4<f32>{var col=textureSample(tileTexture,tileSampler,TexCoord);return vec4<f32>(col.rgb,1.0);}";var Ai={type:"cobalt:fbBlit",refs:[{name:"in",type:"cobaltTexture",format:"PREFERRED_TEXTURE_FORMAT",access:"read"},{name:"out",type:"cobaltTexture",format:"PREFERRED_TEXTURE_FORMAT",access:"write"}],onInit:async function(e,t={}){return fu(e,t)},onRun:function(e,t,n){cu(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){lu(e,t)},onViewportPosition:function(e,t){}};async function fu(e,t){let{device:n}=e,r=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),i=n.createBindGroup({layout:r,entries:[{binding:0,resource:t.refs.in.data.view},{binding:1,resource:t.refs.in.data.sampler}]}),o=n.createPipelineLayout({bindGroupLayouts:[r]}),s=n.createRenderPipeline({label:"fb-blit",vertex:{module:n.createShaderModule({code:vn}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:vn}),entryPoint:"fs_main",targets:[{format:qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:o});return{bindGroupLayout:r,bindGroup:i,pipeline:s}}function cu(e,t,n){let{device:r}=e,i=n.beginRenderPass({label:"fb-blit",colorAttachments:[{view:t.refs.out,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});i.setPipeline(t.data.pipeline),i.setBindGroup(0,t.data.bindGroup),i.draw(3),i.end()}function lu(e,t){let{device:n}=e;t.data.bindGroup=n.createBindGroup({layout:t.data.bindGroupLayout,entries:[{binding:0,resource:t.refs.in.data.view},{binding:1,resource:t.refs.in.data.sampler}]})}var zi={type:"fbTexture",refs:[],onInit:async function(e,t={}){return hu(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){Li(t)},onResize:function(e,t){pu(e,t)},onViewportPosition:function(e,t){}};async function hu(e,t){let{device:n}=e;t.options.format=t.options.format==="PREFERRED_TEXTURE_FORMAT"?qt(e):t.options.format;let{format:r,label:i,mip_count:o,usage:s,viewportScale:f}=t.options;return ne(n,i,e.viewport.width*f,e.viewport.height*f,o,r,s)}function Li(e){e.data.texture.destroy()}function pu(e,t){let{device:n}=e;Li(t);let{width:r,height:i}=e.viewport,{options:o}=t,s=t.options.viewportScale;t.data=ne(n,o.label,r*s,i*s,o.mip_count,o.format,o.usage)}var ae=class e{static structs={definition:`
|
|
2
2
|
struct Light { // align(16) size(48)
|
|
3
3
|
color: vec3<f32>, // offset(0) align(16) size(12)
|
|
4
4
|
radius: f32, // offset(12) align(4) size(4)
|
|
@@ -281,4 +281,4 @@ fn main_fragment(in: VertexOut) -> FragmentOut {
|
|
|
281
281
|
out.color = vec4<f32>(color, 1.0);
|
|
282
282
|
return out;
|
|
283
283
|
}
|
|
284
|
-
`});this.renderPipeline=t.device.createRenderPipeline({label:"LightsRenderer renderpipeline",layout:"auto",vertex:{module:n,entryPoint:"main_vertex"},fragment:{module:n,entryPoint:"main_fragment",targets:[{format:this.targetTexture.format}]},primitive:{cullMode:"none",topology:"triangle-strip"}});let r=this.renderPipeline.getBindGroupLayout(0);this.bindgroup0=t.device.createBindGroup({label:"LightsRenderer bindgroup 0",layout:r,entries:[{binding:0,resource:{buffer:this.uniformsBufferGpu}},{binding:1,resource:{buffer:this.lightsBuffer.gpuBuffer}},{binding:2,resource:this.lightsTexture.texture.createView({label:"LightsRenderer lightsTexture view"})},{binding:3,resource:t.device.createSampler({label:"LightsRenderer sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:t.lightsTextureProperties.filtering,minFilter:t.lightsTextureProperties.filtering})}]}),this.bindgroup1=this.buildBindgroup1(t.albedo),this.renderBundle=this.buildRenderBundle()}computeLightsTexture(t){this.lightsTexture.update(t)}render(t,n){let r=new ArrayBuffer(80);new Float32Array(r,0,16).set(n),new Float32Array(r,64,3).set(this.ambientLight),this.device.queue.writeBuffer(this.uniformsBufferGpu,0,r),t.executeBundles([this.renderBundle])}setAlbedo(t){this.bindgroup1=this.buildBindgroup1(t),this.renderBundle=this.buildRenderBundle()}setAmbientLight(t){this.ambientLight=[...t]}setObstacles(t){this.lightsTexture.setObstacles(t)}destroy(){this.uniformsBufferGpu.destroy(),this.lightsTexture.destroy()}buildBindgroup1(t){return this.device.createBindGroup({label:"LightsRenderer bindgroup 1",layout:this.renderPipeline.getBindGroupLayout(1),entries:[{binding:0,resource:t.view},{binding:1,resource:t.sampler}]})}buildRenderBundle(){let t=this.device.createRenderBundleEncoder({label:"LightsRenderer renderbundle encoder",colorFormats:[this.targetTexture.format]});return t.setPipeline(this.renderPipeline),t.setBindGroup(0,this.bindgroup0),t.setBindGroup(1,this.bindgroup1),t.draw(4),t.finish({label:"LightsRenderer renderbundle"})}};var dn={};hn(dn,{setAmbientLight:()=>du,setLights:()=>vu,setOccluders:()=>gu});function vu(e,t,n){t.data.lights=n,t.data.lightsBufferNeedsUpdate=!0}function du(e,t,n){t.data.lightsRenderer.setAmbientLight(n)}function gu(e,t,n){t.data.lightsRenderer.setObstacles(n),t.data.lightsTextureNeedsUpdate=!0}var br=class{invViewProjectionMatrix=Lt.identity();viewportSize={width:1,height:1};topLeft=[0,0];zoom=1;constructor(t){this.setViewportSize(t.viewportSize.width,t.viewportSize.height);let n=t.center??this.topLeft;this.setTopLeft(...n);let r=t.zoom??1;this.setZoom(r)}get invertViewProjectionMatrix(){return this.invViewProjectionMatrix}setViewportSize(t,n){this.viewportSize.width=t,this.viewportSize.height=n,this.updateMatrices()}setTopLeft(t,n){this.topLeft[0]=t,this.topLeft[1]=n,this.updateMatrices()}setZoom(t){this.zoom=t,this.updateMatrices()}updateMatrices(){Lt.identity(this.invViewProjectionMatrix),Lt.multiply(Lt.scaling([1,-1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.translation([1,1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.scaling([.5*this.viewportSize.width/this.zoom,.5*this.viewportSize.height/this.zoom,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.translation([this.topLeft[0],this.topLeft[1],0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix)}};var Ei={type:"cobalt:light",refs:[{name:"in",type:"textureView",format:"rgba16float",access:"read"},{name:"out",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return wu(e,t)},onRun:function(e,t,n){xu(e,t,n)},onDestroy:function(e,t){yu(t)},onResize:function(e,t){Mu(e,t)},onViewportPosition:function(e,t){t.data.viewport.setTopLeft(...e.viewport.position)},customFunctions:{...dn}};async function wu(e,t){let{device:n}=e,r=256,i=256,o=new ae(n,r),s=new br({viewportSize:{width:e.viewport.width,height:e.viewport.height},center:e.viewport.position,zoom:e.viewport.zoom}),f=new Mr({device:n,albedo:{view:t.refs.in.data.view,sampler:t.refs.in.data.sampler},targetTexture:t.refs.out.data.texture,lightsBuffer:o,lightsTextureProperties:{resolutionPerLight:i,maxLightSize:i,antialiased:!1,filtering:"nearest",textureFormat:qt(e)}});return{lightsBuffer:o,lightsBufferNeedsUpdate:!0,lightsTextureNeedsUpdate:!0,lightsRenderer:f,viewport:s,lights:[]}}function xu(e,t,n){t.data.lightsBufferNeedsUpdate&&(t.data.lightsBuffer.setLights(t.data.lights),t.data.lightsBufferNeedsUpdate=!1,t.data.lightsTextureNeedsUpdate=!0);let r=t.data.lightsRenderer;t.data.lightsTextureNeedsUpdate&&(r.computeLightsTexture(n),t.data.lightsTextureNeedsUpdate=!1);let i=n.beginRenderPass({label:"light",colorAttachments:[{view:t.refs.out.data.view,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});t.data.viewport.setZoom(e.viewport.zoom);let o=t.data.viewport.invertViewProjectionMatrix;r.render(i,o),i.end()}function yu(e){e.data.lightsBuffer.destroy(),e.data.lightsRenderer.destroy()}function Mu(e,t){t.data.lightsRenderer.setAlbedo({view:t.refs.in.data.view,sampler:t.refs.in.data.sampler}),t.data.viewport.setViewportSize(e.viewport.width,e.viewport.height)}function de(e){return e>=0?Math.round(e):e%.5===0?Math.floor(e):Math.round(e)}var Ri="struct TransformData{view:mat4x4<f32>,projection:mat4x4<f32>};@binding(0)@group(0)var<uniform> transformUBO:TransformData;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)Color:vec4<f32>,};@vertex fn vs_main(@location(0)vertexPosition:vec2<f32>,@location(1)vertexColor:vec4<f32>)->Fragment{var sx:f32=1.0;var sy:f32=1.0;var sz:f32=1.0;var rot:f32=0.0;var tx:f32=1.0;var ty:f32=1.0;var tz:f32=0;var s=sin(rot);var c=cos(rot);var scaleM:mat4x4<f32>=mat4x4<f32>(sx,0.0,0.0,0.0,0.0,sy,0.0,0.0,0.0,0.0,sz,0.0,0,0,0,1.0);var modelM:mat4x4<f32>=mat4x4<f32>(c,s,0.0,0.0,-s,c,0.0,0.0,0.0,0.0,1.0,0.0,tx,ty,tz,1.0)*scaleM;var output:Fragment;output.Position=transformUBO.projection*transformUBO.view*modelM*vec4<f32>(vertexPosition,0.0,1.0);output.Color=vertexColor;return output;}@fragment fn fs_main(@location(0)Color:vec4<f32>)->@location(0)vec4<f32>{return Color;}";var ps=pi(co(),1);var hs=pi(ls(),1);function ti(e,t){if(!Array.isArray(e))throw new Error("poly-to-pslg: Error, invalid polygon");if(e.length===0)return{points:[],edges:[]};t=t||{};var n=!0;"nested"in t?n=!!t.nested:e[0].length===2&&typeof e[0][0]=="number"&&(n=!1),n||(e=[e]);for(var r=[],i=[],o=0;o<e.length;++o)for(var s=e[o],f=r.length,h=0;h<s.length;++h)r.push(s[h]),i.push([f+h,f+(h+1)%s.length]);var p="clean"in t?!0:!!t.clean;return p&&(0,hs.default)(r,i),{points:r,edges:i}}var vs={line:Re,save:function(e,t){t.data.transforms.push(Me.clone(t.data.transforms.at(-1)))},restore:function(e,t){t.data.transforms.length>1&&t.data.transforms.pop()},translate:function(e,t,n){let r=t.data.transforms.at(-1);Me.translate(r,n,r)},rotate:function(e,t,n){let r=t.data.transforms.at(-1);Me.rotate(r,n,r)},scale:function(e,t,n){let r=t.data.transforms.at(-1);Me.scale(r,n,r)},strokePath:function(e,t,n,r,i=1){for(let o of n)Re(e,t,o[0],o[1],r,i)},filledPath:function(e,t,n,r){let i=ti(n),o=(0,ps.default)(i.points,i.edges,{exterior:!1}),s=t.data.transforms.at(-1),f=t.data.vertexCount*6,h=t.data.vertexCount*6,p=o.length*3*6;t.data.vertices=Zr(Float32Array,t.data.vertices,h,p);let g=Et.create();for(let D of o)Et.transformMat3(n[D[0]],s,g),t.data.vertices[f+0]=g[0],t.data.vertices[f+1]=g[1],t.data.vertices[f+2]=r[0],t.data.vertices[f+3]=r[1],t.data.vertices[f+4]=r[2],t.data.vertices[f+5]=r[3],Et.transformMat3(n[D[1]],s,g),t.data.vertices[f+6]=g[0],t.data.vertices[f+7]=g[1],t.data.vertices[f+8]=r[0],t.data.vertices[f+9]=r[1],t.data.vertices[f+10]=r[2],t.data.vertices[f+11]=r[3],Et.transformMat3(n[D[2]],s,g),t.data.vertices[f+12]=g[0],t.data.vertices[f+13]=g[1],t.data.vertices[f+14]=r[0],t.data.vertices[f+15]=r[1],t.data.vertices[f+16]=r[2],t.data.vertices[f+17]=r[3],f+=18;t.data.vertexCount+=3*o.length,t.data.dirty=!0},ellipse:function(e,t,n,r,i,o,s,f=1){let[h,p]=n,g=2*Math.PI/o;for(let D=0;D<o;D++){let X=D*g,N=(D+1)*g,I=h+r*Math.cos(X),V=p+i*Math.sin(X),q=h+r*Math.cos(N),Y=p+i*Math.sin(N);Re(e,t,[I,V],[q,Y],s,f)}},filledEllipse:function(e,t,n,r,i,o,s){let[f,h]=n,p=2*Math.PI/o,g=t.data.vertexCount*6,D=o*3*6;t.data.vertices=Zr(Float32Array,t.data.vertices,g,D);let X=t.data.transforms.at(-1);for(let N=0;N<o;N++){let I=N*p,V=(N+1)*p,q=f+r*Math.cos(I),Y=h+i*Math.sin(I),K=f+r*Math.cos(V),Q=h+i*Math.sin(V),H=t.data.vertexCount*6+N*18,W=Et.transformMat3([f,h],X);t.data.vertices[H+0]=W[0],t.data.vertices[H+1]=W[1],t.data.vertices[H+2]=s[0],t.data.vertices[H+3]=s[1],t.data.vertices[H+4]=s[2],t.data.vertices[H+5]=s[3],Et.transformMat3([q,Y],X,W),t.data.vertices[H+6]=W[0],t.data.vertices[H+7]=W[1],t.data.vertices[H+8]=s[0],t.data.vertices[H+9]=s[1],t.data.vertices[H+10]=s[2],t.data.vertices[H+11]=s[3],Et.transformMat3([K,Q],X,W),t.data.vertices[H+12]=W[0],t.data.vertices[H+13]=W[1],t.data.vertices[H+14]=s[0],t.data.vertices[H+15]=s[1],t.data.vertices[H+16]=s[2],t.data.vertices[H+17]=s[3]}t.data.vertexCount+=3*o,t.data.dirty=!0},box:function(e,t,n,r,i,o,s=1){let[f,h]=n,p=r/2,g=i/2,D=[f-p,h-g],X=[f+p,h-g],N=[f-p,h+g],I=[f+p,h+g];Re(e,t,D,X,o,s),Re(e,t,N,I,o,s),Re(e,t,D,N,o,s),Re(e,t,X,I,o,s)},filledBox:function(e,t,n,r,i,o){let[s,f]=n,h=r/2,p=i/2,g=t.data.transforms.at(-1),D=Et.transformMat3([s-h,f-p],g),X=Et.transformMat3([s+h,f-p],g),N=Et.transformMat3([s-h,f+p],g),I=Et.transformMat3([s+h,f+p],g),V=t.data.vertexCount*6,q=36;t.data.vertices=Zr(Float32Array,t.data.vertices,V,q);let Y=t.data.vertexCount*6;t.data.vertices[Y+0]=D[0],t.data.vertices[Y+1]=D[1],t.data.vertices[Y+2]=o[0],t.data.vertices[Y+3]=o[1],t.data.vertices[Y+4]=o[2],t.data.vertices[Y+5]=o[3],t.data.vertices[Y+6]=N[0],t.data.vertices[Y+7]=N[1],t.data.vertices[Y+8]=o[0],t.data.vertices[Y+9]=o[1],t.data.vertices[Y+10]=o[2],t.data.vertices[Y+11]=o[3],t.data.vertices[Y+12]=X[0],t.data.vertices[Y+13]=X[1],t.data.vertices[Y+14]=o[0],t.data.vertices[Y+15]=o[1],t.data.vertices[Y+16]=o[2],t.data.vertices[Y+17]=o[3],t.data.vertices[Y+18]=N[0],t.data.vertices[Y+19]=N[1],t.data.vertices[Y+20]=o[0],t.data.vertices[Y+21]=o[1],t.data.vertices[Y+22]=o[2],t.data.vertices[Y+23]=o[3],t.data.vertices[Y+24]=I[0],t.data.vertices[Y+25]=I[1],t.data.vertices[Y+26]=o[0],t.data.vertices[Y+27]=o[1],t.data.vertices[Y+28]=o[2],t.data.vertices[Y+29]=o[3],t.data.vertices[Y+30]=X[0],t.data.vertices[Y+31]=X[1],t.data.vertices[Y+32]=o[0],t.data.vertices[Y+33]=o[1],t.data.vertices[Y+34]=o[2],t.data.vertices[Y+35]=o[3],t.data.vertexCount+=6,t.data.dirty=!0},clear:function(e,t){t.data.vertexCount=0,t.data.transforms.length=1,Me.identity(t.data.transforms[0]),t.data.dirty=!0}};function Re(e,t,n,r,i,o=1){let s=t.data.transforms.at(-1);n=Et.transformMat3(n,s),r=Et.transformMat3(r,s);let f=Et.sub(r,n),h=Et.normalize(f),p=Sc(h),g=o/2,D=t.data.vertexCount*6,X=t.data.vertexCount*6,N=36;t.data.vertices=Zr(Float32Array,t.data.vertices,X,N),t.data.vertices[D+0]=n[0]+p[0]*g,t.data.vertices[D+1]=n[1]+p[1]*g,t.data.vertices[D+2]=i[0],t.data.vertices[D+3]=i[1],t.data.vertices[D+4]=i[2],t.data.vertices[D+5]=i[3],t.data.vertices[D+6]=n[0]-p[0]*g,t.data.vertices[D+7]=n[1]-p[1]*g,t.data.vertices[D+8]=i[0],t.data.vertices[D+9]=i[1],t.data.vertices[D+10]=i[2],t.data.vertices[D+11]=i[3],t.data.vertices[D+12]=r[0]+p[0]*g,t.data.vertices[D+13]=r[1]+p[1]*g,t.data.vertices[D+14]=i[0],t.data.vertices[D+15]=i[1],t.data.vertices[D+16]=i[2],t.data.vertices[D+17]=i[3],t.data.vertices[D+18]=n[0]-p[0]*g,t.data.vertices[D+19]=n[1]-p[1]*g,t.data.vertices[D+20]=i[0],t.data.vertices[D+21]=i[1],t.data.vertices[D+22]=i[2],t.data.vertices[D+23]=i[3],t.data.vertices[D+24]=r[0]+p[0]*g,t.data.vertices[D+25]=r[1]+p[1]*g,t.data.vertices[D+26]=i[0],t.data.vertices[D+27]=i[1],t.data.vertices[D+28]=i[2],t.data.vertices[D+29]=i[3],t.data.vertices[D+30]=r[0]-p[0]*g,t.data.vertices[D+31]=r[1]-p[1]*g,t.data.vertices[D+32]=i[0],t.data.vertices[D+33]=i[1],t.data.vertices[D+34]=i[2],t.data.vertices[D+35]=i[3],t.data.vertexCount+=6,t.data.dirty=!0}function Zr(e,t,n,r){if(n+r<=t.length)return t;let i=t.length*2,o=16*1024*1024/t.BYTES_PER_ELEMENT;if(i>o)throw new Error("vertices exceed max array size");let s=new e(i);return s.set(t),s}function Sc(e){return[-e[1],e[0]]}var ds=fe.create(0,0,0),ws={type:"cobalt:primitives",refs:[{name:"color",type:"textView",format:"PREFERRED_TEXTURE_VIEW",access:"write"}],onInit:async function(e,t={}){return _c(e,t)},onRun:function(e,t,n){Bc(e,t,n)},onDestroy:function(e,t){Dc(t)},onResize:function(e,t){gs(e,t)},onViewportPosition:function(e,t){gs(e,t)},customFunctions:vs};async function _c(e,t){let{device:n}=e,r=new Float32Array(1024),i=n.createBuffer({size:r.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),o=n.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=n.createShaderModule({code:Ri}),f=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}}]}),h=n.createPipelineLayout({bindGroupLayouts:[f]}),p=n.createBindGroup({layout:f,entries:[{binding:0,resource:{buffer:o}}]}),g=n.createRenderPipeline({label:"primitives",layout:h,vertex:{module:s,entryPoint:"vs_main",buffers:[{arrayStride:6*Float32Array.BYTES_PER_ELEMENT,attributes:[{shaderLocation:0,offset:0,format:"float32x2"},{shaderLocation:1,format:"float32x4",offset:8}]}]},fragment:{module:s,entryPoint:"fs_main",targets:[{format:qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"}});return{uniformBuffer:o,vertexBuffer:i,pipeline:g,bindGroup:p,vertexCount:0,dirty:!1,vertices:r,transforms:[Me.identity()]}}function Bc(e,t,n){if(t.data.vertexCount===0)return;let{device:r}=e;if(t.data.dirty){t.data.dirty=!1;let s=6*Float32Array.BYTES_PER_ELEMENT;t.data.vertices.buffer.byteLength>t.data.vertexBuffer.size&&(t.data.vertexBuffer.destroy(),t.data.vertexBuffer=r.createBuffer({size:t.data.vertices.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}));let f=t.data.vertexCount*s;if(f>t.data.vertexBuffer.size){console.error("too many primitives, bailing");return}e.device.queue.writeBuffer(t.data.vertexBuffer,0,t.data.vertices.buffer,0,f)}let i=t.options.loadOp||"load",o=n.beginRenderPass({label:"primitives",colorAttachments:[{view:t.refs.color,clearValue:e.clearValue,loadOp:i,storeOp:"store"}]});o.setPipeline(t.data.pipeline),o.setBindGroup(0,t.data.bindGroup),o.setVertexBuffer(0,t.data.vertexBuffer),o.draw(t.data.vertexCount),o.end()}function Dc(e){e.data.vertexBuffer.destroy(),e.data.vertexBuffer=null,e.data.uniformBuffer.destroy(),e.data.uniformBuffer=null,e.data.transforms.length=0}function gs(e,t){let{device:n}=e,r=e.viewport.width/e.viewport.zoom,i=e.viewport.height/e.viewport.zoom,o=Lt.ortho(0,r,i,0,-10,10);fe.set(-e.viewport.position[0]-1,-e.viewport.position[1]-1,0,ds);let s=Lt.translation(ds);n.queue.writeBuffer(t.data.uniformBuffer,0,s.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,o.buffer)}var ei="struct BloomComposite{bloom_intensity:f32,bloom_combine_constant:f32,}@group(0)@binding(0)var mySampler:sampler;@group(0)@binding(1)var colorTexture:texture_2d<f32>;@group(0)@binding(2)var emissiveTexture:texture_2d<f32>;@group(0)@binding(3)var<uniform> composite_parameter:BloomComposite;struct VertexOutput{@builtin(position)Position:vec4<f32>,@location(0)fragUV:vec2<f32>,}const positions=array<vec2<f32>,3>(vec2<f32>(-1.0,-3.0),vec2<f32>(3.0,1.0),vec2<f32>(-1.0,1.0));const uvs=array<vec2<f32>,3>(vec2<f32>(0.0,2.0),vec2<f32>(2.0,0.0),vec2<f32>(0.0,0.0));@vertex fn vert_main(@builtin(vertex_index)VertexIndex:u32)->VertexOutput{var output:VertexOutput;output.Position=vec4<f32>(positions[VertexIndex],0.0,1.0);output.fragUV=vec2<f32>(uvs[VertexIndex]);return output;}fn GTTonemap_point(x:f32)->f32{let m:f32=0.22;let a:f32=1.0;let c:f32=1.33;let P:f32=1.0;let l:f32=0.4;let l0:f32=((P-m)*l)/a;let S0:f32=m+l0;let S1:f32=m+a*l0;let C2:f32=(a*P)/(P-S1);let L:f32=m+a*(x-m);let T:f32=m*pow(x/m,c);let S:f32=P-(P-S1)*exp(-C2*(x-S0)/P);let w0:f32=1.0-smoothstep(0.0,m,x);var w2:f32=1.0;if(x<m+l){w2=0.0;}let w1:f32=1.0-w0-w2;return f32(T*w0+L*w1+S*w2);}fn GTTonemap(x:vec3<f32>)->vec3<f32>{return vec3<f32>(GTTonemap_point(x.r),GTTonemap_point(x.g),GTTonemap_point(x.b));}fn aces(x:vec3<f32>)->vec3<f32>{let a:f32=2.51;let b:f32=0.03;let c:f32=2.43;let d:f32=0.59;let e:f32=0.14;return clamp((x*(a*x+b))/(x*(c*x+d)+e),vec3<f32>(0.0),vec3<f32>(1.0));}@fragment fn frag_main(@location(0)fragUV:vec2<f32>)->@location(0)vec4<f32>{let hdr_color=textureSample(colorTexture,mySampler,fragUV);let bloom_color=textureSample(emissiveTexture,mySampler,fragUV);let combined_color=((bloom_color*composite_parameter.bloom_intensity)*composite_parameter.bloom_combine_constant);let mapped_color=GTTonemap(combined_color.rgb);let gamma_corrected_color=pow(mapped_color,vec3<f32>(1.0/2.2));return vec4<f32>(gamma_corrected_color+hdr_color.rgb,1.0);}";var xs={type:"cobalt:bloom",refs:[{name:"hdr",type:"textureView",format:"rgba16",access:"read"},{name:"bloom",type:"textureView",format:"rgba16",access:"read"},{name:"combined",type:"textureView",format:"PREFERRED_TEXTURE_FORMAT",access:"write"}],onInit:async function(e,t={}){return Uc(e,t)},onRun:function(e,t,n){Fc(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){Gc(e,t)},onViewportPosition:function(e,t){}};function Uc(e,t){let{options:n,refs:r}=t,{device:i}=e,o=qt(e),s=n.bloom_intensity??40,f=n.bloom_combine_constant??.68,h=new Float32Array([s,f]),p=i.createBuffer({label:"scene composite params buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});new Float32Array(p.getMappedRange()).set(h),p.unmap();let g=i.createRenderPipeline({label:"scenecomposite",layout:"auto",vertex:{module:i.createShaderModule({code:ei}),entryPoint:"vert_main"},fragment:{module:i.createShaderModule({code:ei}),entryPoint:"frag_main",targets:[{format:o}]},primitive:{topology:"triangle-list"}});return{bindGroup:i.createBindGroup({layout:g.getBindGroupLayout(0),entries:[{binding:0,resource:r.hdr.data.sampler},{binding:1,resource:r.hdr.data.view},{binding:2,resource:r.bloom.data.mip_view[0]},{binding:3,resource:{buffer:p}}]}),pipeline:g,params_buf:p}}function Fc(e,t,n){let r=n.beginRenderPass({label:"scene-composite",colorAttachments:[{view:t.refs.combined.data.view,clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),{pipeline:i,bindGroup:o}=t.data;r.setPipeline(i),r.setBindGroup(0,o),r.draw(3),r.end()}function Gc(e,t){let{pipeline:n,params_buf:r}=t.data,{device:i}=e;t.data.bindGroup=i.createBindGroup({layout:n.getBindGroupLayout(0),entries:[{binding:0,resource:t.refs.hdr.data.sampler},{binding:1,resource:t.refs.hdr.data.view},{binding:2,resource:t.refs.bloom.data.mip_view[0]},{binding:3,resource:{buffer:r}}]})}var ri={};hn(ri,{addSprite:()=>Ac,clear:()=>Lc,removeSprite:()=>zc,setSpriteName:()=>Ec,setSpriteOpacity:()=>Oc,setSpritePosition:()=>Rc,setSpriteRotation:()=>mc,setSpriteScale:()=>Vc,setSpriteTint:()=>Ic});function Ac(e,t,n,r,i,o,s,f){let{idByName:h}=t.refs.spritesheet.data;return t.data.sprites.push({position:Et.clone(r),sizeX:1,sizeY:1,scale:Et.clone(i),rotation:f,opacity:s,tint:Ce.clone(o),spriteID:h.get(n),id:Be()}),t.data.sprites.at(-1).id}function zc(e,t,n){for(let r=0;r<t.data.sprites.length;r++)if(t.data.sprites[r].id===n){t.data.sprites.splice(r,1);return}}function Lc(e,t){t.data.sprites.length=0}function Ec(e,t,n,r){let i=t.data.sprites.find(s=>s.id===n);if(!i)return;let{idByName:o}=t.refs.spritesheet.data;i.spriteID=o.get(r)}function Rc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.position)}function Ic(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Ce.copy(r,i.tint)}function Oc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.opacity=r)}function mc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.rotation=r)}function Vc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.scale)}var ys="struct ViewParams{view:mat4x4<f32>,proj:mat4x4<f32>};@group(0)@binding(0)var<uniform> uView:ViewParams;@group(0)@binding(1)var uSampler:sampler;@group(0)@binding(2)var uTex:texture_2d<f32>;struct SpriteDesc{uvOrigin:vec2<f32>,uvSpan:vec2<f32>,frameSize:vec2<f32>,centerOffset:vec2<f32>,};@group(0)@binding(3)var<storage,read>Sprites:array<SpriteDesc>;struct VSOut{@builtin(position)pos:vec4<f32>,@location(0)uv:vec2<f32>,@location(1)tint:vec4<f32>,@location(2)opacity:f32,};const corners=array<vec2<f32>,4>(vec2<f32>(-0.5,-0.5),vec2<f32>(0.5,-0.5),vec2<f32>(-0.5,0.5),vec2<f32>(0.5,0.5),);const uvBase=array<vec2<f32>,4>(vec2<f32>(0.0,0.0),vec2<f32>(1.0,0.0),vec2<f32>(0.0,1.0),vec2<f32>(1.0,1.0),);@vertex fn vs_main(@builtin(vertex_index)vid:u32,@location(0)i_pos:vec2<f32>,@location(1)i_size:vec2<f32>,@location(2)i_scale:vec2<f32>,@location(3)i_tint:vec4<f32>,@location(4)i_spriteId:u32,@location(5)i_opacity:f32,@location(6)i_rotation:f32)->VSOut{let rot=i_rotation;let c=cos(rot);let s=sin(rot);let d=Sprites[i_spriteId];let corner=corners[vid];let sizePx=d.frameSize*i_size*i_scale;var local=corner*sizePx;local+=d.centerOffset*i_scale;let rotated=vec2<f32>(local.x*c-local.y*s,local.x*s+local.y*c);let world=vec4<f32>(rotated+i_pos,0.0,1.0);var out:VSOut;out.pos=uView.proj*uView.view*world;out.uv=d.uvOrigin+d.uvSpan*uvBase[vid];out.tint=i_tint;out.opacity=i_opacity;return out;}@fragment fn fs_main(in:VSOut)->@location(0)vec4<f32>{let texel=textureSample(uTex,uSampler,in.uv);return vec4<f32>(texel.rgb*(1.0-in.tint.a)+(in.tint.rgb*in.tint.a),texel.a*in.opacity);}";var ni=fe.create(0,0,0),Ie=64,ii=0,oi=8,ai=16,fr=24,bs=40,Ts=44,Ps=48,Ss={type:"cobalt:sprite",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"color",type:"textureView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return qc(e,t)},onRun:function(e,t,n){Cc(e,t,n)},onDestroy:function(e,t){try{t.data.instanceBuf?.destroy()}catch{}try{t.data.spriteBuf?.destroy()}catch{}try{t.data.uniformBuffer?.destroy()}catch{}t.data.pipeline=null,t.data.bindGroup=null,t.data.bindGroupLayout=null,t.data.instanceStaging=null,t.data.instanceView=null,t.data.sprites.length=0,t.data.visible.length=0},onResize:function(e,t){Ms(e,t)},onViewportPosition:function(e,t){Ms(e,t)},customFunctions:{...ri}};async function qc(e,t){let{device:n}=e,{descs:r,names:i}=t.refs.spritesheet.data.spritesheet,o=n.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=32,f=new ArrayBuffer(s*r.length),h=new Float32Array(f);for(let tt=0;tt<r.length;tt++){let H=r[tt],W=tt*8;h[W+0]=H.UvOrigin[0],h[W+1]=H.UvOrigin[1],h[W+2]=H.UvSpan[0],h[W+3]=H.UvSpan[1],h[W+4]=H.FrameSize[0],h[W+5]=H.FrameSize[1],h[W+6]=H.CenterOffset[0],h[W+7]=H.CenterOffset[1]}let p=n.createBuffer({label:"sprite desc table",size:Math.max(16,f.byteLength),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});n.queue.writeBuffer(p,0,f);let g=1024,D=n.createBuffer({label:"sprite instances",size:Ie*g,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),X=new ArrayBuffer(Ie*g),N=new DataView(X),I=n.createShaderModule({code:ys}),V=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float"}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}]}),q=n.createPipelineLayout({bindGroupLayouts:[V]}),Y={arrayStride:Ie,stepMode:"instance",attributes:[{shaderLocation:0,offset:ii,format:"float32x2"},{shaderLocation:1,offset:oi,format:"float32x2"},{shaderLocation:2,offset:ai,format:"float32x2"},{shaderLocation:3,offset:fr,format:"float32x4"},{shaderLocation:4,offset:bs,format:"uint32"},{shaderLocation:5,offset:Ts,format:"float32"},{shaderLocation:6,offset:Ps,format:"float32"}]},K=n.createRenderPipeline({layout:q,vertex:{module:I,entryPoint:"vs_main",buffers:[Y]},fragment:{module:I,entryPoint:"fs_main",targets:[{format:qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-strip",cullMode:"none"},multisample:{count:1}}),Q=n.createBindGroup({layout:V,entries:[{binding:0,resource:{buffer:o}},{binding:1,resource:t.refs.spritesheet.data.colorTexture.sampler},{binding:2,resource:t.refs.spritesheet.data.colorTexture.view},{binding:3,resource:{buffer:p}}]});return{sprites:[],visible:[],visibleCount:0,viewRect:{x:0,y:0,w:0,h:0},spriteBuf:p,uniformBuffer:o,instanceCap:g,instanceView:N,instanceBuf:D,instanceStaging:X,pipeline:K,bindGroup:Q}}function Nc(e,t,n){let{instanceCap:r}=t.data;if(n<=r)return;let i=r;for(i===0&&(i=1024);i<n;)i*=2;t.data.instanceBuf.destroy(),t.data.instanceBuf=e.device.createBuffer({size:Ie*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),t.data.instanceStaging=new ArrayBuffer(Ie*i),t.data.instanceView=new DataView(t.data.instanceStaging),t.data.instanceCap=i}function Cc(e,t,n){let{device:r,context:i}=e,{instanceView:o,instanceBuf:s,instanceStaging:f,pipeline:h,bindGroup:p}=t.data,{descs:g}=t.refs.spritesheet.data.spritesheet,D=t.data.viewRect;D.x=e.viewport.position[0],D.y=e.viewport.position[1],D.w=e.viewport.width,D.h=e.viewport.height,t.data.visibleCount=0;for(let I of t.data.sprites){let V=g[I.spriteID];if(V){if(!t.options.isScreenSpace){let q=V.FrameSize[0]*I.sizeX*I.scale[0]*.5,Y=V.FrameSize[1]*I.sizeY*I.scale[1]*.5,K=Math.hypot(q,Y),Q=I.position[0],tt=I.position[1];if(Q+K<D.x||Q-K>D.x+D.w||tt+K<D.y||tt-K>D.y+D.h)continue}t.data.visible[t.data.visibleCount]=I,t.data.visibleCount++}}Nc(e,t,t.data.visibleCount);for(let I=0;I<t.data.visibleCount;I++){let V=I*Ie,q=t.data.visible[I],Y=q.tint;o.setFloat32(V+ii+0,q.position[0],!0),o.setFloat32(V+ii+4,q.position[1],!0),o.setFloat32(V+oi+0,q.sizeX,!0),o.setFloat32(V+oi+4,q.sizeY,!0),o.setFloat32(V+ai+0,q.scale[0],!0),o.setFloat32(V+ai+4,q.scale[1],!0),o.setFloat32(V+fr+0,Y[0],!0),o.setFloat32(V+fr+4,Y[1],!0),o.setFloat32(V+fr+8,Y[2],!0),o.setFloat32(V+fr+12,Y[3],!0),o.setUint32(V+bs,q.spriteID>>>0,!0),o.setFloat32(V+Ts,q.opacity,!0),o.setFloat32(V+Ps,q.rotation,!0)}r.queue.writeBuffer(s,0,f,0,t.data.visibleCount*Ie);let X=t.options.loadOp||"load",N=n.beginRenderPass({label:"sprite renderpass",colorAttachments:[{view:t.refs.color,clearValue:e.clearValue,loadOp:X,storeOp:"store"}]});N.setPipeline(h),N.setBindGroup(0,p),N.setVertexBuffer(0,s),t.data.visibleCount&&N.draw(4,t.data.visibleCount,0,0),N.end()}function Ms(e,t){let{device:n,viewport:r}=e,i=r.width/r.zoom,o=r.height/r.zoom,s=Lt.ortho(0,i,o,0,-10,10);t.options.isScreenSpace?fe.set(0,0,0,ni):fe.set(-de(r.position[0]),-de(r.position[1]),0,ni);let f=Lt.translation(ni);n.queue.writeBuffer(t.data.uniformBuffer,0,f.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,s.buffer)}var si={};hn(si,{addSprite:()=>Xc,clear:()=>Yc,removeSprite:()=>kc,setSpriteName:()=>Hc,setSpriteOpacity:()=>Wc,setSpritePosition:()=>Zc,setSpriteRotation:()=>Kc,setSpriteScale:()=>Qc,setSpriteTint:()=>$c});function Xc(e,t,n,r,i,o,s,f){let{idByName:h}=t.refs.spritesheet.data;return t.data.sprites.push({position:Et.clone(r),sizeX:1,sizeY:1,scale:Et.clone(i),rotation:f,opacity:s,tint:Ce.clone(o),spriteID:h.get(n),id:Be()}),t.data.sprites.at(-1).id}function kc(e,t,n){for(let r=0;r<t.data.sprites.length;r++)if(t.data.sprites[r].id===n){t.data.sprites.splice(r,1);return}}function Yc(e,t){t.data.sprites.length=0}function Hc(e,t,n,r){let i=t.data.sprites.find(s=>s.id===n);if(!i)return;let{idByName:o}=t.refs.spritesheet.data;i.spriteID=o.get(r)}function Zc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.position)}function $c(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Ce.copy(r,i.tint)}function Wc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.opacity=r)}function Kc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.rotation=r)}function Qc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.scale)}var _s="struct ViewParams{view:mat4x4<f32>,proj:mat4x4<f32>};@group(0)@binding(0)var<uniform> uView:ViewParams;@group(0)@binding(1)var uSampler:sampler;@group(0)@binding(2)var uTex:texture_2d<f32>;struct SpriteDesc{uvOrigin:vec2<f32>,uvSpan:vec2<f32>,frameSize:vec2<f32>,centerOffset:vec2<f32>,};@group(0)@binding(3)var<storage,read>Sprites:array<SpriteDesc>;@group(0)@binding(4)var emissiveTexture:texture_2d<f32>;struct VSOut{@builtin(position)pos:vec4<f32>,@location(0)uv:vec2<f32>,@location(1)tint:vec4<f32>,@location(2)opacity:f32,};const corners=array<vec2<f32>,4>(vec2<f32>(-0.5,-0.5),vec2<f32>(0.5,-0.5),vec2<f32>(-0.5,0.5),vec2<f32>(0.5,0.5),);const uvBase=array<vec2<f32>,4>(vec2<f32>(0.0,0.0),vec2<f32>(1.0,0.0),vec2<f32>(0.0,1.0),vec2<f32>(1.0,1.0),);struct GBufferOutput{@location(0)color:vec4<f32>,@location(1)emissive:vec4<f32>,}@vertex fn vs_main(@builtin(vertex_index)vid:u32,@location(0)i_pos:vec2<f32>,@location(1)i_size:vec2<f32>,@location(2)i_scale:vec2<f32>,@location(3)i_tint:vec4<f32>,@location(4)i_spriteId:u32,@location(5)i_opacity:f32,@location(6)i_rotation:f32)->VSOut{let rot=i_rotation;let c=cos(rot);let s=sin(rot);let d=Sprites[i_spriteId];let corner=corners[vid];let sizePx=d.frameSize*i_size*i_scale;var local=corner*sizePx;local+=d.centerOffset*i_scale;let rotated=vec2<f32>(local.x*c-local.y*s,local.x*s+local.y*c);let world=vec4<f32>(rotated+i_pos,0.0,1.0);var out:VSOut;out.pos=uView.proj*uView.view*world;out.uv=d.uvOrigin+d.uvSpan*uvBase[vid];out.tint=i_tint;out.opacity=i_opacity;return out;}@fragment fn fs_main(in:VSOut)->GBufferOutput{var output:GBufferOutput;let texel=textureSample(uTex,uSampler,in.uv);output.color=vec4<f32>(texel.rgb*(1.0-in.tint.a)+(in.tint.rgb*in.tint.a),texel.a*in.opacity);let emissive=textureSample(emissiveTexture,uSampler,in.uv);output.emissive=vec4(emissive.rgb,1.0)*emissive.a;return output;}";var ui=fe.create(0,0,0),Oe=64,fi=0,ci=8,li=16,cr=24,Ds=40,Us=44,Fs=48,Gs={type:"cobalt:spriteHDR",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"color",type:"textureView",format:"rgba16float",access:"write"},{name:"emissive",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return Jc(e,t)},onRun:function(e,t,n){tl(e,t,n)},onDestroy:function(e,t){try{t.data.instanceBuf?.destroy()}catch{}try{t.data.spriteBuf?.destroy()}catch{}try{t.data.uniformBuffer?.destroy()}catch{}t.data.pipeline=null,t.data.bindGroup=null,t.data.bindGroupLayout=null,t.data.instanceStaging=null,t.data.instanceView=null,t.data.sprites.length=0,t.data.visible.length=0},onResize:function(e,t){Bs(e,t)},onViewportPosition:function(e,t){Bs(e,t)},customFunctions:{...si}};async function Jc(e,t){let{device:n}=e,{descs:r,names:i}=t.refs.spritesheet.data.spritesheet,o=n.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=32,f=new ArrayBuffer(s*r.length),h=new Float32Array(f);for(let H=0;H<r.length;H++){let W=r[H],st=H*8;h[st+0]=W.UvOrigin[0],h[st+1]=W.UvOrigin[1],h[st+2]=W.UvSpan[0],h[st+3]=W.UvSpan[1],h[st+4]=W.FrameSize[0],h[st+5]=W.FrameSize[1],h[st+6]=W.CenterOffset[0],h[st+7]=W.CenterOffset[1]}let p=n.createBuffer({label:"spriteHDR desc table",size:Math.max(16,f.byteLength),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});n.queue.writeBuffer(p,0,f);let g=1024,D=n.createBuffer({label:"spriteHDR instances",size:Oe*g,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),X=new ArrayBuffer(Oe*g),N=new DataView(X),I=n.createShaderModule({code:_s}),V=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float"}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}},{binding:4,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float"}}]}),q=n.createPipelineLayout({bindGroupLayouts:[V]}),Y={arrayStride:Oe,stepMode:"instance",attributes:[{shaderLocation:0,offset:fi,format:"float32x2"},{shaderLocation:1,offset:ci,format:"float32x2"},{shaderLocation:2,offset:li,format:"float32x2"},{shaderLocation:3,offset:cr,format:"float32x4"},{shaderLocation:4,offset:Ds,format:"uint32"},{shaderLocation:5,offset:Us,format:"float32"},{shaderLocation:6,offset:Fs,format:"float32"}]},K=n.createRenderPipeline({layout:q,vertex:{module:I,entryPoint:"vs_main",buffers:[Y]},fragment:{module:I,entryPoint:"fs_main",targets:[{format:"rgba16float",blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}},{format:"rgba16float"}]},primitive:{topology:"triangle-strip",cullMode:"none"},multisample:{count:1}}),Q=V,tt=n.createBindGroup({layout:V,entries:[{binding:0,resource:{buffer:o}},{binding:1,resource:t.refs.spritesheet.data.colorTexture.sampler},{binding:2,resource:t.refs.spritesheet.data.colorTexture.view},{binding:3,resource:{buffer:p}},{binding:4,resource:t.refs.spritesheet.data.emissiveTexture.view}]});return{sprites:[],visible:[],visibleCount:0,viewRect:{x:0,y:0,w:0,h:0},spriteBuf:p,uniformBuffer:o,instanceCap:g,instanceView:N,instanceBuf:D,instanceStaging:X,pipeline:K,bindGroup:tt}}function jc(e,t,n){let{instanceCap:r}=t.data;if(n<=r)return;let i=r;for(i===0&&(i=1024);i<n;)i*=2;t.data.instanceBuf.destroy(),t.data.instanceBuf=e.device.createBuffer({size:Oe*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),t.data.instanceStaging=new ArrayBuffer(Oe*i),t.data.instanceView=new DataView(t.data.instanceStaging),t.data.instanceCap=i}function tl(e,t,n){let{device:r,context:i}=e,{instanceView:o,instanceBuf:s,instanceStaging:f,pipeline:h,bindGroup:p}=t.data,{descs:g}=t.refs.spritesheet.data.spritesheet,D=t.data.viewRect;D.x=e.viewport.position[0],D.y=e.viewport.position[1],D.w=e.viewport.width,D.h=e.viewport.height,t.data.visibleCount=0;for(let I of t.data.sprites){let V=g[I.spriteID];if(V){if(!t.options.isScreenSpace){let q=V.FrameSize[0]*I.sizeX*I.scale[0]*.5,Y=V.FrameSize[1]*I.sizeY*I.scale[1]*.5,K=Math.hypot(q,Y),Q=I.position[0],tt=I.position[1];if(Q+K<D.x||Q-K>D.x+D.w||tt+K<D.y||tt-K>D.y+D.h)continue}t.data.visible[t.data.visibleCount]=I,t.data.visibleCount++}}jc(e,t,t.data.visibleCount);for(let I=0;I<t.data.visibleCount;I++){let V=I*Oe,q=t.data.visible[I],Y=q.tint;o.setFloat32(V+fi+0,q.position[0],!0),o.setFloat32(V+fi+4,q.position[1],!0),o.setFloat32(V+ci+0,q.sizeX,!0),o.setFloat32(V+ci+4,q.sizeY,!0),o.setFloat32(V+li+0,q.scale[0],!0),o.setFloat32(V+li+4,q.scale[1],!0),o.setFloat32(V+cr+0,Y[0],!0),o.setFloat32(V+cr+4,Y[1],!0),o.setFloat32(V+cr+8,Y[2],!0),o.setFloat32(V+cr+12,Y[3],!0),o.setUint32(V+Ds,q.spriteID>>>0,!0),o.setFloat32(V+Us,q.opacity,!0),o.setFloat32(V+Fs,q.rotation,!0)}r.queue.writeBuffer(s,0,f,0,t.data.visibleCount*Oe);let X=t.options.loadOp||"load",N=n.beginRenderPass({label:"spriteHDR renderpass",colorAttachments:[{view:t.refs.color.data.view,clearValue:e.clearValue,loadOp:X,storeOp:"store"},{view:t.refs.emissive.data.view,clearValue:e.clearValue,loadOp:"clear",storeOp:"store"}]});N.setPipeline(h),N.setBindGroup(0,p),N.setVertexBuffer(0,s),t.data.visibleCount&&N.draw(4,t.data.visibleCount,0,0),N.end()}function Bs(e,t){let{device:n,viewport:r}=e,i=r.width/r.zoom,o=r.height/r.zoom,s=Lt.ortho(0,i,o,0,-10,10);t.options.isScreenSpace?fe.set(0,0,0,ui):fe.set(-de(r.position[0]),-de(r.position[1]),0,ui);let f=Lt.translation(ui);n.queue.writeBuffer(t.data.uniformBuffer,0,f.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,s.buffer)}function $r(e){let t=e.meta.size.w,n=e.meta.size.h,r=Object.keys(e.frames).sort(),i=new Array(r.length);for(let o=0;o<r.length;o++){let s=e.frames[r[o]],f=s.frame.x,h=s.frame.y,p=s.frame.w,g=s.frame.h,D=f/t,X=h/n,N=p/t,I=g/n,V=s.sourceSize.w,q=s.sourceSize.h,Y=s.spriteSourceSize.x,K=s.spriteSourceSize.y,Q=Y+p*.5-V*.5,tt=K+g*.5-q*.5;i[o]={UvOrigin:[D,X],UvSpan:[N,I],FrameSize:[p,g],CenterOffset:[Q,tt]}}return{descs:i,names:r}}var As={type:"cobalt:spritesheet",refs:[],onInit:async function(e,t={}){return el(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){rl(t)},onResize:function(e,t){},onViewportPosition:function(e,t){}};async function el(e,t){let{canvas:n,device:r}=e,i,o,s,f=t.options.format||"rgba8unorm";n?(i=await fetch(t.options.spriteSheetJsonUrl),i=await i.json(),i=$r(i),o=await ve(e,"sprite",t.options.colorTextureUrl,f),s=await ve(e,"emissive sprite",t.options.emissiveTextureUrl,f),n.style.imageRendering="pixelated"):(i=$r(t.options.spriteSheetJson),o=await pe(e,"sprite",t.options.colorTexture,f),s=await pe(e,"emissive sprite",t.options.emissiveTexture,f));let h=new Map(i.names.map((p,g)=>[p,g]));return{colorTexture:o,emissiveTexture:s,spritesheet:i,idByName:h}}function rl(e){e.data.quads.buffer.destroy(),e.data.colorTexture.buffer.destroy(),e.data.emissiveTexture.texture.destroy()}var hi="struct TransformData{viewOffset:vec2<f32>,viewportSize:vec2<f32>,inverseAtlasTextureSize:vec2<f32>,tileSize:f32,inverseTileSize:f32,};struct TileScroll{scrollScale:vec2<f32>};const positions=array<vec2<f32>,3>(vec2<f32>(-1.0,-3.0),vec2<f32>(3.0,1.0),vec2<f32>(-1.0,1.0));const uvs=array<vec2<f32>,3>(vec2<f32>(0.0,2.0),vec2<f32>(2.0,0.0),vec2<f32>(0.0,0.0));@binding(0)@group(0)var<uniform> myScroll:TileScroll;@binding(1)@group(0)var tileTexture:texture_2d<f32>;@binding(2)@group(0)var tileSampler:sampler;@binding(0)@group(1)var<uniform> transformUBO:TransformData;@binding(1)@group(1)var atlasTexture:texture_2d<f32>;@binding(2)@group(1)var atlasSampler:sampler;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>};@vertex fn vs_main(@builtin(instance_index)i_id:u32,@builtin(vertex_index)VertexIndex:u32)->Fragment{var vertexPosition=vec2<f32>(positions[VertexIndex]);var vertexTexCoord=vec2<f32>(uvs[VertexIndex]);var output:Fragment;let inverseTileTextureSize=1/vec2<f32>(textureDimensions(tileTexture,0));var scrollScale=myScroll.scrollScale;var viewOffset:vec2<f32>=transformUBO.viewOffset*scrollScale;let PixelCoord=(vertexTexCoord*transformUBO.viewportSize)+viewOffset;output.TexCoord=PixelCoord/transformUBO.tileSize;output.Position=vec4<f32>(vertexPosition,0.0,1.0);return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>)->@location(0)vec4<f32>{var tilemapCoord=floor(TexCoord);var u_tilemapSize=vec2<f32>(textureDimensions(tileTexture,0));var tileFoo=fract((tilemapCoord+vec2<f32>(0.5,0.5))/u_tilemapSize);var tile=floor(textureSample(tileTexture,tileSampler,tileFoo)*255.0);if(tile.x==255&&tile.y==255){discard;}var u_tilesetSize=vec2<f32>(textureDimensions(atlasTexture,0))/transformUBO.tileSize;let u_tileUVMinBounds=vec2<f32>(0.5/transformUBO.tileSize,0.5/transformUBO.tileSize);let u_tileUVMaxBounds=vec2<f32>((transformUBO.tileSize-0.5)/transformUBO.tileSize,(transformUBO.tileSize-0.5)/transformUBO.tileSize);var texcoord=clamp(fract(TexCoord),u_tileUVMinBounds,u_tileUVMaxBounds);var tileCoord=(tile.xy+texcoord)/u_tilesetSize;var color=textureSample(atlasTexture,atlasSampler,tileCoord);if(color.a<=0.1){discard;}return color;}";var ye=new Float32Array(8),Ls={type:"cobalt:tileAtlas",refs:[],onInit:async function(e,t={}){return nl(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){il(t)},onResize:function(e,t){zs(e,t)},onViewportPosition:function(e,t){zs(e,t)}};async function nl(e,t){let{canvas:n,device:r}=e,i=t.options.format||"rgba8unorm",o;n?o=await ve(e,"tile atlas",t.options.textureUrl,i):o=await pe(e,"tile atlas",t.options.texture,i);let s=r.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),f=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),h=r.createBindGroup({layout:f,entries:[{binding:0,resource:{buffer:s}},{binding:1,resource:o.view},{binding:2,resource:o.sampler}]}),p=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),g=r.createPipelineLayout({bindGroupLayouts:[p,f]});return{pipeline:r.createRenderPipeline({label:"tileatlas",vertex:{module:r.createShaderModule({code:hi}),entryPoint:"vs_main",buffers:[]},fragment:{module:r.createShaderModule({code:hi}),entryPoint:"fs_main",targets:[{format:t.options.outputFormat||qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:g}),uniformBuffer:s,atlasBindGroup:h,atlasMaterial:o,tileBindGroupLayout:p,tileSize:t.options.tileSize,tileScale:t.options.tileScale}}function il(e){e.data.atlasMaterial.texture.destroy(),e.data.atlasMaterial.texture=void 0}function zs(e,t){ye[0]=de(e.viewport.position[0]),ye[1]=de(e.viewport.position[1]);let n=t.data,{tileScale:r,tileSize:i}=n,o=e.viewport.width/e.viewport.zoom,s=e.viewport.height/e.viewport.zoom;ye[2]=o/r,ye[3]=s/r,ye[4]=1/n.atlasMaterial.texture.width,ye[5]=1/n.atlasMaterial.texture.height,ye[6]=i,ye[7]=1/i,e.device.queue.writeBuffer(n.uniformBuffer,0,ye,0,8)}var Rs={type:"cobalt:tileHDR",refs:[{name:"tileAtlas",type:"textureView",format:"rgba8unorm",access:"read"},{name:"hdr",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return ol(e,t)},onRun:function(e,t,n){al(e,t,n)},onDestroy:function(e,t){Es(t)},onResize:function(e,t){},onViewportPosition:function(e,t){},customFunctions:{setTexture:async function(e,t,n){let{canvas:r,device:i}=e;Es(t);let o=t.options.format||qt(e),s;r?(t.options.textureUrl=n,s=await ve(e,"tile map",n,o)):s=await pe(e,"tile map",n,o);let f=i.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:t.data.uniformBuffer}},{binding:1,resource:s.view},{binding:2,resource:s.sampler}]});t.data.bindGroup=f,t.data.material=s}}};async function ol(e,t){let{canvas:n,device:r}=e,i,o=t.options.format||qt(e);n?i=await ve(e,"tile map",t.options.textureUrl,o):i=await pe(e,"tile map",t.options.texture,o);let s=new Float32Array([t.options.scrollScale,t.options.scrollScale]),f=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,h={size:s.byteLength,usage:f,mappedAtCreation:!0},p=r.createBuffer(h);return new Float32Array(p.getMappedRange()).set(s),p.unmap(),{bindGroup:r.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:p}},{binding:1,resource:i.view},{binding:2,resource:i.sampler}]}),material:i,uniformBuffer:p,scrollScale:t.options.scrollScale}}function al(e,t,n){if(!t.data.material.texture)return;let{device:r}=e,i=t.options.loadOp||"load",o=n.beginRenderPass({label:"tile",colorAttachments:[{view:t.refs.hdr.data?.view||t.refs.hdr,clearValue:e.clearValue,loadOp:i,storeOp:"store"}]}),s=t.refs.tileAtlas.data;o.setPipeline(s.pipeline),o.setBindGroup(0,t.data.bindGroup),o.setBindGroup(1,s.atlasBindGroup),o.draw(3),o.end()}function Es(e){e.data.material.texture.destroy(),e.data.material.texture=void 0}async function Ap(e,t,n){let r,i,o,s;return e.sdlWindow&&e.gpu?(i=e.gpu,r=await(await i.create(["verbose=1","enable-dawn-features=allow_unsafe_apis"]).requestAdapter()).requestDevice({requiredFeatures:["texture-component-swizzle"]}),o=i.renderGPUDeviceToWindow({device:r,window:e.sdlWindow}),global.GPUBufferUsage=i.GPUBufferUsage,global.GPUShaderStage=i.GPUShaderStage,global.GPUTextureUsage=i.GPUTextureUsage):(s=e,r=await(await navigator.gpu?.requestAdapter({powerPreference:"high-performance"}))?.requestDevice(),i=navigator.gpu,o=s.getContext("webgpu"),o.configure({device:r,format:navigator.gpu?.getPreferredCanvasFormat(),alphaMode:"opaque"})),{nodeDefs:{"cobalt:tileAtlas":Ls,"cobalt:spritesheet":As,"cobalt:fbTexture":zi,"cobalt:sprite":Ss,"cobalt:bloom":wi,"cobalt:composite":xs,"cobalt:spriteHDR":Gs,"cobalt:tileHDR":Rs,"cobalt:displacement":Gi,"cobalt:fbBlit":Ai,"cobalt:primitives":ws,"cobalt:light":Ei},nodes:[],defaultTextureViewRefs:[],canvas:s,device:r,context:o,gpu:i,clearValue:{r:0,g:0,b:0,a:1},viewport:{width:t,height:n,zoom:1,position:[0,0]}}}function zp(e,t){if(!t?.type)throw new Error("Can't define a new node missing a type.");e.nodeDefs[t.type]=t}async function Lp(e,t){let n=e.nodeDefs[t?.type];if(!n)throw new Error("Can't initialize a new node missing a type.");let r={type:t.type,refs:t.refs||{},options:t.options||{},data:{},enabled:!0};for(let o in r.refs)r.refs[o]==="FRAME_TEXTURE_VIEW"&&(e.defaultTextureViewRefs.push({node:r,refName:o}),r.refs[o]=Is(e));r.data=await n.onInit(e,r);let i=n.customFunctions||{};for(let o in i)r[o]=function(...s){return i[o](e,r,...s)};return e.nodes.push(r),r}function Ep(e){let{device:t,context:n}=e,r=t.createCommandEncoder(),i=Is(e);for(let o of e.defaultTextureViewRefs)o.node.refs[o.refName]=i;for(let o of e.nodes){if(!o.enabled)continue;e.nodeDefs[o.type].onRun(e,o,r)}t.queue.submit([r.finish()]),e.canvas||e.context.swap()}function Rp(e){for(let t of e.nodes)e.nodeDefs[t.type].onDestroy(e,t);e.nodes.length=0,e.defaultTextureViewRefs.length=0}function Ip(e,t,n){e.viewport.width=t,e.viewport.height=n;for(let r of e.nodes)e.nodeDefs[r.type].onResize(e,r)}function Op(e,t){e.viewport.position[0]=t[0]-e.viewport.width/2/e.viewport.zoom,e.viewport.position[1]=t[1]-e.viewport.height/2/e.viewport.zoom;for(let n of e.nodes)e.nodeDefs[n.type].onViewportPosition(e,n)}function Is(e){return e.canvas?e.context.getCurrentTexture().createView():e.context.getCurrentTextureView()}export{ne as createTexture,pe as createTextureFromBuffer,ve as createTextureFromUrl,zp as defineNode,Ep as draw,Is as getCurrentTextureView,Ap as init,Lp as initNode,Rp as reset,Ip as setViewportDimensions,Op as setViewportPosition};
|
|
284
|
+
`});this.renderPipeline=t.device.createRenderPipeline({label:"LightsRenderer renderpipeline",layout:"auto",vertex:{module:n,entryPoint:"main_vertex"},fragment:{module:n,entryPoint:"main_fragment",targets:[{format:this.targetTexture.format}]},primitive:{cullMode:"none",topology:"triangle-strip"}});let r=this.renderPipeline.getBindGroupLayout(0);this.bindgroup0=t.device.createBindGroup({label:"LightsRenderer bindgroup 0",layout:r,entries:[{binding:0,resource:{buffer:this.uniformsBufferGpu}},{binding:1,resource:{buffer:this.lightsBuffer.gpuBuffer}},{binding:2,resource:this.lightsTexture.texture.createView({label:"LightsRenderer lightsTexture view"})},{binding:3,resource:t.device.createSampler({label:"LightsRenderer sampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",magFilter:t.lightsTextureProperties.filtering,minFilter:t.lightsTextureProperties.filtering})}]}),this.bindgroup1=this.buildBindgroup1(t.albedo),this.renderBundle=this.buildRenderBundle()}computeLightsTexture(t){this.lightsTexture.update(t)}render(t,n){let r=new ArrayBuffer(80);new Float32Array(r,0,16).set(n),new Float32Array(r,64,3).set(this.ambientLight),this.device.queue.writeBuffer(this.uniformsBufferGpu,0,r),t.executeBundles([this.renderBundle])}setAlbedo(t){this.bindgroup1=this.buildBindgroup1(t),this.renderBundle=this.buildRenderBundle()}setAmbientLight(t){this.ambientLight=[...t]}setObstacles(t){this.lightsTexture.setObstacles(t)}destroy(){this.uniformsBufferGpu.destroy(),this.lightsTexture.destroy()}buildBindgroup1(t){return this.device.createBindGroup({label:"LightsRenderer bindgroup 1",layout:this.renderPipeline.getBindGroupLayout(1),entries:[{binding:0,resource:t.view},{binding:1,resource:t.sampler}]})}buildRenderBundle(){let t=this.device.createRenderBundleEncoder({label:"LightsRenderer renderbundle encoder",colorFormats:[this.targetTexture.format]});return t.setPipeline(this.renderPipeline),t.setBindGroup(0,this.bindgroup0),t.setBindGroup(1,this.bindgroup1),t.draw(4),t.finish({label:"LightsRenderer renderbundle"})}};var dn={};hn(dn,{setAmbientLight:()=>du,setLights:()=>vu,setOccluders:()=>gu});function vu(e,t,n){t.data.lights=n,t.data.lightsBufferNeedsUpdate=!0}function du(e,t,n){t.data.lightsRenderer.setAmbientLight(n)}function gu(e,t,n){t.data.lightsRenderer.setObstacles(n),t.data.lightsTextureNeedsUpdate=!0}var br=class{invViewProjectionMatrix=Lt.identity();viewportSize={width:1,height:1};topLeft=[0,0];zoom=1;constructor(t){this.setViewportSize(t.viewportSize.width,t.viewportSize.height);let n=t.center??this.topLeft;this.setTopLeft(...n);let r=t.zoom??1;this.setZoom(r)}get invertViewProjectionMatrix(){return this.invViewProjectionMatrix}setViewportSize(t,n){this.viewportSize.width=t,this.viewportSize.height=n,this.updateMatrices()}setTopLeft(t,n){this.topLeft[0]=t,this.topLeft[1]=n,this.updateMatrices()}setZoom(t){this.zoom=t,this.updateMatrices()}updateMatrices(){Lt.identity(this.invViewProjectionMatrix),Lt.multiply(Lt.scaling([1,-1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.translation([1,1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.scaling([.5*this.viewportSize.width/this.zoom,.5*this.viewportSize.height/this.zoom,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.translation([this.topLeft[0],this.topLeft[1],0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix)}};var Ei={type:"cobalt:light",refs:[{name:"in",type:"textureView",format:"rgba16float",access:"read"},{name:"out",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return wu(e,t)},onRun:function(e,t,n){xu(e,t,n)},onDestroy:function(e,t){yu(t)},onResize:function(e,t){Mu(e,t)},onViewportPosition:function(e,t){t.data.viewport.setTopLeft(...e.viewport.position)},customFunctions:{...dn}};async function wu(e,t){let{device:n}=e,r=256,i=256,o=new ae(n,r),s=new br({viewportSize:{width:e.viewport.width,height:e.viewport.height},center:e.viewport.position,zoom:e.viewport.zoom}),f=new Mr({device:n,albedo:{view:t.refs.in.data.view,sampler:t.refs.in.data.sampler},targetTexture:t.refs.out.data.texture,lightsBuffer:o,lightsTextureProperties:{resolutionPerLight:i,maxLightSize:i,antialiased:!1,filtering:"nearest",textureFormat:qt(e)}});return{lightsBuffer:o,lightsBufferNeedsUpdate:!0,lightsTextureNeedsUpdate:!0,lightsRenderer:f,viewport:s,lights:[]}}function xu(e,t,n){t.data.lightsBufferNeedsUpdate&&(t.data.lightsBuffer.setLights(t.data.lights),t.data.lightsBufferNeedsUpdate=!1,t.data.lightsTextureNeedsUpdate=!0);let r=t.data.lightsRenderer;t.data.lightsTextureNeedsUpdate&&(r.computeLightsTexture(n),t.data.lightsTextureNeedsUpdate=!1);let i=n.beginRenderPass({label:"light",colorAttachments:[{view:t.refs.out.data.view,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});t.data.viewport.setZoom(e.viewport.zoom);let o=t.data.viewport.invertViewProjectionMatrix;r.render(i,o),i.end()}function yu(e){e.data.lightsBuffer.destroy(),e.data.lightsRenderer.destroy()}function Mu(e,t){t.data.lightsRenderer.setAlbedo({view:t.refs.in.data.view,sampler:t.refs.in.data.sampler}),t.data.viewport.setViewportSize(e.viewport.width,e.viewport.height)}function de(e){return e>=0?Math.round(e):e%.5===0?Math.floor(e):Math.round(e)}var Ri="struct TransformData{view:mat4x4<f32>,projection:mat4x4<f32>};@binding(0)@group(0)var<uniform> transformUBO:TransformData;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)Color:vec4<f32>,};@vertex fn vs_main(@location(0)vertexPosition:vec2<f32>,@location(1)vertexColor:vec4<f32>)->Fragment{var sx:f32=1.0;var sy:f32=1.0;var sz:f32=1.0;var rot:f32=0.0;var tx:f32=1.0;var ty:f32=1.0;var tz:f32=0;var s=sin(rot);var c=cos(rot);var scaleM:mat4x4<f32>=mat4x4<f32>(sx,0.0,0.0,0.0,0.0,sy,0.0,0.0,0.0,0.0,sz,0.0,0,0,0,1.0);var modelM:mat4x4<f32>=mat4x4<f32>(c,s,0.0,0.0,-s,c,0.0,0.0,0.0,0.0,1.0,0.0,tx,ty,tz,1.0)*scaleM;var output:Fragment;output.Position=transformUBO.projection*transformUBO.view*modelM*vec4<f32>(vertexPosition,0.0,1.0);output.Color=vertexColor;return output;}@fragment fn fs_main(@location(0)Color:vec4<f32>)->@location(0)vec4<f32>{return Color;}";var ps=pi(co(),1);var hs=pi(ls(),1);function ti(e,t){if(!Array.isArray(e))throw new Error("poly-to-pslg: Error, invalid polygon");if(e.length===0)return{points:[],edges:[]};t=t||{};var n=!0;"nested"in t?n=!!t.nested:e[0].length===2&&typeof e[0][0]=="number"&&(n=!1),n||(e=[e]);for(var r=[],i=[],o=0;o<e.length;++o)for(var s=e[o],f=r.length,h=0;h<s.length;++h)r.push(s[h]),i.push([f+h,f+(h+1)%s.length]);var p="clean"in t?!0:!!t.clean;return p&&(0,hs.default)(r,i),{points:r,edges:i}}var vs={line:Re,save:function(e,t){t.data.transforms.push(Me.clone(t.data.transforms.at(-1)))},restore:function(e,t){t.data.transforms.length>1&&t.data.transforms.pop()},translate:function(e,t,n){let r=t.data.transforms.at(-1);Me.translate(r,n,r)},rotate:function(e,t,n){let r=t.data.transforms.at(-1);Me.rotate(r,n,r)},scale:function(e,t,n){let r=t.data.transforms.at(-1);Me.scale(r,n,r)},strokePath:function(e,t,n,r,i=1){for(let o of n)Re(e,t,o[0],o[1],r,i)},filledPath:function(e,t,n,r){let i=ti(n),o=(0,ps.default)(i.points,i.edges,{exterior:!1}),s=t.data.transforms.at(-1),f=t.data.vertexCount*6,h=t.data.vertexCount*6,p=o.length*3*6;t.data.vertices=Zr(Float32Array,t.data.vertices,h,p);let g=Et.create();for(let D of o)Et.transformMat3(n[D[0]],s,g),t.data.vertices[f+0]=g[0],t.data.vertices[f+1]=g[1],t.data.vertices[f+2]=r[0],t.data.vertices[f+3]=r[1],t.data.vertices[f+4]=r[2],t.data.vertices[f+5]=r[3],Et.transformMat3(n[D[1]],s,g),t.data.vertices[f+6]=g[0],t.data.vertices[f+7]=g[1],t.data.vertices[f+8]=r[0],t.data.vertices[f+9]=r[1],t.data.vertices[f+10]=r[2],t.data.vertices[f+11]=r[3],Et.transformMat3(n[D[2]],s,g),t.data.vertices[f+12]=g[0],t.data.vertices[f+13]=g[1],t.data.vertices[f+14]=r[0],t.data.vertices[f+15]=r[1],t.data.vertices[f+16]=r[2],t.data.vertices[f+17]=r[3],f+=18;t.data.vertexCount+=3*o.length,t.data.dirty=!0},ellipse:function(e,t,n,r,i,o,s,f=1){let[h,p]=n,g=2*Math.PI/o;for(let D=0;D<o;D++){let X=D*g,N=(D+1)*g,I=h+r*Math.cos(X),V=p+i*Math.sin(X),q=h+r*Math.cos(N),Y=p+i*Math.sin(N);Re(e,t,[I,V],[q,Y],s,f)}},filledEllipse:function(e,t,n,r,i,o,s){let[f,h]=n,p=2*Math.PI/o,g=t.data.vertexCount*6,D=o*3*6;t.data.vertices=Zr(Float32Array,t.data.vertices,g,D);let X=t.data.transforms.at(-1);for(let N=0;N<o;N++){let I=N*p,V=(N+1)*p,q=f+r*Math.cos(I),Y=h+i*Math.sin(I),K=f+r*Math.cos(V),Q=h+i*Math.sin(V),H=t.data.vertexCount*6+N*18,W=Et.transformMat3([f,h],X);t.data.vertices[H+0]=W[0],t.data.vertices[H+1]=W[1],t.data.vertices[H+2]=s[0],t.data.vertices[H+3]=s[1],t.data.vertices[H+4]=s[2],t.data.vertices[H+5]=s[3],Et.transformMat3([q,Y],X,W),t.data.vertices[H+6]=W[0],t.data.vertices[H+7]=W[1],t.data.vertices[H+8]=s[0],t.data.vertices[H+9]=s[1],t.data.vertices[H+10]=s[2],t.data.vertices[H+11]=s[3],Et.transformMat3([K,Q],X,W),t.data.vertices[H+12]=W[0],t.data.vertices[H+13]=W[1],t.data.vertices[H+14]=s[0],t.data.vertices[H+15]=s[1],t.data.vertices[H+16]=s[2],t.data.vertices[H+17]=s[3]}t.data.vertexCount+=3*o,t.data.dirty=!0},box:function(e,t,n,r,i,o,s=1){let[f,h]=n,p=r/2,g=i/2,D=[f-p,h-g],X=[f+p,h-g],N=[f-p,h+g],I=[f+p,h+g];Re(e,t,D,X,o,s),Re(e,t,N,I,o,s),Re(e,t,D,N,o,s),Re(e,t,X,I,o,s)},filledBox:function(e,t,n,r,i,o){let[s,f]=n,h=r/2,p=i/2,g=t.data.transforms.at(-1),D=Et.transformMat3([s-h,f-p],g),X=Et.transformMat3([s+h,f-p],g),N=Et.transformMat3([s-h,f+p],g),I=Et.transformMat3([s+h,f+p],g),V=t.data.vertexCount*6,q=36;t.data.vertices=Zr(Float32Array,t.data.vertices,V,q);let Y=t.data.vertexCount*6;t.data.vertices[Y+0]=D[0],t.data.vertices[Y+1]=D[1],t.data.vertices[Y+2]=o[0],t.data.vertices[Y+3]=o[1],t.data.vertices[Y+4]=o[2],t.data.vertices[Y+5]=o[3],t.data.vertices[Y+6]=N[0],t.data.vertices[Y+7]=N[1],t.data.vertices[Y+8]=o[0],t.data.vertices[Y+9]=o[1],t.data.vertices[Y+10]=o[2],t.data.vertices[Y+11]=o[3],t.data.vertices[Y+12]=X[0],t.data.vertices[Y+13]=X[1],t.data.vertices[Y+14]=o[0],t.data.vertices[Y+15]=o[1],t.data.vertices[Y+16]=o[2],t.data.vertices[Y+17]=o[3],t.data.vertices[Y+18]=N[0],t.data.vertices[Y+19]=N[1],t.data.vertices[Y+20]=o[0],t.data.vertices[Y+21]=o[1],t.data.vertices[Y+22]=o[2],t.data.vertices[Y+23]=o[3],t.data.vertices[Y+24]=I[0],t.data.vertices[Y+25]=I[1],t.data.vertices[Y+26]=o[0],t.data.vertices[Y+27]=o[1],t.data.vertices[Y+28]=o[2],t.data.vertices[Y+29]=o[3],t.data.vertices[Y+30]=X[0],t.data.vertices[Y+31]=X[1],t.data.vertices[Y+32]=o[0],t.data.vertices[Y+33]=o[1],t.data.vertices[Y+34]=o[2],t.data.vertices[Y+35]=o[3],t.data.vertexCount+=6,t.data.dirty=!0},clear:function(e,t){t.data.vertexCount=0,t.data.transforms.length=1,Me.identity(t.data.transforms[0]),t.data.dirty=!0}};function Re(e,t,n,r,i,o=1){let s=t.data.transforms.at(-1);n=Et.transformMat3(n,s),r=Et.transformMat3(r,s);let f=Et.sub(r,n),h=Et.normalize(f),p=Sc(h),g=o/2,D=t.data.vertexCount*6,X=t.data.vertexCount*6,N=36;t.data.vertices=Zr(Float32Array,t.data.vertices,X,N),t.data.vertices[D+0]=n[0]+p[0]*g,t.data.vertices[D+1]=n[1]+p[1]*g,t.data.vertices[D+2]=i[0],t.data.vertices[D+3]=i[1],t.data.vertices[D+4]=i[2],t.data.vertices[D+5]=i[3],t.data.vertices[D+6]=n[0]-p[0]*g,t.data.vertices[D+7]=n[1]-p[1]*g,t.data.vertices[D+8]=i[0],t.data.vertices[D+9]=i[1],t.data.vertices[D+10]=i[2],t.data.vertices[D+11]=i[3],t.data.vertices[D+12]=r[0]+p[0]*g,t.data.vertices[D+13]=r[1]+p[1]*g,t.data.vertices[D+14]=i[0],t.data.vertices[D+15]=i[1],t.data.vertices[D+16]=i[2],t.data.vertices[D+17]=i[3],t.data.vertices[D+18]=n[0]-p[0]*g,t.data.vertices[D+19]=n[1]-p[1]*g,t.data.vertices[D+20]=i[0],t.data.vertices[D+21]=i[1],t.data.vertices[D+22]=i[2],t.data.vertices[D+23]=i[3],t.data.vertices[D+24]=r[0]+p[0]*g,t.data.vertices[D+25]=r[1]+p[1]*g,t.data.vertices[D+26]=i[0],t.data.vertices[D+27]=i[1],t.data.vertices[D+28]=i[2],t.data.vertices[D+29]=i[3],t.data.vertices[D+30]=r[0]-p[0]*g,t.data.vertices[D+31]=r[1]-p[1]*g,t.data.vertices[D+32]=i[0],t.data.vertices[D+33]=i[1],t.data.vertices[D+34]=i[2],t.data.vertices[D+35]=i[3],t.data.vertexCount+=6,t.data.dirty=!0}function Zr(e,t,n,r){if(n+r<=t.length)return t;let i=t.length*2,o=16*1024*1024/t.BYTES_PER_ELEMENT;if(i>o)throw new Error("vertices exceed max array size");let s=new e(i);return s.set(t),s}function Sc(e){return[-e[1],e[0]]}var ds=fe.create(0,0,0),ws={type:"cobalt:primitives",refs:[{name:"color",type:"textView",format:"PREFERRED_TEXTURE_VIEW",access:"write"}],onInit:async function(e,t={}){return _c(e,t)},onRun:function(e,t,n){Bc(e,t,n)},onDestroy:function(e,t){Dc(t)},onResize:function(e,t){gs(e,t)},onViewportPosition:function(e,t){gs(e,t)},customFunctions:vs};async function _c(e,t){let{device:n}=e,r=new Float32Array(1024),i=n.createBuffer({size:r.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),o=n.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=n.createShaderModule({code:Ri}),f=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}}]}),h=n.createPipelineLayout({bindGroupLayouts:[f]}),p=n.createBindGroup({layout:f,entries:[{binding:0,resource:{buffer:o}}]}),g=n.createRenderPipeline({label:"primitives",layout:h,vertex:{module:s,entryPoint:"vs_main",buffers:[{arrayStride:6*Float32Array.BYTES_PER_ELEMENT,attributes:[{shaderLocation:0,offset:0,format:"float32x2"},{shaderLocation:1,format:"float32x4",offset:8}]}]},fragment:{module:s,entryPoint:"fs_main",targets:[{format:qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"}});return{uniformBuffer:o,vertexBuffer:i,pipeline:g,bindGroup:p,vertexCount:0,dirty:!1,vertices:r,transforms:[Me.identity()]}}function Bc(e,t,n){if(t.data.vertexCount===0)return;let{device:r}=e;if(t.data.dirty){t.data.dirty=!1;let s=6*Float32Array.BYTES_PER_ELEMENT;t.data.vertices.buffer.byteLength>t.data.vertexBuffer.size&&(t.data.vertexBuffer.destroy(),t.data.vertexBuffer=r.createBuffer({size:t.data.vertices.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}));let f=t.data.vertexCount*s;if(f>t.data.vertexBuffer.size){console.error("too many primitives, bailing");return}e.device.queue.writeBuffer(t.data.vertexBuffer,0,t.data.vertices.buffer,0,f)}let i=t.options.loadOp||"load",o=n.beginRenderPass({label:"primitives",colorAttachments:[{view:t.refs.color,clearValue:e.clearValue,loadOp:i,storeOp:"store"}]});o.setPipeline(t.data.pipeline),o.setBindGroup(0,t.data.bindGroup),o.setVertexBuffer(0,t.data.vertexBuffer),o.draw(t.data.vertexCount),o.end()}function Dc(e){e.data.vertexBuffer.destroy(),e.data.vertexBuffer=null,e.data.uniformBuffer.destroy(),e.data.uniformBuffer=null,e.data.transforms.length=0}function gs(e,t){let{device:n}=e,r=e.viewport.width/e.viewport.zoom,i=e.viewport.height/e.viewport.zoom,o=Lt.ortho(0,r,i,0,-10,10);fe.set(-e.viewport.position[0]-1,-e.viewport.position[1]-1,0,ds);let s=Lt.translation(ds);n.queue.writeBuffer(t.data.uniformBuffer,0,s.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,o.buffer)}var ei="struct BloomComposite{bloom_intensity:f32,bloom_combine_constant:f32,}@group(0)@binding(0)var mySampler:sampler;@group(0)@binding(1)var colorTexture:texture_2d<f32>;@group(0)@binding(2)var emissiveTexture:texture_2d<f32>;@group(0)@binding(3)var<uniform> composite_parameter:BloomComposite;struct VertexOutput{@builtin(position)Position:vec4<f32>,@location(0)fragUV:vec2<f32>,}const positions=array<vec2<f32>,3>(vec2<f32>(-1.0,-3.0),vec2<f32>(3.0,1.0),vec2<f32>(-1.0,1.0));const uvs=array<vec2<f32>,3>(vec2<f32>(0.0,2.0),vec2<f32>(2.0,0.0),vec2<f32>(0.0,0.0));@vertex fn vert_main(@builtin(vertex_index)VertexIndex:u32)->VertexOutput{var output:VertexOutput;output.Position=vec4<f32>(positions[VertexIndex],0.0,1.0);output.fragUV=vec2<f32>(uvs[VertexIndex]);return output;}fn GTTonemap_point(x:f32)->f32{let m:f32=0.22;let a:f32=1.0;let c:f32=1.33;let P:f32=1.0;let l:f32=0.4;let l0:f32=((P-m)*l)/a;let S0:f32=m+l0;let S1:f32=m+a*l0;let C2:f32=(a*P)/(P-S1);let L:f32=m+a*(x-m);let T:f32=m*pow(x/m,c);let S:f32=P-(P-S1)*exp(-C2*(x-S0)/P);let w0:f32=1.0-smoothstep(0.0,m,x);var w2:f32=1.0;if(x<m+l){w2=0.0;}let w1:f32=1.0-w0-w2;return f32(T*w0+L*w1+S*w2);}fn GTTonemap(x:vec3<f32>)->vec3<f32>{return vec3<f32>(GTTonemap_point(x.r),GTTonemap_point(x.g),GTTonemap_point(x.b));}fn aces(x:vec3<f32>)->vec3<f32>{let a:f32=2.51;let b:f32=0.03;let c:f32=2.43;let d:f32=0.59;let e:f32=0.14;return clamp((x*(a*x+b))/(x*(c*x+d)+e),vec3<f32>(0.0),vec3<f32>(1.0));}@fragment fn frag_main(@location(0)fragUV:vec2<f32>)->@location(0)vec4<f32>{let hdr_color=textureSample(colorTexture,mySampler,fragUV);let bloom_color=textureSample(emissiveTexture,mySampler,fragUV);let combined_color=((bloom_color*composite_parameter.bloom_intensity)*composite_parameter.bloom_combine_constant);let mapped_color=GTTonemap(combined_color.rgb);let gamma_corrected_color=pow(mapped_color,vec3<f32>(1.0/2.2));return vec4<f32>(gamma_corrected_color+hdr_color.rgb,1.0);}";var xs={type:"cobalt:bloom",refs:[{name:"hdr",type:"textureView",format:"rgba16",access:"read"},{name:"bloom",type:"textureView",format:"rgba16",access:"read"},{name:"combined",type:"textureView",format:"PREFERRED_TEXTURE_FORMAT",access:"write"}],onInit:async function(e,t={}){return Uc(e,t)},onRun:function(e,t,n){Fc(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){Gc(e,t)},onViewportPosition:function(e,t){}};function Uc(e,t){let{options:n,refs:r}=t,{device:i}=e,o=qt(e),s=n.bloom_intensity??40,f=n.bloom_combine_constant??.68,h=new Float32Array([s,f]),p=i.createBuffer({label:"scene composite params buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});new Float32Array(p.getMappedRange()).set(h),p.unmap();let g=i.createRenderPipeline({label:"scenecomposite",layout:"auto",vertex:{module:i.createShaderModule({code:ei}),entryPoint:"vert_main"},fragment:{module:i.createShaderModule({code:ei}),entryPoint:"frag_main",targets:[{format:o}]},primitive:{topology:"triangle-list"}});return{bindGroup:i.createBindGroup({layout:g.getBindGroupLayout(0),entries:[{binding:0,resource:r.hdr.data.sampler},{binding:1,resource:r.hdr.data.view},{binding:2,resource:r.bloom.data.mip_view[0]},{binding:3,resource:{buffer:p}}]}),pipeline:g,params_buf:p}}function Fc(e,t,n){let r=n.beginRenderPass({label:"scene-composite",colorAttachments:[{view:t.refs.combined.data.view,clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),{pipeline:i,bindGroup:o}=t.data;r.setPipeline(i),r.setBindGroup(0,o),r.draw(3),r.end()}function Gc(e,t){let{pipeline:n,params_buf:r}=t.data,{device:i}=e;t.data.bindGroup=i.createBindGroup({layout:n.getBindGroupLayout(0),entries:[{binding:0,resource:t.refs.hdr.data.sampler},{binding:1,resource:t.refs.hdr.data.view},{binding:2,resource:t.refs.bloom.data.mip_view[0]},{binding:3,resource:{buffer:r}}]})}var ri={};hn(ri,{addSprite:()=>Ac,clear:()=>Lc,removeSprite:()=>zc,setSpriteName:()=>Ec,setSpriteOpacity:()=>Oc,setSpritePosition:()=>Rc,setSpriteRotation:()=>mc,setSpriteScale:()=>Vc,setSpriteTint:()=>Ic});function Ac(e,t,n,r,i,o,s,f){let{idByName:h}=t.refs.spritesheet.data;return t.data.sprites.push({position:Et.clone(r),sizeX:1,sizeY:1,scale:Et.clone(i),rotation:f,opacity:s,tint:Ce.clone(o),spriteID:h.get(n),id:Be()}),t.data.sprites.at(-1).id}function zc(e,t,n){for(let r=0;r<t.data.sprites.length;r++)if(t.data.sprites[r].id===n){t.data.sprites.splice(r,1);return}}function Lc(e,t){t.data.sprites.length=0}function Ec(e,t,n,r){let i=t.data.sprites.find(s=>s.id===n);if(!i)return;let{idByName:o}=t.refs.spritesheet.data;i.spriteID=o.get(r)}function Rc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.position)}function Ic(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Ce.copy(r,i.tint)}function Oc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.opacity=r)}function mc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.rotation=r)}function Vc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.scale)}var ys="struct ViewParams{view:mat4x4<f32>,proj:mat4x4<f32>};@group(0)@binding(0)var<uniform> uView:ViewParams;@group(0)@binding(1)var uSampler:sampler;@group(0)@binding(2)var uTex:texture_2d<f32>;struct SpriteDesc{uvOrigin:vec2<f32>,uvSpan:vec2<f32>,frameSize:vec2<f32>,centerOffset:vec2<f32>,};@group(0)@binding(3)var<storage,read>Sprites:array<SpriteDesc>;struct VSOut{@builtin(position)pos:vec4<f32>,@location(0)uv:vec2<f32>,@location(1)tint:vec4<f32>,@location(2)opacity:f32,};const corners=array<vec2<f32>,4>(vec2<f32>(-0.5,-0.5),vec2<f32>(0.5,-0.5),vec2<f32>(-0.5,0.5),vec2<f32>(0.5,0.5),);const uvBase=array<vec2<f32>,4>(vec2<f32>(0.0,0.0),vec2<f32>(1.0,0.0),vec2<f32>(0.0,1.0),vec2<f32>(1.0,1.0),);@vertex fn vs_main(@builtin(vertex_index)vid:u32,@location(0)i_pos:vec2<f32>,@location(1)i_size:vec2<f32>,@location(2)i_scale:vec2<f32>,@location(3)i_tint:vec4<f32>,@location(4)i_spriteId:u32,@location(5)i_opacity:f32,@location(6)i_rotation:f32)->VSOut{let rot=i_rotation;let c=cos(rot);let s=sin(rot);let d=Sprites[i_spriteId];let corner=corners[vid];let sizePx=d.frameSize*i_size*i_scale;var local=corner*sizePx;local+=d.centerOffset*i_scale;let rotated=vec2<f32>(local.x*c-local.y*s,local.x*s+local.y*c);let world=vec4<f32>(rotated+i_pos,0.0,1.0);var out:VSOut;out.pos=uView.proj*uView.view*world;out.uv=d.uvOrigin+d.uvSpan*uvBase[vid];out.tint=i_tint;out.opacity=i_opacity;return out;}@fragment fn fs_main(in:VSOut)->@location(0)vec4<f32>{let texel=textureSample(uTex,uSampler,in.uv);return vec4<f32>(texel.rgb*(1.0-in.tint.a)+(in.tint.rgb*in.tint.a),texel.a*in.opacity);}";var ni=fe.create(0,0,0),Ie=64,ii=0,oi=8,ai=16,fr=24,bs=40,Ts=44,Ps=48,Ss={type:"cobalt:sprite",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"color",type:"textureView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return qc(e,t)},onRun:function(e,t,n){Cc(e,t,n)},onDestroy:function(e,t){try{t.data.instanceBuf?.destroy()}catch{}try{t.data.spriteBuf?.destroy()}catch{}try{t.data.uniformBuffer?.destroy()}catch{}t.data.pipeline=null,t.data.bindGroup=null,t.data.bindGroupLayout=null,t.data.instanceStaging=null,t.data.instanceView=null,t.data.sprites.length=0,t.data.visible.length=0},onResize:function(e,t){Ms(e,t)},onViewportPosition:function(e,t){Ms(e,t)},customFunctions:{...ri}};async function qc(e,t){let{device:n}=e,{descs:r,names:i}=t.refs.spritesheet.data.spritesheet,o=n.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=32,f=new ArrayBuffer(s*r.length),h=new Float32Array(f);for(let tt=0;tt<r.length;tt++){let H=r[tt],W=tt*8;h[W+0]=H.UvOrigin[0],h[W+1]=H.UvOrigin[1],h[W+2]=H.UvSpan[0],h[W+3]=H.UvSpan[1],h[W+4]=H.FrameSize[0],h[W+5]=H.FrameSize[1],h[W+6]=H.CenterOffset[0],h[W+7]=H.CenterOffset[1]}let p=n.createBuffer({label:"sprite desc table",size:Math.max(16,f.byteLength),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});n.queue.writeBuffer(p,0,f);let g=1024,D=n.createBuffer({label:"sprite instances",size:Ie*g,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),X=new ArrayBuffer(Ie*g),N=new DataView(X),I=n.createShaderModule({code:ys}),V=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float"}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}]}),q=n.createPipelineLayout({bindGroupLayouts:[V]}),Y={arrayStride:Ie,stepMode:"instance",attributes:[{shaderLocation:0,offset:ii,format:"float32x2"},{shaderLocation:1,offset:oi,format:"float32x2"},{shaderLocation:2,offset:ai,format:"float32x2"},{shaderLocation:3,offset:fr,format:"float32x4"},{shaderLocation:4,offset:bs,format:"uint32"},{shaderLocation:5,offset:Ts,format:"float32"},{shaderLocation:6,offset:Ps,format:"float32"}]},K=n.createRenderPipeline({layout:q,vertex:{module:I,entryPoint:"vs_main",buffers:[Y]},fragment:{module:I,entryPoint:"fs_main",targets:[{format:qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-strip",cullMode:"none"},multisample:{count:1}}),Q=n.createBindGroup({layout:V,entries:[{binding:0,resource:{buffer:o}},{binding:1,resource:t.refs.spritesheet.data.colorTexture.sampler},{binding:2,resource:t.refs.spritesheet.data.colorTexture.view},{binding:3,resource:{buffer:p}}]});return{sprites:[],visible:[],visibleCount:0,viewRect:{x:0,y:0,w:0,h:0},spriteBuf:p,uniformBuffer:o,instanceCap:g,instanceView:N,instanceBuf:D,instanceStaging:X,pipeline:K,bindGroup:Q}}function Nc(e,t,n){let{instanceCap:r}=t.data;if(n<=r)return;let i=r;for(i===0&&(i=1024);i<n;)i*=2;t.data.instanceBuf.destroy(),t.data.instanceBuf=e.device.createBuffer({size:Ie*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),t.data.instanceStaging=new ArrayBuffer(Ie*i),t.data.instanceView=new DataView(t.data.instanceStaging),t.data.instanceCap=i}function Cc(e,t,n){let{device:r,context:i}=e,{instanceView:o,instanceBuf:s,instanceStaging:f,pipeline:h,bindGroup:p}=t.data,{descs:g}=t.refs.spritesheet.data.spritesheet,D=t.data.viewRect;D.x=e.viewport.position[0],D.y=e.viewport.position[1],D.w=e.viewport.width,D.h=e.viewport.height,t.data.visibleCount=0;for(let I of t.data.sprites){let V=g[I.spriteID];if(V){if(!t.options.isScreenSpace){let q=V.FrameSize[0]*I.sizeX*I.scale[0]*.5,Y=V.FrameSize[1]*I.sizeY*I.scale[1]*.5,K=Math.hypot(q,Y),Q=I.position[0],tt=I.position[1];if(Q+K<D.x||Q-K>D.x+D.w||tt+K<D.y||tt-K>D.y+D.h)continue}t.data.visible[t.data.visibleCount]=I,t.data.visibleCount++}}Nc(e,t,t.data.visibleCount);for(let I=0;I<t.data.visibleCount;I++){let V=I*Ie,q=t.data.visible[I],Y=q.tint;o.setFloat32(V+ii+0,q.position[0],!0),o.setFloat32(V+ii+4,q.position[1],!0),o.setFloat32(V+oi+0,q.sizeX,!0),o.setFloat32(V+oi+4,q.sizeY,!0),o.setFloat32(V+ai+0,q.scale[0],!0),o.setFloat32(V+ai+4,q.scale[1],!0),o.setFloat32(V+fr+0,Y[0],!0),o.setFloat32(V+fr+4,Y[1],!0),o.setFloat32(V+fr+8,Y[2],!0),o.setFloat32(V+fr+12,Y[3],!0),o.setUint32(V+bs,q.spriteID>>>0,!0),o.setFloat32(V+Ts,q.opacity,!0),o.setFloat32(V+Ps,q.rotation,!0)}r.queue.writeBuffer(s,0,f,0,t.data.visibleCount*Ie);let X=t.options.loadOp||"load",N=n.beginRenderPass({label:"sprite renderpass",colorAttachments:[{view:t.refs.color,clearValue:e.clearValue,loadOp:X,storeOp:"store"}]});N.setPipeline(h),N.setBindGroup(0,p),N.setVertexBuffer(0,s),t.data.visibleCount&&N.draw(4,t.data.visibleCount,0,0),N.end()}function Ms(e,t){let{device:n,viewport:r}=e,i=r.width/r.zoom,o=r.height/r.zoom,s=Lt.ortho(0,i,o,0,-10,10);t.options.isScreenSpace?fe.set(0,0,0,ni):fe.set(-de(r.position[0]),-de(r.position[1]),0,ni);let f=Lt.translation(ni);n.queue.writeBuffer(t.data.uniformBuffer,0,f.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,s.buffer)}var si={};hn(si,{addSprite:()=>Xc,clear:()=>Yc,removeSprite:()=>kc,setSpriteName:()=>Hc,setSpriteOpacity:()=>Wc,setSpritePosition:()=>Zc,setSpriteRotation:()=>Kc,setSpriteScale:()=>Qc,setSpriteTint:()=>$c});function Xc(e,t,n,r,i,o,s,f){let{idByName:h}=t.refs.spritesheet.data;return t.data.sprites.push({position:Et.clone(r),sizeX:1,sizeY:1,scale:Et.clone(i),rotation:f,opacity:s,tint:Ce.clone(o),spriteID:h.get(n),id:Be()}),t.data.sprites.at(-1).id}function kc(e,t,n){for(let r=0;r<t.data.sprites.length;r++)if(t.data.sprites[r].id===n){t.data.sprites.splice(r,1);return}}function Yc(e,t){t.data.sprites.length=0}function Hc(e,t,n,r){let i=t.data.sprites.find(s=>s.id===n);if(!i)return;let{idByName:o}=t.refs.spritesheet.data;i.spriteID=o.get(r)}function Zc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.position)}function $c(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Ce.copy(r,i.tint)}function Wc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.opacity=r)}function Kc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&(i.rotation=r)}function Qc(e,t,n,r){let i=t.data.sprites.find(o=>o.id===n);i&&Et.copy(r,i.scale)}var _s="struct ViewParams{view:mat4x4<f32>,proj:mat4x4<f32>};@group(0)@binding(0)var<uniform> uView:ViewParams;@group(0)@binding(1)var uSampler:sampler;@group(0)@binding(2)var uTex:texture_2d<f32>;struct SpriteDesc{uvOrigin:vec2<f32>,uvSpan:vec2<f32>,frameSize:vec2<f32>,centerOffset:vec2<f32>,};@group(0)@binding(3)var<storage,read>Sprites:array<SpriteDesc>;@group(0)@binding(4)var emissiveTexture:texture_2d<f32>;struct VSOut{@builtin(position)pos:vec4<f32>,@location(0)uv:vec2<f32>,@location(1)tint:vec4<f32>,@location(2)opacity:f32,};const corners=array<vec2<f32>,4>(vec2<f32>(-0.5,-0.5),vec2<f32>(0.5,-0.5),vec2<f32>(-0.5,0.5),vec2<f32>(0.5,0.5),);const uvBase=array<vec2<f32>,4>(vec2<f32>(0.0,0.0),vec2<f32>(1.0,0.0),vec2<f32>(0.0,1.0),vec2<f32>(1.0,1.0),);struct GBufferOutput{@location(0)color:vec4<f32>,@location(1)emissive:vec4<f32>,}@vertex fn vs_main(@builtin(vertex_index)vid:u32,@location(0)i_pos:vec2<f32>,@location(1)i_size:vec2<f32>,@location(2)i_scale:vec2<f32>,@location(3)i_tint:vec4<f32>,@location(4)i_spriteId:u32,@location(5)i_opacity:f32,@location(6)i_rotation:f32)->VSOut{let rot=i_rotation;let c=cos(rot);let s=sin(rot);let d=Sprites[i_spriteId];let corner=corners[vid];let sizePx=d.frameSize*i_size*i_scale;var local=corner*sizePx;local+=d.centerOffset*i_scale;let rotated=vec2<f32>(local.x*c-local.y*s,local.x*s+local.y*c);let world=vec4<f32>(rotated+i_pos,0.0,1.0);var out:VSOut;out.pos=uView.proj*uView.view*world;out.uv=d.uvOrigin+d.uvSpan*uvBase[vid];out.tint=i_tint;out.opacity=i_opacity;return out;}@fragment fn fs_main(in:VSOut)->GBufferOutput{var output:GBufferOutput;let texel=textureSample(uTex,uSampler,in.uv);output.color=vec4<f32>(texel.rgb*(1.0-in.tint.a)+(in.tint.rgb*in.tint.a),texel.a*in.opacity);let emissive=textureSample(emissiveTexture,uSampler,in.uv);output.emissive=vec4(emissive.rgb,1.0)*emissive.a;return output;}";var ui=fe.create(0,0,0),Oe=64,fi=0,ci=8,li=16,cr=24,Ds=40,Us=44,Fs=48,Gs={type:"cobalt:spriteHDR",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"color",type:"textureView",format:"rgba16float",access:"write"},{name:"emissive",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return Jc(e,t)},onRun:function(e,t,n){tl(e,t,n)},onDestroy:function(e,t){try{t.data.instanceBuf?.destroy()}catch{}try{t.data.spriteBuf?.destroy()}catch{}try{t.data.uniformBuffer?.destroy()}catch{}t.data.pipeline=null,t.data.bindGroup=null,t.data.bindGroupLayout=null,t.data.instanceStaging=null,t.data.instanceView=null,t.data.sprites.length=0,t.data.visible.length=0},onResize:function(e,t){Bs(e,t)},onViewportPosition:function(e,t){Bs(e,t)},customFunctions:{...si}};async function Jc(e,t){let{device:n}=e,{descs:r,names:i}=t.refs.spritesheet.data.spritesheet,o=n.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=32,f=new ArrayBuffer(s*r.length),h=new Float32Array(f);for(let H=0;H<r.length;H++){let W=r[H],st=H*8;h[st+0]=W.UvOrigin[0],h[st+1]=W.UvOrigin[1],h[st+2]=W.UvSpan[0],h[st+3]=W.UvSpan[1],h[st+4]=W.FrameSize[0],h[st+5]=W.FrameSize[1],h[st+6]=W.CenterOffset[0],h[st+7]=W.CenterOffset[1]}let p=n.createBuffer({label:"spriteHDR desc table",size:Math.max(16,f.byteLength),usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST});n.queue.writeBuffer(p,0,f);let g=1024,D=n.createBuffer({label:"spriteHDR instances",size:Oe*g,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),X=new ArrayBuffer(Oe*g),N=new DataView(X),I=n.createShaderModule({code:_s}),V=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{type:"uniform"}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{type:"filtering"}},{binding:2,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float"}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}},{binding:4,visibility:GPUShaderStage.FRAGMENT,texture:{sampleType:"float"}}]}),q=n.createPipelineLayout({bindGroupLayouts:[V]}),Y={arrayStride:Oe,stepMode:"instance",attributes:[{shaderLocation:0,offset:fi,format:"float32x2"},{shaderLocation:1,offset:ci,format:"float32x2"},{shaderLocation:2,offset:li,format:"float32x2"},{shaderLocation:3,offset:cr,format:"float32x4"},{shaderLocation:4,offset:Ds,format:"uint32"},{shaderLocation:5,offset:Us,format:"float32"},{shaderLocation:6,offset:Fs,format:"float32"}]},K=n.createRenderPipeline({layout:q,vertex:{module:I,entryPoint:"vs_main",buffers:[Y]},fragment:{module:I,entryPoint:"fs_main",targets:[{format:"rgba16float",blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}},{format:"rgba16float"}]},primitive:{topology:"triangle-strip",cullMode:"none"},multisample:{count:1}}),Q=V,tt=n.createBindGroup({layout:V,entries:[{binding:0,resource:{buffer:o}},{binding:1,resource:t.refs.spritesheet.data.colorTexture.sampler},{binding:2,resource:t.refs.spritesheet.data.colorTexture.view},{binding:3,resource:{buffer:p}},{binding:4,resource:t.refs.spritesheet.data.emissiveTexture.view}]});return{sprites:[],visible:[],visibleCount:0,viewRect:{x:0,y:0,w:0,h:0},spriteBuf:p,uniformBuffer:o,instanceCap:g,instanceView:N,instanceBuf:D,instanceStaging:X,pipeline:K,bindGroup:tt}}function jc(e,t,n){let{instanceCap:r}=t.data;if(n<=r)return;let i=r;for(i===0&&(i=1024);i<n;)i*=2;t.data.instanceBuf.destroy(),t.data.instanceBuf=e.device.createBuffer({size:Oe*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),t.data.instanceStaging=new ArrayBuffer(Oe*i),t.data.instanceView=new DataView(t.data.instanceStaging),t.data.instanceCap=i}function tl(e,t,n){let{device:r,context:i}=e,{instanceView:o,instanceBuf:s,instanceStaging:f,pipeline:h,bindGroup:p}=t.data,{descs:g}=t.refs.spritesheet.data.spritesheet,D=t.data.viewRect;D.x=e.viewport.position[0],D.y=e.viewport.position[1],D.w=e.viewport.width,D.h=e.viewport.height,t.data.visibleCount=0;for(let I of t.data.sprites){let V=g[I.spriteID];if(V){if(!t.options.isScreenSpace){let q=V.FrameSize[0]*I.sizeX*I.scale[0]*.5,Y=V.FrameSize[1]*I.sizeY*I.scale[1]*.5,K=Math.hypot(q,Y),Q=I.position[0],tt=I.position[1];if(Q+K<D.x||Q-K>D.x+D.w||tt+K<D.y||tt-K>D.y+D.h)continue}t.data.visible[t.data.visibleCount]=I,t.data.visibleCount++}}jc(e,t,t.data.visibleCount);for(let I=0;I<t.data.visibleCount;I++){let V=I*Oe,q=t.data.visible[I],Y=q.tint;o.setFloat32(V+fi+0,q.position[0],!0),o.setFloat32(V+fi+4,q.position[1],!0),o.setFloat32(V+ci+0,q.sizeX,!0),o.setFloat32(V+ci+4,q.sizeY,!0),o.setFloat32(V+li+0,q.scale[0],!0),o.setFloat32(V+li+4,q.scale[1],!0),o.setFloat32(V+cr+0,Y[0],!0),o.setFloat32(V+cr+4,Y[1],!0),o.setFloat32(V+cr+8,Y[2],!0),o.setFloat32(V+cr+12,Y[3],!0),o.setUint32(V+Ds,q.spriteID>>>0,!0),o.setFloat32(V+Us,q.opacity,!0),o.setFloat32(V+Fs,q.rotation,!0)}r.queue.writeBuffer(s,0,f,0,t.data.visibleCount*Oe);let X=t.options.loadOp||"load",N=n.beginRenderPass({label:"spriteHDR renderpass",colorAttachments:[{view:t.refs.color.data.view,clearValue:e.clearValue,loadOp:X,storeOp:"store"},{view:t.refs.emissive.data.view,clearValue:e.clearValue,loadOp:"clear",storeOp:"store"}]});N.setPipeline(h),N.setBindGroup(0,p),N.setVertexBuffer(0,s),t.data.visibleCount&&N.draw(4,t.data.visibleCount,0,0),N.end()}function Bs(e,t){let{device:n,viewport:r}=e,i=r.width/r.zoom,o=r.height/r.zoom,s=Lt.ortho(0,i,o,0,-10,10);t.options.isScreenSpace?fe.set(0,0,0,ui):fe.set(-de(r.position[0]),-de(r.position[1]),0,ui);let f=Lt.translation(ui);n.queue.writeBuffer(t.data.uniformBuffer,0,f.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,s.buffer)}function $r(e){let t=e.meta.size.w,n=e.meta.size.h,r=Object.keys(e.frames).sort(),i=new Array(r.length);for(let o=0;o<r.length;o++){let s=e.frames[r[o]],f=s.frame.x,h=s.frame.y,p=s.frame.w,g=s.frame.h,D=f/t,X=h/n,N=p/t,I=g/n,V=s.sourceSize.w,q=s.sourceSize.h,Y=s.spriteSourceSize.x,K=s.spriteSourceSize.y,Q=Y+p*.5-V*.5,tt=K+g*.5-q*.5;i[o]={UvOrigin:[D,X],UvSpan:[N,I],FrameSize:[p,g],CenterOffset:[Q,tt]}}return{descs:i,names:r}}var As={type:"cobalt:spritesheet",refs:[],onInit:async function(e,t={}){return el(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){rl(t)},onResize:function(e,t){},onViewportPosition:function(e,t){}};async function el(e,t){let{canvas:n,device:r}=e,i,o,s,f=t.options.format||"rgba8unorm";n?(i=await fetch(t.options.spriteSheetJsonUrl),i=await i.json(),i=$r(i),o=await ve(e,"sprite",t.options.colorTextureUrl,f),s=await ve(e,"emissive sprite",t.options.emissiveTextureUrl,f),n.style.imageRendering="pixelated"):(i=$r(t.options.spriteSheetJson),o=await pe(e,"sprite",t.options.colorTexture,f),s=await pe(e,"emissive sprite",t.options.emissiveTexture,f));let h=new Map(i.names.map((p,g)=>[p,g]));return{colorTexture:o,emissiveTexture:s,spritesheet:i,idByName:h}}function rl(e){e.data.colorTexture.buffer.destroy(),e.data.emissiveTexture.texture.destroy()}var hi="struct TransformData{viewOffset:vec2<f32>,viewportSize:vec2<f32>,inverseAtlasTextureSize:vec2<f32>,tileSize:f32,inverseTileSize:f32,};struct TileScroll{scrollScale:vec2<f32>};const positions=array<vec2<f32>,3>(vec2<f32>(-1.0,-3.0),vec2<f32>(3.0,1.0),vec2<f32>(-1.0,1.0));const uvs=array<vec2<f32>,3>(vec2<f32>(0.0,2.0),vec2<f32>(2.0,0.0),vec2<f32>(0.0,0.0));@binding(0)@group(0)var<uniform> myScroll:TileScroll;@binding(1)@group(0)var tileTexture:texture_2d<f32>;@binding(2)@group(0)var tileSampler:sampler;@binding(0)@group(1)var<uniform> transformUBO:TransformData;@binding(1)@group(1)var atlasTexture:texture_2d<f32>;@binding(2)@group(1)var atlasSampler:sampler;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>};@vertex fn vs_main(@builtin(instance_index)i_id:u32,@builtin(vertex_index)VertexIndex:u32)->Fragment{var vertexPosition=vec2<f32>(positions[VertexIndex]);var vertexTexCoord=vec2<f32>(uvs[VertexIndex]);var output:Fragment;let inverseTileTextureSize=1/vec2<f32>(textureDimensions(tileTexture,0));var scrollScale=myScroll.scrollScale;var viewOffset:vec2<f32>=transformUBO.viewOffset*scrollScale;let PixelCoord=(vertexTexCoord*transformUBO.viewportSize)+viewOffset;output.TexCoord=PixelCoord/transformUBO.tileSize;output.Position=vec4<f32>(vertexPosition,0.0,1.0);return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>)->@location(0)vec4<f32>{var tilemapCoord=floor(TexCoord);var u_tilemapSize=vec2<f32>(textureDimensions(tileTexture,0));var tileFoo=fract((tilemapCoord+vec2<f32>(0.5,0.5))/u_tilemapSize);var tile=floor(textureSample(tileTexture,tileSampler,tileFoo)*255.0);if(tile.x==255&&tile.y==255){discard;}var u_tilesetSize=vec2<f32>(textureDimensions(atlasTexture,0))/transformUBO.tileSize;let u_tileUVMinBounds=vec2<f32>(0.5/transformUBO.tileSize,0.5/transformUBO.tileSize);let u_tileUVMaxBounds=vec2<f32>((transformUBO.tileSize-0.5)/transformUBO.tileSize,(transformUBO.tileSize-0.5)/transformUBO.tileSize);var texcoord=clamp(fract(TexCoord),u_tileUVMinBounds,u_tileUVMaxBounds);var tileCoord=(tile.xy+texcoord)/u_tilesetSize;var color=textureSample(atlasTexture,atlasSampler,tileCoord);if(color.a<=0.1){discard;}return color;}";var ye=new Float32Array(8),Ls={type:"cobalt:tileAtlas",refs:[],onInit:async function(e,t={}){return nl(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){il(t)},onResize:function(e,t){zs(e,t)},onViewportPosition:function(e,t){zs(e,t)}};async function nl(e,t){let{canvas:n,device:r}=e,i=t.options.format||"rgba8unorm",o;n?o=await ve(e,"tile atlas",t.options.textureUrl,i):o=await pe(e,"tile atlas",t.options.texture,i);let s=r.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),f=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),h=r.createBindGroup({layout:f,entries:[{binding:0,resource:{buffer:s}},{binding:1,resource:o.view},{binding:2,resource:o.sampler}]}),p=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),g=r.createPipelineLayout({bindGroupLayouts:[p,f]});return{pipeline:r.createRenderPipeline({label:"tileatlas",vertex:{module:r.createShaderModule({code:hi}),entryPoint:"vs_main",buffers:[]},fragment:{module:r.createShaderModule({code:hi}),entryPoint:"fs_main",targets:[{format:t.options.outputFormat||qt(e),blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:g}),uniformBuffer:s,atlasBindGroup:h,atlasMaterial:o,tileBindGroupLayout:p,tileSize:t.options.tileSize,tileScale:t.options.tileScale}}function il(e){e.data.atlasMaterial.texture.destroy(),e.data.atlasMaterial.texture=void 0}function zs(e,t){ye[0]=de(e.viewport.position[0]),ye[1]=de(e.viewport.position[1]);let n=t.data,{tileScale:r,tileSize:i}=n,o=e.viewport.width/e.viewport.zoom,s=e.viewport.height/e.viewport.zoom;ye[2]=o/r,ye[3]=s/r,ye[4]=1/n.atlasMaterial.texture.width,ye[5]=1/n.atlasMaterial.texture.height,ye[6]=i,ye[7]=1/i,e.device.queue.writeBuffer(n.uniformBuffer,0,ye,0,8)}var Rs={type:"cobalt:tileHDR",refs:[{name:"tileAtlas",type:"textureView",format:"rgba8unorm",access:"read"},{name:"hdr",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return ol(e,t)},onRun:function(e,t,n){al(e,t,n)},onDestroy:function(e,t){Es(t)},onResize:function(e,t){},onViewportPosition:function(e,t){},customFunctions:{setTexture:async function(e,t,n){let{canvas:r,device:i}=e;Es(t);let o=t.options.format||qt(e),s;r?(t.options.textureUrl=n,s=await ve(e,"tile map",n,o)):s=await pe(e,"tile map",n,o);let f=i.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:t.data.uniformBuffer}},{binding:1,resource:s.view},{binding:2,resource:s.sampler}]});t.data.bindGroup=f,t.data.material=s}}};async function ol(e,t){let{canvas:n,device:r}=e,i,o=t.options.format||qt(e);n?i=await ve(e,"tile map",t.options.textureUrl,o):i=await pe(e,"tile map",t.options.texture,o);let s=new Float32Array([t.options.scrollScale,t.options.scrollScale]),f=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,h={size:s.byteLength,usage:f,mappedAtCreation:!0},p=r.createBuffer(h);return new Float32Array(p.getMappedRange()).set(s),p.unmap(),{bindGroup:r.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:p}},{binding:1,resource:i.view},{binding:2,resource:i.sampler}]}),material:i,uniformBuffer:p,scrollScale:t.options.scrollScale}}function al(e,t,n){if(!t.data.material.texture)return;let{device:r}=e,i=t.options.loadOp||"load",o=n.beginRenderPass({label:"tile",colorAttachments:[{view:t.refs.hdr.data?.view||t.refs.hdr,clearValue:e.clearValue,loadOp:i,storeOp:"store"}]}),s=t.refs.tileAtlas.data;o.setPipeline(s.pipeline),o.setBindGroup(0,t.data.bindGroup),o.setBindGroup(1,s.atlasBindGroup),o.draw(3),o.end()}function Es(e){e.data.material.texture.destroy(),e.data.material.texture=void 0}async function Ap(e,t,n){let r,i,o,s;return e.sdlWindow&&e.gpu?(i=e.gpu,r=await(await i.create(["verbose=1","enable-dawn-features=allow_unsafe_apis"]).requestAdapter()).requestDevice({requiredFeatures:["texture-component-swizzle"]}),o=i.renderGPUDeviceToWindow({device:r,window:e.sdlWindow}),global.GPUBufferUsage=i.GPUBufferUsage,global.GPUShaderStage=i.GPUShaderStage,global.GPUTextureUsage=i.GPUTextureUsage):(s=e,r=await(await navigator.gpu?.requestAdapter({powerPreference:"high-performance"}))?.requestDevice(),i=navigator.gpu,o=s.getContext("webgpu"),o.configure({device:r,format:navigator.gpu?.getPreferredCanvasFormat(),alphaMode:"opaque"})),{nodeDefs:{"cobalt:tileAtlas":Ls,"cobalt:spritesheet":As,"cobalt:fbTexture":zi,"cobalt:sprite":Ss,"cobalt:bloom":wi,"cobalt:composite":xs,"cobalt:spriteHDR":Gs,"cobalt:tileHDR":Rs,"cobalt:displacement":Gi,"cobalt:fbBlit":Ai,"cobalt:primitives":ws,"cobalt:light":Ei},nodes:[],defaultTextureViewRefs:[],canvas:s,device:r,context:o,gpu:i,clearValue:{r:0,g:0,b:0,a:1},viewport:{width:t,height:n,zoom:1,position:[0,0]}}}function zp(e,t){if(!t?.type)throw new Error("Can't define a new node missing a type.");e.nodeDefs[t.type]=t}async function Lp(e,t){let n=e.nodeDefs[t?.type];if(!n)throw new Error("Can't initialize a new node missing a type.");let r={type:t.type,refs:t.refs||{},options:t.options||{},data:{},enabled:!0};for(let o in r.refs)r.refs[o]==="FRAME_TEXTURE_VIEW"&&(e.defaultTextureViewRefs.push({node:r,refName:o}),r.refs[o]=Is(e));r.data=await n.onInit(e,r);let i=n.customFunctions||{};for(let o in i)r[o]=function(...s){return i[o](e,r,...s)};return e.nodes.push(r),r}function Ep(e){let{device:t,context:n}=e,r=t.createCommandEncoder(),i=Is(e);for(let o of e.defaultTextureViewRefs)o.node.refs[o.refName]=i;for(let o of e.nodes){if(!o.enabled)continue;e.nodeDefs[o.type].onRun(e,o,r)}t.queue.submit([r.finish()]),e.canvas||e.context.swap()}function Rp(e){for(let t of e.nodes)e.nodeDefs[t.type].onDestroy(e,t);e.nodes.length=0,e.defaultTextureViewRefs.length=0}function Ip(e,t,n){e.viewport.width=t,e.viewport.height=n;for(let r of e.nodes)e.nodeDefs[r.type].onResize(e,r)}function Op(e,t){e.viewport.position[0]=t[0]-e.viewport.width/2/e.viewport.zoom,e.viewport.position[1]=t[1]-e.viewport.height/2/e.viewport.zoom;for(let n of e.nodes)e.nodeDefs[n.type].onViewportPosition(e,n)}function Is(e){return e.canvas?e.context.getCurrentTexture().createView():e.context.getCurrentTextureView()}export{ne as createTexture,pe as createTextureFromBuffer,ve as createTextureFromUrl,zp as defineNode,Ep as draw,Is as getCurrentTextureView,Ap as init,Lp as initNode,Rp as reset,Ip as setViewportDimensions,Op as setViewportPosition};
|
package/package.json
CHANGED