-
Notifications
You must be signed in to change notification settings - Fork 0
/
bundle.js
290 lines (247 loc) · 268 KB
/
bundle.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
var wu=Object.create;var Pn=Object.defineProperty;var du=Object.getOwnPropertyDescriptor;var yu=Object.getOwnPropertyNames;var xu=Object.getPrototypeOf,Mu=Object.prototype.hasOwnProperty;var or=(r,t)=>()=>(t||r((t={exports:{}}).exports,t),t.exports),xi=(r,t)=>{for(var n in t)Pn(r,n,{get:t[n],enumerable:!0})},_u=(r,t,n,e)=>{if(t&&typeof t=="object"||typeof t=="function")for(let o of yu(t))!Mu.call(r,o)&&o!==n&&Pn(r,o,{get:()=>t[o],enumerable:!(e=du(t,o))||e.enumerable});return r};var Tu=(r,t,n)=>(n=r!=null?wu(xu(r)):{},_u(t||!r||!r.__esModule?Pn(n,"default",{value:r,enumerable:!0}):n,r));var ue=or((ap,Wi)=>{"use strict";function bs(r,t,n,e,o){for(var i=o+1;e<=o;){var a=e+o>>>1,u=r[a],s=n!==void 0?n(u,t):u-t;s>=0?(i=a,o=a-1):e=a+1}return i}function Bs(r,t,n,e,o){for(var i=o+1;e<=o;){var a=e+o>>>1,u=r[a],s=n!==void 0?n(u,t):u-t;s>0?(i=a,o=a-1):e=a+1}return i}function Es(r,t,n,e,o){for(var i=e-1;e<=o;){var a=e+o>>>1,u=r[a],s=n!==void 0?n(u,t):u-t;s<0?(i=a,e=a+1):o=a-1}return i}function Ss(r,t,n,e,o){for(var i=e-1;e<=o;){var a=e+o>>>1,u=r[a],s=n!==void 0?n(u,t):u-t;s<=0?(i=a,e=a+1):o=a-1}return i}function Us(r,t,n,e,o){for(;e<=o;){var i=e+o>>>1,a=r[i],u=n!==void 0?n(a,t):a-t;if(u===0)return i;u<=0?e=i+1:o=i-1}return-1}function ae(r,t,n,e,o,i){return typeof n=="function"?i(r,t,n,e===void 0?0:e|0,o===void 0?r.length-1:o|0):i(r,t,void 0,n===void 0?0:n|0,e===void 0?r.length-1:e|0)}Wi.exports={ge:function(r,t,n,e,o){return ae(r,t,n,e,o,bs)},gt:function(r,t,n,e,o){return ae(r,t,n,e,o,Bs)},lt:function(r,t,n,e,o){return ae(r,t,n,e,o,Es)},le:function(r,t,n,e,o){return ae(r,t,n,e,o,Ss)},eq:function(r,t,n,e,o){return ae(r,t,n,e,o,Us)}}});var Be=or((up,Ki)=>{"use strict";Ki.exports=As;var Qi=+(Math.pow(2,27)+1);function As(r,t,n){var e=r*t,o=Qi*r,i=o-r,a=o-i,u=r-a,s=Qi*t,l=s-t,p=s-l,_=t-p,F=e-a*p,z=F-u*p,I=z-a*_,m=u*_-I;return n?(n[0]=m,n[1]=e,n):[m,e]}});var zn=or((sp,Ji)=>{"use strict";Ji.exports=Ds;function Ps(r,t){var n=r+t,e=n-r,o=n-e,i=t-e,a=r-o,u=a+i;return u?[u,n]:[n]}function Ds(r,t){var n=r.length|0,e=t.length|0;if(n===1&&e===1)return Ps(r[0],t[0]);var o=n+e,i=new Array(o),a=0,u=0,s=0,l=Math.abs,p=r[u],_=l(p),F=t[s],z=l(F),I,m;_<z?(m=p,u+=1,u<n&&(p=r[u],_=l(p))):(m=F,s+=1,s<e&&(F=t[s],z=l(F))),u<n&&_<z||s>=e?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=t[s],z=l(F)));for(var L=I+m,W=L-I,V=m-W,H=V,$=L,Z,Q,it,et,X;u<n&&s<e;)_<z?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=t[s],z=l(F))),m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z;for(;u<n;)I=p,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,u+=1,u<n&&(p=r[u]);for(;s<e;)I=F,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,s+=1,s<e&&(F=t[s]);return H&&(i[a++]=H),$&&(i[a++]=$),a||(i[a++]=0),i.length=a,i}});var to=or((cp,ji)=>{"use strict";ji.exports=Is;function Is(r,t,n){var e=r+t,o=e-r,i=e-o,a=t-o,u=r-i;return n?(n[0]=u+a,n[1]=e,n):[u+a,e]}});var Cn=or((lp,ro)=>{"use strict";var On=Be(),ms=to();ro.exports=Rs;function Rs(r,t){var n=r.length;if(n===1){var e=On(r[0],t);return e[0]?e:[e[1]]}var o=new Array(2*n),i=[.1,.1],a=[.1,.1],u=0;On(r[0],t,i),i[0]&&(o[u++]=i[0]);for(var s=1;s<n;++s){On(r[s],t,a);var l=i[1];ms(l,a[0],i),i[0]&&(o[u++]=i[0]);var p=a[1],_=i[1],F=p+_,z=F-p,I=_-z;i[1]=F,I&&(o[u++]=I)}return i[1]&&(o[u++]=i[1]),u===0&&(o[u++]=0),o.length=u,o}});var Nn=or((fp,eo)=>{"use strict";eo.exports=Gs;function Ls(r,t){var n=r+t,e=n-r,o=n-e,i=t-e,a=r-o,u=a+i;return u?[u,n]:[n]}function Gs(r,t){var n=r.length|0,e=t.length|0;if(n===1&&e===1)return Ls(r[0],-t[0]);var o=n+e,i=new Array(o),a=0,u=0,s=0,l=Math.abs,p=r[u],_=l(p),F=-t[s],z=l(F),I,m;_<z?(m=p,u+=1,u<n&&(p=r[u],_=l(p))):(m=F,s+=1,s<e&&(F=-t[s],z=l(F))),u<n&&_<z||s>=e?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=-t[s],z=l(F)));for(var L=I+m,W=L-I,V=m-W,H=V,$=L,Z,Q,it,et,X;u<n&&s<e;)_<z?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=-t[s],z=l(F))),m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z;for(;u<n;)I=p,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,u+=1,u<n&&(p=r[u]);for(;s<e;)I=F,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,s+=1,s<e&&(F=-t[s]);return H&&(i[a++]=H),$&&(i[a++]=$),a||(i[a++]=0),i.length=a,i}});var io=or((hp,Vn)=>{"use strict";var Fs=Be(),zs=zn(),Os=Cn(),Cs=Nn(),no=5,Ee=11102230246251565e-32,Ns=(3+16*Ee)*Ee,Vs=(7+56*Ee)*Ee;function qs(r,t,n,e){return function(i,a,u){var s=r(r(t(a[1],u[0]),t(-u[1],a[0])),r(t(i[1],a[0]),t(-a[1],i[0]))),l=r(t(i[1],u[0]),t(-u[1],i[0])),p=e(s,l);return p[p.length-1]}}function Ys(r,t,n,e){return function(i,a,u,s){var l=r(r(n(r(t(u[1],s[0]),t(-s[1],u[0])),a[2]),r(n(r(t(a[1],s[0]),t(-s[1],a[0])),-u[2]),n(r(t(a[1],u[0]),t(-u[1],a[0])),s[2]))),r(n(r(t(a[1],s[0]),t(-s[1],a[0])),i[2]),r(n(r(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),s[2])))),p=r(r(n(r(t(u[1],s[0]),t(-s[1],u[0])),i[2]),r(n(r(t(i[1],s[0]),t(-s[1],i[0])),-u[2]),n(r(t(i[1],u[0]),t(-u[1],i[0])),s[2]))),r(n(r(t(a[1],u[0]),t(-u[1],a[0])),i[2]),r(n(r(t(i[1],u[0]),t(-u[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),u[2])))),_=e(l,p);return _[_.length-1]}}function ks(r,t,n,e){return function(i,a,u,s,l){var p=r(r(r(n(r(n(r(t(s[1],l[0]),t(-l[1],s[0])),u[2]),r(n(r(t(u[1],l[0]),t(-l[1],u[0])),-s[2]),n(r(t(u[1],s[0]),t(-s[1],u[0])),l[2]))),a[3]),r(n(r(n(r(t(s[1],l[0]),t(-l[1],s[0])),a[2]),r(n(r(t(a[1],l[0]),t(-l[1],a[0])),-s[2]),n(r(t(a[1],s[0]),t(-s[1],a[0])),l[2]))),-u[3]),n(r(n(r(t(u[1],l[0]),t(-l[1],u[0])),a[2]),r(n(r(t(a[1],l[0]),t(-l[1],a[0])),-u[2]),n(r(t(a[1],u[0]),t(-u[1],a[0])),l[2]))),s[3]))),r(n(r(n(r(t(u[1],s[0]),t(-s[1],u[0])),a[2]),r(n(r(t(a[1],s[0]),t(-s[1],a[0])),-u[2]),n(r(t(a[1],u[0]),t(-u[1],a[0])),s[2]))),-l[3]),r(n(r(n(r(t(s[1],l[0]),t(-l[1],s[0])),a[2]),r(n(r(t(a[1],l[0]),t(-l[1],a[0])),-s[2]),n(r(t(a[1],s[0]),t(-s[1],a[0])),l[2]))),i[3]),n(r(n(r(t(s[1],l[0]),t(-l[1],s[0])),i[2]),r(n(r(t(i[1],l[0]),t(-l[1],i[0])),-s[2]),n(r(t(i[1],s[0]),t(-s[1],i[0])),l[2]))),-a[3])))),r(r(n(r(n(r(t(a[1],l[0]),t(-l[1],a[0])),i[2]),r(n(r(t(i[1],l[0]),t(-l[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),l[2]))),s[3]),r(n(r(n(r(t(a[1],s[0]),t(-s[1],a[0])),i[2]),r(n(r(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),-l[3]),n(r(n(r(t(u[1],s[0]),t(-s[1],u[0])),a[2]),r(n(r(t(a[1],s[0]),t(-s[1],a[0])),-u[2]),n(r(t(a[1],u[0]),t(-u[1],a[0])),s[2]))),i[3]))),r(n(r(n(r(t(u[1],s[0]),t(-s[1],u[0])),i[2]),r(n(r(t(i[1],s[0]),t(-s[1],i[0])),-u[2]),n(r(t(i[1],u[0]),t(-u[1],i[0])),s[2]))),-a[3]),r(n(r(n(r(t(a[1],s[0]),t(-s[1],a[0])),i[2]),r(n(r(t(i[1],s[0]),t(-s[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),s[2]))),u[3]),n(r(n(r(t(a[1],u[0]),t(-u[1],a[0])),i[2]),r(n(r(t(i[1],u[0]),t(-u[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),u[2]))),-s[3]))))),_=r(r(r(n(r(n(r(t(s[1],l[0]),t(-l[1],s[0])),u[2]),r(n(r(t(u[1],l[0]),t(-l[1],u[0])),-s[2]),n(r(t(u[1],s[0]),t(-s[1],u[0])),l[2]))),i[3]),n(r(n(r(t(s[1],l[0]),t(-l[1],s[0])),i[2]),r(n(r(t(i[1],l[0]),t(-l[1],i[0])),-s[2]),n(r(t(i[1],s[0]),t(-s[1],i[0])),l[2]))),-u[3])),r(n(r(n(r(t(u[1],l[0]),t(-l[1],u[0])),i[2]),r(n(r(t(i[1],l[0]),t(-l[1],i[0])),-u[2]),n(r(t(i[1],u[0]),t(-u[1],i[0])),l[2]))),s[3]),n(r(n(r(t(u[1],s[0]),t(-s[1],u[0])),i[2]),r(n(r(t(i[1],s[0]),t(-s[1],i[0])),-u[2]),n(r(t(i[1],u[0]),t(-u[1],i[0])),s[2]))),-l[3]))),r(r(n(r(n(r(t(u[1],l[0]),t(-l[1],u[0])),a[2]),r(n(r(t(a[1],l[0]),t(-l[1],a[0])),-u[2]),n(r(t(a[1],u[0]),t(-u[1],a[0])),l[2]))),i[3]),n(r(n(r(t(u[1],l[0]),t(-l[1],u[0])),i[2]),r(n(r(t(i[1],l[0]),t(-l[1],i[0])),-u[2]),n(r(t(i[1],u[0]),t(-u[1],i[0])),l[2]))),-a[3])),r(n(r(n(r(t(a[1],l[0]),t(-l[1],a[0])),i[2]),r(n(r(t(i[1],l[0]),t(-l[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),l[2]))),u[3]),n(r(n(r(t(a[1],u[0]),t(-u[1],a[0])),i[2]),r(n(r(t(i[1],u[0]),t(-u[1],i[0])),-a[2]),n(r(t(i[1],a[0]),t(-a[1],i[0])),u[2]))),-l[3])))),F=e(p,_);return F[F.length-1]}}function Se(r){var t=r===3?qs:r===4?Ys:ks;return t(zs,Fs,Os,Cs)}var Xs=Se(3),Hs=Se(4),Fr=[function(){return 0},function(){return 0},function(t,n){return n[0]-t[0]},function(t,n,e){var o=(t[1]-e[1])*(n[0]-e[0]),i=(t[0]-e[0])*(n[1]-e[1]),a=o-i,u;if(o>0){if(i<=0)return a;u=o+i}else if(o<0){if(i>=0)return a;u=-(o+i)}else return a;var s=Ns*u;return a>=s||a<=-s?a:Xs(t,n,e)},function(t,n,e,o){var i=t[0]-o[0],a=n[0]-o[0],u=e[0]-o[0],s=t[1]-o[1],l=n[1]-o[1],p=e[1]-o[1],_=t[2]-o[2],F=n[2]-o[2],z=e[2]-o[2],I=a*p,m=u*l,L=u*s,W=i*p,V=i*l,H=a*s,$=_*(I-m)+F*(L-W)+z*(V-H),Z=(Math.abs(I)+Math.abs(m))*Math.abs(_)+(Math.abs(L)+Math.abs(W))*Math.abs(F)+(Math.abs(V)+Math.abs(H))*Math.abs(z),Q=Vs*Z;return $>Q||-$>Q?$:Hs(t,n,e,o)}];function $s(r){var t=Fr[r.length];return t||(t=Fr[r.length]=Se(r.length)),t.apply(void 0,r)}function Zs(r,t,n,e,o,i,a){return function(s,l,p,_,F){switch(arguments.length){case 0:case 1:return 0;case 2:return e(s,l);case 3:return o(s,l,p);case 4:return i(s,l,p,_);case 5:return a(s,l,p,_,F)}for(var z=new Array(arguments.length),I=0;I<arguments.length;++I)z[I]=arguments[I];return r(z)}}function Ws(){for(;Fr.length<=no;)Fr.push(Se(Fr.length));Vn.exports=Zs.apply(void 0,[$s].concat(Fr));for(var r=0;r<=no;++r)Vn.exports[r]=Fr[r]}Ws()});var lo=or((pp,co)=>{"use strict";var Ue=ue(),Pr=io()[3],Yn=0,oo=1,qn=2;co.exports=t0;function uo(r,t,n,e,o){this.a=r,this.b=t,this.idx=n,this.lowerIds=e,this.upperIds=o}function se(r,t,n,e){this.a=r,this.b=t,this.type=n,this.idx=e}function Qs(r,t){var n=r.a[0]-t.a[0]||r.a[1]-t.a[1]||r.type-t.type;return n||r.type!==Yn&&(n=Pr(r.a,r.b,t.b),n)?n:r.idx-t.idx}function ao(r,t){return Pr(r.a,r.b,t)}function Ks(r,t,n,e,o){for(var i=Ue.lt(t,e,ao),a=Ue.gt(t,e,ao),u=i;u<a;++u){for(var s=t[u],l=s.lowerIds,_=l.length;_>1&&Pr(n[l[_-2]],n[l[_-1]],e)>0;)r.push([l[_-1],l[_-2],o]),_-=1;l.length=_,l.push(o);for(var p=s.upperIds,_=p.length;_>1&&Pr(n[p[_-2]],n[p[_-1]],e)<0;)r.push([p[_-2],p[_-1],o]),_-=1;p.length=_,p.push(o)}}function so(r,t){var n;return r.a[0]<t.a[0]?n=Pr(r.a,r.b,t.a):n=Pr(t.b,t.a,r.a),n||(t.b[0]<r.b[0]?n=Pr(r.a,r.b,t.b):n=Pr(t.b,t.a,r.b),n||r.idx-t.idx)}function Js(r,t,n){var e=Ue.le(r,n,so),o=r[e],i=o.upperIds,a=i[i.length-1];o.upperIds=[a],r.splice(e+1,0,new uo(n.a,n.b,n.idx,[a],i))}function js(r,t,n){var e=n.a;n.a=n.b,n.b=e;var o=Ue.eq(r,n,so),i=r[o],a=r[o-1];a.upperIds=i.upperIds,r.splice(o,1)}function t0(r,t){for(var n=r.length,e=t.length,o=[],i=0;i<n;++i)o.push(new se(r[i],null,Yn,i));for(var i=0;i<e;++i){var a=t[i],u=r[a[0]],s=r[a[1]];u[0]<s[0]?o.push(new se(u,s,qn,i),new se(s,u,oo,i)):u[0]>s[0]&&o.push(new se(s,u,qn,i),new se(u,s,oo,i))}o.sort(Qs);for(var l=o[0].a[0]-(1+Math.abs(o[0].a[0]))*Math.pow(2,-52),p=[new uo([l,1],[l,0],-1,[],[],[],[])],_=[],i=0,F=o.length;i<F;++i){var z=o[i],I=z.type;I===Yn?Ks(_,p,r,z.a,z.idx):I===qn?Js(p,r,z):js(p,r,z)}return _}});var po=or((vp,ho)=>{"use strict";var r0=ue();ho.exports=e0;function fo(r,t){this.stars=r,this.edges=t}var zr=fo.prototype;function kn(r,t,n){for(var e=1,o=r.length;e<o;e+=2)if(r[e-1]===t&&r[e]===n){r[e-1]=r[o-2],r[e]=r[o-1],r.length=o-2;return}}zr.isConstraint=function(){var r=[0,0];function t(n,e){return n[0]-e[0]||n[1]-e[1]}return function(n,e){return r[0]=Math.min(n,e),r[1]=Math.max(n,e),r0.eq(this.edges,r,t)>=0}}();zr.removeTriangle=function(r,t,n){var e=this.stars;kn(e[r],t,n),kn(e[t],n,r),kn(e[n],r,t)};zr.addTriangle=function(r,t,n){var e=this.stars;e[r].push(t,n),e[t].push(n,r),e[n].push(r,t)};zr.opposite=function(r,t){for(var n=this.stars[t],e=1,o=n.length;e<o;e+=2)if(n[e]===r)return n[e-1];return-1};zr.flip=function(r,t){var n=this.opposite(r,t),e=this.opposite(t,r);this.removeTriangle(r,t,n),this.removeTriangle(t,r,e),this.addTriangle(r,e,n),this.addTriangle(t,n,e)};zr.edges=function(){for(var r=this.stars,t=[],n=0,e=r.length;n<e;++n)for(var o=r[n],i=0,a=o.length;i<a;i+=2)t.push([o[i],o[i+1]]);return t};zr.cells=function(){for(var r=this.stars,t=[],n=0,e=r.length;n<e;++n)for(var o=r[n],i=0,a=o.length;i<a;i+=2){var u=o[i],s=o[i+1];n<Math.min(u,s)&&t.push([n,u,s])}return t};function e0(r,t){for(var n=new Array(r),e=0;e<r;++e)n[e]=[];return new fo(n,t)}});var wo=or((gp,Xn)=>{"use strict";var n0=Be(),i0=zn(),o0=Nn(),a0=Cn(),vo=6;function go(r){var t=r===3?l0:r===4?f0:r===5?h0:p0;return t(i0,o0,n0,a0)}function u0(){return 0}function s0(){return 0}function c0(){return 0}function l0(r,t,n,e){function o(i,a,u){var s=n(i[0],i[0]),l=e(s,a[0]),p=e(s,u[0]),_=n(a[0],a[0]),F=e(_,i[0]),z=e(_,u[0]),I=n(u[0],u[0]),m=e(I,i[0]),L=e(I,a[0]),W=r(t(L,z),t(F,l)),V=t(m,p),H=t(W,V);return H[H.length-1]}return o}function f0(r,t,n,e){function o(i,a,u,s){var l=r(n(i[0],i[0]),n(i[1],i[1])),p=e(l,a[0]),_=e(l,u[0]),F=e(l,s[0]),z=r(n(a[0],a[0]),n(a[1],a[1])),I=e(z,i[0]),m=e(z,u[0]),L=e(z,s[0]),W=r(n(u[0],u[0]),n(u[1],u[1])),V=e(W,i[0]),H=e(W,a[0]),$=e(W,s[0]),Z=r(n(s[0],s[0]),n(s[1],s[1])),Q=e(Z,i[0]),it=e(Z,a[0]),et=e(Z,u[0]),X=r(r(e(t(et,$),a[1]),r(e(t(it,L),-u[1]),e(t(H,m),s[1]))),r(e(t(it,L),i[1]),r(e(t(Q,F),-a[1]),e(t(I,p),s[1])))),j=r(r(e(t(et,$),i[1]),r(e(t(Q,F),-u[1]),e(t(V,_),s[1]))),r(e(t(H,m),i[1]),r(e(t(V,_),-a[1]),e(t(I,p),u[1])))),E=t(X,j);return E[E.length-1]}return o}function h0(r,t,n,e){function o(i,a,u,s,l){var p=r(n(i[0],i[0]),r(n(i[1],i[1]),n(i[2],i[2]))),_=e(p,a[0]),F=e(p,u[0]),z=e(p,s[0]),I=e(p,l[0]),m=r(n(a[0],a[0]),r(n(a[1],a[1]),n(a[2],a[2]))),L=e(m,i[0]),W=e(m,u[0]),V=e(m,s[0]),H=e(m,l[0]),$=r(n(u[0],u[0]),r(n(u[1],u[1]),n(u[2],u[2]))),Z=e($,i[0]),Q=e($,a[0]),it=e($,s[0]),et=e($,l[0]),X=r(n(s[0],s[0]),r(n(s[1],s[1]),n(s[2],s[2]))),j=e(X,i[0]),E=e(X,a[0]),c=e(X,u[0]),w=e(X,l[0]),M=r(n(l[0],l[0]),r(n(l[1],l[1]),n(l[2],l[2]))),B=e(M,i[0]),S=e(M,a[0]),O=e(M,u[0]),N=e(M,s[0]),A=r(r(r(e(r(e(t(N,w),u[1]),r(e(t(O,et),-s[1]),e(t(c,it),l[1]))),a[2]),r(e(r(e(t(N,w),a[1]),r(e(t(S,H),-s[1]),e(t(E,V),l[1]))),-u[2]),e(r(e(t(O,et),a[1]),r(e(t(S,H),-u[1]),e(t(Q,W),l[1]))),s[2]))),r(e(r(e(t(c,it),a[1]),r(e(t(E,V),-u[1]),e(t(Q,W),s[1]))),-l[2]),r(e(r(e(t(N,w),a[1]),r(e(t(S,H),-s[1]),e(t(E,V),l[1]))),i[2]),e(r(e(t(N,w),i[1]),r(e(t(B,I),-s[1]),e(t(j,z),l[1]))),-a[2])))),r(r(e(r(e(t(S,H),i[1]),r(e(t(B,I),-a[1]),e(t(L,_),l[1]))),s[2]),r(e(r(e(t(E,V),i[1]),r(e(t(j,z),-a[1]),e(t(L,_),s[1]))),-l[2]),e(r(e(t(c,it),a[1]),r(e(t(E,V),-u[1]),e(t(Q,W),s[1]))),i[2]))),r(e(r(e(t(c,it),i[1]),r(e(t(j,z),-u[1]),e(t(Z,F),s[1]))),-a[2]),r(e(r(e(t(E,V),i[1]),r(e(t(j,z),-a[1]),e(t(L,_),s[1]))),u[2]),e(r(e(t(Q,W),i[1]),r(e(t(Z,F),-a[1]),e(t(L,_),u[1]))),-s[2]))))),h=r(r(r(e(r(e(t(N,w),u[1]),r(e(t(O,et),-s[1]),e(t(c,it),l[1]))),i[2]),e(r(e(t(N,w),i[1]),r(e(t(B,I),-s[1]),e(t(j,z),l[1]))),-u[2])),r(e(r(e(t(O,et),i[1]),r(e(t(B,I),-u[1]),e(t(Z,F),l[1]))),s[2]),e(r(e(t(c,it),i[1]),r(e(t(j,z),-u[1]),e(t(Z,F),s[1]))),-l[2]))),r(r(e(r(e(t(O,et),a[1]),r(e(t(S,H),-u[1]),e(t(Q,W),l[1]))),i[2]),e(r(e(t(O,et),i[1]),r(e(t(B,I),-u[1]),e(t(Z,F),l[1]))),-a[2])),r(e(r(e(t(S,H),i[1]),r(e(t(B,I),-a[1]),e(t(L,_),l[1]))),u[2]),e(r(e(t(Q,W),i[1]),r(e(t(Z,F),-a[1]),e(t(L,_),u[1]))),-l[2])))),D=t(A,h);return D[D.length-1]}return o}function p0(r,t,n,e){function o(i,a,u,s,l,p){var _=r(r(n(i[0],i[0]),n(i[1],i[1])),r(n(i[2],i[2]),n(i[3],i[3]))),F=e(_,a[0]),z=e(_,u[0]),I=e(_,s[0]),m=e(_,l[0]),L=e(_,p[0]),W=r(r(n(a[0],a[0]),n(a[1],a[1])),r(n(a[2],a[2]),n(a[3],a[3]))),V=e(W,i[0]),H=e(W,u[0]),$=e(W,s[0]),Z=e(W,l[0]),Q=e(W,p[0]),it=r(r(n(u[0],u[0]),n(u[1],u[1])),r(n(u[2],u[2]),n(u[3],u[3]))),et=e(it,i[0]),X=e(it,a[0]),j=e(it,s[0]),E=e(it,l[0]),c=e(it,p[0]),w=r(r(n(s[0],s[0]),n(s[1],s[1])),r(n(s[2],s[2]),n(s[3],s[3]))),M=e(w,i[0]),B=e(w,a[0]),S=e(w,u[0]),O=e(w,l[0]),N=e(w,p[0]),A=r(r(n(l[0],l[0]),n(l[1],l[1])),r(n(l[2],l[2]),n(l[3],l[3]))),h=e(A,i[0]),D=e(A,a[0]),ot=e(A,u[0]),ct=e(A,s[0]),st=e(A,p[0]),vt=r(r(n(p[0],p[0]),n(p[1],p[1])),r(n(p[2],p[2]),n(p[3],p[3]))),pt=e(vt,i[0]),d=e(vt,a[0]),G=e(vt,u[0]),g=e(vt,s[0]),y=e(vt,l[0]),R=r(r(r(e(r(r(e(r(e(t(y,st),s[1]),r(e(t(g,N),-l[1]),e(t(ct,O),p[1]))),u[2]),e(r(e(t(y,st),u[1]),r(e(t(G,c),-l[1]),e(t(ot,E),p[1]))),-s[2])),r(e(r(e(t(g,N),u[1]),r(e(t(G,c),-s[1]),e(t(S,j),p[1]))),l[2]),e(r(e(t(ct,O),u[1]),r(e(t(ot,E),-s[1]),e(t(S,j),l[1]))),-p[2]))),a[3]),r(e(r(r(e(r(e(t(y,st),s[1]),r(e(t(g,N),-l[1]),e(t(ct,O),p[1]))),a[2]),e(r(e(t(y,st),a[1]),r(e(t(d,Q),-l[1]),e(t(D,Z),p[1]))),-s[2])),r(e(r(e(t(g,N),a[1]),r(e(t(d,Q),-s[1]),e(t(B,$),p[1]))),l[2]),e(r(e(t(ct,O),a[1]),r(e(t(D,Z),-s[1]),e(t(B,$),l[1]))),-p[2]))),-u[3]),e(r(r(e(r(e(t(y,st),u[1]),r(e(t(G,c),-l[1]),e(t(ot,E),p[1]))),a[2]),e(r(e(t(y,st),a[1]),r(e(t(d,Q),-l[1]),e(t(D,Z),p[1]))),-u[2])),r(e(r(e(t(G,c),a[1]),r(e(t(d,Q),-u[1]),e(t(X,H),p[1]))),l[2]),e(r(e(t(ot,E),a[1]),r(e(t(D,Z),-u[1]),e(t(X,H),l[1]))),-p[2]))),s[3]))),r(r(e(r(r(e(r(e(t(g,N),u[1]),r(e(t(G,c),-s[1]),e(t(S,j),p[1]))),a[2]),e(r(e(t(g,N),a[1]),r(e(t(d,Q),-s[1]),e(t(B,$),p[1]))),-u[2])),r(e(r(e(t(G,c),a[1]),r(e(t(d,Q),-u[1]),e(t(X,H),p[1]))),s[2]),e(r(e(t(S,j),a[1]),r(e(t(B,$),-u[1]),e(t(X,H),s[1]))),-p[2]))),-l[3]),e(r(r(e(r(e(t(ct,O),u[1]),r(e(t(ot,E),-s[1]),e(t(S,j),l[1]))),a[2]),e(r(e(t(ct,O),a[1]),r(e(t(D,Z),-s[1]),e(t(B,$),l[1]))),-u[2])),r(e(r(e(t(ot,E),a[1]),r(e(t(D,Z),-u[1]),e(t(X,H),l[1]))),s[2]),e(r(e(t(S,j),a[1]),r(e(t(B,$),-u[1]),e(t(X,H),s[1]))),-l[2]))),p[3])),r(e(r(r(e(r(e(t(y,st),s[1]),r(e(t(g,N),-l[1]),e(t(ct,O),p[1]))),a[2]),e(r(e(t(y,st),a[1]),r(e(t(d,Q),-l[1]),e(t(D,Z),p[1]))),-s[2])),r(e(r(e(t(g,N),a[1]),r(e(t(d,Q),-s[1]),e(t(B,$),p[1]))),l[2]),e(r(e(t(ct,O),a[1]),r(e(t(D,Z),-s[1]),e(t(B,$),l[1]))),-p[2]))),i[3]),e(r(r(e(r(e(t(y,st),s[1]),r(e(t(g,N),-l[1]),e(t(ct,O),p[1]))),i[2]),e(r(e(t(y,st),i[1]),r(e(t(pt,L),-l[1]),e(t(h,m),p[1]))),-s[2])),r(e(r(e(t(g,N),i[1]),r(e(t(pt,L),-s[1]),e(t(M,I),p[1]))),l[2]),e(r(e(t(ct,O),i[1]),r(e(t(h,m),-s[1]),e(t(M,I),l[1]))),-p[2]))),-a[3])))),r(r(r(e(r(r(e(r(e(t(y,st),a[1]),r(e(t(d,Q),-l[1]),e(t(D,Z),p[1]))),i[2]),e(r(e(t(y,st),i[1]),r(e(t(pt,L),-l[1]),e(t(h,m),p[1]))),-a[2])),r(e(r(e(t(d,Q),i[1]),r(e(t(pt,L),-a[1]),e(t(V,F),p[1]))),l[2]),e(r(e(t(D,Z),i[1]),r(e(t(h,m),-a[1]),e(t(V,F),l[1]))),-p[2]))),s[3]),e(r(r(e(r(e(t(g,N),a[1]),r(e(t(d,Q),-s[1]),e(t(B,$),p[1]))),i[2]),e(r(e(t(g,N),i[1]),r(e(t(pt,L),-s[1]),e(t(M,I),p[1]))),-a[2])),r(e(r(e(t(d,Q),i[1]),r(e(t(pt,L),-a[1]),e(t(V,F),p[1]))),s[2]),e(r(e(t(B,$),i[1]),r(e(t(M,I),-a[1]),e(t(V,F),s[1]))),-p[2]))),-l[3])),r(e(r(r(e(r(e(t(ct,O),a[1]),r(e(t(D,Z),-s[1]),e(t(B,$),l[1]))),i[2]),e(r(e(t(ct,O),i[1]),r(e(t(h,m),-s[1]),e(t(M,I),l[1]))),-a[2])),r(e(r(e(t(D,Z),i[1]),r(e(t(h,m),-a[1]),e(t(V,F),l[1]))),s[2]),e(r(e(t(B,$),i[1]),r(e(t(M,I),-a[1]),e(t(V,F),s[1]))),-l[2]))),p[3]),e(r(r(e(r(e(t(g,N),u[1]),r(e(t(G,c),-s[1]),e(t(S,j),p[1]))),a[2]),e(r(e(t(g,N),a[1]),r(e(t(d,Q),-s[1]),e(t(B,$),p[1]))),-u[2])),r(e(r(e(t(G,c),a[1]),r(e(t(d,Q),-u[1]),e(t(X,H),p[1]))),s[2]),e(r(e(t(S,j),a[1]),r(e(t(B,$),-u[1]),e(t(X,H),s[1]))),-p[2]))),i[3]))),r(r(e(r(r(e(r(e(t(g,N),u[1]),r(e(t(G,c),-s[1]),e(t(S,j),p[1]))),i[2]),e(r(e(t(g,N),i[1]),r(e(t(pt,L),-s[1]),e(t(M,I),p[1]))),-u[2])),r(e(r(e(t(G,c),i[1]),r(e(t(pt,L),-u[1]),e(t(et,z),p[1]))),s[2]),e(r(e(t(S,j),i[1]),r(e(t(M,I),-u[1]),e(t(et,z),s[1]))),-p[2]))),-a[3]),e(r(r(e(r(e(t(g,N),a[1]),r(e(t(d,Q),-s[1]),e(t(B,$),p[1]))),i[2]),e(r(e(t(g,N),i[1]),r(e(t(pt,L),-s[1]),e(t(M,I),p[1]))),-a[2])),r(e(r(e(t(d,Q),i[1]),r(e(t(pt,L),-a[1]),e(t(V,F),p[1]))),s[2]),e(r(e(t(B,$),i[1]),r(e(t(M,I),-a[1]),e(t(V,F),s[1]))),-p[2]))),u[3])),r(e(r(r(e(r(e(t(G,c),a[1]),r(e(t(d,Q),-u[1]),e(t(X,H),p[1]))),i[2]),e(r(e(t(G,c),i[1]),r(e(t(pt,L),-u[1]),e(t(et,z),p[1]))),-a[2])),r(e(r(e(t(d,Q),i[1]),r(e(t(pt,L),-a[1]),e(t(V,F),p[1]))),u[2]),e(r(e(t(X,H),i[1]),r(e(t(et,z),-a[1]),e(t(V,F),u[1]))),-p[2]))),-s[3]),e(r(r(e(r(e(t(S,j),a[1]),r(e(t(B,$),-u[1]),e(t(X,H),s[1]))),i[2]),e(r(e(t(S,j),i[1]),r(e(t(M,I),-u[1]),e(t(et,z),s[1]))),-a[2])),r(e(r(e(t(B,$),i[1]),r(e(t(M,I),-a[1]),e(t(V,F),s[1]))),u[2]),e(r(e(t(X,H),i[1]),r(e(t(et,z),-a[1]),e(t(V,F),u[1]))),-s[2]))),p[3]))))),C=r(r(r(e(r(r(e(r(e(t(y,st),s[1]),r(e(t(g,N),-l[1]),e(t(ct,O),p[1]))),u[2]),e(r(e(t(y,st),u[1]),r(e(t(G,c),-l[1]),e(t(ot,E),p[1]))),-s[2])),r(e(r(e(t(g,N),u[1]),r(e(t(G,c),-s[1]),e(t(S,j),p[1]))),l[2]),e(r(e(t(ct,O),u[1]),r(e(t(ot,E),-s[1]),e(t(S,j),l[1]))),-p[2]))),i[3]),r(e(r(r(e(r(e(t(y,st),s[1]),r(e(t(g,N),-l[1]),e(t(ct,O),p[1]))),i[2]),e(r(e(t(y,st),i[1]),r(e(t(pt,L),-l[1]),e(t(h,m),p[1]))),-s[2])),r(e(r(e(t(g,N),i[1]),r(e(t(pt,L),-s[1]),e(t(M,I),p[1]))),l[2]),e(r(e(t(ct,O),i[1]),r(e(t(h,m),-s[1]),e(t(M,I),l[1]))),-p[2]))),-u[3]),e(r(r(e(r(e(t(y,st),u[1]),r(e(t(G,c),-l[1]),e(t(ot,E),p[1]))),i[2]),e(r(e(t(y,st),i[1]),r(e(t(pt,L),-l[1]),e(t(h,m),p[1]))),-u[2])),r(e(r(e(t(G,c),i[1]),r(e(t(pt,L),-u[1]),e(t(et,z),p[1]))),l[2]),e(r(e(t(ot,E),i[1]),r(e(t(h,m),-u[1]),e(t(et,z),l[1]))),-p[2]))),s[3]))),r(r(e(r(r(e(r(e(t(g,N),u[1]),r(e(t(G,c),-s[1]),e(t(S,j),p[1]))),i[2]),e(r(e(t(g,N),i[1]),r(e(t(pt,L),-s[1]),e(t(M,I),p[1]))),-u[2])),r(e(r(e(t(G,c),i[1]),r(e(t(pt,L),-u[1]),e(t(et,z),p[1]))),s[2]),e(r(e(t(S,j),i[1]),r(e(t(M,I),-u[1]),e(t(et,z),s[1]))),-p[2]))),-l[3]),e(r(r(e(r(e(t(ct,O),u[1]),r(e(t(ot,E),-s[1]),e(t(S,j),l[1]))),i[2]),e(r(e(t(ct,O),i[1]),r(e(t(h,m),-s[1]),e(t(M,I),l[1]))),-u[2])),r(e(r(e(t(ot,E),i[1]),r(e(t(h,m),-u[1]),e(t(et,z),l[1]))),s[2]),e(r(e(t(S,j),i[1]),r(e(t(M,I),-u[1]),e(t(et,z),s[1]))),-l[2]))),p[3])),r(e(r(r(e(r(e(t(y,st),u[1]),r(e(t(G,c),-l[1]),e(t(ot,E),p[1]))),a[2]),e(r(e(t(y,st),a[1]),r(e(t(d,Q),-l[1]),e(t(D,Z),p[1]))),-u[2])),r(e(r(e(t(G,c),a[1]),r(e(t(d,Q),-u[1]),e(t(X,H),p[1]))),l[2]),e(r(e(t(ot,E),a[1]),r(e(t(D,Z),-u[1]),e(t(X,H),l[1]))),-p[2]))),i[3]),e(r(r(e(r(e(t(y,st),u[1]),r(e(t(G,c),-l[1]),e(t(ot,E),p[1]))),i[2]),e(r(e(t(y,st),i[1]),r(e(t(pt,L),-l[1]),e(t(h,m),p[1]))),-u[2])),r(e(r(e(t(G,c),i[1]),r(e(t(pt,L),-u[1]),e(t(et,z),p[1]))),l[2]),e(r(e(t(ot,E),i[1]),r(e(t(h,m),-u[1]),e(t(et,z),l[1]))),-p[2]))),-a[3])))),r(r(r(e(r(r(e(r(e(t(y,st),a[1]),r(e(t(d,Q),-l[1]),e(t(D,Z),p[1]))),i[2]),e(r(e(t(y,st),i[1]),r(e(t(pt,L),-l[1]),e(t(h,m),p[1]))),-a[2])),r(e(r(e(t(d,Q),i[1]),r(e(t(pt,L),-a[1]),e(t(V,F),p[1]))),l[2]),e(r(e(t(D,Z),i[1]),r(e(t(h,m),-a[1]),e(t(V,F),l[1]))),-p[2]))),u[3]),e(r(r(e(r(e(t(G,c),a[1]),r(e(t(d,Q),-u[1]),e(t(X,H),p[1]))),i[2]),e(r(e(t(G,c),i[1]),r(e(t(pt,L),-u[1]),e(t(et,z),p[1]))),-a[2])),r(e(r(e(t(d,Q),i[1]),r(e(t(pt,L),-a[1]),e(t(V,F),p[1]))),u[2]),e(r(e(t(X,H),i[1]),r(e(t(et,z),-a[1]),e(t(V,F),u[1]))),-p[2]))),-l[3])),r(e(r(r(e(r(e(t(ot,E),a[1]),r(e(t(D,Z),-u[1]),e(t(X,H),l[1]))),i[2]),e(r(e(t(ot,E),i[1]),r(e(t(h,m),-u[1]),e(t(et,z),l[1]))),-a[2])),r(e(r(e(t(D,Z),i[1]),r(e(t(h,m),-a[1]),e(t(V,F),l[1]))),u[2]),e(r(e(t(X,H),i[1]),r(e(t(et,z),-a[1]),e(t(V,F),u[1]))),-l[2]))),p[3]),e(r(r(e(r(e(t(ct,O),u[1]),r(e(t(ot,E),-s[1]),e(t(S,j),l[1]))),a[2]),e(r(e(t(ct,O),a[1]),r(e(t(D,Z),-s[1]),e(t(B,$),l[1]))),-u[2])),r(e(r(e(t(ot,E),a[1]),r(e(t(D,Z),-u[1]),e(t(X,H),l[1]))),s[2]),e(r(e(t(S,j),a[1]),r(e(t(B,$),-u[1]),e(t(X,H),s[1]))),-l[2]))),i[3]))),r(r(e(r(r(e(r(e(t(ct,O),u[1]),r(e(t(ot,E),-s[1]),e(t(S,j),l[1]))),i[2]),e(r(e(t(ct,O),i[1]),r(e(t(h,m),-s[1]),e(t(M,I),l[1]))),-u[2])),r(e(r(e(t(ot,E),i[1]),r(e(t(h,m),-u[1]),e(t(et,z),l[1]))),s[2]),e(r(e(t(S,j),i[1]),r(e(t(M,I),-u[1]),e(t(et,z),s[1]))),-l[2]))),-a[3]),e(r(r(e(r(e(t(ct,O),a[1]),r(e(t(D,Z),-s[1]),e(t(B,$),l[1]))),i[2]),e(r(e(t(ct,O),i[1]),r(e(t(h,m),-s[1]),e(t(M,I),l[1]))),-a[2])),r(e(r(e(t(D,Z),i[1]),r(e(t(h,m),-a[1]),e(t(V,F),l[1]))),s[2]),e(r(e(t(B,$),i[1]),r(e(t(M,I),-a[1]),e(t(V,F),s[1]))),-l[2]))),u[3])),r(e(r(r(e(r(e(t(ot,E),a[1]),r(e(t(D,Z),-u[1]),e(t(X,H),l[1]))),i[2]),e(r(e(t(ot,E),i[1]),r(e(t(h,m),-u[1]),e(t(et,z),l[1]))),-a[2])),r(e(r(e(t(D,Z),i[1]),r(e(t(h,m),-a[1]),e(t(V,F),l[1]))),u[2]),e(r(e(t(X,H),i[1]),r(e(t(et,z),-a[1]),e(t(V,F),u[1]))),-l[2]))),-s[3]),e(r(r(e(r(e(t(S,j),a[1]),r(e(t(B,$),-u[1]),e(t(X,H),s[1]))),i[2]),e(r(e(t(S,j),i[1]),r(e(t(M,I),-u[1]),e(t(et,z),s[1]))),-a[2])),r(e(r(e(t(B,$),i[1]),r(e(t(M,I),-a[1]),e(t(V,F),s[1]))),u[2]),e(r(e(t(X,H),i[1]),r(e(t(et,z),-a[1]),e(t(V,F),u[1]))),-s[2]))),l[3]))))),K=t(R,C);return K[K.length-1]}return o}var Or=[u0,s0,c0];function v0(r){var t=Or[r.length];return t||(t=Or[r.length]=go(r.length)),t.apply(void 0,r)}function g0(r,t,n,e,o,i,a,u){function s(l,p,_,F,z,I){switch(arguments.length){case 0:case 1:return 0;case 2:return e(l,p);case 3:return o(l,p,_);case 4:return i(l,p,_,F);case 5:return a(l,p,_,F,z);case 6:return u(l,p,_,F,z,I)}for(var m=new Array(arguments.length),L=0;L<arguments.length;++L)m[L]=arguments[L];return r(m)}return s}function w0(){for(;Or.length<=vo;)Or.push(go(Or.length));Xn.exports=g0.apply(void 0,[v0].concat(Or));for(var r=0;r<=vo;++r)Xn.exports[r]=Or[r]}w0()});var xo=or((dp,yo)=>{"use strict";var Hn=wo()[4],wp=ue();yo.exports=d0;function Ae(r,t,n,e,o,i){var a=t.opposite(e,o);if(!(a<0)){if(o<e){var u=e;e=o,o=u,u=i,i=a,a=u}t.isConstraint(e,o)||Hn(r[e],r[o],r[i],r[a])<0&&n.push(e,o)}}function d0(r,t){for(var n=[],e=r.length,o=t.stars,i=0;i<e;++i)for(var a=o[i],u=1;u<a.length;u+=2){var s=a[u];if(!(s<i)&&!t.isConstraint(i,s)){for(var l=a[u-1],p=-1,_=1;_<a.length;_+=2)if(a[_-1]===s){p=a[_];break}p<0||Hn(r[i],r[s],r[l],r[p])<0&&n.push(i,s)}}for(;n.length>0;){for(var s=n.pop(),i=n.pop(),l=-1,p=-1,a=o[i],F=1;F<a.length;F+=2){var z=a[F-1],I=a[F];z===s?p=I:I===s&&(l=z)}l<0||p<0||Hn(r[i],r[s],r[l],r[p])>=0||(t.flip(i,s),Ae(r,t,n,l,i,p),Ae(r,t,n,i,p,l),Ae(r,t,n,p,s,l),Ae(r,t,n,s,l,p))}}});var bo=or((yp,To)=>{"use strict";var y0=ue();To.exports=T0;function Mo(r,t,n,e,o,i,a){this.cells=r,this.neighbor=t,this.flags=e,this.constraint=n,this.active=o,this.next=i,this.boundary=a}var x0=Mo.prototype;function _o(r,t){return r[0]-t[0]||r[1]-t[1]||r[2]-t[2]}x0.locate=function(){var r=[0,0,0];return function(t,n,e){var o=t,i=n,a=e;return n<e?n<t&&(o=n,i=e,a=t):e<t&&(o=e,i=t,a=n),o<0?-1:(r[0]=o,r[1]=i,r[2]=a,y0.eq(this.cells,r,_o))}}();function M0(r,t){for(var n=r.cells(),e=n.length,o=0;o<e;++o){var i=n[o],a=i[0],u=i[1],s=i[2];u<s?u<a&&(i[0]=u,i[1]=s,i[2]=a):s<a&&(i[0]=s,i[1]=a,i[2]=u)}n.sort(_o);for(var l=new Array(e),o=0;o<l.length;++o)l[o]=0;var p=[],_=[],F=new Array(3*e),z=new Array(3*e),I=null;t&&(I=[]);for(var m=new Mo(n,F,z,l,p,_,I),o=0;o<e;++o)for(var i=n[o],L=0;L<3;++L){var a=i[L],u=i[(L+1)%3],W=F[3*o+L]=m.locate(u,a,r.opposite(u,a)),V=z[3*o+L]=r.isConstraint(a,u);W<0&&(V?_.push(o):(p.push(o),l[o]=1),t&&I.push([u,a,-1]))}return m}function _0(r,t,n){for(var e=0,o=0;o<r.length;++o)t[o]===n&&(r[e++]=r[o]);return r.length=e,r}function T0(r,t,n){var e=M0(r,n);if(t===0)return n?e.cells.concat(e.boundary):e.cells;for(var o=1,i=e.active,a=e.next,u=e.flags,s=e.cells,l=e.constraint,p=e.neighbor;i.length>0||a.length>0;){for(;i.length>0;){var _=i.pop();if(u[_]!==-o){u[_]=o;for(var F=s[_],z=0;z<3;++z){var I=p[3*_+z];I>=0&&u[I]===0&&(l[3*_+z]?a.push(I):(i.push(I),u[I]=o))}}}var m=a;a=i,i=m,a.length=0,o=-o}var L=_0(s,u,t);return n?L.concat(e.boundary):L}});var Eo=or((xp,Bo)=>{"use strict";var b0=lo(),B0=po(),E0=xo(),$n=bo();Bo.exports=P0;function S0(r){return[Math.min(r[0],r[1]),Math.max(r[0],r[1])]}function U0(r,t){return r[0]-t[0]||r[1]-t[1]}function A0(r){return r.map(S0).sort(U0)}function Pe(r,t,n){return t in r?r[t]:n}function P0(r,t,n){Array.isArray(t)?(n=n||{},t=t||[]):(n=t||{},t=[]);var e=!!Pe(n,"delaunay",!0),o=!!Pe(n,"interior",!0),i=!!Pe(n,"exterior",!0),a=!!Pe(n,"infinity",!1);if(!o&&!i||r.length===0)return[];var u=b0(r,t);if(e||o!==i||a){for(var s=B0(r.length,A0(t)),l=0;l<u.length;++l){var p=u[l];s.addTriangle(p[0],p[1],p[2])}return e&&E0(r,s),i?o?a?$n(s,0,a):s.cells():$n(s,1,a):$n(s,-1)}else return u}});function er(r,t,n,e,o,i,a){let u=r.createTexture({label:t,size:{width:n,height:e},format:i,usage:a,mipLevelCount:o,sampleCount:1,dimension:"2d"}),s=u.createView(),l=[];for(let _=0;_<o;_++)l.push(u.createView({label:t,format:i,dimension:"2d",aspect:"all",baseMipLevel:_,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1}));let p=r.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:e},texture:u,view:s,mip_view:l,sampler:p}}async function gr(r,t,n,e="rgba8unorm"){let i=await(await fetch(n)).blob(),a=await createImageBitmap(i),u=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,l=er(r.device,t,a.width,a.height,1,e,u);r.device.queue.copyExternalImageToTexture({source:a},{texture:l.texture},{width:a.width,height:a.height});let p={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return l.sampler=r.device.createSampler(p),l}function ne(r,t,n,e="rgba8unorm"){let o=GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.COPY_DST|GPUTextureUsage.RENDER_ATTACHMENT,a=er(r.device,t,n.width,n.height,1,e,o);r.device.queue.writeTexture({texture:a.texture},n.data,{bytesPerRow:4*n.width},{width:n.width,height:n.height});let u={addressModeU:"repeat",addressModeV:"repeat",magFilter:"nearest",minFilter:"nearest",mipmapFilter:"nearest",maxAnisotropy:1};return a.sampler=r.device.createSampler(u),a}var Mi="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 fr=7,Bu=0,_i=1,Eu=2,Ti=3,bi={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(r,t={}){return Su(r,t)},onRun:function(r,t,n){Uu(r,t.data,n)},onDestroy:function(r,t){Ei(t)},onResize:function(r,t){Au(r,t)},onViewportPosition:function(r,t){}};function Su(r,t){let{device:n}=r,e=r.viewport.width,o=r.viewport.height,i={compute_pipeline:null,bind_group:[],bind_group_layout:[],bind_groups_textures:[]},a=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"}}]});i.bind_group_layout.push(a),i.bind_groups_textures.push(er(n,"bloom downsampler image 0",e/2,o/2,fr,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),i.bind_groups_textures.push(er(n,"bloom downsampler image 1",e/2,o/2,fr,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),i.bind_groups_textures.push(t.refs.bloom.data);let u=n.createPipelineLayout({bindGroupLayouts:i.bind_group_layout}),s=n.createComputePipeline({layout:u,compute:{module:n.createShaderModule({code:Mi}),entryPoint:"cs_main"}});return Bi(r,i,t),i.compute_pipeline=s,i}function Bi(r,t,n){let{refs:e}=n,{device:o}=r,i=n.options.bloom_threshold??.1,a=n.options.bloom_knee??.2,u=n.options.bloom_combine_constant??.68,s=new Float32Array([i,i-a,a*2,.25/a,u,0,0,0]),l=o.createBuffer({label:"bloom static parameters buffer",size:s.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});new Float32Array(l.getMappedRange()).set(s),l.unmap(),t.bind_group.length=0,t.params_buf=l,t.bind_group.push(Zr(o,t,t.bind_groups_textures[0].mip_view[0],e.emissive.data.view,e.hdr.data.view,e.hdr.data.sampler,l,Bu<<16|0));for(let _=1;_<fr;_++)t.bind_group.push(Zr(o,t,t.bind_groups_textures[1].mip_view[_],t.bind_groups_textures[0].view,e.hdr.data.view,e.hdr.data.sampler,l,_i<<16|_-1)),t.bind_group.push(Zr(o,t,t.bind_groups_textures[0].mip_view[_],t.bind_groups_textures[1].view,e.hdr.data.view,e.hdr.data.sampler,l,_i<<16|_));t.bind_group.push(Zr(o,t,t.bind_groups_textures[2].mip_view[fr-1],t.bind_groups_textures[0].view,e.hdr.data.view,e.hdr.data.sampler,l,Eu<<16|fr-2));let p=!0;for(let _=fr-2;_>=0;_--)p?(t.bind_group.push(Zr(o,t,t.bind_groups_textures[1].mip_view[_],t.bind_groups_textures[0].view,t.bind_groups_textures[2].view,e.hdr.data.sampler,l,Ti<<16|_)),p=!1):(t.bind_group.push(Zr(o,t,t.bind_groups_textures[2].mip_view[_],t.bind_groups_textures[0].view,t.bind_groups_textures[1].view,e.hdr.data.sampler,l,Ti<<16|_)),p=!0)}function Zr(r,t,n,e,o,i,a,u){let s=new Uint32Array([u]),l=r.createBuffer({label:"bloom static mode_lod buffer",size:s.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});return new Uint32Array(l.getMappedRange()).set(s),l.unmap(),r.createBindGroup({label:"bloom bind group layout",layout:t.bind_group_layout[0],entries:[{binding:0,resource:n},{binding:1,resource:e},{binding:2,resource:o},{binding:3,resource:i},{binding:4,resource:{buffer:a}},{binding:5,resource:{buffer:l}}]})}function Uu(r,t,n){let u=0,s=n.beginComputePass({label:"bloom Compute Pass"});s.setPipeline(t.compute_pipeline),s.setBindGroup(0,t.bind_group[u]),u+=1;let l=ye(0,t.bind_groups_textures[0]);s.dispatchWorkgroups(l.width/8+1,l.height/4+1,1);for(let p=1;p<fr;p++)l=ye(p,t.bind_groups_textures[0]),s.setBindGroup(0,t.bind_group[u]),u+=1,s.dispatchWorkgroups(l.width/8+1,l.height/4+1,1),s.setBindGroup(0,t.bind_group[u]),u+=1,s.dispatchWorkgroups(l.width/8+1,l.height/4+1,1);s.setBindGroup(0,t.bind_group[u]),u+=1,l=ye(fr-1,t.bind_groups_textures[2]),s.dispatchWorkgroups(l.width/8+1,l.height/4+1,1);for(let p=fr-2;p>=0;p--)l=ye(p,t.bind_groups_textures[2]),s.setBindGroup(0,t.bind_group[u]),u+=1,s.dispatchWorkgroups(l.width/8+1,l.height/4+1,1);s.end()}function ye(r,t){let n=t.size.width,e=t.size.height;for(let o=0;o<r;o++)n/=2,e/=2;return{width:n,height:e,depthOrArrayLayers:1}}function Au(r,t){let{device:n}=r,e=t.data;Ei(e),e.bind_groups_textures.push(er(n,"bloom downsampler image 0",r.viewport.width/2,r.viewport.height/2,fr,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),e.bind_groups_textures.push(er(n,"bloom downsampler image 1",r.viewport.width/2,r.viewport.height/2,fr,"rgba16float",GPUTextureUsage.STORAGE_BINDING|GPUTextureUsage.TEXTURE_BINDING)),e.bind_groups_textures.push(t.refs.bloom.data),Bi(r,e,t)}function Ei(r){for(let t of r.bind_groups_textures)t.texture.destroy();r.bind_groups_textures.length=0}var Dn="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 Si={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(r,t={}){return Du(r,t)},onRun:function(r,t,n){Iu(r,t,n)},onDestroy:function(r,t){},onResize:function(r,t){mu(r,t)},onViewportPosition:function(r,t){}};function Du(r,t){let{options:n,refs:e}=t,{device:o}=r,i=Ui(r),a=n.bloom_intensity??40,u=n.bloom_combine_constant??.68,s=new Float32Array([a,u]),l=o.createBuffer({label:"scene composite params buffer",size:s.byteLength,mappedAtCreation:!0,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});new Float32Array(l.getMappedRange()).set(s),l.unmap();let p=o.createRenderPipeline({layout:"auto",vertex:{module:o.createShaderModule({code:Dn}),entryPoint:"vert_main"},fragment:{module:o.createShaderModule({code:Dn}),entryPoint:"frag_main",targets:[{format:i}]},primitive:{topology:"triangle-list"}});return{bindGroup:o.createBindGroup({layout:p.getBindGroupLayout(0),entries:[{binding:0,resource:e.hdr.data.sampler},{binding:1,resource:e.hdr.data.view},{binding:2,resource:e.bloom.data.mip_view[0]},{binding:3,resource:{buffer:l}}]}),pipeline:p,params_buf:l}}function Iu(r,t,n){let e=n.beginRenderPass({colorAttachments:[{view:t.refs.combined.data.view,clearValue:{r:0,g:0,b:0,a:1},loadOp:"clear",storeOp:"store"}]}),{pipeline:o,bindGroup:i}=t.data;e.setPipeline(o),e.setBindGroup(0,i),e.draw(3),e.end()}function mu(r,t){let{pipeline:n,params_buf:e}=t.data,{device:o}=r;t.data.bindGroup=o.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:e}}]})}var oe={};xi(oe,{addSprite:()=>Lu,clear:()=>Fu,removeSprite:()=>Gu,setSprite:()=>Yu,setSpriteName:()=>zu,setSpriteOpacity:()=>Nu,setSpritePosition:()=>Ou,setSpriteRotation:()=>Vu,setSpriteScale:()=>qu,setSpriteTint:()=>Cu});function In(r,t,n){if(n.spriteCount===0)return 0;let e=0,o=n.spriteCount-1,i=r<<16&16711680|t&65535;for(;e<=o;){let a=n.spriteData[e*12+11];if(i<=a)return e;let u=n.spriteData[o*12+11];if(i>=u)return o+1;let s=Math.floor((e+o)/2),l=n.spriteData[s*12+11];if(i===l)return s+1;i>l?e=s+1:o=s-1}return e}function ie(){return Math.ceil(Math.random()*(Number.MAX_SAFE_INTEGER-10))}function Lu(r,t,n,e,o,i,a,u,s){let l=t.refs.spritesheet.data.spritesheet;t=t.data;let p=l.locations.indexOf(n),_=In(s,p,t),F=(_+1)*12;t.spriteData.set(t.spriteData.subarray(_*12,t.spriteCount*12),F),Ai(t,l,_,n,e,o,i,a,u,s);for(let[I,m]of t.spriteIndices)m>=_&&t.spriteIndices.set(I,m+1);let z=ie();return t.spriteIndices.set(z,_),t.spriteCount++,t.dirty=!0,z}function Gu(r,t,n){t=t.data;let e=t.spriteIndices.get(n);for(let[i,a]of t.spriteIndices)a>e&&t.spriteIndices.set(i,a-1);let o=e*12;t.spriteData.set(t.spriteData.subarray((e+1)*12,t.spriteCount*12),o),t.spriteIndices.delete(n),t.spriteCount--,t.dirty=!0}function Fu(r,t){t=t.data,t.spriteIndices.clear(),t.spriteCount=0,t.instancedDrawCallCount=0,t.dirty=!0}function zu(r,t,n,e,o){let i=t.refs.spritesheet.data.spritesheet;t=t.data;let a=i.locations.indexOf(e),u=i.spriteMeta[e].w,s=i.spriteMeta[e].h,p=t.spriteIndices.get(n)*12;t.spriteData[p+2]=u*o[0],t.spriteData[p+3]=s*o[1];let F=(t.spriteData[p+11]>>16&255)<<16&16711680|a&65535;t.spriteData[p+11]=F,t.dirty=!0}function Ou(r,t,n,e){t=t.data;let i=t.spriteIndices.get(n)*12;t.spriteData[i]=e[0],t.spriteData[i+1]=e[1],t.dirty=!0}function Cu(r,t,n,e){t=t.data;let i=t.spriteIndices.get(n)*12;t.spriteData[i+4]=e[0],t.spriteData[i+5]=e[1],t.spriteData[i+6]=e[2],t.spriteData[i+7]=e[3],t.dirty=!0}function Nu(r,t,n,e){t=t.data;let i=t.spriteIndices.get(n)*12;t.spriteData[i+8]=e,t.dirty=!0}function Vu(r,t,n,e){t=t.data;let i=t.spriteIndices.get(n)*12;t.spriteData[i+9]=e,t.dirty=!0}function qu(r,t,n,e,o){let i=t.refs.spritesheet.data.spritesheet;t=t.data;let u=t.spriteIndices.get(n)*12,s=i.spriteMeta[e].w,l=i.spriteMeta[e].h;t.spriteData[u+2]=s*o[0],t.spriteData[u+3]=l*o[1],t.dirty=!0}function Yu(r,t,n,e,o,i,a,u,s,l){let p=t.refs.spritesheet.data.spritesheet;t=t.data;let _=t.spriteIndices.get(n);Ai(t,p,_,e,o,i,a,u,s,l),t.dirty=!0}function Ai(r,t,n,e,o,i,a,u,s,l){if(!t.spriteMeta[e])throw new Error(`Sprite name ${e} could not be found in the spritesheet metaData`);let p=n*12,_=t.spriteMeta[e].w,F=t.spriteMeta[e].h,z=t.locations.indexOf(e),I=l<<16&16711680|z&65535;r.spriteData[p]=o[0],r.spriteData[p+1]=o[1],r.spriteData[p+2]=_*i[0],r.spriteData[p+3]=F*i[1],r.spriteData[p+4]=a[0],r.spriteData[p+5]=a[1],r.spriteData[p+6]=a[2],r.spriteData[p+7]=a[3],r.spriteData[p+8]=u,r.spriteData[p+9]=s,r.spriteData[p+11]=I}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(r,t={}){return ku(r,t)},onRun:function(r,t,n){Xu(r,t,n)},onDestroy:function(r,t){$u(t)},onResize:function(r,t){},onViewportPosition:function(r,t){},customFunctions:{...oe}};async function ku(r,t){let{device:n}=r,e=16192,o=e,a=Float32Array.BYTES_PER_ELEMENT*2,s=Float32Array.BYTES_PER_ELEMENT*2,p=Float32Array.BYTES_PER_ELEMENT*4,F=Float32Array.BYTES_PER_ELEMENT*4,z=n.createBuffer({size:(a+s+p+F)*o,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),I=t.refs.spritesheet.data,m=n.createBindGroup({layout:t.refs.spritesheet.data.bindGroupLayout,entries:[{binding:0,resource:{buffer:I.uniformBuffer}},{binding:1,resource:I.colorTexture.view},{binding:2,resource:I.colorTexture.sampler},{binding:3,resource:{buffer:z}},{binding:4,resource:I.emissiveTexture.view}]});return{instancedDrawCalls:new Uint32Array(e*2),instancedDrawCallCount:0,bindGroup:m,spriteBuffer:z,spriteData:new Float32Array(e*12),spriteCount:0,spriteIndices:new Map,dirty:!1}}function Xu(r,t,n){let{device:e}=r,o=t.options.loadOp||"load";if(t.data.dirty&&(Hu(t.data),t.data.dirty=!1),t.data.spriteCount>0){let s=t.data.spriteCount*12*Float32Array.BYTES_PER_ELEMENT;e.queue.writeBuffer(t.data.spriteBuffer,0,t.data.spriteData.buffer,0,s)}let i=n.beginRenderPass({colorAttachments:[{view:t.refs.hdr.data.view,clearValue:r.clearValue,loadOp:o,storeOp:"store"},{view:t.refs.emissive.data.view,clearValue:r.clearValue,loadOp:"clear",storeOp:"store"}]});i.setPipeline(t.refs.spritesheet.data.pipeline),i.setBindGroup(0,t.data.bindGroup),i.setVertexBuffer(0,t.refs.spritesheet.data.quads.buffer);let a=6,u=0;for(let s=0;s<t.data.instancedDrawCallCount;s++){let l=t.data.instancedDrawCalls[s*2]*a,p=t.data.instancedDrawCalls[s*2+1];i.draw(a,p,l,u),u+=p}i.end()}function Hu(r){let t=-1,n=0;r.instancedDrawCallCount=0;for(let e=0;e<r.spriteCount;e++){let o=r.spriteData[e*12+11]&65535;o!==t&&(n>0&&(r.instancedDrawCalls[r.instancedDrawCallCount*2]=t,r.instancedDrawCalls[r.instancedDrawCallCount*2+1]=n,r.instancedDrawCallCount++),t=o,n=0),n++}n>0&&(r.instancedDrawCalls[r.instancedDrawCallCount*2]=t,r.instancedDrawCalls[r.instancedDrawCallCount*2+1]=n,r.instancedDrawCallCount++)}function $u(r){r.data.instancedDrawCalls=null,r.data.bindGroup=null,r.data.spriteBuffer.destroy(),r.data.spriteBuffer=null,r.data.spriteData=null,r.data.spriteIndices.clear(),r.data.spriteIndices=null}var Ii={type:"cobalt:tile",refs:[{name:"tileAtlas",type:"textureView",format:"rgba8unorm",access:"write"}],onInit:async function(r,t={}){return Zu(r,t)},onRun:function(r,t,n){Wu(r,t,n)},onDestroy:function(r,t){Di(t)},onResize:function(r,t){},onViewportPosition:function(r,t){},customFunctions:{setTexture:async function(r,t,n){let{device:e}=r;Di(t),t.options.textureUrl=n;let o=await gr(r,"tile map",t.options.textureUrl),i=e.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:t.data.uniformBuffer}},{binding:1,resource:o.view},{binding:2,resource:o.sampler}]});t.data.bindGroup=i,t.data.material=o}}};async function Zu(r,t){let{device:n}=r,e=await gr(r,"tile map",t.options.textureUrl),o=new Float32Array([t.options.scrollScale,t.options.scrollScale]),i=GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST,a={size:o.byteLength,usage:i,mappedAtCreation:!0},u=n.createBuffer(a);return new Float32Array(u.getMappedRange()).set(o),u.unmap(),{bindGroup:n.createBindGroup({layout:t.refs.tileAtlas.data.tileBindGroupLayout,entries:[{binding:0,resource:{buffer:u}},{binding:1,resource:e.view},{binding:2,resource:e.sampler}]}),material:e,uniformBuffer:u,scrollScale:t.options.scrollScale}}function Wu(r,t,n){let{device:e}=r,o=t.options.loadOp||"load",i=n.beginRenderPass({colorAttachments:[{view:t.refs.hdr.data.view,clearValue:r.clearValue,loadOp:o,storeOp:"store"}]}),a=t.refs.tileAtlas.data;i.setPipeline(a.pipeline),i.setBindGroup(0,t.data.bindGroup),i.setBindGroup(1,a.atlasBindGroup),i.draw(3),i.end()}function Di(r){r.data.material.texture.destroy(),r.data.material.texture=void 0}var xe=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 e of this.sprites.values())t.push(...e);let n=new Float32Array(t);this.device.queue.writeBuffer(this.bufferGpu,0,n)}}addTriangle(t){let n=ie();if(this.sprites.has(n))throw new Error(`Duplicate triangle "${n}".`);let e=this.buildTriangleData(t);return this.sprites.set(n,e),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 e=this.buildTriangleData(n);this.sprites.set(t,e),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 Me=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 mi="struct DisplacementParameters{offset:vec2<f32>,scale:f32,};@group(0)@binding(0)var<uniform> uniforms:DisplacementParameters;@group(0)@binding(1)var colorTexture:texture_2d<f32>;@group(0)@binding(2)var colorSampler:sampler;@group(0)@binding(3)var noiseTexture:texture_2d<f32>;@group(0)@binding(4)var noiseSampler:sampler;@group(0)@binding(5)var displacementTexture:texture_2d<f32>;struct VertexIn{@builtin(vertex_index)vertexIndex:u32,};struct VertexOut{@builtin(position)position:vec4<f32>,@location(0)uv:vec2<f32>,};@vertex fn main_vertex(in:VertexIn)->VertexOut{const corners=array<vec2<f32>,4>(vec2<f32>(-1,-1),vec2<f32>(1,-1),vec2<f32>(-1,1),vec2<f32>(1,1),);let screenPosition=corners[in.vertexIndex];var out:VertexOut;out.position=vec4<f32>(screenPosition,0,1);out.uv=(0.5+0.5*screenPosition*vec2<f32>(1,-1));return out;}struct FragmentOut{@location(0)color:vec4<f32>,};@fragment fn main_fragment(in:VertexOut)->FragmentOut{let noiseTextureDimensions=vec2<f32>(textureDimensions(noiseTexture,0));let noiseUv=in.uv+uniforms.offset/noiseTextureDimensions;var noise=textureSample(noiseTexture,noiseSampler,noiseUv).rg;noise-=0.5;noise*=uniforms.scale/noiseTextureDimensions;let displacement=textureSample(displacementTexture,colorSampler,in.uv).r;noise*=displacement;let colorUv=in.uv+noise;var out:FragmentOut;out.color=textureSample(colorTexture,colorSampler,colorUv);return out;}";var _e=class{device;targetFormat;renderPipeline;colorSampler;noiseSampler;displacementParametersBuffer;renderBundle=null;colorTextureView;noiseMapTextureView;displacementTextureView;constructor(t){this.device=t.device,this.targetFormat=t.targetFormat,this.colorTextureView=t.colorTextureView,this.noiseMapTextureView=t.noiseMapTextureView,this.displacementTextureView=t.displacementTextureView,this.displacementParametersBuffer=t.displacementParametersBuffer;let n=this.device.createShaderModule({label:"DisplacementComposition shader module",code:mi});this.renderPipeline=this.device.createRenderPipeline({label:"DisplacementComposition renderpipeline",layout:"auto",vertex:{module:n,entryPoint:"main_vertex"},fragment:{module:n,entryPoint:"main_fragment",targets:[{format:t.targetFormat}]},primitive:{cullMode:"none",topology:"triangle-strip"}}),this.noiseSampler=this.device.createSampler({label:"DisplacementComposition noisesampler",addressModeU:"repeat",addressModeV:"repeat",addressModeW:"repeat",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"}),this.colorSampler=this.device.createSampler({label:"DisplacementComposition colorSampler",addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",addressModeW:"clamp-to-edge",magFilter:"linear",minFilter:"linear",mipmapFilter:"linear"})}getRenderBundle(){return this.renderBundle||(this.renderBundle=this.buildRenderBundle()),this.renderBundle}destroy(){}setColorTextureView(t){this.colorTextureView=t,this.renderBundle=null}setNoiseMapTextureView(t){this.noiseMapTextureView=t,this.renderBundle=null}setDisplacementTextureView(t){this.displacementTextureView=t,this.renderBundle=null}buildRenderBundle(){let t=this.device.createBindGroup({label:"DisplacementComposition bindgroup 0",layout:this.renderPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.displacementParametersBuffer.bufferGpu}},{binding:1,resource:this.colorTextureView},{binding:2,resource:this.colorSampler},{binding:3,resource:this.noiseMapTextureView},{binding:4,resource:this.noiseSampler},{binding:5,resource:this.displacementTextureView}]}),n=this.device.createRenderBundleEncoder({label:"DisplacementComposition renderbundle encoder",colorFormats:[this.targetFormat]});return n.setPipeline(this.renderPipeline),n.setBindGroup(0,t),n.draw(4),n.finish({label:"DisplacementComposition renderbundle"})}};var Ri="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 Ju(r,t){return class extends r{constructor(...n){super(...n),t(this)}}}var ju=Ju(Array,r=>r.fill(0)),Mt=1e-6;function ts(r){function t(f=0,T=0){let v=new r(2);return f!==void 0&&(v[0]=f,T!==void 0&&(v[1]=T)),v}let n=t;function e(f,T,v){let x=v??new r(2);return x[0]=f,x[1]=T,x}function o(f,T){let v=T??new r(2);return v[0]=Math.ceil(f[0]),v[1]=Math.ceil(f[1]),v}function i(f,T){let v=T??new r(2);return v[0]=Math.floor(f[0]),v[1]=Math.floor(f[1]),v}function a(f,T){let v=T??new r(2);return v[0]=Math.round(f[0]),v[1]=Math.round(f[1]),v}function u(f,T=0,v=1,x){let U=x??new r(2);return U[0]=Math.min(v,Math.max(T,f[0])),U[1]=Math.min(v,Math.max(T,f[1])),U}function s(f,T,v){let x=v??new r(2);return x[0]=f[0]+T[0],x[1]=f[1]+T[1],x}function l(f,T,v,x){let U=x??new r(2);return U[0]=f[0]+T[0]*v,U[1]=f[1]+T[1]*v,U}function p(f,T){let v=f[0],x=f[1],U=T[0],q=T[1],rt=Math.sqrt(v*v+x*x),b=Math.sqrt(U*U+q*q),P=rt*b,k=P&&X(f,T)/P;return Math.acos(k)}function _(f,T,v){let x=v??new r(2);return x[0]=f[0]-T[0],x[1]=f[1]-T[1],x}let F=_;function z(f,T){return Math.abs(f[0]-T[0])<Mt&&Math.abs(f[1]-T[1])<Mt}function I(f,T){return f[0]===T[0]&&f[1]===T[1]}function m(f,T,v,x){let U=x??new r(2);return U[0]=f[0]+v*(T[0]-f[0]),U[1]=f[1]+v*(T[1]-f[1]),U}function L(f,T,v,x){let U=x??new r(2);return U[0]=f[0]+v[0]*(T[0]-f[0]),U[1]=f[1]+v[1]*(T[1]-f[1]),U}function W(f,T,v){let x=v??new r(2);return x[0]=Math.max(f[0],T[0]),x[1]=Math.max(f[1],T[1]),x}function V(f,T,v){let x=v??new r(2);return x[0]=Math.min(f[0],T[0]),x[1]=Math.min(f[1],T[1]),x}function H(f,T,v){let x=v??new r(2);return x[0]=f[0]*T,x[1]=f[1]*T,x}let $=H;function Z(f,T,v){let x=v??new r(2);return x[0]=f[0]/T,x[1]=f[1]/T,x}function Q(f,T){let v=T??new r(2);return v[0]=1/f[0],v[1]=1/f[1],v}let it=Q;function et(f,T,v){let x=v??new r(3),U=f[0]*T[1]-f[1]*T[0];return x[0]=0,x[1]=0,x[2]=U,x}function X(f,T){return f[0]*T[0]+f[1]*T[1]}function j(f){let T=f[0],v=f[1];return Math.sqrt(T*T+v*v)}let E=j;function c(f){let T=f[0],v=f[1];return T*T+v*v}let w=c;function M(f,T){let v=f[0]-T[0],x=f[1]-T[1];return Math.sqrt(v*v+x*x)}let B=M;function S(f,T){let v=f[0]-T[0],x=f[1]-T[1];return v*v+x*x}let O=S;function N(f,T){let v=T??new r(2),x=f[0],U=f[1],q=Math.sqrt(x*x+U*U);return q>1e-5?(v[0]=x/q,v[1]=U/q):(v[0]=0,v[1]=0),v}function A(f,T){let v=T??new r(2);return v[0]=-f[0],v[1]=-f[1],v}function h(f,T){let v=T??new r(2);return v[0]=f[0],v[1]=f[1],v}let D=h;function ot(f,T,v){let x=v??new r(2);return x[0]=f[0]*T[0],x[1]=f[1]*T[1],x}let ct=ot;function st(f,T,v){let x=v??new r(2);return x[0]=f[0]/T[0],x[1]=f[1]/T[1],x}let vt=st;function pt(f=1,T){let v=T??new r(2),x=Math.random()*2*Math.PI;return v[0]=Math.cos(x)*f,v[1]=Math.sin(x)*f,v}function d(f){let T=f??new r(2);return T[0]=0,T[1]=0,T}function G(f,T,v){let x=v??new r(2),U=f[0],q=f[1];return x[0]=U*T[0]+q*T[4]+T[12],x[1]=U*T[1]+q*T[5]+T[13],x}function g(f,T,v){let x=v??new r(2),U=f[0],q=f[1];return x[0]=T[0]*U+T[4]*q+T[8],x[1]=T[1]*U+T[5]*q+T[9],x}function y(f,T,v,x){let U=x??new r(2),q=f[0]-T[0],rt=f[1]-T[1],b=Math.sin(v),P=Math.cos(v);return U[0]=q*P-rt*b+T[0],U[1]=q*b+rt*P+T[1],U}function R(f,T,v){let x=v??new r(2);return N(f,x),H(x,T,x)}function C(f,T,v){let x=v??new r(2);return j(f)>T?R(f,T,x):h(f,x)}function K(f,T,v){let x=v??new r(2);return m(f,T,.5,x)}return{create:t,fromValues:n,set:e,ceil:o,floor:i,round:a,clamp:u,add:s,addScaled:l,angle:p,subtract:_,sub:F,equalsApproximately:z,equals:I,lerp:m,lerpV:L,max:W,min:V,mulScalar:H,scale:$,divScalar:Z,inverse:Q,invert:it,cross:et,dot:X,length:j,len:E,lengthSq:c,lenSq:w,distance:M,dist:B,distanceSq:S,distSq:O,normalize:N,negate:A,copy:h,clone:D,multiply:ot,mul:ct,divide:st,div:vt,random:pt,zero:d,transformMat4:G,transformMat3:g,rotate:y,setLength:R,truncate:C,midpoint:K}}var Li=new Map;function Ni(r){let t=Li.get(r);return t||(t=ts(r),Li.set(r,t)),t}function rs(r){function t(b,P,k){let Y=new r(3);return b!==void 0&&(Y[0]=b,P!==void 0&&(Y[1]=P,k!==void 0&&(Y[2]=k))),Y}let n=t;function e(b,P,k,Y){let J=Y??new r(3);return J[0]=b,J[1]=P,J[2]=k,J}function o(b,P){let k=P??new r(3);return k[0]=Math.ceil(b[0]),k[1]=Math.ceil(b[1]),k[2]=Math.ceil(b[2]),k}function i(b,P){let k=P??new r(3);return k[0]=Math.floor(b[0]),k[1]=Math.floor(b[1]),k[2]=Math.floor(b[2]),k}function a(b,P){let k=P??new r(3);return k[0]=Math.round(b[0]),k[1]=Math.round(b[1]),k[2]=Math.round(b[2]),k}function u(b,P=0,k=1,Y){let J=Y??new r(3);return J[0]=Math.min(k,Math.max(P,b[0])),J[1]=Math.min(k,Math.max(P,b[1])),J[2]=Math.min(k,Math.max(P,b[2])),J}function s(b,P,k){let Y=k??new r(3);return Y[0]=b[0]+P[0],Y[1]=b[1]+P[1],Y[2]=b[2]+P[2],Y}function l(b,P,k,Y){let J=Y??new r(3);return J[0]=b[0]+P[0]*k,J[1]=b[1]+P[1]*k,J[2]=b[2]+P[2]*k,J}function p(b,P){let k=b[0],Y=b[1],J=b[2],nt=P[0],tt=P[1],ft=P[2],wt=Math.sqrt(k*k+Y*Y+J*J),lt=Math.sqrt(nt*nt+tt*tt+ft*ft),ht=wt*lt,yt=ht&&X(b,P)/ht;return Math.acos(yt)}function _(b,P,k){let Y=k??new r(3);return Y[0]=b[0]-P[0],Y[1]=b[1]-P[1],Y[2]=b[2]-P[2],Y}let F=_;function z(b,P){return Math.abs(b[0]-P[0])<Mt&&Math.abs(b[1]-P[1])<Mt&&Math.abs(b[2]-P[2])<Mt}function I(b,P){return b[0]===P[0]&&b[1]===P[1]&&b[2]===P[2]}function m(b,P,k,Y){let J=Y??new r(3);return J[0]=b[0]+k*(P[0]-b[0]),J[1]=b[1]+k*(P[1]-b[1]),J[2]=b[2]+k*(P[2]-b[2]),J}function L(b,P,k,Y){let J=Y??new r(3);return J[0]=b[0]+k[0]*(P[0]-b[0]),J[1]=b[1]+k[1]*(P[1]-b[1]),J[2]=b[2]+k[2]*(P[2]-b[2]),J}function W(b,P,k){let Y=k??new r(3);return Y[0]=Math.max(b[0],P[0]),Y[1]=Math.max(b[1],P[1]),Y[2]=Math.max(b[2],P[2]),Y}function V(b,P,k){let Y=k??new r(3);return Y[0]=Math.min(b[0],P[0]),Y[1]=Math.min(b[1],P[1]),Y[2]=Math.min(b[2],P[2]),Y}function H(b,P,k){let Y=k??new r(3);return Y[0]=b[0]*P,Y[1]=b[1]*P,Y[2]=b[2]*P,Y}let $=H;function Z(b,P,k){let Y=k??new r(3);return Y[0]=b[0]/P,Y[1]=b[1]/P,Y[2]=b[2]/P,Y}function Q(b,P){let k=P??new r(3);return k[0]=1/b[0],k[1]=1/b[1],k[2]=1/b[2],k}let it=Q;function et(b,P,k){let Y=k??new r(3),J=b[2]*P[0]-b[0]*P[2],nt=b[0]*P[1]-b[1]*P[0];return Y[0]=b[1]*P[2]-b[2]*P[1],Y[1]=J,Y[2]=nt,Y}function X(b,P){return b[0]*P[0]+b[1]*P[1]+b[2]*P[2]}function j(b){let P=b[0],k=b[1],Y=b[2];return Math.sqrt(P*P+k*k+Y*Y)}let E=j;function c(b){let P=b[0],k=b[1],Y=b[2];return P*P+k*k+Y*Y}let w=c;function M(b,P){let k=b[0]-P[0],Y=b[1]-P[1],J=b[2]-P[2];return Math.sqrt(k*k+Y*Y+J*J)}let B=M;function S(b,P){let k=b[0]-P[0],Y=b[1]-P[1],J=b[2]-P[2];return k*k+Y*Y+J*J}let O=S;function N(b,P){let k=P??new r(3),Y=b[0],J=b[1],nt=b[2],tt=Math.sqrt(Y*Y+J*J+nt*nt);return tt>1e-5?(k[0]=Y/tt,k[1]=J/tt,k[2]=nt/tt):(k[0]=0,k[1]=0,k[2]=0),k}function A(b,P){let k=P??new r(3);return k[0]=-b[0],k[1]=-b[1],k[2]=-b[2],k}function h(b,P){let k=P??new r(3);return k[0]=b[0],k[1]=b[1],k[2]=b[2],k}let D=h;function ot(b,P,k){let Y=k??new r(3);return Y[0]=b[0]*P[0],Y[1]=b[1]*P[1],Y[2]=b[2]*P[2],Y}let ct=ot;function st(b,P,k){let Y=k??new r(3);return Y[0]=b[0]/P[0],Y[1]=b[1]/P[1],Y[2]=b[2]/P[2],Y}let vt=st;function pt(b=1,P){let k=P??new r(3),Y=Math.random()*2*Math.PI,J=Math.random()*2-1,nt=Math.sqrt(1-J*J)*b;return k[0]=Math.cos(Y)*nt,k[1]=Math.sin(Y)*nt,k[2]=J*b,k}function d(b){let P=b??new r(3);return P[0]=0,P[1]=0,P[2]=0,P}function G(b,P,k){let Y=k??new r(3),J=b[0],nt=b[1],tt=b[2],ft=P[3]*J+P[7]*nt+P[11]*tt+P[15]||1;return Y[0]=(P[0]*J+P[4]*nt+P[8]*tt+P[12])/ft,Y[1]=(P[1]*J+P[5]*nt+P[9]*tt+P[13])/ft,Y[2]=(P[2]*J+P[6]*nt+P[10]*tt+P[14])/ft,Y}function g(b,P,k){let Y=k??new r(3),J=b[0],nt=b[1],tt=b[2];return Y[0]=J*P[0*4+0]+nt*P[1*4+0]+tt*P[2*4+0],Y[1]=J*P[0*4+1]+nt*P[1*4+1]+tt*P[2*4+1],Y[2]=J*P[0*4+2]+nt*P[1*4+2]+tt*P[2*4+2],Y}function y(b,P,k){let Y=k??new r(3),J=b[0],nt=b[1],tt=b[2];return Y[0]=J*P[0]+nt*P[4]+tt*P[8],Y[1]=J*P[1]+nt*P[5]+tt*P[9],Y[2]=J*P[2]+nt*P[6]+tt*P[10],Y}function R(b,P,k){let Y=k??new r(3),J=P[0],nt=P[1],tt=P[2],ft=P[3]*2,wt=b[0],lt=b[1],ht=b[2],yt=nt*ht-tt*lt,gt=tt*wt-J*ht,dt=J*lt-nt*wt;return Y[0]=wt+yt*ft+(nt*dt-tt*gt)*2,Y[1]=lt+gt*ft+(tt*yt-J*dt)*2,Y[2]=ht+dt*ft+(J*gt-nt*yt)*2,Y}function C(b,P){let k=P??new r(3);return k[0]=b[12],k[1]=b[13],k[2]=b[14],k}function K(b,P,k){let Y=k??new r(3),J=P*4;return Y[0]=b[J+0],Y[1]=b[J+1],Y[2]=b[J+2],Y}function f(b,P){let k=P??new r(3),Y=b[0],J=b[1],nt=b[2],tt=b[4],ft=b[5],wt=b[6],lt=b[8],ht=b[9],yt=b[10];return k[0]=Math.sqrt(Y*Y+J*J+nt*nt),k[1]=Math.sqrt(tt*tt+ft*ft+wt*wt),k[2]=Math.sqrt(lt*lt+ht*ht+yt*yt),k}function T(b,P,k,Y){let J=Y??new r(3),nt=[],tt=[];return nt[0]=b[0]-P[0],nt[1]=b[1]-P[1],nt[2]=b[2]-P[2],tt[0]=nt[0],tt[1]=nt[1]*Math.cos(k)-nt[2]*Math.sin(k),tt[2]=nt[1]*Math.sin(k)+nt[2]*Math.cos(k),J[0]=tt[0]+P[0],J[1]=tt[1]+P[1],J[2]=tt[2]+P[2],J}function v(b,P,k,Y){let J=Y??new r(3),nt=[],tt=[];return nt[0]=b[0]-P[0],nt[1]=b[1]-P[1],nt[2]=b[2]-P[2],tt[0]=nt[2]*Math.sin(k)+nt[0]*Math.cos(k),tt[1]=nt[1],tt[2]=nt[2]*Math.cos(k)-nt[0]*Math.sin(k),J[0]=tt[0]+P[0],J[1]=tt[1]+P[1],J[2]=tt[2]+P[2],J}function x(b,P,k,Y){let J=Y??new r(3),nt=[],tt=[];return nt[0]=b[0]-P[0],nt[1]=b[1]-P[1],nt[2]=b[2]-P[2],tt[0]=nt[0]*Math.cos(k)-nt[1]*Math.sin(k),tt[1]=nt[0]*Math.sin(k)+nt[1]*Math.cos(k),tt[2]=nt[2],J[0]=tt[0]+P[0],J[1]=tt[1]+P[1],J[2]=tt[2]+P[2],J}function U(b,P,k){let Y=k??new r(3);return N(b,Y),H(Y,P,Y)}function q(b,P,k){let Y=k??new r(3);return j(b)>P?U(b,P,Y):h(b,Y)}function rt(b,P,k){let Y=k??new r(3);return m(b,P,.5,Y)}return{create:t,fromValues:n,set:e,ceil:o,floor:i,round:a,clamp:u,add:s,addScaled:l,angle:p,subtract:_,sub:F,equalsApproximately:z,equals:I,lerp:m,lerpV:L,max:W,min:V,mulScalar:H,scale:$,divScalar:Z,inverse:Q,invert:it,cross:et,dot:X,length:j,len:E,lengthSq:c,lenSq:w,distance:M,dist:B,distanceSq:S,distSq:O,normalize:N,negate:A,copy:h,clone:D,multiply:ot,mul:ct,divide:st,div:vt,random:pt,zero:d,transformMat4:G,transformMat4Upper3x3:g,transformMat3:y,transformQuat:R,getTranslation:C,getAxis:K,getScaling:f,rotateX:T,rotateY:v,rotateZ:x,setLength:U,truncate:q,midpoint:rt}}var Gi=new Map;function Te(r){let t=Gi.get(r);return t||(t=rs(r),Gi.set(r,t)),t}function es(r){let t=Ni(r),n=Te(r);function e(d,G,g,y,R,C,K,f,T){let v=new r(12);return v[3]=0,v[7]=0,v[11]=0,d!==void 0&&(v[0]=d,G!==void 0&&(v[1]=G,g!==void 0&&(v[2]=g,y!==void 0&&(v[4]=y,R!==void 0&&(v[5]=R,C!==void 0&&(v[6]=C,K!==void 0&&(v[8]=K,f!==void 0&&(v[9]=f,T!==void 0&&(v[10]=T))))))))),v}function o(d,G,g,y,R,C,K,f,T,v){let x=v??new r(12);return x[0]=d,x[1]=G,x[2]=g,x[3]=0,x[4]=y,x[5]=R,x[6]=C,x[7]=0,x[8]=K,x[9]=f,x[10]=T,x[11]=0,x}function i(d,G){let g=G??new r(12);return g[0]=d[0],g[1]=d[1],g[2]=d[2],g[3]=0,g[4]=d[4],g[5]=d[5],g[6]=d[6],g[7]=0,g[8]=d[8],g[9]=d[9],g[10]=d[10],g[11]=0,g}function a(d,G){let g=G??new r(12),y=d[0],R=d[1],C=d[2],K=d[3],f=y+y,T=R+R,v=C+C,x=y*f,U=R*f,q=R*T,rt=C*f,b=C*T,P=C*v,k=K*f,Y=K*T,J=K*v;return g[0]=1-q-P,g[1]=U+J,g[2]=rt-Y,g[3]=0,g[4]=U-J,g[5]=1-x-P,g[6]=b+k,g[7]=0,g[8]=rt+Y,g[9]=b-k,g[10]=1-x-q,g[11]=0,g}function u(d,G){let g=G??new r(12);return g[0]=-d[0],g[1]=-d[1],g[2]=-d[2],g[4]=-d[4],g[5]=-d[5],g[6]=-d[6],g[8]=-d[8],g[9]=-d[9],g[10]=-d[10],g}function s(d,G){let g=G??new r(12);return g[0]=d[0],g[1]=d[1],g[2]=d[2],g[4]=d[4],g[5]=d[5],g[6]=d[6],g[8]=d[8],g[9]=d[9],g[10]=d[10],g}let l=s;function p(d,G){return Math.abs(d[0]-G[0])<Mt&&Math.abs(d[1]-G[1])<Mt&&Math.abs(d[2]-G[2])<Mt&&Math.abs(d[4]-G[4])<Mt&&Math.abs(d[5]-G[5])<Mt&&Math.abs(d[6]-G[6])<Mt&&Math.abs(d[8]-G[8])<Mt&&Math.abs(d[9]-G[9])<Mt&&Math.abs(d[10]-G[10])<Mt}function _(d,G){return d[0]===G[0]&&d[1]===G[1]&&d[2]===G[2]&&d[4]===G[4]&&d[5]===G[5]&&d[6]===G[6]&&d[8]===G[8]&&d[9]===G[9]&&d[10]===G[10]}function F(d){let G=d??new r(12);return G[0]=1,G[1]=0,G[2]=0,G[4]=0,G[5]=1,G[6]=0,G[8]=0,G[9]=0,G[10]=1,G}function z(d,G){let g=G??new r(12);if(g===d){let q;return q=d[1],d[1]=d[4],d[4]=q,q=d[2],d[2]=d[8],d[8]=q,q=d[6],d[6]=d[9],d[9]=q,g}let y=d[0*4+0],R=d[0*4+1],C=d[0*4+2],K=d[1*4+0],f=d[1*4+1],T=d[1*4+2],v=d[2*4+0],x=d[2*4+1],U=d[2*4+2];return g[0]=y,g[1]=K,g[2]=v,g[4]=R,g[5]=f,g[6]=x,g[8]=C,g[9]=T,g[10]=U,g}function I(d,G){let g=G??new r(12),y=d[0*4+0],R=d[0*4+1],C=d[0*4+2],K=d[1*4+0],f=d[1*4+1],T=d[1*4+2],v=d[2*4+0],x=d[2*4+1],U=d[2*4+2],q=U*f-T*x,rt=-U*K+T*v,b=x*K-f*v,P=1/(y*q+R*rt+C*b);return g[0]=q*P,g[1]=(-U*R+C*x)*P,g[2]=(T*R-C*f)*P,g[4]=rt*P,g[5]=(U*y-C*v)*P,g[6]=(-T*y+C*K)*P,g[8]=b*P,g[9]=(-x*y+R*v)*P,g[10]=(f*y-R*K)*P,g}function m(d){let G=d[0],g=d[0*4+1],y=d[0*4+2],R=d[1*4+0],C=d[1*4+1],K=d[1*4+2],f=d[2*4+0],T=d[2*4+1],v=d[2*4+2];return G*(C*v-T*K)-R*(g*v-T*y)+f*(g*K-C*y)}let L=I;function W(d,G,g){let y=g??new r(12),R=d[0],C=d[1],K=d[2],f=d[4],T=d[5],v=d[6],x=d[8],U=d[9],q=d[10],rt=G[0],b=G[1],P=G[2],k=G[4],Y=G[5],J=G[6],nt=G[8],tt=G[9],ft=G[10];return y[0]=R*rt+f*b+x*P,y[1]=C*rt+T*b+U*P,y[2]=K*rt+v*b+q*P,y[4]=R*k+f*Y+x*J,y[5]=C*k+T*Y+U*J,y[6]=K*k+v*Y+q*J,y[8]=R*nt+f*tt+x*ft,y[9]=C*nt+T*tt+U*ft,y[10]=K*nt+v*tt+q*ft,y}let V=W;function H(d,G,g){let y=g??F();return d!==y&&(y[0]=d[0],y[1]=d[1],y[2]=d[2],y[4]=d[4],y[5]=d[5],y[6]=d[6]),y[8]=G[0],y[9]=G[1],y[10]=1,y}function $(d,G){let g=G??t.create();return g[0]=d[8],g[1]=d[9],g}function Z(d,G,g){let y=g??t.create(),R=G*4;return y[0]=d[R+0],y[1]=d[R+1],y}function Q(d,G,g,y){let R=y===d?d:s(d,y),C=g*4;return R[C+0]=G[0],R[C+1]=G[1],R}function it(d,G){let g=G??t.create(),y=d[0],R=d[1],C=d[4],K=d[5];return g[0]=Math.sqrt(y*y+R*R),g[1]=Math.sqrt(C*C+K*K),g}function et(d,G){let g=G??n.create(),y=d[0],R=d[1],C=d[2],K=d[4],f=d[5],T=d[6],v=d[8],x=d[9],U=d[10];return g[0]=Math.sqrt(y*y+R*R+C*C),g[1]=Math.sqrt(K*K+f*f+T*T),g[2]=Math.sqrt(v*v+x*x+U*U),g}function X(d,G){let g=G??new r(12);return g[0]=1,g[1]=0,g[2]=0,g[4]=0,g[5]=1,g[6]=0,g[8]=d[0],g[9]=d[1],g[10]=1,g}function j(d,G,g){let y=g??new r(12),R=G[0],C=G[1],K=d[0],f=d[1],T=d[2],v=d[1*4+0],x=d[1*4+1],U=d[1*4+2],q=d[2*4+0],rt=d[2*4+1],b=d[2*4+2];return d!==y&&(y[0]=K,y[1]=f,y[2]=T,y[4]=v,y[5]=x,y[6]=U),y[8]=K*R+v*C+q,y[9]=f*R+x*C+rt,y[10]=T*R+U*C+b,y}function E(d,G){let g=G??new r(12),y=Math.cos(d),R=Math.sin(d);return g[0]=y,g[1]=R,g[2]=0,g[4]=-R,g[5]=y,g[6]=0,g[8]=0,g[9]=0,g[10]=1,g}function c(d,G,g){let y=g??new r(12),R=d[0*4+0],C=d[0*4+1],K=d[0*4+2],f=d[1*4+0],T=d[1*4+1],v=d[1*4+2],x=Math.cos(G),U=Math.sin(G);return y[0]=x*R+U*f,y[1]=x*C+U*T,y[2]=x*K+U*v,y[4]=x*f-U*R,y[5]=x*T-U*C,y[6]=x*v-U*K,d!==y&&(y[8]=d[8],y[9]=d[9],y[10]=d[10]),y}function w(d,G){let g=G??new r(12),y=Math.cos(d),R=Math.sin(d);return g[0]=1,g[1]=0,g[2]=0,g[4]=0,g[5]=y,g[6]=R,g[8]=0,g[9]=-R,g[10]=y,g}function M(d,G,g){let y=g??new r(12),R=d[4],C=d[5],K=d[6],f=d[8],T=d[9],v=d[10],x=Math.cos(G),U=Math.sin(G);return y[4]=x*R+U*f,y[5]=x*C+U*T,y[6]=x*K+U*v,y[8]=x*f-U*R,y[9]=x*T-U*C,y[10]=x*v-U*K,d!==y&&(y[0]=d[0],y[1]=d[1],y[2]=d[2]),y}function B(d,G){let g=G??new r(12),y=Math.cos(d),R=Math.sin(d);return g[0]=y,g[1]=0,g[2]=-R,g[4]=0,g[5]=1,g[6]=0,g[8]=R,g[9]=0,g[10]=y,g}function S(d,G,g){let y=g??new r(12),R=d[0*4+0],C=d[0*4+1],K=d[0*4+2],f=d[2*4+0],T=d[2*4+1],v=d[2*4+2],x=Math.cos(G),U=Math.sin(G);return y[0]=x*R-U*f,y[1]=x*C-U*T,y[2]=x*K-U*v,y[8]=x*f+U*R,y[9]=x*T+U*C,y[10]=x*v+U*K,d!==y&&(y[4]=d[4],y[5]=d[5],y[6]=d[6]),y}let O=E,N=c;function A(d,G){let g=G??new r(12);return g[0]=d[0],g[1]=0,g[2]=0,g[4]=0,g[5]=d[1],g[6]=0,g[8]=0,g[9]=0,g[10]=1,g}function h(d,G,g){let y=g??new r(12),R=G[0],C=G[1];return y[0]=R*d[0*4+0],y[1]=R*d[0*4+1],y[2]=R*d[0*4+2],y[4]=C*d[1*4+0],y[5]=C*d[1*4+1],y[6]=C*d[1*4+2],d!==y&&(y[8]=d[8],y[9]=d[9],y[10]=d[10]),y}function D(d,G){let g=G??new r(12);return g[0]=d[0],g[1]=0,g[2]=0,g[4]=0,g[5]=d[1],g[6]=0,g[8]=0,g[9]=0,g[10]=d[2],g}function ot(d,G,g){let y=g??new r(12),R=G[0],C=G[1],K=G[2];return y[0]=R*d[0*4+0],y[1]=R*d[0*4+1],y[2]=R*d[0*4+2],y[4]=C*d[1*4+0],y[5]=C*d[1*4+1],y[6]=C*d[1*4+2],y[8]=K*d[2*4+0],y[9]=K*d[2*4+1],y[10]=K*d[2*4+2],y}function ct(d,G){let g=G??new r(12);return g[0]=d,g[1]=0,g[2]=0,g[4]=0,g[5]=d,g[6]=0,g[8]=0,g[9]=0,g[10]=1,g}function st(d,G,g){let y=g??new r(12);return y[0]=G*d[0*4+0],y[1]=G*d[0*4+1],y[2]=G*d[0*4+2],y[4]=G*d[1*4+0],y[5]=G*d[1*4+1],y[6]=G*d[1*4+2],d!==y&&(y[8]=d[8],y[9]=d[9],y[10]=d[10]),y}function vt(d,G){let g=G??new r(12);return g[0]=d,g[1]=0,g[2]=0,g[4]=0,g[5]=d,g[6]=0,g[8]=0,g[9]=0,g[10]=d,g}function pt(d,G,g){let y=g??new r(12);return y[0]=G*d[0*4+0],y[1]=G*d[0*4+1],y[2]=G*d[0*4+2],y[4]=G*d[1*4+0],y[5]=G*d[1*4+1],y[6]=G*d[1*4+2],y[8]=G*d[2*4+0],y[9]=G*d[2*4+1],y[10]=G*d[2*4+2],y}return{clone:l,create:e,set:o,fromMat4:i,fromQuat:a,negate:u,copy:s,equalsApproximately:p,equals:_,identity:F,transpose:z,inverse:I,invert:L,determinant:m,mul:V,multiply:W,setTranslation:H,getTranslation:$,getAxis:Z,setAxis:Q,getScaling:it,get3DScaling:et,translation:X,translate:j,rotation:E,rotate:c,rotationX:w,rotateX:M,rotationY:B,rotateY:S,rotationZ:O,rotateZ:N,scaling:A,scale:h,uniformScaling:ct,uniformScale:st,scaling3D:D,scale3D:ot,uniformScaling3D:vt,uniformScale3D:pt}}var Fi=new Map;function ns(r){let t=Fi.get(r);return t||(t=es(r),Fi.set(r,t)),t}function is(r){let t=Te(r);function n(f,T,v,x,U,q,rt,b,P,k,Y,J,nt,tt,ft,wt){let lt=new r(16);return f!==void 0&&(lt[0]=f,T!==void 0&&(lt[1]=T,v!==void 0&&(lt[2]=v,x!==void 0&&(lt[3]=x,U!==void 0&&(lt[4]=U,q!==void 0&&(lt[5]=q,rt!==void 0&&(lt[6]=rt,b!==void 0&&(lt[7]=b,P!==void 0&&(lt[8]=P,k!==void 0&&(lt[9]=k,Y!==void 0&&(lt[10]=Y,J!==void 0&&(lt[11]=J,nt!==void 0&&(lt[12]=nt,tt!==void 0&&(lt[13]=tt,ft!==void 0&&(lt[14]=ft,wt!==void 0&&(lt[15]=wt)))))))))))))))),lt}function e(f,T,v,x,U,q,rt,b,P,k,Y,J,nt,tt,ft,wt,lt){let ht=lt??new r(16);return ht[0]=f,ht[1]=T,ht[2]=v,ht[3]=x,ht[4]=U,ht[5]=q,ht[6]=rt,ht[7]=b,ht[8]=P,ht[9]=k,ht[10]=Y,ht[11]=J,ht[12]=nt,ht[13]=tt,ht[14]=ft,ht[15]=wt,ht}function o(f,T){let v=T??new r(16);return v[0]=f[0],v[1]=f[1],v[2]=f[2],v[3]=0,v[4]=f[4],v[5]=f[5],v[6]=f[6],v[7]=0,v[8]=f[8],v[9]=f[9],v[10]=f[10],v[11]=0,v[12]=0,v[13]=0,v[14]=0,v[15]=1,v}function i(f,T){let v=T??new r(16),x=f[0],U=f[1],q=f[2],rt=f[3],b=x+x,P=U+U,k=q+q,Y=x*b,J=U*b,nt=U*P,tt=q*b,ft=q*P,wt=q*k,lt=rt*b,ht=rt*P,yt=rt*k;return v[0]=1-nt-wt,v[1]=J+yt,v[2]=tt-ht,v[3]=0,v[4]=J-yt,v[5]=1-Y-wt,v[6]=ft+lt,v[7]=0,v[8]=tt+ht,v[9]=ft-lt,v[10]=1-Y-nt,v[11]=0,v[12]=0,v[13]=0,v[14]=0,v[15]=1,v}function a(f,T){let v=T??new r(16);return v[0]=-f[0],v[1]=-f[1],v[2]=-f[2],v[3]=-f[3],v[4]=-f[4],v[5]=-f[5],v[6]=-f[6],v[7]=-f[7],v[8]=-f[8],v[9]=-f[9],v[10]=-f[10],v[11]=-f[11],v[12]=-f[12],v[13]=-f[13],v[14]=-f[14],v[15]=-f[15],v}function u(f,T){let v=T??new r(16);return v[0]=f[0],v[1]=f[1],v[2]=f[2],v[3]=f[3],v[4]=f[4],v[5]=f[5],v[6]=f[6],v[7]=f[7],v[8]=f[8],v[9]=f[9],v[10]=f[10],v[11]=f[11],v[12]=f[12],v[13]=f[13],v[14]=f[14],v[15]=f[15],v}let s=u;function l(f,T){return Math.abs(f[0]-T[0])<Mt&&Math.abs(f[1]-T[1])<Mt&&Math.abs(f[2]-T[2])<Mt&&Math.abs(f[3]-T[3])<Mt&&Math.abs(f[4]-T[4])<Mt&&Math.abs(f[5]-T[5])<Mt&&Math.abs(f[6]-T[6])<Mt&&Math.abs(f[7]-T[7])<Mt&&Math.abs(f[8]-T[8])<Mt&&Math.abs(f[9]-T[9])<Mt&&Math.abs(f[10]-T[10])<Mt&&Math.abs(f[11]-T[11])<Mt&&Math.abs(f[12]-T[12])<Mt&&Math.abs(f[13]-T[13])<Mt&&Math.abs(f[14]-T[14])<Mt&&Math.abs(f[15]-T[15])<Mt}function p(f,T){return f[0]===T[0]&&f[1]===T[1]&&f[2]===T[2]&&f[3]===T[3]&&f[4]===T[4]&&f[5]===T[5]&&f[6]===T[6]&&f[7]===T[7]&&f[8]===T[8]&&f[9]===T[9]&&f[10]===T[10]&&f[11]===T[11]&&f[12]===T[12]&&f[13]===T[13]&&f[14]===T[14]&&f[15]===T[15]}function _(f){let T=f??new r(16);return T[0]=1,T[1]=0,T[2]=0,T[3]=0,T[4]=0,T[5]=1,T[6]=0,T[7]=0,T[8]=0,T[9]=0,T[10]=1,T[11]=0,T[12]=0,T[13]=0,T[14]=0,T[15]=1,T}function F(f,T){let v=T??new r(16);if(v===f){let gt;return gt=f[1],f[1]=f[4],f[4]=gt,gt=f[2],f[2]=f[8],f[8]=gt,gt=f[3],f[3]=f[12],f[12]=gt,gt=f[6],f[6]=f[9],f[9]=gt,gt=f[7],f[7]=f[13],f[13]=gt,gt=f[11],f[11]=f[14],f[14]=gt,v}let x=f[0*4+0],U=f[0*4+1],q=f[0*4+2],rt=f[0*4+3],b=f[1*4+0],P=f[1*4+1],k=f[1*4+2],Y=f[1*4+3],J=f[2*4+0],nt=f[2*4+1],tt=f[2*4+2],ft=f[2*4+3],wt=f[3*4+0],lt=f[3*4+1],ht=f[3*4+2],yt=f[3*4+3];return v[0]=x,v[1]=b,v[2]=J,v[3]=wt,v[4]=U,v[5]=P,v[6]=nt,v[7]=lt,v[8]=q,v[9]=k,v[10]=tt,v[11]=ht,v[12]=rt,v[13]=Y,v[14]=ft,v[15]=yt,v}function z(f,T){let v=T??new r(16),x=f[0*4+0],U=f[0*4+1],q=f[0*4+2],rt=f[0*4+3],b=f[1*4+0],P=f[1*4+1],k=f[1*4+2],Y=f[1*4+3],J=f[2*4+0],nt=f[2*4+1],tt=f[2*4+2],ft=f[2*4+3],wt=f[3*4+0],lt=f[3*4+1],ht=f[3*4+2],yt=f[3*4+3],gt=tt*yt,dt=ht*ft,qt=k*yt,xt=ht*Y,Tt=k*ft,kt=tt*Y,bt=q*yt,Bt=ht*rt,Xt=q*ft,Et=tt*rt,Ut=q*Y,Ht=k*rt,At=J*lt,Pt=wt*nt,Kt=b*lt,mt=wt*P,Rt=b*nt,Rr=J*P,Gt=x*lt,Ft=wt*U,Lr=x*nt,zt=J*U,Ot=x*P,Gr=b*U,Ct=gt*P+xt*nt+Tt*lt-(dt*P+qt*nt+kt*lt),Nt=dt*U+bt*nt+Et*lt-(gt*U+Bt*nt+Xt*lt),ee=qt*U+Bt*P+Ut*lt-(xt*U+bt*P+Ht*lt),Vt=kt*U+Xt*P+Ht*nt-(Tt*U+Et*P+Ut*nt),St=1/(x*Ct+b*Nt+J*ee+wt*Vt);return v[0]=St*Ct,v[1]=St*Nt,v[2]=St*ee,v[3]=St*Vt,v[4]=St*(dt*b+qt*J+kt*wt-(gt*b+xt*J+Tt*wt)),v[5]=St*(gt*x+Bt*J+Xt*wt-(dt*x+bt*J+Et*wt)),v[6]=St*(xt*x+bt*b+Ht*wt-(qt*x+Bt*b+Ut*wt)),v[7]=St*(Tt*x+Et*b+Ut*J-(kt*x+Xt*b+Ht*J)),v[8]=St*(At*Y+mt*ft+Rt*yt-(Pt*Y+Kt*ft+Rr*yt)),v[9]=St*(Pt*rt+Gt*ft+zt*yt-(At*rt+Ft*ft+Lr*yt)),v[10]=St*(Kt*rt+Ft*Y+Ot*yt-(mt*rt+Gt*Y+Gr*yt)),v[11]=St*(Rr*rt+Lr*Y+Gr*ft-(Rt*rt+zt*Y+Ot*ft)),v[12]=St*(Kt*tt+Rr*ht+Pt*k-(Rt*ht+At*k+mt*tt)),v[13]=St*(Lr*ht+At*q+Ft*tt-(Gt*tt+zt*ht+Pt*q)),v[14]=St*(Gt*k+Gr*ht+mt*q-(Ot*ht+Kt*q+Ft*k)),v[15]=St*(Ot*tt+Rt*q+zt*k-(Lr*k+Gr*tt+Rr*q)),v}function I(f){let T=f[0],v=f[0*4+1],x=f[0*4+2],U=f[0*4+3],q=f[1*4+0],rt=f[1*4+1],b=f[1*4+2],P=f[1*4+3],k=f[2*4+0],Y=f[2*4+1],J=f[2*4+2],nt=f[2*4+3],tt=f[3*4+0],ft=f[3*4+1],wt=f[3*4+2],lt=f[3*4+3],ht=J*lt,yt=wt*nt,gt=b*lt,dt=wt*P,qt=b*nt,xt=J*P,Tt=x*lt,kt=wt*U,bt=x*nt,Bt=J*U,Xt=x*P,Et=b*U,Ut=ht*rt+dt*Y+qt*ft-(yt*rt+gt*Y+xt*ft),Ht=yt*v+Tt*Y+Bt*ft-(ht*v+kt*Y+bt*ft),At=gt*v+kt*rt+Xt*ft-(dt*v+Tt*rt+Et*ft),Pt=xt*v+bt*rt+Et*Y-(qt*v+Bt*rt+Xt*Y);return T*Ut+q*Ht+k*At+tt*Pt}let m=z;function L(f,T,v){let x=v??new r(16),U=f[0],q=f[1],rt=f[2],b=f[3],P=f[4],k=f[5],Y=f[6],J=f[7],nt=f[8],tt=f[9],ft=f[10],wt=f[11],lt=f[12],ht=f[13],yt=f[14],gt=f[15],dt=T[0],qt=T[1],xt=T[2],Tt=T[3],kt=T[4],bt=T[5],Bt=T[6],Xt=T[7],Et=T[8],Ut=T[9],Ht=T[10],At=T[11],Pt=T[12],Kt=T[13],mt=T[14],Rt=T[15];return x[0]=U*dt+P*qt+nt*xt+lt*Tt,x[1]=q*dt+k*qt+tt*xt+ht*Tt,x[2]=rt*dt+Y*qt+ft*xt+yt*Tt,x[3]=b*dt+J*qt+wt*xt+gt*Tt,x[4]=U*kt+P*bt+nt*Bt+lt*Xt,x[5]=q*kt+k*bt+tt*Bt+ht*Xt,x[6]=rt*kt+Y*bt+ft*Bt+yt*Xt,x[7]=b*kt+J*bt+wt*Bt+gt*Xt,x[8]=U*Et+P*Ut+nt*Ht+lt*At,x[9]=q*Et+k*Ut+tt*Ht+ht*At,x[10]=rt*Et+Y*Ut+ft*Ht+yt*At,x[11]=b*Et+J*Ut+wt*Ht+gt*At,x[12]=U*Pt+P*Kt+nt*mt+lt*Rt,x[13]=q*Pt+k*Kt+tt*mt+ht*Rt,x[14]=rt*Pt+Y*Kt+ft*mt+yt*Rt,x[15]=b*Pt+J*Kt+wt*mt+gt*Rt,x}let W=L;function V(f,T,v){let x=v??_();return f!==x&&(x[0]=f[0],x[1]=f[1],x[2]=f[2],x[3]=f[3],x[4]=f[4],x[5]=f[5],x[6]=f[6],x[7]=f[7],x[8]=f[8],x[9]=f[9],x[10]=f[10],x[11]=f[11]),x[12]=T[0],x[13]=T[1],x[14]=T[2],x[15]=1,x}function H(f,T){let v=T??t.create();return v[0]=f[12],v[1]=f[13],v[2]=f[14],v}function $(f,T,v){let x=v??t.create(),U=T*4;return x[0]=f[U+0],x[1]=f[U+1],x[2]=f[U+2],x}function Z(f,T,v,x){let U=x===f?x:u(f,x),q=v*4;return U[q+0]=T[0],U[q+1]=T[1],U[q+2]=T[2],U}function Q(f,T){let v=T??t.create(),x=f[0],U=f[1],q=f[2],rt=f[4],b=f[5],P=f[6],k=f[8],Y=f[9],J=f[10];return v[0]=Math.sqrt(x*x+U*U+q*q),v[1]=Math.sqrt(rt*rt+b*b+P*P),v[2]=Math.sqrt(k*k+Y*Y+J*J),v}function it(f,T,v,x,U){let q=U??new r(16),rt=Math.tan(Math.PI*.5-.5*f);if(q[0]=rt/T,q[1]=0,q[2]=0,q[3]=0,q[4]=0,q[5]=rt,q[6]=0,q[7]=0,q[8]=0,q[9]=0,q[11]=-1,q[12]=0,q[13]=0,q[15]=0,Number.isFinite(x)){let b=1/(v-x);q[10]=x*b,q[14]=x*v*b}else q[10]=-1,q[14]=-v;return q}function et(f,T,v,x=1/0,U){let q=U??new r(16),rt=1/Math.tan(f*.5);if(q[0]=rt/T,q[1]=0,q[2]=0,q[3]=0,q[4]=0,q[5]=rt,q[6]=0,q[7]=0,q[8]=0,q[9]=0,q[11]=-1,q[12]=0,q[13]=0,q[15]=0,x===1/0)q[10]=0,q[14]=v;else{let b=1/(x-v);q[10]=v*b,q[14]=x*v*b}return q}function X(f,T,v,x,U,q,rt){let b=rt??new r(16);return b[0]=2/(T-f),b[1]=0,b[2]=0,b[3]=0,b[4]=0,b[5]=2/(x-v),b[6]=0,b[7]=0,b[8]=0,b[9]=0,b[10]=1/(U-q),b[11]=0,b[12]=(T+f)/(f-T),b[13]=(x+v)/(v-x),b[14]=U/(U-q),b[15]=1,b}function j(f,T,v,x,U,q,rt){let b=rt??new r(16),P=T-f,k=x-v,Y=U-q;return b[0]=2*U/P,b[1]=0,b[2]=0,b[3]=0,b[4]=0,b[5]=2*U/k,b[6]=0,b[7]=0,b[8]=(f+T)/P,b[9]=(x+v)/k,b[10]=q/Y,b[11]=-1,b[12]=0,b[13]=0,b[14]=U*q/Y,b[15]=0,b}function E(f,T,v,x,U,q=1/0,rt){let b=rt??new r(16),P=T-f,k=x-v;if(b[0]=2*U/P,b[1]=0,b[2]=0,b[3]=0,b[4]=0,b[5]=2*U/k,b[6]=0,b[7]=0,b[8]=(f+T)/P,b[9]=(x+v)/k,b[11]=-1,b[12]=0,b[13]=0,b[15]=0,q===1/0)b[10]=0,b[14]=U;else{let Y=1/(q-U);b[10]=U*Y,b[14]=q*U*Y}return b}let c=t.create(),w=t.create(),M=t.create();function B(f,T,v,x){let U=x??new r(16);return t.normalize(t.subtract(T,f,M),M),t.normalize(t.cross(v,M,c),c),t.normalize(t.cross(M,c,w),w),U[0]=c[0],U[1]=c[1],U[2]=c[2],U[3]=0,U[4]=w[0],U[5]=w[1],U[6]=w[2],U[7]=0,U[8]=M[0],U[9]=M[1],U[10]=M[2],U[11]=0,U[12]=f[0],U[13]=f[1],U[14]=f[2],U[15]=1,U}function S(f,T,v,x){let U=x??new r(16);return t.normalize(t.subtract(f,T,M),M),t.normalize(t.cross(v,M,c),c),t.normalize(t.cross(M,c,w),w),U[0]=c[0],U[1]=c[1],U[2]=c[2],U[3]=0,U[4]=w[0],U[5]=w[1],U[6]=w[2],U[7]=0,U[8]=M[0],U[9]=M[1],U[10]=M[2],U[11]=0,U[12]=f[0],U[13]=f[1],U[14]=f[2],U[15]=1,U}function O(f,T,v,x){let U=x??new r(16);return t.normalize(t.subtract(f,T,M),M),t.normalize(t.cross(v,M,c),c),t.normalize(t.cross(M,c,w),w),U[0]=c[0],U[1]=w[0],U[2]=M[0],U[3]=0,U[4]=c[1],U[5]=w[1],U[6]=M[1],U[7]=0,U[8]=c[2],U[9]=w[2],U[10]=M[2],U[11]=0,U[12]=-(c[0]*f[0]+c[1]*f[1]+c[2]*f[2]),U[13]=-(w[0]*f[0]+w[1]*f[1]+w[2]*f[2]),U[14]=-(M[0]*f[0]+M[1]*f[1]+M[2]*f[2]),U[15]=1,U}function N(f,T){let v=T??new r(16);return v[0]=1,v[1]=0,v[2]=0,v[3]=0,v[4]=0,v[5]=1,v[6]=0,v[7]=0,v[8]=0,v[9]=0,v[10]=1,v[11]=0,v[12]=f[0],v[13]=f[1],v[14]=f[2],v[15]=1,v}function A(f,T,v){let x=v??new r(16),U=T[0],q=T[1],rt=T[2],b=f[0],P=f[1],k=f[2],Y=f[3],J=f[1*4+0],nt=f[1*4+1],tt=f[1*4+2],ft=f[1*4+3],wt=f[2*4+0],lt=f[2*4+1],ht=f[2*4+2],yt=f[2*4+3],gt=f[3*4+0],dt=f[3*4+1],qt=f[3*4+2],xt=f[3*4+3];return f!==x&&(x[0]=b,x[1]=P,x[2]=k,x[3]=Y,x[4]=J,x[5]=nt,x[6]=tt,x[7]=ft,x[8]=wt,x[9]=lt,x[10]=ht,x[11]=yt),x[12]=b*U+J*q+wt*rt+gt,x[13]=P*U+nt*q+lt*rt+dt,x[14]=k*U+tt*q+ht*rt+qt,x[15]=Y*U+ft*q+yt*rt+xt,x}function h(f,T){let v=T??new r(16),x=Math.cos(f),U=Math.sin(f);return v[0]=1,v[1]=0,v[2]=0,v[3]=0,v[4]=0,v[5]=x,v[6]=U,v[7]=0,v[8]=0,v[9]=-U,v[10]=x,v[11]=0,v[12]=0,v[13]=0,v[14]=0,v[15]=1,v}function D(f,T,v){let x=v??new r(16),U=f[4],q=f[5],rt=f[6],b=f[7],P=f[8],k=f[9],Y=f[10],J=f[11],nt=Math.cos(T),tt=Math.sin(T);return x[4]=nt*U+tt*P,x[5]=nt*q+tt*k,x[6]=nt*rt+tt*Y,x[7]=nt*b+tt*J,x[8]=nt*P-tt*U,x[9]=nt*k-tt*q,x[10]=nt*Y-tt*rt,x[11]=nt*J-tt*b,f!==x&&(x[0]=f[0],x[1]=f[1],x[2]=f[2],x[3]=f[3],x[12]=f[12],x[13]=f[13],x[14]=f[14],x[15]=f[15]),x}function ot(f,T){let v=T??new r(16),x=Math.cos(f),U=Math.sin(f);return v[0]=x,v[1]=0,v[2]=-U,v[3]=0,v[4]=0,v[5]=1,v[6]=0,v[7]=0,v[8]=U,v[9]=0,v[10]=x,v[11]=0,v[12]=0,v[13]=0,v[14]=0,v[15]=1,v}function ct(f,T,v){let x=v??new r(16),U=f[0*4+0],q=f[0*4+1],rt=f[0*4+2],b=f[0*4+3],P=f[2*4+0],k=f[2*4+1],Y=f[2*4+2],J=f[2*4+3],nt=Math.cos(T),tt=Math.sin(T);return x[0]=nt*U-tt*P,x[1]=nt*q-tt*k,x[2]=nt*rt-tt*Y,x[3]=nt*b-tt*J,x[8]=nt*P+tt*U,x[9]=nt*k+tt*q,x[10]=nt*Y+tt*rt,x[11]=nt*J+tt*b,f!==x&&(x[4]=f[4],x[5]=f[5],x[6]=f[6],x[7]=f[7],x[12]=f[12],x[13]=f[13],x[14]=f[14],x[15]=f[15]),x}function st(f,T){let v=T??new r(16),x=Math.cos(f),U=Math.sin(f);return v[0]=x,v[1]=U,v[2]=0,v[3]=0,v[4]=-U,v[5]=x,v[6]=0,v[7]=0,v[8]=0,v[9]=0,v[10]=1,v[11]=0,v[12]=0,v[13]=0,v[14]=0,v[15]=1,v}function vt(f,T,v){let x=v??new r(16),U=f[0*4+0],q=f[0*4+1],rt=f[0*4+2],b=f[0*4+3],P=f[1*4+0],k=f[1*4+1],Y=f[1*4+2],J=f[1*4+3],nt=Math.cos(T),tt=Math.sin(T);return x[0]=nt*U+tt*P,x[1]=nt*q+tt*k,x[2]=nt*rt+tt*Y,x[3]=nt*b+tt*J,x[4]=nt*P-tt*U,x[5]=nt*k-tt*q,x[6]=nt*Y-tt*rt,x[7]=nt*J-tt*b,f!==x&&(x[8]=f[8],x[9]=f[9],x[10]=f[10],x[11]=f[11],x[12]=f[12],x[13]=f[13],x[14]=f[14],x[15]=f[15]),x}function pt(f,T,v){let x=v??new r(16),U=f[0],q=f[1],rt=f[2],b=Math.sqrt(U*U+q*q+rt*rt);U/=b,q/=b,rt/=b;let P=U*U,k=q*q,Y=rt*rt,J=Math.cos(T),nt=Math.sin(T),tt=1-J;return x[0]=P+(1-P)*J,x[1]=U*q*tt+rt*nt,x[2]=U*rt*tt-q*nt,x[3]=0,x[4]=U*q*tt-rt*nt,x[5]=k+(1-k)*J,x[6]=q*rt*tt+U*nt,x[7]=0,x[8]=U*rt*tt+q*nt,x[9]=q*rt*tt-U*nt,x[10]=Y+(1-Y)*J,x[11]=0,x[12]=0,x[13]=0,x[14]=0,x[15]=1,x}let d=pt;function G(f,T,v,x){let U=x??new r(16),q=T[0],rt=T[1],b=T[2],P=Math.sqrt(q*q+rt*rt+b*b);q/=P,rt/=P,b/=P;let k=q*q,Y=rt*rt,J=b*b,nt=Math.cos(v),tt=Math.sin(v),ft=1-nt,wt=k+(1-k)*nt,lt=q*rt*ft+b*tt,ht=q*b*ft-rt*tt,yt=q*rt*ft-b*tt,gt=Y+(1-Y)*nt,dt=rt*b*ft+q*tt,qt=q*b*ft+rt*tt,xt=rt*b*ft-q*tt,Tt=J+(1-J)*nt,kt=f[0],bt=f[1],Bt=f[2],Xt=f[3],Et=f[4],Ut=f[5],Ht=f[6],At=f[7],Pt=f[8],Kt=f[9],mt=f[10],Rt=f[11];return U[0]=wt*kt+lt*Et+ht*Pt,U[1]=wt*bt+lt*Ut+ht*Kt,U[2]=wt*Bt+lt*Ht+ht*mt,U[3]=wt*Xt+lt*At+ht*Rt,U[4]=yt*kt+gt*Et+dt*Pt,U[5]=yt*bt+gt*Ut+dt*Kt,U[6]=yt*Bt+gt*Ht+dt*mt,U[7]=yt*Xt+gt*At+dt*Rt,U[8]=qt*kt+xt*Et+Tt*Pt,U[9]=qt*bt+xt*Ut+Tt*Kt,U[10]=qt*Bt+xt*Ht+Tt*mt,U[11]=qt*Xt+xt*At+Tt*Rt,f!==U&&(U[12]=f[12],U[13]=f[13],U[14]=f[14],U[15]=f[15]),U}let g=G;function y(f,T){let v=T??new r(16);return v[0]=f[0],v[1]=0,v[2]=0,v[3]=0,v[4]=0,v[5]=f[1],v[6]=0,v[7]=0,v[8]=0,v[9]=0,v[10]=f[2],v[11]=0,v[12]=0,v[13]=0,v[14]=0,v[15]=1,v}function R(f,T,v){let x=v??new r(16),U=T[0],q=T[1],rt=T[2];return x[0]=U*f[0*4+0],x[1]=U*f[0*4+1],x[2]=U*f[0*4+2],x[3]=U*f[0*4+3],x[4]=q*f[1*4+0],x[5]=q*f[1*4+1],x[6]=q*f[1*4+2],x[7]=q*f[1*4+3],x[8]=rt*f[2*4+0],x[9]=rt*f[2*4+1],x[10]=rt*f[2*4+2],x[11]=rt*f[2*4+3],f!==x&&(x[12]=f[12],x[13]=f[13],x[14]=f[14],x[15]=f[15]),x}function C(f,T){let v=T??new r(16);return v[0]=f,v[1]=0,v[2]=0,v[3]=0,v[4]=0,v[5]=f,v[6]=0,v[7]=0,v[8]=0,v[9]=0,v[10]=f,v[11]=0,v[12]=0,v[13]=0,v[14]=0,v[15]=1,v}function K(f,T,v){let x=v??new r(16);return x[0]=T*f[0*4+0],x[1]=T*f[0*4+1],x[2]=T*f[0*4+2],x[3]=T*f[0*4+3],x[4]=T*f[1*4+0],x[5]=T*f[1*4+1],x[6]=T*f[1*4+2],x[7]=T*f[1*4+3],x[8]=T*f[2*4+0],x[9]=T*f[2*4+1],x[10]=T*f[2*4+2],x[11]=T*f[2*4+3],f!==x&&(x[12]=f[12],x[13]=f[13],x[14]=f[14],x[15]=f[15]),x}return{create:n,set:e,fromMat3:o,fromQuat:i,negate:a,copy:u,clone:s,equalsApproximately:l,equals:p,identity:_,transpose:F,inverse:z,determinant:I,invert:m,multiply:L,mul:W,setTranslation:V,getTranslation:H,getAxis:$,setAxis:Z,getScaling:Q,perspective:it,perspectiveReverseZ:et,ortho:X,frustum:j,frustumReverseZ:E,aim:B,cameraAim:S,lookAt:O,translation:N,translate:A,rotationX:h,rotateX:D,rotationY:ot,rotateY:ct,rotationZ:st,rotateZ:vt,axisRotation:pt,rotation:d,axisRotate:G,rotate:g,scaling:y,scale:R,uniformScaling:C,uniformScale:K}}var zi=new Map;function os(r){let t=zi.get(r);return t||(t=is(r),zi.set(r,t)),t}function as(r){let t=Te(r);function n(d,G,g,y){let R=new r(4);return d!==void 0&&(R[0]=d,G!==void 0&&(R[1]=G,g!==void 0&&(R[2]=g,y!==void 0&&(R[3]=y)))),R}let e=n;function o(d,G,g,y,R){let C=R??new r(4);return C[0]=d,C[1]=G,C[2]=g,C[3]=y,C}function i(d,G,g){let y=g??new r(4),R=G*.5,C=Math.sin(R);return y[0]=C*d[0],y[1]=C*d[1],y[2]=C*d[2],y[3]=Math.cos(R),y}function a(d,G){let g=G??t.create(3),y=Math.acos(d[3])*2,R=Math.sin(y*.5);return R>Mt?(g[0]=d[0]/R,g[1]=d[1]/R,g[2]=d[2]/R):(g[0]=1,g[1]=0,g[2]=0),{angle:y,axis:g}}function u(d,G){let g=j(d,G);return Math.acos(2*g*g-1)}function s(d,G,g){let y=g??new r(4),R=d[0],C=d[1],K=d[2],f=d[3],T=G[0],v=G[1],x=G[2],U=G[3];return y[0]=R*U+f*T+C*x-K*v,y[1]=C*U+f*v+K*T-R*x,y[2]=K*U+f*x+R*v-C*T,y[3]=f*U-R*T-C*v-K*x,y}let l=s;function p(d,G,g){let y=g??new r(4),R=G*.5,C=d[0],K=d[1],f=d[2],T=d[3],v=Math.sin(R),x=Math.cos(R);return y[0]=C*x+T*v,y[1]=K*x+f*v,y[2]=f*x-K*v,y[3]=T*x-C*v,y}function _(d,G,g){let y=g??new r(4),R=G*.5,C=d[0],K=d[1],f=d[2],T=d[3],v=Math.sin(R),x=Math.cos(R);return y[0]=C*x-f*v,y[1]=K*x+T*v,y[2]=f*x+C*v,y[3]=T*x-K*v,y}function F(d,G,g){let y=g??new r(4),R=G*.5,C=d[0],K=d[1],f=d[2],T=d[3],v=Math.sin(R),x=Math.cos(R);return y[0]=C*x+K*v,y[1]=K*x-C*v,y[2]=f*x+T*v,y[3]=T*x-f*v,y}function z(d,G,g,y){let R=y??new r(4),C=d[0],K=d[1],f=d[2],T=d[3],v=G[0],x=G[1],U=G[2],q=G[3],rt=C*v+K*x+f*U+T*q;rt<0&&(rt=-rt,v=-v,x=-x,U=-U,q=-q);let b,P;if(1-rt>Mt){let k=Math.acos(rt),Y=Math.sin(k);b=Math.sin((1-g)*k)/Y,P=Math.sin(g*k)/Y}else b=1-g,P=g;return R[0]=b*C+P*v,R[1]=b*K+P*x,R[2]=b*f+P*U,R[3]=b*T+P*q,R}function I(d,G){let g=G??new r(4),y=d[0],R=d[1],C=d[2],K=d[3],f=y*y+R*R+C*C+K*K,T=f?1/f:0;return g[0]=-y*T,g[1]=-R*T,g[2]=-C*T,g[3]=K*T,g}function m(d,G){let g=G??new r(4);return g[0]=-d[0],g[1]=-d[1],g[2]=-d[2],g[3]=d[3],g}function L(d,G){let g=G??new r(4),y=d[0]+d[5]+d[10];if(y>0){let R=Math.sqrt(y+1);g[3]=.5*R;let C=.5/R;g[0]=(d[6]-d[9])*C,g[1]=(d[8]-d[2])*C,g[2]=(d[1]-d[4])*C}else{let R=0;d[5]>d[0]&&(R=1),d[10]>d[R*4+R]&&(R=2);let C=(R+1)%3,K=(R+2)%3,f=Math.sqrt(d[R*4+R]-d[C*4+C]-d[K*4+K]+1);g[R]=.5*f;let T=.5/f;g[3]=(d[C*4+K]-d[K*4+C])*T,g[C]=(d[C*4+R]+d[R*4+C])*T,g[K]=(d[K*4+R]+d[R*4+K])*T}return g}function W(d,G,g,y,R){let C=R??new r(4),K=d*.5,f=G*.5,T=g*.5,v=Math.sin(K),x=Math.cos(K),U=Math.sin(f),q=Math.cos(f),rt=Math.sin(T),b=Math.cos(T);switch(y){case"xyz":C[0]=v*q*b+x*U*rt,C[1]=x*U*b-v*q*rt,C[2]=x*q*rt+v*U*b,C[3]=x*q*b-v*U*rt;break;case"xzy":C[0]=v*q*b-x*U*rt,C[1]=x*U*b-v*q*rt,C[2]=x*q*rt+v*U*b,C[3]=x*q*b+v*U*rt;break;case"yxz":C[0]=v*q*b+x*U*rt,C[1]=x*U*b-v*q*rt,C[2]=x*q*rt-v*U*b,C[3]=x*q*b+v*U*rt;break;case"yzx":C[0]=v*q*b+x*U*rt,C[1]=x*U*b+v*q*rt,C[2]=x*q*rt-v*U*b,C[3]=x*q*b-v*U*rt;break;case"zxy":C[0]=v*q*b-x*U*rt,C[1]=x*U*b+v*q*rt,C[2]=x*q*rt+v*U*b,C[3]=x*q*b-v*U*rt;break;case"zyx":C[0]=v*q*b-x*U*rt,C[1]=x*U*b+v*q*rt,C[2]=x*q*rt-v*U*b,C[3]=x*q*b+v*U*rt;break;default:throw new Error(`Unknown rotation order: ${y}`)}return C}function V(d,G){let g=G??new r(4);return g[0]=d[0],g[1]=d[1],g[2]=d[2],g[3]=d[3],g}let H=V;function $(d,G,g){let y=g??new r(4);return y[0]=d[0]+G[0],y[1]=d[1]+G[1],y[2]=d[2]+G[2],y[3]=d[3]+G[3],y}function Z(d,G,g){let y=g??new r(4);return y[0]=d[0]-G[0],y[1]=d[1]-G[1],y[2]=d[2]-G[2],y[3]=d[3]-G[3],y}let Q=Z;function it(d,G,g){let y=g??new r(4);return y[0]=d[0]*G,y[1]=d[1]*G,y[2]=d[2]*G,y[3]=d[3]*G,y}let et=it;function X(d,G,g){let y=g??new r(4);return y[0]=d[0]/G,y[1]=d[1]/G,y[2]=d[2]/G,y[3]=d[3]/G,y}function j(d,G){return d[0]*G[0]+d[1]*G[1]+d[2]*G[2]+d[3]*G[3]}function E(d,G,g,y){let R=y??new r(4);return R[0]=d[0]+g*(G[0]-d[0]),R[1]=d[1]+g*(G[1]-d[1]),R[2]=d[2]+g*(G[2]-d[2]),R[3]=d[3]+g*(G[3]-d[3]),R}function c(d){let G=d[0],g=d[1],y=d[2],R=d[3];return Math.sqrt(G*G+g*g+y*y+R*R)}let w=c;function M(d){let G=d[0],g=d[1],y=d[2],R=d[3];return G*G+g*g+y*y+R*R}let B=M;function S(d,G){let g=G??new r(4),y=d[0],R=d[1],C=d[2],K=d[3],f=Math.sqrt(y*y+R*R+C*C+K*K);return f>1e-5?(g[0]=y/f,g[1]=R/f,g[2]=C/f,g[3]=K/f):(g[0]=0,g[1]=0,g[2]=0,g[3]=1),g}function O(d,G){return Math.abs(d[0]-G[0])<Mt&&Math.abs(d[1]-G[1])<Mt&&Math.abs(d[2]-G[2])<Mt&&Math.abs(d[3]-G[3])<Mt}function N(d,G){return d[0]===G[0]&&d[1]===G[1]&&d[2]===G[2]&&d[3]===G[3]}function A(d){let G=d??new r(4);return G[0]=0,G[1]=0,G[2]=0,G[3]=1,G}let h=t.create(),D=t.create(),ot=t.create();function ct(d,G,g){let y=g??new r(4),R=t.dot(d,G);return R<-.999999?(t.cross(D,d,h),t.len(h)<1e-6&&t.cross(ot,d,h),t.normalize(h,h),i(h,Math.PI,y),y):R>.999999?(y[0]=0,y[1]=0,y[2]=0,y[3]=1,y):(t.cross(d,G,h),y[0]=h[0],y[1]=h[1],y[2]=h[2],y[3]=1+R,S(y,y))}let st=new r(4),vt=new r(4);function pt(d,G,g,y,R,C){let K=C??new r(4);return z(d,y,R,st),z(G,g,R,vt),z(st,vt,2*R*(1-R),K),K}return{create:n,fromValues:e,set:o,fromAxisAngle:i,toAxisAngle:a,angle:u,multiply:s,mul:l,rotateX:p,rotateY:_,rotateZ:F,slerp:z,inverse:I,conjugate:m,fromMat:L,fromEuler:W,copy:V,clone:H,add:$,subtract:Z,sub:Q,mulScalar:it,scale:et,divScalar:X,dot:j,lerp:E,length:c,len:w,lengthSq:M,lenSq:B,normalize:S,equalsApproximately:O,equals:N,identity:A,rotationTo:ct,sqlerp:pt}}var Oi=new Map;function us(r){let t=Oi.get(r);return t||(t=as(r),Oi.set(r,t)),t}function ss(r){function t(g,y,R,C){let K=new r(4);return g!==void 0&&(K[0]=g,y!==void 0&&(K[1]=y,R!==void 0&&(K[2]=R,C!==void 0&&(K[3]=C)))),K}let n=t;function e(g,y,R,C,K){let f=K??new r(4);return f[0]=g,f[1]=y,f[2]=R,f[3]=C,f}function o(g,y){let R=y??new r(4);return R[0]=Math.ceil(g[0]),R[1]=Math.ceil(g[1]),R[2]=Math.ceil(g[2]),R[3]=Math.ceil(g[3]),R}function i(g,y){let R=y??new r(4);return R[0]=Math.floor(g[0]),R[1]=Math.floor(g[1]),R[2]=Math.floor(g[2]),R[3]=Math.floor(g[3]),R}function a(g,y){let R=y??new r(4);return R[0]=Math.round(g[0]),R[1]=Math.round(g[1]),R[2]=Math.round(g[2]),R[3]=Math.round(g[3]),R}function u(g,y=0,R=1,C){let K=C??new r(4);return K[0]=Math.min(R,Math.max(y,g[0])),K[1]=Math.min(R,Math.max(y,g[1])),K[2]=Math.min(R,Math.max(y,g[2])),K[3]=Math.min(R,Math.max(y,g[3])),K}function s(g,y,R){let C=R??new r(4);return C[0]=g[0]+y[0],C[1]=g[1]+y[1],C[2]=g[2]+y[2],C[3]=g[3]+y[3],C}function l(g,y,R,C){let K=C??new r(4);return K[0]=g[0]+y[0]*R,K[1]=g[1]+y[1]*R,K[2]=g[2]+y[2]*R,K[3]=g[3]+y[3]*R,K}function p(g,y,R){let C=R??new r(4);return C[0]=g[0]-y[0],C[1]=g[1]-y[1],C[2]=g[2]-y[2],C[3]=g[3]-y[3],C}let _=p;function F(g,y){return Math.abs(g[0]-y[0])<Mt&&Math.abs(g[1]-y[1])<Mt&&Math.abs(g[2]-y[2])<Mt&&Math.abs(g[3]-y[3])<Mt}function z(g,y){return g[0]===y[0]&&g[1]===y[1]&&g[2]===y[2]&&g[3]===y[3]}function I(g,y,R,C){let K=C??new r(4);return K[0]=g[0]+R*(y[0]-g[0]),K[1]=g[1]+R*(y[1]-g[1]),K[2]=g[2]+R*(y[2]-g[2]),K[3]=g[3]+R*(y[3]-g[3]),K}function m(g,y,R,C){let K=C??new r(4);return K[0]=g[0]+R[0]*(y[0]-g[0]),K[1]=g[1]+R[1]*(y[1]-g[1]),K[2]=g[2]+R[2]*(y[2]-g[2]),K[3]=g[3]+R[3]*(y[3]-g[3]),K}function L(g,y,R){let C=R??new r(4);return C[0]=Math.max(g[0],y[0]),C[1]=Math.max(g[1],y[1]),C[2]=Math.max(g[2],y[2]),C[3]=Math.max(g[3],y[3]),C}function W(g,y,R){let C=R??new r(4);return C[0]=Math.min(g[0],y[0]),C[1]=Math.min(g[1],y[1]),C[2]=Math.min(g[2],y[2]),C[3]=Math.min(g[3],y[3]),C}function V(g,y,R){let C=R??new r(4);return C[0]=g[0]*y,C[1]=g[1]*y,C[2]=g[2]*y,C[3]=g[3]*y,C}let H=V;function $(g,y,R){let C=R??new r(4);return C[0]=g[0]/y,C[1]=g[1]/y,C[2]=g[2]/y,C[3]=g[3]/y,C}function Z(g,y){let R=y??new r(4);return R[0]=1/g[0],R[1]=1/g[1],R[2]=1/g[2],R[3]=1/g[3],R}let Q=Z;function it(g,y){return g[0]*y[0]+g[1]*y[1]+g[2]*y[2]+g[3]*y[3]}function et(g){let y=g[0],R=g[1],C=g[2],K=g[3];return Math.sqrt(y*y+R*R+C*C+K*K)}let X=et;function j(g){let y=g[0],R=g[1],C=g[2],K=g[3];return y*y+R*R+C*C+K*K}let E=j;function c(g,y){let R=g[0]-y[0],C=g[1]-y[1],K=g[2]-y[2],f=g[3]-y[3];return Math.sqrt(R*R+C*C+K*K+f*f)}let w=c;function M(g,y){let R=g[0]-y[0],C=g[1]-y[1],K=g[2]-y[2],f=g[3]-y[3];return R*R+C*C+K*K+f*f}let B=M;function S(g,y){let R=y??new r(4),C=g[0],K=g[1],f=g[2],T=g[3],v=Math.sqrt(C*C+K*K+f*f+T*T);return v>1e-5?(R[0]=C/v,R[1]=K/v,R[2]=f/v,R[3]=T/v):(R[0]=0,R[1]=0,R[2]=0,R[3]=0),R}function O(g,y){let R=y??new r(4);return R[0]=-g[0],R[1]=-g[1],R[2]=-g[2],R[3]=-g[3],R}function N(g,y){let R=y??new r(4);return R[0]=g[0],R[1]=g[1],R[2]=g[2],R[3]=g[3],R}let A=N;function h(g,y,R){let C=R??new r(4);return C[0]=g[0]*y[0],C[1]=g[1]*y[1],C[2]=g[2]*y[2],C[3]=g[3]*y[3],C}let D=h;function ot(g,y,R){let C=R??new r(4);return C[0]=g[0]/y[0],C[1]=g[1]/y[1],C[2]=g[2]/y[2],C[3]=g[3]/y[3],C}let ct=ot;function st(g){let y=g??new r(4);return y[0]=0,y[1]=0,y[2]=0,y[3]=0,y}function vt(g,y,R){let C=R??new r(4),K=g[0],f=g[1],T=g[2],v=g[3];return C[0]=y[0]*K+y[4]*f+y[8]*T+y[12]*v,C[1]=y[1]*K+y[5]*f+y[9]*T+y[13]*v,C[2]=y[2]*K+y[6]*f+y[10]*T+y[14]*v,C[3]=y[3]*K+y[7]*f+y[11]*T+y[15]*v,C}function pt(g,y,R){let C=R??new r(4);return S(g,C),V(C,y,C)}function d(g,y,R){let C=R??new r(4);return et(g)>y?pt(g,y,C):N(g,C)}function G(g,y,R){let C=R??new r(4);return I(g,y,.5,C)}return{create:t,fromValues:n,set:e,ceil:o,floor:i,round:a,clamp:u,add:s,addScaled:l,subtract:p,sub:_,equalsApproximately:F,equals:z,lerp:I,lerpV:m,max:L,min:W,mulScalar:V,scale:H,divScalar:$,inverse:Z,invert:Q,dot:it,length:et,len:X,lengthSq:j,lenSq:E,distance:c,dist:w,distanceSq:M,distSq:B,normalize:S,negate:O,copy:N,clone:A,multiply:h,mul:D,divide:ot,div:ct,zero:st,transformMat4:vt,setLength:pt,truncate:d,midpoint:G}}var Ci=new Map;function cs(r){let t=Ci.get(r);return t||(t=ss(r),Ci.set(r,t)),t}function mn(r,t,n,e,o,i){return{mat3:ns(r),mat4:os(t),quat:us(n),vec2:Ni(e),vec3:Te(o),vec4:cs(i)}}var{mat3:Ar,mat4:Lt,quat:_h,vec2:Jt,vec3:_r,vec4:Vi}=mn(Float32Array,Float32Array,Float32Array,Float32Array,Float32Array,Float32Array),{mat3:Th,mat4:bh,quat:Bh,vec2:Eh,vec3:Sh,vec4:Uh}=mn(Float64Array,Float64Array,Float64Array,Float64Array,Float64Array,Float64Array),{mat3:Ah,mat4:Ph,quat:Dh,vec2:Ih,vec3:mh,vec4:Rh}=mn(ju,Array,Array,Array,Array,Array);var be=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:Ri});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,e={view:n.view,clearValue:[0,0,0,1],loadOp:"clear",storeOp:"store"};this.textureMultisampled&&(e.resolveTarget=this.textureSimple.view);let o=t.beginRenderPass({label:"DisplacementTexture render to texture renderpass",colorAttachments:[e]}),[i,a]=[n.texture.width,n.texture.height];o.setViewport(0,0,i,a,0,1),o.setScissorRect(0,0,i,a),o.setPipeline(this.renderPipeline),o.setBindGroup(0,this.bindgroup),o.setVertexBuffer(0,this.trianglesBuffer.bufferGpu),o.draw(3*this.trianglesBuffer.spriteCount),o.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],e=0,o=[1,1,0],i=Lt.identity();Lt.multiply(Lt.scaling(n),i,i),Lt.multiply(Lt.rotationZ(e),i,i),Lt.multiply(Lt.translation(o),i,i);let a=Lt.translation([-t.position[0],-t.position[1],0]),u=t.width/t.zoom,s=t.height/t.zoom,l=Lt.ortho(0,u,s,0,-10,10),p=Lt.identity();Lt.multiply(a,i,p),Lt.multiply(l,p,p),this.device.queue.writeBuffer(this.uniformsBuffer,0,p)}getView(){return this.textureSimple.view}destroy(){this.textureSimple.texture.destroy(),this.textureMultisampled?.texture.destroy(),this.uniformsBuffer.destroy()}createTextures(t,n){let e=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}),o={texture:e,view:e.createView({label:"DisplacementTexture texture view"})},i=null;if(this.multisample>1){let a=this.device.createTexture({label:"DisplacementTexture texture multisampled",size:[e.width,e.height],format:e.format,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT,sampleCount:this.multisample});i={texture:a,view:a.createView({label:"DisplacementTexture texture multisampled view"})}}return[o,i]}};var Yi={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(r,t={}){return ls(r,t)},onRun:function(r,t,n){fs(r,t,n)},onDestroy:function(r,t){hs(t)},onResize:function(r,t){t.data.displacementTexture.resize(r.viewport.width,r.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(r,t){t.data.displacementTexture.setViewport(r.viewport)},customFunctions:{addTriangle:function(r,t,n){return t.data.trianglesBuffer.addTriangle(n)},removeTriangle:function(r,t,n){t.data.trianglesBuffer.removeTriangle(n)},setPosition:function(r,t,n,e){t.data.trianglesBuffer.setTriangle(n,e)}}};async function ls(r,t){let{device:n}=r,e=new Me({device:n,initialParameters:{offsetX:t.options.offseyX??0,offsetY:t.options.offseyY??0,scale:t.options.scale??20}}),o=256,i=new xe({device:n,maxSpriteCount:o}),a=new be({device:n,width:r.viewport.width,height:r.viewport.height,blurFactor:8,trianglesBuffer:i}),u=new _e({device:n,targetFormat:"bgra8unorm",colorTextureView:t.refs.color.data.view,noiseMapTextureView:t.refs.map.view,displacementTextureView:a.getView(),displacementParametersBuffer:e});return{displacementParameters:e,displacementTexture:a,displacementComposition:u,trianglesBuffer:i}}function fs(r,t,n){if(t.data.trianglesBuffer.spriteCount===0)return;t.data.trianglesBuffer.update(),t.data.displacementTexture.update(n);let o=n.beginRenderPass({colorAttachments:[{view:t.refs.out,clearValue:r.clearValue,loadOp:"load",storeOp:"store"}]});o.executeBundles([t.data.displacementComposition.getRenderBundle()]),o.end()}function hs(r){r.data.trianglesBuffer.destroy(),r.data.trianglesBuffer=null,r.data.displacementParameters.destroy(),r.data.displacementParameters=null,r.data.displacementTexture.destroy(),r.data.displacementTexture=null,r.data.displacementComposition.destroy(),r.data.displacementComposition=null}function Rn(r,t){let n=t.vertices,e=GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST,o={size:n.byteLength,usage:e,mappedAtCreation:!0},i=r.createBuffer(o);return new Float32Array(i.getMappedRange()).set(n),i.unmap(),{buffer:i,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 tp=Vi.create(),ki=_r.create(),Hi={type:"cobalt:overlay",refs:[{name:"spritesheet",type:"customResource",access:"read"},{name:"color",type:"textView",format:"rgba8unorm",access:"write"}],onInit:async function(r,t={}){return vs(r,t)},onRun:function(r,t,n){gs(r,t,n)},onDestroy:function(r,t){ds(t)},onResize:function(r,t){Xi(r,t)},onViewportPosition:function(r,t){Xi(r,t)},customFunctions:{...oe}};async function vs(r,t){let{device:n}=r,e=16192,o=e,a=Float32Array.BYTES_PER_ELEMENT*2,s=Float32Array.BYTES_PER_ELEMENT*2,p=Float32Array.BYTES_PER_ELEMENT*4,F=Float32Array.BYTES_PER_ELEMENT*4,z=n.createBuffer({size:(a+s+p+F)*o,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST}),I=n.createBuffer({size:64*2,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),m=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"}}]}),L=n.createBindGroup({layout:m,entries:[{binding:0,resource:{buffer:I}},{binding:1,resource:t.refs.spritesheet.data.colorTexture.view},{binding:2,resource:t.refs.spritesheet.data.colorTexture.sampler},{binding:3,resource:{buffer:z}}]}),W=n.createPipelineLayout({bindGroupLayouts:[m]}),V=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:W});return{instancedDrawCalls:new Uint32Array(e*2),instancedDrawCallCount:0,spriteBuffer:z,uniformBuffer:I,pipeline:V,bindGroupLayout:m,bindGroup:L,spriteData:new Float32Array(e*12),spriteCount:0,spriteIndices:new Map,dirty:!1}}function gs(r,t,n){let{device:e}=r,o=t.options.loadOp||"load";if(t.data.dirty&&(ws(t.data),t.data.dirty=!1),t.data.spriteCount>0){let s=t.data.spriteCount*12*Float32Array.BYTES_PER_ELEMENT;e.queue.writeBuffer(t.data.spriteBuffer,0,t.data.spriteData.buffer,0,s)}let i=n.beginRenderPass({colorAttachments:[{view:t.refs.color,clearValue:r.clearValue,loadOp:o,storeOp:"store"}]});i.setPipeline(t.data.pipeline),i.setBindGroup(0,t.data.bindGroup),i.setVertexBuffer(0,t.refs.spritesheet.data.quads.buffer);let a=6,u=0;for(let s=0;s<t.data.instancedDrawCallCount;s++){let l=t.data.instancedDrawCalls[s*2]*a,p=t.data.instancedDrawCalls[s*2+1];i.draw(a,p,l,u),u+=p}i.end()}function ws(r){let t=-1,n=0;r.instancedDrawCallCount=0;for(let e=0;e<r.spriteCount;e++){let o=r.spriteData[e*12+11]&65535;o!==t&&(n>0&&(r.instancedDrawCalls[r.instancedDrawCallCount*2]=t,r.instancedDrawCalls[r.instancedDrawCallCount*2+1]=n,r.instancedDrawCallCount++),t=o,n=0),n++}n>0&&(r.instancedDrawCalls[r.instancedDrawCallCount*2]=t,r.instancedDrawCalls[r.instancedDrawCallCount*2+1]=n,r.instancedDrawCallCount++)}function Xi(r,t){let e=Math.round(r.viewport.width/1),o=Math.round(r.viewport.height/1),i=Lt.ortho(0,e,o,0,-10,10);_r.set(0,0,0,ki);let a=Lt.translation(ki);r.device.queue.writeBuffer(t.data.uniformBuffer,0,a.buffer),r.device.queue.writeBuffer(t.data.uniformBuffer,64,i.buffer)}function ds(r){r.data.instancedDrawCalls=null,r.data.bindGroup=null,r.data.spriteBuffer.destroy(),r.data.spriteBuffer=null,r.data.uniformBuffer.destroy(),r.data.uniformBuffer=null,r.data.spriteData=null,r.data.spriteIndices.clear(),r.data.spriteIndices=null}var Fn="@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 $i={type:"cobalt:fbBlit",refs:[{name:"in",type:"cobaltTexture",format:"bgra8unorm",access:"read"},{name:"out",type:"cobaltTexture",format:"bgra8unorm",access:"write"}],onInit:async function(r,t={}){return xs(r,t)},onRun:function(r,t,n){Ms(r,t,n)},onDestroy:function(r,t){},onResize:function(r,t){_s(r,t)},onViewportPosition:function(r,t){}};async function xs(r,t){let{device:n}=r,e=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),o=n.createBindGroup({layout:e,entries:[{binding:0,resource:t.refs.in.data.view},{binding:1,resource:t.refs.in.data.sampler}]}),i=n.createPipelineLayout({bindGroupLayouts:[e]}),a=n.createRenderPipeline({label:"fb-blit",vertex:{module:n.createShaderModule({code:Fn}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:Fn}),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:i});return{bindGroupLayout:e,bindGroup:o,pipeline:a}}function Ms(r,t,n){let{device:e}=r,o=n.beginRenderPass({colorAttachments:[{view:t.refs.out,clearValue:r.clearValue,loadOp:"load",storeOp:"store"}]});o.setPipeline(t.data.pipeline),o.setBindGroup(0,t.data.bindGroup),o.draw(3),o.end()}function _s(r,t){let{device:n}=r;t.data.bindGroup=n.createBindGroup({layout:t.data.bindGroupLayout,entries:[{binding:0,resource:t.refs.in.data.view},{binding:1,resource:t.refs.in.data.sampler}]})}var Zi="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 eu=Tu(Eo(),1);var D0=So;function So(r){this.roots=new Array(r),this.ranks=new Array(r);for(var t=0;t<r;++t)this.roots[t]=t,this.ranks[t]=0}var De=So.prototype;Object.defineProperty(De,"length",{get:function(){return this.roots.length}});De.makeSet=function(){var r=this.roots.length;return this.roots.push(r),this.ranks.push(0),r};De.find=function(r){for(var t=r,n=this.roots;n[r]!==r;)r=n[r];for(;n[t]!==r;){var e=n[t];n[t]=r,t=e}return r};De.link=function(r,t){var n=this.find(r),e=this.find(t);if(n!==e){var o=this.ranks,i=this.roots,a=o[n],u=o[e];a<u?i[n]=e:u<a?i[e]=n:(i[e]=n,++o[n])}};var Uo=D0;var Zn=32,I0=Zn,m0=2147483647,R0=-1<<Zn-1,L0=function(r){return(r>0)-(r<0)},G0=function(r){var t=r>>Zn-1;return(r^t)-t},F0=function(r,t){return t^(r^t)&-(r<t)},z0=function(r,t){return r^(r^t)&-(r<t)},O0=function(r){return!(r&r-1)&&!!r},C0=function(r){var t,n;return t=(r>65535)<<4,r>>>=t,n=(r>255)<<3,r>>>=n,t|=n,n=(r>15)<<2,r>>>=n,t|=n,n=(r>3)<<1,r>>>=n,t|=n,t|r>>1},N0=function(r){return r>=1e9?9:r>=1e8?8:r>=1e7?7:r>=1e6?6:r>=1e5?5:r>=1e4?4:r>=1e3?3:r>=100?2:r>=10?1:0},V0=function(r){return r=r-(r>>>1&1431655765),r=(r&858993459)+(r>>>2&858993459),(r+(r>>>4)&252645135)*16843009>>>24};function Ao(r){var t=32;return r&=-r,r&&t--,r&65535&&(t-=16),r&16711935&&(t-=8),r&252645135&&(t-=4),r&858993459&&(t-=2),r&1431655765&&(t-=1),t}var q0=Ao,Y0=function(r){return r+=r===0,--r,r|=r>>>1,r|=r>>>2,r|=r>>>4,r|=r>>>8,r|=r>>>16,r+1},k0=function(r){return r|=r>>>1,r|=r>>>2,r|=r>>>4,r|=r>>>8,r|=r>>>16,r-(r>>>1)},X0=function(r){return r^=r>>>16,r^=r>>>8,r^=r>>>4,r&=15,27030>>>r&1},ce=new Array(256);(function(r){for(var t=0;t<256;++t){var n=t,e=t,o=7;for(n>>>=1;n;n>>>=1)e<<=1,e|=n&1,--o;r[t]=e<<o&255}})(ce);var H0=function(r){return ce[r&255]<<24|ce[r>>>8&255]<<16|ce[r>>>16&255]<<8|ce[r>>>24&255]},$0=function(r,t){return r&=65535,r=(r|r<<8)&16711935,r=(r|r<<4)&252645135,r=(r|r<<2)&858993459,r=(r|r<<1)&1431655765,t&=65535,t=(t|t<<8)&16711935,t=(t|t<<4)&252645135,t=(t|t<<2)&858993459,t=(t|t<<1)&1431655765,r|t<<1},Z0=function(r,t){return r=r>>>t&1431655765,r=(r|r>>>1)&858993459,r=(r|r>>>2)&252645135,r=(r|r>>>4)&16711935,r=(r|r>>>16)&65535,r<<16>>16},W0=function(r,t,n){return r&=1023,r=(r|r<<16)&4278190335,r=(r|r<<8)&251719695,r=(r|r<<4)&3272356035,r=(r|r<<2)&1227133513,t&=1023,t=(t|t<<16)&4278190335,t=(t|t<<8)&251719695,t=(t|t<<4)&3272356035,t=(t|t<<2)&1227133513,r|=t<<1,n&=1023,n=(n|n<<16)&4278190335,n=(n|n<<8)&251719695,n=(n|n<<4)&3272356035,n=(n|n<<2)&1227133513,r|n<<2},Q0=function(r,t){return r=r>>>t&1227133513,r=(r|r>>>2)&3272356035,r=(r|r>>>4)&251719695,r=(r|r>>>8)&4278190335,r=(r|r>>>16)&1023,r<<22>>22},K0=function(r){var t=r|r-1;return t+1|(~t&-~t)-1>>>Ao(r)+1},J0={INT_BITS:I0,INT_MAX:m0,INT_MIN:R0,sign:L0,abs:G0,min:F0,max:z0,isPow2:O0,log2:C0,log10:N0,popCount:V0,countTrailingZeros:q0,nextPow2:Y0,prevPow2:k0,parity:X0,reverse:H0,interleave2:$0,deinterleave2:Z0,interleave3:W0,deinterleave3:Q0,nextCombination:K0},jt=J0;function Po(r,t,n){var e=r[n]|0;if(e<=0)return[];var o=new Array(e),i;if(n===r.length-1)for(i=0;i<e;++i)o[i]=t;else for(i=0;i<e;++i)o[i]=Po(r,t,n+1);return o}function j0(r,t){var n,e;for(n=new Array(r),e=0;e<r;++e)n[e]=t;return n}function tc(r,t){switch(typeof t>"u"&&(t=0),typeof r){case"number":if(r>0)return j0(r|0,t);break;case"object":if(typeof r.length=="number")return Po(r,t,0);break}return[]}var rc=tc,$t=rc;var Wn=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function ec(r,t,n){return n={path:t,exports:{},require:function(e,o){return nc(e,o??n.path)}},r(n,n.exports),n.exports}function nc(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var Do=typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{},wr=[],sr=[],ic=typeof Uint8Array<"u"?Uint8Array:Array,Kn=!1;function Lo(){Kn=!0;for(var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,n=r.length;t<n;++t)wr[t]=r[t],sr[r.charCodeAt(t)]=t;sr[45]=62,sr[95]=63}function oc(r){Kn||Lo();var t,n,e,o,i,a,u=r.length;if(u%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i=r[u-2]==="="?2:r[u-1]==="="?1:0,a=new ic(u*3/4-i),e=i>0?u-4:u;var s=0;for(t=0,n=0;t<e;t+=4,n+=3)o=sr[r.charCodeAt(t)]<<18|sr[r.charCodeAt(t+1)]<<12|sr[r.charCodeAt(t+2)]<<6|sr[r.charCodeAt(t+3)],a[s++]=o>>16&255,a[s++]=o>>8&255,a[s++]=o&255;return i===2?(o=sr[r.charCodeAt(t)]<<2|sr[r.charCodeAt(t+1)]>>4,a[s++]=o&255):i===1&&(o=sr[r.charCodeAt(t)]<<10|sr[r.charCodeAt(t+1)]<<4|sr[r.charCodeAt(t+2)]>>2,a[s++]=o>>8&255,a[s++]=o&255),a}function ac(r){return wr[r>>18&63]+wr[r>>12&63]+wr[r>>6&63]+wr[r&63]}function uc(r,t,n){for(var e,o=[],i=t;i<n;i+=3)e=(r[i]<<16)+(r[i+1]<<8)+r[i+2],o.push(ac(e));return o.join("")}function Io(r){Kn||Lo();for(var t,n=r.length,e=n%3,o="",i=[],a=16383,u=0,s=n-e;u<s;u+=a)i.push(uc(r,u,u+a>s?s:u+a));return e===1?(t=r[n-1],o+=wr[t>>2],o+=wr[t<<4&63],o+="=="):e===2&&(t=(r[n-2]<<8)+r[n-1],o+=wr[t>>10],o+=wr[t>>4&63],o+=wr[t<<2&63],o+="="),i.push(o),i.join("")}function Re(r,t,n,e,o){var i,a,u=o*8-e-1,s=(1<<u)-1,l=s>>1,p=-7,_=n?o-1:0,F=n?-1:1,z=r[t+_];for(_+=F,i=z&(1<<-p)-1,z>>=-p,p+=u;p>0;i=i*256+r[t+_],_+=F,p-=8);for(a=i&(1<<-p)-1,i>>=-p,p+=e;p>0;a=a*256+r[t+_],_+=F,p-=8);if(i===0)i=1-l;else{if(i===s)return a?NaN:(z?-1:1)*(1/0);a=a+Math.pow(2,e),i=i-l}return(z?-1:1)*a*Math.pow(2,i-e)}function Go(r,t,n,e,o,i){var a,u,s,l=i*8-o-1,p=(1<<l)-1,_=p>>1,F=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,z=e?0:i-1,I=e?1:-1,m=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,a=p):(a=Math.floor(Math.log(t)/Math.LN2),t*(s=Math.pow(2,-a))<1&&(a--,s*=2),a+_>=1?t+=F/s:t+=F*Math.pow(2,1-_),t*s>=2&&(a++,s/=2),a+_>=p?(u=0,a=p):a+_>=1?(u=(t*s-1)*Math.pow(2,o),a=a+_):(u=t*Math.pow(2,_-1)*Math.pow(2,o),a=0));o>=8;r[n+z]=u&255,z+=I,u/=256,o-=8);for(a=a<<o|u,l+=o;l>0;r[n+z]=a&255,z+=I,a/=256,l-=8);r[n+z-I]|=m*128}var sc={}.toString,Fo=Array.isArray||function(r){return sc.call(r)=="[object Array]"};var zo=50;at.TYPED_ARRAY_SUPPORT=Do.TYPED_ARRAY_SUPPORT!==void 0?Do.TYPED_ARRAY_SUPPORT:!0;var cc=Ie();function Ie(){return at.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Tr(r,t){if(Ie()<t)throw new RangeError("Invalid typed array length");return at.TYPED_ARRAY_SUPPORT?(r=new Uint8Array(t),r.__proto__=at.prototype):(r===null&&(r=new at(t)),r.length=t),r}function at(r,t,n){if(!at.TYPED_ARRAY_SUPPORT&&!(this instanceof at))return new at(r,t,n);if(typeof r=="number"){if(typeof t=="string")throw new Error("If encoding is specified then the first argument must be a string");return Jn(this,r)}return Oo(this,r,t,n)}at.poolSize=8192;at._augment=function(r){return r.__proto__=at.prototype,r};function Oo(r,t,n,e){if(typeof t=="number")throw new TypeError('"value" argument must not be a number');return typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer?hc(r,t,n,e):typeof t=="string"?fc(r,t,n):pc(r,t)}at.from=function(r,t,n){return Oo(null,r,t,n)};at.TYPED_ARRAY_SUPPORT&&(at.prototype.__proto__=Uint8Array.prototype,at.__proto__=Uint8Array);function Co(r){if(typeof r!="number")throw new TypeError('"size" argument must be a number');if(r<0)throw new RangeError('"size" argument must not be negative')}function lc(r,t,n,e){return Co(t),t<=0?Tr(r,t):n!==void 0?typeof e=="string"?Tr(r,t).fill(n,e):Tr(r,t).fill(n):Tr(r,t)}at.alloc=function(r,t,n){return lc(null,r,t,n)};function Jn(r,t){if(Co(t),r=Tr(r,t<0?0:jn(t)|0),!at.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)r[n]=0;return r}at.allocUnsafe=function(r){return Jn(null,r)};at.allocUnsafeSlow=function(r){return Jn(null,r)};function fc(r,t,n){if((typeof n!="string"||n==="")&&(n="utf8"),!at.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var e=No(t,n)|0;r=Tr(r,e);var o=r.write(t,n);return o!==e&&(r=r.slice(0,o)),r}function Qn(r,t){var n=t.length<0?0:jn(t.length)|0;r=Tr(r,n);for(var e=0;e<n;e+=1)r[e]=t[e]&255;return r}function hc(r,t,n,e){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(e||0))throw new RangeError("'length' is out of bounds");return n===void 0&&e===void 0?t=new Uint8Array(t):e===void 0?t=new Uint8Array(t,n):t=new Uint8Array(t,n,e),at.TYPED_ARRAY_SUPPORT?(r=t,r.__proto__=at.prototype):r=Qn(r,t),r}function pc(r,t){if(dr(t)){var n=jn(t.length)|0;return r=Tr(r,n),r.length===0||t.copy(r,0,0,n),r}if(t){if(typeof ArrayBuffer<"u"&&t.buffer instanceof ArrayBuffer||"length"in t)return typeof t.length!="number"||Rc(t.length)?Tr(r,0):Qn(r,t);if(t.type==="Buffer"&&Fo(t.data))return Qn(r,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function jn(r){if(r>=Ie())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+Ie().toString(16)+" bytes");return r|0}function vc(r){return+r!=r&&(r=0),at.alloc(+r)}at.isBuffer=Zo;function dr(r){return!!(r!=null&&r._isBuffer)}at.compare=function(t,n){if(!dr(t)||!dr(n))throw new TypeError("Arguments must be Buffers");if(t===n)return 0;for(var e=t.length,o=n.length,i=0,a=Math.min(e,o);i<a;++i)if(t[i]!==n[i]){e=t[i],o=n[i];break}return e<o?-1:o<e?1:0};at.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};at.concat=function(t,n){if(!Fo(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return at.alloc(0);var e;if(n===void 0)for(n=0,e=0;e<t.length;++e)n+=t[e].length;var o=at.allocUnsafe(n),i=0;for(e=0;e<t.length;++e){var a=t[e];if(!dr(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(o,i),i+=a.length}return o};function No(r,t){if(dr(r))return r.length;if(typeof ArrayBuffer<"u"&&typeof ArrayBuffer.isView=="function"&&(ArrayBuffer.isView(r)||r instanceof ArrayBuffer))return r.byteLength;typeof r!="string"&&(r=""+r);var n=r.length;if(n===0)return 0;for(var e=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return me(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n*2;case"hex":return n>>>1;case"base64":return $o(r).length;default:if(e)return me(r).length;t=(""+t).toLowerCase(),e=!0}}at.byteLength=No;function gc(r,t,n){var e=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return"";for(r||(r="utf8");;)switch(r){case"hex":return Ec(this,t,n);case"utf8":case"utf-8":return Yo(this,t,n);case"ascii":return bc(this,t,n);case"latin1":case"binary":return Bc(this,t,n);case"base64":return _c(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Sc(this,t,n);default:if(e)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),e=!0}}at.prototype._isBuffer=!0;function Cr(r,t,n){var e=r[t];r[t]=r[n],r[n]=e}at.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var n=0;n<t;n+=2)Cr(this,n,n+1);return this};at.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var n=0;n<t;n+=4)Cr(this,n,n+3),Cr(this,n+1,n+2);return this};at.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var n=0;n<t;n+=8)Cr(this,n,n+7),Cr(this,n+1,n+6),Cr(this,n+2,n+5),Cr(this,n+3,n+4);return this};at.prototype.toString=function(){var t=this.length|0;return t===0?"":arguments.length===0?Yo(this,0,t):gc.apply(this,arguments)};at.prototype.equals=function(t){if(!dr(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:at.compare(this,t)===0};at.prototype.inspect=function(){var t="",n=zo;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),"<Buffer "+t+">"};at.prototype.compare=function(t,n,e,o,i){if(!dr(t))throw new TypeError("Argument must be a Buffer");if(n===void 0&&(n=0),e===void 0&&(e=t?t.length:0),o===void 0&&(o=0),i===void 0&&(i=this.length),n<0||e>t.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&n>=e)return 0;if(o>=i)return-1;if(n>=e)return 1;if(n>>>=0,e>>>=0,o>>>=0,i>>>=0,this===t)return 0;for(var a=i-o,u=e-n,s=Math.min(a,u),l=this.slice(o,i),p=t.slice(n,e),_=0;_<s;++_)if(l[_]!==p[_]){a=l[_],u=p[_];break}return a<u?-1:u<a?1:0};function Vo(r,t,n,e,o){if(r.length===0)return-1;if(typeof n=="string"?(e=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:r.length-1),n<0&&(n=r.length+n),n>=r.length){if(o)return-1;n=r.length-1}else if(n<0)if(o)n=0;else return-1;if(typeof t=="string"&&(t=at.from(t,e)),dr(t))return t.length===0?-1:mo(r,t,n,e,o);if(typeof t=="number")return t=t&255,at.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(r,t,n):Uint8Array.prototype.lastIndexOf.call(r,t,n):mo(r,[t],n,e,o);throw new TypeError("val must be string, number or Buffer")}function mo(r,t,n,e,o){var i=1,a=r.length,u=t.length;if(e!==void 0&&(e=String(e).toLowerCase(),e==="ucs2"||e==="ucs-2"||e==="utf16le"||e==="utf-16le")){if(r.length<2||t.length<2)return-1;i=2,a/=2,u/=2,n/=2}function s(z,I){return i===1?z[I]:z.readUInt16BE(I*i)}var l;if(o){var p=-1;for(l=n;l<a;l++)if(s(r,l)===s(t,p===-1?0:l-p)){if(p===-1&&(p=l),l-p+1===u)return p*i}else p!==-1&&(l-=l-p),p=-1}else for(n+u>a&&(n=a-u),l=n;l>=0;l--){for(var _=!0,F=0;F<u;F++)if(s(r,l+F)!==s(t,F)){_=!1;break}if(_)return l}return-1}at.prototype.includes=function(t,n,e){return this.indexOf(t,n,e)!==-1};at.prototype.indexOf=function(t,n,e){return Vo(this,t,n,e,!0)};at.prototype.lastIndexOf=function(t,n,e){return Vo(this,t,n,e,!1)};function wc(r,t,n,e){n=Number(n)||0;var o=r.length-n;e?(e=Number(e),e>o&&(e=o)):e=o;var i=t.length;if(i%2!==0)throw new TypeError("Invalid hex string");e>i/2&&(e=i/2);for(var a=0;a<e;++a){var u=parseInt(t.substr(a*2,2),16);if(isNaN(u))return a;r[n+a]=u}return a}function dc(r,t,n,e){return Fe(me(t,r.length-n),r,n,e)}function qo(r,t,n,e){return Fe(Ic(t),r,n,e)}function yc(r,t,n,e){return qo(r,t,n,e)}function xc(r,t,n,e){return Fe($o(t),r,n,e)}function Mc(r,t,n,e){return Fe(mc(t,r.length-n),r,n,e)}at.prototype.write=function(t,n,e,o){if(n===void 0)o="utf8",e=this.length,n=0;else if(e===void 0&&typeof n=="string")o=n,e=this.length,n=0;else if(isFinite(n))n=n|0,isFinite(e)?(e=e|0,o===void 0&&(o="utf8")):(o=e,e=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var i=this.length-n;if((e===void 0||e>i)&&(e=i),t.length>0&&(e<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");for(var a=!1;;)switch(o){case"hex":return wc(this,t,n,e);case"utf8":case"utf-8":return dc(this,t,n,e);case"ascii":return qo(this,t,n,e);case"latin1":case"binary":return yc(this,t,n,e);case"base64":return xc(this,t,n,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return Mc(this,t,n,e);default:if(a)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),a=!0}};at.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function _c(r,t,n){return t===0&&n===r.length?Io(r):Io(r.slice(t,n))}function Yo(r,t,n){n=Math.min(r.length,n);for(var e=[],o=t;o<n;){var i=r[o],a=null,u=i>239?4:i>223?3:i>191?2:1;if(o+u<=n){var s,l,p,_;switch(u){case 1:i<128&&(a=i);break;case 2:s=r[o+1],(s&192)===128&&(_=(i&31)<<6|s&63,_>127&&(a=_));break;case 3:s=r[o+1],l=r[o+2],(s&192)===128&&(l&192)===128&&(_=(i&15)<<12|(s&63)<<6|l&63,_>2047&&(_<55296||_>57343)&&(a=_));break;case 4:s=r[o+1],l=r[o+2],p=r[o+3],(s&192)===128&&(l&192)===128&&(p&192)===128&&(_=(i&15)<<18|(s&63)<<12|(l&63)<<6|p&63,_>65535&&_<1114112&&(a=_))}}a===null?(a=65533,u=1):a>65535&&(a-=65536,e.push(a>>>10&1023|55296),a=56320|a&1023),e.push(a),o+=u}return Tc(e)}var Ro=4096;function Tc(r){var t=r.length;if(t<=Ro)return String.fromCharCode.apply(String,r);for(var n="",e=0;e<t;)n+=String.fromCharCode.apply(String,r.slice(e,e+=Ro));return n}function bc(r,t,n){var e="";n=Math.min(r.length,n);for(var o=t;o<n;++o)e+=String.fromCharCode(r[o]&127);return e}function Bc(r,t,n){var e="";n=Math.min(r.length,n);for(var o=t;o<n;++o)e+=String.fromCharCode(r[o]);return e}function Ec(r,t,n){var e=r.length;(!t||t<0)&&(t=0),(!n||n<0||n>e)&&(n=e);for(var o="",i=t;i<n;++i)o+=Dc(r[i]);return o}function Sc(r,t,n){for(var e=r.slice(t,n),o="",i=0;i<e.length;i+=2)o+=String.fromCharCode(e[i]+e[i+1]*256);return o}at.prototype.slice=function(t,n){var e=this.length;t=~~t,n=n===void 0?e:~~n,t<0?(t+=e,t<0&&(t=0)):t>e&&(t=e),n<0?(n+=e,n<0&&(n=0)):n>e&&(n=e),n<t&&(n=t);var o;if(at.TYPED_ARRAY_SUPPORT)o=this.subarray(t,n),o.__proto__=at.prototype;else{var i=n-t;o=new at(i,void 0);for(var a=0;a<i;++a)o[a]=this[a+t]}return o};function Zt(r,t,n){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+t>n)throw new RangeError("Trying to access beyond buffer length")}at.prototype.readUIntLE=function(t,n,e){t=t|0,n=n|0,e||Zt(t,n,this.length);for(var o=this[t],i=1,a=0;++a<n&&(i*=256);)o+=this[t+a]*i;return o};at.prototype.readUIntBE=function(t,n,e){t=t|0,n=n|0,e||Zt(t,n,this.length);for(var o=this[t+--n],i=1;n>0&&(i*=256);)o+=this[t+--n]*i;return o};at.prototype.readUInt8=function(t,n){return n||Zt(t,1,this.length),this[t]};at.prototype.readUInt16LE=function(t,n){return n||Zt(t,2,this.length),this[t]|this[t+1]<<8};at.prototype.readUInt16BE=function(t,n){return n||Zt(t,2,this.length),this[t]<<8|this[t+1]};at.prototype.readUInt32LE=function(t,n){return n||Zt(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};at.prototype.readUInt32BE=function(t,n){return n||Zt(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};at.prototype.readIntLE=function(t,n,e){t=t|0,n=n|0,e||Zt(t,n,this.length);for(var o=this[t],i=1,a=0;++a<n&&(i*=256);)o+=this[t+a]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*n)),o};at.prototype.readIntBE=function(t,n,e){t=t|0,n=n|0,e||Zt(t,n,this.length);for(var o=n,i=1,a=this[t+--o];o>0&&(i*=256);)a+=this[t+--o]*i;return i*=128,a>=i&&(a-=Math.pow(2,8*n)),a};at.prototype.readInt8=function(t,n){return n||Zt(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};at.prototype.readInt16LE=function(t,n){n||Zt(t,2,this.length);var e=this[t]|this[t+1]<<8;return e&32768?e|4294901760:e};at.prototype.readInt16BE=function(t,n){n||Zt(t,2,this.length);var e=this[t+1]|this[t]<<8;return e&32768?e|4294901760:e};at.prototype.readInt32LE=function(t,n){return n||Zt(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};at.prototype.readInt32BE=function(t,n){return n||Zt(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};at.prototype.readFloatLE=function(t,n){return n||Zt(t,4,this.length),Re(this,t,!0,23,4)};at.prototype.readFloatBE=function(t,n){return n||Zt(t,4,this.length),Re(this,t,!1,23,4)};at.prototype.readDoubleLE=function(t,n){return n||Zt(t,8,this.length),Re(this,t,!0,52,8)};at.prototype.readDoubleBE=function(t,n){return n||Zt(t,8,this.length),Re(this,t,!1,52,8)};function nr(r,t,n,e,o,i){if(!dr(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(n+e>r.length)throw new RangeError("Index out of range")}at.prototype.writeUIntLE=function(t,n,e,o){if(t=+t,n=n|0,e=e|0,!o){var i=Math.pow(2,8*e)-1;nr(this,t,n,e,i,0)}var a=1,u=0;for(this[n]=t&255;++u<e&&(a*=256);)this[n+u]=t/a&255;return n+e};at.prototype.writeUIntBE=function(t,n,e,o){if(t=+t,n=n|0,e=e|0,!o){var i=Math.pow(2,8*e)-1;nr(this,t,n,e,i,0)}var a=e-1,u=1;for(this[n+a]=t&255;--a>=0&&(u*=256);)this[n+a]=t/u&255;return n+e};at.prototype.writeUInt8=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,1,255,0),at.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[n]=t&255,n+1};function Le(r,t,n,e){t<0&&(t=65535+t+1);for(var o=0,i=Math.min(r.length-n,2);o<i;++o)r[n+o]=(t&255<<8*(e?o:1-o))>>>(e?o:1-o)*8}at.prototype.writeUInt16LE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,2,65535,0),at.TYPED_ARRAY_SUPPORT?(this[n]=t&255,this[n+1]=t>>>8):Le(this,t,n,!0),n+2};at.prototype.writeUInt16BE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,2,65535,0),at.TYPED_ARRAY_SUPPORT?(this[n]=t>>>8,this[n+1]=t&255):Le(this,t,n,!1),n+2};function Ge(r,t,n,e){t<0&&(t=4294967295+t+1);for(var o=0,i=Math.min(r.length-n,4);o<i;++o)r[n+o]=t>>>(e?o:3-o)*8&255}at.prototype.writeUInt32LE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,4,4294967295,0),at.TYPED_ARRAY_SUPPORT?(this[n+3]=t>>>24,this[n+2]=t>>>16,this[n+1]=t>>>8,this[n]=t&255):Ge(this,t,n,!0),n+4};at.prototype.writeUInt32BE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,4,4294967295,0),at.TYPED_ARRAY_SUPPORT?(this[n]=t>>>24,this[n+1]=t>>>16,this[n+2]=t>>>8,this[n+3]=t&255):Ge(this,t,n,!1),n+4};at.prototype.writeIntLE=function(t,n,e,o){if(t=+t,n=n|0,!o){var i=Math.pow(2,8*e-1);nr(this,t,n,e,i-1,-i)}var a=0,u=1,s=0;for(this[n]=t&255;++a<e&&(u*=256);)t<0&&s===0&&this[n+a-1]!==0&&(s=1),this[n+a]=(t/u>>0)-s&255;return n+e};at.prototype.writeIntBE=function(t,n,e,o){if(t=+t,n=n|0,!o){var i=Math.pow(2,8*e-1);nr(this,t,n,e,i-1,-i)}var a=e-1,u=1,s=0;for(this[n+a]=t&255;--a>=0&&(u*=256);)t<0&&s===0&&this[n+a+1]!==0&&(s=1),this[n+a]=(t/u>>0)-s&255;return n+e};at.prototype.writeInt8=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,1,127,-128),at.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[n]=t&255,n+1};at.prototype.writeInt16LE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,2,32767,-32768),at.TYPED_ARRAY_SUPPORT?(this[n]=t&255,this[n+1]=t>>>8):Le(this,t,n,!0),n+2};at.prototype.writeInt16BE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,2,32767,-32768),at.TYPED_ARRAY_SUPPORT?(this[n]=t>>>8,this[n+1]=t&255):Le(this,t,n,!1),n+2};at.prototype.writeInt32LE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,4,2147483647,-2147483648),at.TYPED_ARRAY_SUPPORT?(this[n]=t&255,this[n+1]=t>>>8,this[n+2]=t>>>16,this[n+3]=t>>>24):Ge(this,t,n,!0),n+4};at.prototype.writeInt32BE=function(t,n,e){return t=+t,n=n|0,e||nr(this,t,n,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),at.TYPED_ARRAY_SUPPORT?(this[n]=t>>>24,this[n+1]=t>>>16,this[n+2]=t>>>8,this[n+3]=t&255):Ge(this,t,n,!1),n+4};function ko(r,t,n,e,o,i){if(n+e>r.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function Xo(r,t,n,e,o){return o||ko(r,t,n,4),Go(r,t,n,e,23,4),n+4}at.prototype.writeFloatLE=function(t,n,e){return Xo(this,t,n,!0,e)};at.prototype.writeFloatBE=function(t,n,e){return Xo(this,t,n,!1,e)};function Ho(r,t,n,e,o){return o||ko(r,t,n,8),Go(r,t,n,e,52,8),n+8}at.prototype.writeDoubleLE=function(t,n,e){return Ho(this,t,n,!0,e)};at.prototype.writeDoubleBE=function(t,n,e){return Ho(this,t,n,!1,e)};at.prototype.copy=function(t,n,e,o){if(e||(e=0),!o&&o!==0&&(o=this.length),n>=t.length&&(n=t.length),n||(n=0),o>0&&o<e&&(o=e),o===e||t.length===0||this.length===0)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("sourceStart out of bounds");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),t.length-n<o-e&&(o=t.length-n+e);var i=o-e,a;if(this===t&&e<n&&n<o)for(a=i-1;a>=0;--a)t[a+n]=this[a+e];else if(i<1e3||!at.TYPED_ARRAY_SUPPORT)for(a=0;a<i;++a)t[a+n]=this[a+e];else Uint8Array.prototype.set.call(t,this.subarray(e,e+i),n);return i};at.prototype.fill=function(t,n,e,o){if(typeof t=="string"){if(typeof n=="string"?(o=n,n=0,e=this.length):typeof e=="string"&&(o=e,e=this.length),t.length===1){var i=t.charCodeAt(0);i<256&&(t=i)}if(o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!at.isEncoding(o))throw new TypeError("Unknown encoding: "+o)}else typeof t=="number"&&(t=t&255);if(n<0||this.length<n||this.length<e)throw new RangeError("Out of range index");if(e<=n)return this;n=n>>>0,e=e===void 0?this.length:e>>>0,t||(t=0);var a;if(typeof t=="number")for(a=n;a<e;++a)this[a]=t;else{var u=dr(t)?t:me(new at(t,o).toString()),s=u.length;for(a=0;a<e-n;++a)this[a+n]=u[a%s]}return this};var Uc=/[^+\/0-9A-Za-z-_]/g;function Ac(r){if(r=Pc(r).replace(Uc,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function Pc(r){return r.trim?r.trim():r.replace(/^\s+|\s+$/g,"")}function Dc(r){return r<16?"0"+r.toString(16):r.toString(16)}function me(r,t){t=t||1/0;for(var n,e=r.length,o=null,i=[],a=0;a<e;++a){if(n=r.charCodeAt(a),n>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(a+1===e){(t-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&i.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;i.push(n)}else if(n<2048){if((t-=2)<0)break;i.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;i.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return i}function Ic(r){for(var t=[],n=0;n<r.length;++n)t.push(r.charCodeAt(n)&255);return t}function mc(r,t){for(var n,e,o,i=[],a=0;a<r.length&&!((t-=2)<0);++a)n=r.charCodeAt(a),e=n>>8,o=n%256,i.push(o),i.push(e);return i}function $o(r){return oc(Ac(r))}function Fe(r,t,n,e){for(var o=0;o<e&&!(o+n>=t.length||o>=r.length);++o)t[o+n]=r[o];return o}function Rc(r){return r!==r}function Zo(r){return r!=null&&(!!r._isBuffer||Wo(r)||Lc(r))}function Wo(r){return!!r.constructor&&typeof r.constructor.isBuffer=="function"&&r.constructor.isBuffer(r)}function Lc(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&Wo(r.slice(0,0))}var Gc=Object.freeze({__proto__:null,Buffer:at,INSPECT_MAX_BYTES:zo,SlowBuffer:vc,isBuffer:Zo,kMaxLength:cc}),Dt=ec(function(r,t){var n=Gc.Buffer;Wn.__TYPEDARRAY_POOL||(Wn.__TYPEDARRAY_POOL={UINT8:$t([32,0]),UINT16:$t([32,0]),UINT32:$t([32,0]),BIGUINT64:$t([32,0]),INT8:$t([32,0]),INT16:$t([32,0]),INT32:$t([32,0]),BIGINT64:$t([32,0]),FLOAT:$t([32,0]),DOUBLE:$t([32,0]),DATA:$t([32,0]),UINT8C:$t([32,0]),BUFFER:$t([32,0])});var e=typeof Uint8ClampedArray<"u",o=typeof BigUint64Array<"u",i=typeof BigInt64Array<"u",a=Wn.__TYPEDARRAY_POOL;a.UINT8C||(a.UINT8C=$t([32,0])),a.BIGUINT64||(a.BIGUINT64=$t([32,0])),a.BIGINT64||(a.BIGINT64=$t([32,0])),a.BUFFER||(a.BUFFER=$t([32,0]));var u=a.DATA,s=a.BUFFER;t.free=function(j){if(n.isBuffer(j))s[jt.log2(j.length)].push(j);else{if(Object.prototype.toString.call(j)!=="[object ArrayBuffer]"&&(j=j.buffer),!j)return;var E=j.length||j.byteLength,c=jt.log2(E)|0;u[c].push(j)}};function l(X){if(X){var j=X.length||X.byteLength,E=jt.log2(j);u[E].push(X)}}function p(X){l(X.buffer)}t.freeUint8=t.freeUint16=t.freeUint32=t.freeBigUint64=t.freeInt8=t.freeInt16=t.freeInt32=t.freeBigInt64=t.freeFloat32=t.freeFloat=t.freeFloat64=t.freeDouble=t.freeUint8Clamped=t.freeDataView=p,t.freeArrayBuffer=l,t.freeBuffer=function(j){s[jt.log2(j.length)].push(j)},t.malloc=function(j,E){if(E===void 0||E==="arraybuffer")return _(j);switch(E){case"uint8":return F(j);case"uint16":return z(j);case"uint32":return I(j);case"int8":return m(j);case"int16":return L(j);case"int32":return W(j);case"float":case"float32":return V(j);case"double":case"float64":return H(j);case"uint8_clamped":return $(j);case"bigint64":return Q(j);case"biguint64":return Z(j);case"buffer":return et(j);case"data":case"dataview":return it(j);default:return null}return null};function _(j){var j=jt.nextPow2(j),E=jt.log2(j),c=u[E];return c.length>0?c.pop():new ArrayBuffer(j)}t.mallocArrayBuffer=_;function F(X){return new Uint8Array(_(X),0,X)}t.mallocUint8=F;function z(X){return new Uint16Array(_(2*X),0,X)}t.mallocUint16=z;function I(X){return new Uint32Array(_(4*X),0,X)}t.mallocUint32=I;function m(X){return new Int8Array(_(X),0,X)}t.mallocInt8=m;function L(X){return new Int16Array(_(2*X),0,X)}t.mallocInt16=L;function W(X){return new Int32Array(_(4*X),0,X)}t.mallocInt32=W;function V(X){return new Float32Array(_(4*X),0,X)}t.mallocFloat32=t.mallocFloat=V;function H(X){return new Float64Array(_(8*X),0,X)}t.mallocFloat64=t.mallocDouble=H;function $(X){return e?new Uint8ClampedArray(_(X),0,X):F(X)}t.mallocUint8Clamped=$;function Z(X){return o?new BigUint64Array(_(8*X),0,X):null}t.mallocBigUint64=Z;function Q(X){return i?new BigInt64Array(_(8*X),0,X):null}t.mallocBigInt64=Q;function it(X){return new DataView(_(X),0,X)}t.mallocDataView=it;function et(X){X=jt.nextPow2(X);var j=jt.log2(X),E=s[j];return E.length>0?E.pop():new n(X)}t.mallocBuffer=et,t.clearCache=function(){for(var j=0;j<32;++j)a.UINT8[j].length=0,a.UINT16[j].length=0,a.UINT32[j].length=0,a.INT8[j].length=0,a.INT16[j].length=0,a.INT32[j].length=0,a.FLOAT[j].length=0,a.DOUBLE[j].length=0,a.BIGUINT64[j].length=0,a.BIGINT64[j].length=0,a.UINT8C[j].length=0,u[j].length=0,s[j].length=0}}),Ep=Dt.clearCache,It=Dt,Sp=Dt.free,Up=Dt.freeArrayBuffer,Ap=Dt.freeBigInt64,Pp=Dt.freeBigUint64,Dp=Dt.freeBuffer,Ip=Dt.freeDataView,mp=Dt.freeDouble,Rp=Dt.freeFloat,Lp=Dt.freeFloat32,Gp=Dt.freeFloat64,Fp=Dt.freeInt16,zp=Dt.freeInt32,Op=Dt.freeInt8,Cp=Dt.freeUint16,Np=Dt.freeUint32,Vp=Dt.freeUint8,qp=Dt.freeUint8Clamped,Yp=Dt.malloc,kp=Dt.mallocArrayBuffer,Xp=Dt.mallocBigInt64,Hp=Dt.mallocBigUint64,$p=Dt.mallocBuffer,Zp=Dt.mallocDataView,Wp=Dt.mallocDouble,Qp=Dt.mallocFloat,Kp=Dt.mallocFloat32,Jp=Dt.mallocFloat64,jp=Dt.mallocInt16,tv=Dt.mallocInt32,rv=Dt.mallocInt8,ev=Dt.mallocUint16,nv=Dt.mallocUint32,iv=Dt.mallocUint8,ov=Dt.mallocUint8Clamped;var ke=Fc,Oe=32;function Fc(r,t){t<=4*Oe?Ce(0,t-1,r):Ne(0,t-1,r)}function Ce(r,t,n){for(var e=2*(r+1),o=r+1;o<=t;++o){for(var i=n[e++],a=n[e++],u=o,s=e-2;u-- >r;){var l=n[s-2],p=n[s-1];if(l<i)break;if(l===i&&p<a)break;n[s]=l,n[s+1]=p,s-=2}n[s]=i,n[s+1]=a}}function Qo(r,t,n){r*=2,t*=2;var e=n[r],o=n[r+1];n[r]=n[t],n[r+1]=n[t+1],n[t]=e,n[t+1]=o}function Ko(r,t,n){r*=2,t*=2,n[r]=n[t],n[r+1]=n[t+1]}function zc(r,t,n,e){r*=2,t*=2,n*=2;var o=e[r],i=e[r+1];e[r]=e[t],e[r+1]=e[t+1],e[t]=e[n],e[t+1]=e[n+1],e[n]=o,e[n+1]=i}function Jo(r,t,n,e,o){r*=2,t*=2,o[r]=o[t],o[t]=n,o[r+1]=o[t+1],o[t+1]=e}function br(r,t,n){r*=2,t*=2;var e=n[r],o=n[t];return e<o?!1:e===o?n[r+1]>n[t+1]:!0}function ze(r,t,n,e){r*=2;var o=e[r];return o<t?!0:o===t?e[r+1]<n:!1}function Ne(r,t,n){var e=(t-r+1)/6|0,o=r+e,i=t-e,a=r+t>>1,u=a-e,s=a+e,l=o,p=u,_=a,F=s,z=i,I=r+1,m=t-1,L=0;br(l,p,n)&&(L=l,l=p,p=L),br(F,z,n)&&(L=F,F=z,z=L),br(l,_,n)&&(L=l,l=_,_=L),br(p,_,n)&&(L=p,p=_,_=L),br(l,F,n)&&(L=l,l=F,F=L),br(_,F,n)&&(L=_,_=F,F=L),br(p,z,n)&&(L=p,p=z,z=L),br(p,_,n)&&(L=p,p=_,_=L),br(F,z,n)&&(L=F,F=z,z=L);for(var W=n[2*p],V=n[2*p+1],H=n[2*F],$=n[2*F+1],Z=2*l,Q=2*_,it=2*z,et=2*o,X=2*a,j=2*i,E=0;E<2;++E){var c=n[Z+E],w=n[Q+E],M=n[it+E];n[et+E]=c,n[X+E]=w,n[j+E]=M}Ko(u,r,n),Ko(s,t,n);for(var B=I;B<=m;++B)if(ze(B,W,V,n))B!==I&&Qo(B,I,n),++I;else if(!ze(B,H,$,n))for(;;)if(ze(m,H,$,n)){ze(m,W,V,n)?(zc(B,I,m,n),++I,--m):(Qo(B,m,n),--m);break}else{if(--m<B)break;continue}Jo(r,I-1,W,V,n),Jo(t,m+1,H,$,n),I-2-r<=Oe?Ce(r,I-2,n):Ne(r,I-2,n),t-(m+2)<=Oe?Ce(m+2,t,n):Ne(m+2,t,n),m-I<=Oe?Ce(I,m,n):Ne(I,m,n)}var cr={init:Oc,sweepBipartite:Cc,sweepComplete:Nc,scanBipartite:Vc,scanComplete:qc},ar=1<<28,Yr=1024,Qt=It.mallocInt32(Yr),Br=It.mallocInt32(Yr),Er=It.mallocInt32(Yr),Vr=It.mallocInt32(Yr),Jr=It.mallocInt32(Yr),pe=It.mallocInt32(Yr),_t=It.mallocDouble(Yr*8);function Oc(r){var t=jt.nextPow2(r);Qt.length<t&&(It.free(Qt),Qt=It.mallocInt32(t)),Br.length<t&&(It.free(Br),Br=It.mallocInt32(t)),Er.length<t&&(It.free(Er),Er=It.mallocInt32(t)),Vr.length<t&&(It.free(Vr),Vr=It.mallocInt32(t)),Jr.length<t&&(It.free(Jr),Jr=It.mallocInt32(t)),pe.length<t&&(It.free(pe),pe=It.mallocInt32(t));var n=8*t;_t.length<n&&(It.free(_t),_t=It.mallocDouble(n))}function jr(r,t,n,e){var o=t[e],i=r[n-1];r[o]=i,t[i]=o}function te(r,t,n,e){r[n]=e,t[e]=n}function Cc(r,t,n,e,o,i,a,u,s,l){for(var p=0,_=2*r,F=r-1,z=_-1,I=n;I<e;++I){var m=i[I],L=_*I;_t[p++]=o[L+F],_t[p++]=-(m+1),_t[p++]=o[L+z],_t[p++]=m}for(var I=a;I<u;++I){var m=l[I]+ar,W=_*I;_t[p++]=s[W+F],_t[p++]=-m,_t[p++]=s[W+z],_t[p++]=m}var V=p>>>1;ke(_t,V);for(var H=0,$=0,I=0;I<V;++I){var Z=_t[2*I+1]|0;if(Z>=ar)Z=Z-ar|0,jr(Er,Vr,$--,Z);else if(Z>=0)jr(Qt,Br,H--,Z);else if(Z<=-ar){Z=-Z-ar|0;for(var Q=0;Q<H;++Q){var it=t(Qt[Q],Z);if(it!==void 0)return it}te(Er,Vr,$++,Z)}else{Z=-Z-1|0;for(var Q=0;Q<$;++Q){var it=t(Z,Er[Q]);if(it!==void 0)return it}te(Qt,Br,H++,Z)}}}function Nc(r,t,n,e,o,i,a,u,s,l){for(var p=0,_=2*r,F=r-1,z=_-1,I=n;I<e;++I){var m=i[I]+1<<1,L=_*I;_t[p++]=o[L+F],_t[p++]=-m,_t[p++]=o[L+z],_t[p++]=m}for(var I=a;I<u;++I){var m=l[I]+1<<1,W=_*I;_t[p++]=s[W+F],_t[p++]=-m|1,_t[p++]=s[W+z],_t[p++]=m|1}var V=p>>>1;ke(_t,V);for(var H=0,$=0,Z=0,I=0;I<V;++I){var Q=_t[2*I+1]|0,it=Q&1;if(I<V-1&&Q>>1===_t[2*I+3]>>1&&(it=2,I+=1),Q<0){for(var et=-(Q>>1)-1,X=0;X<Z;++X){var j=t(Jr[X],et);if(j!==void 0)return j}if(it!==0)for(var X=0;X<H;++X){var j=t(Qt[X],et);if(j!==void 0)return j}if(it!==1)for(var X=0;X<$;++X){var j=t(Er[X],et);if(j!==void 0)return j}it===0?te(Qt,Br,H++,et):it===1?te(Er,Vr,$++,et):it===2&&te(Jr,pe,Z++,et)}else{var et=(Q>>1)-1;it===0?jr(Qt,Br,H--,et):it===1?jr(Er,Vr,$--,et):it===2&&jr(Jr,pe,Z--,et)}}}function Vc(r,t,n,e,o,i,a,u,s,l,p,_){var F=0,z=2*r,I=t,m=t+r,L=1,W=1;e?W=ar:L=ar;for(var V=o;V<i;++V){var H=V+L,$=z*V;_t[F++]=a[$+I],_t[F++]=-H,_t[F++]=a[$+m],_t[F++]=H}for(var V=s;V<l;++V){var H=V+W,Z=z*V;_t[F++]=p[Z+I],_t[F++]=-H}var Q=F>>>1;ke(_t,Q);for(var it=0,V=0;V<Q;++V){var et=_t[2*V+1]|0;if(et<0){var H=-et,X=!1;if(H>=ar?(X=!e,H-=ar):(X=!!e,H-=1),X)te(Qt,Br,it++,H);else{var j=_[H],E=z*H,c=p[E+t+1],w=p[E+t+1+r];t:for(var M=0;M<it;++M){var B=Qt[M],S=z*B;if(!(w<a[S+t+1]||a[S+t+1+r]<c)){for(var O=t+2;O<r;++O)if(p[E+O+r]<a[S+O]||a[S+O+r]<p[E+O])continue t;var N=u[B],A;if(e?A=n(j,N):A=n(N,j),A!==void 0)return A}}}}else jr(Qt,Br,it--,et-L)}}function qc(r,t,n,e,o,i,a,u,s,l,p){for(var _=0,F=2*r,z=t,I=t+r,m=e;m<o;++m){var L=m+ar,W=F*m;_t[_++]=i[W+z],_t[_++]=-L,_t[_++]=i[W+I],_t[_++]=L}for(var m=u;m<s;++m){var L=m+1,V=F*m;_t[_++]=l[V+z],_t[_++]=-L}var H=_>>>1;ke(_t,H);for(var $=0,m=0;m<H;++m){var Z=_t[2*m+1]|0;if(Z<0){var L=-Z;if(L>=ar)Qt[$++]=L-ar;else{L-=1;var Q=p[L],it=F*L,et=l[it+t+1],X=l[it+t+1+r];t:for(var j=0;j<$;++j){var E=Qt[j],c=a[E];if(c===Q)break;var w=F*E;if(!(X<i[w+t+1]||i[w+t+1+r]<et)){for(var M=t+2;M<r;++M)if(l[it+M+r]<i[w+M]||i[w+M+r]<l[it+M])continue t;var B=n(c,Q);if(B!==void 0)return B}}}}else{for(var L=Z-ar,j=$-1;j>=0;--j)if(Qt[j]===L){for(var M=j+1;M<$;++M)Qt[M-1]=Qt[M];break}--$}}}var Nr="d",Kr="ax",ia="vv",ti="fp",le="es",Ve="rs",ii="re",fe="rb",oa="ri",Wr="rp",qe="bs",oi="be",he="bb",aa="bi",Qr="bp",ri="rv",ei="Q",ni=[Nr,Kr,ia,Ve,ii,fe,oa,qe,oi,he,aa];function Yc(r,t,n){var e="bruteForce"+(r?"Red":"Blue")+(t?"Flip":"")+(n?"Full":""),o=["function ",e,"(",ni.join(),"){","var ",le,"=2*",Nr,";"],i="for(var i="+Ve+","+Wr+"="+le+"*"+Ve+";i<"+ii+";++i,"+Wr+"+="+le+"){var x0="+fe+"["+Kr+"+"+Wr+"],x1="+fe+"["+Kr+"+"+Wr+"+"+Nr+"],xi="+oa+"[i];",a="for(var j="+qe+","+Qr+"="+le+"*"+qe+";j<"+oi+";++j,"+Qr+"+="+le+"){var y0="+he+"["+Kr+"+"+Qr+"],"+(n?"y1="+he+"["+Kr+"+"+Qr+"+"+Nr+"],":"")+"yi="+aa+"[j];";return r?o.push(i,ei,":",a):o.push(a,ei,":",i),n?o.push("if(y1<x0||x1<y0)continue;"):t?o.push("if(y0<=x0||x1<y0)continue;"):o.push("if(y0<x0||x1<y0)continue;"),o.push("for(var k="+Kr+"+1;k<"+Nr+";++k){var r0="+fe+"[k+"+Wr+"],r1="+fe+"[k+"+Nr+"+"+Wr+"],b0="+he+"[k+"+Qr+"],b1="+he+"[k+"+Nr+"+"+Qr+"];if(r1<b0||b1<r0)continue "+ei+";}var "+ri+"="+ia+"("),t?o.push("yi,xi"):o.push("xi,yi"),o.push(");if("+ri+"!==void 0)return "+ri+";}}}"),{name:e,code:o.join("")}}function ua(r){var t="bruteForce"+(r?"Full":"Partial"),n=[],e=ni.slice();r||e.splice(3,0,ti);var o=["function "+t+"("+e.join()+"){"];function i(s,l){var p=Yc(s,l,r);n.push(p.code),o.push("return "+p.name+"("+ni.join()+");")}o.push("if("+ii+"-"+Ve+">"+oi+"-"+qe+"){"),r?(i(!0,!1),o.push("}else{"),i(!1,!1)):(o.push("if("+ti+"){"),i(!0,!0),o.push("}else{"),i(!0,!1),o.push("}}else{if("+ti+"){"),i(!1,!0),o.push("}else{"),i(!1,!1),o.push("}")),o.push("}}return "+t);var a=n.join("")+o.join(""),u=new Function(a);return u()}var kc=ua(!1),Xc=ua(!0),sa={partial:kc,full:Xc},kr=$c,Hc="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 $c(r,t){var n="abcdef".split("").concat(t),e=[];return r.indexOf("lo")>=0&&e.push("lo=e[k+n]"),r.indexOf("hi")>=0&&e.push("hi=e[k+o]"),n.push(Hc.replace("_",e.join()).replace("$",r)),Function.apply(void 0,n)}var Zc=Kc,jo=kr("lo<p0",["p0"]),Wc=8;function Qc(r,t,n,e,o,i){for(var a=2*r,u=a*(n+1)+t,s=n+1;s<e;++s,u+=a)for(var l=o[u],p=s,_=a*(s-1);p>n&&o[_+t]>l;--p,_-=a){for(var F=_,z=_+a,I=0;I<a;++I,++F,++z){var m=o[F];o[F]=o[z],o[z]=m}var L=i[p];i[p]=i[p-1],i[p-1]=L}}function Kc(r,t,n,e,o,i){if(e<=n+1)return n;for(var a=n,u=e,s=e+n>>>1,l=2*r,p=s,_=o[l*s+t];a<u;){if(u-a<Wc){Qc(r,t,a,u,o,i),_=o[l*s+t];break}var F=u-a,z=Math.random()*F+a|0,I=o[l*z+t],m=Math.random()*F+a|0,L=o[l*m+t],W=Math.random()*F+a|0,V=o[l*W+t];I<=L?V>=L?(p=m,_=L):I>=V?(p=z,_=I):(p=W,_=V):L>=V?(p=m,_=L):V>=I?(p=z,_=I):(p=W,_=V);for(var Z=l*(u-1),Q=l*p,H=0;H<l;++H,++Z,++Q){var $=o[Z];o[Z]=o[Q],o[Q]=$}var it=i[u-1];i[u-1]=i[p],i[p]=it,p=jo(r,t,a,u-1,o,i,_);for(var Z=l*(u-1),Q=l*p,H=0;H<l;++H,++Z,++Q){var $=o[Z];o[Z]=o[Q],o[Q]=$}var it=i[u-1];if(i[u-1]=i[p],i[p]=it,s<p){for(u=p-1;a<u&&o[l*(u-1)+t]===_;)u-=1;u+=1}else if(p<s)for(a=p+1;a<u&&o[l*a+t]===_;)a+=1;else break}return jo(r,t,n,s,o,i,o[l*s+t])}var Jc=ll,jc=sa.partial,tl=sa.full,ta=128,rl=1<<22,el=1<<22,nl=kr("!(lo>=p0)&&!(p1>=hi)",["p0","p1"]),ra=kr("lo===p0",["p0"]),il=kr("lo<p0",["p0"]),ol=kr("hi<=p0",["p0"]),ea=kr("lo<=p0&&p0<=hi",["p0"]),al=kr("lo<p0&&p0<=hi",["p0"]),ai=6,ui=2,ca=1024,tr=It.mallocInt32(ca),qr=It.mallocDouble(ca);function ul(r,t){var n=8*jt.log2(t+1)*(r+1)|0,e=jt.nextPow2(ai*n);tr.length<e&&(It.free(tr),tr=It.mallocInt32(e));var o=jt.nextPow2(ui*n);qr.length<o&&(It.free(qr),qr=It.mallocDouble(o))}function hr(r,t,n,e,o,i,a,u,s){var l=ai*r;tr[l]=t,tr[l+1]=n,tr[l+2]=e,tr[l+3]=o,tr[l+4]=i,tr[l+5]=a;var p=ui*r;qr[p]=u,qr[p+1]=s}function sl(r,t,n,e,o,i,a,u,s,l,p){var _=2*r,F=s*_,z=l[F+t];t:for(var I=o,m=o*_;I<i;++I,m+=_){var L=a[m+t],W=a[m+t+r];if(!(z<L||W<z)&&!(e&&z===L)){for(var V=u[I],H=t+1;H<r;++H){var L=a[m+H],W=a[m+H+r],$=l[F+H],Z=l[F+H+r];if(W<$||Z<L)continue t}var Q;if(e?Q=n(p,V):Q=n(V,p),Q!==void 0)return Q}}}function cl(r,t,n,e,o,i,a,u,s,l){var p=2*r,_=u*p,F=s[_+t];t:for(var z=e,I=e*p;z<o;++z,I+=p){var m=a[z];if(m!==l){var L=i[I+t],W=i[I+t+r];if(!(F<L||W<F)){for(var V=t+1;V<r;++V){var L=i[I+V],W=i[I+V+r],H=s[_+V],$=s[_+V+r];if(W<H||$<L)continue t}var Z=n(m,l);if(Z!==void 0)return Z}}}}function ll(r,t,n,e,o,i,a,u,s){ul(r,e+a);var l=0,p=2*r,_;for(hr(l++,0,0,e,0,a,n?16:0,-1/0,1/0),n||hr(l++,0,0,a,0,e,1,-1/0,1/0);l>0;){l-=1;var F=l*ai,z=tr[F],I=tr[F+1],m=tr[F+2],L=tr[F+3],W=tr[F+4],V=tr[F+5],H=l*ui,$=qr[H],Z=qr[H+1],Q=V&1,it=!!(V&16),et=o,X=i,j=u,E=s;if(Q&&(et=u,X=s,j=o,E=i),!(V&2&&(m=il(r,z,I,m,et,X,Z),I>=m))&&!(V&4&&(I=ol(r,z,I,m,et,X,$),I>=m))){var c=m-I,w=W-L;if(it){if(r*c*(c+w)<el){if(_=cr.scanComplete(r,z,t,I,m,et,X,L,W,j,E),_!==void 0)return _;continue}}else if(r*Math.min(c,w)<ta){if(_=jc(r,z,t,Q,I,m,et,X,L,W,j,E),_!==void 0)return _;continue}else if(r*c*w<rl){if(_=cr.scanBipartite(r,z,t,Q,I,m,et,X,L,W,j,E),_!==void 0)return _;continue}var M=nl(r,z,I,m,et,X,$,Z);if(I<M)if(r*(M-I)<ta){if(_=tl(r,z+1,t,I,M,et,X,L,W,j,E),_!==void 0)return _}else if(z===r-2){if(Q?_=cr.sweepBipartite(r,t,L,W,j,E,I,M,et,X):_=cr.sweepBipartite(r,t,I,M,et,X,L,W,j,E),_!==void 0)return _}else hr(l++,z+1,I,M,L,W,Q,-1/0,1/0),hr(l++,z+1,L,W,I,M,Q^1,-1/0,1/0);if(M<m){var B=Zc(r,z,L,W,j,E),S=j[p*B+z],O=ra(r,z,B,W,j,E,S);if(O<W&&hr(l++,z,M,m,O,W,(Q|4)+(it?16:0),S,Z),L<B&&hr(l++,z,M,m,L,B,(Q|2)+(it?16:0),$,S),B+1===O){if(it?_=cl(r,z,t,M,m,et,X,B,j,E[B]):_=sl(r,z,t,Q,M,m,et,X,B,j,E[B]),_!==void 0)return _}else if(B<O){var N;if(it){if(N=ea(r,z,M,m,et,X,S),M<N){var A=ra(r,z,M,N,et,X,S);if(z===r-2){if(M<A&&(_=cr.sweepComplete(r,t,M,A,et,X,B,O,j,E),_!==void 0)||A<N&&(_=cr.sweepBipartite(r,t,A,N,et,X,B,O,j,E),_!==void 0))return _}else M<A&&hr(l++,z+1,M,A,B,O,16,-1/0,1/0),A<N&&(hr(l++,z+1,A,N,B,O,0,-1/0,1/0),hr(l++,z+1,B,O,A,N,1,-1/0,1/0))}}else Q?N=al(r,z,M,m,et,X,S):N=ea(r,z,M,m,et,X,S),M<N&&(z===r-2?Q?_=cr.sweepBipartite(r,t,B,O,j,E,M,N,et,X):_=cr.sweepBipartite(r,t,M,N,et,X,B,O,j,E):(hr(l++,z+1,M,N,B,O,Q,-1/0,1/0),hr(l++,z+1,B,O,M,N,Q^1,-1/0,1/0)))}}}}}var fl=gl;function hl(r,t){for(var n=0;n<r;++n)if(!(t[n]<=t[n+r]))return!0;return!1}function na(r,t,n,e){for(var o=0,i=0,a=0,u=r.length;a<u;++a){var s=r[a];if(!hl(t,s)){for(var l=0;l<2*t;++l)n[o++]=s[l];e[i++]=a}}return i}function Ye(r,t,n,e){var o=r.length,i=t.length;if(!(o<=0||i<=0)){var a=r[0].length>>>1;if(!(a<=0)){var u,s=It.mallocDouble(2*a*o),l=It.mallocInt32(o);if(o=na(r,a,s,l),o>0){if(a===1&&e)cr.init(o),u=cr.sweepComplete(a,n,0,o,s,l,0,o,s,l);else{var p=It.mallocDouble(2*a*i),_=It.mallocInt32(i);i=na(t,a,p,_),i>0&&(cr.init(o+i),a===1?u=cr.sweepBipartite(a,n,0,o,s,l,0,i,p,_):u=Jc(a,n,e,o,s,l,i,p,_),It.free(p),It.free(_))}It.free(s),It.free(l)}return u}}}var ve;function la(r,t){ve.push([r,t])}function pl(r){return ve=[],Ye(r,r,la,!0),ve}function vl(r,t){return ve=[],Ye(r,t,la,!1),ve}function gl(r,t,n){switch(arguments.length){case 1:return pl(r);case 2:return typeof t=="function"?Ye(r,r,t,!0):vl(r,t);case 3:return Ye(r,t,n,!1);default:throw new Error("box-intersect: Invalid arguments")}}var Xe=fl;var wl=dl,fa=+(Math.pow(2,27)+1);function dl(r,t,n){var e=r*t,o=fa*r,i=o-r,a=o-i,u=r-a,s=fa*t,l=s-t,p=s-l,_=t-p,F=e-a*p,z=F-u*p,I=z-a*_,m=u*_-I;return n?(n[0]=m,n[1]=e,n):[m,e]}var re=wl;var yl=Ml;function xl(r,t){var n=r+t,e=n-r,o=n-e,i=t-e,a=r-o,u=a+i;return u?[u,n]:[n]}function Ml(r,t){var n=r.length|0,e=t.length|0;if(n===1&&e===1)return xl(r[0],t[0]);var o=n+e,i=new Array(o),a=0,u=0,s=0,l=Math.abs,p=r[u],_=l(p),F=t[s],z=l(F),I,m;_<z?(m=p,u+=1,u<n&&(p=r[u],_=l(p))):(m=F,s+=1,s<e&&(F=t[s],z=l(F))),u<n&&_<z||s>=e?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=t[s],z=l(F)));for(var L=I+m,W=L-I,V=m-W,H=V,$=L,Z,Q,it,et,X;u<n&&s<e;)_<z?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=t[s],z=l(F))),m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z;for(;u<n;)I=p,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,u+=1,u<n&&(p=r[u]);for(;s<e;)I=F,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,s+=1,s<e&&(F=t[s]);return H&&(i[a++]=H),$&&(i[a++]=$),a||(i[a++]=0),i.length=a,i}var ha=yl;var _l=Tl;function Tl(r,t,n){var e=r+t,o=e-r,i=e-o,a=t-o,u=r-i;return n?(n[0]=u+a,n[1]=e,n):[u+a,e]}var pa=_l;var bl=Bl;function Bl(r,t){var n=r.length;if(n===1){var e=re(r[0],t);return e[0]?e:[e[1]]}var o=new Array(2*n),i=[.1,.1],a=[.1,.1],u=0;re(r[0],t,i),i[0]&&(o[u++]=i[0]);for(var s=1;s<n;++s){re(r[s],t,a);var l=i[1];pa(l,a[0],i),i[0]&&(o[u++]=i[0]);var p=a[1],_=i[1],F=p+_,z=F-p,I=_-z;i[1]=F,I&&(o[u++]=I)}return i[1]&&(o[u++]=i[1]),u===0&&(o[u++]=0),o.length=u,o}var va=bl;var El=Ul;function Sl(r,t){var n=r+t,e=n-r,o=n-e,i=t-e,a=r-o,u=a+i;return u?[u,n]:[n]}function Ul(r,t){var n=r.length|0,e=t.length|0;if(n===1&&e===1)return Sl(r[0],-t[0]);var o=n+e,i=new Array(o),a=0,u=0,s=0,l=Math.abs,p=r[u],_=l(p),F=-t[s],z=l(F),I,m;_<z?(m=p,u+=1,u<n&&(p=r[u],_=l(p))):(m=F,s+=1,s<e&&(F=-t[s],z=l(F))),u<n&&_<z||s>=e?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=-t[s],z=l(F)));for(var L=I+m,W=L-I,V=m-W,H=V,$=L,Z,Q,it,et,X;u<n&&s<e;)_<z?(I=p,u+=1,u<n&&(p=r[u],_=l(p))):(I=F,s+=1,s<e&&(F=-t[s],z=l(F))),m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z;for(;u<n;)I=p,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,u+=1,u<n&&(p=r[u]);for(;s<e;)I=F,m=H,L=I+m,W=L-I,V=m-W,V&&(i[a++]=V),Z=$+L,Q=Z-$,it=Z-Q,et=L-Q,X=$-it,H=X+et,$=Z,s+=1,s<e&&(F=-t[s]);return H&&(i[a++]=H),$&&(i[a++]=$),a||(i[a++]=0),i.length=a,i}var ga=El;function Al(r,t,n){return n={path:t,exports:{},require:function(e,o){return Pl(e,o??n.path)}},r(n,n.exports),n.exports}function Pl(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var Dl=Al(function(r){var t=5,n=11102230246251565e-32,e=(3+16*n)*n,o=(7+56*n)*n;function i(L,W){for(var V=new Array(L.length-1),H=1;H<L.length;++H)for(var $=V[H-1]=new Array(L.length-1),Z=0,Q=0;Z<L.length;++Z)Z!==W&&($[Q++]=L[H][Z]);return V}function a(L){for(var W=new Array(L),V=0;V<L;++V){W[V]=new Array(L);for(var H=0;H<L;++H)W[V][H]=["m",H,"[",L-V-1,"]"].join("")}return W}function u(L){return L&1?"-":""}function s(L){if(L.length===1)return L[0];if(L.length===2)return["sum(",L[0],",",L[1],")"].join("");var W=L.length>>1;return["sum(",s(L.slice(0,W)),",",s(L.slice(W)),")"].join("")}function l(L){if(L.length===2)return[["sum(prod(",L[0][0],",",L[1][1],"),prod(-",L[0][1],",",L[1][0],"))"].join("")];for(var W=[],V=0;V<L.length;++V)W.push(["scale(",s(l(i(L,V))),",",u(V),L[0][V],")"].join(""));return W}function p(L){for(var W=[],V=[],H=a(L),$=[],Z=0;Z<L;++Z)Z&1?V.push.apply(V,l(i(H,Z))):W.push.apply(W,l(i(H,Z))),$.push("m"+Z);var Q=s(W),it=s(V),et="orientation"+L+"Exact",X=["function ",et,"(",$.join(),"){var p=",Q,",n=",it,",d=sub(p,n);return d[d.length-1];};return ",et].join(""),j=new Function("sum","prod","scale","sub",X);return j(ha,re,va,ga)}var _=p(3),F=p(4),z=[function(){return 0},function(){return 0},function(W,V){return V[0]-W[0]},function(W,V,H){var $=(W[1]-H[1])*(V[0]-H[0]),Z=(W[0]-H[0])*(V[1]-H[1]),Q=$-Z,it;if($>0){if(Z<=0)return Q;it=$+Z}else if($<0){if(Z>=0)return Q;it=-($+Z)}else return Q;var et=e*it;return Q>=et||Q<=-et?Q:_(W,V,H)},function(W,V,H,$){var Z=W[0]-$[0],Q=V[0]-$[0],it=H[0]-$[0],et=W[1]-$[1],X=V[1]-$[1],j=H[1]-$[1],E=W[2]-$[2],c=V[2]-$[2],w=H[2]-$[2],M=Q*j,B=it*X,S=it*et,O=Z*j,N=Z*X,A=Q*et,h=E*(M-B)+c*(S-O)+w*(N-A),D=(Math.abs(M)+Math.abs(B))*Math.abs(E)+(Math.abs(S)+Math.abs(O))*Math.abs(c)+(Math.abs(N)+Math.abs(A))*Math.abs(w),ot=o*D;return h>ot||-h>ot?h:F(W,V,H,$)}];function I(L){var W=z[L.length];return W||(W=z[L.length]=p(L.length)),W.apply(void 0,L)}function m(){for(;z.length<=t;)z.push(p(z.length));for(var L=[],W=["slow"],V=0;V<=t;++V)L.push("a"+V),W.push("o"+V);for(var H=["function getOrientation(",L.join(),"){switch(arguments.length){case 0:case 1:return 0;"],V=2;V<=t;++V)H.push("case ",V,":return o",V,"(",L.slice(0,V).join(),");");H.push("}var s=new Array(arguments.length);for(var i=0;i<arguments.length;++i){s[i]=arguments[i]};return slow(s);}return getOrientation"),W.push(H.join(""));var $=Function.apply(void 0,W);r.exports=$.apply(void 0,[I].concat(z));for(var V=0;V<=t;++V)r.exports[V]=z[V]}m()}),wa=Dl;var Il=Rl,He=wa[3];function ml(r,t,n,e){for(var o=0;o<2;++o){var i=r[o],a=t[o],u=Math.min(i,a),s=Math.max(i,a),l=n[o],p=e[o],_=Math.min(l,p),F=Math.max(l,p);if(F<u||s<_)return!1}return!0}function Rl(r,t,n,e){var o=He(r,n,e),i=He(t,n,e);if(o>0&&i>0||o<0&&i<0)return!1;var a=He(n,r,t),u=He(e,r,t);return a>0&&u>0||a<0&&u<0?!1:o===0&&i===0&&a===0&&u===0?ml(r,t,n,e):!0}var si=Il;var Ll=typeof globalThis<"u"?globalThis:typeof window<"u"?window:typeof global<"u"?global:typeof self<"u"?self:{};function Gl(r,t,n){return n={path:t,exports:{},require:function(e,o){return zl(e,o??n.path)}},r(n,n.exports),n.exports}function Fl(r){return r&&Object.prototype.hasOwnProperty.call(r,"default")&&Object.keys(r).length===1?r.default:r}function zl(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var Ol={},Cl=Object.freeze({__proto__:null,default:Ol}),Nl=Fl(Cl),da=Gl(function(r){(function(t,n){function e(E,c){if(!E)throw new Error(c||"Assertion failed")}function o(E,c){E.super_=c;var w=function(){};w.prototype=c.prototype,E.prototype=new w,E.prototype.constructor=E}function i(E,c,w){if(i.isBN(E))return E;this.negative=0,this.words=null,this.length=0,this.red=null,E!==null&&((c==="le"||c==="be")&&(w=c,c=10),this._init(E||0,c||10,w||"be"))}typeof t=="object"?t.exports=i:n.BN=i,i.BN=i,i.wordSize=26;var a;try{typeof window<"u"&&typeof window.Buffer<"u"?a=window.Buffer:a=Nl.Buffer}catch{}i.isBN=function(c){return c instanceof i?!0:c!==null&&typeof c=="object"&&c.constructor.wordSize===i.wordSize&&Array.isArray(c.words)},i.max=function(c,w){return c.cmp(w)>0?c:w},i.min=function(c,w){return c.cmp(w)<0?c:w},i.prototype._init=function(c,w,M){if(typeof c=="number")return this._initNumber(c,w,M);if(typeof c=="object")return this._initArray(c,w,M);w==="hex"&&(w=16),e(w===(w|0)&&w>=2&&w<=36),c=c.toString().replace(/\s+/g,"");var B=0;c[0]==="-"&&(B++,this.negative=1),B<c.length&&(w===16?this._parseHex(c,B,M):(this._parseBase(c,w,B),M==="le"&&this._initArray(this.toArray(),w,M)))},i.prototype._initNumber=function(c,w,M){c<0&&(this.negative=1,c=-c),c<67108864?(this.words=[c&67108863],this.length=1):c<4503599627370496?(this.words=[c&67108863,c/67108864&67108863],this.length=2):(e(c<9007199254740992),this.words=[c&67108863,c/67108864&67108863,1],this.length=3),M==="le"&&this._initArray(this.toArray(),w,M)},i.prototype._initArray=function(c,w,M){if(e(typeof c.length=="number"),c.length<=0)return this.words=[0],this.length=1,this;this.length=Math.ceil(c.length/3),this.words=new Array(this.length);for(var B=0;B<this.length;B++)this.words[B]=0;var S,O,N=0;if(M==="be")for(B=c.length-1,S=0;B>=0;B-=3)O=c[B]|c[B-1]<<8|c[B-2]<<16,this.words[S]|=O<<N&67108863,this.words[S+1]=O>>>26-N&67108863,N+=24,N>=26&&(N-=26,S++);else if(M==="le")for(B=0,S=0;B<c.length;B+=3)O=c[B]|c[B+1]<<8|c[B+2]<<16,this.words[S]|=O<<N&67108863,this.words[S+1]=O>>>26-N&67108863,N+=24,N>=26&&(N-=26,S++);return this.strip()};function u(E,c){var w=E.charCodeAt(c);return w>=65&&w<=70?w-55:w>=97&&w<=102?w-87:w-48&15}function s(E,c,w){var M=u(E,w);return w-1>=c&&(M|=u(E,w-1)<<4),M}i.prototype._parseHex=function(c,w,M){this.length=Math.ceil((c.length-w)/6),this.words=new Array(this.length);for(var B=0;B<this.length;B++)this.words[B]=0;var S=0,O=0,N;if(M==="be")for(B=c.length-1;B>=w;B-=2)N=s(c,w,B)<<S,this.words[O]|=N&67108863,S>=18?(S-=18,O+=1,this.words[O]|=N>>>26):S+=8;else{var A=c.length-w;for(B=A%2===0?w+1:w;B<c.length;B+=2)N=s(c,w,B)<<S,this.words[O]|=N&67108863,S>=18?(S-=18,O+=1,this.words[O]|=N>>>26):S+=8}this.strip()};function l(E,c,w,M){for(var B=0,S=Math.min(E.length,w),O=c;O<S;O++){var N=E.charCodeAt(O)-48;B*=M,N>=49?B+=N-49+10:N>=17?B+=N-17+10:B+=N}return B}i.prototype._parseBase=function(c,w,M){this.words=[0],this.length=1;for(var B=0,S=1;S<=67108863;S*=w)B++;B--,S=S/w|0;for(var O=c.length-M,N=O%B,A=Math.min(O,O-N)+M,h=0,D=M;D<A;D+=B)h=l(c,D,D+B,w),this.imuln(S),this.words[0]+h<67108864?this.words[0]+=h:this._iaddn(h);if(N!==0){var ot=1;for(h=l(c,D,c.length,w),D=0;D<N;D++)ot*=w;this.imuln(ot),this.words[0]+h<67108864?this.words[0]+=h:this._iaddn(h)}this.strip()},i.prototype.copy=function(c){c.words=new Array(this.length);for(var w=0;w<this.length;w++)c.words[w]=this.words[w];c.length=this.length,c.negative=this.negative,c.red=this.red},i.prototype.clone=function(){var c=new i(null);return this.copy(c),c},i.prototype._expand=function(c){for(;this.length<c;)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"],_=[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(c,w){c=c||10,w=w|0||1;var M;if(c===16||c==="hex"){M="";for(var B=0,S=0,O=0;O<this.length;O++){var N=this.words[O],A=((N<<B|S)&16777215).toString(16);S=N>>>24-B&16777215,S!==0||O!==this.length-1?M=p[6-A.length]+A+M:M=A+M,B+=2,B>=26&&(B-=26,O--)}for(S!==0&&(M=S.toString(16)+M);M.length%w!==0;)M="0"+M;return this.negative!==0&&(M="-"+M),M}if(c===(c|0)&&c>=2&&c<=36){var h=_[c],D=F[c];M="";var ot=this.clone();for(ot.negative=0;!ot.isZero();){var ct=ot.modn(D).toString(c);ot=ot.idivn(D),ot.isZero()?M=ct+M:M=p[h-ct.length]+ct+M}for(this.isZero()&&(M="0"+M);M.length%w!==0;)M="0"+M;return this.negative!==0&&(M="-"+M),M}e(!1,"Base should be between 2 and 36")},i.prototype.toNumber=function(){var c=this.words[0];return this.length===2?c+=this.words[1]*67108864:this.length===3&&this.words[2]===1?c+=4503599627370496+this.words[1]*67108864:this.length>2&&e(!1,"Number can only safely store up to 53 bits"),this.negative!==0?-c:c},i.prototype.toJSON=function(){return this.toString(16)},i.prototype.toBuffer=function(c,w){return e(typeof a<"u"),this.toArrayLike(a,c,w)},i.prototype.toArray=function(c,w){return this.toArrayLike(Array,c,w)},i.prototype.toArrayLike=function(c,w,M){var B=this.byteLength(),S=M||Math.max(1,B);e(B<=S,"byte array longer than desired length"),e(S>0,"Requested array length <= 0"),this.strip();var O=w==="le",N=new c(S),A,h,D=this.clone();if(O){for(h=0;!D.isZero();h++)A=D.andln(255),D.iushrn(8),N[h]=A;for(;h<S;h++)N[h]=0}else{for(h=0;h<S-B;h++)N[h]=0;for(h=0;!D.isZero();h++)A=D.andln(255),D.iushrn(8),N[S-h-1]=A}return N},Math.clz32?i.prototype._countBits=function(c){return 32-Math.clz32(c)}:i.prototype._countBits=function(c){var w=c,M=0;return w>=4096&&(M+=13,w>>>=13),w>=64&&(M+=7,w>>>=7),w>=8&&(M+=4,w>>>=4),w>=2&&(M+=2,w>>>=2),M+w},i.prototype._zeroBits=function(c){if(c===0)return 26;var w=c,M=0;return w&8191||(M+=13,w>>>=13),w&127||(M+=7,w>>>=7),w&15||(M+=4,w>>>=4),w&3||(M+=2,w>>>=2),w&1||M++,M},i.prototype.bitLength=function(){var c=this.words[this.length-1],w=this._countBits(c);return(this.length-1)*26+w};function z(E){for(var c=new Array(E.bitLength()),w=0;w<c.length;w++){var M=w/26|0,B=w%26;c[w]=(E.words[M]&1<<B)>>>B}return c}i.prototype.zeroBits=function(){if(this.isZero())return 0;for(var c=0,w=0;w<this.length;w++){var M=this._zeroBits(this.words[w]);if(c+=M,M!==26)break}return c},i.prototype.byteLength=function(){return Math.ceil(this.bitLength()/8)},i.prototype.toTwos=function(c){return this.negative!==0?this.abs().inotn(c).iaddn(1):this.clone()},i.prototype.fromTwos=function(c){return this.testn(c-1)?this.notn(c).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(c){for(;this.length<c.length;)this.words[this.length++]=0;for(var w=0;w<c.length;w++)this.words[w]=this.words[w]|c.words[w];return this.strip()},i.prototype.ior=function(c){return e((this.negative|c.negative)===0),this.iuor(c)},i.prototype.or=function(c){return this.length>c.length?this.clone().ior(c):c.clone().ior(this)},i.prototype.uor=function(c){return this.length>c.length?this.clone().iuor(c):c.clone().iuor(this)},i.prototype.iuand=function(c){var w;this.length>c.length?w=c:w=this;for(var M=0;M<w.length;M++)this.words[M]=this.words[M]&c.words[M];return this.length=w.length,this.strip()},i.prototype.iand=function(c){return e((this.negative|c.negative)===0),this.iuand(c)},i.prototype.and=function(c){return this.length>c.length?this.clone().iand(c):c.clone().iand(this)},i.prototype.uand=function(c){return this.length>c.length?this.clone().iuand(c):c.clone().iuand(this)},i.prototype.iuxor=function(c){var w,M;this.length>c.length?(w=this,M=c):(w=c,M=this);for(var B=0;B<M.length;B++)this.words[B]=w.words[B]^M.words[B];if(this!==w)for(;B<w.length;B++)this.words[B]=w.words[B];return this.length=w.length,this.strip()},i.prototype.ixor=function(c){return e((this.negative|c.negative)===0),this.iuxor(c)},i.prototype.xor=function(c){return this.length>c.length?this.clone().ixor(c):c.clone().ixor(this)},i.prototype.uxor=function(c){return this.length>c.length?this.clone().iuxor(c):c.clone().iuxor(this)},i.prototype.inotn=function(c){e(typeof c=="number"&&c>=0);var w=Math.ceil(c/26)|0,M=c%26;this._expand(w),M>0&&w--;for(var B=0;B<w;B++)this.words[B]=~this.words[B]&67108863;return M>0&&(this.words[B]=~this.words[B]&67108863>>26-M),this.strip()},i.prototype.notn=function(c){return this.clone().inotn(c)},i.prototype.setn=function(c,w){e(typeof c=="number"&&c>=0);var M=c/26|0,B=c%26;return this._expand(M+1),w?this.words[M]=this.words[M]|1<<B:this.words[M]=this.words[M]&~(1<<B),this.strip()},i.prototype.iadd=function(c){var w;if(this.negative!==0&&c.negative===0)return this.negative=0,w=this.isub(c),this.negative^=1,this._normSign();if(this.negative===0&&c.negative!==0)return c.negative=0,w=this.isub(c),c.negative=1,w._normSign();var M,B;this.length>c.length?(M=this,B=c):(M=c,B=this);for(var S=0,O=0;O<B.length;O++)w=(M.words[O]|0)+(B.words[O]|0)+S,this.words[O]=w&67108863,S=w>>>26;for(;S!==0&&O<M.length;O++)w=(M.words[O]|0)+S,this.words[O]=w&67108863,S=w>>>26;if(this.length=M.length,S!==0)this.words[this.length]=S,this.length++;else if(M!==this)for(;O<M.length;O++)this.words[O]=M.words[O];return this},i.prototype.add=function(c){var w;return c.negative!==0&&this.negative===0?(c.negative=0,w=this.sub(c),c.negative^=1,w):c.negative===0&&this.negative!==0?(this.negative=0,w=c.sub(this),this.negative=1,w):this.length>c.length?this.clone().iadd(c):c.clone().iadd(this)},i.prototype.isub=function(c){if(c.negative!==0){c.negative=0;var w=this.iadd(c);return c.negative=1,w._normSign()}else if(this.negative!==0)return this.negative=0,this.iadd(c),this.negative=1,this._normSign();var M=this.cmp(c);if(M===0)return this.negative=0,this.length=1,this.words[0]=0,this;var B,S;M>0?(B=this,S=c):(B=c,S=this);for(var O=0,N=0;N<S.length;N++)w=(B.words[N]|0)-(S.words[N]|0)+O,O=w>>26,this.words[N]=w&67108863;for(;O!==0&&N<B.length;N++)w=(B.words[N]|0)+O,O=w>>26,this.words[N]=w&67108863;if(O===0&&N<B.length&&B!==this)for(;N<B.length;N++)this.words[N]=B.words[N];return this.length=Math.max(this.length,N),B!==this&&(this.negative=1),this.strip()},i.prototype.sub=function(c){return this.clone().isub(c)};function I(E,c,w){w.negative=c.negative^E.negative;var M=E.length+c.length|0;w.length=M,M=M-1|0;var B=E.words[0]|0,S=c.words[0]|0,O=B*S,N=O&67108863,A=O/67108864|0;w.words[0]=N;for(var h=1;h<M;h++){for(var D=A>>>26,ot=A&67108863,ct=Math.min(h,c.length-1),st=Math.max(0,h-E.length+1);st<=ct;st++){var vt=h-st|0;B=E.words[vt]|0,S=c.words[st]|0,O=B*S+ot,D+=O/67108864|0,ot=O&67108863}w.words[h]=ot|0,A=D|0}return A!==0?w.words[h]=A|0:w.length--,w.strip()}var m=function(c,w,M){var B=c.words,S=w.words,O=M.words,N=0,A,h,D,ot=B[0]|0,ct=ot&8191,st=ot>>>13,vt=B[1]|0,pt=vt&8191,d=vt>>>13,G=B[2]|0,g=G&8191,y=G>>>13,R=B[3]|0,C=R&8191,K=R>>>13,f=B[4]|0,T=f&8191,v=f>>>13,x=B[5]|0,U=x&8191,q=x>>>13,rt=B[6]|0,b=rt&8191,P=rt>>>13,k=B[7]|0,Y=k&8191,J=k>>>13,nt=B[8]|0,tt=nt&8191,ft=nt>>>13,wt=B[9]|0,lt=wt&8191,ht=wt>>>13,yt=S[0]|0,gt=yt&8191,dt=yt>>>13,qt=S[1]|0,xt=qt&8191,Tt=qt>>>13,kt=S[2]|0,bt=kt&8191,Bt=kt>>>13,Xt=S[3]|0,Et=Xt&8191,Ut=Xt>>>13,Ht=S[4]|0,At=Ht&8191,Pt=Ht>>>13,Kt=S[5]|0,mt=Kt&8191,Rt=Kt>>>13,Rr=S[6]|0,Gt=Rr&8191,Ft=Rr>>>13,Lr=S[7]|0,zt=Lr&8191,Ot=Lr>>>13,Gr=S[8]|0,Ct=Gr&8191,Nt=Gr>>>13,ee=S[9]|0,Vt=ee&8191,St=ee>>>13;M.negative=c.negative^w.negative,M.length=19,A=Math.imul(ct,gt),h=Math.imul(ct,dt),h=h+Math.imul(st,gt)|0,D=Math.imul(st,dt);var ln=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(ln>>>26)|0,ln&=67108863,A=Math.imul(pt,gt),h=Math.imul(pt,dt),h=h+Math.imul(d,gt)|0,D=Math.imul(d,dt),A=A+Math.imul(ct,xt)|0,h=h+Math.imul(ct,Tt)|0,h=h+Math.imul(st,xt)|0,D=D+Math.imul(st,Tt)|0;var fn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(fn>>>26)|0,fn&=67108863,A=Math.imul(g,gt),h=Math.imul(g,dt),h=h+Math.imul(y,gt)|0,D=Math.imul(y,dt),A=A+Math.imul(pt,xt)|0,h=h+Math.imul(pt,Tt)|0,h=h+Math.imul(d,xt)|0,D=D+Math.imul(d,Tt)|0,A=A+Math.imul(ct,bt)|0,h=h+Math.imul(ct,Bt)|0,h=h+Math.imul(st,bt)|0,D=D+Math.imul(st,Bt)|0;var hn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(hn>>>26)|0,hn&=67108863,A=Math.imul(C,gt),h=Math.imul(C,dt),h=h+Math.imul(K,gt)|0,D=Math.imul(K,dt),A=A+Math.imul(g,xt)|0,h=h+Math.imul(g,Tt)|0,h=h+Math.imul(y,xt)|0,D=D+Math.imul(y,Tt)|0,A=A+Math.imul(pt,bt)|0,h=h+Math.imul(pt,Bt)|0,h=h+Math.imul(d,bt)|0,D=D+Math.imul(d,Bt)|0,A=A+Math.imul(ct,Et)|0,h=h+Math.imul(ct,Ut)|0,h=h+Math.imul(st,Et)|0,D=D+Math.imul(st,Ut)|0;var pn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(pn>>>26)|0,pn&=67108863,A=Math.imul(T,gt),h=Math.imul(T,dt),h=h+Math.imul(v,gt)|0,D=Math.imul(v,dt),A=A+Math.imul(C,xt)|0,h=h+Math.imul(C,Tt)|0,h=h+Math.imul(K,xt)|0,D=D+Math.imul(K,Tt)|0,A=A+Math.imul(g,bt)|0,h=h+Math.imul(g,Bt)|0,h=h+Math.imul(y,bt)|0,D=D+Math.imul(y,Bt)|0,A=A+Math.imul(pt,Et)|0,h=h+Math.imul(pt,Ut)|0,h=h+Math.imul(d,Et)|0,D=D+Math.imul(d,Ut)|0,A=A+Math.imul(ct,At)|0,h=h+Math.imul(ct,Pt)|0,h=h+Math.imul(st,At)|0,D=D+Math.imul(st,Pt)|0;var vn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(vn>>>26)|0,vn&=67108863,A=Math.imul(U,gt),h=Math.imul(U,dt),h=h+Math.imul(q,gt)|0,D=Math.imul(q,dt),A=A+Math.imul(T,xt)|0,h=h+Math.imul(T,Tt)|0,h=h+Math.imul(v,xt)|0,D=D+Math.imul(v,Tt)|0,A=A+Math.imul(C,bt)|0,h=h+Math.imul(C,Bt)|0,h=h+Math.imul(K,bt)|0,D=D+Math.imul(K,Bt)|0,A=A+Math.imul(g,Et)|0,h=h+Math.imul(g,Ut)|0,h=h+Math.imul(y,Et)|0,D=D+Math.imul(y,Ut)|0,A=A+Math.imul(pt,At)|0,h=h+Math.imul(pt,Pt)|0,h=h+Math.imul(d,At)|0,D=D+Math.imul(d,Pt)|0,A=A+Math.imul(ct,mt)|0,h=h+Math.imul(ct,Rt)|0,h=h+Math.imul(st,mt)|0,D=D+Math.imul(st,Rt)|0;var gn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(gn>>>26)|0,gn&=67108863,A=Math.imul(b,gt),h=Math.imul(b,dt),h=h+Math.imul(P,gt)|0,D=Math.imul(P,dt),A=A+Math.imul(U,xt)|0,h=h+Math.imul(U,Tt)|0,h=h+Math.imul(q,xt)|0,D=D+Math.imul(q,Tt)|0,A=A+Math.imul(T,bt)|0,h=h+Math.imul(T,Bt)|0,h=h+Math.imul(v,bt)|0,D=D+Math.imul(v,Bt)|0,A=A+Math.imul(C,Et)|0,h=h+Math.imul(C,Ut)|0,h=h+Math.imul(K,Et)|0,D=D+Math.imul(K,Ut)|0,A=A+Math.imul(g,At)|0,h=h+Math.imul(g,Pt)|0,h=h+Math.imul(y,At)|0,D=D+Math.imul(y,Pt)|0,A=A+Math.imul(pt,mt)|0,h=h+Math.imul(pt,Rt)|0,h=h+Math.imul(d,mt)|0,D=D+Math.imul(d,Rt)|0,A=A+Math.imul(ct,Gt)|0,h=h+Math.imul(ct,Ft)|0,h=h+Math.imul(st,Gt)|0,D=D+Math.imul(st,Ft)|0;var wn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(wn>>>26)|0,wn&=67108863,A=Math.imul(Y,gt),h=Math.imul(Y,dt),h=h+Math.imul(J,gt)|0,D=Math.imul(J,dt),A=A+Math.imul(b,xt)|0,h=h+Math.imul(b,Tt)|0,h=h+Math.imul(P,xt)|0,D=D+Math.imul(P,Tt)|0,A=A+Math.imul(U,bt)|0,h=h+Math.imul(U,Bt)|0,h=h+Math.imul(q,bt)|0,D=D+Math.imul(q,Bt)|0,A=A+Math.imul(T,Et)|0,h=h+Math.imul(T,Ut)|0,h=h+Math.imul(v,Et)|0,D=D+Math.imul(v,Ut)|0,A=A+Math.imul(C,At)|0,h=h+Math.imul(C,Pt)|0,h=h+Math.imul(K,At)|0,D=D+Math.imul(K,Pt)|0,A=A+Math.imul(g,mt)|0,h=h+Math.imul(g,Rt)|0,h=h+Math.imul(y,mt)|0,D=D+Math.imul(y,Rt)|0,A=A+Math.imul(pt,Gt)|0,h=h+Math.imul(pt,Ft)|0,h=h+Math.imul(d,Gt)|0,D=D+Math.imul(d,Ft)|0,A=A+Math.imul(ct,zt)|0,h=h+Math.imul(ct,Ot)|0,h=h+Math.imul(st,zt)|0,D=D+Math.imul(st,Ot)|0;var dn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(dn>>>26)|0,dn&=67108863,A=Math.imul(tt,gt),h=Math.imul(tt,dt),h=h+Math.imul(ft,gt)|0,D=Math.imul(ft,dt),A=A+Math.imul(Y,xt)|0,h=h+Math.imul(Y,Tt)|0,h=h+Math.imul(J,xt)|0,D=D+Math.imul(J,Tt)|0,A=A+Math.imul(b,bt)|0,h=h+Math.imul(b,Bt)|0,h=h+Math.imul(P,bt)|0,D=D+Math.imul(P,Bt)|0,A=A+Math.imul(U,Et)|0,h=h+Math.imul(U,Ut)|0,h=h+Math.imul(q,Et)|0,D=D+Math.imul(q,Ut)|0,A=A+Math.imul(T,At)|0,h=h+Math.imul(T,Pt)|0,h=h+Math.imul(v,At)|0,D=D+Math.imul(v,Pt)|0,A=A+Math.imul(C,mt)|0,h=h+Math.imul(C,Rt)|0,h=h+Math.imul(K,mt)|0,D=D+Math.imul(K,Rt)|0,A=A+Math.imul(g,Gt)|0,h=h+Math.imul(g,Ft)|0,h=h+Math.imul(y,Gt)|0,D=D+Math.imul(y,Ft)|0,A=A+Math.imul(pt,zt)|0,h=h+Math.imul(pt,Ot)|0,h=h+Math.imul(d,zt)|0,D=D+Math.imul(d,Ot)|0,A=A+Math.imul(ct,Ct)|0,h=h+Math.imul(ct,Nt)|0,h=h+Math.imul(st,Ct)|0,D=D+Math.imul(st,Nt)|0;var yn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(yn>>>26)|0,yn&=67108863,A=Math.imul(lt,gt),h=Math.imul(lt,dt),h=h+Math.imul(ht,gt)|0,D=Math.imul(ht,dt),A=A+Math.imul(tt,xt)|0,h=h+Math.imul(tt,Tt)|0,h=h+Math.imul(ft,xt)|0,D=D+Math.imul(ft,Tt)|0,A=A+Math.imul(Y,bt)|0,h=h+Math.imul(Y,Bt)|0,h=h+Math.imul(J,bt)|0,D=D+Math.imul(J,Bt)|0,A=A+Math.imul(b,Et)|0,h=h+Math.imul(b,Ut)|0,h=h+Math.imul(P,Et)|0,D=D+Math.imul(P,Ut)|0,A=A+Math.imul(U,At)|0,h=h+Math.imul(U,Pt)|0,h=h+Math.imul(q,At)|0,D=D+Math.imul(q,Pt)|0,A=A+Math.imul(T,mt)|0,h=h+Math.imul(T,Rt)|0,h=h+Math.imul(v,mt)|0,D=D+Math.imul(v,Rt)|0,A=A+Math.imul(C,Gt)|0,h=h+Math.imul(C,Ft)|0,h=h+Math.imul(K,Gt)|0,D=D+Math.imul(K,Ft)|0,A=A+Math.imul(g,zt)|0,h=h+Math.imul(g,Ot)|0,h=h+Math.imul(y,zt)|0,D=D+Math.imul(y,Ot)|0,A=A+Math.imul(pt,Ct)|0,h=h+Math.imul(pt,Nt)|0,h=h+Math.imul(d,Ct)|0,D=D+Math.imul(d,Nt)|0,A=A+Math.imul(ct,Vt)|0,h=h+Math.imul(ct,St)|0,h=h+Math.imul(st,Vt)|0,D=D+Math.imul(st,St)|0;var xn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(xn>>>26)|0,xn&=67108863,A=Math.imul(lt,xt),h=Math.imul(lt,Tt),h=h+Math.imul(ht,xt)|0,D=Math.imul(ht,Tt),A=A+Math.imul(tt,bt)|0,h=h+Math.imul(tt,Bt)|0,h=h+Math.imul(ft,bt)|0,D=D+Math.imul(ft,Bt)|0,A=A+Math.imul(Y,Et)|0,h=h+Math.imul(Y,Ut)|0,h=h+Math.imul(J,Et)|0,D=D+Math.imul(J,Ut)|0,A=A+Math.imul(b,At)|0,h=h+Math.imul(b,Pt)|0,h=h+Math.imul(P,At)|0,D=D+Math.imul(P,Pt)|0,A=A+Math.imul(U,mt)|0,h=h+Math.imul(U,Rt)|0,h=h+Math.imul(q,mt)|0,D=D+Math.imul(q,Rt)|0,A=A+Math.imul(T,Gt)|0,h=h+Math.imul(T,Ft)|0,h=h+Math.imul(v,Gt)|0,D=D+Math.imul(v,Ft)|0,A=A+Math.imul(C,zt)|0,h=h+Math.imul(C,Ot)|0,h=h+Math.imul(K,zt)|0,D=D+Math.imul(K,Ot)|0,A=A+Math.imul(g,Ct)|0,h=h+Math.imul(g,Nt)|0,h=h+Math.imul(y,Ct)|0,D=D+Math.imul(y,Nt)|0,A=A+Math.imul(pt,Vt)|0,h=h+Math.imul(pt,St)|0,h=h+Math.imul(d,Vt)|0,D=D+Math.imul(d,St)|0;var Mn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(Mn>>>26)|0,Mn&=67108863,A=Math.imul(lt,bt),h=Math.imul(lt,Bt),h=h+Math.imul(ht,bt)|0,D=Math.imul(ht,Bt),A=A+Math.imul(tt,Et)|0,h=h+Math.imul(tt,Ut)|0,h=h+Math.imul(ft,Et)|0,D=D+Math.imul(ft,Ut)|0,A=A+Math.imul(Y,At)|0,h=h+Math.imul(Y,Pt)|0,h=h+Math.imul(J,At)|0,D=D+Math.imul(J,Pt)|0,A=A+Math.imul(b,mt)|0,h=h+Math.imul(b,Rt)|0,h=h+Math.imul(P,mt)|0,D=D+Math.imul(P,Rt)|0,A=A+Math.imul(U,Gt)|0,h=h+Math.imul(U,Ft)|0,h=h+Math.imul(q,Gt)|0,D=D+Math.imul(q,Ft)|0,A=A+Math.imul(T,zt)|0,h=h+Math.imul(T,Ot)|0,h=h+Math.imul(v,zt)|0,D=D+Math.imul(v,Ot)|0,A=A+Math.imul(C,Ct)|0,h=h+Math.imul(C,Nt)|0,h=h+Math.imul(K,Ct)|0,D=D+Math.imul(K,Nt)|0,A=A+Math.imul(g,Vt)|0,h=h+Math.imul(g,St)|0,h=h+Math.imul(y,Vt)|0,D=D+Math.imul(y,St)|0;var _n=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(_n>>>26)|0,_n&=67108863,A=Math.imul(lt,Et),h=Math.imul(lt,Ut),h=h+Math.imul(ht,Et)|0,D=Math.imul(ht,Ut),A=A+Math.imul(tt,At)|0,h=h+Math.imul(tt,Pt)|0,h=h+Math.imul(ft,At)|0,D=D+Math.imul(ft,Pt)|0,A=A+Math.imul(Y,mt)|0,h=h+Math.imul(Y,Rt)|0,h=h+Math.imul(J,mt)|0,D=D+Math.imul(J,Rt)|0,A=A+Math.imul(b,Gt)|0,h=h+Math.imul(b,Ft)|0,h=h+Math.imul(P,Gt)|0,D=D+Math.imul(P,Ft)|0,A=A+Math.imul(U,zt)|0,h=h+Math.imul(U,Ot)|0,h=h+Math.imul(q,zt)|0,D=D+Math.imul(q,Ot)|0,A=A+Math.imul(T,Ct)|0,h=h+Math.imul(T,Nt)|0,h=h+Math.imul(v,Ct)|0,D=D+Math.imul(v,Nt)|0,A=A+Math.imul(C,Vt)|0,h=h+Math.imul(C,St)|0,h=h+Math.imul(K,Vt)|0,D=D+Math.imul(K,St)|0;var Tn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(Tn>>>26)|0,Tn&=67108863,A=Math.imul(lt,At),h=Math.imul(lt,Pt),h=h+Math.imul(ht,At)|0,D=Math.imul(ht,Pt),A=A+Math.imul(tt,mt)|0,h=h+Math.imul(tt,Rt)|0,h=h+Math.imul(ft,mt)|0,D=D+Math.imul(ft,Rt)|0,A=A+Math.imul(Y,Gt)|0,h=h+Math.imul(Y,Ft)|0,h=h+Math.imul(J,Gt)|0,D=D+Math.imul(J,Ft)|0,A=A+Math.imul(b,zt)|0,h=h+Math.imul(b,Ot)|0,h=h+Math.imul(P,zt)|0,D=D+Math.imul(P,Ot)|0,A=A+Math.imul(U,Ct)|0,h=h+Math.imul(U,Nt)|0,h=h+Math.imul(q,Ct)|0,D=D+Math.imul(q,Nt)|0,A=A+Math.imul(T,Vt)|0,h=h+Math.imul(T,St)|0,h=h+Math.imul(v,Vt)|0,D=D+Math.imul(v,St)|0;var bn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(bn>>>26)|0,bn&=67108863,A=Math.imul(lt,mt),h=Math.imul(lt,Rt),h=h+Math.imul(ht,mt)|0,D=Math.imul(ht,Rt),A=A+Math.imul(tt,Gt)|0,h=h+Math.imul(tt,Ft)|0,h=h+Math.imul(ft,Gt)|0,D=D+Math.imul(ft,Ft)|0,A=A+Math.imul(Y,zt)|0,h=h+Math.imul(Y,Ot)|0,h=h+Math.imul(J,zt)|0,D=D+Math.imul(J,Ot)|0,A=A+Math.imul(b,Ct)|0,h=h+Math.imul(b,Nt)|0,h=h+Math.imul(P,Ct)|0,D=D+Math.imul(P,Nt)|0,A=A+Math.imul(U,Vt)|0,h=h+Math.imul(U,St)|0,h=h+Math.imul(q,Vt)|0,D=D+Math.imul(q,St)|0;var Bn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(Bn>>>26)|0,Bn&=67108863,A=Math.imul(lt,Gt),h=Math.imul(lt,Ft),h=h+Math.imul(ht,Gt)|0,D=Math.imul(ht,Ft),A=A+Math.imul(tt,zt)|0,h=h+Math.imul(tt,Ot)|0,h=h+Math.imul(ft,zt)|0,D=D+Math.imul(ft,Ot)|0,A=A+Math.imul(Y,Ct)|0,h=h+Math.imul(Y,Nt)|0,h=h+Math.imul(J,Ct)|0,D=D+Math.imul(J,Nt)|0,A=A+Math.imul(b,Vt)|0,h=h+Math.imul(b,St)|0,h=h+Math.imul(P,Vt)|0,D=D+Math.imul(P,St)|0;var En=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(En>>>26)|0,En&=67108863,A=Math.imul(lt,zt),h=Math.imul(lt,Ot),h=h+Math.imul(ht,zt)|0,D=Math.imul(ht,Ot),A=A+Math.imul(tt,Ct)|0,h=h+Math.imul(tt,Nt)|0,h=h+Math.imul(ft,Ct)|0,D=D+Math.imul(ft,Nt)|0,A=A+Math.imul(Y,Vt)|0,h=h+Math.imul(Y,St)|0,h=h+Math.imul(J,Vt)|0,D=D+Math.imul(J,St)|0;var Sn=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(Sn>>>26)|0,Sn&=67108863,A=Math.imul(lt,Ct),h=Math.imul(lt,Nt),h=h+Math.imul(ht,Ct)|0,D=Math.imul(ht,Nt),A=A+Math.imul(tt,Vt)|0,h=h+Math.imul(tt,St)|0,h=h+Math.imul(ft,Vt)|0,D=D+Math.imul(ft,St)|0;var Un=(N+A|0)+((h&8191)<<13)|0;N=(D+(h>>>13)|0)+(Un>>>26)|0,Un&=67108863,A=Math.imul(lt,Vt),h=Math.imul(lt,St),h=h+Math.imul(ht,Vt)|0,D=Math.imul(ht,St);var An=(N+A|0)+((h&8191)<<13)|0;return N=(D+(h>>>13)|0)+(An>>>26)|0,An&=67108863,O[0]=ln,O[1]=fn,O[2]=hn,O[3]=pn,O[4]=vn,O[5]=gn,O[6]=wn,O[7]=dn,O[8]=yn,O[9]=xn,O[10]=Mn,O[11]=_n,O[12]=Tn,O[13]=bn,O[14]=Bn,O[15]=En,O[16]=Sn,O[17]=Un,O[18]=An,N!==0&&(O[19]=N,M.length++),M};Math.imul||(m=I);function L(E,c,w){w.negative=c.negative^E.negative,w.length=E.length+c.length;for(var M=0,B=0,S=0;S<w.length-1;S++){var O=B;B=0;for(var N=M&67108863,A=Math.min(S,c.length-1),h=Math.max(0,S-E.length+1);h<=A;h++){var D=S-h,ot=E.words[D]|0,ct=c.words[h]|0,st=ot*ct,vt=st&67108863;O=O+(st/67108864|0)|0,vt=vt+N|0,N=vt&67108863,O=O+(vt>>>26)|0,B+=O>>>26,O&=67108863}w.words[S]=N,M=O,O=B}return M!==0?w.words[S]=M:w.length--,w.strip()}function W(E,c,w){var M=new V;return M.mulp(E,c,w)}i.prototype.mulTo=function(c,w){var M,B=this.length+c.length;return this.length===10&&c.length===10?M=m(this,c,w):B<63?M=I(this,c,w):B<1024?M=L(this,c,w):M=W(this,c,w),M};function V(E,c){this.x=E,this.y=c}V.prototype.makeRBT=function(c){for(var w=new Array(c),M=i.prototype._countBits(c)-1,B=0;B<c;B++)w[B]=this.revBin(B,M,c);return w},V.prototype.revBin=function(c,w,M){if(c===0||c===M-1)return c;for(var B=0,S=0;S<w;S++)B|=(c&1)<<w-S-1,c>>=1;return B},V.prototype.permute=function(c,w,M,B,S,O){for(var N=0;N<O;N++)B[N]=w[c[N]],S[N]=M[c[N]]},V.prototype.transform=function(c,w,M,B,S,O){this.permute(O,c,w,M,B,S);for(var N=1;N<S;N<<=1)for(var A=N<<1,h=Math.cos(2*Math.PI/A),D=Math.sin(2*Math.PI/A),ot=0;ot<S;ot+=A)for(var ct=h,st=D,vt=0;vt<N;vt++){var pt=M[ot+vt],d=B[ot+vt],G=M[ot+vt+N],g=B[ot+vt+N],y=ct*G-st*g;g=ct*g+st*G,G=y,M[ot+vt]=pt+G,B[ot+vt]=d+g,M[ot+vt+N]=pt-G,B[ot+vt+N]=d-g,vt!==A&&(y=h*ct-D*st,st=h*st+D*ct,ct=y)}},V.prototype.guessLen13b=function(c,w){var M=Math.max(w,c)|1,B=M&1,S=0;for(M=M/2|0;M;M=M>>>1)S++;return 1<<S+1+B},V.prototype.conjugate=function(c,w,M){if(!(M<=1))for(var B=0;B<M/2;B++){var S=c[B];c[B]=c[M-B-1],c[M-B-1]=S,S=w[B],w[B]=-w[M-B-1],w[M-B-1]=-S}},V.prototype.normalize13b=function(c,w){for(var M=0,B=0;B<w/2;B++){var S=Math.round(c[2*B+1]/w)*8192+Math.round(c[2*B]/w)+M;c[B]=S&67108863,S<67108864?M=0:M=S/67108864|0}return c},V.prototype.convert13b=function(c,w,M,B){for(var S=0,O=0;O<w;O++)S=S+(c[O]|0),M[2*O]=S&8191,S=S>>>13,M[2*O+1]=S&8191,S=S>>>13;for(O=2*w;O<B;++O)M[O]=0;e(S===0),e((S&-8192)===0)},V.prototype.stub=function(c){for(var w=new Array(c),M=0;M<c;M++)w[M]=0;return w},V.prototype.mulp=function(c,w,M){var B=2*this.guessLen13b(c.length,w.length),S=this.makeRBT(B),O=this.stub(B),N=new Array(B),A=new Array(B),h=new Array(B),D=new Array(B),ot=new Array(B),ct=new Array(B),st=M.words;st.length=B,this.convert13b(c.words,c.length,N,B),this.convert13b(w.words,w.length,D,B),this.transform(N,O,A,h,B,S),this.transform(D,O,ot,ct,B,S);for(var vt=0;vt<B;vt++){var pt=A[vt]*ot[vt]-h[vt]*ct[vt];h[vt]=A[vt]*ct[vt]+h[vt]*ot[vt],A[vt]=pt}return this.conjugate(A,h,B),this.transform(A,h,st,O,B,S),this.conjugate(st,O,B),this.normalize13b(st,B),M.negative=c.negative^w.negative,M.length=c.length+w.length,M.strip()},i.prototype.mul=function(c){var w=new i(null);return w.words=new Array(this.length+c.length),this.mulTo(c,w)},i.prototype.mulf=function(c){var w=new i(null);return w.words=new Array(this.length+c.length),W(this,c,w)},i.prototype.imul=function(c){return this.clone().mulTo(c,this)},i.prototype.imuln=function(c){e(typeof c=="number"),e(c<67108864);for(var w=0,M=0;M<this.length;M++){var B=(this.words[M]|0)*c,S=(B&67108863)+(w&67108863);w>>=26,w+=B/67108864|0,w+=S>>>26,this.words[M]=S&67108863}return w!==0&&(this.words[M]=w,this.length++),this},i.prototype.muln=function(c){return this.clone().imuln(c)},i.prototype.sqr=function(){return this.mul(this)},i.prototype.isqr=function(){return this.imul(this.clone())},i.prototype.pow=function(c){var w=z(c);if(w.length===0)return new i(1);for(var M=this,B=0;B<w.length&&w[B]===0;B++,M=M.sqr());if(++B<w.length)for(var S=M.sqr();B<w.length;B++,S=S.sqr())w[B]!==0&&(M=M.mul(S));return M},i.prototype.iushln=function(c){e(typeof c=="number"&&c>=0);var w=c%26,M=(c-w)/26,B=67108863>>>26-w<<26-w,S;if(w!==0){var O=0;for(S=0;S<this.length;S++){var N=this.words[S]&B,A=(this.words[S]|0)-N<<w;this.words[S]=A|O,O=N>>>26-w}O&&(this.words[S]=O,this.length++)}if(M!==0){for(S=this.length-1;S>=0;S--)this.words[S+M]=this.words[S];for(S=0;S<M;S++)this.words[S]=0;this.length+=M}return this.strip()},i.prototype.ishln=function(c){return e(this.negative===0),this.iushln(c)},i.prototype.iushrn=function(c,w,M){e(typeof c=="number"&&c>=0);var B;w?B=(w-w%26)/26:B=0;var S=c%26,O=Math.min((c-S)/26,this.length),N=67108863^67108863>>>S<<S,A=M;if(B-=O,B=Math.max(0,B),A){for(var h=0;h<O;h++)A.words[h]=this.words[h];A.length=O}if(O!==0)if(this.length>O)for(this.length-=O,h=0;h<this.length;h++)this.words[h]=this.words[h+O];else this.words[0]=0,this.length=1;var D=0;for(h=this.length-1;h>=0&&(D!==0||h>=B);h--){var ot=this.words[h]|0;this.words[h]=D<<26-S|ot>>>S,D=ot&N}return A&&D!==0&&(A.words[A.length++]=D),this.length===0&&(this.words[0]=0,this.length=1),this.strip()},i.prototype.ishrn=function(c,w,M){return e(this.negative===0),this.iushrn(c,w,M)},i.prototype.shln=function(c){return this.clone().ishln(c)},i.prototype.ushln=function(c){return this.clone().iushln(c)},i.prototype.shrn=function(c){return this.clone().ishrn(c)},i.prototype.ushrn=function(c){return this.clone().iushrn(c)},i.prototype.testn=function(c){e(typeof c=="number"&&c>=0);var w=c%26,M=(c-w)/26,B=1<<w;if(this.length<=M)return!1;var S=this.words[M];return!!(S&B)},i.prototype.imaskn=function(c){e(typeof c=="number"&&c>=0);var w=c%26,M=(c-w)/26;if(e(this.negative===0,"imaskn works only with positive numbers"),this.length<=M)return this;if(w!==0&&M++,this.length=Math.min(M,this.length),w!==0){var B=67108863^67108863>>>w<<w;this.words[this.length-1]&=B}return this.strip()},i.prototype.maskn=function(c){return this.clone().imaskn(c)},i.prototype.iaddn=function(c){return e(typeof c=="number"),e(c<67108864),c<0?this.isubn(-c):this.negative!==0?this.length===1&&(this.words[0]|0)<c?(this.words[0]=c-(this.words[0]|0),this.negative=0,this):(this.negative=0,this.isubn(c),this.negative=1,this):this._iaddn(c)},i.prototype._iaddn=function(c){this.words[0]+=c;for(var w=0;w<this.length&&this.words[w]>=67108864;w++)this.words[w]-=67108864,w===this.length-1?this.words[w+1]=1:this.words[w+1]++;return this.length=Math.max(this.length,w+1),this},i.prototype.isubn=function(c){if(e(typeof c=="number"),e(c<67108864),c<0)return this.iaddn(-c);if(this.negative!==0)return this.negative=0,this.iaddn(c),this.negative=1,this;if(this.words[0]-=c,this.length===1&&this.words[0]<0)this.words[0]=-this.words[0],this.negative=1;else for(var w=0;w<this.length&&this.words[w]<0;w++)this.words[w]+=67108864,this.words[w+1]-=1;return this.strip()},i.prototype.addn=function(c){return this.clone().iaddn(c)},i.prototype.subn=function(c){return this.clone().isubn(c)},i.prototype.iabs=function(){return this.negative=0,this},i.prototype.abs=function(){return this.clone().iabs()},i.prototype._ishlnsubmul=function(c,w,M){var B=c.length+M,S;this._expand(B);var O,N=0;for(S=0;S<c.length;S++){O=(this.words[S+M]|0)+N;var A=(c.words[S]|0)*w;O-=A&67108863,N=(O>>26)-(A/67108864|0),this.words[S+M]=O&67108863}for(;S<this.length-M;S++)O=(this.words[S+M]|0)+N,N=O>>26,this.words[S+M]=O&67108863;if(N===0)return this.strip();for(e(N===-1),N=0,S=0;S<this.length;S++)O=-(this.words[S]|0)+N,N=O>>26,this.words[S]=O&67108863;return this.negative=1,this.strip()},i.prototype._wordDiv=function(c,w){var M=this.length-c.length,B=this.clone(),S=c,O=S.words[S.length-1]|0,N=this._countBits(O);M=26-N,M!==0&&(S=S.ushln(M),B.iushln(M),O=S.words[S.length-1]|0);var A=B.length-S.length,h;if(w!=="mod"){h=new i(null),h.length=A+1,h.words=new Array(h.length);for(var D=0;D<h.length;D++)h.words[D]=0}var ot=B.clone()._ishlnsubmul(S,1,A);ot.negative===0&&(B=ot,h&&(h.words[A]=1));for(var ct=A-1;ct>=0;ct--){var st=(B.words[S.length+ct]|0)*67108864+(B.words[S.length+ct-1]|0);for(st=Math.min(st/O|0,67108863),B._ishlnsubmul(S,st,ct);B.negative!==0;)st--,B.negative=0,B._ishlnsubmul(S,1,ct),B.isZero()||(B.negative^=1);h&&(h.words[ct]=st)}return h&&h.strip(),B.strip(),w!=="div"&&M!==0&&B.iushrn(M),{div:h||null,mod:B}},i.prototype.divmod=function(c,w,M){if(e(!c.isZero()),this.isZero())return{div:new i(0),mod:new i(0)};var B,S,O;return this.negative!==0&&c.negative===0?(O=this.neg().divmod(c,w),w!=="mod"&&(B=O.div.neg()),w!=="div"&&(S=O.mod.neg(),M&&S.negative!==0&&S.iadd(c)),{div:B,mod:S}):this.negative===0&&c.negative!==0?(O=this.divmod(c.neg(),w),w!=="mod"&&(B=O.div.neg()),{div:B,mod:O.mod}):this.negative&c.negative?(O=this.neg().divmod(c.neg(),w),w!=="div"&&(S=O.mod.neg(),M&&S.negative!==0&&S.isub(c)),{div:O.div,mod:S}):c.length>this.length||this.cmp(c)<0?{div:new i(0),mod:this}:c.length===1?w==="div"?{div:this.divn(c.words[0]),mod:null}:w==="mod"?{div:null,mod:new i(this.modn(c.words[0]))}:{div:this.divn(c.words[0]),mod:new i(this.modn(c.words[0]))}:this._wordDiv(c,w)},i.prototype.div=function(c){return this.divmod(c,"div",!1).div},i.prototype.mod=function(c){return this.divmod(c,"mod",!1).mod},i.prototype.umod=function(c){return this.divmod(c,"mod",!0).mod},i.prototype.divRound=function(c){var w=this.divmod(c);if(w.mod.isZero())return w.div;var M=w.div.negative!==0?w.mod.isub(c):w.mod,B=c.ushrn(1),S=c.andln(1),O=M.cmp(B);return O<0||S===1&&O===0?w.div:w.div.negative!==0?w.div.isubn(1):w.div.iaddn(1)},i.prototype.modn=function(c){e(c<=67108863);for(var w=(1<<26)%c,M=0,B=this.length-1;B>=0;B--)M=(w*M+(this.words[B]|0))%c;return M},i.prototype.idivn=function(c){e(c<=67108863);for(var w=0,M=this.length-1;M>=0;M--){var B=(this.words[M]|0)+w*67108864;this.words[M]=B/c|0,w=B%c}return this.strip()},i.prototype.divn=function(c){return this.clone().idivn(c)},i.prototype.egcd=function(c){e(c.negative===0),e(!c.isZero());var w=this,M=c.clone();w.negative!==0?w=w.umod(c):w=w.clone();for(var B=new i(1),S=new i(0),O=new i(0),N=new i(1),A=0;w.isEven()&&M.isEven();)w.iushrn(1),M.iushrn(1),++A;for(var h=M.clone(),D=w.clone();!w.isZero();){for(var ot=0,ct=1;!(w.words[0]&ct)&&ot<26;++ot,ct<<=1);if(ot>0)for(w.iushrn(ot);ot-- >0;)(B.isOdd()||S.isOdd())&&(B.iadd(h),S.isub(D)),B.iushrn(1),S.iushrn(1);for(var st=0,vt=1;!(M.words[0]&vt)&&st<26;++st,vt<<=1);if(st>0)for(M.iushrn(st);st-- >0;)(O.isOdd()||N.isOdd())&&(O.iadd(h),N.isub(D)),O.iushrn(1),N.iushrn(1);w.cmp(M)>=0?(w.isub(M),B.isub(O),S.isub(N)):(M.isub(w),O.isub(B),N.isub(S))}return{a:O,b:N,gcd:M.iushln(A)}},i.prototype._invmp=function(c){e(c.negative===0),e(!c.isZero());var w=this,M=c.clone();w.negative!==0?w=w.umod(c):w=w.clone();for(var B=new i(1),S=new i(0),O=M.clone();w.cmpn(1)>0&&M.cmpn(1)>0;){for(var N=0,A=1;!(w.words[0]&A)&&N<26;++N,A<<=1);if(N>0)for(w.iushrn(N);N-- >0;)B.isOdd()&&B.iadd(O),B.iushrn(1);for(var h=0,D=1;!(M.words[0]&D)&&h<26;++h,D<<=1);if(h>0)for(M.iushrn(h);h-- >0;)S.isOdd()&&S.iadd(O),S.iushrn(1);w.cmp(M)>=0?(w.isub(M),B.isub(S)):(M.isub(w),S.isub(B))}var ot;return w.cmpn(1)===0?ot=B:ot=S,ot.cmpn(0)<0&&ot.iadd(c),ot},i.prototype.gcd=function(c){if(this.isZero())return c.abs();if(c.isZero())return this.abs();var w=this.clone(),M=c.clone();w.negative=0,M.negative=0;for(var B=0;w.isEven()&&M.isEven();B++)w.iushrn(1),M.iushrn(1);do{for(;w.isEven();)w.iushrn(1);for(;M.isEven();)M.iushrn(1);var S=w.cmp(M);if(S<0){var O=w;w=M,M=O}else if(S===0||M.cmpn(1)===0)break;w.isub(M)}while(!0);return M.iushln(B)},i.prototype.invm=function(c){return this.egcd(c).a.umod(c)},i.prototype.isEven=function(){return(this.words[0]&1)===0},i.prototype.isOdd=function(){return(this.words[0]&1)===1},i.prototype.andln=function(c){return this.words[0]&c},i.prototype.bincn=function(c){e(typeof c=="number");var w=c%26,M=(c-w)/26,B=1<<w;if(this.length<=M)return this._expand(M+1),this.words[M]|=B,this;for(var S=B,O=M;S!==0&&O<this.length;O++){var N=this.words[O]|0;N+=S,S=N>>>26,N&=67108863,this.words[O]=N}return S!==0&&(this.words[O]=S,this.length++),this},i.prototype.isZero=function(){return this.length===1&&this.words[0]===0},i.prototype.cmpn=function(c){var w=c<0;if(this.negative!==0&&!w)return-1;if(this.negative===0&&w)return 1;this.strip();var M;if(this.length>1)M=1;else{w&&(c=-c),e(c<=67108863,"Number is too big");var B=this.words[0]|0;M=B===c?0:B<c?-1:1}return this.negative!==0?-M|0:M},i.prototype.cmp=function(c){if(this.negative!==0&&c.negative===0)return-1;if(this.negative===0&&c.negative!==0)return 1;var w=this.ucmp(c);return this.negative!==0?-w|0:w},i.prototype.ucmp=function(c){if(this.length>c.length)return 1;if(this.length<c.length)return-1;for(var w=0,M=this.length-1;M>=0;M--){var B=this.words[M]|0,S=c.words[M]|0;if(B!==S){B<S?w=-1:B>S&&(w=1);break}}return w},i.prototype.gtn=function(c){return this.cmpn(c)===1},i.prototype.gt=function(c){return this.cmp(c)===1},i.prototype.gten=function(c){return this.cmpn(c)>=0},i.prototype.gte=function(c){return this.cmp(c)>=0},i.prototype.ltn=function(c){return this.cmpn(c)===-1},i.prototype.lt=function(c){return this.cmp(c)===-1},i.prototype.lten=function(c){return this.cmpn(c)<=0},i.prototype.lte=function(c){return this.cmp(c)<=0},i.prototype.eqn=function(c){return this.cmpn(c)===0},i.prototype.eq=function(c){return this.cmp(c)===0},i.red=function(c){return new X(c)},i.prototype.toRed=function(c){return e(!this.red,"Already a number in reduction context"),e(this.negative===0,"red works only with positives"),c.convertTo(this)._forceRed(c)},i.prototype.fromRed=function(){return e(this.red,"fromRed works only with numbers in reduction context"),this.red.convertFrom(this)},i.prototype._forceRed=function(c){return this.red=c,this},i.prototype.forceRed=function(c){return e(!this.red,"Already a number in reduction context"),this._forceRed(c)},i.prototype.redAdd=function(c){return e(this.red,"redAdd works only with red numbers"),this.red.add(this,c)},i.prototype.redIAdd=function(c){return e(this.red,"redIAdd works only with red numbers"),this.red.iadd(this,c)},i.prototype.redSub=function(c){return e(this.red,"redSub works only with red numbers"),this.red.sub(this,c)},i.prototype.redISub=function(c){return e(this.red,"redISub works only with red numbers"),this.red.isub(this,c)},i.prototype.redShl=function(c){return e(this.red,"redShl works only with red numbers"),this.red.shl(this,c)},i.prototype.redMul=function(c){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.mul(this,c)},i.prototype.redIMul=function(c){return e(this.red,"redMul works only with red numbers"),this.red._verify2(this,c),this.red.imul(this,c)},i.prototype.redSqr=function(){return e(this.red,"redSqr works only with red numbers"),this.red._verify1(this),this.red.sqr(this)},i.prototype.redISqr=function(){return e(this.red,"redISqr works only with red numbers"),this.red._verify1(this),this.red.isqr(this)},i.prototype.redSqrt=function(){return e(this.red,"redSqrt works only with red numbers"),this.red._verify1(this),this.red.sqrt(this)},i.prototype.redInvm=function(){return e(this.red,"redInvm works only with red numbers"),this.red._verify1(this),this.red.invm(this)},i.prototype.redNeg=function(){return e(this.red,"redNeg works only with red numbers"),this.red._verify1(this),this.red.neg(this)},i.prototype.redPow=function(c){return e(this.red&&!c.red,"redPow(normalNum)"),this.red._verify1(this),this.red.pow(this,c)};var H={k256:null,p224:null,p192:null,p25519:null};function $(E,c){this.name=E,this.p=new i(c,16),this.n=this.p.bitLength(),this.k=new i(1).iushln(this.n).isub(this.p),this.tmp=this._tmp()}$.prototype._tmp=function(){var c=new i(null);return c.words=new Array(Math.ceil(this.n/13)),c},$.prototype.ireduce=function(c){var w=c,M;do this.split(w,this.tmp),w=this.imulK(w),w=w.iadd(this.tmp),M=w.bitLength();while(M>this.n);var B=M<this.n?-1:w.ucmp(this.p);return B===0?(w.words[0]=0,w.length=1):B>0?w.isub(this.p):w.strip!==void 0?w.strip():w._strip(),w},$.prototype.split=function(c,w){c.iushrn(this.n,0,w)},$.prototype.imulK=function(c){return c.imul(this.k)};function Z(){$.call(this,"k256","ffffffff ffffffff ffffffff ffffffff ffffffff ffffffff fffffffe fffffc2f")}o(Z,$),Z.prototype.split=function(c,w){for(var M=4194303,B=Math.min(c.length,9),S=0;S<B;S++)w.words[S]=c.words[S];if(w.length=B,c.length<=9){c.words[0]=0,c.length=1;return}var O=c.words[9];for(w.words[w.length++]=O&M,S=10;S<c.length;S++){var N=c.words[S]|0;c.words[S-10]=(N&M)<<4|O>>>22,O=N}O>>>=22,c.words[S-10]=O,O===0&&c.length>10?c.length-=10:c.length-=9},Z.prototype.imulK=function(c){c.words[c.length]=0,c.words[c.length+1]=0,c.length+=2;for(var w=0,M=0;M<c.length;M++){var B=c.words[M]|0;w+=B*977,c.words[M]=w&67108863,w=B*64+(w/67108864|0)}return c.words[c.length-1]===0&&(c.length--,c.words[c.length-1]===0&&c.length--),c};function Q(){$.call(this,"p224","ffffffff ffffffff ffffffff ffffffff 00000000 00000000 00000001")}o(Q,$);function it(){$.call(this,"p192","ffffffff ffffffff ffffffff fffffffe ffffffff ffffffff")}o(it,$);function et(){$.call(this,"25519","7fffffffffffffff ffffffffffffffff ffffffffffffffff ffffffffffffffed")}o(et,$),et.prototype.imulK=function(c){for(var w=0,M=0;M<c.length;M++){var B=(c.words[M]|0)*19+w,S=B&67108863;B>>>=26,c.words[M]=S,w=B}return w!==0&&(c.words[c.length++]=w),c},i._prime=function(c){if(H[c])return H[c];var w;if(c==="k256")w=new Z;else if(c==="p224")w=new Q;else if(c==="p192")w=new it;else if(c==="p25519")w=new et;else throw new Error("Unknown prime "+c);return H[c]=w,w};function X(E){if(typeof E=="string"){var c=i._prime(E);this.m=c.p,this.prime=c}else e(E.gtn(1),"modulus must be greater than 1"),this.m=E,this.prime=null}X.prototype._verify1=function(c){e(c.negative===0,"red works only with positives"),e(c.red,"red works only with red numbers")},X.prototype._verify2=function(c,w){e((c.negative|w.negative)===0,"red works only with positives"),e(c.red&&c.red===w.red,"red works only with red numbers")},X.prototype.imod=function(c){return this.prime?this.prime.ireduce(c)._forceRed(this):c.umod(this.m)._forceRed(this)},X.prototype.neg=function(c){return c.isZero()?c.clone():this.m.sub(c)._forceRed(this)},X.prototype.add=function(c,w){this._verify2(c,w);var M=c.add(w);return M.cmp(this.m)>=0&&M.isub(this.m),M._forceRed(this)},X.prototype.iadd=function(c,w){this._verify2(c,w);var M=c.iadd(w);return M.cmp(this.m)>=0&&M.isub(this.m),M},X.prototype.sub=function(c,w){this._verify2(c,w);var M=c.sub(w);return M.cmpn(0)<0&&M.iadd(this.m),M._forceRed(this)},X.prototype.isub=function(c,w){this._verify2(c,w);var M=c.isub(w);return M.cmpn(0)<0&&M.iadd(this.m),M},X.prototype.shl=function(c,w){return this._verify1(c),this.imod(c.ushln(w))},X.prototype.imul=function(c,w){return this._verify2(c,w),this.imod(c.imul(w))},X.prototype.mul=function(c,w){return this._verify2(c,w),this.imod(c.mul(w))},X.prototype.isqr=function(c){return this.imul(c,c.clone())},X.prototype.sqr=function(c){return this.mul(c,c)},X.prototype.sqrt=function(c){if(c.isZero())return c.clone();var w=this.m.andln(3);if(e(w%2===1),w===3){var M=this.m.add(new i(1)).iushrn(2);return this.pow(c,M)}for(var B=this.m.subn(1),S=0;!B.isZero()&&B.andln(1)===0;)S++,B.iushrn(1);e(!B.isZero());var O=new i(1).toRed(this),N=O.redNeg(),A=this.m.subn(1).iushrn(1),h=this.m.bitLength();for(h=new i(2*h*h).toRed(this);this.pow(h,A).cmp(N)!==0;)h.redIAdd(N);for(var D=this.pow(h,B),ot=this.pow(c,B.addn(1).iushrn(1)),ct=this.pow(c,B),st=S;ct.cmp(O)!==0;){for(var vt=ct,pt=0;vt.cmp(O)!==0;pt++)vt=vt.redSqr();e(pt<st);var d=this.pow(D,new i(1).iushln(st-pt-1));ot=ot.redMul(d),D=d.redSqr(),ct=ct.redMul(D),st=pt}return ot},X.prototype.invm=function(c){var w=c._invmp(this.m);return w.negative!==0?(w.negative=0,this.imod(w).redNeg()):this.imod(w)},X.prototype.pow=function(c,w){if(w.isZero())return new i(1).toRed(this);if(w.cmpn(1)===0)return c.clone();var M=4,B=new Array(1<<M);B[0]=new i(1).toRed(this),B[1]=c;for(var S=2;S<B.length;S++)B[S]=this.mul(B[S-1],c);var O=B[0],N=0,A=0,h=w.bitLength()%26;for(h===0&&(h=26),S=w.length-1;S>=0;S--){for(var D=w.words[S],ot=h-1;ot>=0;ot--){var ct=D>>ot&1;if(O!==B[0]&&(O=this.sqr(O)),ct===0&&N===0){A=0;continue}N<<=1,N|=ct,A++,!(A!==M&&(S!==0||ot!==0))&&(O=this.mul(O,B[N]),A=0,N=0)}h=26}return O},X.prototype.convertTo=function(c){var w=c.umod(this.m);return w===c?w.clone():w},X.prototype.convertFrom=function(c){var w=c.clone();return w.red=null,w},i.mont=function(c){return new j(c)};function j(E){X.call(this,E),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)}o(j,X),j.prototype.convertTo=function(c){return this.imod(c.ushln(this.shift))},j.prototype.convertFrom=function(c){var w=this.imod(c.mul(this.rinv));return w.red=null,w},j.prototype.imul=function(c,w){if(c.isZero()||w.isZero())return c.words[0]=0,c.length=1,c;var M=c.imul(w),B=M.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=M.isub(B).iushrn(this.shift),O=S;return S.cmp(this.m)>=0?O=S.isub(this.m):S.cmpn(0)<0&&(O=S.iadd(this.m)),O._forceRed(this)},j.prototype.mul=function(c,w){if(c.isZero()||w.isZero())return new i(0)._forceRed(this);var M=c.mul(w),B=M.maskn(this.shift).mul(this.minv).imaskn(this.shift).mul(this.m),S=M.isub(B).iushrn(this.shift),O=S;return S.cmp(this.m)>=0?O=S.isub(this.m):S.cmpn(0)<0&&(O=S.iadd(this.m)),O._forceRed(this)},j.prototype.invm=function(c){var w=this.imod(c._invmp(this.m).mul(this.r2));return w._forceRed(this)}})(r,Ll)}),Bv=da.BN,yr=da;var ya=typeof global<"u"?global:typeof self<"u"?self:typeof window<"u"?window:{},xr=[],lr=[],Vl=typeof Uint8Array<"u"?Uint8Array:Array,fi=!1;function Ta(){fi=!0;for(var r="ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/",t=0,n=r.length;t<n;++t)xr[t]=r[t],lr[r.charCodeAt(t)]=t;lr[45]=62,lr[95]=63}function ql(r){fi||Ta();var t,n,e,o,i,a,u=r.length;if(u%4>0)throw new Error("Invalid string. Length must be a multiple of 4");i=r[u-2]==="="?2:r[u-1]==="="?1:0,a=new Vl(u*3/4-i),e=i>0?u-4:u;var s=0;for(t=0,n=0;t<e;t+=4,n+=3)o=lr[r.charCodeAt(t)]<<18|lr[r.charCodeAt(t+1)]<<12|lr[r.charCodeAt(t+2)]<<6|lr[r.charCodeAt(t+3)],a[s++]=o>>16&255,a[s++]=o>>8&255,a[s++]=o&255;return i===2?(o=lr[r.charCodeAt(t)]<<2|lr[r.charCodeAt(t+1)]>>4,a[s++]=o&255):i===1&&(o=lr[r.charCodeAt(t)]<<10|lr[r.charCodeAt(t+1)]<<4|lr[r.charCodeAt(t+2)]>>2,a[s++]=o>>8&255,a[s++]=o&255),a}function Yl(r){return xr[r>>18&63]+xr[r>>12&63]+xr[r>>6&63]+xr[r&63]}function kl(r,t,n){for(var e,o=[],i=t;i<n;i+=3)e=(r[i]<<16)+(r[i+1]<<8)+r[i+2],o.push(Yl(e));return o.join("")}function xa(r){fi||Ta();for(var t,n=r.length,e=n%3,o="",i=[],a=16383,u=0,s=n-e;u<s;u+=a)i.push(kl(r,u,u+a>s?s:u+a));return e===1?(t=r[n-1],o+=xr[t>>2],o+=xr[t<<4&63],o+="=="):e===2&&(t=(r[n-2]<<8)+r[n-1],o+=xr[t>>10],o+=xr[t>>4&63],o+=xr[t<<2&63],o+="="),i.push(o),i.join("")}function Ze(r,t,n,e,o){var i,a,u=o*8-e-1,s=(1<<u)-1,l=s>>1,p=-7,_=n?o-1:0,F=n?-1:1,z=r[t+_];for(_+=F,i=z&(1<<-p)-1,z>>=-p,p+=u;p>0;i=i*256+r[t+_],_+=F,p-=8);for(a=i&(1<<-p)-1,i>>=-p,p+=e;p>0;a=a*256+r[t+_],_+=F,p-=8);if(i===0)i=1-l;else{if(i===s)return a?NaN:(z?-1:1)*(1/0);a=a+Math.pow(2,e),i=i-l}return(z?-1:1)*a*Math.pow(2,i-e)}function ba(r,t,n,e,o,i){var a,u,s,l=i*8-o-1,p=(1<<l)-1,_=p>>1,F=o===23?Math.pow(2,-24)-Math.pow(2,-77):0,z=e?0:i-1,I=e?1:-1,m=t<0||t===0&&1/t<0?1:0;for(t=Math.abs(t),isNaN(t)||t===1/0?(u=isNaN(t)?1:0,a=p):(a=Math.floor(Math.log(t)/Math.LN2),t*(s=Math.pow(2,-a))<1&&(a--,s*=2),a+_>=1?t+=F/s:t+=F*Math.pow(2,1-_),t*s>=2&&(a++,s/=2),a+_>=p?(u=0,a=p):a+_>=1?(u=(t*s-1)*Math.pow(2,o),a=a+_):(u=t*Math.pow(2,_-1)*Math.pow(2,o),a=0));o>=8;r[n+z]=u&255,z+=I,u/=256,o-=8);for(a=a<<o|u,l+=o;l>0;r[n+z]=a&255,z+=I,a/=256,l-=8);r[n+z-I]|=m*128}var Xl={}.toString,Ba=Array.isArray||function(r){return Xl.call(r)=="[object Array]"};var Hl=50;ut.TYPED_ARRAY_SUPPORT=ya.TYPED_ARRAY_SUPPORT!==void 0?ya.TYPED_ARRAY_SUPPORT:!0;function ci(){return ut.TYPED_ARRAY_SUPPORT?2147483647:1073741823}function Sr(r,t){if(ci()<t)throw new RangeError("Invalid typed array length");return ut.TYPED_ARRAY_SUPPORT?(r=new Uint8Array(t),r.__proto__=ut.prototype):(r===null&&(r=new ut(t)),r.length=t),r}function ut(r,t,n){if(!ut.TYPED_ARRAY_SUPPORT&&!(this instanceof ut))return new ut(r,t,n);if(typeof r=="number"){if(typeof t=="string")throw new Error("If encoding is specified then the first argument must be a string");return hi(this,r)}return Ea(this,r,t,n)}ut.poolSize=8192;ut._augment=function(r){return r.__proto__=ut.prototype,r};function Ea(r,t,n,e){if(typeof t=="number")throw new TypeError('"value" argument must not be a number');return typeof ArrayBuffer<"u"&&t instanceof ArrayBuffer?Wl(r,t,n,e):typeof t=="string"?Zl(r,t,n):Ql(r,t)}ut.from=function(r,t,n){return Ea(null,r,t,n)};ut.TYPED_ARRAY_SUPPORT&&(ut.prototype.__proto__=Uint8Array.prototype,ut.__proto__=Uint8Array);function Sa(r){if(typeof r!="number")throw new TypeError('"size" argument must be a number');if(r<0)throw new RangeError('"size" argument must not be negative')}function $l(r,t,n,e){return Sa(t),t<=0?Sr(r,t):n!==void 0?typeof e=="string"?Sr(r,t).fill(n,e):Sr(r,t).fill(n):Sr(r,t)}ut.alloc=function(r,t,n){return $l(null,r,t,n)};function hi(r,t){if(Sa(t),r=Sr(r,t<0?0:pi(t)|0),!ut.TYPED_ARRAY_SUPPORT)for(var n=0;n<t;++n)r[n]=0;return r}ut.allocUnsafe=function(r){return hi(null,r)};ut.allocUnsafeSlow=function(r){return hi(null,r)};function Zl(r,t,n){if((typeof n!="string"||n==="")&&(n="utf8"),!ut.isEncoding(n))throw new TypeError('"encoding" must be a valid string encoding');var e=Ua(t,n)|0;r=Sr(r,e);var o=r.write(t,n);return o!==e&&(r=r.slice(0,o)),r}function li(r,t){var n=t.length<0?0:pi(t.length)|0;r=Sr(r,n);for(var e=0;e<n;e+=1)r[e]=t[e]&255;return r}function Wl(r,t,n,e){if(t.byteLength,n<0||t.byteLength<n)throw new RangeError("'offset' is out of bounds");if(t.byteLength<n+(e||0))throw new RangeError("'length' is out of bounds");return n===void 0&&e===void 0?t=new Uint8Array(t):e===void 0?t=new Uint8Array(t,n):t=new Uint8Array(t,n,e),ut.TYPED_ARRAY_SUPPORT?(r=t,r.__proto__=ut.prototype):r=li(r,t),r}function Ql(r,t){if(Mr(t)){var n=pi(t.length)|0;return r=Sr(r,n),r.length===0||t.copy(r,0,0,n),r}if(t){if(typeof ArrayBuffer<"u"&&t.buffer instanceof ArrayBuffer||"length"in t)return typeof t.length!="number"||g1(t.length)?Sr(r,0):li(r,t);if(t.type==="Buffer"&&Ba(t.data))return li(r,t.data)}throw new TypeError("First argument must be a string, Buffer, ArrayBuffer, Array, or array-like object.")}function pi(r){if(r>=ci())throw new RangeError("Attempt to allocate Buffer larger than maximum size: 0x"+ci().toString(16)+" bytes");return r|0}ut.isBuffer=w1;function Mr(r){return!!(r!=null&&r._isBuffer)}ut.compare=function(t,n){if(!Mr(t)||!Mr(n))throw new TypeError("Arguments must be Buffers");if(t===n)return 0;for(var e=t.length,o=n.length,i=0,a=Math.min(e,o);i<a;++i)if(t[i]!==n[i]){e=t[i],o=n[i];break}return e<o?-1:o<e?1:0};ut.isEncoding=function(t){switch(String(t).toLowerCase()){case"hex":case"utf8":case"utf-8":case"ascii":case"latin1":case"binary":case"base64":case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return!0;default:return!1}};ut.concat=function(t,n){if(!Ba(t))throw new TypeError('"list" argument must be an Array of Buffers');if(t.length===0)return ut.alloc(0);var e;if(n===void 0)for(n=0,e=0;e<t.length;++e)n+=t[e].length;var o=ut.allocUnsafe(n),i=0;for(e=0;e<t.length;++e){var a=t[e];if(!Mr(a))throw new TypeError('"list" argument must be an Array of Buffers');a.copy(o,i),i+=a.length}return o};function Ua(r,t){if(Mr(r))return r.length;if(typeof ArrayBuffer<"u"&&typeof ArrayBuffer.isView=="function"&&(ArrayBuffer.isView(r)||r instanceof ArrayBuffer))return r.byteLength;typeof r!="string"&&(r=""+r);var n=r.length;if(n===0)return 0;for(var e=!1;;)switch(t){case"ascii":case"latin1":case"binary":return n;case"utf8":case"utf-8":case void 0:return $e(r).length;case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return n*2;case"hex":return n>>>1;case"base64":return La(r).length;default:if(e)return $e(r).length;t=(""+t).toLowerCase(),e=!0}}ut.byteLength=Ua;function Kl(r,t,n){var e=!1;if((t===void 0||t<0)&&(t=0),t>this.length||((n===void 0||n>this.length)&&(n=this.length),n<=0)||(n>>>=0,t>>>=0,n<=t))return"";for(r||(r="utf8");;)switch(r){case"hex":return u1(this,t,n);case"utf8":case"utf-8":return Da(this,t,n);case"ascii":return o1(this,t,n);case"latin1":case"binary":return a1(this,t,n);case"base64":return n1(this,t,n);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return s1(this,t,n);default:if(e)throw new TypeError("Unknown encoding: "+r);r=(r+"").toLowerCase(),e=!0}}ut.prototype._isBuffer=!0;function Xr(r,t,n){var e=r[t];r[t]=r[n],r[n]=e}ut.prototype.swap16=function(){var t=this.length;if(t%2!==0)throw new RangeError("Buffer size must be a multiple of 16-bits");for(var n=0;n<t;n+=2)Xr(this,n,n+1);return this};ut.prototype.swap32=function(){var t=this.length;if(t%4!==0)throw new RangeError("Buffer size must be a multiple of 32-bits");for(var n=0;n<t;n+=4)Xr(this,n,n+3),Xr(this,n+1,n+2);return this};ut.prototype.swap64=function(){var t=this.length;if(t%8!==0)throw new RangeError("Buffer size must be a multiple of 64-bits");for(var n=0;n<t;n+=8)Xr(this,n,n+7),Xr(this,n+1,n+6),Xr(this,n+2,n+5),Xr(this,n+3,n+4);return this};ut.prototype.toString=function(){var t=this.length|0;return t===0?"":arguments.length===0?Da(this,0,t):Kl.apply(this,arguments)};ut.prototype.equals=function(t){if(!Mr(t))throw new TypeError("Argument must be a Buffer");return this===t?!0:ut.compare(this,t)===0};ut.prototype.inspect=function(){var t="",n=Hl;return this.length>0&&(t=this.toString("hex",0,n).match(/.{2}/g).join(" "),this.length>n&&(t+=" ... ")),"<Buffer "+t+">"};ut.prototype.compare=function(t,n,e,o,i){if(!Mr(t))throw new TypeError("Argument must be a Buffer");if(n===void 0&&(n=0),e===void 0&&(e=t?t.length:0),o===void 0&&(o=0),i===void 0&&(i=this.length),n<0||e>t.length||o<0||i>this.length)throw new RangeError("out of range index");if(o>=i&&n>=e)return 0;if(o>=i)return-1;if(n>=e)return 1;if(n>>>=0,e>>>=0,o>>>=0,i>>>=0,this===t)return 0;for(var a=i-o,u=e-n,s=Math.min(a,u),l=this.slice(o,i),p=t.slice(n,e),_=0;_<s;++_)if(l[_]!==p[_]){a=l[_],u=p[_];break}return a<u?-1:u<a?1:0};function Aa(r,t,n,e,o){if(r.length===0)return-1;if(typeof n=="string"?(e=n,n=0):n>2147483647?n=2147483647:n<-2147483648&&(n=-2147483648),n=+n,isNaN(n)&&(n=o?0:r.length-1),n<0&&(n=r.length+n),n>=r.length){if(o)return-1;n=r.length-1}else if(n<0)if(o)n=0;else return-1;if(typeof t=="string"&&(t=ut.from(t,e)),Mr(t))return t.length===0?-1:Ma(r,t,n,e,o);if(typeof t=="number")return t=t&255,ut.TYPED_ARRAY_SUPPORT&&typeof Uint8Array.prototype.indexOf=="function"?o?Uint8Array.prototype.indexOf.call(r,t,n):Uint8Array.prototype.lastIndexOf.call(r,t,n):Ma(r,[t],n,e,o);throw new TypeError("val must be string, number or Buffer")}function Ma(r,t,n,e,o){var i=1,a=r.length,u=t.length;if(e!==void 0&&(e=String(e).toLowerCase(),e==="ucs2"||e==="ucs-2"||e==="utf16le"||e==="utf-16le")){if(r.length<2||t.length<2)return-1;i=2,a/=2,u/=2,n/=2}function s(z,I){return i===1?z[I]:z.readUInt16BE(I*i)}var l;if(o){var p=-1;for(l=n;l<a;l++)if(s(r,l)===s(t,p===-1?0:l-p)){if(p===-1&&(p=l),l-p+1===u)return p*i}else p!==-1&&(l-=l-p),p=-1}else for(n+u>a&&(n=a-u),l=n;l>=0;l--){for(var _=!0,F=0;F<u;F++)if(s(r,l+F)!==s(t,F)){_=!1;break}if(_)return l}return-1}ut.prototype.includes=function(t,n,e){return this.indexOf(t,n,e)!==-1};ut.prototype.indexOf=function(t,n,e){return Aa(this,t,n,e,!0)};ut.prototype.lastIndexOf=function(t,n,e){return Aa(this,t,n,e,!1)};function Jl(r,t,n,e){n=Number(n)||0;var o=r.length-n;e?(e=Number(e),e>o&&(e=o)):e=o;var i=t.length;if(i%2!==0)throw new TypeError("Invalid hex string");e>i/2&&(e=i/2);for(var a=0;a<e;++a){var u=parseInt(t.substr(a*2,2),16);if(isNaN(u))return a;r[n+a]=u}return a}function jl(r,t,n,e){return Ke($e(t,r.length-n),r,n,e)}function Pa(r,t,n,e){return Ke(p1(t),r,n,e)}function t1(r,t,n,e){return Pa(r,t,n,e)}function r1(r,t,n,e){return Ke(La(t),r,n,e)}function e1(r,t,n,e){return Ke(v1(t,r.length-n),r,n,e)}ut.prototype.write=function(t,n,e,o){if(n===void 0)o="utf8",e=this.length,n=0;else if(e===void 0&&typeof n=="string")o=n,e=this.length,n=0;else if(isFinite(n))n=n|0,isFinite(e)?(e=e|0,o===void 0&&(o="utf8")):(o=e,e=void 0);else throw new Error("Buffer.write(string, encoding, offset[, length]) is no longer supported");var i=this.length-n;if((e===void 0||e>i)&&(e=i),t.length>0&&(e<0||n<0)||n>this.length)throw new RangeError("Attempt to write outside buffer bounds");o||(o="utf8");for(var a=!1;;)switch(o){case"hex":return Jl(this,t,n,e);case"utf8":case"utf-8":return jl(this,t,n,e);case"ascii":return Pa(this,t,n,e);case"latin1":case"binary":return t1(this,t,n,e);case"base64":return r1(this,t,n,e);case"ucs2":case"ucs-2":case"utf16le":case"utf-16le":return e1(this,t,n,e);default:if(a)throw new TypeError("Unknown encoding: "+o);o=(""+o).toLowerCase(),a=!0}};ut.prototype.toJSON=function(){return{type:"Buffer",data:Array.prototype.slice.call(this._arr||this,0)}};function n1(r,t,n){return t===0&&n===r.length?xa(r):xa(r.slice(t,n))}function Da(r,t,n){n=Math.min(r.length,n);for(var e=[],o=t;o<n;){var i=r[o],a=null,u=i>239?4:i>223?3:i>191?2:1;if(o+u<=n){var s,l,p,_;switch(u){case 1:i<128&&(a=i);break;case 2:s=r[o+1],(s&192)===128&&(_=(i&31)<<6|s&63,_>127&&(a=_));break;case 3:s=r[o+1],l=r[o+2],(s&192)===128&&(l&192)===128&&(_=(i&15)<<12|(s&63)<<6|l&63,_>2047&&(_<55296||_>57343)&&(a=_));break;case 4:s=r[o+1],l=r[o+2],p=r[o+3],(s&192)===128&&(l&192)===128&&(p&192)===128&&(_=(i&15)<<18|(s&63)<<12|(l&63)<<6|p&63,_>65535&&_<1114112&&(a=_))}}a===null?(a=65533,u=1):a>65535&&(a-=65536,e.push(a>>>10&1023|55296),a=56320|a&1023),e.push(a),o+=u}return i1(e)}var _a=4096;function i1(r){var t=r.length;if(t<=_a)return String.fromCharCode.apply(String,r);for(var n="",e=0;e<t;)n+=String.fromCharCode.apply(String,r.slice(e,e+=_a));return n}function o1(r,t,n){var e="";n=Math.min(r.length,n);for(var o=t;o<n;++o)e+=String.fromCharCode(r[o]&127);return e}function a1(r,t,n){var e="";n=Math.min(r.length,n);for(var o=t;o<n;++o)e+=String.fromCharCode(r[o]);return e}function u1(r,t,n){var e=r.length;(!t||t<0)&&(t=0),(!n||n<0||n>e)&&(n=e);for(var o="",i=t;i<n;++i)o+=h1(r[i]);return o}function s1(r,t,n){for(var e=r.slice(t,n),o="",i=0;i<e.length;i+=2)o+=String.fromCharCode(e[i]+e[i+1]*256);return o}ut.prototype.slice=function(t,n){var e=this.length;t=~~t,n=n===void 0?e:~~n,t<0?(t+=e,t<0&&(t=0)):t>e&&(t=e),n<0?(n+=e,n<0&&(n=0)):n>e&&(n=e),n<t&&(n=t);var o;if(ut.TYPED_ARRAY_SUPPORT)o=this.subarray(t,n),o.__proto__=ut.prototype;else{var i=n-t;o=new ut(i,void 0);for(var a=0;a<i;++a)o[a]=this[a+t]}return o};function Wt(r,t,n){if(r%1!==0||r<0)throw new RangeError("offset is not uint");if(r+t>n)throw new RangeError("Trying to access beyond buffer length")}ut.prototype.readUIntLE=function(t,n,e){t=t|0,n=n|0,e||Wt(t,n,this.length);for(var o=this[t],i=1,a=0;++a<n&&(i*=256);)o+=this[t+a]*i;return o};ut.prototype.readUIntBE=function(t,n,e){t=t|0,n=n|0,e||Wt(t,n,this.length);for(var o=this[t+--n],i=1;n>0&&(i*=256);)o+=this[t+--n]*i;return o};ut.prototype.readUInt8=function(t,n){return n||Wt(t,1,this.length),this[t]};ut.prototype.readUInt16LE=function(t,n){return n||Wt(t,2,this.length),this[t]|this[t+1]<<8};ut.prototype.readUInt16BE=function(t,n){return n||Wt(t,2,this.length),this[t]<<8|this[t+1]};ut.prototype.readUInt32LE=function(t,n){return n||Wt(t,4,this.length),(this[t]|this[t+1]<<8|this[t+2]<<16)+this[t+3]*16777216};ut.prototype.readUInt32BE=function(t,n){return n||Wt(t,4,this.length),this[t]*16777216+(this[t+1]<<16|this[t+2]<<8|this[t+3])};ut.prototype.readIntLE=function(t,n,e){t=t|0,n=n|0,e||Wt(t,n,this.length);for(var o=this[t],i=1,a=0;++a<n&&(i*=256);)o+=this[t+a]*i;return i*=128,o>=i&&(o-=Math.pow(2,8*n)),o};ut.prototype.readIntBE=function(t,n,e){t=t|0,n=n|0,e||Wt(t,n,this.length);for(var o=n,i=1,a=this[t+--o];o>0&&(i*=256);)a+=this[t+--o]*i;return i*=128,a>=i&&(a-=Math.pow(2,8*n)),a};ut.prototype.readInt8=function(t,n){return n||Wt(t,1,this.length),this[t]&128?(255-this[t]+1)*-1:this[t]};ut.prototype.readInt16LE=function(t,n){n||Wt(t,2,this.length);var e=this[t]|this[t+1]<<8;return e&32768?e|4294901760:e};ut.prototype.readInt16BE=function(t,n){n||Wt(t,2,this.length);var e=this[t+1]|this[t]<<8;return e&32768?e|4294901760:e};ut.prototype.readInt32LE=function(t,n){return n||Wt(t,4,this.length),this[t]|this[t+1]<<8|this[t+2]<<16|this[t+3]<<24};ut.prototype.readInt32BE=function(t,n){return n||Wt(t,4,this.length),this[t]<<24|this[t+1]<<16|this[t+2]<<8|this[t+3]};ut.prototype.readFloatLE=function(t,n){return n||Wt(t,4,this.length),Ze(this,t,!0,23,4)};ut.prototype.readFloatBE=function(t,n){return n||Wt(t,4,this.length),Ze(this,t,!1,23,4)};ut.prototype.readDoubleLE=function(t,n){return n||Wt(t,8,this.length),Ze(this,t,!0,52,8)};ut.prototype.readDoubleBE=function(t,n){return n||Wt(t,8,this.length),Ze(this,t,!1,52,8)};function ir(r,t,n,e,o,i){if(!Mr(r))throw new TypeError('"buffer" argument must be a Buffer instance');if(t>o||t<i)throw new RangeError('"value" argument is out of bounds');if(n+e>r.length)throw new RangeError("Index out of range")}ut.prototype.writeUIntLE=function(t,n,e,o){if(t=+t,n=n|0,e=e|0,!o){var i=Math.pow(2,8*e)-1;ir(this,t,n,e,i,0)}var a=1,u=0;for(this[n]=t&255;++u<e&&(a*=256);)this[n+u]=t/a&255;return n+e};ut.prototype.writeUIntBE=function(t,n,e,o){if(t=+t,n=n|0,e=e|0,!o){var i=Math.pow(2,8*e)-1;ir(this,t,n,e,i,0)}var a=e-1,u=1;for(this[n+a]=t&255;--a>=0&&(u*=256);)this[n+a]=t/u&255;return n+e};ut.prototype.writeUInt8=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,1,255,0),ut.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),this[n]=t&255,n+1};function We(r,t,n,e){t<0&&(t=65535+t+1);for(var o=0,i=Math.min(r.length-n,2);o<i;++o)r[n+o]=(t&255<<8*(e?o:1-o))>>>(e?o:1-o)*8}ut.prototype.writeUInt16LE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,2,65535,0),ut.TYPED_ARRAY_SUPPORT?(this[n]=t&255,this[n+1]=t>>>8):We(this,t,n,!0),n+2};ut.prototype.writeUInt16BE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,2,65535,0),ut.TYPED_ARRAY_SUPPORT?(this[n]=t>>>8,this[n+1]=t&255):We(this,t,n,!1),n+2};function Qe(r,t,n,e){t<0&&(t=4294967295+t+1);for(var o=0,i=Math.min(r.length-n,4);o<i;++o)r[n+o]=t>>>(e?o:3-o)*8&255}ut.prototype.writeUInt32LE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,4,4294967295,0),ut.TYPED_ARRAY_SUPPORT?(this[n+3]=t>>>24,this[n+2]=t>>>16,this[n+1]=t>>>8,this[n]=t&255):Qe(this,t,n,!0),n+4};ut.prototype.writeUInt32BE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,4,4294967295,0),ut.TYPED_ARRAY_SUPPORT?(this[n]=t>>>24,this[n+1]=t>>>16,this[n+2]=t>>>8,this[n+3]=t&255):Qe(this,t,n,!1),n+4};ut.prototype.writeIntLE=function(t,n,e,o){if(t=+t,n=n|0,!o){var i=Math.pow(2,8*e-1);ir(this,t,n,e,i-1,-i)}var a=0,u=1,s=0;for(this[n]=t&255;++a<e&&(u*=256);)t<0&&s===0&&this[n+a-1]!==0&&(s=1),this[n+a]=(t/u>>0)-s&255;return n+e};ut.prototype.writeIntBE=function(t,n,e,o){if(t=+t,n=n|0,!o){var i=Math.pow(2,8*e-1);ir(this,t,n,e,i-1,-i)}var a=e-1,u=1,s=0;for(this[n+a]=t&255;--a>=0&&(u*=256);)t<0&&s===0&&this[n+a+1]!==0&&(s=1),this[n+a]=(t/u>>0)-s&255;return n+e};ut.prototype.writeInt8=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,1,127,-128),ut.TYPED_ARRAY_SUPPORT||(t=Math.floor(t)),t<0&&(t=255+t+1),this[n]=t&255,n+1};ut.prototype.writeInt16LE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,2,32767,-32768),ut.TYPED_ARRAY_SUPPORT?(this[n]=t&255,this[n+1]=t>>>8):We(this,t,n,!0),n+2};ut.prototype.writeInt16BE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,2,32767,-32768),ut.TYPED_ARRAY_SUPPORT?(this[n]=t>>>8,this[n+1]=t&255):We(this,t,n,!1),n+2};ut.prototype.writeInt32LE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,4,2147483647,-2147483648),ut.TYPED_ARRAY_SUPPORT?(this[n]=t&255,this[n+1]=t>>>8,this[n+2]=t>>>16,this[n+3]=t>>>24):Qe(this,t,n,!0),n+4};ut.prototype.writeInt32BE=function(t,n,e){return t=+t,n=n|0,e||ir(this,t,n,4,2147483647,-2147483648),t<0&&(t=4294967295+t+1),ut.TYPED_ARRAY_SUPPORT?(this[n]=t>>>24,this[n+1]=t>>>16,this[n+2]=t>>>8,this[n+3]=t&255):Qe(this,t,n,!1),n+4};function Ia(r,t,n,e,o,i){if(n+e>r.length)throw new RangeError("Index out of range");if(n<0)throw new RangeError("Index out of range")}function ma(r,t,n,e,o){return o||Ia(r,t,n,4),ba(r,t,n,e,23,4),n+4}ut.prototype.writeFloatLE=function(t,n,e){return ma(this,t,n,!0,e)};ut.prototype.writeFloatBE=function(t,n,e){return ma(this,t,n,!1,e)};function Ra(r,t,n,e,o){return o||Ia(r,t,n,8),ba(r,t,n,e,52,8),n+8}ut.prototype.writeDoubleLE=function(t,n,e){return Ra(this,t,n,!0,e)};ut.prototype.writeDoubleBE=function(t,n,e){return Ra(this,t,n,!1,e)};ut.prototype.copy=function(t,n,e,o){if(e||(e=0),!o&&o!==0&&(o=this.length),n>=t.length&&(n=t.length),n||(n=0),o>0&&o<e&&(o=e),o===e||t.length===0||this.length===0)return 0;if(n<0)throw new RangeError("targetStart out of bounds");if(e<0||e>=this.length)throw new RangeError("sourceStart out of bounds");if(o<0)throw new RangeError("sourceEnd out of bounds");o>this.length&&(o=this.length),t.length-n<o-e&&(o=t.length-n+e);var i=o-e,a;if(this===t&&e<n&&n<o)for(a=i-1;a>=0;--a)t[a+n]=this[a+e];else if(i<1e3||!ut.TYPED_ARRAY_SUPPORT)for(a=0;a<i;++a)t[a+n]=this[a+e];else Uint8Array.prototype.set.call(t,this.subarray(e,e+i),n);return i};ut.prototype.fill=function(t,n,e,o){if(typeof t=="string"){if(typeof n=="string"?(o=n,n=0,e=this.length):typeof e=="string"&&(o=e,e=this.length),t.length===1){var i=t.charCodeAt(0);i<256&&(t=i)}if(o!==void 0&&typeof o!="string")throw new TypeError("encoding must be a string");if(typeof o=="string"&&!ut.isEncoding(o))throw new TypeError("Unknown encoding: "+o)}else typeof t=="number"&&(t=t&255);if(n<0||this.length<n||this.length<e)throw new RangeError("Out of range index");if(e<=n)return this;n=n>>>0,e=e===void 0?this.length:e>>>0,t||(t=0);var a;if(typeof t=="number")for(a=n;a<e;++a)this[a]=t;else{var u=Mr(t)?t:$e(new ut(t,o).toString()),s=u.length;for(a=0;a<e-n;++a)this[a+n]=u[a%s]}return this};var c1=/[^+\/0-9A-Za-z-_]/g;function l1(r){if(r=f1(r).replace(c1,""),r.length<2)return"";for(;r.length%4!==0;)r=r+"=";return r}function f1(r){return r.trim?r.trim():r.replace(/^\s+|\s+$/g,"")}function h1(r){return r<16?"0"+r.toString(16):r.toString(16)}function $e(r,t){t=t||1/0;for(var n,e=r.length,o=null,i=[],a=0;a<e;++a){if(n=r.charCodeAt(a),n>55295&&n<57344){if(!o){if(n>56319){(t-=3)>-1&&i.push(239,191,189);continue}else if(a+1===e){(t-=3)>-1&&i.push(239,191,189);continue}o=n;continue}if(n<56320){(t-=3)>-1&&i.push(239,191,189),o=n;continue}n=(o-55296<<10|n-56320)+65536}else o&&(t-=3)>-1&&i.push(239,191,189);if(o=null,n<128){if((t-=1)<0)break;i.push(n)}else if(n<2048){if((t-=2)<0)break;i.push(n>>6|192,n&63|128)}else if(n<65536){if((t-=3)<0)break;i.push(n>>12|224,n>>6&63|128,n&63|128)}else if(n<1114112){if((t-=4)<0)break;i.push(n>>18|240,n>>12&63|128,n>>6&63|128,n&63|128)}else throw new Error("Invalid code point")}return i}function p1(r){for(var t=[],n=0;n<r.length;++n)t.push(r.charCodeAt(n)&255);return t}function v1(r,t){for(var n,e,o,i=[],a=0;a<r.length&&!((t-=2)<0);++a)n=r.charCodeAt(a),e=n>>8,o=n%256,i.push(o),i.push(e);return i}function La(r){return ql(l1(r))}function Ke(r,t,n,e){for(var o=0;o<e&&!(o+n>=t.length||o>=r.length);++o)t[o+n]=r[o];return o}function g1(r){return r!==r}function w1(r){return r!=null&&(!!r._isBuffer||Ga(r)||d1(r))}function Ga(r){return!!r.constructor&&typeof r.constructor.isBuffer=="function"&&r.constructor.isBuffer(r)}function d1(r){return typeof r.readFloatLE=="function"&&typeof r.slice=="function"&&Ga(r.slice(0,0))}function y1(r,t,n){return n={path:t,exports:{},require:function(e,o){return x1(e,o??n.path)}},r(n,n.exports),n.exports}function x1(){throw new Error("Dynamic requires are not currently supported by @rollup/plugin-commonjs")}var Dr=y1(function(r){var t=!1;if(typeof Float64Array<"u"){var n=new Float64Array(1),e=new Uint32Array(n.buffer);if(n[0]=1,t=!0,e[1]===1072693248){let i=function(s,l){return e[0]=s,e[1]=l,n[0]},a=function(s){return n[0]=s,e[0]},u=function(s){return n[0]=s,e[1]};r.exports=function(l){return n[0]=l,[e[0],e[1]]},r.exports.pack=i,r.exports.lo=a,r.exports.hi=u}else if(e[0]===1072693248){let i=function(s,l){return e[1]=s,e[0]=l,n[0]},a=function(s){return n[0]=s,e[1]},u=function(s){return n[0]=s,e[0]};r.exports=function(l){return n[0]=l,[e[1],e[0]]},r.exports.pack=i,r.exports.lo=a,r.exports.hi=u}else t=!1}if(!t){let i=function(s,l){return o.writeUInt32LE(s,0,!0),o.writeUInt32LE(l,4,!0),o.readDoubleLE(0,!0)},a=function(s){return o.writeDoubleLE(s,0,!0),o.readUInt32LE(0,!0)},u=function(s){return o.writeDoubleLE(s,0,!0),o.readUInt32LE(4,!0)};var o=new ut(8);r.exports=function(l){return o.writeDoubleLE(l,0,!0),[o.readUInt32LE(0,!0),o.readUInt32LE(4,!0)]},r.exports.pack=i,r.exports.lo=a,r.exports.hi=u}r.exports.sign=function(i){return r.exports.hi(i)>>>31},r.exports.exponent=function(i){var a=r.exports.hi(i);return(a<<1>>>21)-1023},r.exports.fraction=function(i){var a=r.exports.lo(i),u=r.exports.hi(i),s=u&(1<<20)-1;return u&2146435072&&(s+=1<<20),[a,s]},r.exports.denormalized=function(i){var a=r.exports.hi(i);return!(a&2146435072)}}),pr=Dr,Sv=Dr.denormalized,Uv=Dr.exponent,Av=Dr.fraction,Pv=Dr.hi,Dv=Dr.lo,Iv=Dr.pack,mv=Dr.sign;var Je=M1;function M1(r){return r&&typeof r=="object"&&!!r.words}var Fa=_1;function _1(r){return Array.isArray(r)&&r.length===2&&Je(r[0])&&Je(r[1])}var vr=T1;function T1(r){var t=pr.exponent(r);return t<52?new yr(r):new yr(r*Math.pow(2,52-t)).ushln(t-52)}var za=b1;function b1(r){return new yr(r)}var Oa=B1;function B1(r){return r.cmp(new yr(0))}var Ca=E1;function E1(r,t){var n=Oa(r),e=Oa(t);if(n===0)return[vr(0),vr(1)];if(e===0)return[vr(0),vr(0)];e<0&&(r=r.neg(),t=t.neg());var o=r.gcd(t);return o.cmpn(1)?[r.div(o),t.div(o)]:[r,t]}var S1=U1;function U1(r,t){return Ca(r[0].mul(t[1]),r[1].mul(t[0]))}var A1=Na;function Na(r,t){if(Fa(r))return t?S1(r,Na(t)):[r[0].clone(),r[1].clone()];var n=0,e,o;if(Je(r))e=r.clone();else if(typeof r=="string")e=za(r);else{if(r===0)return[vr(0),vr(1)];if(r===Math.floor(r))e=vr(r);else{for(;r!==Math.floor(r);)r=r*Math.pow(2,256),n-=256;e=vr(r)}}if(Fa(t))e.mul(t[1]),o=t[0].clone();else if(Je(t))o=t.clone();else if(typeof t=="string")o=za(t);else if(!t)o=vr(1);else if(t===Math.floor(t))o=vr(t);else{for(;t!==Math.floor(t);)t=t*Math.pow(2,256),n+=256;o=vr(t)}return n>0?e=e.ushln(n):n<0&&(o=o.ushln(-n)),Ca(e,o)}var Hr=A1;var P1=D1;function D1(r,t){return r[0].mul(t[1]).cmp(t[0].mul(r[1]))}var vi=P1;var I1=m1;function m1(r){return r.cmp(new yr(0))}var Ir=I1;var R1=L1;function L1(r){var t=r.length,n=r.words,e=0;if(t===1)e=n[0];else if(t===2)e=n[0]+n[1]*67108864;else for(var o=0;o<t;o++){var i=n[o];e+=i*Math.pow(67108864,o)}return Ir(r)*e}var je=R1;var Va=jt.countTrailingZeros,G1=F1;function F1(r){var t=Va(pr.lo(r));if(t<32)return t;var n=Va(pr.hi(r));return n>20?52:n+32}var qa=G1;var z1=O1;function O1(r){var t=r[0],n=r[1];if(t.cmpn(0)===0)return 0;var e=t.abs().divmod(n.abs()),o=e.div,i=je(o),a=e.mod,u=t.negative!==n.negative?-1:1;if(a.cmpn(0)===0)return u*i;if(i){var s=qa(i)+4,l=je(a.ushln(s).divRound(n));return u*(i+l*Math.pow(2,-s))}else{var p=n.bitLength()-a.bitLength()+53,l=je(a.ushln(p).divRound(n));return p<1023?u*l*Math.pow(2,-p):(l*=Math.pow(2,-1023),u*l*Math.pow(2,1023-p))}}var tn=z1;var C1=N1;function N1(r){for(var t=new Array(r.length),n=0;n<r.length;++n)t[n]=Hr(r[n]);return t}var ge=C1;var Ya=Math.pow(2,-1074),ka=-1>>>0,V1=q1;function q1(r,t){if(isNaN(r)||isNaN(t))return NaN;if(r===t)return r;if(r===0)return t<0?-Ya:Ya;var n=pr.hi(r),e=pr.lo(r);return t>r==r>0?e===ka?(n+=1,e=0):e+=1:e===0?(e=ka,n-=1):e-=1,pr.pack(e,n)}var rr=V1;var Y1=k1;function k1(r){var t=pr.exponent(r);return t<52?new yr(r):new yr(r*Math.pow(2,52-t)).ushln(t-52)}var we=Y1;var X1=H1;function H1(r,t){var n=Ir(r),e=Ir(t);if(n===0)return[we(0),we(1)];if(e===0)return[we(0),we(0)];e<0&&(r=r.neg(),t=t.neg());var o=r.gcd(t);return o.cmpn(1)?[r.div(o),t.div(o)]:[r,t]}var mr=X1;var $1=Z1;function Z1(r,t){return mr(r[0].mul(t[0]),r[1].mul(t[1]))}var de=$1;var W1=Q1;function Q1(r,t){return mr(r[0].mul(t[1]),r[1].mul(t[0]))}var Xa=W1;var K1=J1;function J1(r,t){return mr(r[0].mul(t[1]).sub(r[1].mul(t[0])),r[1].mul(t[1]))}var rn=K1;var j1=tf;function tf(r){return Ir(r[0])*Ir(r[1])}var Ha=j1;var rf=ef;function ef(r,t){for(var n=r.length,e=new Array(n),o=0;o<n;++o)e[o]=rn(r[o],t[o]);return e}var en=rf;var nf=of;function of(r,t){return mr(r[0].mul(t[1]).add(t[0].mul(r[1])),r[1].mul(t[1]))}var $a=nf;var af=uf;function uf(r,t){for(var n=r.length,e=new Array(n),o=0;o<n;++o)e[o]=$a(r[o],t[o]);return e}var Za=af;var sf=cf;function cf(r,t){for(var n=Hr(t),e=r.length,o=new Array(e),i=0;i<e;++i)o[i]=de(r[i],n);return o}var Wa=sf;var lf=ff;function Qa(r,t){return rn(de(r[0],t[1]),de(r[1],t[0]))}function ff(r,t,n,e){var o=en(t,r),i=en(e,n),a=Qa(o,i);if(Ha(a)===0)return null;var u=en(r,n),s=Qa(i,u),l=Xa(s,a),p=Wa(o,l),_=Za(r,p);return _}var hf=_f;function Ka(r){var t=tn(r);return[rr(t,-1/0),rr(t,1/0)]}function pf(r,t){for(var n=new Array(t.length),e=0;e<t.length;++e){var o=t[e],i=r[o[0]],a=r[o[1]];n[e]=[rr(Math.min(i[0],a[0]),-1/0),rr(Math.min(i[1],a[1]),-1/0),rr(Math.max(i[0],a[0]),1/0),rr(Math.max(i[1],a[1]),1/0)]}return n}function Ja(r){for(var t=new Array(r.length),n=0;n<r.length;++n){var e=r[n];t[n]=[rr(e[0],-1/0),rr(e[1],-1/0),rr(e[0],1/0),rr(e[1],1/0)]}return t}function vf(r,t,n){var e=[];return Xe(n,function(o,i){var a=t[o],u=t[i];if(!(a[0]===u[0]||a[0]===u[1]||a[1]===u[0]||a[1]===u[1])){var s=r[a[0]],l=r[a[1]],p=r[u[0]],_=r[u[1]];si(s,l,p,_)&&e.push([o,i])}}),e}function gf(r,t,n,e){var o=[];return Xe(n,e,function(i,a){var u=t[i];if(!(u[0]===a||u[1]===a)){var s=r[a],l=r[u[0]],p=r[u[1]];si(l,p,s,s)&&o.push([i,a])}}),o}function wf(r,t,n,e,o){var i,a,u=r.map(function(et){return[Hr(et[0]),Hr(et[1])]});for(i=0;i<n.length;++i){var s=n[i];a=s[0];var l=s[1],p=t[a],_=t[l],F=lf(ge(r[p[0]]),ge(r[p[1]]),ge(r[_[0]]),ge(r[_[1]]));if(F){var z=r.length;r.push([tn(F[0]),tn(F[1])]),u.push(F),e.push([a,z],[l,z])}}for(e.sort(function(et,X){if(et[0]!==X[0])return et[0]-X[0];var j=u[et[1]],E=u[X[1]];return vi(j[0],E[0])||vi(j[1],E[1])}),i=e.length-1;i>=0;--i){var I=e[i];a=I[0];var m=t[a],L=m[0],W=m[1],V=r[L],H=r[W];if((V[0]-H[0]||V[1]-H[1])<0){var $=L;L=W,W=$}m[0]=L;var Z=m[1]=I[1],Q;for(o&&(Q=m[2]);i>0&&e[i-1][0]===a;){var I=e[--i],it=I[1];o?t.push([Z,it,Q]):t.push([Z,it]),Z=it}o?t.push([Z,W,Q]):t.push([Z,W])}return u}function ja(r,t,n){for(var e=t.length,o=new Uo(e),i=[],a=0;a<t.length;++a){var u=t[a],s=Ka(u[0]),l=Ka(u[1]);i.push([rr(s[0],-1/0),rr(l[0],-1/0),rr(s[1],1/0),rr(l[1],1/0)])}Xe(i,function(I,m){o.link(I,m)});for(var p=!0,_=new Array(e),a=0;a<e;++a){var F=o.find(a);F!==a&&(p=!1,r[F]=[Math.min(r[a][0],r[F][0]),Math.min(r[a][1],r[F][1])])}if(p)return null;for(var z=0,a=0;a<e;++a){var F=o.find(a);F===a?(_[a]=z,r[z++]=r[a]):_[a]=-1}r.length=z;for(var a=0;a<e;++a)_[a]<0&&(_[a]=_[o.find(a)]);return _}function df(r,t){return r[0]-t[0]||r[1]-t[1]}function yf(r,t){var n=r[0]-t[0]||r[1]-t[1];return n||(r[2]<t[2]?-1:r[2]>t[2]?1:0)}function tu(r,t,n){if(r.length!==0){if(t)for(var e=0;e<r.length;++e){var o=r[e],i=t[o[0]],a=t[o[1]];o[0]=Math.min(i,a),o[1]=Math.max(i,a)}else for(var e=0;e<r.length;++e){var o=r[e],i=o[0],a=o[1];o[0]=Math.min(i,a),o[1]=Math.max(i,a)}n?r.sort(yf):r.sort(df);for(var u=1,e=1;e<r.length;++e){var s=r[e-1],l=r[e];l[0]===s[0]&&l[1]===s[1]&&(!n||l[2]===s[2])||(r[u++]=l)}r.length=u}}function xf(r,t,n){var e=ja(r,[],Ja(r));return tu(t,e,n),!!e}function Mf(r,t,n){var e=pf(r,t),o=vf(r,t,e),i=Ja(r),a=gf(r,t,e,i),u=wf(r,t,o,a,n),s=ja(r,u);return tu(t,s,n),s?!0:o.length>0||a.length>0}function _f(r,t,n){var e;if(n){e=t;for(var o=new Array(t.length),i=0;i<t.length;++i){var a=t[i];o[i]=[a[0],a[1],n[i]]}t=o}for(var u=xf(r,t,!!n);Mf(r,t,!!n);)u=!0;if(n&&u){e.length=0,n.length=0;for(var i=0;i<t.length;++i){var a=t[i];e.push([a[0],a[1]]),n.push(a[2])}}return u}var ru=hf;var Tf=bf;function bf(r,t){if(!Array.isArray(r))throw new Error("poly-to-pslg: Error, invalid polygon");if(r.length===0)return{points:[],edges:[]};t=t||{};var n=!0;"nested"in t?n=!!t.nested:r[0].length===2&&typeof r[0][0]=="number"&&(n=!1),n||(r=[r]);for(var e=[],o=[],i=0;i<r.length;++i)for(var a=r[i],u=e.length,s=0;s<a.length;++s)e.push(a[s]),o.push([u+s,u+(s+1)%a.length]);var l="clean"in t?!0:!!t.clean;return l&&ru(e,o),{points:e,edges:o}}var gi=Tf;var nu={line:$r,save:function(r,t){t.data.transforms.push(Ar.clone(t.data.transforms.at(-1)))},restore:function(r,t){t.data.transforms.length>1&&t.data.transforms.pop()},translate:function(r,t,n){let e=t.data.transforms.at(-1);Ar.translate(e,n,e)},rotate:function(r,t,n){let e=t.data.transforms.at(-1);Ar.rotate(e,n,e)},scale:function(r,t,n){let e=t.data.transforms.at(-1);Ar.scale(e,n,e)},strokePath:function(r,t,n,e,o=1){for(let i of n)$r(r,t,i[0],i[1],e,o)},filledPath:function(r,t,n,e){let o=gi(n),i=(0,eu.default)(o.points,o.edges,{exterior:!1}),a=t.data.transforms.at(-1),u=t.data.vertexCount*6,s=Jt.create();for(let l of i)Jt.transformMat3(n[l[0]],a,s),t.data.vertices[u+0]=s[0],t.data.vertices[u+1]=s[1],t.data.vertices[u+2]=e[0],t.data.vertices[u+3]=e[1],t.data.vertices[u+4]=e[2],t.data.vertices[u+5]=e[3],Jt.transformMat3(n[l[1]],a,s),t.data.vertices[u+6]=s[0],t.data.vertices[u+7]=s[1],t.data.vertices[u+8]=e[0],t.data.vertices[u+9]=e[1],t.data.vertices[u+10]=e[2],t.data.vertices[u+11]=e[3],Jt.transformMat3(n[l[2]],a,s),t.data.vertices[u+12]=s[0],t.data.vertices[u+13]=s[1],t.data.vertices[u+14]=e[0],t.data.vertices[u+15]=e[1],t.data.vertices[u+16]=e[2],t.data.vertices[u+17]=e[3],u+=18;t.data.vertexCount+=3*i.length,t.data.dirty=!0},ellipse:function(r,t,n,e,o,i,a,u=1){let[s,l]=n,p=2*Math.PI/i;for(let _=0;_<i;_++){let F=_*p,z=(_+1)*p,I=s+e*Math.cos(F),m=l+o*Math.sin(F),L=s+e*Math.cos(z),W=l+o*Math.sin(z);$r(r,t,[I,m],[L,W],a,u)}},filledEllipse:function(r,t,n,e,o,i,a){let[u,s]=n,l=2*Math.PI/i,p=t.data.transforms.at(-1);for(let _=0;_<i;_++){let F=_*l,z=(_+1)*l,I=u+e*Math.cos(F),m=s+o*Math.sin(F),L=u+e*Math.cos(z),W=s+o*Math.sin(z),H=t.data.vertexCount*6+_*18,$=Jt.transformMat3([u,s],p);t.data.vertices[H+0]=$[0],t.data.vertices[H+1]=$[1],t.data.vertices[H+2]=a[0],t.data.vertices[H+3]=a[1],t.data.vertices[H+4]=a[2],t.data.vertices[H+5]=a[3],Jt.transformMat3([I,m],p,$),t.data.vertices[H+6]=$[0],t.data.vertices[H+7]=$[1],t.data.vertices[H+8]=a[0],t.data.vertices[H+9]=a[1],t.data.vertices[H+10]=a[2],t.data.vertices[H+11]=a[3],Jt.transformMat3([L,W],p,$),t.data.vertices[H+12]=$[0],t.data.vertices[H+13]=$[1],t.data.vertices[H+14]=a[0],t.data.vertices[H+15]=a[1],t.data.vertices[H+16]=a[2],t.data.vertices[H+17]=a[3]}t.data.vertexCount+=3*i,t.data.dirty=!0},box:function(r,t,n,e,o,i,a=1){let[u,s]=n,l=e/2,p=o/2,_=[u-l,s-p],F=[u+l,s-p],z=[u-l,s+p],I=[u+l,s+p];$r(r,t,_,F,i,a),$r(r,t,z,I,i,a),$r(r,t,_,z,i,a),$r(r,t,F,I,i,a)},filledBox:function(r,t,n,e,o,i){let[a,u]=n,s=e/2,l=o/2,p=t.data.transforms.at(-1),_=Jt.transformMat3([a-s,u-l],p),F=Jt.transformMat3([a+s,u-l],p),z=Jt.transformMat3([a-s,u+l],p),I=Jt.transformMat3([a+s,u+l],p),m=t.data.vertexCount*6;t.data.vertices[m+0]=_[0],t.data.vertices[m+1]=_[1],t.data.vertices[m+2]=i[0],t.data.vertices[m+3]=i[1],t.data.vertices[m+4]=i[2],t.data.vertices[m+5]=i[3],t.data.vertices[m+6]=z[0],t.data.vertices[m+7]=z[1],t.data.vertices[m+8]=i[0],t.data.vertices[m+9]=i[1],t.data.vertices[m+10]=i[2],t.data.vertices[m+11]=i[3],t.data.vertices[m+12]=F[0],t.data.vertices[m+13]=F[1],t.data.vertices[m+14]=i[0],t.data.vertices[m+15]=i[1],t.data.vertices[m+16]=i[2],t.data.vertices[m+17]=i[3],t.data.vertices[m+18]=z[0],t.data.vertices[m+19]=z[1],t.data.vertices[m+20]=i[0],t.data.vertices[m+21]=i[1],t.data.vertices[m+22]=i[2],t.data.vertices[m+23]=i[3],t.data.vertices[m+24]=I[0],t.data.vertices[m+25]=I[1],t.data.vertices[m+26]=i[0],t.data.vertices[m+27]=i[1],t.data.vertices[m+28]=i[2],t.data.vertices[m+29]=i[3],t.data.vertices[m+30]=F[0],t.data.vertices[m+31]=F[1],t.data.vertices[m+32]=i[0],t.data.vertices[m+33]=i[1],t.data.vertices[m+34]=i[2],t.data.vertices[m+35]=i[3],t.data.vertexCount+=6,t.data.dirty=!0},clear:function(r,t){t.data.vertexCount=0,t.data.transforms.length=1,Ar.identity(t.data.transforms[0]),t.data.dirty=!0}};function $r(r,t,n,e,o,i=1){let a=t.data.transforms.at(-1);n=Jt.transformMat3(n,a),e=Jt.transformMat3(e,a);let u=Jt.sub(e,n),s=Jt.normalize(u),l=Bf(s),p=i/2,_=t.data.vertexCount*6;t.data.vertices[_+0]=n[0]+l[0]*p,t.data.vertices[_+1]=n[1]+l[1]*p,t.data.vertices[_+2]=o[0],t.data.vertices[_+3]=o[1],t.data.vertices[_+4]=o[2],t.data.vertices[_+5]=o[3],t.data.vertices[_+6]=n[0]-l[0]*p,t.data.vertices[_+7]=n[1]-l[1]*p,t.data.vertices[_+8]=o[0],t.data.vertices[_+9]=o[1],t.data.vertices[_+10]=o[2],t.data.vertices[_+11]=o[3],t.data.vertices[_+12]=e[0]+l[0]*p,t.data.vertices[_+13]=e[1]+l[1]*p,t.data.vertices[_+14]=o[0],t.data.vertices[_+15]=o[1],t.data.vertices[_+16]=o[2],t.data.vertices[_+17]=o[3],t.data.vertices[_+18]=n[0]-l[0]*p,t.data.vertices[_+19]=n[1]-l[1]*p,t.data.vertices[_+20]=o[0],t.data.vertices[_+21]=o[1],t.data.vertices[_+22]=o[2],t.data.vertices[_+23]=o[3],t.data.vertices[_+24]=e[0]+l[0]*p,t.data.vertices[_+25]=e[1]+l[1]*p,t.data.vertices[_+26]=o[0],t.data.vertices[_+27]=o[1],t.data.vertices[_+28]=o[2],t.data.vertices[_+29]=o[3],t.data.vertices[_+30]=e[0]-l[0]*p,t.data.vertices[_+31]=e[1]-l[1]*p,t.data.vertices[_+32]=o[0],t.data.vertices[_+33]=o[1],t.data.vertices[_+34]=o[2],t.data.vertices[_+35]=o[3],t.data.vertexCount+=6,t.data.dirty=!0}function Bf(r){return[-r[1],r[0]]}var iu=_r.create(0,0,0),au={type:"cobalt:primitives",refs:[{name:"color",type:"textView",format:"rgba8unorm",access:"write"}],onInit:async function(r,t={}){return Ef(r,t)},onRun:function(r,t,n){Sf(r,t,n)},onDestroy:function(r,t){Uf(t)},onResize:function(r,t){ou(r,t)},onViewportPosition:function(r,t){ou(r,t)},customFunctions:nu};async function Ef(r,t){let{device:n}=r,e=new Float32Array(3e5),o=n.createBuffer({size:e.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),i=n.createBuffer({size:64*2,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),a=n.createShaderModule({code:Zi}),u=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX,buffer:{}}]}),s=n.createPipelineLayout({bindGroupLayouts:[u]}),l=n.createBindGroup({layout:u,entries:[{binding:0,resource:{buffer:i}}]}),p=n.createRenderPipeline({layout:s,vertex:{module:a,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:a,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:i,vertexBuffer:o,pipeline:p,bindGroup:l,vertexCount:0,dirty:!1,vertices:e,transforms:[Ar.identity()]}}function Sf(r,t,n){if(t.data.vertexCount===0)return;let{device:e}=r;if(t.data.dirty){t.data.dirty=!1;let a=6*Float32Array.BYTES_PER_ELEMENT,u=t.data.vertexCount*a;if(u>t.data.vertexBuffer.size){console.warn("too many primitives, bailing");return}r.device.queue.writeBuffer(t.data.vertexBuffer,0,t.data.vertices.buffer,0,u)}let o=t.options.loadOp||"load",i=n.beginRenderPass({colorAttachments:[{view:t.refs.color,clearValue:r.clearValue,loadOp:o,storeOp:"store"}]});i.setPipeline(t.data.pipeline),i.setBindGroup(0,t.data.bindGroup),i.setVertexBuffer(0,t.data.vertexBuffer),i.draw(t.data.vertexCount),i.end()}function Uf(r){r.data.vertexBuffer.destroy(),r.data.vertexBuffer=null,r.data.uniformBuffer.destroy(),r.data.uniformBuffer=null,r.data.transforms.length=0}function ou(r,t){let{device:n}=r,e=r.viewport.width/r.viewport.zoom,o=r.viewport.height/r.viewport.zoom,i=Lt.ortho(0,e,o,0,-10,10);_r.set(-r.viewport.position[0],-r.viewport.position[1],0,iu);let a=Lt.translation(iu);n.queue.writeBuffer(t.data.uniformBuffer,0,a.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,i.buffer)}var wi={};xi(wi,{setAmbientLight:()=>Pf,setLights:()=>Af,setOccluders:()=>Df});function Af(r,t,n){t.data.lights=n,t.data.lightsBufferNeedsUpdate=!0}function Pf(r,t,n){t.data.lightsRenderer.setAmbientLight(n)}function Df(r,t,n){t.data.lightsRenderer.setObstacles(n),t.data.lightsTextureNeedsUpdate=!0}var nn=class{invViewProjectionMatrix=Lt.identity();viewportSize={width:1,height:1};topLeft=[0,0];zoom=1;constructor(t){this.setViewportSize(t.viewportSize.width,t.viewportSize.height);let n=t.center??this.topLeft;this.setTopLeft(...n);let e=t.zoom??1;this.setZoom(e)}get invertViewProjectionMatrix(){return this.invViewProjectionMatrix}setViewportSize(t,n){this.viewportSize.width=t,this.viewportSize.height=n,this.updateMatrices()}setTopLeft(t,n){this.topLeft[0]=t,this.topLeft[1]=n,this.updateMatrices()}setZoom(t){this.zoom=t,this.updateMatrices()}updateMatrices(){Lt.identity(this.invViewProjectionMatrix),Lt.multiply(Lt.scaling([1,-1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.translation([1,1,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.scaling([.5*this.viewportSize.width/this.zoom,.5*this.viewportSize.height/this.zoom,0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix),Lt.multiply(Lt.translation([this.topLeft[0],this.topLeft[1],0]),this.invViewProjectionMatrix,this.invViewProjectionMatrix)}};var ur=class r{static structs={definition:`
struct Light { // align(16) size(48)
color: vec3<f32>, // offset(0) align(16) size(12)
radius: f32, // offset(12) align(4) size(4)
position: vec2<f32>, // offset(16) align(8) size(8)
intensity: f32, // offset(24) align(4) size(4)
attenuationLinear: f32, // offset(28) align(4) size(4)
attenuationExp: f32, // offset(32) align(4) size(4)
};
struct LightsBuffer { // align(16)
count: u32, // offset(0) align(4) size(4)
// padding
lights: array<Light>, // offset(16) align(16)
};
`,light:{radius:{offset:12},position:{offset:16}},lightsBuffer:{lights:{offset:16,stride:48}}};device;maxLightsCount;currentLightsCount=0;buffer;get gpuBuffer(){return this.buffer.bufferGpu}constructor(t,n){this.device=t,this.maxLightsCount=n;let e=new ArrayBuffer(r.computeBufferBytesLength(n)),o=t.createBuffer({label:"LightsBuffer buffer",size:e.byteLength,usage:GPUBufferUsage.STORAGE|GPUBufferUsage.COPY_DST|GPUBufferUsage.VERTEX});this.buffer={bufferCpu:e,bufferGpu:o},this.setLights([])}setLights(t){if(t.length>this.maxLightsCount)throw new Error(`Too many lights "${t.length}", max is "${this.maxLightsCount}".`);let n=r.computeBufferBytesLength(t.length);new Uint32Array(this.buffer.bufferCpu,0,1).set([t.length]),t.forEach((e,o)=>{new Float32Array(this.buffer.bufferCpu,r.structs.lightsBuffer.lights.offset+r.structs.lightsBuffer.lights.stride*o,9).set([...e.color,e.radius,...e.position,e.intensity,e.attenuationLinear,e.attenuationExp])}),this.device.queue.writeBuffer(this.buffer.bufferGpu,0,this.buffer.bufferCpu,0,n),this.currentLightsCount=t.length}get lightsCount(){return this.currentLightsCount}destroy(){this.buffer.bufferGpu.destroy()}static computeBufferBytesLength(t){return r.structs.lightsBuffer.lights.offset+r.structs.lightsBuffer.lights.stride*t}};var on=class{lightsBuffer;renderPipeline;bindgroup;renderBundle;constructor(t,n,e,o){this.lightsBuffer=n;let i=t.createShaderModule({label:"LightsTextureInitializer shader module",code:`
${ur.structs.definition}
@group(0) @binding(0) var<storage,read> lightsBuffer: LightsBuffer;
struct VertexIn {
@builtin(vertex_index) vertexIndex: u32,
};
struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) uv: vec2<f32>,
};
const cellsGridSizeU = vec2<u32>(${e.gridSize.x}, ${e.gridSize.y});
const cellsGridSizeF = vec2<f32>(${e.gridSize.x}, ${e.gridSize.y});
@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.0, 1.0);
out.uv = (0.5 + 0.5 * screenPosition) * cellsGridSizeF;
return out;
}
struct FragmentOut {
@location(0) color: vec4<f32>,
};
struct LightProperties {
radius: f32,
intensity: f32,
attenuationLinear: f32,
attenuationExp: f32,
};
fn get_light_properties(lightId: u32) -> LightProperties {
var lightProperties: LightProperties;
if (lightId < lightsBuffer.count) {
let light = lightsBuffer.lights[lightId];
lightProperties.radius = light.radius;
lightProperties.intensity = 1.0;
lightProperties.attenuationLinear = light.attenuationLinear;
lightProperties.attenuationExp = light.attenuationExp;
} else {
lightProperties.radius = 0.0;
lightProperties.intensity = 0.0;
lightProperties.attenuationLinear = 0.0;
lightProperties.attenuationExp = 0.0;
}
return lightProperties;
}
@fragment
fn main_fragment(in: VertexOut) -> FragmentOut {
let cellId = vec2<u32>(in.uv);
let lightIdFrom = 4u * (cellId.x + cellId.y * cellsGridSizeU.x);
let lightProperties = array<LightProperties, 4>(
get_light_properties(lightIdFrom + 0u),
get_light_properties(lightIdFrom + 1u),
get_light_properties(lightIdFrom + 2u),
get_light_properties(lightIdFrom + 3u),
);
let sizes = vec4<f32>(
lightProperties[0].radius,
lightProperties[1].radius,
lightProperties[2].radius,
lightProperties[3].radius,
);
let localUv = fract(in.uv);
let fromCenter = 2.0 * localUv - 1.0;
let uvDistanceFromCenter = distance(vec2<f32>(0,0), fromCenter);
let distancesFromCenter = vec4<f32>(uvDistanceFromCenter / sizes * f32(${o}));
let intensities = vec4<f32>(
lightProperties[0].intensity * (1.0 + 1.0 * step(uvDistanceFromCenter, 0.01)),
lightProperties[1].intensity * (1.0 + 1.0 * step(uvDistanceFromCenter, 0.01)),
lightProperties[2].intensity * (1.0 + 1.0 * step(uvDistanceFromCenter, 0.01)),
lightProperties[3].intensity * (1.0 + 1.0 * step(uvDistanceFromCenter, 0.01)),
);
let attenuationsLinear = vec4<f32>(
lightProperties[0].attenuationLinear,
lightProperties[1].attenuationLinear,
lightProperties[2].attenuationLinear,
lightProperties[3].attenuationLinear,
);
let attenuationsExp = vec4<f32>(
lightProperties[0].attenuationExp,
lightProperties[1].attenuationExp,
lightProperties[2].attenuationExp,
lightProperties[3].attenuationExp,
);
var lightIntensities = intensities / (1.0 + distancesFromCenter * (attenuationsLinear + distancesFromCenter * attenuationsExp)); // base intensity equation
lightIntensities *= cos(distancesFromCenter * ${Math.PI/2}); // soft limit;
lightIntensities *= step(distancesFromCenter, vec4<f32>(1.0)); // hard limit
var out: FragmentOut;
out.color = lightIntensities;
return out;
}
`});this.renderPipeline=t.createRenderPipeline({label:"LightsTextureInitializer renderpipeline",layout:"auto",vertex:{module:i,entryPoint:"main_vertex"},fragment:{module:i,entryPoint:"main_fragment",targets:[{format:e.format}]},primitive:{cullMode:"none",topology:"triangle-strip"},multisample:{count:e.sampleCount}}),this.bindgroup=t.createBindGroup({label:"LightsTextureInitializer bindgroup 0",layout:this.renderPipeline.getBindGroupLayout(0),entries:[{binding:0,resource:{buffer:this.lightsBuffer.gpuBuffer}}]});let a=t.createRenderBundleEncoder({label:"LightsTextureInitializer renderbundle encoder",colorFormats:[e.format],sampleCount:e.sampleCount});a.setPipeline(this.renderPipeline),a.setBindGroup(0,this.bindgroup),a.draw(4),this.renderBundle=a.finish({label:"LightsTextureInitializer renderbundle"})}getRenderBundle(){return this.renderBundle}destroy(){}};var an=class{device;renderPipeline;renderBundleEncoderDescriptor;renderBundle;lightsBuffer;indirectDrawing;obstacles=null;constructor(t,n,e,o){this.device=t,this.lightsBuffer=n;let i=!0,a=t.createShaderModule({label:"LightsTextureMask shader module",code:`
struct VertexIn {
@builtin(instance_index) lightIndex: u32,
@location(0) position: vec3<f32>,
@location(1) lightSize: f32,
@location(2) lightPosition: vec2<f32>,
};
struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) color: vec4<f32>,
@location(1) localPosition: vec2<f32>,
};
const cellsGridSizeU = vec2<u32>(${e.gridSize.x}, ${e.gridSize.y});
const cellsGridSizeF = vec2<f32>(${e.gridSize.x}, ${e.gridSize.y});
@vertex
fn main_vertex(in: VertexIn) -> VertexOut {
let worldPosition = in.lightPosition + (in.position.xy - in.lightPosition) * (1.0 + 10000.0 * in.position.z);
let scaling = f32(${o});
let cellIndex = in.lightIndex / 4u;
let indexInCell = in.lightIndex % 4u;
let cellIdU = vec2<u32>(
cellIndex % cellsGridSizeU.x,
cellIndex / cellsGridSizeU.x,
);
let cellIdF = vec2<f32>(cellIdU);
var out: VertexOut;
out.localPosition = (worldPosition - in.lightPosition) / scaling;
out.position = vec4<f32>(
(out.localPosition - (cellsGridSizeF - 1.0) + 2.0 * cellIdF) / cellsGridSizeF,
0.0,
1.0,
);
out.color = vec4<f32>(
vec4<u32>(indexInCell) != vec4<u32>(0u, 1u, 2u, 3u),
);
return out;
}
struct FragmentOut {
@location(0) color: vec4<f32>,
};
@fragment
fn main_fragment(in: VertexOut) -> FragmentOut {
if (in.localPosition.x < -1.0 || in.localPosition.x > 1.0 || in.localPosition.y <= -1.0 || in.localPosition.y > 1.0) {
discard;
}
var out: FragmentOut;
out.color = in.color;
return out;
}
`});this.renderPipeline=t.createRenderPipeline({label:"LightsTextureMask renderpipeline",layout:"auto",vertex:{module:a,entryPoint:"main_vertex",buffers:[{attributes:[{shaderLocation:0,offset:0,format:"float32x3"}],arrayStride:3*Float32Array.BYTES_PER_ELEMENT,stepMode:"vertex"},{attributes:[{shaderLocation:1,offset:ur.structs.light.radius.offset,format:"float32"},{shaderLocation:2,offset:ur.structs.light.position.offset,format:"float32x2"}],arrayStride:ur.structs.lightsBuffer.lights.stride,stepMode:"instance"}]},fragment:{module:a,entryPoint:"main_fragment",targets:[{format:e.format,blend:{color:{operation:"min",srcFactor:"one",dstFactor:"one"},alpha:{operation:"min",srcFactor:"one",dstFactor:"one"}}}]},primitive:{cullMode:i?"none":"back",topology:"triangle-list"},multisample:{count:e.sampleCount}}),this.indirectDrawing={bufferCpu:new ArrayBuffer(20),bufferGpu:t.createBuffer({label:"LightsTextureMask indirect buffer",size:20,usage:GPUBufferUsage.INDIRECT|GPUBufferUsage.COPY_DST})},this.uploadIndirectDrawingBuffer(),this.renderBundleEncoderDescriptor={label:"LightsTextureMask renderbundle encoder",colorFormats:[e.format],sampleCount:e.sampleCount},this.renderBundle=this.buildRenderBundle()}getRenderBundle(){return this.renderBundle}setObstacles(t){let n=[],e=[];for(let l of t){let p=n.length/3;n.push(...l[0],0,...l[1],0,...l[0],1,...l[1],1),e.push(p+0,p+1,p+3,p+0,p+3,p+2)}let o=!1,i=new Float32Array(n),a=this.obstacles?.positionsBufferGpu;(!a||a.size<i.byteLength)&&(a?.destroy(),a=this.device.createBuffer({label:"LightsTextureMask positions buffer",size:i.byteLength,usage:GPUBufferUsage.VERTEX|GPUBufferUsage.COPY_DST}),o=!0),this.device.queue.writeBuffer(a,0,i);let u=new Uint16Array(e),s=this.obstacles?.indexBufferGpu;(!s||s.size<u.byteLength)&&(s?.destroy(),s=this.device.createBuffer({label:"LightsTextureMask index buffer",size:u.byteLength,usage:GPUBufferUsage.INDEX|GPUBufferUsage.COPY_DST}),o=!0),this.device.queue.writeBuffer(s,0,u),this.obstacles={positionsBufferGpu:a,indexBufferGpu:s},this.setIndirectIndexCount(e.length),o&&(this.renderBundle=this.buildRenderBundle())}setLightsCount(t){this.setIndirectInstanceCount(t)}destroy(){this.indirectDrawing.bufferGpu.destroy(),this.obstacles?.positionsBufferGpu.destroy(),this.obstacles?.indexBufferGpu.destroy()}setIndirectIndexCount(t){let n=new Uint32Array(this.indirectDrawing.bufferCpu);n[0]!==t&&(n[0]=t,this.uploadIndirectDrawingBuffer())}setIndirectInstanceCount(t){let n=new Uint32Array(this.indirectDrawing.bufferCpu);n[1]!==t&&(n[1]=t,this.uploadIndirectDrawingBuffer())}buildRenderBundle(){let t=this.device.createRenderBundleEncoder(this.renderBundleEncoderDescriptor);return this.obstacles&&(t.setPipeline(this.renderPipeline),t.setVertexBuffer(0,this.obstacles.positionsBufferGpu),t.setVertexBuffer(1,this.lightsBuffer.gpuBuffer,ur.structs.lightsBuffer.lights.offset),t.setIndexBuffer(this.obstacles.indexBufferGpu,"uint16"),t.drawIndexedIndirect(this.indirectDrawing.bufferGpu,0)),t.finish({label:"LightsTextureMask renderbundle"})}uploadIndirectDrawingBuffer(){this.device.queue.writeBuffer(this.indirectDrawing.bufferGpu,0,this.indirectDrawing.bufferCpu)}};var un=class{lightsBuffer;texture;gridSize;textureMultisampled=null;textureRenderpassDescriptor;textureInitializer;textureMask;constructor(t,n,e){this.lightsBuffer=n;let o=this.lightsBuffer.maxLightsCount/4,i={x:Math.ceil(Math.sqrt(o)),y:0};i.y=Math.ceil(o/i.x),this.gridSize=i;let a={width:i.x*e.resolutionPerLight,height:i.y*e.resolutionPerLight},u="rgba8unorm";this.texture=t.createTexture({label:"LightsTextureMask texture",size:[a.width,a.height],format:u,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT}),e.antialiased&&(this.textureMultisampled=t.createTexture({label:"LightsTextureMask texture multisampled",size:[a.width,a.height],format:u,usage:GPUTextureUsage.TEXTURE_BINDING|GPUTextureUsage.RENDER_ATTACHMENT,sampleCount:4}));let l={view:(this.textureMultisampled??this.texture).createView(),clearValue:[0,0,0,1],loadOp:"load",storeOp:"store"};e.antialiased&&(l.resolveTarget=this.texture.createView()),this.textureRenderpassDescriptor={label:"lights-renderer render to texture renderpass",colorAttachments:[l]};let p={gridSize:i,format:u,sampleCount:this.textureMultisampled?.sampleCount??1};this.textureInitializer=new on(t,n,p,e.maxLightSize),this.textureMask=new an(t,n,p,e.maxLightSize)}update(t){this.textureMask.setLightsCount(this.lightsBuffer.lightsCount);let n=t.beginRenderPass(this.textureRenderpassDescriptor),[e,o]=[this.texture.width,this.texture.height];n.setViewport(0,0,e,o,0,1),n.setScissorRect(0,0,e,o),n.executeBundles([this.textureInitializer.getRenderBundle(),this.textureMask.getRenderBundle()]),n.end()}setObstacles(t){this.textureMask.setObstacles(t)}destroy(){this.texture.destroy(),this.textureMultisampled?.destroy(),this.textureInitializer.destroy(),this.textureMask.destroy()}};var sn=class{device;ambientLight=[.2,.2,.2];targetTexture;renderPipeline;uniformsBufferGpu;bindgroup0;bindgroup1;renderBundle;lightsBuffer;lightsTexture;constructor(t){this.device=t.device,this.targetTexture=t.targetTexture,this.lightsBuffer=t.lightsBuffer,this.lightsTexture=new un(t.device,t.lightsBuffer,t.lightsTextureProperties),this.uniformsBufferGpu=t.device.createBuffer({label:"LightsRenderer uniforms buffer",size:80,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST});let n=t.device.createShaderModule({label:"LightsRenderer shader module",code:`
struct Uniforms { // align(16) size(80)
invertViewMatrix: mat4x4<f32>, // offset(0) align(16) size(64)
ambientLight: vec3<f32>, // offset(64) align(16) size(12)
};
${ur.structs.definition}
@group(0) @binding(0) var<uniform> uniforms: Uniforms;
@group(0) @binding(1) var<storage,read> lightsBuffer: LightsBuffer;
@group(0) @binding(2) var lightsTexture: texture_2d<f32>;
@group(0) @binding(3) var lightsTextureSampler: sampler;
@group(1) @binding(0) var albedoTexture: texture_2d<f32>;
@group(1) @binding(1) var albedoSampler: sampler;
struct VertexIn {
@builtin(vertex_index) vertexIndex: u32,
};
struct VertexOut {
@builtin(position) position: vec4<f32>,
@location(0) worldPosition: vec2<f32>,
@location(1) 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.0, 1.0);
out.worldPosition = (uniforms.invertViewMatrix * out.position).xy;
out.uv = 0.5 + 0.5 * screenPosition * vec2<f32>(1.0, -1.0);
return out;
}
struct FragmentOut {
@location(0) color: vec4<f32>,
};
const cellsGridSizeU = vec2<u32>(${this.lightsTexture.gridSize.x}, ${this.lightsTexture.gridSize.y});
const cellsGridSizeF = vec2<f32>(${this.lightsTexture.gridSize.x}, ${this.lightsTexture.gridSize.y});
fn sampleLightBaseIntensity(lightId: u32, localUv: vec2<f32>) -> f32 {
let cellIndex = lightId / 4u;
let indexInCell = lightId % 4u;
let cellIdU = vec2<u32>(
cellIndex % cellsGridSizeU.x,
cellIndex / cellsGridSizeU.x,
);
let cellIdF = vec2<f32>(cellIdU);
let uv = (cellIdF + localUv) / cellsGridSizeF;
let uvYInverted = vec2<f32>(uv.x, 1.0 - uv.y);
let sample = textureSampleLevel(lightsTexture, lightsTextureSampler, uvYInverted, 0.0);
let channel = vec4<f32>(
vec4<u32>(indexInCell) == vec4<u32>(0u, 1u, 2u, 3u),
);
return dot(sample, channel);
}
fn compute_lights(worldPosition: vec2<f32>) -> vec3<f32> {
var color = vec3<f32>(uniforms.ambientLight);
const maxUvDistance = f32(${1-2/t.lightsTextureProperties.resolutionPerLight});
let lightsCount = lightsBuffer.count;
for (var iLight = 0u; iLight < lightsCount; iLight++) {
let light = lightsBuffer.lights[iLight];
let lightSize = f32(${t.lightsTextureProperties.resolutionPerLight});
let relativePosition = (worldPosition - light.position) / lightSize;
if (max(abs(relativePosition.x), abs(relativePosition.y)) < maxUvDistance) {
let localUv = 0.5 + 0.5 * relativePosition;
let lightIntensity = light.intensity * sampleLightBaseIntensity(iLight, localUv);
color += lightIntensity * light.color;
}
}
return color;
}
@fragment
fn main_fragment(in: VertexOut) -> FragmentOut {
let light = compute_lights(in.worldPosition);
let albedo = textureSample(albedoTexture, albedoSampler, in.uv);
let color = albedo.rgb * light;
var out: FragmentOut;
out.color = vec4<f32>(color, 1.0);
return out;
}
`});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 e=this.renderPipeline.getBindGroupLayout(0);this.bindgroup0=t.device.createBindGroup({label:"LightsRenderer bindgroup 0",layout:e,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 e=new ArrayBuffer(80);new Float32Array(e,0,16).set(n),new Float32Array(e,64,3).set(this.ambientLight),this.device.queue.writeBuffer(this.uniformsBufferGpu,0,e),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 uu={type:"cobalt:light",refs:[{name:"in",type:"textureView",format:"rgba16float",access:"read"},{name:"out",type:"textureView",format:"rgba16float",access:"write"}],onInit:async function(r,t={}){return If(r,t)},onRun:function(r,t,n){mf(r,t,n)},onDestroy:function(r,t){Rf(t)},onResize:function(r,t){Lf(r,t)},onViewportPosition:function(r,t){t.data.viewport.setTopLeft(...r.viewport.position)},customFunctions:{...wi}};async function If(r,t){let{device:n}=r,e=256,o=256,i=new ur(n,e),a=new nn({viewportSize:{width:r.viewport.width,height:r.viewport.height},center:r.viewport.position,zoom:r.viewport.zoom}),u=new sn({device:n,albedo:{view:t.refs.in.data.view,sampler:t.refs.in.data.sampler},targetTexture:t.refs.out.data.texture,lightsBuffer:i,lightsTextureProperties:{resolutionPerLight:o,maxLightSize:o,antialiased:!1,filtering:"nearest"}});return{lightsBuffer:i,lightsBufferNeedsUpdate:!0,lightsTextureNeedsUpdate:!0,lightsRenderer:u,viewport:a,lights:[]}}function mf(r,t,n){t.data.lightsBufferNeedsUpdate&&(t.data.lightsBuffer.setLights(t.data.lights),t.data.lightsBufferNeedsUpdate=!1,t.data.lightsTextureNeedsUpdate=!0);let e=t.data.lightsRenderer;t.data.lightsTextureNeedsUpdate&&(e.computeLightsTexture(n),t.data.lightsTextureNeedsUpdate=!1);let o=n.beginRenderPass({colorAttachments:[{view:t.refs.out.data.view,clearValue:r.clearValue,loadOp:"load",storeOp:"store"}]});t.data.viewport.setZoom(r.viewport.zoom);let i=t.data.viewport.invertViewProjectionMatrix;e.render(o,i),o.end()}function Rf(r){r.data.lightsBuffer.destroy(),r.data.lightsRenderer.destroy()}function Lf(r,t){t.data.lightsRenderer.setAlbedo({view:t.refs.in.data.view,sampler:t.refs.in.data.sampler}),t.data.viewport.setViewportSize(r.viewport.width,r.viewport.height)}var di="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 Ur=new Float32Array(8),cu={type:"cobalt:tileAtlas",refs:[],onInit:async function(r,t={}){return Ff(r,t)},onRun:function(r,t,n){},onDestroy:function(r,t){zf(data)},onResize:function(r,t){su(r,t)},onViewportPosition:function(r,t){su(r,t)}};async function Ff(r,t){let{device:n}=r,e=await gr(r,"tile atlas",t.options.textureUrl),o=n.createBuffer({size:32,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),i=n.createBindGroupLayout({entries:[{binding:0,visibility:GPUShaderStage.VERTEX|GPUShaderStage.FRAGMENT,buffer:{}},{binding:1,visibility:GPUShaderStage.FRAGMENT,texture:{}},{binding:2,visibility:GPUShaderStage.FRAGMENT,sampler:{}}]}),a=n.createBindGroup({layout:i,entries:[{binding:0,resource:{buffer:o}},{binding:1,resource:e.view},{binding:2,resource:e.sampler}]}),u=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:{}}]}),s=n.createPipelineLayout({bindGroupLayouts:[u,i]});return{pipeline:n.createRenderPipeline({label:"tile",vertex:{module:n.createShaderModule({code:di}),entryPoint:"vs_main",buffers:[]},fragment:{module:n.createShaderModule({code:di}),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:s}),uniformBuffer:o,atlasBindGroup:a,atlasMaterial:e,tileBindGroupLayout:u,tileSize:t.options.tileSize,tileScale:t.options.tileScale}}function zf(r){r.atlasMaterial.texture.destroy(),r.atlasMaterial.texture=void 0}function su(r,t){Ur[0]=r.viewport.position[0],Ur[1]=r.viewport.position[1];let n=t.data,{tileScale:e,tileSize:o}=n,i=r.viewport.width/r.viewport.zoom,a=r.viewport.height/r.viewport.zoom;Ur[2]=i/e,Ur[3]=a/e,Ur[4]=1/n.atlasMaterial.texture.width,Ur[5]=1/n.atlasMaterial.texture.height,Ur[6]=o,Ur[7]=1/o,r.device.queue.writeBuffer(n.uniformBuffer,0,Ur,0,8)}function cn(r){let n=Object.keys(r.frames).length,e=new Float32Array(n*30),o=[],i={},a=0;for(let u in r.frames){let s=r.frames[u];o.push(u),i[u]=s.sourceSize;let l=-.5+s.spriteSourceSize.x/s.sourceSize.w,p=-.5+s.spriteSourceSize.y/s.sourceSize.h,_=-.5+(s.spriteSourceSize.x+s.spriteSourceSize.w)/s.sourceSize.w,F=-.5+(s.spriteSourceSize.y+s.spriteSourceSize.h)/s.sourceSize.h,z=[l,p,0],I=[l,F,0],m=[_,F,0],L=[_,p,0],W=0+s.frame.x/r.meta.size.w,V=0+s.frame.y/r.meta.size.h,H=0+(s.frame.x+s.frame.w)/r.meta.size.w,$=0+(s.frame.y+s.frame.h)/r.meta.size.h,Z=[W,V],Q=[W,$],it=[H,$],et=[H,V];e.set(z,a),e.set(Z,a+3),e.set(I,a+5),e.set(Q,a+8),e.set(m,a+10),e.set(it,a+13),e.set(z,a+15),e.set(Z,a+18),e.set(m,a+20),e.set(it,a+23),e.set(L,a+25),e.set(et,a+28),a+=30}return{spriteMeta:i,locations:o,vertices:e}}var yi="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 lu=_r.create(0,0,0),hu={type:"cobalt:spritesheet",refs:[],onInit:async function(r,t={}){return Cf(r,t)},onRun:function(r,t,n){},onDestroy:function(r,t){Nf(t)},onResize:function(r,t){fu(r,t)},onViewportPosition:function(r,t){fu(r,t)}};async function Cf(r,t){let{canvas:n,device:e}=r,o,i,a;n?(o=await Vf(t.options.spriteSheetJsonUrl),o=cn(o),i=await gr(r,"sprite",t.options.colorTextureUrl,"rgba8unorm"),a=await gr(r,"emissive sprite",t.options.emissiveTextureUrl,"rgba8unorm"),n.style.imageRendering="pixelated"):(o=cn(t.options.spriteSheetJson),i=await ne(r,"sprite",t.options.colorTexture,"rgba8unorm"),a=await ne(r,"emissive sprite",t.options.emissiveTexture,"rgba8unorm"));let u=Rn(e,o),s=e.createBuffer({size:64*2,usage:GPUBufferUsage.UNIFORM|GPUBufferUsage.COPY_DST}),l=e.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:{}}]}),p=e.createPipelineLayout({bindGroupLayouts:[l]});return{pipeline:e.createRenderPipeline({label:"sprite",vertex:{module:e.createShaderModule({code:yi}),entryPoint:"vs_main",buffers:[u.bufferLayout]},fragment:{module:e.createShaderModule({code:yi}),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:p}),uniformBuffer:s,quads:u,colorTexture:i,emissiveTexture:a,bindGroupLayout:l,spritesheet:o}}function Nf(r){r.data.quads.buffer.destroy(),r.data.colorTexture.buffer.destroy(),r.data.uniformBuffer.destroy(),r.data.emissiveTexture.texture.destroy()}async function Vf(r){return(await fetch(r)).json()}function fu(r,t){let{device:n,viewport:e}=r,o=e.width/e.zoom,i=e.height/e.zoom,a=Lt.ortho(0,o,i,0,-10,10);_r.set(-e.position[0],-e.position[1],0,lu);let u=Lt.translation(lu);n.queue.writeBuffer(t.data.uniformBuffer,0,u.buffer),n.queue.writeBuffer(t.data.uniformBuffer,64,a.buffer)}var pu={type:"fbTexture",refs:[],onInit:async function(r,t={}){return qf(r,t)},onRun:function(r,t,n){},onDestroy:function(r,t){vu(data)},onResize:function(r,t){Yf(r,t)},onViewportPosition:function(r,t){}};async function qf(r,t){let{device:n}=r,{label:e,mip_count:o,format:i,usage:a,viewportScale:u}=t.options;return er(n,e,r.viewport.width*u,r.viewport.height*u,o,i,a)}function vu(r){r.data.texture.destroy()}function Yf(r,t){let{device:n}=r;vu(t);let{width:e,height:o}=r.viewport,{options:i}=t,a=t.options.viewportScale;t.data=er(n,i.label,e*a,o*a,i.mip_count,i.format,i.usage)}async function Wg(r,t,n){let e,o,i,a;return r.sdlWindow&&r.gpu?(o=r.gpu,e=await(await o.create(["verbose=1"]).requestAdapter()).requestDevice(),i=o.renderGPUDeviceToWindow({device:e,window:r.sdlWindow}),global.GPUBufferUsage=o.GPUBufferUsage,global.GPUShaderStage=o.GPUShaderStage,global.GPUTextureUsage=o.GPUTextureUsage):(a=r,e=await(await navigator.gpu?.requestAdapter({powerPreference:"high-performance"}))?.requestDevice(),o=navigator.gpu,i=a.getContext("webgpu"),i.configure({device:e,format:navigator.gpu?.getPreferredCanvasFormat(),alphaMode:"opaque"})),{nodeDefs:{"cobalt:tileAtlas":cu,"cobalt:spritesheet":hu,"cobalt:fbTexture":pu,"cobalt:bloom":bi,"cobalt:composite":Si,"cobalt:sprite":Pi,"cobalt:tile":Ii,"cobalt:displacement":Yi,"cobalt:overlay":Hi,"cobalt:fbBlit":$i,"cobalt:primitives":au,"cobalt:light":uu},nodes:[],defaultTextureViewRefs:[],canvas:a,device:e,context:i,gpu:o,clearValue:{r:0,g:0,b:0,a:1},viewport:{width:t,height:n,zoom:1,position:[0,0]}}}function Qg(r,t){if(!t?.type)throw new Error("Can't define a new node missing a type.");r.nodeDefs[t.type]=t}async function Kg(r,t){let n=r.nodeDefs[t?.type];if(!n)throw new Error("Can't initialize a new node missing a type.");let e={type:t.type,refs:t.refs||{},options:t.options||{},data:{},enabled:!0};for(let i in e.refs)e.refs[i]==="FRAME_TEXTURE_VIEW"&&(r.defaultTextureViewRefs.push({node:e,refName:i}),e.refs[i]=gu(r));e.data=await n.onInit(r,e);let o=n.customFunctions||{};for(let i in o)e[i]=function(...a){return o[i](r,e,...a)};return r.nodes.push(e),e}function Jg(r){let{device:t,context:n}=r,e=t.createCommandEncoder(),o=gu(r);for(let i of r.defaultTextureViewRefs)i.node.refs[i.refName]=o;for(let i of r.nodes){if(!i.enabled)continue;r.nodeDefs[i.type].onRun(r,i,e)}t.queue.submit([e.finish()]),r.canvas||r.context.swap()}function jg(r){for(let t of r.nodes)r.nodeDefs[t.type].onDestroy(r,t);r.nodes.length=0,r.defaultTextureViewRefs.length=0}function tw(r,t,n){r.viewport.width=t,r.viewport.height=n;for(let e of r.nodes)r.nodeDefs[e.type].onResize(r,e)}function rw(r,t){r.viewport.position[0]=t[0]-r.viewport.width/2/r.viewport.zoom,r.viewport.position[1]=t[1]-r.viewport.height/2/r.viewport.zoom;for(let n of r.nodes)r.nodeDefs[n.type].onViewportPosition(r,n)}function Ui(r){return r.canvas?navigator.gpu.getPreferredCanvasFormat():r.context.getPreferredFormat()}function gu(r){return r.canvas?r.context.getCurrentTexture().createView():r.context.getCurrentTextureView()}export{er as createTexture,ne as createTextureFromBuffer,gr as createTextureFromUrl,Qg as defineNode,Jg as draw,gu as getCurrentTextureView,Ui as getPreferredFormat,Wg as init,Kg as initNode,jg as reset,tw as setViewportDimensions,rw as setViewportPosition};
/*!
* The buffer module from node.js, for the browser.
*
* @author Feross Aboukhadijeh <feross@feross.org> <http://feross.org>
* @license MIT
*/