@footgun/cobalt 0.5.0 → 0.5.1

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 CHANGED
@@ -1,3 +1,6 @@
1
+ # 0.5.1
2
+ * add labels to all render pipelines
3
+
1
4
  # 0.5.0
2
5
  * resize the primitives vertexBuffer to use memory more conservatively
3
6
 
package/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- var Ss=Object.create;var an=Object.defineProperty;var Bs=Object.getOwnPropertyDescriptor;var Ps=Object.getOwnPropertyNames;var Ds=Object.getPrototypeOf,Us=Object.prototype.hasOwnProperty;var xt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ri=(e,t)=>{for(var n in t)an(e,n,{get:t[n],enumerable:!0})},Gs=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ps(t))!Us.call(e,i)&&i!==n&&an(e,i,{get:()=>t[i],enumerable:!(r=Bs(t,i))||r.enumerable});return e};var ni=(e,t,n)=>(n=e!=null?Ss(Ds(e)):{},Gs(t||!e||!e.__esModule?an(n,"default",{value:e,enumerable:!0}):n,e));var Qe=xt((a1,Ei)=>{"use strict";function _u(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h>=0?(o=s,i=s-1):r=s+1}return o}function Su(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h>0?(o=s,i=s-1):r=s+1}return o}function Bu(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h<0?(o=s,r=s+1):i=s-1}return o}function Pu(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h<=0?(o=s,r=s+1):i=s-1}return o}function Du(e,t,n,r,i){for(;r<=i;){var o=r+i>>>1,s=e[o],c=n!==void 0?n(s,t):s-t;if(c===0)return o;c<=0?r=o+1:i=o-1}return-1}function We(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)}Ei.exports={ge:function(e,t,n,r,i){return We(e,t,n,r,i,_u)},gt:function(e,t,n,r,i){return We(e,t,n,r,i,Su)},lt:function(e,t,n,r,i){return We(e,t,n,r,i,Bu)},le:function(e,t,n,r,i){return We(e,t,n,r,i,Pu)},eq:function(e,t,n,r,i){return We(e,t,n,r,i,Du)}}});var hr=xt((s1,zi)=>{"use strict";zi.exports=Uu;var Li=+(Math.pow(2,27)+1);function Uu(e,t,n){var r=e*t,i=Li*e,o=i-e,s=i-o,c=e-s,h=Li*t,p=h-t,g=h-p,F=t-g,N=r-s*g,q=N-c*g,m=q-s*F,C=c*F-m;return n?(n[0]=C,n[1]=r,n):[C,r]}});var vn=xt((u1,Ri)=>{"use strict";Ri.exports=Fu;function Gu(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,c=s+o;return c?[c,n]:[n]}function Fu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return Gu(e[0],t[0]);var i=n+r,o=new Array(i),s=0,c=0,h=0,p=Math.abs,g=e[c],F=p(g),N=t[h],q=p(N),m,C;F<q?(C=g,c+=1,c<n&&(g=e[c],F=p(g))):(C=N,h+=1,h<r&&(N=t[h],q=p(N))),c<n&&F<q||h>=r?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=t[h],q=p(N)));for(var Y=m+C,H=Y-m,W=C-H,Q=W,et=Y,$,J,ut,tt,rt;c<n&&h<r;)F<q?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=t[h],q=p(N))),C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$;for(;c<n;)m=g,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,c+=1,c<n&&(g=e[c]);for(;h<r;)m=N,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,h+=1,h<r&&(N=t[h]);return Q&&(o[s++]=Q),et&&(o[s++]=et),s||(o[s++]=0),o.length=s,o}});var Oi=xt((c1,mi)=>{"use strict";mi.exports=Au;function Au(e,t,n){var r=e+t,i=r-e,o=r-i,s=t-i,c=e-o;return n?(n[0]=c+s,n[1]=r,n):[c+s,r]}});var gn=xt((f1,Vi)=>{"use strict";var dn=hr(),Iu=Oi();Vi.exports=Eu;function Eu(e,t){var n=e.length;if(n===1){var r=dn(e[0],t);return r[0]?r:[r[1]]}var i=new Array(2*n),o=[.1,.1],s=[.1,.1],c=0;dn(e[0],t,o),o[0]&&(i[c++]=o[0]);for(var h=1;h<n;++h){dn(e[h],t,s);var p=o[1];Iu(p,s[0],o),o[0]&&(i[c++]=o[0]);var g=s[1],F=o[1],N=g+F,q=N-g,m=F-q;o[1]=N,m&&(i[c++]=m)}return o[1]&&(i[c++]=o[1]),c===0&&(i[c++]=0),i.length=c,i}});var wn=xt((l1,qi)=>{"use strict";qi.exports=zu;function Lu(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,c=s+o;return c?[c,n]:[n]}function zu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return Lu(e[0],-t[0]);var i=n+r,o=new Array(i),s=0,c=0,h=0,p=Math.abs,g=e[c],F=p(g),N=-t[h],q=p(N),m,C;F<q?(C=g,c+=1,c<n&&(g=e[c],F=p(g))):(C=N,h+=1,h<r&&(N=-t[h],q=p(N))),c<n&&F<q||h>=r?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=-t[h],q=p(N)));for(var Y=m+C,H=Y-m,W=C-H,Q=W,et=Y,$,J,ut,tt,rt;c<n&&h<r;)F<q?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=-t[h],q=p(N))),C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$;for(;c<n;)m=g,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,c+=1,c<n&&(g=e[c]);for(;h<r;)m=N,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,h+=1,h<r&&(N=-t[h]);return Q&&(o[s++]=Q),et&&(o[s++]=et),s||(o[s++]=0),o.length=s,o}});var yn=xt((h1,xn)=>{"use strict";var Ru=hr(),mu=vn(),Ou=gn(),Vu=wn(),Ni=5,pr=11102230246251565e-32,qu=(3+16*pr)*pr,Nu=(7+56*pr)*pr;function Cu(e,t,n,r){return function(o,s,c){var h=e(e(t(s[1],c[0]),t(-c[1],s[0])),e(t(o[1],s[0]),t(-s[1],o[0]))),p=e(t(o[1],c[0]),t(-c[1],o[0])),g=r(h,p);return g[g.length-1]}}function ku(e,t,n,r){return function(o,s,c,h){var p=e(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[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(c[1],h[0]),t(-h[1],c[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[1],o[0])),h[2]))),e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2])))),F=r(p,g);return F[F.length-1]}}function Yu(e,t,n,r){return function(o,s,c,h,p){var g=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),c[2]),e(n(e(t(c[1],p[0]),t(-p[1],c[0])),-h[2]),n(e(t(c[1],h[0]),t(-h[1],c[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]))),-c[3]),n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[1],s[0])),p[2]))),h[3]))),e(n(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[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(c[1],h[0]),t(-h[1],c[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[1],s[0])),h[2]))),o[3]))),e(n(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[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]))),c[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),-h[3]))))),F=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),c[2]),e(n(e(t(c[1],p[0]),t(-p[1],c[0])),-h[2]),n(e(t(c[1],h[0]),t(-h[1],c[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]))),-c[3])),e(n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[1],o[0])),p[2]))),h[3]),n(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[1],o[0])),h[2]))),-p[3]))),e(e(n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[1],s[0])),p[2]))),o[3]),n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[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]))),c[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),-p[3])))),N=r(g,F);return N[N.length-1]}}function vr(e){var t=e===3?Cu:e===4?ku:Yu;return t(mu,Ru,Ou,Vu)}var Xu=vr(3),Hu=vr(4),Se=[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,c;if(i>0){if(o<=0)return s;c=i+o}else if(i<0){if(o>=0)return s;c=-(i+o)}else return s;var h=qu*c;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],c=r[0]-i[0],h=t[1]-i[1],p=n[1]-i[1],g=r[1]-i[1],F=t[2]-i[2],N=n[2]-i[2],q=r[2]-i[2],m=s*g,C=c*p,Y=c*h,H=o*g,W=o*p,Q=s*h,et=F*(m-C)+N*(Y-H)+q*(W-Q),$=(Math.abs(m)+Math.abs(C))*Math.abs(F)+(Math.abs(Y)+Math.abs(H))*Math.abs(N)+(Math.abs(W)+Math.abs(Q))*Math.abs(q),J=Nu*$;return et>J||-et>J?et:Hu(t,n,r,i)}];function Zu(e){var t=Se[e.length];return t||(t=Se[e.length]=vr(e.length)),t.apply(void 0,e)}function $u(e,t,n,r,i,o,s){return function(h,p,g,F,N){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,F);case 5:return s(h,p,g,F,N)}for(var q=new Array(arguments.length),m=0;m<arguments.length;++m)q[m]=arguments[m];return e(q)}}function Wu(){for(;Se.length<=Ni;)Se.push(vr(Se.length));xn.exports=$u.apply(void 0,[Zu].concat(Se));for(var e=0;e<=Ni;++e)xn.exports[e]=Se[e]}Wu()});var Zi=xt((p1,Hi)=>{"use strict";var dr=Qe(),ye=yn()[3],bn=0,Ci=1,Mn=2;Hi.exports=t0;function Yi(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function Ke(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function Qu(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==bn&&(n=ye(e.a,e.b,t.b),n)?n:e.idx-t.idx}function ki(e,t){return ye(e.a,e.b,t)}function Ku(e,t,n,r,i){for(var o=dr.lt(t,r,ki),s=dr.gt(t,r,ki),c=o;c<s;++c){for(var h=t[c],p=h.lowerIds,F=p.length;F>1&&ye(n[p[F-2]],n[p[F-1]],r)>0;)e.push([p[F-1],p[F-2],i]),F-=1;p.length=F,p.push(i);for(var g=h.upperIds,F=g.length;F>1&&ye(n[g[F-2]],n[g[F-1]],r)<0;)e.push([g[F-2],g[F-1],i]),F-=1;g.length=F,g.push(i)}}function Xi(e,t){var n;return e.a[0]<t.a[0]?n=ye(e.a,e.b,t.a):n=ye(t.b,t.a,e.a),n||(t.b[0]<e.b[0]?n=ye(e.a,e.b,t.b):n=ye(t.b,t.a,e.b),n||e.idx-t.idx)}function Ju(e,t,n){var r=dr.le(e,n,Xi),i=e[r],o=i.upperIds,s=o[o.length-1];i.upperIds=[s],e.splice(r+1,0,new Yi(n.a,n.b,n.idx,[s],o))}function ju(e,t,n){var r=n.a;n.a=n.b,n.b=r;var i=dr.eq(e,n,Xi),o=e[i],s=e[i-1];s.upperIds=o.upperIds,e.splice(i,1)}function t0(e,t){for(var n=e.length,r=t.length,i=[],o=0;o<n;++o)i.push(new Ke(e[o],null,bn,o));for(var o=0;o<r;++o){var s=t[o],c=e[s[0]],h=e[s[1]];c[0]<h[0]?i.push(new Ke(c,h,Mn,o),new Ke(h,c,Ci,o)):c[0]>h[0]&&i.push(new Ke(h,c,Mn,o),new Ke(c,h,Ci,o))}i.sort(Qu);for(var p=i[0].a[0]-(1+Math.abs(i[0].a[0]))*Math.pow(2,-52),g=[new Yi([p,1],[p,0],-1,[],[],[],[])],F=[],o=0,N=i.length;o<N;++o){var q=i[o],m=q.type;m===bn?Ku(F,g,e,q.a,q.idx):m===Mn?Ju(g,e,q):ju(g,e,q)}return F}});var Qi=xt((v1,Wi)=>{"use strict";var e0=Qe();Wi.exports=r0;function $i(e,t){this.stars=e,this.edges=t}var Be=$i.prototype;function Tn(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}}Be.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),e0.eq(this.edges,e,t)>=0}}();Be.removeTriangle=function(e,t,n){var r=this.stars;Tn(r[e],t,n),Tn(r[t],n,e),Tn(r[n],e,t)};Be.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)};Be.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};Be.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)};Be.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};Be.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 c=i[o],h=i[o+1];n<Math.min(c,h)&&t.push([n,c,h])}return t};function r0(e,t){for(var n=new Array(e),r=0;r<e;++r)n[r]=[];return new $i(n,t)}});var ji=xt((d1,_n)=>{"use strict";var n0=hr(),i0=vn(),o0=wn(),a0=gn(),Ki=6;function Ji(e){var t=e===3?f0:e===4?l0:e===5?h0:p0;return t(i0,o0,n0,a0)}function s0(){return 0}function u0(){return 0}function c0(){return 0}function f0(e,t,n,r){function i(o,s,c){var h=n(o[0],o[0]),p=r(h,s[0]),g=r(h,c[0]),F=n(s[0],s[0]),N=r(F,o[0]),q=r(F,c[0]),m=n(c[0],c[0]),C=r(m,o[0]),Y=r(m,s[0]),H=e(t(Y,q),t(N,p)),W=t(C,g),Q=t(H,W);return Q[Q.length-1]}return i}function l0(e,t,n,r){function i(o,s,c,h){var p=e(n(o[0],o[0]),n(o[1],o[1])),g=r(p,s[0]),F=r(p,c[0]),N=r(p,h[0]),q=e(n(s[0],s[0]),n(s[1],s[1])),m=r(q,o[0]),C=r(q,c[0]),Y=r(q,h[0]),H=e(n(c[0],c[0]),n(c[1],c[1])),W=r(H,o[0]),Q=r(H,s[0]),et=r(H,h[0]),$=e(n(h[0],h[0]),n(h[1],h[1])),J=r($,o[0]),ut=r($,s[0]),tt=r($,c[0]),rt=e(e(r(t(tt,et),s[1]),e(r(t(ut,Y),-c[1]),r(t(Q,C),h[1]))),e(r(t(ut,Y),o[1]),e(r(t(J,N),-s[1]),r(t(m,g),h[1])))),D=e(e(r(t(tt,et),o[1]),e(r(t(J,N),-c[1]),r(t(W,F),h[1]))),e(r(t(Q,C),o[1]),e(r(t(W,F),-s[1]),r(t(m,g),c[1])))),a=t(rt,D);return a[a.length-1]}return i}function h0(e,t,n,r){function i(o,s,c,h,p){var g=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),F=r(g,s[0]),N=r(g,c[0]),q=r(g,h[0]),m=r(g,p[0]),C=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),Y=r(C,o[0]),H=r(C,c[0]),W=r(C,h[0]),Q=r(C,p[0]),et=e(n(c[0],c[0]),e(n(c[1],c[1]),n(c[2],c[2]))),$=r(et,o[0]),J=r(et,s[0]),ut=r(et,h[0]),tt=r(et,p[0]),rt=e(n(h[0],h[0]),e(n(h[1],h[1]),n(h[2],h[2]))),D=r(rt,o[0]),a=r(rt,s[0]),v=r(rt,c[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]),E=r(M,s[0]),R=r(M,c[0]),P=r(M,h[0]),l=e(e(e(r(e(r(t(P,T),c[1]),e(r(t(R,tt),-h[1]),r(t(v,ut),p[1]))),s[2]),e(r(e(r(t(P,T),s[1]),e(r(t(E,Q),-h[1]),r(t(a,W),p[1]))),-c[2]),r(e(r(t(R,tt),s[1]),e(r(t(E,Q),-c[1]),r(t(J,H),p[1]))),h[2]))),e(r(e(r(t(v,ut),s[1]),e(r(t(a,W),-c[1]),r(t(J,H),h[1]))),-p[2]),e(r(e(r(t(P,T),s[1]),e(r(t(E,Q),-h[1]),r(t(a,W),p[1]))),o[2]),r(e(r(t(P,T),o[1]),e(r(t(S,m),-h[1]),r(t(D,q),p[1]))),-s[2])))),e(e(r(e(r(t(E,Q),o[1]),e(r(t(S,m),-s[1]),r(t(Y,F),p[1]))),h[2]),e(r(e(r(t(a,W),o[1]),e(r(t(D,q),-s[1]),r(t(Y,F),h[1]))),-p[2]),r(e(r(t(v,ut),s[1]),e(r(t(a,W),-c[1]),r(t(J,H),h[1]))),o[2]))),e(r(e(r(t(v,ut),o[1]),e(r(t(D,q),-c[1]),r(t($,N),h[1]))),-s[2]),e(r(e(r(t(a,W),o[1]),e(r(t(D,q),-s[1]),r(t(Y,F),h[1]))),c[2]),r(e(r(t(J,H),o[1]),e(r(t($,N),-s[1]),r(t(Y,F),c[1]))),-h[2]))))),G=e(e(e(r(e(r(t(P,T),c[1]),e(r(t(R,tt),-h[1]),r(t(v,ut),p[1]))),o[2]),r(e(r(t(P,T),o[1]),e(r(t(S,m),-h[1]),r(t(D,q),p[1]))),-c[2])),e(r(e(r(t(R,tt),o[1]),e(r(t(S,m),-c[1]),r(t($,N),p[1]))),h[2]),r(e(r(t(v,ut),o[1]),e(r(t(D,q),-c[1]),r(t($,N),h[1]))),-p[2]))),e(e(r(e(r(t(R,tt),s[1]),e(r(t(E,Q),-c[1]),r(t(J,H),p[1]))),o[2]),r(e(r(t(R,tt),o[1]),e(r(t(S,m),-c[1]),r(t($,N),p[1]))),-s[2])),e(r(e(r(t(E,Q),o[1]),e(r(t(S,m),-s[1]),r(t(Y,F),p[1]))),c[2]),r(e(r(t(J,H),o[1]),e(r(t($,N),-s[1]),r(t(Y,F),c[1]))),-p[2])))),ot=t(l,G);return ot[ot.length-1]}return i}function p0(e,t,n,r){function i(o,s,c,h,p,g){var F=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),N=r(F,s[0]),q=r(F,c[0]),m=r(F,h[0]),C=r(F,p[0]),Y=r(F,g[0]),H=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),W=r(H,o[0]),Q=r(H,c[0]),et=r(H,h[0]),$=r(H,p[0]),J=r(H,g[0]),ut=e(e(n(c[0],c[0]),n(c[1],c[1])),e(n(c[2],c[2]),n(c[3],c[3]))),tt=r(ut,o[0]),rt=r(ut,s[0]),D=r(ut,h[0]),a=r(ut,p[0]),v=r(ut,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]),E=r(T,c[0]),R=r(T,p[0]),P=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,c[0]),st=r(l,h[0]),ct=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]),Z=r(yt,c[0]),U=r(yt,h[0]),f=r(yt,p[0]),b=e(e(e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),c[2]),r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),p[2]),r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),-g[2]))),s[3]),e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-h[2])),e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),p[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-g[2]))),-c[3]),r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),s[2]),r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),s[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-c[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-h[2])),e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),p[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-h[2])),e(r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),p[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),p[2]),r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),-g[2]))),h[3]),r(e(e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),s[2]),r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-g[2]))),o[3]))),e(e(r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-g[2]))),-s[3]),r(e(e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-g[2]))),c[3])),e(r(e(e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-g[2]))),-h[3]),r(e(e(r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-s[2])),e(r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-h[2]))),g[3]))))),w=e(e(e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),c[2]),r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),p[2]),r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),-g[2]))),o[3]),e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-h[2])),e(r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),p[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-g[2]))),-c[3]),r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-c[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),p[2]),r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),-g[2]))),c[3]),r(e(e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),s[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-c[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-p[2]))),o[3]))),e(e(r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-c[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-p[2]))),-s[3]),r(e(e(r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-p[2]))),c[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-p[2]))),-h[3]),r(e(e(r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-s[2])),e(r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-h[2]))),p[3]))))),I=t(b,w);return I[I.length-1]}return i}var Pe=[s0,u0,c0];function v0(e){var t=Pe[e.length];return t||(t=Pe[e.length]=Ji(e.length)),t.apply(void 0,e)}function d0(e,t,n,r,i,o,s,c){function h(p,g,F,N,q,m){switch(arguments.length){case 0:case 1:return 0;case 2:return r(p,g);case 3:return i(p,g,F);case 4:return o(p,g,F,N);case 5:return s(p,g,F,N,q);case 6:return c(p,g,F,N,q,m)}for(var C=new Array(arguments.length),Y=0;Y<arguments.length;++Y)C[Y]=arguments[Y];return e(C)}return h}function g0(){for(;Pe.length<=Ki;)Pe.push(Ji(Pe.length));_n.exports=d0.apply(void 0,[v0].concat(Pe));for(var e=0;e<=Ki;++e)_n.exports[e]=Pe[e]}g0()});var eo=xt((w1,to)=>{"use strict";var Sn=ji()[4],g1=Qe();to.exports=w0;function gr(e,t,n,r,i,o){var s=t.opposite(r,i);if(!(s<0)){if(i<r){var c=r;r=i,i=c,c=o,o=s,s=c}t.isConstraint(r,i)||Sn(e[r],e[i],e[o],e[s])<0&&n.push(r,i)}}function w0(e,t){for(var n=[],r=e.length,i=t.stars,o=0;o<r;++o)for(var s=i[o],c=1;c<s.length;c+=2){var h=s[c];if(!(h<o)&&!t.isConstraint(o,h)){for(var p=s[c-1],g=-1,F=1;F<s.length;F+=2)if(s[F-1]===h){g=s[F];break}g<0||Sn(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],N=1;N<s.length;N+=2){var q=s[N-1],m=s[N];q===h?g=m:m===h&&(p=q)}p<0||g<0||Sn(e[o],e[h],e[p],e[g])>=0||(t.flip(o,h),gr(e,t,n,p,o,g),gr(e,t,n,o,g,p),gr(e,t,n,g,h,p),gr(e,t,n,h,p,g))}}});var oo=xt((x1,io)=>{"use strict";var x0=Qe();io.exports=T0;function ro(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 y0=ro.prototype;function no(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}y0.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,x0.eq(this.cells,e,no))}}();function M0(e,t){for(var n=e.cells(),r=n.length,i=0;i<r;++i){var o=n[i],s=o[0],c=o[1],h=o[2];c<h?c<s&&(o[0]=c,o[1]=h,o[2]=s):h<s&&(o[0]=h,o[1]=s,o[2]=c)}n.sort(no);for(var p=new Array(r),i=0;i<p.length;++i)p[i]=0;var g=[],F=[],N=new Array(3*r),q=new Array(3*r),m=null;t&&(m=[]);for(var C=new ro(n,N,q,p,g,F,m),i=0;i<r;++i)for(var o=n[i],Y=0;Y<3;++Y){var s=o[Y],c=o[(Y+1)%3],H=N[3*i+Y]=C.locate(c,s,e.opposite(c,s)),W=q[3*i+Y]=e.isConstraint(s,c);H<0&&(W?F.push(i):(g.push(i),p[i]=1),t&&m.push([c,s,-1]))}return C}function b0(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 T0(e,t,n){var r=M0(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,o=r.active,s=r.next,c=r.flags,h=r.cells,p=r.constraint,g=r.neighbor;o.length>0||s.length>0;){for(;o.length>0;){var F=o.pop();if(c[F]!==-i){c[F]=i;for(var N=h[F],q=0;q<3;++q){var m=g[3*F+q];m>=0&&c[m]===0&&(p[3*F+q]?s.push(m):(o.push(m),c[m]=i))}}}var C=s;s=o,o=C,s.length=0,i=-i}var Y=b0(h,c,t);return n?Y.concat(r.boundary):Y}});var so=xt((y1,ao)=>{"use strict";var _0=Zi(),S0=Qi(),B0=eo(),Bn=oo();ao.exports=G0;function P0(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function D0(e,t){return e[0]-t[0]||e[1]-t[1]}function U0(e){return e.map(P0).sort(D0)}function wr(e,t,n){return t in e?e[t]:n}function G0(e,t,n){Array.isArray(t)?(n=n||{},t=t||[]):(n=t||{},t=[]);var r=!!wr(n,"delaunay",!0),i=!!wr(n,"interior",!0),o=!!wr(n,"exterior",!0),s=!!wr(n,"infinity",!1);if(!i&&!o||e.length===0)return[];var c=_0(e,t);if(r||i!==o||s){for(var h=S0(e.length,U0(t)),p=0;p<c.length;++p){var g=c[p];h.addTriangle(g[0],g[1],g[2])}return r&&B0(e,h),o?i?s?Bn(h,0,s):h.cells():Bn(h,1,s):Bn(h,-1)}else return c}});var fo=xt((M1,co)=>{"use strict";"use restrict";co.exports=uo;function uo(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 xr=uo.prototype;Object.defineProperty(xr,"length",{get:function(){return this.roots.length}});xr.makeSet=function(){var e=this.roots.length;return this.roots.push(e),this.ranks.push(0),e};xr.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};xr.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],c=i[r];s<c?o[n]=r:c<s?o[r]=n:(o[r]=n,++i[n])}}});var je=xt(Nt=>{"use strict";"use restrict";var Pn=32;Nt.INT_BITS=Pn;Nt.INT_MAX=2147483647;Nt.INT_MIN=-1<<Pn-1;Nt.sign=function(e){return(e>0)-(e<0)};Nt.abs=function(e){var t=e>>Pn-1;return(e^t)-t};Nt.min=function(e,t){return t^(e^t)&-(e<t)};Nt.max=function(e,t){return e^(e^t)&-(e<t)};Nt.isPow2=function(e){return!(e&e-1)&&!!e};Nt.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};Nt.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};Nt.popCount=function(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),(e+(e>>>4)&252645135)*16843009>>>24};function lo(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}Nt.countTrailingZeros=lo;Nt.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};Nt.prevPow2=function(e){return e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e-(e>>>1)};Nt.parity=function(e){return e^=e>>>16,e^=e>>>8,e^=e>>>4,e&=15,27030>>>e&1};var Je=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}})(Je);Nt.reverse=function(e){return Je[e&255]<<24|Je[e>>>8&255]<<16|Je[e>>>16&255]<<8|Je[e>>>24&255]};Nt.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};Nt.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};Nt.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};Nt.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};Nt.nextCombination=function(e){var t=e|e-1;return t+1|(~t&-~t)-1>>>lo(e)+1}});var vo=xt((T1,po)=>{"use strict";function ho(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]=ho(e,t,n+1);return i}function F0(e,t){var n,r;for(n=new Array(e),r=0;r<e;++r)n[r]=t;return n}function A0(e,t){switch(typeof t>"u"&&(t=0),typeof e){case"number":if(e>0)return F0(e|0,t);break;case"object":if(typeof e.length=="number")return ho(e,t,0);break}return[]}po.exports=A0});var br=xt(It=>{"use strict";var yr=je(),te=vo();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 I0=typeof Uint8ClampedArray<"u",E0=typeof BigUint64Array<"u",L0=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 Mr=Qt.DATA;It.free=function(t){if(Object.prototype.toString.call(t)!=="[object ArrayBuffer]"&&(t=t.buffer),!!t){var n=t.length||t.byteLength,r=yr.log2(n)|0;Mr[r].push(t)}};function go(e){if(e){var t=e.length||e.byteLength,n=yr.log2(t);Mr[n].push(e)}}function z0(e){go(e.buffer)}It.freeUint8=It.freeUint16=It.freeUint32=It.freeBigUint64=It.freeInt8=It.freeInt16=It.freeInt32=It.freeBigInt64=It.freeFloat32=It.freeFloat=It.freeFloat64=It.freeDouble=It.freeUint8Clamped=It.freeDataView=z0;It.freeArrayBuffer=go;It.malloc=function(t,n){if(n===void 0||n==="arraybuffer")return ie(t);switch(n){case"uint8":return Dn(t);case"uint16":return wo(t);case"uint32":return xo(t);case"int8":return yo(t);case"int16":return Mo(t);case"int32":return bo(t);case"float":case"float32":return To(t);case"double":case"float64":return _o(t);case"uint8_clamped":return So(t);case"bigint64":return Po(t);case"biguint64":return Bo(t);case"data":case"dataview":return Do(t);default:return null}return null};function ie(t){var t=yr.nextPow2(t),n=yr.log2(t),r=Mr[n];return r.length>0?r.pop():new ArrayBuffer(t)}It.mallocArrayBuffer=ie;function Dn(e){return new Uint8Array(ie(e),0,e)}It.mallocUint8=Dn;function wo(e){return new Uint16Array(ie(2*e),0,e)}It.mallocUint16=wo;function xo(e){return new Uint32Array(ie(4*e),0,e)}It.mallocUint32=xo;function yo(e){return new Int8Array(ie(e),0,e)}It.mallocInt8=yo;function Mo(e){return new Int16Array(ie(2*e),0,e)}It.mallocInt16=Mo;function bo(e){return new Int32Array(ie(4*e),0,e)}It.mallocInt32=bo;function To(e){return new Float32Array(ie(4*e),0,e)}It.mallocFloat32=It.mallocFloat=To;function _o(e){return new Float64Array(ie(8*e),0,e)}It.mallocFloat64=It.mallocDouble=_o;function So(e){return I0?new Uint8ClampedArray(ie(e),0,e):Dn(e)}It.mallocUint8Clamped=So;function Bo(e){return E0?new BigUint64Array(ie(8*e),0,e):null}It.mallocBigUint64=Bo;function Po(e){return L0?new BigInt64Array(ie(8*e),0,e):null}It.mallocBigInt64=Po;function Do(e){return new DataView(ie(e),0,e)}It.mallocDataView=Do;It.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,Mr[t].length=0}});var Io=xt((S1,Ao)=>{"use strict";Ao.exports=R0;var _r=32;function R0(e,t){t<=4*_r?Sr(0,t-1,e):Br(0,t-1,e)}function Sr(e,t,n){for(var r=2*(e+1),i=e+1;i<=t;++i){for(var o=n[r++],s=n[r++],c=i,h=r-2;c-- >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 Uo(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 Go(e,t,n){e*=2,t*=2,n[e]=n[t],n[e+1]=n[t+1]}function m0(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 Fo(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 ve(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 Tr(e,t,n,r){e*=2;var i=r[e];return i<t?!0:i===t?r[e+1]<n:!1}function Br(e,t,n){var r=(t-e+1)/6|0,i=e+r,o=t-r,s=e+t>>1,c=s-r,h=s+r,p=i,g=c,F=s,N=h,q=o,m=e+1,C=t-1,Y=0;ve(p,g,n)&&(Y=p,p=g,g=Y),ve(N,q,n)&&(Y=N,N=q,q=Y),ve(p,F,n)&&(Y=p,p=F,F=Y),ve(g,F,n)&&(Y=g,g=F,F=Y),ve(p,N,n)&&(Y=p,p=N,N=Y),ve(F,N,n)&&(Y=F,F=N,N=Y),ve(g,q,n)&&(Y=g,g=q,q=Y),ve(g,F,n)&&(Y=g,g=F,F=Y),ve(N,q,n)&&(Y=N,N=q,q=Y);for(var H=n[2*g],W=n[2*g+1],Q=n[2*N],et=n[2*N+1],$=2*p,J=2*F,ut=2*q,tt=2*i,rt=2*s,D=2*o,a=0;a<2;++a){var v=n[$+a],T=n[J+a],M=n[ut+a];n[tt+a]=v,n[rt+a]=T,n[D+a]=M}Go(c,e,n),Go(h,t,n);for(var S=m;S<=C;++S)if(Tr(S,H,W,n))S!==m&&Uo(S,m,n),++m;else if(!Tr(S,Q,et,n))for(;;)if(Tr(C,Q,et,n)){Tr(C,H,W,n)?(m0(S,m,C,n),++m,--C):(Uo(S,C,n),--C);break}else{if(--C<S)break;continue}Fo(e,m-1,H,W,n),Fo(t,C+1,Q,et,n),m-2-e<=_r?Sr(e,m-2,n):Br(e,m-2,n),t-(C+2)<=_r?Sr(C+2,t,n):Br(C+2,t,n),C-m<=_r?Sr(m,C,n):Br(m,C,n)}});var Un=xt((B1,Eo)=>{"use strict";Eo.exports={init:V0,sweepBipartite:q0,sweepComplete:N0,scanBipartite:C0,scanComplete:k0};var Yt=br(),O0=je(),Pr=Io(),ae=1<<28,Ue=1024,Kt=Yt.mallocInt32(Ue),de=Yt.mallocInt32(Ue),ge=Yt.mallocInt32(Ue),De=Yt.mallocInt32(Ue),me=Yt.mallocInt32(Ue),tr=Yt.mallocInt32(Ue),_t=Yt.mallocDouble(Ue*8);function V0(e){var t=O0.nextPow2(e);Kt.length<t&&(Yt.free(Kt),Kt=Yt.mallocInt32(t)),de.length<t&&(Yt.free(de),de=Yt.mallocInt32(t)),ge.length<t&&(Yt.free(ge),ge=Yt.mallocInt32(t)),De.length<t&&(Yt.free(De),De=Yt.mallocInt32(t)),me.length<t&&(Yt.free(me),me=Yt.mallocInt32(t)),tr.length<t&&(Yt.free(tr),tr=Yt.mallocInt32(t));var n=8*t;_t.length<n&&(Yt.free(_t),_t=Yt.mallocDouble(n))}function Oe(e,t,n,r){var i=t[r],o=e[n-1];e[i]=o,t[o]=i}function Ve(e,t,n,r){e[n]=r,t[r]=n}function q0(e,t,n,r,i,o,s,c,h,p){for(var g=0,F=2*e,N=e-1,q=F-1,m=n;m<r;++m){var C=o[m],Y=F*m;_t[g++]=i[Y+N],_t[g++]=-(C+1),_t[g++]=i[Y+q],_t[g++]=C}for(var m=s;m<c;++m){var C=p[m]+ae,H=F*m;_t[g++]=h[H+N],_t[g++]=-C,_t[g++]=h[H+q],_t[g++]=C}var W=g>>>1;Pr(_t,W);for(var Q=0,et=0,m=0;m<W;++m){var $=_t[2*m+1]|0;if($>=ae)$=$-ae|0,Oe(ge,De,et--,$);else if($>=0)Oe(Kt,de,Q--,$);else if($<=-ae){$=-$-ae|0;for(var J=0;J<Q;++J){var ut=t(Kt[J],$);if(ut!==void 0)return ut}Ve(ge,De,et++,$)}else{$=-$-1|0;for(var J=0;J<et;++J){var ut=t($,ge[J]);if(ut!==void 0)return ut}Ve(Kt,de,Q++,$)}}}function N0(e,t,n,r,i,o,s,c,h,p){for(var g=0,F=2*e,N=e-1,q=F-1,m=n;m<r;++m){var C=o[m]+1<<1,Y=F*m;_t[g++]=i[Y+N],_t[g++]=-C,_t[g++]=i[Y+q],_t[g++]=C}for(var m=s;m<c;++m){var C=p[m]+1<<1,H=F*m;_t[g++]=h[H+N],_t[g++]=-C|1,_t[g++]=h[H+q],_t[g++]=C|1}var W=g>>>1;Pr(_t,W);for(var Q=0,et=0,$=0,m=0;m<W;++m){var J=_t[2*m+1]|0,ut=J&1;if(m<W-1&&J>>1===_t[2*m+3]>>1&&(ut=2,m+=1),J<0){for(var tt=-(J>>1)-1,rt=0;rt<$;++rt){var D=t(me[rt],tt);if(D!==void 0)return D}if(ut!==0)for(var rt=0;rt<Q;++rt){var D=t(Kt[rt],tt);if(D!==void 0)return D}if(ut!==1)for(var rt=0;rt<et;++rt){var D=t(ge[rt],tt);if(D!==void 0)return D}ut===0?Ve(Kt,de,Q++,tt):ut===1?Ve(ge,De,et++,tt):ut===2&&Ve(me,tr,$++,tt)}else{var tt=(J>>1)-1;ut===0?Oe(Kt,de,Q--,tt):ut===1?Oe(ge,De,et--,tt):ut===2&&Oe(me,tr,$--,tt)}}}function C0(e,t,n,r,i,o,s,c,h,p,g,F){var N=0,q=2*e,m=t,C=t+e,Y=1,H=1;r?H=ae:Y=ae;for(var W=i;W<o;++W){var Q=W+Y,et=q*W;_t[N++]=s[et+m],_t[N++]=-Q,_t[N++]=s[et+C],_t[N++]=Q}for(var W=h;W<p;++W){var Q=W+H,$=q*W;_t[N++]=g[$+m],_t[N++]=-Q}var J=N>>>1;Pr(_t,J);for(var ut=0,W=0;W<J;++W){var tt=_t[2*W+1]|0;if(tt<0){var Q=-tt,rt=!1;if(Q>=ae?(rt=!r,Q-=ae):(rt=!!r,Q-=1),rt)Ve(Kt,de,ut++,Q);else{var D=F[Q],a=q*Q,v=g[a+t+1],T=g[a+t+1+e];t:for(var M=0;M<ut;++M){var S=Kt[M],E=q*S;if(!(T<s[E+t+1]||s[E+t+1+e]<v)){for(var R=t+2;R<e;++R)if(g[a+R+e]<s[E+R]||s[E+R+e]<g[a+R])continue t;var P=c[S],l;if(r?l=n(D,P):l=n(P,D),l!==void 0)return l}}}}else Oe(Kt,de,ut--,tt-Y)}}function k0(e,t,n,r,i,o,s,c,h,p,g){for(var F=0,N=2*e,q=t,m=t+e,C=r;C<i;++C){var Y=C+ae,H=N*C;_t[F++]=o[H+q],_t[F++]=-Y,_t[F++]=o[H+m],_t[F++]=Y}for(var C=c;C<h;++C){var Y=C+1,W=N*C;_t[F++]=p[W+q],_t[F++]=-Y}var Q=F>>>1;Pr(_t,Q);for(var et=0,C=0;C<Q;++C){var $=_t[2*C+1]|0;if($<0){var Y=-$;if(Y>=ae)Kt[et++]=Y-ae;else{Y-=1;var J=g[Y],ut=N*Y,tt=p[ut+t+1],rt=p[ut+t+1+e];t:for(var D=0;D<et;++D){var a=Kt[D],v=s[a];if(v===J)break;var T=N*a;if(!(rt<o[T+t+1]||o[T+t+1+e]<tt)){for(var M=t+2;M<e;++M)if(p[ut+M+e]<o[T+M]||o[T+M+e]<p[ut+M])continue t;var S=n(v,J);if(S!==void 0)return S}}}}else{for(var Y=$-ae,D=et-1;D>=0;--D)if(Kt[D]===Y){for(var M=D+1;M<et;++M)Kt[M-1]=Kt[M];break}--et}}}});var Oo=xt(zn=>{"use strict";var Ge="d",Ce="ax",Lo="vv",Gn="fp",er="es",Dr="rs",En="re",rr="rb",zo="ri",qe="rp",Ur="bs",Ln="be",nr="bb",Ro="bi",Ne="bp",Fn="rv",An="Q",In=[Ge,Ce,Lo,Dr,En,rr,zo,Ur,Ln,nr,Ro];function Y0(e,t,n){var r="bruteForce"+(e?"Red":"Blue")+(t?"Flip":"")+(n?"Full":""),i=["function ",r,"(",In.join(),"){","var ",er,"=2*",Ge,";"],o="for(var i="+Dr+","+qe+"="+er+"*"+Dr+";i<"+En+";++i,"+qe+"+="+er+"){var x0="+rr+"["+Ce+"+"+qe+"],x1="+rr+"["+Ce+"+"+qe+"+"+Ge+"],xi="+zo+"[i];",s="for(var j="+Ur+","+Ne+"="+er+"*"+Ur+";j<"+Ln+";++j,"+Ne+"+="+er+"){var y0="+nr+"["+Ce+"+"+Ne+"],"+(n?"y1="+nr+"["+Ce+"+"+Ne+"+"+Ge+"],":"")+"yi="+Ro+"[j];";return e?i.push(o,An,":",s):i.push(s,An,":",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="+Ce+"+1;k<"+Ge+";++k){var r0="+rr+"[k+"+qe+"],r1="+rr+"[k+"+Ge+"+"+qe+"],b0="+nr+"[k+"+Ne+"],b1="+nr+"[k+"+Ge+"+"+Ne+"];if(r1<b0||b1<r0)continue "+An+";}var "+Fn+"="+Lo+"("),t?i.push("yi,xi"):i.push("xi,yi"),i.push(");if("+Fn+"!==void 0)return "+Fn+";}}}"),{name:r,code:i.join("")}}function mo(e){var t="bruteForce"+(e?"Full":"Partial"),n=[],r=In.slice();e||r.splice(3,0,Gn);var i=["function "+t+"("+r.join()+"){"];function o(h,p){var g=Y0(h,p,e);n.push(g.code),i.push("return "+g.name+"("+In.join()+");")}i.push("if("+En+"-"+Dr+">"+Ln+"-"+Ur+"){"),e?(o(!0,!1),i.push("}else{"),o(!1,!1)):(i.push("if("+Gn+"){"),o(!0,!0),i.push("}else{"),o(!0,!1),i.push("}}else{if("+Gn+"){"),o(!1,!0),i.push("}else{"),o(!1,!1),i.push("}")),i.push("}}return "+t);var s=n.join("")+i.join(""),c=new Function(s);return c()}zn.partial=mo(!1);zn.full=mo(!0)});var Rn=xt((D1,Vo)=>{"use strict";Vo.exports=H0;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 H0(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 Co=xt((U1,No)=>{"use strict";No.exports=Q0;var Z0=Rn(),qo=Z0("lo<p0",["p0"]),$0=8;function W0(e,t,n,r,i,o){for(var s=2*e,c=s*(n+1)+t,h=n+1;h<r;++h,c+=s)for(var p=i[c],g=h,F=s*(h-1);g>n&&i[F+t]>p;--g,F-=s){for(var N=F,q=F+s,m=0;m<s;++m,++N,++q){var C=i[N];i[N]=i[q],i[q]=C}var Y=o[g];o[g]=o[g-1],o[g-1]=Y}}function Q0(e,t,n,r,i,o){if(r<=n+1)return n;for(var s=n,c=r,h=r+n>>>1,p=2*e,g=h,F=i[p*h+t];s<c;){if(c-s<$0){W0(e,t,s,c,i,o),F=i[p*h+t];break}var N=c-s,q=Math.random()*N+s|0,m=i[p*q+t],C=Math.random()*N+s|0,Y=i[p*C+t],H=Math.random()*N+s|0,W=i[p*H+t];m<=Y?W>=Y?(g=C,F=Y):m>=W?(g=q,F=m):(g=H,F=W):Y>=W?(g=C,F=Y):W>=m?(g=q,F=m):(g=H,F=W);for(var $=p*(c-1),J=p*g,Q=0;Q<p;++Q,++$,++J){var et=i[$];i[$]=i[J],i[J]=et}var ut=o[c-1];o[c-1]=o[g],o[g]=ut,g=qo(e,t,s,c-1,i,o,F);for(var $=p*(c-1),J=p*g,Q=0;Q<p;++Q,++$,++J){var et=i[$];i[$]=i[J],i[J]=et}var ut=o[c-1];if(o[c-1]=o[g],o[g]=ut,h<g){for(c=g-1;s<c&&i[p*(c-1)+t]===F;)c-=1;c+=1}else if(g<h)for(s=g+1;s<c&&i[p*s+t]===F;)s+=1;else break}return qo(e,t,n,h,i,o,i[p*h+t])}});var Wo=xt((G1,$o)=>{"use strict";$o.exports=cc;var ke=br(),mn=je(),Ho=Oo(),K0=Ho.partial,J0=Ho.full,Me=Un(),j0=Co(),Ye=Rn(),ko=128,tc=1<<22,ec=1<<22,rc=Ye("!(lo>=p0)&&!(p1>=hi)",["p0","p1"]),Yo=Ye("lo===p0",["p0"]),nc=Ye("lo<p0",["p0"]),ic=Ye("hi<=p0",["p0"]),Xo=Ye("lo<=p0&&p0<=hi",["p0"]),oc=Ye("lo<p0&&p0<=hi",["p0"]),On=6,Vn=2,Zo=1024,ee=ke.mallocInt32(Zo),Fe=ke.mallocDouble(Zo);function ac(e,t){var n=8*mn.log2(t+1)*(e+1)|0,r=mn.nextPow2(On*n);ee.length<r&&(ke.free(ee),ee=ke.mallocInt32(r));var i=mn.nextPow2(Vn*n);Fe.length<i&&(ke.free(Fe),Fe=ke.mallocDouble(i))}function ce(e,t,n,r,i,o,s,c,h){var p=On*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=Vn*e;Fe[g]=c,Fe[g+1]=h}function sc(e,t,n,r,i,o,s,c,h,p,g){var F=2*e,N=h*F,q=p[N+t];t:for(var m=i,C=i*F;m<o;++m,C+=F){var Y=s[C+t],H=s[C+t+e];if(!(q<Y||H<q)&&!(r&&q===Y)){for(var W=c[m],Q=t+1;Q<e;++Q){var Y=s[C+Q],H=s[C+Q+e],et=p[N+Q],$=p[N+Q+e];if(H<et||$<Y)continue t}var J;if(r?J=n(g,W):J=n(W,g),J!==void 0)return J}}}function uc(e,t,n,r,i,o,s,c,h,p){var g=2*e,F=c*g,N=h[F+t];t:for(var q=r,m=r*g;q<i;++q,m+=g){var C=s[q];if(C!==p){var Y=o[m+t],H=o[m+t+e];if(!(N<Y||H<N)){for(var W=t+1;W<e;++W){var Y=o[m+W],H=o[m+W+e],Q=h[F+W],et=h[F+W+e];if(H<Q||et<Y)continue t}var $=n(C,p);if($!==void 0)return $}}}}function cc(e,t,n,r,i,o,s,c,h){ac(e,r+s);var p=0,g=2*e,F;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 N=p*On,q=ee[N],m=ee[N+1],C=ee[N+2],Y=ee[N+3],H=ee[N+4],W=ee[N+5],Q=p*Vn,et=Fe[Q],$=Fe[Q+1],J=W&1,ut=!!(W&16),tt=i,rt=o,D=c,a=h;if(J&&(tt=c,rt=h,D=i,a=o),!(W&2&&(C=nc(e,q,m,C,tt,rt,$),m>=C))&&!(W&4&&(m=ic(e,q,m,C,tt,rt,et),m>=C))){var v=C-m,T=H-Y;if(ut){if(e*v*(v+T)<ec){if(F=Me.scanComplete(e,q,t,m,C,tt,rt,Y,H,D,a),F!==void 0)return F;continue}}else if(e*Math.min(v,T)<ko){if(F=K0(e,q,t,J,m,C,tt,rt,Y,H,D,a),F!==void 0)return F;continue}else if(e*v*T<tc){if(F=Me.scanBipartite(e,q,t,J,m,C,tt,rt,Y,H,D,a),F!==void 0)return F;continue}var M=rc(e,q,m,C,tt,rt,et,$);if(m<M)if(e*(M-m)<ko){if(F=J0(e,q+1,t,m,M,tt,rt,Y,H,D,a),F!==void 0)return F}else if(q===e-2){if(J?F=Me.sweepBipartite(e,t,Y,H,D,a,m,M,tt,rt):F=Me.sweepBipartite(e,t,m,M,tt,rt,Y,H,D,a),F!==void 0)return F}else ce(p++,q+1,m,M,Y,H,J,-1/0,1/0),ce(p++,q+1,Y,H,m,M,J^1,-1/0,1/0);if(M<C){var S=j0(e,q,Y,H,D,a),E=D[g*S+q],R=Yo(e,q,S,H,D,a,E);if(R<H&&ce(p++,q,M,C,R,H,(J|4)+(ut?16:0),E,$),Y<S&&ce(p++,q,M,C,Y,S,(J|2)+(ut?16:0),et,E),S+1===R){if(ut?F=uc(e,q,t,M,C,tt,rt,S,D,a[S]):F=sc(e,q,t,J,M,C,tt,rt,S,D,a[S]),F!==void 0)return F}else if(S<R){var P;if(ut){if(P=Xo(e,q,M,C,tt,rt,E),M<P){var l=Yo(e,q,M,P,tt,rt,E);if(q===e-2){if(M<l&&(F=Me.sweepComplete(e,t,M,l,tt,rt,S,R,D,a),F!==void 0)||l<P&&(F=Me.sweepBipartite(e,t,l,P,tt,rt,S,R,D,a),F!==void 0))return F}else M<l&&ce(p++,q+1,M,l,S,R,16,-1/0,1/0),l<P&&(ce(p++,q+1,l,P,S,R,0,-1/0,1/0),ce(p++,q+1,S,R,l,P,1,-1/0,1/0))}}else J?P=oc(e,q,M,C,tt,rt,E):P=Xo(e,q,M,C,tt,rt,E),M<P&&(q===e-2?J?F=Me.sweepBipartite(e,t,S,R,D,a,M,P,tt,rt):F=Me.sweepBipartite(e,t,M,P,tt,rt,S,R,D,a):(ce(p++,q+1,M,P,S,R,J,-1/0,1/0),ce(p++,q+1,S,R,M,P,J^1,-1/0,1/0)))}}}}}});var jo=xt((F1,Jo)=>{"use strict";Jo.exports=vc;var be=br(),Gr=Un(),fc=Wo();function lc(e,t){for(var n=0;n<e;++n)if(!(t[n]<=t[n+e]))return!0;return!1}function Qo(e,t,n,r){for(var i=0,o=0,s=0,c=e.length;s<c;++s){var h=e[s];if(!lc(t,h)){for(var p=0;p<2*t;++p)n[i++]=h[p];r[o++]=s}}return o}function Fr(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 c,h=be.mallocDouble(2*s*i),p=be.mallocInt32(i);if(i=Qo(e,s,h,p),i>0){if(s===1&&r)Gr.init(i),c=Gr.sweepComplete(s,n,0,i,h,p,0,i,h,p);else{var g=be.mallocDouble(2*s*o),F=be.mallocInt32(o);o=Qo(t,s,g,F),o>0&&(Gr.init(i+o),s===1?c=Gr.sweepBipartite(s,n,0,i,h,p,0,o,g,F):c=fc(s,n,r,i,h,p,o,g,F),be.free(g),be.free(F))}be.free(h),be.free(p)}return c}}}var ir;function Ko(e,t){ir.push([e,t])}function hc(e){return ir=[],Fr(e,e,Ko,!0),ir}function pc(e,t){return ir=[],Fr(e,t,Ko,!1),ir}function vc(e,t,n){var r;switch(arguments.length){case 1:return hc(e);case 2:return typeof t=="function"?Fr(e,e,t,!0):pc(e,t);case 3:return Fr(e,t,n,!1);default:throw new Error("box-intersect: Invalid arguments")}}});var ea=xt((A1,ta)=>{"use strict";ta.exports=gc;var Ar=yn()[3];function dc(e,t,n,r){for(var i=0;i<2;++i){var o=e[i],s=t[i],c=Math.min(o,s),h=Math.max(o,s),p=n[i],g=r[i],F=Math.min(p,g),N=Math.max(p,g);if(N<c||h<F)return!1}return!0}function gc(e,t,n,r){var i=Ar(e,n,r),o=Ar(t,n,r);if(i>0&&o>0||i<0&&o<0)return!1;var s=Ar(n,e,t),c=Ar(r,e,t);return s>0&&c>0||s<0&&c<0?!1:i===0&&o===0&&s===0&&c===0?dc(e,t,n,r):!0}});var ra=xt(()=>{});var or=xt((na,qn)=>{(function(e,t){"use strict";function n(D,a){if(!D)throw new Error(a||"Assertion failed")}function r(D,a){D.super_=a;var v=function(){};v.prototype=a.prototype,D.prototype=new v,D.prototype.constructor=D}function i(D,a,v){if(i.isBN(D))return D;this.negative=0,this.words=null,this.length=0,this.red=null,D!==null&&((a==="le"||a==="be")&&(v=a,a=10),this._init(D||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=ra().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,E,R=0;if(T==="be")for(M=a.length-1,S=0;M>=0;M-=3)E=a[M]|a[M-1]<<8|a[M-2]<<16,this.words[S]|=E<<R&67108863,this.words[S+1]=E>>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);else if(T==="le")for(M=0,S=0;M<a.length;M+=3)E=a[M]|a[M+1]<<8|a[M+2]<<16,this.words[S]|=E<<R&67108863,this.words[S+1]=E>>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);return this.strip()};function s(D,a){var v=D.charCodeAt(a);return v>=65&&v<=70?v-55:v>=97&&v<=102?v-87:v-48&15}function c(D,a,v){var T=s(D,v);return v-1>=a&&(T|=s(D,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,E=0,R;if(T==="be")for(M=a.length-1;M>=v;M-=2)R=c(a,v,M)<<S,this.words[E]|=R&67108863,S>=18?(S-=18,E+=1,this.words[E]|=R>>>26):S+=8;else{var P=a.length-v;for(M=P%2===0?v+1:v;M<a.length;M+=2)R=c(a,v,M)<<S,this.words[E]|=R&67108863,S>=18?(S-=18,E+=1,this.words[E]|=R>>>26):S+=8}this.strip()};function h(D,a,v,T){for(var M=0,S=Math.min(D.length,v),E=a;E<S;E++){var R=D.charCodeAt(E)-48;M*=T,R>=49?M+=R-49+10:R>=17?M+=R-17+10:M+=R}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 E=a.length-T,R=E%M,P=Math.min(E,E-R)+T,l=0,G=T;G<P;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(R!==0){var ot=1;for(l=h(a,G,a.length,v),G=0;G<R;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],F=[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,E=0;E<this.length;E++){var R=this.words[E],P=((R<<M|S)&16777215).toString(16);S=R>>>24-M&16777215,M+=2,M>=26&&(M-=26,E--),S!==0||E!==this.length-1?T=p[6-P.length]+P+T:T=P+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=F[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 E=v==="le",R=new a(S),P,l,G=this.clone();if(E){for(l=0;!G.isZero();l++)P=G.andln(255),G.iushrn(8),R[l]=P;for(;l<S;l++)R[l]=0}else{for(l=0;l<S-M;l++)R[l]=0;for(l=0;!G.isZero();l++)P=G.andln(255),G.iushrn(8),R[S-l-1]=P}return R},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 N(D){for(var a=new Array(D.bitLength()),v=0;v<a.length;v++){var T=v/26|0,M=v%26;a[v]=(D.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,E=0;E<M.length;E++)v=(T.words[E]|0)+(M.words[E]|0)+S,this.words[E]=v&67108863,S=v>>>26;for(;S!==0&&E<T.length;E++)v=(T.words[E]|0)+S,this.words[E]=v&67108863,S=v>>>26;if(this.length=T.length,S!==0)this.words[this.length]=S,this.length++;else if(T!==this)for(;E<T.length;E++)this.words[E]=T.words[E];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 E=0,R=0;R<S.length;R++)v=(M.words[R]|0)-(S.words[R]|0)+E,E=v>>26,this.words[R]=v&67108863;for(;E!==0&&R<M.length;R++)v=(M.words[R]|0)+E,E=v>>26,this.words[R]=v&67108863;if(E===0&&R<M.length&&M!==this)for(;R<M.length;R++)this.words[R]=M.words[R];return this.length=Math.max(this.length,R),M!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(a){return this.clone().isub(a)};function q(D,a,v){v.negative=a.negative^D.negative;var T=D.length+a.length|0;v.length=T,T=T-1|0;var M=D.words[0]|0,S=a.words[0]|0,E=M*S,R=E&67108863,P=E/67108864|0;v.words[0]=R;for(var l=1;l<T;l++){for(var G=P>>>26,ot=P&67108863,at=Math.min(l,a.length-1),st=Math.max(0,l-D.length+1);st<=at;st++){var ct=l-st|0;M=D.words[ct]|0,S=a.words[st]|0,E=M*S+ot,G+=E/67108864|0,ot=E&67108863}v.words[l]=ot|0,P=G|0}return P!==0?v.words[l]=P|0:v.length--,v.strip()}var m=function(a,v,T){var M=a.words,S=v.words,E=T.words,R=0,P,l,G,ot=M[0]|0,at=ot&8191,st=ot>>>13,ct=M[1]|0,yt=ct&8191,pt=ct>>>13,k=M[2]|0,Z=k&8191,U=k>>>13,f=M[3]|0,b=f&8191,w=f>>>13,I=M[4]|0,z=I&8191,O=I>>>13,V=M[5]|0,u=V&8191,B=V>>>13,x=M[6]|0,y=x&8191,d=x>>>13,_=M[7]|0,L=_&8191,A=_>>>13,X=M[8]|0,K=X&8191,j=X>>>13,ft=M[9]|0,nt=ft&8191,it=ft>>>13,vt=S[0]|0,ht=vt&8191,lt=vt>>>13,dt=S[1]|0,wt=dt&8191,gt=dt>>>13,qt=S[2]|0,Mt=qt&8191,bt=qt>>>13,Xt=S[3]|0,St=Xt&8191,Bt=Xt>>>13,Zt=S[4]|0,Pt=Zt&8191,Dt=Zt>>>13,$t=S[5]|0,Ut=$t&8191,Gt=$t>>>13,Wt=S[6]|0,Ft=Wt&8191,At=Wt>>>13,Jt=S[7]|0,Lt=Jt&8191,zt=Jt>>>13,Te=S[8]|0,Rt=Te&8191,mt=Te>>>13,_e=S[9]|0,Ot=_e&8191,Vt=_e>>>13;T.negative=a.negative^v.negative,T.length=19,P=Math.imul(at,ht),l=Math.imul(at,lt),l=l+Math.imul(st,ht)|0,G=Math.imul(st,lt);var Ee=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,P=Math.imul(yt,ht),l=Math.imul(yt,lt),l=l+Math.imul(pt,ht)|0,G=Math.imul(pt,lt),P=P+Math.imul(at,wt)|0,l=l+Math.imul(at,gt)|0,l=l+Math.imul(st,wt)|0,G=G+Math.imul(st,gt)|0;var Le=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Le>>>26)|0,Le&=67108863,P=Math.imul(Z,ht),l=Math.imul(Z,lt),l=l+Math.imul(U,ht)|0,G=Math.imul(U,lt),P=P+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,P=P+Math.imul(at,Mt)|0,l=l+Math.imul(at,bt)|0,l=l+Math.imul(st,Mt)|0,G=G+Math.imul(st,bt)|0;var ze=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(ze>>>26)|0,ze&=67108863,P=Math.imul(b,ht),l=Math.imul(b,lt),l=l+Math.imul(w,ht)|0,G=Math.imul(w,lt),P=P+Math.imul(Z,wt)|0,l=l+Math.imul(Z,gt)|0,l=l+Math.imul(U,wt)|0,G=G+Math.imul(U,gt)|0,P=P+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,P=P+Math.imul(at,St)|0,l=l+Math.imul(at,Bt)|0,l=l+Math.imul(st,St)|0,G=G+Math.imul(st,Bt)|0;var Ht=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,P=Math.imul(z,ht),l=Math.imul(z,lt),l=l+Math.imul(O,ht)|0,G=Math.imul(O,lt),P=P+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,P=P+Math.imul(Z,Mt)|0,l=l+Math.imul(Z,bt)|0,l=l+Math.imul(U,Mt)|0,G=G+Math.imul(U,bt)|0,P=P+Math.imul(yt,St)|0,l=l+Math.imul(yt,Bt)|0,l=l+Math.imul(pt,St)|0,G=G+Math.imul(pt,Bt)|0,P=P+Math.imul(at,Pt)|0,l=l+Math.imul(at,Dt)|0,l=l+Math.imul(st,Pt)|0,G=G+Math.imul(st,Dt)|0;var Yr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Yr>>>26)|0,Yr&=67108863,P=Math.imul(u,ht),l=Math.imul(u,lt),l=l+Math.imul(B,ht)|0,G=Math.imul(B,lt),P=P+Math.imul(z,wt)|0,l=l+Math.imul(z,gt)|0,l=l+Math.imul(O,wt)|0,G=G+Math.imul(O,gt)|0,P=P+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,P=P+Math.imul(Z,St)|0,l=l+Math.imul(Z,Bt)|0,l=l+Math.imul(U,St)|0,G=G+Math.imul(U,Bt)|0,P=P+Math.imul(yt,Pt)|0,l=l+Math.imul(yt,Dt)|0,l=l+Math.imul(pt,Pt)|0,G=G+Math.imul(pt,Dt)|0,P=P+Math.imul(at,Ut)|0,l=l+Math.imul(at,Gt)|0,l=l+Math.imul(st,Ut)|0,G=G+Math.imul(st,Gt)|0;var Xr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Xr>>>26)|0,Xr&=67108863,P=Math.imul(y,ht),l=Math.imul(y,lt),l=l+Math.imul(d,ht)|0,G=Math.imul(d,lt),P=P+Math.imul(u,wt)|0,l=l+Math.imul(u,gt)|0,l=l+Math.imul(B,wt)|0,G=G+Math.imul(B,gt)|0,P=P+Math.imul(z,Mt)|0,l=l+Math.imul(z,bt)|0,l=l+Math.imul(O,Mt)|0,G=G+Math.imul(O,bt)|0,P=P+Math.imul(b,St)|0,l=l+Math.imul(b,Bt)|0,l=l+Math.imul(w,St)|0,G=G+Math.imul(w,Bt)|0,P=P+Math.imul(Z,Pt)|0,l=l+Math.imul(Z,Dt)|0,l=l+Math.imul(U,Pt)|0,G=G+Math.imul(U,Dt)|0,P=P+Math.imul(yt,Ut)|0,l=l+Math.imul(yt,Gt)|0,l=l+Math.imul(pt,Ut)|0,G=G+Math.imul(pt,Gt)|0,P=P+Math.imul(at,Ft)|0,l=l+Math.imul(at,At)|0,l=l+Math.imul(st,Ft)|0,G=G+Math.imul(st,At)|0;var Hr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Hr>>>26)|0,Hr&=67108863,P=Math.imul(L,ht),l=Math.imul(L,lt),l=l+Math.imul(A,ht)|0,G=Math.imul(A,lt),P=P+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,P=P+Math.imul(u,Mt)|0,l=l+Math.imul(u,bt)|0,l=l+Math.imul(B,Mt)|0,G=G+Math.imul(B,bt)|0,P=P+Math.imul(z,St)|0,l=l+Math.imul(z,Bt)|0,l=l+Math.imul(O,St)|0,G=G+Math.imul(O,Bt)|0,P=P+Math.imul(b,Pt)|0,l=l+Math.imul(b,Dt)|0,l=l+Math.imul(w,Pt)|0,G=G+Math.imul(w,Dt)|0,P=P+Math.imul(Z,Ut)|0,l=l+Math.imul(Z,Gt)|0,l=l+Math.imul(U,Ut)|0,G=G+Math.imul(U,Gt)|0,P=P+Math.imul(yt,Ft)|0,l=l+Math.imul(yt,At)|0,l=l+Math.imul(pt,Ft)|0,G=G+Math.imul(pt,At)|0,P=P+Math.imul(at,Lt)|0,l=l+Math.imul(at,zt)|0,l=l+Math.imul(st,Lt)|0,G=G+Math.imul(st,zt)|0;var Zr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Zr>>>26)|0,Zr&=67108863,P=Math.imul(K,ht),l=Math.imul(K,lt),l=l+Math.imul(j,ht)|0,G=Math.imul(j,lt),P=P+Math.imul(L,wt)|0,l=l+Math.imul(L,gt)|0,l=l+Math.imul(A,wt)|0,G=G+Math.imul(A,gt)|0,P=P+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,P=P+Math.imul(u,St)|0,l=l+Math.imul(u,Bt)|0,l=l+Math.imul(B,St)|0,G=G+Math.imul(B,Bt)|0,P=P+Math.imul(z,Pt)|0,l=l+Math.imul(z,Dt)|0,l=l+Math.imul(O,Pt)|0,G=G+Math.imul(O,Dt)|0,P=P+Math.imul(b,Ut)|0,l=l+Math.imul(b,Gt)|0,l=l+Math.imul(w,Ut)|0,G=G+Math.imul(w,Gt)|0,P=P+Math.imul(Z,Ft)|0,l=l+Math.imul(Z,At)|0,l=l+Math.imul(U,Ft)|0,G=G+Math.imul(U,At)|0,P=P+Math.imul(yt,Lt)|0,l=l+Math.imul(yt,zt)|0,l=l+Math.imul(pt,Lt)|0,G=G+Math.imul(pt,zt)|0,P=P+Math.imul(at,Rt)|0,l=l+Math.imul(at,mt)|0,l=l+Math.imul(st,Rt)|0,G=G+Math.imul(st,mt)|0;var $r=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+($r>>>26)|0,$r&=67108863,P=Math.imul(nt,ht),l=Math.imul(nt,lt),l=l+Math.imul(it,ht)|0,G=Math.imul(it,lt),P=P+Math.imul(K,wt)|0,l=l+Math.imul(K,gt)|0,l=l+Math.imul(j,wt)|0,G=G+Math.imul(j,gt)|0,P=P+Math.imul(L,Mt)|0,l=l+Math.imul(L,bt)|0,l=l+Math.imul(A,Mt)|0,G=G+Math.imul(A,bt)|0,P=P+Math.imul(y,St)|0,l=l+Math.imul(y,Bt)|0,l=l+Math.imul(d,St)|0,G=G+Math.imul(d,Bt)|0,P=P+Math.imul(u,Pt)|0,l=l+Math.imul(u,Dt)|0,l=l+Math.imul(B,Pt)|0,G=G+Math.imul(B,Dt)|0,P=P+Math.imul(z,Ut)|0,l=l+Math.imul(z,Gt)|0,l=l+Math.imul(O,Ut)|0,G=G+Math.imul(O,Gt)|0,P=P+Math.imul(b,Ft)|0,l=l+Math.imul(b,At)|0,l=l+Math.imul(w,Ft)|0,G=G+Math.imul(w,At)|0,P=P+Math.imul(Z,Lt)|0,l=l+Math.imul(Z,zt)|0,l=l+Math.imul(U,Lt)|0,G=G+Math.imul(U,zt)|0,P=P+Math.imul(yt,Rt)|0,l=l+Math.imul(yt,mt)|0,l=l+Math.imul(pt,Rt)|0,G=G+Math.imul(pt,mt)|0,P=P+Math.imul(at,Ot)|0,l=l+Math.imul(at,Vt)|0,l=l+Math.imul(st,Ot)|0,G=G+Math.imul(st,Vt)|0;var Wr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,P=Math.imul(nt,wt),l=Math.imul(nt,gt),l=l+Math.imul(it,wt)|0,G=Math.imul(it,gt),P=P+Math.imul(K,Mt)|0,l=l+Math.imul(K,bt)|0,l=l+Math.imul(j,Mt)|0,G=G+Math.imul(j,bt)|0,P=P+Math.imul(L,St)|0,l=l+Math.imul(L,Bt)|0,l=l+Math.imul(A,St)|0,G=G+Math.imul(A,Bt)|0,P=P+Math.imul(y,Pt)|0,l=l+Math.imul(y,Dt)|0,l=l+Math.imul(d,Pt)|0,G=G+Math.imul(d,Dt)|0,P=P+Math.imul(u,Ut)|0,l=l+Math.imul(u,Gt)|0,l=l+Math.imul(B,Ut)|0,G=G+Math.imul(B,Gt)|0,P=P+Math.imul(z,Ft)|0,l=l+Math.imul(z,At)|0,l=l+Math.imul(O,Ft)|0,G=G+Math.imul(O,At)|0,P=P+Math.imul(b,Lt)|0,l=l+Math.imul(b,zt)|0,l=l+Math.imul(w,Lt)|0,G=G+Math.imul(w,zt)|0,P=P+Math.imul(Z,Rt)|0,l=l+Math.imul(Z,mt)|0,l=l+Math.imul(U,Rt)|0,G=G+Math.imul(U,mt)|0,P=P+Math.imul(yt,Ot)|0,l=l+Math.imul(yt,Vt)|0,l=l+Math.imul(pt,Ot)|0,G=G+Math.imul(pt,Vt)|0;var Qr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,P=Math.imul(nt,Mt),l=Math.imul(nt,bt),l=l+Math.imul(it,Mt)|0,G=Math.imul(it,bt),P=P+Math.imul(K,St)|0,l=l+Math.imul(K,Bt)|0,l=l+Math.imul(j,St)|0,G=G+Math.imul(j,Bt)|0,P=P+Math.imul(L,Pt)|0,l=l+Math.imul(L,Dt)|0,l=l+Math.imul(A,Pt)|0,G=G+Math.imul(A,Dt)|0,P=P+Math.imul(y,Ut)|0,l=l+Math.imul(y,Gt)|0,l=l+Math.imul(d,Ut)|0,G=G+Math.imul(d,Gt)|0,P=P+Math.imul(u,Ft)|0,l=l+Math.imul(u,At)|0,l=l+Math.imul(B,Ft)|0,G=G+Math.imul(B,At)|0,P=P+Math.imul(z,Lt)|0,l=l+Math.imul(z,zt)|0,l=l+Math.imul(O,Lt)|0,G=G+Math.imul(O,zt)|0,P=P+Math.imul(b,Rt)|0,l=l+Math.imul(b,mt)|0,l=l+Math.imul(w,Rt)|0,G=G+Math.imul(w,mt)|0,P=P+Math.imul(Z,Ot)|0,l=l+Math.imul(Z,Vt)|0,l=l+Math.imul(U,Ot)|0,G=G+Math.imul(U,Vt)|0;var Kr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,P=Math.imul(nt,St),l=Math.imul(nt,Bt),l=l+Math.imul(it,St)|0,G=Math.imul(it,Bt),P=P+Math.imul(K,Pt)|0,l=l+Math.imul(K,Dt)|0,l=l+Math.imul(j,Pt)|0,G=G+Math.imul(j,Dt)|0,P=P+Math.imul(L,Ut)|0,l=l+Math.imul(L,Gt)|0,l=l+Math.imul(A,Ut)|0,G=G+Math.imul(A,Gt)|0,P=P+Math.imul(y,Ft)|0,l=l+Math.imul(y,At)|0,l=l+Math.imul(d,Ft)|0,G=G+Math.imul(d,At)|0,P=P+Math.imul(u,Lt)|0,l=l+Math.imul(u,zt)|0,l=l+Math.imul(B,Lt)|0,G=G+Math.imul(B,zt)|0,P=P+Math.imul(z,Rt)|0,l=l+Math.imul(z,mt)|0,l=l+Math.imul(O,Rt)|0,G=G+Math.imul(O,mt)|0,P=P+Math.imul(b,Ot)|0,l=l+Math.imul(b,Vt)|0,l=l+Math.imul(w,Ot)|0,G=G+Math.imul(w,Vt)|0;var Jr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,P=Math.imul(nt,Pt),l=Math.imul(nt,Dt),l=l+Math.imul(it,Pt)|0,G=Math.imul(it,Dt),P=P+Math.imul(K,Ut)|0,l=l+Math.imul(K,Gt)|0,l=l+Math.imul(j,Ut)|0,G=G+Math.imul(j,Gt)|0,P=P+Math.imul(L,Ft)|0,l=l+Math.imul(L,At)|0,l=l+Math.imul(A,Ft)|0,G=G+Math.imul(A,At)|0,P=P+Math.imul(y,Lt)|0,l=l+Math.imul(y,zt)|0,l=l+Math.imul(d,Lt)|0,G=G+Math.imul(d,zt)|0,P=P+Math.imul(u,Rt)|0,l=l+Math.imul(u,mt)|0,l=l+Math.imul(B,Rt)|0,G=G+Math.imul(B,mt)|0,P=P+Math.imul(z,Ot)|0,l=l+Math.imul(z,Vt)|0,l=l+Math.imul(O,Ot)|0,G=G+Math.imul(O,Vt)|0;var jr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(jr>>>26)|0,jr&=67108863,P=Math.imul(nt,Ut),l=Math.imul(nt,Gt),l=l+Math.imul(it,Ut)|0,G=Math.imul(it,Gt),P=P+Math.imul(K,Ft)|0,l=l+Math.imul(K,At)|0,l=l+Math.imul(j,Ft)|0,G=G+Math.imul(j,At)|0,P=P+Math.imul(L,Lt)|0,l=l+Math.imul(L,zt)|0,l=l+Math.imul(A,Lt)|0,G=G+Math.imul(A,zt)|0,P=P+Math.imul(y,Rt)|0,l=l+Math.imul(y,mt)|0,l=l+Math.imul(d,Rt)|0,G=G+Math.imul(d,mt)|0,P=P+Math.imul(u,Ot)|0,l=l+Math.imul(u,Vt)|0,l=l+Math.imul(B,Ot)|0,G=G+Math.imul(B,Vt)|0;var tn=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(tn>>>26)|0,tn&=67108863,P=Math.imul(nt,Ft),l=Math.imul(nt,At),l=l+Math.imul(it,Ft)|0,G=Math.imul(it,At),P=P+Math.imul(K,Lt)|0,l=l+Math.imul(K,zt)|0,l=l+Math.imul(j,Lt)|0,G=G+Math.imul(j,zt)|0,P=P+Math.imul(L,Rt)|0,l=l+Math.imul(L,mt)|0,l=l+Math.imul(A,Rt)|0,G=G+Math.imul(A,mt)|0,P=P+Math.imul(y,Ot)|0,l=l+Math.imul(y,Vt)|0,l=l+Math.imul(d,Ot)|0,G=G+Math.imul(d,Vt)|0;var en=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(en>>>26)|0,en&=67108863,P=Math.imul(nt,Lt),l=Math.imul(nt,zt),l=l+Math.imul(it,Lt)|0,G=Math.imul(it,zt),P=P+Math.imul(K,Rt)|0,l=l+Math.imul(K,mt)|0,l=l+Math.imul(j,Rt)|0,G=G+Math.imul(j,mt)|0,P=P+Math.imul(L,Ot)|0,l=l+Math.imul(L,Vt)|0,l=l+Math.imul(A,Ot)|0,G=G+Math.imul(A,Vt)|0;var rn=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(rn>>>26)|0,rn&=67108863,P=Math.imul(nt,Rt),l=Math.imul(nt,mt),l=l+Math.imul(it,Rt)|0,G=Math.imul(it,mt),P=P+Math.imul(K,Ot)|0,l=l+Math.imul(K,Vt)|0,l=l+Math.imul(j,Ot)|0,G=G+Math.imul(j,Vt)|0;var nn=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(nn>>>26)|0,nn&=67108863,P=Math.imul(nt,Ot),l=Math.imul(nt,Vt),l=l+Math.imul(it,Ot)|0,G=Math.imul(it,Vt);var on=(R+P|0)+((l&8191)<<13)|0;return R=(G+(l>>>13)|0)+(on>>>26)|0,on&=67108863,E[0]=Ee,E[1]=Le,E[2]=ze,E[3]=Ht,E[4]=Yr,E[5]=Xr,E[6]=Hr,E[7]=Zr,E[8]=$r,E[9]=Wr,E[10]=Qr,E[11]=Kr,E[12]=Jr,E[13]=jr,E[14]=tn,E[15]=en,E[16]=rn,E[17]=nn,E[18]=on,R!==0&&(E[19]=R,T.length++),T};Math.imul||(m=q);function C(D,a,v){v.negative=a.negative^D.negative,v.length=D.length+a.length;for(var T=0,M=0,S=0;S<v.length-1;S++){var E=M;M=0;for(var R=T&67108863,P=Math.min(S,a.length-1),l=Math.max(0,S-D.length+1);l<=P;l++){var G=S-l,ot=D.words[G]|0,at=a.words[l]|0,st=ot*at,ct=st&67108863;E=E+(st/67108864|0)|0,ct=ct+R|0,R=ct&67108863,E=E+(ct>>>26)|0,M+=E>>>26,E&=67108863}v.words[S]=R,T=E,E=M}return T!==0?v.words[S]=T:v.length--,v.strip()}function Y(D,a,v){var T=new H;return T.mulp(D,a,v)}i.prototype.mulTo=function(a,v){var T,M=this.length+a.length;return this.length===10&&a.length===10?T=m(this,a,v):M<63?T=q(this,a,v):M<1024?T=C(this,a,v):T=Y(this,a,v),T};function H(D,a){this.x=D,this.y=a}H.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},H.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},H.prototype.permute=function(a,v,T,M,S,E){for(var R=0;R<E;R++)M[R]=v[a[R]],S[R]=T[a[R]]},H.prototype.transform=function(a,v,T,M,S,E){this.permute(E,a,v,T,M,S);for(var R=1;R<S;R<<=1)for(var P=R<<1,l=Math.cos(2*Math.PI/P),G=Math.sin(2*Math.PI/P),ot=0;ot<S;ot+=P)for(var at=l,st=G,ct=0;ct<R;ct++){var yt=T[ot+ct],pt=M[ot+ct],k=T[ot+ct+R],Z=M[ot+ct+R],U=at*k-st*Z;Z=at*Z+st*k,k=U,T[ot+ct]=yt+k,M[ot+ct]=pt+Z,T[ot+ct+R]=yt-k,M[ot+ct+R]=pt-Z,ct!==P&&(U=l*at-G*st,st=l*st+G*at,at=U)}},H.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},H.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}},H.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},H.prototype.convert13b=function(a,v,T,M){for(var S=0,E=0;E<v;E++)S=S+(a[E]|0),T[2*E]=S&8191,S=S>>>13,T[2*E+1]=S&8191,S=S>>>13;for(E=2*v;E<M;++E)T[E]=0;n(S===0),n((S&-8192)===0)},H.prototype.stub=function(a){for(var v=new Array(a),T=0;T<a;T++)v[T]=0;return v},H.prototype.mulp=function(a,v,T){var M=2*this.guessLen13b(a.length,v.length),S=this.makeRBT(M),E=this.stub(M),R=new Array(M),P=new Array(M),l=new Array(M),G=new Array(M),ot=new Array(M),at=new Array(M),st=T.words;st.length=M,this.convert13b(a.words,a.length,R,M),this.convert13b(v.words,v.length,G,M),this.transform(R,E,P,l,M,S),this.transform(G,E,ot,at,M,S);for(var ct=0;ct<M;ct++){var yt=P[ct]*ot[ct]-l[ct]*at[ct];l[ct]=P[ct]*at[ct]+l[ct]*ot[ct],P[ct]=yt}return this.conjugate(P,l,M),this.transform(P,l,st,E,M,S),this.conjugate(st,E,M),this.normalize13b(st,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),Y(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=N(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 E=0;for(S=0;S<this.length;S++){var R=this.words[S]&M,P=(this.words[S]|0)-R<<v;this.words[S]=P|E,E=R>>>26-v}E&&(this.words[S]=E,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,E=Math.min((a-S)/26,this.length),R=67108863^67108863>>>S<<S,P=T;if(M-=E,M=Math.max(0,M),P){for(var l=0;l<E;l++)P.words[l]=this.words[l];P.length=E}if(E!==0)if(this.length>E)for(this.length-=E,l=0;l<this.length;l++)this.words[l]=this.words[l+E];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&R}return P&&G!==0&&(P.words[P.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 E,R=0;for(S=0;S<a.length;S++){E=(this.words[S+T]|0)+R;var P=(a.words[S]|0)*v;E-=P&67108863,R=(E>>26)-(P/67108864|0),this.words[S+T]=E&67108863}for(;S<this.length-T;S++)E=(this.words[S+T]|0)+R,R=E>>26,this.words[S+T]=E&67108863;if(R===0)return this.strip();for(n(R===-1),R=0,S=0;S<this.length;S++)E=-(this.words[S]|0)+R,R=E>>26,this.words[S]=E&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(a,v){var T=this.length-a.length,M=this.clone(),S=a,E=S.words[S.length-1]|0,R=this._countBits(E);T=26-R,T!==0&&(S=S.ushln(T),M.iushln(T),E=S.words[S.length-1]|0);var P=M.length-S.length,l;if(v!=="mod"){l=new i(null),l.length=P+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,P);ot.negative===0&&(M=ot,l&&(l.words[P]=1));for(var at=P-1;at>=0;at--){var st=(M.words[S.length+at]|0)*67108864+(M.words[S.length+at-1]|0);for(st=Math.min(st/E|0,67108863),M._ishlnsubmul(S,st,at);M.negative!==0;)st--,M.negative=0,M._ishlnsubmul(S,1,at),M.isZero()||(M.negative^=1);l&&(l.words[at]=st)}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,E;return this.negative!==0&&a.negative===0?(E=this.neg().divmod(a,v),v!=="mod"&&(M=E.div.neg()),v!=="div"&&(S=E.mod.neg(),T&&S.negative!==0&&S.iadd(a)),{div:M,mod:S}):this.negative===0&&a.negative!==0?(E=this.divmod(a.neg(),v),v!=="mod"&&(M=E.div.neg()),{div:M,mod:E.mod}):(this.negative&a.negative)!==0?(E=this.neg().divmod(a.neg(),v),v!=="div"&&(S=E.mod.neg(),T&&S.negative!==0&&S.isub(a)),{div:E.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),E=T.cmp(M);return E<0||S===1&&E===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),E=new i(0),R=new i(1),P=0;v.isEven()&&T.isEven();)v.iushrn(1),T.iushrn(1),++P;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 st=0,ct=1;(T.words[0]&ct)===0&&st<26;++st,ct<<=1);if(st>0)for(T.iushrn(st);st-- >0;)(E.isOdd()||R.isOdd())&&(E.iadd(l),R.isub(G)),E.iushrn(1),R.iushrn(1);v.cmp(T)>=0?(v.isub(T),M.isub(E),S.isub(R)):(T.isub(v),E.isub(M),R.isub(S))}return{a:E,b:R,gcd:T.iushln(P)}},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),E=T.clone();v.cmpn(1)>0&&T.cmpn(1)>0;){for(var R=0,P=1;(v.words[0]&P)===0&&R<26;++R,P<<=1);if(R>0)for(v.iushrn(R);R-- >0;)M.isOdd()&&M.iadd(E),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(E),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 E=v;v=T,T=E}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,E=T;S!==0&&E<this.length;E++){var R=this.words[E]|0;R+=S,S=R>>>26,R&=67108863,this.words[E]=R}return S!==0&&(this.words[E]=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 tt(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 W={k256:null,p224:null,p192:null,p25519:null};function Q(D,a){this.name=D,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 et(){Q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(et,Q),et.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 E=a.words[9];for(v.words[v.length++]=E&T,S=10;S<a.length;S++){var R=a.words[S]|0;a.words[S-10]=(R&T)<<4|E>>>22,E=R}E>>>=22,a.words[S-10]=E,E===0&&a.length>10?a.length-=10:a.length-=9},et.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 $(){Q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r($,Q);function J(){Q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(J,Q);function ut(){Q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(ut,Q),ut.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(W[a])return W[a];var v;if(a==="k256")v=new et;else if(a==="p224")v=new $;else if(a==="p192")v=new J;else if(a==="p25519")v=new ut;else throw new Error("Unknown prime "+a);return W[a]=v,v};function tt(D){if(typeof D=="string"){var a=i._prime(D);this.m=a.p,this.prime=a}else n(D.gtn(1),"modulus must be greater than 1"),this.m=D,this.prime=null}tt.prototype._verify1=function(a){n(a.negative===0,"red works only with positives"),n(a.red,"red works only with red numbers")},tt.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")},tt.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):a.umod(this.m)._forceRed(this)},tt.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},tt.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)},tt.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},tt.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)},tt.prototype.isub=function(a,v){this._verify2(a,v);var T=a.isub(v);return T.cmpn(0)<0&&T.iadd(this.m),T},tt.prototype.shl=function(a,v){return this._verify1(a),this.imod(a.ushln(v))},tt.prototype.imul=function(a,v){return this._verify2(a,v),this.imod(a.imul(v))},tt.prototype.mul=function(a,v){return this._verify2(a,v),this.imod(a.mul(v))},tt.prototype.isqr=function(a){return this.imul(a,a.clone())},tt.prototype.sqr=function(a){return this.mul(a,a)},tt.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 E=new i(1).toRed(this),R=E.redNeg(),P=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new i(2*l*l).toRed(this);this.pow(l,P).cmp(R)!==0;)l.redIAdd(R);for(var G=this.pow(l,M),ot=this.pow(a,M.addn(1).iushrn(1)),at=this.pow(a,M),st=S;at.cmp(E)!==0;){for(var ct=at,yt=0;ct.cmp(E)!==0;yt++)ct=ct.redSqr();n(yt<st);var pt=this.pow(G,new i(1).iushln(st-yt-1));ot=ot.redMul(pt),G=pt.redSqr(),at=at.redMul(G),st=yt}return ot},tt.prototype.invm=function(a){var v=a._invmp(this.m);return v.negative!==0?(v.negative=0,this.imod(v).redNeg()):this.imod(v)},tt.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 E=M[0],R=0,P=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(E!==M[0]&&(E=this.sqr(E)),at===0&&R===0){P=0;continue}R<<=1,R|=at,P++,!(P!==T&&(S!==0||ot!==0))&&(E=this.mul(E,M[R]),P=0,R=0)}l=26}return E},tt.prototype.convertTo=function(a){var v=a.umod(this.m);return v===a?v.clone():v},tt.prototype.convertFrom=function(a){var v=a.clone();return v.red=null,v},i.mont=function(a){return new rt(a)};function rt(D){tt.call(this,D),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,tt),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),E=S;return S.cmp(this.m)>=0?E=S.isub(this.m):S.cmpn(0)<0&&(E=S.iadd(this.m)),E._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),E=S;return S.cmp(this.m)>=0?E=S.isub(this.m):S.cmpn(0)<0&&(E=S.iadd(this.m)),E._forceRed(this)},rt.prototype.invm=function(a){var v=this.imod(a._invmp(this.m).mul(this.r2));return v._forceRed(this)}})(typeof qn>"u"||qn,na)});var Nn=xt((z1,ia)=>{"use strict";var L1=or();ia.exports=wc;function wc(e){return e&&typeof e=="object"&&!!e.words}});var sa=xt((R1,aa)=>{"use strict";var oa=Nn();aa.exports=xc;function xc(e){return Array.isArray(e)&&e.length===2&&oa(e[0])&&oa(e[1])}});var Ir=xt((m1,Ct)=>{var Cn=!1;if(typeof Float64Array<"u")if(fe=new Float64Array(1),re=new Uint32Array(fe.buffer),fe[0]=1,Cn=!0,re[1]===1072693248){let e=function(r,i){return re[0]=r,re[1]=i,fe[0]},t=function(r){return fe[0]=r,re[0]},n=function(r){return fe[0]=r,re[1]};yc=e,Mc=t,bc=n,Ct.exports=function(i){return fe[0]=i,[re[0],re[1]]},Ct.exports.pack=e,Ct.exports.lo=t,Ct.exports.hi=n}else if(re[0]===1072693248){let e=function(r,i){return re[1]=r,re[0]=i,fe[0]},t=function(r){return fe[0]=r,re[1]},n=function(r){return fe[0]=r,re[0]};Tc=e,_c=t,Sc=n,Ct.exports=function(i){return fe[0]=i,[re[1],re[0]]},Ct.exports.pack=e,Ct.exports.lo=t,Ct.exports.hi=n}else Cn=!1;var fe,re,yc,Mc,bc,Tc,_c,Sc;if(!Cn){let e=function(r,i){return le.writeUInt32LE(r,0,!0),le.writeUInt32LE(i,4,!0),le.readDoubleLE(0,!0)},t=function(r){return le.writeDoubleLE(r,0,!0),le.readUInt32LE(0,!0)},n=function(r){return le.writeDoubleLE(r,0,!0),le.readUInt32LE(4,!0)};Bc=e,Pc=t,Dc=n,le=new Buffer(8),Ct.exports=function(i){return le.writeDoubleLE(i,0,!0),[le.readUInt32LE(0,!0),le.readUInt32LE(4,!0)]},Ct.exports.pack=e,Ct.exports.lo=t,Ct.exports.hi=n}var le,Bc,Pc,Dc;Ct.exports.sign=function(e){return Ct.exports.hi(e)>>>31};Ct.exports.exponent=function(e){var t=Ct.exports.hi(e);return(t<<1>>>21)-1023};Ct.exports.fraction=function(e){var t=Ct.exports.lo(e),n=Ct.exports.hi(e),r=n&(1<<20)-1;return n&2146435072&&(r+=1<<20),[t,r]};Ct.exports.denormalized=function(e){var t=Ct.exports.hi(e);return!(t&2146435072)}});var kn=xt((O1,ca)=>{"use strict";var ua=or(),Uc=Ir();ca.exports=Gc;function Gc(e){var t=Uc.exponent(e);return t<52?new ua(e):new ua(e*Math.pow(2,52-t)).ushln(t-52)}});var la=xt((V1,fa)=>{"use strict";var Fc=or();fa.exports=Ac;function Ac(e){return new Fc(e)}});var Er=xt((q1,ha)=>{"use strict";var Ic=or();ha.exports=Ec;function Ec(e){return e.cmp(new Ic(0))}});var Xe=xt((N1,va)=>{"use strict";var Lr=kn(),pa=Er();va.exports=Lc;function Lc(e,t){var n=pa(e),r=pa(t);if(n===0)return[Lr(0),Lr(1)];if(r===0)return[Lr(0),Lr(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 Yn=xt((C1,da)=>{"use strict";var zc=Xe();da.exports=Rc;function Rc(e,t){return zc(e[0].mul(t[1]),e[1].mul(t[0]))}});var zr=xt((k1,Ma)=>{"use strict";var ga=sa(),wa=Nn(),Ae=kn(),xa=la(),mc=Xe(),Oc=Yn();Ma.exports=ya;function ya(e,t){if(ga(e))return t?Oc(e,ya(t)):[e[0].clone(),e[1].clone()];var n=0,r,i;if(wa(e))r=e.clone();else if(typeof e=="string")r=xa(e);else{if(e===0)return[Ae(0),Ae(1)];if(e===Math.floor(e))r=Ae(e);else{for(;e!==Math.floor(e);)e=e*Math.pow(2,256),n-=256;r=Ae(e)}}if(ga(t))r.mul(t[1]),i=t[0].clone();else if(wa(t))i=t.clone();else if(typeof t=="string")i=xa(t);else if(!t)i=Ae(1);else if(t===Math.floor(t))i=Ae(t);else{for(;t!==Math.floor(t);)t=t*Math.pow(2,256),n+=256;i=Ae(t)}return n>0?r=r.ushln(n):n<0&&(i=i.ushln(-n)),mc(r,i)}});var Ta=xt((Y1,ba)=>{"use strict";ba.exports=Vc;function Vc(e,t){return e[0].mul(t[1]).cmp(t[0].mul(e[1]))}});var Sa=xt((X1,_a)=>{"use strict";var qc=Er();_a.exports=Nc;function Nc(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 qc(e)*r}});var Ua=xt((H1,Da)=>{"use strict";var Ba=Ir(),Pa=je().countTrailingZeros;Da.exports=Cc;function Cc(e){var t=Pa(Ba.lo(e));if(t<32)return t;var n=Pa(Ba.hi(e));return n>20?52:n+32}});var Fa=xt((Z1,Ga)=>{"use strict";var Xn=Sa(),kc=Ua();Ga.exports=Yc;function Yc(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=Xn(i),s=r.mod,c=t.negative!==n.negative?-1:1;if(s.cmpn(0)===0)return c*o;if(o){var h=kc(o)+4,p=Xn(s.ushln(h).divRound(n));return c*(o+p*Math.pow(2,-h))}else{var g=n.bitLength()-s.bitLength()+53,p=Xn(s.ushln(g).divRound(n));return g<1023?c*p*Math.pow(2,-g):(p*=Math.pow(2,-1023),c*p*Math.pow(2,1023-g))}}});var Ia=xt(($1,Aa)=>{"use strict";Aa.exports=Hc;var Xc=zr();function Hc(e){for(var t=new Array(e.length),n=0;n<e.length;++n)t[n]=Xc(e[n]);return t}});var Ra=xt((W1,za)=>{"use strict";var Hn=Ir(),Ea=Math.pow(2,-1074),La=-1>>>0;za.exports=Zc;function Zc(e,t){if(isNaN(e)||isNaN(t))return NaN;if(e===t)return e;if(e===0)return t<0?-Ea:Ea;var n=Hn.hi(e),r=Hn.lo(e);return t>e==e>0?r===La?(n+=1,r=0):r+=1:r===0?(r=La,n-=1):r-=1,Hn.pack(r,n)}});var Zn=xt((Q1,ma)=>{"use strict";var $c=Xe();ma.exports=Wc;function Wc(e,t){return $c(e[0].mul(t[0]),e[1].mul(t[1]))}});var $n=xt((K1,Oa)=>{"use strict";var Qc=Xe();Oa.exports=Kc;function Kc(e,t){return Qc(e[0].mul(t[1]).sub(e[1].mul(t[0])),e[1].mul(t[1]))}});var Na=xt((J1,qa)=>{"use strict";var Va=Er();qa.exports=Jc;function Jc(e){return Va(e[0])*Va(e[1])}});var ka=xt((j1,Ca)=>{"use strict";var jc=$n();Ca.exports=tf;function tf(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=jc(e[i],t[i]);return r}});var Xa=xt((th,Ya)=>{"use strict";var ef=Xe();Ya.exports=rf;function rf(e,t){return ef(e[0].mul(t[1]).add(t[0].mul(e[1])),e[1].mul(t[1]))}});var Za=xt((eh,Ha)=>{"use strict";var nf=Xa();Ha.exports=of;function of(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=nf(e[i],t[i]);return r}});var Wa=xt((rh,$a)=>{"use strict";var af=zr(),sf=Zn();$a.exports=uf;function uf(e,t){for(var n=af(t),r=e.length,i=new Array(r),o=0;o<r;++o)i[o]=sf(e[o],n);return i}});var ja=xt((nh,Ja)=>{"use strict";Ja.exports=vf;var Qa=Zn(),cf=Yn(),ff=$n(),lf=Na(),Wn=ka(),hf=Za(),pf=Wa();function Ka(e,t){return ff(Qa(e[0],t[1]),Qa(e[1],t[0]))}function vf(e,t,n,r){var i=Wn(t,e),o=Wn(r,n),s=Ka(i,o);if(lf(s)===0)return null;var c=Wn(e,n),h=Ka(o,c),p=cf(h,s),g=pf(i,p),F=hf(e,g);return F}});var us=xt((ih,ss)=>{"use strict";ss.exports=Bf;var df=fo(),Kn=jo(),ns=ea(),ts=zr(),es=Ta(),Qn=Fa(),Rr=Ia(),oe=Ra(),gf=ja();function rs(e){var t=Qn(e);return[oe(t,-1/0),oe(t,1/0)]}function wf(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 is(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 xf(e,t,n){var r=[];return Kn(n,function(i,o){var s=t[i],c=t[o];if(!(s[0]===c[0]||s[0]===c[1]||s[1]===c[0]||s[1]===c[1])){var h=e[s[0]],p=e[s[1]],g=e[c[0]],F=e[c[1]];ns(h,p,g,F)&&r.push([i,o])}}),r}function yf(e,t,n,r){var i=[];return Kn(n,r,function(o,s){var c=t[o];if(!(c[0]===s||c[1]===s)){var h=e[s],p=e[c[0]],g=e[c[1]];ns(p,g,h,h)&&i.push([o,s])}}),i}function Mf(e,t,n,r,i){var o,s,c=e.map(function(tt){return[ts(tt[0]),ts(tt[1])]});for(o=0;o<n.length;++o){var h=n[o];s=h[0];var p=h[1],g=t[s],F=t[p],N=gf(Rr(e[g[0]]),Rr(e[g[1]]),Rr(e[F[0]]),Rr(e[F[1]]));if(N){var q=e.length;e.push([Qn(N[0]),Qn(N[1])]),c.push(N),r.push([s,q],[p,q])}}for(r.sort(function(tt,rt){if(tt[0]!==rt[0])return tt[0]-rt[0];var D=c[tt[1]],a=c[rt[1]];return es(D[0],a[0])||es(D[1],a[1])}),o=r.length-1;o>=0;--o){var m=r[o];s=m[0];var C=t[s],Y=C[0],H=C[1],W=e[Y],Q=e[H];if((W[0]-Q[0]||W[1]-Q[1])<0){var et=Y;Y=H,H=et}C[0]=Y;var $=C[1]=m[1],J;for(i&&(J=C[2]);o>0&&r[o-1][0]===s;){var m=r[--o],ut=m[1];i?t.push([$,ut,J]):t.push([$,ut]),$=ut}i?t.push([$,H,J]):t.push([$,H])}return c}function os(e,t,n){for(var r=t.length,i=new df(r),o=[],s=0;s<t.length;++s){var c=t[s],h=rs(c[0]),p=rs(c[1]);o.push([oe(h[0],-1/0),oe(p[0],-1/0),oe(h[1],1/0),oe(p[1],1/0)])}Kn(o,function(m,C){i.link(m,C)});for(var g=!0,F=new Array(r),s=0;s<r;++s){var N=i.find(s);N!==s&&(g=!1,e[N]=[Math.min(e[s][0],e[N][0]),Math.min(e[s][1],e[N][1])])}if(g)return null;for(var q=0,s=0;s<r;++s){var N=i.find(s);N===s?(F[s]=q,e[q++]=e[s]):F[s]=-1}e.length=q;for(var s=0;s<r;++s)F[s]<0&&(F[s]=F[i.find(s)]);return F}function bf(e,t){return e[0]-t[0]||e[1]-t[1]}function Tf(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 as(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(Tf):e.sort(bf);for(var c=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[c++]=p)}e.length=c}}function _f(e,t,n){var r=os(e,[],is(e));return as(t,r,n),!!r}function Sf(e,t,n){var r=wf(e,t),i=xf(e,t,r),o=is(e),s=yf(e,t,r,o),c=Mf(e,t,i,s,n),h=os(e,c,o);return as(t,h,n),h?!0:i.length>0||s.length>0}function Bf(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 c=_f(e,t,!!n);Sf(e,t,!!n);)c=!0;if(n&&c){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 c}});function ne(e,t,n,r,i,o,s){let c=e.createTexture({label:t,size:{width:n,height:r},format:o,usage:s,mipLevelCount:i,sampleCount:1,dimension:"2d"}),h=c.createView(),p=[];for(let F=0;F<i;F++)p.push(c.createView({label:t,format:o,dimension:"2d",aspect:"all",baseMipLevel:F,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:c,view:h,mip_view:p,sampler:g}}async function he(e,t,n,r="rgba8unorm"){let o=await(await fetch(n)).blob(),s=await createImageBitmap(o),c=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,p=ne(e.device,t,s.width,s.height,1,r,c);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}function He(e,t,n,r="rgba8unorm"){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 c={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return s.sampler=e.device.createSampler(c),s}var ii="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,Fs=0,oi=1,As=2,ai=3,si={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 Is(e,t)},onRun:function(e,t,n){Es(e,t.data,n)},onDestroy:function(e,t){ci(t)},onResize:function(e,t){Ls(e,t)},onViewportPosition:function(e,t){}};function Is(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:[]},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 c=n.createPipelineLayout({bindGroupLayouts:o.bind_group_layout}),h=n.createComputePipeline({layout:c,compute:{module:n.createShaderModule({code:ii}),entryPoint:"cs_main"}});return ui(e,o,t),o.compute_pipeline=h,o}function ui(e,t,n){let{refs:r}=n,{device:i}=e,o=n.options.bloom_threshold??.1,s=n.options.bloom_knee??.2,c=n.options.bloom_combine_constant??.68,h=new Float32Array([o,o-s,s*2,.25/s,c,0,0,0]),p=i.createBuffer({label:"bloom static parameters buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});new Float32Array(p.getMappedRange()).set(h),p.unmap(),t.bind_group.length=0,t.params_buf=p,t.bind_group.push(Re(i,t,t.bind_groups_textures[0].mip_view[0],r.emissive.data.view,r.hdr.data.view,r.hdr.data.sampler,p,Fs<<16|0));for(let F=1;F<ue;F++)t.bind_group.push(Re(i,t,t.bind_groups_textures[1].mip_view[F],t.bind_groups_textures[0].view,r.hdr.data.view,r.hdr.data.sampler,p,oi<<16|F-1)),t.bind_group.push(Re(i,t,t.bind_groups_textures[0].mip_view[F],t.bind_groups_textures[1].view,r.hdr.data.view,r.hdr.data.sampler,p,oi<<16|F));t.bind_group.push(Re(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,As<<16|ue-2));let g=!0;for(let F=ue-2;F>=0;F--)g?(t.bind_group.push(Re(i,t,t.bind_groups_textures[1].mip_view[F],t.bind_groups_textures[0].view,t.bind_groups_textures[2].view,r.hdr.data.sampler,p,ai<<16|F)),g=!1):(t.bind_group.push(Re(i,t,t.bind_groups_textures[2].mip_view[F],t.bind_groups_textures[0].view,t.bind_groups_textures[1].view,r.hdr.data.sampler,p,ai<<16|F)),g=!0)}function Re(e,t,n,r,i,o,s,c){let h=new Uint32Array([c]),p=e.createBuffer({label:"bloom static mode_lod buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});return 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 Es(e,t,n){let c=0,h=n.beginComputePass({label:"bloom Compute Pass"});h.setPipeline(t.compute_pipeline),h.setBindGroup(0,t.bind_group[c]),c+=1;let p=ar(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=ar(g,t.bind_groups_textures[0]),h.setBindGroup(0,t.bind_group[c]),c+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1),h.setBindGroup(0,t.bind_group[c]),c+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.setBindGroup(0,t.bind_group[c]),c+=1,p=ar(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=ar(g,t.bind_groups_textures[2]),h.setBindGroup(0,t.bind_group[c]),c+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.end()}function ar(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 Ls(e,t){let{device:n}=e,r=t.data;ci(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),ui(e,r,t)}function ci(e){for(let t of e.bind_groups_textures)t.texture.destroy();e.bind_groups_textures.length=0}var sn="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 fi={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:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return zs(e,t)},onRun:function(e,t,n){Rs(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){ms(e,t)},onViewportPosition:function(e,t){}};function zs(e,t){let{options:n,refs:r}=t,{device:i}=e,o=li(e),s=n.bloom_intensity??40,c=n.bloom_combine_constant??.68,h=new Float32Array([s,c]),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({layout:"auto",vertex:{module:i.createShaderModule({code:sn}),entryPoint:"vert_main"},fragment:{module:i.createShaderModule({code:sn}),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 Rs(e,t,n){let r=n.beginRenderPass({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 ms(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 $e={};ri($e,{addSprite:()=>Vs,clear:()=>Ns,removeSprite:()=>qs,setSprite:()=>$s,setSpriteName:()=>Cs,setSpriteOpacity:()=>Xs,setSpritePosition:()=>ks,setSpriteRotation:()=>Hs,setSpriteScale:()=>Zs,setSpriteTint:()=>Ys});function un(e,t,n){if(n.spriteCount===0)return 0;let r=0,i=n.spriteCount-1,o=e<<16&16711680|t&65535;for(;r<=i;){let s=n.spriteData[r*12+11];if(o<=s)return r;let c=n.spriteData[i*12+11];if(o>=c)return i+1;let h=Math.floor((r+i)/2),p=n.spriteData[h*12+11];if(o===p)return h+1;o>p?r=h+1:i=h-1}return r}function Ze(){return Math.ceil(Math.random()*(Number.MAX_SAFE_INTEGER-10))}function Vs(e,t,n,r,i,o,s,c,h){let p=t.refs.spritesheet.data.spritesheet;t=t.data;let g=p.locations.indexOf(n),F=un(h,g,t),N=(F+1)*12;t.spriteData.set(t.spriteData.subarray(F*12,t.spriteCount*12),N),hi(t,p,F,n,r,i,o,s,c,h);for(let[m,C]of t.spriteIndices)C>=F&&t.spriteIndices.set(m,C+1);let q=Ze();return t.spriteIndices.set(q,F),t.spriteCount++,t.dirty=!0,q}function qs(e,t,n){t=t.data;let r=t.spriteIndices.get(n);for(let[o,s]of t.spriteIndices)s>r&&t.spriteIndices.set(o,s-1);let i=r*12;t.spriteData.set(t.spriteData.subarray((r+1)*12,t.spriteCount*12),i),t.spriteIndices.delete(n),t.spriteCount--,t.dirty=!0}function Ns(e,t){t=t.data,t.spriteIndices.clear(),t.spriteCount=0,t.instancedDrawCallCount=0,t.dirty=!0}function Cs(e,t,n,r,i){let o=t.refs.spritesheet.data.spritesheet;t=t.data;let s=o.locations.indexOf(r),c=o.spriteMeta[r].w,h=o.spriteMeta[r].h,g=t.spriteIndices.get(n)*12;t.spriteData[g+2]=c*i[0],t.spriteData[g+3]=h*i[1];let N=(t.spriteData[g+11]>>16&255)<<16&16711680|s&65535;t.spriteData[g+11]=N,t.dirty=!0}function ks(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o]=r[0],t.spriteData[o+1]=r[1],t.dirty=!0}function Ys(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o+4]=r[0],t.spriteData[o+5]=r[1],t.spriteData[o+6]=r[2],t.spriteData[o+7]=r[3],t.dirty=!0}function Xs(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o+8]=r,t.dirty=!0}function Hs(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o+9]=r,t.dirty=!0}function Zs(e,t,n,r,i){let o=t.refs.spritesheet.data.spritesheet;t=t.data;let c=t.spriteIndices.get(n)*12,h=o.spriteMeta[r].w,p=o.spriteMeta[r].h;t.spriteData[c+2]=h*i[0],t.spriteData[c+3]=p*i[1],t.dirty=!0}function $s(e,t,n,r,i,o,s,c,h,p){let g=t.refs.spritesheet.data.spritesheet;t=t.data;let F=t.spriteIndices.get(n);hi(t,g,F,r,i,o,s,c,h,p),t.dirty=!0}function hi(e,t,n,r,i,o,s,c,h,p){if(!t.spriteMeta[r])throw new Error(`Sprite name ${r} could not be found in the spritesheet metaData`);let g=n*12,F=t.spriteMeta[r].w,N=t.spriteMeta[r].h,q=t.locations.indexOf(r),m=p<<16&16711680|q&65535;e.spriteData[g]=i[0],e.spriteData[g+1]=i[1],e.spriteData[g+2]=F*o[0],e.spriteData[g+3]=N*o[1],e.spriteData[g+4]=s[0],e.spriteData[g+5]=s[1],e.spriteData[g+6]=s[2],e.spriteData[g+7]=s[3],e.spriteData[g+8]=c,e.spriteData[g+9]=h,e.spriteData[g+11]=m}var pi={type:"cobalt:sprite",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"hdr",type:"textureView",format:"rgba16float",access:"write"},{name:"emissive",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return Ws(e,t)},onRun:function(e,t,n){Qs(e,t,n)},onDestroy:function(e,t){Js(t)},onResize:function(e,t){},onViewportPosition:function(e,t){},customFunctions:{...$e}};async function Ws(e,t){let{device:n}=e,r=16192,i=r,s=Float32Array.BYTES_PER_ELEMENT*2,h=Float32Array.BYTES_PER_ELEMENT*2,g=Float32Array.BYTES_PER_ELEMENT*4,N=Float32Array.BYTES_PER_ELEMENT*4,q=n.createBuffer({size:(s+h+g+N)*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),m=t.refs.spritesheet.data,C=n.createBindGroup({layout:t.refs.spritesheet.data.bindGroupLayout,entries:[{binding:0,resource:{buffer:m.uniformBuffer}},{binding:1,resource:m.colorTexture.view},{binding:2,resource:m.colorTexture.sampler},{binding:3,resource:{buffer:q}},{binding:4,resource:m.emissiveTexture.view}]});return{instancedDrawCalls:new Uint32Array(r*2),instancedDrawCallCount:0,bindGroup:C,spriteBuffer:q,spriteData:new Float32Array(r*12),spriteCount:0,spriteIndices:new Map,dirty:!1}}function Qs(e,t,n){let{device:r}=e,i=t.options.loadOp||"load";if(t.data.dirty&&(Ks(t.data),t.data.dirty=!1),t.data.spriteCount>0){let h=t.data.spriteCount*12*Float32Array.BYTES_PER_ELEMENT;r.queue.writeBuffer(t.data.spriteBuffer,0,t.data.spriteData.buffer,0,h)}let o=n.beginRenderPass({colorAttachments:[{view:t.refs.hdr.data.view,clearValue:e.clearValue,loadOp:i,storeOp:"store"},{view:t.refs.emissive.data.view,clearValue:e.clearValue,loadOp:"clear",storeOp:"store"}]});o.setPipeline(t.refs.spritesheet.data.pipeline),o.setBindGroup(0,t.data.bindGroup),o.setVertexBuffer(0,t.refs.spritesheet.data.quads.buffer);let s=6,c=0;for(let h=0;h<t.data.instancedDrawCallCount;h++){let p=t.data.instancedDrawCalls[h*2]*s,g=t.data.instancedDrawCalls[h*2+1];o.draw(s,g,p,c),c+=g}o.end()}function Ks(e){let t=-1,n=0;e.instancedDrawCallCount=0;for(let r=0;r<e.spriteCount;r++){let i=e.spriteData[r*12+11]&65535;i!==t&&(n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++),t=i,n=0),n++}n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++)}function Js(e){e.data.instancedDrawCalls=null,e.data.bindGroup=null,e.data.spriteBuffer.destroy(),e.data.spriteBuffer=null,e.data.spriteData=null,e.data.spriteIndices.clear(),e.data.spriteIndices=null}var di={type:"cobalt:tile",refs:[{name:"tileAtlas",type:"textureView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return js(e,t)},onRun:function(e,t,n){tu(e,t,n)},onDestroy:function(e,t){vi(t)},onResize:function(e,t){},onViewportPosition:function(e,t){},customFunctions:{setTexture:async function(e,t,n){let{device:r}=e;vi(t),t.options.textureUrl=n;let i=await he(e,"tile map",t.options.textureUrl),o=r.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:t.data.uniformBuffer}},{binding:1,resource:i.view},{binding:2,resource:i.sampler}]});t.data.bindGroup=o,t.data.material=i}}};async function js(e,t){let{device:n}=e,r=await he(e,"tile map",t.options.textureUrl),i=new Float32Array([t.options.scrollScale,t.options.scrollScale]),o=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,s={size:i.byteLength,usage:o,mappedAtCreation:!0},c=n.createBuffer(s);return new Float32Array(c.getMappedRange()).set(i),c.unmap(),{bindGroup:n.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:c}},{binding:1,resource:r.view},{binding:2,resource:r.sampler}]}),material:r,uniformBuffer:c,scrollScale:t.options.scrollScale}}function tu(e,t,n){let{device:r}=e,i=t.options.loadOp||"load",o=n.beginRenderPass({colorAttachments:[{view:t.refs.hdr.data.view,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 vi(e){e.data.material.texture.destroy(),e.data.material.texture=void 0}var sr=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=Ze();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 ur=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 gi="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 cr=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:gi});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 wi="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 eu(e,t){return class extends e{constructor(...n){super(...n),t(this)}}}var ru=eu(Array,e=>e.fill(0)),Tt=1e-6;function nu(e){function t(z=0,O=0){let V=new e(2);return z!==void 0&&(V[0]=z,O!==void 0&&(V[1]=O)),V}let n=t;function r(z,O,V){let u=V??new e(2);return u[0]=z,u[1]=O,u}function i(z,O){let V=O??new e(2);return V[0]=Math.ceil(z[0]),V[1]=Math.ceil(z[1]),V}function o(z,O){let V=O??new e(2);return V[0]=Math.floor(z[0]),V[1]=Math.floor(z[1]),V}function s(z,O){let V=O??new e(2);return V[0]=Math.round(z[0]),V[1]=Math.round(z[1]),V}function c(z,O=0,V=1,u){let B=u??new e(2);return B[0]=Math.min(V,Math.max(O,z[0])),B[1]=Math.min(V,Math.max(O,z[1])),B}function h(z,O,V){let u=V??new e(2);return u[0]=z[0]+O[0],u[1]=z[1]+O[1],u}function p(z,O,V,u){let B=u??new e(2);return B[0]=z[0]+O[0]*V,B[1]=z[1]+O[1]*V,B}function g(z,O){let V=z[0],u=z[1],B=O[0],x=O[1],y=Math.sqrt(V*V+u*u),d=Math.sqrt(B*B+x*x),_=y*d,L=_&&rt(z,O)/_;return Math.acos(L)}function F(z,O,V){let u=V??new e(2);return u[0]=z[0]-O[0],u[1]=z[1]-O[1],u}let N=F;function q(z,O){return Math.abs(z[0]-O[0])<Tt&&Math.abs(z[1]-O[1])<Tt}function m(z,O){return z[0]===O[0]&&z[1]===O[1]}function C(z,O,V,u){let B=u??new e(2);return B[0]=z[0]+V*(O[0]-z[0]),B[1]=z[1]+V*(O[1]-z[1]),B}function Y(z,O,V,u){let B=u??new e(2);return B[0]=z[0]+V[0]*(O[0]-z[0]),B[1]=z[1]+V[1]*(O[1]-z[1]),B}function H(z,O,V){let u=V??new e(2);return u[0]=Math.max(z[0],O[0]),u[1]=Math.max(z[1],O[1]),u}function W(z,O,V){let u=V??new e(2);return u[0]=Math.min(z[0],O[0]),u[1]=Math.min(z[1],O[1]),u}function Q(z,O,V){let u=V??new e(2);return u[0]=z[0]*O,u[1]=z[1]*O,u}let et=Q;function $(z,O,V){let u=V??new e(2);return u[0]=z[0]/O,u[1]=z[1]/O,u}function J(z,O){let V=O??new e(2);return V[0]=1/z[0],V[1]=1/z[1],V}let ut=J;function tt(z,O,V){let u=V??new e(3),B=z[0]*O[1]-z[1]*O[0];return u[0]=0,u[1]=0,u[2]=B,u}function rt(z,O){return z[0]*O[0]+z[1]*O[1]}function D(z){let O=z[0],V=z[1];return Math.sqrt(O*O+V*V)}let a=D;function v(z){let O=z[0],V=z[1];return O*O+V*V}let T=v;function M(z,O){let V=z[0]-O[0],u=z[1]-O[1];return Math.sqrt(V*V+u*u)}let S=M;function E(z,O){let V=z[0]-O[0],u=z[1]-O[1];return V*V+u*u}let R=E;function P(z,O){let V=O??new e(2),u=z[0],B=z[1],x=Math.sqrt(u*u+B*B);return x>1e-5?(V[0]=u/x,V[1]=B/x):(V[0]=0,V[1]=0),V}function l(z,O){let V=O??new e(2);return V[0]=-z[0],V[1]=-z[1],V}function G(z,O){let V=O??new e(2);return V[0]=z[0],V[1]=z[1],V}let ot=G;function at(z,O,V){let u=V??new e(2);return u[0]=z[0]*O[0],u[1]=z[1]*O[1],u}let st=at;function ct(z,O,V){let u=V??new e(2);return u[0]=z[0]/O[0],u[1]=z[1]/O[1],u}let yt=ct;function pt(z=1,O){let V=O??new e(2),u=Math.random()*2*Math.PI;return V[0]=Math.cos(u)*z,V[1]=Math.sin(u)*z,V}function k(z){let O=z??new e(2);return O[0]=0,O[1]=0,O}function Z(z,O,V){let u=V??new e(2),B=z[0],x=z[1];return u[0]=B*O[0]+x*O[4]+O[12],u[1]=B*O[1]+x*O[5]+O[13],u}function U(z,O,V){let u=V??new e(2),B=z[0],x=z[1];return u[0]=O[0]*B+O[4]*x+O[8],u[1]=O[1]*B+O[5]*x+O[9],u}function f(z,O,V,u){let B=u??new e(2),x=z[0]-O[0],y=z[1]-O[1],d=Math.sin(V),_=Math.cos(V);return B[0]=x*_-y*d+O[0],B[1]=x*d+y*_+O[1],B}function b(z,O,V){let u=V??new e(2);return P(z,u),Q(u,O,u)}function w(z,O,V){let u=V??new e(2);return D(z)>O?b(z,O,u):G(z,u)}function I(z,O,V){let u=V??new e(2);return C(z,O,.5,u)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:c,add:h,addScaled:p,angle:g,subtract:F,sub:N,equalsApproximately:q,equals:m,lerp:C,lerpV:Y,max:H,min:W,mulScalar:Q,scale:et,divScalar:$,inverse:J,invert:ut,cross:tt,dot:rt,length:D,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:E,distSq:R,normalize:P,negate:l,copy:G,clone:ot,multiply:at,mul:st,divide:ct,div:yt,random:pt,zero:k,transformMat4:Z,transformMat3:U,rotate:f,setLength:b,truncate:w,midpoint:I}}var xi=new Map;function Si(e){let t=xi.get(e);return t||(t=nu(e),xi.set(e,t)),t}function iu(e){function t(d,_,L){let A=new e(3);return d!==void 0&&(A[0]=d,_!==void 0&&(A[1]=_,L!==void 0&&(A[2]=L))),A}let n=t;function r(d,_,L,A){let X=A??new e(3);return X[0]=d,X[1]=_,X[2]=L,X}function i(d,_){let L=_??new e(3);return L[0]=Math.ceil(d[0]),L[1]=Math.ceil(d[1]),L[2]=Math.ceil(d[2]),L}function o(d,_){let L=_??new e(3);return L[0]=Math.floor(d[0]),L[1]=Math.floor(d[1]),L[2]=Math.floor(d[2]),L}function s(d,_){let L=_??new e(3);return L[0]=Math.round(d[0]),L[1]=Math.round(d[1]),L[2]=Math.round(d[2]),L}function c(d,_=0,L=1,A){let X=A??new e(3);return X[0]=Math.min(L,Math.max(_,d[0])),X[1]=Math.min(L,Math.max(_,d[1])),X[2]=Math.min(L,Math.max(_,d[2])),X}function h(d,_,L){let A=L??new e(3);return A[0]=d[0]+_[0],A[1]=d[1]+_[1],A[2]=d[2]+_[2],A}function p(d,_,L,A){let X=A??new e(3);return X[0]=d[0]+_[0]*L,X[1]=d[1]+_[1]*L,X[2]=d[2]+_[2]*L,X}function g(d,_){let L=d[0],A=d[1],X=d[2],K=_[0],j=_[1],ft=_[2],nt=Math.sqrt(L*L+A*A+X*X),it=Math.sqrt(K*K+j*j+ft*ft),vt=nt*it,ht=vt&&rt(d,_)/vt;return Math.acos(ht)}function F(d,_,L){let A=L??new e(3);return A[0]=d[0]-_[0],A[1]=d[1]-_[1],A[2]=d[2]-_[2],A}let N=F;function q(d,_){return Math.abs(d[0]-_[0])<Tt&&Math.abs(d[1]-_[1])<Tt&&Math.abs(d[2]-_[2])<Tt}function m(d,_){return d[0]===_[0]&&d[1]===_[1]&&d[2]===_[2]}function C(d,_,L,A){let X=A??new e(3);return X[0]=d[0]+L*(_[0]-d[0]),X[1]=d[1]+L*(_[1]-d[1]),X[2]=d[2]+L*(_[2]-d[2]),X}function Y(d,_,L,A){let X=A??new e(3);return X[0]=d[0]+L[0]*(_[0]-d[0]),X[1]=d[1]+L[1]*(_[1]-d[1]),X[2]=d[2]+L[2]*(_[2]-d[2]),X}function H(d,_,L){let A=L??new e(3);return A[0]=Math.max(d[0],_[0]),A[1]=Math.max(d[1],_[1]),A[2]=Math.max(d[2],_[2]),A}function W(d,_,L){let A=L??new e(3);return A[0]=Math.min(d[0],_[0]),A[1]=Math.min(d[1],_[1]),A[2]=Math.min(d[2],_[2]),A}function Q(d,_,L){let A=L??new e(3);return A[0]=d[0]*_,A[1]=d[1]*_,A[2]=d[2]*_,A}let et=Q;function $(d,_,L){let A=L??new e(3);return A[0]=d[0]/_,A[1]=d[1]/_,A[2]=d[2]/_,A}function J(d,_){let L=_??new e(3);return L[0]=1/d[0],L[1]=1/d[1],L[2]=1/d[2],L}let ut=J;function tt(d,_,L){let A=L??new e(3),X=d[2]*_[0]-d[0]*_[2],K=d[0]*_[1]-d[1]*_[0];return A[0]=d[1]*_[2]-d[2]*_[1],A[1]=X,A[2]=K,A}function rt(d,_){return d[0]*_[0]+d[1]*_[1]+d[2]*_[2]}function D(d){let _=d[0],L=d[1],A=d[2];return Math.sqrt(_*_+L*L+A*A)}let a=D;function v(d){let _=d[0],L=d[1],A=d[2];return _*_+L*L+A*A}let T=v;function M(d,_){let L=d[0]-_[0],A=d[1]-_[1],X=d[2]-_[2];return Math.sqrt(L*L+A*A+X*X)}let S=M;function E(d,_){let L=d[0]-_[0],A=d[1]-_[1],X=d[2]-_[2];return L*L+A*A+X*X}let R=E;function P(d,_){let L=_??new e(3),A=d[0],X=d[1],K=d[2],j=Math.sqrt(A*A+X*X+K*K);return j>1e-5?(L[0]=A/j,L[1]=X/j,L[2]=K/j):(L[0]=0,L[1]=0,L[2]=0),L}function l(d,_){let L=_??new e(3);return L[0]=-d[0],L[1]=-d[1],L[2]=-d[2],L}function G(d,_){let L=_??new e(3);return L[0]=d[0],L[1]=d[1],L[2]=d[2],L}let ot=G;function at(d,_,L){let A=L??new e(3);return A[0]=d[0]*_[0],A[1]=d[1]*_[1],A[2]=d[2]*_[2],A}let st=at;function ct(d,_,L){let A=L??new e(3);return A[0]=d[0]/_[0],A[1]=d[1]/_[1],A[2]=d[2]/_[2],A}let yt=ct;function pt(d=1,_){let L=_??new e(3),A=Math.random()*2*Math.PI,X=Math.random()*2-1,K=Math.sqrt(1-X*X)*d;return L[0]=Math.cos(A)*K,L[1]=Math.sin(A)*K,L[2]=X*d,L}function k(d){let _=d??new e(3);return _[0]=0,_[1]=0,_[2]=0,_}function Z(d,_,L){let A=L??new e(3),X=d[0],K=d[1],j=d[2],ft=_[3]*X+_[7]*K+_[11]*j+_[15]||1;return A[0]=(_[0]*X+_[4]*K+_[8]*j+_[12])/ft,A[1]=(_[1]*X+_[5]*K+_[9]*j+_[13])/ft,A[2]=(_[2]*X+_[6]*K+_[10]*j+_[14])/ft,A}function U(d,_,L){let A=L??new e(3),X=d[0],K=d[1],j=d[2];return A[0]=X*_[0*4+0]+K*_[1*4+0]+j*_[2*4+0],A[1]=X*_[0*4+1]+K*_[1*4+1]+j*_[2*4+1],A[2]=X*_[0*4+2]+K*_[1*4+2]+j*_[2*4+2],A}function f(d,_,L){let A=L??new e(3),X=d[0],K=d[1],j=d[2];return A[0]=X*_[0]+K*_[4]+j*_[8],A[1]=X*_[1]+K*_[5]+j*_[9],A[2]=X*_[2]+K*_[6]+j*_[10],A}function b(d,_,L){let A=L??new e(3),X=_[0],K=_[1],j=_[2],ft=_[3]*2,nt=d[0],it=d[1],vt=d[2],ht=K*vt-j*it,lt=j*nt-X*vt,dt=X*it-K*nt;return A[0]=nt+ht*ft+(K*dt-j*lt)*2,A[1]=it+lt*ft+(j*ht-X*dt)*2,A[2]=vt+dt*ft+(X*lt-K*ht)*2,A}function w(d,_){let L=_??new e(3);return L[0]=d[12],L[1]=d[13],L[2]=d[14],L}function I(d,_,L){let A=L??new e(3),X=_*4;return A[0]=d[X+0],A[1]=d[X+1],A[2]=d[X+2],A}function z(d,_){let L=_??new e(3),A=d[0],X=d[1],K=d[2],j=d[4],ft=d[5],nt=d[6],it=d[8],vt=d[9],ht=d[10];return L[0]=Math.sqrt(A*A+X*X+K*K),L[1]=Math.sqrt(j*j+ft*ft+nt*nt),L[2]=Math.sqrt(it*it+vt*vt+ht*ht),L}function O(d,_,L,A){let X=A??new e(3),K=[],j=[];return K[0]=d[0]-_[0],K[1]=d[1]-_[1],K[2]=d[2]-_[2],j[0]=K[0],j[1]=K[1]*Math.cos(L)-K[2]*Math.sin(L),j[2]=K[1]*Math.sin(L)+K[2]*Math.cos(L),X[0]=j[0]+_[0],X[1]=j[1]+_[1],X[2]=j[2]+_[2],X}function V(d,_,L,A){let X=A??new e(3),K=[],j=[];return K[0]=d[0]-_[0],K[1]=d[1]-_[1],K[2]=d[2]-_[2],j[0]=K[2]*Math.sin(L)+K[0]*Math.cos(L),j[1]=K[1],j[2]=K[2]*Math.cos(L)-K[0]*Math.sin(L),X[0]=j[0]+_[0],X[1]=j[1]+_[1],X[2]=j[2]+_[2],X}function u(d,_,L,A){let X=A??new e(3),K=[],j=[];return K[0]=d[0]-_[0],K[1]=d[1]-_[1],K[2]=d[2]-_[2],j[0]=K[0]*Math.cos(L)-K[1]*Math.sin(L),j[1]=K[0]*Math.sin(L)+K[1]*Math.cos(L),j[2]=K[2],X[0]=j[0]+_[0],X[1]=j[1]+_[1],X[2]=j[2]+_[2],X}function B(d,_,L){let A=L??new e(3);return P(d,A),Q(A,_,A)}function x(d,_,L){let A=L??new e(3);return D(d)>_?B(d,_,A):G(d,A)}function y(d,_,L){let A=L??new e(3);return C(d,_,.5,A)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:c,add:h,addScaled:p,angle:g,subtract:F,sub:N,equalsApproximately:q,equals:m,lerp:C,lerpV:Y,max:H,min:W,mulScalar:Q,scale:et,divScalar:$,inverse:J,invert:ut,cross:tt,dot:rt,length:D,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:E,distSq:R,normalize:P,negate:l,copy:G,clone:ot,multiply:at,mul:st,divide:ct,div:yt,random:pt,zero:k,transformMat4:Z,transformMat4Upper3x3:U,transformMat3:f,transformQuat:b,getTranslation:w,getAxis:I,getScaling:z,rotateX:O,rotateY:V,rotateZ:u,setLength:B,truncate:x,midpoint:y}}var yi=new Map;function fr(e){let t=yi.get(e);return t||(t=iu(e),yi.set(e,t)),t}function ou(e){let t=Si(e),n=fr(e);function r(f,b,w,I,z,O,V,u,B){let x=new e(12);return x[3]=0,x[7]=0,x[11]=0,f!==void 0&&(x[0]=f,b!==void 0&&(x[1]=b,w!==void 0&&(x[2]=w,I!==void 0&&(x[4]=I,z!==void 0&&(x[5]=z,O!==void 0&&(x[6]=O,V!==void 0&&(x[8]=V,u!==void 0&&(x[9]=u,B!==void 0&&(x[10]=B))))))))),x}function i(f,b,w,I,z,O,V,u,B,x){let y=x??new e(12);return y[0]=f,y[1]=b,y[2]=w,y[3]=0,y[4]=I,y[5]=z,y[6]=O,y[7]=0,y[8]=V,y[9]=u,y[10]=B,y[11]=0,y}function o(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=f[1],w[2]=f[2],w[3]=0,w[4]=f[4],w[5]=f[5],w[6]=f[6],w[7]=0,w[8]=f[8],w[9]=f[9],w[10]=f[10],w[11]=0,w}function s(f,b){let w=b??new e(12),I=f[0],z=f[1],O=f[2],V=f[3],u=I+I,B=z+z,x=O+O,y=I*u,d=z*u,_=z*B,L=O*u,A=O*B,X=O*x,K=V*u,j=V*B,ft=V*x;return w[0]=1-_-X,w[1]=d+ft,w[2]=L-j,w[3]=0,w[4]=d-ft,w[5]=1-y-X,w[6]=A+K,w[7]=0,w[8]=L+j,w[9]=A-K,w[10]=1-y-_,w[11]=0,w}function c(f,b){let w=b??new e(12);return w[0]=-f[0],w[1]=-f[1],w[2]=-f[2],w[4]=-f[4],w[5]=-f[5],w[6]=-f[6],w[8]=-f[8],w[9]=-f[9],w[10]=-f[10],w}function h(f,b,w){let I=w??new e(12);return I[0]=f[0]*b,I[1]=f[1]*b,I[2]=f[2]*b,I[4]=f[4]*b,I[5]=f[5]*b,I[6]=f[6]*b,I[8]=f[8]*b,I[9]=f[9]*b,I[10]=f[10]*b,I}let p=h;function g(f,b,w){let I=w??new e(12);return I[0]=f[0]+b[0],I[1]=f[1]+b[1],I[2]=f[2]+b[2],I[4]=f[4]+b[4],I[5]=f[5]+b[5],I[6]=f[6]+b[6],I[8]=f[8]+b[8],I[9]=f[9]+b[9],I[10]=f[10]+b[10],I}function F(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=f[1],w[2]=f[2],w[4]=f[4],w[5]=f[5],w[6]=f[6],w[8]=f[8],w[9]=f[9],w[10]=f[10],w}let N=F;function q(f,b){return Math.abs(f[0]-b[0])<Tt&&Math.abs(f[1]-b[1])<Tt&&Math.abs(f[2]-b[2])<Tt&&Math.abs(f[4]-b[4])<Tt&&Math.abs(f[5]-b[5])<Tt&&Math.abs(f[6]-b[6])<Tt&&Math.abs(f[8]-b[8])<Tt&&Math.abs(f[9]-b[9])<Tt&&Math.abs(f[10]-b[10])<Tt}function m(f,b){return f[0]===b[0]&&f[1]===b[1]&&f[2]===b[2]&&f[4]===b[4]&&f[5]===b[5]&&f[6]===b[6]&&f[8]===b[8]&&f[9]===b[9]&&f[10]===b[10]}function C(f){let b=f??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 Y(f,b){let w=b??new e(12);if(w===f){let _;return _=f[1],f[1]=f[4],f[4]=_,_=f[2],f[2]=f[8],f[8]=_,_=f[6],f[6]=f[9],f[9]=_,w}let I=f[0*4+0],z=f[0*4+1],O=f[0*4+2],V=f[1*4+0],u=f[1*4+1],B=f[1*4+2],x=f[2*4+0],y=f[2*4+1],d=f[2*4+2];return w[0]=I,w[1]=V,w[2]=x,w[4]=z,w[5]=u,w[6]=y,w[8]=O,w[9]=B,w[10]=d,w}function H(f,b){let w=b??new e(12),I=f[0*4+0],z=f[0*4+1],O=f[0*4+2],V=f[1*4+0],u=f[1*4+1],B=f[1*4+2],x=f[2*4+0],y=f[2*4+1],d=f[2*4+2],_=d*u-B*y,L=-d*V+B*x,A=y*V-u*x,X=1/(I*_+z*L+O*A);return w[0]=_*X,w[1]=(-d*z+O*y)*X,w[2]=(B*z-O*u)*X,w[4]=L*X,w[5]=(d*I-O*x)*X,w[6]=(-B*I+O*V)*X,w[8]=A*X,w[9]=(-y*I+z*x)*X,w[10]=(u*I-z*V)*X,w}function W(f){let b=f[0],w=f[0*4+1],I=f[0*4+2],z=f[1*4+0],O=f[1*4+1],V=f[1*4+2],u=f[2*4+0],B=f[2*4+1],x=f[2*4+2];return b*(O*x-B*V)-z*(w*x-B*I)+u*(w*V-O*I)}let Q=H;function et(f,b,w){let I=w??new e(12),z=f[0],O=f[1],V=f[2],u=f[4],B=f[5],x=f[6],y=f[8],d=f[9],_=f[10],L=b[0],A=b[1],X=b[2],K=b[4],j=b[5],ft=b[6],nt=b[8],it=b[9],vt=b[10];return I[0]=z*L+u*A+y*X,I[1]=O*L+B*A+d*X,I[2]=V*L+x*A+_*X,I[4]=z*K+u*j+y*ft,I[5]=O*K+B*j+d*ft,I[6]=V*K+x*j+_*ft,I[8]=z*nt+u*it+y*vt,I[9]=O*nt+B*it+d*vt,I[10]=V*nt+x*it+_*vt,I}let $=et;function J(f,b,w){let I=w??C();return f!==I&&(I[0]=f[0],I[1]=f[1],I[2]=f[2],I[4]=f[4],I[5]=f[5],I[6]=f[6]),I[8]=b[0],I[9]=b[1],I[10]=1,I}function ut(f,b){let w=b??t.create();return w[0]=f[8],w[1]=f[9],w}function tt(f,b,w){let I=w??t.create(),z=b*4;return I[0]=f[z+0],I[1]=f[z+1],I}function rt(f,b,w,I){let z=I===f?f:F(f,I),O=w*4;return z[O+0]=b[0],z[O+1]=b[1],z}function D(f,b){let w=b??t.create(),I=f[0],z=f[1],O=f[4],V=f[5];return w[0]=Math.sqrt(I*I+z*z),w[1]=Math.sqrt(O*O+V*V),w}function a(f,b){let w=b??n.create(),I=f[0],z=f[1],O=f[2],V=f[4],u=f[5],B=f[6],x=f[8],y=f[9],d=f[10];return w[0]=Math.sqrt(I*I+z*z+O*O),w[1]=Math.sqrt(V*V+u*u+B*B),w[2]=Math.sqrt(x*x+y*y+d*d),w}function v(f,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]=f[0],w[9]=f[1],w[10]=1,w}function T(f,b,w){let I=w??new e(12),z=b[0],O=b[1],V=f[0],u=f[1],B=f[2],x=f[1*4+0],y=f[1*4+1],d=f[1*4+2],_=f[2*4+0],L=f[2*4+1],A=f[2*4+2];return f!==I&&(I[0]=V,I[1]=u,I[2]=B,I[4]=x,I[5]=y,I[6]=d),I[8]=V*z+x*O+_,I[9]=u*z+y*O+L,I[10]=B*z+d*O+A,I}function M(f,b){let w=b??new e(12),I=Math.cos(f),z=Math.sin(f);return w[0]=I,w[1]=z,w[2]=0,w[4]=-z,w[5]=I,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function S(f,b,w){let I=w??new e(12),z=f[0*4+0],O=f[0*4+1],V=f[0*4+2],u=f[1*4+0],B=f[1*4+1],x=f[1*4+2],y=Math.cos(b),d=Math.sin(b);return I[0]=y*z+d*u,I[1]=y*O+d*B,I[2]=y*V+d*x,I[4]=y*u-d*z,I[5]=y*B-d*O,I[6]=y*x-d*V,f!==I&&(I[8]=f[8],I[9]=f[9],I[10]=f[10]),I}function E(f,b){let w=b??new e(12),I=Math.cos(f),z=Math.sin(f);return w[0]=1,w[1]=0,w[2]=0,w[4]=0,w[5]=I,w[6]=z,w[8]=0,w[9]=-z,w[10]=I,w}function R(f,b,w){let I=w??new e(12),z=f[4],O=f[5],V=f[6],u=f[8],B=f[9],x=f[10],y=Math.cos(b),d=Math.sin(b);return I[4]=y*z+d*u,I[5]=y*O+d*B,I[6]=y*V+d*x,I[8]=y*u-d*z,I[9]=y*B-d*O,I[10]=y*x-d*V,f!==I&&(I[0]=f[0],I[1]=f[1],I[2]=f[2]),I}function P(f,b){let w=b??new e(12),I=Math.cos(f),z=Math.sin(f);return w[0]=I,w[1]=0,w[2]=-z,w[4]=0,w[5]=1,w[6]=0,w[8]=z,w[9]=0,w[10]=I,w}function l(f,b,w){let I=w??new e(12),z=f[0*4+0],O=f[0*4+1],V=f[0*4+2],u=f[2*4+0],B=f[2*4+1],x=f[2*4+2],y=Math.cos(b),d=Math.sin(b);return I[0]=y*z-d*u,I[1]=y*O-d*B,I[2]=y*V-d*x,I[8]=y*u+d*z,I[9]=y*B+d*O,I[10]=y*x+d*V,f!==I&&(I[4]=f[4],I[5]=f[5],I[6]=f[6]),I}let G=M,ot=S;function at(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=0,w[2]=0,w[4]=0,w[5]=f[1],w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function st(f,b,w){let I=w??new e(12),z=b[0],O=b[1];return I[0]=z*f[0*4+0],I[1]=z*f[0*4+1],I[2]=z*f[0*4+2],I[4]=O*f[1*4+0],I[5]=O*f[1*4+1],I[6]=O*f[1*4+2],f!==I&&(I[8]=f[8],I[9]=f[9],I[10]=f[10]),I}function ct(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=0,w[2]=0,w[4]=0,w[5]=f[1],w[6]=0,w[8]=0,w[9]=0,w[10]=f[2],w}function yt(f,b,w){let I=w??new e(12),z=b[0],O=b[1],V=b[2];return I[0]=z*f[0*4+0],I[1]=z*f[0*4+1],I[2]=z*f[0*4+2],I[4]=O*f[1*4+0],I[5]=O*f[1*4+1],I[6]=O*f[1*4+2],I[8]=V*f[2*4+0],I[9]=V*f[2*4+1],I[10]=V*f[2*4+2],I}function pt(f,b){let w=b??new e(12);return w[0]=f,w[1]=0,w[2]=0,w[4]=0,w[5]=f,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function k(f,b,w){let I=w??new e(12);return I[0]=b*f[0*4+0],I[1]=b*f[0*4+1],I[2]=b*f[0*4+2],I[4]=b*f[1*4+0],I[5]=b*f[1*4+1],I[6]=b*f[1*4+2],f!==I&&(I[8]=f[8],I[9]=f[9],I[10]=f[10]),I}function Z(f,b){let w=b??new e(12);return w[0]=f,w[1]=0,w[2]=0,w[4]=0,w[5]=f,w[6]=0,w[8]=0,w[9]=0,w[10]=f,w}function U(f,b,w){let I=w??new e(12);return I[0]=b*f[0*4+0],I[1]=b*f[0*4+1],I[2]=b*f[0*4+2],I[4]=b*f[1*4+0],I[5]=b*f[1*4+1],I[6]=b*f[1*4+2],I[8]=b*f[2*4+0],I[9]=b*f[2*4+1],I[10]=b*f[2*4+2],I}return{add:g,clone:N,copy:F,create:r,determinant:W,equals:m,equalsApproximately:q,fromMat4:o,fromQuat:s,get3DScaling:a,getAxis:tt,getScaling:D,getTranslation:ut,identity:C,inverse:H,invert:Q,mul:$,mulScalar:p,multiply:et,multiplyScalar:h,negate:c,rotate:S,rotateX:R,rotateY:l,rotateZ:ot,rotation:M,rotationX:E,rotationY:P,rotationZ:G,scale:st,scale3D:yt,scaling:at,scaling3D:ct,set:i,setAxis:rt,setTranslation:J,translate:T,translation:v,transpose:Y,uniformScale:k,uniformScale3D:U,uniformScaling:pt,uniformScaling3D:Z}}var Mi=new Map;function au(e){let t=Mi.get(e);return t||(t=ou(e),Mi.set(e,t)),t}function su(e){let t=fr(e);function n(u,B,x,y,d,_,L,A,X,K,j,ft,nt,it,vt,ht){let lt=new e(16);return u!==void 0&&(lt[0]=u,B!==void 0&&(lt[1]=B,x!==void 0&&(lt[2]=x,y!==void 0&&(lt[3]=y,d!==void 0&&(lt[4]=d,_!==void 0&&(lt[5]=_,L!==void 0&&(lt[6]=L,A!==void 0&&(lt[7]=A,X!==void 0&&(lt[8]=X,K!==void 0&&(lt[9]=K,j!==void 0&&(lt[10]=j,ft!==void 0&&(lt[11]=ft,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,B,x,y,d,_,L,A,X,K,j,ft,nt,it,vt,ht,lt){let dt=lt??new e(16);return dt[0]=u,dt[1]=B,dt[2]=x,dt[3]=y,dt[4]=d,dt[5]=_,dt[6]=L,dt[7]=A,dt[8]=X,dt[9]=K,dt[10]=j,dt[11]=ft,dt[12]=nt,dt[13]=it,dt[14]=vt,dt[15]=ht,dt}function i(u,B){let x=B??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,B){let x=B??new e(16),y=u[0],d=u[1],_=u[2],L=u[3],A=y+y,X=d+d,K=_+_,j=y*A,ft=d*A,nt=d*X,it=_*A,vt=_*X,ht=_*K,lt=L*A,dt=L*X,wt=L*K;return x[0]=1-nt-ht,x[1]=ft+wt,x[2]=it-dt,x[3]=0,x[4]=ft-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,B){let x=B??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 c(u,B,x){let y=x??new e(16);return y[0]=u[0]+B[0],y[1]=u[1]+B[1],y[2]=u[2]+B[2],y[3]=u[3]+B[3],y[4]=u[4]+B[4],y[5]=u[5]+B[5],y[6]=u[6]+B[6],y[7]=u[7]+B[7],y[8]=u[8]+B[8],y[9]=u[9]+B[9],y[10]=u[10]+B[10],y[11]=u[11]+B[11],y[12]=u[12]+B[12],y[13]=u[13]+B[13],y[14]=u[14]+B[14],y[15]=u[15]+B[15],y}function h(u,B,x){let y=x??new e(16);return y[0]=u[0]*B,y[1]=u[1]*B,y[2]=u[2]*B,y[3]=u[3]*B,y[4]=u[4]*B,y[5]=u[5]*B,y[6]=u[6]*B,y[7]=u[7]*B,y[8]=u[8]*B,y[9]=u[9]*B,y[10]=u[10]*B,y[11]=u[11]*B,y[12]=u[12]*B,y[13]=u[13]*B,y[14]=u[14]*B,y[15]=u[15]*B,y}let p=h;function g(u,B){let x=B??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 F=g;function N(u,B){return Math.abs(u[0]-B[0])<Tt&&Math.abs(u[1]-B[1])<Tt&&Math.abs(u[2]-B[2])<Tt&&Math.abs(u[3]-B[3])<Tt&&Math.abs(u[4]-B[4])<Tt&&Math.abs(u[5]-B[5])<Tt&&Math.abs(u[6]-B[6])<Tt&&Math.abs(u[7]-B[7])<Tt&&Math.abs(u[8]-B[8])<Tt&&Math.abs(u[9]-B[9])<Tt&&Math.abs(u[10]-B[10])<Tt&&Math.abs(u[11]-B[11])<Tt&&Math.abs(u[12]-B[12])<Tt&&Math.abs(u[13]-B[13])<Tt&&Math.abs(u[14]-B[14])<Tt&&Math.abs(u[15]-B[15])<Tt}function q(u,B){return u[0]===B[0]&&u[1]===B[1]&&u[2]===B[2]&&u[3]===B[3]&&u[4]===B[4]&&u[5]===B[5]&&u[6]===B[6]&&u[7]===B[7]&&u[8]===B[8]&&u[9]===B[9]&&u[10]===B[10]&&u[11]===B[11]&&u[12]===B[12]&&u[13]===B[13]&&u[14]===B[14]&&u[15]===B[15]}function m(u){let B=u??new e(16);return B[0]=1,B[1]=0,B[2]=0,B[3]=0,B[4]=0,B[5]=1,B[6]=0,B[7]=0,B[8]=0,B[9]=0,B[10]=1,B[11]=0,B[12]=0,B[13]=0,B[14]=0,B[15]=1,B}function C(u,B){let x=B??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*4+0],d=u[0*4+1],_=u[0*4+2],L=u[0*4+3],A=u[1*4+0],X=u[1*4+1],K=u[1*4+2],j=u[1*4+3],ft=u[2*4+0],nt=u[2*4+1],it=u[2*4+2],vt=u[2*4+3],ht=u[3*4+0],lt=u[3*4+1],dt=u[3*4+2],wt=u[3*4+3];return x[0]=y,x[1]=A,x[2]=ft,x[3]=ht,x[4]=d,x[5]=X,x[6]=nt,x[7]=lt,x[8]=_,x[9]=K,x[10]=it,x[11]=dt,x[12]=L,x[13]=j,x[14]=vt,x[15]=wt,x}function Y(u,B){let x=B??new e(16),y=u[0*4+0],d=u[0*4+1],_=u[0*4+2],L=u[0*4+3],A=u[1*4+0],X=u[1*4+1],K=u[1*4+2],j=u[1*4+3],ft=u[2*4+0],nt=u[2*4+1],it=u[2*4+2],vt=u[2*4+3],ht=u[3*4+0],lt=u[3*4+1],dt=u[3*4+2],wt=u[3*4+3],gt=it*wt,qt=dt*vt,Mt=K*wt,bt=dt*j,Xt=K*vt,St=it*j,Bt=_*wt,Zt=dt*L,Pt=_*vt,Dt=it*L,$t=_*j,Ut=K*L,Gt=ft*lt,Wt=ht*nt,Ft=A*lt,At=ht*X,Jt=A*nt,Lt=ft*X,zt=y*lt,Te=ht*d,Rt=y*nt,mt=ft*d,_e=y*X,Ot=A*d,Vt=gt*X+bt*nt+Xt*lt-(qt*X+Mt*nt+St*lt),Ee=qt*d+Bt*nt+Dt*lt-(gt*d+Zt*nt+Pt*lt),Le=Mt*d+Zt*X+$t*lt-(bt*d+Bt*X+Ut*lt),ze=St*d+Pt*X+Ut*nt-(Xt*d+Dt*X+$t*nt),Ht=1/(y*Vt+A*Ee+ft*Le+ht*ze);return x[0]=Ht*Vt,x[1]=Ht*Ee,x[2]=Ht*Le,x[3]=Ht*ze,x[4]=Ht*(qt*A+Mt*ft+St*ht-(gt*A+bt*ft+Xt*ht)),x[5]=Ht*(gt*y+Zt*ft+Pt*ht-(qt*y+Bt*ft+Dt*ht)),x[6]=Ht*(bt*y+Bt*A+Ut*ht-(Mt*y+Zt*A+$t*ht)),x[7]=Ht*(Xt*y+Dt*A+$t*ft-(St*y+Pt*A+Ut*ft)),x[8]=Ht*(Gt*j+At*vt+Jt*wt-(Wt*j+Ft*vt+Lt*wt)),x[9]=Ht*(Wt*L+zt*vt+mt*wt-(Gt*L+Te*vt+Rt*wt)),x[10]=Ht*(Ft*L+Te*j+_e*wt-(At*L+zt*j+Ot*wt)),x[11]=Ht*(Lt*L+Rt*j+Ot*vt-(Jt*L+mt*j+_e*vt)),x[12]=Ht*(Ft*it+Lt*dt+Wt*K-(Jt*dt+Gt*K+At*it)),x[13]=Ht*(Rt*dt+Gt*_+Te*it-(zt*it+mt*dt+Wt*_)),x[14]=Ht*(zt*K+Ot*dt+At*_-(_e*dt+Ft*_+Te*K)),x[15]=Ht*(_e*it+Jt*_+mt*K-(Rt*K+Ot*it+Lt*_)),x}function H(u){let B=u[0],x=u[0*4+1],y=u[0*4+2],d=u[0*4+3],_=u[1*4+0],L=u[1*4+1],A=u[1*4+2],X=u[1*4+3],K=u[2*4+0],j=u[2*4+1],ft=u[2*4+2],nt=u[2*4+3],it=u[3*4+0],vt=u[3*4+1],ht=u[3*4+2],lt=u[3*4+3],dt=ft*lt,wt=ht*nt,gt=A*lt,qt=ht*X,Mt=A*nt,bt=ft*X,Xt=y*lt,St=ht*d,Bt=y*nt,Zt=ft*d,Pt=y*X,Dt=A*d,$t=dt*L+qt*j+Mt*vt-(wt*L+gt*j+bt*vt),Ut=wt*x+Xt*j+Zt*vt-(dt*x+St*j+Bt*vt),Gt=gt*x+St*L+Pt*vt-(qt*x+Xt*L+Dt*vt),Wt=bt*x+Bt*L+Dt*j-(Mt*x+Zt*L+Pt*j);return B*$t+_*Ut+K*Gt+it*Wt}let W=Y;function Q(u,B,x){let y=x??new e(16),d=u[0],_=u[1],L=u[2],A=u[3],X=u[4],K=u[5],j=u[6],ft=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],qt=B[0],Mt=B[1],bt=B[2],Xt=B[3],St=B[4],Bt=B[5],Zt=B[6],Pt=B[7],Dt=B[8],$t=B[9],Ut=B[10],Gt=B[11],Wt=B[12],Ft=B[13],At=B[14],Jt=B[15];return y[0]=d*qt+X*Mt+nt*bt+lt*Xt,y[1]=_*qt+K*Mt+it*bt+dt*Xt,y[2]=L*qt+j*Mt+vt*bt+wt*Xt,y[3]=A*qt+ft*Mt+ht*bt+gt*Xt,y[4]=d*St+X*Bt+nt*Zt+lt*Pt,y[5]=_*St+K*Bt+it*Zt+dt*Pt,y[6]=L*St+j*Bt+vt*Zt+wt*Pt,y[7]=A*St+ft*Bt+ht*Zt+gt*Pt,y[8]=d*Dt+X*$t+nt*Ut+lt*Gt,y[9]=_*Dt+K*$t+it*Ut+dt*Gt,y[10]=L*Dt+j*$t+vt*Ut+wt*Gt,y[11]=A*Dt+ft*$t+ht*Ut+gt*Gt,y[12]=d*Wt+X*Ft+nt*At+lt*Jt,y[13]=_*Wt+K*Ft+it*At+dt*Jt,y[14]=L*Wt+j*Ft+vt*At+wt*Jt,y[15]=A*Wt+ft*Ft+ht*At+gt*Jt,y}let et=Q;function $(u,B,x){let y=x??m();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]=B[0],y[13]=B[1],y[14]=B[2],y[15]=1,y}function J(u,B){let x=B??t.create();return x[0]=u[12],x[1]=u[13],x[2]=u[14],x}function ut(u,B,x){let y=x??t.create(),d=B*4;return y[0]=u[d+0],y[1]=u[d+1],y[2]=u[d+2],y}function tt(u,B,x,y){let d=y===u?y:g(u,y),_=x*4;return d[_+0]=B[0],d[_+1]=B[1],d[_+2]=B[2],d}function rt(u,B){let x=B??t.create(),y=u[0],d=u[1],_=u[2],L=u[4],A=u[5],X=u[6],K=u[8],j=u[9],ft=u[10];return x[0]=Math.sqrt(y*y+d*d+_*_),x[1]=Math.sqrt(L*L+A*A+X*X),x[2]=Math.sqrt(K*K+j*j+ft*ft),x}function D(u,B,x,y,d){let _=d??new e(16),L=Math.tan(Math.PI*.5-.5*u);if(_[0]=L/B,_[1]=0,_[2]=0,_[3]=0,_[4]=0,_[5]=L,_[6]=0,_[7]=0,_[8]=0,_[9]=0,_[11]=-1,_[12]=0,_[13]=0,_[15]=0,Number.isFinite(y)){let A=1/(x-y);_[10]=y*A,_[14]=y*x*A}else _[10]=-1,_[14]=-x;return _}function a(u,B,x,y=1/0,d){let _=d??new e(16),L=1/Math.tan(u*.5);if(_[0]=L/B,_[1]=0,_[2]=0,_[3]=0,_[4]=0,_[5]=L,_[6]=0,_[7]=0,_[8]=0,_[9]=0,_[11]=-1,_[12]=0,_[13]=0,_[15]=0,y===1/0)_[10]=0,_[14]=x;else{let A=1/(y-x);_[10]=x*A,_[14]=y*x*A}return _}function v(u,B,x,y,d,_,L){let A=L??new e(16);return A[0]=2/(B-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-_),A[11]=0,A[12]=(B+u)/(u-B),A[13]=(y+x)/(x-y),A[14]=d/(d-_),A[15]=1,A}function T(u,B,x,y,d,_,L){let A=L??new e(16),X=B-u,K=y-x,j=d-_;return A[0]=2*d/X,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/K,A[6]=0,A[7]=0,A[8]=(u+B)/X,A[9]=(y+x)/K,A[10]=_/j,A[11]=-1,A[12]=0,A[13]=0,A[14]=d*_/j,A[15]=0,A}function M(u,B,x,y,d,_=1/0,L){let A=L??new e(16),X=B-u,K=y-x;if(A[0]=2*d/X,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/K,A[6]=0,A[7]=0,A[8]=(u+B)/X,A[9]=(y+x)/K,A[11]=-1,A[12]=0,A[13]=0,A[15]=0,_===1/0)A[10]=0,A[14]=d;else{let j=1/(_-d);A[10]=d*j,A[14]=_*d*j}return A}let S=t.create(),E=t.create(),R=t.create();function P(u,B,x,y){let d=y??new e(16);return t.normalize(t.subtract(B,u,R),R),t.normalize(t.cross(x,R,S),S),t.normalize(t.cross(R,S,E),E),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=E[0],d[5]=E[1],d[6]=E[2],d[7]=0,d[8]=R[0],d[9]=R[1],d[10]=R[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function l(u,B,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,B,R),R),t.normalize(t.cross(x,R,S),S),t.normalize(t.cross(R,S,E),E),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=E[0],d[5]=E[1],d[6]=E[2],d[7]=0,d[8]=R[0],d[9]=R[1],d[10]=R[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function G(u,B,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,B,R),R),t.normalize(t.cross(x,R,S),S),t.normalize(t.cross(R,S,E),E),d[0]=S[0],d[1]=E[0],d[2]=R[0],d[3]=0,d[4]=S[1],d[5]=E[1],d[6]=R[1],d[7]=0,d[8]=S[2],d[9]=E[2],d[10]=R[2],d[11]=0,d[12]=-(S[0]*u[0]+S[1]*u[1]+S[2]*u[2]),d[13]=-(E[0]*u[0]+E[1]*u[1]+E[2]*u[2]),d[14]=-(R[0]*u[0]+R[1]*u[1]+R[2]*u[2]),d[15]=1,d}function ot(u,B){let x=B??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,B,x){let y=x??new e(16),d=B[0],_=B[1],L=B[2],A=u[0],X=u[1],K=u[2],j=u[3],ft=u[1*4+0],nt=u[1*4+1],it=u[1*4+2],vt=u[1*4+3],ht=u[2*4+0],lt=u[2*4+1],dt=u[2*4+2],wt=u[2*4+3],gt=u[3*4+0],qt=u[3*4+1],Mt=u[3*4+2],bt=u[3*4+3];return u!==y&&(y[0]=A,y[1]=X,y[2]=K,y[3]=j,y[4]=ft,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+ft*_+ht*L+gt,y[13]=X*d+nt*_+lt*L+qt,y[14]=K*d+it*_+dt*L+Mt,y[15]=j*d+vt*_+wt*L+bt,y}function st(u,B){let x=B??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 ct(u,B,x){let y=x??new e(16),d=u[4],_=u[5],L=u[6],A=u[7],X=u[8],K=u[9],j=u[10],ft=u[11],nt=Math.cos(B),it=Math.sin(B);return y[4]=nt*d+it*X,y[5]=nt*_+it*K,y[6]=nt*L+it*j,y[7]=nt*A+it*ft,y[8]=nt*X-it*d,y[9]=nt*K-it*_,y[10]=nt*j-it*L,y[11]=nt*ft-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,B){let x=B??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,B,x){let y=x??new e(16),d=u[0*4+0],_=u[0*4+1],L=u[0*4+2],A=u[0*4+3],X=u[2*4+0],K=u[2*4+1],j=u[2*4+2],ft=u[2*4+3],nt=Math.cos(B),it=Math.sin(B);return y[0]=nt*d-it*X,y[1]=nt*_-it*K,y[2]=nt*L-it*j,y[3]=nt*A-it*ft,y[8]=nt*X+it*d,y[9]=nt*K+it*_,y[10]=nt*j+it*L,y[11]=nt*ft+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,B){let x=B??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 Z(u,B,x){let y=x??new e(16),d=u[0*4+0],_=u[0*4+1],L=u[0*4+2],A=u[0*4+3],X=u[1*4+0],K=u[1*4+1],j=u[1*4+2],ft=u[1*4+3],nt=Math.cos(B),it=Math.sin(B);return y[0]=nt*d+it*X,y[1]=nt*_+it*K,y[2]=nt*L+it*j,y[3]=nt*A+it*ft,y[4]=nt*X-it*d,y[5]=nt*K-it*_,y[6]=nt*j-it*L,y[7]=nt*ft-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 U(u,B,x){let y=x??new e(16),d=u[0],_=u[1],L=u[2],A=Math.sqrt(d*d+_*_+L*L);d/=A,_/=A,L/=A;let X=d*d,K=_*_,j=L*L,ft=Math.cos(B),nt=Math.sin(B),it=1-ft;return y[0]=X+(1-X)*ft,y[1]=d*_*it+L*nt,y[2]=d*L*it-_*nt,y[3]=0,y[4]=d*_*it-L*nt,y[5]=K+(1-K)*ft,y[6]=_*L*it+d*nt,y[7]=0,y[8]=d*L*it+_*nt,y[9]=_*L*it-d*nt,y[10]=j+(1-j)*ft,y[11]=0,y[12]=0,y[13]=0,y[14]=0,y[15]=1,y}let f=U;function b(u,B,x,y){let d=y??new e(16),_=B[0],L=B[1],A=B[2],X=Math.sqrt(_*_+L*L+A*A);_/=X,L/=X,A/=X;let K=_*_,j=L*L,ft=A*A,nt=Math.cos(x),it=Math.sin(x),vt=1-nt,ht=K+(1-K)*nt,lt=_*L*vt+A*it,dt=_*A*vt-L*it,wt=_*L*vt-A*it,gt=j+(1-j)*nt,qt=L*A*vt+_*it,Mt=_*A*vt+L*it,bt=L*A*vt-_*it,Xt=ft+(1-ft)*nt,St=u[0],Bt=u[1],Zt=u[2],Pt=u[3],Dt=u[4],$t=u[5],Ut=u[6],Gt=u[7],Wt=u[8],Ft=u[9],At=u[10],Jt=u[11];return d[0]=ht*St+lt*Dt+dt*Wt,d[1]=ht*Bt+lt*$t+dt*Ft,d[2]=ht*Zt+lt*Ut+dt*At,d[3]=ht*Pt+lt*Gt+dt*Jt,d[4]=wt*St+gt*Dt+qt*Wt,d[5]=wt*Bt+gt*$t+qt*Ft,d[6]=wt*Zt+gt*Ut+qt*At,d[7]=wt*Pt+gt*Gt+qt*Jt,d[8]=Mt*St+bt*Dt+Xt*Wt,d[9]=Mt*Bt+bt*$t+Xt*Ft,d[10]=Mt*Zt+bt*Ut+Xt*At,d[11]=Mt*Pt+bt*Gt+Xt*Jt,u!==d&&(d[12]=u[12],d[13]=u[13],d[14]=u[14],d[15]=u[15]),d}let w=b;function I(u,B){let x=B??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 z(u,B,x){let y=x??new e(16),d=B[0],_=B[1],L=B[2];return y[0]=d*u[0*4+0],y[1]=d*u[0*4+1],y[2]=d*u[0*4+2],y[3]=d*u[0*4+3],y[4]=_*u[1*4+0],y[5]=_*u[1*4+1],y[6]=_*u[1*4+2],y[7]=_*u[1*4+3],y[8]=L*u[2*4+0],y[9]=L*u[2*4+1],y[10]=L*u[2*4+2],y[11]=L*u[2*4+3],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function O(u,B){let x=B??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 V(u,B,x){let y=x??new e(16);return y[0]=B*u[0*4+0],y[1]=B*u[0*4+1],y[2]=B*u[0*4+2],y[3]=B*u[0*4+3],y[4]=B*u[1*4+0],y[5]=B*u[1*4+1],y[6]=B*u[1*4+2],y[7]=B*u[1*4+3],y[8]=B*u[2*4+0],y[9]=B*u[2*4+1],y[10]=B*u[2*4+2],y[11]=B*u[2*4+3],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}return{add:c,aim:P,axisRotate:b,axisRotation:U,cameraAim:l,clone:F,copy:g,create:n,determinant:H,equals:q,equalsApproximately:N,fromMat3:i,fromQuat:o,frustum:T,frustumReverseZ:M,getAxis:ut,getScaling:rt,getTranslation:J,identity:m,inverse:Y,invert:W,lookAt:G,mul:et,mulScalar:p,multiply:Q,multiplyScalar:h,negate:s,ortho:v,perspective:D,perspectiveReverseZ:a,rotate:w,rotateX:ct,rotateY:pt,rotateZ:Z,rotation:f,rotationX:st,rotationY:yt,rotationZ:k,scale:z,scaling:I,set:r,setAxis:tt,setTranslation:$,translate:at,translation:ot,transpose:C,uniformScale:V,uniformScaling:O}}var bi=new Map;function uu(e){let t=bi.get(e);return t||(t=su(e),bi.set(e,t)),t}function cu(e){let t=fr(e);function n(k,Z,U,f){let b=new e(4);return k!==void 0&&(b[0]=k,Z!==void 0&&(b[1]=Z,U!==void 0&&(b[2]=U,f!==void 0&&(b[3]=f)))),b}let r=n;function i(k,Z,U,f,b){let w=b??new e(4);return w[0]=k,w[1]=Z,w[2]=U,w[3]=f,w}function o(k,Z,U){let f=U??new e(4),b=Z*.5,w=Math.sin(b);return f[0]=w*k[0],f[1]=w*k[1],f[2]=w*k[2],f[3]=Math.cos(b),f}function s(k,Z){let U=Z??t.create(3),f=Math.acos(k[3])*2,b=Math.sin(f*.5);return b>Tt?(U[0]=k[0]/b,U[1]=k[1]/b,U[2]=k[2]/b):(U[0]=1,U[1]=0,U[2]=0),{angle:f,axis:U}}function c(k,Z){let U=D(k,Z);return Math.acos(2*U*U-1)}function h(k,Z,U){let f=U??new e(4),b=k[0],w=k[1],I=k[2],z=k[3],O=Z[0],V=Z[1],u=Z[2],B=Z[3];return f[0]=b*B+z*O+w*u-I*V,f[1]=w*B+z*V+I*O-b*u,f[2]=I*B+z*u+b*V-w*O,f[3]=z*B-b*O-w*V-I*u,f}let p=h;function g(k,Z,U){let f=U??new e(4),b=Z*.5,w=k[0],I=k[1],z=k[2],O=k[3],V=Math.sin(b),u=Math.cos(b);return f[0]=w*u+O*V,f[1]=I*u+z*V,f[2]=z*u-I*V,f[3]=O*u-w*V,f}function F(k,Z,U){let f=U??new e(4),b=Z*.5,w=k[0],I=k[1],z=k[2],O=k[3],V=Math.sin(b),u=Math.cos(b);return f[0]=w*u-z*V,f[1]=I*u+O*V,f[2]=z*u+w*V,f[3]=O*u-I*V,f}function N(k,Z,U){let f=U??new e(4),b=Z*.5,w=k[0],I=k[1],z=k[2],O=k[3],V=Math.sin(b),u=Math.cos(b);return f[0]=w*u+I*V,f[1]=I*u-w*V,f[2]=z*u+O*V,f[3]=O*u-z*V,f}function q(k,Z,U,f){let b=f??new e(4),w=k[0],I=k[1],z=k[2],O=k[3],V=Z[0],u=Z[1],B=Z[2],x=Z[3],y=w*V+I*u+z*B+O*x;y<0&&(y=-y,V=-V,u=-u,B=-B,x=-x);let d,_;if(1-y>Tt){let L=Math.acos(y),A=Math.sin(L);d=Math.sin((1-U)*L)/A,_=Math.sin(U*L)/A}else d=1-U,_=U;return b[0]=d*w+_*V,b[1]=d*I+_*u,b[2]=d*z+_*B,b[3]=d*O+_*x,b}function m(k,Z){let U=Z??new e(4),f=k[0],b=k[1],w=k[2],I=k[3],z=f*f+b*b+w*w+I*I,O=z?1/z:0;return U[0]=-f*O,U[1]=-b*O,U[2]=-w*O,U[3]=I*O,U}function C(k,Z){let U=Z??new e(4);return U[0]=-k[0],U[1]=-k[1],U[2]=-k[2],U[3]=k[3],U}function Y(k,Z){let U=Z??new e(4),f=k[0]+k[5]+k[10];if(f>0){let b=Math.sqrt(f+1);U[3]=.5*b;let w=.5/b;U[0]=(k[6]-k[9])*w,U[1]=(k[8]-k[2])*w,U[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,I=(b+2)%3,z=Math.sqrt(k[b*4+b]-k[w*4+w]-k[I*4+I]+1);U[b]=.5*z;let O=.5/z;U[3]=(k[w*4+I]-k[I*4+w])*O,U[w]=(k[w*4+b]+k[b*4+w])*O,U[I]=(k[I*4+b]+k[b*4+I])*O}return U}function H(k,Z,U,f,b){let w=b??new e(4),I=k*.5,z=Z*.5,O=U*.5,V=Math.sin(I),u=Math.cos(I),B=Math.sin(z),x=Math.cos(z),y=Math.sin(O),d=Math.cos(O);switch(f){case"xyz":w[0]=V*x*d+u*B*y,w[1]=u*B*d-V*x*y,w[2]=u*x*y+V*B*d,w[3]=u*x*d-V*B*y;break;case"xzy":w[0]=V*x*d-u*B*y,w[1]=u*B*d-V*x*y,w[2]=u*x*y+V*B*d,w[3]=u*x*d+V*B*y;break;case"yxz":w[0]=V*x*d+u*B*y,w[1]=u*B*d-V*x*y,w[2]=u*x*y-V*B*d,w[3]=u*x*d+V*B*y;break;case"yzx":w[0]=V*x*d+u*B*y,w[1]=u*B*d+V*x*y,w[2]=u*x*y-V*B*d,w[3]=u*x*d-V*B*y;break;case"zxy":w[0]=V*x*d-u*B*y,w[1]=u*B*d+V*x*y,w[2]=u*x*y+V*B*d,w[3]=u*x*d-V*B*y;break;case"zyx":w[0]=V*x*d-u*B*y,w[1]=u*B*d+V*x*y,w[2]=u*x*y-V*B*d,w[3]=u*x*d+V*B*y;break;default:throw new Error(`Unknown rotation order: ${f}`)}return w}function W(k,Z){let U=Z??new e(4);return U[0]=k[0],U[1]=k[1],U[2]=k[2],U[3]=k[3],U}let Q=W;function et(k,Z,U){let f=U??new e(4);return f[0]=k[0]+Z[0],f[1]=k[1]+Z[1],f[2]=k[2]+Z[2],f[3]=k[3]+Z[3],f}function $(k,Z,U){let f=U??new e(4);return f[0]=k[0]-Z[0],f[1]=k[1]-Z[1],f[2]=k[2]-Z[2],f[3]=k[3]-Z[3],f}let J=$;function ut(k,Z,U){let f=U??new e(4);return f[0]=k[0]*Z,f[1]=k[1]*Z,f[2]=k[2]*Z,f[3]=k[3]*Z,f}let tt=ut;function rt(k,Z,U){let f=U??new e(4);return f[0]=k[0]/Z,f[1]=k[1]/Z,f[2]=k[2]/Z,f[3]=k[3]/Z,f}function D(k,Z){return k[0]*Z[0]+k[1]*Z[1]+k[2]*Z[2]+k[3]*Z[3]}function a(k,Z,U,f){let b=f??new e(4);return b[0]=k[0]+U*(Z[0]-k[0]),b[1]=k[1]+U*(Z[1]-k[1]),b[2]=k[2]+U*(Z[2]-k[2]),b[3]=k[3]+U*(Z[3]-k[3]),b}function v(k){let Z=k[0],U=k[1],f=k[2],b=k[3];return Math.sqrt(Z*Z+U*U+f*f+b*b)}let T=v;function M(k){let Z=k[0],U=k[1],f=k[2],b=k[3];return Z*Z+U*U+f*f+b*b}let S=M;function E(k,Z){let U=Z??new e(4),f=k[0],b=k[1],w=k[2],I=k[3],z=Math.sqrt(f*f+b*b+w*w+I*I);return z>1e-5?(U[0]=f/z,U[1]=b/z,U[2]=w/z,U[3]=I/z):(U[0]=0,U[1]=0,U[2]=0,U[3]=1),U}function R(k,Z){return Math.abs(k[0]-Z[0])<Tt&&Math.abs(k[1]-Z[1])<Tt&&Math.abs(k[2]-Z[2])<Tt&&Math.abs(k[3]-Z[3])<Tt}function P(k,Z){return k[0]===Z[0]&&k[1]===Z[1]&&k[2]===Z[2]&&k[3]===Z[3]}function l(k){let Z=k??new e(4);return Z[0]=0,Z[1]=0,Z[2]=0,Z[3]=1,Z}let G=t.create(),ot=t.create(),at=t.create();function st(k,Z,U){let f=U??new e(4),b=t.dot(k,Z);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,f),f):b>.999999?(f[0]=0,f[1]=0,f[2]=0,f[3]=1,f):(t.cross(k,Z,G),f[0]=G[0],f[1]=G[1],f[2]=G[2],f[3]=1+b,E(f,f))}let ct=new e(4),yt=new e(4);function pt(k,Z,U,f,b,w){let I=w??new e(4);return q(k,f,b,ct),q(Z,U,b,yt),q(ct,yt,2*b*(1-b),I),I}return{create:n,fromValues:r,set:i,fromAxisAngle:o,toAxisAngle:s,angle:c,multiply:h,mul:p,rotateX:g,rotateY:F,rotateZ:N,slerp:q,inverse:m,conjugate:C,fromMat:Y,fromEuler:H,copy:W,clone:Q,add:et,subtract:$,sub:J,mulScalar:ut,scale:tt,divScalar:rt,dot:D,lerp:a,length:v,len:T,lengthSq:M,lenSq:S,normalize:E,equalsApproximately:R,equals:P,identity:l,rotationTo:st,sqlerp:pt}}var Ti=new Map;function fu(e){let t=Ti.get(e);return t||(t=cu(e),Ti.set(e,t)),t}function lu(e){function t(U,f,b,w){let I=new e(4);return U!==void 0&&(I[0]=U,f!==void 0&&(I[1]=f,b!==void 0&&(I[2]=b,w!==void 0&&(I[3]=w)))),I}let n=t;function r(U,f,b,w,I){let z=I??new e(4);return z[0]=U,z[1]=f,z[2]=b,z[3]=w,z}function i(U,f){let b=f??new e(4);return b[0]=Math.ceil(U[0]),b[1]=Math.ceil(U[1]),b[2]=Math.ceil(U[2]),b[3]=Math.ceil(U[3]),b}function o(U,f){let b=f??new e(4);return b[0]=Math.floor(U[0]),b[1]=Math.floor(U[1]),b[2]=Math.floor(U[2]),b[3]=Math.floor(U[3]),b}function s(U,f){let b=f??new e(4);return b[0]=Math.round(U[0]),b[1]=Math.round(U[1]),b[2]=Math.round(U[2]),b[3]=Math.round(U[3]),b}function c(U,f=0,b=1,w){let I=w??new e(4);return I[0]=Math.min(b,Math.max(f,U[0])),I[1]=Math.min(b,Math.max(f,U[1])),I[2]=Math.min(b,Math.max(f,U[2])),I[3]=Math.min(b,Math.max(f,U[3])),I}function h(U,f,b){let w=b??new e(4);return w[0]=U[0]+f[0],w[1]=U[1]+f[1],w[2]=U[2]+f[2],w[3]=U[3]+f[3],w}function p(U,f,b,w){let I=w??new e(4);return I[0]=U[0]+f[0]*b,I[1]=U[1]+f[1]*b,I[2]=U[2]+f[2]*b,I[3]=U[3]+f[3]*b,I}function g(U,f,b){let w=b??new e(4);return w[0]=U[0]-f[0],w[1]=U[1]-f[1],w[2]=U[2]-f[2],w[3]=U[3]-f[3],w}let F=g;function N(U,f){return Math.abs(U[0]-f[0])<Tt&&Math.abs(U[1]-f[1])<Tt&&Math.abs(U[2]-f[2])<Tt&&Math.abs(U[3]-f[3])<Tt}function q(U,f){return U[0]===f[0]&&U[1]===f[1]&&U[2]===f[2]&&U[3]===f[3]}function m(U,f,b,w){let I=w??new e(4);return I[0]=U[0]+b*(f[0]-U[0]),I[1]=U[1]+b*(f[1]-U[1]),I[2]=U[2]+b*(f[2]-U[2]),I[3]=U[3]+b*(f[3]-U[3]),I}function C(U,f,b,w){let I=w??new e(4);return I[0]=U[0]+b[0]*(f[0]-U[0]),I[1]=U[1]+b[1]*(f[1]-U[1]),I[2]=U[2]+b[2]*(f[2]-U[2]),I[3]=U[3]+b[3]*(f[3]-U[3]),I}function Y(U,f,b){let w=b??new e(4);return w[0]=Math.max(U[0],f[0]),w[1]=Math.max(U[1],f[1]),w[2]=Math.max(U[2],f[2]),w[3]=Math.max(U[3],f[3]),w}function H(U,f,b){let w=b??new e(4);return w[0]=Math.min(U[0],f[0]),w[1]=Math.min(U[1],f[1]),w[2]=Math.min(U[2],f[2]),w[3]=Math.min(U[3],f[3]),w}function W(U,f,b){let w=b??new e(4);return w[0]=U[0]*f,w[1]=U[1]*f,w[2]=U[2]*f,w[3]=U[3]*f,w}let Q=W;function et(U,f,b){let w=b??new e(4);return w[0]=U[0]/f,w[1]=U[1]/f,w[2]=U[2]/f,w[3]=U[3]/f,w}function $(U,f){let b=f??new e(4);return b[0]=1/U[0],b[1]=1/U[1],b[2]=1/U[2],b[3]=1/U[3],b}let J=$;function ut(U,f){return U[0]*f[0]+U[1]*f[1]+U[2]*f[2]+U[3]*f[3]}function tt(U){let f=U[0],b=U[1],w=U[2],I=U[3];return Math.sqrt(f*f+b*b+w*w+I*I)}let rt=tt;function D(U){let f=U[0],b=U[1],w=U[2],I=U[3];return f*f+b*b+w*w+I*I}let a=D;function v(U,f){let b=U[0]-f[0],w=U[1]-f[1],I=U[2]-f[2],z=U[3]-f[3];return Math.sqrt(b*b+w*w+I*I+z*z)}let T=v;function M(U,f){let b=U[0]-f[0],w=U[1]-f[1],I=U[2]-f[2],z=U[3]-f[3];return b*b+w*w+I*I+z*z}let S=M;function E(U,f){let b=f??new e(4),w=U[0],I=U[1],z=U[2],O=U[3],V=Math.sqrt(w*w+I*I+z*z+O*O);return V>1e-5?(b[0]=w/V,b[1]=I/V,b[2]=z/V,b[3]=O/V):(b[0]=0,b[1]=0,b[2]=0,b[3]=0),b}function R(U,f){let b=f??new e(4);return b[0]=-U[0],b[1]=-U[1],b[2]=-U[2],b[3]=-U[3],b}function P(U,f){let b=f??new e(4);return b[0]=U[0],b[1]=U[1],b[2]=U[2],b[3]=U[3],b}let l=P;function G(U,f,b){let w=b??new e(4);return w[0]=U[0]*f[0],w[1]=U[1]*f[1],w[2]=U[2]*f[2],w[3]=U[3]*f[3],w}let ot=G;function at(U,f,b){let w=b??new e(4);return w[0]=U[0]/f[0],w[1]=U[1]/f[1],w[2]=U[2]/f[2],w[3]=U[3]/f[3],w}let st=at;function ct(U){let f=U??new e(4);return f[0]=0,f[1]=0,f[2]=0,f[3]=0,f}function yt(U,f,b){let w=b??new e(4),I=U[0],z=U[1],O=U[2],V=U[3];return w[0]=f[0]*I+f[4]*z+f[8]*O+f[12]*V,w[1]=f[1]*I+f[5]*z+f[9]*O+f[13]*V,w[2]=f[2]*I+f[6]*z+f[10]*O+f[14]*V,w[3]=f[3]*I+f[7]*z+f[11]*O+f[15]*V,w}function pt(U,f,b){let w=b??new e(4);return E(U,w),W(w,f,w)}function k(U,f,b){let w=b??new e(4);return tt(U)>f?pt(U,f,w):P(U,w)}function Z(U,f,b){let w=b??new e(4);return m(U,f,.5,w)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:c,add:h,addScaled:p,subtract:g,sub:F,equalsApproximately:N,equals:q,lerp:m,lerpV:C,max:Y,min:H,mulScalar:W,scale:Q,divScalar:et,inverse:$,invert:J,dot:ut,length:tt,len:rt,lengthSq:D,lenSq:a,distance:v,dist:T,distanceSq:M,distSq:S,normalize:E,negate:R,copy:P,clone:l,multiply:G,mul:ot,divide:at,div:st,zero:ct,transformMat4:yt,setLength:pt,truncate:k,midpoint:Z}}var _i=new Map;function hu(e){let t=_i.get(e);return t||(t=lu(e),_i.set(e,t)),t}function cn(e,t,n,r,i,o){return{mat3:au(e),mat4:uu(t),quat:fu(n),vec2:Si(r),vec3:fr(i),vec4:hu(o)}}var{mat3:xe,mat4:Et,quat:bl,vec2:jt,vec3:pe,vec4:Bi}=cn(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array),{mat3:Tl,mat4:_l,quat:Sl,vec2:Bl,vec3:Pl,vec4:Dl}=cn(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array),{mat3:Ul,mat4:Gl,quat:Fl,vec2:Al,vec3:Il,vec4:El}=cn(ru,Array,Array,Array,Array,Array);var lr=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:wi});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=Et.identity();Et.multiply(Et.scaling(n),o,o),Et.multiply(Et.rotationZ(r),o,o),Et.multiply(Et.translation(i),o,o);let s=Et.translation([-t.position[0],-t.position[1],0]),c=t.width/t.zoom,h=t.height/t.zoom,p=Et.ortho(0,c,h,0,-10,10),g=Et.identity();Et.multiply(s,o,g),Et.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]}};var Di={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 pu(e,t)},onRun:function(e,t,n){vu(e,t,n)},onDestroy:function(e,t){du(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 pu(e,t){let{device:n}=e,r=new ur({device:n,initialParameters:{offsetX:t.options.offseyX??0,offsetY:t.options.offseyY??0,scale:t.options.scale??20}}),i=256,o=new sr({device:n,maxSpriteCount:i}),s=new lr({device:n,width:e.viewport.width,height:e.viewport.height,blurFactor:8,trianglesBuffer:o}),c=new cr({device:n,targetFormat:"bgra8unorm",colorTextureView:t.refs.color.data.view,noiseMapTextureView:t.refs.map.view,displacementTextureView:s.getView(),displacementParametersBuffer:r});return{displacementParameters:r,displacementTexture:s,displacementComposition:c,trianglesBuffer:o}}function vu(e,t,n){if(t.data.trianglesBuffer.spriteCount===0)return;t.data.trianglesBuffer.update(),t.data.displacementTexture.update(n);let i=n.beginRenderPass({colorAttachments:[{view:t.refs.out,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});i.executeBundles([t.data.displacementComposition.getRenderBundle()]),i.end()}function du(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}function fn(e,t){let n=t.vertices,r=GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,i={size:n.byteLength,usage:r,mappedAtCreation:!0},o=e.createBuffer(i);return new Float32Array(o.getMappedRange()).set(n),o.unmap(),{buffer:o,bufferLayout:{arrayStride:20,stepMode:"vertex",attributes:[{shaderLocation:0,format:"float32x3",offset:0},{shaderLocation:1,format:"float32x2",offset:12}]}}}var ln="struct TransformData{view:mat4x4<f32>,projection:mat4x4<f32>};struct Sprite{translate:vec2<f32>,scale:vec2<f32>,tint:vec4<f32>,opacity:f32,rotation:f32,};struct SpritesBuffer{models:array<Sprite>,};@binding(0)@group(0)var<uniform> transformUBO:TransformData;@binding(1)@group(0)var myTexture:texture_2d<f32>;@binding(2)@group(0)var mySampler:sampler;@binding(3)@group(0)var<storage,read>sprites:SpritesBuffer;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32,};@vertex fn vs_main(@builtin(instance_index)i_id:u32,@location(0)vertexPosition:vec3<f32>,@location(1)vertexTexCoord:vec2<f32>)->Fragment{var output:Fragment;var sx:f32=sprites.models[i_id].scale.x;var sy:f32=sprites.models[i_id].scale.y;var sz:f32=1.0;var rot:f32=sprites.models[i_id].rotation;var tx:f32=sprites.models[i_id].translate.x;var ty:f32=sprites.models[i_id].translate.y;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;output.Position=transformUBO.projection*transformUBO.view*modelM*vec4<f32>(vertexPosition,1.0);output.TexCoord=vertexTexCoord;output.Tint=sprites.models[i_id].tint;output.Opacity=sprites.models[i_id].opacity;return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32)->@location(0)vec4<f32>{var outColor:vec4<f32>=textureSample(myTexture,mySampler,TexCoord);var output=vec4<f32>(outColor.rgb*(1.0-Tint.a)+(Tint.rgb*Tint.a),outColor.a*Opacity);return output;}";var t1=Bi.create(),Ui=pe.create(),Fi={type:"cobalt:overlay",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"color",type:"textView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return gu(e,t)},onRun:function(e,t,n){wu(e,t,n)},onDestroy:function(e,t){yu(t)},onResize:function(e,t){Gi(e,t)},onViewportPosition:function(e,t){Gi(e,t)},customFunctions:{...$e}};async function gu(e,t){let{device:n}=e,r=16192,i=r,s=Float32Array.BYTES_PER_ELEMENT*2,h=Float32Array.BYTES_PER_ELEMENT*2,g=Float32Array.BYTES_PER_ELEMENT*4,N=Float32Array.BYTES_PER_ELEMENT*4,q=n.createBuffer({size:(s+h+g+N)*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),m=n.createBuffer({size:64*2,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),C=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}]}),Y=n.createBindGroup({layout:C,entries:[{binding:0,resource:{buffer:m}},{binding:1,resource:t.refs.spritesheet.data.colorTexture.view},{binding:2,resource:t.refs.spritesheet.data.colorTexture.sampler},{binding:3,resource:{buffer:q}}]}),H=n.createPipelineLayout({bindGroupLayouts:[C]}),W=n.createRenderPipeline({label:"overlay",vertex:{module:n.createShaderModule({code:ln}),entryPoint:"vs_main",buffers:[t.refs.spritesheet.data.quads.bufferLayout]},fragment:{module:n.createShaderModule({code:ln}),entryPoint:"fs_main",targets:[{format:"bgra8unorm",blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:H});return{instancedDrawCalls:new Uint32Array(r*2),instancedDrawCallCount:0,spriteBuffer:q,uniformBuffer:m,pipeline:W,bindGroupLayout:C,bindGroup:Y,spriteData:new Float32Array(r*12),spriteCount:0,spriteIndices:new Map,dirty:!1}}function wu(e,t,n){let{device:r}=e,i=t.options.loadOp||"load";if(t.data.dirty&&(xu(t.data),t.data.dirty=!1),t.data.spriteCount>0){let h=t.data.spriteCount*12*Float32Array.BYTES_PER_ELEMENT;r.queue.writeBuffer(t.data.spriteBuffer,0,t.data.spriteData.buffer,0,h)}let o=n.beginRenderPass({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.refs.spritesheet.data.quads.buffer);let s=6,c=0;for(let h=0;h<t.data.instancedDrawCallCount;h++){let p=t.data.instancedDrawCalls[h*2]*s,g=t.data.instancedDrawCalls[h*2+1];o.draw(s,g,p,c),c+=g}o.end()}function xu(e){let t=-1,n=0;e.instancedDrawCallCount=0;for(let r=0;r<e.spriteCount;r++){let i=e.spriteData[r*12+11]&65535;i!==t&&(n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++),t=i,n=0),n++}n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++)}function Gi(e,t){let r=Math.round(e.viewport.width/1),i=Math.round(e.viewport.height/1),o=Et.ortho(0,r,i,0,-10,10);pe.set(0,0,0,Ui);let s=Et.translation(Ui);e.device.queue.writeBuffer(t.data.uniformBuffer,0,s.buffer),e.device.queue.writeBuffer(t.data.uniformBuffer,64,o.buffer)}function yu(e){e.data.instancedDrawCalls=null,e.data.bindGroup=null,e.data.spriteBuffer.destroy(),e.data.spriteBuffer=null,e.data.uniformBuffer.destroy(),e.data.uniformBuffer=null,e.data.spriteData=null,e.data.spriteIndices.clear(),e.data.spriteIndices=null}var pn="@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:"bgra8unorm",access:"read"},{name:"out",type:"cobaltTexture",format:"bgra8unorm",access:"write"}],onInit:async function(e,t={}){return Mu(e,t)},onRun:function(e,t,n){bu(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){Tu(e,t)},onViewportPosition:function(e,t){}};async function Mu(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:pn}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:pn}),entryPoint:"fs_main",targets:[{format:"bgra8unorm",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 bu(e,t,n){let{device:r}=e,i=n.beginRenderPass({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 Tu(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 Ii="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 fs=ni(so(),1);var cs=ni(us(),1);function Jn(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],c=r.length,h=0;h<s.length;++h)r.push(s[h]),i.push([c+h,c+(h+1)%s.length]);var p="clean"in t?!0:!!t.clean;return p&&(0,cs.default)(r,i),{points:r,edges:i}}var ls={line:Ie,save:function(e,t){t.data.transforms.push(xe.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);xe.translate(r,n,r)},rotate:function(e,t,n){let r=t.data.transforms.at(-1);xe.rotate(r,n,r)},scale:function(e,t,n){let r=t.data.transforms.at(-1);xe.scale(r,n,r)},strokePath:function(e,t,n,r,i=1){for(let o of n)Ie(e,t,o[0],o[1],r,i)},filledPath:function(e,t,n,r){let i=Jn(n),o=(0,fs.default)(i.points,i.edges,{exterior:!1}),s=t.data.transforms.at(-1),c=t.data.vertexCount*6,h=t.data.vertexCount*6,p=o.length*3*6;t.data.vertices=mr(Float32Array,t.data.vertices,h,p);let g=jt.create();for(let F of o)jt.transformMat3(n[F[0]],s,g),t.data.vertices[c+0]=g[0],t.data.vertices[c+1]=g[1],t.data.vertices[c+2]=r[0],t.data.vertices[c+3]=r[1],t.data.vertices[c+4]=r[2],t.data.vertices[c+5]=r[3],jt.transformMat3(n[F[1]],s,g),t.data.vertices[c+6]=g[0],t.data.vertices[c+7]=g[1],t.data.vertices[c+8]=r[0],t.data.vertices[c+9]=r[1],t.data.vertices[c+10]=r[2],t.data.vertices[c+11]=r[3],jt.transformMat3(n[F[2]],s,g),t.data.vertices[c+12]=g[0],t.data.vertices[c+13]=g[1],t.data.vertices[c+14]=r[0],t.data.vertices[c+15]=r[1],t.data.vertices[c+16]=r[2],t.data.vertices[c+17]=r[3],c+=18;t.data.vertexCount+=3*o.length,t.data.dirty=!0},ellipse:function(e,t,n,r,i,o,s,c=1){let[h,p]=n,g=2*Math.PI/o;for(let F=0;F<o;F++){let N=F*g,q=(F+1)*g,m=h+r*Math.cos(N),C=p+i*Math.sin(N),Y=h+r*Math.cos(q),H=p+i*Math.sin(q);Ie(e,t,[m,C],[Y,H],s,c)}},filledEllipse:function(e,t,n,r,i,o,s){let[c,h]=n,p=2*Math.PI/o,g=t.data.vertexCount*6,F=o*3*6;t.data.vertices=mr(Float32Array,t.data.vertices,g,F);let N=t.data.transforms.at(-1);for(let q=0;q<o;q++){let m=q*p,C=(q+1)*p,Y=c+r*Math.cos(m),H=h+i*Math.sin(m),W=c+r*Math.cos(C),Q=h+i*Math.sin(C),$=t.data.vertexCount*6+q*18,J=jt.transformMat3([c,h],N);t.data.vertices[$+0]=J[0],t.data.vertices[$+1]=J[1],t.data.vertices[$+2]=s[0],t.data.vertices[$+3]=s[1],t.data.vertices[$+4]=s[2],t.data.vertices[$+5]=s[3],jt.transformMat3([Y,H],N,J),t.data.vertices[$+6]=J[0],t.data.vertices[$+7]=J[1],t.data.vertices[$+8]=s[0],t.data.vertices[$+9]=s[1],t.data.vertices[$+10]=s[2],t.data.vertices[$+11]=s[3],jt.transformMat3([W,Q],N,J),t.data.vertices[$+12]=J[0],t.data.vertices[$+13]=J[1],t.data.vertices[$+14]=s[0],t.data.vertices[$+15]=s[1],t.data.vertices[$+16]=s[2],t.data.vertices[$+17]=s[3]}t.data.vertexCount+=3*o,t.data.dirty=!0},box:function(e,t,n,r,i,o,s=1){let[c,h]=n,p=r/2,g=i/2,F=[c-p,h-g],N=[c+p,h-g],q=[c-p,h+g],m=[c+p,h+g];Ie(e,t,F,N,o,s),Ie(e,t,q,m,o,s),Ie(e,t,F,q,o,s),Ie(e,t,N,m,o,s)},filledBox:function(e,t,n,r,i,o){let[s,c]=n,h=r/2,p=i/2,g=t.data.transforms.at(-1),F=jt.transformMat3([s-h,c-p],g),N=jt.transformMat3([s+h,c-p],g),q=jt.transformMat3([s-h,c+p],g),m=jt.transformMat3([s+h,c+p],g),C=t.data.vertexCount*6,Y=6*6;t.data.vertices=mr(Float32Array,t.data.vertices,C,Y);let H=t.data.vertexCount*6;t.data.vertices[H+0]=F[0],t.data.vertices[H+1]=F[1],t.data.vertices[H+2]=o[0],t.data.vertices[H+3]=o[1],t.data.vertices[H+4]=o[2],t.data.vertices[H+5]=o[3],t.data.vertices[H+6]=q[0],t.data.vertices[H+7]=q[1],t.data.vertices[H+8]=o[0],t.data.vertices[H+9]=o[1],t.data.vertices[H+10]=o[2],t.data.vertices[H+11]=o[3],t.data.vertices[H+12]=N[0],t.data.vertices[H+13]=N[1],t.data.vertices[H+14]=o[0],t.data.vertices[H+15]=o[1],t.data.vertices[H+16]=o[2],t.data.vertices[H+17]=o[3],t.data.vertices[H+18]=q[0],t.data.vertices[H+19]=q[1],t.data.vertices[H+20]=o[0],t.data.vertices[H+21]=o[1],t.data.vertices[H+22]=o[2],t.data.vertices[H+23]=o[3],t.data.vertices[H+24]=m[0],t.data.vertices[H+25]=m[1],t.data.vertices[H+26]=o[0],t.data.vertices[H+27]=o[1],t.data.vertices[H+28]=o[2],t.data.vertices[H+29]=o[3],t.data.vertices[H+30]=N[0],t.data.vertices[H+31]=N[1],t.data.vertices[H+32]=o[0],t.data.vertices[H+33]=o[1],t.data.vertices[H+34]=o[2],t.data.vertices[H+35]=o[3],t.data.vertexCount+=6,t.data.dirty=!0},clear:function(e,t){t.data.vertexCount=0,t.data.transforms.length=1,xe.identity(t.data.transforms[0]),t.data.dirty=!0}};function Ie(e,t,n,r,i,o=1){let s=t.data.transforms.at(-1);n=jt.transformMat3(n,s),r=jt.transformMat3(r,s);let c=jt.sub(r,n),h=jt.normalize(c),p=Pf(h),g=o/2,F=t.data.vertexCount*6,N=t.data.vertexCount*6,q=6*6;t.data.vertices=mr(Float32Array,t.data.vertices,N,q),t.data.vertices[F+0]=n[0]+p[0]*g,t.data.vertices[F+1]=n[1]+p[1]*g,t.data.vertices[F+2]=i[0],t.data.vertices[F+3]=i[1],t.data.vertices[F+4]=i[2],t.data.vertices[F+5]=i[3],t.data.vertices[F+6]=n[0]-p[0]*g,t.data.vertices[F+7]=n[1]-p[1]*g,t.data.vertices[F+8]=i[0],t.data.vertices[F+9]=i[1],t.data.vertices[F+10]=i[2],t.data.vertices[F+11]=i[3],t.data.vertices[F+12]=r[0]+p[0]*g,t.data.vertices[F+13]=r[1]+p[1]*g,t.data.vertices[F+14]=i[0],t.data.vertices[F+15]=i[1],t.data.vertices[F+16]=i[2],t.data.vertices[F+17]=i[3],t.data.vertices[F+18]=n[0]-p[0]*g,t.data.vertices[F+19]=n[1]-p[1]*g,t.data.vertices[F+20]=i[0],t.data.vertices[F+21]=i[1],t.data.vertices[F+22]=i[2],t.data.vertices[F+23]=i[3],t.data.vertices[F+24]=r[0]+p[0]*g,t.data.vertices[F+25]=r[1]+p[1]*g,t.data.vertices[F+26]=i[0],t.data.vertices[F+27]=i[1],t.data.vertices[F+28]=i[2],t.data.vertices[F+29]=i[3],t.data.vertices[F+30]=r[0]-p[0]*g,t.data.vertices[F+31]=r[1]-p[1]*g,t.data.vertices[F+32]=i[0],t.data.vertices[F+33]=i[1],t.data.vertices[F+34]=i[2],t.data.vertices[F+35]=i[3],t.data.vertexCount+=6,t.data.dirty=!0}function mr(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 Pf(e){return[-e[1],e[0]]}var hs=pe.create(0,0,0),vs={type:"cobalt:primitives",refs:[{name:"color",type:"textView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return Df(e,t)},onRun:function(e,t,n){Uf(e,t,n)},onDestroy:function(e,t){Gf(t)},onResize:function(e,t){ps(e,t)},onViewportPosition:function(e,t){ps(e,t)},customFunctions:ls};async function Df(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:64*2,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),s=n.createShaderModule({code:Ii}),c=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}}]}),h=n.createPipelineLayout({bindGroupLayouts:[c]}),p=n.createBindGroup({layout:c,entries:[{binding:0,resource:{buffer:o}}]}),g=n.createRenderPipeline({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:"bgra8unorm",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:[xe.identity()]}}function Uf(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 c=t.data.vertexCount*s;if(c>t.data.vertexBuffer.size){console.error("too many primitives, bailing");return}e.device.queue.writeBuffer(t.data.vertexBuffer,0,t.data.vertices.buffer,0,c)}let i=t.options.loadOp||"load",o=n.beginRenderPass({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 Gf(e){e.data.vertexBuffer.destroy(),e.data.vertexBuffer=null,e.data.uniformBuffer.destroy(),e.data.uniformBuffer=null,e.data.transforms.length=0}function ps(e,t){let{device:n}=e,r=e.viewport.width/e.viewport.zoom,i=e.viewport.height/e.viewport.zoom,o=Et.ortho(0,r,i,0,-10,10);pe.set(-e.viewport.position[0]-1,-e.viewport.position[1]-1,0,hs);let s=Et.translation(hs);n.queue.writeBuffer(t.data.uniformBuffer,0,s.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,o.buffer)}var jn={};ri(jn,{setAmbientLight:()=>Af,setLights:()=>Ff,setOccluders:()=>If});function Ff(e,t,n){t.data.lights=n,t.data.lightsBufferNeedsUpdate=!0}function Af(e,t,n){t.data.lightsRenderer.setAmbientLight(n)}function If(e,t,n){t.data.lightsRenderer.setObstacles(n),t.data.lightsTextureNeedsUpdate=!0}var Or=class{invViewProjectionMatrix=Et.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(){Et.identity(this.invViewProjectionMatrix),Et.multiply(Et.scaling([1,-1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Et.multiply(Et.translation([1,1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Et.multiply(Et.scaling([.5*this.viewportSize.width/this.zoom,.5*this.viewportSize.height/this.zoom,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Et.multiply(Et.translation([this.topLeft[0],this.topLeft[1],0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix)}};var se=class e{static structs={definition:`
1
+ var Ss=Object.create;var an=Object.defineProperty;var Bs=Object.getOwnPropertyDescriptor;var Ps=Object.getOwnPropertyNames;var Ds=Object.getPrototypeOf,Us=Object.prototype.hasOwnProperty;var xt=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),ri=(e,t)=>{for(var n in t)an(e,n,{get:t[n],enumerable:!0})},Gs=(e,t,n,r)=>{if(t&&typeof t=="object"||typeof t=="function")for(let i of Ps(t))!Us.call(e,i)&&i!==n&&an(e,i,{get:()=>t[i],enumerable:!(r=Bs(t,i))||r.enumerable});return e};var ni=(e,t,n)=>(n=e!=null?Ss(Ds(e)):{},Gs(t||!e||!e.__esModule?an(n,"default",{value:e,enumerable:!0}):n,e));var Qe=xt((a1,Ei)=>{"use strict";function _u(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h>=0?(o=s,i=s-1):r=s+1}return o}function Su(e,t,n,r,i){for(var o=i+1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h>0?(o=s,i=s-1):r=s+1}return o}function Bu(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h<0?(o=s,r=s+1):i=s-1}return o}function Pu(e,t,n,r,i){for(var o=r-1;r<=i;){var s=r+i>>>1,c=e[s],h=n!==void 0?n(c,t):c-t;h<=0?(o=s,r=s+1):i=s-1}return o}function Du(e,t,n,r,i){for(;r<=i;){var o=r+i>>>1,s=e[o],c=n!==void 0?n(s,t):s-t;if(c===0)return o;c<=0?r=o+1:i=o-1}return-1}function We(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)}Ei.exports={ge:function(e,t,n,r,i){return We(e,t,n,r,i,_u)},gt:function(e,t,n,r,i){return We(e,t,n,r,i,Su)},lt:function(e,t,n,r,i){return We(e,t,n,r,i,Bu)},le:function(e,t,n,r,i){return We(e,t,n,r,i,Pu)},eq:function(e,t,n,r,i){return We(e,t,n,r,i,Du)}}});var hr=xt((s1,zi)=>{"use strict";zi.exports=Uu;var Li=+(Math.pow(2,27)+1);function Uu(e,t,n){var r=e*t,i=Li*e,o=i-e,s=i-o,c=e-s,h=Li*t,p=h-t,g=h-p,F=t-g,N=r-s*g,q=N-c*g,m=q-s*F,C=c*F-m;return n?(n[0]=C,n[1]=r,n):[C,r]}});var vn=xt((u1,Ri)=>{"use strict";Ri.exports=Fu;function Gu(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,c=s+o;return c?[c,n]:[n]}function Fu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return Gu(e[0],t[0]);var i=n+r,o=new Array(i),s=0,c=0,h=0,p=Math.abs,g=e[c],F=p(g),N=t[h],q=p(N),m,C;F<q?(C=g,c+=1,c<n&&(g=e[c],F=p(g))):(C=N,h+=1,h<r&&(N=t[h],q=p(N))),c<n&&F<q||h>=r?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=t[h],q=p(N)));for(var Y=m+C,H=Y-m,W=C-H,Q=W,et=Y,$,J,ut,tt,rt;c<n&&h<r;)F<q?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=t[h],q=p(N))),C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$;for(;c<n;)m=g,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,c+=1,c<n&&(g=e[c]);for(;h<r;)m=N,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,h+=1,h<r&&(N=t[h]);return Q&&(o[s++]=Q),et&&(o[s++]=et),s||(o[s++]=0),o.length=s,o}});var Oi=xt((c1,mi)=>{"use strict";mi.exports=Au;function Au(e,t,n){var r=e+t,i=r-e,o=r-i,s=t-i,c=e-o;return n?(n[0]=c+s,n[1]=r,n):[c+s,r]}});var gn=xt((f1,Vi)=>{"use strict";var dn=hr(),Iu=Oi();Vi.exports=Eu;function Eu(e,t){var n=e.length;if(n===1){var r=dn(e[0],t);return r[0]?r:[r[1]]}var i=new Array(2*n),o=[.1,.1],s=[.1,.1],c=0;dn(e[0],t,o),o[0]&&(i[c++]=o[0]);for(var h=1;h<n;++h){dn(e[h],t,s);var p=o[1];Iu(p,s[0],o),o[0]&&(i[c++]=o[0]);var g=s[1],F=o[1],N=g+F,q=N-g,m=F-q;o[1]=N,m&&(i[c++]=m)}return o[1]&&(i[c++]=o[1]),c===0&&(i[c++]=0),i.length=c,i}});var wn=xt((l1,qi)=>{"use strict";qi.exports=zu;function Lu(e,t){var n=e+t,r=n-e,i=n-r,o=t-r,s=e-i,c=s+o;return c?[c,n]:[n]}function zu(e,t){var n=e.length|0,r=t.length|0;if(n===1&&r===1)return Lu(e[0],-t[0]);var i=n+r,o=new Array(i),s=0,c=0,h=0,p=Math.abs,g=e[c],F=p(g),N=-t[h],q=p(N),m,C;F<q?(C=g,c+=1,c<n&&(g=e[c],F=p(g))):(C=N,h+=1,h<r&&(N=-t[h],q=p(N))),c<n&&F<q||h>=r?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=-t[h],q=p(N)));for(var Y=m+C,H=Y-m,W=C-H,Q=W,et=Y,$,J,ut,tt,rt;c<n&&h<r;)F<q?(m=g,c+=1,c<n&&(g=e[c],F=p(g))):(m=N,h+=1,h<r&&(N=-t[h],q=p(N))),C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$;for(;c<n;)m=g,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,c+=1,c<n&&(g=e[c]);for(;h<r;)m=N,C=Q,Y=m+C,H=Y-m,W=C-H,W&&(o[s++]=W),$=et+Y,J=$-et,ut=$-J,tt=Y-J,rt=et-ut,Q=rt+tt,et=$,h+=1,h<r&&(N=-t[h]);return Q&&(o[s++]=Q),et&&(o[s++]=et),s||(o[s++]=0),o.length=s,o}});var yn=xt((h1,xn)=>{"use strict";var Ru=hr(),mu=vn(),Ou=gn(),Vu=wn(),Ni=5,pr=11102230246251565e-32,qu=(3+16*pr)*pr,Nu=(7+56*pr)*pr;function Cu(e,t,n,r){return function(o,s,c){var h=e(e(t(s[1],c[0]),t(-c[1],s[0])),e(t(o[1],s[0]),t(-s[1],o[0]))),p=e(t(o[1],c[0]),t(-c[1],o[0])),g=r(h,p);return g[g.length-1]}}function ku(e,t,n,r){return function(o,s,c,h){var p=e(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[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(c[1],h[0]),t(-h[1],c[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[1],o[0])),h[2]))),e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2])))),F=r(p,g);return F[F.length-1]}}function Yu(e,t,n,r){return function(o,s,c,h,p){var g=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),c[2]),e(n(e(t(c[1],p[0]),t(-p[1],c[0])),-h[2]),n(e(t(c[1],h[0]),t(-h[1],c[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]))),-c[3]),n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[1],s[0])),p[2]))),h[3]))),e(n(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[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(c[1],h[0]),t(-h[1],c[0])),s[2]),e(n(e(t(s[1],h[0]),t(-h[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[1],s[0])),h[2]))),o[3]))),e(n(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[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]))),c[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),-h[3]))))),F=e(e(e(n(e(n(e(t(h[1],p[0]),t(-p[1],h[0])),c[2]),e(n(e(t(c[1],p[0]),t(-p[1],c[0])),-h[2]),n(e(t(c[1],h[0]),t(-h[1],c[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]))),-c[3])),e(n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[1],o[0])),p[2]))),h[3]),n(e(n(e(t(c[1],h[0]),t(-h[1],c[0])),o[2]),e(n(e(t(o[1],h[0]),t(-h[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[1],o[0])),h[2]))),-p[3]))),e(e(n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),s[2]),e(n(e(t(s[1],p[0]),t(-p[1],s[0])),-c[2]),n(e(t(s[1],c[0]),t(-c[1],s[0])),p[2]))),o[3]),n(e(n(e(t(c[1],p[0]),t(-p[1],c[0])),o[2]),e(n(e(t(o[1],p[0]),t(-p[1],o[0])),-c[2]),n(e(t(o[1],c[0]),t(-c[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]))),c[3]),n(e(n(e(t(s[1],c[0]),t(-c[1],s[0])),o[2]),e(n(e(t(o[1],c[0]),t(-c[1],o[0])),-s[2]),n(e(t(o[1],s[0]),t(-s[1],o[0])),c[2]))),-p[3])))),N=r(g,F);return N[N.length-1]}}function vr(e){var t=e===3?Cu:e===4?ku:Yu;return t(mu,Ru,Ou,Vu)}var Xu=vr(3),Hu=vr(4),Se=[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,c;if(i>0){if(o<=0)return s;c=i+o}else if(i<0){if(o>=0)return s;c=-(i+o)}else return s;var h=qu*c;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],c=r[0]-i[0],h=t[1]-i[1],p=n[1]-i[1],g=r[1]-i[1],F=t[2]-i[2],N=n[2]-i[2],q=r[2]-i[2],m=s*g,C=c*p,Y=c*h,H=o*g,W=o*p,Q=s*h,et=F*(m-C)+N*(Y-H)+q*(W-Q),$=(Math.abs(m)+Math.abs(C))*Math.abs(F)+(Math.abs(Y)+Math.abs(H))*Math.abs(N)+(Math.abs(W)+Math.abs(Q))*Math.abs(q),J=Nu*$;return et>J||-et>J?et:Hu(t,n,r,i)}];function Zu(e){var t=Se[e.length];return t||(t=Se[e.length]=vr(e.length)),t.apply(void 0,e)}function $u(e,t,n,r,i,o,s){return function(h,p,g,F,N){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,F);case 5:return s(h,p,g,F,N)}for(var q=new Array(arguments.length),m=0;m<arguments.length;++m)q[m]=arguments[m];return e(q)}}function Wu(){for(;Se.length<=Ni;)Se.push(vr(Se.length));xn.exports=$u.apply(void 0,[Zu].concat(Se));for(var e=0;e<=Ni;++e)xn.exports[e]=Se[e]}Wu()});var Zi=xt((p1,Hi)=>{"use strict";var dr=Qe(),ye=yn()[3],bn=0,Ci=1,Mn=2;Hi.exports=t0;function Yi(e,t,n,r,i){this.a=e,this.b=t,this.idx=n,this.lowerIds=r,this.upperIds=i}function Ke(e,t,n,r){this.a=e,this.b=t,this.type=n,this.idx=r}function Qu(e,t){var n=e.a[0]-t.a[0]||e.a[1]-t.a[1]||e.type-t.type;return n||e.type!==bn&&(n=ye(e.a,e.b,t.b),n)?n:e.idx-t.idx}function ki(e,t){return ye(e.a,e.b,t)}function Ku(e,t,n,r,i){for(var o=dr.lt(t,r,ki),s=dr.gt(t,r,ki),c=o;c<s;++c){for(var h=t[c],p=h.lowerIds,F=p.length;F>1&&ye(n[p[F-2]],n[p[F-1]],r)>0;)e.push([p[F-1],p[F-2],i]),F-=1;p.length=F,p.push(i);for(var g=h.upperIds,F=g.length;F>1&&ye(n[g[F-2]],n[g[F-1]],r)<0;)e.push([g[F-2],g[F-1],i]),F-=1;g.length=F,g.push(i)}}function Xi(e,t){var n;return e.a[0]<t.a[0]?n=ye(e.a,e.b,t.a):n=ye(t.b,t.a,e.a),n||(t.b[0]<e.b[0]?n=ye(e.a,e.b,t.b):n=ye(t.b,t.a,e.b),n||e.idx-t.idx)}function Ju(e,t,n){var r=dr.le(e,n,Xi),i=e[r],o=i.upperIds,s=o[o.length-1];i.upperIds=[s],e.splice(r+1,0,new Yi(n.a,n.b,n.idx,[s],o))}function ju(e,t,n){var r=n.a;n.a=n.b,n.b=r;var i=dr.eq(e,n,Xi),o=e[i],s=e[i-1];s.upperIds=o.upperIds,e.splice(i,1)}function t0(e,t){for(var n=e.length,r=t.length,i=[],o=0;o<n;++o)i.push(new Ke(e[o],null,bn,o));for(var o=0;o<r;++o){var s=t[o],c=e[s[0]],h=e[s[1]];c[0]<h[0]?i.push(new Ke(c,h,Mn,o),new Ke(h,c,Ci,o)):c[0]>h[0]&&i.push(new Ke(h,c,Mn,o),new Ke(c,h,Ci,o))}i.sort(Qu);for(var p=i[0].a[0]-(1+Math.abs(i[0].a[0]))*Math.pow(2,-52),g=[new Yi([p,1],[p,0],-1,[],[],[],[])],F=[],o=0,N=i.length;o<N;++o){var q=i[o],m=q.type;m===bn?Ku(F,g,e,q.a,q.idx):m===Mn?Ju(g,e,q):ju(g,e,q)}return F}});var Qi=xt((v1,Wi)=>{"use strict";var e0=Qe();Wi.exports=r0;function $i(e,t){this.stars=e,this.edges=t}var Be=$i.prototype;function Tn(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}}Be.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),e0.eq(this.edges,e,t)>=0}})();Be.removeTriangle=function(e,t,n){var r=this.stars;Tn(r[e],t,n),Tn(r[t],n,e),Tn(r[n],e,t)};Be.addTriangle=function(e,t,n){var r=this.stars;r[e].push(t,n),r[t].push(n,e),r[n].push(e,t)};Be.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};Be.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)};Be.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};Be.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 c=i[o],h=i[o+1];n<Math.min(c,h)&&t.push([n,c,h])}return t};function r0(e,t){for(var n=new Array(e),r=0;r<e;++r)n[r]=[];return new $i(n,t)}});var ji=xt((d1,_n)=>{"use strict";var n0=hr(),i0=vn(),o0=wn(),a0=gn(),Ki=6;function Ji(e){var t=e===3?f0:e===4?l0:e===5?h0:p0;return t(i0,o0,n0,a0)}function s0(){return 0}function u0(){return 0}function c0(){return 0}function f0(e,t,n,r){function i(o,s,c){var h=n(o[0],o[0]),p=r(h,s[0]),g=r(h,c[0]),F=n(s[0],s[0]),N=r(F,o[0]),q=r(F,c[0]),m=n(c[0],c[0]),C=r(m,o[0]),Y=r(m,s[0]),H=e(t(Y,q),t(N,p)),W=t(C,g),Q=t(H,W);return Q[Q.length-1]}return i}function l0(e,t,n,r){function i(o,s,c,h){var p=e(n(o[0],o[0]),n(o[1],o[1])),g=r(p,s[0]),F=r(p,c[0]),N=r(p,h[0]),q=e(n(s[0],s[0]),n(s[1],s[1])),m=r(q,o[0]),C=r(q,c[0]),Y=r(q,h[0]),H=e(n(c[0],c[0]),n(c[1],c[1])),W=r(H,o[0]),Q=r(H,s[0]),et=r(H,h[0]),$=e(n(h[0],h[0]),n(h[1],h[1])),J=r($,o[0]),ut=r($,s[0]),tt=r($,c[0]),rt=e(e(r(t(tt,et),s[1]),e(r(t(ut,Y),-c[1]),r(t(Q,C),h[1]))),e(r(t(ut,Y),o[1]),e(r(t(J,N),-s[1]),r(t(m,g),h[1])))),D=e(e(r(t(tt,et),o[1]),e(r(t(J,N),-c[1]),r(t(W,F),h[1]))),e(r(t(Q,C),o[1]),e(r(t(W,F),-s[1]),r(t(m,g),c[1])))),a=t(rt,D);return a[a.length-1]}return i}function h0(e,t,n,r){function i(o,s,c,h,p){var g=e(n(o[0],o[0]),e(n(o[1],o[1]),n(o[2],o[2]))),F=r(g,s[0]),N=r(g,c[0]),q=r(g,h[0]),m=r(g,p[0]),C=e(n(s[0],s[0]),e(n(s[1],s[1]),n(s[2],s[2]))),Y=r(C,o[0]),H=r(C,c[0]),W=r(C,h[0]),Q=r(C,p[0]),et=e(n(c[0],c[0]),e(n(c[1],c[1]),n(c[2],c[2]))),$=r(et,o[0]),J=r(et,s[0]),ut=r(et,h[0]),tt=r(et,p[0]),rt=e(n(h[0],h[0]),e(n(h[1],h[1]),n(h[2],h[2]))),D=r(rt,o[0]),a=r(rt,s[0]),v=r(rt,c[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]),E=r(M,s[0]),R=r(M,c[0]),P=r(M,h[0]),l=e(e(e(r(e(r(t(P,T),c[1]),e(r(t(R,tt),-h[1]),r(t(v,ut),p[1]))),s[2]),e(r(e(r(t(P,T),s[1]),e(r(t(E,Q),-h[1]),r(t(a,W),p[1]))),-c[2]),r(e(r(t(R,tt),s[1]),e(r(t(E,Q),-c[1]),r(t(J,H),p[1]))),h[2]))),e(r(e(r(t(v,ut),s[1]),e(r(t(a,W),-c[1]),r(t(J,H),h[1]))),-p[2]),e(r(e(r(t(P,T),s[1]),e(r(t(E,Q),-h[1]),r(t(a,W),p[1]))),o[2]),r(e(r(t(P,T),o[1]),e(r(t(S,m),-h[1]),r(t(D,q),p[1]))),-s[2])))),e(e(r(e(r(t(E,Q),o[1]),e(r(t(S,m),-s[1]),r(t(Y,F),p[1]))),h[2]),e(r(e(r(t(a,W),o[1]),e(r(t(D,q),-s[1]),r(t(Y,F),h[1]))),-p[2]),r(e(r(t(v,ut),s[1]),e(r(t(a,W),-c[1]),r(t(J,H),h[1]))),o[2]))),e(r(e(r(t(v,ut),o[1]),e(r(t(D,q),-c[1]),r(t($,N),h[1]))),-s[2]),e(r(e(r(t(a,W),o[1]),e(r(t(D,q),-s[1]),r(t(Y,F),h[1]))),c[2]),r(e(r(t(J,H),o[1]),e(r(t($,N),-s[1]),r(t(Y,F),c[1]))),-h[2]))))),G=e(e(e(r(e(r(t(P,T),c[1]),e(r(t(R,tt),-h[1]),r(t(v,ut),p[1]))),o[2]),r(e(r(t(P,T),o[1]),e(r(t(S,m),-h[1]),r(t(D,q),p[1]))),-c[2])),e(r(e(r(t(R,tt),o[1]),e(r(t(S,m),-c[1]),r(t($,N),p[1]))),h[2]),r(e(r(t(v,ut),o[1]),e(r(t(D,q),-c[1]),r(t($,N),h[1]))),-p[2]))),e(e(r(e(r(t(R,tt),s[1]),e(r(t(E,Q),-c[1]),r(t(J,H),p[1]))),o[2]),r(e(r(t(R,tt),o[1]),e(r(t(S,m),-c[1]),r(t($,N),p[1]))),-s[2])),e(r(e(r(t(E,Q),o[1]),e(r(t(S,m),-s[1]),r(t(Y,F),p[1]))),c[2]),r(e(r(t(J,H),o[1]),e(r(t($,N),-s[1]),r(t(Y,F),c[1]))),-p[2])))),ot=t(l,G);return ot[ot.length-1]}return i}function p0(e,t,n,r){function i(o,s,c,h,p,g){var F=e(e(n(o[0],o[0]),n(o[1],o[1])),e(n(o[2],o[2]),n(o[3],o[3]))),N=r(F,s[0]),q=r(F,c[0]),m=r(F,h[0]),C=r(F,p[0]),Y=r(F,g[0]),H=e(e(n(s[0],s[0]),n(s[1],s[1])),e(n(s[2],s[2]),n(s[3],s[3]))),W=r(H,o[0]),Q=r(H,c[0]),et=r(H,h[0]),$=r(H,p[0]),J=r(H,g[0]),ut=e(e(n(c[0],c[0]),n(c[1],c[1])),e(n(c[2],c[2]),n(c[3],c[3]))),tt=r(ut,o[0]),rt=r(ut,s[0]),D=r(ut,h[0]),a=r(ut,p[0]),v=r(ut,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]),E=r(T,c[0]),R=r(T,p[0]),P=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,c[0]),st=r(l,h[0]),ct=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]),Z=r(yt,c[0]),U=r(yt,h[0]),f=r(yt,p[0]),b=e(e(e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),c[2]),r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),p[2]),r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),-g[2]))),s[3]),e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-h[2])),e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),p[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-g[2]))),-c[3]),r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),s[2]),r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),s[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-c[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-h[2])),e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),p[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-h[2])),e(r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),p[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),p[2]),r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),-g[2]))),h[3]),r(e(e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),s[2]),r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-g[2]))),o[3]))),e(e(r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-g[2]))),-s[3]),r(e(e(r(e(r(t(U,P),s[1]),e(r(t(k,J),-h[1]),r(t(S,et),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-g[2]))),c[3])),e(r(e(e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-g[2]))),-h[3]),r(e(e(r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-s[2])),e(r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-h[2]))),g[3]))))),w=e(e(e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),c[2]),r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),-h[2])),e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),p[2]),r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),-g[2]))),o[3]),e(r(e(e(r(e(r(t(f,ct),h[1]),e(r(t(U,P),-p[1]),r(t(st,R),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-h[2])),e(r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),p[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-g[2]))),-c[3]),r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-g[2]))),h[3]))),e(e(r(e(e(r(e(r(t(U,P),c[1]),e(r(t(Z,v),-h[1]),r(t(E,D),g[1]))),o[2]),r(e(r(t(U,P),o[1]),e(r(t(pt,Y),-h[1]),r(t(M,m),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-g[2]))),-p[3]),r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-c[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-p[2]))),g[3])),e(r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),s[2]),r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),-c[2])),e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),p[2]),r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),-g[2]))),o[3]),r(e(e(r(e(r(t(f,ct),c[1]),e(r(t(Z,v),-p[1]),r(t(at,a),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-c[2])),e(r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),p[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-g[2]))),-s[3])))),e(e(e(r(e(e(r(e(r(t(f,ct),s[1]),e(r(t(k,J),-p[1]),r(t(ot,$),g[1]))),o[2]),r(e(r(t(f,ct),o[1]),e(r(t(pt,Y),-p[1]),r(t(G,C),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),p[2]),r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),-g[2]))),c[3]),r(e(e(r(e(r(t(Z,v),s[1]),e(r(t(k,J),-c[1]),r(t(rt,Q),g[1]))),o[2]),r(e(r(t(Z,v),o[1]),e(r(t(pt,Y),-c[1]),r(t(tt,q),g[1]))),-s[2])),e(r(e(r(t(k,J),o[1]),e(r(t(pt,Y),-s[1]),r(t(W,N),g[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-g[2]))),-p[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-p[2]))),g[3]),r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),s[2]),r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),-c[2])),e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),h[2]),r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),-p[2]))),o[3]))),e(e(r(e(e(r(e(r(t(st,R),c[1]),e(r(t(at,a),-h[1]),r(t(E,D),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-c[2])),e(r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),h[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-p[2]))),-s[3]),r(e(e(r(e(r(t(st,R),s[1]),e(r(t(ot,$),-h[1]),r(t(S,et),p[1]))),o[2]),r(e(r(t(st,R),o[1]),e(r(t(G,C),-h[1]),r(t(M,m),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),h[2]),r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),-p[2]))),c[3])),e(r(e(e(r(e(r(t(at,a),s[1]),e(r(t(ot,$),-c[1]),r(t(rt,Q),p[1]))),o[2]),r(e(r(t(at,a),o[1]),e(r(t(G,C),-c[1]),r(t(tt,q),p[1]))),-s[2])),e(r(e(r(t(ot,$),o[1]),e(r(t(G,C),-s[1]),r(t(W,N),p[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-p[2]))),-h[3]),r(e(e(r(e(r(t(E,D),s[1]),e(r(t(S,et),-c[1]),r(t(rt,Q),h[1]))),o[2]),r(e(r(t(E,D),o[1]),e(r(t(M,m),-c[1]),r(t(tt,q),h[1]))),-s[2])),e(r(e(r(t(S,et),o[1]),e(r(t(M,m),-s[1]),r(t(W,N),h[1]))),c[2]),r(e(r(t(rt,Q),o[1]),e(r(t(tt,q),-s[1]),r(t(W,N),c[1]))),-h[2]))),p[3]))))),I=t(b,w);return I[I.length-1]}return i}var Pe=[s0,u0,c0];function v0(e){var t=Pe[e.length];return t||(t=Pe[e.length]=Ji(e.length)),t.apply(void 0,e)}function d0(e,t,n,r,i,o,s,c){function h(p,g,F,N,q,m){switch(arguments.length){case 0:case 1:return 0;case 2:return r(p,g);case 3:return i(p,g,F);case 4:return o(p,g,F,N);case 5:return s(p,g,F,N,q);case 6:return c(p,g,F,N,q,m)}for(var C=new Array(arguments.length),Y=0;Y<arguments.length;++Y)C[Y]=arguments[Y];return e(C)}return h}function g0(){for(;Pe.length<=Ki;)Pe.push(Ji(Pe.length));_n.exports=d0.apply(void 0,[v0].concat(Pe));for(var e=0;e<=Ki;++e)_n.exports[e]=Pe[e]}g0()});var eo=xt((w1,to)=>{"use strict";var Sn=ji()[4],g1=Qe();to.exports=w0;function gr(e,t,n,r,i,o){var s=t.opposite(r,i);if(!(s<0)){if(i<r){var c=r;r=i,i=c,c=o,o=s,s=c}t.isConstraint(r,i)||Sn(e[r],e[i],e[o],e[s])<0&&n.push(r,i)}}function w0(e,t){for(var n=[],r=e.length,i=t.stars,o=0;o<r;++o)for(var s=i[o],c=1;c<s.length;c+=2){var h=s[c];if(!(h<o)&&!t.isConstraint(o,h)){for(var p=s[c-1],g=-1,F=1;F<s.length;F+=2)if(s[F-1]===h){g=s[F];break}g<0||Sn(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],N=1;N<s.length;N+=2){var q=s[N-1],m=s[N];q===h?g=m:m===h&&(p=q)}p<0||g<0||Sn(e[o],e[h],e[p],e[g])>=0||(t.flip(o,h),gr(e,t,n,p,o,g),gr(e,t,n,o,g,p),gr(e,t,n,g,h,p),gr(e,t,n,h,p,g))}}});var oo=xt((x1,io)=>{"use strict";var x0=Qe();io.exports=T0;function ro(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 y0=ro.prototype;function no(e,t){return e[0]-t[0]||e[1]-t[1]||e[2]-t[2]}y0.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,x0.eq(this.cells,e,no))}})();function M0(e,t){for(var n=e.cells(),r=n.length,i=0;i<r;++i){var o=n[i],s=o[0],c=o[1],h=o[2];c<h?c<s&&(o[0]=c,o[1]=h,o[2]=s):h<s&&(o[0]=h,o[1]=s,o[2]=c)}n.sort(no);for(var p=new Array(r),i=0;i<p.length;++i)p[i]=0;var g=[],F=[],N=new Array(3*r),q=new Array(3*r),m=null;t&&(m=[]);for(var C=new ro(n,N,q,p,g,F,m),i=0;i<r;++i)for(var o=n[i],Y=0;Y<3;++Y){var s=o[Y],c=o[(Y+1)%3],H=N[3*i+Y]=C.locate(c,s,e.opposite(c,s)),W=q[3*i+Y]=e.isConstraint(s,c);H<0&&(W?F.push(i):(g.push(i),p[i]=1),t&&m.push([c,s,-1]))}return C}function b0(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 T0(e,t,n){var r=M0(e,n);if(t===0)return n?r.cells.concat(r.boundary):r.cells;for(var i=1,o=r.active,s=r.next,c=r.flags,h=r.cells,p=r.constraint,g=r.neighbor;o.length>0||s.length>0;){for(;o.length>0;){var F=o.pop();if(c[F]!==-i){c[F]=i;for(var N=h[F],q=0;q<3;++q){var m=g[3*F+q];m>=0&&c[m]===0&&(p[3*F+q]?s.push(m):(o.push(m),c[m]=i))}}}var C=s;s=o,o=C,s.length=0,i=-i}var Y=b0(h,c,t);return n?Y.concat(r.boundary):Y}});var so=xt((y1,ao)=>{"use strict";var _0=Zi(),S0=Qi(),B0=eo(),Bn=oo();ao.exports=G0;function P0(e){return[Math.min(e[0],e[1]),Math.max(e[0],e[1])]}function D0(e,t){return e[0]-t[0]||e[1]-t[1]}function U0(e){return e.map(P0).sort(D0)}function wr(e,t,n){return t in e?e[t]:n}function G0(e,t,n){Array.isArray(t)?(n=n||{},t=t||[]):(n=t||{},t=[]);var r=!!wr(n,"delaunay",!0),i=!!wr(n,"interior",!0),o=!!wr(n,"exterior",!0),s=!!wr(n,"infinity",!1);if(!i&&!o||e.length===0)return[];var c=_0(e,t);if(r||i!==o||s){for(var h=S0(e.length,U0(t)),p=0;p<c.length;++p){var g=c[p];h.addTriangle(g[0],g[1],g[2])}return r&&B0(e,h),o?i?s?Bn(h,0,s):h.cells():Bn(h,1,s):Bn(h,-1)}else return c}});var fo=xt((M1,co)=>{"use strict";"use restrict";co.exports=uo;function uo(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 xr=uo.prototype;Object.defineProperty(xr,"length",{get:function(){return this.roots.length}});xr.makeSet=function(){var e=this.roots.length;return this.roots.push(e),this.ranks.push(0),e};xr.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};xr.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],c=i[r];s<c?o[n]=r:c<s?o[r]=n:(o[r]=n,++i[n])}}});var je=xt(Nt=>{"use strict";"use restrict";var Pn=32;Nt.INT_BITS=Pn;Nt.INT_MAX=2147483647;Nt.INT_MIN=-1<<Pn-1;Nt.sign=function(e){return(e>0)-(e<0)};Nt.abs=function(e){var t=e>>Pn-1;return(e^t)-t};Nt.min=function(e,t){return t^(e^t)&-(e<t)};Nt.max=function(e,t){return e^(e^t)&-(e<t)};Nt.isPow2=function(e){return!(e&e-1)&&!!e};Nt.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};Nt.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};Nt.popCount=function(e){return e=e-(e>>>1&1431655765),e=(e&858993459)+(e>>>2&858993459),(e+(e>>>4)&252645135)*16843009>>>24};function lo(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}Nt.countTrailingZeros=lo;Nt.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};Nt.prevPow2=function(e){return e|=e>>>1,e|=e>>>2,e|=e>>>4,e|=e>>>8,e|=e>>>16,e-(e>>>1)};Nt.parity=function(e){return e^=e>>>16,e^=e>>>8,e^=e>>>4,e&=15,27030>>>e&1};var Je=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}})(Je);Nt.reverse=function(e){return Je[e&255]<<24|Je[e>>>8&255]<<16|Je[e>>>16&255]<<8|Je[e>>>24&255]};Nt.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};Nt.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};Nt.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};Nt.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};Nt.nextCombination=function(e){var t=e|e-1;return t+1|(~t&-~t)-1>>>lo(e)+1}});var vo=xt((T1,po)=>{"use strict";function ho(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]=ho(e,t,n+1);return i}function F0(e,t){var n,r;for(n=new Array(e),r=0;r<e;++r)n[r]=t;return n}function A0(e,t){switch(typeof t>"u"&&(t=0),typeof e){case"number":if(e>0)return F0(e|0,t);break;case"object":if(typeof e.length=="number")return ho(e,t,0);break}return[]}po.exports=A0});var br=xt(It=>{"use strict";var yr=je(),te=vo();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 I0=typeof Uint8ClampedArray<"u",E0=typeof BigUint64Array<"u",L0=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 Mr=Qt.DATA;It.free=function(t){if(Object.prototype.toString.call(t)!=="[object ArrayBuffer]"&&(t=t.buffer),!!t){var n=t.length||t.byteLength,r=yr.log2(n)|0;Mr[r].push(t)}};function go(e){if(e){var t=e.length||e.byteLength,n=yr.log2(t);Mr[n].push(e)}}function z0(e){go(e.buffer)}It.freeUint8=It.freeUint16=It.freeUint32=It.freeBigUint64=It.freeInt8=It.freeInt16=It.freeInt32=It.freeBigInt64=It.freeFloat32=It.freeFloat=It.freeFloat64=It.freeDouble=It.freeUint8Clamped=It.freeDataView=z0;It.freeArrayBuffer=go;It.malloc=function(t,n){if(n===void 0||n==="arraybuffer")return ie(t);switch(n){case"uint8":return Dn(t);case"uint16":return wo(t);case"uint32":return xo(t);case"int8":return yo(t);case"int16":return Mo(t);case"int32":return bo(t);case"float":case"float32":return To(t);case"double":case"float64":return _o(t);case"uint8_clamped":return So(t);case"bigint64":return Po(t);case"biguint64":return Bo(t);case"data":case"dataview":return Do(t);default:return null}return null};function ie(t){var t=yr.nextPow2(t),n=yr.log2(t),r=Mr[n];return r.length>0?r.pop():new ArrayBuffer(t)}It.mallocArrayBuffer=ie;function Dn(e){return new Uint8Array(ie(e),0,e)}It.mallocUint8=Dn;function wo(e){return new Uint16Array(ie(2*e),0,e)}It.mallocUint16=wo;function xo(e){return new Uint32Array(ie(4*e),0,e)}It.mallocUint32=xo;function yo(e){return new Int8Array(ie(e),0,e)}It.mallocInt8=yo;function Mo(e){return new Int16Array(ie(2*e),0,e)}It.mallocInt16=Mo;function bo(e){return new Int32Array(ie(4*e),0,e)}It.mallocInt32=bo;function To(e){return new Float32Array(ie(4*e),0,e)}It.mallocFloat32=It.mallocFloat=To;function _o(e){return new Float64Array(ie(8*e),0,e)}It.mallocFloat64=It.mallocDouble=_o;function So(e){return I0?new Uint8ClampedArray(ie(e),0,e):Dn(e)}It.mallocUint8Clamped=So;function Bo(e){return E0?new BigUint64Array(ie(8*e),0,e):null}It.mallocBigUint64=Bo;function Po(e){return L0?new BigInt64Array(ie(8*e),0,e):null}It.mallocBigInt64=Po;function Do(e){return new DataView(ie(e),0,e)}It.mallocDataView=Do;It.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,Mr[t].length=0}});var Io=xt((S1,Ao)=>{"use strict";Ao.exports=R0;var _r=32;function R0(e,t){t<=4*_r?Sr(0,t-1,e):Br(0,t-1,e)}function Sr(e,t,n){for(var r=2*(e+1),i=e+1;i<=t;++i){for(var o=n[r++],s=n[r++],c=i,h=r-2;c-- >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 Uo(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 Go(e,t,n){e*=2,t*=2,n[e]=n[t],n[e+1]=n[t+1]}function m0(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 Fo(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 ve(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 Tr(e,t,n,r){e*=2;var i=r[e];return i<t?!0:i===t?r[e+1]<n:!1}function Br(e,t,n){var r=(t-e+1)/6|0,i=e+r,o=t-r,s=e+t>>1,c=s-r,h=s+r,p=i,g=c,F=s,N=h,q=o,m=e+1,C=t-1,Y=0;ve(p,g,n)&&(Y=p,p=g,g=Y),ve(N,q,n)&&(Y=N,N=q,q=Y),ve(p,F,n)&&(Y=p,p=F,F=Y),ve(g,F,n)&&(Y=g,g=F,F=Y),ve(p,N,n)&&(Y=p,p=N,N=Y),ve(F,N,n)&&(Y=F,F=N,N=Y),ve(g,q,n)&&(Y=g,g=q,q=Y),ve(g,F,n)&&(Y=g,g=F,F=Y),ve(N,q,n)&&(Y=N,N=q,q=Y);for(var H=n[2*g],W=n[2*g+1],Q=n[2*N],et=n[2*N+1],$=2*p,J=2*F,ut=2*q,tt=2*i,rt=2*s,D=2*o,a=0;a<2;++a){var v=n[$+a],T=n[J+a],M=n[ut+a];n[tt+a]=v,n[rt+a]=T,n[D+a]=M}Go(c,e,n),Go(h,t,n);for(var S=m;S<=C;++S)if(Tr(S,H,W,n))S!==m&&Uo(S,m,n),++m;else if(!Tr(S,Q,et,n))for(;;)if(Tr(C,Q,et,n)){Tr(C,H,W,n)?(m0(S,m,C,n),++m,--C):(Uo(S,C,n),--C);break}else{if(--C<S)break;continue}Fo(e,m-1,H,W,n),Fo(t,C+1,Q,et,n),m-2-e<=_r?Sr(e,m-2,n):Br(e,m-2,n),t-(C+2)<=_r?Sr(C+2,t,n):Br(C+2,t,n),C-m<=_r?Sr(m,C,n):Br(m,C,n)}});var Un=xt((B1,Eo)=>{"use strict";Eo.exports={init:V0,sweepBipartite:q0,sweepComplete:N0,scanBipartite:C0,scanComplete:k0};var Yt=br(),O0=je(),Pr=Io(),ae=1<<28,Ue=1024,Kt=Yt.mallocInt32(Ue),de=Yt.mallocInt32(Ue),ge=Yt.mallocInt32(Ue),De=Yt.mallocInt32(Ue),me=Yt.mallocInt32(Ue),tr=Yt.mallocInt32(Ue),_t=Yt.mallocDouble(Ue*8);function V0(e){var t=O0.nextPow2(e);Kt.length<t&&(Yt.free(Kt),Kt=Yt.mallocInt32(t)),de.length<t&&(Yt.free(de),de=Yt.mallocInt32(t)),ge.length<t&&(Yt.free(ge),ge=Yt.mallocInt32(t)),De.length<t&&(Yt.free(De),De=Yt.mallocInt32(t)),me.length<t&&(Yt.free(me),me=Yt.mallocInt32(t)),tr.length<t&&(Yt.free(tr),tr=Yt.mallocInt32(t));var n=8*t;_t.length<n&&(Yt.free(_t),_t=Yt.mallocDouble(n))}function Oe(e,t,n,r){var i=t[r],o=e[n-1];e[i]=o,t[o]=i}function Ve(e,t,n,r){e[n]=r,t[r]=n}function q0(e,t,n,r,i,o,s,c,h,p){for(var g=0,F=2*e,N=e-1,q=F-1,m=n;m<r;++m){var C=o[m],Y=F*m;_t[g++]=i[Y+N],_t[g++]=-(C+1),_t[g++]=i[Y+q],_t[g++]=C}for(var m=s;m<c;++m){var C=p[m]+ae,H=F*m;_t[g++]=h[H+N],_t[g++]=-C,_t[g++]=h[H+q],_t[g++]=C}var W=g>>>1;Pr(_t,W);for(var Q=0,et=0,m=0;m<W;++m){var $=_t[2*m+1]|0;if($>=ae)$=$-ae|0,Oe(ge,De,et--,$);else if($>=0)Oe(Kt,de,Q--,$);else if($<=-ae){$=-$-ae|0;for(var J=0;J<Q;++J){var ut=t(Kt[J],$);if(ut!==void 0)return ut}Ve(ge,De,et++,$)}else{$=-$-1|0;for(var J=0;J<et;++J){var ut=t($,ge[J]);if(ut!==void 0)return ut}Ve(Kt,de,Q++,$)}}}function N0(e,t,n,r,i,o,s,c,h,p){for(var g=0,F=2*e,N=e-1,q=F-1,m=n;m<r;++m){var C=o[m]+1<<1,Y=F*m;_t[g++]=i[Y+N],_t[g++]=-C,_t[g++]=i[Y+q],_t[g++]=C}for(var m=s;m<c;++m){var C=p[m]+1<<1,H=F*m;_t[g++]=h[H+N],_t[g++]=-C|1,_t[g++]=h[H+q],_t[g++]=C|1}var W=g>>>1;Pr(_t,W);for(var Q=0,et=0,$=0,m=0;m<W;++m){var J=_t[2*m+1]|0,ut=J&1;if(m<W-1&&J>>1===_t[2*m+3]>>1&&(ut=2,m+=1),J<0){for(var tt=-(J>>1)-1,rt=0;rt<$;++rt){var D=t(me[rt],tt);if(D!==void 0)return D}if(ut!==0)for(var rt=0;rt<Q;++rt){var D=t(Kt[rt],tt);if(D!==void 0)return D}if(ut!==1)for(var rt=0;rt<et;++rt){var D=t(ge[rt],tt);if(D!==void 0)return D}ut===0?Ve(Kt,de,Q++,tt):ut===1?Ve(ge,De,et++,tt):ut===2&&Ve(me,tr,$++,tt)}else{var tt=(J>>1)-1;ut===0?Oe(Kt,de,Q--,tt):ut===1?Oe(ge,De,et--,tt):ut===2&&Oe(me,tr,$--,tt)}}}function C0(e,t,n,r,i,o,s,c,h,p,g,F){var N=0,q=2*e,m=t,C=t+e,Y=1,H=1;r?H=ae:Y=ae;for(var W=i;W<o;++W){var Q=W+Y,et=q*W;_t[N++]=s[et+m],_t[N++]=-Q,_t[N++]=s[et+C],_t[N++]=Q}for(var W=h;W<p;++W){var Q=W+H,$=q*W;_t[N++]=g[$+m],_t[N++]=-Q}var J=N>>>1;Pr(_t,J);for(var ut=0,W=0;W<J;++W){var tt=_t[2*W+1]|0;if(tt<0){var Q=-tt,rt=!1;if(Q>=ae?(rt=!r,Q-=ae):(rt=!!r,Q-=1),rt)Ve(Kt,de,ut++,Q);else{var D=F[Q],a=q*Q,v=g[a+t+1],T=g[a+t+1+e];t:for(var M=0;M<ut;++M){var S=Kt[M],E=q*S;if(!(T<s[E+t+1]||s[E+t+1+e]<v)){for(var R=t+2;R<e;++R)if(g[a+R+e]<s[E+R]||s[E+R+e]<g[a+R])continue t;var P=c[S],l;if(r?l=n(D,P):l=n(P,D),l!==void 0)return l}}}}else Oe(Kt,de,ut--,tt-Y)}}function k0(e,t,n,r,i,o,s,c,h,p,g){for(var F=0,N=2*e,q=t,m=t+e,C=r;C<i;++C){var Y=C+ae,H=N*C;_t[F++]=o[H+q],_t[F++]=-Y,_t[F++]=o[H+m],_t[F++]=Y}for(var C=c;C<h;++C){var Y=C+1,W=N*C;_t[F++]=p[W+q],_t[F++]=-Y}var Q=F>>>1;Pr(_t,Q);for(var et=0,C=0;C<Q;++C){var $=_t[2*C+1]|0;if($<0){var Y=-$;if(Y>=ae)Kt[et++]=Y-ae;else{Y-=1;var J=g[Y],ut=N*Y,tt=p[ut+t+1],rt=p[ut+t+1+e];t:for(var D=0;D<et;++D){var a=Kt[D],v=s[a];if(v===J)break;var T=N*a;if(!(rt<o[T+t+1]||o[T+t+1+e]<tt)){for(var M=t+2;M<e;++M)if(p[ut+M+e]<o[T+M]||o[T+M+e]<p[ut+M])continue t;var S=n(v,J);if(S!==void 0)return S}}}}else{for(var Y=$-ae,D=et-1;D>=0;--D)if(Kt[D]===Y){for(var M=D+1;M<et;++M)Kt[M-1]=Kt[M];break}--et}}}});var Oo=xt(zn=>{"use strict";var Ge="d",Ce="ax",Lo="vv",Gn="fp",er="es",Dr="rs",En="re",rr="rb",zo="ri",qe="rp",Ur="bs",Ln="be",nr="bb",Ro="bi",Ne="bp",Fn="rv",An="Q",In=[Ge,Ce,Lo,Dr,En,rr,zo,Ur,Ln,nr,Ro];function Y0(e,t,n){var r="bruteForce"+(e?"Red":"Blue")+(t?"Flip":"")+(n?"Full":""),i=["function ",r,"(",In.join(),"){","var ",er,"=2*",Ge,";"],o="for(var i="+Dr+","+qe+"="+er+"*"+Dr+";i<"+En+";++i,"+qe+"+="+er+"){var x0="+rr+"["+Ce+"+"+qe+"],x1="+rr+"["+Ce+"+"+qe+"+"+Ge+"],xi="+zo+"[i];",s="for(var j="+Ur+","+Ne+"="+er+"*"+Ur+";j<"+Ln+";++j,"+Ne+"+="+er+"){var y0="+nr+"["+Ce+"+"+Ne+"],"+(n?"y1="+nr+"["+Ce+"+"+Ne+"+"+Ge+"],":"")+"yi="+Ro+"[j];";return e?i.push(o,An,":",s):i.push(s,An,":",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="+Ce+"+1;k<"+Ge+";++k){var r0="+rr+"[k+"+qe+"],r1="+rr+"[k+"+Ge+"+"+qe+"],b0="+nr+"[k+"+Ne+"],b1="+nr+"[k+"+Ge+"+"+Ne+"];if(r1<b0||b1<r0)continue "+An+";}var "+Fn+"="+Lo+"("),t?i.push("yi,xi"):i.push("xi,yi"),i.push(");if("+Fn+"!==void 0)return "+Fn+";}}}"),{name:r,code:i.join("")}}function mo(e){var t="bruteForce"+(e?"Full":"Partial"),n=[],r=In.slice();e||r.splice(3,0,Gn);var i=["function "+t+"("+r.join()+"){"];function o(h,p){var g=Y0(h,p,e);n.push(g.code),i.push("return "+g.name+"("+In.join()+");")}i.push("if("+En+"-"+Dr+">"+Ln+"-"+Ur+"){"),e?(o(!0,!1),i.push("}else{"),o(!1,!1)):(i.push("if("+Gn+"){"),o(!0,!0),i.push("}else{"),o(!0,!1),i.push("}}else{if("+Gn+"){"),o(!1,!0),i.push("}else{"),o(!1,!1),i.push("}")),i.push("}}return "+t);var s=n.join("")+i.join(""),c=new Function(s);return c()}zn.partial=mo(!1);zn.full=mo(!0)});var Rn=xt((D1,Vo)=>{"use strict";Vo.exports=H0;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 H0(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 Co=xt((U1,No)=>{"use strict";No.exports=Q0;var Z0=Rn(),qo=Z0("lo<p0",["p0"]),$0=8;function W0(e,t,n,r,i,o){for(var s=2*e,c=s*(n+1)+t,h=n+1;h<r;++h,c+=s)for(var p=i[c],g=h,F=s*(h-1);g>n&&i[F+t]>p;--g,F-=s){for(var N=F,q=F+s,m=0;m<s;++m,++N,++q){var C=i[N];i[N]=i[q],i[q]=C}var Y=o[g];o[g]=o[g-1],o[g-1]=Y}}function Q0(e,t,n,r,i,o){if(r<=n+1)return n;for(var s=n,c=r,h=r+n>>>1,p=2*e,g=h,F=i[p*h+t];s<c;){if(c-s<$0){W0(e,t,s,c,i,o),F=i[p*h+t];break}var N=c-s,q=Math.random()*N+s|0,m=i[p*q+t],C=Math.random()*N+s|0,Y=i[p*C+t],H=Math.random()*N+s|0,W=i[p*H+t];m<=Y?W>=Y?(g=C,F=Y):m>=W?(g=q,F=m):(g=H,F=W):Y>=W?(g=C,F=Y):W>=m?(g=q,F=m):(g=H,F=W);for(var $=p*(c-1),J=p*g,Q=0;Q<p;++Q,++$,++J){var et=i[$];i[$]=i[J],i[J]=et}var ut=o[c-1];o[c-1]=o[g],o[g]=ut,g=qo(e,t,s,c-1,i,o,F);for(var $=p*(c-1),J=p*g,Q=0;Q<p;++Q,++$,++J){var et=i[$];i[$]=i[J],i[J]=et}var ut=o[c-1];if(o[c-1]=o[g],o[g]=ut,h<g){for(c=g-1;s<c&&i[p*(c-1)+t]===F;)c-=1;c+=1}else if(g<h)for(s=g+1;s<c&&i[p*s+t]===F;)s+=1;else break}return qo(e,t,n,h,i,o,i[p*h+t])}});var Wo=xt((G1,$o)=>{"use strict";$o.exports=cc;var ke=br(),mn=je(),Ho=Oo(),K0=Ho.partial,J0=Ho.full,Me=Un(),j0=Co(),Ye=Rn(),ko=128,tc=1<<22,ec=1<<22,rc=Ye("!(lo>=p0)&&!(p1>=hi)",["p0","p1"]),Yo=Ye("lo===p0",["p0"]),nc=Ye("lo<p0",["p0"]),ic=Ye("hi<=p0",["p0"]),Xo=Ye("lo<=p0&&p0<=hi",["p0"]),oc=Ye("lo<p0&&p0<=hi",["p0"]),On=6,Vn=2,Zo=1024,ee=ke.mallocInt32(Zo),Fe=ke.mallocDouble(Zo);function ac(e,t){var n=8*mn.log2(t+1)*(e+1)|0,r=mn.nextPow2(On*n);ee.length<r&&(ke.free(ee),ee=ke.mallocInt32(r));var i=mn.nextPow2(Vn*n);Fe.length<i&&(ke.free(Fe),Fe=ke.mallocDouble(i))}function ce(e,t,n,r,i,o,s,c,h){var p=On*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=Vn*e;Fe[g]=c,Fe[g+1]=h}function sc(e,t,n,r,i,o,s,c,h,p,g){var F=2*e,N=h*F,q=p[N+t];t:for(var m=i,C=i*F;m<o;++m,C+=F){var Y=s[C+t],H=s[C+t+e];if(!(q<Y||H<q)&&!(r&&q===Y)){for(var W=c[m],Q=t+1;Q<e;++Q){var Y=s[C+Q],H=s[C+Q+e],et=p[N+Q],$=p[N+Q+e];if(H<et||$<Y)continue t}var J;if(r?J=n(g,W):J=n(W,g),J!==void 0)return J}}}function uc(e,t,n,r,i,o,s,c,h,p){var g=2*e,F=c*g,N=h[F+t];t:for(var q=r,m=r*g;q<i;++q,m+=g){var C=s[q];if(C!==p){var Y=o[m+t],H=o[m+t+e];if(!(N<Y||H<N)){for(var W=t+1;W<e;++W){var Y=o[m+W],H=o[m+W+e],Q=h[F+W],et=h[F+W+e];if(H<Q||et<Y)continue t}var $=n(C,p);if($!==void 0)return $}}}}function cc(e,t,n,r,i,o,s,c,h){ac(e,r+s);var p=0,g=2*e,F;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 N=p*On,q=ee[N],m=ee[N+1],C=ee[N+2],Y=ee[N+3],H=ee[N+4],W=ee[N+5],Q=p*Vn,et=Fe[Q],$=Fe[Q+1],J=W&1,ut=!!(W&16),tt=i,rt=o,D=c,a=h;if(J&&(tt=c,rt=h,D=i,a=o),!(W&2&&(C=nc(e,q,m,C,tt,rt,$),m>=C))&&!(W&4&&(m=ic(e,q,m,C,tt,rt,et),m>=C))){var v=C-m,T=H-Y;if(ut){if(e*v*(v+T)<ec){if(F=Me.scanComplete(e,q,t,m,C,tt,rt,Y,H,D,a),F!==void 0)return F;continue}}else if(e*Math.min(v,T)<ko){if(F=K0(e,q,t,J,m,C,tt,rt,Y,H,D,a),F!==void 0)return F;continue}else if(e*v*T<tc){if(F=Me.scanBipartite(e,q,t,J,m,C,tt,rt,Y,H,D,a),F!==void 0)return F;continue}var M=rc(e,q,m,C,tt,rt,et,$);if(m<M)if(e*(M-m)<ko){if(F=J0(e,q+1,t,m,M,tt,rt,Y,H,D,a),F!==void 0)return F}else if(q===e-2){if(J?F=Me.sweepBipartite(e,t,Y,H,D,a,m,M,tt,rt):F=Me.sweepBipartite(e,t,m,M,tt,rt,Y,H,D,a),F!==void 0)return F}else ce(p++,q+1,m,M,Y,H,J,-1/0,1/0),ce(p++,q+1,Y,H,m,M,J^1,-1/0,1/0);if(M<C){var S=j0(e,q,Y,H,D,a),E=D[g*S+q],R=Yo(e,q,S,H,D,a,E);if(R<H&&ce(p++,q,M,C,R,H,(J|4)+(ut?16:0),E,$),Y<S&&ce(p++,q,M,C,Y,S,(J|2)+(ut?16:0),et,E),S+1===R){if(ut?F=uc(e,q,t,M,C,tt,rt,S,D,a[S]):F=sc(e,q,t,J,M,C,tt,rt,S,D,a[S]),F!==void 0)return F}else if(S<R){var P;if(ut){if(P=Xo(e,q,M,C,tt,rt,E),M<P){var l=Yo(e,q,M,P,tt,rt,E);if(q===e-2){if(M<l&&(F=Me.sweepComplete(e,t,M,l,tt,rt,S,R,D,a),F!==void 0)||l<P&&(F=Me.sweepBipartite(e,t,l,P,tt,rt,S,R,D,a),F!==void 0))return F}else M<l&&ce(p++,q+1,M,l,S,R,16,-1/0,1/0),l<P&&(ce(p++,q+1,l,P,S,R,0,-1/0,1/0),ce(p++,q+1,S,R,l,P,1,-1/0,1/0))}}else J?P=oc(e,q,M,C,tt,rt,E):P=Xo(e,q,M,C,tt,rt,E),M<P&&(q===e-2?J?F=Me.sweepBipartite(e,t,S,R,D,a,M,P,tt,rt):F=Me.sweepBipartite(e,t,M,P,tt,rt,S,R,D,a):(ce(p++,q+1,M,P,S,R,J,-1/0,1/0),ce(p++,q+1,S,R,M,P,J^1,-1/0,1/0)))}}}}}});var jo=xt((F1,Jo)=>{"use strict";Jo.exports=vc;var be=br(),Gr=Un(),fc=Wo();function lc(e,t){for(var n=0;n<e;++n)if(!(t[n]<=t[n+e]))return!0;return!1}function Qo(e,t,n,r){for(var i=0,o=0,s=0,c=e.length;s<c;++s){var h=e[s];if(!lc(t,h)){for(var p=0;p<2*t;++p)n[i++]=h[p];r[o++]=s}}return o}function Fr(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 c,h=be.mallocDouble(2*s*i),p=be.mallocInt32(i);if(i=Qo(e,s,h,p),i>0){if(s===1&&r)Gr.init(i),c=Gr.sweepComplete(s,n,0,i,h,p,0,i,h,p);else{var g=be.mallocDouble(2*s*o),F=be.mallocInt32(o);o=Qo(t,s,g,F),o>0&&(Gr.init(i+o),s===1?c=Gr.sweepBipartite(s,n,0,i,h,p,0,o,g,F):c=fc(s,n,r,i,h,p,o,g,F),be.free(g),be.free(F))}be.free(h),be.free(p)}return c}}}var ir;function Ko(e,t){ir.push([e,t])}function hc(e){return ir=[],Fr(e,e,Ko,!0),ir}function pc(e,t){return ir=[],Fr(e,t,Ko,!1),ir}function vc(e,t,n){var r;switch(arguments.length){case 1:return hc(e);case 2:return typeof t=="function"?Fr(e,e,t,!0):pc(e,t);case 3:return Fr(e,t,n,!1);default:throw new Error("box-intersect: Invalid arguments")}}});var ea=xt((A1,ta)=>{"use strict";ta.exports=gc;var Ar=yn()[3];function dc(e,t,n,r){for(var i=0;i<2;++i){var o=e[i],s=t[i],c=Math.min(o,s),h=Math.max(o,s),p=n[i],g=r[i],F=Math.min(p,g),N=Math.max(p,g);if(N<c||h<F)return!1}return!0}function gc(e,t,n,r){var i=Ar(e,n,r),o=Ar(t,n,r);if(i>0&&o>0||i<0&&o<0)return!1;var s=Ar(n,e,t),c=Ar(r,e,t);return s>0&&c>0||s<0&&c<0?!1:i===0&&o===0&&s===0&&c===0?dc(e,t,n,r):!0}});var ra=xt(()=>{});var or=xt((na,qn)=>{(function(e,t){"use strict";function n(D,a){if(!D)throw new Error(a||"Assertion failed")}function r(D,a){D.super_=a;var v=function(){};v.prototype=a.prototype,D.prototype=new v,D.prototype.constructor=D}function i(D,a,v){if(i.isBN(D))return D;this.negative=0,this.words=null,this.length=0,this.red=null,D!==null&&((a==="le"||a==="be")&&(v=a,a=10),this._init(D||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=ra().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,E,R=0;if(T==="be")for(M=a.length-1,S=0;M>=0;M-=3)E=a[M]|a[M-1]<<8|a[M-2]<<16,this.words[S]|=E<<R&67108863,this.words[S+1]=E>>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);else if(T==="le")for(M=0,S=0;M<a.length;M+=3)E=a[M]|a[M+1]<<8|a[M+2]<<16,this.words[S]|=E<<R&67108863,this.words[S+1]=E>>>26-R&67108863,R+=24,R>=26&&(R-=26,S++);return this.strip()};function s(D,a){var v=D.charCodeAt(a);return v>=65&&v<=70?v-55:v>=97&&v<=102?v-87:v-48&15}function c(D,a,v){var T=s(D,v);return v-1>=a&&(T|=s(D,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,E=0,R;if(T==="be")for(M=a.length-1;M>=v;M-=2)R=c(a,v,M)<<S,this.words[E]|=R&67108863,S>=18?(S-=18,E+=1,this.words[E]|=R>>>26):S+=8;else{var P=a.length-v;for(M=P%2===0?v+1:v;M<a.length;M+=2)R=c(a,v,M)<<S,this.words[E]|=R&67108863,S>=18?(S-=18,E+=1,this.words[E]|=R>>>26):S+=8}this.strip()};function h(D,a,v,T){for(var M=0,S=Math.min(D.length,v),E=a;E<S;E++){var R=D.charCodeAt(E)-48;M*=T,R>=49?M+=R-49+10:R>=17?M+=R-17+10:M+=R}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 E=a.length-T,R=E%M,P=Math.min(E,E-R)+T,l=0,G=T;G<P;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(R!==0){var ot=1;for(l=h(a,G,a.length,v),G=0;G<R;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],F=[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,E=0;E<this.length;E++){var R=this.words[E],P=((R<<M|S)&16777215).toString(16);S=R>>>24-M&16777215,M+=2,M>=26&&(M-=26,E--),S!==0||E!==this.length-1?T=p[6-P.length]+P+T:T=P+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=F[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 E=v==="le",R=new a(S),P,l,G=this.clone();if(E){for(l=0;!G.isZero();l++)P=G.andln(255),G.iushrn(8),R[l]=P;for(;l<S;l++)R[l]=0}else{for(l=0;l<S-M;l++)R[l]=0;for(l=0;!G.isZero();l++)P=G.andln(255),G.iushrn(8),R[S-l-1]=P}return R},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 N(D){for(var a=new Array(D.bitLength()),v=0;v<a.length;v++){var T=v/26|0,M=v%26;a[v]=(D.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,E=0;E<M.length;E++)v=(T.words[E]|0)+(M.words[E]|0)+S,this.words[E]=v&67108863,S=v>>>26;for(;S!==0&&E<T.length;E++)v=(T.words[E]|0)+S,this.words[E]=v&67108863,S=v>>>26;if(this.length=T.length,S!==0)this.words[this.length]=S,this.length++;else if(T!==this)for(;E<T.length;E++)this.words[E]=T.words[E];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 E=0,R=0;R<S.length;R++)v=(M.words[R]|0)-(S.words[R]|0)+E,E=v>>26,this.words[R]=v&67108863;for(;E!==0&&R<M.length;R++)v=(M.words[R]|0)+E,E=v>>26,this.words[R]=v&67108863;if(E===0&&R<M.length&&M!==this)for(;R<M.length;R++)this.words[R]=M.words[R];return this.length=Math.max(this.length,R),M!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(a){return this.clone().isub(a)};function q(D,a,v){v.negative=a.negative^D.negative;var T=D.length+a.length|0;v.length=T,T=T-1|0;var M=D.words[0]|0,S=a.words[0]|0,E=M*S,R=E&67108863,P=E/67108864|0;v.words[0]=R;for(var l=1;l<T;l++){for(var G=P>>>26,ot=P&67108863,at=Math.min(l,a.length-1),st=Math.max(0,l-D.length+1);st<=at;st++){var ct=l-st|0;M=D.words[ct]|0,S=a.words[st]|0,E=M*S+ot,G+=E/67108864|0,ot=E&67108863}v.words[l]=ot|0,P=G|0}return P!==0?v.words[l]=P|0:v.length--,v.strip()}var m=function(a,v,T){var M=a.words,S=v.words,E=T.words,R=0,P,l,G,ot=M[0]|0,at=ot&8191,st=ot>>>13,ct=M[1]|0,yt=ct&8191,pt=ct>>>13,k=M[2]|0,Z=k&8191,U=k>>>13,f=M[3]|0,b=f&8191,w=f>>>13,I=M[4]|0,z=I&8191,O=I>>>13,V=M[5]|0,u=V&8191,B=V>>>13,x=M[6]|0,y=x&8191,d=x>>>13,_=M[7]|0,L=_&8191,A=_>>>13,X=M[8]|0,K=X&8191,j=X>>>13,ft=M[9]|0,nt=ft&8191,it=ft>>>13,vt=S[0]|0,ht=vt&8191,lt=vt>>>13,dt=S[1]|0,wt=dt&8191,gt=dt>>>13,qt=S[2]|0,Mt=qt&8191,bt=qt>>>13,Xt=S[3]|0,St=Xt&8191,Bt=Xt>>>13,Zt=S[4]|0,Pt=Zt&8191,Dt=Zt>>>13,$t=S[5]|0,Ut=$t&8191,Gt=$t>>>13,Wt=S[6]|0,Ft=Wt&8191,At=Wt>>>13,Jt=S[7]|0,Lt=Jt&8191,zt=Jt>>>13,Te=S[8]|0,Rt=Te&8191,mt=Te>>>13,_e=S[9]|0,Ot=_e&8191,Vt=_e>>>13;T.negative=a.negative^v.negative,T.length=19,P=Math.imul(at,ht),l=Math.imul(at,lt),l=l+Math.imul(st,ht)|0,G=Math.imul(st,lt);var Ee=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Ee>>>26)|0,Ee&=67108863,P=Math.imul(yt,ht),l=Math.imul(yt,lt),l=l+Math.imul(pt,ht)|0,G=Math.imul(pt,lt),P=P+Math.imul(at,wt)|0,l=l+Math.imul(at,gt)|0,l=l+Math.imul(st,wt)|0,G=G+Math.imul(st,gt)|0;var Le=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Le>>>26)|0,Le&=67108863,P=Math.imul(Z,ht),l=Math.imul(Z,lt),l=l+Math.imul(U,ht)|0,G=Math.imul(U,lt),P=P+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,P=P+Math.imul(at,Mt)|0,l=l+Math.imul(at,bt)|0,l=l+Math.imul(st,Mt)|0,G=G+Math.imul(st,bt)|0;var ze=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(ze>>>26)|0,ze&=67108863,P=Math.imul(b,ht),l=Math.imul(b,lt),l=l+Math.imul(w,ht)|0,G=Math.imul(w,lt),P=P+Math.imul(Z,wt)|0,l=l+Math.imul(Z,gt)|0,l=l+Math.imul(U,wt)|0,G=G+Math.imul(U,gt)|0,P=P+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,P=P+Math.imul(at,St)|0,l=l+Math.imul(at,Bt)|0,l=l+Math.imul(st,St)|0,G=G+Math.imul(st,Bt)|0;var Ht=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Ht>>>26)|0,Ht&=67108863,P=Math.imul(z,ht),l=Math.imul(z,lt),l=l+Math.imul(O,ht)|0,G=Math.imul(O,lt),P=P+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,P=P+Math.imul(Z,Mt)|0,l=l+Math.imul(Z,bt)|0,l=l+Math.imul(U,Mt)|0,G=G+Math.imul(U,bt)|0,P=P+Math.imul(yt,St)|0,l=l+Math.imul(yt,Bt)|0,l=l+Math.imul(pt,St)|0,G=G+Math.imul(pt,Bt)|0,P=P+Math.imul(at,Pt)|0,l=l+Math.imul(at,Dt)|0,l=l+Math.imul(st,Pt)|0,G=G+Math.imul(st,Dt)|0;var Yr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Yr>>>26)|0,Yr&=67108863,P=Math.imul(u,ht),l=Math.imul(u,lt),l=l+Math.imul(B,ht)|0,G=Math.imul(B,lt),P=P+Math.imul(z,wt)|0,l=l+Math.imul(z,gt)|0,l=l+Math.imul(O,wt)|0,G=G+Math.imul(O,gt)|0,P=P+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,P=P+Math.imul(Z,St)|0,l=l+Math.imul(Z,Bt)|0,l=l+Math.imul(U,St)|0,G=G+Math.imul(U,Bt)|0,P=P+Math.imul(yt,Pt)|0,l=l+Math.imul(yt,Dt)|0,l=l+Math.imul(pt,Pt)|0,G=G+Math.imul(pt,Dt)|0,P=P+Math.imul(at,Ut)|0,l=l+Math.imul(at,Gt)|0,l=l+Math.imul(st,Ut)|0,G=G+Math.imul(st,Gt)|0;var Xr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Xr>>>26)|0,Xr&=67108863,P=Math.imul(y,ht),l=Math.imul(y,lt),l=l+Math.imul(d,ht)|0,G=Math.imul(d,lt),P=P+Math.imul(u,wt)|0,l=l+Math.imul(u,gt)|0,l=l+Math.imul(B,wt)|0,G=G+Math.imul(B,gt)|0,P=P+Math.imul(z,Mt)|0,l=l+Math.imul(z,bt)|0,l=l+Math.imul(O,Mt)|0,G=G+Math.imul(O,bt)|0,P=P+Math.imul(b,St)|0,l=l+Math.imul(b,Bt)|0,l=l+Math.imul(w,St)|0,G=G+Math.imul(w,Bt)|0,P=P+Math.imul(Z,Pt)|0,l=l+Math.imul(Z,Dt)|0,l=l+Math.imul(U,Pt)|0,G=G+Math.imul(U,Dt)|0,P=P+Math.imul(yt,Ut)|0,l=l+Math.imul(yt,Gt)|0,l=l+Math.imul(pt,Ut)|0,G=G+Math.imul(pt,Gt)|0,P=P+Math.imul(at,Ft)|0,l=l+Math.imul(at,At)|0,l=l+Math.imul(st,Ft)|0,G=G+Math.imul(st,At)|0;var Hr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Hr>>>26)|0,Hr&=67108863,P=Math.imul(L,ht),l=Math.imul(L,lt),l=l+Math.imul(A,ht)|0,G=Math.imul(A,lt),P=P+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,P=P+Math.imul(u,Mt)|0,l=l+Math.imul(u,bt)|0,l=l+Math.imul(B,Mt)|0,G=G+Math.imul(B,bt)|0,P=P+Math.imul(z,St)|0,l=l+Math.imul(z,Bt)|0,l=l+Math.imul(O,St)|0,G=G+Math.imul(O,Bt)|0,P=P+Math.imul(b,Pt)|0,l=l+Math.imul(b,Dt)|0,l=l+Math.imul(w,Pt)|0,G=G+Math.imul(w,Dt)|0,P=P+Math.imul(Z,Ut)|0,l=l+Math.imul(Z,Gt)|0,l=l+Math.imul(U,Ut)|0,G=G+Math.imul(U,Gt)|0,P=P+Math.imul(yt,Ft)|0,l=l+Math.imul(yt,At)|0,l=l+Math.imul(pt,Ft)|0,G=G+Math.imul(pt,At)|0,P=P+Math.imul(at,Lt)|0,l=l+Math.imul(at,zt)|0,l=l+Math.imul(st,Lt)|0,G=G+Math.imul(st,zt)|0;var Zr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Zr>>>26)|0,Zr&=67108863,P=Math.imul(K,ht),l=Math.imul(K,lt),l=l+Math.imul(j,ht)|0,G=Math.imul(j,lt),P=P+Math.imul(L,wt)|0,l=l+Math.imul(L,gt)|0,l=l+Math.imul(A,wt)|0,G=G+Math.imul(A,gt)|0,P=P+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,P=P+Math.imul(u,St)|0,l=l+Math.imul(u,Bt)|0,l=l+Math.imul(B,St)|0,G=G+Math.imul(B,Bt)|0,P=P+Math.imul(z,Pt)|0,l=l+Math.imul(z,Dt)|0,l=l+Math.imul(O,Pt)|0,G=G+Math.imul(O,Dt)|0,P=P+Math.imul(b,Ut)|0,l=l+Math.imul(b,Gt)|0,l=l+Math.imul(w,Ut)|0,G=G+Math.imul(w,Gt)|0,P=P+Math.imul(Z,Ft)|0,l=l+Math.imul(Z,At)|0,l=l+Math.imul(U,Ft)|0,G=G+Math.imul(U,At)|0,P=P+Math.imul(yt,Lt)|0,l=l+Math.imul(yt,zt)|0,l=l+Math.imul(pt,Lt)|0,G=G+Math.imul(pt,zt)|0,P=P+Math.imul(at,Rt)|0,l=l+Math.imul(at,mt)|0,l=l+Math.imul(st,Rt)|0,G=G+Math.imul(st,mt)|0;var $r=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+($r>>>26)|0,$r&=67108863,P=Math.imul(nt,ht),l=Math.imul(nt,lt),l=l+Math.imul(it,ht)|0,G=Math.imul(it,lt),P=P+Math.imul(K,wt)|0,l=l+Math.imul(K,gt)|0,l=l+Math.imul(j,wt)|0,G=G+Math.imul(j,gt)|0,P=P+Math.imul(L,Mt)|0,l=l+Math.imul(L,bt)|0,l=l+Math.imul(A,Mt)|0,G=G+Math.imul(A,bt)|0,P=P+Math.imul(y,St)|0,l=l+Math.imul(y,Bt)|0,l=l+Math.imul(d,St)|0,G=G+Math.imul(d,Bt)|0,P=P+Math.imul(u,Pt)|0,l=l+Math.imul(u,Dt)|0,l=l+Math.imul(B,Pt)|0,G=G+Math.imul(B,Dt)|0,P=P+Math.imul(z,Ut)|0,l=l+Math.imul(z,Gt)|0,l=l+Math.imul(O,Ut)|0,G=G+Math.imul(O,Gt)|0,P=P+Math.imul(b,Ft)|0,l=l+Math.imul(b,At)|0,l=l+Math.imul(w,Ft)|0,G=G+Math.imul(w,At)|0,P=P+Math.imul(Z,Lt)|0,l=l+Math.imul(Z,zt)|0,l=l+Math.imul(U,Lt)|0,G=G+Math.imul(U,zt)|0,P=P+Math.imul(yt,Rt)|0,l=l+Math.imul(yt,mt)|0,l=l+Math.imul(pt,Rt)|0,G=G+Math.imul(pt,mt)|0,P=P+Math.imul(at,Ot)|0,l=l+Math.imul(at,Vt)|0,l=l+Math.imul(st,Ot)|0,G=G+Math.imul(st,Vt)|0;var Wr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Wr>>>26)|0,Wr&=67108863,P=Math.imul(nt,wt),l=Math.imul(nt,gt),l=l+Math.imul(it,wt)|0,G=Math.imul(it,gt),P=P+Math.imul(K,Mt)|0,l=l+Math.imul(K,bt)|0,l=l+Math.imul(j,Mt)|0,G=G+Math.imul(j,bt)|0,P=P+Math.imul(L,St)|0,l=l+Math.imul(L,Bt)|0,l=l+Math.imul(A,St)|0,G=G+Math.imul(A,Bt)|0,P=P+Math.imul(y,Pt)|0,l=l+Math.imul(y,Dt)|0,l=l+Math.imul(d,Pt)|0,G=G+Math.imul(d,Dt)|0,P=P+Math.imul(u,Ut)|0,l=l+Math.imul(u,Gt)|0,l=l+Math.imul(B,Ut)|0,G=G+Math.imul(B,Gt)|0,P=P+Math.imul(z,Ft)|0,l=l+Math.imul(z,At)|0,l=l+Math.imul(O,Ft)|0,G=G+Math.imul(O,At)|0,P=P+Math.imul(b,Lt)|0,l=l+Math.imul(b,zt)|0,l=l+Math.imul(w,Lt)|0,G=G+Math.imul(w,zt)|0,P=P+Math.imul(Z,Rt)|0,l=l+Math.imul(Z,mt)|0,l=l+Math.imul(U,Rt)|0,G=G+Math.imul(U,mt)|0,P=P+Math.imul(yt,Ot)|0,l=l+Math.imul(yt,Vt)|0,l=l+Math.imul(pt,Ot)|0,G=G+Math.imul(pt,Vt)|0;var Qr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Qr>>>26)|0,Qr&=67108863,P=Math.imul(nt,Mt),l=Math.imul(nt,bt),l=l+Math.imul(it,Mt)|0,G=Math.imul(it,bt),P=P+Math.imul(K,St)|0,l=l+Math.imul(K,Bt)|0,l=l+Math.imul(j,St)|0,G=G+Math.imul(j,Bt)|0,P=P+Math.imul(L,Pt)|0,l=l+Math.imul(L,Dt)|0,l=l+Math.imul(A,Pt)|0,G=G+Math.imul(A,Dt)|0,P=P+Math.imul(y,Ut)|0,l=l+Math.imul(y,Gt)|0,l=l+Math.imul(d,Ut)|0,G=G+Math.imul(d,Gt)|0,P=P+Math.imul(u,Ft)|0,l=l+Math.imul(u,At)|0,l=l+Math.imul(B,Ft)|0,G=G+Math.imul(B,At)|0,P=P+Math.imul(z,Lt)|0,l=l+Math.imul(z,zt)|0,l=l+Math.imul(O,Lt)|0,G=G+Math.imul(O,zt)|0,P=P+Math.imul(b,Rt)|0,l=l+Math.imul(b,mt)|0,l=l+Math.imul(w,Rt)|0,G=G+Math.imul(w,mt)|0,P=P+Math.imul(Z,Ot)|0,l=l+Math.imul(Z,Vt)|0,l=l+Math.imul(U,Ot)|0,G=G+Math.imul(U,Vt)|0;var Kr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Kr>>>26)|0,Kr&=67108863,P=Math.imul(nt,St),l=Math.imul(nt,Bt),l=l+Math.imul(it,St)|0,G=Math.imul(it,Bt),P=P+Math.imul(K,Pt)|0,l=l+Math.imul(K,Dt)|0,l=l+Math.imul(j,Pt)|0,G=G+Math.imul(j,Dt)|0,P=P+Math.imul(L,Ut)|0,l=l+Math.imul(L,Gt)|0,l=l+Math.imul(A,Ut)|0,G=G+Math.imul(A,Gt)|0,P=P+Math.imul(y,Ft)|0,l=l+Math.imul(y,At)|0,l=l+Math.imul(d,Ft)|0,G=G+Math.imul(d,At)|0,P=P+Math.imul(u,Lt)|0,l=l+Math.imul(u,zt)|0,l=l+Math.imul(B,Lt)|0,G=G+Math.imul(B,zt)|0,P=P+Math.imul(z,Rt)|0,l=l+Math.imul(z,mt)|0,l=l+Math.imul(O,Rt)|0,G=G+Math.imul(O,mt)|0,P=P+Math.imul(b,Ot)|0,l=l+Math.imul(b,Vt)|0,l=l+Math.imul(w,Ot)|0,G=G+Math.imul(w,Vt)|0;var Jr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(Jr>>>26)|0,Jr&=67108863,P=Math.imul(nt,Pt),l=Math.imul(nt,Dt),l=l+Math.imul(it,Pt)|0,G=Math.imul(it,Dt),P=P+Math.imul(K,Ut)|0,l=l+Math.imul(K,Gt)|0,l=l+Math.imul(j,Ut)|0,G=G+Math.imul(j,Gt)|0,P=P+Math.imul(L,Ft)|0,l=l+Math.imul(L,At)|0,l=l+Math.imul(A,Ft)|0,G=G+Math.imul(A,At)|0,P=P+Math.imul(y,Lt)|0,l=l+Math.imul(y,zt)|0,l=l+Math.imul(d,Lt)|0,G=G+Math.imul(d,zt)|0,P=P+Math.imul(u,Rt)|0,l=l+Math.imul(u,mt)|0,l=l+Math.imul(B,Rt)|0,G=G+Math.imul(B,mt)|0,P=P+Math.imul(z,Ot)|0,l=l+Math.imul(z,Vt)|0,l=l+Math.imul(O,Ot)|0,G=G+Math.imul(O,Vt)|0;var jr=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(jr>>>26)|0,jr&=67108863,P=Math.imul(nt,Ut),l=Math.imul(nt,Gt),l=l+Math.imul(it,Ut)|0,G=Math.imul(it,Gt),P=P+Math.imul(K,Ft)|0,l=l+Math.imul(K,At)|0,l=l+Math.imul(j,Ft)|0,G=G+Math.imul(j,At)|0,P=P+Math.imul(L,Lt)|0,l=l+Math.imul(L,zt)|0,l=l+Math.imul(A,Lt)|0,G=G+Math.imul(A,zt)|0,P=P+Math.imul(y,Rt)|0,l=l+Math.imul(y,mt)|0,l=l+Math.imul(d,Rt)|0,G=G+Math.imul(d,mt)|0,P=P+Math.imul(u,Ot)|0,l=l+Math.imul(u,Vt)|0,l=l+Math.imul(B,Ot)|0,G=G+Math.imul(B,Vt)|0;var tn=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(tn>>>26)|0,tn&=67108863,P=Math.imul(nt,Ft),l=Math.imul(nt,At),l=l+Math.imul(it,Ft)|0,G=Math.imul(it,At),P=P+Math.imul(K,Lt)|0,l=l+Math.imul(K,zt)|0,l=l+Math.imul(j,Lt)|0,G=G+Math.imul(j,zt)|0,P=P+Math.imul(L,Rt)|0,l=l+Math.imul(L,mt)|0,l=l+Math.imul(A,Rt)|0,G=G+Math.imul(A,mt)|0,P=P+Math.imul(y,Ot)|0,l=l+Math.imul(y,Vt)|0,l=l+Math.imul(d,Ot)|0,G=G+Math.imul(d,Vt)|0;var en=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(en>>>26)|0,en&=67108863,P=Math.imul(nt,Lt),l=Math.imul(nt,zt),l=l+Math.imul(it,Lt)|0,G=Math.imul(it,zt),P=P+Math.imul(K,Rt)|0,l=l+Math.imul(K,mt)|0,l=l+Math.imul(j,Rt)|0,G=G+Math.imul(j,mt)|0,P=P+Math.imul(L,Ot)|0,l=l+Math.imul(L,Vt)|0,l=l+Math.imul(A,Ot)|0,G=G+Math.imul(A,Vt)|0;var rn=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(rn>>>26)|0,rn&=67108863,P=Math.imul(nt,Rt),l=Math.imul(nt,mt),l=l+Math.imul(it,Rt)|0,G=Math.imul(it,mt),P=P+Math.imul(K,Ot)|0,l=l+Math.imul(K,Vt)|0,l=l+Math.imul(j,Ot)|0,G=G+Math.imul(j,Vt)|0;var nn=(R+P|0)+((l&8191)<<13)|0;R=(G+(l>>>13)|0)+(nn>>>26)|0,nn&=67108863,P=Math.imul(nt,Ot),l=Math.imul(nt,Vt),l=l+Math.imul(it,Ot)|0,G=Math.imul(it,Vt);var on=(R+P|0)+((l&8191)<<13)|0;return R=(G+(l>>>13)|0)+(on>>>26)|0,on&=67108863,E[0]=Ee,E[1]=Le,E[2]=ze,E[3]=Ht,E[4]=Yr,E[5]=Xr,E[6]=Hr,E[7]=Zr,E[8]=$r,E[9]=Wr,E[10]=Qr,E[11]=Kr,E[12]=Jr,E[13]=jr,E[14]=tn,E[15]=en,E[16]=rn,E[17]=nn,E[18]=on,R!==0&&(E[19]=R,T.length++),T};Math.imul||(m=q);function C(D,a,v){v.negative=a.negative^D.negative,v.length=D.length+a.length;for(var T=0,M=0,S=0;S<v.length-1;S++){var E=M;M=0;for(var R=T&67108863,P=Math.min(S,a.length-1),l=Math.max(0,S-D.length+1);l<=P;l++){var G=S-l,ot=D.words[G]|0,at=a.words[l]|0,st=ot*at,ct=st&67108863;E=E+(st/67108864|0)|0,ct=ct+R|0,R=ct&67108863,E=E+(ct>>>26)|0,M+=E>>>26,E&=67108863}v.words[S]=R,T=E,E=M}return T!==0?v.words[S]=T:v.length--,v.strip()}function Y(D,a,v){var T=new H;return T.mulp(D,a,v)}i.prototype.mulTo=function(a,v){var T,M=this.length+a.length;return this.length===10&&a.length===10?T=m(this,a,v):M<63?T=q(this,a,v):M<1024?T=C(this,a,v):T=Y(this,a,v),T};function H(D,a){this.x=D,this.y=a}H.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},H.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},H.prototype.permute=function(a,v,T,M,S,E){for(var R=0;R<E;R++)M[R]=v[a[R]],S[R]=T[a[R]]},H.prototype.transform=function(a,v,T,M,S,E){this.permute(E,a,v,T,M,S);for(var R=1;R<S;R<<=1)for(var P=R<<1,l=Math.cos(2*Math.PI/P),G=Math.sin(2*Math.PI/P),ot=0;ot<S;ot+=P)for(var at=l,st=G,ct=0;ct<R;ct++){var yt=T[ot+ct],pt=M[ot+ct],k=T[ot+ct+R],Z=M[ot+ct+R],U=at*k-st*Z;Z=at*Z+st*k,k=U,T[ot+ct]=yt+k,M[ot+ct]=pt+Z,T[ot+ct+R]=yt-k,M[ot+ct+R]=pt-Z,ct!==P&&(U=l*at-G*st,st=l*st+G*at,at=U)}},H.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},H.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}},H.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},H.prototype.convert13b=function(a,v,T,M){for(var S=0,E=0;E<v;E++)S=S+(a[E]|0),T[2*E]=S&8191,S=S>>>13,T[2*E+1]=S&8191,S=S>>>13;for(E=2*v;E<M;++E)T[E]=0;n(S===0),n((S&-8192)===0)},H.prototype.stub=function(a){for(var v=new Array(a),T=0;T<a;T++)v[T]=0;return v},H.prototype.mulp=function(a,v,T){var M=2*this.guessLen13b(a.length,v.length),S=this.makeRBT(M),E=this.stub(M),R=new Array(M),P=new Array(M),l=new Array(M),G=new Array(M),ot=new Array(M),at=new Array(M),st=T.words;st.length=M,this.convert13b(a.words,a.length,R,M),this.convert13b(v.words,v.length,G,M),this.transform(R,E,P,l,M,S),this.transform(G,E,ot,at,M,S);for(var ct=0;ct<M;ct++){var yt=P[ct]*ot[ct]-l[ct]*at[ct];l[ct]=P[ct]*at[ct]+l[ct]*ot[ct],P[ct]=yt}return this.conjugate(P,l,M),this.transform(P,l,st,E,M,S),this.conjugate(st,E,M),this.normalize13b(st,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),Y(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=N(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 E=0;for(S=0;S<this.length;S++){var R=this.words[S]&M,P=(this.words[S]|0)-R<<v;this.words[S]=P|E,E=R>>>26-v}E&&(this.words[S]=E,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,E=Math.min((a-S)/26,this.length),R=67108863^67108863>>>S<<S,P=T;if(M-=E,M=Math.max(0,M),P){for(var l=0;l<E;l++)P.words[l]=this.words[l];P.length=E}if(E!==0)if(this.length>E)for(this.length-=E,l=0;l<this.length;l++)this.words[l]=this.words[l+E];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&R}return P&&G!==0&&(P.words[P.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 E,R=0;for(S=0;S<a.length;S++){E=(this.words[S+T]|0)+R;var P=(a.words[S]|0)*v;E-=P&67108863,R=(E>>26)-(P/67108864|0),this.words[S+T]=E&67108863}for(;S<this.length-T;S++)E=(this.words[S+T]|0)+R,R=E>>26,this.words[S+T]=E&67108863;if(R===0)return this.strip();for(n(R===-1),R=0,S=0;S<this.length;S++)E=-(this.words[S]|0)+R,R=E>>26,this.words[S]=E&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(a,v){var T=this.length-a.length,M=this.clone(),S=a,E=S.words[S.length-1]|0,R=this._countBits(E);T=26-R,T!==0&&(S=S.ushln(T),M.iushln(T),E=S.words[S.length-1]|0);var P=M.length-S.length,l;if(v!=="mod"){l=new i(null),l.length=P+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,P);ot.negative===0&&(M=ot,l&&(l.words[P]=1));for(var at=P-1;at>=0;at--){var st=(M.words[S.length+at]|0)*67108864+(M.words[S.length+at-1]|0);for(st=Math.min(st/E|0,67108863),M._ishlnsubmul(S,st,at);M.negative!==0;)st--,M.negative=0,M._ishlnsubmul(S,1,at),M.isZero()||(M.negative^=1);l&&(l.words[at]=st)}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,E;return this.negative!==0&&a.negative===0?(E=this.neg().divmod(a,v),v!=="mod"&&(M=E.div.neg()),v!=="div"&&(S=E.mod.neg(),T&&S.negative!==0&&S.iadd(a)),{div:M,mod:S}):this.negative===0&&a.negative!==0?(E=this.divmod(a.neg(),v),v!=="mod"&&(M=E.div.neg()),{div:M,mod:E.mod}):(this.negative&a.negative)!==0?(E=this.neg().divmod(a.neg(),v),v!=="div"&&(S=E.mod.neg(),T&&S.negative!==0&&S.isub(a)),{div:E.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),E=T.cmp(M);return E<0||S===1&&E===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),E=new i(0),R=new i(1),P=0;v.isEven()&&T.isEven();)v.iushrn(1),T.iushrn(1),++P;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 st=0,ct=1;(T.words[0]&ct)===0&&st<26;++st,ct<<=1);if(st>0)for(T.iushrn(st);st-- >0;)(E.isOdd()||R.isOdd())&&(E.iadd(l),R.isub(G)),E.iushrn(1),R.iushrn(1);v.cmp(T)>=0?(v.isub(T),M.isub(E),S.isub(R)):(T.isub(v),E.isub(M),R.isub(S))}return{a:E,b:R,gcd:T.iushln(P)}},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),E=T.clone();v.cmpn(1)>0&&T.cmpn(1)>0;){for(var R=0,P=1;(v.words[0]&P)===0&&R<26;++R,P<<=1);if(R>0)for(v.iushrn(R);R-- >0;)M.isOdd()&&M.iadd(E),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(E),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 E=v;v=T,T=E}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,E=T;S!==0&&E<this.length;E++){var R=this.words[E]|0;R+=S,S=R>>>26,R&=67108863,this.words[E]=R}return S!==0&&(this.words[E]=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 tt(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 W={k256:null,p224:null,p192:null,p25519:null};function Q(D,a){this.name=D,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 et(){Q.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}r(et,Q),et.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 E=a.words[9];for(v.words[v.length++]=E&T,S=10;S<a.length;S++){var R=a.words[S]|0;a.words[S-10]=(R&T)<<4|E>>>22,E=R}E>>>=22,a.words[S-10]=E,E===0&&a.length>10?a.length-=10:a.length-=9},et.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 $(){Q.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}r($,Q);function J(){Q.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}r(J,Q);function ut(){Q.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}r(ut,Q),ut.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(W[a])return W[a];var v;if(a==="k256")v=new et;else if(a==="p224")v=new $;else if(a==="p192")v=new J;else if(a==="p25519")v=new ut;else throw new Error("Unknown prime "+a);return W[a]=v,v};function tt(D){if(typeof D=="string"){var a=i._prime(D);this.m=a.p,this.prime=a}else n(D.gtn(1),"modulus must be greater than 1"),this.m=D,this.prime=null}tt.prototype._verify1=function(a){n(a.negative===0,"red works only with positives"),n(a.red,"red works only with red numbers")},tt.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")},tt.prototype.imod=function(a){return this.prime?this.prime.ireduce(a)._forceRed(this):a.umod(this.m)._forceRed(this)},tt.prototype.neg=function(a){return a.isZero()?a.clone():this.m.sub(a)._forceRed(this)},tt.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)},tt.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},tt.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)},tt.prototype.isub=function(a,v){this._verify2(a,v);var T=a.isub(v);return T.cmpn(0)<0&&T.iadd(this.m),T},tt.prototype.shl=function(a,v){return this._verify1(a),this.imod(a.ushln(v))},tt.prototype.imul=function(a,v){return this._verify2(a,v),this.imod(a.imul(v))},tt.prototype.mul=function(a,v){return this._verify2(a,v),this.imod(a.mul(v))},tt.prototype.isqr=function(a){return this.imul(a,a.clone())},tt.prototype.sqr=function(a){return this.mul(a,a)},tt.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 E=new i(1).toRed(this),R=E.redNeg(),P=this.m.subn(1).iushrn(1),l=this.m.bitLength();for(l=new i(2*l*l).toRed(this);this.pow(l,P).cmp(R)!==0;)l.redIAdd(R);for(var G=this.pow(l,M),ot=this.pow(a,M.addn(1).iushrn(1)),at=this.pow(a,M),st=S;at.cmp(E)!==0;){for(var ct=at,yt=0;ct.cmp(E)!==0;yt++)ct=ct.redSqr();n(yt<st);var pt=this.pow(G,new i(1).iushln(st-yt-1));ot=ot.redMul(pt),G=pt.redSqr(),at=at.redMul(G),st=yt}return ot},tt.prototype.invm=function(a){var v=a._invmp(this.m);return v.negative!==0?(v.negative=0,this.imod(v).redNeg()):this.imod(v)},tt.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 E=M[0],R=0,P=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(E!==M[0]&&(E=this.sqr(E)),at===0&&R===0){P=0;continue}R<<=1,R|=at,P++,!(P!==T&&(S!==0||ot!==0))&&(E=this.mul(E,M[R]),P=0,R=0)}l=26}return E},tt.prototype.convertTo=function(a){var v=a.umod(this.m);return v===a?v.clone():v},tt.prototype.convertFrom=function(a){var v=a.clone();return v.red=null,v},i.mont=function(a){return new rt(a)};function rt(D){tt.call(this,D),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,tt),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),E=S;return S.cmp(this.m)>=0?E=S.isub(this.m):S.cmpn(0)<0&&(E=S.iadd(this.m)),E._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),E=S;return S.cmp(this.m)>=0?E=S.isub(this.m):S.cmpn(0)<0&&(E=S.iadd(this.m)),E._forceRed(this)},rt.prototype.invm=function(a){var v=this.imod(a._invmp(this.m).mul(this.r2));return v._forceRed(this)}})(typeof qn>"u"||qn,na)});var Nn=xt((z1,ia)=>{"use strict";var L1=or();ia.exports=wc;function wc(e){return e&&typeof e=="object"&&!!e.words}});var sa=xt((R1,aa)=>{"use strict";var oa=Nn();aa.exports=xc;function xc(e){return Array.isArray(e)&&e.length===2&&oa(e[0])&&oa(e[1])}});var Ir=xt((m1,Ct)=>{var Cn=!1;if(typeof Float64Array<"u")if(fe=new Float64Array(1),re=new Uint32Array(fe.buffer),fe[0]=1,Cn=!0,re[1]===1072693248){let e=function(r,i){return re[0]=r,re[1]=i,fe[0]},t=function(r){return fe[0]=r,re[0]},n=function(r){return fe[0]=r,re[1]};yc=e,Mc=t,bc=n,Ct.exports=function(i){return fe[0]=i,[re[0],re[1]]},Ct.exports.pack=e,Ct.exports.lo=t,Ct.exports.hi=n}else if(re[0]===1072693248){let e=function(r,i){return re[1]=r,re[0]=i,fe[0]},t=function(r){return fe[0]=r,re[1]},n=function(r){return fe[0]=r,re[0]};Tc=e,_c=t,Sc=n,Ct.exports=function(i){return fe[0]=i,[re[1],re[0]]},Ct.exports.pack=e,Ct.exports.lo=t,Ct.exports.hi=n}else Cn=!1;var fe,re,yc,Mc,bc,Tc,_c,Sc;if(!Cn){let e=function(r,i){return le.writeUInt32LE(r,0,!0),le.writeUInt32LE(i,4,!0),le.readDoubleLE(0,!0)},t=function(r){return le.writeDoubleLE(r,0,!0),le.readUInt32LE(0,!0)},n=function(r){return le.writeDoubleLE(r,0,!0),le.readUInt32LE(4,!0)};Bc=e,Pc=t,Dc=n,le=new Buffer(8),Ct.exports=function(i){return le.writeDoubleLE(i,0,!0),[le.readUInt32LE(0,!0),le.readUInt32LE(4,!0)]},Ct.exports.pack=e,Ct.exports.lo=t,Ct.exports.hi=n}var le,Bc,Pc,Dc;Ct.exports.sign=function(e){return Ct.exports.hi(e)>>>31};Ct.exports.exponent=function(e){var t=Ct.exports.hi(e);return(t<<1>>>21)-1023};Ct.exports.fraction=function(e){var t=Ct.exports.lo(e),n=Ct.exports.hi(e),r=n&(1<<20)-1;return n&2146435072&&(r+=1<<20),[t,r]};Ct.exports.denormalized=function(e){var t=Ct.exports.hi(e);return!(t&2146435072)}});var kn=xt((O1,ca)=>{"use strict";var ua=or(),Uc=Ir();ca.exports=Gc;function Gc(e){var t=Uc.exponent(e);return t<52?new ua(e):new ua(e*Math.pow(2,52-t)).ushln(t-52)}});var la=xt((V1,fa)=>{"use strict";var Fc=or();fa.exports=Ac;function Ac(e){return new Fc(e)}});var Er=xt((q1,ha)=>{"use strict";var Ic=or();ha.exports=Ec;function Ec(e){return e.cmp(new Ic(0))}});var Xe=xt((N1,va)=>{"use strict";var Lr=kn(),pa=Er();va.exports=Lc;function Lc(e,t){var n=pa(e),r=pa(t);if(n===0)return[Lr(0),Lr(1)];if(r===0)return[Lr(0),Lr(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 Yn=xt((C1,da)=>{"use strict";var zc=Xe();da.exports=Rc;function Rc(e,t){return zc(e[0].mul(t[1]),e[1].mul(t[0]))}});var zr=xt((k1,Ma)=>{"use strict";var ga=sa(),wa=Nn(),Ae=kn(),xa=la(),mc=Xe(),Oc=Yn();Ma.exports=ya;function ya(e,t){if(ga(e))return t?Oc(e,ya(t)):[e[0].clone(),e[1].clone()];var n=0,r,i;if(wa(e))r=e.clone();else if(typeof e=="string")r=xa(e);else{if(e===0)return[Ae(0),Ae(1)];if(e===Math.floor(e))r=Ae(e);else{for(;e!==Math.floor(e);)e=e*Math.pow(2,256),n-=256;r=Ae(e)}}if(ga(t))r.mul(t[1]),i=t[0].clone();else if(wa(t))i=t.clone();else if(typeof t=="string")i=xa(t);else if(!t)i=Ae(1);else if(t===Math.floor(t))i=Ae(t);else{for(;t!==Math.floor(t);)t=t*Math.pow(2,256),n+=256;i=Ae(t)}return n>0?r=r.ushln(n):n<0&&(i=i.ushln(-n)),mc(r,i)}});var Ta=xt((Y1,ba)=>{"use strict";ba.exports=Vc;function Vc(e,t){return e[0].mul(t[1]).cmp(t[0].mul(e[1]))}});var Sa=xt((X1,_a)=>{"use strict";var qc=Er();_a.exports=Nc;function Nc(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 qc(e)*r}});var Ua=xt((H1,Da)=>{"use strict";var Ba=Ir(),Pa=je().countTrailingZeros;Da.exports=Cc;function Cc(e){var t=Pa(Ba.lo(e));if(t<32)return t;var n=Pa(Ba.hi(e));return n>20?52:n+32}});var Fa=xt((Z1,Ga)=>{"use strict";var Xn=Sa(),kc=Ua();Ga.exports=Yc;function Yc(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=Xn(i),s=r.mod,c=t.negative!==n.negative?-1:1;if(s.cmpn(0)===0)return c*o;if(o){var h=kc(o)+4,p=Xn(s.ushln(h).divRound(n));return c*(o+p*Math.pow(2,-h))}else{var g=n.bitLength()-s.bitLength()+53,p=Xn(s.ushln(g).divRound(n));return g<1023?c*p*Math.pow(2,-g):(p*=Math.pow(2,-1023),c*p*Math.pow(2,1023-g))}}});var Ia=xt(($1,Aa)=>{"use strict";Aa.exports=Hc;var Xc=zr();function Hc(e){for(var t=new Array(e.length),n=0;n<e.length;++n)t[n]=Xc(e[n]);return t}});var Ra=xt((W1,za)=>{"use strict";var Hn=Ir(),Ea=Math.pow(2,-1074),La=-1>>>0;za.exports=Zc;function Zc(e,t){if(isNaN(e)||isNaN(t))return NaN;if(e===t)return e;if(e===0)return t<0?-Ea:Ea;var n=Hn.hi(e),r=Hn.lo(e);return t>e==e>0?r===La?(n+=1,r=0):r+=1:r===0?(r=La,n-=1):r-=1,Hn.pack(r,n)}});var Zn=xt((Q1,ma)=>{"use strict";var $c=Xe();ma.exports=Wc;function Wc(e,t){return $c(e[0].mul(t[0]),e[1].mul(t[1]))}});var $n=xt((K1,Oa)=>{"use strict";var Qc=Xe();Oa.exports=Kc;function Kc(e,t){return Qc(e[0].mul(t[1]).sub(e[1].mul(t[0])),e[1].mul(t[1]))}});var Na=xt((J1,qa)=>{"use strict";var Va=Er();qa.exports=Jc;function Jc(e){return Va(e[0])*Va(e[1])}});var ka=xt((j1,Ca)=>{"use strict";var jc=$n();Ca.exports=tf;function tf(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=jc(e[i],t[i]);return r}});var Xa=xt((th,Ya)=>{"use strict";var ef=Xe();Ya.exports=rf;function rf(e,t){return ef(e[0].mul(t[1]).add(t[0].mul(e[1])),e[1].mul(t[1]))}});var Za=xt((eh,Ha)=>{"use strict";var nf=Xa();Ha.exports=of;function of(e,t){for(var n=e.length,r=new Array(n),i=0;i<n;++i)r[i]=nf(e[i],t[i]);return r}});var Wa=xt((rh,$a)=>{"use strict";var af=zr(),sf=Zn();$a.exports=uf;function uf(e,t){for(var n=af(t),r=e.length,i=new Array(r),o=0;o<r;++o)i[o]=sf(e[o],n);return i}});var ja=xt((nh,Ja)=>{"use strict";Ja.exports=vf;var Qa=Zn(),cf=Yn(),ff=$n(),lf=Na(),Wn=ka(),hf=Za(),pf=Wa();function Ka(e,t){return ff(Qa(e[0],t[1]),Qa(e[1],t[0]))}function vf(e,t,n,r){var i=Wn(t,e),o=Wn(r,n),s=Ka(i,o);if(lf(s)===0)return null;var c=Wn(e,n),h=Ka(o,c),p=cf(h,s),g=pf(i,p),F=hf(e,g);return F}});var us=xt((ih,ss)=>{"use strict";ss.exports=Bf;var df=fo(),Kn=jo(),ns=ea(),ts=zr(),es=Ta(),Qn=Fa(),Rr=Ia(),oe=Ra(),gf=ja();function rs(e){var t=Qn(e);return[oe(t,-1/0),oe(t,1/0)]}function wf(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 is(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 xf(e,t,n){var r=[];return Kn(n,function(i,o){var s=t[i],c=t[o];if(!(s[0]===c[0]||s[0]===c[1]||s[1]===c[0]||s[1]===c[1])){var h=e[s[0]],p=e[s[1]],g=e[c[0]],F=e[c[1]];ns(h,p,g,F)&&r.push([i,o])}}),r}function yf(e,t,n,r){var i=[];return Kn(n,r,function(o,s){var c=t[o];if(!(c[0]===s||c[1]===s)){var h=e[s],p=e[c[0]],g=e[c[1]];ns(p,g,h,h)&&i.push([o,s])}}),i}function Mf(e,t,n,r,i){var o,s,c=e.map(function(tt){return[ts(tt[0]),ts(tt[1])]});for(o=0;o<n.length;++o){var h=n[o];s=h[0];var p=h[1],g=t[s],F=t[p],N=gf(Rr(e[g[0]]),Rr(e[g[1]]),Rr(e[F[0]]),Rr(e[F[1]]));if(N){var q=e.length;e.push([Qn(N[0]),Qn(N[1])]),c.push(N),r.push([s,q],[p,q])}}for(r.sort(function(tt,rt){if(tt[0]!==rt[0])return tt[0]-rt[0];var D=c[tt[1]],a=c[rt[1]];return es(D[0],a[0])||es(D[1],a[1])}),o=r.length-1;o>=0;--o){var m=r[o];s=m[0];var C=t[s],Y=C[0],H=C[1],W=e[Y],Q=e[H];if((W[0]-Q[0]||W[1]-Q[1])<0){var et=Y;Y=H,H=et}C[0]=Y;var $=C[1]=m[1],J;for(i&&(J=C[2]);o>0&&r[o-1][0]===s;){var m=r[--o],ut=m[1];i?t.push([$,ut,J]):t.push([$,ut]),$=ut}i?t.push([$,H,J]):t.push([$,H])}return c}function os(e,t,n){for(var r=t.length,i=new df(r),o=[],s=0;s<t.length;++s){var c=t[s],h=rs(c[0]),p=rs(c[1]);o.push([oe(h[0],-1/0),oe(p[0],-1/0),oe(h[1],1/0),oe(p[1],1/0)])}Kn(o,function(m,C){i.link(m,C)});for(var g=!0,F=new Array(r),s=0;s<r;++s){var N=i.find(s);N!==s&&(g=!1,e[N]=[Math.min(e[s][0],e[N][0]),Math.min(e[s][1],e[N][1])])}if(g)return null;for(var q=0,s=0;s<r;++s){var N=i.find(s);N===s?(F[s]=q,e[q++]=e[s]):F[s]=-1}e.length=q;for(var s=0;s<r;++s)F[s]<0&&(F[s]=F[i.find(s)]);return F}function bf(e,t){return e[0]-t[0]||e[1]-t[1]}function Tf(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 as(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(Tf):e.sort(bf);for(var c=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[c++]=p)}e.length=c}}function _f(e,t,n){var r=os(e,[],is(e));return as(t,r,n),!!r}function Sf(e,t,n){var r=wf(e,t),i=xf(e,t,r),o=is(e),s=yf(e,t,r,o),c=Mf(e,t,i,s,n),h=os(e,c,o);return as(t,h,n),h?!0:i.length>0||s.length>0}function Bf(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 c=_f(e,t,!!n);Sf(e,t,!!n);)c=!0;if(n&&c){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 c}});function ne(e,t,n,r,i,o,s){let c=e.createTexture({label:t,size:{width:n,height:r},format:o,usage:s,mipLevelCount:i,sampleCount:1,dimension:"2d"}),h=c.createView(),p=[];for(let F=0;F<i;F++)p.push(c.createView({label:t,format:o,dimension:"2d",aspect:"all",baseMipLevel:F,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:c,view:h,mip_view:p,sampler:g}}async function he(e,t,n,r="rgba8unorm"){let o=await(await fetch(n)).blob(),s=await createImageBitmap(o),c=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,p=ne(e.device,t,s.width,s.height,1,r,c);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}function He(e,t,n,r="rgba8unorm"){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 c={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return s.sampler=e.device.createSampler(c),s}var ii="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,Fs=0,oi=1,As=2,ai=3,si={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 Is(e,t)},onRun:function(e,t,n){Es(e,t.data,n)},onDestroy:function(e,t){ci(t)},onResize:function(e,t){Ls(e,t)},onViewportPosition:function(e,t){}};function Is(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:[]},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 c=n.createPipelineLayout({bindGroupLayouts:o.bind_group_layout}),h=n.createComputePipeline({layout:c,compute:{module:n.createShaderModule({code:ii}),entryPoint:"cs_main"}});return ui(e,o,t),o.compute_pipeline=h,o}function ui(e,t,n){let{refs:r}=n,{device:i}=e,o=n.options.bloom_threshold??.1,s=n.options.bloom_knee??.2,c=n.options.bloom_combine_constant??.68,h=new Float32Array([o,o-s,s*2,.25/s,c,0,0,0]),p=i.createBuffer({label:"bloom static parameters buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});new Float32Array(p.getMappedRange()).set(h),p.unmap(),t.bind_group.length=0,t.params_buf=p,t.bind_group.push(Re(i,t,t.bind_groups_textures[0].mip_view[0],r.emissive.data.view,r.hdr.data.view,r.hdr.data.sampler,p,Fs<<16|0));for(let F=1;F<ue;F++)t.bind_group.push(Re(i,t,t.bind_groups_textures[1].mip_view[F],t.bind_groups_textures[0].view,r.hdr.data.view,r.hdr.data.sampler,p,oi<<16|F-1)),t.bind_group.push(Re(i,t,t.bind_groups_textures[0].mip_view[F],t.bind_groups_textures[1].view,r.hdr.data.view,r.hdr.data.sampler,p,oi<<16|F));t.bind_group.push(Re(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,As<<16|ue-2));let g=!0;for(let F=ue-2;F>=0;F--)g?(t.bind_group.push(Re(i,t,t.bind_groups_textures[1].mip_view[F],t.bind_groups_textures[0].view,t.bind_groups_textures[2].view,r.hdr.data.sampler,p,ai<<16|F)),g=!1):(t.bind_group.push(Re(i,t,t.bind_groups_textures[2].mip_view[F],t.bind_groups_textures[0].view,t.bind_groups_textures[1].view,r.hdr.data.sampler,p,ai<<16|F)),g=!0)}function Re(e,t,n,r,i,o,s,c){let h=new Uint32Array([c]),p=e.createBuffer({label:"bloom static mode_lod buffer",size:h.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});return 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 Es(e,t,n){let c=0,h=n.beginComputePass({label:"bloom Compute Pass"});h.setPipeline(t.compute_pipeline),h.setBindGroup(0,t.bind_group[c]),c+=1;let p=ar(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=ar(g,t.bind_groups_textures[0]),h.setBindGroup(0,t.bind_group[c]),c+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1),h.setBindGroup(0,t.bind_group[c]),c+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.setBindGroup(0,t.bind_group[c]),c+=1,p=ar(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=ar(g,t.bind_groups_textures[2]),h.setBindGroup(0,t.bind_group[c]),c+=1,h.dispatchWorkgroups(p.width/8+1,p.height/4+1,1);h.end()}function ar(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 Ls(e,t){let{device:n}=e,r=t.data;ci(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),ui(e,r,t)}function ci(e){for(let t of e.bind_groups_textures)t.texture.destroy();e.bind_groups_textures.length=0}var sn="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 fi={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:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return zs(e,t)},onRun:function(e,t,n){Rs(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){ms(e,t)},onViewportPosition:function(e,t){}};function zs(e,t){let{options:n,refs:r}=t,{device:i}=e,o=li(e),s=n.bloom_intensity??40,c=n.bloom_combine_constant??.68,h=new Float32Array([s,c]),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:sn}),entryPoint:"vert_main"},fragment:{module:i.createShaderModule({code:sn}),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 Rs(e,t,n){let r=n.beginRenderPass({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 ms(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 $e={};ri($e,{addSprite:()=>Vs,clear:()=>Ns,removeSprite:()=>qs,setSprite:()=>$s,setSpriteName:()=>Cs,setSpriteOpacity:()=>Xs,setSpritePosition:()=>ks,setSpriteRotation:()=>Hs,setSpriteScale:()=>Zs,setSpriteTint:()=>Ys});function un(e,t,n){if(n.spriteCount===0)return 0;let r=0,i=n.spriteCount-1,o=e<<16&16711680|t&65535;for(;r<=i;){let s=n.spriteData[r*12+11];if(o<=s)return r;let c=n.spriteData[i*12+11];if(o>=c)return i+1;let h=Math.floor((r+i)/2),p=n.spriteData[h*12+11];if(o===p)return h+1;o>p?r=h+1:i=h-1}return r}function Ze(){return Math.ceil(Math.random()*(Number.MAX_SAFE_INTEGER-10))}function Vs(e,t,n,r,i,o,s,c,h){let p=t.refs.spritesheet.data.spritesheet;t=t.data;let g=p.locations.indexOf(n),F=un(h,g,t),N=(F+1)*12;t.spriteData.set(t.spriteData.subarray(F*12,t.spriteCount*12),N),hi(t,p,F,n,r,i,o,s,c,h);for(let[m,C]of t.spriteIndices)C>=F&&t.spriteIndices.set(m,C+1);let q=Ze();return t.spriteIndices.set(q,F),t.spriteCount++,t.dirty=!0,q}function qs(e,t,n){t=t.data;let r=t.spriteIndices.get(n);for(let[o,s]of t.spriteIndices)s>r&&t.spriteIndices.set(o,s-1);let i=r*12;t.spriteData.set(t.spriteData.subarray((r+1)*12,t.spriteCount*12),i),t.spriteIndices.delete(n),t.spriteCount--,t.dirty=!0}function Ns(e,t){t=t.data,t.spriteIndices.clear(),t.spriteCount=0,t.instancedDrawCallCount=0,t.dirty=!0}function Cs(e,t,n,r,i){let o=t.refs.spritesheet.data.spritesheet;t=t.data;let s=o.locations.indexOf(r),c=o.spriteMeta[r].w,h=o.spriteMeta[r].h,g=t.spriteIndices.get(n)*12;t.spriteData[g+2]=c*i[0],t.spriteData[g+3]=h*i[1];let N=(t.spriteData[g+11]>>16&255)<<16&16711680|s&65535;t.spriteData[g+11]=N,t.dirty=!0}function ks(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o]=r[0],t.spriteData[o+1]=r[1],t.dirty=!0}function Ys(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o+4]=r[0],t.spriteData[o+5]=r[1],t.spriteData[o+6]=r[2],t.spriteData[o+7]=r[3],t.dirty=!0}function Xs(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o+8]=r,t.dirty=!0}function Hs(e,t,n,r){t=t.data;let o=t.spriteIndices.get(n)*12;t.spriteData[o+9]=r,t.dirty=!0}function Zs(e,t,n,r,i){let o=t.refs.spritesheet.data.spritesheet;t=t.data;let c=t.spriteIndices.get(n)*12,h=o.spriteMeta[r].w,p=o.spriteMeta[r].h;t.spriteData[c+2]=h*i[0],t.spriteData[c+3]=p*i[1],t.dirty=!0}function $s(e,t,n,r,i,o,s,c,h,p){let g=t.refs.spritesheet.data.spritesheet;t=t.data;let F=t.spriteIndices.get(n);hi(t,g,F,r,i,o,s,c,h,p),t.dirty=!0}function hi(e,t,n,r,i,o,s,c,h,p){if(!t.spriteMeta[r])throw new Error(`Sprite name ${r} could not be found in the spritesheet metaData`);let g=n*12,F=t.spriteMeta[r].w,N=t.spriteMeta[r].h,q=t.locations.indexOf(r),m=p<<16&16711680|q&65535;e.spriteData[g]=i[0],e.spriteData[g+1]=i[1],e.spriteData[g+2]=F*o[0],e.spriteData[g+3]=N*o[1],e.spriteData[g+4]=s[0],e.spriteData[g+5]=s[1],e.spriteData[g+6]=s[2],e.spriteData[g+7]=s[3],e.spriteData[g+8]=c,e.spriteData[g+9]=h,e.spriteData[g+11]=m}var pi={type:"cobalt:sprite",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"hdr",type:"textureView",format:"rgba16float",access:"write"},{name:"emissive",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(e,t={}){return Ws(e,t)},onRun:function(e,t,n){Qs(e,t,n)},onDestroy:function(e,t){Js(t)},onResize:function(e,t){},onViewportPosition:function(e,t){},customFunctions:{...$e}};async function Ws(e,t){let{device:n}=e,r=16192,i=r,s=Float32Array.BYTES_PER_ELEMENT*2,h=Float32Array.BYTES_PER_ELEMENT*2,g=Float32Array.BYTES_PER_ELEMENT*4,N=Float32Array.BYTES_PER_ELEMENT*4,q=n.createBuffer({size:(s+h+g+N)*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),m=t.refs.spritesheet.data,C=n.createBindGroup({layout:t.refs.spritesheet.data.bindGroupLayout,entries:[{binding:0,resource:{buffer:m.uniformBuffer}},{binding:1,resource:m.colorTexture.view},{binding:2,resource:m.colorTexture.sampler},{binding:3,resource:{buffer:q}},{binding:4,resource:m.emissiveTexture.view}]});return{instancedDrawCalls:new Uint32Array(r*2),instancedDrawCallCount:0,bindGroup:C,spriteBuffer:q,spriteData:new Float32Array(r*12),spriteCount:0,spriteIndices:new Map,dirty:!1}}function Qs(e,t,n){let{device:r}=e,i=t.options.loadOp||"load";if(t.data.dirty&&(Ks(t.data),t.data.dirty=!1),t.data.spriteCount>0){let h=t.data.spriteCount*12*Float32Array.BYTES_PER_ELEMENT;r.queue.writeBuffer(t.data.spriteBuffer,0,t.data.spriteData.buffer,0,h)}let o=n.beginRenderPass({colorAttachments:[{view:t.refs.hdr.data.view,clearValue:e.clearValue,loadOp:i,storeOp:"store"},{view:t.refs.emissive.data.view,clearValue:e.clearValue,loadOp:"clear",storeOp:"store"}]});o.setPipeline(t.refs.spritesheet.data.pipeline),o.setBindGroup(0,t.data.bindGroup),o.setVertexBuffer(0,t.refs.spritesheet.data.quads.buffer);let s=6,c=0;for(let h=0;h<t.data.instancedDrawCallCount;h++){let p=t.data.instancedDrawCalls[h*2]*s,g=t.data.instancedDrawCalls[h*2+1];o.draw(s,g,p,c),c+=g}o.end()}function Ks(e){let t=-1,n=0;e.instancedDrawCallCount=0;for(let r=0;r<e.spriteCount;r++){let i=e.spriteData[r*12+11]&65535;i!==t&&(n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++),t=i,n=0),n++}n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++)}function Js(e){e.data.instancedDrawCalls=null,e.data.bindGroup=null,e.data.spriteBuffer.destroy(),e.data.spriteBuffer=null,e.data.spriteData=null,e.data.spriteIndices.clear(),e.data.spriteIndices=null}var di={type:"cobalt:tile",refs:[{name:"tileAtlas",type:"textureView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return js(e,t)},onRun:function(e,t,n){tu(e,t,n)},onDestroy:function(e,t){vi(t)},onResize:function(e,t){},onViewportPosition:function(e,t){},customFunctions:{setTexture:async function(e,t,n){let{device:r}=e;vi(t),t.options.textureUrl=n;let i=await he(e,"tile map",t.options.textureUrl),o=r.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:t.data.uniformBuffer}},{binding:1,resource:i.view},{binding:2,resource:i.sampler}]});t.data.bindGroup=o,t.data.material=i}}};async function js(e,t){let{device:n}=e,r=await he(e,"tile map",t.options.textureUrl),i=new Float32Array([t.options.scrollScale,t.options.scrollScale]),o=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,s={size:i.byteLength,usage:o,mappedAtCreation:!0},c=n.createBuffer(s);return new Float32Array(c.getMappedRange()).set(i),c.unmap(),{bindGroup:n.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:c}},{binding:1,resource:r.view},{binding:2,resource:r.sampler}]}),material:r,uniformBuffer:c,scrollScale:t.options.scrollScale}}function tu(e,t,n){let{device:r}=e,i=t.options.loadOp||"load",o=n.beginRenderPass({colorAttachments:[{view:t.refs.hdr.data.view,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 vi(e){e.data.material.texture.destroy(),e.data.material.texture=void 0}var sr=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=Ze();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 ur=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 gi="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 cr=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:gi});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 wi="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 eu(e,t){return class extends e{constructor(...n){super(...n),t(this)}}}var ru=eu(Array,e=>e.fill(0)),Tt=1e-6;function nu(e){function t(z=0,O=0){let V=new e(2);return z!==void 0&&(V[0]=z,O!==void 0&&(V[1]=O)),V}let n=t;function r(z,O,V){let u=V??new e(2);return u[0]=z,u[1]=O,u}function i(z,O){let V=O??new e(2);return V[0]=Math.ceil(z[0]),V[1]=Math.ceil(z[1]),V}function o(z,O){let V=O??new e(2);return V[0]=Math.floor(z[0]),V[1]=Math.floor(z[1]),V}function s(z,O){let V=O??new e(2);return V[0]=Math.round(z[0]),V[1]=Math.round(z[1]),V}function c(z,O=0,V=1,u){let B=u??new e(2);return B[0]=Math.min(V,Math.max(O,z[0])),B[1]=Math.min(V,Math.max(O,z[1])),B}function h(z,O,V){let u=V??new e(2);return u[0]=z[0]+O[0],u[1]=z[1]+O[1],u}function p(z,O,V,u){let B=u??new e(2);return B[0]=z[0]+O[0]*V,B[1]=z[1]+O[1]*V,B}function g(z,O){let V=z[0],u=z[1],B=O[0],x=O[1],y=Math.sqrt(V*V+u*u),d=Math.sqrt(B*B+x*x),_=y*d,L=_&&rt(z,O)/_;return Math.acos(L)}function F(z,O,V){let u=V??new e(2);return u[0]=z[0]-O[0],u[1]=z[1]-O[1],u}let N=F;function q(z,O){return Math.abs(z[0]-O[0])<Tt&&Math.abs(z[1]-O[1])<Tt}function m(z,O){return z[0]===O[0]&&z[1]===O[1]}function C(z,O,V,u){let B=u??new e(2);return B[0]=z[0]+V*(O[0]-z[0]),B[1]=z[1]+V*(O[1]-z[1]),B}function Y(z,O,V,u){let B=u??new e(2);return B[0]=z[0]+V[0]*(O[0]-z[0]),B[1]=z[1]+V[1]*(O[1]-z[1]),B}function H(z,O,V){let u=V??new e(2);return u[0]=Math.max(z[0],O[0]),u[1]=Math.max(z[1],O[1]),u}function W(z,O,V){let u=V??new e(2);return u[0]=Math.min(z[0],O[0]),u[1]=Math.min(z[1],O[1]),u}function Q(z,O,V){let u=V??new e(2);return u[0]=z[0]*O,u[1]=z[1]*O,u}let et=Q;function $(z,O,V){let u=V??new e(2);return u[0]=z[0]/O,u[1]=z[1]/O,u}function J(z,O){let V=O??new e(2);return V[0]=1/z[0],V[1]=1/z[1],V}let ut=J;function tt(z,O,V){let u=V??new e(3),B=z[0]*O[1]-z[1]*O[0];return u[0]=0,u[1]=0,u[2]=B,u}function rt(z,O){return z[0]*O[0]+z[1]*O[1]}function D(z){let O=z[0],V=z[1];return Math.sqrt(O*O+V*V)}let a=D;function v(z){let O=z[0],V=z[1];return O*O+V*V}let T=v;function M(z,O){let V=z[0]-O[0],u=z[1]-O[1];return Math.sqrt(V*V+u*u)}let S=M;function E(z,O){let V=z[0]-O[0],u=z[1]-O[1];return V*V+u*u}let R=E;function P(z,O){let V=O??new e(2),u=z[0],B=z[1],x=Math.sqrt(u*u+B*B);return x>1e-5?(V[0]=u/x,V[1]=B/x):(V[0]=0,V[1]=0),V}function l(z,O){let V=O??new e(2);return V[0]=-z[0],V[1]=-z[1],V}function G(z,O){let V=O??new e(2);return V[0]=z[0],V[1]=z[1],V}let ot=G;function at(z,O,V){let u=V??new e(2);return u[0]=z[0]*O[0],u[1]=z[1]*O[1],u}let st=at;function ct(z,O,V){let u=V??new e(2);return u[0]=z[0]/O[0],u[1]=z[1]/O[1],u}let yt=ct;function pt(z=1,O){let V=O??new e(2),u=Math.random()*2*Math.PI;return V[0]=Math.cos(u)*z,V[1]=Math.sin(u)*z,V}function k(z){let O=z??new e(2);return O[0]=0,O[1]=0,O}function Z(z,O,V){let u=V??new e(2),B=z[0],x=z[1];return u[0]=B*O[0]+x*O[4]+O[12],u[1]=B*O[1]+x*O[5]+O[13],u}function U(z,O,V){let u=V??new e(2),B=z[0],x=z[1];return u[0]=O[0]*B+O[4]*x+O[8],u[1]=O[1]*B+O[5]*x+O[9],u}function f(z,O,V,u){let B=u??new e(2),x=z[0]-O[0],y=z[1]-O[1],d=Math.sin(V),_=Math.cos(V);return B[0]=x*_-y*d+O[0],B[1]=x*d+y*_+O[1],B}function b(z,O,V){let u=V??new e(2);return P(z,u),Q(u,O,u)}function w(z,O,V){let u=V??new e(2);return D(z)>O?b(z,O,u):G(z,u)}function I(z,O,V){let u=V??new e(2);return C(z,O,.5,u)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:c,add:h,addScaled:p,angle:g,subtract:F,sub:N,equalsApproximately:q,equals:m,lerp:C,lerpV:Y,max:H,min:W,mulScalar:Q,scale:et,divScalar:$,inverse:J,invert:ut,cross:tt,dot:rt,length:D,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:E,distSq:R,normalize:P,negate:l,copy:G,clone:ot,multiply:at,mul:st,divide:ct,div:yt,random:pt,zero:k,transformMat4:Z,transformMat3:U,rotate:f,setLength:b,truncate:w,midpoint:I}}var xi=new Map;function Si(e){let t=xi.get(e);return t||(t=nu(e),xi.set(e,t)),t}function iu(e){function t(d,_,L){let A=new e(3);return d!==void 0&&(A[0]=d,_!==void 0&&(A[1]=_,L!==void 0&&(A[2]=L))),A}let n=t;function r(d,_,L,A){let X=A??new e(3);return X[0]=d,X[1]=_,X[2]=L,X}function i(d,_){let L=_??new e(3);return L[0]=Math.ceil(d[0]),L[1]=Math.ceil(d[1]),L[2]=Math.ceil(d[2]),L}function o(d,_){let L=_??new e(3);return L[0]=Math.floor(d[0]),L[1]=Math.floor(d[1]),L[2]=Math.floor(d[2]),L}function s(d,_){let L=_??new e(3);return L[0]=Math.round(d[0]),L[1]=Math.round(d[1]),L[2]=Math.round(d[2]),L}function c(d,_=0,L=1,A){let X=A??new e(3);return X[0]=Math.min(L,Math.max(_,d[0])),X[1]=Math.min(L,Math.max(_,d[1])),X[2]=Math.min(L,Math.max(_,d[2])),X}function h(d,_,L){let A=L??new e(3);return A[0]=d[0]+_[0],A[1]=d[1]+_[1],A[2]=d[2]+_[2],A}function p(d,_,L,A){let X=A??new e(3);return X[0]=d[0]+_[0]*L,X[1]=d[1]+_[1]*L,X[2]=d[2]+_[2]*L,X}function g(d,_){let L=d[0],A=d[1],X=d[2],K=_[0],j=_[1],ft=_[2],nt=Math.sqrt(L*L+A*A+X*X),it=Math.sqrt(K*K+j*j+ft*ft),vt=nt*it,ht=vt&&rt(d,_)/vt;return Math.acos(ht)}function F(d,_,L){let A=L??new e(3);return A[0]=d[0]-_[0],A[1]=d[1]-_[1],A[2]=d[2]-_[2],A}let N=F;function q(d,_){return Math.abs(d[0]-_[0])<Tt&&Math.abs(d[1]-_[1])<Tt&&Math.abs(d[2]-_[2])<Tt}function m(d,_){return d[0]===_[0]&&d[1]===_[1]&&d[2]===_[2]}function C(d,_,L,A){let X=A??new e(3);return X[0]=d[0]+L*(_[0]-d[0]),X[1]=d[1]+L*(_[1]-d[1]),X[2]=d[2]+L*(_[2]-d[2]),X}function Y(d,_,L,A){let X=A??new e(3);return X[0]=d[0]+L[0]*(_[0]-d[0]),X[1]=d[1]+L[1]*(_[1]-d[1]),X[2]=d[2]+L[2]*(_[2]-d[2]),X}function H(d,_,L){let A=L??new e(3);return A[0]=Math.max(d[0],_[0]),A[1]=Math.max(d[1],_[1]),A[2]=Math.max(d[2],_[2]),A}function W(d,_,L){let A=L??new e(3);return A[0]=Math.min(d[0],_[0]),A[1]=Math.min(d[1],_[1]),A[2]=Math.min(d[2],_[2]),A}function Q(d,_,L){let A=L??new e(3);return A[0]=d[0]*_,A[1]=d[1]*_,A[2]=d[2]*_,A}let et=Q;function $(d,_,L){let A=L??new e(3);return A[0]=d[0]/_,A[1]=d[1]/_,A[2]=d[2]/_,A}function J(d,_){let L=_??new e(3);return L[0]=1/d[0],L[1]=1/d[1],L[2]=1/d[2],L}let ut=J;function tt(d,_,L){let A=L??new e(3),X=d[2]*_[0]-d[0]*_[2],K=d[0]*_[1]-d[1]*_[0];return A[0]=d[1]*_[2]-d[2]*_[1],A[1]=X,A[2]=K,A}function rt(d,_){return d[0]*_[0]+d[1]*_[1]+d[2]*_[2]}function D(d){let _=d[0],L=d[1],A=d[2];return Math.sqrt(_*_+L*L+A*A)}let a=D;function v(d){let _=d[0],L=d[1],A=d[2];return _*_+L*L+A*A}let T=v;function M(d,_){let L=d[0]-_[0],A=d[1]-_[1],X=d[2]-_[2];return Math.sqrt(L*L+A*A+X*X)}let S=M;function E(d,_){let L=d[0]-_[0],A=d[1]-_[1],X=d[2]-_[2];return L*L+A*A+X*X}let R=E;function P(d,_){let L=_??new e(3),A=d[0],X=d[1],K=d[2],j=Math.sqrt(A*A+X*X+K*K);return j>1e-5?(L[0]=A/j,L[1]=X/j,L[2]=K/j):(L[0]=0,L[1]=0,L[2]=0),L}function l(d,_){let L=_??new e(3);return L[0]=-d[0],L[1]=-d[1],L[2]=-d[2],L}function G(d,_){let L=_??new e(3);return L[0]=d[0],L[1]=d[1],L[2]=d[2],L}let ot=G;function at(d,_,L){let A=L??new e(3);return A[0]=d[0]*_[0],A[1]=d[1]*_[1],A[2]=d[2]*_[2],A}let st=at;function ct(d,_,L){let A=L??new e(3);return A[0]=d[0]/_[0],A[1]=d[1]/_[1],A[2]=d[2]/_[2],A}let yt=ct;function pt(d=1,_){let L=_??new e(3),A=Math.random()*2*Math.PI,X=Math.random()*2-1,K=Math.sqrt(1-X*X)*d;return L[0]=Math.cos(A)*K,L[1]=Math.sin(A)*K,L[2]=X*d,L}function k(d){let _=d??new e(3);return _[0]=0,_[1]=0,_[2]=0,_}function Z(d,_,L){let A=L??new e(3),X=d[0],K=d[1],j=d[2],ft=_[3]*X+_[7]*K+_[11]*j+_[15]||1;return A[0]=(_[0]*X+_[4]*K+_[8]*j+_[12])/ft,A[1]=(_[1]*X+_[5]*K+_[9]*j+_[13])/ft,A[2]=(_[2]*X+_[6]*K+_[10]*j+_[14])/ft,A}function U(d,_,L){let A=L??new e(3),X=d[0],K=d[1],j=d[2];return A[0]=X*_[0]+K*_[4]+j*_[8],A[1]=X*_[1]+K*_[5]+j*_[9],A[2]=X*_[2]+K*_[6]+j*_[10],A}function f(d,_,L){let A=L??new e(3),X=d[0],K=d[1],j=d[2];return A[0]=X*_[0]+K*_[4]+j*_[8],A[1]=X*_[1]+K*_[5]+j*_[9],A[2]=X*_[2]+K*_[6]+j*_[10],A}function b(d,_,L){let A=L??new e(3),X=_[0],K=_[1],j=_[2],ft=_[3]*2,nt=d[0],it=d[1],vt=d[2],ht=K*vt-j*it,lt=j*nt-X*vt,dt=X*it-K*nt;return A[0]=nt+ht*ft+(K*dt-j*lt)*2,A[1]=it+lt*ft+(j*ht-X*dt)*2,A[2]=vt+dt*ft+(X*lt-K*ht)*2,A}function w(d,_){let L=_??new e(3);return L[0]=d[12],L[1]=d[13],L[2]=d[14],L}function I(d,_,L){let A=L??new e(3),X=_*4;return A[0]=d[X+0],A[1]=d[X+1],A[2]=d[X+2],A}function z(d,_){let L=_??new e(3),A=d[0],X=d[1],K=d[2],j=d[4],ft=d[5],nt=d[6],it=d[8],vt=d[9],ht=d[10];return L[0]=Math.sqrt(A*A+X*X+K*K),L[1]=Math.sqrt(j*j+ft*ft+nt*nt),L[2]=Math.sqrt(it*it+vt*vt+ht*ht),L}function O(d,_,L,A){let X=A??new e(3),K=[],j=[];return K[0]=d[0]-_[0],K[1]=d[1]-_[1],K[2]=d[2]-_[2],j[0]=K[0],j[1]=K[1]*Math.cos(L)-K[2]*Math.sin(L),j[2]=K[1]*Math.sin(L)+K[2]*Math.cos(L),X[0]=j[0]+_[0],X[1]=j[1]+_[1],X[2]=j[2]+_[2],X}function V(d,_,L,A){let X=A??new e(3),K=[],j=[];return K[0]=d[0]-_[0],K[1]=d[1]-_[1],K[2]=d[2]-_[2],j[0]=K[2]*Math.sin(L)+K[0]*Math.cos(L),j[1]=K[1],j[2]=K[2]*Math.cos(L)-K[0]*Math.sin(L),X[0]=j[0]+_[0],X[1]=j[1]+_[1],X[2]=j[2]+_[2],X}function u(d,_,L,A){let X=A??new e(3),K=[],j=[];return K[0]=d[0]-_[0],K[1]=d[1]-_[1],K[2]=d[2]-_[2],j[0]=K[0]*Math.cos(L)-K[1]*Math.sin(L),j[1]=K[0]*Math.sin(L)+K[1]*Math.cos(L),j[2]=K[2],X[0]=j[0]+_[0],X[1]=j[1]+_[1],X[2]=j[2]+_[2],X}function B(d,_,L){let A=L??new e(3);return P(d,A),Q(A,_,A)}function x(d,_,L){let A=L??new e(3);return D(d)>_?B(d,_,A):G(d,A)}function y(d,_,L){let A=L??new e(3);return C(d,_,.5,A)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:c,add:h,addScaled:p,angle:g,subtract:F,sub:N,equalsApproximately:q,equals:m,lerp:C,lerpV:Y,max:H,min:W,mulScalar:Q,scale:et,divScalar:$,inverse:J,invert:ut,cross:tt,dot:rt,length:D,len:a,lengthSq:v,lenSq:T,distance:M,dist:S,distanceSq:E,distSq:R,normalize:P,negate:l,copy:G,clone:ot,multiply:at,mul:st,divide:ct,div:yt,random:pt,zero:k,transformMat4:Z,transformMat4Upper3x3:U,transformMat3:f,transformQuat:b,getTranslation:w,getAxis:I,getScaling:z,rotateX:O,rotateY:V,rotateZ:u,setLength:B,truncate:x,midpoint:y}}var yi=new Map;function fr(e){let t=yi.get(e);return t||(t=iu(e),yi.set(e,t)),t}function ou(e){let t=Si(e),n=fr(e);function r(f,b,w,I,z,O,V,u,B){let x=new e(12);return x[3]=0,x[7]=0,x[11]=0,f!==void 0&&(x[0]=f,b!==void 0&&(x[1]=b,w!==void 0&&(x[2]=w,I!==void 0&&(x[4]=I,z!==void 0&&(x[5]=z,O!==void 0&&(x[6]=O,V!==void 0&&(x[8]=V,u!==void 0&&(x[9]=u,B!==void 0&&(x[10]=B))))))))),x}function i(f,b,w,I,z,O,V,u,B,x){let y=x??new e(12);return y[0]=f,y[1]=b,y[2]=w,y[3]=0,y[4]=I,y[5]=z,y[6]=O,y[7]=0,y[8]=V,y[9]=u,y[10]=B,y[11]=0,y}function o(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=f[1],w[2]=f[2],w[3]=0,w[4]=f[4],w[5]=f[5],w[6]=f[6],w[7]=0,w[8]=f[8],w[9]=f[9],w[10]=f[10],w[11]=0,w}function s(f,b){let w=b??new e(12),I=f[0],z=f[1],O=f[2],V=f[3],u=I+I,B=z+z,x=O+O,y=I*u,d=z*u,_=z*B,L=O*u,A=O*B,X=O*x,K=V*u,j=V*B,ft=V*x;return w[0]=1-_-X,w[1]=d+ft,w[2]=L-j,w[3]=0,w[4]=d-ft,w[5]=1-y-X,w[6]=A+K,w[7]=0,w[8]=L+j,w[9]=A-K,w[10]=1-y-_,w[11]=0,w}function c(f,b){let w=b??new e(12);return w[0]=-f[0],w[1]=-f[1],w[2]=-f[2],w[4]=-f[4],w[5]=-f[5],w[6]=-f[6],w[8]=-f[8],w[9]=-f[9],w[10]=-f[10],w}function h(f,b,w){let I=w??new e(12);return I[0]=f[0]*b,I[1]=f[1]*b,I[2]=f[2]*b,I[4]=f[4]*b,I[5]=f[5]*b,I[6]=f[6]*b,I[8]=f[8]*b,I[9]=f[9]*b,I[10]=f[10]*b,I}let p=h;function g(f,b,w){let I=w??new e(12);return I[0]=f[0]+b[0],I[1]=f[1]+b[1],I[2]=f[2]+b[2],I[4]=f[4]+b[4],I[5]=f[5]+b[5],I[6]=f[6]+b[6],I[8]=f[8]+b[8],I[9]=f[9]+b[9],I[10]=f[10]+b[10],I}function F(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=f[1],w[2]=f[2],w[4]=f[4],w[5]=f[5],w[6]=f[6],w[8]=f[8],w[9]=f[9],w[10]=f[10],w}let N=F;function q(f,b){return Math.abs(f[0]-b[0])<Tt&&Math.abs(f[1]-b[1])<Tt&&Math.abs(f[2]-b[2])<Tt&&Math.abs(f[4]-b[4])<Tt&&Math.abs(f[5]-b[5])<Tt&&Math.abs(f[6]-b[6])<Tt&&Math.abs(f[8]-b[8])<Tt&&Math.abs(f[9]-b[9])<Tt&&Math.abs(f[10]-b[10])<Tt}function m(f,b){return f[0]===b[0]&&f[1]===b[1]&&f[2]===b[2]&&f[4]===b[4]&&f[5]===b[5]&&f[6]===b[6]&&f[8]===b[8]&&f[9]===b[9]&&f[10]===b[10]}function C(f){let b=f??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 Y(f,b){let w=b??new e(12);if(w===f){let _;return _=f[1],f[1]=f[4],f[4]=_,_=f[2],f[2]=f[8],f[8]=_,_=f[6],f[6]=f[9],f[9]=_,w}let I=f[0],z=f[1],O=f[2],V=f[4],u=f[5],B=f[6],x=f[8],y=f[9],d=f[10];return w[0]=I,w[1]=V,w[2]=x,w[4]=z,w[5]=u,w[6]=y,w[8]=O,w[9]=B,w[10]=d,w}function H(f,b){let w=b??new e(12),I=f[0],z=f[1],O=f[2],V=f[4],u=f[5],B=f[6],x=f[8],y=f[9],d=f[10],_=d*u-B*y,L=-d*V+B*x,A=y*V-u*x,X=1/(I*_+z*L+O*A);return w[0]=_*X,w[1]=(-d*z+O*y)*X,w[2]=(B*z-O*u)*X,w[4]=L*X,w[5]=(d*I-O*x)*X,w[6]=(-B*I+O*V)*X,w[8]=A*X,w[9]=(-y*I+z*x)*X,w[10]=(u*I-z*V)*X,w}function W(f){let b=f[0],w=f[1],I=f[2],z=f[4],O=f[5],V=f[6],u=f[8],B=f[9],x=f[10];return b*(O*x-B*V)-z*(w*x-B*I)+u*(w*V-O*I)}let Q=H;function et(f,b,w){let I=w??new e(12),z=f[0],O=f[1],V=f[2],u=f[4],B=f[5],x=f[6],y=f[8],d=f[9],_=f[10],L=b[0],A=b[1],X=b[2],K=b[4],j=b[5],ft=b[6],nt=b[8],it=b[9],vt=b[10];return I[0]=z*L+u*A+y*X,I[1]=O*L+B*A+d*X,I[2]=V*L+x*A+_*X,I[4]=z*K+u*j+y*ft,I[5]=O*K+B*j+d*ft,I[6]=V*K+x*j+_*ft,I[8]=z*nt+u*it+y*vt,I[9]=O*nt+B*it+d*vt,I[10]=V*nt+x*it+_*vt,I}let $=et;function J(f,b,w){let I=w??C();return f!==I&&(I[0]=f[0],I[1]=f[1],I[2]=f[2],I[4]=f[4],I[5]=f[5],I[6]=f[6]),I[8]=b[0],I[9]=b[1],I[10]=1,I}function ut(f,b){let w=b??t.create();return w[0]=f[8],w[1]=f[9],w}function tt(f,b,w){let I=w??t.create(),z=b*4;return I[0]=f[z+0],I[1]=f[z+1],I}function rt(f,b,w,I){let z=I===f?f:F(f,I),O=w*4;return z[O+0]=b[0],z[O+1]=b[1],z}function D(f,b){let w=b??t.create(),I=f[0],z=f[1],O=f[4],V=f[5];return w[0]=Math.sqrt(I*I+z*z),w[1]=Math.sqrt(O*O+V*V),w}function a(f,b){let w=b??n.create(),I=f[0],z=f[1],O=f[2],V=f[4],u=f[5],B=f[6],x=f[8],y=f[9],d=f[10];return w[0]=Math.sqrt(I*I+z*z+O*O),w[1]=Math.sqrt(V*V+u*u+B*B),w[2]=Math.sqrt(x*x+y*y+d*d),w}function v(f,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]=f[0],w[9]=f[1],w[10]=1,w}function T(f,b,w){let I=w??new e(12),z=b[0],O=b[1],V=f[0],u=f[1],B=f[2],x=f[4],y=f[5],d=f[6],_=f[8],L=f[9],A=f[10];return f!==I&&(I[0]=V,I[1]=u,I[2]=B,I[4]=x,I[5]=y,I[6]=d),I[8]=V*z+x*O+_,I[9]=u*z+y*O+L,I[10]=B*z+d*O+A,I}function M(f,b){let w=b??new e(12),I=Math.cos(f),z=Math.sin(f);return w[0]=I,w[1]=z,w[2]=0,w[4]=-z,w[5]=I,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function S(f,b,w){let I=w??new e(12),z=f[0],O=f[1],V=f[2],u=f[4],B=f[5],x=f[6],y=Math.cos(b),d=Math.sin(b);return I[0]=y*z+d*u,I[1]=y*O+d*B,I[2]=y*V+d*x,I[4]=y*u-d*z,I[5]=y*B-d*O,I[6]=y*x-d*V,f!==I&&(I[8]=f[8],I[9]=f[9],I[10]=f[10]),I}function E(f,b){let w=b??new e(12),I=Math.cos(f),z=Math.sin(f);return w[0]=1,w[1]=0,w[2]=0,w[4]=0,w[5]=I,w[6]=z,w[8]=0,w[9]=-z,w[10]=I,w}function R(f,b,w){let I=w??new e(12),z=f[4],O=f[5],V=f[6],u=f[8],B=f[9],x=f[10],y=Math.cos(b),d=Math.sin(b);return I[4]=y*z+d*u,I[5]=y*O+d*B,I[6]=y*V+d*x,I[8]=y*u-d*z,I[9]=y*B-d*O,I[10]=y*x-d*V,f!==I&&(I[0]=f[0],I[1]=f[1],I[2]=f[2]),I}function P(f,b){let w=b??new e(12),I=Math.cos(f),z=Math.sin(f);return w[0]=I,w[1]=0,w[2]=-z,w[4]=0,w[5]=1,w[6]=0,w[8]=z,w[9]=0,w[10]=I,w}function l(f,b,w){let I=w??new e(12),z=f[0],O=f[1],V=f[2],u=f[8],B=f[9],x=f[10],y=Math.cos(b),d=Math.sin(b);return I[0]=y*z-d*u,I[1]=y*O-d*B,I[2]=y*V-d*x,I[8]=y*u+d*z,I[9]=y*B+d*O,I[10]=y*x+d*V,f!==I&&(I[4]=f[4],I[5]=f[5],I[6]=f[6]),I}let G=M,ot=S;function at(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=0,w[2]=0,w[4]=0,w[5]=f[1],w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function st(f,b,w){let I=w??new e(12),z=b[0],O=b[1];return I[0]=z*f[0],I[1]=z*f[1],I[2]=z*f[2],I[4]=O*f[4],I[5]=O*f[5],I[6]=O*f[6],f!==I&&(I[8]=f[8],I[9]=f[9],I[10]=f[10]),I}function ct(f,b){let w=b??new e(12);return w[0]=f[0],w[1]=0,w[2]=0,w[4]=0,w[5]=f[1],w[6]=0,w[8]=0,w[9]=0,w[10]=f[2],w}function yt(f,b,w){let I=w??new e(12),z=b[0],O=b[1],V=b[2];return I[0]=z*f[0],I[1]=z*f[1],I[2]=z*f[2],I[4]=O*f[4],I[5]=O*f[5],I[6]=O*f[6],I[8]=V*f[8],I[9]=V*f[9],I[10]=V*f[10],I}function pt(f,b){let w=b??new e(12);return w[0]=f,w[1]=0,w[2]=0,w[4]=0,w[5]=f,w[6]=0,w[8]=0,w[9]=0,w[10]=1,w}function k(f,b,w){let I=w??new e(12);return I[0]=b*f[0],I[1]=b*f[1],I[2]=b*f[2],I[4]=b*f[4],I[5]=b*f[5],I[6]=b*f[6],f!==I&&(I[8]=f[8],I[9]=f[9],I[10]=f[10]),I}function Z(f,b){let w=b??new e(12);return w[0]=f,w[1]=0,w[2]=0,w[4]=0,w[5]=f,w[6]=0,w[8]=0,w[9]=0,w[10]=f,w}function U(f,b,w){let I=w??new e(12);return I[0]=b*f[0],I[1]=b*f[1],I[2]=b*f[2],I[4]=b*f[4],I[5]=b*f[5],I[6]=b*f[6],I[8]=b*f[8],I[9]=b*f[9],I[10]=b*f[10],I}return{add:g,clone:N,copy:F,create:r,determinant:W,equals:m,equalsApproximately:q,fromMat4:o,fromQuat:s,get3DScaling:a,getAxis:tt,getScaling:D,getTranslation:ut,identity:C,inverse:H,invert:Q,mul:$,mulScalar:p,multiply:et,multiplyScalar:h,negate:c,rotate:S,rotateX:R,rotateY:l,rotateZ:ot,rotation:M,rotationX:E,rotationY:P,rotationZ:G,scale:st,scale3D:yt,scaling:at,scaling3D:ct,set:i,setAxis:rt,setTranslation:J,translate:T,translation:v,transpose:Y,uniformScale:k,uniformScale3D:U,uniformScaling:pt,uniformScaling3D:Z}}var Mi=new Map;function au(e){let t=Mi.get(e);return t||(t=ou(e),Mi.set(e,t)),t}function su(e){let t=fr(e);function n(u,B,x,y,d,_,L,A,X,K,j,ft,nt,it,vt,ht){let lt=new e(16);return u!==void 0&&(lt[0]=u,B!==void 0&&(lt[1]=B,x!==void 0&&(lt[2]=x,y!==void 0&&(lt[3]=y,d!==void 0&&(lt[4]=d,_!==void 0&&(lt[5]=_,L!==void 0&&(lt[6]=L,A!==void 0&&(lt[7]=A,X!==void 0&&(lt[8]=X,K!==void 0&&(lt[9]=K,j!==void 0&&(lt[10]=j,ft!==void 0&&(lt[11]=ft,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,B,x,y,d,_,L,A,X,K,j,ft,nt,it,vt,ht,lt){let dt=lt??new e(16);return dt[0]=u,dt[1]=B,dt[2]=x,dt[3]=y,dt[4]=d,dt[5]=_,dt[6]=L,dt[7]=A,dt[8]=X,dt[9]=K,dt[10]=j,dt[11]=ft,dt[12]=nt,dt[13]=it,dt[14]=vt,dt[15]=ht,dt}function i(u,B){let x=B??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,B){let x=B??new e(16),y=u[0],d=u[1],_=u[2],L=u[3],A=y+y,X=d+d,K=_+_,j=y*A,ft=d*A,nt=d*X,it=_*A,vt=_*X,ht=_*K,lt=L*A,dt=L*X,wt=L*K;return x[0]=1-nt-ht,x[1]=ft+wt,x[2]=it-dt,x[3]=0,x[4]=ft-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,B){let x=B??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 c(u,B,x){let y=x??new e(16);return y[0]=u[0]+B[0],y[1]=u[1]+B[1],y[2]=u[2]+B[2],y[3]=u[3]+B[3],y[4]=u[4]+B[4],y[5]=u[5]+B[5],y[6]=u[6]+B[6],y[7]=u[7]+B[7],y[8]=u[8]+B[8],y[9]=u[9]+B[9],y[10]=u[10]+B[10],y[11]=u[11]+B[11],y[12]=u[12]+B[12],y[13]=u[13]+B[13],y[14]=u[14]+B[14],y[15]=u[15]+B[15],y}function h(u,B,x){let y=x??new e(16);return y[0]=u[0]*B,y[1]=u[1]*B,y[2]=u[2]*B,y[3]=u[3]*B,y[4]=u[4]*B,y[5]=u[5]*B,y[6]=u[6]*B,y[7]=u[7]*B,y[8]=u[8]*B,y[9]=u[9]*B,y[10]=u[10]*B,y[11]=u[11]*B,y[12]=u[12]*B,y[13]=u[13]*B,y[14]=u[14]*B,y[15]=u[15]*B,y}let p=h;function g(u,B){let x=B??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 F=g;function N(u,B){return Math.abs(u[0]-B[0])<Tt&&Math.abs(u[1]-B[1])<Tt&&Math.abs(u[2]-B[2])<Tt&&Math.abs(u[3]-B[3])<Tt&&Math.abs(u[4]-B[4])<Tt&&Math.abs(u[5]-B[5])<Tt&&Math.abs(u[6]-B[6])<Tt&&Math.abs(u[7]-B[7])<Tt&&Math.abs(u[8]-B[8])<Tt&&Math.abs(u[9]-B[9])<Tt&&Math.abs(u[10]-B[10])<Tt&&Math.abs(u[11]-B[11])<Tt&&Math.abs(u[12]-B[12])<Tt&&Math.abs(u[13]-B[13])<Tt&&Math.abs(u[14]-B[14])<Tt&&Math.abs(u[15]-B[15])<Tt}function q(u,B){return u[0]===B[0]&&u[1]===B[1]&&u[2]===B[2]&&u[3]===B[3]&&u[4]===B[4]&&u[5]===B[5]&&u[6]===B[6]&&u[7]===B[7]&&u[8]===B[8]&&u[9]===B[9]&&u[10]===B[10]&&u[11]===B[11]&&u[12]===B[12]&&u[13]===B[13]&&u[14]===B[14]&&u[15]===B[15]}function m(u){let B=u??new e(16);return B[0]=1,B[1]=0,B[2]=0,B[3]=0,B[4]=0,B[5]=1,B[6]=0,B[7]=0,B[8]=0,B[9]=0,B[10]=1,B[11]=0,B[12]=0,B[13]=0,B[14]=0,B[15]=1,B}function C(u,B){let x=B??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],_=u[2],L=u[3],A=u[4],X=u[5],K=u[6],j=u[7],ft=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]=ft,x[3]=ht,x[4]=d,x[5]=X,x[6]=nt,x[7]=lt,x[8]=_,x[9]=K,x[10]=it,x[11]=dt,x[12]=L,x[13]=j,x[14]=vt,x[15]=wt,x}function Y(u,B){let x=B??new e(16),y=u[0],d=u[1],_=u[2],L=u[3],A=u[4],X=u[5],K=u[6],j=u[7],ft=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,qt=dt*vt,Mt=K*wt,bt=dt*j,Xt=K*vt,St=it*j,Bt=_*wt,Zt=dt*L,Pt=_*vt,Dt=it*L,$t=_*j,Ut=K*L,Gt=ft*lt,Wt=ht*nt,Ft=A*lt,At=ht*X,Jt=A*nt,Lt=ft*X,zt=y*lt,Te=ht*d,Rt=y*nt,mt=ft*d,_e=y*X,Ot=A*d,Vt=gt*X+bt*nt+Xt*lt-(qt*X+Mt*nt+St*lt),Ee=qt*d+Bt*nt+Dt*lt-(gt*d+Zt*nt+Pt*lt),Le=Mt*d+Zt*X+$t*lt-(bt*d+Bt*X+Ut*lt),ze=St*d+Pt*X+Ut*nt-(Xt*d+Dt*X+$t*nt),Ht=1/(y*Vt+A*Ee+ft*Le+ht*ze);return x[0]=Ht*Vt,x[1]=Ht*Ee,x[2]=Ht*Le,x[3]=Ht*ze,x[4]=Ht*(qt*A+Mt*ft+St*ht-(gt*A+bt*ft+Xt*ht)),x[5]=Ht*(gt*y+Zt*ft+Pt*ht-(qt*y+Bt*ft+Dt*ht)),x[6]=Ht*(bt*y+Bt*A+Ut*ht-(Mt*y+Zt*A+$t*ht)),x[7]=Ht*(Xt*y+Dt*A+$t*ft-(St*y+Pt*A+Ut*ft)),x[8]=Ht*(Gt*j+At*vt+Jt*wt-(Wt*j+Ft*vt+Lt*wt)),x[9]=Ht*(Wt*L+zt*vt+mt*wt-(Gt*L+Te*vt+Rt*wt)),x[10]=Ht*(Ft*L+Te*j+_e*wt-(At*L+zt*j+Ot*wt)),x[11]=Ht*(Lt*L+Rt*j+Ot*vt-(Jt*L+mt*j+_e*vt)),x[12]=Ht*(Ft*it+Lt*dt+Wt*K-(Jt*dt+Gt*K+At*it)),x[13]=Ht*(Rt*dt+Gt*_+Te*it-(zt*it+mt*dt+Wt*_)),x[14]=Ht*(zt*K+Ot*dt+At*_-(_e*dt+Ft*_+Te*K)),x[15]=Ht*(_e*it+Jt*_+mt*K-(Rt*K+Ot*it+Lt*_)),x}function H(u){let B=u[0],x=u[1],y=u[2],d=u[3],_=u[4],L=u[5],A=u[6],X=u[7],K=u[8],j=u[9],ft=u[10],nt=u[11],it=u[12],vt=u[13],ht=u[14],lt=u[15],dt=ft*lt,wt=ht*nt,gt=A*lt,qt=ht*X,Mt=A*nt,bt=ft*X,Xt=y*lt,St=ht*d,Bt=y*nt,Zt=ft*d,Pt=y*X,Dt=A*d,$t=dt*L+qt*j+Mt*vt-(wt*L+gt*j+bt*vt),Ut=wt*x+Xt*j+Zt*vt-(dt*x+St*j+Bt*vt),Gt=gt*x+St*L+Pt*vt-(qt*x+Xt*L+Dt*vt),Wt=bt*x+Bt*L+Dt*j-(Mt*x+Zt*L+Pt*j);return B*$t+_*Ut+K*Gt+it*Wt}let W=Y;function Q(u,B,x){let y=x??new e(16),d=u[0],_=u[1],L=u[2],A=u[3],X=u[4],K=u[5],j=u[6],ft=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],qt=B[0],Mt=B[1],bt=B[2],Xt=B[3],St=B[4],Bt=B[5],Zt=B[6],Pt=B[7],Dt=B[8],$t=B[9],Ut=B[10],Gt=B[11],Wt=B[12],Ft=B[13],At=B[14],Jt=B[15];return y[0]=d*qt+X*Mt+nt*bt+lt*Xt,y[1]=_*qt+K*Mt+it*bt+dt*Xt,y[2]=L*qt+j*Mt+vt*bt+wt*Xt,y[3]=A*qt+ft*Mt+ht*bt+gt*Xt,y[4]=d*St+X*Bt+nt*Zt+lt*Pt,y[5]=_*St+K*Bt+it*Zt+dt*Pt,y[6]=L*St+j*Bt+vt*Zt+wt*Pt,y[7]=A*St+ft*Bt+ht*Zt+gt*Pt,y[8]=d*Dt+X*$t+nt*Ut+lt*Gt,y[9]=_*Dt+K*$t+it*Ut+dt*Gt,y[10]=L*Dt+j*$t+vt*Ut+wt*Gt,y[11]=A*Dt+ft*$t+ht*Ut+gt*Gt,y[12]=d*Wt+X*Ft+nt*At+lt*Jt,y[13]=_*Wt+K*Ft+it*At+dt*Jt,y[14]=L*Wt+j*Ft+vt*At+wt*Jt,y[15]=A*Wt+ft*Ft+ht*At+gt*Jt,y}let et=Q;function $(u,B,x){let y=x??m();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]=B[0],y[13]=B[1],y[14]=B[2],y[15]=1,y}function J(u,B){let x=B??t.create();return x[0]=u[12],x[1]=u[13],x[2]=u[14],x}function ut(u,B,x){let y=x??t.create(),d=B*4;return y[0]=u[d+0],y[1]=u[d+1],y[2]=u[d+2],y}function tt(u,B,x,y){let d=y===u?y:g(u,y),_=x*4;return d[_+0]=B[0],d[_+1]=B[1],d[_+2]=B[2],d}function rt(u,B){let x=B??t.create(),y=u[0],d=u[1],_=u[2],L=u[4],A=u[5],X=u[6],K=u[8],j=u[9],ft=u[10];return x[0]=Math.sqrt(y*y+d*d+_*_),x[1]=Math.sqrt(L*L+A*A+X*X),x[2]=Math.sqrt(K*K+j*j+ft*ft),x}function D(u,B,x,y,d){let _=d??new e(16),L=Math.tan(Math.PI*.5-.5*u);if(_[0]=L/B,_[1]=0,_[2]=0,_[3]=0,_[4]=0,_[5]=L,_[6]=0,_[7]=0,_[8]=0,_[9]=0,_[11]=-1,_[12]=0,_[13]=0,_[15]=0,Number.isFinite(y)){let A=1/(x-y);_[10]=y*A,_[14]=y*x*A}else _[10]=-1,_[14]=-x;return _}function a(u,B,x,y=1/0,d){let _=d??new e(16),L=1/Math.tan(u*.5);if(_[0]=L/B,_[1]=0,_[2]=0,_[3]=0,_[4]=0,_[5]=L,_[6]=0,_[7]=0,_[8]=0,_[9]=0,_[11]=-1,_[12]=0,_[13]=0,_[15]=0,y===1/0)_[10]=0,_[14]=x;else{let A=1/(y-x);_[10]=x*A,_[14]=y*x*A}return _}function v(u,B,x,y,d,_,L){let A=L??new e(16);return A[0]=2/(B-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-_),A[11]=0,A[12]=(B+u)/(u-B),A[13]=(y+x)/(x-y),A[14]=d/(d-_),A[15]=1,A}function T(u,B,x,y,d,_,L){let A=L??new e(16),X=B-u,K=y-x,j=d-_;return A[0]=2*d/X,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/K,A[6]=0,A[7]=0,A[8]=(u+B)/X,A[9]=(y+x)/K,A[10]=_/j,A[11]=-1,A[12]=0,A[13]=0,A[14]=d*_/j,A[15]=0,A}function M(u,B,x,y,d,_=1/0,L){let A=L??new e(16),X=B-u,K=y-x;if(A[0]=2*d/X,A[1]=0,A[2]=0,A[3]=0,A[4]=0,A[5]=2*d/K,A[6]=0,A[7]=0,A[8]=(u+B)/X,A[9]=(y+x)/K,A[11]=-1,A[12]=0,A[13]=0,A[15]=0,_===1/0)A[10]=0,A[14]=d;else{let j=1/(_-d);A[10]=d*j,A[14]=_*d*j}return A}let S=t.create(),E=t.create(),R=t.create();function P(u,B,x,y){let d=y??new e(16);return t.normalize(t.subtract(B,u,R),R),t.normalize(t.cross(x,R,S),S),t.normalize(t.cross(R,S,E),E),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=E[0],d[5]=E[1],d[6]=E[2],d[7]=0,d[8]=R[0],d[9]=R[1],d[10]=R[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function l(u,B,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,B,R),R),t.normalize(t.cross(x,R,S),S),t.normalize(t.cross(R,S,E),E),d[0]=S[0],d[1]=S[1],d[2]=S[2],d[3]=0,d[4]=E[0],d[5]=E[1],d[6]=E[2],d[7]=0,d[8]=R[0],d[9]=R[1],d[10]=R[2],d[11]=0,d[12]=u[0],d[13]=u[1],d[14]=u[2],d[15]=1,d}function G(u,B,x,y){let d=y??new e(16);return t.normalize(t.subtract(u,B,R),R),t.normalize(t.cross(x,R,S),S),t.normalize(t.cross(R,S,E),E),d[0]=S[0],d[1]=E[0],d[2]=R[0],d[3]=0,d[4]=S[1],d[5]=E[1],d[6]=R[1],d[7]=0,d[8]=S[2],d[9]=E[2],d[10]=R[2],d[11]=0,d[12]=-(S[0]*u[0]+S[1]*u[1]+S[2]*u[2]),d[13]=-(E[0]*u[0]+E[1]*u[1]+E[2]*u[2]),d[14]=-(R[0]*u[0]+R[1]*u[1]+R[2]*u[2]),d[15]=1,d}function ot(u,B){let x=B??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,B,x){let y=x??new e(16),d=B[0],_=B[1],L=B[2],A=u[0],X=u[1],K=u[2],j=u[3],ft=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],qt=u[13],Mt=u[14],bt=u[15];return u!==y&&(y[0]=A,y[1]=X,y[2]=K,y[3]=j,y[4]=ft,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+ft*_+ht*L+gt,y[13]=X*d+nt*_+lt*L+qt,y[14]=K*d+it*_+dt*L+Mt,y[15]=j*d+vt*_+wt*L+bt,y}function st(u,B){let x=B??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 ct(u,B,x){let y=x??new e(16),d=u[4],_=u[5],L=u[6],A=u[7],X=u[8],K=u[9],j=u[10],ft=u[11],nt=Math.cos(B),it=Math.sin(B);return y[4]=nt*d+it*X,y[5]=nt*_+it*K,y[6]=nt*L+it*j,y[7]=nt*A+it*ft,y[8]=nt*X-it*d,y[9]=nt*K-it*_,y[10]=nt*j-it*L,y[11]=nt*ft-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,B){let x=B??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,B,x){let y=x??new e(16),d=u[0],_=u[1],L=u[2],A=u[3],X=u[8],K=u[9],j=u[10],ft=u[11],nt=Math.cos(B),it=Math.sin(B);return y[0]=nt*d-it*X,y[1]=nt*_-it*K,y[2]=nt*L-it*j,y[3]=nt*A-it*ft,y[8]=nt*X+it*d,y[9]=nt*K+it*_,y[10]=nt*j+it*L,y[11]=nt*ft+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,B){let x=B??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 Z(u,B,x){let y=x??new e(16),d=u[0],_=u[1],L=u[2],A=u[3],X=u[4],K=u[5],j=u[6],ft=u[7],nt=Math.cos(B),it=Math.sin(B);return y[0]=nt*d+it*X,y[1]=nt*_+it*K,y[2]=nt*L+it*j,y[3]=nt*A+it*ft,y[4]=nt*X-it*d,y[5]=nt*K-it*_,y[6]=nt*j-it*L,y[7]=nt*ft-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 U(u,B,x){let y=x??new e(16),d=u[0],_=u[1],L=u[2],A=Math.sqrt(d*d+_*_+L*L);d/=A,_/=A,L/=A;let X=d*d,K=_*_,j=L*L,ft=Math.cos(B),nt=Math.sin(B),it=1-ft;return y[0]=X+(1-X)*ft,y[1]=d*_*it+L*nt,y[2]=d*L*it-_*nt,y[3]=0,y[4]=d*_*it-L*nt,y[5]=K+(1-K)*ft,y[6]=_*L*it+d*nt,y[7]=0,y[8]=d*L*it+_*nt,y[9]=_*L*it-d*nt,y[10]=j+(1-j)*ft,y[11]=0,y[12]=0,y[13]=0,y[14]=0,y[15]=1,y}let f=U;function b(u,B,x,y){let d=y??new e(16),_=B[0],L=B[1],A=B[2],X=Math.sqrt(_*_+L*L+A*A);_/=X,L/=X,A/=X;let K=_*_,j=L*L,ft=A*A,nt=Math.cos(x),it=Math.sin(x),vt=1-nt,ht=K+(1-K)*nt,lt=_*L*vt+A*it,dt=_*A*vt-L*it,wt=_*L*vt-A*it,gt=j+(1-j)*nt,qt=L*A*vt+_*it,Mt=_*A*vt+L*it,bt=L*A*vt-_*it,Xt=ft+(1-ft)*nt,St=u[0],Bt=u[1],Zt=u[2],Pt=u[3],Dt=u[4],$t=u[5],Ut=u[6],Gt=u[7],Wt=u[8],Ft=u[9],At=u[10],Jt=u[11];return d[0]=ht*St+lt*Dt+dt*Wt,d[1]=ht*Bt+lt*$t+dt*Ft,d[2]=ht*Zt+lt*Ut+dt*At,d[3]=ht*Pt+lt*Gt+dt*Jt,d[4]=wt*St+gt*Dt+qt*Wt,d[5]=wt*Bt+gt*$t+qt*Ft,d[6]=wt*Zt+gt*Ut+qt*At,d[7]=wt*Pt+gt*Gt+qt*Jt,d[8]=Mt*St+bt*Dt+Xt*Wt,d[9]=Mt*Bt+bt*$t+Xt*Ft,d[10]=Mt*Zt+bt*Ut+Xt*At,d[11]=Mt*Pt+bt*Gt+Xt*Jt,u!==d&&(d[12]=u[12],d[13]=u[13],d[14]=u[14],d[15]=u[15]),d}let w=b;function I(u,B){let x=B??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 z(u,B,x){let y=x??new e(16),d=B[0],_=B[1],L=B[2];return y[0]=d*u[0],y[1]=d*u[1],y[2]=d*u[2],y[3]=d*u[3],y[4]=_*u[4],y[5]=_*u[5],y[6]=_*u[6],y[7]=_*u[7],y[8]=L*u[8],y[9]=L*u[9],y[10]=L*u[10],y[11]=L*u[11],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}function O(u,B){let x=B??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 V(u,B,x){let y=x??new e(16);return y[0]=B*u[0],y[1]=B*u[1],y[2]=B*u[2],y[3]=B*u[3],y[4]=B*u[4],y[5]=B*u[5],y[6]=B*u[6],y[7]=B*u[7],y[8]=B*u[8],y[9]=B*u[9],y[10]=B*u[10],y[11]=B*u[11],u!==y&&(y[12]=u[12],y[13]=u[13],y[14]=u[14],y[15]=u[15]),y}return{add:c,aim:P,axisRotate:b,axisRotation:U,cameraAim:l,clone:F,copy:g,create:n,determinant:H,equals:q,equalsApproximately:N,fromMat3:i,fromQuat:o,frustum:T,frustumReverseZ:M,getAxis:ut,getScaling:rt,getTranslation:J,identity:m,inverse:Y,invert:W,lookAt:G,mul:et,mulScalar:p,multiply:Q,multiplyScalar:h,negate:s,ortho:v,perspective:D,perspectiveReverseZ:a,rotate:w,rotateX:ct,rotateY:pt,rotateZ:Z,rotation:f,rotationX:st,rotationY:yt,rotationZ:k,scale:z,scaling:I,set:r,setAxis:tt,setTranslation:$,translate:at,translation:ot,transpose:C,uniformScale:V,uniformScaling:O}}var bi=new Map;function uu(e){let t=bi.get(e);return t||(t=su(e),bi.set(e,t)),t}function cu(e){let t=fr(e);function n(k,Z,U,f){let b=new e(4);return k!==void 0&&(b[0]=k,Z!==void 0&&(b[1]=Z,U!==void 0&&(b[2]=U,f!==void 0&&(b[3]=f)))),b}let r=n;function i(k,Z,U,f,b){let w=b??new e(4);return w[0]=k,w[1]=Z,w[2]=U,w[3]=f,w}function o(k,Z,U){let f=U??new e(4),b=Z*.5,w=Math.sin(b);return f[0]=w*k[0],f[1]=w*k[1],f[2]=w*k[2],f[3]=Math.cos(b),f}function s(k,Z){let U=Z??t.create(3),f=Math.acos(k[3])*2,b=Math.sin(f*.5);return b>Tt?(U[0]=k[0]/b,U[1]=k[1]/b,U[2]=k[2]/b):(U[0]=1,U[1]=0,U[2]=0),{angle:f,axis:U}}function c(k,Z){let U=D(k,Z);return Math.acos(2*U*U-1)}function h(k,Z,U){let f=U??new e(4),b=k[0],w=k[1],I=k[2],z=k[3],O=Z[0],V=Z[1],u=Z[2],B=Z[3];return f[0]=b*B+z*O+w*u-I*V,f[1]=w*B+z*V+I*O-b*u,f[2]=I*B+z*u+b*V-w*O,f[3]=z*B-b*O-w*V-I*u,f}let p=h;function g(k,Z,U){let f=U??new e(4),b=Z*.5,w=k[0],I=k[1],z=k[2],O=k[3],V=Math.sin(b),u=Math.cos(b);return f[0]=w*u+O*V,f[1]=I*u+z*V,f[2]=z*u-I*V,f[3]=O*u-w*V,f}function F(k,Z,U){let f=U??new e(4),b=Z*.5,w=k[0],I=k[1],z=k[2],O=k[3],V=Math.sin(b),u=Math.cos(b);return f[0]=w*u-z*V,f[1]=I*u+O*V,f[2]=z*u+w*V,f[3]=O*u-I*V,f}function N(k,Z,U){let f=U??new e(4),b=Z*.5,w=k[0],I=k[1],z=k[2],O=k[3],V=Math.sin(b),u=Math.cos(b);return f[0]=w*u+I*V,f[1]=I*u-w*V,f[2]=z*u+O*V,f[3]=O*u-z*V,f}function q(k,Z,U,f){let b=f??new e(4),w=k[0],I=k[1],z=k[2],O=k[3],V=Z[0],u=Z[1],B=Z[2],x=Z[3],y=w*V+I*u+z*B+O*x;y<0&&(y=-y,V=-V,u=-u,B=-B,x=-x);let d,_;if(1-y>Tt){let L=Math.acos(y),A=Math.sin(L);d=Math.sin((1-U)*L)/A,_=Math.sin(U*L)/A}else d=1-U,_=U;return b[0]=d*w+_*V,b[1]=d*I+_*u,b[2]=d*z+_*B,b[3]=d*O+_*x,b}function m(k,Z){let U=Z??new e(4),f=k[0],b=k[1],w=k[2],I=k[3],z=f*f+b*b+w*w+I*I,O=z?1/z:0;return U[0]=-f*O,U[1]=-b*O,U[2]=-w*O,U[3]=I*O,U}function C(k,Z){let U=Z??new e(4);return U[0]=-k[0],U[1]=-k[1],U[2]=-k[2],U[3]=k[3],U}function Y(k,Z){let U=Z??new e(4),f=k[0]+k[5]+k[10];if(f>0){let b=Math.sqrt(f+1);U[3]=.5*b;let w=.5/b;U[0]=(k[6]-k[9])*w,U[1]=(k[8]-k[2])*w,U[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,I=(b+2)%3,z=Math.sqrt(k[b*4+b]-k[w*4+w]-k[I*4+I]+1);U[b]=.5*z;let O=.5/z;U[3]=(k[w*4+I]-k[I*4+w])*O,U[w]=(k[w*4+b]+k[b*4+w])*O,U[I]=(k[I*4+b]+k[b*4+I])*O}return U}function H(k,Z,U,f,b){let w=b??new e(4),I=k*.5,z=Z*.5,O=U*.5,V=Math.sin(I),u=Math.cos(I),B=Math.sin(z),x=Math.cos(z),y=Math.sin(O),d=Math.cos(O);switch(f){case"xyz":w[0]=V*x*d+u*B*y,w[1]=u*B*d-V*x*y,w[2]=u*x*y+V*B*d,w[3]=u*x*d-V*B*y;break;case"xzy":w[0]=V*x*d-u*B*y,w[1]=u*B*d-V*x*y,w[2]=u*x*y+V*B*d,w[3]=u*x*d+V*B*y;break;case"yxz":w[0]=V*x*d+u*B*y,w[1]=u*B*d-V*x*y,w[2]=u*x*y-V*B*d,w[3]=u*x*d+V*B*y;break;case"yzx":w[0]=V*x*d+u*B*y,w[1]=u*B*d+V*x*y,w[2]=u*x*y-V*B*d,w[3]=u*x*d-V*B*y;break;case"zxy":w[0]=V*x*d-u*B*y,w[1]=u*B*d+V*x*y,w[2]=u*x*y+V*B*d,w[3]=u*x*d-V*B*y;break;case"zyx":w[0]=V*x*d-u*B*y,w[1]=u*B*d+V*x*y,w[2]=u*x*y-V*B*d,w[3]=u*x*d+V*B*y;break;default:throw new Error(`Unknown rotation order: ${f}`)}return w}function W(k,Z){let U=Z??new e(4);return U[0]=k[0],U[1]=k[1],U[2]=k[2],U[3]=k[3],U}let Q=W;function et(k,Z,U){let f=U??new e(4);return f[0]=k[0]+Z[0],f[1]=k[1]+Z[1],f[2]=k[2]+Z[2],f[3]=k[3]+Z[3],f}function $(k,Z,U){let f=U??new e(4);return f[0]=k[0]-Z[0],f[1]=k[1]-Z[1],f[2]=k[2]-Z[2],f[3]=k[3]-Z[3],f}let J=$;function ut(k,Z,U){let f=U??new e(4);return f[0]=k[0]*Z,f[1]=k[1]*Z,f[2]=k[2]*Z,f[3]=k[3]*Z,f}let tt=ut;function rt(k,Z,U){let f=U??new e(4);return f[0]=k[0]/Z,f[1]=k[1]/Z,f[2]=k[2]/Z,f[3]=k[3]/Z,f}function D(k,Z){return k[0]*Z[0]+k[1]*Z[1]+k[2]*Z[2]+k[3]*Z[3]}function a(k,Z,U,f){let b=f??new e(4);return b[0]=k[0]+U*(Z[0]-k[0]),b[1]=k[1]+U*(Z[1]-k[1]),b[2]=k[2]+U*(Z[2]-k[2]),b[3]=k[3]+U*(Z[3]-k[3]),b}function v(k){let Z=k[0],U=k[1],f=k[2],b=k[3];return Math.sqrt(Z*Z+U*U+f*f+b*b)}let T=v;function M(k){let Z=k[0],U=k[1],f=k[2],b=k[3];return Z*Z+U*U+f*f+b*b}let S=M;function E(k,Z){let U=Z??new e(4),f=k[0],b=k[1],w=k[2],I=k[3],z=Math.sqrt(f*f+b*b+w*w+I*I);return z>1e-5?(U[0]=f/z,U[1]=b/z,U[2]=w/z,U[3]=I/z):(U[0]=0,U[1]=0,U[2]=0,U[3]=1),U}function R(k,Z){return Math.abs(k[0]-Z[0])<Tt&&Math.abs(k[1]-Z[1])<Tt&&Math.abs(k[2]-Z[2])<Tt&&Math.abs(k[3]-Z[3])<Tt}function P(k,Z){return k[0]===Z[0]&&k[1]===Z[1]&&k[2]===Z[2]&&k[3]===Z[3]}function l(k){let Z=k??new e(4);return Z[0]=0,Z[1]=0,Z[2]=0,Z[3]=1,Z}let G=t.create(),ot=t.create(),at=t.create();function st(k,Z,U){let f=U??new e(4),b=t.dot(k,Z);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,f),f):b>.999999?(f[0]=0,f[1]=0,f[2]=0,f[3]=1,f):(t.cross(k,Z,G),f[0]=G[0],f[1]=G[1],f[2]=G[2],f[3]=1+b,E(f,f))}let ct=new e(4),yt=new e(4);function pt(k,Z,U,f,b,w){let I=w??new e(4);return q(k,f,b,ct),q(Z,U,b,yt),q(ct,yt,2*b*(1-b),I),I}return{create:n,fromValues:r,set:i,fromAxisAngle:o,toAxisAngle:s,angle:c,multiply:h,mul:p,rotateX:g,rotateY:F,rotateZ:N,slerp:q,inverse:m,conjugate:C,fromMat:Y,fromEuler:H,copy:W,clone:Q,add:et,subtract:$,sub:J,mulScalar:ut,scale:tt,divScalar:rt,dot:D,lerp:a,length:v,len:T,lengthSq:M,lenSq:S,normalize:E,equalsApproximately:R,equals:P,identity:l,rotationTo:st,sqlerp:pt}}var Ti=new Map;function fu(e){let t=Ti.get(e);return t||(t=cu(e),Ti.set(e,t)),t}function lu(e){function t(U,f,b,w){let I=new e(4);return U!==void 0&&(I[0]=U,f!==void 0&&(I[1]=f,b!==void 0&&(I[2]=b,w!==void 0&&(I[3]=w)))),I}let n=t;function r(U,f,b,w,I){let z=I??new e(4);return z[0]=U,z[1]=f,z[2]=b,z[3]=w,z}function i(U,f){let b=f??new e(4);return b[0]=Math.ceil(U[0]),b[1]=Math.ceil(U[1]),b[2]=Math.ceil(U[2]),b[3]=Math.ceil(U[3]),b}function o(U,f){let b=f??new e(4);return b[0]=Math.floor(U[0]),b[1]=Math.floor(U[1]),b[2]=Math.floor(U[2]),b[3]=Math.floor(U[3]),b}function s(U,f){let b=f??new e(4);return b[0]=Math.round(U[0]),b[1]=Math.round(U[1]),b[2]=Math.round(U[2]),b[3]=Math.round(U[3]),b}function c(U,f=0,b=1,w){let I=w??new e(4);return I[0]=Math.min(b,Math.max(f,U[0])),I[1]=Math.min(b,Math.max(f,U[1])),I[2]=Math.min(b,Math.max(f,U[2])),I[3]=Math.min(b,Math.max(f,U[3])),I}function h(U,f,b){let w=b??new e(4);return w[0]=U[0]+f[0],w[1]=U[1]+f[1],w[2]=U[2]+f[2],w[3]=U[3]+f[3],w}function p(U,f,b,w){let I=w??new e(4);return I[0]=U[0]+f[0]*b,I[1]=U[1]+f[1]*b,I[2]=U[2]+f[2]*b,I[3]=U[3]+f[3]*b,I}function g(U,f,b){let w=b??new e(4);return w[0]=U[0]-f[0],w[1]=U[1]-f[1],w[2]=U[2]-f[2],w[3]=U[3]-f[3],w}let F=g;function N(U,f){return Math.abs(U[0]-f[0])<Tt&&Math.abs(U[1]-f[1])<Tt&&Math.abs(U[2]-f[2])<Tt&&Math.abs(U[3]-f[3])<Tt}function q(U,f){return U[0]===f[0]&&U[1]===f[1]&&U[2]===f[2]&&U[3]===f[3]}function m(U,f,b,w){let I=w??new e(4);return I[0]=U[0]+b*(f[0]-U[0]),I[1]=U[1]+b*(f[1]-U[1]),I[2]=U[2]+b*(f[2]-U[2]),I[3]=U[3]+b*(f[3]-U[3]),I}function C(U,f,b,w){let I=w??new e(4);return I[0]=U[0]+b[0]*(f[0]-U[0]),I[1]=U[1]+b[1]*(f[1]-U[1]),I[2]=U[2]+b[2]*(f[2]-U[2]),I[3]=U[3]+b[3]*(f[3]-U[3]),I}function Y(U,f,b){let w=b??new e(4);return w[0]=Math.max(U[0],f[0]),w[1]=Math.max(U[1],f[1]),w[2]=Math.max(U[2],f[2]),w[3]=Math.max(U[3],f[3]),w}function H(U,f,b){let w=b??new e(4);return w[0]=Math.min(U[0],f[0]),w[1]=Math.min(U[1],f[1]),w[2]=Math.min(U[2],f[2]),w[3]=Math.min(U[3],f[3]),w}function W(U,f,b){let w=b??new e(4);return w[0]=U[0]*f,w[1]=U[1]*f,w[2]=U[2]*f,w[3]=U[3]*f,w}let Q=W;function et(U,f,b){let w=b??new e(4);return w[0]=U[0]/f,w[1]=U[1]/f,w[2]=U[2]/f,w[3]=U[3]/f,w}function $(U,f){let b=f??new e(4);return b[0]=1/U[0],b[1]=1/U[1],b[2]=1/U[2],b[3]=1/U[3],b}let J=$;function ut(U,f){return U[0]*f[0]+U[1]*f[1]+U[2]*f[2]+U[3]*f[3]}function tt(U){let f=U[0],b=U[1],w=U[2],I=U[3];return Math.sqrt(f*f+b*b+w*w+I*I)}let rt=tt;function D(U){let f=U[0],b=U[1],w=U[2],I=U[3];return f*f+b*b+w*w+I*I}let a=D;function v(U,f){let b=U[0]-f[0],w=U[1]-f[1],I=U[2]-f[2],z=U[3]-f[3];return Math.sqrt(b*b+w*w+I*I+z*z)}let T=v;function M(U,f){let b=U[0]-f[0],w=U[1]-f[1],I=U[2]-f[2],z=U[3]-f[3];return b*b+w*w+I*I+z*z}let S=M;function E(U,f){let b=f??new e(4),w=U[0],I=U[1],z=U[2],O=U[3],V=Math.sqrt(w*w+I*I+z*z+O*O);return V>1e-5?(b[0]=w/V,b[1]=I/V,b[2]=z/V,b[3]=O/V):(b[0]=0,b[1]=0,b[2]=0,b[3]=0),b}function R(U,f){let b=f??new e(4);return b[0]=-U[0],b[1]=-U[1],b[2]=-U[2],b[3]=-U[3],b}function P(U,f){let b=f??new e(4);return b[0]=U[0],b[1]=U[1],b[2]=U[2],b[3]=U[3],b}let l=P;function G(U,f,b){let w=b??new e(4);return w[0]=U[0]*f[0],w[1]=U[1]*f[1],w[2]=U[2]*f[2],w[3]=U[3]*f[3],w}let ot=G;function at(U,f,b){let w=b??new e(4);return w[0]=U[0]/f[0],w[1]=U[1]/f[1],w[2]=U[2]/f[2],w[3]=U[3]/f[3],w}let st=at;function ct(U){let f=U??new e(4);return f[0]=0,f[1]=0,f[2]=0,f[3]=0,f}function yt(U,f,b){let w=b??new e(4),I=U[0],z=U[1],O=U[2],V=U[3];return w[0]=f[0]*I+f[4]*z+f[8]*O+f[12]*V,w[1]=f[1]*I+f[5]*z+f[9]*O+f[13]*V,w[2]=f[2]*I+f[6]*z+f[10]*O+f[14]*V,w[3]=f[3]*I+f[7]*z+f[11]*O+f[15]*V,w}function pt(U,f,b){let w=b??new e(4);return E(U,w),W(w,f,w)}function k(U,f,b){let w=b??new e(4);return tt(U)>f?pt(U,f,w):P(U,w)}function Z(U,f,b){let w=b??new e(4);return m(U,f,.5,w)}return{create:t,fromValues:n,set:r,ceil:i,floor:o,round:s,clamp:c,add:h,addScaled:p,subtract:g,sub:F,equalsApproximately:N,equals:q,lerp:m,lerpV:C,max:Y,min:H,mulScalar:W,scale:Q,divScalar:et,inverse:$,invert:J,dot:ut,length:tt,len:rt,lengthSq:D,lenSq:a,distance:v,dist:T,distanceSq:M,distSq:S,normalize:E,negate:R,copy:P,clone:l,multiply:G,mul:ot,divide:at,div:st,zero:ct,transformMat4:yt,setLength:pt,truncate:k,midpoint:Z}}var _i=new Map;function hu(e){let t=_i.get(e);return t||(t=lu(e),_i.set(e,t)),t}function cn(e,t,n,r,i,o){return{mat3:au(e),mat4:uu(t),quat:fu(n),vec2:Si(r),vec3:fr(i),vec4:hu(o)}}var{mat3:xe,mat4:Et,quat:bl,vec2:jt,vec3:pe,vec4:Bi}=cn(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array),{mat3:Tl,mat4:_l,quat:Sl,vec2:Bl,vec3:Pl,vec4:Dl}=cn(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array),{mat3:Ul,mat4:Gl,quat:Fl,vec2:Al,vec3:Il,vec4:El}=cn(ru,Array,Array,Array,Array,Array);var lr=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:wi});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=Et.identity();Et.multiply(Et.scaling(n),o,o),Et.multiply(Et.rotationZ(r),o,o),Et.multiply(Et.translation(i),o,o);let s=Et.translation([-t.position[0],-t.position[1],0]),c=t.width/t.zoom,h=t.height/t.zoom,p=Et.ortho(0,c,h,0,-10,10),g=Et.identity();Et.multiply(s,o,g),Et.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]}};var Di={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 pu(e,t)},onRun:function(e,t,n){vu(e,t,n)},onDestroy:function(e,t){du(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 pu(e,t){let{device:n}=e,r=new ur({device:n,initialParameters:{offsetX:t.options.offseyX??0,offsetY:t.options.offseyY??0,scale:t.options.scale??20}}),i=256,o=new sr({device:n,maxSpriteCount:i}),s=new lr({device:n,width:e.viewport.width,height:e.viewport.height,blurFactor:8,trianglesBuffer:o}),c=new cr({device:n,targetFormat:"bgra8unorm",colorTextureView:t.refs.color.data.view,noiseMapTextureView:t.refs.map.view,displacementTextureView:s.getView(),displacementParametersBuffer:r});return{displacementParameters:r,displacementTexture:s,displacementComposition:c,trianglesBuffer:o}}function vu(e,t,n){if(t.data.trianglesBuffer.spriteCount===0)return;t.data.trianglesBuffer.update(),t.data.displacementTexture.update(n);let i=n.beginRenderPass({colorAttachments:[{view:t.refs.out,clearValue:e.clearValue,loadOp:"load",storeOp:"store"}]});i.executeBundles([t.data.displacementComposition.getRenderBundle()]),i.end()}function du(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}function fn(e,t){let n=t.vertices,r=GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,i={size:n.byteLength,usage:r,mappedAtCreation:!0},o=e.createBuffer(i);return new Float32Array(o.getMappedRange()).set(n),o.unmap(),{buffer:o,bufferLayout:{arrayStride:20,stepMode:"vertex",attributes:[{shaderLocation:0,format:"float32x3",offset:0},{shaderLocation:1,format:"float32x2",offset:12}]}}}var ln="struct TransformData{view:mat4x4<f32>,projection:mat4x4<f32>};struct Sprite{translate:vec2<f32>,scale:vec2<f32>,tint:vec4<f32>,opacity:f32,rotation:f32,};struct SpritesBuffer{models:array<Sprite>,};@binding(0)@group(0)var<uniform> transformUBO:TransformData;@binding(1)@group(0)var myTexture:texture_2d<f32>;@binding(2)@group(0)var mySampler:sampler;@binding(3)@group(0)var<storage,read>sprites:SpritesBuffer;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32,};@vertex fn vs_main(@builtin(instance_index)i_id:u32,@location(0)vertexPosition:vec3<f32>,@location(1)vertexTexCoord:vec2<f32>)->Fragment{var output:Fragment;var sx:f32=sprites.models[i_id].scale.x;var sy:f32=sprites.models[i_id].scale.y;var sz:f32=1.0;var rot:f32=sprites.models[i_id].rotation;var tx:f32=sprites.models[i_id].translate.x;var ty:f32=sprites.models[i_id].translate.y;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;output.Position=transformUBO.projection*transformUBO.view*modelM*vec4<f32>(vertexPosition,1.0);output.TexCoord=vertexTexCoord;output.Tint=sprites.models[i_id].tint;output.Opacity=sprites.models[i_id].opacity;return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32)->@location(0)vec4<f32>{var outColor:vec4<f32>=textureSample(myTexture,mySampler,TexCoord);var output=vec4<f32>(outColor.rgb*(1.0-Tint.a)+(Tint.rgb*Tint.a),outColor.a*Opacity);return output;}";var t1=Bi.create(),Ui=pe.create(),Fi={type:"cobalt:overlay",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"color",type:"textView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return gu(e,t)},onRun:function(e,t,n){wu(e,t,n)},onDestroy:function(e,t){yu(t)},onResize:function(e,t){Gi(e,t)},onViewportPosition:function(e,t){Gi(e,t)},customFunctions:{...$e}};async function gu(e,t){let{device:n}=e,r=16192,i=r,s=Float32Array.BYTES_PER_ELEMENT*2,h=Float32Array.BYTES_PER_ELEMENT*2,g=Float32Array.BYTES_PER_ELEMENT*4,N=Float32Array.BYTES_PER_ELEMENT*4,q=n.createBuffer({size:(s+h+g+N)*i,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),m=n.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),C=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}}]}),Y=n.createBindGroup({layout:C,entries:[{binding:0,resource:{buffer:m}},{binding:1,resource:t.refs.spritesheet.data.colorTexture.view},{binding:2,resource:t.refs.spritesheet.data.colorTexture.sampler},{binding:3,resource:{buffer:q}}]}),H=n.createPipelineLayout({bindGroupLayouts:[C]}),W=n.createRenderPipeline({label:"overlaysprite",vertex:{module:n.createShaderModule({code:ln}),entryPoint:"vs_main",buffers:[t.refs.spritesheet.data.quads.bufferLayout]},fragment:{module:n.createShaderModule({code:ln}),entryPoint:"fs_main",targets:[{format:"bgra8unorm",blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:H});return{instancedDrawCalls:new Uint32Array(r*2),instancedDrawCallCount:0,spriteBuffer:q,uniformBuffer:m,pipeline:W,bindGroupLayout:C,bindGroup:Y,spriteData:new Float32Array(r*12),spriteCount:0,spriteIndices:new Map,dirty:!1}}function wu(e,t,n){let{device:r}=e,i=t.options.loadOp||"load";if(t.data.dirty&&(xu(t.data),t.data.dirty=!1),t.data.spriteCount>0){let h=t.data.spriteCount*12*Float32Array.BYTES_PER_ELEMENT;r.queue.writeBuffer(t.data.spriteBuffer,0,t.data.spriteData.buffer,0,h)}let o=n.beginRenderPass({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.refs.spritesheet.data.quads.buffer);let s=6,c=0;for(let h=0;h<t.data.instancedDrawCallCount;h++){let p=t.data.instancedDrawCalls[h*2]*s,g=t.data.instancedDrawCalls[h*2+1];o.draw(s,g,p,c),c+=g}o.end()}function xu(e){let t=-1,n=0;e.instancedDrawCallCount=0;for(let r=0;r<e.spriteCount;r++){let i=e.spriteData[r*12+11]&65535;i!==t&&(n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++),t=i,n=0),n++}n>0&&(e.instancedDrawCalls[e.instancedDrawCallCount*2]=t,e.instancedDrawCalls[e.instancedDrawCallCount*2+1]=n,e.instancedDrawCallCount++)}function Gi(e,t){let r=Math.round(e.viewport.width/1),i=Math.round(e.viewport.height/1),o=Et.ortho(0,r,i,0,-10,10);pe.set(0,0,0,Ui);let s=Et.translation(Ui);e.device.queue.writeBuffer(t.data.uniformBuffer,0,s.buffer),e.device.queue.writeBuffer(t.data.uniformBuffer,64,o.buffer)}function yu(e){e.data.instancedDrawCalls=null,e.data.bindGroup=null,e.data.spriteBuffer.destroy(),e.data.spriteBuffer=null,e.data.uniformBuffer.destroy(),e.data.uniformBuffer=null,e.data.spriteData=null,e.data.spriteIndices.clear(),e.data.spriteIndices=null}var pn="@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:"bgra8unorm",access:"read"},{name:"out",type:"cobaltTexture",format:"bgra8unorm",access:"write"}],onInit:async function(e,t={}){return Mu(e,t)},onRun:function(e,t,n){bu(e,t,n)},onDestroy:function(e,t){},onResize:function(e,t){Tu(e,t)},onViewportPosition:function(e,t){}};async function Mu(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:pn}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:pn}),entryPoint:"fs_main",targets:[{format:"bgra8unorm",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 bu(e,t,n){let{device:r}=e,i=n.beginRenderPass({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 Tu(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 Ii="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 fs=ni(so(),1);var cs=ni(us(),1);function Jn(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],c=r.length,h=0;h<s.length;++h)r.push(s[h]),i.push([c+h,c+(h+1)%s.length]);var p="clean"in t?!0:!!t.clean;return p&&(0,cs.default)(r,i),{points:r,edges:i}}var ls={line:Ie,save:function(e,t){t.data.transforms.push(xe.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);xe.translate(r,n,r)},rotate:function(e,t,n){let r=t.data.transforms.at(-1);xe.rotate(r,n,r)},scale:function(e,t,n){let r=t.data.transforms.at(-1);xe.scale(r,n,r)},strokePath:function(e,t,n,r,i=1){for(let o of n)Ie(e,t,o[0],o[1],r,i)},filledPath:function(e,t,n,r){let i=Jn(n),o=(0,fs.default)(i.points,i.edges,{exterior:!1}),s=t.data.transforms.at(-1),c=t.data.vertexCount*6,h=t.data.vertexCount*6,p=o.length*3*6;t.data.vertices=mr(Float32Array,t.data.vertices,h,p);let g=jt.create();for(let F of o)jt.transformMat3(n[F[0]],s,g),t.data.vertices[c+0]=g[0],t.data.vertices[c+1]=g[1],t.data.vertices[c+2]=r[0],t.data.vertices[c+3]=r[1],t.data.vertices[c+4]=r[2],t.data.vertices[c+5]=r[3],jt.transformMat3(n[F[1]],s,g),t.data.vertices[c+6]=g[0],t.data.vertices[c+7]=g[1],t.data.vertices[c+8]=r[0],t.data.vertices[c+9]=r[1],t.data.vertices[c+10]=r[2],t.data.vertices[c+11]=r[3],jt.transformMat3(n[F[2]],s,g),t.data.vertices[c+12]=g[0],t.data.vertices[c+13]=g[1],t.data.vertices[c+14]=r[0],t.data.vertices[c+15]=r[1],t.data.vertices[c+16]=r[2],t.data.vertices[c+17]=r[3],c+=18;t.data.vertexCount+=3*o.length,t.data.dirty=!0},ellipse:function(e,t,n,r,i,o,s,c=1){let[h,p]=n,g=2*Math.PI/o;for(let F=0;F<o;F++){let N=F*g,q=(F+1)*g,m=h+r*Math.cos(N),C=p+i*Math.sin(N),Y=h+r*Math.cos(q),H=p+i*Math.sin(q);Ie(e,t,[m,C],[Y,H],s,c)}},filledEllipse:function(e,t,n,r,i,o,s){let[c,h]=n,p=2*Math.PI/o,g=t.data.vertexCount*6,F=o*3*6;t.data.vertices=mr(Float32Array,t.data.vertices,g,F);let N=t.data.transforms.at(-1);for(let q=0;q<o;q++){let m=q*p,C=(q+1)*p,Y=c+r*Math.cos(m),H=h+i*Math.sin(m),W=c+r*Math.cos(C),Q=h+i*Math.sin(C),$=t.data.vertexCount*6+q*18,J=jt.transformMat3([c,h],N);t.data.vertices[$+0]=J[0],t.data.vertices[$+1]=J[1],t.data.vertices[$+2]=s[0],t.data.vertices[$+3]=s[1],t.data.vertices[$+4]=s[2],t.data.vertices[$+5]=s[3],jt.transformMat3([Y,H],N,J),t.data.vertices[$+6]=J[0],t.data.vertices[$+7]=J[1],t.data.vertices[$+8]=s[0],t.data.vertices[$+9]=s[1],t.data.vertices[$+10]=s[2],t.data.vertices[$+11]=s[3],jt.transformMat3([W,Q],N,J),t.data.vertices[$+12]=J[0],t.data.vertices[$+13]=J[1],t.data.vertices[$+14]=s[0],t.data.vertices[$+15]=s[1],t.data.vertices[$+16]=s[2],t.data.vertices[$+17]=s[3]}t.data.vertexCount+=3*o,t.data.dirty=!0},box:function(e,t,n,r,i,o,s=1){let[c,h]=n,p=r/2,g=i/2,F=[c-p,h-g],N=[c+p,h-g],q=[c-p,h+g],m=[c+p,h+g];Ie(e,t,F,N,o,s),Ie(e,t,q,m,o,s),Ie(e,t,F,q,o,s),Ie(e,t,N,m,o,s)},filledBox:function(e,t,n,r,i,o){let[s,c]=n,h=r/2,p=i/2,g=t.data.transforms.at(-1),F=jt.transformMat3([s-h,c-p],g),N=jt.transformMat3([s+h,c-p],g),q=jt.transformMat3([s-h,c+p],g),m=jt.transformMat3([s+h,c+p],g),C=t.data.vertexCount*6,Y=36;t.data.vertices=mr(Float32Array,t.data.vertices,C,Y);let H=t.data.vertexCount*6;t.data.vertices[H+0]=F[0],t.data.vertices[H+1]=F[1],t.data.vertices[H+2]=o[0],t.data.vertices[H+3]=o[1],t.data.vertices[H+4]=o[2],t.data.vertices[H+5]=o[3],t.data.vertices[H+6]=q[0],t.data.vertices[H+7]=q[1],t.data.vertices[H+8]=o[0],t.data.vertices[H+9]=o[1],t.data.vertices[H+10]=o[2],t.data.vertices[H+11]=o[3],t.data.vertices[H+12]=N[0],t.data.vertices[H+13]=N[1],t.data.vertices[H+14]=o[0],t.data.vertices[H+15]=o[1],t.data.vertices[H+16]=o[2],t.data.vertices[H+17]=o[3],t.data.vertices[H+18]=q[0],t.data.vertices[H+19]=q[1],t.data.vertices[H+20]=o[0],t.data.vertices[H+21]=o[1],t.data.vertices[H+22]=o[2],t.data.vertices[H+23]=o[3],t.data.vertices[H+24]=m[0],t.data.vertices[H+25]=m[1],t.data.vertices[H+26]=o[0],t.data.vertices[H+27]=o[1],t.data.vertices[H+28]=o[2],t.data.vertices[H+29]=o[3],t.data.vertices[H+30]=N[0],t.data.vertices[H+31]=N[1],t.data.vertices[H+32]=o[0],t.data.vertices[H+33]=o[1],t.data.vertices[H+34]=o[2],t.data.vertices[H+35]=o[3],t.data.vertexCount+=6,t.data.dirty=!0},clear:function(e,t){t.data.vertexCount=0,t.data.transforms.length=1,xe.identity(t.data.transforms[0]),t.data.dirty=!0}};function Ie(e,t,n,r,i,o=1){let s=t.data.transforms.at(-1);n=jt.transformMat3(n,s),r=jt.transformMat3(r,s);let c=jt.sub(r,n),h=jt.normalize(c),p=Pf(h),g=o/2,F=t.data.vertexCount*6,N=t.data.vertexCount*6,q=36;t.data.vertices=mr(Float32Array,t.data.vertices,N,q),t.data.vertices[F+0]=n[0]+p[0]*g,t.data.vertices[F+1]=n[1]+p[1]*g,t.data.vertices[F+2]=i[0],t.data.vertices[F+3]=i[1],t.data.vertices[F+4]=i[2],t.data.vertices[F+5]=i[3],t.data.vertices[F+6]=n[0]-p[0]*g,t.data.vertices[F+7]=n[1]-p[1]*g,t.data.vertices[F+8]=i[0],t.data.vertices[F+9]=i[1],t.data.vertices[F+10]=i[2],t.data.vertices[F+11]=i[3],t.data.vertices[F+12]=r[0]+p[0]*g,t.data.vertices[F+13]=r[1]+p[1]*g,t.data.vertices[F+14]=i[0],t.data.vertices[F+15]=i[1],t.data.vertices[F+16]=i[2],t.data.vertices[F+17]=i[3],t.data.vertices[F+18]=n[0]-p[0]*g,t.data.vertices[F+19]=n[1]-p[1]*g,t.data.vertices[F+20]=i[0],t.data.vertices[F+21]=i[1],t.data.vertices[F+22]=i[2],t.data.vertices[F+23]=i[3],t.data.vertices[F+24]=r[0]+p[0]*g,t.data.vertices[F+25]=r[1]+p[1]*g,t.data.vertices[F+26]=i[0],t.data.vertices[F+27]=i[1],t.data.vertices[F+28]=i[2],t.data.vertices[F+29]=i[3],t.data.vertices[F+30]=r[0]-p[0]*g,t.data.vertices[F+31]=r[1]-p[1]*g,t.data.vertices[F+32]=i[0],t.data.vertices[F+33]=i[1],t.data.vertices[F+34]=i[2],t.data.vertices[F+35]=i[3],t.data.vertexCount+=6,t.data.dirty=!0}function mr(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 Pf(e){return[-e[1],e[0]]}var hs=pe.create(0,0,0),vs={type:"cobalt:primitives",refs:[{name:"color",type:"textView",format:"rgba8unorm",access:"write"}],onInit:async function(e,t={}){return Df(e,t)},onRun:function(e,t,n){Uf(e,t,n)},onDestroy:function(e,t){Gf(t)},onResize:function(e,t){ps(e,t)},onViewportPosition:function(e,t){ps(e,t)},customFunctions:ls};async function Df(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:Ii}),c=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}}]}),h=n.createPipelineLayout({bindGroupLayouts:[c]}),p=n.createBindGroup({layout:c,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:"bgra8unorm",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:[xe.identity()]}}function Uf(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 c=t.data.vertexCount*s;if(c>t.data.vertexBuffer.size){console.error("too many primitives, bailing");return}e.device.queue.writeBuffer(t.data.vertexBuffer,0,t.data.vertices.buffer,0,c)}let i=t.options.loadOp||"load",o=n.beginRenderPass({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 Gf(e){e.data.vertexBuffer.destroy(),e.data.vertexBuffer=null,e.data.uniformBuffer.destroy(),e.data.uniformBuffer=null,e.data.transforms.length=0}function ps(e,t){let{device:n}=e,r=e.viewport.width/e.viewport.zoom,i=e.viewport.height/e.viewport.zoom,o=Et.ortho(0,r,i,0,-10,10);pe.set(-e.viewport.position[0]-1,-e.viewport.position[1]-1,0,hs);let s=Et.translation(hs);n.queue.writeBuffer(t.data.uniformBuffer,0,s.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,o.buffer)}var jn={};ri(jn,{setAmbientLight:()=>Af,setLights:()=>Ff,setOccluders:()=>If});function Ff(e,t,n){t.data.lights=n,t.data.lightsBufferNeedsUpdate=!0}function Af(e,t,n){t.data.lightsRenderer.setAmbientLight(n)}function If(e,t,n){t.data.lightsRenderer.setObstacles(n),t.data.lightsTextureNeedsUpdate=!0}var Or=class{invViewProjectionMatrix=Et.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(){Et.identity(this.invViewProjectionMatrix),Et.multiply(Et.scaling([1,-1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Et.multiply(Et.translation([1,1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Et.multiply(Et.scaling([.5*this.viewportSize.width/this.zoom,.5*this.viewportSize.height/this.zoom,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Et.multiply(Et.translation([this.topLeft[0],this.topLeft[1],0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix)}};var se=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 ds={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 Ef(e,t)},onRun:function(e,t,n){Lf(e,t,n)},onDestroy:function(e,t){zf(t)},onResize:function(e,t){Rf(e,t)},onViewportPosition:function(e,t){t.data.viewport.setTopLeft(...e.viewport.position)},customFunctions:{...jn}};async function Ef(e,t){let{device:n}=e,r=256,i=256,o=new se(n,r),s=new Or({viewportSize:{width:e.viewport.width,height:e.viewport.height},center:e.viewport.position,zoom:e.viewport.zoom}),c=new Cr({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"}});return{lightsBuffer:o,lightsBufferNeedsUpdate:!0,lightsTextureNeedsUpdate:!0,lightsRenderer:c,viewport:s,lights:[]}}function Lf(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({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 zf(e){e.data.lightsBuffer.destroy(),e.data.lightsRenderer.destroy()}function Rf(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)}var ti="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 we=new Float32Array(8),ws={type:"cobalt:tileAtlas",refs:[],onInit:async function(e,t={}){return mf(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){Of(data)},onResize:function(e,t){gs(e,t)},onViewportPosition:function(e,t){gs(e,t)}};async function mf(e,t){let{device:n}=e,r=await he(e,"tile atlas",t.options.textureUrl),i=n.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),o=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),s=n.createBindGroup({layout:o,entries:[{binding:0,resource:{buffer:i}},{binding:1,resource:r.view},{binding:2,resource:r.sampler}]}),c=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),h=n.createPipelineLayout({bindGroupLayouts:[c,o]});return{pipeline:n.createRenderPipeline({label:"tile",vertex:{module:n.createShaderModule({code:ti}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:ti}),entryPoint:"fs_main",targets:[{format:"rgba16float",blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:h}),uniformBuffer:i,atlasBindGroup:s,atlasMaterial:r,tileBindGroupLayout:c,tileSize:t.options.tileSize,tileScale:t.options.tileScale}}function Of(e){e.atlasMaterial.texture.destroy(),e.atlasMaterial.texture=void 0}function gs(e,t){we[0]=e.viewport.position[0],we[1]=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;we[2]=o/r,we[3]=s/r,we[4]=1/n.atlasMaterial.texture.width,we[5]=1/n.atlasMaterial.texture.height,we[6]=i,we[7]=1/i,e.device.queue.writeBuffer(n.uniformBuffer,0,we,0,8)}function kr(e){let n=Object.keys(e.frames).length,r=new Float32Array(n*30),i=[],o={},s=0;for(let c in e.frames){let h=e.frames[c];i.push(c),o[c]=h.sourceSize;let p=-.5+h.spriteSourceSize.x/h.sourceSize.w,g=-.5+h.spriteSourceSize.y/h.sourceSize.h,F=-.5+(h.spriteSourceSize.x+h.spriteSourceSize.w)/h.sourceSize.w,N=-.5+(h.spriteSourceSize.y+h.spriteSourceSize.h)/h.sourceSize.h,q=[p,g,0],m=[p,N,0],C=[F,N,0],Y=[F,g,0],H=0+h.frame.x/e.meta.size.w,W=0+h.frame.y/e.meta.size.h,Q=0+(h.frame.x+h.frame.w)/e.meta.size.w,et=0+(h.frame.y+h.frame.h)/e.meta.size.h,$=[H,W],J=[H,et],ut=[Q,et],tt=[Q,W];r.set(q,s),r.set($,s+3),r.set(m,s+5),r.set(J,s+8),r.set(C,s+10),r.set(ut,s+13),r.set(q,s+15),r.set($,s+18),r.set(C,s+20),r.set(ut,s+23),r.set(Y,s+25),r.set(tt,s+28),s+=30}return{spriteMeta:o,locations:i,vertices:r}}var ei="struct TransformData{view:mat4x4<f32>,projection:mat4x4<f32>};struct Sprite{translate:vec2<f32>,scale:vec2<f32>,tint:vec4<f32>,opacity:f32,rotation:f32,emissiveIntensity:f32,sortValue:f32,};struct SpritesBuffer{models:array<Sprite>,};@binding(0)@group(0)var<uniform> transformUBO:TransformData;@binding(1)@group(0)var myTexture:texture_2d<f32>;@binding(2)@group(0)var mySampler:sampler;@binding(3)@group(0)var<storage,read>sprites:SpritesBuffer;@binding(4)@group(0)var emissiveTexture:texture_2d<f32>;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32,};struct GBufferOutput{@location(0)color:vec4<f32>,@location(1)emissive:vec4<f32>,}@vertex fn vs_main(@builtin(instance_index)i_id:u32,@location(0)vertexPosition:vec3<f32>,@location(1)vertexTexCoord:vec2<f32>)->Fragment{var output:Fragment;var sx:f32=sprites.models[i_id].scale.x;var sy:f32=sprites.models[i_id].scale.y;var sz:f32=1.0;var rot:f32=sprites.models[i_id].rotation;var tx:f32=sprites.models[i_id].translate.x;var ty:f32=sprites.models[i_id].translate.y;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;output.Position=transformUBO.projection*transformUBO.view*modelM*vec4<f32>(vertexPosition,1.0);output.TexCoord=vertexTexCoord;output.Tint=sprites.models[i_id].tint;output.Opacity=sprites.models[i_id].opacity;return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32)->GBufferOutput{var output:GBufferOutput;var outColor:vec4<f32>=textureSample(myTexture,mySampler,TexCoord);output.color=vec4<f32>(outColor.rgb*(1.0-Tint.a)+(Tint.rgb*Tint.a),outColor.a*Opacity);let emissive=textureSample(emissiveTexture,mySampler,TexCoord);output.emissive=vec4(emissive.rgb,1.0)*emissive.a;return output;}";var xs=pe.create(0,0,0),Ms={type:"cobalt:spritesheet",refs:[],onInit:async function(e,t={}){return Vf(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){qf(t)},onResize:function(e,t){ys(e,t)},onViewportPosition:function(e,t){ys(e,t)}};async function Vf(e,t){let{canvas:n,device:r}=e,i,o,s;n?(i=await Nf(t.options.spriteSheetJsonUrl),i=kr(i),o=await he(e,"sprite",t.options.colorTextureUrl,"rgba8unorm"),s=await he(e,"emissive sprite",t.options.emissiveTextureUrl,"rgba8unorm"),n.style.imageRendering="pixelated"):(i=kr(t.options.spriteSheetJson),o=await He(e,"sprite",t.options.colorTexture,"rgba8unorm"),s=await He(e,"emissive sprite",t.options.emissiveTexture,"rgba8unorm"));let c=fn(r,i),h=r.createBuffer({size:64*2,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),p=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}},{binding:4,visibility:GPUShaderStage.FRAGMENT,texture:{}}]}),g=r.createPipelineLayout({bindGroupLayouts:[p]});return{pipeline:r.createRenderPipeline({label:"sprite",vertex:{module:r.createShaderModule({code:ei}),entryPoint:"vs_main",buffers:[c.bufferLayout]},fragment:{module:r.createShaderModule({code:ei}),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-list"},layout:g}),uniformBuffer:h,quads:c,colorTexture:o,emissiveTexture:s,bindGroupLayout:p,spritesheet:i}}function qf(e){e.data.quads.buffer.destroy(),e.data.colorTexture.buffer.destroy(),e.data.uniformBuffer.destroy(),e.data.emissiveTexture.texture.destroy()}async function Nf(e){return(await fetch(e)).json()}function ys(e,t){let{device:n,viewport:r}=e,i=r.width/r.zoom,o=r.height/r.zoom,s=Et.ortho(0,i,o,0,-10,10);pe.set(-r.position[0],-r.position[1],0,xs);let c=Et.translation(xs);n.queue.writeBuffer(t.data.uniformBuffer,0,c.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,s.buffer)}var bs={type:"fbTexture",refs:[],onInit:async function(e,t={}){return Cf(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){Ts(data)},onResize:function(e,t){kf(e,t)},onViewportPosition:function(e,t){}};async function Cf(e,t){let{device:n}=e,{label:r,mip_count:i,format:o,usage:s,viewportScale:c}=t.options;return ne(n,r,e.viewport.width*c,e.viewport.height*c,i,o,s)}function Ts(e){e.data.texture.destroy()}function kf(e,t){let{device:n}=e;Ts(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)}async function pp(e,t,n){let r,i,o,s;return e.sdlWindow&&e.gpu?(i=e.gpu,r=await(await i.create(["verbose=1"]).requestAdapter()).requestDevice(),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":ws,"cobalt:spritesheet":Ms,"cobalt:fbTexture":bs,"cobalt:bloom":si,"cobalt:composite":fi,"cobalt:sprite":pi,"cobalt:tile":di,"cobalt:displacement":Di,"cobalt:overlay":Fi,"cobalt:fbBlit":Ai,"cobalt:primitives":vs,"cobalt:light":ds},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 vp(e,t){if(!t?.type)throw new Error("Can't define a new node missing a type.");e.nodeDefs[t.type]=t}async function dp(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]=_s(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 gp(e){let{device:t,context:n}=e,r=t.createCommandEncoder(),i=_s(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 wp(e){for(let t of e.nodes)e.nodeDefs[t.type].onDestroy(e,t);e.nodes.length=0,e.defaultTextureViewRefs.length=0}function xp(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 yp(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 li(e){return e.canvas?navigator.gpu.getPreferredCanvasFormat():e.context.getPreferredFormat()}function _s(e){return e.canvas?e.context.getCurrentTexture().createView():e.context.getCurrentTextureView()}export{ne as createTexture,He as createTextureFromBuffer,he as createTextureFromUrl,vp as defineNode,gp as draw,_s as getCurrentTextureView,li as getPreferredFormat,pp as init,dp as initNode,wp as reset,xp as setViewportDimensions,yp 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 ds={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 Ef(e,t)},onRun:function(e,t,n){Lf(e,t,n)},onDestroy:function(e,t){zf(t)},onResize:function(e,t){Rf(e,t)},onViewportPosition:function(e,t){t.data.viewport.setTopLeft(...e.viewport.position)},customFunctions:{...jn}};async function Ef(e,t){let{device:n}=e,r=256,i=256,o=new se(n,r),s=new Or({viewportSize:{width:e.viewport.width,height:e.viewport.height},center:e.viewport.position,zoom:e.viewport.zoom}),c=new Cr({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"}});return{lightsBuffer:o,lightsBufferNeedsUpdate:!0,lightsTextureNeedsUpdate:!0,lightsRenderer:c,viewport:s,lights:[]}}function Lf(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({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 zf(e){e.data.lightsBuffer.destroy(),e.data.lightsRenderer.destroy()}function Rf(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)}var ti="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 we=new Float32Array(8),ws={type:"cobalt:tileAtlas",refs:[],onInit:async function(e,t={}){return mf(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){Of(data)},onResize:function(e,t){gs(e,t)},onViewportPosition:function(e,t){gs(e,t)}};async function mf(e,t){let{device:n}=e,r=await he(e,"tile atlas",t.options.textureUrl),i=n.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),o=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),s=n.createBindGroup({layout:o,entries:[{binding:0,resource:{buffer:i}},{binding:1,resource:r.view},{binding:2,resource:r.sampler}]}),c=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),h=n.createPipelineLayout({bindGroupLayouts:[c,o]});return{pipeline:n.createRenderPipeline({label:"tileatlas",vertex:{module:n.createShaderModule({code:ti}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:ti}),entryPoint:"fs_main",targets:[{format:"rgba16float",blend:{color:{srcFactor:"src-alpha",dstFactor:"one-minus-src-alpha"},alpha:{srcFactor:"zero",dstFactor:"one"}}}]},primitive:{topology:"triangle-list"},layout:h}),uniformBuffer:i,atlasBindGroup:s,atlasMaterial:r,tileBindGroupLayout:c,tileSize:t.options.tileSize,tileScale:t.options.tileScale}}function Of(e){e.atlasMaterial.texture.destroy(),e.atlasMaterial.texture=void 0}function gs(e,t){we[0]=e.viewport.position[0],we[1]=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;we[2]=o/r,we[3]=s/r,we[4]=1/n.atlasMaterial.texture.width,we[5]=1/n.atlasMaterial.texture.height,we[6]=i,we[7]=1/i,e.device.queue.writeBuffer(n.uniformBuffer,0,we,0,8)}function kr(e){let n=Object.keys(e.frames).length,r=new Float32Array(n*30),i=[],o={},s=0;for(let c in e.frames){let h=e.frames[c];i.push(c),o[c]=h.sourceSize;let p=-.5+h.spriteSourceSize.x/h.sourceSize.w,g=-.5+h.spriteSourceSize.y/h.sourceSize.h,F=-.5+(h.spriteSourceSize.x+h.spriteSourceSize.w)/h.sourceSize.w,N=-.5+(h.spriteSourceSize.y+h.spriteSourceSize.h)/h.sourceSize.h,q=[p,g,0],m=[p,N,0],C=[F,N,0],Y=[F,g,0],H=0+h.frame.x/e.meta.size.w,W=0+h.frame.y/e.meta.size.h,Q=0+(h.frame.x+h.frame.w)/e.meta.size.w,et=0+(h.frame.y+h.frame.h)/e.meta.size.h,$=[H,W],J=[H,et],ut=[Q,et],tt=[Q,W];r.set(q,s),r.set($,s+3),r.set(m,s+5),r.set(J,s+8),r.set(C,s+10),r.set(ut,s+13),r.set(q,s+15),r.set($,s+18),r.set(C,s+20),r.set(ut,s+23),r.set(Y,s+25),r.set(tt,s+28),s+=30}return{spriteMeta:o,locations:i,vertices:r}}var ei="struct TransformData{view:mat4x4<f32>,projection:mat4x4<f32>};struct Sprite{translate:vec2<f32>,scale:vec2<f32>,tint:vec4<f32>,opacity:f32,rotation:f32,emissiveIntensity:f32,sortValue:f32,};struct SpritesBuffer{models:array<Sprite>,};@binding(0)@group(0)var<uniform> transformUBO:TransformData;@binding(1)@group(0)var myTexture:texture_2d<f32>;@binding(2)@group(0)var mySampler:sampler;@binding(3)@group(0)var<storage,read>sprites:SpritesBuffer;@binding(4)@group(0)var emissiveTexture:texture_2d<f32>;struct Fragment{@builtin(position)Position:vec4<f32>,@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32,};struct GBufferOutput{@location(0)color:vec4<f32>,@location(1)emissive:vec4<f32>,}@vertex fn vs_main(@builtin(instance_index)i_id:u32,@location(0)vertexPosition:vec3<f32>,@location(1)vertexTexCoord:vec2<f32>)->Fragment{var output:Fragment;var sx:f32=sprites.models[i_id].scale.x;var sy:f32=sprites.models[i_id].scale.y;var sz:f32=1.0;var rot:f32=sprites.models[i_id].rotation;var tx:f32=sprites.models[i_id].translate.x;var ty:f32=sprites.models[i_id].translate.y;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;output.Position=transformUBO.projection*transformUBO.view*modelM*vec4<f32>(vertexPosition,1.0);output.TexCoord=vertexTexCoord;output.Tint=sprites.models[i_id].tint;output.Opacity=sprites.models[i_id].opacity;return output;}@fragment fn fs_main(@location(0)TexCoord:vec2<f32>,@location(1)Tint:vec4<f32>,@location(2)Opacity:f32)->GBufferOutput{var output:GBufferOutput;var outColor:vec4<f32>=textureSample(myTexture,mySampler,TexCoord);output.color=vec4<f32>(outColor.rgb*(1.0-Tint.a)+(Tint.rgb*Tint.a),outColor.a*Opacity);let emissive=textureSample(emissiveTexture,mySampler,TexCoord);output.emissive=vec4(emissive.rgb,1.0)*emissive.a;return output;}";var xs=pe.create(0,0,0),Ms={type:"cobalt:spritesheet",refs:[],onInit:async function(e,t={}){return Vf(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){qf(t)},onResize:function(e,t){ys(e,t)},onViewportPosition:function(e,t){ys(e,t)}};async function Vf(e,t){let{canvas:n,device:r}=e,i,o,s;n?(i=await Nf(t.options.spriteSheetJsonUrl),i=kr(i),o=await he(e,"sprite",t.options.colorTextureUrl,"rgba8unorm"),s=await he(e,"emissive sprite",t.options.emissiveTextureUrl,"rgba8unorm"),n.style.imageRendering="pixelated"):(i=kr(t.options.spriteSheetJson),o=await He(e,"sprite",t.options.colorTexture,"rgba8unorm"),s=await He(e,"emissive sprite",t.options.emissiveTexture,"rgba8unorm"));let c=fn(r,i),h=r.createBuffer({size:128,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),p=r.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}},{binding:3,visibility:GPUShaderStage.VERTEX,buffer:{type:"read-only-storage"}},{binding:4,visibility:GPUShaderStage.FRAGMENT,texture:{}}]}),g=r.createPipelineLayout({bindGroupLayouts:[p]});return{pipeline:r.createRenderPipeline({label:"spritesheet",vertex:{module:r.createShaderModule({code:ei}),entryPoint:"vs_main",buffers:[c.bufferLayout]},fragment:{module:r.createShaderModule({code:ei}),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-list"},layout:g}),uniformBuffer:h,quads:c,colorTexture:o,emissiveTexture:s,bindGroupLayout:p,spritesheet:i}}function qf(e){e.data.quads.buffer.destroy(),e.data.colorTexture.buffer.destroy(),e.data.uniformBuffer.destroy(),e.data.emissiveTexture.texture.destroy()}async function Nf(e){return(await fetch(e)).json()}function ys(e,t){let{device:n,viewport:r}=e,i=r.width/r.zoom,o=r.height/r.zoom,s=Et.ortho(0,i,o,0,-10,10);pe.set(-r.position[0],-r.position[1],0,xs);let c=Et.translation(xs);n.queue.writeBuffer(t.data.uniformBuffer,0,c.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,s.buffer)}var bs={type:"fbTexture",refs:[],onInit:async function(e,t={}){return Cf(e,t)},onRun:function(e,t,n){},onDestroy:function(e,t){Ts(data)},onResize:function(e,t){kf(e,t)},onViewportPosition:function(e,t){}};async function Cf(e,t){let{device:n}=e,{label:r,mip_count:i,format:o,usage:s,viewportScale:c}=t.options;return ne(n,r,e.viewport.width*c,e.viewport.height*c,i,o,s)}function Ts(e){e.data.texture.destroy()}function kf(e,t){let{device:n}=e;Ts(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)}async function pp(e,t,n){let r,i,o,s;return e.sdlWindow&&e.gpu?(i=e.gpu,r=await(await i.create(["verbose=1"]).requestAdapter()).requestDevice(),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":ws,"cobalt:spritesheet":Ms,"cobalt:fbTexture":bs,"cobalt:bloom":si,"cobalt:composite":fi,"cobalt:sprite":pi,"cobalt:tile":di,"cobalt:displacement":Di,"cobalt:overlay":Fi,"cobalt:fbBlit":Ai,"cobalt:primitives":vs,"cobalt:light":ds},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 vp(e,t){if(!t?.type)throw new Error("Can't define a new node missing a type.");e.nodeDefs[t.type]=t}async function dp(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]=_s(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 gp(e){let{device:t,context:n}=e,r=t.createCommandEncoder(),i=_s(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 wp(e){for(let t of e.nodes)e.nodeDefs[t.type].onDestroy(e,t);e.nodes.length=0,e.defaultTextureViewRefs.length=0}function xp(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 yp(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 li(e){return e.canvas?navigator.gpu.getPreferredCanvasFormat():e.context.getPreferredFormat()}function _s(e){return e.canvas?e.context.getCurrentTexture().createView():e.context.getCurrentTextureView()}export{ne as createTexture,He as createTextureFromBuffer,he as createTextureFromUrl,vp as defineNode,gp as draw,_s as getCurrentTextureView,li as getPreferredFormat,pp as init,dp as initNode,wp as reset,xp as setViewportDimensions,yp as setViewportPosition};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@footgun/cobalt",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "type": "module",
5
5
  "main": "bundle.js",
6
6
  "description": "A 2D WebGpu renderer",
@@ -0,0 +1,11 @@
1
+ > Why do I have a folder named ".vercel" in my project?
2
+ The ".vercel" folder is created when you link a directory to a Vercel project.
3
+
4
+ > What does the "project.json" file contain?
5
+ The "project.json" file contains:
6
+ - The ID of the Vercel project that you linked ("projectId")
7
+ - The ID of the user or team your Vercel project is owned by ("orgId")
8
+
9
+ > Should I commit the ".vercel" folder?
10
+ No, you should not share the ".vercel" folder with anyone.
11
+ Upon creation, it will be automatically added to your ".gitignore" file.
@@ -0,0 +1 @@
1
+ {"projectId":"prj_jJXTHkZlQjFtTW7K7D94nIPjxcOX","orgId":"team_b8j5PhQ0qhPb9qIqUQzkxmra"}
@@ -142,7 +142,7 @@ async function init (cobalt, nodeData) {
142
142
  })
143
143
 
144
144
  const pipeline = device.createRenderPipeline({
145
- label: 'overlay',
145
+ label: 'overlaysprite',
146
146
  vertex: {
147
147
  module: device.createShaderModule({
148
148
  code: overlayWGSL
@@ -108,6 +108,7 @@ async function init (cobalt, node) {
108
108
 
109
109
  // Create render pipeline
110
110
  const pipeline = device.createRenderPipeline({
111
+ label: "primitives",
111
112
  layout: pipelineLayout,
112
113
  vertex: {
113
114
  module: shaderModule,
@@ -55,6 +55,7 @@ function init (cobalt, node) {
55
55
  params_buf.unmap()
56
56
 
57
57
  const pipeline = device.createRenderPipeline({
58
+ label: 'scenecomposite',
58
59
  layout: 'auto',
59
60
  vertex: {
60
61
  module: device.createShaderModule({
@@ -113,7 +113,7 @@ async function init (cobalt, node) {
113
113
  })
114
114
 
115
115
  const pipeline = device.createRenderPipeline({
116
- label: 'sprite',
116
+ label: 'spritesheet',
117
117
  vertex: {
118
118
  module: device.createShaderModule({
119
119
  code: spriteWGSL
package/src/tile/atlas.js CHANGED
@@ -111,7 +111,7 @@ async function init (cobalt, nodeData) {
111
111
  })
112
112
 
113
113
  const pipeline = device.createRenderPipeline({
114
- label: 'tile',
114
+ label: 'tileatlas',
115
115
  vertex: {
116
116
  module: device.createShaderModule({
117
117
  code: tileWGSL